2 pf.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 ATAPI disk
6 drives based on chips supported by the paride module.
8 By default, the driver will autoprobe for a single parallel
9 port ATAPI disk drive, but if their individual parameters are
10 specified, the driver can handle up to 4 drives.
12 The behaviour of the pf 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-7 integers as follows:
19 drive3 <prt>,<pro>,<uni>,<mod>,<slv>,<lun>,<dly>
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 <slv> ATAPI CDroms can be jumpered to master or slave.
42 Set this to 0 to choose the master drive, 1 to
43 choose the slave, -1 (the default) to choose the
46 <lun> Some ATAPI devices support multiple LUNs.
47 One example is the ATAPI PD/CD drive from
48 Matshita/Panasonic. This device has a
49 CD drive on LUN 0 and a PD drive on LUN 1.
50 By default, the driver will search for the
51 first LUN with a supported device. Set
52 this parameter to force it to use a specific
55 <dly> some parallel ports require the driver to
56 go more slowly. -1 sets a default value that
57 should work with the chosen protocol. Otherwise,
58 set this to a small integer, the larger it is
59 the slower the port i/o. In some cases, setting
60 this to zero will speed up the device. (default -1)
62 major You may use this parameter to overide the
63 default major number (47) that this driver
64 will use. Be sure to change the device
67 name This parameter is a character string that
68 contains the name the kernel will use for this
69 device (in /proc output, for instance).
72 cluster The driver will attempt to aggregate requests
73 for adjacent blocks into larger multi-block
74 clusters. The maximum cluster size (in 512
75 byte sectors) is set with this parameter.
78 verbose This parameter controls the amount of logging
79 that the driver will do. Set it to 0 for
80 normal operation, 1 to see autoprobe progress
81 messages, or 2 to see additional debugging
84 nice This parameter controls the driver's use of
85 idle CPU time, at the expense of some speed.
87 If this driver is built into the kernel, you can use the
88 following command line parameters, with the same values
89 as the corresponding module parameters listed above:
98 In addition, you can use the parameter pf.disable to disable
105 1.01 GRG 1998.05.03 Changes for SMP. Eliminate sti().
106 Fix for drives that don't clear STAT_ERR
107 until after next CDB delivered.
108 Small change in pf_completion to round
110 1.02 GRG 1998.06.16 Eliminated an Ugh
111 1.03 GRG 1998.08.16 Use HZ in loop timings, extra debugging
112 1.04 GRG 1998.09.24 Added jumbo support
116 #define PF_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
= PF_MAJOR
;
129 static char *name
= PF_NAME
;
130 static int cluster
= 64;
132 static int disable
= 0;
134 static int drive0
[7] = {0,0,0,-1,-1,-1,-1};
135 static int drive1
[7] = {0,0,0,-1,-1,-1,-1};
136 static int drive2
[7] = {0,0,0,-1,-1,-1,-1};
137 static int drive3
[7] = {0,0,0,-1,-1,-1,-1};
139 static int (*drives
[4])[7] = {&drive0
,&drive1
,&drive2
,&drive3
};
140 static int pf_drive_count
;
150 #define DU (*drives[unit])
152 /* 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>
163 #include <linux/spinlock.h>
165 #include <asm/uaccess.h>
171 static STT pf_stt
[7] = {{"drive0",7,drive0
},
175 {"disable",1,&disable
},
176 {"cluster",1,&cluster
},
179 void pf_setup( char *str
, int *ints
)
181 { generic_setup(pf_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-7i");
192 MODULE_PARM(drive1
,"1-7i");
193 MODULE_PARM(drive2
,"1-7i");
194 MODULE_PARM(drive3
,"1-7i");
198 /* set up defines for blk.h, why don't all drivers do it this way ? */
200 #define MAJOR_NR major
201 #define DEVICE_NAME "PF"
202 #define DEVICE_REQUEST do_pf_request
203 #define DEVICE_NR(device) MINOR(device)
204 #define DEVICE_ON(device)
205 #define DEVICE_OFF(device)
207 #include <linux/blk.h>
208 #include <linux/blkpg.h>
212 /* constants for faking geometry numbers */
214 #define PF_FD_MAX 8192 /* use FD geometry under this size */
220 #define PF_MAX_RETRIES 5
221 #define PF_TMO 800 /* interrupt timeout in jiffies */
222 #define PF_SPIN_DEL 50 /* spin delay in micro-seconds */
224 #define PF_SPIN (1000000*PF_TMO)/(HZ*PF_SPIN_DEL)
226 #define STAT_ERR 0x00001
227 #define STAT_INDEX 0x00002
228 #define STAT_ECC 0x00004
229 #define STAT_DRQ 0x00008
230 #define STAT_SEEK 0x00010
231 #define STAT_WRERR 0x00020
232 #define STAT_READY 0x00040
233 #define STAT_BUSY 0x00080
235 #define ATAPI_REQ_SENSE 0x03
236 #define ATAPI_LOCK 0x1e
237 #define ATAPI_DOOR 0x1b
238 #define ATAPI_MODE_SENSE 0x5a
239 #define ATAPI_CAPACITY 0x25
240 #define ATAPI_IDENTIFY 0x12
241 #define ATAPI_READ_10 0x28
242 #define ATAPI_WRITE_10 0x2a
246 void cleanup_module( void );
248 static int pf_open(struct inode
*inode
, struct file
*file
);
249 static void do_pf_request(request_queue_t
* q
);
250 static int pf_ioctl(struct inode
*inode
,struct file
*file
,
251 unsigned int cmd
, unsigned long arg
);
253 static int pf_release (struct inode
*inode
, struct file
*file
);
255 static int pf_detect(void);
256 static void do_pf_read(void);
257 static void do_pf_read_start(void);
258 static void do_pf_write(void);
259 static void do_pf_write_start(void);
260 static void do_pf_read_drq( void );
261 static void do_pf_write_done( void );
263 static int pf_identify (int unit
);
264 static void pf_lock(int unit
, int func
);
265 static void pf_eject(int unit
);
266 static int pf_check_media(kdev_t dev
);
268 static int pf_blocksizes
[PF_UNITS
];
277 struct pi_adapter pia
; /* interface to paride layer */
278 struct pi_adapter
*pi
;
279 int removable
; /* removable media device ? */
280 int media_status
; /* media present ? WP ? */
281 int drive
; /* drive */
283 int access
; /* count of active opens ... */
284 int capacity
; /* Size of this volume in sectors */
285 int present
; /* device present ? */
286 char name
[PF_NAMELEN
]; /* pf0, pf1, ... */
289 struct pf_unit pf
[PF_UNITS
];
291 /* 'unit' must be defined in all functions - either as a local or a param */
296 static char pf_scratch
[512]; /* scratch block buffer */
298 /* the variables below are used mainly in the I/O request engine, which
299 processes only one request at a time.
302 static int pf_retries
= 0; /* i/o error retry count */
303 static int pf_busy
= 0; /* request being processed ? */
304 static int pf_block
; /* address of next requested block */
305 static int pf_count
; /* number of blocks still to do */
306 static int pf_run
; /* sectors in current cluster */
307 static int pf_cmd
; /* current command READ/WRITE */
308 static int pf_unit
; /* unit of current request */
309 static int pf_mask
; /* stopper for pseudo-int */
310 static char * pf_buf
; /* buffer for request in progress */
312 /* kernel glue structures */
314 static struct block_device_operations pf_fops
= {
318 check_media_change
: pf_check_media
,
321 void pf_init_units( void )
326 for (unit
=0;unit
<PF_UNITS
;unit
++) {
329 PF
.media_status
= PF_NM
;
332 PF
.drive
= DU
[D_SLV
];
335 while ((j
< PF_NAMELEN
-2) && (PF
.name
[j
]=name
[j
])) j
++;
336 PF
.name
[j
++] = '0' + unit
;
338 if (DU
[D_PRT
]) pf_drive_count
++;
342 static inline int pf_new_segment(request_queue_t
*q
, struct request
*req
, int max_segments
)
344 if (max_segments
> cluster
)
345 max_segments
= cluster
;
347 if (req
->nr_segments
< max_segments
) {
349 q
->elevator
.nr_segments
++;
355 static int pf_back_merge_fn(request_queue_t
*q
, struct request
*req
,
356 struct buffer_head
*bh
, int max_segments
)
358 if (req
->bhtail
->b_data
+ req
->bhtail
->b_size
== bh
->b_data
)
360 return pf_new_segment(q
, req
, max_segments
);
363 static int pf_front_merge_fn(request_queue_t
*q
, struct request
*req
,
364 struct buffer_head
*bh
, int max_segments
)
366 if (bh
->b_data
+ bh
->b_size
== req
->bh
->b_data
)
368 return pf_new_segment(q
, req
, max_segments
);
371 static int pf_merge_requests_fn(request_queue_t
*q
, struct request
*req
,
372 struct request
*next
, int max_segments
)
374 int total_segments
= req
->nr_segments
+ next
->nr_segments
;
377 if (max_segments
> cluster
)
378 max_segments
= cluster
;
381 if (req
->bhtail
->b_data
+ req
->bhtail
->b_size
== next
->bh
->b_data
) {
386 if (total_segments
> max_segments
)
389 q
->elevator
.nr_segments
-= same_segment
;
390 req
->nr_segments
= total_segments
;
394 int pf_init (void) /* preliminary initialisation */
399 if (disable
) return -1;
403 if (pf_detect()) return -1;
406 if (register_blkdev(MAJOR_NR
,name
,&pf_fops
)) {
407 printk("pf_init: unable to get major number %d\n",
411 q
= BLK_DEFAULT_QUEUE(MAJOR_NR
);
412 blk_init_queue(q
, DEVICE_REQUEST
);
413 q
->back_merge_fn
= pf_back_merge_fn
;
414 q
->front_merge_fn
= pf_front_merge_fn
;
415 q
->merge_requests_fn
= pf_merge_requests_fn
;
416 read_ahead
[MAJOR_NR
] = 8; /* 8 sector (4kB) read ahead */
418 for (i
=0;i
<PF_UNITS
;i
++) pf_blocksizes
[i
] = 1024;
419 blksize_size
[MAJOR_NR
] = pf_blocksizes
;
420 for (i
=0;i
<PF_UNITS
;i
++)
421 register_disk(NULL
, MKDEV(MAJOR_NR
, i
), 1, &pf_fops
, 0);
426 static int pf_open (struct inode
*inode
, struct file
*file
)
428 { int unit
= DEVICE_NR(inode
->i_rdev
);
430 if ((unit
>= PF_UNITS
) || (!PF
.present
)) return -ENODEV
;
436 if (PF
.media_status
== PF_NM
) {
441 if ((PF
.media_status
== PF_RO
) && (file
->f_mode
& 2)) {
447 if (PF
.removable
) pf_lock(unit
,1);
452 static int pf_ioctl(struct inode
*inode
,struct file
*file
,
453 unsigned int cmd
, unsigned long arg
)
456 struct hd_geometry
*geo
= (struct hd_geometry
*) arg
;
458 if ((!inode
) || (!inode
->i_rdev
)) return -EINVAL
;
459 unit
= DEVICE_NR(inode
->i_rdev
);
460 if (unit
>= PF_UNITS
) return -EINVAL
;
461 if (!PF
.present
) return -ENODEV
;
465 if (PF
.access
== 1) {
470 if (!geo
) return -EINVAL
;
471 err
= verify_area(VERIFY_WRITE
,geo
,sizeof(*geo
));
473 if (PF
.capacity
< PF_FD_MAX
) {
474 put_user(PF
.capacity
/(PF_FD_HDS
*PF_FD_SPT
),
475 (short *) &geo
->cylinders
);
476 put_user(PF_FD_HDS
, (char *) &geo
->heads
);
477 put_user(PF_FD_SPT
, (char *) &geo
->sectors
);
479 put_user(PF
.capacity
/(PF_HD_HDS
*PF_HD_SPT
),
480 (short *) &geo
->cylinders
);
481 put_user(PF_HD_HDS
, (char *) &geo
->heads
);
482 put_user(PF_HD_SPT
, (char *) &geo
->sectors
);
484 put_user(0,(long *)&geo
->start
);
487 if (!arg
) return -EINVAL
;
488 err
= verify_area(VERIFY_WRITE
,(long *) arg
,sizeof(long));
489 if (err
) return (err
);
490 put_user(PF
.capacity
,(long *) arg
);
497 return blk_ioctl(inode
->i_rdev
, cmd
, arg
);
504 static int pf_release (struct inode
*inode
, struct file
*file
)
509 devp
= inode
->i_rdev
;
510 unit
= DEVICE_NR(devp
);
512 if ((unit
>= PF_UNITS
) || (PF
.access
<= 0))
517 if (!PF
.access
&& PF
.removable
)
526 static int pf_check_media( kdev_t dev
)
533 /* Glue for modules ... */
535 void cleanup_module(void);
537 int init_module(void)
542 { extern paride_init();
552 void cleanup_module(void)
556 unregister_blkdev(MAJOR_NR
,name
);
558 for (unit
=0;unit
<PF_UNITS
;unit
++)
559 if (PF
.present
) pi_release(PI
);
564 #define WR(c,r,v) pi_write_regr(PI,c,r,v)
565 #define RR(c,r) (pi_read_regr(PI,c,r))
567 #define LUN (0x20*PF.lun)
568 #define DRIVE (0xa0+0x10*PF.drive)
570 static int pf_wait( int unit
, int go
, int stop
, char * fun
, char * msg
)
575 while ((((r
=RR(1,6))&go
)||(stop
&&(!(r
&stop
))))&&(j
++<PF_SPIN
))
578 if ((r
&(STAT_ERR
&stop
))||(j
>=PF_SPIN
)) {
582 if (j
>= PF_SPIN
) e
|= 0x100;
583 if (fun
) printk("%s: %s %s: alt=0x%x stat=0x%x err=0x%x"
584 " loop=%d phase=%d\n",
585 PF
.name
,fun
,msg
,r
,s
,e
,j
,p
);
591 static int pf_command( int unit
, char * cmd
, int dlen
, char * fun
)
597 if (pf_wait(unit
,STAT_BUSY
|STAT_DRQ
,0,fun
,"before command")) {
604 WR(0,7,0xa0); /* ATAPI packet command */
606 if (pf_wait(unit
,STAT_BUSY
,STAT_DRQ
,fun
,"command DRQ")) {
612 printk("%s: %s: command phase error\n",PF
.name
,fun
);
617 pi_write_block(PI
,cmd
,12);
622 static int pf_completion( int unit
, char * buf
, char * fun
)
626 r
= pf_wait(unit
,STAT_BUSY
,STAT_DRQ
|STAT_READY
|STAT_ERR
,
629 if ((RR(0,2)&2) && (RR(0,7)&STAT_DRQ
)) {
630 n
= (((RR(0,4)+256*RR(0,5))+3)&0xfffc);
631 pi_read_block(PI
,buf
,n
);
634 s
= pf_wait(unit
,STAT_BUSY
,STAT_READY
|STAT_ERR
,fun
,"data done");
641 static void pf_req_sense( int unit
, int quiet
)
643 { char rs_cmd
[12] = { ATAPI_REQ_SENSE
,LUN
,0,0,16,0,0,0,0,0,0,0 };
647 r
= pf_command(unit
,rs_cmd
,16,"Request sense");
649 if (!r
) pf_completion(unit
,buf
,"Request sense");
652 printk("%s: Sense key: %x, ASC: %x, ASQ: %x\n",
653 PF
.name
,buf
[2]&0xf,buf
[12],buf
[13]);
656 static int pf_atapi( int unit
, char * cmd
, int dlen
, char * buf
, char * fun
)
660 r
= pf_command(unit
,cmd
,dlen
,fun
);
662 if (!r
) r
= pf_completion(unit
,buf
,fun
);
663 if (r
) pf_req_sense(unit
,!fun
);
668 #define DBMSG(msg) ((verbose>1)?(msg):NULL)
670 static void pf_lock(int unit
, int func
)
672 { char lo_cmd
[12] = { ATAPI_LOCK
,LUN
,0,0,func
,0,0,0,0,0,0,0 };
674 pf_atapi(unit
,lo_cmd
,0,pf_scratch
,func
?"unlock":"lock");
678 static void pf_eject( int unit
)
680 { char ej_cmd
[12] = { ATAPI_DOOR
,LUN
,0,0,2,0,0,0,0,0,0,0 };
683 pf_atapi(unit
,ej_cmd
,0,pf_scratch
,"eject");
686 #define PF_RESET_TMO 30 /* in tenths of a second */
688 static void pf_sleep( int cs
)
690 { current
->state
= TASK_INTERRUPTIBLE
;
691 schedule_timeout(cs
);
695 static int pf_reset( int unit
)
697 /* the ATAPI standard actually specifies the contents of all 7 registers
698 after a reset, but the specification is ambiguous concerning the last
699 two bytes, and different drives interpret the standard differently.
703 int expect
[5] = {1,1,1,0x14,0xeb};
709 pf_sleep(20*HZ
/1000);
712 while ((k
++ < PF_RESET_TMO
) && (RR(1,6)&STAT_BUSY
))
716 for(i
=0;i
<5;i
++) flg
&= (RR(0,i
+1) == expect
[i
]);
719 printk("%s: Reset (%d) signature = ",PF
.name
,k
);
720 for (i
=0;i
<5;i
++) printk("%3x",RR(0,i
+1));
721 if (!flg
) printk(" (incorrect)");
729 static void pf_mode_sense( int unit
)
731 { char ms_cmd
[12] = { ATAPI_MODE_SENSE
,LUN
,0,0,0,0,0,0,8,0,0,0};
734 pf_atapi(unit
,ms_cmd
,8,buf
,DBMSG("mode sense"));
735 PF
.media_status
= PF_RW
;
736 if (buf
[3] & 0x80) PF
.media_status
= PF_RO
;
739 static void xs( char *buf
, char *targ
, int offs
, int len
)
745 if((buf
[k
+offs
]!=0x20)||(buf
[k
+offs
]!=l
))
746 l
=targ
[j
++]=buf
[k
+offs
];
747 if (l
==0x20) j
--; targ
[j
]=0;
750 static int xl( char *buf
, int offs
)
755 for(k
=0;k
<4;k
++) v
=v
*256+(buf
[k
+offs
]&0xff);
759 static void pf_get_capacity( int unit
)
761 { char rc_cmd
[12] = { ATAPI_CAPACITY
,LUN
,0,0,0,0,0,0,0,0,0,0};
765 if (pf_atapi(unit
,rc_cmd
,8,buf
,DBMSG("get capacity"))) {
766 PF
.media_status
= PF_NM
;
769 PF
.capacity
= xl(buf
,0) + 1;
773 if (verbose
) printk("%s: Drive %d, LUN %d,"
774 " unsupported block size %d\n",
775 PF
.name
,PF
.drive
,PF
.lun
,bs
);
779 static int pf_identify( int unit
)
782 char *ms
[2] = {"master","slave"};
784 char id_cmd
[12] = { ATAPI_IDENTIFY
,LUN
,0,0,36,0,0,0,0,0,0,0};
787 s
= pf_atapi(unit
,id_cmd
,36,buf
,"identify");
791 if ((dt
!= 0) && (dt
!= 7)) {
793 printk("%s: Drive %d, LUN %d, unsupported type %d\n",
794 PF
.name
,PF
.drive
,PF
.lun
,dt
);
801 PF
.removable
= (buf
[1] & 0x80);
807 pf_get_capacity(unit
);
809 printk("%s: %s %s, %s LUN %d, type %d",
810 PF
.name
,mf
,id
,ms
[PF
.drive
],PF
.lun
,dt
);
811 if (PF
.removable
) printk(", removable");
812 if (PF
.media_status
== PF_NM
)
813 printk(", no media\n");
814 else { if (PF
.media_status
== PF_RO
) printk(", RO");
815 printk(", %d blocks\n",PF
.capacity
);
821 static int pf_probe( int unit
)
823 /* returns 0, with id set if drive is detected
824 -1, if drive detection failed
827 { if (PF
.drive
== -1) {
828 for (PF
.drive
=0;PF
.drive
<=1;PF
.drive
++)
829 if (!pf_reset(unit
)) {
830 if (PF
.lun
!= -1) return pf_identify(unit
);
831 else for (PF
.lun
=0;PF
.lun
<8;PF
.lun
++)
832 if (!pf_identify(unit
)) return 0;
835 if (pf_reset(unit
)) return -1;
836 if (PF
.lun
!= -1) return pf_identify(unit
);
837 for (PF
.lun
=0;PF
.lun
<8;PF
.lun
++)
838 if (!pf_identify(unit
)) return 0;
843 static int pf_detect( void )
847 printk("%s: %s version %s, major %d, cluster %d, nice %d\n",
848 name
,name
,PF_VERSION
,major
,cluster
,nice
);
851 if (pf_drive_count
== 0) {
853 if (pi_init(PI
,1,-1,-1,-1,-1,-1,pf_scratch
,
854 PI_PF
,verbose
,PF
.name
)) {
855 if (!pf_probe(unit
)) {
858 } else pi_release(PI
);
861 } else for (unit
=0;unit
<PF_UNITS
;unit
++) if (DU
[D_PRT
])
862 if (pi_init(PI
,0,DU
[D_PRT
],DU
[D_MOD
],DU
[D_UNI
],
863 DU
[D_PRO
],DU
[D_DLY
],pf_scratch
,PI_PF
,verbose
,
865 if (!pf_probe(unit
)) {
868 } else pi_release(PI
);
873 printk("%s: No ATAPI disk detected\n",name
);
877 /* The i/o request engine */
879 static int pf_start( int unit
, int cmd
, int b
, int c
)
882 char io_cmd
[12] = {cmd
,LUN
,0,0,0,0,0,0,0,0,0,0};
885 io_cmd
[5-i
] = b
& 0xff;
889 io_cmd
[8] = c
& 0xff;
890 io_cmd
[7] = (c
>> 8) & 0xff;
892 i
= pf_command(unit
,io_cmd
,c
*512,"start i/o");
899 static int pf_ready( void )
901 { int unit
= pf_unit
;
903 return (((RR(1,6)&(STAT_BUSY
|pf_mask
)) == pf_mask
));
906 static void do_pf_request (request_queue_t
* q
)
908 { struct buffer_head
* bh
;
913 if (QUEUE_EMPTY
|| (CURRENT
->rq_status
== RQ_INACTIVE
)) return;
916 pf_unit
= unit
= DEVICE_NR(CURRENT
->rq_dev
);
917 pf_block
= CURRENT
->sector
;
918 pf_run
= CURRENT
->nr_sectors
;
919 pf_count
= CURRENT
->current_nr_sectors
;
923 if ((pf_unit
>= PF_UNITS
) || (pf_block
+pf_count
> PF
.capacity
)) {
928 pf_cmd
= CURRENT
->cmd
;
929 pf_buf
= CURRENT
->buffer
;
933 if (pf_cmd
== READ
) pi_do_claimed(PI
,do_pf_read
);
934 else if (pf_cmd
== WRITE
) pi_do_claimed(PI
,do_pf_write
);
941 static void pf_next_buf( int unit
)
945 spin_lock_irqsave(&io_request_lock
,saved_flags
);
947 if (!pf_run
) { spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
954 (CURRENT
->cmd
!= pf_cmd
) ||
955 (DEVICE_NR(CURRENT
->rq_dev
) != pf_unit
) ||
956 (CURRENT
->rq_status
== RQ_INACTIVE
) ||
957 (CURRENT
->sector
!= pf_block
))
958 printk("%s: OUCH: request list changed unexpectedly\n",
961 pf_count
= CURRENT
->current_nr_sectors
;
962 pf_buf
= CURRENT
->buffer
;
963 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
966 static void do_pf_read( void )
968 /* detach from the calling context - in case the spinlock is held */
970 { ps_set_intr(do_pf_read_start
,0,0,nice
);
973 static void do_pf_read_start( void )
975 { int unit
= pf_unit
;
980 if (pf_start(unit
,ATAPI_READ_10
,pf_block
,pf_run
)) {
982 if (pf_retries
< PF_MAX_RETRIES
) {
984 pi_do_claimed(PI
,do_pf_read_start
);
987 spin_lock_irqsave(&io_request_lock
,saved_flags
);
991 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
995 ps_set_intr(do_pf_read_drq
,pf_ready
,PF_TMO
,nice
);
998 static void do_pf_read_drq( void )
1000 { int unit
= pf_unit
;
1004 if (pf_wait(unit
,STAT_BUSY
,STAT_DRQ
|STAT_ERR
,
1005 "read block","completion") & STAT_ERR
) {
1007 if (pf_retries
< PF_MAX_RETRIES
) {
1008 pf_req_sense(unit
,0);
1010 pi_do_claimed(PI
,do_pf_read_start
);
1013 spin_lock_irqsave(&io_request_lock
,saved_flags
);
1016 do_pf_request(NULL
);
1017 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
1020 pi_read_block(PI
,pf_buf
,512);
1021 pf_count
--; pf_run
--;
1025 if (!pf_count
) pf_next_buf(unit
);
1028 spin_lock_irqsave(&io_request_lock
,saved_flags
);
1031 do_pf_request(NULL
);
1032 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
1035 static void do_pf_write( void )
1037 { ps_set_intr(do_pf_write_start
,0,0,nice
);
1040 static void do_pf_write_start( void )
1042 { int unit
= pf_unit
;
1047 if (pf_start(unit
,ATAPI_WRITE_10
,pf_block
,pf_run
)) {
1049 if (pf_retries
< PF_MAX_RETRIES
) {
1051 pi_do_claimed(PI
,do_pf_write_start
);
1054 spin_lock_irqsave(&io_request_lock
,saved_flags
);
1057 do_pf_request(NULL
);
1058 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
1063 if (pf_wait(unit
,STAT_BUSY
,STAT_DRQ
|STAT_ERR
,
1064 "write block","data wait") & STAT_ERR
) {
1066 if (pf_retries
< PF_MAX_RETRIES
) {
1068 pi_do_claimed(PI
,do_pf_write_start
);
1071 spin_lock_irqsave(&io_request_lock
,saved_flags
);
1074 do_pf_request(NULL
);
1075 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
1078 pi_write_block(PI
,pf_buf
,512);
1079 pf_count
--; pf_run
--;
1083 if (!pf_count
) pf_next_buf(unit
);
1086 ps_set_intr(do_pf_write_done
,pf_ready
,PF_TMO
,nice
);
1089 static void do_pf_write_done( void )
1091 { int unit
= pf_unit
;
1094 if (pf_wait(unit
,STAT_BUSY
,0,"write block","done") & STAT_ERR
) {
1096 if (pf_retries
< PF_MAX_RETRIES
) {
1098 pi_do_claimed(PI
,do_pf_write_start
);
1101 spin_lock_irqsave(&io_request_lock
,saved_flags
);
1104 do_pf_request(NULL
);
1105 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);
1109 spin_lock_irqsave(&io_request_lock
,saved_flags
);
1112 do_pf_request(NULL
);
1113 spin_unlock_irqrestore(&io_request_lock
,saved_flags
);