Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 
0003 #include <linux/module.h>
0004 #include <linux/io.h>
0005 #include <linux/isa.h>
0006 #include <scsi/scsi_host.h>
0007 #include "fdomain.h"
0008 
0009 #define MAXBOARDS_PARAM 4
0010 static int io[MAXBOARDS_PARAM] = { 0, 0, 0, 0 };
0011 module_param_hw_array(io, int, ioport, NULL, 0);
0012 MODULE_PARM_DESC(io, "base I/O address of controller (0x140, 0x150, 0x160, 0x170)");
0013 
0014 static int irq[MAXBOARDS_PARAM] = { 0, 0, 0, 0 };
0015 module_param_hw_array(irq, int, irq, NULL, 0);
0016 MODULE_PARM_DESC(irq, "IRQ of controller (0=auto [default])");
0017 
0018 static int scsi_id[MAXBOARDS_PARAM] = { 0, 0, 0, 0 };
0019 module_param_hw_array(scsi_id, int, other, NULL, 0);
0020 MODULE_PARM_DESC(scsi_id, "SCSI ID of controller (default = 7)");
0021 
0022 static unsigned long addresses[] = {
0023     0xc8000,
0024     0xca000,
0025     0xce000,
0026     0xde000,
0027 };
0028 #define ADDRESS_COUNT ARRAY_SIZE(addresses)
0029 
0030 static unsigned short ports[] = { 0x140, 0x150, 0x160, 0x170 };
0031 #define PORT_COUNT ARRAY_SIZE(ports)
0032 
0033 static unsigned short irqs[] = { 3, 5, 10, 11, 12, 14, 15, 0 };
0034 
0035 /* This driver works *ONLY* for Future Domain cards using the TMC-1800,
0036  * TMC-18C50, or TMC-18C30 chip.  This includes models TMC-1650, 1660, 1670,
0037  * and 1680. These are all 16-bit cards.
0038  * BIOS versions prior to 3.2 assigned SCSI ID 6 to SCSI adapter.
0039  *
0040  * The following BIOS signature signatures are for boards which do *NOT*
0041  * work with this driver (these TMC-8xx and TMC-9xx boards may work with the
0042  * Seagate driver):
0043  *
0044  * FUTURE DOMAIN CORP. (C) 1986-1988 V4.0I 03/16/88
0045  * FUTURE DOMAIN CORP. (C) 1986-1989 V5.0C2/14/89
0046  * FUTURE DOMAIN CORP. (C) 1986-1989 V6.0A7/28/89
0047  * FUTURE DOMAIN CORP. (C) 1986-1990 V6.0105/31/90
0048  * FUTURE DOMAIN CORP. (C) 1986-1990 V6.0209/18/90
0049  * FUTURE DOMAIN CORP. (C) 1986-1990 V7.009/18/90
0050  * FUTURE DOMAIN CORP. (C) 1992 V8.00.004/02/92
0051  *
0052  * (The cards which do *NOT* work are all 8-bit cards -- although some of
0053  * them have a 16-bit form-factor, the upper 8-bits are used only for IRQs
0054  * and are *NOT* used for data. You can tell the difference by following
0055  * the tracings on the circuit board -- if only the IRQ lines are involved,
0056  * you have a "8-bit" card, and should *NOT* use this driver.)
0057  */
0058 
0059 static struct signature {
0060     const char *signature;
0061     int offset;
0062     int length;
0063     int this_id;
0064     int base_offset;
0065 } signatures[] = {
0066 /*          1         2         3         4         5         6 */
0067 /* 123456789012345678901234567890123456789012345678901234567890 */
0068 { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V2.07/28/89",  5, 50,  6, 0x1fcc },
0069 { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V1.07/28/89",  5, 50,  6, 0x1fcc },
0070 { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V2.07/28/89", 72, 50,  6, 0x1fa2 },
0071 { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V2.0",    73, 43,  6, 0x1fa2 },
0072 { "FUTURE DOMAIN CORP. (C) 1991 1800-V2.0.",        72, 39,  6, 0x1fa3 },
0073 { "FUTURE DOMAIN CORP. (C) 1992 V3.00.004/02/92",    5, 44,  6, 0 },
0074 { "FUTURE DOMAIN TMC-18XX (C) 1993 V3.203/12/93",    5, 44,  7, 0 },
0075 { "IBM F1 P2 BIOS v1.0011/09/92",            5, 28,  7, 0x1ff3 },
0076 { "IBM F1 P2 BIOS v1.0104/29/93",            5, 28,  7, 0 },
0077 { "Future Domain Corp. V1.0008/18/93",           5, 33,  7, 0 },
0078 { "Future Domain Corp. V2.0108/18/93",           5, 33,  7, 0 },
0079 { "FUTURE DOMAIN CORP.  V3.5008/18/93",          5, 34,  7, 0 },
0080 { "FUTURE DOMAIN 18c30/18c50/1800 (C) 1994 V3.5",    5, 44,  7, 0 },
0081 { "FUTURE DOMAIN CORP.  V3.6008/18/93",          5, 34,  7, 0 },
0082 { "FUTURE DOMAIN CORP.  V3.6108/18/93",          5, 34,  7, 0 },
0083 };
0084 #define SIGNATURE_COUNT ARRAY_SIZE(signatures)
0085 
0086 static int fdomain_isa_match(struct device *dev, unsigned int ndev)
0087 {
0088     struct Scsi_Host *sh;
0089     int i, base = 0, irq = 0;
0090     unsigned long bios_base = 0;
0091     struct signature *sig = NULL;
0092     void __iomem *p;
0093     static struct signature *saved_sig;
0094     int this_id = 7;
0095 
0096     if (ndev < ADDRESS_COUNT) { /* scan supported ISA BIOS addresses */
0097         p = ioremap(addresses[ndev], FDOMAIN_BIOS_SIZE);
0098         if (!p)
0099             return 0;
0100         for (i = 0; i < SIGNATURE_COUNT; i++)
0101             if (check_signature(p + signatures[i].offset,
0102                         signatures[i].signature,
0103                         signatures[i].length))
0104                 break;
0105         if (i == SIGNATURE_COUNT)   /* no signature found */
0106             goto fail_unmap;
0107         sig = &signatures[i];
0108         bios_base = addresses[ndev];
0109         /* read I/O base from BIOS area */
0110         if (sig->base_offset)
0111             base = readb(p + sig->base_offset) +
0112                   (readb(p + sig->base_offset + 1) << 8);
0113         iounmap(p);
0114         if (base) {
0115             dev_info(dev, "BIOS at 0x%lx specifies I/O base 0x%x\n",
0116                  bios_base, base);
0117         } else { /* no I/O base in BIOS area */
0118             dev_info(dev, "BIOS at 0x%lx\n", bios_base);
0119             /* save BIOS signature for later use in port probing */
0120             saved_sig = sig;
0121             return 0;
0122         }
0123     } else  /* scan supported I/O ports */
0124         base = ports[ndev - ADDRESS_COUNT];
0125 
0126     /* use saved BIOS signature if present */
0127     if (!sig && saved_sig)
0128         sig = saved_sig;
0129 
0130     if (!request_region(base, FDOMAIN_REGION_SIZE, "fdomain_isa"))
0131         return 0;
0132 
0133     irq = irqs[(inb(base + REG_CFG1) & CFG1_IRQ_MASK) >> 1];
0134 
0135     if (sig)
0136         this_id = sig->this_id;
0137 
0138     sh = fdomain_create(base, irq, this_id, dev);
0139     if (!sh) {
0140         release_region(base, FDOMAIN_REGION_SIZE);
0141         return 0;
0142     }
0143 
0144     dev_set_drvdata(dev, sh);
0145     return 1;
0146 fail_unmap:
0147     iounmap(p);
0148     return 0;
0149 }
0150 
0151 static int fdomain_isa_param_match(struct device *dev, unsigned int ndev)
0152 {
0153     struct Scsi_Host *sh;
0154     int irq_ = irq[ndev];
0155 
0156     if (!io[ndev])
0157         return 0;
0158 
0159     if (!request_region(io[ndev], FDOMAIN_REGION_SIZE, "fdomain_isa")) {
0160         dev_err(dev, "base 0x%x already in use", io[ndev]);
0161         return 0;
0162     }
0163 
0164     if (irq_ <= 0)
0165         irq_ = irqs[(inb(io[ndev] + REG_CFG1) & CFG1_IRQ_MASK) >> 1];
0166 
0167     sh = fdomain_create(io[ndev], irq_, scsi_id[ndev], dev);
0168     if (!sh) {
0169         dev_err(dev, "controller not found at base 0x%x", io[ndev]);
0170         release_region(io[ndev], FDOMAIN_REGION_SIZE);
0171         return 0;
0172     }
0173 
0174     dev_set_drvdata(dev, sh);
0175     return 1;
0176 }
0177 
0178 static void fdomain_isa_remove(struct device *dev, unsigned int ndev)
0179 {
0180     struct Scsi_Host *sh = dev_get_drvdata(dev);
0181     int base = sh->io_port;
0182 
0183     fdomain_destroy(sh);
0184     release_region(base, FDOMAIN_REGION_SIZE);
0185     dev_set_drvdata(dev, NULL);
0186 }
0187 
0188 static struct isa_driver fdomain_isa_driver = {
0189     .match      = fdomain_isa_match,
0190     .remove     = fdomain_isa_remove,
0191     .driver = {
0192         .name   = "fdomain_isa",
0193         .pm = FDOMAIN_PM_OPS,
0194     },
0195 };
0196 
0197 static int __init fdomain_isa_init(void)
0198 {
0199     int isa_probe_count = ADDRESS_COUNT + PORT_COUNT;
0200 
0201     if (io[0]) {    /* use module parameters if present */
0202         fdomain_isa_driver.match = fdomain_isa_param_match;
0203         isa_probe_count = MAXBOARDS_PARAM;
0204     }
0205 
0206     return isa_register_driver(&fdomain_isa_driver, isa_probe_count);
0207 }
0208 
0209 static void __exit fdomain_isa_exit(void)
0210 {
0211     isa_unregister_driver(&fdomain_isa_driver);
0212 }
0213 
0214 module_init(fdomain_isa_init);
0215 module_exit(fdomain_isa_exit);
0216 
0217 MODULE_AUTHOR("Ondrej Zary, Rickard E. Faith");
0218 MODULE_DESCRIPTION("Future Domain TMC-16x0 ISA SCSI driver");
0219 MODULE_LICENSE("GPL");