home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (c) 1992 NeXT Computer, Inc.
- *
- * Inline functions for SCSI drivers.
- *
- * HISTORY
- *
- * 8 July 1992 David E. Bohman at NeXT
- * Created.
- */
-
- #if defined(KERNEL_PRIVATE) || defined(DRIVER_PRIVATE)
-
- #import <mach/mach_types.h>
-
- #import <bsd/dev/scsireg.h>
-
- typedef union {
- struct {
- unsigned char byte0,
- byte1,
- byte2,
- byte3;
- } bytes;
- unsigned int word;
- } conv_t;
-
- /*
- * Setup SCSI command blocks.
- */
-
- static inline
- void
- scsi_testrdy_setup(
- struct cdb_6 *c6p,
- int lun
- )
- {
- c6p->c6_opcode = C6OP_TESTRDY;
- c6p->c6_lun = lun;
- }
-
- static inline
- void
- scsi_inquiry_setup(
- struct cdb_6 *c6p,
- int lun,
- int len
- )
- {
- c6p->c6_opcode = C6OP_INQUIRY;
- c6p->c6_lun = lun;
- c6p->c6_len = len;
- }
-
- static inline
- void
- scsi_modesense_setup(
- struct cdb_6 *c6p,
- int lun,
- int len
- )
- {
- c6p->c6_opcode = C6OP_MODESENSE;
- c6p->c6_lun = lun;
- c6p->c6_len = len;
- }
-
- static inline
- void
- scsi_reqsense_setup(
- struct cdb_6 *c6p,
- int lun,
- int len
- )
- {
- c6p->c6_opcode = C6OP_REQSENSE;
- c6p->c6_lun = lun;
- c6p->c6_len = len;
- }
-
- static inline
- scsi_spinup_setup(
- struct cdb_6s *c6p,
- int lun
- )
- {
- c6p->c6s_opcode = C6OP_STARTSTOP;
- c6p->c6s_lun = lun;
- c6p->c6s_opt = C6OPT_IMMED;
- c6p->c6s_len0 = C6S_SS_START;
- }
-
- static inline
- scsi_eject_setup(
- struct cdb_6s *c6p,
- int lun
- )
- {
- c6p->c6s_opcode = C6OP_STARTSTOP;
- c6p->c6s_lun = lun;
- c6p->c6s_len0 = C6S_SS_EJECT;
- }
-
- static inline
- scsi_readcapacity_setup(
- struct cdb_10 *c10p,
- int lun
- )
- {
- c10p->c10_opcode = C10OP_READCAPACITY;
- c10p->c10_lun = lun;
- }
-
- static inline
- scsi_readextended_setup(
- struct cdb_10 *c10p,
- int lun,
- unsigned int blkno,
- unsigned int nblk
- )
- {
- conv_t tconv;
-
- c10p->c10_opcode = C10OP_READEXTENDED;
- c10p->c10_lun = lun;
-
- tconv.word = blkno;
- c10p->c10_lba3 = tconv.bytes.byte3;
- c10p->c10_lba2 = tconv.bytes.byte2;
- c10p->c10_lba1 = tconv.bytes.byte1;
- c10p->c10_lba0 = tconv.bytes.byte0;
-
- tconv.word = nblk;
- c10p->c10_len1 = tconv.bytes.byte1;
- c10p->c10_len0 = tconv.bytes.byte0;
- }
-
- static inline
- scsi_writeextended_setup(
- struct cdb_10 *c10p,
- int lun,
- unsigned int blkno,
- unsigned int nblk
- )
- {
- conv_t tconv;
-
- c10p->c10_opcode = C10OP_WRITEEXTENDED;
- c10p->c10_lun = lun;
-
- tconv.word = blkno;
- c10p->c10_lba3 = tconv.bytes.byte3;
- c10p->c10_lba2 = tconv.bytes.byte2;
- c10p->c10_lba1 = tconv.bytes.byte1;
- c10p->c10_lba0 = tconv.bytes.byte0;
-
- tconv.word = nblk;
- c10p->c10_len1 = tconv.bytes.byte1;
- c10p->c10_len0 = tconv.bytes.byte0;
- }
-
- /*
- * Access fields in returned SCSI
- * data structures.
- */
-
- static inline
- unsigned int
- scsi_blklen(
- capacity_reply_t *crp
- )
- {
- conv_t tconv;
-
- tconv.bytes.byte3 = crp->cr_blklen3;
- tconv.bytes.byte2 = crp->cr_blklen2;
- tconv.bytes.byte1 = crp->cr_blklen1;
- tconv.bytes.byte0 = crp->cr_blklen0;
-
- return (tconv.word);
- }
-
- static inline
- unsigned int
- scsi_lastlba(
- capacity_reply_t *crp
- )
- {
- conv_t tconv;
-
- tconv.bytes.byte3 = crp->cr_lastlba3;
- tconv.bytes.byte2 = crp->cr_lastlba2;
- tconv.bytes.byte1 = crp->cr_lastlba1;
- tconv.bytes.byte0 = crp->cr_lastlba0;
-
- return (tconv.word);
- }
-
- static inline
- unsigned int
- scsi_error_info(
- esense_reply_t *erp
- )
- {
- conv_t tconv;
-
- tconv.bytes.byte3 = erp->er_info3;
- tconv.bytes.byte2 = erp->er_info2;
- tconv.bytes.byte1 = erp->er_info1;
- tconv.bytes.byte0 = erp->er_info0;
-
- return (tconv.word);
- }
-
-
- static inline void
- scsi_crp_setup(
- capacity_reply_t *crp,
- unsigned int cr_blklen,
- unsigned int cr_lastlba
- )
- {
- conv_t tconv;
-
- tconv.word = cr_blklen;
- crp->cr_blklen3 = tconv.bytes.byte3;
- crp->cr_blklen2 = tconv.bytes.byte2;
- crp->cr_blklen1 = tconv.bytes.byte1;
- crp->cr_blklen0 = tconv.bytes.byte0;
-
- tconv.word = cr_lastlba;
- crp->cr_lastlba3 = tconv.bytes.byte3;
- crp->cr_lastlba2 = tconv.bytes.byte2;
- crp->cr_lastlba1 = tconv.bytes.byte1;
- crp->cr_lastlba0 = tconv.bytes.byte0;
- }
-
- #endif
-