1 /* $NetBSD: scsipiconf.h,v 1.43 2000/05/31 09:15:48 augustss 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 333 /* 334 * scsipi_xfer status flags 335 */ 336 #define XS_STS_DONE 0x00000001 /* scsipi_xfer is done */ 337 338 /* 339 * Error values an adapter driver may return 340 */ 341 #define XS_NOERROR 0 /* there is no error, (sense is invalid) */ 342 #define XS_SENSE 1 /* Check the returned sense for the error */ 343 #define XS_SHORTSENSE 2 /* Check the ATAPI sense for the error */ 344 #define XS_DRIVER_STUFFUP 3 /* Driver failed to perform operation */ 345 #define XS_SELTIMEOUT 4 /* The device timed out.. turned off? */ 346 #define XS_TIMEOUT 5 /* The Timeout reported was caught by SW */ 347 #define XS_BUSY 7 /* The device busy, try again later? */ 348 #define XS_RESET 8 /* bus was reset; possible retry command */ 349 350 /* 351 * This describes matching information for scsipi_inqmatch(). The more things 352 * match, the higher the configuration priority. 353 */ 354 struct scsipi_inquiry_pattern { 355 u_int8_t type; 356 boolean removable; 357 char *vendor; 358 char *product; 359 char *revision; 360 }; 361 362 /* 363 * This is used to pass information from the high-level configuration code 364 * to the device-specific drivers. 365 */ 366 367 struct scsipibus_attach_args { 368 struct scsipi_link *sa_sc_link; 369 struct scsipi_inquiry_pattern sa_inqbuf; 370 struct scsipi_inquiry_data *sa_inqptr; 371 union { /* bus-type specific infos */ 372 u_int8_t scsi_version; /* SCSI version */ 373 } scsipi_info; 374 }; 375 376 /* 377 * this describes a quirk entry 378 */ 379 380 struct scsi_quirk_inquiry_pattern { 381 struct scsipi_inquiry_pattern pattern; 382 u_int16_t quirks; 383 }; 384 385 /* 386 * Macro to issue a SCSI command. Treat it like a function: 387 * 388 * int scsipi_command __P((struct scsipi_link *link, 389 * struct scsipi_generic *scsipi_cmd, int cmdlen, 390 * u_char *data_addr, int datalen, int retries, 391 * int timeout, struct buf *bp, int flags)); 392 */ 393 #define scsipi_command(l, c, cl, da, dl, r, t, b, f) \ 394 (*(l)->scsipi_cmd)((l), (c), (cl), (da), (dl), (r), (t), (b), (f)) 395 396 /* 397 * Default number of retries, used for generic routines. 398 */ 399 #define SCSIPIRETRIES 4 400 401 /* 402 * Similar, but invoke the controller directly with a scsipi_xfer. 403 */ 404 #define scsipi_command_direct(xs) \ 405 (*(xs)->sc_link->adapter->scsipi_cmd)((xs)) 406 407 #ifdef _KERNEL 408 void scsipi_init __P((void)); 409 caddr_t scsipi_inqmatch __P((struct scsipi_inquiry_pattern *, caddr_t, 410 int, int, int *)); 411 char *scsipi_dtype __P((int)); 412 void scsipi_strvis __P((u_char *, int, u_char *, int)); 413 int scsipi_execute_xs __P((struct scsipi_xfer *)); 414 u_long scsipi_size __P((struct scsipi_link *, int)); 415 int scsipi_test_unit_ready __P((struct scsipi_link *, int)); 416 int scsipi_prevent __P((struct scsipi_link *, int, int)); 417 int scsipi_inquire __P((struct scsipi_link *, 418 struct scsipi_inquiry_data *, int)); 419 int scsipi_start __P((struct scsipi_link *, int, int)); 420 void scsipi_done __P((struct scsipi_xfer *)); 421 void scsipi_user_done __P((struct scsipi_xfer *)); 422 int scsipi_interpret_sense __P((struct scsipi_xfer *)); 423 void scsipi_wait_drain __P((struct scsipi_link *)); 424 void scsipi_kill_pending __P((struct scsipi_link *)); 425 #ifdef SCSIVERBOSE 426 void scsipi_print_sense __P((struct scsipi_xfer *, int)); 427 void scsipi_print_sense_data __P((struct scsipi_sense_data *, int)); 428 char *scsipi_decode_sense __P((void *, int)); 429 #endif 430 int scsipi_do_ioctl __P((struct scsipi_link *, dev_t, u_long, caddr_t, 431 int, struct proc *)); 432 433 int scsipi_adapter_addref __P((struct scsipi_link *)); 434 void scsipi_adapter_delref __P((struct scsipi_link *)); 435 436 void show_scsipi_xs __P((struct scsipi_xfer *)); 437 void show_scsipi_cmd __P((struct scsipi_xfer *)); 438 void show_mem __P((u_char *, int)); 439 #endif /* _KERNEL */ 440 441 static __inline void _lto2b __P((u_int32_t val, u_int8_t *bytes)) 442 __attribute__ ((unused)); 443 static __inline void _lto3b __P((u_int32_t val, u_int8_t *bytes)) 444 __attribute__ ((unused)); 445 static __inline void _lto4b __P((u_int32_t val, u_int8_t *bytes)) 446 __attribute__ ((unused)); 447 static __inline u_int32_t _2btol __P((const u_int8_t *bytes)) 448 __attribute__ ((unused)); 449 static __inline u_int32_t _3btol __P((const u_int8_t *bytes)) 450 __attribute__ ((unused)); 451 static __inline u_int32_t _4btol __P((const u_int8_t *bytes)) 452 __attribute__ ((unused)); 453 454 static __inline void _lto2l __P((u_int32_t val, u_int8_t *bytes)) 455 __attribute__ ((unused)); 456 static __inline void _lto3l __P((u_int32_t val, u_int8_t *bytes)) 457 __attribute__ ((unused)); 458 static __inline void _lto4l __P((u_int32_t val, u_int8_t *bytes)) 459 __attribute__ ((unused)); 460 static __inline u_int32_t _2ltol __P((const u_int8_t *bytes)) 461 __attribute__ ((unused)); 462 static __inline u_int32_t _3ltol __P((const u_int8_t *bytes)) 463 __attribute__ ((unused)); 464 static __inline u_int32_t _4ltol __P((const u_int8_t *bytes)) 465 __attribute__ ((unused)); 466 static __inline void bswap __P((char *, int)) 467 __attribute__ ((unused)); 468 469 static __inline void 470 _lto2b(val, bytes) 471 u_int32_t val; 472 u_int8_t *bytes; 473 { 474 475 bytes[0] = (val >> 8) & 0xff; 476 bytes[1] = val & 0xff; 477 } 478 479 static __inline void 480 _lto3b(val, bytes) 481 u_int32_t val; 482 u_int8_t *bytes; 483 { 484 485 bytes[0] = (val >> 16) & 0xff; 486 bytes[1] = (val >> 8) & 0xff; 487 bytes[2] = val & 0xff; 488 } 489 490 static __inline void 491 _lto4b(val, bytes) 492 u_int32_t val; 493 u_int8_t *bytes; 494 { 495 496 bytes[0] = (val >> 24) & 0xff; 497 bytes[1] = (val >> 16) & 0xff; 498 bytes[2] = (val >> 8) & 0xff; 499 bytes[3] = val & 0xff; 500 } 501 502 static __inline u_int32_t 503 _2btol(bytes) 504 const u_int8_t *bytes; 505 { 506 u_int32_t rv; 507 508 rv = (bytes[0] << 8) | 509 bytes[1]; 510 return (rv); 511 } 512 513 static __inline u_int32_t 514 _3btol(bytes) 515 const u_int8_t *bytes; 516 { 517 u_int32_t rv; 518 519 rv = (bytes[0] << 16) | 520 (bytes[1] << 8) | 521 bytes[2]; 522 return (rv); 523 } 524 525 static __inline u_int32_t 526 _4btol(bytes) 527 const u_int8_t *bytes; 528 { 529 u_int32_t rv; 530 531 rv = (bytes[0] << 24) | 532 (bytes[1] << 16) | 533 (bytes[2] << 8) | 534 bytes[3]; 535 return (rv); 536 } 537 538 static __inline void 539 _lto2l(val, bytes) 540 u_int32_t val; 541 u_int8_t *bytes; 542 { 543 544 bytes[0] = val & 0xff; 545 bytes[1] = (val >> 8) & 0xff; 546 } 547 548 static __inline void 549 _lto3l(val, bytes) 550 u_int32_t val; 551 u_int8_t *bytes; 552 { 553 554 bytes[0] = val & 0xff; 555 bytes[1] = (val >> 8) & 0xff; 556 bytes[2] = (val >> 16) & 0xff; 557 } 558 559 static __inline void 560 _lto4l(val, bytes) 561 u_int32_t val; 562 u_int8_t *bytes; 563 { 564 565 bytes[0] = val & 0xff; 566 bytes[1] = (val >> 8) & 0xff; 567 bytes[2] = (val >> 16) & 0xff; 568 bytes[3] = (val >> 24) & 0xff; 569 } 570 571 static __inline u_int32_t 572 _2ltol(bytes) 573 const u_int8_t *bytes; 574 { 575 u_int32_t rv; 576 577 rv = bytes[0] | 578 (bytes[1] << 8); 579 return (rv); 580 } 581 582 static __inline u_int32_t 583 _3ltol(bytes) 584 const u_int8_t *bytes; 585 { 586 u_int32_t rv; 587 588 rv = bytes[0] | 589 (bytes[1] << 8) | 590 (bytes[2] << 16); 591 return (rv); 592 } 593 594 static __inline u_int32_t 595 _4ltol(bytes) 596 const u_int8_t *bytes; 597 { 598 u_int32_t rv; 599 600 rv = bytes[0] | 601 (bytes[1] << 8) | 602 (bytes[2] << 16) | 603 (bytes[3] << 24); 604 return (rv); 605 } 606 607 static __inline void 608 bswap (buf, len) 609 char *buf; 610 int len; 611 { 612 u_int16_t *p = (u_int16_t *)(buf + len); 613 614 while (--p >= (u_int16_t *)buf) 615 *p = (*p & 0xff) << 8 | (*p >> 8 & 0xff); 616 } 617 618 #endif /* _DEV_SCSIPI_SCSIPICONF_H_ */ 619