target_core_base.h 27 KB

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