2 pd.c (c) 1997-8 Grant R. Guenther <grant@torque.net>
3 Under the terms of the GNU public license.
5 This is the high-level driver for parallel port IDE hard
6 drives based on chips supported by the paride module.
8 By default, the driver will autoprobe for a single parallel
9 port IDE drive, but if their individual parameters are
10 specified, the driver can handle up to 4 drives.
12 The behaviour of the pd driver can be altered by setting
13 some parameters from the insmod command line. The following
14 parameters are adjustable:
16 drive0 These four arguments can be arrays of
17 drive1 1-8 integers as follows:
19 drive3 <prt>,<pro>,<uni>,<mod>,<geo>,<sby>,<dly>,<slv>
23 <prt> is the base of the parallel port address for
24 the corresponding drive. (required)
26 <pro> is the protocol number for the adapter that
27 supports this drive. These numbers are
28 logged by 'paride' when the protocol modules
29 are initialised. (0 if not given)
31 <uni> for those adapters that support chained
32 devices, this is the unit selector for the
33 chain of devices on the given port. It should
34 be zero for devices that don't support chaining.
37 <mod> this can be -1 to choose the best mode, or one
38 of the mode numbers supported by the adapter.
41 <geo> this defaults to 0 to indicate that the driver
42 should use the CHS geometry provided by the drive
43 itself. If set to 1, the driver will provide
44 a logical geometry with 64 heads and 32 sectors
45 per track, to be consistent with most SCSI
46 drivers. (0 if not given)
48 <sby> set this to zero to disable the power saving
49 standby mode, if needed. (1 if not given)
51 <dly> some parallel ports require the driver to
52 go more slowly. -1 sets a default value that
53 should work with the chosen protocol. Otherwise,
54 set this to a small integer, the larger it is
55 the slower the port i/o. In some cases, setting
56 this to zero will speed up the device. (default -1)
58 <slv> IDE disks can be jumpered to master or slave.
59 Set this to 0 to choose the master drive, 1 to
60 choose the slave, -1 (the default) to choose the
64 major You may use this parameter to overide the
65 default major number (45) that this driver
66 will use. Be sure to change the device
69 name This parameter is a character string that
70 contains the name the kernel will use for this
71 device (in /proc output, for instance).
74 cluster The driver will attempt to aggregate requests
75 for adjacent blocks into larger multi-block
76 clusters. The maximum cluster size (in 512
77 byte sectors) is set with this parameter.
80 verbose This parameter controls the amount of logging
81 that the driver will do. Set it to 0 for
82 normal operation, 1 to see autoprobe progress
83 messages, or 2 to see additional debugging
86 nice This parameter controls the driver's use of
87 idle CPU time, at the expense of some speed.
89 If this driver is built into the kernel, you can use kernel
90 the following command line parameters, with the same values
91 as the corresponding module parameters listed above:
100 In addition, you can use the parameter pd.disable to disable
107 1.01 GRG 1997.01.24 Restored pd_reset()
109 1.02 GRG 1998.05.06 SMP spinlock changes,
111 1.03 GRG 1998.06.16 Eliminate an Ugh.
112 1.04 GRG 1998.08.15 Extra debugging, use HZ in loop timing
116 #define PD_VERSION "1.04"
121 /* Here are things one can override from the insmod command.
122 Most are autoprobed by paride unless set here. Verbose is off
127 static int verbose
= 0;
128 static int major
= PD_MAJOR
;
129 static char *name
= PD_NAME
;
130 static int cluster
= 64;
132 static int disable
= 0;
134 static int drive0
[8] = {0,0,0,-1,0,1,-1,-1};
135 static int drive1
[8] = {0,0,0,-1,0,1,-1,-1};
136 static int drive2
[8] = {0,0,0,-1,0,1,-1,-1};
137 static int drive3
[8] = {0,0,0,-1,0,1,-1,-1};
139 static int (*drives
[4])[8] = {&drive0
,&drive1
,&drive2
,&drive3
};
140 static int pd_drive_count
;
151 #define DU (*drives[unit])
153 /* end of parameters */
155 #include <linux/module.h>
156 #include <linux/errno.h>
157 #include <linux/fs.h>
158 #include <linux/kernel.h>
159 #include <linux/delay.h>
160 #include <linux/genhd.h>
161 #include <linux/hdreg.h>
162 #include <linux/cdrom.h> /* for the eject ioctl */
164 #include <asm/spinlock.h>
165 #include <asm/uaccess.h>
171 static STT pd_stt
[7] = {{"drive0",8,drive0
},
175 {"disable",1,&disable
},
176 {"cluster",1,&cluster
},
179 void pd_setup( char *str
, int *ints
)
181 { generic_setup(pd_stt
,7,str
);
186 MODULE_PARM(verbose
,"i");
187 MODULE_PARM(major
,"i");
188 MODULE_PARM(name
,"s");
189 MODULE_PARM(cluster
,"i");
190 MODULE_PARM(nice
,"i");
191 MODULE_PARM(drive0
,"1-8i");
192 MODULE_PARM(drive1
,"1-8i");
193 MODULE_PARM(drive2
,"1-8i");
194 MODULE_PARM(drive3
,"1-8i");
200 /* set up defines for blk.h, why don't all drivers do it this way ? */
202 #define MAJOR_NR major
203 #define DEVICE_NAME "PD"
204 #define DEVICE_REQUEST do_pd_request
205 #define DEVICE_NR(device) (MINOR(device)>>PD_BITS)
206 #define DEVICE_ON(device)
207 #define DEVICE_OFF(device)
209 #include <linux/blk.h>
213 #define PD_PARTNS (1<<PD_BITS)
214 #define PD_DEVS PD_PARTNS*PD_UNITS
216 /* numbers for "SCSI" geometry */
218 #define PD_LOG_HEADS 64
219 #define PD_LOG_SECTS 32
224 #define PD_MAX_RETRIES 5
225 #define PD_TMO 800 /* interrupt timeout in jiffies */
226 #define PD_SPIN_DEL 50 /* spin delay in micro-seconds */
228 #define PD_SPIN (1000000*PD_TMO)/(HZ*PD_SPIN_DEL)
230 #define STAT_ERR 0x00001
231 #define STAT_INDEX 0x00002
232 #define STAT_ECC 0x00004
233 #define STAT_DRQ 0x00008
234 #define STAT_SEEK 0x00010
235 #define STAT_WRERR 0x00020
236 #define STAT_READY 0x00040
237 #define STAT_BUSY 0x00080
239 #define ERR_AMNF 0x00100
240 #define ERR_TK0NF 0x00200
241 #define ERR_ABRT 0x00400
242 #define ERR_MCR 0x00800
243 #define ERR_IDNF 0x01000
244 #define ERR_MC 0x02000
245 #define ERR_UNC 0x04000
246 #define ERR_TMO 0x10000
248 #define IDE_READ 0x20
249 #define IDE_WRITE 0x30
250 #define IDE_READ_VRFY 0x40
251 #define IDE_INIT_DEV_PARMS 0x91
252 #define IDE_STANDBY 0x96
253 #define IDE_ACKCHANGE 0xdb
254 #define IDE_DOORLOCK 0xde
255 #define IDE_DOORUNLOCK 0xdf
256 #define IDE_IDENTIFY 0xec
257 #define IDE_EJECT 0xed
260 void pd_setup(char * str
, int * ints
);
262 void cleanup_module( void );
264 static void pd_geninit(struct gendisk
*ignored
);
265 static int pd_open(struct inode
*inode
, struct file
*file
);
266 static void do_pd_request(void);
267 static int pd_ioctl(struct inode
*inode
,struct file
*file
,
268 unsigned int cmd
, unsigned long arg
);
269 static int pd_release (struct inode
*inode
, struct file
*file
);
270 static int pd_revalidate(kdev_t dev
);
271 static int pd_detect(void);
272 static void do_pd_read(void);
273 static void do_pd_read_start(void);
274 static void do_pd_write(void);
275 static void do_pd_write_start(void);
276 static void do_pd_read_drq( void );
277 static void do_pd_write_done( void );
279 static int pd_identify (int unit
);
280 static void pd_media_check(int unit
);
281 static void pd_doorlock(int unit
, int func
);
282 static int pd_check_media(kdev_t dev
);
283 static void pd_eject( int unit
);
285 static struct hd_struct pd_hd
[PD_DEVS
];
286 static int pd_sizes
[PD_DEVS
];
287 static int pd_blocksizes
[PD_DEVS
];
292 struct pi_adapter pia
; /* interface to paride layer */
293 struct pi_adapter
*pi
;
294 int access
; /* count of active opens ... */
295 int capacity
; /* Size of this volume in sectors */
296 int heads
; /* physical geometry */
299 int drive
; /* master=0 slave=1 */
300 int changed
; /* Have we seen a disk change ? */
301 int removable
; /* removable media device ? */
305 char name
[PD_NAMELEN
]; /* pda, pdb, etc ... */
308 struct pd_unit pd
[PD_UNITS
];
310 /* 'unit' must be defined in all functions - either as a local or a param */
315 static int pd_valid
= 1; /* serialise partition checks */
316 static char pd_scratch
[512]; /* scratch block buffer */
318 /* the variables below are used mainly in the I/O request engine, which
319 processes only one request at a time.
322 static int pd_retries
= 0; /* i/o error retry count */
323 static int pd_busy
= 0; /* request being processed ? */
324 static int pd_block
; /* address of next requested block */
325 static int pd_count
; /* number of blocks still to do */
326 static int pd_run
; /* sectors in current cluster */
327 static int pd_cmd
; /* current command READ/WRITE */
328 static int pd_unit
; /* unit of current request */
329 static int pd_dev
; /* minor of current request */
330 static int pd_poffs
; /* partition offset of current minor */
331 static char * pd_buf
; /* buffer for request in progress */
333 static struct wait_queue
*pd_wait_open
= NULL
;
335 static char *pd_errs
[17] = { "ERR","INDEX","ECC","DRQ","SEEK","WRERR",
336 "READY","BUSY","AMNF","TK0NF","ABRT","MCR",
337 "IDNF","MC","UNC","???","TMO"};
339 /* kernel glue structures */
341 static struct gendisk pd_gendisk
= {
342 PD_MAJOR
, /* Major number */
343 PD_NAME
, /* Major name */
344 PD_BITS
, /* Bits to shift to get real from partition */
345 PD_PARTNS
, /* Number of partitions per real */
346 PD_UNITS
, /* maximum number of real */
347 pd_geninit
, /* init function */
348 pd_hd
, /* hd struct */
349 pd_sizes
, /* block sizes */
355 static struct file_operations pd_fops
= {
356 NULL
, /* lseek - default */
357 block_read
, /* read - general block-dev read */
358 block_write
, /* write - general block-dev write */
359 NULL
, /* readdir - bad */
361 pd_ioctl
, /* ioctl */
365 pd_release
, /* release */
366 block_fsync
, /* fsync */
368 pd_check_media
, /* media change ? */
369 pd_revalidate
/* revalidate new media */
372 void pd_init_units( void )
377 for (unit
=0;unit
<PD_UNITS
;unit
++) {
382 PD
.drive
= DU
[D_SLV
];
385 while ((j
< PD_NAMELEN
-2) && (PD
.name
[j
]=name
[j
])) j
++;
386 PD
.name
[j
++] = 'a' + unit
;
388 PD
.alt_geom
= DU
[D_GEO
];
389 PD
.standby
= DU
[D_SBY
];
390 if (DU
[D_PRT
]) pd_drive_count
++;
398 if (disable
) return -1;
400 if (register_blkdev(MAJOR_NR
,name
,&pd_fops
)) {
401 printk("%s: unable to get major number %d\n",
405 blk_dev
[MAJOR_NR
].request_fn
= DEVICE_REQUEST
;
406 read_ahead
[MAJOR_NR
] = 8; /* 8 sector (4kB) read ahead */
408 pd_gendisk
.major
= major
;
409 pd_gendisk
.major_name
= name
;
410 pd_gendisk
.next
= gendisk_head
;
411 gendisk_head
= &pd_gendisk
;
413 for(i
=0;i
<PD_DEVS
;i
++) pd_blocksizes
[i
] = 1024;
414 blksize_size
[MAJOR_NR
] = pd_blocksizes
;
416 printk("%s: %s version %s, major %d, cluster %d, nice %d\n",
417 name
,name
,PD_VERSION
,major
,cluster
,nice
);
422 static void pd_geninit (struct gendisk
*ignored
)
425 pd_gendisk
.nr_real
= pd_detect();
428 if (!pd_gendisk
.nr_real
) cleanup_module();
433 static int pd_open (struct inode
*inode
, struct file
*file
)
435 { int unit
= DEVICE_NR(inode
->i_rdev
);
437 if ((unit
>= PD_UNITS
) || (!PD
.present
)) return -ENODEV
;
441 while (!pd_valid
) sleep_on(&pd_wait_open
);
446 pd_media_check(unit
);
447 pd_doorlock(unit
,IDE_DOORLOCK
);
452 static int pd_ioctl(struct inode
*inode
,struct file
*file
,
453 unsigned int cmd
, unsigned long arg
)
455 { struct hd_geometry
*geo
= (struct hd_geometry
*) arg
;
458 if ((!inode
) || (!inode
->i_rdev
)) return -EINVAL
;
459 dev
= MINOR(inode
->i_rdev
);
460 unit
= DEVICE_NR(inode
->i_rdev
);
461 if (dev
>= PD_DEVS
) return -EINVAL
;
462 if (!PD
.present
) return -ENODEV
;
466 if (PD
.access
== 1) pd_eject(unit
);
469 if (!geo
) return -EINVAL
;
470 err
= verify_area(VERIFY_WRITE
,geo
,sizeof(*geo
));
474 put_user(PD
.capacity
/(PD_LOG_HEADS
*PD_LOG_SECTS
),
475 (short *) &geo
->cylinders
);
476 put_user(PD_LOG_HEADS
, (char *) &geo
->heads
);
477 put_user(PD_LOG_SECTS
, (char *) &geo
->sectors
);
479 put_user(PD
.cylinders
, (short *) &geo
->cylinders
);
480 put_user(PD
.heads
, (char *) &geo
->heads
);
481 put_user(PD
.sectors
, (char *) &geo
->sectors
);
483 put_user(pd_hd
[dev
].start_sect
,(long *)&geo
->start
);
486 if(!capable(CAP_SYS_ADMIN
)) return -EACCES
;
487 if(!(inode
->i_rdev
)) return -EINVAL
;
488 if(arg
> 0xff) return -EINVAL
;
489 read_ahead
[MAJOR(inode
->i_rdev
)] = arg
;
492 if (!arg
) return -EINVAL
;
493 err
= verify_area(VERIFY_WRITE
,(long *) arg
,sizeof(long));
494 if (err
) return (err
);
495 put_user(read_ahead
[MAJOR(inode
->i_rdev
)],(long *) arg
);
498 if (!arg
) return -EINVAL
;
499 err
= verify_area(VERIFY_WRITE
,(long *) arg
,sizeof(long));
500 if (err
) return (err
);
501 put_user(pd_hd
[dev
].nr_sects
,(long *) arg
);
504 if(!capable(CAP_SYS_ADMIN
)) return -EACCES
;
505 if(!(inode
->i_rdev
)) return -EINVAL
;
506 fsync_dev(inode
->i_rdev
);
507 invalidate_buffers(inode
->i_rdev
);
510 if (!capable(CAP_SYS_ADMIN
))
512 return pd_revalidate(inode
->i_rdev
);
513 RO_IOCTLS(inode
->i_rdev
,arg
);
519 static int pd_release (struct inode
*inode
, struct file
*file
)
524 struct super_block
*sb
;
526 devp
= inode
->i_rdev
;
527 unit
= DEVICE_NR(devp
);
529 if ((unit
>= PD_UNITS
) || (PD
.access
<= 0))
537 sb
= get_super(devp
);
538 if (sb
) invalidate_inodes(sb
);
540 invalidate_buffers(devp
);
541 if (PD
.removable
) pd_doorlock(unit
,IDE_DOORUNLOCK
);
549 static int pd_check_media( kdev_t dev
)
553 unit
= DEVICE_NR(dev
);
554 if ((unit
>= PD_UNITS
) || (!PD
.present
)) return -ENODEV
;
555 if (!PD
.removable
) return 0;
556 pd_media_check(unit
);
562 static int pd_revalidate(kdev_t dev
)
564 { int p
, unit
, minor
;
568 struct super_block
*sb
;
570 unit
= DEVICE_NR(dev
);
571 if ((unit
>= PD_UNITS
) || (!PD
.present
)) return -ENODEV
;
576 restore_flags(flags
);
580 restore_flags(flags
);
582 for (p
=(PD_PARTNS
-1);p
>=0;p
--) {
583 minor
= p
+ unit
*PD_PARTNS
;
584 devp
= MKDEV(MAJOR_NR
, minor
);
587 sb
= get_super(devp
);
588 if (sb
) invalidate_inodes(sb
);
590 invalidate_buffers(devp
);
591 pd_hd
[minor
].start_sect
= 0;
592 pd_hd
[minor
].nr_sects
= 0;
596 resetup_one_dev(&pd_gendisk
,unit
);
599 wake_up(&pd_wait_open
);
606 /* Glue for modules ... */
608 void cleanup_module(void);
610 int init_module(void)
617 pd_geninit(&pd_gendisk
);
619 if (!pd_gendisk
.nr_real
) return -1;
622 for (unit
=0;unit
<PD_UNITS
;unit
++)
623 if (PD
.present
) resetup_one_dev(&pd_gendisk
,unit
);
629 void cleanup_module(void)
631 { struct gendisk
**gdp
;
634 unregister_blkdev(MAJOR_NR
,name
);
636 for(gdp
=&gendisk_head
;*gdp
;gdp
=&((*gdp
)->next
))
637 if (*gdp
== &pd_gendisk
) break;
638 if (*gdp
) *gdp
= (*gdp
)->next
;
640 for (unit
=0;unit
<PD_UNITS
;unit
++)
641 if (PD
.present
) pi_release(PI
);
646 #define WR(c,r,v) pi_write_regr(PI,c,r,v)
647 #define RR(c,r) (pi_read_regr(PI,c,r))
649 #define DRIVE (0xa0+0x10*PD.drive)
651 /* ide command interface */
653 static void pd_print_error( int unit
, char * msg
, int status
)
657 printk("%s: %s: status = 0x%x =",PD
.name
,msg
,status
);
658 for(i
=0;i
<18;i
++) if (status
& (1<<i
)) printk(" %s",pd_errs
[i
]);
662 static void pd_reset( int unit
) /* called only for MASTER drive */
672 #define DBMSG(msg) ((verbose>1)?(msg):NULL)
674 static int pd_wait_for( int unit
, int w
, char * msg
) /* polled wait */
682 if (((r
& w
) == w
) && !(r
& STAT_BUSY
)) break;
685 e
= (RR(0,1)<<8) + RR(0,7);
686 if (k
>= PD_SPIN
) e
|= ERR_TMO
;
687 if ((e
& (STAT_ERR
|ERR_TMO
)) && (msg
!= NULL
))
688 pd_print_error(unit
,msg
,e
);
692 static void pd_send_command( int unit
, int n
, int s
, int h
,
693 int c0
, int c1
, int func
)
697 WR(0,1,0); /* the IDE task file */
707 static void pd_ide_command( int unit
, int func
, int block
, int count
)
709 /* Don't use this call if the capacity is zero. */
713 s
= ( block
% PD
.sectors
) + 1;
714 h
= ( block
/ PD
.sectors
) % PD
.heads
;
715 c0
= ( block
/ (PD
.sectors
*PD
.heads
)) % 256;
716 c1
= ( block
/ (PD
.sectors
*PD
.heads
*256));
718 pd_send_command(unit
,count
,s
,h
,c0
,c1
,func
);
721 /* According to the ATA standard, the default CHS geometry should be
722 available following a reset. Some Western Digital drives come up
723 in a mode where only LBA addresses are accepted until the device
724 parameters are initialised.
727 static void pd_init_dev_parms( int unit
)
730 pd_wait_for(unit
,0,DBMSG("before init_dev_parms"));
731 pd_send_command(unit
,PD
.sectors
,0,PD
.heads
-1,0,0,IDE_INIT_DEV_PARMS
);
733 pd_wait_for(unit
,0,"Initialise device parameters");
737 static void pd_doorlock( int unit
, int func
)
740 if (pd_wait_for(unit
,STAT_READY
,"Lock") & STAT_ERR
) {
744 pd_send_command(unit
,1,0,0,0,0,func
);
745 pd_wait_for(unit
,STAT_READY
,"Lock done");
749 static void pd_eject( int unit
)
752 pd_wait_for(unit
,0,DBMSG("before unlock on eject"));
753 pd_send_command(unit
,1,0,0,0,0,IDE_DOORUNLOCK
);
754 pd_wait_for(unit
,0,DBMSG("after unlock on eject"));
755 pd_wait_for(unit
,0,DBMSG("before eject"));
756 pd_send_command(unit
,0,0,0,0,0,IDE_EJECT
);
757 pd_wait_for(unit
,0,DBMSG("after eject"));
761 static void pd_media_check( int unit
)
766 r
= pd_wait_for(unit
,STAT_READY
,DBMSG("before media_check"));
767 if (!(r
& STAT_ERR
)) {
768 pd_send_command(unit
,1,1,0,0,0,IDE_READ_VRFY
);
769 r
= pd_wait_for(unit
,STAT_READY
,DBMSG("RDY after READ_VRFY"));
770 } else PD
.changed
= 1; /* say changed if other error */
773 pd_send_command(unit
,1,0,0,0,0,IDE_ACKCHANGE
);
774 pd_wait_for(unit
,STAT_READY
,DBMSG("RDY after ACKCHANGE"));
775 pd_send_command(unit
,1,1,0,0,0,IDE_READ_VRFY
);
776 r
= pd_wait_for(unit
,STAT_READY
,DBMSG("RDY after VRFY"));
782 static void pd_standby_off( int unit
)
785 pd_wait_for(unit
,0,DBMSG("before STANDBY"));
786 pd_send_command(unit
,0,0,0,0,0,IDE_STANDBY
);
787 pd_wait_for(unit
,0,DBMSG("after STANDBY"));
791 #define word_val(n) ((pd_scratch[2*n]&0xff)+256*(pd_scratch[2*n+1]&0xff))
793 static int pd_identify( int unit
)
796 char id
[PD_ID_LEN
+1];
798 /* WARNING: here there may be dragons. reset() applies to both drives,
799 but we call it only on probing the MASTER. This should allow most
800 common configurations to work, but be warned that a reset can clear
801 settings on the SLAVE drive.
804 if (PD
.drive
== 0) pd_reset(unit
);
808 pd_wait_for(unit
,0,DBMSG("before IDENT"));
809 pd_send_command(unit
,1,0,0,0,0,IDE_IDENTIFY
);
811 if (pd_wait_for(unit
,STAT_DRQ
,DBMSG("IDENT DRQ")) & STAT_ERR
) {
815 pi_read_block(PI
,pd_scratch
,512);
817 PD
.sectors
= word_val(6);
818 PD
.heads
= word_val(3);
819 PD
.cylinders
= word_val(1);
820 PD
.capacity
= PD
.sectors
*PD
.heads
*PD
.cylinders
;
822 for(j
=0;j
<PD_ID_LEN
;j
++) id
[j
^1] = pd_scratch
[j
+PD_ID_OFF
];
824 while ((j
>= 0) && (id
[j
] <= 0x20)) j
--;
827 PD
.removable
= (word_val(0) & 0x80);
829 printk("%s: %s, %s, %d blocks [%dM], (%d/%d/%d), %s media\n",
831 PD
.drive
?"slave":"master",
832 PD
.capacity
,PD
.capacity
/2048,
833 PD
.cylinders
,PD
.heads
,PD
.sectors
,
834 PD
.removable
?"removable":"fixed");
836 if (PD
.capacity
) pd_init_dev_parms(unit
);
837 if (!PD
.standby
) pd_standby_off(unit
);
839 pd_hd
[unit
<<PD_BITS
].nr_sects
= PD
.capacity
;
840 pd_hd
[unit
<<PD_BITS
].start_sect
= 0;
845 static int pd_probe_drive( int unit
)
847 { if (PD
.drive
== -1) {
848 for (PD
.drive
=0;PD
.drive
<=1;PD
.drive
++)
849 if (pd_identify(unit
)) return 1;
852 else return pd_identify(unit
);
855 static int pd_detect( void )
860 if (pd_drive_count
== 0) { /* nothing spec'd - so autoprobe for 1 */
862 if (pi_init(PI
,1,-1,-1,-1,-1,-1,pd_scratch
,
863 PI_PD
,verbose
,PD
.name
)) {
864 if (pd_probe_drive(unit
)) {
867 } else pi_release(PI
);
870 } else for (unit
=0;unit
<PD_UNITS
;unit
++) if (DU
[D_PRT
])
871 if (pi_init(PI
,0,DU
[D_PRT
],DU
[D_MOD
],DU
[D_UNI
],
872 DU
[D_PRO
],DU
[D_DLY
],pd_scratch
,
873 PI_PD
,verbose
,PD
.name
)) {
874 if (pd_probe_drive(unit
)) {
877 } else pi_release(PI
);
880 /* We lie about the number of drives found, as the generic partition
881 scanner assumes that the drives are numbered sequentially from 0.
882 This can result in some bogus error messages if non-sequential
883 drive numbers are used.
888 printk("%s: no valid drive found\n",name
);
892 /* The i/o request engine */
894 static int pd_ready( void )
896 { int unit
= pd_unit
;
898 return (!(RR(1,6) & STAT_BUSY
)) ;
901 static void do_pd_request (void)
903 { struct buffer_head
* bh
;
904 struct request
* req
;
909 if ((!CURRENT
) || (CURRENT
->rq_status
== RQ_INACTIVE
)) return;
912 pd_dev
= MINOR(CURRENT
->rq_dev
);
913 pd_unit
= unit
= DEVICE_NR(CURRENT
->rq_dev
);
914 pd_block
= CURRENT
->sector
;
915 pd_count
= CURRENT
->nr_sectors
;
920 printk("%s: OUCH: b_reqnext != NULL\n",PD
.name
);
922 if ((pd_dev
>= PD_DEVS
) ||
923 ((pd_block
+pd_count
) > pd_hd
[pd_dev
].nr_sects
)) {
928 pd_cmd
= CURRENT
->cmd
;
930 while ((pd_run
<= cluster
) &&
932 (pd_block
+pd_run
== req
->sector
) &&
933 (pd_cmd
== req
->cmd
) &&
934 (pd_dev
== MINOR(req
->rq_dev
)))
935 pd_run
+= req
->nr_sectors
;
937 pd_poffs
= pd_hd
[pd_dev
].start_sect
;
938 pd_block
+= pd_poffs
;
939 pd_buf
= CURRENT
->buffer
;
943 if (pd_cmd
== READ
) pi_do_claimed(PI
,do_pd_read
);
944 else if (pd_cmd
== WRITE
) pi_do_claimed(PI
,do_pd_write
);
951 static void pd_next_buf( int unit
)
955 spin_lock_irqsave(&io_request_lock
,saved_flags
);
957 if (!pd_run
) { spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
964 (CURRENT
->cmd
!= pd_cmd
) ||
965 (MINOR(CURRENT
->rq_dev
) != pd_dev
) ||
966 (CURRENT
->rq_status
== RQ_INACTIVE
) ||
967 (CURRENT
->sector
+pd_poffs
!= pd_block
))
968 printk("%s: OUCH: request list changed unexpectedly\n",
971 pd_count
= CURRENT
->nr_sectors
;
972 pd_buf
= CURRENT
->buffer
;
973 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
976 static void do_pd_read( void )
978 { ps_set_intr(do_pd_read_start
,0,0,nice
);
981 static void do_pd_read_start( void )
983 { int unit
= pd_unit
;
989 if (pd_wait_for(unit
,STAT_READY
,"do_pd_read") & STAT_ERR
) {
991 if (pd_retries
< PD_MAX_RETRIES
) {
993 pi_do_claimed(PI
,do_pd_read_start
);
996 spin_lock_irqsave(&io_request_lock
,saved_flags
);
1000 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
1003 pd_ide_command(unit
,IDE_READ
,pd_block
,pd_run
);
1004 ps_set_intr(do_pd_read_drq
,pd_ready
,PD_TMO
,nice
);
1007 static void do_pd_read_drq( void )
1009 { int unit
= pd_unit
;
1013 if (pd_wait_for(unit
,STAT_DRQ
,"do_pd_read_drq") & STAT_ERR
) {
1015 if (pd_retries
< PD_MAX_RETRIES
) {
1017 pi_do_claimed(PI
,do_pd_read_start
);
1020 spin_lock_irqsave(&io_request_lock
,saved_flags
);
1024 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
1027 pi_read_block(PI
,pd_buf
,512);
1028 pd_count
--; pd_run
--;
1032 if (!pd_count
) pd_next_buf(unit
);
1035 spin_lock_irqsave(&io_request_lock
,saved_flags
);
1039 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
1042 static void do_pd_write( void )
1044 { ps_set_intr(do_pd_write_start
,0,0,nice
);
1047 static void do_pd_write_start( void )
1049 { int unit
= pd_unit
;
1055 if (pd_wait_for(unit
,STAT_READY
,"do_pd_write") & STAT_ERR
) {
1057 if (pd_retries
< PD_MAX_RETRIES
) {
1059 pi_do_claimed(PI
,do_pd_write_start
);
1062 spin_lock_irqsave(&io_request_lock
,saved_flags
);
1066 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
1069 pd_ide_command(unit
,IDE_WRITE
,pd_block
,pd_run
);
1071 if (pd_wait_for(unit
,STAT_DRQ
,"do_pd_write_drq") & STAT_ERR
) {
1073 if (pd_retries
< PD_MAX_RETRIES
) {
1075 pi_do_claimed(PI
,do_pd_write_start
);
1078 spin_lock_irqsave(&io_request_lock
,saved_flags
);
1082 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
1085 pi_write_block(PI
,pd_buf
,512);
1086 pd_count
--; pd_run
--;
1090 if (!pd_count
) pd_next_buf(unit
);
1092 ps_set_intr(do_pd_write_done
,pd_ready
,PD_TMO
,nice
);
1095 static void do_pd_write_done( void )
1097 { int unit
= pd_unit
;
1100 if (pd_wait_for(unit
,STAT_READY
,"do_pd_write_done") & STAT_ERR
) {
1102 if (pd_retries
< PD_MAX_RETRIES
) {
1104 pi_do_claimed(PI
,do_pd_write_start
);
1107 spin_lock_irqsave(&io_request_lock
,saved_flags
);
1111 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
1115 spin_lock_irqsave(&io_request_lock
,saved_flags
);
1119 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);