31 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33 #define DRV_NAME "fmvj18x_cs"
34 #define DRV_VERSION "2.9"
36 #include <linux/module.h>
37 #include <linux/kernel.h>
39 #include <linux/ptrace.h>
40 #include <linux/slab.h>
41 #include <linux/string.h>
46 #include <linux/ethtool.h>
47 #include <linux/netdevice.h>
50 #include <linux/if_arp.h>
58 #include <asm/uaccess.h>
68 #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
79 static int fmvj18x_config(
struct pcmcia_device *
link);
81 static int fmvj18x_setup_mfc(
struct pcmcia_device *
link);
82 static void fmvj18x_release(
struct pcmcia_device *
link);
83 static void fmvj18x_detach(
struct pcmcia_device *p_dev);
111 struct pcmcia_device *
p_dev;
121 #define MC_FILTERBREAK 64
149 #define UNGERMANN_MAC_ID 0x18
154 #define ENA_TMT_OK 0x80
155 #define ENA_TMT_REC 0x20
157 #define ENA_16_COL 0x02
158 #define ENA_TBUS_ERR 0x01
160 #define ENA_PKT_RDY 0x80
161 #define ENA_BUS_ERR 0x40
162 #define ENA_LEN_ERR 0x08
163 #define ENA_ALG_ERR 0x04
164 #define ENA_CRC_ERR 0x02
165 #define ENA_OVR_FLO 0x01
168 #define F_TMT_RDY 0x80
169 #define F_NET_BSY 0x40
170 #define F_TMT_OK 0x20
171 #define F_SRT_PKT 0x10
172 #define F_COL_ERR 0x04
173 #define F_16_COL 0x02
174 #define F_TBUS_ERR 0x01
176 #define F_PKT_RDY 0x80
177 #define F_BUS_ERR 0x40
178 #define F_LEN_ERR 0x08
179 #define F_ALG_ERR 0x04
180 #define F_CRC_ERR 0x02
181 #define F_OVR_FLO 0x01
183 #define F_BUF_EMP 0x40
185 #define F_SKP_PKT 0x05
188 #define D_TX_INTR ( ENA_TMT_OK )
189 #define D_RX_INTR ( ENA_PKT_RDY | ENA_LEN_ERR \
190 | ENA_ALG_ERR | ENA_CRC_ERR | ENA_OVR_FLO )
191 #define TX_STAT_M ( F_TMT_RDY )
192 #define RX_STAT_M ( F_PKT_RDY | F_LEN_ERR \
193 | F_ALG_ERR | F_CRC_ERR | F_OVR_FLO )
196 #define D_TX_MODE 0x06
197 #define ID_MATCHED 0x02
198 #define RECV_ALL 0x03
199 #define CONFIG0_DFL 0x5a
200 #define CONFIG0_DFL_1 0x5e
201 #define CONFIG0_RST 0xda
202 #define CONFIG0_RST_1 0xde
206 #define CHIP_OFF 0x80
208 #define SEND_PKT 0x81
209 #define AUTO_MODE 0x07
210 #define MANU_MODE 0x03
211 #define TDK_AUTO_MODE 0x47
212 #define TDK_MANU_MODE 0x43
213 #define INTR_OFF 0x0d
216 #define TX_TIMEOUT ((400*HZ)/1000)
223 .ndo_open = fjn_open,
224 .ndo_stop = fjn_close,
225 .ndo_start_xmit = fjn_start_xmit,
226 .ndo_tx_timeout = fjn_tx_timeout,
227 .ndo_set_config = fjn_config,
228 .ndo_set_rx_mode = set_rx_mode,
234 static int fmvj18x_probe(
struct pcmcia_device *
link)
239 dev_dbg(&link->dev,
"fmvj18x_attach()\n");
245 lp = netdev_priv(dev);
251 link->resource[0]->end = 32;
252 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
255 link->config_flags |= CONF_ENABLE_IRQ;
262 return fmvj18x_config(link);
267 static void fmvj18x_detach(
struct pcmcia_device *link)
271 dev_dbg(&link->dev,
"fmvj18x_detach\n");
275 fmvj18x_release(link);
282 static int mfc_try_io_port(
struct pcmcia_device *link)
285 static const unsigned int serial_base[5] =
286 { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
288 for (i = 0; i < 5; i++) {
289 link->resource[1]->start = serial_base[
i];
290 link->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
291 if (link->resource[1]->start == 0) {
292 link->resource[1]->end = 0;
293 pr_notice(
"out of resource for serial\n");
302 static int ungermann_try_io_port(
struct pcmcia_device *link)
310 for (ioaddr = 0x300; ioaddr < 0x3e0; ioaddr += 0x20) {
311 link->resource[0]->start = ioaddr;
316 ((link->resource[0]->start & 0x0f0) >> 3) | 0x22;
323 static int fmvj18x_ioprobe(
struct pcmcia_device *p_dev,
void *priv_data)
328 static int fmvj18x_config(
struct pcmcia_device *link)
335 char *card_name =
"unknown";
340 dev_dbg(&link->dev,
"fmvj18x_config\n");
349 ret = pcmcia_loop_config(link, fmvj18x_ioprobe,
NULL);
353 switch (link->manf_id) {
360 link->config_base = 0x800;
361 link->config_index = 0x47;
362 link->resource[1]->end = 8;
367 link->config_base = 0x800;
368 link->config_index = 0x47;
369 link->resource[1]->end = 8;
373 link->config_base = 0x800;
374 link->config_index = 0x47;
375 link->resource[1]->end = 8;
381 if (link->config_base == 0x0fe0)
397 switch (link->manf_id) {
401 link->config_index = 0x20;
404 link->config_index = 1;
412 link->config_index = 1;
416 if (link->resource[1]->end != 0) {
417 ret = mfc_try_io_port(link);
418 if (ret != 0)
goto failed;
420 ret = ungermann_try_io_port(link);
421 if (ret != 0)
goto failed;
434 dev->
irq = link->irq;
435 dev->
base_addr = link->resource[0]->start;
437 if (resource_size(link->resource[1]) != 0) {
438 ret = fmvj18x_setup_mfc(link);
439 if (ret != 0)
goto failed;
445 if (sram_config == 0)
465 card_name =
"FMV-J182";
473 for (i = 5; i < 11; i++)
477 if (pcmcia_get_mac_from_cis(link, dev))
479 if( cardtype ==
TDK ) {
480 card_name =
"TDK LAK-CD021";
481 }
else if( cardtype ==
LA501 ) {
483 }
else if( cardtype ==
NEC ) {
484 card_name =
"PK-UG-J001";
485 }
else if( cardtype ==
KME ) {
486 card_name =
"Panasonic";
488 card_name =
"C-NET(PC)C";
494 for (i = 0; i < 6; i++)
496 card_name =
"Access/CARD";
500 if (fmvj18x_get_hwinfo(link, buggybuf) == -1) {
501 pr_notice(
"unable to read hardware net address\n");
504 for (i = 0 ; i < 6; i++) {
507 card_name =
"FMV-J182";
512 for (i = 0; i < 6; i++)
514 card_name =
"FMV-J181";
527 netdev_info(dev,
"%s, sram %s, port %#3lx, irq %d, hw_addr %pM\n",
528 card_name, sram_config == 0 ?
"4K TX*2" :
"8K TX*2",
534 fmvj18x_release(link);
539 static int fmvj18x_get_hwinfo(
struct pcmcia_device *link,
u_char *
node_id)
545 link->resource[2]->flags |= WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|
WIN_ENABLE;
546 link->resource[2]->start = 0; link->resource[2]->end = 0;
551 base =
ioremap(link->resource[2]->start, resource_size(link->resource[2]));
560 for (i = 0; i < 0x200; i++) {
561 if (
readb(base+i*2) == 0x22) {
562 if (
readb(base+(i-1)*2) == 0xff &&
563 readb(base+(i+5)*2) == 0x04 &&
564 readb(base+(i+6)*2) == 0x06 &&
565 readb(base+(i+13)*2) == 0xff)
571 for (j = 0 ; j < 6; j++,i++) {
572 node_id[
j] =
readb(base+(i+7)*2);
578 return (i != 0x200) ? 0 : -1;
583 static int fmvj18x_setup_mfc(
struct pcmcia_device *link)
591 link->resource[3]->flags = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|
WIN_ENABLE;
592 link->resource[3]->start = link->resource[3]->end = 0;
598 resource_size(link->resource[3]));
600 netdev_notice(dev,
"ioremap failed\n");
626 static void fmvj18x_release(
struct pcmcia_device *link)
633 dev_dbg(&link->dev,
"fmvj18x_release\n");
645 static int fmvj18x_suspend(
struct pcmcia_device *link)
655 static int fmvj18x_resume(
struct pcmcia_device *link)
670 PCMCIA_DEVICE_MANF_CARD(0x0004, 0x0004),
671 PCMCIA_DEVICE_PROD_ID12(
"EAGLE Technology",
"NE200 ETHERNET LAN MBH10302 04", 0x528c88c4, 0x74f91e59),
672 PCMCIA_DEVICE_PROD_ID12(
"Eiger Labs,Inc",
"EPX-10BT PC Card Ethernet 10BT", 0x53af556e, 0x877f9922),
673 PCMCIA_DEVICE_PROD_ID12(
"Eiger labs,Inc.",
"EPX-10BT PC Card Ethernet 10BT", 0xf47e6c66, 0x877f9922),
674 PCMCIA_DEVICE_PROD_ID12(
"FUJITSU",
"LAN Card(FMV-J182)", 0x6ee5a3d8, 0x5baf31db),
675 PCMCIA_DEVICE_PROD_ID12(
"FUJITSU",
"MBH10308", 0x6ee5a3d8, 0x3f04875e),
676 PCMCIA_DEVICE_PROD_ID12(
"FUJITSU TOWA",
"LA501", 0xb8451188, 0x12939ba2),
677 PCMCIA_DEVICE_PROD_ID12(
"HITACHI",
"HT-4840-11", 0xf4f43949, 0x773910f4),
678 PCMCIA_DEVICE_PROD_ID12(
"NextComK.K.",
"NC5310B Ver1.0 ", 0x8cef4d3a, 0x075fc7b6),
679 PCMCIA_DEVICE_PROD_ID12(
"NextComK.K.",
"NC5310 Ver1.0 ", 0x8cef4d3a, 0xbccf43e6),
680 PCMCIA_DEVICE_PROD_ID12(
"RATOC System Inc.",
"10BASE_T CARD R280", 0x85c10e17, 0xd9413666),
681 PCMCIA_DEVICE_PROD_ID12(
"TDK",
"LAC-CD02x", 0x1eae9475, 0x8fa0ee70),
682 PCMCIA_DEVICE_PROD_ID12(
"TDK",
"LAC-CF010", 0x1eae9475, 0x7683bc9a),
683 PCMCIA_DEVICE_PROD_ID1(
"CONTEC Co.,Ltd.", 0x58d8fee2),
684 PCMCIA_DEVICE_PROD_ID1(
"PCMCIA LAN MBH10304 ES", 0x2599f454),
685 PCMCIA_DEVICE_PROD_ID1(
"PCMCIA MBH10302", 0x8f4005da),
686 PCMCIA_DEVICE_PROD_ID1(
"UBKK,V2.0", 0x90888080),
687 PCMCIA_PFC_DEVICE_PROD_ID12(0,
"TDK",
"GlobalNetworker 3410/3412", 0x1eae9475, 0xd9a93bed),
688 PCMCIA_PFC_DEVICE_PROD_ID12(0,
"NEC",
"PK-UG-J001" ,0x18df0ba0 ,0x831b1064),
689 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0105, 0x0d0a),
690 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0105, 0x0e0a),
691 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0032, 0x0e01),
692 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0032, 0x0a05),
693 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0032, 0x0b05),
694 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0032, 0x1101),
699 static struct pcmcia_driver fmvj18x_cs_driver = {
701 .name =
"fmvj18x_cs",
702 .probe = fmvj18x_probe,
703 .remove = fmvj18x_detach,
704 .id_table = fmvj18x_ids,
705 .suspend = fmvj18x_suspend,
706 .resume = fmvj18x_resume,
709 static int __init init_fmvj18x_cs(
void)
714 static void __exit exit_fmvj18x_cs(
void)
747 pr_debug(
"%s: interrupt, rx_status %02x.\n", dev->
name, rx_stat);
748 pr_debug(
" tx_status %02x.\n", tx_stat);
766 netif_wake_queue(dev);
769 pr_debug(
" tx_status %02x, rx_status %02x.\n", tx_stat, rx_stat);
786 static void fjn_tx_timeout(
struct net_device *dev)
791 netdev_notice(dev,
"transmit timed out with status %04x, %s?\n",
794 ?
"IRQ conflict" :
"network cable problem");
795 netdev_notice(dev,
"timeout registers: %04x %04x %04x "
796 "%04x %04x %04x %04x %04x.\n",
801 dev->
stats.tx_errors++;
812 netif_wake_queue(dev);
829 netif_stop_queue(dev);
832 unsigned char *buf = skb->
data;
835 netdev_notice(dev,
"Attempting to send a large packet (%d bytes)\n",
840 netdev_dbg(dev,
"Transmitting a packet of length %lu\n",
841 (
unsigned long)skb->
len);
863 netif_start_queue(dev);
865 if( sram_config == 0 ) {
868 netif_start_queue(dev);
873 netif_start_queue(dev);
897 if( sram_config == 0 )
914 for (i = 0; i < 6; i++)
940 if( sram_config == 0 )
972 pr_debug(
"%s: in rx_packet(), rx_status %02x.\n",
975 while ((
inb(ioaddr +
RX_MODE) & F_BUF_EMP) == 0) {
978 netdev_dbg(dev,
"Rxing packet mode %02x status %04x.\n",
980 #ifndef final_version
986 if ((status & 0xF0) != 0x20) {
987 dev->
stats.rx_errors++;
997 if (pkt_len > 1550) {
998 netdev_notice(dev,
"The FMV-18x claimed a very large packet, size %d\n",
1001 dev->
stats.rx_errors++;
1004 skb = netdev_alloc_skb(dev, pkt_len + 2);
1006 netdev_notice(dev,
"Memory squeeze, dropping packet (len %d)\n",
1009 dev->
stats.rx_dropped++;
1013 skb_reserve(skb, 2);
1015 (pkt_len + 1) >> 1);
1020 pr_debug(
"%s: Rxed packet of length %d: ",
1021 dev->
name, pkt_len);
1022 for (i = 0; i < 14; i++)
1028 dev->
stats.rx_packets++;
1031 if (--boguscount <= 0)
1057 static void netdev_get_drvinfo(
struct net_device *dev,
1066 static const struct ethtool_ops netdev_ethtool_ops = {
1067 .get_drvinfo = netdev_get_drvinfo,
1077 struct pcmcia_device *link = lp->
p_dev;
1092 netif_start_queue(dev);
1102 struct pcmcia_device *link = lp->
p_dev;
1108 netif_stop_queue(dev);
1111 if( sram_config == 0 )
1136 static void set_rx_mode(
struct net_device *dev)
1149 if (sram_config == 0)
1155 memset(mc_filter, 0xff,
sizeof(mc_filter));
1160 memset(mc_filter, 0xff,
sizeof(mc_filter));
1163 memset(mc_filter, 0x00,
sizeof(mc_filter));
1168 memset(mc_filter, 0,
sizeof(mc_filter));
1171 mc_filter[bit >> 3] |= (1 << (bit & 7));
1180 for (i = 0; i < 8; i++)