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