1 /*======================================================================
2     fmvj18x_cs.c 2.8 2002/03/23
3 
4     A fmvj18x (and its compatibles) PCMCIA client driver
5 
6     Contributed by Shingo Fujimoto, shingo@flab.fujitsu.co.jp
7 
8     TDK LAK-CD021 and CONTEC C-NET(PC)C support added by
9     Nobuhiro Katayama, kata-n@po.iijnet.or.jp
10 
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:
15 
16     Written 1993-94 by Donald Becker.
17 
18     Copyright 1993 United States Government as represented by the
19     Director, National Security Agency.
20 
21     This software may be used and distributed according to the terms
22     of the GNU General Public License, incorporated herein by reference.
23 
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
28 
29 ======================================================================*/
30 
31 #define DRV_NAME	"fmvj18x_cs"
32 #define DRV_VERSION	"2.8"
33 
34 #include <linux/module.h>
35 #include <linux/kernel.h>
36 #include <linux/init.h>
37 #include <linux/sched.h>
38 #include <linux/ptrace.h>
39 #include <linux/slab.h>
40 #include <linux/string.h>
41 #include <linux/timer.h>
42 #include <linux/interrupt.h>
43 #include <linux/in.h>
44 #include <linux/delay.h>
45 #include <linux/ethtool.h>
46 
47 #include <asm/uaccess.h>
48 #include <asm/io.h>
49 #include <asm/system.h>
50 
51 #include <linux/netdevice.h>
52 #include <linux/etherdevice.h>
53 #include <linux/skbuff.h>
54 #include <linux/if_arp.h>
55 #include <linux/ioport.h>
56 #include <linux/crc32.h>
57 
58 #include <pcmcia/version.h>
59 #include <pcmcia/cs_types.h>
60 #include <pcmcia/cs.h>
61 #include <pcmcia/cistpl.h>
62 #include <pcmcia/ciscode.h>
63 #include <pcmcia/ds.h>
64 
65 /*====================================================================*/
66 
67 /* Module parameters */
68 
69 MODULE_DESCRIPTION("fmvj18x and compatible PCMCIA ethernet driver");
70 MODULE_LICENSE("GPL");
71 
72 #define INT_MODULE_PARM(n, v) static int n = v; MODULE_PARM(n, "i")
73 
74 /* Bit map of interrupts to choose from */
75 /* This means pick from 15, 14, 12, 11, 10, 9, 7, 5, 4, and 3 */
76 INT_MODULE_PARM(irq_mask, 0xdeb8);
77 static int irq_list[4] = { -1 };
78 MODULE_PARM(irq_list, "1-4i");
79 
80 /* SRAM configuration */
81 /* 0:4KB*2 TX buffer   else:8KB*2 TX buffer */
82 INT_MODULE_PARM(sram_config, 0);
83 
84 #ifdef PCMCIA_DEBUG
85 INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);
86 #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
87 static char *version = DRV_NAME ".c " DRV_VERSION " 2002/03/23";
88 #else
89 #define DEBUG(n, args...)
90 #endif
91 
92 /*====================================================================*/
93 /*
94     PCMCIA event handlers
95  */
96 static void fmvj18x_config(dev_link_t *link);
97 static int fmvj18x_get_hwinfo(dev_link_t *link, u_char *node_id);
98 static int fmvj18x_setup_mfc(dev_link_t *link);
99 static void fmvj18x_release(u_long arg);
100 static int fmvj18x_event(event_t event, int priority,
101 			  event_callback_args_t *args);
102 static dev_link_t *fmvj18x_attach(void);
103 static void fmvj18x_detach(dev_link_t *);
104 
105 /*
106     LAN controller(MBH86960A) specific routines
107  */
108 static int fjn_config(struct net_device *dev, struct ifmap *map);
109 static int fjn_open(struct net_device *dev);
110 static int fjn_close(struct net_device *dev);
111 static int fjn_start_xmit(struct sk_buff *skb, struct net_device *dev);
112 static void fjn_interrupt(int irq, void *dev_id, struct pt_regs *regs);
113 static void fjn_rx(struct net_device *dev);
114 static void fjn_reset(struct net_device *dev);
115 static struct net_device_stats *fjn_get_stats(struct net_device *dev);
116 static void set_rx_mode(struct net_device *dev);
117 static void fjn_tx_timeout(struct net_device *dev);
118 static struct ethtool_ops netdev_ethtool_ops;
119 
120 static dev_info_t dev_info = "fmvj18x_cs";
121 static dev_link_t *dev_list;
122 
123 /*
124     card type
125  */
126 typedef enum { MBH10302, MBH10304, TDK, CONTEC, LA501, UNGERMANN,
127 	       XXX10304
128 } cardtype_t;
129 
130 /*
131     driver specific data structure
132 */
133 typedef struct local_info_t {
134     dev_link_t link;
135     struct net_device dev;
136     dev_node_t node;
137     struct net_device_stats stats;
138     long open_time;
139     uint tx_started:1;
140     uint tx_queue;
141     u_short tx_queue_len;
142     cardtype_t cardtype;
143     u_short sent;
144     u_char mc_filter[8];
145 } local_info_t;
146 
147 #define MC_FILTERBREAK 64
148 
149 /*====================================================================*/
150 /*
151     ioport offset from the base address
152  */
153 #define TX_STATUS               0 /* transmit status register */
154 #define RX_STATUS               1 /* receive status register */
155 #define TX_INTR                 2 /* transmit interrupt mask register */
156 #define RX_INTR                 3 /* receive interrupt mask register */
157 #define TX_MODE                 4 /* transmit mode register */
158 #define RX_MODE                 5 /* receive mode register */
159 #define CONFIG_0                6 /* configuration register 0 */
160 #define CONFIG_1                7 /* configuration register 1 */
161 
162 #define NODE_ID                 8 /* node ID register            (bank 0) */
163 #define MAR_ADR                 8 /* multicast address registers (bank 1) */
164 
165 #define DATAPORT                8 /* buffer mem port registers   (bank 2) */
166 #define TX_START               10 /* transmit start register */
167 #define COL_CTRL               11 /* 16 collision control register */
168 #define BMPR12                 12 /* reserved */
169 #define BMPR13                 13 /* reserved */
170 #define RX_SKIP                14 /* skip received packet register */
171 
172 #define LAN_CTRL               16 /* LAN card control register */
173 
174 #define MAC_ID               0x1a /* hardware address */
175 #define UNGERMANN_MAC_ID     0x18 /* UNGERMANN-BASS hardware address */
176 
177 /*
178     control bits
179  */
180 #define ENA_TMT_OK           0x80
181 #define ENA_TMT_REC          0x20
182 #define ENA_COL              0x04
183 #define ENA_16_COL           0x02
184 #define ENA_TBUS_ERR         0x01
185 
186 #define ENA_PKT_RDY          0x80
187 #define ENA_BUS_ERR          0x40
188 #define ENA_LEN_ERR          0x08
189 #define ENA_ALG_ERR          0x04
190 #define ENA_CRC_ERR          0x02
191 #define ENA_OVR_FLO          0x01
192 
193 /* flags */
194 #define F_TMT_RDY            0x80 /* can accept new packet */
195 #define F_NET_BSY            0x40 /* carrier is detected */
196 #define F_TMT_OK             0x20 /* send packet successfully */
197 #define F_SRT_PKT            0x10 /* short packet error */
198 #define F_COL_ERR            0x04 /* collision error */
199 #define F_16_COL             0x02 /* 16 collision error */
200 #define F_TBUS_ERR           0x01 /* bus read error */
201 
202 #define F_PKT_RDY            0x80 /* packet(s) in buffer */
203 #define F_BUS_ERR            0x40 /* bus read error */
204 #define F_LEN_ERR            0x08 /* short packet */
205 #define F_ALG_ERR            0x04 /* frame error */
206 #define F_CRC_ERR            0x02 /* CRC error */
207 #define F_OVR_FLO            0x01 /* overflow error */
208 
209 #define F_BUF_EMP            0x40 /* receive buffer is empty */
210 
211 #define F_SKP_PKT            0x05 /* drop packet in buffer */
212 
213 /* default bitmaps */
214 #define D_TX_INTR  ( ENA_TMT_OK )
215 #define D_RX_INTR  ( ENA_PKT_RDY | ENA_LEN_ERR \
216 		   | ENA_ALG_ERR | ENA_CRC_ERR | ENA_OVR_FLO )
217 #define TX_STAT_M  ( F_TMT_RDY )
218 #define RX_STAT_M  ( F_PKT_RDY | F_LEN_ERR \
219                    | F_ALG_ERR | F_CRC_ERR | F_OVR_FLO )
220 
221 /* commands */
222 #define D_TX_MODE            0x06 /* no tests, detect carrier */
223 #define ID_MATCHED           0x02 /* (RX_MODE) */
224 #define RECV_ALL             0x03 /* (RX_MODE) */
225 #define CONFIG0_DFL          0x5a /* 16bit bus, 4K x 2 Tx queues */
226 #define CONFIG0_DFL_1        0x5e /* 16bit bus, 8K x 2 Tx queues */
227 #define CONFIG0_RST          0xda /* Data Link Controller off (CONFIG_0) */
228 #define CONFIG0_RST_1        0xde /* Data Link Controller off (CONFIG_0) */
229 #define BANK_0               0xa0 /* bank 0 (CONFIG_1) */
230 #define BANK_1               0xa4 /* bank 1 (CONFIG_1) */
231 #define BANK_2               0xa8 /* bank 2 (CONFIG_1) */
232 #define CHIP_OFF             0x80 /* contrl chip power off (CONFIG_1) */
233 #define DO_TX                0x80 /* do transmit packet */
234 #define SEND_PKT             0x81 /* send a packet */
235 #define AUTO_MODE            0x07 /* Auto skip packet on 16 col detected */
236 #define MANU_MODE            0x03 /* Stop and skip packet on 16 col */
237 #define TDK_AUTO_MODE        0x47 /* Auto skip packet on 16 col detected */
238 #define TDK_MANU_MODE        0x43 /* Stop and skip packet on 16 col */
239 #define INTR_OFF             0x0d /* LAN controller ignores interrupts */
240 #define INTR_ON              0x1d /* LAN controller will catch interrupts */
241 
242 #define TX_TIMEOUT		((400*HZ)/1000)
243 
244 #define BANK_0U              0x20 /* bank 0 (CONFIG_1) */
245 #define BANK_1U              0x24 /* bank 1 (CONFIG_1) */
246 #define BANK_2U              0x28 /* bank 2 (CONFIG_1) */
247 
248 /*======================================================================
249 
250     This bit of code is used to avoid unregistering network devices
251     at inappropriate times.  2.2 and later kernels are fairly picky
252     about when this can happen.
253 
254 ======================================================================*/
255 
flush_stale_links(void)256 static void flush_stale_links(void)
257 {
258     dev_link_t *link, *next;
259     for (link = dev_list; link; link = next) {
260 	next = link->next;
261 	if (link->state & DEV_STALE_LINK)
262 	    fmvj18x_detach(link);
263     }
264 }
265 
266 /*====================================================================*/
267 
cs_error(client_handle_t handle,int func,int ret)268 static void cs_error(client_handle_t handle, int func, int ret)
269 {
270     error_info_t err = { func, ret };
271     CardServices(ReportError, handle, &err);
272 }
273 
274 /*====================================================================*/
275 
fmvj18x_attach(void)276 static dev_link_t *fmvj18x_attach(void)
277 {
278     local_info_t *lp;
279     dev_link_t *link;
280     struct net_device *dev;
281     client_reg_t client_reg;
282     int i, ret;
283 
284     DEBUG(0, "fmvj18x_attach()\n");
285     flush_stale_links();
286 
287     /* Make up a FMVJ18x specific data structure */
288     lp = kmalloc(sizeof(*lp), GFP_KERNEL);
289     if (!lp) return NULL;
290     memset(lp, 0, sizeof(*lp));
291     link = &lp->link; dev = &lp->dev;
292     link->priv = dev->priv = link->irq.Instance = lp;
293 
294     link->release.function = &fmvj18x_release;
295     link->release.data = (u_long)link;
296 
297     /* The io structure describes IO port mapping */
298     link->io.NumPorts1 = 32;
299     link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
300     link->io.IOAddrLines = 5;
301 
302     /* Interrupt setup */
303     link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
304     link->irq.IRQInfo1 = IRQ_INFO2_VALID|IRQ_LEVEL_ID;
305     if (irq_list[0] == -1)
306 	link->irq.IRQInfo2 = irq_mask;
307     else
308 	for (i = 0; i < 4; i++)
309 	    link->irq.IRQInfo2 |= 1 << irq_list[i];
310     link->irq.Handler = &fjn_interrupt;
311 
312     /* General socket configuration */
313     link->conf.Attributes = CONF_ENABLE_IRQ;
314     link->conf.Vcc = 50;
315     link->conf.IntType = INT_MEMORY_AND_IO;
316 
317     /* The FMVJ18x specific entries in the device structure. */
318     dev->hard_start_xmit = &fjn_start_xmit;
319     dev->set_config = &fjn_config;
320     dev->get_stats = &fjn_get_stats;
321     dev->set_multicast_list = &set_rx_mode;
322     ether_setup(dev);
323     dev->open = &fjn_open;
324     dev->stop = &fjn_close;
325 #ifdef HAVE_TX_TIMEOUT
326     dev->tx_timeout = fjn_tx_timeout;
327     dev->watchdog_timeo = TX_TIMEOUT;
328 #endif
329     SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
330 
331     /* Register with Card Services */
332     link->next = dev_list;
333     dev_list = link;
334     client_reg.dev_info = &dev_info;
335     client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
336     client_reg.EventMask =
337 	CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
338 	CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
339 	CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
340     client_reg.event_handler = &fmvj18x_event;
341     client_reg.Version = 0x0210;
342     client_reg.event_callback_args.client_data = link;
343     ret = CardServices(RegisterClient, &link->handle, &client_reg);
344     if (ret != 0) {
345 	cs_error(link->handle, RegisterClient, ret);
346 	fmvj18x_detach(link);
347 	return NULL;
348     }
349 
350     return link;
351 } /* fmvj18x_attach */
352 
353 /*====================================================================*/
354 
fmvj18x_detach(dev_link_t * link)355 static void fmvj18x_detach(dev_link_t *link)
356 {
357     local_info_t *lp = link->priv;
358     dev_link_t **linkp;
359 
360     DEBUG(0, "fmvj18x_detach(0x%p)\n", link);
361 
362     /* Locate device structure */
363     for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
364 	if (*linkp == link) break;
365     if (*linkp == NULL)
366 	return;
367 
368     del_timer_sync(&link->release);
369     if (link->state & DEV_CONFIG) {
370 	fmvj18x_release((u_long)link);
371 	if (link->state & DEV_STALE_CONFIG) {
372 	    link->state |= DEV_STALE_LINK;
373 	    return;
374 	}
375     }
376 
377     /* Break the link with Card Services */
378     if (link->handle)
379 	CardServices(DeregisterClient, link->handle);
380 
381     /* Unlink device structure, free pieces */
382     *linkp = link->next;
383     if (link->dev)
384 	unregister_netdev(&lp->dev);
385     kfree(lp);
386 
387 } /* fmvj18x_detach */
388 
389 /*====================================================================*/
390 
391 #define CS_CHECK(fn, args...) \
392 while ((last_ret=CardServices(last_fn=(fn), args))!=0) goto cs_failed
393 
mfc_try_io_port(dev_link_t * link)394 static int mfc_try_io_port(dev_link_t *link)
395 {
396     int i, ret;
397     static ioaddr_t serial_base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
398 
399     for (i = 0; i < 5; i++) {
400 	link->io.BasePort2 = serial_base[i];
401 	link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
402 	if (link->io.BasePort2 == 0) {
403 	    link->io.NumPorts2 = 0;
404 	    printk(KERN_NOTICE "fmvj18x_cs: out of resource for serial\n");
405 	}
406 	ret = CardServices(RequestIO, link->handle, &link->io);
407 	if (ret == CS_SUCCESS) return ret;
408     }
409     return ret;
410 }
411 
ungermann_try_io_port(dev_link_t * link)412 static int ungermann_try_io_port(dev_link_t *link)
413 {
414     int ret;
415     ioaddr_t ioaddr;
416     /*
417 	Ungermann-Bass Access/CARD accepts 0x300,0x320,0x340,0x360
418 	0x380,0x3c0 only for ioport.
419     */
420     for (ioaddr = 0x300; ioaddr < 0x3e0; ioaddr += 0x20) {
421 	link->io.BasePort1 = ioaddr;
422 	ret = CardServices(RequestIO, link->handle, &link->io);
423 	if (ret == CS_SUCCESS) {
424 	    /* calculate ConfigIndex value */
425 	    link->conf.ConfigIndex =
426 		((link->io.BasePort1 & 0x0f0) >> 3) | 0x22;
427 	    return ret;
428 	}
429     }
430     return ret;	/* RequestIO failed */
431 }
432 
fmvj18x_config(dev_link_t * link)433 static void fmvj18x_config(dev_link_t *link)
434 {
435     client_handle_t handle = link->handle;
436     local_info_t *lp = link->priv;
437     struct net_device *dev = &lp->dev;
438     tuple_t tuple;
439     cisparse_t parse;
440     u_short buf[32];
441     int i, last_fn, last_ret, ret;
442     ioaddr_t ioaddr;
443     cardtype_t cardtype;
444     char *card_name = "unknown";
445     u_char *node_id;
446 
447     DEBUG(0, "fmvj18x_config(0x%p)\n", link);
448 
449     /*
450        This reads the card's CONFIG tuple to find its configuration
451        registers.
452     */
453     tuple.DesiredTuple = CISTPL_CONFIG;
454     CS_CHECK(GetFirstTuple, handle, &tuple);
455     tuple.TupleData = (u_char *)buf;
456     tuple.TupleDataMax = 64;
457     tuple.TupleOffset = 0;
458     CS_CHECK(GetTupleData, handle, &tuple);
459     CS_CHECK(ParseTuple, handle, &tuple, &parse);
460 
461     /* Configure card */
462     link->state |= DEV_CONFIG;
463 
464     link->conf.ConfigBase = parse.config.base;
465     link->conf.Present = parse.config.rmask[0];
466 
467     tuple.DesiredTuple = CISTPL_FUNCE;
468     tuple.TupleOffset = 0;
469     if (CardServices(GetFirstTuple, handle, &tuple) == CS_SUCCESS) {
470 	/* Yes, I have CISTPL_FUNCE. Let's check CISTPL_MANFID */
471 	tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
472 	CS_CHECK(GetFirstTuple, handle, &tuple);
473 	CS_CHECK(GetTupleData, handle, &tuple);
474 	CS_CHECK(ParseTuple, handle, &tuple, &parse);
475 	link->conf.ConfigIndex = parse.cftable_entry.index;
476 	tuple.DesiredTuple = CISTPL_MANFID;
477 	if (CardServices(GetFirstTuple, handle, &tuple) == CS_SUCCESS)
478 	    CS_CHECK(GetTupleData, handle, &tuple);
479 	else
480 	    buf[0] = 0xffff;
481 	switch (le16_to_cpu(buf[0])) {
482 	case MANFID_TDK:
483 	    cardtype = TDK;
484 	    if (le16_to_cpu(buf[1]) == PRODID_TDK_CF010) {
485 		cs_status_t status;
486 		CardServices(GetStatus, handle, &status);
487 		if (status.CardState & CS_EVENT_3VCARD)
488 		    link->conf.Vcc = 33; /* inserted in 3.3V slot */
489 	    } else if (le16_to_cpu(buf[1]) == PRODID_TDK_GN3410) {
490 		/* MultiFunction Card */
491 		link->conf.ConfigBase = 0x800;
492 		link->conf.ConfigIndex = 0x47;
493 		link->io.NumPorts2 = 8;
494 	    }
495 	    break;
496 	case MANFID_CONTEC:
497 	    cardtype = CONTEC;
498 	    break;
499 	case MANFID_FUJITSU:
500 	    if (le16_to_cpu(buf[1]) == PRODID_FUJITSU_MBH10302)
501                 /* RATOC REX-5588/9822/4886's PRODID are 0004(=MBH10302),
502                    but these are MBH10304 based card. */
503 		cardtype = MBH10304;
504 	    else if (le16_to_cpu(buf[1]) == PRODID_FUJITSU_MBH10304)
505 		cardtype = MBH10304;
506 	    else
507 		cardtype = LA501;
508 	    break;
509 	default:
510 	    cardtype = MBH10304;
511 	}
512     } else {
513 	/* old type card */
514 	tuple.DesiredTuple = CISTPL_MANFID;
515 	if (CardServices(GetFirstTuple, handle, &tuple) == CS_SUCCESS)
516 	    CS_CHECK(GetTupleData, handle, &tuple);
517 	else
518 	    buf[0] = 0xffff;
519 	switch (le16_to_cpu(buf[0])) {
520 	case MANFID_FUJITSU:
521 	    if (le16_to_cpu(buf[1]) == PRODID_FUJITSU_MBH10304) {
522 		cardtype = XXX10304;    /* MBH10304 with buggy CIS */
523 	        link->conf.ConfigIndex = 0x20;
524 	    } else {
525 		cardtype = MBH10302;    /* NextCom NC5310, etc. */
526 		link->conf.ConfigIndex = 1;
527 	    }
528 	    break;
529 	case MANFID_UNGERMANN:
530 	    cardtype = UNGERMANN;
531 	    break;
532 	default:
533 	    cardtype = MBH10302;
534 	    link->conf.ConfigIndex = 1;
535 	}
536     }
537 
538     if (link->io.NumPorts2 != 0) {
539     	link->irq.Attributes =
540 		IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT;
541 	ret = mfc_try_io_port(link);
542 	if (ret != CS_SUCCESS) goto cs_failed;
543     } else if (cardtype == UNGERMANN) {
544 	ret = ungermann_try_io_port(link);
545 	if (ret != CS_SUCCESS) goto cs_failed;
546     } else {
547 	CS_CHECK(RequestIO, link->handle, &link->io);
548     }
549     CS_CHECK(RequestIRQ, link->handle, &link->irq);
550     CS_CHECK(RequestConfiguration, link->handle, &link->conf);
551     dev->irq = link->irq.AssignedIRQ;
552     dev->base_addr = link->io.BasePort1;
553     if (register_netdev(dev) != 0) {
554 	printk(KERN_NOTICE "fmvj18x_cs: register_netdev() failed\n");
555 	goto failed;
556     }
557 
558     if (link->io.BasePort2 != 0)
559 	fmvj18x_setup_mfc(link);
560 
561     ioaddr = dev->base_addr;
562 
563     /* Reset controller */
564     if (sram_config == 0)
565 	outb(CONFIG0_RST, ioaddr + CONFIG_0);
566     else
567 	outb(CONFIG0_RST_1, ioaddr + CONFIG_0);
568 
569     /* Power On chip and select bank 0 */
570     if (cardtype == MBH10302)
571 	outb(BANK_0, ioaddr + CONFIG_1);
572     else
573 	outb(BANK_0U, ioaddr + CONFIG_1);
574 
575     /* Set hardware address */
576     switch (cardtype) {
577     case MBH10304:
578     case TDK:
579     case LA501:
580     case CONTEC:
581 	tuple.DesiredTuple = CISTPL_FUNCE;
582 	tuple.TupleOffset = 0;
583 	CS_CHECK(GetFirstTuple, handle, &tuple);
584 	tuple.TupleOffset = 0;
585 	CS_CHECK(GetTupleData, handle, &tuple);
586 	if (cardtype == MBH10304) {
587 	    /* MBH10304's CIS_FUNCE is corrupted */
588 	    node_id = &(tuple.TupleData[5]);
589 	    card_name = "FMV-J182";
590 	} else {
591 	    while (tuple.TupleData[0] != CISTPL_FUNCE_LAN_NODE_ID ) {
592 		CS_CHECK(GetNextTuple, handle, &tuple) ;
593 		CS_CHECK(GetTupleData, handle, &tuple) ;
594 	    }
595 	    node_id = &(tuple.TupleData[2]);
596 	    if( cardtype == TDK ) {
597 		card_name = "TDK LAK-CD021";
598 	    } else if( cardtype == LA501 ) {
599 		card_name = "LA501";
600 	    } else {
601 		card_name = "C-NET(PC)C";
602 	    }
603 	}
604 	/* Read MACID from CIS */
605 	for (i = 0; i < 6; i++)
606 	    dev->dev_addr[i] = node_id[i];
607 	break;
608     case UNGERMANN:
609 	/* Read MACID from register */
610 	for (i = 0; i < 6; i++)
611 	    dev->dev_addr[i] = inb(ioaddr + UNGERMANN_MAC_ID + i);
612 	card_name = "Access/CARD";
613 	break;
614     case XXX10304:
615 	/* Read MACID from Buggy CIS */
616 	if (fmvj18x_get_hwinfo(link, tuple.TupleData) == -1) {
617 	    printk(KERN_NOTICE "fmvj18x_cs: unable to read hardware net address.\n");
618 	    unregister_netdev(dev);
619 	    goto failed;
620 	}
621 	for (i = 0 ; i < 6; i++) {
622 	    dev->dev_addr[i] = tuple.TupleData[i];
623 	}
624 	card_name = "FMV-J182";
625 	break;
626     case MBH10302:
627     default:
628 	/* Read MACID from register */
629 	for (i = 0; i < 6; i++)
630 	    dev->dev_addr[i] = inb(ioaddr + MAC_ID + i);
631 	card_name = "FMV-J181";
632 	break;
633     }
634 
635     strcpy(lp->node.dev_name, dev->name);
636     link->dev = &lp->node;
637 
638     lp->cardtype = cardtype;
639     /* print current configuration */
640     printk(KERN_INFO "%s: %s, sram %s, port %#3lx, irq %d, hw_addr ",
641 	   dev->name, card_name, sram_config == 0 ? "4K TX*2" : "8K TX*2",
642 	   dev->base_addr, dev->irq);
643     for (i = 0; i < 6; i++)
644 	printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
645 
646     link->state &= ~DEV_CONFIG_PENDING;
647     return;
648 
649 cs_failed:
650     /* All Card Services errors end up here */
651     cs_error(link->handle, last_fn, last_ret);
652 failed:
653     fmvj18x_release((u_long)link);
654     link->state &= ~DEV_CONFIG_PENDING;
655 
656 } /* fmvj18x_config */
657 /*====================================================================*/
658 
fmvj18x_get_hwinfo(dev_link_t * link,u_char * node_id)659 static int fmvj18x_get_hwinfo(dev_link_t *link, u_char *node_id)
660 {
661     win_req_t req;
662     memreq_t mem;
663     u_char *base;
664     int i, j;
665 
666     /* Allocate a small memory window */
667     req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
668     req.Base = 0; req.Size = 0;
669     req.AccessSpeed = 0;
670     link->win = (window_handle_t)link->handle;
671     i = CardServices(RequestWindow, &link->win, &req);
672     if (i != CS_SUCCESS) {
673 	cs_error(link->handle, RequestWindow, i);
674 	return -1;
675     }
676 
677     base = ioremap(req.Base, req.Size);
678     mem.Page = 0;
679     mem.CardOffset = 0;
680     CardServices(MapMemPage, link->win, &mem);
681 
682     /*
683      *  MBH10304 CISTPL_FUNCE_LAN_NODE_ID format
684      *  22 0d xx xx xx 04 06 yy yy yy yy yy yy ff
685      *  'xx' is garbage.
686      *  'yy' is MAC address.
687     */
688     for (i = 0; i < 0x200; i++) {
689 	if (readb(base+i*2) == 0x22) {
690 	    if (readb(base+(i-1)*2) == 0xff
691 	     && readb(base+(i+5)*2) == 0x04
692 	     && readb(base+(i+6)*2) == 0x06
693 	     && readb(base+(i+13)*2) == 0xff)
694 		break;
695 	}
696     }
697 
698     if (i != 0x200) {
699 	for (j = 0 ; j < 6; j++,i++) {
700 	    node_id[j] = readb(base+(i+7)*2);
701 	}
702     }
703 
704     iounmap(base);
705     j = CardServices(ReleaseWindow, link->win);
706     if (j != CS_SUCCESS)
707 	cs_error(link->handle, ReleaseWindow, j);
708     return (i != 0x200) ? 0 : -1;
709 
710 } /* fmvj18x_get_hwinfo */
711 /*====================================================================*/
712 
fmvj18x_setup_mfc(dev_link_t * link)713 static int fmvj18x_setup_mfc(dev_link_t *link)
714 {
715     win_req_t req;
716     memreq_t mem;
717     u_char *base;
718     int i, j;
719     local_info_t *lp = link->priv;
720     struct net_device *dev = &lp->dev;
721     ioaddr_t ioaddr;
722 
723     /* Allocate a small memory window */
724     req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
725     req.Base = 0; req.Size = 0;
726     req.AccessSpeed = 0;
727     link->win = (window_handle_t)link->handle;
728     i = CardServices(RequestWindow, &link->win, &req);
729     if (i != CS_SUCCESS) {
730 	cs_error(link->handle, RequestWindow, i);
731 	return -1;
732     }
733 
734     base = ioremap(req.Base, req.Size);
735     mem.Page = 0;
736     mem.CardOffset = 0;
737     CardServices(MapMemPage, link->win, &mem);
738 
739     ioaddr = dev->base_addr;
740     writeb(0x47, base+0x800);	/* Config Option Register of LAN */
741     writeb(0x0, base+0x802);	/* Config and Status Register */
742 
743     writeb(ioaddr & 0xff, base+0x80a);		/* I/O Base(Low) of LAN */
744     writeb((ioaddr >> 8) & 0xff, base+0x80c);	/* I/O Base(High) of LAN */
745 
746     writeb(0x45, base+0x820);	/* Config Option Register of Modem */
747     writeb(0x8, base+0x822);	/* Config and Status Register */
748 
749     iounmap(base);
750     j = CardServices(ReleaseWindow, link->win);
751     if (j != CS_SUCCESS)
752 	cs_error(link->handle, ReleaseWindow, j);
753     return 0;
754 
755 }
756 /*====================================================================*/
757 
fmvj18x_release(u_long arg)758 static void fmvj18x_release(u_long arg)
759 {
760     dev_link_t *link = (dev_link_t *)arg;
761 
762     DEBUG(0, "fmvj18x_release(0x%p)\n", link);
763 
764     /*
765        If the device is currently in use, we won't release until it
766        is actually closed.
767     */
768     if (link->open) {
769 	DEBUG(1, "fmvj18x_cs: release postponed, '%s' "
770 	      "still open\n", link->dev->dev_name);
771 	link->state |= DEV_STALE_CONFIG;
772 	return;
773     }
774 
775     /* Don't bother checking to see if these succeed or not */
776     CardServices(ReleaseWindow, link->win);
777     CardServices(ReleaseConfiguration, link->handle);
778     CardServices(ReleaseIO, link->handle, &link->io);
779     CardServices(ReleaseIRQ, link->handle, &link->irq);
780 
781     link->state &= ~DEV_CONFIG;
782 
783 } /* fmvj18x_release */
784 
785 /*====================================================================*/
786 
fmvj18x_event(event_t event,int priority,event_callback_args_t * args)787 static int fmvj18x_event(event_t event, int priority,
788 			  event_callback_args_t *args)
789 {
790     dev_link_t *link = args->client_data;
791     local_info_t *lp = link->priv;
792     struct net_device *dev = &lp->dev;
793 
794     DEBUG(1, "fmvj18x_event(0x%06x)\n", event);
795 
796     switch (event) {
797     case CS_EVENT_CARD_REMOVAL:
798 	link->state &= ~DEV_PRESENT;
799 	if (link->state & DEV_CONFIG) {
800 	    netif_device_detach(dev);
801 	    mod_timer(&link->release, jiffies + HZ/20);
802 	}
803 	break;
804     case CS_EVENT_CARD_INSERTION:
805 	link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
806 	fmvj18x_config(link);
807 	break;
808     case CS_EVENT_PM_SUSPEND:
809 	link->state |= DEV_SUSPEND;
810 	/* Fall through... */
811     case CS_EVENT_RESET_PHYSICAL:
812 	if (link->state & DEV_CONFIG) {
813 	    if (link->open)
814 		netif_device_detach(dev);
815 	    CardServices(ReleaseConfiguration, link->handle);
816 	}
817 	break;
818     case CS_EVENT_PM_RESUME:
819 	link->state &= ~DEV_SUSPEND;
820 	/* Fall through... */
821     case CS_EVENT_CARD_RESET:
822 	if (link->state & DEV_CONFIG) {
823 	    CardServices(RequestConfiguration, link->handle, &link->conf);
824 	    if (link->open) {
825 		fjn_reset(dev);
826 		netif_device_attach(dev);
827 	    }
828 	}
829 	break;
830     }
831     return 0;
832 } /* fmvj18x_event */
833 
834 /*====================================================================*/
835 
init_fmvj18x_cs(void)836 static int __init init_fmvj18x_cs(void)
837 {
838     servinfo_t serv;
839     DEBUG(0, "%s\n", version);
840     CardServices(GetCardServicesInfo, &serv);
841     if (serv.Revision != CS_RELEASE_CODE) {
842 	printk(KERN_NOTICE "fmvj18x: Card Services release "
843 	       "does not match!\n");
844 	return -EINVAL;
845     }
846     register_pccard_driver(&dev_info, &fmvj18x_attach, &fmvj18x_detach);
847     return 0;
848 }
849 
exit_fmvj18x_cs(void)850 static void __exit exit_fmvj18x_cs(void)
851 {
852     DEBUG(0, "fmvj18x_cs: unloading\n");
853     unregister_pccard_driver(&dev_info);
854     while (dev_list != NULL)
855 	fmvj18x_detach(dev_list);
856 }
857 
858 module_init(init_fmvj18x_cs);
859 module_exit(exit_fmvj18x_cs);
860 
861 /*====================================================================*/
862 
fjn_interrupt(int irq,void * dev_id,struct pt_regs * regs)863 static void fjn_interrupt(int irq, void *dev_id, struct pt_regs *regs)
864 {
865     local_info_t *lp = dev_id;
866     struct net_device *dev = &lp->dev;
867     ioaddr_t ioaddr;
868     unsigned short tx_stat, rx_stat;
869 
870     if (lp == NULL) {
871         printk(KERN_NOTICE "fjn_interrupt(): irq %d for "
872 	       "unknown device.\n", irq);
873         return;
874     }
875     ioaddr = dev->base_addr;
876 
877     /* avoid multiple interrupts */
878     outw(0x0000, ioaddr + TX_INTR);
879 
880     /* wait for a while */
881     udelay(1);
882 
883     /* get status */
884     tx_stat = inb(ioaddr + TX_STATUS);
885     rx_stat = inb(ioaddr + RX_STATUS);
886 
887     /* clear status */
888     outb(tx_stat, ioaddr + TX_STATUS);
889     outb(rx_stat, ioaddr + RX_STATUS);
890 
891     DEBUG(4, "%s: interrupt, rx_status %02x.\n", dev->name, rx_stat);
892     DEBUG(4, "               tx_status %02x.\n", tx_stat);
893 
894     if (rx_stat || (inb(ioaddr + RX_MODE) & F_BUF_EMP) == 0) {
895 	/* there is packet(s) in rx buffer */
896 	fjn_rx(dev);
897     }
898     if (tx_stat & F_TMT_RDY) {
899 	lp->stats.tx_packets += lp->sent ;
900         lp->sent = 0 ;
901 	if (lp->tx_queue) {
902 	    outb(DO_TX | lp->tx_queue, ioaddr + TX_START);
903 	    lp->sent = lp->tx_queue ;
904 	    lp->tx_queue = 0;
905 	    lp->tx_queue_len = 0;
906 	    dev->trans_start = jiffies;
907 	} else {
908 	    lp->tx_started = 0;
909 	}
910 	netif_wake_queue(dev);
911     }
912     DEBUG(4, "%s: exiting interrupt,\n", dev->name);
913     DEBUG(4, "    tx_status %02x, rx_status %02x.\n", tx_stat, rx_stat);
914 
915     outb(D_TX_INTR, ioaddr + TX_INTR);
916     outb(D_RX_INTR, ioaddr + RX_INTR);
917 
918 } /* fjn_interrupt */
919 
920 /*====================================================================*/
921 
fjn_tx_timeout(struct net_device * dev)922 static void fjn_tx_timeout(struct net_device *dev)
923 {
924     struct local_info_t *lp = (struct local_info_t *)dev->priv;
925     ioaddr_t ioaddr = dev->base_addr;
926 
927     printk(KERN_NOTICE "%s: transmit timed out with status %04x, %s?\n",
928 	   dev->name, htons(inw(ioaddr + TX_STATUS)),
929 	   inb(ioaddr + TX_STATUS) & F_TMT_RDY
930 	   ? "IRQ conflict" : "network cable problem");
931     printk(KERN_NOTICE "%s: timeout registers: %04x %04x %04x "
932 	   "%04x %04x %04x %04x %04x.\n",
933 	   dev->name, htons(inw(ioaddr + 0)),
934 	   htons(inw(ioaddr + 2)), htons(inw(ioaddr + 4)),
935 	   htons(inw(ioaddr + 6)), htons(inw(ioaddr + 8)),
936 	   htons(inw(ioaddr +10)), htons(inw(ioaddr +12)),
937 	   htons(inw(ioaddr +14)));
938     lp->stats.tx_errors++;
939     /* ToDo: We should try to restart the adaptor... */
940     cli();
941 
942     fjn_reset(dev);
943 
944     lp->tx_started = 0;
945     lp->tx_queue = 0;
946     lp->tx_queue_len = 0;
947     lp->sent = 0;
948     lp->open_time = jiffies;
949     sti();
950     netif_wake_queue(dev);
951 }
952 
fjn_start_xmit(struct sk_buff * skb,struct net_device * dev)953 static int fjn_start_xmit(struct sk_buff *skb, struct net_device *dev)
954 {
955     struct local_info_t *lp = (struct local_info_t *)dev->priv;
956     ioaddr_t ioaddr = dev->base_addr;
957     short length = skb->len;
958 
959     if(length < ETH_ZLEN)
960     {
961     	skb = skb_padto(skb, ETH_ZLEN);
962     	if(skb == NULL)
963     		return 0;
964     	length = ETH_ZLEN;
965     }
966 
967     netif_stop_queue(dev);
968 
969     {
970 	unsigned char *buf = skb->data;
971 
972 	if (length > ETH_FRAME_LEN) {
973 	    printk(KERN_NOTICE "%s: Attempting to send a large packet"
974 		   " (%d bytes).\n", dev->name, length);
975 	    return 1;
976 	}
977 
978 	DEBUG(4, "%s: Transmitting a packet of length %lu.\n",
979 	      dev->name, (unsigned long)skb->len);
980 	lp->stats.tx_bytes += skb->len;
981 
982 	/* Disable both interrupts. */
983 	outw(0x0000, ioaddr + TX_INTR);
984 
985 	/* wait for a while */
986 	udelay(1);
987 
988 	outw(length, ioaddr + DATAPORT);
989 	outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1);
990 
991 	lp->tx_queue++;
992 	lp->tx_queue_len += ((length+3) & ~1);
993 
994 	if (lp->tx_started == 0) {
995 	    /* If the Tx is idle, always trigger a transmit. */
996 	    outb(DO_TX | lp->tx_queue, ioaddr + TX_START);
997 	    lp->sent = lp->tx_queue ;
998 	    lp->tx_queue = 0;
999 	    lp->tx_queue_len = 0;
1000 	    dev->trans_start = jiffies;
1001 	    lp->tx_started = 1;
1002 	    netif_start_queue(dev);
1003 	} else {
1004 	    if( sram_config == 0 ) {
1005 		if (lp->tx_queue_len < (4096 - (ETH_FRAME_LEN +2)) )
1006 		    /* Yes, there is room for one more packet. */
1007 		    netif_start_queue(dev);
1008 	    } else {
1009 		if (lp->tx_queue_len < (8192 - (ETH_FRAME_LEN +2)) &&
1010 						lp->tx_queue < 127 )
1011 		    /* Yes, there is room for one more packet. */
1012 		    netif_start_queue(dev);
1013 	    }
1014 	}
1015 
1016 	/* Re-enable interrupts */
1017 	outb(D_TX_INTR, ioaddr + TX_INTR);
1018 	outb(D_RX_INTR, ioaddr + RX_INTR);
1019     }
1020     dev_kfree_skb (skb);
1021 
1022     return 0;
1023 } /* fjn_start_xmit */
1024 
1025 /*====================================================================*/
1026 
fjn_reset(struct net_device * dev)1027 static void fjn_reset(struct net_device *dev)
1028 {
1029     struct local_info_t *lp = (struct local_info_t *)dev->priv;
1030     ioaddr_t ioaddr = dev->base_addr;
1031     int i;
1032 
1033     DEBUG(4, "fjn_reset(%s) called.\n",dev->name);
1034 
1035     /* Reset controller */
1036     if( sram_config == 0 )
1037 	outb(CONFIG0_RST, ioaddr + CONFIG_0);
1038     else
1039 	outb(CONFIG0_RST_1, ioaddr + CONFIG_0);
1040 
1041     /* Power On chip and select bank 0 */
1042     if (lp->cardtype == MBH10302)
1043 	outb(BANK_0, ioaddr + CONFIG_1);
1044     else
1045 	outb(BANK_0U, ioaddr + CONFIG_1);
1046 
1047     /* Set Tx modes */
1048     outb(D_TX_MODE, ioaddr + TX_MODE);
1049     /* set Rx modes */
1050     outb(ID_MATCHED, ioaddr + RX_MODE);
1051 
1052     /* Set hardware address */
1053     for (i = 0; i < 6; i++)
1054         outb(dev->dev_addr[i], ioaddr + NODE_ID + i);
1055 
1056     /* Switch to bank 1 */
1057     if (lp->cardtype == MBH10302)
1058 	outb(BANK_1, ioaddr + CONFIG_1);
1059     else
1060 	outb(BANK_1U, ioaddr + CONFIG_1);
1061 
1062     /* set the multicast table to accept none. */
1063     for (i = 0; i < 6; i++)
1064         outb(0x00, ioaddr + MAR_ADR + i);
1065 
1066     /* Switch to bank 2 (runtime mode) */
1067     if (lp->cardtype == MBH10302)
1068 	outb(BANK_2, ioaddr + CONFIG_1);
1069     else
1070 	outb(BANK_2U, ioaddr + CONFIG_1);
1071 
1072     /* set 16col ctrl bits */
1073     if( lp->cardtype == TDK || lp->cardtype == CONTEC)
1074         outb(TDK_AUTO_MODE, ioaddr + COL_CTRL);
1075     else
1076         outb(AUTO_MODE, ioaddr + COL_CTRL);
1077 
1078     /* clear Reserved Regs */
1079     outb(0x00, ioaddr + BMPR12);
1080     outb(0x00, ioaddr + BMPR13);
1081 
1082     /* reset Skip packet reg. */
1083     outb(0x01, ioaddr + RX_SKIP);
1084 
1085     /* Enable Tx and Rx */
1086     if( sram_config == 0 )
1087 	outb(CONFIG0_DFL, ioaddr + CONFIG_0);
1088     else
1089 	outb(CONFIG0_DFL_1, ioaddr + CONFIG_0);
1090 
1091     /* Init receive pointer ? */
1092     inw(ioaddr + DATAPORT);
1093     inw(ioaddr + DATAPORT);
1094 
1095     /* Clear all status */
1096     outb(0xff, ioaddr + TX_STATUS);
1097     outb(0xff, ioaddr + RX_STATUS);
1098 
1099     if (lp->cardtype == MBH10302)
1100 	outb(INTR_OFF, ioaddr + LAN_CTRL);
1101 
1102     /* Turn on Rx interrupts */
1103     outb(D_TX_INTR, ioaddr + TX_INTR);
1104     outb(D_RX_INTR, ioaddr + RX_INTR);
1105 
1106     /* Turn on interrupts from LAN card controller */
1107     if (lp->cardtype == MBH10302)
1108 	outb(INTR_ON, ioaddr + LAN_CTRL);
1109 } /* fjn_reset */
1110 
1111 /*====================================================================*/
1112 
fjn_rx(struct net_device * dev)1113 static void fjn_rx(struct net_device *dev)
1114 {
1115     struct local_info_t *lp = (struct local_info_t *)dev->priv;
1116     ioaddr_t ioaddr = dev->base_addr;
1117     int boguscount = 10;	/* 5 -> 10: by agy 19940922 */
1118 
1119     DEBUG(4, "%s: in rx_packet(), rx_status %02x.\n",
1120 	  dev->name, inb(ioaddr + RX_STATUS));
1121 
1122     while ((inb(ioaddr + RX_MODE) & F_BUF_EMP) == 0) {
1123 	u_short status = inw(ioaddr + DATAPORT);
1124 
1125 	DEBUG(4, "%s: Rxing packet mode %02x status %04x.\n",
1126 	      dev->name, inb(ioaddr + RX_MODE), status);
1127 #ifndef final_version
1128 	if (status == 0) {
1129 	    outb(F_SKP_PKT, ioaddr + RX_SKIP);
1130 	    break;
1131 	}
1132 #endif
1133 	if ((status & 0xF0) != 0x20) {	/* There was an error. */
1134 	    lp->stats.rx_errors++;
1135 	    if (status & F_LEN_ERR) lp->stats.rx_length_errors++;
1136 	    if (status & F_ALG_ERR) lp->stats.rx_frame_errors++;
1137 	    if (status & F_CRC_ERR) lp->stats.rx_crc_errors++;
1138 	    if (status & F_OVR_FLO) lp->stats.rx_over_errors++;
1139 	} else {
1140 	    u_short pkt_len = inw(ioaddr + DATAPORT);
1141 	    /* Malloc up new buffer. */
1142 	    struct sk_buff *skb;
1143 
1144 	    if (pkt_len > 1550) {
1145 		printk(KERN_NOTICE "%s: The FMV-18x claimed a very "
1146 		       "large packet, size %d.\n", dev->name, pkt_len);
1147 		outb(F_SKP_PKT, ioaddr + RX_SKIP);
1148 		lp->stats.rx_errors++;
1149 		break;
1150 	    }
1151 	    skb = dev_alloc_skb(pkt_len+2);
1152 	    if (skb == NULL) {
1153 		printk(KERN_NOTICE "%s: Memory squeeze, dropping "
1154 		       "packet (len %d).\n", dev->name, pkt_len);
1155 		outb(F_SKP_PKT, ioaddr + RX_SKIP);
1156 		lp->stats.rx_dropped++;
1157 		break;
1158 	    }
1159 	    skb->dev = dev;
1160 
1161 	    skb_reserve(skb, 2);
1162 	    insw(ioaddr + DATAPORT, skb_put(skb, pkt_len),
1163 		 (pkt_len + 1) >> 1);
1164 	    skb->protocol = eth_type_trans(skb, dev);
1165 
1166 #ifdef PCMCIA_DEBUG
1167 	    if (pc_debug > 5) {
1168 		int i;
1169 		printk(KERN_DEBUG "%s: Rxed packet of length %d: ",
1170 		       dev->name, pkt_len);
1171 		for (i = 0; i < 14; i++)
1172 		    printk(" %02x", skb->data[i]);
1173 		printk(".\n");
1174 	    }
1175 #endif
1176 
1177 	    netif_rx(skb);
1178 	    dev->last_rx = jiffies;
1179 	    lp->stats.rx_packets++;
1180 	    lp->stats.rx_bytes += pkt_len;
1181 	}
1182 	if (--boguscount <= 0)
1183 	    break;
1184     }
1185 
1186     /* If any worth-while packets have been received, dev_rint()
1187 	   has done a netif_wake_queue() for us and will work on them
1188 	   when we get to the bottom-half routine. */
1189 /*
1190     if (lp->cardtype != TDK) {
1191 	int i;
1192 	for (i = 0; i < 20; i++) {
1193 	    if ((inb(ioaddr + RX_MODE) & F_BUF_EMP) == F_BUF_EMP)
1194 		break;
1195 	    (void)inw(ioaddr + DATAPORT);  /+ dummy status read +/
1196 	    outb(F_SKP_PKT, ioaddr + RX_SKIP);
1197 	}
1198 
1199 	if (i > 0)
1200 	    DEBUG(5, "%s: Exint Rx packet with mode %02x after "
1201 		  "%d ticks.\n", dev->name, inb(ioaddr + RX_MODE), i);
1202     }
1203 */
1204 
1205     return;
1206 } /* fjn_rx */
1207 
1208 /*====================================================================*/
1209 
netdev_get_drvinfo(struct net_device * dev,struct ethtool_drvinfo * info)1210 static void netdev_get_drvinfo(struct net_device *dev,
1211 			       struct ethtool_drvinfo *info)
1212 {
1213 	strcpy(info->driver, DRV_NAME);
1214 	strcpy(info->version, DRV_VERSION);
1215 	sprintf(info->bus_info, "PCMCIA 0x%lx", dev->base_addr);
1216 }
1217 
1218 #ifdef PCMCIA_DEBUG
netdev_get_msglevel(struct net_device * dev)1219 static u32 netdev_get_msglevel(struct net_device *dev)
1220 {
1221 	return pc_debug;
1222 }
1223 
netdev_set_msglevel(struct net_device * dev,u32 level)1224 static void netdev_set_msglevel(struct net_device *dev, u32 level)
1225 {
1226 	pc_debug = level;
1227 }
1228 #endif /* PCMCIA_DEBUG */
1229 
1230 static struct ethtool_ops netdev_ethtool_ops = {
1231 	.get_drvinfo		= netdev_get_drvinfo,
1232 #ifdef PCMCIA_DEBUG
1233 	.get_msglevel		= netdev_get_msglevel,
1234 	.set_msglevel		= netdev_set_msglevel,
1235 #endif /* PCMCIA_DEBUG */
1236 };
1237 
fjn_config(struct net_device * dev,struct ifmap * map)1238 static int fjn_config(struct net_device *dev, struct ifmap *map){
1239     return 0;
1240 }
1241 
fjn_open(struct net_device * dev)1242 static int fjn_open(struct net_device *dev)
1243 {
1244     struct local_info_t *lp = (struct local_info_t *)dev->priv;
1245     dev_link_t *link = &lp->link;
1246 
1247     DEBUG(4, "fjn_open('%s').\n", dev->name);
1248 
1249     if (!DEV_OK(link))
1250 	return -ENODEV;
1251 
1252     link->open++;
1253 
1254     fjn_reset(dev);
1255 
1256     lp->tx_started = 0;
1257     lp->tx_queue = 0;
1258     lp->tx_queue_len = 0;
1259     lp->open_time = jiffies;
1260     netif_start_queue(dev);
1261 
1262     MOD_INC_USE_COUNT;
1263 
1264     return 0;
1265 } /* fjn_open */
1266 
1267 /*====================================================================*/
1268 
fjn_close(struct net_device * dev)1269 static int fjn_close(struct net_device *dev)
1270 {
1271     struct local_info_t *lp = (struct local_info_t *)dev->priv;
1272     dev_link_t *link = &lp->link;
1273     ioaddr_t ioaddr = dev->base_addr;
1274 
1275     DEBUG(4, "fjn_close('%s').\n", dev->name);
1276 
1277     lp->open_time = 0;
1278     netif_stop_queue(dev);
1279 
1280     /* Set configuration register 0 to disable Tx and Rx. */
1281     if( sram_config == 0 )
1282 	outb(CONFIG0_RST ,ioaddr + CONFIG_0);
1283     else
1284 	outb(CONFIG0_RST_1 ,ioaddr + CONFIG_0);
1285 
1286     /* Update the statistics -- ToDo. */
1287 
1288     /* Power-down the chip.  Green, green, green! */
1289     outb(CHIP_OFF ,ioaddr + CONFIG_1);
1290 
1291     /* Set the ethernet adaptor disable IRQ */
1292     if (lp->cardtype == MBH10302)
1293 	outb(INTR_OFF, ioaddr + LAN_CTRL);
1294 
1295     link->open--;
1296     if (link->state & DEV_STALE_CONFIG)
1297 	mod_timer(&link->release, jiffies + HZ/20);
1298     MOD_DEC_USE_COUNT;
1299 
1300     return 0;
1301 } /* fjn_close */
1302 
1303 /*====================================================================*/
1304 
fjn_get_stats(struct net_device * dev)1305 static struct net_device_stats *fjn_get_stats(struct net_device *dev)
1306 {
1307     local_info_t *lp = (local_info_t *)dev->priv;
1308     return &lp->stats;
1309 } /* fjn_get_stats */
1310 
1311 /*====================================================================*/
1312 
1313 /*
1314   Set the multicast/promiscuous mode for this adaptor.
1315 */
1316 
set_rx_mode(struct net_device * dev)1317 static void set_rx_mode(struct net_device *dev)
1318 {
1319     ioaddr_t ioaddr = dev->base_addr;
1320     struct local_info_t *lp = (struct local_info_t *)dev->priv;
1321     u_char mc_filter[8];		 /* Multicast hash filter */
1322     u_long flags;
1323     int i;
1324 
1325     if (dev->flags & IFF_PROMISC) {
1326 	/* Unconditionally log net taps. */
1327 	printk("%s: Promiscuous mode enabled.\n", dev->name);
1328 	memset(mc_filter, 0xff, sizeof(mc_filter));
1329 	outb(3, ioaddr + RX_MODE);	/* Enable promiscuous mode */
1330     } else if (dev->mc_count > MC_FILTERBREAK
1331 	       ||  (dev->flags & IFF_ALLMULTI)) {
1332 	/* Too many to filter perfectly -- accept all multicasts. */
1333 	memset(mc_filter, 0xff, sizeof(mc_filter));
1334 	outb(2, ioaddr + RX_MODE);	/* Use normal mode. */
1335     } else if (dev->mc_count == 0) {
1336 	memset(mc_filter, 0x00, sizeof(mc_filter));
1337 	outb(1, ioaddr + RX_MODE);	/* Ignore almost all multicasts. */
1338     } else {
1339 	struct dev_mc_list *mclist;
1340 	int i;
1341 
1342 	memset(mc_filter, 0, sizeof(mc_filter));
1343 	for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
1344 	     i++, mclist = mclist->next)
1345 	    set_bit(ether_crc_le(ETH_ALEN, mclist->dmi_addr) & 0x3f,
1346 		    mc_filter);
1347     }
1348 
1349     save_flags(flags);
1350     cli();
1351     if (memcmp(mc_filter, lp->mc_filter, sizeof(mc_filter))) {
1352 	int saved_bank = inb(ioaddr + CONFIG_1);
1353 	/* Switch to bank 1 and set the multicast table. */
1354 	outb(0xe4, ioaddr + CONFIG_1);
1355 	for (i = 0; i < 8; i++)
1356 	    outb(mc_filter[i], ioaddr + 8 + i);
1357 	memcpy(lp->mc_filter, mc_filter, sizeof(mc_filter));
1358 	outb(saved_bank, ioaddr + CONFIG_1);
1359     }
1360     restore_flags(flags);
1361 }
1362