target_core_base.h 28 KB

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