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