target_core_base.h 27 KB

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