Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Sun3 SCSI stuff by Erik Verbruggen (erik@bigmama.xtdnet.nl) |
| 3 | * |
| 4 | * Sun3 DMA routines added by Sam Creasey (sammy@sammy.net) |
| 5 | * |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 6 | * VME support added by Sam Creasey |
| 7 | * |
| 8 | * TODO: modify this driver to support multiple Sun3 SCSI VME boards |
| 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * Adapted from mac_scsinew.c: |
| 11 | */ |
| 12 | /* |
| 13 | * Generic Macintosh NCR5380 driver |
| 14 | * |
| 15 | * Copyright 1998, Michael Schmitz <mschmitz@lbl.gov> |
| 16 | * |
| 17 | * derived in part from: |
| 18 | */ |
| 19 | /* |
| 20 | * Generic Generic NCR5380 driver |
| 21 | * |
| 22 | * Copyright 1995, Russell King |
| 23 | * |
| 24 | * ALPHA RELEASE 1. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | */ |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/types.h> |
| 28 | #include <linux/stddef.h> |
| 29 | #include <linux/ctype.h> |
| 30 | #include <linux/delay.h> |
| 31 | |
| 32 | #include <linux/module.h> |
| 33 | #include <linux/signal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/ioport.h> |
| 35 | #include <linux/init.h> |
| 36 | #include <linux/blkdev.h> |
| 37 | |
| 38 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | #include <asm/sun3ints.h> |
| 41 | #include <asm/dvma.h> |
| 42 | #include <asm/idprom.h> |
| 43 | #include <asm/machines.h> |
| 44 | |
| 45 | /* dma on! */ |
| 46 | #define REAL_DMA |
| 47 | |
| 48 | #include "scsi.h" |
| 49 | #include <scsi/scsi_host.h> |
| 50 | #include "sun3_scsi.h" |
Finn Thain | 9f6620a | 2014-03-18 11:42:23 +1100 | [diff] [blame] | 51 | #include "NCR5380.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 53 | extern int sun3_map_test(unsigned long, char *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | /*#define RESET_BOOT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | /* #define SUPPORT_TAGS */ |
| 57 | |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 58 | #ifdef SUN3_SCSI_VME |
| 59 | #define ENABLE_IRQ() |
| 60 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #define ENABLE_IRQ() enable_irq( IRQ_SUN3_SCSI ); |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 62 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 65 | static irqreturn_t scsi_sun3_intr(int irq, void *dummy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
| 67 | static int setup_can_queue = -1; |
| 68 | module_param(setup_can_queue, int, 0); |
| 69 | static int setup_cmd_per_lun = -1; |
| 70 | module_param(setup_cmd_per_lun, int, 0); |
| 71 | static int setup_sg_tablesize = -1; |
| 72 | module_param(setup_sg_tablesize, int, 0); |
| 73 | #ifdef SUPPORT_TAGS |
| 74 | static int setup_use_tagged_queuing = -1; |
| 75 | module_param(setup_use_tagged_queuing, int, 0); |
| 76 | #endif |
| 77 | static int setup_hostid = -1; |
| 78 | module_param(setup_hostid, int, 0); |
| 79 | |
Henne | 811c936 | 2006-10-03 19:51:59 +0200 | [diff] [blame] | 80 | static struct scsi_cmnd *sun3_dma_setup_done = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
Michael Schmitz | 2b0f834 | 2014-05-02 20:43:01 +1200 | [diff] [blame] | 82 | #define RESET_RUN_DONE |
| 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | #define AFTER_RESET_DELAY (HZ/2) |
| 85 | |
| 86 | /* ms to wait after hitting dma regs */ |
| 87 | #define SUN3_DMA_DELAY 10 |
| 88 | |
| 89 | /* dvma buffer to allocate -- 32k should hopefully be more than sufficient */ |
| 90 | #define SUN3_DVMA_BUFSIZE 0xe000 |
| 91 | |
| 92 | /* minimum number of bytes to do dma on */ |
| 93 | #define SUN3_DMA_MINSIZE 128 |
| 94 | |
| 95 | static volatile unsigned char *sun3_scsi_regp; |
| 96 | static volatile struct sun3_dma_regs *dregs; |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 97 | #ifndef SUN3_SCSI_VME |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | static struct sun3_udc_regs *udc_regs = NULL; |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 99 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | static unsigned char *sun3_dma_orig_addr = NULL; |
| 101 | static unsigned long sun3_dma_orig_count = 0; |
| 102 | static int sun3_dma_active = 0; |
| 103 | static unsigned long last_residual = 0; |
| 104 | |
| 105 | /* |
| 106 | * NCR 5380 register access functions |
| 107 | */ |
| 108 | |
| 109 | static inline unsigned char sun3scsi_read(int reg) |
| 110 | { |
| 111 | return( sun3_scsi_regp[reg] ); |
| 112 | } |
| 113 | |
| 114 | static inline void sun3scsi_write(int reg, int value) |
| 115 | { |
| 116 | sun3_scsi_regp[reg] = value; |
| 117 | } |
| 118 | |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 119 | #ifndef SUN3_SCSI_VME |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | /* dma controller register access functions */ |
| 121 | |
| 122 | static inline unsigned short sun3_udc_read(unsigned char reg) |
| 123 | { |
| 124 | unsigned short ret; |
| 125 | |
| 126 | dregs->udc_addr = UDC_CSR; |
| 127 | udelay(SUN3_DMA_DELAY); |
| 128 | ret = dregs->udc_data; |
| 129 | udelay(SUN3_DMA_DELAY); |
| 130 | |
| 131 | return ret; |
| 132 | } |
| 133 | |
| 134 | static inline void sun3_udc_write(unsigned short val, unsigned char reg) |
| 135 | { |
| 136 | dregs->udc_addr = reg; |
| 137 | udelay(SUN3_DMA_DELAY); |
| 138 | dregs->udc_data = val; |
| 139 | udelay(SUN3_DMA_DELAY); |
| 140 | } |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 141 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
| 143 | /* |
| 144 | * XXX: status debug |
| 145 | */ |
| 146 | static struct Scsi_Host *default_instance; |
| 147 | |
| 148 | /* |
Christoph Hellwig | d0be4a7d | 2005-10-31 18:31:40 +0100 | [diff] [blame] | 149 | * Function : int sun3scsi_detect(struct scsi_host_template * tpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | * |
| 151 | * Purpose : initializes mac NCR5380 driver based on the |
| 152 | * command line / compile time port and irq definitions. |
| 153 | * |
| 154 | * Inputs : tpnt - template for this SCSI adapter. |
| 155 | * |
| 156 | * Returns : 1 if a host adapter was found, 0 if not. |
| 157 | * |
| 158 | */ |
| 159 | |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 160 | static int __init sun3scsi_detect(struct scsi_host_template *tpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | { |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 162 | unsigned long ioaddr, irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | static int called = 0; |
| 164 | struct Scsi_Host *instance; |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 165 | #ifdef SUN3_SCSI_VME |
| 166 | int i; |
| 167 | unsigned long addrs[3] = { IOBASE_SUN3_VMESCSI, |
| 168 | IOBASE_SUN3_VMESCSI + 0x4000, |
| 169 | 0 }; |
| 170 | unsigned long vecs[3] = { SUN3_VEC_VMESCSI0, |
| 171 | SUN3_VEC_VMESCSI1, |
| 172 | 0 }; |
| 173 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
| 175 | /* check that this machine has an onboard 5380 */ |
| 176 | switch(idprom->id_machtype) { |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 177 | #ifdef SUN3_SCSI_VME |
| 178 | case SM_SUN3|SM_3_160: |
| 179 | case SM_SUN3|SM_3_260: |
| 180 | break; |
| 181 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | case SM_SUN3|SM_3_50: |
| 183 | case SM_SUN3|SM_3_60: |
| 184 | break; |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 185 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
| 187 | default: |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | if(called) |
| 192 | return 0; |
| 193 | |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 194 | #ifdef SUN3_SCSI_VME |
| 195 | tpnt->proc_name = "Sun3 5380 VME SCSI"; |
| 196 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | tpnt->proc_name = "Sun3 5380 SCSI"; |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 198 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | /* setup variables */ |
Finn Thain | d572f65f | 2014-11-12 16:12:00 +1100 | [diff] [blame^] | 201 | if (setup_can_queue > 0) |
| 202 | tpnt->can_queue = setup_can_queue; |
| 203 | if (setup_cmd_per_lun > 0) |
| 204 | tpnt->cmd_per_lun = setup_cmd_per_lun; |
| 205 | if (setup_sg_tablesize >= 0) |
| 206 | tpnt->sg_tablesize = setup_sg_tablesize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
| 208 | if (setup_hostid >= 0) |
| 209 | tpnt->this_id = setup_hostid; |
| 210 | else { |
| 211 | /* use 7 as default */ |
| 212 | tpnt->this_id = 7; |
| 213 | } |
| 214 | |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 215 | #ifdef SUN3_SCSI_VME |
| 216 | ioaddr = 0; |
| 217 | for (i = 0; addrs[i] != 0; i++) { |
| 218 | unsigned char x; |
| 219 | |
| 220 | ioaddr = (unsigned long)sun3_ioremap(addrs[i], PAGE_SIZE, |
| 221 | SUN3_PAGE_TYPE_VME16); |
| 222 | irq = vecs[i]; |
| 223 | sun3_scsi_regp = (unsigned char *)ioaddr; |
| 224 | |
| 225 | dregs = (struct sun3_dma_regs *)(((unsigned char *)ioaddr) + 8); |
| 226 | |
| 227 | if (sun3_map_test((unsigned long)dregs, &x)) { |
| 228 | unsigned short oldcsr; |
| 229 | |
| 230 | oldcsr = dregs->csr; |
| 231 | dregs->csr = 0; |
| 232 | udelay(SUN3_DMA_DELAY); |
| 233 | if (dregs->csr == 0x1400) |
| 234 | break; |
| 235 | |
| 236 | dregs->csr = oldcsr; |
| 237 | } |
| 238 | |
| 239 | iounmap((void *)ioaddr); |
| 240 | ioaddr = 0; |
| 241 | } |
| 242 | |
| 243 | if (!ioaddr) |
| 244 | return 0; |
| 245 | #else |
| 246 | irq = IRQ_SUN3_SCSI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | ioaddr = (unsigned long)ioremap(IOBASE_SUN3_SCSI, PAGE_SIZE); |
| 248 | sun3_scsi_regp = (unsigned char *)ioaddr; |
| 249 | |
| 250 | dregs = (struct sun3_dma_regs *)(((unsigned char *)ioaddr) + 8); |
| 251 | |
| 252 | if((udc_regs = dvma_malloc(sizeof(struct sun3_udc_regs))) |
| 253 | == NULL) { |
| 254 | printk("SUN3 Scsi couldn't allocate DVMA memory!\n"); |
| 255 | return 0; |
| 256 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | #endif |
| 258 | #ifdef SUPPORT_TAGS |
| 259 | if (setup_use_tagged_queuing < 0) |
Finn Thain | d572f65f | 2014-11-12 16:12:00 +1100 | [diff] [blame^] | 260 | setup_use_tagged_queuing = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | #endif |
| 262 | |
| 263 | instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata)); |
| 264 | if(instance == NULL) |
| 265 | return 0; |
| 266 | |
| 267 | default_instance = instance; |
| 268 | |
| 269 | instance->io_port = (unsigned long) ioaddr; |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 270 | instance->irq = irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
| 272 | NCR5380_init(instance, 0); |
| 273 | |
| 274 | instance->n_io_port = 32; |
| 275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | if (request_irq(instance->irq, scsi_sun3_intr, |
Jeff Garzik | 1e64166 | 2007-11-11 19:52:05 -0500 | [diff] [blame] | 277 | 0, "Sun3SCSI-5380", instance)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | #ifndef REAL_DMA |
| 279 | printk("scsi%d: IRQ%d not free, interrupts disabled\n", |
| 280 | instance->host_no, instance->irq); |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame] | 281 | instance->irq = NO_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | #else |
| 283 | printk("scsi%d: IRQ%d not free, bailing out\n", |
| 284 | instance->host_no, instance->irq); |
| 285 | return 0; |
| 286 | #endif |
| 287 | } |
| 288 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | dregs->csr = 0; |
| 290 | udelay(SUN3_DMA_DELAY); |
| 291 | dregs->csr = CSR_SCSI | CSR_FIFO | CSR_INTR; |
| 292 | udelay(SUN3_DMA_DELAY); |
| 293 | dregs->fifo_count = 0; |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 294 | #ifdef SUN3_SCSI_VME |
| 295 | dregs->fifo_count_hi = 0; |
| 296 | dregs->dma_addr_hi = 0; |
| 297 | dregs->dma_addr_lo = 0; |
| 298 | dregs->dma_count_hi = 0; |
| 299 | dregs->dma_count_lo = 0; |
| 300 | |
| 301 | dregs->ivect = VME_DATA24 | (instance->irq & 0xff); |
| 302 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
| 304 | called = 1; |
| 305 | |
| 306 | #ifdef RESET_BOOT |
| 307 | sun3_scsi_reset_boot(instance); |
| 308 | #endif |
| 309 | |
| 310 | return 1; |
| 311 | } |
| 312 | |
Finn Thain | ed8b9e7 | 2014-11-12 16:11:51 +1100 | [diff] [blame] | 313 | static int sun3scsi_release(struct Scsi_Host *shpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | { |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame] | 315 | if (shpnt->irq != NO_IRQ) |
Jeff Garzik | 1e64166 | 2007-11-11 19:52:05 -0500 | [diff] [blame] | 316 | free_irq(shpnt->irq, shpnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
| 318 | iounmap((void *)sun3_scsi_regp); |
| 319 | |
Geert Uytterhoeven | 19b6c51 | 2011-06-13 20:39:19 +0200 | [diff] [blame] | 320 | NCR5380_exit(shpnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | return 0; |
| 322 | } |
| 323 | |
| 324 | #ifdef RESET_BOOT |
| 325 | /* |
| 326 | * Our 'bus reset on boot' function |
| 327 | */ |
| 328 | |
| 329 | static void sun3_scsi_reset_boot(struct Scsi_Host *instance) |
| 330 | { |
| 331 | unsigned long end; |
| 332 | |
| 333 | NCR5380_local_declare(); |
| 334 | NCR5380_setup(instance); |
| 335 | |
| 336 | /* |
| 337 | * Do a SCSI reset to clean up the bus during initialization. No |
| 338 | * messing with the queues, interrupts, or locks necessary here. |
| 339 | */ |
| 340 | |
| 341 | printk( "Sun3 SCSI: resetting the SCSI bus..." ); |
| 342 | |
| 343 | /* switch off SCSI IRQ - catch an interrupt without IRQ bit set else */ |
| 344 | // sun3_disable_irq( IRQ_SUN3_SCSI ); |
| 345 | |
| 346 | /* get in phase */ |
| 347 | NCR5380_write( TARGET_COMMAND_REG, |
| 348 | PHASE_SR_TO_TCR( NCR5380_read(STATUS_REG) )); |
| 349 | |
| 350 | /* assert RST */ |
| 351 | NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST ); |
| 352 | |
| 353 | /* The min. reset hold time is 25us, so 40us should be enough */ |
| 354 | udelay( 50 ); |
| 355 | |
| 356 | /* reset RST and interrupt */ |
| 357 | NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE ); |
| 358 | NCR5380_read( RESET_PARITY_INTERRUPT_REG ); |
| 359 | |
| 360 | for( end = jiffies + AFTER_RESET_DELAY; time_before(jiffies, end); ) |
| 361 | barrier(); |
| 362 | |
| 363 | /* switch on SCSI IRQ again */ |
| 364 | // sun3_enable_irq( IRQ_SUN3_SCSI ); |
| 365 | |
| 366 | printk( " done\n" ); |
| 367 | } |
| 368 | #endif |
| 369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | // safe bits for the CSR |
| 371 | #define CSR_GOOD 0x060f |
| 372 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 373 | static irqreturn_t scsi_sun3_intr(int irq, void *dummy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | { |
| 375 | unsigned short csr = dregs->csr; |
| 376 | int handled = 0; |
| 377 | |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 378 | #ifdef SUN3_SCSI_VME |
| 379 | dregs->csr &= ~CSR_DMA_ENABLE; |
| 380 | #endif |
| 381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | if(csr & ~CSR_GOOD) { |
| 383 | if(csr & CSR_DMA_BUSERR) { |
| 384 | printk("scsi%d: bus error in dma\n", default_instance->host_no); |
| 385 | } |
| 386 | |
| 387 | if(csr & CSR_DMA_CONFLICT) { |
| 388 | printk("scsi%d: dma conflict\n", default_instance->host_no); |
| 389 | } |
| 390 | handled = 1; |
| 391 | } |
| 392 | |
| 393 | if(csr & (CSR_SDB_INT | CSR_DMA_INT)) { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 394 | NCR5380_intr(irq, dummy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | handled = 1; |
| 396 | } |
| 397 | |
| 398 | return IRQ_RETVAL(handled); |
| 399 | } |
| 400 | |
| 401 | /* |
| 402 | * Debug stuff - to be called on NMI, or sysrq key. Use at your own risk; |
| 403 | * reentering NCR5380_print_status seems to have ugly side effects |
| 404 | */ |
| 405 | |
| 406 | /* this doesn't seem to get used at all -- sam */ |
| 407 | #if 0 |
| 408 | void sun3_sun3_debug (void) |
| 409 | { |
| 410 | unsigned long flags; |
| 411 | NCR5380_local_declare(); |
| 412 | |
| 413 | if (default_instance) { |
| 414 | local_irq_save(flags); |
| 415 | NCR5380_print_status(default_instance); |
| 416 | local_irq_restore(flags); |
| 417 | } |
| 418 | } |
| 419 | #endif |
| 420 | |
| 421 | |
| 422 | /* sun3scsi_dma_setup() -- initialize the dma controller for a read/write */ |
| 423 | static unsigned long sun3scsi_dma_setup(void *data, unsigned long count, int write_flag) |
| 424 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | void *addr; |
| 426 | |
| 427 | if(sun3_dma_orig_addr != NULL) |
| 428 | dvma_unmap(sun3_dma_orig_addr); |
| 429 | |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 430 | #ifdef SUN3_SCSI_VME |
| 431 | addr = (void *)dvma_map_vme((unsigned long) data, count); |
| 432 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | addr = (void *)dvma_map((unsigned long) data, count); |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 434 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
| 436 | sun3_dma_orig_addr = addr; |
| 437 | sun3_dma_orig_count = count; |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 438 | |
| 439 | #ifndef SUN3_SCSI_VME |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | dregs->fifo_count = 0; |
| 441 | sun3_udc_write(UDC_RESET, UDC_CSR); |
| 442 | |
| 443 | /* reset fifo */ |
| 444 | dregs->csr &= ~CSR_FIFO; |
| 445 | dregs->csr |= CSR_FIFO; |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 446 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
| 448 | /* set direction */ |
| 449 | if(write_flag) |
| 450 | dregs->csr |= CSR_SEND; |
| 451 | else |
| 452 | dregs->csr &= ~CSR_SEND; |
| 453 | |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 454 | #ifdef SUN3_SCSI_VME |
| 455 | dregs->csr |= CSR_PACK_ENABLE; |
| 456 | |
| 457 | dregs->dma_addr_hi = ((unsigned long)addr >> 16); |
| 458 | dregs->dma_addr_lo = ((unsigned long)addr & 0xffff); |
| 459 | |
| 460 | dregs->dma_count_hi = 0; |
| 461 | dregs->dma_count_lo = 0; |
| 462 | dregs->fifo_count_hi = 0; |
| 463 | dregs->fifo_count = 0; |
| 464 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | /* byte count for fifo */ |
| 466 | dregs->fifo_count = count; |
| 467 | |
| 468 | sun3_udc_write(UDC_RESET, UDC_CSR); |
| 469 | |
| 470 | /* reset fifo */ |
| 471 | dregs->csr &= ~CSR_FIFO; |
| 472 | dregs->csr |= CSR_FIFO; |
| 473 | |
| 474 | if(dregs->fifo_count != count) { |
| 475 | printk("scsi%d: fifo_mismatch %04x not %04x\n", |
| 476 | default_instance->host_no, dregs->fifo_count, |
| 477 | (unsigned int) count); |
Finn Thain | d614f06 | 2014-03-18 11:42:16 +1100 | [diff] [blame] | 478 | NCR5380_dprint(NDEBUG_DMA, default_instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | /* setup udc */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | udc_regs->addr_hi = (((unsigned long)(addr) & 0xff0000) >> 8); |
| 483 | udc_regs->addr_lo = ((unsigned long)(addr) & 0xffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | udc_regs->count = count/2; /* count in words */ |
| 485 | udc_regs->mode_hi = UDC_MODE_HIWORD; |
| 486 | if(write_flag) { |
| 487 | if(count & 1) |
| 488 | udc_regs->count++; |
| 489 | udc_regs->mode_lo = UDC_MODE_LSEND; |
| 490 | udc_regs->rsel = UDC_RSEL_SEND; |
| 491 | } else { |
| 492 | udc_regs->mode_lo = UDC_MODE_LRECV; |
| 493 | udc_regs->rsel = UDC_RSEL_RECV; |
| 494 | } |
| 495 | |
| 496 | /* announce location of regs block */ |
| 497 | sun3_udc_write(((dvma_vtob(udc_regs) & 0xff0000) >> 8), |
| 498 | UDC_CHN_HI); |
| 499 | |
| 500 | sun3_udc_write((dvma_vtob(udc_regs) & 0xffff), UDC_CHN_LO); |
| 501 | |
| 502 | /* set dma master on */ |
| 503 | sun3_udc_write(0xd, UDC_MODE); |
| 504 | |
| 505 | /* interrupt enable */ |
| 506 | sun3_udc_write(UDC_INT_ENABLE, UDC_CSR); |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 507 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
| 509 | return count; |
| 510 | |
| 511 | } |
| 512 | |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 513 | #ifndef SUN3_SCSI_VME |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | static inline unsigned long sun3scsi_dma_count(struct Scsi_Host *instance) |
| 515 | { |
| 516 | unsigned short resid; |
| 517 | |
| 518 | dregs->udc_addr = 0x32; |
| 519 | udelay(SUN3_DMA_DELAY); |
| 520 | resid = dregs->udc_data; |
| 521 | udelay(SUN3_DMA_DELAY); |
| 522 | resid *= 2; |
| 523 | |
| 524 | return (unsigned long) resid; |
| 525 | } |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 526 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | |
| 528 | static inline unsigned long sun3scsi_dma_residual(struct Scsi_Host *instance) |
| 529 | { |
| 530 | return last_residual; |
| 531 | } |
| 532 | |
Henne | 811c936 | 2006-10-03 19:51:59 +0200 | [diff] [blame] | 533 | static inline unsigned long sun3scsi_dma_xfer_len(unsigned long wanted, |
| 534 | struct scsi_cmnd *cmd, |
| 535 | int write_flag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | { |
Christoph Hellwig | 33659eb | 2010-08-07 18:17:56 +0200 | [diff] [blame] | 537 | if (cmd->request->cmd_type == REQ_TYPE_FS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | return wanted; |
| 539 | else |
| 540 | return 0; |
| 541 | } |
| 542 | |
| 543 | static inline int sun3scsi_dma_start(unsigned long count, unsigned char *data) |
| 544 | { |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 545 | #ifdef SUN3_SCSI_VME |
| 546 | unsigned short csr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 548 | csr = dregs->csr; |
| 549 | |
| 550 | dregs->dma_count_hi = (sun3_dma_orig_count >> 16); |
| 551 | dregs->dma_count_lo = (sun3_dma_orig_count & 0xffff); |
| 552 | |
| 553 | dregs->fifo_count_hi = (sun3_dma_orig_count >> 16); |
| 554 | dregs->fifo_count = (sun3_dma_orig_count & 0xffff); |
| 555 | |
| 556 | /* if(!(csr & CSR_DMA_ENABLE)) |
| 557 | * dregs->csr |= CSR_DMA_ENABLE; |
| 558 | */ |
| 559 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | sun3_udc_write(UDC_CHN_START, UDC_CSR); |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 561 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | |
| 563 | return 0; |
| 564 | } |
| 565 | |
| 566 | /* clean up after our dma is done */ |
| 567 | static int sun3scsi_dma_finish(int write_flag) |
| 568 | { |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 569 | unsigned short __maybe_unused count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | unsigned short fifo; |
| 571 | int ret = 0; |
| 572 | |
| 573 | sun3_dma_active = 0; |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 574 | |
| 575 | #ifdef SUN3_SCSI_VME |
| 576 | dregs->csr &= ~CSR_DMA_ENABLE; |
| 577 | |
| 578 | fifo = dregs->fifo_count; |
| 579 | if (write_flag) { |
| 580 | if ((fifo > 0) && (fifo < sun3_dma_orig_count)) |
| 581 | fifo++; |
| 582 | } |
| 583 | |
| 584 | last_residual = fifo; |
| 585 | /* empty bytes from the fifo which didn't make it */ |
| 586 | if ((!write_flag) && (dregs->csr & CSR_LEFT)) { |
| 587 | unsigned char *vaddr; |
| 588 | |
| 589 | vaddr = (unsigned char *)dvma_vmetov(sun3_dma_orig_addr); |
| 590 | |
| 591 | vaddr += (sun3_dma_orig_count - fifo); |
| 592 | vaddr--; |
| 593 | |
| 594 | switch (dregs->csr & CSR_LEFT) { |
| 595 | case CSR_LEFT_3: |
| 596 | *vaddr = (dregs->bpack_lo & 0xff00) >> 8; |
| 597 | vaddr--; |
| 598 | |
| 599 | case CSR_LEFT_2: |
| 600 | *vaddr = (dregs->bpack_hi & 0x00ff); |
| 601 | vaddr--; |
| 602 | |
| 603 | case CSR_LEFT_1: |
| 604 | *vaddr = (dregs->bpack_hi & 0xff00) >> 8; |
| 605 | break; |
| 606 | } |
| 607 | } |
| 608 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | // check to empty the fifo on a read |
| 610 | if(!write_flag) { |
| 611 | int tmo = 20000; /* .2 sec */ |
| 612 | |
| 613 | while(1) { |
| 614 | if(dregs->csr & CSR_FIFO_EMPTY) |
| 615 | break; |
| 616 | |
| 617 | if(--tmo <= 0) { |
| 618 | printk("sun3scsi: fifo failed to empty!\n"); |
| 619 | return 1; |
| 620 | } |
| 621 | udelay(10); |
| 622 | } |
| 623 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
| 625 | count = sun3scsi_dma_count(default_instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
| 627 | fifo = dregs->fifo_count; |
| 628 | last_residual = fifo; |
| 629 | |
| 630 | /* empty bytes from the fifo which didn't make it */ |
| 631 | if((!write_flag) && (count - fifo) == 2) { |
| 632 | unsigned short data; |
| 633 | unsigned char *vaddr; |
| 634 | |
| 635 | data = dregs->fifo_data; |
| 636 | vaddr = (unsigned char *)dvma_btov(sun3_dma_orig_addr); |
| 637 | |
| 638 | vaddr += (sun3_dma_orig_count - fifo); |
| 639 | |
| 640 | vaddr[-2] = (data & 0xff00) >> 8; |
| 641 | vaddr[-1] = (data & 0xff); |
| 642 | } |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 643 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
| 645 | dvma_unmap(sun3_dma_orig_addr); |
| 646 | sun3_dma_orig_addr = NULL; |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 647 | |
| 648 | #ifdef SUN3_SCSI_VME |
| 649 | dregs->dma_addr_hi = 0; |
| 650 | dregs->dma_addr_lo = 0; |
| 651 | dregs->dma_count_hi = 0; |
| 652 | dregs->dma_count_lo = 0; |
| 653 | |
| 654 | dregs->fifo_count = 0; |
| 655 | dregs->fifo_count_hi = 0; |
| 656 | |
| 657 | dregs->csr &= ~CSR_SEND; |
| 658 | /* dregs->csr |= CSR_DMA_ENABLE; */ |
| 659 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | sun3_udc_write(UDC_RESET, UDC_CSR); |
| 661 | dregs->fifo_count = 0; |
| 662 | dregs->csr &= ~CSR_SEND; |
| 663 | |
| 664 | /* reset fifo */ |
| 665 | dregs->csr &= ~CSR_FIFO; |
| 666 | dregs->csr |= CSR_FIFO; |
Finn Thain | 757f5ba | 2014-03-18 11:42:24 +1100 | [diff] [blame] | 667 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
| 669 | sun3_dma_setup_done = NULL; |
| 670 | |
| 671 | return ret; |
| 672 | |
| 673 | } |
| 674 | |
| 675 | #include "sun3_NCR5380.c" |
| 676 | |
Christoph Hellwig | d0be4a7d | 2005-10-31 18:31:40 +0100 | [diff] [blame] | 677 | static struct scsi_host_template driver_template = { |
Geert Uytterhoeven | 9dcc26c | 2013-04-10 13:52:09 +0200 | [diff] [blame] | 678 | .show_info = sun3scsi_show_info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | .name = SUN3_SCSI_NAME, |
| 680 | .detect = sun3scsi_detect, |
| 681 | .release = sun3scsi_release, |
| 682 | .info = sun3scsi_info, |
| 683 | .queuecommand = sun3scsi_queue_command, |
| 684 | .eh_abort_handler = sun3scsi_abort, |
| 685 | .eh_bus_reset_handler = sun3scsi_bus_reset, |
Finn Thain | d572f65f | 2014-11-12 16:12:00 +1100 | [diff] [blame^] | 686 | .can_queue = 16, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | .this_id = 7, |
Finn Thain | d572f65f | 2014-11-12 16:12:00 +1100 | [diff] [blame^] | 688 | .sg_tablesize = SG_NONE, |
| 689 | .cmd_per_lun = 2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | .use_clustering = DISABLE_CLUSTERING |
| 691 | }; |
| 692 | |
| 693 | |
| 694 | #include "scsi_module.c" |
| 695 | |
| 696 | MODULE_LICENSE("GPL"); |