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