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