📄 eesox.c
字号:
/* * linux/arch/arm/drivers/scsi/eesox.c * * Copyright (C) 1997-1998 Russell King * * 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. */#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/unistd.h>#include <linux/stat.h>#include <asm/delay.h>#include <asm/io.h>#include <asm/irq.h>#include <asm/dma.h>#include <asm/ecard.h>#include <asm/pgtable.h>#include "sd.h"#include "hosts.h"#include "eesox.h"#define NO_IRQ 255#define NO_DMA 255/* Configuration */#define EESOX_XTALFREQ 40#define EESOX_ASYNC_PERIOD 200#define EESOX_SYNC_DEPTH 7/* * 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_STATUS 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_DMA_OFFSET 0xe00/* * Version */#define VER_MAJOR 0#define VER_MINOR 0#define VER_PATCH 2static struct expansion_card *ecs[MAX_ECARDS];/* * Use term=0,1,0,0,0 to turn terminators on/off */int term[MAX_ECARDS] = { 1, 1, 1, 1, 1, 1, 1, 1 };static struct proc_dir_entry proc_scsi_eesox = { PROC_SCSI_QLOGICISP, 5, "eesox", S_IFDIR | S_IRUGO | S_IXUGO, 2};/* 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 control *control = (struct control *)ec->irq_data; control->control |= EESOX_INTR_ENABLE; outb(control->control, control->io_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 control *control = (struct control *)ec->irq_data; control->control &= ~EESOX_INTR_ENABLE; outb(control->control, control->io_port);}static const expansioncard_ops_t eesoxscsi_ops = { eesoxscsi_irqenable, eesoxscsi_irqdisable, NULL, NULL, NULL, NULL};/* 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){ EESOXScsi_Info *info = (EESOXScsi_Info *)host->hostdata; unsigned long flags; save_flags_cli(flags); if (on_off) info->control.control |= EESOX_TERM_ENABLE; else info->control.control &= ~EESOX_TERM_ENABLE; restore_flags(flags); outb(info->control.control, info->control.io_port);}/* 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){ struct Scsi_Host *host = (struct Scsi_Host *)dev_id; fas216_intr(host);}static voideesoxscsi_invalidate(char *addr, long len, fasdmadir_t direction){ unsigned int page; if (direction == DMA_OUT) { for(page = (unsigned int) addr; len > 0; page += PAGE_SIZE, len -= PAGE_SIZE) flush_page_to_ram(page); } else flush_cache_range(current->mm, (unsigned long)addr, (unsigned long)addr + len);}/* 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){ EESOXScsi_Info *info = (EESOXScsi_Info *)host->hostdata; int dmach = host->dma_channel; if (dmach != NO_DMA && (min_type == fasdma_real_all || SCp->this_residual >= 512)) { int buf; for(buf = 1; buf <= SCp->buffers_residual && buf < NR_SG; buf++) { info->dmasg[buf].address = __virt_to_bus( (unsigned long)SCp->buffer[buf].address); info->dmasg[buf].length = SCp->buffer[buf].length; eesoxscsi_invalidate(SCp->buffer[buf].address, SCp->buffer[buf].length, direction); } info->dmasg[0].address = __virt_to_phys((unsigned long)SCp->ptr); info->dmasg[0].length = SCp->this_residual; eesoxscsi_invalidate(SCp->ptr, SCp->this_residual, direction); disable_dma(dmach); set_dma_sg(dmach, info->dmasg, buf); set_dma_mode(dmach, direction == DMA_OUT ? DMA_MODE_WRITE : DMA_MODE_READ); 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 voideesoxscsi_dma_pseudo(struct Scsi_Host *host, Scsi_Pointer *SCp, fasdmadir_t dir, int transfer_size){ EESOXScsi_Info *info = (EESOXScsi_Info *)host->hostdata; unsigned int status; unsigned int length = SCp->this_residual; union { unsigned char *c; unsigned short *s; unsigned long *l; } buffer; buffer.c = SCp->ptr; status = inb(host->io_port + EESOX_STATUS); if (dir == DMA_IN) { while (length > 8) { if (status & EESOX_STAT_DMA) { unsigned long l1, l2; l1 = inw(info->dmaarea); l1 |= inw(info->dmaarea) << 16; l2 = inw(info->dmaarea); l2 |= inw(info->dmaarea) << 16; *buffer.l++ = l1; *buffer.l++ = l2; length -= 8; } else if (status & EESOX_STAT_INTR) goto end; status = inb(host->io_port + EESOX_STATUS); } while (length > 1) { if (status & EESOX_STAT_DMA) { *buffer.s++ = inw(info->dmaarea); length -= 2; } else if (status & EESOX_STAT_INTR) goto end; status = inb(host->io_port + EESOX_STATUS); } while (length > 0) { if (status & EESOX_STAT_DMA) { *buffer.c++ = inw(info->dmaarea); length -= 1; } else if (status & EESOX_STAT_INTR) goto end; status = inb(host->io_port + EESOX_STATUS); } } else { while (length > 8) { if (status & EESOX_STAT_DMA) { unsigned long l1, l2; l1 = *buffer.l++; l2 = *buffer.l++; outw(l1, info->dmaarea); outw(l1 >> 16, info->dmaarea); outw(l2, info->dmaarea); outw(l2 >> 16, info->dmaarea); length -= 8; } else if (status & EESOX_STAT_INTR) goto end; status = inb(host->io_port + EESOX_STATUS); } while (length > 1) { if (status & EESOX_STAT_DMA) { outw(*buffer.s++, info->dmaarea); length -= 2; } else if (status & EESOX_STAT_INTR) goto end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -