0001
0002
0003
0004
0005
0006
0007 #include <linux/module.h>
0008 #include <linux/blkdev.h>
0009 #include <linux/kernel.h>
0010 #include <linux/string.h>
0011 #include <linux/ioport.h>
0012 #include <linux/proc_fs.h>
0013 #include <linux/delay.h>
0014 #include <linux/interrupt.h>
0015 #include <linux/init.h>
0016 #include <linux/dma-mapping.h>
0017 #include <linux/pgtable.h>
0018
0019 #include <asm/dma.h>
0020 #include <asm/ecard.h>
0021 #include <asm/io.h>
0022
0023 #include <scsi/scsi.h>
0024 #include <scsi/scsi_cmnd.h>
0025 #include <scsi/scsi_device.h>
0026 #include <scsi/scsi_eh.h>
0027 #include <scsi/scsi_host.h>
0028 #include <scsi/scsi_tcq.h>
0029 #include "fas216.h"
0030 #include "arm_scsi.h"
0031
0032 #include <scsi/scsicam.h>
0033
0034 #define POWERTEC_FAS216_OFFSET 0x3000
0035 #define POWERTEC_FAS216_SHIFT 6
0036
0037 #define POWERTEC_INTR_STATUS 0x2000
0038 #define POWERTEC_INTR_BIT 0x80
0039
0040 #define POWERTEC_RESET_CONTROL 0x1018
0041 #define POWERTEC_RESET_BIT 1
0042
0043 #define POWERTEC_TERM_CONTROL 0x2018
0044 #define POWERTEC_TERM_ENABLE 1
0045
0046 #define POWERTEC_INTR_CONTROL 0x101c
0047 #define POWERTEC_INTR_ENABLE 1
0048 #define POWERTEC_INTR_DISABLE 0
0049
0050 #define VERSION "1.10 (19/01/2003 2.5.59)"
0051
0052
0053
0054
0055
0056 static int term[MAX_ECARDS] = { 1, 1, 1, 1, 1, 1, 1, 1 };
0057
0058 #define NR_SG 256
0059
0060 struct powertec_info {
0061 FAS216_Info info;
0062 struct expansion_card *ec;
0063 void __iomem *base;
0064 unsigned int term_ctl;
0065 struct scatterlist sg[NR_SG];
0066 };
0067
0068
0069
0070
0071
0072
0073 static void
0074 powertecscsi_irqenable(struct expansion_card *ec, int irqnr)
0075 {
0076 struct powertec_info *info = ec->irq_data;
0077 writeb(POWERTEC_INTR_ENABLE, info->base + POWERTEC_INTR_CONTROL);
0078 }
0079
0080
0081
0082
0083
0084
0085 static void
0086 powertecscsi_irqdisable(struct expansion_card *ec, int irqnr)
0087 {
0088 struct powertec_info *info = ec->irq_data;
0089 writeb(POWERTEC_INTR_DISABLE, info->base + POWERTEC_INTR_CONTROL);
0090 }
0091
0092 static const expansioncard_ops_t powertecscsi_ops = {
0093 .irqenable = powertecscsi_irqenable,
0094 .irqdisable = powertecscsi_irqdisable,
0095 };
0096
0097
0098
0099
0100
0101
0102 static void
0103 powertecscsi_terminator_ctl(struct Scsi_Host *host, int on_off)
0104 {
0105 struct powertec_info *info = (struct powertec_info *)host->hostdata;
0106
0107 info->term_ctl = on_off ? POWERTEC_TERM_ENABLE : 0;
0108 writeb(info->term_ctl, info->base + POWERTEC_TERM_CONTROL);
0109 }
0110
0111
0112
0113
0114
0115
0116 static irqreturn_t powertecscsi_intr(int irq, void *dev_id)
0117 {
0118 struct powertec_info *info = dev_id;
0119
0120 return fas216_intr(&info->info);
0121 }
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131 static fasdmatype_t
0132 powertecscsi_dma_setup(struct Scsi_Host *host, struct scsi_pointer *SCp,
0133 fasdmadir_t direction, fasdmatype_t min_type)
0134 {
0135 struct powertec_info *info = (struct powertec_info *)host->hostdata;
0136 struct device *dev = scsi_get_device(host);
0137 int dmach = info->info.scsi.dma;
0138
0139 if (info->info.ifcfg.capabilities & FASCAP_DMA &&
0140 min_type == fasdma_real_all) {
0141 int bufs, map_dir, dma_dir;
0142
0143 bufs = copy_SCp_to_sg(&info->sg[0], SCp, NR_SG);
0144
0145 if (direction == DMA_OUT) {
0146 map_dir = DMA_TO_DEVICE;
0147 dma_dir = DMA_MODE_WRITE;
0148 } else {
0149 map_dir = DMA_FROM_DEVICE;
0150 dma_dir = DMA_MODE_READ;
0151 }
0152
0153 dma_map_sg(dev, info->sg, bufs, map_dir);
0154
0155 disable_dma(dmach);
0156 set_dma_sg(dmach, info->sg, bufs);
0157 set_dma_mode(dmach, dma_dir);
0158 enable_dma(dmach);
0159 return fasdma_real_all;
0160 }
0161
0162
0163
0164
0165
0166 return fasdma_pio;
0167 }
0168
0169
0170
0171
0172
0173
0174 static void
0175 powertecscsi_dma_stop(struct Scsi_Host *host, struct scsi_pointer *SCp)
0176 {
0177 struct powertec_info *info = (struct powertec_info *)host->hostdata;
0178 if (info->info.scsi.dma != NO_DMA)
0179 disable_dma(info->info.scsi.dma);
0180 }
0181
0182
0183
0184
0185
0186
0187 const char *powertecscsi_info(struct Scsi_Host *host)
0188 {
0189 struct powertec_info *info = (struct powertec_info *)host->hostdata;
0190 static char string[150];
0191
0192 sprintf(string, "%s (%s) in slot %d v%s terminators o%s",
0193 host->hostt->name, info->info.scsi.type, info->ec->slot_no,
0194 VERSION, info->term_ctl ? "n" : "ff");
0195
0196 return string;
0197 }
0198
0199
0200
0201
0202
0203
0204
0205
0206 static int
0207 powertecscsi_set_proc_info(struct Scsi_Host *host, char *buffer, int length)
0208 {
0209 int ret = length;
0210
0211 if (length >= 12 && strncmp(buffer, "POWERTECSCSI", 12) == 0) {
0212 buffer += 12;
0213 length -= 12;
0214
0215 if (length >= 5 && strncmp(buffer, "term=", 5) == 0) {
0216 if (buffer[5] == '1')
0217 powertecscsi_terminator_ctl(host, 1);
0218 else if (buffer[5] == '0')
0219 powertecscsi_terminator_ctl(host, 0);
0220 else
0221 ret = -EINVAL;
0222 } else
0223 ret = -EINVAL;
0224 } else
0225 ret = -EINVAL;
0226
0227 return ret;
0228 }
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242 static int powertecscsi_show_info(struct seq_file *m, struct Scsi_Host *host)
0243 {
0244 struct powertec_info *info;
0245
0246 info = (struct powertec_info *)host->hostdata;
0247
0248 seq_printf(m, "PowerTec SCSI driver v%s\n", VERSION);
0249 fas216_print_host(&info->info, m);
0250 seq_printf(m, "Term : o%s\n",
0251 info->term_ctl ? "n" : "ff");
0252
0253 fas216_print_stats(&info->info, m);
0254 fas216_print_devices(&info->info, m);
0255 return 0;
0256 }
0257
0258 static ssize_t powertecscsi_show_term(struct device *dev, struct device_attribute *attr, char *buf)
0259 {
0260 struct expansion_card *ec = ECARD_DEV(dev);
0261 struct Scsi_Host *host = ecard_get_drvdata(ec);
0262 struct powertec_info *info = (struct powertec_info *)host->hostdata;
0263
0264 return sprintf(buf, "%d\n", info->term_ctl ? 1 : 0);
0265 }
0266
0267 static ssize_t
0268 powertecscsi_store_term(struct device *dev, struct device_attribute *attr, const char *buf, size_t len)
0269 {
0270 struct expansion_card *ec = ECARD_DEV(dev);
0271 struct Scsi_Host *host = ecard_get_drvdata(ec);
0272
0273 if (len > 1)
0274 powertecscsi_terminator_ctl(host, buf[0] != '0');
0275
0276 return len;
0277 }
0278
0279 static DEVICE_ATTR(bus_term, S_IRUGO | S_IWUSR,
0280 powertecscsi_show_term, powertecscsi_store_term);
0281
0282 static struct scsi_host_template powertecscsi_template = {
0283 .module = THIS_MODULE,
0284 .show_info = powertecscsi_show_info,
0285 .write_info = powertecscsi_set_proc_info,
0286 .name = "PowerTec SCSI",
0287 .info = powertecscsi_info,
0288 .queuecommand = fas216_queue_command,
0289 .eh_host_reset_handler = fas216_eh_host_reset,
0290 .eh_bus_reset_handler = fas216_eh_bus_reset,
0291 .eh_device_reset_handler = fas216_eh_device_reset,
0292 .eh_abort_handler = fas216_eh_abort,
0293 .cmd_size = sizeof(struct fas216_cmd_priv),
0294 .can_queue = 8,
0295 .this_id = 7,
0296 .sg_tablesize = SG_MAX_SEGMENTS,
0297 .dma_boundary = IOMD_DMA_BOUNDARY,
0298 .cmd_per_lun = 2,
0299 .proc_name = "powertec",
0300 };
0301
0302 static int powertecscsi_probe(struct expansion_card *ec,
0303 const struct ecard_id *id)
0304 {
0305 struct Scsi_Host *host;
0306 struct powertec_info *info;
0307 void __iomem *base;
0308 int ret;
0309
0310 ret = ecard_request_resources(ec);
0311 if (ret)
0312 goto out;
0313
0314 base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
0315 if (!base) {
0316 ret = -ENOMEM;
0317 goto out_region;
0318 }
0319
0320 host = scsi_host_alloc(&powertecscsi_template,
0321 sizeof (struct powertec_info));
0322 if (!host) {
0323 ret = -ENOMEM;
0324 goto out_region;
0325 }
0326
0327 ecard_set_drvdata(ec, host);
0328
0329 info = (struct powertec_info *)host->hostdata;
0330 info->base = base;
0331 powertecscsi_terminator_ctl(host, term[ec->slot_no]);
0332
0333 info->ec = ec;
0334 info->info.scsi.io_base = base + POWERTEC_FAS216_OFFSET;
0335 info->info.scsi.io_shift = POWERTEC_FAS216_SHIFT;
0336 info->info.scsi.irq = ec->irq;
0337 info->info.scsi.dma = ec->dma;
0338 info->info.ifcfg.clockrate = 40;
0339 info->info.ifcfg.select_timeout = 255;
0340 info->info.ifcfg.asyncperiod = 200;
0341 info->info.ifcfg.sync_max_depth = 7;
0342 info->info.ifcfg.cntl3 = CNTL3_BS8 | CNTL3_FASTSCSI | CNTL3_FASTCLK;
0343 info->info.ifcfg.disconnect_ok = 1;
0344 info->info.ifcfg.wide_max_size = 0;
0345 info->info.ifcfg.capabilities = 0;
0346 info->info.dma.setup = powertecscsi_dma_setup;
0347 info->info.dma.pseudo = NULL;
0348 info->info.dma.stop = powertecscsi_dma_stop;
0349
0350 ec->irqaddr = base + POWERTEC_INTR_STATUS;
0351 ec->irqmask = POWERTEC_INTR_BIT;
0352
0353 ecard_setirq(ec, &powertecscsi_ops, info);
0354
0355 device_create_file(&ec->dev, &dev_attr_bus_term);
0356
0357 ret = fas216_init(host);
0358 if (ret)
0359 goto out_free;
0360
0361 ret = request_irq(ec->irq, powertecscsi_intr,
0362 0, "powertec", info);
0363 if (ret) {
0364 printk("scsi%d: IRQ%d not free: %d\n",
0365 host->host_no, ec->irq, ret);
0366 goto out_release;
0367 }
0368
0369 if (info->info.scsi.dma != NO_DMA) {
0370 if (request_dma(info->info.scsi.dma, "powertec")) {
0371 printk("scsi%d: DMA%d not free, using PIO\n",
0372 host->host_no, info->info.scsi.dma);
0373 info->info.scsi.dma = NO_DMA;
0374 } else {
0375 set_dma_speed(info->info.scsi.dma, 180);
0376 info->info.ifcfg.capabilities |= FASCAP_DMA;
0377 }
0378 }
0379
0380 ret = fas216_add(host, &ec->dev);
0381 if (ret == 0)
0382 goto out;
0383
0384 if (info->info.scsi.dma != NO_DMA)
0385 free_dma(info->info.scsi.dma);
0386 free_irq(ec->irq, info);
0387
0388 out_release:
0389 fas216_release(host);
0390
0391 out_free:
0392 device_remove_file(&ec->dev, &dev_attr_bus_term);
0393 scsi_host_put(host);
0394
0395 out_region:
0396 ecard_release_resources(ec);
0397
0398 out:
0399 return ret;
0400 }
0401
0402 static void powertecscsi_remove(struct expansion_card *ec)
0403 {
0404 struct Scsi_Host *host = ecard_get_drvdata(ec);
0405 struct powertec_info *info = (struct powertec_info *)host->hostdata;
0406
0407 ecard_set_drvdata(ec, NULL);
0408 fas216_remove(host);
0409
0410 device_remove_file(&ec->dev, &dev_attr_bus_term);
0411
0412 if (info->info.scsi.dma != NO_DMA)
0413 free_dma(info->info.scsi.dma);
0414 free_irq(ec->irq, info);
0415
0416 fas216_release(host);
0417 scsi_host_put(host);
0418 ecard_release_resources(ec);
0419 }
0420
0421 static const struct ecard_id powertecscsi_cids[] = {
0422 { MANU_ALSYSTEMS, PROD_ALSYS_SCSIATAPI },
0423 { 0xffff, 0xffff },
0424 };
0425
0426 static struct ecard_driver powertecscsi_driver = {
0427 .probe = powertecscsi_probe,
0428 .remove = powertecscsi_remove,
0429 .id_table = powertecscsi_cids,
0430 .drv = {
0431 .name = "powertecscsi",
0432 },
0433 };
0434
0435 static int __init powertecscsi_init(void)
0436 {
0437 return ecard_register_driver(&powertecscsi_driver);
0438 }
0439
0440 static void __exit powertecscsi_exit(void)
0441 {
0442 ecard_remove_driver(&powertecscsi_driver);
0443 }
0444
0445 module_init(powertecscsi_init);
0446 module_exit(powertecscsi_exit);
0447
0448 MODULE_AUTHOR("Russell King");
0449 MODULE_DESCRIPTION("Powertec SCSI driver");
0450 module_param_array(term, int, NULL, 0);
0451 MODULE_PARM_DESC(term, "SCSI bus termination");
0452 MODULE_LICENSE("GPL");