Commit 8e840158 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] scsi/imm.c cleanup and fixes (1/8)

	* imm.c fed through Lindent, functions unused elsewhere (by now -
	  all of them) made static.
parent 0968e60c
...@@ -14,14 +14,13 @@ ...@@ -14,14 +14,13 @@
#include <linux/config.h> #include <linux/config.h>
/* The following #define is to avoid a clash with hosts.c */ /* The following #define is to avoid a clash with hosts.c */
#define IMM_CODE 1
#define IMM_PROBE_SPP 0x0001 #define IMM_PROBE_SPP 0x0001
#define IMM_PROBE_PS2 0x0002 #define IMM_PROBE_PS2 0x0002
#define IMM_PROBE_ECR 0x0010 #define IMM_PROBE_ECR 0x0010
#define IMM_PROBE_EPP17 0x0100 #define IMM_PROBE_EPP17 0x0100
#define IMM_PROBE_EPP19 0x0200 #define IMM_PROBE_EPP19 0x0200
void imm_reset_pulse(unsigned int base); static void imm_reset_pulse(unsigned int base);
static int device_check(int host_no); static int device_check(int host_no);
#include <linux/blkdev.h> #include <linux/blkdev.h>
...@@ -32,18 +31,18 @@ static int device_check(int host_no); ...@@ -32,18 +31,18 @@ static int device_check(int host_no);
#include "hosts.h" #include "hosts.h"
typedef struct { typedef struct {
struct pardevice *dev; /* Parport device entry */ struct pardevice *dev; /* Parport device entry */
int base; /* Actual port address */ int base; /* Actual port address */
int base_hi; /* Hi Base address for ECP-ISA chipset */ int base_hi; /* Hi Base address for ECP-ISA chipset */
int mode; /* Transfer mode */ int mode; /* Transfer mode */
int host; /* Host number (for proc) */ int host; /* Host number (for proc) */
Scsi_Cmnd *cur_cmd; /* Current queued command */ Scsi_Cmnd *cur_cmd; /* Current queued command */
struct work_struct imm_tq; /* Polling interrupt stuff */ struct work_struct imm_tq; /* Polling interrupt stuff */
unsigned long jstart; /* Jiffies at start */ unsigned long jstart; /* Jiffies at start */
unsigned failed:1; /* Failure flag */ unsigned failed:1; /* Failure flag */
unsigned dp:1; /* Data phase present */ unsigned dp:1; /* Data phase present */
unsigned rd:1; /* Read data in data phase */ unsigned rd:1; /* Read data in data phase */
unsigned p_busy:1; /* Parport sharing busy flag */ unsigned p_busy:1; /* Parport sharing busy flag */
} imm_struct; } imm_struct;
#define IMM_EMPTY \ #define IMM_EMPTY \
...@@ -55,51 +54,50 @@ typedef struct { ...@@ -55,51 +54,50 @@ typedef struct {
#include "imm.h" #include "imm.h"
#define NO_HOSTS 4 #define NO_HOSTS 4
static imm_struct imm_hosts[NO_HOSTS] = static imm_struct imm_hosts[NO_HOSTS] =
{IMM_EMPTY, IMM_EMPTY, IMM_EMPTY, IMM_EMPTY}; { IMM_EMPTY, IMM_EMPTY, IMM_EMPTY, IMM_EMPTY };
#define IMM_BASE(x) imm_hosts[(x)].base #define IMM_BASE(x) imm_hosts[(x)].base
#define IMM_BASE_HI(x) imm_hosts[(x)].base_hi #define IMM_BASE_HI(x) imm_hosts[(x)].base_hi
int parbus_base[NO_HOSTS] = int parbus_base[NO_HOSTS] = { 0x03bc, 0x0378, 0x0278, 0x0000 };
{0x03bc, 0x0378, 0x0278, 0x0000};
void imm_wakeup(void *ref) static void imm_wakeup(void *ref)
{ {
imm_struct *imm_dev = (imm_struct *) ref; imm_struct *imm_dev = (imm_struct *) ref;
if (!imm_dev->p_busy) if (!imm_dev->p_busy)
return; return;
if (parport_claim(imm_dev->dev)) { if (parport_claim(imm_dev->dev)) {
printk("imm: bug in imm_wakeup\n"); printk("imm: bug in imm_wakeup\n");
return;
}
imm_dev->p_busy = 0;
imm_dev->base = imm_dev->dev->port->base;
if (imm_dev->cur_cmd)
imm_dev->cur_cmd->SCp.phase++;
return; return;
}
imm_dev->p_busy = 0;
imm_dev->base = imm_dev->dev->port->base;
if (imm_dev->cur_cmd)
imm_dev->cur_cmd->SCp.phase++;
return;
} }
int imm_release(struct Scsi_Host *host) static int imm_release(struct Scsi_Host *host)
{ {
int host_no = host->unique_id; int host_no = host->unique_id;
printk("Releasing imm%i\n", host_no); printk("Releasing imm%i\n", host_no);
scsi_unregister(host); scsi_unregister(host);
parport_unregister_device(imm_hosts[host_no].dev); parport_unregister_device(imm_hosts[host_no].dev);
return 0; return 0;
} }
static int imm_pb_claim(int host_no) static int imm_pb_claim(int host_no)
{ {
if (parport_claim(imm_hosts[host_no].dev)) { if (parport_claim(imm_hosts[host_no].dev)) {
imm_hosts[host_no].p_busy = 1; imm_hosts[host_no].p_busy = 1;
return 1; return 1;
} }
if (imm_hosts[host_no].cur_cmd) if (imm_hosts[host_no].cur_cmd)
imm_hosts[host_no].cur_cmd->SCp.phase++; imm_hosts[host_no].cur_cmd->SCp.phase++;
return 0; return 0;
} }
#define imm_pb_release(x) parport_release(imm_hosts[(x)].dev) #define imm_pb_release(x) parport_release(imm_hosts[(x)].dev)
...@@ -109,128 +107,131 @@ static int imm_pb_claim(int host_no) ...@@ -109,128 +107,131 @@ static int imm_pb_claim(int host_no)
***************************************************************************/ ***************************************************************************/
static Scsi_Host_Template driver_template = { static Scsi_Host_Template driver_template = {
.proc_name = "imm", .proc_name = "imm",
.proc_info = imm_proc_info, .proc_info = imm_proc_info,
.name = "Iomega VPI2 (imm) interface", .name = "Iomega VPI2 (imm) interface",
.detect = imm_detect, .detect = imm_detect,
.release = imm_release, .release = imm_release,
.queuecommand = imm_queuecommand, .queuecommand = imm_queuecommand,
.eh_abort_handler = imm_abort, .eh_abort_handler = imm_abort,
.eh_bus_reset_handler = imm_reset, .eh_bus_reset_handler = imm_reset,
.eh_host_reset_handler = imm_reset, .eh_host_reset_handler = imm_reset,
.bios_param = imm_biosparam, .bios_param = imm_biosparam,
.this_id = 7, .this_id = 7,
.sg_tablesize = SG_ALL, .sg_tablesize = SG_ALL,
.cmd_per_lun = 1, .cmd_per_lun = 1,
.use_clustering = ENABLE_CLUSTERING, .use_clustering = ENABLE_CLUSTERING,
}; };
#include "scsi_module.c" #include "scsi_module.c"
int imm_detect(Scsi_Host_Template * host) static int imm_detect(Scsi_Host_Template * host)
{ {
struct Scsi_Host *hreg; struct Scsi_Host *hreg;
int ports; int ports;
int i, nhosts, try_again; int i, nhosts, try_again;
struct parport *pb; struct parport *pb;
pb = parport_enumerate(); pb = parport_enumerate();
printk("imm: Version %s\n", IMM_VERSION); printk("imm: Version %s\n", IMM_VERSION);
nhosts = 0; nhosts = 0;
try_again = 0; try_again = 0;
if (!pb) { if (!pb) {
printk("imm: parport reports no devices.\n"); printk("imm: parport reports no devices.\n");
return 0; return 0;
} }
retry_entry: retry_entry:
for (i = 0; pb; i++, pb = pb->next) { for (i = 0; pb; i++, pb = pb->next) {
int modes, ppb; int modes, ppb;
imm_hosts[i].dev = imm_hosts[i].dev =
parport_register_device(pb, "imm", NULL, imm_wakeup, parport_register_device(pb, "imm", NULL, imm_wakeup,
NULL, 0, (void *) &imm_hosts[i]); NULL, 0, (void *) &imm_hosts[i]);
if (!imm_hosts[i].dev) if (!imm_hosts[i].dev)
continue; continue;
/* Claim the bus so it remembers what we do to the control /* Claim the bus so it remembers what we do to the control
* registers. [ CTR and ECP ] * registers. [ CTR and ECP ]
*/ */
if (imm_pb_claim(i)) { if (imm_pb_claim(i)) {
unsigned long now = jiffies; unsigned long now = jiffies;
while (imm_hosts[i].p_busy) { while (imm_hosts[i].p_busy) {
schedule(); /* We are safe to schedule here */ schedule(); /* We are safe to schedule here */
if (time_after(jiffies, now + 3 * HZ)) { if (time_after(jiffies, now + 3 * HZ)) {
printk(KERN_ERR "imm%d: failed to claim parport because a " printk(KERN_ERR
"pardevice is owning the port for too longtime!\n", "imm%d: failed to claim parport because a "
i); "pardevice is owning the port for too longtime!\n",
parport_unregister_device (imm_hosts[i].dev); i);
return 0; parport_unregister_device(imm_hosts[i].
dev);
return 0;
}
}
} }
} ppb = IMM_BASE(i) = imm_hosts[i].dev->port->base;
} IMM_BASE_HI(i) = imm_hosts[i].dev->port->base_hi;
ppb = IMM_BASE(i) = imm_hosts[i].dev->port->base; w_ctr(ppb, 0x0c);
IMM_BASE_HI(i) = imm_hosts[i].dev->port->base_hi; modes = imm_hosts[i].dev->port->modes;
w_ctr(ppb, 0x0c);
modes = imm_hosts[i].dev->port->modes;
/* Mode detection works up the chain of speed /* Mode detection works up the chain of speed
* This avoids a nasty if-then-else-if-... tree * This avoids a nasty if-then-else-if-... tree
*/ */
imm_hosts[i].mode = IMM_NIBBLE; imm_hosts[i].mode = IMM_NIBBLE;
if (modes & PARPORT_MODE_TRISTATE) if (modes & PARPORT_MODE_TRISTATE)
imm_hosts[i].mode = IMM_PS2; imm_hosts[i].mode = IMM_PS2;
/* Done configuration */ /* Done configuration */
imm_pb_release(i); imm_pb_release(i);
if (imm_init(i)) { if (imm_init(i)) {
parport_unregister_device(imm_hosts[i].dev); parport_unregister_device(imm_hosts[i].dev);
continue; continue;
} }
/* now the glue ... */ /* now the glue ... */
switch (imm_hosts[i].mode) { switch (imm_hosts[i].mode) {
case IMM_NIBBLE: case IMM_NIBBLE:
ports = 3; ports = 3;
break; break;
case IMM_PS2: case IMM_PS2:
ports = 3; ports = 3;
break; break;
case IMM_EPP_8: case IMM_EPP_8:
case IMM_EPP_16: case IMM_EPP_16:
case IMM_EPP_32: case IMM_EPP_32:
ports = 8; ports = 8;
break; break;
default: /* Never gets here */ default: /* Never gets here */
continue; continue;
} }
INIT_WORK(&imm_hosts[i].imm_tq, imm_interrupt, &imm_hosts[i]); INIT_WORK(&imm_hosts[i].imm_tq, imm_interrupt, &imm_hosts[i]);
host->can_queue = IMM_CAN_QUEUE; host->can_queue = IMM_CAN_QUEUE;
host->sg_tablesize = imm_sg; host->sg_tablesize = imm_sg;
hreg = scsi_register(host, 0); hreg = scsi_register(host, 0);
if(hreg == NULL) if (hreg == NULL)
continue; continue;
hreg->io_port = pb->base; hreg->io_port = pb->base;
hreg->n_io_port = ports; hreg->n_io_port = ports;
hreg->dma_channel = -1; hreg->dma_channel = -1;
hreg->unique_id = i; hreg->unique_id = i;
imm_hosts[i].host = hreg->host_no; imm_hosts[i].host = hreg->host_no;
nhosts++; nhosts++;
} }
if (nhosts == 0) { if (nhosts == 0) {
if (try_again == 1) { if (try_again == 1) {
return 0; return 0;
}
try_again = 1;
goto retry_entry;
} else {
return 1; /* return number of hosts detected */
} }
try_again = 1;
goto retry_entry;
} else {
return 1; /* return number of hosts detected */
}
} }
/* This is to give the imm driver a way to modify the timings (and other /* This is to give the imm driver a way to modify the timings (and other
...@@ -242,58 +243,64 @@ int imm_detect(Scsi_Host_Template * host) ...@@ -242,58 +243,64 @@ int imm_detect(Scsi_Host_Template * host)
*/ */
static inline int imm_proc_write(int hostno, char *buffer, int length) static inline int imm_proc_write(int hostno, char *buffer, int length)
{ {
unsigned long x; unsigned long x;
if ((length > 5) && (strncmp(buffer, "mode=", 5) == 0)) { if ((length > 5) && (strncmp(buffer, "mode=", 5) == 0)) {
x = simple_strtoul(buffer + 5, NULL, 0); x = simple_strtoul(buffer + 5, NULL, 0);
imm_hosts[hostno].mode = x; imm_hosts[hostno].mode = x;
return length; return length;
} }
printk("imm /proc: invalid variable\n"); printk("imm /proc: invalid variable\n");
return (-EINVAL); return (-EINVAL);
} }
int imm_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset, static int imm_proc_info(struct Scsi_Host *host, char *buffer, char **start,
int length, int inout) off_t offset, int length, int inout)
{ {
int i; int i;
int len = 0; int len = 0;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
if (imm_hosts[i].host == host->host_no) if (imm_hosts[i].host == host->host_no)
break; break;
if (inout) if (inout)
return imm_proc_write(i, buffer, length); return imm_proc_write(i, buffer, length);
len += sprintf(buffer + len, "Version : %s\n", IMM_VERSION); len += sprintf(buffer + len, "Version : %s\n", IMM_VERSION);
len += sprintf(buffer + len, "Parport : %s\n", imm_hosts[i].dev->port->name); len +=
len += sprintf(buffer + len, "Mode : %s\n", IMM_MODE_STRING[imm_hosts[i].mode]); sprintf(buffer + len, "Parport : %s\n",
imm_hosts[i].dev->port->name);
/* Request for beyond end of buffer */ len +=
if (offset > len) sprintf(buffer + len, "Mode : %s\n",
return 0; IMM_MODE_STRING[imm_hosts[i].mode]);
/* Request for beyond end of buffer */
if (offset > len)
return 0;
*start = buffer + offset; *start = buffer + offset;
len -= offset; len -= offset;
if (len > length) if (len > length)
len = length; len = length;
return len; return len;
} }
#if IMM_DEBUG > 0 #if IMM_DEBUG > 0
#define imm_fail(x,y) printk("imm: imm_fail(%i) from %s at line %d\n",\ #define imm_fail(x,y) printk("imm: imm_fail(%i) from %s at line %d\n",\
y, __FUNCTION__, __LINE__); imm_fail_func(x,y); y, __FUNCTION__, __LINE__); imm_fail_func(x,y);
static inline void imm_fail_func(int host_no, int error_code) static inline void
imm_fail_func(int host_no, int error_code)
#else #else
static inline void imm_fail(int host_no, int error_code) static inline void
imm_fail(int host_no, int error_code)
#endif #endif
{ {
/* If we fail a device then we trash status / message bytes */ /* If we fail a device then we trash status / message bytes */
if (imm_hosts[host_no].cur_cmd) { if (imm_hosts[host_no].cur_cmd) {
imm_hosts[host_no].cur_cmd->result = error_code << 16; imm_hosts[host_no].cur_cmd->result = error_code << 16;
imm_hosts[host_no].failed = 1; imm_hosts[host_no].failed = 1;
} }
} }
/* /*
...@@ -305,94 +312,95 @@ static inline void imm_fail(int host_no, int error_code) ...@@ -305,94 +312,95 @@ static inline void imm_fail(int host_no, int error_code)
*/ */
static unsigned char imm_wait(int host_no) static unsigned char imm_wait(int host_no)
{ {
int k; int k;
unsigned short ppb = IMM_BASE(host_no); unsigned short ppb = IMM_BASE(host_no);
unsigned char r; unsigned char r;
w_ctr(ppb, 0x0c);
w_ctr(ppb, 0x0c); k = IMM_SPIN_TMO;
do {
r = r_str(ppb);
k--;
udelay(1);
}
while (!(r & 0x80) && (k));
k = IMM_SPIN_TMO; /*
do { * STR register (LPT base+1) to SCSI mapping:
r = r_str(ppb); *
k--; * STR imm imm
udelay(1); * ===================================
} * 0x80 S_REQ S_REQ
while (!(r & 0x80) && (k)); * 0x40 !S_BSY (????)
* 0x20 !S_CD !S_CD
/* * 0x10 !S_IO !S_IO
* STR register (LPT base+1) to SCSI mapping: * 0x08 (????) !S_BSY
* *
* STR imm imm * imm imm meaning
* =================================== * ==================================
* 0x80 S_REQ S_REQ * 0xf0 0xb8 Bit mask
* 0x40 !S_BSY (????) * 0xc0 0x88 ZIP wants more data
* 0x20 !S_CD !S_CD * 0xd0 0x98 ZIP wants to send more data
* 0x10 !S_IO !S_IO * 0xe0 0xa8 ZIP is expecting SCSI command data
* 0x08 (????) !S_BSY * 0xf0 0xb8 end of transfer, ZIP is sending status
* */
* imm imm meaning w_ctr(ppb, 0x04);
* ================================== if (k)
* 0xf0 0xb8 Bit mask return (r & 0xb8);
* 0xc0 0x88 ZIP wants more data
* 0xd0 0x98 ZIP wants to send more data /* Counter expired - Time out occurred */
* 0xe0 0xa8 ZIP is expecting SCSI command data imm_fail(host_no, DID_TIME_OUT);
* 0xf0 0xb8 end of transfer, ZIP is sending status printk("imm timeout in imm_wait\n");
*/ return 0; /* command timed out */
w_ctr(ppb, 0x04);
if (k)
return (r & 0xb8);
/* Counter expired - Time out occurred */
imm_fail(host_no, DID_TIME_OUT);
printk("imm timeout in imm_wait\n");
return 0; /* command timed out */
} }
static int imm_negotiate(imm_struct * tmp) static int imm_negotiate(imm_struct * tmp)
{ {
/* /*
* The following is supposedly the IEEE 1284-1994 negotiate * The following is supposedly the IEEE 1284-1994 negotiate
* sequence. I have yet to obtain a copy of the above standard * sequence. I have yet to obtain a copy of the above standard
* so this is a bit of a guess... * so this is a bit of a guess...
* *
* A fair chunk of this is based on the Linux parport implementation * A fair chunk of this is based on the Linux parport implementation
* of IEEE 1284. * of IEEE 1284.
* *
* Return 0 if data available * Return 0 if data available
* 1 if no data available * 1 if no data available
*/ */
unsigned short base = tmp->base; unsigned short base = tmp->base;
unsigned char a, mode; unsigned char a, mode;
switch (tmp->mode) { switch (tmp->mode) {
case IMM_NIBBLE: case IMM_NIBBLE:
mode = 0x00; mode = 0x00;
break; break;
case IMM_PS2: case IMM_PS2:
mode = 0x01; mode = 0x01;
break; break;
default: default:
return 0; return 0;
} }
w_ctr(base, 0x04); w_ctr(base, 0x04);
udelay(5); udelay(5);
w_dtr(base, mode); w_dtr(base, mode);
udelay(100); udelay(100);
w_ctr(base, 0x06); w_ctr(base, 0x06);
udelay(5); udelay(5);
a = (r_str(base) & 0x20) ? 0 : 1; a = (r_str(base) & 0x20) ? 0 : 1;
udelay(5); udelay(5);
w_ctr(base, 0x07); w_ctr(base, 0x07);
udelay(5); udelay(5);
w_ctr(base, 0x06); w_ctr(base, 0x06);
if (a) { if (a) {
printk("IMM: IEEE1284 negotiate indicates no data available.\n"); printk
imm_fail(tmp->host, DID_ERROR); ("IMM: IEEE1284 negotiate indicates no data available.\n");
} imm_fail(tmp->host, DID_ERROR);
return a; }
return a;
} }
/* /*
...@@ -400,11 +408,11 @@ static int imm_negotiate(imm_struct * tmp) ...@@ -400,11 +408,11 @@ static int imm_negotiate(imm_struct * tmp)
*/ */
static inline void epp_reset(unsigned short ppb) static inline void epp_reset(unsigned short ppb)
{ {
int i; int i;
i = r_str(ppb); i = r_str(ppb);
w_str(ppb, i); w_str(ppb, i);
w_str(ppb, i & 0xfe); w_str(ppb, i & 0xfe);
} }
/* /*
...@@ -412,352 +420,353 @@ static inline void epp_reset(unsigned short ppb) ...@@ -412,352 +420,353 @@ static inline void epp_reset(unsigned short ppb)
*/ */
static inline void ecp_sync(unsigned short hostno) static inline void ecp_sync(unsigned short hostno)
{ {
int i, ppb_hi=IMM_BASE_HI(hostno); int i, ppb_hi = IMM_BASE_HI(hostno);
if (ppb_hi == 0) return; if (ppb_hi == 0)
return;
if ((r_ecr(ppb_hi) & 0xe0) == 0x60) { /* mode 011 == ECP fifo mode */ if ((r_ecr(ppb_hi) & 0xe0) == 0x60) { /* mode 011 == ECP fifo mode */
for (i = 0; i < 100; i++) { for (i = 0; i < 100; i++) {
if (r_ecr(ppb_hi) & 0x01) if (r_ecr(ppb_hi) & 0x01)
return; return;
udelay(5); udelay(5);
}
printk("imm: ECP sync failed as data still present in FIFO.\n");
} }
printk("imm: ECP sync failed as data still present in FIFO.\n");
}
} }
static int imm_byte_out(unsigned short base, const char *buffer, int len) static int imm_byte_out(unsigned short base, const char *buffer, int len)
{ {
int i; int i;
w_ctr(base, 0x4); /* apparently a sane mode */ w_ctr(base, 0x4); /* apparently a sane mode */
for (i = len >> 1; i; i--) { for (i = len >> 1; i; i--) {
w_dtr(base, *buffer++); w_dtr(base, *buffer++);
w_ctr(base, 0x5); /* Drop STROBE low */ w_ctr(base, 0x5); /* Drop STROBE low */
w_dtr(base, *buffer++); w_dtr(base, *buffer++);
w_ctr(base, 0x0); /* STROBE high + INIT low */ w_ctr(base, 0x0); /* STROBE high + INIT low */
} }
w_ctr(base, 0x4); /* apparently a sane mode */ w_ctr(base, 0x4); /* apparently a sane mode */
return 1; /* All went well - we hope! */ return 1; /* All went well - we hope! */
} }
static int imm_nibble_in(unsigned short base, char *buffer, int len) static int imm_nibble_in(unsigned short base, char *buffer, int len)
{ {
unsigned char l; unsigned char l;
int i; int i;
/* /*
* The following is based on documented timing signals * The following is based on documented timing signals
*/ */
w_ctr(base, 0x4);
for (i = len; i; i--) {
w_ctr(base, 0x6);
l = (r_str(base) & 0xf0) >> 4;
w_ctr(base, 0x5);
*buffer++ = (r_str(base) & 0xf0) | l;
w_ctr(base, 0x4); w_ctr(base, 0x4);
} for (i = len; i; i--) {
return 1; /* All went well - we hope! */ w_ctr(base, 0x6);
l = (r_str(base) & 0xf0) >> 4;
w_ctr(base, 0x5);
*buffer++ = (r_str(base) & 0xf0) | l;
w_ctr(base, 0x4);
}
return 1; /* All went well - we hope! */
} }
static int imm_byte_in(unsigned short base, char *buffer, int len) static int imm_byte_in(unsigned short base, char *buffer, int len)
{ {
int i; int i;
/* /*
* The following is based on documented timing signals * The following is based on documented timing signals
*/ */
w_ctr(base, 0x4); w_ctr(base, 0x4);
for (i = len; i; i--) { for (i = len; i; i--) {
w_ctr(base, 0x26); w_ctr(base, 0x26);
*buffer++ = r_dtr(base); *buffer++ = r_dtr(base);
w_ctr(base, 0x25); w_ctr(base, 0x25);
} }
return 1; /* All went well - we hope! */ return 1; /* All went well - we hope! */
} }
static int imm_out(int host_no, char *buffer, int len) static int imm_out(int host_no, char *buffer, int len)
{ {
int r; int r;
unsigned short ppb = IMM_BASE(host_no); unsigned short ppb = IMM_BASE(host_no);
r = imm_wait(host_no); r = imm_wait(host_no);
/* /*
* Make sure that: * Make sure that:
* a) the SCSI bus is BUSY (device still listening) * a) the SCSI bus is BUSY (device still listening)
* b) the device is listening * b) the device is listening
*/ */
if ((r & 0x18) != 0x08) { if ((r & 0x18) != 0x08) {
imm_fail(host_no, DID_ERROR); imm_fail(host_no, DID_ERROR);
printk("IMM: returned SCSI status %2x\n", r); printk("IMM: returned SCSI status %2x\n", r);
return 0; return 0;
} }
switch (imm_hosts[host_no].mode) { switch (imm_hosts[host_no].mode) {
case IMM_EPP_32: case IMM_EPP_32:
case IMM_EPP_16: case IMM_EPP_16:
case IMM_EPP_8: case IMM_EPP_8:
epp_reset(ppb); epp_reset(ppb);
w_ctr(ppb, 0x4); w_ctr(ppb, 0x4);
#ifdef CONFIG_SCSI_IZIP_EPP16 #ifdef CONFIG_SCSI_IZIP_EPP16
if (!(((long) buffer | len) & 0x01)) if (!(((long) buffer | len) & 0x01))
outsw(ppb + 4, buffer, len >> 1); outsw(ppb + 4, buffer, len >> 1);
#else #else
if (!(((long) buffer | len) & 0x03)) if (!(((long) buffer | len) & 0x03))
outsl(ppb + 4, buffer, len >> 2); outsl(ppb + 4, buffer, len >> 2);
#endif #endif
else else
outsb(ppb + 4, buffer, len); outsb(ppb + 4, buffer, len);
w_ctr(ppb, 0xc); w_ctr(ppb, 0xc);
r = !(r_str(ppb) & 0x01); r = !(r_str(ppb) & 0x01);
w_ctr(ppb, 0xc); w_ctr(ppb, 0xc);
ecp_sync(host_no); ecp_sync(host_no);
break; break;
case IMM_NIBBLE: case IMM_NIBBLE:
case IMM_PS2: case IMM_PS2:
/* 8 bit output, with a loop */ /* 8 bit output, with a loop */
r = imm_byte_out(ppb, buffer, len); r = imm_byte_out(ppb, buffer, len);
break; break;
default: default:
printk("IMM: bug in imm_out()\n"); printk("IMM: bug in imm_out()\n");
r = 0; r = 0;
} }
return r; return r;
} }
static int imm_in(int host_no, char *buffer, int len) static int imm_in(int host_no, char *buffer, int len)
{ {
int r; int r;
unsigned short ppb = IMM_BASE(host_no); unsigned short ppb = IMM_BASE(host_no);
r = imm_wait(host_no);
/*
* Make sure that:
* a) the SCSI bus is BUSY (device still listening)
* b) the device is sending data
*/
if ((r & 0x18) != 0x18) {
imm_fail(host_no, DID_ERROR);
return 0;
}
switch (imm_hosts[host_no].mode) {
case IMM_NIBBLE:
/* 4 bit input, with a loop */
r = imm_nibble_in(ppb, buffer, len);
w_ctr(ppb, 0xc);
break;
case IMM_PS2: r = imm_wait(host_no);
/* 8 bit input, with a loop */
r = imm_byte_in(ppb, buffer, len);
w_ctr(ppb, 0xc);
break;
case IMM_EPP_32: /*
case IMM_EPP_16: * Make sure that:
case IMM_EPP_8: * a) the SCSI bus is BUSY (device still listening)
epp_reset(ppb); * b) the device is sending data
w_ctr(ppb, 0x24); */
if ((r & 0x18) != 0x18) {
imm_fail(host_no, DID_ERROR);
return 0;
}
switch (imm_hosts[host_no].mode) {
case IMM_NIBBLE:
/* 4 bit input, with a loop */
r = imm_nibble_in(ppb, buffer, len);
w_ctr(ppb, 0xc);
break;
case IMM_PS2:
/* 8 bit input, with a loop */
r = imm_byte_in(ppb, buffer, len);
w_ctr(ppb, 0xc);
break;
case IMM_EPP_32:
case IMM_EPP_16:
case IMM_EPP_8:
epp_reset(ppb);
w_ctr(ppb, 0x24);
#ifdef CONFIG_SCSI_IZIP_EPP16 #ifdef CONFIG_SCSI_IZIP_EPP16
if (!(((long) buffer | len) & 0x01)) if (!(((long) buffer | len) & 0x01))
insw(ppb + 4, buffer, len >> 1); insw(ppb + 4, buffer, len >> 1);
#else #else
if (!(((long) buffer | len) & 0x03)) if (!(((long) buffer | len) & 0x03))
insl(ppb + 4, buffer, len >> 2); insl(ppb + 4, buffer, len >> 2);
#endif #endif
else else
insb(ppb + 4, buffer, len); insb(ppb + 4, buffer, len);
w_ctr(ppb, 0x2c); w_ctr(ppb, 0x2c);
r = !(r_str(ppb) & 0x01); r = !(r_str(ppb) & 0x01);
w_ctr(ppb, 0x2c); w_ctr(ppb, 0x2c);
ecp_sync(host_no); ecp_sync(host_no);
break; break;
default: default:
printk("IMM: bug in imm_ins()\n"); printk("IMM: bug in imm_ins()\n");
r = 0; r = 0;
break; break;
} }
return r; return r;
} }
static int imm_cpp(unsigned short ppb, unsigned char b) static int imm_cpp(unsigned short ppb, unsigned char b)
{ {
/* /*
* Comments on udelay values refer to the * Comments on udelay values refer to the
* Command Packet Protocol (CPP) timing diagram. * Command Packet Protocol (CPP) timing diagram.
*/ */
unsigned char s1, s2, s3; unsigned char s1, s2, s3;
w_ctr(ppb, 0x0c); w_ctr(ppb, 0x0c);
udelay(2); /* 1 usec - infinite */ udelay(2); /* 1 usec - infinite */
w_dtr(ppb, 0xaa); w_dtr(ppb, 0xaa);
udelay(10); /* 7 usec - infinite */ udelay(10); /* 7 usec - infinite */
w_dtr(ppb, 0x55); w_dtr(ppb, 0x55);
udelay(10); /* 7 usec - infinite */ udelay(10); /* 7 usec - infinite */
w_dtr(ppb, 0x00); w_dtr(ppb, 0x00);
udelay(10); /* 7 usec - infinite */ udelay(10); /* 7 usec - infinite */
w_dtr(ppb, 0xff); w_dtr(ppb, 0xff);
udelay(10); /* 7 usec - infinite */ udelay(10); /* 7 usec - infinite */
s1 = r_str(ppb) & 0xb8; s1 = r_str(ppb) & 0xb8;
w_dtr(ppb, 0x87); w_dtr(ppb, 0x87);
udelay(10); /* 7 usec - infinite */ udelay(10); /* 7 usec - infinite */
s2 = r_str(ppb) & 0xb8; s2 = r_str(ppb) & 0xb8;
w_dtr(ppb, 0x78); w_dtr(ppb, 0x78);
udelay(10); /* 7 usec - infinite */ udelay(10); /* 7 usec - infinite */
s3 = r_str(ppb) & 0x38; s3 = r_str(ppb) & 0x38;
/* /*
* Values for b are: * Values for b are:
* 0000 00aa Assign address aa to current device * 0000 00aa Assign address aa to current device
* 0010 00aa Select device aa in EPP Winbond mode * 0010 00aa Select device aa in EPP Winbond mode
* 0010 10aa Select device aa in EPP mode * 0010 10aa Select device aa in EPP mode
* 0011 xxxx Deselect all devices * 0011 xxxx Deselect all devices
* 0110 00aa Test device aa * 0110 00aa Test device aa
* 1101 00aa Select device aa in ECP mode * 1101 00aa Select device aa in ECP mode
* 1110 00aa Select device aa in Compatible mode * 1110 00aa Select device aa in Compatible mode
*/ */
w_dtr(ppb, b); w_dtr(ppb, b);
udelay(2); /* 1 usec - infinite */ udelay(2); /* 1 usec - infinite */
w_ctr(ppb, 0x0c); w_ctr(ppb, 0x0c);
udelay(10); /* 7 usec - infinite */ udelay(10); /* 7 usec - infinite */
w_ctr(ppb, 0x0d); w_ctr(ppb, 0x0d);
udelay(2); /* 1 usec - infinite */ udelay(2); /* 1 usec - infinite */
w_ctr(ppb, 0x0c); w_ctr(ppb, 0x0c);
udelay(10); /* 7 usec - infinite */ udelay(10); /* 7 usec - infinite */
w_dtr(ppb, 0xff); w_dtr(ppb, 0xff);
udelay(10); /* 7 usec - infinite */ udelay(10); /* 7 usec - infinite */
/* /*
* The following table is electrical pin values. * The following table is electrical pin values.
* (BSY is inverted at the CTR register) * (BSY is inverted at the CTR register)
* *
* BSY ACK POut SEL Fault * BSY ACK POut SEL Fault
* S1 0 X 1 1 1 * S1 0 X 1 1 1
* S2 1 X 0 1 1 * S2 1 X 0 1 1
* S3 L X 1 1 S * S3 L X 1 1 S
* *
* L => Last device in chain * L => Last device in chain
* S => Selected * S => Selected
* *
* Observered values for S1,S2,S3 are: * Observered values for S1,S2,S3 are:
* Disconnect => f8/58/78 * Disconnect => f8/58/78
* Connect => f8/58/70 * Connect => f8/58/70
*/ */
if ((s1 == 0xb8) && (s2 == 0x18) && (s3 == 0x30)) if ((s1 == 0xb8) && (s2 == 0x18) && (s3 == 0x30))
return 1; /* Connected */ return 1; /* Connected */
if ((s1 == 0xb8) && (s2 == 0x18) && (s3 == 0x38)) if ((s1 == 0xb8) && (s2 == 0x18) && (s3 == 0x38))
return 0; /* Disconnected */ return 0; /* Disconnected */
return -1; /* No device present */ return -1; /* No device present */
} }
static inline int imm_connect(int host_no, int flag) static inline int imm_connect(int host_no, int flag)
{ {
unsigned short ppb = IMM_BASE(host_no); unsigned short ppb = IMM_BASE(host_no);
imm_cpp(ppb, 0xe0); /* Select device 0 in compatible mode */ imm_cpp(ppb, 0xe0); /* Select device 0 in compatible mode */
imm_cpp(ppb, 0x30); /* Disconnect all devices */ imm_cpp(ppb, 0x30); /* Disconnect all devices */
if ((imm_hosts[host_no].mode == IMM_EPP_8) || if ((imm_hosts[host_no].mode == IMM_EPP_8) ||
(imm_hosts[host_no].mode == IMM_EPP_16) || (imm_hosts[host_no].mode == IMM_EPP_16) ||
(imm_hosts[host_no].mode == IMM_EPP_32)) (imm_hosts[host_no].mode == IMM_EPP_32))
return imm_cpp(ppb, 0x28); /* Select device 0 in EPP mode */ return imm_cpp(ppb, 0x28); /* Select device 0 in EPP mode */
return imm_cpp(ppb, 0xe0); /* Select device 0 in compatible mode */ return imm_cpp(ppb, 0xe0); /* Select device 0 in compatible mode */
} }
static void imm_disconnect(int host_no) static void imm_disconnect(int host_no)
{ {
unsigned short ppb = IMM_BASE(host_no); unsigned short ppb = IMM_BASE(host_no);
imm_cpp(ppb, 0x30); /* Disconnect all devices */ imm_cpp(ppb, 0x30); /* Disconnect all devices */
} }
static int imm_select(int host_no, int target) static int imm_select(int host_no, int target)
{ {
int k; int k;
unsigned short ppb = IMM_BASE(host_no); unsigned short ppb = IMM_BASE(host_no);
/* /*
* Firstly we want to make sure there is nothing * Firstly we want to make sure there is nothing
* holding onto the SCSI bus. * holding onto the SCSI bus.
*/ */
w_ctr(ppb, 0xc); w_ctr(ppb, 0xc);
k = IMM_SELECT_TMO; k = IMM_SELECT_TMO;
do { do {
k--; k--;
} while ((r_str(ppb) & 0x08) && (k)); } while ((r_str(ppb) & 0x08) && (k));
if (!k) if (!k)
return 0; return 0;
/* /*
* Now assert the SCSI ID (HOST and TARGET) on the data bus * Now assert the SCSI ID (HOST and TARGET) on the data bus
*/ */
w_ctr(ppb, 0x4); w_ctr(ppb, 0x4);
w_dtr(ppb, 0x80 | (1 << target)); w_dtr(ppb, 0x80 | (1 << target));
udelay(1); udelay(1);
/* /*
* Deassert SELIN first followed by STROBE * Deassert SELIN first followed by STROBE
*/ */
w_ctr(ppb, 0xc); w_ctr(ppb, 0xc);
w_ctr(ppb, 0xd); w_ctr(ppb, 0xd);
/* /*
* ACK should drop low while SELIN is deasserted. * ACK should drop low while SELIN is deasserted.
* FAULT should drop low when the SCSI device latches the bus. * FAULT should drop low when the SCSI device latches the bus.
*/ */
k = IMM_SELECT_TMO; k = IMM_SELECT_TMO;
do { do {
k--; k--;
} }
while (!(r_str(ppb) & 0x08) && (k)); while (!(r_str(ppb) & 0x08) && (k));
/* /*
* Place the interface back into a sane state (status mode) * Place the interface back into a sane state (status mode)
*/ */
w_ctr(ppb, 0xc); w_ctr(ppb, 0xc);
return (k) ? 1 : 0; return (k) ? 1 : 0;
} }
static int imm_init(int host_no) static int imm_init(int host_no)
{ {
int retv; int retv;
#if defined(CONFIG_PARPORT) || defined(CONFIG_PARPORT_MODULE) #if defined(CONFIG_PARPORT) || defined(CONFIG_PARPORT_MODULE)
if (imm_pb_claim(host_no)) if (imm_pb_claim(host_no))
while (imm_hosts[host_no].p_busy) while (imm_hosts[host_no].p_busy)
schedule(); /* We can safe schedule here */ schedule(); /* We can safe schedule here */
#endif #endif
retv = imm_connect(host_no, 0); retv = imm_connect(host_no, 0);
if (retv == 1) { if (retv == 1) {
imm_reset_pulse(IMM_BASE(host_no)); imm_reset_pulse(IMM_BASE(host_no));
udelay(1000); /* Delay to allow devices to settle */ udelay(1000); /* Delay to allow devices to settle */
imm_disconnect(host_no); imm_disconnect(host_no);
udelay(1000); /* Another delay to allow devices to settle */ udelay(1000); /* Another delay to allow devices to settle */
retv = device_check(host_no); retv = device_check(host_no);
imm_pb_release(host_no);
return retv;
}
imm_pb_release(host_no); imm_pb_release(host_no);
return retv; return 1;
}
imm_pb_release(host_no);
return 1;
} }
static inline int imm_send_command(Scsi_Cmnd * cmd) static inline int imm_send_command(Scsi_Cmnd *cmd)
{ {
int host_no = cmd->device->host->unique_id; int host_no = cmd->device->host->unique_id;
int k; int k;
/* NOTE: IMM uses byte pairs */ /* NOTE: IMM uses byte pairs */
for (k = 0; k < cmd->cmd_len; k += 2) for (k = 0; k < cmd->cmd_len; k += 2)
if (!imm_out(host_no, &cmd->cmnd[k], 2)) if (!imm_out(host_no, &cmd->cmnd[k], 2))
return 0; return 0;
return 1; return 1;
} }
/* /*
...@@ -768,94 +777,99 @@ static inline int imm_send_command(Scsi_Cmnd * cmd) ...@@ -768,94 +777,99 @@ static inline int imm_send_command(Scsi_Cmnd * cmd)
* The driver appears to remain stable if we speed up the parallel port * The driver appears to remain stable if we speed up the parallel port
* i/o in this function, but not elsewhere. * i/o in this function, but not elsewhere.
*/ */
static int imm_completion(Scsi_Cmnd * cmd) static int imm_completion(Scsi_Cmnd *cmd)
{ {
/* Return codes: /* Return codes:
* -1 Error * -1 Error
* 0 Told to schedule * 0 Told to schedule
* 1 Finished data transfer * 1 Finished data transfer
*/
int host_no = cmd->device->host->unique_id;
unsigned short ppb = IMM_BASE(host_no);
unsigned long start_jiffies = jiffies;
unsigned char r, v;
int fast, bulk, status;
v = cmd->cmnd[0];
bulk = ((v == READ_6) ||
(v == READ_10) ||
(v == WRITE_6) ||
(v == WRITE_10));
/*
* We only get here if the drive is ready to comunicate,
* hence no need for a full imm_wait.
*/
w_ctr(ppb, 0x0c);
r = (r_str(ppb) & 0xb8);
/*
* while (device is not ready to send status byte)
* loop;
*/
while (r != (unsigned char) 0xb8) {
/*
* If we have been running for more than a full timer tick
* then take a rest.
*/ */
if (time_after(jiffies, start_jiffies + 1)) int host_no = cmd->device->host->unique_id;
return 0; unsigned short ppb = IMM_BASE(host_no);
unsigned long start_jiffies = jiffies;
unsigned char r, v;
int fast, bulk, status;
v = cmd->cmnd[0];
bulk = ((v == READ_6) ||
(v == READ_10) || (v == WRITE_6) || (v == WRITE_10));
/* /*
* FAIL if: * We only get here if the drive is ready to comunicate,
* a) Drive status is screwy (!ready && !present) * hence no need for a full imm_wait.
* b) Drive is requesting/sending more data than expected
*/ */
if (((r & 0x88) != 0x88) || (cmd->SCp.this_residual <= 0)) { w_ctr(ppb, 0x0c);
imm_fail(host_no, DID_ERROR); r = (r_str(ppb) & 0xb8);
return -1; /* ERROR_RETURN */
}
/* determine if we should use burst I/O */
if (imm_hosts[host_no].rd == 0) {
fast = (bulk && (cmd->SCp.this_residual >= IMM_BURST_SIZE)) ? IMM_BURST_SIZE : 2;
status = imm_out(host_no, cmd->SCp.ptr, fast);
} else {
fast = (bulk && (cmd->SCp.this_residual >= IMM_BURST_SIZE)) ? IMM_BURST_SIZE : 1;
status = imm_in(host_no, cmd->SCp.ptr, fast);
}
cmd->SCp.ptr += fast;
cmd->SCp.this_residual -= fast;
if (!status) { /*
imm_fail(host_no, DID_BUS_BUSY); * while (device is not ready to send status byte)
return -1; /* ERROR_RETURN */ * loop;
} */
if (cmd->SCp.buffer && !cmd->SCp.this_residual) { while (r != (unsigned char) 0xb8) {
/* if scatter/gather, advance to the next segment */ /*
if (cmd->SCp.buffers_residual--) { * If we have been running for more than a full timer tick
cmd->SCp.buffer++; * then take a rest.
cmd->SCp.this_residual = cmd->SCp.buffer->length; */
cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) + cmd->SCp.buffer->offset; if (time_after(jiffies, start_jiffies + 1))
return 0;
/* /*
* Make sure that we transfer even number of bytes * FAIL if:
* otherwise it makes imm_byte_out() messy. * a) Drive status is screwy (!ready && !present)
* b) Drive is requesting/sending more data than expected
*/ */
if (cmd->SCp.this_residual & 0x01) if (((r & 0x88) != 0x88) || (cmd->SCp.this_residual <= 0)) {
cmd->SCp.this_residual++; imm_fail(host_no, DID_ERROR);
} return -1; /* ERROR_RETURN */
} }
/* Now check to see if the drive is ready to comunicate */ /* determine if we should use burst I/O */
w_ctr(ppb, 0x0c); if (imm_hosts[host_no].rd == 0) {
r = (r_str(ppb) & 0xb8); fast = (bulk
&& (cmd->SCp.this_residual >=
IMM_BURST_SIZE)) ? IMM_BURST_SIZE : 2;
status = imm_out(host_no, cmd->SCp.ptr, fast);
} else {
fast = (bulk
&& (cmd->SCp.this_residual >=
IMM_BURST_SIZE)) ? IMM_BURST_SIZE : 1;
status = imm_in(host_no, cmd->SCp.ptr, fast);
}
cmd->SCp.ptr += fast;
cmd->SCp.this_residual -= fast;
/* If not, drop back down to the scheduler and wait a timer tick */ if (!status) {
if (!(r & 0x80)) imm_fail(host_no, DID_BUS_BUSY);
return 0; return -1; /* ERROR_RETURN */
} }
return 1; /* FINISH_RETURN */ if (cmd->SCp.buffer && !cmd->SCp.this_residual) {
/* if scatter/gather, advance to the next segment */
if (cmd->SCp.buffers_residual--) {
cmd->SCp.buffer++;
cmd->SCp.this_residual =
cmd->SCp.buffer->length;
cmd->SCp.ptr =
page_address(cmd->SCp.buffer->page) +
cmd->SCp.buffer->offset;
/*
* Make sure that we transfer even number of bytes
* otherwise it makes imm_byte_out() messy.
*/
if (cmd->SCp.this_residual & 0x01)
cmd->SCp.this_residual++;
}
}
/* Now check to see if the drive is ready to comunicate */
w_ctr(ppb, 0x0c);
r = (r_str(ppb) & 0xb8);
/* If not, drop back down to the scheduler and wait a timer tick */
if (!(r & 0x80))
return 0;
}
return 1; /* FINISH_RETURN */
} }
/* /*
...@@ -865,226 +879,231 @@ static int imm_completion(Scsi_Cmnd * cmd) ...@@ -865,226 +879,231 @@ static int imm_completion(Scsi_Cmnd * cmd)
*/ */
static void imm_interrupt(void *data) static void imm_interrupt(void *data)
{ {
imm_struct *tmp = (imm_struct *) data; imm_struct *tmp = (imm_struct *) data;
Scsi_Cmnd *cmd = tmp->cur_cmd; Scsi_Cmnd *cmd = tmp->cur_cmd;
struct Scsi_Host *host = cmd->device->host; struct Scsi_Host *host = cmd->device->host;
unsigned long flags; unsigned long flags;
if (!cmd) { if (!cmd) {
printk("IMM: bug in imm_interrupt\n"); printk("IMM: bug in imm_interrupt\n");
return; return;
} }
if (imm_engine(tmp, cmd)) { if (imm_engine(tmp, cmd)) {
INIT_WORK(&tmp->imm_tq, imm_interrupt, (void *)tmp); INIT_WORK(&tmp->imm_tq, imm_interrupt, (void *) tmp);
schedule_delayed_work(&tmp->imm_tq, 1); schedule_delayed_work(&tmp->imm_tq, 1);
return; return;
} }
/* Command must of completed hence it is safe to let go... */ /* Command must of completed hence it is safe to let go... */
#if IMM_DEBUG > 0 #if IMM_DEBUG > 0
switch ((cmd->result >> 16) & 0xff) { switch ((cmd->result >> 16) & 0xff) {
case DID_OK: case DID_OK:
break; break;
case DID_NO_CONNECT: case DID_NO_CONNECT:
printk("imm: no device at SCSI ID %i\n", cmd->target); printk("imm: no device at SCSI ID %i\n", cmd->target);
break; break;
case DID_BUS_BUSY: case DID_BUS_BUSY:
printk("imm: BUS BUSY - EPP timeout detected\n"); printk("imm: BUS BUSY - EPP timeout detected\n");
break; break;
case DID_TIME_OUT: case DID_TIME_OUT:
printk("imm: unknown timeout\n"); printk("imm: unknown timeout\n");
break; break;
case DID_ABORT: case DID_ABORT:
printk("imm: told to abort\n"); printk("imm: told to abort\n");
break; break;
case DID_PARITY: case DID_PARITY:
printk("imm: parity error (???)\n"); printk("imm: parity error (???)\n");
break; break;
case DID_ERROR: case DID_ERROR:
printk("imm: internal driver error\n"); printk("imm: internal driver error\n");
break; break;
case DID_RESET: case DID_RESET:
printk("imm: told to reset device\n"); printk("imm: told to reset device\n");
break; break;
case DID_BAD_INTR: case DID_BAD_INTR:
printk("imm: bad interrupt (???)\n"); printk("imm: bad interrupt (???)\n");
break; break;
default: default:
printk("imm: bad return code (%02x)\n", (cmd->result >> 16) & 0xff); printk("imm: bad return code (%02x)\n",
} (cmd->result >> 16) & 0xff);
}
#endif #endif
if (cmd->SCp.phase > 1) if (cmd->SCp.phase > 1)
imm_disconnect(cmd->device->host->unique_id); imm_disconnect(cmd->device->host->unique_id);
if (cmd->SCp.phase > 0) if (cmd->SCp.phase > 0)
imm_pb_release(cmd->device->host->unique_id); imm_pb_release(cmd->device->host->unique_id);
spin_lock_irqsave(host->host_lock, flags); spin_lock_irqsave(host->host_lock, flags);
tmp->cur_cmd = 0; tmp->cur_cmd = 0;
cmd->scsi_done(cmd); cmd->scsi_done(cmd);
spin_unlock_irqrestore(host->host_lock, flags); spin_unlock_irqrestore(host->host_lock, flags);
return; return;
} }
static int imm_engine(imm_struct * tmp, Scsi_Cmnd * cmd) static int imm_engine(imm_struct *tmp, Scsi_Cmnd *cmd)
{ {
int host_no = cmd->device->host->unique_id; int host_no = cmd->device->host->unique_id;
unsigned short ppb = IMM_BASE(host_no); unsigned short ppb = IMM_BASE(host_no);
unsigned char l = 0, h = 0; unsigned char l = 0, h = 0;
int retv, x; int retv, x;
/* First check for any errors that may have occurred
* Here we check for internal errors
*/
if (tmp->failed)
return 0;
switch (cmd->SCp.phase) { /* First check for any errors that may have occurred
case 0: /* Phase 0 - Waiting for parport */ * Here we check for internal errors
if ((jiffies - tmp->jstart) > HZ) { */
/* if (tmp->failed)
* We waited more than a second
* for parport to call us
*/
imm_fail(host_no, DID_BUS_BUSY);
return 0;
}
return 1; /* wait until imm_wakeup claims parport */
/* Phase 1 - Connected */
case 1:
imm_connect(host_no, CONNECT_EPP_MAYBE);
cmd->SCp.phase++;
/* Phase 2 - We are now talking to the scsi bus */
case 2:
if (!imm_select(host_no, cmd->device->id)) {
imm_fail(host_no, DID_NO_CONNECT);
return 0;
}
cmd->SCp.phase++;
/* Phase 3 - Ready to accept a command */
case 3:
w_ctr(ppb, 0x0c);
if (!(r_str(ppb) & 0x80))
return 1;
if (!imm_send_command(cmd))
return 0;
cmd->SCp.phase++;
/* Phase 4 - Setup scatter/gather buffers */
case 4:
if (cmd->use_sg) {
/* if many buffers are available, start filling the first */
cmd->SCp.buffer = (struct scatterlist *) cmd->request_buffer;
cmd->SCp.this_residual = cmd->SCp.buffer->length;
cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) + cmd->SCp.buffer->offset;
} else {
/* else fill the only available buffer */
cmd->SCp.buffer = NULL;
cmd->SCp.this_residual = cmd->request_bufflen;
cmd->SCp.ptr = cmd->request_buffer;
}
cmd->SCp.buffers_residual = cmd->use_sg - 1;
cmd->SCp.phase++;
if (cmd->SCp.this_residual & 0x01)
cmd->SCp.this_residual++;
/* Phase 5 - Pre-Data transfer stage */
case 5:
/* Spin lock for BUSY */
w_ctr(ppb, 0x0c);
if (!(r_str(ppb) & 0x80))
return 1;
/* Require negotiation for read requests */
x = (r_str(ppb) & 0xb8);
tmp->rd = (x & 0x10) ? 1 : 0;
tmp->dp = (x & 0x20) ? 0 : 1;
if ((tmp->dp) && (tmp->rd))
if (imm_negotiate(tmp))
return 0; return 0;
cmd->SCp.phase++;
/* Phase 6 - Data transfer stage */
case 6:
/* Spin lock for BUSY */
w_ctr(ppb, 0x0c);
if (!(r_str(ppb) & 0x80))
return 1;
if (tmp->dp) { switch (cmd->SCp.phase) {
retv = imm_completion(cmd); case 0: /* Phase 0 - Waiting for parport */
if (retv == -1) if ((jiffies - tmp->jstart) > HZ) {
return 0; /*
if (retv == 0) * We waited more than a second
return 1; * for parport to call us
} */
cmd->SCp.phase++; imm_fail(host_no, DID_BUS_BUSY);
return 0;
}
return 1; /* wait until imm_wakeup claims parport */
/* Phase 1 - Connected */
case 1:
imm_connect(host_no, CONNECT_EPP_MAYBE);
cmd->SCp.phase++;
/* Phase 2 - We are now talking to the scsi bus */
case 2:
if (!imm_select(host_no, cmd->device->id)) {
imm_fail(host_no, DID_NO_CONNECT);
return 0;
}
cmd->SCp.phase++;
/* Phase 3 - Ready to accept a command */
case 3:
w_ctr(ppb, 0x0c);
if (!(r_str(ppb) & 0x80))
return 1;
if (!imm_send_command(cmd))
return 0;
cmd->SCp.phase++;
/* Phase 4 - Setup scatter/gather buffers */
case 4:
if (cmd->use_sg) {
/* if many buffers are available, start filling the first */
cmd->SCp.buffer =
(struct scatterlist *) cmd->request_buffer;
cmd->SCp.this_residual = cmd->SCp.buffer->length;
cmd->SCp.ptr =
page_address(cmd->SCp.buffer->page) +
cmd->SCp.buffer->offset;
} else {
/* else fill the only available buffer */
cmd->SCp.buffer = NULL;
cmd->SCp.this_residual = cmd->request_bufflen;
cmd->SCp.ptr = cmd->request_buffer;
}
cmd->SCp.buffers_residual = cmd->use_sg - 1;
cmd->SCp.phase++;
if (cmd->SCp.this_residual & 0x01)
cmd->SCp.this_residual++;
/* Phase 5 - Pre-Data transfer stage */
case 5:
/* Spin lock for BUSY */
w_ctr(ppb, 0x0c);
if (!(r_str(ppb) & 0x80))
return 1;
/* Require negotiation for read requests */
x = (r_str(ppb) & 0xb8);
tmp->rd = (x & 0x10) ? 1 : 0;
tmp->dp = (x & 0x20) ? 0 : 1;
if ((tmp->dp) && (tmp->rd))
if (imm_negotiate(tmp))
return 0;
cmd->SCp.phase++;
/* Phase 6 - Data transfer stage */
case 6:
/* Spin lock for BUSY */
w_ctr(ppb, 0x0c);
if (!(r_str(ppb) & 0x80))
return 1;
if (tmp->dp) {
retv = imm_completion(cmd);
if (retv == -1)
return 0;
if (retv == 0)
return 1;
}
cmd->SCp.phase++;
/* Phase 7 - Post data transfer stage */
case 7:
if ((tmp->dp) && (tmp->rd)) {
if ((tmp->mode == IMM_NIBBLE) || (tmp->mode == IMM_PS2)) {
w_ctr(ppb, 0x4);
w_ctr(ppb, 0xc);
w_ctr(ppb, 0xe);
w_ctr(ppb, 0x4);
}
}
cmd->SCp.phase++;
/* Phase 8 - Read status/message */
case 8:
/* Check for data overrun */
if (imm_wait(host_no) != (unsigned char) 0xb8) {
imm_fail(host_no, DID_ERROR);
return 0;
}
if (imm_negotiate(tmp))
return 0;
if (imm_in(host_no, &l, 1)) { /* read status byte */
/* Check for optional message byte */
if (imm_wait(host_no) == (unsigned char) 0xb8)
imm_in(host_no, &h, 1);
cmd->result = (DID_OK << 16) + (l & STATUS_MASK);
}
if ((tmp->mode == IMM_NIBBLE) || (tmp->mode == IMM_PS2)) {
w_ctr(ppb, 0x4);
w_ctr(ppb, 0xc);
w_ctr(ppb, 0xe);
w_ctr(ppb, 0x4);
}
return 0; /* Finished */
break;
/* Phase 7 - Post data transfer stage */ default:
case 7: printk("imm: Invalid scsi phase\n");
if ((tmp->dp) && (tmp->rd)) {
if ((tmp->mode == IMM_NIBBLE) || (tmp->mode == IMM_PS2)) {
w_ctr(ppb, 0x4);
w_ctr(ppb, 0xc);
w_ctr(ppb, 0xe);
w_ctr(ppb, 0x4);
}
}
cmd->SCp.phase++;
/* Phase 8 - Read status/message */
case 8:
/* Check for data overrun */
if (imm_wait(host_no) != (unsigned char) 0xb8) {
imm_fail(host_no, DID_ERROR);
return 0;
}
if (imm_negotiate(tmp))
return 0;
if (imm_in(host_no, &l, 1)) { /* read status byte */
/* Check for optional message byte */
if (imm_wait(host_no) == (unsigned char) 0xb8)
imm_in(host_no, &h, 1);
cmd->result = (DID_OK << 16) + (l & STATUS_MASK);
} }
if ((tmp->mode == IMM_NIBBLE) || (tmp->mode == IMM_PS2)) { return 0;
w_ctr(ppb, 0x4);
w_ctr(ppb, 0xc);
w_ctr(ppb, 0xe);
w_ctr(ppb, 0x4);
}
return 0; /* Finished */
break;
default:
printk("imm: Invalid scsi phase\n");
}
return 0;
} }
int imm_queuecommand(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *)) static int imm_queuecommand(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
{ {
int host_no = cmd->device->host->unique_id; int host_no = cmd->device->host->unique_id;
if (imm_hosts[host_no].cur_cmd) { if (imm_hosts[host_no].cur_cmd) {
printk("IMM: bug in imm_queuecommand\n"); printk("IMM: bug in imm_queuecommand\n");
return 0; return 0;
} }
imm_hosts[host_no].failed = 0; imm_hosts[host_no].failed = 0;
imm_hosts[host_no].jstart = jiffies; imm_hosts[host_no].jstart = jiffies;
imm_hosts[host_no].cur_cmd = cmd; imm_hosts[host_no].cur_cmd = cmd;
cmd->scsi_done = done; cmd->scsi_done = done;
cmd->result = DID_ERROR << 16; /* default return code */ cmd->result = DID_ERROR << 16; /* default return code */
cmd->SCp.phase = 0; /* bus free */ cmd->SCp.phase = 0; /* bus free */
imm_pb_claim(host_no); imm_pb_claim(host_no);
INIT_WORK(&imm_hosts[host_no].imm_tq, imm_interrupt, imm_hosts + host_no); INIT_WORK(&imm_hosts[host_no].imm_tq, imm_interrupt,
schedule_work(&imm_hosts[host_no].imm_tq); imm_hosts + host_no);
schedule_work(&imm_hosts[host_no].imm_tq);
return 0; return 0;
} }
/* /*
...@@ -1093,150 +1112,153 @@ int imm_queuecommand(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *)) ...@@ -1093,150 +1112,153 @@ int imm_queuecommand(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *))
* be done in sd.c. Even if it gets fixed there, this will still * be done in sd.c. Even if it gets fixed there, this will still
* work. * work.
*/ */
int imm_biosparam(struct scsi_device *sdev, struct block_device *dev, static int imm_biosparam(struct scsi_device *sdev, struct block_device *dev,
sector_t capacity, int ip[]) sector_t capacity, int ip[])
{ {
ip[0] = 0x40; ip[0] = 0x40;
ip[1] = 0x20; ip[1] = 0x20;
ip[2] = ((unsigned long)capacity + 1) / (ip[0] * ip[1]); ip[2] = ((unsigned long) capacity + 1) / (ip[0] * ip[1]);
if (ip[2] > 1024) { if (ip[2] > 1024) {
ip[0] = 0xff; ip[0] = 0xff;
ip[1] = 0x3f; ip[1] = 0x3f;
ip[2] = ((unsigned long)capacity + 1) / (ip[0] * ip[1]); ip[2] = ((unsigned long) capacity + 1) / (ip[0] * ip[1]);
} }
return 0; return 0;
} }
int imm_abort(Scsi_Cmnd * cmd) static int imm_abort(Scsi_Cmnd *cmd)
{ {
int host_no = cmd->device->host->unique_id; int host_no = cmd->device->host->unique_id;
/* /*
* There is no method for aborting commands since Iomega * There is no method for aborting commands since Iomega
* have tied the SCSI_MESSAGE line high in the interface * have tied the SCSI_MESSAGE line high in the interface
*/ */
switch (cmd->SCp.phase) { switch (cmd->SCp.phase) {
case 0: /* Do not have access to parport */ case 0: /* Do not have access to parport */
case 1: /* Have not connected to interface */ case 1: /* Have not connected to interface */
imm_hosts[host_no].cur_cmd = NULL; /* Forget the problem */ imm_hosts[host_no].cur_cmd = NULL; /* Forget the problem */
return SUCCESS; return SUCCESS;
break; break;
default: /* SCSI command sent, can not abort */ default: /* SCSI command sent, can not abort */
return FAILED; return FAILED;
break; break;
} }
} }
void imm_reset_pulse(unsigned int base) static void imm_reset_pulse(unsigned int base)
{ {
w_ctr(base, 0x04); w_ctr(base, 0x04);
w_dtr(base, 0x40); w_dtr(base, 0x40);
udelay(1); udelay(1);
w_ctr(base, 0x0c); w_ctr(base, 0x0c);
w_ctr(base, 0x0d); w_ctr(base, 0x0d);
udelay(50); udelay(50);
w_ctr(base, 0x0c); w_ctr(base, 0x0c);
w_ctr(base, 0x04); w_ctr(base, 0x04);
} }
int imm_reset(Scsi_Cmnd * cmd) static int imm_reset(Scsi_Cmnd *cmd)
{ {
int host_no = cmd->device->host->unique_id; int host_no = cmd->device->host->unique_id;
if (cmd->SCp.phase)
imm_disconnect(host_no);
imm_hosts[host_no].cur_cmd = NULL; /* Forget the problem */
if (cmd->SCp.phase) imm_connect(host_no, CONNECT_NORMAL);
imm_reset_pulse(IMM_BASE(host_no));
udelay(1000); /* device settle delay */
imm_disconnect(host_no); imm_disconnect(host_no);
imm_hosts[host_no].cur_cmd = NULL; /* Forget the problem */ udelay(1000); /* device settle delay */
return SUCCESS;
imm_connect(host_no, CONNECT_NORMAL);
imm_reset_pulse(IMM_BASE(host_no));
udelay(1000); /* device settle delay */
imm_disconnect(host_no);
udelay(1000); /* device settle delay */
return SUCCESS;
} }
static int device_check(int host_no) static int device_check(int host_no)
{ {
/* This routine looks for a device and then attempts to use EPP /* This routine looks for a device and then attempts to use EPP
to send a command. If all goes as planned then EPP is available. */ to send a command. If all goes as planned then EPP is available. */
static char cmd[6] = static char cmd[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; int loop, old_mode, status, k, ppb = IMM_BASE(host_no);
int loop, old_mode, status, k, ppb = IMM_BASE(host_no); unsigned char l;
unsigned char l;
old_mode = imm_hosts[host_no].mode;
old_mode = imm_hosts[host_no].mode; for (loop = 0; loop < 8; loop++) {
for (loop = 0; loop < 8; loop++) { /* Attempt to use EPP for Test Unit Ready */
/* Attempt to use EPP for Test Unit Ready */ if ((ppb & 0x0007) == 0x0000)
if ((ppb & 0x0007) == 0x0000) imm_hosts[host_no].mode = IMM_EPP_32;
imm_hosts[host_no].mode = IMM_EPP_32;
second_pass:
second_pass: imm_connect(host_no, CONNECT_EPP_MAYBE);
imm_connect(host_no, CONNECT_EPP_MAYBE); /* Select SCSI device */
/* Select SCSI device */ if (!imm_select(host_no, loop)) {
if (!imm_select(host_no, loop)) { imm_disconnect(host_no);
imm_disconnect(host_no); continue;
continue; }
} printk("imm: Found device at ID %i, Attempting to use %s\n",
printk("imm: Found device at ID %i, Attempting to use %s\n", loop, loop, IMM_MODE_STRING[imm_hosts[host_no].mode]);
IMM_MODE_STRING[imm_hosts[host_no].mode]);
/* Send SCSI command */
/* Send SCSI command */ status = 1;
status = 1; w_ctr(ppb, 0x0c);
w_ctr(ppb, 0x0c); for (l = 0; (l < 3) && (status); l++)
for (l = 0; (l < 3) && (status); l++) status = imm_out(host_no, &cmd[l << 1], 2);
status = imm_out(host_no, &cmd[l << 1], 2);
if (!status) {
if (!status) { imm_disconnect(host_no);
imm_disconnect(host_no); imm_connect(host_no, CONNECT_EPP_MAYBE);
imm_connect(host_no, CONNECT_EPP_MAYBE); imm_reset_pulse(IMM_BASE(host_no));
imm_reset_pulse(IMM_BASE(host_no)); udelay(1000);
udelay(1000); imm_disconnect(host_no);
imm_disconnect(host_no); udelay(1000);
udelay(1000); if (imm_hosts[host_no].mode == IMM_EPP_32) {
if (imm_hosts[host_no].mode == IMM_EPP_32) { imm_hosts[host_no].mode = old_mode;
imm_hosts[host_no].mode = old_mode; goto second_pass;
goto second_pass; }
} printk
printk("imm: Unable to establish communication, aborting driver load.\n"); ("imm: Unable to establish communication, aborting driver load.\n");
return 1; return 1;
} }
w_ctr(ppb, 0x0c); w_ctr(ppb, 0x0c);
k = 1000000; /* 1 Second */ k = 1000000; /* 1 Second */
do { do {
l = r_str(ppb); l = r_str(ppb);
k--; k--;
udelay(1); udelay(1);
} while (!(l & 0x80) && (k)); } while (!(l & 0x80) && (k));
l &= 0xb8; l &= 0xb8;
if (l != 0xb8) { if (l != 0xb8) {
imm_disconnect(host_no); imm_disconnect(host_no);
imm_connect(host_no, CONNECT_EPP_MAYBE); imm_connect(host_no, CONNECT_EPP_MAYBE);
imm_reset_pulse(IMM_BASE(host_no)); imm_reset_pulse(IMM_BASE(host_no));
udelay(1000); udelay(1000);
imm_disconnect(host_no); imm_disconnect(host_no);
udelay(1000); udelay(1000);
if (imm_hosts[host_no].mode == IMM_EPP_32) { if (imm_hosts[host_no].mode == IMM_EPP_32) {
imm_hosts[host_no].mode = old_mode; imm_hosts[host_no].mode = old_mode;
goto second_pass; goto second_pass;
} }
printk("imm: Unable to establish communication, aborting driver load.\n"); printk
return 1; ("imm: Unable to establish communication, aborting driver load.\n");
return 1;
}
imm_disconnect(host_no);
printk
("imm: Communication established at 0x%x with ID %i using %s\n",
ppb, loop, IMM_MODE_STRING[imm_hosts[host_no].mode]);
imm_connect(host_no, CONNECT_EPP_MAYBE);
imm_reset_pulse(IMM_BASE(host_no));
udelay(1000);
imm_disconnect(host_no);
udelay(1000);
return 0;
} }
imm_disconnect(host_no); printk("imm: No devices found, aborting driver load.\n");
printk("imm: Communication established at 0x%x with ID %i using %s\n", ppb, loop, return 1;
IMM_MODE_STRING[imm_hosts[host_no].mode]);
imm_connect(host_no, CONNECT_EPP_MAYBE);
imm_reset_pulse(IMM_BASE(host_no));
udelay(1000);
imm_disconnect(host_no);
udelay(1000);
return 0;
}
printk("imm: No devices found, aborting driver load.\n");
return 1;
} }
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
...@@ -66,7 +66,6 @@ ...@@ -66,7 +66,6 @@
*/ */
/* ------ END OF USER CONFIGURABLE PARAMETERS ----- */ /* ------ END OF USER CONFIGURABLE PARAMETERS ----- */
#ifdef IMM_CODE
#include <linux/config.h> #include <linux/config.h>
#include <linux/stddef.h> #include <linux/stddef.h>
#include <linux/module.h> #include <linux/module.h>
...@@ -150,18 +149,12 @@ static int imm_init(int); ...@@ -150,18 +149,12 @@ static int imm_init(int);
static void imm_interrupt(void *); static void imm_interrupt(void *);
static int imm_out(int, char *, int); static int imm_out(int, char *, int);
#else static int imm_detect(Scsi_Host_Template *);
#define imm_release 0 static int imm_queuecommand(Scsi_Cmnd *, void (*done) (Scsi_Cmnd *));
#endif static int imm_abort(Scsi_Cmnd *);
static int imm_reset(Scsi_Cmnd *);
int imm_detect(Scsi_Host_Template *); static int imm_proc_info(struct Scsi_Host *, char *, char **, off_t, int, int);
const char *imm_info(struct Scsi_Host *); static int imm_biosparam(struct scsi_device *, struct block_device *,
int imm_command(Scsi_Cmnd *);
int imm_queuecommand(Scsi_Cmnd *, void (*done) (Scsi_Cmnd *));
int imm_abort(Scsi_Cmnd *);
int imm_reset(Scsi_Cmnd *);
int imm_proc_info(struct Scsi_Host *, char *, char **, off_t, int, int);
int imm_biosparam(struct scsi_device *, struct block_device *,
sector_t, int *); sector_t, int *);
#endif /* _IMM_H */ #endif /* _IMM_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment