Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 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 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 48 | /* |
| 49 | * struct se_subsystem_dev->su_dev_flags |
| 50 | */ |
| 51 | #define SDF_FIRMWARE_VPD_UNIT_SERIAL 0x00000001 |
| 52 | #define SDF_EMULATED_VPD_UNIT_SERIAL 0x00000002 |
| 53 | #define SDF_USING_UDEV_PATH 0x00000004 |
| 54 | #define SDF_USING_ALIAS 0x00000008 |
| 55 | |
| 56 | /* |
| 57 | * struct se_device->dev_flags |
| 58 | */ |
| 59 | #define DF_READ_ONLY 0x00000001 |
| 60 | #define DF_SPC2_RESERVATIONS 0x00000002 |
| 61 | #define DF_SPC2_RESERVATIONS_WITH_ISID 0x00000004 |
| 62 | |
| 63 | /* struct se_dev_attrib sanity values */ |
| 64 | /* 10 Minutes */ |
| 65 | #define DA_TASK_TIMEOUT_MAX 600 |
| 66 | /* Default max_unmap_lba_count */ |
| 67 | #define DA_MAX_UNMAP_LBA_COUNT 0 |
| 68 | /* Default max_unmap_block_desc_count */ |
| 69 | #define DA_MAX_UNMAP_BLOCK_DESC_COUNT 0 |
| 70 | /* Default unmap_granularity */ |
| 71 | #define DA_UNMAP_GRANULARITY_DEFAULT 0 |
| 72 | /* Default unmap_granularity_alignment */ |
| 73 | #define DA_UNMAP_GRANULARITY_ALIGNMENT_DEFAULT 0 |
| 74 | /* Emulation for Direct Page Out */ |
| 75 | #define DA_EMULATE_DPO 0 |
| 76 | /* Emulation for Forced Unit Access WRITEs */ |
| 77 | #define DA_EMULATE_FUA_WRITE 1 |
| 78 | /* Emulation for Forced Unit Access READs */ |
| 79 | #define DA_EMULATE_FUA_READ 0 |
| 80 | /* Emulation for WriteCache and SYNCHRONIZE_CACHE */ |
| 81 | #define DA_EMULATE_WRITE_CACHE 0 |
| 82 | /* Emulation for UNIT ATTENTION Interlock Control */ |
| 83 | #define DA_EMULATE_UA_INTLLCK_CTRL 0 |
| 84 | /* Emulation for TASK_ABORTED status (TAS) by default */ |
| 85 | #define DA_EMULATE_TAS 1 |
| 86 | /* Emulation for Thin Provisioning UNMAP using block/blk-lib.c:blkdev_issue_discard() */ |
| 87 | #define DA_EMULATE_TPU 0 |
| 88 | /* |
| 89 | * Emulation for Thin Provisioning WRITE_SAME w/ UNMAP=1 bit using |
| 90 | * block/blk-lib.c:blkdev_issue_discard() |
| 91 | */ |
| 92 | #define DA_EMULATE_TPWS 0 |
| 93 | /* No Emulation for PSCSI by default */ |
| 94 | #define DA_EMULATE_RESERVATIONS 0 |
| 95 | /* No Emulation for PSCSI by default */ |
| 96 | #define DA_EMULATE_ALUA 0 |
| 97 | /* Enforce SCSI Initiator Port TransportID with 'ISID' for PR */ |
| 98 | #define DA_ENFORCE_PR_ISIDS 1 |
| 99 | #define DA_STATUS_MAX_SECTORS_MIN 16 |
| 100 | #define DA_STATUS_MAX_SECTORS_MAX 8192 |
Roland Dreier | e22a7f0 | 2011-07-05 13:34:52 -0700 | [diff] [blame] | 101 | /* By default don't report non-rotating (solid state) medium */ |
| 102 | #define DA_IS_NONROT 0 |
Nicholas Bellinger | 5de619a | 2011-07-17 02:57:58 -0700 | [diff] [blame] | 103 | /* Queue Algorithm Modifier default for restricted reordering in control mode page */ |
| 104 | #define DA_EMULATE_REST_REORD 0 |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 105 | |
| 106 | #define SE_MODE_PAGE_BUF 512 |
| 107 | |
| 108 | #define MOD_MAX_SECTORS(ms, bs) (ms % (PAGE_SIZE / bs)) |
| 109 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 110 | struct se_subsystem_api; |
| 111 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 112 | extern int init_se_kmem_caches(void); |
| 113 | extern void release_se_kmem_caches(void); |
Nicholas Bellinger | e89d15e | 2011-02-09 15:35:03 -0800 | [diff] [blame] | 114 | extern u32 scsi_get_new_index(scsi_index_t); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 115 | extern void transport_init_queue_obj(struct se_queue_obj *); |
Nicholas Bellinger | dbc5623 | 2011-10-22 01:03:54 -0700 | [diff] [blame^] | 116 | extern void transport_subsystem_check_init(void); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 117 | extern int transport_subsystem_register(struct se_subsystem_api *); |
| 118 | extern void transport_subsystem_release(struct se_subsystem_api *); |
| 119 | extern void transport_load_plugins(void); |
| 120 | extern struct se_session *transport_init_session(void); |
| 121 | extern void __transport_register_session(struct se_portal_group *, |
| 122 | struct se_node_acl *, |
| 123 | struct se_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_free_session(struct se_session *); |
| 128 | extern void transport_deregister_session_configfs(struct se_session *); |
| 129 | extern void transport_deregister_session(struct se_session *); |
| 130 | extern void transport_cmd_finish_abort(struct se_cmd *, int); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 131 | extern void transport_complete_sync_cache(struct se_cmd *, int); |
| 132 | extern void transport_complete_task(struct se_task *, int); |
| 133 | extern void transport_add_task_to_execute_queue(struct se_task *, |
| 134 | struct se_task *, |
| 135 | struct se_device *); |
Nicholas Bellinger | 52208ae | 2011-02-24 16:58:20 -0800 | [diff] [blame] | 136 | extern void transport_remove_task_from_execute_queue(struct se_task *, |
| 137 | struct se_device *); |
Christoph Hellwig | 04629b7 | 2011-10-12 11:07:04 -0400 | [diff] [blame] | 138 | extern void __transport_remove_task_from_execute_queue(struct se_task *, |
| 139 | struct se_device *); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 140 | unsigned char *transport_dump_cmd_direction(struct se_cmd *); |
| 141 | extern void transport_dump_dev_state(struct se_device *, char *, int *); |
| 142 | extern void transport_dump_dev_info(struct se_device *, struct se_lun *, |
| 143 | unsigned long long, char *, int *); |
| 144 | extern void transport_dump_vpd_proto_id(struct t10_vpd *, |
| 145 | unsigned char *, int); |
| 146 | extern void transport_set_vpd_proto_id(struct t10_vpd *, unsigned char *); |
| 147 | extern int transport_dump_vpd_assoc(struct t10_vpd *, |
| 148 | unsigned char *, int); |
| 149 | extern int transport_set_vpd_assoc(struct t10_vpd *, unsigned char *); |
| 150 | extern int transport_dump_vpd_ident_type(struct t10_vpd *, |
| 151 | unsigned char *, int); |
| 152 | extern int transport_set_vpd_ident_type(struct t10_vpd *, unsigned char *); |
| 153 | extern int transport_dump_vpd_ident(struct t10_vpd *, |
| 154 | unsigned char *, int); |
| 155 | extern int transport_set_vpd_ident(struct t10_vpd *, unsigned char *); |
| 156 | extern struct se_device *transport_add_device_to_core_hba(struct se_hba *, |
| 157 | struct se_subsystem_api *, |
| 158 | struct se_subsystem_dev *, u32, |
| 159 | void *, struct se_dev_limits *, |
| 160 | const char *, const char *); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 161 | extern void transport_init_se_cmd(struct se_cmd *, |
| 162 | struct target_core_fabric_ops *, |
| 163 | struct se_session *, u32, int, int, |
| 164 | unsigned char *); |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 165 | void *transport_kmap_first_data_page(struct se_cmd *cmd); |
| 166 | void transport_kunmap_first_data_page(struct se_cmd *cmd); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 167 | extern int transport_generic_allocate_tasks(struct se_cmd *, unsigned char *); |
Nicholas Bellinger | 695434e1 | 2011-06-03 20:59:19 -0700 | [diff] [blame] | 168 | extern int transport_handle_cdb_direct(struct se_cmd *); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 169 | extern int transport_generic_handle_cdb_map(struct se_cmd *); |
| 170 | extern int transport_generic_handle_data(struct se_cmd *); |
| 171 | extern void transport_new_cmd_failure(struct se_cmd *); |
| 172 | extern int transport_generic_handle_tmr(struct se_cmd *); |
Nicholas Bellinger | f436677 | 2011-05-19 20:19:11 -0700 | [diff] [blame] | 173 | extern void transport_generic_free_cmd_intr(struct se_cmd *); |
Christoph Hellwig | cdbb70b | 2011-10-17 13:56:46 -0400 | [diff] [blame] | 174 | extern bool target_stop_task(struct se_task *task, unsigned long *flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 175 | extern int transport_generic_map_mem_to_cmd(struct se_cmd *cmd, struct scatterlist *, u32, |
| 176 | struct scatterlist *, u32); |
| 177 | extern int transport_clear_lun_from_sessions(struct se_lun *); |
Nicholas Bellinger | d14921d | 2011-10-09 01:00:58 -0700 | [diff] [blame] | 178 | extern void transport_wait_for_tasks(struct se_cmd *); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 179 | extern int transport_check_aborted_status(struct se_cmd *, int); |
| 180 | extern int transport_send_check_condition_and_sense(struct se_cmd *, u8, int); |
| 181 | extern void transport_send_task_abort(struct se_cmd *); |
Christoph Hellwig | 3546297 | 2011-05-31 23:56:57 -0400 | [diff] [blame] | 182 | extern void transport_release_cmd(struct se_cmd *); |
Nicholas Bellinger | 39c05f3 | 2011-10-08 13:59:52 -0700 | [diff] [blame] | 183 | extern void transport_generic_free_cmd(struct se_cmd *, int); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 184 | extern void transport_generic_wait_for_cmds(struct se_cmd *, int); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 185 | extern void transport_do_task_sg_chain(struct se_cmd *); |
| 186 | extern void transport_generic_process_write(struct se_cmd *); |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 187 | extern int transport_generic_new_cmd(struct se_cmd *); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 188 | extern int transport_generic_do_tmr(struct se_cmd *); |
| 189 | /* From target_core_alua.c */ |
| 190 | extern int core_alua_check_nonop_delay(struct se_cmd *); |
Dan Carpenter | 5dd7ed2 | 2011-03-14 04:06:01 -0700 | [diff] [blame] | 191 | /* From target_core_cdb.c */ |
| 192 | extern int transport_emulate_control_cdb(struct se_task *); |
Christoph Hellwig | 485fd0d | 2011-10-12 11:09:12 -0400 | [diff] [blame] | 193 | extern void target_get_task_cdb(struct se_task *task, unsigned char *cdb); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 194 | |
| 195 | /* |
| 196 | * Each se_transport_task_t can have N number of possible struct se_task's |
| 197 | * for the storage transport(s) to possibly execute. |
| 198 | * Used primarily for splitting up CDBs that exceed the physical storage |
| 199 | * HBA's maximum sector count per task. |
| 200 | */ |
| 201 | struct se_mem { |
| 202 | struct page *se_page; |
| 203 | u32 se_len; |
| 204 | u32 se_off; |
| 205 | struct list_head se_list; |
| 206 | } ____cacheline_aligned; |
| 207 | |
| 208 | /* |
| 209 | * Each type of disk transport supported MUST have a template defined |
| 210 | * within its .h file. |
| 211 | */ |
| 212 | struct se_subsystem_api { |
| 213 | /* |
| 214 | * The Name. :-) |
| 215 | */ |
| 216 | char name[16]; |
| 217 | /* |
| 218 | * Transport Type. |
| 219 | */ |
| 220 | u8 transport_type; |
Christoph Hellwig | f55918f | 2011-10-14 07:30:17 -0400 | [diff] [blame] | 221 | |
| 222 | unsigned int fua_write_emulated : 1; |
| 223 | unsigned int write_cache_emulated : 1; |
| 224 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 225 | /* |
| 226 | * struct module for struct se_hba references |
| 227 | */ |
| 228 | struct module *owner; |
| 229 | /* |
| 230 | * Used for global se_subsystem_api list_head |
| 231 | */ |
| 232 | struct list_head sub_api_list; |
| 233 | /* |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 234 | * attach_hba(): |
| 235 | */ |
| 236 | int (*attach_hba)(struct se_hba *, u32); |
| 237 | /* |
| 238 | * detach_hba(): |
| 239 | */ |
| 240 | void (*detach_hba)(struct se_hba *); |
| 241 | /* |
| 242 | * pmode_hba(): Used for TCM/pSCSI subsystem plugin HBA -> |
| 243 | * Linux/SCSI struct Scsi_Host passthrough |
| 244 | */ |
| 245 | int (*pmode_enable_hba)(struct se_hba *, unsigned long); |
| 246 | /* |
| 247 | * allocate_virtdevice(): |
| 248 | */ |
| 249 | void *(*allocate_virtdevice)(struct se_hba *, const char *); |
| 250 | /* |
| 251 | * create_virtdevice(): Only for Virtual HBAs |
| 252 | */ |
| 253 | struct se_device *(*create_virtdevice)(struct se_hba *, |
| 254 | struct se_subsystem_dev *, void *); |
| 255 | /* |
| 256 | * free_device(): |
| 257 | */ |
| 258 | void (*free_device)(void *); |
| 259 | |
| 260 | /* |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 261 | * transport_complete(): |
| 262 | * |
| 263 | * Use transport_generic_complete() for majority of DAS transport |
| 264 | * drivers. Provided out of convenience. |
| 265 | */ |
| 266 | int (*transport_complete)(struct se_task *task); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 267 | struct se_task *(*alloc_task)(unsigned char *cdb); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 268 | /* |
| 269 | * do_task(): |
| 270 | */ |
| 271 | int (*do_task)(struct se_task *); |
| 272 | /* |
| 273 | * Used by virtual subsystem plugins IBLOCK and FILEIO to emulate |
| 274 | * UNMAP and WRITE_SAME_* w/ UNMAP=1 <-> Linux/Block Discard |
| 275 | */ |
| 276 | int (*do_discard)(struct se_device *, sector_t, u32); |
| 277 | /* |
| 278 | * Used by virtual subsystem plugins IBLOCK and FILEIO to emulate |
| 279 | * SYNCHRONIZE_CACHE_* <-> Linux/Block blkdev_issue_flush() |
| 280 | */ |
| 281 | void (*do_sync_cache)(struct se_task *); |
| 282 | /* |
| 283 | * free_task(): |
| 284 | */ |
| 285 | void (*free_task)(struct se_task *); |
| 286 | /* |
| 287 | * check_configfs_dev_params(): |
| 288 | */ |
| 289 | ssize_t (*check_configfs_dev_params)(struct se_hba *, struct se_subsystem_dev *); |
| 290 | /* |
| 291 | * set_configfs_dev_params(): |
| 292 | */ |
| 293 | ssize_t (*set_configfs_dev_params)(struct se_hba *, struct se_subsystem_dev *, |
| 294 | const char *, ssize_t); |
| 295 | /* |
| 296 | * show_configfs_dev_params(): |
| 297 | */ |
| 298 | ssize_t (*show_configfs_dev_params)(struct se_hba *, struct se_subsystem_dev *, |
| 299 | char *); |
| 300 | /* |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 301 | * get_device_rev(): |
| 302 | */ |
| 303 | u32 (*get_device_rev)(struct se_device *); |
| 304 | /* |
| 305 | * get_device_type(): |
| 306 | */ |
| 307 | u32 (*get_device_type)(struct se_device *); |
| 308 | /* |
| 309 | * Get the sector_t from a subsystem backstore.. |
| 310 | */ |
| 311 | sector_t (*get_blocks)(struct se_device *); |
| 312 | /* |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 313 | * get_sense_buffer(): |
| 314 | */ |
| 315 | unsigned char *(*get_sense_buffer)(struct se_task *); |
| 316 | } ____cacheline_aligned; |
| 317 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 318 | #endif /* TARGET_CORE_TRANSPORT_H */ |