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$ 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 57 EXTERN(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 68 typedef 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 */ 85 typedef 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_DO_AUTOSENSE = 0x00000020, /* grab sense info */ 92 CTL_FLAG_USER_REQ = 0x00000040, /* request came from userland */ 93 CTL_FLAG_ALLOCATED = 0x00000100, /* data space allocated */ 94 CTL_FLAG_BLOCKED = 0x00000200, /* on the blocked queue */ 95 CTL_FLAG_ABORT_STATUS = 0x00000400, /* return TASK ABORTED status */ 96 CTL_FLAG_ABORT = 0x00000800, /* this I/O should be aborted */ 97 CTL_FLAG_DMA_INPROG = 0x00001000, /* DMA in progress */ 98 CTL_FLAG_DELAY_DONE = 0x00004000, /* delay injection done */ 99 CTL_FLAG_INT_COPY = 0x00008000, /* internal copy, no done call*/ 100 CTL_FLAG_SENT_2OTHER_SC = 0x00010000, 101 CTL_FLAG_FROM_OTHER_SC = 0x00020000, 102 CTL_FLAG_IS_WAS_ON_RTR = 0x00040000, /* Don't rerun cmd on failover*/ 103 CTL_FLAG_BUS_ADDR = 0x00080000, /* ctl_sglist contains BUS 104 addresses, not virtual ones*/ 105 CTL_FLAG_IO_CONT = 0x00100000, /* Continue I/O instead of 106 completing */ 107 #if 0 108 CTL_FLAG_ALREADY_DONE = 0x00200000 /* I/O already completed */ 109 #endif 110 CTL_FLAG_NO_DATAMOVE = 0x00400000, 111 CTL_FLAG_DMA_QUEUED = 0x00800000, /* DMA queued but not started*/ 112 CTL_FLAG_STATUS_QUEUED = 0x01000000, /* Status queued but not sent*/ 113 114 CTL_FLAG_FAILOVER = 0x04000000, /* Killed by a failover */ 115 CTL_FLAG_IO_ACTIVE = 0x08000000, /* I/O active on this SC */ 116 CTL_FLAG_STATUS_SENT = 0x10000000, /* Status sent by datamove */ 117 CTL_FLAG_SERSEQ_DONE = 0x20000000 /* All storage I/O started */ 118 } ctl_io_flags; 119 120 121 struct ctl_lba_len { 122 uint64_t lba; 123 uint32_t len; 124 }; 125 126 struct ctl_lba_len_flags { 127 uint64_t lba; 128 uint32_t len; 129 uint32_t flags; 130 #define CTL_LLF_FUA 0x04000000 131 #define CTL_LLF_DPO 0x08000000 132 #define CTL_LLF_READ 0x10000000 133 #define CTL_LLF_WRITE 0x20000000 134 #define CTL_LLF_VERIFY 0x40000000 135 #define CTL_LLF_COMPARE 0x80000000 136 }; 137 138 struct ctl_ptr_len_flags { 139 uint8_t *ptr; 140 uint32_t len; 141 uint32_t flags; 142 }; 143 144 union ctl_priv { 145 uint8_t bytes[sizeof(uint64_t) * 2]; 146 uint64_t integer; 147 void *ptr; 148 }; 149 150 /* 151 * Number of CTL private areas. 152 */ 153 #define CTL_NUM_PRIV 6 154 155 /* 156 * Which private area are we using for a particular piece of data? 157 */ 158 #define CTL_PRIV_LUN 0 /* CTL LUN pointer goes here */ 159 #define CTL_PRIV_LBA_LEN 1 /* Decoded LBA/len for read/write*/ 160 #define CTL_PRIV_MODEPAGE 1 /* Modepage info for config write */ 161 #define CTL_PRIV_BACKEND 2 /* Reserved for block, RAIDCore */ 162 #define CTL_PRIV_BACKEND_LUN 3 /* Backend LUN pointer */ 163 #define CTL_PRIV_FRONTEND 4 /* Frontend storage */ 164 #define CTL_PRIV_FRONTEND2 5 /* Another frontend storage */ 165 166 #define CTL_INVALID_PORTNAME 0xFF 167 #define CTL_UNMAPPED_IID 0xFF 168 169 struct ctl_sg_entry { 170 void *addr; 171 size_t len; 172 }; 173 174 typedef enum { 175 CTL_IO_NONE, 176 CTL_IO_SCSI, 177 CTL_IO_TASK, 178 } ctl_io_type; 179 180 struct ctl_nexus { 181 uint32_t initid; /* Initiator ID */ 182 uint32_t targ_port; /* Target port, filled in by PORT */ 183 uint32_t targ_lun; /* Destination lun */ 184 uint32_t targ_mapped_lun; /* Destination lun CTL-wide */ 185 }; 186 187 typedef enum { 188 CTL_MSG_SERIALIZE, 189 CTL_MSG_R2R, 190 CTL_MSG_FINISH_IO, 191 CTL_MSG_BAD_JUJU, 192 CTL_MSG_MANAGE_TASKS, 193 CTL_MSG_PERS_ACTION, 194 CTL_MSG_DATAMOVE, 195 CTL_MSG_DATAMOVE_DONE, 196 CTL_MSG_UA, /* Set/clear UA on secondary. */ 197 CTL_MSG_PORT_SYNC, /* Information about port. */ 198 CTL_MSG_LUN_SYNC, /* Information about LUN. */ 199 CTL_MSG_IID_SYNC, /* Information about initiator. */ 200 CTL_MSG_LOGIN, /* Information about HA peer. */ 201 CTL_MSG_MODE_SYNC, /* Mode page current content. */ 202 CTL_MSG_FAILOVER /* Fake, never sent though the wire */ 203 } ctl_msg_type; 204 205 struct ctl_scsiio; 206 207 struct ctl_io_hdr { 208 uint32_t version; /* interface version XXX */ 209 ctl_io_type io_type; /* task I/O, SCSI I/O, etc. */ 210 ctl_msg_type msg_type; 211 struct ctl_nexus nexus; /* Initiator, port, target, lun */ 212 uint32_t iid_indx; /* the index into the iid mapping */ 213 uint32_t flags; /* transaction flags */ 214 uint32_t status; /* transaction status */ 215 uint32_t port_status; /* trans status, set by PORT, 0 = good*/ 216 uint32_t timeout; /* timeout in ms */ 217 uint32_t retries; /* retry count */ 218 #ifdef CTL_IO_DELAY 219 struct callout delay_callout; 220 #endif /* CTL_IO_DELAY */ 221 #ifdef CTL_TIME_IO 222 time_t start_time; /* I/O start time */ 223 struct bintime start_bt; /* Timer start ticks */ 224 struct bintime dma_start_bt; /* DMA start ticks */ 225 struct bintime dma_bt; /* DMA total ticks */ 226 #endif /* CTL_TIME_IO */ 227 uint32_t num_dmas; /* Number of DMAs */ 228 union ctl_io *original_sc; 229 union ctl_io *serializing_sc; 230 void *pool; /* I/O pool */ 231 union ctl_priv ctl_private[CTL_NUM_PRIV];/* CTL private area */ 232 struct ctl_sg_entry *remote_sglist; 233 struct ctl_sg_entry *local_sglist; 234 STAILQ_ENTRY(ctl_io_hdr) links; /* linked list pointer */ 235 TAILQ_ENTRY(ctl_io_hdr) ooa_links; 236 TAILQ_ENTRY(ctl_io_hdr) blocked_links; 237 }; 238 239 typedef enum { 240 CTL_TAG_UNTAGGED, 241 CTL_TAG_SIMPLE, 242 CTL_TAG_ORDERED, 243 CTL_TAG_HEAD_OF_QUEUE, 244 CTL_TAG_ACA 245 } ctl_tag_type; 246 247 union ctl_io; 248 249 /* 250 * SCSI passthrough I/O structure for the CAM Target Layer. Note 251 * that some of these fields are here for completeness, but they aren't 252 * used in the CTL implementation. e.g., timeout and retries won't be 253 * used. 254 * 255 * Note: Make sure the io_hdr is *always* the first element in this 256 * structure. 257 */ 258 struct ctl_scsiio { 259 struct ctl_io_hdr io_hdr; /* common to all I/O types */ 260 261 /* 262 * The ext_* fields are generally intended for frontend use; CTL itself 263 * doesn't modify or use them. 264 */ 265 uint32_t ext_sg_entries; /* 0 = no S/G list, > 0 = num entries */ 266 uint8_t *ext_data_ptr; /* data buffer or S/G list */ 267 uint32_t ext_data_len; /* Data transfer length */ 268 uint32_t ext_data_filled; /* Amount of data filled so far */ 269 270 /* 271 * The number of scatter/gather entries in the list pointed to 272 * by kern_data_ptr. 0 means there is no list, just a data pointer. 273 */ 274 uint32_t kern_sg_entries; 275 276 uint32_t rem_sg_entries; /* Unused. */ 277 278 /* 279 * The data pointer or a pointer to the scatter/gather list. 280 */ 281 uint8_t *kern_data_ptr; 282 283 /* 284 * Length of the data buffer or scatter/gather list. It's also 285 * the length of this particular piece of the data transfer, 286 * ie. number of bytes expected to be transferred by the current 287 * invocation of frontend's datamove() callback. It's always 288 * less than or equal to kern_total_len. 289 */ 290 uint32_t kern_data_len; 291 292 /* 293 * Total length of data to be transferred during this particular 294 * SCSI command, as decoded from SCSI CDB. 295 */ 296 uint32_t kern_total_len; 297 298 /* 299 * Amount of data left after the current data transfer. 300 */ 301 uint32_t kern_data_resid; 302 303 /* 304 * Byte offset of this transfer, equal to the amount of data 305 * already transferred for this SCSI command during previous 306 * datamove() invocations. 307 */ 308 uint32_t kern_rel_offset; 309 310 struct scsi_sense_data sense_data; /* sense data */ 311 uint8_t sense_len; /* Returned sense length */ 312 uint8_t scsi_status; /* SCSI status byte */ 313 uint8_t sense_residual; /* Unused. */ 314 uint32_t residual; /* data residual length */ 315 uint32_t tag_num; /* tag number */ 316 ctl_tag_type tag_type; /* simple, ordered, head of queue,etc.*/ 317 uint8_t cdb_len; /* CDB length */ 318 uint8_t cdb[CTL_MAX_CDBLEN]; /* CDB */ 319 int (*be_move_done)(union ctl_io *io); /* called by fe */ 320 int (*io_cont)(union ctl_io *io); /* to continue processing */ 321 }; 322 323 typedef enum { 324 CTL_TASK_ABORT_TASK, 325 CTL_TASK_ABORT_TASK_SET, 326 CTL_TASK_CLEAR_ACA, 327 CTL_TASK_CLEAR_TASK_SET, 328 CTL_TASK_I_T_NEXUS_RESET, 329 CTL_TASK_LUN_RESET, 330 CTL_TASK_TARGET_RESET, 331 CTL_TASK_BUS_RESET, 332 CTL_TASK_PORT_LOGIN, 333 CTL_TASK_PORT_LOGOUT, 334 CTL_TASK_QUERY_TASK, 335 CTL_TASK_QUERY_TASK_SET, 336 CTL_TASK_QUERY_ASYNC_EVENT 337 } ctl_task_type; 338 339 typedef enum { 340 CTL_TASK_FUNCTION_COMPLETE, 341 CTL_TASK_FUNCTION_SUCCEEDED, 342 CTL_TASK_FUNCTION_REJECTED, 343 CTL_TASK_LUN_DOES_NOT_EXIST, 344 CTL_TASK_FUNCTION_NOT_SUPPORTED 345 } ctl_task_status; 346 347 /* 348 * Task management I/O structure. Aborts, bus resets, etc., are sent using 349 * this structure. 350 * 351 * Note: Make sure the io_hdr is *always* the first element in this 352 * structure. 353 */ 354 struct ctl_taskio { 355 struct ctl_io_hdr io_hdr; /* common to all I/O types */ 356 ctl_task_type task_action; /* Target Reset, Abort, etc. */ 357 uint32_t tag_num; /* tag number */ 358 ctl_tag_type tag_type; /* simple, ordered, etc. */ 359 uint8_t task_status; /* Complete, Succeeded, etc. */ 360 uint8_t task_resp[3];/* Response information */ 361 }; 362 363 364 /* 365 * HA link messages. 366 */ 367 #define CTL_HA_VERSION 1 368 369 /* 370 * Used for CTL_MSG_LOGIN. 371 */ 372 struct ctl_ha_msg_login { 373 ctl_msg_type msg_type; 374 int version; 375 int ha_mode; 376 int ha_id; 377 int max_luns; 378 int max_ports; 379 int max_init_per_port; 380 }; 381 382 typedef enum { 383 CTL_PR_REG_KEY, 384 CTL_PR_UNREG_KEY, 385 CTL_PR_PREEMPT, 386 CTL_PR_CLEAR, 387 CTL_PR_RESERVE, 388 CTL_PR_RELEASE 389 } ctl_pr_action; 390 391 /* 392 * The PR info is specifically for sending Persistent Reserve actions 393 * to the other SC which it must also act on. 394 * 395 * Note: Make sure the io_hdr is *always* the first element in this 396 * structure. 397 */ 398 struct ctl_pr_info { 399 ctl_pr_action action; 400 uint8_t sa_res_key[8]; 401 uint8_t res_type; 402 uint32_t residx; 403 }; 404 405 struct ctl_ha_msg_hdr { 406 ctl_msg_type msg_type; 407 uint32_t status; /* transaction status */ 408 union ctl_io *original_sc; 409 union ctl_io *serializing_sc; 410 struct ctl_nexus nexus; /* Initiator, port, target, lun */ 411 }; 412 413 #define CTL_HA_MAX_SG_ENTRIES 16 414 #define CTL_HA_DATAMOVE_SEGMENT 131072 415 416 /* 417 * Used for CTL_MSG_PERS_ACTION. 418 */ 419 struct ctl_ha_msg_pr { 420 struct ctl_ha_msg_hdr hdr; 421 struct ctl_pr_info pr_info; 422 }; 423 424 /* 425 * Used for CTL_MSG_UA. 426 */ 427 struct ctl_ha_msg_ua { 428 struct ctl_ha_msg_hdr hdr; 429 int ua_all; 430 int ua_set; 431 int ua_type; 432 uint8_t ua_info[8]; 433 }; 434 435 /* 436 * The S/G handling here is a little different than the standard ctl_scsiio 437 * structure, because we can't pass data by reference in between controllers. 438 * The S/G list in the ctl_scsiio struct is normally passed in the 439 * kern_data_ptr field. So kern_sg_entries here will always be non-zero, 440 * even if there is only one entry. 441 * 442 * Used for CTL_MSG_DATAMOVE. 443 */ 444 struct ctl_ha_msg_dt { 445 struct ctl_ha_msg_hdr hdr; 446 ctl_io_flags flags; /* Only I/O flags are used here */ 447 uint32_t sg_sequence; /* S/G portion number */ 448 uint8_t sg_last; /* last S/G batch = 1 */ 449 uint32_t sent_sg_entries; /* previous S/G count */ 450 uint32_t cur_sg_entries; /* current S/G entries */ 451 uint32_t kern_sg_entries; /* total S/G entries */ 452 uint32_t kern_data_len; /* Length of this S/G list */ 453 uint32_t kern_total_len; /* Total length of this 454 transaction */ 455 uint32_t kern_data_resid; /* Length left to transfer 456 after this*/ 457 uint32_t kern_rel_offset; /* Byte Offset of this 458 transfer */ 459 struct ctl_sg_entry sg_list[CTL_HA_MAX_SG_ENTRIES]; 460 }; 461 462 /* 463 * Used for CTL_MSG_SERIALIZE, CTL_MSG_FINISH_IO, CTL_MSG_BAD_JUJU. 464 */ 465 struct ctl_ha_msg_scsi { 466 struct ctl_ha_msg_hdr hdr; 467 uint32_t tag_num; /* tag number */ 468 ctl_tag_type tag_type; /* simple, ordered, etc. */ 469 uint8_t cdb[CTL_MAX_CDBLEN]; /* CDB */ 470 uint8_t cdb_len; /* CDB length */ 471 uint8_t scsi_status; /* SCSI status byte */ 472 uint8_t sense_len; /* Returned sense length */ 473 uint8_t sense_residual; /* sense residual length */ 474 uint32_t residual; /* data residual length */ 475 uint32_t fetd_status; /* trans status, set by FETD, 476 0 = good*/ 477 struct scsi_sense_data sense_data; /* sense data */ 478 }; 479 480 /* 481 * Used for CTL_MSG_MANAGE_TASKS. 482 */ 483 struct ctl_ha_msg_task { 484 struct ctl_ha_msg_hdr hdr; 485 ctl_task_type task_action; /* Target Reset, Abort, etc. */ 486 uint32_t tag_num; /* tag number */ 487 ctl_tag_type tag_type; /* simple, ordered, etc. */ 488 }; 489 490 /* 491 * Used for CTL_MSG_PORT_SYNC. 492 */ 493 struct ctl_ha_msg_port { 494 struct ctl_ha_msg_hdr hdr; 495 int port_type; 496 int physical_port; 497 int virtual_port; 498 int status; 499 int name_len; 500 int lun_map_len; 501 int port_devid_len; 502 int target_devid_len; 503 int init_devid_len; 504 uint8_t data[]; 505 }; 506 507 /* 508 * Used for CTL_MSG_LUN_SYNC. 509 */ 510 struct ctl_ha_msg_lun { 511 struct ctl_ha_msg_hdr hdr; 512 int flags; 513 unsigned int pr_generation; 514 uint32_t pr_res_idx; 515 uint8_t pr_res_type; 516 int lun_devid_len; 517 int pr_key_count; 518 uint8_t data[]; 519 }; 520 521 struct ctl_ha_msg_lun_pr_key { 522 uint32_t pr_iid; 523 uint64_t pr_key; 524 }; 525 526 /* 527 * Used for CTL_MSG_IID_SYNC. 528 */ 529 struct ctl_ha_msg_iid { 530 struct ctl_ha_msg_hdr hdr; 531 int in_use; 532 int name_len; 533 uint64_t wwpn; 534 uint8_t data[]; 535 }; 536 537 /* 538 * Used for CTL_MSG_MODE_SYNC. 539 */ 540 struct ctl_ha_msg_mode { 541 struct ctl_ha_msg_hdr hdr; 542 uint8_t page_code; 543 uint8_t subpage; 544 uint16_t page_len; 545 uint8_t data[]; 546 }; 547 548 union ctl_ha_msg { 549 struct ctl_ha_msg_hdr hdr; 550 struct ctl_ha_msg_task task; 551 struct ctl_ha_msg_scsi scsi; 552 struct ctl_ha_msg_dt dt; 553 struct ctl_ha_msg_pr pr; 554 struct ctl_ha_msg_ua ua; 555 struct ctl_ha_msg_port port; 556 struct ctl_ha_msg_lun lun; 557 struct ctl_ha_msg_iid iid; 558 struct ctl_ha_msg_login login; 559 struct ctl_ha_msg_mode mode; 560 }; 561 562 struct ctl_prio { 563 struct ctl_io_hdr io_hdr; 564 struct ctl_ha_msg_pr pr_msg; 565 }; 566 567 union ctl_io { 568 struct ctl_io_hdr io_hdr; /* common to all I/O types */ 569 struct ctl_scsiio scsiio; /* Normal SCSI commands */ 570 struct ctl_taskio taskio; /* SCSI task management/reset */ 571 struct ctl_prio presio; /* update per. res info on other SC */ 572 }; 573 574 #ifdef _KERNEL 575 576 union ctl_io *ctl_alloc_io(void *pool_ref); 577 union ctl_io *ctl_alloc_io_nowait(void *pool_ref); 578 void ctl_free_io(union ctl_io *io); 579 void ctl_zero_io(union ctl_io *io); 580 void ctl_copy_io(union ctl_io *src, union ctl_io *dest); 581 582 #endif /* _KERNEL */ 583 584 #endif /* _CTL_IO_H_ */ 585 586 /* 587 * vim: ts=8 588 */ 589