ac3200.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. /* ac3200.c: A driver for the Ansel Communications EISA ethernet adaptor. */
  2. /*
  3. Written 1993, 1994 by Donald Becker.
  4. Copyright 1993 United States Government as represented by the Director,
  5. National Security Agency. This software may only be used and distributed
  6. according to the terms of the GNU General Public License as modified by SRC,
  7. incorporated herein by reference.
  8. The author may be reached as becker@scyld.com, or C/O
  9. Scyld Computing Corporation
  10. 410 Severn Ave., Suite 210
  11. Annapolis MD 21403
  12. This is driver for the Ansel Communications Model 3200 EISA Ethernet LAN
  13. Adapter. The programming information is from the users manual, as related
  14. by glee@ardnassak.math.clemson.edu.
  15. Changelog:
  16. Paul Gortmaker 05/98 : add support for shared mem above 1MB.
  17. */
  18. static const char version[] =
  19. "ac3200.c:v1.01 7/1/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
  20. #include <linux/module.h>
  21. #include <linux/eisa.h>
  22. #include <linux/kernel.h>
  23. #include <linux/errno.h>
  24. #include <linux/string.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/etherdevice.h>
  27. #include <linux/init.h>
  28. #include <asm/system.h>
  29. #include <asm/io.h>
  30. #include <asm/irq.h>
  31. #include "8390.h"
  32. #define DRV_NAME "ac3200"
  33. /* Offsets from the base address. */
  34. #define AC_NIC_BASE 0x00
  35. #define AC_SA_PROM 0x16 /* The station address PROM. */
  36. #define AC_ADDR0 0x00 /* Prefix station address values. */
  37. #define AC_ADDR1 0x40
  38. #define AC_ADDR2 0x90
  39. #define AC_ID_PORT 0xC80
  40. #define AC_EISA_ID 0x0110d305
  41. #define AC_RESET_PORT 0xC84
  42. #define AC_RESET 0x00
  43. #define AC_ENABLE 0x01
  44. #define AC_CONFIG 0xC90 /* The configuration port. */
  45. #define AC_IO_EXTENT 0x20
  46. /* Actually accessed is:
  47. * AC_NIC_BASE (0-15)
  48. * AC_SA_PROM (0-5)
  49. * AC_ID_PORT (0-3)
  50. * AC_RESET_PORT
  51. * AC_CONFIG
  52. */
  53. /* Decoding of the configuration register. */
  54. static unsigned char config2irqmap[8] __initdata = {15, 12, 11, 10, 9, 7, 5, 3};
  55. static int addrmap[8] =
  56. {0xFF0000, 0xFE0000, 0xFD0000, 0xFFF0000, 0xFFE0000, 0xFFC0000, 0xD0000, 0 };
  57. static const char *port_name[4] = { "10baseT", "invalid", "AUI", "10base2"};
  58. #define config2irq(configval) config2irqmap[((configval) >> 3) & 7]
  59. #define config2mem(configval) addrmap[(configval) & 7]
  60. #define config2name(configval) port_name[((configval) >> 6) & 3]
  61. /* First and last 8390 pages. */
  62. #define AC_START_PG 0x00 /* First page of 8390 TX buffer */
  63. #define AC_STOP_PG 0x80 /* Last page +1 of the 8390 RX ring */
  64. static int ac_probe1(int ioaddr, struct net_device *dev);
  65. static int ac_open(struct net_device *dev);
  66. static void ac_reset_8390(struct net_device *dev);
  67. static void ac_block_input(struct net_device *dev, int count,
  68. struct sk_buff *skb, int ring_offset);
  69. static void ac_block_output(struct net_device *dev, const int count,
  70. const unsigned char *buf, const int start_page);
  71. static void ac_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
  72. int ring_page);
  73. static int ac_close_card(struct net_device *dev);
  74. /* Probe for the AC3200.
  75. The AC3200 can be identified by either the EISA configuration registers,
  76. or the unique value in the station address PROM.
  77. */
  78. static int __init do_ac3200_probe(struct net_device *dev)
  79. {
  80. unsigned short ioaddr = dev->base_addr;
  81. int irq = dev->irq;
  82. int mem_start = dev->mem_start;
  83. if (ioaddr > 0x1ff) /* Check a single specified location. */
  84. return ac_probe1(ioaddr, dev);
  85. else if (ioaddr > 0) /* Don't probe at all. */
  86. return -ENXIO;
  87. if ( ! EISA_bus)
  88. return -ENXIO;
  89. for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
  90. if (ac_probe1(ioaddr, dev) == 0)
  91. return 0;
  92. dev->irq = irq;
  93. dev->mem_start = mem_start;
  94. }
  95. return -ENODEV;
  96. }
  97. #ifndef MODULE
  98. struct net_device * __init ac3200_probe(int unit)
  99. {
  100. struct net_device *dev = alloc_ei_netdev();
  101. int err;
  102. if (!dev)
  103. return ERR_PTR(-ENOMEM);
  104. sprintf(dev->name, "eth%d", unit);
  105. netdev_boot_setup_check(dev);
  106. err = do_ac3200_probe(dev);
  107. if (err)
  108. goto out;
  109. return dev;
  110. out:
  111. free_netdev(dev);
  112. return ERR_PTR(err);
  113. }
  114. #endif
  115. static const struct net_device_ops ac_netdev_ops = {
  116. .ndo_open = ac_open,
  117. .ndo_stop = ac_close_card,
  118. .ndo_start_xmit = ei_start_xmit,
  119. .ndo_tx_timeout = ei_tx_timeout,
  120. .ndo_get_stats = ei_get_stats,
  121. .ndo_set_multicast_list = ei_set_multicast_list,
  122. .ndo_validate_addr = eth_validate_addr,
  123. .ndo_set_mac_address = eth_mac_addr,
  124. .ndo_change_mtu = eth_change_mtu,
  125. #ifdef CONFIG_NET_POLL_CONTROLLER
  126. .ndo_poll_controller = ei_poll,
  127. #endif
  128. };
  129. static int __init ac_probe1(int ioaddr, struct net_device *dev)
  130. {
  131. int i, retval;
  132. if (!request_region(ioaddr, AC_IO_EXTENT, DRV_NAME))
  133. return -EBUSY;
  134. if (inb_p(ioaddr + AC_ID_PORT) == 0xff) {
  135. retval = -ENODEV;
  136. goto out;
  137. }
  138. if (inl(ioaddr + AC_ID_PORT) != AC_EISA_ID) {
  139. retval = -ENODEV;
  140. goto out;
  141. }
  142. #ifndef final_version
  143. printk(KERN_DEBUG "AC3200 ethercard configuration register is %#02x,"
  144. " EISA ID %02x %02x %02x %02x.\n", inb(ioaddr + AC_CONFIG),
  145. inb(ioaddr + AC_ID_PORT + 0), inb(ioaddr + AC_ID_PORT + 1),
  146. inb(ioaddr + AC_ID_PORT + 2), inb(ioaddr + AC_ID_PORT + 3));
  147. #endif
  148. for (i = 0; i < 6; i++)
  149. dev->dev_addr[i] = inb(ioaddr + AC_SA_PROM + i);
  150. printk(KERN_DEBUG "AC3200 in EISA slot %d, node %pM",
  151. ioaddr/0x1000, dev->dev_addr);
  152. #if 0
  153. /* Check the vendor ID/prefix. Redundant after checking the EISA ID */
  154. if (inb(ioaddr + AC_SA_PROM + 0) != AC_ADDR0
  155. || inb(ioaddr + AC_SA_PROM + 1) != AC_ADDR1
  156. || inb(ioaddr + AC_SA_PROM + 2) != AC_ADDR2 ) {
  157. printk(", not found (invalid prefix).\n");
  158. retval = -ENODEV;
  159. goto out;
  160. }
  161. #endif
  162. /* Assign and allocate the interrupt now. */
  163. if (dev->irq == 0) {
  164. dev->irq = config2irq(inb(ioaddr + AC_CONFIG));
  165. printk(", using");
  166. } else {
  167. dev->irq = irq_canonicalize(dev->irq);
  168. printk(", assigning");
  169. }
  170. retval = request_irq(dev->irq, ei_interrupt, 0, DRV_NAME, dev);
  171. if (retval) {
  172. printk (" nothing! Unable to get IRQ %d.\n", dev->irq);
  173. goto out;
  174. }
  175. printk(" IRQ %d, %s port\n", dev->irq, port_name[dev->if_port]);
  176. dev->base_addr = ioaddr;
  177. #ifdef notyet
  178. if (dev->mem_start) { /* Override the value from the board. */
  179. for (i = 0; i < 7; i++)
  180. if (addrmap[i] == dev->mem_start)
  181. break;
  182. if (i >= 7)
  183. i = 0;
  184. outb((inb(ioaddr + AC_CONFIG) & ~7) | i, ioaddr + AC_CONFIG);
  185. }
  186. #endif
  187. dev->if_port = inb(ioaddr + AC_CONFIG) >> 6;
  188. dev->mem_start = config2mem(inb(ioaddr + AC_CONFIG));
  189. printk("%s: AC3200 at %#3x with %dkB memory at physical address %#lx.\n",
  190. dev->name, ioaddr, AC_STOP_PG/4, dev->mem_start);
  191. /*
  192. * BEWARE!! Some dain-bramaged EISA SCUs will allow you to put
  193. * the card mem within the region covered by `normal' RAM !!!
  194. *
  195. * ioremap() will fail in that case.
  196. */
  197. ei_status.mem = ioremap(dev->mem_start, AC_STOP_PG*0x100);
  198. if (!ei_status.mem) {
  199. printk(KERN_ERR "ac3200.c: Unable to remap card memory above 1MB !!\n");
  200. printk(KERN_ERR "ac3200.c: Try using EISA SCU to set memory below 1MB.\n");
  201. printk(KERN_ERR "ac3200.c: Driver NOT installed.\n");
  202. retval = -EINVAL;
  203. goto out1;
  204. }
  205. printk("ac3200.c: remapped %dkB card memory to virtual address %p\n",
  206. AC_STOP_PG/4, ei_status.mem);
  207. dev->mem_start = (unsigned long)ei_status.mem;
  208. dev->mem_end = dev->mem_start + (AC_STOP_PG - AC_START_PG)*256;
  209. ei_status.name = "AC3200";
  210. ei_status.tx_start_page = AC_START_PG;
  211. ei_status.rx_start_page = AC_START_PG + TX_PAGES;
  212. ei_status.stop_page = AC_STOP_PG;
  213. ei_status.word16 = 1;
  214. if (ei_debug > 0)
  215. printk(version);
  216. ei_status.reset_8390 = &ac_reset_8390;
  217. ei_status.block_input = &ac_block_input;
  218. ei_status.block_output = &ac_block_output;
  219. ei_status.get_8390_hdr = &ac_get_8390_hdr;
  220. dev->netdev_ops = &ac_netdev_ops;
  221. NS8390_init(dev, 0);
  222. retval = register_netdev(dev);
  223. if (retval)
  224. goto out2;
  225. return 0;
  226. out2:
  227. if (ei_status.reg0)
  228. iounmap(ei_status.mem);
  229. out1:
  230. free_irq(dev->irq, dev);
  231. out:
  232. release_region(ioaddr, AC_IO_EXTENT);
  233. return retval;
  234. }
  235. static int ac_open(struct net_device *dev)
  236. {
  237. #ifdef notyet
  238. /* Someday we may enable the IRQ and shared memory here. */
  239. int ioaddr = dev->base_addr;
  240. #endif
  241. ei_open(dev);
  242. return 0;
  243. }
  244. static void ac_reset_8390(struct net_device *dev)
  245. {
  246. ushort ioaddr = dev->base_addr;
  247. outb(AC_RESET, ioaddr + AC_RESET_PORT);
  248. if (ei_debug > 1) printk("resetting AC3200, t=%ld...", jiffies);
  249. ei_status.txing = 0;
  250. outb(AC_ENABLE, ioaddr + AC_RESET_PORT);
  251. if (ei_debug > 1) printk("reset done\n");
  252. }
  253. /* Grab the 8390 specific header. Similar to the block_input routine, but
  254. we don't need to be concerned with ring wrap as the header will be at
  255. the start of a page, so we optimize accordingly. */
  256. static void
  257. ac_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
  258. {
  259. void __iomem *hdr_start = ei_status.mem + ((ring_page - AC_START_PG)<<8);
  260. memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
  261. }
  262. /* Block input and output are easy on shared memory ethercards, the only
  263. complication is when the ring buffer wraps. */
  264. static void ac_block_input(struct net_device *dev, int count, struct sk_buff *skb,
  265. int ring_offset)
  266. {
  267. void __iomem *start = ei_status.mem + ring_offset - AC_START_PG*256;
  268. if (ring_offset + count > AC_STOP_PG*256) {
  269. /* We must wrap the input move. */
  270. int semi_count = AC_STOP_PG*256 - ring_offset;
  271. memcpy_fromio(skb->data, start, semi_count);
  272. count -= semi_count;
  273. memcpy_fromio(skb->data + semi_count,
  274. ei_status.mem + TX_PAGES*256, count);
  275. } else {
  276. memcpy_fromio(skb->data, start, count);
  277. }
  278. }
  279. static void ac_block_output(struct net_device *dev, int count,
  280. const unsigned char *buf, int start_page)
  281. {
  282. void __iomem *shmem = ei_status.mem + ((start_page - AC_START_PG)<<8);
  283. memcpy_toio(shmem, buf, count);
  284. }
  285. static int ac_close_card(struct net_device *dev)
  286. {
  287. if (ei_debug > 1)
  288. printk("%s: Shutting down ethercard.\n", dev->name);
  289. #ifdef notyet
  290. /* We should someday disable shared memory and interrupts. */
  291. outb(0x00, ioaddr + 6); /* Disable interrupts. */
  292. free_irq(dev->irq, dev);
  293. #endif
  294. ei_close(dev);
  295. return 0;
  296. }
  297. #ifdef MODULE
  298. #define MAX_AC32_CARDS 4 /* Max number of AC32 cards per module */
  299. static struct net_device *dev_ac32[MAX_AC32_CARDS];
  300. static int io[MAX_AC32_CARDS];
  301. static int irq[MAX_AC32_CARDS];
  302. static int mem[MAX_AC32_CARDS];
  303. module_param_array(io, int, NULL, 0);
  304. module_param_array(irq, int, NULL, 0);
  305. module_param_array(mem, int, NULL, 0);
  306. MODULE_PARM_DESC(io, "I/O base address(es)");
  307. MODULE_PARM_DESC(irq, "IRQ number(s)");
  308. MODULE_PARM_DESC(mem, "Memory base address(es)");
  309. MODULE_DESCRIPTION("Ansel AC3200 EISA ethernet driver");
  310. MODULE_LICENSE("GPL");
  311. static int __init ac3200_module_init(void)
  312. {
  313. struct net_device *dev;
  314. int this_dev, found = 0;
  315. for (this_dev = 0; this_dev < MAX_AC32_CARDS; this_dev++) {
  316. if (io[this_dev] == 0 && this_dev != 0)
  317. break;
  318. dev = alloc_ei_netdev();
  319. if (!dev)
  320. break;
  321. dev->irq = irq[this_dev];
  322. dev->base_addr = io[this_dev];
  323. dev->mem_start = mem[this_dev]; /* Currently ignored by driver */
  324. if (do_ac3200_probe(dev) == 0) {
  325. dev_ac32[found++] = dev;
  326. continue;
  327. }
  328. free_netdev(dev);
  329. printk(KERN_WARNING "ac3200.c: No ac3200 card found (i/o = 0x%x).\n", io[this_dev]);
  330. break;
  331. }
  332. if (found)
  333. return 0;
  334. return -ENXIO;
  335. }
  336. static void cleanup_card(struct net_device *dev)
  337. {
  338. /* Someday free_irq may be in ac_close_card() */
  339. free_irq(dev->irq, dev);
  340. release_region(dev->base_addr, AC_IO_EXTENT);
  341. iounmap(ei_status.mem);
  342. }
  343. static void __exit ac3200_module_exit(void)
  344. {
  345. int this_dev;
  346. for (this_dev = 0; this_dev < MAX_AC32_CARDS; this_dev++) {
  347. struct net_device *dev = dev_ac32[this_dev];
  348. if (dev) {
  349. unregister_netdev(dev);
  350. cleanup_card(dev);
  351. free_netdev(dev);
  352. }
  353. }
  354. }
  355. module_init(ac3200_module_init);
  356. module_exit(ac3200_module_exit);
  357. #endif /* MODULE */