📄 gdth.c
字号:
/************************************************************************ * GDT ISA/EISA/PCI Disk Array Controller driver for Linux * * * * gdth.c * * Copyright (C) 1995-98 ICP vortex Computersysteme GmbH, Achim Leubner * * * * <achim@vortex.de> * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published * * by the Free Software Foundation; either version 2 of the License, * * or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this kernel; if not, write to the Free Software * * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * * * Tested with Linux 1.2.13, ..., 2.1.103 * * * * $Log: gdth.c,v $ * Revision 1.1 1999/04/26 05:54:35 tb * 1998-11-30 OKUJI Yoshinori <okuji@kuicr.kyoto-u.ac.jp> * * Clean up linux emulation code to make it architecture-independent * as much as possible. * * * linux: Renamed from linuxdev. * * Makefile.in (objfiles): Add linux.o instead of linuxdev.o. * (MAKE): New variable. Used for the linux.o target. * * configure.in: Add AC_CHECK_TOOL(MAKE, make). * * i386/i386/spl.h: Include <i386/ipl.h>, for compatibility with * OSF Mach 3.0. Suggested by Elgin Lee <ehl@funghi.com>. * * linux/src: Renamed from linux/linux. * * linux/dev: Renamed from linux/mach. * * linux/Drivers.in (AC_INIT): Use dev/include/linux/autoconf.h, * instead of mach/include/linux/autoconf.h. * * Makefile.in (all): Target ../linux.o instead of ../linuxdev.o. * * linux/dev/drivers/block/genhd.c: Include <machine/spl.h> instead * of <i386/ipl.h>. * * linux/dev/drivers/net/auto_irq.c: Remove unneeded header files, * <i386/ipl.h> and <i386/pic.h>. * * linux/dev/init/main.c: Many i386-dependent codes moved to ... * * linux/dev/arch/i386/irq.c: ... here. * * linux/dev/arch/i386/setup.c: New file. * * linux/dev/arch/i386/linux_emul.h: Likewise. * * linux/dev/arch/i386/glue/timer.c: Merged into sched.c. * * linux/dev/arch/i386/glue/sched.c: Include <machine/spl.h> instead * of <i386/ipl.h>, and moved to ... * * linux/dev/kernel/sched.c: ... here. * * linux/dev/arch/i386/glue/block.c: Include <machine/spl.h> and * <linux_emul.h>, instead of i386-dependent header files, and * moved to ... * * linux/dev/glue/blocl.c: ... here. * * linux/dev/arch/i386/glue/net.c: Include <machine/spl.h> and * <linux_emul.h>, instead of i386-dependent header files, and * moved to ... * * linux/dev/glue/net.c: ... here. * * linux/dev/arch/i386/glue/misc.c: Remove `x86' and moved to ... * * linux/dev/glue/misc.c: ... here. * * linux/dev/arch/i386/glue/kmem.c: Moved to ... * * linux/dev/glue/kmem.c: ... here. * * Revision 1.16 1998/09/28 16:08:46 achim * GDT_PCIMPR: DPMEM remapping, if required * mdelay() added * * Revision 1.15 1998/06/03 14:54:06 achim * gdth_delay(), gdth_flush() implemented * Bugfix: gdth_release() changed * * Revision 1.14 1998/05/22 10:01:17 achim * mj: pcibios_strerror() removed * Improved SMP support (if version >= 2.1.95) * gdth_halt(): halt_called flag added (if version < 2.1) * * Revision 1.13 1998/04/16 09:14:57 achim * Reserve drives (for raw service) implemented * New error handling code enabled * Get controller name from board_info() IOCTL * Final round of PCI device driver patches by Martin Mares * * Revision 1.12 1998/03/03 09:32:37 achim * Fibre channel controller support added * * Revision 1.11 1998/01/27 16:19:14 achim * SA_SHIRQ added * add_timer()/del_timer() instead of GDTH_TIMER * scsi_add_timer()/scsi_del_timer() instead of SCSI_TIMER * New error handling included * * Revision 1.10 1997/10/31 12:29:57 achim * Read heads/sectors from host drive * * Revision 1.9 1997/09/04 10:07:25 achim * IO-mapping with virt_to_bus(), readb(), writeb(), ... * register_reboot_notifier() to get a notify on shutdown used * * Revision 1.8 1997/04/02 12:14:30 achim * Version 1.00 (see gdth.h), tested with kernel 2.0.29 * * Revision 1.7 1997/03/12 13:33:37 achim * gdth_reset() changed, new async. events * * Revision 1.6 1997/03/04 14:01:11 achim * Shutdown routine gdth_halt() implemented * * Revision 1.5 1997/02/21 09:08:36 achim * New controller included (RP, RP1, RP2 series) * IOCTL interface implemented * * Revision 1.4 1996/07/05 12:48:55 achim * Function gdth_bios_param() implemented * New constant GDTH_MAXC_P_L inserted * GDT_WRITE_THR, GDT_EXT_INFO implemented * Function gdth_reset() changed * * Revision 1.3 1996/05/10 09:04:41 achim * Small changes for Linux 1.2.13 * * Revision 1.2 1996/05/09 12:45:27 achim * Loadable module support implemented * /proc support corrections made * * Revision 1.1 1996/04/11 07:35:57 achim * Initial revision * * * $Id: gdth.c,v 1.1 1999/04/26 05:54:35 tb Exp $ ************************************************************************/#ifdef MODULE#include <linux/module.h>#endif#include <linux/version.h>#include <linux/kernel.h>#include <linux/head.h>#include <linux/types.h>#include <linux/pci.h>#include <linux/string.h>#include <linux/ioport.h>#include <linux/delay.h>#include <linux/sched.h>#include <linux/in.h>#include <linux/proc_fs.h>#include <linux/time.h>#include <linux/timer.h>#if LINUX_VERSION_CODE >= 0x020100#include <linux/reboot.h>#else#include <linux/bios32.h>#endif#include <asm/dma.h>#include <asm/system.h>#include <asm/io.h>#if LINUX_VERSION_CODE >= 0x02015F#include <asm/spinlock.h>#endif#if LINUX_VERSION_CODE >= 0x010300#include <linux/blk.h>#else#include "../block/blk.h"#endif#include "scsi.h"#include "hosts.h"#include "sd.h"#include "gdth.h"/****************************************************************************//* LILO params: gdth=<IRQ> * * Where: <IRQ> is any of the valid IRQs for EISA controllers (10,11,12,14) * Sets the IRQ of the GDT3000/3020 EISA controller to this value, * if the IRQ can not automat. detect (controller BIOS disabled) * See gdth_init_eisa() * * You can use the command line gdth=0 to disable the driver */static unchar irqs[MAXHA] = {0xff};static unchar disable_gdth_scan = FALSE;/* Reserve drives for raw service: Fill the following structure with the * appropriate values: Controller number, Channel, Target ID */static gdth_reserve_str reserve_list[] = { /* { 0, 1, 4 }, Example: Controller 0, Channel B, ID 4 */ { 0xff, 0xff, 0xff } /* end of list */};/****************************************************************************/#if LINUX_VERSION_CODE >= 0x02015Fstatic void gdth_interrupt(int irq,void *dev_id,struct pt_regs *regs);static void do_gdth_interrupt(int irq,void *dev_id,struct pt_regs *regs);#elif LINUX_VERSION_CODE >= 0x010346static void gdth_interrupt(int irq,void *dev_id,struct pt_regs *regs);#elsestatic void gdth_interrupt(int irq,struct pt_regs *regs);#endifstatic int gdth_sync_event(int hanum,int service,unchar index,Scsi_Cmnd *scp);static int gdth_async_event(int hanum,int service);static void gdth_putq(int hanum,Scsi_Cmnd *scp,unchar priority);static void gdth_next(int hanum);static int gdth_fill_raw_cmd(int hanum,Scsi_Cmnd *scp,unchar b);static int gdth_special_cmd(int hanum,Scsi_Cmnd *scp,unchar b);static gdth_evt_str *gdth_store_event(ushort source, ushort idx, gdth_evt_data *evt);static int gdth_read_event(int handle, gdth_evt_str *estr);static void gdth_readapp_event(unchar application, gdth_evt_str *estr);static void gdth_clear_events(void);static void gdth_copy_internal_data(Scsi_Cmnd *scp,char *buffer,ushort count);static int gdth_internal_cache_cmd(int hanum,Scsi_Cmnd *scp, unchar b,ulong *flags);static int gdth_fill_cache_cmd(int hanum,Scsi_Cmnd *scp,ushort hdrive);static int gdth_search_eisa(ushort eisa_adr);static int gdth_search_isa(ulong bios_adr);static int gdth_search_pci(ushort device_id,ushort index,gdth_pci_str *pcistr);static int gdth_init_eisa(ushort eisa_adr,gdth_ha_str *ha);static int gdth_init_isa(ulong bios_adr,gdth_ha_str *ha);static int gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha);static void gdth_enable_int(int hanum);static int gdth_get_status(unchar *pIStatus,int irq);static int gdth_test_busy(int hanum);static int gdth_get_cmd_index(int hanum);static void gdth_release_event(int hanum);static int gdth_wait(int hanum,int index,ulong time);static int gdth_internal_cmd(int hanum,unchar service,ushort opcode,ulong p1, ulong p2,ulong p3);static int gdth_search_drives(int hanum);static void *gdth_mmap(ulong paddr, ulong size);static void gdth_munmap(void *addr);static const char *gdth_ctr_name(int hanum);static void gdth_flush(int hanum);#if LINUX_VERSION_CODE >= 0x020100static int gdth_halt(struct notifier_block *nb, ulong event, void *buf);#elsestatic int halt_called = FALSE;void gdth_halt(void);#endif#ifdef DEBUG_GDTHstatic unchar DebugState = DEBUG_GDTH;extern int sys_syslog(int,char*,int);#define LOGEN sys_syslog(7,NULL,0)#ifdef __SERIAL__#define MAX_SERBUF 160static void ser_init(void);static void ser_puts(char *str);static void ser_putc(char c);static int ser_printk(const char *fmt, ...);static char strbuf[MAX_SERBUF+1];#ifdef __COM2__#define COM_BASE 0x2f8#else#define COM_BASE 0x3f8#endifstatic void ser_init(){ unsigned port=COM_BASE; outb(0x80,port+3); outb(0,port+1); /* 19200 Baud, if 9600: outb(12,port) */ outb(6, port); outb(3,port+3); outb(0,port+1); /* ser_putc('I'); ser_putc(' '); */}static void ser_puts(char *str){ char *ptr; ser_init(); for (ptr=str;*ptr;++ptr) ser_putc(*ptr);}static void ser_putc(char c){ unsigned port=COM_BASE; while ((inb(port+5) & 0x20)==0); outb(c,port); if (c==0x0a) { while ((inb(port+5) & 0x20)==0); outb(0x0d,port); }}static int ser_printk(const char *fmt, ...){ va_list args; int i; va_start(args,fmt); i = vsprintf(strbuf,fmt,args); ser_puts(strbuf); va_end(args); return i;}#define TRACE(a) {if (DebugState==1) {ser_printk a;}}#define TRACE2(a) {if (DebugState==1 || DebugState==2) {ser_printk a;}}#define TRACE3(a) {if (DebugState!=0) {ser_printk a;}}#else /* !__SERIAL__ */#define TRACE(a) {if (DebugState==1) {LOGEN;printk a;}}#define TRACE2(a) {if (DebugState==1 || DebugState==2) {LOGEN;printk a;}}#define TRACE3(a) {if (DebugState!=0) {LOGEN;printk a;}}#endif#else /* !DEBUG */#define TRACE(a)#define TRACE2(a)#define TRACE3(a)#endif#ifdef GDTH_STATISTICSstatic ulong max_rq=0, max_index=0, max_sg=0;static ulong act_ints=0, act_ios=0, act_stats=0, act_rq=0;static struct timer_list gdth_timer;#endif#define PTR2USHORT(a) (ushort)(ulong)(a)#define GDTOFFSOF(a,b) (size_t)&(((a*)0)->b) #define INDEX_OK(i,t) ((i)<sizeof(t)/sizeof((t)[0]))#define NUMDATA(a) ( (gdth_num_str *)((a)->hostdata))#define HADATA(a) (&((gdth_ext_str *)((a)->hostdata))->haext)#define CMDDATA(a) (&((gdth_ext_str *)((a)->hostdata))->cmdext)#define DMADATA(a) (&((gdth_ext_str *)((a)->hostdata))->dmaext)#if LINUX_VERSION_CODE < 0x010300static void *gdth_mmap(ulong paddr, ulong size) { if (paddr >= high_memory) return NULL; else return (void *)paddr;}static void gdth_munmap(void *addr) {}inline ulong virt_to_phys(volatile void *addr){ return (ulong)addr;}inline void *phys_to_virt(ulong addr){ return (void *)addr;}#define virt_to_bus virt_to_phys#define bus_to_virt phys_to_virt#define readb(addr) (*(volatile unchar *)(addr))#define readw(addr) (*(volatile ushort *)(addr))#define readl(addr) (*(volatile ulong *)(addr))#define writeb(b,addr) (*(volatile unchar *)(addr) = (b))#define writew(b,addr) (*(volatile ushort *)(addr) = (b))#define writel(b,addr) (*(volatile ulong *)(addr) = (b))#define memset_io(a,b,c) memset((void *)(a),(b),(c))#define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))#define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))#elif LINUX_VERSION_CODE < 0x020100
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -