1 /* ppa.c -- low level driver for the IOMEGA PPA3
2 * parallel port SCSI host adapter.
4 * (The PPA3 is the embedded controller in the ZIP drive.)
6 * (c) 1995,1996 Grant R. Guenther, grant@torque.net,
7 * under the terms of the GNU Public License.
9 * Current Maintainer: David Campbell (Perth, Western Australia, GMT+0800)
13 #include <linux/config.h>
15 /* The following #define is to avoid a clash with hosts.c */
18 #include <linux/blk.h>
20 #include <linux/parport.h>
23 int ppa_release(struct Scsi_Host
*);
24 static void ppa_reset_pulse(unsigned int base
);
27 struct pardevice
*dev
; /* Parport device entry */
28 int base
; /* Actual port address */
29 int mode
; /* Transfer mode */
30 int host
; /* Host number (for proc) */
31 Scsi_Cmnd
*cur_cmd
; /* Current queued command */
32 struct tq_struct ppa_tq
; /* Polling interupt stuff */
33 unsigned long jstart
; /* Jiffies at start */
34 unsigned int failed
:1; /* Failure flag */
35 unsigned int p_busy
:1; /* Parport sharing busy flag */
41 mode: PPA_AUTODETECT, \
44 ppa_tq: { routine: ppa_interrupt }, \
53 static ppa_struct ppa_hosts
[NO_HOSTS
] =
54 {PPA_EMPTY
, PPA_EMPTY
, PPA_EMPTY
, PPA_EMPTY
};
56 #define PPA_BASE(x) ppa_hosts[(x)].base
58 void ppa_wakeup(void *ref
)
60 ppa_struct
*ppa_dev
= (ppa_struct
*) ref
;
65 if (parport_claim(ppa_dev
->dev
)) {
66 printk("ppa: bug in ppa_wakeup\n");
70 ppa_dev
->base
= ppa_dev
->dev
->port
->base
;
72 ppa_dev
->cur_cmd
->SCp
.phase
++;
76 int ppa_release(struct Scsi_Host
*host
)
78 int host_no
= host
->unique_id
;
80 printk("Releasing ppa%i\n", host_no
);
81 parport_unregister_device(ppa_hosts
[host_no
].dev
);
85 static int ppa_pb_claim(int host_no
)
87 if (parport_claim(ppa_hosts
[host_no
].dev
)) {
88 ppa_hosts
[host_no
].p_busy
= 1;
91 if (ppa_hosts
[host_no
].cur_cmd
)
92 ppa_hosts
[host_no
].cur_cmd
->SCp
.phase
++;
96 #define ppa_pb_release(x) parport_release(ppa_hosts[(x)].dev)
98 /***************************************************************************
99 * Parallel port probing routines *
100 ***************************************************************************/
102 static Scsi_Host_Template driver_template
= PPA
;
103 #include "scsi_module.c"
106 * Start of Chipset kludges
109 int ppa_detect(Scsi_Host_Template
* host
)
111 struct Scsi_Host
*hreg
;
113 int i
, nhosts
, try_again
;
117 * unlock to allow the lowlevel parport driver to probe
120 spin_unlock_irq(&io_request_lock
);
121 pb
= parport_enumerate();
123 printk("ppa: Version %s\n", PPA_VERSION
);
128 printk("ppa: parport reports no devices.\n");
129 spin_lock_irq(&io_request_lock
);
133 for (i
= 0; pb
; i
++, pb
= pb
->next
) {
134 int modes
, ppb
, ppb_hi
;
137 parport_register_device(pb
, "ppa", NULL
, ppa_wakeup
,
138 NULL
, 0, (void *) &ppa_hosts
[i
]);
140 if (!ppa_hosts
[i
].dev
)
143 /* Claim the bus so it remembers what we do to the control
144 * registers. [ CTR and ECP ]
146 if (ppa_pb_claim(i
)) {
147 unsigned long now
= jiffies
;
148 while (ppa_hosts
[i
].p_busy
) {
149 schedule(); /* We are safe to schedule here */
150 if (time_after(jiffies
, now
+ 3 * HZ
)) {
151 printk(KERN_ERR
"ppa%d: failed to claim parport because a "
152 "pardevice is owning the port for too longtime!\n",
154 spin_lock_irq(&io_request_lock
);
159 ppb
= PPA_BASE(i
) = ppa_hosts
[i
].dev
->port
->base
;
160 ppb_hi
= ppa_hosts
[i
].dev
->port
->base_hi
;
162 modes
= ppa_hosts
[i
].dev
->port
->modes
;
164 /* Mode detection works up the chain of speed
165 * This avoids a nasty if-then-else-if-... tree
167 ppa_hosts
[i
].mode
= PPA_NIBBLE
;
169 if (modes
& PARPORT_MODE_TRISTATE
)
170 ppa_hosts
[i
].mode
= PPA_PS2
;
172 if (modes
& PARPORT_MODE_ECP
) {
174 ppa_hosts
[i
].mode
= PPA_PS2
;
176 if ((modes
& PARPORT_MODE_EPP
) && (modes
& PARPORT_MODE_ECP
))
179 /* Done configuration */
183 parport_unregister_device(ppa_hosts
[i
].dev
);
186 /* now the glue ... */
187 switch (ppa_hosts
[i
].mode
) {
199 default: /* Never gets here */
203 host
->can_queue
= PPA_CAN_QUEUE
;
204 host
->sg_tablesize
= ppa_sg
;
205 hreg
= scsi_register(host
, 0);
208 hreg
->io_port
= pb
->base
;
209 hreg
->n_io_port
= ports
;
210 hreg
->dma_channel
= -1;
212 ppa_hosts
[i
].host
= hreg
->host_no
;
216 if (try_again
== 1) {
217 printk("WARNING - no ppa compatible devices found.\n");
218 printk(" As of 31/Aug/1998 Iomega started shipping parallel\n");
219 printk(" port ZIP drives with a different interface which is\n");
220 printk(" supported by the imm (ZIP Plus) driver. If the\n");
221 printk(" cable is marked with \"AutoDetect\", this is what has\n");
222 printk(" happened.\n");
224 spin_lock_irq(&io_request_lock
);
229 spin_lock_irq(&io_request_lock
);
230 return 1; /* return number of hosts detected */
234 /* This is to give the ppa driver a way to modify the timings (and other
235 * parameters) by writing to the /proc/scsi/ppa/0 file.
236 * Very simple method really... (To simple, no error checking :( )
237 * Reason: Kernel hackers HATE having to unload and reload modules for
239 * Also gives a method to use a script to obtain optimum timings (TODO)
242 static inline int ppa_proc_write(int hostno
, char *buffer
, int length
)
246 if ((length
> 5) && (strncmp(buffer
, "mode=", 5) == 0)) {
247 x
= simple_strtoul(buffer
+ 5, NULL
, 0);
248 ppa_hosts
[hostno
].mode
= x
;
251 printk("ppa /proc: invalid variable\n");
255 int ppa_proc_info(char *buffer
, char **start
, off_t offset
,
256 int length
, int hostno
, int inout
)
261 for (i
= 0; i
< 4; i
++)
262 if (ppa_hosts
[i
].host
== hostno
)
266 return ppa_proc_write(i
, buffer
, length
);
268 len
+= sprintf(buffer
+ len
, "Version : %s\n", PPA_VERSION
);
269 len
+= sprintf(buffer
+ len
, "Parport : %s\n", ppa_hosts
[i
].dev
->port
->name
);
270 len
+= sprintf(buffer
+ len
, "Mode : %s\n", PPA_MODE_STRING
[ppa_hosts
[i
].mode
]);
272 /* Request for beyond end of buffer */
276 *start
= buffer
+ offset
;
283 static int device_check(int host_no
);
286 #define ppa_fail(x,y) printk("ppa: ppa_fail(%i) from %s at line %d\n",\
287 y, __FUNCTION__, __LINE__); ppa_fail_func(x,y);
288 static inline void ppa_fail_func(int host_no
, int error_code
)
290 static inline void ppa_fail(int host_no
, int error_code
)
293 /* If we fail a device then we trash status / message bytes */
294 if (ppa_hosts
[host_no
].cur_cmd
) {
295 ppa_hosts
[host_no
].cur_cmd
->result
= error_code
<< 16;
296 ppa_hosts
[host_no
].failed
= 1;
301 * Wait for the high bit to be set.
303 * In principle, this could be tied to an interrupt, but the adapter
304 * doesn't appear to be designed to support interrupts. We spin on
305 * the 0x80 ready bit.
307 static unsigned char ppa_wait(int host_no
)
310 unsigned short ppb
= PPA_BASE(host_no
);
314 /* Wait for bit 6 and 7 - PJC */
315 for (r
= r_str (ppb
); ((r
& 0xc0)!=0xc0) && (k
); k
--) {
321 * return some status information.
322 * Semantics: 0xc0 = ZIP wants more data
323 * 0xd0 = ZIP wants to send more data
324 * 0xe0 = ZIP is expecting SCSI command data
325 * 0xf0 = end of transfer, ZIP is sending status
330 /* Counter expired - Time out occurred */
331 ppa_fail(host_no
, DID_TIME_OUT
);
332 printk("ppa timeout in ppa_wait\n");
333 return 0; /* command timed out */
337 * Clear EPP Timeout Bit
339 static inline void epp_reset(unsigned short ppb
)
345 w_str(ppb
, i
& 0xfe);
349 * Wait for empty ECP fifo (if we are in ECP fifo mode only)
351 static inline void ecp_sync(unsigned short hostno
)
353 int i
, ppb_hi
=ppa_hosts
[hostno
].dev
->port
->base_hi
;
355 if (ppb_hi
== 0) return;
357 if ((r_ecr(ppb_hi
) & 0xe0) == 0x60) { /* mode 011 == ECP fifo mode */
358 for (i
= 0; i
< 100; i
++) {
359 if (r_ecr(ppb_hi
) & 0x01)
363 printk("ppa: ECP sync failed as data still present in FIFO.\n");
367 static int ppa_byte_out(unsigned short base
, const char *buffer
, int len
)
371 for (i
= len
; i
; i
--) {
372 w_dtr(base
, *buffer
++);
376 return 1; /* All went well - we hope! */
379 static int ppa_byte_in(unsigned short base
, char *buffer
, int len
)
383 for (i
= len
; i
; i
--) {
384 *buffer
++ = r_dtr(base
);
388 return 1; /* All went well - we hope! */
391 static int ppa_nibble_in(unsigned short base
, char *buffer
, int len
)
397 h
= r_str(base
) & 0xf0;
399 *buffer
++ = h
| ((r_str(base
) & 0xf0) >> 4);
401 return 1; /* All went well - we hope! */
404 static int ppa_out(int host_no
, char *buffer
, int len
)
407 unsigned short ppb
= PPA_BASE(host_no
);
409 r
= ppa_wait(host_no
);
411 if ((r
& 0x50) != 0x40) {
412 ppa_fail(host_no
, DID_ERROR
);
415 switch (ppa_hosts
[host_no
].mode
) {
418 /* 8 bit output, with a loop */
419 r
= ppa_byte_out(ppb
, buffer
, len
);
427 #ifdef CONFIG_SCSI_IZIP_EPP16
428 if (!(((long) buffer
| len
) & 0x01))
429 outsw(ppb
+ 4, buffer
, len
>> 1);
431 if (!(((long) buffer
| len
) & 0x03))
432 outsl(ppb
+ 4, buffer
, len
>> 2);
435 outsb(ppb
+ 4, buffer
, len
);
437 r
= !(r_str(ppb
) & 0x01);
443 printk("PPA: bug in ppa_out()\n");
449 static int ppa_in(int host_no
, char *buffer
, int len
)
452 unsigned short ppb
= PPA_BASE(host_no
);
454 r
= ppa_wait(host_no
);
456 if ((r
& 0x50) != 0x50) {
457 ppa_fail(host_no
, DID_ERROR
);
460 switch (ppa_hosts
[host_no
].mode
) {
462 /* 4 bit input, with a loop */
463 r
= ppa_nibble_in(ppb
, buffer
, len
);
468 /* 8 bit input, with a loop */
470 r
= ppa_byte_in(ppb
, buffer
, len
);
480 #ifdef CONFIG_SCSI_IZIP_EPP16
481 if (!(((long) buffer
| len
) & 0x01))
482 insw(ppb
+ 4, buffer
, len
>> 1);
484 if (!(((long) buffer
| len
) & 0x03))
485 insl(ppb
+ 4, buffer
, len
>> 2);
488 insb(ppb
+ 4, buffer
, len
);
490 r
= !(r_str(ppb
) & 0x01);
496 printk("PPA: bug in ppa_ins()\n");
503 /* end of ppa_io.h */
504 static inline void ppa_d_pulse(unsigned short ppb
, unsigned char b
)
514 static void ppa_disconnect(int host_no
)
516 unsigned short ppb
= PPA_BASE(host_no
);
519 ppa_d_pulse(ppb
, 0x3c);
520 ppa_d_pulse(ppb
, 0x20);
521 ppa_d_pulse(ppb
, 0xf);
524 static inline void ppa_c_pulse(unsigned short ppb
, unsigned char b
)
533 static inline void ppa_connect(int host_no
, int flag
)
535 unsigned short ppb
= PPA_BASE(host_no
);
538 ppa_c_pulse(ppb
, 0x3c);
539 ppa_c_pulse(ppb
, 0x20);
540 if ((flag
== CONNECT_EPP_MAYBE
) &&
541 IN_EPP_MODE(ppa_hosts
[host_no
].mode
))
542 ppa_c_pulse(ppb
, 0xcf);
544 ppa_c_pulse(ppb
, 0x8f);
547 static int ppa_select(int host_no
, int target
)
550 unsigned short ppb
= PPA_BASE(host_no
);
553 * Bit 6 (0x40) is the device selected bit.
554 * First we must wait till the current device goes off line...
559 } while ((r_str(ppb
) & 0x40) && (k
));
563 w_dtr(ppb
, (1 << target
));
566 w_dtr(ppb
, 0x80); /* This is NOT the initator */
573 while (!(r_str(ppb
) & 0x40) && (k
));
581 * This is based on a trace of what the Iomega DOS 'guest' driver does.
582 * I've tried several different kinds of parallel ports with guest and
583 * coded this to react in the same ways that it does.
585 * The return value from this function is just a hint about where the
586 * handshaking failed.
589 static int ppa_init(int host_no
)
592 unsigned short ppb
= PPA_BASE(host_no
);
594 #if defined(CONFIG_PARPORT) || defined(CONFIG_PARPORT_MODULE)
595 if (ppa_pb_claim(host_no
))
596 while (ppa_hosts
[host_no
].p_busy
)
597 schedule(); /* We can safe schedule here */
600 ppa_disconnect(host_no
);
601 ppa_connect(host_no
, CONNECT_NORMAL
);
603 retv
= 2; /* Failed */
606 if ((r_str(ppb
) & 0x08) == 0x08)
610 if ((r_str(ppb
) & 0x08) == 0x00)
614 ppa_reset_pulse(ppb
);
615 udelay(1000); /* Allow devices to settle down */
616 ppa_disconnect(host_no
);
617 udelay(1000); /* Another delay to allow devices to settle */
620 retv
= device_check(host_no
);
622 ppa_pb_release(host_no
);
626 static inline int ppa_send_command(Scsi_Cmnd
* cmd
)
628 int host_no
= cmd
->host
->unique_id
;
631 w_ctr(PPA_BASE(host_no
), 0x0c);
633 for (k
= 0; k
< cmd
->cmd_len
; k
++)
634 if (!ppa_out(host_no
, &cmd
->cmnd
[k
], 1))
640 * The bulk flag enables some optimisations in the data transfer loops,
641 * it should be true for any command that transfers data in integral
642 * numbers of sectors.
644 * The driver appears to remain stable if we speed up the parallel port
645 * i/o in this function, but not elsewhere.
647 static int ppa_completion(Scsi_Cmnd
* cmd
)
652 * 1 Finished data transfer
654 int host_no
= cmd
->host
->unique_id
;
655 unsigned long start_jiffies
= jiffies
;
658 int fast
, bulk
, status
;
661 bulk
= ((v
== READ_6
) ||
666 r
= ppa_wait(host_no
); /* Need a ppa_wait() - PJC */
668 while (r
!= (unsigned char) 0xf0) {
670 * If we have been running for more than a full timer tick
673 if (time_after(jiffies
, start_jiffies
+ 1))
676 if (((r
& 0xc0) != 0xc0) || (cmd
->SCp
.this_residual
<= 0)) {
677 ppa_fail(host_no
, DID_ERROR
);
678 return -1; /* ERROR_RETURN */
680 /* determine if we should use burst I/O */ fast
= (bulk
&& (cmd
->SCp
.this_residual
>= PPA_BURST_SIZE
))
681 ? PPA_BURST_SIZE
: 1;
683 if (r
== (unsigned char) 0xc0)
684 status
= ppa_out(host_no
, cmd
->SCp
.ptr
, fast
);
686 status
= ppa_in(host_no
, cmd
->SCp
.ptr
, fast
);
688 cmd
->SCp
.ptr
+= fast
;
689 cmd
->SCp
.this_residual
-= fast
;
692 ppa_fail(host_no
, DID_BUS_BUSY
);
693 return -1; /* ERROR_RETURN */
695 if (cmd
->SCp
.buffer
&& !cmd
->SCp
.this_residual
) {
696 /* if scatter/gather, advance to the next segment */
697 if (cmd
->SCp
.buffers_residual
--) {
699 cmd
->SCp
.this_residual
= cmd
->SCp
.buffer
->length
;
700 cmd
->SCp
.ptr
= cmd
->SCp
.buffer
->address
;
703 /* Now check to see if the drive is ready to comunicate */
704 r
= ppa_wait(host_no
); /* need ppa_wait() - PJC */
705 /* If not, drop back down to the scheduler and wait a timer tick */
709 return 1; /* FINISH_RETURN */
712 /* deprecated synchronous interface */
713 int ppa_command(Scsi_Cmnd
* cmd
)
715 static int first_pass
= 1;
716 int host_no
= cmd
->host
->unique_id
;
719 printk("ppa: using non-queuing interface\n");
722 if (ppa_hosts
[host_no
].cur_cmd
) {
723 printk("PPA: bug in ppa_command\n");
726 ppa_hosts
[host_no
].failed
= 0;
727 ppa_hosts
[host_no
].jstart
= jiffies
;
728 ppa_hosts
[host_no
].cur_cmd
= cmd
;
729 cmd
->result
= DID_ERROR
<< 16; /* default return code */
732 ppa_pb_claim(host_no
);
734 while (ppa_engine(&ppa_hosts
[host_no
], cmd
))
737 if (cmd
->SCp
.phase
) /* Only disconnect if we have connected */
738 ppa_disconnect(cmd
->host
->unique_id
);
740 ppa_pb_release(host_no
);
741 ppa_hosts
[host_no
].cur_cmd
= 0;
746 * Since the PPA itself doesn't generate interrupts, we use
747 * the scheduler's task queue to generate a stream of call-backs and
748 * complete the request when the drive is ready.
750 static void ppa_interrupt(void *data
)
752 ppa_struct
*tmp
= (ppa_struct
*) data
;
753 Scsi_Cmnd
*cmd
= tmp
->cur_cmd
;
757 printk("PPA: bug in ppa_interrupt\n");
760 if (ppa_engine(tmp
, cmd
)) {
761 tmp
->ppa_tq
.data
= (void *) tmp
;
762 tmp
->ppa_tq
.sync
= 0;
763 queue_task(&tmp
->ppa_tq
, &tq_timer
);
766 /* Command must of completed hence it is safe to let go... */
768 switch ((cmd
->result
>> 16) & 0xff) {
772 printk("ppa: no device at SCSI ID %i\n", cmd
->target
);
775 printk("ppa: BUS BUSY - EPP timeout detected\n");
778 printk("ppa: unknown timeout\n");
781 printk("ppa: told to abort\n");
784 printk("ppa: parity error (???)\n");
787 printk("ppa: internal driver error\n");
790 printk("ppa: told to reset device\n");
793 printk("ppa: bad interrupt (???)\n");
796 printk("ppa: bad return code (%02x)\n", (cmd
->result
>> 16) & 0xff);
800 if (cmd
->SCp
.phase
> 1)
801 ppa_disconnect(cmd
->host
->unique_id
);
802 if (cmd
->SCp
.phase
> 0)
803 ppa_pb_release(cmd
->host
->unique_id
);
807 spin_lock_irqsave(&io_request_lock
, flags
);
809 spin_unlock_irqrestore(&io_request_lock
, flags
);
813 static int ppa_engine(ppa_struct
* tmp
, Scsi_Cmnd
* cmd
)
815 int host_no
= cmd
->host
->unique_id
;
816 unsigned short ppb
= PPA_BASE(host_no
);
817 unsigned char l
= 0, h
= 0;
820 /* First check for any errors that may of occurred
821 * Here we check for internal errors
826 switch (cmd
->SCp
.phase
) {
827 case 0: /* Phase 0 - Waiting for parport */
828 if ((jiffies
- tmp
->jstart
) > HZ
) {
830 * We waited more than a second
831 * for parport to call us
833 ppa_fail(host_no
, DID_BUS_BUSY
);
836 return 1; /* wait until ppa_wakeup claims parport */
837 case 1: /* Phase 1 - Connected */
838 { /* Perform a sanity check for cable unplugged */
839 int retv
= 2; /* Failed */
841 ppa_connect(host_no
, CONNECT_EPP_MAYBE
);
844 if ((r_str(ppb
) & 0x08) == 0x08)
848 if ((r_str(ppb
) & 0x08) == 0x00)
852 if ((jiffies
- tmp
->jstart
) > (1 * HZ
)) {
853 printk("ppa: Parallel port cable is unplugged!!\n");
854 ppa_fail(host_no
, DID_BUS_BUSY
);
857 ppa_disconnect(host_no
);
858 return 1; /* Try again in a jiffy */
864 case 2: /* Phase 2 - We are now talking to the scsi bus */
865 if (!ppa_select(host_no
, cmd
->target
)) {
866 ppa_fail(host_no
, DID_NO_CONNECT
);
871 case 3: /* Phase 3 - Ready to accept a command */
873 if (!(r_str(ppb
) & 0x80))
876 if (!ppa_send_command(cmd
))
880 case 4: /* Phase 4 - Setup scatter/gather buffers */
882 /* if many buffers are available, start filling the first */
883 cmd
->SCp
.buffer
= (struct scatterlist
*) cmd
->request_buffer
;
884 cmd
->SCp
.this_residual
= cmd
->SCp
.buffer
->length
;
885 cmd
->SCp
.ptr
= cmd
->SCp
.buffer
->address
;
887 /* else fill the only available buffer */
888 cmd
->SCp
.buffer
= NULL
;
889 cmd
->SCp
.this_residual
= cmd
->request_bufflen
;
890 cmd
->SCp
.ptr
= cmd
->request_buffer
;
892 cmd
->SCp
.buffers_residual
= cmd
->use_sg
;
895 case 5: /* Phase 5 - Data transfer stage */
897 if (!(r_str(ppb
) & 0x80))
900 retv
= ppa_completion(cmd
);
907 case 6: /* Phase 6 - Read status/message */
908 cmd
->result
= DID_OK
<< 16;
909 /* Check for data overrun */
910 if (ppa_wait(host_no
) != (unsigned char) 0xf0) {
911 ppa_fail(host_no
, DID_ERROR
);
914 if (ppa_in(host_no
, &l
, 1)) { /* read status byte */
915 /* Check for optional message byte */
916 if (ppa_wait(host_no
) == (unsigned char) 0xf0)
917 ppa_in(host_no
, &h
, 1);
918 cmd
->result
= (DID_OK
<< 16) + (h
<< 8) + (l
& STATUS_MASK
);
920 return 0; /* Finished */
924 printk("ppa: Invalid scsi phase\n");
929 int ppa_queuecommand(Scsi_Cmnd
* cmd
, void (*done
) (Scsi_Cmnd
*))
931 int host_no
= cmd
->host
->unique_id
;
933 if (ppa_hosts
[host_no
].cur_cmd
) {
934 printk("PPA: bug in ppa_queuecommand\n");
937 ppa_hosts
[host_no
].failed
= 0;
938 ppa_hosts
[host_no
].jstart
= jiffies
;
939 ppa_hosts
[host_no
].cur_cmd
= cmd
;
940 cmd
->scsi_done
= done
;
941 cmd
->result
= DID_ERROR
<< 16; /* default return code */
942 cmd
->SCp
.phase
= 0; /* bus free */
944 ppa_pb_claim(host_no
);
946 ppa_hosts
[host_no
].ppa_tq
.data
= ppa_hosts
+ host_no
;
947 ppa_hosts
[host_no
].ppa_tq
.sync
= 0;
948 queue_task(&ppa_hosts
[host_no
].ppa_tq
, &tq_immediate
);
949 mark_bh(IMMEDIATE_BH
);
955 * Apparently the the disk->capacity attribute is off by 1 sector
956 * for all disk drives. We add the one here, but it should really
957 * be done in sd.c. Even if it gets fixed there, this will still
960 int ppa_biosparam(Disk
* disk
, kdev_t dev
, int ip
[])
964 ip
[2] = (disk
->capacity
+ 1) / (ip
[0] * ip
[1]);
968 ip
[2] = (disk
->capacity
+ 1) / (ip
[0] * ip
[1]);
975 int ppa_abort(Scsi_Cmnd
* cmd
)
977 int host_no
= cmd
->host
->unique_id
;
979 * There is no method for aborting commands since Iomega
980 * have tied the SCSI_MESSAGE line high in the interface
983 switch (cmd
->SCp
.phase
) {
984 case 0: /* Do not have access to parport */
985 case 1: /* Have not connected to interface */
986 ppa_hosts
[host_no
].cur_cmd
= NULL
; /* Forget the problem */
989 default: /* SCSI command sent, can not abort */
995 static void ppa_reset_pulse(unsigned int base
)
1003 int ppa_reset(Scsi_Cmnd
* cmd
)
1005 int host_no
= cmd
->host
->unique_id
;
1008 ppa_disconnect(host_no
);
1009 ppa_hosts
[host_no
].cur_cmd
= NULL
; /* Forget the problem */
1011 ppa_connect(host_no
, CONNECT_NORMAL
);
1012 ppa_reset_pulse(PPA_BASE(host_no
));
1013 udelay(1000); /* device settle delay */
1014 ppa_disconnect(host_no
);
1015 udelay(1000); /* device settle delay */
1019 static int device_check(int host_no
)
1021 /* This routine looks for a device and then attempts to use EPP
1022 to send a command. If all goes as planned then EPP is available. */
1024 static char cmd
[6] =
1025 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1026 int loop
, old_mode
, status
, k
, ppb
= PPA_BASE(host_no
);
1029 old_mode
= ppa_hosts
[host_no
].mode
;
1030 for (loop
= 0; loop
< 8; loop
++) {
1031 /* Attempt to use EPP for Test Unit Ready */
1032 if ((ppb
& 0x0007) == 0x0000)
1033 ppa_hosts
[host_no
].mode
= PPA_EPP_32
;
1036 ppa_connect(host_no
, CONNECT_EPP_MAYBE
);
1037 /* Select SCSI device */
1038 if (!ppa_select(host_no
, loop
)) {
1039 ppa_disconnect(host_no
);
1042 printk("ppa: Found device at ID %i, Attempting to use %s\n", loop
,
1043 PPA_MODE_STRING
[ppa_hosts
[host_no
].mode
]);
1045 /* Send SCSI command */
1048 for (l
= 0; (l
< 6) && (status
); l
++)
1049 status
= ppa_out(host_no
, cmd
, 1);
1052 ppa_disconnect(host_no
);
1053 ppa_connect(host_no
, CONNECT_EPP_MAYBE
);
1059 ppa_disconnect(host_no
);
1061 if (ppa_hosts
[host_no
].mode
== PPA_EPP_32
) {
1062 ppa_hosts
[host_no
].mode
= old_mode
;
1065 printk("ppa: Unable to establish communication, aborting driver load.\n");
1069 k
= 1000000; /* 1 Second */
1074 } while (!(l
& 0x80) && (k
));
1079 ppa_disconnect(host_no
);
1080 ppa_connect(host_no
, CONNECT_EPP_MAYBE
);
1081 ppa_reset_pulse(ppb
);
1083 ppa_disconnect(host_no
);
1085 if (ppa_hosts
[host_no
].mode
== PPA_EPP_32
) {
1086 ppa_hosts
[host_no
].mode
= old_mode
;
1089 printk("ppa: Unable to establish communication, aborting driver load.\n");
1092 ppa_disconnect(host_no
);
1093 printk("ppa: Communication established with ID %i using %s\n", loop
,
1094 PPA_MODE_STRING
[ppa_hosts
[host_no
].mode
]);
1095 ppa_connect(host_no
, CONNECT_EPP_MAYBE
);
1096 ppa_reset_pulse(ppb
);
1098 ppa_disconnect(host_no
);
1102 printk("ppa: No devices found, aborting driver load.\n");