ctl_io.h revision 288730
1/*- 2 * Copyright (c) 2003 Silicon Graphics International Corp. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions, and the following disclaimer, 10 * without modification. 11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12 * substantially similar to the "NO WARRANTY" disclaimer below 13 * ("Disclaimer") and any redistribution must be conditioned upon 14 * including a substantially similar Disclaimer requirement for further 15 * binary redistribution. 16 * 17 * NO WARRANTY 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGES. 29 * 30 * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_io.h#5 $ 31 * $FreeBSD: stable/10/sys/cam/ctl/ctl_io.h 288730 2015-10-05 08:55:00Z mav $ 32 */ 33/* 34 * CAM Target Layer data movement structures/interface. 35 * 36 * Author: Ken Merry <ken@FreeBSD.org> 37 */ 38 39#ifndef _CTL_IO_H_ 40#define _CTL_IO_H_ 41 42#ifdef _CTL_C 43#define EXTERN(__var,__val) __var = __val 44#else 45#define EXTERN(__var,__val) extern __var 46#endif 47 48#define CTL_MAX_CDBLEN 32 49/* 50 * Uncomment this next line to enable printing out times for I/Os 51 * that take longer than CTL_TIME_IO_SECS seconds to get to the datamove 52 * and/or done stage. 53 */ 54#define CTL_TIME_IO 55#ifdef CTL_TIME_IO 56#define CTL_TIME_IO_DEFAULT_SECS 90 57EXTERN(int ctl_time_io_secs, CTL_TIME_IO_DEFAULT_SECS); 58#endif 59 60/* 61 * Uncomment this next line to enable the CTL I/O delay feature. You 62 * can delay I/O at two different points -- datamove and done. This is 63 * useful for diagnosing abort conditions (for hosts that send an abort on a 64 * timeout), and for determining how long a host's timeout is. 65 */ 66//#define CTL_IO_DELAY 67 68typedef enum { 69 CTL_STATUS_NONE, /* No status */ 70 CTL_SUCCESS, /* Transaction completed successfully */ 71 CTL_CMD_TIMEOUT, /* Command timed out, shouldn't happen here */ 72 CTL_SEL_TIMEOUT, /* Selection timeout, shouldn't happen here */ 73 CTL_ERROR, /* General CTL error XXX expand on this? */ 74 CTL_SCSI_ERROR, /* SCSI error, look at status byte/sense data */ 75 CTL_CMD_ABORTED, /* Command aborted, don't return status */ 76 CTL_STATUS_MASK = 0xfff,/* Mask off any status flags */ 77 CTL_AUTOSENSE = 0x1000 /* Autosense performed */ 78} ctl_io_status; 79 80/* 81 * WARNING: Keep the data in/out/none flags where they are. They're used 82 * in conjuction with ctl_cmd_flags. See comment above ctl_cmd_flags 83 * definition in ctl_private.h. 84 */ 85typedef enum { 86 CTL_FLAG_NONE = 0x00000000, /* no flags */ 87 CTL_FLAG_DATA_IN = 0x00000001, /* DATA IN */ 88 CTL_FLAG_DATA_OUT = 0x00000002, /* DATA OUT */ 89 CTL_FLAG_DATA_NONE = 0x00000003, /* no data */ 90 CTL_FLAG_DATA_MASK = 0x00000003, 91 CTL_FLAG_KDPTR_SGLIST = 0x00000008, /* kern_data_ptr is S/G list*/ 92 CTL_FLAG_EDPTR_SGLIST = 0x00000010, /* ext_data_ptr is S/G list */ 93 CTL_FLAG_DO_AUTOSENSE = 0x00000020, /* grab sense info */ 94 CTL_FLAG_USER_REQ = 0x00000040, /* request came from userland */ 95 CTL_FLAG_CONTROL_DEV = 0x00000080, /* processor device */ 96 CTL_FLAG_ALLOCATED = 0x00000100, /* data space allocated */ 97 CTL_FLAG_BLOCKED = 0x00000200, /* on the blocked queue */ 98 CTL_FLAG_ABORT_STATUS = 0x00000400, /* return TASK ABORTED status */ 99 CTL_FLAG_ABORT = 0x00000800, /* this I/O should be aborted */ 100 CTL_FLAG_DMA_INPROG = 0x00001000, /* DMA in progress */ 101 CTL_FLAG_NO_DATASYNC = 0x00002000, /* don't cache flush data */ 102 CTL_FLAG_DELAY_DONE = 0x00004000, /* delay injection done */ 103 CTL_FLAG_INT_COPY = 0x00008000, /* internal copy, no done call*/ 104 CTL_FLAG_SENT_2OTHER_SC = 0x00010000, 105 CTL_FLAG_FROM_OTHER_SC = 0x00020000, 106 CTL_FLAG_IS_WAS_ON_RTR = 0x00040000, /* Don't rerun cmd on failover*/ 107 CTL_FLAG_BUS_ADDR = 0x00080000, /* ctl_sglist contains BUS 108 addresses, not virtual ones*/ 109 CTL_FLAG_IO_CONT = 0x00100000, /* Continue I/O instead of 110 completing */ 111 CTL_FLAG_AUTO_MIRROR = 0x00200000, /* Automatically use memory 112 from the RC cache mirrored 113 address area. */ 114#if 0 115 CTL_FLAG_ALREADY_DONE = 0x00200000 /* I/O already completed */ 116#endif 117 CTL_FLAG_NO_DATAMOVE = 0x00400000, 118 CTL_FLAG_DMA_QUEUED = 0x00800000, /* DMA queued but not started*/ 119 CTL_FLAG_STATUS_QUEUED = 0x01000000, /* Status queued but not sent*/ 120 121 CTL_FLAG_REDIR_DONE = 0x02000000, /* Redirection has already 122 been done. */ 123 CTL_FLAG_FAILOVER = 0x04000000, /* Killed by a failover */ 124 CTL_FLAG_IO_ACTIVE = 0x08000000, /* I/O active on this SC */ 125 CTL_FLAG_RDMA_MASK = CTL_FLAG_NO_DATASYNC | CTL_FLAG_BUS_ADDR | 126 CTL_FLAG_AUTO_MIRROR | CTL_FLAG_REDIR_DONE, 127 /* Flags we care about for 128 remote DMA */ 129 CTL_FLAG_STATUS_SENT = 0x10000000 /* Status sent by datamove */ 130} ctl_io_flags; 131 132 133struct ctl_lba_len { 134 uint64_t lba; 135 uint32_t len; 136}; 137 138struct ctl_lba_len_flags { 139 uint64_t lba; 140 uint32_t len; 141 uint32_t flags; 142#define CTL_LLF_FUA 0x04000000 143#define CTL_LLF_DPO 0x08000000 144#define CTL_LLF_READ 0x10000000 145#define CTL_LLF_WRITE 0x20000000 146#define CTL_LLF_VERIFY 0x40000000 147#define CTL_LLF_COMPARE 0x80000000 148}; 149 150struct ctl_ptr_len_flags { 151 uint8_t *ptr; 152 uint32_t len; 153 uint32_t flags; 154}; 155 156union ctl_priv { 157 uint8_t bytes[sizeof(uint64_t) * 2]; 158 uint64_t integer; 159 void *ptr; 160}; 161 162/* 163 * Number of CTL private areas. 164 */ 165#define CTL_NUM_PRIV 6 166 167/* 168 * Which private area are we using for a particular piece of data? 169 */ 170#define CTL_PRIV_LUN 0 /* CTL LUN pointer goes here */ 171#define CTL_PRIV_LBA_LEN 1 /* Decoded LBA/len for read/write*/ 172#define CTL_PRIV_MODEPAGE 1 /* Modepage info for config write */ 173#define CTL_PRIV_BACKEND 2 /* Reserved for block, RAIDCore */ 174#define CTL_PRIV_BACKEND_LUN 3 /* Backend LUN pointer */ 175#define CTL_PRIV_FRONTEND 4 /* Frontend storage */ 176#define CTL_PRIV_FRONTEND2 5 /* Another frontend storage */ 177 178#define CTL_INVALID_PORTNAME 0xFF 179#define CTL_UNMAPPED_IID 0xFF 180 181struct ctl_sg_entry { 182 void *addr; 183 size_t len; 184}; 185 186struct ctl_id { 187 uint32_t id; 188 uint64_t wwid[2]; 189}; 190 191typedef enum { 192 CTL_IO_NONE, 193 CTL_IO_SCSI, 194 CTL_IO_TASK, 195} ctl_io_type; 196 197struct ctl_nexus { 198 struct ctl_id initid; /* Initiator ID */ 199 uint32_t targ_port; /* Target port, filled in by PORT */ 200 struct ctl_id targ_target; /* Destination target */ 201 uint32_t targ_lun; /* Destination lun */ 202 uint32_t targ_mapped_lun; /* Destination lun CTL-wide */ 203}; 204 205typedef enum { 206 CTL_MSG_SERIALIZE, 207 CTL_MSG_R2R, 208 CTL_MSG_FINISH_IO, 209 CTL_MSG_BAD_JUJU, 210 CTL_MSG_MANAGE_TASKS, 211 CTL_MSG_PERS_ACTION, 212 CTL_MSG_SYNC_FE, 213 CTL_MSG_DATAMOVE, 214 CTL_MSG_DATAMOVE_DONE 215} ctl_msg_type; 216 217struct ctl_scsiio; 218 219#define CTL_NUM_SG_ENTRIES 9 220 221struct ctl_io_hdr { 222 uint32_t version; /* interface version XXX */ 223 ctl_io_type io_type; /* task I/O, SCSI I/O, etc. */ 224 ctl_msg_type msg_type; 225 struct ctl_nexus nexus; /* Initiator, port, target, lun */ 226 uint32_t iid_indx; /* the index into the iid mapping */ 227 uint32_t flags; /* transaction flags */ 228 uint32_t status; /* transaction status */ 229 uint32_t port_status; /* trans status, set by PORT, 0 = good*/ 230 uint32_t timeout; /* timeout in ms */ 231 uint32_t retries; /* retry count */ 232#ifdef CTL_IO_DELAY 233 struct callout delay_callout; 234#endif /* CTL_IO_DELAY */ 235#ifdef CTL_TIME_IO 236 time_t start_time; /* I/O start time */ 237 struct bintime start_bt; /* Timer start ticks */ 238 struct bintime dma_start_bt; /* DMA start ticks */ 239 struct bintime dma_bt; /* DMA total ticks */ 240 uint32_t num_dmas; /* Number of DMAs */ 241#endif /* CTL_TIME_IO */ 242 union ctl_io *original_sc; 243 union ctl_io *serializing_sc; 244 void *pool; /* I/O pool */ 245 union ctl_priv ctl_private[CTL_NUM_PRIV];/* CTL private area */ 246 struct ctl_sg_entry remote_sglist[CTL_NUM_SG_ENTRIES]; 247 struct ctl_sg_entry remote_dma_sglist[CTL_NUM_SG_ENTRIES]; 248 struct ctl_sg_entry local_sglist[CTL_NUM_SG_ENTRIES]; 249 struct ctl_sg_entry local_dma_sglist[CTL_NUM_SG_ENTRIES]; 250 STAILQ_ENTRY(ctl_io_hdr) links; /* linked list pointer */ 251 TAILQ_ENTRY(ctl_io_hdr) ooa_links; 252 TAILQ_ENTRY(ctl_io_hdr) blocked_links; 253}; 254 255typedef enum { 256 CTL_TAG_UNTAGGED, 257 CTL_TAG_SIMPLE, 258 CTL_TAG_ORDERED, 259 CTL_TAG_HEAD_OF_QUEUE, 260 CTL_TAG_ACA 261} ctl_tag_type; 262 263union ctl_io; 264 265/* 266 * SCSI passthrough I/O structure for the CAM Target Layer. Note 267 * that some of these fields are here for completeness, but they aren't 268 * used in the CTL implementation. e.g., timeout and retries won't be 269 * used. 270 * 271 * Note: Make sure the io_hdr is *always* the first element in this 272 * structure. 273 */ 274struct ctl_scsiio { 275 struct ctl_io_hdr io_hdr; /* common to all I/O types */ 276 277 /* 278 * The ext_* fields are generally intended for frontend use; CTL itself 279 * doesn't modify or use them. 280 */ 281 uint32_t ext_sg_entries; /* 0 = no S/G list, > 0 = num entries */ 282 uint8_t *ext_data_ptr; /* data buffer or S/G list */ 283 uint32_t ext_data_len; /* Data transfer length */ 284 uint32_t ext_data_filled; /* Amount of data filled so far */ 285 286 /* 287 * The number of scatter/gather entries in the list pointed to 288 * by kern_data_ptr. 0 means there is no list, just a data pointer. 289 */ 290 uint32_t kern_sg_entries; 291 292 uint32_t rem_sg_entries; /* Unused. */ 293 294 /* 295 * The data pointer or a pointer to the scatter/gather list. 296 */ 297 uint8_t *kern_data_ptr; 298 299 /* 300 * Length of the data buffer or scatter/gather list. It's also 301 * the length of this particular piece of the data transfer, 302 * ie. number of bytes expected to be transferred by the current 303 * invocation of frontend's datamove() callback. It's always 304 * less than or equal to kern_total_len. 305 */ 306 uint32_t kern_data_len; 307 308 /* 309 * Total length of data to be transferred during this particular 310 * SCSI command, as decoded from SCSI CDB. 311 */ 312 uint32_t kern_total_len; 313 314 /* 315 * Amount of data left after the current data transfer. 316 */ 317 uint32_t kern_data_resid; 318 319 /* 320 * Byte offset of this transfer, equal to the amount of data 321 * already transferred for this SCSI command during previous 322 * datamove() invocations. 323 */ 324 uint32_t kern_rel_offset; 325 326 struct scsi_sense_data sense_data; /* sense data */ 327 uint8_t sense_len; /* Returned sense length */ 328 uint8_t scsi_status; /* SCSI status byte */ 329 uint8_t sense_residual; /* Unused. */ 330 uint32_t residual; /* data residual length */ 331 uint32_t tag_num; /* tag number */ 332 ctl_tag_type tag_type; /* simple, ordered, head of queue,etc.*/ 333 uint8_t cdb_len; /* CDB length */ 334 uint8_t cdb[CTL_MAX_CDBLEN]; /* CDB */ 335 int (*be_move_done)(union ctl_io *io); /* called by fe */ 336 int (*io_cont)(union ctl_io *io); /* to continue processing */ 337}; 338 339typedef enum { 340 CTL_TASK_ABORT_TASK, 341 CTL_TASK_ABORT_TASK_SET, 342 CTL_TASK_CLEAR_ACA, 343 CTL_TASK_CLEAR_TASK_SET, 344 CTL_TASK_I_T_NEXUS_RESET, 345 CTL_TASK_LUN_RESET, 346 CTL_TASK_TARGET_RESET, 347 CTL_TASK_BUS_RESET, 348 CTL_TASK_PORT_LOGIN, 349 CTL_TASK_PORT_LOGOUT 350} ctl_task_type; 351 352/* 353 * Task management I/O structure. Aborts, bus resets, etc., are sent using 354 * this structure. 355 * 356 * Note: Make sure the io_hdr is *always* the first element in this 357 * structure. 358 */ 359struct ctl_taskio { 360 struct ctl_io_hdr io_hdr; /* common to all I/O types */ 361 ctl_task_type task_action; /* Target Reset, Abort, etc. */ 362 uint32_t tag_num; /* tag number */ 363 ctl_tag_type tag_type; /* simple, ordered, etc. */ 364}; 365 366typedef enum { 367 CTL_PR_REG_KEY, 368 CTL_PR_UNREG_KEY, 369 CTL_PR_PREEMPT, 370 CTL_PR_CLEAR, 371 CTL_PR_RESERVE, 372 CTL_PR_RELEASE 373} ctl_pr_action; 374 375/* 376 * The PR info is specifically for sending Persistent Reserve actions 377 * to the other SC which it must also act on. 378 * 379 * Note: Make sure the io_hdr is *always* the first element in this 380 * structure. 381 */ 382struct ctl_pr_info { 383 ctl_pr_action action; 384 uint8_t sa_res_key[8]; 385 uint8_t res_type; 386 uint32_t residx; 387}; 388 389struct ctl_ha_msg_hdr { 390 ctl_msg_type msg_type; 391 union ctl_io *original_sc; 392 union ctl_io *serializing_sc; 393 struct ctl_nexus nexus; /* Initiator, port, target, lun */ 394 uint32_t status; /* transaction status */ 395 TAILQ_ENTRY(ctl_ha_msg_hdr) links; 396}; 397 398#define CTL_HA_MAX_SG_ENTRIES 16 399 400/* 401 * Used for CTL_MSG_PERS_ACTION. 402 */ 403struct ctl_ha_msg_pr { 404 struct ctl_ha_msg_hdr hdr; 405 struct ctl_pr_info pr_info; 406}; 407 408/* 409 * The S/G handling here is a little different than the standard ctl_scsiio 410 * structure, because we can't pass data by reference in between controllers. 411 * The S/G list in the ctl_scsiio struct is normally passed in the 412 * kern_data_ptr field. So kern_sg_entries here will always be non-zero, 413 * even if there is only one entry. 414 * 415 * Used for CTL_MSG_DATAMOVE. 416 */ 417struct ctl_ha_msg_dt { 418 struct ctl_ha_msg_hdr hdr; 419 ctl_io_flags flags; /* Only I/O flags are used here */ 420 uint32_t sg_sequence; /* S/G portion number */ 421 uint8_t sg_last; /* last S/G batch = 1 */ 422 uint32_t sent_sg_entries; /* previous S/G count */ 423 uint32_t cur_sg_entries; /* current S/G entries */ 424 uint32_t kern_sg_entries; /* total S/G entries */ 425 uint32_t kern_data_len; /* Length of this S/G list */ 426 uint32_t kern_total_len; /* Total length of this 427 transaction */ 428 uint32_t kern_data_resid; /* Length left to transfer 429 after this*/ 430 uint32_t kern_rel_offset; /* Byte Offset of this 431 transfer */ 432 struct ctl_sg_entry sg_list[CTL_HA_MAX_SG_ENTRIES]; 433}; 434 435/* 436 * Used for CTL_MSG_SERIALIZE, CTL_MSG_FINISH_IO, CTL_MSG_BAD_JUJU. 437 */ 438struct ctl_ha_msg_scsi { 439 struct ctl_ha_msg_hdr hdr; 440 uint8_t cdb[CTL_MAX_CDBLEN]; /* CDB */ 441 uint32_t tag_num; /* tag number */ 442 ctl_tag_type tag_type; /* simple, ordered, etc. */ 443 uint8_t scsi_status; /* SCSI status byte */ 444 struct scsi_sense_data sense_data; /* sense data */ 445 uint8_t sense_len; /* Returned sense length */ 446 uint8_t sense_residual; /* sense residual length */ 447 uint32_t residual; /* data residual length */ 448 uint32_t fetd_status; /* trans status, set by FETD, 449 0 = good*/ 450 struct ctl_lba_len lbalen; /* used for stats */ 451}; 452 453/* 454 * Used for CTL_MSG_MANAGE_TASKS. 455 */ 456struct ctl_ha_msg_task { 457 struct ctl_ha_msg_hdr hdr; 458 ctl_task_type task_action; /* Target Reset, Abort, etc. */ 459 uint32_t tag_num; /* tag number */ 460 ctl_tag_type tag_type; /* simple, ordered, etc. */ 461}; 462 463union ctl_ha_msg { 464 struct ctl_ha_msg_hdr hdr; 465 struct ctl_ha_msg_task task; 466 struct ctl_ha_msg_scsi scsi; 467 struct ctl_ha_msg_dt dt; 468 struct ctl_ha_msg_pr pr; 469}; 470 471 472struct ctl_prio { 473 struct ctl_io_hdr io_hdr; 474 struct ctl_ha_msg_pr pr_msg; 475}; 476 477 478 479union ctl_io { 480 struct ctl_io_hdr io_hdr; /* common to all I/O types */ 481 struct ctl_scsiio scsiio; /* Normal SCSI commands */ 482 struct ctl_taskio taskio; /* SCSI task management/reset */ 483 struct ctl_prio presio; /* update per. res info on other SC */ 484}; 485 486#ifdef _KERNEL 487 488union ctl_io *ctl_alloc_io(void *pool_ref); 489union ctl_io *ctl_alloc_io_nowait(void *pool_ref); 490void ctl_free_io(union ctl_io *io); 491void ctl_zero_io(union ctl_io *io); 492void ctl_copy_io(union ctl_io *src, union ctl_io *dest); 493 494#endif /* _KERNEL */ 495 496#endif /* _CTL_IO_H_ */ 497 498/* 499 * vim: ts=8 500 */ 501