⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wd7000.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* $Id: $ *  linux/drivers/scsi/wd7000.c * *  Copyright (C) 1992  Thomas Wuensche *	closely related to the aha1542 driver from Tommy Thorn *	( as close as different hardware allows on a lowlevel-driver :-) ) * *  Revised (and renamed) by John Boyd <boyd@cis.ohio-state.edu> to *  accommodate Eric Youngdale's modifications to scsi.c.  Nov 1992. * *  Additional changes to support scatter/gather.  Dec. 1992.  tw/jb * *  No longer tries to reset SCSI bus at boot (it wasn't working anyway). *  Rewritten to support multiple host adapters. *  Miscellaneous cleanup. *  So far, still doesn't do reset or abort correctly, since I have no idea *  how to do them with this board (8^(.                      Jan 1994 jb * * This driver now supports both of the two standard configurations (per * the 3.36 Owner's Manual, my latest reference) by the same method as * before; namely, by looking for a BIOS signature.  Thus, the location of * the BIOS signature determines the board configuration.  Until I have * time to do something more flexible, users should stick to one of the * following: * * Standard configuration for single-adapter systems: *    - BIOS at CE00h *    - I/O base address 350h *    - IRQ level 15 *    - DMA channel 6 * Standard configuration for a second adapter in a system: *    - BIOS at C800h *    - I/O base address 330h *    - IRQ level 11 *    - DMA channel 5 * * Anyone who can recompile the kernel is welcome to add others as need * arises, but unpredictable results may occur if there are conflicts. * In any event, if there are multiple adapters in a system, they MUST * use different I/O bases, IRQ levels, and DMA channels, since they will be * indistinguishable (and in direct conflict) otherwise. * *   As a point of information, the NO_OP command toggles the CMD_RDY bit * of the status port, and this fact could be used as a test for the I/O * base address (or more generally, board detection).  There is an interrupt * status port, so IRQ probing could also be done.  I suppose the full * DMA diagnostic could be used to detect the DMA channel being used.  I * haven't done any of this, though, because I think there's too much of * a chance that such explorations could be destructive, if some other * board's resources are used inadvertently.  So, call me a wimp, but I * don't want to try it.  The only kind of exploration I trust is memory * exploration, since it's more certain that reading memory won't be * destructive. * * More to my liking would be a LILO boot command line specification, such * as is used by the aha152x driver (and possibly others).  I'll look into * it, as I have time... * *   I get mail occasionally from people who either are using or are * considering using a WD7000 with Linux.  There is a variety of * nomenclature describing WD7000's.  To the best of my knowledge, the * following is a brief summary (from an old WD doc - I don't work for * them or anything like that): * * WD7000-FASST2: This is a WD7000 board with the real-mode SST ROM BIOS *        installed.  Last I heard, the BIOS was actually done by Columbia *        Data Products.  The BIOS is only used by this driver (and thus *        by Linux) to identify the board; none of it can be executed under *        Linux. * * WD7000-ASC: This is the original adapter board, with or without BIOS. *        The board uses a WD33C93 or WD33C93A SBIC, which in turn is *        controlled by an onboard Z80 processor.  The board interface *        visible to the host CPU is defined effectively by the Z80's *        firmware, and it is this firmware's revision level that is *        determined and reported by this driver.  (The version of the *        on-board BIOS is of no interest whatsoever.)  The host CPU has *        no access to the SBIC; hence the fact that it is a WD33C93 is *        also of no interest to this driver. * * WD7000-AX: * WD7000-MX: * WD7000-EX: These are newer versions of the WD7000-ASC.  The -ASC is *        largely built from discrete components; these boards use more *        integration.  The -AX is an ISA bus board (like the -ASC), *        the -MX is an MCA (i.e., PS/2) bus board), and the -EX is an *        EISA bus board. * *  At the time of my documentation, the -?X boards were "future" products, *  and were not yet available.  However, I vaguely recall that Thomas *  Wuensche had an -AX, so I believe at least it is supported by this *  driver.  I have no personal knowledge of either -MX or -EX boards. * *  P.S. Just recently, I've discovered (directly from WD and Future *  Domain) that all but the WD7000-EX have been out of production for *  two years now.  FD has production rights to the 7000-EX, and are *  producing it under a new name, and with a new BIOS.  If anyone has *  one of the FD boards, it would be nice to come up with a signature *  for it. *                                                           J.B. Jan 1994. * * *  Revisions by Miroslav Zagorac <zaga@fly.cc.fer.hr> * *  08/24/1996. * *  Enhancement for wd7000_detect function has been made, so you don't have *  to enter BIOS ROM address in initialisation data (see struct Config). *  We cannot detect IRQ, DMA and I/O base address for now, so we have to *  enter them as arguments while wd_7000 is detected. If someone has IRQ, *  DMA or I/O base address set to some other value, he can enter them in *  configuration without any problem. Also I wrote a function wd7000_setup, *  so now you can enter WD-7000 definition as kernel arguments, *  as in lilo.conf: * *     append="wd7000=IRQ,DMA,IO" * *  PS: If card BIOS ROM is disabled, function wd7000_detect now will recognize *      adapter, unlike the old one. Anyway, BIOS ROM from WD7000 adapter is *      useless for Linux. B^) * * *  09/06/1996. * *  Autodetecting of I/O base address from wd7000_detect function is removed, *  some little bugs removed, etc... * *  Thanks to Roger Scott for driver debugging. * *  06/07/1997 * *  Added support for /proc file system (/proc/scsi/wd7000/[0...] files). *  Now, driver can handle hard disks with capacity >1GB. * *  01/15/1998 * *  Added support for BUS_ON and BUS_OFF parameters in config line. *  Miscellaneous cleanup. * *  03/01/1998 * *  WD7000 driver now work on kernels >= 2.1.x */#ifdef MODULE#include <linux/module.h>#endif#include <stdarg.h>#include <linux/kernel.h>#include <linux/types.h>#include <linux/string.h>#include <linux/sched.h>#include <linux/malloc.h>#include <linux/spinlock.h>#include <asm/system.h>#include <asm/dma.h>#include <asm/io.h>#include <linux/ioport.h>#include <linux/proc_fs.h>#include <linux/blk.h>#include <linux/version.h>#include <linux/init.h>#include "scsi.h"#include "hosts.h"#include "sd.h"#include <scsi/scsicam.h>#define ANY2SCSI_INLINE		/* undef this to use old macros */#undef  WD7000_DEBUG		/* general debug                */#include "wd7000.h"#include <linux/stat.h>/* *  Mailbox structure sizes. *  I prefer to keep the number of ICMBs much larger than the number of *  OGMBs.  OGMBs are used very quickly by the driver to start one or *  more commands, while ICMBs are used by the host adapter per command. */#define OGMB_CNT	16#define ICMB_CNT	32/* *  Scb's are shared by all active adapters.  So, if they all become busy, *  callers may be made to wait in alloc_scbs for them to free.  That can *  be avoided by setting MAX_SCBS to NUM_CONFIG * WD7000_Q.  If you'd *  rather conserve memory, use a smaller number (> 0, of course) - things *  will should still work OK. */#define MAX_SCBS        32/* *  WD7000-specific mailbox structure * */typedef volatile struct mailbox {    unchar status;    unchar scbptr[3];		/* SCSI-style - MSB first (big endian) */} Mailbox;/* *  This structure should contain all per-adapter global data.  I.e., any *  new global per-adapter data should put in here. */typedef struct adapter {    struct Scsi_Host *sh;	/* Pointer to Scsi_Host structure    */    int iobase;			/* This adapter's I/O base address   */    int irq;			/* This adapter's IRQ level          */    int dma;			/* This adapter's DMA channel        */    int int_counter;		/* This adapter's interrupt counter  */    int bus_on;			/* This adapter's BUS_ON time        */    int bus_off;		/* This adapter's BUS_OFF time       */    struct {			/* This adapter's mailboxes          */	Mailbox ogmb[OGMB_CNT];	/* Outgoing mailboxes                */	Mailbox icmb[ICMB_CNT];	/* Incoming mailboxes                */    } mb;    int next_ogmb;		/* to reduce contention at mailboxes */    unchar control;		/* shadows CONTROL port value        */    unchar rev1, rev2;		/* filled in by wd7000_revision      */} Adapter;/* * (linear) base address for ROM BIOS */static const long wd7000_biosaddr[] ={    0xc0000, 0xc2000, 0xc4000, 0xc6000, 0xc8000, 0xca000, 0xcc000, 0xce000,    0xd0000, 0xd2000, 0xd4000, 0xd6000, 0xd8000, 0xda000, 0xdc000, 0xde000};#define NUM_ADDRS (sizeof(wd7000_biosaddr)/sizeof(long))static const unsigned short wd7000_iobase[] ={    0x0300, 0x0308, 0x0310, 0x0318, 0x0320, 0x0328, 0x0330, 0x0338,    0x0340, 0x0348, 0x0350, 0x0358, 0x0360, 0x0368, 0x0370, 0x0378,    0x0380, 0x0388, 0x0390, 0x0398, 0x03a0, 0x03a8, 0x03b0, 0x03b8,    0x03c0, 0x03c8, 0x03d0, 0x03d8, 0x03e0, 0x03e8, 0x03f0, 0x03f8};#define NUM_IOPORTS (sizeof(wd7000_iobase)/sizeof(unsigned short))static const short wd7000_irq[] = { 3, 4, 5, 7, 9, 10, 11, 12, 14, 15 };#define NUM_IRQS (sizeof(wd7000_irq)/sizeof(short))static const short wd7000_dma[] = { 5, 6, 7 };#define NUM_DMAS (sizeof(wd7000_dma)/sizeof(short))/* * possible irq range */#define IRQ_MIN   3#define IRQ_MAX   15#define IRQS      (IRQ_MAX - IRQ_MIN + 1)/* * The following is set up by wd7000_detect, and used thereafter by * wd7000_intr_handle to map the irq level to the corresponding Adapter. * Note that if SA_INTERRUPT is not used, wd7000_intr_handle must be * changed to pick up the IRQ level correctly. */static struct Scsi_Host *wd7000_host[IRQS];#define BUS_ON    64	/* x 125ns = 8000ns (BIOS default) */#define BUS_OFF   15	/* x 125ns = 1875ns (BIOS default) *//* *  Standard Adapter Configurations - used by wd7000_detect */typedef struct {    short irq;		/* IRQ level                                  */    short dma;		/* DMA channel                                */    unsigned iobase;	/* I/O base address                           */    short bus_on;	/* Time that WD7000 spends on the AT-bus when */			/* transferring data. BIOS default is 8000ns. */    short bus_off;	/* Time that WD7000 spends OFF THE BUS after  */			/* while it is transferring data.             */			/* BIOS default is 1875ns                     */} Config;/* * Add here your configuration... */static Config configs[] ={    { 15,  6, 0x350, BUS_ON, BUS_OFF },	/* defaults for single adapter */    { 11,  5, 0x320, BUS_ON, BUS_OFF },	/* defaults for second adapter */    {  7,  6, 0x350, BUS_ON, BUS_OFF },	/* My configuration (Zaga)     */    { -1, -1, 0x0,   BUS_ON, BUS_OFF }	/* Empty slot                  */};#define NUM_CONFIGS (sizeof(configs)/sizeof(Config))/* *  The following list defines strings to look for in the BIOS that identify *  it as the WD7000-FASST2 SST BIOS.  I suspect that something should be *  added for the Future Domain version. */typedef struct signature {    const char *sig;		/* String to look for            */    unsigned long ofs;		/* offset from BIOS base address */    unsigned len;		/* length of string              */} Signature;static const Signature signatures[] ={    {"SSTBIOS", 0x0000d, 7}	/* "SSTBIOS" @ offset 0x0000d */};#define NUM_SIGNATURES (sizeof(signatures)/sizeof(Signature))/* *  I/O Port Offsets and Bit Definitions *  4 addresses are used.  Those not defined here are reserved. */#define ASC_STAT        0	/* Status,  Read          */#define ASC_COMMAND     0	/* Command, Write         */#define ASC_INTR_STAT   1	/* Interrupt Status, Read */#define ASC_INTR_ACK    1	/* Acknowledge, Write     */#define ASC_CONTROL     2	/* Control, Write         *//* * ASC Status Port */#define INT_IM		0x80	/* Interrupt Image Flag           */#define CMD_RDY		0x40	/* Command Port Ready             */#define CMD_REJ		0x20	/* Command Port Byte Rejected     */#define ASC_INIT        0x10	/* ASC Initialized Flag           */#define ASC_STATMASK    0xf0	/* The lower 4 Bytes are reserved *//* * COMMAND opcodes * *  Unfortunately, I have no idea how to properly use some of these commands, *  as the OEM manual does not make it clear.  I have not been able to use *  enable/disable unsolicited interrupts or the reset commands with any *  discernible effect whatsoever.  I think they may be related to certain *  ICB commands, but again, the OEM manual doesn't make that clear. */#define NO_OP             0	/* NO-OP toggles CMD_RDY bit in ASC_STAT  */#define INITIALIZATION    1	/* initialization (10 bytes)              */#define DISABLE_UNS_INTR  2	/* disable unsolicited interrupts         */#define ENABLE_UNS_INTR   3	/* enable unsolicited interrupts          */#define INTR_ON_FREE_OGMB 4	/* interrupt on free OGMB                 */#define SOFT_RESET        5	/* SCSI bus soft reset                    */#define HARD_RESET_ACK    6	/* SCSI bus hard reset acknowledge        */#define START_OGMB        0x80	/* start command in OGMB (n)              */#define SCAN_OGMBS        0xc0	/* start multiple commands, signature (n) */				/*    where (n) = lower 6 bits            *//* * For INITIALIZATION: */typedef struct initCmd {    unchar op;			/* command opcode (= 1)                    */    unchar ID;			/* Adapter's SCSI ID                       */    unchar bus_on;		/* Bus on time, x 125ns (see below)        */    unchar bus_off;		/* Bus off time, ""         ""             */    unchar rsvd;		/* Reserved                                */    unchar mailboxes[3];	/* Address of Mailboxes, MSB first         */    unchar ogmbs;		/* Number of outgoing MBs, max 64, 0,1 = 1 */    unchar icmbs;		/* Number of incoming MBs,   ""       ""   */} InitCmd;/* * Interrupt Status Port - also returns diagnostic codes at ASC reset * * if msb is zero, the lower bits are diagnostic status * Diagnostics: * 01   No diagnostic error occurred * 02   RAM failure * 03   FIFO R/W failed * 04   SBIC register read/write failed * 05   Initialization D-FF failed * 06   Host IRQ D-FF failed * 07   ROM checksum error * Interrupt status (bitwise): * 10NNNNNN   outgoing mailbox NNNNNN is free * 11NNNNNN   incoming mailbox NNNNNN needs service */#define MB_INTR    0xC0		/* Mailbox Service possible/required */#define IMB_INTR   0x40		/* 1 Incoming / 0 Outgoing           */#define MB_MASK    0x3f		/* mask for mailbox number           *//* * CONTROL port bits */#define INT_EN     0x08		/* Interrupt Enable */#define DMA_EN     0x04		/* DMA Enable       */#define SCSI_RES   0x02		/* SCSI Reset       */#define ASC_RES    0x01		/* ASC Reset        *//* * Driver data structures: *   - mb and scbs are required for interfacing with the host adapter. *     An SCB has extra fields not visible to the adapter; mb's *     _cannot_ do this, since the adapter assumes they are contiguous in *     memory, 4 bytes each, with ICMBs following OGMBs, and uses this fact *     to access them. *   - An icb is for host-only (non-SCSI) commands.  ICBs are 16 bytes each; *     the additional bytes are used only by the driver. *   - For now, a pool of SCBs are kept in global storage by this driver, *     and are allocated and freed as needed. * *  The 7000-FASST2 marks OGMBs empty as soon as it has _started_ a command, *  not when it has finished.  Since the SCB must be around for completion, *  problems arise when SCBs correspond to OGMBs, which may be reallocated *  earlier (or delayed unnecessarily until a command completes). *  Mailboxes are used as transient data structures, simply for *  carrying SCB addresses to/from the 7000-FASST2. * *  Note also since SCBs are not "permanently" associated with mailboxes, *  there is no need to keep a global list of Scsi_Cmnd pointers indexed *  by OGMB.   Again, SCBs reference their Scsi_Cmnds directly, so mailbox *  indices need not be involved. *//* *  WD7000-specific scatter/gather element structure */typedef struct sgb {    unchar len[3];    unchar ptr[3];		/* Also SCSI-style - MSB first */} Sgb;typedef struct scb {		/* Command Control Block 5.4.1               */    unchar op;			/* Command Control Block Operation Code      */    unchar idlun;		/* op=0,2:Target Id, op=1:Initiator Id       */				/* Outbound data transfer, length is checked */				/* Inbound data transfer, length is checked  */				/* Logical Unit Number                       */    unchar cdb[12];		/* SCSI Command Block                        */    volatile unchar status;	/* SCSI Return Status                        */    volatile unchar vue;	/* Vendor Unique Error Code                  */    unchar maxlen[3];		/* Maximum Data Transfer Length              */    unchar dataptr[3];		/* SCSI Data Block Pointer                   */    unchar linkptr[3];		/* Next Command Link Pointer                 */    unchar direc;		/* Transfer Direction                        */    unchar reserved2[6];	/* SCSI Command Descriptor Block             */				/* end of hardware SCB                       */    Scsi_Cmnd *SCpnt;		/* Scsi_Cmnd using this SCB                  */    Sgb sgb[WD7000_SG];		/* Scatter/gather list for this SCB          */    Adapter *host;		/* host adapter                              */    struct scb *next;		/* for lists of scbs                         */} Scb;/* *  This driver is written to allow host-only commands to be executed. *  These use a 16-byte block called an ICB.  The format is extended by the *  driver to 18 bytes, to support the status returned in the ICMB and

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -