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