target_core_base.h 26 KB

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