1
0

scsireq.h 5.4 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. u8 *p;
  28. i32 count;
  29. u8 write;
  30. } ScsiPtr;
  31. typedef struct {
  32. int flags;
  33. char *unit; /* unit directory */
  34. int lun;
  35. u32 lbsize;
  36. u64 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. u8 sense[MaxDirData]; /* returned sense data */
  43. u8 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 u8* */
  109. #define GETBELONG(p) ((u32)(p)[0]<<24 | (u32)(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) ((u32)(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. i32 SRready(ScsiReq*);
  115. i32 SRrewind(ScsiReq*);
  116. i32 SRreqsense(ScsiReq*);
  117. i32 SRformat(ScsiReq*);
  118. i32 SRrblimits(ScsiReq*, u8*);
  119. i32 SRread(ScsiReq*, void*, i32);
  120. i32 SRwrite(ScsiReq*, void*, i32);
  121. i32 SRseek(ScsiReq*, i32, int);
  122. i32 SRfilemark(ScsiReq*, u32);
  123. i32 SRspace(ScsiReq*, u8, i32);
  124. i32 SRinquiry(ScsiReq*);
  125. i32 SRmodeselect6(ScsiReq*, u8*, i32);
  126. i32 SRmodeselect10(ScsiReq*, u8*, i32);
  127. i32 SRmodesense6(ScsiReq*, u8, u8*, i32);
  128. i32 SRmodesense10(ScsiReq*, u8, u8*, i32);
  129. i32 SRstart(ScsiReq*, u8);
  130. i32 SRrcapacity(ScsiReq*, u8*);
  131. i32 SRrcapacity16(ScsiReq*, u8*);
  132. i32 SRblank(ScsiReq*, u8, u8); /* MMC CD-R/CD-RW commands */
  133. i32 SRsynccache(ScsiReq*);
  134. i32 SRTOC(ScsiReq*, void*, int, u8, u8);
  135. i32 SRrdiscinfo(ScsiReq*, void*, int);
  136. i32 SRrtrackinfo(ScsiReq*, void*, int, int);
  137. i32 SRcdpause(ScsiReq*, int); /* MMC CD audio commands */
  138. i32 SRcdstop(ScsiReq*);
  139. i32 SRcdload(ScsiReq*, int, int);
  140. i32 SRcdplay(ScsiReq*, int, i32, i32);
  141. i32 SRcdstatus(ScsiReq*, u8*, int);
  142. i32 SRgetconf(ScsiReq*, u8*, int);
  143. /* old CD-R/CD-RW commands */
  144. i32 SRfwaddr(ScsiReq*, u8, u8, u8, u8*);
  145. i32 SRtreserve(ScsiReq*, i32);
  146. i32 SRtinfo(ScsiReq*, u8, u8*);
  147. i32 SRwtrack(ScsiReq*, void*, i32, u8, u8);
  148. i32 SRmload(ScsiReq*, u8);
  149. i32 SRfixation(ScsiReq*, u8);
  150. i32 SReinitialise(ScsiReq*); /* CHANGER commands */
  151. i32 SRestatus(ScsiReq*, u8, u8*, int);
  152. i32 SRmmove(ScsiReq*, int, int, int, int);
  153. i32 SRrequest(ScsiReq*);
  154. int SRclose(ScsiReq*);
  155. int SRopenraw(ScsiReq*, char*);
  156. int SRopen(ScsiReq*, char*);
  157. void makesense(ScsiReq*);
  158. i32 umsrequest(struct Umsc*, ScsiPtr*, ScsiPtr*, int*);
  159. void scsidebug(int);
  160. char* scsierrmsg(int n);