target_core_base.h 28 KB

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