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 void * scsi_malloc(unsigned int);
320 int scsi_free(void *, 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 old_use_sg;
356
357 unsigned short use_sg;
358 unsigned short sglist_len;
359 unsigned bufflen;
360 void *buffer;
361
362 unsigned underflow;
363
364
365 unsigned transfersize;
366
367
368
369
370
371 struct request request;
372
373 unsigned char sense_buffer[16];
374
375
376 int retries;
377 int allowed;
378 int timeout_per_command, timeout_total, timeout;
379
380
381
382
383
384 unsigned volatile char internal_timeout;
385
386 unsigned flags;
387
388
389
390 int this_count;
391
392
393
394
395 void (*scsi_done)(struct scsi_cmnd *);
396
397 void (*done)(struct scsi_cmnd *);
398
399
400
401
402 Scsi_Pointer SCp;
403
404 unsigned char * host_scribble;
405
406
407
408
409
410
411
412 int result;
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
432 extern int scsi_reset (Scsi_Cmnd *);
433
434 extern int max_scsi_hosts;
435 extern int MAX_SD, NR_SD, MAX_ST, NR_ST, MAX_SR, NR_SR;
436 extern unsigned long sd_init(unsigned long, unsigned long);
437 extern unsigned long sd_init1(unsigned long, unsigned long);
438 extern void sd_attach(Scsi_Device *);
439
440 extern unsigned long sr_init(unsigned long, unsigned long);
441 extern unsigned long sr_init1(unsigned long, unsigned long);
442 extern void sr_attach(Scsi_Device *);
443
444 extern unsigned long st_init(unsigned long, unsigned long);
445 extern unsigned long st_init1(unsigned long, unsigned long);
446 extern void st_attach(Scsi_Device *);
447
448 #if defined(MAJOR_NR) && (MAJOR_NR != 9)
449 static void end_scsi_request(Scsi_Cmnd * SCpnt, int uptodate, int sectors)
450 {
451 struct request * req;
452 struct buffer_head * bh;
453 struct task_struct * p;
454
455 req = &SCpnt->request;
456 req->errors = 0;
457 if (!uptodate) {
458 printk(DEVICE_NAME " I/O error\n");
459 printk("dev %04x, sector %d\n",req->dev,req->sector);
460 }
461
462 do {
463 if ((bh = req->bh) != NULL) {
464 req->bh = bh->b_reqnext;
465 req->nr_sectors -= bh->b_size >> 9;
466 req->sector += bh->b_size >> 9;
467 bh->b_reqnext = NULL;
468 bh->b_uptodate = uptodate;
469 unlock_buffer(bh);
470 sectors -= bh->b_size >> 9;
471 if ((bh = req->bh) != NULL) {
472 req->current_nr_sectors = bh->b_size >> 9;
473 if (req->nr_sectors < req->current_nr_sectors) {
474 req->nr_sectors = req->current_nr_sectors;
475 printk("end_scsi_request: buffer-list destroyed\n");
476 }
477 }
478 }
479 } while(sectors && bh);
480 if (req->bh){
481 req->buffer = bh->b_data;
482 return;
483 };
484 DEVICE_OFF(req->dev);
485 if ((p = req->waiting) != NULL) {
486 req->waiting = NULL;
487 p->state = TASK_RUNNING;
488 if (p->counter > current->counter)
489 need_resched = 1;
490 }
491 req->dev = -1;
492 wake_up(&scsi_devices[SCpnt->index].device_wait);
493 return;
494 }
495
496
497
498
499
500
501 #define INIT_SCSI_REQUEST \
502 if (!CURRENT) {\
503 CLEAR_INTR; \
504 sti(); \
505 return; \
506 } \
507 if (MAJOR(CURRENT->dev) != MAJOR_NR) \
508 panic(DEVICE_NAME ": request list destroyed"); \
509 if (CURRENT->bh) { \
510 if (!CURRENT->bh->b_lock) \
511 panic(DEVICE_NAME ": block not locked"); \
512 }
513 #endif
514
515 #define SCSI_SLEEP(QUEUE, CONDITION) { \
516 if (CONDITION) { \
517 struct wait_queue wait = { current, NULL}; \
518 add_wait_queue(QUEUE, &wait); \
519 sleep_repeat: \
520 current->state = TASK_UNINTERRUPTIBLE; \
521 if (CONDITION) { \
522 schedule(); \
523 goto sleep_repeat; \
524 } \
525 remove_wait_queue(QUEUE, &wait); \
526 current->state = TASK_RUNNING; \
527 }; }
528
529 #endif