cregit-Linux how code gets into the kernel

Release 4.11 drivers/scsi/a100u2w.c

Directory: drivers/scsi
/*
 * Initio A100 device driver for Linux.
 *
 * Copyright (c) 1994-1998 Initio Corporation
 * Copyright (c) 2003-2004 Christoph Hellwig
 * All rights reserved.
 *
 * 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, 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 program; see the file COPYING.  If not, write to
 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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.
 */

/*
 * Revision History:
 * 07/02/98 hl  - v.91n Initial drivers.
 * 09/14/98 hl - v1.01 Support new Kernel.
 * 09/22/98 hl - v1.01a Support reset.
 * 09/24/98 hl - v1.01b Fixed reset.
 * 10/05/98 hl - v1.02 split the source code and release.
 * 12/19/98 bv - v1.02a Use spinlocks for 2.1.95 and up
 * 01/31/99 bv - v1.02b Use mdelay instead of waitForPause
 * 08/08/99 bv - v1.02c Use waitForPause again.
 * 06/25/02 Doug Ledford <dledford@redhat.com> - v1.02d
 *          - Remove limit on number of controllers
 *          - Port to DMA mapping API
 *          - Clean up interrupt handler registration
 *          - Fix memory leaks
 *          - Fix allocation of scsi host structs and private data
 * 11/18/03 Christoph Hellwig <hch@lst.de>
 *          - Port to new probing API
 *          - Fix some more leaks in init failure cases
 * 9/28/04 Christoph Hellwig <hch@lst.de>
 *          - merge the two source files
 *          - remove internal queueing code
 * 14/06/07 Alan Cox <alan@lxorguk.ukuu.org.uk>
 *       - Grand cleanup and Linuxisation
 */

#include <linux/module.h>
#include <linux/errno.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/pci.h>
#include <linux/init.h>
#include <linux/blkdev.h>
#include <linux/spinlock.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/ioport.h>
#include <linux/dma-mapping.h>

#include <asm/io.h>
#include <asm/irq.h>

#include <scsi/scsi.h>
#include <scsi/scsi_cmnd.h>
#include <scsi/scsi_device.h>
#include <scsi/scsi_host.h>

#include "a100u2w.h"


static struct orc_scb *__orc_alloc_scb(struct orc_host * host);
static void inia100_scb_handler(struct orc_host *host, struct orc_scb *scb);



static struct orc_nvram nvram, *nvramp = &nvram;


static u8 default_nvram[64] =
{
/*----------header -------------*/
	0x01,			/* 0x00: Sub System Vendor ID 0 */
	0x11,			/* 0x01: Sub System Vendor ID 1 */
	0x60,			/* 0x02: Sub System ID 0        */
	0x10,			/* 0x03: Sub System ID 1        */
	0x00,			/* 0x04: SubClass               */
	0x01,			/* 0x05: Vendor ID 0            */
	0x11,			/* 0x06: Vendor ID 1            */
	0x60,			/* 0x07: Device ID 0            */
	0x10,			/* 0x08: Device ID 1            */
	0x00,			/* 0x09: Reserved               */
	0x00,			/* 0x0A: Reserved               */
	0x01,			/* 0x0B: Revision of Data Structure     */
				/* -- Host Adapter Structure --- */
	0x01,			/* 0x0C: Number Of SCSI Channel */
	0x01,			/* 0x0D: BIOS Configuration 1   */
	0x00,			/* 0x0E: BIOS Configuration 2   */
	0x00,			/* 0x0F: BIOS Configuration 3   */
				/* --- SCSI Channel 0 Configuration --- */
	0x07,			/* 0x10: H/A ID                 */
	0x83,			/* 0x11: Channel Configuration  */
	0x20,			/* 0x12: MAX TAG per target     */
	0x0A,			/* 0x13: SCSI Reset Recovering time     */
	0x00,			/* 0x14: Channel Configuration4 */
	0x00,			/* 0x15: Channel Configuration5 */
				/* SCSI Channel 0 Target Configuration  */
				/* 0x16-0x25                    */
	0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8,
	0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8,
				/* --- SCSI Channel 1 Configuration --- */
	0x07,			/* 0x26: H/A ID                 */
	0x83,			/* 0x27: Channel Configuration  */
	0x20,			/* 0x28: MAX TAG per target     */
	0x0A,			/* 0x29: SCSI Reset Recovering time     */
	0x00,			/* 0x2A: Channel Configuration4 */
	0x00,			/* 0x2B: Channel Configuration5 */
				/* SCSI Channel 1 Target Configuration  */
				/* 0x2C-0x3B                    */
	0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8,
	0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8,
	0x00,			/* 0x3C: Reserved               */
	0x00,			/* 0x3D: Reserved               */
	0x00,			/* 0x3E: Reserved               */
	0x00			/* 0x3F: Checksum               */
};



