⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eesox.c

📁 linux-2.4.29操作系统的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  linux/drivers/acorn/scsi/eesox.c * *  Copyright (C) 1997-2003 Russell King * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * *  This driver is based on experimentation.  Hence, it may have made *  assumptions about the particular card that I have available, and *  may not be reliable! * *  Changelog: *   01-10-1997	RMK		Created, READONLY version *   15-02-1998	RMK		READ/WRITE version *				added DMA support and hardware definitions *   14-03-1998	RMK		Updated DMA support *				Added terminator control *   15-04-1998	RMK		Only do PIO if FAS216 will allow it. *   27-06-1998	RMK		Changed asm/delay.h to linux/delay.h *   02-04-2000	RMK	0.0.3	Fixed NO_IRQ/NO_DMA problem, updated for new *				error handling code. */#include <linux/module.h>#include <linux/blk.h>#include <linux/kernel.h>#include <linux/string.h>#include <linux/ioport.h>#include <linux/sched.h>#include <linux/proc_fs.h>#include <linux/delay.h>#include <linux/pci.h>#include <linux/init.h>#include <asm/io.h>#include <asm/irq.h>#include <asm/dma.h>#include <asm/ecard.h>#include <asm/pgtable.h>#include "../../scsi/sd.h"#include "../../scsi/hosts.h"#include "fas216.h"#include "scsi.h"#include <scsi/scsicam.h>/* * List of devices that the driver will recognise */#define EESOXSCSI_LIST	{ MANU_EESOX, PROD_EESOX_SCSI2 }#define EESOX_FAS216_OFFSET	0xc00#define EESOX_FAS216_SHIFT	3#define EESOX_DMASTAT		0xa00#define EESOX_STAT_INTR		0x01#define EESOX_STAT_DMA		0x02#define EESOX_CONTROL		0xa00#define EESOX_INTR_ENABLE	0x04#define EESOX_TERM_ENABLE	0x02#define EESOX_RESET		0x01#define EESOX_DMADATA		0xe00/* * Version */#define VERSION "1.10 (22/01/2003 2.4.19-rmk5)"/* * Use term=0,1,0,0,0 to turn terminators on/off */static int term[MAX_ECARDS] = { 1, 1, 1, 1, 1, 1, 1, 1 };#define NR_SG	256struct eesoxscsi_info {	FAS216_Info		info;	struct expansion_card	*ec;	unsigned int		ctl_port;	unsigned int		control;	struct scatterlist	sg[NR_SG];	/* Scatter DMA list	*/};/* Prototype: void eesoxscsi_irqenable(ec, irqnr) * Purpose  : Enable interrupts on EESOX SCSI card * Params   : ec    - expansion card structure *          : irqnr - interrupt number */static voideesoxscsi_irqenable(struct expansion_card *ec, int irqnr){	struct eesoxscsi_info *info = (struct eesoxscsi_info *)ec->irq_data;	info->control |= EESOX_INTR_ENABLE;	outb(info->control, info->ctl_port);}/* Prototype: void eesoxscsi_irqdisable(ec, irqnr) * Purpose  : Disable interrupts on EESOX SCSI card * Params   : ec    - expansion card structure *          : irqnr - interrupt number */static voideesoxscsi_irqdisable(struct expansion_card *ec, int irqnr){	struct eesoxscsi_info *info = (struct eesoxscsi_info *)ec->irq_data;	info->control &= ~EESOX_INTR_ENABLE;	outb(info->control, info->ctl_port);}static const expansioncard_ops_t eesoxscsi_ops = {	.irqenable	= eesoxscsi_irqenable,	.irqdisable	= eesoxscsi_irqdisable,};/* Prototype: void eesoxscsi_terminator_ctl(*host, on_off) * Purpose  : Turn the EESOX SCSI terminators on or off * Params   : host   - card to turn on/off *          : on_off - !0 to turn on, 0 to turn off */static voideesoxscsi_terminator_ctl(struct Scsi_Host *host, int on_off){	struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;	unsigned long flags;	save_flags_cli(flags);	if (on_off)		info->control |= EESOX_TERM_ENABLE;	else		info->control &= ~EESOX_TERM_ENABLE;	outb(info->control, info->ctl_port);	restore_flags(flags);}/* Prototype: void eesoxscsi_intr(irq, *dev_id, *regs) * Purpose  : handle interrupts from EESOX SCSI card * Params   : irq    - interrupt number *	      dev_id - user-defined (Scsi_Host structure) *	      regs   - processor registers at interrupt */static voideesoxscsi_intr(int irq, void *dev_id, struct pt_regs *regs){	fas216_intr(dev_id);}/* Prototype: fasdmatype_t eesoxscsi_dma_setup(host, SCpnt, direction, min_type) * Purpose  : initialises DMA/PIO * Params   : host      - host *	      SCpnt     - command *	      direction - DMA on to/off of card *	      min_type  - minimum DMA support that we must have for this transfer * Returns  : type of transfer to be performed */static fasdmatype_teesoxscsi_dma_setup(struct Scsi_Host *host, Scsi_Pointer *SCp,		       fasdmadir_t direction, fasdmatype_t min_type){	struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;	int dmach = host->dma_channel;	if (dmach != NO_DMA &&	    (min_type == fasdma_real_all || SCp->this_residual >= 512)) {		int bufs, map_dir, dma_dir;		bufs = copy_SCp_to_sg(&info->sg[0], SCp, NR_SG);		if (direction == DMA_OUT)			map_dir = PCI_DMA_TODEVICE,			dma_dir = DMA_MODE_WRITE;		else			map_dir = PCI_DMA_FROMDEVICE,			dma_dir = DMA_MODE_READ;		pci_map_sg(NULL, info->sg, bufs, map_dir);		disable_dma(dmach);		set_dma_sg(dmach, info->sg, bufs);		set_dma_mode(dmach, dma_dir);		enable_dma(dmach);		return fasdma_real_all;	}	/*	 * We don't do DMA, we only do slow PIO	 *	 * Some day, we will do Pseudo DMA	 */	return fasdma_pseudo;}static void eesoxscsi_buffer_in(void *buf, int length, unsigned long base){	const unsigned long reg_fas = base + EESOX_FAS216_OFFSET;	const unsigned long reg_dmastat = base + EESOX_DMASTAT;	const unsigned long reg_dmadata = base + EESOX_DMADATA;	do {		unsigned int status;		/*		 * Interrupt request?		 */		status = inb(reg_fas + (REG_STAT << EESOX_FAS216_SHIFT));		if (status & STAT_INT)			break;		/*		 * DMA request active?		 */		status = inb(reg_dmastat);		if (!(status & EESOX_STAT_DMA))			continue;		/*		 * Get number of bytes in FIFO		 */		status = inb(reg_fas + (REG_CFIS << EESOX_FAS216_SHIFT)) & CFIS_CF;		if (status > 16)			status = 16;		if (status > length)			status = length;		/*		 * Align buffer.		 */		if (((u32)buf) & 2 && status >= 2) {			*((u16 *)buf)++ = inw(reg_dmadata);			status -= 2;			length -= 2;		}		if (status >= 8) {			unsigned long l1, l2;			l1 = inw(reg_dmadata);			l1 |= inw(reg_dmadata) << 16;			l2 = inw(reg_dmadata);			l2 |= inw(reg_dmadata) << 16;			*((u32 *)buf)++ = l1;			*((u32 *)buf)++ = l2;			length -= 8;			continue;		}		if (status >= 4) {			unsigned long l1;			l1 = inw(reg_dmadata);			l1 |= inw(reg_dmadata) << 16;			*((u32 *)buf)++ = l1;			length -= 4;			continue;		}		if (status >= 2) {			*((u16 *)buf)++ = inw(reg_dmadata);			length -= 2;		}	} while (length);}static void eesoxscsi_buffer_out(void *buf, int length, unsigned long base){	const unsigned long reg_fas = base + EESOX_FAS216_OFFSET;	const unsigned long reg_dmastat = base + EESOX_DMASTAT;	const unsigned long reg_dmadata = base + EESOX_DMADATA;	do {		unsigned int status;		/*		 * Interrupt request?		 */		status = inb(reg_fas + (REG_STAT << EESOX_FAS216_SHIFT));		if (status & STAT_INT)			break;		/*		 * DMA request active?		 */		status = inb(reg_dmastat);		if (!(status & EESOX_STAT_DMA))			continue;		/*		 * Get number of bytes in FIFO		 */		status = inb(reg_fas + (REG_CFIS << EESOX_FAS216_SHIFT)) & CFIS_CF;		if (status > 16)			status = 16;		status = 16 - status;		if (status > length)			status = length;		/*		 * Align buffer.		 */		if (((u32)buf) & 2 && status >= 2) {			outw(*((u16 *)buf)++, reg_dmadata);			status -= 2;			length -= 2;		}		if (status >= 8) {			unsigned long l1, l2;			l1 = *((u32 *)buf)++;			l2 = *((u32 *)buf)++;			outw(l1, reg_dmadata);			outw(l1 >> 16, reg_dmadata);			outw(l2, reg_dmadata);			outw(l2 >> 16, reg_dmadata);			status -= 8;			length -= 8;			continue;		}		if (status >= 4) {			unsigned long l1;			l1 = *((u32 *)buf)++;			outw(l1, reg_dmadata);			outw(l1 >> 16, reg_dmadata);			status -= 4;			length -= 4;			continue;		}		if (status >= 2) {			outw(*((u16 *)buf)++, reg_dmadata);			length -= 2;		}	} while (length);}

⌨️ 快捷键说明

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