[IPV4]: FIB Trie cleanups.
[linux-2.6/zen-sources.git] / drivers / net / pcmcia / fmvj18x_cs.c
blob384a736a0d2f820f5c6a7fcce3306d8e6ff04264
1 /*======================================================================
2 fmvj18x_cs.c 2.8 2002/03/23
4 A fmvj18x (and its compatibles) PCMCIA client driver
6 Contributed by Shingo Fujimoto, shingo@flab.fujitsu.co.jp
8 TDK LAK-CD021 and CONTEC C-NET(PC)C support added by
9 Nobuhiro Katayama, kata-n@po.iijnet.or.jp
11 The PCMCIA client code is based on code written by David Hinds.
12 Network code is based on the "FMV-18x driver" by Yutaka TAMIYA
13 but is actually largely Donald Becker's AT1700 driver, which
14 carries the following attribution:
16 Written 1993-94 by Donald Becker.
18 Copyright 1993 United States Government as represented by the
19 Director, National Security Agency.
21 This software may be used and distributed according to the terms
22 of the GNU General Public License, incorporated herein by reference.
24 The author may be reached as becker@scyld.com, or C/O
25 Scyld Computing Corporation
26 410 Severn Ave., Suite 210
27 Annapolis MD 21403
29 ======================================================================*/
31 #define DRV_NAME "fmvj18x_cs"
32 #define DRV_VERSION "2.8"
34 #include <linux/module.h>
35 #include <linux/kernel.h>
36 #include <linux/init.h>
37 #include <linux/ptrace.h>
38 #include <linux/slab.h>
39 #include <linux/string.h>
40 #include <linux/timer.h>
41 #include <linux/interrupt.h>
42 #include <linux/in.h>
43 #include <linux/delay.h>
44 #include <linux/ethtool.h>
45 #include <linux/netdevice.h>
46 #include <linux/etherdevice.h>
47 #include <linux/skbuff.h>
48 #include <linux/if_arp.h>
49 #include <linux/ioport.h>
50 #include <linux/crc32.h>
52 #include <pcmcia/cs_types.h>
53 #include <pcmcia/cs.h>
54 #include <pcmcia/cistpl.h>
55 #include <pcmcia/ciscode.h>
56 #include <pcmcia/ds.h>
58 #include <asm/uaccess.h>
59 #include <asm/io.h>
60 #include <asm/system.h>
62 /*====================================================================*/
64 /* Module parameters */
66 MODULE_DESCRIPTION("fmvj18x and compatible PCMCIA ethernet driver");
67 MODULE_LICENSE("GPL");
69 #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
71 /* SRAM configuration */
72 /* 0:4KB*2 TX buffer else:8KB*2 TX buffer */
73 INT_MODULE_PARM(sram_config, 0);
75 #ifdef PCMCIA_DEBUG
76 INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);
77 #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
78 static char *version = DRV_NAME ".c " DRV_VERSION " 2002/03/23";
79 #else
80 #define DEBUG(n, args...)
81 #endif
83 /*====================================================================*/
85 PCMCIA event handlers
87 static void fmvj18x_config(dev_link_t *link);
88 static int fmvj18x_get_hwinfo(dev_link_t *link, u_char *node_id);
89 static int fmvj18x_setup_mfc(dev_link_t *link);
90 static void fmvj18x_release(dev_link_t *link);
91 static int fmvj18x_event(event_t event, int priority,
92 event_callback_args_t *args);
93 static dev_link_t *fmvj18x_attach(void);
94 static void fmvj18x_detach(dev_link_t *);
97 LAN controller(MBH86960A) specific routines
99 static int fjn_config(struct net_device *dev, struct ifmap *map);
100 static int fjn_open(struct net_device *dev);
101 static int fjn_close(struct net_device *dev);
102 static int fjn_start_xmit(struct sk_buff *skb, struct net_device *dev);
103 static irqreturn_t fjn_interrupt(int irq, void *dev_id, struct pt_regs *regs);
104 static void fjn_rx(struct net_device *dev);
105 static void fjn_reset(struct net_device *dev);
106 static struct net_device_stats *fjn_get_stats(struct net_device *dev);
107 static void set_rx_mode(struct net_device *dev);
108 static void fjn_tx_timeout(struct net_device *dev);
109 static struct ethtool_ops netdev_ethtool_ops;
111 static dev_info_t dev_info = "fmvj18x_cs";
112 static dev_link_t *dev_list;
115 card type
117 typedef enum { MBH10302, MBH10304, TDK, CONTEC, LA501, UNGERMANN,
118 XXX10304
119 } cardtype_t;
122 driver specific data structure
124 typedef struct local_info_t {
125 dev_link_t link;
126 dev_node_t node;
127 struct net_device_stats stats;
128 long open_time;
129 uint tx_started:1;
130 uint tx_queue;
131 u_short tx_queue_len;
132 cardtype_t cardtype;
133 u_short sent;
134 u_char mc_filter[8];
135 } local_info_t;
137 #define MC_FILTERBREAK 8
139 /*====================================================================*/
141 ioport offset from the base address
143 #define TX_STATUS 0 /* transmit status register */
144 #define RX_STATUS 1 /* receive status register */
145 #define TX_INTR 2 /* transmit interrupt mask register */
146 #define RX_INTR 3 /* receive interrupt mask register */
147 #define TX_MODE 4 /* transmit mode register */
148 #define RX_MODE 5 /* receive mode register */
149 #define CONFIG_0 6 /* configuration register 0 */
150 #define CONFIG_1 7 /* configuration register 1 */
152 #define NODE_ID 8 /* node ID register (bank 0) */
153 #define MAR_ADR 8 /* multicast address registers (bank 1) */
155 #define DATAPORT 8 /* buffer mem port registers (bank 2) */
156 #define TX_START 10 /* transmit start register */
157 #define COL_CTRL 11 /* 16 collision control register */
158 #define BMPR12 12 /* reserved */
159 #define BMPR13 13 /* reserved */
160 #define RX_SKIP 14 /* skip received packet register */
162 #define LAN_CTRL 16 /* LAN card control register */
164 #define MAC_ID 0x1a /* hardware address */
165 #define UNGERMANN_MAC_ID 0x18 /* UNGERMANN-BASS hardware address */
168 control bits
170 #define ENA_TMT_OK 0x80
171 #define ENA_TMT_REC 0x20
172 #define ENA_COL 0x04
173 #define ENA_16_COL 0x02
174 #define ENA_TBUS_ERR 0x01
176 #define ENA_PKT_RDY 0x80
177 #define ENA_BUS_ERR 0x40
178 #define ENA_LEN_ERR 0x08
179 #define ENA_ALG_ERR 0x04
180 #define ENA_CRC_ERR 0x02
181 #define ENA_OVR_FLO 0x01
183 /* flags */
184 #define F_TMT_RDY 0x80 /* can accept new packet */
185 #define F_NET_BSY 0x40 /* carrier is detected */
186 #define F_TMT_OK 0x20 /* send packet successfully */
187 #define F_SRT_PKT 0x10 /* short packet error */
188 #define F_COL_ERR 0x04 /* collision error */
189 #define F_16_COL 0x02 /* 16 collision error */
190 #define F_TBUS_ERR 0x01 /* bus read error */
192 #define F_PKT_RDY 0x80 /* packet(s) in buffer */
193 #define F_BUS_ERR 0x40 /* bus read error */
194 #define F_LEN_ERR 0x08 /* short packet */
195 #define F_ALG_ERR 0x04 /* frame error */
196 #define F_CRC_ERR 0x02 /* CRC error */
197 #define F_OVR_FLO 0x01 /* overflow error */
199 #define F_BUF_EMP 0x40 /* receive buffer is empty */
201 #define F_SKP_PKT 0x05 /* drop packet in buffer */
203 /* default bitmaps */
204 #define D_TX_INTR ( ENA_TMT_OK )
205 #define D_RX_INTR ( ENA_PKT_RDY | ENA_LEN_ERR \
206 | ENA_ALG_ERR | ENA_CRC_ERR | ENA_OVR_FLO )
207 #define TX_STAT_M ( F_TMT_RDY )
208 #define RX_STAT_M ( F_PKT_RDY | F_LEN_ERR \
209 | F_ALG_ERR | F_CRC_ERR | F_OVR_FLO )
211 /* commands */
212 #define D_TX_MODE 0x06 /* no tests, detect carrier */
213 #define ID_MATCHED 0x02 /* (RX_MODE) */
214 #define RECV_ALL 0x03 /* (RX_MODE) */
215 #define CONFIG0_DFL 0x5a /* 16bit bus, 4K x 2 Tx queues */
216 #define CONFIG0_DFL_1 0x5e /* 16bit bus, 8K x 2 Tx queues */
217 #define CONFIG0_RST 0xda /* Data Link Controller off (CONFIG_0) */
218 #define CONFIG0_RST_1 0xde /* Data Link Controller off (CONFIG_0) */
219 #define BANK_0 0xa0 /* bank 0 (CONFIG_1) */
220 #define BANK_1 0xa4 /* bank 1 (CONFIG_1) */
221 #define BANK_2 0xa8 /* bank 2 (CONFIG_1) */
222 #define CHIP_OFF 0x80 /* contrl chip power off (CONFIG_1) */
223 #define DO_TX 0x80 /* do transmit packet */
224 #define SEND_PKT 0x81 /* send a packet */
225 #define AUTO_MODE 0x07 /* Auto skip packet on 16 col detected */
226 #define MANU_MODE 0x03 /* Stop and skip packet on 16 col */
227 #define TDK_AUTO_MODE 0x47 /* Auto skip packet on 16 col detected */
228 #define TDK_MANU_MODE 0x43 /* Stop and skip packet on 16 col */
229 #define INTR_OFF 0x0d /* LAN controller ignores interrupts */
230 #define INTR_ON 0x1d /* LAN controller will catch interrupts */
232 #define TX_TIMEOUT ((400*HZ)/1000)
234 #define BANK_0U 0x20 /* bank 0 (CONFIG_1) */
235 #define BANK_1U 0x24 /* bank 1 (CONFIG_1) */
236 #define BANK_2U 0x28 /* bank 2 (CONFIG_1) */
238 static dev_link_t *fmvj18x_attach(void)
240 local_info_t *lp;
241 dev_link_t *link;
242 struct net_device *dev;
243 client_reg_t client_reg;
244 int ret;
246 DEBUG(0, "fmvj18x_attach()\n");
248 /* Make up a FMVJ18x specific data structure */
249 dev = alloc_etherdev(sizeof(local_info_t));
250 if (!dev)
251 return NULL;
252 lp = netdev_priv(dev);
253 link = &lp->link;
254 link->priv = dev;
256 /* The io structure describes IO port mapping */
257 link->io.NumPorts1 = 32;
258 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
259 link->io.IOAddrLines = 5;
261 /* Interrupt setup */
262 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
263 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
264 link->irq.Handler = &fjn_interrupt;
265 link->irq.Instance = dev;
267 /* General socket configuration */
268 link->conf.Attributes = CONF_ENABLE_IRQ;
269 link->conf.Vcc = 50;
270 link->conf.IntType = INT_MEMORY_AND_IO;
272 /* The FMVJ18x specific entries in the device structure. */
273 SET_MODULE_OWNER(dev);
274 dev->hard_start_xmit = &fjn_start_xmit;
275 dev->set_config = &fjn_config;
276 dev->get_stats = &fjn_get_stats;
277 dev->set_multicast_list = &set_rx_mode;
278 dev->open = &fjn_open;
279 dev->stop = &fjn_close;
280 #ifdef HAVE_TX_TIMEOUT
281 dev->tx_timeout = fjn_tx_timeout;
282 dev->watchdog_timeo = TX_TIMEOUT;
283 #endif
284 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
286 /* Register with Card Services */
287 link->next = dev_list;
288 dev_list = link;
289 client_reg.dev_info = &dev_info;
290 client_reg.Version = 0x0210;
291 client_reg.event_callback_args.client_data = link;
292 ret = pcmcia_register_client(&link->handle, &client_reg);
293 if (ret != 0) {
294 cs_error(link->handle, RegisterClient, ret);
295 fmvj18x_detach(link);
296 return NULL;
299 return link;
300 } /* fmvj18x_attach */
302 /*====================================================================*/
304 static void fmvj18x_detach(dev_link_t *link)
306 struct net_device *dev = link->priv;
307 dev_link_t **linkp;
309 DEBUG(0, "fmvj18x_detach(0x%p)\n", link);
311 /* Locate device structure */
312 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
313 if (*linkp == link) break;
314 if (*linkp == NULL)
315 return;
317 if (link->dev)
318 unregister_netdev(dev);
320 if (link->state & DEV_CONFIG)
321 fmvj18x_release(link);
323 /* Break the link with Card Services */
324 if (link->handle)
325 pcmcia_deregister_client(link->handle);
327 /* Unlink device structure, free pieces */
328 *linkp = link->next;
329 free_netdev(dev);
330 } /* fmvj18x_detach */
332 /*====================================================================*/
334 #define CS_CHECK(fn, ret) \
335 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
337 static int mfc_try_io_port(dev_link_t *link)
339 int i, ret;
340 static kio_addr_t serial_base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
342 for (i = 0; i < 5; i++) {
343 link->io.BasePort2 = serial_base[i];
344 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
345 if (link->io.BasePort2 == 0) {
346 link->io.NumPorts2 = 0;
347 printk(KERN_NOTICE "fmvj18x_cs: out of resource for serial\n");
349 ret = pcmcia_request_io(link->handle, &link->io);
350 if (ret == CS_SUCCESS) return ret;
352 return ret;
355 static int ungermann_try_io_port(dev_link_t *link)
357 int ret;
358 kio_addr_t ioaddr;
360 Ungermann-Bass Access/CARD accepts 0x300,0x320,0x340,0x360
361 0x380,0x3c0 only for ioport.
363 for (ioaddr = 0x300; ioaddr < 0x3e0; ioaddr += 0x20) {
364 link->io.BasePort1 = ioaddr;
365 ret = pcmcia_request_io(link->handle, &link->io);
366 if (ret == CS_SUCCESS) {
367 /* calculate ConfigIndex value */
368 link->conf.ConfigIndex =
369 ((link->io.BasePort1 & 0x0f0) >> 3) | 0x22;
370 return ret;
373 return ret; /* RequestIO failed */
376 static void fmvj18x_config(dev_link_t *link)
378 client_handle_t handle = link->handle;
379 struct net_device *dev = link->priv;
380 local_info_t *lp = netdev_priv(dev);
381 tuple_t tuple;
382 cisparse_t parse;
383 u_short buf[32];
384 int i, last_fn, last_ret, ret;
385 kio_addr_t ioaddr;
386 cardtype_t cardtype;
387 char *card_name = "unknown";
388 u_char *node_id;
390 DEBUG(0, "fmvj18x_config(0x%p)\n", link);
393 This reads the card's CONFIG tuple to find its configuration
394 registers.
396 tuple.DesiredTuple = CISTPL_CONFIG;
397 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
398 tuple.TupleData = (u_char *)buf;
399 tuple.TupleDataMax = 64;
400 tuple.TupleOffset = 0;
401 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
402 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
404 /* Configure card */
405 link->state |= DEV_CONFIG;
407 link->conf.ConfigBase = parse.config.base;
408 link->conf.Present = parse.config.rmask[0];
410 tuple.DesiredTuple = CISTPL_FUNCE;
411 tuple.TupleOffset = 0;
412 if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) {
413 /* Yes, I have CISTPL_FUNCE. Let's check CISTPL_MANFID */
414 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
415 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
416 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
417 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
418 link->conf.ConfigIndex = parse.cftable_entry.index;
419 tuple.DesiredTuple = CISTPL_MANFID;
420 if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS)
421 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
422 else
423 buf[0] = 0xffff;
424 switch (le16_to_cpu(buf[0])) {
425 case MANFID_TDK:
426 cardtype = TDK;
427 if (le16_to_cpu(buf[1]) == PRODID_TDK_CF010) {
428 cs_status_t status;
429 pcmcia_get_status(handle, &status);
430 if (status.CardState & CS_EVENT_3VCARD)
431 link->conf.Vcc = 33; /* inserted in 3.3V slot */
432 } else if (le16_to_cpu(buf[1]) == PRODID_TDK_GN3410
433 || le16_to_cpu(buf[1]) == PRODID_TDK_NP9610
434 || le16_to_cpu(buf[1]) == PRODID_TDK_MN3200) {
435 /* MultiFunction Card */
436 link->conf.ConfigBase = 0x800;
437 link->conf.ConfigIndex = 0x47;
438 link->io.NumPorts2 = 8;
440 break;
441 case MANFID_CONTEC:
442 cardtype = CONTEC;
443 break;
444 case MANFID_FUJITSU:
445 if (le16_to_cpu(buf[1]) == PRODID_FUJITSU_MBH10302)
446 /* RATOC REX-5588/9822/4886's PRODID are 0004(=MBH10302),
447 but these are MBH10304 based card. */
448 cardtype = MBH10304;
449 else if (le16_to_cpu(buf[1]) == PRODID_FUJITSU_MBH10304)
450 cardtype = MBH10304;
451 else
452 cardtype = LA501;
453 break;
454 default:
455 cardtype = MBH10304;
457 } else {
458 /* old type card */
459 tuple.DesiredTuple = CISTPL_MANFID;
460 if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS)
461 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
462 else
463 buf[0] = 0xffff;
464 switch (le16_to_cpu(buf[0])) {
465 case MANFID_FUJITSU:
466 if (le16_to_cpu(buf[1]) == PRODID_FUJITSU_MBH10304) {
467 cardtype = XXX10304; /* MBH10304 with buggy CIS */
468 link->conf.ConfigIndex = 0x20;
469 } else {
470 cardtype = MBH10302; /* NextCom NC5310, etc. */
471 link->conf.ConfigIndex = 1;
473 break;
474 case MANFID_UNGERMANN:
475 cardtype = UNGERMANN;
476 break;
477 default:
478 cardtype = MBH10302;
479 link->conf.ConfigIndex = 1;
483 if (link->io.NumPorts2 != 0) {
484 link->irq.Attributes =
485 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT;
486 ret = mfc_try_io_port(link);
487 if (ret != CS_SUCCESS) goto cs_failed;
488 } else if (cardtype == UNGERMANN) {
489 ret = ungermann_try_io_port(link);
490 if (ret != CS_SUCCESS) goto cs_failed;
491 } else {
492 CS_CHECK(RequestIO, pcmcia_request_io(link->handle, &link->io));
494 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq));
495 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf));
496 dev->irq = link->irq.AssignedIRQ;
497 dev->base_addr = link->io.BasePort1;
499 if (link->io.BasePort2 != 0)
500 fmvj18x_setup_mfc(link);
502 ioaddr = dev->base_addr;
504 /* Reset controller */
505 if (sram_config == 0)
506 outb(CONFIG0_RST, ioaddr + CONFIG_0);
507 else
508 outb(CONFIG0_RST_1, ioaddr + CONFIG_0);
510 /* Power On chip and select bank 0 */
511 if (cardtype == MBH10302)
512 outb(BANK_0, ioaddr + CONFIG_1);
513 else
514 outb(BANK_0U, ioaddr + CONFIG_1);
516 /* Set hardware address */
517 switch (cardtype) {
518 case MBH10304:
519 case TDK:
520 case LA501:
521 case CONTEC:
522 tuple.DesiredTuple = CISTPL_FUNCE;
523 tuple.TupleOffset = 0;
524 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
525 tuple.TupleOffset = 0;
526 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
527 if (cardtype == MBH10304) {
528 /* MBH10304's CIS_FUNCE is corrupted */
529 node_id = &(tuple.TupleData[5]);
530 card_name = "FMV-J182";
531 } else {
532 while (tuple.TupleData[0] != CISTPL_FUNCE_LAN_NODE_ID ) {
533 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple));
534 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
536 node_id = &(tuple.TupleData[2]);
537 if( cardtype == TDK ) {
538 card_name = "TDK LAK-CD021";
539 } else if( cardtype == LA501 ) {
540 card_name = "LA501";
541 } else {
542 card_name = "C-NET(PC)C";
545 /* Read MACID from CIS */
546 for (i = 0; i < 6; i++)
547 dev->dev_addr[i] = node_id[i];
548 break;
549 case UNGERMANN:
550 /* Read MACID from register */
551 for (i = 0; i < 6; i++)
552 dev->dev_addr[i] = inb(ioaddr + UNGERMANN_MAC_ID + i);
553 card_name = "Access/CARD";
554 break;
555 case XXX10304:
556 /* Read MACID from Buggy CIS */
557 if (fmvj18x_get_hwinfo(link, tuple.TupleData) == -1) {
558 printk(KERN_NOTICE "fmvj18x_cs: unable to read hardware net address.\n");
559 goto failed;
561 for (i = 0 ; i < 6; i++) {
562 dev->dev_addr[i] = tuple.TupleData[i];
564 card_name = "FMV-J182";
565 break;
566 case MBH10302:
567 default:
568 /* Read MACID from register */
569 for (i = 0; i < 6; i++)
570 dev->dev_addr[i] = inb(ioaddr + MAC_ID + i);
571 card_name = "FMV-J181";
572 break;
575 lp->cardtype = cardtype;
576 link->dev = &lp->node;
577 link->state &= ~DEV_CONFIG_PENDING;
578 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
580 if (register_netdev(dev) != 0) {
581 printk(KERN_NOTICE "fmvj18x_cs: register_netdev() failed\n");
582 link->dev = NULL;
583 goto failed;
586 strcpy(lp->node.dev_name, dev->name);
588 /* print current configuration */
589 printk(KERN_INFO "%s: %s, sram %s, port %#3lx, irq %d, hw_addr ",
590 dev->name, card_name, sram_config == 0 ? "4K TX*2" : "8K TX*2",
591 dev->base_addr, dev->irq);
592 for (i = 0; i < 6; i++)
593 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
595 return;
597 cs_failed:
598 /* All Card Services errors end up here */
599 cs_error(link->handle, last_fn, last_ret);
600 failed:
601 fmvj18x_release(link);
602 link->state &= ~DEV_CONFIG_PENDING;
604 } /* fmvj18x_config */
605 /*====================================================================*/
607 static int fmvj18x_get_hwinfo(dev_link_t *link, u_char *node_id)
609 win_req_t req;
610 memreq_t mem;
611 u_char __iomem *base;
612 int i, j;
614 /* Allocate a small memory window */
615 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
616 req.Base = 0; req.Size = 0;
617 req.AccessSpeed = 0;
618 i = pcmcia_request_window(&link->handle, &req, &link->win);
619 if (i != CS_SUCCESS) {
620 cs_error(link->handle, RequestWindow, i);
621 return -1;
624 base = ioremap(req.Base, req.Size);
625 mem.Page = 0;
626 mem.CardOffset = 0;
627 pcmcia_map_mem_page(link->win, &mem);
630 * MBH10304 CISTPL_FUNCE_LAN_NODE_ID format
631 * 22 0d xx xx xx 04 06 yy yy yy yy yy yy ff
632 * 'xx' is garbage.
633 * 'yy' is MAC address.
635 for (i = 0; i < 0x200; i++) {
636 if (readb(base+i*2) == 0x22) {
637 if (readb(base+(i-1)*2) == 0xff
638 && readb(base+(i+5)*2) == 0x04
639 && readb(base+(i+6)*2) == 0x06
640 && readb(base+(i+13)*2) == 0xff)
641 break;
645 if (i != 0x200) {
646 for (j = 0 ; j < 6; j++,i++) {
647 node_id[j] = readb(base+(i+7)*2);
651 iounmap(base);
652 j = pcmcia_release_window(link->win);
653 if (j != CS_SUCCESS)
654 cs_error(link->handle, ReleaseWindow, j);
655 return (i != 0x200) ? 0 : -1;
657 } /* fmvj18x_get_hwinfo */
658 /*====================================================================*/
660 static int fmvj18x_setup_mfc(dev_link_t *link)
662 win_req_t req;
663 memreq_t mem;
664 u_char __iomem *base;
665 int i, j;
666 struct net_device *dev = link->priv;
667 kio_addr_t ioaddr;
669 /* Allocate a small memory window */
670 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
671 req.Base = 0; req.Size = 0;
672 req.AccessSpeed = 0;
673 i = pcmcia_request_window(&link->handle, &req, &link->win);
674 if (i != CS_SUCCESS) {
675 cs_error(link->handle, RequestWindow, i);
676 return -1;
679 base = ioremap(req.Base, req.Size);
680 mem.Page = 0;
681 mem.CardOffset = 0;
682 pcmcia_map_mem_page(link->win, &mem);
684 ioaddr = dev->base_addr;
685 writeb(0x47, base+0x800); /* Config Option Register of LAN */
686 writeb(0x0, base+0x802); /* Config and Status Register */
688 writeb(ioaddr & 0xff, base+0x80a); /* I/O Base(Low) of LAN */
689 writeb((ioaddr >> 8) & 0xff, base+0x80c); /* I/O Base(High) of LAN */
691 writeb(0x45, base+0x820); /* Config Option Register of Modem */
692 writeb(0x8, base+0x822); /* Config and Status Register */
694 iounmap(base);
695 j = pcmcia_release_window(link->win);
696 if (j != CS_SUCCESS)
697 cs_error(link->handle, ReleaseWindow, j);
698 return 0;
701 /*====================================================================*/
703 static void fmvj18x_release(dev_link_t *link)
706 DEBUG(0, "fmvj18x_release(0x%p)\n", link);
708 /* Don't bother checking to see if these succeed or not */
709 pcmcia_release_window(link->win);
710 pcmcia_release_configuration(link->handle);
711 pcmcia_release_io(link->handle, &link->io);
712 pcmcia_release_irq(link->handle, &link->irq);
714 link->state &= ~DEV_CONFIG;
717 /*====================================================================*/
719 static int fmvj18x_event(event_t event, int priority,
720 event_callback_args_t *args)
722 dev_link_t *link = args->client_data;
723 struct net_device *dev = link->priv;
725 DEBUG(1, "fmvj18x_event(0x%06x)\n", event);
727 switch (event) {
728 case CS_EVENT_CARD_REMOVAL:
729 link->state &= ~DEV_PRESENT;
730 if (link->state & DEV_CONFIG)
731 netif_device_detach(dev);
732 break;
733 case CS_EVENT_CARD_INSERTION:
734 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
735 fmvj18x_config(link);
736 break;
737 case CS_EVENT_PM_SUSPEND:
738 link->state |= DEV_SUSPEND;
739 /* Fall through... */
740 case CS_EVENT_RESET_PHYSICAL:
741 if (link->state & DEV_CONFIG) {
742 if (link->open)
743 netif_device_detach(dev);
744 pcmcia_release_configuration(link->handle);
746 break;
747 case CS_EVENT_PM_RESUME:
748 link->state &= ~DEV_SUSPEND;
749 /* Fall through... */
750 case CS_EVENT_CARD_RESET:
751 if (link->state & DEV_CONFIG) {
752 pcmcia_request_configuration(link->handle, &link->conf);
753 if (link->open) {
754 fjn_reset(dev);
755 netif_device_attach(dev);
758 break;
760 return 0;
761 } /* fmvj18x_event */
763 static struct pcmcia_device_id fmvj18x_ids[] = {
764 PCMCIA_DEVICE_MANF_CARD(0x0004, 0x0004),
765 PCMCIA_DEVICE_PROD_ID12("EAGLE Technology", "NE200 ETHERNET LAN MBH10302 04", 0x528c88c4, 0x74f91e59),
766 PCMCIA_DEVICE_PROD_ID12("Eiger Labs,Inc", "EPX-10BT PC Card Ethernet 10BT", 0x53af556e, 0x877f9922),
767 PCMCIA_DEVICE_PROD_ID12("Eiger labs,Inc.", "EPX-10BT PC Card Ethernet 10BT", 0xf47e6c66, 0x877f9922),
768 PCMCIA_DEVICE_PROD_ID12("FUJITSU", "LAN Card(FMV-J182)", 0x6ee5a3d8, 0x5baf31db),
769 PCMCIA_DEVICE_PROD_ID12("FUJITSU", "MBH10308", 0x6ee5a3d8, 0x3f04875e),
770 PCMCIA_DEVICE_PROD_ID12("FUJITSU TOWA", "LA501", 0xb8451188, 0x12939ba2),
771 PCMCIA_DEVICE_PROD_ID12("HITACHI", "HT-4840-11", 0xf4f43949, 0x773910f4),
772 PCMCIA_DEVICE_PROD_ID12("NextComK.K.", "NC5310B Ver1.0 ", 0x8cef4d3a, 0x075fc7b6),
773 PCMCIA_DEVICE_PROD_ID12("NextComK.K.", "NC5310 Ver1.0 ", 0x8cef4d3a, 0xbccf43e6),
774 PCMCIA_DEVICE_PROD_ID12("RATOC System Inc.", "10BASE_T CARD R280", 0x85c10e17, 0xd9413666),
775 PCMCIA_DEVICE_PROD_ID12("TDK", "LAC-CD02x", 0x1eae9475, 0x8fa0ee70),
776 PCMCIA_DEVICE_PROD_ID12("TDK", "LAC-CF010", 0x1eae9475, 0x7683bc9a),
777 PCMCIA_DEVICE_PROD_ID1("CONTEC Co.,Ltd.", 0x58d8fee2),
778 PCMCIA_DEVICE_PROD_ID1("PCMCIA LAN MBH10304 ES", 0x2599f454),
779 PCMCIA_DEVICE_PROD_ID1("PCMCIA MBH10302", 0x8f4005da),
780 PCMCIA_DEVICE_PROD_ID1("UBKK,V2.0", 0x90888080),
781 PCMCIA_PFC_DEVICE_PROD_ID12(0, "TDK", "GlobalNetworker 3410/3412", 0x1eae9475, 0xd9a93bed),
782 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0105, 0x0d0a),
783 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0105, 0x0e0a),
784 PCMCIA_DEVICE_NULL,
786 MODULE_DEVICE_TABLE(pcmcia, fmvj18x_ids);
788 static struct pcmcia_driver fmvj18x_cs_driver = {
789 .owner = THIS_MODULE,
790 .drv = {
791 .name = "fmvj18x_cs",
793 .attach = fmvj18x_attach,
794 .event = fmvj18x_event,
795 .detach = fmvj18x_detach,
796 .id_table = fmvj18x_ids,
799 static int __init init_fmvj18x_cs(void)
801 return pcmcia_register_driver(&fmvj18x_cs_driver);
804 static void __exit exit_fmvj18x_cs(void)
806 pcmcia_unregister_driver(&fmvj18x_cs_driver);
807 BUG_ON(dev_list != NULL);
810 module_init(init_fmvj18x_cs);
811 module_exit(exit_fmvj18x_cs);
813 /*====================================================================*/
815 static irqreturn_t fjn_interrupt(int irq, void *dev_id, struct pt_regs *regs)
817 struct net_device *dev = dev_id;
818 local_info_t *lp = netdev_priv(dev);
819 kio_addr_t ioaddr;
820 unsigned short tx_stat, rx_stat;
822 if (lp == NULL) {
823 printk(KERN_NOTICE "fjn_interrupt(): irq %d for "
824 "unknown device.\n", irq);
825 return IRQ_NONE;
827 ioaddr = dev->base_addr;
829 /* avoid multiple interrupts */
830 outw(0x0000, ioaddr + TX_INTR);
832 /* wait for a while */
833 udelay(1);
835 /* get status */
836 tx_stat = inb(ioaddr + TX_STATUS);
837 rx_stat = inb(ioaddr + RX_STATUS);
839 /* clear status */
840 outb(tx_stat, ioaddr + TX_STATUS);
841 outb(rx_stat, ioaddr + RX_STATUS);
843 DEBUG(4, "%s: interrupt, rx_status %02x.\n", dev->name, rx_stat);
844 DEBUG(4, " tx_status %02x.\n", tx_stat);
846 if (rx_stat || (inb(ioaddr + RX_MODE) & F_BUF_EMP) == 0) {
847 /* there is packet(s) in rx buffer */
848 fjn_rx(dev);
850 if (tx_stat & F_TMT_RDY) {
851 lp->stats.tx_packets += lp->sent ;
852 lp->sent = 0 ;
853 if (lp->tx_queue) {
854 outb(DO_TX | lp->tx_queue, ioaddr + TX_START);
855 lp->sent = lp->tx_queue ;
856 lp->tx_queue = 0;
857 lp->tx_queue_len = 0;
858 dev->trans_start = jiffies;
859 } else {
860 lp->tx_started = 0;
862 netif_wake_queue(dev);
864 DEBUG(4, "%s: exiting interrupt,\n", dev->name);
865 DEBUG(4, " tx_status %02x, rx_status %02x.\n", tx_stat, rx_stat);
867 outb(D_TX_INTR, ioaddr + TX_INTR);
868 outb(D_RX_INTR, ioaddr + RX_INTR);
869 return IRQ_HANDLED;
871 } /* fjn_interrupt */
873 /*====================================================================*/
875 static void fjn_tx_timeout(struct net_device *dev)
877 struct local_info_t *lp = netdev_priv(dev);
878 kio_addr_t ioaddr = dev->base_addr;
880 printk(KERN_NOTICE "%s: transmit timed out with status %04x, %s?\n",
881 dev->name, htons(inw(ioaddr + TX_STATUS)),
882 inb(ioaddr + TX_STATUS) & F_TMT_RDY
883 ? "IRQ conflict" : "network cable problem");
884 printk(KERN_NOTICE "%s: timeout registers: %04x %04x %04x "
885 "%04x %04x %04x %04x %04x.\n",
886 dev->name, htons(inw(ioaddr + 0)),
887 htons(inw(ioaddr + 2)), htons(inw(ioaddr + 4)),
888 htons(inw(ioaddr + 6)), htons(inw(ioaddr + 8)),
889 htons(inw(ioaddr +10)), htons(inw(ioaddr +12)),
890 htons(inw(ioaddr +14)));
891 lp->stats.tx_errors++;
892 /* ToDo: We should try to restart the adaptor... */
893 local_irq_disable();
894 fjn_reset(dev);
896 lp->tx_started = 0;
897 lp->tx_queue = 0;
898 lp->tx_queue_len = 0;
899 lp->sent = 0;
900 lp->open_time = jiffies;
901 local_irq_enable();
902 netif_wake_queue(dev);
905 static int fjn_start_xmit(struct sk_buff *skb, struct net_device *dev)
907 struct local_info_t *lp = netdev_priv(dev);
908 kio_addr_t ioaddr = dev->base_addr;
909 short length = skb->len;
911 if (length < ETH_ZLEN)
913 skb = skb_padto(skb, ETH_ZLEN);
914 if (skb == NULL)
915 return 0;
916 length = ETH_ZLEN;
919 netif_stop_queue(dev);
922 unsigned char *buf = skb->data;
924 if (length > ETH_FRAME_LEN) {
925 printk(KERN_NOTICE "%s: Attempting to send a large packet"
926 " (%d bytes).\n", dev->name, length);
927 return 1;
930 DEBUG(4, "%s: Transmitting a packet of length %lu.\n",
931 dev->name, (unsigned long)skb->len);
932 lp->stats.tx_bytes += skb->len;
934 /* Disable both interrupts. */
935 outw(0x0000, ioaddr + TX_INTR);
937 /* wait for a while */
938 udelay(1);
940 outw(length, ioaddr + DATAPORT);
941 outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1);
943 lp->tx_queue++;
944 lp->tx_queue_len += ((length+3) & ~1);
946 if (lp->tx_started == 0) {
947 /* If the Tx is idle, always trigger a transmit. */
948 outb(DO_TX | lp->tx_queue, ioaddr + TX_START);
949 lp->sent = lp->tx_queue ;
950 lp->tx_queue = 0;
951 lp->tx_queue_len = 0;
952 dev->trans_start = jiffies;
953 lp->tx_started = 1;
954 netif_start_queue(dev);
955 } else {
956 if( sram_config == 0 ) {
957 if (lp->tx_queue_len < (4096 - (ETH_FRAME_LEN +2)) )
958 /* Yes, there is room for one more packet. */
959 netif_start_queue(dev);
960 } else {
961 if (lp->tx_queue_len < (8192 - (ETH_FRAME_LEN +2)) &&
962 lp->tx_queue < 127 )
963 /* Yes, there is room for one more packet. */
964 netif_start_queue(dev);
968 /* Re-enable interrupts */
969 outb(D_TX_INTR, ioaddr + TX_INTR);
970 outb(D_RX_INTR, ioaddr + RX_INTR);
972 dev_kfree_skb (skb);
974 return 0;
975 } /* fjn_start_xmit */
977 /*====================================================================*/
979 static void fjn_reset(struct net_device *dev)
981 struct local_info_t *lp = netdev_priv(dev);
982 kio_addr_t ioaddr = dev->base_addr;
983 int i;
985 DEBUG(4, "fjn_reset(%s) called.\n",dev->name);
987 /* Reset controller */
988 if( sram_config == 0 )
989 outb(CONFIG0_RST, ioaddr + CONFIG_0);
990 else
991 outb(CONFIG0_RST_1, ioaddr + CONFIG_0);
993 /* Power On chip and select bank 0 */
994 if (lp->cardtype == MBH10302)
995 outb(BANK_0, ioaddr + CONFIG_1);
996 else
997 outb(BANK_0U, ioaddr + CONFIG_1);
999 /* Set Tx modes */
1000 outb(D_TX_MODE, ioaddr + TX_MODE);
1001 /* set Rx modes */
1002 outb(ID_MATCHED, ioaddr + RX_MODE);
1004 /* Set hardware address */
1005 for (i = 0; i < 6; i++)
1006 outb(dev->dev_addr[i], ioaddr + NODE_ID + i);
1008 /* Switch to bank 1 */
1009 if (lp->cardtype == MBH10302)
1010 outb(BANK_1, ioaddr + CONFIG_1);
1011 else
1012 outb(BANK_1U, ioaddr + CONFIG_1);
1014 /* set the multicast table to accept none. */
1015 for (i = 0; i < 8; i++)
1016 outb(0x00, ioaddr + MAR_ADR + i);
1018 /* Switch to bank 2 (runtime mode) */
1019 if (lp->cardtype == MBH10302)
1020 outb(BANK_2, ioaddr + CONFIG_1);
1021 else
1022 outb(BANK_2U, ioaddr + CONFIG_1);
1024 /* set 16col ctrl bits */
1025 if( lp->cardtype == TDK || lp->cardtype == CONTEC)
1026 outb(TDK_AUTO_MODE, ioaddr + COL_CTRL);
1027 else
1028 outb(AUTO_MODE, ioaddr + COL_CTRL);
1030 /* clear Reserved Regs */
1031 outb(0x00, ioaddr + BMPR12);
1032 outb(0x00, ioaddr + BMPR13);
1034 /* reset Skip packet reg. */
1035 outb(0x01, ioaddr + RX_SKIP);
1037 /* Enable Tx and Rx */
1038 if( sram_config == 0 )
1039 outb(CONFIG0_DFL, ioaddr + CONFIG_0);
1040 else
1041 outb(CONFIG0_DFL_1, ioaddr + CONFIG_0);
1043 /* Init receive pointer ? */
1044 inw(ioaddr + DATAPORT);
1045 inw(ioaddr + DATAPORT);
1047 /* Clear all status */
1048 outb(0xff, ioaddr + TX_STATUS);
1049 outb(0xff, ioaddr + RX_STATUS);
1051 if (lp->cardtype == MBH10302)
1052 outb(INTR_OFF, ioaddr + LAN_CTRL);
1054 /* Turn on Rx interrupts */
1055 outb(D_TX_INTR, ioaddr + TX_INTR);
1056 outb(D_RX_INTR, ioaddr + RX_INTR);
1058 /* Turn on interrupts from LAN card controller */
1059 if (lp->cardtype == MBH10302)
1060 outb(INTR_ON, ioaddr + LAN_CTRL);
1061 } /* fjn_reset */
1063 /*====================================================================*/
1065 static void fjn_rx(struct net_device *dev)
1067 struct local_info_t *lp = netdev_priv(dev);
1068 kio_addr_t ioaddr = dev->base_addr;
1069 int boguscount = 10; /* 5 -> 10: by agy 19940922 */
1071 DEBUG(4, "%s: in rx_packet(), rx_status %02x.\n",
1072 dev->name, inb(ioaddr + RX_STATUS));
1074 while ((inb(ioaddr + RX_MODE) & F_BUF_EMP) == 0) {
1075 u_short status = inw(ioaddr + DATAPORT);
1077 DEBUG(4, "%s: Rxing packet mode %02x status %04x.\n",
1078 dev->name, inb(ioaddr + RX_MODE), status);
1079 #ifndef final_version
1080 if (status == 0) {
1081 outb(F_SKP_PKT, ioaddr + RX_SKIP);
1082 break;
1084 #endif
1085 if ((status & 0xF0) != 0x20) { /* There was an error. */
1086 lp->stats.rx_errors++;
1087 if (status & F_LEN_ERR) lp->stats.rx_length_errors++;
1088 if (status & F_ALG_ERR) lp->stats.rx_frame_errors++;
1089 if (status & F_CRC_ERR) lp->stats.rx_crc_errors++;
1090 if (status & F_OVR_FLO) lp->stats.rx_over_errors++;
1091 } else {
1092 u_short pkt_len = inw(ioaddr + DATAPORT);
1093 /* Malloc up new buffer. */
1094 struct sk_buff *skb;
1096 if (pkt_len > 1550) {
1097 printk(KERN_NOTICE "%s: The FMV-18x claimed a very "
1098 "large packet, size %d.\n", dev->name, pkt_len);
1099 outb(F_SKP_PKT, ioaddr + RX_SKIP);
1100 lp->stats.rx_errors++;
1101 break;
1103 skb = dev_alloc_skb(pkt_len+2);
1104 if (skb == NULL) {
1105 printk(KERN_NOTICE "%s: Memory squeeze, dropping "
1106 "packet (len %d).\n", dev->name, pkt_len);
1107 outb(F_SKP_PKT, ioaddr + RX_SKIP);
1108 lp->stats.rx_dropped++;
1109 break;
1111 skb->dev = dev;
1113 skb_reserve(skb, 2);
1114 insw(ioaddr + DATAPORT, skb_put(skb, pkt_len),
1115 (pkt_len + 1) >> 1);
1116 skb->protocol = eth_type_trans(skb, dev);
1118 #ifdef PCMCIA_DEBUG
1119 if (pc_debug > 5) {
1120 int i;
1121 printk(KERN_DEBUG "%s: Rxed packet of length %d: ",
1122 dev->name, pkt_len);
1123 for (i = 0; i < 14; i++)
1124 printk(" %02x", skb->data[i]);
1125 printk(".\n");
1127 #endif
1129 netif_rx(skb);
1130 dev->last_rx = jiffies;
1131 lp->stats.rx_packets++;
1132 lp->stats.rx_bytes += pkt_len;
1134 if (--boguscount <= 0)
1135 break;
1138 /* If any worth-while packets have been received, dev_rint()
1139 has done a netif_wake_queue() for us and will work on them
1140 when we get to the bottom-half routine. */
1142 if (lp->cardtype != TDK) {
1143 int i;
1144 for (i = 0; i < 20; i++) {
1145 if ((inb(ioaddr + RX_MODE) & F_BUF_EMP) == F_BUF_EMP)
1146 break;
1147 (void)inw(ioaddr + DATAPORT); /+ dummy status read +/
1148 outb(F_SKP_PKT, ioaddr + RX_SKIP);
1151 if (i > 0)
1152 DEBUG(5, "%s: Exint Rx packet with mode %02x after "
1153 "%d ticks.\n", dev->name, inb(ioaddr + RX_MODE), i);
1157 return;
1158 } /* fjn_rx */
1160 /*====================================================================*/
1162 static void netdev_get_drvinfo(struct net_device *dev,
1163 struct ethtool_drvinfo *info)
1165 strcpy(info->driver, DRV_NAME);
1166 strcpy(info->version, DRV_VERSION);
1167 sprintf(info->bus_info, "PCMCIA 0x%lx", dev->base_addr);
1170 #ifdef PCMCIA_DEBUG
1171 static u32 netdev_get_msglevel(struct net_device *dev)
1173 return pc_debug;
1176 static void netdev_set_msglevel(struct net_device *dev, u32 level)
1178 pc_debug = level;
1180 #endif /* PCMCIA_DEBUG */
1182 static struct ethtool_ops netdev_ethtool_ops = {
1183 .get_drvinfo = netdev_get_drvinfo,
1184 #ifdef PCMCIA_DEBUG
1185 .get_msglevel = netdev_get_msglevel,
1186 .set_msglevel = netdev_set_msglevel,
1187 #endif /* PCMCIA_DEBUG */
1190 static int fjn_config(struct net_device *dev, struct ifmap *map){
1191 return 0;
1194 static int fjn_open(struct net_device *dev)
1196 struct local_info_t *lp = netdev_priv(dev);
1197 dev_link_t *link = &lp->link;
1199 DEBUG(4, "fjn_open('%s').\n", dev->name);
1201 if (!DEV_OK(link))
1202 return -ENODEV;
1204 link->open++;
1206 fjn_reset(dev);
1208 lp->tx_started = 0;
1209 lp->tx_queue = 0;
1210 lp->tx_queue_len = 0;
1211 lp->open_time = jiffies;
1212 netif_start_queue(dev);
1214 return 0;
1215 } /* fjn_open */
1217 /*====================================================================*/
1219 static int fjn_close(struct net_device *dev)
1221 struct local_info_t *lp = netdev_priv(dev);
1222 dev_link_t *link = &lp->link;
1223 kio_addr_t ioaddr = dev->base_addr;
1225 DEBUG(4, "fjn_close('%s').\n", dev->name);
1227 lp->open_time = 0;
1228 netif_stop_queue(dev);
1230 /* Set configuration register 0 to disable Tx and Rx. */
1231 if( sram_config == 0 )
1232 outb(CONFIG0_RST ,ioaddr + CONFIG_0);
1233 else
1234 outb(CONFIG0_RST_1 ,ioaddr + CONFIG_0);
1236 /* Update the statistics -- ToDo. */
1238 /* Power-down the chip. Green, green, green! */
1239 outb(CHIP_OFF ,ioaddr + CONFIG_1);
1241 /* Set the ethernet adaptor disable IRQ */
1242 if (lp->cardtype == MBH10302)
1243 outb(INTR_OFF, ioaddr + LAN_CTRL);
1245 link->open--;
1247 return 0;
1248 } /* fjn_close */
1250 /*====================================================================*/
1252 static struct net_device_stats *fjn_get_stats(struct net_device *dev)
1254 local_info_t *lp = netdev_priv(dev);
1255 return &lp->stats;
1256 } /* fjn_get_stats */
1258 /*====================================================================*/
1261 Set the multicast/promiscuous mode for this adaptor.
1264 static void set_rx_mode(struct net_device *dev)
1266 kio_addr_t ioaddr = dev->base_addr;
1267 struct local_info_t *lp = netdev_priv(dev);
1268 u_char mc_filter[8]; /* Multicast hash filter */
1269 u_long flags;
1270 int i;
1272 int saved_config_0 = inb(ioaddr + CONFIG_0);
1274 local_irq_save(flags);
1276 /* Disable Tx and Rx */
1277 if (sram_config == 0)
1278 outb(CONFIG0_RST, ioaddr + CONFIG_0);
1279 else
1280 outb(CONFIG0_RST_1, ioaddr + CONFIG_0);
1282 if (dev->flags & IFF_PROMISC) {
1283 /* Unconditionally log net taps. */
1284 printk("%s: Promiscuous mode enabled.\n", dev->name);
1285 memset(mc_filter, 0xff, sizeof(mc_filter));
1286 outb(3, ioaddr + RX_MODE); /* Enable promiscuous mode */
1287 } else if (dev->mc_count > MC_FILTERBREAK
1288 || (dev->flags & IFF_ALLMULTI)) {
1289 /* Too many to filter perfectly -- accept all multicasts. */
1290 memset(mc_filter, 0xff, sizeof(mc_filter));
1291 outb(2, ioaddr + RX_MODE); /* Use normal mode. */
1292 } else if (dev->mc_count == 0) {
1293 memset(mc_filter, 0x00, sizeof(mc_filter));
1294 outb(1, ioaddr + RX_MODE); /* Ignore almost all multicasts. */
1295 } else {
1296 struct dev_mc_list *mclist;
1297 int i;
1299 memset(mc_filter, 0, sizeof(mc_filter));
1300 for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
1301 i++, mclist = mclist->next) {
1302 unsigned int bit =
1303 ether_crc_le(ETH_ALEN, mclist->dmi_addr) >> 26;
1304 mc_filter[bit >> 3] |= (1 << (bit & 7));
1306 outb(2, ioaddr + RX_MODE); /* Use normal mode. */
1309 if (memcmp(mc_filter, lp->mc_filter, sizeof(mc_filter))) {
1310 int saved_bank = inb(ioaddr + CONFIG_1);
1311 /* Switch to bank 1 and set the multicast table. */
1312 outb(0xe4, ioaddr + CONFIG_1);
1313 for (i = 0; i < 8; i++)
1314 outb(mc_filter[i], ioaddr + MAR_ADR + i);
1315 memcpy(lp->mc_filter, mc_filter, sizeof(mc_filter));
1316 outb(saved_bank, ioaddr + CONFIG_1);
1319 outb(saved_config_0, ioaddr + CONFIG_0);
1321 local_irq_restore(flags);