2 pd.c (c) 1997-8 Grant R. Guenther <grant@torque.net>
3 Under the terms of the GNU General 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
113 1.05 GRG 1998.09.24 Added jumbo support
117 #define PD_VERSION "1.05"
122 /* Here are things one can override from the insmod command.
123 Most are autoprobed by paride unless set here. Verbose is off
128 static int verbose = 0;
129 static int major = PD_MAJOR;
130 static char *name = PD_NAME;
131 static int cluster = 64;
133 static int disable = 0;
135 static int drive0[8] = {0,0,0,-1,0,1,-1,-1};
136 static int drive1[8] = {0,0,0,-1,0,1,-1,-1};
137 static int drive2[8] = {0,0,0,-1,0,1,-1,-1};
138 static int drive3[8] = {0,0,0,-1,0,1,-1,-1};
140 static int (*drives[4])[8] = {&drive0,&drive1,&drive2,&drive3};
141 static int pd_drive_count;
152 #define DU (*drives[unit])
154 /* end of parameters */
156 #include <linux/module.h>
157 #include <linux/errno.h>
158 #include <linux/fs.h>
159 #include <linux/devfs_fs_kernel.h>
160 #include <linux/kernel.h>
161 #include <linux/delay.h>
162 #include <linux/genhd.h>
163 #include <linux/hdreg.h>
164 #include <linux/cdrom.h> /* for the eject ioctl */
165 #include <linux/spinlock.h>
167 #include <asm/uaccess.h>
173 static STT pd_stt[7] = {{"drive0",8,drive0},
177 {"disable",1,&disable},
178 {"cluster",1,&cluster},
181 void pd_setup( char *str, int *ints)
184 generic_setup(pd_stt,7,str);
189 MODULE_PARM(verbose,"i");
190 MODULE_PARM(major,"i");
191 MODULE_PARM(name,"s");
192 MODULE_PARM(cluster,"i");
193 MODULE_PARM(nice,"i");
194 MODULE_PARM(drive0,"1-8i");
195 MODULE_PARM(drive1,"1-8i");
196 MODULE_PARM(drive2,"1-8i");
197 MODULE_PARM(drive3,"1-8i");
203 /* set up defines for blk.h, why don't all drivers do it this way ? */
205 #define MAJOR_NR major
206 #define DEVICE_NAME "PD"
207 #define DEVICE_REQUEST do_pd_request
208 #define DEVICE_NR(device) (MINOR(device)>>PD_BITS)
209 #define DEVICE_ON(device)
210 #define DEVICE_OFF(device)
212 #include <linux/blk.h>
213 #include <linux/blkpg.h>
217 #define PD_PARTNS (1<<PD_BITS)
218 #define PD_DEVS PD_PARTNS*PD_UNITS
220 /* numbers for "SCSI" geometry */
222 #define PD_LOG_HEADS 64
223 #define PD_LOG_SECTS 32
228 #define PD_MAX_RETRIES 5
229 #define PD_TMO 800 /* interrupt timeout in jiffies */
230 #define PD_SPIN_DEL 50 /* spin delay in micro-seconds */
232 #define PD_SPIN (1000000*PD_TMO)/(HZ*PD_SPIN_DEL)
234 #define STAT_ERR 0x00001
235 #define STAT_INDEX 0x00002
236 #define STAT_ECC 0x00004
237 #define STAT_DRQ 0x00008
238 #define STAT_SEEK 0x00010
239 #define STAT_WRERR 0x00020
240 #define STAT_READY 0x00040
241 #define STAT_BUSY 0x00080
243 #define ERR_AMNF 0x00100
244 #define ERR_TK0NF 0x00200
245 #define ERR_ABRT 0x00400
246 #define ERR_MCR 0x00800
247 #define ERR_IDNF 0x01000
248 #define ERR_MC 0x02000
249 #define ERR_UNC 0x04000
250 #define ERR_TMO 0x10000
252 #define IDE_READ 0x20
253 #define IDE_WRITE 0x30
254 #define IDE_READ_VRFY 0x40
255 #define IDE_INIT_DEV_PARMS 0x91
256 #define IDE_STANDBY 0x96
257 #define IDE_ACKCHANGE 0xdb
258 #define IDE_DOORLOCK 0xde
259 #define IDE_DOORUNLOCK 0xdf
260 #define IDE_IDENTIFY 0xec
261 #define IDE_EJECT 0xed
264 void pd_setup(char * str, int * ints);
266 void cleanup_module( void );
268 static int pd_open(struct inode *inode, struct file *file);
269 static void do_pd_request(request_queue_t * q);
270 static int pd_ioctl(struct inode *inode,struct file *file,
271 unsigned int cmd, unsigned long arg);
272 static int pd_release (struct inode *inode, struct file *file);
273 static int pd_revalidate(kdev_t dev);
274 static int pd_detect(void);
275 static void do_pd_read(void);
276 static void do_pd_read_start(void);
277 static void do_pd_write(void);
278 static void do_pd_write_start(void);
279 static void do_pd_read_drq( void );
280 static void do_pd_write_done( void );
282 static int pd_identify (int unit);
283 static void pd_media_check(int unit);
284 static void pd_doorlock(int unit, int func);
285 static int pd_check_media(kdev_t dev);
286 static void pd_eject( int unit);
288 static struct hd_struct pd_hd[PD_DEVS];
289 static int pd_sizes[PD_DEVS];
290 static int pd_blocksizes[PD_DEVS];
291 static int pd_maxsectors[PD_DEVS];
296 struct pi_adapter pia; /* interface to paride layer */
297 struct pi_adapter *pi;
298 int access; /* count of active opens ... */
299 int capacity; /* Size of this volume in sectors */
300 int heads; /* physical geometry */
304 int drive; /* master=0 slave=1 */
305 int changed; /* Have we seen a disk change ? */
306 int removable; /* removable media device ? */
310 char name[PD_NAMELEN]; /* pda, pdb, etc ... */
313 struct pd_unit pd[PD_UNITS];
315 /* 'unit' must be defined in all functions - either as a local or a param */
320 static int pd_valid = 1; /* serialise partition checks */
321 static char pd_scratch[512]; /* scratch block buffer */
323 /* the variables below are used mainly in the I/O request engine, which
324 processes only one request at a time.
327 static int pd_retries = 0; /* i/o error retry count */
328 static int pd_busy = 0; /* request being processed ? */
329 static int pd_block; /* address of next requested block */
330 static int pd_count; /* number of blocks still to do */
331 static int pd_run; /* sectors in current cluster */
332 static int pd_cmd; /* current command READ/WRITE */
333 static int pd_unit; /* unit of current request */
334 static int pd_dev; /* minor of current request */
335 static int pd_poffs; /* partition offset of current minor */
336 static char * pd_buf; /* buffer for request in progress */
338 static DECLARE_WAIT_QUEUE_HEAD(pd_wait_open);
340 static char *pd_errs[17] = { "ERR","INDEX","ECC","DRQ","SEEK","WRERR",
341 "READY","BUSY","AMNF","TK0NF","ABRT","MCR",
342 "IDNF","MC","UNC","???","TMO"};
344 /* kernel glue structures */
346 static struct block_device_operations pd_fops = {
351 check_media_change: pd_check_media,
352 revalidate: pd_revalidate
355 static struct gendisk pd_gendisk = {
358 minor_shift: PD_BITS,
365 void pd_init_units( void )
370 for (unit=0;unit<PD_UNITS;unit++) {
375 PD.drive = DU[D_SLV];
378 while ((j < PD_NAMELEN-2) && (PD.name[j]=name[j])) j++;
379 PD.name[j++] = 'a' + unit;
381 PD.alt_geom = DU[D_GEO];
382 PD.standby = DU[D_SBY];
383 if (DU[D_PRT]) pd_drive_count++;
392 if (disable) return -1;
393 if (devfs_register_blkdev(MAJOR_NR,name,&pd_fops)) {
394 printk("%s: unable to get major number %d\n",
398 q = BLK_DEFAULT_QUEUE(MAJOR_NR);
399 blk_init_queue(q, DEVICE_REQUEST);
400 read_ahead[MAJOR_NR] = 8; /* 8 sector (4kB) read ahead */
402 pd_gendisk.major = major;
403 pd_gendisk.major_name = name;
404 add_gendisk(&pd_gendisk);
406 for(i=0;i<PD_DEVS;i++) pd_blocksizes[i] = 1024;
407 blksize_size[MAJOR_NR] = pd_blocksizes;
409 for(i=0;i<PD_DEVS;i++) pd_maxsectors[i] = cluster;
410 max_sectors[MAJOR_NR] = pd_maxsectors;
412 printk("%s: %s version %s, major %d, cluster %d, nice %d\n",
413 name,name,PD_VERSION,major,cluster,nice);
416 pd_gendisk.nr_real = pd_detect();
420 if (!pd_gendisk.nr_real) {
428 static int pd_open (struct inode *inode, struct file *file)
430 { int unit = DEVICE_NR(inode->i_rdev);
432 if ((unit >= PD_UNITS) || (!PD.present)) return -ENODEV;
434 wait_event (pd_wait_open, pd_valid);
439 pd_media_check(unit);
440 pd_doorlock(unit,IDE_DOORLOCK);
445 static int pd_ioctl(struct inode *inode,struct file *file,
446 unsigned int cmd, unsigned long arg)
448 { struct hd_geometry *geo = (struct hd_geometry *) arg;
451 if ((!inode) || (!inode->i_rdev)) return -EINVAL;
452 dev = MINOR(inode->i_rdev);
453 unit = DEVICE_NR(inode->i_rdev);
454 if (dev >= PD_DEVS) return -EINVAL;
455 if (!PD.present) return -ENODEV;
459 if (PD.access == 1) pd_eject(unit);
462 if (!geo) return -EINVAL;
463 err = verify_area(VERIFY_WRITE,geo,sizeof(*geo));
467 put_user(PD.capacity/(PD_LOG_HEADS*PD_LOG_SECTS),
468 (short *) &geo->cylinders);
469 put_user(PD_LOG_HEADS, (char *) &geo->heads);
470 put_user(PD_LOG_SECTS, (char *) &geo->sectors);
472 put_user(PD.cylinders, (short *) &geo->cylinders);
473 put_user(PD.heads, (char *) &geo->heads);
474 put_user(PD.sectors, (char *) &geo->sectors);
476 put_user(pd_hd[dev].start_sect,(long *)&geo->start);
479 if (!capable(CAP_SYS_ADMIN))
481 return pd_revalidate(inode->i_rdev);
490 return blk_ioctl(inode->i_rdev, cmd, arg);
496 static int pd_release (struct inode *inode, struct file *file)
501 devp = inode->i_rdev;
502 unit = DEVICE_NR(devp);
504 if ((unit >= PD_UNITS) || (PD.access <= 0))
509 if (!PD.access && PD.removable)
510 pd_doorlock(unit,IDE_DOORUNLOCK);
515 static int pd_check_media( kdev_t dev)
519 unit = DEVICE_NR(dev);
520 if ((unit >= PD_UNITS) || (!PD.present)) return -ENODEV;
521 if (!PD.removable) return 0;
522 pd_media_check(unit);
528 static int pd_revalidate(kdev_t dev)
530 { int p, unit, minor;
533 unit = DEVICE_NR(dev);
534 if ((unit >= PD_UNITS) || (!PD.present)) return -ENODEV;
539 restore_flags(flags);
543 restore_flags(flags);
545 for (p=(PD_PARTNS-1);p>=0;p--) {
546 minor = p + unit*PD_PARTNS;
547 invalidate_device(MKDEV(MAJOR_NR, minor), 1);
548 pd_hd[minor].start_sect = 0;
549 pd_hd[minor].nr_sects = 0;
552 if (pd_identify(unit))
553 grok_partitions(&pd_gendisk,unit,1<<PD_BITS,PD.capacity);
556 wake_up(&pd_wait_open);
563 /* Glue for modules ... */
565 void cleanup_module(void);
567 int init_module(void)
572 { extern paride_init();
579 void cleanup_module(void)
583 devfs_unregister_blkdev(MAJOR_NR,name);
584 del_gendisk(&pd_gendisk);
586 for (unit=0;unit<PD_UNITS;unit++)
587 if (PD.present) pi_release(PI);
589 max_sectors[MAJOR_NR] = NULL;
594 #define WR(c,r,v) pi_write_regr(PI,c,r,v)
595 #define RR(c,r) (pi_read_regr(PI,c,r))
597 #define DRIVE (0xa0+0x10*PD.drive)
599 /* ide command interface */
601 static void pd_print_error( int unit, char * msg, int status )
605 printk("%s: %s: status = 0x%x =",PD.name,msg,status);
606 for(i=0;i<18;i++) if (status & (1<<i)) printk(" %s",pd_errs[i]);
610 static void pd_reset( int unit ) /* called only for MASTER drive */
620 #define DBMSG(msg) ((verbose>1)?(msg):NULL)
622 static int pd_wait_for( int unit, int w, char * msg ) /* polled wait */
630 if (((r & w) == w) && !(r & STAT_BUSY)) break;
633 e = (RR(0,1)<<8) + RR(0,7);
634 if (k >= PD_SPIN) e |= ERR_TMO;
635 if ((e & (STAT_ERR|ERR_TMO)) && (msg != NULL))
636 pd_print_error(unit,msg,e);
640 static void pd_send_command( int unit, int n, int s, int h,
641 int c0, int c1, int func )
645 WR(0,1,0); /* the IDE task file */
655 static void pd_ide_command( int unit, int func, int block, int count )
657 /* Don't use this call if the capacity is zero. */
663 c0 = (block >>= 8) & 255;
664 c1 = (block >>= 8) & 255;
665 h = ((block >>= 8) & 15) + 0x40;
667 s = ( block % PD.sectors) + 1;
668 h = ( block /= PD.sectors) % PD.heads;
669 c0 = ( block /= PD.heads) % 256;
672 pd_send_command(unit,count,s,h,c0,c1,func);
675 /* According to the ATA standard, the default CHS geometry should be
676 available following a reset. Some Western Digital drives come up
677 in a mode where only LBA addresses are accepted until the device
678 parameters are initialised.
681 static void pd_init_dev_parms( int unit )
684 pd_wait_for(unit,0,DBMSG("before init_dev_parms"));
685 pd_send_command(unit,PD.sectors,0,PD.heads-1,0,0,IDE_INIT_DEV_PARMS);
687 pd_wait_for(unit,0,"Initialise device parameters");
691 static void pd_doorlock( int unit, int func )
694 if (pd_wait_for(unit,STAT_READY,"Lock") & STAT_ERR) {
698 pd_send_command(unit,1,0,0,0,0,func);
699 pd_wait_for(unit,STAT_READY,"Lock done");
703 static void pd_eject( int unit )
706 pd_wait_for(unit,0,DBMSG("before unlock on eject"));
707 pd_send_command(unit,1,0,0,0,0,IDE_DOORUNLOCK);
708 pd_wait_for(unit,0,DBMSG("after unlock on eject"));
709 pd_wait_for(unit,0,DBMSG("before eject"));
710 pd_send_command(unit,0,0,0,0,0,IDE_EJECT);
711 pd_wait_for(unit,0,DBMSG("after eject"));
715 static void pd_media_check( int unit )
720 r = pd_wait_for(unit,STAT_READY,DBMSG("before media_check"));
721 if (!(r & STAT_ERR)) {
722 pd_send_command(unit,1,1,0,0,0,IDE_READ_VRFY);
723 r = pd_wait_for(unit,STAT_READY,DBMSG("RDY after READ_VRFY"));
724 } else PD.changed = 1; /* say changed if other error */
727 pd_send_command(unit,1,0,0,0,0,IDE_ACKCHANGE);
728 pd_wait_for(unit,STAT_READY,DBMSG("RDY after ACKCHANGE"));
729 pd_send_command(unit,1,1,0,0,0,IDE_READ_VRFY);
730 r = pd_wait_for(unit,STAT_READY,DBMSG("RDY after VRFY"));
736 static void pd_standby_off( int unit )
739 pd_wait_for(unit,0,DBMSG("before STANDBY"));
740 pd_send_command(unit,0,0,0,0,0,IDE_STANDBY);
741 pd_wait_for(unit,0,DBMSG("after STANDBY"));
745 #define word_val(n) ((pd_scratch[2*n]&0xff)+256*(pd_scratch[2*n+1]&0xff))
747 static int pd_identify( int unit )
750 char id[PD_ID_LEN+1];
752 /* WARNING: here there may be dragons. reset() applies to both drives,
753 but we call it only on probing the MASTER. This should allow most
754 common configurations to work, but be warned that a reset can clear
755 settings on the SLAVE drive.
758 if (PD.drive == 0) pd_reset(unit);
762 pd_wait_for(unit,0,DBMSG("before IDENT"));
763 pd_send_command(unit,1,0,0,0,0,IDE_IDENTIFY);
765 if (pd_wait_for(unit,STAT_DRQ,DBMSG("IDENT DRQ")) & STAT_ERR) {
769 pi_read_block(PI,pd_scratch,512);
771 PD.can_lba = pd_scratch[99] & 2;
772 PD.sectors = le16_to_cpu(*(u16*)(pd_scratch+12));
773 PD.heads = le16_to_cpu(*(u16*)(pd_scratch+6));
774 PD.cylinders = le16_to_cpu(*(u16*)(pd_scratch+2));
776 PD.capacity = le32_to_cpu(*(u32*)(pd_scratch + 120));
778 PD.capacity = PD.sectors*PD.heads*PD.cylinders;
780 for(j=0;j<PD_ID_LEN;j++) id[j^1] = pd_scratch[j+PD_ID_OFF];
782 while ((j >= 0) && (id[j] <= 0x20)) j--;
785 PD.removable = (word_val(0) & 0x80);
787 printk("%s: %s, %s, %d blocks [%dM], (%d/%d/%d), %s media\n",
789 PD.drive?"slave":"master",
790 PD.capacity,PD.capacity/2048,
791 PD.cylinders,PD.heads,PD.sectors,
792 PD.removable?"removable":"fixed");
794 if (PD.capacity) pd_init_dev_parms(unit);
795 if (!PD.standby) pd_standby_off(unit);
800 static int pd_probe_drive( int unit )
802 if (PD.drive == -1) {
803 for (PD.drive=0;PD.drive<=1;PD.drive++)
804 if (pd_identify(unit))
808 return pd_identify(unit);
811 static int pd_detect( void )
816 if (pd_drive_count == 0) { /* nothing spec'd - so autoprobe for 1 */
818 if (pi_init(PI,1,-1,-1,-1,-1,-1,pd_scratch,
819 PI_PD,verbose,PD.name)) {
820 if (pd_probe_drive(unit)) {
823 } else pi_release(PI);
826 } else for (unit=0;unit<PD_UNITS;unit++) if (DU[D_PRT])
827 if (pi_init(PI,0,DU[D_PRT],DU[D_MOD],DU[D_UNI],
828 DU[D_PRO],DU[D_DLY],pd_scratch,
829 PI_PD,verbose,PD.name)) {
830 if (pd_probe_drive(unit)) {
833 } else pi_release(PI);
835 for (unit=0;unit<PD_UNITS;unit++)
836 register_disk(&pd_gendisk,MKDEV(MAJOR_NR,unit<<PD_BITS),
838 PD.present?PD.capacity:0);
840 /* We lie about the number of drives found, as the generic partition
841 scanner assumes that the drives are numbered sequentially from 0.
842 This can result in some bogus error messages if non-sequential
843 drive numbers are used.
847 printk("%s: no valid drive found\n",name);
851 /* The i/o request engine */
853 static int pd_ready( void )
855 { int unit = pd_unit;
857 return (!(RR(1,6) & STAT_BUSY)) ;
860 static void do_pd_request (request_queue_t * q)
862 { struct buffer_head * bh;
867 if (QUEUE_EMPTY || (CURRENT->rq_status == RQ_INACTIVE)) return;
870 pd_dev = MINOR(CURRENT->rq_dev);
871 pd_unit = unit = DEVICE_NR(CURRENT->rq_dev);
872 pd_block = CURRENT->sector;
873 pd_run = CURRENT->nr_sectors;
874 pd_count = CURRENT->current_nr_sectors;
878 if ((pd_dev >= PD_DEVS) ||
879 ((pd_block+pd_count) > pd_hd[pd_dev].nr_sects)) {
884 pd_cmd = CURRENT->cmd;
885 pd_poffs = pd_hd[pd_dev].start_sect;
886 pd_block += pd_poffs;
887 pd_buf = CURRENT->buffer;
891 if (pd_cmd == READ) pi_do_claimed(PI,do_pd_read);
892 else if (pd_cmd == WRITE) pi_do_claimed(PI,do_pd_write);
899 static void pd_next_buf( int unit )
901 { unsigned long saved_flags;
903 spin_lock_irqsave(&io_request_lock,saved_flags);
905 if (!pd_run) { spin_unlock_irqrestore(&io_request_lock,saved_flags);
912 (CURRENT->cmd != pd_cmd) ||
913 (MINOR(CURRENT->rq_dev) != pd_dev) ||
914 (CURRENT->rq_status == RQ_INACTIVE) ||
915 (CURRENT->sector+pd_poffs != pd_block))
916 printk("%s: OUCH: request list changed unexpectedly\n",
919 pd_count = CURRENT->current_nr_sectors;
920 pd_buf = CURRENT->buffer;
921 spin_unlock_irqrestore(&io_request_lock,saved_flags);
924 static void do_pd_read( void )
926 { ps_set_intr(do_pd_read_start,0,0,nice);
929 static void do_pd_read_start( void )
931 { int unit = pd_unit;
932 unsigned long saved_flags;
937 if (pd_wait_for(unit,STAT_READY,"do_pd_read") & STAT_ERR) {
939 if (pd_retries < PD_MAX_RETRIES) {
941 pi_do_claimed(PI,do_pd_read_start);
944 spin_lock_irqsave(&io_request_lock,saved_flags);
948 spin_unlock_irqrestore(&io_request_lock,saved_flags);
951 pd_ide_command(unit,IDE_READ,pd_block,pd_run);
952 ps_set_intr(do_pd_read_drq,pd_ready,PD_TMO,nice);
955 static void do_pd_read_drq( void )
957 { int unit = pd_unit;
958 unsigned long saved_flags;
961 if (pd_wait_for(unit,STAT_DRQ,"do_pd_read_drq") & STAT_ERR) {
963 if (pd_retries < PD_MAX_RETRIES) {
965 pi_do_claimed(PI,do_pd_read_start);
968 spin_lock_irqsave(&io_request_lock,saved_flags);
972 spin_unlock_irqrestore(&io_request_lock,saved_flags);
975 pi_read_block(PI,pd_buf,512);
976 pd_count--; pd_run--;
980 if (!pd_count) pd_next_buf(unit);
983 spin_lock_irqsave(&io_request_lock,saved_flags);
987 spin_unlock_irqrestore(&io_request_lock,saved_flags);
990 static void do_pd_write( void )
992 { ps_set_intr(do_pd_write_start,0,0,nice);
995 static void do_pd_write_start( void )
997 { int unit = pd_unit;
998 unsigned long saved_flags;
1003 if (pd_wait_for(unit,STAT_READY,"do_pd_write") & STAT_ERR) {
1005 if (pd_retries < PD_MAX_RETRIES) {
1007 pi_do_claimed(PI,do_pd_write_start);
1010 spin_lock_irqsave(&io_request_lock,saved_flags);
1013 do_pd_request(NULL);
1014 spin_unlock_irqrestore(&io_request_lock,saved_flags);
1017 pd_ide_command(unit,IDE_WRITE,pd_block,pd_run);
1019 if (pd_wait_for(unit,STAT_DRQ,"do_pd_write_drq") & STAT_ERR) {
1021 if (pd_retries < PD_MAX_RETRIES) {
1023 pi_do_claimed(PI,do_pd_write_start);
1026 spin_lock_irqsave(&io_request_lock,saved_flags);
1029 do_pd_request(NULL);
1030 spin_unlock_irqrestore(&io_request_lock,saved_flags);
1033 pi_write_block(PI,pd_buf,512);
1034 pd_count--; pd_run--;
1038 if (!pd_count) pd_next_buf(unit);
1040 ps_set_intr(do_pd_write_done,pd_ready,PD_TMO,nice);
1043 static void do_pd_write_done( void )
1045 { int unit = pd_unit;
1046 unsigned long saved_flags;
1048 if (pd_wait_for(unit,STAT_READY,"do_pd_write_done") & STAT_ERR) {
1050 if (pd_retries < PD_MAX_RETRIES) {
1052 pi_do_claimed(PI,do_pd_write_start);
1055 spin_lock_irqsave(&io_request_lock,saved_flags);
1058 do_pd_request(NULL);
1059 spin_unlock_irqrestore(&io_request_lock,saved_flags);
1063 spin_lock_irqsave(&io_request_lock,saved_flags);
1066 do_pd_request(NULL);
1067 spin_unlock_irqrestore(&io_request_lock,saved_flags);
1072 MODULE_LICENSE("GPL");