1 /* 2 * This is /sys/src/cmd/scuzz/scsireq.c 3 * changed to add more debug support, to keep 4 * disk compiling without a scuzz that includes these changes. 5 */ 6 /* this file is also included by usb/disk and cdfs */ 7 typedef struct Umsc Umsc; 8 #pragma incomplete Umsc 9 10 enum { /* fundamental constants/defaults */ 11 NTargetID = 8, /* number of target IDs */ 12 CtlrID = 7, /* default controller target ID */ 13 MaxDirData = 255, /* max. direct data returned */ 14 LBsize = 512, /* default logical-block size */ 15 }; 16 17 typedef struct { 18 uchar *p; 19 long count; 20 uchar write; 21 } ScsiPtr; 22 23 typedef struct { 24 int flags; 25 char *unit; /* unit directory */ 26 int lun; 27 ulong lbsize; 28 ulong 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 uchar sense[MaxDirData]; /* returned sense data */ 35 uchar inquiry[MaxDirData]; /* returned inquiry data */ 36 int readblock; /* flag: read a block since open */ 37 } ScsiReq; 38 39 enum { /* software flags */ 40 Fopen = 0x0001, /* open */ 41 Fseqdev = 0x0002, /* sequential-access device */ 42 Fwritten = 0x0004, /* device written */ 43 Fronly = 0x0008, /* device is read-only */ 44 Fwormdev = 0x0010, /* write-once read-multiple device */ 45 Fprintdev = 0x0020, /* printer */ 46 Fbfixed = 0x0040, /* fixed block size */ 47 Fchanger = 0x0080, /* medium-changer device */ 48 Finqok = 0x0100, /* inquiry data is OK */ 49 Fmode6 = 0x0200, /* use 6-byte modeselect */ 50 Frw10 = 0x0400, /* use 10-byte read/write */ 51 Fusb = 0x0800, /* USB transparent scsi */ 52 }; 53 54 enum { 55 STnomem =-4, /* buffer allocation failed */ 56 STharderr =-3, /* controller error of some kind */ 57 STtimeout =-2, /* bus timeout */ 58 STok = 0, /* good */ 59 STcheck = 0x02, /* check condition */ 60 STcondmet = 0x04, /* condition met/good */ 61 STbusy = 0x08, /* busy */ 62 STintok = 0x10, /* intermediate/good */ 63 STintcondmet = 0x14, /* intermediate/condition met/good */ 64 STresconf = 0x18, /* reservation conflict */ 65 STterminated = 0x22, /* command terminated */ 66 STqfull = 0x28, /* queue full */ 67 }; 68 69 enum { /* status */ 70 Status_SD = 0x80, /* sense-data available */ 71 Status_SW = 0x83, /* internal software error */ 72 Status_BADARG = 0x84, /* bad argument to request */ 73 Status_RO = 0x85, /* device is read-only */ 74 }; 75 76 enum { /* SCSI command codes */ 77 ScmdTur = 0x00, /* test unit ready */ 78 ScmdRewind = 0x01, /* rezero/rewind */ 79 ScmdRsense = 0x03, /* request sense */ 80 ScmdFormat = 0x04, /* format unit */ 81 ScmdRblimits = 0x05, /* read block limits */ 82 ScmdRead = 0x08, /* read */ 83 ScmdWrite = 0x0A, /* write */ 84 ScmdSeek = 0x0B, /* seek */ 85 ScmdFmark = 0x10, /* write filemarks */ 86 ScmdSpace = 0x11, /* space forward/backward */ 87 ScmdInq = 0x12, /* inquiry */ 88 ScmdMselect6 = 0x15, /* mode select */ 89 ScmdMselect10 = 0x55, /* mode select */ 90 ScmdMsense6 = 0x1A, /* mode sense */ 91 ScmdMsense10 = 0x5A, /* mode sense */ 92 ScmdStart = 0x1B, /* start/stop unit */ 93 ScmdRcapacity = 0x25, /* read capacity */ 94 ScmdRcapacity16 = 0x9e, /* long read capacity */ 95 ScmdExtread = 0x28, /* extended read */ 96 ScmdExtwrite = 0x2A, /* extended write */ 97 ScmdExtseek = 0x2B, /* extended seek */ 98 99 ScmdSynccache = 0x35, /* flush cache */ 100 ScmdRTOC = 0x43, /* read TOC data */ 101 ScmdRdiscinfo = 0x51, /* read disc information */ 102 ScmdRtrackinfo = 0x52, /* read track information */ 103 ScmdReserve = 0x53, /* reserve track */ 104 ScmdBlank = 0xA1, /* blank *-RW media */ 105 106 ScmdCDpause = 0x4B, /* pause/resume */ 107 ScmdCDstop = 0x4E, /* stop play/scan */ 108 ScmdCDplay = 0xA5, /* play audio */ 109 ScmdCDload = 0xA6, /* load/unload */ 110 ScmdCDscan = 0xBA, /* fast forward/reverse */ 111 ScmdCDstatus = 0xBD, /* mechanism status */ 112 Scmdgetconf = 0x46, /* get configuration */ 113 114 ScmdEInitialise = 0x07, /* initialise element status */ 115 ScmdMMove = 0xA5, /* move medium */ 116 ScmdEStatus = 0xB8, /* read element status */ 117 ScmdMExchange = 0xA6, /* exchange medium */ 118 ScmdEposition = 0x2B, /* position to element */ 119 120 ScmdReadDVD = 0xAD, /* read dvd structure */ 121 ScmdReportKey = 0xA4, /* read dvd key */ 122 ScmdSendKey = 0xA3, /* write dvd key */ 123 124 ScmdClosetracksess= 0x5B, 125 ScmdRead12 = 0xA8, 126 ScmdSetcdspeed = 0xBB, 127 ScmdReadcd = 0xBE, 128 129 /* vendor-specific */ 130 ScmdFwaddr = 0xE2, /* first writeable address */ 131 ScmdTreserve = 0xE4, /* reserve track */ 132 ScmdTinfo = 0xE5, /* read track info */ 133 ScmdTwrite = 0xE6, /* write track */ 134 ScmdMload = 0xE7, /* medium load/unload */ 135 ScmdFixation = 0xE9, /* fixation */ 136 }; 137 138 enum { 139 /* sense data byte 0 */ 140 Sd0valid = 0x80, /* valid sense data present */ 141 142 /* sense data byte 2 */ 143 /* incorrect-length indicator, difference in bytes 3—6 */ 144 Sd2ili = 0x20, 145 Sd2eom = 0x40, /* end of medium (tape) */ 146 Sd2filemark = 0x80, /* at a filemark (tape) */ 147 148 /* command byte 1 */ 149 Cmd1fixed = 1, /* use fixed-length blocks */ 150 Cmd1sili = 2, /* don't set Sd2ili */ 151 152 /* limit of block #s in 24-bit ccbs */ 153 Max24off = (1<<21) - 1, /* 2ⁱ - 1 */ 154 155 /* mode pages */ 156 Allmodepages = 0x3F, 157 }; 158 159 /* p arguments should be of type uchar* */ 160 #define GETBELONG(p) ((ulong)(p)[0]<<24 | (ulong)(p)[1]<<16 | (p)[2]<<8 | (p)[3]) 161 #define PUTBELONG(p, ul) ((p)[0] = (ul)>>24, (p)[1] = (ul)>>16, \ 162 (p)[2] = (ul)>>8, (p)[3] = (ul)) 163 #define GETBE24(p) ((ulong)(p)[0]<<16 | (p)[1]<<8 | (p)[2]) 164 #define PUTBE24(p, ul) ((p)[0] = (ul)>>16, (p)[1] = (ul)>>8, (p)[2] = (ul)) 165 166 extern long maxiosize; 167 168 long SRready(ScsiReq*); 169 long SRrewind(ScsiReq*); 170 long SRreqsense(ScsiReq*); 171 long SRformat(ScsiReq*); 172 long SRrblimits(ScsiReq*, uchar*); 173 long SRread(ScsiReq*, void*, long); 174 long SRwrite(ScsiReq*, void*, long); 175 long SRseek(ScsiReq*, long, int); 176 long SRfilemark(ScsiReq*, ulong); 177 long SRspace(ScsiReq*, uchar, long); 178 long SRinquiry(ScsiReq*); 179 long SRmodeselect6(ScsiReq*, uchar*, long); 180 long SRmodeselect10(ScsiReq*, uchar*, long); 181 long SRmodesense6(ScsiReq*, uchar, uchar*, long); 182 long SRmodesense10(ScsiReq*, uchar, uchar*, long); 183 long SRstart(ScsiReq*, uchar); 184 long SRrcapacity(ScsiReq*, uchar*); 185 long SRrcapacity16(ScsiReq*, uchar*); 186 187 long SRblank(ScsiReq*, uchar, uchar); /* MMC CD-R/CD-RW commands */ 188 long SRsynccache(ScsiReq*); 189 long SRTOC(ScsiReq*, void*, int, uchar, uchar); 190 long SRrdiscinfo(ScsiReq*, void*, int); 191 long SRrtrackinfo(ScsiReq*, void*, int, int); 192 193 long SRcdpause(ScsiReq*, int); /* MMC CD audio commands */ 194 long SRcdstop(ScsiReq*); 195 long SRcdload(ScsiReq*, int, int); 196 long SRcdplay(ScsiReq*, int, long, long); 197 long SRcdstatus(ScsiReq*, uchar*, int); 198 long SRgetconf(ScsiReq*, uchar*, int); 199 200 /* old CD-R/CD-RW commands */ 201 long SRfwaddr(ScsiReq*, uchar, uchar, uchar, uchar*); 202 long SRtreserve(ScsiReq*, long); 203 long SRtinfo(ScsiReq*, uchar, uchar*); 204 long SRwtrack(ScsiReq*, void*, long, uchar, uchar); 205 long SRmload(ScsiReq*, uchar); 206 long SRfixation(ScsiReq*, uchar); 207 208 long SReinitialise(ScsiReq*); /* CHANGER commands */ 209 long SRestatus(ScsiReq*, uchar, uchar*, int); 210 long SRmmove(ScsiReq*, int, int, int, int); 211 212 long SRrequest(ScsiReq*); 213 int SRclose(ScsiReq*); 214 int SRopenraw(ScsiReq*, char*); 215 int SRopen(ScsiReq*, char*); 216 217 void makesense(ScsiReq*); 218 219 long umsrequest(struct Umsc*, ScsiPtr*, ScsiPtr*, int*); 220 221 void scsidebug(int); 222 223 char* scsierrmsg(int n); 224