static u8 wait_chip_ready(struct orc_host * host) { int i; for (i = 0; i < 10; i++) { /* Wait 1 second for report timeout */ if (inb(host->base + ORC_HCTRL) & HOSTSTOP) /* Wait HOSTSTOP set */ return 1; mdelay(100); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)4276.36%250.00%
Alan Cox1018.18%125.00%
Christoph Hellwig35.45%125.00%
Total55100.00%4100.00%


static u8 wait_firmware_ready(struct orc_host * host) { int i; for (i = 0; i < 10; i++) { /* Wait 1 second for report timeout */ if (inb(host->base + ORC_HSTUS) & RREADY) /* Wait READY set */ return 1; mdelay(100); /* wait 100ms before try again */ } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)4376.79%250.00%
Alan Cox1017.86%125.00%
Christoph Hellwig35.36%125.00%
Total56100.00%4100.00%

/***************************************************************************/
static u8 wait_scsi_reset_done(struct orc_host * host) { int i; for (i = 0; i < 10; i++) { /* Wait 1 second for report timeout */ if (!(inb(host->base + ORC_HCTRL) & SCSIRST)) /* Wait SCSIRST done */ return 1; mdelay(100); /* wait 100ms before try again */ } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)4677.97%250.00%
Alan Cox1016.95%125.00%
Christoph Hellwig35.08%125.00%
Total59100.00%4100.00%

/***************************************************************************/
static u8 wait_HDO_off(struct orc_host * host) { int i; for (i = 0; i < 10; i++) { /* Wait 1 second for report timeout */ if (!(inb(host->base + ORC_HCTRL) & HDO)) /* Wait HDO off */ return 1; mdelay(100); /* wait 100ms before try again */ } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)4677.97%250.00%
Alan Cox1016.95%125.00%
Christoph Hellwig35.08%125.00%
Total59100.00%4100.00%

/***************************************************************************/
static u8 wait_hdi_set(struct orc_host * host, u8 * data) { int i; for (i = 0; i < 10; i++) { /* Wait 1 second for report timeout */ if ((*data = inb(host->base + ORC_HSTUS)) & HDI) return 1; /* Wait HDI set */ mdelay(100); /* wait 100ms before try again */ } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)4975.38%250.00%
Alan Cox1320.00%125.00%
Christoph Hellwig34.62%125.00%
Total65100.00%4100.00%

/***************************************************************************/
static unsigned short orc_read_fwrev(struct orc_host * host) { u16 version; u8 data; outb(ORC_CMD_VERSION, host->base + ORC_HDATA); outb(HDO, host->base + ORC_HCTRL); if (wait_HDO_off(host) == 0) /* Wait HDO off */ return 0; if (wait_hdi_set(host, &data) == 0) /* Wait HDI set */ return 0; version = inb(host->base + ORC_HDATA); outb(data, host->base + ORC_HSTUS); /* Clear HDI */ if (wait_hdi_set(host, &data) == 0) /* Wait HDI set */ return 0; version |= inb(host->base + ORC_HDATA) << 8; outb(data, host->base + ORC_HSTUS); /* Clear HDI */ return version; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)7958.09%133.33%
Alan Cox5036.76%133.33%
Christoph Hellwig75.15%133.33%
Total136100.00%3100.00%

/***************************************************************************/
static u8 orc_nv_write(struct orc_host * host, unsigned char address, unsigned char value) { outb(ORC_CMD_SET_NVM, host->base + ORC_HDATA); /* Write command */ outb(HDO, host->base + ORC_HCTRL); if (wait_HDO_off(host) == 0) /* Wait HDO off */ return 0; outb(address, host->base + ORC_HDATA); /* Write address */ outb(HDO, host->base + ORC_HCTRL); if (wait_HDO_off(host) == 0) /* Wait HDO off */ return 0; outb(value, host->base + ORC_HDATA); /* Write value */ outb(HDO, host->base + ORC_HCTRL); if (wait_HDO_off(host) == 0) /* Wait HDO off */ return 0; return 1; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)8162.31%133.33%
Alan Cox4131.54%133.33%
Christoph Hellwig86.15%133.33%
Total130100.00%3100.00%

/***************************************************************************/
static u8 orc_nv_read(struct orc_host * host, u8 address, u8 *ptr) { unsigned char data; outb(ORC_CMD_GET_NVM, host->base + ORC_HDATA); /* Write command */ outb(HDO, host->base + ORC_HCTRL); if (wait_HDO_off(host) == 0) /* Wait HDO off */ return 0; outb(address, host->base + ORC_HDATA); /* Write address */ outb(HDO, host->base + ORC_HCTRL); if (wait_HDO_off(host) == 0) /* Wait HDO off */ return 0; if (wait_hdi_set(host, &data) == 0) /* Wait HDI set */ return 0; *ptr = inb(host->base + ORC_HDATA); outb(data, host->base + ORC_HSTUS); /* Clear HDI */ return 1; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)8360.58%133.33%
Alan Cox4633.58%133.33%
Christoph Hellwig85.84%133.33%
Total137100.00%3100.00%

/** * orc_exec_sb - Queue an SCB with the HA * @host: host adapter the SCB belongs to * @scb: SCB to queue for execution */
static void orc_exec_scb(struct orc_host * host, struct orc_scb * scb) { scb->status = ORCSCB_POST; outb(scb->scbidx, host->base + ORC_PQUEUE); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)1851.43%125.00%
Alan Cox1542.86%125.00%
Doug Ledford12.86%125.00%
Christoph Hellwig12.86%125.00%
Total35100.00%4100.00%

/** * se2_rd_all - read SCSI parameters from EEPROM * @host: Host whose EEPROM is being loaded * * Read SCSI H/A configuration parameters from serial EEPROM */
static int se2_rd_all(struct orc_host * host) { int i; u8 *np, chksum = 0; np = (u8 *) nvramp; for (i = 0; i < 64; i++, np++) { /* <01> */ if (orc_nv_read(host, (u8) i, np) == 0) return -1; } /*------ Is ckecksum ok ? ------*/ np = (u8 *) nvramp; for (i = 0; i < 63; i++) chksum += *np++; if (nvramp->CheckSum != (u8) chksum) return -1; return 1; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)10389.57%133.33%
Alan Cox108.70%133.33%
Christoph Hellwig21.74%133.33%
Total115100.00%3100.00%

/** * se2_update_all - update the EEPROM * @host: Host whose EEPROM is being updated * * Update changed bytes in the EEPROM image. */
static void se2_update_all(struct orc_host * host) { /* setup default pattern */ int i; u8 *np, *np1, chksum = 0; /* Calculate checksum first */ np = (u8 *) default_nvram; for (i = 0; i < 63; i++) chksum += *np++; *np = chksum; np = (u8 *) default_nvram; np1 = (u8 *) nvramp; for (i = 0; i < 64; i++, np++, np1++) { if (*np != *np1) orc_nv_write(host, (u8) i, *np); } }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)10488.89%133.33%
Alan Cox1210.26%133.33%
Christoph Hellwig10.85%133.33%
Total117100.00%3100.00%

