sim710.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. /*
  2. * sim710.c - Copyright (C) 1999 Richard Hirst <richard@sleepie.demon.co.uk>
  3. *
  4. *----------------------------------------------------------------------------
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  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. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. *----------------------------------------------------------------------------
  19. *
  20. * MCA card detection code by Trent McNair.
  21. * Fixes to not explicitly nul bss data from Xavier Bestel.
  22. * Some multiboard fixes from Rolf Eike Beer.
  23. * Auto probing of EISA config space from Trevor Hemsley.
  24. *
  25. * Rewritten to use 53c700.c by James.Bottomley@SteelEye.com
  26. *
  27. */
  28. #include <linux/module.h>
  29. #include <linux/blkdev.h>
  30. #include <linux/device.h>
  31. #include <linux/init.h>
  32. #include <linux/mca.h>
  33. #include <linux/eisa.h>
  34. #include <linux/interrupt.h>
  35. #include <scsi/scsi_host.h>
  36. #include <scsi/scsi_device.h>
  37. #include <scsi/scsi_transport.h>
  38. #include <scsi/scsi_transport_spi.h>
  39. #include "53c700.h"
  40. /* Must be enough for both EISA and MCA */
  41. #define MAX_SLOTS 8
  42. static __u8 __initdata id_array[MAX_SLOTS] = { [0 ... MAX_SLOTS-1] = 7 };
  43. static char *sim710; /* command line passed by insmod */
  44. MODULE_AUTHOR("Richard Hirst");
  45. MODULE_DESCRIPTION("Simple NCR53C710 driver");
  46. MODULE_LICENSE("GPL");
  47. module_param(sim710, charp, 0);
  48. #ifdef MODULE
  49. #define ARG_SEP ' '
  50. #else
  51. #define ARG_SEP ','
  52. #endif
  53. static __init int
  54. param_setup(char *str)
  55. {
  56. char *pos = str, *next;
  57. int slot = -1;
  58. while(pos != NULL && (next = strchr(pos, ':')) != NULL) {
  59. int val = (int)simple_strtoul(++next, NULL, 0);
  60. if(!strncmp(pos, "slot:", 5))
  61. slot = val;
  62. else if(!strncmp(pos, "id:", 3)) {
  63. if(slot == -1) {
  64. printk(KERN_WARNING "sim710: Must specify slot for id parameter\n");
  65. } else if(slot >= MAX_SLOTS) {
  66. printk(KERN_WARNING "sim710: Illegal slot %d for id %d\n", slot, val);
  67. } else {
  68. id_array[slot] = val;
  69. }
  70. }
  71. if((pos = strchr(pos, ARG_SEP)) != NULL)
  72. pos++;
  73. }
  74. return 1;
  75. }
  76. __setup("sim710=", param_setup);
  77. static struct scsi_host_template sim710_driver_template = {
  78. .name = "LSI (Symbios) 710 MCA/EISA",
  79. .proc_name = "sim710",
  80. .this_id = 7,
  81. .module = THIS_MODULE,
  82. };
  83. static __devinit int
  84. sim710_probe_common(struct device *dev, unsigned long base_addr,
  85. int irq, int clock, int differential, int scsi_id)
  86. {
  87. struct Scsi_Host * host = NULL;
  88. struct NCR_700_Host_Parameters *hostdata =
  89. kmalloc(sizeof(struct NCR_700_Host_Parameters), GFP_KERNEL);
  90. printk(KERN_NOTICE "sim710: %s\n", dev->bus_id);
  91. printk(KERN_NOTICE "sim710: irq = %d, clock = %d, base = 0x%lx, scsi_id = %d\n",
  92. irq, clock, base_addr, scsi_id);
  93. if(hostdata == NULL) {
  94. printk(KERN_ERR "sim710: Failed to allocate host data\n");
  95. goto out;
  96. }
  97. memset(hostdata, 0, sizeof(struct NCR_700_Host_Parameters));
  98. if(request_region(base_addr, 64, "sim710") == NULL) {
  99. printk(KERN_ERR "sim710: Failed to reserve IO region 0x%lx\n",
  100. base_addr);
  101. goto out_free;
  102. }
  103. /* Fill in the three required pieces of hostdata */
  104. hostdata->base = ioport_map(base_addr, 64);
  105. hostdata->differential = differential;
  106. hostdata->clock = clock;
  107. hostdata->chip710 = 1;
  108. hostdata->burst_length = 8;
  109. /* and register the chip */
  110. if((host = NCR_700_detect(&sim710_driver_template, hostdata, dev))
  111. == NULL) {
  112. printk(KERN_ERR "sim710: No host detected; card configuration problem?\n");
  113. goto out_release;
  114. }
  115. host->this_id = scsi_id;
  116. host->base = base_addr;
  117. host->irq = irq;
  118. if (request_irq(irq, NCR_700_intr, IRQF_SHARED, "sim710", host)) {
  119. printk(KERN_ERR "sim710: request_irq failed\n");
  120. goto out_put_host;
  121. }
  122. scsi_scan_host(host);
  123. return 0;
  124. out_put_host:
  125. scsi_host_put(host);
  126. out_release:
  127. release_region(base_addr, 64);
  128. out_free:
  129. kfree(hostdata);
  130. out:
  131. return -ENODEV;
  132. }
  133. static __devexit int
  134. sim710_device_remove(struct device *dev)
  135. {
  136. struct Scsi_Host *host = dev_to_shost(dev);
  137. struct NCR_700_Host_Parameters *hostdata =
  138. (struct NCR_700_Host_Parameters *)host->hostdata[0];
  139. scsi_remove_host(host);
  140. NCR_700_release(host);
  141. kfree(hostdata);
  142. free_irq(host->irq, host);
  143. release_region(host->base, 64);
  144. return 0;
  145. }
  146. #ifdef CONFIG_MCA
  147. /* CARD ID 01BB and 01BA use the same pos values */
  148. #define MCA_01BB_IO_PORTS { 0x0000, 0x0000, 0x0800, 0x0C00, 0x1000, 0x1400, \
  149. 0x1800, 0x1C00, 0x2000, 0x2400, 0x2800, \
  150. 0x2C00, 0x3000, 0x3400, 0x3800, 0x3C00, \
  151. 0x4000, 0x4400, 0x4800, 0x4C00, 0x5000 }
  152. #define MCA_01BB_IRQS { 3, 5, 11, 14 }
  153. /* CARD ID 004f */
  154. #define MCA_004F_IO_PORTS { 0x0000, 0x0200, 0x0300, 0x0400, 0x0500, 0x0600 }
  155. #define MCA_004F_IRQS { 5, 9, 14 }
  156. static short sim710_mca_id_table[] = { 0x01bb, 0x01ba, 0x004f, 0};
  157. static __init int
  158. sim710_mca_probe(struct device *dev)
  159. {
  160. struct mca_device *mca_dev = to_mca_device(dev);
  161. int slot = mca_dev->slot;
  162. int pos[3];
  163. unsigned int base;
  164. int irq_vector;
  165. short id = sim710_mca_id_table[mca_dev->index];
  166. static int io_004f_by_pos[] = MCA_004F_IO_PORTS;
  167. static int irq_004f_by_pos[] = MCA_004F_IRQS;
  168. static int io_01bb_by_pos[] = MCA_01BB_IO_PORTS;
  169. static int irq_01bb_by_pos[] = MCA_01BB_IRQS;
  170. char *name;
  171. int clock;
  172. pos[0] = mca_device_read_stored_pos(mca_dev, 2);
  173. pos[1] = mca_device_read_stored_pos(mca_dev, 3);
  174. pos[2] = mca_device_read_stored_pos(mca_dev, 4);
  175. /*
  176. * 01BB & 01BA port base by bits 7,6,5,4,3,2 in pos[2]
  177. *
  178. * 000000 <disabled> 001010 0x2800
  179. * 000001 <invalid> 001011 0x2C00
  180. * 000010 0x0800 001100 0x3000
  181. * 000011 0x0C00 001101 0x3400
  182. * 000100 0x1000 001110 0x3800
  183. * 000101 0x1400 001111 0x3C00
  184. * 000110 0x1800 010000 0x4000
  185. * 000111 0x1C00 010001 0x4400
  186. * 001000 0x2000 010010 0x4800
  187. * 001001 0x2400 010011 0x4C00
  188. * 010100 0x5000
  189. *
  190. * 00F4 port base by bits 3,2,1 in pos[0]
  191. *
  192. * 000 <disabled> 001 0x200
  193. * 010 0x300 011 0x400
  194. * 100 0x500 101 0x600
  195. *
  196. * 01BB & 01BA IRQ is specified in pos[0] bits 7 and 6:
  197. *
  198. * 00 3 10 11
  199. * 01 5 11 14
  200. *
  201. * 00F4 IRQ specified by bits 6,5,4 in pos[0]
  202. *
  203. * 100 5 101 9
  204. * 110 14
  205. */
  206. if (id == 0x01bb || id == 0x01ba) {
  207. base = io_01bb_by_pos[(pos[2] & 0xFC) >> 2];
  208. irq_vector =
  209. irq_01bb_by_pos[((pos[0] & 0xC0) >> 6)];
  210. clock = 50;
  211. if (id == 0x01bb)
  212. name = "NCR 3360/3430 SCSI SubSystem";
  213. else
  214. name = "NCR Dual SIOP SCSI Host Adapter Board";
  215. } else if ( id == 0x004f ) {
  216. base = io_004f_by_pos[((pos[0] & 0x0E) >> 1)];
  217. irq_vector =
  218. irq_004f_by_pos[((pos[0] & 0x70) >> 4) - 4];
  219. clock = 50;
  220. name = "NCR 53c710 SCSI Host Adapter Board";
  221. } else {
  222. return -ENODEV;
  223. }
  224. mca_device_set_name(mca_dev, name);
  225. mca_device_set_claim(mca_dev, 1);
  226. base = mca_device_transform_ioport(mca_dev, base);
  227. irq_vector = mca_device_transform_irq(mca_dev, irq_vector);
  228. return sim710_probe_common(dev, base, irq_vector, clock,
  229. 0, id_array[slot]);
  230. }
  231. static struct mca_driver sim710_mca_driver = {
  232. .id_table = sim710_mca_id_table,
  233. .driver = {
  234. .name = "sim710",
  235. .bus = &mca_bus_type,
  236. .probe = sim710_mca_probe,
  237. .remove = __devexit_p(sim710_device_remove),
  238. },
  239. };
  240. #endif /* CONFIG_MCA */
  241. #ifdef CONFIG_EISA
  242. static struct eisa_device_id sim710_eisa_ids[] = {
  243. { "CPQ4410" },
  244. { "CPQ4411" },
  245. { "HWP0C80" },
  246. { "" }
  247. };
  248. MODULE_DEVICE_TABLE(eisa, sim710_eisa_ids);
  249. static __init int
  250. sim710_eisa_probe(struct device *dev)
  251. {
  252. struct eisa_device *edev = to_eisa_device(dev);
  253. unsigned long io_addr = edev->base_addr;
  254. char eisa_cpq_irqs[] = { 11, 14, 15, 10, 9, 0 };
  255. char eisa_hwp_irqs[] = { 3, 4, 5, 7, 12, 10, 11, 0};
  256. char *eisa_irqs;
  257. unsigned char irq_index;
  258. unsigned char irq, differential = 0, scsi_id = 7;
  259. if(strcmp(edev->id.sig, "HWP0C80") == 0) {
  260. __u8 val;
  261. eisa_irqs = eisa_hwp_irqs;
  262. irq_index = (inb(io_addr + 0xc85) & 0x7) - 1;
  263. val = inb(io_addr + 0x4);
  264. scsi_id = ffs(val) - 1;
  265. if(scsi_id > 7 || (val & ~(1<<scsi_id)) != 0) {
  266. printk(KERN_ERR "sim710.c, EISA card %s has incorrect scsi_id, setting to 7\n", dev->bus_id);
  267. scsi_id = 7;
  268. }
  269. } else {
  270. eisa_irqs = eisa_cpq_irqs;
  271. irq_index = inb(io_addr + 0xc88) & 0x07;
  272. }
  273. if(irq_index >= strlen(eisa_irqs)) {
  274. printk("sim710.c: irq nasty\n");
  275. return -ENODEV;
  276. }
  277. irq = eisa_irqs[irq_index];
  278. return sim710_probe_common(dev, io_addr, irq, 50,
  279. differential, scsi_id);
  280. }
  281. static struct eisa_driver sim710_eisa_driver = {
  282. .id_table = sim710_eisa_ids,
  283. .driver = {
  284. .name = "sim710",
  285. .probe = sim710_eisa_probe,
  286. .remove = __devexit_p(sim710_device_remove),
  287. },
  288. };
  289. #endif /* CONFIG_EISA */
  290. static int __init sim710_init(void)
  291. {
  292. int err = -ENODEV;
  293. #ifdef MODULE
  294. if (sim710)
  295. param_setup(sim710);
  296. #endif
  297. #ifdef CONFIG_MCA
  298. err = mca_register_driver(&sim710_mca_driver);
  299. #endif
  300. #ifdef CONFIG_EISA
  301. err = eisa_driver_register(&sim710_eisa_driver);
  302. #endif
  303. /* FIXME: what we'd really like to return here is -ENODEV if
  304. * no devices have actually been found. Instead, the err
  305. * above actually only reports problems with kobject_register,
  306. * so for the moment return success */
  307. return 0;
  308. }
  309. static void __exit sim710_exit(void)
  310. {
  311. #ifdef CONFIG_MCA
  312. if (MCA_bus)
  313. mca_unregister_driver(&sim710_mca_driver);
  314. #endif
  315. #ifdef CONFIG_EISA
  316. eisa_driver_unregister(&sim710_eisa_driver);
  317. #endif
  318. }
  319. module_init(sim710_init);
  320. module_exit(sim710_exit);