proteon.c 9.2 KB

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