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