📄 aha1542.c
字号:
/* $Id: aha1542.c,v 1.1 1999/04/26 05:54:11 tb Exp $ * linux/kernel/aha1542.c * * Copyright (C) 1992 Tommy Thorn * Copyright (C) 1993, 1994, 1995 Eric Youngdale * * Modified by Eric Youngdale * Use request_irq and request_dma to help prevent unexpected conflicts * Set up on-board DMA controller, such that we do not have to * have the bios enabled to use the aha1542. * Modified by David Gentzel * Don't call request_dma if dma mask is 0 (for BusLogic BT-445S VL-Bus * controller). * Modified by Matti Aarnio * Accept parameters from LILO cmd-line. -- 1-Oct-94 * Modified by Mike McLagan <mike.mclagan@linux.org> * Recognise extended mode on AHA1542CP, different bit than 1542CF * 1-Jan-97 * Modified by Bjorn L. Thordarson and Einar Thor Einarsson * Recognize that DMA0 is valid DMA channel -- 13-Jul-98 */#include <linux/module.h>#include <linux/kernel.h>#include <linux/head.h>#include <linux/types.h>#include <linux/string.h>#include <linux/ioport.h>#include <linux/delay.h>#include <linux/sched.h>#include <linux/proc_fs.h>#include <asm/dma.h>#include <asm/system.h>#include <asm/io.h>#include <linux/blk.h>#include "scsi.h"#include "hosts.h"#include "aha1542.h"#include<linux/stat.h>struct proc_dir_entry proc_scsi_aha1542 = { PROC_SCSI_AHA1542, 7, "aha1542", S_IFDIR | S_IRUGO | S_IXUGO, 2};#ifdef DEBUG#define DEB(x) x#else#define DEB(x)#endif/*static const char RCSid[] = "$Header: /cvsroot/hurd/gnumach/linux/src/drivers/scsi/Attic/aha1542.c,v 1.1 1999/04/26 05:54:11 tb Exp $";*//* The adaptec can be configured for quite a number of addresses, butI generally do not want the card poking around at random. We allowtwo addresses - this allows people to use the Adaptec with a Midicard, which also used 0x330 -- can be overridden with LILO! */#define MAXBOARDS 2 /* Increase this and the sizes of the arrays below, if you need more.. */static unsigned int bases[MAXBOARDS]={0x330, 0x334};/* set by aha1542_setup according to the command line */static int setup_called[MAXBOARDS] = {0,0};static int setup_buson[MAXBOARDS] = {0,0};static int setup_busoff[MAXBOARDS] = {0,0};static int setup_dmaspeed[MAXBOARDS] = {-1,-1};static char *setup_str[MAXBOARDS] = {(char *)NULL,(char *)NULL};/* * LILO params: aha1542=<PORTBASE>[,<BUSON>,<BUSOFF>[,<DMASPEED>]] * * Where: <PORTBASE> is any of the valid AHA addresses: * 0x130, 0x134, 0x230, 0x234, 0x330, 0x334 * <BUSON> is the time (in microsecs) that AHA spends on the AT-bus * when transferring data. 1542A power-on default is 11us, * valid values are in range: 2..15 (decimal) * <BUSOFF> is the time that AHA spends OFF THE BUS after while * it is transferring data (not to monopolize the bus). * Power-on default is 4us, valid range: 1..64 microseconds. * <DMASPEED> Default is jumper selected (1542A: on the J1), * but experimenter can alter it with this. * Valid values: 5, 6, 7, 8, 10 (MB/s) * Factory default is 5 MB/s. */#define BIOS_TRANSLATION_1632 0 /* Used by some old 1542A boards */#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; Scsi_Cmnd * SCint[AHA1542_MAILBOXES]; struct mailbox mb[2*AHA1542_MAILBOXES]; struct ccb ccb[AHA1542_MAILBOXES];};#define HOSTDATA(host) ((struct aha1542_hostdata *) &host->hostdata)static struct Scsi_Host * aha_host[7] = {NULL,}; /* One for each IRQ level (9-15) */#define WAITnexttimeout 3000000static void setup_mailboxes(int base_io, struct Scsi_Host * shpnt);static int aha1542_restart(struct Scsi_Host * shost);#define aha1542_intr_reset(base) outb(IRST, CONTROL(base))#define WAIT(port, mask, allof, noneof) \ { register WAITbits; \ register WAITtimeout = WAITnexttimeout; \ while (1) { \ WAITbits = inb(port) & (mask); \ if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \ break; \ if (--WAITtimeout == 0) goto fail; \ } \ }/* Similar to WAIT, except we use the udelay call to regulate the amount of time we wait. */#define WAITd(port, mask, allof, noneof, timeout) \ { register WAITbits; \ register WAITtimeout = timeout; \ while (1) { \ WAITbits = inb(port) & (mask); \ if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \ break; \ udelay(1000); \ if (--WAITtimeout == 0) goto fail; \ } \ }static void aha1542_stat(void){/* int s = inb(STATUS), i = inb(INTRFLAGS); printk("status=%x intrflags=%x\n", s, i, WAITnexttimeout-WAITtimeout); */}/* This is a bit complicated, but we need to make sure that an interrupt routine does not send something out while we are in the middle of this. Fortunately, it is only at boot time that multi-byte messages are ever sent. */static int aha1542_out(unsigned int base, unchar *cmdp, int len){ unsigned long flags = 0; save_flags(flags); if(len == 1) { while(1==1){ WAIT(STATUS(base), CDF, 0, CDF); cli(); if(inb(STATUS(base)) & CDF) {restore_flags(flags); continue;} outb(*cmdp, DATA(base)); restore_flags(flags); return 0; } } else { cli(); while (len--) { WAIT(STATUS(base), CDF, 0, CDF); outb(*cmdp++, DATA(base)); } restore_flags(flags); } return 0; fail: restore_flags(flags); printk("aha1542_out failed(%d): ", len+1); aha1542_stat(); return 1;}/* Only used at boot time, so we do not need to worry about latency as much here */static int aha1542_in(unsigned int base, unchar *cmdp, int len){ unsigned long flags; save_flags(flags); cli(); while (len--) { WAIT(STATUS(base), DF, DF, 0); *cmdp++ = inb(DATA(base)); } restore_flags(flags); return 0; fail: restore_flags(flags); printk("aha1542_in failed(%d): ", len+1); aha1542_stat(); return 1;}/* Similar to aha1542_in, except that we wait a very short period of time. We use this if we know the board is alive and awake, but we are not sure if the board will respond to the command we are about to send or not */static int aha1542_in1(unsigned int base, unchar *cmdp, int len){ unsigned long flags; save_flags(flags); cli(); while (len--) { WAITd(STATUS(base), DF, DF, 0, 100); *cmdp++ = inb(DATA(base)); } restore_flags(flags); return 0; fail: restore_flags(flags); return 1;}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. */ DEB(printk("Aha1542: %x %x\n", hosterr, scsierr)); 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("makecode: unknown hoststatus %x\n", hosterr); break; } return scsierr|(hosterr << 16);}static int aha1542_test_port(int bse, struct Scsi_Host * shpnt){ int i; unchar inquiry_cmd[] = {CMD_INQUIRY }; unchar inquiry_result[4]; unchar *cmdp; int len; volatile int debug = 0; /* Quick and dirty test for presence of the card. */ if(inb(STATUS(bse)) == 0xff) return 0; /* Reset the adapter. I ought to make a hard reset, but it's not really necessary */ /* DEB(printk("aha1542_test_port called \n")); */ /* In case some other card was probing here, reset interrupts */ aha1542_intr_reset(bse); /* reset interrupts, so they don't block */ outb(SRST|IRST/*|SCRST*/, CONTROL(bse)); i = jiffies + 2; while (i>jiffies); /* Wait a little bit for things to settle down. */ debug = 1; /* Expect INIT and IDLE, any of the others are bad */ WAIT(STATUS(bse), STATMASK, INIT|IDLE, STST|DIAGF|INVDCMD|DF|CDF); debug = 2; /* Shouldn't have generated any interrupts during reset */ if (inb(INTRFLAGS(bse))&INTRMASK) goto fail; /* Perform a host adapter inquiry instead so we do not need to set up the mailboxes ahead of time */ aha1542_out(bse, inquiry_cmd, 1); debug = 3; len = 4; cmdp = &inquiry_result[0]; while (len--) { WAIT(STATUS(bse), DF, DF, 0); *cmdp++ = inb(DATA(bse)); } debug = 8; /* Reading port should reset DF */ if (inb(STATUS(bse)) & DF) goto fail; debug = 9; /* When HACC, command is completed, and we're though testing */ WAIT(INTRFLAGS(bse), HACC, HACC, 0); /* now initialize adapter */ debug = 10; /* Clear interrupts */ outb(IRST, CONTROL(bse)); debug = 11; return debug; /* 1 = ok */ fail: return 0; /* 0 = not ok */}/* A "high" level interrupt handler */static void aha1542_intr_handle(int irq, void *dev_id, struct pt_regs *regs){ void (*my_done)(Scsi_Cmnd *) = NULL; int errstatus, mbi, mbo, mbistatus; int number_serviced; unsigned int flags; struct Scsi_Host * shost; Scsi_Cmnd * SCtmp; int flag; int needs_restart; struct mailbox * mb; struct ccb *ccb; shost = aha_host[irq - 9]; if(!shost) panic("Splunge!"); mb = HOSTDATA(shost)->mb; ccb = HOSTDATA(shost)->ccb;#ifdef DEBUG { flag = inb(INTRFLAGS(shost->io_port)); printk("aha1542_intr_handle: "); 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 "); printk("status %02x\n", inb(STATUS(shost->io_port))); };#endif number_serviced = 0; needs_restart = 0; while(1==1){ flag = inb(INTRFLAGS(shost->io_port)); /* 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 "); if (flag&SCRD) { needs_restart = 1; printk("SCRD "); } } aha1542_intr_reset(shost->io_port); save_flags(flags); cli(); mbi = HOSTDATA(shost)->aha1542_last_mbi_used + 1; if (mbi >= 2*AHA1542_MAILBOXES) mbi = AHA1542_MAILBOXES; do{ if(mb[mbi].status != 0) break; mbi++; if (mbi >= 2*AHA1542_MAILBOXES) mbi = AHA1542_MAILBOXES; } while (mbi != HOSTDATA(shost)->aha1542_last_mbi_used); if(mb[mbi].status == 0){ restore_flags(flags); /* Hmm, no mail. Must have read it the last time around */ if (!number_serviced && !needs_restart) printk("aha1542.c: interrupt received, but no mail.\n"); /* We detected a reset. Restart all pending commands for devices that use the hard reset option */ if(needs_restart) aha1542_restart(shost); return; }; mbo = (scsi2int(mb[mbi].ccbptr) - ((unsigned int) &ccb[0])) / sizeof(struct ccb); mbistatus = mb[mbi].status; mb[mbi].status = 0; HOSTDATA(shost)->aha1542_last_mbi_used = mbi; restore_flags(flags); #ifdef DEBUG { if (ccb[mbo].tarstat|ccb[mbo].hastat) printk("aha1542_command: returning %x (status %d)\n", ccb[mbo].tarstat + ((int) ccb[mbo].hastat << 16), mb[mbi].status); };#endif if(mbistatus == 3) continue; /* Aborted command not found */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -