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