proteon.c 8.9 KB

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