home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.1 (Developer) [x86] / NeXT Step 3.1 Intel dev.cdr.dmg / NextDeveloper / Headers / bsd / dev / i386 / scsi_inline.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-30  |  4.1 KB  |  240 lines

  1. /*
  2.  * Copyright (c) 1992 NeXT Computer, Inc.
  3.  *
  4.  * Inline functions for SCSI drivers.
  5.  *
  6.  * HISTORY
  7.  *
  8.  * 8 July 1992 David E. Bohman at NeXT
  9.  *    Created.
  10.  */
  11.  
  12. #if    defined(KERNEL_PRIVATE) || defined(DRIVER_PRIVATE)
  13.  
  14. #import <mach/mach_types.h>
  15.  
  16. #import <bsd/dev/scsireg.h>
  17.  
  18. typedef union {
  19.     struct {
  20.     unsigned char    byte0,
  21.             byte1,
  22.             byte2,
  23.             byte3;
  24.     } bytes;
  25.     unsigned int    word;
  26. } conv_t;
  27.  
  28. /*
  29.  * Setup SCSI command blocks.
  30.  */
  31.  
  32. static inline
  33. void
  34. scsi_testrdy_setup(
  35.     struct cdb_6    *c6p,
  36.     int            lun
  37. )
  38. {
  39.     c6p->c6_opcode    = C6OP_TESTRDY;
  40.     c6p->c6_lun        = lun;
  41. }
  42.  
  43. static inline
  44. void
  45. scsi_inquiry_setup(
  46.     struct cdb_6    *c6p,
  47.     int            lun,
  48.     int            len
  49. )
  50. {
  51.     c6p->c6_opcode    = C6OP_INQUIRY;
  52.     c6p->c6_lun        = lun;
  53.     c6p->c6_len        = len;
  54. }
  55.  
  56. static inline
  57. void
  58. scsi_modesense_setup(
  59.     struct cdb_6    *c6p,
  60.     int            lun,
  61.     int            len
  62. )
  63. {
  64.     c6p->c6_opcode    = C6OP_MODESENSE;
  65.     c6p->c6_lun        = lun;
  66.     c6p->c6_len        = len;
  67. }
  68.  
  69. static inline
  70. void
  71. scsi_reqsense_setup(
  72.     struct cdb_6    *c6p,
  73.     int            lun,
  74.     int            len
  75. )
  76. {
  77.     c6p->c6_opcode    = C6OP_REQSENSE;
  78.     c6p->c6_lun        = lun;
  79.     c6p->c6_len        = len;
  80. }
  81.  
  82. static inline
  83. scsi_spinup_setup(
  84.     struct cdb_6s    *c6p,
  85.     int            lun
  86. )
  87. {
  88.     c6p->c6s_opcode    = C6OP_STARTSTOP;
  89.     c6p->c6s_lun    = lun;
  90.     c6p->c6s_opt    = C6OPT_IMMED;
  91.     c6p->c6s_len0    = C6S_SS_START;
  92. }
  93.  
  94. static inline
  95. scsi_eject_setup(
  96.     struct cdb_6s    *c6p,
  97.     int            lun
  98. )
  99. {
  100.     c6p->c6s_opcode    = C6OP_STARTSTOP;
  101.     c6p->c6s_lun    = lun;
  102.     c6p->c6s_len0    = C6S_SS_EJECT;
  103. }
  104.  
  105. static inline
  106. scsi_readcapacity_setup(
  107.     struct cdb_10    *c10p,
  108.     int            lun
  109. )
  110. {
  111.     c10p->c10_opcode    = C10OP_READCAPACITY;
  112.     c10p->c10_lun    = lun;
  113. }
  114.  
  115. static inline
  116. scsi_readextended_setup(
  117.     struct cdb_10    *c10p,
  118.     int            lun,
  119.     unsigned int    blkno,
  120.     unsigned int    nblk
  121. )
  122. {
  123.     conv_t        tconv;
  124.  
  125.     c10p->c10_opcode    = C10OP_READEXTENDED;
  126.     c10p->c10_lun    = lun;
  127.     
  128.     tconv.word        = blkno;
  129.     c10p->c10_lba3    = tconv.bytes.byte3;
  130.     c10p->c10_lba2    = tconv.bytes.byte2;
  131.     c10p->c10_lba1    = tconv.bytes.byte1;
  132.     c10p->c10_lba0    = tconv.bytes.byte0;
  133.     
  134.     tconv.word        = nblk;
  135.     c10p->c10_len1    = tconv.bytes.byte1;
  136.     c10p->c10_len0    = tconv.bytes.byte0;
  137. }
  138.  
  139. static inline
  140. scsi_writeextended_setup(
  141.     struct cdb_10    *c10p,
  142.     int            lun,
  143.     unsigned int    blkno,
  144.     unsigned int    nblk
  145. )
  146. {
  147.     conv_t        tconv;
  148.  
  149.     c10p->c10_opcode    = C10OP_WRITEEXTENDED;
  150.     c10p->c10_lun    = lun;
  151.     
  152.     tconv.word        = blkno;
  153.     c10p->c10_lba3    = tconv.bytes.byte3;
  154.     c10p->c10_lba2    = tconv.bytes.byte2;
  155.     c10p->c10_lba1    = tconv.bytes.byte1;
  156.     c10p->c10_lba0    = tconv.bytes.byte0;
  157.     
  158.     tconv.word        = nblk;
  159.     c10p->c10_len1    = tconv.bytes.byte1;
  160.     c10p->c10_len0    = tconv.bytes.byte0;
  161. }
  162.  
  163. /*
  164.  * Access fields in returned SCSI
  165.  * data structures.
  166.  */
  167.  
  168. static inline
  169. unsigned int
  170. scsi_blklen(
  171.     capacity_reply_t    *crp
  172. )
  173. {
  174.     conv_t        tconv;
  175.     
  176.     tconv.bytes.byte3    = crp->cr_blklen3;
  177.     tconv.bytes.byte2    = crp->cr_blklen2;
  178.     tconv.bytes.byte1    = crp->cr_blklen1;
  179.     tconv.bytes.byte0    = crp->cr_blklen0;
  180.     
  181.     return (tconv.word);
  182. }
  183.  
  184. static inline
  185. unsigned int
  186. scsi_lastlba(
  187.     capacity_reply_t    *crp
  188. )
  189. {
  190.     conv_t        tconv;
  191.     
  192.     tconv.bytes.byte3    = crp->cr_lastlba3;
  193.     tconv.bytes.byte2    = crp->cr_lastlba2;
  194.     tconv.bytes.byte1    = crp->cr_lastlba1;
  195.     tconv.bytes.byte0    = crp->cr_lastlba0;
  196.     
  197.     return (tconv.word);
  198. }
  199.  
  200. static inline
  201. unsigned int
  202. scsi_error_info(
  203.     esense_reply_t    *erp
  204. )
  205. {
  206.     conv_t        tconv;
  207.     
  208.     tconv.bytes.byte3    = erp->er_info3;
  209.     tconv.bytes.byte2    = erp->er_info2;
  210.     tconv.bytes.byte1    = erp->er_info1;
  211.     tconv.bytes.byte0    = erp->er_info0;
  212.     
  213.     return (tconv.word);
  214. }
  215.  
  216.  
  217. static inline void
  218. scsi_crp_setup(
  219.     capacity_reply_t    *crp,
  220.     unsigned int    cr_blklen,
  221.     unsigned int    cr_lastlba
  222. )
  223. {
  224.     conv_t        tconv;
  225.     
  226.     tconv.word = cr_blklen;
  227.     crp->cr_blklen3 = tconv.bytes.byte3;
  228.     crp->cr_blklen2 = tconv.bytes.byte2;
  229.     crp->cr_blklen1 = tconv.bytes.byte1;
  230.     crp->cr_blklen0 = tconv.bytes.byte0;
  231.    
  232.     tconv.word = cr_lastlba;
  233.     crp->cr_lastlba3 = tconv.bytes.byte3;
  234.     crp->cr_lastlba2 = tconv.bytes.byte2;
  235.     crp->cr_lastlba1 = tconv.bytes.byte1;
  236.     crp->cr_lastlba0 = tconv.bytes.byte0;
  237. }
  238.  
  239. #endif
  240.