ac3200.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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. SET_MODULE_OWNER(dev);
  84. if (ioaddr > 0x1ff) /* Check a single specified location. */
  85. return ac_probe1(ioaddr, dev);
  86. else if (ioaddr > 0) /* Don't probe at all. */
  87. return -ENXIO;
  88. if ( ! EISA_bus)
  89. return -ENXIO;
  90. for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
  91. if (ac_probe1(ioaddr, dev) == 0)
  92. return 0;
  93. dev->irq = irq;
  94. dev->mem_start = mem_start;
  95. }
  96. return -ENODEV;
  97. }
  98. #ifndef MODULE
  99. struct net_device * __init ac3200_probe(int unit)
  100. {
  101. struct net_device *dev = alloc_ei_netdev();
  102. int err;
  103. if (!dev)
  104. return ERR_PTR(-ENOMEM);
  105. sprintf(dev->name, "eth%d", unit);
  106. netdev_boot_setup_check(dev);
  107. err = do_ac3200_probe(dev);
  108. if (err)
  109. goto out;
  110. return dev;
  111. out:
  112. free_netdev(dev);
  113. return ERR_PTR(err);
  114. }
  115. #endif
  116. static int __init ac_probe1(int ioaddr, struct net_device *dev)
  117. {
  118. int i, retval;
  119. if (!request_region(ioaddr, AC_IO_EXTENT, DRV_NAME))
  120. return -EBUSY;
  121. if (inb_p(ioaddr + AC_ID_PORT) == 0xff) {
  122. retval = -ENODEV;
  123. goto out;
  124. }
  125. if (inl(ioaddr + AC_ID_PORT) != AC_EISA_ID) {
  126. retval = -ENODEV;
  127. goto out;
  128. }
  129. #ifndef final_version
  130. printk(KERN_DEBUG "AC3200 ethercard configuration register is %#02x,"
  131. " EISA ID %02x %02x %02x %02x.\n", inb(ioaddr + AC_CONFIG),
  132. inb(ioaddr + AC_ID_PORT + 0), inb(ioaddr + AC_ID_PORT + 1),
  133. inb(ioaddr + AC_ID_PORT + 2), inb(ioaddr + AC_ID_PORT + 3));
  134. #endif
  135. printk("AC3200 in EISA slot %d, node", ioaddr/0x1000);
  136. for(i = 0; i < 6; i++)
  137. printk(" %02x", dev->dev_addr[i] = inb(ioaddr + AC_SA_PROM + i));
  138. #if 0
  139. /* Check the vendor ID/prefix. Redundant after checking the EISA ID */
  140. if (inb(ioaddr + AC_SA_PROM + 0) != AC_ADDR0
  141. || inb(ioaddr + AC_SA_PROM + 1) != AC_ADDR1
  142. || inb(ioaddr + AC_SA_PROM + 2) != AC_ADDR2 ) {
  143. printk(", not found (invalid prefix).\n");
  144. retval = -ENODEV;
  145. goto out;
  146. }
  147. #endif
  148. /* Assign and allocate the interrupt now. */
  149. if (dev->irq == 0) {
  150. dev->irq = config2irq(inb(ioaddr + AC_CONFIG));
  151. printk(", using");
  152. } else {
  153. dev->irq = irq_canonicalize(dev->irq);
  154. printk(", assigning");
  155. }
  156. retval = request_irq(dev->irq, ei_interrupt, 0, DRV_NAME, dev);
  157. if (retval) {
  158. printk (" nothing! Unable to get IRQ %d.\n", dev->irq);
  159. goto out1;
  160. }
  161. printk(" IRQ %d, %s port\n", dev->irq, port_name[dev->if_port]);
  162. dev->base_addr = ioaddr;
  163. #ifdef notyet
  164. if (dev->mem_start) { /* Override the value from the board. */
  165. for (i = 0; i < 7; i++)
  166. if (addrmap[i] == dev->mem_start)
  167. break;
  168. if (i >= 7)
  169. i = 0;
  170. outb((inb(ioaddr + AC_CONFIG) & ~7) | i, ioaddr + AC_CONFIG);
  171. }
  172. #endif
  173. dev->if_port = inb(ioaddr + AC_CONFIG) >> 6;
  174. dev->mem_start = config2mem(inb(ioaddr + AC_CONFIG));
  175. printk("%s: AC3200 at %#3x with %dkB memory at physical address %#lx.\n",
  176. dev->name, ioaddr, AC_STOP_PG/4, dev->mem_start);
  177. /*
  178. * BEWARE!! Some dain-bramaged EISA SCUs will allow you to put
  179. * the card mem within the region covered by `normal' RAM !!!
  180. *
  181. * ioremap() will fail in that case.
  182. */
  183. ei_status.mem = ioremap(dev->mem_start, AC_STOP_PG*0x100);
  184. if (!ei_status.mem) {
  185. printk(KERN_ERR "ac3200.c: Unable to remap card memory above 1MB !!\n");
  186. printk(KERN_ERR "ac3200.c: Try using EISA SCU to set memory below 1MB.\n");
  187. printk(KERN_ERR "ac3200.c: Driver NOT installed.\n");
  188. retval = -EINVAL;
  189. goto out1;
  190. }
  191. printk("ac3200.c: remapped %dkB card memory to virtual address %p\n",
  192. AC_STOP_PG/4, ei_status.mem);
  193. dev->mem_start = (unsigned long)ei_status.mem;
  194. dev->mem_end = dev->mem_start + (AC_STOP_PG - AC_START_PG)*256;
  195. ei_status.name = "AC3200";
  196. ei_status.tx_start_page = AC_START_PG;
  197. ei_status.rx_start_page = AC_START_PG + TX_PAGES;
  198. ei_status.stop_page = AC_STOP_PG;
  199. ei_status.word16 = 1;
  200. if (ei_debug > 0)
  201. printk(version);
  202. ei_status.reset_8390 = &ac_reset_8390;
  203. ei_status.block_input = &ac_block_input;
  204. ei_status.block_output = &ac_block_output;
  205. ei_status.get_8390_hdr = &ac_get_8390_hdr;
  206. dev->open = &ac_open;
  207. dev->stop = &ac_close_card;
  208. #ifdef CONFIG_NET_POLL_CONTROLLER
  209. dev->poll_controller = ei_poll;
  210. #endif
  211. NS8390_init(dev, 0);
  212. retval = register_netdev(dev);
  213. if (retval)
  214. goto out2;
  215. return 0;
  216. out2:
  217. if (ei_status.reg0)
  218. iounmap(ei_status.mem);
  219. out1:
  220. free_irq(dev->irq, dev);
  221. out:
  222. release_region(ioaddr, AC_IO_EXTENT);
  223. return retval;
  224. }
  225. static int ac_open(struct net_device *dev)
  226. {
  227. #ifdef notyet
  228. /* Someday we may enable the IRQ and shared memory here. */
  229. int ioaddr = dev->base_addr;
  230. #endif
  231. ei_open(dev);
  232. return 0;
  233. }
  234. static void ac_reset_8390(struct net_device *dev)
  235. {
  236. ushort ioaddr = dev->base_addr;
  237. outb(AC_RESET, ioaddr + AC_RESET_PORT);
  238. if (ei_debug > 1) printk("resetting AC3200, t=%ld...", jiffies);
  239. ei_status.txing = 0;
  240. outb(AC_ENABLE, ioaddr + AC_RESET_PORT);
  241. if (ei_debug > 1) printk("reset done\n");
  242. return;
  243. }
  244. /* Grab the 8390 specific header. Similar to the block_input routine, but
  245. we don't need to be concerned with ring wrap as the header will be at
  246. the start of a page, so we optimize accordingly. */
  247. static void
  248. ac_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
  249. {
  250. void __iomem *hdr_start = ei_status.mem + ((ring_page - AC_START_PG)<<8);
  251. memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
  252. }
  253. /* Block input and output are easy on shared memory ethercards, the only
  254. complication is when the ring buffer wraps. */
  255. static void ac_block_input(struct net_device *dev, int count, struct sk_buff *skb,
  256. int ring_offset)
  257. {
  258. void __iomem *start = ei_status.mem + ring_offset - AC_START_PG*256;
  259. if (ring_offset + count > AC_STOP_PG*256) {
  260. /* We must wrap the input move. */
  261. int semi_count = AC_STOP_PG*256 - ring_offset;
  262. memcpy_fromio(skb->data, start, semi_count);
  263. count -= semi_count;
  264. memcpy_fromio(skb->data + semi_count,
  265. ei_status.mem + TX_PAGES*256, count);
  266. } else {
  267. memcpy_fromio(skb->data, start, count);
  268. }
  269. }
  270. static void ac_block_output(struct net_device *dev, int count,
  271. const unsigned char *buf, int start_page)
  272. {
  273. void __iomem *shmem = ei_status.mem + ((start_page - AC_START_PG)<<8);
  274. memcpy_toio(shmem, buf, count);
  275. }
  276. static int ac_close_card(struct net_device *dev)
  277. {
  278. if (ei_debug > 1)
  279. printk("%s: Shutting down ethercard.\n", dev->name);
  280. #ifdef notyet
  281. /* We should someday disable shared memory and interrupts. */
  282. outb(0x00, ioaddr + 6); /* Disable interrupts. */
  283. free_irq(dev->irq, dev);
  284. #endif
  285. ei_close(dev);
  286. return 0;
  287. }
  288. #ifdef MODULE
  289. #define MAX_AC32_CARDS 4 /* Max number of AC32 cards per module */
  290. static struct net_device *dev_ac32[MAX_AC32_CARDS];
  291. static int io[MAX_AC32_CARDS];
  292. static int irq[MAX_AC32_CARDS];
  293. static int mem[MAX_AC32_CARDS];
  294. module_param_array(io, int, NULL, 0);
  295. module_param_array(irq, int, NULL, 0);
  296. module_param_array(mem, int, NULL, 0);
  297. MODULE_PARM_DESC(io, "I/O base address(es)");
  298. MODULE_PARM_DESC(irq, "IRQ number(s)");
  299. MODULE_PARM_DESC(mem, "Memory base address(es)");
  300. MODULE_DESCRIPTION("Ansel AC3200 EISA ethernet driver");
  301. MODULE_LICENSE("GPL");
  302. int __init init_module(void)
  303. {
  304. struct net_device *dev;
  305. int this_dev, found = 0;
  306. for (this_dev = 0; this_dev < MAX_AC32_CARDS; this_dev++) {
  307. if (io[this_dev] == 0 && this_dev != 0)
  308. break;
  309. dev = alloc_ei_netdev();
  310. if (!dev)
  311. break;
  312. dev->irq = irq[this_dev];
  313. dev->base_addr = io[this_dev];
  314. dev->mem_start = mem[this_dev]; /* Currently ignored by driver */
  315. if (do_ac3200_probe(dev) == 0) {
  316. dev_ac32[found++] = dev;
  317. continue;
  318. }
  319. free_netdev(dev);
  320. printk(KERN_WARNING "ac3200.c: No ac3200 card found (i/o = 0x%x).\n", io[this_dev]);
  321. break;
  322. }
  323. if (found)
  324. return 0;
  325. return -ENXIO;
  326. }
  327. static void cleanup_card(struct net_device *dev)
  328. {
  329. /* Someday free_irq may be in ac_close_card() */
  330. free_irq(dev->irq, dev);
  331. release_region(dev->base_addr, AC_IO_EXTENT);
  332. iounmap(ei_status.mem);
  333. }
  334. void __exit
  335. cleanup_module(void)
  336. {
  337. int this_dev;
  338. for (this_dev = 0; this_dev < MAX_AC32_CARDS; this_dev++) {
  339. struct net_device *dev = dev_ac32[this_dev];
  340. if (dev) {
  341. unregister_netdev(dev);
  342. cleanup_card(dev);
  343. free_netdev(dev);
  344. }
  345. }
  346. }
  347. #endif /* MODULE */