ne3210.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /*
  2. ne3210.c
  3. Linux driver for Novell NE3210 EISA Network Adapter
  4. Copyright (C) 1998, 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) Based upon my other EISA 8390 drivers (lne390, es3210, smc-ultra32)
  9. 2) The existing myriad of other Linux 8390 drivers by Donald Becker.
  10. 3) Info for getting IRQ and sh-mem gleaned from the EISA cfg file
  11. The NE3210 is an EISA shared memory NS8390 implementation. Shared
  12. memory address > 1MB should work with this driver.
  13. Note that the .cfg file (3/11/93, v1.0) has AUI and BNC switched
  14. around (or perhaps there are some defective/backwards cards ???)
  15. This driver WILL NOT WORK FOR THE NE3200 - it is completely different
  16. and does not use an 8390 at all.
  17. Updated to EISA probing API 5/2003 by Marc Zyngier.
  18. */
  19. #include <linux/module.h>
  20. #include <linux/eisa.h>
  21. #include <linux/kernel.h>
  22. #include <linux/errno.h>
  23. #include <linux/string.h>
  24. #include <linux/delay.h>
  25. #include <linux/init.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/netdevice.h>
  28. #include <linux/etherdevice.h>
  29. #include <linux/mm.h>
  30. #include <asm/io.h>
  31. #include <asm/system.h>
  32. #include "8390.h"
  33. #define DRV_NAME "ne3210"
  34. static void ne3210_reset_8390(struct net_device *dev);
  35. static void ne3210_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page);
  36. static void ne3210_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset);
  37. static void ne3210_block_output(struct net_device *dev, int count, const unsigned char *buf, const int start_page);
  38. #define NE3210_START_PG 0x00 /* First page of TX buffer */
  39. #define NE3210_STOP_PG 0x80 /* Last page +1 of RX ring */
  40. #define NE3210_IO_EXTENT 0x20
  41. #define NE3210_SA_PROM 0x16 /* Start of e'net addr. */
  42. #define NE3210_RESET_PORT 0xc84
  43. #define NE3210_NIC_OFFSET 0x00 /* Hello, the 8390 is *here* */
  44. #define NE3210_ADDR0 0x00 /* 3 byte vendor prefix */
  45. #define NE3210_ADDR1 0x00
  46. #define NE3210_ADDR2 0x1b
  47. #define NE3210_CFG1 0xc84 /* NB: 0xc84 is also "reset" port. */
  48. #define NE3210_CFG2 0xc90
  49. #define NE3210_CFG_EXTENT (NE3210_CFG2 - NE3210_CFG1 + 1)
  50. /*
  51. * You can OR any of the following bits together and assign it
  52. * to NE3210_DEBUG to get verbose driver info during operation.
  53. * Currently only the probe one is implemented.
  54. */
  55. #define NE3210_D_PROBE 0x01
  56. #define NE3210_D_RX_PKT 0x02
  57. #define NE3210_D_TX_PKT 0x04
  58. #define NE3210_D_IRQ 0x08
  59. #define NE3210_DEBUG 0x0
  60. static unsigned char irq_map[] __initdata = {15, 12, 11, 10, 9, 7, 5, 3};
  61. static unsigned int shmem_map[] __initdata = {0xff0, 0xfe0, 0xfff0, 0xd8, 0xffe0, 0xffc0, 0xd0, 0x0};
  62. static const char *ifmap[] __initdata = {"UTP", "?", "BNC", "AUI"};
  63. static int ifmap_val[] __initdata = {
  64. IF_PORT_10BASET,
  65. IF_PORT_UNKNOWN,
  66. IF_PORT_10BASE2,
  67. IF_PORT_AUI,
  68. };
  69. static int __init ne3210_eisa_probe (struct device *device)
  70. {
  71. unsigned long ioaddr, phys_mem;
  72. int i, retval, port_index;
  73. struct eisa_device *edev = to_eisa_device (device);
  74. struct net_device *dev;
  75. /* Allocate dev->priv and fill in 8390 specific dev fields. */
  76. if (!(dev = alloc_ei_netdev ())) {
  77. printk ("ne3210.c: unable to allocate memory for dev!\n");
  78. return -ENOMEM;
  79. }
  80. SET_NETDEV_DEV(dev, device);
  81. dev_set_drvdata(device, dev);
  82. ioaddr = edev->base_addr;
  83. if (!request_region(ioaddr, NE3210_IO_EXTENT, DRV_NAME)) {
  84. retval = -EBUSY;
  85. goto out;
  86. }
  87. if (!request_region(ioaddr + NE3210_CFG1,
  88. NE3210_CFG_EXTENT, DRV_NAME)) {
  89. retval = -EBUSY;
  90. goto out1;
  91. }
  92. #if NE3210_DEBUG & NE3210_D_PROBE
  93. printk("ne3210-debug: probe at %#x, ID %s\n", ioaddr, edev->id.sig);
  94. printk("ne3210-debug: config regs: %#x %#x\n",
  95. inb(ioaddr + NE3210_CFG1), inb(ioaddr + NE3210_CFG2));
  96. #endif
  97. port_index = inb(ioaddr + NE3210_CFG2) >> 6;
  98. for(i = 0; i < ETHER_ADDR_LEN; i++)
  99. dev->dev_addr[i] = inb(ioaddr + NE3210_SA_PROM + i);
  100. printk("ne3210.c: NE3210 in EISA slot %d, media: %s, addr: %pM.\n",
  101. edev->slot, ifmap[port_index], dev->dev_addr);
  102. /* Snarf the interrupt now. CFG file has them all listed as `edge' with share=NO */
  103. dev->irq = irq_map[(inb(ioaddr + NE3210_CFG2) >> 3) & 0x07];
  104. printk("ne3210.c: using IRQ %d, ", dev->irq);
  105. retval = request_irq(dev->irq, ei_interrupt, 0, DRV_NAME, dev);
  106. if (retval) {
  107. printk (" unable to get IRQ %d.\n", dev->irq);
  108. goto out2;
  109. }
  110. phys_mem = shmem_map[inb(ioaddr + NE3210_CFG2) & 0x07] * 0x1000;
  111. /*
  112. BEWARE!! Some dain-bramaged EISA SCUs will allow you to put
  113. the card mem within the region covered by `normal' RAM !!!
  114. */
  115. if (phys_mem > 1024*1024) { /* phys addr > 1MB */
  116. if (phys_mem < virt_to_phys(high_memory)) {
  117. printk(KERN_CRIT "ne3210.c: Card RAM overlaps with normal memory!!!\n");
  118. printk(KERN_CRIT "ne3210.c: Use EISA SCU to set card memory below 1MB,\n");
  119. printk(KERN_CRIT "ne3210.c: or to an address above 0x%llx.\n",
  120. (u64)virt_to_phys(high_memory));
  121. printk(KERN_CRIT "ne3210.c: Driver NOT installed.\n");
  122. retval = -EINVAL;
  123. goto out3;
  124. }
  125. }
  126. if (!request_mem_region (phys_mem, NE3210_STOP_PG*0x100, DRV_NAME)) {
  127. printk ("ne3210.c: Unable to request shared memory at physical address %#lx\n",
  128. phys_mem);
  129. goto out3;
  130. }
  131. printk("%dkB memory at physical address %#lx\n",
  132. NE3210_STOP_PG/4, phys_mem);
  133. ei_status.mem = ioremap(phys_mem, NE3210_STOP_PG*0x100);
  134. if (!ei_status.mem) {
  135. printk(KERN_ERR "ne3210.c: Unable to remap card memory !!\n");
  136. printk(KERN_ERR "ne3210.c: Driver NOT installed.\n");
  137. retval = -EAGAIN;
  138. goto out4;
  139. }
  140. printk("ne3210.c: remapped %dkB card memory to virtual address %p\n",
  141. NE3210_STOP_PG/4, ei_status.mem);
  142. dev->mem_start = (unsigned long)ei_status.mem;
  143. dev->mem_end = dev->mem_start + (NE3210_STOP_PG - NE3210_START_PG)*256;
  144. /* The 8390 offset is zero for the NE3210 */
  145. dev->base_addr = ioaddr;
  146. ei_status.name = "NE3210";
  147. ei_status.tx_start_page = NE3210_START_PG;
  148. ei_status.rx_start_page = NE3210_START_PG + TX_PAGES;
  149. ei_status.stop_page = NE3210_STOP_PG;
  150. ei_status.word16 = 1;
  151. ei_status.priv = phys_mem;
  152. if (ei_debug > 0)
  153. printk("ne3210 loaded.\n");
  154. ei_status.reset_8390 = &ne3210_reset_8390;
  155. ei_status.block_input = &ne3210_block_input;
  156. ei_status.block_output = &ne3210_block_output;
  157. ei_status.get_8390_hdr = &ne3210_get_8390_hdr;
  158. dev->netdev_ops = &ei_netdev_ops;
  159. dev->if_port = ifmap_val[port_index];
  160. if ((retval = register_netdev (dev)))
  161. goto out5;
  162. NS8390_init(dev, 0);
  163. return 0;
  164. out5:
  165. iounmap(ei_status.mem);
  166. out4:
  167. release_mem_region (phys_mem, NE3210_STOP_PG*0x100);
  168. out3:
  169. free_irq (dev->irq, dev);
  170. out2:
  171. release_region (ioaddr + NE3210_CFG1, NE3210_CFG_EXTENT);
  172. out1:
  173. release_region (ioaddr, NE3210_IO_EXTENT);
  174. out:
  175. free_netdev (dev);
  176. return retval;
  177. }
  178. static int __devexit ne3210_eisa_remove (struct device *device)
  179. {
  180. struct net_device *dev = dev_get_drvdata(device);
  181. unsigned long ioaddr = to_eisa_device (device)->base_addr;
  182. unregister_netdev (dev);
  183. iounmap(ei_status.mem);
  184. release_mem_region (ei_status.priv, NE3210_STOP_PG*0x100);
  185. free_irq (dev->irq, dev);
  186. release_region (ioaddr + NE3210_CFG1, NE3210_CFG_EXTENT);
  187. release_region (ioaddr, NE3210_IO_EXTENT);
  188. free_netdev (dev);
  189. return 0;
  190. }
  191. /*
  192. * Reset by toggling the "Board Enable" bits (bit 2 and 0).
  193. */
  194. static void ne3210_reset_8390(struct net_device *dev)
  195. {
  196. unsigned short ioaddr = dev->base_addr;
  197. outb(0x04, ioaddr + NE3210_RESET_PORT);
  198. if (ei_debug > 1) printk("%s: resetting the NE3210...", dev->name);
  199. mdelay(2);
  200. ei_status.txing = 0;
  201. outb(0x01, ioaddr + NE3210_RESET_PORT);
  202. if (ei_debug > 1) printk("reset done\n");
  203. }
  204. /*
  205. * Note: In the following three functions is the implicit assumption
  206. * that the associated memcpy will only use "rep; movsl" as long as
  207. * we keep the counts as some multiple of doublewords. This is a
  208. * requirement of the hardware, and also prevents us from using
  209. * eth_io_copy_and_sum() since we can't guarantee it will limit
  210. * itself to doubleword access.
  211. */
  212. /*
  213. * Grab the 8390 specific header. Similar to the block_input routine, but
  214. * we don't need to be concerned with ring wrap as the header will be at
  215. * the start of a page, so we optimize accordingly. (A single doubleword.)
  216. */
  217. static void
  218. ne3210_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
  219. {
  220. void __iomem *hdr_start = ei_status.mem + ((ring_page - NE3210_START_PG)<<8);
  221. memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
  222. hdr->count = (hdr->count + 3) & ~3; /* Round up allocation. */
  223. }
  224. /*
  225. * Block input and output are easy on shared memory ethercards, the only
  226. * complication is when the ring buffer wraps. The count will already
  227. * be rounded up to a doubleword value via ne3210_get_8390_hdr() above.
  228. */
  229. static void ne3210_block_input(struct net_device *dev, int count, struct sk_buff *skb,
  230. int ring_offset)
  231. {
  232. void __iomem *start = ei_status.mem + ring_offset - NE3210_START_PG*256;
  233. if (ring_offset + count > NE3210_STOP_PG*256) {
  234. /* Packet wraps over end of ring buffer. */
  235. int semi_count = NE3210_STOP_PG*256 - ring_offset;
  236. memcpy_fromio(skb->data, start, semi_count);
  237. count -= semi_count;
  238. memcpy_fromio(skb->data + semi_count,
  239. ei_status.mem + TX_PAGES*256, count);
  240. } else {
  241. /* Packet is in one chunk. */
  242. memcpy_fromio(skb->data, start, count);
  243. }
  244. }
  245. static void ne3210_block_output(struct net_device *dev, int count,
  246. const unsigned char *buf, int start_page)
  247. {
  248. void __iomem *shmem = ei_status.mem + ((start_page - NE3210_START_PG)<<8);
  249. count = (count + 3) & ~3; /* Round up to doubleword */
  250. memcpy_toio(shmem, buf, count);
  251. }
  252. static struct eisa_device_id ne3210_ids[] = {
  253. { "EGL0101" },
  254. { "NVL1801" },
  255. { "" },
  256. };
  257. MODULE_DEVICE_TABLE(eisa, ne3210_ids);
  258. static struct eisa_driver ne3210_eisa_driver = {
  259. .id_table = ne3210_ids,
  260. .driver = {
  261. .name = "ne3210",
  262. .probe = ne3210_eisa_probe,
  263. .remove = __devexit_p (ne3210_eisa_remove),
  264. },
  265. };
  266. MODULE_DESCRIPTION("NE3210 EISA Ethernet driver");
  267. MODULE_LICENSE("GPL");
  268. MODULE_DEVICE_TABLE(eisa, ne3210_ids);
  269. static int ne3210_init(void)
  270. {
  271. return eisa_driver_register (&ne3210_eisa_driver);
  272. }
  273. static void ne3210_cleanup(void)
  274. {
  275. eisa_driver_unregister (&ne3210_eisa_driver);
  276. }
  277. module_init (ne3210_init);
  278. module_exit (ne3210_cleanup);