Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * sim710.c - Copyright (C) 1999 Richard Hirst <richard@sleepie.demon.co.uk> |
| 3 | * |
| 4 | *---------------------------------------------------------------------------- |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 | *---------------------------------------------------------------------------- |
| 19 | * |
| 20 | * MCA card detection code by Trent McNair. |
| 21 | * Fixes to not explicitly nul bss data from Xavier Bestel. |
| 22 | * Some multiboard fixes from Rolf Eike Beer. |
| 23 | * Auto probing of EISA config space from Trevor Hemsley. |
| 24 | * |
| 25 | * Rewritten to use 53c700.c by James.Bottomley@SteelEye.com |
| 26 | * |
| 27 | */ |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/module.h> |
| 30 | |
| 31 | #include <linux/blkdev.h> |
| 32 | #include <linux/device.h> |
| 33 | #include <linux/init.h> |
| 34 | #include <linux/mca.h> |
| 35 | #include <linux/eisa.h> |
| 36 | #include <linux/interrupt.h> |
| 37 | #include <scsi/scsi_host.h> |
| 38 | #include <scsi/scsi_device.h> |
| 39 | #include <scsi/scsi_transport.h> |
| 40 | #include <scsi/scsi_transport_spi.h> |
| 41 | |
| 42 | #include "53c700.h" |
| 43 | |
| 44 | |
| 45 | /* Must be enough for both EISA and MCA */ |
| 46 | #define MAX_SLOTS 8 |
| 47 | static __u8 __initdata id_array[MAX_SLOTS] = { [0 ... MAX_SLOTS-1] = 7 }; |
| 48 | |
| 49 | static char *sim710; /* command line passed by insmod */ |
| 50 | |
| 51 | MODULE_AUTHOR("Richard Hirst"); |
| 52 | MODULE_DESCRIPTION("Simple NCR53C710 driver"); |
| 53 | MODULE_LICENSE("GPL"); |
| 54 | |
| 55 | module_param(sim710, charp, 0); |
| 56 | |
| 57 | #ifdef MODULE |
| 58 | #define ARG_SEP ' ' |
| 59 | #else |
| 60 | #define ARG_SEP ',' |
| 61 | #endif |
| 62 | |
| 63 | static __init int |
| 64 | param_setup(char *str) |
| 65 | { |
| 66 | char *pos = str, *next; |
| 67 | int slot = -1; |
| 68 | |
| 69 | while(pos != NULL && (next = strchr(pos, ':')) != NULL) { |
| 70 | int val = (int)simple_strtoul(++next, NULL, 0); |
| 71 | |
| 72 | if(!strncmp(pos, "slot:", 5)) |
| 73 | slot = val; |
| 74 | else if(!strncmp(pos, "id:", 3)) { |
| 75 | if(slot == -1) { |
| 76 | printk(KERN_WARNING "sim710: Must specify slot for id parameter\n"); |
Eric Sesterhenn | 1a34456 | 2006-04-18 21:09:20 -0700 | [diff] [blame] | 77 | } else if(slot >= MAX_SLOTS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | printk(KERN_WARNING "sim710: Illegal slot %d for id %d\n", slot, val); |
| 79 | } else { |
| 80 | id_array[slot] = val; |
| 81 | } |
| 82 | } |
| 83 | if((pos = strchr(pos, ARG_SEP)) != NULL) |
| 84 | pos++; |
| 85 | } |
| 86 | return 1; |
| 87 | } |
| 88 | __setup("sim710=", param_setup); |
| 89 | |
| 90 | static struct scsi_host_template sim710_driver_template = { |
| 91 | .name = "LSI (Symbios) 710 MCA/EISA", |
| 92 | .proc_name = "sim710", |
| 93 | .this_id = 7, |
| 94 | .module = THIS_MODULE, |
| 95 | }; |
| 96 | |
| 97 | static __devinit int |
| 98 | sim710_probe_common(struct device *dev, unsigned long base_addr, |
| 99 | int irq, int clock, int differential, int scsi_id) |
| 100 | { |
| 101 | struct Scsi_Host * host = NULL; |
| 102 | struct NCR_700_Host_Parameters *hostdata = |
| 103 | kmalloc(sizeof(struct NCR_700_Host_Parameters), GFP_KERNEL); |
| 104 | |
| 105 | printk(KERN_NOTICE "sim710: %s\n", dev->bus_id); |
| 106 | printk(KERN_NOTICE "sim710: irq = %d, clock = %d, base = 0x%lx, scsi_id = %d\n", |
| 107 | irq, clock, base_addr, scsi_id); |
| 108 | |
| 109 | if(hostdata == NULL) { |
| 110 | printk(KERN_ERR "sim710: Failed to allocate host data\n"); |
| 111 | goto out; |
| 112 | } |
| 113 | memset(hostdata, 0, sizeof(struct NCR_700_Host_Parameters)); |
| 114 | |
| 115 | if(request_region(base_addr, 64, "sim710") == NULL) { |
| 116 | printk(KERN_ERR "sim710: Failed to reserve IO region 0x%lx\n", |
| 117 | base_addr); |
| 118 | goto out_free; |
| 119 | } |
| 120 | |
| 121 | /* Fill in the three required pieces of hostdata */ |
| 56fece2 | 2005-04-03 03:57:48 -0600 | [diff] [blame] | 122 | hostdata->base = ioport_map(base_addr, 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | hostdata->differential = differential; |
| 124 | hostdata->clock = clock; |
| 125 | hostdata->chip710 = 1; |
Thomas Bogendoerfer | f67a9c1 | 2006-12-25 21:30:08 +0100 | [diff] [blame] | 126 | hostdata->burst_length = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
| 128 | /* and register the chip */ |
| 129 | if((host = NCR_700_detect(&sim710_driver_template, hostdata, dev)) |
| 130 | == NULL) { |
| 131 | printk(KERN_ERR "sim710: No host detected; card configuration problem?\n"); |
| 132 | goto out_release; |
| 133 | } |
| 134 | host->this_id = scsi_id; |
| 56fece2 | 2005-04-03 03:57:48 -0600 | [diff] [blame] | 135 | host->base = base_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | host->irq = irq; |
Thomas Gleixner | 1d6f359 | 2006-07-01 19:29:42 -0700 | [diff] [blame] | 137 | if (request_irq(irq, NCR_700_intr, IRQF_SHARED, "sim710", host)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | printk(KERN_ERR "sim710: request_irq failed\n"); |
| 139 | goto out_put_host; |
| 140 | } |
| 141 | |
| 142 | scsi_scan_host(host); |
| 143 | |
| 144 | return 0; |
| 145 | |
| 146 | out_put_host: |
| 147 | scsi_host_put(host); |
| 148 | out_release: |
Adrian Bunk | a1d4f73 | 2006-03-10 23:25:00 +0100 | [diff] [blame] | 149 | release_region(base_addr, 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | out_free: |
| 151 | kfree(hostdata); |
| 152 | out: |
| 153 | return -ENODEV; |
| 154 | } |
| 155 | |
| 156 | static __devexit int |
| 157 | sim710_device_remove(struct device *dev) |
| 158 | { |
| 159 | struct Scsi_Host *host = dev_to_shost(dev); |
| 160 | struct NCR_700_Host_Parameters *hostdata = |
| 161 | (struct NCR_700_Host_Parameters *)host->hostdata[0]; |
| 162 | |
| 163 | scsi_remove_host(host); |
| 164 | NCR_700_release(host); |
| 165 | kfree(hostdata); |
| 166 | free_irq(host->irq, host); |
| 56fece2 | 2005-04-03 03:57:48 -0600 | [diff] [blame] | 167 | release_region(host->base, 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | #ifdef CONFIG_MCA |
| 172 | |
| 173 | /* CARD ID 01BB and 01BA use the same pos values */ |
| 174 | #define MCA_01BB_IO_PORTS { 0x0000, 0x0000, 0x0800, 0x0C00, 0x1000, 0x1400, \ |
| 175 | 0x1800, 0x1C00, 0x2000, 0x2400, 0x2800, \ |
| 176 | 0x2C00, 0x3000, 0x3400, 0x3800, 0x3C00, \ |
| 177 | 0x4000, 0x4400, 0x4800, 0x4C00, 0x5000 } |
| 178 | |
| 179 | #define MCA_01BB_IRQS { 3, 5, 11, 14 } |
| 180 | |
| 181 | /* CARD ID 004f */ |
| 182 | #define MCA_004F_IO_PORTS { 0x0000, 0x0200, 0x0300, 0x0400, 0x0500, 0x0600 } |
| 183 | #define MCA_004F_IRQS { 5, 9, 14 } |
| 184 | |
| 185 | static short sim710_mca_id_table[] = { 0x01bb, 0x01ba, 0x004f, 0}; |
| 186 | |
| 187 | static __init int |
| 188 | sim710_mca_probe(struct device *dev) |
| 189 | { |
| 190 | struct mca_device *mca_dev = to_mca_device(dev); |
| 191 | int slot = mca_dev->slot; |
| 192 | int pos[3]; |
| 193 | unsigned int base; |
| 194 | int irq_vector; |
| 195 | short id = sim710_mca_id_table[mca_dev->index]; |
| 196 | static int io_004f_by_pos[] = MCA_004F_IO_PORTS; |
| 197 | static int irq_004f_by_pos[] = MCA_004F_IRQS; |
| 198 | static int io_01bb_by_pos[] = MCA_01BB_IO_PORTS; |
| 199 | static int irq_01bb_by_pos[] = MCA_01BB_IRQS; |
| 200 | char *name; |
| 201 | int clock; |
| 202 | |
| 203 | pos[0] = mca_device_read_stored_pos(mca_dev, 2); |
| 204 | pos[1] = mca_device_read_stored_pos(mca_dev, 3); |
| 205 | pos[2] = mca_device_read_stored_pos(mca_dev, 4); |
| 206 | |
| 207 | /* |
| 208 | * 01BB & 01BA port base by bits 7,6,5,4,3,2 in pos[2] |
| 209 | * |
| 210 | * 000000 <disabled> 001010 0x2800 |
| 211 | * 000001 <invalid> 001011 0x2C00 |
| 212 | * 000010 0x0800 001100 0x3000 |
| 213 | * 000011 0x0C00 001101 0x3400 |
| 214 | * 000100 0x1000 001110 0x3800 |
| 215 | * 000101 0x1400 001111 0x3C00 |
| 216 | * 000110 0x1800 010000 0x4000 |
| 217 | * 000111 0x1C00 010001 0x4400 |
| 218 | * 001000 0x2000 010010 0x4800 |
| 219 | * 001001 0x2400 010011 0x4C00 |
| 220 | * 010100 0x5000 |
| 221 | * |
| 222 | * 00F4 port base by bits 3,2,1 in pos[0] |
| 223 | * |
| 224 | * 000 <disabled> 001 0x200 |
| 225 | * 010 0x300 011 0x400 |
| 226 | * 100 0x500 101 0x600 |
| 227 | * |
| 228 | * 01BB & 01BA IRQ is specified in pos[0] bits 7 and 6: |
| 229 | * |
| 230 | * 00 3 10 11 |
| 231 | * 01 5 11 14 |
| 232 | * |
| 233 | * 00F4 IRQ specified by bits 6,5,4 in pos[0] |
| 234 | * |
| 235 | * 100 5 101 9 |
| 236 | * 110 14 |
| 237 | */ |
| 238 | |
| 239 | if (id == 0x01bb || id == 0x01ba) { |
| 240 | base = io_01bb_by_pos[(pos[2] & 0xFC) >> 2]; |
| 241 | irq_vector = |
| 242 | irq_01bb_by_pos[((pos[0] & 0xC0) >> 6)]; |
| 243 | |
| 244 | clock = 50; |
| 245 | if (id == 0x01bb) |
| 246 | name = "NCR 3360/3430 SCSI SubSystem"; |
| 247 | else |
| 248 | name = "NCR Dual SIOP SCSI Host Adapter Board"; |
| 249 | } else if ( id == 0x004f ) { |
| 250 | base = io_004f_by_pos[((pos[0] & 0x0E) >> 1)]; |
| 251 | irq_vector = |
| 252 | irq_004f_by_pos[((pos[0] & 0x70) >> 4) - 4]; |
| 253 | clock = 50; |
| 254 | name = "NCR 53c710 SCSI Host Adapter Board"; |
| 255 | } else { |
| 256 | return -ENODEV; |
| 257 | } |
| 258 | mca_device_set_name(mca_dev, name); |
| 259 | mca_device_set_claim(mca_dev, 1); |
| 260 | base = mca_device_transform_ioport(mca_dev, base); |
| 261 | irq_vector = mca_device_transform_irq(mca_dev, irq_vector); |
| 262 | |
| 263 | return sim710_probe_common(dev, base, irq_vector, clock, |
| 264 | 0, id_array[slot]); |
| 265 | } |
| 266 | |
| 267 | static struct mca_driver sim710_mca_driver = { |
| 268 | .id_table = sim710_mca_id_table, |
| 269 | .driver = { |
| 270 | .name = "sim710", |
| 271 | .bus = &mca_bus_type, |
| 272 | .probe = sim710_mca_probe, |
| 273 | .remove = __devexit_p(sim710_device_remove), |
| 274 | }, |
| 275 | }; |
| 276 | |
| 277 | #endif /* CONFIG_MCA */ |
| 278 | |
| 279 | #ifdef CONFIG_EISA |
| 280 | static struct eisa_device_id sim710_eisa_ids[] = { |
| 281 | { "CPQ4410" }, |
| 282 | { "CPQ4411" }, |
| 283 | { "HWP0C80" }, |
| 284 | { "" } |
| 285 | }; |
Michael Tokarev | 07563c7 | 2006-09-27 01:50:56 -0700 | [diff] [blame] | 286 | MODULE_DEVICE_TABLE(eisa, sim710_eisa_ids); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
| 288 | static __init int |
| 289 | sim710_eisa_probe(struct device *dev) |
| 290 | { |
| 291 | struct eisa_device *edev = to_eisa_device(dev); |
| 292 | unsigned long io_addr = edev->base_addr; |
| 293 | char eisa_cpq_irqs[] = { 11, 14, 15, 10, 9, 0 }; |
| 294 | char eisa_hwp_irqs[] = { 3, 4, 5, 7, 12, 10, 11, 0}; |
| 295 | char *eisa_irqs; |
| 296 | unsigned char irq_index; |
| 297 | unsigned char irq, differential = 0, scsi_id = 7; |
| 298 | |
| 299 | if(strcmp(edev->id.sig, "HWP0C80") == 0) { |
| 300 | __u8 val; |
| 301 | eisa_irqs = eisa_hwp_irqs; |
| 302 | irq_index = (inb(io_addr + 0xc85) & 0x7) - 1; |
| 303 | |
| 304 | val = inb(io_addr + 0x4); |
| 305 | scsi_id = ffs(val) - 1; |
| 306 | |
| 307 | if(scsi_id > 7 || (val & ~(1<<scsi_id)) != 0) { |
| 308 | printk(KERN_ERR "sim710.c, EISA card %s has incorrect scsi_id, setting to 7\n", dev->bus_id); |
| 309 | scsi_id = 7; |
| 310 | } |
| 311 | } else { |
| 312 | eisa_irqs = eisa_cpq_irqs; |
| 313 | irq_index = inb(io_addr + 0xc88) & 0x07; |
| 314 | } |
| 315 | |
| 316 | if(irq_index >= strlen(eisa_irqs)) { |
| 317 | printk("sim710.c: irq nasty\n"); |
| 318 | return -ENODEV; |
| 319 | } |
| 320 | |
| 321 | irq = eisa_irqs[irq_index]; |
| 322 | |
| 323 | return sim710_probe_common(dev, io_addr, irq, 50, |
| 324 | differential, scsi_id); |
| 325 | } |
| 326 | |
| 327 | static struct eisa_driver sim710_eisa_driver = { |
| 328 | .id_table = sim710_eisa_ids, |
| 329 | .driver = { |
| 330 | .name = "sim710", |
| 331 | .probe = sim710_eisa_probe, |
| 332 | .remove = __devexit_p(sim710_device_remove), |
| 333 | }, |
| 334 | }; |
| 335 | #endif /* CONFIG_EISA */ |
| 336 | |
| 337 | static int __init sim710_init(void) |
| 338 | { |
| 339 | int err = -ENODEV; |
| 340 | |
| 341 | #ifdef MODULE |
| 342 | if (sim710) |
| 343 | param_setup(sim710); |
| 344 | #endif |
| 345 | |
| 346 | #ifdef CONFIG_MCA |
| 347 | err = mca_register_driver(&sim710_mca_driver); |
| 348 | #endif |
| 349 | |
| 350 | #ifdef CONFIG_EISA |
| 351 | err = eisa_driver_register(&sim710_eisa_driver); |
| 352 | #endif |
| 353 | /* FIXME: what we'd really like to return here is -ENODEV if |
| 354 | * no devices have actually been found. Instead, the err |
| 355 | * above actually only reports problems with kobject_register, |
| 356 | * so for the moment return success */ |
| 357 | |
| 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | static void __exit sim710_exit(void) |
| 362 | { |
| 363 | #ifdef CONFIG_MCA |
| 364 | if (MCA_bus) |
| 365 | mca_unregister_driver(&sim710_mca_driver); |
| 366 | #endif |
| 367 | |
| 368 | #ifdef CONFIG_EISA |
| 369 | eisa_driver_unregister(&sim710_eisa_driver); |
| 370 | #endif |
| 371 | } |
| 372 | |
| 373 | module_init(sim710_init); |
| 374 | module_exit(sim710_exit); |