target_core_base.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef TARGET_CORE_BASE_H
  3. #define TARGET_CORE_BASE_H
  4. #include <linux/configfs.h> /* struct config_group */
  5. #include <linux/dma-direction.h> /* enum dma_data_direction */
  6. #include <linux/sbitmap.h>
  7. #include <linux/percpu-refcount.h>
  8. #include <linux/semaphore.h> /* struct semaphore */
  9. #include <linux/completion.h>
  10. #define TARGET_CORE_VERSION "v5.0"
  11. /*
  12. * Maximum size of a CDB that can be stored in se_cmd without allocating
  13. * memory dynamically for the CDB.
  14. */
  15. #define TCM_MAX_COMMAND_SIZE 32
  16. /*
  17. * From include/scsi/scsi_cmnd.h:SCSI_SENSE_BUFFERSIZE, currently
  18. * defined 96, but the real limit is 252 (or 260 including the header)
  19. */
  20. #define TRANSPORT_SENSE_BUFFER 96
  21. /* Used by transport_send_check_condition_and_sense() */
  22. #define SPC_SENSE_KEY_OFFSET 2
  23. #define SPC_ADD_SENSE_LEN_OFFSET 7
  24. #define SPC_DESC_TYPE_OFFSET 8
  25. #define SPC_ADDITIONAL_DESC_LEN_OFFSET 9
  26. #define SPC_VALIDITY_OFFSET 10
  27. #define SPC_ASC_KEY_OFFSET 12
  28. #define SPC_ASCQ_KEY_OFFSET 13
  29. #define TRANSPORT_IQN_LEN 224
  30. /* Used by target_core_store_alua_lu_gp() and target_core_alua_lu_gp_show_attr_members() */
  31. #define LU_GROUP_NAME_BUF 256
  32. /* Used by core_alua_store_tg_pt_gp_info() and target_core_alua_tg_pt_gp_show_attr_members() */
  33. #define TG_PT_GROUP_NAME_BUF 256
  34. /* Used to parse VPD into struct t10_vpd */
  35. #define VPD_TMP_BUF_SIZE 254
  36. /* Used by transport_generic_cmd_sequencer() */
  37. #define READ_BLOCK_LEN 6
  38. #define READ_CAP_LEN 8
  39. #define READ_POSITION_LEN 20
  40. #define INQUIRY_LEN 36
  41. /* Used by transport_get_inquiry_vpd_serial() */
  42. #define INQUIRY_VPD_SERIAL_LEN 254
  43. /* Used by transport_get_inquiry_vpd_device_ident() */
  44. #define INQUIRY_VPD_DEVICE_IDENTIFIER_LEN 254
  45. #define INQUIRY_VENDOR_LEN 8
  46. #define INQUIRY_MODEL_LEN 16
  47. #define INQUIRY_REVISION_LEN 4
  48. /* Attempts before moving from SHORT to LONG */
  49. #define PYX_TRANSPORT_WINDOW_CLOSED_THRESHOLD 3
  50. #define PYX_TRANSPORT_WINDOW_CLOSED_WAIT_SHORT 3 /* In milliseconds */
  51. #define PYX_TRANSPORT_WINDOW_CLOSED_WAIT_LONG 10 /* In milliseconds */
  52. #define PYX_TRANSPORT_STATUS_INTERVAL 5 /* In seconds */
  53. /* struct se_dev_attrib sanity values */
  54. /* Default max_unmap_lba_count */
  55. #define DA_MAX_UNMAP_LBA_COUNT 0
  56. /* Default max_unmap_block_desc_count */
  57. #define DA_MAX_UNMAP_BLOCK_DESC_COUNT 0
  58. /* Default unmap_granularity */
  59. #define DA_UNMAP_GRANULARITY_DEFAULT 0
  60. /* Default unmap_granularity_alignment */
  61. #define DA_UNMAP_GRANULARITY_ALIGNMENT_DEFAULT 0
  62. /* Default unmap_zeroes_data */
  63. #define DA_UNMAP_ZEROES_DATA_DEFAULT 0
  64. /* Default max_write_same_len, disabled by default */
  65. #define DA_MAX_WRITE_SAME_LEN 0
  66. /* Use a model alias based on the configfs backend device name */
  67. #define DA_EMULATE_MODEL_ALIAS 0
  68. /* Emulation for WriteCache and SYNCHRONIZE_CACHE */
  69. #define DA_EMULATE_WRITE_CACHE 0
  70. /* Emulation for TASK_ABORTED status (TAS) by default */
  71. #define DA_EMULATE_TAS 1
  72. /* Emulation for Thin Provisioning UNMAP using block/blk-lib.c:blkdev_issue_discard() */
  73. #define DA_EMULATE_TPU 0
  74. /*
  75. * Emulation for Thin Provisioning WRITE_SAME w/ UNMAP=1 bit using
  76. * block/blk-lib.c:blkdev_issue_discard()
  77. */
  78. #define DA_EMULATE_TPWS 0
  79. /* Emulation for CompareAndWrite (AtomicTestandSet) by default */
  80. #define DA_EMULATE_CAW 1
  81. /* Emulation for 3rd Party Copy (ExtendedCopy) by default */
  82. #define DA_EMULATE_3PC 1
  83. /* No Emulation for PSCSI by default */
  84. #define DA_EMULATE_ALUA 0
  85. /* Emulate SCSI2 RESERVE/RELEASE and Persistent Reservations by default */
  86. #define DA_EMULATE_PR 1
  87. /* Enforce SCSI Initiator Port TransportID with 'ISID' for PR */
  88. #define DA_ENFORCE_PR_ISIDS 1
  89. /* Force SPC-3 PR Activate Persistence across Target Power Loss */
  90. #define DA_FORCE_PR_APTPL 0
  91. #define DA_STATUS_MAX_SECTORS_MIN 16
  92. #define DA_STATUS_MAX_SECTORS_MAX 8192
  93. /* By default don't report non-rotating (solid state) medium */
  94. #define DA_IS_NONROT 0
  95. /* Queue Algorithm Modifier default for restricted reordering in control mode page */
  96. #define DA_EMULATE_REST_REORD 0
  97. #define SE_INQUIRY_BUF 1024
  98. #define SE_MODE_PAGE_BUF 512
  99. #define SE_SENSE_BUF 96
  100. /* struct se_hba->hba_flags */
  101. enum hba_flags_table {
  102. HBA_FLAGS_INTERNAL_USE = 0x01,
  103. HBA_FLAGS_PSCSI_MODE = 0x02,
  104. };
  105. /* Special transport agnostic struct se_cmd->t_states */
  106. enum transport_state_table {
  107. TRANSPORT_NO_STATE = 0,
  108. TRANSPORT_NEW_CMD = 1,
  109. TRANSPORT_WRITE_PENDING = 3,
  110. TRANSPORT_PROCESSING = 5,
  111. TRANSPORT_COMPLETE = 6,
  112. TRANSPORT_ISTATE_PROCESSING = 11,
  113. TRANSPORT_COMPLETE_QF_WP = 18,
  114. TRANSPORT_COMPLETE_QF_OK = 19,
  115. TRANSPORT_COMPLETE_QF_ERR = 20,
  116. };
  117. /* Used for struct se_cmd->se_cmd_flags */
  118. enum se_cmd_flags_table {
  119. SCF_SUPPORTED_SAM_OPCODE = 0x00000001,
  120. SCF_TRANSPORT_TASK_SENSE = 0x00000002,
  121. SCF_EMULATED_TASK_SENSE = 0x00000004,
  122. SCF_SCSI_DATA_CDB = 0x00000008,
  123. SCF_SCSI_TMR_CDB = 0x00000010,
  124. SCF_FUA = 0x00000080,
  125. SCF_SE_LUN_CMD = 0x00000100,
  126. SCF_BIDI = 0x00000400,
  127. SCF_SENT_CHECK_CONDITION = 0x00000800,
  128. SCF_OVERFLOW_BIT = 0x00001000,
  129. SCF_UNDERFLOW_BIT = 0x00002000,
  130. SCF_ALUA_NON_OPTIMIZED = 0x00008000,
  131. SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC = 0x00020000,
  132. SCF_COMPARE_AND_WRITE = 0x00080000,
  133. SCF_PASSTHROUGH_PROT_SG_TO_MEM_NOALLOC = 0x00200000,
  134. SCF_ACK_KREF = 0x00400000,
  135. SCF_USE_CPUID = 0x00800000,
  136. SCF_TASK_ATTR_SET = 0x01000000,
  137. SCF_TREAT_READ_AS_NORMAL = 0x02000000,
  138. };
  139. /*
  140. * Used by transport_send_check_condition_and_sense()
  141. * to signal which ASC/ASCQ sense payload should be built.
  142. */
  143. typedef unsigned __bitwise sense_reason_t;
  144. enum tcm_sense_reason_table {
  145. #define R(x) (__force sense_reason_t )(x)
  146. TCM_NO_SENSE = R(0x00),
  147. TCM_NON_EXISTENT_LUN = R(0x01),
  148. TCM_UNSUPPORTED_SCSI_OPCODE = R(0x02),
  149. TCM_INCORRECT_AMOUNT_OF_DATA = R(0x03),
  150. TCM_UNEXPECTED_UNSOLICITED_DATA = R(0x04),
  151. TCM_SERVICE_CRC_ERROR = R(0x05),
  152. TCM_SNACK_REJECTED = R(0x06),
  153. TCM_SECTOR_COUNT_TOO_MANY = R(0x07),
  154. TCM_INVALID_CDB_FIELD = R(0x08),
  155. TCM_INVALID_PARAMETER_LIST = R(0x09),
  156. TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE = R(0x0a),
  157. TCM_UNKNOWN_MODE_PAGE = R(0x0b),
  158. TCM_WRITE_PROTECTED = R(0x0c),
  159. TCM_CHECK_CONDITION_ABORT_CMD = R(0x0d),
  160. TCM_CHECK_CONDITION_UNIT_ATTENTION = R(0x0e),
  161. TCM_CHECK_CONDITION_NOT_READY = R(0x0f),
  162. TCM_RESERVATION_CONFLICT = R(0x10),
  163. TCM_ADDRESS_OUT_OF_RANGE = R(0x11),
  164. TCM_OUT_OF_RESOURCES = R(0x12),
  165. TCM_PARAMETER_LIST_LENGTH_ERROR = R(0x13),
  166. TCM_MISCOMPARE_VERIFY = R(0x14),
  167. TCM_LOGICAL_BLOCK_GUARD_CHECK_FAILED = R(0x15),
  168. TCM_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED = R(0x16),
  169. TCM_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED = R(0x17),
  170. TCM_COPY_TARGET_DEVICE_NOT_REACHABLE = R(0x18),
  171. TCM_TOO_MANY_TARGET_DESCS = R(0x19),
  172. TCM_UNSUPPORTED_TARGET_DESC_TYPE_CODE = R(0x1a),
  173. TCM_TOO_MANY_SEGMENT_DESCS = R(0x1b),
  174. TCM_UNSUPPORTED_SEGMENT_DESC_TYPE_CODE = R(0x1c),
  175. TCM_INSUFFICIENT_REGISTRATION_RESOURCES = R(0x1d),
  176. TCM_LUN_BUSY = R(0x1e),
  177. #undef R
  178. };
  179. enum target_sc_flags_table {
  180. TARGET_SCF_BIDI_OP = 0x01,
  181. TARGET_SCF_ACK_KREF = 0x02,
  182. TARGET_SCF_UNKNOWN_SIZE = 0x04,
  183. TARGET_SCF_USE_CPUID = 0x08,
  184. TARGET_SCF_LOOKUP_LUN_FROM_TAG = 0x10,
  185. };
  186. /* fabric independent task management function values */
  187. enum tcm_tmreq_table {
  188. TMR_ABORT_TASK = 1,
  189. TMR_ABORT_TASK_SET = 2,
  190. TMR_CLEAR_ACA = 3,
  191. TMR_CLEAR_TASK_SET = 4,
  192. TMR_LUN_RESET = 5,
  193. TMR_TARGET_WARM_RESET = 6,
  194. TMR_TARGET_COLD_RESET = 7,
  195. TMR_LUN_RESET_PRO = 0x80,
  196. TMR_UNKNOWN = 0xff,
  197. };
  198. /* fabric independent task management response values */
  199. enum tcm_tmrsp_table {
  200. TMR_FUNCTION_FAILED = 0,
  201. TMR_FUNCTION_COMPLETE = 1,
  202. TMR_TASK_DOES_NOT_EXIST = 2,
  203. TMR_LUN_DOES_NOT_EXIST = 3,
  204. TMR_TASK_MGMT_FUNCTION_NOT_SUPPORTED = 4,
  205. TMR_FUNCTION_REJECTED = 5,
  206. };
  207. /*
  208. * Used for target SCSI statistics
  209. */
  210. typedef enum {
  211. SCSI_INST_INDEX,
  212. SCSI_AUTH_INTR_INDEX,
  213. SCSI_INDEX_TYPE_MAX
  214. } scsi_index_t;
  215. struct se_cmd;
  216. struct t10_alua_lba_map_member {
  217. struct list_head lba_map_mem_list;
  218. int lba_map_mem_alua_state;
  219. int lba_map_mem_alua_pg_id;
  220. };
  221. struct t10_alua_lba_map {
  222. u64 lba_map_first_lba;
  223. u64 lba_map_last_lba;
  224. struct list_head lba_map_list;
  225. struct list_head lba_map_mem_list;
  226. };
  227. struct t10_alua {
  228. /* ALUA Target Port Group ID */
  229. u16 alua_tg_pt_gps_counter;
  230. u32 alua_tg_pt_gps_count;
  231. /* Referrals support */
  232. spinlock_t lba_map_lock;
  233. u32 lba_map_segment_size;
  234. u32 lba_map_segment_multiplier;
  235. struct list_head lba_map_list;
  236. spinlock_t tg_pt_gps_lock;
  237. struct se_device *t10_dev;
  238. /* Used for default ALUA Target Port Group */
  239. struct t10_alua_tg_pt_gp *default_tg_pt_gp;
  240. /* Used for default ALUA Target Port Group ConfigFS group */
  241. struct config_group alua_tg_pt_gps_group;
  242. struct list_head tg_pt_gps_list;
  243. };
  244. struct t10_alua_lu_gp {
  245. u16 lu_gp_id;
  246. int lu_gp_valid_id;
  247. u32 lu_gp_members;
  248. atomic_t lu_gp_ref_cnt;
  249. spinlock_t lu_gp_lock;
  250. struct config_group lu_gp_group;
  251. struct list_head lu_gp_node;
  252. struct list_head lu_gp_mem_list;
  253. };
  254. struct t10_alua_lu_gp_member {
  255. bool lu_gp_assoc;
  256. atomic_t lu_gp_mem_ref_cnt;
  257. spinlock_t lu_gp_mem_lock;
  258. struct t10_alua_lu_gp *lu_gp;
  259. struct se_device *lu_gp_mem_dev;
  260. struct list_head lu_gp_mem_list;
  261. };
  262. struct t10_alua_tg_pt_gp {
  263. u16 tg_pt_gp_id;
  264. int tg_pt_gp_valid_id;
  265. int tg_pt_gp_alua_supported_states;
  266. int tg_pt_gp_alua_access_status;
  267. int tg_pt_gp_alua_access_type;
  268. int tg_pt_gp_nonop_delay_msecs;
  269. int tg_pt_gp_trans_delay_msecs;
  270. int tg_pt_gp_implicit_trans_secs;
  271. int tg_pt_gp_pref;
  272. int tg_pt_gp_write_metadata;
  273. u32 tg_pt_gp_members;
  274. int tg_pt_gp_alua_access_state;
  275. atomic_t tg_pt_gp_ref_cnt;
  276. spinlock_t tg_pt_gp_lock;
  277. struct mutex tg_pt_gp_transition_mutex;
  278. struct se_device *tg_pt_gp_dev;
  279. struct config_group tg_pt_gp_group;
  280. struct list_head tg_pt_gp_list;
  281. struct list_head tg_pt_gp_lun_list;
  282. struct se_lun *tg_pt_gp_alua_lun;
  283. struct se_node_acl *tg_pt_gp_alua_nacl;
  284. };
  285. struct t10_vpd {
  286. unsigned char device_identifier[INQUIRY_VPD_DEVICE_IDENTIFIER_LEN];
  287. int protocol_identifier_set;
  288. u32 protocol_identifier;
  289. u32 device_identifier_code_set;
  290. u32 association;
  291. u32 device_identifier_type;
  292. struct list_head vpd_list;
  293. };
  294. struct t10_wwn {
  295. /*
  296. * SCSI left aligned strings may not be null terminated. +1 to ensure a
  297. * null terminator is always present.
  298. */
  299. char vendor[INQUIRY_VENDOR_LEN + 1];
  300. char model[INQUIRY_MODEL_LEN + 1];
  301. char revision[INQUIRY_REVISION_LEN + 1];
  302. char unit_serial[INQUIRY_VPD_SERIAL_LEN];
  303. spinlock_t t10_vpd_lock;
  304. struct se_device *t10_dev;
  305. struct config_group t10_wwn_group;
  306. struct list_head t10_vpd_list;
  307. };
  308. struct t10_pr_registration {
  309. /* Used for fabrics that contain WWN+ISID */
  310. #define PR_REG_ISID_LEN 16
  311. /* PR_REG_ISID_LEN + ',i,0x' */
  312. #define PR_REG_ISID_ID_LEN (PR_REG_ISID_LEN + 5)
  313. char pr_reg_isid[PR_REG_ISID_LEN];
  314. /* Used during APTPL metadata reading */
  315. #define PR_APTPL_MAX_IPORT_LEN 256
  316. unsigned char pr_iport[PR_APTPL_MAX_IPORT_LEN];
  317. /* Used during APTPL metadata reading */
  318. #define PR_APTPL_MAX_TPORT_LEN 256
  319. unsigned char pr_tport[PR_APTPL_MAX_TPORT_LEN];
  320. u16 pr_aptpl_rpti;
  321. u16 pr_reg_tpgt;
  322. /* Reservation effects all target ports */
  323. int pr_reg_all_tg_pt;
  324. /* Activate Persistence across Target Power Loss */
  325. int pr_reg_aptpl;
  326. int pr_res_holder;
  327. int pr_res_type;
  328. int pr_res_scope;
  329. /* Used for fabric initiator WWPNs using a ISID */
  330. bool isid_present_at_reg;
  331. u64 pr_res_mapped_lun;
  332. u64 pr_aptpl_target_lun;
  333. u16 tg_pt_sep_rtpi;
  334. u32 pr_res_generation;
  335. u64 pr_reg_bin_isid;
  336. u64 pr_res_key;
  337. atomic_t pr_res_holders;
  338. struct se_node_acl *pr_reg_nacl;
  339. /* Used by ALL_TG_PT=1 registration with deve->pr_ref taken */
  340. struct se_dev_entry *pr_reg_deve;
  341. struct list_head pr_reg_list;
  342. struct list_head pr_reg_abort_list;
  343. struct list_head pr_reg_aptpl_list;
  344. struct list_head pr_reg_atp_list;
  345. struct list_head pr_reg_atp_mem_list;
  346. };
  347. struct t10_reservation {
  348. /* Reservation effects all target ports */
  349. int pr_all_tg_pt;
  350. /* Activate Persistence across Target Power Loss enabled
  351. * for SCSI device */
  352. int pr_aptpl_active;
  353. #define PR_APTPL_BUF_LEN 262144
  354. u32 pr_generation;
  355. spinlock_t registration_lock;
  356. spinlock_t aptpl_reg_lock;
  357. /*
  358. * This will always be set by one individual I_T Nexus.
  359. * However with all_tg_pt=1, other I_T Nexus from the
  360. * same initiator can access PR reg/res info on a different
  361. * target port.
  362. *
  363. * There is also the 'All Registrants' case, where there is
  364. * a single *pr_res_holder of the reservation, but all
  365. * registrations are considered reservation holders.
  366. */
  367. struct se_node_acl *pr_res_holder;
  368. struct list_head registration_list;
  369. struct list_head aptpl_reg_list;
  370. };
  371. struct se_tmr_req {
  372. /* Task Management function to be performed */
  373. u8 function;
  374. /* Task Management response to send */
  375. u8 response;
  376. int call_transport;
  377. /* Reference to ITT that Task Mgmt should be performed */
  378. u64 ref_task_tag;
  379. void *fabric_tmr_ptr;
  380. struct se_cmd *task_cmd;
  381. struct se_device *tmr_dev;
  382. struct list_head tmr_list;
  383. };
  384. enum target_prot_op {
  385. TARGET_PROT_NORMAL = 0,
  386. TARGET_PROT_DIN_INSERT = (1 << 0),
  387. TARGET_PROT_DOUT_INSERT = (1 << 1),
  388. TARGET_PROT_DIN_STRIP = (1 << 2),
  389. TARGET_PROT_DOUT_STRIP = (1 << 3),
  390. TARGET_PROT_DIN_PASS = (1 << 4),
  391. TARGET_PROT_DOUT_PASS = (1 << 5),
  392. };
  393. #define TARGET_PROT_ALL TARGET_PROT_DIN_INSERT | TARGET_PROT_DOUT_INSERT | \
  394. TARGET_PROT_DIN_STRIP | TARGET_PROT_DOUT_STRIP | \
  395. TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS
  396. enum target_prot_type {
  397. TARGET_DIF_TYPE0_PROT,
  398. TARGET_DIF_TYPE1_PROT,
  399. TARGET_DIF_TYPE2_PROT,
  400. TARGET_DIF_TYPE3_PROT,
  401. };
  402. /* Emulation for UNIT ATTENTION Interlock Control */
  403. enum target_ua_intlck_ctrl {
  404. TARGET_UA_INTLCK_CTRL_CLEAR = 0,
  405. TARGET_UA_INTLCK_CTRL_NO_CLEAR = 1,
  406. TARGET_UA_INTLCK_CTRL_ESTABLISH_UA = 2,
  407. };
  408. enum target_core_dif_check {
  409. TARGET_DIF_CHECK_GUARD = 0x1 << 0,
  410. TARGET_DIF_CHECK_APPTAG = 0x1 << 1,
  411. TARGET_DIF_CHECK_REFTAG = 0x1 << 2,
  412. };
  413. /* for sam_task_attr */
  414. #define TCM_SIMPLE_TAG 0x20
  415. #define TCM_HEAD_TAG 0x21
  416. #define TCM_ORDERED_TAG 0x22
  417. #define TCM_ACA_TAG 0x24
  418. struct se_cmd {
  419. /* SAM response code being sent to initiator */
  420. u8 scsi_status;
  421. u8 scsi_asc;
  422. u8 scsi_ascq;
  423. u16 scsi_sense_length;
  424. unsigned unknown_data_length:1;
  425. bool state_active:1;
  426. u64 tag; /* SAM command identifier aka task tag */
  427. /* Delay for ALUA Active/NonOptimized state access in milliseconds */
  428. int alua_nonop_delay;
  429. /* See include/linux/dma-mapping.h */
  430. enum dma_data_direction data_direction;
  431. /* For SAM Task Attribute */
  432. int sam_task_attr;
  433. /* Used for se_sess->sess_tag_pool */
  434. unsigned int map_tag;
  435. int map_cpu;
  436. /* Transport protocol dependent state, see transport_state_table */
  437. enum transport_state_table t_state;
  438. /* See se_cmd_flags_table */
  439. u32 se_cmd_flags;
  440. /* Total size in bytes associated with command */
  441. u32 data_length;
  442. u32 residual_count;
  443. u64 orig_fe_lun;
  444. /* Persistent Reservation key */
  445. u64 pr_res_key;
  446. /* Used for sense data */
  447. void *sense_buffer;
  448. struct list_head se_delayed_node;
  449. struct list_head se_qf_node;
  450. struct se_device *se_dev;
  451. struct se_lun *se_lun;
  452. /* Only used for internal passthrough and legacy TCM fabric modules */
  453. struct se_session *se_sess;
  454. struct se_tmr_req *se_tmr_req;
  455. struct list_head se_cmd_list;
  456. struct completion *free_compl;
  457. struct completion *abrt_compl;
  458. const struct target_core_fabric_ops *se_tfo;
  459. sense_reason_t (*execute_cmd)(struct se_cmd *);
  460. sense_reason_t (*transport_complete_callback)(struct se_cmd *, bool, int *);
  461. void *protocol_data;
  462. unsigned char *t_task_cdb;
  463. unsigned char __t_task_cdb[TCM_MAX_COMMAND_SIZE];
  464. unsigned long long t_task_lba;
  465. unsigned int t_task_nolb;
  466. unsigned int transport_state;
  467. #define CMD_T_ABORTED (1 << 0)
  468. #define CMD_T_ACTIVE (1 << 1)
  469. #define CMD_T_COMPLETE (1 << 2)
  470. #define CMD_T_SENT (1 << 4)
  471. #define CMD_T_STOP (1 << 5)
  472. #define CMD_T_TAS (1 << 10)
  473. #define CMD_T_FABRIC_STOP (1 << 11)
  474. spinlock_t t_state_lock;
  475. struct kref cmd_kref;
  476. struct completion t_transport_stop_comp;
  477. struct work_struct work;
  478. struct scatterlist *t_data_sg;
  479. struct scatterlist *t_data_sg_orig;
  480. unsigned int t_data_nents;
  481. unsigned int t_data_nents_orig;
  482. void *t_data_vmap;
  483. struct scatterlist *t_bidi_data_sg;
  484. unsigned int t_bidi_data_nents;
  485. /* Used for lun->lun_ref counting */
  486. int lun_ref_active;
  487. struct list_head state_list;
  488. /* backend private data */
  489. void *priv;
  490. /* DIF related members */
  491. enum target_prot_op prot_op;
  492. enum target_prot_type prot_type;
  493. u8 prot_checks;
  494. bool prot_pto;
  495. u32 prot_length;
  496. u32 reftag_seed;
  497. struct scatterlist *t_prot_sg;
  498. unsigned int t_prot_nents;
  499. sense_reason_t pi_err;
  500. sector_t bad_sector;
  501. int cpuid;
  502. };
  503. struct se_ua {
  504. u8 ua_asc;
  505. u8 ua_ascq;
  506. struct list_head ua_nacl_list;
  507. };
  508. struct se_node_acl {
  509. char initiatorname[TRANSPORT_IQN_LEN];
  510. /* Used to signal demo mode created ACL, disabled by default */
  511. bool dynamic_node_acl;
  512. bool dynamic_stop;
  513. u32 queue_depth;
  514. u32 acl_index;
  515. enum target_prot_type saved_prot_type;
  516. #define MAX_ACL_TAG_SIZE 64
  517. char acl_tag[MAX_ACL_TAG_SIZE];
  518. /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
  519. atomic_t acl_pr_ref_count;
  520. struct hlist_head lun_entry_hlist;
  521. struct se_session *nacl_sess;
  522. struct se_portal_group *se_tpg;
  523. struct mutex lun_entry_mutex;
  524. spinlock_t nacl_sess_lock;
  525. struct config_group acl_group;
  526. struct config_group acl_attrib_group;
  527. struct config_group acl_auth_group;
  528. struct config_group acl_param_group;
  529. struct config_group acl_fabric_stat_group;
  530. struct list_head acl_list;
  531. struct list_head acl_sess_list;
  532. struct completion acl_free_comp;
  533. struct kref acl_kref;
  534. };
  535. static inline struct se_node_acl *acl_to_nacl(struct config_item *item)
  536. {
  537. return container_of(to_config_group(item), struct se_node_acl,
  538. acl_group);
  539. }
  540. static inline struct se_node_acl *attrib_to_nacl(struct config_item *item)
  541. {
  542. return container_of(to_config_group(item), struct se_node_acl,
  543. acl_attrib_group);
  544. }
  545. static inline struct se_node_acl *auth_to_nacl(struct config_item *item)
  546. {
  547. return container_of(to_config_group(item), struct se_node_acl,
  548. acl_auth_group);
  549. }
  550. static inline struct se_node_acl *param_to_nacl(struct config_item *item)
  551. {
  552. return container_of(to_config_group(item), struct se_node_acl,
  553. acl_param_group);
  554. }
  555. static inline struct se_node_acl *fabric_stat_to_nacl(struct config_item *item)
  556. {
  557. return container_of(to_config_group(item), struct se_node_acl,
  558. acl_fabric_stat_group);
  559. }
  560. struct se_session {
  561. unsigned sess_tearing_down:1;
  562. u64 sess_bin_isid;
  563. enum target_prot_op sup_prot_ops;
  564. enum target_prot_type sess_prot_type;
  565. struct se_node_acl *se_node_acl;
  566. struct se_portal_group *se_tpg;
  567. void *fabric_sess_ptr;
  568. struct percpu_ref cmd_count;
  569. struct list_head sess_list;
  570. struct list_head sess_acl_list;
  571. struct list_head sess_cmd_list;
  572. spinlock_t sess_cmd_lock;
  573. wait_queue_head_t cmd_list_wq;
  574. void *sess_cmd_map;
  575. struct sbitmap_queue sess_tag_pool;
  576. };
  577. struct se_device;
  578. struct se_transform_info;
  579. struct scatterlist;
  580. struct se_ml_stat_grps {
  581. struct config_group stat_group;
  582. struct config_group scsi_auth_intr_group;
  583. struct config_group scsi_att_intr_port_group;
  584. };
  585. struct se_lun_acl {
  586. u64 mapped_lun;
  587. struct se_node_acl *se_lun_nacl;
  588. struct se_lun *se_lun;
  589. struct config_group se_lun_group;
  590. struct se_ml_stat_grps ml_stat_grps;
  591. };
  592. struct se_dev_entry {
  593. u64 mapped_lun;
  594. u64 pr_res_key;
  595. u64 creation_time;
  596. bool lun_access_ro;
  597. u32 attach_count;
  598. atomic_long_t total_cmds;
  599. atomic_long_t read_bytes;
  600. atomic_long_t write_bytes;
  601. /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
  602. struct kref pr_kref;
  603. struct completion pr_comp;
  604. struct se_lun_acl __rcu *se_lun_acl;
  605. spinlock_t ua_lock;
  606. struct se_lun __rcu *se_lun;
  607. #define DEF_PR_REG_ACTIVE 1
  608. unsigned long deve_flags;
  609. struct list_head alua_port_list;
  610. struct list_head lun_link;
  611. struct list_head ua_list;
  612. struct hlist_node link;
  613. struct rcu_head rcu_head;
  614. };
  615. struct se_dev_attrib {
  616. bool emulate_model_alias;
  617. bool emulate_dpo; /* deprecated */
  618. bool emulate_fua_write;
  619. bool emulate_fua_read; /* deprecated */
  620. bool emulate_write_cache;
  621. enum target_ua_intlck_ctrl emulate_ua_intlck_ctrl;
  622. bool emulate_tas;
  623. bool emulate_tpu;
  624. bool emulate_tpws;
  625. bool emulate_caw;
  626. bool emulate_3pc;
  627. bool emulate_pr;
  628. enum target_prot_type pi_prot_type;
  629. enum target_prot_type hw_pi_prot_type;
  630. bool pi_prot_verify;
  631. bool enforce_pr_isids;
  632. bool force_pr_aptpl;
  633. bool is_nonrot;
  634. bool emulate_rest_reord;
  635. bool unmap_zeroes_data;
  636. u32 hw_block_size;
  637. u32 block_size;
  638. u32 hw_max_sectors;
  639. u32 optimal_sectors;
  640. u32 hw_queue_depth;
  641. u32 queue_depth;
  642. u32 max_unmap_lba_count;
  643. u32 max_unmap_block_desc_count;
  644. u32 unmap_granularity;
  645. u32 unmap_granularity_alignment;
  646. u32 max_write_same_len;
  647. u32 max_bytes_per_io;
  648. struct se_device *da_dev;
  649. struct config_group da_group;
  650. };
  651. struct se_port_stat_grps {
  652. struct config_group stat_group;
  653. struct config_group scsi_port_group;
  654. struct config_group scsi_tgt_port_group;
  655. struct config_group scsi_transport_group;
  656. };
  657. struct scsi_port_stats {
  658. atomic_long_t cmd_pdus;
  659. atomic_long_t tx_data_octets;
  660. atomic_long_t rx_data_octets;
  661. };
  662. struct se_lun {
  663. u64 unpacked_lun;
  664. bool lun_shutdown;
  665. bool lun_access_ro;
  666. u32 lun_index;
  667. /* RELATIVE TARGET PORT IDENTIFER */
  668. u16 lun_rtpi;
  669. atomic_t lun_acl_count;
  670. struct se_device __rcu *lun_se_dev;
  671. struct list_head lun_deve_list;
  672. spinlock_t lun_deve_lock;
  673. /* ALUA state */
  674. int lun_tg_pt_secondary_stat;
  675. int lun_tg_pt_secondary_write_md;
  676. atomic_t lun_tg_pt_secondary_offline;
  677. struct mutex lun_tg_pt_md_mutex;
  678. /* ALUA target port group linkage */
  679. struct list_head lun_tg_pt_gp_link;
  680. struct t10_alua_tg_pt_gp *lun_tg_pt_gp;
  681. spinlock_t lun_tg_pt_gp_lock;
  682. struct se_portal_group *lun_tpg;
  683. struct scsi_port_stats lun_stats;
  684. struct config_group lun_group;
  685. struct se_port_stat_grps port_stat_grps;
  686. struct completion lun_shutdown_comp;
  687. struct percpu_ref lun_ref;
  688. struct list_head lun_dev_link;
  689. struct hlist_node link;
  690. struct rcu_head rcu_head;
  691. };
  692. struct se_dev_stat_grps {
  693. struct config_group stat_group;
  694. struct config_group scsi_dev_group;
  695. struct config_group scsi_tgt_dev_group;
  696. struct config_group scsi_lu_group;
  697. };
  698. struct se_device {
  699. /* RELATIVE TARGET PORT IDENTIFER Counter */
  700. u16 dev_rpti_counter;
  701. /* Used for SAM Task Attribute ordering */
  702. u32 dev_cur_ordered_id;
  703. u32 dev_flags;
  704. #define DF_CONFIGURED 0x00000001
  705. #define DF_FIRMWARE_VPD_UNIT_SERIAL 0x00000002
  706. #define DF_EMULATED_VPD_UNIT_SERIAL 0x00000004
  707. #define DF_USING_UDEV_PATH 0x00000008
  708. #define DF_USING_ALIAS 0x00000010
  709. #define DF_READ_ONLY 0x00000020
  710. u8 transport_flags;
  711. /* Physical device queue depth */
  712. u32 queue_depth;
  713. /* Used for SPC-2 reservations enforce of ISIDs */
  714. u64 dev_res_bin_isid;
  715. /* Pointer to transport specific device structure */
  716. u32 dev_index;
  717. u64 creation_time;
  718. atomic_long_t num_resets;
  719. atomic_long_t aborts_complete;
  720. atomic_long_t aborts_no_task;
  721. atomic_long_t num_cmds;
  722. atomic_long_t read_bytes;
  723. atomic_long_t write_bytes;
  724. /* Active commands on this virtual SE device */
  725. atomic_t non_ordered;
  726. bool ordered_sync_in_progress;
  727. atomic_t delayed_cmd_count;
  728. atomic_t dev_qf_count;
  729. u32 export_count;
  730. spinlock_t delayed_cmd_lock;
  731. spinlock_t execute_task_lock;
  732. spinlock_t dev_reservation_lock;
  733. unsigned int dev_reservation_flags;
  734. #define DRF_SPC2_RESERVATIONS 0x00000001
  735. #define DRF_SPC2_RESERVATIONS_WITH_ISID 0x00000002
  736. spinlock_t se_port_lock;
  737. spinlock_t se_tmr_lock;
  738. spinlock_t qf_cmd_lock;
  739. struct semaphore caw_sem;
  740. /* Used for legacy SPC-2 reservations */
  741. struct se_session *reservation_holder;
  742. /* Used for ALUA Logical Unit Group membership */
  743. struct t10_alua_lu_gp_member *dev_alua_lu_gp_mem;
  744. /* Used for SPC-3 Persistent Reservations */
  745. struct t10_pr_registration *dev_pr_res_holder;
  746. struct list_head dev_sep_list;
  747. struct list_head dev_tmr_list;
  748. struct work_struct qf_work_queue;
  749. struct work_struct delayed_cmd_work;
  750. struct list_head delayed_cmd_list;
  751. struct list_head state_list;
  752. struct list_head qf_cmd_list;
  753. /* Pointer to associated SE HBA */
  754. struct se_hba *se_hba;
  755. /* T10 Inquiry and VPD WWN Information */
  756. struct t10_wwn t10_wwn;
  757. /* T10 Asymmetric Logical Unit Assignment for Target Ports */
  758. struct t10_alua t10_alua;
  759. /* T10 SPC-2 + SPC-3 Reservations */
  760. struct t10_reservation t10_pr;
  761. struct se_dev_attrib dev_attrib;
  762. struct config_group dev_action_group;
  763. struct config_group dev_group;
  764. struct config_group dev_pr_group;
  765. struct se_dev_stat_grps dev_stat_grps;
  766. #define SE_DEV_ALIAS_LEN 512 /* must be less than PAGE_SIZE */
  767. unsigned char dev_alias[SE_DEV_ALIAS_LEN];
  768. #define SE_UDEV_PATH_LEN 512 /* must be less than PAGE_SIZE */
  769. unsigned char udev_path[SE_UDEV_PATH_LEN];
  770. /* Pointer to template of function pointers for transport */
  771. const struct target_backend_ops *transport;
  772. struct se_lun xcopy_lun;
  773. /* Protection Information */
  774. int prot_length;
  775. /* For se_lun->lun_se_dev RCU read-side critical access */
  776. u32 hba_index;
  777. struct rcu_head rcu_head;
  778. };
  779. struct se_hba {
  780. u16 hba_tpgt;
  781. u32 hba_id;
  782. /* See hba_flags_table */
  783. u32 hba_flags;
  784. /* Virtual iSCSI devices attached. */
  785. u32 dev_count;
  786. u32 hba_index;
  787. /* Pointer to transport specific host structure. */
  788. void *hba_ptr;
  789. struct list_head hba_node;
  790. spinlock_t device_lock;
  791. struct config_group hba_group;
  792. struct mutex hba_access_mutex;
  793. struct target_backend *backend;
  794. };
  795. struct se_tpg_np {
  796. struct se_portal_group *tpg_np_parent;
  797. struct config_group tpg_np_group;
  798. };
  799. static inline struct se_tpg_np *to_tpg_np(struct config_item *item)
  800. {
  801. return container_of(to_config_group(item), struct se_tpg_np,
  802. tpg_np_group);
  803. }
  804. struct se_portal_group {
  805. /*
  806. * PROTOCOL IDENTIFIER value per SPC4, 7.5.1.
  807. *
  808. * Negative values can be used by fabric drivers for internal use TPGs.
  809. */
  810. int proto_id;
  811. /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
  812. atomic_t tpg_pr_ref_count;
  813. /* Spinlock for adding/removing ACLed Nodes */
  814. struct mutex acl_node_mutex;
  815. /* Spinlock for adding/removing sessions */
  816. spinlock_t session_lock;
  817. struct mutex tpg_lun_mutex;
  818. /* linked list for initiator ACL list */
  819. struct list_head acl_node_list;
  820. struct hlist_head tpg_lun_hlist;
  821. struct se_lun *tpg_virt_lun0;
  822. /* List of TCM sessions associated wth this TPG */
  823. struct list_head tpg_sess_list;
  824. /* Pointer to $FABRIC_MOD dependent code */
  825. const struct target_core_fabric_ops *se_tpg_tfo;
  826. struct se_wwn *se_tpg_wwn;
  827. struct config_group tpg_group;
  828. struct config_group tpg_lun_group;
  829. struct config_group tpg_np_group;
  830. struct config_group tpg_acl_group;
  831. struct config_group tpg_attrib_group;
  832. struct config_group tpg_auth_group;
  833. struct config_group tpg_param_group;
  834. };
  835. static inline struct se_portal_group *to_tpg(struct config_item *item)
  836. {
  837. return container_of(to_config_group(item), struct se_portal_group,
  838. tpg_group);
  839. }
  840. static inline struct se_portal_group *attrib_to_tpg(struct config_item *item)
  841. {
  842. return container_of(to_config_group(item), struct se_portal_group,
  843. tpg_attrib_group);
  844. }
  845. static inline struct se_portal_group *auth_to_tpg(struct config_item *item)
  846. {
  847. return container_of(to_config_group(item), struct se_portal_group,
  848. tpg_auth_group);
  849. }
  850. static inline struct se_portal_group *param_to_tpg(struct config_item *item)
  851. {
  852. return container_of(to_config_group(item), struct se_portal_group,
  853. tpg_param_group);
  854. }
  855. struct se_wwn {
  856. struct target_fabric_configfs *wwn_tf;
  857. void *priv;
  858. struct config_group wwn_group;
  859. struct config_group fabric_stat_group;
  860. };
  861. static inline void atomic_inc_mb(atomic_t *v)
  862. {
  863. smp_mb__before_atomic();
  864. atomic_inc(v);
  865. smp_mb__after_atomic();
  866. }
  867. static inline void atomic_dec_mb(atomic_t *v)
  868. {
  869. smp_mb__before_atomic();
  870. atomic_dec(v);
  871. smp_mb__after_atomic();
  872. }
  873. static inline void target_free_tag(struct se_session *sess, struct se_cmd *cmd)
  874. {
  875. sbitmap_queue_clear(&sess->sess_tag_pool, cmd->map_tag, cmd->map_cpu);
  876. }
  877. #endif /* TARGET_CORE_BASE_H */