1 /* imm.c -- low level driver for the IOMEGA MatchMaker
2 * parallel port SCSI host adapter.
4 * (The IMM is the embedded controller in the ZIP Plus drive.)
6 * Current Maintainer: David Campbell (Perth, Western Australia)
9 * My unoffical company acronym list is 21 pages long:
10 * FLA: Four letter acronym with built in facility for
11 * future expansion to five letters.
14 #include <linux/config.h>
16 /* The following #define is to avoid a clash with hosts.c */
18 #define IMM_PROBE_SPP 0x0001
19 #define IMM_PROBE_PS2 0x0002
20 #define IMM_PROBE_ECR 0x0010
21 #define IMM_PROBE_EPP17 0x0100
22 #define IMM_PROBE_EPP19 0x0200
24 void imm_reset_pulse(unsigned int base);
25 static int device_check(int host_no);
27 #include <linux/blk.h>
29 #include <linux/parport.h>
33 struct pardevice *dev; /* Parport device entry */
34 int base; /* Actual port address */
35 int base_hi; /* Hi Base address for ECP-ISA chipset */
36 int mode; /* Transfer mode */
37 int host; /* Host number (for proc) */
38 Scsi_Cmnd *cur_cmd; /* Current queued command */
39 struct tq_struct imm_tq; /* Polling interrupt stuff */
40 unsigned long jstart; /* Jiffies at start */
41 unsigned failed:1; /* Failure flag */
42 unsigned dp:1; /* Data phase present */
43 unsigned rd:1; /* Read data in data phase */
44 unsigned p_busy:1; /* Parport sharing busy flag */
51 mode: IMM_AUTODETECT, \
54 imm_tq: { routine: imm_interrupt }, \
64 static imm_struct imm_hosts[NO_HOSTS] =
65 {IMM_EMPTY, IMM_EMPTY, IMM_EMPTY, IMM_EMPTY};
67 #define IMM_BASE(x) imm_hosts[(x)].base
68 #define IMM_BASE_HI(x) imm_hosts[(x)].base_hi
70 int parbus_base[NO_HOSTS] =
71 {0x03bc, 0x0378, 0x0278, 0x0000};
73 void imm_wakeup(void *ref)
75 imm_struct *imm_dev = (imm_struct *) ref;
80 if (parport_claim(imm_dev->dev)) {
81 printk("imm: bug in imm_wakeup\n");
85 imm_dev->base = imm_dev->dev->port->base;
87 imm_dev->cur_cmd->SCp.phase++;
91 int imm_release(struct Scsi_Host *host)
93 int host_no = host->unique_id;
95 printk("Releasing imm%i\n", host_no);
96 parport_unregister_device(imm_hosts[host_no].dev);
100 static int imm_pb_claim(int host_no)
102 if (parport_claim(imm_hosts[host_no].dev)) {
103 imm_hosts[host_no].p_busy = 1;
106 if (imm_hosts[host_no].cur_cmd)
107 imm_hosts[host_no].cur_cmd->SCp.phase++;
111 #define imm_pb_release(x) parport_release(imm_hosts[(x)].dev)
113 /***************************************************************************
114 * Parallel port probing routines *
115 ***************************************************************************/
117 static Scsi_Host_Template driver_template = IMM;
118 #include "scsi_module.c"
120 int imm_detect(Scsi_Host_Template * host)
122 struct Scsi_Host *hreg;
124 int i, nhosts, try_again;
128 * unlock to allow the lowlevel parport driver to probe
131 spin_unlock_irq(&io_request_lock);
132 pb = parport_enumerate();
134 printk("imm: Version %s\n", IMM_VERSION);
139 printk("imm: parport reports no devices.\n");
140 spin_lock_irq(&io_request_lock);
144 for (i = 0; pb; i++, pb = pb->next) {
148 parport_register_device(pb, "imm", NULL, imm_wakeup,
149 NULL, 0, (void *) &imm_hosts[i]);
151 if (!imm_hosts[i].dev)
154 /* Claim the bus so it remembers what we do to the control
155 * registers. [ CTR and ECP ]
157 if (imm_pb_claim(i)) {
158 unsigned long now = jiffies;
159 while (imm_hosts[i].p_busy) {
160 schedule(); /* We are safe to schedule here */
161 if (time_after(jiffies, now + 3 * HZ)) {
162 printk(KERN_ERR "imm%d: failed to claim parport because a "
163 "pardevice is owning the port for too longtime!\n",
165 parport_unregister_device (imm_hosts[i].dev);
166 spin_lock_irq(&io_request_lock);
171 ppb = IMM_BASE(i) = imm_hosts[i].dev->port->base;
172 IMM_BASE_HI(i) = imm_hosts[i].dev->port->base_hi;
174 modes = imm_hosts[i].dev->port->modes;
176 /* Mode detection works up the chain of speed
177 * This avoids a nasty if-then-else-if-... tree
179 imm_hosts[i].mode = IMM_NIBBLE;
181 if (modes & PARPORT_MODE_TRISTATE)
182 imm_hosts[i].mode = IMM_PS2;
184 /* Done configuration */
188 parport_unregister_device(imm_hosts[i].dev);
191 /* now the glue ... */
192 switch (imm_hosts[i].mode) {
204 default: /* Never gets here */
208 host->can_queue = IMM_CAN_QUEUE;
209 host->sg_tablesize = imm_sg;
210 hreg = scsi_register(host, 0);
213 hreg->io_port = pb->base;
214 hreg->n_io_port = ports;
215 hreg->dma_channel = -1;
217 imm_hosts[i].host = hreg->host_no;
221 if (try_again == 1) {
222 spin_lock_irq(&io_request_lock);
228 spin_lock_irq (&io_request_lock);
229 return 1; /* return number of hosts detected */
233 /* This is to give the imm driver a way to modify the timings (and other
234 * parameters) by writing to the /proc/scsi/imm/0 file.
235 * Very simple method really... (To simple, no error checking :( )
236 * Reason: Kernel hackers HATE having to unload and reload modules for
238 * Also gives a method to use a script to obtain optimum timings (TODO)
240 static inline int imm_proc_write(int hostno, char *buffer, int length)
244 if ((length > 5) && (strncmp(buffer, "mode=", 5) == 0)) {
245 x = simple_strtoul(buffer + 5, NULL, 0);
246 imm_hosts[hostno].mode = x;
249 printk("imm /proc: invalid variable\n");
253 int imm_proc_info(char *buffer, char **start, off_t offset,
254 int length, int hostno, int inout)
259 for (i = 0; i < 4; i++)
260 if (imm_hosts[i].host == hostno)
264 return imm_proc_write(i, buffer, length);
266 len += sprintf(buffer + len, "Version : %s\n", IMM_VERSION);
267 len += sprintf(buffer + len, "Parport : %s\n", imm_hosts[i].dev->port->name);
268 len += sprintf(buffer + len, "Mode : %s\n", IMM_MODE_STRING[imm_hosts[i].mode]);
270 /* Request for beyond end of buffer */
274 *start = buffer + offset;
282 #define imm_fail(x,y) printk("imm: imm_fail(%i) from %s at line %d\n",\
283 y, __FUNCTION__, __LINE__); imm_fail_func(x,y);
284 static inline void imm_fail_func(int host_no, int error_code)
286 static inline void imm_fail(int host_no, int error_code)
289 /* If we fail a device then we trash status / message bytes */
290 if (imm_hosts[host_no].cur_cmd) {
291 imm_hosts[host_no].cur_cmd->result = error_code << 16;
292 imm_hosts[host_no].failed = 1;
297 * Wait for the high bit to be set.
299 * In principle, this could be tied to an interrupt, but the adapter
300 * doesn't appear to be designed to support interrupts. We spin on
301 * the 0x80 ready bit.
303 static unsigned char imm_wait(int host_no)
306 unsigned short ppb = IMM_BASE(host_no);
317 while (!(r & 0x80) && (k));
320 * STR register (LPT base+1) to SCSI mapping:
323 * ===================================
331 * ==================================
333 * 0xc0 0x88 ZIP wants more data
334 * 0xd0 0x98 ZIP wants to send more data
335 * 0xe0 0xa8 ZIP is expecting SCSI command data
336 * 0xf0 0xb8 end of transfer, ZIP is sending status
342 /* Counter expired - Time out occurred */
343 imm_fail(host_no, DID_TIME_OUT);
344 printk("imm timeout in imm_wait\n");
345 return 0; /* command timed out */
348 static int imm_negotiate(imm_struct * tmp)
351 * The following is supposedly the IEEE 1284-1994 negotiate
352 * sequence. I have yet to obtain a copy of the above standard
353 * so this is a bit of a guess...
355 * A fair chunk of this is based on the Linux parport implementation
358 * Return 0 if data available
359 * 1 if no data available
362 unsigned short base = tmp->base;
363 unsigned char a, mode;
382 a = (r_str(base) & 0x20) ? 0 : 1;
389 printk("IMM: IEEE1284 negotiate indicates no data available.\n");
390 imm_fail(tmp->host, DID_ERROR);
396 * Clear EPP timeout bit.
398 static inline void epp_reset(unsigned short ppb)
404 w_str(ppb, i & 0xfe);
408 * Wait for empty ECP fifo (if we are in ECP fifo mode only)
410 static inline void ecp_sync(unsigned short hostno)
412 int i, ppb_hi=IMM_BASE_HI(hostno);
414 if (ppb_hi == 0) return;
416 if ((r_ecr(ppb_hi) & 0xe0) == 0x60) { /* mode 011 == ECP fifo mode */
417 for (i = 0; i < 100; i++) {
418 if (r_ecr(ppb_hi) & 0x01)
422 printk("imm: ECP sync failed as data still present in FIFO.\n");
426 static int imm_byte_out(unsigned short base, const char *buffer, int len)
430 w_ctr(base, 0x4); /* apparently a sane mode */
431 for (i = len >> 1; i; i--) {
432 w_dtr(base, *buffer++);
433 w_ctr(base, 0x5); /* Drop STROBE low */
434 w_dtr(base, *buffer++);
435 w_ctr(base, 0x0); /* STROBE high + INIT low */
437 w_ctr(base, 0x4); /* apparently a sane mode */
438 return 1; /* All went well - we hope! */
441 static int imm_nibble_in(unsigned short base, char *buffer, int len)
447 * The following is based on documented timing signals
450 for (i = len; i; i--) {
452 l = (r_str(base) & 0xf0) >> 4;
454 *buffer++ = (r_str(base) & 0xf0) | l;
457 return 1; /* All went well - we hope! */
460 static int imm_byte_in(unsigned short base, char *buffer, int len)
465 * The following is based on documented timing signals
468 for (i = len; i; i--) {
470 *buffer++ = r_dtr(base);
473 return 1; /* All went well - we hope! */
476 static int imm_out(int host_no, char *buffer, int len)
479 unsigned short ppb = IMM_BASE(host_no);
481 r = imm_wait(host_no);
485 * a) the SCSI bus is BUSY (device still listening)
486 * b) the device is listening
488 if ((r & 0x18) != 0x08) {
489 imm_fail(host_no, DID_ERROR);
490 printk("IMM: returned SCSI status %2x\n", r);
493 switch (imm_hosts[host_no].mode) {
499 #ifdef CONFIG_SCSI_IZIP_EPP16
500 if (!(((long) buffer | len) & 0x01))
501 outsw(ppb + 4, buffer, len >> 1);
503 if (!(((long) buffer | len) & 0x03))
504 outsl(ppb + 4, buffer, len >> 2);
507 outsb(ppb + 4, buffer, len);
509 r = !(r_str(ppb) & 0x01);
516 /* 8 bit output, with a loop */
517 r = imm_byte_out(ppb, buffer, len);
521 printk("IMM: bug in imm_out()\n");
527 static int imm_in(int host_no, char *buffer, int len)
530 unsigned short ppb = IMM_BASE(host_no);
532 r = imm_wait(host_no);
536 * a) the SCSI bus is BUSY (device still listening)
537 * b) the device is sending data
539 if ((r & 0x18) != 0x18) {
540 imm_fail(host_no, DID_ERROR);
543 switch (imm_hosts[host_no].mode) {
545 /* 4 bit input, with a loop */
546 r = imm_nibble_in(ppb, buffer, len);
551 /* 8 bit input, with a loop */
552 r = imm_byte_in(ppb, buffer, len);
561 #ifdef CONFIG_SCSI_IZIP_EPP16
562 if (!(((long) buffer | len) & 0x01))
563 insw(ppb + 4, buffer, len >> 1);
565 if (!(((long) buffer | len) & 0x03))
566 insl(ppb + 4, buffer, len >> 2);
569 insb(ppb + 4, buffer, len);
571 r = !(r_str(ppb) & 0x01);
577 printk("IMM: bug in imm_ins()\n");
584 static int imm_cpp(unsigned short ppb, unsigned char b)
587 * Comments on udelay values refer to the
588 * Command Packet Protocol (CPP) timing diagram.
591 unsigned char s1, s2, s3;
593 udelay(2); /* 1 usec - infinite */
595 udelay(10); /* 7 usec - infinite */
597 udelay(10); /* 7 usec - infinite */
599 udelay(10); /* 7 usec - infinite */
601 udelay(10); /* 7 usec - infinite */
602 s1 = r_str(ppb) & 0xb8;
604 udelay(10); /* 7 usec - infinite */
605 s2 = r_str(ppb) & 0xb8;
607 udelay(10); /* 7 usec - infinite */
608 s3 = r_str(ppb) & 0x38;
611 * 0000 00aa Assign address aa to current device
612 * 0010 00aa Select device aa in EPP Winbond mode
613 * 0010 10aa Select device aa in EPP mode
614 * 0011 xxxx Deselect all devices
615 * 0110 00aa Test device aa
616 * 1101 00aa Select device aa in ECP mode
617 * 1110 00aa Select device aa in Compatible mode
620 udelay(2); /* 1 usec - infinite */
622 udelay(10); /* 7 usec - infinite */
624 udelay(2); /* 1 usec - infinite */
626 udelay(10); /* 7 usec - infinite */
628 udelay(10); /* 7 usec - infinite */
631 * The following table is electrical pin values.
632 * (BSY is inverted at the CTR register)
634 * BSY ACK POut SEL Fault
639 * L => Last device in chain
642 * Observered values for S1,S2,S3 are:
643 * Disconnect => f8/58/78
644 * Connect => f8/58/70
646 if ((s1 == 0xb8) && (s2 == 0x18) && (s3 == 0x30))
647 return 1; /* Connected */
648 if ((s1 == 0xb8) && (s2 == 0x18) && (s3 == 0x38))
649 return 0; /* Disconnected */
651 return -1; /* No device present */
654 static inline int imm_connect(int host_no, int flag)
656 unsigned short ppb = IMM_BASE(host_no);
658 imm_cpp(ppb, 0xe0); /* Select device 0 in compatible mode */
659 imm_cpp(ppb, 0x30); /* Disconnect all devices */
661 if ((imm_hosts[host_no].mode == IMM_EPP_8) ||
662 (imm_hosts[host_no].mode == IMM_EPP_16) ||
663 (imm_hosts[host_no].mode == IMM_EPP_32))
664 return imm_cpp(ppb, 0x28); /* Select device 0 in EPP mode */
665 return imm_cpp(ppb, 0xe0); /* Select device 0 in compatible mode */
668 static void imm_disconnect(int host_no)
670 unsigned short ppb = IMM_BASE(host_no);
672 imm_cpp(ppb, 0x30); /* Disconnect all devices */
675 static int imm_select(int host_no, int target)
678 unsigned short ppb = IMM_BASE(host_no);
681 * Firstly we want to make sure there is nothing
682 * holding onto the SCSI bus.
689 } while ((r_str(ppb) & 0x08) && (k));
695 * Now assert the SCSI ID (HOST and TARGET) on the data bus
698 w_dtr(ppb, 0x80 | (1 << target));
702 * Deassert SELIN first followed by STROBE
708 * ACK should drop low while SELIN is deasserted.
709 * FAULT should drop low when the SCSI device latches the bus.
715 while (!(r_str(ppb) & 0x08) && (k));
718 * Place the interface back into a sane state (status mode)
724 static int imm_init(int host_no)
728 #if defined(CONFIG_PARPORT) || defined(CONFIG_PARPORT_MODULE)
729 if (imm_pb_claim(host_no))
730 while (imm_hosts[host_no].p_busy)
731 schedule(); /* We can safe schedule here */
733 retv = imm_connect(host_no, 0);
736 imm_reset_pulse(IMM_BASE(host_no));
737 udelay(1000); /* Delay to allow devices to settle */
738 imm_disconnect(host_no);
739 udelay(1000); /* Another delay to allow devices to settle */
740 retv = device_check(host_no);
741 imm_pb_release(host_no);
744 imm_pb_release(host_no);
748 static inline int imm_send_command(Scsi_Cmnd * cmd)
750 int host_no = cmd->host->unique_id;
753 /* NOTE: IMM uses byte pairs */
754 for (k = 0; k < cmd->cmd_len; k += 2)
755 if (!imm_out(host_no, &cmd->cmnd[k], 2))
761 * The bulk flag enables some optimisations in the data transfer loops,
762 * it should be true for any command that transfers data in integral
763 * numbers of sectors.
765 * The driver appears to remain stable if we speed up the parallel port
766 * i/o in this function, but not elsewhere.
768 static int imm_completion(Scsi_Cmnd * cmd)
773 * 1 Finished data transfer
775 int host_no = cmd->host->unique_id;
776 unsigned short ppb = IMM_BASE(host_no);
777 unsigned long start_jiffies = jiffies;
780 int fast, bulk, status;
783 bulk = ((v == READ_6) ||
789 * We only get here if the drive is ready to comunicate,
790 * hence no need for a full imm_wait.
793 r = (r_str(ppb) & 0xb8);
796 * while (device is not ready to send status byte)
799 while (r != (unsigned char) 0xb8) {
801 * If we have been running for more than a full timer tick
804 if (time_after(jiffies, start_jiffies + 1))
809 * a) Drive status is screwy (!ready && !present)
810 * b) Drive is requesting/sending more data than expected
812 if (((r & 0x88) != 0x88) || (cmd->SCp.this_residual <= 0)) {
813 imm_fail(host_no, DID_ERROR);
814 return -1; /* ERROR_RETURN */
816 /* determine if we should use burst I/O */
817 if (imm_hosts[host_no].rd == 0) {
818 fast = (bulk && (cmd->SCp.this_residual >= IMM_BURST_SIZE)) ? IMM_BURST_SIZE : 2;
819 status = imm_out(host_no, cmd->SCp.ptr, fast);
821 fast = (bulk && (cmd->SCp.this_residual >= IMM_BURST_SIZE)) ? IMM_BURST_SIZE : 1;
822 status = imm_in(host_no, cmd->SCp.ptr, fast);
825 cmd->SCp.ptr += fast;
826 cmd->SCp.this_residual -= fast;
829 imm_fail(host_no, DID_BUS_BUSY);
830 return -1; /* ERROR_RETURN */
832 if (cmd->SCp.buffer && !cmd->SCp.this_residual) {
833 /* if scatter/gather, advance to the next segment */
834 if (cmd->SCp.buffers_residual--) {
836 cmd->SCp.this_residual = cmd->SCp.buffer->length;
837 cmd->SCp.ptr = cmd->SCp.buffer->address;
840 * Make sure that we transfer even number of bytes
841 * otherwise it makes imm_byte_out() messy.
843 if (cmd->SCp.this_residual & 0x01)
844 cmd->SCp.this_residual++;
847 /* Now check to see if the drive is ready to comunicate */
849 r = (r_str(ppb) & 0xb8);
851 /* If not, drop back down to the scheduler and wait a timer tick */
855 return 1; /* FINISH_RETURN */
858 /* deprecated synchronous interface */
859 int imm_command(Scsi_Cmnd * cmd)
861 static int first_pass = 1;
862 int host_no = cmd->host->unique_id;
865 printk("imm: using non-queuing interface\n");
868 if (imm_hosts[host_no].cur_cmd) {
869 printk("IMM: bug in imm_command\n");
872 imm_hosts[host_no].failed = 0;
873 imm_hosts[host_no].jstart = jiffies;
874 imm_hosts[host_no].cur_cmd = cmd;
875 cmd->result = DID_ERROR << 16; /* default return code */
878 imm_pb_claim(host_no);
880 while (imm_engine(&imm_hosts[host_no], cmd))
883 if (cmd->SCp.phase) /* Only disconnect if we have connected */
884 imm_disconnect(cmd->host->unique_id);
886 imm_pb_release(host_no);
887 imm_hosts[host_no].cur_cmd = 0;
892 * Since the IMM itself doesn't generate interrupts, we use
893 * the scheduler's task queue to generate a stream of call-backs and
894 * complete the request when the drive is ready.
896 static void imm_interrupt(void *data)
898 imm_struct *tmp = (imm_struct *) data;
899 Scsi_Cmnd *cmd = tmp->cur_cmd;
903 printk("IMM: bug in imm_interrupt\n");
906 if (imm_engine(tmp, cmd)) {
907 tmp->imm_tq.data = (void *) tmp;
908 tmp->imm_tq.sync = 0;
909 queue_task(&tmp->imm_tq, &tq_timer);
912 /* Command must of completed hence it is safe to let go... */
914 switch ((cmd->result >> 16) & 0xff) {
918 printk("imm: no device at SCSI ID %i\n", cmd->target);
921 printk("imm: BUS BUSY - EPP timeout detected\n");
924 printk("imm: unknown timeout\n");
927 printk("imm: told to abort\n");
930 printk("imm: parity error (???)\n");
933 printk("imm: internal driver error\n");
936 printk("imm: told to reset device\n");
939 printk("imm: bad interrupt (???)\n");
942 printk("imm: bad return code (%02x)\n", (cmd->result >> 16) & 0xff);
946 if (cmd->SCp.phase > 1)
947 imm_disconnect(cmd->host->unique_id);
948 if (cmd->SCp.phase > 0)
949 imm_pb_release(cmd->host->unique_id);
951 spin_lock_irqsave(&io_request_lock, flags);
954 spin_unlock_irqrestore(&io_request_lock, flags);
958 static int imm_engine(imm_struct * tmp, Scsi_Cmnd * cmd)
960 int host_no = cmd->host->unique_id;
961 unsigned short ppb = IMM_BASE(host_no);
962 unsigned char l = 0, h = 0;
965 /* First check for any errors that may of occurred
966 * Here we check for internal errors
971 switch (cmd->SCp.phase) {
972 case 0: /* Phase 0 - Waiting for parport */
973 if ((jiffies - tmp->jstart) > HZ) {
975 * We waited more than a second
976 * for parport to call us
978 imm_fail(host_no, DID_BUS_BUSY);
981 return 1; /* wait until imm_wakeup claims parport */
982 /* Phase 1 - Connected */
984 imm_connect(host_no, CONNECT_EPP_MAYBE);
987 /* Phase 2 - We are now talking to the scsi bus */
989 if (!imm_select(host_no, cmd->target)) {
990 imm_fail(host_no, DID_NO_CONNECT);
995 /* Phase 3 - Ready to accept a command */
998 if (!(r_str(ppb) & 0x80))
1001 if (!imm_send_command(cmd))
1005 /* Phase 4 - Setup scatter/gather buffers */
1008 /* if many buffers are available, start filling the first */
1009 cmd->SCp.buffer = (struct scatterlist *) cmd->request_buffer;
1010 cmd->SCp.this_residual = cmd->SCp.buffer->length;
1011 cmd->SCp.ptr = cmd->SCp.buffer->address;
1013 /* else fill the only available buffer */
1014 cmd->SCp.buffer = NULL;
1015 cmd->SCp.this_residual = cmd->request_bufflen;
1016 cmd->SCp.ptr = cmd->request_buffer;
1018 cmd->SCp.buffers_residual = cmd->use_sg;
1020 if (cmd->SCp.this_residual & 0x01)
1021 cmd->SCp.this_residual++;
1022 /* Phase 5 - Pre-Data transfer stage */
1024 /* Spin lock for BUSY */
1026 if (!(r_str(ppb) & 0x80))
1029 /* Require negotiation for read requests */
1030 x = (r_str(ppb) & 0xb8);
1031 tmp->rd = (x & 0x10) ? 1 : 0;
1032 tmp->dp = (x & 0x20) ? 0 : 1;
1034 if ((tmp->dp) && (tmp->rd))
1035 if (imm_negotiate(tmp))
1039 /* Phase 6 - Data transfer stage */
1041 /* Spin lock for BUSY */
1043 if (!(r_str(ppb) & 0x80))
1047 retv = imm_completion(cmd);
1055 /* Phase 7 - Post data transfer stage */
1057 if ((tmp->dp) && (tmp->rd)) {
1058 if ((tmp->mode == IMM_NIBBLE) || (tmp->mode == IMM_PS2)) {
1067 /* Phase 8 - Read status/message */
1069 /* Check for data overrun */
1070 if (imm_wait(host_no) != (unsigned char) 0xb8) {
1071 imm_fail(host_no, DID_ERROR);
1074 if (imm_negotiate(tmp))
1076 if (imm_in(host_no, &l, 1)) { /* read status byte */
1077 /* Check for optional message byte */
1078 if (imm_wait(host_no) == (unsigned char) 0xb8)
1079 imm_in(host_no, &h, 1);
1080 cmd->result = (DID_OK << 16) + (l & STATUS_MASK);
1082 if ((tmp->mode == IMM_NIBBLE) || (tmp->mode == IMM_PS2)) {
1088 return 0; /* Finished */
1092 printk("imm: Invalid scsi phase\n");
1097 int imm_queuecommand(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *))
1099 int host_no = cmd->host->unique_id;
1101 if (imm_hosts[host_no].cur_cmd) {
1102 printk("IMM: bug in imm_queuecommand\n");
1105 imm_hosts[host_no].failed = 0;
1106 imm_hosts[host_no].jstart = jiffies;
1107 imm_hosts[host_no].cur_cmd = cmd;
1108 cmd->scsi_done = done;
1109 cmd->result = DID_ERROR << 16; /* default return code */
1110 cmd->SCp.phase = 0; /* bus free */
1112 imm_pb_claim(host_no);
1114 imm_hosts[host_no].imm_tq.data = imm_hosts + host_no;
1115 imm_hosts[host_no].imm_tq.sync = 0;
1116 queue_task(&imm_hosts[host_no].imm_tq, &tq_immediate);
1117 mark_bh(IMMEDIATE_BH);
1123 * Apparently the disk->capacity attribute is off by 1 sector
1124 * for all disk drives. We add the one here, but it should really
1125 * be done in sd.c. Even if it gets fixed there, this will still
1128 int imm_biosparam(Disk * disk, kdev_t dev, int ip[])
1132 ip[2] = (disk->capacity + 1) / (ip[0] * ip[1]);
1136 ip[2] = (disk->capacity + 1) / (ip[0] * ip[1]);
1141 int imm_abort(Scsi_Cmnd * cmd)
1143 int host_no = cmd->host->unique_id;
1145 * There is no method for aborting commands since Iomega
1146 * have tied the SCSI_MESSAGE line high in the interface
1149 switch (cmd->SCp.phase) {
1150 case 0: /* Do not have access to parport */
1151 case 1: /* Have not connected to interface */
1152 imm_hosts[host_no].cur_cmd = NULL; /* Forget the problem */
1155 default: /* SCSI command sent, can not abort */
1161 void imm_reset_pulse(unsigned int base)
1173 int imm_reset(Scsi_Cmnd * cmd)
1175 int host_no = cmd->host->unique_id;
1178 imm_disconnect(host_no);
1179 imm_hosts[host_no].cur_cmd = NULL; /* Forget the problem */
1181 imm_connect(host_no, CONNECT_NORMAL);
1182 imm_reset_pulse(IMM_BASE(host_no));
1183 udelay(1000); /* device settle delay */
1184 imm_disconnect(host_no);
1185 udelay(1000); /* device settle delay */
1189 static int device_check(int host_no)
1191 /* This routine looks for a device and then attempts to use EPP
1192 to send a command. If all goes as planned then EPP is available. */
1194 static char cmd[6] =
1195 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1196 int loop, old_mode, status, k, ppb = IMM_BASE(host_no);
1199 old_mode = imm_hosts[host_no].mode;
1200 for (loop = 0; loop < 8; loop++) {
1201 /* Attempt to use EPP for Test Unit Ready */
1202 if ((ppb & 0x0007) == 0x0000)
1203 imm_hosts[host_no].mode = IMM_EPP_32;
1206 imm_connect(host_no, CONNECT_EPP_MAYBE);
1207 /* Select SCSI device */
1208 if (!imm_select(host_no, loop)) {
1209 imm_disconnect(host_no);
1212 printk("imm: Found device at ID %i, Attempting to use %s\n", loop,
1213 IMM_MODE_STRING[imm_hosts[host_no].mode]);
1215 /* Send SCSI command */
1218 for (l = 0; (l < 3) && (status); l++)
1219 status = imm_out(host_no, &cmd[l << 1], 2);
1222 imm_disconnect(host_no);
1223 imm_connect(host_no, CONNECT_EPP_MAYBE);
1224 imm_reset_pulse(IMM_BASE(host_no));
1226 imm_disconnect(host_no);
1228 if (imm_hosts[host_no].mode == IMM_EPP_32) {
1229 imm_hosts[host_no].mode = old_mode;
1232 printk("imm: Unable to establish communication, aborting driver load.\n");
1237 k = 1000000; /* 1 Second */
1242 } while (!(l & 0x80) && (k));
1247 imm_disconnect(host_no);
1248 imm_connect(host_no, CONNECT_EPP_MAYBE);
1249 imm_reset_pulse(IMM_BASE(host_no));
1251 imm_disconnect(host_no);
1253 if (imm_hosts[host_no].mode == IMM_EPP_32) {
1254 imm_hosts[host_no].mode = old_mode;
1257 printk("imm: Unable to establish communication, aborting driver load.\n");
1260 imm_disconnect(host_no);
1261 printk("imm: Communication established at 0x%x with ID %i using %s\n", ppb, loop,
1262 IMM_MODE_STRING[imm_hosts[host_no].mode]);
1263 imm_connect(host_no, CONNECT_EPP_MAYBE);
1264 imm_reset_pulse(IMM_BASE(host_no));
1266 imm_disconnect(host_no);
1270 printk("imm: No devices found, aborting driver load.\n");
1273 MODULE_LICENSE("GPL");