scsireq.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. /* this file is also included by usb/disk and cdfs */
  10. typedef struct Umsc Umsc;
  11. #pragma incomplete Umsc
  12. enum { /* fundamental constants/defaults */
  13. NTargetID = 8, /* number of target IDs */
  14. CtlrID = 7, /* default controller target ID */
  15. MaxDirData = 255, /* max. direct data returned */
  16. LBsize = 512, /* default logical-block size */
  17. };
  18. typedef struct {
  19. unsigned char *p;
  20. int32_t count;
  21. unsigned char write;
  22. } ScsiPtr;
  23. typedef struct {
  24. int flags;
  25. char *unit; /* unit directory */
  26. int lun;
  27. uint32_t lbsize;
  28. uint32_t offset; /* in blocks of lbsize bytes */
  29. int fd;
  30. Umsc *umsc; /* lun */
  31. ScsiPtr cmd;
  32. ScsiPtr data;
  33. int status; /* returned status */
  34. unsigned char sense[MaxDirData]; /* returned sense data */
  35. unsigned char inquiry[MaxDirData]; /* returned inquiry data */
  36. int readblock; /* flag: read a block since open */
  37. } ScsiReq;
  38. enum { /* software flags */
  39. Fopen = 0x0001, /* open */
  40. Fseqdev = 0x0002, /* sequential-access device */
  41. Fwritten = 0x0004, /* device written */
  42. Fronly = 0x0008, /* device is read-only */
  43. Fwormdev = 0x0010, /* write-once read-multiple device */
  44. Fprintdev = 0x0020, /* printer */
  45. Fbfixed = 0x0040, /* fixed block size */
  46. Fchanger = 0x0080, /* medium-changer device */
  47. Finqok = 0x0100, /* inquiry data is OK */
  48. Fmode6 = 0x0200, /* use 6-byte modeselect */
  49. Frw10 = 0x0400, /* use 10-byte read/write */
  50. Fusb = 0x0800, /* USB transparent scsi */
  51. };
  52. enum {
  53. STnomem =-4, /* buffer allocation failed */
  54. STharderr =-3, /* controller error of some kind */
  55. STtimeout =-2, /* bus timeout */
  56. STok = 0, /* good */
  57. STcheck = 0x02, /* check condition */
  58. STcondmet = 0x04, /* condition met/good */
  59. STbusy = 0x08, /* busy */
  60. STintok = 0x10, /* intermediate/good */
  61. STintcondmet = 0x14, /* intermediate/condition met/good */
  62. STresconf = 0x18, /* reservation conflict */
  63. STterminated = 0x22, /* command terminated */
  64. STqfull = 0x28, /* queue full */
  65. };
  66. enum { /* status */
  67. Status_SD = 0x80, /* sense-data available */
  68. Status_SW = 0x83, /* internal software error */
  69. Status_BADARG = 0x84, /* bad argument to request */
  70. Status_RO = 0x85, /* device is read-only */
  71. };
  72. enum {
  73. /* sense data byte 0 */
  74. Sd0valid = 0x80, /* valid sense data present */
  75. /* sense data byte 2 */
  76. /* incorrect-length indicator, difference in bytes 3—6 */
  77. Sd2ili = 0x20,
  78. Sd2eom = 0x40, /* end of medium (tape) */
  79. Sd2filemark = 0x80, /* at a filemark (tape) */
  80. /* command byte 1 */
  81. Cmd1fixed = 1, /* use fixed-length blocks */
  82. Cmd1sili = 2, /* don't set Sd2ili */
  83. /* limit of block #s in 24-bit ccbs */
  84. Max24off = (1<<21) - 1, /* 2⁲ⁱ - 1 */
  85. /* mode pages */
  86. Allmodepages = 0x3F,
  87. };
  88. /* p arguments should be of type unsigned char* */
  89. #define GETBELONG(p) ((uint32_t)(p)[0]<<24 | (uint32_t)(p)[1]<<16 | (p)[2]<<8 | (p)[3])
  90. #define PUTBELONG(p, ul) ((p)[0] = (ul)>>24, (p)[1] = (ul)>>16, \
  91. (p)[2] = (ul)>>8, (p)[3] = (ul))
  92. #define GETBE24(p) ((uint32_t)(p)[0]<<16 | (p)[1]<<8 | (p)[2])
  93. #define PUTBE24(p, ul) ((p)[0] = (ul)>>16, (p)[1] = (ul)>>8, (p)[2] = (ul))
  94. extern int32_t maxiosize;
  95. int32_t SRready(ScsiReq*);
  96. int32_t SRrewind(ScsiReq*);
  97. int32_t SRreqsense(ScsiReq*);
  98. int32_t SRformat(ScsiReq*);
  99. int32_t SRrblimits(ScsiReq*, unsigned char*);
  100. int32_t SRread(ScsiReq*, void*, int32_t);
  101. int32_t SRwrite(ScsiReq*, void*, int32_t);
  102. int32_t SRseek(ScsiReq*, int32_t, int);
  103. int32_t SRfilemark(ScsiReq*, uint32_t);
  104. int32_t SRspace(ScsiReq*, unsigned char, int32_t);
  105. int32_t SRinquiry(ScsiReq*);
  106. int32_t SRmodeselect6(ScsiReq*, unsigned char*, int32_t);
  107. int32_t SRmodeselect10(ScsiReq*, unsigned char*, int32_t);
  108. int32_t SRmodesense6(ScsiReq*, unsigned char, unsigned char*, int32_t);
  109. int32_t SRmodesense10(ScsiReq*, unsigned char, unsigned char*, int32_t);
  110. int32_t SRstart(ScsiReq*, unsigned char);
  111. int32_t SRrcapacity(ScsiReq*, unsigned char*);
  112. int32_t SRblank(ScsiReq*, unsigned char, unsigned char); /* MMC CD-R/CD-RW commands */
  113. int32_t SRsynccache(ScsiReq*);
  114. int32_t SRTOC(ScsiReq*, void*, int, unsigned char, unsigned char);
  115. int32_t SRrdiscinfo(ScsiReq*, void*, int);
  116. int32_t SRrtrackinfo(ScsiReq*, void*, int, int);
  117. int32_t SRcdpause(ScsiReq*, int); /* MMC CD audio commands */
  118. int32_t SRcdstop(ScsiReq*);
  119. int32_t SRcdload(ScsiReq*, int, int);
  120. int32_t SRcdplay(ScsiReq*, int, int32_t, int32_t);
  121. int32_t SRcdstatus(ScsiReq*, unsigned char*, int);
  122. int32_t SRgetconf(ScsiReq*, unsigned char*, int);
  123. /* old CD-R/CD-RW commands */
  124. int32_t SRfwaddr(ScsiReq*, unsigned char, unsigned char, unsigned char, unsigned char*);
  125. int32_t SRtreserve(ScsiReq*, int32_t);
  126. int32_t SRtinfo(ScsiReq*, unsigned char, unsigned char*);
  127. int32_t SRwtrack(ScsiReq*, void*, int32_t, unsigned char, unsigned char);
  128. int32_t SRmload(ScsiReq*, unsigned char);
  129. int32_t SRfixation(ScsiReq*, unsigned char);
  130. int32_t SReinitialise(ScsiReq*); /* CHANGER commands */
  131. int32_t SRestatus(ScsiReq*, unsigned char, unsigned char*, int);
  132. int32_t SRmmove(ScsiReq*, int, int, int, int);
  133. int32_t SRrequest(ScsiReq*);
  134. int SRclose(ScsiReq*);
  135. int SRopenraw(ScsiReq*, char*);
  136. int SRopen(ScsiReq*, char*);
  137. void makesense(ScsiReq*);
  138. int32_t umsrequest(struct Umsc*, ScsiPtr*, ScsiPtr*, int*);