target_core_base.h 27 KB

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