target_core_base.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953
  1. #ifndef TARGET_CORE_BASE_H
  2. #define TARGET_CORE_BASE_H
  3. #include <linux/in.h>
  4. #include <linux/configfs.h>
  5. #include <linux/dma-mapping.h>
  6. #include <linux/blkdev.h>
  7. #include <scsi/scsi_cmnd.h>
  8. #include <net/sock.h>
  9. #include <net/tcp.h>
  10. #define TARGET_CORE_MOD_VERSION "v4.0.0-rc6"
  11. #define SHUTDOWN_SIGS (sigmask(SIGKILL)|sigmask(SIGINT)|sigmask(SIGABRT))
  12. /* Used by transport_generic_allocate_iovecs() */
  13. #define TRANSPORT_IOV_DATA_BUFFER 5
  14. /* Maximum Number of LUNs per Target Portal Group */
  15. #define TRANSPORT_MAX_LUNS_PER_TPG 256
  16. /*
  17. * By default we use 32-byte CDBs in TCM Core and subsystem plugin code.
  18. *
  19. * Note that both include/scsi/scsi_cmnd.h:MAX_COMMAND_SIZE and
  20. * include/linux/blkdev.h:BLOCK_MAX_CDB as of v2.6.36-rc4 still use
  21. * 16-byte CDBs by default and require an extra allocation for
  22. * 32-byte CDBs to becasue of legacy issues.
  23. *
  24. * Within TCM Core there are no such legacy limitiations, so we go ahead
  25. * use 32-byte CDBs by default and use include/scsi/scsi.h:scsi_command_size()
  26. * within all TCM Core and subsystem plugin code.
  27. */
  28. #define TCM_MAX_COMMAND_SIZE 32
  29. /*
  30. * From include/scsi/scsi_cmnd.h:SCSI_SENSE_BUFFERSIZE, currently
  31. * defined 96, but the real limit is 252 (or 260 including the header)
  32. */
  33. #define TRANSPORT_SENSE_BUFFER SCSI_SENSE_BUFFERSIZE
  34. /* Used by transport_send_check_condition_and_sense() */
  35. #define SPC_SENSE_KEY_OFFSET 2
  36. #define SPC_ASC_KEY_OFFSET 12
  37. #define SPC_ASCQ_KEY_OFFSET 13
  38. #define TRANSPORT_IQN_LEN 224
  39. /* Used by target_core_store_alua_lu_gp() and target_core_alua_lu_gp_show_attr_members() */
  40. #define LU_GROUP_NAME_BUF 256
  41. /* Used by core_alua_store_tg_pt_gp_info() and target_core_alua_tg_pt_gp_show_attr_members() */
  42. #define TG_PT_GROUP_NAME_BUF 256
  43. /* Used to parse VPD into struct t10_vpd */
  44. #define VPD_TMP_BUF_SIZE 128
  45. /* Used by transport_generic_cmd_sequencer() */
  46. #define READ_BLOCK_LEN 6
  47. #define READ_CAP_LEN 8
  48. #define READ_POSITION_LEN 20
  49. #define INQUIRY_LEN 36
  50. /* Used by transport_get_inquiry_vpd_serial() */
  51. #define INQUIRY_VPD_SERIAL_LEN 254
  52. /* Used by transport_get_inquiry_vpd_device_ident() */
  53. #define INQUIRY_VPD_DEVICE_IDENTIFIER_LEN 254
  54. /* struct se_hba->hba_flags */
  55. enum hba_flags_table {
  56. HBA_FLAGS_INTERNAL_USE = 0x01,
  57. HBA_FLAGS_PSCSI_MODE = 0x02,
  58. };
  59. /* struct se_lun->lun_status */
  60. enum transport_lun_status_table {
  61. TRANSPORT_LUN_STATUS_FREE = 0,
  62. TRANSPORT_LUN_STATUS_ACTIVE = 1,
  63. };
  64. /* struct se_portal_group->se_tpg_type */
  65. enum transport_tpg_type_table {
  66. TRANSPORT_TPG_TYPE_NORMAL = 0,
  67. TRANSPORT_TPG_TYPE_DISCOVERY = 1,
  68. };
  69. /* Used for generate timer flags */
  70. enum timer_flags_table {
  71. TF_RUNNING = 0x01,
  72. TF_STOP = 0x02,
  73. };
  74. /* Special transport agnostic struct se_cmd->t_states */
  75. enum transport_state_table {
  76. TRANSPORT_NO_STATE = 0,
  77. TRANSPORT_NEW_CMD = 1,
  78. TRANSPORT_DEFERRED_CMD = 2,
  79. TRANSPORT_WRITE_PENDING = 3,
  80. TRANSPORT_PROCESS_WRITE = 4,
  81. TRANSPORT_PROCESSING = 5,
  82. TRANSPORT_COMPLETE_OK = 6,
  83. TRANSPORT_COMPLETE_FAILURE = 7,
  84. TRANSPORT_COMPLETE_TIMEOUT = 8,
  85. TRANSPORT_PROCESS_TMR = 9,
  86. TRANSPORT_TMR_COMPLETE = 10,
  87. TRANSPORT_ISTATE_PROCESSING = 11,
  88. TRANSPORT_ISTATE_PROCESSED = 12,
  89. TRANSPORT_KILL = 13,
  90. TRANSPORT_REMOVE = 14,
  91. TRANSPORT_FREE = 15,
  92. TRANSPORT_NEW_CMD_MAP = 16,
  93. };
  94. /* Used for struct se_cmd->se_cmd_flags */
  95. enum se_cmd_flags_table {
  96. SCF_SUPPORTED_SAM_OPCODE = 0x00000001,
  97. SCF_TRANSPORT_TASK_SENSE = 0x00000002,
  98. SCF_EMULATED_TASK_SENSE = 0x00000004,
  99. SCF_SCSI_DATA_SG_IO_CDB = 0x00000008,
  100. SCF_SCSI_CONTROL_SG_IO_CDB = 0x00000010,
  101. SCF_SCSI_CONTROL_NONSG_IO_CDB = 0x00000020,
  102. SCF_SCSI_NON_DATA_CDB = 0x00000040,
  103. SCF_SCSI_CDB_EXCEPTION = 0x00000080,
  104. SCF_SCSI_RESERVATION_CONFLICT = 0x00000100,
  105. SCF_CMD_PASSTHROUGH_NOALLOC = 0x00000200,
  106. SCF_SE_CMD_FAILED = 0x00000400,
  107. SCF_SE_LUN_CMD = 0x00000800,
  108. SCF_SE_ALLOW_EOO = 0x00001000,
  109. SCF_SE_DISABLE_ONLINE_CHECK = 0x00002000,
  110. SCF_SENT_CHECK_CONDITION = 0x00004000,
  111. SCF_OVERFLOW_BIT = 0x00008000,
  112. SCF_UNDERFLOW_BIT = 0x00010000,
  113. SCF_SENT_DELAYED_TAS = 0x00020000,
  114. SCF_ALUA_NON_OPTIMIZED = 0x00040000,
  115. SCF_DELAYED_CMD_FROM_SAM_ATTR = 0x00080000,
  116. SCF_PASSTHROUGH_SG_TO_MEM = 0x00100000,
  117. SCF_PASSTHROUGH_CONTIG_TO_SG = 0x00200000,
  118. SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC = 0x00400000,
  119. SCF_EMULATE_SYNC_CACHE = 0x00800000,
  120. SCF_EMULATE_CDB_ASYNC = 0x01000000,
  121. SCF_EMULATE_SYNC_UNMAP = 0x02000000
  122. };
  123. /* struct se_dev_entry->lun_flags and struct se_lun->lun_access */
  124. enum transport_lunflags_table {
  125. TRANSPORT_LUNFLAGS_NO_ACCESS = 0x00,
  126. TRANSPORT_LUNFLAGS_INITIATOR_ACCESS = 0x01,
  127. TRANSPORT_LUNFLAGS_READ_ONLY = 0x02,
  128. TRANSPORT_LUNFLAGS_READ_WRITE = 0x04,
  129. };
  130. /* struct se_device->dev_status */
  131. enum transport_device_status_table {
  132. TRANSPORT_DEVICE_ACTIVATED = 0x01,
  133. TRANSPORT_DEVICE_DEACTIVATED = 0x02,
  134. TRANSPORT_DEVICE_QUEUE_FULL = 0x04,
  135. TRANSPORT_DEVICE_SHUTDOWN = 0x08,
  136. TRANSPORT_DEVICE_OFFLINE_ACTIVATED = 0x10,
  137. TRANSPORT_DEVICE_OFFLINE_DEACTIVATED = 0x20,
  138. };
  139. /*
  140. * Used by transport_send_check_condition_and_sense() and se_cmd->scsi_sense_reason
  141. * to signal which ASC/ASCQ sense payload should be built.
  142. */
  143. enum tcm_sense_reason_table {
  144. TCM_NON_EXISTENT_LUN = 0x01,
  145. TCM_UNSUPPORTED_SCSI_OPCODE = 0x02,
  146. TCM_INCORRECT_AMOUNT_OF_DATA = 0x03,
  147. TCM_UNEXPECTED_UNSOLICITED_DATA = 0x04,
  148. TCM_SERVICE_CRC_ERROR = 0x05,
  149. TCM_SNACK_REJECTED = 0x06,
  150. TCM_SECTOR_COUNT_TOO_MANY = 0x07,
  151. TCM_INVALID_CDB_FIELD = 0x08,
  152. TCM_INVALID_PARAMETER_LIST = 0x09,
  153. TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE = 0x0a,
  154. TCM_UNKNOWN_MODE_PAGE = 0x0b,
  155. TCM_WRITE_PROTECTED = 0x0c,
  156. TCM_CHECK_CONDITION_ABORT_CMD = 0x0d,
  157. TCM_CHECK_CONDITION_UNIT_ATTENTION = 0x0e,
  158. TCM_CHECK_CONDITION_NOT_READY = 0x0f,
  159. };
  160. struct se_obj {
  161. atomic_t obj_access_count;
  162. } ____cacheline_aligned;
  163. /*
  164. * Used by TCM Core internally to signal if ALUA emulation is enabled or
  165. * disabled, or running in with TCM/pSCSI passthrough mode
  166. */
  167. typedef enum {
  168. SPC_ALUA_PASSTHROUGH,
  169. SPC2_ALUA_DISABLED,
  170. SPC3_ALUA_EMULATED
  171. } t10_alua_index_t;
  172. /*
  173. * Used by TCM Core internally to signal if SAM Task Attribute emulation
  174. * is enabled or disabled, or running in with TCM/pSCSI passthrough mode
  175. */
  176. typedef enum {
  177. SAM_TASK_ATTR_PASSTHROUGH,
  178. SAM_TASK_ATTR_UNTAGGED,
  179. SAM_TASK_ATTR_EMULATED
  180. } t10_task_attr_index_t;
  181. /*
  182. * Used for target SCSI statistics
  183. */
  184. typedef enum {
  185. SCSI_INST_INDEX,
  186. SCSI_DEVICE_INDEX,
  187. SCSI_AUTH_INTR_INDEX,
  188. SCSI_INDEX_TYPE_MAX
  189. } scsi_index_t;
  190. struct scsi_index_table {
  191. spinlock_t lock;
  192. u32 scsi_mib_index[SCSI_INDEX_TYPE_MAX];
  193. } ____cacheline_aligned;
  194. struct se_cmd;
  195. struct t10_alua {
  196. t10_alua_index_t alua_type;
  197. /* ALUA Target Port Group ID */
  198. u16 alua_tg_pt_gps_counter;
  199. u32 alua_tg_pt_gps_count;
  200. spinlock_t tg_pt_gps_lock;
  201. struct se_subsystem_dev *t10_sub_dev;
  202. /* Used for default ALUA Target Port Group */
  203. struct t10_alua_tg_pt_gp *default_tg_pt_gp;
  204. /* Used for default ALUA Target Port Group ConfigFS group */
  205. struct config_group alua_tg_pt_gps_group;
  206. int (*alua_state_check)(struct se_cmd *, unsigned char *, u8 *);
  207. struct list_head tg_pt_gps_list;
  208. } ____cacheline_aligned;
  209. struct t10_alua_lu_gp {
  210. u16 lu_gp_id;
  211. int lu_gp_valid_id;
  212. u32 lu_gp_members;
  213. atomic_t lu_gp_shutdown;
  214. atomic_t lu_gp_ref_cnt;
  215. spinlock_t lu_gp_lock;
  216. struct config_group lu_gp_group;
  217. struct list_head lu_gp_list;
  218. struct list_head lu_gp_mem_list;
  219. } ____cacheline_aligned;
  220. struct t10_alua_lu_gp_member {
  221. int lu_gp_assoc:1;
  222. atomic_t lu_gp_mem_ref_cnt;
  223. spinlock_t lu_gp_mem_lock;
  224. struct t10_alua_lu_gp *lu_gp;
  225. struct se_device *lu_gp_mem_dev;
  226. struct list_head lu_gp_mem_list;
  227. } ____cacheline_aligned;
  228. struct t10_alua_tg_pt_gp {
  229. u16 tg_pt_gp_id;
  230. int tg_pt_gp_valid_id;
  231. int tg_pt_gp_alua_access_status;
  232. int tg_pt_gp_alua_access_type;
  233. int tg_pt_gp_nonop_delay_msecs;
  234. int tg_pt_gp_trans_delay_msecs;
  235. int tg_pt_gp_pref;
  236. int tg_pt_gp_write_metadata;
  237. /* Used by struct t10_alua_tg_pt_gp->tg_pt_gp_md_buf_len */
  238. #define ALUA_MD_BUF_LEN 1024
  239. u32 tg_pt_gp_md_buf_len;
  240. u32 tg_pt_gp_members;
  241. atomic_t tg_pt_gp_alua_access_state;
  242. atomic_t tg_pt_gp_ref_cnt;
  243. spinlock_t tg_pt_gp_lock;
  244. struct mutex tg_pt_gp_md_mutex;
  245. struct se_subsystem_dev *tg_pt_gp_su_dev;
  246. struct config_group tg_pt_gp_group;
  247. struct list_head tg_pt_gp_list;
  248. struct list_head tg_pt_gp_mem_list;
  249. } ____cacheline_aligned;
  250. struct t10_alua_tg_pt_gp_member {
  251. int tg_pt_gp_assoc:1;
  252. atomic_t tg_pt_gp_mem_ref_cnt;
  253. spinlock_t tg_pt_gp_mem_lock;
  254. struct t10_alua_tg_pt_gp *tg_pt_gp;
  255. struct se_port *tg_pt;
  256. struct list_head tg_pt_gp_mem_list;
  257. } ____cacheline_aligned;
  258. struct t10_vpd {
  259. unsigned char device_identifier[INQUIRY_VPD_DEVICE_IDENTIFIER_LEN];
  260. int protocol_identifier_set;
  261. u32 protocol_identifier;
  262. u32 device_identifier_code_set;
  263. u32 association;
  264. u32 device_identifier_type;
  265. struct list_head vpd_list;
  266. } ____cacheline_aligned;
  267. struct t10_wwn {
  268. unsigned char vendor[8];
  269. unsigned char model[16];
  270. unsigned char revision[4];
  271. unsigned char unit_serial[INQUIRY_VPD_SERIAL_LEN];
  272. spinlock_t t10_vpd_lock;
  273. struct se_subsystem_dev *t10_sub_dev;
  274. struct config_group t10_wwn_group;
  275. struct list_head t10_vpd_list;
  276. } ____cacheline_aligned;
  277. /*
  278. * Used by TCM Core internally to signal if >= SPC-3 peristent reservations
  279. * emulation is enabled or disabled, or running in with TCM/pSCSI passthrough
  280. * mode
  281. */
  282. typedef enum {
  283. SPC_PASSTHROUGH,
  284. SPC2_RESERVATIONS,
  285. SPC3_PERSISTENT_RESERVATIONS
  286. } t10_reservations_index_t;
  287. struct t10_pr_registration {
  288. /* Used for fabrics that contain WWN+ISID */
  289. #define PR_REG_ISID_LEN 16
  290. /* PR_REG_ISID_LEN + ',i,0x' */
  291. #define PR_REG_ISID_ID_LEN (PR_REG_ISID_LEN + 5)
  292. char pr_reg_isid[PR_REG_ISID_LEN];
  293. /* Used during APTPL metadata reading */
  294. #define PR_APTPL_MAX_IPORT_LEN 256
  295. unsigned char pr_iport[PR_APTPL_MAX_IPORT_LEN];
  296. /* Used during APTPL metadata reading */
  297. #define PR_APTPL_MAX_TPORT_LEN 256
  298. unsigned char pr_tport[PR_APTPL_MAX_TPORT_LEN];
  299. /* For writing out live meta data */
  300. unsigned char *pr_aptpl_buf;
  301. u16 pr_aptpl_rpti;
  302. u16 pr_reg_tpgt;
  303. /* Reservation effects all target ports */
  304. int pr_reg_all_tg_pt;
  305. /* Activate Persistence across Target Power Loss */
  306. int pr_reg_aptpl;
  307. int pr_res_holder;
  308. int pr_res_type;
  309. int pr_res_scope;
  310. /* Used for fabric initiator WWPNs using a ISID */
  311. int isid_present_at_reg:1;
  312. u32 pr_res_mapped_lun;
  313. u32 pr_aptpl_target_lun;
  314. u32 pr_res_generation;
  315. u64 pr_reg_bin_isid;
  316. u64 pr_res_key;
  317. atomic_t pr_res_holders;
  318. struct se_node_acl *pr_reg_nacl;
  319. struct se_dev_entry *pr_reg_deve;
  320. struct se_lun *pr_reg_tg_pt_lun;
  321. struct list_head pr_reg_list;
  322. struct list_head pr_reg_abort_list;
  323. struct list_head pr_reg_aptpl_list;
  324. struct list_head pr_reg_atp_list;
  325. struct list_head pr_reg_atp_mem_list;
  326. } ____cacheline_aligned;
  327. /*
  328. * This set of function pointer ops is set based upon SPC3_PERSISTENT_RESERVATIONS,
  329. * SPC2_RESERVATIONS or SPC_PASSTHROUGH in drivers/target/target_core_pr.c:
  330. * core_setup_reservations()
  331. */
  332. struct t10_reservation_ops {
  333. int (*t10_reservation_check)(struct se_cmd *, u32 *);
  334. int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
  335. int (*t10_pr_register)(struct se_cmd *);
  336. int (*t10_pr_clear)(struct se_cmd *);
  337. };
  338. struct t10_reservation_template {
  339. /* Reservation effects all target ports */
  340. int pr_all_tg_pt;
  341. /* Activate Persistence across Target Power Loss enabled
  342. * for SCSI device */
  343. int pr_aptpl_active;
  344. /* Used by struct t10_reservation_template->pr_aptpl_buf_len */
  345. #define PR_APTPL_BUF_LEN 8192
  346. u32 pr_aptpl_buf_len;
  347. u32 pr_generation;
  348. t10_reservations_index_t res_type;
  349. spinlock_t registration_lock;
  350. spinlock_t aptpl_reg_lock;
  351. /*
  352. * This will always be set by one individual I_T Nexus.
  353. * However with all_tg_pt=1, other I_T Nexus from the
  354. * same initiator can access PR reg/res info on a different
  355. * target port.
  356. *
  357. * There is also the 'All Registrants' case, where there is
  358. * a single *pr_res_holder of the reservation, but all
  359. * registrations are considered reservation holders.
  360. */
  361. struct se_node_acl *pr_res_holder;
  362. struct list_head registration_list;
  363. struct list_head aptpl_reg_list;
  364. struct t10_reservation_ops pr_ops;
  365. } ____cacheline_aligned;
  366. struct se_queue_req {
  367. int state;
  368. void *cmd;
  369. struct list_head qr_list;
  370. } ____cacheline_aligned;
  371. struct se_queue_obj {
  372. atomic_t queue_cnt;
  373. spinlock_t cmd_queue_lock;
  374. struct list_head qobj_list;
  375. wait_queue_head_t thread_wq;
  376. } ____cacheline_aligned;
  377. /*
  378. * Used one per struct se_cmd to hold all extra struct se_task
  379. * metadata. This structure is setup and allocated in
  380. * drivers/target/target_core_transport.c:__transport_alloc_se_cmd()
  381. */
  382. struct se_transport_task {
  383. unsigned char *t_task_cdb;
  384. unsigned char __t_task_cdb[TCM_MAX_COMMAND_SIZE];
  385. unsigned long long t_task_lba;
  386. int t_tasks_failed;
  387. int t_tasks_fua;
  388. int t_tasks_bidi:1;
  389. u32 t_task_cdbs;
  390. u32 t_tasks_check;
  391. u32 t_tasks_no;
  392. u32 t_tasks_sectors;
  393. u32 t_tasks_se_num;
  394. u32 t_tasks_se_bidi_num;
  395. u32 t_tasks_sg_chained_no;
  396. atomic_t t_fe_count;
  397. atomic_t t_se_count;
  398. atomic_t t_task_cdbs_left;
  399. atomic_t t_task_cdbs_ex_left;
  400. atomic_t t_task_cdbs_timeout_left;
  401. atomic_t t_task_cdbs_sent;
  402. atomic_t t_transport_aborted;
  403. atomic_t t_transport_active;
  404. atomic_t t_transport_complete;
  405. atomic_t t_transport_queue_active;
  406. atomic_t t_transport_sent;
  407. atomic_t t_transport_stop;
  408. atomic_t t_transport_timeout;
  409. atomic_t transport_dev_active;
  410. atomic_t transport_lun_active;
  411. atomic_t transport_lun_fe_stop;
  412. atomic_t transport_lun_stop;
  413. spinlock_t t_state_lock;
  414. struct completion t_transport_stop_comp;
  415. struct completion transport_lun_fe_stop_comp;
  416. struct completion transport_lun_stop_comp;
  417. struct scatterlist *t_tasks_sg_chained;
  418. struct scatterlist t_tasks_sg_bounce;
  419. void *t_task_buf;
  420. /*
  421. * Used for pre-registered fabric SGL passthrough WRITE and READ
  422. * with the special SCF_PASSTHROUGH_CONTIG_TO_SG case for TCM_Loop
  423. * and other HW target mode fabric modules.
  424. */
  425. struct scatterlist *t_task_pt_sgl;
  426. struct list_head *t_mem_list;
  427. /* Used for BIDI READ */
  428. struct list_head *t_mem_bidi_list;
  429. struct list_head t_task_list;
  430. } ____cacheline_aligned;
  431. struct se_task {
  432. unsigned char task_sense;
  433. struct scatterlist *task_sg;
  434. struct scatterlist *task_sg_bidi;
  435. u8 task_scsi_status;
  436. u8 task_flags;
  437. int task_error_status;
  438. int task_state_flags;
  439. int task_padded_sg:1;
  440. unsigned long long task_lba;
  441. u32 task_no;
  442. u32 task_sectors;
  443. u32 task_size;
  444. u32 task_sg_num;
  445. u32 task_sg_offset;
  446. enum dma_data_direction task_data_direction;
  447. struct se_cmd *task_se_cmd;
  448. struct se_device *se_dev;
  449. struct completion task_stop_comp;
  450. atomic_t task_active;
  451. atomic_t task_execute_queue;
  452. atomic_t task_timeout;
  453. atomic_t task_sent;
  454. atomic_t task_stop;
  455. atomic_t task_state_active;
  456. struct timer_list task_timer;
  457. struct se_device *se_obj_ptr;
  458. struct list_head t_list;
  459. struct list_head t_execute_list;
  460. struct list_head t_state_list;
  461. } ____cacheline_aligned;
  462. #define TASK_CMD(task) ((struct se_cmd *)task->task_se_cmd)
  463. #define TASK_DEV(task) ((struct se_device *)task->se_dev)
  464. struct se_cmd {
  465. /* SAM response code being sent to initiator */
  466. u8 scsi_status;
  467. u8 scsi_asc;
  468. u8 scsi_ascq;
  469. u8 scsi_sense_reason;
  470. u16 scsi_sense_length;
  471. /* Delay for ALUA Active/NonOptimized state access in milliseconds */
  472. int alua_nonop_delay;
  473. /* See include/linux/dma-mapping.h */
  474. enum dma_data_direction data_direction;
  475. /* For SAM Task Attribute */
  476. int sam_task_attr;
  477. /* Transport protocol dependent state, see transport_state_table */
  478. enum transport_state_table t_state;
  479. /* Transport protocol dependent state for out of order CmdSNs */
  480. int deferred_t_state;
  481. /* Transport specific error status */
  482. int transport_error_status;
  483. /* See se_cmd_flags_table */
  484. u32 se_cmd_flags;
  485. u32 se_ordered_id;
  486. /* Total size in bytes associated with command */
  487. u32 data_length;
  488. /* SCSI Presented Data Transfer Length */
  489. u32 cmd_spdtl;
  490. u32 residual_count;
  491. u32 orig_fe_lun;
  492. /* Persistent Reservation key */
  493. u64 pr_res_key;
  494. atomic_t transport_sent;
  495. /* Used for sense data */
  496. void *sense_buffer;
  497. struct list_head se_delayed_list;
  498. struct list_head se_ordered_list;
  499. struct list_head se_lun_list;
  500. struct se_device *se_dev;
  501. struct se_dev_entry *se_deve;
  502. struct se_device *se_obj_ptr;
  503. struct se_device *se_orig_obj_ptr;
  504. struct se_lun *se_lun;
  505. /* Only used for internal passthrough and legacy TCM fabric modules */
  506. struct se_session *se_sess;
  507. struct se_tmr_req *se_tmr_req;
  508. /* t_task is setup to t_task_backstore in transport_init_se_cmd() */
  509. struct se_transport_task *t_task;
  510. struct se_transport_task t_task_backstore;
  511. struct target_core_fabric_ops *se_tfo;
  512. int (*transport_emulate_cdb)(struct se_cmd *);
  513. void (*transport_split_cdb)(unsigned long long, u32 *, unsigned char *);
  514. void (*transport_wait_for_tasks)(struct se_cmd *, int, int);
  515. void (*transport_complete_callback)(struct se_cmd *);
  516. } ____cacheline_aligned;
  517. #define T_TASK(cmd) ((struct se_transport_task *)(cmd->t_task))
  518. #define CMD_TFO(cmd) ((struct target_core_fabric_ops *)cmd->se_tfo)
  519. struct se_tmr_req {
  520. /* Task Management function to be preformed */
  521. u8 function;
  522. /* Task Management response to send */
  523. u8 response;
  524. int call_transport;
  525. /* Reference to ITT that Task Mgmt should be preformed */
  526. u32 ref_task_tag;
  527. /* 64-bit encoded SAM LUN from $FABRIC_MOD TMR header */
  528. u64 ref_task_lun;
  529. void *fabric_tmr_ptr;
  530. struct se_cmd *task_cmd;
  531. struct se_cmd *ref_cmd;
  532. struct se_device *tmr_dev;
  533. struct se_lun *tmr_lun;
  534. struct list_head tmr_list;
  535. } ____cacheline_aligned;
  536. struct se_ua {
  537. u8 ua_asc;
  538. u8 ua_ascq;
  539. struct se_node_acl *ua_nacl;
  540. struct list_head ua_dev_list;
  541. struct list_head ua_nacl_list;
  542. } ____cacheline_aligned;
  543. struct se_node_acl {
  544. char initiatorname[TRANSPORT_IQN_LEN];
  545. /* Used to signal demo mode created ACL, disabled by default */
  546. int dynamic_node_acl:1;
  547. u32 queue_depth;
  548. u32 acl_index;
  549. u64 num_cmds;
  550. u64 read_bytes;
  551. u64 write_bytes;
  552. spinlock_t stats_lock;
  553. /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
  554. atomic_t acl_pr_ref_count;
  555. struct se_dev_entry *device_list;
  556. struct se_session *nacl_sess;
  557. struct se_portal_group *se_tpg;
  558. spinlock_t device_list_lock;
  559. spinlock_t nacl_sess_lock;
  560. struct config_group acl_group;
  561. struct config_group acl_attrib_group;
  562. struct config_group acl_auth_group;
  563. struct config_group acl_param_group;
  564. struct config_group *acl_default_groups[4];
  565. struct list_head acl_list;
  566. struct list_head acl_sess_list;
  567. } ____cacheline_aligned;
  568. struct se_session {
  569. u64 sess_bin_isid;
  570. struct se_node_acl *se_node_acl;
  571. struct se_portal_group *se_tpg;
  572. void *fabric_sess_ptr;
  573. struct list_head sess_list;
  574. struct list_head sess_acl_list;
  575. } ____cacheline_aligned;
  576. #define SE_SESS(cmd) ((struct se_session *)(cmd)->se_sess)
  577. #define SE_NODE_ACL(sess) ((struct se_node_acl *)(sess)->se_node_acl)
  578. struct se_device;
  579. struct se_transform_info;
  580. struct scatterlist;
  581. struct se_lun_acl {
  582. char initiatorname[TRANSPORT_IQN_LEN];
  583. u32 mapped_lun;
  584. struct se_node_acl *se_lun_nacl;
  585. struct se_lun *se_lun;
  586. struct list_head lacl_list;
  587. struct config_group se_lun_group;
  588. } ____cacheline_aligned;
  589. struct se_dev_entry {
  590. int def_pr_registered:1;
  591. /* See transport_lunflags_table */
  592. u32 lun_flags;
  593. u32 deve_cmds;
  594. u32 mapped_lun;
  595. u32 average_bytes;
  596. u32 last_byte_count;
  597. u32 total_cmds;
  598. u32 total_bytes;
  599. u64 pr_res_key;
  600. u64 creation_time;
  601. u32 attach_count;
  602. u64 read_bytes;
  603. u64 write_bytes;
  604. atomic_t ua_count;
  605. /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
  606. atomic_t pr_ref_count;
  607. struct se_lun_acl *se_lun_acl;
  608. spinlock_t ua_lock;
  609. struct se_lun *se_lun;
  610. struct list_head alua_port_list;
  611. struct list_head ua_list;
  612. } ____cacheline_aligned;
  613. struct se_dev_limits {
  614. /* Max supported HW queue depth */
  615. u32 hw_queue_depth;
  616. /* Max supported virtual queue depth */
  617. u32 queue_depth;
  618. /* From include/linux/blkdev.h for the other HW/SW limits. */
  619. struct queue_limits limits;
  620. } ____cacheline_aligned;
  621. struct se_dev_attrib {
  622. int emulate_dpo;
  623. int emulate_fua_write;
  624. int emulate_fua_read;
  625. int emulate_write_cache;
  626. int emulate_ua_intlck_ctrl;
  627. int emulate_tas;
  628. int emulate_tpu;
  629. int emulate_tpws;
  630. int emulate_reservations;
  631. int emulate_alua;
  632. int enforce_pr_isids;
  633. u32 hw_block_size;
  634. u32 block_size;
  635. u32 hw_max_sectors;
  636. u32 max_sectors;
  637. u32 optimal_sectors;
  638. u32 hw_queue_depth;
  639. u32 queue_depth;
  640. u32 task_timeout;
  641. u32 max_unmap_lba_count;
  642. u32 max_unmap_block_desc_count;
  643. u32 unmap_granularity;
  644. u32 unmap_granularity_alignment;
  645. struct se_subsystem_dev *da_sub_dev;
  646. struct config_group da_group;
  647. } ____cacheline_aligned;
  648. struct se_subsystem_dev {
  649. /* Used for struct se_subsystem_dev-->se_dev_alias, must be less than PAGE_SIZE */
  650. #define SE_DEV_ALIAS_LEN 512
  651. unsigned char se_dev_alias[SE_DEV_ALIAS_LEN];
  652. /* Used for struct se_subsystem_dev->se_dev_udev_path[], must be less than PAGE_SIZE */
  653. #define SE_UDEV_PATH_LEN 512
  654. unsigned char se_dev_udev_path[SE_UDEV_PATH_LEN];
  655. u32 su_dev_flags;
  656. struct se_hba *se_dev_hba;
  657. struct se_device *se_dev_ptr;
  658. struct se_dev_attrib se_dev_attrib;
  659. /* T10 Asymmetric Logical Unit Assignment for Target Ports */
  660. struct t10_alua t10_alua;
  661. /* T10 Inquiry and VPD WWN Information */
  662. struct t10_wwn t10_wwn;
  663. /* T10 SPC-2 + SPC-3 Reservations */
  664. struct t10_reservation_template t10_reservation;
  665. spinlock_t se_dev_lock;
  666. void *se_dev_su_ptr;
  667. struct list_head g_se_dev_list;
  668. struct config_group se_dev_group;
  669. /* For T10 Reservations */
  670. struct config_group se_dev_pr_group;
  671. } ____cacheline_aligned;
  672. #define T10_ALUA(su_dev) (&(su_dev)->t10_alua)
  673. #define T10_RES(su_dev) (&(su_dev)->t10_reservation)
  674. #define T10_PR_OPS(su_dev) (&(su_dev)->t10_reservation.pr_ops)
  675. struct se_device {
  676. /* Set to 1 if thread is NOT sleeping on thread_sem */
  677. u8 thread_active;
  678. u8 dev_status_timer_flags;
  679. /* RELATIVE TARGET PORT IDENTIFER Counter */
  680. u16 dev_rpti_counter;
  681. /* Used for SAM Task Attribute ordering */
  682. u32 dev_cur_ordered_id;
  683. u32 dev_flags;
  684. u32 dev_port_count;
  685. /* See transport_device_status_table */
  686. u32 dev_status;
  687. u32 dev_tcq_window_closed;
  688. /* Physical device queue depth */
  689. u32 queue_depth;
  690. /* Used for SPC-2 reservations enforce of ISIDs */
  691. u64 dev_res_bin_isid;
  692. t10_task_attr_index_t dev_task_attr_type;
  693. /* Pointer to transport specific device structure */
  694. void *dev_ptr;
  695. u32 dev_index;
  696. u64 creation_time;
  697. u32 num_resets;
  698. u64 num_cmds;
  699. u64 read_bytes;
  700. u64 write_bytes;
  701. spinlock_t stats_lock;
  702. /* Active commands on this virtual SE device */
  703. atomic_t active_cmds;
  704. atomic_t simple_cmds;
  705. atomic_t depth_left;
  706. atomic_t dev_ordered_id;
  707. atomic_t dev_tur_active;
  708. atomic_t execute_tasks;
  709. atomic_t dev_status_thr_count;
  710. atomic_t dev_hoq_count;
  711. atomic_t dev_ordered_sync;
  712. struct se_obj dev_obj;
  713. struct se_obj dev_access_obj;
  714. struct se_obj dev_export_obj;
  715. struct se_queue_obj *dev_queue_obj;
  716. struct se_queue_obj *dev_status_queue_obj;
  717. spinlock_t delayed_cmd_lock;
  718. spinlock_t ordered_cmd_lock;
  719. spinlock_t execute_task_lock;
  720. spinlock_t state_task_lock;
  721. spinlock_t dev_alua_lock;
  722. spinlock_t dev_reservation_lock;
  723. spinlock_t dev_state_lock;
  724. spinlock_t dev_status_lock;
  725. spinlock_t dev_status_thr_lock;
  726. spinlock_t se_port_lock;
  727. spinlock_t se_tmr_lock;
  728. /* Used for legacy SPC-2 reservationsa */
  729. struct se_node_acl *dev_reserved_node_acl;
  730. /* Used for ALUA Logical Unit Group membership */
  731. struct t10_alua_lu_gp_member *dev_alua_lu_gp_mem;
  732. /* Used for SPC-3 Persistent Reservations */
  733. struct t10_pr_registration *dev_pr_res_holder;
  734. struct list_head dev_sep_list;
  735. struct list_head dev_tmr_list;
  736. struct timer_list dev_status_timer;
  737. /* Pointer to descriptor for processing thread */
  738. struct task_struct *process_thread;
  739. pid_t process_thread_pid;
  740. struct task_struct *dev_mgmt_thread;
  741. struct list_head delayed_cmd_list;
  742. struct list_head ordered_cmd_list;
  743. struct list_head execute_task_list;
  744. struct list_head state_task_list;
  745. /* Pointer to associated SE HBA */
  746. struct se_hba *se_hba;
  747. struct se_subsystem_dev *se_sub_dev;
  748. /* Pointer to template of function pointers for transport */
  749. struct se_subsystem_api *transport;
  750. /* Linked list for struct se_hba struct se_device list */
  751. struct list_head dev_list;
  752. /* Linked list for struct se_global->g_se_dev_list */
  753. struct list_head g_se_dev_list;
  754. } ____cacheline_aligned;
  755. #define SE_DEV(cmd) ((struct se_device *)(cmd)->se_lun->lun_se_dev)
  756. #define SU_DEV(dev) ((struct se_subsystem_dev *)(dev)->se_sub_dev)
  757. #define DEV_ATTRIB(dev) (&(dev)->se_sub_dev->se_dev_attrib)
  758. #define DEV_T10_WWN(dev) (&(dev)->se_sub_dev->t10_wwn)
  759. struct se_hba {
  760. u16 hba_tpgt;
  761. u32 hba_id;
  762. /* See hba_flags_table */
  763. u32 hba_flags;
  764. /* Virtual iSCSI devices attached. */
  765. u32 dev_count;
  766. u32 hba_index;
  767. atomic_t load_balance_queue;
  768. atomic_t left_queue_depth;
  769. /* Maximum queue depth the HBA can handle. */
  770. atomic_t max_queue_depth;
  771. /* Pointer to transport specific host structure. */
  772. void *hba_ptr;
  773. /* Linked list for struct se_device */
  774. struct list_head hba_dev_list;
  775. struct list_head hba_list;
  776. spinlock_t device_lock;
  777. spinlock_t hba_queue_lock;
  778. struct config_group hba_group;
  779. struct mutex hba_access_mutex;
  780. struct se_subsystem_api *transport;
  781. } ____cacheline_aligned;
  782. #define SE_HBA(d) ((struct se_hba *)(d)->se_hba)
  783. struct se_lun {
  784. /* See transport_lun_status_table */
  785. enum transport_lun_status_table lun_status;
  786. u32 lun_access;
  787. u32 lun_flags;
  788. u32 unpacked_lun;
  789. atomic_t lun_acl_count;
  790. spinlock_t lun_acl_lock;
  791. spinlock_t lun_cmd_lock;
  792. spinlock_t lun_sep_lock;
  793. struct completion lun_shutdown_comp;
  794. struct list_head lun_cmd_list;
  795. struct list_head lun_acl_list;
  796. struct se_device *lun_se_dev;
  797. struct config_group lun_group;
  798. struct se_port *lun_sep;
  799. } ____cacheline_aligned;
  800. #define SE_LUN(c) ((struct se_lun *)(c)->se_lun)
  801. struct scsi_port_stats {
  802. u64 cmd_pdus;
  803. u64 tx_data_octets;
  804. u64 rx_data_octets;
  805. } ____cacheline_aligned;
  806. struct se_port {
  807. /* RELATIVE TARGET PORT IDENTIFER */
  808. u16 sep_rtpi;
  809. int sep_tg_pt_secondary_stat;
  810. int sep_tg_pt_secondary_write_md;
  811. u32 sep_index;
  812. struct scsi_port_stats sep_stats;
  813. /* Used for ALUA Target Port Groups membership */
  814. atomic_t sep_tg_pt_gp_active;
  815. atomic_t sep_tg_pt_secondary_offline;
  816. /* Used for PR ALL_TG_PT=1 */
  817. atomic_t sep_tg_pt_ref_cnt;
  818. spinlock_t sep_alua_lock;
  819. struct mutex sep_tg_pt_md_mutex;
  820. struct t10_alua_tg_pt_gp_member *sep_alua_tg_pt_gp_mem;
  821. struct se_lun *sep_lun;
  822. struct se_portal_group *sep_tpg;
  823. struct list_head sep_alua_list;
  824. struct list_head sep_list;
  825. } ____cacheline_aligned;
  826. struct se_tpg_np {
  827. struct se_portal_group *tpg_np_parent;
  828. struct config_group tpg_np_group;
  829. } ____cacheline_aligned;
  830. struct se_portal_group {
  831. /* Type of target portal group, see transport_tpg_type_table */
  832. enum transport_tpg_type_table se_tpg_type;
  833. /* Number of ACLed Initiator Nodes for this TPG */
  834. u32 num_node_acls;
  835. /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
  836. atomic_t tpg_pr_ref_count;
  837. /* Spinlock for adding/removing ACLed Nodes */
  838. spinlock_t acl_node_lock;
  839. /* Spinlock for adding/removing sessions */
  840. spinlock_t session_lock;
  841. spinlock_t tpg_lun_lock;
  842. /* Pointer to $FABRIC_MOD portal group */
  843. void *se_tpg_fabric_ptr;
  844. struct list_head se_tpg_list;
  845. /* linked list for initiator ACL list */
  846. struct list_head acl_node_list;
  847. struct se_lun *tpg_lun_list;
  848. struct se_lun tpg_virt_lun0;
  849. /* List of TCM sessions assoicated wth this TPG */
  850. struct list_head tpg_sess_list;
  851. /* Pointer to $FABRIC_MOD dependent code */
  852. struct target_core_fabric_ops *se_tpg_tfo;
  853. struct se_wwn *se_tpg_wwn;
  854. struct config_group tpg_group;
  855. struct config_group *tpg_default_groups[6];
  856. struct config_group tpg_lun_group;
  857. struct config_group tpg_np_group;
  858. struct config_group tpg_acl_group;
  859. struct config_group tpg_attrib_group;
  860. struct config_group tpg_param_group;
  861. } ____cacheline_aligned;
  862. #define TPG_TFO(se_tpg) ((struct target_core_fabric_ops *)(se_tpg)->se_tpg_tfo)
  863. struct se_wwn {
  864. struct target_fabric_configfs *wwn_tf;
  865. struct config_group wwn_group;
  866. } ____cacheline_aligned;
  867. struct se_global {
  868. u16 alua_lu_gps_counter;
  869. int g_sub_api_initialized;
  870. u32 in_shutdown;
  871. u32 alua_lu_gps_count;
  872. u32 g_hba_id_counter;
  873. struct config_group target_core_hbagroup;
  874. struct config_group alua_group;
  875. struct config_group alua_lu_gps_group;
  876. struct list_head g_lu_gps_list;
  877. struct list_head g_se_tpg_list;
  878. struct list_head g_hba_list;
  879. struct list_head g_se_dev_list;
  880. struct se_hba *g_lun0_hba;
  881. struct se_subsystem_dev *g_lun0_su_dev;
  882. struct se_device *g_lun0_dev;
  883. struct t10_alua_lu_gp *default_lu_gp;
  884. spinlock_t g_device_lock;
  885. spinlock_t hba_lock;
  886. spinlock_t se_tpg_lock;
  887. spinlock_t lu_gps_lock;
  888. spinlock_t plugin_class_lock;
  889. } ____cacheline_aligned;
  890. #endif /* TARGET_CORE_BASE_H */