sim710.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * sim710.c - Copyright (C) 1999 Richard Hirst <richard@sleepie.demon.co.uk>
  4. *
  5. *----------------------------------------------------------------------------
  6. *----------------------------------------------------------------------------
  7. *
  8. * MCA card detection code by Trent McNair. (now deleted)
  9. * Fixes to not explicitly nul bss data from Xavier Bestel.
  10. * Some multiboard fixes from Rolf Eike Beer.
  11. * Auto probing of EISA config space from Trevor Hemsley.
  12. *
  13. * Rewritten to use 53c700.c by James.Bottomley@SteelEye.com
  14. */
  15. #include <linux/module.h>
  16. #include <linux/slab.h>
  17. #include <linux/blkdev.h>
  18. #include <linux/device.h>
  19. #include <linux/init.h>
  20. #include <linux/eisa.h>
  21. #include <linux/interrupt.h>
  22. #include <scsi/scsi_host.h>
  23. #include <scsi/scsi_device.h>
  24. #include <scsi/scsi_transport.h>
  25. #include <scsi/scsi_transport_spi.h>
  26. #include "53c700.h"
  27. /* Must be enough for EISA */
  28. #define MAX_SLOTS 8
  29. static __u8 __initdata id_array[MAX_SLOTS] = { [0 ... MAX_SLOTS-1] = 7 };
  30. static char *sim710; /* command line passed by insmod */
  31. MODULE_AUTHOR("Richard Hirst");
  32. MODULE_DESCRIPTION("Simple NCR53C710 driver");
  33. MODULE_LICENSE("GPL");
  34. module_param(sim710, charp, 0);
  35. #ifdef MODULE
  36. #define ARG_SEP ' '
  37. #else
  38. #define ARG_SEP ','
  39. #endif
  40. static __init int
  41. param_setup(char *str)
  42. {
  43. char *pos = str, *next;
  44. int slot = -1;
  45. while(pos != NULL && (next = strchr(pos, ':')) != NULL) {
  46. int val = (int)simple_strtoul(++next, NULL, 0);
  47. if(!strncmp(pos, "slot:", 5))
  48. slot = val;
  49. else if(!strncmp(pos, "id:", 3)) {
  50. if(slot == -1) {
  51. printk(KERN_WARNING "sim710: Must specify slot for id parameter\n");
  52. } else if(slot >= MAX_SLOTS) {
  53. printk(KERN_WARNING "sim710: Illegal slot %d for id %d\n", slot, val);
  54. } else {
  55. id_array[slot] = val;
  56. }
  57. }
  58. if((pos = strchr(pos, ARG_SEP)) != NULL)
  59. pos++;
  60. }
  61. return 1;
  62. }
  63. __setup("sim710=", param_setup);
  64. static struct scsi_host_template sim710_driver_template = {
  65. .name = "LSI (Symbios) 710 EISA",
  66. .proc_name = "sim710",
  67. .this_id = 7,
  68. .module = THIS_MODULE,
  69. };
  70. static int sim710_probe_common(struct device *dev, unsigned long base_addr,
  71. int irq, int clock, int differential,
  72. int scsi_id)
  73. {
  74. struct Scsi_Host * host = NULL;
  75. struct NCR_700_Host_Parameters *hostdata =
  76. kzalloc(sizeof(struct NCR_700_Host_Parameters), GFP_KERNEL);
  77. printk(KERN_NOTICE "sim710: %s\n", dev_name(dev));
  78. printk(KERN_NOTICE "sim710: irq = %d, clock = %d, base = 0x%lx, scsi_id = %d\n",
  79. irq, clock, base_addr, scsi_id);
  80. if(hostdata == NULL) {
  81. printk(KERN_ERR "sim710: Failed to allocate host data\n");
  82. goto out;
  83. }
  84. if(request_region(base_addr, 64, "sim710") == NULL) {
  85. printk(KERN_ERR "sim710: Failed to reserve IO region 0x%lx\n",
  86. base_addr);
  87. goto out_free;
  88. }
  89. /* Fill in the three required pieces of hostdata */
  90. hostdata->base = ioport_map(base_addr, 64);
  91. hostdata->differential = differential;
  92. hostdata->clock = clock;
  93. hostdata->chip710 = 1;
  94. hostdata->burst_length = 8;
  95. /* and register the chip */
  96. if((host = NCR_700_detect(&sim710_driver_template, hostdata, dev))
  97. == NULL) {
  98. printk(KERN_ERR "sim710: No host detected; card configuration problem?\n");
  99. goto out_release;
  100. }
  101. host->this_id = scsi_id;
  102. host->base = base_addr;
  103. host->irq = irq;
  104. if (request_irq(irq, NCR_700_intr, IRQF_SHARED, "sim710", host)) {
  105. printk(KERN_ERR "sim710: request_irq failed\n");
  106. goto out_put_host;
  107. }
  108. dev_set_drvdata(dev, host);
  109. scsi_scan_host(host);
  110. return 0;
  111. out_put_host:
  112. scsi_host_put(host);
  113. out_release:
  114. release_region(base_addr, 64);
  115. out_free:
  116. kfree(hostdata);
  117. out:
  118. return -ENODEV;
  119. }
  120. static int sim710_device_remove(struct device *dev)
  121. {
  122. struct Scsi_Host *host = dev_get_drvdata(dev);
  123. struct NCR_700_Host_Parameters *hostdata =
  124. (struct NCR_700_Host_Parameters *)host->hostdata[0];
  125. scsi_remove_host(host);
  126. NCR_700_release(host);
  127. kfree(hostdata);
  128. free_irq(host->irq, host);
  129. release_region(host->base, 64);
  130. return 0;
  131. }
  132. #ifdef CONFIG_EISA
  133. static struct eisa_device_id sim710_eisa_ids[] = {
  134. { "CPQ4410" },
  135. { "CPQ4411" },
  136. { "HWP0C80" },
  137. { "" }
  138. };
  139. MODULE_DEVICE_TABLE(eisa, sim710_eisa_ids);
  140. static int sim710_eisa_probe(struct device *dev)
  141. {
  142. struct eisa_device *edev = to_eisa_device(dev);
  143. unsigned long io_addr = edev->base_addr;
  144. char eisa_cpq_irqs[] = { 11, 14, 15, 10, 9, 0 };
  145. char eisa_hwp_irqs[] = { 3, 4, 5, 7, 12, 10, 11, 0};
  146. char *eisa_irqs;
  147. unsigned char irq_index;
  148. unsigned char irq, differential = 0, scsi_id = 7;
  149. if(strcmp(edev->id.sig, "HWP0C80") == 0) {
  150. __u8 val;
  151. eisa_irqs = eisa_hwp_irqs;
  152. irq_index = (inb(io_addr + 0xc85) & 0x7) - 1;
  153. val = inb(io_addr + 0x4);
  154. scsi_id = ffs(val) - 1;
  155. if(scsi_id > 7 || (val & ~(1<<scsi_id)) != 0) {
  156. printk(KERN_ERR "sim710.c, EISA card %s has incorrect scsi_id, setting to 7\n", dev_name(dev));
  157. scsi_id = 7;
  158. }
  159. } else {
  160. eisa_irqs = eisa_cpq_irqs;
  161. irq_index = inb(io_addr + 0xc88) & 0x07;
  162. }
  163. if(irq_index >= strlen(eisa_irqs)) {
  164. printk("sim710.c: irq nasty\n");
  165. return -ENODEV;
  166. }
  167. irq = eisa_irqs[irq_index];
  168. return sim710_probe_common(dev, io_addr, irq, 50,
  169. differential, scsi_id);
  170. }
  171. static struct eisa_driver sim710_eisa_driver = {
  172. .id_table = sim710_eisa_ids,
  173. .driver = {
  174. .name = "sim710",
  175. .probe = sim710_eisa_probe,
  176. .remove = sim710_device_remove,
  177. },
  178. };
  179. #endif /* CONFIG_EISA */
  180. static int __init sim710_init(void)
  181. {
  182. int err = -ENODEV;
  183. #ifdef MODULE
  184. if (sim710)
  185. param_setup(sim710);
  186. #endif
  187. #ifdef CONFIG_EISA
  188. err = eisa_driver_register(&sim710_eisa_driver);
  189. #endif
  190. /* FIXME: what we'd really like to return here is -ENODEV if
  191. * no devices have actually been found. Instead, the err
  192. * above actually only reports problems with kobject_register,
  193. * so for the moment return success */
  194. return 0;
  195. }
  196. static void __exit sim710_exit(void)
  197. {
  198. #ifdef CONFIG_EISA
  199. eisa_driver_unregister(&sim710_eisa_driver);
  200. #endif
  201. }
  202. module_init(sim710_init);
  203. module_exit(sim710_exit);