This source file includes following definitions.
- sd_open
- sd_release
- sd_geninit
- rw_intr
- do_sd_request
- requeue_sd_request
- check_scsidisk_media_change
- sd_init_done
- sd_init_onedisk
- sd_init
- sd_init1
- sd_attach
- revalidate_scsidisk
1
2
3
4
5
6
7
8
9
10
11
12
13 #include <linux/fs.h>
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <linux/string.h>
17 #include <linux/errno.h>
18 #include <asm/system.h>
19
20 #define MAJOR_NR SCSI_DISK_MAJOR
21 #include "../block/blk.h"
22 #include "scsi.h"
23 #include "hosts.h"
24 #include "sd.h"
25 #include "scsi_ioctl.h"
26 #include "constants.h"
27
28 #include <linux/genhd.h>
29
30
31
32
33
34 #define MAX_RETRIES 5
35
36
37
38
39
40 #define SD_TIMEOUT 300
41
42 struct hd_struct * sd;
43
44 int NR_SD=0;
45 int MAX_SD=0;
46 Scsi_Disk * rscsi_disks;
47 static int * sd_sizes;
48 static int * sd_blocksizes;
49
50 extern int sd_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
51
52 static sd_init_onedisk(int);
53
54 static void requeue_sd_request (Scsi_Cmnd * SCpnt);
55
56 static int sd_open(struct inode * inode, struct file * filp)
57 {
58 int target;
59 target = DEVICE_NR(MINOR(inode->i_rdev));
60
61 if(target >= NR_SD || !rscsi_disks[target].device)
62 return -ENODEV;
63
64
65
66
67 while (rscsi_disks[target].device->busy);
68
69 if(rscsi_disks[target].device->removable) {
70 check_disk_change(inode->i_rdev);
71
72 if(!rscsi_disks[target].device->access_count)
73 sd_ioctl(inode, NULL, SCSI_IOCTL_DOORLOCK, 0);
74 };
75 rscsi_disks[target].device->access_count++;
76 return 0;
77 }
78
79 static void sd_release(struct inode * inode, struct file * file)
80 {
81 int target;
82 sync_dev(inode->i_rdev);
83
84 target = DEVICE_NR(MINOR(inode->i_rdev));
85
86 rscsi_disks[target].device->access_count--;
87
88 if(rscsi_disks[target].device->removable) {
89 if(!rscsi_disks[target].device->access_count)
90 sd_ioctl(inode, NULL, SCSI_IOCTL_DOORUNLOCK, 0);
91 };
92 }
93
94 static void sd_geninit(void);
95
96 static struct file_operations sd_fops = {
97 NULL,
98 block_read,
99 block_write,
100 NULL,
101 NULL,
102 sd_ioctl,
103 NULL,
104 sd_open,
105 sd_release,
106 block_fsync
107 };
108
109 static struct gendisk sd_gendisk = {
110 MAJOR_NR,
111 "sd",
112 4,
113 1 << 4,
114 0,
115 sd_geninit,
116 NULL,
117 NULL,
118 0,
119 NULL,
120 NULL
121 };
122
123 static void sd_geninit (void)
124 {
125 int i;
126
127 for (i = 0; i < NR_SD; ++i)
128 sd[i << 4].nr_sects = rscsi_disks[i].capacity;
129 sd_gendisk.nr_real = NR_SD;
130 }
131
132
133
134
135
136
137
138 static void rw_intr (Scsi_Cmnd *SCpnt)
139 {
140 int result = SCpnt->result;
141 int this_count = SCpnt->bufflen >> 9;
142
143 #ifdef DEBUG
144 printk("sd%d : rw_intr(%d, %d)\n", MINOR(SCpnt->request.dev), SCpnt->host->host_no, result);
145 #endif
146
147
148
149
150
151
152
153 if (!result) {
154
155 #ifdef DEBUG
156 printk("sd%d : %d sectors remain.\n", MINOR(SCpnt->request.dev), SCpnt->request.nr_sectors);
157 printk("use_sg is %d\n ",SCpnt->use_sg);
158 #endif
159 if (SCpnt->use_sg) {
160 struct scatterlist * sgpnt;
161 int i;
162 sgpnt = (struct scatterlist *) SCpnt->buffer;
163 for(i=0; i<SCpnt->use_sg; i++) {
164 #ifdef DEBUG
165 printk(":%x %x %d\n",sgpnt[i].alt_address, sgpnt[i].address, sgpnt[i].length);
166 #endif
167 if (sgpnt[i].alt_address) {
168 if (SCpnt->request.cmd == READ)
169 memcpy(sgpnt[i].alt_address, sgpnt[i].address, sgpnt[i].length);
170 scsi_free(sgpnt[i].address, sgpnt[i].length);
171 };
172 };
173 scsi_free(SCpnt->buffer, SCpnt->sglist_len);
174 } else {
175 if (SCpnt->buffer != SCpnt->request.buffer) {
176 #ifdef DEBUG
177 printk("nosg: %x %x %d\n",SCpnt->request.buffer, SCpnt->buffer,
178 SCpnt->bufflen);
179 #endif
180 if (SCpnt->request.cmd == READ)
181 memcpy(SCpnt->request.buffer, SCpnt->buffer,
182 SCpnt->bufflen);
183 scsi_free(SCpnt->buffer, SCpnt->bufflen);
184 };
185 };
186
187
188
189
190
191 if (SCpnt->request.nr_sectors > this_count)
192 {
193 SCpnt->request.errors = 0;
194
195 if (!SCpnt->request.bh)
196 {
197 #ifdef DEBUG
198 printk("sd%d : handling page request, no buffer\n",
199 MINOR(SCpnt->request.dev));
200 #endif
201
202
203
204
205 panic("sd.c: linked page request (%lx %x)",
206 SCpnt->request.sector, this_count);
207 }
208 }
209 end_scsi_request(SCpnt, 1, this_count);
210 requeue_sd_request(SCpnt);
211 return;
212 }
213
214
215 if (SCpnt->use_sg) {
216 struct scatterlist * sgpnt;
217 int i;
218 sgpnt = (struct scatterlist *) SCpnt->buffer;
219 for(i=0; i<SCpnt->use_sg; i++) {
220 #ifdef DEBUG
221 printk("err: %x %x %d\n",SCpnt->request.buffer, SCpnt->buffer,
222 SCpnt->bufflen);
223 #endif
224 if (sgpnt[i].alt_address) {
225 scsi_free(sgpnt[i].address, sgpnt[i].length);
226 };
227 };
228 scsi_free(SCpnt->buffer, SCpnt->sglist_len);
229 } else {
230 #ifdef DEBUG
231 printk("nosgerr: %x %x %d\n",SCpnt->request.buffer, SCpnt->buffer,
232 SCpnt->bufflen);
233 #endif
234 if (SCpnt->buffer != SCpnt->request.buffer)
235 scsi_free(SCpnt->buffer, SCpnt->bufflen);
236 };
237
238
239
240
241
242
243
244 if (driver_byte(result) != 0) {
245 if (sugestion(result) == SUGGEST_REMAP) {
246 #ifdef REMAP
247
248
249
250
251 if rscsi_disks[DEVICE_NR(SCpnt->request.dev)].remap
252 {
253 result = 0;
254 }
255 else
256
257 #endif
258 }
259
260 if ((SCpnt->sense_buffer[0] & 0x7f) == 0x70) {
261 if ((SCpnt->sense_buffer[2] & 0xf) == UNIT_ATTENTION) {
262 if(rscsi_disks[DEVICE_NR(SCpnt->request.dev)].device->removable) {
263
264
265
266 rscsi_disks[DEVICE_NR(SCpnt->request.dev)].device->changed = 1;
267 end_scsi_request(SCpnt, 0, this_count);
268 requeue_sd_request(SCpnt);
269 return;
270 }
271 }
272 }
273
274
275
276
277
278
279
280
281
282 if (SCpnt->sense_buffer[2] == ILLEGAL_REQUEST) {
283 if (rscsi_disks[DEVICE_NR(SCpnt->request.dev)].ten) {
284 rscsi_disks[DEVICE_NR(SCpnt->request.dev)].ten = 0;
285 requeue_sd_request(SCpnt);
286 result = 0;
287 } else {
288 }
289 }
290 }
291 if (result) {
292 printk("SCSI disk error : host %d id %d lun %d return code = %x\n",
293 rscsi_disks[DEVICE_NR(SCpnt->request.dev)].device->host->host_no,
294 rscsi_disks[DEVICE_NR(SCpnt->request.dev)].device->id,
295 rscsi_disks[DEVICE_NR(SCpnt->request.dev)].device->lun, result);
296
297 if (driver_byte(result) & DRIVER_SENSE)
298 print_sense("sd", SCpnt);
299 end_scsi_request(SCpnt, 0, SCpnt->request.current_nr_sectors);
300 requeue_sd_request(SCpnt);
301 return;
302 }
303 }
304
305
306
307
308
309
310
311 static void do_sd_request (void)
312 {
313 Scsi_Cmnd * SCpnt = NULL;
314 struct request * req = NULL;
315 int flag = 0;
316 while (1==1){
317 cli();
318 if (CURRENT != NULL && CURRENT->dev == -1) {
319 sti();
320 return;
321 };
322
323 INIT_SCSI_REQUEST;
324
325
326
327
328
329
330
331
332
333
334
335
336
337 if (flag++ == 0)
338 SCpnt = allocate_device(&CURRENT,
339 rscsi_disks[DEVICE_NR(MINOR(CURRENT->dev))].device->index, 0);
340 else SCpnt = NULL;
341 sti();
342
343
344
345
346
347
348
349
350 if (!SCpnt && NR_SD > 1){
351 struct request *req1;
352 req1 = NULL;
353 cli();
354 req = CURRENT;
355 while(req){
356 SCpnt = request_queueable(req,
357 rscsi_disks[DEVICE_NR(MINOR(req->dev))].device->index);
358 if(SCpnt) break;
359 req1 = req;
360 req = req->next;
361 };
362 if (SCpnt && req->dev == -1) {
363 if (req == CURRENT)
364 CURRENT = CURRENT->next;
365 else
366 req1->next = req->next;
367 };
368 sti();
369 };
370
371 if (!SCpnt) return;
372
373 wake_up(&wait_for_request);
374
375
376 requeue_sd_request(SCpnt);
377 };
378 }
379
380 static void requeue_sd_request (Scsi_Cmnd * SCpnt)
381 {
382 int dev, block, this_count;
383 unsigned char cmd[10];
384 char * buff;
385
386 repeat:
387
388 if(SCpnt->request.dev <= 0) {
389 do_sd_request();
390 return;
391 }
392
393 dev = MINOR(SCpnt->request.dev);
394 block = SCpnt->request.sector;
395 this_count = 0;
396
397 #ifdef DEBUG
398 printk("Doing sd request, dev = %d, block = %d\n", dev, block);
399 #endif
400
401 if (dev >= (NR_SD << 4) || block + SCpnt->request.nr_sectors > sd[dev].nr_sects)
402 {
403 end_scsi_request(SCpnt, 0, SCpnt->request.nr_sectors);
404 goto repeat;
405 }
406
407 block += sd[dev].start_sect;
408 dev = DEVICE_NR(dev);
409
410 if (rscsi_disks[dev].device->changed)
411 {
412
413
414
415
416 end_scsi_request(SCpnt, 0, SCpnt->request.nr_sectors);
417 goto repeat;
418 }
419
420 #ifdef DEBUG
421 printk("sd%d : real dev = /dev/sd%d, block = %d\n", MINOR(SCpnt->request.dev), dev, block);
422 #endif
423
424 switch (SCpnt->request.cmd)
425 {
426 case WRITE :
427 if (!rscsi_disks[dev].device->writeable)
428 {
429 end_scsi_request(SCpnt, 0, SCpnt->request.nr_sectors);
430 goto repeat;
431 }
432 cmd[0] = WRITE_6;
433 break;
434 case READ :
435 cmd[0] = READ_6;
436 break;
437 default :
438 panic ("Unknown sd command %d\n", SCpnt->request.cmd);
439 }
440
441 SCpnt->this_count = 0;
442
443 if (!SCpnt->request.bh ||
444 (SCpnt->request.nr_sectors == SCpnt->request.current_nr_sectors)) {
445
446
447 this_count = SCpnt->request.nr_sectors;
448 buff = SCpnt->request.buffer;
449 SCpnt->use_sg = 0;
450
451 } else if (SCpnt->host->sg_tablesize == 0 ||
452 (need_isa_buffer &&
453 dma_free_sectors < 10)) {
454
455
456
457
458
459
460
461
462 if (SCpnt->host->sg_tablesize != 0 &&
463 need_isa_buffer &&
464 dma_free_sectors < 10)
465 printk("Warning: SCSI DMA buffer space running low. Using non scatter-gather I/O.\n");
466
467 this_count = SCpnt->request.current_nr_sectors;
468 buff = SCpnt->request.buffer;
469 SCpnt->use_sg = 0;
470
471 } else {
472
473
474 struct buffer_head * bh;
475 struct scatterlist * sgpnt;
476 int count, this_count_max;
477 bh = SCpnt->request.bh;
478 this_count = 0;
479 this_count_max = (rscsi_disks[dev].ten ? 0xffff : 0xff);
480 count = 0;
481 while(bh && count < SCpnt->host->sg_tablesize) {
482 if ((this_count + (bh->b_size >> 9)) > this_count_max) break;
483 this_count += (bh->b_size >> 9);
484 count++;
485 bh = bh->b_reqnext;
486 };
487 SCpnt->use_sg = count;
488 count = 512;
489 while( count < (SCpnt->use_sg * sizeof(struct scatterlist)))
490 count = count << 1;
491 SCpnt->sglist_len = count;
492 sgpnt = (struct scatterlist * ) scsi_malloc(count);
493 if (!sgpnt) {
494 printk("Warning - running *really* short on DMA buffers\n");
495 SCpnt->use_sg = 0;
496 this_count = SCpnt->request.current_nr_sectors;
497 buff = SCpnt->request.buffer;
498 } else {
499 buff = (char *) sgpnt;
500 count = 0;
501 bh = SCpnt->request.bh;
502 for(count = 0, bh = SCpnt->request.bh; count < SCpnt->use_sg;
503 count++, bh = bh->b_reqnext) {
504 sgpnt[count].address = bh->b_data;
505 sgpnt[count].alt_address = NULL;
506 sgpnt[count].length = bh->b_size;
507 if (((int) sgpnt[count].address) + sgpnt[count].length >
508 ISA_DMA_THRESHOLD & (SCpnt->host->unchecked_isa_dma)) {
509 sgpnt[count].alt_address = sgpnt[count].address;
510
511
512
513 if(dma_free_sectors < (bh->b_size >> 9) + 5) {
514 sgpnt[count].address = NULL;
515 } else {
516 sgpnt[count].address = (char *) scsi_malloc(sgpnt[count].length);
517 };
518
519
520
521
522 if(sgpnt[count].address == NULL){
523 printk("Warning: Running low on SCSI DMA buffers");
524
525 while(--count >= 0){
526 if(sgpnt[count].alt_address)
527 scsi_free(sgpnt[count].address, sgpnt[count].length);
528 };
529 this_count = SCpnt->request.current_nr_sectors;
530 buff = SCpnt->request.buffer;
531 SCpnt->use_sg = 0;
532 scsi_free(buff, SCpnt->sglist_len);
533 break;
534 };
535
536 if (SCpnt->request.cmd == WRITE)
537 memcpy(sgpnt[count].address, sgpnt[count].alt_address,
538 sgpnt[count].length);
539 };
540 };
541 };
542 };
543
544
545
546 if(SCpnt->use_sg == 0){
547 if (((int) buff) + (this_count << 9) > ISA_DMA_THRESHOLD &&
548 (SCpnt->host->unchecked_isa_dma)) {
549 buff = (char *) scsi_malloc(this_count << 9);
550 if(buff == NULL) panic("Ran out of DMA buffers.");
551 if (SCpnt->request.cmd == WRITE)
552 memcpy(buff, (char *)SCpnt->request.buffer, this_count << 9);
553 };
554 };
555
556 #ifdef DEBUG
557 printk("sd%d : %s %d/%d 512 byte blocks.\n", MINOR(SCpnt->request.dev),
558 (SCpnt->request.cmd == WRITE) ? "writing" : "reading",
559 this_count, SCpnt->request.nr_sectors);
560 #endif
561
562 cmd[1] = (SCpnt->lun << 5) & 0xe0;
563
564 if (rscsi_disks[dev].sector_size == 1024){
565 if(block & 1) panic("sd.c:Bad block number requested");
566 if(this_count & 1) panic("sd.c:Bad block number requested");
567 block = block >> 1;
568 this_count = this_count >> 1;
569 };
570
571 if (rscsi_disks[dev].sector_size == 256){
572 block = block << 1;
573 this_count = this_count << 1;
574 };
575
576 if (((this_count > 0xff) || (block > 0x1fffff)) && rscsi_disks[dev].ten)
577 {
578 if (this_count > 0xffff)
579 this_count = 0xffff;
580
581 cmd[0] += READ_10 - READ_6 ;
582 cmd[2] = (unsigned char) (block >> 24) & 0xff;
583 cmd[3] = (unsigned char) (block >> 16) & 0xff;
584 cmd[4] = (unsigned char) (block >> 8) & 0xff;
585 cmd[5] = (unsigned char) block & 0xff;
586 cmd[6] = cmd[9] = 0;
587 cmd[7] = (unsigned char) (this_count >> 8) & 0xff;
588 cmd[8] = (unsigned char) this_count & 0xff;
589 }
590 else
591 {
592 if (this_count > 0xff)
593 this_count = 0xff;
594
595 cmd[1] |= (unsigned char) ((block >> 16) & 0x1f);
596 cmd[2] = (unsigned char) ((block >> 8) & 0xff);
597 cmd[3] = (unsigned char) block & 0xff;
598 cmd[4] = (unsigned char) this_count;
599 cmd[5] = 0;
600 }
601
602
603
604
605
606
607
608 SCpnt->transfersize = rscsi_disks[dev].sector_size;
609 SCpnt->underflow = this_count << 9;
610
611 scsi_do_cmd (SCpnt, (void *) cmd, buff,
612 this_count * rscsi_disks[dev].sector_size,
613 rw_intr, SD_TIMEOUT, MAX_RETRIES);
614 }
615
616 int check_scsidisk_media_change(int full_dev, int flag){
617 int retval;
618 int target;
619 struct inode inode;
620
621 target = DEVICE_NR(MINOR(full_dev));
622
623 if (target >= NR_SD) {
624 printk("SCSI disk request error: invalid device.\n");
625 return 0;
626 };
627
628 if(!rscsi_disks[target].device->removable) return 0;
629
630 inode.i_rdev = full_dev;
631 retval = sd_ioctl(&inode, NULL, SCSI_IOCTL_TEST_UNIT_READY, 0);
632
633 if(retval){
634
635
636
637
638 rscsi_disks[target].device->changed = 1;
639 return 1;
640
641 };
642
643 retval = rscsi_disks[target].device->changed;
644 if(!flag) rscsi_disks[target].device->changed = 0;
645 return retval;
646 }
647
648 static void sd_init_done (Scsi_Cmnd * SCpnt)
649 {
650 struct request * req;
651 struct task_struct * p;
652
653 req = &SCpnt->request;
654 req->dev = 0xfffe;
655
656 if ((p = req->waiting) != NULL) {
657 req->waiting = NULL;
658 p->state = TASK_RUNNING;
659 if (p->counter > current->counter)
660 need_resched = 1;
661 }
662 }
663
664 static int sd_init_onedisk(int i)
665 {
666 int j = 0;
667 unsigned char cmd[10];
668 unsigned char *buffer;
669 char spintime;
670 int the_result, retries;
671 Scsi_Cmnd * SCpnt;
672
673
674
675
676
677 SCpnt = allocate_device(NULL, rscsi_disks[i].device->index, 1);
678 buffer = (unsigned char *) scsi_malloc(512);
679
680 spintime = 0;
681
682
683 if (current == task[0]){
684 do{
685 cmd[0] = TEST_UNIT_READY;
686 cmd[1] = (rscsi_disks[i].device->lun << 5) & 0xe0;
687 memset ((void *) &cmd[2], 0, 8);
688 SCpnt->request.dev = 0xffff;
689 SCpnt->sense_buffer[0] = 0;
690 SCpnt->sense_buffer[2] = 0;
691
692 scsi_do_cmd (SCpnt,
693 (void *) cmd, (void *) buffer,
694 512, sd_init_done, SD_TIMEOUT,
695 MAX_RETRIES);
696
697 while(SCpnt->request.dev != 0xfffe);
698
699 the_result = SCpnt->result;
700
701
702
703 if(the_result && !rscsi_disks[i].device->removable &&
704 SCpnt->sense_buffer[2] == NOT_READY) {
705 int time1;
706 if(!spintime){
707 printk( "sd%d: Spinning up disk...", i );
708 cmd[0] = START_STOP;
709 cmd[1] = (rscsi_disks[i].device->lun << 5) & 0xe0;
710 cmd[1] |= 1;
711 memset ((void *) &cmd[2], 0, 8);
712 cmd[4] = 1;
713 SCpnt->request.dev = 0xffff;
714 SCpnt->sense_buffer[0] = 0;
715 SCpnt->sense_buffer[2] = 0;
716
717 scsi_do_cmd (SCpnt,
718 (void *) cmd, (void *) buffer,
719 512, sd_init_done, SD_TIMEOUT,
720 MAX_RETRIES);
721
722 while(SCpnt->request.dev != 0xfffe);
723
724 spintime = jiffies;
725 };
726
727 time1 = jiffies;
728 while(jiffies < time1 + 100);
729 printk( "." );
730 };
731 } while(the_result && spintime && spintime+5000 > jiffies);
732 if (spintime) {
733 if (the_result)
734 printk( "not responding...\n" );
735 else
736 printk( "ready\n" );
737 }
738 };
739
740
741 retries = 3;
742 do {
743 cmd[0] = READ_CAPACITY;
744 cmd[1] = (rscsi_disks[i].device->lun << 5) & 0xe0;
745 memset ((void *) &cmd[2], 0, 8);
746 memset ((void *) buffer, 0, 8);
747 SCpnt->request.dev = 0xffff;
748 SCpnt->sense_buffer[0] = 0;
749 SCpnt->sense_buffer[2] = 0;
750
751 scsi_do_cmd (SCpnt,
752 (void *) cmd, (void *) buffer,
753 8, sd_init_done, SD_TIMEOUT,
754 MAX_RETRIES);
755
756 if (current == task[0])
757 while(SCpnt->request.dev != 0xfffe);
758 else
759 if (SCpnt->request.dev != 0xfffe){
760 SCpnt->request.waiting = current;
761 current->state = TASK_UNINTERRUPTIBLE;
762 while (SCpnt->request.dev != 0xfffe) schedule();
763 };
764
765 the_result = SCpnt->result;
766 retries--;
767
768 } while(the_result && retries);
769
770 SCpnt->request.dev = -1;
771
772 wake_up(&scsi_devices[SCpnt->index].device_wait);
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789 if (the_result)
790 {
791 printk ("sd%d : READ CAPACITY failed.\n"
792 "sd%d : status = %x, message = %02x, host = %d, driver = %02x \n",
793 i,i,
794 status_byte(the_result),
795 msg_byte(the_result),
796 host_byte(the_result),
797 driver_byte(the_result)
798 );
799 if (driver_byte(the_result) & DRIVER_SENSE)
800 printk("sd%d : extended sense code = %1x \n", i, SCpnt->sense_buffer[2] & 0xf);
801 else
802 printk("sd%d : sense not available. \n", i);
803
804 printk("sd%d : block size assumed to be 512 bytes, disk size 1GB. \n", i);
805 rscsi_disks[i].capacity = 0x1fffff;
806 rscsi_disks[i].sector_size = 512;
807
808
809
810 if(rscsi_disks[i].device->removable &&
811 SCpnt->sense_buffer[2] == NOT_READY)
812 rscsi_disks[i].device->changed = 1;
813
814 }
815 else
816 {
817 rscsi_disks[i].capacity = (buffer[0] << 24) |
818 (buffer[1] << 16) |
819 (buffer[2] << 8) |
820 buffer[3];
821
822 rscsi_disks[i].sector_size = (buffer[4] << 24) |
823 (buffer[5] << 16) | (buffer[6] << 8) | buffer[7];
824
825 if (rscsi_disks[i].sector_size != 512 &&
826 rscsi_disks[i].sector_size != 1024 &&
827 rscsi_disks[i].sector_size != 256)
828 {
829 printk ("sd%d : unsupported sector size %d.\n",
830 i, rscsi_disks[i].sector_size);
831 if(rscsi_disks[i].device->removable){
832 rscsi_disks[i].capacity = 0;
833 } else {
834 printk ("scsi : deleting disk entry.\n");
835 for (j=i; j < NR_SD - 1;)
836 rscsi_disks[j] = rscsi_disks[++j];
837 --i;
838 --NR_SD;
839 scsi_free(buffer, 512);
840 return i;
841 };
842 }
843 if(rscsi_disks[i].sector_size == 1024)
844 rscsi_disks[i].capacity <<= 1;
845 if(rscsi_disks[i].sector_size == 256)
846 rscsi_disks[i].capacity >>= 1;
847 }
848
849 rscsi_disks[i].ten = 1;
850 rscsi_disks[i].remap = 1;
851 scsi_free(buffer, 512);
852 return i;
853 }
854
855
856
857
858
859
860 unsigned long sd_init(unsigned long memory_start, unsigned long memory_end)
861 {
862 int i;
863
864 if (register_blkdev(MAJOR_NR,"sd",&sd_fops)) {
865 printk("Unable to get major %d for SCSI disk\n",MAJOR_NR);
866 return memory_start;
867 }
868 if (MAX_SD == 0) return memory_start;
869
870 sd_sizes = (int *) memory_start;
871 memory_start += (MAX_SD << 4) * sizeof(int);
872 memset(sd_sizes, 0, (MAX_SD << 4) * sizeof(int));
873
874 sd_blocksizes = (int *) memory_start;
875 memory_start += (MAX_SD << 4) * sizeof(int);
876 for(i=0;i<(MAX_SD << 4);i++) sd_blocksizes[i] = 1024;
877 blksize_size[MAJOR_NR] = sd_blocksizes;
878
879 sd = (struct hd_struct *) memory_start;
880 memory_start += (MAX_SD << 4) * sizeof(struct hd_struct);
881
882 sd_gendisk.max_nr = MAX_SD;
883 sd_gendisk.part = sd;
884 sd_gendisk.sizes = sd_sizes;
885 sd_gendisk.real_devices = (void *) rscsi_disks;
886
887 for (i = 0; i < NR_SD; ++i)
888 i = sd_init_onedisk(i);
889
890 blk_dev[MAJOR_NR].request_fn = DEVICE_REQUEST;
891
892
893
894
895 if(rscsi_disks[0].device->host->sg_tablesize)
896 read_ahead[MAJOR_NR] = 32;
897
898 else
899 read_ahead[MAJOR_NR] = 4;
900
901 sd_gendisk.next = gendisk_head;
902 gendisk_head = &sd_gendisk;
903 return memory_start;
904 }
905
906 unsigned long sd_init1(unsigned long mem_start, unsigned long mem_end){
907 rscsi_disks = (Scsi_Disk *) mem_start;
908 mem_start += MAX_SD * sizeof(Scsi_Disk);
909 return mem_start;
910 };
911
912 void sd_attach(Scsi_Device * SDp){
913 rscsi_disks[NR_SD++].device = SDp;
914 if(NR_SD > MAX_SD) panic ("scsi_devices corrupt (sd)");
915 };
916
917 #define DEVICE_BUSY rscsi_disks[target].device->busy
918 #define USAGE rscsi_disks[target].device->access_count
919 #define CAPACITY rscsi_disks[target].capacity
920 #define MAYBE_REINIT sd_init_onedisk(target)
921 #define GENDISK_STRUCT sd_gendisk
922
923
924
925
926
927
928
929
930 int revalidate_scsidisk(int dev, int maxusage){
931 int target, major;
932 struct gendisk * gdev;
933 int max_p;
934 int start;
935 int i;
936
937 target = DEVICE_NR(MINOR(dev));
938 gdev = &GENDISK_STRUCT;
939
940 cli();
941 if (DEVICE_BUSY || USAGE > maxusage) {
942 sti();
943 printk("Device busy for revalidation (usage=%d)\n", USAGE);
944 return -EBUSY;
945 };
946 DEVICE_BUSY = 1;
947 sti();
948
949 max_p = gdev->max_p;
950 start = target << gdev->minor_shift;
951 major = MAJOR_NR << 8;
952
953 for (i=max_p - 1; i >=0 ; i--) {
954 sync_dev(major | start | i);
955 invalidate_inodes(major | start | i);
956 invalidate_buffers(major | start | i);
957 gdev->part[start+i].start_sect = 0;
958 gdev->part[start+i].nr_sects = 0;
959 };
960
961 #ifdef MAYBE_REINIT
962 MAYBE_REINIT;
963 #endif
964
965 gdev->part[start].nr_sects = CAPACITY;
966 resetup_one_dev(gdev, target);
967
968 DEVICE_BUSY = 0;
969 return 0;
970 }