ne2.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. /* ne2.c: A NE/2 Ethernet Driver for Linux. */
  2. /*
  3. Based on the NE2000 driver written by Donald Becker (1992-94).
  4. modified by Wim Dumon (Apr 1996)
  5. This software may be used and distributed according to the terms
  6. of the GNU General Public License, incorporated herein by reference.
  7. The author may be reached as wimpie@linux.cc.kuleuven.ac.be
  8. Currently supported: NE/2
  9. This patch was never tested on other MCA-ethernet adapters, but it
  10. might work. Just give it a try and let me know if you have problems.
  11. Also mail me if it really works, please!
  12. Changelog:
  13. Mon Feb 3 16:26:02 MET 1997
  14. - adapted the driver to work with the 2.1.25 kernel
  15. - multiple ne2 support (untested)
  16. - module support (untested)
  17. Fri Aug 28 00:18:36 CET 1998 (David Weinehall)
  18. - fixed a few minor typos
  19. - made the MODULE_PARM conditional (it only works with the v2.1.x kernels)
  20. - fixed the module support (Now it's working...)
  21. Mon Sep 7 19:01:44 CET 1998 (David Weinehall)
  22. - added support for Arco Electronics AE/2-card (experimental)
  23. Mon Sep 14 09:53:42 CET 1998 (David Weinehall)
  24. - added support for Compex ENET-16MC/P (experimental)
  25. Tue Sep 15 16:21:12 CET 1998 (David Weinehall, Magnus Jonsson, Tomas Ogren)
  26. - Miscellaneous bugfixes
  27. Tue Sep 19 16:21:12 CET 1998 (Magnus Jonsson)
  28. - Cleanup
  29. Wed Sep 23 14:33:34 CET 1998 (David Weinehall)
  30. - Restructuring and rewriting for v2.1.x compliance
  31. Wed Oct 14 17:19:21 CET 1998 (David Weinehall)
  32. - Added code that unregisters irq and proc-info
  33. - Version# bump
  34. Mon Nov 16 15:28:23 CET 1998 (Wim Dumon)
  35. - pass 'dev' as last parameter of request_irq in stead of 'NULL'
  36. Wed Feb 7 21:24:00 CET 2001 (Alfred Arnold)
  37. - added support for the D-Link DE-320CT
  38. * WARNING
  39. -------
  40. This is alpha-test software. It is not guaranteed to work. As a
  41. matter of fact, I'm quite sure there are *LOTS* of bugs in here. I
  42. would like to hear from you if you use this driver, even if it works.
  43. If it doesn't work, be sure to send me a mail with the problems !
  44. */
  45. static const char *version = "ne2.c:v0.91 Nov 16 1998 Wim Dumon <wimpie@kotnet.org>\n";
  46. #include <linux/module.h>
  47. #include <linux/kernel.h>
  48. #include <linux/types.h>
  49. #include <linux/fcntl.h>
  50. #include <linux/interrupt.h>
  51. #include <linux/ioport.h>
  52. #include <linux/in.h>
  53. #include <linux/string.h>
  54. #include <linux/errno.h>
  55. #include <linux/init.h>
  56. #include <linux/mca-legacy.h>
  57. #include <linux/netdevice.h>
  58. #include <linux/etherdevice.h>
  59. #include <linux/skbuff.h>
  60. #include <linux/bitops.h>
  61. #include <linux/jiffies.h>
  62. #include <asm/system.h>
  63. #include <asm/io.h>
  64. #include <asm/dma.h>
  65. #include "8390.h"
  66. #define DRV_NAME "ne2"
  67. /* Some defines that people can play with if so inclined. */
  68. /* Do we perform extra sanity checks on stuff ? */
  69. /* #define NE_SANITY_CHECK */
  70. /* Do we implement the read before write bugfix ? */
  71. /* #define NE_RW_BUGFIX */
  72. /* Do we have a non std. amount of memory? (in units of 256 byte pages) */
  73. /* #define PACKETBUF_MEMSIZE 0x40 */
  74. /* ---- No user-serviceable parts below ---- */
  75. #define NE_BASE (dev->base_addr)
  76. #define NE_CMD 0x00
  77. #define NE_DATAPORT 0x10 /* NatSemi-defined port window offset. */
  78. #define NE_RESET 0x20 /* Issue a read to reset, a write to clear. */
  79. #define NE_IO_EXTENT 0x30
  80. #define NE1SM_START_PG 0x20 /* First page of TX buffer */
  81. #define NE1SM_STOP_PG 0x40 /* Last page +1 of RX ring */
  82. #define NESM_START_PG 0x40 /* First page of TX buffer */
  83. #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */
  84. /* From the .ADF file: */
  85. static unsigned int addresses[7] __initdata =
  86. {0x1000, 0x2020, 0x8020, 0xa0a0, 0xb0b0, 0xc0c0, 0xc3d0};
  87. static int irqs[4] __initdata = {3, 4, 5, 9};
  88. /* From the D-Link ADF file: */
  89. static unsigned int dlink_addresses[4] __initdata =
  90. {0x300, 0x320, 0x340, 0x360};
  91. static int dlink_irqs[8] __initdata = {3, 4, 5, 9, 10, 11, 14, 15};
  92. struct ne2_adapters_t {
  93. unsigned int id;
  94. char *name;
  95. };
  96. static struct ne2_adapters_t ne2_adapters[] __initdata = {
  97. { 0x6354, "Arco Ethernet Adapter AE/2" },
  98. { 0x70DE, "Compex ENET-16 MC/P" },
  99. { 0x7154, "Novell Ethernet Adapter NE/2" },
  100. { 0x56ea, "D-Link DE-320CT" },
  101. { 0x0000, NULL }
  102. };
  103. extern int netcard_probe(struct net_device *dev);
  104. static int ne2_probe1(struct net_device *dev, int slot);
  105. static void ne_reset_8390(struct net_device *dev);
  106. static void ne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
  107. int ring_page);
  108. static void ne_block_input(struct net_device *dev, int count,
  109. struct sk_buff *skb, int ring_offset);
  110. static void ne_block_output(struct net_device *dev, const int count,
  111. const unsigned char *buf, const int start_page);
  112. /*
  113. * special code to read the DE-320's MAC address EEPROM. In contrast to a
  114. * standard NE design, this is a serial EEPROM (93C46) that has to be read
  115. * bit by bit. The EEPROM cotrol port at base + 0x1e has the following
  116. * layout:
  117. *
  118. * Bit 0 = Data out (read from EEPROM)
  119. * Bit 1 = Data in (write to EEPROM)
  120. * Bit 2 = Clock
  121. * Bit 3 = Chip Select
  122. * Bit 7 = ~50 kHz clock for defined delays
  123. *
  124. */
  125. static void __init dlink_put_eeprom(unsigned char value, unsigned int addr)
  126. {
  127. int z;
  128. unsigned char v1, v2;
  129. /* write the value to the NIC EEPROM register */
  130. outb(value, addr + 0x1e);
  131. /* now wait the clock line to toggle twice. Effectively, we are
  132. waiting (at least) for one clock cycle */
  133. for (z = 0; z < 2; z++) {
  134. do {
  135. v1 = inb(addr + 0x1e);
  136. v2 = inb(addr + 0x1e);
  137. }
  138. while (!((v1 ^ v2) & 0x80));
  139. }
  140. }
  141. static void __init dlink_send_eeprom_bit(unsigned int bit, unsigned int addr)
  142. {
  143. /* shift data bit into correct position */
  144. bit = bit << 1;
  145. /* write value, keep clock line high for two cycles */
  146. dlink_put_eeprom(0x09 | bit, addr);
  147. dlink_put_eeprom(0x0d | bit, addr);
  148. dlink_put_eeprom(0x0d | bit, addr);
  149. dlink_put_eeprom(0x09 | bit, addr);
  150. }
  151. static void __init dlink_send_eeprom_word(unsigned int value, unsigned int len, unsigned int addr)
  152. {
  153. int z;
  154. /* adjust bits so that they are left-aligned in a 16-bit-word */
  155. value = value << (16 - len);
  156. /* shift bits out to the EEPROM */
  157. for (z = 0; z < len; z++) {
  158. dlink_send_eeprom_bit((value & 0x8000) >> 15, addr);
  159. value = value << 1;
  160. }
  161. }
  162. static unsigned int __init dlink_get_eeprom(unsigned int eeaddr, unsigned int addr)
  163. {
  164. int z;
  165. unsigned int value = 0;
  166. /* pull the CS line low for a moment. This resets the EEPROM-
  167. internal logic, and makes it ready for a new command. */
  168. dlink_put_eeprom(0x01, addr);
  169. dlink_put_eeprom(0x09, addr);
  170. /* send one start bit, read command (1 - 0), plus the address to
  171. the EEPROM */
  172. dlink_send_eeprom_word(0x0180 | (eeaddr & 0x3f), 9, addr);
  173. /* get the data word. We clock by sending 0s to the EEPROM, which
  174. get ignored during the read process */
  175. for (z = 0; z < 16; z++) {
  176. dlink_send_eeprom_bit(0, addr);
  177. value = (value << 1) | (inb(addr + 0x1e) & 0x01);
  178. }
  179. return value;
  180. }
  181. /*
  182. * Note that at boot, this probe only picks up one card at a time.
  183. */
  184. static int __init do_ne2_probe(struct net_device *dev)
  185. {
  186. static int current_mca_slot = -1;
  187. int i;
  188. int adapter_found = 0;
  189. /* Do not check any supplied i/o locations.
  190. POS registers usually don't fail :) */
  191. /* MCA cards have POS registers.
  192. Autodetecting MCA cards is extremely simple.
  193. Just search for the card. */
  194. for(i = 0; (ne2_adapters[i].name != NULL) && !adapter_found; i++) {
  195. current_mca_slot =
  196. mca_find_unused_adapter(ne2_adapters[i].id, 0);
  197. if((current_mca_slot != MCA_NOTFOUND) && !adapter_found) {
  198. int res;
  199. mca_set_adapter_name(current_mca_slot,
  200. ne2_adapters[i].name);
  201. mca_mark_as_used(current_mca_slot);
  202. res = ne2_probe1(dev, current_mca_slot);
  203. if (res)
  204. mca_mark_as_unused(current_mca_slot);
  205. return res;
  206. }
  207. }
  208. return -ENODEV;
  209. }
  210. #ifndef MODULE
  211. struct net_device * __init ne2_probe(int unit)
  212. {
  213. struct net_device *dev = alloc_eip_netdev();
  214. int err;
  215. if (!dev)
  216. return ERR_PTR(-ENOMEM);
  217. sprintf(dev->name, "eth%d", unit);
  218. netdev_boot_setup_check(dev);
  219. err = do_ne2_probe(dev);
  220. if (err)
  221. goto out;
  222. return dev;
  223. out:
  224. free_netdev(dev);
  225. return ERR_PTR(err);
  226. }
  227. #endif
  228. static int ne2_procinfo(char *buf, int slot, struct net_device *dev)
  229. {
  230. int len=0;
  231. len += sprintf(buf+len, "The NE/2 Ethernet Adapter\n" );
  232. len += sprintf(buf+len, "Driver written by Wim Dumon ");
  233. len += sprintf(buf+len, "<wimpie@kotnet.org>\n");
  234. len += sprintf(buf+len, "Modified by ");
  235. len += sprintf(buf+len, "David Weinehall <tao@acc.umu.se>\n");
  236. len += sprintf(buf+len, "and by Magnus Jonsson <bigfoot@acc.umu.se>\n");
  237. len += sprintf(buf+len, "Based on the original NE2000 drivers\n" );
  238. len += sprintf(buf+len, "Base IO: %#x\n", (unsigned int)dev->base_addr);
  239. len += sprintf(buf+len, "IRQ : %d\n", dev->irq);
  240. len += sprintf(buf+len, "HW addr : %pM\n", dev->dev_addr);
  241. return len;
  242. }
  243. static int __init ne2_probe1(struct net_device *dev, int slot)
  244. {
  245. int i, base_addr, irq, retval;
  246. unsigned char POS;
  247. unsigned char SA_prom[32];
  248. const char *name = "NE/2";
  249. int start_page, stop_page;
  250. static unsigned version_printed;
  251. if (ei_debug && version_printed++ == 0)
  252. printk(version);
  253. printk("NE/2 ethercard found in slot %d:", slot);
  254. /* Read base IO and IRQ from the POS-registers */
  255. POS = mca_read_stored_pos(slot, 2);
  256. if(!(POS % 2)) {
  257. printk(" disabled.\n");
  258. return -ENODEV;
  259. }
  260. /* handle different POS register structure for D-Link card */
  261. if (mca_read_stored_pos(slot, 0) == 0xea) {
  262. base_addr = dlink_addresses[(POS >> 5) & 0x03];
  263. irq = dlink_irqs[(POS >> 2) & 0x07];
  264. }
  265. else {
  266. i = (POS & 0xE)>>1;
  267. /* printk("Halleluja sdog, als er na de pijl een 1 staat is 1 - 1 == 0"
  268. " en zou het moeten werken -> %d\n", i);
  269. The above line was for remote testing, thanx to sdog ... */
  270. base_addr = addresses[i - 1];
  271. irq = irqs[(POS & 0x60)>>5];
  272. }
  273. if (!request_region(base_addr, NE_IO_EXTENT, DRV_NAME))
  274. return -EBUSY;
  275. #ifdef DEBUG
  276. printk("POS info : pos 2 = %#x ; base = %#x ; irq = %ld\n", POS,
  277. base_addr, irq);
  278. #endif
  279. #ifndef CRYNWR_WAY
  280. /* Reset the card the way they do it in the Crynwr packet driver */
  281. for (i=0; i<8; i++)
  282. outb(0x0, base_addr + NE_RESET);
  283. inb(base_addr + NE_RESET);
  284. outb(0x21, base_addr + NE_CMD);
  285. if (inb(base_addr + NE_CMD) != 0x21) {
  286. printk("NE/2 adapter not responding\n");
  287. retval = -ENODEV;
  288. goto out;
  289. }
  290. /* In the crynwr sources they do a RAM-test here. I skip it. I suppose
  291. my RAM is okay. Suppose your memory is broken. Then this test
  292. should fail and you won't be able to use your card. But if I do not
  293. test, you won't be able to use your card, neither. So this test
  294. won't help you. */
  295. #else /* _I_ never tested it this way .. Go ahead and try ...*/
  296. /* Reset card. Who knows what dain-bramaged state it was left in. */
  297. {
  298. unsigned long reset_start_time = jiffies;
  299. /* DON'T change these to inb_p/outb_p or reset will fail on
  300. clones.. */
  301. outb(inb(base_addr + NE_RESET), base_addr + NE_RESET);
  302. while ((inb_p(base_addr + EN0_ISR) & ENISR_RESET) == 0)
  303. if (time_after(jiffies, reset_start_time + 2*HZ/100)) {
  304. printk(" not found (no reset ack).\n");
  305. retval = -ENODEV;
  306. goto out;
  307. }
  308. outb_p(0xff, base_addr + EN0_ISR); /* Ack all intr. */
  309. }
  310. #endif
  311. /* Read the 16 bytes of station address PROM.
  312. We must first initialize registers, similar to
  313. NS8390p_init(eifdev, 0).
  314. We can't reliably read the SAPROM address without this.
  315. (I learned the hard way!). */
  316. {
  317. struct {
  318. unsigned char value, offset;
  319. } program_seq[] = {
  320. /* Select page 0 */
  321. {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD},
  322. {0x49, EN0_DCFG}, /* Set WORD-wide (0x49) access. */
  323. {0x00, EN0_RCNTLO}, /* Clear the count regs. */
  324. {0x00, EN0_RCNTHI},
  325. {0x00, EN0_IMR}, /* Mask completion irq. */
  326. {0xFF, EN0_ISR},
  327. {E8390_RXOFF, EN0_RXCR}, /* 0x20 Set to monitor */
  328. {E8390_TXOFF, EN0_TXCR}, /* 0x02 and loopback mode. */
  329. {32, EN0_RCNTLO},
  330. {0x00, EN0_RCNTHI},
  331. {0x00, EN0_RSARLO}, /* DMA starting at 0x0000. */
  332. {0x00, EN0_RSARHI},
  333. {E8390_RREAD+E8390_START, E8390_CMD},
  334. };
  335. for (i = 0; i < ARRAY_SIZE(program_seq); i++)
  336. outb_p(program_seq[i].value, base_addr +
  337. program_seq[i].offset);
  338. }
  339. for(i = 0; i < 6 /*sizeof(SA_prom)*/; i+=1) {
  340. SA_prom[i] = inb(base_addr + NE_DATAPORT);
  341. }
  342. /* I don't know whether the previous sequence includes the general
  343. board reset procedure, so better don't omit it and just overwrite
  344. the garbage read from a DE-320 with correct stuff. */
  345. if (mca_read_stored_pos(slot, 0) == 0xea) {
  346. unsigned int v;
  347. for (i = 0; i < 3; i++) {
  348. v = dlink_get_eeprom(i, base_addr);
  349. SA_prom[(i << 1) ] = v & 0xff;
  350. SA_prom[(i << 1) + 1] = (v >> 8) & 0xff;
  351. }
  352. }
  353. start_page = NESM_START_PG;
  354. stop_page = NESM_STOP_PG;
  355. dev->irq=irq;
  356. /* Snarf the interrupt now. There's no point in waiting since we cannot
  357. share and the board will usually be enabled. */
  358. retval = request_irq(dev->irq, eip_interrupt, 0, DRV_NAME, dev);
  359. if (retval) {
  360. printk (" unable to get IRQ %d (irqval=%d).\n",
  361. dev->irq, retval);
  362. goto out;
  363. }
  364. dev->base_addr = base_addr;
  365. for(i = 0; i < ETHER_ADDR_LEN; i++)
  366. dev->dev_addr[i] = SA_prom[i];
  367. printk(" %pM\n", dev->dev_addr);
  368. printk("%s: %s found at %#x, using IRQ %d.\n",
  369. dev->name, name, base_addr, dev->irq);
  370. mca_set_adapter_procfn(slot, (MCA_ProcFn) ne2_procinfo, dev);
  371. ei_status.name = name;
  372. ei_status.tx_start_page = start_page;
  373. ei_status.stop_page = stop_page;
  374. ei_status.word16 = (2 == 2);
  375. ei_status.rx_start_page = start_page + TX_PAGES;
  376. #ifdef PACKETBUF_MEMSIZE
  377. /* Allow the packet buffer size to be overridden by know-it-alls. */
  378. ei_status.stop_page = ei_status.tx_start_page + PACKETBUF_MEMSIZE;
  379. #endif
  380. ei_status.reset_8390 = &ne_reset_8390;
  381. ei_status.block_input = &ne_block_input;
  382. ei_status.block_output = &ne_block_output;
  383. ei_status.get_8390_hdr = &ne_get_8390_hdr;
  384. ei_status.priv = slot;
  385. dev->netdev_ops = &eip_netdev_ops;
  386. NS8390p_init(dev, 0);
  387. retval = register_netdev(dev);
  388. if (retval)
  389. goto out1;
  390. return 0;
  391. out1:
  392. mca_set_adapter_procfn( ei_status.priv, NULL, NULL);
  393. free_irq(dev->irq, dev);
  394. out:
  395. release_region(base_addr, NE_IO_EXTENT);
  396. return retval;
  397. }
  398. /* Hard reset the card. This used to pause for the same period that a
  399. 8390 reset command required, but that shouldn't be necessary. */
  400. static void ne_reset_8390(struct net_device *dev)
  401. {
  402. unsigned long reset_start_time = jiffies;
  403. if (ei_debug > 1)
  404. printk("resetting the 8390 t=%ld...", jiffies);
  405. /* DON'T change these to inb_p/outb_p or reset will fail on clones. */
  406. outb(inb(NE_BASE + NE_RESET), NE_BASE + NE_RESET);
  407. ei_status.txing = 0;
  408. ei_status.dmaing = 0;
  409. /* This check _should_not_ be necessary, omit eventually. */
  410. while ((inb_p(NE_BASE+EN0_ISR) & ENISR_RESET) == 0)
  411. if (time_after(jiffies, reset_start_time + 2*HZ/100)) {
  412. printk("%s: ne_reset_8390() did not complete.\n",
  413. dev->name);
  414. break;
  415. }
  416. outb_p(ENISR_RESET, NE_BASE + EN0_ISR); /* Ack intr. */
  417. }
  418. /* Grab the 8390 specific header. Similar to the block_input routine, but
  419. we don't need to be concerned with ring wrap as the header will be at
  420. the start of a page, so we optimize accordingly. */
  421. static void ne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
  422. int ring_page)
  423. {
  424. int nic_base = dev->base_addr;
  425. /* This *shouldn't* happen.
  426. If it does, it's the last thing you'll see */
  427. if (ei_status.dmaing) {
  428. printk("%s: DMAing conflict in ne_get_8390_hdr "
  429. "[DMAstat:%d][irqlock:%d].\n",
  430. dev->name, ei_status.dmaing, ei_status.irqlock);
  431. return;
  432. }
  433. ei_status.dmaing |= 0x01;
  434. outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
  435. outb_p(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO);
  436. outb_p(0, nic_base + EN0_RCNTHI);
  437. outb_p(0, nic_base + EN0_RSARLO); /* On page boundary */
  438. outb_p(ring_page, nic_base + EN0_RSARHI);
  439. outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
  440. if (ei_status.word16)
  441. insw(NE_BASE + NE_DATAPORT, hdr,
  442. sizeof(struct e8390_pkt_hdr)>>1);
  443. else
  444. insb(NE_BASE + NE_DATAPORT, hdr,
  445. sizeof(struct e8390_pkt_hdr));
  446. outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
  447. ei_status.dmaing &= ~0x01;
  448. }
  449. /* Block input and output, similar to the Crynwr packet driver. If you
  450. are porting to a new ethercard, look at the packet driver source for
  451. hints. The NEx000 doesn't share the on-board packet memory -- you have
  452. to put the packet out through the "remote DMA" dataport using outb. */
  453. static void ne_block_input(struct net_device *dev, int count, struct sk_buff *skb,
  454. int ring_offset)
  455. {
  456. #ifdef NE_SANITY_CHECK
  457. int xfer_count = count;
  458. #endif
  459. int nic_base = dev->base_addr;
  460. char *buf = skb->data;
  461. /* This *shouldn't* happen.
  462. If it does, it's the last thing you'll see */
  463. if (ei_status.dmaing) {
  464. printk("%s: DMAing conflict in ne_block_input "
  465. "[DMAstat:%d][irqlock:%d].\n",
  466. dev->name, ei_status.dmaing, ei_status.irqlock);
  467. return;
  468. }
  469. ei_status.dmaing |= 0x01;
  470. outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
  471. outb_p(count & 0xff, nic_base + EN0_RCNTLO);
  472. outb_p(count >> 8, nic_base + EN0_RCNTHI);
  473. outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
  474. outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
  475. outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
  476. if (ei_status.word16) {
  477. insw(NE_BASE + NE_DATAPORT,buf,count>>1);
  478. if (count & 0x01) {
  479. buf[count-1] = inb(NE_BASE + NE_DATAPORT);
  480. #ifdef NE_SANITY_CHECK
  481. xfer_count++;
  482. #endif
  483. }
  484. } else {
  485. insb(NE_BASE + NE_DATAPORT, buf, count);
  486. }
  487. #ifdef NE_SANITY_CHECK
  488. /* This was for the ALPHA version only, but enough people have
  489. been encountering problems so it is still here. If you see
  490. this message you either 1) have a slightly incompatible clone
  491. or 2) have noise/speed problems with your bus. */
  492. if (ei_debug > 1) { /* DMA termination address check... */
  493. int addr, tries = 20;
  494. do {
  495. /* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here
  496. -- it's broken for Rx on some cards! */
  497. int high = inb_p(nic_base + EN0_RSARHI);
  498. int low = inb_p(nic_base + EN0_RSARLO);
  499. addr = (high << 8) + low;
  500. if (((ring_offset + xfer_count) & 0xff) == low)
  501. break;
  502. } while (--tries > 0);
  503. if (tries <= 0)
  504. printk("%s: RX transfer address mismatch,"
  505. "%#4.4x (expected) vs. %#4.4x (actual).\n",
  506. dev->name, ring_offset + xfer_count, addr);
  507. }
  508. #endif
  509. outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
  510. ei_status.dmaing &= ~0x01;
  511. }
  512. static void ne_block_output(struct net_device *dev, int count,
  513. const unsigned char *buf, const int start_page)
  514. {
  515. int nic_base = NE_BASE;
  516. unsigned long dma_start;
  517. #ifdef NE_SANITY_CHECK
  518. int retries = 0;
  519. #endif
  520. /* Round the count up for word writes. Do we need to do this?
  521. What effect will an odd byte count have on the 8390?
  522. I should check someday. */
  523. if (ei_status.word16 && (count & 0x01))
  524. count++;
  525. /* This *shouldn't* happen.
  526. If it does, it's the last thing you'll see */
  527. if (ei_status.dmaing) {
  528. printk("%s: DMAing conflict in ne_block_output."
  529. "[DMAstat:%d][irqlock:%d]\n",
  530. dev->name, ei_status.dmaing, ei_status.irqlock);
  531. return;
  532. }
  533. ei_status.dmaing |= 0x01;
  534. /* We should already be in page 0, but to be safe... */
  535. outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD);
  536. #ifdef NE_SANITY_CHECK
  537. retry:
  538. #endif
  539. #ifdef NE8390_RW_BUGFIX
  540. /* Handle the read-before-write bug the same way as the
  541. Crynwr packet driver -- the NatSemi method doesn't work.
  542. Actually this doesn't always work either, but if you have
  543. problems with your NEx000 this is better than nothing! */
  544. outb_p(0x42, nic_base + EN0_RCNTLO);
  545. outb_p(0x00, nic_base + EN0_RCNTHI);
  546. outb_p(0x42, nic_base + EN0_RSARLO);
  547. outb_p(0x00, nic_base + EN0_RSARHI);
  548. outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
  549. /* Make certain that the dummy read has occurred. */
  550. SLOW_DOWN_IO;
  551. SLOW_DOWN_IO;
  552. SLOW_DOWN_IO;
  553. #endif
  554. outb_p(ENISR_RDC, nic_base + EN0_ISR);
  555. /* Now the normal output. */
  556. outb_p(count & 0xff, nic_base + EN0_RCNTLO);
  557. outb_p(count >> 8, nic_base + EN0_RCNTHI);
  558. outb_p(0x00, nic_base + EN0_RSARLO);
  559. outb_p(start_page, nic_base + EN0_RSARHI);
  560. outb_p(E8390_RWRITE+E8390_START, nic_base + NE_CMD);
  561. if (ei_status.word16) {
  562. outsw(NE_BASE + NE_DATAPORT, buf, count>>1);
  563. } else {
  564. outsb(NE_BASE + NE_DATAPORT, buf, count);
  565. }
  566. dma_start = jiffies;
  567. #ifdef NE_SANITY_CHECK
  568. /* This was for the ALPHA version only, but enough people have
  569. been encountering problems so it is still here. */
  570. if (ei_debug > 1) { /* DMA termination address check... */
  571. int addr, tries = 20;
  572. do {
  573. int high = inb_p(nic_base + EN0_RSARHI);
  574. int low = inb_p(nic_base + EN0_RSARLO);
  575. addr = (high << 8) + low;
  576. if ((start_page << 8) + count == addr)
  577. break;
  578. } while (--tries > 0);
  579. if (tries <= 0) {
  580. printk("%s: Tx packet transfer address mismatch,"
  581. "%#4.4x (expected) vs. %#4.4x (actual).\n",
  582. dev->name, (start_page << 8) + count, addr);
  583. if (retries++ == 0)
  584. goto retry;
  585. }
  586. }
  587. #endif
  588. while ((inb_p(nic_base + EN0_ISR) & ENISR_RDC) == 0)
  589. if (time_after(jiffies, dma_start + 2*HZ/100)) { /* 20ms */
  590. printk("%s: timeout waiting for Tx RDC.\n", dev->name);
  591. ne_reset_8390(dev);
  592. NS8390p_init(dev, 1);
  593. break;
  594. }
  595. outb_p(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
  596. ei_status.dmaing &= ~0x01;
  597. }
  598. #ifdef MODULE
  599. #define MAX_NE_CARDS 4 /* Max number of NE cards per module */
  600. static struct net_device *dev_ne[MAX_NE_CARDS];
  601. static int io[MAX_NE_CARDS];
  602. static int irq[MAX_NE_CARDS];
  603. static int bad[MAX_NE_CARDS]; /* 0xbad = bad sig or no reset ack */
  604. MODULE_LICENSE("GPL");
  605. module_param_array(io, int, NULL, 0);
  606. module_param_array(irq, int, NULL, 0);
  607. module_param_array(bad, int, NULL, 0);
  608. MODULE_PARM_DESC(io, "(ignored)");
  609. MODULE_PARM_DESC(irq, "(ignored)");
  610. MODULE_PARM_DESC(bad, "(ignored)");
  611. /* Module code fixed by David Weinehall */
  612. int __init init_module(void)
  613. {
  614. struct net_device *dev;
  615. int this_dev, found = 0;
  616. for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) {
  617. dev = alloc_eip_netdev();
  618. if (!dev)
  619. break;
  620. dev->irq = irq[this_dev];
  621. dev->mem_end = bad[this_dev];
  622. dev->base_addr = io[this_dev];
  623. if (do_ne2_probe(dev) == 0) {
  624. dev_ne[found++] = dev;
  625. continue;
  626. }
  627. free_netdev(dev);
  628. break;
  629. }
  630. if (found)
  631. return 0;
  632. printk(KERN_WARNING "ne2.c: No NE/2 card found\n");
  633. return -ENXIO;
  634. }
  635. static void cleanup_card(struct net_device *dev)
  636. {
  637. mca_mark_as_unused(ei_status.priv);
  638. mca_set_adapter_procfn( ei_status.priv, NULL, NULL);
  639. free_irq(dev->irq, dev);
  640. release_region(dev->base_addr, NE_IO_EXTENT);
  641. }
  642. void __exit cleanup_module(void)
  643. {
  644. int this_dev;
  645. for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) {
  646. struct net_device *dev = dev_ne[this_dev];
  647. if (dev) {
  648. unregister_netdev(dev);
  649. cleanup_card(dev);
  650. free_netdev(dev);
  651. }
  652. }
  653. }
  654. #endif /* MODULE */