^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) dmx3191d.c - driver for the Domex DMX3191D SCSI card.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) Copyright (C) 2000 by Massimo Piccioni <dafastidio@libero.it>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) Portions Copyright (C) 2004 by Christoph Hellwig <hch@lst.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) Based on the generic NCR5380 driver by Drew Eckhardt et al.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * Definitions for the generic 5380 driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define NCR5380_read(reg) inb(hostdata->base + (reg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define NCR5380_write(reg, value) outb(value, hostdata->base + (reg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define NCR5380_dma_xfer_len NCR5380_dma_xfer_none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define NCR5380_dma_recv_setup NCR5380_dma_setup_none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define NCR5380_dma_send_setup NCR5380_dma_setup_none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define NCR5380_dma_residual NCR5380_dma_residual_none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define NCR5380_implementation_fields /* none */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include "NCR5380.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include "NCR5380.c"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define DMX3191D_DRIVER_NAME "dmx3191d"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define DMX3191D_REGION_LEN 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static struct scsi_host_template dmx3191d_driver_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) .module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) .proc_name = DMX3191D_DRIVER_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) .name = "Domex DMX3191D",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) .info = NCR5380_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) .queuecommand = NCR5380_queue_command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) .eh_abort_handler = NCR5380_abort,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) .eh_host_reset_handler = NCR5380_host_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) .can_queue = 32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) .this_id = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .sg_tablesize = SG_ALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) .cmd_per_lun = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) .dma_boundary = PAGE_SIZE - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) .cmd_size = NCR5380_CMD_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static int dmx3191d_probe_one(struct pci_dev *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) const struct pci_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct Scsi_Host *shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct NCR5380_hostdata *hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) unsigned long io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) int error = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (pci_enable_device(pdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) io = pci_resource_start(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (!request_region(io, DMX3191D_REGION_LEN, DMX3191D_DRIVER_NAME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) printk(KERN_ERR "dmx3191: region 0x%lx-0x%lx already reserved\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) io, io + DMX3191D_REGION_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) goto out_disable_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) shost = scsi_host_alloc(&dmx3191d_driver_template,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) sizeof(struct NCR5380_hostdata));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (!shost)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) goto out_release_region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) hostdata = shost_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) hostdata->base = io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /* This card does not seem to raise an interrupt on pdev->irq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * Steam-powered SCSI controllers run without an IRQ anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) shost->irq = NO_IRQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) error = NCR5380_init(shost, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) goto out_host_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) NCR5380_maybe_reset_bus(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) pci_set_drvdata(pdev, shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) error = scsi_add_host(shost, &pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) goto out_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) scsi_scan_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) out_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) NCR5380_exit(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) out_host_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) scsi_host_put(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) out_release_region:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) release_region(io, DMX3191D_REGION_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) out_disable_device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) pci_disable_device(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static void dmx3191d_remove_one(struct pci_dev *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct Scsi_Host *shost = pci_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct NCR5380_hostdata *hostdata = shost_priv(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) unsigned long io = hostdata->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) scsi_remove_host(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) NCR5380_exit(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) scsi_host_put(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) release_region(io, DMX3191D_REGION_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) pci_disable_device(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static struct pci_device_id dmx3191d_pci_tbl[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {PCI_VENDOR_ID_DOMEX, PCI_DEVICE_ID_DOMEX_DMX3191D,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) MODULE_DEVICE_TABLE(pci, dmx3191d_pci_tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static struct pci_driver dmx3191d_pci_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .name = DMX3191D_DRIVER_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) .id_table = dmx3191d_pci_tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) .probe = dmx3191d_probe_one,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .remove = dmx3191d_remove_one,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) module_pci_driver(dmx3191d_pci_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) MODULE_DESCRIPTION("Domex DMX3191D SCSI driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) MODULE_LICENSE("GPL");