📄 gdth.c
字号:
/************************************************************************ * GDT ISA/EISA/PCI Disk Array Controller driver for Linux * * * * gdth.c * * Copyright (C) 1995-99 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.2.4 * * * * $Log: gdth.c,v $ * Revision 1.23 1999/03/26 09:12:31 achim * Default value for hdr_channel set to 0 * * Revision 1.22 1999/03/22 16:27:16 achim * Bugfix: gdth_store_event() must not be locked with GDTH_LOCK_HA() * * Revision 1.21 1999/03/16 13:40:34 achim * Problems with reserved drives solved * gdth_eh_bus_reset() implemented * * Revision 1.20 1999/03/10 09:08:13 achim * Bugfix: Corrections in gdth_direction_tab[] made * Bugfix: Increase command timeout (gdth_update_timeout()) NOT in gdth_putq() * * Revision 1.19 1999/03/05 14:38:16 achim * Bugfix: Heads/Sectors mapping for reserved devices possibly wrong * -> gdth_eval_mapping() implemented, changes in gdth_bios_param() * INIT_RETRIES set to 100s to avoid DEINIT-Timeout for controllers * with BIOS disabled and memory test set to Intensive * Enhanced /proc support * * Revision 1.18 1999/02/24 09:54:33 achim * Command line parameter hdr_channel implemented * Bugfix for EISA controllers + Linux 2.2.x * * Revision 1.17 1998/12/17 15:58:11 achim * Command line parameters implemented * Changes for Alpha platforms * PCI controller scan changed * SMP support improved (spin_lock_irqsave(),...) * New async. events, new scan/reserve commands included * * 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(), gdth_readb(), gdth_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 * ************************************************************************/#ident "$Id: gdth.c,v 1.23 1999/03/26 09:12:31 achim Exp $" /* All GDT Disk Array Controllers are fully supported by this driver. * This includes the PCI/EISA/ISA SCSI Disk Array Controllers and the * PCI Fibre Channel Disk Array Controllers. See gdth.h for a complete * list of all controller types. * * If you have one or more GDT3000/3020 EISA controllers with * controller BIOS disabled, you have to set the IRQ values with the * command line option "gdth=irq1,irq2,...", where the irq1,irq2,... are * the IRQ values for the EISA controllers. * * After the optional list of IRQ values, other possible * command line options are: * disable:Y disable driver * disable:N enable driver * reserve_mode:0 reserve no drives for the raw service * reserve_mode:1 reserve all not init., removable drives * reserve_mode:2 reserve all not init. drives * reserve_list:h,b,t,l,h,b,t,l,... reserve particular drive(s) with * h- controller no., b- channel no., * t- target ID, l- LUN * reverse_scan:Y reverse scan order for PCI controllers * reverse_scan:N scan PCI controllers like BIOS * max_ids:x x - target ID count per channel (1..MAXID) * rescan:Y rescan all channels/IDs * rescan:N use all devices found until now * hdr_channel:x x - number of virtual bus for host drives * * The default value is: "gdth=disable:N,reserve_mode:1,reverse_scan:N, * max_ids:127,rescan:N,hdr_channel:0". * Here is another example: "gdth=reserve_list:0,1,2,0,0,1,3,0,rescan:Y". * * When loading the gdth driver as a module, the same options are available. * You can set the IRQs with "IRQ=...". However, the syntax to specify the * options changes slightly. You must replace all ',' between options * with ' ' and all ':' with '=' and you must use * '1' in place of 'Y' and '0' in place of 'N'. * * Default: "modprobe gdth disable=0 reserve_mode=1 reverse_scan=0 * max_ids=127 rescan=0 hdr_channel=0" * The other example: "modprobe gdth reserve_list=0,1,2,0,0,1,3,0 rescan=1". */#ifdef MODULE#include <linux/module.h>#endif#include <linux/version.h>#include <linux/kernel.h>#include <linux/types.h>#include <linux/pci.h>#include <linux/string.h>#include <linux/ctype.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>#include <linux/reboot.h>#include <asm/dma.h>#include <asm/system.h>#include <asm/io.h>#include <linux/spinlock.h>#include <linux/blk.h>#include "scsi.h"#include "hosts.h"#include "sd.h"#include "gdth.h"static void gdth_delay(int milliseconds);static void gdth_eval_mapping(ulong32 size, int *cyls, int *heads, int *secs);static void gdth_interrupt(int irq,void *dev_id,struct pt_regs *regs);static 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_log_event(gdth_evt_data *dvr, char *buffer);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);static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, ushort source, ushort idx, gdth_evt_data *evt);static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr);static void gdth_readapp_event(gdth_ha_str *ha, 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);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(ulong32 bios_adr);static int gdth_search_pci(gdth_pci_str *pcistr);static void gdth_sort_pci(gdth_pci_str *pcistr, int cnt);static int gdth_init_eisa(ushort eisa_adr,gdth_ha_str *ha);static int gdth_init_isa(ulong32 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,ulong32 time);static int gdth_internal_cmd(int hanum,unchar service,ushort opcode,ulong32 p1, ulong32 p2,ulong32 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);static int gdth_halt(struct notifier_block *nb, ulong event, void *buf);#ifdef DEBUG_GDTHstatic unchar DebugState = DEBUG_GDTH;extern long 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 ulong32 max_rq=0, max_index=0, max_sg=0;static ulong32 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 BUS_L2P(a,b) ((b)>(a)->virt_bus ? (b-1):(b))static void *gdth_mmap(ulong paddr, ulong size) { return ioremap(paddr, size); }static void gdth_munmap(void *addr) { return iounmap(addr);}#define gdth_readb(addr) readb((ulong)(addr))#define gdth_readw(addr) readw((ulong)(addr))#define gdth_readl(addr) (ulong32)readl((ulong)(addr))#define gdth_writeb(b,addr) writeb((b),(ulong)(addr))#define gdth_writew(b,addr) writew((b),(ulong)(addr))#define gdth_writel(b,addr) writel((b),(ulong)(addr))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -