target_core_base.h 26 KB

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