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
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/kernel.h>
160 #include <linux/delay.h>
161 #include <linux/genhd.h>
162 #include <linux/hdreg.h>
163 #include <linux/cdrom.h> /* for the eject ioctl */
164 #include <linux/spinlock.h>
166 #include <asm/uaccess.h>
172 static STT pd_stt
[7] = {{"drive0",8,drive0
},
176 {"disable",1,&disable
},
177 {"cluster",1,&cluster
},
180 void pd_setup( char *str
, int *ints
)
182 { generic_setup(pd_stt
,7,str
);
187 MODULE_PARM(verbose
,"i");
188 MODULE_PARM(major
,"i");
189 MODULE_PARM(name
,"s");
190 MODULE_PARM(cluster
,"i");
191 MODULE_PARM(nice
,"i");
192 MODULE_PARM(drive0
,"1-8i");
193 MODULE_PARM(drive1
,"1-8i");
194 MODULE_PARM(drive2
,"1-8i");
195 MODULE_PARM(drive3
,"1-8i");
201 /* set up defines for blk.h, why don't all drivers do it this way ? */
203 #define MAJOR_NR major
204 #define DEVICE_NAME "PD"
205 #define DEVICE_REQUEST do_pd_request
206 #define DEVICE_NR(device) (MINOR(device)>>PD_BITS)
207 #define DEVICE_ON(device)
208 #define DEVICE_OFF(device)
210 #include <linux/blk.h>
211 #include <linux/blkpg.h>
215 #define PD_PARTNS (1<<PD_BITS)
216 #define PD_DEVS PD_PARTNS*PD_UNITS
218 /* numbers for "SCSI" geometry */
220 #define PD_LOG_HEADS 64
221 #define PD_LOG_SECTS 32
226 #define PD_MAX_RETRIES 5
227 #define PD_TMO 800 /* interrupt timeout in jiffies */
228 #define PD_SPIN_DEL 50 /* spin delay in micro-seconds */
230 #define PD_SPIN (1000000*PD_TMO)/(HZ*PD_SPIN_DEL)
232 #define STAT_ERR 0x00001
233 #define STAT_INDEX 0x00002
234 #define STAT_ECC 0x00004
235 #define STAT_DRQ 0x00008
236 #define STAT_SEEK 0x00010
237 #define STAT_WRERR 0x00020
238 #define STAT_READY 0x00040
239 #define STAT_BUSY 0x00080
241 #define ERR_AMNF 0x00100
242 #define ERR_TK0NF 0x00200
243 #define ERR_ABRT 0x00400
244 #define ERR_MCR 0x00800
245 #define ERR_IDNF 0x01000
246 #define ERR_MC 0x02000
247 #define ERR_UNC 0x04000
248 #define ERR_TMO 0x10000
250 #define IDE_READ 0x20
251 #define IDE_WRITE 0x30
252 #define IDE_READ_VRFY 0x40
253 #define IDE_INIT_DEV_PARMS 0x91
254 #define IDE_STANDBY 0x96
255 #define IDE_ACKCHANGE 0xdb
256 #define IDE_DOORLOCK 0xde
257 #define IDE_DOORUNLOCK 0xdf
258 #define IDE_IDENTIFY 0xec
259 #define IDE_EJECT 0xed
262 void pd_setup(char * str
, int * ints
);
264 void cleanup_module( void );
266 static void pd_geninit(struct gendisk
*ignored
);
267 static int pd_open(struct inode
*inode
, struct file
*file
);
268 static void do_pd_request(void);
269 static int pd_ioctl(struct inode
*inode
,struct file
*file
,
270 unsigned int cmd
, unsigned long arg
);
271 static int pd_release (struct inode
*inode
, struct file
*file
);
272 static int pd_revalidate(kdev_t dev
);
273 static int pd_detect(void);
274 static void do_pd_read(void);
275 static void do_pd_read_start(void);
276 static void do_pd_write(void);
277 static void do_pd_write_start(void);
278 static void do_pd_read_drq( void );
279 static void do_pd_write_done( void );
281 static int pd_identify (int unit
);
282 static void pd_media_check(int unit
);
283 static void pd_doorlock(int unit
, int func
);
284 static int pd_check_media(kdev_t dev
);
285 static void pd_eject( int unit
);
287 static struct hd_struct pd_hd
[PD_DEVS
];
288 static int pd_sizes
[PD_DEVS
];
289 static int pd_blocksizes
[PD_DEVS
];
294 struct pi_adapter pia
; /* interface to paride layer */
295 struct pi_adapter
*pi
;
296 int access
; /* count of active opens ... */
297 int capacity
; /* Size of this volume in sectors */
298 int heads
; /* physical geometry */
301 int drive
; /* master=0 slave=1 */
302 int changed
; /* Have we seen a disk change ? */
303 int removable
; /* removable media device ? */
307 char name
[PD_NAMELEN
]; /* pda, pdb, etc ... */
310 struct pd_unit pd
[PD_UNITS
];
312 /* 'unit' must be defined in all functions - either as a local or a param */
317 static int pd_valid
= 1; /* serialise partition checks */
318 static char pd_scratch
[512]; /* scratch block buffer */
320 /* the variables below are used mainly in the I/O request engine, which
321 processes only one request at a time.
324 static int pd_retries
= 0; /* i/o error retry count */
325 static int pd_busy
= 0; /* request being processed ? */
326 static int pd_block
; /* address of next requested block */
327 static int pd_count
; /* number of blocks still to do */
328 static int pd_run
; /* sectors in current cluster */
329 static int pd_cmd
; /* current command READ/WRITE */
330 static int pd_unit
; /* unit of current request */
331 static int pd_dev
; /* minor of current request */
332 static int pd_poffs
; /* partition offset of current minor */
333 static char * pd_buf
; /* buffer for request in progress */
335 static DECLARE_WAIT_QUEUE_HEAD(pd_wait_open
);
337 static char *pd_errs
[17] = { "ERR","INDEX","ECC","DRQ","SEEK","WRERR",
338 "READY","BUSY","AMNF","TK0NF","ABRT","MCR",
339 "IDNF","MC","UNC","???","TMO"};
341 /* kernel glue structures */
343 static struct gendisk pd_gendisk
= {
344 PD_MAJOR
, /* Major number */
345 PD_NAME
, /* Major name */
346 PD_BITS
, /* Bits to shift to get real from partition */
347 PD_PARTNS
, /* Number of partitions per real */
348 PD_UNITS
, /* maximum number of real */
349 pd_geninit
, /* init function */
350 pd_hd
, /* hd struct */
351 pd_sizes
, /* block sizes */
357 static struct file_operations pd_fops
= {
358 NULL
, /* lseek - default */
359 block_read
, /* read - general block-dev read */
360 block_write
, /* write - general block-dev write */
361 NULL
, /* readdir - bad */
363 pd_ioctl
, /* ioctl */
367 pd_release
, /* release */
368 block_fsync
, /* fsync */
370 pd_check_media
, /* media change ? */
371 pd_revalidate
/* revalidate new media */
374 void pd_init_units( void )
379 for (unit
=0;unit
<PD_UNITS
;unit
++) {
384 PD
.drive
= DU
[D_SLV
];
387 while ((j
< PD_NAMELEN
-2) && (PD
.name
[j
]=name
[j
])) j
++;
388 PD
.name
[j
++] = 'a' + unit
;
390 PD
.alt_geom
= DU
[D_GEO
];
391 PD
.standby
= DU
[D_SBY
];
392 if (DU
[D_PRT
]) pd_drive_count
++;
400 if (disable
) return -1;
402 if (register_blkdev(MAJOR_NR
,name
,&pd_fops
)) {
403 printk("%s: unable to get major number %d\n",
407 blk_dev
[MAJOR_NR
].request_fn
= DEVICE_REQUEST
;
408 read_ahead
[MAJOR_NR
] = 8; /* 8 sector (4kB) read ahead */
410 pd_gendisk
.major
= major
;
411 pd_gendisk
.major_name
= name
;
412 pd_gendisk
.next
= gendisk_head
;
413 gendisk_head
= &pd_gendisk
;
415 for(i
=0;i
<PD_DEVS
;i
++) pd_blocksizes
[i
] = 1024;
416 blksize_size
[MAJOR_NR
] = pd_blocksizes
;
418 printk("%s: %s version %s, major %d, cluster %d, nice %d\n",
419 name
,name
,PD_VERSION
,major
,cluster
,nice
);
424 static void pd_geninit (struct gendisk
*ignored
)
427 pd_gendisk
.nr_real
= pd_detect();
430 if (!pd_gendisk
.nr_real
) cleanup_module();
435 static int pd_open (struct inode
*inode
, struct file
*file
)
437 { int unit
= DEVICE_NR(inode
->i_rdev
);
439 if ((unit
>= PD_UNITS
) || (!PD
.present
)) return -ENODEV
;
443 while (!pd_valid
) sleep_on(&pd_wait_open
);
448 pd_media_check(unit
);
449 pd_doorlock(unit
,IDE_DOORLOCK
);
454 static int pd_ioctl(struct inode
*inode
,struct file
*file
,
455 unsigned int cmd
, unsigned long arg
)
457 { struct hd_geometry
*geo
= (struct hd_geometry
*) arg
;
460 if ((!inode
) || (!inode
->i_rdev
)) return -EINVAL
;
461 dev
= MINOR(inode
->i_rdev
);
462 unit
= DEVICE_NR(inode
->i_rdev
);
463 if (dev
>= PD_DEVS
) return -EINVAL
;
464 if (!PD
.present
) return -ENODEV
;
468 if (PD
.access
== 1) pd_eject(unit
);
471 if (!geo
) return -EINVAL
;
472 err
= verify_area(VERIFY_WRITE
,geo
,sizeof(*geo
));
476 put_user(PD
.capacity
/(PD_LOG_HEADS
*PD_LOG_SECTS
),
477 (short *) &geo
->cylinders
);
478 put_user(PD_LOG_HEADS
, (char *) &geo
->heads
);
479 put_user(PD_LOG_SECTS
, (char *) &geo
->sectors
);
481 put_user(PD
.cylinders
, (short *) &geo
->cylinders
);
482 put_user(PD
.heads
, (char *) &geo
->heads
);
483 put_user(PD
.sectors
, (char *) &geo
->sectors
);
485 put_user(pd_hd
[dev
].start_sect
,(long *)&geo
->start
);
488 if (!arg
) return -EINVAL
;
489 err
= verify_area(VERIFY_WRITE
,(long *) arg
,sizeof(long));
490 if (err
) return (err
);
491 put_user(pd_hd
[dev
].nr_sects
,(long *) arg
);
494 if (!capable(CAP_SYS_ADMIN
))
496 return pd_revalidate(inode
->i_rdev
);
503 return blk_ioctl(inode
->i_rdev
, cmd
, arg
);
509 static int pd_release (struct inode
*inode
, struct file
*file
)
514 struct super_block
*sb
;
516 devp
= inode
->i_rdev
;
517 unit
= DEVICE_NR(devp
);
519 if ((unit
>= PD_UNITS
) || (PD
.access
<= 0))
527 sb
= get_super(devp
);
528 if (sb
) invalidate_inodes(sb
);
530 invalidate_buffers(devp
);
531 if (PD
.removable
) pd_doorlock(unit
,IDE_DOORUNLOCK
);
539 static int pd_check_media( kdev_t dev
)
543 unit
= DEVICE_NR(dev
);
544 if ((unit
>= PD_UNITS
) || (!PD
.present
)) return -ENODEV
;
545 if (!PD
.removable
) return 0;
546 pd_media_check(unit
);
552 static int pd_revalidate(kdev_t dev
)
554 { int p
, unit
, minor
;
558 struct super_block
*sb
;
560 unit
= DEVICE_NR(dev
);
561 if ((unit
>= PD_UNITS
) || (!PD
.present
)) return -ENODEV
;
566 restore_flags(flags
);
570 restore_flags(flags
);
572 for (p
=(PD_PARTNS
-1);p
>=0;p
--) {
573 minor
= p
+ unit
*PD_PARTNS
;
574 devp
= MKDEV(MAJOR_NR
, minor
);
577 sb
= get_super(devp
);
578 if (sb
) invalidate_inodes(sb
);
580 invalidate_buffers(devp
);
581 pd_hd
[minor
].start_sect
= 0;
582 pd_hd
[minor
].nr_sects
= 0;
586 resetup_one_dev(&pd_gendisk
,unit
);
589 wake_up(&pd_wait_open
);
596 /* Glue for modules ... */
598 void cleanup_module(void);
600 int init_module(void)
605 { extern paride_init();
613 pd_geninit(&pd_gendisk
);
615 if (!pd_gendisk
.nr_real
) return -1;
618 for (unit
=0;unit
<PD_UNITS
;unit
++)
619 if (PD
.present
) resetup_one_dev(&pd_gendisk
,unit
);
625 void cleanup_module(void)
627 { struct gendisk
**gdp
;
630 unregister_blkdev(MAJOR_NR
,name
);
632 for(gdp
=&gendisk_head
;*gdp
;gdp
=&((*gdp
)->next
))
633 if (*gdp
== &pd_gendisk
) break;
634 if (*gdp
) *gdp
= (*gdp
)->next
;
636 for (unit
=0;unit
<PD_UNITS
;unit
++)
637 if (PD
.present
) pi_release(PI
);
642 #define WR(c,r,v) pi_write_regr(PI,c,r,v)
643 #define RR(c,r) (pi_read_regr(PI,c,r))
645 #define DRIVE (0xa0+0x10*PD.drive)
647 /* ide command interface */
649 static void pd_print_error( int unit
, char * msg
, int status
)
653 printk("%s: %s: status = 0x%x =",PD
.name
,msg
,status
);
654 for(i
=0;i
<18;i
++) if (status
& (1<<i
)) printk(" %s",pd_errs
[i
]);
658 static void pd_reset( int unit
) /* called only for MASTER drive */
668 #define DBMSG(msg) ((verbose>1)?(msg):NULL)
670 static int pd_wait_for( int unit
, int w
, char * msg
) /* polled wait */
678 if (((r
& w
) == w
) && !(r
& STAT_BUSY
)) break;
681 e
= (RR(0,1)<<8) + RR(0,7);
682 if (k
>= PD_SPIN
) e
|= ERR_TMO
;
683 if ((e
& (STAT_ERR
|ERR_TMO
)) && (msg
!= NULL
))
684 pd_print_error(unit
,msg
,e
);
688 static void pd_send_command( int unit
, int n
, int s
, int h
,
689 int c0
, int c1
, int func
)
693 WR(0,1,0); /* the IDE task file */
703 static void pd_ide_command( int unit
, int func
, int block
, int count
)
705 /* Don't use this call if the capacity is zero. */
709 s
= ( block
% PD
.sectors
) + 1;
710 h
= ( block
/ PD
.sectors
) % PD
.heads
;
711 c0
= ( block
/ (PD
.sectors
*PD
.heads
)) % 256;
712 c1
= ( block
/ (PD
.sectors
*PD
.heads
*256));
714 pd_send_command(unit
,count
,s
,h
,c0
,c1
,func
);
717 /* According to the ATA standard, the default CHS geometry should be
718 available following a reset. Some Western Digital drives come up
719 in a mode where only LBA addresses are accepted until the device
720 parameters are initialised.
723 static void pd_init_dev_parms( int unit
)
726 pd_wait_for(unit
,0,DBMSG("before init_dev_parms"));
727 pd_send_command(unit
,PD
.sectors
,0,PD
.heads
-1,0,0,IDE_INIT_DEV_PARMS
);
729 pd_wait_for(unit
,0,"Initialise device parameters");
733 static void pd_doorlock( int unit
, int func
)
736 if (pd_wait_for(unit
,STAT_READY
,"Lock") & STAT_ERR
) {
740 pd_send_command(unit
,1,0,0,0,0,func
);
741 pd_wait_for(unit
,STAT_READY
,"Lock done");
745 static void pd_eject( int unit
)
748 pd_wait_for(unit
,0,DBMSG("before unlock on eject"));
749 pd_send_command(unit
,1,0,0,0,0,IDE_DOORUNLOCK
);
750 pd_wait_for(unit
,0,DBMSG("after unlock on eject"));
751 pd_wait_for(unit
,0,DBMSG("before eject"));
752 pd_send_command(unit
,0,0,0,0,0,IDE_EJECT
);
753 pd_wait_for(unit
,0,DBMSG("after eject"));
757 static void pd_media_check( int unit
)
762 r
= pd_wait_for(unit
,STAT_READY
,DBMSG("before media_check"));
763 if (!(r
& STAT_ERR
)) {
764 pd_send_command(unit
,1,1,0,0,0,IDE_READ_VRFY
);
765 r
= pd_wait_for(unit
,STAT_READY
,DBMSG("RDY after READ_VRFY"));
766 } else PD
.changed
= 1; /* say changed if other error */
769 pd_send_command(unit
,1,0,0,0,0,IDE_ACKCHANGE
);
770 pd_wait_for(unit
,STAT_READY
,DBMSG("RDY after ACKCHANGE"));
771 pd_send_command(unit
,1,1,0,0,0,IDE_READ_VRFY
);
772 r
= pd_wait_for(unit
,STAT_READY
,DBMSG("RDY after VRFY"));
778 static void pd_standby_off( int unit
)
781 pd_wait_for(unit
,0,DBMSG("before STANDBY"));
782 pd_send_command(unit
,0,0,0,0,0,IDE_STANDBY
);
783 pd_wait_for(unit
,0,DBMSG("after STANDBY"));
787 #define word_val(n) ((pd_scratch[2*n]&0xff)+256*(pd_scratch[2*n+1]&0xff))
789 static int pd_identify( int unit
)
792 char id
[PD_ID_LEN
+1];
794 /* WARNING: here there may be dragons. reset() applies to both drives,
795 but we call it only on probing the MASTER. This should allow most
796 common configurations to work, but be warned that a reset can clear
797 settings on the SLAVE drive.
800 if (PD
.drive
== 0) pd_reset(unit
);
804 pd_wait_for(unit
,0,DBMSG("before IDENT"));
805 pd_send_command(unit
,1,0,0,0,0,IDE_IDENTIFY
);
807 if (pd_wait_for(unit
,STAT_DRQ
,DBMSG("IDENT DRQ")) & STAT_ERR
) {
811 pi_read_block(PI
,pd_scratch
,512);
813 PD
.sectors
= word_val(6);
814 PD
.heads
= word_val(3);
815 PD
.cylinders
= word_val(1);
816 PD
.capacity
= PD
.sectors
*PD
.heads
*PD
.cylinders
;
818 for(j
=0;j
<PD_ID_LEN
;j
++) id
[j
^1] = pd_scratch
[j
+PD_ID_OFF
];
820 while ((j
>= 0) && (id
[j
] <= 0x20)) j
--;
823 PD
.removable
= (word_val(0) & 0x80);
825 printk("%s: %s, %s, %d blocks [%dM], (%d/%d/%d), %s media\n",
827 PD
.drive
?"slave":"master",
828 PD
.capacity
,PD
.capacity
/2048,
829 PD
.cylinders
,PD
.heads
,PD
.sectors
,
830 PD
.removable
?"removable":"fixed");
832 if (PD
.capacity
) pd_init_dev_parms(unit
);
833 if (!PD
.standby
) pd_standby_off(unit
);
835 pd_hd
[unit
<<PD_BITS
].nr_sects
= PD
.capacity
;
836 pd_hd
[unit
<<PD_BITS
].start_sect
= 0;
841 static int pd_probe_drive( int unit
)
843 { if (PD
.drive
== -1) {
844 for (PD
.drive
=0;PD
.drive
<=1;PD
.drive
++)
845 if (pd_identify(unit
)) return 1;
848 else return pd_identify(unit
);
851 static int pd_detect( void )
856 if (pd_drive_count
== 0) { /* nothing spec'd - so autoprobe for 1 */
858 if (pi_init(PI
,1,-1,-1,-1,-1,-1,pd_scratch
,
859 PI_PD
,verbose
,PD
.name
)) {
860 if (pd_probe_drive(unit
)) {
863 } else pi_release(PI
);
866 } else for (unit
=0;unit
<PD_UNITS
;unit
++) if (DU
[D_PRT
])
867 if (pi_init(PI
,0,DU
[D_PRT
],DU
[D_MOD
],DU
[D_UNI
],
868 DU
[D_PRO
],DU
[D_DLY
],pd_scratch
,
869 PI_PD
,verbose
,PD
.name
)) {
870 if (pd_probe_drive(unit
)) {
873 } else pi_release(PI
);
876 /* We lie about the number of drives found, as the generic partition
877 scanner assumes that the drives are numbered sequentially from 0.
878 This can result in some bogus error messages if non-sequential
879 drive numbers are used.
884 printk("%s: no valid drive found\n",name
);
888 /* The i/o request engine */
890 static int pd_ready( void )
892 { int unit
= pd_unit
;
894 return (!(RR(1,6) & STAT_BUSY
)) ;
897 static void do_pd_request (void)
899 { struct buffer_head
* bh
;
900 struct request
* req
;
905 if ((!CURRENT
) || (CURRENT
->rq_status
== RQ_INACTIVE
)) return;
908 pd_dev
= MINOR(CURRENT
->rq_dev
);
909 pd_unit
= unit
= DEVICE_NR(CURRENT
->rq_dev
);
910 pd_block
= CURRENT
->sector
;
911 pd_count
= CURRENT
->nr_sectors
;
916 printk("%s: OUCH: b_reqnext != NULL\n",PD
.name
);
918 if ((pd_dev
>= PD_DEVS
) ||
919 ((pd_block
+pd_count
) > pd_hd
[pd_dev
].nr_sects
)) {
924 pd_cmd
= CURRENT
->cmd
;
926 while ((pd_run
<= cluster
) &&
928 (pd_block
+pd_run
== req
->sector
) &&
929 (pd_cmd
== req
->cmd
) &&
930 (pd_dev
== MINOR(req
->rq_dev
)))
931 pd_run
+= req
->nr_sectors
;
933 pd_poffs
= pd_hd
[pd_dev
].start_sect
;
934 pd_block
+= pd_poffs
;
935 pd_buf
= CURRENT
->buffer
;
939 if (pd_cmd
== READ
) pi_do_claimed(PI
,do_pd_read
);
940 else if (pd_cmd
== WRITE
) pi_do_claimed(PI
,do_pd_write
);
947 static void pd_next_buf( int unit
)
951 spin_lock_irqsave(&io_request_lock
,saved_flags
);
953 if (!pd_run
) { spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
960 (CURRENT
->cmd
!= pd_cmd
) ||
961 (MINOR(CURRENT
->rq_dev
) != pd_dev
) ||
962 (CURRENT
->rq_status
== RQ_INACTIVE
) ||
963 (CURRENT
->sector
+pd_poffs
!= pd_block
))
964 printk("%s: OUCH: request list changed unexpectedly\n",
967 pd_count
= CURRENT
->nr_sectors
;
968 pd_buf
= CURRENT
->buffer
;
969 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
972 static void do_pd_read( void )
974 { ps_set_intr(do_pd_read_start
,0,0,nice
);
977 static void do_pd_read_start( void )
979 { int unit
= pd_unit
;
985 if (pd_wait_for(unit
,STAT_READY
,"do_pd_read") & STAT_ERR
) {
987 if (pd_retries
< PD_MAX_RETRIES
) {
989 pi_do_claimed(PI
,do_pd_read_start
);
992 spin_lock_irqsave(&io_request_lock
,saved_flags
);
996 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
999 pd_ide_command(unit
,IDE_READ
,pd_block
,pd_run
);
1000 ps_set_intr(do_pd_read_drq
,pd_ready
,PD_TMO
,nice
);
1003 static void do_pd_read_drq( void )
1005 { int unit
= pd_unit
;
1009 if (pd_wait_for(unit
,STAT_DRQ
,"do_pd_read_drq") & STAT_ERR
) {
1011 if (pd_retries
< PD_MAX_RETRIES
) {
1013 pi_do_claimed(PI
,do_pd_read_start
);
1016 spin_lock_irqsave(&io_request_lock
,saved_flags
);
1020 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
1023 pi_read_block(PI
,pd_buf
,512);
1024 pd_count
--; pd_run
--;
1028 if (!pd_count
) pd_next_buf(unit
);
1031 spin_lock_irqsave(&io_request_lock
,saved_flags
);
1035 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
1038 static void do_pd_write( void )
1040 { ps_set_intr(do_pd_write_start
,0,0,nice
);
1043 static void do_pd_write_start( void )
1045 { int unit
= pd_unit
;
1051 if (pd_wait_for(unit
,STAT_READY
,"do_pd_write") & STAT_ERR
) {
1053 if (pd_retries
< PD_MAX_RETRIES
) {
1055 pi_do_claimed(PI
,do_pd_write_start
);
1058 spin_lock_irqsave(&io_request_lock
,saved_flags
);
1062 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
1065 pd_ide_command(unit
,IDE_WRITE
,pd_block
,pd_run
);
1067 if (pd_wait_for(unit
,STAT_DRQ
,"do_pd_write_drq") & STAT_ERR
) {
1069 if (pd_retries
< PD_MAX_RETRIES
) {
1071 pi_do_claimed(PI
,do_pd_write_start
);
1074 spin_lock_irqsave(&io_request_lock
,saved_flags
);
1078 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
1081 pi_write_block(PI
,pd_buf
,512);
1082 pd_count
--; pd_run
--;
1086 if (!pd_count
) pd_next_buf(unit
);
1088 ps_set_intr(do_pd_write_done
,pd_ready
,PD_TMO
,nice
);
1091 static void do_pd_write_done( void )
1093 { int unit
= pd_unit
;
1096 if (pd_wait_for(unit
,STAT_READY
,"do_pd_write_done") & STAT_ERR
) {
1098 if (pd_retries
< PD_MAX_RETRIES
) {
1100 pi_do_claimed(PI
,do_pd_write_start
);
1103 spin_lock_irqsave(&io_request_lock
,saved_flags
);
1107 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
1111 spin_lock_irqsave(&io_request_lock
,saved_flags
);
1115 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);