proteon.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. /*
  2. * proteon.c: A network driver for Proteon ISA token ring cards.
  3. *
  4. * Based on tmspci written 1999 by Adam Fritzler
  5. *
  6. * Written 2003 by Jochen Friedrich
  7. *
  8. * This software may be used and distributed according to the terms
  9. * of the GNU General Public License, incorporated herein by reference.
  10. *
  11. * This driver module supports the following cards:
  12. * - Proteon 1392, 1392+
  13. *
  14. * Maintainer(s):
  15. * AF Adam Fritzler
  16. * JF Jochen Friedrich jochen@scram.de
  17. *
  18. * Modification History:
  19. * 02-Jan-03 JF Created
  20. *
  21. */
  22. static const char version[] = "proteon.c: v1.00 02/01/2003 by Jochen Friedrich\n";
  23. #include <linux/module.h>
  24. #include <linux/kernel.h>
  25. #include <linux/delay.h>
  26. #include <linux/errno.h>
  27. #include <linux/pci.h>
  28. #include <linux/init.h>
  29. #include <linux/netdevice.h>
  30. #include <linux/trdevice.h>
  31. #include <linux/platform_device.h>
  32. #include <asm/system.h>
  33. #include <asm/io.h>
  34. #include <asm/irq.h>
  35. #include <asm/pci.h>
  36. #include <asm/dma.h>
  37. #include "tms380tr.h"
  38. #define PROTEON_IO_EXTENT 32
  39. /* A zero-terminated list of I/O addresses to be probed. */
  40. static unsigned int portlist[] __initdata = {
  41. 0x0A20, 0x0E20, 0x1A20, 0x1E20, 0x2A20, 0x2E20, 0x3A20, 0x3E20,// Prot.
  42. 0x4A20, 0x4E20, 0x5A20, 0x5E20, 0x6A20, 0x6E20, 0x7A20, 0x7E20,// Prot.
  43. 0x8A20, 0x8E20, 0x9A20, 0x9E20, 0xAA20, 0xAE20, 0xBA20, 0xBE20,// Prot.
  44. 0xCA20, 0xCE20, 0xDA20, 0xDE20, 0xEA20, 0xEE20, 0xFA20, 0xFE20,// Prot.
  45. 0
  46. };
  47. /* A zero-terminated list of IRQs to be probed. */
  48. static unsigned short irqlist[] = {
  49. 7, 6, 5, 4, 3, 12, 11, 10, 9,
  50. 0
  51. };
  52. /* A zero-terminated list of DMAs to be probed. */
  53. static int dmalist[] __initdata = {
  54. 5, 6, 7,
  55. 0
  56. };
  57. static char cardname[] = "Proteon 1392\0";
  58. static u64 dma_mask = ISA_MAX_ADDRESS;
  59. static int proteon_open(struct net_device *dev);
  60. static void proteon_read_eeprom(struct net_device *dev);
  61. static unsigned short proteon_setnselout_pins(struct net_device *dev);
  62. static unsigned short proteon_sifreadb(struct net_device *dev, unsigned short reg)
  63. {
  64. return inb(dev->base_addr + reg);
  65. }
  66. static unsigned short proteon_sifreadw(struct net_device *dev, unsigned short reg)
  67. {
  68. return inw(dev->base_addr + reg);
  69. }
  70. static void proteon_sifwriteb(struct net_device *dev, unsigned short val, unsigned short reg)
  71. {
  72. outb(val, dev->base_addr + reg);
  73. }
  74. static void proteon_sifwritew(struct net_device *dev, unsigned short val, unsigned short reg)
  75. {
  76. outw(val, dev->base_addr + reg);
  77. }
  78. static int __init proteon_probe1(struct net_device *dev, int ioaddr)
  79. {
  80. unsigned char chk1, chk2;
  81. int i;
  82. if (!request_region(ioaddr, PROTEON_IO_EXTENT, cardname))
  83. return -ENODEV;
  84. chk1 = inb(ioaddr + 0x1f); /* Get Proteon ID reg 1 */
  85. if (chk1 != 0x1f)
  86. goto nodev;
  87. chk1 = inb(ioaddr + 0x1e) & 0x07; /* Get Proteon ID reg 0 */
  88. for (i=0; i<16; i++) {
  89. chk2 = inb(ioaddr + 0x1e) & 0x07;
  90. if (((chk1 + 1) & 0x07) != chk2)
  91. goto nodev;
  92. chk1 = chk2;
  93. }
  94. dev->base_addr = ioaddr;
  95. return (0);
  96. nodev:
  97. release_region(ioaddr, PROTEON_IO_EXTENT);
  98. return -ENODEV;
  99. }
  100. static int __init setup_card(struct net_device *dev, struct device *pdev)
  101. {
  102. struct net_local *tp;
  103. static int versionprinted;
  104. const unsigned *port;
  105. int j,err = 0;
  106. if (!dev)
  107. return -ENOMEM;
  108. if (dev->base_addr) /* probe specific location */
  109. err = proteon_probe1(dev, dev->base_addr);
  110. else {
  111. for (port = portlist; *port; port++) {
  112. err = proteon_probe1(dev, *port);
  113. if (!err)
  114. break;
  115. }
  116. }
  117. if (err)
  118. goto out5;
  119. /* At this point we have found a valid card. */
  120. if (versionprinted++ == 0)
  121. printk(KERN_DEBUG "%s", version);
  122. err = -EIO;
  123. pdev->dma_mask = &dma_mask;
  124. if (tmsdev_init(dev, pdev))
  125. goto out4;
  126. dev->base_addr &= ~3;
  127. proteon_read_eeprom(dev);
  128. printk(KERN_DEBUG "proteon.c: Ring Station Address: %pM\n",
  129. dev->dev_addr);
  130. tp = netdev_priv(dev);
  131. tp->setnselout = proteon_setnselout_pins;
  132. tp->sifreadb = proteon_sifreadb;
  133. tp->sifreadw = proteon_sifreadw;
  134. tp->sifwriteb = proteon_sifwriteb;
  135. tp->sifwritew = proteon_sifwritew;
  136. memcpy(tp->ProductID, cardname, PROD_ID_SIZE + 1);
  137. tp->tmspriv = NULL;
  138. dev->open = proteon_open;
  139. dev->stop = tms380tr_close;
  140. if (dev->irq == 0)
  141. {
  142. for(j = 0; irqlist[j] != 0; j++)
  143. {
  144. dev->irq = irqlist[j];
  145. if (!request_irq(dev->irq, tms380tr_interrupt, 0,
  146. cardname, dev))
  147. break;
  148. }
  149. if(irqlist[j] == 0)
  150. {
  151. printk(KERN_INFO "proteon.c: AutoSelect no IRQ available\n");
  152. goto out3;
  153. }
  154. }
  155. else
  156. {
  157. for(j = 0; irqlist[j] != 0; j++)
  158. if (irqlist[j] == dev->irq)
  159. break;
  160. if (irqlist[j] == 0)
  161. {
  162. printk(KERN_INFO "proteon.c: Illegal IRQ %d specified\n",
  163. dev->irq);
  164. goto out3;
  165. }
  166. if (request_irq(dev->irq, tms380tr_interrupt, 0,
  167. cardname, dev))
  168. {
  169. printk(KERN_INFO "proteon.c: Selected IRQ %d not available\n",
  170. dev->irq);
  171. goto out3;
  172. }
  173. }
  174. if (dev->dma == 0)
  175. {
  176. for(j = 0; dmalist[j] != 0; j++)
  177. {
  178. dev->dma = dmalist[j];
  179. if (!request_dma(dev->dma, cardname))
  180. break;
  181. }
  182. if(dmalist[j] == 0)
  183. {
  184. printk(KERN_INFO "proteon.c: AutoSelect no DMA available\n");
  185. goto out2;
  186. }
  187. }
  188. else
  189. {
  190. for(j = 0; dmalist[j] != 0; j++)
  191. if (dmalist[j] == dev->dma)
  192. break;
  193. if (dmalist[j] == 0)
  194. {
  195. printk(KERN_INFO "proteon.c: Illegal DMA %d specified\n",
  196. dev->dma);
  197. goto out2;
  198. }
  199. if (request_dma(dev->dma, cardname))
  200. {
  201. printk(KERN_INFO "proteon.c: Selected DMA %d not available\n",
  202. dev->dma);
  203. goto out2;
  204. }
  205. }
  206. err = register_netdev(dev);
  207. if (err)
  208. goto out;
  209. printk(KERN_DEBUG "%s: IO: %#4lx IRQ: %d DMA: %d\n",
  210. dev->name, dev->base_addr, dev->irq, dev->dma);
  211. return 0;
  212. out:
  213. free_dma(dev->dma);
  214. out2:
  215. free_irq(dev->irq, dev);
  216. out3:
  217. tmsdev_term(dev);
  218. out4:
  219. release_region(dev->base_addr, PROTEON_IO_EXTENT);
  220. out5:
  221. return err;
  222. }
  223. /*
  224. * Reads MAC address from adapter RAM, which should've read it from
  225. * the onboard ROM.
  226. *
  227. * Calling this on a board that does not support it can be a very
  228. * dangerous thing. The Madge board, for instance, will lock your
  229. * machine hard when this is called. Luckily, its supported in a
  230. * separate driver. --ASF
  231. */
  232. static void proteon_read_eeprom(struct net_device *dev)
  233. {
  234. int i;
  235. /* Address: 0000:0000 */
  236. proteon_sifwritew(dev, 0, SIFADX);
  237. proteon_sifwritew(dev, 0, SIFADR);
  238. /* Read six byte MAC address data */
  239. dev->addr_len = 6;
  240. for(i = 0; i < 6; i++)
  241. dev->dev_addr[i] = proteon_sifreadw(dev, SIFINC) >> 8;
  242. }
  243. static unsigned short proteon_setnselout_pins(struct net_device *dev)
  244. {
  245. return 0;
  246. }
  247. static int proteon_open(struct net_device *dev)
  248. {
  249. struct net_local *tp = netdev_priv(dev);
  250. unsigned short val = 0;
  251. int i;
  252. /* Proteon reset sequence */
  253. outb(0, dev->base_addr + 0x11);
  254. mdelay(20);
  255. outb(0x04, dev->base_addr + 0x11);
  256. mdelay(20);
  257. outb(0, dev->base_addr + 0x11);
  258. mdelay(100);
  259. /* set control/status reg */
  260. val = inb(dev->base_addr + 0x11);
  261. val |= 0x78;
  262. val &= 0xf9;
  263. if(tp->DataRate == SPEED_4)
  264. val |= 0x20;
  265. else
  266. val &= ~0x20;
  267. outb(val, dev->base_addr + 0x11);
  268. outb(0xff, dev->base_addr + 0x12);
  269. for(i = 0; irqlist[i] != 0; i++)
  270. {
  271. if(irqlist[i] == dev->irq)
  272. break;
  273. }
  274. val = i;
  275. i = (7 - dev->dma) << 4;
  276. val |= i;
  277. outb(val, dev->base_addr + 0x13);
  278. return tms380tr_open(dev);
  279. }
  280. #define ISATR_MAX_ADAPTERS 3
  281. static int io[ISATR_MAX_ADAPTERS];
  282. static int irq[ISATR_MAX_ADAPTERS];
  283. static int dma[ISATR_MAX_ADAPTERS];
  284. MODULE_LICENSE("GPL");
  285. module_param_array(io, int, NULL, 0);
  286. module_param_array(irq, int, NULL, 0);
  287. module_param_array(dma, int, NULL, 0);
  288. static struct platform_device *proteon_dev[ISATR_MAX_ADAPTERS];
  289. static struct platform_driver proteon_driver = {
  290. .driver = {
  291. .name = "proteon",
  292. },
  293. };
  294. static int __init proteon_init(void)
  295. {
  296. struct net_device *dev;
  297. struct platform_device *pdev;
  298. int i, num = 0, err = 0;
  299. err = platform_driver_register(&proteon_driver);
  300. if (err)
  301. return err;
  302. for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) {
  303. dev = alloc_trdev(sizeof(struct net_local));
  304. if (!dev)
  305. continue;
  306. dev->base_addr = io[i];
  307. dev->irq = irq[i];
  308. dev->dma = dma[i];
  309. pdev = platform_device_register_simple("proteon",
  310. i, NULL, 0);
  311. if (IS_ERR(pdev)) {
  312. free_netdev(dev);
  313. continue;
  314. }
  315. err = setup_card(dev, &pdev->dev);
  316. if (!err) {
  317. proteon_dev[i] = pdev;
  318. platform_set_drvdata(pdev, dev);
  319. ++num;
  320. } else {
  321. platform_device_unregister(pdev);
  322. free_netdev(dev);
  323. }
  324. }
  325. printk(KERN_NOTICE "proteon.c: %d cards found.\n", num);
  326. /* Probe for cards. */
  327. if (num == 0) {
  328. printk(KERN_NOTICE "proteon.c: No cards found.\n");
  329. platform_driver_unregister(&proteon_driver);
  330. return -ENODEV;
  331. }
  332. return 0;
  333. }
  334. static void __exit proteon_cleanup(void)
  335. {
  336. struct net_device *dev;
  337. int i;
  338. for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) {
  339. struct platform_device *pdev = proteon_dev[i];
  340. if (!pdev)
  341. continue;
  342. dev = platform_get_drvdata(pdev);
  343. unregister_netdev(dev);
  344. release_region(dev->base_addr, PROTEON_IO_EXTENT);
  345. free_irq(dev->irq, dev);
  346. free_dma(dev->dma);
  347. tmsdev_term(dev);
  348. free_netdev(dev);
  349. platform_set_drvdata(pdev, NULL);
  350. platform_device_unregister(pdev);
  351. }
  352. platform_driver_unregister(&proteon_driver);
  353. }
  354. module_init(proteon_init);
  355. module_exit(proteon_cleanup);