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