Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #define PSEUDO_DMA |
| 3 | #define DONT_USE_INTR |
| 4 | #define UNSAFE /* Leave interrupts enabled during pseudo-dma I/O */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | #define DMA_WORKS_RIGHT |
| 6 | |
| 7 | |
| 8 | /* |
| 9 | * DTC 3180/3280 driver, by |
| 10 | * Ray Van Tassle rayvt@comm.mot.com |
| 11 | * |
| 12 | * taken from ... |
| 13 | * Trantor T128/T128F/T228 driver by... |
| 14 | * |
| 15 | * Drew Eckhardt |
| 16 | * Visionary Computing |
| 17 | * (Unix and Linux consulting and custom programming) |
| 18 | * drew@colorado.edu |
| 19 | * +1 (303) 440-4894 |
| 20 | * |
| 21 | * DISTRIBUTION RELEASE 1. |
Finn Thain | 3f9e986 | 2014-11-12 16:11:55 +1100 | [diff] [blame] | 22 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | * The card is detected and initialized in one of several ways : |
| 26 | * 1. Autoprobe (default) - since the board is memory mapped, |
| 27 | * a BIOS signature is scanned for to locate the registers. |
| 28 | * An interrupt is triggered to autoprobe for the interrupt |
| 29 | * line. |
| 30 | * |
| 31 | * 2. With command line overrides - dtc=address,irq may be |
| 32 | * used on the LILO command line to override the defaults. |
| 33 | * |
| 34 | */ |
| 35 | |
| 36 | /*----------------------------------------------------------------*/ |
| 37 | /* the following will set the monitor border color (useful to find |
| 38 | where something crashed or gets stuck at */ |
| 39 | /* 1 = blue |
| 40 | 2 = green |
| 41 | 3 = cyan |
| 42 | 4 = red |
| 43 | 5 = magenta |
| 44 | 6 = yellow |
| 45 | 7 = white |
| 46 | */ |
| 47 | #if 0 |
| 48 | #define rtrc(i) {inb(0x3da); outb(0x31, 0x3c0); outb((i), 0x3c0);} |
| 49 | #else |
| 50 | #define rtrc(i) {} |
| 51 | #endif |
| 52 | |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #include <linux/module.h> |
| 55 | #include <linux/signal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #include <linux/blkdev.h> |
| 57 | #include <linux/delay.h> |
| 58 | #include <linux/stat.h> |
| 59 | #include <linux/string.h> |
| 60 | #include <linux/init.h> |
| 61 | #include <linux/interrupt.h> |
Matthew Wilcox | 53d5ed6 | 2006-10-11 01:22:01 -0700 | [diff] [blame] | 62 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #include "scsi.h" |
| 64 | #include <scsi/scsi_host.h> |
| 65 | #include "dtc.h" |
| 66 | #define AUTOPROBE_IRQ |
| 67 | #include "NCR5380.h" |
| 68 | |
| 69 | |
| 70 | #define DTC_PUBLIC_RELEASE 2 |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | /* |
| 73 | * The DTC3180 & 3280 boards are memory mapped. |
| 74 | * |
| 75 | */ |
| 76 | |
| 77 | /* |
| 78 | */ |
| 79 | /* Offset from DTC_5380_OFFSET */ |
| 80 | #define DTC_CONTROL_REG 0x100 /* rw */ |
| 81 | #define D_CR_ACCESS 0x80 /* ro set=can access 3280 registers */ |
| 82 | #define CSR_DIR_READ 0x40 /* rw direction, 1 = read 0 = write */ |
| 83 | |
| 84 | #define CSR_RESET 0x80 /* wo Resets 53c400 */ |
| 85 | #define CSR_5380_REG 0x80 /* ro 5380 registers can be accessed */ |
| 86 | #define CSR_TRANS_DIR 0x40 /* rw Data transfer direction */ |
| 87 | #define CSR_SCSI_BUFF_INTR 0x20 /* rw Enable int on transfer ready */ |
| 88 | #define CSR_5380_INTR 0x10 /* rw Enable 5380 interrupts */ |
| 89 | #define CSR_SHARED_INTR 0x08 /* rw Interrupt sharing */ |
| 90 | #define CSR_HOST_BUF_NOT_RDY 0x04 /* ro Host buffer not ready */ |
| 91 | #define CSR_SCSI_BUF_RDY 0x02 /* ro SCSI buffer ready */ |
| 92 | #define CSR_GATED_5380_IRQ 0x01 /* ro Last block xferred */ |
| 93 | #define CSR_INT_BASE (CSR_SCSI_BUFF_INTR | CSR_5380_INTR) |
| 94 | |
| 95 | |
| 96 | #define DTC_BLK_CNT 0x101 /* rw |
| 97 | * # of 128-byte blocks to transfer */ |
| 98 | |
| 99 | |
| 100 | #define D_CR_ACCESS 0x80 /* ro set=can access 3280 registers */ |
| 101 | |
| 102 | #define DTC_SWITCH_REG 0x3982 /* ro - DIP switches */ |
| 103 | #define DTC_RESUME_XFER 0x3982 /* wo - resume data xfer |
| 104 | * after disconnect/reconnect*/ |
| 105 | |
| 106 | #define DTC_5380_OFFSET 0x3880 /* 8 registers here, see NCR5380.h */ |
| 107 | |
| 108 | /*!!!! for dtc, it's a 128 byte buffer at 3900 !!! */ |
| 109 | #define DTC_DATA_BUF 0x3900 /* rw 128 bytes long */ |
| 110 | |
| 111 | static struct override { |
| 112 | unsigned int address; |
| 113 | int irq; |
| 114 | } overrides |
| 115 | #ifdef OVERRIDE |
| 116 | [] __initdata = OVERRIDE; |
| 117 | #else |
Alan Cox | 1fbe852 | 2007-08-10 14:50:41 -0700 | [diff] [blame] | 118 | [4] __initdata = { |
| 119 | { 0, IRQ_AUTO }, { 0, IRQ_AUTO }, { 0, IRQ_AUTO }, { 0, IRQ_AUTO } |
| 120 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | #endif |
| 122 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 123 | #define NO_OVERRIDES ARRAY_SIZE(overrides) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
| 125 | static struct base { |
| 126 | unsigned long address; |
| 127 | int noauto; |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 128 | } bases[] __initdata = { |
| 129 | { 0xcc000, 0 }, |
| 130 | { 0xc8000, 0 }, |
| 131 | { 0xdc000, 0 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | { 0xd8000, 0 } |
| 133 | }; |
| 134 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 135 | #define NO_BASES ARRAY_SIZE(bases) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
| 137 | static const struct signature { |
| 138 | const char *string; |
| 139 | int offset; |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 140 | } signatures[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | {"DATA TECHNOLOGY CORPORATION BIOS", 0x25}, |
| 142 | }; |
| 143 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 144 | #define NO_SIGNATURES ARRAY_SIZE(signatures) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | #ifndef MODULE |
| 147 | /* |
| 148 | * Function : dtc_setup(char *str, int *ints) |
| 149 | * |
| 150 | * Purpose : LILO command line initialization of the overrides array, |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 151 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | * Inputs : str - unused, ints - array of integer parameters with ints[0] |
| 153 | * equal to the number of ints. |
| 154 | * |
Alan Cox | 1fbe852 | 2007-08-10 14:50:41 -0700 | [diff] [blame] | 155 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Finn Thain | 925e461 | 2014-11-12 16:11:49 +1100 | [diff] [blame] | 157 | static int __init dtc_setup(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | { |
| 159 | static int commandline_current = 0; |
| 160 | int i; |
Finn Thain | 925e461 | 2014-11-12 16:11:49 +1100 | [diff] [blame] | 161 | int ints[10]; |
| 162 | |
| 163 | get_options(str, ARRAY_SIZE(ints), ints); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | if (ints[0] != 2) |
| 165 | printk("dtc_setup: usage dtc=address,irq\n"); |
| 166 | else if (commandline_current < NO_OVERRIDES) { |
| 167 | overrides[commandline_current].address = ints[1]; |
| 168 | overrides[commandline_current].irq = ints[2]; |
| 169 | for (i = 0; i < NO_BASES; ++i) |
| 170 | if (bases[i].address == ints[1]) { |
| 171 | bases[i].noauto = 1; |
| 172 | break; |
| 173 | } |
| 174 | ++commandline_current; |
| 175 | } |
Finn Thain | 925e461 | 2014-11-12 16:11:49 +1100 | [diff] [blame] | 176 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | } |
Finn Thain | 925e461 | 2014-11-12 16:11:49 +1100 | [diff] [blame] | 178 | |
| 179 | __setup("dtc=", dtc_setup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | #endif |
| 181 | |
| 182 | /* |
Christoph Hellwig | d0be4a7d | 2005-10-31 18:31:40 +0100 | [diff] [blame] | 183 | * Function : int dtc_detect(struct scsi_host_template * tpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | * |
| 185 | * Purpose : detects and initializes DTC 3180/3280 controllers |
| 186 | * that were autoprobed, overridden on the LILO command line, |
| 187 | * or specified at compile time. |
| 188 | * |
| 189 | * Inputs : tpnt - template for this SCSI adapter. |
| 190 | * |
| 191 | * Returns : 1 if a host adapter was found, 0 if not. |
| 192 | * |
| 193 | */ |
| 194 | |
Christoph Hellwig | d0be4a7d | 2005-10-31 18:31:40 +0100 | [diff] [blame] | 195 | static int __init dtc_detect(struct scsi_host_template * tpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
| 197 | static int current_override = 0, current_base = 0; |
| 198 | struct Scsi_Host *instance; |
| 199 | unsigned int addr; |
| 200 | void __iomem *base; |
| 201 | int sig, count; |
| 202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | for (count = 0; current_override < NO_OVERRIDES; ++current_override) { |
| 204 | addr = 0; |
| 205 | base = NULL; |
| 206 | |
| 207 | if (overrides[current_override].address) { |
| 208 | addr = overrides[current_override].address; |
| 209 | base = ioremap(addr, 0x2000); |
| 210 | if (!base) |
| 211 | addr = 0; |
| 212 | } else |
| 213 | for (; !addr && (current_base < NO_BASES); ++current_base) { |
| 214 | #if (DTCDEBUG & DTCDEBUG_INIT) |
Alan Cox | 1fbe852 | 2007-08-10 14:50:41 -0700 | [diff] [blame] | 215 | printk(KERN_DEBUG "scsi-dtc : probing address %08x\n", bases[current_base].address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | #endif |
| 217 | if (bases[current_base].noauto) |
| 218 | continue; |
| 219 | base = ioremap(bases[current_base].address, 0x2000); |
| 220 | if (!base) |
| 221 | continue; |
| 222 | for (sig = 0; sig < NO_SIGNATURES; ++sig) { |
| 223 | if (check_signature(base + signatures[sig].offset, signatures[sig].string, strlen(signatures[sig].string))) { |
| 224 | addr = bases[current_base].address; |
| 225 | #if (DTCDEBUG & DTCDEBUG_INIT) |
Alan Cox | 5307b1e | 2007-09-20 15:12:11 +0100 | [diff] [blame] | 226 | printk(KERN_DEBUG "scsi-dtc : detected board.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | #endif |
| 228 | goto found; |
| 229 | } |
| 230 | } |
| 231 | iounmap(base); |
| 232 | } |
| 233 | |
| 234 | #if defined(DTCDEBUG) && (DTCDEBUG & DTCDEBUG_INIT) |
Alan Cox | 1fbe852 | 2007-08-10 14:50:41 -0700 | [diff] [blame] | 235 | printk(KERN_DEBUG "scsi-dtc : base = %08x\n", addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | #endif |
| 237 | |
| 238 | if (!addr) |
| 239 | break; |
| 240 | |
| 241 | found: |
| 242 | instance = scsi_register(tpnt, sizeof(struct NCR5380_hostdata)); |
| 243 | if (instance == NULL) |
| 244 | break; |
| 245 | |
| 246 | instance->base = addr; |
| 247 | ((struct NCR5380_hostdata *)(instance)->hostdata)->base = base; |
| 248 | |
| 249 | NCR5380_init(instance, 0); |
| 250 | |
| 251 | NCR5380_write(DTC_CONTROL_REG, CSR_5380_INTR); /* Enable int's */ |
| 252 | if (overrides[current_override].irq != IRQ_AUTO) |
| 253 | instance->irq = overrides[current_override].irq; |
| 254 | else |
| 255 | instance->irq = NCR5380_probe_irq(instance, DTC_IRQS); |
| 256 | |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame^] | 257 | /* Compatibility with documented NCR5380 kernel parameters */ |
| 258 | if (instance->irq == 255) |
| 259 | instance->irq = NO_IRQ; |
| 260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | #ifndef DONT_USE_INTR |
| 262 | /* With interrupts enabled, it will sometimes hang when doing heavy |
| 263 | * reads. So better not enable them until I finger it out. */ |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame^] | 264 | if (instance->irq != NO_IRQ) |
Michael Opdenacker | 4909cc2 | 2014-03-05 06:09:41 +0100 | [diff] [blame] | 265 | if (request_irq(instance->irq, dtc_intr, 0, |
Jeff Garzik | 1e64166 | 2007-11-11 19:52:05 -0500 | [diff] [blame] | 266 | "dtc", instance)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | printk(KERN_ERR "scsi%d : IRQ%d not free, interrupts disabled\n", instance->host_no, instance->irq); |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame^] | 268 | instance->irq = NO_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame^] | 271 | if (instance->irq == NO_IRQ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | printk(KERN_WARNING "scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no); |
| 273 | printk(KERN_WARNING "scsi%d : please jumper the board for a free IRQ.\n", instance->host_no); |
| 274 | } |
| 275 | #else |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame^] | 276 | if (instance->irq != NO_IRQ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | printk(KERN_WARNING "scsi%d : interrupts not used. Might as well not jumper it.\n", instance->host_no); |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame^] | 278 | instance->irq = NO_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | #endif |
| 280 | #if defined(DTCDEBUG) && (DTCDEBUG & DTCDEBUG_INIT) |
| 281 | printk("scsi%d : irq = %d\n", instance->host_no, instance->irq); |
| 282 | #endif |
| 283 | |
| 284 | printk(KERN_INFO "scsi%d : at 0x%05X", instance->host_no, (int) instance->base); |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame^] | 285 | if (instance->irq == NO_IRQ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | printk(" interrupts disabled"); |
| 287 | else |
| 288 | printk(" irq %d", instance->irq); |
| 289 | printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d", CAN_QUEUE, CMD_PER_LUN, DTC_PUBLIC_RELEASE); |
| 290 | NCR5380_print_options(instance); |
| 291 | printk("\n"); |
| 292 | |
| 293 | ++current_override; |
| 294 | ++count; |
| 295 | } |
| 296 | return count; |
| 297 | } |
| 298 | |
| 299 | /* |
| 300 | * Function : int dtc_biosparam(Disk * disk, struct block_device *dev, int *ip) |
| 301 | * |
| 302 | * Purpose : Generates a BIOS / DOS compatible H-C-S mapping for |
| 303 | * the specified device / size. |
| 304 | * |
| 305 | * Inputs : size = size of device in sectors (512 bytes), dev = block device |
| 306 | * major / minor, ip[] = {heads, sectors, cylinders} |
| 307 | * |
| 308 | * Returns : always 0 (success), initializes ip |
| 309 | * |
| 310 | */ |
| 311 | |
| 312 | /* |
| 313 | * XXX Most SCSI boards use this mapping, I could be incorrect. Some one |
| 314 | * using hard disks on a trantor should verify that this mapping corresponds |
| 315 | * to that used by the BIOS / ASPI driver by running the linux fdisk program |
| 316 | * and matching the H_C_S coordinates to what DOS uses. |
| 317 | */ |
| 318 | |
| 319 | static int dtc_biosparam(struct scsi_device *sdev, struct block_device *dev, |
| 320 | sector_t capacity, int *ip) |
| 321 | { |
| 322 | int size = capacity; |
| 323 | |
| 324 | ip[0] = 64; |
| 325 | ip[1] = 32; |
| 326 | ip[2] = size >> 11; |
| 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | |
| 331 | /**************************************************************** |
| 332 | * Function : int NCR5380_pread (struct Scsi_Host *instance, |
| 333 | * unsigned char *dst, int len) |
| 334 | * |
| 335 | * Purpose : Fast 5380 pseudo-dma read function, reads len bytes to |
| 336 | * dst |
| 337 | * |
| 338 | * Inputs : dst = destination, len = length in bytes |
| 339 | * |
| 340 | * Returns : 0 on success, non zero on a failure such as a watchdog |
| 341 | * timeout. |
| 342 | */ |
| 343 | |
| 344 | static int dtc_maxi = 0; |
| 345 | static int dtc_wmaxi = 0; |
| 346 | |
| 347 | static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *dst, int len) |
| 348 | { |
| 349 | unsigned char *d = dst; |
| 350 | int i; /* For counting time spent in the poll-loop */ |
| 351 | NCR5380_local_declare(); |
| 352 | NCR5380_setup(instance); |
| 353 | |
| 354 | i = 0; |
| 355 | NCR5380_read(RESET_PARITY_INTERRUPT_REG); |
| 356 | NCR5380_write(MODE_REG, MR_ENABLE_EOP_INTR | MR_DMA_MODE); |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame^] | 357 | if (instance->irq == NO_IRQ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | NCR5380_write(DTC_CONTROL_REG, CSR_DIR_READ); |
| 359 | else |
| 360 | NCR5380_write(DTC_CONTROL_REG, CSR_DIR_READ | CSR_INT_BASE); |
| 361 | NCR5380_write(DTC_BLK_CNT, len >> 7); /* Block count */ |
| 362 | rtrc(1); |
| 363 | while (len > 0) { |
| 364 | rtrc(2); |
| 365 | while (NCR5380_read(DTC_CONTROL_REG) & CSR_HOST_BUF_NOT_RDY) |
| 366 | ++i; |
| 367 | rtrc(3); |
| 368 | memcpy_fromio(d, base + DTC_DATA_BUF, 128); |
| 369 | d += 128; |
| 370 | len -= 128; |
| 371 | rtrc(7); |
| 372 | /*** with int's on, it sometimes hangs after here. |
| 373 | * Looks like something makes HBNR go away. */ |
| 374 | } |
| 375 | rtrc(4); |
| 376 | while (!(NCR5380_read(DTC_CONTROL_REG) & D_CR_ACCESS)) |
| 377 | ++i; |
| 378 | NCR5380_write(MODE_REG, 0); /* Clear the operating mode */ |
| 379 | rtrc(0); |
| 380 | NCR5380_read(RESET_PARITY_INTERRUPT_REG); |
| 381 | if (i > dtc_maxi) |
| 382 | dtc_maxi = i; |
| 383 | return (0); |
| 384 | } |
| 385 | |
| 386 | /**************************************************************** |
| 387 | * Function : int NCR5380_pwrite (struct Scsi_Host *instance, |
| 388 | * unsigned char *src, int len) |
| 389 | * |
| 390 | * Purpose : Fast 5380 pseudo-dma write function, transfers len bytes from |
| 391 | * src |
| 392 | * |
| 393 | * Inputs : src = source, len = length in bytes |
| 394 | * |
| 395 | * Returns : 0 on success, non zero on a failure such as a watchdog |
| 396 | * timeout. |
| 397 | */ |
| 398 | |
| 399 | static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *src, int len) |
| 400 | { |
| 401 | int i; |
| 402 | NCR5380_local_declare(); |
| 403 | NCR5380_setup(instance); |
| 404 | |
| 405 | NCR5380_read(RESET_PARITY_INTERRUPT_REG); |
| 406 | NCR5380_write(MODE_REG, MR_ENABLE_EOP_INTR | MR_DMA_MODE); |
| 407 | /* set direction (write) */ |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame^] | 408 | if (instance->irq == NO_IRQ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | NCR5380_write(DTC_CONTROL_REG, 0); |
| 410 | else |
| 411 | NCR5380_write(DTC_CONTROL_REG, CSR_5380_INTR); |
| 412 | NCR5380_write(DTC_BLK_CNT, len >> 7); /* Block count */ |
| 413 | for (i = 0; len > 0; ++i) { |
| 414 | rtrc(5); |
| 415 | /* Poll until the host buffer can accept data. */ |
| 416 | while (NCR5380_read(DTC_CONTROL_REG) & CSR_HOST_BUF_NOT_RDY) |
| 417 | ++i; |
| 418 | rtrc(3); |
| 419 | memcpy_toio(base + DTC_DATA_BUF, src, 128); |
| 420 | src += 128; |
| 421 | len -= 128; |
| 422 | } |
| 423 | rtrc(4); |
| 424 | while (!(NCR5380_read(DTC_CONTROL_REG) & D_CR_ACCESS)) |
| 425 | ++i; |
| 426 | rtrc(6); |
| 427 | /* Wait until the last byte has been sent to the disk */ |
| 428 | while (!(NCR5380_read(TARGET_COMMAND_REG) & TCR_LAST_BYTE_SENT)) |
| 429 | ++i; |
| 430 | rtrc(7); |
| 431 | /* Check for parity error here. fixme. */ |
| 432 | NCR5380_write(MODE_REG, 0); /* Clear the operating mode */ |
| 433 | rtrc(0); |
| 434 | if (i > dtc_wmaxi) |
| 435 | dtc_wmaxi = i; |
| 436 | return (0); |
| 437 | } |
| 438 | |
| 439 | MODULE_LICENSE("GPL"); |
| 440 | |
| 441 | #include "NCR5380.c" |
| 442 | |
| 443 | static int dtc_release(struct Scsi_Host *shost) |
| 444 | { |
| 445 | NCR5380_local_declare(); |
| 446 | NCR5380_setup(shost); |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame^] | 447 | if (shost->irq != NO_IRQ) |
Jeff Garzik | 1e64166 | 2007-11-11 19:52:05 -0500 | [diff] [blame] | 448 | free_irq(shost->irq, shost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | NCR5380_exit(shost); |
| 450 | if (shost->io_port && shost->n_io_port) |
| 451 | release_region(shost->io_port, shost->n_io_port); |
| 452 | scsi_unregister(shost); |
| 453 | iounmap(base); |
| 454 | return 0; |
| 455 | } |
| 456 | |
Christoph Hellwig | d0be4a7d | 2005-10-31 18:31:40 +0100 | [diff] [blame] | 457 | static struct scsi_host_template driver_template = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | .name = "DTC 3180/3280 ", |
| 459 | .detect = dtc_detect, |
| 460 | .release = dtc_release, |
Finn Thain | 4d3d2a5 | 2014-11-12 16:11:52 +1100 | [diff] [blame] | 461 | .proc_name = "dtc3x80", |
| 462 | .show_info = dtc_show_info, |
| 463 | .write_info = dtc_write_info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | .queuecommand = dtc_queue_command, |
| 465 | .eh_abort_handler = dtc_abort, |
| 466 | .eh_bus_reset_handler = dtc_bus_reset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | .bios_param = dtc_biosparam, |
| 468 | .can_queue = CAN_QUEUE, |
| 469 | .this_id = 7, |
| 470 | .sg_tablesize = SG_ALL, |
| 471 | .cmd_per_lun = CMD_PER_LUN, |
| 472 | .use_clustering = DISABLE_CLUSTERING, |
| 473 | }; |
| 474 | #include "scsi_module.c" |