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