diff -urN ultra-1.0.8/cam/cam.c ultra-1.0.8-mike/cam/cam.c --- ultra-1.0.8/cam/cam.c 2003-02-07 22:48:00.000000000 +0800 +++ ultra-1.0.8-mike/cam/cam.c 2004-09-26 14:11:25.000000000 +0800 @@ -16,6 +16,8 @@ #include "cam_gb.h" #include "cam_exp.h" +extern int cam_debug(const char *fmt,...); + #ifdef _MMIO_ void @@ -94,40 +96,40 @@ void CAMInitPacketQ(U8 card_no, PAC_Q_TYPE q_type) { - U16 i; - PU8 base_addr; + U16 i; U32 basephyaddr; PADAPTER_CONFIG pCurAdapter = &(gAdapterConfig[card_no]); if (card_no > (MAX_ADAPTER_NUM -1)) return; - base_addr = (PU8)pCurAdapter->MemVirAddr; - basephyaddr = pCurAdapter->MemPhyAddress; + basephyaddr = pCurAdapter->MemPhyAddress; switch (q_type) { - case ATA_PAC: - base_addr += ATA_BASE_ADDR; + case ATA_PAC: { + PCAM_ATA_PACKET base_addr = pCurAdapter->MemVirAddr + ATA_BASE_ADDR; basephyaddr = basephyaddr+ATA_BASE_ADDR+PACKET_HEAD_SIZE; for (i = 0; i < MAX_ATA_PAC; i++) { - ATAPacketQueue[card_no][i] = (PCAM_ATA_PACKET)base_addr; + ATAPacketQueue[card_no][i] = base_addr; (ATAPacketQueue[card_no][i])->PacketHead.Address = basephyaddr; - ((PCAM_ATA_PACKET)base_addr)++; + base_addr++; basephyaddr += ATA_PAC_SIZE; } ATAPacketCurrent[card_no] = 0; break; - case XOR_PAC: - base_addr += XOR_BASE_ADDR; - basephyaddr = basephyaddr+XOR_BASE_ADDR+PACKET_HEAD_SIZE; - for (i = 0; i < MAX_XOR_PAC; i++) { - XORPacketQueue[card_no][i] = (PCAM_XOR_PACKET)base_addr; + } + case XOR_PAC: { + PCAM_XOR_PACKET base_addr = pCurAdapter->MemVirAddr + XOR_BASE_ADDR; + basephyaddr = basephyaddr+XOR_BASE_ADDR+PACKET_HEAD_SIZE; + for (i = 0; i < MAX_XOR_PAC; i++) { + XORPacketQueue[card_no][i] = base_addr; (XORPacketQueue[card_no][i])->PacketHead.Address = basephyaddr; - ((PCAM_XOR_PACKET)base_addr)++; + base_addr++; basephyaddr += XOR_PAC_SIZE; - } + } XORPacketCurrent[card_no] = 0; break; + } default: return; } @@ -190,43 +192,42 @@ void CAMInitSGQ(U8 card_no, PAC_Q_TYPE q_type) { - U16 i; - PU8 base_addr; + U16 i; U32 basephyaddr; PADAPTER_CONFIG pCurAdapter = &(gAdapterConfig[card_no]); if (card_no > (MAX_ADAPTER_NUM -1)) return; - base_addr = (PU8)pCurAdapter->MemVirAddr; basephyaddr = pCurAdapter->MemPhyAddress; - switch (q_type) { - case ATA_PAC: - base_addr += ATA_SG_BASE_ADDR; - basephyaddr = basephyaddr+ATA_SG_BASE_ADDR; - for (i = 0; i < MAX_ATA_PAC; i++) { - PCAM_ATA_SG_Queue[card_no][i] = (PCAM_ATA_SG)base_addr; - (PCAM_ATA_SG_Queue[card_no][i])->Address = basephyaddr; - ((PCAM_ATA_SG)base_addr)++; - basephyaddr += ATA_SG_SIZE; - } - CAM_ATA_SG_Current[card_no] = 0; - break; - case XOR_PAC: - base_addr += XOR_SG_BASE_ADDR; - basephyaddr = basephyaddr+XOR_SG_BASE_ADDR; - for (i = 0; i < MAX_XOR_PAC; i++) { - PCAM_XOR_SG_Queue[card_no][i] = (PCAM_XOR_SG)base_addr; - (PCAM_XOR_SG_Queue[card_no][i])->Address = basephyaddr; - ((PCAM_XOR_SG)base_addr)++; - basephyaddr += XOR_SG_SIZE; - } - CAM_XOR_SG_Current[card_no] = 0; - break; - default: - return; + case ATA_PAC: { + PCAM_ATA_SG base_addr = pCurAdapter->MemVirAddr + ATA_SG_BASE_ADDR; + basephyaddr = basephyaddr+ATA_SG_BASE_ADDR; + for (i = 0; i < MAX_ATA_PAC; i++) { + PCAM_ATA_SG_Queue[card_no][i] = base_addr; + (PCAM_ATA_SG_Queue[card_no][i])->Address = basephyaddr; + base_addr++; + basephyaddr += ATA_SG_SIZE; + } + CAM_ATA_SG_Current[card_no] = 0; + break; + } + case XOR_PAC: { + PCAM_XOR_SG base_addr = pCurAdapter->MemVirAddr + XOR_SG_BASE_ADDR; + basephyaddr = basephyaddr+XOR_SG_BASE_ADDR; + for (i = 0; i < MAX_XOR_PAC; i++) { + PCAM_XOR_SG_Queue[card_no][i] = base_addr; + (PCAM_XOR_SG_Queue[card_no][i])->Address = basephyaddr; + base_addr++; + basephyaddr += XOR_SG_SIZE; + } + CAM_XOR_SG_Current[card_no] = 0; + break; + } + default: + return; } return; } @@ -446,7 +447,6 @@ if ( pAdapter->MemSize < MIN_CAM_MEMSIZE ) return(camFAIL); - /* save adapter data */ CurAdapter_ID = pAdapter->Adapter_ID; diff -urN ultra-1.0.8/Makefile ultra-1.0.8-mike/Makefile --- ultra-1.0.8/Makefile 2003-02-07 22:48:00.000000000 +0800 +++ ultra-1.0.8-mike/Makefile 2004-09-26 01:09:01.000000000 +0800 @@ -1,125 +1,46 @@ -########################################################################### -# Environment tests -# -# Kernel Search Path -# All the places we look for kernel source -KSP := /lib/modules/$(shell uname -r)/build \ - /usr/src/linux-$(shell uname -r) \ - /usr/src/linux-$(shell uname -r | sed 's/-.*//') \ - /usr/src/kernel-headers-$(shell uname -r) \ - /usr/src/kernel-source-$(shell uname -r) \ - /usr/src/linux-$(shell uname -r | sed 's/\([0-9]*\.[0-9]*\)\..*/\1/') \ - /usr/src/linux - -# prune the list down to only values that exist -# and have an include/linux sub-directory -test_dir = $(shell [ -e $(dir)/include/linux ] && echo $(dir)) -KSP := $(foreach dir, $(KSP), $(test_dir)) -# we will use this first valid entry in the search path -KSRC := $(firstword $(KSP)) +MODDIR:= /lib/modules/$(shell uname -r) +KERNELDIR:= $(MODDIR)/build -ifeq (,$(KSRC)) - $(error Linux kernel source not found) -endif +CONFIG_PDC_ULTRA=m +MODULE_NAME := pdc-ultra +MODULES := $(MODULE_NAME).o +MODULE_OBJS := pdc618_mod.o +MODULE_OBJS += cam/cam.o cam/cam_ata.o cam/cam_hdma.o cam/cam_isr.o \ + cam/cam_swap.o cam/cam_var.o cam/cam_xor.o +KERNEL_MODULE:=$(MODULE_NAME).ko + +ifeq ($(PDC_ULTRA_SRC_DIR),) +PDC_ULTRA_SRC_DIR := $(shell pwd) +endif +export PDC_ULTRA_SRC_DIR + +ifneq ($(KERNELRELEASE),) + +EXTRA_CFLAGS := "-I$(PDC_ULTRA_SRC_DIR)/cam" +#EXTRA_LDFLAGS:= "$(PDC_ULTRA_SRC_DIR)/cam/cam_mod.o" +obj-$(CONFIG_PDC_ULTRA) += $(MODULES) +$(MODULE_NAME)-objs += $(MODULE_OBJS) -# files we get information from in KSRC -# check for version.h and autoconf.h for running kernel in /boot (SuSE) -ifneq (,$(wildcard /boot/vmlinuz.version.h)) - VERSION_FILE := /boot/vmlinuz.version.h - CONFIG_FILE := /boot/vmlinuz.autoconf.h - KVER := $(shell $(CC) $(CFLAGS) -I$(KSRC)/include -E -dM $(VERSION_FILE) | grep UTS_RELEASE | awk '{ print $$3 }' | sed 's/\"//g') - ifeq ($(KVER),$(shell uname -r)) - # set up include path to override headers from kernel source - x:=$(shell rm -rf include) - x:=$(shell mkdir -p include/linux) - x:=$(shell cp /boot/vmlinuz.version.h include/linux/version.h) - x:=$(shell cp /boot/vmlinuz.autoconf.h include/linux/autoconf.h) - CFLAGS += -I./include - else - VERSION_FILE := $(KSRC)/include/linux/version.h - CONFIG_FILE := $(KSRC)/include/linux/config.h - endif else - VERSION_FILE := $(KSRC)/include/linux/version.h - CONFIG_FILE := $(KSRC)/include/linux/config.h -endif - -ifeq (,$(wildcard $(VERSION_FILE))) - $(error Linux kernel source not configured - missing version.h) -endif -ifeq (,$(wildcard $(CONFIG_FILE))) - $(error Linux kernel source not configured - missing config.h) -endif +all: modules -# get the kernel version - we use this to find the correct install path -KVER := $(shell $(CC) $(CFLAGS) -I$(KSRC)/include -E -dM $(VERSION_FILE) | grep UTS_RELEASE | awk '{ print $$3 }' | sed 's/\"//g') +modules: + rm -f build; ln -fs "$(KERNELDIR)" build + $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PDC_ULTRA_SRC_DIR) modules + +install: + install $(KERNEL_MODULE) $(MODDIR) + depmod -ae + +uninstall: + rm -f $(MODDIR)/$(KERNEL_MODULE) + depmod -ae -ifneq ($(KVER),$(shell uname -r)) - $(warning ***) - $(warning *** Warning: kernel source version ($(KVER))) - $(warning *** does not match running kernel ($(shell uname -r))) - $(warning *** Continuing with build,) - $(warning *** resulting driver may not be what you want) - $(warning ***) -endif +clean: + rm -f $(MODULE_NAME).ko $(MODULE_OBJS) $(MODULES) *~ cam/*~ + rm -f .*o.cmd cam/.*.o.cmd *.mod.? build + rm -rf .tmp_versions -# pick an appropriate install path -ifneq (,$(wildcard /lib/modules/$(KVER)/kernel)) - INSTDIR := /lib/modules/$(KVER)/kernel/drivers/scsi -else - INSTDIR := /lib/modules/$(KVER)/scsi endif - -CROSS_COMPILE = -CC = $(CROSS_COMPILE)gcc -LD = $(CROSS_COMPILE)ld -HPATH = -I$(KSRC)/include -I$(KSRC) -Icam -I$(KSRC)/arch/i386/mach-generic -MFLAGS = -D__KERNEL__ -DMODULE -D__LINUX__ -D_MMIO_ $(HPATH) -CFLAGS += $(MFLAGS) -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer \ - -fno-strict-aliasing -pipe -mpreferred-stack-boundary=2 - -CFLAGS += $(shell [ -f $(KSRC)/include/linux/modversions.h ] && \ - echo "-DMODVERSIONS -include $(KSRC)/include/linux/modversions.h") - -GENERIC = $(CFLAGS) -fno-common -march=i386 - -SuSE = $(CFLAGS) -march=i586 - -TURBO = $(CFLAGS) -march=i586 - -MDK = $(CFLAGS) -fno-common -fno-merge-constants -march=i586 - -PPC = $(CFLAGS) -fno-common -DCPU=ppc - -TARGET = pdc-ultra.o -CFILES = pdc618_mod.c -HFILES = pdc618_mod.h - - -.SLIENT: $(TARGET) -$(TARGET): $(filter-out $(TARGET), $(CFILES:.c=.o)) cam/cam_mod.o - $(LD) -r -o $@ $^ - -$(CFILES:.c=.o): $(CFILES) $(HFILES) Makefile - cd cam; ${MAKE} - $(CC) $(GENERIC) -c $*.c -#$(CC) $(SuSE) -c $*.c -#$(CC) $(TURBO) -c $*.c -#$(CC) $(MDK) -c $*.c -#$(CC) $(PPC) -c $*.c - -install: $(TARGET) - find /lib/modules/$(KVER) -name $(TARGET)/ -exec rm {} \; - mkdir -p $(INSTDIR) - install -m 644 -o 0 $(TARGET) $(INSTDIR) - /sbin/depmod -aqs - -uninstall: - rm -f $(INSTDIR)/$(TARGET) - /sbin/depmod -aqs - -clean : - cd cam; ${MAKE} clean - rm -rf $(TARGET) $(CFILES:.c=.o) include diff -urN ultra-1.0.8/Makefile.orig ultra-1.0.8-mike/Makefile.orig --- ultra-1.0.8/Makefile.orig 1970-01-01 08:00:00.000000000 +0800 +++ ultra-1.0.8-mike/Makefile.orig 2003-02-07 22:48:44.000000000 +0800 @@ -0,0 +1,125 @@ +########################################################################### +# Environment tests +# +# Kernel Search Path +# All the places we look for kernel source +KSP := /lib/modules/$(shell uname -r)/build \ + /usr/src/linux-$(shell uname -r) \ + /usr/src/linux-$(shell uname -r | sed 's/-.*//') \ + /usr/src/kernel-headers-$(shell uname -r) \ + /usr/src/kernel-source-$(shell uname -r) \ + /usr/src/linux-$(shell uname -r | sed 's/\([0-9]*\.[0-9]*\)\..*/\1/') \ + /usr/src/linux + +# prune the list down to only values that exist +# and have an include/linux sub-directory +test_dir = $(shell [ -e $(dir)/include/linux ] && echo $(dir)) +KSP := $(foreach dir, $(KSP), $(test_dir)) + +# we will use this first valid entry in the search path +KSRC := $(firstword $(KSP)) + +ifeq (,$(KSRC)) + $(error Linux kernel source not found) +endif + +# files we get information from in KSRC +# check for version.h and autoconf.h for running kernel in /boot (SuSE) +ifneq (,$(wildcard /boot/vmlinuz.version.h)) + VERSION_FILE := /boot/vmlinuz.version.h + CONFIG_FILE := /boot/vmlinuz.autoconf.h + KVER := $(shell $(CC) $(CFLAGS) -I$(KSRC)/include -E -dM $(VERSION_FILE) | grep UTS_RELEASE | awk '{ print $$3 }' | sed 's/\"//g') + ifeq ($(KVER),$(shell uname -r)) + # set up include path to override headers from kernel source + x:=$(shell rm -rf include) + x:=$(shell mkdir -p include/linux) + x:=$(shell cp /boot/vmlinuz.version.h include/linux/version.h) + x:=$(shell cp /boot/vmlinuz.autoconf.h include/linux/autoconf.h) + CFLAGS += -I./include + else + VERSION_FILE := $(KSRC)/include/linux/version.h + CONFIG_FILE := $(KSRC)/include/linux/config.h + endif +else + VERSION_FILE := $(KSRC)/include/linux/version.h + CONFIG_FILE := $(KSRC)/include/linux/config.h +endif + +ifeq (,$(wildcard $(VERSION_FILE))) + $(error Linux kernel source not configured - missing version.h) +endif + +ifeq (,$(wildcard $(CONFIG_FILE))) + $(error Linux kernel source not configured - missing config.h) +endif + +# get the kernel version - we use this to find the correct install path +KVER := $(shell $(CC) $(CFLAGS) -I$(KSRC)/include -E -dM $(VERSION_FILE) | grep UTS_RELEASE | awk '{ print $$3 }' | sed 's/\"//g') + +ifneq ($(KVER),$(shell uname -r)) + $(warning ***) + $(warning *** Warning: kernel source version ($(KVER))) + $(warning *** does not match running kernel ($(shell uname -r))) + $(warning *** Continuing with build,) + $(warning *** resulting driver may not be what you want) + $(warning ***) +endif + +# pick an appropriate install path +ifneq (,$(wildcard /lib/modules/$(KVER)/kernel)) + INSTDIR := /lib/modules/$(KVER)/kernel/drivers/scsi +else + INSTDIR := /lib/modules/$(KVER)/scsi +endif + +CROSS_COMPILE = +CC = $(CROSS_COMPILE)gcc +LD = $(CROSS_COMPILE)ld +HPATH = -I$(KSRC)/include -I$(KSRC) -Icam -I$(KSRC)/arch/i386/mach-generic +MFLAGS = -D__KERNEL__ -DMODULE -D__LINUX__ -D_MMIO_ $(HPATH) +CFLAGS += $(MFLAGS) -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer \ + -fno-strict-aliasing -pipe -mpreferred-stack-boundary=2 + +CFLAGS += $(shell [ -f $(KSRC)/include/linux/modversions.h ] && \ + echo "-DMODVERSIONS -include $(KSRC)/include/linux/modversions.h") + +GENERIC = $(CFLAGS) -fno-common -march=i386 + +SuSE = $(CFLAGS) -march=i586 + +TURBO = $(CFLAGS) -march=i586 + +MDK = $(CFLAGS) -fno-common -fno-merge-constants -march=i586 + +PPC = $(CFLAGS) -fno-common -DCPU=ppc + +TARGET = pdc-ultra.o +CFILES = pdc618_mod.c +HFILES = pdc618_mod.h + + +.SLIENT: $(TARGET) +$(TARGET): $(filter-out $(TARGET), $(CFILES:.c=.o)) cam/cam_mod.o + $(LD) -r -o $@ $^ + +$(CFILES:.c=.o): $(CFILES) $(HFILES) Makefile + cd cam; ${MAKE} + $(CC) $(GENERIC) -c $*.c +#$(CC) $(SuSE) -c $*.c +#$(CC) $(TURBO) -c $*.c +#$(CC) $(MDK) -c $*.c +#$(CC) $(PPC) -c $*.c + +install: $(TARGET) + find /lib/modules/$(KVER) -name $(TARGET)/ -exec rm {} \; + mkdir -p $(INSTDIR) + install -m 644 -o 0 $(TARGET) $(INSTDIR) + /sbin/depmod -aqs + +uninstall: + rm -f $(INSTDIR)/$(TARGET) + /sbin/depmod -aqs + +clean : + cd cam; ${MAKE} clean + rm -rf $(TARGET) $(CFILES:.c=.o) include diff -urN ultra-1.0.8/pdc618_mod.c ultra-1.0.8-mike/pdc618_mod.c --- ultra-1.0.8/pdc618_mod.c 2003-02-07 22:48:00.000000000 +0800 +++ ultra-1.0.8-mike/pdc618_mod.c 2004-09-26 22:08:37.000000000 +0800 @@ -6,7 +6,7 @@ * ------ * parameter: * atapi 1/0, enable atapi deivce, default is 0 - * debug 0-2, debug level, default is 0 + * debug 0-15, debug level, default is 0 * * History * ------- @@ -39,17 +39,27 @@ #include #include #include -#include +#include +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) #include +#endif #include #include +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) #include +#endif #include #include +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) #include #include #include +#else +#include "build/drivers/scsi/scsi.h" +#include +#endif + #include #include @@ -109,6 +119,20 @@ static inline int pdc618_ata_rw(Scsi_Cmnd *SCpnt); void pdc618_scan_device(unsigned long drv); +int cam_debug(const char *fmt, ...) +{ + va_list args; + int len; + static char cam_debug_buf[1024]; + va_start(args, fmt); + strcpy(cam_debug_buf, KERN_ERR); + len=strlen(cam_debug_buf); + len+=vscnprintf(cam_debug_buf+len, sizeof(cam_debug_buf)-len, fmt, args); + va_end(args); + printk(cam_debug_buf); + return len; +} + /* * Deal with DMA mapping/unmapping. */ @@ -290,27 +314,29 @@ /* * interrupt handler */ -void pdc618_interrupt(int irq, void *dev_id, struct pt_regs *regs) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) +#define irq_ret(x) return +void +#else +#define irq_ret(x) return (x) +static irqreturn_t +#endif +pdc618_interrupt(int irq, void *dev_id, struct pt_regs *regs) { unsigned long flags = 0; unsigned long irqhandle = 0; - pdc618_adapter_t *pada = (pdc618_adapter_t *) dev_id; unsigned char ua; spinlock_t *host_lock; -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,3) - host_lock = &io_request_lock; -#else - host_lock = pada->host->host_lock; -#endif - + pdc618_adapter_t *pada = (pdc618_adapter_t *) dev_id; /* check adapter data */ if ( (!pada) ) { - return; + if (debug & LOGISR) printk(KERN_ERR "%s: no pada\n", PDCNAME); + irq_ret(IRQ_NONE); } - /* set adapter bit according to irq */ + if (debug & LOGISR) printk(KERN_DEBUG "%s: [D] ISR irq %d\n", PDCNAME, irq); for (ua = 0; ua < MAXADAPTER; ua++) { if(pdc618_adapter[ua].present) { if (pdc618_adapter[ua].irq == irq) @@ -319,30 +345,40 @@ } } + /* debug */ + if (debug & (LOGATA|LOGISR)) { + printk(KERN_DEBUG "%s:[D] ISR handle=%#lx\n", + PDCNAME, irqhandle); + } + /* not our irq */ if (!irqhandle) { - return; + irq_ret(IRQ_NONE); } - /* debug */ - if (debug & LOGATA) { - printk(KERN_DEBUG "%s:[D] ISR handle=%#lx\n", - PDCNAME, irqhandle); + if (!pada->host) { + if (debug & LOGISR) printk(KERN_ERR "%s: pada->host is null\n", PDCNAME); + irq_ret(IRQ_NONE); } +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,3) + host_lock = &io_request_lock; +#else + host_lock = pada->host->host_lock; +#endif + spin_lock_irqsave(host_lock, flags); CAM_ISR(irqhandle); spin_unlock_irqrestore(host_lock, flags); - return; + irq_ret(IRQ_HANDLED); } /* * initialize ioport and irq */ -int pdc618_init_ioport(unsigned char ada) +int pdc618_init_ioport(pdc618_adapter_t *pada) { unsigned char uc; - pdc618_adapter_t *pada = &pdc618_adapter[ada]; struct pci_dev *pdc618_pci_dev = pada->pci_dev; unsigned short command; @@ -357,7 +393,7 @@ pci_write_config_dword(pdc618_pci_dev,PCI_BASE_ADDRESS_0+4*uc,base); pada->base[uc] = base & PCI_BASE_ADDRESS_IO_MASK; - /* printk("base[%d]=%#x\n",uc,pada->base[uc]); */ + if (debug) printk("adapter %d base[%d]=%#x\n",pada->id,uc,pada->base[uc]); } /* enable bus master */ @@ -367,16 +403,15 @@ pci_read_config_dword(pdc618_pci_dev,0x30,&pada->rombase); /* register ioport */ - if (!check_region(pada->base[0],pada->range[0])) { - request_region(pada->base[0],pada->range[0],PDCNAME"(ATA)"); - } - if (!check_region(pada->base[1],pada->range[1])) - request_region(pada->base[1],pada->range[1],PDCNAME"(XOR)"); - if (!check_region(pada->base[2],pada->range[2])) - request_region(pada->base[2],pada->range[2],PDCNAME"(HOST)"); + if (!request_region(pada->base[0],pada->range[0],PDCNAME"(ATA)")) + return 2; + if (!request_region(pada->base[1],pada->range[1],PDCNAME"(XOR)")) + return 2; + if (!request_region(pada->base[2],pada->range[2],PDCNAME"(HOST)")) + return 2; if (request_irq(pdc618_pci_dev->irq, pdc618_interrupt, SA_INTERRUPT| SA_SHIRQ, PDCNAME,pada)) { - printk(KERN_ERR "%s:[error] adapter%d request irq failed\n",PDCNAME,ada); + printk(KERN_ERR "%s:[error] adapter%d request irq failed\n",PDCNAME,pada->id); return(2); } return(0); @@ -396,6 +431,7 @@ struct pci_dev *pdc618_pci_dev = pci_devices ; #endif class = adapter = 0; + while (PDC618_DEVID[class]) { /* search pci bus according to vendorID, deviceID */ while( (pdc618_pci_dev = pci_find_device(PCI_VENDOR_ID_PROMISE, PDC618_DEVID[class], pdc618_pci_dev)) ) { @@ -418,6 +454,7 @@ /* offset 0x0C SATA:0x91 FT:0x90 */ if (PDC618_DEVID[class] == DID378) { unsigned char code = 0; + pci_read_config_byte(pdc618_pci_dev, 0x0c, &code); /* SATA is 0x91 */ if (code != 0x91) @@ -669,13 +706,12 @@ /* * initialize cam */ -int pdc618_init_cam(unsigned char ada) +int pdc618_init_cam(pdc618_adapter_t *pada) { unsigned char i,uc,ud; unsigned char order = 0; unsigned long cam_size; unsigned long *cam_mem; - pdc618_adapter_t *pada = &pdc618_adapter[ada]; ADAPTER_CONFIG_INFO *pcam_ada = pada->cam_ada; CAM_INFO *pcam_info = pada->cam_info; MODULE_PACKET_COUNT pcnt; @@ -707,25 +743,27 @@ pcam_ada->MemSize = (unsigned long) (1 << order) << PAGE_SHIFT; /* init cam */ - if (CAM_Init(pcam_ada) != camSUCCESS) + if (CAM_Init(pcam_ada) != camSUCCESS) { printk(KERN_ERR "%s:[error] cam init failed\n",PDCNAME); + return 1; + } /* scan device */ for (ud = 0; ud < DrvPCh*ChPAda; ud++) { - unsigned long drv = ada*DrvPCh*ChPAda + ud; + unsigned long drv = pada->id*DrvPCh*ChPAda + ud; pdc618_scan_device(drv); } /* get cam packet count */ - CAM_GetPacketCount(ada, &pcnt); + CAM_GetPacketCount(pada->id, &pcnt); /* set cam packet count to 1 to avoid overrun */ for (uc = 0; uc < ChPAda; uc++) { - pcnt.ATAModule[uc] = 1; + pcnt.ATAModule[pada->id] = 1; } /* set cam packet count */ - CAM_SetPacketCount(ada, &pcnt); + CAM_SetPacketCount(pada->id, &pcnt); return(0); } @@ -733,12 +771,12 @@ /* * free resource: adapter dependent */ -void pdc618_cleanup(int ada) +void pdc618_cleanup(pdc618_adapter_t *pada) { unsigned char i,j; - pdc618_adapter_t *pada = &pdc618_adapter[ada]; +#ifdef _MMIO_ CAM_INFO *pcam_info = pada->cam_info; - +#endif if (!pada->present) return; @@ -796,7 +834,8 @@ /* remove timer */ for ( i = 0; i < MAXTIMER; i++) { - del_timer(&pdc618_timer[i].timer); + if (pdc618_timer[i].status != camFREE) + del_timer(&pdc618_timer[i].timer); } /* free queue memory */ @@ -843,7 +882,7 @@ if(!pdc618_adapter[ua].present) continue; - if (pdc618_init_ioport(ua)) { + if (pdc618_init_ioport(&pdc618_adapter[ua])) { printk(KERN_ERR "%s:[error] adapter%d: init ioport failed\n",PDCNAME,ua); return(0); } @@ -854,7 +893,7 @@ if(!pdc618_adapter[ua].present) continue; - if (pdc618_init_cam(ua)) { + if (pdc618_init_cam(&pdc618_adapter[ua])) { printk(KERN_ERR "%s:[error] adapter%d: init cam failed\n",PDCNAME,ua); return(0); } @@ -862,10 +901,11 @@ /* register scsi host */ for (ua = 0; ua < adapters; ua++) { + if (debug) printk(KERN_ERR "%s: registering scsi host for adapter %d\n", PDCNAME, ua); shpnt = scsi_register(pdc618_host,sizeof(pdc618_adapter_t)); if (shpnt == NULL) { printk(KERN_ERR "%s:[error] adapter%d: register scsi host failed\n",PDCNAME,ua); - pdc618_cleanup(ua); + pdc618_cleanup(&pdc618_adapter[ua]); return(0); } shpnt->max_channel=0; @@ -873,12 +913,13 @@ shpnt->max_lun=1; if (!shpnt->hostdata) { printk(KERN_ERR "%s:[error] adapter%d: register scsi host failed\n",PDCNAME,ua); - pdc618_cleanup(ua); + pdc618_cleanup(&pdc618_adapter[ua]); return(0); } + pdc618_adapter[ua].host=shpnt; pada = (pdc618_adapter_t *) shpnt->hostdata; - memcpy(pada, &pdc618_adapter[ua], sizeof(pdc618_adapter_t)); - pada->host = shpnt; + memcpy(pada, &pdc618_adapter[ua], sizeof(pdc618_adapter_t)); + } return(adapters); @@ -889,7 +930,7 @@ */ int pdc618_release(struct Scsi_Host *shpnt) { -#if 0 +#if 1 pdc618_adapter_t *pada =(pdc618_adapter_t *)shpnt->hostdata; /* close cam */ @@ -900,7 +941,7 @@ } /* free memory, irq, ioport */ - pdc618_cleanup(pada->id); + pdc618_cleanup(pada); /* free queue, timer */ pdc618_cleanup2(); @@ -1050,7 +1091,13 @@ /* * proc info */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) +int pdc618_proc_info(struct Scsi_Host *host, + char *buffer, char **start, off_t offset, + int length, int func) +#else int pdc618_proc_info(char *buffer, char **start, off_t offset, int length, int hostno, int func) +#endif { pdc618_info_t info; unsigned char i; @@ -1286,7 +1333,12 @@ { pdc618_req_t *req = (pdc618_req_t *) ptask->pTaskExtension; Scsi_Cmnd *SCpnt = req->cmd; + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) + pdc618_adapter_t *pada =(pdc618_adapter_t *)SCpnt->device->host->hostdata; +#else pdc618_adapter_t *pada =(pdc618_adapter_t *)SCpnt->host->hostdata; +#endif pdc618_drive_t *pdrv; int result = DID_OK << 16; int id; @@ -1343,7 +1395,11 @@ { pdc618_req_t *req = (pdc618_req_t *) ptask->pTaskExtension; Scsi_Cmnd *SCpnt = req->cmd; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) + pdc618_adapter_t *pada =(pdc618_adapter_t *)SCpnt->device->host->hostdata; +#else pdc618_adapter_t *pada =(pdc618_adapter_t *)SCpnt->host->hostdata; +#endif /* unmap DMA mapping */ if (SCpnt->use_sg) @@ -1454,13 +1510,16 @@ static inline int pdc618_ata_rw(Scsi_Cmnd *SCpnt) { unsigned char id; - pdc618_req_t *queue; - pdc618_adapter_t *pada =(pdc618_adapter_t *)SCpnt->host->hostdata; + pdc618_req_t *queue=pdc618_request_start(); unsigned char *cmd = (unsigned char *) SCpnt->cmnd; - queue = pdc618_request_start(); - +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) + pdc618_adapter_t *pada =(pdc618_adapter_t *)SCpnt->device->host->hostdata; + id = pada->id*ChPAda*DrvPCh + SCpnt->device->id; +#else + pdc618_adapter_t *pada =(pdc618_adapter_t *)SCpnt->host->hostdata; id = pada->id*ChPAda*DrvPCh + SCpnt->target; +#endif /* attach SCpnt for DMA mapping */ queue->cmd = SCpnt; @@ -1563,9 +1622,13 @@ int bufflen = SCpnt->request_bufflen; PCAMSG psg; pdc618_req_t *queue; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) + pdc618_adapter_t *pada =(pdc618_adapter_t *)SCpnt->device->host->hostdata; + id = pada->id*ChPAda*DrvPCh + SCpnt->device->id; +#else pdc618_adapter_t *pada =(pdc618_adapter_t *)SCpnt->host->hostdata; - id = pada->id*ChPAda*DrvPCh + SCpnt->target; +#endif queue = pdc618_request_start(); queue->cmd = SCpnt; @@ -1645,9 +1708,13 @@ unsigned char id; int bufflen = SCpnt->request_bufflen; pdc618_req_t *queue; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) + pdc618_adapter_t *pada =(pdc618_adapter_t *)SCpnt->device->host->hostdata; + id = pada->id*ChPAda*DrvPCh + SCpnt->device->id; +#else pdc618_adapter_t *pada =(pdc618_adapter_t *)SCpnt->host->hostdata; - id = pada->id*ChPAda*DrvPCh + SCpnt->target; +#endif queue = pdc618_request_start(); queue->cmd = SCpnt; @@ -1741,13 +1808,21 @@ __data_mapped(SCpnt) = 0; __data_mapping(SCpnt) = 0; - if ( debug ) { - printk(KERN_DEBUG "%s:[D] Qcmd t=%d cmd=", - PDCNAME, SCpnt->target); + if ( debug & (LOGATA|LOGATAPI) ) { + printk(KERN_DEBUG "%s:[D] Qcmd t=%d cmd=", PDCNAME, +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) + SCpnt->device->id); +#else + SCpnt->target); +#endif hexdump(SCpnt->cmnd, SCpnt->cmd_len); } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) + pada = (pdc618_adapter_t *)SCpnt->device->host->hostdata; +#else pada = (pdc618_adapter_t *) SCpnt->host->hostdata; +#endif if (pada == NULL ) { printk(KERN_ERR "%s:[error] invalid device in queue cmd\n",PDCNAME); SCpnt->result = (DID_ERROR << 16); @@ -1756,7 +1831,11 @@ } spin_lock_irqsave(&pada->pdc618_lock, lock); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) + drv = pada->id*ChPAda*DrvPCh + SCpnt->device->id; +#else drv = pada->id*ChPAda*DrvPCh + SCpnt->target; +#endif pdrv = &pdc618_drive[drv]; pcam_dev = pdrv->cam_dev; @@ -1910,9 +1989,14 @@ { unsigned char chn,id; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) + pdc618_adapter_t *pada = (pdc618_adapter_t *)SCpnt->device->host->hostdata; + id = pada->id*ChPAda*DrvPCh + SCpnt->device->id; +#else pdc618_adapter_t *pada =(pdc618_adapter_t *)SCpnt->host->hostdata; - id = pada->id*ChPAda*DrvPCh + SCpnt->target; +#endif + chn = id / DrvPCh; printk(KERN_WARNING "%s:[warning] scsi reset channel%x ",PDCNAME,chn+1); SCpnt->result = DID_RESET << 16; @@ -1931,11 +2015,16 @@ int pdc618_scsi_eh_device_reset(Scsi_Cmnd *SCpnt) { unsigned char chn,id; - pdc618_adapter_t *pada =(pdc618_adapter_t *)SCpnt->host->hostdata; pdc618_drive_t *pdrv; PDEV_CONFIG cam_dev; - +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) + pdc618_adapter_t *pada = (pdc618_adapter_t *)SCpnt->device->host->hostdata; + id = pada->id*ChPAda*DrvPCh + SCpnt->device->id; +#else + pdc618_adapter_t *pada =(pdc618_adapter_t *)SCpnt->host->hostdata; id = pada->id*ChPAda*DrvPCh + SCpnt->target; +#endif + chn = id / DrvPCh; pdrv = &pdc618_drive[id]; cam_dev = pdrv->cam_dev; @@ -1956,9 +2045,14 @@ { unsigned char chn,id; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) + pdc618_adapter_t *pada = (pdc618_adapter_t *)SCpnt->device->host->hostdata; + id = pada->id*ChPAda*DrvPCh + SCpnt->device->id; +#else pdc618_adapter_t *pada =(pdc618_adapter_t *)SCpnt->host->hostdata; - id = pada->id*ChPAda*DrvPCh + SCpnt->target; +#endif + chn = id / DrvPCh; printk(KERN_WARNING "%s:[warning] scsi eh reset channel%x ",PDCNAME,chn+1); if (CAM_ResetATAChannel(chn) == camSUCCESS) { @@ -1974,26 +2068,33 @@ * returns unit geometry in cylinders/heads/sectors */ #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,27) +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0) +int pdc618_bios_param(struct scsi_device *disk, struct block_device *dev, + sector_t capacity, int geom[]) +{ unsigned long size=capacity; +#else int pdc618_bios_param(Disk *disk, struct block_device *dev, int geom[]) +{ unsigned long size=disk->capacity; +#endif #else int pdc618_bios_param(Disk *disk, kdev_t dev, int geom[]) +{ unsigned long size=disk->capacity; #endif -{ int heads, sectors, cylinders; heads = 64; sectors = 32; - cylinders = disk->capacity / (heads * sectors); + cylinders = size / (heads * sectors); - if (disk->capacity > 0x200000) /* > 1GB */ { + if (size > 0x200000) /* > 1GB */ { heads = 255; sectors = 63; - cylinders = disk->capacity / (heads * sectors); + cylinders = size / (heads * sectors); /* > 526GB (C/H/S = 65535/255/63) */ if ( cylinders > 65535 ) { cylinders = 65535; - sectors = disk->capacity / (cylinders*heads); + sectors = size / (cylinders*heads); } } @@ -2207,7 +2308,39 @@ #endif #ifdef MODULE -Scsi_Host_Template driver_template = pdc618; +Scsi_Host_Template driver_template = { +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) + next: NULL, + command: NULL, + use_new_eh_code: 0, + slave_attach: NULL, + abort: pdc618_scsi_abort, + reset: pdc618_scsi_reset, +#endif + proc_info: pdc618_proc_info, + name: PDCNAME, + detect: pdc618_detect, + release: pdc618_release, + ioctl: pdc618_ioctl, + info: NULL, + queuecommand: pdc618_queuecommand, + eh_abort_handler: pdc618_scsi_eh_abort, + eh_device_reset_handler: pdc618_scsi_eh_device_reset, + eh_host_reset_handler: pdc618_scsi_eh_host_reset, + bios_param: pdc618_bios_param, + can_queue: QLENGTH, + this_id: -1, + sg_tablesize: MAXSGTABLE, + cmd_per_lun: 1, + present: 0, + unchecked_isa_dma: 0, + use_clustering: DISABLE_CLUSTERING, + emulated: 1 +}; + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) +#include "build/drivers/scsi/scsi_module.c" +#else #include int init_module(void) { @@ -2243,7 +2376,7 @@ printk(KERN_ERR "%s:[error] can't close cam\n",PDCNAME); /* free memory, irq, ioport */ - pdc618_cleanup(ua); + pdc618_cleanup(pada); } } @@ -2260,3 +2393,5 @@ } #endif + +#endif diff -urN ultra-1.0.8/pdc618_mod.h ultra-1.0.8-mike/pdc618_mod.h --- ultra-1.0.8/pdc618_mod.h 2003-02-07 22:48:00.000000000 +0800 +++ ultra-1.0.8-mike/pdc618_mod.h 2004-09-26 19:44:36.000000000 +0800 @@ -38,6 +38,8 @@ #define LOGATA 0x1 #define LOGATAPI 0x2 +#define LOGISR 0x4 +#define LOGINIT 0x8 unsigned short PDC618_DEVID[5] = { DID618, DID318, DID375, DID378, 0}; @@ -107,32 +109,4 @@ int position; } __attribute__ ((packed)); -#define pdc618 { \ - next: NULL, \ - proc_info: pdc618_proc_info, \ - name: PDCNAME, \ - detect: pdc618_detect, \ - release: pdc618_release, \ - ioctl: pdc618_ioctl, \ - info: NULL, \ - command: NULL, \ - queuecommand: pdc618_queuecommand, \ - abort: pdc618_scsi_abort, \ - reset: pdc618_scsi_reset, \ - eh_abort_handler: pdc618_scsi_eh_abort, \ - eh_device_reset_handler: pdc618_scsi_eh_device_reset, \ - eh_host_reset_handler: pdc618_scsi_eh_host_reset, \ - slave_attach: NULL, \ - bios_param: pdc618_bios_param, \ - can_queue: QLENGTH, \ - this_id: -1, \ - sg_tablesize: MAXSGTABLE, \ - cmd_per_lun: 1, \ - present: 0, \ - unchecked_isa_dma: 0, \ - use_clustering: DISABLE_CLUSTERING, \ - use_new_eh_code: 0, \ - emulated: 1 \ -} - #endif /* end of _PDC618_MOD_H */