target_core_base.h 29 KB

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