/** * read_eeprom - load EEPROM * @host: Host EEPROM to read * * Read the EEPROM for a given host. If it is invalid or fails * the restore the defaults and use them. */
static void read_eeprom(struct orc_host * host) { if (se2_rd_all(host) != 1) { se2_update_all(host); /* setup default pattern */ se2_rd_all(host); /* load again */ } }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)2779.41%133.33%
Alan Cox617.65%133.33%
Christoph Hellwig12.94%133.33%
Total34100.00%3100.00%

/** * orc_load_firmware - initialise firmware * @host: Host to set up * * Load the firmware from the EEPROM into controller SRAM. This * is basically a 4K block copy and then a 4K block read to check * correctness. The rest is convulted by the indirect interfaces * in the hardware */
static u8 orc_load_firmware(struct orc_host * host) { u32 data32; u16 bios_addr; u16 i; u8 *data32_ptr, data; /* Set up the EEPROM for access */ data = inb(host->base + ORC_GCFG); outb(data | EEPRG, host->base + ORC_GCFG); /* Enable EEPROM programming */ outb(0x00, host->base + ORC_EBIOSADR2); outw(0x0000, host->base + ORC_EBIOSADR0); if (inb(host->base + ORC_EBIOSDATA) != 0x55) { outb(data, host->base + ORC_GCFG); /* Disable EEPROM programming */ return 0; } outw(0x0001, host->base + ORC_EBIOSADR0); if (inb(host->base + ORC_EBIOSDATA) != 0xAA) { outb(data, host->base + ORC_GCFG); /* Disable EEPROM programming */ return 0; } outb(PRGMRST | DOWNLOAD, host->base + ORC_RISCCTL); /* Enable SRAM programming */ data32_ptr = (u8 *) & data32; data32 = cpu_to_le32(0); /* Initial FW address to 0 */ outw(0x0010, host->base + ORC_EBIOSADR0); *data32_ptr = inb(host->base + ORC_EBIOSDATA); /* Read from BIOS */ outw(0x0011, host->base + ORC_EBIOSADR0); *(data32_ptr + 1) = inb(host->base + ORC_EBIOSDATA); /* Read from BIOS */ outw(0x0012, host->base + ORC_EBIOSADR0); *(data32_ptr + 2) = inb(host->base + ORC_EBIOSDATA); /* Read from BIOS */ outw(*(data32_ptr + 2), host->base + ORC_EBIOSADR2); outl(le32_to_cpu(data32), host->base + ORC_FWBASEADR); /* Write FW address */ /* Copy the code from the BIOS to the SRAM */ udelay(500); /* Required on Sun Ultra 5 ... 350 -> failures */ bios_addr = (u16) le32_to_cpu(data32); /* FW code locate at BIOS address + ? */ for (i = 0, data32_ptr = (u8 *) & data32; /* Download the code */ i < 0x1000; /* Firmware code size = 4K */ i++, bios_addr++) { outw(bios_addr, host->base + ORC_EBIOSADR0); *data32_ptr++ = inb(host->base + ORC_EBIOSDATA); /* Read from BIOS */ if ((i % 4) == 3) { outl(le32_to_cpu(data32), host->base + ORC_RISCRAM); /* Write every 4 bytes */ data32_ptr = (u8 *) & data32; } } /* Go back and check they match */ outb(PRGMRST | DOWNLOAD, host->base + ORC_RISCCTL); /* Reset program count 0 */ bios_addr -= 0x1000; /* Reset the BIOS address */ for (i = 0, data32_ptr = (u8 *) & data32; /* Check the code */ i < 0x1000; /* Firmware code size = 4K */ i++, bios_addr++) { outw(bios_addr, host->base + ORC_EBIOSADR0); *data32_ptr++ = inb(host->base + ORC_EBIOSDATA); /* Read from BIOS */ if ((i % 4) == 3) { if (inl(host->base + ORC_RISCRAM) != le32_to_cpu(data32)) { outb(PRGMRST, host->base + ORC_RISCCTL); /* Reset program to 0 */ outb(data, host->base + ORC_GCFG); /*Disable EEPROM programming */ return 0; } data32_ptr = (u8 *) & data32; } } /* Success */ outb(PRGMRST, host->base + ORC_RISCCTL); /* Reset program to 0 */ outb(data, host->base + ORC_GCFG); /* Disable EEPROM programming */ return 1; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)34461.10%116.67%
Alan Cox19234.10%116.67%
Mikulas Patocka213.73%233.33%
Christoph Hellwig50.89%116.67%
Uwe Kleine-König10.18%116.67%
Total563100.00%6100.00%

