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 extern int sd_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
53
54 static sd_init_onedisk(int);
55
56 static void requeue_sd_request (Scsi_Cmnd * SCpnt);
57
58 static int sd_open(struct inode * inode, struct file * filp)
59 {
60 int target;
61 target = DEVICE_NR(MINOR(inode->i_rdev));
62
63 if(target >= NR_SD || !rscsi_disks[target].device)
64 return -ENODEV;
65
66
67
68
69 while (rscsi_disks[target].device->busy);
70
71 if(rscsi_disks[target].device->removable) {
72 check_disk_change(inode->i_rdev);
73
74 if(!rscsi_disks[target].device->access_count)
75 sd_ioctl(inode, NULL, SCSI_IOCTL_DOORLOCK, 0);
76 };
77 rscsi_disks[target].device->access_count++;
78 return 0;
79 }
80
81 static void sd_release(struct inode * inode, struct file * file)
82 {
83 int target;
84 sync_dev(inode->i_rdev);
85
86 target = DEVICE_NR(MINOR(inode->i_rdev));
87
88 rscsi_disks[target].device->access_count--;
89
90 if(rscsi_disks[target].device->removable) {
91 if(!rscsi_disks[target].device->access_count)
92 sd_ioctl(inode, NULL, SCSI_IOCTL_DOORUNLOCK, 0);
93 };
94 }
95
96 static void sd_geninit(void);
97
98 static struct file_operations sd_fops = {
99 NULL,
100 block_read,
101 block_write,
102 NULL,
103 NULL,
104 sd_ioctl,
105 NULL,
106 sd_open,
107 sd_release,
108 block_fsync
109 };
110
111 static struct gendisk sd_gendisk = {
112 MAJOR_NR,
113 "sd",
114 4,
115 1 << 4,
116 0,
117 sd_geninit,
118 NULL,
119 NULL,
120 0,
121 NULL,
122 NULL
123 };
124
125 static void sd_geninit (void)
126 {
127 int i;
128
129 for (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 if (sugestion(result) == SUGGEST_REMAP) {
249 #ifdef REMAP
250
251
252
253
254 if rscsi_disks[DEVICE_NR(SCpnt->request.dev)].remap
255 {
256 result = 0;
257 }
258 else
259
260 #endif
261 }
262
263 if ((SCpnt->sense_buffer[0] & 0x7f) == 0x70) {
264 if ((SCpnt->sense_buffer[2] & 0xf) == UNIT_ATTENTION) {
265
266
267
268 rscsi_disks[DEVICE_NR(SCpnt->request.dev)].device->changed = 1;
269 end_scsi_request(SCpnt, 0, this_count);
270 requeue_sd_request(SCpnt);
271 return;
272 }
273 }
274
275
276
277
278
279
280
281
282
283 if (SCpnt->sense_buffer[2] == ILLEGAL_REQUEST) {
284 if (rscsi_disks[DEVICE_NR(SCpnt->request.dev)].ten) {
285 rscsi_disks[DEVICE_NR(SCpnt->request.dev)].ten = 0;
286 requeue_sd_request(SCpnt);
287 result = 0;
288 } else {
289 }
290 }
291 }
292 if (result) {
293 printk("SCSI disk error : host %d id %d lun %d return code = %x\n",
294 rscsi_disks[DEVICE_NR(SCpnt->request.dev)].device->host_no,
295 rscsi_disks[DEVICE_NR(SCpnt->request.dev)].device->id,
296 rscsi_disks[DEVICE_NR(SCpnt->request.dev)].device->lun, result);
297
298 if (driver_byte(result) & DRIVER_SENSE)
299 print_sense("sd", SCpnt);
300 end_scsi_request(SCpnt, 0, SCpnt->request.current_nr_sectors);
301 requeue_sd_request(SCpnt);
302 return;
303 }
304 }
305
306
307
308
309
310
311
312 static void do_sd_request (void)
313 {
314 Scsi_Cmnd * SCpnt = NULL;
315 struct request * req = NULL;
316 int flag = 0;
317 while (1==1){
318 cli();
319 if (CURRENT != NULL && CURRENT->dev == -1) {
320 sti();
321 return;
322 };
323
324 INIT_SCSI_REQUEST;
325
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 char spintime;
672 int the_result, retries;
673 Scsi_Cmnd * SCpnt;
674
675
676
677
678
679 SCpnt = allocate_device(NULL, rscsi_disks[i].device->index, 1);
680 buffer = (unsigned char *) scsi_malloc(512);
681
682 spintime = 0;
683
684
685 if (current == task[0]){
686 do{
687 cmd[0] = TEST_UNIT_READY;
688 cmd[1] = (rscsi_disks[i].device->lun << 5) & 0xe0;
689 memset ((void *) &cmd[2], 0, 8);
690 SCpnt->request.dev = 0xffff;
691 SCpnt->sense_buffer[0] = 0;
692 SCpnt->sense_buffer[2] = 0;
693
694 scsi_do_cmd (SCpnt,
695 (void *) cmd, (void *) buffer,
696 512, sd_init_done, SD_TIMEOUT,
697 MAX_RETRIES);
698
699 while(SCpnt->request.dev != 0xfffe);
700
701 the_result = SCpnt->result;
702
703
704
705 if(the_result && !rscsi_disks[i].device->removable &&
706 SCpnt->sense_buffer[2] == NOT_READY) {
707 int time1;
708 if(!spintime){
709 cmd[0] = START_STOP;
710 cmd[1] = (rscsi_disks[i].device->lun << 5) & 0xe0;
711 cmd[1] |= 1;
712 memset ((void *) &cmd[2], 0, 8);
713 cmd[4] = 1;
714 SCpnt->request.dev = 0xffff;
715 SCpnt->sense_buffer[0] = 0;
716 SCpnt->sense_buffer[2] = 0;
717
718 scsi_do_cmd (SCpnt,
719 (void *) cmd, (void *) buffer,
720 512, sd_init_done, SD_TIMEOUT,
721 MAX_RETRIES);
722
723 while(SCpnt->request.dev != 0xfffe);
724
725 spintime = jiffies;
726 };
727
728 time1 = jiffies;
729 while(jiffies < time1 + 100);
730 };
731 } while(the_result && spintime && spintime+1500 < jiffies);
732 };
733
734
735 retries = 3;
736 do {
737 cmd[0] = READ_CAPACITY;
738 cmd[1] = (rscsi_disks[i].device->lun << 5) & 0xe0;
739 memset ((void *) &cmd[2], 0, 8);
740 memset ((void *) buffer, 0, 8);
741 SCpnt->request.dev = 0xffff;
742 SCpnt->sense_buffer[0] = 0;
743 SCpnt->sense_buffer[2] = 0;
744
745 scsi_do_cmd (SCpnt,
746 (void *) cmd, (void *) buffer,
747 8, sd_init_done, SD_TIMEOUT,
748 MAX_RETRIES);
749
750 if (current == task[0])
751 while(SCpnt->request.dev != 0xfffe);
752 else
753 if (SCpnt->request.dev != 0xfffe){
754 SCpnt->request.waiting = current;
755 current->state = TASK_UNINTERRUPTIBLE;
756 while (SCpnt->request.dev != 0xfffe) schedule();
757 };
758
759 the_result = SCpnt->result;
760 retries--;
761
762 } while(the_result && retries);
763
764 SCpnt->request.dev = -1;
765
766 wake_up(&scsi_devices[SCpnt->index].device_wait);
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783 if (the_result)
784 {
785 printk ("sd%d : READ CAPACITY failed.\n"
786 "sd%d : status = %x, message = %02x, host = %02x, driver = %02x \n",
787 i,i,
788 rscsi_disks[i].device->host_no, rscsi_disks[i].device->id,
789 rscsi_disks[i].device->lun,
790 status_byte(the_result),
791 msg_byte(the_result),
792 host_byte(the_result),
793 driver_byte(the_result)
794 );
795 if (driver_byte(the_result) & DRIVER_SENSE)
796 printk("sd%d : extended sense code = %1x \n", i, SCpnt->sense_buffer[2] & 0xf);
797 else
798 printk("sd%d : sense not available. \n", i);
799
800 printk("sd%d : block size assumed to be 512 bytes, disk size 1GB. \n", i);
801 rscsi_disks[i].capacity = 0x1fffff;
802 rscsi_disks[i].sector_size = 512;
803
804
805
806 if(rscsi_disks[i].device->removable &&
807 SCpnt->sense_buffer[2] == NOT_READY)
808 rscsi_disks[i].device->changed = 1;
809
810 }
811 else
812 {
813 rscsi_disks[i].capacity = (buffer[0] << 24) |
814 (buffer[1] << 16) |
815 (buffer[2] << 8) |
816 buffer[3];
817
818 rscsi_disks[i].sector_size = (buffer[4] << 24) |
819 (buffer[5] << 16) | (buffer[6] << 8) | buffer[7];
820
821 if (rscsi_disks[i].sector_size != 512 &&
822 rscsi_disks[i].sector_size != 1024 &&
823 rscsi_disks[i].sector_size != 256)
824 {
825 printk ("sd%d : unsupported sector size %d.\n",
826 i, rscsi_disks[i].sector_size);
827 if(rscsi_disks[i].device->removable){
828 rscsi_disks[i].capacity = 0;
829 } else {
830 printk ("scsi : deleting disk entry.\n");
831 for (j=i; j < NR_SD - 1;)
832 rscsi_disks[j] = rscsi_disks[++j];
833 --i;
834 --NR_SD;
835 scsi_free(buffer, 512);
836 return i;
837 };
838 }
839 if(rscsi_disks[i].sector_size == 1024)
840 rscsi_disks[i].capacity <<= 1;
841 if(rscsi_disks[i].sector_size == 256)
842 rscsi_disks[i].capacity >>= 1;
843 }
844
845 rscsi_disks[i].ten = 1;
846 rscsi_disks[i].remap = 1;
847 scsi_free(buffer, 512);
848 return i;
849 }
850
851
852
853
854
855
856 unsigned long sd_init(unsigned long memory_start, unsigned long memory_end)
857 {
858 int i;
859
860 if (register_blkdev(MAJOR_NR,"sd",&sd_fops)) {
861 printk("Unable to get major %d for SCSI disk\n",MAJOR_NR);
862 return memory_start;
863 }
864 if (MAX_SD == 0) return memory_start;
865
866 sd_sizes = (int *) memory_start;
867 memory_start += (MAX_SD << 4) * sizeof(int);
868 memset(sd_sizes, 0, (MAX_SD << 4) * sizeof(int));
869
870 sd_blocksizes = (int *) memory_start;
871 memory_start += (MAX_SD << 4) * sizeof(int);
872 for(i=0;i<(MAX_SD << 4);i++) sd_blocksizes[i] = 1024;
873 blksize_size[MAJOR_NR] = sd_blocksizes;
874
875 sd = (struct hd_struct *) memory_start;
876 memory_start += (MAX_SD << 4) * sizeof(struct hd_struct);
877
878 sd_gendisk.max_nr = MAX_SD;
879 sd_gendisk.part = sd;
880 sd_gendisk.sizes = sd_sizes;
881 sd_gendisk.real_devices = (void *) rscsi_disks;
882
883 for (i = 0; i < NR_SD; ++i)
884 i = sd_init_onedisk(i);
885
886 blk_dev[MAJOR_NR].request_fn = DEVICE_REQUEST;
887
888
889
890
891 if(scsi_hosts[rscsi_disks[0].device->host_no].sg_tablesize)
892 read_ahead[MAJOR_NR] = 16;
893 else
894 read_ahead[MAJOR_NR] = 4;
895
896 sd_gendisk.next = gendisk_head;
897 gendisk_head = &sd_gendisk;
898 return memory_start;
899 }
900
901 unsigned long sd_init1(unsigned long mem_start, unsigned long mem_end){
902 rscsi_disks = (Scsi_Disk *) mem_start;
903 mem_start += MAX_SD * sizeof(Scsi_Disk);
904 return mem_start;
905 };
906
907 void sd_attach(Scsi_Device * SDp){
908 rscsi_disks[NR_SD++].device = SDp;
909 if(NR_SD > MAX_SD) panic ("scsi_devices corrupt (sd)");
910 };
911
912 #define DEVICE_BUSY rscsi_disks[target].device->busy
913 #define USAGE rscsi_disks[target].device->access_count
914 #define CAPACITY rscsi_disks[target].capacity
915 #define MAYBE_REINIT sd_init_onedisk(target)
916 #define GENDISK_STRUCT sd_gendisk
917
918
919
920
921
922
923
924
925 int revalidate_scsidisk(int dev, int maxusage){
926 int target, major;
927 struct gendisk * gdev;
928 int max_p;
929 int start;
930 int i;
931
932 target = DEVICE_NR(MINOR(dev));
933 gdev = &GENDISK_STRUCT;
934
935 cli();
936 if (DEVICE_BUSY || USAGE > maxusage) {
937 sti();
938 printk("Device busy for revalidation (usage=%d)\n", USAGE);
939 return -EBUSY;
940 };
941 DEVICE_BUSY = 1;
942 sti();
943
944 max_p = gdev->max_p;
945 start = target << gdev->minor_shift;
946 major = MAJOR_NR << 8;
947
948 for (i=max_p - 1; i >=0 ; i--) {
949 sync_dev(major | start | i);
950 invalidate_inodes(major | start | i);
951 invalidate_buffers(major | start | i);
952 gdev->part[start+i].start_sect = 0;
953 gdev->part[start+i].nr_sects = 0;
954 };
955
956 #ifdef MAYBE_REINIT
957 MAYBE_REINIT;
958 #endif
959
960 gdev->part[start].nr_sects = CAPACITY;
961 resetup_one_dev(gdev, target);
962
963 DEVICE_BUSY = 0;
964 return 0;
965 }