1 /* 2 * Data structures and definitions for CAM Control Blocks (CCBs). 3 * 4 * Copyright (c) 1997, 1998 Justin T. Gibbs. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions, and the following disclaimer, 12 * without modification, immediately at the beginning of the file. 13 * 2. The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $Id: cam_ccb.h,v 1.2 1998/10/15 23:17:35 gibbs Exp $ 29 */ 30 31 #ifndef _CAM_CAM_CCB_H 32 #define _CAM_CAM_CCB_H 1 33 34 #include <sys/queue.h> 35 #include <sys/cdefs.h> 36 #ifndef KERNEL 37 #include <sys/callout.h> 38 #endif 39 #include <cam/cam_debug.h> 40 #include <cam/scsi/scsi_all.h> 41 42 43 /* General allocation length definitions for CCB structures */ 44 #define IOCDBLEN CAM_MAX_CDBLEN /* Space for CDB bytes/pointer */ 45 #define VUHBALEN 14 /* Vendor Unique HBA length */ 46 #define SIM_IDLEN 16 /* ASCII string len for SIM ID */ 47 #define HBA_IDLEN 16 /* ASCII string len for HBA ID */ 48 #define DEV_IDLEN 16 /* ASCII string len for device names */ 49 #define CCB_PERIPH_PRIV_SIZE 2 /* size of peripheral private area */ 50 #define CCB_SIM_PRIV_SIZE 2 /* size of sim private area */ 51 52 /* Struct definitions for CAM control blocks */ 53 54 /* Common CCB header */ 55 /* CAM CCB flags */ 56 typedef enum { 57 CAM_CDB_POINTER = 0x00000001,/* The CDB field is a pointer */ 58 CAM_QUEUE_ENABLE = 0x00000002,/* SIM queue actions are enabled */ 59 CAM_CDB_LINKED = 0x00000004,/* CCB contains a linked CDB */ 60 CAM_SCATTER_VALID = 0x00000010,/* Scatter/gather list is valid */ 61 CAM_DIS_AUTOSENSE = 0x00000020,/* Disable autosense feature */ 62 CAM_DIR_RESV = 0x00000000,/* Data direction (00:reserved) */ 63 CAM_DIR_IN = 0x00000040,/* Data direction (01:DATA IN) */ 64 CAM_DIR_OUT = 0x00000080,/* Data direction (10:DATA OUT) */ 65 CAM_DIR_NONE = 0x000000C0,/* Data direction (11:no data) */ 66 CAM_DIR_MASK = 0x000000C0,/* Data direction Mask */ 67 CAM_SOFT_RST_OP = 0x00000100,/* Use Soft reset alternative */ 68 CAM_ENG_SYNC = 0x00000200,/* Flush resid bytes on complete */ 69 CAM_DEV_QFRZDIS = 0x00000400,/* Disable DEV Q freezing */ 70 CAM_DEV_QFREEZE = 0x00000800,/* Freeze DEV Q on execution */ 71 CAM_HIGH_POWER = 0x00001000,/* Command takes a lot of power */ 72 CAM_SENSE_PTR = 0x00002000,/* Sense data is a pointer */ 73 CAM_SENSE_PHYS = 0x00004000,/* Sense pointer is physical addr*/ 74 CAM_TAG_ACTION_VALID = 0x00008000,/* Use the tag action in this ccb*/ 75 CAM_PASS_ERR_RECOVER = 0x00010000,/* Pass driver does err. recovery*/ 76 CAM_DIS_DISCONNECT = 0x00020000,/* Disable disconnect */ 77 CAM_SG_LIST_PHYS = 0x00040000,/* SG list has physical addrs. */ 78 CAM_MSG_BUF_PHYS = 0x00080000,/* Message buffer ptr is physical*/ 79 CAM_SNS_BUF_PHYS = 0x00100000,/* Autosense data ptr is physical*/ 80 CAM_DATA_PHYS = 0x00200000,/* SG/Buffer data ptrs are phys. */ 81 CAM_CDB_PHYS = 0x00400000,/* CDB poiner is physical */ 82 CAM_ENG_SGLIST = 0x00800000,/* SG list is for the HBA engine */ 83 84 /* Phase cognizant mode flags */ 85 CAM_DIS_AUTOSRP = 0x01000000,/* Diable autosave/restore ptrs */ 86 CAM_DIS_AUTODISC = 0x02000000,/* Disable auto disconnect */ 87 CAM_TGT_CCB_AVAIL = 0x04000000,/* Target CCB available */ 88 CAM_TGT_PHASE_MODE = 0x08000000,/* The SIM runs in phase mode */ 89 CAM_MSGB_VALID = 0x20000000,/* Message buffer valid */ 90 CAM_STATUS_VALID = 0x40000000,/* Status buffer valid */ 91 CAM_DATAB_VALID = 0x80000000,/* Data buffer valid */ 92 93 /* Host target Mode flags */ 94 CAM_TERM_IO = 0x20000000,/* Terminate I/O Message sup. */ 95 CAM_DISCONNECT = 0x40000000,/* Disconnects are mandatory */ 96 CAM_SEND_STATUS = 0x80000000,/* Send status after data phase */ 97 } ccb_flags; 98 99 /* XPT Opcodes for xpt_action */ 100 typedef enum { 101 /* Common function commands: 0x00->0x0F */ 102 XPT_NOOP, /* Execute Nothing */ 103 XPT_SCSI_IO, /* Execute the requested I/O operation */ 104 XPT_GDEV_TYPE, /* Get type information for specified device */ 105 XPT_GDEVLIST, /* Get a list of peripheral devices */ 106 XPT_PATH_INQ, /* Path routing inquiry */ 107 XPT_REL_SIMQ, /* Release a frozen SIM queue */ 108 XPT_SASYNC_CB, /* Set Asynchronous Callback Parameters */ 109 XPT_SDEV_TYPE, /* Set device type information */ 110 XPT_SCAN_BUS, /* (Re)Scan the SCSI Bus */ 111 XPT_DEV_MATCH, /* Get EDT entries matching the given pattern */ 112 XPT_DEBUG, /* Turn on debugging for a bus, target or lun */ 113 /* SCSI Control Functions: 0x10->0x1F */ 114 XPT_ABORT = 0x10, /* Abort the specified CCB */ 115 XPT_RESET_BUS, /* Reset the specified SCSI bus */ 116 XPT_RESET_DEV, /* Bus Device Reset the specified SCSI device */ 117 XPT_TERM_IO, /* Terminate the I/O process */ 118 XPT_SCAN_LUN, /* Scan Logical Unit */ 119 XPT_GET_TRAN_SETTINGS, /* 120 * Get default/user transfer settings 121 * for the target 122 */ 123 XPT_SET_TRAN_SETTINGS, /* 124 * Set transfer rate/width 125 * negotiation settings 126 */ 127 XPT_CALC_GEOMETRY, /* 128 * Calculate the geometry parameters for 129 * a device give the sector size and 130 * volume size. 131 */ 132 133 /* HBA engine commands 0x20->0x2F */ 134 XPT_ENG_INQ = 0x20, /* HBA engine feature inquiry */ 135 XPT_ENG_EXEC, /* HBA execute engine request */ 136 137 /* Target mode commands: 0x30->0x3F */ 138 XPT_EN_LUN = 0x30, /* Enable LUN as a target */ 139 XPT_TARGET_IO, /* Execute target I/O request */ 140 XPT_ACCEPT_TARGET_IO, /* Accept Host Target Mode CDB */ 141 XPT_CONT_TARGET_IO, /* Continue Host Target I/O Connection */ 142 XPT_IMMED_NOTIFY, /* Notify Host Target driver of event */ 143 XPT_NOTIFY_ACK, /* Acknowledgement of event */ 144 145 /* Vendor Unique codes: 0x80->0x8F */ 146 XPT_VUNIQUE = 0x80 147 } xpt_opcode; 148 149 typedef union { 150 LIST_ENTRY(ccb_hdr) le; 151 SLIST_ENTRY(ccb_hdr) sle; 152 TAILQ_ENTRY(ccb_hdr) tqe; 153 STAILQ_ENTRY(ccb_hdr) stqe; 154 } camq_entry; 155 156 typedef union { 157 void *ptr; 158 u_long field; 159 u_int8_t bytes[sizeof(void *) > sizeof(u_long) 160 ? sizeof(void *) : sizeof(u_long)]; 161 } ccb_priv_entry; 162 163 typedef union { 164 ccb_priv_entry entries[CCB_PERIPH_PRIV_SIZE]; 165 u_int8_t bytes[CCB_PERIPH_PRIV_SIZE * sizeof(ccb_priv_entry)]; 166 } ccb_ppriv_area; 167 168 typedef union { 169 ccb_priv_entry entries[CCB_SIM_PRIV_SIZE]; 170 u_int8_t bytes[CCB_SIM_PRIV_SIZE * sizeof(ccb_priv_entry)]; 171 } ccb_spriv_area; 172 173 struct ccb_hdr { 174 cam_pinfo pinfo; /* Info for priority scheduling */ 175 camq_entry xpt_links; /* For chaining in the XPT layer */ 176 camq_entry sim_links; /* For chaining in the SIM layer */ 177 camq_entry periph_links;/* For chaining in the type driver */ 178 u_int32_t retry_count; 179 /* Callback on completion function */ 180 void (*cbfcnp)(struct cam_periph *, union ccb *); 181 xpt_opcode func_code; /* XPT function code */ 182 u_int32_t status; /* Status returned by CAM subsystem */ 183 /* Compiled path for this ccb */ 184 struct cam_path *path; 185 path_id_t path_id; /* Path ID for the request */ 186 target_id_t target_id; /* Target device ID */ 187 lun_id_t target_lun; /* Target LUN number */ 188 u_int32_t flags; 189 ccb_ppriv_area periph_priv; 190 ccb_spriv_area sim_priv; 191 u_int32_t timeout; /* Timeout value */ 192 /* Callout handle used for timeouts */ 193 struct callout_handle timeout_ch; 194 }; 195 196 /* Get Device Information CCB */ 197 struct ccb_getdev { 198 struct ccb_hdr ccb_h; 199 struct scsi_inquiry_data inq_data; 200 u_int8_t serial_num[252]; 201 u_int8_t serial_num_len; 202 u_int8_t pd_type; /* returned peripheral device type */ 203 int dev_openings; /* Space left for more work on device*/ 204 int dev_active; /* Transactions running on the device */ 205 int devq_openings;/* Space left for more queued work */ 206 int devq_queued; /* Transactions queued to be sent */ 207 int held; /* 208 * CCBs held by peripheral drivers 209 * for this device 210 */ 211 u_int8_t maxtags; /* 212 * Boundary conditions for number of 213 * tagged operations 214 */ 215 u_int8_t mintags; 216 }; 217 218 219 typedef enum { 220 CAM_GDEVLIST_LAST_DEVICE, 221 CAM_GDEVLIST_LIST_CHANGED, 222 CAM_GDEVLIST_MORE_DEVS, 223 CAM_GDEVLIST_ERROR 224 } ccb_getdevlist_status_e; 225 226 struct ccb_getdevlist { 227 struct ccb_hdr ccb_h; 228 char periph_name[DEV_IDLEN]; 229 u_int32_t unit_number; 230 unsigned int generation; 231 u_int32_t index; 232 ccb_getdevlist_status_e status; 233 }; 234 235 typedef enum { 236 PERIPH_MATCH_NONE = 0x000, 237 PERIPH_MATCH_PATH = 0x001, 238 PERIPH_MATCH_TARGET = 0x002, 239 PERIPH_MATCH_LUN = 0x004, 240 PERIPH_MATCH_NAME = 0x008, 241 PERIPH_MATCH_UNIT = 0x010, 242 PERIPH_MATCH_ANY = 0x01f 243 } periph_pattern_flags; 244 245 struct periph_match_pattern { 246 char periph_name[DEV_IDLEN]; 247 u_int32_t unit_number; 248 path_id_t path_id; 249 target_id_t target_id; 250 lun_id_t target_lun; 251 periph_pattern_flags flags; 252 }; 253 254 typedef enum { 255 DEV_MATCH_NONE = 0x000, 256 DEV_MATCH_PATH = 0x001, 257 DEV_MATCH_TARGET = 0x002, 258 DEV_MATCH_LUN = 0x004, 259 DEV_MATCH_INQUIRY = 0x008, 260 DEV_MATCH_ANY = 0x00f 261 } dev_pattern_flags; 262 263 struct device_match_pattern { 264 path_id_t path_id; 265 target_id_t target_id; 266 lun_id_t target_lun; 267 struct scsi_static_inquiry_pattern inq_pat; 268 dev_pattern_flags flags; 269 }; 270 271 typedef enum { 272 BUS_MATCH_NONE = 0x000, 273 BUS_MATCH_PATH = 0x001, 274 BUS_MATCH_NAME = 0x002, 275 BUS_MATCH_UNIT = 0x004, 276 BUS_MATCH_BUS_ID = 0x008, 277 BUS_MATCH_ANY = 0x00f 278 } bus_pattern_flags; 279 280 struct bus_match_pattern { 281 path_id_t path_id; 282 char dev_name[DEV_IDLEN]; 283 u_int32_t unit_number; 284 u_int32_t bus_id; 285 bus_pattern_flags flags; 286 }; 287 288 union match_pattern { 289 struct periph_match_pattern periph_pattern; 290 struct device_match_pattern device_pattern; 291 struct bus_match_pattern bus_pattern; 292 }; 293 294 typedef enum { 295 DEV_MATCH_PERIPH, 296 DEV_MATCH_DEVICE, 297 DEV_MATCH_BUS 298 } dev_match_type; 299 300 struct dev_match_pattern { 301 dev_match_type type; 302 union match_pattern pattern; 303 }; 304 305 struct periph_match_result { 306 char periph_name[DEV_IDLEN]; 307 u_int32_t unit_number; 308 path_id_t path_id; 309 target_id_t target_id; 310 lun_id_t target_lun; 311 }; 312 313 struct device_match_result { 314 path_id_t path_id; 315 target_id_t target_id; 316 lun_id_t target_lun; 317 struct scsi_inquiry_data inq_data; 318 }; 319 320 struct bus_match_result { 321 path_id_t path_id; 322 char dev_name[DEV_IDLEN]; 323 u_int32_t unit_number; 324 u_int32_t bus_id; 325 }; 326 327 union match_result { 328 struct periph_match_result periph_result; 329 struct device_match_result device_result; 330 struct bus_match_result bus_result; 331 }; 332 333 struct dev_match_result { 334 dev_match_type type; 335 union match_result result; 336 }; 337 338 typedef enum { 339 CAM_DEV_MATCH_LAST, 340 CAM_DEV_MATCH_MORE, 341 CAM_DEV_MATCH_LIST_CHANGED, 342 CAM_DEV_MATCH_SIZE_ERROR, 343 CAM_DEV_MATCH_ERROR 344 } ccb_dev_match_status; 345 346 typedef enum { 347 CAM_DEV_POS_NONE = 0x000, 348 CAM_DEV_POS_BUS = 0x001, 349 CAM_DEV_POS_TARGET = 0x002, 350 CAM_DEV_POS_DEVICE = 0x004, 351 CAM_DEV_POS_PERIPH = 0x008, 352 CAM_DEV_POS_PDPTR = 0x010, 353 CAM_DEV_POS_TYPEMASK = 0xf00, 354 CAM_DEV_POS_EDT = 0x100, 355 CAM_DEV_POS_PDRV = 0x200 356 } dev_pos_type; 357 358 struct ccb_dm_cookie { 359 void *bus; 360 void *target; 361 void *device; 362 void *periph; 363 void *pdrv; 364 }; 365 366 struct ccb_dev_position { 367 u_int generations[4]; 368 #define CAM_BUS_GENERATION 0x00 369 #define CAM_TARGET_GENERATION 0x01 370 #define CAM_DEV_GENERATION 0x02 371 #define CAM_PERIPH_GENERATION 0x03 372 dev_pos_type position_type; 373 struct ccb_dm_cookie cookie; 374 }; 375 376 struct ccb_dev_match { 377 struct ccb_hdr ccb_h; 378 ccb_dev_match_status status; 379 u_int32_t num_patterns; 380 u_int32_t pattern_buf_len; 381 struct dev_match_pattern *patterns; 382 u_int32_t num_matches; 383 u_int32_t match_buf_len; 384 struct dev_match_result *matches; 385 struct ccb_dev_position pos; 386 }; 387 388 /* 389 * Definitions for the path inquiry CCB fields. 390 */ 391 #define CAM_VERSION 0x10 /* Hex value for current version */ 392 393 typedef enum { 394 PI_MDP_ABLE = 0x80, /* Supports MDP message */ 395 PI_WIDE_32 = 0x40, /* Supports 32 bit wide SCSI */ 396 PI_WIDE_16 = 0x20, /* Supports 16 bit wide SCSI */ 397 PI_SDTR_ABLE = 0x10, /* Supports SDTR message */ 398 PI_LINKED_CDB = 0x08, /* Supports linked CDBs */ 399 PI_TAG_ABLE = 0x02, /* Supports tag queue messages */ 400 PI_SOFT_RST = 0x01, /* Supports soft reset alternative */ 401 } pi_inqflag; 402 403 typedef enum { 404 PIT_PROCESSOR = 0x80, /* Target mode processor mode */ 405 PIT_PHASE = 0x40, /* Target mode phase cog. mode */ 406 PIT_DISCONNECT = 0x20, /* Disconnects supported in target mode */ 407 PIT_TERM_IO = 0x10, /* Terminate I/O message supported in TM */ 408 PIT_GRP_6 = 0x08, /* Group 6 commands supported */ 409 PIT_GRP_7 = 0x04, /* Group 7 commands supported */ 410 } pi_tmflag; 411 412 typedef enum { 413 PIM_SCANHILO = 0x80, /* Bus scans from high ID to low ID */ 414 PIM_NOREMOVE = 0x40, /* Removeable devices not included in scan */ 415 PIM_NOINITIATOR = 0x20, /* Initiator role not supported. */ 416 PIM_NOBUSRESET = 0x10, /* User has disabled initial BUS RESET */ 417 } pi_miscflag; 418 419 /* Path Inquiry CCB */ 420 struct ccb_pathinq { 421 struct ccb_hdr ccb_h; 422 u_int8_t version_num; /* Version number for the SIM/HBA */ 423 u_int8_t hba_inquiry; /* Mimic of INQ byte 7 for the HBA */ 424 u_int8_t target_sprt; /* Flags for target mode support */ 425 u_int8_t hba_misc; /* Misc HBA features */ 426 u_int16_t hba_eng_cnt; /* HBA engine count */ 427 /* Vendor Unique capabilities */ 428 u_int8_t vuhba_flags[VUHBALEN]; 429 u_int32_t max_target; /* Maximum supported Target */ 430 u_int32_t max_lun; /* Maximum supported Lun */ 431 u_int32_t async_flags; /* Installed Async handlers */ 432 path_id_t hpath_id; /* Highest Path ID in the subsystem */ 433 target_id_t initiator_id; /* ID of the HBA on the SCSI bus */ 434 char sim_vid[SIM_IDLEN]; /* Vendor ID of the SIM */ 435 char hba_vid[HBA_IDLEN]; /* Vendor ID of the HBA */ 436 char dev_name[DEV_IDLEN];/* Device name for SIM */ 437 u_int32_t unit_number; /* Unit number for SIM */ 438 u_int32_t bus_id; /* Bus ID for SIM */ 439 }; 440 441 typedef union { 442 u_int8_t *sense_ptr; /* 443 * Pointer to storage 444 * for sense information 445 */ 446 /* Storage Area for sense information */ 447 struct scsi_sense_data sense_buf; 448 } sense_t; 449 450 typedef union { 451 u_int8_t *cdb_ptr; /* Pointer to the CDB bytes to send */ 452 /* Area for the CDB send */ 453 u_int8_t cdb_bytes[IOCDBLEN]; 454 } cdb_t; 455 456 /* 457 * SCSI I/O Request CCB used for the XPT_SCSI_IO and XPT_CONT_TARGET_IO 458 * function codes. 459 */ 460 struct ccb_scsiio { 461 struct ccb_hdr ccb_h; 462 union ccb *next_ccb; /* Ptr for next CCB for action */ 463 u_int8_t *req_map; /* Ptr to mapping info */ 464 u_int8_t *data_ptr; /* Ptr to the data buf/SG list */ 465 u_int32_t dxfer_len; /* Data transfer length */ 466 /* Autosense storage */ 467 struct scsi_sense_data sense_data; 468 u_int8_t sense_len; /* Number of bytes to autosense */ 469 u_int8_t cdb_len; /* Number of bytes for the CDB */ 470 u_int16_t sglist_cnt; /* Number of SG list entries */ 471 u_int8_t scsi_status; /* Returned SCSI status */ 472 u_int8_t sense_resid; /* Autosense resid length: 2's comp */ 473 u_int32_t resid; /* Transfer residual length: 2's comp */ 474 cdb_t cdb_io; /* Union for CDB bytes/pointer */ 475 u_int8_t *msg_ptr; /* Pointer to the message buffer */ 476 u_int16_t msg_len; /* Number of bytes for the Message */ 477 u_int8_t tag_action; /* What to do for tag queueing */ 478 /* 479 * The tag action should be either the define below (to send a 480 * non-tagged transaction) or one of the defined scsi tag messages 481 * from scsi_message.h. 482 */ 483 #define CAM_TAG_ACTION_NONE 0x00 484 u_int8_t tag_id; /* tag id from initator (target mode) */ 485 u_int8_t init_id; /* initiator id of who selected */ 486 }; 487 488 struct ccb_accept_tio { 489 struct ccb_hdr ccb_h; 490 cdb_t cdb_io; /* Union for CDB bytes/pointer */ 491 u_int8_t cdb_len; /* Number of bytes for the CDB */ 492 u_int8_t tag_action; /* What to do for tag queueing */ 493 u_int8_t tag_id; /* tag id from initator (target mode) */ 494 u_int8_t init_id; /* initiator id of who selected */ 495 }; 496 497 /* Release SIM Queue */ 498 struct ccb_relsim { 499 struct ccb_hdr ccb_h; 500 u_int32_t release_flags; 501 #define RELSIM_ADJUST_OPENINGS 0x01 502 #define RELSIM_RELEASE_AFTER_TIMEOUT 0x02 503 #define RELSIM_RELEASE_AFTER_CMDCMPLT 0x04 504 #define RELSIM_RELEASE_AFTER_QEMPTY 0x08 505 u_int32_t openings; 506 u_int32_t release_timeout; 507 u_int32_t qfrozen_cnt; 508 }; 509 510 /* 511 * Definitions for the asynchronous callback CCB fields. 512 */ 513 typedef enum { 514 AC_GETDEV_CHANGED = 0x800,/* Getdev info might have changed */ 515 AC_INQ_CHANGED = 0x400,/* Inquiry info might have changed */ 516 AC_TRANSFER_NEG = 0x200,/* New transfer settings in effect */ 517 AC_LOST_DEVICE = 0x100,/* A device went away */ 518 AC_FOUND_DEVICE = 0x080,/* A new device was found */ 519 AC_PATH_DEREGISTERED = 0x040,/* A path has de-registered */ 520 AC_PATH_REGISTERED = 0x020,/* A new path has been registered */ 521 AC_SENT_BDR = 0x010,/* A BDR message was sent to target */ 522 AC_SCSI_AEN = 0x008,/* A SCSI AEN has been received */ 523 AC_UNSOL_RESEL = 0x002,/* Unsolicited reselection occurred */ 524 AC_BUS_RESET = 0x001 /* A SCSI bus reset occurred */ 525 } ac_code; 526 527 typedef void ac_callback_t (void *softc, u_int32_t code, 528 struct cam_path *path, void *args); 529 530 /* Set Asynchronous Callback CCB */ 531 struct ccb_setasync { 532 struct ccb_hdr ccb_h; 533 u_int32_t event_enable; /* Async Event enables */ 534 ac_callback_t *callback; 535 void *callback_arg; 536 }; 537 538 /* Set Device Type CCB */ 539 struct ccb_setdev { 540 struct ccb_hdr ccb_h; 541 u_int8_t dev_type; /* Value for dev type field in EDT */ 542 }; 543 544 /* SCSI Control Functions */ 545 546 /* Abort XPT request CCB */ 547 struct ccb_abort { 548 struct ccb_hdr ccb_h; 549 union ccb *abort_ccb; /* Pointer to CCB to abort */ 550 }; 551 552 /* Reset SCSI Bus CCB */ 553 struct ccb_resetbus { 554 struct ccb_hdr ccb_h; 555 }; 556 557 /* Reset SCSI Device CCB */ 558 struct ccb_resetdev { 559 struct ccb_hdr ccb_h; 560 }; 561 562 /* Terminate I/O Process Request CCB */ 563 struct ccb_termio { 564 struct ccb_hdr ccb_h; 565 union ccb *termio_ccb; /* Pointer to CCB to terminate */ 566 }; 567 568 /* Get/Set transfer rate/width/disconnection/tag queueing settings */ 569 struct ccb_trans_settings { 570 struct ccb_hdr ccb_h; 571 u_int valid; /* Which fields to honor */ 572 #define CCB_TRANS_SYNC_RATE_VALID 0x01 573 #define CCB_TRANS_SYNC_OFFSET_VALID 0x02 574 #define CCB_TRANS_BUS_WIDTH_VALID 0x04 575 #define CCB_TRANS_DISC_VALID 0x08 576 #define CCB_TRANS_TQ_VALID 0x10 577 u_int flags; 578 #define CCB_TRANS_CURRENT_SETTINGS 0x01 579 #define CCB_TRANS_USER_SETTINGS 0x02 580 #define CCB_TRANS_DISC_ENB 0x04 581 #define CCB_TRANS_TAG_ENB 0x08 582 u_int sync_period; 583 u_int sync_offset; 584 u_int bus_width; 585 }; 586 587 /* 588 * Calculate the geometry parameters for a device 589 * give the block size and volume size in blocks. 590 */ 591 struct ccb_calc_geometry { 592 struct ccb_hdr ccb_h; 593 u_int32_t block_size; 594 u_int32_t volume_size; 595 u_int16_t cylinders; 596 u_int8_t heads; 597 u_int8_t secs_per_track; 598 }; 599 600 /* 601 * Rescan the given bus, or bus/target/lun 602 */ 603 struct ccb_rescan { 604 struct ccb_hdr ccb_h; 605 cam_flags flags; 606 }; 607 608 /* 609 * Turn on debugging for the given bus, bus/target, or bus/target/lun. 610 */ 611 struct ccb_debug { 612 struct ccb_hdr ccb_h; 613 cam_debug_flags flags; 614 }; 615 616 /* Target mode structures. */ 617 618 struct ccb_en_lun { 619 struct ccb_hdr ccb_h; 620 u_int16_t grp6_len; /* Group 6 VU CDB length */ 621 u_int16_t grp7_len; /* Group 7 VU CDB length */ 622 u_int8_t enable; 623 }; 624 625 struct ccb_immed_notify { 626 struct ccb_hdr ccb_h; 627 struct scsi_sense_data sense_data; 628 u_int8_t sense_len; /* Number of bytes in sese buffer */ 629 u_int8_t initiator_id; /* Id of initiator that selected */ 630 u_int16_t seq_id; /* Sequence Identifier */ 631 u_int8_t message_code; /* Message Code */ 632 u_int8_t message_args[7]; /* Message Arguments */ 633 }; 634 635 struct ccb_notify_ack { 636 struct ccb_hdr ccb_h; 637 u_int16_t seq_id; /* Sequence identifier */ 638 u_int8_t event; /* Event flags */ 639 }; 640 641 /* HBA engine structures. */ 642 643 typedef enum { 644 EIT_BUFFER, /* Engine type: buffer memory */ 645 EIT_LOSSLESS, /* Engine type: lossless compression */ 646 EIT_LOSSY, /* Engine type: lossy compression */ 647 EIT_ENCRYPT /* Engine type: encryption */ 648 } ei_type; 649 650 typedef enum { 651 EAD_VUNIQUE, /* Engine algorithm ID: vendor unique */ 652 EAD_LZ1V1, /* Engine algorithm ID: LZ1 var.1 */ 653 EAD_LZ2V1, /* Engine algorithm ID: LZ2 var.1 */ 654 EAD_LZ2V2, /* Engine algorithm ID: LZ2 var.2 */ 655 } ei_algo; 656 657 struct ccb_eng_inq { 658 struct ccb_hdr ccb_h; 659 u_int16_t eng_num; /* The engine number for this inquiry */ 660 ei_type eng_type; /* Returned engine type */ 661 ei_algo eng_algo; /* Returned engine algorithm type */ 662 u_int32_t eng_memeory; /* Returned engine memory size */ 663 }; 664 665 struct ccb_eng_exec { /* This structure must match SCSIIO size */ 666 struct ccb_hdr ccb_h; 667 u_int8_t *pdrv_ptr; /* Ptr used by the peripheral driver */ 668 u_int8_t *req_map; /* Ptr for mapping info on the req. */ 669 u_int8_t *data_ptr; /* Pointer to the data buf/SG list */ 670 u_int32_t dxfer_len; /* Data transfer length */ 671 u_int8_t *engdata_ptr; /* Pointer to the engine buffer data */ 672 u_int16_t sglist_cnt; /* Num of scatter gather list entries */ 673 u_int32_t dmax_len; /* Destination data maximum length */ 674 u_int32_t dest_len; /* Destination data length */ 675 int32_t src_resid; /* Source residual length: 2's comp */ 676 u_int32_t timeout; /* Timeout value */ 677 u_int16_t eng_num; /* Engine number for this request */ 678 u_int16_t vu_flags; /* Vendor Unique flags */ 679 }; 680 681 /* 682 * Definitions for the timeout field in the SCSI I/O CCB. 683 */ 684 #define CAM_TIME_DEFAULT 0x00000000 /* Use SIM default value */ 685 #define CAM_TIME_INFINITY 0xFFFFFFFF /* Infinite timeout */ 686 687 #define CAM_SUCCESS 0 /* For signaling general success */ 688 #define CAM_FAILURE 1 /* For signaling general failure */ 689 690 #define CAM_FALSE 0 691 #define CAM_TRUE 1 692 693 #define XPT_CCB_INVALID -1 /* for signaling a bad CCB to free */ 694 695 /* 696 * Union of all CCB types for kernel space allocation. This union should 697 * never be used for manipulating CCBs - its only use is for the allocation 698 * and deallocation of raw CCB space and is the return type of xpt_ccb_alloc 699 * and the argument to xpt_ccb_free. 700 */ 701 union ccb { 702 struct ccb_hdr ccb_h; /* For convenience */ 703 struct ccb_scsiio csio; 704 struct ccb_getdev cgd; 705 struct ccb_getdevlist cgdl; 706 struct ccb_pathinq cpi; 707 struct ccb_relsim crs; 708 struct ccb_setasync csa; 709 struct ccb_setdev csd; 710 struct ccb_dev_match cdm; 711 struct ccb_trans_settings cts; 712 struct ccb_calc_geometry ccg; 713 struct ccb_abort cab; 714 struct ccb_resetbus crb; 715 struct ccb_resetdev crd; 716 struct ccb_termio tio; 717 struct ccb_accept_tio atio; 718 struct ccb_scsiio ctio; 719 struct ccb_en_lun cel; 720 struct ccb_immed_notify cin; 721 struct ccb_notify_ack cna; 722 struct ccb_eng_inq cei; 723 struct ccb_eng_exec cee; 724 struct ccb_rescan crcn; 725 struct ccb_debug cdbg; 726 }; 727 728 __BEGIN_DECLS 729 static __inline void 730 cam_fill_csio(struct ccb_scsiio *csio, u_int32_t retries, 731 void (*cbfcnp)(struct cam_periph *, union ccb *), 732 u_int32_t flags, u_int8_t tag_action, 733 u_int8_t *data_ptr, u_int32_t dxfer_len, 734 u_int8_t sense_len, u_int8_t cdb_len, 735 u_int32_t timeout); 736 737 static __inline void 738 cam_fill_ctio(struct ccb_scsiio *csio, u_int32_t retries, 739 void (*cbfcnp)(struct cam_periph *, union ccb *), 740 u_int32_t flags, u_int tag_action, u_int tag_id, 741 u_int init_id, u_int scsi_status, u_int8_t *data_ptr, 742 u_int32_t dxfer_len, u_int32_t timeout); 743 744 static __inline void 745 cam_fill_csio(struct ccb_scsiio *csio, u_int32_t retries, 746 void (*cbfcnp)(struct cam_periph *, union ccb *), 747 u_int32_t flags, u_int8_t tag_action, 748 u_int8_t *data_ptr, u_int32_t dxfer_len, 749 u_int8_t sense_len, u_int8_t cdb_len, 750 u_int32_t timeout) 751 { 752 csio->ccb_h.func_code = XPT_SCSI_IO; 753 csio->ccb_h.flags = flags; 754 csio->ccb_h.retry_count = retries; 755 csio->ccb_h.cbfcnp = cbfcnp; 756 csio->ccb_h.timeout = timeout; 757 csio->data_ptr = data_ptr; 758 csio->dxfer_len = dxfer_len; 759 csio->sense_len = sense_len; 760 csio->cdb_len = cdb_len; 761 csio->tag_action = tag_action; 762 } 763 764 static __inline void 765 cam_fill_ctio(struct ccb_scsiio *csio, u_int32_t retries, 766 void (*cbfcnp)(struct cam_periph *, union ccb *), 767 u_int32_t flags, u_int tag_action, u_int tag_id, 768 u_int init_id, u_int scsi_status, u_int8_t *data_ptr, 769 u_int32_t dxfer_len, u_int32_t timeout) 770 { 771 csio->ccb_h.func_code = XPT_CONT_TARGET_IO; 772 csio->ccb_h.flags = flags; 773 csio->ccb_h.retry_count = retries; 774 csio->ccb_h.cbfcnp = cbfcnp; 775 csio->ccb_h.timeout = timeout; 776 csio->data_ptr = data_ptr; 777 csio->dxfer_len = dxfer_len; 778 csio->scsi_status = scsi_status; 779 csio->tag_action = tag_action; 780 csio->tag_id = tag_id; 781 csio->init_id = init_id; 782 } 783 784 __END_DECLS 785 786 #endif /* _CAM_CAM_CCB_H */ 787