Automatic merge of /spare/repo/netdev-2.6 branch natsemi
[linux-2.6] / drivers / scsi / dmx3191d.c
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 /*
34  * Defintions for the generic 5380 driver.
35  */
36 #define AUTOSENSE
37
38 #define NCR5380_read(reg)               inb(port + reg)
39 #define NCR5380_write(reg, value)       outb(value, port + reg)
40
41 #define NCR5380_implementation_fields   unsigned int port
42 #define NCR5380_local_declare()         NCR5380_implementation_fields
43 #define NCR5380_setup(instance)         port = instance->io_port
44
45 /*
46  * Includes needed for NCR5380.[ch] (XXX: Move them to NCR5380.h)
47  */
48 #include <linux/delay.h>
49 #include "scsi.h"
50
51 #include "NCR5380.h"
52 #include "NCR5380.c"
53
54 #define DMX3191D_DRIVER_NAME    "dmx3191d"
55 #define DMX3191D_REGION_LEN     8
56
57
58 static struct scsi_host_template dmx3191d_driver_template = {
59         .proc_name              = DMX3191D_DRIVER_NAME,
60         .name                   = "Domex DMX3191D",
61         .queuecommand           = NCR5380_queue_command,
62         .eh_abort_handler       = NCR5380_abort,
63         .eh_bus_reset_handler   = NCR5380_bus_reset,
64         .eh_device_reset_handler= NCR5380_device_reset,
65         .eh_host_reset_handler  = NCR5380_host_reset,
66         .can_queue              = 32,
67         .this_id                = 7,
68         .sg_tablesize           = SG_ALL,
69         .cmd_per_lun            = 2,
70         .use_clustering         = DISABLE_CLUSTERING,
71 };
72
73 static int __devinit dmx3191d_probe_one(struct pci_dev *pdev,
74                 const struct pci_device_id *id)
75 {
76         struct Scsi_Host *shost;
77         unsigned long io;
78         int error = -ENODEV;
79
80         if (pci_enable_device(pdev))
81                 goto out;
82
83         io = pci_resource_start(pdev, 0);
84         if (!request_region(io, DMX3191D_REGION_LEN, DMX3191D_DRIVER_NAME)) {
85                 printk(KERN_ERR "dmx3191: region 0x%lx-0x%lx already reserved\n",
86                                 io, io + DMX3191D_REGION_LEN);
87                 goto out_disable_device;
88         }
89
90         shost = scsi_host_alloc(&dmx3191d_driver_template,
91                         sizeof(struct NCR5380_hostdata));
92         if (!shost)
93                 goto out_release_region;       
94         shost->io_port = io;
95         shost->irq = pdev->irq;
96
97         NCR5380_init(shost, FLAG_NO_PSEUDO_DMA | FLAG_DTC3181E);
98
99         if (request_irq(pdev->irq, NCR5380_intr, SA_SHIRQ,
100                                 DMX3191D_DRIVER_NAME, shost)) {
101                 /*
102                  * Steam powered scsi controllers run without an IRQ anyway
103                  */
104                 printk(KERN_WARNING "dmx3191: IRQ %d not available - "
105                                     "switching to polled mode.\n", pdev->irq);
106                 shost->irq = SCSI_IRQ_NONE;
107         }
108
109         pci_set_drvdata(pdev, shost);
110
111         error = scsi_add_host(shost, &pdev->dev);
112         if (error)
113                 goto out_free_irq;
114
115         scsi_scan_host(shost);
116         return 0;
117
118  out_free_irq:
119         free_irq(shost->irq, shost);
120  out_release_region:
121         release_region(shost->io_port, DMX3191D_REGION_LEN);
122  out_disable_device:
123         pci_disable_device(pdev);
124  out:
125         return error;
126 }
127
128 static void __devexit dmx3191d_remove_one(struct pci_dev *pdev)
129 {
130         struct Scsi_Host *shost = pci_get_drvdata(pdev);
131
132         scsi_remove_host(shost);
133
134         NCR5380_exit(shost);
135
136         if (shost->irq != SCSI_IRQ_NONE)
137                 free_irq(shost->irq, shost);
138         release_region(shost->io_port, DMX3191D_REGION_LEN);
139         pci_disable_device(pdev);
140
141         scsi_host_put(shost);
142 }
143
144 static struct pci_device_id dmx3191d_pci_tbl[] = {
145         {PCI_VENDOR_ID_DOMEX, PCI_DEVICE_ID_DOMEX_DMX3191D,
146                 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
147         { }
148 };
149 MODULE_DEVICE_TABLE(pci, dmx3191d_pci_tbl);
150
151 static struct pci_driver dmx3191d_pci_driver = {
152         .name           = DMX3191D_DRIVER_NAME,
153         .id_table       = dmx3191d_pci_tbl,
154         .probe          = dmx3191d_probe_one,
155         .remove         = __devexit_p(dmx3191d_remove_one),
156 };
157
158 static int __init dmx3191d_init(void)
159 {
160         return pci_module_init(&dmx3191d_pci_driver);
161 }
162
163 static void __exit dmx3191d_exit(void)
164 {
165         pci_unregister_driver(&dmx3191d_pci_driver);
166 }
167
168 module_init(dmx3191d_init);
169 module_exit(dmx3191d_exit);
170
171 MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
172 MODULE_DESCRIPTION("Domex DMX3191D SCSI driver");
173 MODULE_LICENSE("GPL");