3c503.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. /* 3c503.c: A shared-memory NS8390 ethernet driver for linux. */
  2. /*
  3. Written 1992-94 by Donald Becker.
  4. Copyright 1993 United States Government as represented by the
  5. Director, National Security Agency. This software may be used and
  6. distributed according to the terms of the GNU General Public License,
  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 driver should work with the 3c503 and 3c503/16. It should be used
  13. in shared memory mode for best performance, although it may also work
  14. in programmed-I/O mode.
  15. Sources:
  16. EtherLink II Technical Reference Manual,
  17. EtherLink II/16 Technical Reference Manual Supplement,
  18. 3Com Corporation, 5400 Bayfront Plaza, Santa Clara CA 95052-8145
  19. The Crynwr 3c503 packet driver.
  20. Changelog:
  21. Paul Gortmaker : add support for the 2nd 8kB of RAM on 16 bit cards.
  22. Paul Gortmaker : multiple card support for module users.
  23. rjohnson@analogic.com : Fix up PIO interface for efficient operation.
  24. Jeff Garzik : ethtool support
  25. */
  26. #define DRV_NAME "3c503"
  27. #define DRV_VERSION "1.10a"
  28. #define DRV_RELDATE "11/17/2001"
  29. static const char version[] =
  30. DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " Donald Becker (becker@scyld.com)\n";
  31. #include <linux/module.h>
  32. #include <linux/kernel.h>
  33. #include <linux/errno.h>
  34. #include <linux/string.h>
  35. #include <linux/delay.h>
  36. #include <linux/netdevice.h>
  37. #include <linux/etherdevice.h>
  38. #include <linux/init.h>
  39. #include <linux/ethtool.h>
  40. #include <asm/uaccess.h>
  41. #include <asm/io.h>
  42. #include <asm/system.h>
  43. #include <asm/byteorder.h>
  44. #include "8390.h"
  45. #include "3c503.h"
  46. #define WRD_COUNT 4
  47. static int el2_pio_probe(struct net_device *dev);
  48. static int el2_probe1(struct net_device *dev, int ioaddr);
  49. /* A zero-terminated list of I/O addresses to be probed in PIO mode. */
  50. static unsigned int netcard_portlist[] __initdata =
  51. { 0x300,0x310,0x330,0x350,0x250,0x280,0x2a0,0x2e0,0};
  52. #define EL2_IO_EXTENT 16
  53. static int el2_open(struct net_device *dev);
  54. static int el2_close(struct net_device *dev);
  55. static void el2_reset_8390(struct net_device *dev);
  56. static void el2_init_card(struct net_device *dev);
  57. static void el2_block_output(struct net_device *dev, int count,
  58. const unsigned char *buf, int start_page);
  59. static void el2_block_input(struct net_device *dev, int count, struct sk_buff *skb,
  60. int ring_offset);
  61. static void el2_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
  62. int ring_page);
  63. static const struct ethtool_ops netdev_ethtool_ops;
  64. /* This routine probes for a memory-mapped 3c503 board by looking for
  65. the "location register" at the end of the jumpered boot PROM space.
  66. This works even if a PROM isn't there.
  67. If the ethercard isn't found there is an optional probe for
  68. ethercard jumpered to programmed-I/O mode.
  69. */
  70. static int __init do_el2_probe(struct net_device *dev)
  71. {
  72. int *addr, addrs[] = { 0xddffe, 0xd9ffe, 0xcdffe, 0xc9ffe, 0};
  73. int base_addr = dev->base_addr;
  74. int irq = dev->irq;
  75. if (base_addr > 0x1ff) /* Check a single specified location. */
  76. return el2_probe1(dev, base_addr);
  77. else if (base_addr != 0) /* Don't probe at all. */
  78. return -ENXIO;
  79. for (addr = addrs; *addr; addr++) {
  80. void __iomem *p = ioremap(*addr, 1);
  81. unsigned base_bits;
  82. int i;
  83. if (!p)
  84. continue;
  85. base_bits = readb(p);
  86. iounmap(p);
  87. i = ffs(base_bits) - 1;
  88. if (i == -1 || base_bits != (1 << i))
  89. continue;
  90. if (el2_probe1(dev, netcard_portlist[i]) == 0)
  91. return 0;
  92. dev->irq = irq;
  93. }
  94. #if ! defined(no_probe_nonshared_memory)
  95. return el2_pio_probe(dev);
  96. #else
  97. return -ENODEV;
  98. #endif
  99. }
  100. /* Try all of the locations that aren't obviously empty. This touches
  101. a lot of locations, and is much riskier than the code above. */
  102. static int __init
  103. el2_pio_probe(struct net_device *dev)
  104. {
  105. int i;
  106. int base_addr = dev->base_addr;
  107. int irq = dev->irq;
  108. if (base_addr > 0x1ff) /* Check a single specified location. */
  109. return el2_probe1(dev, base_addr);
  110. else if (base_addr != 0) /* Don't probe at all. */
  111. return -ENXIO;
  112. for (i = 0; netcard_portlist[i]; i++) {
  113. if (el2_probe1(dev, netcard_portlist[i]) == 0)
  114. return 0;
  115. dev->irq = irq;
  116. }
  117. return -ENODEV;
  118. }
  119. #ifndef MODULE
  120. struct net_device * __init el2_probe(int unit)
  121. {
  122. struct net_device *dev = alloc_eip_netdev();
  123. int err;
  124. if (!dev)
  125. return ERR_PTR(-ENOMEM);
  126. sprintf(dev->name, "eth%d", unit);
  127. netdev_boot_setup_check(dev);
  128. err = do_el2_probe(dev);
  129. if (err)
  130. goto out;
  131. return dev;
  132. out:
  133. free_netdev(dev);
  134. return ERR_PTR(err);
  135. }
  136. #endif
  137. static const struct net_device_ops el2_netdev_ops = {
  138. .ndo_open = el2_open,
  139. .ndo_stop = el2_close,
  140. .ndo_start_xmit = eip_start_xmit,
  141. .ndo_tx_timeout = eip_tx_timeout,
  142. .ndo_get_stats = eip_get_stats,
  143. .ndo_set_multicast_list = eip_set_multicast_list,
  144. .ndo_validate_addr = eth_validate_addr,
  145. .ndo_set_mac_address = eth_mac_addr,
  146. .ndo_change_mtu = eth_change_mtu,
  147. #ifdef CONFIG_NET_POLL_CONTROLLER
  148. .ndo_poll_controller = eip_poll,
  149. #endif
  150. };
  151. /* Probe for the Etherlink II card at I/O port base IOADDR,
  152. returning non-zero on success. If found, set the station
  153. address and memory parameters in DEVICE. */
  154. static int __init
  155. el2_probe1(struct net_device *dev, int ioaddr)
  156. {
  157. int i, iobase_reg, membase_reg, saved_406, wordlength, retval;
  158. static unsigned version_printed;
  159. unsigned long vendor_id;
  160. if (!request_region(ioaddr, EL2_IO_EXTENT, DRV_NAME))
  161. return -EBUSY;
  162. if (!request_region(ioaddr + 0x400, 8, DRV_NAME)) {
  163. retval = -EBUSY;
  164. goto out;
  165. }
  166. /* Reset and/or avoid any lurking NE2000 */
  167. if (inb(ioaddr + 0x408) == 0xff) {
  168. mdelay(1);
  169. retval = -ENODEV;
  170. goto out1;
  171. }
  172. /* We verify that it's a 3C503 board by checking the first three octets
  173. of its ethernet address. */
  174. iobase_reg = inb(ioaddr+0x403);
  175. membase_reg = inb(ioaddr+0x404);
  176. /* ASIC location registers should be 0 or have only a single bit set. */
  177. if ((iobase_reg & (iobase_reg - 1)) ||
  178. (membase_reg & (membase_reg - 1))) {
  179. retval = -ENODEV;
  180. goto out1;
  181. }
  182. saved_406 = inb_p(ioaddr + 0x406);
  183. outb_p(ECNTRL_RESET|ECNTRL_THIN, ioaddr + 0x406); /* Reset it... */
  184. outb_p(ECNTRL_THIN, ioaddr + 0x406);
  185. /* Map the station addr PROM into the lower I/O ports. We now check
  186. for both the old and new 3Com prefix */
  187. outb(ECNTRL_SAPROM|ECNTRL_THIN, ioaddr + 0x406);
  188. vendor_id = inb(ioaddr)*0x10000 + inb(ioaddr + 1)*0x100 + inb(ioaddr + 2);
  189. if ((vendor_id != OLD_3COM_ID) && (vendor_id != NEW_3COM_ID)) {
  190. /* Restore the register we frobbed. */
  191. outb(saved_406, ioaddr + 0x406);
  192. retval = -ENODEV;
  193. goto out1;
  194. }
  195. if (ei_debug && version_printed++ == 0)
  196. pr_debug("%s", version);
  197. dev->base_addr = ioaddr;
  198. pr_info("%s: 3c503 at i/o base %#3x, node ", dev->name, ioaddr);
  199. /* Retrieve and print the ethernet address. */
  200. for (i = 0; i < 6; i++)
  201. dev->dev_addr[i] = inb(ioaddr + i);
  202. pr_cont("%pM", dev->dev_addr);
  203. /* Map the 8390 back into the window. */
  204. outb(ECNTRL_THIN, ioaddr + 0x406);
  205. /* Check for EL2/16 as described in tech. man. */
  206. outb_p(E8390_PAGE0, ioaddr + E8390_CMD);
  207. outb_p(0, ioaddr + EN0_DCFG);
  208. outb_p(E8390_PAGE2, ioaddr + E8390_CMD);
  209. wordlength = inb_p(ioaddr + EN0_DCFG) & ENDCFG_WTS;
  210. outb_p(E8390_PAGE0, ioaddr + E8390_CMD);
  211. /* Probe for, turn on and clear the board's shared memory. */
  212. if (ei_debug > 2)
  213. pr_cont(" memory jumpers %2.2x ", membase_reg);
  214. outb(EGACFR_NORM, ioaddr + 0x405); /* Enable RAM */
  215. /* This should be probed for (or set via an ioctl()) at run-time.
  216. Right now we use a sleazy hack to pass in the interface number
  217. at boot-time via the low bits of the mem_end field. That value is
  218. unused, and the low bits would be discarded even if it was used. */
  219. #if defined(EI8390_THICK) || defined(EL2_AUI)
  220. ei_status.interface_num = 1;
  221. #else
  222. ei_status.interface_num = dev->mem_end & 0xf;
  223. #endif
  224. pr_cont(", using %sternal xcvr.\n", ei_status.interface_num == 0 ? "in" : "ex");
  225. if ((membase_reg & 0xf0) == 0) {
  226. dev->mem_start = 0;
  227. ei_status.name = "3c503-PIO";
  228. ei_status.mem = NULL;
  229. } else {
  230. dev->mem_start = ((membase_reg & 0xc0) ? 0xD8000 : 0xC8000) +
  231. ((membase_reg & 0xA0) ? 0x4000 : 0);
  232. #define EL2_MEMSIZE (EL2_MB1_STOP_PG - EL2_MB1_START_PG)*256
  233. ei_status.mem = ioremap(dev->mem_start, EL2_MEMSIZE);
  234. #ifdef EL2MEMTEST
  235. /* This has never found an error, but someone might care.
  236. Note that it only tests the 2nd 8kB on 16kB 3c503/16
  237. cards between card addr. 0x2000 and 0x3fff. */
  238. { /* Check the card's memory. */
  239. void __iomem *mem_base = ei_status.mem;
  240. unsigned int test_val = 0xbbadf00d;
  241. writel(0xba5eba5e, mem_base);
  242. for (i = sizeof(test_val); i < EL2_MEMSIZE; i+=sizeof(test_val)) {
  243. writel(test_val, mem_base + i);
  244. if (readl(mem_base) != 0xba5eba5e ||
  245. readl(mem_base + i) != test_val) {
  246. pr_warning("3c503: memory failure or memory address conflict.\n");
  247. dev->mem_start = 0;
  248. ei_status.name = "3c503-PIO";
  249. iounmap(mem_base);
  250. ei_status.mem = NULL;
  251. break;
  252. }
  253. test_val += 0x55555555;
  254. writel(0, mem_base + i);
  255. }
  256. }
  257. #endif /* EL2MEMTEST */
  258. if (dev->mem_start)
  259. dev->mem_end = dev->mem_start + EL2_MEMSIZE;
  260. if (wordlength) { /* No Tx pages to skip over to get to Rx */
  261. ei_status.priv = 0;
  262. ei_status.name = "3c503/16";
  263. } else {
  264. ei_status.priv = TX_PAGES * 256;
  265. ei_status.name = "3c503";
  266. }
  267. }
  268. /*
  269. Divide up the memory on the card. This is the same regardless of
  270. whether shared-mem or PIO is used. For 16 bit cards (16kB RAM),
  271. we use the entire 8k of bank1 for an Rx ring. We only use 3k
  272. of the bank0 for 2 full size Tx packet slots. For 8 bit cards,
  273. (8kB RAM) we use 3kB of bank1 for two Tx slots, and the remaining
  274. 5kB for an Rx ring. */
  275. if (wordlength) {
  276. ei_status.tx_start_page = EL2_MB0_START_PG;
  277. ei_status.rx_start_page = EL2_MB1_START_PG;
  278. } else {
  279. ei_status.tx_start_page = EL2_MB1_START_PG;
  280. ei_status.rx_start_page = EL2_MB1_START_PG + TX_PAGES;
  281. }
  282. /* Finish setting the board's parameters. */
  283. ei_status.stop_page = EL2_MB1_STOP_PG;
  284. ei_status.word16 = wordlength;
  285. ei_status.reset_8390 = el2_reset_8390;
  286. ei_status.get_8390_hdr = el2_get_8390_hdr;
  287. ei_status.block_input = el2_block_input;
  288. ei_status.block_output = el2_block_output;
  289. if (dev->irq == 2)
  290. dev->irq = 9;
  291. else if (dev->irq > 5 && dev->irq != 9) {
  292. pr_warning("3c503: configured interrupt %d invalid, will use autoIRQ.\n",
  293. dev->irq);
  294. dev->irq = 0;
  295. }
  296. ei_status.saved_irq = dev->irq;
  297. dev->netdev_ops = &el2_netdev_ops;
  298. dev->ethtool_ops = &netdev_ethtool_ops;
  299. retval = register_netdev(dev);
  300. if (retval)
  301. goto out1;
  302. if (dev->mem_start)
  303. pr_info("%s: %s - %dkB RAM, 8kB shared mem window at %#6lx-%#6lx.\n",
  304. dev->name, ei_status.name, (wordlength+1)<<3,
  305. dev->mem_start, dev->mem_end-1);
  306. else
  307. {
  308. ei_status.tx_start_page = EL2_MB1_START_PG;
  309. ei_status.rx_start_page = EL2_MB1_START_PG + TX_PAGES;
  310. pr_info("%s: %s, %dkB RAM, using programmed I/O (REJUMPER for SHARED MEMORY).\n",
  311. dev->name, ei_status.name, (wordlength+1)<<3);
  312. }
  313. release_region(ioaddr + 0x400, 8);
  314. return 0;
  315. out1:
  316. release_region(ioaddr + 0x400, 8);
  317. out:
  318. release_region(ioaddr, EL2_IO_EXTENT);
  319. return retval;
  320. }
  321. static irqreturn_t el2_probe_interrupt(int irq, void *seen)
  322. {
  323. *(bool *)seen = true;
  324. return IRQ_HANDLED;
  325. }
  326. static int
  327. el2_open(struct net_device *dev)
  328. {
  329. int retval;
  330. if (dev->irq < 2) {
  331. static const int irqlist[] = {5, 9, 3, 4, 0};
  332. const int *irqp = irqlist;
  333. outb(EGACFR_NORM, E33G_GACFR); /* Enable RAM and interrupts. */
  334. do {
  335. bool seen;
  336. retval = request_irq(*irqp, el2_probe_interrupt, 0,
  337. dev->name, &seen);
  338. if (retval == -EBUSY)
  339. continue;
  340. if (retval < 0)
  341. goto err_disable;
  342. /* Twinkle the interrupt, and check if it's seen. */
  343. seen = false;
  344. smp_wmb();
  345. outb_p(0x04 << ((*irqp == 9) ? 2 : *irqp), E33G_IDCFR);
  346. outb_p(0x00, E33G_IDCFR);
  347. msleep(1);
  348. free_irq(*irqp, &seen);
  349. if (!seen)
  350. continue;
  351. retval = request_irq(dev->irq = *irqp, eip_interrupt, 0,
  352. dev->name, dev);
  353. if (retval == -EBUSY)
  354. continue;
  355. if (retval < 0)
  356. goto err_disable;
  357. break;
  358. } while (*++irqp);
  359. if (*irqp == 0) {
  360. err_disable:
  361. outb(EGACFR_IRQOFF, E33G_GACFR); /* disable interrupts. */
  362. return -EAGAIN;
  363. }
  364. } else {
  365. if ((retval = request_irq(dev->irq, eip_interrupt, 0, dev->name, dev))) {
  366. return retval;
  367. }
  368. }
  369. el2_init_card(dev);
  370. eip_open(dev);
  371. return 0;
  372. }
  373. static int
  374. el2_close(struct net_device *dev)
  375. {
  376. free_irq(dev->irq, dev);
  377. dev->irq = ei_status.saved_irq;
  378. outb(EGACFR_IRQOFF, E33G_GACFR); /* disable interrupts. */
  379. eip_close(dev);
  380. return 0;
  381. }
  382. /* This is called whenever we have a unrecoverable failure:
  383. transmit timeout
  384. Bad ring buffer packet header
  385. */
  386. static void
  387. el2_reset_8390(struct net_device *dev)
  388. {
  389. if (ei_debug > 1) {
  390. pr_debug("%s: Resetting the 3c503 board...", dev->name);
  391. pr_cont(" %#lx=%#02x %#lx=%#02x %#lx=%#02x...", E33G_IDCFR, inb(E33G_IDCFR),
  392. E33G_CNTRL, inb(E33G_CNTRL), E33G_GACFR, inb(E33G_GACFR));
  393. }
  394. outb_p(ECNTRL_RESET|ECNTRL_THIN, E33G_CNTRL);
  395. ei_status.txing = 0;
  396. outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
  397. el2_init_card(dev);
  398. if (ei_debug > 1)
  399. pr_cont("done\n");
  400. }
  401. /* Initialize the 3c503 GA registers after a reset. */
  402. static void
  403. el2_init_card(struct net_device *dev)
  404. {
  405. /* Unmap the station PROM and select the DIX or BNC connector. */
  406. outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
  407. /* Set ASIC copy of rx's first and last+1 buffer pages */
  408. /* These must be the same as in the 8390. */
  409. outb(ei_status.rx_start_page, E33G_STARTPG);
  410. outb(ei_status.stop_page, E33G_STOPPG);
  411. /* Point the vector pointer registers somewhere ?harmless?. */
  412. outb(0xff, E33G_VP2); /* Point at the ROM restart location 0xffff0 */
  413. outb(0xff, E33G_VP1);
  414. outb(0x00, E33G_VP0);
  415. /* Turn off all interrupts until we're opened. */
  416. outb_p(0x00, dev->base_addr + EN0_IMR);
  417. /* Enable IRQs iff started. */
  418. outb(EGACFR_NORM, E33G_GACFR);
  419. /* Set the interrupt line. */
  420. outb_p((0x04 << (dev->irq == 9 ? 2 : dev->irq)), E33G_IDCFR);
  421. outb_p((WRD_COUNT << 1), E33G_DRQCNT); /* Set burst size to 8 */
  422. outb_p(0x20, E33G_DMAAH); /* Put a valid addr in the GA DMA */
  423. outb_p(0x00, E33G_DMAAL);
  424. return; /* We always succeed */
  425. }
  426. /*
  427. * Either use the shared memory (if enabled on the board) or put the packet
  428. * out through the ASIC FIFO.
  429. */
  430. static void
  431. el2_block_output(struct net_device *dev, int count,
  432. const unsigned char *buf, int start_page)
  433. {
  434. unsigned short int *wrd;
  435. int boguscount; /* timeout counter */
  436. unsigned short word; /* temporary for better machine code */
  437. void __iomem *base = ei_status.mem;
  438. if (ei_status.word16) /* Tx packets go into bank 0 on EL2/16 card */
  439. outb(EGACFR_RSEL|EGACFR_TCM, E33G_GACFR);
  440. else
  441. outb(EGACFR_NORM, E33G_GACFR);
  442. if (base) { /* Shared memory transfer */
  443. memcpy_toio(base + ((start_page - ei_status.tx_start_page) << 8),
  444. buf, count);
  445. outb(EGACFR_NORM, E33G_GACFR); /* Back to bank1 in case on bank0 */
  446. return;
  447. }
  448. /*
  449. * No shared memory, put the packet out the other way.
  450. * Set up then start the internal memory transfer to Tx Start Page
  451. */
  452. word = (unsigned short)start_page;
  453. outb(word&0xFF, E33G_DMAAH);
  454. outb(word>>8, E33G_DMAAL);
  455. outb_p((ei_status.interface_num ? ECNTRL_AUI : ECNTRL_THIN ) | ECNTRL_OUTPUT
  456. | ECNTRL_START, E33G_CNTRL);
  457. /*
  458. * Here I am going to write data to the FIFO as quickly as possible.
  459. * Note that E33G_FIFOH is defined incorrectly. It is really
  460. * E33G_FIFOL, the lowest port address for both the byte and
  461. * word write. Variable 'count' is NOT checked. Caller must supply a
  462. * valid count. Note that I may write a harmless extra byte to the
  463. * 8390 if the byte-count was not even.
  464. */
  465. wrd = (unsigned short int *) buf;
  466. count = (count + 1) >> 1;
  467. for(;;)
  468. {
  469. boguscount = 0x1000;
  470. while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0)
  471. {
  472. if(!boguscount--)
  473. {
  474. pr_notice("%s: FIFO blocked in el2_block_output.\n", dev->name);
  475. el2_reset_8390(dev);
  476. goto blocked;
  477. }
  478. }
  479. if(count > WRD_COUNT)
  480. {
  481. outsw(E33G_FIFOH, wrd, WRD_COUNT);
  482. wrd += WRD_COUNT;
  483. count -= WRD_COUNT;
  484. }
  485. else
  486. {
  487. outsw(E33G_FIFOH, wrd, count);
  488. break;
  489. }
  490. }
  491. blocked:;
  492. outb_p(ei_status.interface_num==0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
  493. }
  494. /* Read the 4 byte, page aligned 8390 specific header. */
  495. static void
  496. el2_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
  497. {
  498. int boguscount;
  499. void __iomem *base = ei_status.mem;
  500. unsigned short word;
  501. if (base) { /* Use the shared memory. */
  502. void __iomem *hdr_start = base + ((ring_page - EL2_MB1_START_PG)<<8);
  503. memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
  504. hdr->count = le16_to_cpu(hdr->count);
  505. return;
  506. }
  507. /*
  508. * No shared memory, use programmed I/O.
  509. */
  510. word = (unsigned short)ring_page;
  511. outb(word&0xFF, E33G_DMAAH);
  512. outb(word>>8, E33G_DMAAL);
  513. outb_p((ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI) | ECNTRL_INPUT
  514. | ECNTRL_START, E33G_CNTRL);
  515. boguscount = 0x1000;
  516. while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0)
  517. {
  518. if(!boguscount--)
  519. {
  520. pr_notice("%s: FIFO blocked in el2_get_8390_hdr.\n", dev->name);
  521. memset(hdr, 0x00, sizeof(struct e8390_pkt_hdr));
  522. el2_reset_8390(dev);
  523. goto blocked;
  524. }
  525. }
  526. insw(E33G_FIFOH, hdr, (sizeof(struct e8390_pkt_hdr))>> 1);
  527. blocked:;
  528. outb_p(ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
  529. }
  530. static void
  531. el2_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
  532. {
  533. int boguscount = 0;
  534. void __iomem *base = ei_status.mem;
  535. unsigned short int *buf;
  536. unsigned short word;
  537. /* Maybe enable shared memory just be to be safe... nahh.*/
  538. if (base) { /* Use the shared memory. */
  539. ring_offset -= (EL2_MB1_START_PG<<8);
  540. if (ring_offset + count > EL2_MEMSIZE) {
  541. /* We must wrap the input move. */
  542. int semi_count = EL2_MEMSIZE - ring_offset;
  543. memcpy_fromio(skb->data, base + ring_offset, semi_count);
  544. count -= semi_count;
  545. memcpy_fromio(skb->data + semi_count, base + ei_status.priv, count);
  546. } else {
  547. memcpy_fromio(skb->data, base + ring_offset, count);
  548. }
  549. return;
  550. }
  551. /*
  552. * No shared memory, use programmed I/O.
  553. */
  554. word = (unsigned short) ring_offset;
  555. outb(word>>8, E33G_DMAAH);
  556. outb(word&0xFF, E33G_DMAAL);
  557. outb_p((ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI) | ECNTRL_INPUT
  558. | ECNTRL_START, E33G_CNTRL);
  559. /*
  560. * Here I also try to get data as fast as possible. I am betting that I
  561. * can read one extra byte without clobbering anything in the kernel because
  562. * this would only occur on an odd byte-count and allocation of skb->data
  563. * is word-aligned. Variable 'count' is NOT checked. Caller must check
  564. * for a valid count.
  565. * [This is currently quite safe.... but if one day the 3c503 explodes
  566. * you know where to come looking ;)]
  567. */
  568. buf = (unsigned short int *) skb->data;
  569. count = (count + 1) >> 1;
  570. for(;;)
  571. {
  572. boguscount = 0x1000;
  573. while ((inb(E33G_STATUS) & ESTAT_DPRDY) == 0)
  574. {
  575. if(!boguscount--)
  576. {
  577. pr_notice("%s: FIFO blocked in el2_block_input.\n", dev->name);
  578. el2_reset_8390(dev);
  579. goto blocked;
  580. }
  581. }
  582. if(count > WRD_COUNT)
  583. {
  584. insw(E33G_FIFOH, buf, WRD_COUNT);
  585. buf += WRD_COUNT;
  586. count -= WRD_COUNT;
  587. }
  588. else
  589. {
  590. insw(E33G_FIFOH, buf, count);
  591. break;
  592. }
  593. }
  594. blocked:;
  595. outb_p(ei_status.interface_num == 0 ? ECNTRL_THIN : ECNTRL_AUI, E33G_CNTRL);
  596. }
  597. static void netdev_get_drvinfo(struct net_device *dev,
  598. struct ethtool_drvinfo *info)
  599. {
  600. strcpy(info->driver, DRV_NAME);
  601. strcpy(info->version, DRV_VERSION);
  602. sprintf(info->bus_info, "ISA 0x%lx", dev->base_addr);
  603. }
  604. static const struct ethtool_ops netdev_ethtool_ops = {
  605. .get_drvinfo = netdev_get_drvinfo,
  606. };
  607. #ifdef MODULE
  608. #define MAX_EL2_CARDS 4 /* Max number of EL2 cards per module */
  609. static struct net_device *dev_el2[MAX_EL2_CARDS];
  610. static int io[MAX_EL2_CARDS];
  611. static int irq[MAX_EL2_CARDS];
  612. static int xcvr[MAX_EL2_CARDS]; /* choose int. or ext. xcvr */
  613. module_param_array(io, int, NULL, 0);
  614. module_param_array(irq, int, NULL, 0);
  615. module_param_array(xcvr, int, NULL, 0);
  616. MODULE_PARM_DESC(io, "I/O base address(es)");
  617. MODULE_PARM_DESC(irq, "IRQ number(s) (assigned)");
  618. MODULE_PARM_DESC(xcvr, "transceiver(s) (0=internal, 1=external)");
  619. MODULE_DESCRIPTION("3Com ISA EtherLink II, II/16 (3c503, 3c503/16) driver");
  620. MODULE_LICENSE("GPL");
  621. /* This is set up so that only a single autoprobe takes place per call.
  622. ISA device autoprobes on a running machine are not recommended. */
  623. int __init
  624. init_module(void)
  625. {
  626. struct net_device *dev;
  627. int this_dev, found = 0;
  628. for (this_dev = 0; this_dev < MAX_EL2_CARDS; this_dev++) {
  629. if (io[this_dev] == 0) {
  630. if (this_dev != 0) break; /* only autoprobe 1st one */
  631. pr_notice("3c503.c: Presently autoprobing (not recommended) for a single card.\n");
  632. }
  633. dev = alloc_eip_netdev();
  634. if (!dev)
  635. break;
  636. dev->irq = irq[this_dev];
  637. dev->base_addr = io[this_dev];
  638. dev->mem_end = xcvr[this_dev]; /* low 4bits = xcvr sel. */
  639. if (do_el2_probe(dev) == 0) {
  640. dev_el2[found++] = dev;
  641. continue;
  642. }
  643. free_netdev(dev);
  644. pr_warning("3c503.c: No 3c503 card found (i/o = 0x%x).\n", io[this_dev]);
  645. break;
  646. }
  647. if (found)
  648. return 0;
  649. return -ENXIO;
  650. }
  651. static void cleanup_card(struct net_device *dev)
  652. {
  653. /* NB: el2_close() handles free_irq */
  654. release_region(dev->base_addr, EL2_IO_EXTENT);
  655. if (ei_status.mem)
  656. iounmap(ei_status.mem);
  657. }
  658. void __exit
  659. cleanup_module(void)
  660. {
  661. int this_dev;
  662. for (this_dev = 0; this_dev < MAX_EL2_CARDS; this_dev++) {
  663. struct net_device *dev = dev_el2[this_dev];
  664. if (dev) {
  665. unregister_netdev(dev);
  666. cleanup_card(dev);
  667. free_netdev(dev);
  668. }
  669. }
  670. }
  671. #endif /* MODULE */