es3210.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. /*
  2. es3210.c
  3. Linux driver for Racal-Interlan ES3210 EISA Network Adapter
  4. Copyright (C) 1996, Paul Gortmaker.
  5. This software may be used and distributed according to the terms
  6. of the GNU General Public License, incorporated herein by reference.
  7. Information and Code Sources:
  8. 1) The existing myriad of Linux 8390 drivers written by Donald Becker.
  9. 2) Once again Russ Nelson's asm packet driver provided additional info.
  10. 3) Info for getting IRQ and sh-mem gleaned from the EISA cfg files.
  11. Too bad it doesn't work -- see below.
  12. The ES3210 is an EISA shared memory NS8390 implementation. Note
  13. that all memory copies to/from the board must be 32bit transfers.
  14. Which rules out using eth_io_copy_and_sum() in this driver.
  15. Apparently there are two slightly different revisions of the
  16. card, since there are two distinct EISA cfg files (!rii0101.cfg
  17. and !rii0102.cfg) One has media select in the cfg file and the
  18. other doesn't. Hopefully this will work with either.
  19. That is about all I can tell you about it, having never actually
  20. even seen one of these cards. :) Try http://www.interlan.com
  21. if you want more info.
  22. Thanks go to Mark Salazar for testing v0.02 of this driver.
  23. Bugs, to-fix, etc:
  24. 1) The EISA cfg ports that are *supposed* to have the IRQ and shared
  25. mem values just read 0xff all the time. Hrrmpf. Apparently the
  26. same happens with the packet driver as the code for reading
  27. these registers is disabled there. In the meantime, boot with:
  28. ether=<IRQ>,0,0x<shared_mem_addr>,eth0 to override the IRQ and
  29. shared memory detection. (The i/o port detection is okay.)
  30. 2) Module support currently untested. Probably works though.
  31. */
  32. static const char version[] =
  33. "es3210.c: Driver revision v0.03, 14/09/96\n";
  34. #include <linux/module.h>
  35. #include <linux/eisa.h>
  36. #include <linux/kernel.h>
  37. #include <linux/errno.h>
  38. #include <linux/string.h>
  39. #include <linux/init.h>
  40. #include <linux/netdevice.h>
  41. #include <linux/etherdevice.h>
  42. #include <asm/io.h>
  43. #include <asm/system.h>
  44. #include "8390.h"
  45. static int es_probe1(struct net_device *dev, int ioaddr);
  46. static int es_open(struct net_device *dev);
  47. static int es_close(struct net_device *dev);
  48. static void es_reset_8390(struct net_device *dev);
  49. static void es_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page);
  50. static void es_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset);
  51. static void es_block_output(struct net_device *dev, int count, const unsigned char *buf, int start_page);
  52. #define ES_START_PG 0x00 /* First page of TX buffer */
  53. #define ES_STOP_PG 0x40 /* Last page +1 of RX ring */
  54. #define ES_IO_EXTENT 0x37 /* The cfg file says 0xc90 -> 0xcc7 */
  55. #define ES_ID_PORT 0xc80 /* Same for all EISA cards */
  56. #define ES_SA_PROM 0xc90 /* Start of e'net addr. */
  57. #define ES_RESET_PORT 0xc84 /* From the packet driver source */
  58. #define ES_NIC_OFFSET 0xca0 /* Hello, the 8390 is *here* */
  59. #define ES_ADDR0 0x02 /* 3 byte vendor prefix */
  60. #define ES_ADDR1 0x07
  61. #define ES_ADDR2 0x01
  62. /*
  63. * Two card revisions. EISA ID's are always rev. minor, rev. major,, and
  64. * then the three vendor letters stored in 5 bits each, with an "a" = 1.
  65. * For eg: "rii" = 10010 01001 01001 = 0x4929, which is how the EISA
  66. * config utility determines automagically what config file(s) to use.
  67. */
  68. #define ES_EISA_ID1 0x01012949 /* !rii0101.cfg */
  69. #define ES_EISA_ID2 0x02012949 /* !rii0102.cfg */
  70. #define ES_CFG1 0xcc0 /* IOPORT(1) --> IOPORT(6) in cfg file */
  71. #define ES_CFG2 0xcc1
  72. #define ES_CFG3 0xcc2
  73. #define ES_CFG4 0xcc3
  74. #define ES_CFG5 0xcc4
  75. #define ES_CFG6 0xc84 /* NB: 0xc84 is also "reset" port. */
  76. /*
  77. * You can OR any of the following bits together and assign it
  78. * to ES_DEBUG to get verbose driver info during operation.
  79. * Some of these don't do anything yet.
  80. */
  81. #define ES_D_PROBE 0x01
  82. #define ES_D_RX_PKT 0x02
  83. #define ES_D_TX_PKT 0x04
  84. #define ED_D_IRQ 0x08
  85. #define ES_DEBUG 0
  86. static unsigned char lo_irq_map[] __initdata = {3, 4, 5, 6, 7, 9, 10};
  87. static unsigned char hi_irq_map[] __initdata = {11, 12, 0, 14, 0, 0, 0, 15};
  88. /*
  89. * Probe for the card. The best way is to read the EISA ID if it
  90. * is known. Then we check the prefix of the station address
  91. * PROM for a match against the Racal-Interlan assigned value.
  92. */
  93. static int __init do_es_probe(struct net_device *dev)
  94. {
  95. unsigned short ioaddr = dev->base_addr;
  96. int irq = dev->irq;
  97. int mem_start = dev->mem_start;
  98. SET_MODULE_OWNER(dev);
  99. if (ioaddr > 0x1ff) /* Check a single specified location. */
  100. return es_probe1(dev, ioaddr);
  101. else if (ioaddr > 0) /* Don't probe at all. */
  102. return -ENXIO;
  103. if (!EISA_bus) {
  104. #if ES_DEBUG & ES_D_PROBE
  105. printk("es3210.c: Not EISA bus. Not probing high ports.\n");
  106. #endif
  107. return -ENXIO;
  108. }
  109. /* EISA spec allows for up to 16 slots, but 8 is typical. */
  110. for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
  111. if (es_probe1(dev, ioaddr) == 0)
  112. return 0;
  113. dev->irq = irq;
  114. dev->mem_start = mem_start;
  115. }
  116. return -ENODEV;
  117. }
  118. #ifndef MODULE
  119. struct net_device * __init es_probe(int unit)
  120. {
  121. struct net_device *dev = alloc_ei_netdev();
  122. int err;
  123. if (!dev)
  124. return ERR_PTR(-ENOMEM);
  125. sprintf(dev->name, "eth%d", unit);
  126. netdev_boot_setup_check(dev);
  127. err = do_es_probe(dev);
  128. if (err)
  129. goto out;
  130. return dev;
  131. out:
  132. free_netdev(dev);
  133. return ERR_PTR(err);
  134. }
  135. #endif
  136. static int __init es_probe1(struct net_device *dev, int ioaddr)
  137. {
  138. int i, retval;
  139. unsigned long eisa_id;
  140. if (!request_region(ioaddr + ES_SA_PROM, ES_IO_EXTENT, "es3210"))
  141. return -ENODEV;
  142. #if ES_DEBUG & ES_D_PROBE
  143. printk("es3210.c: probe at %#x, ID %#8x\n", ioaddr, inl(ioaddr + ES_ID_PORT));
  144. printk("es3210.c: config regs: %#x %#x %#x %#x %#x %#x\n",
  145. inb(ioaddr + ES_CFG1), inb(ioaddr + ES_CFG2), inb(ioaddr + ES_CFG3),
  146. inb(ioaddr + ES_CFG4), inb(ioaddr + ES_CFG5), inb(ioaddr + ES_CFG6));
  147. #endif
  148. /* Check the EISA ID of the card. */
  149. eisa_id = inl(ioaddr + ES_ID_PORT);
  150. if ((eisa_id != ES_EISA_ID1) && (eisa_id != ES_EISA_ID2)) {
  151. retval = -ENODEV;
  152. goto out;
  153. }
  154. /* Check the Racal vendor ID as well. */
  155. if (inb(ioaddr + ES_SA_PROM + 0) != ES_ADDR0
  156. || inb(ioaddr + ES_SA_PROM + 1) != ES_ADDR1
  157. || inb(ioaddr + ES_SA_PROM + 2) != ES_ADDR2 ) {
  158. printk("es3210.c: card not found");
  159. for(i = 0; i < ETHER_ADDR_LEN; i++)
  160. printk(" %02x", inb(ioaddr + ES_SA_PROM + i));
  161. printk(" (invalid prefix).\n");
  162. retval = -ENODEV;
  163. goto out;
  164. }
  165. printk("es3210.c: ES3210 rev. %ld at %#x, node", eisa_id>>24, ioaddr);
  166. for(i = 0; i < ETHER_ADDR_LEN; i++)
  167. printk(" %02x", (dev->dev_addr[i] = inb(ioaddr + ES_SA_PROM + i)));
  168. /* Snarf the interrupt now. */
  169. if (dev->irq == 0) {
  170. unsigned char hi_irq = inb(ioaddr + ES_CFG2) & 0x07;
  171. unsigned char lo_irq = inb(ioaddr + ES_CFG1) & 0xfe;
  172. if (hi_irq != 0) {
  173. dev->irq = hi_irq_map[hi_irq - 1];
  174. } else {
  175. int i = 0;
  176. while (lo_irq > (1<<i)) i++;
  177. dev->irq = lo_irq_map[i];
  178. }
  179. printk(" using IRQ %d", dev->irq);
  180. #if ES_DEBUG & ES_D_PROBE
  181. printk("es3210.c: hi_irq %#x, lo_irq %#x, dev->irq = %d\n",
  182. hi_irq, lo_irq, dev->irq);
  183. #endif
  184. } else {
  185. if (dev->irq == 2)
  186. dev->irq = 9; /* Doh! */
  187. printk(" assigning IRQ %d", dev->irq);
  188. }
  189. if (request_irq(dev->irq, ei_interrupt, 0, "es3210", dev)) {
  190. printk (" unable to get IRQ %d.\n", dev->irq);
  191. retval = -EAGAIN;
  192. goto out;
  193. }
  194. if (dev->mem_start == 0) {
  195. unsigned char mem_enabled = inb(ioaddr + ES_CFG2) & 0xc0;
  196. unsigned char mem_bits = inb(ioaddr + ES_CFG3) & 0x07;
  197. if (mem_enabled != 0x80) {
  198. printk(" shared mem disabled - giving up\n");
  199. retval = -ENXIO;
  200. goto out1;
  201. }
  202. dev->mem_start = 0xC0000 + mem_bits*0x4000;
  203. printk(" using ");
  204. } else {
  205. printk(" assigning ");
  206. }
  207. ei_status.mem = ioremap(dev->mem_start, (ES_STOP_PG - ES_START_PG)*256);
  208. if (!ei_status.mem) {
  209. printk("ioremap failed - giving up\n");
  210. retval = -ENXIO;
  211. goto out1;
  212. }
  213. dev->mem_end = dev->mem_start + (ES_STOP_PG - ES_START_PG)*256;
  214. printk("mem %#lx-%#lx\n", dev->mem_start, dev->mem_end-1);
  215. #if ES_DEBUG & ES_D_PROBE
  216. if (inb(ioaddr + ES_CFG5))
  217. printk("es3210: Warning - DMA channel enabled, but not used here.\n");
  218. #endif
  219. /* Note, point at the 8390, and not the card... */
  220. dev->base_addr = ioaddr + ES_NIC_OFFSET;
  221. ei_status.name = "ES3210";
  222. ei_status.tx_start_page = ES_START_PG;
  223. ei_status.rx_start_page = ES_START_PG + TX_PAGES;
  224. ei_status.stop_page = ES_STOP_PG;
  225. ei_status.word16 = 1;
  226. if (ei_debug > 0)
  227. printk(version);
  228. ei_status.reset_8390 = &es_reset_8390;
  229. ei_status.block_input = &es_block_input;
  230. ei_status.block_output = &es_block_output;
  231. ei_status.get_8390_hdr = &es_get_8390_hdr;
  232. dev->open = &es_open;
  233. dev->stop = &es_close;
  234. #ifdef CONFIG_NET_POLL_CONTROLLER
  235. dev->poll_controller = ei_poll;
  236. #endif
  237. NS8390_init(dev, 0);
  238. retval = register_netdev(dev);
  239. if (retval)
  240. goto out1;
  241. return 0;
  242. out1:
  243. free_irq(dev->irq, dev);
  244. out:
  245. release_region(ioaddr + ES_SA_PROM, ES_IO_EXTENT);
  246. return retval;
  247. }
  248. /*
  249. * Reset as per the packet driver method. Judging by the EISA cfg
  250. * file, this just toggles the "Board Enable" bits (bit 2 and 0).
  251. */
  252. static void es_reset_8390(struct net_device *dev)
  253. {
  254. unsigned short ioaddr = dev->base_addr;
  255. unsigned long end;
  256. outb(0x04, ioaddr + ES_RESET_PORT);
  257. if (ei_debug > 1) printk("%s: resetting the ES3210...", dev->name);
  258. end = jiffies + 2*HZ/100;
  259. while ((signed)(end - jiffies) > 0) continue;
  260. ei_status.txing = 0;
  261. outb(0x01, ioaddr + ES_RESET_PORT);
  262. if (ei_debug > 1) printk("reset done\n");
  263. return;
  264. }
  265. /*
  266. * Note: In the following three functions is the implicit assumption
  267. * that the associated memcpy will only use "rep; movsl" as long as
  268. * we keep the counts as some multiple of doublewords. This is a
  269. * requirement of the hardware, and also prevents us from using
  270. * eth_io_copy_and_sum() since we can't guarantee it will limit
  271. * itself to doubleword access.
  272. */
  273. /*
  274. * Grab the 8390 specific header. Similar to the block_input routine, but
  275. * we don't need to be concerned with ring wrap as the header will be at
  276. * the start of a page, so we optimize accordingly. (A single doubleword.)
  277. */
  278. static void
  279. es_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
  280. {
  281. void __iomem *hdr_start = ei_status.mem + ((ring_page - ES_START_PG)<<8);
  282. memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
  283. hdr->count = (hdr->count + 3) & ~3; /* Round up allocation. */
  284. }
  285. /*
  286. * Block input and output are easy on shared memory ethercards, the only
  287. * complication is when the ring buffer wraps. The count will already
  288. * be rounded up to a doubleword value via es_get_8390_hdr() above.
  289. */
  290. static void es_block_input(struct net_device *dev, int count, struct sk_buff *skb,
  291. int ring_offset)
  292. {
  293. void __iomem *xfer_start = ei_status.mem + ring_offset - ES_START_PG*256;
  294. if (ring_offset + count > ES_STOP_PG*256) {
  295. /* Packet wraps over end of ring buffer. */
  296. int semi_count = ES_STOP_PG*256 - ring_offset;
  297. memcpy_fromio(skb->data, xfer_start, semi_count);
  298. count -= semi_count;
  299. memcpy_fromio(skb->data + semi_count, ei_status.mem, count);
  300. } else {
  301. /* Packet is in one chunk. */
  302. memcpy_fromio(skb->data, xfer_start, count);
  303. }
  304. }
  305. static void es_block_output(struct net_device *dev, int count,
  306. const unsigned char *buf, int start_page)
  307. {
  308. void __iomem *shmem = ei_status.mem + ((start_page - ES_START_PG)<<8);
  309. count = (count + 3) & ~3; /* Round up to doubleword */
  310. memcpy_toio(shmem, buf, count);
  311. }
  312. static int es_open(struct net_device *dev)
  313. {
  314. ei_open(dev);
  315. return 0;
  316. }
  317. static int es_close(struct net_device *dev)
  318. {
  319. if (ei_debug > 1)
  320. printk("%s: Shutting down ethercard.\n", dev->name);
  321. ei_close(dev);
  322. return 0;
  323. }
  324. #ifdef MODULE
  325. #define MAX_ES_CARDS 4 /* Max number of ES3210 cards per module */
  326. #define NAMELEN 8 /* # of chars for storing dev->name */
  327. static struct net_device *dev_es3210[MAX_ES_CARDS];
  328. static int io[MAX_ES_CARDS];
  329. static int irq[MAX_ES_CARDS];
  330. static int mem[MAX_ES_CARDS];
  331. module_param_array(io, int, NULL, 0);
  332. module_param_array(irq, int, NULL, 0);
  333. module_param_array(mem, int, NULL, 0);
  334. MODULE_PARM_DESC(io, "I/O base address(es)");
  335. MODULE_PARM_DESC(irq, "IRQ number(s)");
  336. MODULE_PARM_DESC(mem, "memory base address(es)");
  337. MODULE_DESCRIPTION("Racal-Interlan ES3210 EISA ethernet driver");
  338. MODULE_LICENSE("GPL");
  339. int __init init_module(void)
  340. {
  341. struct net_device *dev;
  342. int this_dev, found = 0;
  343. for (this_dev = 0; this_dev < MAX_ES_CARDS; this_dev++) {
  344. if (io[this_dev] == 0 && this_dev != 0)
  345. break;
  346. dev = alloc_ei_netdev();
  347. if (!dev)
  348. break;
  349. dev->irq = irq[this_dev];
  350. dev->base_addr = io[this_dev];
  351. dev->mem_start = mem[this_dev];
  352. if (do_es_probe(dev) == 0) {
  353. dev_es3210[found++] = dev;
  354. continue;
  355. }
  356. free_netdev(dev);
  357. printk(KERN_WARNING "es3210.c: No es3210 card found (i/o = 0x%x).\n", io[this_dev]);
  358. break;
  359. }
  360. if (found)
  361. return 0;
  362. return -ENXIO;
  363. }
  364. static void cleanup_card(struct net_device *dev)
  365. {
  366. free_irq(dev->irq, dev);
  367. release_region(dev->base_addr, ES_IO_EXTENT);
  368. iounmap(ei_status.mem);
  369. }
  370. void __exit
  371. cleanup_module(void)
  372. {
  373. int this_dev;
  374. for (this_dev = 0; this_dev < MAX_ES_CARDS; this_dev++) {
  375. struct net_device *dev = dev_es3210[this_dev];
  376. if (dev) {
  377. unregister_netdev(dev);
  378. cleanup_card(dev);
  379. free_netdev(dev);
  380. }
  381. }
  382. }
  383. #endif /* MODULE */