target_core_base.h 28 KB

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