^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/drivers/acorn/scsi/eesox.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1997-2005 Russell King
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * This driver is based on experimentation. Hence, it may have made
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * assumptions about the particular card that I have available, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * may not be reliable!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Changelog:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * 01-10-1997 RMK Created, READONLY version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * 15-02-1998 RMK READ/WRITE version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * added DMA support and hardware definitions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * 14-03-1998 RMK Updated DMA support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Added terminator control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * 15-04-1998 RMK Only do PIO if FAS216 will allow it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * 27-06-1998 RMK Changed asm/delay.h to linux/delay.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * 02-04-2000 RMK 0.0.3 Fixed NO_IRQ/NO_DMA problem, updated for new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * error handling code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/pgtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <asm/dma.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <asm/ecard.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include "../scsi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include "fas216.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include "scsi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <scsi/scsicam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define EESOX_FAS216_OFFSET 0x3000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define EESOX_FAS216_SHIFT 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define EESOX_DMASTAT 0x2800
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define EESOX_STAT_INTR 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define EESOX_STAT_DMA 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define EESOX_CONTROL 0x2800
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define EESOX_INTR_ENABLE 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define EESOX_TERM_ENABLE 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define EESOX_RESET 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define EESOX_DMADATA 0x3800
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define VERSION "1.10 (17/01/2003 2.5.59)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * Use term=0,1,0,0,0 to turn terminators on/off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static int term[MAX_ECARDS] = { 1, 1, 1, 1, 1, 1, 1, 1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define NR_SG 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct eesoxscsi_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) FAS216_Info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct expansion_card *ec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) void __iomem *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) void __iomem *ctl_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) unsigned int control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct scatterlist sg[NR_SG]; /* Scatter DMA list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /* Prototype: void eesoxscsi_irqenable(ec, irqnr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * Purpose : Enable interrupts on EESOX SCSI card
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * Params : ec - expansion card structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * : irqnr - interrupt number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) eesoxscsi_irqenable(struct expansion_card *ec, int irqnr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct eesoxscsi_info *info = (struct eesoxscsi_info *)ec->irq_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) info->control |= EESOX_INTR_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) writeb(info->control, info->ctl_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) /* Prototype: void eesoxscsi_irqdisable(ec, irqnr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * Purpose : Disable interrupts on EESOX SCSI card
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * Params : ec - expansion card structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * : irqnr - interrupt number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) eesoxscsi_irqdisable(struct expansion_card *ec, int irqnr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct eesoxscsi_info *info = (struct eesoxscsi_info *)ec->irq_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) info->control &= ~EESOX_INTR_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) writeb(info->control, info->ctl_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static const expansioncard_ops_t eesoxscsi_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) .irqenable = eesoxscsi_irqenable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) .irqdisable = eesoxscsi_irqdisable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /* Prototype: void eesoxscsi_terminator_ctl(*host, on_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * Purpose : Turn the EESOX SCSI terminators on or off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * Params : host - card to turn on/off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * : on_off - !0 to turn on, 0 to turn off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) eesoxscsi_terminator_ctl(struct Scsi_Host *host, int on_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) spin_lock_irqsave(host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (on_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) info->control |= EESOX_TERM_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) info->control &= ~EESOX_TERM_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) writeb(info->control, info->ctl_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) spin_unlock_irqrestore(host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /* Prototype: void eesoxscsi_intr(irq, *dev_id, *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * Purpose : handle interrupts from EESOX SCSI card
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * Params : irq - interrupt number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * dev_id - user-defined (Scsi_Host structure)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static irqreturn_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) eesoxscsi_intr(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct eesoxscsi_info *info = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return fas216_intr(&info->info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /* Prototype: fasdmatype_t eesoxscsi_dma_setup(host, SCpnt, direction, min_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * Purpose : initialises DMA/PIO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * Params : host - host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * SCpnt - command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * direction - DMA on to/off of card
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * min_type - minimum DMA support that we must have for this transfer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * Returns : type of transfer to be performed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static fasdmatype_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) eesoxscsi_dma_setup(struct Scsi_Host *host, struct scsi_pointer *SCp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) fasdmadir_t direction, fasdmatype_t min_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct device *dev = scsi_get_device(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) int dmach = info->info.scsi.dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (dmach != NO_DMA &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) (min_type == fasdma_real_all || SCp->this_residual >= 512)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) int bufs, map_dir, dma_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) bufs = copy_SCp_to_sg(&info->sg[0], SCp, NR_SG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (direction == DMA_OUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) map_dir = DMA_TO_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) dma_dir = DMA_MODE_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) map_dir = DMA_FROM_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) dma_dir = DMA_MODE_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) dma_map_sg(dev, info->sg, bufs, map_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) disable_dma(dmach);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) set_dma_sg(dmach, info->sg, bufs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) set_dma_mode(dmach, dma_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) enable_dma(dmach);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return fasdma_real_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * We don't do DMA, we only do slow PIO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * Some day, we will do Pseudo DMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return fasdma_pseudo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static void eesoxscsi_buffer_in(void *buf, int length, void __iomem *base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) const void __iomem *reg_fas = base + EESOX_FAS216_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) const void __iomem *reg_dmastat = base + EESOX_DMASTAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) const void __iomem *reg_dmadata = base + EESOX_DMADATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) register const unsigned long mask = 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) unsigned int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * Interrupt request?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) status = readb(reg_fas + (REG_STAT << EESOX_FAS216_SHIFT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (status & STAT_INT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * DMA request active?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) status = readb(reg_dmastat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (!(status & EESOX_STAT_DMA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * Get number of bytes in FIFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) status = readb(reg_fas + (REG_CFIS << EESOX_FAS216_SHIFT)) & CFIS_CF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (status > 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) status = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (status > length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) status = length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * Align buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (((u32)buf) & 2 && status >= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) *(u16 *)buf = readl(reg_dmadata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) buf += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) status -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) length -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (status >= 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) unsigned long l1, l2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) l1 = readl(reg_dmadata) & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) l1 |= readl(reg_dmadata) << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) l2 = readl(reg_dmadata) & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) l2 |= readl(reg_dmadata) << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) *(u32 *)buf = l1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) buf += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) *(u32 *)buf = l2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) buf += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) length -= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (status >= 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) unsigned long l1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) l1 = readl(reg_dmadata) & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) l1 |= readl(reg_dmadata) << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) *(u32 *)buf = l1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) buf += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) length -= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (status >= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) *(u16 *)buf = readl(reg_dmadata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) buf += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) length -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) } while (length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static void eesoxscsi_buffer_out(void *buf, int length, void __iomem *base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) const void __iomem *reg_fas = base + EESOX_FAS216_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) const void __iomem *reg_dmastat = base + EESOX_DMASTAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) void __iomem *reg_dmadata = base + EESOX_DMADATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) unsigned int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * Interrupt request?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) status = readb(reg_fas + (REG_STAT << EESOX_FAS216_SHIFT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if (status & STAT_INT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) * DMA request active?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) status = readb(reg_dmastat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if (!(status & EESOX_STAT_DMA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) * Get number of bytes in FIFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) status = readb(reg_fas + (REG_CFIS << EESOX_FAS216_SHIFT)) & CFIS_CF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (status > 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) status = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) status = 16 - status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (status > length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) status = length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) status &= ~1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * Align buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) if (((u32)buf) & 2 && status >= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) writel(*(u16 *)buf << 16, reg_dmadata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) buf += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) status -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) length -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) if (status >= 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) unsigned long l1, l2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) l1 = *(u32 *)buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) buf += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) l2 = *(u32 *)buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) buf += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) writel(l1 << 16, reg_dmadata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) writel(l1, reg_dmadata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) writel(l2 << 16, reg_dmadata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) writel(l2, reg_dmadata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) length -= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) if (status >= 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) unsigned long l1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) l1 = *(u32 *)buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) buf += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) writel(l1 << 16, reg_dmadata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) writel(l1, reg_dmadata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) length -= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) if (status >= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) writel(*(u16 *)buf << 16, reg_dmadata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) buf += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) length -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) } while (length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) eesoxscsi_dma_pseudo(struct Scsi_Host *host, struct scsi_pointer *SCp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) fasdmadir_t dir, int transfer_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) if (dir == DMA_IN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) eesoxscsi_buffer_in(SCp->ptr, SCp->this_residual, info->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) eesoxscsi_buffer_out(SCp->ptr, SCp->this_residual, info->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) /* Prototype: int eesoxscsi_dma_stop(host, SCpnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) * Purpose : stops DMA/PIO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * Params : host - host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) * SCpnt - command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) eesoxscsi_dma_stop(struct Scsi_Host *host, struct scsi_pointer *SCp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) if (info->info.scsi.dma != NO_DMA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) disable_dma(info->info.scsi.dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) /* Prototype: const char *eesoxscsi_info(struct Scsi_Host * host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) * Purpose : returns a descriptive string about this interface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) * Params : host - driver host structure to return info for.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) * Returns : pointer to a static buffer containing null terminated string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) const char *eesoxscsi_info(struct Scsi_Host *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static char string[150];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) sprintf(string, "%s (%s) in slot %d v%s terminators o%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) host->hostt->name, info->info.scsi.type, info->ec->slot_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) VERSION, info->control & EESOX_TERM_ENABLE ? "n" : "ff");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) return string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) /* Prototype: int eesoxscsi_set_proc_info(struct Scsi_Host *host, char *buffer, int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) * Purpose : Set a driver specific function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) * Params : host - host to setup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) * : buffer - buffer containing string describing operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) * : length - length of string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) * Returns : -EINVAL, or 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) eesoxscsi_set_proc_info(struct Scsi_Host *host, char *buffer, int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) int ret = length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) if (length >= 9 && strncmp(buffer, "EESOXSCSI", 9) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) buffer += 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) length -= 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) if (length >= 5 && strncmp(buffer, "term=", 5) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if (buffer[5] == '1')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) eesoxscsi_terminator_ctl(host, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) else if (buffer[5] == '0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) eesoxscsi_terminator_ctl(host, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) static int eesoxscsi_show_info(struct seq_file *m, struct Scsi_Host *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) struct eesoxscsi_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) info = (struct eesoxscsi_info *)host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) seq_printf(m, "EESOX SCSI driver v%s\n", VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) fas216_print_host(&info->info, m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) seq_printf(m, "Term : o%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) info->control & EESOX_TERM_ENABLE ? "n" : "ff");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) fas216_print_stats(&info->info, m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) fas216_print_devices(&info->info, m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) static ssize_t eesoxscsi_show_term(struct device *dev, struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) struct expansion_card *ec = ECARD_DEV(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) struct Scsi_Host *host = ecard_get_drvdata(ec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) return sprintf(buf, "%d\n", info->control & EESOX_TERM_ENABLE ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) static ssize_t eesoxscsi_store_term(struct device *dev, struct device_attribute *attr, const char *buf, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) struct expansion_card *ec = ECARD_DEV(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) struct Scsi_Host *host = ecard_get_drvdata(ec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) if (len > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) spin_lock_irqsave(host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) if (buf[0] != '0') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) info->control |= EESOX_TERM_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) info->control &= ~EESOX_TERM_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) writeb(info->control, info->ctl_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) spin_unlock_irqrestore(host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static DEVICE_ATTR(bus_term, S_IRUGO | S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) eesoxscsi_show_term, eesoxscsi_store_term);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) static struct scsi_host_template eesox_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) .module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) .show_info = eesoxscsi_show_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) .write_info = eesoxscsi_set_proc_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) .name = "EESOX SCSI",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) .info = eesoxscsi_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) .queuecommand = fas216_queue_command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) .eh_host_reset_handler = fas216_eh_host_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) .eh_bus_reset_handler = fas216_eh_bus_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) .eh_device_reset_handler = fas216_eh_device_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) .eh_abort_handler = fas216_eh_abort,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) .can_queue = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) .this_id = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) .sg_tablesize = SG_MAX_SEGMENTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) .dma_boundary = IOMD_DMA_BOUNDARY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) .proc_name = "eesox",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) static int eesoxscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) struct Scsi_Host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) struct eesoxscsi_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) void __iomem *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) ret = ecard_request_resources(ec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) if (!base) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) goto out_region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) host = scsi_host_alloc(&eesox_template,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) sizeof(struct eesoxscsi_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) if (!host) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) goto out_region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) ecard_set_drvdata(ec, host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) info = (struct eesoxscsi_info *)host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) info->ec = ec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) info->base = base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) info->ctl_port = base + EESOX_CONTROL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) info->control = term[ec->slot_no] ? EESOX_TERM_ENABLE : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) writeb(info->control, info->ctl_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) info->info.scsi.io_base = base + EESOX_FAS216_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) info->info.scsi.io_shift = EESOX_FAS216_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) info->info.scsi.irq = ec->irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) info->info.scsi.dma = ec->dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) info->info.ifcfg.clockrate = 40; /* MHz */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) info->info.ifcfg.select_timeout = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) info->info.ifcfg.asyncperiod = 200; /* ns */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) info->info.ifcfg.sync_max_depth = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) info->info.ifcfg.cntl3 = CNTL3_FASTSCSI | CNTL3_FASTCLK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) info->info.ifcfg.disconnect_ok = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) info->info.ifcfg.wide_max_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) info->info.ifcfg.capabilities = FASCAP_PSEUDODMA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) info->info.dma.setup = eesoxscsi_dma_setup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) info->info.dma.pseudo = eesoxscsi_dma_pseudo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) info->info.dma.stop = eesoxscsi_dma_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) ec->irqaddr = base + EESOX_DMASTAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) ec->irqmask = EESOX_STAT_INTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) ecard_setirq(ec, &eesoxscsi_ops, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) device_create_file(&ec->dev, &dev_attr_bus_term);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) ret = fas216_init(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) ret = request_irq(ec->irq, eesoxscsi_intr, 0, "eesoxscsi", info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) printk("scsi%d: IRQ%d not free: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) host->host_no, ec->irq, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) goto out_remove;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) if (info->info.scsi.dma != NO_DMA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) if (request_dma(info->info.scsi.dma, "eesox")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) printk("scsi%d: DMA%d not free, DMA disabled\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) host->host_no, info->info.scsi.dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) info->info.scsi.dma = NO_DMA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) set_dma_speed(info->info.scsi.dma, 180);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) info->info.ifcfg.capabilities |= FASCAP_DMA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) info->info.ifcfg.cntl3 |= CNTL3_BS8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) ret = fas216_add(host, &ec->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) if (info->info.scsi.dma != NO_DMA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) free_dma(info->info.scsi.dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) free_irq(ec->irq, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) out_remove:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) fas216_remove(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) device_remove_file(&ec->dev, &dev_attr_bus_term);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) scsi_host_put(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) out_region:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) ecard_release_resources(ec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) static void eesoxscsi_remove(struct expansion_card *ec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) struct Scsi_Host *host = ecard_get_drvdata(ec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) ecard_set_drvdata(ec, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) fas216_remove(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) if (info->info.scsi.dma != NO_DMA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) free_dma(info->info.scsi.dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) free_irq(ec->irq, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) device_remove_file(&ec->dev, &dev_attr_bus_term);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) fas216_release(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) scsi_host_put(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) ecard_release_resources(ec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) static const struct ecard_id eesoxscsi_cids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) { MANU_EESOX, PROD_EESOX_SCSI2 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) { 0xffff, 0xffff },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) static struct ecard_driver eesoxscsi_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) .probe = eesoxscsi_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) .remove = eesoxscsi_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) .id_table = eesoxscsi_cids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) .drv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) .name = "eesoxscsi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) static int __init eesox_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) return ecard_register_driver(&eesoxscsi_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) static void __exit eesox_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) ecard_remove_driver(&eesoxscsi_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) module_init(eesox_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) module_exit(eesox_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) MODULE_AUTHOR("Russell King");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) MODULE_DESCRIPTION("EESOX 'Fast' SCSI driver for Acorn machines");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) module_param_array(term, int, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) MODULE_PARM_DESC(term, "SCSI bus termination");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) MODULE_LICENSE("GPL");