0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include <linux/module.h>
0023 #include <linux/blkdev.h>
0024 #include <linux/kernel.h>
0025 #include <linux/string.h>
0026 #include <linux/ioport.h>
0027 #include <linux/proc_fs.h>
0028 #include <linux/delay.h>
0029 #include <linux/interrupt.h>
0030 #include <linux/init.h>
0031 #include <linux/dma-mapping.h>
0032 #include <linux/pgtable.h>
0033
0034 #include <asm/io.h>
0035 #include <asm/dma.h>
0036 #include <asm/ecard.h>
0037
0038 #include <scsi/scsi.h>
0039 #include <scsi/scsi_cmnd.h>
0040 #include <scsi/scsi_device.h>
0041 #include <scsi/scsi_eh.h>
0042 #include <scsi/scsi_host.h>
0043 #include <scsi/scsi_tcq.h>
0044 #include "fas216.h"
0045 #include "arm_scsi.h"
0046
0047 #include <scsi/scsicam.h>
0048
0049 #define EESOX_FAS216_OFFSET 0x3000
0050 #define EESOX_FAS216_SHIFT 5
0051
0052 #define EESOX_DMASTAT 0x2800
0053 #define EESOX_STAT_INTR 0x01
0054 #define EESOX_STAT_DMA 0x02
0055
0056 #define EESOX_CONTROL 0x2800
0057 #define EESOX_INTR_ENABLE 0x04
0058 #define EESOX_TERM_ENABLE 0x02
0059 #define EESOX_RESET 0x01
0060
0061 #define EESOX_DMADATA 0x3800
0062
0063 #define VERSION "1.10 (17/01/2003 2.5.59)"
0064
0065
0066
0067
0068 static int term[MAX_ECARDS] = { 1, 1, 1, 1, 1, 1, 1, 1 };
0069
0070 #define NR_SG 256
0071
0072 struct eesoxscsi_info {
0073 FAS216_Info info;
0074 struct expansion_card *ec;
0075 void __iomem *base;
0076 void __iomem *ctl_port;
0077 unsigned int control;
0078 struct scatterlist sg[NR_SG];
0079 };
0080
0081
0082
0083
0084
0085
0086 static void
0087 eesoxscsi_irqenable(struct expansion_card *ec, int irqnr)
0088 {
0089 struct eesoxscsi_info *info = (struct eesoxscsi_info *)ec->irq_data;
0090
0091 info->control |= EESOX_INTR_ENABLE;
0092
0093 writeb(info->control, info->ctl_port);
0094 }
0095
0096
0097
0098
0099
0100
0101 static void
0102 eesoxscsi_irqdisable(struct expansion_card *ec, int irqnr)
0103 {
0104 struct eesoxscsi_info *info = (struct eesoxscsi_info *)ec->irq_data;
0105
0106 info->control &= ~EESOX_INTR_ENABLE;
0107
0108 writeb(info->control, info->ctl_port);
0109 }
0110
0111 static const expansioncard_ops_t eesoxscsi_ops = {
0112 .irqenable = eesoxscsi_irqenable,
0113 .irqdisable = eesoxscsi_irqdisable,
0114 };
0115
0116
0117
0118
0119
0120
0121 static void
0122 eesoxscsi_terminator_ctl(struct Scsi_Host *host, int on_off)
0123 {
0124 struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
0125 unsigned long flags;
0126
0127 spin_lock_irqsave(host->host_lock, flags);
0128 if (on_off)
0129 info->control |= EESOX_TERM_ENABLE;
0130 else
0131 info->control &= ~EESOX_TERM_ENABLE;
0132
0133 writeb(info->control, info->ctl_port);
0134 spin_unlock_irqrestore(host->host_lock, flags);
0135 }
0136
0137
0138
0139
0140
0141
0142 static irqreturn_t
0143 eesoxscsi_intr(int irq, void *dev_id)
0144 {
0145 struct eesoxscsi_info *info = dev_id;
0146
0147 return fas216_intr(&info->info);
0148 }
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158 static fasdmatype_t
0159 eesoxscsi_dma_setup(struct Scsi_Host *host, struct scsi_pointer *SCp,
0160 fasdmadir_t direction, fasdmatype_t min_type)
0161 {
0162 struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
0163 struct device *dev = scsi_get_device(host);
0164 int dmach = info->info.scsi.dma;
0165
0166 if (dmach != NO_DMA &&
0167 (min_type == fasdma_real_all || SCp->this_residual >= 512)) {
0168 int bufs, map_dir, dma_dir;
0169
0170 bufs = copy_SCp_to_sg(&info->sg[0], SCp, NR_SG);
0171
0172 if (direction == DMA_OUT) {
0173 map_dir = DMA_TO_DEVICE;
0174 dma_dir = DMA_MODE_WRITE;
0175 } else {
0176 map_dir = DMA_FROM_DEVICE;
0177 dma_dir = DMA_MODE_READ;
0178 }
0179
0180 dma_map_sg(dev, info->sg, bufs, map_dir);
0181
0182 disable_dma(dmach);
0183 set_dma_sg(dmach, info->sg, bufs);
0184 set_dma_mode(dmach, dma_dir);
0185 enable_dma(dmach);
0186 return fasdma_real_all;
0187 }
0188
0189
0190
0191
0192
0193 return fasdma_pseudo;
0194 }
0195
0196 static void eesoxscsi_buffer_in(void *buf, int length, void __iomem *base)
0197 {
0198 const void __iomem *reg_fas = base + EESOX_FAS216_OFFSET;
0199 const void __iomem *reg_dmastat = base + EESOX_DMASTAT;
0200 const void __iomem *reg_dmadata = base + EESOX_DMADATA;
0201 register const unsigned long mask = 0xffff;
0202
0203 do {
0204 unsigned int status;
0205
0206
0207
0208
0209 status = readb(reg_fas + (REG_STAT << EESOX_FAS216_SHIFT));
0210 if (status & STAT_INT)
0211 break;
0212
0213
0214
0215
0216 status = readb(reg_dmastat);
0217 if (!(status & EESOX_STAT_DMA))
0218 continue;
0219
0220
0221
0222
0223 status = readb(reg_fas + (REG_CFIS << EESOX_FAS216_SHIFT)) & CFIS_CF;
0224 if (status > 16)
0225 status = 16;
0226 if (status > length)
0227 status = length;
0228
0229
0230
0231
0232 if (((u32)buf) & 2 && status >= 2) {
0233 *(u16 *)buf = readl(reg_dmadata);
0234 buf += 2;
0235 status -= 2;
0236 length -= 2;
0237 }
0238
0239 if (status >= 8) {
0240 unsigned long l1, l2;
0241
0242 l1 = readl(reg_dmadata) & mask;
0243 l1 |= readl(reg_dmadata) << 16;
0244 l2 = readl(reg_dmadata) & mask;
0245 l2 |= readl(reg_dmadata) << 16;
0246 *(u32 *)buf = l1;
0247 buf += 4;
0248 *(u32 *)buf = l2;
0249 buf += 4;
0250 length -= 8;
0251 continue;
0252 }
0253
0254 if (status >= 4) {
0255 unsigned long l1;
0256
0257 l1 = readl(reg_dmadata) & mask;
0258 l1 |= readl(reg_dmadata) << 16;
0259
0260 *(u32 *)buf = l1;
0261 buf += 4;
0262 length -= 4;
0263 continue;
0264 }
0265
0266 if (status >= 2) {
0267 *(u16 *)buf = readl(reg_dmadata);
0268 buf += 2;
0269 length -= 2;
0270 }
0271 } while (length);
0272 }
0273
0274 static void eesoxscsi_buffer_out(void *buf, int length, void __iomem *base)
0275 {
0276 const void __iomem *reg_fas = base + EESOX_FAS216_OFFSET;
0277 const void __iomem *reg_dmastat = base + EESOX_DMASTAT;
0278 void __iomem *reg_dmadata = base + EESOX_DMADATA;
0279
0280 do {
0281 unsigned int status;
0282
0283
0284
0285
0286 status = readb(reg_fas + (REG_STAT << EESOX_FAS216_SHIFT));
0287 if (status & STAT_INT)
0288 break;
0289
0290
0291
0292
0293 status = readb(reg_dmastat);
0294 if (!(status & EESOX_STAT_DMA))
0295 continue;
0296
0297
0298
0299
0300 status = readb(reg_fas + (REG_CFIS << EESOX_FAS216_SHIFT)) & CFIS_CF;
0301 if (status > 16)
0302 status = 16;
0303 status = 16 - status;
0304 if (status > length)
0305 status = length;
0306 status &= ~1;
0307
0308
0309
0310
0311 if (((u32)buf) & 2 && status >= 2) {
0312 writel(*(u16 *)buf << 16, reg_dmadata);
0313 buf += 2;
0314 status -= 2;
0315 length -= 2;
0316 }
0317
0318 if (status >= 8) {
0319 unsigned long l1, l2;
0320
0321 l1 = *(u32 *)buf;
0322 buf += 4;
0323 l2 = *(u32 *)buf;
0324 buf += 4;
0325
0326 writel(l1 << 16, reg_dmadata);
0327 writel(l1, reg_dmadata);
0328 writel(l2 << 16, reg_dmadata);
0329 writel(l2, reg_dmadata);
0330 length -= 8;
0331 continue;
0332 }
0333
0334 if (status >= 4) {
0335 unsigned long l1;
0336
0337 l1 = *(u32 *)buf;
0338 buf += 4;
0339
0340 writel(l1 << 16, reg_dmadata);
0341 writel(l1, reg_dmadata);
0342 length -= 4;
0343 continue;
0344 }
0345
0346 if (status >= 2) {
0347 writel(*(u16 *)buf << 16, reg_dmadata);
0348 buf += 2;
0349 length -= 2;
0350 }
0351 } while (length);
0352 }
0353
0354 static void
0355 eesoxscsi_dma_pseudo(struct Scsi_Host *host, struct scsi_pointer *SCp,
0356 fasdmadir_t dir, int transfer_size)
0357 {
0358 struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
0359 if (dir == DMA_IN) {
0360 eesoxscsi_buffer_in(SCp->ptr, SCp->this_residual, info->base);
0361 } else {
0362 eesoxscsi_buffer_out(SCp->ptr, SCp->this_residual, info->base);
0363 }
0364 }
0365
0366
0367
0368
0369
0370
0371 static void
0372 eesoxscsi_dma_stop(struct Scsi_Host *host, struct scsi_pointer *SCp)
0373 {
0374 struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
0375 if (info->info.scsi.dma != NO_DMA)
0376 disable_dma(info->info.scsi.dma);
0377 }
0378
0379
0380
0381
0382
0383
0384 const char *eesoxscsi_info(struct Scsi_Host *host)
0385 {
0386 struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
0387 static char string[150];
0388
0389 sprintf(string, "%s (%s) in slot %d v%s terminators o%s",
0390 host->hostt->name, info->info.scsi.type, info->ec->slot_no,
0391 VERSION, info->control & EESOX_TERM_ENABLE ? "n" : "ff");
0392
0393 return string;
0394 }
0395
0396
0397
0398
0399
0400
0401
0402
0403 static int
0404 eesoxscsi_set_proc_info(struct Scsi_Host *host, char *buffer, int length)
0405 {
0406 int ret = length;
0407
0408 if (length >= 9 && strncmp(buffer, "EESOXSCSI", 9) == 0) {
0409 buffer += 9;
0410 length -= 9;
0411
0412 if (length >= 5 && strncmp(buffer, "term=", 5) == 0) {
0413 if (buffer[5] == '1')
0414 eesoxscsi_terminator_ctl(host, 1);
0415 else if (buffer[5] == '0')
0416 eesoxscsi_terminator_ctl(host, 0);
0417 else
0418 ret = -EINVAL;
0419 } else
0420 ret = -EINVAL;
0421 } else
0422 ret = -EINVAL;
0423
0424 return ret;
0425 }
0426
0427 static int eesoxscsi_show_info(struct seq_file *m, struct Scsi_Host *host)
0428 {
0429 struct eesoxscsi_info *info;
0430
0431 info = (struct eesoxscsi_info *)host->hostdata;
0432
0433 seq_printf(m, "EESOX SCSI driver v%s\n", VERSION);
0434 fas216_print_host(&info->info, m);
0435 seq_printf(m, "Term : o%s\n",
0436 info->control & EESOX_TERM_ENABLE ? "n" : "ff");
0437
0438 fas216_print_stats(&info->info, m);
0439 fas216_print_devices(&info->info, m);
0440 return 0;
0441 }
0442
0443 static ssize_t eesoxscsi_show_term(struct device *dev, struct device_attribute *attr, char *buf)
0444 {
0445 struct expansion_card *ec = ECARD_DEV(dev);
0446 struct Scsi_Host *host = ecard_get_drvdata(ec);
0447 struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
0448
0449 return sprintf(buf, "%d\n", info->control & EESOX_TERM_ENABLE ? 1 : 0);
0450 }
0451
0452 static ssize_t eesoxscsi_store_term(struct device *dev, struct device_attribute *attr, const char *buf, size_t len)
0453 {
0454 struct expansion_card *ec = ECARD_DEV(dev);
0455 struct Scsi_Host *host = ecard_get_drvdata(ec);
0456 struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
0457 unsigned long flags;
0458
0459 if (len > 1) {
0460 spin_lock_irqsave(host->host_lock, flags);
0461 if (buf[0] != '0') {
0462 info->control |= EESOX_TERM_ENABLE;
0463 } else {
0464 info->control &= ~EESOX_TERM_ENABLE;
0465 }
0466 writeb(info->control, info->ctl_port);
0467 spin_unlock_irqrestore(host->host_lock, flags);
0468 }
0469
0470 return len;
0471 }
0472
0473 static DEVICE_ATTR(bus_term, S_IRUGO | S_IWUSR,
0474 eesoxscsi_show_term, eesoxscsi_store_term);
0475
0476 static struct scsi_host_template eesox_template = {
0477 .module = THIS_MODULE,
0478 .show_info = eesoxscsi_show_info,
0479 .write_info = eesoxscsi_set_proc_info,
0480 .name = "EESOX SCSI",
0481 .info = eesoxscsi_info,
0482 .queuecommand = fas216_queue_command,
0483 .eh_host_reset_handler = fas216_eh_host_reset,
0484 .eh_bus_reset_handler = fas216_eh_bus_reset,
0485 .eh_device_reset_handler = fas216_eh_device_reset,
0486 .eh_abort_handler = fas216_eh_abort,
0487 .cmd_size = sizeof(struct fas216_cmd_priv),
0488 .can_queue = 1,
0489 .this_id = 7,
0490 .sg_tablesize = SG_MAX_SEGMENTS,
0491 .dma_boundary = IOMD_DMA_BOUNDARY,
0492 .proc_name = "eesox",
0493 };
0494
0495 static int eesoxscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
0496 {
0497 struct Scsi_Host *host;
0498 struct eesoxscsi_info *info;
0499 void __iomem *base;
0500 int ret;
0501
0502 ret = ecard_request_resources(ec);
0503 if (ret)
0504 goto out;
0505
0506 base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
0507 if (!base) {
0508 ret = -ENOMEM;
0509 goto out_region;
0510 }
0511
0512 host = scsi_host_alloc(&eesox_template,
0513 sizeof(struct eesoxscsi_info));
0514 if (!host) {
0515 ret = -ENOMEM;
0516 goto out_region;
0517 }
0518
0519 ecard_set_drvdata(ec, host);
0520
0521 info = (struct eesoxscsi_info *)host->hostdata;
0522 info->ec = ec;
0523 info->base = base;
0524 info->ctl_port = base + EESOX_CONTROL;
0525 info->control = term[ec->slot_no] ? EESOX_TERM_ENABLE : 0;
0526 writeb(info->control, info->ctl_port);
0527
0528 info->info.scsi.io_base = base + EESOX_FAS216_OFFSET;
0529 info->info.scsi.io_shift = EESOX_FAS216_SHIFT;
0530 info->info.scsi.irq = ec->irq;
0531 info->info.scsi.dma = ec->dma;
0532 info->info.ifcfg.clockrate = 40;
0533 info->info.ifcfg.select_timeout = 255;
0534 info->info.ifcfg.asyncperiod = 200;
0535 info->info.ifcfg.sync_max_depth = 7;
0536 info->info.ifcfg.cntl3 = CNTL3_FASTSCSI | CNTL3_FASTCLK;
0537 info->info.ifcfg.disconnect_ok = 1;
0538 info->info.ifcfg.wide_max_size = 0;
0539 info->info.ifcfg.capabilities = FASCAP_PSEUDODMA;
0540 info->info.dma.setup = eesoxscsi_dma_setup;
0541 info->info.dma.pseudo = eesoxscsi_dma_pseudo;
0542 info->info.dma.stop = eesoxscsi_dma_stop;
0543
0544 ec->irqaddr = base + EESOX_DMASTAT;
0545 ec->irqmask = EESOX_STAT_INTR;
0546
0547 ecard_setirq(ec, &eesoxscsi_ops, info);
0548
0549 device_create_file(&ec->dev, &dev_attr_bus_term);
0550
0551 ret = fas216_init(host);
0552 if (ret)
0553 goto out_free;
0554
0555 ret = request_irq(ec->irq, eesoxscsi_intr, 0, "eesoxscsi", info);
0556 if (ret) {
0557 printk("scsi%d: IRQ%d not free: %d\n",
0558 host->host_no, ec->irq, ret);
0559 goto out_remove;
0560 }
0561
0562 if (info->info.scsi.dma != NO_DMA) {
0563 if (request_dma(info->info.scsi.dma, "eesox")) {
0564 printk("scsi%d: DMA%d not free, DMA disabled\n",
0565 host->host_no, info->info.scsi.dma);
0566 info->info.scsi.dma = NO_DMA;
0567 } else {
0568 set_dma_speed(info->info.scsi.dma, 180);
0569 info->info.ifcfg.capabilities |= FASCAP_DMA;
0570 info->info.ifcfg.cntl3 |= CNTL3_BS8;
0571 }
0572 }
0573
0574 ret = fas216_add(host, &ec->dev);
0575 if (ret == 0)
0576 goto out;
0577
0578 if (info->info.scsi.dma != NO_DMA)
0579 free_dma(info->info.scsi.dma);
0580 free_irq(ec->irq, info);
0581
0582 out_remove:
0583 fas216_remove(host);
0584
0585 out_free:
0586 device_remove_file(&ec->dev, &dev_attr_bus_term);
0587 scsi_host_put(host);
0588
0589 out_region:
0590 ecard_release_resources(ec);
0591
0592 out:
0593 return ret;
0594 }
0595
0596 static void eesoxscsi_remove(struct expansion_card *ec)
0597 {
0598 struct Scsi_Host *host = ecard_get_drvdata(ec);
0599 struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
0600
0601 ecard_set_drvdata(ec, NULL);
0602 fas216_remove(host);
0603
0604 if (info->info.scsi.dma != NO_DMA)
0605 free_dma(info->info.scsi.dma);
0606 free_irq(ec->irq, info);
0607
0608 device_remove_file(&ec->dev, &dev_attr_bus_term);
0609
0610 fas216_release(host);
0611 scsi_host_put(host);
0612 ecard_release_resources(ec);
0613 }
0614
0615 static const struct ecard_id eesoxscsi_cids[] = {
0616 { MANU_EESOX, PROD_EESOX_SCSI2 },
0617 { 0xffff, 0xffff },
0618 };
0619
0620 static struct ecard_driver eesoxscsi_driver = {
0621 .probe = eesoxscsi_probe,
0622 .remove = eesoxscsi_remove,
0623 .id_table = eesoxscsi_cids,
0624 .drv = {
0625 .name = "eesoxscsi",
0626 },
0627 };
0628
0629 static int __init eesox_init(void)
0630 {
0631 return ecard_register_driver(&eesoxscsi_driver);
0632 }
0633
0634 static void __exit eesox_exit(void)
0635 {
0636 ecard_remove_driver(&eesoxscsi_driver);
0637 }
0638
0639 module_init(eesox_init);
0640 module_exit(eesox_exit);
0641
0642 MODULE_AUTHOR("Russell King");
0643 MODULE_DESCRIPTION("EESOX 'Fast' SCSI driver for Acorn machines");
0644 module_param_array(term, int, NULL, 0);
0645 MODULE_PARM_DESC(term, "SCSI bus termination");
0646 MODULE_LICENSE("GPL");