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 READ_POSITION 0x34
65 #define SYNCRONIZE_CACHE 0x35
66 #define LOCK_UNLOCK_CACHE 0x36
67 #define READ_DEFECT_DATA 0x37
68 #define COMPARE 0x39
69 #define COPY_VERIFY 0x3a
70 #define WRITE_BUFFER 0x3b
71 #define READ_BUFFER 0x3c
72 #define READ_LONG 0x3e
73 #define CHANGE_DEFINITION 0x40
74 #define LOG_SELECT 0x4c
75 #define LOG_SENSE 0x4d
76 #define MODE_SELECT_10 0x55
77 #define MODE_SENSE_10 0x5a
78
79 extern const unsigned char scsi_command_size[8];
80 #define COMMAND_SIZE(opcode) scsi_command_size[((opcode) >> 5) & 7]
81
82
83
84
85
86 #define COMMAND_COMPLETE 0x00
87 #define EXTENDED_MESSAGE 0x01
88 #define SAVE_POINTERS 0x02
89 #define RESTORE_POINTERS 0x03
90 #define DISCONNECT 0x04
91 #define INITIATOR_ERROR 0x05
92 #define ABORT 0x06
93 #define MESSAGE_REJECT 0x07
94 #define NOP 0x08
95 #define MSG_PARITY_ERROR 0x09
96 #define LINKED_CMD_COMPLETE 0x0a
97 #define LINKED_FLG_CMD_COMPLETE 0x0b
98 #define BUS_DEVICE_RESET 0x0c
99 #define IDENTIFY_BASE 0x80
100 #define IDENTIFY(can_disconnect, lun) (IDENTIFY_BASE |\
101 ((can_disconnect) ? 0x40 : 0) |\
102 ((lun) & 0x07))
103
104
105
106
107
108
109 #define GOOD 0x00
110 #define CHECK_CONDITION 0x01
111 #define CONDITION_GOOD 0x02
112 #define BUSY 0x04
113 #define INTERMEDIATE_GOOD 0x08
114 #define INTERMEDIATE_C_GOOD 0x0a
115 #define RESERVATION_CONFLICT 0x0c
116
117 #define STATUS_MASK 0x1e
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139 #define DID_OK 0x00
140
141 #define DID_NO_CONNECT 0x01
142
143 #define DID_BUS_BUSY 0x02
144
145 #define DID_TIME_OUT 0x03
146
147 #define DID_BAD_TARGET 0x04
148
149 #define DID_ABORT 0x05
150
151
152
153 #define DID_PARITY 0x06
154
155
156
157 #define DID_ERROR 0x07
158
159
160
161 #define DID_RESET 0x08
162
163
164
165 #define DID_BAD_INTR 0x09
166
167
168
169
170 #define DRIVER_OK 0x00
171
172
173
174
175
176 #define DRIVER_BUSY 0x01
177 #define DRIVER_SOFT 0x02
178 #define DRIVER_MEDIA 0x03
179 #define DRIVER_ERROR 0x04
180
181 #define DRIVER_INVALID 0x05
182 #define DRIVER_TIMEOUT 0x06
183 #define DRIVER_HARD 0x07
184
185 #define SUGGEST_RETRY 0x10
186 #define SUGGEST_ABORT 0x20
187 #define SUGGEST_REMAP 0x30
188 #define SUGGEST_DIE 0x40
189 #define SUGGEST_SENSE 0x80
190
191 #define DRIVER_SENSE 0x08
192
193 #define DRIVER_MASK 0x0f
194 #define SUGGEST_MASK 0xf0
195
196
197
198
199
200
201 #define NO_SENSE 0x00
202 #define RECOVERED_ERROR 0x01
203 #define NOT_READY 0x02
204 #define MEDIUM_ERROR 0x03
205 #define HARDWARE_ERROR 0x04
206 #define ILLEGAL_REQUEST 0x05
207 #define UNIT_ATTENTION 0x06
208 #define DATA_PROTECT 0x07
209 #define BLANK_CHECK 0x08
210 #define COPY_ABORTED 0x0a
211 #define ABORTED_COMMAND 0x0b
212 #define VOLUME_OVERFLOW 0x0d
213 #define MISCOMPARE 0x0e
214
215
216
217
218
219
220
221 #define TYPE_DISK 0x00
222 #define TYPE_TAPE 0x01
223 #define TYPE_WORM 0x04
224 #define TYPE_ROM 0x05
225 #define TYPE_MOD 0x07
226 #define TYPE_NO_LUN 0x7f
227
228
229
230
231
232
233 #define SCSI_UNKNOWN 0
234 #define SCSI_1 1
235 #define SCSI_1_CCS 2
236 #define SCSI_2 3
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252 typedef struct scsi_device {
253 unsigned char host_no, id, lun, index;
254 int access_count;
255 struct wait_queue * device_wait;
256 char type;
257 char scsi_level;
258 unsigned writeable:1;
259 unsigned removable:1;
260 unsigned random:1;
261 unsigned changed:1;
262 unsigned busy:1;
263 unsigned lockable:1;
264 unsigned borken:1;
265
266 } Scsi_Device;
267
268
269
270
271 #define status_byte(result) (((result) >> 1) & 0xf)
272 #define msg_byte(result) (((result) >> 8) & 0xff)
273 #define host_byte(result) (((result) >> 16) & 0xff)
274 #define driver_byte(result) (((result) >> 24) & 0xff)
275 #define sugestion(result) (driver_byte(result) & SUGGEST_MASK)
276
277 #define sense_class(sense) (((sense) >> 4) & 0x7)
278 #define sense_error(sense) ((sense) & 0xf)
279 #define sense_valid(sense) ((sense) & 0x80);
280
281
282
283
284
285 extern int NR_SCSI_DEVICES;
286 extern Scsi_Device * scsi_devices;
287
288
289
290
291 extern unsigned long scsi_dev_init (unsigned long, unsigned long);
292
293 struct scatterlist {
294 char * address;
295 char * alt_address;
296
297 unsigned short length;
298 };
299
300 #define ISA_DMA_THRESHOLD (0x00ffffff)
301
302 void * scsi_malloc(unsigned int);
303 int scsi_free(void *, unsigned int);
304 extern unsigned int dma_free_sectors;
305 extern unsigned int need_isa_buffer;
306
307
308
309
310
311
312 typedef struct scsi_pointer {
313 char * ptr;
314 int this_residual;
315 struct scatterlist *buffer;
316 int buffers_residual;
317
318 volatile int Status;
319 volatile int Message;
320 volatile int have_data_in;
321 volatile int sent_command;
322 volatile int phase;
323 } Scsi_Pointer;
324
325 typedef struct scsi_cmnd {
326 int host;
327 unsigned char target, lun, index;
328 struct scsi_cmnd *next, *prev;
329
330
331 unsigned char cmnd[10];
332 unsigned request_bufflen;
333
334 void * request_buffer;
335
336
337 unsigned char data_cmnd[12];
338 unsigned short old_use_sg;
339
340 unsigned short use_sg;
341 unsigned short sglist_len;
342 unsigned bufflen;
343 void *buffer;
344
345 unsigned underflow;
346
347
348 unsigned transfersize;
349
350
351
352
353
354 struct request request;
355
356 unsigned char sense_buffer[16];
357
358
359 int retries;
360 int allowed;
361 int timeout_per_command, timeout_total, timeout;
362
363
364
365
366
367 unsigned volatile char internal_timeout;
368
369 unsigned flags;
370
371
372
373 int this_count;
374
375
376
377
378 void (*scsi_done)(struct scsi_cmnd *);
379
380 void (*done)(struct scsi_cmnd *);
381
382
383
384
385 Scsi_Pointer SCp;
386
387 unsigned char * host_scribble;
388
389
390
391
392
393
394
395 int result;
396 } Scsi_Cmnd;
397
398
399
400
401
402
403
404 extern int scsi_abort (Scsi_Cmnd *, int code);
405
406 extern void scsi_do_cmd (Scsi_Cmnd *, const void *cmnd ,
407 void *buffer, unsigned bufflen, void (*done)(struct scsi_cmnd *),
408 int timeout, int retries);
409
410
411 extern Scsi_Cmnd * allocate_device(struct request **, int, int);
412
413 extern Scsi_Cmnd * request_queueable(struct request *, int);
414
415 extern int scsi_reset (Scsi_Cmnd *);
416
417 extern int max_scsi_hosts;
418 extern int MAX_SD, NR_SD, MAX_ST, NR_ST, MAX_SR, NR_SR;
419 extern unsigned long sd_init(unsigned long, unsigned long);
420 extern unsigned long sd_init1(unsigned long, unsigned long);
421 extern void sd_attach(Scsi_Device *);
422
423 extern unsigned long sr_init(unsigned long, unsigned long);
424 extern unsigned long sr_init1(unsigned long, unsigned long);
425 extern void sr_attach(Scsi_Device *);
426
427 extern unsigned long st_init(unsigned long, unsigned long);
428 extern unsigned long st_init1(unsigned long, unsigned long);
429 extern void st_attach(Scsi_Device *);
430
431 #if defined(MAJOR_NR) && (MAJOR_NR != 9)
432 static void end_scsi_request(Scsi_Cmnd * SCpnt, int uptodate, int sectors)
433 {
434 struct request * req;
435 struct buffer_head * bh;
436 struct task_struct * p;
437
438 req = &SCpnt->request;
439 req->errors = 0;
440 if (!uptodate) {
441 printk(DEVICE_NAME " I/O error\n");
442 printk("dev %04x, sector %d\n",req->dev,req->sector);
443 }
444
445 do {
446 if ((bh = req->bh) != NULL) {
447 req->bh = bh->b_reqnext;
448 req->nr_sectors -= bh->b_size >> 9;
449 req->sector += bh->b_size >> 9;
450 bh->b_reqnext = NULL;
451 bh->b_uptodate = uptodate;
452 unlock_buffer(bh);
453 sectors -= bh->b_size >> 9;
454 if ((bh = req->bh) != NULL) {
455 req->current_nr_sectors = bh->b_size >> 9;
456 if (req->nr_sectors < req->current_nr_sectors) {
457 req->nr_sectors = req->current_nr_sectors;
458 printk("end_scsi_request: buffer-list destroyed\n");
459 }
460 }
461 }
462 } while(sectors && bh);
463 if (req->bh){
464 req->buffer = bh->b_data;
465 return;
466 };
467 DEVICE_OFF(req->dev);
468 if ((p = req->waiting) != NULL) {
469 req->waiting = NULL;
470 p->state = TASK_RUNNING;
471 if (p->counter > current->counter)
472 need_resched = 1;
473 }
474 req->dev = -1;
475 wake_up(&scsi_devices[SCpnt->index].device_wait);
476 return;
477 }
478
479
480
481
482
483
484 #define INIT_SCSI_REQUEST \
485 if (!CURRENT) {\
486 CLEAR_INTR; \
487 sti(); \
488 return; \
489 } \
490 if (MAJOR(CURRENT->dev) != MAJOR_NR) \
491 panic(DEVICE_NAME ": request list destroyed"); \
492 if (CURRENT->bh) { \
493 if (!CURRENT->bh->b_lock) \
494 panic(DEVICE_NAME ": block not locked"); \
495 }
496 #endif
497
498 #define SCSI_SLEEP(QUEUE, CONDITION) { \
499 if (CONDITION) { \
500 struct wait_queue wait = { current, NULL}; \
501 add_wait_queue(QUEUE, &wait); \
502 sleep_repeat: \
503 current->state = TASK_UNINTERRUPTIBLE; \
504 if (CONDITION) { \
505 schedule(); \
506 goto sleep_repeat; \
507 } \
508 remove_wait_queue(QUEUE, &wait); \
509 current->state = TASK_RUNNING; \
510 }; }
511
512 #endif