1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * linux/drivers/acorn/scsi/eesox.c
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds * Copyright (C) 1997-2005 Russell King
61da177e4SLinus Torvalds *
71da177e4SLinus Torvalds * This driver is based on experimentation. Hence, it may have made
81da177e4SLinus Torvalds * assumptions about the particular card that I have available, and
91da177e4SLinus Torvalds * may not be reliable!
101da177e4SLinus Torvalds *
111da177e4SLinus Torvalds * Changelog:
121da177e4SLinus Torvalds * 01-10-1997 RMK Created, READONLY version
131da177e4SLinus Torvalds * 15-02-1998 RMK READ/WRITE version
141da177e4SLinus Torvalds * added DMA support and hardware definitions
151da177e4SLinus Torvalds * 14-03-1998 RMK Updated DMA support
161da177e4SLinus Torvalds * Added terminator control
171da177e4SLinus Torvalds * 15-04-1998 RMK Only do PIO if FAS216 will allow it.
181da177e4SLinus Torvalds * 27-06-1998 RMK Changed asm/delay.h to linux/delay.h
191da177e4SLinus Torvalds * 02-04-2000 RMK 0.0.3 Fixed NO_IRQ/NO_DMA problem, updated for new
201da177e4SLinus Torvalds * error handling code.
211da177e4SLinus Torvalds */
221da177e4SLinus Torvalds #include <linux/module.h>
231da177e4SLinus Torvalds #include <linux/blkdev.h>
241da177e4SLinus Torvalds #include <linux/kernel.h>
251da177e4SLinus Torvalds #include <linux/string.h>
261da177e4SLinus Torvalds #include <linux/ioport.h>
271da177e4SLinus Torvalds #include <linux/proc_fs.h>
281da177e4SLinus Torvalds #include <linux/delay.h>
291da177e4SLinus Torvalds #include <linux/interrupt.h>
301da177e4SLinus Torvalds #include <linux/init.h>
311da177e4SLinus Torvalds #include <linux/dma-mapping.h>
3265fddcfcSMike Rapoport #include <linux/pgtable.h>
331da177e4SLinus Torvalds
341da177e4SLinus Torvalds #include <asm/io.h>
351da177e4SLinus Torvalds #include <asm/dma.h>
361da177e4SLinus Torvalds #include <asm/ecard.h>
371da177e4SLinus Torvalds
3853555fb7SBart Van Assche #include <scsi/scsi.h>
3953555fb7SBart Van Assche #include <scsi/scsi_cmnd.h>
4053555fb7SBart Van Assche #include <scsi/scsi_device.h>
4153555fb7SBart Van Assche #include <scsi/scsi_eh.h>
421da177e4SLinus Torvalds #include <scsi/scsi_host.h>
4353555fb7SBart Van Assche #include <scsi/scsi_tcq.h>
441da177e4SLinus Torvalds #include "fas216.h"
458c97e2f3SBart Van Assche #include "arm_scsi.h"
461da177e4SLinus Torvalds
471da177e4SLinus Torvalds #include <scsi/scsicam.h>
481da177e4SLinus Torvalds
491da177e4SLinus Torvalds #define EESOX_FAS216_OFFSET 0x3000
501da177e4SLinus Torvalds #define EESOX_FAS216_SHIFT 5
511da177e4SLinus Torvalds
521da177e4SLinus Torvalds #define EESOX_DMASTAT 0x2800
531da177e4SLinus Torvalds #define EESOX_STAT_INTR 0x01
541da177e4SLinus Torvalds #define EESOX_STAT_DMA 0x02
551da177e4SLinus Torvalds
561da177e4SLinus Torvalds #define EESOX_CONTROL 0x2800
571da177e4SLinus Torvalds #define EESOX_INTR_ENABLE 0x04
581da177e4SLinus Torvalds #define EESOX_TERM_ENABLE 0x02
591da177e4SLinus Torvalds #define EESOX_RESET 0x01
601da177e4SLinus Torvalds
611da177e4SLinus Torvalds #define EESOX_DMADATA 0x3800
621da177e4SLinus Torvalds
631da177e4SLinus Torvalds #define VERSION "1.10 (17/01/2003 2.5.59)"
641da177e4SLinus Torvalds
651da177e4SLinus Torvalds /*
661da177e4SLinus Torvalds * Use term=0,1,0,0,0 to turn terminators on/off
671da177e4SLinus Torvalds */
681da177e4SLinus Torvalds static int term[MAX_ECARDS] = { 1, 1, 1, 1, 1, 1, 1, 1 };
691da177e4SLinus Torvalds
701da177e4SLinus Torvalds #define NR_SG 256
711da177e4SLinus Torvalds
721da177e4SLinus Torvalds struct eesoxscsi_info {
731da177e4SLinus Torvalds FAS216_Info info;
741da177e4SLinus Torvalds struct expansion_card *ec;
751da177e4SLinus Torvalds void __iomem *base;
761da177e4SLinus Torvalds void __iomem *ctl_port;
771da177e4SLinus Torvalds unsigned int control;
781da177e4SLinus Torvalds struct scatterlist sg[NR_SG]; /* Scatter DMA list */
791da177e4SLinus Torvalds };
801da177e4SLinus Torvalds
811da177e4SLinus Torvalds /* Prototype: void eesoxscsi_irqenable(ec, irqnr)
821da177e4SLinus Torvalds * Purpose : Enable interrupts on EESOX SCSI card
831da177e4SLinus Torvalds * Params : ec - expansion card structure
841da177e4SLinus Torvalds * : irqnr - interrupt number
851da177e4SLinus Torvalds */
861da177e4SLinus Torvalds static void
eesoxscsi_irqenable(struct expansion_card * ec,int irqnr)871da177e4SLinus Torvalds eesoxscsi_irqenable(struct expansion_card *ec, int irqnr)
881da177e4SLinus Torvalds {
891da177e4SLinus Torvalds struct eesoxscsi_info *info = (struct eesoxscsi_info *)ec->irq_data;
901da177e4SLinus Torvalds
911da177e4SLinus Torvalds info->control |= EESOX_INTR_ENABLE;
921da177e4SLinus Torvalds
931da177e4SLinus Torvalds writeb(info->control, info->ctl_port);
941da177e4SLinus Torvalds }
951da177e4SLinus Torvalds
961da177e4SLinus Torvalds /* Prototype: void eesoxscsi_irqdisable(ec, irqnr)
971da177e4SLinus Torvalds * Purpose : Disable interrupts on EESOX SCSI card
981da177e4SLinus Torvalds * Params : ec - expansion card structure
991da177e4SLinus Torvalds * : irqnr - interrupt number
1001da177e4SLinus Torvalds */
1011da177e4SLinus Torvalds static void
eesoxscsi_irqdisable(struct expansion_card * ec,int irqnr)1021da177e4SLinus Torvalds eesoxscsi_irqdisable(struct expansion_card *ec, int irqnr)
1031da177e4SLinus Torvalds {
1041da177e4SLinus Torvalds struct eesoxscsi_info *info = (struct eesoxscsi_info *)ec->irq_data;
1051da177e4SLinus Torvalds
1061da177e4SLinus Torvalds info->control &= ~EESOX_INTR_ENABLE;
1071da177e4SLinus Torvalds
1081da177e4SLinus Torvalds writeb(info->control, info->ctl_port);
1091da177e4SLinus Torvalds }
1101da177e4SLinus Torvalds
1111da177e4SLinus Torvalds static const expansioncard_ops_t eesoxscsi_ops = {
1121da177e4SLinus Torvalds .irqenable = eesoxscsi_irqenable,
1131da177e4SLinus Torvalds .irqdisable = eesoxscsi_irqdisable,
1141da177e4SLinus Torvalds };
1151da177e4SLinus Torvalds
1161da177e4SLinus Torvalds /* Prototype: void eesoxscsi_terminator_ctl(*host, on_off)
1171da177e4SLinus Torvalds * Purpose : Turn the EESOX SCSI terminators on or off
1181da177e4SLinus Torvalds * Params : host - card to turn on/off
1191da177e4SLinus Torvalds * : on_off - !0 to turn on, 0 to turn off
1201da177e4SLinus Torvalds */
1211da177e4SLinus Torvalds static void
eesoxscsi_terminator_ctl(struct Scsi_Host * host,int on_off)1221da177e4SLinus Torvalds eesoxscsi_terminator_ctl(struct Scsi_Host *host, int on_off)
1231da177e4SLinus Torvalds {
1241da177e4SLinus Torvalds struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
1251da177e4SLinus Torvalds unsigned long flags;
1261da177e4SLinus Torvalds
1271da177e4SLinus Torvalds spin_lock_irqsave(host->host_lock, flags);
1281da177e4SLinus Torvalds if (on_off)
1291da177e4SLinus Torvalds info->control |= EESOX_TERM_ENABLE;
1301da177e4SLinus Torvalds else
1311da177e4SLinus Torvalds info->control &= ~EESOX_TERM_ENABLE;
1321da177e4SLinus Torvalds
1331da177e4SLinus Torvalds writeb(info->control, info->ctl_port);
1341da177e4SLinus Torvalds spin_unlock_irqrestore(host->host_lock, flags);
1351da177e4SLinus Torvalds }
1361da177e4SLinus Torvalds
1371da177e4SLinus Torvalds /* Prototype: void eesoxscsi_intr(irq, *dev_id, *regs)
1381da177e4SLinus Torvalds * Purpose : handle interrupts from EESOX SCSI card
1391da177e4SLinus Torvalds * Params : irq - interrupt number
1401da177e4SLinus Torvalds * dev_id - user-defined (Scsi_Host structure)
1411da177e4SLinus Torvalds */
1421da177e4SLinus Torvalds static irqreturn_t
eesoxscsi_intr(int irq,void * dev_id)1437d12e780SDavid Howells eesoxscsi_intr(int irq, void *dev_id)
1441da177e4SLinus Torvalds {
1451da177e4SLinus Torvalds struct eesoxscsi_info *info = dev_id;
1461da177e4SLinus Torvalds
1471da177e4SLinus Torvalds return fas216_intr(&info->info);
1481da177e4SLinus Torvalds }
1491da177e4SLinus Torvalds
1501da177e4SLinus Torvalds /* Prototype: fasdmatype_t eesoxscsi_dma_setup(host, SCpnt, direction, min_type)
1511da177e4SLinus Torvalds * Purpose : initialises DMA/PIO
1521da177e4SLinus Torvalds * Params : host - host
1531da177e4SLinus Torvalds * SCpnt - command
1541da177e4SLinus Torvalds * direction - DMA on to/off of card
1551da177e4SLinus Torvalds * min_type - minimum DMA support that we must have for this transfer
1561da177e4SLinus Torvalds * Returns : type of transfer to be performed
1571da177e4SLinus Torvalds */
1581da177e4SLinus Torvalds static fasdmatype_t
eesoxscsi_dma_setup(struct Scsi_Host * host,struct scsi_pointer * SCp,fasdmadir_t direction,fasdmatype_t min_type)1590a04137eSChristoph Hellwig eesoxscsi_dma_setup(struct Scsi_Host *host, struct scsi_pointer *SCp,
1601da177e4SLinus Torvalds fasdmadir_t direction, fasdmatype_t min_type)
1611da177e4SLinus Torvalds {
1621da177e4SLinus Torvalds struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
1631da177e4SLinus Torvalds struct device *dev = scsi_get_device(host);
1641da177e4SLinus Torvalds int dmach = info->info.scsi.dma;
1651da177e4SLinus Torvalds
1661da177e4SLinus Torvalds if (dmach != NO_DMA &&
1671da177e4SLinus Torvalds (min_type == fasdma_real_all || SCp->this_residual >= 512)) {
1681da177e4SLinus Torvalds int bufs, map_dir, dma_dir;
1691da177e4SLinus Torvalds
1701da177e4SLinus Torvalds bufs = copy_SCp_to_sg(&info->sg[0], SCp, NR_SG);
1711da177e4SLinus Torvalds
172a08a0732SJoe Perches if (direction == DMA_OUT) {
173a08a0732SJoe Perches map_dir = DMA_TO_DEVICE;
1741da177e4SLinus Torvalds dma_dir = DMA_MODE_WRITE;
175a08a0732SJoe Perches } else {
176a08a0732SJoe Perches map_dir = DMA_FROM_DEVICE;
1771da177e4SLinus Torvalds dma_dir = DMA_MODE_READ;
178a08a0732SJoe Perches }
1791da177e4SLinus Torvalds
18023d046f4SRussell King dma_map_sg(dev, info->sg, bufs, map_dir);
1811da177e4SLinus Torvalds
1821da177e4SLinus Torvalds disable_dma(dmach);
18323d046f4SRussell King set_dma_sg(dmach, info->sg, bufs);
1841da177e4SLinus Torvalds set_dma_mode(dmach, dma_dir);
1851da177e4SLinus Torvalds enable_dma(dmach);
1861da177e4SLinus Torvalds return fasdma_real_all;
1871da177e4SLinus Torvalds }
1881da177e4SLinus Torvalds /*
1891da177e4SLinus Torvalds * We don't do DMA, we only do slow PIO
1901da177e4SLinus Torvalds *
1911da177e4SLinus Torvalds * Some day, we will do Pseudo DMA
1921da177e4SLinus Torvalds */
1931da177e4SLinus Torvalds return fasdma_pseudo;
1941da177e4SLinus Torvalds }
1951da177e4SLinus Torvalds
eesoxscsi_buffer_in(void * buf,int length,void __iomem * base)1961da177e4SLinus Torvalds static void eesoxscsi_buffer_in(void *buf, int length, void __iomem *base)
1971da177e4SLinus Torvalds {
1981da177e4SLinus Torvalds const void __iomem *reg_fas = base + EESOX_FAS216_OFFSET;
1991da177e4SLinus Torvalds const void __iomem *reg_dmastat = base + EESOX_DMASTAT;
2001da177e4SLinus Torvalds const void __iomem *reg_dmadata = base + EESOX_DMADATA;
201c5a69d57STobias Klauser register const unsigned long mask = 0xffff;
2021da177e4SLinus Torvalds
2031da177e4SLinus Torvalds do {
2041da177e4SLinus Torvalds unsigned int status;
2051da177e4SLinus Torvalds
2061da177e4SLinus Torvalds /*
2071da177e4SLinus Torvalds * Interrupt request?
2081da177e4SLinus Torvalds */
2091da177e4SLinus Torvalds status = readb(reg_fas + (REG_STAT << EESOX_FAS216_SHIFT));
2101da177e4SLinus Torvalds if (status & STAT_INT)
2111da177e4SLinus Torvalds break;
2121da177e4SLinus Torvalds
2131da177e4SLinus Torvalds /*
2141da177e4SLinus Torvalds * DMA request active?
2151da177e4SLinus Torvalds */
2161da177e4SLinus Torvalds status = readb(reg_dmastat);
2171da177e4SLinus Torvalds if (!(status & EESOX_STAT_DMA))
2181da177e4SLinus Torvalds continue;
2191da177e4SLinus Torvalds
2201da177e4SLinus Torvalds /*
2211da177e4SLinus Torvalds * Get number of bytes in FIFO
2221da177e4SLinus Torvalds */
2231da177e4SLinus Torvalds status = readb(reg_fas + (REG_CFIS << EESOX_FAS216_SHIFT)) & CFIS_CF;
2241da177e4SLinus Torvalds if (status > 16)
2251da177e4SLinus Torvalds status = 16;
2261da177e4SLinus Torvalds if (status > length)
2271da177e4SLinus Torvalds status = length;
2281da177e4SLinus Torvalds
2291da177e4SLinus Torvalds /*
2301da177e4SLinus Torvalds * Align buffer.
2311da177e4SLinus Torvalds */
2321da177e4SLinus Torvalds if (((u32)buf) & 2 && status >= 2) {
2331da177e4SLinus Torvalds *(u16 *)buf = readl(reg_dmadata);
2341da177e4SLinus Torvalds buf += 2;
2351da177e4SLinus Torvalds status -= 2;
2361da177e4SLinus Torvalds length -= 2;
2371da177e4SLinus Torvalds }
2381da177e4SLinus Torvalds
2391da177e4SLinus Torvalds if (status >= 8) {
2401da177e4SLinus Torvalds unsigned long l1, l2;
2411da177e4SLinus Torvalds
2421da177e4SLinus Torvalds l1 = readl(reg_dmadata) & mask;
2431da177e4SLinus Torvalds l1 |= readl(reg_dmadata) << 16;
2441da177e4SLinus Torvalds l2 = readl(reg_dmadata) & mask;
2451da177e4SLinus Torvalds l2 |= readl(reg_dmadata) << 16;
2461da177e4SLinus Torvalds *(u32 *)buf = l1;
2471da177e4SLinus Torvalds buf += 4;
2481da177e4SLinus Torvalds *(u32 *)buf = l2;
2491da177e4SLinus Torvalds buf += 4;
2501da177e4SLinus Torvalds length -= 8;
2511da177e4SLinus Torvalds continue;
2521da177e4SLinus Torvalds }
2531da177e4SLinus Torvalds
2541da177e4SLinus Torvalds if (status >= 4) {
2551da177e4SLinus Torvalds unsigned long l1;
2561da177e4SLinus Torvalds
2571da177e4SLinus Torvalds l1 = readl(reg_dmadata) & mask;
2581da177e4SLinus Torvalds l1 |= readl(reg_dmadata) << 16;
2591da177e4SLinus Torvalds
2601da177e4SLinus Torvalds *(u32 *)buf = l1;
2611da177e4SLinus Torvalds buf += 4;
2621da177e4SLinus Torvalds length -= 4;
2631da177e4SLinus Torvalds continue;
2641da177e4SLinus Torvalds }
2651da177e4SLinus Torvalds
2661da177e4SLinus Torvalds if (status >= 2) {
2671da177e4SLinus Torvalds *(u16 *)buf = readl(reg_dmadata);
2681da177e4SLinus Torvalds buf += 2;
2691da177e4SLinus Torvalds length -= 2;
2701da177e4SLinus Torvalds }
2711da177e4SLinus Torvalds } while (length);
2721da177e4SLinus Torvalds }
2731da177e4SLinus Torvalds
eesoxscsi_buffer_out(void * buf,int length,void __iomem * base)2741da177e4SLinus Torvalds static void eesoxscsi_buffer_out(void *buf, int length, void __iomem *base)
2751da177e4SLinus Torvalds {
2761da177e4SLinus Torvalds const void __iomem *reg_fas = base + EESOX_FAS216_OFFSET;
2771da177e4SLinus Torvalds const void __iomem *reg_dmastat = base + EESOX_DMASTAT;
278f39f7b7dSArnd Bergmann void __iomem *reg_dmadata = base + EESOX_DMADATA;
2791da177e4SLinus Torvalds
2801da177e4SLinus Torvalds do {
2811da177e4SLinus Torvalds unsigned int status;
2821da177e4SLinus Torvalds
2831da177e4SLinus Torvalds /*
2841da177e4SLinus Torvalds * Interrupt request?
2851da177e4SLinus Torvalds */
2861da177e4SLinus Torvalds status = readb(reg_fas + (REG_STAT << EESOX_FAS216_SHIFT));
2871da177e4SLinus Torvalds if (status & STAT_INT)
2881da177e4SLinus Torvalds break;
2891da177e4SLinus Torvalds
2901da177e4SLinus Torvalds /*
2911da177e4SLinus Torvalds * DMA request active?
2921da177e4SLinus Torvalds */
2931da177e4SLinus Torvalds status = readb(reg_dmastat);
2941da177e4SLinus Torvalds if (!(status & EESOX_STAT_DMA))
2951da177e4SLinus Torvalds continue;
2961da177e4SLinus Torvalds
2971da177e4SLinus Torvalds /*
2981da177e4SLinus Torvalds * Get number of bytes in FIFO
2991da177e4SLinus Torvalds */
3001da177e4SLinus Torvalds status = readb(reg_fas + (REG_CFIS << EESOX_FAS216_SHIFT)) & CFIS_CF;
3011da177e4SLinus Torvalds if (status > 16)
3021da177e4SLinus Torvalds status = 16;
3031da177e4SLinus Torvalds status = 16 - status;
3041da177e4SLinus Torvalds if (status > length)
3051da177e4SLinus Torvalds status = length;
3061da177e4SLinus Torvalds status &= ~1;
3071da177e4SLinus Torvalds
3081da177e4SLinus Torvalds /*
3091da177e4SLinus Torvalds * Align buffer.
3101da177e4SLinus Torvalds */
3111da177e4SLinus Torvalds if (((u32)buf) & 2 && status >= 2) {
3121da177e4SLinus Torvalds writel(*(u16 *)buf << 16, reg_dmadata);
3131da177e4SLinus Torvalds buf += 2;
3141da177e4SLinus Torvalds status -= 2;
3151da177e4SLinus Torvalds length -= 2;
3161da177e4SLinus Torvalds }
3171da177e4SLinus Torvalds
3181da177e4SLinus Torvalds if (status >= 8) {
3191da177e4SLinus Torvalds unsigned long l1, l2;
3201da177e4SLinus Torvalds
3211da177e4SLinus Torvalds l1 = *(u32 *)buf;
3221da177e4SLinus Torvalds buf += 4;
3231da177e4SLinus Torvalds l2 = *(u32 *)buf;
3241da177e4SLinus Torvalds buf += 4;
3251da177e4SLinus Torvalds
3261da177e4SLinus Torvalds writel(l1 << 16, reg_dmadata);
3271da177e4SLinus Torvalds writel(l1, reg_dmadata);
3281da177e4SLinus Torvalds writel(l2 << 16, reg_dmadata);
3291da177e4SLinus Torvalds writel(l2, reg_dmadata);
3301da177e4SLinus Torvalds length -= 8;
3311da177e4SLinus Torvalds continue;
3321da177e4SLinus Torvalds }
3331da177e4SLinus Torvalds
3341da177e4SLinus Torvalds if (status >= 4) {
3351da177e4SLinus Torvalds unsigned long l1;
3361da177e4SLinus Torvalds
3371da177e4SLinus Torvalds l1 = *(u32 *)buf;
3381da177e4SLinus Torvalds buf += 4;
3391da177e4SLinus Torvalds
3401da177e4SLinus Torvalds writel(l1 << 16, reg_dmadata);
3411da177e4SLinus Torvalds writel(l1, reg_dmadata);
3421da177e4SLinus Torvalds length -= 4;
3431da177e4SLinus Torvalds continue;
3441da177e4SLinus Torvalds }
3451da177e4SLinus Torvalds
3461da177e4SLinus Torvalds if (status >= 2) {
3471da177e4SLinus Torvalds writel(*(u16 *)buf << 16, reg_dmadata);
3481da177e4SLinus Torvalds buf += 2;
3491da177e4SLinus Torvalds length -= 2;
3501da177e4SLinus Torvalds }
3511da177e4SLinus Torvalds } while (length);
3521da177e4SLinus Torvalds }
3531da177e4SLinus Torvalds
3541da177e4SLinus Torvalds static void
eesoxscsi_dma_pseudo(struct Scsi_Host * host,struct scsi_pointer * SCp,fasdmadir_t dir,int transfer_size)3550a04137eSChristoph Hellwig eesoxscsi_dma_pseudo(struct Scsi_Host *host, struct scsi_pointer *SCp,
3561da177e4SLinus Torvalds fasdmadir_t dir, int transfer_size)
3571da177e4SLinus Torvalds {
3581da177e4SLinus Torvalds struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
3591da177e4SLinus Torvalds if (dir == DMA_IN) {
3601da177e4SLinus Torvalds eesoxscsi_buffer_in(SCp->ptr, SCp->this_residual, info->base);
3611da177e4SLinus Torvalds } else {
3621da177e4SLinus Torvalds eesoxscsi_buffer_out(SCp->ptr, SCp->this_residual, info->base);
3631da177e4SLinus Torvalds }
3641da177e4SLinus Torvalds }
3651da177e4SLinus Torvalds
3661da177e4SLinus Torvalds /* Prototype: int eesoxscsi_dma_stop(host, SCpnt)
3671da177e4SLinus Torvalds * Purpose : stops DMA/PIO
3681da177e4SLinus Torvalds * Params : host - host
3691da177e4SLinus Torvalds * SCpnt - command
3701da177e4SLinus Torvalds */
3711da177e4SLinus Torvalds static void
eesoxscsi_dma_stop(struct Scsi_Host * host,struct scsi_pointer * SCp)3720a04137eSChristoph Hellwig eesoxscsi_dma_stop(struct Scsi_Host *host, struct scsi_pointer *SCp)
3731da177e4SLinus Torvalds {
3741da177e4SLinus Torvalds struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
3751da177e4SLinus Torvalds if (info->info.scsi.dma != NO_DMA)
3761da177e4SLinus Torvalds disable_dma(info->info.scsi.dma);
3771da177e4SLinus Torvalds }
3781da177e4SLinus Torvalds
3791da177e4SLinus Torvalds /* Prototype: const char *eesoxscsi_info(struct Scsi_Host * host)
3801da177e4SLinus Torvalds * Purpose : returns a descriptive string about this interface,
3811da177e4SLinus Torvalds * Params : host - driver host structure to return info for.
3821da177e4SLinus Torvalds * Returns : pointer to a static buffer containing null terminated string.
3831da177e4SLinus Torvalds */
eesoxscsi_info(struct Scsi_Host * host)3841da177e4SLinus Torvalds const char *eesoxscsi_info(struct Scsi_Host *host)
3851da177e4SLinus Torvalds {
3861da177e4SLinus Torvalds struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
3871da177e4SLinus Torvalds static char string[150];
3881da177e4SLinus Torvalds
3891da177e4SLinus Torvalds sprintf(string, "%s (%s) in slot %d v%s terminators o%s",
3901da177e4SLinus Torvalds host->hostt->name, info->info.scsi.type, info->ec->slot_no,
3911da177e4SLinus Torvalds VERSION, info->control & EESOX_TERM_ENABLE ? "n" : "ff");
3921da177e4SLinus Torvalds
3931da177e4SLinus Torvalds return string;
3941da177e4SLinus Torvalds }
3951da177e4SLinus Torvalds
3961da177e4SLinus Torvalds /* Prototype: int eesoxscsi_set_proc_info(struct Scsi_Host *host, char *buffer, int length)
3971da177e4SLinus Torvalds * Purpose : Set a driver specific function
3981da177e4SLinus Torvalds * Params : host - host to setup
3991da177e4SLinus Torvalds * : buffer - buffer containing string describing operation
4001da177e4SLinus Torvalds * : length - length of string
4011da177e4SLinus Torvalds * Returns : -EINVAL, or 0
4021da177e4SLinus Torvalds */
4031da177e4SLinus Torvalds static int
eesoxscsi_set_proc_info(struct Scsi_Host * host,char * buffer,int length)4041da177e4SLinus Torvalds eesoxscsi_set_proc_info(struct Scsi_Host *host, char *buffer, int length)
4051da177e4SLinus Torvalds {
4061da177e4SLinus Torvalds int ret = length;
4071da177e4SLinus Torvalds
4081da177e4SLinus Torvalds if (length >= 9 && strncmp(buffer, "EESOXSCSI", 9) == 0) {
4091da177e4SLinus Torvalds buffer += 9;
4101da177e4SLinus Torvalds length -= 9;
4111da177e4SLinus Torvalds
4121da177e4SLinus Torvalds if (length >= 5 && strncmp(buffer, "term=", 5) == 0) {
4131da177e4SLinus Torvalds if (buffer[5] == '1')
4141da177e4SLinus Torvalds eesoxscsi_terminator_ctl(host, 1);
4151da177e4SLinus Torvalds else if (buffer[5] == '0')
4161da177e4SLinus Torvalds eesoxscsi_terminator_ctl(host, 0);
4171da177e4SLinus Torvalds else
4181da177e4SLinus Torvalds ret = -EINVAL;
4191da177e4SLinus Torvalds } else
4201da177e4SLinus Torvalds ret = -EINVAL;
4211da177e4SLinus Torvalds } else
4221da177e4SLinus Torvalds ret = -EINVAL;
4231da177e4SLinus Torvalds
4241da177e4SLinus Torvalds return ret;
4251da177e4SLinus Torvalds }
4261da177e4SLinus Torvalds
eesoxscsi_show_info(struct seq_file * m,struct Scsi_Host * host)4279d4e5c54SAl Viro static int eesoxscsi_show_info(struct seq_file *m, struct Scsi_Host *host)
4281da177e4SLinus Torvalds {
4291da177e4SLinus Torvalds struct eesoxscsi_info *info;
4301da177e4SLinus Torvalds
4311da177e4SLinus Torvalds info = (struct eesoxscsi_info *)host->hostdata;
4321da177e4SLinus Torvalds
4339d4e5c54SAl Viro seq_printf(m, "EESOX SCSI driver v%s\n", VERSION);
4349d4e5c54SAl Viro fas216_print_host(&info->info, m);
4359d4e5c54SAl Viro seq_printf(m, "Term : o%s\n",
4361da177e4SLinus Torvalds info->control & EESOX_TERM_ENABLE ? "n" : "ff");
4371da177e4SLinus Torvalds
4389d4e5c54SAl Viro fas216_print_stats(&info->info, m);
4399d4e5c54SAl Viro fas216_print_devices(&info->info, m);
4409d4e5c54SAl Viro return 0;
4411da177e4SLinus Torvalds }
4421da177e4SLinus Torvalds
eesoxscsi_show_term(struct device * dev,struct device_attribute * attr,char * buf)44310523b3bSYani Ioannou static ssize_t eesoxscsi_show_term(struct device *dev, struct device_attribute *attr, char *buf)
4441da177e4SLinus Torvalds {
4451da177e4SLinus Torvalds struct expansion_card *ec = ECARD_DEV(dev);
4461da177e4SLinus Torvalds struct Scsi_Host *host = ecard_get_drvdata(ec);
4471da177e4SLinus Torvalds struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
4481da177e4SLinus Torvalds
4491da177e4SLinus Torvalds return sprintf(buf, "%d\n", info->control & EESOX_TERM_ENABLE ? 1 : 0);
4501da177e4SLinus Torvalds }
4511da177e4SLinus Torvalds
eesoxscsi_store_term(struct device * dev,struct device_attribute * attr,const char * buf,size_t len)45210523b3bSYani Ioannou static ssize_t eesoxscsi_store_term(struct device *dev, struct device_attribute *attr, const char *buf, size_t len)
4531da177e4SLinus Torvalds {
4541da177e4SLinus Torvalds struct expansion_card *ec = ECARD_DEV(dev);
4551da177e4SLinus Torvalds struct Scsi_Host *host = ecard_get_drvdata(ec);
4561da177e4SLinus Torvalds struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
4571da177e4SLinus Torvalds unsigned long flags;
4581da177e4SLinus Torvalds
4591da177e4SLinus Torvalds if (len > 1) {
4601da177e4SLinus Torvalds spin_lock_irqsave(host->host_lock, flags);
4611da177e4SLinus Torvalds if (buf[0] != '0') {
4621da177e4SLinus Torvalds info->control |= EESOX_TERM_ENABLE;
4631da177e4SLinus Torvalds } else {
4641da177e4SLinus Torvalds info->control &= ~EESOX_TERM_ENABLE;
4651da177e4SLinus Torvalds }
4661da177e4SLinus Torvalds writeb(info->control, info->ctl_port);
4671da177e4SLinus Torvalds spin_unlock_irqrestore(host->host_lock, flags);
4681da177e4SLinus Torvalds }
4691da177e4SLinus Torvalds
4701da177e4SLinus Torvalds return len;
4711da177e4SLinus Torvalds }
4721da177e4SLinus Torvalds
4731da177e4SLinus Torvalds static DEVICE_ATTR(bus_term, S_IRUGO | S_IWUSR,
4741da177e4SLinus Torvalds eesoxscsi_show_term, eesoxscsi_store_term);
4751da177e4SLinus Torvalds
476*13c2e964SBart Van Assche static const struct scsi_host_template eesox_template = {
4771da177e4SLinus Torvalds .module = THIS_MODULE,
4789d4e5c54SAl Viro .show_info = eesoxscsi_show_info,
4799d4e5c54SAl Viro .write_info = eesoxscsi_set_proc_info,
4801da177e4SLinus Torvalds .name = "EESOX SCSI",
4811da177e4SLinus Torvalds .info = eesoxscsi_info,
4821da177e4SLinus Torvalds .queuecommand = fas216_queue_command,
4831da177e4SLinus Torvalds .eh_host_reset_handler = fas216_eh_host_reset,
4841da177e4SLinus Torvalds .eh_bus_reset_handler = fas216_eh_bus_reset,
4851da177e4SLinus Torvalds .eh_device_reset_handler = fas216_eh_device_reset,
4861da177e4SLinus Torvalds .eh_abort_handler = fas216_eh_abort,
487caffd3adSBart Van Assche .cmd_size = sizeof(struct fas216_cmd_priv),
4881da177e4SLinus Torvalds .can_queue = 1,
4891da177e4SLinus Torvalds .this_id = 7,
49065e8617fSMing Lin .sg_tablesize = SG_MAX_SEGMENTS,
4915369bea7SRussell King .dma_boundary = IOMD_DMA_BOUNDARY,
4921da177e4SLinus Torvalds .proc_name = "eesox",
4931da177e4SLinus Torvalds };
4941da177e4SLinus Torvalds
eesoxscsi_probe(struct expansion_card * ec,const struct ecard_id * id)4956f039790SGreg Kroah-Hartman static int eesoxscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
4961da177e4SLinus Torvalds {
4971da177e4SLinus Torvalds struct Scsi_Host *host;
4981da177e4SLinus Torvalds struct eesoxscsi_info *info;
4991da177e4SLinus Torvalds void __iomem *base;
5001da177e4SLinus Torvalds int ret;
5011da177e4SLinus Torvalds
5021da177e4SLinus Torvalds ret = ecard_request_resources(ec);
5031da177e4SLinus Torvalds if (ret)
5041da177e4SLinus Torvalds goto out;
5051da177e4SLinus Torvalds
50610bdaaa0SRussell King base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
5071da177e4SLinus Torvalds if (!base) {
5081da177e4SLinus Torvalds ret = -ENOMEM;
5091da177e4SLinus Torvalds goto out_region;
5101da177e4SLinus Torvalds }
5111da177e4SLinus Torvalds
5121da177e4SLinus Torvalds host = scsi_host_alloc(&eesox_template,
5131da177e4SLinus Torvalds sizeof(struct eesoxscsi_info));
5141da177e4SLinus Torvalds if (!host) {
5151da177e4SLinus Torvalds ret = -ENOMEM;
51610bdaaa0SRussell King goto out_region;
5171da177e4SLinus Torvalds }
5181da177e4SLinus Torvalds
5191da177e4SLinus Torvalds ecard_set_drvdata(ec, host);
5201da177e4SLinus Torvalds
5211da177e4SLinus Torvalds info = (struct eesoxscsi_info *)host->hostdata;
5221da177e4SLinus Torvalds info->ec = ec;
5231da177e4SLinus Torvalds info->base = base;
5241da177e4SLinus Torvalds info->ctl_port = base + EESOX_CONTROL;
5251da177e4SLinus Torvalds info->control = term[ec->slot_no] ? EESOX_TERM_ENABLE : 0;
5261da177e4SLinus Torvalds writeb(info->control, info->ctl_port);
5271da177e4SLinus Torvalds
5281da177e4SLinus Torvalds info->info.scsi.io_base = base + EESOX_FAS216_OFFSET;
5291da177e4SLinus Torvalds info->info.scsi.io_shift = EESOX_FAS216_SHIFT;
5301da177e4SLinus Torvalds info->info.scsi.irq = ec->irq;
5311da177e4SLinus Torvalds info->info.scsi.dma = ec->dma;
5321da177e4SLinus Torvalds info->info.ifcfg.clockrate = 40; /* MHz */
5331da177e4SLinus Torvalds info->info.ifcfg.select_timeout = 255;
5341da177e4SLinus Torvalds info->info.ifcfg.asyncperiod = 200; /* ns */
5351da177e4SLinus Torvalds info->info.ifcfg.sync_max_depth = 7;
5361da177e4SLinus Torvalds info->info.ifcfg.cntl3 = CNTL3_FASTSCSI | CNTL3_FASTCLK;
5371da177e4SLinus Torvalds info->info.ifcfg.disconnect_ok = 1;
5381da177e4SLinus Torvalds info->info.ifcfg.wide_max_size = 0;
5391da177e4SLinus Torvalds info->info.ifcfg.capabilities = FASCAP_PSEUDODMA;
5401da177e4SLinus Torvalds info->info.dma.setup = eesoxscsi_dma_setup;
5411da177e4SLinus Torvalds info->info.dma.pseudo = eesoxscsi_dma_pseudo;
5421da177e4SLinus Torvalds info->info.dma.stop = eesoxscsi_dma_stop;
5431da177e4SLinus Torvalds
5441da177e4SLinus Torvalds ec->irqaddr = base + EESOX_DMASTAT;
5451da177e4SLinus Torvalds ec->irqmask = EESOX_STAT_INTR;
546c7b87f3dSRussell King
547c7b87f3dSRussell King ecard_setirq(ec, &eesoxscsi_ops, info);
5481da177e4SLinus Torvalds
5491da177e4SLinus Torvalds device_create_file(&ec->dev, &dev_attr_bus_term);
5501da177e4SLinus Torvalds
5511da177e4SLinus Torvalds ret = fas216_init(host);
5521da177e4SLinus Torvalds if (ret)
5531da177e4SLinus Torvalds goto out_free;
5541da177e4SLinus Torvalds
5551da177e4SLinus Torvalds ret = request_irq(ec->irq, eesoxscsi_intr, 0, "eesoxscsi", info);
5561da177e4SLinus Torvalds if (ret) {
5571da177e4SLinus Torvalds printk("scsi%d: IRQ%d not free: %d\n",
5581da177e4SLinus Torvalds host->host_no, ec->irq, ret);
5591da177e4SLinus Torvalds goto out_remove;
5601da177e4SLinus Torvalds }
5611da177e4SLinus Torvalds
5621da177e4SLinus Torvalds if (info->info.scsi.dma != NO_DMA) {
5631da177e4SLinus Torvalds if (request_dma(info->info.scsi.dma, "eesox")) {
5641da177e4SLinus Torvalds printk("scsi%d: DMA%d not free, DMA disabled\n",
5651da177e4SLinus Torvalds host->host_no, info->info.scsi.dma);
5661da177e4SLinus Torvalds info->info.scsi.dma = NO_DMA;
5671da177e4SLinus Torvalds } else {
5681da177e4SLinus Torvalds set_dma_speed(info->info.scsi.dma, 180);
5691da177e4SLinus Torvalds info->info.ifcfg.capabilities |= FASCAP_DMA;
5701da177e4SLinus Torvalds info->info.ifcfg.cntl3 |= CNTL3_BS8;
5711da177e4SLinus Torvalds }
5721da177e4SLinus Torvalds }
5731da177e4SLinus Torvalds
5741da177e4SLinus Torvalds ret = fas216_add(host, &ec->dev);
5751da177e4SLinus Torvalds if (ret == 0)
5761da177e4SLinus Torvalds goto out;
5771da177e4SLinus Torvalds
5781da177e4SLinus Torvalds if (info->info.scsi.dma != NO_DMA)
5791da177e4SLinus Torvalds free_dma(info->info.scsi.dma);
58086f2da11SChristophe JAILLET free_irq(ec->irq, info);
5811da177e4SLinus Torvalds
5821da177e4SLinus Torvalds out_remove:
5831da177e4SLinus Torvalds fas216_remove(host);
5841da177e4SLinus Torvalds
5851da177e4SLinus Torvalds out_free:
5861da177e4SLinus Torvalds device_remove_file(&ec->dev, &dev_attr_bus_term);
5871da177e4SLinus Torvalds scsi_host_put(host);
5881da177e4SLinus Torvalds
5891da177e4SLinus Torvalds out_region:
5901da177e4SLinus Torvalds ecard_release_resources(ec);
5911da177e4SLinus Torvalds
5921da177e4SLinus Torvalds out:
5931da177e4SLinus Torvalds return ret;
5941da177e4SLinus Torvalds }
5951da177e4SLinus Torvalds
eesoxscsi_remove(struct expansion_card * ec)5966f039790SGreg Kroah-Hartman static void eesoxscsi_remove(struct expansion_card *ec)
5971da177e4SLinus Torvalds {
5981da177e4SLinus Torvalds struct Scsi_Host *host = ecard_get_drvdata(ec);
5991da177e4SLinus Torvalds struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
6001da177e4SLinus Torvalds
6011da177e4SLinus Torvalds ecard_set_drvdata(ec, NULL);
6021da177e4SLinus Torvalds fas216_remove(host);
6031da177e4SLinus Torvalds
6041da177e4SLinus Torvalds if (info->info.scsi.dma != NO_DMA)
6051da177e4SLinus Torvalds free_dma(info->info.scsi.dma);
6061da177e4SLinus Torvalds free_irq(ec->irq, info);
6071da177e4SLinus Torvalds
6081da177e4SLinus Torvalds device_remove_file(&ec->dev, &dev_attr_bus_term);
6091da177e4SLinus Torvalds
6101da177e4SLinus Torvalds fas216_release(host);
6111da177e4SLinus Torvalds scsi_host_put(host);
6121da177e4SLinus Torvalds ecard_release_resources(ec);
6131da177e4SLinus Torvalds }
6141da177e4SLinus Torvalds
6151da177e4SLinus Torvalds static const struct ecard_id eesoxscsi_cids[] = {
6161da177e4SLinus Torvalds { MANU_EESOX, PROD_EESOX_SCSI2 },
6171da177e4SLinus Torvalds { 0xffff, 0xffff },
6181da177e4SLinus Torvalds };
6191da177e4SLinus Torvalds
6201da177e4SLinus Torvalds static struct ecard_driver eesoxscsi_driver = {
6211da177e4SLinus Torvalds .probe = eesoxscsi_probe,
6226f039790SGreg Kroah-Hartman .remove = eesoxscsi_remove,
6231da177e4SLinus Torvalds .id_table = eesoxscsi_cids,
6241da177e4SLinus Torvalds .drv = {
6251da177e4SLinus Torvalds .name = "eesoxscsi",
6261da177e4SLinus Torvalds },
6271da177e4SLinus Torvalds };
6281da177e4SLinus Torvalds
eesox_init(void)6291da177e4SLinus Torvalds static int __init eesox_init(void)
6301da177e4SLinus Torvalds {
6311da177e4SLinus Torvalds return ecard_register_driver(&eesoxscsi_driver);
6321da177e4SLinus Torvalds }
6331da177e4SLinus Torvalds
eesox_exit(void)6341da177e4SLinus Torvalds static void __exit eesox_exit(void)
6351da177e4SLinus Torvalds {
6361da177e4SLinus Torvalds ecard_remove_driver(&eesoxscsi_driver);
6371da177e4SLinus Torvalds }
6381da177e4SLinus Torvalds
6391da177e4SLinus Torvalds module_init(eesox_init);
6401da177e4SLinus Torvalds module_exit(eesox_exit);
6411da177e4SLinus Torvalds
6421da177e4SLinus Torvalds MODULE_AUTHOR("Russell King");
6431da177e4SLinus Torvalds MODULE_DESCRIPTION("EESOX 'Fast' SCSI driver for Acorn machines");
6448d3b33f6SRusty Russell module_param_array(term, int, NULL, 0);
6451da177e4SLinus Torvalds MODULE_PARM_DESC(term, "SCSI bus termination");
6461da177e4SLinus Torvalds MODULE_LICENSE("GPL");
647