Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/acorn/scsi/eesox.c |
| 3 | * |
| 4 | * Copyright (C) 1997-2005 Russell King |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This driver is based on experimentation. Hence, it may have made |
| 11 | * assumptions about the particular card that I have available, and |
| 12 | * may not be reliable! |
| 13 | * |
| 14 | * Changelog: |
| 15 | * 01-10-1997 RMK Created, READONLY version |
| 16 | * 15-02-1998 RMK READ/WRITE version |
| 17 | * added DMA support and hardware definitions |
| 18 | * 14-03-1998 RMK Updated DMA support |
| 19 | * Added terminator control |
| 20 | * 15-04-1998 RMK Only do PIO if FAS216 will allow it. |
| 21 | * 27-06-1998 RMK Changed asm/delay.h to linux/delay.h |
| 22 | * 02-04-2000 RMK 0.0.3 Fixed NO_IRQ/NO_DMA problem, updated for new |
| 23 | * error handling code. |
| 24 | */ |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/blkdev.h> |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/string.h> |
| 29 | #include <linux/ioport.h> |
| 30 | #include <linux/sched.h> |
| 31 | #include <linux/proc_fs.h> |
| 32 | #include <linux/delay.h> |
| 33 | #include <linux/interrupt.h> |
| 34 | #include <linux/init.h> |
| 35 | #include <linux/dma-mapping.h> |
| 36 | |
| 37 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <asm/dma.h> |
| 39 | #include <asm/ecard.h> |
| 40 | #include <asm/pgtable.h> |
| 41 | |
| 42 | #include "../scsi.h" |
| 43 | #include <scsi/scsi_host.h> |
| 44 | #include "fas216.h" |
| 45 | #include "scsi.h" |
| 46 | |
| 47 | #include <scsi/scsicam.h> |
| 48 | |
| 49 | #define EESOX_FAS216_OFFSET 0x3000 |
| 50 | #define EESOX_FAS216_SHIFT 5 |
| 51 | |
| 52 | #define EESOX_DMASTAT 0x2800 |
| 53 | #define EESOX_STAT_INTR 0x01 |
| 54 | #define EESOX_STAT_DMA 0x02 |
| 55 | |
| 56 | #define EESOX_CONTROL 0x2800 |
| 57 | #define EESOX_INTR_ENABLE 0x04 |
| 58 | #define EESOX_TERM_ENABLE 0x02 |
| 59 | #define EESOX_RESET 0x01 |
| 60 | |
| 61 | #define EESOX_DMADATA 0x3800 |
| 62 | |
| 63 | #define VERSION "1.10 (17/01/2003 2.5.59)" |
| 64 | |
| 65 | /* |
| 66 | * Use term=0,1,0,0,0 to turn terminators on/off |
| 67 | */ |
| 68 | static int term[MAX_ECARDS] = { 1, 1, 1, 1, 1, 1, 1, 1 }; |
| 69 | |
| 70 | #define NR_SG 256 |
| 71 | |
| 72 | struct eesoxscsi_info { |
| 73 | FAS216_Info info; |
| 74 | struct expansion_card *ec; |
| 75 | void __iomem *base; |
| 76 | void __iomem *ctl_port; |
| 77 | unsigned int control; |
| 78 | struct scatterlist sg[NR_SG]; /* Scatter DMA list */ |
| 79 | }; |
| 80 | |
| 81 | /* Prototype: void eesoxscsi_irqenable(ec, irqnr) |
| 82 | * Purpose : Enable interrupts on EESOX SCSI card |
| 83 | * Params : ec - expansion card structure |
| 84 | * : irqnr - interrupt number |
| 85 | */ |
| 86 | static void |
| 87 | eesoxscsi_irqenable(struct expansion_card *ec, int irqnr) |
| 88 | { |
| 89 | struct eesoxscsi_info *info = (struct eesoxscsi_info *)ec->irq_data; |
| 90 | |
| 91 | info->control |= EESOX_INTR_ENABLE; |
| 92 | |
| 93 | writeb(info->control, info->ctl_port); |
| 94 | } |
| 95 | |
| 96 | /* Prototype: void eesoxscsi_irqdisable(ec, irqnr) |
| 97 | * Purpose : Disable interrupts on EESOX SCSI card |
| 98 | * Params : ec - expansion card structure |
| 99 | * : irqnr - interrupt number |
| 100 | */ |
| 101 | static void |
| 102 | eesoxscsi_irqdisable(struct expansion_card *ec, int irqnr) |
| 103 | { |
| 104 | struct eesoxscsi_info *info = (struct eesoxscsi_info *)ec->irq_data; |
| 105 | |
| 106 | info->control &= ~EESOX_INTR_ENABLE; |
| 107 | |
| 108 | writeb(info->control, info->ctl_port); |
| 109 | } |
| 110 | |
| 111 | static const expansioncard_ops_t eesoxscsi_ops = { |
| 112 | .irqenable = eesoxscsi_irqenable, |
| 113 | .irqdisable = eesoxscsi_irqdisable, |
| 114 | }; |
| 115 | |
| 116 | /* Prototype: void eesoxscsi_terminator_ctl(*host, on_off) |
| 117 | * Purpose : Turn the EESOX SCSI terminators on or off |
| 118 | * Params : host - card to turn on/off |
| 119 | * : on_off - !0 to turn on, 0 to turn off |
| 120 | */ |
| 121 | static void |
| 122 | eesoxscsi_terminator_ctl(struct Scsi_Host *host, int on_off) |
| 123 | { |
| 124 | struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata; |
| 125 | unsigned long flags; |
| 126 | |
| 127 | spin_lock_irqsave(host->host_lock, flags); |
| 128 | if (on_off) |
| 129 | info->control |= EESOX_TERM_ENABLE; |
| 130 | else |
| 131 | info->control &= ~EESOX_TERM_ENABLE; |
| 132 | |
| 133 | writeb(info->control, info->ctl_port); |
| 134 | spin_unlock_irqrestore(host->host_lock, flags); |
| 135 | } |
| 136 | |
| 137 | /* Prototype: void eesoxscsi_intr(irq, *dev_id, *regs) |
| 138 | * Purpose : handle interrupts from EESOX SCSI card |
| 139 | * Params : irq - interrupt number |
| 140 | * dev_id - user-defined (Scsi_Host structure) |
| 141 | * regs - processor registers at interrupt |
| 142 | */ |
| 143 | static irqreturn_t |
| 144 | eesoxscsi_intr(int irq, void *dev_id, struct pt_regs *regs) |
| 145 | { |
| 146 | struct eesoxscsi_info *info = dev_id; |
| 147 | |
| 148 | return fas216_intr(&info->info); |
| 149 | } |
| 150 | |
| 151 | /* Prototype: fasdmatype_t eesoxscsi_dma_setup(host, SCpnt, direction, min_type) |
| 152 | * Purpose : initialises DMA/PIO |
| 153 | * Params : host - host |
| 154 | * SCpnt - command |
| 155 | * direction - DMA on to/off of card |
| 156 | * min_type - minimum DMA support that we must have for this transfer |
| 157 | * Returns : type of transfer to be performed |
| 158 | */ |
| 159 | static fasdmatype_t |
Christoph Hellwig | 0a04137 | 2005-10-31 18:31:56 +0100 | [diff] [blame] | 160 | eesoxscsi_dma_setup(struct Scsi_Host *host, struct scsi_pointer *SCp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | fasdmadir_t direction, fasdmatype_t min_type) |
| 162 | { |
| 163 | struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata; |
| 164 | struct device *dev = scsi_get_device(host); |
| 165 | int dmach = info->info.scsi.dma; |
| 166 | |
| 167 | if (dmach != NO_DMA && |
| 168 | (min_type == fasdma_real_all || SCp->this_residual >= 512)) { |
| 169 | int bufs, map_dir, dma_dir; |
| 170 | |
| 171 | bufs = copy_SCp_to_sg(&info->sg[0], SCp, NR_SG); |
| 172 | |
| 173 | if (direction == DMA_OUT) |
| 174 | map_dir = DMA_TO_DEVICE, |
| 175 | dma_dir = DMA_MODE_WRITE; |
| 176 | else |
| 177 | map_dir = DMA_FROM_DEVICE, |
| 178 | dma_dir = DMA_MODE_READ; |
| 179 | |
| 180 | dma_map_sg(dev, info->sg, bufs + 1, map_dir); |
| 181 | |
| 182 | disable_dma(dmach); |
| 183 | set_dma_sg(dmach, info->sg, bufs + 1); |
| 184 | set_dma_mode(dmach, dma_dir); |
| 185 | enable_dma(dmach); |
| 186 | return fasdma_real_all; |
| 187 | } |
| 188 | /* |
| 189 | * We don't do DMA, we only do slow PIO |
| 190 | * |
| 191 | * Some day, we will do Pseudo DMA |
| 192 | */ |
| 193 | return fasdma_pseudo; |
| 194 | } |
| 195 | |
| 196 | static void eesoxscsi_buffer_in(void *buf, int length, void __iomem *base) |
| 197 | { |
| 198 | const void __iomem *reg_fas = base + EESOX_FAS216_OFFSET; |
| 199 | const void __iomem *reg_dmastat = base + EESOX_DMASTAT; |
| 200 | const void __iomem *reg_dmadata = base + EESOX_DMADATA; |
| 201 | const register unsigned long mask = 0xffff; |
| 202 | |
| 203 | do { |
| 204 | unsigned int status; |
| 205 | |
| 206 | /* |
| 207 | * Interrupt request? |
| 208 | */ |
| 209 | status = readb(reg_fas + (REG_STAT << EESOX_FAS216_SHIFT)); |
| 210 | if (status & STAT_INT) |
| 211 | break; |
| 212 | |
| 213 | /* |
| 214 | * DMA request active? |
| 215 | */ |
| 216 | status = readb(reg_dmastat); |
| 217 | if (!(status & EESOX_STAT_DMA)) |
| 218 | continue; |
| 219 | |
| 220 | /* |
| 221 | * Get number of bytes in FIFO |
| 222 | */ |
| 223 | status = readb(reg_fas + (REG_CFIS << EESOX_FAS216_SHIFT)) & CFIS_CF; |
| 224 | if (status > 16) |
| 225 | status = 16; |
| 226 | if (status > length) |
| 227 | status = length; |
| 228 | |
| 229 | /* |
| 230 | * Align buffer. |
| 231 | */ |
| 232 | if (((u32)buf) & 2 && status >= 2) { |
| 233 | *(u16 *)buf = readl(reg_dmadata); |
| 234 | buf += 2; |
| 235 | status -= 2; |
| 236 | length -= 2; |
| 237 | } |
| 238 | |
| 239 | if (status >= 8) { |
| 240 | unsigned long l1, l2; |
| 241 | |
| 242 | l1 = readl(reg_dmadata) & mask; |
| 243 | l1 |= readl(reg_dmadata) << 16; |
| 244 | l2 = readl(reg_dmadata) & mask; |
| 245 | l2 |= readl(reg_dmadata) << 16; |
| 246 | *(u32 *)buf = l1; |
| 247 | buf += 4; |
| 248 | *(u32 *)buf = l2; |
| 249 | buf += 4; |
| 250 | length -= 8; |
| 251 | continue; |
| 252 | } |
| 253 | |
| 254 | if (status >= 4) { |
| 255 | unsigned long l1; |
| 256 | |
| 257 | l1 = readl(reg_dmadata) & mask; |
| 258 | l1 |= readl(reg_dmadata) << 16; |
| 259 | |
| 260 | *(u32 *)buf = l1; |
| 261 | buf += 4; |
| 262 | length -= 4; |
| 263 | continue; |
| 264 | } |
| 265 | |
| 266 | if (status >= 2) { |
| 267 | *(u16 *)buf = readl(reg_dmadata); |
| 268 | buf += 2; |
| 269 | length -= 2; |
| 270 | } |
| 271 | } while (length); |
| 272 | } |
| 273 | |
| 274 | static void eesoxscsi_buffer_out(void *buf, int length, void __iomem *base) |
| 275 | { |
| 276 | const void __iomem *reg_fas = base + EESOX_FAS216_OFFSET; |
| 277 | const void __iomem *reg_dmastat = base + EESOX_DMASTAT; |
| 278 | const void __iomem *reg_dmadata = base + EESOX_DMADATA; |
| 279 | |
| 280 | do { |
| 281 | unsigned int status; |
| 282 | |
| 283 | /* |
| 284 | * Interrupt request? |
| 285 | */ |
| 286 | status = readb(reg_fas + (REG_STAT << EESOX_FAS216_SHIFT)); |
| 287 | if (status & STAT_INT) |
| 288 | break; |
| 289 | |
| 290 | /* |
| 291 | * DMA request active? |
| 292 | */ |
| 293 | status = readb(reg_dmastat); |
| 294 | if (!(status & EESOX_STAT_DMA)) |
| 295 | continue; |
| 296 | |
| 297 | /* |
| 298 | * Get number of bytes in FIFO |
| 299 | */ |
| 300 | status = readb(reg_fas + (REG_CFIS << EESOX_FAS216_SHIFT)) & CFIS_CF; |
| 301 | if (status > 16) |
| 302 | status = 16; |
| 303 | status = 16 - status; |
| 304 | if (status > length) |
| 305 | status = length; |
| 306 | status &= ~1; |
| 307 | |
| 308 | /* |
| 309 | * Align buffer. |
| 310 | */ |
| 311 | if (((u32)buf) & 2 && status >= 2) { |
| 312 | writel(*(u16 *)buf << 16, reg_dmadata); |
| 313 | buf += 2; |
| 314 | status -= 2; |
| 315 | length -= 2; |
| 316 | } |
| 317 | |
| 318 | if (status >= 8) { |
| 319 | unsigned long l1, l2; |
| 320 | |
| 321 | l1 = *(u32 *)buf; |
| 322 | buf += 4; |
| 323 | l2 = *(u32 *)buf; |
| 324 | buf += 4; |
| 325 | |
| 326 | writel(l1 << 16, reg_dmadata); |
| 327 | writel(l1, reg_dmadata); |
| 328 | writel(l2 << 16, reg_dmadata); |
| 329 | writel(l2, reg_dmadata); |
| 330 | length -= 8; |
| 331 | continue; |
| 332 | } |
| 333 | |
| 334 | if (status >= 4) { |
| 335 | unsigned long l1; |
| 336 | |
| 337 | l1 = *(u32 *)buf; |
| 338 | buf += 4; |
| 339 | |
| 340 | writel(l1 << 16, reg_dmadata); |
| 341 | writel(l1, reg_dmadata); |
| 342 | length -= 4; |
| 343 | continue; |
| 344 | } |
| 345 | |
| 346 | if (status >= 2) { |
| 347 | writel(*(u16 *)buf << 16, reg_dmadata); |
| 348 | buf += 2; |
| 349 | length -= 2; |
| 350 | } |
| 351 | } while (length); |
| 352 | } |
| 353 | |
| 354 | static void |
Christoph Hellwig | 0a04137 | 2005-10-31 18:31:56 +0100 | [diff] [blame] | 355 | eesoxscsi_dma_pseudo(struct Scsi_Host *host, struct scsi_pointer *SCp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | fasdmadir_t dir, int transfer_size) |
| 357 | { |
| 358 | struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata; |
| 359 | if (dir == DMA_IN) { |
| 360 | eesoxscsi_buffer_in(SCp->ptr, SCp->this_residual, info->base); |
| 361 | } else { |
| 362 | eesoxscsi_buffer_out(SCp->ptr, SCp->this_residual, info->base); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | /* Prototype: int eesoxscsi_dma_stop(host, SCpnt) |
| 367 | * Purpose : stops DMA/PIO |
| 368 | * Params : host - host |
| 369 | * SCpnt - command |
| 370 | */ |
| 371 | static void |
Christoph Hellwig | 0a04137 | 2005-10-31 18:31:56 +0100 | [diff] [blame] | 372 | eesoxscsi_dma_stop(struct Scsi_Host *host, struct scsi_pointer *SCp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | { |
| 374 | struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata; |
| 375 | if (info->info.scsi.dma != NO_DMA) |
| 376 | disable_dma(info->info.scsi.dma); |
| 377 | } |
| 378 | |
| 379 | /* Prototype: const char *eesoxscsi_info(struct Scsi_Host * host) |
| 380 | * Purpose : returns a descriptive string about this interface, |
| 381 | * Params : host - driver host structure to return info for. |
| 382 | * Returns : pointer to a static buffer containing null terminated string. |
| 383 | */ |
| 384 | const char *eesoxscsi_info(struct Scsi_Host *host) |
| 385 | { |
| 386 | struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata; |
| 387 | static char string[150]; |
| 388 | |
| 389 | sprintf(string, "%s (%s) in slot %d v%s terminators o%s", |
| 390 | host->hostt->name, info->info.scsi.type, info->ec->slot_no, |
| 391 | VERSION, info->control & EESOX_TERM_ENABLE ? "n" : "ff"); |
| 392 | |
| 393 | return string; |
| 394 | } |
| 395 | |
| 396 | /* Prototype: int eesoxscsi_set_proc_info(struct Scsi_Host *host, char *buffer, int length) |
| 397 | * Purpose : Set a driver specific function |
| 398 | * Params : host - host to setup |
| 399 | * : buffer - buffer containing string describing operation |
| 400 | * : length - length of string |
| 401 | * Returns : -EINVAL, or 0 |
| 402 | */ |
| 403 | static int |
| 404 | eesoxscsi_set_proc_info(struct Scsi_Host *host, char *buffer, int length) |
| 405 | { |
| 406 | int ret = length; |
| 407 | |
| 408 | if (length >= 9 && strncmp(buffer, "EESOXSCSI", 9) == 0) { |
| 409 | buffer += 9; |
| 410 | length -= 9; |
| 411 | |
| 412 | if (length >= 5 && strncmp(buffer, "term=", 5) == 0) { |
| 413 | if (buffer[5] == '1') |
| 414 | eesoxscsi_terminator_ctl(host, 1); |
| 415 | else if (buffer[5] == '0') |
| 416 | eesoxscsi_terminator_ctl(host, 0); |
| 417 | else |
| 418 | ret = -EINVAL; |
| 419 | } else |
| 420 | ret = -EINVAL; |
| 421 | } else |
| 422 | ret = -EINVAL; |
| 423 | |
| 424 | return ret; |
| 425 | } |
| 426 | |
| 427 | /* Prototype: int eesoxscsi_proc_info(char *buffer, char **start, off_t offset, |
| 428 | * int length, int host_no, int inout) |
| 429 | * Purpose : Return information about the driver to a user process accessing |
| 430 | * the /proc filesystem. |
| 431 | * Params : buffer - a buffer to write information to |
| 432 | * start - a pointer into this buffer set by this routine to the start |
| 433 | * of the required information. |
| 434 | * offset - offset into information that we have read upto. |
| 435 | * length - length of buffer |
| 436 | * host_no - host number to return information for |
| 437 | * inout - 0 for reading, 1 for writing. |
| 438 | * Returns : length of data written to buffer. |
| 439 | */ |
| 440 | int eesoxscsi_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset, |
| 441 | int length, int inout) |
| 442 | { |
| 443 | struct eesoxscsi_info *info; |
| 444 | char *p = buffer; |
| 445 | int pos; |
| 446 | |
| 447 | if (inout == 1) |
| 448 | return eesoxscsi_set_proc_info(host, buffer, length); |
| 449 | |
| 450 | info = (struct eesoxscsi_info *)host->hostdata; |
| 451 | |
| 452 | p += sprintf(p, "EESOX SCSI driver v%s\n", VERSION); |
| 453 | p += fas216_print_host(&info->info, p); |
| 454 | p += sprintf(p, "Term : o%s\n", |
| 455 | info->control & EESOX_TERM_ENABLE ? "n" : "ff"); |
| 456 | |
| 457 | p += fas216_print_stats(&info->info, p); |
| 458 | p += fas216_print_devices(&info->info, p); |
| 459 | |
| 460 | *start = buffer + offset; |
| 461 | pos = p - buffer - offset; |
| 462 | if (pos > length) |
| 463 | pos = length; |
| 464 | |
| 465 | return pos; |
| 466 | } |
| 467 | |
Yani Ioannou | 10523b3 | 2005-05-17 06:43:37 -0400 | [diff] [blame] | 468 | static ssize_t eesoxscsi_show_term(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | { |
| 470 | struct expansion_card *ec = ECARD_DEV(dev); |
| 471 | struct Scsi_Host *host = ecard_get_drvdata(ec); |
| 472 | struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata; |
| 473 | |
| 474 | return sprintf(buf, "%d\n", info->control & EESOX_TERM_ENABLE ? 1 : 0); |
| 475 | } |
| 476 | |
Yani Ioannou | 10523b3 | 2005-05-17 06:43:37 -0400 | [diff] [blame] | 477 | static ssize_t eesoxscsi_store_term(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | { |
| 479 | struct expansion_card *ec = ECARD_DEV(dev); |
| 480 | struct Scsi_Host *host = ecard_get_drvdata(ec); |
| 481 | struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata; |
| 482 | unsigned long flags; |
| 483 | |
| 484 | if (len > 1) { |
| 485 | spin_lock_irqsave(host->host_lock, flags); |
| 486 | if (buf[0] != '0') { |
| 487 | info->control |= EESOX_TERM_ENABLE; |
| 488 | } else { |
| 489 | info->control &= ~EESOX_TERM_ENABLE; |
| 490 | } |
| 491 | writeb(info->control, info->ctl_port); |
| 492 | spin_unlock_irqrestore(host->host_lock, flags); |
| 493 | } |
| 494 | |
| 495 | return len; |
| 496 | } |
| 497 | |
| 498 | static DEVICE_ATTR(bus_term, S_IRUGO | S_IWUSR, |
| 499 | eesoxscsi_show_term, eesoxscsi_store_term); |
| 500 | |
Christoph Hellwig | d0be4a7d | 2005-10-31 18:31:40 +0100 | [diff] [blame] | 501 | static struct scsi_host_template eesox_template = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | .module = THIS_MODULE, |
| 503 | .proc_info = eesoxscsi_proc_info, |
| 504 | .name = "EESOX SCSI", |
| 505 | .info = eesoxscsi_info, |
| 506 | .queuecommand = fas216_queue_command, |
| 507 | .eh_host_reset_handler = fas216_eh_host_reset, |
| 508 | .eh_bus_reset_handler = fas216_eh_bus_reset, |
| 509 | .eh_device_reset_handler = fas216_eh_device_reset, |
| 510 | .eh_abort_handler = fas216_eh_abort, |
| 511 | .can_queue = 1, |
| 512 | .this_id = 7, |
| 513 | .sg_tablesize = SG_ALL, |
| 514 | .cmd_per_lun = 1, |
| 515 | .use_clustering = DISABLE_CLUSTERING, |
| 516 | .proc_name = "eesox", |
| 517 | }; |
| 518 | |
| 519 | static int __devinit |
| 520 | eesoxscsi_probe(struct expansion_card *ec, const struct ecard_id *id) |
| 521 | { |
| 522 | struct Scsi_Host *host; |
| 523 | struct eesoxscsi_info *info; |
| 524 | unsigned long resbase, reslen; |
| 525 | void __iomem *base; |
| 526 | int ret; |
| 527 | |
| 528 | ret = ecard_request_resources(ec); |
| 529 | if (ret) |
| 530 | goto out; |
| 531 | |
| 532 | resbase = ecard_resource_start(ec, ECARD_RES_IOCFAST); |
| 533 | reslen = ecard_resource_len(ec, ECARD_RES_IOCFAST); |
| 534 | base = ioremap(resbase, reslen); |
| 535 | if (!base) { |
| 536 | ret = -ENOMEM; |
| 537 | goto out_region; |
| 538 | } |
| 539 | |
| 540 | host = scsi_host_alloc(&eesox_template, |
| 541 | sizeof(struct eesoxscsi_info)); |
| 542 | if (!host) { |
| 543 | ret = -ENOMEM; |
| 544 | goto out_unmap; |
| 545 | } |
| 546 | |
| 547 | ecard_set_drvdata(ec, host); |
| 548 | |
| 549 | info = (struct eesoxscsi_info *)host->hostdata; |
| 550 | info->ec = ec; |
| 551 | info->base = base; |
| 552 | info->ctl_port = base + EESOX_CONTROL; |
| 553 | info->control = term[ec->slot_no] ? EESOX_TERM_ENABLE : 0; |
| 554 | writeb(info->control, info->ctl_port); |
| 555 | |
| 556 | info->info.scsi.io_base = base + EESOX_FAS216_OFFSET; |
| 557 | info->info.scsi.io_shift = EESOX_FAS216_SHIFT; |
| 558 | info->info.scsi.irq = ec->irq; |
| 559 | info->info.scsi.dma = ec->dma; |
| 560 | info->info.ifcfg.clockrate = 40; /* MHz */ |
| 561 | info->info.ifcfg.select_timeout = 255; |
| 562 | info->info.ifcfg.asyncperiod = 200; /* ns */ |
| 563 | info->info.ifcfg.sync_max_depth = 7; |
| 564 | info->info.ifcfg.cntl3 = CNTL3_FASTSCSI | CNTL3_FASTCLK; |
| 565 | info->info.ifcfg.disconnect_ok = 1; |
| 566 | info->info.ifcfg.wide_max_size = 0; |
| 567 | info->info.ifcfg.capabilities = FASCAP_PSEUDODMA; |
| 568 | info->info.dma.setup = eesoxscsi_dma_setup; |
| 569 | info->info.dma.pseudo = eesoxscsi_dma_pseudo; |
| 570 | info->info.dma.stop = eesoxscsi_dma_stop; |
| 571 | |
| 572 | ec->irqaddr = base + EESOX_DMASTAT; |
| 573 | ec->irqmask = EESOX_STAT_INTR; |
| 574 | ec->irq_data = info; |
| 575 | ec->ops = &eesoxscsi_ops; |
| 576 | |
| 577 | device_create_file(&ec->dev, &dev_attr_bus_term); |
| 578 | |
| 579 | ret = fas216_init(host); |
| 580 | if (ret) |
| 581 | goto out_free; |
| 582 | |
| 583 | ret = request_irq(ec->irq, eesoxscsi_intr, 0, "eesoxscsi", info); |
| 584 | if (ret) { |
| 585 | printk("scsi%d: IRQ%d not free: %d\n", |
| 586 | host->host_no, ec->irq, ret); |
| 587 | goto out_remove; |
| 588 | } |
| 589 | |
| 590 | if (info->info.scsi.dma != NO_DMA) { |
| 591 | if (request_dma(info->info.scsi.dma, "eesox")) { |
| 592 | printk("scsi%d: DMA%d not free, DMA disabled\n", |
| 593 | host->host_no, info->info.scsi.dma); |
| 594 | info->info.scsi.dma = NO_DMA; |
| 595 | } else { |
| 596 | set_dma_speed(info->info.scsi.dma, 180); |
| 597 | info->info.ifcfg.capabilities |= FASCAP_DMA; |
| 598 | info->info.ifcfg.cntl3 |= CNTL3_BS8; |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | ret = fas216_add(host, &ec->dev); |
| 603 | if (ret == 0) |
| 604 | goto out; |
| 605 | |
| 606 | if (info->info.scsi.dma != NO_DMA) |
| 607 | free_dma(info->info.scsi.dma); |
| 608 | free_irq(ec->irq, host); |
| 609 | |
| 610 | out_remove: |
| 611 | fas216_remove(host); |
| 612 | |
| 613 | out_free: |
| 614 | device_remove_file(&ec->dev, &dev_attr_bus_term); |
| 615 | scsi_host_put(host); |
| 616 | |
| 617 | out_unmap: |
| 618 | iounmap(base); |
| 619 | |
| 620 | out_region: |
| 621 | ecard_release_resources(ec); |
| 622 | |
| 623 | out: |
| 624 | return ret; |
| 625 | } |
| 626 | |
| 627 | static void __devexit eesoxscsi_remove(struct expansion_card *ec) |
| 628 | { |
| 629 | struct Scsi_Host *host = ecard_get_drvdata(ec); |
| 630 | struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata; |
| 631 | |
| 632 | ecard_set_drvdata(ec, NULL); |
| 633 | fas216_remove(host); |
| 634 | |
| 635 | if (info->info.scsi.dma != NO_DMA) |
| 636 | free_dma(info->info.scsi.dma); |
| 637 | free_irq(ec->irq, info); |
| 638 | |
| 639 | device_remove_file(&ec->dev, &dev_attr_bus_term); |
| 640 | |
| 641 | iounmap(info->base); |
| 642 | |
| 643 | fas216_release(host); |
| 644 | scsi_host_put(host); |
| 645 | ecard_release_resources(ec); |
| 646 | } |
| 647 | |
| 648 | static const struct ecard_id eesoxscsi_cids[] = { |
| 649 | { MANU_EESOX, PROD_EESOX_SCSI2 }, |
| 650 | { 0xffff, 0xffff }, |
| 651 | }; |
| 652 | |
| 653 | static struct ecard_driver eesoxscsi_driver = { |
| 654 | .probe = eesoxscsi_probe, |
| 655 | .remove = __devexit_p(eesoxscsi_remove), |
| 656 | .id_table = eesoxscsi_cids, |
| 657 | .drv = { |
| 658 | .name = "eesoxscsi", |
| 659 | }, |
| 660 | }; |
| 661 | |
| 662 | static int __init eesox_init(void) |
| 663 | { |
| 664 | return ecard_register_driver(&eesoxscsi_driver); |
| 665 | } |
| 666 | |
| 667 | static void __exit eesox_exit(void) |
| 668 | { |
| 669 | ecard_remove_driver(&eesoxscsi_driver); |
| 670 | } |
| 671 | |
| 672 | module_init(eesox_init); |
| 673 | module_exit(eesox_exit); |
| 674 | |
| 675 | MODULE_AUTHOR("Russell King"); |
| 676 | MODULE_DESCRIPTION("EESOX 'Fast' SCSI driver for Acorn machines"); |
Rusty Russell | 8d3b33f | 2006-03-25 03:07:05 -0800 | [diff] [blame^] | 677 | module_param_array(term, int, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | MODULE_PARM_DESC(term, "SCSI bus termination"); |
| 679 | MODULE_LICENSE("GPL"); |