Commit cc0f78fc authored by Russell King's avatar Russell King

[ARM] Update Acorn SCSI drivers

- Add scsi devclass support.
- Convert to use ioremap and friends.
- Fix oops which can occur when driver claims interrupt, and there's
  an interrupt pending - move to a two-level fas driver initialisation.
parent 299c2e86
...@@ -3110,7 +3110,8 @@ static struct ecard_driver acornscsi_driver = { ...@@ -3110,7 +3110,8 @@ static struct ecard_driver acornscsi_driver = {
.remove = __devexit_p(acornscsi_remove), .remove = __devexit_p(acornscsi_remove),
.id_table = acornscsi_cids, .id_table = acornscsi_cids,
.drv = { .drv = {
.name = "acornscsi", .devclass = &shost_devclass,
.name = "acornscsi",
}, },
}; };
......
...@@ -40,33 +40,18 @@ ...@@ -40,33 +40,18 @@
#include "fas216.h" #include "fas216.h"
struct arxescsi_info { struct arxescsi_info {
FAS216_Info info; FAS216_Info info;
struct expansion_card *ec;
/* other info... */
unsigned int cstatus; /* card status register */
unsigned int dmaarea; /* Pseudo DMA area */
}; };
#define CSTATUS_IRQ (1 << 0) #define DMADATA_OFFSET (0x200)
#define CSTATUS_DRQ (1 << 0)
#ifndef CAN_QUEUE
#define CAN_QUEUE 1
#endif
#ifndef CMD_PER_LUN #define DMASTAT_OFFSET (0x600)
#define CMD_PER_LUN 1 #define DMASTAT_DRQ (1 << 0)
#endif
/* Hmm - this should go somewhere else */ #define CSTATUS_IRQ (1 << 0)
#define BUS_ADDR(x) ((((unsigned long)(x)) << 2) + IO_BASE)
/* #define VERSION "1.10 (23/01/2003 2.5.57)"
* Version
*/
#define VER_MAJOR 0
#define VER_MINOR 1
#define VER_PATCH 1
/* /*
* Function: int arxescsi_dma_setup(host, SCpnt, direction, min_type) * Function: int arxescsi_dma_setup(host, SCpnt, direction, min_type)
...@@ -87,44 +72,7 @@ arxescsi_dma_setup(struct Scsi_Host *host, Scsi_Pointer *SCp, ...@@ -87,44 +72,7 @@ arxescsi_dma_setup(struct Scsi_Host *host, Scsi_Pointer *SCp,
return fasdma_pseudo; return fasdma_pseudo;
} }
static void arxescsi_pseudo_dma_write(unsigned char *addr, unsigned char *base)
/* Faster transfer routines, written by SH to speed up the loops */
static inline unsigned char getb(unsigned int address, unsigned int reg)
{
unsigned char value;
__asm__ __volatile__(
"ldrb %0, [%1, %2, lsl #5]"
: "=r" (value)
: "r" (address), "r" (reg) );
return value;
}
static inline unsigned int getw(unsigned int address, unsigned int reg)
{
unsigned int value;
__asm__ __volatile__(
"ldr %0, [%1, %2, lsl #5]\n\t"
"mov %0, %0, lsl #16\n\t"
"mov %0, %0, lsr #16"
: "=r" (value)
: "r" (address), "r" (reg) );
return value;
}
static inline void putw(unsigned int address, unsigned int reg, unsigned long value)
{
__asm__ __volatile__(
"mov %0, %0, lsl #16\n\t"
"str %0, [%1, %2, lsl #5]"
:
: "r" (value), "r" (address), "r" (reg) );
}
void arxescsi_pseudo_dma_write(unsigned char *addr, unsigned int io)
{ {
__asm__ __volatile__( __asm__ __volatile__(
" stmdb sp!, {r0-r12}\n" " stmdb sp!, {r0-r12}\n"
...@@ -149,7 +97,7 @@ void arxescsi_pseudo_dma_write(unsigned char *addr, unsigned int io) ...@@ -149,7 +97,7 @@ void arxescsi_pseudo_dma_write(unsigned char *addr, unsigned int io)
" bne .loop_1\n" " bne .loop_1\n"
" ldmia sp!, {r0-r12}\n" " ldmia sp!, {r0-r12}\n"
: :
: "r" (addr), "r" (io) ); : "r" (addr), "r" (base));
} }
/* /*
...@@ -160,40 +108,41 @@ void arxescsi_pseudo_dma_write(unsigned char *addr, unsigned int io) ...@@ -160,40 +108,41 @@ void arxescsi_pseudo_dma_write(unsigned char *addr, unsigned int io)
* direction - DMA on to/off of card * direction - DMA on to/off of card
* transfer - minimum number of bytes we expect to transfer * transfer - minimum number of bytes we expect to transfer
*/ */
void arxescsi_dma_pseudo(struct Scsi_Host *host, Scsi_Pointer *SCp, static void
fasdmadir_t direction, int transfer) arxescsi_dma_pseudo(struct Scsi_Host *host, Scsi_Pointer *SCp,
fasdmadir_t direction, int transfer)
{ {
struct arxescsi_info *info = (struct arxescsi_info *)host->hostdata; struct arxescsi_info *info = (struct arxescsi_info *)host->hostdata;
unsigned int length, io, error=0; unsigned int length, error = 0;
unsigned char *base = info->info.scsi.io_base;
unsigned char *addr; unsigned char *addr;
length = SCp->this_residual; length = SCp->this_residual;
addr = SCp->ptr; addr = SCp->ptr;
io = __ioaddr(host->io_port);
if (direction == DMA_OUT) { if (direction == DMA_OUT) {
unsigned int word; unsigned int word;
while (length > 256) { while (length > 256) {
if (getb(io, 4) & STAT_INT) { if (readb(base + 0x80) & STAT_INT) {
error=1; error = 1;
break; break;
} }
arxescsi_pseudo_dma_write(addr, io); arxescsi_pseudo_dma_write(addr, base);
addr += 256; addr += 256;
length -= 256; length -= 256;
} }
if (!error) if (!error)
while (length > 0) { while (length > 0) {
if (getb(io, 4) & STAT_INT) if (readb(base + 0x80) & STAT_INT)
break; break;
if (!(getb(io, 48) & CSTATUS_IRQ)) if (!(readb(base + DMASTAT_OFFSET) & DMASTAT_DRQ))
continue; continue;
word = *addr | *(addr + 1) << 8; word = *addr | *(addr + 1) << 8;
putw(io, 16, word); writew(word, base + DMADATA_OFFSET);
if (length > 1) { if (length > 1) {
addr += 2; addr += 2;
length -= 2; length -= 2;
...@@ -206,15 +155,15 @@ void arxescsi_dma_pseudo(struct Scsi_Host *host, Scsi_Pointer *SCp, ...@@ -206,15 +155,15 @@ void arxescsi_dma_pseudo(struct Scsi_Host *host, Scsi_Pointer *SCp,
else { else {
if (transfer && (transfer & 255)) { if (transfer && (transfer & 255)) {
while (length >= 256) { while (length >= 256) {
if (getb(io, 4) & STAT_INT) { if (readb(base + 0x80) & STAT_INT) {
error=1; error = 1;
break; break;
} }
if (!(getb(io, 48) & CSTATUS_IRQ)) if (!(readb(base + DMASTAT_OFFSET) & DMASTAT_DRQ))
continue; continue;
insw(info->dmaarea, addr, 256 >> 1); readsw(base + DMADATA_OFFSET, addr, 256 >> 1);
addr += 256; addr += 256;
length -= 256; length -= 256;
} }
...@@ -224,13 +173,13 @@ void arxescsi_dma_pseudo(struct Scsi_Host *host, Scsi_Pointer *SCp, ...@@ -224,13 +173,13 @@ void arxescsi_dma_pseudo(struct Scsi_Host *host, Scsi_Pointer *SCp,
while (length > 0) { while (length > 0) {
unsigned long word; unsigned long word;
if (getb(io, 4) & STAT_INT) if (readb(base + 0x80) & STAT_INT)
break; break;
if (!(getb(io, 48) & CSTATUS_IRQ)) if (!(readb(base + DMASTAT_OFFSET) & DMASTAT_DRQ))
continue; continue;
word = getw(io, 16); word = readw(base + DMADATA_OFFSET);
*addr++ = word; *addr++ = word;
if (--length > 0) { if (--length > 0) {
*addr++ = word >> 8; *addr++ = word >> 8;
...@@ -259,15 +208,14 @@ static void arxescsi_dma_stop(struct Scsi_Host *host, Scsi_Pointer *SCp) ...@@ -259,15 +208,14 @@ static void arxescsi_dma_stop(struct Scsi_Host *host, Scsi_Pointer *SCp)
* Params : host - driver host structure to return info for. * Params : host - driver host structure to return info for.
* Returns : pointer to a static buffer containing null terminated string. * Returns : pointer to a static buffer containing null terminated string.
*/ */
const char *arxescsi_info(struct Scsi_Host *host) static const char *arxescsi_info(struct Scsi_Host *host)
{ {
struct arxescsi_info *info = (struct arxescsi_info *)host->hostdata; struct arxescsi_info *info = (struct arxescsi_info *)host->hostdata;
static char string[150], *p; static char string[150];
p = string; sprintf(string, "%s (%s) in slot %d v%s",
p += sprintf(p, "%s ", host->hostt->name); host->hostt->name, info->info.scsi.type, info->ec->slot_no,
p += fas216_info(&info->info, p); VERSION);
p += sprintf(p, "v%d.%d.%d", VER_MAJOR, VER_MINOR, VER_PATCH);
return string; return string;
} }
...@@ -286,8 +234,9 @@ const char *arxescsi_info(struct Scsi_Host *host) ...@@ -286,8 +234,9 @@ const char *arxescsi_info(struct Scsi_Host *host)
* inout - 0 for reading, 1 for writing. * inout - 0 for reading, 1 for writing.
* Returns : length of data written to buffer. * Returns : length of data written to buffer.
*/ */
int arxescsi_proc_info(char *buffer, char **start, off_t offset, static int
int length, int host_no, int inout) arxescsi_proc_info(char *buffer, char **start, off_t offset, int length,
int host_no, int inout)
{ {
int pos, begin; int pos, begin;
struct Scsi_Host *host; struct Scsi_Host *host;
...@@ -303,9 +252,7 @@ int arxescsi_proc_info(char *buffer, char **start, off_t offset, ...@@ -303,9 +252,7 @@ int arxescsi_proc_info(char *buffer, char **start, off_t offset,
return -EINVAL; return -EINVAL;
begin = 0; begin = 0;
pos = sprintf(buffer, pos = sprintf(buffer, "ARXE 16-bit SCSI driver v%s\n", VERSION);
"ARXE 16-bit SCSI driver version %d.%d.%d\n",
VER_MAJOR, VER_MINOR, VER_PATCH);
pos += fas216_print_host(&info->info, buffer + pos); pos += fas216_print_host(&info->info, buffer + pos);
pos += fas216_print_stats(&info->info, buffer + pos); pos += fas216_print_stats(&info->info, buffer + pos);
...@@ -343,7 +290,7 @@ static Scsi_Host_Template arxescsi_template = { ...@@ -343,7 +290,7 @@ static Scsi_Host_Template arxescsi_template = {
.can_queue = 0, .can_queue = 0,
.this_id = 7, .this_id = 7,
.sg_tablesize = SG_ALL, .sg_tablesize = SG_ALL,
.cmd_per_lun = CMD_PER_LUN, .cmd_per_lun = 1,
.use_clustering = DISABLE_CLUSTERING, .use_clustering = DISABLE_CLUSTERING,
.proc_name = "arxescsi", .proc_name = "arxescsi",
}; };
...@@ -352,21 +299,41 @@ static int __devinit ...@@ -352,21 +299,41 @@ static int __devinit
arxescsi_probe(struct expansion_card *ec, const struct ecard_id *id) arxescsi_probe(struct expansion_card *ec, const struct ecard_id *id)
{ {
struct Scsi_Host *host; struct Scsi_Host *host;
struct arxescsi_info *info; struct arxescsi_info *info;
int ret = -ENOMEM; unsigned long resbase, reslen;
unsigned char *base;
int ret;
host = scsi_register(&arxescsi_template, sizeof(struct arxescsi_info)); resbase = ecard_resource_start(ec, ECARD_RES_MEMC);
if (!host) reslen = ecard_resource_len(ec, ECARD_RES_MEMC);
if (!request_mem_region(resbase, reslen, "arxescsi")) {
ret = -EBUSY;
goto out; goto out;
}
host->io_port = ecard_address(ec, ECARD_MEMC, 0) + 0x0800; base = ioremap(resbase, reslen);
if (!base) {
ret = -ENOMEM;
goto out_region;
}
host = scsi_register(&arxescsi_template, sizeof(struct arxescsi_info));
if (!host) {
ret = -ENOMEM;
goto out_unmap;
}
host->base = (unsigned long)base;
host->irq = NO_IRQ; host->irq = NO_IRQ;
host->dma_channel = NO_DMA; host->dma_channel = NO_DMA;
info = (struct arxescsi_info *)host->hostdata; info = (struct arxescsi_info *)host->hostdata;
info->info.scsi.io_port = host->io_port; info->ec = ec;
info->info.scsi.io_base = base + 0x2000;
info->info.scsi.irq = host->irq; info->info.scsi.irq = host->irq;
info->info.scsi.io_shift = 3; info->info.scsi.io_shift = 5;
info->info.ifcfg.clockrate = 24; /* MHz */ info->info.ifcfg.clockrate = 24; /* MHz */
info->info.ifcfg.select_timeout = 255; info->info.ifcfg.select_timeout = 255;
info->info.ifcfg.asyncperiod = 200; /* ns */ info->info.ifcfg.asyncperiod = 200; /* ns */
...@@ -374,39 +341,29 @@ arxescsi_probe(struct expansion_card *ec, const struct ecard_id *id) ...@@ -374,39 +341,29 @@ arxescsi_probe(struct expansion_card *ec, const struct ecard_id *id)
info->info.ifcfg.cntl3 = CNTL3_FASTSCSI | CNTL3_FASTCLK; info->info.ifcfg.cntl3 = CNTL3_FASTSCSI | CNTL3_FASTCLK;
info->info.ifcfg.disconnect_ok = 0; info->info.ifcfg.disconnect_ok = 0;
info->info.ifcfg.wide_max_size = 0; info->info.ifcfg.wide_max_size = 0;
info->info.ifcfg.capabilities = FASCAP_PSEUDODMA;
info->info.dma.setup = arxescsi_dma_setup; info->info.dma.setup = arxescsi_dma_setup;
info->info.dma.pseudo = arxescsi_dma_pseudo; info->info.dma.pseudo = arxescsi_dma_pseudo;
info->info.dma.stop = arxescsi_dma_stop; info->info.dma.stop = arxescsi_dma_stop;
info->dmaarea = host->io_port + 128;
info->cstatus = host->io_port + 384;
ec->irqaddr = (unsigned char *)BUS_ADDR(host->io_port); ec->irqaddr = base;
ec->irqmask = CSTATUS_IRQ; ec->irqmask = CSTATUS_IRQ;
if (!request_region(host->io_port, 120, "arxescsi-fas")) { ret = fas216_init(host);
ret = -EBUSY; if (ret)
goto out_free; goto out_unregister;
}
if (!request_region(host->io_port + 128, 384, "arxescsi-dma")) {
ret = -EBUSY;
goto out_release;
}
printk("scsi%d: Has no interrupts - using polling mode\n",
host->host_no);
fas216_init(host); ret = fas216_add(host, &ec->dev);
ret = scsi_add_host(host, &ec->dev);
if (ret == 0) if (ret == 0)
goto out; goto out;
release_region(host->io_port + 128, 384); fas216_release(host);
out_release: out_unregister:
release_region(host->io_port, 120);
out_free:
scsi_unregister(host); scsi_unregister(host);
out_unmap:
iounmap(base);
out_region:
release_mem_region(resbase, reslen);
out: out:
return ret; return ret;
} }
...@@ -414,13 +371,19 @@ arxescsi_probe(struct expansion_card *ec, const struct ecard_id *id) ...@@ -414,13 +371,19 @@ arxescsi_probe(struct expansion_card *ec, const struct ecard_id *id)
static void __devexit arxescsi_remove(struct expansion_card *ec) static void __devexit arxescsi_remove(struct expansion_card *ec)
{ {
struct Scsi_Host *host = ecard_get_drvdata(ec); struct Scsi_Host *host = ecard_get_drvdata(ec);
unsigned long resbase, reslen;
ecard_set_drvdata(ec, NULL); ecard_set_drvdata(ec, NULL);
scsi_remove_host(host); fas216_remove(host);
fas216_release(host);
iounmap((void *)host->base);
resbase = ecard_resource_start(ec, ECARD_RES_MEMC);
reslen = ecard_resource_len(ec, ECARD_RES_MEMC);
release_region(host->io_port + 128, 384); release_mem_region(resbase, reslen);
release_region(host->io_port, 120);
fas216_release(host);
scsi_unregister(host); scsi_unregister(host);
} }
...@@ -434,7 +397,8 @@ static struct ecard_driver arxescsi_driver = { ...@@ -434,7 +397,8 @@ static struct ecard_driver arxescsi_driver = {
.remove = __devexit_p(arxescsi_remove), .remove = __devexit_p(arxescsi_remove),
.id_table = arxescsi_cids, .id_table = arxescsi_cids,
.drv = { .drv = {
.name = "arxescsi", .devclass = &shost_devclass,
.name = "arxescsi",
}, },
}; };
......
...@@ -334,7 +334,8 @@ static struct ecard_driver cumanascsi1_driver = { ...@@ -334,7 +334,8 @@ static struct ecard_driver cumanascsi1_driver = {
.remove = __devexit_p(cumanascsi1_remove), .remove = __devexit_p(cumanascsi1_remove),
.id_table = cumanascsi1_cids, .id_table = cumanascsi1_cids,
.drv = { .drv = {
.name = "cumanascsi1", .devclass = &shost_devclass,
.name = "cumanascsi1",
}, },
}; };
......
...@@ -41,12 +41,12 @@ ...@@ -41,12 +41,12 @@
#include <scsi/scsicam.h> #include <scsi/scsicam.h>
#define CUMANASCSI2_STATUS (0) #define CUMANASCSI2_STATUS (0x0000)
#define STATUS_INT (1 << 0) #define STATUS_INT (1 << 0)
#define STATUS_DRQ (1 << 1) #define STATUS_DRQ (1 << 1)
#define STATUS_LATCHED (1 << 3) #define STATUS_LATCHED (1 << 3)
#define CUMANASCSI2_ALATCH (5) #define CUMANASCSI2_ALATCH (0x0014)
#define ALATCH_ENA_INT (3) #define ALATCH_ENA_INT (3)
#define ALATCH_DIS_INT (2) #define ALATCH_DIS_INT (2)
#define ALATCH_ENA_TERM (5) #define ALATCH_ENA_TERM (5)
...@@ -58,11 +58,10 @@ ...@@ -58,11 +58,10 @@
#define ALATCH_DMA_OUT (15) #define ALATCH_DMA_OUT (15)
#define ALATCH_DMA_IN (14) #define ALATCH_DMA_IN (14)
#define CUMANASCSI2_PSEUDODMA (0x80) #define CUMANASCSI2_PSEUDODMA (0x0200)
#define CUMANASCSI2_FAS216_OFFSET (0xc0) #define CUMANASCSI2_FAS216_OFFSET (0x0300)
#define CUMANASCSI2_FAS216_SHIFT 0 #define CUMANASCSI2_FAS216_SHIFT 2
#define CUMANASCSI2_FAS216_SIZE (16)
/* /*
* Version * Version
...@@ -77,13 +76,14 @@ static int term[MAX_ECARDS] = { 1, 1, 1, 1, 1, 1, 1, 1 }; ...@@ -77,13 +76,14 @@ static int term[MAX_ECARDS] = { 1, 1, 1, 1, 1, 1, 1, 1 };
#define NR_SG 256 #define NR_SG 256
struct cumanascsi2_info { struct cumanascsi2_info {
FAS216_Info info; FAS216_Info info;
struct expansion_card *ec;
unsigned int status; /* card status register */
unsigned int alatch; /* Control register */ void *status; /* card status register */
unsigned int terms; /* Terminator state */ void *alatch; /* Control register */
unsigned int dmaarea; /* Pseudo DMA area */ unsigned int terms; /* Terminator state */
struct scatterlist sg[NR_SG]; /* Scatter DMA list */ void *dmaarea; /* Pseudo DMA area */
struct scatterlist sg[NR_SG]; /* Scatter DMA list */
}; };
#define CSTATUS_IRQ (1 << 0) #define CSTATUS_IRQ (1 << 0)
...@@ -97,8 +97,7 @@ struct cumanascsi2_info { ...@@ -97,8 +97,7 @@ struct cumanascsi2_info {
static void static void
cumanascsi_2_irqenable(struct expansion_card *ec, int irqnr) cumanascsi_2_irqenable(struct expansion_card *ec, int irqnr)
{ {
unsigned int port = (unsigned int)ec->irq_data; writeb(ALATCH_ENA_INT, ec->irq_data);
outb(ALATCH_ENA_INT, port);
} }
/* Prototype: void cumanascsi_2_irqdisable(ec, irqnr) /* Prototype: void cumanascsi_2_irqdisable(ec, irqnr)
...@@ -109,8 +108,7 @@ cumanascsi_2_irqenable(struct expansion_card *ec, int irqnr) ...@@ -109,8 +108,7 @@ cumanascsi_2_irqenable(struct expansion_card *ec, int irqnr)
static void static void
cumanascsi_2_irqdisable(struct expansion_card *ec, int irqnr) cumanascsi_2_irqdisable(struct expansion_card *ec, int irqnr)
{ {
unsigned int port = (unsigned int)ec->irq_data; writeb(ALATCH_DIS_INT, ec->irq_data);
outb(ALATCH_DIS_INT, port);
} }
static const expansioncard_ops_t cumanascsi_2_ops = { static const expansioncard_ops_t cumanascsi_2_ops = {
...@@ -130,10 +128,10 @@ cumanascsi_2_terminator_ctl(struct Scsi_Host *host, int on_off) ...@@ -130,10 +128,10 @@ cumanascsi_2_terminator_ctl(struct Scsi_Host *host, int on_off)
if (on_off) { if (on_off) {
info->terms = 1; info->terms = 1;
outb (ALATCH_ENA_TERM, info->alatch); writeb(ALATCH_ENA_TERM, info->alatch);
} else { } else {
info->terms = 0; info->terms = 0;
outb (ALATCH_DIS_TERM, info->alatch); writeb(ALATCH_DIS_TERM, info->alatch);
} }
} }
...@@ -146,9 +144,9 @@ cumanascsi_2_terminator_ctl(struct Scsi_Host *host, int on_off) ...@@ -146,9 +144,9 @@ cumanascsi_2_terminator_ctl(struct Scsi_Host *host, int on_off)
static void static void
cumanascsi_2_intr(int irq, void *dev_id, struct pt_regs *regs) cumanascsi_2_intr(int irq, void *dev_id, struct pt_regs *regs)
{ {
struct Scsi_Host *host = (struct Scsi_Host *)dev_id; struct cumanascsi2_info *info = dev_id;
fas216_intr(host); fas216_intr(&info->info);
} }
/* Prototype: fasdmatype_t cumanascsi_2_dma_setup(host, SCpnt, direction, min_type) /* Prototype: fasdmatype_t cumanascsi_2_dma_setup(host, SCpnt, direction, min_type)
...@@ -167,7 +165,7 @@ cumanascsi_2_dma_setup(struct Scsi_Host *host, Scsi_Pointer *SCp, ...@@ -167,7 +165,7 @@ cumanascsi_2_dma_setup(struct Scsi_Host *host, Scsi_Pointer *SCp,
struct device *dev = scsi_get_device(host); struct device *dev = scsi_get_device(host);
int dmach = host->dma_channel; int dmach = host->dma_channel;
outb(ALATCH_DIS_DMA, info->alatch); writeb(ALATCH_DIS_DMA, info->alatch);
if (dmach != NO_DMA && if (dmach != NO_DMA &&
(min_type == fasdma_real_all || SCp->this_residual >= 512)) { (min_type == fasdma_real_all || SCp->this_residual >= 512)) {
...@@ -188,11 +186,11 @@ cumanascsi_2_dma_setup(struct Scsi_Host *host, Scsi_Pointer *SCp, ...@@ -188,11 +186,11 @@ cumanascsi_2_dma_setup(struct Scsi_Host *host, Scsi_Pointer *SCp,
disable_dma(dmach); disable_dma(dmach);
set_dma_sg(dmach, info->sg, bufs + 1); set_dma_sg(dmach, info->sg, bufs + 1);
outb(alatch_dir, info->alatch); writeb(alatch_dir, info->alatch);
set_dma_mode(dmach, dma_dir); set_dma_mode(dmach, dma_dir);
enable_dma(dmach); enable_dma(dmach);
outb(ALATCH_ENA_DMA, info->alatch); writeb(ALATCH_ENA_DMA, info->alatch);
outb(ALATCH_DIS_BIT32, info->alatch); writeb(ALATCH_DIS_BIT32, info->alatch);
return fasdma_real_all; return fasdma_real_all;
} }
...@@ -226,7 +224,7 @@ cumanascsi_2_dma_pseudo(struct Scsi_Host *host, Scsi_Pointer *SCp, ...@@ -226,7 +224,7 @@ cumanascsi_2_dma_pseudo(struct Scsi_Host *host, Scsi_Pointer *SCp,
#if 0 #if 0
while (length > 1) { while (length > 1) {
unsigned long word; unsigned long word;
unsigned int status = inb(info->status); unsigned int status = readb(info->status);
if (status & STATUS_INT) if (status & STATUS_INT)
goto end; goto end;
...@@ -235,7 +233,7 @@ cumanascsi_2_dma_pseudo(struct Scsi_Host *host, Scsi_Pointer *SCp, ...@@ -235,7 +233,7 @@ cumanascsi_2_dma_pseudo(struct Scsi_Host *host, Scsi_Pointer *SCp,
continue; continue;
word = *addr | *(addr + 1) << 8; word = *addr | *(addr + 1) << 8;
outw (info->dmaarea); writew(word, info->dmaarea);
addr += 2; addr += 2;
length -= 2; length -= 2;
} }
...@@ -245,15 +243,15 @@ cumanascsi_2_dma_pseudo(struct Scsi_Host *host, Scsi_Pointer *SCp, ...@@ -245,15 +243,15 @@ cumanascsi_2_dma_pseudo(struct Scsi_Host *host, Scsi_Pointer *SCp,
else { else {
if (transfer && (transfer & 255)) { if (transfer && (transfer & 255)) {
while (length >= 256) { while (length >= 256) {
unsigned int status = inb(info->status); unsigned int status = readb(info->status);
if (status & STATUS_INT) if (status & STATUS_INT)
goto end; return;
if (!(status & STATUS_DRQ)) if (!(status & STATUS_DRQ))
continue; continue;
insw(info->dmaarea, addr, 256 >> 1); readsw(info->dmaarea, addr, 256 >> 1);
addr += 256; addr += 256;
length -= 256; length -= 256;
} }
...@@ -261,15 +259,15 @@ cumanascsi_2_dma_pseudo(struct Scsi_Host *host, Scsi_Pointer *SCp, ...@@ -261,15 +259,15 @@ cumanascsi_2_dma_pseudo(struct Scsi_Host *host, Scsi_Pointer *SCp,
while (length > 0) { while (length > 0) {
unsigned long word; unsigned long word;
unsigned int status = inb(info->status); unsigned int status = readb(info->status);
if (status & STATUS_INT) if (status & STATUS_INT)
goto end; return;
if (!(status & STATUS_DRQ)) if (!(status & STATUS_DRQ))
continue; continue;
word = inw (info->dmaarea); word = readw(info->dmaarea);
*addr++ = word; *addr++ = word;
if (--length > 0) { if (--length > 0) {
*addr++ = word >> 8; *addr++ = word >> 8;
...@@ -277,8 +275,6 @@ cumanascsi_2_dma_pseudo(struct Scsi_Host *host, Scsi_Pointer *SCp, ...@@ -277,8 +275,6 @@ cumanascsi_2_dma_pseudo(struct Scsi_Host *host, Scsi_Pointer *SCp,
} }
} }
} }
end:
} }
/* Prototype: int cumanascsi_2_dma_stop(host, SCpnt) /* Prototype: int cumanascsi_2_dma_stop(host, SCpnt)
...@@ -291,7 +287,7 @@ cumanascsi_2_dma_stop(struct Scsi_Host *host, Scsi_Pointer *SCp) ...@@ -291,7 +287,7 @@ cumanascsi_2_dma_stop(struct Scsi_Host *host, Scsi_Pointer *SCp)
{ {
struct cumanascsi2_info *info = (struct cumanascsi2_info *)host->hostdata; struct cumanascsi2_info *info = (struct cumanascsi2_info *)host->hostdata;
if (host->dma_channel != NO_DMA) { if (host->dma_channel != NO_DMA) {
outb(ALATCH_DIS_DMA, info->alatch); writeb(ALATCH_DIS_DMA, info->alatch);
disable_dma(host->dma_channel); disable_dma(host->dma_channel);
} }
} }
...@@ -304,13 +300,11 @@ cumanascsi_2_dma_stop(struct Scsi_Host *host, Scsi_Pointer *SCp) ...@@ -304,13 +300,11 @@ cumanascsi_2_dma_stop(struct Scsi_Host *host, Scsi_Pointer *SCp)
const char *cumanascsi_2_info(struct Scsi_Host *host) const char *cumanascsi_2_info(struct Scsi_Host *host)
{ {
struct cumanascsi2_info *info = (struct cumanascsi2_info *)host->hostdata; struct cumanascsi2_info *info = (struct cumanascsi2_info *)host->hostdata;
static char string[150], *p; static char string[150];
p = string; sprintf(string, "%s (%s) in slot %d v%s terminators o%s",
p += sprintf(p, "%s ", host->hostt->name); host->hostt->name, info->info.scsi.type, info->ec->slot_no,
p += fas216_info(&info->info, p); VERSION, info->terms ? "n" : "ff");
p += sprintf(p, "v%s terminators o%s",
VERSION, info->terms ? "n" : "ff");
return string; return string;
} }
...@@ -377,10 +371,7 @@ int cumanascsi_2_proc_info (char *buffer, char **start, off_t offset, ...@@ -377,10 +371,7 @@ int cumanascsi_2_proc_info (char *buffer, char **start, off_t offset,
info = (struct cumanascsi2_info *)host->hostdata; info = (struct cumanascsi2_info *)host->hostdata;
begin = 0; begin = 0;
pos = sprintf(buffer, pos = sprintf(buffer, "Cumana SCSI II driver v%s\n", VERSION);
"Cumana SCSI II driver version v%s\n",
VERSION);
pos += fas216_print_host(&info->info, buffer + pos); pos += fas216_print_host(&info->info, buffer + pos);
pos += sprintf(buffer + pos, "Term : o%s\n", pos += sprintf(buffer + pos, "Term : o%s\n",
info->terms ? "n" : "ff"); info->terms ? "n" : "ff");
...@@ -440,38 +431,52 @@ static int __devinit ...@@ -440,38 +431,52 @@ static int __devinit
cumanascsi2_probe(struct expansion_card *ec, const struct ecard_id *id) cumanascsi2_probe(struct expansion_card *ec, const struct ecard_id *id)
{ {
struct Scsi_Host *host; struct Scsi_Host *host;
struct cumanascsi2_info *info; struct cumanascsi2_info *info;
int ret = -ENOMEM; unsigned long resbase, reslen;
unsigned char *base;
int ret;
host = scsi_register(&cumanascsi2_template, sizeof (struct cumanascsi2_info)); resbase = ecard_resource_start(ec, ECARD_RES_MEMC);
if (!host) reslen = ecard_resource_len(ec, ECARD_RES_MEMC);
if (!request_mem_region(resbase, reslen, "cumanascsi2")) {
ret = -EBUSY;
goto out; goto out;
}
host->io_port = ecard_address(ec, ECARD_MEMC, 0); base = ioremap(resbase, reslen);
host->irq = ec->irq; if (!base) {
host->dma_channel = ec->dma; ret = -ENOMEM;
goto out_region;
}
if (!request_region(host->io_port + CUMANASCSI2_FAS216_OFFSET, host = scsi_register(&cumanascsi2_template,
CUMANASCSI2_FAS216_SIZE, "cumanascsi2-fas")) { sizeof(struct cumanascsi2_info));
ret = -EBUSY; if (!host) {
goto out_free; ret = -ENOMEM;
goto out_unmap;
} }
host->base = (unsigned long)base;
host->irq = ec->irq;
host->dma_channel = ec->dma;
ecard_set_drvdata(ec, host); ecard_set_drvdata(ec, host);
info = (struct cumanascsi2_info *)host->hostdata; info = (struct cumanascsi2_info *)host->hostdata;
info->dmaarea = host->io_port + CUMANASCSI2_PSEUDODMA; info->ec = ec;
info->status = host->io_port + CUMANASCSI2_STATUS; info->dmaarea = base + CUMANASCSI2_PSEUDODMA;
info->alatch = host->io_port + CUMANASCSI2_ALATCH; info->status = base + CUMANASCSI2_STATUS;
info->alatch = base + CUMANASCSI2_ALATCH;
ec->irqaddr = (unsigned char *)ioaddr(info->status); ec->irqaddr = info->status;
ec->irqmask = STATUS_INT; ec->irqmask = STATUS_INT;
ec->irq_data = (void *)info->alatch; ec->irq_data = base + CUMANASCSI2_ALATCH;
ec->ops = (expansioncard_ops_t *)&cumanascsi_2_ops; ec->ops = &cumanascsi_2_ops;
cumanascsi_2_terminator_ctl(host, term[ec->slot_no]); cumanascsi_2_terminator_ctl(host, term[ec->slot_no]);
info->info.scsi.io_port = host->io_port + CUMANASCSI2_FAS216_OFFSET; info->info.scsi.io_base = base + CUMANASCSI2_FAS216_OFFSET;
info->info.scsi.io_shift = CUMANASCSI2_FAS216_SHIFT; info->info.scsi.io_shift = CUMANASCSI2_FAS216_SHIFT;
info->info.scsi.irq = host->irq; info->info.scsi.irq = host->irq;
info->info.ifcfg.clockrate = 40; /* MHz */ info->info.ifcfg.clockrate = 40; /* MHz */
...@@ -481,16 +486,21 @@ cumanascsi2_probe(struct expansion_card *ec, const struct ecard_id *id) ...@@ -481,16 +486,21 @@ cumanascsi2_probe(struct expansion_card *ec, const struct ecard_id *id)
info->info.ifcfg.cntl3 = CNTL3_BS8 | CNTL3_FASTSCSI | CNTL3_FASTCLK; info->info.ifcfg.cntl3 = CNTL3_BS8 | CNTL3_FASTSCSI | CNTL3_FASTCLK;
info->info.ifcfg.disconnect_ok = 1; info->info.ifcfg.disconnect_ok = 1;
info->info.ifcfg.wide_max_size = 0; info->info.ifcfg.wide_max_size = 0;
info->info.ifcfg.capabilities = FASCAP_PSEUDODMA;
info->info.dma.setup = cumanascsi_2_dma_setup; info->info.dma.setup = cumanascsi_2_dma_setup;
info->info.dma.pseudo = cumanascsi_2_dma_pseudo; info->info.dma.pseudo = cumanascsi_2_dma_pseudo;
info->info.dma.stop = cumanascsi_2_dma_stop; info->info.dma.stop = cumanascsi_2_dma_stop;
ret = fas216_init(host);
if (ret)
goto out_free;
ret = request_irq(host->irq, cumanascsi_2_intr, ret = request_irq(host->irq, cumanascsi_2_intr,
SA_INTERRUPT, "cumanascsi2", host); SA_INTERRUPT, "cumanascsi2", info);
if (ret) { if (ret) {
printk("scsi%d: IRQ%d not free: %d\n", printk("scsi%d: IRQ%d not free: %d\n",
host->host_no, host->irq, ret); host->host_no, host->irq, ret);
goto out_region; goto out_release;
} }
if (host->dma_channel != NO_DMA) { if (host->dma_channel != NO_DMA) {
...@@ -500,26 +510,30 @@ cumanascsi2_probe(struct expansion_card *ec, const struct ecard_id *id) ...@@ -500,26 +510,30 @@ cumanascsi2_probe(struct expansion_card *ec, const struct ecard_id *id)
host->dma_channel = NO_DMA; host->dma_channel = NO_DMA;
} else { } else {
set_dma_speed(host->dma_channel, 180); set_dma_speed(host->dma_channel, 180);
info->info.ifcfg.capabilities |= FASCAP_DMA;
} }
} }
fas216_init(host); ret = fas216_add(host, &ec->dev);
ret = scsi_add_host(host, &ec->dev);
if (ret == 0) if (ret == 0)
goto out; goto out;
fas216_release(host);
if (host->dma_channel != NO_DMA) if (host->dma_channel != NO_DMA)
free_dma(host->dma_channel); free_dma(host->dma_channel);
free_irq(host->irq, host); free_irq(host->irq, host);
out_region:
release_region(host->io_port + CUMANASCSI2_FAS216_OFFSET, out_release:
CUMANASCSI2_FAS216_SIZE); fas216_release(host);
out_free: out_free:
scsi_unregister(host); scsi_unregister(host);
out_unmap:
iounmap(base);
out_region:
release_mem_region(resbase, reslen);
out: out:
return ret; return ret;
} }
...@@ -527,17 +541,24 @@ cumanascsi2_probe(struct expansion_card *ec, const struct ecard_id *id) ...@@ -527,17 +541,24 @@ cumanascsi2_probe(struct expansion_card *ec, const struct ecard_id *id)
static void __devexit cumanascsi2_remove(struct expansion_card *ec) static void __devexit cumanascsi2_remove(struct expansion_card *ec)
{ {
struct Scsi_Host *host = ecard_get_drvdata(ec); struct Scsi_Host *host = ecard_get_drvdata(ec);
struct cumanascsi2_info *info = (struct cumanascsi2_info *)host->hostdata;
unsigned long resbase, reslen;
ecard_set_drvdata(ec, NULL); ecard_set_drvdata(ec, NULL);
scsi_remove_host(host); fas216_remove(host);
fas216_release(host);
if (host->dma_channel != NO_DMA) if (host->dma_channel != NO_DMA)
free_dma(host->dma_channel); free_dma(host->dma_channel);
free_irq(host->irq, host); free_irq(host->irq, info);
release_region(host->io_port + CUMANASCSI2_FAS216_OFFSET,
CUMANASCSI2_FAS216_SIZE);
iounmap((void *)host->base);
resbase = ecard_resource_start(ec, ECARD_RES_MEMC);
reslen = ecard_resource_len(ec, ECARD_RES_MEMC);
release_mem_region(resbase, reslen);
fas216_release(host);
scsi_unregister(host); scsi_unregister(host);
} }
...@@ -551,7 +572,8 @@ static struct ecard_driver cumanascsi2_driver = { ...@@ -551,7 +572,8 @@ static struct ecard_driver cumanascsi2_driver = {
.remove = __devexit_p(cumanascsi2_remove), .remove = __devexit_p(cumanascsi2_remove),
.id_table = cumanascsi2_cids, .id_table = cumanascsi2_cids,
.drv = { .drv = {
.name = "cumanascsi2", .devclass = &shost_devclass,
.name = "cumanascsi2",
}, },
}; };
......
/* /*
* linux/drivers/acorn/scsi/eesox.c * linux/drivers/acorn/scsi/eesox.c
* *
* Copyright (C) 1997-2002 Russell King * Copyright (C) 1997-2003 Russell King
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
...@@ -47,25 +47,21 @@ ...@@ -47,25 +47,21 @@
#include <scsi/scsicam.h> #include <scsi/scsicam.h>
#define EESOX_FAS216_OFFSET 0xc00 #define EESOX_FAS216_OFFSET 0x3000
#define EESOX_FAS216_SHIFT 3 #define EESOX_FAS216_SHIFT 5
#define EESOX_FAS216_SIZE (16 << EESOX_FAS216_SHIFT)
#define EESOX_STATUS 0xa00 #define EESOX_DMASTAT 0x2800
#define EESOX_STAT_INTR 0x01 #define EESOX_STAT_INTR 0x01
#define EESOX_STAT_DMA 0x02 #define EESOX_STAT_DMA 0x02
#define EESOX_CONTROL 0xa00 #define EESOX_CONTROL 0x2800
#define EESOX_INTR_ENABLE 0x04 #define EESOX_INTR_ENABLE 0x04
#define EESOX_TERM_ENABLE 0x02 #define EESOX_TERM_ENABLE 0x02
#define EESOX_RESET 0x01 #define EESOX_RESET 0x01
#define EESOX_DMA_OFFSET 0xe00 #define EESOX_DMADATA 0x3800
/* #define VERSION "1.10 (17/01/2003 2.5.59)"
* Version
*/
#define VERSION "1.00 (13/11/2002 2.5.47)"
/* /*
* Use term=0,1,0,0,0 to turn terminators on/off * Use term=0,1,0,0,0 to turn terminators on/off
...@@ -75,12 +71,12 @@ static int term[MAX_ECARDS] = { 1, 1, 1, 1, 1, 1, 1, 1 }; ...@@ -75,12 +71,12 @@ static int term[MAX_ECARDS] = { 1, 1, 1, 1, 1, 1, 1, 1 };
#define NR_SG 256 #define NR_SG 256
struct eesoxscsi_info { struct eesoxscsi_info {
FAS216_Info info; FAS216_Info info;
struct expansion_card *ec;
unsigned int ctl_port; void *ctl_port;
unsigned int control; unsigned int control;
unsigned int dmaarea; /* Pseudo DMA area */ struct scatterlist sg[NR_SG]; /* Scatter DMA list */
struct scatterlist sg[NR_SG]; /* Scatter DMA list */
}; };
/* Prototype: void eesoxscsi_irqenable(ec, irqnr) /* Prototype: void eesoxscsi_irqenable(ec, irqnr)
...@@ -95,7 +91,7 @@ eesoxscsi_irqenable(struct expansion_card *ec, int irqnr) ...@@ -95,7 +91,7 @@ eesoxscsi_irqenable(struct expansion_card *ec, int irqnr)
info->control |= EESOX_INTR_ENABLE; info->control |= EESOX_INTR_ENABLE;
outb(info->control, info->ctl_port); writeb(info->control, info->ctl_port);
} }
/* Prototype: void eesoxscsi_irqdisable(ec, irqnr) /* Prototype: void eesoxscsi_irqdisable(ec, irqnr)
...@@ -110,7 +106,7 @@ eesoxscsi_irqdisable(struct expansion_card *ec, int irqnr) ...@@ -110,7 +106,7 @@ eesoxscsi_irqdisable(struct expansion_card *ec, int irqnr)
info->control &= ~EESOX_INTR_ENABLE; info->control &= ~EESOX_INTR_ENABLE;
outb(info->control, info->ctl_port); writeb(info->control, info->ctl_port);
} }
static const expansioncard_ops_t eesoxscsi_ops = { static const expansioncard_ops_t eesoxscsi_ops = {
...@@ -135,7 +131,7 @@ eesoxscsi_terminator_ctl(struct Scsi_Host *host, int on_off) ...@@ -135,7 +131,7 @@ eesoxscsi_terminator_ctl(struct Scsi_Host *host, int on_off)
else else
info->control &= ~EESOX_TERM_ENABLE; info->control &= ~EESOX_TERM_ENABLE;
outb(info->control, info->ctl_port); writeb(info->control, info->ctl_port);
spin_unlock_irqrestore(host->host_lock, flags); spin_unlock_irqrestore(host->host_lock, flags);
} }
...@@ -148,9 +144,9 @@ eesoxscsi_terminator_ctl(struct Scsi_Host *host, int on_off) ...@@ -148,9 +144,9 @@ eesoxscsi_terminator_ctl(struct Scsi_Host *host, int on_off)
static void static void
eesoxscsi_intr(int irq, void *dev_id, struct pt_regs *regs) eesoxscsi_intr(int irq, void *dev_id, struct pt_regs *regs)
{ {
struct Scsi_Host *host = (struct Scsi_Host *)dev_id; struct eesoxscsi_info *info = dev_id;
fas216_intr(host); fas216_intr(&info->info);
} }
/* Prototype: fasdmatype_t eesoxscsi_dma_setup(host, SCpnt, direction, min_type) /* Prototype: fasdmatype_t eesoxscsi_dma_setup(host, SCpnt, direction, min_type)
...@@ -198,93 +194,164 @@ eesoxscsi_dma_setup(struct Scsi_Host *host, Scsi_Pointer *SCp, ...@@ -198,93 +194,164 @@ eesoxscsi_dma_setup(struct Scsi_Host *host, Scsi_Pointer *SCp,
return fasdma_pseudo; return fasdma_pseudo;
} }
static void static void eesoxscsi_buffer_in(void *buf, int length, void *base)
eesoxscsi_dma_pseudo(struct Scsi_Host *host, Scsi_Pointer *SCp,
fasdmadir_t dir, int transfer_size)
{ {
struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata; const void *reg_fas = base + EESOX_FAS216_OFFSET;
unsigned int status; const void *reg_dmastat = base + EESOX_DMASTAT;
unsigned int length = SCp->this_residual; const void *reg_dmadata = base + EESOX_DMADATA;
union { const register unsigned long mask = 0xffff;
unsigned char *c;
unsigned short *s; do {
unsigned long *l; unsigned int status;
} buffer;
/*
* Interrupt request?
*/
status = readb(reg_fas + (REG_STAT << EESOX_FAS216_SHIFT));
if (status & STAT_INT)
break;
/*
* DMA request active?
*/
status = readb(reg_dmastat);
if (!(status & EESOX_STAT_DMA))
continue;
/*
* Get number of bytes in FIFO
*/
status = readb(reg_fas + (REG_CFIS << EESOX_FAS216_SHIFT)) & CFIS_CF;
if (status > 16)
status = 16;
if (status > length)
status = length;
/*
* Align buffer.
*/
if (((u32)buf) & 2 && status >= 2) {
*((u16 *)buf)++ = readl(reg_dmadata);
status -= 2;
length -= 2;
}
buffer.c = SCp->ptr; if (status >= 8) {
unsigned long l1, l2;
l1 = readl(reg_dmadata) & mask;
l1 |= readl(reg_dmadata) << 16;
l2 = readl(reg_dmadata) & mask;
l2 |= readl(reg_dmadata) << 16;
*((u32 *)buf)++ = l1;
*((u32 *)buf)++ = l2;
length -= 8;
continue;
}
status = inb(host->io_port + EESOX_STATUS); if (status >= 4) {
if (dir == DMA_IN) { unsigned long l1;
while (length > 8) {
if (status & EESOX_STAT_DMA) { l1 = readl(reg_dmadata) & mask;
unsigned long l1, l2; l1 |= readl(reg_dmadata) << 16;
l1 = inw(info->dmaarea); *((u32 *)buf)++ = l1;
l1 |= inw(info->dmaarea) << 16; length -= 4;
l2 = inw(info->dmaarea); continue;
l2 |= inw(info->dmaarea) << 16;
*buffer.l++ = l1;
*buffer.l++ = l2;
length -= 8;
} else if (status & EESOX_STAT_INTR)
goto end;
status = inb(host->io_port + EESOX_STATUS);
} }
while (length > 1) { if (status >= 2) {
if (status & EESOX_STAT_DMA) { *((u16 *)buf)++ = readl(reg_dmadata);
*buffer.s++ = inw(info->dmaarea); length -= 2;
length -= 2;
} else if (status & EESOX_STAT_INTR)
goto end;
status = inb(host->io_port + EESOX_STATUS);
} }
} while (length);
}
while (length > 0) { static void eesoxscsi_buffer_out(void *buf, int length, void *base)
if (status & EESOX_STAT_DMA) { {
*buffer.c++ = inw(info->dmaarea); const void *reg_fas = base + EESOX_FAS216_OFFSET;
length -= 1; const void *reg_dmastat = base + EESOX_DMASTAT;
} else if (status & EESOX_STAT_INTR) const void *reg_dmadata = base + EESOX_DMADATA;
goto end;
status = inb(host->io_port + EESOX_STATUS); do {
unsigned int status;
/*
* Interrupt request?
*/
status = readb(reg_fas + (REG_STAT << EESOX_FAS216_SHIFT));
if (status & STAT_INT)
break;
/*
* DMA request active?
*/
status = readb(reg_dmastat);
if (!(status & EESOX_STAT_DMA))
continue;
/*
* Get number of bytes in FIFO
*/
status = readb(reg_fas + (REG_CFIS << EESOX_FAS216_SHIFT)) & CFIS_CF;
if (status > 16)
status = 16;
status = 16 - status;
if (status > length)
status = length;
status &= ~1;
/*
* Align buffer.
*/
if (((u32)buf) & 2 && status >= 2) {
writel(*((u16 *)buf)++ << 16, reg_dmadata);
status -= 2;
length -= 2;
} }
} else {
while (length > 8) { if (status >= 8) {
if (status & EESOX_STAT_DMA) { unsigned long l1, l2;
unsigned long l1, l2;
l1 = *((u32 *)buf)++;
l1 = *buffer.l++; l2 = *((u32 *)buf)++;
l2 = *buffer.l++;
writel(l1 << 16, reg_dmadata);
outw(l1, info->dmaarea); writel(l1, reg_dmadata);
outw(l1 >> 16, info->dmaarea); writel(l2 << 16, reg_dmadata);
outw(l2, info->dmaarea); writel(l2, reg_dmadata);
outw(l2 >> 16, info->dmaarea); length -= 8;
length -= 8; continue;
} else if (status & EESOX_STAT_INTR)
goto end;
status = inb(host->io_port + EESOX_STATUS);
} }
while (length > 1) { if (status >= 4) {
if (status & EESOX_STAT_DMA) { unsigned long l1;
outw(*buffer.s++, info->dmaarea);
length -= 2; l1 = *((u32 *)buf)++;
} else if (status & EESOX_STAT_INTR)
goto end; writel(l1 << 16, reg_dmadata);
status = inb(host->io_port + EESOX_STATUS); writel(l1, reg_dmadata);
length -= 4;
continue;
} }
while (length > 0) { if (status >= 2) {
if (status & EESOX_STAT_DMA) { writel(*((u16 *)buf)++ << 16, reg_dmadata);
outw(*buffer.c++, info->dmaarea); length -= 2;
length -= 1;
} else if (status & EESOX_STAT_INTR)
goto end;
status = inb(host->io_port + EESOX_STATUS);
} }
} while (length);
}
static void
eesoxscsi_dma_pseudo(struct Scsi_Host *host, Scsi_Pointer *SCp,
fasdmadir_t dir, int transfer_size)
{
void *base = (void *)host->base;
if (dir == DMA_IN) {
eesoxscsi_buffer_in(SCp->ptr, SCp->this_residual, base);
} else {
eesoxscsi_buffer_out(SCp->ptr, SCp->this_residual, base);
} }
end:
} }
/* Prototype: int eesoxscsi_dma_stop(host, SCpnt) /* Prototype: int eesoxscsi_dma_stop(host, SCpnt)
...@@ -307,14 +374,11 @@ eesoxscsi_dma_stop(struct Scsi_Host *host, Scsi_Pointer *SCp) ...@@ -307,14 +374,11 @@ eesoxscsi_dma_stop(struct Scsi_Host *host, Scsi_Pointer *SCp)
const char *eesoxscsi_info(struct Scsi_Host *host) const char *eesoxscsi_info(struct Scsi_Host *host)
{ {
struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata; struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
static char string[150], *p; static char string[150];
p = string; sprintf(string, "%s (%s) in slot %d v%s terminators o%s",
p += sprintf(p, "%s ", host->hostt->name); host->hostt->name, info->info.scsi.type, info->ec->slot_no,
p += fas216_info(&info->info, p); VERSION, info->control & EESOX_TERM_ENABLE ? "n" : "ff");
p += sprintf(p, "v%s terminators o%s",
VERSION,
info->control & EESOX_TERM_ENABLE ? "n" : "ff");
return string; return string;
} }
...@@ -381,9 +445,7 @@ int eesoxscsi_proc_info(char *buffer, char **start, off_t offset, ...@@ -381,9 +445,7 @@ int eesoxscsi_proc_info(char *buffer, char **start, off_t offset,
info = (struct eesoxscsi_info *)host->hostdata; info = (struct eesoxscsi_info *)host->hostdata;
begin = 0; begin = 0;
pos = sprintf(buffer, pos = sprintf(buffer, "EESOX SCSI driver v%s\n", VERSION);
"EESOX SCSI driver version v%s\n",
VERSION);
pos += fas216_print_host(&info->info, buffer + pos); pos += fas216_print_host(&info->info, buffer + pos);
pos += sprintf(buffer + pos, "Term : o%s\n", pos += sprintf(buffer + pos, "Term : o%s\n",
info->control & EESOX_TERM_ENABLE ? "n" : "ff"); info->control & EESOX_TERM_ENABLE ? "n" : "ff");
...@@ -417,6 +479,39 @@ int eesoxscsi_proc_info(char *buffer, char **start, off_t offset, ...@@ -417,6 +479,39 @@ int eesoxscsi_proc_info(char *buffer, char **start, off_t offset,
return pos; return pos;
} }
static ssize_t eesoxscsi_show_term(struct device *dev, char *buf)
{
struct expansion_card *ec = ECARD_DEV(dev);
struct Scsi_Host *host = ecard_get_drvdata(ec);
struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
return sprintf(buf, "%d\n", info->control & EESOX_TERM_ENABLE ? 1 : 0);
}
static ssize_t eesoxscsi_store_term(struct device *dev, const char *buf, size_t len)
{
struct expansion_card *ec = ECARD_DEV(dev);
struct Scsi_Host *host = ecard_get_drvdata(ec);
struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
unsigned long flags;
if (len > 1) {
spin_lock_irqsave(host->host_lock, flags);
if (buf[0] != '0') {
info->control |= EESOX_TERM_ENABLE;
} else {
info->control &= ~EESOX_TERM_ENABLE;
}
writeb(info->control, info->ctl_port);
spin_unlock_irqrestore(host->host_lock, flags);
}
return len;
}
static DEVICE_ATTR(bus_term, S_IRUGO | S_IWUSR,
eesoxscsi_show_term, eesoxscsi_store_term);
static Scsi_Host_Template eesox_template = { static Scsi_Host_Template eesox_template = {
.module = THIS_MODULE, .module = THIS_MODULE,
.proc_info = eesoxscsi_proc_info, .proc_info = eesoxscsi_proc_info,
...@@ -440,57 +535,75 @@ static int __devinit ...@@ -440,57 +535,75 @@ static int __devinit
eesoxscsi_probe(struct expansion_card *ec, const struct ecard_id *id) eesoxscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
{ {
struct Scsi_Host *host; struct Scsi_Host *host;
struct eesoxscsi_info *info; struct eesoxscsi_info *info;
int ret = -ENOMEM; unsigned long resbase, reslen;
unsigned char *base;
int ret;
host = scsi_register(&eesox_template, resbase = ecard_resource_start(ec, ECARD_RES_IOCFAST);
sizeof(struct eesoxscsi_info)); reslen = ecard_resource_len(ec, ECARD_RES_IOCFAST);
if (!host)
if (!request_mem_region(resbase, reslen, "eesoxscsi")) {
ret = -EBUSY;
goto out; goto out;
}
host->io_port = ecard_address(ec, ECARD_IOC, ECARD_FAST); base = ioremap(resbase, reslen);
host->irq = ec->irq; if (!base) {
host->dma_channel = ec->dma; ret = -ENOMEM;
goto out_region;
}
if (!request_region(host->io_port + EESOX_FAS216_OFFSET, host = scsi_register(&eesox_template,
EESOX_FAS216_SIZE, "eesox2-fas")) { sizeof(struct eesoxscsi_info));
ret = -EBUSY; if (!host) {
goto out_free; ret = -ENOMEM;
goto out_unmap;
} }
host->base = (unsigned long)base;
host->irq = ec->irq;
host->dma_channel = ec->dma;
ecard_set_drvdata(ec, host); ecard_set_drvdata(ec, host);
info = (struct eesoxscsi_info *)host->hostdata; info = (struct eesoxscsi_info *)host->hostdata;
info->ctl_port = host->io_port + EESOX_CONTROL; info->ec = ec;
info->control = term[ec->slot_no] ? EESOX_TERM_ENABLE : 0; info->ctl_port = base + EESOX_CONTROL;
outb(info->control, info->ctl_port); info->control = term[ec->slot_no] ? EESOX_TERM_ENABLE : 0;
writeb(info->control, info->ctl_port);
ec->irqaddr = (unsigned char *)ioaddr(host->io_port + EESOX_STATUS); ec->irqaddr = base + EESOX_DMASTAT;
ec->irqmask = EESOX_STAT_INTR; ec->irqmask = EESOX_STAT_INTR;
ec->irq_data = info; ec->irq_data = info;
ec->ops = (expansioncard_ops_t *)&eesoxscsi_ops; ec->ops = &eesoxscsi_ops;
info->info.scsi.io_port = host->io_port + EESOX_FAS216_OFFSET; info->info.scsi.io_base = base + EESOX_FAS216_OFFSET;
info->info.scsi.io_shift = EESOX_FAS216_SHIFT; info->info.scsi.io_shift = EESOX_FAS216_SHIFT;
info->info.scsi.irq = host->irq; info->info.scsi.irq = host->irq;
info->info.ifcfg.clockrate = 40; /* MHz */ info->info.ifcfg.clockrate = 40; /* MHz */
info->info.ifcfg.select_timeout = 255; info->info.ifcfg.select_timeout = 255;
info->info.ifcfg.asyncperiod = 200; /* ns */ info->info.ifcfg.asyncperiod = 200; /* ns */
info->info.ifcfg.sync_max_depth = 7; info->info.ifcfg.sync_max_depth = 7;
info->info.ifcfg.cntl3 = CNTL3_BS8 | CNTL3_FASTSCSI | CNTL3_FASTCLK; info->info.ifcfg.cntl3 = CNTL3_FASTSCSI | CNTL3_FASTCLK;
info->info.ifcfg.disconnect_ok = 1; info->info.ifcfg.disconnect_ok = 1;
info->info.ifcfg.wide_max_size = 0; info->info.ifcfg.wide_max_size = 0;
info->info.ifcfg.capabilities = FASCAP_PSEUDODMA;
info->info.dma.setup = eesoxscsi_dma_setup; info->info.dma.setup = eesoxscsi_dma_setup;
info->info.dma.pseudo = eesoxscsi_dma_pseudo; info->info.dma.pseudo = eesoxscsi_dma_pseudo;
info->info.dma.stop = eesoxscsi_dma_stop; info->info.dma.stop = eesoxscsi_dma_stop;
info->dmaarea = host->io_port + EESOX_DMA_OFFSET;
ret = request_irq(host->irq, eesoxscsi_intr, device_create_file(&ec->dev, &dev_attr_bus_term);
SA_INTERRUPT, "eesox", host);
ret = fas216_init(host);
if (ret)
goto out_free;
ret = request_irq(host->irq, eesoxscsi_intr, 0, "eesoxscsi", info);
if (ret) { if (ret) {
printk("scsi%d: IRQ%d not free: %d\n", printk("scsi%d: IRQ%d not free: %d\n",
host->host_no, host->irq, ret); host->host_no, host->irq, ret);
goto out_region; goto out_remove;
} }
if (host->dma_channel != NO_DMA) { if (host->dma_channel != NO_DMA) {
...@@ -500,24 +613,32 @@ eesoxscsi_probe(struct expansion_card *ec, const struct ecard_id *id) ...@@ -500,24 +613,32 @@ eesoxscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
host->dma_channel = NO_DMA; host->dma_channel = NO_DMA;
} else { } else {
set_dma_speed(host->dma_channel, 180); set_dma_speed(host->dma_channel, 180);
info->info.ifcfg.capabilities |= FASCAP_DMA;
info->info.ifcfg.cntl3 |= CNTL3_BS8;
} }
} }
fas216_init(host); ret = fas216_add(host, &ec->dev);
ret = scsi_add_host(host, &ec->dev);
if (ret == 0) if (ret == 0)
goto out; goto out;
fas216_release(host);
if (host->dma_channel != NO_DMA) if (host->dma_channel != NO_DMA)
free_dma(host->dma_channel); free_dma(host->dma_channel);
free_irq(host->irq, host); free_irq(host->irq, host);
out_region:
release_region(host->io_port + EESOX_FAS216_OFFSET, out_remove:
EESOX_FAS216_SIZE); fas216_remove(host);
out_free: out_free:
device_remove_file(&ec->dev, &dev_attr_bus_term);
scsi_unregister(host); scsi_unregister(host);
out_unmap:
iounmap(base);
out_region:
release_mem_region(resbase, reslen);
out: out:
return ret; return ret;
} }
...@@ -525,15 +646,26 @@ eesoxscsi_probe(struct expansion_card *ec, const struct ecard_id *id) ...@@ -525,15 +646,26 @@ eesoxscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
static void __devexit eesoxscsi_remove(struct expansion_card *ec) static void __devexit eesoxscsi_remove(struct expansion_card *ec)
{ {
struct Scsi_Host *host = ecard_get_drvdata(ec); struct Scsi_Host *host = ecard_get_drvdata(ec);
struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
unsigned long resbase, reslen;
ecard_set_drvdata(ec, NULL); ecard_set_drvdata(ec, NULL);
scsi_remove_host(host); fas216_remove(host);
fas216_release(host);
if (host->dma_channel != NO_DMA) if (host->dma_channel != NO_DMA)
free_dma(host->dma_channel); free_dma(host->dma_channel);
free_irq(host->irq, host); free_irq(host->irq, info);
release_region(host->io_port + EESOX_FAS216_OFFSET, EESOX_FAS216_SIZE);
device_remove_file(&ec->dev, &dev_attr_bus_term);
iounmap((void *)host->base);
resbase = ecard_resource_start(ec, ECARD_RES_IOCFAST);
reslen = ecard_resource_len(ec, ECARD_RES_IOCFAST);
release_mem_region(resbase, reslen);
fas216_release(host);
scsi_unregister(host); scsi_unregister(host);
} }
...@@ -547,7 +679,8 @@ static struct ecard_driver eesoxscsi_driver = { ...@@ -547,7 +679,8 @@ static struct ecard_driver eesoxscsi_driver = {
.remove = __devexit_p(eesoxscsi_remove), .remove = __devexit_p(eesoxscsi_remove),
.id_table = eesoxscsi_cids, .id_table = eesoxscsi_cids,
.drv = { .drv = {
.name = "eesoxscsi", .devclass = &shost_devclass,
.name = "eesoxscsi",
}, },
}; };
......
/* /*
* linux/drivers/acorn/scsi/fas216.c * linux/drivers/acorn/scsi/fas216.c
* *
* Copyright (C) 1997-2000 Russell King * Copyright (C) 1997-2003 Russell King
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* Based on information in qlogicfas.c by Tom Zerucha, Michael Griffith, and * Based on information in qlogicfas.c by Tom Zerucha, Michael Griffith, and
* other sources, including: * other sources, including:
* the AMD Am53CF94 data sheet * the AMD Am53CF94 data sheet
* the AMD Am53C94 data sheet * the AMD Am53C94 data sheet
* *
* This is a generic driver. To use it, have a look at cumana_2.c. You * This is a generic driver. To use it, have a look at cumana_2.c. You
* should define your own structure that overlays FAS216_Info, eg: * should define your own structure that overlays FAS216_Info, eg:
...@@ -33,9 +33,6 @@ ...@@ -33,9 +33,6 @@
* 02-04-2000 RMK Converted to use the new error handling, and * 02-04-2000 RMK Converted to use the new error handling, and
* automatically request sense data upon check * automatically request sense data upon check
* condition status from targets. * condition status from targets.
*
* Todo:
* - allow individual devices to enable sync xfers.
*/ */
#include <linux/module.h> #include <linux/module.h>
#include <linux/blk.h> #include <linux/blk.h>
...@@ -45,6 +42,7 @@ ...@@ -45,6 +42,7 @@
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/bitops.h>
#include <linux/init.h> #include <linux/init.h>
#include <asm/dma.h> #include <asm/dma.h>
...@@ -52,17 +50,11 @@ ...@@ -52,17 +50,11 @@
#include <asm/irq.h> #include <asm/irq.h>
#include <asm/ecard.h> #include <asm/ecard.h>
#define FAS216_C
#include "../../scsi/scsi.h" #include "../../scsi/scsi.h"
#include "../../scsi/hosts.h" #include "../../scsi/hosts.h"
#include "fas216.h" #include "fas216.h"
#include "scsi.h" #include "scsi.h"
#define VER_MAJOR 0
#define VER_MINOR 0
#define VER_PATCH 5
/* NOTE: SCSI2 Synchronous transfers *require* DMA according to /* NOTE: SCSI2 Synchronous transfers *require* DMA according to
* the data sheet. This restriction is crazy, especially when * the data sheet. This restriction is crazy, especially when
* you only want to send 16 bytes! What were the guys who * you only want to send 16 bytes! What were the guys who
...@@ -104,22 +96,43 @@ ...@@ -104,22 +96,43 @@
static int level_mask = LOG_ERROR; static int level_mask = LOG_ERROR;
static inline unsigned char fas216_readb(FAS216_Info *info, unsigned int reg)
{
unsigned int off = reg << info->scsi.io_shift;
if (info->scsi.io_base)
return readb(info->scsi.io_base + off);
else
return inb(info->scsi.io_port + off);
}
static inline void fas216_writeb(FAS216_Info *info, unsigned int reg, unsigned int val)
{
unsigned int off = reg << info->scsi.io_shift;
if (info->scsi.io_base)
writeb(val, info->scsi.io_base + off);
else
outb(val, info->scsi.io_port + off);
}
static void fas216_dumpstate(FAS216_Info *info) static void fas216_dumpstate(FAS216_Info *info)
{ {
unsigned char is, stat, inst; unsigned char is, stat, inst;
is = inb(REG_IS(info)); is = fas216_readb(info, REG_IS);
stat = inb(REG_STAT(info)); stat = fas216_readb(info, REG_STAT);
inst = inb(REG_INST(info)); inst = fas216_readb(info, REG_INST);
printk("FAS216: CTCL=%02X CTCM=%02X CMD=%02X STAT=%02X" printk("FAS216: CTCL=%02X CTCM=%02X CMD=%02X STAT=%02X"
" INST=%02X IS=%02X CFIS=%02X", " INST=%02X IS=%02X CFIS=%02X",
inb(REG_CTCL(info)), inb(REG_CTCM(info)), fas216_readb(info, REG_CTCL),
inb(REG_CMD(info)), stat, inst, is, fas216_readb(info, REG_CTCM),
inb(REG_CFIS(info))); fas216_readb(info, REG_CMD), stat, inst, is,
fas216_readb(info, REG_CFIS));
printk(" CNTL1=%02X CNTL2=%02X CNTL3=%02X CTCH=%02X\n", printk(" CNTL1=%02X CNTL2=%02X CNTL3=%02X CTCH=%02X\n",
inb(REG_CNTL1(info)), inb(REG_CNTL2(info)), fas216_readb(info, REG_CNTL1),
inb(REG_CNTL3(info)), inb(REG_CTCH(info))); fas216_readb(info, REG_CNTL2),
fas216_readb(info, REG_CNTL3),
fas216_readb(info, REG_CTCH));
} }
static void print_SCp(Scsi_Pointer *SCp, const char *prefix, const char *suffix) static void print_SCp(Scsi_Pointer *SCp, const char *prefix, const char *suffix)
...@@ -236,19 +249,63 @@ static char fas216_target(FAS216_Info *info) ...@@ -236,19 +249,63 @@ static char fas216_target(FAS216_Info *info)
return 'H'; return 'H';
} }
static void
fas216_do_log(FAS216_Info *info, char target, char *fmt, va_list ap)
{
static char buf[1024];
vsnprintf(buf, sizeof(buf), fmt, ap);
printk("scsi%d.%c: %s", info->host->host_no, target, buf);
}
static void
fas216_log_command(FAS216_Info *info, int level, Scsi_Cmnd *SCpnt, char *fmt, ...)
{
va_list args;
if (level != 0 && !(level & level_mask))
return;
va_start(args, fmt);
fas216_do_log(info, '0' + SCpnt->target, fmt, args);
va_end(args);
printk(" CDB: ");
print_command(SCpnt->cmnd);
}
static void
fas216_log_target(FAS216_Info *info, int level, int target, char *fmt, ...)
{
va_list args;
if (level != 0 && !(level & level_mask))
return;
if (target < 0)
target = 'H';
else
target += '0';
va_start(args, fmt);
fas216_do_log(info, target, fmt, args);
va_end(args);
printk("\n");
}
static void fas216_log(FAS216_Info *info, int level, char *fmt, ...) static void fas216_log(FAS216_Info *info, int level, char *fmt, ...)
{ {
va_list args; va_list args;
static char buf[1024];
if (level != 0 && !(level & level_mask)) if (level != 0 && !(level & level_mask))
return; return;
va_start(args, fmt); va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args); fas216_do_log(info, fas216_target(info), fmt, args);
va_end(args); va_end(args);
printk("scsi%d.%c: %s\n", info->host->host_no, fas216_target(info), buf); printk("\n");
} }
#define PH_SIZE 32 #define PH_SIZE 32
...@@ -276,7 +333,7 @@ static void fas216_cmd(FAS216_Info *info, unsigned int command) ...@@ -276,7 +333,7 @@ static void fas216_cmd(FAS216_Info *info, unsigned int command)
cmd_ptr = (cmd_ptr + 1) & 7; cmd_ptr = (cmd_ptr + 1) & 7;
outb(command, REG_CMD(info)); fas216_writeb(info, REG_CMD, command);
} }
static void print_debug_list(void) static void print_debug_list(void)
...@@ -308,11 +365,11 @@ static void print_debug_list(void) ...@@ -308,11 +365,11 @@ static void print_debug_list(void)
static void fas216_done(FAS216_Info *info, unsigned int result); static void fas216_done(FAS216_Info *info, unsigned int result);
/** /**
* fast216_clockrate - calculate clock conversion factor * fas216_clockrate - calculate clock conversion factor
* @clock: clock speed in MHz * @clock: clock speed in MHz
* *
* Calculate correct value to be written into clock conversion factor * Calculate correct value to be written into clock conversion factor
* register. Returns CLKF_ value. * register. Returns CLKF_ value.
*/ */
static int fas216_clockrate(int clock) static int fas216_clockrate(int clock)
...@@ -327,11 +384,11 @@ static int fas216_clockrate(int clock) ...@@ -327,11 +384,11 @@ static int fas216_clockrate(int clock)
return clock; return clock;
} }
/** /**
* fas216_get_last_msg - retrive last message from the list * fas216_get_last_msg - retrive last message from the list
* @info: interface to search * @info: interface to search
* @pos: current fifo position * @pos: current fifo position
* *
* Retrieve a last message from the list, using position in fifo. * Retrieve a last message from the list, using position in fifo.
*/ */
static inline unsigned short static inline unsigned short
...@@ -359,12 +416,12 @@ fas216_get_last_msg(FAS216_Info *info, int pos) ...@@ -359,12 +416,12 @@ fas216_get_last_msg(FAS216_Info *info, int pos)
return packed_msg; return packed_msg;
} }
/** /**
* fas216_syncperiod - calculate STP register value * fas216_syncperiod - calculate STP register value
* @info: state structure for interface connected to device * @info: state structure for interface connected to device
* @ns: period in ns (between subsequent bytes) * @ns: period in ns (between subsequent bytes)
* *
* Calculate value to be loaded into the STP register for a given period * Calculate value to be loaded into the STP register for a given period
* in ns. Returns a value suitable for REG_STP. * in ns. Returns a value suitable for REG_STP.
*/ */
static int fas216_syncperiod(FAS216_Info *info, int ns) static int fas216_syncperiod(FAS216_Info *info, int ns)
...@@ -381,11 +438,11 @@ static int fas216_syncperiod(FAS216_Info *info, int ns) ...@@ -381,11 +438,11 @@ static int fas216_syncperiod(FAS216_Info *info, int ns)
return value & 31; return value & 31;
} }
/** /**
* fas216_set_sync - setup FAS216 chip for specified transfer period. * fas216_set_sync - setup FAS216 chip for specified transfer period.
* @info: state structure for interface connected to device * @info: state structure for interface connected to device
* @target: target * @target: target
* *
* Correctly setup FAS216 chip for specified transfer period. * Correctly setup FAS216 chip for specified transfer period.
* Notes : we need to switch the chip out of FASTSCSI mode if we have * Notes : we need to switch the chip out of FASTSCSI mode if we have
* a transfer period >= 200ns - otherwise the chip will violate * a transfer period >= 200ns - otherwise the chip will violate
...@@ -393,12 +450,16 @@ static int fas216_syncperiod(FAS216_Info *info, int ns) ...@@ -393,12 +450,16 @@ static int fas216_syncperiod(FAS216_Info *info, int ns)
*/ */
static void fas216_set_sync(FAS216_Info *info, int target) static void fas216_set_sync(FAS216_Info *info, int target)
{ {
outb(info->device[target].sof, REG_SOF(info)); unsigned int cntl3;
outb(info->device[target].stp, REG_STP(info));
fas216_writeb(info, REG_SOF, info->device[target].sof);
fas216_writeb(info, REG_STP, info->device[target].stp);
cntl3 = info->scsi.cfg[2];
if (info->device[target].period >= (200 / 4)) if (info->device[target].period >= (200 / 4))
outb(info->scsi.cfg[2] & ~CNTL3_FASTSCSI, REG_CNTL3(info)); cntl3 = cntl3 & ~CNTL3_FASTSCSI;
else
outb(info->scsi.cfg[2], REG_CNTL3(info)); fas216_writeb(info, REG_CNTL3, cntl3);
} }
/* Synchronous transfer support /* Synchronous transfer support
...@@ -428,8 +489,8 @@ static void fas216_set_sync(FAS216_Info *info, int target) ...@@ -428,8 +489,8 @@ static void fas216_set_sync(FAS216_Info *info, int target)
/** /**
* fas216_handlesync - Handle a synchronous transfer message * fas216_handlesync - Handle a synchronous transfer message
* @info: state structure for interface * @info: state structure for interface
* @ms: message from target * @msg: message from target
* *
* Handle a synchronous transfer message from the target * Handle a synchronous transfer message from the target
*/ */
static void fas216_handlesync(FAS216_Info *info, char *msg) static void fas216_handlesync(FAS216_Info *info, char *msg)
...@@ -538,11 +599,11 @@ static void fas216_handlesync(FAS216_Info *info, char *msg) ...@@ -538,11 +599,11 @@ static void fas216_handlesync(FAS216_Info *info, char *msg)
} }
} }
/** /**
* fas216_handlewide - Handle a wide transfer message * fas216_handlewide - Handle a wide transfer message
* @info: state structure for interface * @info: state structure for interface
* @msg: message from target * @msg: message from target
* *
* Handle a wide transfer message from the target * Handle a wide transfer message from the target
*/ */
static void fas216_handlewide(FAS216_Info *info, char *msg) static void fas216_handlewide(FAS216_Info *info, char *msg)
...@@ -637,11 +698,11 @@ static void fas216_handlewide(FAS216_Info *info, char *msg) ...@@ -637,11 +698,11 @@ static void fas216_handlewide(FAS216_Info *info, char *msg)
} }
} }
/** /**
* fas216_updateptrs - update data pointers after transfer suspended/paused * fas216_updateptrs - update data pointers after transfer suspended/paused
* @info: interface's local pointer to update * @info: interface's local pointer to update
* @bytes_transferred: number of bytes transferred * @bytes_transferred: number of bytes transferred
* *
* Update data pointers after transfer suspended/paused * Update data pointers after transfer suspended/paused
*/ */
static void fas216_updateptrs(FAS216_Info *info, int bytes_transferred) static void fas216_updateptrs(FAS216_Info *info, int bytes_transferred)
...@@ -662,7 +723,7 @@ static void fas216_updateptrs(FAS216_Info *info, int bytes_transferred) ...@@ -662,7 +723,7 @@ static void fas216_updateptrs(FAS216_Info *info, int bytes_transferred)
* next buffer. * next buffer.
*/ */
bytes_transferred -= SCp->this_residual; bytes_transferred -= SCp->this_residual;
if (!next_SCp(&info->scsi.SCp) && bytes_transferred) { if (!next_SCp(SCp) && bytes_transferred) {
printk(KERN_WARNING "scsi%d.%c: out of buffers\n", printk(KERN_WARNING "scsi%d.%c: out of buffers\n",
info->host->host_no, '0' + info->SCpnt->target); info->host->host_no, '0' + info->SCpnt->target);
return; return;
...@@ -680,33 +741,67 @@ static void fas216_updateptrs(FAS216_Info *info, int bytes_transferred) ...@@ -680,33 +741,67 @@ static void fas216_updateptrs(FAS216_Info *info, int bytes_transferred)
* fas216_pio - transfer data off of/on to card using programmed IO * fas216_pio - transfer data off of/on to card using programmed IO
* @info: interface to transfer data to/from * @info: interface to transfer data to/from
* @direction: direction to transfer data (DMA_OUT/DMA_IN) * @direction: direction to transfer data (DMA_OUT/DMA_IN)
* *
* Transfer data off of/on to card using programmed IO. * Transfer data off of/on to card using programmed IO.
* Notes: this is incredibly slow. * Notes: this is incredibly slow.
*/ */
static void fas216_pio(FAS216_Info *info, fasdmadir_t direction) static void fas216_pio(FAS216_Info *info, fasdmadir_t direction)
{ {
Scsi_Pointer *SCp = &info->scsi.SCp;
fas216_checkmagic(info); fas216_checkmagic(info);
if (direction == DMA_OUT) if (direction == DMA_OUT)
outb(get_next_SCp_byte(&info->scsi.SCp), REG_FF(info)); fas216_writeb(info, REG_FF, get_next_SCp_byte(SCp));
else else
put_next_SCp_byte(&info->scsi.SCp, inb(REG_FF(info))); put_next_SCp_byte(SCp, fas216_readb(info, REG_FF));
if (SCp->this_residual == 0)
next_SCp(SCp);
}
static void fas216_set_stc(FAS216_Info *info, unsigned int length)
{
fas216_writeb(info, REG_STCL, length);
fas216_writeb(info, REG_STCM, length >> 8);
fas216_writeb(info, REG_STCH, length >> 16);
}
static unsigned int fas216_get_ctc(FAS216_Info *info)
{
return fas216_readb(info, REG_CTCL) +
(fas216_readb(info, REG_CTCM) << 8) +
(fas216_readb(info, REG_CTCH) << 16);
} }
/**
* fas216_cleanuptransfer - clean up after a transfer has completed.
* @info: interface to clean up
*
* Update the data pointers according to the number of bytes transferred
* on the SCSI bus.
*/
static void fas216_cleanuptransfer(FAS216_Info *info) static void fas216_cleanuptransfer(FAS216_Info *info)
{ {
unsigned long total, residual, fifo; unsigned long total, residual, fifo;
fasdmatype_t dmatype = info->dma.transfer_type;
info->dma.transfer_type = fasdma_none;
if (info->dma.transfer_type == fasdma_real_all) /*
* PIO transfers do not need to be cleaned up.
*/
if (dmatype == fasdma_pio || dmatype == fasdma_none)
return;
if (dmatype == fasdma_real_all)
total = info->SCpnt->request_bufflen; total = info->SCpnt->request_bufflen;
else else
total = info->scsi.SCp.this_residual; total = info->scsi.SCp.this_residual;
residual = inb(REG_CTCL(info)) + (inb(REG_CTCM(info)) << 8) + residual = fas216_get_ctc(info);
(inb(REG_CTCH(info)) << 16);
fifo = inb(REG_CFIS(info)) & CFIS_CF; fifo = fas216_readb(info, REG_CFIS) & CFIS_CF;
fas216_log(info, LOG_BUFFER, "cleaning up from previous " fas216_log(info, LOG_BUFFER, "cleaning up from previous "
"transfer: length 0x%06x, residual 0x%x, fifo %d", "transfer: length 0x%06x, residual 0x%x, fifo %d",
...@@ -718,54 +813,22 @@ static void fas216_cleanuptransfer(FAS216_Info *info) ...@@ -718,54 +813,22 @@ static void fas216_cleanuptransfer(FAS216_Info *info)
* host to the FIFO. This means we must include the * host to the FIFO. This means we must include the
* bytes left in the FIFO from the transfer counter. * bytes left in the FIFO from the transfer counter.
*/ */
if (info->scsi.phase == PHASE_DATAOUT) { if (info->scsi.phase == PHASE_DATAOUT)
residual += fifo; residual += fifo;
fifo = 0;
}
if (info->dma.transfer_type != fasdma_none &&
info->dma.transfer_type != fasdma_pio) {
fas216_updateptrs(info, total - residual);
}
/*
* If we were performing Data-In, then the FIFO counter
* contains the number of bytes not transferred via DMA
* from the on-board FIFO. Read them manually.
*/
if (info->scsi.phase == PHASE_DATAIN) {
while (fifo && info->scsi.SCp.ptr) {
*info->scsi.SCp.ptr = inb(REG_FF(info));
fas216_updateptrs(info, 1);
fifo--;
}
}
info->dma.transfer_type = fasdma_none; fas216_updateptrs(info, total - residual);
} }
/** /**
* fas216_starttransfer - Start a DMA/PIO transfer off of/on to card * fas216_transfer - Perform a DMA/PIO transfer off of/on to card
* @info: interface from which device disconnected from * @info: interface from which device disconnected from
* @direction: transfer direction (DMA_OUT/DMA_IN) *
*
* Start a DMA/PIO transfer off of/on to card * Start a DMA/PIO transfer off of/on to card
*/ */
static void fas216_starttransfer(FAS216_Info *info, fasdmadir_t direction) static void fas216_transfer(FAS216_Info *info)
{ {
fasdmadir_t direction;
fasdmatype_t dmatype; fasdmatype_t dmatype;
int phase = (direction == DMA_OUT) ? PHASE_DATAOUT : PHASE_DATAIN;
fas216_checkmagic(info);
if (phase != info->scsi.phase) {
info->scsi.phase = phase;
if (direction == DMA_OUT)
fas216_cmd(info, CMD_FLUSHFIFO);
} else {
fas216_cleanuptransfer(info);
}
fas216_log(info, LOG_BUFFER, fas216_log(info, LOG_BUFFER,
"starttransfer: buffer %p length 0x%06x reqlen 0x%06x", "starttransfer: buffer %p length 0x%06x reqlen 0x%06x",
...@@ -781,36 +844,41 @@ static void fas216_starttransfer(FAS216_Info *info, fasdmadir_t direction) ...@@ -781,36 +844,41 @@ static void fas216_starttransfer(FAS216_Info *info, fasdmadir_t direction)
} }
/* /*
* Default to PIO mode or DMA mode if we have * If we have a synchronous transfer agreement in effect, we must
* a synchronous transfer agreement. * use DMA mode. If we are using asynchronous transfers, we may
* use DMA mode or PIO mode.
*/ */
if (info->device[info->SCpnt->target].sof && info->dma.setup) if (info->device[info->SCpnt->target].sof)
dmatype = fasdma_real_all; dmatype = fasdma_real_all;
else else
dmatype = fasdma_pio; dmatype = fasdma_pio;
if (info->scsi.phase == PHASE_DATAOUT)
direction = DMA_OUT;
else
direction = DMA_IN;
if (info->dma.setup) if (info->dma.setup)
dmatype = info->dma.setup(info->host, &info->scsi.SCp, dmatype = info->dma.setup(info->host, &info->scsi.SCp,
direction, dmatype); direction, dmatype);
info->dma.transfer_type = dmatype; info->dma.transfer_type = dmatype;
if (dmatype == fasdma_real_all)
fas216_set_stc(info, info->SCpnt->request_bufflen);
else
fas216_set_stc(info, info->scsi.SCp.this_residual);
switch (dmatype) { switch (dmatype) {
case fasdma_pio: case fasdma_pio:
fas216_log(info, LOG_BUFFER, "PIO transfer"); fas216_log(info, LOG_BUFFER, "PIO transfer");
outb(0, REG_SOF(info)); fas216_writeb(info, REG_SOF, 0);
outb(info->scsi.async_stp, REG_STP(info)); fas216_writeb(info, REG_STP, info->scsi.async_stp);
outb(info->scsi.SCp.this_residual, REG_STCL(info));
outb(info->scsi.SCp.this_residual >> 8, REG_STCM(info));
outb(info->scsi.SCp.this_residual >> 16, REG_STCH(info));
fas216_cmd(info, CMD_TRANSFERINFO); fas216_cmd(info, CMD_TRANSFERINFO);
fas216_pio(info, direction); fas216_pio(info, direction);
break; break;
case fasdma_pseudo: case fasdma_pseudo:
fas216_log(info, LOG_BUFFER, "pseudo transfer"); fas216_log(info, LOG_BUFFER, "pseudo transfer");
outb(info->scsi.SCp.this_residual, REG_STCL(info));
outb(info->scsi.SCp.this_residual >> 8, REG_STCM(info));
outb(info->scsi.SCp.this_residual >> 16, REG_STCH(info));
fas216_cmd(info, CMD_TRANSFERINFO | CMD_WITHDMA); fas216_cmd(info, CMD_TRANSFERINFO | CMD_WITHDMA);
info->dma.pseudo(info->host, &info->scsi.SCp, info->dma.pseudo(info->host, &info->scsi.SCp,
direction, info->SCpnt->transfersize); direction, info->SCpnt->transfersize);
...@@ -818,17 +886,11 @@ static void fas216_starttransfer(FAS216_Info *info, fasdmadir_t direction) ...@@ -818,17 +886,11 @@ static void fas216_starttransfer(FAS216_Info *info, fasdmadir_t direction)
case fasdma_real_block: case fasdma_real_block:
fas216_log(info, LOG_BUFFER, "block dma transfer"); fas216_log(info, LOG_BUFFER, "block dma transfer");
outb(info->scsi.SCp.this_residual, REG_STCL(info));
outb(info->scsi.SCp.this_residual >> 8, REG_STCM(info));
outb(info->scsi.SCp.this_residual >> 16, REG_STCH(info));
fas216_cmd(info, CMD_TRANSFERINFO | CMD_WITHDMA); fas216_cmd(info, CMD_TRANSFERINFO | CMD_WITHDMA);
break; break;
case fasdma_real_all: case fasdma_real_all:
fas216_log(info, LOG_BUFFER, "total dma transfer"); fas216_log(info, LOG_BUFFER, "total dma transfer");
outb(info->SCpnt->request_bufflen, REG_STCL(info));
outb(info->SCpnt->request_bufflen >> 8, REG_STCM(info));
outb(info->SCpnt->request_bufflen >> 16, REG_STCH(info));
fas216_cmd(info, CMD_TRANSFERINFO | CMD_WITHDMA); fas216_cmd(info, CMD_TRANSFERINFO | CMD_WITHDMA);
break; break;
...@@ -839,44 +901,61 @@ static void fas216_starttransfer(FAS216_Info *info, fasdmadir_t direction) ...@@ -839,44 +901,61 @@ static void fas216_starttransfer(FAS216_Info *info, fasdmadir_t direction)
} }
} }
/** /**
* fas216_stoptransfer - Stop a DMA transfer onto / off of the card * fas216_stoptransfer - Stop a DMA transfer onto / off of the card
* @info: interface from which device disconnected from * @info: interface from which device disconnected from
* *
* Stop a DMA transfer onto / off of the card * Called when we switch away from DATA IN or DATA OUT phases.
*/ */
static void fas216_stoptransfer(FAS216_Info *info) static void fas216_stoptransfer(FAS216_Info *info)
{ {
fas216_checkmagic(info); fas216_checkmagic(info);
if ((info->dma.transfer_type == fasdma_real_all || if (info->dma.transfer_type == fasdma_real_all ||
info->dma.transfer_type == fasdma_real_block) && info->dma.transfer_type == fasdma_real_block)
info->dma.stop)
info->dma.stop(info->host, &info->scsi.SCp); info->dma.stop(info->host, &info->scsi.SCp);
fas216_cleanuptransfer(info); fas216_cleanuptransfer(info);
if (info->scsi.phase == PHASE_DATAOUT) if (info->scsi.phase == PHASE_DATAIN) {
unsigned int fifo;
/*
* If we were performing Data-In, then the FIFO counter
* contains the number of bytes not transferred via DMA
* from the on-board FIFO. Read them manually.
*/
fifo = fas216_readb(info, REG_CFIS) & CFIS_CF;
while (fifo && info->scsi.SCp.ptr) {
*info->scsi.SCp.ptr = fas216_readb(info, REG_FF);
fas216_updateptrs(info, 1);
fifo--;
}
} else {
/*
* After a Data-Out phase, there may be unsent
* bytes left in the FIFO. Flush them out.
*/
fas216_cmd(info, CMD_FLUSHFIFO); fas216_cmd(info, CMD_FLUSHFIFO);
}
} }
static void fas216_aborttransfer(FAS216_Info *info) static void fas216_aborttransfer(FAS216_Info *info)
{ {
fas216_checkmagic(info); fas216_checkmagic(info);
if ((info->dma.transfer_type == fasdma_real_all || if (info->dma.transfer_type == fasdma_real_all ||
info->dma.transfer_type == fasdma_real_block) && info->dma.transfer_type == fasdma_real_block)
info->dma.stop)
info->dma.stop(info->host, &info->scsi.SCp); info->dma.stop(info->host, &info->scsi.SCp);
info->dma.transfer_type = fasdma_none; info->dma.transfer_type = fasdma_none;
fas216_cmd(info, CMD_FLUSHFIFO); fas216_cmd(info, CMD_FLUSHFIFO);
} }
/** /**
* fas216_disconnected_intr - handle device disconnection * fas216_disconnected_intr - handle device disconnection
* @info: interface from which device disconnected from * @info: interface from which device disconnected from
* *
* Handle device disconnection * Handle device disconnection
*/ */
static void fas216_disconnect_intr(FAS216_Info *info) static void fas216_disconnect_intr(FAS216_Info *info)
...@@ -924,10 +1003,10 @@ static void fas216_disconnect_intr(FAS216_Info *info) ...@@ -924,10 +1003,10 @@ static void fas216_disconnect_intr(FAS216_Info *info)
} }
} }
/** /**
* fas216_reselected_intr - start reconnection of a device * fas216_reselected_intr - start reconnection of a device
* @info: interface which was reselected * @info: interface which was reselected
* *
* Start reconnection of a device * Start reconnection of a device
*/ */
static void static void
...@@ -952,19 +1031,14 @@ fas216_reselected_intr(FAS216_Info *info) ...@@ -952,19 +1031,14 @@ fas216_reselected_intr(FAS216_Info *info)
fas216_log(info, LOG_CONNECT, "reconnect phase=%02X", info->scsi.phase); fas216_log(info, LOG_CONNECT, "reconnect phase=%02X", info->scsi.phase);
if ((inb(REG_CFIS(info)) & CFIS_CF) != 2) { if ((fas216_readb(info, REG_CFIS) & CFIS_CF) != 2) {
printk(KERN_ERR "scsi%d.H: incorrect number of bytes after reselect\n", printk(KERN_ERR "scsi%d.H: incorrect number of bytes after reselect\n",
info->host->host_no); info->host->host_no);
fas216_cmd(info, CMD_SETATN); goto initiator_error;
msgqueue_flush(&info->scsi.msgs);
msgqueue_addmsg(&info->scsi.msgs, 1, INITIATOR_ERROR);
info->scsi.phase = PHASE_MSGOUT_EXPECT;
fas216_cmd(info, CMD_MSGACCEPTED);
return;
} }
target = inb(REG_FF(info)); target = fas216_readb(info, REG_FF);
identify_msg = inb(REG_FF(info)); identify_msg = fas216_readb(info, REG_FF);
ok = 1; ok = 1;
if (!(target & (1 << info->host->this_id))) { if (!(target & (1 << info->host->this_id))) {
...@@ -983,26 +1057,11 @@ fas216_reselected_intr(FAS216_Info *info) ...@@ -983,26 +1057,11 @@ fas216_reselected_intr(FAS216_Info *info)
* Something went wrong - send an initiator error to * Something went wrong - send an initiator error to
* the target. * the target.
*/ */
fas216_cmd(info, CMD_SETATN); goto initiator_error;
msgqueue_flush(&info->scsi.msgs);
msgqueue_addmsg(&info->scsi.msgs, 1, INITIATOR_ERROR);
info->scsi.phase = PHASE_MSGOUT_EXPECT;
fas216_cmd(info, CMD_MSGACCEPTED);
return;
} }
target &= ~(1 << info->host->this_id); target &= ~(1 << info->host->this_id);
switch (target) { target = ffs(target) - 1;
case 1: target = 0; break;
case 2: target = 1; break;
case 4: target = 2; break;
case 8: target = 3; break;
case 16: target = 4; break;
case 32: target = 5; break;
case 64: target = 6; break;
case 128: target = 7; break;
default: target = info->host->this_id; break;
}
identify_msg &= 7; identify_msg &= 7;
info->scsi.reconnected.target = target; info->scsi.reconnected.target = target;
...@@ -1023,7 +1082,7 @@ fas216_reselected_intr(FAS216_Info *info) ...@@ -1023,7 +1082,7 @@ fas216_reselected_intr(FAS216_Info *info)
msgqueue_flush(&info->scsi.msgs); msgqueue_flush(&info->scsi.msgs);
if (ok) { if (ok) {
info->scsi.phase = PHASE_RECONNECTED; info->scsi.phase = PHASE_RECONNECTED;
outb(target, REG_SDID(info)); fas216_writeb(info, REG_SDID, target);
} else { } else {
/* /*
* Our command structure not found - abort the * Our command structure not found - abort the
...@@ -1037,9 +1096,17 @@ fas216_reselected_intr(FAS216_Info *info) ...@@ -1037,9 +1096,17 @@ fas216_reselected_intr(FAS216_Info *info)
} }
fas216_cmd(info, CMD_MSGACCEPTED); fas216_cmd(info, CMD_MSGACCEPTED);
return;
initiator_error:
fas216_cmd(info, CMD_SETATN);
msgqueue_flush(&info->scsi.msgs);
msgqueue_addmsg(&info->scsi.msgs, 1, INITIATOR_ERROR);
info->scsi.phase = PHASE_MSGOUT_EXPECT;
fas216_cmd(info, CMD_MSGACCEPTED);
} }
/** /**
* fas216_finish_reconnect - finish reconnection sequence for device * fas216_finish_reconnect - finish reconnection sequence for device
* @info: interface which caused function done interrupt * @info: interface which caused function done interrupt
* *
...@@ -1232,7 +1299,7 @@ static int fas216_wait_cmd(FAS216_Info *info, int cmd) ...@@ -1232,7 +1299,7 @@ static int fas216_wait_cmd(FAS216_Info *info, int cmd)
fas216_cmd(info, cmd); fas216_cmd(info, cmd);
for (tout = 1000; tout; tout -= 1) { for (tout = 1000; tout; tout -= 1) {
stat = inb(REG_STAT(info)); stat = fas216_readb(info, REG_STAT);
if (stat & (STAT_INT|STAT_PARITYERROR)) if (stat & (STAT_INT|STAT_PARITYERROR))
break; break;
udelay(1); udelay(1);
...@@ -1251,7 +1318,7 @@ static int fas216_get_msg_byte(FAS216_Info *info) ...@@ -1251,7 +1318,7 @@ static int fas216_get_msg_byte(FAS216_Info *info)
if ((stat & STAT_BUSMASK) != STAT_MESGIN) if ((stat & STAT_BUSMASK) != STAT_MESGIN)
goto unexpected_phase_change; goto unexpected_phase_change;
inb(REG_INST(info)); fas216_readb(info, REG_INST);
stat = fas216_wait_cmd(info, CMD_TRANSFERINFO); stat = fas216_wait_cmd(info, CMD_TRANSFERINFO);
...@@ -1264,9 +1331,9 @@ static int fas216_get_msg_byte(FAS216_Info *info) ...@@ -1264,9 +1331,9 @@ static int fas216_get_msg_byte(FAS216_Info *info)
if ((stat & STAT_BUSMASK) != STAT_MESGIN) if ((stat & STAT_BUSMASK) != STAT_MESGIN)
goto unexpected_phase_change; goto unexpected_phase_change;
inb(REG_INST(info)); fas216_readb(info, REG_INST);
return inb(REG_FF(info)); return fas216_readb(info, REG_FF);
timedout: timedout:
fas216_log(info, LOG_ERROR, "timed out waiting for message byte"); fas216_log(info, LOG_ERROR, "timed out waiting for message byte");
...@@ -1284,7 +1351,7 @@ static int fas216_get_msg_byte(FAS216_Info *info) ...@@ -1284,7 +1351,7 @@ static int fas216_get_msg_byte(FAS216_Info *info)
/** /**
* fas216_message - handle a function done interrupt from FAS216 chip * fas216_message - handle a function done interrupt from FAS216 chip
* @info: interface which caused function done interrupt * @info: interface which caused function done interrupt
* *
* Handle a function done interrupt from FAS216 chip * Handle a function done interrupt from FAS216 chip
*/ */
static void fas216_message(FAS216_Info *info) static void fas216_message(FAS216_Info *info)
...@@ -1295,7 +1362,7 @@ static void fas216_message(FAS216_Info *info) ...@@ -1295,7 +1362,7 @@ static void fas216_message(FAS216_Info *info)
fas216_checkmagic(info); fas216_checkmagic(info);
message[0] = inb(REG_FF(info)); message[0] = fas216_readb(info, REG_FF);
if (message[0] == EXTENDED_MESSAGE) { if (message[0] == EXTENDED_MESSAGE) {
msgbyte = fas216_get_msg_byte(info); msgbyte = fas216_get_msg_byte(info);
...@@ -1317,8 +1384,6 @@ static void fas216_message(FAS216_Info *info) ...@@ -1317,8 +1384,6 @@ static void fas216_message(FAS216_Info *info)
if (msgbyte == -3) if (msgbyte == -3)
goto parity_error; goto parity_error;
info->scsi.msglen = msglen;
#ifdef DEBUG_MESSAGES #ifdef DEBUG_MESSAGES
{ {
int i; int i;
...@@ -1354,7 +1419,7 @@ static void fas216_message(FAS216_Info *info) ...@@ -1354,7 +1419,7 @@ static void fas216_message(FAS216_Info *info)
/** /**
* fas216_send_command - send command after all message bytes have been sent * fas216_send_command - send command after all message bytes have been sent
* @info: interface which caused bus service * @info: interface which caused bus service
* *
* Send a command to a target after all message bytes have been sent * Send a command to a target after all message bytes have been sent
*/ */
static void fas216_send_command(FAS216_Info *info) static void fas216_send_command(FAS216_Info *info)
...@@ -1368,17 +1433,17 @@ static void fas216_send_command(FAS216_Info *info) ...@@ -1368,17 +1433,17 @@ static void fas216_send_command(FAS216_Info *info)
/* load command */ /* load command */
for (i = info->scsi.SCp.sent_command; i < info->SCpnt->cmd_len; i++) for (i = info->scsi.SCp.sent_command; i < info->SCpnt->cmd_len; i++)
outb(info->SCpnt->cmnd[i], REG_FF(info)); fas216_writeb(info, REG_FF, info->SCpnt->cmnd[i]);
fas216_cmd(info, CMD_TRANSFERINFO); fas216_cmd(info, CMD_TRANSFERINFO);
info->scsi.phase = PHASE_COMMAND; info->scsi.phase = PHASE_COMMAND;
} }
/** /**
* fas216_send_messageout - handle bus service to send a message * fas216_send_messageout - handle bus service to send a message
* @info: interface which caused bus service * @info: interface which caused bus service
* *
* Handle bus service to send a message. * Handle bus service to send a message.
* Note: We do not allow the device to change the data direction! * Note: We do not allow the device to change the data direction!
*/ */
...@@ -1398,25 +1463,25 @@ static void fas216_send_messageout(FAS216_Info *info, int start) ...@@ -1398,25 +1463,25 @@ static void fas216_send_messageout(FAS216_Info *info, int start)
int i; int i;
for (i = start; i < msg->length; i++) for (i = start; i < msg->length; i++)
outb(msg->msg[i], REG_FF(info)); fas216_writeb(info, REG_FF, msg->msg[i]);
msg->fifo = tot_msglen - (inb(REG_CFIS(info)) & CFIS_CF); msg->fifo = tot_msglen - (fas216_readb(info, REG_CFIS) & CFIS_CF);
start = 0; start = 0;
} }
} else } else
outb(NOP, REG_FF(info)); fas216_writeb(info, REG_FF, NOP);
fas216_cmd(info, CMD_TRANSFERINFO); fas216_cmd(info, CMD_TRANSFERINFO);
info->scsi.phase = PHASE_MSGOUT; info->scsi.phase = PHASE_MSGOUT;
} }
/** /**
* fas216_busservice_intr - handle bus service interrupt from FAS216 chip * fas216_busservice_intr - handle bus service interrupt from FAS216 chip
* @info: interface which caused bus service interrupt * @info: interface which caused bus service interrupt
* @stat: Status register contents * @stat: Status register contents
* @ssr: SCSI Status register contents * @ssr: SCSI Status register contents
* *
* Handle a bus service interrupt from FAS216 chip * Handle a bus service interrupt from FAS216 chip
*/ */
static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigned int ssr) static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigned int ssr)
...@@ -1429,7 +1494,7 @@ static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigne ...@@ -1429,7 +1494,7 @@ static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigne
switch (info->scsi.phase) { switch (info->scsi.phase) {
case PHASE_SELECTION: case PHASE_SELECTION:
if ((ssr & IS_BITS) != 1) if ((ssr & IS_BITS) != IS_MSGBYTESENT)
goto bad_is; goto bad_is;
break; break;
...@@ -1464,15 +1529,17 @@ static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigne ...@@ -1464,15 +1529,17 @@ static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigne
case STATE(STAT_DATAIN, PHASE_RECONNECTED): case STATE(STAT_DATAIN, PHASE_RECONNECTED):
fas216_finish_reconnect(info); fas216_finish_reconnect(info);
case STATE(STAT_DATAIN, PHASE_SELSTEPS):/* Sel w/ steps -> Data In */ case STATE(STAT_DATAIN, PHASE_SELSTEPS):/* Sel w/ steps -> Data In */
case STATE(STAT_DATAIN, PHASE_DATAIN): /* Data In -> Data In */
case STATE(STAT_DATAIN, PHASE_MSGOUT): /* Message Out -> Data In */ case STATE(STAT_DATAIN, PHASE_MSGOUT): /* Message Out -> Data In */
case STATE(STAT_DATAIN, PHASE_COMMAND): /* Command -> Data In */ case STATE(STAT_DATAIN, PHASE_COMMAND): /* Command -> Data In */
case STATE(STAT_DATAIN, PHASE_MSGIN): /* Message In -> Data In */ case STATE(STAT_DATAIN, PHASE_MSGIN): /* Message In -> Data In */
fas216_starttransfer(info, DMA_IN); info->scsi.phase = PHASE_DATAIN;
fas216_transfer(info);
return; return;
case STATE(STAT_DATAIN, PHASE_DATAIN): /* Data In -> Data In */
case STATE(STAT_DATAOUT, PHASE_DATAOUT):/* Data Out -> Data Out */ case STATE(STAT_DATAOUT, PHASE_DATAOUT):/* Data Out -> Data Out */
fas216_starttransfer(info, DMA_OUT); fas216_cleanuptransfer(info);
fas216_transfer(info);
return; return;
/* Reselmsgin -> Data Out */ /* Reselmsgin -> Data Out */
...@@ -1482,7 +1549,9 @@ static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigne ...@@ -1482,7 +1549,9 @@ static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigne
case STATE(STAT_DATAOUT, PHASE_MSGOUT): /* Message Out -> Data Out */ case STATE(STAT_DATAOUT, PHASE_MSGOUT): /* Message Out -> Data Out */
case STATE(STAT_DATAOUT, PHASE_COMMAND):/* Command -> Data Out */ case STATE(STAT_DATAOUT, PHASE_COMMAND):/* Command -> Data Out */
case STATE(STAT_DATAOUT, PHASE_MSGIN): /* Message In -> Data Out */ case STATE(STAT_DATAOUT, PHASE_MSGIN): /* Message In -> Data Out */
fas216_starttransfer(info, DMA_OUT); fas216_cmd(info, CMD_FLUSHFIFO);
info->scsi.phase = PHASE_DATAOUT;
fas216_transfer(info);
return; return;
/* Reselmsgin -> Status */ /* Reselmsgin -> Status */
...@@ -1507,7 +1576,7 @@ static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigne ...@@ -1507,7 +1576,7 @@ static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigne
case STATE(STAT_MESGIN, PHASE_COMMAND): /* Command -> Message In */ case STATE(STAT_MESGIN, PHASE_COMMAND): /* Command -> Message In */
case STATE(STAT_MESGIN, PHASE_SELSTEPS):/* Sel w/ steps -> Message In */ case STATE(STAT_MESGIN, PHASE_SELSTEPS):/* Sel w/ steps -> Message In */
case STATE(STAT_MESGIN, PHASE_MSGOUT): /* Message Out -> Message In */ case STATE(STAT_MESGIN, PHASE_MSGOUT): /* Message Out -> Message In */
info->scsi.msgin_fifo = inb(REG_CFIS(info)) & CFIS_CF; info->scsi.msgin_fifo = fas216_readb(info, REG_CFIS) & CFIS_CF;
fas216_cmd(info, CMD_FLUSHFIFO); fas216_cmd(info, CMD_FLUSHFIFO);
fas216_cmd(info, CMD_TRANSFERINFO); fas216_cmd(info, CMD_TRANSFERINFO);
info->scsi.phase = PHASE_MSGIN; info->scsi.phase = PHASE_MSGIN;
...@@ -1516,7 +1585,7 @@ static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigne ...@@ -1516,7 +1585,7 @@ static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigne
/* Reselmsgin -> Message In */ /* Reselmsgin -> Message In */
case STATE(STAT_MESGIN, PHASE_RECONNECTED): case STATE(STAT_MESGIN, PHASE_RECONNECTED):
case STATE(STAT_MESGIN, PHASE_MSGIN): case STATE(STAT_MESGIN, PHASE_MSGIN):
info->scsi.msgin_fifo = inb(REG_CFIS(info)) & CFIS_CF; info->scsi.msgin_fifo = fas216_readb(info, REG_CFIS) & CFIS_CF;
fas216_cmd(info, CMD_TRANSFERINFO); fas216_cmd(info, CMD_TRANSFERINFO);
return; return;
...@@ -1555,7 +1624,7 @@ static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigne ...@@ -1555,7 +1624,7 @@ static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigne
*/ */
info->device[info->SCpnt->target].parity_check = 0; info->device[info->SCpnt->target].parity_check = 0;
info->device[info->SCpnt->target].parity_enabled = 1; info->device[info->SCpnt->target].parity_enabled = 1;
outb(info->scsi.cfg[0], REG_CNTL1(info)); fas216_writeb(info, REG_CNTL1, info->scsi.cfg[0]);
} }
if (msgqueue_msglength(&info->scsi.msgs) > 1) if (msgqueue_msglength(&info->scsi.msgs) > 1)
...@@ -1584,9 +1653,7 @@ static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigne ...@@ -1584,9 +1653,7 @@ static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigne
"target trying to receive more command bytes\n", "target trying to receive more command bytes\n",
info->host->host_no, fas216_target(info)); info->host->host_no, fas216_target(info));
fas216_cmd(info, CMD_SETATN); fas216_cmd(info, CMD_SETATN);
outb(15, REG_STCL(info)); fas216_set_stc(info, 15);
outb(0, REG_STCM(info));
outb(0, REG_STCH(info));
fas216_cmd(info, CMD_PADBYTES | CMD_WITHDMA); fas216_cmd(info, CMD_PADBYTES | CMD_WITHDMA);
msgqueue_flush(&info->scsi.msgs); msgqueue_flush(&info->scsi.msgs);
msgqueue_addmsg(&info->scsi.msgs, 1, INITIATOR_ERROR); msgqueue_addmsg(&info->scsi.msgs, 1, INITIATOR_ERROR);
...@@ -1615,6 +1682,7 @@ static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigne ...@@ -1615,6 +1682,7 @@ static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigne
bad_is: bad_is:
fas216_log(info, 0, "bus service at step %d?", ssr & IS_BITS); fas216_log(info, 0, "bus service at step %d?", ssr & IS_BITS);
fas216_dumpstate(info);
print_debug_list(); print_debug_list();
fas216_done(info, DID_ERROR); fas216_done(info, DID_ERROR);
...@@ -1625,12 +1693,12 @@ static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigne ...@@ -1625,12 +1693,12 @@ static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigne
* @info: interface which caused function done interrupt * @info: interface which caused function done interrupt
* @stat: Status register contents * @stat: Status register contents
* @ssr: SCSI Status register contents * @ssr: SCSI Status register contents
* *
* Handle a function done interrupt from FAS216 chip * Handle a function done interrupt from FAS216 chip
*/ */
static void fas216_funcdone_intr(FAS216_Info *info, unsigned int stat, unsigned int ssr) static void fas216_funcdone_intr(FAS216_Info *info, unsigned int stat, unsigned int ssr)
{ {
unsigned int fifo_len = inb(REG_CFIS(info)) & CFIS_CF; unsigned int fifo_len = fas216_readb(info, REG_CFIS) & CFIS_CF;
unsigned int status, message; unsigned int status, message;
fas216_checkmagic(info); fas216_checkmagic(info);
...@@ -1644,8 +1712,8 @@ static void fas216_funcdone_intr(FAS216_Info *info, unsigned int stat, unsigned ...@@ -1644,8 +1712,8 @@ static void fas216_funcdone_intr(FAS216_Info *info, unsigned int stat, unsigned
if (fifo_len != 2) { if (fifo_len != 2) {
fas216_log(info, 0, "odd number of bytes in FIFO: %d", fifo_len); fas216_log(info, 0, "odd number of bytes in FIFO: %d", fifo_len);
} }
status = inb(REG_FF(info)); status = fas216_readb(info, REG_FF);
message = inb(REG_FF(info)); message = fas216_readb(info, REG_FF);
info->scsi.SCp.Message = message; info->scsi.SCp.Message = message;
info->scsi.SCp.Status = status; info->scsi.SCp.Status = status;
info->scsi.phase = PHASE_DONE; info->scsi.phase = PHASE_DONE;
...@@ -1679,26 +1747,21 @@ static void fas216_bus_reset(FAS216_Info *info) ...@@ -1679,26 +1747,21 @@ static void fas216_bus_reset(FAS216_Info *info)
info->scsi.reconnected.lun = 0; info->scsi.reconnected.lun = 0;
info->scsi.reconnected.tag = 0; info->scsi.reconnected.tag = 0;
if (info->ifcfg.wide_max_size == 0) wide_state = neg_invalid;
wide_state = neg_invalid; sync_state = neg_invalid;
else
#ifdef SCSI2_WIDE #ifdef SCSI2_WIDE
if (info->ifcfg.wide_max_size != 0)
wide_state = neg_wait; wide_state = neg_wait;
#else
wide_state = neg_invalid;
#endif #endif
if (info->host->dma_channel == NO_DMA || !info->dma.setup)
sync_state = neg_invalid;
else
#ifdef SCSI2_SYNC #ifdef SCSI2_SYNC
if (info->ifcfg.capabilities & (FASCAP_DMA|FASCAP_PSEUDODMA))
sync_state = neg_wait; sync_state = neg_wait;
#else
sync_state = neg_invalid;
#endif #endif
info->scsi.phase = PHASE_IDLE; info->scsi.phase = PHASE_IDLE;
info->SCpnt = NULL; /* bug! */ info->SCpnt = NULL; /* bug! */
memset(&info->scsi.SCp, 0, sizeof(info->scsi.SCp));
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
info->device[i].disconnect_ok = info->ifcfg.disconnect_ok; info->device[i].disconnect_ok = info->ifcfg.disconnect_ok;
...@@ -1714,22 +1777,21 @@ static void fas216_bus_reset(FAS216_Info *info) ...@@ -1714,22 +1777,21 @@ static void fas216_bus_reset(FAS216_Info *info)
wake_up(&info->eh_wait); wake_up(&info->eh_wait);
} }
/** /**
* fas216_intr - handle interrupts to progress a command * fas216_intr - handle interrupts to progress a command
* @instance: interface to service * @info: interface to service
* *
* Handle interrupts from the interface to progress a command * Handle interrupts from the interface to progress a command
*/ */
void fas216_intr(struct Scsi_Host *instance) void fas216_intr(FAS216_Info *info)
{ {
FAS216_Info *info = (FAS216_Info *)instance->hostdata;
unsigned char isr, ssr, stat; unsigned char isr, ssr, stat;
fas216_checkmagic(info); fas216_checkmagic(info);
stat = inb(REG_STAT(info)); stat = fas216_readb(info, REG_STAT);
ssr = inb(REG_IS(info)); ssr = fas216_readb(info, REG_IS);
isr = inb(REG_INST(info)); isr = fas216_readb(info, REG_INST);
add_debug_list(stat, ssr, isr, info->scsi.phase); add_debug_list(stat, ssr, isr, info->scsi.phase);
...@@ -1762,17 +1824,15 @@ static void __fas216_start_command(FAS216_Info *info, Scsi_Cmnd *SCpnt) ...@@ -1762,17 +1824,15 @@ static void __fas216_start_command(FAS216_Info *info, Scsi_Cmnd *SCpnt)
int tot_msglen; int tot_msglen;
/* following what the ESP driver says */ /* following what the ESP driver says */
outb(0, REG_STCL(info)); fas216_set_stc(info, 0);
outb(0, REG_STCM(info));
outb(0, REG_STCH(info));
fas216_cmd(info, CMD_NOP | CMD_WITHDMA); fas216_cmd(info, CMD_NOP | CMD_WITHDMA);
/* flush FIFO */ /* flush FIFO */
fas216_cmd(info, CMD_FLUSHFIFO); fas216_cmd(info, CMD_FLUSHFIFO);
/* load bus-id and timeout */ /* load bus-id and timeout */
outb(BUSID(SCpnt->target), REG_SDID(info)); fas216_writeb(info, REG_SDID, BUSID(SCpnt->target));
outb(info->ifcfg.select_timeout, REG_STIM(info)); fas216_writeb(info, REG_STIM, info->ifcfg.select_timeout);
/* synchronous transfers */ /* synchronous transfers */
fas216_set_sync(info, SCpnt->target); fas216_set_sync(info, SCpnt->target);
...@@ -1808,13 +1868,13 @@ static void __fas216_start_command(FAS216_Info *info, Scsi_Cmnd *SCpnt) ...@@ -1808,13 +1868,13 @@ static void __fas216_start_command(FAS216_Info *info, Scsi_Cmnd *SCpnt)
/* load message bytes */ /* load message bytes */
while ((msg = msgqueue_getmsg(&info->scsi.msgs, msgnr++)) != NULL) { while ((msg = msgqueue_getmsg(&info->scsi.msgs, msgnr++)) != NULL) {
for (i = 0; i < msg->length; i++) for (i = 0; i < msg->length; i++)
outb(msg->msg[i], REG_FF(info)); fas216_writeb(info, REG_FF, msg->msg[i]);
msg->fifo = tot_msglen - (inb(REG_CFIS(info)) & CFIS_CF); msg->fifo = tot_msglen - (fas216_readb(info, REG_CFIS) & CFIS_CF);
} }
/* load command */ /* load command */
for (i = 0; i < SCpnt->cmd_len; i++) for (i = 0; i < SCpnt->cmd_len; i++)
outb(SCpnt->cmnd[i], REG_FF(info)); fas216_writeb(info, REG_FF, SCpnt->cmnd[i]);
if (tot_msglen == 1) if (tot_msglen == 1)
fas216_cmd(info, CMD_SELECTATN); fas216_cmd(info, CMD_SELECTATN);
...@@ -1828,7 +1888,7 @@ static void __fas216_start_command(FAS216_Info *info, Scsi_Cmnd *SCpnt) ...@@ -1828,7 +1888,7 @@ static void __fas216_start_command(FAS216_Info *info, Scsi_Cmnd *SCpnt)
*/ */
struct message *msg = msgqueue_getmsg(&info->scsi.msgs, 0); struct message *msg = msgqueue_getmsg(&info->scsi.msgs, 0);
outb(msg->msg[0], REG_FF(info)); fas216_writeb(info, REG_FF, msg->msg[0]);
msg->fifo = 1; msg->fifo = 1;
fas216_cmd(info, CMD_SELECTATNSTOP); fas216_cmd(info, CMD_SELECTATNSTOP);
...@@ -1855,11 +1915,6 @@ static void fas216_start_command(FAS216_Info *info, Scsi_Cmnd *SCpnt) ...@@ -1855,11 +1915,6 @@ static void fas216_start_command(FAS216_Info *info, Scsi_Cmnd *SCpnt)
{ {
int disconnect_ok; int disconnect_ok;
if (parity_test(info, SCpnt->target))
outb(info->scsi.cfg[0] | CNTL1_PTE, REG_CNTL1(info));
else
outb(info->scsi.cfg[0], REG_CNTL1(info));
/* /*
* claim host busy * claim host busy
*/ */
...@@ -1868,6 +1923,11 @@ static void fas216_start_command(FAS216_Info *info, Scsi_Cmnd *SCpnt) ...@@ -1868,6 +1923,11 @@ static void fas216_start_command(FAS216_Info *info, Scsi_Cmnd *SCpnt)
info->SCpnt = SCpnt; info->SCpnt = SCpnt;
info->dma.transfer_type = fasdma_none; info->dma.transfer_type = fasdma_none;
if (parity_test(info, SCpnt->target))
fas216_writeb(info, REG_CNTL1, info->scsi.cfg[0] | CNTL1_PTE);
else
fas216_writeb(info, REG_CNTL1, info->scsi.cfg[0]);
/* /*
* Don't allow request sense commands to disconnect. * Don't allow request sense commands to disconnect.
*/ */
...@@ -1966,24 +2026,22 @@ static void fas216_do_bus_device_reset(FAS216_Info *info, Scsi_Cmnd *SCpnt) ...@@ -1966,24 +2026,22 @@ static void fas216_do_bus_device_reset(FAS216_Info *info, Scsi_Cmnd *SCpnt)
msgqueue_addmsg(&info->scsi.msgs, 1, BUS_DEVICE_RESET); msgqueue_addmsg(&info->scsi.msgs, 1, BUS_DEVICE_RESET);
/* following what the ESP driver says */ /* following what the ESP driver says */
outb(0, REG_STCL(info)); fas216_set_stc(info, 0);
outb(0, REG_STCM(info));
outb(0, REG_STCH(info));
fas216_cmd(info, CMD_NOP | CMD_WITHDMA); fas216_cmd(info, CMD_NOP | CMD_WITHDMA);
/* flush FIFO */ /* flush FIFO */
fas216_cmd(info, CMD_FLUSHFIFO); fas216_cmd(info, CMD_FLUSHFIFO);
/* load bus-id and timeout */ /* load bus-id and timeout */
outb(BUSID(SCpnt->target), REG_SDID(info)); fas216_writeb(info, REG_SDID, BUSID(SCpnt->target));
outb(info->ifcfg.select_timeout, REG_STIM(info)); fas216_writeb(info, REG_STIM, info->ifcfg.select_timeout);
/* synchronous transfers */ /* synchronous transfers */
fas216_set_sync(info, SCpnt->target); fas216_set_sync(info, SCpnt->target);
msg = msgqueue_getmsg(&info->scsi.msgs, 0); msg = msgqueue_getmsg(&info->scsi.msgs, 0);
outb(BUS_DEVICE_RESET, REG_FF(info)); fas216_writeb(info, REG_FF, BUS_DEVICE_RESET);
msg->fifo = 1; msg->fifo = 1;
fas216_cmd(info, CMD_SELECTATNSTOP); fas216_cmd(info, CMD_SELECTATNSTOP);
...@@ -1992,8 +2050,8 @@ static void fas216_do_bus_device_reset(FAS216_Info *info, Scsi_Cmnd *SCpnt) ...@@ -1992,8 +2050,8 @@ static void fas216_do_bus_device_reset(FAS216_Info *info, Scsi_Cmnd *SCpnt)
/** /**
* fas216_kick - kick a command to the interface * fas216_kick - kick a command to the interface
* @info: our host interface to kick * @info: our host interface to kick
* *
* kick a command to the interface, interface should be idle. * Kick a command to the interface, interface should be idle.
* Notes: Interrupts are always disabled! * Notes: Interrupts are always disabled!
*/ */
static void fas216_kick(FAS216_Info *info) static void fas216_kick(FAS216_Info *info)
...@@ -2050,11 +2108,8 @@ static void fas216_kick(FAS216_Info *info) ...@@ -2050,11 +2108,8 @@ static void fas216_kick(FAS216_Info *info)
info->SCpnt = NULL; info->SCpnt = NULL;
} }
#if defined(DEBUG_CONNECT) || defined(DEBUG_MESSAGES) fas216_log_command(info, LOG_CONNECT | LOG_MESSAGES, SCpnt,
printk("scsi%d.%c: starting ", "starting");
info->host->host_no, '0' + SCpnt->target);
print_command(SCpnt->cmnd);
#endif
switch (where_from) { switch (where_from) {
case TYPE_QUEUE: case TYPE_QUEUE:
...@@ -2094,13 +2149,13 @@ fas216_devicereset_done(FAS216_Info *info, Scsi_Cmnd *SCpnt, unsigned int result ...@@ -2094,13 +2149,13 @@ fas216_devicereset_done(FAS216_Info *info, Scsi_Cmnd *SCpnt, unsigned int result
* @info: interface that completed * @info: interface that completed
* @SCpnt: command that completed * @SCpnt: command that completed
* @result: driver byte of result * @result: driver byte of result
* *
* Finish processing automatic request sense command * Finish processing automatic request sense command
*/ */
static void static void
fas216_rq_sns_done(FAS216_Info *info, Scsi_Cmnd *SCpnt, unsigned int result) fas216_rq_sns_done(FAS216_Info *info, Scsi_Cmnd *SCpnt, unsigned int result)
{ {
fas216_log(info, LOG_CONNECT, fas216_log_target(info, LOG_CONNECT, SCpnt->target,
"request sense complete, result=0x%04x%02x%02x", "request sense complete, result=0x%04x%02x%02x",
result, SCpnt->SCp.Message, SCpnt->SCp.Status); result, SCpnt->SCp.Message, SCpnt->SCp.Status);
...@@ -2127,7 +2182,7 @@ fas216_rq_sns_done(FAS216_Info *info, Scsi_Cmnd *SCpnt, unsigned int result) ...@@ -2127,7 +2182,7 @@ fas216_rq_sns_done(FAS216_Info *info, Scsi_Cmnd *SCpnt, unsigned int result)
* @info: interface that completed * @info: interface that completed
* @SCpnt: command that completed * @SCpnt: command that completed
* @result: driver byte of result * @result: driver byte of result
* *
* Finish processing of standard command * Finish processing of standard command
*/ */
static void static void
...@@ -2138,17 +2193,14 @@ fas216_std_done(FAS216_Info *info, Scsi_Cmnd *SCpnt, unsigned int result) ...@@ -2138,17 +2193,14 @@ fas216_std_done(FAS216_Info *info, Scsi_Cmnd *SCpnt, unsigned int result)
SCpnt->result = result << 16 | info->scsi.SCp.Message << 8 | SCpnt->result = result << 16 | info->scsi.SCp.Message << 8 |
info->scsi.SCp.Status; info->scsi.SCp.Status;
#ifdef DEBUG_CONNECT fas216_log_command(info, LOG_CONNECT, SCpnt,
printk("scsi%d.%c: command complete, result=%08X, command=", "command complete, result=0x%08x", SCpnt->result);
info->host->host_no, '0' + SCpnt->target, SCpnt->result);
print_command(SCpnt->cmnd);
#endif
/* /*
* If the driver detected an error, or the command * If the driver detected an error, we're all done.
* was request sense, then we're all done.
*/ */
if (result != DID_OK || SCpnt->cmnd[0] == REQUEST_SENSE) if (host_byte(SCpnt->result) != DID_OK ||
msg_byte(SCpnt->result) != COMMAND_COMPLETE)
goto done; goto done;
/* /*
...@@ -2163,7 +2215,7 @@ fas216_std_done(FAS216_Info *info, Scsi_Cmnd *SCpnt, unsigned int result) ...@@ -2163,7 +2215,7 @@ fas216_std_done(FAS216_Info *info, Scsi_Cmnd *SCpnt, unsigned int result)
* If the command did not complete with GOOD status, * If the command did not complete with GOOD status,
* we are all done here. * we are all done here.
*/ */
if (info->scsi.SCp.Status != GOOD) if (status_byte(SCpnt->result) != GOOD)
goto done; goto done;
/* /*
...@@ -2177,17 +2229,19 @@ fas216_std_done(FAS216_Info *info, Scsi_Cmnd *SCpnt, unsigned int result) ...@@ -2177,17 +2229,19 @@ fas216_std_done(FAS216_Info *info, Scsi_Cmnd *SCpnt, unsigned int result)
switch (SCpnt->cmnd[0]) { switch (SCpnt->cmnd[0]) {
case INQUIRY: case INQUIRY:
case START_STOP: case START_STOP:
// case READ_CAPACITY:
case MODE_SENSE: case MODE_SENSE:
break; break;
default: default:
printk(KERN_ERR "scsi%d.%c: incomplete data transfer " printk(KERN_ERR "scsi%d.%c: incomplete data transfer "
"detected: res=%08X ptr=%p len=%X command=", "detected: res=%08X ptr=%p len=%X CDB: ",
info->host->host_no, '0' + SCpnt->target, info->host->host_no, '0' + SCpnt->target,
SCpnt->result, info->scsi.SCp.ptr, SCpnt->result, info->scsi.SCp.ptr,
info->scsi.SCp.this_residual); info->scsi.SCp.this_residual);
print_command(SCpnt->cmnd); print_command(SCpnt->cmnd);
SCpnt->result &= ~(255 << 16);
SCpnt->result |= DID_BAD_TARGET << 16;
goto request_sense;
} }
} }
...@@ -2202,6 +2256,11 @@ fas216_std_done(FAS216_Info *info, Scsi_Cmnd *SCpnt, unsigned int result) ...@@ -2202,6 +2256,11 @@ fas216_std_done(FAS216_Info *info, Scsi_Cmnd *SCpnt, unsigned int result)
request_sense: request_sense:
if (SCpnt->cmnd[0] == REQUEST_SENSE)
goto done;
fas216_log_target(info, LOG_CONNECT, SCpnt->target,
"requesting sense");
memset(SCpnt->cmnd, 0, sizeof (SCpnt->cmnd)); memset(SCpnt->cmnd, 0, sizeof (SCpnt->cmnd));
SCpnt->cmnd[0] = REQUEST_SENSE; SCpnt->cmnd[0] = REQUEST_SENSE;
SCpnt->cmnd[1] = SCpnt->lun << 5; SCpnt->cmnd[1] = SCpnt->lun << 5;
...@@ -2234,7 +2293,7 @@ fas216_std_done(FAS216_Info *info, Scsi_Cmnd *SCpnt, unsigned int result) ...@@ -2234,7 +2293,7 @@ fas216_std_done(FAS216_Info *info, Scsi_Cmnd *SCpnt, unsigned int result)
* fas216_done - complete processing for current command * fas216_done - complete processing for current command
* @info: interface that completed * @info: interface that completed
* @result: driver byte of result * @result: driver byte of result
* *
* Complete processing for current command * Complete processing for current command
*/ */
static void fas216_done(FAS216_Info *info, unsigned int result) static void fas216_done(FAS216_Info *info, unsigned int result)
...@@ -2264,7 +2323,7 @@ static void fas216_done(FAS216_Info *info, unsigned int result) ...@@ -2264,7 +2323,7 @@ static void fas216_done(FAS216_Info *info, unsigned int result)
*/ */
if (info->scsi.SCp.ptr && info->scsi.SCp.this_residual == 0) { if (info->scsi.SCp.ptr && info->scsi.SCp.this_residual == 0) {
printk("scsi%d.%c: zero bytes left to transfer, but " printk("scsi%d.%c: zero bytes left to transfer, but "
"buffer pointer still valid: ptr=%p len=%08x command=", "buffer pointer still valid: ptr=%p len=%08x CDB: ",
info->host->host_no, '0' + SCpnt->target, info->host->host_no, '0' + SCpnt->target,
info->scsi.SCp.ptr, info->scsi.SCp.this_residual); info->scsi.SCp.ptr, info->scsi.SCp.this_residual);
info->scsi.SCp.ptr = NULL; info->scsi.SCp.ptr = NULL;
...@@ -2299,9 +2358,9 @@ static void fas216_done(FAS216_Info *info, unsigned int result) ...@@ -2299,9 +2358,9 @@ static void fas216_done(FAS216_Info *info, unsigned int result)
* fas216_queue_command - queue a command for adapter to process. * fas216_queue_command - queue a command for adapter to process.
* @SCpnt: Command to queue * @SCpnt: Command to queue
* @done: done function to call once command is complete * @done: done function to call once command is complete
* *
* Queue a command for adapter to process. * Queue a command for adapter to process.
* Returns: 0 in success, else error. * Returns: 0 on success, else error.
* Notes: io_request_lock is held, interrupts are disabled. * Notes: io_request_lock is held, interrupts are disabled.
*/ */
int fas216_queue_command(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) int fas216_queue_command(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
...@@ -2311,11 +2370,8 @@ int fas216_queue_command(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) ...@@ -2311,11 +2370,8 @@ int fas216_queue_command(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
fas216_checkmagic(info); fas216_checkmagic(info);
#ifdef DEBUG_CONNECT fas216_log_command(info, LOG_CONNECT, SCpnt,
printk("scsi%d.H: received command for id %d (%p) ", "received command (%p)", SCpnt);
SCpnt->host->host_no, SCpnt->target, SCpnt);
print_command(SCpnt->cmnd);
#endif
SCpnt->scsi_done = done; SCpnt->scsi_done = done;
SCpnt->host_scribble = (void *)fas216_std_done; SCpnt->host_scribble = (void *)fas216_std_done;
...@@ -2342,10 +2398,8 @@ int fas216_queue_command(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) ...@@ -2342,10 +2398,8 @@ int fas216_queue_command(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
fas216_kick(info); fas216_kick(info);
spin_unlock(&info->host_lock); spin_unlock(&info->host_lock);
#ifdef DEBUG_CONNECT fas216_log_target(info, LOG_CONNECT, -1, "queue %s",
printk("scsi%d.H: queue %s\n", info->host->host_no,
result ? "failure" : "success"); result ? "failure" : "success");
#endif
return result; return result;
} }
...@@ -2353,7 +2407,7 @@ int fas216_queue_command(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) ...@@ -2353,7 +2407,7 @@ int fas216_queue_command(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
/** /**
* fas216_internal_done - trigger restart of a waiting thread in fas216_command * fas216_internal_done - trigger restart of a waiting thread in fas216_command
* @SCpnt: Command to wake * @SCpnt: Command to wake
* *
* Trigger restart of a waiting thread in fas216_command * Trigger restart of a waiting thread in fas216_command
*/ */
static void fas216_internal_done(Scsi_Cmnd *SCpnt) static void fas216_internal_done(Scsi_Cmnd *SCpnt)
...@@ -2367,9 +2421,9 @@ static void fas216_internal_done(Scsi_Cmnd *SCpnt) ...@@ -2367,9 +2421,9 @@ static void fas216_internal_done(Scsi_Cmnd *SCpnt)
/** /**
* fas216_command - queue a command for adapter to process. * fas216_command - queue a command for adapter to process.
* @SCpnt: Command to queue * @SCpnt: Command to queue
* *
* Qqueue a command for adapter to process. * Queue a command for adapter to process.
* Returns: scsi result code. * Returns: scsi result code.
* Notes: io_request_lock is held, interrupts are disabled. * Notes: io_request_lock is held, interrupts are disabled.
*/ */
...@@ -2406,9 +2460,9 @@ int fas216_command(Scsi_Cmnd *SCpnt) ...@@ -2406,9 +2460,9 @@ int fas216_command(Scsi_Cmnd *SCpnt)
* and go to sleep if we know that the device is going * and go to sleep if we know that the device is going
* to be some time (eg, disconnected). * to be some time (eg, disconnected).
*/ */
if (inb(REG_STAT(info)) & STAT_INT) { if (fas216_readb(info, REG_STAT) & STAT_INT) {
spin_lock_irq(info->host->host_lock); spin_lock_irq(info->host->host_lock);
fas216_intr(info->host); fas216_intr(info);
spin_unlock_irq(info->host->host_lock); spin_unlock_irq(info->host->host_lock);
} }
} }
...@@ -2447,7 +2501,7 @@ enum res_find { ...@@ -2447,7 +2501,7 @@ enum res_find {
/** /**
* fas216_do_abort - decide how to abort a command * fas216_do_abort - decide how to abort a command
* @SCpnt: command to abort * @SCpnt: command to abort
* *
* Decide how to abort a command. * Decide how to abort a command.
* Returns: abort status * Returns: abort status
*/ */
...@@ -2513,7 +2567,7 @@ static enum res_find fas216_find_command(FAS216_Info *info, Scsi_Cmnd *SCpnt) ...@@ -2513,7 +2567,7 @@ static enum res_find fas216_find_command(FAS216_Info *info, Scsi_Cmnd *SCpnt)
/** /**
* fas216_eh_abort - abort this command * fas216_eh_abort - abort this command
* @SCpnt: command to abort * @SCpnt: command to abort
* *
* Abort this command. * Abort this command.
* Returns: FAILED if unable to abort * Returns: FAILED if unable to abort
* Notes: io_request_lock is taken, and irqs are disabled * Notes: io_request_lock is taken, and irqs are disabled
...@@ -2568,12 +2622,12 @@ int fas216_eh_abort(Scsi_Cmnd *SCpnt) ...@@ -2568,12 +2622,12 @@ int fas216_eh_abort(Scsi_Cmnd *SCpnt)
/** /**
* fas216_eh_device_reset - Reset the device associated with this command * fas216_eh_device_reset - Reset the device associated with this command
* @SCpnt: command specifing device to reset * @SCpnt: command specifing device to reset
* *
* Reset the device associated with this command. * Reset the device associated with this command.
* Returns: FAILED if unable to reset. * Returns: FAILED if unable to reset.
* Notes: We won't be re-entered, so we'll only have one device * Notes: We won't be re-entered, so we'll only have one device
* reset on the go at one time. * reset on the go at one time.
*/ */
int fas216_eh_device_reset(Scsi_Cmnd *SCpnt) int fas216_eh_device_reset(Scsi_Cmnd *SCpnt)
{ {
...@@ -2651,7 +2705,7 @@ int fas216_eh_device_reset(Scsi_Cmnd *SCpnt) ...@@ -2651,7 +2705,7 @@ int fas216_eh_device_reset(Scsi_Cmnd *SCpnt)
/** /**
* fas216_eh_bus_reset - Reset the bus associated with the command * fas216_eh_bus_reset - Reset the bus associated with the command
* @SCpnt: command specifing bus to reset * @SCpnt: command specifing bus to reset
* *
* Reset the bus associated with the command. * Reset the bus associated with the command.
* Returns: FAILED if unable to reset. * Returns: FAILED if unable to reset.
* Notes: Further commands are blocked. * Notes: Further commands are blocked.
...@@ -2673,13 +2727,13 @@ int fas216_eh_bus_reset(Scsi_Cmnd *SCpnt) ...@@ -2673,13 +2727,13 @@ int fas216_eh_bus_reset(Scsi_Cmnd *SCpnt)
* Stop all activity on this interface. * Stop all activity on this interface.
*/ */
fas216_aborttransfer(info); fas216_aborttransfer(info);
outb(info->scsi.cfg[2], REG_CNTL3(info)); fas216_writeb(info, REG_CNTL3, info->scsi.cfg[2]);
/* /*
* Clear any pending interrupts. * Clear any pending interrupts.
*/ */
while (inb(REG_STAT(info)) & STAT_INT) while (fas216_readb(info, REG_STAT) & STAT_INT)
inb(REG_INST(info)); fas216_readb(info, REG_INST);
info->rst_bus_status = 0; info->rst_bus_status = 0;
...@@ -2729,26 +2783,26 @@ int fas216_eh_bus_reset(Scsi_Cmnd *SCpnt) ...@@ -2729,26 +2783,26 @@ int fas216_eh_bus_reset(Scsi_Cmnd *SCpnt)
/** /**
* fas216_init_chip - Initialise FAS216 state after reset * fas216_init_chip - Initialise FAS216 state after reset
* @info: state structure for interface * @info: state structure for interface
* *
* Initialise FAS216 state after reset * Initialise FAS216 state after reset
*/ */
static void fas216_init_chip(FAS216_Info *info) static void fas216_init_chip(FAS216_Info *info)
{ {
outb(fas216_clockrate(info->ifcfg.clockrate), REG_CLKF(info)); fas216_writeb(info, REG_CLKF, fas216_clockrate(info->ifcfg.clockrate));
outb(info->scsi.cfg[0], REG_CNTL1(info)); fas216_writeb(info, REG_CNTL1, info->scsi.cfg[0]);
outb(info->scsi.cfg[1], REG_CNTL2(info)); fas216_writeb(info, REG_CNTL2, info->scsi.cfg[1]);
outb(info->scsi.cfg[2], REG_CNTL3(info)); fas216_writeb(info, REG_CNTL3, info->scsi.cfg[2]);
outb(info->ifcfg.select_timeout, REG_STIM(info)); fas216_writeb(info, REG_STIM, info->ifcfg.select_timeout);
outb(0, REG_SOF(info)); fas216_writeb(info, REG_SOF, 0);
outb(info->scsi.async_stp, REG_STP(info)); fas216_writeb(info, REG_STP, info->scsi.async_stp);
outb(info->scsi.cfg[0], REG_CNTL1(info)); fas216_writeb(info, REG_CNTL1, info->scsi.cfg[0]);
} }
/** /**
* fas216_eh_host_reset - Reset the host associated with this command * fas216_eh_host_reset - Reset the host associated with this command
* @SCpnt: command specifing host to reset * @SCpnt: command specifing host to reset
* *
* Reset the host associated with this command. * Reset the host associated with this command.
* Returns: FAILED if unable to reset. * Returns: FAILED if unable to reset.
* Notes: io_request_lock is taken, and irqs are disabled * Notes: io_request_lock is taken, and irqs are disabled
...@@ -2812,56 +2866,56 @@ static int fas216_detect_type(FAS216_Info *info) ...@@ -2812,56 +2866,56 @@ static int fas216_detect_type(FAS216_Info *info)
/* /*
* Reset the chip. * Reset the chip.
*/ */
outb(CMD_RESETCHIP, REG_CMD(info)); fas216_writeb(info, REG_CMD, CMD_RESETCHIP);
udelay(50); udelay(50);
outb(CMD_NOP, REG_CMD(info)); fas216_writeb(info, REG_CMD, CMD_NOP);
/* /*
* Check to see if control reg 2 is present. * Check to see if control reg 2 is present.
*/ */
outb(0, REG_CNTL3(info)); fas216_writeb(info, REG_CNTL3, 0);
outb(CNTL2_S2FE, REG_CNTL2(info)); fas216_writeb(info, REG_CNTL2, CNTL2_S2FE);
/* /*
* If we are unable to read back control reg 2 * If we are unable to read back control reg 2
* correctly, it is not present, and we have a * correctly, it is not present, and we have a
* NCR53C90. * NCR53C90.
*/ */
if ((inb(REG_CNTL2(info)) & (~0xe0)) != CNTL2_S2FE) if ((fas216_readb(info, REG_CNTL2) & (~0xe0)) != CNTL2_S2FE)
return TYPE_NCR53C90; return TYPE_NCR53C90;
/* /*
* Now, check control register 3 * Now, check control register 3
*/ */
outb(0, REG_CNTL2(info)); fas216_writeb(info, REG_CNTL2, 0);
outb(0, REG_CNTL3(info)); fas216_writeb(info, REG_CNTL3, 0);
outb(5, REG_CNTL3(info)); fas216_writeb(info, REG_CNTL3, 5);
/* /*
* If we are unable to read the register back * If we are unable to read the register back
* correctly, we have a NCR53C90A * correctly, we have a NCR53C90A
*/ */
if (inb(REG_CNTL3(info)) != 5) if (fas216_readb(info, REG_CNTL3) != 5)
return TYPE_NCR53C90A; return TYPE_NCR53C90A;
/* /*
* Now read the ID from the chip. * Now read the ID from the chip.
*/ */
outb(0, REG_CNTL3(info)); fas216_writeb(info, REG_CNTL3, 0);
outb(CNTL3_ADIDCHK, REG_CNTL3(info)); fas216_writeb(info, REG_CNTL3, CNTL3_ADIDCHK);
outb(0, REG_CNTL3(info)); fas216_writeb(info, REG_CNTL3, 0);
outb(CMD_RESETCHIP, REG_CMD(info)); fas216_writeb(info, REG_CMD, CMD_RESETCHIP);
udelay(5); udelay(50);
outb(CMD_WITHDMA | CMD_NOP, REG_CMD(info)); fas216_writeb(info, REG_CMD, CMD_WITHDMA | CMD_NOP);
outb(CNTL2_ENF, REG_CNTL2(info)); fas216_writeb(info, REG_CNTL2, CNTL2_ENF);
outb(CMD_RESETCHIP, REG_CMD(info)); fas216_writeb(info, REG_CMD, CMD_RESETCHIP);
udelay(5); udelay(50);
outb(CMD_NOP, REG_CMD(info)); fas216_writeb(info, REG_CMD, CMD_NOP);
rev = inb(REG1_ID(info)); rev = fas216_readb(info, REG_ID);
family = rev >> 3; family = rev >> 3;
rev &= 7; rev &= 7;
...@@ -2887,10 +2941,10 @@ static int fas216_detect_type(FAS216_Info *info) ...@@ -2887,10 +2941,10 @@ static int fas216_detect_type(FAS216_Info *info)
return TYPE_NCR53C9x; return TYPE_NCR53C9x;
} }
/** /**
* fas216_reset_state - Initialise driver internal state * fas216_reset_state - Initialise driver internal state
* @info: state to initialise * @info: state to initialise
* *
* Initialise driver internal state * Initialise driver internal state
*/ */
static void fas216_reset_state(FAS216_Info *info) static void fas216_reset_state(FAS216_Info *info)
...@@ -2928,23 +2982,23 @@ static void fas216_reset_state(FAS216_Info *info) ...@@ -2928,23 +2982,23 @@ static void fas216_reset_state(FAS216_Info *info)
} }
/** /**
* fas216_init - initialise FAS/NCR/AMD SCSI ic. * fas216_init - initialise FAS/NCR/AMD SCSI structures.
* @instance: a driver-specific filled-out structure * @host: a driver-specific filled-out structure
* *
* Initialise FAS/NCR/AMD SCSI ic. * Initialise FAS/NCR/AMD SCSI structures.
* Returns: 0 on success * Returns: 0 on success
*/ */
int fas216_init(struct Scsi_Host *instance) int fas216_init(struct Scsi_Host *host)
{ {
FAS216_Info *info = (FAS216_Info *)instance->hostdata; FAS216_Info *info = (FAS216_Info *)host->hostdata;
int type;
info->magic_start = MAGIC; info->magic_start = MAGIC;
info->magic_end = MAGIC; info->magic_end = MAGIC;
info->host = instance; info->host = host;
info->scsi.cfg[0] = instance->this_id | CNTL1_PERE; info->scsi.cfg[0] = host->this_id | CNTL1_PERE;
info->scsi.cfg[1] = CNTL2_ENF | CNTL2_S2FE; info->scsi.cfg[1] = CNTL2_ENF | CNTL2_S2FE;
info->scsi.cfg[2] = info->ifcfg.cntl3 | CNTL3_ADIDCHK | CNTL3_G2CB; info->scsi.cfg[2] = info->ifcfg.cntl3 |
CNTL3_ADIDCHK | CNTL3_G2CB | CNTL3_LBTM;
info->scsi.async_stp = fas216_syncperiod(info, info->ifcfg.asyncperiod); info->scsi.async_stp = fas216_syncperiod(info, info->ifcfg.asyncperiod);
info->rst_dev_status = -1; info->rst_dev_status = -1;
...@@ -2961,13 +3015,29 @@ int fas216_init(struct Scsi_Host *instance) ...@@ -2961,13 +3015,29 @@ int fas216_init(struct Scsi_Host *instance)
msgqueue_initialise(&info->scsi.msgs); msgqueue_initialise(&info->scsi.msgs);
if (!queue_initialise(&info->queues.issue)) if (!queue_initialise(&info->queues.issue))
return 1; return -ENOMEM;
if (!queue_initialise(&info->queues.disconnected)) { if (!queue_initialise(&info->queues.disconnected)) {
queue_free(&info->queues.issue); queue_free(&info->queues.issue);
return 1; return -ENOMEM;
} }
return 0;
}
/**
* fas216_add - initialise FAS/NCR/AMD SCSI ic.
* @host: a driver-specific filled-out structure
* @dev: parent device
*
* Initialise FAS/NCR/AMD SCSI ic.
* Returns: 0 on success
*/
int fas216_add(struct Scsi_Host *host, struct device *dev)
{
FAS216_Info *info = (FAS216_Info *)host->hostdata;
int type, ret;
fas216_reset_state(info); fas216_reset_state(info);
type = fas216_detect_type(info); type = fas216_detect_type(info);
info->scsi.type = chip_types[type]; info->scsi.type = chip_types[type];
...@@ -2984,8 +3054,8 @@ int fas216_init(struct Scsi_Host *instance) ...@@ -2984,8 +3054,8 @@ int fas216_init(struct Scsi_Host *instance)
* the resulting reset interrupt, so mask it * the resulting reset interrupt, so mask it
* out. * out.
*/ */
outb(info->scsi.cfg[0] | CNTL1_DISR, REG_CNTL1(info)); fas216_writeb(info, REG_CNTL1, info->scsi.cfg[0] | CNTL1_DISR);
outb(CMD_RESETSCSI, REG_CMD(info)); fas216_writeb(info, REG_CMD, CMD_RESETSCSI);
/* /*
* scsi standard says wait 250ms * scsi standard says wait 250ms
...@@ -2994,60 +3064,40 @@ int fas216_init(struct Scsi_Host *instance) ...@@ -2994,60 +3064,40 @@ int fas216_init(struct Scsi_Host *instance)
scsi_sleep(100*HZ/100); scsi_sleep(100*HZ/100);
spin_lock_irq(info->host->host_lock); spin_lock_irq(info->host->host_lock);
outb(info->scsi.cfg[0], REG_CNTL1(info)); fas216_writeb(info, REG_CNTL1, info->scsi.cfg[0]);
inb(REG_INST(info)); fas216_readb(info, REG_INST);
fas216_checkmagic(info); fas216_checkmagic(info);
return 0; ret = scsi_add_host(host, dev);
if (ret)
fas216_writeb(info, REG_CMD, CMD_RESETCHIP);
return ret;
} }
/** void fas216_remove(struct Scsi_Host *host)
* fas216_release - release all resources for FAS/NCR/AMD SCSI ic.
* @instance: a driver-specific filled-out structure
*
* release all resources and put everything to bed for FAS/NCR/AMD SCSI ic,
* Returns: 0 on success.
*/
int fas216_release(struct Scsi_Host *instance)
{ {
FAS216_Info *info = (FAS216_Info *)instance->hostdata; FAS216_Info *info = (FAS216_Info *)host->hostdata;
fas216_checkmagic(info); fas216_checkmagic(info);
scsi_remove_host(host);
outb(CMD_RESETCHIP, REG_CMD(info)); fas216_writeb(info, REG_CMD, CMD_RESETCHIP);
queue_free(&info->queues.disconnected);
queue_free(&info->queues.issue);
return 0;
} }
/** /**
* fas216_info - generate a string containing information about host. * fas216_release - release all resources for FAS/NCR/AMD SCSI ic.
* @info: FAS216 host information * @host: a driver-specific filled-out structure
* @buffer: string buffer to build string *
* * release all resources and put everything to bed for FAS/NCR/AMD SCSI ic.
* Generate a string containing information about this host.
* Returns: size of built string
*/ */
int fas216_info(FAS216_Info *info, char *buffer) void fas216_release(struct Scsi_Host *host)
{ {
char *p = buffer; FAS216_Info *info = (FAS216_Info *)host->hostdata;
p += sprintf(p, "(%s) at port 0x%08lX ",
info->scsi.type, info->host->io_port);
if (info->host->irq != NO_IRQ) queue_free(&info->queues.disconnected);
p += sprintf(p, "irq %d ", info->host->irq); queue_free(&info->queues.issue);
else
p += sprintf(p, "no irq ");
if (info->host->dma_channel != NO_DMA)
p += sprintf(p, "dma %d ", info->host->dma_channel);
else
p += sprintf(p, "no dma ");
return p - buffer;
} }
int fas216_print_host(FAS216_Info *info, char *buffer) int fas216_print_host(FAS216_Info *info, char *buffer)
...@@ -3055,7 +3105,7 @@ int fas216_print_host(FAS216_Info *info, char *buffer) ...@@ -3055,7 +3105,7 @@ int fas216_print_host(FAS216_Info *info, char *buffer)
return sprintf(buffer, return sprintf(buffer,
"\n" "\n"
"Chip : %s\n" "Chip : %s\n"
" Address: 0x%08lX\n" " Address: 0x%08lx\n"
" IRQ : %d\n" " IRQ : %d\n"
" DMA : %d\n", " DMA : %d\n",
info->scsi.type, info->host->io_port, info->scsi.type, info->host->io_port,
...@@ -3117,11 +3167,12 @@ int fas216_print_device(FAS216_Info *info, Scsi_Device *scd, char *buffer) ...@@ -3117,11 +3167,12 @@ int fas216_print_device(FAS216_Info *info, Scsi_Device *scd, char *buffer)
return p - buffer; return p - buffer;
} }
EXPORT_SYMBOL(fas216_info);
EXPORT_SYMBOL(fas216_init); EXPORT_SYMBOL(fas216_init);
EXPORT_SYMBOL(fas216_add);
EXPORT_SYMBOL(fas216_queue_command); EXPORT_SYMBOL(fas216_queue_command);
EXPORT_SYMBOL(fas216_command); EXPORT_SYMBOL(fas216_command);
EXPORT_SYMBOL(fas216_intr); EXPORT_SYMBOL(fas216_intr);
EXPORT_SYMBOL(fas216_remove);
EXPORT_SYMBOL(fas216_release); EXPORT_SYMBOL(fas216_release);
EXPORT_SYMBOL(fas216_eh_abort); EXPORT_SYMBOL(fas216_eh_abort);
EXPORT_SYMBOL(fas216_eh_device_reset); EXPORT_SYMBOL(fas216_eh_device_reset);
......
...@@ -22,18 +22,18 @@ ...@@ -22,18 +22,18 @@
/* FAS register definitions */ /* FAS register definitions */
/* transfer count low */ /* transfer count low */
#define REG_CTCL(x) ((x)->scsi.io_port) #define REG_CTCL (0)
#define REG_STCL(x) ((x)->scsi.io_port) #define REG_STCL (0)
/* transfer count medium */ /* transfer count medium */
#define REG_CTCM(x) ((x)->scsi.io_port + (1 << (x)->scsi.io_shift)) #define REG_CTCM (1)
#define REG_STCM(x) ((x)->scsi.io_port + (1 << (x)->scsi.io_shift)) #define REG_STCM (1)
/* fifo data */ /* fifo data */
#define REG_FF(x) ((x)->scsi.io_port + (2 << (x)->scsi.io_shift)) #define REG_FF (2)
/* command */ /* command */
#define REG_CMD(x) ((x)->scsi.io_port + (3 << (x)->scsi.io_shift)) #define REG_CMD (3)
#define CMD_NOP 0x00 #define CMD_NOP 0x00
#define CMD_FLUSHFIFO 0x01 #define CMD_FLUSHFIFO 0x01
#define CMD_RESETCHIP 0x02 #define CMD_RESETCHIP 0x02
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
#define CMD_WITHDMA 0x80 #define CMD_WITHDMA 0x80
/* status register (read) */ /* status register (read) */
#define REG_STAT(x) ((x)->scsi.io_port + (4 << (x)->scsi.io_shift)) #define REG_STAT (4)
#define STAT_IO (1 << 0) /* IO phase */ #define STAT_IO (1 << 0) /* IO phase */
#define STAT_CD (1 << 1) /* CD phase */ #define STAT_CD (1 << 1) /* CD phase */
#define STAT_MSG (1 << 2) /* MSG phase */ #define STAT_MSG (1 << 2) /* MSG phase */
...@@ -76,11 +76,11 @@ ...@@ -76,11 +76,11 @@
#define STAT_MESGIN (STAT_MSG|STAT_CD|STAT_IO) /* Message In */ #define STAT_MESGIN (STAT_MSG|STAT_CD|STAT_IO) /* Message In */
/* bus ID for select / reselect */ /* bus ID for select / reselect */
#define REG_SDID(x) ((x)->scsi.io_port + (4 << (x)->scsi.io_shift)) #define REG_SDID (4)
#define BUSID(target) ((target) & 7) #define BUSID(target) ((target) & 7)
/* Interrupt status register (read) */ /* Interrupt status register (read) */
#define REG_INST(x) ((x)->scsi.io_port + (5 << (x)->scsi.io_shift)) #define REG_INST (5)
#define INST_SELWOATN (1 << 0) /* Select w/o ATN */ #define INST_SELWOATN (1 << 0) /* Select w/o ATN */
#define INST_SELATN (1 << 1) /* Select w/ATN */ #define INST_SELATN (1 << 1) /* Select w/ATN */
#define INST_RESELECTED (1 << 2) /* Reselected */ #define INST_RESELECTED (1 << 2) /* Reselected */
...@@ -91,10 +91,10 @@ ...@@ -91,10 +91,10 @@
#define INST_BUSRESET (1 << 7) /* SCSI Bus reset */ #define INST_BUSRESET (1 << 7) /* SCSI Bus reset */
/* Timeout register (write) */ /* Timeout register (write) */
#define REG_STIM(x) ((x)->scsi.io_port + (5 << (x)->scsi.io_shift)) #define REG_STIM (5)
/* Sequence step register (read) */ /* Sequence step register (read) */
#define REG_IS(x) ((x)->scsi.io_port + (6 << (x)->scsi.io_shift)) #define REG_IS (6)
#define IS_BITS 0x07 #define IS_BITS 0x07
#define IS_SELARB 0x00 /* Select & Arb ok */ #define IS_SELARB 0x00 /* Select & Arb ok */
#define IS_MSGBYTESENT 0x01 /* One byte message sent*/ #define IS_MSGBYTESENT 0x01 /* One byte message sent*/
...@@ -104,18 +104,18 @@ ...@@ -104,18 +104,18 @@
#define IS_SOF 0x08 /* Sync off flag */ #define IS_SOF 0x08 /* Sync off flag */
/* Transfer period step (write) */ /* Transfer period step (write) */
#define REG_STP(x) ((x)->scsi.io_port + (6 << (x)->scsi.io_shift)) #define REG_STP (6)
/* Synchronous Offset (write) */ /* Synchronous Offset (write) */
#define REG_SOF(x) ((x)->scsi.io_port + (7 << (x)->scsi.io_shift)) #define REG_SOF (7)
/* Fifo state register (read) */ /* Fifo state register (read) */
#define REG_CFIS(x) ((x)->scsi.io_port + (7 << (x)->scsi.io_shift)) #define REG_CFIS (7)
#define CFIS_CF 0x1f /* Num bytes in FIFO */ #define CFIS_CF 0x1f /* Num bytes in FIFO */
#define CFIS_IS 0xe0 /* Step */ #define CFIS_IS 0xe0 /* Step */
/* config register 1 */ /* config register 1 */
#define REG_CNTL1(x) ((x)->scsi.io_port + (8 << (x)->scsi.io_shift)) #define REG_CNTL1 (8)
#define CNTL1_CID (7 << 0) /* Chip ID */ #define CNTL1_CID (7 << 0) /* Chip ID */
#define CNTL1_STE (1 << 3) /* Self test enable */ #define CNTL1_STE (1 << 3) /* Self test enable */
#define CNTL1_PERE (1 << 4) /* Parity enable reporting en. */ #define CNTL1_PERE (1 << 4) /* Parity enable reporting en. */
...@@ -124,7 +124,7 @@ ...@@ -124,7 +124,7 @@
#define CNTL1_ETM (1 << 7) /* Extended Timing Mode */ #define CNTL1_ETM (1 << 7) /* Extended Timing Mode */
/* Clock conversion factor (read) */ /* Clock conversion factor (read) */
#define REG_CLKF(x) ((x)->scsi.io_port + (9 << (x)->scsi.io_shift)) #define REG_CLKF (9)
#define CLKF_F37MHZ 0x00 /* 35.01 - 40 MHz */ #define CLKF_F37MHZ 0x00 /* 35.01 - 40 MHz */
#define CLKF_F10MHZ 0x02 /* 10 MHz */ #define CLKF_F10MHZ 0x02 /* 10 MHz */
#define CLKF_F12MHZ 0x03 /* 10.01 - 15 MHz */ #define CLKF_F12MHZ 0x03 /* 10.01 - 15 MHz */
...@@ -134,13 +134,13 @@ ...@@ -134,13 +134,13 @@
#define CLKF_F32MHZ 0x07 /* 30.01 - 35 MHz */ #define CLKF_F32MHZ 0x07 /* 30.01 - 35 MHz */
/* Chip test register (write) */ /* Chip test register (write) */
#define REG0_FTM(x) ((x)->scsi.io_port + (10 << (x)->scsi.io_shift)) #define REG_FTM (10)
#define TEST_FTM 0x01 /* Force target mode */ #define TEST_FTM 0x01 /* Force target mode */
#define TEST_FIM 0x02 /* Force initiator mode */ #define TEST_FIM 0x02 /* Force initiator mode */
#define TEST_FHI 0x04 /* Force high impedance mode */ #define TEST_FHI 0x04 /* Force high impedance mode */
/* Configuration register 2 (read/write) */ /* Configuration register 2 (read/write) */
#define REG_CNTL2(x) ((x)->scsi.io_port + (11 << (x)->scsi.io_shift)) #define REG_CNTL2 (11)
#define CNTL2_PGDP (1 << 0) /* Pass Th/Generate Data Parity */ #define CNTL2_PGDP (1 << 0) /* Pass Th/Generate Data Parity */
#define CNTL2_PGRP (1 << 1) /* Pass Th/Generate Reg Parity */ #define CNTL2_PGRP (1 << 1) /* Pass Th/Generate Reg Parity */
#define CNTL2_ACDPE (1 << 2) /* Abort on Cmd/Data Parity Err */ #define CNTL2_ACDPE (1 << 2) /* Abort on Cmd/Data Parity Err */
...@@ -151,7 +151,7 @@ ...@@ -151,7 +151,7 @@
#define CNTL2_DAE (1 << 7) /* Data Alignment Enable */ #define CNTL2_DAE (1 << 7) /* Data Alignment Enable */
/* Configuration register 3 (read/write) */ /* Configuration register 3 (read/write) */
#define REG_CNTL3(x) ((x)->scsi.io_port + (12 << (x)->scsi.io_shift)) #define REG_CNTL3 (12)
#define CNTL3_BS8 (1 << 0) /* Burst size 8 */ #define CNTL3_BS8 (1 << 0) /* Burst size 8 */
#define CNTL3_MDM (1 << 1) /* Modify DMA mode */ #define CNTL3_MDM (1 << 1) /* Modify DMA mode */
#define CNTL3_LBTM (1 << 2) /* Last Byte Transfer mode */ #define CNTL3_LBTM (1 << 2) /* Last Byte Transfer mode */
...@@ -162,14 +162,14 @@ ...@@ -162,14 +162,14 @@
#define CNTL3_ADIDCHK (1 << 7) /* Additional ID check */ #define CNTL3_ADIDCHK (1 << 7) /* Additional ID check */
/* High transfer count (read/write) */ /* High transfer count (read/write) */
#define REG_CTCH(x) ((x)->scsi.io_port + (14 << (x)->scsi.io_shift)) #define REG_CTCH (14)
#define REG_STCH(x) ((x)->scsi.io_port + (14 << (x)->scsi.io_shift)) #define REG_STCH (14)
/* ID reigster (read only) */ /* ID register (read only) */
#define REG1_ID(x) ((x)->scsi.io_port + (14 << (x)->scsi.io_shift)) #define REG_ID (14)
/* Data alignment */ /* Data alignment */
#define REG0_DAL(x) ((x)->scsi.io_port + (15 << (x)->scsi.io_shift)) #define REG_DAL (15)
typedef enum { typedef enum {
PHASE_IDLE, /* we're not planning on doing anything */ PHASE_IDLE, /* we're not planning on doing anything */
...@@ -212,6 +212,9 @@ typedef enum { ...@@ -212,6 +212,9 @@ typedef enum {
#define MAGIC 0x441296bdUL #define MAGIC 0x441296bdUL
#define NR_MSGS 8 #define NR_MSGS 8
#define FASCAP_DMA (1 << 0)
#define FASCAP_PSEUDODMA (1 << 1)
typedef struct { typedef struct {
unsigned long magic_start; unsigned long magic_start;
spinlock_t host_lock; spinlock_t host_lock;
...@@ -233,12 +236,13 @@ typedef struct { ...@@ -233,12 +236,13 @@ typedef struct {
/* driver information */ /* driver information */
struct { struct {
phase_t phase; /* current phase */
void *io_base; /* iomem base of FAS216 */
unsigned int io_port; /* base address of FAS216 */ unsigned int io_port; /* base address of FAS216 */
unsigned int io_shift; /* shift to adjust reg offsets by */ unsigned int io_shift; /* shift to adjust reg offsets by */
unsigned int irq; /* interrupt */
unsigned char cfg[4]; /* configuration registers */ unsigned char cfg[4]; /* configuration registers */
const char *type; /* chip type */ const char *type; /* chip type */
phase_t phase; /* current phase */ unsigned int irq; /* interrupt */
struct { struct {
unsigned char target; /* reconnected target */ unsigned char target; /* reconnected target */
...@@ -253,7 +257,6 @@ typedef struct { ...@@ -253,7 +257,6 @@ typedef struct {
unsigned int async_stp; /* Async transfer STP value */ unsigned int async_stp; /* Async transfer STP value */
unsigned char msgin_fifo; /* bytes in fifo at time of message in */ unsigned char msgin_fifo; /* bytes in fifo at time of message in */
unsigned char message[256]; /* last message received from device */ unsigned char message[256]; /* last message received from device */
unsigned int msglen; /* length of last message received */
unsigned char disconnectable:1; /* this command can be disconnected */ unsigned char disconnectable:1; /* this command can be disconnected */
unsigned char aborting:1; /* aborting command */ unsigned char aborting:1; /* aborting command */
...@@ -281,6 +284,7 @@ typedef struct { ...@@ -281,6 +284,7 @@ typedef struct {
unsigned char wide_max_size; /* Maximum wide transfer size */ unsigned char wide_max_size; /* Maximum wide transfer size */
unsigned char cntl3; /* Control Reg 3 */ unsigned char cntl3; /* Control Reg 3 */
unsigned int asyncperiod; /* Async transfer period (ns) */ unsigned int asyncperiod; /* Async transfer period (ns) */
unsigned int capabilities; /* driver capabilities */
unsigned int disconnect_ok:1; /* Disconnects allowed? */ unsigned int disconnect_ok:1; /* Disconnects allowed? */
} ifcfg; } ifcfg;
...@@ -319,26 +323,18 @@ typedef struct { ...@@ -319,26 +323,18 @@ typedef struct {
} FAS216_Info; } FAS216_Info;
/* Function: int fas216_init (struct Scsi_Host *instance) /* Function: int fas216_init (struct Scsi_Host *instance)
* Purpose : initialise FAS/NCR/AMD SCSI ic. * Purpose : initialise FAS/NCR/AMD SCSI structures.
* Params : instance - a driver-specific filled-out structure * Params : instance - a driver-specific filled-out structure
* Returns : 0 on success * Returns : 0 on success
*/ */
extern int fas216_init (struct Scsi_Host *instance); extern int fas216_init (struct Scsi_Host *instance);
/* Function: int fas216_abort (Scsi_Cmnd *SCpnt) /* Function: int fas216_add (struct Scsi_Host *instance, struct device *dev)
* Purpose : abort a command if something horrible happens. * Purpose : initialise FAS/NCR/AMD SCSI ic.
* Params : SCpnt - Command that is believed to be causing a problem. * Params : instance - a driver-specific filled-out structure
* Returns : one of SCSI_ABORT_ macros. * Returns : 0 on success
*/
extern int fas216_abort (Scsi_Cmnd *);
/* Function: int fas216_reset (Scsi_Cmnd *SCpnt, unsigned int reset_flags)
* Purpose : resets the adapter if something horrible happens.
* Params : SCpnt - Command that is believed to be causing a problem.
* reset_flags - flags indicating reset type that is believed to be required.
* Returns : one of SCSI_RESET_ macros, or'd with the SCSI_RESET_*_RESET macros.
*/ */
extern int fas216_reset (Scsi_Cmnd *, unsigned int); extern int fas216_add (struct Scsi_Host *instance, struct device *dev);
/* Function: int fas216_queue_command (Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) /* Function: int fas216_queue_command (Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
* Purpose : queue a command for adapter to process. * Purpose : queue a command for adapter to process.
...@@ -355,20 +351,21 @@ extern int fas216_queue_command (Scsi_Cmnd *, void (*done)(Scsi_Cmnd *)); ...@@ -355,20 +351,21 @@ extern int fas216_queue_command (Scsi_Cmnd *, void (*done)(Scsi_Cmnd *));
*/ */
extern int fas216_command (Scsi_Cmnd *); extern int fas216_command (Scsi_Cmnd *);
/* Function: void fas216_intr (struct Scsi_Host *instance) /* Function: void fas216_intr (FAS216_Info *info)
* Purpose : handle interrupts from the interface to progress a command * Purpose : handle interrupts from the interface to progress a command
* Params : instance - interface to service * Params : info - interface to service
*/ */
extern void fas216_intr (struct Scsi_Host *instance); extern void fas216_intr (FAS216_Info *info);
extern void fas216_remove (struct Scsi_Host *instance);
/* Function: int fas216_release (struct Scsi_Host *instance) /* Function: void fas216_release (struct Scsi_Host *instance)
* Purpose : release all resources and put everything to bed for FAS/NCR/AMD SCSI ic. * Purpose : release all resources and put everything to bed for FAS/NCR/AMD SCSI ic.
* Params : instance - a driver-specific filled-out structure * Params : instance - a driver-specific filled-out structure
* Returns : 0 on success * Returns : 0 on success
*/ */
extern int fas216_release (struct Scsi_Host *instance); extern void fas216_release (struct Scsi_Host *instance);
extern int fas216_info(FAS216_Info *info, char *buffer);
extern int fas216_print_host(FAS216_Info *info, char *buffer); extern int fas216_print_host(FAS216_Info *info, char *buffer);
extern int fas216_print_stats(FAS216_Info *info, char *buffer); extern int fas216_print_stats(FAS216_Info *info, char *buffer);
extern int fas216_print_device(FAS216_Info *info, Scsi_Device *scd, char *buffer); extern int fas216_print_device(FAS216_Info *info, Scsi_Device *scd, char *buffer);
......
...@@ -192,7 +192,8 @@ static struct ecard_driver oakscsi_driver = { ...@@ -192,7 +192,8 @@ static struct ecard_driver oakscsi_driver = {
.remove = __devexit_p(oakscsi_remove), .remove = __devexit_p(oakscsi_remove),
.id_table = oakscsi_cids, .id_table = oakscsi_cids,
.drv = { .drv = {
.name = "oakscsi", .devclass = &shost_devclass,
.name = "oakscsi",
}, },
}; };
......
/* /*
* linux/drivers/acorn/scsi/powertec.c * linux/drivers/acorn/scsi/powertec.c
* *
* Copyright (C) 1997-2002 Russell King * Copyright (C) 1997-2003 Russell King
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
...@@ -32,24 +32,23 @@ ...@@ -32,24 +32,23 @@
#include <scsi/scsicam.h> #include <scsi/scsicam.h>
#define POWERTEC_FAS216_OFFSET 0xc00 #define POWERTEC_FAS216_OFFSET 0x3000
#define POWERTEC_FAS216_SHIFT 4 #define POWERTEC_FAS216_SHIFT 6
#define POWERTEC_FAS216_SIZE (16 << POWERTEC_FAS216_SHIFT)
#define POWERTEC_INTR_STATUS 0x800 #define POWERTEC_INTR_STATUS 0x2000
#define POWERTEC_INTR_BIT 0x80 #define POWERTEC_INTR_BIT 0x80
#define POWERTEC_RESET_CONTROL 0x406 #define POWERTEC_RESET_CONTROL 0x1018
#define POWERTEC_RESET_BIT 1 #define POWERTEC_RESET_BIT 1
#define POWERTEC_TERM_CONTROL 0x806 #define POWERTEC_TERM_CONTROL 0x2018
#define POWERTEC_TERM_ENABLE 1 #define POWERTEC_TERM_ENABLE 1
#define POWERTEC_INTR_CONTROL 0x407 #define POWERTEC_INTR_CONTROL 0x101c
#define POWERTEC_INTR_ENABLE 1 #define POWERTEC_INTR_ENABLE 1
#define POWERTEC_INTR_DISABLE 0 #define POWERTEC_INTR_DISABLE 0
#define VERSION "1.00 (13/11/2002 2.5.47)" #define VERSION "1.10 (19/01/2003 2.5.59)"
/* /*
* Use term=0,1,0,0,0 to turn terminators on/off. * Use term=0,1,0,0,0 to turn terminators on/off.
...@@ -60,10 +59,11 @@ static int term[MAX_ECARDS] = { 1, 1, 1, 1, 1, 1, 1, 1 }; ...@@ -60,10 +59,11 @@ static int term[MAX_ECARDS] = { 1, 1, 1, 1, 1, 1, 1, 1 };
#define NR_SG 256 #define NR_SG 256
struct powertec_info { struct powertec_info {
FAS216_Info info; FAS216_Info info;
unsigned int term_port; struct expansion_card *ec;
unsigned int term_ctl; void *term_port;
struct scatterlist sg[NR_SG]; unsigned int term_ctl;
struct scatterlist sg[NR_SG];
}; };
/* Prototype: void powertecscsi_irqenable(ec, irqnr) /* Prototype: void powertecscsi_irqenable(ec, irqnr)
...@@ -74,8 +74,7 @@ struct powertec_info { ...@@ -74,8 +74,7 @@ struct powertec_info {
static void static void
powertecscsi_irqenable(struct expansion_card *ec, int irqnr) powertecscsi_irqenable(struct expansion_card *ec, int irqnr)
{ {
unsigned int port = (unsigned int)ec->irq_data; writeb(POWERTEC_INTR_ENABLE, ec->irq_data);
outb(POWERTEC_INTR_ENABLE, port);
} }
/* Prototype: void powertecscsi_irqdisable(ec, irqnr) /* Prototype: void powertecscsi_irqdisable(ec, irqnr)
...@@ -86,8 +85,7 @@ powertecscsi_irqenable(struct expansion_card *ec, int irqnr) ...@@ -86,8 +85,7 @@ powertecscsi_irqenable(struct expansion_card *ec, int irqnr)
static void static void
powertecscsi_irqdisable(struct expansion_card *ec, int irqnr) powertecscsi_irqdisable(struct expansion_card *ec, int irqnr)
{ {
unsigned int port = (unsigned int)ec->irq_data; writeb(POWERTEC_INTR_DISABLE, ec->irq_data);
outb(POWERTEC_INTR_DISABLE, port);
} }
static const expansioncard_ops_t powertecscsi_ops = { static const expansioncard_ops_t powertecscsi_ops = {
...@@ -106,7 +104,7 @@ powertecscsi_terminator_ctl(struct Scsi_Host *host, int on_off) ...@@ -106,7 +104,7 @@ powertecscsi_terminator_ctl(struct Scsi_Host *host, int on_off)
struct powertec_info *info = (struct powertec_info *)host->hostdata; struct powertec_info *info = (struct powertec_info *)host->hostdata;
info->term_ctl = on_off ? POWERTEC_TERM_ENABLE : 0; info->term_ctl = on_off ? POWERTEC_TERM_ENABLE : 0;
outb(info->term_ctl, info->term_port); writeb(info->term_ctl, info->term_port);
} }
/* Prototype: void powertecscsi_intr(irq, *dev_id, *regs) /* Prototype: void powertecscsi_intr(irq, *dev_id, *regs)
...@@ -118,9 +116,9 @@ powertecscsi_terminator_ctl(struct Scsi_Host *host, int on_off) ...@@ -118,9 +116,9 @@ powertecscsi_terminator_ctl(struct Scsi_Host *host, int on_off)
static void static void
powertecscsi_intr(int irq, void *dev_id, struct pt_regs *regs) powertecscsi_intr(int irq, void *dev_id, struct pt_regs *regs)
{ {
struct Scsi_Host *host = (struct Scsi_Host *)dev_id; struct powertec_info *info = dev_id;
fas216_intr(host); fas216_intr(&info->info);
} }
/* Prototype: fasdmatype_t powertecscsi_dma_setup(host, SCpnt, direction, min_type) /* Prototype: fasdmatype_t powertecscsi_dma_setup(host, SCpnt, direction, min_type)
...@@ -139,8 +137,8 @@ powertecscsi_dma_setup(struct Scsi_Host *host, Scsi_Pointer *SCp, ...@@ -139,8 +137,8 @@ powertecscsi_dma_setup(struct Scsi_Host *host, Scsi_Pointer *SCp,
struct device *dev = scsi_get_device(host); struct device *dev = scsi_get_device(host);
int dmach = host->dma_channel; int dmach = host->dma_channel;
if (dmach != NO_DMA && if (info->info.ifcfg.capabilities & FASCAP_DMA &&
(min_type == fasdma_real_all || SCp->this_residual >= 512)) { min_type == fasdma_real_all) {
int bufs, map_dir, dma_dir; int bufs, map_dir, dma_dir;
bufs = copy_SCp_to_sg(&info->sg[0], SCp, NR_SG); bufs = copy_SCp_to_sg(&info->sg[0], SCp, NR_SG);
...@@ -188,13 +186,11 @@ powertecscsi_dma_stop(struct Scsi_Host *host, Scsi_Pointer *SCp) ...@@ -188,13 +186,11 @@ powertecscsi_dma_stop(struct Scsi_Host *host, Scsi_Pointer *SCp)
const char *powertecscsi_info(struct Scsi_Host *host) const char *powertecscsi_info(struct Scsi_Host *host)
{ {
struct powertec_info *info = (struct powertec_info *)host->hostdata; struct powertec_info *info = (struct powertec_info *)host->hostdata;
static char string[150], *p; static char string[150];
p = string; sprintf(string, "%s (%s) in slot %d v%s terminators o%s",
p += sprintf(p, "%s ", host->hostt->name); host->hostt->name, info->info.scsi.type, info->ec->slot_no,
p += fas216_info(&info->info, p); VERSION, info->term_ctl ? "n" : "ff");
p += sprintf(p, "v%s terminators o%s",
VERSION, info->term_ctl ? "n" : "ff");
return string; return string;
} }
...@@ -262,7 +258,6 @@ int powertecscsi_proc_info(char *buffer, char **start, off_t offset, ...@@ -262,7 +258,6 @@ int powertecscsi_proc_info(char *buffer, char **start, off_t offset,
begin = 0; begin = 0;
pos = sprintf(buffer, "PowerTec SCSI driver v%s\n", VERSION); pos = sprintf(buffer, "PowerTec SCSI driver v%s\n", VERSION);
pos += fas216_print_host(&info->info, buffer + pos); pos += fas216_print_host(&info->info, buffer + pos);
pos += sprintf(buffer + pos, "Term : o%s\n", pos += sprintf(buffer + pos, "Term : o%s\n",
info->term_ctl ? "n" : "ff"); info->term_ctl ? "n" : "ff");
...@@ -290,6 +285,30 @@ int powertecscsi_proc_info(char *buffer, char **start, off_t offset, ...@@ -290,6 +285,30 @@ int powertecscsi_proc_info(char *buffer, char **start, off_t offset,
return pos; return pos;
} }
static ssize_t powertecscsi_show_term(struct device *dev, char *buf)
{
struct expansion_card *ec = ECARD_DEV(dev);
struct Scsi_Host *host = ecard_get_drvdata(ec);
struct powertec_info *info = (struct powertec_info *)host->hostdata;
return sprintf(buf, "%d\n", info->term_ctl ? 1 : 0);
}
static ssize_t
powertecscsi_store_term(struct device *dev, const char *buf, size_t len)
{
struct expansion_card *ec = ECARD_DEV(dev);
struct Scsi_Host *host = ecard_get_drvdata(ec);
if (len > 1)
powertecscsi_terminator_ctl(host, buf[0] != '0');
return len;
}
static DEVICE_ATTR(bus_term, S_IRUGO | S_IWUSR,
powertecscsi_show_term, powertecscsi_store_term);
static Scsi_Host_Template powertecscsi_template = { static Scsi_Host_Template powertecscsi_template = {
.module = THIS_MODULE, .module = THIS_MODULE,
.proc_info = powertecscsi_proc_info, .proc_info = powertecscsi_proc_info,
...@@ -302,10 +321,10 @@ static Scsi_Host_Template powertecscsi_template = { ...@@ -302,10 +321,10 @@ static Scsi_Host_Template powertecscsi_template = {
.eh_device_reset_handler = fas216_eh_device_reset, .eh_device_reset_handler = fas216_eh_device_reset,
.eh_abort_handler = fas216_eh_abort, .eh_abort_handler = fas216_eh_abort,
.can_queue = 1, .can_queue = 8,
.this_id = 7, .this_id = 7,
.sg_tablesize = SG_ALL, .sg_tablesize = SG_ALL,
.cmd_per_lun = 1, .cmd_per_lun = 2,
.use_clustering = ENABLE_CLUSTERING, .use_clustering = ENABLE_CLUSTERING,
.proc_name = "powertec", .proc_name = "powertec",
}; };
...@@ -314,37 +333,50 @@ static int __devinit ...@@ -314,37 +333,50 @@ static int __devinit
powertecscsi_probe(struct expansion_card *ec, const struct ecard_id *id) powertecscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
{ {
struct Scsi_Host *host; struct Scsi_Host *host;
struct powertec_info *info; struct powertec_info *info;
int ret = -ENOMEM; unsigned long resbase, reslen;
unsigned char *base;
int ret;
resbase = ecard_resource_start(ec, ECARD_RES_IOCFAST);
reslen = ecard_resource_len(ec, ECARD_RES_IOCFAST);
if (!request_mem_region(resbase, reslen, "powertecscsi")) {
ret = -EBUSY;
goto out;
}
base = ioremap(resbase, reslen);
if (!base) {
ret = -ENOMEM;
goto out_region;
}
host = scsi_register(&powertecscsi_template, host = scsi_register(&powertecscsi_template,
sizeof (struct powertec_info)); sizeof (struct powertec_info));
if (!host) if (!host) {
goto out; ret = -ENOMEM;
goto out_unmap;
}
host->io_port = ecard_address(ec, ECARD_IOC, ECARD_FAST); host->base = (unsigned long)base;
host->irq = ec->irq; host->irq = ec->irq;
host->dma_channel = ec->dma; host->dma_channel = ec->dma;
if (!request_region(host->io_port + POWERTEC_FAS216_OFFSET, ec->irqaddr = base + POWERTEC_INTR_STATUS;
POWERTEC_FAS216_SIZE, "powertec2-fas")) {
ret = -EBUSY;
goto out_free;
}
ec->irqaddr = (unsigned char *)
ioaddr(host->io_port + POWERTEC_INTR_STATUS);
ec->irqmask = POWERTEC_INTR_BIT; ec->irqmask = POWERTEC_INTR_BIT;
ec->irq_data = (void *)(host->io_port + POWERTEC_INTR_CONTROL); ec->irq_data = base + POWERTEC_INTR_CONTROL;
ec->ops = (expansioncard_ops_t *)&powertecscsi_ops; ec->ops = &powertecscsi_ops;
ecard_set_drvdata(ec, host); ecard_set_drvdata(ec, host);
info = (struct powertec_info *)host->hostdata; info = (struct powertec_info *)host->hostdata;
info->term_port = host->io_port + POWERTEC_TERM_CONTROL; info->term_port = base + POWERTEC_TERM_CONTROL;
powertecscsi_terminator_ctl(host, term[ec->slot_no]); powertecscsi_terminator_ctl(host, term[ec->slot_no]);
info->info.scsi.io_port = host->io_port + POWERTEC_FAS216_OFFSET; device_create_file(&ec->dev, &dev_attr_bus_term);
info->info.scsi.io_base = base + POWERTEC_FAS216_OFFSET;
info->info.scsi.io_shift = POWERTEC_FAS216_SHIFT; info->info.scsi.io_shift = POWERTEC_FAS216_SHIFT;
info->info.scsi.irq = host->irq; info->info.scsi.irq = host->irq;
info->info.ifcfg.clockrate = 40; /* MHz */ info->info.ifcfg.clockrate = 40; /* MHz */
...@@ -354,16 +386,21 @@ powertecscsi_probe(struct expansion_card *ec, const struct ecard_id *id) ...@@ -354,16 +386,21 @@ powertecscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
info->info.ifcfg.cntl3 = CNTL3_BS8 | CNTL3_FASTSCSI | CNTL3_FASTCLK; info->info.ifcfg.cntl3 = CNTL3_BS8 | CNTL3_FASTSCSI | CNTL3_FASTCLK;
info->info.ifcfg.disconnect_ok = 1; info->info.ifcfg.disconnect_ok = 1;
info->info.ifcfg.wide_max_size = 0; info->info.ifcfg.wide_max_size = 0;
info->info.ifcfg.capabilities = 0;
info->info.dma.setup = powertecscsi_dma_setup; info->info.dma.setup = powertecscsi_dma_setup;
info->info.dma.pseudo = NULL; info->info.dma.pseudo = NULL;
info->info.dma.stop = powertecscsi_dma_stop; info->info.dma.stop = powertecscsi_dma_stop;
ret = fas216_init(host);
if (ret)
goto out_free;
ret = request_irq(host->irq, powertecscsi_intr, ret = request_irq(host->irq, powertecscsi_intr,
SA_INTERRUPT, "powertec", host); SA_INTERRUPT, "powertec", info);
if (ret) { if (ret) {
printk("scsi%d: IRQ%d not free: %d\n", printk("scsi%d: IRQ%d not free: %d\n",
host->host_no, host->irq, ret); host->host_no, host->irq, ret);
goto out_region; goto out_release;
} }
if (host->dma_channel != NO_DMA) { if (host->dma_channel != NO_DMA) {
...@@ -373,26 +410,31 @@ powertecscsi_probe(struct expansion_card *ec, const struct ecard_id *id) ...@@ -373,26 +410,31 @@ powertecscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
host->dma_channel = NO_DMA; host->dma_channel = NO_DMA;
} else { } else {
set_dma_speed(host->dma_channel, 180); set_dma_speed(host->dma_channel, 180);
info->info.ifcfg.capabilities |= FASCAP_DMA;
} }
} }
fas216_init(host); ret = fas216_add(host, &ec->dev);
ret = scsi_add_host(host, &ec->dev);
if (ret == 0) if (ret == 0)
goto out; goto out;
fas216_release(host);
if (host->dma_channel != NO_DMA) if (host->dma_channel != NO_DMA)
free_dma(host->dma_channel); free_dma(host->dma_channel);
free_irq(host->irq, host); free_irq(host->irq, host);
out_region:
release_region(host->io_port + POWERTEC_FAS216_OFFSET, out_release:
POWERTEC_FAS216_SIZE); fas216_release(host);
out_free: out_free:
device_remove_file(&ec->dev, &dev_attr_bus_term);
scsi_unregister(host); scsi_unregister(host);
out_unmap:
iounmap(base);
out_region:
release_mem_region(resbase, reslen);
out: out:
return ret; return ret;
} }
...@@ -400,16 +442,26 @@ powertecscsi_probe(struct expansion_card *ec, const struct ecard_id *id) ...@@ -400,16 +442,26 @@ powertecscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
static void __devexit powertecscsi_remove(struct expansion_card *ec) static void __devexit powertecscsi_remove(struct expansion_card *ec)
{ {
struct Scsi_Host *host = ecard_get_drvdata(ec); struct Scsi_Host *host = ecard_get_drvdata(ec);
struct powertecscsi_info *info = (struct powertecscsi_info *)host->hostdata;
unsigned long resbase, reslen;
ecard_set_drvdata(ec, NULL); ecard_set_drvdata(ec, NULL);
scsi_remove_host(host); fas216_remove(host);
fas216_release(host);
device_remove_file(&ec->dev, &dev_attr_bus_term);
if (host->dma_channel != NO_DMA) if (host->dma_channel != NO_DMA)
free_dma(host->dma_channel); free_dma(host->dma_channel);
free_irq(host->irq, host); free_irq(host->irq, info);
release_region(host->io_port + POWERTEC_FAS216_OFFSET,
POWERTEC_FAS216_SIZE); iounmap((void *)host->base);
resbase = ecard_resource_start(ec, ECARD_RES_IOCFAST);
reslen = ecard_resource_len(ec, ECARD_RES_IOCFAST);
release_mem_region(resbase, reslen);
fas216_release(host);
scsi_unregister(host); scsi_unregister(host);
} }
...@@ -423,7 +475,8 @@ static struct ecard_driver powertecscsi_driver = { ...@@ -423,7 +475,8 @@ static struct ecard_driver powertecscsi_driver = {
.remove = __devexit_p(powertecscsi_remove), .remove = __devexit_p(powertecscsi_remove),
.id_table = powertecscsi_cids, .id_table = powertecscsi_cids,
.drv = { .drv = {
.name = "powertecscsi", .devclass = &shost_devclass,
.name = "powertecscsi",
}, },
}; };
......
...@@ -55,8 +55,6 @@ static inline unsigned char get_next_SCp_byte(Scsi_Pointer *SCp) ...@@ -55,8 +55,6 @@ static inline unsigned char get_next_SCp_byte(Scsi_Pointer *SCp)
SCp->ptr += 1; SCp->ptr += 1;
SCp->this_residual -= 1; SCp->this_residual -= 1;
if (SCp->this_residual == 0)
next_SCp(SCp);
return c; return c;
} }
...@@ -66,8 +64,6 @@ static inline void put_next_SCp_byte(Scsi_Pointer *SCp, unsigned char c) ...@@ -66,8 +64,6 @@ static inline void put_next_SCp_byte(Scsi_Pointer *SCp, unsigned char c)
*SCp->ptr = c; *SCp->ptr = c;
SCp->ptr += 1; SCp->ptr += 1;
SCp->this_residual -= 1; SCp->this_residual -= 1;
if (SCp->this_residual == 0)
next_SCp(SCp);
} }
static inline void init_SCp(Scsi_Cmnd *SCpnt) static inline void init_SCp(Scsi_Cmnd *SCpnt)
...@@ -112,7 +108,7 @@ static inline void init_SCp(Scsi_Cmnd *SCpnt) ...@@ -112,7 +108,7 @@ static inline void init_SCp(Scsi_Cmnd *SCpnt)
* we aren't interested in the buffer pointer. * we aren't interested in the buffer pointer.
*/ */
if (SCpnt->SCp.this_residual == 0 && SCpnt->SCp.ptr) { if (SCpnt->SCp.this_residual == 0 && SCpnt->SCp.ptr) {
#ifdef BELT_AND_BRACES #if 0 //def BELT_AND_BRACES
printk(KERN_WARNING "scsi%d.%c: zero length buffer passed for " printk(KERN_WARNING "scsi%d.%c: zero length buffer passed for "
"command ", SCpnt->host->host_no, '0' + SCpnt->target); "command ", SCpnt->host->host_no, '0' + SCpnt->target);
print_command(SCpnt->cmnd); print_command(SCpnt->cmnd);
......
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