blob: 6df60b31ecb0d62f66d0d11b9c2e9ec808cc3316 [file] [log] [blame]
Thomas Gleixner74ba9202019-05-20 09:19:02 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 dmx3191d.c - driver for the Domex DMX3191D SCSI card.
4 Copyright (C) 2000 by Massimo Piccioni <dafastidio@libero.it>
5 Portions Copyright (C) 2004 by Christoph Hellwig <hch@lst.de>
6
7 Based on the generic NCR5380 driver by Drew Eckhardt et al.
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009*/
10
11#include <linux/init.h>
12#include <linux/ioport.h>
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/pci.h>
16#include <linux/interrupt.h>
17#include <asm/io.h>
18
19#include <scsi/scsi_host.h>
20
21/*
Adam Buchbinder6070d812009-12-04 15:47:01 -050022 * Definitions for the generic 5380 driver.
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Finn Thain61e1ce52016-10-10 00:46:53 -040025#define NCR5380_read(reg) inb(hostdata->base + (reg))
26#define NCR5380_write(reg, value) outb(value, hostdata->base + (reg))
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Finn Thain4a98f892016-10-10 00:46:53 -040028#define NCR5380_dma_xfer_len NCR5380_dma_xfer_none
29#define NCR5380_dma_recv_setup NCR5380_dma_setup_none
30#define NCR5380_dma_send_setup NCR5380_dma_setup_none
31#define NCR5380_dma_residual NCR5380_dma_residual_none
Finn Thainf825e402016-03-23 21:10:15 +110032
Finn Thainacfc8ca2014-11-12 16:11:48 +110033#define NCR5380_implementation_fields /* none */
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include "NCR5380.h"
36#include "NCR5380.c"
37
38#define DMX3191D_DRIVER_NAME "dmx3191d"
39#define DMX3191D_REGION_LEN 8
40
41
42static struct scsi_host_template dmx3191d_driver_template = {
Finn Thainaa2e2cb12016-01-03 16:05:48 +110043 .module = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 .proc_name = DMX3191D_DRIVER_NAME,
45 .name = "Domex DMX3191D",
Finn Thain8c325132014-11-12 16:11:58 +110046 .info = NCR5380_info,
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 .queuecommand = NCR5380_queue_command,
48 .eh_abort_handler = NCR5380_abort,
Hannes Reinecke12e5fc62017-08-25 13:57:10 +020049 .eh_host_reset_handler = NCR5380_host_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 .can_queue = 32,
51 .this_id = 7,
52 .sg_tablesize = SG_ALL,
53 .cmd_per_lun = 2,
Christoph Hellwig4af14d12018-12-13 16:17:09 +010054 .dma_boundary = PAGE_SIZE - 1,
Finn Thain32b26a12016-01-03 16:05:58 +110055 .cmd_size = NCR5380_CMD_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -070056};
57
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080058static int dmx3191d_probe_one(struct pci_dev *pdev,
59 const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
61 struct Scsi_Host *shost;
Finn Thain820682b2016-10-10 00:46:53 -040062 struct NCR5380_hostdata *hostdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 unsigned long io;
64 int error = -ENODEV;
65
66 if (pci_enable_device(pdev))
67 goto out;
68
69 io = pci_resource_start(pdev, 0);
70 if (!request_region(io, DMX3191D_REGION_LEN, DMX3191D_DRIVER_NAME)) {
71 printk(KERN_ERR "dmx3191: region 0x%lx-0x%lx already reserved\n",
72 io, io + DMX3191D_REGION_LEN);
73 goto out_disable_device;
74 }
75
76 shost = scsi_host_alloc(&dmx3191d_driver_template,
77 sizeof(struct NCR5380_hostdata));
78 if (!shost)
79 goto out_release_region;
Finn Thain820682b2016-10-10 00:46:53 -040080
81 hostdata = shost_priv(shost);
82 hostdata->base = io;
Finn Thainfd9cd672014-11-12 16:12:03 +110083
84 /* This card does not seem to raise an interrupt on pdev->irq.
85 * Steam-powered SCSI controllers run without an IRQ anyway.
86 */
87 shost->irq = NO_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Finn Thain7e9ec8d2016-03-23 21:10:11 +110089 error = NCR5380_init(shost, 0);
Finn Thain0ad0eff2016-01-03 16:05:21 +110090 if (error)
91 goto out_host_put;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Finn Thainb6488f92016-01-03 16:05:08 +110093 NCR5380_maybe_reset_bus(shost);
94
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 pci_set_drvdata(pdev, shost);
96
97 error = scsi_add_host(shost, &pdev->dev);
98 if (error)
Finn Thain0ad0eff2016-01-03 16:05:21 +110099 goto out_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101 scsi_scan_host(shost);
102 return 0;
103
Finn Thain0ad0eff2016-01-03 16:05:21 +1100104out_exit:
105 NCR5380_exit(shost);
106out_host_put:
107 scsi_host_put(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 out_release_region:
Adrian Bunkc3c026b2006-03-10 23:24:21 +0100109 release_region(io, DMX3191D_REGION_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 out_disable_device:
111 pci_disable_device(pdev);
112 out:
113 return error;
114}
115
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800116static void dmx3191d_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117{
118 struct Scsi_Host *shost = pci_get_drvdata(pdev);
Finn Thain820682b2016-10-10 00:46:53 -0400119 struct NCR5380_hostdata *hostdata = shost_priv(shost);
120 unsigned long io = hostdata->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122 scsi_remove_host(shost);
123
124 NCR5380_exit(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 scsi_host_put(shost);
Finn Thain0ad0eff2016-01-03 16:05:21 +1100126 release_region(io, DMX3191D_REGION_LEN);
127 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128}
129
130static struct pci_device_id dmx3191d_pci_tbl[] = {
131 {PCI_VENDOR_ID_DOMEX, PCI_DEVICE_ID_DOMEX_DMX3191D,
132 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
133 { }
134};
135MODULE_DEVICE_TABLE(pci, dmx3191d_pci_tbl);
136
137static struct pci_driver dmx3191d_pci_driver = {
138 .name = DMX3191D_DRIVER_NAME,
139 .id_table = dmx3191d_pci_tbl,
140 .probe = dmx3191d_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800141 .remove = dmx3191d_remove_one,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142};
143
Geliang Tang5e315012016-11-16 21:00:58 +0800144module_pci_driver(dmx3191d_pci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
147MODULE_DESCRIPTION("Domex DMX3191D SCSI driver");
148MODULE_LICENSE("GPL");