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