sim710.c 9.8 KB

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