proteon.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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/io.h>
  33. #include <asm/irq.h>
  34. #include <asm/pci.h>
  35. #include <asm/dma.h>
  36. #include "tms380tr.h"
  37. #define PROTEON_IO_EXTENT 32
  38. /* A zero-terminated list of I/O addresses to be probed. */
  39. static unsigned int portlist[] __initdata = {
  40. 0x0A20, 0x0E20, 0x1A20, 0x1E20, 0x2A20, 0x2E20, 0x3A20, 0x3E20,// Prot.
  41. 0x4A20, 0x4E20, 0x5A20, 0x5E20, 0x6A20, 0x6E20, 0x7A20, 0x7E20,// Prot.
  42. 0x8A20, 0x8E20, 0x9A20, 0x9E20, 0xAA20, 0xAE20, 0xBA20, 0xBE20,// Prot.
  43. 0xCA20, 0xCE20, 0xDA20, 0xDE20, 0xEA20, 0xEE20, 0xFA20, 0xFE20,// Prot.
  44. 0
  45. };
  46. /* A zero-terminated list of IRQs to be probed. */
  47. static unsigned short irqlist[] = {
  48. 7, 6, 5, 4, 3, 12, 11, 10, 9,
  49. 0
  50. };
  51. /* A zero-terminated list of DMAs to be probed. */
  52. static int dmalist[] __initdata = {
  53. 5, 6, 7,
  54. 0
  55. };
  56. static char cardname[] = "Proteon 1392\0";
  57. static u64 dma_mask = ISA_MAX_ADDRESS;
  58. static int proteon_open(struct net_device *dev);
  59. static void proteon_read_eeprom(struct net_device *dev);
  60. static unsigned short proteon_setnselout_pins(struct net_device *dev);
  61. static unsigned short proteon_sifreadb(struct net_device *dev, unsigned short reg)
  62. {
  63. return inb(dev->base_addr + reg);
  64. }
  65. static unsigned short proteon_sifreadw(struct net_device *dev, unsigned short reg)
  66. {
  67. return inw(dev->base_addr + reg);
  68. }
  69. static void proteon_sifwriteb(struct net_device *dev, unsigned short val, unsigned short reg)
  70. {
  71. outb(val, dev->base_addr + reg);
  72. }
  73. static void proteon_sifwritew(struct net_device *dev, unsigned short val, unsigned short reg)
  74. {
  75. outw(val, dev->base_addr + reg);
  76. }
  77. static int __init proteon_probe1(struct net_device *dev, int ioaddr)
  78. {
  79. unsigned char chk1, chk2;
  80. int i;
  81. if (!request_region(ioaddr, PROTEON_IO_EXTENT, cardname))
  82. return -ENODEV;
  83. chk1 = inb(ioaddr + 0x1f); /* Get Proteon ID reg 1 */
  84. if (chk1 != 0x1f)
  85. goto nodev;
  86. chk1 = inb(ioaddr + 0x1e) & 0x07; /* Get Proteon ID reg 0 */
  87. for (i=0; i<16; i++) {
  88. chk2 = inb(ioaddr + 0x1e) & 0x07;
  89. if (((chk1 + 1) & 0x07) != chk2)
  90. goto nodev;
  91. chk1 = chk2;
  92. }
  93. dev->base_addr = ioaddr;
  94. return 0;
  95. nodev:
  96. release_region(ioaddr, PROTEON_IO_EXTENT);
  97. return -ENODEV;
  98. }
  99. static struct net_device_ops proteon_netdev_ops __read_mostly;
  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->netdev_ops = &proteon_netdev_ops;
  139. if (dev->irq == 0)
  140. {
  141. for(j = 0; irqlist[j] != 0; j++)
  142. {
  143. dev->irq = irqlist[j];
  144. if (!request_irq(dev->irq, tms380tr_interrupt, 0,
  145. cardname, dev))
  146. break;
  147. }
  148. if(irqlist[j] == 0)
  149. {
  150. printk(KERN_INFO "proteon.c: AutoSelect no IRQ available\n");
  151. goto out3;
  152. }
  153. }
  154. else
  155. {
  156. for(j = 0; irqlist[j] != 0; j++)
  157. if (irqlist[j] == dev->irq)
  158. break;
  159. if (irqlist[j] == 0)
  160. {
  161. printk(KERN_INFO "proteon.c: Illegal IRQ %d specified\n",
  162. dev->irq);
  163. goto out3;
  164. }
  165. if (request_irq(dev->irq, tms380tr_interrupt, 0,
  166. cardname, dev))
  167. {
  168. printk(KERN_INFO "proteon.c: Selected IRQ %d not available\n",
  169. dev->irq);
  170. goto out3;
  171. }
  172. }
  173. if (dev->dma == 0)
  174. {
  175. for(j = 0; dmalist[j] != 0; j++)
  176. {
  177. dev->dma = dmalist[j];
  178. if (!request_dma(dev->dma, cardname))
  179. break;
  180. }
  181. if(dmalist[j] == 0)
  182. {
  183. printk(KERN_INFO "proteon.c: AutoSelect no DMA available\n");
  184. goto out2;
  185. }
  186. }
  187. else
  188. {
  189. for(j = 0; dmalist[j] != 0; j++)
  190. if (dmalist[j] == dev->dma)
  191. break;
  192. if (dmalist[j] == 0)
  193. {
  194. printk(KERN_INFO "proteon.c: Illegal DMA %d specified\n",
  195. dev->dma);
  196. goto out2;
  197. }
  198. if (request_dma(dev->dma, cardname))
  199. {
  200. printk(KERN_INFO "proteon.c: Selected DMA %d not available\n",
  201. dev->dma);
  202. goto out2;
  203. }
  204. }
  205. err = register_netdev(dev);
  206. if (err)
  207. goto out;
  208. printk(KERN_DEBUG "%s: IO: %#4lx IRQ: %d DMA: %d\n",
  209. dev->name, dev->base_addr, dev->irq, dev->dma);
  210. return 0;
  211. out:
  212. free_dma(dev->dma);
  213. out2:
  214. free_irq(dev->irq, dev);
  215. out3:
  216. tmsdev_term(dev);
  217. out4:
  218. release_region(dev->base_addr, PROTEON_IO_EXTENT);
  219. out5:
  220. return err;
  221. }
  222. /*
  223. * Reads MAC address from adapter RAM, which should've read it from
  224. * the onboard ROM.
  225. *
  226. * Calling this on a board that does not support it can be a very
  227. * dangerous thing. The Madge board, for instance, will lock your
  228. * machine hard when this is called. Luckily, its supported in a
  229. * separate driver. --ASF
  230. */
  231. static void proteon_read_eeprom(struct net_device *dev)
  232. {
  233. int i;
  234. /* Address: 0000:0000 */
  235. proteon_sifwritew(dev, 0, SIFADX);
  236. proteon_sifwritew(dev, 0, SIFADR);
  237. /* Read six byte MAC address data */
  238. dev->addr_len = 6;
  239. for(i = 0; i < 6; i++)
  240. dev->dev_addr[i] = proteon_sifreadw(dev, SIFINC) >> 8;
  241. }
  242. static unsigned short proteon_setnselout_pins(struct net_device *dev)
  243. {
  244. return 0;
  245. }
  246. static int proteon_open(struct net_device *dev)
  247. {
  248. struct net_local *tp = netdev_priv(dev);
  249. unsigned short val = 0;
  250. int i;
  251. /* Proteon reset sequence */
  252. outb(0, dev->base_addr + 0x11);
  253. mdelay(20);
  254. outb(0x04, dev->base_addr + 0x11);
  255. mdelay(20);
  256. outb(0, dev->base_addr + 0x11);
  257. mdelay(100);
  258. /* set control/status reg */
  259. val = inb(dev->base_addr + 0x11);
  260. val |= 0x78;
  261. val &= 0xf9;
  262. if(tp->DataRate == SPEED_4)
  263. val |= 0x20;
  264. else
  265. val &= ~0x20;
  266. outb(val, dev->base_addr + 0x11);
  267. outb(0xff, dev->base_addr + 0x12);
  268. for(i = 0; irqlist[i] != 0; i++)
  269. {
  270. if(irqlist[i] == dev->irq)
  271. break;
  272. }
  273. val = i;
  274. i = (7 - dev->dma) << 4;
  275. val |= i;
  276. outb(val, dev->base_addr + 0x13);
  277. return tms380tr_open(dev);
  278. }
  279. #define ISATR_MAX_ADAPTERS 3
  280. static int io[ISATR_MAX_ADAPTERS];
  281. static int irq[ISATR_MAX_ADAPTERS];
  282. static int dma[ISATR_MAX_ADAPTERS];
  283. MODULE_LICENSE("GPL");
  284. module_param_array(io, int, NULL, 0);
  285. module_param_array(irq, int, NULL, 0);
  286. module_param_array(dma, int, NULL, 0);
  287. static struct platform_device *proteon_dev[ISATR_MAX_ADAPTERS];
  288. static struct platform_driver proteon_driver = {
  289. .driver = {
  290. .name = "proteon",
  291. },
  292. };
  293. static int __init proteon_init(void)
  294. {
  295. struct net_device *dev;
  296. struct platform_device *pdev;
  297. int i, num = 0, err = 0;
  298. proteon_netdev_ops = tms380tr_netdev_ops;
  299. proteon_netdev_ops.ndo_open = proteon_open;
  300. proteon_netdev_ops.ndo_stop = tms380tr_close;
  301. err = platform_driver_register(&proteon_driver);
  302. if (err)
  303. return err;
  304. for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) {
  305. dev = alloc_trdev(sizeof(struct net_local));
  306. if (!dev)
  307. continue;
  308. dev->base_addr = io[i];
  309. dev->irq = irq[i];
  310. dev->dma = dma[i];
  311. pdev = platform_device_register_simple("proteon",
  312. i, NULL, 0);
  313. if (IS_ERR(pdev)) {
  314. free_netdev(dev);
  315. continue;
  316. }
  317. err = setup_card(dev, &pdev->dev);
  318. if (!err) {
  319. proteon_dev[i] = pdev;
  320. platform_set_drvdata(pdev, dev);
  321. ++num;
  322. } else {
  323. platform_device_unregister(pdev);
  324. free_netdev(dev);
  325. }
  326. }
  327. printk(KERN_NOTICE "proteon.c: %d cards found.\n", num);
  328. /* Probe for cards. */
  329. if (num == 0) {
  330. printk(KERN_NOTICE "proteon.c: No cards found.\n");
  331. platform_driver_unregister(&proteon_driver);
  332. return -ENODEV;
  333. }
  334. return 0;
  335. }
  336. static void __exit proteon_cleanup(void)
  337. {
  338. struct net_device *dev;
  339. int i;
  340. for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) {
  341. struct platform_device *pdev = proteon_dev[i];
  342. if (!pdev)
  343. continue;
  344. dev = platform_get_drvdata(pdev);
  345. unregister_netdev(dev);
  346. release_region(dev->base_addr, PROTEON_IO_EXTENT);
  347. free_irq(dev->irq, dev);
  348. free_dma(dev->dma);
  349. tmsdev_term(dev);
  350. free_netdev(dev);
  351. platform_set_drvdata(pdev, NULL);
  352. platform_device_unregister(pdev);
  353. }
  354. platform_driver_unregister(&proteon_driver);
  355. }
  356. module_init(proteon_init);
  357. module_exit(proteon_cleanup);