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