target_core_base.h 28 KB

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