proteon.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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 mid@auk.cx
  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. DECLARE_MAC_BUF(mac);
  107. if (!dev)
  108. return -ENOMEM;
  109. if (dev->base_addr) /* probe specific location */
  110. err = proteon_probe1(dev, dev->base_addr);
  111. else {
  112. for (port = portlist; *port; port++) {
  113. err = proteon_probe1(dev, *port);
  114. if (!err)
  115. break;
  116. }
  117. }
  118. if (err)
  119. goto out5;
  120. /* At this point we have found a valid card. */
  121. if (versionprinted++ == 0)
  122. printk(KERN_DEBUG "%s", version);
  123. err = -EIO;
  124. pdev->dma_mask = &dma_mask;
  125. if (tmsdev_init(dev, pdev))
  126. goto out4;
  127. dev->base_addr &= ~3;
  128. proteon_read_eeprom(dev);
  129. printk(KERN_DEBUG "proteon.c: Ring Station Address: %s\n",
  130. print_mac(mac, dev->dev_addr));
  131. tp = netdev_priv(dev);
  132. tp->setnselout = proteon_setnselout_pins;
  133. tp->sifreadb = proteon_sifreadb;
  134. tp->sifreadw = proteon_sifreadw;
  135. tp->sifwriteb = proteon_sifwriteb;
  136. tp->sifwritew = proteon_sifwritew;
  137. memcpy(tp->ProductID, cardname, PROD_ID_SIZE + 1);
  138. tp->tmspriv = NULL;
  139. dev->open = proteon_open;
  140. dev->stop = tms380tr_close;
  141. if (dev->irq == 0)
  142. {
  143. for(j = 0; irqlist[j] != 0; j++)
  144. {
  145. dev->irq = irqlist[j];
  146. if (!request_irq(dev->irq, tms380tr_interrupt, 0,
  147. cardname, dev))
  148. break;
  149. }
  150. if(irqlist[j] == 0)
  151. {
  152. printk(KERN_INFO "proteon.c: AutoSelect no IRQ available\n");
  153. goto out3;
  154. }
  155. }
  156. else
  157. {
  158. for(j = 0; irqlist[j] != 0; j++)
  159. if (irqlist[j] == dev->irq)
  160. break;
  161. if (irqlist[j] == 0)
  162. {
  163. printk(KERN_INFO "proteon.c: Illegal IRQ %d specified\n",
  164. dev->irq);
  165. goto out3;
  166. }
  167. if (request_irq(dev->irq, tms380tr_interrupt, 0,
  168. cardname, dev))
  169. {
  170. printk(KERN_INFO "proteon.c: Selected IRQ %d not available\n",
  171. dev->irq);
  172. goto out3;
  173. }
  174. }
  175. if (dev->dma == 0)
  176. {
  177. for(j = 0; dmalist[j] != 0; j++)
  178. {
  179. dev->dma = dmalist[j];
  180. if (!request_dma(dev->dma, cardname))
  181. break;
  182. }
  183. if(dmalist[j] == 0)
  184. {
  185. printk(KERN_INFO "proteon.c: AutoSelect no DMA available\n");
  186. goto out2;
  187. }
  188. }
  189. else
  190. {
  191. for(j = 0; dmalist[j] != 0; j++)
  192. if (dmalist[j] == dev->dma)
  193. break;
  194. if (dmalist[j] == 0)
  195. {
  196. printk(KERN_INFO "proteon.c: Illegal DMA %d specified\n",
  197. dev->dma);
  198. goto out2;
  199. }
  200. if (request_dma(dev->dma, cardname))
  201. {
  202. printk(KERN_INFO "proteon.c: Selected DMA %d not available\n",
  203. dev->dma);
  204. goto out2;
  205. }
  206. }
  207. err = register_netdev(dev);
  208. if (err)
  209. goto out;
  210. printk(KERN_DEBUG "%s: IO: %#4lx IRQ: %d DMA: %d\n",
  211. dev->name, dev->base_addr, dev->irq, dev->dma);
  212. return 0;
  213. out:
  214. free_dma(dev->dma);
  215. out2:
  216. free_irq(dev->irq, dev);
  217. out3:
  218. tmsdev_term(dev);
  219. out4:
  220. release_region(dev->base_addr, PROTEON_IO_EXTENT);
  221. out5:
  222. return err;
  223. }
  224. /*
  225. * Reads MAC address from adapter RAM, which should've read it from
  226. * the onboard ROM.
  227. *
  228. * Calling this on a board that does not support it can be a very
  229. * dangerous thing. The Madge board, for instance, will lock your
  230. * machine hard when this is called. Luckily, its supported in a
  231. * separate driver. --ASF
  232. */
  233. static void proteon_read_eeprom(struct net_device *dev)
  234. {
  235. int i;
  236. /* Address: 0000:0000 */
  237. proteon_sifwritew(dev, 0, SIFADX);
  238. proteon_sifwritew(dev, 0, SIFADR);
  239. /* Read six byte MAC address data */
  240. dev->addr_len = 6;
  241. for(i = 0; i < 6; i++)
  242. dev->dev_addr[i] = proteon_sifreadw(dev, SIFINC) >> 8;
  243. }
  244. unsigned short proteon_setnselout_pins(struct net_device *dev)
  245. {
  246. return 0;
  247. }
  248. static int proteon_open(struct net_device *dev)
  249. {
  250. struct net_local *tp = netdev_priv(dev);
  251. unsigned short val = 0;
  252. int i;
  253. /* Proteon reset sequence */
  254. outb(0, dev->base_addr + 0x11);
  255. mdelay(20);
  256. outb(0x04, dev->base_addr + 0x11);
  257. mdelay(20);
  258. outb(0, dev->base_addr + 0x11);
  259. mdelay(100);
  260. /* set control/status reg */
  261. val = inb(dev->base_addr + 0x11);
  262. val |= 0x78;
  263. val &= 0xf9;
  264. if(tp->DataRate == SPEED_4)
  265. val |= 0x20;
  266. else
  267. val &= ~0x20;
  268. outb(val, dev->base_addr + 0x11);
  269. outb(0xff, dev->base_addr + 0x12);
  270. for(i = 0; irqlist[i] != 0; i++)
  271. {
  272. if(irqlist[i] == dev->irq)
  273. break;
  274. }
  275. val = i;
  276. i = (7 - dev->dma) << 4;
  277. val |= i;
  278. outb(val, dev->base_addr + 0x13);
  279. return tms380tr_open(dev);
  280. }
  281. #define ISATR_MAX_ADAPTERS 3
  282. static int io[ISATR_MAX_ADAPTERS];
  283. static int irq[ISATR_MAX_ADAPTERS];
  284. static int dma[ISATR_MAX_ADAPTERS];
  285. MODULE_LICENSE("GPL");
  286. module_param_array(io, int, NULL, 0);
  287. module_param_array(irq, int, NULL, 0);
  288. module_param_array(dma, int, NULL, 0);
  289. static struct platform_device *proteon_dev[ISATR_MAX_ADAPTERS];
  290. static struct platform_driver proteon_driver = {
  291. .driver = {
  292. .name = "proteon",
  293. },
  294. };
  295. static int __init proteon_init(void)
  296. {
  297. struct net_device *dev;
  298. struct platform_device *pdev;
  299. int i, num = 0, err = 0;
  300. err = platform_driver_register(&proteon_driver);
  301. if (err)
  302. return err;
  303. for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) {
  304. dev = alloc_trdev(sizeof(struct net_local));
  305. if (!dev)
  306. continue;
  307. dev->base_addr = io[i];
  308. dev->irq = irq[i];
  309. dev->dma = dma[i];
  310. pdev = platform_device_register_simple("proteon",
  311. i, NULL, 0);
  312. if (IS_ERR(pdev)) {
  313. free_netdev(dev);
  314. continue;
  315. }
  316. err = setup_card(dev, &pdev->dev);
  317. if (!err) {
  318. proteon_dev[i] = pdev;
  319. platform_set_drvdata(pdev, dev);
  320. ++num;
  321. } else {
  322. platform_device_unregister(pdev);
  323. free_netdev(dev);
  324. }
  325. }
  326. printk(KERN_NOTICE "proteon.c: %d cards found.\n", num);
  327. /* Probe for cards. */
  328. if (num == 0) {
  329. printk(KERN_NOTICE "proteon.c: No cards found.\n");
  330. platform_driver_unregister(&proteon_driver);
  331. return -ENODEV;
  332. }
  333. return 0;
  334. }
  335. static void __exit proteon_cleanup(void)
  336. {
  337. struct net_device *dev;
  338. int i;
  339. for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) {
  340. struct platform_device *pdev = proteon_dev[i];
  341. if (!pdev)
  342. continue;
  343. dev = platform_get_drvdata(pdev);
  344. unregister_netdev(dev);
  345. release_region(dev->base_addr, PROTEON_IO_EXTENT);
  346. free_irq(dev->irq, dev);
  347. free_dma(dev->dma);
  348. tmsdev_term(dev);
  349. free_netdev(dev);
  350. platform_set_drvdata(pdev, NULL);
  351. platform_device_unregister(pdev);
  352. }
  353. platform_driver_unregister(&proteon_driver);
  354. }
  355. module_init(proteon_init);
  356. module_exit(proteon_cleanup);