Commit 64a29c61 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] scsi/ppa.c cleanup and fixes (1/9)

	* ppa.c fed through Lindent, functions unused elsewhere (by now -
	  all of them) made static.
parent 1f9530ba
...@@ -21,20 +21,20 @@ ...@@ -21,20 +21,20 @@
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include "scsi.h" #include "scsi.h"
#include "hosts.h" #include "hosts.h"
int ppa_release(struct Scsi_Host *); static int ppa_release(struct Scsi_Host *);
static void ppa_reset_pulse(unsigned int base); static void ppa_reset_pulse(unsigned int base);
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 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 ppa_tq; /* Polling interrupt stuff */ struct work_struct ppa_tq; /* Polling interrupt stuff */
unsigned long jstart; /* Jiffies at start */ unsigned long jstart; /* Jiffies at start */
unsigned long recon_tmo; /* How many usecs to wait for reconnection (6th bit) */ unsigned long recon_tmo; /* How many usecs to wait for reconnection (6th bit) */
unsigned int failed:1; /* Failure flag */ unsigned int failed:1; /* Failure flag */
unsigned int p_busy:1; /* Parport sharing busy flag */ unsigned int p_busy:1; /* Parport sharing busy flag */
} ppa_struct; } ppa_struct;
#define PPA_EMPTY \ #define PPA_EMPTY \
...@@ -49,47 +49,47 @@ typedef struct { ...@@ -49,47 +49,47 @@ typedef struct {
#define NO_HOSTS 4 #define NO_HOSTS 4
static ppa_struct ppa_hosts[NO_HOSTS] = static ppa_struct ppa_hosts[NO_HOSTS] =
{PPA_EMPTY, PPA_EMPTY, PPA_EMPTY, PPA_EMPTY}; { PPA_EMPTY, PPA_EMPTY, PPA_EMPTY, PPA_EMPTY };
#define PPA_BASE(x) ppa_hosts[(x)].base #define PPA_BASE(x) ppa_hosts[(x)].base
void ppa_wakeup(void *ref) static void ppa_wakeup(void *ref)
{ {
ppa_struct *ppa_dev = (ppa_struct *) ref; ppa_struct *ppa_dev = (ppa_struct *) ref;
if (!ppa_dev->p_busy) if (!ppa_dev->p_busy)
return; return;
if (parport_claim(ppa_dev->dev)) { if (parport_claim(ppa_dev->dev)) {
printk("ppa: bug in ppa_wakeup\n"); printk("ppa: bug in ppa_wakeup\n");
return;
}
ppa_dev->p_busy = 0;
ppa_dev->base = ppa_dev->dev->port->base;
if (ppa_dev->cur_cmd)
ppa_dev->cur_cmd->SCp.phase++;
return; return;
}
ppa_dev->p_busy = 0;
ppa_dev->base = ppa_dev->dev->port->base;
if (ppa_dev->cur_cmd)
ppa_dev->cur_cmd->SCp.phase++;
return;
} }
int ppa_release(struct Scsi_Host *host) static int ppa_release(struct Scsi_Host *host)
{ {
int host_no = host->unique_id; int host_no = host->unique_id;
printk("Releasing ppa%i\n", host_no); printk("Releasing ppa%i\n", host_no);
scsi_unregister(host); scsi_unregister(host);
parport_unregister_device(ppa_hosts[host_no].dev); parport_unregister_device(ppa_hosts[host_no].dev);
return 0; return 0;
} }
static int ppa_pb_claim(int host_no) static int ppa_pb_claim(int host_no)
{ {
if (parport_claim(ppa_hosts[host_no].dev)) { if (parport_claim(ppa_hosts[host_no].dev)) {
ppa_hosts[host_no].p_busy = 1; ppa_hosts[host_no].p_busy = 1;
return 1; return 1;
} }
if (ppa_hosts[host_no].cur_cmd) if (ppa_hosts[host_no].cur_cmd)
ppa_hosts[host_no].cur_cmd->SCp.phase++; ppa_hosts[host_no].cur_cmd->SCp.phase++;
return 0; return 0;
} }
#define ppa_pb_release(x) parport_release(ppa_hosts[(x)].dev) #define ppa_pb_release(x) parport_release(ppa_hosts[(x)].dev)
...@@ -99,148 +99,156 @@ static int ppa_pb_claim(int host_no) ...@@ -99,148 +99,156 @@ static int ppa_pb_claim(int host_no)
***************************************************************************/ ***************************************************************************/
static Scsi_Host_Template driver_template = { static Scsi_Host_Template driver_template = {
.proc_name = "ppa", .proc_name = "ppa",
.proc_info = ppa_proc_info, .proc_info = ppa_proc_info,
.name = "Iomega VPI0 (ppa) interface", .name = "Iomega VPI0 (ppa) interface",
.detect = ppa_detect, .detect = ppa_detect,
.release = ppa_release, .release = ppa_release,
.queuecommand = ppa_queuecommand, .queuecommand = ppa_queuecommand,
.eh_abort_handler = ppa_abort, .eh_abort_handler = ppa_abort,
.eh_bus_reset_handler = ppa_reset, .eh_bus_reset_handler = ppa_reset,
.eh_host_reset_handler = ppa_reset, .eh_host_reset_handler = ppa_reset,
.bios_param = ppa_biosparam, .bios_param = ppa_biosparam,
.this_id = -1, .this_id = -1,
.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"
/* /*
* Start of Chipset kludges * Start of Chipset kludges
*/ */
int ppa_detect(Scsi_Host_Template * host) static int ppa_detect(Scsi_Host_Template * host)
{ {
struct Scsi_Host *hreg = NULL; struct Scsi_Host *hreg = NULL;
int ports; int ports;
int i, nhosts, try_again; int i, nhosts, try_again;
struct parport *pb; struct parport *pb;
/*
* unlock to allow the lowlevel parport driver to probe
* the irqs
*/
pb = parport_enumerate();
printk("ppa: Version %s\n", PPA_VERSION);
nhosts = 0;
try_again = 0;
if (!pb) {
printk("ppa: parport reports no devices.\n");
return 0;
}
retry_entry:
for (i = 0; pb; i++, pb = pb->next) {
int modes, ppb, ppb_hi;
ppa_hosts[i].dev =
parport_register_device(pb, "ppa", NULL, ppa_wakeup,
NULL, 0, (void *) &ppa_hosts[i]);
if (!ppa_hosts[i].dev)
continue;
/* Claim the bus so it remembers what we do to the control
* registers. [ CTR and ECP ]
*/
if (ppa_pb_claim(i)) {
unsigned long now = jiffies;
while (ppa_hosts[i].p_busy) {
schedule(); /* We are safe to schedule here */
if (time_after(jiffies, now + 3 * HZ)) {
printk(KERN_ERR "ppa%d: failed to claim parport because a "
"pardevice is owning the port for too longtime!\n",
i);
parport_unregister_device(ppa_hosts[i].dev);
spin_lock_irq(ppa_hosts[i].cur_cmd->device->host->host_lock);
return 0;
}
}
}
ppb = PPA_BASE(i) = ppa_hosts[i].dev->port->base;
ppb_hi = ppa_hosts[i].dev->port->base_hi;
w_ctr(ppb, 0x0c);
modes = ppa_hosts[i].dev->port->modes;
/* Mode detection works up the chain of speed /*
* This avoids a nasty if-then-else-if-... tree * unlock to allow the lowlevel parport driver to probe
* the irqs
*/ */
ppa_hosts[i].mode = PPA_NIBBLE; pb = parport_enumerate();
if (modes & PARPORT_MODE_TRISTATE) printk("ppa: Version %s\n", PPA_VERSION);
ppa_hosts[i].mode = PPA_PS2; nhosts = 0;
try_again = 0;
if (modes & PARPORT_MODE_ECP) { if (!pb) {
w_ecr(ppb_hi, 0x20); printk("ppa: parport reports no devices.\n");
ppa_hosts[i].mode = PPA_PS2; return 0;
} }
if ((modes & PARPORT_MODE_EPP) && (modes & PARPORT_MODE_ECP)) retry_entry:
w_ecr(ppb_hi, 0x80); for (i = 0; pb; i++, pb = pb->next) {
int modes, ppb, ppb_hi;
ppa_hosts[i].dev =
parport_register_device(pb, "ppa", NULL, ppa_wakeup,
NULL, 0, (void *) &ppa_hosts[i]);
if (!ppa_hosts[i].dev)
continue;
/* Claim the bus so it remembers what we do to the control
* registers. [ CTR and ECP ]
*/
if (ppa_pb_claim(i)) {
unsigned long now = jiffies;
while (ppa_hosts[i].p_busy) {
schedule(); /* We are safe to schedule here */
if (time_after(jiffies, now + 3 * HZ)) {
printk(KERN_ERR
"ppa%d: failed to claim parport because a "
"pardevice is owning the port for too longtime!\n",
i);
parport_unregister_device(ppa_hosts[i].
dev);
spin_lock_irq(ppa_hosts[i].cur_cmd->
device->host->host_lock);
return 0;
}
}
}
ppb = PPA_BASE(i) = ppa_hosts[i].dev->port->base;
ppb_hi = ppa_hosts[i].dev->port->base_hi;
w_ctr(ppb, 0x0c);
modes = ppa_hosts[i].dev->port->modes;
/* Mode detection works up the chain of speed
* This avoids a nasty if-then-else-if-... tree
*/
ppa_hosts[i].mode = PPA_NIBBLE;
if (modes & PARPORT_MODE_TRISTATE)
ppa_hosts[i].mode = PPA_PS2;
if (modes & PARPORT_MODE_ECP) {
w_ecr(ppb_hi, 0x20);
ppa_hosts[i].mode = PPA_PS2;
}
if ((modes & PARPORT_MODE_EPP) && (modes & PARPORT_MODE_ECP))
w_ecr(ppb_hi, 0x80);
/* Done configuration */ /* Done configuration */
ppa_pb_release(i); ppa_pb_release(i);
if (ppa_init(i)) { if (ppa_init(i)) {
parport_unregister_device(ppa_hosts[i].dev); parport_unregister_device(ppa_hosts[i].dev);
continue; continue;
} }
/* now the glue ... */ /* now the glue ... */
switch (ppa_hosts[i].mode) { switch (ppa_hosts[i].mode) {
case PPA_NIBBLE: case PPA_NIBBLE:
ports = 3; ports = 3;
break; break;
case PPA_PS2: case PPA_PS2:
ports = 3; ports = 3;
break; break;
case PPA_EPP_8: case PPA_EPP_8:
case PPA_EPP_16: case PPA_EPP_16:
case PPA_EPP_32: case PPA_EPP_32:
ports = 8; ports = 8;
break; break;
default: /* Never gets here */ default: /* Never gets here */
continue; continue;
} }
INIT_WORK(&ppa_hosts[i].ppa_tq, ppa_interrupt, &ppa_hosts[i]); INIT_WORK(&ppa_hosts[i].ppa_tq, ppa_interrupt, &ppa_hosts[i]);
host->can_queue = PPA_CAN_QUEUE; host->can_queue = PPA_CAN_QUEUE;
host->sg_tablesize = ppa_sg; host->sg_tablesize = ppa_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;
ppa_hosts[i].host = hreg->host_no; ppa_hosts[i].host = hreg->host_no;
nhosts++; nhosts++;
}
if (nhosts == 0) {
if (try_again == 1) {
printk("WARNING - no ppa compatible devices found.\n");
printk(" As of 31/Aug/1998 Iomega started shipping parallel\n");
printk(" port ZIP drives with a different interface which is\n");
printk(" supported by the imm (ZIP Plus) driver. If the\n");
printk(" cable is marked with \"AutoDetect\", this is what has\n");
printk(" happened.\n");
return 0;
} }
try_again = 1; if (nhosts == 0) {
goto retry_entry; if (try_again == 1) {
} else printk("WARNING - no ppa compatible devices found.\n");
return 1; /* return number of hosts detected */ printk
(" As of 31/Aug/1998 Iomega started shipping parallel\n");
printk
(" port ZIP drives with a different interface which is\n");
printk
(" supported by the imm (ZIP Plus) driver. If the\n");
printk
(" cable is marked with \"AutoDetect\", this is what has\n");
printk(" happened.\n");
return 0;
}
try_again = 1;
goto retry_entry;
} else
return 1; /* return number of hosts detected */
} }
/* This is to give the ppa driver a way to modify the timings (and other /* This is to give the ppa driver a way to modify the timings (and other
...@@ -253,52 +261,56 @@ int ppa_detect(Scsi_Host_Template * host) ...@@ -253,52 +261,56 @@ int ppa_detect(Scsi_Host_Template * host)
static inline int ppa_proc_write(int hostno, char *buffer, int length) static inline int ppa_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);
ppa_hosts[hostno].mode = x; ppa_hosts[hostno].mode = x;
return length; return length;
} }
if ((length > 10) && (strncmp(buffer, "recon_tmo=", 10) == 0)) { if ((length > 10) && (strncmp(buffer, "recon_tmo=", 10) == 0)) {
x = simple_strtoul(buffer + 10, NULL, 0); x = simple_strtoul(buffer + 10, NULL, 0);
ppa_hosts[hostno].recon_tmo = x; ppa_hosts[hostno].recon_tmo = x;
printk("ppa: recon_tmo set to %ld\n", x); printk("ppa: recon_tmo set to %ld\n", x);
return length; return length;
} }
printk("ppa /proc: invalid variable\n"); printk("ppa /proc: invalid variable\n");
return (-EINVAL); return (-EINVAL);
} }
int ppa_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset, static int ppa_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset, int length, int inout)
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 (ppa_hosts[i].host == host->host_no) if (ppa_hosts[i].host == host->host_no)
break; break;
if (inout) if (inout)
return ppa_proc_write(i, buffer, length); return ppa_proc_write(i, buffer, length);
len += sprintf(buffer + len, "Version : %s\n", PPA_VERSION); len += sprintf(buffer + len, "Version : %s\n", PPA_VERSION);
len += sprintf(buffer + len, "Parport : %s\n", ppa_hosts[i].dev->port->name); len +=
len += sprintf(buffer + len, "Mode : %s\n", PPA_MODE_STRING[ppa_hosts[i].mode]); sprintf(buffer + len, "Parport : %s\n",
ppa_hosts[i].dev->port->name);
len +=
sprintf(buffer + len, "Mode : %s\n",
PPA_MODE_STRING[ppa_hosts[i].mode]);
#if PPA_DEBUG > 0 #if PPA_DEBUG > 0
len += sprintf(buffer + len, "recon_tmo : %lu\n", ppa_hosts[i].recon_tmo); len +=
sprintf(buffer + len, "recon_tmo : %lu\n", ppa_hosts[i].recon_tmo);
#endif #endif
/* Request for beyond end of buffer */ /* Request for beyond end of buffer */
if (offset > length) if (offset > length)
return 0; 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;
} }
static int device_check(int host_no); static int device_check(int host_no);
...@@ -311,11 +323,11 @@ static inline void ppa_fail_func(int host_no, int error_code) ...@@ -311,11 +323,11 @@ static inline void ppa_fail_func(int host_no, int error_code)
static inline void ppa_fail(int host_no, int error_code) static inline void ppa_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 (ppa_hosts[host_no].cur_cmd) { if (ppa_hosts[host_no].cur_cmd) {
ppa_hosts[host_no].cur_cmd->result = error_code << 16; ppa_hosts[host_no].cur_cmd->result = error_code << 16;
ppa_hosts[host_no].failed = 1; ppa_hosts[host_no].failed = 1;
} }
} }
/* /*
...@@ -327,31 +339,31 @@ static inline void ppa_fail(int host_no, int error_code) ...@@ -327,31 +339,31 @@ static inline void ppa_fail(int host_no, int error_code)
*/ */
static unsigned char ppa_wait(int host_no) static unsigned char ppa_wait(int host_no)
{ {
int k; int k;
unsigned short ppb = PPA_BASE(host_no); unsigned short ppb = PPA_BASE(host_no);
unsigned char r; unsigned char r;
k = PPA_SPIN_TMO; k = PPA_SPIN_TMO;
/* Wait for bit 6 and 7 - PJC */ /* Wait for bit 6 and 7 - PJC */
for (r = r_str (ppb); ((r & 0xc0)!=0xc0) && (k); k--) { for (r = r_str(ppb); ((r & 0xc0) != 0xc0) && (k); k--) {
udelay (1); udelay(1);
r = r_str (ppb); r = r_str(ppb);
} }
/* /*
* return some status information. * return some status information.
* Semantics: 0xc0 = ZIP wants more data * Semantics: 0xc0 = ZIP wants more data
* 0xd0 = ZIP wants to send more data * 0xd0 = ZIP wants to send more data
* 0xe0 = ZIP is expecting SCSI command data * 0xe0 = ZIP is expecting SCSI command data
* 0xf0 = end of transfer, ZIP is sending status * 0xf0 = end of transfer, ZIP is sending status
*/ */
if (k) if (k)
return (r & 0xf0); return (r & 0xf0);
/* Counter expired - Time out occurred */ /* Counter expired - Time out occurred */
ppa_fail(host_no, DID_TIME_OUT); ppa_fail(host_no, DID_TIME_OUT);
printk("ppa timeout in ppa_wait\n"); printk("ppa timeout in ppa_wait\n");
return 0; /* command timed out */ return 0; /* command timed out */
} }
/* /*
...@@ -359,11 +371,11 @@ static unsigned char ppa_wait(int host_no) ...@@ -359,11 +371,11 @@ static unsigned char ppa_wait(int host_no)
*/ */
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);
} }
/* /*
...@@ -371,233 +383,233 @@ static inline void epp_reset(unsigned short ppb) ...@@ -371,233 +383,233 @@ 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=ppa_hosts[hostno].dev->port->base_hi; int i, ppb_hi = ppa_hosts[hostno].dev->port->base_hi;
if (ppb_hi == 0) return; if (ppb_hi == 0)
return;
if ((r_ecr(ppb_hi) & 0xe0) == 0x60) { /* mode 011 == ECP fifo mode */
for (i = 0; i < 100; i++) { if ((r_ecr(ppb_hi) & 0xe0) == 0x60) { /* mode 011 == ECP fifo mode */
if (r_ecr(ppb_hi) & 0x01) for (i = 0; i < 100; i++) {
return; if (r_ecr(ppb_hi) & 0x01)
udelay(5); return;
} udelay(5);
printk("ppa: ECP sync failed as data still present in FIFO.\n"); }
} printk("ppa: ECP sync failed as data still present in FIFO.\n");
}
} }
static int ppa_byte_out(unsigned short base, const char *buffer, int len) static int ppa_byte_out(unsigned short base, const char *buffer, int len)
{ {
int i; int i;
for (i = len; i; i--) { for (i = len; i; i--) {
w_dtr(base, *buffer++); w_dtr(base, *buffer++);
w_ctr(base, 0xe); w_ctr(base, 0xe);
w_ctr(base, 0xc); w_ctr(base, 0xc);
} }
return 1; /* All went well - we hope! */ return 1; /* All went well - we hope! */
} }
static int ppa_byte_in(unsigned short base, char *buffer, int len) static int ppa_byte_in(unsigned short base, char *buffer, int len)
{ {
int i; int i;
for (i = len; i; i--) { for (i = len; i; i--) {
*buffer++ = r_dtr(base); *buffer++ = r_dtr(base);
w_ctr(base, 0x27); w_ctr(base, 0x27);
w_ctr(base, 0x25); w_ctr(base, 0x25);
} }
return 1; /* All went well - we hope! */ return 1; /* All went well - we hope! */
} }
static int ppa_nibble_in(unsigned short base, char *buffer, int len) static int ppa_nibble_in(unsigned short base, char *buffer, int len)
{ {
for (; len; len--) { for (; len; len--) {
unsigned char h; unsigned char h;
w_ctr(base, 0x4); w_ctr(base, 0x4);
h = r_str(base) & 0xf0; h = r_str(base) & 0xf0;
w_ctr(base, 0x6); w_ctr(base, 0x6);
*buffer++ = h | ((r_str(base) & 0xf0) >> 4); *buffer++ = h | ((r_str(base) & 0xf0) >> 4);
} }
return 1; /* All went well - we hope! */ return 1; /* All went well - we hope! */
} }
static int ppa_out(int host_no, char *buffer, int len) static int ppa_out(int host_no, char *buffer, int len)
{ {
int r; int r;
unsigned short ppb = PPA_BASE(host_no); unsigned short ppb = PPA_BASE(host_no);
r = ppa_wait(host_no); r = ppa_wait(host_no);
if ((r & 0x50) != 0x40) { if ((r & 0x50) != 0x40) {
ppa_fail(host_no, DID_ERROR); ppa_fail(host_no, DID_ERROR);
return 0; return 0;
} }
switch (ppa_hosts[host_no].mode) { switch (ppa_hosts[host_no].mode) {
case PPA_NIBBLE: case PPA_NIBBLE:
case PPA_PS2: case PPA_PS2:
/* 8 bit output, with a loop */ /* 8 bit output, with a loop */
r = ppa_byte_out(ppb, buffer, len); r = ppa_byte_out(ppb, buffer, len);
break; break;
case PPA_EPP_32: case PPA_EPP_32:
case PPA_EPP_16: case PPA_EPP_16:
case PPA_EPP_8: case PPA_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;
default: default:
printk("PPA: bug in ppa_out()\n"); printk("PPA: bug in ppa_out()\n");
r = 0; r = 0;
} }
return r; return r;
} }
static int ppa_in(int host_no, char *buffer, int len) static int ppa_in(int host_no, char *buffer, int len)
{ {
int r; int r;
unsigned short ppb = PPA_BASE(host_no); unsigned short ppb = PPA_BASE(host_no);
r = ppa_wait(host_no); r = ppa_wait(host_no);
if ((r & 0x50) != 0x50) { if ((r & 0x50) != 0x50) {
ppa_fail(host_no, DID_ERROR); ppa_fail(host_no, DID_ERROR);
return 0; return 0;
} }
switch (ppa_hosts[host_no].mode) { switch (ppa_hosts[host_no].mode) {
case PPA_NIBBLE: case PPA_NIBBLE:
/* 4 bit input, with a loop */ /* 4 bit input, with a loop */
r = ppa_nibble_in(ppb, buffer, len); r = ppa_nibble_in(ppb, buffer, len);
w_ctr(ppb, 0xc); w_ctr(ppb, 0xc);
break; break;
case PPA_PS2: case PPA_PS2:
/* 8 bit input, with a loop */ /* 8 bit input, with a loop */
w_ctr(ppb, 0x25); w_ctr(ppb, 0x25);
r = ppa_byte_in(ppb, buffer, len); r = ppa_byte_in(ppb, buffer, len);
w_ctr(ppb, 0x4); w_ctr(ppb, 0x4);
w_ctr(ppb, 0xc); w_ctr(ppb, 0xc);
break; break;
case PPA_EPP_32: case PPA_EPP_32:
case PPA_EPP_16: case PPA_EPP_16:
case PPA_EPP_8: case PPA_EPP_8:
epp_reset(ppb); epp_reset(ppb);
w_ctr(ppb, 0x24); 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("PPA: bug in ppa_ins()\n"); printk("PPA: bug in ppa_ins()\n");
r = 0; r = 0;
break; break;
} }
return r; return r;
} }
/* end of ppa_io.h */ /* end of ppa_io.h */
static inline void ppa_d_pulse(unsigned short ppb, unsigned char b) static inline void ppa_d_pulse(unsigned short ppb, unsigned char b)
{ {
w_dtr(ppb, b); w_dtr(ppb, b);
w_ctr(ppb, 0xc); w_ctr(ppb, 0xc);
w_ctr(ppb, 0xe); w_ctr(ppb, 0xe);
w_ctr(ppb, 0xc); w_ctr(ppb, 0xc);
w_ctr(ppb, 0x4); w_ctr(ppb, 0x4);
w_ctr(ppb, 0xc); w_ctr(ppb, 0xc);
} }
static void ppa_disconnect(int host_no) static void ppa_disconnect(int host_no)
{ {
unsigned short ppb = PPA_BASE(host_no); unsigned short ppb = PPA_BASE(host_no);
ppa_d_pulse(ppb, 0); ppa_d_pulse(ppb, 0);
ppa_d_pulse(ppb, 0x3c); ppa_d_pulse(ppb, 0x3c);
ppa_d_pulse(ppb, 0x20); ppa_d_pulse(ppb, 0x20);
ppa_d_pulse(ppb, 0xf); ppa_d_pulse(ppb, 0xf);
} }
static inline void ppa_c_pulse(unsigned short ppb, unsigned char b) static inline void ppa_c_pulse(unsigned short ppb, unsigned char b)
{ {
w_dtr(ppb, b); w_dtr(ppb, b);
w_ctr(ppb, 0x4); w_ctr(ppb, 0x4);
w_ctr(ppb, 0x6); w_ctr(ppb, 0x6);
w_ctr(ppb, 0x4); w_ctr(ppb, 0x4);
w_ctr(ppb, 0xc); w_ctr(ppb, 0xc);
} }
static inline void ppa_connect(int host_no, int flag) static inline void ppa_connect(int host_no, int flag)
{ {
unsigned short ppb = PPA_BASE(host_no); unsigned short ppb = PPA_BASE(host_no);
ppa_c_pulse(ppb, 0); ppa_c_pulse(ppb, 0);
ppa_c_pulse(ppb, 0x3c); ppa_c_pulse(ppb, 0x3c);
ppa_c_pulse(ppb, 0x20); ppa_c_pulse(ppb, 0x20);
if ((flag == CONNECT_EPP_MAYBE) && if ((flag == CONNECT_EPP_MAYBE) && IN_EPP_MODE(ppa_hosts[host_no].mode))
IN_EPP_MODE(ppa_hosts[host_no].mode)) ppa_c_pulse(ppb, 0xcf);
ppa_c_pulse(ppb, 0xcf); else
else ppa_c_pulse(ppb, 0x8f);
ppa_c_pulse(ppb, 0x8f);
} }
static int ppa_select(int host_no, int target) static int ppa_select(int host_no, int target)
{ {
int k; int k;
unsigned short ppb = PPA_BASE(host_no); unsigned short ppb = PPA_BASE(host_no);
/*
* Bit 6 (0x40) is the device selected bit.
* First we must wait till the current device goes off line...
*/
k = PPA_SELECT_TMO;
do {
k--;
udelay(1);
} while ((r_str(ppb) & 0x40) && (k));
if (!k)
return 0;
w_dtr(ppb, (1 << target)); /*
w_ctr(ppb, 0xe); * Bit 6 (0x40) is the device selected bit.
w_ctr(ppb, 0xc); * First we must wait till the current device goes off line...
w_dtr(ppb, 0x80); /* This is NOT the initator */ */
w_ctr(ppb, 0x8); k = PPA_SELECT_TMO;
do {
k = PPA_SELECT_TMO; k--;
do { udelay(1);
k--; } while ((r_str(ppb) & 0x40) && (k));
udelay(1); if (!k)
} return 0;
while (!(r_str(ppb) & 0x40) && (k));
if (!k) w_dtr(ppb, (1 << target));
return 0; w_ctr(ppb, 0xe);
w_ctr(ppb, 0xc);
w_dtr(ppb, 0x80); /* This is NOT the initator */
w_ctr(ppb, 0x8);
return 1; k = PPA_SELECT_TMO;
do {
k--;
udelay(1);
}
while (!(r_str(ppb) & 0x40) && (k));
if (!k)
return 0;
return 1;
} }
/* /*
...@@ -611,52 +623,52 @@ static int ppa_select(int host_no, int target) ...@@ -611,52 +623,52 @@ static int ppa_select(int host_no, int target)
*/ */
static int ppa_init(int host_no) static int ppa_init(int host_no)
{ {
int retv; int retv;
unsigned short ppb = PPA_BASE(host_no); unsigned short ppb = PPA_BASE(host_no);
#if defined(CONFIG_PARPORT) || defined(CONFIG_PARPORT_MODULE) #if defined(CONFIG_PARPORT) || defined(CONFIG_PARPORT_MODULE)
if (ppa_pb_claim(host_no)) if (ppa_pb_claim(host_no))
while (ppa_hosts[host_no].p_busy) while (ppa_hosts[host_no].p_busy)
schedule(); /* We can safe schedule here */ schedule(); /* We can safe schedule here */
#endif #endif
ppa_disconnect(host_no); ppa_disconnect(host_no);
ppa_connect(host_no, CONNECT_NORMAL); ppa_connect(host_no, CONNECT_NORMAL);
retv = 2; /* Failed */ retv = 2; /* Failed */
w_ctr(ppb, 0xe); w_ctr(ppb, 0xe);
if ((r_str(ppb) & 0x08) == 0x08) if ((r_str(ppb) & 0x08) == 0x08)
retv--; retv--;
w_ctr(ppb, 0xc); w_ctr(ppb, 0xc);
if ((r_str(ppb) & 0x08) == 0x00) if ((r_str(ppb) & 0x08) == 0x00)
retv--; retv--;
if (!retv) if (!retv)
ppa_reset_pulse(ppb); ppa_reset_pulse(ppb);
udelay(1000); /* Allow devices to settle down */ udelay(1000); /* Allow devices to settle down */
ppa_disconnect(host_no); ppa_disconnect(host_no);
udelay(1000); /* Another delay to allow devices to settle */ udelay(1000); /* Another delay to allow devices to settle */
if (!retv) if (!retv)
retv = device_check(host_no); retv = device_check(host_no);
ppa_pb_release(host_no); ppa_pb_release(host_no);
return retv; return retv;
} }
static inline int ppa_send_command(Scsi_Cmnd * cmd) static inline int ppa_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;
w_ctr(PPA_BASE(host_no), 0x0c); w_ctr(PPA_BASE(host_no), 0x0c);
for (k = 0; k < cmd->cmd_len; k++) for (k = 0; k < cmd->cmd_len; k++)
if (!ppa_out(host_no, &cmd->cmnd[k], 1)) if (!ppa_out(host_no, &cmd->cmnd[k], 1))
return 0; return 0;
return 1; return 1;
} }
/* /*
...@@ -669,96 +681,98 @@ static inline int ppa_send_command(Scsi_Cmnd * cmd) ...@@ -669,96 +681,98 @@ static inline int ppa_send_command(Scsi_Cmnd * cmd)
*/ */
static int ppa_completion(Scsi_Cmnd * cmd) static int ppa_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 = PPA_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 ppa_wait.
*/
r = (r_str(ppb) & 0xf0);
while (r != (unsigned char) 0xf0) {
/*
* 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 = PPA_BASE(host_no);
unsigned long start_jiffies = jiffies;
if ((cmd->SCp.this_residual <= 0)) { unsigned char r, v;
ppa_fail(host_no, DID_ERROR); int fast, bulk, status;
return -1; /* ERROR_RETURN */
} v = cmd->cmnd[0];
bulk = ((v == READ_6) ||
(v == READ_10) || (v == WRITE_6) || (v == WRITE_10));
/* On some hardware we have SCSI disconnected (6th bit low) /*
* for about 100usecs. It is too expensive to wait a * We only get here if the drive is ready to comunicate,
* tick on every loop so we busy wait for no more than * hence no need for a full ppa_wait.
* 500usecs to give the drive a chance first. We do not
* change things for "normal" hardware since generally
* the 6th bit is always high.
* This makes the CPU load higher on some hardware
* but otherwise we can not get more than 50K/secs
* on this problem hardware.
*/ */
if ((r & 0xc0) != 0xc0) { r = (r_str(ppb) & 0xf0);
/* Wait for reconnection should be no more than
* jiffy/2 = 5ms = 5000 loops
*/
unsigned long k = ppa_hosts[host_no].recon_tmo;
for (; k && ((r = (r_str(ppb) & 0xf0)) & 0xc0) != 0xc0; k--)
udelay(1);
if(!k)
return 0;
}
/* determine if we should use burst I/O */
fast = (bulk && (cmd->SCp.this_residual >= PPA_BURST_SIZE))
? PPA_BURST_SIZE : 1;
if (r == (unsigned char) 0xc0)
status = ppa_out(host_no, cmd->SCp.ptr, fast);
else
status = ppa_in(host_no, cmd->SCp.ptr, fast);
cmd->SCp.ptr += fast; while (r != (unsigned char) 0xf0) {
cmd->SCp.this_residual -= fast; /*
* If we have been running for more than a full timer tick
* then take a rest.
*/
if (time_after(jiffies, start_jiffies + 1))
return 0;
if ((cmd->SCp.this_residual <= 0)) {
ppa_fail(host_no, DID_ERROR);
return -1; /* ERROR_RETURN */
}
if (!status) { /* On some hardware we have SCSI disconnected (6th bit low)
ppa_fail(host_no, DID_BUS_BUSY); * for about 100usecs. It is too expensive to wait a
return -1; /* ERROR_RETURN */ * tick on every loop so we busy wait for no more than
} * 500usecs to give the drive a chance first. We do not
if (cmd->SCp.buffer && !cmd->SCp.this_residual) { * change things for "normal" hardware since generally
/* if scatter/gather, advance to the next segment */ * the 6th bit is always high.
if (cmd->SCp.buffers_residual--) { * This makes the CPU load higher on some hardware
cmd->SCp.buffer++; * but otherwise we can not get more than 50K/secs
cmd->SCp.this_residual = cmd->SCp.buffer->length; * on this problem hardware.
cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) + cmd->SCp.buffer->offset; */
} if ((r & 0xc0) != 0xc0) {
/* Wait for reconnection should be no more than
* jiffy/2 = 5ms = 5000 loops
*/
unsigned long k = ppa_hosts[host_no].recon_tmo;
for (; k && ((r = (r_str(ppb) & 0xf0)) & 0xc0) != 0xc0;
k--)
udelay(1);
if (!k)
return 0;
}
/* determine if we should use burst I/O */
fast = (bulk && (cmd->SCp.this_residual >= PPA_BURST_SIZE))
? PPA_BURST_SIZE : 1;
if (r == (unsigned char) 0xc0)
status = ppa_out(host_no, cmd->SCp.ptr, fast);
else
status = ppa_in(host_no, cmd->SCp.ptr, fast);
cmd->SCp.ptr += fast;
cmd->SCp.this_residual -= fast;
if (!status) {
ppa_fail(host_no, DID_BUS_BUSY);
return -1; /* ERROR_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;
}
}
/* Now check to see if the drive is ready to comunicate */
r = (r_str(ppb) & 0xf0);
/* If not, drop back down to the scheduler and wait a timer tick */
if (!(r & 0x80))
return 0;
} }
/* Now check to see if the drive is ready to comunicate */ return 1; /* FINISH_RETURN */
r = (r_str(ppb) & 0xf0);
/* If not, drop back down to the scheduler and wait a timer tick */
if (!(r & 0x80))
return 0;
}
return 1; /* FINISH_RETURN */
} }
/* /*
...@@ -768,203 +782,209 @@ static int ppa_completion(Scsi_Cmnd * cmd) ...@@ -768,203 +782,209 @@ static int ppa_completion(Scsi_Cmnd * cmd)
*/ */
static void ppa_interrupt(void *data) static void ppa_interrupt(void *data)
{ {
ppa_struct *tmp = (ppa_struct *) data; ppa_struct *tmp = (ppa_struct *) data;
Scsi_Cmnd *cmd = tmp->cur_cmd; Scsi_Cmnd *cmd = tmp->cur_cmd;
unsigned long flags; unsigned long flags;
if (!cmd) { if (!cmd) {
printk("PPA: bug in ppa_interrupt\n"); printk("PPA: bug in ppa_interrupt\n");
return; return;
} }
if (ppa_engine(tmp, cmd)) { if (ppa_engine(tmp, cmd)) {
tmp->ppa_tq.data = (void *) tmp; tmp->ppa_tq.data = (void *) tmp;
schedule_delayed_work(&tmp->ppa_tq, 1); schedule_delayed_work(&tmp->ppa_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 PPA_DEBUG > 0 #if PPA_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("ppa: no device at SCSI ID %i\n", cmd->device->target); printk("ppa: no device at SCSI ID %i\n", cmd->device->target);
break; break;
case DID_BUS_BUSY: case DID_BUS_BUSY:
printk("ppa: BUS BUSY - EPP timeout detected\n"); printk("ppa: BUS BUSY - EPP timeout detected\n");
break; break;
case DID_TIME_OUT: case DID_TIME_OUT:
printk("ppa: unknown timeout\n"); printk("ppa: unknown timeout\n");
break; break;
case DID_ABORT: case DID_ABORT:
printk("ppa: told to abort\n"); printk("ppa: told to abort\n");
break; break;
case DID_PARITY: case DID_PARITY:
printk("ppa: parity error (???)\n"); printk("ppa: parity error (???)\n");
break; break;
case DID_ERROR: case DID_ERROR:
printk("ppa: internal driver error\n"); printk("ppa: internal driver error\n");
break; break;
case DID_RESET: case DID_RESET:
printk("ppa: told to reset device\n"); printk("ppa: told to reset device\n");
break; break;
case DID_BAD_INTR: case DID_BAD_INTR:
printk("ppa: bad interrupt (???)\n"); printk("ppa: bad interrupt (???)\n");
break; break;
default: default:
printk("ppa: bad return code (%02x)\n", (cmd->result >> 16) & 0xff); printk("ppa: bad return code (%02x)\n",
} (cmd->result >> 16) & 0xff);
}
#endif #endif
if (cmd->SCp.phase > 1) if (cmd->SCp.phase > 1)
ppa_disconnect(cmd->device->host->unique_id); ppa_disconnect(cmd->device->host->unique_id);
if (cmd->SCp.phase > 0) if (cmd->SCp.phase > 0)
ppa_pb_release(cmd->device->host->unique_id); ppa_pb_release(cmd->device->host->unique_id);
tmp->cur_cmd = 0; tmp->cur_cmd = 0;
spin_lock_irqsave(cmd->device->host->host_lock, flags); spin_lock_irqsave(cmd->device->host->host_lock, flags);
cmd->scsi_done(cmd); cmd->scsi_done(cmd);
spin_unlock_irqrestore(cmd->device->host->host_lock, flags); spin_unlock_irqrestore(cmd->device->host->host_lock, flags);
return; return;
} }
static int ppa_engine(ppa_struct * tmp, Scsi_Cmnd * cmd) static int ppa_engine(ppa_struct * tmp, Scsi_Cmnd * cmd)
{ {
int host_no = cmd->device->host->unique_id; int host_no = cmd->device->host->unique_id;
unsigned short ppb = PPA_BASE(host_no); unsigned short ppb = PPA_BASE(host_no);
unsigned char l = 0, h = 0; unsigned char l = 0, h = 0;
int retv; int retv;
/* First check for any errors that may of occurred
* Here we check for internal errors
*/
if (tmp->failed)
return 0;
switch (cmd->SCp.phase) {
case 0: /* Phase 0 - Waiting for parport */
if ((jiffies - tmp->jstart) > HZ) {
/*
* We waited more than a second
* for parport to call us
*/
ppa_fail(host_no, DID_BUS_BUSY);
return 0;
}
return 1; /* wait until ppa_wakeup claims parport */
case 1: /* Phase 1 - Connected */
{ /* Perform a sanity check for cable unplugged */
int retv = 2; /* Failed */
ppa_connect(host_no, CONNECT_EPP_MAYBE); /* First check for any errors that may of occurred
* Here we check for internal errors
w_ctr(ppb, 0xe); */
if ((r_str(ppb) & 0x08) == 0x08) if (tmp->failed)
retv--; return 0;
w_ctr(ppb, 0xc); switch (cmd->SCp.phase) {
if ((r_str(ppb) & 0x08) == 0x00) case 0: /* Phase 0 - Waiting for parport */
retv--; if ((jiffies - tmp->jstart) > HZ) {
/*
* We waited more than a second
* for parport to call us
*/
ppa_fail(host_no, DID_BUS_BUSY);
return 0;
}
return 1; /* wait until ppa_wakeup claims parport */
case 1: /* Phase 1 - Connected */
{ /* Perform a sanity check for cable unplugged */
int retv = 2; /* Failed */
ppa_connect(host_no, CONNECT_EPP_MAYBE);
w_ctr(ppb, 0xe);
if ((r_str(ppb) & 0x08) == 0x08)
retv--;
w_ctr(ppb, 0xc);
if ((r_str(ppb) & 0x08) == 0x00)
retv--;
if (retv) {
if ((jiffies - tmp->jstart) > (1 * HZ)) {
printk
("ppa: Parallel port cable is unplugged!!\n");
ppa_fail(host_no, DID_BUS_BUSY);
return 0;
} else {
ppa_disconnect(host_no);
return 1; /* Try again in a jiffy */
}
}
cmd->SCp.phase++;
}
if (retv) { case 2: /* Phase 2 - We are now talking to the scsi bus */
if ((jiffies - tmp->jstart) > (1 * HZ)) { if (!ppa_select(host_no, cmd->device->id)) {
printk("ppa: Parallel port cable is unplugged!!\n"); ppa_fail(host_no, DID_NO_CONNECT);
ppa_fail(host_no, DID_BUS_BUSY); return 0;
return 0; }
cmd->SCp.phase++;
case 3: /* Phase 3 - Ready to accept a command */
w_ctr(ppb, 0x0c);
if (!(r_str(ppb) & 0x80))
return 1;
if (!ppa_send_command(cmd))
return 0;
cmd->SCp.phase++;
case 4: /* Phase 4 - Setup scatter/gather buffers */
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 {
ppa_disconnect(host_no); /* else fill the only available buffer */
return 1; /* Try again in a jiffy */ 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++; cmd->SCp.phase++;
}
case 5: /* Phase 5 - Data transfer stage */
w_ctr(ppb, 0x0c);
if (!(r_str(ppb) & 0x80))
return 1;
retv = ppa_completion(cmd);
if (retv == -1)
return 0;
if (retv == 0)
return 1;
cmd->SCp.phase++;
case 6: /* Phase 6 - Read status/message */
cmd->result = DID_OK << 16;
/* Check for data overrun */
if (ppa_wait(host_no) != (unsigned char) 0xf0) {
ppa_fail(host_no, DID_ERROR);
return 0;
}
if (ppa_in(host_no, &l, 1)) { /* read status byte */
/* Check for optional message byte */
if (ppa_wait(host_no) == (unsigned char) 0xf0)
ppa_in(host_no, &h, 1);
cmd->result =
(DID_OK << 16) + (h << 8) + (l & STATUS_MASK);
}
return 0; /* Finished */
break;
case 2: /* Phase 2 - We are now talking to the scsi bus */ default:
if (!ppa_select(host_no, cmd->device->id)) { printk("ppa: Invalid scsi phase\n");
ppa_fail(host_no, DID_NO_CONNECT);
return 0;
} }
cmd->SCp.phase++; return 0;
case 3: /* Phase 3 - Ready to accept a command */
w_ctr(ppb, 0x0c);
if (!(r_str(ppb) & 0x80))
return 1;
if (!ppa_send_command(cmd))
return 0;
cmd->SCp.phase++;
case 4: /* Phase 4 - Setup scatter/gather buffers */
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++;
case 5: /* Phase 5 - Data transfer stage */
w_ctr(ppb, 0x0c);
if (!(r_str(ppb) & 0x80))
return 1;
retv = ppa_completion(cmd);
if (retv == -1)
return 0;
if (retv == 0)
return 1;
cmd->SCp.phase++;
case 6: /* Phase 6 - Read status/message */
cmd->result = DID_OK << 16;
/* Check for data overrun */
if (ppa_wait(host_no) != (unsigned char) 0xf0) {
ppa_fail(host_no, DID_ERROR);
return 0;
}
if (ppa_in(host_no, &l, 1)) { /* read status byte */
/* Check for optional message byte */
if (ppa_wait(host_no) == (unsigned char) 0xf0)
ppa_in(host_no, &h, 1);
cmd->result = (DID_OK << 16) + (h << 8) + (l & STATUS_MASK);
}
return 0; /* Finished */
break;
default:
printk("ppa: Invalid scsi phase\n");
}
return 0;
} }
int ppa_queuecommand(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *)) static int ppa_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 (ppa_hosts[host_no].cur_cmd) { if (ppa_hosts[host_no].cur_cmd) {
printk("PPA: bug in ppa_queuecommand\n"); printk("PPA: bug in ppa_queuecommand\n");
return 0; return 0;
} }
ppa_hosts[host_no].failed = 0; ppa_hosts[host_no].failed = 0;
ppa_hosts[host_no].jstart = jiffies; ppa_hosts[host_no].jstart = jiffies;
ppa_hosts[host_no].cur_cmd = cmd; ppa_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 */
ppa_pb_claim(host_no); ppa_pb_claim(host_no);
ppa_hosts[host_no].ppa_tq.data = ppa_hosts + host_no; ppa_hosts[host_no].ppa_tq.data = ppa_hosts + host_no;
schedule_work(&ppa_hosts[host_no].ppa_tq); schedule_work(&ppa_hosts[host_no].ppa_tq);
return 0; return 0;
} }
/* /*
...@@ -973,150 +993,152 @@ int ppa_queuecommand(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *)) ...@@ -973,150 +993,152 @@ int ppa_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 ppa_biosparam(struct scsi_device *sdev, struct block_device *dev, static int ppa_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]);
if (ip[2] > 1023) if (ip[2] > 1023)
ip[2] = 1023; ip[2] = 1023;
} }
return 0; return 0;
} }
int ppa_abort(Scsi_Cmnd * cmd) static int ppa_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 */
ppa_hosts[host_no].cur_cmd = NULL; /* Forget the problem */ ppa_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;
} }
} }
static void ppa_reset_pulse(unsigned int base) static void ppa_reset_pulse(unsigned int base)
{ {
w_dtr(base, 0x40); w_dtr(base, 0x40);
w_ctr(base, 0x8); w_ctr(base, 0x8);
udelay(30); udelay(30);
w_ctr(base, 0xc); w_ctr(base, 0xc);
} }
int ppa_reset(Scsi_Cmnd * cmd) static int ppa_reset(Scsi_Cmnd * cmd)
{ {
int host_no = cmd->device->host->unique_id; int host_no = cmd->device->host->unique_id;
if (cmd->SCp.phase)
ppa_disconnect(host_no);
ppa_hosts[host_no].cur_cmd = NULL; /* Forget the problem */
if (cmd->SCp.phase) ppa_connect(host_no, CONNECT_NORMAL);
ppa_reset_pulse(PPA_BASE(host_no));
udelay(1000); /* device settle delay */
ppa_disconnect(host_no); ppa_disconnect(host_no);
ppa_hosts[host_no].cur_cmd = NULL; /* Forget the problem */ udelay(1000); /* device settle delay */
return SUCCESS;
ppa_connect(host_no, CONNECT_NORMAL);
ppa_reset_pulse(PPA_BASE(host_no));
udelay(1000); /* device settle delay */
ppa_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 = PPA_BASE(host_no);
int loop, old_mode, status, k, ppb = PPA_BASE(host_no); unsigned char l;
unsigned char l;
old_mode = ppa_hosts[host_no].mode;
old_mode = ppa_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) ppa_hosts[host_no].mode = PPA_EPP_32;
ppa_hosts[host_no].mode = PPA_EPP_32;
second_pass:
second_pass: ppa_connect(host_no, CONNECT_EPP_MAYBE);
ppa_connect(host_no, CONNECT_EPP_MAYBE); /* Select SCSI device */
/* Select SCSI device */ if (!ppa_select(host_no, loop)) {
if (!ppa_select(host_no, loop)) { ppa_disconnect(host_no);
ppa_disconnect(host_no); continue;
continue; }
} printk("ppa: Found device at ID %i, Attempting to use %s\n",
printk("ppa: Found device at ID %i, Attempting to use %s\n", loop, loop, PPA_MODE_STRING[ppa_hosts[host_no].mode]);
PPA_MODE_STRING[ppa_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 < 6) && (status); l++)
for (l = 0; (l < 6) && (status); l++) status = ppa_out(host_no, cmd, 1);
status = ppa_out(host_no, cmd, 1);
if (!status) {
if (!status) { ppa_disconnect(host_no);
ppa_disconnect(host_no); ppa_connect(host_no, CONNECT_EPP_MAYBE);
ppa_connect(host_no, CONNECT_EPP_MAYBE); w_dtr(ppb, 0x40);
w_dtr(ppb, 0x40); w_ctr(ppb, 0x08);
w_ctr(ppb, 0x08); udelay(30);
udelay(30); w_ctr(ppb, 0x0c);
w_ctr(ppb, 0x0c); udelay(1000);
udelay(1000); ppa_disconnect(host_no);
ppa_disconnect(host_no); udelay(1000);
udelay(1000); if (ppa_hosts[host_no].mode == PPA_EPP_32) {
if (ppa_hosts[host_no].mode == PPA_EPP_32) { ppa_hosts[host_no].mode = old_mode;
ppa_hosts[host_no].mode = old_mode; goto second_pass;
goto second_pass; }
} printk
printk("ppa: Unable to establish communication, aborting driver load.\n"); ("ppa: 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 &= 0xf0; l &= 0xf0;
if (l != 0xf0) { if (l != 0xf0) {
ppa_disconnect(host_no); ppa_disconnect(host_no);
ppa_connect(host_no, CONNECT_EPP_MAYBE); ppa_connect(host_no, CONNECT_EPP_MAYBE);
ppa_reset_pulse(ppb); ppa_reset_pulse(ppb);
udelay(1000); udelay(1000);
ppa_disconnect(host_no); ppa_disconnect(host_no);
udelay(1000); udelay(1000);
if (ppa_hosts[host_no].mode == PPA_EPP_32) { if (ppa_hosts[host_no].mode == PPA_EPP_32) {
ppa_hosts[host_no].mode = old_mode; ppa_hosts[host_no].mode = old_mode;
goto second_pass; goto second_pass;
} }
printk("ppa: Unable to establish communication, aborting driver load.\n"); printk
return 1; ("ppa: Unable to establish communication, aborting driver load.\n");
return 1;
}
ppa_disconnect(host_no);
printk("ppa: Communication established with ID %i using %s\n",
loop, PPA_MODE_STRING[ppa_hosts[host_no].mode]);
ppa_connect(host_no, CONNECT_EPP_MAYBE);
ppa_reset_pulse(ppb);
udelay(1000);
ppa_disconnect(host_no);
udelay(1000);
return 0;
} }
ppa_disconnect(host_no); printk("ppa: No devices found, aborting driver load.\n");
printk("ppa: Communication established with ID %i using %s\n", loop, return 1;
PPA_MODE_STRING[ppa_hosts[host_no].mode]);
ppa_connect(host_no, CONNECT_EPP_MAYBE);
ppa_reset_pulse(ppb);
udelay(1000);
ppa_disconnect(host_no);
udelay(1000);
return 0;
}
printk("ppa: No devices found, aborting driver load.\n");
return 1;
} }
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
...@@ -161,14 +161,14 @@ static int ppa_out(int, char *, int); ...@@ -161,14 +161,14 @@ static int ppa_out(int, char *, int);
#define ppa_release 0 #define ppa_release 0
#endif #endif
int ppa_detect(Scsi_Host_Template *); static int ppa_detect(Scsi_Host_Template *);
const char *ppa_info(struct Scsi_Host *); const char *ppa_info(struct Scsi_Host *);
int ppa_command(Scsi_Cmnd *); int ppa_command(Scsi_Cmnd *);
int ppa_queuecommand(Scsi_Cmnd *, void (*done) (Scsi_Cmnd *)); static int ppa_queuecommand(Scsi_Cmnd *, void (*done) (Scsi_Cmnd *));
int ppa_abort(Scsi_Cmnd *); static int ppa_abort(Scsi_Cmnd *);
int ppa_reset(Scsi_Cmnd *); static int ppa_reset(Scsi_Cmnd *);
int ppa_proc_info(struct Scsi_Host *host, char *, char **, off_t, int, int); static int ppa_proc_info(struct Scsi_Host *host, char *, char **, off_t, int, int);
int ppa_biosparam(struct scsi_device *, struct block_device *, static int ppa_biosparam(struct scsi_device *, struct block_device *,
sector_t, int *); sector_t, int *);
#endif /* _PPA_H */ #endif /* _PPA_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