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