dmx3191d.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. Based on the generic NCR5380 driver by Drew Eckhardt et al.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include <linux/init.h>
  19. #include <linux/ioport.h>
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <asm/io.h>
  25. #include <scsi/scsi_host.h>
  26. /*
  27. * Defintions for the generic 5380 driver.
  28. */
  29. #define AUTOSENSE
  30. #define NCR5380_read(reg) inb(port + reg)
  31. #define NCR5380_write(reg, value) outb(value, port + reg)
  32. #define NCR5380_implementation_fields unsigned int port
  33. #define NCR5380_local_declare() NCR5380_implementation_fields
  34. #define NCR5380_setup(instance) port = instance->io_port
  35. /*
  36. * Includes needed for NCR5380.[ch] (XXX: Move them to NCR5380.h)
  37. */
  38. #include <linux/delay.h>
  39. #include "scsi.h"
  40. #include "NCR5380.h"
  41. #include "NCR5380.c"
  42. #define DMX3191D_DRIVER_NAME "dmx3191d"
  43. #define DMX3191D_REGION_LEN 8
  44. static struct scsi_host_template dmx3191d_driver_template = {
  45. .proc_name = DMX3191D_DRIVER_NAME,
  46. .name = "Domex DMX3191D",
  47. .queuecommand = NCR5380_queue_command,
  48. .eh_abort_handler = NCR5380_abort,
  49. .eh_bus_reset_handler = NCR5380_bus_reset,
  50. .eh_device_reset_handler= NCR5380_device_reset,
  51. .eh_host_reset_handler = NCR5380_host_reset,
  52. .can_queue = 32,
  53. .this_id = 7,
  54. .sg_tablesize = SG_ALL,
  55. .cmd_per_lun = 2,
  56. .use_clustering = DISABLE_CLUSTERING,
  57. };
  58. static int __devinit dmx3191d_probe_one(struct pci_dev *pdev,
  59. const struct pci_device_id *id)
  60. {
  61. struct Scsi_Host *shost;
  62. unsigned long io;
  63. int error = -ENODEV;
  64. if (pci_enable_device(pdev))
  65. goto out;
  66. io = pci_resource_start(pdev, 0);
  67. if (!request_region(io, DMX3191D_REGION_LEN, DMX3191D_DRIVER_NAME)) {
  68. printk(KERN_ERR "dmx3191: region 0x%lx-0x%lx already reserved\n",
  69. io, io + DMX3191D_REGION_LEN);
  70. goto out_disable_device;
  71. }
  72. shost = scsi_host_alloc(&dmx3191d_driver_template,
  73. sizeof(struct NCR5380_hostdata));
  74. if (!shost)
  75. goto out_release_region;
  76. shost->io_port = io;
  77. shost->irq = pdev->irq;
  78. NCR5380_init(shost, FLAG_NO_PSEUDO_DMA | FLAG_DTC3181E);
  79. if (request_irq(pdev->irq, NCR5380_intr, SA_SHIRQ,
  80. DMX3191D_DRIVER_NAME, shost)) {
  81. /*
  82. * Steam powered scsi controllers run without an IRQ anyway
  83. */
  84. printk(KERN_WARNING "dmx3191: IRQ %d not available - "
  85. "switching to polled mode.\n", pdev->irq);
  86. shost->irq = SCSI_IRQ_NONE;
  87. }
  88. pci_set_drvdata(pdev, shost);
  89. error = scsi_add_host(shost, &pdev->dev);
  90. if (error)
  91. goto out_free_irq;
  92. scsi_scan_host(shost);
  93. return 0;
  94. out_free_irq:
  95. free_irq(shost->irq, shost);
  96. out_release_region:
  97. release_region(shost->io_port, DMX3191D_REGION_LEN);
  98. out_disable_device:
  99. pci_disable_device(pdev);
  100. out:
  101. return error;
  102. }
  103. static void __devexit dmx3191d_remove_one(struct pci_dev *pdev)
  104. {
  105. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  106. scsi_remove_host(shost);
  107. NCR5380_exit(shost);
  108. if (shost->irq != SCSI_IRQ_NONE)
  109. free_irq(shost->irq, shost);
  110. release_region(shost->io_port, DMX3191D_REGION_LEN);
  111. pci_disable_device(pdev);
  112. scsi_host_put(shost);
  113. }
  114. static struct pci_device_id dmx3191d_pci_tbl[] = {
  115. {PCI_VENDOR_ID_DOMEX, PCI_DEVICE_ID_DOMEX_DMX3191D,
  116. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
  117. { }
  118. };
  119. MODULE_DEVICE_TABLE(pci, dmx3191d_pci_tbl);
  120. static struct pci_driver dmx3191d_pci_driver = {
  121. .name = DMX3191D_DRIVER_NAME,
  122. .id_table = dmx3191d_pci_tbl,
  123. .probe = dmx3191d_probe_one,
  124. .remove = __devexit_p(dmx3191d_remove_one),
  125. };
  126. static int __init dmx3191d_init(void)
  127. {
  128. return pci_module_init(&dmx3191d_pci_driver);
  129. }
  130. static void __exit dmx3191d_exit(void)
  131. {
  132. pci_unregister_driver(&dmx3191d_pci_driver);
  133. }
  134. module_init(dmx3191d_init);
  135. module_exit(dmx3191d_exit);
  136. MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
  137. MODULE_DESCRIPTION("Domex DMX3191D SCSI driver");
  138. MODULE_LICENSE("GPL");