1 /* $NetBSD: scsipiconf.h,v 1.45 2000/07/06 01:56:23 mjacob Exp $ */ 2 3 /*- 4 * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Charles M. Hannum; by Jason R. Thorpe of the Numerical Aerospace 9 * Simulation Facility, NASA Ames Research Center. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by the NetBSD 22 * Foundation, Inc. and its contributors. 23 * 4. Neither the name of The NetBSD Foundation nor the names of its 24 * contributors may be used to endorse or promote products derived 25 * from this software without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 * POSSIBILITY OF SUCH DAMAGE. 38 */ 39 40 /* 41 * Originally written by Julian Elischer (julian@tfs.com) 42 * for TRW Financial Systems for use under the MACH(2.5) operating system. 43 * 44 * TRW Financial Systems, in accordance with their agreement with Carnegie 45 * Mellon University, makes this software available to CMU to distribute 46 * or use in any manner that they see fit as long as this message is kept with 47 * the software. For this reason TFS also grants any other persons or 48 * organisations permission to use or modify this software. 49 * 50 * TFS supplies this software to be publicly redistributed 51 * on the understanding that TFS is not responsible for the correct 52 * functioning of this software in any circumstances. 53 * 54 * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 55 */ 56 57 #ifndef _DEV_SCSIPI_SCSIPICONF_H_ 58 #define _DEV_SCSIPI_SCSIPICONF_H_ 59 60 typedef int boolean; 61 62 #include <sys/callout.h> 63 #include <sys/queue.h> 64 #include <dev/scsipi/scsipi_debug.h> 65 66 /* 67 * The following documentation tries to describe the relationship between the 68 * various structures defined in this file: 69 * 70 * each adapter type has a scsipi_adapter struct. This describes the adapter 71 * and identifies routines that can be called to use the adapter. 72 * each device type has a scsipi_device struct. This describes the device and 73 * identifies routines that can be called to use the device. 74 * each existing device position (scsibus + target + lun or atapibus + drive) 75 * can be described by a scsipi_link struct. 76 * Only scsipi positions that actually have devices, have a scsipi_link 77 * structure assigned. so in effect each device has scsipi_link struct. 78 * The scsipi_link structure contains information identifying both the 79 * device driver and the adapter driver for that position on that scsipi 80 * bus, and can be said to 'link' the two. 81 * each individual scsipi bus has an array that points to all the scsipi_link 82 * structs associated with that scsipi bus. Slots with no device have 83 * a NULL pointer. 84 * each individual device also knows the address of it's own scsipi_link 85 * structure. 86 * 87 * ------------- 88 * 89 * The key to all this is the scsipi_link structure which associates all the 90 * other structures with each other in the correct configuration. The 91 * scsipi_link is the connecting information that allows each part of the 92 * scsipi system to find the associated other parts. 93 */ 94 95 struct buf; 96 struct proc; 97 struct scsipi_link; 98 struct scsipi_xfer; 99 100 /* 101 * The following defines the scsipi_xfer queue. 102 */ 103 TAILQ_HEAD(scsipi_xfer_queue, scsipi_xfer); 104 105 struct scsipi_generic { 106 u_int8_t opcode; 107 u_int8_t bytes[15]; 108 }; 109 110 111 /* 112 * return values for scsipi_cmd() 113 */ 114 #define SUCCESSFULLY_QUEUED 0 115 #define TRY_AGAIN_LATER 1 116 #define COMPLETE 2 117 #define ESCAPE_NOT_SUPPORTED 3 118 119 /* 120 * Device Specific Sense Handlers return either an errno 121 * or one of these three items. 122 */ 123 124 #define SCSIRET_NOERROR 0 /* No Error */ 125 #define SCSIRET_RETRY -1 /* Retry the command that got this sense */ 126 #define SCSIRET_CONTINUE -2 /* Continue with standard sense processing */ 127 128 /* 129 * These entry points are called by the low-end drivers to get services from 130 * whatever high-end drivers they are attached to. Each device type has one 131 * of these statically allocated. 132 */ 133 struct scsipi_device { 134 int (*err_handler) __P((struct scsipi_xfer *)); 135 /* returns -1 to say err processing done */ 136 void (*start) __P((void *)); 137 int (*async) __P((void)); 138 void (*done) __P((struct scsipi_xfer *)); 139 }; 140 141 /* 142 * These entrypoints are called by the high-end drivers to get services from 143 * whatever low-end drivers they are attached to. Each adapter instance has 144 * one of these. 145 * 146 * scsipi_cmd required 147 * scsipi_minphys required 148 * scsipi_ioctl optional 149 * scsipi_enable optional 150 * scsipi_getgeom optional 151 */ 152 struct disk_parms; 153 struct scsipi_adapter { 154 int scsipi_refcnt; /* adapter reference count */ 155 int (*scsipi_cmd) __P((struct scsipi_xfer *)); 156 void (*scsipi_minphys) __P((struct buf *)); 157 int (*scsipi_ioctl) __P((struct scsipi_link *, u_long, 158 caddr_t, int, struct proc *)); 159 int (*scsipi_enable) __P((void *, int)); 160 int (*scsipi_getgeom) __P((struct scsipi_link *, 161 struct disk_parms *, u_long)); 162 }; 163 164 /* 165 * This structure describes the connection between an adapter driver and 166 * a device driver, and is used by each to call services provided by 167 * the other, and to allow generic scsipi glue code to call these services 168 * as well. 169 * 170 * XXX Given the way NetBSD's autoconfiguration works, this is ... 171 * XXX nasty. 172 */ 173 174 /* 175 * XXX Small hack alert 176 * NOTE: The first field of struct scsipi_link is shared with 177 * dev/scspi/scsipiconf.h's struct ata_atapi_attach. This allows 178 * atapibus and scsibus to attach to the same device. 179 */ 180 struct scsipi_link { 181 u_int8_t type; /* device type, i.e. SCSI, ATAPI, ...*/ 182 #define BUS_SCSI 0 183 #define BUS_ATAPI 1 184 /*define BUS_ATA 2*/ 185 int openings; /* max # of outstanding commands */ 186 int active; /* current # of outstanding commands */ 187 int flags; /* flags that all devices have */ 188 #define SDEV_REMOVABLE 0x01 /* media is removable */ 189 #define SDEV_MEDIA_LOADED 0x02 /* device figures are still valid */ 190 #define SDEV_WAITING 0x04 /* a process is waiting for this */ 191 #define SDEV_OPEN 0x08 /* at least 1 open session */ 192 #define SDEV_DBX 0xf0 /* debuging flags (scsipi_debug.h) */ 193 #define SDEV_WAITDRAIN 0x100 /* waiting for pending_xfers to drain */ 194 #define SDEV_KEEP_LABEL 0x200 /* retain label after 'full' close */ 195 u_int16_t quirks; /* per-device oddities */ 196 #define SDEV_AUTOSAVE 0x0001 /* 197 * Do implicit SAVEDATAPOINTER on 198 * disconnect (ancient). 199 */ 200 #define SDEV_NOSYNC 0x0002 /* does not grok SDTR */ 201 #define SDEV_NOWIDE 0x0004 /* does not grok WDTR */ 202 #define SDEV_NOTAG 0x0008 /* does not do command tagging */ 203 #define SDEV_NOLUNS 0x0010 /* does not grok LUNs */ 204 #define SDEV_FORCELUNS 0x0020 /* prehistoric drive/ctlr groks LUNs */ 205 #define SDEV_NOMODESENSE 0x0040 /* removable media/optical drives */ 206 #define SDEV_NOSTARTUNIT 0x0080 /* Do not issue START UNIT requests */ 207 #define SDEV_NOSYNCCACHE 0x0100 /* does not grok SYNCHRONIZE CACHE */ 208 #define SDEV_CDROM 0x0200 /* device is a CD-ROM */ 209 #define ADEV_LITTLETOC 0x0400 /* Audio TOC uses wrong byte order */ 210 #define ADEV_NOCAPACITY 0x0800 /* no READ_CD_CAPACITY command */ 211 #define ADEV_NOTUR 0x1000 /* no TEST_UNIT_READY command */ 212 #define ADEV_NODOORLOCK 0x2000 /* device can't lock door */ 213 #define ADEV_NOSENSE 0x4000 /* device can't handle request sense */ 214 #define SDEV_ONLYBIG 0x8000 /* only use SCSI_{READ,WRITE}_BIG */ 215 216 struct scsipi_device *device; /* device entry points etc. */ 217 void *device_softc; /* needed for call to foo_start */ 218 struct scsipi_adapter *adapter;/* adapter entry points etc. */ 219 void *adapter_softc; /* needed for call to foo_scsipi_cmd */ 220 union { /* needed for call to foo_scsipi_cmd */ 221 struct scsi_link { 222 int channel; /* channel, i.e. bus # on controller */ 223 224 u_int8_t scsi_version; /* SCSI-I, SCSI-II, etc. */ 225 u_int8_t scsibus; /* the Nth scsibus */ 226 u_int8_t target; /* targ of this dev */ 227 u_int8_t lun; /* lun of this dev */ 228 u_int8_t adapter_target;/* what are we on the scsi 229 bus */ 230 int16_t max_target; /* XXX max target supported 231 by adapter (inclusive) */ 232 int16_t max_lun; /* XXX number of luns supported 233 by adapter (inclusive) */ 234 } scsipi_scsi; 235 struct atapi_link { 236 u_int8_t drive; /* drive number on the bus */ 237 u_int8_t channel; /* channel, i.e. bus # on 238 controller */ 239 u_int8_t atapibus; 240 u_int8_t cap; /* drive capability */ 241 /* 0x20-0x40 reserved for ATAPI_CFG_DRQ_MASK */ 242 #define ACAP_LEN 0x01 /* 16 bit commands */ 243 } scsipi_atapi; 244 } _scsipi_link; 245 struct scsipi_xfer_queue pending_xfers; 246 int (*scsipi_cmd) __P((struct scsipi_link *, struct scsipi_generic *, 247 int cmdlen, u_char *data_addr, int datalen, int retries, 248 int timeout, struct buf *bp, int flags)); 249 int (*scsipi_interpret_sense) __P((struct scsipi_xfer *)); 250 void (*sc_print_addr) __P((struct scsipi_link *sc_link)); 251 void (*scsipi_kill_pending) __P((struct scsipi_link *)); 252 }; 253 #define scsipi_scsi _scsipi_link.scsipi_scsi 254 #define scsipi_atapi _scsipi_link.scsipi_atapi 255 256 /* 257 * Each scsipi transaction is fully described by one of these structures 258 * It includes information about the source of the command and also the 259 * device and adapter for which the command is destined. 260 * (via the scsipi_link structure) 261 * 262 * The adapter_q member may be used by host adapter drivers to queue 263 * requests, if necessary. 264 * 265 * The device_q member is maintained by the scsipi middle layer. When 266 * a device issues a command, the xfer is placed on that device's 267 * pending commands queue. When an xfer is done and freed, it is taken 268 * off the device's queue. This allows for a device to wait for all of 269 * its pending commands to complete. 270 */ 271 struct scsipi_xfer { 272 TAILQ_ENTRY(scsipi_xfer) adapter_q; /* queue entry for use by adapter */ 273 TAILQ_ENTRY(scsipi_xfer) device_q; /* device's pending xfers */ 274 struct callout xs_callout; /* callout for adapter use */ 275 int xs_control; /* control flags */ 276 __volatile int xs_status; /* status flags */ 277 struct scsipi_link *sc_link; /* all about our device and adapter */ 278 int retries; /* the number of times to retry */ 279 int timeout; /* in milliseconds */ 280 struct scsipi_generic *cmd; /* The scsipi command to execute */ 281 int cmdlen; /* how long it is */ 282 u_char *data; /* dma address OR a uio address */ 283 int datalen; /* data len (blank if uio) */ 284 int resid; /* how much buffer was not touched */ 285 int error; /* an error value */ 286 struct buf *bp; /* If we need to associate with */ 287 /* a buf */ 288 union { 289 struct scsipi_sense_data scsi_sense; /* 32 bytes */ 290 u_int32_t atapi_sense; 291 } sense; 292 /* 293 * Believe it or not, Some targets fall on the ground with 294 * anything but a certain sense length. 295 */ 296 int req_sense_length; /* Explicit request sense length */ 297 u_int8_t status; /* SCSI status */ 298 struct scsipi_generic cmdstore 299 __attribute__ ((aligned (4)));/* stash the command in here */ 300 }; 301 302 /* 303 * scsipi_xfer control flags 304 * 305 * To do: 306 * 307 * - figure out what to do with XS_CTL_ESCAPE 308 * 309 * - replace XS_CTL_URGENT with an `xs_priority' field 310 */ 311 #define XS_CTL_NOSLEEP 0x00000001 /* don't sleep */ 312 #define XS_CTL_POLL 0x00000002 /* poll for completion */ 313 #define XS_CTL_DISCOVERY 0x00000004 /* doing device discovery */ 314 #define XS_CTL_ASYNC 0x00000008 /* command completes 315 asynchronously */ 316 #define XS_CTL_USERCMD 0x00000010 /* user issued command */ 317 #define XS_CTL_SILENT 0x00000020 /* don't print sense info */ 318 #define XS_CTL_IGNORE_NOT_READY 0x00000040 /* ignore NOT READY */ 319 #define XS_CTL_IGNORE_MEDIA_CHANGE \ 320 0x00000080 /* ignore media change */ 321 #define XS_CTL_IGNORE_ILLEGAL_REQUEST \ 322 0x00000100 /* ignore ILLEGAL REQUEST */ 323 #define XS_CTL_RESET 0x00000200 /* reset the device */ 324 #define XS_CTL_DATA_UIO 0x00000400 /* xs_data points to uio */ 325 #define XS_CTL_DATA_IN 0x00000800 /* data coming into memory */ 326 #define XS_CTL_DATA_OUT 0x00001000 /* data going out of memory */ 327 #define XS_CTL_TARGET 0x00002000 /* target mode operation */ 328 #define XS_CTL_ESCAPE 0x00004000 /* escape operation */ 329 #define XS_CTL_URGENT 0x00008000 /* urgent operation */ 330 #define XS_CTL_SIMPLE_TAG 0x00010000 /* use a Simple Tag */ 331 #define XS_CTL_ORDERED_TAG 0x00020000 /* use an Ordered Tag */ 332 #define XS_CTL_DATA_ONSTACK 0x00040000 /* data is alloc'ed on stack */ 333 334 /* 335 * scsipi_xfer status flags 336 */ 337 #define XS_STS_DONE 0x00000001 /* scsipi_xfer is done */ 338 #define XS_STS_PRIVATE 0xf0000000 /* reserved for HBA's use */ 339 340 /* 341 * Error values an adapter driver may return 342 */ 343 #define XS_NOERROR 0 /* there is no error, (sense is invalid) */ 344 #define XS_SENSE 1 /* Check the returned sense for the error */ 345 #define XS_SHORTSENSE 2 /* Check the ATAPI sense for the error */ 346 #define XS_DRIVER_STUFFUP 3 /* Driver failed to perform operation */ 347 #define XS_SELTIMEOUT 4 /* The device timed out.. turned off? */ 348 #define XS_TIMEOUT 5 /* The Timeout reported was caught by SW */ 349 #define XS_BUSY 7 /* The device busy, try again later? */ 350 #define XS_RESET 8 /* bus was reset; possible retry command */ 351 352 /* 353 * This describes matching information for scsipi_inqmatch(). The more things 354 * match, the higher the configuration priority. 355 */ 356 struct scsipi_inquiry_pattern { 357 u_int8_t type; 358 boolean removable; 359 char *vendor; 360 char *product; 361 char *revision; 362 }; 363 364 /* 365 * This is used to pass information from the high-level configuration code 366 * to the device-specific drivers. 367 */ 368 369 struct scsipibus_attach_args { 370 struct scsipi_link *sa_sc_link; 371 struct scsipi_inquiry_pattern sa_inqbuf; 372 struct scsipi_inquiry_data *sa_inqptr; 373 union { /* bus-type specific infos */ 374 u_int8_t scsi_version; /* SCSI version */ 375 } scsipi_info; 376 }; 377 378 /* 379 * this describes a quirk entry 380 */ 381 382 struct scsi_quirk_inquiry_pattern { 383 struct scsipi_inquiry_pattern pattern; 384 u_int16_t quirks; 385 }; 386 387 /* 388 * Default number of retries, used for generic routines. 389 */ 390 #define SCSIPIRETRIES 4 391 392 /* 393 * Similar, but invoke the controller directly with a scsipi_xfer. 394 */ 395 #define scsipi_command_direct(xs) \ 396 (*(xs)->sc_link->adapter->scsipi_cmd)((xs)) 397 398 #ifdef _KERNEL 399 void scsipi_init __P((void)); 400 int scsipi_command __P((struct scsipi_link *, 401 struct scsipi_generic *, int, u_char *, int, 402 int, int, struct buf *, int)); 403 caddr_t scsipi_inqmatch __P((struct scsipi_inquiry_pattern *, caddr_t, 404 int, int, int *)); 405 char *scsipi_dtype __P((int)); 406 void scsipi_strvis __P((u_char *, int, u_char *, int)); 407 int scsipi_execute_xs __P((struct scsipi_xfer *)); 408 u_long scsipi_size __P((struct scsipi_link *, int)); 409 int scsipi_test_unit_ready __P((struct scsipi_link *, int)); 410 int scsipi_prevent __P((struct scsipi_link *, int, int)); 411 int scsipi_inquire __P((struct scsipi_link *, 412 struct scsipi_inquiry_data *, int)); 413 int scsipi_start __P((struct scsipi_link *, int, int)); 414 void scsipi_done __P((struct scsipi_xfer *)); 415 void scsipi_user_done __P((struct scsipi_xfer *)); 416 int scsipi_interpret_sense __P((struct scsipi_xfer *)); 417 void scsipi_wait_drain __P((struct scsipi_link *)); 418 void scsipi_kill_pending __P((struct scsipi_link *)); 419 #ifdef SCSIVERBOSE 420 void scsipi_print_sense __P((struct scsipi_xfer *, int)); 421 void scsipi_print_sense_data __P((struct scsipi_sense_data *, int)); 422 char *scsipi_decode_sense __P((void *, int)); 423 #endif 424 int scsipi_do_ioctl __P((struct scsipi_link *, dev_t, u_long, caddr_t, 425 int, struct proc *)); 426 427 int scsipi_adapter_addref __P((struct scsipi_link *)); 428 void scsipi_adapter_delref __P((struct scsipi_link *)); 429 430 void show_scsipi_xs __P((struct scsipi_xfer *)); 431 void show_scsipi_cmd __P((struct scsipi_xfer *)); 432 void show_mem __P((u_char *, int)); 433 #endif /* _KERNEL */ 434 435 static __inline void _lto2b __P((u_int32_t val, u_int8_t *bytes)) 436 __attribute__ ((unused)); 437 static __inline void _lto3b __P((u_int32_t val, u_int8_t *bytes)) 438 __attribute__ ((unused)); 439 static __inline void _lto4b __P((u_int32_t val, u_int8_t *bytes)) 440 __attribute__ ((unused)); 441 static __inline u_int32_t _2btol __P((const u_int8_t *bytes)) 442 __attribute__ ((unused)); 443 static __inline u_int32_t _3btol __P((const u_int8_t *bytes)) 444 __attribute__ ((unused)); 445 static __inline u_int32_t _4btol __P((const u_int8_t *bytes)) 446 __attribute__ ((unused)); 447 448 static __inline void _lto2l __P((u_int32_t val, u_int8_t *bytes)) 449 __attribute__ ((unused)); 450 static __inline void _lto3l __P((u_int32_t val, u_int8_t *bytes)) 451 __attribute__ ((unused)); 452 static __inline void _lto4l __P((u_int32_t val, u_int8_t *bytes)) 453 __attribute__ ((unused)); 454 static __inline u_int32_t _2ltol __P((const u_int8_t *bytes)) 455 __attribute__ ((unused)); 456 static __inline u_int32_t _3ltol __P((const u_int8_t *bytes)) 457 __attribute__ ((unused)); 458 static __inline u_int32_t _4ltol __P((const u_int8_t *bytes)) 459 __attribute__ ((unused)); 460 static __inline void bswap __P((char *, int)) 461 __attribute__ ((unused)); 462 463 static __inline void 464 _lto2b(val, bytes) 465 u_int32_t val; 466 u_int8_t *bytes; 467 { 468 469 bytes[0] = (val >> 8) & 0xff; 470 bytes[1] = val & 0xff; 471 } 472 473 static __inline void 474 _lto3b(val, bytes) 475 u_int32_t val; 476 u_int8_t *bytes; 477 { 478 479 bytes[0] = (val >> 16) & 0xff; 480 bytes[1] = (val >> 8) & 0xff; 481 bytes[2] = val & 0xff; 482 } 483 484 static __inline void 485 _lto4b(val, bytes) 486 u_int32_t val; 487 u_int8_t *bytes; 488 { 489 490 bytes[0] = (val >> 24) & 0xff; 491 bytes[1] = (val >> 16) & 0xff; 492 bytes[2] = (val >> 8) & 0xff; 493 bytes[3] = val & 0xff; 494 } 495 496 static __inline u_int32_t 497 _2btol(bytes) 498 const u_int8_t *bytes; 499 { 500 u_int32_t rv; 501 502 rv = (bytes[0] << 8) | 503 bytes[1]; 504 return (rv); 505 } 506 507 static __inline u_int32_t 508 _3btol(bytes) 509 const u_int8_t *bytes; 510 { 511 u_int32_t rv; 512 513 rv = (bytes[0] << 16) | 514 (bytes[1] << 8) | 515 bytes[2]; 516 return (rv); 517 } 518 519 static __inline u_int32_t 520 _4btol(bytes) 521 const u_int8_t *bytes; 522 { 523 u_int32_t rv; 524 525 rv = (bytes[0] << 24) | 526 (bytes[1] << 16) | 527 (bytes[2] << 8) | 528 bytes[3]; 529 return (rv); 530 } 531 532 static __inline void 533 _lto2l(val, bytes) 534 u_int32_t val; 535 u_int8_t *bytes; 536 { 537 538 bytes[0] = val & 0xff; 539 bytes[1] = (val >> 8) & 0xff; 540 } 541 542 static __inline void 543 _lto3l(val, bytes) 544 u_int32_t val; 545 u_int8_t *bytes; 546 { 547 548 bytes[0] = val & 0xff; 549 bytes[1] = (val >> 8) & 0xff; 550 bytes[2] = (val >> 16) & 0xff; 551 } 552 553 static __inline void 554 _lto4l(val, bytes) 555 u_int32_t val; 556 u_int8_t *bytes; 557 { 558 559 bytes[0] = val & 0xff; 560 bytes[1] = (val >> 8) & 0xff; 561 bytes[2] = (val >> 16) & 0xff; 562 bytes[3] = (val >> 24) & 0xff; 563 } 564 565 static __inline u_int32_t 566 _2ltol(bytes) 567 const u_int8_t *bytes; 568 { 569 u_int32_t rv; 570 571 rv = bytes[0] | 572 (bytes[1] << 8); 573 return (rv); 574 } 575 576 static __inline u_int32_t 577 _3ltol(bytes) 578 const u_int8_t *bytes; 579 { 580 u_int32_t rv; 581 582 rv = bytes[0] | 583 (bytes[1] << 8) | 584 (bytes[2] << 16); 585 return (rv); 586 } 587 588 static __inline u_int32_t 589 _4ltol(bytes) 590 const u_int8_t *bytes; 591 { 592 u_int32_t rv; 593 594 rv = bytes[0] | 595 (bytes[1] << 8) | 596 (bytes[2] << 16) | 597 (bytes[3] << 24); 598 return (rv); 599 } 600 601 static __inline void 602 bswap (buf, len) 603 char *buf; 604 int len; 605 { 606 u_int16_t *p = (u_int16_t *)(buf + len); 607 608 while (--p >= (u_int16_t *)buf) 609 *p = (*p & 0xff) << 8 | (*p >> 8 & 0xff); 610 } 611 612 #endif /* _DEV_SCSIPI_SCSIPICONF_H_ */ 613