target_core_base.h 26 KB

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