/***************************************************************************/
static void setup_SCBs(struct orc_host * host) { struct orc_scb *scb; int i; struct orc_extended_scb *escb; dma_addr_t escb_phys; /* Setup SCB base and SCB Size registers */ outb(ORC_MAXQUEUE, host->base + ORC_SCBSIZE); /* Total number of SCBs */ /* SCB base address 0 */ outl(host->scb_phys, host->base + ORC_SCBBASE0); /* SCB base address 1 */ outl(host->scb_phys, host->base + ORC_SCBBASE1); /* setup scatter list address with one buffer */ scb = host->scb_virt; escb = host->escb_virt; for (i = 0; i < ORC_MAXQUEUE; i++) { escb_phys = (host->escb_phys + (sizeof(struct orc_extended_scb) * i)); scb->sg_addr = cpu_to_le32((u32) escb_phys); scb->sense_addr = cpu_to_le32((u32) escb_phys); scb->escb = escb; scb->scbidx = i; scb++; escb++; } }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)8755.77%120.00%
Alan Cox5837.18%120.00%
Mikulas Patocka63.85%120.00%
Doug Ledford42.56%120.00%
Christoph Hellwig10.64%120.00%
Total156100.00%5100.00%

/** * init_alloc_map - initialise allocation map * @host: host map to configure * * Initialise the allocation maps for this device. If the device * is not quiescent the caller must hold the allocation lock */
static void init_alloc_map(struct orc_host * host) { u8 i, j; for (i = 0; i < MAX_CHANNELS; i++) { for (j = 0; j < 8; j++) { host->allocation_map[i][j] = 0xffffffff; } } }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)5187.93%150.00%
Alan Cox712.07%150.00%
Total58100.00%2100.00%

