This source file includes following definitions.
- end_scsi_request
1
2
3
4
5
6
7
8
9
10
11
12
13 #ifndef _SCSI_H
14 #define _SCSI_H
15
16
17
18
19
20
21
22
23
24
25
26
27
28 #define TEST_UNIT_READY 0x00
29 #define REZERO_UNIT 0x01
30 #define REQUEST_SENSE 0x03
31 #define FORMAT_UNIT 0x04
32 #define READ_BLOCK_LIMITS 0x05
33 #define REASSIGN_BLOCKS 0x07
34 #define READ_6 0x08
35 #define WRITE_6 0x0a
36 #define SEEK_6 0x0b
37 #define READ_REVERSE 0x0f
38 #define WRITE_FILEMARKS 0x10
39 #define SPACE 0x11
40 #define INQUIRY 0x12
41 #define RECOVER_BUFFERED_DATA 0x14
42 #define MODE_SELECT 0x15
43 #define RESERVE 0x16
44 #define RELEASE 0x17
45 #define COPY 0x18
46 #define ERASE 0x19
47 #define MODE_SENSE 0x1a
48 #define START_STOP 0x1b
49 #define RECEIVE_DIAGNOSTIC 0x1c
50 #define SEND_DIAGNOSTIC 0x1d
51 #define ALLOW_MEDIUM_REMOVAL 0x1e
52
53 #define READ_CAPACITY 0x25
54 #define READ_10 0x28
55 #define WRITE_10 0x2a
56 #define SEEK_10 0x2b
57 #define WRITE_VERIFY 0x2e
58 #define VERIFY 0x2f
59 #define SEARCH_HIGH 0x30
60 #define SEARCH_EQUAL 0x31
61 #define SEARCH_LOW 0x32
62 #define SET_LIMITS 0x33
63 #define PRE_FETCH 0x34
64 #define SYNCRONIZE_CACHE 0x35
65 #define LOCK_UNLOCK_CACHE 0x36
66 #define READ_DEFECT_DATA 0x37
67 #define COMPARE 0x39
68 #define COPY_VERIFY 0x3a
69 #define WRITE_BUFFER 0x3b
70 #define READ_BUFFER 0x3c
71 #define READ_LONG 0x3e
72 #define CHANGE_DEFINITION 0x40
73 #define LOG_SELECT 0x4c
74 #define LOG_SENSE 0x4d
75 #define MODE_SELECT_10 0x55
76 #define MODE_SENSE_10 0x5a
77
78 #define COMMAND_SIZE(opcode) ((opcode) ? ((opcode) > 0x20 ? 10 : 6) : 0)
79
80
81
82
83
84 #define COMMAND_COMPLETE 0x00
85 #define EXTENDED_MESSAGE 0x01
86 #define SAVE_POINTERS 0x02
87 #define RESTORE_POINTERS 0x03
88 #define DISCONNECT 0x04
89 #define INITIATOR_ERROR 0x05
90 #define ABORT 0x06
91 #define MESSAGE_REJECT 0x07
92 #define NOP 0x08
93 #define MSG_PARITY_ERROR 0x09
94 #define LINKED_CMD_COMPLETE 0x0a
95 #define LINKED_FLG_CMD_COMPLETE 0x0b
96 #define BUS_DEVICE_RESET 0x0c
97 #define IDENTIFY_BASE 0x80
98 #define IDENTIFY(can_disconnect, lun) (IDENTIFY_BASE |\
99 ((can_disconnect) ? 0x40 : 0) |\
100 ((lun) & 0x07))
101
102
103
104
105
106
107 #define GOOD 0x00
108 #define CHECK_CONDITION 0x01
109 #define CONDITION_GOOD 0x02
110 #define BUSY 0x04
111 #define INTERMEDIATE_GOOD 0x08
112 #define INTERMEDIATE_C_GOOD 0x0a
113 #define RESERVATION_CONFLICT 0x0c
114
115 #define STATUS_MASK 0x1e
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137 #define DID_OK 0x00
138
139 #define DID_NO_CONNECT 0x01
140
141 #define DID_BUS_BUSY 0x02
142
143 #define DID_TIME_OUT 0x03
144
145 #define DID_BAD_TARGET 0x04
146
147 #define DID_ABORT 0x05
148
149
150
151 #define DID_PARITY 0x06
152
153
154
155 #define DID_ERROR 0x07
156
157
158
159 #define DID_RESET 0x08
160
161
162
163 #define DID_BAD_INTR 0x09
164
165
166
167
168 #define DRIVER_OK 0x00
169
170
171
172
173
174 #define DRIVER_BUSY 0x01
175 #define DRIVER_SOFT 0x02
176 #define DRIVER_MEDIA 0x03
177 #define DRIVER_ERROR 0x04
178
179 #define DRIVER_INVALID 0x05
180 #define DRIVER_TIMEOUT 0x06
181 #define DRIVER_HARD 0x07
182
183 #define SUGGEST_RETRY 0x08
184 #define SUGGEST_ABORT 0x09
185 #define SUGGEST_REMAP 0x0a
186 #define SUGGEST_DIE 0x0b
187
188 #define DRIVER_SENSE 0x10
189
190 #define DRIVER_MASK 0x0f
191 #define SUGGEST_MASK 0xf0
192
193
194
195
196
197
198 #define NO_SENSE 0x00
199 #define RECOVERED_ERROR 0x01
200 #define NOT_READY 0x02
201 #define MEDIUM_ERROR 0x03
202 #define HARDWARE_ERROR 0x04
203 #define ILLEGAL_REQUEST 0x05
204 #define UNIT_ATTENTION 0x06
205 #define DATA_PROTECT 0x07
206 #define BLANK_CHECK 0x08
207 #define COPY_ABORTED 0x0a
208 #define ABORTED_COMMAND 0x0b
209 #define VOLUME_OVERFLOW 0x0d
210 #define MISCOMPARE 0x0e
211
212
213
214
215
216
217
218 #define TYPE_DISK 0x00
219 #define TYPE_TAPE 0x01
220 #define TYPE_WORM 0x04
221 #define TYPE_ROM 0x05
222 #define TYPE_NO_LUN 0x7f
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237 typedef struct scsi_device {
238 unsigned char host_no, id, lun, index;
239 int access_count;
240 struct wait_queue * device_wait;
241 char type;
242 unsigned writeable:1;
243 unsigned removable:1;
244 unsigned random:1;
245 unsigned changed:1;
246 unsigned busy:1;
247 } Scsi_Device;
248
249
250
251
252 #define status_byte(result) (((result) >> 1) & 0xf)
253 #define msg_byte(result) (((result) >> 8) & 0xff)
254 #define host_byte(result) (((result) >> 16) & 0xff)
255 #define driver_byte(result) (((result) >> 24) & 0xff)
256 #define sugestion(result) (driver_byte(result) & SUGGEST_MASK)
257
258 #define sense_class(sense) (((sense) >> 4) & 0x7)
259 #define sense_error(sense) ((sense) & 0xf)
260 #define sense_valid(sense) ((sense) & 0x80);
261
262
263
264
265
266 extern int NR_SCSI_DEVICES;
267 extern Scsi_Device * scsi_devices;
268
269
270
271
272 extern unsigned long scsi_dev_init (unsigned long, unsigned long);
273
274 struct scatterlist {
275 char * address;
276 char * alt_address;
277
278 unsigned short length;
279 };
280
281 #define ISA_DMA_THRESHOLD (0x00ffffff)
282
283 char * scsi_malloc(unsigned int);
284 int scsi_free(char *, unsigned int);
285 extern unsigned int dma_free_sectors;
286 extern unsigned int need_isa_buffer;
287
288
289
290
291
292
293 typedef struct scsi_pointer {
294 char * ptr;
295 int this_residual;
296 struct scatterlist *buffer;
297 int buffers_residual;
298
299 volatile int Status;
300 volatile int Message;
301 volatile int have_data_in;
302 volatile int sent_command;
303 volatile int phase;
304 } Scsi_Pointer;
305
306 typedef struct scsi_cmnd {
307 int host;
308 unsigned char target, lun, index;
309 struct scsi_cmnd *next, *prev;
310
311
312 unsigned char cmnd[10];
313 unsigned request_bufflen;
314
315 void * request_buffer;
316
317
318 unsigned char data_cmnd[10];
319 unsigned short use_sg;
320 unsigned short sglist_len;
321 unsigned bufflen;
322 void *buffer;
323
324 struct request request;
325
326 unsigned char sense_buffer[16];
327
328
329 int retries;
330 int allowed;
331 int timeout_per_command, timeout_total, timeout;
332
333
334
335
336
337 unsigned char internal_timeout;
338
339 unsigned flags;
340
341
342
343 int this_count;
344
345
346
347
348 void (*scsi_done)(struct scsi_cmnd *);
349
350 void (*done)(struct scsi_cmnd *);
351
352
353
354
355 Scsi_Pointer SCp;
356
357 unsigned char * host_scribble;
358
359
360
361
362
363
364
365 int result;
366 } Scsi_Cmnd;
367
368
369
370
371
372
373
374 extern int scsi_abort (Scsi_Cmnd *, int code);
375
376 extern void scsi_do_cmd (Scsi_Cmnd *, const void *cmnd ,
377 void *buffer, unsigned bufflen, void (*done)(struct scsi_cmnd *),
378 int timeout, int retries);
379
380
381 extern Scsi_Cmnd * allocate_device(struct request **, int, int);
382
383 extern Scsi_Cmnd * request_queueable(struct request *, int);
384
385 extern int scsi_reset (Scsi_Cmnd *);
386
387 extern int max_scsi_hosts;
388 extern int MAX_SD, NR_SD, MAX_ST, NR_ST, MAX_SR, NR_SR;
389 extern unsigned long sd_init(unsigned long, unsigned long);
390 extern unsigned long sd_init1(unsigned long, unsigned long);
391 extern void sd_attach(Scsi_Device *);
392
393 extern unsigned long sr_init(unsigned long, unsigned long);
394 extern unsigned long sr_init1(unsigned long, unsigned long);
395 extern void sr_attach(Scsi_Device *);
396
397 extern unsigned long st_init(unsigned long, unsigned long);
398 extern unsigned long st_init1(unsigned long, unsigned long);
399 extern void st_attach(Scsi_Device *);
400
401 #if defined(MAJOR_NR) && (MAJOR_NR != 9)
402 static void end_scsi_request(Scsi_Cmnd * SCpnt, int uptodate, int sectors)
403 {
404 struct request * req;
405 struct buffer_head * bh;
406 struct task_struct * p;
407
408 req = &SCpnt->request;
409 req->errors = 0;
410 if (!uptodate) {
411 printk(DEVICE_NAME " I/O error\n\r");
412 printk("dev %04x, sector %d\n\r",req->dev,req->sector);
413 }
414
415 do {
416 if ((bh = req->bh) != NULL) {
417 req->bh = bh->b_reqnext;
418 req->nr_sectors -= bh->b_size >> 9;
419 req->sector += bh->b_size >> 9;
420 bh->b_reqnext = NULL;
421 bh->b_uptodate = uptodate;
422 unlock_buffer(bh);
423 sectors -= bh->b_size >> 9;
424 if ((bh = req->bh) != NULL) {
425 req->current_nr_sectors = bh->b_size >> 9;
426 if (req->nr_sectors < req->current_nr_sectors) {
427 req->nr_sectors = req->current_nr_sectors;
428 printk("end_scsi_request: buffer-list destroyed\n");
429 }
430 }
431 }
432 } while(sectors && bh);
433 if (req->bh){
434 req->buffer = bh->b_data;
435 return;
436 };
437 DEVICE_OFF(req->dev);
438 if ((p = req->waiting) != NULL) {
439 req->waiting = NULL;
440 p->state = TASK_RUNNING;
441 if (p->counter > current->counter)
442 need_resched = 1;
443 }
444 req->dev = -1;
445 wake_up(&scsi_devices[SCpnt->index].device_wait);
446 return;
447 }
448 #endif
449
450 #define SCSI_SLEEP(QUEUE, CONDITION) { \
451 if (CONDITION) { \
452 struct wait_queue wait = { current, NULL}; \
453 add_wait_queue(QUEUE, &wait); \
454 sleep_repeat: \
455 current->state = TASK_UNINTERRUPTIBLE; \
456 if (CONDITION) { \
457 schedule(); \
458 goto sleep_repeat; \
459 } \
460 remove_wait_queue(QUEUE, &wait); \
461 current->state = TASK_RUNNING; \
462 }; }
463
464 #endif
465