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