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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/ioport.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/blkdev.h> |
| 19 | #include <linux/interrupt.h> |
Finn Thain | cbad48d | 2014-11-12 16:12:07 +1100 | [diff] [blame] | 20 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Finn Thain | cbad48d | 2014-11-12 16:12:07 +1100 | [diff] [blame] | 22 | #include <asm/hwtest.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <asm/macints.h> |
Finn Thain | cbad48d | 2014-11-12 16:12:07 +1100 | [diff] [blame] | 25 | #include <asm/setup.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <scsi/scsi_host.h> |
Finn Thain | 92de383 | 2014-11-12 16:12:04 +1100 | [diff] [blame] | 28 | |
| 29 | /* Definitions for the core NCR5380 driver. */ |
Boaz Harrosh | e744fde | 2007-10-16 10:25:01 +0200 | [diff] [blame] | 30 | |
Boaz Harrosh | e744fde | 2007-10-16 10:25:01 +0200 | [diff] [blame] | 31 | #define PSEUDO_DMA |
| 32 | |
Finn Thain | cbad48d | 2014-11-12 16:12:07 +1100 | [diff] [blame] | 33 | #define NCR5380_implementation_fields unsigned char *pdma_base |
Finn Thain | 92de383 | 2014-11-12 16:12:04 +1100 | [diff] [blame] | 34 | |
Finn Thain | 54d8fe4 | 2016-01-03 16:05:06 +1100 | [diff] [blame] | 35 | #define NCR5380_read(reg) macscsi_read(instance, reg) |
| 36 | #define NCR5380_write(reg, value) macscsi_write(instance, reg, value) |
Finn Thain | 92de383 | 2014-11-12 16:12:04 +1100 | [diff] [blame] | 37 | |
| 38 | #define NCR5380_pread macscsi_pread |
| 39 | #define NCR5380_pwrite macscsi_pwrite |
Finn Thain | ff3d457 | 2016-01-03 16:05:25 +1100 | [diff] [blame] | 40 | #define NCR5380_dma_xfer_len(instance, cmd, phase) (cmd->transfersize) |
Finn Thain | 92de383 | 2014-11-12 16:12:04 +1100 | [diff] [blame] | 41 | |
| 42 | #define NCR5380_intr macscsi_intr |
| 43 | #define NCR5380_queue_command macscsi_queue_command |
| 44 | #define NCR5380_abort macscsi_abort |
| 45 | #define NCR5380_bus_reset macscsi_bus_reset |
| 46 | #define NCR5380_info macscsi_info |
| 47 | #define NCR5380_show_info macscsi_show_info |
| 48 | #define NCR5380_write_info macscsi_write_info |
| 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #include "NCR5380.h" |
| 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | static int setup_can_queue = -1; |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 53 | module_param(setup_can_queue, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | static int setup_cmd_per_lun = -1; |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 55 | module_param(setup_cmd_per_lun, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | static int setup_sg_tablesize = -1; |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 57 | module_param(setup_sg_tablesize, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | static int setup_use_pdma = -1; |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 59 | module_param(setup_use_pdma, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | static int setup_use_tagged_queuing = -1; |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 61 | module_param(setup_use_tagged_queuing, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | static int setup_hostid = -1; |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 63 | module_param(setup_hostid, int, 0); |
Finn Thain | 9c3f0e2 | 2016-01-03 16:05:11 +1100 | [diff] [blame] | 64 | static int setup_toshiba_delay = -1; |
| 65 | module_param(setup_toshiba_delay, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | /* |
| 68 | * NCR 5380 register access functions |
| 69 | */ |
| 70 | |
Finn Thain | cbad48d | 2014-11-12 16:12:07 +1100 | [diff] [blame] | 71 | static inline char macscsi_read(struct Scsi_Host *instance, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | { |
Finn Thain | cbad48d | 2014-11-12 16:12:07 +1100 | [diff] [blame] | 73 | return in_8(instance->base + (reg << 4)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Finn Thain | cbad48d | 2014-11-12 16:12:07 +1100 | [diff] [blame] | 76 | static inline void macscsi_write(struct Scsi_Host *instance, int reg, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
Finn Thain | cbad48d | 2014-11-12 16:12:07 +1100 | [diff] [blame] | 78 | out_8(instance->base + (reg << 4), value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 81 | #ifndef MODULE |
| 82 | static int __init mac_scsi_setup(char *str) |
| 83 | { |
Finn Thain | 9c3f0e2 | 2016-01-03 16:05:11 +1100 | [diff] [blame] | 84 | int ints[8]; |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 85 | |
| 86 | (void)get_options(str, ARRAY_SIZE(ints), ints); |
| 87 | |
Finn Thain | 9c3f0e2 | 2016-01-03 16:05:11 +1100 | [diff] [blame] | 88 | if (ints[0] < 1) { |
| 89 | pr_err("Usage: mac5380=<can_queue>[,<cmd_per_lun>[,<sg_tablesize>[,<hostid>[,<use_tags>[,<use_pdma>[,<toshiba_delay>]]]]]]\n"); |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 90 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 92 | if (ints[0] >= 1) |
| 93 | setup_can_queue = ints[1]; |
| 94 | if (ints[0] >= 2) |
| 95 | setup_cmd_per_lun = ints[2]; |
| 96 | if (ints[0] >= 3) |
| 97 | setup_sg_tablesize = ints[3]; |
| 98 | if (ints[0] >= 4) |
| 99 | setup_hostid = ints[4]; |
| 100 | if (ints[0] >= 5) |
| 101 | setup_use_tagged_queuing = ints[5]; |
| 102 | if (ints[0] >= 6) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | setup_use_pdma = ints[6]; |
Finn Thain | 9c3f0e2 | 2016-01-03 16:05:11 +1100 | [diff] [blame] | 104 | if (ints[0] >= 7) |
| 105 | setup_toshiba_delay = ints[7]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | return 1; |
| 107 | } |
| 108 | |
| 109 | __setup("mac5380=", mac_scsi_setup); |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 110 | #endif /* !MODULE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame] | 112 | #ifdef PSEUDO_DMA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | /* |
| 114 | Pseudo-DMA: (Ove Edlund) |
| 115 | The code attempts to catch bus errors that occur if one for example |
| 116 | "trips over the cable". |
| 117 | XXX: Since bus errors in the PDMA routines never happen on my |
| 118 | computer, the bus error code is untested. |
| 119 | If the code works as intended, a bus error results in Pseudo-DMA |
Finn Thain | 542cb45 | 2014-10-03 11:42:17 +1000 | [diff] [blame] | 120 | being disabled, meaning that the driver switches to slow handshake. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | If bus errors are NOT extremely rare, this has to be changed. |
| 122 | */ |
| 123 | |
| 124 | #define CP_IO_TO_MEM(s,d,len) \ |
| 125 | __asm__ __volatile__ \ |
| 126 | (" cmp.w #4,%2\n" \ |
| 127 | " bls 8f\n" \ |
| 128 | " move.w %1,%%d0\n" \ |
| 129 | " neg.b %%d0\n" \ |
| 130 | " and.w #3,%%d0\n" \ |
| 131 | " sub.w %%d0,%2\n" \ |
| 132 | " bra 2f\n" \ |
| 133 | " 1: move.b (%0),(%1)+\n" \ |
| 134 | " 2: dbf %%d0,1b\n" \ |
| 135 | " move.w %2,%%d0\n" \ |
| 136 | " lsr.w #5,%%d0\n" \ |
| 137 | " bra 4f\n" \ |
| 138 | " 3: move.l (%0),(%1)+\n" \ |
| 139 | "31: move.l (%0),(%1)+\n" \ |
| 140 | "32: move.l (%0),(%1)+\n" \ |
| 141 | "33: move.l (%0),(%1)+\n" \ |
| 142 | "34: move.l (%0),(%1)+\n" \ |
| 143 | "35: move.l (%0),(%1)+\n" \ |
| 144 | "36: move.l (%0),(%1)+\n" \ |
| 145 | "37: move.l (%0),(%1)+\n" \ |
| 146 | " 4: dbf %%d0,3b\n" \ |
| 147 | " move.w %2,%%d0\n" \ |
| 148 | " lsr.w #2,%%d0\n" \ |
| 149 | " and.w #7,%%d0\n" \ |
| 150 | " bra 6f\n" \ |
| 151 | " 5: move.l (%0),(%1)+\n" \ |
| 152 | " 6: dbf %%d0,5b\n" \ |
| 153 | " and.w #3,%2\n" \ |
| 154 | " bra 8f\n" \ |
| 155 | " 7: move.b (%0),(%1)+\n" \ |
| 156 | " 8: dbf %2,7b\n" \ |
| 157 | " moveq.l #0, %2\n" \ |
| 158 | " 9: \n" \ |
| 159 | ".section .fixup,\"ax\"\n" \ |
| 160 | " .even\n" \ |
| 161 | "90: moveq.l #1, %2\n" \ |
| 162 | " jra 9b\n" \ |
| 163 | ".previous\n" \ |
| 164 | ".section __ex_table,\"a\"\n" \ |
| 165 | " .align 4\n" \ |
| 166 | " .long 1b,90b\n" \ |
| 167 | " .long 3b,90b\n" \ |
| 168 | " .long 31b,90b\n" \ |
| 169 | " .long 32b,90b\n" \ |
| 170 | " .long 33b,90b\n" \ |
| 171 | " .long 34b,90b\n" \ |
| 172 | " .long 35b,90b\n" \ |
| 173 | " .long 36b,90b\n" \ |
| 174 | " .long 37b,90b\n" \ |
| 175 | " .long 5b,90b\n" \ |
| 176 | " .long 7b,90b\n" \ |
| 177 | ".previous" \ |
| 178 | : "=a"(s), "=a"(d), "=d"(len) \ |
| 179 | : "0"(s), "1"(d), "2"(len) \ |
| 180 | : "d0") |
| 181 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame] | 182 | static int macscsi_pread(struct Scsi_Host *instance, |
| 183 | unsigned char *dst, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | { |
Finn Thain | cbad48d | 2014-11-12 16:12:07 +1100 | [diff] [blame] | 185 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame] | 186 | unsigned char *d; |
| 187 | unsigned char *s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
Finn Thain | cbad48d | 2014-11-12 16:12:07 +1100 | [diff] [blame] | 189 | s = hostdata->pdma_base + (INPUT_DATA_REG << 4); |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame] | 190 | d = dst; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame] | 192 | /* These conditions are derived from MacOS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame] | 194 | while (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ) && |
| 195 | !(NCR5380_read(STATUS_REG) & SR_REQ)) |
| 196 | ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame] | 198 | if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ) && |
| 199 | (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH)) { |
| 200 | pr_err("Error in macscsi_pread\n"); |
| 201 | return -1; |
| 202 | } |
| 203 | |
| 204 | CP_IO_TO_MEM(s, d, len); |
| 205 | |
| 206 | if (len != 0) { |
| 207 | pr_notice("Bus error in macscsi_pread\n"); |
| 208 | return -1; |
| 209 | } |
| 210 | |
| 211 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | |
| 215 | #define CP_MEM_TO_IO(s,d,len) \ |
| 216 | __asm__ __volatile__ \ |
| 217 | (" cmp.w #4,%2\n" \ |
| 218 | " bls 8f\n" \ |
| 219 | " move.w %0,%%d0\n" \ |
| 220 | " neg.b %%d0\n" \ |
| 221 | " and.w #3,%%d0\n" \ |
| 222 | " sub.w %%d0,%2\n" \ |
| 223 | " bra 2f\n" \ |
| 224 | " 1: move.b (%0)+,(%1)\n" \ |
| 225 | " 2: dbf %%d0,1b\n" \ |
| 226 | " move.w %2,%%d0\n" \ |
| 227 | " lsr.w #5,%%d0\n" \ |
| 228 | " bra 4f\n" \ |
| 229 | " 3: move.l (%0)+,(%1)\n" \ |
| 230 | "31: move.l (%0)+,(%1)\n" \ |
| 231 | "32: move.l (%0)+,(%1)\n" \ |
| 232 | "33: move.l (%0)+,(%1)\n" \ |
| 233 | "34: move.l (%0)+,(%1)\n" \ |
| 234 | "35: move.l (%0)+,(%1)\n" \ |
| 235 | "36: move.l (%0)+,(%1)\n" \ |
| 236 | "37: move.l (%0)+,(%1)\n" \ |
| 237 | " 4: dbf %%d0,3b\n" \ |
| 238 | " move.w %2,%%d0\n" \ |
| 239 | " lsr.w #2,%%d0\n" \ |
| 240 | " and.w #7,%%d0\n" \ |
| 241 | " bra 6f\n" \ |
| 242 | " 5: move.l (%0)+,(%1)\n" \ |
| 243 | " 6: dbf %%d0,5b\n" \ |
| 244 | " and.w #3,%2\n" \ |
| 245 | " bra 8f\n" \ |
| 246 | " 7: move.b (%0)+,(%1)\n" \ |
| 247 | " 8: dbf %2,7b\n" \ |
| 248 | " moveq.l #0, %2\n" \ |
| 249 | " 9: \n" \ |
| 250 | ".section .fixup,\"ax\"\n" \ |
| 251 | " .even\n" \ |
| 252 | "90: moveq.l #1, %2\n" \ |
| 253 | " jra 9b\n" \ |
| 254 | ".previous\n" \ |
| 255 | ".section __ex_table,\"a\"\n" \ |
| 256 | " .align 4\n" \ |
| 257 | " .long 1b,90b\n" \ |
| 258 | " .long 3b,90b\n" \ |
| 259 | " .long 31b,90b\n" \ |
| 260 | " .long 32b,90b\n" \ |
| 261 | " .long 33b,90b\n" \ |
| 262 | " .long 34b,90b\n" \ |
| 263 | " .long 35b,90b\n" \ |
| 264 | " .long 36b,90b\n" \ |
| 265 | " .long 37b,90b\n" \ |
| 266 | " .long 5b,90b\n" \ |
| 267 | " .long 7b,90b\n" \ |
| 268 | ".previous" \ |
| 269 | : "=a"(s), "=a"(d), "=d"(len) \ |
| 270 | : "0"(s), "1"(d), "2"(len) \ |
| 271 | : "d0") |
| 272 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame] | 273 | static int macscsi_pwrite(struct Scsi_Host *instance, |
| 274 | unsigned char *src, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | { |
Finn Thain | cbad48d | 2014-11-12 16:12:07 +1100 | [diff] [blame] | 276 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame] | 277 | unsigned char *s; |
| 278 | unsigned char *d; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame] | 280 | s = src; |
Finn Thain | cbad48d | 2014-11-12 16:12:07 +1100 | [diff] [blame] | 281 | d = hostdata->pdma_base + (OUTPUT_DATA_REG << 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame] | 283 | /* These conditions are derived from MacOS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame] | 285 | while (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ) && |
| 286 | (!(NCR5380_read(STATUS_REG) & SR_REQ) || |
| 287 | (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH))) |
| 288 | ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame] | 290 | if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)) { |
| 291 | pr_err("Error in macscsi_pwrite\n"); |
| 292 | return -1; |
| 293 | } |
| 294 | |
| 295 | CP_MEM_TO_IO(s, d, len); |
| 296 | |
| 297 | if (len != 0) { |
| 298 | pr_notice("Bus error in macscsi_pwrite\n"); |
| 299 | return -1; |
| 300 | } |
| 301 | |
| 302 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
Finn Thain | ffdede6 | 2014-11-12 16:12:06 +1100 | [diff] [blame] | 304 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | #include "NCR5380.c" |
| 307 | |
Finn Thain | cbad48d | 2014-11-12 16:12:07 +1100 | [diff] [blame] | 308 | #define DRV_MODULE_NAME "mac_scsi" |
| 309 | #define PFX DRV_MODULE_NAME ": " |
| 310 | |
| 311 | static struct scsi_host_template mac_scsi_template = { |
Finn Thain | aa2e2cb | 2016-01-03 16:05:48 +1100 | [diff] [blame^] | 312 | .module = THIS_MODULE, |
| 313 | .proc_name = DRV_MODULE_NAME, |
| 314 | .show_info = macscsi_show_info, |
| 315 | .write_info = macscsi_write_info, |
| 316 | .name = "Macintosh NCR5380 SCSI", |
| 317 | .info = macscsi_info, |
| 318 | .queuecommand = macscsi_queue_command, |
| 319 | .eh_abort_handler = macscsi_abort, |
| 320 | .eh_bus_reset_handler = macscsi_bus_reset, |
| 321 | .can_queue = 16, |
| 322 | .this_id = 7, |
| 323 | .sg_tablesize = SG_ALL, |
| 324 | .cmd_per_lun = 2, |
| 325 | .use_clustering = DISABLE_CLUSTERING, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | }; |
| 327 | |
Finn Thain | cbad48d | 2014-11-12 16:12:07 +1100 | [diff] [blame] | 328 | static int __init mac_scsi_probe(struct platform_device *pdev) |
| 329 | { |
| 330 | struct Scsi_Host *instance; |
| 331 | int error; |
| 332 | int host_flags = 0; |
| 333 | struct resource *irq, *pio_mem, *pdma_mem = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
Finn Thain | cbad48d | 2014-11-12 16:12:07 +1100 | [diff] [blame] | 335 | pio_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 336 | if (!pio_mem) |
| 337 | return -ENODEV; |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 338 | |
Finn Thain | cbad48d | 2014-11-12 16:12:07 +1100 | [diff] [blame] | 339 | #ifdef PSEUDO_DMA |
| 340 | pdma_mem = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 341 | #endif |
| 342 | |
| 343 | irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 344 | |
| 345 | if (!hwreg_present((unsigned char *)pio_mem->start + |
| 346 | (STATUS_REG << 4))) { |
| 347 | pr_info(PFX "no device detected at %pap\n", &pio_mem->start); |
| 348 | return -ENODEV; |
| 349 | } |
| 350 | |
| 351 | if (setup_can_queue > 0) |
| 352 | mac_scsi_template.can_queue = setup_can_queue; |
| 353 | if (setup_cmd_per_lun > 0) |
| 354 | mac_scsi_template.cmd_per_lun = setup_cmd_per_lun; |
| 355 | if (setup_sg_tablesize >= 0) |
| 356 | mac_scsi_template.sg_tablesize = setup_sg_tablesize; |
| 357 | if (setup_hostid >= 0) |
| 358 | mac_scsi_template.this_id = setup_hostid & 7; |
Finn Thain | cbad48d | 2014-11-12 16:12:07 +1100 | [diff] [blame] | 359 | if (setup_use_pdma < 0) |
| 360 | setup_use_pdma = 0; |
| 361 | |
| 362 | instance = scsi_host_alloc(&mac_scsi_template, |
| 363 | sizeof(struct NCR5380_hostdata)); |
| 364 | if (!instance) |
| 365 | return -ENOMEM; |
| 366 | |
| 367 | instance->base = pio_mem->start; |
| 368 | if (irq) |
| 369 | instance->irq = irq->start; |
| 370 | else |
| 371 | instance->irq = NO_IRQ; |
| 372 | |
| 373 | if (pdma_mem && setup_use_pdma) { |
| 374 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
| 375 | |
| 376 | hostdata->pdma_base = (unsigned char *)pdma_mem->start; |
| 377 | } else |
| 378 | host_flags |= FLAG_NO_PSEUDO_DMA; |
| 379 | |
Finn Thain | ca513fc | 2014-11-12 16:12:19 +1100 | [diff] [blame] | 380 | #ifdef SUPPORT_TAGS |
| 381 | host_flags |= setup_use_tagged_queuing > 0 ? FLAG_TAGGED_QUEUING : 0; |
| 382 | #endif |
Finn Thain | 9c3f0e2 | 2016-01-03 16:05:11 +1100 | [diff] [blame] | 383 | host_flags |= setup_toshiba_delay > 0 ? FLAG_TOSHIBA_DELAY : 0; |
Finn Thain | ca513fc | 2014-11-12 16:12:19 +1100 | [diff] [blame] | 384 | |
Finn Thain | 0ad0eff | 2016-01-03 16:05:21 +1100 | [diff] [blame] | 385 | error = NCR5380_init(instance, host_flags); |
| 386 | if (error) |
| 387 | goto fail_init; |
Finn Thain | cbad48d | 2014-11-12 16:12:07 +1100 | [diff] [blame] | 388 | |
| 389 | if (instance->irq != NO_IRQ) { |
| 390 | error = request_irq(instance->irq, macscsi_intr, IRQF_SHARED, |
| 391 | "NCR5380", instance); |
| 392 | if (error) |
| 393 | goto fail_irq; |
| 394 | } |
| 395 | |
Finn Thain | 9c3f0e2 | 2016-01-03 16:05:11 +1100 | [diff] [blame] | 396 | NCR5380_maybe_reset_bus(instance); |
| 397 | |
Finn Thain | cbad48d | 2014-11-12 16:12:07 +1100 | [diff] [blame] | 398 | error = scsi_add_host(instance, NULL); |
| 399 | if (error) |
| 400 | goto fail_host; |
| 401 | |
| 402 | platform_set_drvdata(pdev, instance); |
| 403 | |
| 404 | scsi_scan_host(instance); |
| 405 | return 0; |
| 406 | |
| 407 | fail_host: |
| 408 | if (instance->irq != NO_IRQ) |
| 409 | free_irq(instance->irq, instance); |
| 410 | fail_irq: |
| 411 | NCR5380_exit(instance); |
Finn Thain | 0ad0eff | 2016-01-03 16:05:21 +1100 | [diff] [blame] | 412 | fail_init: |
Finn Thain | cbad48d | 2014-11-12 16:12:07 +1100 | [diff] [blame] | 413 | scsi_host_put(instance); |
| 414 | return error; |
| 415 | } |
| 416 | |
| 417 | static int __exit mac_scsi_remove(struct platform_device *pdev) |
| 418 | { |
| 419 | struct Scsi_Host *instance = platform_get_drvdata(pdev); |
| 420 | |
| 421 | scsi_remove_host(instance); |
| 422 | if (instance->irq != NO_IRQ) |
| 423 | free_irq(instance->irq, instance); |
| 424 | NCR5380_exit(instance); |
| 425 | scsi_host_put(instance); |
| 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | static struct platform_driver mac_scsi_driver = { |
| 430 | .remove = __exit_p(mac_scsi_remove), |
| 431 | .driver = { |
| 432 | .name = DRV_MODULE_NAME, |
Finn Thain | cbad48d | 2014-11-12 16:12:07 +1100 | [diff] [blame] | 433 | }, |
| 434 | }; |
| 435 | |
| 436 | module_platform_driver_probe(mac_scsi_driver, mac_scsi_probe); |
| 437 | |
| 438 | MODULE_ALIAS("platform:" DRV_MODULE_NAME); |
Finn Thain | 6e9ae6d | 2014-11-12 16:12:05 +1100 | [diff] [blame] | 439 | MODULE_LICENSE("GPL"); |