This source file includes following definitions.
- get_device_flags
- scsi_make_blocked_list
- scan_scsis_done
- scsi_luns_setup
- 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_init_malloc
- scsi_init_free
- scsi_build_commandblocks
- scsi_dev_init
- print_inquiry
- scsi_proc_info
- scsi_register_host
- scsi_unregister_host
- scsi_register_device_module
- scsi_unregister_device
- scsi_register_module
- scsi_unregister_module
- scsi_dump_status
- init_module
- cleanup_module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 #ifdef MODULE
24
25
26
27
28 #define _SCSI_SYMS_VER_
29 #include <linux/autoconf.h>
30 #include <linux/module.h>
31 #include <linux/version.h>
32 #else
33 #define MOD_INC_USE_COUNT
34 #define MOD_DEC_USE_COUNT
35 #endif
36
37 #include <asm/system.h>
38 #include <linux/sched.h>
39 #include <linux/timer.h>
40 #include <linux/string.h>
41 #include <linux/malloc.h>
42 #include <asm/irq.h>
43 #include <asm/dma.h>
44 #include <linux/ioport.h>
45 #include <linux/kernel.h>
46 #include<linux/stat.h>
47
48 #include "../block/blk.h"
49 #include "scsi.h"
50 #include "hosts.h"
51 #include "constants.h"
52
53
54 #undef USE_STATIC_SCSI_MEMORY
55
56
57
58
59
60
61
62 const unsigned char scsi_command_size[8] = { 6, 10, 10, 12, 12, 12, 10, 10 };
63
64 #define INTERNAL_ERROR (panic ("Internal error in file %s, line %d.\n", __FILE__, __LINE__))
65
66 static void scsi_done (Scsi_Cmnd *SCpnt);
67 static int update_timeout (Scsi_Cmnd *, int);
68 static void print_inquiry(unsigned char *data);
69 static void scsi_times_out (Scsi_Cmnd * SCpnt, int pid);
70
71 static int time_start;
72 static int time_elapsed;
73 static volatile struct Scsi_Host * host_active = NULL;
74 #define SCSI_BLOCK(HOST) ((HOST->block && host_active && HOST != host_active) \
75 || (HOST->can_queue && HOST->host_busy >= HOST->can_queue))
76
77 #define MAX_SCSI_DEVICE_CODE 10
78 const char *const scsi_device_types[MAX_SCSI_DEVICE_CODE] =
79 {
80 "Direct-Access ",
81 "Sequential-Access",
82 "Printer ",
83 "Processor ",
84 "WORM ",
85 "CD-ROM ",
86 "Scanner ",
87 "Optical Device ",
88 "Medium Changer ",
89 "Communications "
90 };
91
92
93
94
95
96
97
98
99 Scsi_Device * scsi_devices = NULL;
100
101
102 unsigned long scsi_pid = 0;
103
104 static unsigned char generic_sense[6] = {REQUEST_SENSE, 0,0,0, 255, 0};
105
106
107 Scsi_Cmnd * last_cmnd = NULL;
108
109
110
111
112 extern int (* dispatch_scsi_info_ptr)(int ino, char *buffer, char **start,
113 off_t offset, int length, int inout);
114 extern int dispatch_scsi_info(int ino, char *buffer, char **start,
115 off_t offset, int length, int inout);
116
117 struct proc_dir_entry proc_scsi_scsi = {
118 PROC_SCSI_SCSI, 4, "scsi",
119 S_IFREG | S_IRUGO | S_IWUSR, 2, 0, 0, 0,
120 NULL,
121 NULL, NULL,
122 NULL, NULL, NULL
123 };
124
125
126
127
128
129
130
131
132 #define WAS_RESET 0x01
133 #define WAS_TIMEDOUT 0x02
134 #define WAS_SENSE 0x04
135 #define IS_RESETTING 0x08
136 #define IS_ABORTING 0x10
137 #define ASKED_FOR_SENSE 0x20
138
139
140
141
142
143
144
145
146
147
148
149 #ifdef DEBUG_TIMEOUT
150 static void scsi_dump_status(void);
151 #endif
152
153
154 #ifdef DEBUG
155 #define SCSI_TIMEOUT (5*HZ)
156 #else
157 #define SCSI_TIMEOUT (1*HZ)
158 #endif
159
160 #ifdef DEBUG
161 #define SENSE_TIMEOUT SCSI_TIMEOUT
162 #define ABORT_TIMEOUT SCSI_TIMEOUT
163 #define RESET_TIMEOUT SCSI_TIMEOUT
164 #else
165 #define SENSE_TIMEOUT (5*HZ/10)
166 #define RESET_TIMEOUT (5*HZ/10)
167 #define ABORT_TIMEOUT (5*HZ/10)
168 #endif
169
170 #define MIN_RESET_DELAY (1*HZ)
171
172
173 #define MIN_RESET_PERIOD (10*HZ)
174
175
176
177
178
179
180 #define BLIST_NOLUN 0x01
181 #define BLIST_FORCELUN 0x02
182 #define BLIST_BORKEN 0x04
183 #define BLIST_KEY 0x08
184 #define BLIST_SINGLELUN 0x10
185
186 struct dev_info{
187 const char * vendor;
188 const char * model;
189 const char * revision;
190 unsigned flags;
191 };
192
193
194
195
196
197
198
199
200 static struct dev_info device_list[] =
201 {
202 {"CHINON","CD-ROM CDS-431","H42", BLIST_NOLUN},
203 {"CHINON","CD-ROM CDS-535","Q14", BLIST_NOLUN},
204 {"DENON","DRD-25X","V", BLIST_NOLUN},
205 {"HITACHI","DK312C","CM81", BLIST_NOLUN},
206 {"HITACHI","DK314C","CR21" , BLIST_NOLUN},
207 {"IMS", "CDD521/10","2.06", BLIST_NOLUN},
208 {"MAXTOR","XT-3280","PR02", BLIST_NOLUN},
209 {"MAXTOR","XT-4380S","B3C", BLIST_NOLUN},
210 {"MAXTOR","MXT-1240S","I1.2", BLIST_NOLUN},
211 {"MAXTOR","XT-4170S","B5A", BLIST_NOLUN},
212 {"MAXTOR","XT-8760S","B7B", BLIST_NOLUN},
213 {"NEC","CD-ROM DRIVE:841","1.0", BLIST_NOLUN},
214 {"RODIME","RO3000S","2.33", BLIST_NOLUN},
215 {"SEAGATE", "ST157N", "\004|j", BLIST_NOLUN},
216
217
218 {"SEAGATE", "ST296","921", BLIST_NOLUN},
219 {"SONY","CD-ROM CDU-541","4.3d", BLIST_NOLUN},
220 {"SONY","CD-ROM CDU-55S","1.0i", BLIST_NOLUN},
221 {"SONY","CD-ROM CDU-561","1.7x", BLIST_NOLUN},
222 {"TANDBERG","TDC 3600","U07", BLIST_NOLUN},
223 {"TEAC","CD-ROM","1.06", BLIST_NOLUN},
224
225
226 {"TEXEL","CD-ROM","1.06", BLIST_NOLUN},
227
228
229 {"QUANTUM","LPS525S","3110", BLIST_NOLUN},
230 {"QUANTUM","PD1225S","3110", BLIST_NOLUN},
231 {"MEDIAVIS","CDR-H93MV","1.31", BLIST_NOLUN},
232 {"SANKYO", "CP525","6.64", BLIST_NOLUN},
233 {"HP", "C1750A", "3226", BLIST_NOLUN},
234 {"HP", "C1790A", "", BLIST_NOLUN},
235 {"HP", "C2500A", "", BLIST_NOLUN},
236
237
238
239
240 {"SONY","CD-ROM CDU-8001","*", BLIST_BORKEN},
241 {"TEXEL","CD-ROM","1.06", BLIST_BORKEN},
242 {"INSITE","Floptical F*8I","*", BLIST_KEY},
243 {"INSITE","I325VM","*", BLIST_KEY},
244 {"PIONEER","CD-ROMDRM-602X","*", BLIST_FORCELUN | BLIST_SINGLELUN},
245 {"PIONEER","CD-ROMDRM-604X","*", BLIST_FORCELUN | BLIST_SINGLELUN},
246
247
248
249 {NULL, NULL, NULL}
250 };
251
252 static int get_device_flags(unsigned char * response_data){
253 int i = 0;
254 unsigned char * pnt;
255 for(i=0; 1; i++){
256 if(device_list[i].vendor == NULL) return 0;
257 pnt = &response_data[8];
258 while(*pnt && *pnt == ' ') pnt++;
259 if(memcmp(device_list[i].vendor, pnt,
260 strlen(device_list[i].vendor))) continue;
261 pnt = &response_data[16];
262 while(*pnt && *pnt == ' ') pnt++;
263 if(memcmp(device_list[i].model, pnt,
264 strlen(device_list[i].model))) continue;
265 return device_list[i].flags;
266 }
267 return 0;
268 }
269
270
271
272
273
274
275
276
277
278
279 volatile int in_scan_scsis = 0;
280 static int the_result;
281
282 void scsi_make_blocked_list(void) {
283 int block_count = 0, index;
284 unsigned int flags;
285 struct Scsi_Host * sh[128], * shpnt;
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305 save_flags(flags);
306 cli();
307 host_active = NULL;
308
309 for(shpnt=scsi_hostlist; shpnt; shpnt = shpnt->next) {
310
311 #if 0
312
313
314
315
316
317 if (shpnt->unchecked_isa_dma) shpnt->wish_block = 1;
318 #endif
319
320 if (shpnt->wish_block) sh[block_count++] = shpnt;
321 }
322
323 if (block_count == 1) sh[0]->block = NULL;
324
325 else if (block_count > 1) {
326
327 for(index = 0; index < block_count - 1; index++) {
328 sh[index]->block = sh[index + 1];
329 printk("scsi%d : added to blocked host list.\n",
330 sh[index]->host_no);
331 }
332
333 sh[block_count - 1]->block = sh[0];
334 printk("scsi%d : added to blocked host list.\n",
335 sh[index]->host_no);
336 }
337
338 restore_flags(flags);
339 }
340
341 static void scan_scsis_done (Scsi_Cmnd * SCpnt)
342 {
343
344 #ifdef DEBUG
345 printk ("scan_scsis_done(%p, %06x)\n", SCpnt->host, SCpnt->result);
346 #endif
347 SCpnt->request.rq_status = RQ_SCSI_DONE;
348
349 if (SCpnt->request.sem != NULL)
350 up(SCpnt->request.sem);
351 }
352
353 #ifdef CONFIG_SCSI_MULTI_LUN
354 static int max_scsi_luns = 8;
355 #else
356 static int max_scsi_luns = 1;
357 #endif
358
359 void scsi_luns_setup(char *str, int *ints) {
360 if (ints[0] != 1)
361 printk("scsi_luns_setup : usage max_scsi_luns=n (n should be between 1 and 8)\n");
362 else
363 max_scsi_luns = ints[1];
364 }
365
366
367
368
369
370
371
372
373 static
374 void scan_scsis (struct Scsi_Host * shpnt, unchar hardcoded,
375 unchar hchannel, unchar hid, unchar hlun)
376 {
377 int dev, lun, type, channel;
378 unsigned char scsi_cmd [12];
379 unsigned char scsi_result0 [256];
380 unsigned char * scsi_result;
381 Scsi_Device * SDpnt, *SDtail;
382 struct Scsi_Device_Template * sdtpnt;
383 int bflags;
384 int max_dev_lun = 0;
385 Scsi_Cmnd *SCpnt;
386
387 ++in_scan_scsis;
388 lun = 0;
389 type = -1;
390 SCpnt = (Scsi_Cmnd *) scsi_init_malloc(sizeof(Scsi_Cmnd), GFP_ATOMIC|GFP_DMA);
391 SDpnt = (Scsi_Device *) scsi_init_malloc(sizeof (Scsi_Device), GFP_ATOMIC);
392 SDtail = scsi_devices;
393
394 if(scsi_devices) while(SDtail->next) SDtail = SDtail->next;
395
396
397 scsi_result = ((current->pid == 0 || !shpnt->unchecked_isa_dma)
398 ? &scsi_result0[0] : scsi_malloc(512));
399
400 if(scsi_result == NULL) {
401 printk("Unable to obtain scsi_result buffer\n");
402 goto leave;
403 }
404
405 shpnt->host_queue = SCpnt;
406
407 if(hardcoded == 1) {
408 channel = hchannel;
409 dev = hid;
410 lun = hlun;
411 goto crude;
412 }
413
414 for (channel = 0; channel <= shpnt->max_channel; channel++)
415 {
416 for (dev = 0; dev < shpnt->max_id; ++dev) {
417 if (shpnt->this_id != dev) {
418
419
420
421
422
423
424
425 max_dev_lun = (max_scsi_luns < shpnt->max_lun ?
426 max_scsi_luns : shpnt->max_lun);
427
428 for (lun = 0; lun < max_dev_lun; ++lun)
429 {
430 crude:
431 memset(SDpnt, 0, sizeof(Scsi_Device));
432 SDpnt->host = shpnt;
433 SDpnt->id = dev;
434 SDpnt->lun = lun;
435 SDpnt->channel = channel;
436
437
438 SDpnt->type = -1;
439
440
441
442
443 SDpnt->borken = 1;
444 SDpnt->was_reset = 0;
445 SDpnt->expecting_cc_ua = 0;
446
447 scsi_cmd[0] = TEST_UNIT_READY;
448 scsi_cmd[1] = lun << 5;
449 scsi_cmd[2] = scsi_cmd[3] = scsi_cmd[4] = scsi_cmd[5] = 0;
450
451 memset(SCpnt, 0, sizeof(Scsi_Cmnd));
452 SCpnt->host = SDpnt->host;
453 SCpnt->device = SDpnt;
454 SCpnt->target = SDpnt->id;
455 SCpnt->lun = SDpnt->lun;
456 SCpnt->channel = SDpnt->channel;
457
458
459 SCpnt->request.sem = NULL;
460 SCpnt->request.rq_status = RQ_SCSI_BUSY;
461
462 scsi_do_cmd (SCpnt, (void *) scsi_cmd,
463 (void *) scsi_result,
464 256, scan_scsis_done, SCSI_TIMEOUT + 4 * HZ, 5);
465
466
467
468
469
470
471 if (current->pid == 0)
472 while (SCpnt->request.rq_status != RQ_SCSI_DONE)
473 barrier();
474 else if (SCpnt->request.rq_status != RQ_SCSI_DONE) {
475 struct semaphore sem = MUTEX_LOCKED;
476
477 SCpnt->request.sem = &sem;
478 down(&sem);
479
480
481 while (SCpnt->request.rq_status != RQ_SCSI_DONE)
482 schedule();
483 }
484
485 #if defined(DEBUG) || defined(DEBUG_INIT)
486 printk("scsi: scan SCSIS id %d lun %d\n", dev, lun);
487 printk("scsi: return code %08x\n", SCpnt->result);
488 #endif
489
490 if(SCpnt->result) {
491 if (((driver_byte(SCpnt->result) & DRIVER_SENSE) ||
492 (status_byte(SCpnt->result) & CHECK_CONDITION)) &&
493 ((SCpnt->sense_buffer[0] & 0x70) >> 4) == 7) {
494 if (SCpnt->sense_buffer[2] &0xe0)
495 continue;
496 if(((SCpnt->sense_buffer[2] & 0xf) != NOT_READY) &&
497 ((SCpnt->sense_buffer[2] & 0xf) != UNIT_ATTENTION))
498 continue;
499 }
500 else
501 break;
502 }
503
504 #if defined (DEBUG) || defined(DEBUG_INIT)
505 printk("scsi: performing INQUIRY\n");
506 #endif
507
508
509
510
511 scsi_cmd[0] = INQUIRY;
512 scsi_cmd[1] = (lun << 5) & 0xe0;
513 scsi_cmd[2] = 0;
514 scsi_cmd[3] = 0;
515 scsi_cmd[4] = 255;
516 scsi_cmd[5] = 0;
517
518 SCpnt->request.rq_status = RQ_SCSI_BUSY;
519 SCpnt->cmd_len = 0;
520
521 scsi_do_cmd (SCpnt, (void *) scsi_cmd,
522 (void *) scsi_result,
523 256, scan_scsis_done, SCSI_TIMEOUT, 3);
524
525 if (current->pid == 0)
526 while (SCpnt->request.rq_status != RQ_SCSI_DONE)
527 barrier();
528 else if (SCpnt->request.rq_status != RQ_SCSI_DONE) {
529 struct semaphore sem = MUTEX_LOCKED;
530
531 SCpnt->request.sem = &sem;
532 down(&sem);
533
534
535 while (SCpnt->request.rq_status != RQ_SCSI_DONE)
536 schedule();
537 }
538
539 the_result = SCpnt->result;
540
541 #if defined(DEBUG) || defined(DEBUG_INIT)
542 if (!the_result)
543 printk("scsi: INQUIRY successful\n");
544 else
545 printk("scsi: INQUIRY failed with code %08x\n", the_result);
546 #endif
547
548 if(the_result) break;
549
550
551
552 if (!the_result)
553 {
554
555
556
557 if (!strncmp(scsi_result+8,"TOSHIBA",7) &&
558 !strncmp(scsi_result+16,"CD-ROM",6) &&
559 scsi_result[0] == TYPE_DISK) {
560 scsi_result[0] = TYPE_ROM;
561 scsi_result[1] |= 0x80;
562 }
563
564 if (!strncmp(scsi_result+8,"NEC",3)) {
565 if (!strncmp(scsi_result+16,"CD-ROM DRIVE:84 ",16) ||
566 !strncmp(scsi_result+16,"CD-ROM DRIVE:25",15))
567 SDpnt->manufacturer = SCSI_MAN_NEC_OLDCDR;
568 else
569 SDpnt->manufacturer = SCSI_MAN_NEC;
570 } else if (!strncmp(scsi_result+8,"TOSHIBA",7))
571 SDpnt->manufacturer = SCSI_MAN_TOSHIBA;
572 else if (!strncmp(scsi_result+8,"SONY",4))
573 SDpnt->manufacturer = SCSI_MAN_SONY;
574 else if (!strncmp(scsi_result+8, "PIONEER", 7))
575 SDpnt->manufacturer = SCSI_MAN_PIONEER;
576 else
577 SDpnt->manufacturer = SCSI_MAN_UNKNOWN;
578
579 memcpy(SDpnt->vendor, scsi_result+8, 8);
580 memcpy(SDpnt->model, scsi_result+16, 16);
581 memcpy(SDpnt->rev, scsi_result+32, 4);
582
583 SDpnt->removable = (0x80 & scsi_result[1]) >> 7;
584 SDpnt->lockable = SDpnt->removable;
585 SDpnt->changed = 0;
586 SDpnt->access_count = 0;
587 SDpnt->busy = 0;
588 SDpnt->has_cmdblocks = 0;
589
590
591
592
593
594
595 switch (type = (scsi_result[0] & 0x1f))
596 {
597 case TYPE_TAPE :
598 case TYPE_DISK :
599 case TYPE_MOD :
600 case TYPE_PROCESSOR :
601 case TYPE_SCANNER :
602 SDpnt->writeable = 1;
603 break;
604 case TYPE_WORM :
605 case TYPE_ROM :
606 SDpnt->writeable = 0;
607 break;
608 default :
609 #if 0
610 #ifdef DEBUG
611 printk("scsi: unknown type %d\n", type);
612 print_inquiry(scsi_result);
613 #endif
614 type = -1;
615 #endif
616 }
617
618 SDpnt->single_lun = 0;
619 SDpnt->soft_reset =
620 (scsi_result[7] & 1) && ((scsi_result[3] &7) == 2);
621 SDpnt->random = (type == TYPE_TAPE) ? 0 : 1;
622 SDpnt->type = (type & 0x1f);
623
624 if (type != -1)
625 {
626 print_inquiry(scsi_result);
627
628 for(sdtpnt = scsi_devicelist; sdtpnt;
629 sdtpnt = sdtpnt->next)
630 if(sdtpnt->detect) SDpnt->attached +=
631 (*sdtpnt->detect)(SDpnt);
632
633 SDpnt->scsi_level = scsi_result[2] & 0x07;
634 if (SDpnt->scsi_level >= 2 ||
635 (SDpnt->scsi_level == 1 &&
636 (scsi_result[3] & 0x0f) == 1))
637 SDpnt->scsi_level++;
638
639
640
641
642
643
644 SDpnt->tagged_queue = 0;
645
646 if ((SDpnt->scsi_level >= SCSI_2) &&
647 (scsi_result[7] & 2)) {
648 SDpnt->tagged_supported = 1;
649 SDpnt->current_tag = 0;
650 }
651
652
653
654
655
656
657 SDpnt->disconnect = 0;
658
659
660
661
662 bflags = get_device_flags(scsi_result);
663
664
665
666
667
668
669
670
671
672
673 if( (bflags & BLIST_BORKEN) == 0 )
674 {
675 SDpnt->borken = 0;
676 }
677
678
679
680
681
682 if( (bflags & BLIST_KEY) != 0 ) {
683 printk("Unlocked floptical drive.\n");
684 SDpnt->lockable = 0;
685 scsi_cmd[0] = MODE_SENSE;
686 scsi_cmd[1] = (lun << 5) & 0xe0;
687 scsi_cmd[2] = 0x2e;
688 scsi_cmd[3] = 0;
689 scsi_cmd[4] = 0x2a;
690 scsi_cmd[5] = 0;
691
692 SCpnt->request.rq_status = RQ_SCSI_BUSY;
693 SCpnt->cmd_len = 0;
694
695 scsi_do_cmd (SCpnt, (void *) scsi_cmd,
696 (void *) scsi_result, 0x2a,
697 scan_scsis_done, SCSI_TIMEOUT, 3);
698
699 if (current->pid == 0)
700 while (SCpnt->request.rq_status != RQ_SCSI_DONE);
701 else if (SCpnt->request.rq_status != RQ_SCSI_DONE) {
702 struct semaphore sem = MUTEX_LOCKED;
703
704 SCpnt->request.sem = &sem;
705 down(&sem);
706
707
708 while (SCpnt->request.rq_status != RQ_SCSI_DONE)
709 schedule();
710 }
711 }
712
713 if(SDtail)
714 SDtail->next = SDpnt;
715 else
716 scsi_devices = SDpnt;
717 SDtail = SDpnt;
718
719 SDpnt = (Scsi_Device *) scsi_init_malloc(sizeof (Scsi_Device), GFP_ATOMIC);
720
721
722
723 if(bflags & BLIST_NOLUN) break;
724
725
726
727
728
729
730 if(bflags & BLIST_SINGLELUN)
731 {
732 SDpnt->single_lun = 1;
733 }
734
735
736
737
738
739
740 if(bflags & BLIST_FORCELUN)
741 {
742
743
744
745
746 max_dev_lun = 8;
747 }
748
749
750
751 if ((scsi_result[2] & 0x07) == 0)
752 break;
753
754
755
756 if((scsi_result[2] & 0x07) == 1 &&
757 (scsi_result[3] & 0x0f) == 0) break;
758 }
759 }
760
761
762
763
764
765 if(hardcoded == 1)
766 goto leave;
767 }
768 }
769 }
770 }
771
772 leave:
773 shpnt->host_queue = NULL;
774
775
776 if(SDpnt != NULL)
777 scsi_init_free((char *) SDpnt, sizeof(Scsi_Device));
778
779 if(SCpnt != NULL)
780 scsi_init_free((char *) SCpnt, sizeof(Scsi_Cmnd));
781
782
783 if (scsi_result != &scsi_result0[0] && scsi_result != NULL)
784 scsi_free(scsi_result, 512);
785
786 in_scan_scsis = 0;
787 }
788
789
790
791
792
793 #define NORMAL_TIMEOUT 0
794 #define IN_ABORT 1
795 #define IN_RESET 2
796
797
798
799
800
801
802
803 static void scsi_times_out (Scsi_Cmnd * SCpnt, int pid)
804 {
805
806 switch (SCpnt->internal_timeout & (IN_ABORT | IN_RESET))
807 {
808 case NORMAL_TIMEOUT:
809 if (!in_scan_scsis) {
810 #ifdef DEBUG_TIMEOUT
811 scsi_dump_status();
812 #endif
813 }
814
815 if (!scsi_abort (SCpnt, DID_TIME_OUT, pid))
816 return;
817 case IN_ABORT:
818 printk("SCSI host %d abort() timed out - resetting\n",
819 SCpnt->host->host_no);
820 if (!scsi_reset (SCpnt, FALSE))
821 return;
822 case IN_RESET:
823 case (IN_ABORT | IN_RESET):
824
825
826
827
828 printk("Unable to reset scsi host %d - ", SCpnt->host->host_no);
829 printk("probably a SCSI bus hang.\n");
830 scsi_reset (SCpnt, TRUE);
831 return;
832
833 default:
834 INTERNAL_ERROR;
835 }
836
837 }
838
839
840
841
842
843
844
845
846
847 Scsi_Cmnd * request_queueable (struct request * req, Scsi_Device * device)
848 {
849 Scsi_Cmnd * SCpnt = NULL;
850 int tablesize;
851 Scsi_Cmnd * found = NULL;
852 struct buffer_head * bh, *bhp;
853
854 if (!device)
855 panic ("No device passed to request_queueable().\n");
856
857 if (req && req->rq_status == RQ_INACTIVE)
858 panic("Inactive in request_queueable");
859
860 SCpnt = device->host->host_queue;
861
862
863
864
865
866
867
868 SCpnt = device->host->host_queue;
869 if (!device->single_lun) {
870 while(SCpnt){
871 if(SCpnt->target == device->id &&
872 SCpnt->lun == device->lun) {
873 if(SCpnt->request.rq_status == RQ_INACTIVE) break;
874 }
875 SCpnt = SCpnt->next;
876 }
877 } else {
878 while(SCpnt){
879 if(SCpnt->target == device->id) {
880 if (SCpnt->lun == device->lun) {
881 if(found == NULL
882 && SCpnt->request.rq_status == RQ_INACTIVE)
883 {
884 found=SCpnt;
885 }
886 }
887 if(SCpnt->request.rq_status != RQ_INACTIVE) {
888
889
890
891
892
893 return NULL;
894 }
895 }
896 SCpnt = SCpnt->next;
897 }
898 SCpnt = found;
899 }
900
901 if (!SCpnt) return NULL;
902
903 if (SCSI_BLOCK(device->host)) return NULL;
904
905 if (req) {
906 memcpy(&SCpnt->request, req, sizeof(struct request));
907 tablesize = device->host->sg_tablesize;
908 bhp = bh = req->bh;
909 if(!tablesize) bh = NULL;
910
911
912
913
914 while(req->nr_sectors && bh){
915 bhp = bhp->b_reqnext;
916 if(!bhp || !CONTIGUOUS_BUFFERS(bh,bhp)) tablesize--;
917 req->nr_sectors -= bh->b_size >> 9;
918 req->sector += bh->b_size >> 9;
919 if(!tablesize) break;
920 bh = bhp;
921 }
922 if(req->nr_sectors && bh && bh->b_reqnext){
923 SCpnt->request.bhtail = bh;
924 req->bh = bh->b_reqnext;
925 bh->b_reqnext = NULL;
926 bh = req->bh;
927
928
929 SCpnt->request.nr_sectors -= req->nr_sectors;
930 req->current_nr_sectors = bh->b_size >> 9;
931 req->buffer = bh->b_data;
932 SCpnt->request.sem = NULL;
933 } else {
934 req->rq_status = RQ_INACTIVE;
935 wake_up(&wait_for_request);
936 }
937 } else {
938 SCpnt->request.rq_status = RQ_SCSI_BUSY;
939 SCpnt->request.sem = NULL;
940
941 }
942
943 SCpnt->use_sg = 0;
944 SCpnt->old_use_sg = 0;
945 SCpnt->transfersize = 0;
946 SCpnt->underflow = 0;
947 SCpnt->cmd_len = 0;
948
949
950
951
952 SCpnt->channel = device->channel;
953 SCpnt->lun = device->lun;
954 SCpnt->target = device->id;
955
956 return SCpnt;
957 }
958
959
960
961
962
963
964
965
966
967
968
969 Scsi_Cmnd * allocate_device (struct request ** reqp, Scsi_Device * device,
970 int wait)
971 {
972 kdev_t dev;
973 struct request * req = NULL;
974 int tablesize;
975 unsigned int flags;
976 struct buffer_head * bh, *bhp;
977 struct Scsi_Host * host;
978 Scsi_Cmnd * SCpnt = NULL;
979 Scsi_Cmnd * SCwait = NULL;
980 Scsi_Cmnd * found = NULL;
981
982 if (!device)
983 panic ("No device passed to allocate_device().\n");
984
985 if (reqp) req = *reqp;
986
987
988 if (req) {
989 if(req->rq_status == RQ_INACTIVE) return NULL;
990 dev = req->rq_dev;
991 } else
992 dev = 0;
993
994 host = device->host;
995
996 if (intr_count && SCSI_BLOCK(host)) return NULL;
997
998 while (1==1){
999 SCpnt = device->host->host_queue;
1000 if (!device->single_lun) {
1001 while(SCpnt){
1002 if(SCpnt->target == device->id &&
1003 SCpnt->lun == device->lun) {
1004 SCwait = SCpnt;
1005 if(SCpnt->request.rq_status == RQ_INACTIVE) break;
1006 }
1007 SCpnt = SCpnt->next;
1008 }
1009 } else {
1010 while(SCpnt){
1011 if(SCpnt->target == device->id) {
1012 if (SCpnt->lun == device->lun) {
1013 SCwait = SCpnt;
1014 if(found == NULL
1015 && SCpnt->request.rq_status == RQ_INACTIVE)
1016 {
1017 found=SCpnt;
1018 }
1019 }
1020 if(SCpnt->request.rq_status != RQ_INACTIVE) {
1021
1022
1023
1024
1025
1026 found = NULL;
1027 break;
1028 }
1029 }
1030 SCpnt = SCpnt->next;
1031 }
1032 SCpnt = found;
1033 }
1034
1035 save_flags(flags);
1036 cli();
1037
1038
1039 if (req && (req->rq_status == RQ_INACTIVE || req->rq_dev != dev)) {
1040 restore_flags(flags);
1041 return NULL;
1042 }
1043 if (!SCpnt || SCpnt->request.rq_status != RQ_INACTIVE)
1044 {
1045 restore_flags(flags);
1046 if(!wait) return NULL;
1047 if (!SCwait) {
1048 printk("Attempt to allocate device channel %d, target %d, "
1049 "lun %d\n", device->channel, device->id, device->lun);
1050 panic("No device found in allocate_device\n");
1051 }
1052 SCSI_SLEEP(&device->device_wait,
1053 (SCwait->request.rq_status != RQ_INACTIVE));
1054 } else {
1055 if (req) {
1056 memcpy(&SCpnt->request, req, sizeof(struct request));
1057 tablesize = device->host->sg_tablesize;
1058 bhp = bh = req->bh;
1059 if(!tablesize) bh = NULL;
1060
1061
1062
1063
1064 while(req->nr_sectors && bh){
1065 bhp = bhp->b_reqnext;
1066 if(!bhp || !CONTIGUOUS_BUFFERS(bh,bhp)) tablesize--;
1067 req->nr_sectors -= bh->b_size >> 9;
1068 req->sector += bh->b_size >> 9;
1069 if(!tablesize) break;
1070 bh = bhp;
1071 }
1072 if(req->nr_sectors && bh && bh->b_reqnext){
1073 SCpnt->request.bhtail = bh;
1074 req->bh = bh->b_reqnext;
1075 bh->b_reqnext = NULL;
1076 bh = req->bh;
1077
1078 SCpnt->request.nr_sectors -= req->nr_sectors;
1079 req->current_nr_sectors = bh->b_size >> 9;
1080 req->buffer = bh->b_data;
1081 SCpnt->request.sem = NULL;
1082 }
1083 else
1084 {
1085 req->rq_status = RQ_INACTIVE;
1086 *reqp = req->next;
1087 wake_up(&wait_for_request);
1088 }
1089 } else {
1090 SCpnt->request.rq_status = RQ_SCSI_BUSY;
1091 SCpnt->request.sem = NULL;
1092
1093 }
1094 restore_flags(flags);
1095 break;
1096 }
1097 }
1098
1099 SCpnt->use_sg = 0;
1100 SCpnt->old_use_sg = 0;
1101 SCpnt->transfersize = 0;
1102 SCpnt->cmd_len = 0;
1103
1104 SCpnt->underflow = 0;
1105
1106
1107
1108
1109 SCpnt->channel = device->channel;
1110 SCpnt->lun = device->lun;
1111 SCpnt->target = device->id;
1112
1113 return SCpnt;
1114 }
1115
1116
1117
1118
1119
1120 inline void internal_cmnd (Scsi_Cmnd * SCpnt)
1121 {
1122 int temp;
1123 struct Scsi_Host * host;
1124 unsigned int flags;
1125 #ifdef DEBUG_DELAY
1126 int clock;
1127 #endif
1128
1129 host = SCpnt->host;
1130
1131
1132
1133
1134
1135 save_flags(flags);
1136 sti();
1137 temp = host->last_reset + MIN_RESET_DELAY;
1138 while (jiffies < temp);
1139 restore_flags(flags);
1140
1141 update_timeout(SCpnt, SCpnt->timeout_per_command);
1142
1143
1144
1145
1146
1147 #ifdef DEBUG
1148 printk("internal_cmnd (host = %d, channel = %d, target = %d, "
1149 "command = %p, buffer = %p, \nbufflen = %d, done = %p)\n",
1150 SCpnt->host->host_no, SCpnt->channel, SCpnt->target, SCpnt->cmnd,
1151 SCpnt->buffer, SCpnt->bufflen, SCpnt->done);
1152 #endif
1153
1154 if (host->can_queue)
1155 {
1156 #ifdef DEBUG
1157 printk("queuecommand : routine at %p\n",
1158 host->hostt->queuecommand);
1159 #endif
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169 if(!intr_count && SCpnt->host->irq)
1170 disable_irq(SCpnt->host->irq);
1171
1172 host->hostt->queuecommand (SCpnt, scsi_done);
1173
1174 if(!intr_count && SCpnt->host->irq)
1175 enable_irq(SCpnt->host->irq);
1176 }
1177 else
1178 {
1179
1180 #ifdef DEBUG
1181 printk("command() : routine at %p\n", host->hostt->command);
1182 #endif
1183 temp=host->hostt->command (SCpnt);
1184 SCpnt->result = temp;
1185 #ifdef DEBUG_DELAY
1186 clock = jiffies + 4 * HZ;
1187 while (jiffies < clock);
1188 printk("done(host = %d, result = %04x) : routine at %08x\n",
1189 host->host_no, temp);
1190 #endif
1191 scsi_done(SCpnt);
1192 }
1193 #ifdef DEBUG
1194 printk("leaving internal_cmnd()\n");
1195 #endif
1196 }
1197
1198 static void scsi_request_sense (Scsi_Cmnd * SCpnt)
1199 {
1200 unsigned int flags;
1201
1202 save_flags(flags);
1203 cli();
1204 SCpnt->flags |= WAS_SENSE | ASKED_FOR_SENSE;
1205 update_timeout(SCpnt, SENSE_TIMEOUT);
1206 restore_flags(flags);
1207
1208
1209 memcpy ((void *) SCpnt->cmnd , (void *) generic_sense,
1210 sizeof(generic_sense));
1211
1212 SCpnt->cmnd[1] = SCpnt->lun << 5;
1213 SCpnt->cmnd[4] = sizeof(SCpnt->sense_buffer);
1214
1215 SCpnt->request_buffer = &SCpnt->sense_buffer;
1216 SCpnt->request_bufflen = sizeof(SCpnt->sense_buffer);
1217 SCpnt->use_sg = 0;
1218 SCpnt->cmd_len = COMMAND_SIZE(SCpnt->cmnd[0]);
1219 internal_cmnd (SCpnt);
1220 }
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231 void scsi_do_cmd (Scsi_Cmnd * SCpnt, const void *cmnd ,
1232 void *buffer, unsigned bufflen, void (*done)(Scsi_Cmnd *),
1233 int timeout, int retries)
1234 {
1235 unsigned long flags;
1236 struct Scsi_Host * host = SCpnt->host;
1237
1238 #ifdef DEBUG
1239 {
1240 int i;
1241 int target = SCpnt->target;
1242 printk ("scsi_do_cmd (host = %d, channel = %d target = %d, "
1243 "buffer =%p, bufflen = %d, done = %p, timeout = %d, "
1244 "retries = %d)\n"
1245 "command : " , host->host_no, SCpnt->channel, target, buffer,
1246 bufflen, done, timeout, retries);
1247 for (i = 0; i < 10; ++i)
1248 printk ("%02x ", ((unsigned char *) cmnd)[i]);
1249 printk("\n");
1250 }
1251 #endif
1252
1253 if (!host)
1254 {
1255 panic ("Invalid or not present host.\n");
1256 }
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267 save_flags(flags);
1268 cli();
1269 SCpnt->pid = scsi_pid++;
1270
1271 while (SCSI_BLOCK(host)) {
1272 restore_flags(flags);
1273 SCSI_SLEEP(&host->host_wait, SCSI_BLOCK(host));
1274 cli();
1275 }
1276
1277 if (host->block) host_active = host;
1278
1279 host->host_busy++;
1280 restore_flags(flags);
1281
1282
1283
1284
1285
1286
1287
1288
1289 memcpy ((void *) SCpnt->data_cmnd , (const void *) cmnd, 12);
1290 #if 0
1291 SCpnt->host = host;
1292 SCpnt->channel = channel;
1293 SCpnt->target = target;
1294 SCpnt->lun = (SCpnt->data_cmnd[1] >> 5);
1295 #endif
1296 SCpnt->bufflen = bufflen;
1297 SCpnt->buffer = buffer;
1298 SCpnt->flags=0;
1299 SCpnt->retries=0;
1300 SCpnt->allowed=retries;
1301 SCpnt->done = done;
1302 SCpnt->timeout_per_command = timeout;
1303
1304 memcpy ((void *) SCpnt->cmnd , (const void *) cmnd, 12);
1305
1306
1307
1308 memset ((void *) SCpnt->sense_buffer, 0, sizeof SCpnt->sense_buffer);
1309 SCpnt->request_buffer = buffer;
1310 SCpnt->request_bufflen = bufflen;
1311 SCpnt->old_use_sg = SCpnt->use_sg;
1312 if (SCpnt->cmd_len == 0)
1313 SCpnt->cmd_len = COMMAND_SIZE(SCpnt->cmnd[0]);
1314 SCpnt->old_cmd_len = SCpnt->cmd_len;
1315
1316
1317
1318 SCpnt->internal_timeout = 0;
1319 SCpnt->abort_reason = 0;
1320 internal_cmnd (SCpnt);
1321
1322 #ifdef DEBUG
1323 printk ("Leaving scsi_do_cmd()\n");
1324 #endif
1325 }
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335 static void reset (Scsi_Cmnd * SCpnt)
1336 {
1337 #ifdef DEBUG
1338 printk("scsi: reset(%d, channel %d)\n", SCpnt->host->host_no,
1339 SCpnt->channel);
1340 #endif
1341
1342 SCpnt->flags |= (WAS_RESET | IS_RESETTING);
1343 scsi_reset(SCpnt, FALSE);
1344
1345 #ifdef DEBUG
1346 printk("performing request sense\n");
1347 #endif
1348
1349 #if 0
1350 if(SCpnt->flags & NEEDS_JUMPSTART) {
1351 SCpnt->flags &= ~NEEDS_JUMPSTART;
1352 scsi_request_sense (SCpnt);
1353 }
1354 #endif
1355 }
1356
1357
1358
1359 static int check_sense (Scsi_Cmnd * SCpnt)
1360 {
1361
1362
1363
1364
1365 if (((SCpnt->sense_buffer[0] & 0x70) >> 4) != 7) {
1366 if(!(SCpnt->flags & ASKED_FOR_SENSE))
1367 return SUGGEST_SENSE;
1368 else
1369 return SUGGEST_RETRY;
1370 }
1371
1372 SCpnt->flags &= ~ASKED_FOR_SENSE;
1373
1374 #ifdef DEBUG_INIT
1375 printk("scsi%d, channel%d : ", SCpnt->host->host_no, SCpnt->channel);
1376 print_sense("", SCpnt);
1377 printk("\n");
1378 #endif
1379 if (SCpnt->sense_buffer[2] & 0xe0)
1380 return SUGGEST_ABORT;
1381
1382 switch (SCpnt->sense_buffer[2] & 0xf)
1383 {
1384 case NO_SENSE:
1385 return 0;
1386 case RECOVERED_ERROR:
1387 return SUGGEST_IS_OK;
1388
1389 case ABORTED_COMMAND:
1390 return SUGGEST_RETRY;
1391 case NOT_READY:
1392 case UNIT_ATTENTION:
1393
1394
1395
1396
1397
1398
1399 if( SCpnt->device->expecting_cc_ua )
1400 {
1401 SCpnt->device->expecting_cc_ua = 0;
1402 return SUGGEST_RETRY;
1403 }
1404 return SUGGEST_ABORT;
1405
1406
1407 case COPY_ABORTED:
1408 case VOLUME_OVERFLOW:
1409 case MISCOMPARE:
1410
1411 case MEDIUM_ERROR:
1412 return SUGGEST_REMAP;
1413 case BLANK_CHECK:
1414 case DATA_PROTECT:
1415 case HARDWARE_ERROR:
1416 case ILLEGAL_REQUEST:
1417 default:
1418 return SUGGEST_ABORT;
1419 }
1420 }
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443 static void scsi_done (Scsi_Cmnd * SCpnt)
1444 {
1445 int status=0;
1446 int exit=0;
1447 int checked;
1448 int oldto;
1449 struct Scsi_Host * host = SCpnt->host;
1450 int result = SCpnt->result;
1451 oldto = update_timeout(SCpnt, 0);
1452
1453 #ifdef DEBUG_TIMEOUT
1454 if(result) printk("Non-zero result in scsi_done %x %d:%d\n",
1455 result, SCpnt->target, SCpnt->lun);
1456 #endif
1457
1458
1459
1460
1461 if(host_byte(result) == DID_ABORT && SCpnt->abort_reason)
1462 SCpnt->result = result = (result & 0xff00ffff) |
1463 (SCpnt->abort_reason << 16);
1464
1465
1466 #define FINISHED 0
1467 #define MAYREDO 1
1468 #define REDO 3
1469 #define PENDING 4
1470
1471 #ifdef DEBUG
1472 printk("In scsi_done(host = %d, result = %06x)\n", host->host_no, result);
1473 #endif
1474
1475 if(SCpnt->flags & WAS_SENSE)
1476 {
1477 SCpnt->use_sg = SCpnt->old_use_sg;
1478 SCpnt->cmd_len = SCpnt->old_cmd_len;
1479 }
1480
1481 switch (host_byte(result))
1482 {
1483 case DID_OK:
1484 if (status_byte(result) && (SCpnt->flags & WAS_SENSE))
1485
1486 {
1487 SCpnt->flags &= ~WAS_SENSE;
1488 SCpnt->internal_timeout &= ~SENSE_TIMEOUT;
1489
1490 if (!(SCpnt->flags & WAS_RESET))
1491 {
1492 printk("scsi%d : channel %d target %d lun %d request sense"
1493 " failed, performing reset.\n",
1494 SCpnt->host->host_no, SCpnt->channel, SCpnt->target,
1495 SCpnt->lun);
1496 reset(SCpnt);
1497 return;
1498 }
1499 else
1500 {
1501 exit = (DRIVER_HARD | SUGGEST_ABORT);
1502 status = FINISHED;
1503 }
1504 }
1505 else switch(msg_byte(result))
1506 {
1507 case COMMAND_COMPLETE:
1508 switch (status_byte(result))
1509 {
1510 case GOOD:
1511 if (SCpnt->flags & WAS_SENSE)
1512 {
1513 #ifdef DEBUG
1514 printk ("In scsi_done, GOOD status, COMMAND COMPLETE, parsing sense information.\n");
1515 #endif
1516 SCpnt->flags &= ~WAS_SENSE;
1517 SCpnt->internal_timeout &= ~SENSE_TIMEOUT;
1518
1519 switch (checked = check_sense(SCpnt))
1520 {
1521 case SUGGEST_SENSE:
1522 case 0:
1523 #ifdef DEBUG
1524 printk("NO SENSE. status = REDO\n");
1525 #endif
1526 update_timeout(SCpnt, oldto);
1527 status = REDO;
1528 break;
1529 case SUGGEST_IS_OK:
1530 break;
1531 case SUGGEST_REMAP:
1532 case SUGGEST_RETRY:
1533 #ifdef DEBUG
1534 printk("SENSE SUGGEST REMAP or SUGGEST RETRY - status = MAYREDO\n");
1535 #endif
1536 status = MAYREDO;
1537 exit = DRIVER_SENSE | SUGGEST_RETRY;
1538 break;
1539 case SUGGEST_ABORT:
1540 #ifdef DEBUG
1541 printk("SENSE SUGGEST ABORT - status = FINISHED");
1542 #endif
1543 status = FINISHED;
1544 exit = DRIVER_SENSE | SUGGEST_ABORT;
1545 break;
1546 default:
1547 printk ("Internal error %s %d \n", __FILE__,
1548 __LINE__);
1549 }
1550 }
1551 else
1552 {
1553 #ifdef DEBUG
1554 printk("COMMAND COMPLETE message returned, status = FINISHED. \n");
1555 #endif
1556 exit = DRIVER_OK;
1557 status = FINISHED;
1558 }
1559 break;
1560
1561 case CHECK_CONDITION:
1562 switch (check_sense(SCpnt))
1563 {
1564 case 0:
1565 update_timeout(SCpnt, oldto);
1566 status = REDO;
1567 break;
1568 case SUGGEST_REMAP:
1569 case SUGGEST_RETRY:
1570 status = MAYREDO;
1571 exit = DRIVER_SENSE | SUGGEST_RETRY;
1572 break;
1573 case SUGGEST_ABORT:
1574 status = FINISHED;
1575 exit = DRIVER_SENSE | SUGGEST_ABORT;
1576 break;
1577 case SUGGEST_SENSE:
1578 scsi_request_sense (SCpnt);
1579 status = PENDING;
1580 break;
1581 }
1582 break;
1583
1584 case CONDITION_GOOD:
1585 case INTERMEDIATE_GOOD:
1586 case INTERMEDIATE_C_GOOD:
1587 break;
1588
1589 case BUSY:
1590 update_timeout(SCpnt, oldto);
1591 status = REDO;
1592 break;
1593
1594 case RESERVATION_CONFLICT:
1595 printk("scsi%d, channel %d : RESERVATION CONFLICT performing"
1596 " reset.\n", SCpnt->host->host_no, SCpnt->channel);
1597 reset(SCpnt);
1598 return;
1599 #if 0
1600 exit = DRIVER_SOFT | SUGGEST_ABORT;
1601 status = MAYREDO;
1602 break;
1603 #endif
1604 default:
1605 printk ("Internal error %s %d \n"
1606 "status byte = %d \n", __FILE__,
1607 __LINE__, status_byte(result));
1608
1609 }
1610 break;
1611 default:
1612 panic("scsi: unsupported message byte %d received\n",
1613 msg_byte(result));
1614 }
1615 break;
1616 case DID_TIME_OUT:
1617 #ifdef DEBUG
1618 printk("Host returned DID_TIME_OUT - ");
1619 #endif
1620
1621 if (SCpnt->flags & WAS_TIMEDOUT)
1622 {
1623 #ifdef DEBUG
1624 printk("Aborting\n");
1625 #endif
1626 exit = (DRIVER_TIMEOUT | SUGGEST_ABORT);
1627 }
1628 else
1629 {
1630 #ifdef DEBUG
1631 printk ("Retrying.\n");
1632 #endif
1633 SCpnt->flags |= WAS_TIMEDOUT;
1634 SCpnt->internal_timeout &= ~IN_ABORT;
1635 status = REDO;
1636 }
1637 break;
1638 case DID_BUS_BUSY:
1639 case DID_PARITY:
1640 status = REDO;
1641 break;
1642 case DID_NO_CONNECT:
1643 #ifdef DEBUG
1644 printk("Couldn't connect.\n");
1645 #endif
1646 exit = (DRIVER_HARD | SUGGEST_ABORT);
1647 break;
1648 case DID_ERROR:
1649 status = MAYREDO;
1650 exit = (DRIVER_HARD | SUGGEST_ABORT);
1651 break;
1652 case DID_BAD_TARGET:
1653 case DID_ABORT:
1654 exit = (DRIVER_INVALID | SUGGEST_ABORT);
1655 break;
1656 case DID_RESET:
1657 if (SCpnt->flags & IS_RESETTING)
1658 {
1659 SCpnt->flags &= ~IS_RESETTING;
1660 status = REDO;
1661 break;
1662 }
1663
1664 if(msg_byte(result) == GOOD &&
1665 status_byte(result) == CHECK_CONDITION) {
1666 switch (check_sense(SCpnt)) {
1667 case 0:
1668 update_timeout(SCpnt, oldto);
1669 status = REDO;
1670 break;
1671 case SUGGEST_REMAP:
1672 case SUGGEST_RETRY:
1673 status = MAYREDO;
1674 exit = DRIVER_SENSE | SUGGEST_RETRY;
1675 break;
1676 case SUGGEST_ABORT:
1677 status = FINISHED;
1678 exit = DRIVER_SENSE | SUGGEST_ABORT;
1679 break;
1680 case SUGGEST_SENSE:
1681 scsi_request_sense (SCpnt);
1682 status = PENDING;
1683 break;
1684 }
1685 } else {
1686 status=REDO;
1687 exit = SUGGEST_RETRY;
1688 }
1689 break;
1690 default :
1691 exit = (DRIVER_ERROR | SUGGEST_DIE);
1692 }
1693
1694 switch (status)
1695 {
1696 case FINISHED:
1697 case PENDING:
1698 break;
1699 case MAYREDO:
1700 #ifdef DEBUG
1701 printk("In MAYREDO, allowing %d retries, have %d\n",
1702 SCpnt->allowed, SCpnt->retries);
1703 #endif
1704 if ((++SCpnt->retries) < SCpnt->allowed)
1705 {
1706 if ((SCpnt->retries >= (SCpnt->allowed >> 1))
1707 && !(jiffies < SCpnt->host->last_reset + MIN_RESET_PERIOD)
1708 && !(SCpnt->flags & WAS_RESET))
1709 {
1710 printk("scsi%d channel %d : resetting for second half of retries.\n",
1711 SCpnt->host->host_no, SCpnt->channel);
1712 reset(SCpnt);
1713 break;
1714 }
1715
1716 }
1717 else
1718 {
1719 status = FINISHED;
1720 break;
1721 }
1722
1723
1724 case REDO:
1725
1726 if (SCpnt->flags & WAS_SENSE)
1727 scsi_request_sense(SCpnt);
1728 else
1729 {
1730 memcpy ((void *) SCpnt->cmnd,
1731 (void*) SCpnt->data_cmnd,
1732 sizeof(SCpnt->data_cmnd));
1733 SCpnt->request_buffer = SCpnt->buffer;
1734 SCpnt->request_bufflen = SCpnt->bufflen;
1735 SCpnt->use_sg = SCpnt->old_use_sg;
1736 SCpnt->cmd_len = SCpnt->old_cmd_len;
1737 internal_cmnd (SCpnt);
1738 }
1739 break;
1740 default:
1741 INTERNAL_ERROR;
1742 }
1743
1744 if (status == FINISHED) {
1745 #ifdef DEBUG
1746 printk("Calling done function - at address %p\n", SCpnt->done);
1747 #endif
1748 host->host_busy--;
1749
1750 if (host->block && host->host_busy == 0) {
1751 host_active = NULL;
1752
1753
1754 if (MAJOR(SCpnt->request.rq_dev) != SCSI_DISK_MAJOR &&
1755 MAJOR(SCpnt->request.rq_dev) != SCSI_CDROM_MAJOR) {
1756 struct Scsi_Host * next;
1757
1758 for (next = host->block; next != host; next = next->block)
1759 wake_up(&next->host_wait);
1760 }
1761
1762 }
1763
1764 wake_up(&host->host_wait);
1765 SCpnt->result = result | ((exit & 0xff) << 24);
1766 SCpnt->use_sg = SCpnt->old_use_sg;
1767 SCpnt->cmd_len = SCpnt->old_cmd_len;
1768 SCpnt->done (SCpnt);
1769 }
1770
1771 #undef FINISHED
1772 #undef REDO
1773 #undef MAYREDO
1774 #undef PENDING
1775 }
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793 int scsi_abort (Scsi_Cmnd * SCpnt, int why, int pid)
1794 {
1795 int oldto;
1796 unsigned long flags;
1797 struct Scsi_Host * host = SCpnt->host;
1798
1799 while(1)
1800 {
1801 save_flags(flags);
1802 cli();
1803
1804
1805
1806
1807
1808 if (SCpnt->request.rq_status == RQ_INACTIVE || pid != SCpnt->pid) {
1809 restore_flags(flags);
1810 return 0;
1811 }
1812
1813 if (SCpnt->internal_timeout & IN_ABORT)
1814 {
1815 restore_flags(flags);
1816 while (SCpnt->internal_timeout & IN_ABORT)
1817 barrier();
1818 }
1819 else
1820 {
1821 SCpnt->internal_timeout |= IN_ABORT;
1822 oldto = update_timeout(SCpnt, ABORT_TIMEOUT);
1823
1824 if ((SCpnt->flags & IS_RESETTING) &&
1825 SCpnt->device->soft_reset) {
1826
1827
1828
1829 printk("Stale command on %d %d:%d appears to have died when"
1830 " the bus was reset\n",
1831 SCpnt->channel, SCpnt->target, SCpnt->lun);
1832 }
1833
1834 restore_flags(flags);
1835 if (!host->host_busy) {
1836 SCpnt->internal_timeout &= ~IN_ABORT;
1837 update_timeout(SCpnt, oldto);
1838 return 0;
1839 }
1840 printk("scsi : aborting command due to timeout : pid %lu, scsi%d,"
1841 " channel %d, id %d, lun %d ",
1842 SCpnt->pid, SCpnt->host->host_no, (int) SCpnt->channel,
1843 (int) SCpnt->target, (int) SCpnt->lun);
1844 print_command (SCpnt->cmnd);
1845 if (SCpnt->request.rq_status == RQ_INACTIVE || pid != SCpnt->pid)
1846 return 0;
1847 SCpnt->abort_reason = why;
1848 switch(host->hostt->abort(SCpnt)) {
1849
1850
1851
1852
1853 case SCSI_ABORT_BUSY:
1854
1855
1856 case SCSI_ABORT_SNOOZE:
1857 if(why == DID_TIME_OUT) {
1858 save_flags(flags);
1859 cli();
1860 SCpnt->internal_timeout &= ~IN_ABORT;
1861 if(SCpnt->flags & WAS_TIMEDOUT) {
1862 restore_flags(flags);
1863 return 1;
1864
1865
1866
1867 } else {
1868 SCpnt->flags |= WAS_TIMEDOUT;
1869 oldto = SCpnt->timeout_per_command;
1870 update_timeout(SCpnt, oldto);
1871 }
1872 restore_flags(flags);
1873 }
1874 return 0;
1875 case SCSI_ABORT_PENDING:
1876 if(why != DID_TIME_OUT) {
1877 save_flags(flags);
1878 cli();
1879 update_timeout(SCpnt, oldto);
1880 restore_flags(flags);
1881 }
1882 return 0;
1883 case SCSI_ABORT_SUCCESS:
1884
1885
1886
1887 case SCSI_ABORT_NOT_RUNNING:
1888 SCpnt->internal_timeout &= ~IN_ABORT;
1889 update_timeout(SCpnt, 0);
1890 return 0;
1891 case SCSI_ABORT_ERROR:
1892 default:
1893 SCpnt->internal_timeout &= ~IN_ABORT;
1894 return 1;
1895 }
1896 }
1897 }
1898 }
1899
1900 int scsi_reset (Scsi_Cmnd * SCpnt, int bus_reset_flag)
1901 {
1902 int temp, oldto;
1903 unsigned long flags;
1904 Scsi_Cmnd * SCpnt1;
1905 struct Scsi_Host * host = SCpnt->host;
1906
1907 #ifdef DEBUG
1908 printk("Danger Will Robinson! - SCSI bus for host %d is being reset.\n",
1909 host->host_no);
1910 #endif
1911
1912
1913
1914
1915
1916
1917
1918
1919 SCpnt->host->suggest_bus_reset = FALSE;
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929 SCpnt1 = host->host_queue;
1930 while(SCpnt1) {
1931 if( SCpnt->request.rq_status != RQ_INACTIVE
1932 && (SCpnt->flags & WAS_RESET) == 0 )
1933 break;
1934 SCpnt1 = SCpnt1->next;
1935 }
1936 if( SCpnt1 == NULL )
1937 SCpnt->host->suggest_bus_reset = TRUE;
1938
1939
1940
1941
1942
1943
1944
1945 if( bus_reset_flag )
1946 SCpnt->host->suggest_bus_reset = TRUE;
1947
1948 while (1) {
1949 save_flags(flags);
1950 cli();
1951 if (SCpnt->internal_timeout & IN_RESET)
1952 {
1953 restore_flags(flags);
1954 while (SCpnt->internal_timeout & IN_RESET)
1955 barrier();
1956 }
1957 else
1958 {
1959 SCpnt->internal_timeout |= IN_RESET;
1960 oldto = update_timeout(SCpnt, RESET_TIMEOUT);
1961
1962 if (host->host_busy)
1963 {
1964 restore_flags(flags);
1965 SCpnt1 = host->host_queue;
1966 while(SCpnt1) {
1967 if (SCpnt1->request.rq_status != RQ_INACTIVE) {
1968 #if 0
1969 if (!(SCpnt1->flags & IS_RESETTING) &&
1970 !(SCpnt1->internal_timeout & IN_ABORT))
1971 scsi_abort(SCpnt1, DID_RESET, SCpnt->pid);
1972 #endif
1973 SCpnt1->flags |= IS_RESETTING;
1974 }
1975 SCpnt1 = SCpnt1->next;
1976 }
1977
1978 host->last_reset = jiffies;
1979 temp = host->hostt->reset(SCpnt);
1980 host->last_reset = jiffies;
1981 }
1982 else
1983 {
1984 if (!host->block) host->host_busy++;
1985 restore_flags(flags);
1986 host->last_reset = jiffies;
1987 temp = host->hostt->reset(SCpnt);
1988 host->last_reset = jiffies;
1989 if (!host->block) host->host_busy--;
1990 }
1991
1992 #ifdef DEBUG
1993 printk("scsi reset function returned %d\n", temp);
1994 #endif
1995
1996 if( temp & SCSI_RESET_BUS_RESET )
1997 {
1998
1999
2000
2001
2002
2003 SCpnt1 = host->host_queue;
2004 while(SCpnt1) {
2005 SCpnt1->device->was_reset = 1;
2006 SCpnt1->device->expecting_cc_ua = 1;
2007 SCpnt1 = SCpnt1->next;
2008 }
2009 }
2010
2011
2012
2013
2014
2015 switch(temp & SCSI_RESET_ACTION) {
2016 case SCSI_RESET_SUCCESS:
2017 save_flags(flags);
2018 cli();
2019 SCpnt->internal_timeout &= ~IN_RESET;
2020 update_timeout(SCpnt, oldto);
2021 restore_flags(flags);
2022 return 0;
2023 case SCSI_RESET_PENDING:
2024 return 0;
2025 case SCSI_RESET_PUNT:
2026 SCpnt->internal_timeout &= ~IN_RESET;
2027 scsi_request_sense (SCpnt);
2028 return 0;
2029 case SCSI_RESET_WAKEUP:
2030 SCpnt->internal_timeout &= ~IN_RESET;
2031 scsi_request_sense (SCpnt);
2032
2033
2034
2035
2036
2037 if( temp & SCSI_RESET_BUS_RESET )
2038 {
2039 SCpnt1 = host->host_queue;
2040 while(SCpnt1) {
2041 if( SCpnt->request.rq_status != RQ_INACTIVE
2042 && SCpnt1 != SCpnt)
2043 scsi_request_sense (SCpnt);
2044 SCpnt1 = SCpnt1->next;
2045 }
2046 }
2047 return 0;
2048 case SCSI_RESET_SNOOZE:
2049
2050
2051
2052
2053
2054 save_flags(flags);
2055 cli();
2056 SCpnt->internal_timeout &= ~IN_RESET;
2057 update_timeout(SCpnt, 0);
2058 restore_flags(flags);
2059
2060 case SCSI_RESET_ERROR:
2061 default:
2062 return 1;
2063 }
2064
2065 return temp;
2066 }
2067 }
2068 }
2069
2070
2071 static void scsi_main_timeout(void)
2072 {
2073
2074
2075
2076
2077 int timed_out, pid;
2078 unsigned long flags;
2079 struct Scsi_Host * host;
2080 Scsi_Cmnd * SCpnt = NULL;
2081
2082 do {
2083 save_flags(flags);
2084 cli();
2085
2086 update_timeout(NULL, 0);
2087
2088
2089
2090
2091
2092 timed_out = 0;
2093 for(host = scsi_hostlist; host; host = host->next) {
2094 for(SCpnt = host->host_queue; SCpnt; SCpnt = SCpnt->next)
2095 if (SCpnt->timeout == -1)
2096 {
2097 SCpnt->timeout = 0;
2098 pid = SCpnt->pid;
2099 restore_flags(flags);
2100 scsi_times_out(SCpnt, pid);
2101 ++timed_out;
2102 save_flags(flags);
2103 cli();
2104 }
2105 }
2106 } while (timed_out);
2107 restore_flags(flags);
2108 }
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118 static int update_timeout(Scsi_Cmnd * SCset, int timeout)
2119 {
2120 unsigned int least, used;
2121 unsigned int oldto;
2122 unsigned long flags;
2123 struct Scsi_Host * host;
2124 Scsi_Cmnd * SCpnt = NULL;
2125
2126 save_flags(flags);
2127 cli();
2128
2129
2130
2131
2132
2133 used = (time_start) ? (jiffies - time_start) : 0;
2134
2135
2136
2137
2138
2139
2140
2141 oldto = 0;
2142
2143 if(SCset){
2144 oldto = SCset->timeout - used;
2145 SCset->timeout = timeout + used;
2146 }
2147
2148 least = 0xffffffff;
2149
2150 for(host = scsi_hostlist; host; host = host->next)
2151 for(SCpnt = host->host_queue; SCpnt; SCpnt = SCpnt->next)
2152 if (SCpnt->timeout > 0) {
2153 SCpnt->timeout -= used;
2154 if(SCpnt->timeout <= 0) SCpnt->timeout = -1;
2155 if(SCpnt->timeout > 0 && SCpnt->timeout < least)
2156 least = SCpnt->timeout;
2157 }
2158
2159
2160
2161
2162
2163
2164 if (least != 0xffffffff)
2165 {
2166 time_start = jiffies;
2167 timer_table[SCSI_TIMER].expires = (time_elapsed = least) + jiffies;
2168 timer_active |= 1 << SCSI_TIMER;
2169 }
2170 else
2171 {
2172 timer_table[SCSI_TIMER].expires = time_start = time_elapsed = 0;
2173 timer_active &= ~(1 << SCSI_TIMER);
2174 }
2175 restore_flags(flags);
2176 return oldto;
2177 }
2178
2179
2180 static unsigned char * dma_malloc_freelist = NULL;
2181 static int scsi_need_isa_bounce_buffers;
2182 static unsigned int dma_sectors = 0;
2183 unsigned int dma_free_sectors = 0;
2184 unsigned int need_isa_buffer = 0;
2185 static unsigned char ** dma_malloc_pages = NULL;
2186 #define MALLOC_PAGEBITS 12
2187
2188 static int scsi_register_host(Scsi_Host_Template *);
2189 static void scsi_unregister_host(Scsi_Host_Template *);
2190
2191 void *scsi_malloc(unsigned int len)
2192 {
2193 unsigned int nbits, mask;
2194 unsigned long flags;
2195 int i, j;
2196 if((len & 0x1ff) || len > (1<<MALLOC_PAGEBITS))
2197 return NULL;
2198
2199 save_flags(flags);
2200 cli();
2201 nbits = len >> 9;
2202 mask = (1 << nbits) - 1;
2203
2204 for(i=0;i < (dma_sectors >> (MALLOC_PAGEBITS - 9)); i++)
2205 for(j=0; j<=(sizeof(*dma_malloc_freelist) * 8) - nbits; j++){
2206 if ((dma_malloc_freelist[i] & (mask << j)) == 0){
2207 dma_malloc_freelist[i] |= (mask << j);
2208 restore_flags(flags);
2209 dma_free_sectors -= nbits;
2210 #ifdef DEBUG
2211 printk("SMalloc: %d %p ",len, dma_malloc_pages[i] + (j << 9));
2212 #endif
2213 return (void *) ((unsigned long) dma_malloc_pages[i] + (j << 9));
2214 }
2215 }
2216 restore_flags(flags);
2217 return NULL;
2218 }
2219
2220 int scsi_free(void *obj, unsigned int len)
2221 {
2222 int page, sector, nbits, mask;
2223 long offset;
2224 unsigned long flags;
2225
2226 #ifdef DEBUG
2227 printk("Sfree %p %d\n",obj, len);
2228 #endif
2229
2230 offset = -1;
2231 for (page = 0; page < (dma_sectors >> 3); page++)
2232 if ((unsigned long) obj >= (unsigned long) dma_malloc_pages[page] &&
2233 (unsigned long) obj < (unsigned long) dma_malloc_pages[page]
2234 + (1 << MALLOC_PAGEBITS))
2235 {
2236 offset = ((unsigned long) obj) - ((unsigned long)dma_malloc_pages[page]);
2237 break;
2238 }
2239
2240 if (page == (dma_sectors >> 3)) panic("Bad offset");
2241 sector = offset >> 9;
2242 if(sector >= dma_sectors) panic ("Bad page");
2243
2244 sector = (offset >> 9) & (sizeof(*dma_malloc_freelist) * 8 - 1);
2245 nbits = len >> 9;
2246 mask = (1 << nbits) - 1;
2247
2248 if ((mask << sector) > 0xffff) panic ("Bad memory alignment");
2249
2250 save_flags(flags);
2251 cli();
2252 if((dma_malloc_freelist[page] & (mask << sector)) != (mask<<sector))
2253 panic("Trying to free unused memory");
2254
2255 dma_free_sectors += nbits;
2256 dma_malloc_freelist[page] &= ~(mask << sector);
2257 restore_flags(flags);
2258 return 0;
2259 }
2260
2261
2262 int scsi_loadable_module_flag;
2263
2264 void * scsi_init_malloc(unsigned int size, int priority)
2265 {
2266 void * retval;
2267
2268
2269
2270
2271
2272 if ((size % PAGE_SIZE) == 0) {
2273 int order, a_size;
2274 for (order = 0, a_size = PAGE_SIZE;
2275 a_size < size; order++, a_size <<= 1)
2276 ;
2277 retval = (void *) __get_dma_pages(priority & GFP_LEVEL_MASK,
2278 order);
2279 } else
2280 retval = kmalloc(size, priority);
2281
2282 if (retval)
2283 memset(retval, 0, size);
2284 return retval;
2285 }
2286
2287
2288 void scsi_init_free(char * ptr, unsigned int size)
2289 {
2290
2291
2292
2293
2294
2295 if ((size % PAGE_SIZE) == 0) {
2296 int order, a_size;
2297
2298 for (order = 0, a_size = PAGE_SIZE;
2299 a_size < size; order++, a_size <<= 1)
2300 ;
2301 free_pages((unsigned long)ptr, order);
2302 } else
2303 kfree(ptr);
2304 }
2305
2306 void scsi_build_commandblocks(Scsi_Device * SDpnt)
2307 {
2308 int j;
2309 Scsi_Cmnd * SCpnt;
2310 struct Scsi_Host * host = NULL;
2311
2312 for(j=0;j<SDpnt->host->cmd_per_lun;j++){
2313 SCpnt = (Scsi_Cmnd *) scsi_init_malloc(sizeof(Scsi_Cmnd), GFP_ATOMIC);
2314 SCpnt->host = SDpnt->host;
2315 SCpnt->device = SDpnt;
2316 SCpnt->target = SDpnt->id;
2317 SCpnt->lun = SDpnt->lun;
2318 SCpnt->channel = SDpnt->channel;
2319 SCpnt->request.rq_status = RQ_INACTIVE;
2320 SCpnt->use_sg = 0;
2321 SCpnt->old_use_sg = 0;
2322 SCpnt->old_cmd_len = 0;
2323 SCpnt->timeout = 0;
2324 SCpnt->underflow = 0;
2325 SCpnt->transfersize = 0;
2326 SCpnt->host_scribble = NULL;
2327 host = SDpnt->host;
2328 if(host->host_queue)
2329 host->host_queue->prev = SCpnt;
2330 SCpnt->next = host->host_queue;
2331 SCpnt->prev = NULL;
2332 host->host_queue = SCpnt;
2333 }
2334 SDpnt->has_cmdblocks = 1;
2335 }
2336
2337
2338
2339
2340
2341
2342 int scsi_dev_init(void)
2343 {
2344 struct Scsi_Host * host = NULL;
2345 Scsi_Device * SDpnt;
2346 struct Scsi_Host * shpnt;
2347 struct Scsi_Device_Template * sdtpnt;
2348 int i;
2349 #ifdef FOO_ON_YOU
2350 return;
2351 #endif
2352
2353
2354 dispatch_scsi_info_ptr = dispatch_scsi_info;
2355
2356
2357 scsi_loadable_module_flag = 0;
2358
2359 timer_table[SCSI_TIMER].fn = scsi_main_timeout;
2360 timer_table[SCSI_TIMER].expires = 0;
2361
2362
2363
2364 #if CONFIG_PROC_FS
2365 proc_scsi_register(0, &proc_scsi_scsi);
2366 #endif
2367
2368
2369 scsi_init();
2370
2371 scsi_devices = (Scsi_Device *) NULL;
2372
2373 for (shpnt = scsi_hostlist; shpnt; shpnt = shpnt->next)
2374 scan_scsis(shpnt,0,0,0,0);
2375
2376 printk("scsi : detected ");
2377 for (sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2378 if (sdtpnt->dev_noticed && sdtpnt->name)
2379 printk("%d SCSI %s%s ", sdtpnt->dev_noticed, sdtpnt->name,
2380 (sdtpnt->dev_noticed != 1) ? "s" : "");
2381 printk("total.\n");
2382
2383 for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2384 if(sdtpnt->init && sdtpnt->dev_noticed) (*sdtpnt->init)();
2385
2386 for (SDpnt=scsi_devices; SDpnt; SDpnt = SDpnt->next) {
2387 SDpnt->scsi_request_fn = NULL;
2388 for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2389 if(sdtpnt->attach) (*sdtpnt->attach)(SDpnt);
2390 if(SDpnt->attached) scsi_build_commandblocks(SDpnt);
2391 }
2392
2393
2394 if (scsi_devicelist)
2395 dma_sectors = 16;
2396
2397 if (high_memory-1 > ISA_DMA_THRESHOLD)
2398 scsi_need_isa_bounce_buffers = 1;
2399 else
2400 scsi_need_isa_bounce_buffers = 0;
2401
2402 for (SDpnt=scsi_devices; SDpnt; SDpnt = SDpnt->next) {
2403 host = SDpnt->host;
2404
2405 if(SDpnt->type != TYPE_TAPE)
2406 dma_sectors += ((host->sg_tablesize *
2407 sizeof(struct scatterlist) + 511) >> 9) *
2408 host->cmd_per_lun;
2409
2410 if(host->unchecked_isa_dma &&
2411 high_memory - 1 > ISA_DMA_THRESHOLD &&
2412 SDpnt->type != TYPE_TAPE) {
2413 dma_sectors += (PAGE_SIZE >> 9) * host->sg_tablesize *
2414 host->cmd_per_lun;
2415 need_isa_buffer++;
2416 }
2417 }
2418
2419 dma_sectors = (dma_sectors + 15) & 0xfff0;
2420 dma_free_sectors = dma_sectors;
2421
2422 if (dma_sectors)
2423 {
2424 dma_malloc_freelist = (unsigned char *)
2425 scsi_init_malloc(dma_sectors >> 3, GFP_ATOMIC);
2426 memset(dma_malloc_freelist, 0, dma_sectors >> 3);
2427
2428 dma_malloc_pages = (unsigned char **)
2429 scsi_init_malloc(dma_sectors >> 1, GFP_ATOMIC);
2430 memset(dma_malloc_pages, 0, dma_sectors >> 1);
2431
2432 for(i=0; i< dma_sectors >> 3; i++)
2433 dma_malloc_pages[i] = (unsigned char *)
2434 scsi_init_malloc(PAGE_SIZE, GFP_ATOMIC | GFP_DMA);
2435
2436 }
2437
2438
2439
2440 for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2441 if(sdtpnt->finish && sdtpnt->nr_dev)
2442 (*sdtpnt->finish)();
2443
2444 scsi_loadable_module_flag = 1;
2445
2446 return 0;
2447 }
2448
2449 static void print_inquiry(unsigned char *data)
2450 {
2451 int i;
2452
2453 printk(" Vendor: ");
2454 for (i = 8; i < 16; i++)
2455 {
2456 if (data[i] >= 0x20 && i < data[4] + 5)
2457 printk("%c", data[i]);
2458 else
2459 printk(" ");
2460 }
2461
2462 printk(" Model: ");
2463 for (i = 16; i < 32; i++)
2464 {
2465 if (data[i] >= 0x20 && i < data[4] + 5)
2466 printk("%c", data[i]);
2467 else
2468 printk(" ");
2469 }
2470
2471 printk(" Rev: ");
2472 for (i = 32; i < 36; i++)
2473 {
2474 if (data[i] >= 0x20 && i < data[4] + 5)
2475 printk("%c", data[i]);
2476 else
2477 printk(" ");
2478 }
2479
2480 printk("\n");
2481
2482 i = data[0] & 0x1f;
2483
2484 printk(" Type: %s ",
2485 i < MAX_SCSI_DEVICE_CODE ? scsi_device_types[i] : "Unknown " );
2486 printk(" ANSI SCSI revision: %02x", data[2] & 0x07);
2487 if ((data[2] & 0x07) == 1 && (data[3] & 0x0f) == 1)
2488 printk(" CCS\n");
2489 else
2490 printk("\n");
2491 }
2492
2493
2494 #ifdef CONFIG_PROC_FS
2495 int scsi_proc_info(char *buffer, char **start, off_t offset, int length,
2496 int hostno, int inout)
2497 {
2498 Scsi_Device *scd;
2499 struct Scsi_Host *HBA_ptr;
2500 int parameter[4];
2501 char *p;
2502 int size, len = 0;
2503 off_t begin = 0;
2504 off_t pos = 0;
2505
2506 scd = scsi_devices;
2507 HBA_ptr = scsi_hostlist;
2508
2509 if(inout == 0) {
2510 size = sprintf(buffer+len,"Attached devices: %s\n", (scd)?"":"none");
2511 len += size;
2512 pos = begin + len;
2513 while (HBA_ptr) {
2514 #if 0
2515 size += sprintf(buffer+len,"scsi%2d: %s\n", (int) HBA_ptr->host_no,
2516 HBA_ptr->hostt->procname);
2517 len += size;
2518 pos = begin + len;
2519 #endif
2520 scd = scsi_devices;
2521 while (scd) {
2522 if (scd->host == HBA_ptr) {
2523 proc_print_scsidevice(scd, buffer, &size, len);
2524 len += size;
2525 pos = begin + len;
2526
2527 if (pos < offset) {
2528 len = 0;
2529 begin = pos;
2530 }
2531 if (pos > offset + length)
2532 goto stop_output;
2533 }
2534 scd = scd->next;
2535 }
2536 HBA_ptr = HBA_ptr->next;
2537 }
2538
2539 stop_output:
2540 *start=buffer+(offset-begin);
2541 len-=(offset-begin);
2542 if(len>length)
2543 len = length;
2544 return (len);
2545 }
2546
2547 if(!buffer || length < 25 || strncmp("scsi", buffer, 4))
2548 return(-EINVAL);
2549
2550 if(!strncmp("singledevice", buffer + 5, 12)) {
2551 p = buffer + 17;
2552
2553 parameter[0] = simple_strtoul(p , &p, 0);
2554 parameter[1] = simple_strtoul(p , &p, 0);
2555 parameter[2] = simple_strtoul(p , &p, 0);
2556 parameter[3] = simple_strtoul(p , &p, 0);
2557
2558 while(scd && scd->host->host_no != parameter[0]
2559 && scd->channel != parameter[1]
2560 && scd->id != parameter[2]
2561 && scd->lun != parameter[3]) {
2562 scd = scd->next;
2563 }
2564 if(scd)
2565 return(-ENOSYS);
2566 while(HBA_ptr && HBA_ptr->host_no != parameter[0])
2567 HBA_ptr = HBA_ptr->next;
2568
2569 if(!HBA_ptr)
2570 return(-ENXIO);
2571
2572 scan_scsis (HBA_ptr, 1, parameter[1], parameter[2], parameter[3]);
2573 return(0);
2574 }
2575 return(-EINVAL);
2576 }
2577 #endif
2578
2579
2580
2581
2582
2583
2584 static int scsi_register_host(Scsi_Host_Template * tpnt)
2585 {
2586 int pcount;
2587 struct Scsi_Host * shpnt;
2588 struct Scsi_Host * host = NULL;
2589 unsigned long flags;
2590 Scsi_Device * SDpnt;
2591 struct Scsi_Device_Template * sdtpnt;
2592 int i;
2593 const char * name;
2594
2595 if (tpnt->next || !tpnt->detect) return 1;
2596
2597
2598 pcount = next_scsi_host;
2599 if ((tpnt->present = tpnt->detect(tpnt)))
2600 {
2601 if(pcount == next_scsi_host) {
2602 if(tpnt->present > 1) {
2603 printk("Failure to register low-level scsi driver");
2604 scsi_unregister_host(tpnt);
2605 return 1;
2606 }
2607
2608
2609
2610 scsi_register(tpnt,0);
2611 }
2612 tpnt->next = scsi_hosts;
2613 scsi_hosts = tpnt;
2614
2615
2616 #if CONFIG_PROC_FS
2617 build_proc_dir_entries(tpnt);
2618 #endif
2619
2620 for(shpnt=scsi_hostlist; shpnt; shpnt = shpnt->next)
2621 if(shpnt->hostt == tpnt)
2622 {
2623 if(tpnt->info)
2624 name = tpnt->info(shpnt);
2625 else
2626 name = tpnt->name;
2627 printk ("scsi%d : %s\n",
2628 shpnt->host_no, name);
2629 }
2630
2631 printk ("scsi : %d host%s.\n", next_scsi_host,
2632 (next_scsi_host == 1) ? "" : "s");
2633
2634 scsi_make_blocked_list();
2635
2636
2637
2638
2639
2640 for(shpnt=scsi_hostlist; shpnt; shpnt = shpnt->next)
2641 if(shpnt->hostt == tpnt) scan_scsis(shpnt,0,0,0,0);
2642
2643 for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2644 if(sdtpnt->init && sdtpnt->dev_noticed) (*sdtpnt->init)();
2645
2646
2647
2648 for(SDpnt = scsi_devices; SDpnt; SDpnt = SDpnt->next)
2649 if(SDpnt->host->hostt == tpnt)
2650 {
2651 for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2652 if(sdtpnt->attach) (*sdtpnt->attach)(SDpnt);
2653 if(SDpnt->attached) scsi_build_commandblocks(SDpnt);
2654 }
2655
2656
2657 {
2658 unsigned char * new_dma_malloc_freelist = NULL;
2659 unsigned int new_dma_sectors = 0;
2660 unsigned int new_need_isa_buffer = 0;
2661 unsigned char ** new_dma_malloc_pages = NULL;
2662
2663 new_dma_sectors = 16;
2664 if (scsi_devicelist)
2665 for(shpnt=scsi_hostlist; shpnt; shpnt = shpnt->next)
2666 new_dma_sectors += 8;
2667
2668 for (SDpnt=scsi_devices; SDpnt; SDpnt = SDpnt->next) {
2669 host = SDpnt->host;
2670
2671 if(SDpnt->type != TYPE_TAPE)
2672 new_dma_sectors += ((host->sg_tablesize *
2673 sizeof(struct scatterlist) + 511) >> 9) *
2674 host->cmd_per_lun;
2675
2676 if(host->unchecked_isa_dma &&
2677 scsi_need_isa_bounce_buffers &&
2678 SDpnt->type != TYPE_TAPE) {
2679 new_dma_sectors += (PAGE_SIZE >> 9) * host->sg_tablesize *
2680 host->cmd_per_lun;
2681 new_need_isa_buffer++;
2682 }
2683 }
2684
2685 new_dma_sectors = (new_dma_sectors + 15) & 0xfff0;
2686
2687
2688
2689
2690
2691
2692 if( new_dma_sectors < dma_sectors )
2693 new_dma_sectors = dma_sectors;
2694
2695 if (new_dma_sectors)
2696 {
2697 new_dma_malloc_freelist = (unsigned char *)
2698 scsi_init_malloc(new_dma_sectors >> 3, GFP_ATOMIC);
2699 memset(new_dma_malloc_freelist, 0, new_dma_sectors >> 3);
2700
2701 new_dma_malloc_pages = (unsigned char **)
2702 scsi_init_malloc(new_dma_sectors >> 1, GFP_ATOMIC);
2703 memset(new_dma_malloc_pages, 0, new_dma_sectors >> 1);
2704 }
2705
2706
2707
2708
2709 if( new_dma_sectors > dma_sectors ) {
2710 for(i=dma_sectors >> 3; i< new_dma_sectors >> 3; i++)
2711 new_dma_malloc_pages[i] = (unsigned char *)
2712 scsi_init_malloc(PAGE_SIZE, GFP_ATOMIC | GFP_DMA);
2713 }
2714
2715
2716
2717
2718 save_flags(flags);
2719 cli();
2720 if (dma_malloc_freelist)
2721 {
2722 memcpy(new_dma_malloc_freelist, dma_malloc_freelist, dma_sectors >> 3);
2723 scsi_init_free(dma_malloc_freelist, dma_sectors>>3);
2724 }
2725 dma_malloc_freelist = new_dma_malloc_freelist;
2726
2727 if (dma_malloc_pages)
2728 {
2729 memcpy(new_dma_malloc_pages, dma_malloc_pages, dma_sectors >> 1);
2730 scsi_init_free((char *) dma_malloc_pages, dma_sectors>>1);
2731 }
2732
2733 dma_free_sectors += new_dma_sectors - dma_sectors;
2734 dma_malloc_pages = new_dma_malloc_pages;
2735 dma_sectors = new_dma_sectors;
2736 need_isa_buffer = new_need_isa_buffer;
2737 restore_flags(flags);
2738 }
2739
2740
2741 for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2742 if(sdtpnt->finish && sdtpnt->nr_dev)
2743 (*sdtpnt->finish)();
2744 }
2745
2746 #if defined(USE_STATIC_SCSI_MEMORY)
2747 printk ("SCSI memory: total %ldKb, used %ldKb, free %ldKb.\n",
2748 (scsi_memory_upper_value - scsi_memory_lower_value) / 1024,
2749 (scsi_init_memory_start - scsi_memory_lower_value) / 1024,
2750 (scsi_memory_upper_value - scsi_init_memory_start) / 1024);
2751 #endif
2752
2753 MOD_INC_USE_COUNT;
2754 return 0;
2755 }
2756
2757
2758
2759
2760
2761 static void scsi_unregister_host(Scsi_Host_Template * tpnt)
2762 {
2763 Scsi_Host_Template * SHT, *SHTp;
2764 Scsi_Device *sdpnt, * sdppnt, * sdpnt1;
2765 Scsi_Cmnd * SCpnt;
2766 unsigned long flags;
2767 struct Scsi_Device_Template * sdtpnt;
2768 struct Scsi_Host * shpnt, *sh1;
2769 int pcount;
2770
2771
2772
2773
2774 for(sdpnt = scsi_devices; sdpnt; sdpnt = sdpnt->next)
2775 if(sdpnt->host->hostt == tpnt && sdpnt->host->hostt->usage_count
2776 && *sdpnt->host->hostt->usage_count) return;
2777
2778 for(shpnt = scsi_hostlist; shpnt; shpnt = shpnt->next)
2779 {
2780 if (shpnt->hostt != tpnt) continue;
2781 for(SCpnt = shpnt->host_queue; SCpnt; SCpnt = SCpnt->next)
2782 {
2783 save_flags(flags);
2784 cli();
2785 if(SCpnt->request.rq_status != RQ_INACTIVE) {
2786 restore_flags(flags);
2787 for(SCpnt = shpnt->host_queue; SCpnt; SCpnt = SCpnt->next)
2788 if(SCpnt->request.rq_status == RQ_SCSI_DISCONNECTING)
2789 SCpnt->request.rq_status = RQ_INACTIVE;
2790 printk("Device busy???\n");
2791 return;
2792 }
2793 SCpnt->request.rq_status = RQ_SCSI_DISCONNECTING;
2794 restore_flags(flags);
2795 }
2796 }
2797
2798
2799 for(sdpnt = scsi_devices; sdpnt; sdpnt = sdpnt->next)
2800 if(sdpnt->host->hostt == tpnt)
2801 {
2802 for(sdtpnt = scsi_devicelist; sdtpnt; sdtpnt = sdtpnt->next)
2803 if(sdtpnt->detach) (*sdtpnt->detach)(sdpnt);
2804
2805 if (sdpnt->attached) {
2806 printk("Attached usage count = %d\n", sdpnt->attached);
2807 return;
2808 }
2809 }
2810
2811
2812
2813 for(sdpnt = scsi_devices; sdpnt; sdpnt = sdpnt->next)
2814 if(sdpnt->host->hostt == tpnt)
2815 while (sdpnt->host->host_queue) {
2816 SCpnt = sdpnt->host->host_queue->next;
2817 scsi_init_free((char *) sdpnt->host->host_queue, sizeof(Scsi_Cmnd));
2818 sdpnt->host->host_queue = SCpnt;
2819 if (SCpnt) SCpnt->prev = NULL;
2820 sdpnt->has_cmdblocks = 0;
2821 }
2822
2823
2824
2825 sdppnt = NULL;
2826 for(sdpnt = scsi_devices; sdpnt; sdpnt = sdpnt1)
2827 {
2828 sdpnt1 = sdpnt->next;
2829 if (sdpnt->host->hostt == tpnt) {
2830 if (sdppnt)
2831 sdppnt->next = sdpnt->next;
2832 else
2833 scsi_devices = sdpnt->next;
2834 scsi_init_free((char *) sdpnt, sizeof (Scsi_Device));
2835 } else
2836 sdppnt = sdpnt;
2837 }
2838
2839
2840
2841
2842 shpnt = scsi_hostlist;
2843 while(shpnt) {
2844 sh1 = shpnt->next;
2845 if(shpnt->hostt == tpnt) {
2846 if(shpnt->loaded_as_module) {
2847 pcount = next_scsi_host;
2848
2849 #if CONFIG_PROC_FS
2850 proc_scsi_unregister(tpnt->proc_dir,
2851 shpnt->host_no + PROC_SCSI_FILE);
2852 #endif
2853 if(tpnt->release)
2854 (*tpnt->release)(shpnt);
2855 else {
2856
2857
2858
2859
2860 if (shpnt->irq) free_irq(shpnt->irq);
2861 if (shpnt->dma_channel != 0xff) free_dma(shpnt->dma_channel);
2862 if (shpnt->io_port && shpnt->n_io_port)
2863 release_region(shpnt->io_port, shpnt->n_io_port);
2864 }
2865 if(pcount == next_scsi_host) scsi_unregister(shpnt);
2866 tpnt->present--;
2867 }
2868 }
2869 shpnt = sh1;
2870 }
2871
2872 printk ("scsi : %d host%s.\n", next_scsi_host,
2873 (next_scsi_host == 1) ? "" : "s");
2874
2875 #if defined(USE_STATIC_SCSI_MEMORY)
2876 printk ("SCSI memory: total %ldKb, used %ldKb, free %ldKb.\n",
2877 (scsi_memory_upper_value - scsi_memory_lower_value) / 1024,
2878 (scsi_init_memory_start - scsi_memory_lower_value) / 1024,
2879 (scsi_memory_upper_value - scsi_init_memory_start) / 1024);
2880 #endif
2881
2882 scsi_make_blocked_list();
2883
2884
2885
2886 if (tpnt->present) return;
2887
2888
2889
2890 for(SHTp=NULL, SHT=scsi_hosts; SHT; SHTp=SHT, SHT=SHT->next)
2891 if(SHT == tpnt) {
2892 if(SHTp)
2893 SHTp->next = SHT->next;
2894 else
2895 scsi_hosts = SHT->next;
2896 SHT->next = NULL;
2897 break;
2898 }
2899
2900
2901 #if CONFIG_PROC_FS
2902 proc_scsi_unregister(tpnt->proc_dir, tpnt->proc_dir->low_ino);
2903 #endif
2904 MOD_DEC_USE_COUNT;
2905 }
2906
2907
2908
2909
2910
2911 static int scsi_register_device_module(struct Scsi_Device_Template * tpnt)
2912 {
2913 Scsi_Device * SDpnt;
2914
2915 if (tpnt->next) return 1;
2916
2917 scsi_register_device(tpnt);
2918
2919
2920
2921
2922 for(SDpnt = scsi_devices; SDpnt; SDpnt = SDpnt->next)
2923 if(tpnt->detect) SDpnt->attached += (*tpnt->detect)(SDpnt);
2924
2925
2926
2927
2928
2929 if(tpnt->init && tpnt->dev_noticed)
2930 if ((*tpnt->init)()) return 1;
2931
2932
2933
2934
2935 for(SDpnt = scsi_devices; SDpnt; SDpnt = SDpnt->next)
2936 {
2937 if(tpnt->attach) (*tpnt->attach)(SDpnt);
2938
2939
2940
2941
2942 if(SDpnt->attached && SDpnt->has_cmdblocks == 0)
2943 scsi_build_commandblocks(SDpnt);
2944 }
2945
2946
2947
2948
2949 if(tpnt->finish && tpnt->nr_dev) (*tpnt->finish)();
2950 MOD_INC_USE_COUNT;
2951 return 0;
2952 }
2953
2954 static int scsi_unregister_device(struct Scsi_Device_Template * tpnt)
2955 {
2956 Scsi_Device * SDpnt;
2957 Scsi_Cmnd * SCpnt;
2958 struct Scsi_Device_Template * spnt;
2959 struct Scsi_Device_Template * prev_spnt;
2960
2961
2962
2963
2964 if( *tpnt->usage_count != 0) return 0;
2965
2966
2967
2968
2969 for(SDpnt = scsi_devices; SDpnt; SDpnt = SDpnt->next)
2970 {
2971 if(tpnt->detach) (*tpnt->detach)(SDpnt);
2972 if(SDpnt->attached == 0)
2973 {
2974
2975
2976
2977
2978 for(SCpnt = SDpnt->host->host_queue; SCpnt; SCpnt = SCpnt->next)
2979 {
2980 if(SCpnt->device == SDpnt)
2981 {
2982 if(SCpnt->prev != NULL)
2983 SCpnt->prev->next = SCpnt->next;
2984 if(SCpnt->next != NULL)
2985 SCpnt->next->prev = SCpnt->prev;
2986 if(SCpnt == SDpnt->host->host_queue)
2987 SDpnt->host->host_queue = SCpnt->next;
2988 scsi_init_free((char *) SCpnt, sizeof(*SCpnt));
2989 }
2990 }
2991 SDpnt->has_cmdblocks = 0;
2992 }
2993 }
2994
2995
2996
2997 spnt = scsi_devicelist;
2998 prev_spnt = NULL;
2999 while(spnt != tpnt)
3000 {
3001 prev_spnt = spnt;
3002 spnt = spnt->next;
3003 }
3004 if(prev_spnt == NULL)
3005 scsi_devicelist = tpnt->next;
3006 else
3007 prev_spnt->next = spnt->next;
3008
3009 MOD_DEC_USE_COUNT;
3010
3011
3012
3013
3014 return 0;
3015 }
3016
3017
3018 int scsi_register_module(int module_type, void * ptr)
3019 {
3020 switch(module_type){
3021 case MODULE_SCSI_HA:
3022 return scsi_register_host((Scsi_Host_Template *) ptr);
3023
3024
3025 case MODULE_SCSI_DEV:
3026 return scsi_register_device_module((struct Scsi_Device_Template *) ptr);
3027
3028
3029
3030 case MODULE_SCSI_CONST:
3031
3032
3033
3034 case MODULE_SCSI_IOCTL:
3035
3036 default:
3037 return 1;
3038 }
3039 }
3040
3041 void scsi_unregister_module(int module_type, void * ptr)
3042 {
3043 switch(module_type) {
3044 case MODULE_SCSI_HA:
3045 scsi_unregister_host((Scsi_Host_Template *) ptr);
3046 break;
3047 case MODULE_SCSI_DEV:
3048 scsi_unregister_device((struct Scsi_Device_Template *) ptr);
3049 break;
3050
3051 case MODULE_SCSI_CONST:
3052 case MODULE_SCSI_IOCTL:
3053 break;
3054 default:
3055 }
3056 return;
3057 }
3058
3059 #ifdef DEBUG_TIMEOUT
3060 static void
3061 scsi_dump_status(void)
3062 {
3063 int i;
3064 struct Scsi_Host * shpnt;
3065 Scsi_Cmnd * SCpnt;
3066 printk("Dump of scsi parameters:\n");
3067 i = 0;
3068 for(shpnt = scsi_hostlist; shpnt; shpnt = shpnt->next)
3069 for(SCpnt=shpnt->host_queue; SCpnt; SCpnt = SCpnt->next)
3070 {
3071
3072 printk("(%d) %d:%d:%d:%d (%s %ld %ld %ld %ld) (%d %d %x) (%d %d %d) %x %x %x\n",
3073 i++, SCpnt->host->host_no,
3074 SCpnt->channel,
3075 SCpnt->target,
3076 SCpnt->lun,
3077 kdevname(SCpnt->request.rq_dev),
3078 SCpnt->request.sector,
3079 SCpnt->request.nr_sectors,
3080 SCpnt->request.current_nr_sectors,
3081 SCpnt->use_sg,
3082 SCpnt->retries,
3083 SCpnt->allowed,
3084 SCpnt->flags,
3085 SCpnt->timeout_per_command,
3086 SCpnt->timeout,
3087 SCpnt->internal_timeout,
3088 SCpnt->cmnd[0],
3089 SCpnt->sense_buffer[2],
3090 SCpnt->result);
3091 }
3092 printk("wait_for_request = %p\n", wait_for_request);
3093
3094 printk("Dump of pending block device requests\n");
3095 for(i=0; i<MAX_BLKDEV; i++)
3096 if(blk_dev[i].current_request)
3097 {
3098 struct request * req;
3099 printk("%d: ", i);
3100 req = blk_dev[i].current_request;
3101 while(req) {
3102 printk("(%s %d %ld %ld %ld) ",
3103 kdevname(req->rq_dev),
3104 req->cmd,
3105 req->sector,
3106 req->nr_sectors,
3107 req->current_nr_sectors);
3108 req = req->next;
3109 }
3110 printk("\n");
3111 }
3112 }
3113 #endif
3114
3115 #ifdef MODULE
3116
3117
3118 char kernel_version[] = UTS_RELEASE;
3119
3120 extern struct symbol_table scsi_symbol_table;
3121
3122
3123 int init_module(void) {
3124
3125
3126
3127 dispatch_scsi_info_ptr = dispatch_scsi_info;
3128
3129 timer_table[SCSI_TIMER].fn = scsi_main_timeout;
3130 timer_table[SCSI_TIMER].expires = 0;
3131 register_symtab(&scsi_symbol_table);
3132 scsi_loadable_module_flag = 1;
3133
3134 dma_sectors = PAGE_SIZE / 512;
3135
3136
3137
3138
3139
3140
3141 dma_malloc_freelist = (unsigned char *)
3142 scsi_init_malloc(dma_sectors >> 3, GFP_ATOMIC);
3143 memset(dma_malloc_freelist, 0, dma_sectors >> 3);
3144
3145
3146 dma_malloc_pages = (unsigned char **)
3147 scsi_init_malloc(dma_sectors >> 1, GFP_ATOMIC);
3148 dma_malloc_pages[0] = (unsigned char *)
3149 scsi_init_malloc(PAGE_SIZE, GFP_ATOMIC | GFP_DMA);
3150 return 0;
3151 }
3152
3153 void cleanup_module( void)
3154 {
3155 int i;
3156
3157 if (MOD_IN_USE) {
3158 printk(KERN_INFO __FILE__ ": module is in use, remove rejected\n");
3159 return;
3160 }
3161
3162
3163 dispatch_scsi_info_ptr = 0L;
3164
3165
3166
3167
3168 for(i=0; i < dma_sectors >> 3; i++)
3169 scsi_init_free(dma_malloc_pages[i], PAGE_SIZE);
3170 if (dma_malloc_pages)
3171 scsi_init_free((char *) dma_malloc_pages, dma_sectors>>1);
3172 if (dma_malloc_freelist)
3173 scsi_init_free(dma_malloc_freelist, dma_sectors>>3);
3174
3175 timer_table[SCSI_TIMER].fn = NULL;
3176 timer_table[SCSI_TIMER].expires = 0;
3177
3178
3179
3180
3181
3182 register_symtab(0);
3183 }
3184 #endif
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203