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