/** * init_orchid - initialise the host adapter * @host:host adapter to initialise * * Initialise the controller and if necessary load the firmware. * * Returns -1 if the initialisation fails. */
static int init_orchid(struct orc_host * host) { u8 *ptr; u16 revision; u8 i; init_alloc_map(host); outb(0xFF, host->base + ORC_GIMSK); /* Disable all interrupts */ if (inb(host->base + ORC_HSTUS) & RREADY) { /* Orchid is ready */ revision = orc_read_fwrev(host); if (revision == 0xFFFF) { outb(DEVRST, host->base + ORC_HCTRL); /* Reset Host Adapter */ if (wait_chip_ready(host) == 0) return -1; orc_load_firmware(host); /* Download FW */ setup_SCBs(host); /* Setup SCB base and SCB Size registers */ outb(0x00, host->base + ORC_HCTRL); /* clear HOSTSTOP */ if (wait_firmware_ready(host) == 0) return -1; /* Wait for firmware ready */ } else { setup_SCBs(host); /* Setup SCB base and SCB Size registers */ } } else { /* Orchid is not Ready */ outb(DEVRST, host->base + ORC_HCTRL); /* Reset Host Adapter */ if (wait_chip_ready(host) == 0) return -1; orc_load_firmware(host); /* Download FW */ setup_SCBs(host); /* Setup SCB base and SCB Size registers */ outb(HDO, host->base + ORC_HCTRL); /* Do Hardware Reset & */ /* clear HOSTSTOP */ if (wait_firmware_ready(host) == 0) /* Wait for firmware ready */ return -1; } /* Load an EEProm copy into RAM */ /* Assumes single threaded at this point */ read_eeprom(host); if (nvramp->revision != 1) return -1; host->scsi_id = nvramp->scsi_id; host->BIOScfg = nvramp->BIOSConfig1; host->max_targets = MAX_TARGETS; ptr = (u8 *) & (nvramp->Target00Config); for (i = 0; i < 16; ptr++, i++) { host->target_flag[i] = *ptr; host->max_tags[i] = ORC_MAXTAGS; } if (nvramp->SCSI0Config & NCC_BUSRESET) host->flags |= HCF_SCSI_RESET; outb(0xFB, host->base + ORC_GIMSK); /* enable RP FIFO interrupt */ return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)23772.04%125.00%
Alan Cox8626.14%125.00%
Christoph Hellwig51.52%125.00%
Doug Ledford10.30%125.00%
Total329100.00%4100.00%

