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 | |
Finn Thain | 61e1ce5 | 2016-10-10 00:46:53 -0400 | [diff] [blame] | 37 | #define NCR5380_read(reg) inb(hostdata->base + (reg)) |
| 38 | #define NCR5380_write(reg, value) outb(value, hostdata->base + (reg)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Finn Thain | 4a98f89 | 2016-10-10 00:46:53 -0400 | [diff] [blame] | 40 | #define NCR5380_dma_xfer_len NCR5380_dma_xfer_none |
| 41 | #define NCR5380_dma_recv_setup NCR5380_dma_setup_none |
| 42 | #define NCR5380_dma_send_setup NCR5380_dma_setup_none |
| 43 | #define NCR5380_dma_residual NCR5380_dma_residual_none |
Finn Thain | f825e40 | 2016-03-23 21:10:15 +1100 | [diff] [blame] | 44 | |
Finn Thain | acfc8ca | 2014-11-12 16:11:48 +1100 | [diff] [blame] | 45 | #define NCR5380_implementation_fields /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include "NCR5380.h" |
| 48 | #include "NCR5380.c" |
| 49 | |
| 50 | #define DMX3191D_DRIVER_NAME "dmx3191d" |
| 51 | #define DMX3191D_REGION_LEN 8 |
| 52 | |
| 53 | |
| 54 | static struct scsi_host_template dmx3191d_driver_template = { |
Finn Thain | aa2e2cb | 2016-01-03 16:05:48 +1100 | [diff] [blame] | 55 | .module = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | .proc_name = DMX3191D_DRIVER_NAME, |
| 57 | .name = "Domex DMX3191D", |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 58 | .info = NCR5380_info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | .queuecommand = NCR5380_queue_command, |
| 60 | .eh_abort_handler = NCR5380_abort, |
Hannes Reinecke | 12e5fc6 | 2017-08-25 13:57:10 +0200 | [diff] [blame] | 61 | .eh_host_reset_handler = NCR5380_host_reset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | .can_queue = 32, |
| 63 | .this_id = 7, |
| 64 | .sg_tablesize = SG_ALL, |
| 65 | .cmd_per_lun = 2, |
| 66 | .use_clustering = DISABLE_CLUSTERING, |
Finn Thain | 32b26a1 | 2016-01-03 16:05:58 +1100 | [diff] [blame] | 67 | .cmd_size = NCR5380_CMD_SIZE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Finn Thain | 820682b | 2016-10-10 00:46:53 -0400 | [diff] [blame] | 74 | struct NCR5380_hostdata *hostdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | unsigned long io; |
| 76 | int error = -ENODEV; |
| 77 | |
| 78 | if (pci_enable_device(pdev)) |
| 79 | goto out; |
| 80 | |
| 81 | io = pci_resource_start(pdev, 0); |
| 82 | if (!request_region(io, DMX3191D_REGION_LEN, DMX3191D_DRIVER_NAME)) { |
| 83 | printk(KERN_ERR "dmx3191: region 0x%lx-0x%lx already reserved\n", |
| 84 | io, io + DMX3191D_REGION_LEN); |
| 85 | goto out_disable_device; |
| 86 | } |
| 87 | |
| 88 | shost = scsi_host_alloc(&dmx3191d_driver_template, |
| 89 | sizeof(struct NCR5380_hostdata)); |
| 90 | if (!shost) |
| 91 | goto out_release_region; |
Finn Thain | 820682b | 2016-10-10 00:46:53 -0400 | [diff] [blame] | 92 | |
| 93 | hostdata = shost_priv(shost); |
| 94 | hostdata->base = io; |
Finn Thain | fd9cd67 | 2014-11-12 16:12:03 +1100 | [diff] [blame] | 95 | |
| 96 | /* This card does not seem to raise an interrupt on pdev->irq. |
| 97 | * Steam-powered SCSI controllers run without an IRQ anyway. |
| 98 | */ |
| 99 | shost->irq = NO_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Finn Thain | 7e9ec8d | 2016-03-23 21:10:11 +1100 | [diff] [blame] | 101 | error = NCR5380_init(shost, 0); |
Finn Thain | 0ad0eff | 2016-01-03 16:05:21 +1100 | [diff] [blame] | 102 | if (error) |
| 103 | goto out_host_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Finn Thain | b6488f9 | 2016-01-03 16:05:08 +1100 | [diff] [blame] | 105 | NCR5380_maybe_reset_bus(shost); |
| 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | pci_set_drvdata(pdev, shost); |
| 108 | |
| 109 | error = scsi_add_host(shost, &pdev->dev); |
| 110 | if (error) |
Finn Thain | 0ad0eff | 2016-01-03 16:05:21 +1100 | [diff] [blame] | 111 | goto out_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
| 113 | scsi_scan_host(shost); |
| 114 | return 0; |
| 115 | |
Finn Thain | 0ad0eff | 2016-01-03 16:05:21 +1100 | [diff] [blame] | 116 | out_exit: |
| 117 | NCR5380_exit(shost); |
| 118 | out_host_put: |
| 119 | scsi_host_put(shost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | out_release_region: |
Adrian Bunk | c3c026b | 2006-03-10 23:24:21 +0100 | [diff] [blame] | 121 | release_region(io, DMX3191D_REGION_LEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | out_disable_device: |
| 123 | pci_disable_device(pdev); |
| 124 | out: |
| 125 | return error; |
| 126 | } |
| 127 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 128 | static void dmx3191d_remove_one(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | { |
| 130 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
Finn Thain | 820682b | 2016-10-10 00:46:53 -0400 | [diff] [blame] | 131 | struct NCR5380_hostdata *hostdata = shost_priv(shost); |
| 132 | unsigned long io = hostdata->base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
| 134 | scsi_remove_host(shost); |
| 135 | |
| 136 | NCR5380_exit(shost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | scsi_host_put(shost); |
Finn Thain | 0ad0eff | 2016-01-03 16:05:21 +1100 | [diff] [blame] | 138 | release_region(io, DMX3191D_REGION_LEN); |
| 139 | pci_disable_device(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | static struct pci_device_id dmx3191d_pci_tbl[] = { |
| 143 | {PCI_VENDOR_ID_DOMEX, PCI_DEVICE_ID_DOMEX_DMX3191D, |
| 144 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4}, |
| 145 | { } |
| 146 | }; |
| 147 | MODULE_DEVICE_TABLE(pci, dmx3191d_pci_tbl); |
| 148 | |
| 149 | static struct pci_driver dmx3191d_pci_driver = { |
| 150 | .name = DMX3191D_DRIVER_NAME, |
| 151 | .id_table = dmx3191d_pci_tbl, |
| 152 | .probe = dmx3191d_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 153 | .remove = dmx3191d_remove_one, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | }; |
| 155 | |
Geliang Tang | 5e31501 | 2016-11-16 21:00:58 +0800 | [diff] [blame] | 156 | module_pci_driver(dmx3191d_pci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
| 158 | MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>"); |
| 159 | MODULE_DESCRIPTION("Domex DMX3191D SCSI driver"); |
| 160 | MODULE_LICENSE("GPL"); |