1
0

scsireq.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /*
  10. * This is /sys/src/cmd/scuzz/scsireq.h
  11. * changed to add more debug support, and to keep
  12. * disk compiling without a scuzz that includes these changes.
  13. *
  14. * scsireq.h is also included by usb/disk and cdfs.
  15. */
  16. typedef struct Umsc Umsc;
  17. enum { /* fundamental constants/defaults */
  18. MaxDirData = 255, /* max. direct data returned */
  19. /*
  20. * Because we are accessed via devmnt, we can never get i/o counts
  21. * larger than 8216 (Msgsize and devmnt's offered iounit) - 24
  22. * (IOHDRSZ) = 8K.
  23. */
  24. Maxiosize = 8216 - IOHDRSZ, /* max. I/O transfer size */
  25. };
  26. typedef struct {
  27. uint8_t *p;
  28. int32_t count;
  29. uint8_t write;
  30. } ScsiPtr;
  31. typedef struct {
  32. int flags;
  33. char *unit; /* unit directory */
  34. int lun;
  35. uint32_t lbsize;
  36. uint64_t offset; /* in blocks of lbsize bytes */
  37. int fd;
  38. Umsc *umsc; /* lun */
  39. ScsiPtr cmd;
  40. ScsiPtr data;
  41. int status; /* returned status */
  42. uint8_t sense[MaxDirData]; /* returned sense data */
  43. uint8_t inquiry[MaxDirData]; /* returned inquiry data */
  44. int readblock; /* flag: read a block since open */
  45. } ScsiReq;
  46. enum { /* software flags */
  47. Fopen = 0x0001, /* open */
  48. Fseqdev = 0x0002, /* sequential-access device */
  49. Fwritten = 0x0004, /* device written */
  50. Fronly = 0x0008, /* device is read-only */
  51. Fwormdev = 0x0010, /* write-once read-multiple device */
  52. Fprintdev = 0x0020, /* printer */
  53. Fbfixed = 0x0040, /* fixed block size */
  54. Fchanger = 0x0080, /* medium-changer device */
  55. Finqok = 0x0100, /* inquiry data is OK */
  56. Fmode6 = 0x0200, /* use 6-byte modeselect */
  57. Frw10 = 0x0400, /* use 10-byte read/write */
  58. Fusb = 0x0800, /* USB transparent scsi */
  59. };
  60. enum {
  61. STnomem =-4, /* buffer allocation failed */
  62. STharderr =-3, /* controller error of some kind */
  63. STtimeout =-2, /* bus timeout */
  64. STok = 0, /* good */
  65. STcheck = 0x02, /* check condition */
  66. STcondmet = 0x04, /* condition met/good */
  67. STbusy = 0x08, /* busy */
  68. STintok = 0x10, /* intermediate/good */
  69. STintcondmet = 0x14, /* intermediate/condition met/good */
  70. STresconf = 0x18, /* reservation conflict */
  71. STterminated = 0x22, /* command terminated */
  72. STqfull = 0x28, /* queue full */
  73. };
  74. enum { /* status */
  75. Status_SD = 0x80, /* sense-data available */
  76. Status_SW = 0x83, /* internal software error */
  77. Status_BADARG = 0x84, /* bad argument to request */
  78. Status_RO = 0x85, /* device is read-only */
  79. };
  80. enum {
  81. /* sense data byte 0 */
  82. Sd0valid = 0x80, /* valid sense data present */
  83. /* sense data byte 2 */
  84. /* incorrect-length indicator, difference in bytes 3—6 */
  85. Sd2ili = 0x20,
  86. Sd2eom = 0x40, /* end of medium (tape) */
  87. Sd2filemark = 0x80, /* at a filemark (tape) */
  88. /* command byte 1 */
  89. Cmd1fixed = 1, /* use fixed-length blocks */
  90. Cmd1sili = 2, /* don't set Sd2ili */
  91. /* limit of block #s in 24-bit ccbs */
  92. Max24off = (1<<21) - 1, /* 2⁲ⁱ - 1 */
  93. /* mode pages */
  94. Allmodepages = 0x3F,
  95. };
  96. /* scsi device types, from the scsi standards */
  97. enum {
  98. Devdir, /* usually disk */
  99. Devseq, /* usually tape */
  100. Devprint,
  101. Dev3,
  102. Devworm, /* also direct, but special */
  103. Devcd, /* also direct */
  104. Dev6,
  105. Devmo, /* also direct */
  106. Devjuke,
  107. };
  108. /* p arguments should be of type uint8_t* */
  109. #define GETBELONG(p) ((uint32_t)(p)[0]<<24 | (uint32_t)(p)[1]<<16 | (p)[2]<<8 | (p)[3])
  110. #define PUTBELONG(p, ul) ((p)[0] = (ul)>>24, (p)[1] = (ul)>>16, \
  111. (p)[2] = (ul)>>8, (p)[3] = (ul))
  112. #define GETBE24(p) ((uint32_t)(p)[0]<<16 | (p)[1]<<8 | (p)[2])
  113. #define PUTBE24(p, ul) ((p)[0] = (ul)>>16, (p)[1] = (ul)>>8, (p)[2] = (ul))
  114. int32_t SRready(ScsiReq*);
  115. int32_t SRrewind(ScsiReq*);
  116. int32_t SRreqsense(ScsiReq*);
  117. int32_t SRformat(ScsiReq*);
  118. int32_t SRrblimits(ScsiReq*, uint8_t*);
  119. int32_t SRread(ScsiReq*, void*, int32_t);
  120. int32_t SRwrite(ScsiReq*, void*, int32_t);
  121. int32_t SRseek(ScsiReq*, int32_t, int);
  122. int32_t SRfilemark(ScsiReq*, uint32_t);
  123. int32_t SRspace(ScsiReq*, uint8_t, int32_t);
  124. int32_t SRinquiry(ScsiReq*);
  125. int32_t SRmodeselect6(ScsiReq*, uint8_t*, int32_t);
  126. int32_t SRmodeselect10(ScsiReq*, uint8_t*, int32_t);
  127. int32_t SRmodesense6(ScsiReq*, uint8_t, uint8_t*, int32_t);
  128. int32_t SRmodesense10(ScsiReq*, uint8_t, uint8_t*, int32_t);
  129. int32_t SRstart(ScsiReq*, uint8_t);
  130. int32_t SRrcapacity(ScsiReq*, uint8_t*);
  131. int32_t SRrcapacity16(ScsiReq*, uint8_t*);
  132. int32_t SRblank(ScsiReq*, uint8_t, uint8_t); /* MMC CD-R/CD-RW commands */
  133. int32_t SRsynccache(ScsiReq*);
  134. int32_t SRTOC(ScsiReq*, void*, int, uint8_t, uint8_t);
  135. int32_t SRrdiscinfo(ScsiReq*, void*, int);
  136. int32_t SRrtrackinfo(ScsiReq*, void*, int, int);
  137. int32_t SRcdpause(ScsiReq*, int); /* MMC CD audio commands */
  138. int32_t SRcdstop(ScsiReq*);
  139. int32_t SRcdload(ScsiReq*, int, int);
  140. int32_t SRcdplay(ScsiReq*, int, int32_t, int32_t);
  141. int32_t SRcdstatus(ScsiReq*, uint8_t*, int);
  142. int32_t SRgetconf(ScsiReq*, uint8_t*, int);
  143. /* old CD-R/CD-RW commands */
  144. int32_t SRfwaddr(ScsiReq*, uint8_t, uint8_t, uint8_t, uint8_t*);
  145. int32_t SRtreserve(ScsiReq*, int32_t);
  146. int32_t SRtinfo(ScsiReq*, uint8_t, uint8_t*);
  147. int32_t SRwtrack(ScsiReq*, void*, int32_t, uint8_t, uint8_t);
  148. int32_t SRmload(ScsiReq*, uint8_t);
  149. int32_t SRfixation(ScsiReq*, uint8_t);
  150. int32_t SReinitialise(ScsiReq*); /* CHANGER commands */
  151. int32_t SRestatus(ScsiReq*, uint8_t, uint8_t*, int);
  152. int32_t SRmmove(ScsiReq*, int, int, int, int);
  153. int32_t SRrequest(ScsiReq*);
  154. int SRclose(ScsiReq*);
  155. int SRopenraw(ScsiReq*, char*);
  156. int SRopen(ScsiReq*, char*);
  157. void makesense(ScsiReq*);
  158. int32_t umsrequest(struct Umsc*, ScsiPtr*, ScsiPtr*, int*);
  159. void scsidebug(int);
  160. char* scsierrmsg(int n);