a100u2w.c

来自「linux 内核源代码」· C语言 代码 · 共 1,238 行 · 第 1/3 页

C
1,238
字号
/* * 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@redhat.com> *	 - 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/slab.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;}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;}/***************************************************************************/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;}/***************************************************************************/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;}/***************************************************************************/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;}/***************************************************************************/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;}/***************************************************************************/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;}/***************************************************************************/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;}/** *	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);}/** *	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;}/** *	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);	}}/** *	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                   */	}}/** *	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 = 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(data32, host->base + ORC_FWBASEADR);		/* Write FW address */	/* Copy the code from the BIOS to the SRAM */	bios_addr = (u16) 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(data32, host->base + ORC_RISCRAM);	/* Write every 4 bytes */			data32_ptr = (u8 *) & data32;		}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?