dmx3191d.c 4.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/*
    dmx3191d.c - driver for the Domex DMX3191D SCSI card.
    Copyright (C) 2000 by Massimo Piccioni <dafastidio@libero.it>
    Portions Copyright (C) 2004 by Christoph Hellwig <hch@lst.de>

    Based on the generic NCR5380 driver by Drew Eckhardt et al.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <linux/init.h>
#include <linux/ioport.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/interrupt.h>
#include <asm/io.h>

#include <scsi/scsi_host.h>

/*
34
 * Definitions for the generic 5380 driver.
L
Linus Torvalds 已提交
35 36
 */

37 38 39 40
#define priv(instance)	((struct NCR5380_hostdata *)shost_priv(instance))

#define NCR5380_read(reg)		inb(priv(instance)->base + (reg))
#define NCR5380_write(reg, value)	outb(value, priv(instance)->base + (reg))
L
Linus Torvalds 已提交
41

F
Finn Thain 已提交
42
#define NCR5380_dma_xfer_len(instance, cmd, phase)	(0)
F
Finn Thain 已提交
43 44
#define NCR5380_dma_recv_setup(instance, dst, len)	(0)
#define NCR5380_dma_send_setup(instance, src, len)	(0)
45
#define NCR5380_dma_residual(instance)			(0)
F
Finn Thain 已提交
46

47
#define NCR5380_implementation_fields	/* none */
L
Linus Torvalds 已提交
48 49 50 51 52 53 54 55 56

#include "NCR5380.h"
#include "NCR5380.c"

#define DMX3191D_DRIVER_NAME	"dmx3191d"
#define DMX3191D_REGION_LEN	8


static struct scsi_host_template dmx3191d_driver_template = {
57
	.module			= THIS_MODULE,
L
Linus Torvalds 已提交
58 59
	.proc_name		= DMX3191D_DRIVER_NAME,
	.name			= "Domex DMX3191D",
F
Finn Thain 已提交
60
	.info			= NCR5380_info,
L
Linus Torvalds 已提交
61 62 63 64 65 66 67 68
	.queuecommand		= NCR5380_queue_command,
	.eh_abort_handler	= NCR5380_abort,
	.eh_bus_reset_handler	= NCR5380_bus_reset,
	.can_queue		= 32,
	.this_id		= 7,
	.sg_tablesize		= SG_ALL,
	.cmd_per_lun		= 2,
	.use_clustering		= DISABLE_CLUSTERING,
69
	.cmd_size		= NCR5380_CMD_SIZE,
L
Linus Torvalds 已提交
70 71
};

72 73
static int dmx3191d_probe_one(struct pci_dev *pdev,
			      const struct pci_device_id *id)
L
Linus Torvalds 已提交
74 75
{
	struct Scsi_Host *shost;
76
	struct NCR5380_hostdata *hostdata;
L
Linus Torvalds 已提交
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
	unsigned long io;
	int error = -ENODEV;

	if (pci_enable_device(pdev))
		goto out;

	io = pci_resource_start(pdev, 0);
	if (!request_region(io, DMX3191D_REGION_LEN, DMX3191D_DRIVER_NAME)) {
		printk(KERN_ERR "dmx3191: region 0x%lx-0x%lx already reserved\n",
				io, io + DMX3191D_REGION_LEN);
		goto out_disable_device;
	}

	shost = scsi_host_alloc(&dmx3191d_driver_template,
			sizeof(struct NCR5380_hostdata));
	if (!shost)
		goto out_release_region;       
94 95 96

	hostdata = shost_priv(shost);
	hostdata->base = io;
L
Linus Torvalds 已提交
97

F
Finn Thain 已提交
98 99 100 101
	/* This card does not seem to raise an interrupt on pdev->irq.
	 * Steam-powered SCSI controllers run without an IRQ anyway.
	 */
	shost->irq = NO_IRQ;
L
Linus Torvalds 已提交
102

103
	error = NCR5380_init(shost, 0);
104 105
	if (error)
		goto out_host_put;
L
Linus Torvalds 已提交
106

107 108
	NCR5380_maybe_reset_bus(shost);

L
Linus Torvalds 已提交
109 110 111 112
	pci_set_drvdata(pdev, shost);

	error = scsi_add_host(shost, &pdev->dev);
	if (error)
113
		goto out_exit;
L
Linus Torvalds 已提交
114 115 116 117

	scsi_scan_host(shost);
	return 0;

118 119 120 121
out_exit:
	NCR5380_exit(shost);
out_host_put:
	scsi_host_put(shost);
L
Linus Torvalds 已提交
122
 out_release_region:
123
	release_region(io, DMX3191D_REGION_LEN);
L
Linus Torvalds 已提交
124 125 126 127 128 129
 out_disable_device:
	pci_disable_device(pdev);
 out:
	return error;
}

130
static void dmx3191d_remove_one(struct pci_dev *pdev)
L
Linus Torvalds 已提交
131 132
{
	struct Scsi_Host *shost = pci_get_drvdata(pdev);
133 134
	struct NCR5380_hostdata *hostdata = shost_priv(shost);
	unsigned long io = hostdata->base;
L
Linus Torvalds 已提交
135 136 137 138 139

	scsi_remove_host(shost);

	NCR5380_exit(shost);
	scsi_host_put(shost);
140 141
	release_region(io, DMX3191D_REGION_LEN);
	pci_disable_device(pdev);
L
Linus Torvalds 已提交
142 143 144 145 146 147 148 149 150 151 152 153 154
}

static struct pci_device_id dmx3191d_pci_tbl[] = {
	{PCI_VENDOR_ID_DOMEX, PCI_DEVICE_ID_DOMEX_DMX3191D,
		PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
	{ }
};
MODULE_DEVICE_TABLE(pci, dmx3191d_pci_tbl);

static struct pci_driver dmx3191d_pci_driver = {
	.name		= DMX3191D_DRIVER_NAME,
	.id_table	= dmx3191d_pci_tbl,
	.probe		= dmx3191d_probe_one,
155
	.remove		= dmx3191d_remove_one,
L
Linus Torvalds 已提交
156 157 158 159
};

static int __init dmx3191d_init(void)
{
160
	return pci_register_driver(&dmx3191d_pci_driver);
L
Linus Torvalds 已提交
161 162 163 164 165 166 167 168 169 170 171 172 173
}

static void __exit dmx3191d_exit(void)
{
	pci_unregister_driver(&dmx3191d_pci_driver);
}

module_init(dmx3191d_init);
module_exit(dmx3191d_exit);

MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
MODULE_DESCRIPTION("Domex DMX3191D SCSI driver");
MODULE_LICENSE("GPL");