Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * atari_scsi.c -- Device dependent functions for the Atari generic SCSI port |
| 3 | * |
| 4 | * Copyright 1994 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> |
| 5 | * |
| 6 | * Loosely based on the work of Robert De Vries' team and added: |
| 7 | * - working real DMA |
| 8 | * - Falcon support (untested yet!) ++bjoern fixed and now it works |
| 9 | * - lots of extensions and bug fixes. |
| 10 | * |
| 11 | * This file is subject to the terms and conditions of the GNU General Public |
| 12 | * License. See the file COPYING in the main directory of this archive |
| 13 | * for more details. |
| 14 | * |
| 15 | */ |
| 16 | |
| 17 | |
| 18 | /**************************************************************************/ |
| 19 | /* */ |
| 20 | /* Notes for Falcon SCSI: */ |
| 21 | /* ---------------------- */ |
| 22 | /* */ |
| 23 | /* Since the Falcon SCSI uses the ST-DMA chip, that is shared among */ |
| 24 | /* several device drivers, locking and unlocking the access to this */ |
| 25 | /* chip is required. But locking is not possible from an interrupt, */ |
| 26 | /* since it puts the process to sleep if the lock is not available. */ |
| 27 | /* This prevents "late" locking of the DMA chip, i.e. locking it just */ |
| 28 | /* before using it, since in case of disconnection-reconnection */ |
| 29 | /* commands, the DMA is started from the reselection interrupt. */ |
| 30 | /* */ |
| 31 | /* Two possible schemes for ST-DMA-locking would be: */ |
| 32 | /* 1) The lock is taken for each command separately and disconnecting */ |
| 33 | /* is forbidden (i.e. can_queue = 1). */ |
| 34 | /* 2) The DMA chip is locked when the first command comes in and */ |
| 35 | /* released when the last command is finished and all queues are */ |
| 36 | /* empty. */ |
| 37 | /* The first alternative would result in bad performance, since the */ |
| 38 | /* interleaving of commands would not be used. The second is unfair to */ |
| 39 | /* other drivers using the ST-DMA, because the queues will seldom be */ |
| 40 | /* totally empty if there is a lot of disk traffic. */ |
| 41 | /* */ |
| 42 | /* For this reasons I decided to employ a more elaborate scheme: */ |
| 43 | /* - First, we give up the lock every time we can (for fairness), this */ |
| 44 | /* means every time a command finishes and there are no other commands */ |
| 45 | /* on the disconnected queue. */ |
| 46 | /* - If there are others waiting to lock the DMA chip, we stop */ |
| 47 | /* issuing commands, i.e. moving them onto the issue queue. */ |
| 48 | /* Because of that, the disconnected queue will run empty in a */ |
| 49 | /* while. Instead we go to sleep on a 'fairness_queue'. */ |
| 50 | /* - If the lock is released, all processes waiting on the fairness */ |
| 51 | /* queue will be woken. The first of them tries to re-lock the DMA, */ |
| 52 | /* the others wait for the first to finish this task. After that, */ |
| 53 | /* they can all run on and do their commands... */ |
| 54 | /* This sounds complicated (and it is it :-(), but it seems to be a */ |
| 55 | /* good compromise between fairness and performance: As long as no one */ |
| 56 | /* else wants to work with the ST-DMA chip, SCSI can go along as */ |
| 57 | /* usual. If now someone else comes, this behaviour is changed to a */ |
| 58 | /* "fairness mode": just already initiated commands are finished and */ |
| 59 | /* then the lock is released. The other one waiting will probably win */ |
| 60 | /* the race for locking the DMA, since it was waiting for longer. And */ |
| 61 | /* after it has finished, SCSI can go ahead again. Finally: I hope I */ |
| 62 | /* have not produced any deadlock possibilities! */ |
| 63 | /* */ |
| 64 | /**************************************************************************/ |
| 65 | |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | #include <linux/blkdev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | #include <linux/interrupt.h> |
| 71 | #include <linux/init.h> |
| 72 | #include <linux/nvram.h> |
| 73 | #include <linux/bitops.h> |
Arnd Bergmann | eff9cf8 | 2014-03-01 20:51:03 +1300 | [diff] [blame] | 74 | #include <linux/wait.h> |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 75 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | #include <asm/setup.h> |
| 78 | #include <asm/atarihw.h> |
| 79 | #include <asm/atariints.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | #include <asm/atari_stdma.h> |
| 81 | #include <asm/atari_stram.h> |
| 82 | #include <asm/io.h> |
| 83 | |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 84 | #include <scsi/scsi_host.h> |
| 85 | |
Finn Thain | e63449c | 2016-03-23 21:10:13 +1100 | [diff] [blame] | 86 | #define DMA_MIN_SIZE 32 |
| 87 | |
Finn Thain | 4e70520 | 2014-11-12 16:12:10 +1100 | [diff] [blame] | 88 | /* Definitions for the core NCR5380 driver. */ |
| 89 | |
Finn Thain | 4e70520 | 2014-11-12 16:12:10 +1100 | [diff] [blame] | 90 | #define NCR5380_implementation_fields /* none */ |
| 91 | |
| 92 | #define NCR5380_read(reg) atari_scsi_reg_read(reg) |
| 93 | #define NCR5380_write(reg, value) atari_scsi_reg_write(reg, value) |
| 94 | |
| 95 | #define NCR5380_queue_command atari_scsi_queue_command |
| 96 | #define NCR5380_abort atari_scsi_abort |
Finn Thain | 4e70520 | 2014-11-12 16:12:10 +1100 | [diff] [blame] | 97 | #define NCR5380_info atari_scsi_info |
| 98 | |
Finn Thain | 52d3e56 | 2016-03-23 21:10:20 +1100 | [diff] [blame] | 99 | #define NCR5380_dma_recv_setup(instance, data, count) \ |
Finn Thain | 4e70520 | 2014-11-12 16:12:10 +1100 | [diff] [blame] | 100 | atari_scsi_dma_setup(instance, data, count, 0) |
Finn Thain | 52d3e56 | 2016-03-23 21:10:20 +1100 | [diff] [blame] | 101 | #define NCR5380_dma_send_setup(instance, data, count) \ |
Finn Thain | 4e70520 | 2014-11-12 16:12:10 +1100 | [diff] [blame] | 102 | atari_scsi_dma_setup(instance, data, count, 1) |
| 103 | #define NCR5380_dma_residual(instance) \ |
| 104 | atari_scsi_dma_residual(instance) |
| 105 | #define NCR5380_dma_xfer_len(instance, cmd, phase) \ |
| 106 | atari_dma_xfer_len(cmd->SCp.this_residual, cmd, !((phase) & SR_IO)) |
| 107 | |
Finn Thain | a53a21e | 2014-11-12 16:12:21 +1100 | [diff] [blame] | 108 | #define NCR5380_acquire_dma_irq(instance) falcon_get_lock(instance) |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 109 | #define NCR5380_release_dma_irq(instance) falcon_release_lock() |
| 110 | |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 111 | #include "NCR5380.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Finn Thain | 4e70520 | 2014-11-12 16:12:10 +1100 | [diff] [blame] | 113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | #define IS_A_TT() ATARIHW_PRESENT(TT_SCSI) |
| 115 | |
| 116 | #define SCSI_DMA_WRITE_P(elt,val) \ |
| 117 | do { \ |
| 118 | unsigned long v = val; \ |
| 119 | tt_scsi_dma.elt##_lo = v & 0xff; \ |
| 120 | v >>= 8; \ |
| 121 | tt_scsi_dma.elt##_lmd = v & 0xff; \ |
| 122 | v >>= 8; \ |
| 123 | tt_scsi_dma.elt##_hmd = v & 0xff; \ |
| 124 | v >>= 8; \ |
| 125 | tt_scsi_dma.elt##_hi = v & 0xff; \ |
| 126 | } while(0) |
| 127 | |
| 128 | #define SCSI_DMA_READ_P(elt) \ |
| 129 | (((((((unsigned long)tt_scsi_dma.elt##_hi << 8) | \ |
| 130 | (unsigned long)tt_scsi_dma.elt##_hmd) << 8) | \ |
| 131 | (unsigned long)tt_scsi_dma.elt##_lmd) << 8) | \ |
| 132 | (unsigned long)tt_scsi_dma.elt##_lo) |
| 133 | |
| 134 | |
| 135 | static inline void SCSI_DMA_SETADR(unsigned long adr) |
| 136 | { |
| 137 | st_dma.dma_lo = (unsigned char)adr; |
| 138 | MFPDELAY(); |
| 139 | adr >>= 8; |
| 140 | st_dma.dma_md = (unsigned char)adr; |
| 141 | MFPDELAY(); |
| 142 | adr >>= 8; |
| 143 | st_dma.dma_hi = (unsigned char)adr; |
| 144 | MFPDELAY(); |
| 145 | } |
| 146 | |
| 147 | static inline unsigned long SCSI_DMA_GETADR(void) |
| 148 | { |
| 149 | unsigned long adr; |
| 150 | adr = st_dma.dma_lo; |
| 151 | MFPDELAY(); |
| 152 | adr |= (st_dma.dma_md & 0xff) << 8; |
| 153 | MFPDELAY(); |
| 154 | adr |= (st_dma.dma_hi & 0xff) << 16; |
| 155 | MFPDELAY(); |
| 156 | return adr; |
| 157 | } |
| 158 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 159 | static void atari_scsi_fetch_restbytes(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 161 | static unsigned char (*atari_scsi_reg_read)(unsigned char reg); |
| 162 | static void (*atari_scsi_reg_write)(unsigned char reg, unsigned char value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | static unsigned long atari_dma_residual, atari_dma_startaddr; |
| 165 | static short atari_dma_active; |
| 166 | /* pointer to the dribble buffer */ |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 167 | static char *atari_dma_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | /* precalculated physical address of the dribble buffer */ |
| 169 | static unsigned long atari_dma_phys_buffer; |
| 170 | /* != 0 tells the Falcon int handler to copy data from the dribble buffer */ |
| 171 | static char *atari_dma_orig_addr; |
| 172 | /* size of the dribble buffer; 4k seems enough, since the Falcon cannot use |
| 173 | * scatter-gather anyway, so most transfers are 1024 byte only. In the rare |
| 174 | * cases where requests to physical contiguous buffers have been merged, this |
| 175 | * request is <= 4k (one page). So I don't think we have to split transfers |
| 176 | * just due to this buffer size... |
| 177 | */ |
| 178 | #define STRAM_BUFFER_SIZE (4096) |
| 179 | /* mask for address bits that can't be used with the ST-DMA */ |
| 180 | static unsigned long atari_dma_stram_mask; |
| 181 | #define STRAM_ADDR(a) (((a) & atari_dma_stram_mask) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
| 183 | static int setup_can_queue = -1; |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 184 | module_param(setup_can_queue, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | static int setup_cmd_per_lun = -1; |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 186 | module_param(setup_cmd_per_lun, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | static int setup_sg_tablesize = -1; |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 188 | module_param(setup_sg_tablesize, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | static int setup_hostid = -1; |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame] | 190 | module_param(setup_hostid, int, 0); |
Finn Thain | 9c3f0e2 | 2016-01-03 16:05:11 +1100 | [diff] [blame] | 191 | static int setup_toshiba_delay = -1; |
| 192 | module_param(setup_toshiba_delay, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
| 194 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 195 | static int scsi_dma_is_ignored_buserr(unsigned char dma_stat) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
| 197 | int i; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 198 | unsigned long addr = SCSI_DMA_READ_P(dma_addr), end_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | if (dma_stat & 0x01) { |
| 201 | |
| 202 | /* A bus error happens when DMA-ing from the last page of a |
| 203 | * physical memory chunk (DMA prefetch!), but that doesn't hurt. |
| 204 | * Check for this case: |
| 205 | */ |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 206 | |
| 207 | for (i = 0; i < m68k_num_memory; ++i) { |
| 208 | end_addr = m68k_memory[i].addr + m68k_memory[i].size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | if (end_addr <= addr && addr <= end_addr + 4) |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 210 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | } |
| 212 | } |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 213 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | |
| 217 | #if 0 |
| 218 | /* Dead code... wasn't called anyway :-) and causes some trouble, because at |
| 219 | * end-of-DMA, both SCSI ints are triggered simultaneously, so the NCR int has |
| 220 | * to clear the DMA int pending bit before it allows other level 6 interrupts. |
| 221 | */ |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 222 | static void scsi_dma_buserr(int irq, void *dummy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 224 | unsigned char dma_stat = tt_scsi_dma.dma_ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
| 226 | /* Don't do anything if a NCR interrupt is pending. Probably it's just |
| 227 | * masked... */ |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 228 | if (atari_irq_pending(IRQ_TT_MFP_SCSI)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | return; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | printk("Bad SCSI DMA interrupt! dma_addr=0x%08lx dma_stat=%02x dma_cnt=%08lx\n", |
| 232 | SCSI_DMA_READ_P(dma_addr), dma_stat, SCSI_DMA_READ_P(dma_cnt)); |
| 233 | if (dma_stat & 0x80) { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 234 | if (!scsi_dma_is_ignored_buserr(dma_stat)) |
| 235 | printk("SCSI DMA bus error -- bad DMA programming!\n"); |
| 236 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | /* Under normal circumstances we never should get to this point, |
| 238 | * since both interrupts are triggered simultaneously and the 5380 |
| 239 | * int has higher priority. When this irq is handled, that DMA |
| 240 | * interrupt is cleared. So a warning message is printed here. |
| 241 | */ |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 242 | printk("SCSI DMA intr ?? -- this shouldn't happen!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | #endif |
| 246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
Finn Thain | cd46140 | 2016-01-03 16:06:06 +1100 | [diff] [blame] | 248 | static irqreturn_t scsi_tt_intr(int irq, void *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | { |
Finn Thain | cd46140 | 2016-01-03 16:06:06 +1100 | [diff] [blame] | 250 | struct Scsi_Host *instance = dev; |
| 251 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | int dma_stat; |
| 253 | |
| 254 | dma_stat = tt_scsi_dma.dma_ctrl; |
| 255 | |
Finn Thain | cd46140 | 2016-01-03 16:06:06 +1100 | [diff] [blame] | 256 | dsprintk(NDEBUG_INTR, instance, "NCR5380 interrupt, DMA status = %02x\n", |
| 257 | dma_stat & 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
| 259 | /* Look if it was the DMA that has interrupted: First possibility |
| 260 | * is that a bus error occurred... |
| 261 | */ |
| 262 | if (dma_stat & 0x80) { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 263 | if (!scsi_dma_is_ignored_buserr(dma_stat)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | printk(KERN_ERR "SCSI DMA caused bus error near 0x%08lx\n", |
| 265 | SCSI_DMA_READ_P(dma_addr)); |
| 266 | printk(KERN_CRIT "SCSI DMA bus error -- bad DMA programming!"); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | /* If the DMA is active but not finished, we have the case |
| 271 | * that some other 5380 interrupt occurred within the DMA transfer. |
| 272 | * This means we have residual bytes, if the desired end address |
| 273 | * is not yet reached. Maybe we have to fetch some bytes from the |
| 274 | * rest data register, too. The residual must be calculated from |
| 275 | * the address pointer, not the counter register, because only the |
| 276 | * addr reg counts bytes not yet written and pending in the rest |
| 277 | * data reg! |
| 278 | */ |
| 279 | if ((dma_stat & 0x02) && !(dma_stat & 0x40)) { |
Finn Thain | cd46140 | 2016-01-03 16:06:06 +1100 | [diff] [blame] | 280 | atari_dma_residual = hostdata->dma_len - |
| 281 | (SCSI_DMA_READ_P(dma_addr) - atari_dma_startaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 283 | dprintk(NDEBUG_DMA, "SCSI DMA: There are %ld residual bytes.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | atari_dma_residual); |
| 285 | |
| 286 | if ((signed int)atari_dma_residual < 0) |
| 287 | atari_dma_residual = 0; |
| 288 | if ((dma_stat & 1) == 0) { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 289 | /* |
| 290 | * After read operations, we maybe have to |
| 291 | * transport some rest bytes |
| 292 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | atari_scsi_fetch_restbytes(); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 294 | } else { |
| 295 | /* |
| 296 | * There seems to be a nasty bug in some SCSI-DMA/NCR |
| 297 | * combinations: If a target disconnects while a write |
| 298 | * operation is going on, the address register of the |
| 299 | * DMA may be a few bytes farer than it actually read. |
| 300 | * This is probably due to DMA prefetching and a delay |
| 301 | * between DMA and NCR. Experiments showed that the |
| 302 | * dma_addr is 9 bytes to high, but this could vary. |
| 303 | * The problem is, that the residual is thus calculated |
| 304 | * wrong and the next transfer will start behind where |
| 305 | * it should. So we round up the residual to the next |
| 306 | * multiple of a sector size, if it isn't already a |
| 307 | * multiple and the originally expected transfer size |
| 308 | * was. The latter condition is there to ensure that |
| 309 | * the correction is taken only for "real" data |
| 310 | * transfers and not for, e.g., the parameters of some |
| 311 | * other command. These shouldn't disconnect anyway. |
| 312 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | if (atari_dma_residual & 0x1ff) { |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 314 | dprintk(NDEBUG_DMA, "SCSI DMA: DMA bug corrected, " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | "difference %ld bytes\n", |
| 316 | 512 - (atari_dma_residual & 0x1ff)); |
| 317 | atari_dma_residual = (atari_dma_residual + 511) & ~0x1ff; |
| 318 | } |
| 319 | } |
| 320 | tt_scsi_dma.dma_ctrl = 0; |
| 321 | } |
| 322 | |
| 323 | /* If the DMA is finished, fetch the rest bytes and turn it off */ |
| 324 | if (dma_stat & 0x40) { |
| 325 | atari_dma_residual = 0; |
| 326 | if ((dma_stat & 1) == 0) |
| 327 | atari_scsi_fetch_restbytes(); |
| 328 | tt_scsi_dma.dma_ctrl = 0; |
| 329 | } |
| 330 | |
Finn Thain | cd46140 | 2016-01-03 16:06:06 +1100 | [diff] [blame] | 331 | NCR5380_intr(irq, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | return IRQ_HANDLED; |
| 334 | } |
| 335 | |
| 336 | |
Finn Thain | cd46140 | 2016-01-03 16:06:06 +1100 | [diff] [blame] | 337 | static irqreturn_t scsi_falcon_intr(int irq, void *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | { |
Finn Thain | cd46140 | 2016-01-03 16:06:06 +1100 | [diff] [blame] | 339 | struct Scsi_Host *instance = dev; |
| 340 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | int dma_stat; |
| 342 | |
| 343 | /* Turn off DMA and select sector counter register before |
| 344 | * accessing the status register (Atari recommendation!) |
| 345 | */ |
| 346 | st_dma.dma_mode_status = 0x90; |
| 347 | dma_stat = st_dma.dma_mode_status; |
| 348 | |
| 349 | /* Bit 0 indicates some error in the DMA process... don't know |
| 350 | * what happened exactly (no further docu). |
| 351 | */ |
| 352 | if (!(dma_stat & 0x01)) { |
| 353 | /* DMA error */ |
| 354 | printk(KERN_CRIT "SCSI DMA error near 0x%08lx!\n", SCSI_DMA_GETADR()); |
| 355 | } |
| 356 | |
| 357 | /* If the DMA was active, but now bit 1 is not clear, it is some |
| 358 | * other 5380 interrupt that finishes the DMA transfer. We have to |
| 359 | * calculate the number of residual bytes and give a warning if |
| 360 | * bytes are stuck in the ST-DMA fifo (there's no way to reach them!) |
| 361 | */ |
| 362 | if (atari_dma_active && (dma_stat & 0x02)) { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 363 | unsigned long transferred; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
| 365 | transferred = SCSI_DMA_GETADR() - atari_dma_startaddr; |
| 366 | /* The ST-DMA address is incremented in 2-byte steps, but the |
| 367 | * data are written only in 16-byte chunks. If the number of |
| 368 | * transferred bytes is not divisible by 16, the remainder is |
| 369 | * lost somewhere in outer space. |
| 370 | */ |
| 371 | if (transferred & 15) |
| 372 | printk(KERN_ERR "SCSI DMA error: %ld bytes lost in " |
| 373 | "ST-DMA fifo\n", transferred & 15); |
| 374 | |
Finn Thain | cd46140 | 2016-01-03 16:06:06 +1100 | [diff] [blame] | 375 | atari_dma_residual = hostdata->dma_len - transferred; |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 376 | dprintk(NDEBUG_DMA, "SCSI DMA: There are %ld residual bytes.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | atari_dma_residual); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 378 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | atari_dma_residual = 0; |
| 380 | atari_dma_active = 0; |
| 381 | |
| 382 | if (atari_dma_orig_addr) { |
| 383 | /* If the dribble buffer was used on a read operation, copy the DMA-ed |
| 384 | * data to the original destination address. |
| 385 | */ |
| 386 | memcpy(atari_dma_orig_addr, phys_to_virt(atari_dma_startaddr), |
Finn Thain | cd46140 | 2016-01-03 16:06:06 +1100 | [diff] [blame] | 387 | hostdata->dma_len - atari_dma_residual); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | atari_dma_orig_addr = NULL; |
| 389 | } |
| 390 | |
Finn Thain | cd46140 | 2016-01-03 16:06:06 +1100 | [diff] [blame] | 391 | NCR5380_intr(irq, dev); |
| 392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | return IRQ_HANDLED; |
| 394 | } |
| 395 | |
| 396 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 397 | static void atari_scsi_fetch_restbytes(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | { |
| 399 | int nr; |
| 400 | char *src, *dst; |
| 401 | unsigned long phys_dst; |
| 402 | |
| 403 | /* fetch rest bytes in the DMA register */ |
| 404 | phys_dst = SCSI_DMA_READ_P(dma_addr); |
| 405 | nr = phys_dst & 3; |
| 406 | if (nr) { |
| 407 | /* there are 'nr' bytes left for the last long address |
| 408 | before the DMA pointer */ |
| 409 | phys_dst ^= nr; |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 410 | dprintk(NDEBUG_DMA, "SCSI DMA: there are %d rest bytes for phys addr 0x%08lx", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | nr, phys_dst); |
| 412 | /* The content of the DMA pointer is a physical address! */ |
| 413 | dst = phys_to_virt(phys_dst); |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 414 | dprintk(NDEBUG_DMA, " = virt addr %p\n", dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | for (src = (char *)&tt_scsi_dma.dma_restdata; nr != 0; --nr) |
| 416 | *dst++ = *src++; |
| 417 | } |
| 418 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
| 420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | /* This function releases the lock on the DMA chip if there is no |
Finn Thain | 16b29e7 | 2014-11-12 16:12:08 +1100 | [diff] [blame] | 422 | * connected command and the disconnected queue is empty. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | */ |
| 424 | |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 425 | static void falcon_release_lock(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 427 | if (IS_A_TT()) |
| 428 | return; |
| 429 | |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 430 | if (stdma_is_locked_by(scsi_falcon_intr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | stdma_release(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | /* This function manages the locking of the ST-DMA. |
| 435 | * If the DMA isn't locked already for SCSI, it tries to lock it by |
| 436 | * calling stdma_lock(). But if the DMA is locked by the SCSI code and |
| 437 | * there are other drivers waiting for the chip, we do not issue the |
Finn Thain | 16b29e7 | 2014-11-12 16:12:08 +1100 | [diff] [blame] | 438 | * command immediately but tell the SCSI mid-layer to defer. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | */ |
| 440 | |
Finn Thain | a53a21e | 2014-11-12 16:12:21 +1100 | [diff] [blame] | 441 | static int falcon_get_lock(struct Scsi_Host *instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 443 | if (IS_A_TT()) |
Finn Thain | 16b29e7 | 2014-11-12 16:12:08 +1100 | [diff] [blame] | 444 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
Finn Thain | 16b29e7 | 2014-11-12 16:12:08 +1100 | [diff] [blame] | 446 | if (in_interrupt()) |
Finn Thain | a53a21e | 2014-11-12 16:12:21 +1100 | [diff] [blame] | 447 | return stdma_try_lock(scsi_falcon_intr, instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
Finn Thain | a53a21e | 2014-11-12 16:12:21 +1100 | [diff] [blame] | 449 | stdma_lock(scsi_falcon_intr, instance); |
Finn Thain | 16b29e7 | 2014-11-12 16:12:08 +1100 | [diff] [blame] | 450 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Geert Uytterhoeven | 7b54e43 | 2012-03-18 11:54:40 +0100 | [diff] [blame] | 453 | #ifndef MODULE |
| 454 | static int __init atari_scsi_setup(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | { |
| 456 | /* Format of atascsi parameter is: |
| 457 | * atascsi=<can_queue>,<cmd_per_lun>,<sg_tablesize>,<hostid>,<use_tags> |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 458 | * Defaults depend on TT or Falcon, determined at run time. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | * Negative values mean don't change. |
| 460 | */ |
Finn Thain | 9c3f0e2 | 2016-01-03 16:05:11 +1100 | [diff] [blame] | 461 | int ints[8]; |
Geert Uytterhoeven | 7b54e43 | 2012-03-18 11:54:40 +0100 | [diff] [blame] | 462 | |
| 463 | get_options(str, ARRAY_SIZE(ints), ints); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | if (ints[0] < 1) { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 466 | printk("atari_scsi_setup: no arguments!\n"); |
Geert Uytterhoeven | 7b54e43 | 2012-03-18 11:54:40 +0100 | [diff] [blame] | 467 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | } |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 469 | if (ints[0] >= 1) |
| 470 | setup_can_queue = ints[1]; |
| 471 | if (ints[0] >= 2) |
| 472 | setup_cmd_per_lun = ints[2]; |
| 473 | if (ints[0] >= 3) |
| 474 | setup_sg_tablesize = ints[3]; |
| 475 | if (ints[0] >= 4) |
| 476 | setup_hostid = ints[4]; |
Finn Thain | c4ec6f9 | 2016-03-23 21:10:22 +1100 | [diff] [blame] | 477 | /* ints[5] (use_tagged_queuing) is ignored */ |
Finn Thain | 9c3f0e2 | 2016-01-03 16:05:11 +1100 | [diff] [blame] | 478 | /* ints[6] (use_pdma) is ignored */ |
| 479 | if (ints[0] >= 7) |
| 480 | setup_toshiba_delay = ints[7]; |
Geert Uytterhoeven | 7b54e43 | 2012-03-18 11:54:40 +0100 | [diff] [blame] | 481 | |
| 482 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Geert Uytterhoeven | 7b54e43 | 2012-03-18 11:54:40 +0100 | [diff] [blame] | 485 | __setup("atascsi=", atari_scsi_setup); |
| 486 | #endif /* !MODULE */ |
| 487 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 488 | |
Geert Uytterhoeven | 107b5d5 | 2011-06-12 20:48:33 +0200 | [diff] [blame] | 489 | static unsigned long atari_scsi_dma_setup(struct Scsi_Host *instance, |
| 490 | void *data, unsigned long count, |
| 491 | int dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 493 | unsigned long addr = virt_to_phys(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 495 | dprintk(NDEBUG_DMA, "scsi%d: setting up dma, data = %p, phys = %lx, count = %ld, " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | "dir = %d\n", instance->host_no, data, addr, count, dir); |
| 497 | |
| 498 | if (!IS_A_TT() && !STRAM_ADDR(addr)) { |
| 499 | /* If we have a non-DMAable address on a Falcon, use the dribble |
| 500 | * buffer; 'orig_addr' != 0 in the read case tells the interrupt |
| 501 | * handler to copy data from the dribble buffer to the originally |
| 502 | * wanted address. |
| 503 | */ |
| 504 | if (dir) |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 505 | memcpy(atari_dma_buffer, data, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | else |
| 507 | atari_dma_orig_addr = data; |
| 508 | addr = atari_dma_phys_buffer; |
| 509 | } |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | atari_dma_startaddr = addr; /* Needed for calculating residual later. */ |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 512 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | /* Cache cleanup stuff: On writes, push any dirty cache out before sending |
| 514 | * it to the peripheral. (Must be done before DMA setup, since at least |
| 515 | * the ST-DMA begins to fill internal buffers right after setup. For |
| 516 | * reads, invalidate any cache, may be altered after DMA without CPU |
| 517 | * knowledge. |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 518 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | * ++roman: For the Medusa, there's no need at all for that cache stuff, |
| 520 | * because the hardware does bus snooping (fine!). |
| 521 | */ |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 522 | dma_cache_maintenance(addr, count, dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | if (IS_A_TT()) { |
| 525 | tt_scsi_dma.dma_ctrl = dir; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 526 | SCSI_DMA_WRITE_P(dma_addr, addr); |
| 527 | SCSI_DMA_WRITE_P(dma_cnt, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | tt_scsi_dma.dma_ctrl = dir | 2; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 529 | } else { /* ! IS_A_TT */ |
| 530 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | /* set address */ |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 532 | SCSI_DMA_SETADR(addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
| 534 | /* toggle direction bit to clear FIFO and set DMA direction */ |
| 535 | dir <<= 8; |
| 536 | st_dma.dma_mode_status = 0x90 | dir; |
| 537 | st_dma.dma_mode_status = 0x90 | (dir ^ 0x100); |
| 538 | st_dma.dma_mode_status = 0x90 | dir; |
| 539 | udelay(40); |
| 540 | /* On writes, round up the transfer length to the next multiple of 512 |
| 541 | * (see also comment at atari_dma_xfer_len()). */ |
| 542 | st_dma.fdc_acces_seccount = (count + (dir ? 511 : 0)) >> 9; |
| 543 | udelay(40); |
| 544 | st_dma.dma_mode_status = 0x10 | dir; |
| 545 | udelay(40); |
| 546 | /* need not restore value of dir, only boolean value is tested */ |
| 547 | atari_dma_active = 1; |
| 548 | } |
| 549 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 550 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 554 | static long atari_scsi_dma_residual(struct Scsi_Host *instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 556 | return atari_dma_residual; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | |
| 560 | #define CMD_SURELY_BLOCK_MODE 0 |
| 561 | #define CMD_SURELY_BYTE_MODE 1 |
| 562 | #define CMD_MODE_UNKNOWN 2 |
| 563 | |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 564 | static int falcon_classify_cmd(struct scsi_cmnd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | { |
| 566 | unsigned char opcode = cmd->cmnd[0]; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 567 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | if (opcode == READ_DEFECT_DATA || opcode == READ_LONG || |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 569 | opcode == READ_BUFFER) |
| 570 | return CMD_SURELY_BYTE_MODE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | else if (opcode == READ_6 || opcode == READ_10 || |
| 572 | opcode == 0xa8 /* READ_12 */ || opcode == READ_REVERSE || |
| 573 | opcode == RECOVER_BUFFERED_DATA) { |
| 574 | /* In case of a sequential-access target (tape), special care is |
| 575 | * needed here: The transfer is block-mode only if the 'fixed' bit is |
| 576 | * set! */ |
| 577 | if (cmd->device->type == TYPE_TAPE && !(cmd->cmnd[1] & 1)) |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 578 | return CMD_SURELY_BYTE_MODE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | else |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 580 | return CMD_SURELY_BLOCK_MODE; |
| 581 | } else |
| 582 | return CMD_MODE_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | |
| 586 | /* This function calculates the number of bytes that can be transferred via |
| 587 | * DMA. On the TT, this is arbitrary, but on the Falcon we have to use the |
| 588 | * ST-DMA chip. There are only multiples of 512 bytes possible and max. |
| 589 | * 255*512 bytes :-( This means also, that defining READ_OVERRUNS is not |
| 590 | * possible on the Falcon, since that would require to program the DMA for |
| 591 | * n*512 - atari_read_overrun bytes. But it seems that the Falcon doesn't have |
| 592 | * the overrun problem, so this question is academic :-) |
| 593 | */ |
| 594 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 595 | static unsigned long atari_dma_xfer_len(unsigned long wanted_len, |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 596 | struct scsi_cmnd *cmd, int write_flag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | { |
| 598 | unsigned long possible_len, limit; |
Adrian Bunk | 29c8a24 | 2008-10-13 21:58:59 +0200 | [diff] [blame] | 599 | |
Finn Thain | e63449c | 2016-03-23 21:10:13 +1100 | [diff] [blame] | 600 | if (wanted_len < DMA_MIN_SIZE) |
| 601 | return 0; |
| 602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | if (IS_A_TT()) |
| 604 | /* TT SCSI DMA can transfer arbitrary #bytes */ |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 605 | return wanted_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
| 607 | /* ST DMA chip is stupid -- only multiples of 512 bytes! (and max. |
| 608 | * 255*512 bytes, but this should be enough) |
| 609 | * |
| 610 | * ++roman: Aaargl! Another Falcon-SCSI problem... There are some commands |
| 611 | * that return a number of bytes which cannot be known beforehand. In this |
| 612 | * case, the given transfer length is an "allocation length". Now it |
| 613 | * can happen that this allocation length is a multiple of 512 bytes and |
| 614 | * the DMA is used. But if not n*512 bytes really arrive, some input data |
| 615 | * will be lost in the ST-DMA's FIFO :-( Thus, we have to distinguish |
| 616 | * between commands that do block transfers and those that do byte |
| 617 | * transfers. But this isn't easy... there are lots of vendor specific |
| 618 | * commands, and the user can issue any command via the |
| 619 | * SCSI_IOCTL_SEND_COMMAND. |
| 620 | * |
| 621 | * The solution: We classify SCSI commands in 1) surely block-mode cmd.s, |
| 622 | * 2) surely byte-mode cmd.s and 3) cmd.s with unknown mode. In case 1) |
| 623 | * and 3), the thing to do is obvious: allow any number of blocks via DMA |
| 624 | * or none. In case 2), we apply some heuristic: Byte mode is assumed if |
| 625 | * the transfer (allocation) length is < 1024, hoping that no cmd. not |
| 626 | * explicitly known as byte mode have such big allocation lengths... |
| 627 | * BTW, all the discussion above applies only to reads. DMA writes are |
| 628 | * unproblematic anyways, since the targets aborts the transfer after |
| 629 | * receiving a sufficient number of bytes. |
| 630 | * |
| 631 | * Another point: If the transfer is from/to an non-ST-RAM address, we |
| 632 | * use the dribble buffer and thus can do only STRAM_BUFFER_SIZE bytes. |
| 633 | */ |
| 634 | |
| 635 | if (write_flag) { |
| 636 | /* Write operation can always use the DMA, but the transfer size must |
| 637 | * be rounded up to the next multiple of 512 (atari_dma_setup() does |
| 638 | * this). |
| 639 | */ |
| 640 | possible_len = wanted_len; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 641 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | /* Read operations: if the wanted transfer length is not a multiple of |
| 643 | * 512, we cannot use DMA, since the ST-DMA cannot split transfers |
| 644 | * (no interrupt on DMA finished!) |
| 645 | */ |
| 646 | if (wanted_len & 0x1ff) |
| 647 | possible_len = 0; |
| 648 | else { |
| 649 | /* Now classify the command (see above) and decide whether it is |
| 650 | * allowed to do DMA at all */ |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 651 | switch (falcon_classify_cmd(cmd)) { |
| 652 | case CMD_SURELY_BLOCK_MODE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | possible_len = wanted_len; |
| 654 | break; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 655 | case CMD_SURELY_BYTE_MODE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | possible_len = 0; /* DMA prohibited */ |
| 657 | break; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 658 | case CMD_MODE_UNKNOWN: |
| 659 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | /* For unknown commands assume block transfers if the transfer |
| 661 | * size/allocation length is >= 1024 */ |
| 662 | possible_len = (wanted_len < 1024) ? 0 : wanted_len; |
| 663 | break; |
| 664 | } |
| 665 | } |
| 666 | } |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 667 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | /* Last step: apply the hard limit on DMA transfers */ |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 669 | limit = (atari_dma_buffer && !STRAM_ADDR(virt_to_phys(cmd->SCp.ptr))) ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | STRAM_BUFFER_SIZE : 255*512; |
| 671 | if (possible_len > limit) |
| 672 | possible_len = limit; |
| 673 | |
| 674 | if (possible_len != wanted_len) |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 675 | dprintk(NDEBUG_DMA, "Sorry, must cut DMA transfer size to %ld bytes " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | "instead of %ld\n", possible_len, wanted_len); |
| 677 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 678 | return possible_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | /* NCR5380 register access functions |
| 683 | * |
| 684 | * There are separate functions for TT and Falcon, because the access |
| 685 | * methods are quite different. The calling macros NCR5380_read and |
| 686 | * NCR5380_write call these functions via function pointers. |
| 687 | */ |
| 688 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 689 | static unsigned char atari_scsi_tt_reg_read(unsigned char reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 691 | return tt_scsi_regp[reg * 2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | } |
| 693 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 694 | static void atari_scsi_tt_reg_write(unsigned char reg, unsigned char value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | { |
| 696 | tt_scsi_regp[reg * 2] = value; |
| 697 | } |
| 698 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 699 | static unsigned char atari_scsi_falcon_reg_read(unsigned char reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | { |
| 701 | dma_wd.dma_mode_status= (u_short)(0x88 + reg); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 702 | return (u_char)dma_wd.fdc_acces_seccount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | } |
| 704 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 705 | static void atari_scsi_falcon_reg_write(unsigned char reg, unsigned char value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | { |
| 707 | dma_wd.dma_mode_status = (u_short)(0x88 + reg); |
| 708 | dma_wd.fdc_acces_seccount = (u_short)value; |
| 709 | } |
| 710 | |
| 711 | |
Finn Thain | 52d3e56 | 2016-03-23 21:10:20 +1100 | [diff] [blame] | 712 | #include "NCR5380.c" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | |
Finn Thain | 4d3d2a5 | 2014-11-12 16:11:52 +1100 | [diff] [blame] | 714 | static int atari_scsi_bus_reset(struct scsi_cmnd *cmd) |
| 715 | { |
| 716 | int rv; |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 717 | unsigned long flags; |
Finn Thain | 4d3d2a5 | 2014-11-12 16:11:52 +1100 | [diff] [blame] | 718 | |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 719 | local_irq_save(flags); |
| 720 | |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 721 | /* Abort a maybe active DMA transfer */ |
Finn Thain | 4d3d2a5 | 2014-11-12 16:11:52 +1100 | [diff] [blame] | 722 | if (IS_A_TT()) { |
Finn Thain | 4d3d2a5 | 2014-11-12 16:11:52 +1100 | [diff] [blame] | 723 | tt_scsi_dma.dma_ctrl = 0; |
Finn Thain | 4d3d2a5 | 2014-11-12 16:11:52 +1100 | [diff] [blame] | 724 | } else { |
Finn Thain | 4d3d2a5 | 2014-11-12 16:11:52 +1100 | [diff] [blame] | 725 | st_dma.dma_mode_status = 0x90; |
| 726 | atari_dma_active = 0; |
| 727 | atari_dma_orig_addr = NULL; |
Finn Thain | 4d3d2a5 | 2014-11-12 16:11:52 +1100 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | rv = NCR5380_bus_reset(cmd); |
| 731 | |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 732 | /* The 5380 raises its IRQ line while _RST is active but the ST DMA |
| 733 | * "lock" has been released so this interrupt may end up handled by |
| 734 | * floppy or IDE driver (if one of them holds the lock). The NCR5380 |
| 735 | * interrupt flag has been cleared already. |
| 736 | */ |
Finn Thain | 4d3d2a5 | 2014-11-12 16:11:52 +1100 | [diff] [blame] | 737 | |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 738 | local_irq_restore(flags); |
Finn Thain | 4d3d2a5 | 2014-11-12 16:11:52 +1100 | [diff] [blame] | 739 | |
| 740 | return rv; |
| 741 | } |
| 742 | |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 743 | #define DRV_MODULE_NAME "atari_scsi" |
| 744 | #define PFX DRV_MODULE_NAME ": " |
| 745 | |
| 746 | static struct scsi_host_template atari_scsi_template = { |
| 747 | .module = THIS_MODULE, |
| 748 | .proc_name = DRV_MODULE_NAME, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | .name = "Atari native SCSI", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | .info = atari_scsi_info, |
| 751 | .queuecommand = atari_scsi_queue_command, |
| 752 | .eh_abort_handler = atari_scsi_abort, |
| 753 | .eh_bus_reset_handler = atari_scsi_bus_reset, |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 754 | .this_id = 7, |
Finn Thain | a5217a8 | 2016-03-23 21:10:29 +1100 | [diff] [blame^] | 755 | .cmd_per_lun = 2, |
Finn Thain | aa2e2cb | 2016-01-03 16:05:48 +1100 | [diff] [blame] | 756 | .use_clustering = DISABLE_CLUSTERING, |
Finn Thain | 32b26a1 | 2016-01-03 16:05:58 +1100 | [diff] [blame] | 757 | .cmd_size = NCR5380_CMD_SIZE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | }; |
| 759 | |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 760 | static int __init atari_scsi_probe(struct platform_device *pdev) |
| 761 | { |
| 762 | struct Scsi_Host *instance; |
| 763 | int error; |
| 764 | struct resource *irq; |
Finn Thain | ef1081c | 2014-11-12 16:12:14 +1100 | [diff] [blame] | 765 | int host_flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 767 | irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 768 | if (!irq) |
| 769 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 771 | if (ATARIHW_PRESENT(TT_SCSI)) { |
| 772 | atari_scsi_reg_read = atari_scsi_tt_reg_read; |
| 773 | atari_scsi_reg_write = atari_scsi_tt_reg_write; |
| 774 | } else { |
| 775 | atari_scsi_reg_read = atari_scsi_falcon_reg_read; |
| 776 | atari_scsi_reg_write = atari_scsi_falcon_reg_write; |
| 777 | } |
| 778 | |
| 779 | /* The values for CMD_PER_LUN and CAN_QUEUE are somehow arbitrary. |
| 780 | * Higher values should work, too; try it! |
| 781 | * (But cmd_per_lun costs memory!) |
| 782 | * |
| 783 | * But there seems to be a bug somewhere that requires CAN_QUEUE to be |
| 784 | * 2*CMD_PER_LUN. At least on a TT, no spurious timeouts seen since |
| 785 | * changed CMD_PER_LUN... |
| 786 | * |
| 787 | * Note: The Falcon currently uses 8/1 setting due to unsolved problems |
| 788 | * with cmd_per_lun != 1 |
| 789 | */ |
| 790 | if (ATARIHW_PRESENT(TT_SCSI)) { |
| 791 | atari_scsi_template.can_queue = 16; |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 792 | atari_scsi_template.sg_tablesize = SG_ALL; |
| 793 | } else { |
| 794 | atari_scsi_template.can_queue = 8; |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 795 | atari_scsi_template.sg_tablesize = SG_NONE; |
| 796 | } |
| 797 | |
| 798 | if (setup_can_queue > 0) |
| 799 | atari_scsi_template.can_queue = setup_can_queue; |
| 800 | |
| 801 | if (setup_cmd_per_lun > 0) |
| 802 | atari_scsi_template.cmd_per_lun = setup_cmd_per_lun; |
| 803 | |
| 804 | /* Leave sg_tablesize at 0 on a Falcon! */ |
| 805 | if (ATARIHW_PRESENT(TT_SCSI) && setup_sg_tablesize >= 0) |
| 806 | atari_scsi_template.sg_tablesize = setup_sg_tablesize; |
| 807 | |
| 808 | if (setup_hostid >= 0) { |
| 809 | atari_scsi_template.this_id = setup_hostid & 7; |
| 810 | } else { |
| 811 | /* Test if a host id is set in the NVRam */ |
| 812 | if (ATARIHW_PRESENT(TT_CLK) && nvram_check_checksum()) { |
Finn Thain | 6225a16 | 2016-01-03 16:05:02 +1100 | [diff] [blame] | 813 | unsigned char b = nvram_read_byte(16); |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 814 | |
| 815 | /* Arbitration enabled? (for TOS) |
| 816 | * If yes, use configured host ID |
| 817 | */ |
| 818 | if (b & 0x80) |
| 819 | atari_scsi_template.this_id = b & 7; |
| 820 | } |
| 821 | } |
| 822 | |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 823 | /* If running on a Falcon and if there's TT-Ram (i.e., more than one |
| 824 | * memory block, since there's always ST-Ram in a Falcon), then |
| 825 | * allocate a STRAM_BUFFER_SIZE byte dribble buffer for transfers |
| 826 | * from/to alternative Ram. |
| 827 | */ |
| 828 | if (ATARIHW_PRESENT(ST_SCSI) && !ATARIHW_PRESENT(EXTD_DMA) && |
| 829 | m68k_num_memory > 1) { |
| 830 | atari_dma_buffer = atari_stram_alloc(STRAM_BUFFER_SIZE, "SCSI"); |
| 831 | if (!atari_dma_buffer) { |
| 832 | pr_err(PFX "can't allocate ST-RAM double buffer\n"); |
| 833 | return -ENOMEM; |
| 834 | } |
| 835 | atari_dma_phys_buffer = atari_stram_to_phys(atari_dma_buffer); |
| 836 | atari_dma_orig_addr = 0; |
| 837 | } |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 838 | |
| 839 | instance = scsi_host_alloc(&atari_scsi_template, |
| 840 | sizeof(struct NCR5380_hostdata)); |
| 841 | if (!instance) { |
| 842 | error = -ENOMEM; |
| 843 | goto fail_alloc; |
| 844 | } |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 845 | |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 846 | instance->irq = irq->start; |
| 847 | |
Finn Thain | ef1081c | 2014-11-12 16:12:14 +1100 | [diff] [blame] | 848 | host_flags |= IS_A_TT() ? 0 : FLAG_LATE_DMA_SETUP; |
Finn Thain | 9c3f0e2 | 2016-01-03 16:05:11 +1100 | [diff] [blame] | 849 | host_flags |= setup_toshiba_delay > 0 ? FLAG_TOSHIBA_DELAY : 0; |
Finn Thain | ca513fc | 2014-11-12 16:12:19 +1100 | [diff] [blame] | 850 | |
Finn Thain | 0ad0eff | 2016-01-03 16:05:21 +1100 | [diff] [blame] | 851 | error = NCR5380_init(instance, host_flags); |
| 852 | if (error) |
| 853 | goto fail_init; |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 854 | |
| 855 | if (IS_A_TT()) { |
| 856 | error = request_irq(instance->irq, scsi_tt_intr, 0, |
| 857 | "NCR5380", instance); |
| 858 | if (error) { |
| 859 | pr_err(PFX "request irq %d failed, aborting\n", |
| 860 | instance->irq); |
| 861 | goto fail_irq; |
| 862 | } |
| 863 | tt_mfp.active_edge |= 0x80; /* SCSI int on L->H */ |
Finn Thain | e4dec68 | 2016-03-23 21:10:12 +1100 | [diff] [blame] | 864 | |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 865 | tt_scsi_dma.dma_ctrl = 0; |
| 866 | atari_dma_residual = 0; |
| 867 | |
| 868 | /* While the read overruns (described by Drew Eckhardt in |
| 869 | * NCR5380.c) never happened on TTs, they do in fact on the |
| 870 | * Medusa (This was the cause why SCSI didn't work right for |
| 871 | * so long there.) Since handling the overruns slows down |
| 872 | * a bit, I turned the #ifdef's into a runtime condition. |
| 873 | * |
| 874 | * In principle it should be sufficient to do max. 1 byte with |
| 875 | * PIO, but there is another problem on the Medusa with the DMA |
Finn Thain | ef1081c | 2014-11-12 16:12:14 +1100 | [diff] [blame] | 876 | * rest data register. So read_overruns is currently set |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 877 | * to 4 to avoid having transfers that aren't a multiple of 4. |
| 878 | * If the rest data bug is fixed, this can be lowered to 1. |
| 879 | */ |
Finn Thain | ef1081c | 2014-11-12 16:12:14 +1100 | [diff] [blame] | 880 | if (MACH_IS_MEDUSA) { |
| 881 | struct NCR5380_hostdata *hostdata = |
| 882 | shost_priv(instance); |
| 883 | |
| 884 | hostdata->read_overruns = 4; |
| 885 | } |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 886 | } else { |
| 887 | /* Nothing to do for the interrupt: the ST-DMA is initialized |
| 888 | * already. |
| 889 | */ |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 890 | atari_dma_residual = 0; |
| 891 | atari_dma_active = 0; |
| 892 | atari_dma_stram_mask = (ATARIHW_PRESENT(EXTD_DMA) ? 0x00000000 |
| 893 | : 0xff000000); |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 894 | } |
| 895 | |
Finn Thain | 9c3f0e2 | 2016-01-03 16:05:11 +1100 | [diff] [blame] | 896 | NCR5380_maybe_reset_bus(instance); |
| 897 | |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 898 | error = scsi_add_host(instance, NULL); |
| 899 | if (error) |
| 900 | goto fail_host; |
| 901 | |
| 902 | platform_set_drvdata(pdev, instance); |
| 903 | |
| 904 | scsi_scan_host(instance); |
| 905 | return 0; |
| 906 | |
| 907 | fail_host: |
| 908 | if (IS_A_TT()) |
| 909 | free_irq(instance->irq, instance); |
| 910 | fail_irq: |
| 911 | NCR5380_exit(instance); |
Finn Thain | 0ad0eff | 2016-01-03 16:05:21 +1100 | [diff] [blame] | 912 | fail_init: |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 913 | scsi_host_put(instance); |
| 914 | fail_alloc: |
| 915 | if (atari_dma_buffer) |
| 916 | atari_stram_free(atari_dma_buffer); |
| 917 | return error; |
| 918 | } |
| 919 | |
| 920 | static int __exit atari_scsi_remove(struct platform_device *pdev) |
| 921 | { |
| 922 | struct Scsi_Host *instance = platform_get_drvdata(pdev); |
| 923 | |
| 924 | scsi_remove_host(instance); |
| 925 | if (IS_A_TT()) |
| 926 | free_irq(instance->irq, instance); |
| 927 | NCR5380_exit(instance); |
| 928 | scsi_host_put(instance); |
| 929 | if (atari_dma_buffer) |
| 930 | atari_stram_free(atari_dma_buffer); |
| 931 | return 0; |
| 932 | } |
| 933 | |
| 934 | static struct platform_driver atari_scsi_driver = { |
| 935 | .remove = __exit_p(atari_scsi_remove), |
| 936 | .driver = { |
| 937 | .name = DRV_MODULE_NAME, |
Finn Thain | 3ff228a | 2014-11-12 16:12:09 +1100 | [diff] [blame] | 938 | }, |
| 939 | }; |
| 940 | |
| 941 | module_platform_driver_probe(atari_scsi_driver, atari_scsi_probe); |
| 942 | |
| 943 | MODULE_ALIAS("platform:" DRV_MODULE_NAME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | MODULE_LICENSE("GPL"); |