This source file includes following definitions.
- blacklisted
- scan_scsis_done
- scan_scsis
- scsi_times_out
- request_queueable
- allocate_device
- internal_cmnd
- scsi_request_sense
- scsi_do_cmd
- reset
- check_sense
- scsi_done
- scsi_abort
- scsi_reset
- scsi_main_timeout
- update_timeout
- scsi_malloc
- scsi_free
- scsi_dev_init
- print_inquiry
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include <asm/system.h>
19 #include <linux/sched.h>
20 #include <linux/timer.h>
21 #include <linux/string.h>
22
23 #include "../block/blk.h"
24 #include "scsi.h"
25 #include "hosts.h"
26 #include "constants.h"
27
28
29
30
31
32
33 const unsigned char scsi_command_size[8] = { 6, 10, 10, 12, 12, 12, 10, 10 };
34
35 #define INTERNAL_ERROR (panic ("Internal error in file %s, line %d.\n", __FILE__, __LINE__))
36
37 static void scsi_done (Scsi_Cmnd *SCpnt);
38 static int update_timeout (Scsi_Cmnd *, int);
39 static void print_inquiry(unsigned char *data);
40 static void scsi_times_out (Scsi_Cmnd * SCpnt);
41
42 static int time_start;
43 static int time_elapsed;
44
45 #define MAX_SCSI_DEVICE_CODE 10
46 const char *const scsi_device_types[MAX_SCSI_DEVICE_CODE] =
47 {
48 "Direct-Access ",
49 "Sequential-Access",
50 "Printer ",
51 "Processor ",
52 "WORM ",
53 "CD-ROM ",
54 "Scanner ",
55 "Optical Device ",
56 "Medium Changer ",
57 "Communications "
58 };
59
60
61
62
63
64
65
66
67
68 int NR_SCSI_DEVICES=0;
69
70 Scsi_Device * scsi_devices = NULL;
71
72 static unsigned char generic_sense[6] = {REQUEST_SENSE, 0,0,0, 255, 0};
73
74
75 Scsi_Cmnd * last_cmnd = NULL;
76
77
78
79
80
81
82
83 #define WAS_RESET 0x01
84 #define WAS_TIMEDOUT 0x02
85 #define WAS_SENSE 0x04
86 #define IS_RESETTING 0x08
87 #define ASKED_FOR_SENSE 0x10
88
89
90
91
92
93
94
95
96
97
98
99
100 #ifdef DEBUG
101 #define SCSI_TIMEOUT 500
102 #else
103 #define SCSI_TIMEOUT 100
104 #endif
105
106 #ifdef DEBUG
107 #define SENSE_TIMEOUT SCSI_TIMEOUT
108 #define ABORT_TIMEOUT SCSI_TIMEOUT
109 #define RESET_TIMEOUT SCSI_TIMEOUT
110 #else
111 #define SENSE_TIMEOUT 50
112 #define RESET_TIMEOUT 50
113 #define ABORT_TIMEOUT 50
114 #define MIN_RESET_DELAY 100
115 #endif
116
117
118
119
120
121 struct blist{
122 char * vendor;
123 char * model;
124 char * revision;
125 };
126
127 static struct blist blacklist[] =
128 {
129 {"CHINON","CD-ROM CDS-431","H42"},
130 {"CHINON","CD-ROM CDS-535","Q14"},
131 {"DENON","DRD-25X","V"},
132 {"IMS", "CDD521/10","2.06"},
133 {"MAXTOR","XT-3280","PR02"},
134 {"MAXTOR","XT-4380S","B3C"},
135 {"MAXTOR","MXT-1240S","I1.2"},
136 {"MAXTOR","XT-4170S","B5A"},
137 {"MAXTOR","XT-8760S","B7B"},
138 {"NEC","CD-ROM DRIVE:841","1.0"},
139 {"RODIME","RO3000S","2.33"},
140 {"SEAGATE", "ST157N", "\004|j"},
141
142 {"SEAGATE", "ST296","921"},
143 {"SONY","CD-ROM CDU-541","4.3d"},
144 {"TANDBERG","TDC 3600","U07"},
145 {"TEAC","CD-ROM","1.06"},
146
147 {"TEXEL","CD-ROM","1.06"},
148
149 {NULL, NULL, NULL}};
150
151 static int blacklisted(unsigned char * response_data){
152 int i = 0;
153 unsigned char * pnt;
154 for(i=0; 1; i++){
155 if(blacklist[i].vendor == NULL) return 0;
156 pnt = &response_data[8];
157 while(*pnt && *pnt == ' ') pnt++;
158 if(memcmp(blacklist[i].vendor, pnt,
159 strlen(blacklist[i].vendor))) continue;
160 pnt = &response_data[16];
161 while(*pnt && *pnt == ' ') pnt++;
162 if(memcmp(blacklist[i].model, pnt,
163 strlen(blacklist[i].model))) continue;
164 return 1;
165 };
166 };
167
168
169
170
171
172
173
174
175
176
177 static volatile int in_scan = 0;
178 static int the_result;
179 static void scan_scsis_done (Scsi_Cmnd * SCpnt)
180 {
181
182 #ifdef DEBUG
183 printk ("scan_scsis_done(%d, %06x)\n", SCpnt->host, SCpnt->result);
184 #endif
185 SCpnt->request.dev = 0xfffe;
186 }
187
188
189
190
191
192
193
194
195 static void scan_scsis (void)
196 {
197 int dev, lun, type;
198 unsigned char scsi_cmd [12];
199 unsigned char scsi_result [256];
200 struct Scsi_Host * shpnt;
201 Scsi_Cmnd SCmd;
202
203 ++in_scan;
204 lun = 0;
205
206 SCmd.next = NULL;
207 SCmd.prev = NULL;
208 for (shpnt = scsi_hostlist; shpnt; shpnt = shpnt->next)
209 {
210 shpnt->host_queue = &SCmd;
211
212 for (dev = 0; dev < 8; ++dev)
213 if (shpnt->this_id != dev)
214
215
216
217
218 #ifdef NO_MULTI_LUN
219 for (lun = 0; lun < 1; ++lun)
220 #else
221 for (lun = 0; lun < 8; ++lun)
222 #endif
223 {
224 scsi_devices[NR_SCSI_DEVICES].host = shpnt;
225 scsi_devices[NR_SCSI_DEVICES].id = dev;
226 scsi_devices[NR_SCSI_DEVICES].lun = lun;
227 scsi_devices[NR_SCSI_DEVICES].index = NR_SCSI_DEVICES;
228 scsi_devices[NR_SCSI_DEVICES].device_wait = NULL;
229
230
231
232
233 scsi_devices[NR_SCSI_DEVICES].borken = 1;
234
235 scsi_cmd[0] = TEST_UNIT_READY;
236 scsi_cmd[1] = lun << 5;
237 scsi_cmd[2] = scsi_cmd[3] = scsi_cmd[5] = 0;
238 scsi_cmd[4] = 0;
239
240 SCmd.host = shpnt;
241 SCmd.target = dev;
242 SCmd.lun = lun;
243
244 SCmd.request.dev = 0xffff;
245 SCmd.use_sg = 0;
246 SCmd.old_use_sg = 0;
247 SCmd.transfersize = 0;
248 SCmd.underflow = 0;
249 SCmd.index = NR_SCSI_DEVICES;
250
251 scsi_do_cmd (&SCmd,
252 (void *) scsi_cmd, (void *)
253 scsi_result, 256, scan_scsis_done,
254 SCSI_TIMEOUT + 400, 5);
255
256 while (SCmd.request.dev != 0xfffe);
257 #if defined(DEBUG) || defined(DEBUG_INIT)
258 printk("scsi: scan SCSIS id %d lun %d\n", dev, lun);
259 printk("scsi: return code %08x\n", SCmd.result);
260 #endif
261
262
263 if(SCmd.result) {
264 if ((driver_byte(SCmd.result) & DRIVER_SENSE) &&
265 ((SCmd.sense_buffer[0] & 0x70) >> 4) == 7) {
266 if (SCmd.sense_buffer[2] &0xe0)
267 continue;
268 if(((SCmd.sense_buffer[2] & 0xf) != NOT_READY) &&
269 ((SCmd.sense_buffer[2] & 0xf) != UNIT_ATTENTION))
270 continue;
271 }
272 else
273 break;
274 };
275
276 #if defined (DEBUG) || defined(DEBUG_INIT)
277 printk("scsi: performing INQUIRY\n");
278 #endif
279
280
281
282
283
284 scsi_cmd[0] = INQUIRY;
285 scsi_cmd[1] = (lun << 5) & 0xe0;
286 scsi_cmd[2] = 0;
287 scsi_cmd[3] = 0;
288 scsi_cmd[4] = 255;
289 scsi_cmd[5] = 0;
290
291 SCmd.request.dev = 0xffff;
292
293 scsi_do_cmd (&SCmd,
294 (void *) scsi_cmd, (void *)
295 scsi_result, 256, scan_scsis_done,
296 SCSI_TIMEOUT, 3);
297
298 while (SCmd.request.dev != 0xfffe);
299
300 the_result = SCmd.result;
301
302 #if defined(DEBUG) || defined(DEBUG_INIT)
303 if (!the_result)
304 printk("scsi: INQUIRY successful\n");
305 else
306 printk("scsi: INQUIRY failed with code %08x\n");
307 #endif
308
309 if(the_result) break;
310
311
312
313 if (!the_result)
314 {
315 scsi_devices[NR_SCSI_DEVICES].
316 removable = (0x80 &
317 scsi_result[1]) >> 7;
318 scsi_devices[NR_SCSI_DEVICES].lockable =
319 scsi_devices[NR_SCSI_DEVICES].removable;
320 scsi_devices[NR_SCSI_DEVICES].
321 changed = 0;
322 scsi_devices[NR_SCSI_DEVICES].
323 access_count = 0;
324 scsi_devices[NR_SCSI_DEVICES].
325 busy = 0;
326
327
328
329
330
331
332 switch (type = scsi_result[0])
333 {
334 case TYPE_TAPE :
335 case TYPE_DISK :
336 case TYPE_MOD :
337 scsi_devices[NR_SCSI_DEVICES].writeable = 1;
338 break;
339 case TYPE_WORM :
340 case TYPE_ROM :
341 scsi_devices[NR_SCSI_DEVICES].writeable = 0;
342 break;
343 default :
344 #if 0
345 #ifdef DEBUG
346 printk("scsi: unknown type %d\n", type);
347 print_inquiry(scsi_result);
348 #endif
349 #endif
350 type = -1;
351 }
352
353 scsi_devices[NR_SCSI_DEVICES].random =
354 (type == TYPE_TAPE) ? 0 : 1;
355 scsi_devices[NR_SCSI_DEVICES].type = type;
356
357 if (type != -1)
358 {
359 print_inquiry(scsi_result);
360 switch(type){
361 case TYPE_TAPE:
362 printk("Detected scsi tape st%d at scsi%d, id %d, lun %d\n", MAX_ST,
363 shpnt->host_no , dev, lun);
364 if(NR_ST != -1) ++MAX_ST;
365 break;
366 case TYPE_ROM:
367 printk("Detected scsi CD-ROM sr%d at scsi%d, id %d, lun %d\n", MAX_SR,
368 shpnt->host_no , dev, lun);
369 if(NR_SR != -1) ++MAX_SR;
370 break;
371 case TYPE_DISK:
372 case TYPE_MOD:
373 printk("Detected scsi disk sd%c at scsi%d, id %d, lun %d\n", 'a'+MAX_SD,
374 shpnt->host_no , dev, lun);
375 if(NR_SD != -1) ++MAX_SD;
376 break;
377 default:
378 break;
379 };
380
381 if(NR_SG != -1) ++MAX_SG;
382
383 scsi_devices[NR_SCSI_DEVICES].scsi_level =
384 scsi_result[2] & 0x07;
385 if (scsi_devices[NR_SCSI_DEVICES].scsi_level >= 2 ||
386 (scsi_devices[NR_SCSI_DEVICES].scsi_level == 1 &&
387 (scsi_result[3] & 0x0f) == 1))
388 scsi_devices[NR_SCSI_DEVICES].scsi_level++;
389
390
391
392
393
394 scsi_devices[NR_SCSI_DEVICES].tagged_queue = 0;
395
396 if ((scsi_devices[NR_SCSI_DEVICES].scsi_level >= SCSI_2) &&
397 (scsi_result[7] & 2)) {
398 scsi_devices[NR_SCSI_DEVICES].tagged_supported = 1;
399 scsi_devices[NR_SCSI_DEVICES].current_tag = 0;
400 }
401
402
403
404
405
406
407 scsi_devices[NR_SCSI_DEVICES].disconnect = 0;
408
409
410
411
412
413
414
415
416
417 if(strncmp("TEXEL", (char *) &scsi_result[8], 5) != 0 ||
418 strncmp("CD-ROM", (char *) &scsi_result[16], 6) != 0
419
420
421
422
423
424
425 #ifdef notyet
426 || (strncmp("1.06", (char *) &scsi_result[[, 4) != 0)
427 #endif
428 )
429 scsi_devices[NR_SCSI_DEVICES].borken = 0;
430
431
432
433
434 if(memcmp("INSITE", &scsi_result[8], 6) == 0 &&
435 (memcmp("Floptical F*8I", &scsi_result[16], 16) == 0
436 || memcmp("I325VM", &scsi_result[16], 6) == 0)) {
437 printk("Unlocked floptical drive.\n");
438 scsi_devices[NR_SCSI_DEVICES].lockable = 0;
439 scsi_cmd[0] = MODE_SENSE;
440 scsi_cmd[1] = (lun << 5) & 0xe0;
441 scsi_cmd[2] = 0x2e;
442 scsi_cmd[3] = 0;
443 scsi_cmd[4] = 0x2a;
444 scsi_cmd[5] = 0;
445
446 SCmd.request.dev = 0xffff;
447
448 scsi_do_cmd (&SCmd,
449 (void *) scsi_cmd, (void *)
450 scsi_result, 0x2a, scan_scsis_done,
451 SCSI_TIMEOUT, 3);
452
453 while (SCmd.request.dev != 0xfffe);
454 };
455
456 ++NR_SCSI_DEVICES;
457
458
459 if(blacklisted(scsi_result)) break;
460
461 if ((scsi_result[2] & 0x07) == 0)
462 break;
463
464
465 if((scsi_result[2] & 0x07) == 1 &&
466 (scsi_result[3] & 0x0f) == 0) break;
467 }
468 }
469 }
470 shpnt->host_queue = NULL;
471 }
472
473 printk("scsi : detected ");
474 if(NR_SD != -1)
475 printk("%d SCSI disk%s ", MAX_SD, (MAX_SD != 1) ? "s" : "");
476
477 if(NR_ST != -1)
478 printk("%d tape%s ", MAX_ST, (MAX_ST != 1) ? "s" : "");
479
480 if(NR_SR != -1)
481 printk("%d CD-ROM drive%s ", MAX_SR, (MAX_SR != 1) ? "s" : "");
482
483 printk("total.\n");
484 in_scan = 0;
485 }
486
487
488
489
490
491 #define NORMAL_TIMEOUT 0
492 #define IN_ABORT 1
493 #define IN_RESET 2
494
495
496
497
498
499
500 static void scsi_times_out (Scsi_Cmnd * SCpnt)
501 {
502
503 switch (SCpnt->internal_timeout & (IN_ABORT | IN_RESET))
504 {
505 case NORMAL_TIMEOUT:
506 if (!in_scan)
507 printk("SCSI host %d timed out - aborting command\n",
508 SCpnt->host->host_no);
509
510 if (!scsi_abort (SCpnt, DID_TIME_OUT))
511 return;
512 case IN_ABORT:
513 printk("SCSI host %d abort() timed out - reseting\n",
514 SCpnt->host->host_no);
515 if (!scsi_reset (SCpnt))
516 return;
517 case IN_RESET:
518 case (IN_ABORT | IN_RESET):
519 panic("Unable to reset scsi host %d\n",SCpnt->host->host_no);
520 default:
521 INTERNAL_ERROR;
522 }
523
524 }
525
526
527
528
529
530
531
532
533 Scsi_Cmnd * request_queueable (struct request * req, int index)
534 {
535 Scsi_Cmnd * SCpnt = NULL;
536 int tablesize;
537 struct buffer_head * bh, *bhp;
538
539 if ((index < 0) || (index > NR_SCSI_DEVICES))
540 panic ("Index number in allocate_device() is out of range.\n");
541
542 if (req && req->dev <= 0)
543 panic("Invalid device in allocate_device");
544
545 SCpnt = scsi_devices[index].host->host_queue;
546 while(SCpnt){
547 if(SCpnt->target == scsi_devices[index].id &&
548 SCpnt->lun == scsi_devices[index].lun)
549 if(SCpnt->request.dev < 0) break;
550 SCpnt = SCpnt->next;
551 };
552
553 if (!SCpnt) return NULL;
554
555 if (scsi_devices[index].host->hostt->can_queue
556 && scsi_devices[index].host->host_busy >= scsi_devices[index].host->hostt->can_queue) return NULL;
557
558 if (req) {
559 memcpy(&SCpnt->request, req, sizeof(struct request));
560 tablesize = scsi_devices[index].host->sg_tablesize;
561 bhp = bh = req->bh;
562 if(!tablesize) bh = NULL;
563
564
565 while(req->nr_sectors && bh){
566 bhp = bhp->b_reqnext;
567 if(!bhp || !CONTIGUOUS_BUFFERS(bh,bhp)) tablesize--;
568 req->nr_sectors -= bh->b_size >> 9;
569 req->sector += bh->b_size >> 9;
570 if(!tablesize) break;
571 bh = bhp;
572 };
573 if(req->nr_sectors && bh && bh->b_reqnext){
574 SCpnt->request.bhtail = bh;
575 req->bh = bh->b_reqnext;
576 bh->b_reqnext = NULL;
577 bh = req->bh;
578
579
580 SCpnt->request.nr_sectors -= req->nr_sectors;
581 req->current_nr_sectors = bh->b_size >> 9;
582 req->buffer = bh->b_data;
583 SCpnt->request.waiting = NULL;
584 } else {
585 req->dev = -1;
586 wake_up(&wait_for_request);
587 };
588 } else {
589 SCpnt->request.dev = 0xffff;
590 SCpnt->request.waiting = NULL;
591 };
592
593 SCpnt->use_sg = 0;
594 SCpnt->old_use_sg = 0;
595 SCpnt->transfersize = 0;
596 SCpnt->underflow = 0;
597 return SCpnt;
598 }
599
600
601
602
603
604
605
606
607
608
609 Scsi_Cmnd * allocate_device (struct request ** reqp, int index, int wait)
610 {
611 int dev = -1;
612 struct request * req = NULL;
613 int tablesize;
614 struct buffer_head * bh, *bhp;
615 struct Scsi_Host * host;
616 Scsi_Cmnd * SCpnt = NULL;
617 Scsi_Cmnd * SCwait = NULL;
618
619 if ((index < 0) || (index > NR_SCSI_DEVICES))
620 panic ("Index number in allocate_device() is out of range.\n");
621
622 if (reqp) req = *reqp;
623
624
625 if (req && (dev = req->dev) <= 0) return NULL;
626
627 host = scsi_devices[index].host;
628
629 while (1==1){
630 SCpnt = host->host_queue;
631 while(SCpnt){
632 if(SCpnt->target == scsi_devices[index].id &&
633 SCpnt->lun == scsi_devices[index].lun) {
634 SCwait = SCpnt;
635 if(SCpnt->request.dev < 0) break;
636 };
637 SCpnt = SCpnt->next;
638 };
639 cli();
640
641 if (req && ((req->dev < 0) || (req->dev != dev))) {
642 sti();
643 return NULL;
644 };
645 if (!SCpnt || SCpnt->request.dev >= 0)
646 {
647 sti();
648 if(!wait) return NULL;
649 if (!SCwait) {
650 printk("Attempt to allocate device index %d, target %d, lun %d\n",
651 index, scsi_devices[index].id ,scsi_devices[index].lun);
652 panic("No device found in allocate_device\n");
653 };
654 SCSI_SLEEP(&scsi_devices[SCwait->index].device_wait,
655 (SCwait->request.dev > 0));
656 } else {
657 if (req) {
658 memcpy(&SCpnt->request, req, sizeof(struct request));
659 tablesize = scsi_devices[index].host->sg_tablesize;
660 bhp = bh = req->bh;
661 if(!tablesize) bh = NULL;
662
663
664 while(req->nr_sectors && bh){
665 bhp = bhp->b_reqnext;
666 if(!bhp || !CONTIGUOUS_BUFFERS(bh,bhp)) tablesize--;
667 req->nr_sectors -= bh->b_size >> 9;
668 req->sector += bh->b_size >> 9;
669 if(!tablesize) break;
670 bh = bhp;
671 };
672 if(req->nr_sectors && bh && bh->b_reqnext){
673 SCpnt->request.bhtail = bh;
674 req->bh = bh->b_reqnext;
675 bh->b_reqnext = NULL;
676 bh = req->bh;
677
678 SCpnt->request.nr_sectors -= req->nr_sectors;
679 req->current_nr_sectors = bh->b_size >> 9;
680 req->buffer = bh->b_data;
681 SCpnt->request.waiting = NULL;
682 }
683 else
684 {
685 req->dev = -1;
686 *reqp = req->next;
687 wake_up(&wait_for_request);
688 };
689 } else {
690 SCpnt->request.dev = 0xffff;
691 SCpnt->request.waiting = NULL;
692 };
693 sti();
694 break;
695 };
696 };
697
698 SCpnt->use_sg = 0;
699 SCpnt->old_use_sg = 0;
700 SCpnt->transfersize = 0;
701 SCpnt->underflow = 0;
702 return SCpnt;
703 }
704
705
706
707
708
709 inline void internal_cmnd (Scsi_Cmnd * SCpnt)
710 {
711 int temp;
712 struct Scsi_Host * host;
713 #ifdef DEBUG_DELAY
714 int clock;
715 #endif
716
717 if ((unsigned long) &SCpnt < current->kernel_stack_page)
718 panic("Kernel stack overflow.");
719
720 host = SCpnt->host;
721
722
723
724
725
726 temp = host->last_reset;
727 while (jiffies < temp);
728
729 update_timeout(SCpnt, SCpnt->timeout_per_command);
730
731
732
733
734
735 #ifdef DEBUG
736 printk("internal_cmnd (host = %d, target = %d, command = %08x, buffer = %08x, \n"
737 "bufflen = %d, done = %08x)\n", SCpnt->host->host_no, SCpnt->target, SCpnt->cmnd, SCpnt->buffer, SCpnt->bufflen, SCpnt->done);
738 #endif
739
740 if (host->hostt->can_queue)
741 {
742 #ifdef DEBUG
743 printk("queuecommand : routine at %08x\n",
744 host->hostt->queuecommand);
745 #endif
746 host->hostt->queuecommand (SCpnt, scsi_done);
747 }
748 else
749 {
750
751 #ifdef DEBUG
752 printk("command() : routine at %08x\n", host->hostt->command);
753 #endif
754 temp=host->hostt->command (SCpnt);
755 SCpnt->result = temp;
756 #ifdef DEBUG_DELAY
757 clock = jiffies + 400;
758 while (jiffies < clock);
759 printk("done(host = %d, result = %04x) : routine at %08x\n", host->host_no, temp, done);
760 #endif
761 scsi_done(SCpnt);
762 }
763 #ifdef DEBUG
764 printk("leaving internal_cmnd()\n");
765 #endif
766 }
767
768 static void scsi_request_sense (Scsi_Cmnd * SCpnt)
769 {
770 cli();
771 SCpnt->flags |= WAS_SENSE | ASKED_FOR_SENSE;
772 update_timeout(SCpnt, SENSE_TIMEOUT);
773 sti();
774
775
776 memcpy ((void *) SCpnt->cmnd , (void *) generic_sense,
777 sizeof(generic_sense));
778
779 SCpnt->cmnd[1] = SCpnt->lun << 5;
780 SCpnt->cmnd[4] = sizeof(SCpnt->sense_buffer);
781
782 SCpnt->request_buffer = &SCpnt->sense_buffer;
783 SCpnt->request_bufflen = sizeof(SCpnt->sense_buffer);
784 SCpnt->use_sg = 0;
785 internal_cmnd (SCpnt);
786 SCpnt->use_sg = SCpnt->old_use_sg;
787 }
788
789
790
791
792
793
794
795
796
797
798 void scsi_do_cmd (Scsi_Cmnd * SCpnt, const void *cmnd ,
799 void *buffer, unsigned bufflen, void (*done)(Scsi_Cmnd *),
800 int timeout, int retries
801 )
802 {
803 struct Scsi_Host * host = SCpnt->host;
804
805 #ifdef DEBUG
806 {
807 int i;
808 int target = SCpnt->target;
809 printk ("scsi_do_cmd (host = %d, target = %d, buffer =%08x, "
810 "bufflen = %d, done = %08x, timeout = %d, retries = %d)\n"
811 "command : " , host->host_no, target, buffer, bufflen, done, timeout, retries);
812 for (i = 0; i < 10; ++i)
813 printk ("%02x ", ((unsigned char *) cmnd)[i]);
814 printk("\n");
815 };
816 #endif
817
818 if (!host)
819 {
820 panic ("Invalid or not present host. %d\n", host->host_no);
821 }
822
823
824
825
826
827
828
829
830
831
832 while (1==1){
833 cli();
834 if (host->hostt->can_queue
835 && host->host_busy >= host->hostt->can_queue)
836 {
837 sti();
838 SCSI_SLEEP(&host->host_wait,
839 (host->host_busy >= host->hostt->can_queue));
840 } else {
841 host->host_busy++;
842 sti();
843 break;
844 };
845 };
846
847
848
849
850
851
852
853
854 memcpy ((void *) SCpnt->data_cmnd , (void *) cmnd, 12);
855 #if 0
856 SCpnt->host = host;
857 SCpnt->target = target;
858 SCpnt->lun = (SCpnt->data_cmnd[1] >> 5);
859 #endif
860 SCpnt->bufflen = bufflen;
861 SCpnt->buffer = buffer;
862 SCpnt->flags=0;
863 SCpnt->retries=0;
864 SCpnt->allowed=retries;
865 SCpnt->done = done;
866 SCpnt->timeout_per_command = timeout;
867
868 memcpy ((void *) SCpnt->cmnd , (void *) cmnd, 12);
869
870
871 memset ((void *) SCpnt->sense_buffer, 0, sizeof SCpnt->sense_buffer);
872 SCpnt->request_buffer = buffer;
873 SCpnt->request_bufflen = bufflen;
874 SCpnt->old_use_sg = SCpnt->use_sg;
875
876
877
878 SCpnt->internal_timeout = 0;
879 internal_cmnd (SCpnt);
880
881 #ifdef DEBUG
882 printk ("Leaving scsi_do_cmd()\n");
883 #endif
884 }
885
886
887
888
889
890
891
892
893
894 static void reset (Scsi_Cmnd * SCpnt)
895 {
896 #ifdef DEBUG
897 printk("scsi: reset(%d)\n", SCpnt->host->host_no);
898 #endif
899
900 SCpnt->flags |= (WAS_RESET | IS_RESETTING);
901 scsi_reset(SCpnt);
902
903 #ifdef DEBUG
904 printk("performing request sense\n");
905 #endif
906
907 if(SCpnt->flags & NEEDS_JUMPSTART) {
908 SCpnt->flags &= ~NEEDS_JUMPSTART;
909 scsi_request_sense (SCpnt);
910 };
911 }
912
913
914
915 static int check_sense (Scsi_Cmnd * SCpnt)
916 {
917
918
919
920 if (((SCpnt->sense_buffer[0] & 0x70) >> 4) != 7) {
921 if(!(SCpnt->flags & ASKED_FOR_SENSE))
922 return SUGGEST_SENSE;
923 else
924 return SUGGEST_RETRY;
925 }
926
927 SCpnt->flags &= ~ASKED_FOR_SENSE;
928
929 #ifdef DEBUG_INIT
930 printk("scsi%d : ", SCpnt->host->host_no);
931 print_sense("", SCpnt);
932 printk("\n");
933 #endif
934 if (SCpnt->sense_buffer[2] &0xe0)
935 return SUGGEST_ABORT;
936
937 switch (SCpnt->sense_buffer[2] & 0xf)
938 {
939 case NO_SENSE:
940 return 0;
941 case RECOVERED_ERROR:
942 if (scsi_devices[SCpnt->index].type == TYPE_TAPE)
943 return SUGGEST_IS_OK;
944 else
945 return 0;
946
947 case ABORTED_COMMAND:
948 return SUGGEST_RETRY;
949 case NOT_READY:
950 case UNIT_ATTENTION:
951 return SUGGEST_ABORT;
952
953
954 case COPY_ABORTED:
955 case VOLUME_OVERFLOW:
956 case MISCOMPARE:
957
958 case MEDIUM_ERROR:
959 return SUGGEST_REMAP;
960 case BLANK_CHECK:
961 case DATA_PROTECT:
962 case HARDWARE_ERROR:
963 case ILLEGAL_REQUEST:
964 default:
965 return SUGGEST_ABORT;
966 }
967 }
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990 static void scsi_done (Scsi_Cmnd * SCpnt)
991 {
992 int status=0;
993 int exit=0;
994 int checked;
995 int oldto;
996 struct Scsi_Host * host = SCpnt->host;
997 int result = SCpnt->result;
998 oldto = update_timeout(SCpnt, 0);
999
1000 #define FINISHED 0
1001 #define MAYREDO 1
1002 #define REDO 3
1003 #define PENDING 4
1004
1005 #ifdef DEBUG
1006 printk("In scsi_done(host = %d, result = %06x)\n", host->host_no, result);
1007 #endif
1008 switch (host_byte(result))
1009 {
1010 case DID_OK:
1011 if (SCpnt->flags & IS_RESETTING)
1012 {
1013 SCpnt->flags &= ~IS_RESETTING;
1014 status = REDO;
1015 break;
1016 }
1017
1018 if (status_byte(result) && (SCpnt->flags & WAS_SENSE))
1019
1020 {
1021 SCpnt->flags &= ~WAS_SENSE;
1022 SCpnt->internal_timeout &= ~SENSE_TIMEOUT;
1023
1024 if (!(SCpnt->flags & WAS_RESET))
1025 {
1026 printk("scsi%d : target %d lun %d request sense failed, performing reset.\n",
1027 SCpnt->host->host_no, SCpnt->target, SCpnt->lun);
1028 reset(SCpnt);
1029 return;
1030 }
1031 else
1032 {
1033 exit = (DRIVER_HARD | SUGGEST_ABORT);
1034 status = FINISHED;
1035 }
1036 }
1037 else switch(msg_byte(result))
1038 {
1039 case COMMAND_COMPLETE:
1040 switch (status_byte(result))
1041 {
1042 case GOOD:
1043 if (SCpnt->flags & WAS_SENSE)
1044 {
1045 #ifdef DEBUG
1046 printk ("In scsi_done, GOOD status, COMMAND COMPLETE, parsing sense information.\n");
1047 #endif
1048
1049 SCpnt->flags &= ~WAS_SENSE;
1050 SCpnt->internal_timeout &= ~SENSE_TIMEOUT;
1051
1052 switch (checked = check_sense(SCpnt))
1053 {
1054 case SUGGEST_SENSE:
1055 case 0:
1056 #ifdef DEBUG
1057 printk("NO SENSE. status = REDO\n");
1058 #endif
1059
1060 update_timeout(SCpnt, oldto);
1061 status = REDO;
1062 break;
1063 case SUGGEST_IS_OK:
1064 break;
1065 case SUGGEST_REMAP:
1066 case SUGGEST_RETRY:
1067 #ifdef DEBUG
1068 printk("SENSE SUGGEST REMAP or SUGGEST RETRY - status = MAYREDO\n");
1069 #endif
1070
1071 status = MAYREDO;
1072 exit = DRIVER_SENSE | SUGGEST_RETRY;
1073 break;
1074 case SUGGEST_ABORT:
1075 #ifdef DEBUG
1076 printk("SENSE SUGGEST ABORT - status = FINISHED");
1077 #endif
1078
1079 status = FINISHED;
1080 exit = DRIVER_SENSE | SUGGEST_ABORT;
1081 break;
1082 default:
1083 printk ("Internal error %s %d \n", __FILE__,
1084 __LINE__);
1085 }
1086 }
1087 else
1088 {
1089 #ifdef DEBUG
1090 printk("COMMAND COMPLETE message returned, status = FINISHED. \n");
1091 #endif
1092
1093 exit = DRIVER_OK;
1094 status = FINISHED;
1095 }
1096 break;
1097
1098 case CHECK_CONDITION:
1099 switch (check_sense(SCpnt))
1100 {
1101 case 0:
1102 update_timeout(SCpnt, oldto);
1103 status = REDO;
1104 break;
1105 case SUGGEST_REMAP:
1106 case SUGGEST_RETRY:
1107 status = MAYREDO;
1108 exit = DRIVER_SENSE | SUGGEST_RETRY;
1109 break;
1110 case SUGGEST_ABORT:
1111 status = FINISHED;
1112 exit = DRIVER_SENSE | SUGGEST_ABORT;
1113 break;
1114 case SUGGEST_SENSE:
1115 scsi_request_sense (SCpnt);
1116 status = PENDING;
1117 break;
1118 }
1119 break;
1120
1121 case CONDITION_GOOD:
1122 case INTERMEDIATE_GOOD:
1123 case INTERMEDIATE_C_GOOD:
1124 break;
1125
1126 case BUSY:
1127 update_timeout(SCpnt, oldto);
1128 status = REDO;
1129 break;
1130
1131 case RESERVATION_CONFLICT:
1132 printk("scsi%d : RESERVATION CONFLICT performing reset.\n",
1133 SCpnt->host->host_no);
1134 reset(SCpnt);
1135 return;
1136 #if 0
1137 exit = DRIVER_SOFT | SUGGEST_ABORT;
1138 status = MAYREDO;
1139 break;
1140 #endif
1141 default:
1142 printk ("Internal error %s %d \n"
1143 "status byte = %d \n", __FILE__,
1144 __LINE__, status_byte(result));
1145
1146 }
1147 break;
1148 default:
1149 panic("scsi: unsupported message byte %d recieved\n", msg_byte(result));
1150 }
1151 break;
1152 case DID_TIME_OUT:
1153 #ifdef DEBUG
1154 printk("Host returned DID_TIME_OUT - ");
1155 #endif
1156
1157 if (SCpnt->flags & WAS_TIMEDOUT)
1158 {
1159 #ifdef DEBUG
1160 printk("Aborting\n");
1161 #endif
1162 exit = (DRIVER_TIMEOUT | SUGGEST_ABORT);
1163 }
1164 else
1165 {
1166 #ifdef DEBUG
1167 printk ("Retrying.\n");
1168 #endif
1169 SCpnt->flags |= WAS_TIMEDOUT;
1170 status = REDO;
1171 }
1172 break;
1173 case DID_BUS_BUSY:
1174 case DID_PARITY:
1175 status = REDO;
1176 break;
1177 case DID_NO_CONNECT:
1178 #ifdef DEBUG
1179 printk("Couldn't connect.\n");
1180 #endif
1181 exit = (DRIVER_HARD | SUGGEST_ABORT);
1182 break;
1183 case DID_ERROR:
1184 status = MAYREDO;
1185 exit = (DRIVER_HARD | SUGGEST_ABORT);
1186 break;
1187 case DID_BAD_TARGET:
1188 case DID_ABORT:
1189 exit = (DRIVER_INVALID | SUGGEST_ABORT);
1190 break;
1191 case DID_RESET:
1192 if(msg_byte(result) == GOOD &&
1193 status_byte(result) == CHECK_CONDITION) {
1194 switch (check_sense(SCpnt)) {
1195 case 0:
1196 update_timeout(SCpnt, oldto);
1197 status = REDO;
1198 break;
1199 case SUGGEST_REMAP:
1200 case SUGGEST_RETRY:
1201 status = MAYREDO;
1202 exit = DRIVER_SENSE | SUGGEST_RETRY;
1203 break;
1204 case SUGGEST_ABORT:
1205 status = FINISHED;
1206 exit = DRIVER_SENSE | SUGGEST_ABORT;
1207 break;
1208 case SUGGEST_SENSE:
1209 scsi_request_sense (SCpnt);
1210 status = PENDING;
1211 break;
1212 }
1213 } else {
1214 status=REDO;
1215 exit = SUGGEST_RETRY;
1216 }
1217 break;
1218 default :
1219 exit = (DRIVER_ERROR | SUGGEST_DIE);
1220 }
1221
1222 switch (status)
1223 {
1224 case FINISHED:
1225 case PENDING:
1226 break;
1227 case MAYREDO:
1228
1229 #ifdef DEBUG
1230 printk("In MAYREDO, allowing %d retries, have %d\n",
1231 SCpnt->allowed, SCpnt->retries);
1232 #endif
1233
1234 if ((++SCpnt->retries) < SCpnt->allowed)
1235 {
1236 if ((SCpnt->retries >= (SCpnt->allowed >> 1))
1237 && !(SCpnt->flags & WAS_RESET))
1238 {
1239 printk("scsi%d : reseting for second half of retries.\n",
1240 SCpnt->host->host_no);
1241 reset(SCpnt);
1242 break;
1243 }
1244
1245 }
1246 else
1247 {
1248 status = FINISHED;
1249 break;
1250 }
1251
1252
1253 case REDO:
1254 if (SCpnt->flags & WAS_SENSE)
1255 scsi_request_sense(SCpnt);
1256 else
1257 {
1258 memcpy ((void *) SCpnt->cmnd,
1259 (void*) SCpnt->data_cmnd,
1260 sizeof(SCpnt->data_cmnd));
1261 SCpnt->request_buffer = SCpnt->buffer;
1262 SCpnt->request_bufflen = SCpnt->bufflen;
1263 SCpnt->use_sg = SCpnt->old_use_sg;
1264 internal_cmnd (SCpnt);
1265 };
1266 break;
1267 default:
1268 INTERNAL_ERROR;
1269 }
1270
1271 if (status == FINISHED)
1272 {
1273 #ifdef DEBUG
1274 printk("Calling done function - at address %08x\n", SCpnt->done);
1275 #endif
1276 host->host_busy--;
1277 wake_up(&host->host_wait);
1278 SCpnt->result = result | ((exit & 0xff) << 24);
1279 SCpnt->use_sg = SCpnt->old_use_sg;
1280 SCpnt->done (SCpnt);
1281 }
1282
1283
1284 #undef FINISHED
1285 #undef REDO
1286 #undef MAYREDO
1287 #undef PENDING
1288 }
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306 int scsi_abort (Scsi_Cmnd * SCpnt, int why)
1307 {
1308 int temp, oldto;
1309 struct Scsi_Host * host = SCpnt->host;
1310
1311 while(1)
1312 {
1313 cli();
1314 if (SCpnt->internal_timeout & IN_ABORT)
1315 {
1316 sti();
1317 while (SCpnt->internal_timeout & IN_ABORT);
1318 }
1319 else
1320 {
1321 SCpnt->internal_timeout |= IN_ABORT;
1322 oldto = update_timeout(SCpnt, ABORT_TIMEOUT);
1323
1324
1325 sti();
1326 if (!host->host_busy || !host->hostt->abort(SCpnt, why))
1327 temp = 0;
1328 else
1329 temp = 1;
1330
1331 cli();
1332 SCpnt->internal_timeout &= ~IN_ABORT;
1333 update_timeout(SCpnt, oldto);
1334 sti();
1335 return temp;
1336 }
1337 }
1338 }
1339
1340 int scsi_reset (Scsi_Cmnd * SCpnt)
1341 {
1342 int temp, oldto;
1343 Scsi_Cmnd * SCpnt1;
1344 struct Scsi_Host * host = SCpnt->host;
1345
1346 #ifdef DEBUG
1347 printk("Danger Will Robinson! - SCSI bus for host %d is being reset.\n",host->host_no);
1348 #endif
1349 while (1) {
1350 cli();
1351 if (SCpnt->internal_timeout & IN_RESET)
1352 {
1353 sti();
1354 while (SCpnt->internal_timeout & IN_RESET);
1355 }
1356 else
1357 {
1358 SCpnt->internal_timeout |= IN_RESET;
1359 oldto = update_timeout(SCpnt, RESET_TIMEOUT);
1360
1361 if (host->host_busy)
1362 {
1363 sti();
1364 SCpnt1 = host->host_queue;
1365 while(SCpnt1) {
1366 if ((SCpnt1->request.dev > 0) &&
1367 !(SCpnt1->flags & IS_RESETTING) &&
1368 !(SCpnt1->internal_timeout & IN_ABORT))
1369 scsi_abort(SCpnt1, DID_RESET);
1370 SCpnt1 = SCpnt1->next;
1371 };
1372
1373 temp = host->hostt->reset(SCpnt);
1374 }
1375 else
1376 {
1377 host->host_busy++;
1378
1379 sti();
1380 temp = host->hostt->reset(SCpnt);
1381 host->last_reset = jiffies;
1382 host->host_busy--;
1383 }
1384
1385 cli();
1386 SCpnt->internal_timeout &= ~IN_RESET;
1387 update_timeout(SCpnt, oldto);
1388 sti();
1389 return temp;
1390 }
1391 }
1392 }
1393
1394
1395 static void scsi_main_timeout(void)
1396 {
1397
1398
1399
1400
1401 int timed_out;
1402 struct Scsi_Host * host;
1403 Scsi_Cmnd * SCpnt = NULL;
1404
1405 do {
1406 cli();
1407
1408
1409
1410
1411
1412
1413 timed_out = 0;
1414 for(host = scsi_hostlist; host; host = host->next) {
1415 SCpnt = host->host_queue;
1416 while (SCpnt){
1417 if (SCpnt->timeout > 0 && SCpnt->timeout <= time_elapsed)
1418 {
1419 sti();
1420 SCpnt->timeout = 0;
1421 scsi_times_out(SCpnt);
1422 ++timed_out;
1423 cli();
1424 }
1425 SCpnt = SCpnt->next;
1426 };
1427 };
1428 update_timeout(NULL, 0);
1429 } while (timed_out);
1430 sti();
1431 }
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441 static int update_timeout(Scsi_Cmnd * SCset, int timeout)
1442 {
1443 unsigned int least, used;
1444 unsigned int oldto;
1445 struct Scsi_Host * host;
1446 Scsi_Cmnd * SCpnt = NULL;
1447
1448 cli();
1449
1450
1451
1452
1453
1454 used = (time_start) ? (jiffies - time_start) : 0;
1455
1456
1457
1458
1459
1460
1461
1462 oldto = 0;
1463
1464 if(SCset){
1465 oldto = SCset->timeout - used;
1466 SCset->timeout = timeout + used;
1467 };
1468
1469 least = 0xffffffff;
1470
1471 for(host = scsi_hostlist; host; host = host->next) {
1472 SCpnt = host->host_queue;
1473 while (SCpnt){
1474 if (SCpnt->timeout > 0 && (SCpnt->timeout -= used) < least)
1475 least = SCpnt->timeout;
1476 SCpnt = SCpnt->next;
1477 };
1478 };
1479
1480
1481
1482
1483
1484
1485 if (least != 0xffffffff)
1486 {
1487 time_start = jiffies;
1488 timer_table[SCSI_TIMER].expires = (time_elapsed = least) + jiffies;
1489 timer_active |= 1 << SCSI_TIMER;
1490 }
1491 else
1492 {
1493 timer_table[SCSI_TIMER].expires = time_start = time_elapsed = 0;
1494 timer_active &= ~(1 << SCSI_TIMER);
1495 }
1496 sti();
1497 return oldto;
1498 }
1499
1500
1501 static unsigned short * dma_malloc_freelist = NULL;
1502 static unsigned int dma_sectors = 0;
1503 unsigned int dma_free_sectors = 0;
1504 unsigned int need_isa_buffer = 0;
1505 static unsigned char * dma_malloc_buffer = NULL;
1506
1507 void *scsi_malloc(unsigned int len)
1508 {
1509 unsigned int nbits, mask;
1510 int i, j;
1511 if((len & 0x1ff) || len > 8192)
1512 return NULL;
1513
1514 cli();
1515 nbits = len >> 9;
1516 mask = (1 << nbits) - 1;
1517
1518 for(i=0;i < (dma_sectors >> 4); i++)
1519 for(j=0; j<17-nbits; j++){
1520 if ((dma_malloc_freelist[i] & (mask << j)) == 0){
1521 dma_malloc_freelist[i] |= (mask << j);
1522 sti();
1523 dma_free_sectors -= nbits;
1524 #ifdef DEBUG
1525 printk("SMalloc: %d %x ",len, dma_malloc_buffer + (i << 13) + (j << 9));
1526 #endif
1527 return (void *) ((unsigned long) dma_malloc_buffer + (i << 13) + (j << 9));
1528 };
1529 };
1530 sti();
1531 return NULL;
1532 }
1533
1534 int scsi_free(void *obj, unsigned int len)
1535 {
1536 int offset;
1537 int page, sector, nbits, mask;
1538
1539 #ifdef DEBUG
1540 printk("Sfree %x %d\n",obj, len);
1541 #endif
1542
1543 offset = ((int) obj) - ((int) dma_malloc_buffer);
1544
1545 if (offset < 0) panic("Bad offset");
1546 page = offset >> 13;
1547 sector = offset >> 9;
1548 if(sector >= dma_sectors) panic ("Bad page");
1549
1550 sector = (offset >> 9) & 15;
1551 nbits = len >> 9;
1552 mask = (1 << nbits) - 1;
1553
1554 if ((mask << sector) > 0xffff) panic ("Bad memory alignment");
1555
1556 cli();
1557 if(dma_malloc_freelist[page] & (mask << sector) != (mask<<sector))
1558 panic("Trying to free unused memory");
1559
1560 dma_free_sectors += nbits;
1561 dma_malloc_freelist[page] &= ~(mask << sector);
1562 sti();
1563 return 0;
1564 }
1565
1566
1567
1568
1569
1570
1571
1572 unsigned long scsi_dev_init (unsigned long memory_start,unsigned long memory_end)
1573 {
1574 int i;
1575 struct Scsi_Host * host;
1576 Scsi_Cmnd * SCpnt;
1577 #ifdef FOO_ON_YOU
1578 return;
1579 #endif
1580 timer_table[SCSI_TIMER].fn = scsi_main_timeout;
1581 timer_table[SCSI_TIMER].expires = 0;
1582
1583
1584 memory_start = scsi_init(memory_start, memory_end);
1585
1586 scsi_devices = (Scsi_Device *) memory_start;
1587 scan_scsis();
1588 memory_start += NR_SCSI_DEVICES * sizeof(Scsi_Device);
1589
1590 memory_start = sd_init1(memory_start, memory_end);
1591 memory_start = st_init1(memory_start, memory_end);
1592 memory_start = sr_init1(memory_start, memory_end);
1593 memory_start = sg_init1(memory_start, memory_end);
1594
1595 last_cmnd = (Scsi_Cmnd *) memory_start;
1596
1597 SCpnt = last_cmnd;
1598
1599 for (i=0; i< NR_SCSI_DEVICES; i++) {
1600 int j;
1601 scsi_devices[i].scsi_request_fn = NULL;
1602 switch (scsi_devices[i].type)
1603 {
1604 case TYPE_TAPE :
1605 st_attach(&scsi_devices[i]);
1606 break;
1607 case TYPE_ROM:
1608 sr_attach(&scsi_devices[i]);
1609 break;
1610 case TYPE_DISK:
1611 case TYPE_MOD:
1612 sd_attach(&scsi_devices[i]);
1613 default:
1614 break;
1615 };
1616 sg_attach(&scsi_devices[i]);
1617 if(scsi_devices[i].type != -1){
1618 for(j=0;j<scsi_devices[i].host->hostt->cmd_per_lun;j++){
1619 SCpnt->host = scsi_devices[i].host;
1620 SCpnt->target = scsi_devices[i].id;
1621 SCpnt->lun = scsi_devices[i].lun;
1622 SCpnt->index = i;
1623 SCpnt->request.dev = -1;
1624 SCpnt->use_sg = 0;
1625 SCpnt->old_use_sg = 0;
1626 SCpnt->underflow = 0;
1627 SCpnt->transfersize = 0;
1628 SCpnt->host_scribble = NULL;
1629 host = scsi_devices[i].host;
1630 if(host->host_queue)
1631 host->host_queue->prev = SCpnt;
1632 SCpnt->next = host->host_queue;
1633 SCpnt->prev = NULL;
1634 host->host_queue = SCpnt;
1635 SCpnt++;
1636 };
1637 };
1638 };
1639
1640 memory_start = (int) SCpnt;
1641
1642 if (NR_SD > 0 || NR_SR > 0 || NR_ST > 0)
1643 dma_sectors = 16;
1644
1645 for (i = 0; i < NR_SCSI_DEVICES; ++i) {
1646 struct Scsi_Host * host;
1647 host = scsi_devices[i].host;
1648
1649 if(scsi_devices[i].type != TYPE_TAPE)
1650 dma_sectors += ((host->sg_tablesize *
1651 sizeof(struct scatterlist) + 511) >> 9) *
1652 host->hostt->cmd_per_lun;
1653
1654 if(host->unchecked_isa_dma &&
1655 memory_end > ISA_DMA_THRESHOLD &&
1656 scsi_devices[i].type != TYPE_TAPE) {
1657 dma_sectors += (PAGE_SIZE >> 9) * host->sg_tablesize *
1658 host->hostt->cmd_per_lun;
1659 need_isa_buffer++;
1660 };
1661 };
1662
1663 dma_sectors = (dma_sectors + 15) & 0xfff0;
1664 dma_free_sectors = dma_sectors;
1665
1666 memory_start = (memory_start + 3) & 0xfffffffc;
1667 dma_malloc_freelist = (unsigned short *) memory_start;
1668 memory_start += dma_sectors >> 3;
1669 memset(dma_malloc_freelist, 0, dma_sectors >> 3);
1670
1671 if(memory_start & 1) memory_start++;
1672
1673 dma_malloc_buffer = (unsigned char *) memory_start;
1674 memory_start += dma_sectors << 9;
1675
1676 memory_start = sd_init(memory_start, memory_end);
1677 memory_start = st_init(memory_start, memory_end);
1678 memory_start = sr_init(memory_start, memory_end);
1679 memory_start = sg_init(memory_start, memory_end);
1680
1681 return memory_start;
1682 }
1683
1684 static void print_inquiry(unsigned char *data)
1685 {
1686 int i;
1687
1688 printk(" Vendor: ");
1689 for (i = 8; i < 16; i++)
1690 {
1691 if (data[i] >= 0x20 && i < data[4] + 5)
1692 printk("%c", data[i]);
1693 else
1694 printk(" ");
1695 }
1696
1697 printk(" Model: ");
1698 for (i = 16; i < 32; i++)
1699 {
1700 if (data[i] >= 0x20 && i < data[4] + 5)
1701 printk("%c", data[i]);
1702 else
1703 printk(" ");
1704 }
1705
1706 printk(" Rev: ");
1707 for (i = 32; i < 36; i++)
1708 {
1709 if (data[i] >= 0x20 && i < data[4] + 5)
1710 printk("%c", data[i]);
1711 else
1712 printk(" ");
1713 }
1714
1715 printk("\n");
1716
1717 i = data[0] & 0x1f;
1718
1719 printk(" Type: %s ",
1720 i < MAX_SCSI_DEVICE_CODE ? scsi_device_types[i] : "Unknown " );
1721 printk(" ANSI SCSI revision: %02x", data[2] & 0x07);
1722 if ((data[2] & 0x07) == 1 && (data[3] & 0x0f) == 1)
1723 printk(" CCS\n");
1724 else
1725 printk("\n");
1726 }