Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Generic Macintosh NCR5380 driver |
| 3 | * |
| 4 | * Copyright 1998, Michael Schmitz <mschmitz@lbl.gov> |
| 5 | * |
| 6 | * derived in part from: |
| 7 | */ |
| 8 | /* |
| 9 | * Generic Generic NCR5380 driver |
| 10 | * |
| 11 | * Copyright 1995, Russell King |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | */ |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/types.h> |
| 15 | #include <linux/stddef.h> |
| 16 | #include <linux/ctype.h> |
| 17 | #include <linux/delay.h> |
| 18 | |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/signal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/ioport.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/blkdev.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | |
| 26 | #include <asm/io.h> |
| 27 | #include <asm/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | #include <asm/macintosh.h> |
| 30 | #include <asm/macints.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/mac_via.h> |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <scsi/scsi_host.h> |
Finn Thain | 92de383 | 2014-11-12 16:12:04 +1100 | [diff] [blame] | 34 | |
| 35 | /* Definitions for the core NCR5380 driver. */ |
Boaz Harrosh | e744fde | 2007-10-16 10:25:01 +0200 | [diff] [blame] | 36 | |
Boaz Harrosh | e744fde | 2007-10-16 10:25:01 +0200 | [diff] [blame] | 37 | #define PSEUDO_DMA |
| 38 | |
Finn Thain | 92de383 | 2014-11-12 16:12:04 +1100 | [diff] [blame] | 39 | #define NCR5380_implementation_fields /* none */ |
| 40 | #define NCR5380_local_declare() struct Scsi_Host *_instance |
| 41 | #define NCR5380_setup(instance) _instance = instance |
| 42 | |
| 43 | #define NCR5380_read(reg) macscsi_read(_instance, reg) |
| 44 | #define NCR5380_write(reg, value) macscsi_write(_instance, reg, value) |
| 45 | |
| 46 | #define NCR5380_pread macscsi_pread |
| 47 | #define NCR5380_pwrite macscsi_pwrite |
| 48 | |
| 49 | #define NCR5380_intr macscsi_intr |
| 50 | #define NCR5380_queue_command macscsi_queue_command |
| 51 | #define NCR5380_abort macscsi_abort |
| 52 | #define NCR5380_bus_reset macscsi_bus_reset |
| 53 | #define NCR5380_info macscsi_info |
| 54 | #define NCR5380_show_info macscsi_show_info |
| 55 | #define NCR5380_write_info macscsi_write_info |
| 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #include "NCR5380.h" |
| 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #define RESET_BOOT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #ifdef RESET_BOOT |
| 62 | static void mac_scsi_reset_boot(struct Scsi_Host *instance); |
| 63 | #endif |
| 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | static int setup_can_queue = -1; |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 66 | module_param(setup_can_queue, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | static int setup_cmd_per_lun = -1; |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 68 | module_param(setup_cmd_per_lun, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | static int setup_sg_tablesize = -1; |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 70 | module_param(setup_sg_tablesize, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | static int setup_use_pdma = -1; |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 72 | module_param(setup_use_pdma, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | static int setup_use_tagged_queuing = -1; |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 74 | module_param(setup_use_tagged_queuing, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | static int setup_hostid = -1; |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 76 | module_param(setup_hostid, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | /* Time (in jiffies) to wait after a reset; the SCSI standard calls for 250ms, |
| 79 | * we usually do 0.5s to be on the safe side. But Toshiba CD-ROMs once more |
| 80 | * need ten times the standard value... */ |
| 81 | #define TOSHIBA_DELAY |
| 82 | |
| 83 | #ifdef TOSHIBA_DELAY |
| 84 | #define AFTER_RESET_DELAY (5*HZ/2) |
| 85 | #else |
| 86 | #define AFTER_RESET_DELAY (HZ/2) |
| 87 | #endif |
| 88 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame^] | 89 | static unsigned char *mac_scsi_regp; |
| 90 | static unsigned char *mac_scsi_drq; |
| 91 | static unsigned char *mac_scsi_nodrq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 93 | |
| 94 | /* |
| 95 | * NCR 5380 register access functions |
| 96 | */ |
| 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | static __inline__ char macscsi_read(struct Scsi_Host *instance, int reg) |
| 99 | { |
| 100 | return in_8(instance->io_port + (reg<<4)); |
| 101 | } |
| 102 | |
| 103 | static __inline__ void macscsi_write(struct Scsi_Host *instance, int reg, int value) |
| 104 | { |
| 105 | out_8(instance->io_port + (reg<<4), value); |
| 106 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 108 | #ifndef MODULE |
| 109 | static int __init mac_scsi_setup(char *str) |
| 110 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | int ints[7]; |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 112 | |
| 113 | (void)get_options(str, ARRAY_SIZE(ints), ints); |
| 114 | |
| 115 | if (ints[0] < 1 || ints[0] > 6) { |
| 116 | pr_err("Usage: mac5380=<can_queue>[,<cmd_per_lun>[,<sg_tablesize>[,<hostid>[,<use_tags>[,<use_pdma>]]]]]\n"); |
| 117 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 119 | if (ints[0] >= 1) |
| 120 | setup_can_queue = ints[1]; |
| 121 | if (ints[0] >= 2) |
| 122 | setup_cmd_per_lun = ints[2]; |
| 123 | if (ints[0] >= 3) |
| 124 | setup_sg_tablesize = ints[3]; |
| 125 | if (ints[0] >= 4) |
| 126 | setup_hostid = ints[4]; |
| 127 | if (ints[0] >= 5) |
| 128 | setup_use_tagged_queuing = ints[5]; |
| 129 | if (ints[0] >= 6) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | setup_use_pdma = ints[6]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | return 1; |
| 132 | } |
| 133 | |
| 134 | __setup("mac5380=", mac_scsi_setup); |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 135 | #endif /* !MODULE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
| 137 | /* |
Christoph Hellwig | d0be4a7d | 2005-10-31 18:31:40 +0100 | [diff] [blame] | 138 | * Function : int macscsi_detect(struct scsi_host_template * tpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | * |
| 140 | * Purpose : initializes mac NCR5380 driver based on the |
| 141 | * command line / compile time port and irq definitions. |
| 142 | * |
| 143 | * Inputs : tpnt - template for this SCSI adapter. |
| 144 | * |
| 145 | * Returns : 1 if a host adapter was found, 0 if not. |
| 146 | * |
| 147 | */ |
| 148 | |
Geert Uytterhoeven | 70c26cf | 2011-06-13 20:39:16 +0200 | [diff] [blame] | 149 | int __init macscsi_detect(struct scsi_host_template * tpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | { |
| 151 | static int called = 0; |
| 152 | int flags = 0; |
| 153 | struct Scsi_Host *instance; |
| 154 | |
| 155 | if (!MACH_IS_MAC || called) |
| 156 | return( 0 ); |
| 157 | |
| 158 | if (macintosh_config->scsi_type != MAC_SCSI_OLD) |
| 159 | return( 0 ); |
| 160 | |
Finn Thain | d572f65 | 2014-11-12 16:12:00 +1100 | [diff] [blame] | 161 | if (setup_can_queue > 0) |
| 162 | tpnt->can_queue = setup_can_queue; |
| 163 | if (setup_cmd_per_lun > 0) |
| 164 | tpnt->cmd_per_lun = setup_cmd_per_lun; |
| 165 | if (setup_sg_tablesize >= 0) |
| 166 | tpnt->sg_tablesize = setup_sg_tablesize; |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 167 | if (setup_hostid >= 0) |
| 168 | tpnt->this_id = setup_hostid & 7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
| 170 | #ifdef SUPPORT_TAGS |
| 171 | if (setup_use_tagged_queuing < 0) |
Finn Thain | d572f65 | 2014-11-12 16:12:00 +1100 | [diff] [blame] | 172 | setup_use_tagged_queuing = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | #endif |
| 174 | |
| 175 | /* Once we support multiple 5380s (e.g. DuoDock) we'll do |
| 176 | something different here */ |
| 177 | instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata)); |
Alan | 603f202 | 2013-12-03 16:11:04 +0000 | [diff] [blame] | 178 | if (instance == NULL) |
| 179 | return 0; |
Geert Uytterhoeven | 5db5c50 | 2011-06-13 20:39:17 +0200 | [diff] [blame] | 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | if (macintosh_config->ident == MAC_MODEL_IIFX) { |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 182 | mac_scsi_regp = (unsigned char *) VIA1_BASE + 0x8000; |
| 183 | mac_scsi_drq = (unsigned char *) VIA1_BASE + 0xE000; |
| 184 | mac_scsi_nodrq = (unsigned char *) VIA1_BASE + 0xC000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | /* The IIFX should be able to do true DMA, but pseudo-dma doesn't work */ |
| 186 | flags = FLAG_NO_PSEUDO_DMA; |
| 187 | } else { |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 188 | mac_scsi_regp = (unsigned char *) VIA1_BASE + 0x10000; |
| 189 | mac_scsi_drq = (unsigned char *) VIA1_BASE + 0x6000; |
| 190 | mac_scsi_nodrq = (unsigned char *) VIA1_BASE + 0x12000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | if (! setup_use_pdma) |
| 194 | flags = FLAG_NO_PSEUDO_DMA; |
| 195 | |
| 196 | instance->io_port = (unsigned long) mac_scsi_regp; |
| 197 | instance->irq = IRQ_MAC_SCSI; |
| 198 | |
| 199 | #ifdef RESET_BOOT |
| 200 | mac_scsi_reset_boot(instance); |
| 201 | #endif |
| 202 | |
| 203 | NCR5380_init(instance, flags); |
| 204 | |
| 205 | instance->n_io_port = 255; |
| 206 | |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame] | 207 | if (instance->irq != NO_IRQ) |
Geert Uytterhoeven | dddaaf7 | 2011-12-11 10:04:51 +0100 | [diff] [blame] | 208 | if (request_irq(instance->irq, NCR5380_intr, 0, "ncr5380", instance)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | printk(KERN_WARNING "scsi%d: IRQ%d not free, interrupts disabled\n", |
| 210 | instance->host_no, instance->irq); |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame] | 211 | instance->irq = NO_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | called = 1; |
| 215 | return 1; |
| 216 | } |
| 217 | |
| 218 | int macscsi_release (struct Scsi_Host *shpnt) |
| 219 | { |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame] | 220 | if (shpnt->irq != NO_IRQ) |
Jeff Garzik | 1e64166 | 2007-11-11 19:52:05 -0500 | [diff] [blame] | 221 | free_irq(shpnt->irq, shpnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | NCR5380_exit(shpnt); |
| 223 | |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | #ifdef RESET_BOOT |
| 228 | /* |
| 229 | * Our 'bus reset on boot' function |
| 230 | */ |
| 231 | |
| 232 | static void mac_scsi_reset_boot(struct Scsi_Host *instance) |
| 233 | { |
| 234 | unsigned long end; |
| 235 | |
| 236 | NCR5380_local_declare(); |
| 237 | NCR5380_setup(instance); |
| 238 | |
| 239 | /* |
| 240 | * Do a SCSI reset to clean up the bus during initialization. No messing |
| 241 | * with the queues, interrupts, or locks necessary here. |
| 242 | */ |
| 243 | |
| 244 | printk(KERN_INFO "Macintosh SCSI: resetting the SCSI bus..." ); |
| 245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | /* get in phase */ |
| 247 | NCR5380_write( TARGET_COMMAND_REG, |
| 248 | PHASE_SR_TO_TCR( NCR5380_read(STATUS_REG) )); |
| 249 | |
| 250 | /* assert RST */ |
| 251 | NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST ); |
| 252 | /* The min. reset hold time is 25us, so 40us should be enough */ |
| 253 | udelay( 50 ); |
| 254 | /* reset RST and interrupt */ |
| 255 | NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE ); |
| 256 | NCR5380_read( RESET_PARITY_INTERRUPT_REG ); |
| 257 | |
| 258 | for( end = jiffies + AFTER_RESET_DELAY; time_before(jiffies, end); ) |
| 259 | barrier(); |
| 260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | printk(KERN_INFO " done\n" ); |
| 262 | } |
| 263 | #endif |
| 264 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame^] | 265 | #ifdef PSEUDO_DMA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | /* |
| 267 | Pseudo-DMA: (Ove Edlund) |
| 268 | The code attempts to catch bus errors that occur if one for example |
| 269 | "trips over the cable". |
| 270 | XXX: Since bus errors in the PDMA routines never happen on my |
| 271 | computer, the bus error code is untested. |
| 272 | If the code works as intended, a bus error results in Pseudo-DMA |
| 273 | beeing disabled, meaning that the driver switches to slow handshake. |
| 274 | If bus errors are NOT extremely rare, this has to be changed. |
| 275 | */ |
| 276 | |
| 277 | #define CP_IO_TO_MEM(s,d,len) \ |
| 278 | __asm__ __volatile__ \ |
| 279 | (" cmp.w #4,%2\n" \ |
| 280 | " bls 8f\n" \ |
| 281 | " move.w %1,%%d0\n" \ |
| 282 | " neg.b %%d0\n" \ |
| 283 | " and.w #3,%%d0\n" \ |
| 284 | " sub.w %%d0,%2\n" \ |
| 285 | " bra 2f\n" \ |
| 286 | " 1: move.b (%0),(%1)+\n" \ |
| 287 | " 2: dbf %%d0,1b\n" \ |
| 288 | " move.w %2,%%d0\n" \ |
| 289 | " lsr.w #5,%%d0\n" \ |
| 290 | " bra 4f\n" \ |
| 291 | " 3: move.l (%0),(%1)+\n" \ |
| 292 | "31: move.l (%0),(%1)+\n" \ |
| 293 | "32: move.l (%0),(%1)+\n" \ |
| 294 | "33: move.l (%0),(%1)+\n" \ |
| 295 | "34: move.l (%0),(%1)+\n" \ |
| 296 | "35: move.l (%0),(%1)+\n" \ |
| 297 | "36: move.l (%0),(%1)+\n" \ |
| 298 | "37: move.l (%0),(%1)+\n" \ |
| 299 | " 4: dbf %%d0,3b\n" \ |
| 300 | " move.w %2,%%d0\n" \ |
| 301 | " lsr.w #2,%%d0\n" \ |
| 302 | " and.w #7,%%d0\n" \ |
| 303 | " bra 6f\n" \ |
| 304 | " 5: move.l (%0),(%1)+\n" \ |
| 305 | " 6: dbf %%d0,5b\n" \ |
| 306 | " and.w #3,%2\n" \ |
| 307 | " bra 8f\n" \ |
| 308 | " 7: move.b (%0),(%1)+\n" \ |
| 309 | " 8: dbf %2,7b\n" \ |
| 310 | " moveq.l #0, %2\n" \ |
| 311 | " 9: \n" \ |
| 312 | ".section .fixup,\"ax\"\n" \ |
| 313 | " .even\n" \ |
| 314 | "90: moveq.l #1, %2\n" \ |
| 315 | " jra 9b\n" \ |
| 316 | ".previous\n" \ |
| 317 | ".section __ex_table,\"a\"\n" \ |
| 318 | " .align 4\n" \ |
| 319 | " .long 1b,90b\n" \ |
| 320 | " .long 3b,90b\n" \ |
| 321 | " .long 31b,90b\n" \ |
| 322 | " .long 32b,90b\n" \ |
| 323 | " .long 33b,90b\n" \ |
| 324 | " .long 34b,90b\n" \ |
| 325 | " .long 35b,90b\n" \ |
| 326 | " .long 36b,90b\n" \ |
| 327 | " .long 37b,90b\n" \ |
| 328 | " .long 5b,90b\n" \ |
| 329 | " .long 7b,90b\n" \ |
| 330 | ".previous" \ |
| 331 | : "=a"(s), "=a"(d), "=d"(len) \ |
| 332 | : "0"(s), "1"(d), "2"(len) \ |
| 333 | : "d0") |
| 334 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame^] | 335 | static int macscsi_pread(struct Scsi_Host *instance, |
| 336 | unsigned char *dst, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | { |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame^] | 338 | unsigned char *d; |
| 339 | unsigned char *s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame^] | 341 | NCR5380_local_declare(); |
| 342 | NCR5380_setup(instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame^] | 344 | s = mac_scsi_drq + (INPUT_DATA_REG << 4); |
| 345 | d = dst; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame^] | 347 | /* These conditions are derived from MacOS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame^] | 349 | while (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ) && |
| 350 | !(NCR5380_read(STATUS_REG) & SR_REQ)) |
| 351 | ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame^] | 353 | if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ) && |
| 354 | (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH)) { |
| 355 | pr_err("Error in macscsi_pread\n"); |
| 356 | return -1; |
| 357 | } |
| 358 | |
| 359 | CP_IO_TO_MEM(s, d, len); |
| 360 | |
| 361 | if (len != 0) { |
| 362 | pr_notice("Bus error in macscsi_pread\n"); |
| 363 | return -1; |
| 364 | } |
| 365 | |
| 366 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | |
| 370 | #define CP_MEM_TO_IO(s,d,len) \ |
| 371 | __asm__ __volatile__ \ |
| 372 | (" cmp.w #4,%2\n" \ |
| 373 | " bls 8f\n" \ |
| 374 | " move.w %0,%%d0\n" \ |
| 375 | " neg.b %%d0\n" \ |
| 376 | " and.w #3,%%d0\n" \ |
| 377 | " sub.w %%d0,%2\n" \ |
| 378 | " bra 2f\n" \ |
| 379 | " 1: move.b (%0)+,(%1)\n" \ |
| 380 | " 2: dbf %%d0,1b\n" \ |
| 381 | " move.w %2,%%d0\n" \ |
| 382 | " lsr.w #5,%%d0\n" \ |
| 383 | " bra 4f\n" \ |
| 384 | " 3: move.l (%0)+,(%1)\n" \ |
| 385 | "31: move.l (%0)+,(%1)\n" \ |
| 386 | "32: move.l (%0)+,(%1)\n" \ |
| 387 | "33: move.l (%0)+,(%1)\n" \ |
| 388 | "34: move.l (%0)+,(%1)\n" \ |
| 389 | "35: move.l (%0)+,(%1)\n" \ |
| 390 | "36: move.l (%0)+,(%1)\n" \ |
| 391 | "37: move.l (%0)+,(%1)\n" \ |
| 392 | " 4: dbf %%d0,3b\n" \ |
| 393 | " move.w %2,%%d0\n" \ |
| 394 | " lsr.w #2,%%d0\n" \ |
| 395 | " and.w #7,%%d0\n" \ |
| 396 | " bra 6f\n" \ |
| 397 | " 5: move.l (%0)+,(%1)\n" \ |
| 398 | " 6: dbf %%d0,5b\n" \ |
| 399 | " and.w #3,%2\n" \ |
| 400 | " bra 8f\n" \ |
| 401 | " 7: move.b (%0)+,(%1)\n" \ |
| 402 | " 8: dbf %2,7b\n" \ |
| 403 | " moveq.l #0, %2\n" \ |
| 404 | " 9: \n" \ |
| 405 | ".section .fixup,\"ax\"\n" \ |
| 406 | " .even\n" \ |
| 407 | "90: moveq.l #1, %2\n" \ |
| 408 | " jra 9b\n" \ |
| 409 | ".previous\n" \ |
| 410 | ".section __ex_table,\"a\"\n" \ |
| 411 | " .align 4\n" \ |
| 412 | " .long 1b,90b\n" \ |
| 413 | " .long 3b,90b\n" \ |
| 414 | " .long 31b,90b\n" \ |
| 415 | " .long 32b,90b\n" \ |
| 416 | " .long 33b,90b\n" \ |
| 417 | " .long 34b,90b\n" \ |
| 418 | " .long 35b,90b\n" \ |
| 419 | " .long 36b,90b\n" \ |
| 420 | " .long 37b,90b\n" \ |
| 421 | " .long 5b,90b\n" \ |
| 422 | " .long 7b,90b\n" \ |
| 423 | ".previous" \ |
| 424 | : "=a"(s), "=a"(d), "=d"(len) \ |
| 425 | : "0"(s), "1"(d), "2"(len) \ |
| 426 | : "d0") |
| 427 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame^] | 428 | static int macscsi_pwrite(struct Scsi_Host *instance, |
| 429 | unsigned char *src, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | { |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame^] | 431 | unsigned char *s; |
| 432 | unsigned char *d; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame^] | 434 | NCR5380_local_declare(); |
| 435 | NCR5380_setup(instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame^] | 437 | s = src; |
| 438 | d = mac_scsi_drq + (OUTPUT_DATA_REG << 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame^] | 440 | /* These conditions are derived from MacOS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame^] | 442 | while (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ) && |
| 443 | (!(NCR5380_read(STATUS_REG) & SR_REQ) || |
| 444 | (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH))) |
| 445 | ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame^] | 447 | if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)) { |
| 448 | pr_err("Error in macscsi_pwrite\n"); |
| 449 | return -1; |
| 450 | } |
| 451 | |
| 452 | CP_MEM_TO_IO(s, d, len); |
| 453 | |
| 454 | if (len != 0) { |
| 455 | pr_notice("Bus error in macscsi_pwrite\n"); |
| 456 | return -1; |
| 457 | } |
| 458 | |
| 459 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | } |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame^] | 461 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | #include "NCR5380.c" |
| 464 | |
Christoph Hellwig | d0be4a7d | 2005-10-31 18:31:40 +0100 | [diff] [blame] | 465 | static struct scsi_host_template driver_template = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | .proc_name = "Mac5380", |
Al Viro | dd7ab71 | 2013-03-31 01:15:54 -0400 | [diff] [blame] | 467 | .show_info = macscsi_show_info, |
| 468 | .write_info = macscsi_write_info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | .name = "Macintosh NCR5380 SCSI", |
| 470 | .detect = macscsi_detect, |
| 471 | .release = macscsi_release, |
| 472 | .info = macscsi_info, |
| 473 | .queuecommand = macscsi_queue_command, |
| 474 | .eh_abort_handler = macscsi_abort, |
| 475 | .eh_bus_reset_handler = macscsi_bus_reset, |
Finn Thain | d572f65 | 2014-11-12 16:12:00 +1100 | [diff] [blame] | 476 | .can_queue = 16, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | .this_id = 7, |
| 478 | .sg_tablesize = SG_ALL, |
Finn Thain | d572f65 | 2014-11-12 16:12:00 +1100 | [diff] [blame] | 479 | .cmd_per_lun = 2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | .use_clustering = DISABLE_CLUSTERING |
| 481 | }; |
| 482 | |
| 483 | |
| 484 | #include "scsi_module.c" |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 485 | |
| 486 | MODULE_LICENSE("GPL"); |