target_core_base.h 25 KB

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