Thomas Gleixner | 09c434b | 2019-05-19 13:08:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | #include <linux/init.h> |
| 4 | #include <linux/interrupt.h> |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 5 | #include <linux/mm.h> |
| 6 | #include <linux/slab.h> |
| 7 | #include <linux/spinlock.h> |
| 8 | #include <linux/zorro.h> |
Paul Gortmaker | acf3368f | 2011-05-27 09:47:43 -0400 | [diff] [blame] | 9 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <asm/page.h> |
| 12 | #include <asm/pgtable.h> |
| 13 | #include <asm/amigaints.h> |
| 14 | #include <asm/amigahw.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | #include "scsi.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include "wd33c93.h" |
| 18 | #include "gvp11.h" |
| 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Geert Uytterhoeven | 11ca46e | 2009-05-17 20:44:16 +0200 | [diff] [blame] | 21 | #define CHECK_WD33C93 |
| 22 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 23 | struct gvp11_hostdata { |
| 24 | struct WD33C93_hostdata wh; |
| 25 | struct gvp11_scsiregs *regs; |
| 26 | }; |
| 27 | |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 28 | static irqreturn_t gvp11_intr(int irq, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | { |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 30 | struct Scsi_Host *instance = data; |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 31 | struct gvp11_hostdata *hdata = shost_priv(instance); |
| 32 | unsigned int status = hdata->regs->CNTR; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 33 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 35 | if (!(status & GVP11_DMAC_INT_PENDING)) |
| 36 | return IRQ_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 38 | spin_lock_irqsave(instance->host_lock, flags); |
| 39 | wd33c93_intr(instance); |
| 40 | spin_unlock_irqrestore(instance->host_lock, flags); |
| 41 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | static int gvp11_xfer_mask = 0; |
| 45 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 46 | void gvp11_setup(char *str, int *ints) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 48 | gvp11_xfer_mask = ints[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Henrik Kretzschmar | 6539641 | 2006-09-12 23:49:33 +0200 | [diff] [blame] | 51 | static int dma_setup(struct scsi_cmnd *cmd, int dir_in) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 53 | struct Scsi_Host *instance = cmd->device->host; |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 54 | struct gvp11_hostdata *hdata = shost_priv(instance); |
| 55 | struct WD33C93_hostdata *wh = &hdata->wh; |
| 56 | struct gvp11_scsiregs *regs = hdata->regs; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 57 | unsigned short cntr = GVP11_DMAC_INT_ENABLE; |
| 58 | unsigned long addr = virt_to_bus(cmd->SCp.ptr); |
| 59 | int bank_mask; |
| 60 | static int scsi_alloc_out_of_range = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 62 | /* use bounce buffer if the physical address is bad */ |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 63 | if (addr & wh->dma_xfer_mask) { |
| 64 | wh->dma_bounce_len = (cmd->SCp.this_residual + 511) & ~0x1ff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 66 | if (!scsi_alloc_out_of_range) { |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 67 | wh->dma_bounce_buffer = |
| 68 | kmalloc(wh->dma_bounce_len, GFP_KERNEL); |
| 69 | wh->dma_buffer_pool = BUF_SCSI_ALLOCED; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 70 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 72 | if (scsi_alloc_out_of_range || |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 73 | !wh->dma_bounce_buffer) { |
| 74 | wh->dma_bounce_buffer = |
| 75 | amiga_chip_alloc(wh->dma_bounce_len, |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 76 | "GVP II SCSI Bounce Buffer"); |
| 77 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 78 | if (!wh->dma_bounce_buffer) { |
| 79 | wh->dma_bounce_len = 0; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 80 | return 1; |
| 81 | } |
| 82 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 83 | wh->dma_buffer_pool = BUF_CHIP_ALLOCED; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | /* check if the address of the bounce buffer is OK */ |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 87 | addr = virt_to_bus(wh->dma_bounce_buffer); |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 88 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 89 | if (addr & wh->dma_xfer_mask) { |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 90 | /* fall back to Chip RAM if address out of range */ |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 91 | if (wh->dma_buffer_pool == BUF_SCSI_ALLOCED) { |
| 92 | kfree(wh->dma_bounce_buffer); |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 93 | scsi_alloc_out_of_range = 1; |
| 94 | } else { |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 95 | amiga_chip_free(wh->dma_bounce_buffer); |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 96 | } |
| 97 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 98 | wh->dma_bounce_buffer = |
| 99 | amiga_chip_alloc(wh->dma_bounce_len, |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 100 | "GVP II SCSI Bounce Buffer"); |
| 101 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 102 | if (!wh->dma_bounce_buffer) { |
| 103 | wh->dma_bounce_len = 0; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 104 | return 1; |
| 105 | } |
| 106 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 107 | addr = virt_to_bus(wh->dma_bounce_buffer); |
| 108 | wh->dma_buffer_pool = BUF_CHIP_ALLOCED; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | if (!dir_in) { |
| 112 | /* copy to bounce buffer for a write */ |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 113 | memcpy(wh->dma_bounce_buffer, cmd->SCp.ptr, |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 114 | cmd->SCp.this_residual); |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 115 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 117 | |
| 118 | /* setup dma direction */ |
| 119 | if (!dir_in) |
| 120 | cntr |= GVP11_DMAC_DIR_WRITE; |
| 121 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 122 | wh->dma_dir = dir_in; |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 123 | regs->CNTR = cntr; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 124 | |
| 125 | /* setup DMA *physical* address */ |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 126 | regs->ACR = addr; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 127 | |
| 128 | if (dir_in) { |
| 129 | /* invalidate any cache */ |
| 130 | cache_clear(addr, cmd->SCp.this_residual); |
| 131 | } else { |
| 132 | /* push any dirty cache */ |
| 133 | cache_push(addr, cmd->SCp.this_residual); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 136 | bank_mask = (~wh->dma_xfer_mask >> 18) & 0x01c0; |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 137 | if (bank_mask) |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 138 | regs->BANK = bank_mask & (addr >> 18); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 140 | /* start DMA */ |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 141 | regs->ST_DMA = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 143 | /* return success */ |
| 144 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Henrik Kretzschmar | 6539641 | 2006-09-12 23:49:33 +0200 | [diff] [blame] | 147 | static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt, |
| 148 | int status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | { |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 150 | struct gvp11_hostdata *hdata = shost_priv(instance); |
| 151 | struct WD33C93_hostdata *wh = &hdata->wh; |
| 152 | struct gvp11_scsiregs *regs = hdata->regs; |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 153 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 154 | /* stop DMA */ |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 155 | regs->SP_DMA = 1; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 156 | /* remove write bit from CONTROL bits */ |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 157 | regs->CNTR = GVP11_DMAC_INT_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 159 | /* copy from a bounce buffer, if necessary */ |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 160 | if (status && wh->dma_bounce_buffer) { |
| 161 | if (wh->dma_dir && SCpnt) |
| 162 | memcpy(SCpnt->SCp.ptr, wh->dma_bounce_buffer, |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 163 | SCpnt->SCp.this_residual); |
| 164 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 165 | if (wh->dma_buffer_pool == BUF_SCSI_ALLOCED) |
| 166 | kfree(wh->dma_bounce_buffer); |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 167 | else |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 168 | amiga_chip_free(wh->dma_bounce_buffer); |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 169 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 170 | wh->dma_bounce_buffer = NULL; |
| 171 | wh->dma_bounce_len = 0; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 172 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 175 | static struct scsi_host_template gvp11_scsi_template = { |
| 176 | .module = THIS_MODULE, |
| 177 | .name = "GVP Series II SCSI", |
Al Viro | 408bb25 | 2013-03-31 00:30:35 -0400 | [diff] [blame] | 178 | .show_info = wd33c93_show_info, |
| 179 | .write_info = wd33c93_write_info, |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 180 | .proc_name = "GVP11", |
| 181 | .queuecommand = wd33c93_queuecommand, |
| 182 | .eh_abort_handler = wd33c93_abort, |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 183 | .eh_host_reset_handler = wd33c93_host_reset, |
| 184 | .can_queue = CAN_QUEUE, |
| 185 | .this_id = 7, |
| 186 | .sg_tablesize = SG_ALL, |
| 187 | .cmd_per_lun = CMD_PER_LUN, |
Christoph Hellwig | 4af14d1 | 2018-12-13 16:17:09 +0100 | [diff] [blame] | 188 | .dma_boundary = PAGE_SIZE - 1, |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 189 | }; |
| 190 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 191 | static int check_wd33c93(struct gvp11_scsiregs *regs) |
Geert Uytterhoeven | 11ca46e | 2009-05-17 20:44:16 +0200 | [diff] [blame] | 192 | { |
| 193 | #ifdef CHECK_WD33C93 |
| 194 | volatile unsigned char *sasr_3393, *scmd_3393; |
| 195 | unsigned char save_sasr; |
| 196 | unsigned char q, qq; |
| 197 | |
| 198 | /* |
| 199 | * These darn GVP boards are a problem - it can be tough to tell |
| 200 | * whether or not they include a SCSI controller. This is the |
| 201 | * ultimate Yet-Another-GVP-Detection-Hack in that it actually |
| 202 | * probes for a WD33c93 chip: If we find one, it's extremely |
| 203 | * likely that this card supports SCSI, regardless of Product_ |
| 204 | * Code, Board_Size, etc. |
| 205 | */ |
| 206 | |
| 207 | /* Get pointers to the presumed register locations and save contents */ |
| 208 | |
| 209 | sasr_3393 = ®s->SASR; |
| 210 | scmd_3393 = ®s->SCMD; |
| 211 | save_sasr = *sasr_3393; |
| 212 | |
| 213 | /* First test the AuxStatus Reg */ |
| 214 | |
| 215 | q = *sasr_3393; /* read it */ |
| 216 | if (q & 0x08) /* bit 3 should always be clear */ |
| 217 | return -ENODEV; |
| 218 | *sasr_3393 = WD_AUXILIARY_STATUS; /* setup indirect address */ |
| 219 | if (*sasr_3393 == WD_AUXILIARY_STATUS) { /* shouldn't retain the write */ |
| 220 | *sasr_3393 = save_sasr; /* Oops - restore this byte */ |
| 221 | return -ENODEV; |
| 222 | } |
| 223 | if (*sasr_3393 != q) { /* should still read the same */ |
| 224 | *sasr_3393 = save_sasr; /* Oops - restore this byte */ |
| 225 | return -ENODEV; |
| 226 | } |
| 227 | if (*scmd_3393 != q) /* and so should the image at 0x1f */ |
| 228 | return -ENODEV; |
| 229 | |
| 230 | /* |
| 231 | * Ok, we probably have a wd33c93, but let's check a few other places |
| 232 | * for good measure. Make sure that this works for both 'A and 'B |
| 233 | * chip versions. |
| 234 | */ |
| 235 | |
| 236 | *sasr_3393 = WD_SCSI_STATUS; |
| 237 | q = *scmd_3393; |
| 238 | *sasr_3393 = WD_SCSI_STATUS; |
| 239 | *scmd_3393 = ~q; |
| 240 | *sasr_3393 = WD_SCSI_STATUS; |
| 241 | qq = *scmd_3393; |
| 242 | *sasr_3393 = WD_SCSI_STATUS; |
| 243 | *scmd_3393 = q; |
| 244 | if (qq != q) /* should be read only */ |
| 245 | return -ENODEV; |
| 246 | *sasr_3393 = 0x1e; /* this register is unimplemented */ |
| 247 | q = *scmd_3393; |
| 248 | *sasr_3393 = 0x1e; |
| 249 | *scmd_3393 = ~q; |
| 250 | *sasr_3393 = 0x1e; |
| 251 | qq = *scmd_3393; |
| 252 | *sasr_3393 = 0x1e; |
| 253 | *scmd_3393 = q; |
| 254 | if (qq != q || qq != 0xff) /* should be read only, all 1's */ |
| 255 | return -ENODEV; |
| 256 | *sasr_3393 = WD_TIMEOUT_PERIOD; |
| 257 | q = *scmd_3393; |
| 258 | *sasr_3393 = WD_TIMEOUT_PERIOD; |
| 259 | *scmd_3393 = ~q; |
| 260 | *sasr_3393 = WD_TIMEOUT_PERIOD; |
| 261 | qq = *scmd_3393; |
| 262 | *sasr_3393 = WD_TIMEOUT_PERIOD; |
| 263 | *scmd_3393 = q; |
| 264 | if (qq != (~q & 0xff)) /* should be read/write */ |
| 265 | return -ENODEV; |
| 266 | #endif /* CHECK_WD33C93 */ |
| 267 | |
| 268 | return 0; |
| 269 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 271 | static int gvp11_probe(struct zorro_dev *z, const struct zorro_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | { |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 273 | struct Scsi_Host *instance; |
| 274 | unsigned long address; |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 275 | int error; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 276 | unsigned int epc; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 277 | unsigned int default_dma_xfer_mask; |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 278 | struct gvp11_hostdata *hdata; |
Geert Uytterhoeven | 349d65f | 2009-05-17 21:05:55 +0200 | [diff] [blame] | 279 | struct gvp11_scsiregs *regs; |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 280 | wd33c93_regs wdregs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 282 | default_dma_xfer_mask = ent->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 284 | /* |
| 285 | * Rumors state that some GVP ram boards use the same product |
| 286 | * code as the SCSI controllers. Therefore if the board-size |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 287 | * is not 64KB we assume it is a ram board and bail out. |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 288 | */ |
| 289 | if (zorro_resource_len(z) != 0x10000) |
| 290 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 292 | address = z->resource.start; |
| 293 | if (!request_mem_region(address, 256, "wd33c93")) |
| 294 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
Geert Uytterhoeven | 6112ea0 | 2011-01-09 11:03:43 +0100 | [diff] [blame] | 296 | regs = ZTWO_VADDR(address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 298 | error = check_wd33c93(regs); |
| 299 | if (error) |
| 300 | goto fail_check_or_alloc; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 301 | |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 302 | instance = scsi_host_alloc(&gvp11_scsi_template, |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 303 | sizeof(struct gvp11_hostdata)); |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 304 | if (!instance) { |
| 305 | error = -ENOMEM; |
| 306 | goto fail_check_or_alloc; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 307 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 309 | instance->irq = IRQ_AMIGA_PORTS; |
| 310 | instance->unique_id = z->slotaddr; |
| 311 | |
| 312 | regs->secret2 = 1; |
| 313 | regs->secret1 = 0; |
| 314 | regs->secret3 = 15; |
| 315 | while (regs->CNTR & GVP11_DMAC_BUSY) |
| 316 | ; |
| 317 | regs->CNTR = 0; |
| 318 | regs->BANK = 0; |
| 319 | |
| 320 | wdregs.SASR = ®s->SASR; |
| 321 | wdregs.SCMD = ®s->SCMD; |
| 322 | |
| 323 | hdata = shost_priv(instance); |
| 324 | if (gvp11_xfer_mask) |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 325 | hdata->wh.dma_xfer_mask = gvp11_xfer_mask; |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 326 | else |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 327 | hdata->wh.dma_xfer_mask = default_dma_xfer_mask; |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 328 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 329 | hdata->wh.no_sync = 0xff; |
| 330 | hdata->wh.fast = 0; |
| 331 | hdata->wh.dma_mode = CTRL_DMA; |
| 332 | hdata->regs = regs; |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 333 | |
| 334 | /* |
| 335 | * Check for 14MHz SCSI clock |
| 336 | */ |
| 337 | epc = *(unsigned short *)(ZTWO_VADDR(address) + 0x8000); |
| 338 | wd33c93_init(instance, wdregs, dma_setup, dma_stop, |
| 339 | (epc & GVP_SCSICLKMASK) ? WD33C93_FS_8_10 |
| 340 | : WD33C93_FS_12_15); |
| 341 | |
| 342 | error = request_irq(IRQ_AMIGA_PORTS, gvp11_intr, IRQF_SHARED, |
| 343 | "GVP11 SCSI", instance); |
| 344 | if (error) |
| 345 | goto fail_irq; |
| 346 | |
| 347 | regs->CNTR = GVP11_DMAC_INT_ENABLE; |
| 348 | |
| 349 | error = scsi_add_host(instance, NULL); |
| 350 | if (error) |
| 351 | goto fail_host; |
| 352 | |
| 353 | zorro_set_drvdata(z, instance); |
| 354 | scsi_scan_host(instance); |
| 355 | return 0; |
| 356 | |
| 357 | fail_host: |
| 358 | free_irq(IRQ_AMIGA_PORTS, instance); |
| 359 | fail_irq: |
| 360 | scsi_host_put(instance); |
| 361 | fail_check_or_alloc: |
| 362 | release_mem_region(address, 256); |
| 363 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 366 | static void gvp11_remove(struct zorro_dev *z) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | { |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 368 | struct Scsi_Host *instance = zorro_get_drvdata(z); |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 369 | struct gvp11_hostdata *hdata = shost_priv(instance); |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 370 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 371 | hdata->regs->CNTR = 0; |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 372 | scsi_remove_host(instance); |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 373 | free_irq(IRQ_AMIGA_PORTS, instance); |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 374 | scsi_host_put(instance); |
| 375 | release_mem_region(z->resource.start, 256); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | } |
| 377 | |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 378 | /* |
| 379 | * This should (hopefully) be the correct way to identify |
| 380 | * all the different GVP SCSI controllers (except for the |
| 381 | * SERIES I though). |
| 382 | */ |
| 383 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 384 | static struct zorro_device_id gvp11_zorro_tbl[] = { |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 385 | { ZORRO_PROD_GVP_COMBO_030_R3_SCSI, ~0x00ffffff }, |
| 386 | { ZORRO_PROD_GVP_SERIES_II, ~0x00ffffff }, |
| 387 | { ZORRO_PROD_GVP_GFORCE_030_SCSI, ~0x01ffffff }, |
| 388 | { ZORRO_PROD_GVP_A530_SCSI, ~0x01ffffff }, |
| 389 | { ZORRO_PROD_GVP_COMBO_030_R4_SCSI, ~0x01ffffff }, |
| 390 | { ZORRO_PROD_GVP_A1291, ~0x07ffffff }, |
| 391 | { ZORRO_PROD_GVP_GFORCE_040_SCSI_1, ~0x07ffffff }, |
| 392 | { 0 } |
| 393 | }; |
| 394 | MODULE_DEVICE_TABLE(zorro, gvp11_zorro_tbl); |
| 395 | |
| 396 | static struct zorro_driver gvp11_driver = { |
| 397 | .name = "gvp11", |
| 398 | .id_table = gvp11_zorro_tbl, |
| 399 | .probe = gvp11_probe, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 400 | .remove = gvp11_remove, |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 401 | }; |
| 402 | |
| 403 | static int __init gvp11_init(void) |
| 404 | { |
| 405 | return zorro_register_driver(&gvp11_driver); |
| 406 | } |
| 407 | module_init(gvp11_init); |
| 408 | |
| 409 | static void __exit gvp11_exit(void) |
| 410 | { |
| 411 | zorro_unregister_driver(&gvp11_driver); |
| 412 | } |
| 413 | module_exit(gvp11_exit); |
| 414 | |
| 415 | MODULE_DESCRIPTION("GVP Series II SCSI"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | MODULE_LICENSE("GPL"); |