X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=drivers%2Fscsi%2Fsym53c8xx_2%2Fsym_glue.c;h=3ed36af0c893d65be84f8c036b5f3938488f0ab6;hb=6a77f38946aaee1cd85eeec6cf4229b204c15071;hp=0d9d1b42b184362ab84a0f3a0c67166ce7719f96;hpb=87fc8d1bb10cd459024a742c6a10961fefcef18f;p=linux-2.6.git diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c index 0d9d1b42b..3ed36af0c 100644 --- a/drivers/scsi/sym53c8xx_2/sym_glue.c +++ b/drivers/scsi/sym53c8xx_2/sym_glue.c @@ -3,6 +3,7 @@ * of PCI-SCSI IO processors. * * Copyright (C) 1999-2001 Gerard Roudier + * Copyright (c) 2003-2004 Matthew Wilcox * * This driver is derived from the Linux sym53c8xx driver. * Copyright (C) 1998-2000 Gerard Roudier @@ -22,39 +23,25 @@ * *----------------------------------------------------------------------------- * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * 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. * - * Where this Software is combined with software released under the terms of - * the GNU Public License ("GPL") and the terms of the GPL would require the - * combined work to also be released under the terms of the GPL, the terms - * and conditions of this License will apply in addition to those of the - * GPL with the exception of any terms or conditions of this License that - * conflict with, or are expressly prohibited by, the GPL. + * 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. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define SYM_GLUE_C - #include #include #include #include +#include #include #include #include @@ -68,6 +55,86 @@ #define NAME53C "sym53c" #define NAME53C8XX "sym53c8xx" +/* SPARC just has to be different ... */ +#ifdef __sparc__ +#define IRQ_FMT "%s" +#define IRQ_PRM(x) __irq_itoa(x) +#else +#define IRQ_FMT "%d" +#define IRQ_PRM(x) (x) +#endif + +struct sym_driver_setup sym_driver_setup = SYM_LINUX_DRIVER_SETUP; +unsigned int sym_debug_flags = 0; + +static char *excl_string; +static char *safe_string; +module_param_named(cmd_per_lun, sym_driver_setup.max_tag, ushort, 0); +module_param_string(tag_ctrl, sym_driver_setup.tag_ctrl, 100, 0); +module_param_named(burst, sym_driver_setup.burst_order, byte, 0); +module_param_named(led, sym_driver_setup.scsi_led, byte, 0); +module_param_named(diff, sym_driver_setup.scsi_diff, byte, 0); +module_param_named(irqm, sym_driver_setup.irq_mode, byte, 0); +module_param_named(buschk, sym_driver_setup.scsi_bus_check, byte, 0); +module_param_named(hostid, sym_driver_setup.host_id, byte, 0); +module_param_named(verb, sym_driver_setup.verbose, byte, 0); +module_param_named(debug, sym_debug_flags, uint, 0); +module_param_named(settle, sym_driver_setup.settle_delay, byte, 0); +module_param_named(nvram, sym_driver_setup.use_nvram, byte, 0); +module_param_named(excl, excl_string, charp, 0); +module_param_named(safe, safe_string, charp, 0); + +MODULE_PARM_DESC(cmd_per_lun, "The maximum number of tags to use by default"); +MODULE_PARM_DESC(tag_ctrl, "More detailed control over tags per LUN"); +MODULE_PARM_DESC(burst, "Maximum burst. 0 to disable, 255 to read from registers"); +MODULE_PARM_DESC(led, "Set to 1 to enable LED support"); +MODULE_PARM_DESC(diff, "0 for no differential mode, 1 for BIOS, 2 for always, 3 for not GPIO3"); +MODULE_PARM_DESC(irqm, "0 for open drain, 1 to leave alone, 2 for totem pole"); +MODULE_PARM_DESC(buschk, "0 to not check, 1 for detach on error, 2 for warn on error"); +MODULE_PARM_DESC(hostid, "The SCSI ID to use for the host adapters"); +MODULE_PARM_DESC(verb, "0 for minimal verbosity, 1 for normal, 2 for excessive"); +MODULE_PARM_DESC(debug, "Set bits to enable debugging"); +MODULE_PARM_DESC(settle, "Settle delay in seconds. Default 3"); +MODULE_PARM_DESC(nvram, "Option currently not used"); +MODULE_PARM_DESC(excl, "List ioport addresses here to prevent controllers from being attached"); +MODULE_PARM_DESC(safe, "Set other settings to a \"safe mode\""); + +MODULE_LICENSE("GPL"); +MODULE_VERSION(SYM_VERSION); +MODULE_AUTHOR("Matthew Wilcox "); +MODULE_DESCRIPTION("NCR, Symbios and LSI 8xx and 1010 PCI SCSI adapters"); + +static void sym2_setup_params(void) +{ + char *p = excl_string; + int xi = 0; + + while (p && (xi < 8)) { + char *next_p; + int val = (int) simple_strtoul(p, &next_p, 0); + sym_driver_setup.excludes[xi++] = val; + p = next_p; + } + + if (safe_string) { + if (*safe_string == 'y') { + sym_driver_setup.max_tag = 0; + sym_driver_setup.burst_order = 0; + sym_driver_setup.scsi_led = 0; + sym_driver_setup.scsi_diff = 1; + sym_driver_setup.irq_mode = 0; + sym_driver_setup.scsi_bus_check = 2; + sym_driver_setup.host_id = 7; + sym_driver_setup.verbose = 2; + sym_driver_setup.settle_delay = 10; + sym_driver_setup.use_nvram = 1; + } else if (*safe_string != 'n') { + printk(KERN_WARNING NAME53C8XX "Ignoring parameter %s" + " passed to safe option", safe_string); + } + } +} + static int __devinit pci_get_base_address(struct pci_dev *pdev, int index, u_long *base) { @@ -89,7 +156,7 @@ pci_get_base_address(struct pci_dev *pdev, int index, u_long *base) } /* This lock protects only the memory allocation/free. */ -spinlock_t sym53c8xx_lock = SPIN_LOCK_UNLOCKED; +static DEFINE_SPINLOCK(sym53c8xx_lock); static struct scsi_transport_template *sym2_transport_template = NULL; @@ -147,7 +214,7 @@ m_addr_t __vtobus(m_pool_ident_t dev_dmat, void *m) * It is allocated on the eh thread stack. */ struct sym_eh_wait { - struct semaphore sem; + struct completion done; struct timer_list timer; void (*old_done)(struct scsi_cmnd *); int to_do; @@ -158,7 +225,6 @@ struct sym_eh_wait { * Driver private area in the SCSI command structure. */ struct sym_ucmd { /* Override the SCSI pointer structure */ - SYM_QUEHEAD link_cmdq; /* Must stay at offset ZERO */ dma_addr_t data_mapping; u_char data_mapped; struct sym_eh_wait *eh_wait; @@ -224,12 +290,11 @@ static int __map_scsi_sg_data(struct pci_dev *pdev, struct scsi_cmnd *cmd) */ void sym_xpt_done(struct sym_hcb *np, struct scsi_cmnd *ccb) { - sym_remque(&SYM_UCMD_PTR(ccb)->link_cmdq); unmap_scsi_data(np, ccb); ccb->scsi_done(ccb); } -void sym_xpt_done2(struct sym_hcb *np, struct scsi_cmnd *ccb, int cam_status) +static void sym_xpt_done2(struct sym_hcb *np, struct scsi_cmnd *ccb, int cam_status) { sym_set_cam_status(ccb, cam_status); sym_xpt_done(np, ccb); @@ -323,7 +388,7 @@ void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid) /* * Bounce back the sense data to user. */ - bzero(&csio->sense_buffer, sizeof(csio->sense_buffer)); + memset(&csio->sense_buffer, 0, sizeof(csio->sense_buffer)); memcpy(csio->sense_buffer, cp->sns_bbuf, min(sizeof(csio->sense_buffer), (size_t)SYM_SNS_BBUF_LEN)); @@ -457,7 +522,7 @@ static int sym_queue_command(struct sym_hcb *np, struct scsi_cmnd *ccb) } /* - * Retreive the target descriptor. + * Retrieve the target descriptor. */ tp = &np->target[ccb->device->id]; @@ -573,7 +638,6 @@ int sym_setup_data_and_start(struct sym_hcb *np, struct scsi_cmnd *csio, struct switch (cp->cdb_buf[0]) { case 0x0A: case 0x2A: case 0xAA: panic("XXXXXXXXXXXXX WRITE NOT YET ALLOWED XXXXXXXXXXXXXX\n"); - MDELAY(10000); break; default: break; @@ -661,31 +725,6 @@ void sym_log_bus_error(struct sym_hcb *np) } } - -/* - * Requeue awaiting commands. - */ -static void sym_requeue_awaiting_cmds(struct sym_hcb *np) -{ - struct sym_ucmd *ucp; - SYM_QUEHEAD tmp_cmdq; - int sts; - - sym_que_move(&np->s.wait_cmdq, &tmp_cmdq); - - while ((ucp = (struct sym_ucmd *) sym_remque_head(&tmp_cmdq)) != 0) { - struct scsi_cmnd *cmd; - - sym_insque_tail(&ucp->link_cmdq, &np->s.busy_cmdq); - cmd = SYM_SCMD_PTR(ucp); - sts = sym_queue_command(np, cmd); - if (sts) { - sym_remque(&ucp->link_cmdq); - sym_insque_head(&ucp->link_cmdq, &np->s.wait_cmdq); - } - } -} - /* * queuecommand method. Entered with the host adapter lock held and * interrupts disabled. @@ -713,18 +752,12 @@ static int sym53c8xx_queue_command(struct scsi_cmnd *cmd, } } - if (np->s.settle_time_valid || !sym_que_empty(&np->s.wait_cmdq)) { - sym_insque_tail(&ucp->link_cmdq, &np->s.wait_cmdq); - goto out; - } + if (np->s.settle_time_valid) + return SCSI_MLQUEUE_HOST_BUSY; - sym_insque_tail(&ucp->link_cmdq, &np->s.busy_cmdq); sts = sym_queue_command(np, cmd); - if (sts) { - sym_remque(&ucp->link_cmdq); - sym_insque_tail(&ucp->link_cmdq, &np->s.wait_cmdq); - } -out: + if (sts) + return SCSI_MLQUEUE_HOST_BUSY; return 0; } @@ -739,15 +772,7 @@ static irqreturn_t sym53c8xx_intr(int irq, void *dev_id, struct pt_regs * regs) if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("["); spin_lock_irqsave(np->s.host->host_lock, flags); - sym_interrupt(np); - - /* - * push queue walk-through to tasklet - */ - if (!sym_que_empty(&np->s.wait_cmdq) && !np->s.settle_time_valid) - sym_requeue_awaiting_cmds(np); - spin_unlock_irqrestore(np->s.host->host_lock, flags); if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("]\n"); @@ -764,12 +789,7 @@ static void sym53c8xx_timer(unsigned long npref) unsigned long flags; spin_lock_irqsave(np->s.host->host_lock, flags); - sym_timer(np); - - if (!sym_que_empty(&np->s.wait_cmdq) && !np->s.settle_time_valid) - sym_requeue_awaiting_cmds(np); - spin_unlock_irqrestore(np->s.host->host_lock, flags); } @@ -811,7 +831,7 @@ static void __sym_eh_done(struct scsi_cmnd *cmd, int timed_out) /* Wake up the eh thread if it wants to sleep */ if (ep->to_do == SYM_EH_DO_WAIT) - up(&ep->sem); + complete(&ep->done); } /* @@ -847,14 +867,6 @@ static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd) goto prepare; #endif - /* This one is not queued to the core driver -> to complete here */ - FOR_EACH_QUEUED_ELEMENT(&np->s.wait_cmdq, qp) { - if (SYM_SCMD_PTR(qp) == cmd) { - to_do = SYM_EH_DO_COMPLETE; - goto prepare; - } - } - /* This one is queued in some place -> to wait for completion */ FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) { struct sym_ccb *cp = sym_que_entry(qp, struct sym_ccb, link_ccbq); @@ -871,7 +883,7 @@ prepare: case SYM_EH_DO_IGNORE: break; case SYM_EH_DO_WAIT: - init_MUTEX_LOCKED(&ep->sem); + init_completion(&ep->done); /* fall through */ case SYM_EH_DO_COMPLETE: ep->old_done = cmd->scsi_done; @@ -922,7 +934,7 @@ prepare: ep->timed_out = 1; /* Be pessimistic for once :) */ add_timer(&ep->timer); spin_unlock_irq(np->s.host->host_lock); - down(&ep->sem); + wait_for_completion(&ep->done); spin_lock_irq(np->s.host->host_lock); if (ep->timed_out) sts = -2; @@ -986,7 +998,6 @@ static void sym_tune_dev_queuing(struct sym_hcb *np, int target, int lun, u_shor } } -#ifdef SYM_LINUX_BOOT_COMMAND_LINE_SUPPORT /* * Linux select queue depths function */ @@ -1039,9 +1050,6 @@ static int device_queue_depth(struct sym_hcb *np, int target, int lun) } return DEF_DEPTH; } -#else -#define device_queue_depth(np, t, l) (sym_driver_setup.max_tag) -#endif /* SYM_LINUX_BOOT_COMMAND_LINE_SUPPORT */ /* * Linux entry point for device queue sizing. @@ -1096,7 +1104,8 @@ static int sym53c8xx_slave_configure(struct scsi_device *device) lp->s.scdev_depth = depth_to_use; sym_tune_dev_queuing(np, device->id, device->lun, reqtags); - spi_dv_device(device); + if (!spi_initial_dv(device->sdev_target)) + spi_dv_device(device); return 0; } @@ -1176,7 +1185,7 @@ static void sym_exec_user_command (struct sym_hcb *np, struct sym_usrcmd *uc) if (uc->data <= 9 && np->minsync_dt) { if (uc->data < np->minsync_dt) uc->data = np->minsync_dt; - tp->tinfo.goal.options = PPR_OPT_DT; + tp->tinfo.goal.options = PPR_OPT_MASK; tp->tinfo.goal.width = 1; tp->tinfo.goal.period = uc->data; tp->tinfo.goal.offset = np->maxoffs_dt; @@ -1277,7 +1286,7 @@ static int sym_user_command(struct sym_hcb *np, char *buffer, int length) int arg_len; u_long target; - bzero(uc, sizeof(*uc)); + memset(uc, 0, sizeof(*uc)); if (len > 0 && ptr[len-1] == '\n') --len; @@ -1467,18 +1476,8 @@ static int sym_host_info(struct sym_hcb *np, char *ptr, off_t offset, int len) copy_info(&info, "Chip " NAME53C "%s, device id 0x%x, " "revision id 0x%x\n", np->s.chip_name, np->device_id, np->revision_id); - copy_info(&info, "At PCI address %s, " -#ifdef __sparc__ - "IRQ %s\n", -#else - "IRQ %d\n", -#endif - pci_name(np->s.device), -#ifdef __sparc__ - __irq_itoa(np->s.irq)); -#else - (int) np->s.irq); -#endif + copy_info(&info, "At PCI address %s, IRQ " IRQ_FMT "\n", + pci_name(np->s.device), IRQ_PRM(np->s.irq)); copy_info(&info, "Min. period factor %d, %s SCSI BUS%s\n", (int) (np->minsync_dt ? np->minsync_dt : np->minsync), np->maxwide ? "Wide" : "Narrow", @@ -1558,32 +1557,23 @@ static void sym_free_resources(struct sym_hcb *np) */ static int sym_setup_bus_dma_mask(struct sym_hcb *np) { -#if SYM_CONF_DMA_ADDRESSING_MODE == 0 - if (pci_set_dma_mask(np->s.device, 0xffffffffUL)) - goto out_err32; -#else +#if SYM_CONF_DMA_ADDRESSING_MODE > 0 #if SYM_CONF_DMA_ADDRESSING_MODE == 1 -#define PciDmaMask 0xffffffffffULL +#define DMA_DAC_MASK 0x000000ffffffffffULL /* 40-bit */ #elif SYM_CONF_DMA_ADDRESSING_MODE == 2 -#define PciDmaMask 0xffffffffffffffffULL +#define DMA_DAC_MASK DMA_64BIT_MASK #endif - if (np->features & FE_DAC) { - if (!pci_set_dma_mask(np->s.device, PciDmaMask)) { - np->use_dac = 1; - printf_info("%s: using 64 bit DMA addressing\n", - sym_name(np)); - } else { - if (pci_set_dma_mask(np->s.device, 0xffffffffUL)) - goto out_err32; - } + if ((np->features & FE_DAC) && + !pci_set_dma_mask(np->s.device, DMA_DAC_MASK)) { + np->use_dac = 1; + return 0; } -#undef PciDmaMask #endif - return 0; -out_err32: - printf_warning("%s: 32 BIT DMA ADDRESSING NOT SUPPORTED\n", - sym_name(np)); + if (!pci_set_dma_mask(np->s.device, DMA_32BIT_MASK)) + return 0; + + printf_warning("%s: No suitable DMA available\n", sym_name(np)); return -1; } @@ -1606,19 +1596,9 @@ static struct Scsi_Host * __devinit sym_attach(struct scsi_host_template *tpnt, struct sym_fw *fw; printk(KERN_INFO - "sym%d: <%s> rev 0x%x at pci %s " -#ifdef __sparc__ - "irq %s\n", -#else - "irq %d\n", -#endif + "sym%d: <%s> rev 0x%x at pci %s irq " IRQ_FMT "\n", unit, dev->chip.name, dev->chip.revision_id, - pci_name(dev->pdev), -#ifdef __sparc__ - __irq_itoa(dev->s.irq)); -#else - dev->s.irq); -#endif + pci_name(dev->pdev), IRQ_PRM(dev->s.irq)); /* * Get the firmware for this chip. @@ -1672,9 +1652,6 @@ static struct Scsi_Host * __devinit sym_attach(struct scsi_host_template *tpnt, strlcpy(np->s.chip_name, dev->chip.name, sizeof(np->s.chip_name)); sprintf(np->s.inst_name, "sym%d", np->s.unit); - /* - * Ask/tell the system about DMA addressing. - */ if (sym_setup_bus_dma_mask(np)) goto attach_failed; @@ -1743,12 +1720,6 @@ static struct Scsi_Host * __devinit sym_attach(struct scsi_host_template *tpnt, if (sym_reset_scsi_bus(np, 0)) goto reset_failed; - /* - * Initialize some queue headers. - */ - sym_que_init(&np->s.wait_cmdq); - sym_que_init(&np->s.busy_cmdq); - /* * Start the SCRIPTS. */ @@ -1840,178 +1811,14 @@ static inline void sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp) } #endif /* SYM_CONF_NVRAM_SUPPORT */ -/* - * Driver setup from the boot command line - */ -#ifdef SYM_LINUX_BOOT_COMMAND_LINE_SUPPORT - -static struct sym_driver_setup - sym_driver_safe_setup __initdata = SYM_LINUX_DRIVER_SAFE_SETUP; -#ifdef MODULE -char *sym53c8xx; /* command line passed by insmod */ -MODULE_PARM(sym53c8xx, "s"); -#endif - -#define OPT_MAX_TAG 1 -#define OPT_BURST_ORDER 2 -#define OPT_SCSI_LED 3 -#define OPT_SCSI_DIFF 4 -#define OPT_IRQ_MODE 5 -#define OPT_SCSI_BUS_CHECK 6 -#define OPT_HOST_ID 7 -#define OPT_REVERSE_PROBE 8 -#define OPT_VERBOSE 9 -#define OPT_DEBUG 10 -#define OPT_SETTLE_DELAY 11 -#define OPT_USE_NVRAM 12 -#define OPT_EXCLUDE 13 -#define OPT_SAFE_SETUP 14 - -static char setup_token[] __initdata = - "tags:" "burst:" - "led:" "diff:" - "irqm:" "buschk:" - "hostid:" "revprob:" - "verb:" "debug:" - "settle:" "nvram:" - "excl:" "safe:" - ; - -#ifdef MODULE -#define ARG_SEP ' ' -#else -#define ARG_SEP ',' -#endif - -static int __init get_setup_token(char *p) -{ - char *cur = setup_token; - char *pc; - int i = 0; - - while (cur != NULL && (pc = strchr(cur, ':')) != NULL) { - ++pc; - ++i; - if (!strncmp(p, cur, pc - cur)) - return i; - cur = pc; - } - return 0; -} -#endif /* SYM_LINUX_BOOT_COMMAND_LINE_SUPPORT */ - -int __init sym53c8xx_setup(char *str) -{ -#ifdef SYM_LINUX_BOOT_COMMAND_LINE_SUPPORT - char *cur = str; - char *pc, *pv; - unsigned long val; - unsigned int i, c; - int xi = 0; - - while (cur != NULL && (pc = strchr(cur, ':')) != NULL) { - char *pe; - - val = 0; - pv = pc; - c = *++pv; - - if (c == 'n') - val = 0; - else if (c == 'y') - val = 1; - else - val = (int) simple_strtoul(pv, &pe, 0); - - switch (get_setup_token(cur)) { - case OPT_MAX_TAG: - sym_driver_setup.max_tag = val; - if (!(pe && *pe == '/')) - break; - i = 0; - while (*pe && *pe != ARG_SEP && - i < sizeof(sym_driver_setup.tag_ctrl)-1) { - sym_driver_setup.tag_ctrl[i++] = *pe++; - } - sym_driver_setup.tag_ctrl[i] = '\0'; - break; - case OPT_SAFE_SETUP: - memcpy(&sym_driver_setup, &sym_driver_safe_setup, - sizeof(sym_driver_setup)); - break; - case OPT_EXCLUDE: - if (xi < 8) - sym_driver_setup.excludes[xi++] = val; - break; - -#define __SIMPLE_OPTION(NAME, name) \ - case OPT_ ## NAME : \ - sym_driver_setup.name = val;\ - break; - - __SIMPLE_OPTION(BURST_ORDER, burst_order) - __SIMPLE_OPTION(SCSI_LED, scsi_led) - __SIMPLE_OPTION(SCSI_DIFF, scsi_diff) - __SIMPLE_OPTION(IRQ_MODE, irq_mode) - __SIMPLE_OPTION(SCSI_BUS_CHECK, scsi_bus_check) - __SIMPLE_OPTION(HOST_ID, host_id) - __SIMPLE_OPTION(REVERSE_PROBE, reverse_probe) - __SIMPLE_OPTION(VERBOSE, verbose) - __SIMPLE_OPTION(DEBUG, debug) - __SIMPLE_OPTION(SETTLE_DELAY, settle_delay) - __SIMPLE_OPTION(USE_NVRAM, use_nvram) - -#undef __SIMPLE_OPTION - - default: - printk("sym53c8xx_setup: unexpected boot option '%.*s' ignored\n", (int)(pc-cur+1), cur); - break; - } - - if ((cur = strchr(cur, ARG_SEP)) != NULL) - ++cur; - } -#endif /* SYM_LINUX_BOOT_COMMAND_LINE_SUPPORT */ - return 1; -} - -#ifndef MODULE -__setup("sym53c8xx=", sym53c8xx_setup); -#endif - -/* - * Read and check the PCI configuration for any detected NCR - * boards and save data for attaching after all boards have - * been detected. - */ -static int __devinit -sym53c8xx_pci_init(struct pci_dev *pdev, struct sym_device *device) +static int __devinit sym_check_supported(struct sym_device *device) { struct sym_pci_chip *chip; - u_long base, base_2; - u_long base_c, base_2_c, io_port; - int i; - u_short device_id, status_reg; + struct pci_dev *pdev = device->pdev; u_char revision; - - /* Choose some short name for this device */ - sprintf(device->s.inst_name, "sym.%d.%d.%d", pdev->bus->number, - PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); - - device_id = pdev->device; - - io_port = pdev->resource[0].start; - - base_c = pdev->resource[1].start; - i = pci_get_base_address(pdev, 1, &base); - - base_2_c = pdev->resource[i].start; - pci_get_base_address(pdev, i, &base_2); - - base &= PCI_BASE_ADDRESS_MEM_MASK; - base_2 &= PCI_BASE_ADDRESS_MEM_MASK; - - pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision); + unsigned long io_port = device->s.io_port; + unsigned long base = device->s.base; + int i; /* * If user excluded this chip, do not initialize it. @@ -2019,19 +1826,10 @@ sym53c8xx_pci_init(struct pci_dev *pdev, struct sym_device *device) if (io_port) { for (i = 0 ; i < 8 ; i++) { if (sym_driver_setup.excludes[i] == io_port) - return -1; + return -ENODEV; } } - /* - * Check if the chip is supported. - */ - chip = sym_lookup_pci_chip_table(device_id, revision); - if (!chip) { - printf_info("%s: device not supported\n", sym_name(device)); - return -1; - } - /* * Check if the chip has been assigned resources we need. * XXX: can this still happen with Linux 2.6's PCI layer? @@ -2040,66 +1838,84 @@ sym53c8xx_pci_init(struct pci_dev *pdev, struct sym_device *device) if (!io_port) { printf_info("%s: IO base address disabled.\n", sym_name(device)); - return -1; + return -ENODEV; } #else if (!base) { printf_info("%s: MMIO base address disabled.\n", sym_name(device)); - return -1; + return -ENODEV; } #endif /* - * Ignore Symbios chips controlled by various RAID controllers. - * These controllers set value 0x52414944 at RAM end - 16. + * Check if the chip is supported. Then copy the chip description + * to our device structure so we can make it match the actual device + * and options. */ -#if defined(__i386__) - if (base_2_c) { - unsigned int ram_size, ram_val; - void *ram_ptr; - - if (chip->features & FE_RAM8K) - ram_size = 8192; - else - ram_size = 4096; - - ram_ptr = ioremap(base_2_c, ram_size); - if (ram_ptr) { - ram_val = readl_raw(ram_ptr + ram_size - 16); - iounmap(ram_ptr); - if (ram_val == 0x52414944) { - printf_info("%s: not initializing, " - "driven by RAID controller.\n", - sym_name(device)); - return -1; - } - } + pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision); + chip = sym_lookup_pci_chip_table(pdev->device, revision); + if (!chip) { + printf_info("%s: device not supported\n", sym_name(device)); + return -ENODEV; } -#endif /* i386 and PCI MEMORY accessible */ - - /* - * Copy the chip description to our device structure, - * so we can make it match the actual device and options. - */ memcpy(&device->chip, chip, sizeof(device->chip)); device->chip.revision_id = revision; + return 0; +} + +/* + * Ignore Symbios chips controlled by various RAID controllers. + * These controllers set value 0x52414944 at RAM end - 16. + */ +static int __devinit sym_check_raid(struct sym_device *device) +{ + unsigned long base_2_c = device->s.base_2_c; + unsigned int ram_size, ram_val; + void __iomem *ram_ptr; + + if (!base_2_c) + return 0; + + if (device->chip.features & FE_RAM8K) + ram_size = 8192; + else + ram_size = 4096; + + ram_ptr = ioremap(base_2_c, ram_size); + if (!ram_ptr) + return 0; + + ram_val = readl(ram_ptr + ram_size - 16); + iounmap(ram_ptr); + if (ram_val != 0x52414944) + return 0; + + printf_info("%s: not initializing, driven by RAID controller.\n", + sym_name(device)); + return -ENODEV; +} + +static int __devinit sym_set_workarounds(struct sym_device *device) +{ + struct sym_pci_chip *chip = &device->chip; + struct pci_dev *pdev = device->pdev; + u_short status_reg; + /* - * Some features are required to be enabled in order to - * work around some chip problems. :) ;) * (ITEM 12 of a DEL about the 896 I haven't yet). * We must ensure the chip will use WRITE AND INVALIDATE. * The revision number limit is for now arbitrary. */ - if (device_id == PCI_DEVICE_ID_NCR_53C896 && revision < 0x4) { + if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && chip->revision_id < 0x4) { chip->features |= (FE_WRIE | FE_CLSE); } /* If the chip can do Memory Write Invalidate, enable it */ if (chip->features & FE_WRIE) { if (pci_set_mwi(pdev)) - return -1; + return -ENODEV; } /* @@ -2125,20 +1941,39 @@ sym53c8xx_pci_init(struct pci_dev *pdev, struct sym_device *device) } } - /* - * Initialise device structure with items required by sym_attach. - */ - device->pdev = pdev; - device->s.base = base; - device->s.base_2 = base_2; - device->s.base_c = base_c; - device->s.base_2_c = base_2_c; - device->s.io_port = io_port; - device->s.irq = pdev->irq; - return 0; } +/* + * Read and check the PCI configuration for any detected NCR + * boards and save data for attaching after all boards have + * been detected. + */ +static void __devinit +sym_init_device(struct pci_dev *pdev, struct sym_device *device) +{ + unsigned long base, base_2; + int i; + + device->host_id = SYM_SETUP_HOST_ID; + device->pdev = pdev; + device->s.irq = pdev->irq; + + /* Choose some short name for this device */ + sprintf(device->s.inst_name, "sym.%d.%d.%d", pdev->bus->number, + PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); + + device->s.io_port = pdev->resource[0].start; + + device->s.base_c = pdev->resource[1].start; + i = pci_get_base_address(pdev, 1, &base); + device->s.base = base & PCI_BASE_ADDRESS_MEM_MASK; + + device->s.base_2_c = pdev->resource[i].start; + pci_get_base_address(pdev, i, &base_2); + device->s.base_2 = base_2 & PCI_BASE_ADDRESS_MEM_MASK; +} + /* * The NCR PQS and PDS cards are constructed as a DEC bridge * behind which sits a proprietary NCR memory controller and @@ -2152,12 +1987,12 @@ sym53c8xx_pci_init(struct pci_dev *pdev, struct sym_device *device) * the preset SCSI ID (which may be zero) must be read in from * a special configuration space register of the 875. */ -void sym_config_pqs(struct pci_dev *pdev, struct sym_device *sym_dev) +static void sym_config_pqs(struct pci_dev *pdev, struct sym_device *sym_dev) { int slot; + u8 tmp; for (slot = 0; slot < 256; slot++) { - u8 tmp; struct pci_dev *memc = pci_get_slot(pdev->bus, slot); if (!memc || memc->vendor != 0x101a || memc->device == 0x0009) { @@ -2165,28 +2000,26 @@ void sym_config_pqs(struct pci_dev *pdev, struct sym_device *sym_dev) continue; } - /* - * We set these bits in the memory controller once per 875. - * This isn't a problem in practice. - */ - /* bit 1: allow individual 875 configuration */ pci_read_config_byte(memc, 0x44, &tmp); - tmp |= 0x2; - pci_write_config_byte(memc, 0x44, tmp); + if ((tmp & 0x2) == 0) { + tmp |= 0x2; + pci_write_config_byte(memc, 0x44, tmp); + } /* bit 2: drive individual 875 interrupts to the bus */ pci_read_config_byte(memc, 0x45, &tmp); - tmp |= 0x4; - pci_write_config_byte(memc, 0x45, tmp); - - pci_read_config_byte(pdev, 0x84, &tmp); - sym_dev->host_id = tmp; + if ((tmp & 0x4) == 0) { + tmp |= 0x4; + pci_write_config_byte(memc, 0x45, tmp); + } pci_dev_put(memc); - break; } + + pci_read_config_byte(pdev, 0x84, &tmp); + sym_dev->host_id = tmp; } /* @@ -2215,9 +2048,6 @@ static int sym_detach(struct sym_hcb *np) return 1; } -MODULE_LICENSE("Dual BSD/GPL"); -MODULE_VERSION(SYM_VERSION); - /* * Driver host template. */ @@ -2252,15 +2082,21 @@ static int __devinit sym2_probe(struct pci_dev *pdev, memset(&nvram, 0, sizeof(nvram)); if (pci_enable_device(pdev)) - return -ENODEV; + goto leave; pci_set_master(pdev); if (pci_request_regions(pdev, NAME53C8XX)) goto disable; - sym_dev.host_id = SYM_SETUP_HOST_ID; - if (sym53c8xx_pci_init(pdev, &sym_dev)) + sym_init_device(pdev, &sym_dev); + if (sym_check_supported(&sym_dev)) + goto free; + + if (sym_check_raid(&sym_dev)) + goto leave; /* Don't disable the device */ + + if (sym_set_workarounds(&sym_dev)) goto free; sym_config_pqs(pdev, &sym_dev); @@ -2285,6 +2121,7 @@ static int __devinit sym2_probe(struct pci_dev *pdev, pci_release_regions(pdev); disable: pci_disable_device(pdev); + leave: return -ENODEV; } @@ -2304,35 +2141,61 @@ static void __devexit sym2_remove(struct pci_dev *pdev) attach_count--; } -static void sym2_get_offset(struct scsi_device *sdev) +static void sym2_get_signalling(struct Scsi_Host *shost) { - struct sym_hcb *np = ((struct host_data *)sdev->host->hostdata)->ncb; - struct sym_tcb *tp = &np->target[sdev->id]; + struct sym_hcb *np = ((struct host_data *)shost->hostdata)->ncb; + enum spi_signal_type type; - spi_offset(sdev) = tp->tinfo.curr.offset; + switch (np->scsi_mode) { + case SMODE_SE: + type = SPI_SIGNAL_SE; + break; + case SMODE_LVD: + type = SPI_SIGNAL_LVD; + break; + case SMODE_HVD: + type = SPI_SIGNAL_HVD; + break; + default: + type = SPI_SIGNAL_UNKNOWN; + break; + } + spi_signalling(shost) = type; +} + +static void sym2_get_offset(struct scsi_target *starget) +{ + struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); + struct sym_hcb *np = ((struct host_data *)shost->hostdata)->ncb; + struct sym_tcb *tp = &np->target[starget->id]; + + spi_offset(starget) = tp->tinfo.curr.offset; } -static void sym2_set_offset(struct scsi_device *sdev, int offset) +static void sym2_set_offset(struct scsi_target *starget, int offset) { - struct sym_hcb *np = ((struct host_data *)sdev->host->hostdata)->ncb; - struct sym_tcb *tp = &np->target[sdev->id]; + struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); + struct sym_hcb *np = ((struct host_data *)shost->hostdata)->ncb; + struct sym_tcb *tp = &np->target[starget->id]; tp->tinfo.goal.offset = offset; } -static void sym2_get_period(struct scsi_device *sdev) +static void sym2_get_period(struct scsi_target *starget) { - struct sym_hcb *np = ((struct host_data *)sdev->host->hostdata)->ncb; - struct sym_tcb *tp = &np->target[sdev->id]; + struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); + struct sym_hcb *np = ((struct host_data *)shost->hostdata)->ncb; + struct sym_tcb *tp = &np->target[starget->id]; - spi_period(sdev) = tp->tinfo.curr.period; + spi_period(starget) = tp->tinfo.curr.period; } -static void sym2_set_period(struct scsi_device *sdev, int period) +static void sym2_set_period(struct scsi_target *starget, int period) { - struct sym_hcb *np = ((struct host_data *)sdev->host->hostdata)->ncb; - struct sym_tcb *tp = &np->target[sdev->id]; + struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); + struct sym_hcb *np = ((struct host_data *)shost->hostdata)->ncb; + struct sym_tcb *tp = &np->target[starget->id]; /* have to have DT for these transfers */ if (period <= np->minsync) @@ -2341,45 +2204,93 @@ static void sym2_set_period(struct scsi_device *sdev, int period) tp->tinfo.goal.period = period; } -static void sym2_get_width(struct scsi_device *sdev) +static void sym2_get_width(struct scsi_target *starget) { - struct sym_hcb *np = ((struct host_data *)sdev->host->hostdata)->ncb; - struct sym_tcb *tp = &np->target[sdev->id]; + struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); + struct sym_hcb *np = ((struct host_data *)shost->hostdata)->ncb; + struct sym_tcb *tp = &np->target[starget->id]; - spi_width(sdev) = tp->tinfo.curr.width ? 1 : 0; + spi_width(starget) = tp->tinfo.curr.width ? 1 : 0; } -static void sym2_set_width(struct scsi_device *sdev, int width) +static void sym2_set_width(struct scsi_target *starget, int width) { - struct sym_hcb *np = ((struct host_data *)sdev->host->hostdata)->ncb; - struct sym_tcb *tp = &np->target[sdev->id]; + struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); + struct sym_hcb *np = ((struct host_data *)shost->hostdata)->ncb; + struct sym_tcb *tp = &np->target[starget->id]; - /* It is illegal to have DT set on narrow transfers */ + /* It is illegal to have DT set on narrow transfers. If DT is + * clear, we must also clear IU and QAS. */ if (width == 0) - tp->tinfo.goal.options &= ~PPR_OPT_DT; + tp->tinfo.goal.options &= ~PPR_OPT_MASK; tp->tinfo.goal.width = width; } -static void sym2_get_dt(struct scsi_device *sdev) +static void sym2_get_dt(struct scsi_target *starget) { - struct sym_hcb *np = ((struct host_data *)sdev->host->hostdata)->ncb; - struct sym_tcb *tp = &np->target[sdev->id]; + struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); + struct sym_hcb *np = ((struct host_data *)shost->hostdata)->ncb; + struct sym_tcb *tp = &np->target[starget->id]; - spi_dt(sdev) = (tp->tinfo.curr.options & PPR_OPT_DT) ? 1 : 0; + spi_dt(starget) = (tp->tinfo.curr.options & PPR_OPT_DT) ? 1 : 0; } -static void sym2_set_dt(struct scsi_device *sdev, int dt) +static void sym2_set_dt(struct scsi_target *starget, int dt) { - struct sym_hcb *np = ((struct host_data *)sdev->host->hostdata)->ncb; - struct sym_tcb *tp = &np->target[sdev->id]; + struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); + struct sym_hcb *np = ((struct host_data *)shost->hostdata)->ncb; + struct sym_tcb *tp = &np->target[starget->id]; + /* We must clear QAS and IU if DT is clear */ if (dt) tp->tinfo.goal.options |= PPR_OPT_DT; else - tp->tinfo.goal.options &= ~PPR_OPT_DT; + tp->tinfo.goal.options &= ~PPR_OPT_MASK; } - + +static void sym2_get_iu(struct scsi_target *starget) +{ + struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); + struct sym_hcb *np = ((struct host_data *)shost->hostdata)->ncb; + struct sym_tcb *tp = &np->target[starget->id]; + + spi_iu(starget) = (tp->tinfo.curr.options & PPR_OPT_IU) ? 1 : 0; +} + +static void sym2_set_iu(struct scsi_target *starget, int iu) +{ + struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); + struct sym_hcb *np = ((struct host_data *)shost->hostdata)->ncb; + struct sym_tcb *tp = &np->target[starget->id]; + + if (iu) + tp->tinfo.goal.options |= PPR_OPT_IU | PPR_OPT_DT; + else + tp->tinfo.goal.options &= ~PPR_OPT_IU; +} + +static void sym2_get_qas(struct scsi_target *starget) +{ + struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); + struct sym_hcb *np = ((struct host_data *)shost->hostdata)->ncb; + struct sym_tcb *tp = &np->target[starget->id]; + + spi_qas(starget) = (tp->tinfo.curr.options & PPR_OPT_QAS) ? 1 : 0; +} + +static void sym2_set_qas(struct scsi_target *starget, int qas) +{ + struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); + struct sym_hcb *np = ((struct host_data *)shost->hostdata)->ncb; + struct sym_tcb *tp = &np->target[starget->id]; + + if (qas) + tp->tinfo.goal.options |= PPR_OPT_QAS | PPR_OPT_DT; + else + tp->tinfo.goal.options &= ~PPR_OPT_QAS; +} + static struct spi_function_template sym2_transport_functions = { .set_offset = sym2_set_offset, @@ -2394,6 +2305,13 @@ static struct spi_function_template sym2_transport_functions = { .get_dt = sym2_get_dt, .set_dt = sym2_set_dt, .show_dt = 1, + .get_iu = sym2_get_iu, + .set_iu = sym2_set_iu, + .show_iu = 1, + .get_qas = sym2_get_qas, + .set_qas = sym2_set_qas, + .show_qas = 1, + .get_signalling = sym2_get_signalling, }; static struct pci_device_id sym2_id_table[] __devinitdata = { @@ -2445,12 +2363,17 @@ static struct pci_driver sym2_driver = { static int __init sym2_init(void) { + int error; + + sym2_setup_params(); sym2_transport_template = spi_attach_transport(&sym2_transport_functions); if (!sym2_transport_template) return -ENODEV; - pci_register_driver(&sym2_driver); - return 0; + error = pci_module_init(&sym2_driver); + if (error) + spi_release_transport(sym2_transport_template); + return error; } static void __exit sym2_exit(void)