ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / scsi / dmx3191d.c
1
2 /*
3     dmx3191d.c - midlevel driver for the Domex DMX3191D SCSI card.
4     Copyright (C) 2000 by Massimo Piccioni <dafastidio@libero.it>
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 <asm/io.h>
24 #include <asm/system.h>
25 #include <linux/blkdev.h>
26 #include <linux/init.h>
27 #include <linux/ioport.h>
28 #include <linux/module.h>
29 #include <linux/pci.h>
30 #include <linux/sched.h>
31 #include <linux/signal.h>
32 #include <linux/stat.h>
33 #include <linux/interrupt.h>
34 #include <linux/delay.h>
35
36 #include "scsi.h"
37 #include "hosts.h"
38
39 #include "dmx3191d.h"
40
41 /* play with these values to tune up your system performances */
42 /* default setting from g_NCR5380.c */
43 /*
44 #define USLEEP
45 #define USLEEP_POLL             1
46 #define USLEEP_SLEEP            20
47 #define USLEEP_WAITLONG         500
48 */
49
50 #define AUTOSENSE
51 #include "NCR5380.h"
52 #include "NCR5380.c"
53
54
55 static int __init dmx3191d_detect(Scsi_Host_Template *tmpl) {
56         int boards = 0;
57         struct Scsi_Host *instance = NULL;
58         struct pci_dev *pdev = NULL;
59
60         tmpl->proc_name = DMX3191D_DRIVER_NAME;
61
62         while ((pdev = pci_find_device(PCI_VENDOR_ID_DOMEX,
63                         PCI_DEVICE_ID_DOMEX_DMX3191D, pdev))) {
64
65                 unsigned long port;
66                 if (pci_enable_device(pdev))
67                         continue;
68
69                 port = pci_resource_start (pdev, 0);
70                 
71                 if (!request_region(port, DMX3191D_REGION, DMX3191D_DRIVER_NAME)) {
72                         printk(KERN_ERR "dmx3191: region 0x%lx-0x%lx already reserved\n",
73                                 port, port + DMX3191D_REGION);
74                         continue;
75                 }
76
77                 instance = scsi_register(tmpl, sizeof(struct NCR5380_hostdata));
78                 if(instance == NULL)
79                 {
80                         release_region(port, DMX3191D_REGION);
81                         continue;
82                 }
83                 scsi_set_device(instance, &pdev->dev);
84                 instance->io_port = port;
85                 instance->irq = pdev->irq;
86                 NCR5380_init(instance, FLAG_NO_PSEUDO_DMA | FLAG_DTC3181E);
87
88                 if (request_irq(pdev->irq, dmx3191d_intr, SA_SHIRQ,
89                                 DMX3191D_DRIVER_NAME, instance)) {
90                         printk(KERN_WARNING "dmx3191: IRQ %d not available - switching to polled mode.\n", pdev->irq);
91                         /* Steam powered scsi controllers run without an IRQ
92                            anyway */
93                         instance->irq = SCSI_IRQ_NONE;
94                 }
95
96                 boards++;
97         }
98         return boards;
99 }
100
101 static const char * dmx3191d_info(struct Scsi_Host *host) {
102         static const char *info ="Domex DMX3191D";
103
104         return info;
105 }
106
107 static int dmx3191d_release_resources(struct Scsi_Host *instance)
108 {
109         release_region(instance->io_port, DMX3191D_REGION);
110         if(instance->irq!=SCSI_IRQ_NONE)
111                 free_irq(instance->irq, instance);
112
113         return 0;
114 }
115
116 MODULE_LICENSE("GPL");
117
118 static Scsi_Host_Template driver_template = {
119         .proc_info              = dmx3191d_proc_info,
120         .name                   = "Domex DMX3191D",
121         .detect                 = dmx3191d_detect,
122         .release                = dmx3191d_release_resources,
123         .info                   = dmx3191d_info,
124         .queuecommand           = dmx3191d_queue_command,
125         .eh_abort_handler       = dmx3191d_abort,
126         .eh_bus_reset_handler   = dmx3191d_bus_reset,
127         .eh_device_reset_handler = dmx3191d_device_reset,
128         .eh_host_reset_handler  = dmx3191d_host_reset,
129         .can_queue              = 32,
130         .this_id                = 7,
131         .sg_tablesize           = SG_ALL,
132         .cmd_per_lun            = 2,
133         .use_clustering         = DISABLE_CLUSTERING,
134 };
135 #include "scsi_module.c"
136