target_core_base.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902
  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 <linux/percpu_ida.h>
  8. #include <scsi/scsi_cmnd.h>
  9. #include <net/sock.h>
  10. #include <net/tcp.h>
  11. #define TARGET_CORE_MOD_VERSION "v4.1.0"
  12. #define TARGET_CORE_VERSION TARGET_CORE_MOD_VERSION
  13. /* Maximum Number of LUNs per Target Portal Group */
  14. /* Don't raise above 511 or REPORT_LUNS needs to handle >1 page */
  15. #define TRANSPORT_MAX_LUNS_PER_TPG 256
  16. /*
  17. * By default we use 32-byte CDBs in TCM Core and subsystem plugin code.
  18. *
  19. * Note that both include/scsi/scsi_cmnd.h:MAX_COMMAND_SIZE and
  20. * include/linux/blkdev.h:BLOCK_MAX_CDB as of v2.6.36-rc4 still use
  21. * 16-byte CDBs by default and require an extra allocation for
  22. * 32-byte CDBs to because of legacy issues.
  23. *
  24. * Within TCM Core there are no such legacy limitiations, so we go ahead
  25. * use 32-byte CDBs by default and use include/scsi/scsi.h:scsi_command_size()
  26. * within all TCM Core and subsystem plugin code.
  27. */
  28. #define TCM_MAX_COMMAND_SIZE 32
  29. /*
  30. * From include/scsi/scsi_cmnd.h:SCSI_SENSE_BUFFERSIZE, currently
  31. * defined 96, but the real limit is 252 (or 260 including the header)
  32. */
  33. #define TRANSPORT_SENSE_BUFFER SCSI_SENSE_BUFFERSIZE
  34. /* Used by transport_send_check_condition_and_sense() */
  35. #define SPC_SENSE_KEY_OFFSET 2
  36. #define SPC_ADD_SENSE_LEN_OFFSET 7
  37. #define SPC_DESC_TYPE_OFFSET 8
  38. #define SPC_ADDITIONAL_DESC_LEN_OFFSET 9
  39. #define SPC_VALIDITY_OFFSET 10
  40. #define SPC_ASC_KEY_OFFSET 12
  41. #define SPC_ASCQ_KEY_OFFSET 13
  42. #define TRANSPORT_IQN_LEN 224
  43. /* Used by target_core_store_alua_lu_gp() and target_core_alua_lu_gp_show_attr_members() */
  44. #define LU_GROUP_NAME_BUF 256
  45. /* Used by core_alua_store_tg_pt_gp_info() and target_core_alua_tg_pt_gp_show_attr_members() */
  46. #define TG_PT_GROUP_NAME_BUF 256
  47. /* Used to parse VPD into struct t10_vpd */
  48. #define VPD_TMP_BUF_SIZE 254
  49. /* Used by transport_generic_cmd_sequencer() */
  50. #define READ_BLOCK_LEN 6
  51. #define READ_CAP_LEN 8
  52. #define READ_POSITION_LEN 20
  53. #define INQUIRY_LEN 36
  54. /* Used by transport_get_inquiry_vpd_serial() */
  55. #define INQUIRY_VPD_SERIAL_LEN 254
  56. /* Used by transport_get_inquiry_vpd_device_ident() */
  57. #define INQUIRY_VPD_DEVICE_IDENTIFIER_LEN 254
  58. /* Attempts before moving from SHORT to LONG */
  59. #define PYX_TRANSPORT_WINDOW_CLOSED_THRESHOLD 3
  60. #define PYX_TRANSPORT_WINDOW_CLOSED_WAIT_SHORT 3 /* In milliseconds */
  61. #define PYX_TRANSPORT_WINDOW_CLOSED_WAIT_LONG 10 /* In milliseconds */
  62. #define PYX_TRANSPORT_STATUS_INTERVAL 5 /* In seconds */
  63. /* struct se_dev_attrib sanity values */
  64. /* Default max_unmap_lba_count */
  65. #define DA_MAX_UNMAP_LBA_COUNT 0
  66. /* Default max_unmap_block_desc_count */
  67. #define DA_MAX_UNMAP_BLOCK_DESC_COUNT 0
  68. /* Default unmap_granularity */
  69. #define DA_UNMAP_GRANULARITY_DEFAULT 0
  70. /* Default unmap_granularity_alignment */
  71. #define DA_UNMAP_GRANULARITY_ALIGNMENT_DEFAULT 0
  72. /* Default max_write_same_len, disabled by default */
  73. #define DA_MAX_WRITE_SAME_LEN 0
  74. /* Use a model alias based on the configfs backend device name */
  75. #define DA_EMULATE_MODEL_ALIAS 0
  76. /* Emulation for WriteCache and SYNCHRONIZE_CACHE */
  77. #define DA_EMULATE_WRITE_CACHE 0
  78. /* Emulation for UNIT ATTENTION Interlock Control */
  79. #define DA_EMULATE_UA_INTLLCK_CTRL 0
  80. /* Emulation for TASK_ABORTED status (TAS) by default */
  81. #define DA_EMULATE_TAS 1
  82. /* Emulation for Thin Provisioning UNMAP using block/blk-lib.c:blkdev_issue_discard() */
  83. #define DA_EMULATE_TPU 0
  84. /*
  85. * Emulation for Thin Provisioning WRITE_SAME w/ UNMAP=1 bit using
  86. * block/blk-lib.c:blkdev_issue_discard()
  87. */
  88. #define DA_EMULATE_TPWS 0
  89. /* Emulation for CompareAndWrite (AtomicTestandSet) by default */
  90. #define DA_EMULATE_CAW 1
  91. /* Emulation for 3rd Party Copy (ExtendedCopy) by default */
  92. #define DA_EMULATE_3PC 1
  93. /* No Emulation for PSCSI by default */
  94. #define DA_EMULATE_ALUA 0
  95. /* Enforce SCSI Initiator Port TransportID with 'ISID' for PR */
  96. #define DA_ENFORCE_PR_ISIDS 1
  97. /* Force SPC-3 PR Activate Persistence across Target Power Loss */
  98. #define DA_FORCE_PR_APTPL 0
  99. #define DA_STATUS_MAX_SECTORS_MIN 16
  100. #define DA_STATUS_MAX_SECTORS_MAX 8192
  101. /* By default don't report non-rotating (solid state) medium */
  102. #define DA_IS_NONROT 0
  103. /* Queue Algorithm Modifier default for restricted reordering in control mode page */
  104. #define DA_EMULATE_REST_REORD 0
  105. #define SE_INQUIRY_BUF 1024
  106. #define SE_MODE_PAGE_BUF 512
  107. #define SE_SENSE_BUF 96
  108. /* struct se_hba->hba_flags */
  109. enum hba_flags_table {
  110. HBA_FLAGS_INTERNAL_USE = 0x01,
  111. HBA_FLAGS_PSCSI_MODE = 0x02,
  112. };
  113. /* Special transport agnostic struct se_cmd->t_states */
  114. enum transport_state_table {
  115. TRANSPORT_NO_STATE = 0,
  116. TRANSPORT_NEW_CMD = 1,
  117. TRANSPORT_WRITE_PENDING = 3,
  118. TRANSPORT_PROCESSING = 5,
  119. TRANSPORT_COMPLETE = 6,
  120. TRANSPORT_ISTATE_PROCESSING = 11,
  121. TRANSPORT_COMPLETE_QF_WP = 18,
  122. TRANSPORT_COMPLETE_QF_OK = 19,
  123. };
  124. /* Used for struct se_cmd->se_cmd_flags */
  125. enum se_cmd_flags_table {
  126. SCF_SUPPORTED_SAM_OPCODE = 0x00000001,
  127. SCF_TRANSPORT_TASK_SENSE = 0x00000002,
  128. SCF_EMULATED_TASK_SENSE = 0x00000004,
  129. SCF_SCSI_DATA_CDB = 0x00000008,
  130. SCF_SCSI_TMR_CDB = 0x00000010,
  131. SCF_FUA = 0x00000080,
  132. SCF_SE_LUN_CMD = 0x00000100,
  133. SCF_BIDI = 0x00000400,
  134. SCF_SENT_CHECK_CONDITION = 0x00000800,
  135. SCF_OVERFLOW_BIT = 0x00001000,
  136. SCF_UNDERFLOW_BIT = 0x00002000,
  137. SCF_SEND_DELAYED_TAS = 0x00004000,
  138. SCF_ALUA_NON_OPTIMIZED = 0x00008000,
  139. SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC = 0x00020000,
  140. SCF_COMPARE_AND_WRITE = 0x00080000,
  141. SCF_COMPARE_AND_WRITE_POST = 0x00100000,
  142. SCF_PASSTHROUGH_PROT_SG_TO_MEM_NOALLOC = 0x00200000,
  143. };
  144. /* struct se_dev_entry->lun_flags and struct se_lun->lun_access */
  145. enum transport_lunflags_table {
  146. TRANSPORT_LUNFLAGS_READ_ONLY = 0x01,
  147. TRANSPORT_LUNFLAGS_READ_WRITE = 0x02,
  148. };
  149. /*
  150. * Used by transport_send_check_condition_and_sense()
  151. * to signal which ASC/ASCQ sense payload should be built.
  152. */
  153. typedef unsigned __bitwise__ sense_reason_t;
  154. enum tcm_sense_reason_table {
  155. #define R(x) (__force sense_reason_t )(x)
  156. TCM_NO_SENSE = R(0x00),
  157. TCM_NON_EXISTENT_LUN = R(0x01),
  158. TCM_UNSUPPORTED_SCSI_OPCODE = R(0x02),
  159. TCM_INCORRECT_AMOUNT_OF_DATA = R(0x03),
  160. TCM_UNEXPECTED_UNSOLICITED_DATA = R(0x04),
  161. TCM_SERVICE_CRC_ERROR = R(0x05),
  162. TCM_SNACK_REJECTED = R(0x06),
  163. TCM_SECTOR_COUNT_TOO_MANY = R(0x07),
  164. TCM_INVALID_CDB_FIELD = R(0x08),
  165. TCM_INVALID_PARAMETER_LIST = R(0x09),
  166. TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE = R(0x0a),
  167. TCM_UNKNOWN_MODE_PAGE = R(0x0b),
  168. TCM_WRITE_PROTECTED = R(0x0c),
  169. TCM_CHECK_CONDITION_ABORT_CMD = R(0x0d),
  170. TCM_CHECK_CONDITION_UNIT_ATTENTION = R(0x0e),
  171. TCM_CHECK_CONDITION_NOT_READY = R(0x0f),
  172. TCM_RESERVATION_CONFLICT = R(0x10),
  173. TCM_ADDRESS_OUT_OF_RANGE = R(0x11),
  174. TCM_OUT_OF_RESOURCES = R(0x12),
  175. TCM_PARAMETER_LIST_LENGTH_ERROR = R(0x13),
  176. TCM_MISCOMPARE_VERIFY = R(0x14),
  177. TCM_LOGICAL_BLOCK_GUARD_CHECK_FAILED = R(0x15),
  178. TCM_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED = R(0x16),
  179. TCM_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED = R(0x17),
  180. #undef R
  181. };
  182. enum target_sc_flags_table {
  183. TARGET_SCF_BIDI_OP = 0x01,
  184. TARGET_SCF_ACK_KREF = 0x02,
  185. TARGET_SCF_UNKNOWN_SIZE = 0x04,
  186. };
  187. /* fabric independent task management function values */
  188. enum tcm_tmreq_table {
  189. TMR_ABORT_TASK = 1,
  190. TMR_ABORT_TASK_SET = 2,
  191. TMR_CLEAR_ACA = 3,
  192. TMR_CLEAR_TASK_SET = 4,
  193. TMR_LUN_RESET = 5,
  194. TMR_TARGET_WARM_RESET = 6,
  195. TMR_TARGET_COLD_RESET = 7,
  196. };
  197. /* fabric independent task management response values */
  198. enum tcm_tmrsp_table {
  199. TMR_FUNCTION_FAILED = 0,
  200. TMR_FUNCTION_COMPLETE = 1,
  201. TMR_TASK_DOES_NOT_EXIST = 2,
  202. TMR_LUN_DOES_NOT_EXIST = 3,
  203. TMR_TASK_MGMT_FUNCTION_NOT_SUPPORTED = 4,
  204. TMR_FUNCTION_REJECTED = 5,
  205. };
  206. /*
  207. * Used for target SCSI statistics
  208. */
  209. typedef enum {
  210. SCSI_INST_INDEX,
  211. SCSI_DEVICE_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_pending_state;
  267. int tg_pt_gp_alua_previous_state;
  268. int tg_pt_gp_alua_access_status;
  269. int tg_pt_gp_alua_access_type;
  270. int tg_pt_gp_nonop_delay_msecs;
  271. int tg_pt_gp_trans_delay_msecs;
  272. int tg_pt_gp_implicit_trans_secs;
  273. int tg_pt_gp_pref;
  274. int tg_pt_gp_write_metadata;
  275. u32 tg_pt_gp_members;
  276. atomic_t tg_pt_gp_alua_access_state;
  277. atomic_t tg_pt_gp_ref_cnt;
  278. spinlock_t tg_pt_gp_lock;
  279. struct mutex tg_pt_gp_md_mutex;
  280. struct se_device *tg_pt_gp_dev;
  281. struct config_group tg_pt_gp_group;
  282. struct list_head tg_pt_gp_list;
  283. struct list_head tg_pt_gp_lun_list;
  284. struct se_lun *tg_pt_gp_alua_lun;
  285. struct se_node_acl *tg_pt_gp_alua_nacl;
  286. struct delayed_work tg_pt_gp_transition_work;
  287. struct completion *tg_pt_gp_transition_complete;
  288. };
  289. struct t10_vpd {
  290. unsigned char device_identifier[INQUIRY_VPD_DEVICE_IDENTIFIER_LEN];
  291. int protocol_identifier_set;
  292. u32 protocol_identifier;
  293. u32 device_identifier_code_set;
  294. u32 association;
  295. u32 device_identifier_type;
  296. struct list_head vpd_list;
  297. };
  298. struct t10_wwn {
  299. char vendor[8];
  300. char model[16];
  301. char revision[4];
  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. u32 pr_res_mapped_lun;
  332. u32 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 se_lun *tmr_lun;
  383. struct list_head tmr_list;
  384. };
  385. enum target_prot_op {
  386. TARGET_PROT_NORMAL = 0,
  387. TARGET_PROT_DIN_INSERT = (1 << 0),
  388. TARGET_PROT_DOUT_INSERT = (1 << 1),
  389. TARGET_PROT_DIN_STRIP = (1 << 2),
  390. TARGET_PROT_DOUT_STRIP = (1 << 3),
  391. TARGET_PROT_DIN_PASS = (1 << 4),
  392. TARGET_PROT_DOUT_PASS = (1 << 5),
  393. };
  394. #define TARGET_PROT_ALL TARGET_PROT_DIN_INSERT | TARGET_PROT_DOUT_INSERT | \
  395. TARGET_PROT_DIN_STRIP | TARGET_PROT_DOUT_STRIP | \
  396. TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS
  397. enum target_prot_type {
  398. TARGET_DIF_TYPE0_PROT,
  399. TARGET_DIF_TYPE1_PROT,
  400. TARGET_DIF_TYPE2_PROT,
  401. TARGET_DIF_TYPE3_PROT,
  402. };
  403. enum target_core_dif_check {
  404. TARGET_DIF_CHECK_GUARD = 0x1 << 0,
  405. TARGET_DIF_CHECK_APPTAG = 0x1 << 1,
  406. TARGET_DIF_CHECK_REFTAG = 0x1 << 2,
  407. };
  408. struct se_dif_v1_tuple {
  409. __be16 guard_tag;
  410. __be16 app_tag;
  411. __be32 ref_tag;
  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. u64 tag; /* SAM command identifier aka task tag */
  425. /* Delay for ALUA Active/NonOptimized state access in milliseconds */
  426. int alua_nonop_delay;
  427. /* See include/linux/dma-mapping.h */
  428. enum dma_data_direction data_direction;
  429. /* For SAM Task Attribute */
  430. int sam_task_attr;
  431. /* Used for se_sess->sess_tag_pool */
  432. unsigned int map_tag;
  433. /* Transport protocol dependent state, see transport_state_table */
  434. enum transport_state_table t_state;
  435. unsigned cmd_wait_set:1;
  436. unsigned unknown_data_length:1;
  437. /* See se_cmd_flags_table */
  438. u32 se_cmd_flags;
  439. u32 se_ordered_id;
  440. /* Total size in bytes associated with command */
  441. u32 data_length;
  442. u32 residual_count;
  443. u32 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 cmd_wait_comp;
  457. struct kref cmd_kref;
  458. const struct target_core_fabric_ops *se_tfo;
  459. sense_reason_t (*execute_cmd)(struct se_cmd *);
  460. sense_reason_t (*execute_rw)(struct se_cmd *, struct scatterlist *,
  461. u32, enum dma_data_direction);
  462. sense_reason_t (*transport_complete_callback)(struct se_cmd *, bool);
  463. unsigned char *t_task_cdb;
  464. unsigned char __t_task_cdb[TCM_MAX_COMMAND_SIZE];
  465. unsigned long long t_task_lba;
  466. unsigned int t_task_nolb;
  467. unsigned int transport_state;
  468. #define CMD_T_ABORTED (1 << 0)
  469. #define CMD_T_ACTIVE (1 << 1)
  470. #define CMD_T_COMPLETE (1 << 2)
  471. #define CMD_T_SENT (1 << 4)
  472. #define CMD_T_STOP (1 << 5)
  473. #define CMD_T_DEV_ACTIVE (1 << 7)
  474. #define CMD_T_REQUEST_STOP (1 << 8)
  475. #define CMD_T_BUSY (1 << 9)
  476. spinlock_t t_state_lock;
  477. struct completion t_transport_stop_comp;
  478. struct work_struct work;
  479. struct scatterlist *t_data_sg;
  480. struct scatterlist *t_data_sg_orig;
  481. unsigned int t_data_nents;
  482. unsigned int t_data_nents_orig;
  483. void *t_data_vmap;
  484. struct scatterlist *t_bidi_data_sg;
  485. unsigned int t_bidi_data_nents;
  486. struct list_head state_list;
  487. bool state_active;
  488. /* old task stop completion, consider merging with some of the above */
  489. struct completion task_stop_comp;
  490. /* backend private data */
  491. void *priv;
  492. /* Used for lun->lun_ref counting */
  493. int lun_ref_active;
  494. /* DIF related members */
  495. enum target_prot_op prot_op;
  496. enum target_prot_type prot_type;
  497. u8 prot_checks;
  498. u32 prot_length;
  499. u32 reftag_seed;
  500. struct scatterlist *t_prot_sg;
  501. unsigned int t_prot_nents;
  502. sense_reason_t pi_err;
  503. sector_t bad_sector;
  504. bool prot_pto;
  505. };
  506. struct se_ua {
  507. u8 ua_asc;
  508. u8 ua_ascq;
  509. struct se_node_acl *ua_nacl;
  510. struct list_head ua_nacl_list;
  511. };
  512. struct se_node_acl {
  513. char initiatorname[TRANSPORT_IQN_LEN];
  514. /* Used to signal demo mode created ACL, disabled by default */
  515. bool dynamic_node_acl;
  516. bool acl_stop:1;
  517. u32 queue_depth;
  518. u32 acl_index;
  519. enum target_prot_type saved_prot_type;
  520. #define MAX_ACL_TAG_SIZE 64
  521. char acl_tag[MAX_ACL_TAG_SIZE];
  522. /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
  523. atomic_t acl_pr_ref_count;
  524. struct hlist_head lun_entry_hlist;
  525. struct se_session *nacl_sess;
  526. struct se_portal_group *se_tpg;
  527. struct mutex lun_entry_mutex;
  528. spinlock_t nacl_sess_lock;
  529. struct config_group acl_group;
  530. struct config_group acl_attrib_group;
  531. struct config_group acl_auth_group;
  532. struct config_group acl_param_group;
  533. struct config_group acl_fabric_stat_group;
  534. struct config_group *acl_default_groups[5];
  535. struct list_head acl_list;
  536. struct list_head acl_sess_list;
  537. struct completion acl_free_comp;
  538. struct kref acl_kref;
  539. };
  540. struct se_session {
  541. unsigned sess_tearing_down:1;
  542. u64 sess_bin_isid;
  543. enum target_prot_op sup_prot_ops;
  544. enum target_prot_type sess_prot_type;
  545. struct se_node_acl *se_node_acl;
  546. struct se_portal_group *se_tpg;
  547. void *fabric_sess_ptr;
  548. struct list_head sess_list;
  549. struct list_head sess_acl_list;
  550. struct list_head sess_cmd_list;
  551. struct list_head sess_wait_list;
  552. spinlock_t sess_cmd_lock;
  553. struct kref sess_kref;
  554. void *sess_cmd_map;
  555. struct percpu_ida sess_tag_pool;
  556. };
  557. struct se_device;
  558. struct se_transform_info;
  559. struct scatterlist;
  560. struct se_ml_stat_grps {
  561. struct config_group stat_group;
  562. struct config_group scsi_auth_intr_group;
  563. struct config_group scsi_att_intr_port_group;
  564. };
  565. struct se_lun_acl {
  566. char initiatorname[TRANSPORT_IQN_LEN];
  567. u32 mapped_lun;
  568. struct se_node_acl *se_lun_nacl;
  569. struct se_lun *se_lun;
  570. struct config_group se_lun_group;
  571. struct se_ml_stat_grps ml_stat_grps;
  572. };
  573. struct se_dev_entry {
  574. /* See transport_lunflags_table */
  575. u32 lun_flags;
  576. u32 mapped_lun;
  577. u64 pr_res_key;
  578. u64 creation_time;
  579. u32 attach_count;
  580. atomic_long_t total_cmds;
  581. atomic_long_t read_bytes;
  582. atomic_long_t write_bytes;
  583. atomic_t ua_count;
  584. /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
  585. struct kref pr_kref;
  586. struct completion pr_comp;
  587. struct se_lun_acl __rcu *se_lun_acl;
  588. spinlock_t ua_lock;
  589. struct se_lun __rcu *se_lun;
  590. #define DEF_PR_REG_ACTIVE 1
  591. unsigned long deve_flags;
  592. struct list_head alua_port_list;
  593. struct list_head lun_link;
  594. struct list_head ua_list;
  595. struct hlist_node link;
  596. struct rcu_head rcu_head;
  597. };
  598. struct se_dev_attrib {
  599. int emulate_model_alias;
  600. int emulate_dpo;
  601. int emulate_fua_write;
  602. int emulate_fua_read;
  603. int emulate_write_cache;
  604. int emulate_ua_intlck_ctrl;
  605. int emulate_tas;
  606. int emulate_tpu;
  607. int emulate_tpws;
  608. int emulate_caw;
  609. int emulate_3pc;
  610. int pi_prot_format;
  611. enum target_prot_type pi_prot_type;
  612. enum target_prot_type hw_pi_prot_type;
  613. int enforce_pr_isids;
  614. int force_pr_aptpl;
  615. int is_nonrot;
  616. int emulate_rest_reord;
  617. u32 hw_block_size;
  618. u32 block_size;
  619. u32 hw_max_sectors;
  620. u32 optimal_sectors;
  621. u32 hw_queue_depth;
  622. u32 queue_depth;
  623. u32 max_unmap_lba_count;
  624. u32 max_unmap_block_desc_count;
  625. u32 unmap_granularity;
  626. u32 unmap_granularity_alignment;
  627. u32 max_write_same_len;
  628. u32 max_bytes_per_io;
  629. struct se_device *da_dev;
  630. struct config_group da_group;
  631. };
  632. struct se_port_stat_grps {
  633. struct config_group stat_group;
  634. struct config_group scsi_port_group;
  635. struct config_group scsi_tgt_port_group;
  636. struct config_group scsi_transport_group;
  637. };
  638. struct scsi_port_stats {
  639. u32 cmd_pdus;
  640. u64 tx_data_octets;
  641. u64 rx_data_octets;
  642. };
  643. struct se_lun {
  644. /* RELATIVE TARGET PORT IDENTIFER */
  645. u16 lun_rtpi;
  646. #define SE_LUN_LINK_MAGIC 0xffff7771
  647. u32 lun_link_magic;
  648. u32 lun_access;
  649. u32 lun_flags;
  650. u32 unpacked_lun;
  651. u32 lun_index;
  652. atomic_t lun_acl_count;
  653. spinlock_t lun_sep_lock;
  654. struct se_device __rcu *lun_se_dev;
  655. struct list_head lun_deve_list;
  656. spinlock_t lun_deve_lock;
  657. /* ALUA state */
  658. int lun_tg_pt_secondary_stat;
  659. int lun_tg_pt_secondary_write_md;
  660. atomic_t lun_tg_pt_secondary_offline;
  661. struct mutex lun_tg_pt_md_mutex;
  662. /* ALUA target port group linkage */
  663. struct list_head lun_tg_pt_gp_link;
  664. struct t10_alua_tg_pt_gp *lun_tg_pt_gp;
  665. spinlock_t lun_tg_pt_gp_lock;
  666. atomic_t lun_active;
  667. struct se_portal_group *lun_tpg;
  668. struct scsi_port_stats lun_stats;
  669. struct config_group lun_group;
  670. struct se_port_stat_grps port_stat_grps;
  671. struct completion lun_ref_comp;
  672. struct percpu_ref lun_ref;
  673. struct list_head lun_dev_link;
  674. struct hlist_node link;
  675. struct rcu_head rcu_head;
  676. };
  677. struct se_dev_stat_grps {
  678. struct config_group stat_group;
  679. struct config_group scsi_dev_group;
  680. struct config_group scsi_tgt_dev_group;
  681. struct config_group scsi_lu_group;
  682. };
  683. struct se_device {
  684. #define SE_DEV_LINK_MAGIC 0xfeeddeef
  685. u32 dev_link_magic;
  686. /* RELATIVE TARGET PORT IDENTIFER Counter */
  687. u16 dev_rpti_counter;
  688. /* Used for SAM Task Attribute ordering */
  689. u32 dev_cur_ordered_id;
  690. u32 dev_flags;
  691. #define DF_CONFIGURED 0x00000001
  692. #define DF_FIRMWARE_VPD_UNIT_SERIAL 0x00000002
  693. #define DF_EMULATED_VPD_UNIT_SERIAL 0x00000004
  694. #define DF_USING_UDEV_PATH 0x00000008
  695. #define DF_USING_ALIAS 0x00000010
  696. /* Physical device queue depth */
  697. u32 queue_depth;
  698. /* Used for SPC-2 reservations enforce of ISIDs */
  699. u64 dev_res_bin_isid;
  700. /* Pointer to transport specific device structure */
  701. u32 dev_index;
  702. u64 creation_time;
  703. atomic_long_t num_resets;
  704. atomic_long_t num_cmds;
  705. atomic_long_t read_bytes;
  706. atomic_long_t write_bytes;
  707. /* Active commands on this virtual SE device */
  708. atomic_t simple_cmds;
  709. atomic_t dev_ordered_id;
  710. atomic_t dev_ordered_sync;
  711. atomic_t dev_qf_count;
  712. u32 export_count;
  713. spinlock_t delayed_cmd_lock;
  714. spinlock_t execute_task_lock;
  715. spinlock_t dev_reservation_lock;
  716. unsigned int dev_reservation_flags;
  717. #define DRF_SPC2_RESERVATIONS 0x00000001
  718. #define DRF_SPC2_RESERVATIONS_WITH_ISID 0x00000002
  719. spinlock_t se_port_lock;
  720. spinlock_t se_tmr_lock;
  721. spinlock_t qf_cmd_lock;
  722. struct semaphore caw_sem;
  723. /* Used for legacy SPC-2 reservationsa */
  724. struct se_node_acl *dev_reserved_node_acl;
  725. /* Used for ALUA Logical Unit Group membership */
  726. struct t10_alua_lu_gp_member *dev_alua_lu_gp_mem;
  727. /* Used for SPC-3 Persistent Reservations */
  728. struct t10_pr_registration *dev_pr_res_holder;
  729. struct list_head dev_sep_list;
  730. struct list_head dev_tmr_list;
  731. struct workqueue_struct *tmr_wq;
  732. struct work_struct qf_work_queue;
  733. struct list_head delayed_cmd_list;
  734. struct list_head state_list;
  735. struct list_head qf_cmd_list;
  736. struct list_head g_dev_node;
  737. /* Pointer to associated SE HBA */
  738. struct se_hba *se_hba;
  739. /* T10 Inquiry and VPD WWN Information */
  740. struct t10_wwn t10_wwn;
  741. /* T10 Asymmetric Logical Unit Assignment for Target Ports */
  742. struct t10_alua t10_alua;
  743. /* T10 SPC-2 + SPC-3 Reservations */
  744. struct t10_reservation t10_pr;
  745. struct se_dev_attrib dev_attrib;
  746. struct config_group dev_group;
  747. struct config_group dev_pr_group;
  748. struct se_dev_stat_grps dev_stat_grps;
  749. #define SE_DEV_ALIAS_LEN 512 /* must be less than PAGE_SIZE */
  750. unsigned char dev_alias[SE_DEV_ALIAS_LEN];
  751. #define SE_UDEV_PATH_LEN 512 /* must be less than PAGE_SIZE */
  752. unsigned char udev_path[SE_UDEV_PATH_LEN];
  753. /* Pointer to template of function pointers for transport */
  754. const struct target_backend_ops *transport;
  755. /* Linked list for struct se_hba struct se_device list */
  756. struct list_head dev_list;
  757. struct se_lun xcopy_lun;
  758. /* Protection Information */
  759. int prot_length;
  760. };
  761. struct se_hba {
  762. u16 hba_tpgt;
  763. u32 hba_id;
  764. /* See hba_flags_table */
  765. u32 hba_flags;
  766. /* Virtual iSCSI devices attached. */
  767. u32 dev_count;
  768. u32 hba_index;
  769. /* Pointer to transport specific host structure. */
  770. void *hba_ptr;
  771. struct list_head hba_node;
  772. spinlock_t device_lock;
  773. struct config_group hba_group;
  774. struct mutex hba_access_mutex;
  775. struct target_backend *backend;
  776. };
  777. struct se_tpg_np {
  778. struct se_portal_group *tpg_np_parent;
  779. struct config_group tpg_np_group;
  780. };
  781. struct se_portal_group {
  782. /*
  783. * PROTOCOL IDENTIFIER value per SPC4, 7.5.1.
  784. *
  785. * Negative values can be used by fabric drivers for internal use TPGs.
  786. */
  787. int proto_id;
  788. /* Number of ACLed Initiator Nodes for this TPG */
  789. u32 num_node_acls;
  790. /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
  791. atomic_t tpg_pr_ref_count;
  792. /* Spinlock for adding/removing ACLed Nodes */
  793. struct mutex acl_node_mutex;
  794. /* Spinlock for adding/removing sessions */
  795. spinlock_t session_lock;
  796. struct mutex tpg_lun_mutex;
  797. struct list_head se_tpg_node;
  798. /* linked list for initiator ACL list */
  799. struct list_head acl_node_list;
  800. struct hlist_head tpg_lun_hlist;
  801. struct se_lun *tpg_virt_lun0;
  802. /* List of TCM sessions associated wth this TPG */
  803. struct list_head tpg_sess_list;
  804. /* Pointer to $FABRIC_MOD dependent code */
  805. const struct target_core_fabric_ops *se_tpg_tfo;
  806. struct se_wwn *se_tpg_wwn;
  807. struct config_group tpg_group;
  808. struct config_group *tpg_default_groups[7];
  809. struct config_group tpg_lun_group;
  810. struct config_group tpg_np_group;
  811. struct config_group tpg_acl_group;
  812. struct config_group tpg_attrib_group;
  813. struct config_group tpg_auth_group;
  814. struct config_group tpg_param_group;
  815. };
  816. struct se_wwn {
  817. struct target_fabric_configfs *wwn_tf;
  818. struct config_group wwn_group;
  819. struct config_group *wwn_default_groups[2];
  820. struct config_group fabric_stat_group;
  821. };
  822. static inline void atomic_inc_mb(atomic_t *v)
  823. {
  824. smp_mb__before_atomic();
  825. atomic_inc(v);
  826. smp_mb__after_atomic();
  827. }
  828. static inline void atomic_dec_mb(atomic_t *v)
  829. {
  830. smp_mb__before_atomic();
  831. atomic_dec(v);
  832. smp_mb__after_atomic();
  833. }
  834. #endif /* TARGET_CORE_BASE_H */