/** * orc_reset_scsi_bus - perform bus reset * @host: host being reset * * Perform a full bus reset on the adapter. */
static int orc_reset_scsi_bus(struct orc_host * host) { /* I need Host Control Block Information */ unsigned long flags; spin_lock_irqsave(&host->allocation_lock, flags); init_alloc_map(host); /* reset scsi bus */ outb(SCSIRST, host->base + ORC_HCTRL); /* FIXME: We can spend up to a second with the lock held and interrupts off here */ if (wait_scsi_reset_done(host) == 0) { spin_unlock_irqrestore(&host->allocation_lock, flags); return FAILED; } else { spin_unlock_irqrestore(&host->allocation_lock, flags); return SUCCESS; } }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)5970.24%125.00%
Alan Cox2327.38%250.00%
Christoph Hellwig22.38%125.00%
Total84100.00%4100.00%

/** * orc_device_reset - device reset handler * @host: host to reset * @cmd: command causing the reset * @target; target device * * Reset registers, reset a hanging bus and kill active and disconnected * commands for target w/o soft reset */
static int orc_device_reset(struct orc_host * host, struct scsi_cmnd *cmd, unsigned int target) { /* I need Host Control Block Information */ struct orc_scb *scb; struct orc_extended_scb *escb; struct orc_scb *host_scb; u8 i; unsigned long flags; spin_lock_irqsave(&(host->allocation_lock), flags); scb = (struct orc_scb *) NULL; escb = (struct orc_extended_scb *) NULL; /* setup scatter list address with one buffer */ host_scb = host->scb_virt; /* FIXME: is this safe if we then fail to issue the reset or race a completion ? */ init_alloc_map(host); /* Find the scb corresponding to the command */ for (i = 0; i < ORC_MAXQUEUE; i++) { escb = host_scb->escb; if (host_scb->status && escb->srb == cmd) break; host_scb++; } if (i == ORC_MAXQUEUE) { printk(KERN_ERR "Unable to Reset - No SCB Found\n"); spin_unlock_irqrestore(&(host->allocation_lock), flags); return FAILED; } /* Allocate a new SCB for the reset command to the firmware */ if ((scb = __orc_alloc_scb(host)) == NULL) { /* Can't happen.. */ spin_unlock_irqrestore(&(host->allocation_lock), flags); return FAILED; } /* Reset device is handled by the firmware, we fill in an SCB and fire it at the controller, it does the rest */ scb->opcode = ORC_BUSDEVRST; scb->target = target; scb->hastat = 0; scb->tastat = 0; scb->status = 0x0; scb->link = 0xFF; scb->reserved0 = 0; scb->reserved1 = 0; scb->xferlen = cpu_to_le32(0); scb->sg_len = cpu_to_le32(0); escb->srb = NULL; escb->srb = cmd; orc_exec_scb(host, scb); /* Start execute SCB */ spin_unlock_irqrestore(&host->allocation_lock, flags); return SUCCESS; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)18966.32%112.50%
Alan Cox8228.77%225.00%
Mikulas Patocka62.11%112.50%
Christoph Hellwig31.05%112.50%
Doug Ledford31.05%112.50%
Nick Andrew10.35%112.50%
Al Viro10.35%112.50%
Total285100.00%8100.00%

