ni5010.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. /* ni5010.c: A network driver for the MiCom-Interlan NI5010 ethercard.
  2. *
  3. * Copyright 1996,1997,2006 Jan-Pascal van Best and Andreas Mohr.
  4. *
  5. * This software may be used and distributed according to the terms
  6. * of the GNU General Public License, incorporated herein by reference.
  7. *
  8. * The authors may be reached as:
  9. * janpascal@vanbest.org andi@lisas.de
  10. *
  11. * Sources:
  12. * Donald Becker's "skeleton.c"
  13. * Crynwr ni5010 packet driver
  14. *
  15. * Changes:
  16. * v0.0: First test version
  17. * v0.1: First working version
  18. * v0.2:
  19. * v0.3->v0.90: Now demand setting io and irq when loading as module
  20. * 970430 v0.91: modified for Linux 2.1.14
  21. * v0.92: Implemented Andreas' (better) NI5010 probe
  22. * 970503 v0.93: Fixed auto-irq failure on warm reboot (JB)
  23. * 970623 v1.00: First kernel version (AM)
  24. * 970814 v1.01: Added detection of onboard receive buffer size (AM)
  25. * 060611 v1.02: slight cleanup: email addresses, driver modernization.
  26. * Bugs:
  27. * - not SMP-safe (no locking of I/O accesses)
  28. * - Note that you have to patch ifconfig for the new /proc/net/dev
  29. * format. It gives incorrect stats otherwise.
  30. *
  31. * To do:
  32. * Fix all bugs :-)
  33. * Move some stuff to chipset_init()
  34. * Handle xmt errors other than collisions
  35. * Complete merge with Andreas' driver
  36. * Implement ring buffers (Is this useful? You can't squeeze
  37. * too many packet in a 2k buffer!)
  38. * Implement DMA (Again, is this useful? Some docs say DMA is
  39. * slower than programmed I/O)
  40. *
  41. * Compile with:
  42. * gcc -O2 -fomit-frame-pointer -m486 -D__KERNEL__ \
  43. * -DMODULE -c ni5010.c
  44. *
  45. * Insert with e.g.:
  46. * insmod ni5010.ko io=0x300 irq=5
  47. */
  48. #include <linux/module.h>
  49. #include <linux/kernel.h>
  50. #include <linux/string.h>
  51. #include <linux/errno.h>
  52. #include <linux/ioport.h>
  53. #include <linux/interrupt.h>
  54. #include <linux/delay.h>
  55. #include <linux/init.h>
  56. #include <linux/bitops.h>
  57. #include <asm/io.h>
  58. #include <asm/dma.h>
  59. #include <linux/netdevice.h>
  60. #include <linux/etherdevice.h>
  61. #include <linux/skbuff.h>
  62. #include "ni5010.h"
  63. static const char boardname[] = "NI5010";
  64. static char version[] __initdata =
  65. "ni5010.c: v1.02 20060611 Jan-Pascal van Best and Andreas Mohr\n";
  66. /* bufsize_rcv == 0 means autoprobing */
  67. static unsigned int bufsize_rcv;
  68. #define JUMPERED_INTERRUPTS /* IRQ line jumpered on board */
  69. #undef JUMPERED_DMA /* No DMA used */
  70. #undef FULL_IODETECT /* Only detect in portlist */
  71. #ifndef FULL_IODETECT
  72. /* A zero-terminated list of I/O addresses to be probed. */
  73. static unsigned int ports[] __initdata =
  74. { 0x300, 0x320, 0x340, 0x360, 0x380, 0x3a0, 0 };
  75. #endif
  76. /* Use 0 for production, 1 for verification, >2 for debug */
  77. #ifndef NI5010_DEBUG
  78. #define NI5010_DEBUG 0
  79. #endif
  80. /* Information that needs to be kept for each board. */
  81. struct ni5010_local {
  82. int o_pkt_size;
  83. spinlock_t lock;
  84. };
  85. /* Index to functions, as function prototypes. */
  86. static int ni5010_probe1(struct net_device *dev, int ioaddr);
  87. static int ni5010_open(struct net_device *dev);
  88. static int ni5010_send_packet(struct sk_buff *skb, struct net_device *dev);
  89. static irqreturn_t ni5010_interrupt(int irq, void *dev_id);
  90. static void ni5010_rx(struct net_device *dev);
  91. static void ni5010_timeout(struct net_device *dev);
  92. static int ni5010_close(struct net_device *dev);
  93. static void ni5010_set_multicast_list(struct net_device *dev);
  94. static void reset_receiver(struct net_device *dev);
  95. static int process_xmt_interrupt(struct net_device *dev);
  96. #define tx_done(dev) 1
  97. static void hardware_send_packet(struct net_device *dev, char *buf, int length, int pad);
  98. static void chipset_init(struct net_device *dev, int startp);
  99. static void dump_packet(void *buf, int len);
  100. static void ni5010_show_registers(struct net_device *dev);
  101. static int io;
  102. static int irq;
  103. struct net_device * __init ni5010_probe(int unit)
  104. {
  105. struct net_device *dev = alloc_etherdev(sizeof(struct ni5010_local));
  106. int *port;
  107. int err = 0;
  108. if (!dev)
  109. return ERR_PTR(-ENOMEM);
  110. if (unit >= 0) {
  111. sprintf(dev->name, "eth%d", unit);
  112. netdev_boot_setup_check(dev);
  113. io = dev->base_addr;
  114. irq = dev->irq;
  115. }
  116. PRINTK2((KERN_DEBUG "%s: Entering ni5010_probe\n", dev->name));
  117. if (io > 0x1ff) { /* Check a single specified location. */
  118. err = ni5010_probe1(dev, io);
  119. } else if (io != 0) { /* Don't probe at all. */
  120. err = -ENXIO;
  121. } else {
  122. #ifdef FULL_IODETECT
  123. for (io=0x200; io<0x400 && ni5010_probe1(dev, io) ; io+=0x20)
  124. ;
  125. if (io == 0x400)
  126. err = -ENODEV;
  127. #else
  128. for (port = ports; *port && ni5010_probe1(dev, *port); port++)
  129. ;
  130. if (!*port)
  131. err = -ENODEV;
  132. #endif /* FULL_IODETECT */
  133. }
  134. if (err)
  135. goto out;
  136. err = register_netdev(dev);
  137. if (err)
  138. goto out1;
  139. return dev;
  140. out1:
  141. release_region(dev->base_addr, NI5010_IO_EXTENT);
  142. out:
  143. free_netdev(dev);
  144. return ERR_PTR(err);
  145. }
  146. static inline int rd_port(int ioaddr)
  147. {
  148. inb(IE_RBUF);
  149. return inb(IE_SAPROM);
  150. }
  151. static void __init trigger_irq(int ioaddr)
  152. {
  153. outb(0x00, EDLC_RESET); /* Clear EDLC hold RESET state */
  154. outb(0x00, IE_RESET); /* Board reset */
  155. outb(0x00, EDLC_XMASK); /* Disable all Xmt interrupts */
  156. outb(0x00, EDLC_RMASK); /* Disable all Rcv interrupt */
  157. outb(0xff, EDLC_XCLR); /* Clear all pending Xmt interrupts */
  158. outb(0xff, EDLC_RCLR); /* Clear all pending Rcv interrupts */
  159. /*
  160. * Transmit packet mode: Ignore parity, Power xcvr,
  161. * Enable loopback
  162. */
  163. outb(XMD_IG_PAR | XMD_T_MODE | XMD_LBC, EDLC_XMODE);
  164. outb(RMD_BROADCAST, EDLC_RMODE); /* Receive normal&broadcast */
  165. outb(XM_ALL, EDLC_XMASK); /* Enable all Xmt interrupts */
  166. udelay(50); /* FIXME: Necessary? */
  167. outb(MM_EN_XMT|MM_MUX, IE_MMODE); /* Start transmission */
  168. }
  169. static const struct net_device_ops ni5010_netdev_ops = {
  170. .ndo_open = ni5010_open,
  171. .ndo_stop = ni5010_close,
  172. .ndo_start_xmit = ni5010_send_packet,
  173. .ndo_set_multicast_list = ni5010_set_multicast_list,
  174. .ndo_tx_timeout = ni5010_timeout,
  175. .ndo_validate_addr = eth_validate_addr,
  176. .ndo_set_mac_address = eth_mac_addr,
  177. .ndo_change_mtu = eth_change_mtu,
  178. };
  179. /*
  180. * This is the real probe routine. Linux has a history of friendly device
  181. * probes on the ISA bus. A good device probes avoids doing writes, and
  182. * verifies that the correct device exists and functions.
  183. */
  184. static int __init ni5010_probe1(struct net_device *dev, int ioaddr)
  185. {
  186. static unsigned version_printed;
  187. struct ni5010_local *lp;
  188. int i;
  189. unsigned int data = 0;
  190. int boguscount = 40;
  191. int err = -ENODEV;
  192. dev->base_addr = ioaddr;
  193. dev->irq = irq;
  194. if (!request_region(ioaddr, NI5010_IO_EXTENT, boardname))
  195. return -EBUSY;
  196. /*
  197. * This is no "official" probe method, I've rather tested which
  198. * probe works best with my seven NI5010 cards
  199. * (they have very different serial numbers)
  200. * Suggestions or failure reports are very, very welcome !
  201. * But I think it is a relatively good probe method
  202. * since it doesn't use any "outb"
  203. * It should be nearly 100% reliable !
  204. * well-known WARNING: this probe method (like many others)
  205. * will hang the system if a NE2000 card region is probed !
  206. *
  207. * - Andreas
  208. */
  209. PRINTK2((KERN_DEBUG "%s: entering ni5010_probe1(%#3x)\n",
  210. dev->name, ioaddr));
  211. if (inb(ioaddr+0) == 0xff)
  212. goto out;
  213. while ( (rd_port(ioaddr) & rd_port(ioaddr) & rd_port(ioaddr) &
  214. rd_port(ioaddr) & rd_port(ioaddr) & rd_port(ioaddr)) != 0xff)
  215. {
  216. if (boguscount-- == 0)
  217. goto out;
  218. }
  219. PRINTK2((KERN_DEBUG "%s: I/O #1 passed!\n", dev->name));
  220. for (i=0; i<32; i++)
  221. if ( (data = rd_port(ioaddr)) != 0xff) break;
  222. if (data==0xff)
  223. goto out;
  224. PRINTK2((KERN_DEBUG "%s: I/O #2 passed!\n", dev->name));
  225. if ((data != SA_ADDR0) || (rd_port(ioaddr) != SA_ADDR1) ||
  226. (rd_port(ioaddr) != SA_ADDR2))
  227. goto out;
  228. for (i=0; i<4; i++)
  229. rd_port(ioaddr);
  230. if ( (rd_port(ioaddr) != NI5010_MAGICVAL1) ||
  231. (rd_port(ioaddr) != NI5010_MAGICVAL2) )
  232. goto out;
  233. PRINTK2((KERN_DEBUG "%s: I/O #3 passed!\n", dev->name));
  234. if (NI5010_DEBUG && version_printed++ == 0)
  235. printk(KERN_INFO "%s", version);
  236. printk("NI5010 ethercard probe at 0x%x: ", ioaddr);
  237. dev->base_addr = ioaddr;
  238. for (i=0; i<6; i++) {
  239. outw(i, IE_GP);
  240. dev->dev_addr[i] = inb(IE_SAPROM);
  241. }
  242. printk("%pM ", dev->dev_addr);
  243. PRINTK2((KERN_DEBUG "%s: I/O #4 passed!\n", dev->name));
  244. #ifdef JUMPERED_INTERRUPTS
  245. if (dev->irq == 0xff)
  246. ;
  247. else if (dev->irq < 2) {
  248. unsigned long irq_mask;
  249. PRINTK2((KERN_DEBUG "%s: I/O #5 passed!\n", dev->name));
  250. irq_mask = probe_irq_on();
  251. trigger_irq(ioaddr);
  252. mdelay(20);
  253. dev->irq = probe_irq_off(irq_mask);
  254. PRINTK2((KERN_DEBUG "%s: I/O #6 passed!\n", dev->name));
  255. if (dev->irq == 0) {
  256. err = -EAGAIN;
  257. printk(KERN_WARNING "%s: no IRQ found!\n", dev->name);
  258. goto out;
  259. }
  260. PRINTK2((KERN_DEBUG "%s: I/O #7 passed!\n", dev->name));
  261. } else if (dev->irq == 2) {
  262. dev->irq = 9;
  263. }
  264. #endif /* JUMPERED_INTERRUPTS */
  265. PRINTK2((KERN_DEBUG "%s: I/O #9 passed!\n", dev->name));
  266. /* DMA is not supported (yet?), so no use detecting it */
  267. lp = netdev_priv(dev);
  268. spin_lock_init(&lp->lock);
  269. PRINTK2((KERN_DEBUG "%s: I/O #10 passed!\n", dev->name));
  270. /* get the size of the onboard receive buffer
  271. * higher addresses than bufsize are wrapped into real buffer
  272. * i.e. data for offs. 0x801 is written to 0x1 with a 2K onboard buffer
  273. */
  274. if (!bufsize_rcv) {
  275. outb(1, IE_MMODE); /* Put Rcv buffer on system bus */
  276. outw(0, IE_GP); /* Point GP at start of packet */
  277. outb(0, IE_RBUF); /* set buffer byte 0 to 0 */
  278. for (i = 1; i < 0xff; i++) {
  279. outw(i << 8, IE_GP); /* Point GP at packet size to be tested */
  280. outb(i, IE_RBUF);
  281. outw(0x0, IE_GP); /* Point GP at start of packet */
  282. data = inb(IE_RBUF);
  283. if (data == i) break;
  284. }
  285. bufsize_rcv = i << 8;
  286. outw(0, IE_GP); /* Point GP at start of packet */
  287. outb(0, IE_RBUF); /* set buffer byte 0 to 0 again */
  288. }
  289. printk("-> bufsize rcv/xmt=%d/%d\n", bufsize_rcv, NI5010_BUFSIZE);
  290. dev->netdev_ops = &ni5010_netdev_ops;
  291. dev->watchdog_timeo = HZ/20;
  292. dev->flags &= ~IFF_MULTICAST; /* Multicast doesn't work */
  293. /* Shut up the ni5010 */
  294. outb(0, EDLC_RMASK); /* Mask all receive interrupts */
  295. outb(0, EDLC_XMASK); /* Mask all xmit interrupts */
  296. outb(0xff, EDLC_RCLR); /* Kill all pending rcv interrupts */
  297. outb(0xff, EDLC_XCLR); /* Kill all pending xmt interrupts */
  298. printk(KERN_INFO "%s: NI5010 found at 0x%x, using IRQ %d", dev->name, ioaddr, dev->irq);
  299. if (dev->dma)
  300. printk(" & DMA %d", dev->dma);
  301. printk(".\n");
  302. return 0;
  303. out:
  304. release_region(dev->base_addr, NI5010_IO_EXTENT);
  305. return err;
  306. }
  307. /*
  308. * Open/initialize the board. This is called (in the current kernel)
  309. * sometime after booting when the 'ifconfig' program is run.
  310. *
  311. * This routine should set everything up anew at each open, even
  312. * registers that "should" only need to be set once at boot, so that
  313. * there is a non-reboot way to recover if something goes wrong.
  314. */
  315. static int ni5010_open(struct net_device *dev)
  316. {
  317. int ioaddr = dev->base_addr;
  318. int i;
  319. PRINTK2((KERN_DEBUG "%s: entering ni5010_open()\n", dev->name));
  320. if (request_irq(dev->irq, ni5010_interrupt, 0, boardname, dev)) {
  321. printk(KERN_WARNING "%s: Cannot get irq %#2x\n", dev->name, dev->irq);
  322. return -EAGAIN;
  323. }
  324. PRINTK3((KERN_DEBUG "%s: passed open() #1\n", dev->name));
  325. /*
  326. * Always allocate the DMA channel after the IRQ,
  327. * and clean up on failure.
  328. */
  329. #ifdef JUMPERED_DMA
  330. if (request_dma(dev->dma, cardname)) {
  331. printk(KERN_WARNING "%s: Cannot get dma %#2x\n", dev->name, dev->dma);
  332. free_irq(dev->irq, NULL);
  333. return -EAGAIN;
  334. }
  335. #endif /* JUMPERED_DMA */
  336. PRINTK3((KERN_DEBUG "%s: passed open() #2\n", dev->name));
  337. /* Reset the hardware here. Don't forget to set the station address. */
  338. outb(RS_RESET, EDLC_RESET); /* Hold up EDLC_RESET while configing board */
  339. outb(0, IE_RESET); /* Hardware reset of ni5010 board */
  340. outb(XMD_LBC, EDLC_XMODE); /* Only loopback xmits */
  341. PRINTK3((KERN_DEBUG "%s: passed open() #3\n", dev->name));
  342. /* Set the station address */
  343. for(i = 0;i < 6; i++) {
  344. outb(dev->dev_addr[i], EDLC_ADDR + i);
  345. }
  346. PRINTK3((KERN_DEBUG "%s: Initialising ni5010\n", dev->name));
  347. outb(0, EDLC_XMASK); /* No xmit interrupts for now */
  348. outb(XMD_IG_PAR | XMD_T_MODE | XMD_LBC, EDLC_XMODE);
  349. /* Normal packet xmit mode */
  350. outb(0xff, EDLC_XCLR); /* Clear all pending xmit interrupts */
  351. outb(RMD_BROADCAST, EDLC_RMODE);
  352. /* Receive broadcast and normal packets */
  353. reset_receiver(dev); /* Ready ni5010 for receiving packets */
  354. outb(0, EDLC_RESET); /* Un-reset the ni5010 */
  355. netif_start_queue(dev);
  356. if (NI5010_DEBUG) ni5010_show_registers(dev);
  357. PRINTK((KERN_DEBUG "%s: open successful\n", dev->name));
  358. return 0;
  359. }
  360. static void reset_receiver(struct net_device *dev)
  361. {
  362. int ioaddr = dev->base_addr;
  363. PRINTK3((KERN_DEBUG "%s: resetting receiver\n", dev->name));
  364. outw(0, IE_GP); /* Receive packet at start of buffer */
  365. outb(0xff, EDLC_RCLR); /* Clear all pending rcv interrupts */
  366. outb(0, IE_MMODE); /* Put EDLC to rcv buffer */
  367. outb(MM_EN_RCV, IE_MMODE); /* Enable rcv */
  368. outb(0xff, EDLC_RMASK); /* Enable all rcv interrupts */
  369. }
  370. static void ni5010_timeout(struct net_device *dev)
  371. {
  372. printk(KERN_WARNING "%s: transmit timed out, %s?\n", dev->name,
  373. tx_done(dev) ? "IRQ conflict" : "network cable problem");
  374. /* Try to restart the adaptor. */
  375. /* FIXME: Give it a real kick here */
  376. chipset_init(dev, 1);
  377. dev->trans_start = jiffies; /* prevent tx timeout */
  378. netif_wake_queue(dev);
  379. }
  380. static int ni5010_send_packet(struct sk_buff *skb, struct net_device *dev)
  381. {
  382. int length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
  383. PRINTK2((KERN_DEBUG "%s: entering ni5010_send_packet\n", dev->name));
  384. /*
  385. * Block sending
  386. */
  387. netif_stop_queue(dev);
  388. hardware_send_packet(dev, (unsigned char *)skb->data, skb->len, length-skb->len);
  389. dev_kfree_skb (skb);
  390. return NETDEV_TX_OK;
  391. }
  392. /*
  393. * The typical workload of the driver:
  394. * Handle the network interface interrupts.
  395. */
  396. static irqreturn_t ni5010_interrupt(int irq, void *dev_id)
  397. {
  398. struct net_device *dev = dev_id;
  399. struct ni5010_local *lp;
  400. int ioaddr, status;
  401. int xmit_was_error = 0;
  402. PRINTK2((KERN_DEBUG "%s: entering ni5010_interrupt\n", dev->name));
  403. ioaddr = dev->base_addr;
  404. lp = netdev_priv(dev);
  405. spin_lock(&lp->lock);
  406. status = inb(IE_ISTAT);
  407. PRINTK3((KERN_DEBUG "%s: IE_ISTAT = %#02x\n", dev->name, status));
  408. if ((status & IS_R_INT) == 0) ni5010_rx(dev);
  409. if ((status & IS_X_INT) == 0) {
  410. xmit_was_error = process_xmt_interrupt(dev);
  411. }
  412. if ((status & IS_DMA_INT) == 0) {
  413. PRINTK((KERN_DEBUG "%s: DMA complete (?)\n", dev->name));
  414. outb(0, IE_DMA_RST); /* Reset DMA int */
  415. }
  416. if (!xmit_was_error)
  417. reset_receiver(dev);
  418. spin_unlock(&lp->lock);
  419. return IRQ_HANDLED;
  420. }
  421. static void dump_packet(void *buf, int len)
  422. {
  423. int i;
  424. printk(KERN_DEBUG "Packet length = %#4x\n", len);
  425. for (i = 0; i < len; i++){
  426. if (i % 16 == 0) printk(KERN_DEBUG "%#4.4x", i);
  427. if (i % 2 == 0) printk(" ");
  428. printk("%2.2x", ((unsigned char *)buf)[i]);
  429. if (i % 16 == 15) printk("\n");
  430. }
  431. printk("\n");
  432. }
  433. /* We have a good packet, get it out of the buffer. */
  434. static void ni5010_rx(struct net_device *dev)
  435. {
  436. int ioaddr = dev->base_addr;
  437. unsigned char rcv_stat;
  438. struct sk_buff *skb;
  439. int i_pkt_size;
  440. PRINTK2((KERN_DEBUG "%s: entering ni5010_rx()\n", dev->name));
  441. rcv_stat = inb(EDLC_RSTAT);
  442. PRINTK3((KERN_DEBUG "%s: EDLC_RSTAT = %#2x\n", dev->name, rcv_stat));
  443. if ( (rcv_stat & RS_VALID_BITS) != RS_PKT_OK) {
  444. PRINTK((KERN_INFO "%s: receive error.\n", dev->name));
  445. dev->stats.rx_errors++;
  446. if (rcv_stat & RS_RUNT) dev->stats.rx_length_errors++;
  447. if (rcv_stat & RS_ALIGN) dev->stats.rx_frame_errors++;
  448. if (rcv_stat & RS_CRC_ERR) dev->stats.rx_crc_errors++;
  449. if (rcv_stat & RS_OFLW) dev->stats.rx_fifo_errors++;
  450. outb(0xff, EDLC_RCLR); /* Clear the interrupt */
  451. return;
  452. }
  453. outb(0xff, EDLC_RCLR); /* Clear the interrupt */
  454. i_pkt_size = inw(IE_RCNT);
  455. if (i_pkt_size > ETH_FRAME_LEN || i_pkt_size < 10 ) {
  456. PRINTK((KERN_DEBUG "%s: Packet size error, packet size = %#4.4x\n",
  457. dev->name, i_pkt_size));
  458. dev->stats.rx_errors++;
  459. dev->stats.rx_length_errors++;
  460. return;
  461. }
  462. /* Malloc up new buffer. */
  463. skb = dev_alloc_skb(i_pkt_size + 3);
  464. if (skb == NULL) {
  465. printk(KERN_WARNING "%s: Memory squeeze, dropping packet.\n", dev->name);
  466. dev->stats.rx_dropped++;
  467. return;
  468. }
  469. skb_reserve(skb, 2);
  470. /* Read packet into buffer */
  471. outb(MM_MUX, IE_MMODE); /* Rcv buffer to system bus */
  472. outw(0, IE_GP); /* Seek to beginning of packet */
  473. insb(IE_RBUF, skb_put(skb, i_pkt_size), i_pkt_size);
  474. if (NI5010_DEBUG >= 4)
  475. dump_packet(skb->data, skb->len);
  476. skb->protocol = eth_type_trans(skb,dev);
  477. netif_rx(skb);
  478. dev->stats.rx_packets++;
  479. dev->stats.rx_bytes += i_pkt_size;
  480. PRINTK2((KERN_DEBUG "%s: Received packet, size=%#4.4x\n",
  481. dev->name, i_pkt_size));
  482. }
  483. static int process_xmt_interrupt(struct net_device *dev)
  484. {
  485. struct ni5010_local *lp = netdev_priv(dev);
  486. int ioaddr = dev->base_addr;
  487. int xmit_stat;
  488. PRINTK2((KERN_DEBUG "%s: entering process_xmt_interrupt\n", dev->name));
  489. xmit_stat = inb(EDLC_XSTAT);
  490. PRINTK3((KERN_DEBUG "%s: EDLC_XSTAT = %2.2x\n", dev->name, xmit_stat));
  491. outb(0, EDLC_XMASK); /* Disable xmit IRQ's */
  492. outb(0xff, EDLC_XCLR); /* Clear all pending xmit IRQ's */
  493. if (xmit_stat & XS_COLL){
  494. PRINTK((KERN_DEBUG "%s: collision detected, retransmitting\n",
  495. dev->name));
  496. outw(NI5010_BUFSIZE - lp->o_pkt_size, IE_GP);
  497. /* outb(0, IE_MMODE); */ /* xmt buf on sysbus FIXME: needed ? */
  498. outb(MM_EN_XMT | MM_MUX, IE_MMODE);
  499. outb(XM_ALL, EDLC_XMASK); /* Enable xmt IRQ's */
  500. dev->stats.collisions++;
  501. return 1;
  502. }
  503. /* FIXME: handle other xmt error conditions */
  504. dev->stats.tx_packets++;
  505. dev->stats.tx_bytes += lp->o_pkt_size;
  506. netif_wake_queue(dev);
  507. PRINTK2((KERN_DEBUG "%s: sent packet, size=%#4.4x\n",
  508. dev->name, lp->o_pkt_size));
  509. return 0;
  510. }
  511. /* The inverse routine to ni5010_open(). */
  512. static int ni5010_close(struct net_device *dev)
  513. {
  514. int ioaddr = dev->base_addr;
  515. PRINTK2((KERN_DEBUG "%s: entering ni5010_close\n", dev->name));
  516. #ifdef JUMPERED_INTERRUPTS
  517. free_irq(dev->irq, NULL);
  518. #endif
  519. /* Put card in held-RESET state */
  520. outb(0, IE_MMODE);
  521. outb(RS_RESET, EDLC_RESET);
  522. netif_stop_queue(dev);
  523. PRINTK((KERN_DEBUG "%s: %s closed down\n", dev->name, boardname));
  524. return 0;
  525. }
  526. /* Set or clear the multicast filter for this adaptor.
  527. num_addrs == -1 Promiscuous mode, receive all packets
  528. num_addrs == 0 Normal mode, clear multicast list
  529. num_addrs > 0 Multicast mode, receive normal and MC packets, and do
  530. best-effort filtering.
  531. */
  532. static void ni5010_set_multicast_list(struct net_device *dev)
  533. {
  534. short ioaddr = dev->base_addr;
  535. PRINTK2((KERN_DEBUG "%s: entering set_multicast_list\n", dev->name));
  536. if (dev->flags & IFF_PROMISC || dev->flags & IFF_ALLMULTI ||
  537. !netdev_mc_empty(dev)) {
  538. outb(RMD_PROMISC, EDLC_RMODE); /* Enable promiscuous mode */
  539. PRINTK((KERN_DEBUG "%s: Entering promiscuous mode\n", dev->name));
  540. } else {
  541. PRINTK((KERN_DEBUG "%s: Entering broadcast mode\n", dev->name));
  542. outb(RMD_BROADCAST, EDLC_RMODE); /* Disable promiscuous mode, use normal mode */
  543. }
  544. }
  545. static void hardware_send_packet(struct net_device *dev, char *buf, int length, int pad)
  546. {
  547. struct ni5010_local *lp = netdev_priv(dev);
  548. int ioaddr = dev->base_addr;
  549. unsigned long flags;
  550. unsigned int buf_offs;
  551. PRINTK2((KERN_DEBUG "%s: entering hardware_send_packet\n", dev->name));
  552. if (length > ETH_FRAME_LEN) {
  553. PRINTK((KERN_WARNING "%s: packet too large, not possible\n",
  554. dev->name));
  555. return;
  556. }
  557. if (NI5010_DEBUG) ni5010_show_registers(dev);
  558. if (inb(IE_ISTAT) & IS_EN_XMT) {
  559. PRINTK((KERN_WARNING "%s: sending packet while already transmitting, not possible\n",
  560. dev->name));
  561. return;
  562. }
  563. if (NI5010_DEBUG > 3) dump_packet(buf, length);
  564. buf_offs = NI5010_BUFSIZE - length - pad;
  565. spin_lock_irqsave(&lp->lock, flags);
  566. lp->o_pkt_size = length + pad;
  567. outb(0, EDLC_RMASK); /* Mask all receive interrupts */
  568. outb(0, IE_MMODE); /* Put Xmit buffer on system bus */
  569. outb(0xff, EDLC_RCLR); /* Clear out pending rcv interrupts */
  570. outw(buf_offs, IE_GP); /* Point GP at start of packet */
  571. outsb(IE_XBUF, buf, length); /* Put data in buffer */
  572. while(pad--)
  573. outb(0, IE_XBUF);
  574. outw(buf_offs, IE_GP); /* Rewrite where packet starts */
  575. /* should work without that outb() (Crynwr used it) */
  576. /*outb(MM_MUX, IE_MMODE);*/ /* Xmt buffer to EDLC bus */
  577. outb(MM_EN_XMT | MM_MUX, IE_MMODE); /* Begin transmission */
  578. outb(XM_ALL, EDLC_XMASK); /* Cause interrupt after completion or fail */
  579. spin_unlock_irqrestore(&lp->lock, flags);
  580. netif_wake_queue(dev);
  581. if (NI5010_DEBUG) ni5010_show_registers(dev);
  582. }
  583. static void chipset_init(struct net_device *dev, int startp)
  584. {
  585. /* FIXME: Move some stuff here */
  586. PRINTK3((KERN_DEBUG "%s: doing NOTHING in chipset_init\n", dev->name));
  587. }
  588. static void ni5010_show_registers(struct net_device *dev)
  589. {
  590. int ioaddr = dev->base_addr;
  591. PRINTK3((KERN_DEBUG "%s: XSTAT %#2.2x\n", dev->name, inb(EDLC_XSTAT)));
  592. PRINTK3((KERN_DEBUG "%s: XMASK %#2.2x\n", dev->name, inb(EDLC_XMASK)));
  593. PRINTK3((KERN_DEBUG "%s: RSTAT %#2.2x\n", dev->name, inb(EDLC_RSTAT)));
  594. PRINTK3((KERN_DEBUG "%s: RMASK %#2.2x\n", dev->name, inb(EDLC_RMASK)));
  595. PRINTK3((KERN_DEBUG "%s: RMODE %#2.2x\n", dev->name, inb(EDLC_RMODE)));
  596. PRINTK3((KERN_DEBUG "%s: XMODE %#2.2x\n", dev->name, inb(EDLC_XMODE)));
  597. PRINTK3((KERN_DEBUG "%s: ISTAT %#2.2x\n", dev->name, inb(IE_ISTAT)));
  598. }
  599. #ifdef MODULE
  600. static struct net_device *dev_ni5010;
  601. module_param(io, int, 0);
  602. module_param(irq, int, 0);
  603. MODULE_PARM_DESC(io, "ni5010 I/O base address");
  604. MODULE_PARM_DESC(irq, "ni5010 IRQ number");
  605. static int __init ni5010_init_module(void)
  606. {
  607. PRINTK2((KERN_DEBUG "%s: entering init_module\n", boardname));
  608. /*
  609. if(io <= 0 || irq == 0){
  610. printk(KERN_WARNING "%s: Autoprobing not allowed for modules.\n", boardname);
  611. printk(KERN_WARNING "%s: Set symbols 'io' and 'irq'\n", boardname);
  612. return -EINVAL;
  613. }
  614. */
  615. if (io <= 0){
  616. printk(KERN_WARNING "%s: Autoprobing for modules is hazardous, trying anyway..\n", boardname);
  617. }
  618. PRINTK2((KERN_DEBUG "%s: init_module irq=%#2x, io=%#3x\n", boardname, irq, io));
  619. dev_ni5010 = ni5010_probe(-1);
  620. if (IS_ERR(dev_ni5010))
  621. return PTR_ERR(dev_ni5010);
  622. return 0;
  623. }
  624. static void __exit ni5010_cleanup_module(void)
  625. {
  626. PRINTK2((KERN_DEBUG "%s: entering cleanup_module\n", boardname));
  627. unregister_netdev(dev_ni5010);
  628. release_region(dev_ni5010->base_addr, NI5010_IO_EXTENT);
  629. free_netdev(dev_ni5010);
  630. }
  631. module_init(ni5010_init_module);
  632. module_exit(ni5010_cleanup_module);
  633. #endif /* MODULE */
  634. MODULE_LICENSE("GPL");