This source file includes following definitions.
- scan_scsis_done
- scan_scsis
- scsi_times_out
- internal_cmnd
- scsi_request_sense
- scsi_do_cmd
- reset
- check_sense
- scsi_done
- scsi_abort
- scsi_reset
- scsi_main_timeout
- update_timeout
- scsi_dev_init
- print_inquiry
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #include <linux/config.h>
15
16 #ifdef CONFIG_SCSI
17 #include <asm/system.h>
18 #include <linux/sched.h>
19 #include <linux/timer.h>
20 #include <linux/string.h>
21
22 #include "scsi.h"
23 #include "hosts.h"
24
25 #ifdef CONFIG_BLK_DEV_SD
26 #include "sd.h"
27 #endif
28
29 #ifdef CONFIG_BLK_DEV_ST
30 #include "st.h"
31 #endif
32
33 #ifdef CONFIG_BLK_DEV_SR
34 #include "sr.h"
35 #endif
36
37
38
39
40
41 #define INTERNAL_ERROR (printk ("Internal error in file %s, line %d.\n", __FILE__, __LINE__), panic(""))
42
43 static void scsi_done (int host, int result);
44 static void update_timeout (void);
45 static void print_inquiry(unsigned char *data);
46
47 static int time_start;
48 static int time_elapsed;
49
50
51
52
53
54
55
56
57 int NR_SCSI_DEVICES=0;
58 Scsi_Device scsi_devices[MAX_SCSI_DEVICE];
59
60 #define SENSE_LENGTH 255
61
62
63
64
65
66
67 #define WAS_RESET 0x01
68 #define WAS_TIMEDOUT 0x02
69 #define WAS_SENSE 0x04
70 #define IS_RESETTING 0x08
71
72 static Scsi_Cmnd last_cmnd[MAX_SCSI_HOSTS];
73 static int last_reset[MAX_SCSI_HOSTS];
74
75
76
77
78
79
80
81
82
83
84
85 #ifdef DEBUG
86 #define SCSI_TIMEOUT 500
87 #else
88 #define SCSI_TIMEOUT 100
89 #endif
90
91 #ifdef DEBUG
92 #define SENSE_TIMEOUT SCSI_TIMEOUT
93 #define ABORT_TIMEOUT SCSI_TIMEOUT
94 #define RESET_TIMEOUT SCSI_TIMEOUT
95 #else
96 #define SENSE_TIMEOUT 50
97 #define RESET_TIMEOUT 50
98 #define ABORT_TIMEOUT 50
99 #define MIN_RESET_DELAY 25
100 #endif
101
102
103
104
105
106
107
108
109
110
111 volatile static int in_scan = 0;
112 static int the_result;
113 static unsigned char sense_buffer[SENSE_LENGTH];
114 static void scan_scsis_done (int host, int result)
115 {
116
117 #ifdef DEBUG
118 printk ("scan_scsis_done(%d, %06x)\n\r", host, result);
119 #endif
120 the_result = result;
121 }
122
123
124
125
126
127
128
129
130 static void scan_scsis (void)
131 {
132 int host_nr , dev, lun, type, maxed, slave;
133 static unsigned char scsi_cmd [12];
134 static unsigned char scsi_result [256];
135
136 ++in_scan;
137
138 for (slave = host_nr = 0; host_nr < MAX_SCSI_HOSTS; ++host_nr,
139 slave = 0)
140 if (scsi_hosts[host_nr].present)
141 {
142 for (dev = 0; dev < 7; ++dev)
143 if (scsi_hosts[host_nr].this_id != dev)
144 #ifdef MULTI_LUN
145 for (lun = 0; lun < 8; ++lun)
146 {
147 #else
148 {
149 lun = 0;
150 #endif
151
152
153
154
155 scsi_cmd[0] = INQUIRY;
156 scsi_cmd[1] = (lun << 5) & 0xe0;
157 scsi_cmd[2] = 0;
158 scsi_cmd[3] = 0;
159 scsi_cmd[4] = 255;
160 scsi_cmd[5] = 0;
161 the_result = -1;
162 #ifdef DEBUG
163 memset ((void *) scsi_result , 0, 255);
164 #endif
165 scsi_do_cmd (host_nr, dev, (void *) scsi_cmd, (void *)
166 scsi_result, 256, scan_scsis_done,
167 SCSI_TIMEOUT, sense_buffer, 3);
168
169
170
171
172
173 while (the_result < 0);
174
175 if (!the_result)
176 {
177 scsi_devices[NR_SCSI_DEVICES].
178 host_no = host_nr;
179 scsi_devices[NR_SCSI_DEVICES].
180 id = dev;
181 scsi_devices[NR_SCSI_DEVICES].
182 lun = lun;
183 scsi_devices[NR_SCSI_DEVICES].
184 removable = (0x80 &
185 scsi_result[1]) >> 7;
186 scsi_devices[NR_SCSI_DEVICES].
187 changed = 0;
188 scsi_devices[NR_SCSI_DEVICES].
189 access_count = 0;
190 scsi_devices[NR_SCSI_DEVICES].
191 busy = 0;
192
193
194
195
196
197
198 switch (type = scsi_result[0])
199 {
200 case TYPE_TAPE :
201 case TYPE_DISK :
202 scsi_devices[NR_SCSI_DEVICES].writeable = 1;
203 break;
204 case TYPE_WORM :
205 case TYPE_ROM :
206 scsi_devices[NR_SCSI_DEVICES].writeable = 0;
207 break;
208 default :
209 type = -1;
210 }
211
212 scsi_devices[NR_SCSI_DEVICES].random = (type == TYPE_TAPE) ? 0 : 1;
213
214 maxed = 0;
215 switch (type)
216 {
217 case -1 :
218 break;
219 case TYPE_TAPE :
220 #ifdef DEBUG
221 printk("Detected scsi tape at host %d, ID %d, lun %d \n", host_nr, dev, lun);
222 #endif
223 #ifdef CONFIG_BLK_DEV_ST
224 if (!(maxed = (NR_ST == MAX_ST)))
225 scsi_tapes[NR_ST].device = &scsi_devices[NR_SCSI_DEVICES];
226 #endif
227 break;
228 case TYPE_ROM:
229 printk("Detected scsi CD-ROM at host %d, ID %d, lun %d \n", host_nr, dev, lun);
230 #ifdef CONFIG_BLK_DEV_SR
231 if (!(maxed = (NR_SR >= MAX_SR)))
232 scsi_CDs[NR_SR].device = &scsi_devices[NR_SCSI_DEVICES];
233 #endif
234 break;
235 default :
236 #ifdef DEBUG
237 printk("Detected scsi disk at host %d, ID %d, lun %d \n", host_nr, dev, lun);
238 #endif
239 #ifdef CONFIG_BLK_DEV_SD
240 if (!(maxed = (NR_SD >= MAX_SD)))
241 rscsi_disks[NR_SD].device = &scsi_devices[NR_SCSI_DEVICES];
242 #endif
243 }
244
245 print_inquiry(scsi_result);
246
247 if (maxed)
248 {
249 printk ("Already have detected "
250 "maximum number of SCSI "
251 "%ss Unable to \n"
252 "add drive at SCSI host "
253 "%s, ID %d, LUN %d\n\r",
254 (type == TYPE_TAPE) ?
255 "tape" :
256 (type == TYPE_DISK) ?
257 "disk" : "CD-ROM",
258 scsi_hosts[host_nr].name,
259 dev, lun);
260 type = -1;
261 break;
262 }
263
264 else if (type != -1)
265 {
266 char *p;
267 char str[25];
268 memcpy((void *) str, (void *) &scsi_result[8], 8);
269 for (p = str; (p < (str + 8)) && (*p != ' '); ++p);
270 *p++ = ' ';
271 memcpy((void *) p, (void *) &scsi_result[16], 16);
272 for (; *p != ' '; ++p);
273 *p = 0;
274
275 printk("s%c%d at scsi%d, id %d, lun %d : %s\n",
276 (type == TYPE_TAPE) ? 't' : ((type == TYPE_ROM) ? 'r' : 'd'),
277 (type == TYPE_TAPE) ?
278 #ifdef CONFIG_BLK_DEV_ST
279 NR_ST
280 #else
281 -1
282 #endif
283 :
284 (type == TYPE_ROM ?
285 #ifdef CONFIG_BLK_DEV_SR
286 NR_SR
287 #else
288 -1
289 #endif
290 :
291 #ifdef CONFIG_BLK_DEV_SD
292 NR_SD
293 #else
294 -1
295 #endif
296 )
297
298 ,host_nr , dev, lun, p);
299 if (type == TYPE_TAPE)
300 #ifdef CONFIG_BLK_DEV_ST
301 ++NR_ST;
302 #else
303 ;
304 #endif
305
306 else if (type == TYPE_DISK)
307 #ifdef CONFIG_BLK_DEV_SD
308 ++NR_SD;
309 #else
310 ;
311 #endif
312 else
313 #ifdef CONFIG_BLK_DEV_SR
314 ++NR_SR;
315 #else
316 ;
317 #endif
318 }
319 ++slave;
320 ++NR_SCSI_DEVICES;
321 }
322 }
323 }
324
325 printk("scsi : detected "
326 #ifdef CONFIG_BLK_DEV_SD
327 "%d SCSI disk%s "
328 #endif
329
330 #ifdef CONFIG_BLK_DEV_ST
331 "%d tape%s "
332 #endif
333
334 #ifdef CONFIG_BLK_DEV_SR
335 "%d CD-ROM drive%s "
336 #endif
337
338 "total.\n"
339
340 #ifdef CONFIG_BLK_DEV_SD
341 , NR_SD, (NR_SD != 1) ? "s" : ""
342 #endif
343
344 #ifdef CONFIG_BLK_DEV_ST
345 , NR_ST, (NR_ST != 1) ? "s" : ""
346 #endif
347
348 #ifdef CONFIG_BLK_DEV_SR
349 , NR_SR, (NR_SR != 1) ? "s" : ""
350 #endif
351 );
352 in_scan = 0;
353 }
354
355
356
357
358
359
360 static unsigned char internal_timeout[MAX_SCSI_HOSTS];
361
362
363
364
365
366 #define NORMAL_TIMEOUT 0
367 #define IN_ABORT 1
368 #define IN_RESET 2
369
370
371
372
373
374
375 static void scsi_times_out (int host)
376 {
377
378 switch (internal_timeout[host] & (IN_ABORT | IN_RESET))
379 {
380 case NORMAL_TIMEOUT:
381 if (!in_scan)
382 printk("SCSI host %d timed out - aborting command \r\n",
383 host);
384
385 if (!scsi_abort (host, DID_TIME_OUT))
386 return;
387 case IN_ABORT:
388 printk("SCSI host %d abort() timed out - reseting \r\n",
389 host);
390 if (!scsi_reset (host))
391 return;
392 case IN_RESET:
393 case (IN_ABORT | IN_RESET):
394 printk("Unable to reset scsi host %d\r\n",host);
395 panic("");
396 default:
397 INTERNAL_ERROR;
398 }
399
400 }
401
402
403
404
405
406 static void internal_cmnd (int host, unsigned char target, const void *cmnd ,
407 void *buffer, unsigned bufflen, void (*done)(int,int))
408 {
409 int temp;
410
411 #ifdef DEBUG_DELAY
412 int clock;
413 #endif
414
415 if ((host < 0) || (host > MAX_SCSI_HOSTS))
416 panic ("Host number in internal_cmnd() is out of range.\n");
417
418
419
420
421
422
423 temp = last_reset[host];
424 while (jiffies < temp);
425
426 host_timeout[host] = last_cmnd[host].timeout_per_command;
427 update_timeout();
428
429
430
431
432
433 #ifdef DEBUG
434 printk("internal_cmnd (host = %d, target = %d, command = %08x, buffer = %08x, \n"
435 "bufflen = %d, done = %08x)\n", host, target, cmnd, buffer, bufflen, done);
436 #endif
437
438 if (scsi_hosts[host].can_queue)
439 {
440 #ifdef DEBUG
441 printk("queuecommand : routine at %08x\n",
442 scsi_hosts[host].queuecommand);
443 #endif
444 scsi_hosts[host].queuecommand (target, cmnd, buffer, bufflen,
445 done);
446 }
447 else
448 {
449
450 #ifdef DEBUG
451 printk("command() : routine at %08x\n", scsi_hosts[host].command);
452 #endif
453 temp=scsi_hosts[host].command (target, cmnd, buffer, bufflen);
454
455 #ifdef DEBUG_DELAY
456 clock = jiffies + 400;
457 while (jiffies < clock);
458 printk("done(host = %d, result = %04x) : routine at %08x\n", host, temp, done);
459 #endif
460 done(host, temp);
461 }
462 #ifdef DEBUG
463 printk("leaving internal_cmnd()\n");
464 #endif
465 }
466
467 static void scsi_request_sense (int host, unsigned char target,
468 unsigned char lun)
469 {
470 cli();
471 host_timeout[host] = SENSE_TIMEOUT;
472 update_timeout();
473 last_cmnd[host].flags |= WAS_SENSE;
474 sti();
475
476 last_cmnd[host].sense_cmnd[1] = lun << 5;
477
478 internal_cmnd (host, target, (void *) last_cmnd[host].sense_cmnd,
479 (void *) last_cmnd[host].sense_buffer, SENSE_LENGTH,
480 scsi_done);
481 }
482
483
484
485
486
487
488
489
490
491
492
493
494 void scsi_do_cmd (int host, unsigned char target, const void *cmnd ,
495 void *buffer, unsigned bufflen, void (*done)(int,int),
496 int timeout, unsigned char *sense_buffer, int retries
497 )
498 {
499 int ok = 0;
500
501 #ifdef DEBUG
502 int i;
503 printk ("scsi_do_cmd (host = %d, target = %d, buffer =%08x, "
504 "bufflen = %d, done = %08x, timeout = %d, retries = %d)\n"
505 "command : " , host, target, buffer, bufflen, done, timeout, retries);
506 for (i = 0; i < 10; ++i)
507 printk ("%02x ", ((unsigned char *) cmnd)[i]);
508 printk("\n");
509 #endif
510
511 if ((host >= MAX_SCSI_HOSTS) || !scsi_hosts[host].present)
512 {
513 printk ("Invalid or not present host number. %d\n", host);
514 panic("");
515 }
516
517
518
519
520
521
522
523
524
525
526 do {
527 cli();
528 if (host_busy[host])
529 {
530 sti();
531 #ifdef DEBUG
532 printk("Host %d is busy.\n", host);
533 #endif
534 while (host_busy[host]);
535 #ifdef DEBUG
536 printk("Host %d is no longer busy.\n", host);
537 #endif
538 }
539 else
540 {
541 host_busy[host] = 1;
542 ok = 1;
543 sti();
544 }
545 } while (!ok);
546
547
548
549
550
551
552
553
554
555
556 memcpy ((void *) last_cmnd[host].cmnd , (void *) cmnd, 10);
557 last_cmnd[host].host = host;
558 last_cmnd[host].target = target;
559 last_cmnd[host].lun = (last_cmnd[host].cmnd[1] >> 5);
560 last_cmnd[host].bufflen = bufflen;
561 last_cmnd[host].buffer = buffer;
562 last_cmnd[host].sense_buffer = sense_buffer;
563 last_cmnd[host].flags=0;
564 last_cmnd[host].retries=0;
565 last_cmnd[host].allowed=retries;
566 last_cmnd[host].done = done;
567 last_cmnd[host].timeout_per_command = timeout;
568
569
570
571 internal_timeout[host] = 0;
572 internal_cmnd (host, target, cmnd , buffer, bufflen, scsi_done);
573
574 #ifdef DEBUG
575 printk ("Leaving scsi_do_cmd()\n");
576 #endif
577 }
578
579
580
581
582
583
584
585
586 static void reset (int host)
587 {
588 #ifdef DEBUG
589 printk("reset(%d)\n", host);
590 #endif
591
592 last_cmnd[host].flags |= (WAS_RESET | IS_RESETTING);
593 scsi_reset(host);
594
595 #ifdef DEBUG
596 printk("performing request sense\n");
597 #endif
598
599 scsi_request_sense (host, last_cmnd[host].target, last_cmnd[host].lun);
600 }
601
602
603
604 static int check_sense (int host)
605 {
606 if (((last_cmnd[host].sense_buffer[0] & 0x70) >> 4) == 7)
607 switch (last_cmnd[host].sense_buffer[2] & 0xf)
608 {
609 case NO_SENSE:
610 case RECOVERED_ERROR:
611 return 0;
612
613 case ABORTED_COMMAND:
614 case NOT_READY:
615 return SUGGEST_RETRY;
616 case UNIT_ATTENTION:
617 return SUGGEST_ABORT;
618
619
620 case COPY_ABORTED:
621 case VOLUME_OVERFLOW:
622 case MISCOMPARE:
623
624 case MEDIUM_ERROR:
625 return SUGGEST_REMAP;
626 case BLANK_CHECK:
627 case DATA_PROTECT:
628 case HARDWARE_ERROR:
629 case ILLEGAL_REQUEST:
630 default:
631 return SUGGEST_ABORT;
632 }
633 else
634 return SUGGEST_RETRY;
635 }
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658 static void scsi_done (int host, int result)
659 {
660 int status=0;
661 int exit=0;
662 int checked;
663 int oldto;
664 oldto = host_timeout[host];
665 host_timeout[host] = 0;
666 update_timeout();
667
668 #define FINISHED 0
669 #define MAYREDO 1
670 #define REDO 3
671 #define PENDING 4
672
673 #ifdef DEBUG
674 printk("In scsi_done(host = %d, result = %06x)\n", host, result);
675 #endif
676 if (host > MAX_SCSI_HOSTS || host < 0)
677 {
678 host_timeout[host] = 0;
679 update_timeout();
680 panic("scsi_done() called with invalid host number.\n");
681 }
682
683 switch (host_byte(result))
684 {
685 case DID_OK:
686 if (last_cmnd[host].flags & IS_RESETTING)
687 {
688 last_cmnd[host].flags &= ~IS_RESETTING;
689 status = REDO;
690 break;
691 }
692
693 if (status_byte(result) && (last_cmnd[host].flags &
694 WAS_SENSE))
695 {
696 last_cmnd[host].flags &= ~WAS_SENSE;
697 cli();
698 internal_timeout[host] &= ~SENSE_TIMEOUT;
699 sti();
700
701 if (!(last_cmnd[host].flags & WAS_RESET))
702 {
703 reset(host);
704 return;
705 }
706 else
707 {
708 exit = (DRIVER_HARD | SUGGEST_ABORT);
709 status = FINISHED;
710 }
711 }
712 else switch(msg_byte(result))
713 {
714 case COMMAND_COMPLETE:
715 switch (status_byte(result))
716 {
717 case GOOD:
718 if (last_cmnd[host].flags & WAS_SENSE)
719 {
720 #ifdef DEBUG
721 printk ("In scsi_done, GOOD status, COMMAND COMPLETE, parsing sense information.\n");
722 #endif
723
724 last_cmnd[host].flags &= ~WAS_SENSE;
725 cli();
726 internal_timeout[host] &= ~SENSE_TIMEOUT;
727 sti();
728
729 switch (checked = check_sense(host))
730 {
731 case 0:
732 #ifdef DEBUG
733 printk("NO SENSE. status = REDO\n");
734 #endif
735
736 host_timeout[host] = oldto;
737 update_timeout();
738 status = REDO;
739 break;
740 case SUGGEST_REMAP:
741 case SUGGEST_RETRY:
742 #ifdef DEBUG
743 printk("SENSE SUGGEST REMAP or SUGGEST RETRY - status = MAYREDO\n");
744 #endif
745
746 status = MAYREDO;
747 exit = SUGGEST_RETRY;
748 break;
749 case SUGGEST_ABORT:
750 #ifdef DEBUG
751 printk("SENSE SUGGEST ABORT - status = FINISHED");
752 #endif
753
754 status = FINISHED;
755 exit = DRIVER_SENSE;
756 break;
757 default:
758 printk ("Internal error %s %s \n", __FILE__,
759 __LINE__);
760 }
761 }
762 else
763 {
764 #ifdef DEBUG
765 printk("COMMAND COMPLETE message returned, status = FINISHED. \n");
766 #endif
767
768 exit = DRIVER_OK;
769 status = FINISHED;
770 }
771 break;
772
773 case CHECK_CONDITION:
774
775 #ifdef DEBUG
776 printk("CHECK CONDITION message returned, performing request sense.\n");
777 #endif
778
779 scsi_request_sense (host, last_cmnd[host].target, last_cmnd[host].lun);
780 status = PENDING;
781 break;
782
783 case CONDITION_GOOD:
784 case INTERMEDIATE_GOOD:
785 case INTERMEDIATE_C_GOOD:
786 #ifdef DEBUG
787 printk("CONDITION GOOD, INTERMEDIATE GOOD, or INTERMEDIATE CONDITION GOOD recieved and ignored. \n");
788 #endif
789 break;
790
791 case BUSY:
792 #ifdef DEBUG
793 printk("BUSY message returned, performing REDO");
794 #endif
795 host_timeout[host] = oldto;
796 update_timeout();
797 status = REDO;
798 break;
799
800 case RESERVATION_CONFLICT:
801 reset(host);
802 return;
803 #if 0
804 exit = DRIVER_SOFT | SUGGEST_ABORT;
805 status = MAYREDO;
806 break;
807 #endif
808 default:
809 printk ("Internal error %s %s \n"
810 "status byte = %d \n", __FILE__,
811 __LINE__, status_byte(result));
812
813 }
814 break;
815 default:
816 panic ("unsupported message byte recieved.");
817 }
818 break;
819 case DID_TIME_OUT:
820 #ifdef DEBUG
821 printk("Host returned DID_TIME_OUT - ");
822 #endif
823
824 if (last_cmnd[host].flags & WAS_TIMEDOUT)
825 {
826 #ifdef DEBUG
827 printk("Aborting\n");
828 #endif
829 exit = (DRIVER_TIMEOUT | SUGGEST_ABORT);
830 }
831 else
832 {
833 #ifdef DEBUG
834 printk ("Retrying.\n");
835 #endif
836 last_cmnd[host].flags |= WAS_TIMEDOUT;
837 status = REDO;
838 }
839 break;
840 case DID_BUS_BUSY:
841 case DID_PARITY:
842 status = REDO;
843 break;
844 case DID_NO_CONNECT:
845 #ifdef DEBUG
846 printk("Couldn't connect.\n");
847 #endif
848 exit = (DRIVER_HARD | SUGGEST_ABORT);
849 break;
850 case DID_ERROR:
851 status = MAYREDO;
852 exit = (DRIVER_HARD | SUGGEST_ABORT);
853 break;
854 case DID_BAD_TARGET:
855 case DID_ABORT:
856 exit = (DRIVER_INVALID | SUGGEST_ABORT);
857 break;
858 default :
859 exit = (DRIVER_ERROR | SUGGEST_DIE);
860 }
861
862 switch (status)
863 {
864 case FINISHED:
865 case PENDING:
866 break;
867 case MAYREDO:
868
869 #ifdef DEBUG
870 printk("In MAYREDO, allowing %d retries, have %d\n\r",
871 last_cmnd[host].allowed, last_cmnd[host].retries);
872 #endif
873
874 if ((++last_cmnd[host].retries) < last_cmnd[host].allowed)
875 {
876 if ((last_cmnd[host].retries >= (last_cmnd[host].allowed >> 1))
877 && !(last_cmnd[host].flags & WAS_RESET))
878 {
879 reset(host);
880 break;
881 }
882
883 }
884 else
885 {
886 status = FINISHED;
887 break;
888 }
889
890
891 case REDO:
892 if (last_cmnd[host].flags & WAS_SENSE)
893 scsi_request_sense (host, last_cmnd[host].target,
894 last_cmnd[host].lun);
895 else
896 internal_cmnd (host, last_cmnd[host].target,
897 last_cmnd[host].cmnd,
898 last_cmnd[host].buffer,
899 last_cmnd[host].bufflen, scsi_done);
900 break;
901 default:
902 INTERNAL_ERROR;
903 }
904
905 if (status == FINISHED)
906 {
907 #ifdef DEBUG
908 printk("Calling done function - at address %08x\n", last_cmnd[host].done);
909 #endif
910 host_busy[host] = 0;
911 last_cmnd[host].done (host, (result | ((exit & 0xff) << 24)));
912 }
913
914
915 #undef FINISHED
916 #undef REDO
917 #undef MAYREDO
918 #undef PENDING
919 }
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937 int scsi_abort (int host, int why)
938 {
939 int temp, oldto;
940
941 while(1)
942 {
943 cli();
944 if (internal_timeout[host] & IN_ABORT)
945 {
946 sti();
947 while (internal_timeout[host] & IN_ABORT);
948 }
949 else
950 {
951 oldto = host_timeout[host];
952 internal_timeout[host] |= IN_ABORT;
953 host_timeout[host] = ABORT_TIMEOUT;
954 update_timeout();
955
956
957 sti();
958 if (!host_busy[host] || !scsi_hosts[host].abort(why))
959 temp = 0;
960 else
961 temp = 1;
962
963 cli();
964 internal_timeout[host] &= ~IN_ABORT;
965 host_timeout[host]=oldto;
966 update_timeout();
967 sti();
968 return temp;
969 }
970 }
971 }
972
973 int scsi_reset (int host)
974 {
975 int temp, oldto;
976
977 while (1) {
978 cli();
979 if (internal_timeout[host] & IN_RESET)
980 {
981 sti();
982 while (internal_timeout[host] & IN_RESET);
983 }
984 else
985 {
986 oldto = host_timeout[host];
987 host_timeout[host] = RESET_TIMEOUT;
988 update_timeout();
989 internal_timeout[host] |= IN_RESET;
990
991 if (host_busy[host])
992 {
993 sti();
994 if (!(last_cmnd[host].flags & IS_RESETTING) && !(internal_timeout[host] & IN_ABORT))
995 scsi_abort(host, DID_RESET);
996
997 temp = scsi_hosts[host].reset();
998 }
999 else
1000 {
1001 host_busy[host]=1;
1002
1003 sti();
1004 temp = scsi_hosts[host].reset();
1005 last_reset[host] = jiffies;
1006 host_busy[host]=0;
1007 }
1008
1009 cli();
1010 host_timeout[host] = oldto;
1011 update_timeout();
1012 internal_timeout[host] &= ~IN_RESET;
1013 sti();
1014 return temp;
1015 }
1016 }
1017 }
1018
1019
1020 static void scsi_main_timeout(void)
1021 {
1022
1023
1024
1025
1026 int i, timed_out;
1027
1028 do {
1029 cli();
1030
1031
1032
1033
1034
1035
1036 for (i = timed_out = 0; i < MAX_SCSI_HOSTS; ++i)
1037 if (host_timeout[i] != 0 && host_timeout[i] <= time_elapsed)
1038 {
1039 sti();
1040 host_timeout[i] = 0;
1041 scsi_times_out(i);
1042 ++timed_out;
1043 }
1044
1045 update_timeout();
1046 } while (timed_out);
1047 sti();
1048 }
1049
1050
1051
1052
1053
1054 static int time_start, time_elapsed;
1055
1056
1057
1058
1059
1060
1061 static void update_timeout(void)
1062 {
1063 unsigned int i, least, used;
1064
1065 cli();
1066
1067
1068
1069
1070
1071 used = (time_start) ? (jiffies - time_start) : 0;
1072
1073
1074
1075
1076
1077
1078
1079 for (i = 0, least = 0xffffffff; i < MAX_SCSI_HOSTS; ++i)
1080 if (host_timeout[i] > 0 && (host_timeout[i] -= used) < least)
1081 least = host_timeout[i];
1082
1083
1084
1085
1086
1087
1088 if (least != 0xffffffff)
1089 {
1090 time_start = jiffies;
1091 timer_table[SCSI_TIMER].expires = (time_elapsed = least) + jiffies;
1092 timer_active |= 1 << SCSI_TIMER;
1093 }
1094 else
1095 {
1096 timer_table[SCSI_TIMER].expires = time_start = time_elapsed = 0;
1097 timer_active &= ~(1 << SCSI_TIMER);
1098 }
1099 sti();
1100 }
1101
1102
1103
1104
1105
1106
1107 static unsigned char generic_sense[6] = {REQUEST_SENSE, 0,0,0, 255, 0};
1108 unsigned long scsi_dev_init (unsigned long memory_start,unsigned long memory_end)
1109 {
1110 int i;
1111 #ifdef FOO_ON_YOU
1112 return;
1113 #endif
1114 timer_table[SCSI_TIMER].fn = scsi_main_timeout;
1115 timer_table[SCSI_TIMER].expires = 0;
1116
1117 scsi_init();
1118
1119
1120
1121
1122 for (i = 0; i < MAX_SCSI_HOSTS; ++i)
1123 {
1124 memcpy ((void *) last_cmnd[i].sense_cmnd, (void *) generic_sense,
1125 6);
1126 last_reset[i] = 0;
1127 }
1128
1129 scan_scsis();
1130
1131 #ifdef CONFIG_BLK_DEV_SD
1132 memory_start = sd_init(memory_start, memory_end);
1133 #endif
1134
1135 #ifdef CONFIG_BLK_DEV_ST
1136 memory_start = st_init(memory_start, memory_end);
1137 #endif
1138
1139 #ifdef CONFIG_BLK_DEV_SR
1140 memory_start = sr_init(memory_start, memory_end);
1141 #endif
1142 return memory_start;
1143 }
1144 #endif
1145
1146 static void print_inquiry(unsigned char *data)
1147 {
1148 int i;
1149
1150 printk(" Vendor:");
1151 for (i = 8; i < 15; i++)
1152 {
1153 if (data[i] >= 20)
1154 printk("%c", data[i]);
1155 else
1156 printk(" ");
1157 }
1158
1159 printk(" Model:");
1160 for (i = 16; i < 31; i++)
1161 {
1162 if (data[i] >= 20)
1163 printk("%c", data[i]);
1164 else
1165 printk(" ");
1166 }
1167
1168 printk(" Rev:");
1169 for (i = 32; i < 35; i++)
1170 {
1171 if (data[i] >= 20)
1172 printk("%c", data[i]);
1173 else
1174 printk(" ");
1175 }
1176
1177 printk("\n");
1178
1179 i = data[0] & 0x1f;
1180
1181 printk(" Type: %s ", i == 0x00 ? "Direct-Access " :
1182 i == 0x01 ? "Sequential-Access" :
1183 i == 0x02 ? "Printer " :
1184 i == 0x03 ? "Processor " :
1185 i == 0x04 ? "WORM " :
1186 i == 0x05 ? "CD-ROM " :
1187 i == 0x06 ? "Scanner " :
1188 i == 0x07 ? "Optical Device " :
1189 i == 0x08 ? "Medium Changer " :
1190 i == 0x09 ? "Communications " :
1191 "Unknown " );
1192 printk("ANSI SCSI revision: %02x\n", data[2] & 0x07);
1193 }
1194