Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | dmx3191d.c - driver for the Domex DMX3191D SCSI card. |
| 3 | Copyright (C) 2000 by Massimo Piccioni <dafastidio@libero.it> |
| 4 | Portions Copyright (C) 2004 by Christoph Hellwig <hch@lst.de> |
| 5 | |
| 6 | Based on the generic NCR5380 driver by Drew Eckhardt et al. |
| 7 | |
| 8 | This program is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program; if not, write to the Free Software |
| 20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/ioport.h> |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/pci.h> |
| 28 | #include <linux/interrupt.h> |
| 29 | #include <asm/io.h> |
| 30 | |
| 31 | #include <scsi/scsi_host.h> |
| 32 | |
| 33 | /* |
Adam Buchbinder | 6070d81 | 2009-12-04 15:47:01 -0500 | [diff] [blame] | 34 | * Definitions for the generic 5380 driver. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | #define NCR5380_read(reg) inb(port + reg) |
| 38 | #define NCR5380_write(reg, value) outb(value, port + reg) |
| 39 | |
Finn Thain | acfc8ca | 2014-11-12 16:11:48 +1100 | [diff] [blame] | 40 | #define NCR5380_implementation_fields /* none */ |
| 41 | #define NCR5380_local_declare() unsigned int port |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #define NCR5380_setup(instance) port = instance->io_port |
| 43 | |
| 44 | /* |
| 45 | * Includes needed for NCR5380.[ch] (XXX: Move them to NCR5380.h) |
| 46 | */ |
| 47 | #include <linux/delay.h> |
| 48 | #include "scsi.h" |
| 49 | |
| 50 | #include "NCR5380.h" |
| 51 | #include "NCR5380.c" |
| 52 | |
| 53 | #define DMX3191D_DRIVER_NAME "dmx3191d" |
| 54 | #define DMX3191D_REGION_LEN 8 |
| 55 | |
| 56 | |
| 57 | static struct scsi_host_template dmx3191d_driver_template = { |
| 58 | .proc_name = DMX3191D_DRIVER_NAME, |
| 59 | .name = "Domex DMX3191D", |
| 60 | .queuecommand = NCR5380_queue_command, |
| 61 | .eh_abort_handler = NCR5380_abort, |
| 62 | .eh_bus_reset_handler = NCR5380_bus_reset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | .can_queue = 32, |
| 64 | .this_id = 7, |
| 65 | .sg_tablesize = SG_ALL, |
| 66 | .cmd_per_lun = 2, |
| 67 | .use_clustering = DISABLE_CLUSTERING, |
| 68 | }; |
| 69 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 70 | static int dmx3191d_probe_one(struct pci_dev *pdev, |
| 71 | const struct pci_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | { |
| 73 | struct Scsi_Host *shost; |
| 74 | unsigned long io; |
| 75 | int error = -ENODEV; |
| 76 | |
| 77 | if (pci_enable_device(pdev)) |
| 78 | goto out; |
| 79 | |
| 80 | io = pci_resource_start(pdev, 0); |
| 81 | if (!request_region(io, DMX3191D_REGION_LEN, DMX3191D_DRIVER_NAME)) { |
| 82 | printk(KERN_ERR "dmx3191: region 0x%lx-0x%lx already reserved\n", |
| 83 | io, io + DMX3191D_REGION_LEN); |
| 84 | goto out_disable_device; |
| 85 | } |
| 86 | |
| 87 | shost = scsi_host_alloc(&dmx3191d_driver_template, |
| 88 | sizeof(struct NCR5380_hostdata)); |
| 89 | if (!shost) |
| 90 | goto out_release_region; |
| 91 | shost->io_port = io; |
| 92 | shost->irq = pdev->irq; |
| 93 | |
| 94 | NCR5380_init(shost, FLAG_NO_PSEUDO_DMA | FLAG_DTC3181E); |
| 95 | |
Thomas Gleixner | 1d6f359 | 2006-07-01 19:29:42 -0700 | [diff] [blame] | 96 | if (request_irq(pdev->irq, NCR5380_intr, IRQF_SHARED, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | DMX3191D_DRIVER_NAME, shost)) { |
| 98 | /* |
| 99 | * Steam powered scsi controllers run without an IRQ anyway |
| 100 | */ |
| 101 | printk(KERN_WARNING "dmx3191: IRQ %d not available - " |
| 102 | "switching to polled mode.\n", pdev->irq); |
| 103 | shost->irq = SCSI_IRQ_NONE; |
| 104 | } |
| 105 | |
| 106 | pci_set_drvdata(pdev, shost); |
| 107 | |
| 108 | error = scsi_add_host(shost, &pdev->dev); |
| 109 | if (error) |
| 110 | goto out_free_irq; |
| 111 | |
| 112 | scsi_scan_host(shost); |
| 113 | return 0; |
| 114 | |
| 115 | out_free_irq: |
| 116 | free_irq(shost->irq, shost); |
| 117 | out_release_region: |
Adrian Bunk | c3c026b | 2006-03-10 23:24:21 +0100 | [diff] [blame] | 118 | release_region(io, DMX3191D_REGION_LEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | out_disable_device: |
| 120 | pci_disable_device(pdev); |
| 121 | out: |
| 122 | return error; |
| 123 | } |
| 124 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 125 | static void dmx3191d_remove_one(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | { |
| 127 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 128 | |
| 129 | scsi_remove_host(shost); |
| 130 | |
| 131 | NCR5380_exit(shost); |
| 132 | |
| 133 | if (shost->irq != SCSI_IRQ_NONE) |
| 134 | free_irq(shost->irq, shost); |
| 135 | release_region(shost->io_port, DMX3191D_REGION_LEN); |
| 136 | pci_disable_device(pdev); |
| 137 | |
| 138 | scsi_host_put(shost); |
| 139 | } |
| 140 | |
| 141 | static struct pci_device_id dmx3191d_pci_tbl[] = { |
| 142 | {PCI_VENDOR_ID_DOMEX, PCI_DEVICE_ID_DOMEX_DMX3191D, |
| 143 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4}, |
| 144 | { } |
| 145 | }; |
| 146 | MODULE_DEVICE_TABLE(pci, dmx3191d_pci_tbl); |
| 147 | |
| 148 | static struct pci_driver dmx3191d_pci_driver = { |
| 149 | .name = DMX3191D_DRIVER_NAME, |
| 150 | .id_table = dmx3191d_pci_tbl, |
| 151 | .probe = dmx3191d_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 152 | .remove = dmx3191d_remove_one, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | }; |
| 154 | |
| 155 | static int __init dmx3191d_init(void) |
| 156 | { |
Henrik Kretzschmar | dcbccbde | 2006-09-25 16:58:58 -0700 | [diff] [blame] | 157 | return pci_register_driver(&dmx3191d_pci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | static void __exit dmx3191d_exit(void) |
| 161 | { |
| 162 | pci_unregister_driver(&dmx3191d_pci_driver); |
| 163 | } |
| 164 | |
| 165 | module_init(dmx3191d_init); |
| 166 | module_exit(dmx3191d_exit); |
| 167 | |
| 168 | MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>"); |
| 169 | MODULE_DESCRIPTION("Domex DMX3191D SCSI driver"); |
| 170 | MODULE_LICENSE("GPL"); |