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