/** * __orc_alloc_scb - allocate an SCB * @host: host to allocate from * * Allocate an SCB and return a pointer to the SCB object. NULL * is returned if no SCB is free. The caller must already hold * the allocator lock at this point. */
static struct orc_scb *__orc_alloc_scb(struct orc_host * host) { u8 channel; unsigned long idx; u8 index; u8 i; channel = host->index; for (i = 0; i < 8; i++) { for (index = 0; index < 32; index++) { if ((host->allocation_map[channel][i] >> index) & 0x01) { host->allocation_map[channel][i] &= ~(1 << index); idx = index + 32 * i; /* * Translate the index to a structure instance */ return host->scb_virt + idx; } } } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)8471.19%120.00%
Alan Cox2319.49%120.00%
Linus Torvalds75.93%120.00%
Akinobu Mita32.54%120.00%
Christoph Hellwig10.85%120.00%
Total118100.00%5100.00%

/** * orc_alloc_scb - allocate an SCB * @host: host to allocate from * * Allocate an SCB and return a pointer to the SCB object. NULL * is returned if no SCB is free. */
static struct orc_scb *orc_alloc_scb(struct orc_host * host) { struct orc_scb *scb; unsigned long flags; spin_lock_irqsave(&host->allocation_lock, flags); scb = __orc_alloc_scb(host); spin_unlock_irqrestore(&host->allocation_lock, flags); return scb; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)2242.31%125.00%
Alan Cox1732.69%125.00%
Linus Torvalds1223.08%125.00%
Christoph Hellwig11.92%125.00%
Total52100.00%4100.00%

/** * orc_release_scb - release an SCB * @host: host owning the SCB * @scb: SCB that is now free * * Called to return a completed SCB to the allocation pool. Before * calling the SCB must be out of use on both the host and the HA. */
static void orc_release_scb(struct orc_host *host, struct orc_scb *scb) { unsigned long flags; u8 index, i, channel; spin_lock_irqsave(&(host->allocation_lock), flags); channel = host->index; /* Channel */ index = scb->scbidx; i = index / 32; index %= 32; host->allocation_map[channel][i] |= (1 << index); spin_unlock_irqrestore(&(host->allocation_lock), flags); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)5965.56%133.33%
Alan Cox3033.33%133.33%
Christoph Hellwig11.11%133.33%
Total90100.00%3100.00%

/** * orchid_abort_scb - abort a command * * Abort a queued command that has been passed to the firmware layer * if possible. This is all handled by the firmware. We aks the firmware * and it either aborts the command or fails */
static int orchid_abort_scb(struct orc_host * host, struct orc_scb * scb) { unsigned char data, status; outb(ORC_CMD_ABORT_SCB, host->base + ORC_HDATA); /* Write command */ outb(HDO, host->base + ORC_HCTRL); if (wait_HDO_off(host) == 0) /* Wait HDO off */ return 0; outb(scb->scbidx, host->base + ORC_HDATA); /* Write address */ outb(HDO, host->base + ORC_HCTRL); if (wait_HDO_off(host) == 0) /* Wait HDO off */ return 0; if (wait_hdi_set(