target_core_transport.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. #ifndef TARGET_CORE_TRANSPORT_H
  2. #define TARGET_CORE_TRANSPORT_H
  3. #define TARGET_CORE_VERSION TARGET_CORE_MOD_VERSION
  4. /* Attempts before moving from SHORT to LONG */
  5. #define PYX_TRANSPORT_WINDOW_CLOSED_THRESHOLD 3
  6. #define PYX_TRANSPORT_WINDOW_CLOSED_WAIT_SHORT 3 /* In milliseconds */
  7. #define PYX_TRANSPORT_WINDOW_CLOSED_WAIT_LONG 10 /* In milliseconds */
  8. #define PYX_TRANSPORT_STATUS_INTERVAL 5 /* In seconds */
  9. #define PYX_TRANSPORT_SENT_TO_TRANSPORT 0
  10. #define PYX_TRANSPORT_WRITE_PENDING 1
  11. #define PYX_TRANSPORT_UNKNOWN_SAM_OPCODE -1
  12. #define PYX_TRANSPORT_HBA_QUEUE_FULL -2
  13. #define PYX_TRANSPORT_REQ_TOO_MANY_SECTORS -3
  14. #define PYX_TRANSPORT_OUT_OF_MEMORY_RESOURCES -4
  15. #define PYX_TRANSPORT_INVALID_CDB_FIELD -5
  16. #define PYX_TRANSPORT_INVALID_PARAMETER_LIST -6
  17. #define PYX_TRANSPORT_LU_COMM_FAILURE -7
  18. #define PYX_TRANSPORT_UNKNOWN_MODE_PAGE -8
  19. #define PYX_TRANSPORT_WRITE_PROTECTED -9
  20. #define PYX_TRANSPORT_TASK_TIMEOUT -10
  21. #define PYX_TRANSPORT_RESERVATION_CONFLICT -11
  22. #define PYX_TRANSPORT_ILLEGAL_REQUEST -12
  23. #define PYX_TRANSPORT_USE_SENSE_REASON -13
  24. #ifndef SAM_STAT_RESERVATION_CONFLICT
  25. #define SAM_STAT_RESERVATION_CONFLICT 0x18
  26. #endif
  27. #define TRANSPORT_PLUGIN_FREE 0
  28. #define TRANSPORT_PLUGIN_REGISTERED 1
  29. #define TRANSPORT_PLUGIN_PHBA_PDEV 1
  30. #define TRANSPORT_PLUGIN_VHBA_PDEV 2
  31. #define TRANSPORT_PLUGIN_VHBA_VDEV 3
  32. /* For SE OBJ Plugins, in seconds */
  33. #define TRANSPORT_TIMEOUT_TUR 10
  34. #define TRANSPORT_TIMEOUT_TYPE_DISK 60
  35. #define TRANSPORT_TIMEOUT_TYPE_ROM 120
  36. #define TRANSPORT_TIMEOUT_TYPE_TAPE 600
  37. #define TRANSPORT_TIMEOUT_TYPE_OTHER 300
  38. /* For se_task->task_state_flags */
  39. #define TSF_EXCEPTION_CLEARED 0x01
  40. /*
  41. * struct se_subsystem_dev->su_dev_flags
  42. */
  43. #define SDF_FIRMWARE_VPD_UNIT_SERIAL 0x00000001
  44. #define SDF_EMULATED_VPD_UNIT_SERIAL 0x00000002
  45. #define SDF_USING_UDEV_PATH 0x00000004
  46. #define SDF_USING_ALIAS 0x00000008
  47. /*
  48. * struct se_device->dev_flags
  49. */
  50. #define DF_READ_ONLY 0x00000001
  51. #define DF_SPC2_RESERVATIONS 0x00000002
  52. #define DF_SPC2_RESERVATIONS_WITH_ISID 0x00000004
  53. /* struct se_dev_attrib sanity values */
  54. /* 10 Minutes */
  55. #define DA_TASK_TIMEOUT_MAX 600
  56. /* Default max_unmap_lba_count */
  57. #define DA_MAX_UNMAP_LBA_COUNT 0
  58. /* Default max_unmap_block_desc_count */
  59. #define DA_MAX_UNMAP_BLOCK_DESC_COUNT 0
  60. /* Default unmap_granularity */
  61. #define DA_UNMAP_GRANULARITY_DEFAULT 0
  62. /* Default unmap_granularity_alignment */
  63. #define DA_UNMAP_GRANULARITY_ALIGNMENT_DEFAULT 0
  64. /* Emulation for Direct Page Out */
  65. #define DA_EMULATE_DPO 0
  66. /* Emulation for Forced Unit Access WRITEs */
  67. #define DA_EMULATE_FUA_WRITE 1
  68. /* Emulation for Forced Unit Access READs */
  69. #define DA_EMULATE_FUA_READ 0
  70. /* Emulation for WriteCache and SYNCHRONIZE_CACHE */
  71. #define DA_EMULATE_WRITE_CACHE 0
  72. /* Emulation for UNIT ATTENTION Interlock Control */
  73. #define DA_EMULATE_UA_INTLLCK_CTRL 0
  74. /* Emulation for TASK_ABORTED status (TAS) by default */
  75. #define DA_EMULATE_TAS 1
  76. /* Emulation for Thin Provisioning UNMAP using block/blk-lib.c:blkdev_issue_discard() */
  77. #define DA_EMULATE_TPU 0
  78. /*
  79. * Emulation for Thin Provisioning WRITE_SAME w/ UNMAP=1 bit using
  80. * block/blk-lib.c:blkdev_issue_discard()
  81. */
  82. #define DA_EMULATE_TPWS 0
  83. /* No Emulation for PSCSI by default */
  84. #define DA_EMULATE_RESERVATIONS 0
  85. /* No Emulation for PSCSI by default */
  86. #define DA_EMULATE_ALUA 0
  87. /* Enforce SCSI Initiator Port TransportID with 'ISID' for PR */
  88. #define DA_ENFORCE_PR_ISIDS 1
  89. #define DA_STATUS_MAX_SECTORS_MIN 16
  90. #define DA_STATUS_MAX_SECTORS_MAX 8192
  91. #define SE_MODE_PAGE_BUF 512
  92. #define MOD_MAX_SECTORS(ms, bs) (ms % (PAGE_SIZE / bs))
  93. struct se_mem;
  94. struct se_subsystem_api;
  95. extern struct kmem_cache *se_mem_cache;
  96. extern int init_se_global(void);
  97. extern void release_se_global(void);
  98. extern void init_scsi_index_table(void);
  99. extern u32 scsi_get_new_index(scsi_index_t);
  100. extern void transport_init_queue_obj(struct se_queue_obj *);
  101. extern int transport_subsystem_check_init(void);
  102. extern int transport_subsystem_register(struct se_subsystem_api *);
  103. extern void transport_subsystem_release(struct se_subsystem_api *);
  104. extern void transport_load_plugins(void);
  105. extern struct se_session *transport_init_session(void);
  106. extern void __transport_register_session(struct se_portal_group *,
  107. struct se_node_acl *,
  108. struct se_session *, void *);
  109. extern void transport_register_session(struct se_portal_group *,
  110. struct se_node_acl *,
  111. struct se_session *, void *);
  112. extern void transport_free_session(struct se_session *);
  113. extern void transport_deregister_session_configfs(struct se_session *);
  114. extern void transport_deregister_session(struct se_session *);
  115. extern void transport_cmd_finish_abort(struct se_cmd *, int);
  116. extern void transport_cmd_finish_abort_tmr(struct se_cmd *);
  117. extern void transport_complete_sync_cache(struct se_cmd *, int);
  118. extern void transport_complete_task(struct se_task *, int);
  119. extern void transport_add_task_to_execute_queue(struct se_task *,
  120. struct se_task *,
  121. struct se_device *);
  122. extern void transport_remove_task_from_execute_queue(struct se_task *,
  123. struct se_device *);
  124. unsigned char *transport_dump_cmd_direction(struct se_cmd *);
  125. extern void transport_dump_dev_state(struct se_device *, char *, int *);
  126. extern void transport_dump_dev_info(struct se_device *, struct se_lun *,
  127. unsigned long long, char *, int *);
  128. extern void transport_dump_vpd_proto_id(struct t10_vpd *,
  129. unsigned char *, int);
  130. extern void transport_set_vpd_proto_id(struct t10_vpd *, unsigned char *);
  131. extern int transport_dump_vpd_assoc(struct t10_vpd *,
  132. unsigned char *, int);
  133. extern int transport_set_vpd_assoc(struct t10_vpd *, unsigned char *);
  134. extern int transport_dump_vpd_ident_type(struct t10_vpd *,
  135. unsigned char *, int);
  136. extern int transport_set_vpd_ident_type(struct t10_vpd *, unsigned char *);
  137. extern int transport_dump_vpd_ident(struct t10_vpd *,
  138. unsigned char *, int);
  139. extern int transport_set_vpd_ident(struct t10_vpd *, unsigned char *);
  140. extern struct se_device *transport_add_device_to_core_hba(struct se_hba *,
  141. struct se_subsystem_api *,
  142. struct se_subsystem_dev *, u32,
  143. void *, struct se_dev_limits *,
  144. const char *, const char *);
  145. extern void transport_device_setup_cmd(struct se_cmd *);
  146. extern void transport_init_se_cmd(struct se_cmd *,
  147. struct target_core_fabric_ops *,
  148. struct se_session *, u32, int, int,
  149. unsigned char *);
  150. extern void transport_free_se_cmd(struct se_cmd *);
  151. extern int transport_generic_allocate_tasks(struct se_cmd *, unsigned char *);
  152. extern int transport_generic_handle_cdb(struct se_cmd *);
  153. extern int transport_generic_handle_cdb_map(struct se_cmd *);
  154. extern int transport_generic_handle_data(struct se_cmd *);
  155. extern void transport_new_cmd_failure(struct se_cmd *);
  156. extern int transport_generic_handle_tmr(struct se_cmd *);
  157. extern void transport_generic_free_cmd_intr(struct se_cmd *);
  158. extern void __transport_stop_task_timer(struct se_task *, unsigned long *);
  159. extern unsigned char transport_asciihex_to_binaryhex(unsigned char val[2]);
  160. extern int transport_generic_map_mem_to_cmd(struct se_cmd *cmd, struct scatterlist *, u32,
  161. struct scatterlist *, u32);
  162. extern int transport_clear_lun_from_sessions(struct se_lun *);
  163. extern int transport_check_aborted_status(struct se_cmd *, int);
  164. extern int transport_send_check_condition_and_sense(struct se_cmd *, u8, int);
  165. extern void transport_send_task_abort(struct se_cmd *);
  166. extern void transport_release_cmd_to_pool(struct se_cmd *);
  167. extern void transport_generic_free_cmd(struct se_cmd *, int, int, int);
  168. extern void transport_generic_wait_for_cmds(struct se_cmd *, int);
  169. extern u32 transport_calc_sg_num(struct se_task *, struct se_mem *, u32);
  170. extern int transport_map_mem_to_sg(struct se_task *, struct list_head *,
  171. void *, struct se_mem *,
  172. struct se_mem **, u32 *, u32 *);
  173. extern void transport_do_task_sg_chain(struct se_cmd *);
  174. extern void transport_generic_process_write(struct se_cmd *);
  175. extern int transport_generic_do_tmr(struct se_cmd *);
  176. /* From target_core_alua.c */
  177. extern int core_alua_check_nonop_delay(struct se_cmd *);
  178. /* From target_core_cdb.c */
  179. extern int transport_emulate_control_cdb(struct se_task *);
  180. /*
  181. * Each se_transport_task_t can have N number of possible struct se_task's
  182. * for the storage transport(s) to possibly execute.
  183. * Used primarily for splitting up CDBs that exceed the physical storage
  184. * HBA's maximum sector count per task.
  185. */
  186. struct se_mem {
  187. struct page *se_page;
  188. u32 se_len;
  189. u32 se_off;
  190. struct list_head se_list;
  191. } ____cacheline_aligned;
  192. /*
  193. * Each type of disk transport supported MUST have a template defined
  194. * within its .h file.
  195. */
  196. struct se_subsystem_api {
  197. /*
  198. * The Name. :-)
  199. */
  200. char name[16];
  201. /*
  202. * Transport Type.
  203. */
  204. u8 transport_type;
  205. /*
  206. * struct module for struct se_hba references
  207. */
  208. struct module *owner;
  209. /*
  210. * Used for global se_subsystem_api list_head
  211. */
  212. struct list_head sub_api_list;
  213. /*
  214. * For SCF_SCSI_NON_DATA_CDB
  215. */
  216. int (*cdb_none)(struct se_task *);
  217. /*
  218. * For SCF_SCSI_CONTROL_NONSG_IO_CDB
  219. */
  220. int (*map_task_non_SG)(struct se_task *);
  221. /*
  222. * For SCF_SCSI_DATA_SG_IO_CDB and SCF_SCSI_CONTROL_SG_IO_CDB
  223. */
  224. int (*map_task_SG)(struct se_task *);
  225. /*
  226. * attach_hba():
  227. */
  228. int (*attach_hba)(struct se_hba *, u32);
  229. /*
  230. * detach_hba():
  231. */
  232. void (*detach_hba)(struct se_hba *);
  233. /*
  234. * pmode_hba(): Used for TCM/pSCSI subsystem plugin HBA ->
  235. * Linux/SCSI struct Scsi_Host passthrough
  236. */
  237. int (*pmode_enable_hba)(struct se_hba *, unsigned long);
  238. /*
  239. * allocate_virtdevice():
  240. */
  241. void *(*allocate_virtdevice)(struct se_hba *, const char *);
  242. /*
  243. * create_virtdevice(): Only for Virtual HBAs
  244. */
  245. struct se_device *(*create_virtdevice)(struct se_hba *,
  246. struct se_subsystem_dev *, void *);
  247. /*
  248. * free_device():
  249. */
  250. void (*free_device)(void *);
  251. /*
  252. * dpo_emulated():
  253. */
  254. int (*dpo_emulated)(struct se_device *);
  255. /*
  256. * fua_write_emulated():
  257. */
  258. int (*fua_write_emulated)(struct se_device *);
  259. /*
  260. * fua_read_emulated():
  261. */
  262. int (*fua_read_emulated)(struct se_device *);
  263. /*
  264. * write_cache_emulated():
  265. */
  266. int (*write_cache_emulated)(struct se_device *);
  267. /*
  268. * transport_complete():
  269. *
  270. * Use transport_generic_complete() for majority of DAS transport
  271. * drivers. Provided out of convenience.
  272. */
  273. int (*transport_complete)(struct se_task *task);
  274. struct se_task *(*alloc_task)(struct se_cmd *);
  275. /*
  276. * do_task():
  277. */
  278. int (*do_task)(struct se_task *);
  279. /*
  280. * Used by virtual subsystem plugins IBLOCK and FILEIO to emulate
  281. * UNMAP and WRITE_SAME_* w/ UNMAP=1 <-> Linux/Block Discard
  282. */
  283. int (*do_discard)(struct se_device *, sector_t, u32);
  284. /*
  285. * Used by virtual subsystem plugins IBLOCK and FILEIO to emulate
  286. * SYNCHRONIZE_CACHE_* <-> Linux/Block blkdev_issue_flush()
  287. */
  288. void (*do_sync_cache)(struct se_task *);
  289. /*
  290. * free_task():
  291. */
  292. void (*free_task)(struct se_task *);
  293. /*
  294. * check_configfs_dev_params():
  295. */
  296. ssize_t (*check_configfs_dev_params)(struct se_hba *, struct se_subsystem_dev *);
  297. /*
  298. * set_configfs_dev_params():
  299. */
  300. ssize_t (*set_configfs_dev_params)(struct se_hba *, struct se_subsystem_dev *,
  301. const char *, ssize_t);
  302. /*
  303. * show_configfs_dev_params():
  304. */
  305. ssize_t (*show_configfs_dev_params)(struct se_hba *, struct se_subsystem_dev *,
  306. char *);
  307. /*
  308. * get_cdb():
  309. */
  310. unsigned char *(*get_cdb)(struct se_task *);
  311. /*
  312. * get_device_rev():
  313. */
  314. u32 (*get_device_rev)(struct se_device *);
  315. /*
  316. * get_device_type():
  317. */
  318. u32 (*get_device_type)(struct se_device *);
  319. /*
  320. * Get the sector_t from a subsystem backstore..
  321. */
  322. sector_t (*get_blocks)(struct se_device *);
  323. /*
  324. * do_se_mem_map():
  325. */
  326. int (*do_se_mem_map)(struct se_task *, struct list_head *, void *,
  327. struct se_mem *, struct se_mem **, u32 *, u32 *);
  328. /*
  329. * get_sense_buffer():
  330. */
  331. unsigned char *(*get_sense_buffer)(struct se_task *);
  332. } ____cacheline_aligned;
  333. #define TRANSPORT(dev) ((dev)->transport)
  334. #define HBA_TRANSPORT(hba) ((hba)->transport)
  335. extern struct se_global *se_global;
  336. #endif /* TARGET_CORE_TRANSPORT_H */