2015-02-06 15:11:47 -07:00
|
|
|
/*
|
|
|
|
* Driver for Adaptec AHA-1542 SCSI host adapters
|
2005-04-16 16:20:36 -06:00
|
|
|
*
|
|
|
|
* Copyright (C) 1992 Tommy Thorn
|
|
|
|
* Copyright (C) 1993, 1994, 1995 Eric Youngdale
|
2015-02-06 15:11:47 -07:00
|
|
|
* Copyright (C) 2015 Ondrej Zary
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/spinlock.h>
|
2015-02-06 15:11:22 -07:00
|
|
|
#include <linux/isa.h>
|
|
|
|
#include <linux/pnp.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2015-02-06 15:11:48 -07:00
|
|
|
#include <linux/io.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <asm/dma.h>
|
2015-02-06 15:11:48 -07:00
|
|
|
#include <scsi/scsi_cmnd.h>
|
|
|
|
#include <scsi/scsi_device.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <scsi/scsi_host.h>
|
|
|
|
#include "aha1542.h"
|
|
|
|
|
2015-02-06 15:11:41 -07:00
|
|
|
#define MAXBOARDS 4
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:41 -07:00
|
|
|
static bool isapnp = 1;
|
|
|
|
module_param(isapnp, bool, 0);
|
|
|
|
MODULE_PARM_DESC(isapnp, "enable PnP support (default=1)");
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:41 -07:00
|
|
|
static int io[MAXBOARDS] = { 0x330, 0x334, 0, 0 };
|
2017-04-04 09:54:27 -06:00
|
|
|
module_param_hw_array(io, int, ioport, NULL, 0);
|
2015-02-06 15:11:41 -07:00
|
|
|
MODULE_PARM_DESC(io, "base IO address of controller (0x130,0x134,0x230,0x234,0x330,0x334, default=0x330,0x334)");
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:41 -07:00
|
|
|
/* time AHA spends on the AT-bus during data transfer */
|
|
|
|
static int bus_on[MAXBOARDS] = { -1, -1, -1, -1 }; /* power-on default: 11us */
|
|
|
|
module_param_array(bus_on, int, NULL, 0);
|
|
|
|
MODULE_PARM_DESC(bus_on, "bus on time [us] (2-15, default=-1 [HW default: 11])");
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:41 -07:00
|
|
|
/* time AHA spends off the bus (not to monopolize it) during data transfer */
|
|
|
|
static int bus_off[MAXBOARDS] = { -1, -1, -1, -1 }; /* power-on default: 4us */
|
|
|
|
module_param_array(bus_off, int, NULL, 0);
|
|
|
|
MODULE_PARM_DESC(bus_off, "bus off time [us] (1-64, default=-1 [HW default: 4])");
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:41 -07:00
|
|
|
/* default is jumper selected (J1 on 1542A), factory default = 5 MB/s */
|
|
|
|
static int dma_speed[MAXBOARDS] = { -1, -1, -1, -1 };
|
|
|
|
module_param_array(dma_speed, int, NULL, 0);
|
|
|
|
MODULE_PARM_DESC(dma_speed, "DMA speed [MB/s] (5,6,7,8,10, default=-1 [by jumper])");
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#define BIOS_TRANSLATION_6432 1 /* Default case these days */
|
|
|
|
#define BIOS_TRANSLATION_25563 2 /* Big disk case */
|
|
|
|
|
|
|
|
struct aha1542_hostdata {
|
|
|
|
/* This will effectively start both of them at the first mailbox */
|
|
|
|
int bios_translation; /* Mapping bios uses - for compatibility */
|
|
|
|
int aha1542_last_mbi_used;
|
|
|
|
int aha1542_last_mbo_used;
|
2015-02-06 15:11:44 -07:00
|
|
|
struct scsi_cmnd *int_cmds[AHA1542_MAILBOXES];
|
2005-04-16 16:20:36 -06:00
|
|
|
struct mailbox mb[2 * AHA1542_MAILBOXES];
|
|
|
|
struct ccb ccb[AHA1542_MAILBOXES];
|
|
|
|
};
|
|
|
|
|
2015-02-06 15:11:26 -07:00
|
|
|
static inline void aha1542_intr_reset(u16 base)
|
|
|
|
{
|
|
|
|
outb(IRST, CONTROL(base));
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:31 -07:00
|
|
|
static inline bool wait_mask(u16 port, u8 mask, u8 allof, u8 noneof, int timeout)
|
|
|
|
{
|
|
|
|
bool delayed = true;
|
|
|
|
|
|
|
|
if (timeout == 0) {
|
|
|
|
timeout = 3000000;
|
|
|
|
delayed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
u8 bits = inb(port) & mask;
|
|
|
|
if ((bits & allof) == allof && ((bits & noneof) == 0))
|
|
|
|
break;
|
|
|
|
if (delayed)
|
|
|
|
mdelay(1);
|
|
|
|
if (--timeout == 0)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:43 -07:00
|
|
|
static int aha1542_outb(unsigned int base, u8 val)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2015-02-06 15:11:57 -07:00
|
|
|
if (!wait_mask(STATUS(base), CDF, 0, CDF, 0))
|
|
|
|
return 1;
|
|
|
|
outb(val, DATA(base));
|
|
|
|
|
|
|
|
return 0;
|
2015-02-06 15:11:33 -07:00
|
|
|
}
|
|
|
|
|
2015-02-06 15:11:43 -07:00
|
|
|
static int aha1542_out(unsigned int base, u8 *buf, int len)
|
2015-02-06 15:11:33 -07:00
|
|
|
{
|
|
|
|
while (len--) {
|
2015-02-06 15:11:55 -07:00
|
|
|
if (!wait_mask(STATUS(base), CDF, 0, CDF, 0))
|
2015-02-06 15:11:33 -07:00
|
|
|
return 1;
|
2015-02-06 15:11:43 -07:00
|
|
|
outb(*buf++, DATA(base));
|
2015-02-06 15:11:33 -07:00
|
|
|
}
|
2015-02-06 15:11:39 -07:00
|
|
|
if (!wait_mask(INTRFLAGS(base), INTRMASK, HACC, 0, 0))
|
|
|
|
return 1;
|
2015-02-06 15:11:33 -07:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only used at boot time, so we do not need to worry about latency as much
|
|
|
|
here */
|
|
|
|
|
2015-02-06 15:11:43 -07:00
|
|
|
static int aha1542_in(unsigned int base, u8 *buf, int len, int timeout)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
while (len--) {
|
2015-02-06 15:11:55 -07:00
|
|
|
if (!wait_mask(STATUS(base), DF, DF, 0, timeout))
|
2015-02-06 15:11:34 -07:00
|
|
|
return 1;
|
2015-02-06 15:11:43 -07:00
|
|
|
*buf++ = inb(DATA(base));
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int makecode(unsigned hosterr, unsigned scsierr)
|
|
|
|
{
|
|
|
|
switch (hosterr) {
|
|
|
|
case 0x0:
|
|
|
|
case 0xa: /* Linked command complete without error and linked normally */
|
|
|
|
case 0xb: /* Linked command complete without error, interrupt generated */
|
|
|
|
hosterr = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x11: /* Selection time out-The initiator selection or target
|
|
|
|
reselection was not complete within the SCSI Time out period */
|
|
|
|
hosterr = DID_TIME_OUT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x12: /* Data overrun/underrun-The target attempted to transfer more data
|
|
|
|
than was allocated by the Data Length field or the sum of the
|
|
|
|
Scatter / Gather Data Length fields. */
|
|
|
|
|
|
|
|
case 0x13: /* Unexpected bus free-The target dropped the SCSI BSY at an unexpected time. */
|
|
|
|
|
|
|
|
case 0x15: /* MBO command was not 00, 01 or 02-The first byte of the CB was
|
|
|
|
invalid. This usually indicates a software failure. */
|
|
|
|
|
|
|
|
case 0x16: /* Invalid CCB Operation Code-The first byte of the CCB was invalid.
|
|
|
|
This usually indicates a software failure. */
|
|
|
|
|
|
|
|
case 0x17: /* Linked CCB does not have the same LUN-A subsequent CCB of a set
|
|
|
|
of linked CCB's does not specify the same logical unit number as
|
|
|
|
the first. */
|
|
|
|
case 0x18: /* Invalid Target Direction received from Host-The direction of a
|
|
|
|
Target Mode CCB was invalid. */
|
|
|
|
|
|
|
|
case 0x19: /* Duplicate CCB Received in Target Mode-More than once CCB was
|
|
|
|
received to service data transfer between the same target LUN
|
|
|
|
and initiator SCSI ID in the same direction. */
|
|
|
|
|
|
|
|
case 0x1a: /* Invalid CCB or Segment List Parameter-A segment list with a zero
|
|
|
|
length segment or invalid segment list boundaries was received.
|
|
|
|
A CCB parameter was invalid. */
|
2015-02-06 15:11:52 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
printk("Aha1542: %x %x\n", hosterr, scsierr);
|
|
|
|
#endif
|
2005-04-16 16:20:36 -06:00
|
|
|
hosterr = DID_ERROR; /* Couldn't find any better */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x14: /* Target bus phase sequence failure-An invalid bus phase or bus
|
|
|
|
phase sequence was requested by the target. The host adapter
|
|
|
|
will generate a SCSI Reset Condition, notifying the host with
|
|
|
|
a SCRD interrupt */
|
|
|
|
hosterr = DID_RESET;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printk(KERN_ERR "aha1542: makecode: unknown hoststatus %x\n", hosterr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return scsierr | (hosterr << 16);
|
|
|
|
}
|
|
|
|
|
2015-02-06 15:11:49 -07:00
|
|
|
static int aha1542_test_port(struct Scsi_Host *sh)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2015-02-06 15:11:27 -07:00
|
|
|
u8 inquiry_result[4];
|
2015-02-06 15:11:43 -07:00
|
|
|
int i;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* Quick and dirty test for presence of the card. */
|
2015-02-06 15:11:49 -07:00
|
|
|
if (inb(STATUS(sh->io_port)) == 0xff)
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Reset the adapter. I ought to make a hard reset, but it's not really necessary */
|
|
|
|
|
|
|
|
/* In case some other card was probing here, reset interrupts */
|
2015-02-06 15:11:49 -07:00
|
|
|
aha1542_intr_reset(sh->io_port); /* reset interrupts, so they don't block */
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:49 -07:00
|
|
|
outb(SRST | IRST /*|SCRST */ , CONTROL(sh->io_port));
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
mdelay(20); /* Wait a little bit for things to settle down. */
|
|
|
|
|
|
|
|
/* Expect INIT and IDLE, any of the others are bad */
|
2015-02-06 15:11:49 -07:00
|
|
|
if (!wait_mask(STATUS(sh->io_port), STATMASK, INIT | IDLE, STST | DIAGF | INVDCMD | DF | CDF, 0))
|
2015-02-06 15:11:34 -07:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* Shouldn't have generated any interrupts during reset */
|
2015-02-06 15:11:49 -07:00
|
|
|
if (inb(INTRFLAGS(sh->io_port)) & INTRMASK)
|
2015-02-06 15:11:34 -07:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* Perform a host adapter inquiry instead so we do not need to set
|
|
|
|
up the mailboxes ahead of time */
|
|
|
|
|
2015-02-06 15:11:49 -07:00
|
|
|
aha1542_outb(sh->io_port, CMD_INQUIRY);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:43 -07:00
|
|
|
for (i = 0; i < 4; i++) {
|
2015-02-06 15:11:49 -07:00
|
|
|
if (!wait_mask(STATUS(sh->io_port), DF, DF, 0, 0))
|
2015-02-06 15:11:34 -07:00
|
|
|
return 0;
|
2015-02-06 15:11:49 -07:00
|
|
|
inquiry_result[i] = inb(DATA(sh->io_port));
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Reading port should reset DF */
|
2015-02-06 15:11:49 -07:00
|
|
|
if (inb(STATUS(sh->io_port)) & DF)
|
2015-02-06 15:11:34 -07:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* When HACC, command is completed, and we're though testing */
|
2015-02-06 15:11:49 -07:00
|
|
|
if (!wait_mask(INTRFLAGS(sh->io_port), HACC, HACC, 0, 0))
|
2015-02-06 15:11:34 -07:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* Clear interrupts */
|
2015-02-06 15:11:49 -07:00
|
|
|
outb(IRST, CONTROL(sh->io_port));
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:35 -07:00
|
|
|
return 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2015-02-06 15:11:55 -07:00
|
|
|
static irqreturn_t aha1542_interrupt(int irq, void *dev_id)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2015-02-06 15:11:55 -07:00
|
|
|
struct Scsi_Host *sh = dev_id;
|
2015-02-06 15:11:45 -07:00
|
|
|
struct aha1542_hostdata *aha1542 = shost_priv(sh);
|
2015-02-06 15:11:44 -07:00
|
|
|
void (*my_done)(struct scsi_cmnd *) = NULL;
|
2005-04-16 16:20:36 -06:00
|
|
|
int errstatus, mbi, mbo, mbistatus;
|
|
|
|
int number_serviced;
|
|
|
|
unsigned long flags;
|
2015-02-06 15:11:44 -07:00
|
|
|
struct scsi_cmnd *tmp_cmd;
|
2005-04-16 16:20:36 -06:00
|
|
|
int flag;
|
2015-02-06 15:11:25 -07:00
|
|
|
struct mailbox *mb = aha1542->mb;
|
|
|
|
struct ccb *ccb = aha1542->ccb;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
2015-02-06 15:11:45 -07:00
|
|
|
flag = inb(INTRFLAGS(sh->io_port));
|
2015-02-06 15:11:51 -07:00
|
|
|
shost_printk(KERN_DEBUG, sh, "aha1542_intr_handle: ");
|
2005-04-16 16:20:36 -06:00
|
|
|
if (!(flag & ANYINTR))
|
|
|
|
printk("no interrupt?");
|
|
|
|
if (flag & MBIF)
|
|
|
|
printk("MBIF ");
|
|
|
|
if (flag & MBOA)
|
|
|
|
printk("MBOF ");
|
|
|
|
if (flag & HACC)
|
|
|
|
printk("HACC ");
|
|
|
|
if (flag & SCRD)
|
|
|
|
printk("SCRD ");
|
2015-02-06 15:11:45 -07:00
|
|
|
printk("status %02x\n", inb(STATUS(sh->io_port)));
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
number_serviced = 0;
|
|
|
|
|
2015-02-06 15:11:55 -07:00
|
|
|
spin_lock_irqsave(sh->host_lock, flags);
|
|
|
|
while (1) {
|
2015-02-06 15:11:45 -07:00
|
|
|
flag = inb(INTRFLAGS(sh->io_port));
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* Check for unusual interrupts. If any of these happen, we should
|
|
|
|
probably do something special, but for now just printing a message
|
|
|
|
is sufficient. A SCSI reset detected is something that we really
|
|
|
|
need to deal with in some way. */
|
|
|
|
if (flag & ~MBIF) {
|
|
|
|
if (flag & MBOA)
|
|
|
|
printk("MBOF ");
|
|
|
|
if (flag & HACC)
|
|
|
|
printk("HACC ");
|
2015-02-06 15:11:36 -07:00
|
|
|
if (flag & SCRD)
|
2005-04-16 16:20:36 -06:00
|
|
|
printk("SCRD ");
|
|
|
|
}
|
2015-02-06 15:11:45 -07:00
|
|
|
aha1542_intr_reset(sh->io_port);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:25 -07:00
|
|
|
mbi = aha1542->aha1542_last_mbi_used + 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
if (mbi >= 2 * AHA1542_MAILBOXES)
|
|
|
|
mbi = AHA1542_MAILBOXES;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (mb[mbi].status != 0)
|
|
|
|
break;
|
|
|
|
mbi++;
|
|
|
|
if (mbi >= 2 * AHA1542_MAILBOXES)
|
|
|
|
mbi = AHA1542_MAILBOXES;
|
2015-02-06 15:11:25 -07:00
|
|
|
} while (mbi != aha1542->aha1542_last_mbi_used);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
if (mb[mbi].status == 0) {
|
2015-02-06 15:11:55 -07:00
|
|
|
spin_unlock_irqrestore(sh->host_lock, flags);
|
2005-04-16 16:20:36 -06:00
|
|
|
/* Hmm, no mail. Must have read it the last time around */
|
2015-02-06 15:11:36 -07:00
|
|
|
if (!number_serviced)
|
2015-02-06 15:11:51 -07:00
|
|
|
shost_printk(KERN_WARNING, sh, "interrupt received, but no mail.\n");
|
2015-02-06 15:11:55 -07:00
|
|
|
return IRQ_HANDLED;
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
2015-02-06 15:11:24 -07:00
|
|
|
mbo = (scsi2int(mb[mbi].ccbptr) - (isa_virt_to_bus(&ccb[0]))) / sizeof(struct ccb);
|
2005-04-16 16:20:36 -06:00
|
|
|
mbistatus = mb[mbi].status;
|
|
|
|
mb[mbi].status = 0;
|
2015-02-06 15:11:25 -07:00
|
|
|
aha1542->aha1542_last_mbi_used = mbi;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2015-02-06 15:11:52 -07:00
|
|
|
if (ccb[mbo].tarstat | ccb[mbo].hastat)
|
|
|
|
shost_printk(KERN_DEBUG, sh, "aha1542_command: returning %x (status %d)\n",
|
|
|
|
ccb[mbo].tarstat + ((int) ccb[mbo].hastat << 16), mb[mbi].status);
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (mbistatus == 3)
|
|
|
|
continue; /* Aborted command not found */
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2015-02-06 15:11:51 -07:00
|
|
|
shost_printk(KERN_DEBUG, sh, "...done %d %d\n", mbo, mbi);
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
|
|
|
|
2015-02-06 15:11:44 -07:00
|
|
|
tmp_cmd = aha1542->int_cmds[mbo];
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:44 -07:00
|
|
|
if (!tmp_cmd || !tmp_cmd->scsi_done) {
|
2015-02-06 15:11:55 -07:00
|
|
|
spin_unlock_irqrestore(sh->host_lock, flags);
|
2015-02-06 15:11:51 -07:00
|
|
|
shost_printk(KERN_WARNING, sh, "Unexpected interrupt\n");
|
|
|
|
shost_printk(KERN_WARNING, sh, "tarstat=%x, hastat=%x idlun=%x ccb#=%d\n", ccb[mbo].tarstat,
|
2005-04-16 16:20:36 -06:00
|
|
|
ccb[mbo].hastat, ccb[mbo].idlun, mbo);
|
2015-02-06 15:11:55 -07:00
|
|
|
return IRQ_HANDLED;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2015-02-06 15:11:44 -07:00
|
|
|
my_done = tmp_cmd->scsi_done;
|
|
|
|
kfree(tmp_cmd->host_scribble);
|
|
|
|
tmp_cmd->host_scribble = NULL;
|
2005-04-16 16:20:36 -06:00
|
|
|
/* Fetch the sense data, and tuck it away, in the required slot. The
|
|
|
|
Adaptec automatically fetches it, and there is no guarantee that
|
|
|
|
we will still have it in the cdb when we come back */
|
|
|
|
if (ccb[mbo].tarstat == 2)
|
2015-02-06 15:11:44 -07:00
|
|
|
memcpy(tmp_cmd->sense_buffer, &ccb[mbo].cdb[ccb[mbo].cdblen],
|
2008-01-12 23:46:13 -07:00
|
|
|
SCSI_SENSE_BUFFERSIZE);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
|
|
|
|
/* is there mail :-) */
|
|
|
|
|
|
|
|
/* more error checking left out here */
|
|
|
|
if (mbistatus != 1)
|
|
|
|
/* This is surely wrong, but I don't know what's right */
|
|
|
|
errstatus = makecode(ccb[mbo].hastat, ccb[mbo].tarstat);
|
|
|
|
else
|
|
|
|
errstatus = 0;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (errstatus)
|
2015-02-06 15:11:51 -07:00
|
|
|
shost_printk(KERN_DEBUG, sh, "(aha1542 error:%x %x %x) ", errstatus,
|
2005-04-16 16:20:36 -06:00
|
|
|
ccb[mbo].hastat, ccb[mbo].tarstat);
|
2015-02-06 15:11:53 -07:00
|
|
|
if (ccb[mbo].tarstat == 2)
|
|
|
|
print_hex_dump_bytes("sense: ", DUMP_PREFIX_NONE, &ccb[mbo].cdb[ccb[mbo].cdblen], 12);
|
2015-02-06 15:11:52 -07:00
|
|
|
if (errstatus)
|
|
|
|
printk("aha1542_intr_handle: returning %6x\n", errstatus);
|
|
|
|
#endif
|
2015-02-06 15:11:44 -07:00
|
|
|
tmp_cmd->result = errstatus;
|
|
|
|
aha1542->int_cmds[mbo] = NULL; /* This effectively frees up the mailbox slot, as
|
2015-02-06 15:11:25 -07:00
|
|
|
far as queuecommand is concerned */
|
2015-02-06 15:11:44 -07:00
|
|
|
my_done(tmp_cmd);
|
2005-04-16 16:20:36 -06:00
|
|
|
number_serviced++;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-02-06 15:11:55 -07:00
|
|
|
static int aha1542_queuecommand(struct Scsi_Host *sh, struct scsi_cmnd *cmd)
|
2015-02-06 15:11:28 -07:00
|
|
|
{
|
2015-02-06 15:11:51 -07:00
|
|
|
struct aha1542_hostdata *aha1542 = shost_priv(sh);
|
2015-02-06 15:11:27 -07:00
|
|
|
u8 direction;
|
2015-02-06 15:11:44 -07:00
|
|
|
u8 target = cmd->device->id;
|
|
|
|
u8 lun = cmd->device->lun;
|
2005-04-16 16:20:36 -06:00
|
|
|
unsigned long flags;
|
2015-02-06 15:11:44 -07:00
|
|
|
int bufflen = scsi_bufflen(cmd);
|
2015-04-21 15:27:50 -06:00
|
|
|
int mbo, sg_count;
|
2015-02-06 15:11:25 -07:00
|
|
|
struct mailbox *mb = aha1542->mb;
|
|
|
|
struct ccb *ccb = aha1542->ccb;
|
2015-04-21 15:27:50 -06:00
|
|
|
struct chain *cptr;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:44 -07:00
|
|
|
if (*cmd->cmnd == REQUEST_SENSE) {
|
2005-04-16 16:20:36 -06:00
|
|
|
/* Don't do the command - we have the sense data already */
|
2015-02-06 15:11:44 -07:00
|
|
|
cmd->result = 0;
|
2015-02-06 15:11:55 -07:00
|
|
|
cmd->scsi_done(cmd);
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
2015-02-06 15:11:54 -07:00
|
|
|
{
|
|
|
|
int i = -1;
|
|
|
|
if (*cmd->cmnd == READ_10 || *cmd->cmnd == WRITE_10)
|
|
|
|
i = xscsi2int(cmd->cmnd + 2);
|
|
|
|
else if (*cmd->cmnd == READ_6 || *cmd->cmnd == WRITE_6)
|
|
|
|
i = scsi2int(cmd->cmnd + 2);
|
|
|
|
shost_printk(KERN_DEBUG, sh, "aha1542_queuecommand: dev %d cmd %02x pos %d len %d",
|
|
|
|
target, *cmd->cmnd, i, bufflen);
|
|
|
|
print_hex_dump_bytes("command: ", DUMP_PREFIX_NONE, cmd->cmnd, cmd->cmd_len);
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
2015-04-21 15:27:50 -06:00
|
|
|
if (bufflen) { /* allocate memory before taking host_lock */
|
|
|
|
sg_count = scsi_sg_count(cmd);
|
|
|
|
cptr = kmalloc(sizeof(*cptr) * sg_count, GFP_KERNEL | GFP_DMA);
|
|
|
|
if (!cptr)
|
|
|
|
return SCSI_MLQUEUE_HOST_BUSY;
|
2016-01-27 08:57:22 -07:00
|
|
|
} else {
|
|
|
|
sg_count = 0;
|
|
|
|
cptr = NULL;
|
2015-04-21 15:27:50 -06:00
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/* Use the outgoing mailboxes in a round-robin fashion, because this
|
|
|
|
is how the host adapter will scan for them */
|
|
|
|
|
2015-02-06 15:11:55 -07:00
|
|
|
spin_lock_irqsave(sh->host_lock, flags);
|
2015-02-06 15:11:25 -07:00
|
|
|
mbo = aha1542->aha1542_last_mbo_used + 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
if (mbo >= AHA1542_MAILBOXES)
|
|
|
|
mbo = 0;
|
|
|
|
|
|
|
|
do {
|
2015-02-06 15:11:44 -07:00
|
|
|
if (mb[mbo].status == 0 && aha1542->int_cmds[mbo] == NULL)
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
mbo++;
|
|
|
|
if (mbo >= AHA1542_MAILBOXES)
|
|
|
|
mbo = 0;
|
2015-02-06 15:11:25 -07:00
|
|
|
} while (mbo != aha1542->aha1542_last_mbo_used);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:44 -07:00
|
|
|
if (mb[mbo].status || aha1542->int_cmds[mbo])
|
2005-04-16 16:20:36 -06:00
|
|
|
panic("Unable to find empty mailbox for aha1542.\n");
|
|
|
|
|
2015-02-06 15:11:44 -07:00
|
|
|
aha1542->int_cmds[mbo] = cmd; /* This will effectively prevent someone else from
|
2015-02-06 15:11:25 -07:00
|
|
|
screwing with this cdb. */
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:25 -07:00
|
|
|
aha1542->aha1542_last_mbo_used = mbo;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2015-02-06 15:11:55 -07:00
|
|
|
shost_printk(KERN_DEBUG, sh, "Sending command (%d %p)...", mbo, cmd->scsi_done);
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
|
|
|
|
2015-02-06 15:11:24 -07:00
|
|
|
any2scsi(mb[mbo].ccbptr, isa_virt_to_bus(&ccb[mbo])); /* This gets trashed for some reason */
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
memset(&ccb[mbo], 0, sizeof(struct ccb));
|
|
|
|
|
2015-02-06 15:11:44 -07:00
|
|
|
ccb[mbo].cdblen = cmd->cmd_len;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
direction = 0;
|
2015-02-06 15:11:44 -07:00
|
|
|
if (*cmd->cmnd == READ_10 || *cmd->cmnd == READ_6)
|
2005-04-16 16:20:36 -06:00
|
|
|
direction = 8;
|
2015-02-06 15:11:44 -07:00
|
|
|
else if (*cmd->cmnd == WRITE_10 || *cmd->cmnd == WRITE_6)
|
2005-04-16 16:20:36 -06:00
|
|
|
direction = 16;
|
|
|
|
|
2015-02-06 15:11:44 -07:00
|
|
|
memcpy(ccb[mbo].cdb, cmd->cmnd, ccb[mbo].cdblen);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-09-09 12:02:45 -06:00
|
|
|
if (bufflen) {
|
2007-07-16 02:00:31 -06:00
|
|
|
struct scatterlist *sg;
|
2015-04-21 15:27:50 -06:00
|
|
|
int i;
|
2015-02-06 15:11:53 -07:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
ccb[mbo].op = 2; /* SCSI Initiator Command w/scatter-gather */
|
2015-04-21 15:27:50 -06:00
|
|
|
cmd->host_scribble = (void *)cptr;
|
2015-02-06 15:11:44 -07:00
|
|
|
scsi_for_each_sg(cmd, sg, sg_count, i) {
|
2015-02-06 15:11:24 -07:00
|
|
|
any2scsi(cptr[i].dataptr, isa_page_to_bus(sg_page(sg))
|
|
|
|
+ sg->offset);
|
2007-07-16 02:00:31 -06:00
|
|
|
any2scsi(cptr[i].datalen, sg->length);
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
2007-09-09 12:02:45 -06:00
|
|
|
any2scsi(ccb[mbo].datalen, sg_count * sizeof(struct chain));
|
2015-02-06 15:11:24 -07:00
|
|
|
any2scsi(ccb[mbo].dataptr, isa_virt_to_bus(cptr));
|
2005-04-16 16:20:36 -06:00
|
|
|
#ifdef DEBUG
|
2015-02-06 15:11:53 -07:00
|
|
|
shost_printk(KERN_DEBUG, sh, "cptr %p: ", cptr);
|
|
|
|
print_hex_dump_bytes("cptr: ", DUMP_PREFIX_NONE, cptr, 18);
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
ccb[mbo].op = 0; /* SCSI Initiator Command */
|
2015-02-06 15:11:44 -07:00
|
|
|
cmd->host_scribble = NULL;
|
2007-09-09 12:02:45 -06:00
|
|
|
any2scsi(ccb[mbo].datalen, 0);
|
|
|
|
any2scsi(ccb[mbo].dataptr, 0);
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
ccb[mbo].idlun = (target & 7) << 5 | direction | (lun & 7); /*SCSI Target Id */
|
|
|
|
ccb[mbo].rsalen = 16;
|
|
|
|
ccb[mbo].linkptr[0] = ccb[mbo].linkptr[1] = ccb[mbo].linkptr[2] = 0;
|
|
|
|
ccb[mbo].commlinkid = 0;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2015-02-06 15:11:53 -07:00
|
|
|
print_hex_dump_bytes("sending: ", DUMP_PREFIX_NONE, &ccb[mbo], sizeof(ccb[mbo]) - 10);
|
2015-02-06 15:11:55 -07:00
|
|
|
printk("aha1542_queuecommand: now waiting for interrupt ");
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
2015-02-06 15:11:55 -07:00
|
|
|
mb[mbo].status = 1;
|
|
|
|
aha1542_outb(cmd->device->host->io_port, CMD_START_SCSI);
|
|
|
|
spin_unlock_irqrestore(sh->host_lock, flags);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize mailboxes */
|
2015-02-06 15:11:49 -07:00
|
|
|
static void setup_mailboxes(struct Scsi_Host *sh)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2015-02-06 15:11:45 -07:00
|
|
|
struct aha1542_hostdata *aha1542 = shost_priv(sh);
|
2005-04-16 16:20:36 -06:00
|
|
|
int i;
|
2015-02-06 15:11:25 -07:00
|
|
|
struct mailbox *mb = aha1542->mb;
|
|
|
|
struct ccb *ccb = aha1542->ccb;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:43 -07:00
|
|
|
u8 mb_cmd[5] = { CMD_MBINIT, AHA1542_MAILBOXES, 0, 0, 0};
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
for (i = 0; i < AHA1542_MAILBOXES; i++) {
|
|
|
|
mb[i].status = mb[AHA1542_MAILBOXES + i].status = 0;
|
2015-02-06 15:11:24 -07:00
|
|
|
any2scsi(mb[i].ccbptr, isa_virt_to_bus(&ccb[i]));
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
2015-02-06 15:11:49 -07:00
|
|
|
aha1542_intr_reset(sh->io_port); /* reset interrupts, so they don't block */
|
2015-02-06 15:11:43 -07:00
|
|
|
any2scsi((mb_cmd + 2), isa_virt_to_bus(mb));
|
2015-02-06 15:11:49 -07:00
|
|
|
if (aha1542_out(sh->io_port, mb_cmd, 5))
|
2015-02-06 15:11:51 -07:00
|
|
|
shost_printk(KERN_ERR, sh, "failed setting up mailboxes\n");
|
2015-02-06 15:11:49 -07:00
|
|
|
aha1542_intr_reset(sh->io_port);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2015-02-06 15:11:49 -07:00
|
|
|
static int aha1542_getconfig(struct Scsi_Host *sh)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2015-02-06 15:11:27 -07:00
|
|
|
u8 inquiry_result[3];
|
2005-04-16 16:20:36 -06:00
|
|
|
int i;
|
2015-02-06 15:11:49 -07:00
|
|
|
i = inb(STATUS(sh->io_port));
|
2005-04-16 16:20:36 -06:00
|
|
|
if (i & DF) {
|
2015-02-06 15:11:49 -07:00
|
|
|
i = inb(DATA(sh->io_port));
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
2015-02-06 15:11:49 -07:00
|
|
|
aha1542_outb(sh->io_port, CMD_RETCONF);
|
|
|
|
aha1542_in(sh->io_port, inquiry_result, 3, 0);
|
|
|
|
if (!wait_mask(INTRFLAGS(sh->io_port), INTRMASK, HACC, 0, 0))
|
2015-02-06 15:11:51 -07:00
|
|
|
shost_printk(KERN_ERR, sh, "error querying board settings\n");
|
2015-02-06 15:11:49 -07:00
|
|
|
aha1542_intr_reset(sh->io_port);
|
2005-04-16 16:20:36 -06:00
|
|
|
switch (inquiry_result[0]) {
|
|
|
|
case 0x80:
|
2015-02-06 15:11:49 -07:00
|
|
|
sh->dma_channel = 7;
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
case 0x40:
|
2015-02-06 15:11:49 -07:00
|
|
|
sh->dma_channel = 6;
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
case 0x20:
|
2015-02-06 15:11:49 -07:00
|
|
|
sh->dma_channel = 5;
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
case 0x01:
|
2015-02-06 15:11:49 -07:00
|
|
|
sh->dma_channel = 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
/* This means that the adapter, although Adaptec 1542 compatible, doesn't use a DMA channel.
|
|
|
|
Currently only aware of the BusLogic BT-445S VL-Bus adapter which needs this. */
|
2015-02-06 15:11:49 -07:00
|
|
|
sh->dma_channel = 0xFF;
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
default:
|
2015-02-06 15:11:51 -07:00
|
|
|
shost_printk(KERN_ERR, sh, "Unable to determine DMA channel.\n");
|
2005-04-16 16:20:36 -06:00
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
switch (inquiry_result[1]) {
|
|
|
|
case 0x40:
|
2015-02-06 15:11:49 -07:00
|
|
|
sh->irq = 15;
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
case 0x20:
|
2015-02-06 15:11:49 -07:00
|
|
|
sh->irq = 14;
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
case 0x8:
|
2015-02-06 15:11:49 -07:00
|
|
|
sh->irq = 12;
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
case 0x4:
|
2015-02-06 15:11:49 -07:00
|
|
|
sh->irq = 11;
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
case 0x2:
|
2015-02-06 15:11:49 -07:00
|
|
|
sh->irq = 10;
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
case 0x1:
|
2015-02-06 15:11:49 -07:00
|
|
|
sh->irq = 9;
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
default:
|
2015-02-06 15:11:51 -07:00
|
|
|
shost_printk(KERN_ERR, sh, "Unable to determine IRQ level.\n");
|
2005-04-16 16:20:36 -06:00
|
|
|
return -1;
|
|
|
|
};
|
2015-02-06 15:11:49 -07:00
|
|
|
sh->this_id = inquiry_result[2] & 7;
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This function should only be called for 1542C boards - we can detect
|
|
|
|
the special firmware settings and unlock the board */
|
|
|
|
|
2015-02-06 15:11:49 -07:00
|
|
|
static int aha1542_mbenable(struct Scsi_Host *sh)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2015-02-06 15:11:27 -07:00
|
|
|
static u8 mbenable_cmd[3];
|
|
|
|
static u8 mbenable_result[2];
|
2005-04-16 16:20:36 -06:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
retval = BIOS_TRANSLATION_6432;
|
|
|
|
|
2015-02-06 15:11:49 -07:00
|
|
|
aha1542_outb(sh->io_port, CMD_EXTBIOS);
|
|
|
|
if (aha1542_in(sh->io_port, mbenable_result, 2, 100))
|
2005-04-16 16:20:36 -06:00
|
|
|
return retval;
|
2015-02-06 15:11:49 -07:00
|
|
|
if (!wait_mask(INTRFLAGS(sh->io_port), INTRMASK, HACC, 0, 100))
|
2015-02-06 15:11:31 -07:00
|
|
|
goto fail;
|
2015-02-06 15:11:49 -07:00
|
|
|
aha1542_intr_reset(sh->io_port);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
if ((mbenable_result[0] & 0x08) || mbenable_result[1]) {
|
|
|
|
mbenable_cmd[0] = CMD_MBENABLE;
|
|
|
|
mbenable_cmd[1] = 0;
|
|
|
|
mbenable_cmd[2] = mbenable_result[1];
|
|
|
|
|
|
|
|
if ((mbenable_result[0] & 0x08) && (mbenable_result[1] & 0x03))
|
|
|
|
retval = BIOS_TRANSLATION_25563;
|
|
|
|
|
2015-02-06 15:11:49 -07:00
|
|
|
if (aha1542_out(sh->io_port, mbenable_cmd, 3))
|
2015-02-06 15:11:31 -07:00
|
|
|
goto fail;
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
while (0) {
|
|
|
|
fail:
|
2015-02-06 15:11:51 -07:00
|
|
|
shost_printk(KERN_ERR, sh, "Mailbox init failed\n");
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2015-02-06 15:11:49 -07:00
|
|
|
aha1542_intr_reset(sh->io_port);
|
2005-04-16 16:20:36 -06:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Query the board to find out if it is a 1542 or a 1740, or whatever. */
|
2015-02-06 15:11:49 -07:00
|
|
|
static int aha1542_query(struct Scsi_Host *sh)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2015-02-06 15:11:49 -07:00
|
|
|
struct aha1542_hostdata *aha1542 = shost_priv(sh);
|
2015-02-06 15:11:27 -07:00
|
|
|
u8 inquiry_result[4];
|
2005-04-16 16:20:36 -06:00
|
|
|
int i;
|
2015-02-06 15:11:49 -07:00
|
|
|
i = inb(STATUS(sh->io_port));
|
2005-04-16 16:20:36 -06:00
|
|
|
if (i & DF) {
|
2015-02-06 15:11:49 -07:00
|
|
|
i = inb(DATA(sh->io_port));
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
2015-02-06 15:11:49 -07:00
|
|
|
aha1542_outb(sh->io_port, CMD_INQUIRY);
|
|
|
|
aha1542_in(sh->io_port, inquiry_result, 4, 0);
|
|
|
|
if (!wait_mask(INTRFLAGS(sh->io_port), INTRMASK, HACC, 0, 0))
|
2015-02-06 15:11:51 -07:00
|
|
|
shost_printk(KERN_ERR, sh, "error querying card type\n");
|
2015-02-06 15:11:49 -07:00
|
|
|
aha1542_intr_reset(sh->io_port);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:49 -07:00
|
|
|
aha1542->bios_translation = BIOS_TRANSLATION_6432; /* Default case */
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* For an AHA1740 series board, we ignore the board since there is a
|
|
|
|
hardware bug which can lead to wrong blocks being returned if the board
|
|
|
|
is operating in the 1542 emulation mode. Since there is an extended mode
|
|
|
|
driver, we simply ignore the board and let the 1740 driver pick it up.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (inquiry_result[0] == 0x43) {
|
2015-02-06 15:11:51 -07:00
|
|
|
shost_printk(KERN_INFO, sh, "Emulation mode not supported for AHA-1740 hardware, use aha1740 driver instead.\n");
|
2005-04-16 16:20:36 -06:00
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Always call this - boards that do not support extended bios translation
|
|
|
|
will ignore the command, and we will set the proper default */
|
|
|
|
|
2015-02-06 15:11:49 -07:00
|
|
|
aha1542->bios_translation = aha1542_mbenable(sh);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-06 15:11:41 -07:00
|
|
|
static u8 dma_speed_hw(int dma_speed)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2015-02-06 15:11:41 -07:00
|
|
|
switch (dma_speed) {
|
|
|
|
case 5:
|
|
|
|
return 0x00;
|
|
|
|
case 6:
|
|
|
|
return 0x04;
|
|
|
|
case 7:
|
|
|
|
return 0x01;
|
|
|
|
case 8:
|
|
|
|
return 0x02;
|
|
|
|
case 10:
|
|
|
|
return 0x03;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2015-02-06 15:11:41 -07:00
|
|
|
return 0xff; /* invalid */
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2015-02-06 15:11:41 -07:00
|
|
|
/* Set the Bus on/off-times as not to ruin floppy performance */
|
2015-02-06 15:11:50 -07:00
|
|
|
static void aha1542_set_bus_times(struct Scsi_Host *sh, int bus_on, int bus_off, int dma_speed)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2015-02-06 15:11:50 -07:00
|
|
|
if (bus_on > 0) {
|
|
|
|
u8 oncmd[] = { CMD_BUSON_TIME, clamp(bus_on, 2, 15) };
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:50 -07:00
|
|
|
aha1542_intr_reset(sh->io_port);
|
|
|
|
if (aha1542_out(sh->io_port, oncmd, 2))
|
2015-02-06 15:11:41 -07:00
|
|
|
goto fail;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:50 -07:00
|
|
|
if (bus_off > 0) {
|
|
|
|
u8 offcmd[] = { CMD_BUSOFF_TIME, clamp(bus_off, 1, 64) };
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:50 -07:00
|
|
|
aha1542_intr_reset(sh->io_port);
|
|
|
|
if (aha1542_out(sh->io_port, offcmd, 2))
|
2015-02-06 15:11:41 -07:00
|
|
|
goto fail;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:50 -07:00
|
|
|
if (dma_speed_hw(dma_speed) != 0xff) {
|
|
|
|
u8 dmacmd[] = { CMD_DMASPEED, dma_speed_hw(dma_speed) };
|
2015-02-06 15:11:38 -07:00
|
|
|
|
2015-02-06 15:11:50 -07:00
|
|
|
aha1542_intr_reset(sh->io_port);
|
|
|
|
if (aha1542_out(sh->io_port, dmacmd, 2))
|
2015-02-06 15:11:38 -07:00
|
|
|
goto fail;
|
|
|
|
}
|
2015-02-06 15:11:50 -07:00
|
|
|
aha1542_intr_reset(sh->io_port);
|
2015-02-06 15:11:38 -07:00
|
|
|
return;
|
|
|
|
fail:
|
2015-02-06 15:11:51 -07:00
|
|
|
shost_printk(KERN_ERR, sh, "setting bus on/off-time failed\n");
|
2015-02-06 15:11:50 -07:00
|
|
|
aha1542_intr_reset(sh->io_port);
|
2015-02-06 15:11:38 -07:00
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/* return non-zero on detection */
|
2015-02-06 15:11:22 -07:00
|
|
|
static struct Scsi_Host *aha1542_hw_init(struct scsi_host_template *tpnt, struct device *pdev, int indx)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2015-02-06 15:11:41 -07:00
|
|
|
unsigned int base_io = io[indx];
|
2015-02-06 15:11:45 -07:00
|
|
|
struct Scsi_Host *sh;
|
2015-02-06 15:11:25 -07:00
|
|
|
struct aha1542_hostdata *aha1542;
|
2015-02-06 15:11:51 -07:00
|
|
|
char dma_info[] = "no DMA";
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:40 -07:00
|
|
|
if (base_io == 0)
|
|
|
|
return NULL;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:40 -07:00
|
|
|
if (!request_region(base_io, AHA1542_REGION_SIZE, "aha1542"))
|
|
|
|
return NULL;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:45 -07:00
|
|
|
sh = scsi_host_alloc(tpnt, sizeof(struct aha1542_hostdata));
|
|
|
|
if (!sh)
|
2015-02-06 15:11:40 -07:00
|
|
|
goto release;
|
2015-02-06 15:11:45 -07:00
|
|
|
aha1542 = shost_priv(sh);
|
2015-02-06 15:11:38 -07:00
|
|
|
|
2015-02-06 15:11:49 -07:00
|
|
|
sh->unique_id = base_io;
|
|
|
|
sh->io_port = base_io;
|
|
|
|
sh->n_io_port = AHA1542_REGION_SIZE;
|
|
|
|
aha1542->aha1542_last_mbi_used = 2 * AHA1542_MAILBOXES - 1;
|
|
|
|
aha1542->aha1542_last_mbo_used = AHA1542_MAILBOXES - 1;
|
|
|
|
|
|
|
|
if (!aha1542_test_port(sh))
|
2015-02-06 15:11:40 -07:00
|
|
|
goto unregister;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:50 -07:00
|
|
|
aha1542_set_bus_times(sh, bus_on[indx], bus_off[indx], dma_speed[indx]);
|
2015-02-06 15:11:49 -07:00
|
|
|
if (aha1542_query(sh))
|
2015-02-06 15:11:40 -07:00
|
|
|
goto unregister;
|
2015-02-06 15:11:49 -07:00
|
|
|
if (aha1542_getconfig(sh) == -1)
|
2015-02-06 15:11:40 -07:00
|
|
|
goto unregister;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:45 -07:00
|
|
|
if (sh->dma_channel != 0xFF)
|
2015-02-06 15:11:51 -07:00
|
|
|
snprintf(dma_info, sizeof(dma_info), "DMA %d", sh->dma_channel);
|
|
|
|
shost_printk(KERN_INFO, sh, "Adaptec AHA-1542 (SCSI-ID %d) at IO 0x%x, IRQ %d, %s\n",
|
|
|
|
sh->this_id, base_io, sh->irq, dma_info);
|
2015-02-06 15:11:40 -07:00
|
|
|
if (aha1542->bios_translation == BIOS_TRANSLATION_25563)
|
2015-02-06 15:11:51 -07:00
|
|
|
shost_printk(KERN_INFO, sh, "Using extended bios translation\n");
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:49 -07:00
|
|
|
setup_mailboxes(sh);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:55 -07:00
|
|
|
if (request_irq(sh->irq, aha1542_interrupt, 0, "aha1542", sh)) {
|
2015-02-06 15:11:51 -07:00
|
|
|
shost_printk(KERN_ERR, sh, "Unable to allocate IRQ.\n");
|
2015-02-06 15:11:40 -07:00
|
|
|
goto unregister;
|
|
|
|
}
|
2015-02-06 15:11:45 -07:00
|
|
|
if (sh->dma_channel != 0xFF) {
|
|
|
|
if (request_dma(sh->dma_channel, "aha1542")) {
|
2015-02-06 15:11:51 -07:00
|
|
|
shost_printk(KERN_ERR, sh, "Unable to allocate DMA channel.\n");
|
2015-02-06 15:11:40 -07:00
|
|
|
goto free_irq;
|
|
|
|
}
|
2015-02-06 15:11:45 -07:00
|
|
|
if (sh->dma_channel == 0 || sh->dma_channel >= 5) {
|
|
|
|
set_dma_mode(sh->dma_channel, DMA_MODE_CASCADE);
|
|
|
|
enable_dma(sh->dma_channel);
|
2015-02-06 15:11:40 -07:00
|
|
|
}
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:45 -07:00
|
|
|
if (scsi_add_host(sh, pdev))
|
2015-02-06 15:11:40 -07:00
|
|
|
goto free_dma;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:45 -07:00
|
|
|
scsi_scan_host(sh);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:45 -07:00
|
|
|
return sh;
|
2015-02-06 15:11:40 -07:00
|
|
|
free_dma:
|
2015-02-06 15:11:45 -07:00
|
|
|
if (sh->dma_channel != 0xff)
|
|
|
|
free_dma(sh->dma_channel);
|
2015-02-06 15:11:40 -07:00
|
|
|
free_irq:
|
2015-02-06 15:11:45 -07:00
|
|
|
free_irq(sh->irq, sh);
|
2015-02-06 15:11:40 -07:00
|
|
|
unregister:
|
2015-02-06 15:11:45 -07:00
|
|
|
scsi_host_put(sh);
|
2015-02-06 15:11:40 -07:00
|
|
|
release:
|
|
|
|
release_region(base_io, AHA1542_REGION_SIZE);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:22 -07:00
|
|
|
return NULL;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2015-02-06 15:11:45 -07:00
|
|
|
static int aha1542_release(struct Scsi_Host *sh)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2015-02-06 15:11:45 -07:00
|
|
|
scsi_remove_host(sh);
|
|
|
|
if (sh->dma_channel != 0xff)
|
|
|
|
free_dma(sh->dma_channel);
|
|
|
|
if (sh->irq)
|
|
|
|
free_irq(sh->irq, sh);
|
|
|
|
if (sh->io_port && sh->n_io_port)
|
|
|
|
release_region(sh->io_port, sh->n_io_port);
|
|
|
|
scsi_host_put(sh);
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a device reset. This is handled by sending a special command
|
|
|
|
* to the device.
|
|
|
|
*/
|
2015-02-06 15:11:44 -07:00
|
|
|
static int aha1542_dev_reset(struct scsi_cmnd *cmd)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2015-02-06 15:11:55 -07:00
|
|
|
struct Scsi_Host *sh = cmd->device->host;
|
|
|
|
struct aha1542_hostdata *aha1542 = shost_priv(sh);
|
2005-04-16 16:20:36 -06:00
|
|
|
unsigned long flags;
|
2015-02-06 15:11:25 -07:00
|
|
|
struct mailbox *mb = aha1542->mb;
|
2015-02-06 15:11:44 -07:00
|
|
|
u8 target = cmd->device->id;
|
|
|
|
u8 lun = cmd->device->lun;
|
2005-04-16 16:20:36 -06:00
|
|
|
int mbo;
|
2015-02-06 15:11:25 -07:00
|
|
|
struct ccb *ccb = aha1542->ccb;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:55 -07:00
|
|
|
spin_lock_irqsave(sh->host_lock, flags);
|
2015-02-06 15:11:25 -07:00
|
|
|
mbo = aha1542->aha1542_last_mbo_used + 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
if (mbo >= AHA1542_MAILBOXES)
|
|
|
|
mbo = 0;
|
|
|
|
|
|
|
|
do {
|
2015-02-06 15:11:44 -07:00
|
|
|
if (mb[mbo].status == 0 && aha1542->int_cmds[mbo] == NULL)
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
mbo++;
|
|
|
|
if (mbo >= AHA1542_MAILBOXES)
|
|
|
|
mbo = 0;
|
2015-02-06 15:11:25 -07:00
|
|
|
} while (mbo != aha1542->aha1542_last_mbo_used);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:44 -07:00
|
|
|
if (mb[mbo].status || aha1542->int_cmds[mbo])
|
2005-04-16 16:20:36 -06:00
|
|
|
panic("Unable to find empty mailbox for aha1542.\n");
|
|
|
|
|
2015-02-06 15:11:44 -07:00
|
|
|
aha1542->int_cmds[mbo] = cmd; /* This will effectively
|
2015-02-06 15:11:25 -07:00
|
|
|
prevent someone else from
|
|
|
|
screwing with this cdb. */
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:25 -07:00
|
|
|
aha1542->aha1542_last_mbo_used = mbo;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:24 -07:00
|
|
|
any2scsi(mb[mbo].ccbptr, isa_virt_to_bus(&ccb[mbo])); /* This gets trashed for some reason */
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
memset(&ccb[mbo], 0, sizeof(struct ccb));
|
|
|
|
|
|
|
|
ccb[mbo].op = 0x81; /* BUS DEVICE RESET */
|
|
|
|
|
|
|
|
ccb[mbo].idlun = (target & 7) << 5 | (lun & 7); /*SCSI Target Id */
|
|
|
|
|
|
|
|
ccb[mbo].linkptr[0] = ccb[mbo].linkptr[1] = ccb[mbo].linkptr[2] = 0;
|
|
|
|
ccb[mbo].commlinkid = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now tell the 1542 to flush all pending commands for this
|
|
|
|
* target
|
|
|
|
*/
|
2015-02-06 15:11:55 -07:00
|
|
|
aha1542_outb(sh->io_port, CMD_START_SCSI);
|
|
|
|
spin_unlock_irqrestore(sh->host_lock, flags);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:44 -07:00
|
|
|
scmd_printk(KERN_WARNING, cmd,
|
2005-10-24 16:04:36 -06:00
|
|
|
"Trying device reset for target\n");
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2015-02-06 15:11:44 -07:00
|
|
|
static int aha1542_reset(struct scsi_cmnd *cmd, u8 reset_cmd)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2015-02-06 15:11:55 -07:00
|
|
|
struct Scsi_Host *sh = cmd->device->host;
|
|
|
|
struct aha1542_hostdata *aha1542 = shost_priv(sh);
|
|
|
|
unsigned long flags;
|
2005-04-16 16:20:36 -06:00
|
|
|
int i;
|
|
|
|
|
2015-02-06 15:11:55 -07:00
|
|
|
spin_lock_irqsave(sh->host_lock, flags);
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* This does a scsi reset for all devices on the bus.
|
|
|
|
* In principle, we could also reset the 1542 - should
|
|
|
|
* we do this? Try this first, and we can add that later
|
|
|
|
* if it turns out to be useful.
|
|
|
|
*/
|
2015-02-06 15:11:44 -07:00
|
|
|
outb(reset_cmd, CONTROL(cmd->device->host->io_port));
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:44 -07:00
|
|
|
if (!wait_mask(STATUS(cmd->device->host->io_port),
|
2015-02-06 15:11:56 -07:00
|
|
|
STATMASK, IDLE, STST | DIAGF | INVDCMD | DF | CDF, 0)) {
|
2015-02-06 15:11:55 -07:00
|
|
|
spin_unlock_irqrestore(sh->host_lock, flags);
|
2015-02-06 15:11:34 -07:00
|
|
|
return FAILED;
|
|
|
|
}
|
2015-02-06 15:11:55 -07:00
|
|
|
|
2015-02-06 15:11:37 -07:00
|
|
|
/*
|
|
|
|
* We need to do this too before the 1542 can interact with
|
|
|
|
* us again after host reset.
|
|
|
|
*/
|
|
|
|
if (reset_cmd & HRST)
|
2015-02-06 15:11:49 -07:00
|
|
|
setup_mailboxes(cmd->device->host);
|
2015-02-06 15:11:55 -07:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Now try to pick up the pieces. For all pending commands,
|
|
|
|
* free any internal data structures, and basically clear things
|
|
|
|
* out. We do not try and restart any commands or anything -
|
|
|
|
* the strategy handler takes care of that crap.
|
|
|
|
*/
|
2015-02-06 15:11:51 -07:00
|
|
|
shost_printk(KERN_WARNING, cmd->device->host, "Sent BUS RESET to scsi host %d\n", cmd->device->host->host_no);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
for (i = 0; i < AHA1542_MAILBOXES; i++) {
|
2015-02-06 15:11:44 -07:00
|
|
|
if (aha1542->int_cmds[i] != NULL) {
|
|
|
|
struct scsi_cmnd *tmp_cmd;
|
|
|
|
tmp_cmd = aha1542->int_cmds[i];
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:44 -07:00
|
|
|
if (tmp_cmd->device->soft_reset) {
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* If this device implements the soft reset option,
|
|
|
|
* then it is still holding onto the command, and
|
|
|
|
* may yet complete it. In this case, we don't
|
|
|
|
* flush the data.
|
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
}
|
2015-02-06 15:11:44 -07:00
|
|
|
kfree(tmp_cmd->host_scribble);
|
|
|
|
tmp_cmd->host_scribble = NULL;
|
|
|
|
aha1542->int_cmds[i] = NULL;
|
2015-02-06 15:11:25 -07:00
|
|
|
aha1542->mb[i].status = 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-06 15:11:55 -07:00
|
|
|
spin_unlock_irqrestore(sh->host_lock, flags);
|
2005-04-16 16:20:36 -06:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2015-02-06 15:11:44 -07:00
|
|
|
static int aha1542_bus_reset(struct scsi_cmnd *cmd)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2015-02-06 15:11:44 -07:00
|
|
|
return aha1542_reset(cmd, SCRST);
|
2015-02-06 15:11:37 -07:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:44 -07:00
|
|
|
static int aha1542_host_reset(struct scsi_cmnd *cmd)
|
2015-02-06 15:11:37 -07:00
|
|
|
{
|
2015-02-06 15:11:44 -07:00
|
|
|
return aha1542_reset(cmd, HRST | SCRST);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int aha1542_biosparam(struct scsi_device *sdev,
|
2015-02-06 15:11:42 -07:00
|
|
|
struct block_device *bdev, sector_t capacity, int geom[])
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2015-02-06 15:11:25 -07:00
|
|
|
struct aha1542_hostdata *aha1542 = shost_priv(sdev->host);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-02-06 15:11:42 -07:00
|
|
|
if (capacity >= 0x200000 &&
|
|
|
|
aha1542->bios_translation == BIOS_TRANSLATION_25563) {
|
2005-04-16 16:20:36 -06:00
|
|
|
/* Please verify that this is the same as what DOS returns */
|
2015-02-06 15:11:42 -07:00
|
|
|
geom[0] = 255; /* heads */
|
|
|
|
geom[1] = 63; /* sectors */
|
2005-04-16 16:20:36 -06:00
|
|
|
} else {
|
2015-02-06 15:11:42 -07:00
|
|
|
geom[0] = 64; /* heads */
|
|
|
|
geom[1] = 32; /* sectors */
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2015-02-06 15:11:42 -07:00
|
|
|
geom[2] = sector_div(capacity, geom[0] * geom[1]); /* cylinders */
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2005-10-31 10:31:40 -07:00
|
|
|
static struct scsi_host_template driver_template = {
|
2015-02-06 15:11:22 -07:00
|
|
|
.module = THIS_MODULE,
|
2005-04-16 16:20:36 -06:00
|
|
|
.proc_name = "aha1542",
|
|
|
|
.name = "Adaptec 1542",
|
|
|
|
.queuecommand = aha1542_queuecommand,
|
|
|
|
.eh_device_reset_handler= aha1542_dev_reset,
|
|
|
|
.eh_bus_reset_handler = aha1542_bus_reset,
|
|
|
|
.eh_host_reset_handler = aha1542_host_reset,
|
|
|
|
.bios_param = aha1542_biosparam,
|
|
|
|
.can_queue = AHA1542_MAILBOXES,
|
|
|
|
.this_id = 7,
|
2015-02-06 15:11:24 -07:00
|
|
|
.sg_tablesize = 16,
|
2005-04-16 16:20:36 -06:00
|
|
|
.unchecked_isa_dma = 1,
|
|
|
|
.use_clustering = ENABLE_CLUSTERING,
|
|
|
|
};
|
2015-02-06 15:11:22 -07:00
|
|
|
|
|
|
|
static int aha1542_isa_match(struct device *pdev, unsigned int ndev)
|
|
|
|
{
|
|
|
|
struct Scsi_Host *sh = aha1542_hw_init(&driver_template, pdev, ndev);
|
|
|
|
|
|
|
|
if (!sh)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
dev_set_drvdata(pdev, sh);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int aha1542_isa_remove(struct device *pdev,
|
|
|
|
unsigned int ndev)
|
|
|
|
{
|
|
|
|
aha1542_release(dev_get_drvdata(pdev));
|
|
|
|
dev_set_drvdata(pdev, NULL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct isa_driver aha1542_isa_driver = {
|
|
|
|
.match = aha1542_isa_match,
|
|
|
|
.remove = aha1542_isa_remove,
|
|
|
|
.driver = {
|
|
|
|
.name = "aha1542"
|
|
|
|
},
|
|
|
|
};
|
|
|
|
static int isa_registered;
|
|
|
|
|
|
|
|
#ifdef CONFIG_PNP
|
|
|
|
static struct pnp_device_id aha1542_pnp_ids[] = {
|
|
|
|
{ .id = "ADP1542" },
|
|
|
|
{ .id = "" }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(pnp, aha1542_pnp_ids);
|
|
|
|
|
|
|
|
static int aha1542_pnp_probe(struct pnp_dev *pdev, const struct pnp_device_id *id)
|
|
|
|
{
|
|
|
|
int indx;
|
|
|
|
struct Scsi_Host *sh;
|
|
|
|
|
2015-02-06 15:11:41 -07:00
|
|
|
for (indx = 0; indx < ARRAY_SIZE(io); indx++) {
|
|
|
|
if (io[indx])
|
2015-02-06 15:11:22 -07:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (pnp_activate_dev(pdev) < 0)
|
|
|
|
continue;
|
|
|
|
|
2015-02-06 15:11:41 -07:00
|
|
|
io[indx] = pnp_port_start(pdev, 0);
|
2015-02-06 15:11:22 -07:00
|
|
|
|
|
|
|
/* The card can be queried for its DMA, we have
|
|
|
|
the DMA set up that is enough */
|
|
|
|
|
2015-02-06 15:11:51 -07:00
|
|
|
dev_info(&pdev->dev, "ISAPnP found an AHA1535 at I/O 0x%03X", io[indx]);
|
2015-02-06 15:11:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
sh = aha1542_hw_init(&driver_template, &pdev->dev, indx);
|
|
|
|
if (!sh)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
pnp_set_drvdata(pdev, sh);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void aha1542_pnp_remove(struct pnp_dev *pdev)
|
|
|
|
{
|
|
|
|
aha1542_release(pnp_get_drvdata(pdev));
|
|
|
|
pnp_set_drvdata(pdev, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct pnp_driver aha1542_pnp_driver = {
|
|
|
|
.name = "aha1542",
|
|
|
|
.id_table = aha1542_pnp_ids,
|
|
|
|
.probe = aha1542_pnp_probe,
|
|
|
|
.remove = aha1542_pnp_remove,
|
|
|
|
};
|
|
|
|
static int pnp_registered;
|
|
|
|
#endif /* CONFIG_PNP */
|
|
|
|
|
|
|
|
static int __init aha1542_init(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
#ifdef CONFIG_PNP
|
|
|
|
if (isapnp) {
|
|
|
|
ret = pnp_register_driver(&aha1542_pnp_driver);
|
|
|
|
if (!ret)
|
|
|
|
pnp_registered = 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
ret = isa_register_driver(&aha1542_isa_driver, MAXBOARDS);
|
|
|
|
if (!ret)
|
|
|
|
isa_registered = 1;
|
|
|
|
|
|
|
|
#ifdef CONFIG_PNP
|
|
|
|
if (pnp_registered)
|
|
|
|
ret = 0;
|
|
|
|
#endif
|
|
|
|
if (isa_registered)
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit aha1542_exit(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_PNP
|
|
|
|
if (pnp_registered)
|
|
|
|
pnp_unregister_driver(&aha1542_pnp_driver);
|
|
|
|
#endif
|
|
|
|
if (isa_registered)
|
|
|
|
isa_unregister_driver(&aha1542_isa_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(aha1542_init);
|
|
|
|
module_exit(aha1542_exit);
|