blob: 384a736a0d2f820f5c6a7fcce3306d8e6ff04264 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*======================================================================
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/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>
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#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>
57
58#include <asm/uaccess.h>
59#include <asm/io.h>
60#include <asm/system.h>
61
62/*====================================================================*/
63
64/* Module parameters */
65
66MODULE_DESCRIPTION("fmvj18x and compatible PCMCIA ethernet driver");
67MODULE_LICENSE("GPL");
68
69#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
70
71/* SRAM configuration */
72/* 0:4KB*2 TX buffer else:8KB*2 TX buffer */
73INT_MODULE_PARM(sram_config, 0);
74
75#ifdef PCMCIA_DEBUG
76INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);
77#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
78static char *version = DRV_NAME ".c " DRV_VERSION " 2002/03/23";
79#else
80#define DEBUG(n, args...)
81#endif
82
83/*====================================================================*/
84/*
85 PCMCIA event handlers
86 */
87static void fmvj18x_config(dev_link_t *link);
88static int fmvj18x_get_hwinfo(dev_link_t *link, u_char *node_id);
89static int fmvj18x_setup_mfc(dev_link_t *link);
90static void fmvj18x_release(dev_link_t *link);
91static int fmvj18x_event(event_t event, int priority,
92 event_callback_args_t *args);
93static dev_link_t *fmvj18x_attach(void);
94static void fmvj18x_detach(dev_link_t *);
95
96/*
97 LAN controller(MBH86960A) specific routines
98 */
99static int fjn_config(struct net_device *dev, struct ifmap *map);
100static int fjn_open(struct net_device *dev);
101static int fjn_close(struct net_device *dev);
102static int fjn_start_xmit(struct sk_buff *skb, struct net_device *dev);
103static irqreturn_t fjn_interrupt(int irq, void *dev_id, struct pt_regs *regs);
104static void fjn_rx(struct net_device *dev);
105static void fjn_reset(struct net_device *dev);
106static struct net_device_stats *fjn_get_stats(struct net_device *dev);
107static void set_rx_mode(struct net_device *dev);
108static void fjn_tx_timeout(struct net_device *dev);
109static struct ethtool_ops netdev_ethtool_ops;
110
111static dev_info_t dev_info = "fmvj18x_cs";
112static dev_link_t *dev_list;
113
114/*
115 card type
116 */
117typedef enum { MBH10302, MBH10304, TDK, CONTEC, LA501, UNGERMANN,
118 XXX10304
119} cardtype_t;
120
121/*
122 driver specific data structure
123*/
124typedef 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;
136
Komurod9a8a0a2005-08-06 12:01:43 +0900137#define MC_FILTERBREAK 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139/*====================================================================*/
140/*
141 ioport offset from the base address
142 */
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 */
151
152#define NODE_ID 8 /* node ID register (bank 0) */
153#define MAR_ADR 8 /* multicast address registers (bank 1) */
154
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 */
161
162#define LAN_CTRL 16 /* LAN card control register */
163
164#define MAC_ID 0x1a /* hardware address */
165#define UNGERMANN_MAC_ID 0x18 /* UNGERMANN-BASS hardware address */
166
167/*
168 control bits
169 */
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
175
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
182
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 */
191
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 */
198
199#define F_BUF_EMP 0x40 /* receive buffer is empty */
200
201#define F_SKP_PKT 0x05 /* drop packet in buffer */
202
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 )
210
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 */
231
232#define TX_TIMEOUT ((400*HZ)/1000)
233
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) */
237
238static dev_link_t *fmvj18x_attach(void)
239{
240 local_info_t *lp;
241 dev_link_t *link;
242 struct net_device *dev;
243 client_reg_t client_reg;
244 int ret;
245
246 DEBUG(0, "fmvj18x_attach()\n");
247
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;
255
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;
260
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;
266
267 /* General socket configuration */
268 link->conf.Attributes = CONF_ENABLE_IRQ;
269 link->conf.Vcc = 50;
270 link->conf.IntType = INT_MEMORY_AND_IO;
271
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);
285
286 /* Register with Card Services */
287 link->next = dev_list;
288 dev_list = link;
289 client_reg.dev_info = &dev_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 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;
297 }
298
299 return link;
300} /* fmvj18x_attach */
301
302/*====================================================================*/
303
304static void fmvj18x_detach(dev_link_t *link)
305{
306 struct net_device *dev = link->priv;
307 dev_link_t **linkp;
308
309 DEBUG(0, "fmvj18x_detach(0x%p)\n", link);
310
311 /* Locate device structure */
312 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
313 if (*linkp == link) break;
314 if (*linkp == NULL)
315 return;
316
317 if (link->dev)
318 unregister_netdev(dev);
319
320 if (link->state & DEV_CONFIG)
321 fmvj18x_release(link);
322
323 /* Break the link with Card Services */
324 if (link->handle)
325 pcmcia_deregister_client(link->handle);
326
327 /* Unlink device structure, free pieces */
328 *linkp = link->next;
329 free_netdev(dev);
330} /* fmvj18x_detach */
331
332/*====================================================================*/
333
334#define CS_CHECK(fn, ret) \
335do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
336
337static int mfc_try_io_port(dev_link_t *link)
338{
339 int i, ret;
340 static kio_addr_t serial_base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
341
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");
348 }
349 ret = pcmcia_request_io(link->handle, &link->io);
350 if (ret == CS_SUCCESS) return ret;
351 }
352 return ret;
353}
354
355static int ungermann_try_io_port(dev_link_t *link)
356{
357 int ret;
358 kio_addr_t ioaddr;
359 /*
360 Ungermann-Bass Access/CARD accepts 0x300,0x320,0x340,0x360
361 0x380,0x3c0 only for ioport.
362 */
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;
371 }
372 }
373 return ret; /* RequestIO failed */
374}
375
376static void fmvj18x_config(dev_link_t *link)
377{
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;
389
390 DEBUG(0, "fmvj18x_config(0x%p)\n", link);
391
392 /*
393 This reads the card's CONFIG tuple to find its configuration
394 registers.
395 */
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));
403
404 /* Configure card */
405 link->state |= DEV_CONFIG;
406
407 link->conf.ConfigBase = parse.config.base;
408 link->conf.Present = parse.config.rmask[0];
409
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 */
Jun Komurof4d75102005-06-27 16:28:44 -0700432 } 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) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 /* MultiFunction Card */
436 link->conf.ConfigBase = 0x800;
437 link->conf.ConfigIndex = 0x47;
438 link->io.NumPorts2 = 8;
439 }
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;
456 }
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;
472 }
473 break;
474 case MANFID_UNGERMANN:
475 cardtype = UNGERMANN;
476 break;
477 default:
478 cardtype = MBH10302;
479 link->conf.ConfigIndex = 1;
480 }
481 }
482
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));
493 }
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;
498
499 if (link->io.BasePort2 != 0)
500 fmvj18x_setup_mfc(link);
501
502 ioaddr = dev->base_addr;
503
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);
509
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);
515
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));
535 }
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";
543 }
544 }
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;
560 }
561 for (i = 0 ; i < 6; i++) {
562 dev->dev_addr[i] = tuple.TupleData[i];
563 }
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;
573 }
574
575 lp->cardtype = cardtype;
576 link->dev = &lp->node;
577 link->state &= ~DEV_CONFIG_PENDING;
578 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
579
580 if (register_netdev(dev) != 0) {
581 printk(KERN_NOTICE "fmvj18x_cs: register_netdev() failed\n");
582 link->dev = NULL;
583 goto failed;
584 }
585
586 strcpy(lp->node.dev_name, dev->name);
587
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"));
594
595 return;
596
597cs_failed:
598 /* All Card Services errors end up here */
599 cs_error(link->handle, last_fn, last_ret);
600failed:
601 fmvj18x_release(link);
602 link->state &= ~DEV_CONFIG_PENDING;
603
604} /* fmvj18x_config */
605/*====================================================================*/
606
607static int fmvj18x_get_hwinfo(dev_link_t *link, u_char *node_id)
608{
609 win_req_t req;
610 memreq_t mem;
611 u_char __iomem *base;
612 int i, j;
613
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;
622 }
623
624 base = ioremap(req.Base, req.Size);
625 mem.Page = 0;
626 mem.CardOffset = 0;
627 pcmcia_map_mem_page(link->win, &mem);
628
629 /*
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.
634 */
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;
642 }
643 }
644
645 if (i != 0x200) {
646 for (j = 0 ; j < 6; j++,i++) {
647 node_id[j] = readb(base+(i+7)*2);
648 }
649 }
650
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;
656
657} /* fmvj18x_get_hwinfo */
658/*====================================================================*/
659
660static int fmvj18x_setup_mfc(dev_link_t *link)
661{
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;
668
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;
677 }
678
679 base = ioremap(req.Base, req.Size);
680 mem.Page = 0;
681 mem.CardOffset = 0;
682 pcmcia_map_mem_page(link->win, &mem);
683
684 ioaddr = dev->base_addr;
685 writeb(0x47, base+0x800); /* Config Option Register of LAN */
686 writeb(0x0, base+0x802); /* Config and Status Register */
687
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 */
690
691 writeb(0x45, base+0x820); /* Config Option Register of Modem */
692 writeb(0x8, base+0x822); /* Config and Status Register */
693
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;
699
700}
701/*====================================================================*/
702
703static void fmvj18x_release(dev_link_t *link)
704{
705
706 DEBUG(0, "fmvj18x_release(0x%p)\n", link);
707
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);
713
714 link->state &= ~DEV_CONFIG;
715}
716
717/*====================================================================*/
718
719static int fmvj18x_event(event_t event, int priority,
720 event_callback_args_t *args)
721{
722 dev_link_t *link = args->client_data;
723 struct net_device *dev = link->priv;
724
725 DEBUG(1, "fmvj18x_event(0x%06x)\n", event);
726
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);
745 }
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);
756 }
757 }
758 break;
759 }
760 return 0;
761} /* fmvj18x_event */
762
Dominik Brodowskicda4de82005-06-27 16:28:22 -0700763static 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),
Jun Komurof4d75102005-06-27 16:28:44 -0700782 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0105, 0x0d0a),
783 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0105, 0x0e0a),
Dominik Brodowskicda4de82005-06-27 16:28:22 -0700784 PCMCIA_DEVICE_NULL,
785};
786MODULE_DEVICE_TABLE(pcmcia, fmvj18x_ids);
787
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788static struct pcmcia_driver fmvj18x_cs_driver = {
789 .owner = THIS_MODULE,
790 .drv = {
791 .name = "fmvj18x_cs",
792 },
793 .attach = fmvj18x_attach,
Dominik Brodowski1e212f32005-07-07 17:59:00 -0700794 .event = fmvj18x_event,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 .detach = fmvj18x_detach,
Dominik Brodowskicda4de82005-06-27 16:28:22 -0700796 .id_table = fmvj18x_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797};
798
799static int __init init_fmvj18x_cs(void)
800{
801 return pcmcia_register_driver(&fmvj18x_cs_driver);
802}
803
804static void __exit exit_fmvj18x_cs(void)
805{
806 pcmcia_unregister_driver(&fmvj18x_cs_driver);
807 BUG_ON(dev_list != NULL);
808}
809
810module_init(init_fmvj18x_cs);
811module_exit(exit_fmvj18x_cs);
812
813/*====================================================================*/
814
815static irqreturn_t fjn_interrupt(int irq, void *dev_id, struct pt_regs *regs)
816{
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;
821
822 if (lp == NULL) {
823 printk(KERN_NOTICE "fjn_interrupt(): irq %d for "
824 "unknown device.\n", irq);
825 return IRQ_NONE;
826 }
827 ioaddr = dev->base_addr;
828
829 /* avoid multiple interrupts */
830 outw(0x0000, ioaddr + TX_INTR);
831
832 /* wait for a while */
833 udelay(1);
834
835 /* get status */
836 tx_stat = inb(ioaddr + TX_STATUS);
837 rx_stat = inb(ioaddr + RX_STATUS);
838
839 /* clear status */
840 outb(tx_stat, ioaddr + TX_STATUS);
841 outb(rx_stat, ioaddr + RX_STATUS);
842
843 DEBUG(4, "%s: interrupt, rx_status %02x.\n", dev->name, rx_stat);
844 DEBUG(4, " tx_status %02x.\n", tx_stat);
845
846 if (rx_stat || (inb(ioaddr + RX_MODE) & F_BUF_EMP) == 0) {
847 /* there is packet(s) in rx buffer */
848 fjn_rx(dev);
849 }
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;
861 }
862 netif_wake_queue(dev);
863 }
864 DEBUG(4, "%s: exiting interrupt,\n", dev->name);
865 DEBUG(4, " tx_status %02x, rx_status %02x.\n", tx_stat, rx_stat);
866
867 outb(D_TX_INTR, ioaddr + TX_INTR);
868 outb(D_RX_INTR, ioaddr + RX_INTR);
869 return IRQ_HANDLED;
870
871} /* fjn_interrupt */
872
873/*====================================================================*/
874
875static void fjn_tx_timeout(struct net_device *dev)
876{
877 struct local_info_t *lp = netdev_priv(dev);
878 kio_addr_t ioaddr = dev->base_addr;
879
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);
895
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);
903}
904
905static int fjn_start_xmit(struct sk_buff *skb, struct net_device *dev)
906{
907 struct local_info_t *lp = netdev_priv(dev);
908 kio_addr_t ioaddr = dev->base_addr;
909 short length = skb->len;
910
911 if (length < ETH_ZLEN)
912 {
913 skb = skb_padto(skb, ETH_ZLEN);
914 if (skb == NULL)
915 return 0;
916 length = ETH_ZLEN;
917 }
918
919 netif_stop_queue(dev);
920
921 {
922 unsigned char *buf = skb->data;
923
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;
928 }
929
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;
933
934 /* Disable both interrupts. */
935 outw(0x0000, ioaddr + TX_INTR);
936
937 /* wait for a while */
938 udelay(1);
939
940 outw(length, ioaddr + DATAPORT);
941 outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1);
942
943 lp->tx_queue++;
944 lp->tx_queue_len += ((length+3) & ~1);
945
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);
965 }
966 }
967
968 /* Re-enable interrupts */
969 outb(D_TX_INTR, ioaddr + TX_INTR);
970 outb(D_RX_INTR, ioaddr + RX_INTR);
971 }
972 dev_kfree_skb (skb);
973
974 return 0;
975} /* fjn_start_xmit */
976
977/*====================================================================*/
978
979static void fjn_reset(struct net_device *dev)
980{
981 struct local_info_t *lp = netdev_priv(dev);
982 kio_addr_t ioaddr = dev->base_addr;
983 int i;
984
985 DEBUG(4, "fjn_reset(%s) called.\n",dev->name);
986
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);
992
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);
998
999 /* Set Tx modes */
1000 outb(D_TX_MODE, ioaddr + TX_MODE);
1001 /* set Rx modes */
1002 outb(ID_MATCHED, ioaddr + RX_MODE);
1003
1004 /* Set hardware address */
1005 for (i = 0; i < 6; i++)
1006 outb(dev->dev_addr[i], ioaddr + NODE_ID + i);
1007
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);
1013
1014 /* set the multicast table to accept none. */
Komurod9a8a0a2005-08-06 12:01:43 +09001015 for (i = 0; i < 8; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 outb(0x00, ioaddr + MAR_ADR + i);
1017
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);
1023
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);
1029
1030 /* clear Reserved Regs */
1031 outb(0x00, ioaddr + BMPR12);
1032 outb(0x00, ioaddr + BMPR13);
1033
1034 /* reset Skip packet reg. */
1035 outb(0x01, ioaddr + RX_SKIP);
1036
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);
1042
1043 /* Init receive pointer ? */
1044 inw(ioaddr + DATAPORT);
1045 inw(ioaddr + DATAPORT);
1046
1047 /* Clear all status */
1048 outb(0xff, ioaddr + TX_STATUS);
1049 outb(0xff, ioaddr + RX_STATUS);
1050
1051 if (lp->cardtype == MBH10302)
1052 outb(INTR_OFF, ioaddr + LAN_CTRL);
1053
1054 /* Turn on Rx interrupts */
1055 outb(D_TX_INTR, ioaddr + TX_INTR);
1056 outb(D_RX_INTR, ioaddr + RX_INTR);
1057
1058 /* Turn on interrupts from LAN card controller */
1059 if (lp->cardtype == MBH10302)
1060 outb(INTR_ON, ioaddr + LAN_CTRL);
1061} /* fjn_reset */
1062
1063/*====================================================================*/
1064
1065static void fjn_rx(struct net_device *dev)
1066{
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 */
1070
1071 DEBUG(4, "%s: in rx_packet(), rx_status %02x.\n",
1072 dev->name, inb(ioaddr + RX_STATUS));
1073
1074 while ((inb(ioaddr + RX_MODE) & F_BUF_EMP) == 0) {
1075 u_short status = inw(ioaddr + DATAPORT);
1076
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;
1083 }
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;
1095
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;
1102 }
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;
1110 }
1111 skb->dev = dev;
1112
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);
1117
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");
1126 }
1127#endif
1128
1129 netif_rx(skb);
1130 dev->last_rx = jiffies;
1131 lp->stats.rx_packets++;
1132 lp->stats.rx_bytes += pkt_len;
1133 }
1134 if (--boguscount <= 0)
1135 break;
1136 }
1137
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. */
1141/*
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);
1149 }
1150
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);
1154 }
1155*/
1156
1157 return;
1158} /* fjn_rx */
1159
1160/*====================================================================*/
1161
1162static void netdev_get_drvinfo(struct net_device *dev,
1163 struct ethtool_drvinfo *info)
1164{
1165 strcpy(info->driver, DRV_NAME);
1166 strcpy(info->version, DRV_VERSION);
1167 sprintf(info->bus_info, "PCMCIA 0x%lx", dev->base_addr);
1168}
1169
1170#ifdef PCMCIA_DEBUG
1171static u32 netdev_get_msglevel(struct net_device *dev)
1172{
1173 return pc_debug;
1174}
1175
1176static void netdev_set_msglevel(struct net_device *dev, u32 level)
1177{
1178 pc_debug = level;
1179}
1180#endif /* PCMCIA_DEBUG */
1181
1182static 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 */
1188};
1189
1190static int fjn_config(struct net_device *dev, struct ifmap *map){
1191 return 0;
1192}
1193
1194static int fjn_open(struct net_device *dev)
1195{
1196 struct local_info_t *lp = netdev_priv(dev);
1197 dev_link_t *link = &lp->link;
1198
1199 DEBUG(4, "fjn_open('%s').\n", dev->name);
1200
1201 if (!DEV_OK(link))
1202 return -ENODEV;
1203
1204 link->open++;
1205
1206 fjn_reset(dev);
1207
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);
1213
1214 return 0;
1215} /* fjn_open */
1216
1217/*====================================================================*/
1218
1219static int fjn_close(struct net_device *dev)
1220{
1221 struct local_info_t *lp = netdev_priv(dev);
1222 dev_link_t *link = &lp->link;
1223 kio_addr_t ioaddr = dev->base_addr;
1224
1225 DEBUG(4, "fjn_close('%s').\n", dev->name);
1226
1227 lp->open_time = 0;
1228 netif_stop_queue(dev);
1229
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);
1235
1236 /* Update the statistics -- ToDo. */
1237
1238 /* Power-down the chip. Green, green, green! */
1239 outb(CHIP_OFF ,ioaddr + CONFIG_1);
1240
1241 /* Set the ethernet adaptor disable IRQ */
1242 if (lp->cardtype == MBH10302)
1243 outb(INTR_OFF, ioaddr + LAN_CTRL);
1244
1245 link->open--;
1246
1247 return 0;
1248} /* fjn_close */
1249
1250/*====================================================================*/
1251
1252static struct net_device_stats *fjn_get_stats(struct net_device *dev)
1253{
1254 local_info_t *lp = netdev_priv(dev);
1255 return &lp->stats;
1256} /* fjn_get_stats */
1257
1258/*====================================================================*/
1259
1260/*
1261 Set the multicast/promiscuous mode for this adaptor.
1262*/
1263
1264static void set_rx_mode(struct net_device *dev)
1265{
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;
1271
Komurod9a8a0a2005-08-06 12:01:43 +09001272 int saved_config_0 = inb(ioaddr + CONFIG_0);
1273
1274 local_irq_save(flags);
1275
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);
1281
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 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;
1298
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 =
Komurod9a8a0a2005-08-06 12:01:43 +09001303 ether_crc_le(ETH_ALEN, mclist->dmi_addr) >> 26;
1304 mc_filter[bit >> 3] |= (1 << (bit & 7));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 }
Komurod9a8a0a2005-08-06 12:01:43 +09001306 outb(2, ioaddr + RX_MODE); /* Use normal mode. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 }
1308
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 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++)
Komurod9a8a0a2005-08-06 12:01:43 +09001314 outb(mc_filter[i], ioaddr + MAR_ADR + i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 memcpy(lp->mc_filter, mc_filter, sizeof(mc_filter));
1316 outb(saved_bank, ioaddr + CONFIG_1);
1317 }
Komurod9a8a0a2005-08-06 12:01:43 +09001318
1319 outb(saved_config_0, ioaddr + CONFIG_0);
1320
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 local_irq_restore(flags);
1322}