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