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