proteon.c 9.1 KB

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