fmv18x.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /* fmv18x.c: A network device driver for the Fujitsu FMV-181/182/183/184.
  2. Original: at1700.c (1993-94 by Donald Becker).
  3. Copyright 1993 United States Government as represented by the
  4. Director, National Security Agency.
  5. The author may be reached as becker@scyld.com, or C/O
  6. Scyld Computing Corporation
  7. 410 Severn Ave., Suite 210
  8. Annapolis MD 21403
  9. Modified by Yutaka TAMIYA (tamy@flab.fujitsu.co.jp)
  10. Copyright 1994 Fujitsu Laboratories Ltd.
  11. Special thanks to:
  12. Masayoshi UTAKA (utaka@ace.yk.fujitsu.co.jp)
  13. for testing this driver.
  14. H. NEGISHI (agy, negishi@sun45.psd.cs.fujitsu.co.jp)
  15. for suggestion of some program modification.
  16. Masahiro SEKIGUCHI <seki@sysrap.cs.fujitsu.co.jp>
  17. for suggestion of some program modification.
  18. Kazutoshi MORIOKA (morioka@aurora.oaks.cs.fujitsu.co.jp)
  19. for testing this driver.
  20. This software may be used and distributed according to the terms
  21. of the GNU General Public License, incorporated herein by reference.
  22. This is a device driver for the Fujitsu FMV-181/182/183/184, which
  23. is a straight-forward Fujitsu MB86965 implementation.
  24. Sources:
  25. at1700.c
  26. The Fujitsu MB86965 datasheet.
  27. The Fujitsu FMV-181/182 user's guide
  28. */
  29. static const char version[] =
  30. "fmv18x.c:v2.2.0 09/24/98 Yutaka TAMIYA (tamy@flab.fujitsu.co.jp)\n";
  31. #include <linux/module.h>
  32. #include <linux/kernel.h>
  33. #include <linux/types.h>
  34. #include <linux/fcntl.h>
  35. #include <linux/interrupt.h>
  36. #include <linux/ioport.h>
  37. #include <linux/in.h>
  38. #include <linux/slab.h>
  39. #include <linux/string.h>
  40. #include <linux/init.h>
  41. #include <linux/errno.h>
  42. #include <linux/spinlock.h>
  43. #include <linux/netdevice.h>
  44. #include <linux/etherdevice.h>
  45. #include <linux/skbuff.h>
  46. #include <linux/delay.h>
  47. #include <linux/bitops.h>
  48. #include <asm/system.h>
  49. #include <asm/io.h>
  50. #include <asm/dma.h>
  51. #define DRV_NAME "fmv18x"
  52. static unsigned fmv18x_probe_list[] __initdata = {
  53. 0x220, 0x240, 0x260, 0x280, 0x2a0, 0x2c0, 0x300, 0x340, 0
  54. };
  55. /* use 0 for production, 1 for verification, >2 for debug */
  56. #ifndef NET_DEBUG
  57. #define NET_DEBUG 1
  58. #endif
  59. static unsigned int net_debug = NET_DEBUG;
  60. typedef unsigned char uchar;
  61. /* Information that need to be kept for each board. */
  62. struct net_local {
  63. struct net_device_stats stats;
  64. long open_time; /* Useless example local info. */
  65. uint tx_started:1; /* Number of packet on the Tx queue. */
  66. uint tx_queue_ready:1; /* Tx queue is ready to be sent. */
  67. uint rx_started:1; /* Packets are Rxing. */
  68. uchar tx_queue; /* Number of packet on the Tx queue. */
  69. ushort tx_queue_len; /* Current length of the Tx queue. */
  70. spinlock_t lock;
  71. };
  72. /* Offsets from the base address. */
  73. #define STATUS 0
  74. #define TX_STATUS 0
  75. #define RX_STATUS 1
  76. #define TX_INTR 2 /* Bit-mapped interrupt enable registers. */
  77. #define RX_INTR 3
  78. #define TX_MODE 4
  79. #define RX_MODE 5
  80. #define CONFIG_0 6 /* Misc. configuration settings. */
  81. #define CONFIG_1 7
  82. /* Run-time register bank 2 definitions. */
  83. #define DATAPORT 8 /* Word-wide DMA or programmed-I/O dataport. */
  84. #define TX_START 10
  85. #define COL16CNTL 11 /* Controll Reg for 16 collisions */
  86. #define MODE13 13
  87. /* Fujitsu FMV-18x Card Configuration */
  88. #define FJ_STATUS0 0x10
  89. #define FJ_STATUS1 0x11
  90. #define FJ_CONFIG0 0x12
  91. #define FJ_CONFIG1 0x13
  92. #define FJ_MACADDR 0x14 /* 0x14 - 0x19 */
  93. #define FJ_BUFCNTL 0x1A
  94. #define FJ_BUFDATA 0x1C
  95. #define FMV18X_IO_EXTENT 32
  96. /* Index to functions, as function prototypes. */
  97. static int fmv18x_probe1(struct net_device *dev, short ioaddr);
  98. static int net_open(struct net_device *dev);
  99. static int net_send_packet(struct sk_buff *skb, struct net_device *dev);
  100. static irqreturn_t net_interrupt(int irq, void *dev_id, struct pt_regs *regs);
  101. static void net_rx(struct net_device *dev);
  102. static void net_timeout(struct net_device *dev);
  103. static int net_close(struct net_device *dev);
  104. static struct net_device_stats *net_get_stats(struct net_device *dev);
  105. static void set_multicast_list(struct net_device *dev);
  106. /* Check for a network adaptor of this type, and return '0' iff one exists.
  107. If dev->base_addr == 0, probe all likely locations.
  108. If dev->base_addr == 1, always return failure.
  109. If dev->base_addr == 2, allocate space for the device and return success
  110. (detachable devices only).
  111. */
  112. static int io = 0x220;
  113. static int irq;
  114. struct net_device * __init fmv18x_probe(int unit)
  115. {
  116. struct net_device *dev = alloc_etherdev(sizeof(struct net_local));
  117. unsigned *port;
  118. int err = 0;
  119. if (!dev)
  120. return ERR_PTR(-ENODEV);
  121. if (unit >= 0) {
  122. sprintf(dev->name, "eth%d", unit);
  123. netdev_boot_setup_check(dev);
  124. io = dev->base_addr;
  125. irq = dev->irq;
  126. }
  127. SET_MODULE_OWNER(dev);
  128. if (io > 0x1ff) { /* Check a single specified location. */
  129. err = fmv18x_probe1(dev, io);
  130. } else if (io != 0) { /* Don't probe at all. */
  131. err = -ENXIO;
  132. } else {
  133. for (port = fmv18x_probe_list; *port; port++)
  134. if (fmv18x_probe1(dev, *port) == 0)
  135. break;
  136. if (!*port)
  137. err = -ENODEV;
  138. }
  139. if (err)
  140. goto out;
  141. err = register_netdev(dev);
  142. if (err)
  143. goto out1;
  144. return dev;
  145. out1:
  146. free_irq(dev->irq, dev);
  147. release_region(dev->base_addr, FMV18X_IO_EXTENT);
  148. out:
  149. free_netdev(dev);
  150. return ERR_PTR(err);
  151. }
  152. /* The Fujitsu datasheet suggests that the NIC be probed for by checking its
  153. "signature", the default bit pattern after a reset. This *doesn't* work --
  154. there is no way to reset the bus interface without a complete power-cycle!
  155. It turns out that ATI came to the same conclusion I did: the only thing
  156. that can be done is checking a few bits and then diving right into MAC
  157. address check. */
  158. static int __init fmv18x_probe1(struct net_device *dev, short ioaddr)
  159. {
  160. char irqmap[4] = {3, 7, 10, 15};
  161. char irqmap_pnp[8] = {3, 4, 5, 7, 9, 10, 11, 15};
  162. unsigned int i, retval;
  163. struct net_local *lp;
  164. /* Resetting the chip doesn't reset the ISA interface, so don't bother.
  165. That means we have to be careful with the register values we probe for.
  166. */
  167. if (!request_region(ioaddr, FMV18X_IO_EXTENT, DRV_NAME))
  168. return -EBUSY;
  169. dev->irq = irq;
  170. dev->base_addr = ioaddr;
  171. /* Check I/O address configuration and Fujitsu vendor code */
  172. if (inb(ioaddr+FJ_MACADDR ) != 0x00
  173. || inb(ioaddr+FJ_MACADDR+1) != 0x00
  174. || inb(ioaddr+FJ_MACADDR+2) != 0x0e) {
  175. retval = -ENODEV;
  176. goto out;
  177. }
  178. /* Check PnP mode for FMV-183/184/183A/184A. */
  179. /* This PnP routine is very poor. IO and IRQ should be known. */
  180. if (inb(ioaddr + FJ_STATUS1) & 0x20) {
  181. for (i = 0; i < 8; i++) {
  182. if (dev->irq == irqmap_pnp[i])
  183. break;
  184. }
  185. if (i == 8) {
  186. retval = -ENODEV;
  187. goto out;
  188. }
  189. } else {
  190. if (fmv18x_probe_list[inb(ioaddr + FJ_CONFIG0) & 0x07] != ioaddr)
  191. return -ENODEV;
  192. dev->irq = irqmap[(inb(ioaddr + FJ_CONFIG0)>>6) & 0x03];
  193. }
  194. /* Snarf the interrupt vector now. */
  195. retval = request_irq(dev->irq, &net_interrupt, 0, DRV_NAME, dev);
  196. if (retval) {
  197. printk ("FMV-18x found at %#3x, but it's unusable due to a conflict on"
  198. "IRQ %d.\n", ioaddr, dev->irq);
  199. goto out;
  200. }
  201. printk("%s: FMV-18x found at %#3x, IRQ %d, address ", dev->name,
  202. ioaddr, dev->irq);
  203. for(i = 0; i < 6; i++) {
  204. unsigned char val = inb(ioaddr + FJ_MACADDR + i);
  205. printk("%02x", val);
  206. dev->dev_addr[i] = val;
  207. }
  208. /* "FJ_STATUS0" 12 bit 0x0400 means use regular 100 ohm 10baseT signals,
  209. rather than 150 ohm shielded twisted pair compensation.
  210. 0x0000 == auto-sense the interface
  211. 0x0800 == use TP interface
  212. 0x1800 == use coax interface
  213. */
  214. {
  215. const char *porttype[] = {"auto-sense", "10baseT", "auto-sense", "10base2/5"};
  216. ushort setup_value = inb(ioaddr + FJ_STATUS0);
  217. switch( setup_value & 0x07 ){
  218. case 0x01 /* 10base5 */:
  219. case 0x02 /* 10base2 */: dev->if_port = 0x18; break;
  220. case 0x04 /* 10baseT */: dev->if_port = 0x08; break;
  221. default /* auto-sense*/: dev->if_port = 0x00; break;
  222. }
  223. printk(" %s interface.\n", porttype[(dev->if_port>>3) & 3]);
  224. }
  225. /* Initialize LAN Controller and LAN Card */
  226. outb(0xda, ioaddr + CONFIG_0); /* Initialize LAN Controller */
  227. outb(0x00, ioaddr + CONFIG_1); /* Stand by mode */
  228. outb(0x00, ioaddr + FJ_CONFIG1); /* Disable IRQ of LAN Card */
  229. outb(0x00, ioaddr + FJ_BUFCNTL); /* Reset ? I'm not sure (TAMIYA) */
  230. /* wait for a while */
  231. udelay(200);
  232. /* Set the station address in bank zero. */
  233. outb(0x00, ioaddr + CONFIG_1);
  234. for (i = 0; i < 6; i++)
  235. outb(dev->dev_addr[i], ioaddr + 8 + i);
  236. /* Switch to bank 1 and set the multicast table to accept none. */
  237. outb(0x04, ioaddr + CONFIG_1);
  238. for (i = 0; i < 8; i++)
  239. outb(0x00, ioaddr + 8 + i);
  240. /* Switch to bank 2 and lock our I/O address. */
  241. outb(0x08, ioaddr + CONFIG_1);
  242. outb(dev->if_port, ioaddr + MODE13);
  243. outb(0x00, ioaddr + COL16CNTL);
  244. if (net_debug)
  245. printk(version);
  246. /* Initialize the device structure. */
  247. dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
  248. if (!dev->priv) {
  249. retval = -ENOMEM;
  250. goto out_irq;
  251. }
  252. memset(dev->priv, 0, sizeof(struct net_local));
  253. lp = dev->priv;
  254. spin_lock_init(&lp->lock);
  255. dev->open = net_open;
  256. dev->stop = net_close;
  257. dev->hard_start_xmit = net_send_packet;
  258. dev->tx_timeout = net_timeout;
  259. dev->watchdog_timeo = HZ/10;
  260. dev->get_stats = net_get_stats;
  261. dev->set_multicast_list = set_multicast_list;
  262. return 0;
  263. out_irq:
  264. free_irq(dev->irq, dev);
  265. out:
  266. release_region(ioaddr, FMV18X_IO_EXTENT);
  267. return retval;
  268. }
  269. static int net_open(struct net_device *dev)
  270. {
  271. struct net_local *lp = dev->priv;
  272. int ioaddr = dev->base_addr;
  273. /* Set the configuration register 0 to 32K 100ns. byte-wide memory,
  274. 16 bit bus access, and two 4K Tx, enable the Rx and Tx. */
  275. outb(0x5a, ioaddr + CONFIG_0);
  276. /* Powerup and switch to register bank 2 for the run-time registers. */
  277. outb(0xe8, ioaddr + CONFIG_1);
  278. lp->tx_started = 0;
  279. lp->tx_queue_ready = 1;
  280. lp->rx_started = 0;
  281. lp->tx_queue = 0;
  282. lp->tx_queue_len = 0;
  283. /* Clear Tx and Rx Status */
  284. outb(0xff, ioaddr + TX_STATUS);
  285. outb(0xff, ioaddr + RX_STATUS);
  286. lp->open_time = jiffies;
  287. netif_start_queue(dev);
  288. /* Enable the IRQ of the LAN Card */
  289. outb(0x80, ioaddr + FJ_CONFIG1);
  290. /* Enable both Tx and Rx interrupts */
  291. outw(0x8182, ioaddr+TX_INTR);
  292. return 0;
  293. }
  294. static void net_timeout(struct net_device *dev)
  295. {
  296. struct net_local *lp = dev->priv;
  297. int ioaddr = dev->base_addr;
  298. unsigned long flags;
  299. printk(KERN_WARNING "%s: transmit timed out with status %04x, %s?\n", dev->name,
  300. htons(inw(ioaddr + TX_STATUS)),
  301. inb(ioaddr + TX_STATUS) & 0x80
  302. ? "IRQ conflict" : "network cable problem");
  303. printk(KERN_WARNING "%s: timeout registers: %04x %04x %04x %04x %04x %04x %04x %04x.\n",
  304. dev->name, htons(inw(ioaddr + 0)),
  305. htons(inw(ioaddr + 2)), htons(inw(ioaddr + 4)),
  306. htons(inw(ioaddr + 6)), htons(inw(ioaddr + 8)),
  307. htons(inw(ioaddr +10)), htons(inw(ioaddr +12)),
  308. htons(inw(ioaddr +14)));
  309. printk(KERN_WARNING "eth card: %04x %04x\n",
  310. htons(inw(ioaddr+FJ_STATUS0)),
  311. htons(inw(ioaddr+FJ_CONFIG0)));
  312. lp->stats.tx_errors++;
  313. /* ToDo: We should try to restart the adaptor... */
  314. spin_lock_irqsave(&lp->lock, flags);
  315. /* Initialize LAN Controller and LAN Card */
  316. outb(0xda, ioaddr + CONFIG_0); /* Initialize LAN Controller */
  317. outb(0x00, ioaddr + CONFIG_1); /* Stand by mode */
  318. outb(0x00, ioaddr + FJ_CONFIG1); /* Disable IRQ of LAN Card */
  319. outb(0x00, ioaddr + FJ_BUFCNTL); /* Reset ? I'm not sure */
  320. net_open(dev);
  321. spin_unlock_irqrestore(&lp->lock, flags);
  322. netif_wake_queue(dev);
  323. }
  324. static int net_send_packet(struct sk_buff *skb, struct net_device *dev)
  325. {
  326. struct net_local *lp = dev->priv;
  327. int ioaddr = dev->base_addr;
  328. short length = skb->len;
  329. unsigned char *buf;
  330. unsigned long flags;
  331. /* Block a transmit from overlapping. */
  332. if (length > ETH_FRAME_LEN) {
  333. if (net_debug)
  334. printk("%s: Attempting to send a large packet (%d bytes).\n",
  335. dev->name, length);
  336. return 1;
  337. }
  338. if (length < ETH_ZLEN) {
  339. skb = skb_padto(skb, ETH_ZLEN);
  340. if (skb == NULL)
  341. return 0;
  342. length = ETH_ZLEN;
  343. }
  344. buf = skb->data;
  345. if (net_debug > 4)
  346. printk("%s: Transmitting a packet of length %lu.\n", dev->name,
  347. (unsigned long)skb->len);
  348. /* We may not start transmitting unless we finish transferring
  349. a packet into the Tx queue. During executing the following
  350. codes we possibly catch a Tx interrupt. Thus we flag off
  351. tx_queue_ready, so that we prevent the interrupt routine
  352. (net_interrupt) to start transmitting. */
  353. spin_lock_irqsave(&lp->lock, flags);
  354. lp->tx_queue_ready = 0;
  355. {
  356. outw(length, ioaddr + DATAPORT);
  357. outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1);
  358. lp->tx_queue++;
  359. lp->tx_queue_len += length + 2;
  360. }
  361. lp->tx_queue_ready = 1;
  362. spin_unlock_irqrestore(&lp->lock, flags);
  363. if (lp->tx_started == 0) {
  364. /* If the Tx is idle, always trigger a transmit. */
  365. outb(0x80 | lp->tx_queue, ioaddr + TX_START);
  366. lp->tx_queue = 0;
  367. lp->tx_queue_len = 0;
  368. dev->trans_start = jiffies;
  369. lp->tx_started = 1;
  370. } else if (lp->tx_queue_len >= 4096 - 1502) /* No room for a packet */
  371. netif_stop_queue(dev);
  372. dev_kfree_skb(skb);
  373. return 0;
  374. }
  375. /* The typical workload of the driver:
  376. Handle the network interface interrupts. */
  377. static irqreturn_t
  378. net_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  379. {
  380. struct net_device *dev = dev_id;
  381. struct net_local *lp;
  382. int ioaddr, status;
  383. ioaddr = dev->base_addr;
  384. lp = dev->priv;
  385. status = inw(ioaddr + TX_STATUS);
  386. outw(status, ioaddr + TX_STATUS);
  387. if (net_debug > 4)
  388. printk("%s: Interrupt with status %04x.\n", dev->name, status);
  389. if (lp->rx_started == 0 &&
  390. (status & 0xff00 || (inb(ioaddr + RX_MODE) & 0x40) == 0)) {
  391. /* Got a packet(s).
  392. We cannot execute net_rx more than once at the same time for
  393. the same device. During executing net_rx, we possibly catch a
  394. Tx interrupt. Thus we flag on rx_started, so that we prevent
  395. the interrupt routine (net_interrupt) to dive into net_rx
  396. again. */
  397. lp->rx_started = 1;
  398. outb(0x00, ioaddr + RX_INTR); /* Disable RX intr. */
  399. net_rx(dev);
  400. outb(0x81, ioaddr + RX_INTR); /* Enable RX intr. */
  401. lp->rx_started = 0;
  402. }
  403. if (status & 0x00ff) {
  404. if (status & 0x02) {
  405. /* More than 16 collisions occurred */
  406. if (net_debug > 4)
  407. printk("%s: 16 Collision occur during Txing.\n", dev->name);
  408. /* Cancel sending a packet. */
  409. outb(0x03, ioaddr + COL16CNTL);
  410. lp->stats.collisions++;
  411. }
  412. if (status & 0x82) {
  413. spin_lock(&lp->lock);
  414. lp->stats.tx_packets++;
  415. if (lp->tx_queue && lp->tx_queue_ready) {
  416. outb(0x80 | lp->tx_queue, ioaddr + TX_START);
  417. lp->tx_queue = 0;
  418. lp->tx_queue_len = 0;
  419. dev->trans_start = jiffies;
  420. netif_wake_queue(dev); /* Inform upper layers. */
  421. } else {
  422. lp->tx_started = 0;
  423. netif_wake_queue(dev); /* Inform upper layers. */
  424. }
  425. spin_unlock(&lp->lock);
  426. }
  427. }
  428. return IRQ_RETVAL(status);
  429. }
  430. /* We have a good packet(s), get it/them out of the buffers. */
  431. static void net_rx(struct net_device *dev)
  432. {
  433. struct net_local *lp = dev->priv;
  434. int ioaddr = dev->base_addr;
  435. int boguscount = 5;
  436. while ((inb(ioaddr + RX_MODE) & 0x40) == 0) {
  437. /* Clear PKT_RDY bit: by agy 19940922 */
  438. /* outb(0x80, ioaddr + RX_STATUS); */
  439. ushort status = inw(ioaddr + DATAPORT);
  440. if (net_debug > 4)
  441. printk("%s: Rxing packet mode %02x status %04x.\n",
  442. dev->name, inb(ioaddr + RX_MODE), status);
  443. #ifndef final_version
  444. if (status == 0) {
  445. outb(0x05, ioaddr + 14);
  446. break;
  447. }
  448. #endif
  449. if ((status & 0xF0) != 0x20) { /* There was an error. */
  450. lp->stats.rx_errors++;
  451. if (status & 0x08) lp->stats.rx_length_errors++;
  452. if (status & 0x04) lp->stats.rx_frame_errors++;
  453. if (status & 0x02) lp->stats.rx_crc_errors++;
  454. if (status & 0x01) lp->stats.rx_over_errors++;
  455. } else {
  456. ushort pkt_len = inw(ioaddr + DATAPORT);
  457. /* Malloc up new buffer. */
  458. struct sk_buff *skb;
  459. if (pkt_len > 1550) {
  460. printk("%s: The FMV-18x claimed a very large packet, size %d.\n",
  461. dev->name, pkt_len);
  462. outb(0x05, ioaddr + 14);
  463. lp->stats.rx_errors++;
  464. break;
  465. }
  466. skb = dev_alloc_skb(pkt_len+3);
  467. if (skb == NULL) {
  468. printk("%s: Memory squeeze, dropping packet (len %d).\n",
  469. dev->name, pkt_len);
  470. outb(0x05, ioaddr + 14);
  471. lp->stats.rx_dropped++;
  472. break;
  473. }
  474. skb->dev = dev;
  475. skb_reserve(skb,2);
  476. insw(ioaddr + DATAPORT, skb_put(skb,pkt_len), (pkt_len + 1) >> 1);
  477. if (net_debug > 5) {
  478. int i;
  479. printk("%s: Rxed packet of length %d: ", dev->name, pkt_len);
  480. for (i = 0; i < 14; i++)
  481. printk(" %02x", skb->data[i]);
  482. printk(".\n");
  483. }
  484. skb->protocol=eth_type_trans(skb, dev);
  485. netif_rx(skb);
  486. dev->last_rx = jiffies;
  487. lp->stats.rx_packets++;
  488. lp->stats.rx_bytes += pkt_len;
  489. }
  490. if (--boguscount <= 0)
  491. break;
  492. }
  493. /* If any worth-while packets have been received, dev_rint()
  494. has done a mark_bh(NET_BH) for us and will work on them
  495. when we get to the bottom-half routine. */
  496. {
  497. int i;
  498. for (i = 0; i < 20; i++) {
  499. if ((inb(ioaddr + RX_MODE) & 0x40) == 0x40)
  500. break;
  501. (void)inw(ioaddr + DATAPORT); /* dummy status read */
  502. outb(0x05, ioaddr + 14);
  503. }
  504. if (net_debug > 5 && i > 0)
  505. printk("%s: Exint Rx packet with mode %02x after %d ticks.\n",
  506. dev->name, inb(ioaddr + RX_MODE), i);
  507. }
  508. return;
  509. }
  510. /* The inverse routine to net_open(). */
  511. static int net_close(struct net_device *dev)
  512. {
  513. int ioaddr = dev->base_addr;
  514. ((struct net_local *)dev->priv)->open_time = 0;
  515. netif_stop_queue(dev);
  516. /* Set configuration register 0 to disable Tx and Rx. */
  517. outb(0xda, ioaddr + CONFIG_0);
  518. /* Update the statistics -- ToDo. */
  519. /* Power-down the chip. Green, green, green! */
  520. outb(0x00, ioaddr + CONFIG_1);
  521. /* Set the ethernet adaptor disable IRQ */
  522. outb(0x00, ioaddr + FJ_CONFIG1);
  523. return 0;
  524. }
  525. /* Get the current statistics. This may be called with the card open or
  526. closed. */
  527. static struct net_device_stats *net_get_stats(struct net_device *dev)
  528. {
  529. struct net_local *lp = dev->priv;
  530. return &lp->stats;
  531. }
  532. /* Set or clear the multicast filter for this adaptor.
  533. num_addrs == -1 Promiscuous mode, receive all packets
  534. num_addrs == 0 Normal mode, clear multicast list
  535. num_addrs > 0 Multicast mode, receive normal and MC packets, and do
  536. best-effort filtering.
  537. */
  538. static void set_multicast_list(struct net_device *dev)
  539. {
  540. short ioaddr = dev->base_addr;
  541. if (dev->mc_count || dev->flags&(IFF_PROMISC|IFF_ALLMULTI))
  542. {
  543. /*
  544. * We must make the kernel realise we had to move
  545. * into promisc mode or we start all out war on
  546. * the cable. - AC
  547. */
  548. dev->flags|=IFF_PROMISC;
  549. outb(3, ioaddr + RX_MODE); /* Enable promiscuous mode */
  550. }
  551. else
  552. outb(2, ioaddr + RX_MODE); /* Disable promiscuous, use normal mode */
  553. }
  554. #ifdef MODULE
  555. static struct net_device *dev_fmv18x;
  556. MODULE_PARM(io, "i");
  557. MODULE_PARM(irq, "i");
  558. MODULE_PARM(net_debug, "i");
  559. MODULE_PARM_DESC(io, "FMV-18X I/O address");
  560. MODULE_PARM_DESC(irq, "FMV-18X IRQ number");
  561. MODULE_PARM_DESC(net_debug, "FMV-18X debug level (0-1,5-6)");
  562. MODULE_LICENSE("GPL");
  563. int init_module(void)
  564. {
  565. if (io == 0)
  566. printk("fmv18x: You should not use auto-probing with insmod!\n");
  567. dev_fmv18x = fmv18x_probe(-1);
  568. if (IS_ERR(dev_fmv18x))
  569. return PTR_ERR(dev_fmv18x);
  570. return 0;
  571. }
  572. void
  573. cleanup_module(void)
  574. {
  575. unregister_netdev(dev_fmv18x);
  576. free_irq(dev_fmv18x->irq, dev_fmv18x);
  577. release_region(dev_fmv18x->base_addr, FMV18X_IO_EXTENT);
  578. free_netdev(dev_fmv18x);
  579. }
  580. #endif /* MODULE */
  581. /*
  582. * Local variables:
  583. * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c fmv18x.c"
  584. * version-control: t
  585. * kept-new-versions: 5
  586. * tab-width: 4
  587. * c-indent-level: 4
  588. * End:
  589. */