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