18c2ecf20Sopenharmony_ci/*====================================================================== 28c2ecf20Sopenharmony_ci fmvj18x_cs.c 2.8 2002/03/23 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci A fmvj18x (and its compatibles) PCMCIA client driver 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci Contributed by Shingo Fujimoto, shingo@flab.fujitsu.co.jp 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci TDK LAK-CD021 and CONTEC C-NET(PC)C support added by 98c2ecf20Sopenharmony_ci Nobuhiro Katayama, kata-n@po.iijnet.or.jp 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci The PCMCIA client code is based on code written by David Hinds. 128c2ecf20Sopenharmony_ci Network code is based on the "FMV-18x driver" by Yutaka TAMIYA 138c2ecf20Sopenharmony_ci but is actually largely Donald Becker's AT1700 driver, which 148c2ecf20Sopenharmony_ci carries the following attribution: 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci Written 1993-94 by Donald Becker. 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci Copyright 1993 United States Government as represented by the 198c2ecf20Sopenharmony_ci Director, National Security Agency. 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci This software may be used and distributed according to the terms 228c2ecf20Sopenharmony_ci of the GNU General Public License, incorporated herein by reference. 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci The author may be reached as becker@scyld.com, or C/O 258c2ecf20Sopenharmony_ci Scyld Computing Corporation 268c2ecf20Sopenharmony_ci 410 Severn Ave., Suite 210 278c2ecf20Sopenharmony_ci Annapolis MD 21403 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci======================================================================*/ 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define DRV_NAME "fmvj18x_cs" 348c2ecf20Sopenharmony_ci#define DRV_VERSION "2.9" 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#include <linux/module.h> 378c2ecf20Sopenharmony_ci#include <linux/kernel.h> 388c2ecf20Sopenharmony_ci#include <linux/ptrace.h> 398c2ecf20Sopenharmony_ci#include <linux/slab.h> 408c2ecf20Sopenharmony_ci#include <linux/string.h> 418c2ecf20Sopenharmony_ci#include <linux/timer.h> 428c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 438c2ecf20Sopenharmony_ci#include <linux/in.h> 448c2ecf20Sopenharmony_ci#include <linux/delay.h> 458c2ecf20Sopenharmony_ci#include <linux/ethtool.h> 468c2ecf20Sopenharmony_ci#include <linux/netdevice.h> 478c2ecf20Sopenharmony_ci#include <linux/etherdevice.h> 488c2ecf20Sopenharmony_ci#include <linux/skbuff.h> 498c2ecf20Sopenharmony_ci#include <linux/if_arp.h> 508c2ecf20Sopenharmony_ci#include <linux/ioport.h> 518c2ecf20Sopenharmony_ci#include <linux/crc32.h> 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci#include <pcmcia/cistpl.h> 548c2ecf20Sopenharmony_ci#include <pcmcia/ciscode.h> 558c2ecf20Sopenharmony_ci#include <pcmcia/ds.h> 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci#include <linux/uaccess.h> 588c2ecf20Sopenharmony_ci#include <asm/io.h> 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci/*====================================================================*/ 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci/* Module parameters */ 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("fmvj18x and compatible PCMCIA ethernet driver"); 658c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0) 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci/* SRAM configuration */ 708c2ecf20Sopenharmony_ci/* 0:4KB*2 TX buffer else:8KB*2 TX buffer */ 718c2ecf20Sopenharmony_ciINT_MODULE_PARM(sram_config, 0); 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci/*====================================================================*/ 758c2ecf20Sopenharmony_ci/* 768c2ecf20Sopenharmony_ci PCMCIA event handlers 778c2ecf20Sopenharmony_ci */ 788c2ecf20Sopenharmony_cistatic int fmvj18x_config(struct pcmcia_device *link); 798c2ecf20Sopenharmony_cistatic int fmvj18x_get_hwinfo(struct pcmcia_device *link, u_char *node_id); 808c2ecf20Sopenharmony_cistatic int fmvj18x_setup_mfc(struct pcmcia_device *link); 818c2ecf20Sopenharmony_cistatic void fmvj18x_release(struct pcmcia_device *link); 828c2ecf20Sopenharmony_cistatic void fmvj18x_detach(struct pcmcia_device *p_dev); 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci/* 858c2ecf20Sopenharmony_ci LAN controller(MBH86960A) specific routines 868c2ecf20Sopenharmony_ci */ 878c2ecf20Sopenharmony_cistatic int fjn_config(struct net_device *dev, struct ifmap *map); 888c2ecf20Sopenharmony_cistatic int fjn_open(struct net_device *dev); 898c2ecf20Sopenharmony_cistatic int fjn_close(struct net_device *dev); 908c2ecf20Sopenharmony_cistatic netdev_tx_t fjn_start_xmit(struct sk_buff *skb, 918c2ecf20Sopenharmony_ci struct net_device *dev); 928c2ecf20Sopenharmony_cistatic irqreturn_t fjn_interrupt(int irq, void *dev_id); 938c2ecf20Sopenharmony_cistatic void fjn_rx(struct net_device *dev); 948c2ecf20Sopenharmony_cistatic void fjn_reset(struct net_device *dev); 958c2ecf20Sopenharmony_cistatic void set_rx_mode(struct net_device *dev); 968c2ecf20Sopenharmony_cistatic void fjn_tx_timeout(struct net_device *dev, unsigned int txqueue); 978c2ecf20Sopenharmony_cistatic const struct ethtool_ops netdev_ethtool_ops; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci/* 1008c2ecf20Sopenharmony_ci card type 1018c2ecf20Sopenharmony_ci */ 1028c2ecf20Sopenharmony_cienum cardtype { MBH10302, MBH10304, TDK, CONTEC, LA501, UNGERMANN, 1038c2ecf20Sopenharmony_ci XXX10304, NEC, KME 1048c2ecf20Sopenharmony_ci}; 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci/* 1078c2ecf20Sopenharmony_ci driver specific data structure 1088c2ecf20Sopenharmony_ci*/ 1098c2ecf20Sopenharmony_cistruct local_info { 1108c2ecf20Sopenharmony_ci struct pcmcia_device *p_dev; 1118c2ecf20Sopenharmony_ci long open_time; 1128c2ecf20Sopenharmony_ci uint tx_started:1; 1138c2ecf20Sopenharmony_ci uint tx_queue; 1148c2ecf20Sopenharmony_ci u_short tx_queue_len; 1158c2ecf20Sopenharmony_ci enum cardtype cardtype; 1168c2ecf20Sopenharmony_ci u_short sent; 1178c2ecf20Sopenharmony_ci u_char __iomem *base; 1188c2ecf20Sopenharmony_ci}; 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci#define MC_FILTERBREAK 64 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci/*====================================================================*/ 1238c2ecf20Sopenharmony_ci/* 1248c2ecf20Sopenharmony_ci ioport offset from the base address 1258c2ecf20Sopenharmony_ci */ 1268c2ecf20Sopenharmony_ci#define TX_STATUS 0 /* transmit status register */ 1278c2ecf20Sopenharmony_ci#define RX_STATUS 1 /* receive status register */ 1288c2ecf20Sopenharmony_ci#define TX_INTR 2 /* transmit interrupt mask register */ 1298c2ecf20Sopenharmony_ci#define RX_INTR 3 /* receive interrupt mask register */ 1308c2ecf20Sopenharmony_ci#define TX_MODE 4 /* transmit mode register */ 1318c2ecf20Sopenharmony_ci#define RX_MODE 5 /* receive mode register */ 1328c2ecf20Sopenharmony_ci#define CONFIG_0 6 /* configuration register 0 */ 1338c2ecf20Sopenharmony_ci#define CONFIG_1 7 /* configuration register 1 */ 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci#define NODE_ID 8 /* node ID register (bank 0) */ 1368c2ecf20Sopenharmony_ci#define MAR_ADR 8 /* multicast address registers (bank 1) */ 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci#define DATAPORT 8 /* buffer mem port registers (bank 2) */ 1398c2ecf20Sopenharmony_ci#define TX_START 10 /* transmit start register */ 1408c2ecf20Sopenharmony_ci#define COL_CTRL 11 /* 16 collision control register */ 1418c2ecf20Sopenharmony_ci#define BMPR12 12 /* reserved */ 1428c2ecf20Sopenharmony_ci#define BMPR13 13 /* reserved */ 1438c2ecf20Sopenharmony_ci#define RX_SKIP 14 /* skip received packet register */ 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci#define LAN_CTRL 16 /* LAN card control register */ 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci#define MAC_ID 0x1a /* hardware address */ 1488c2ecf20Sopenharmony_ci#define UNGERMANN_MAC_ID 0x18 /* UNGERMANN-BASS hardware address */ 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci/* 1518c2ecf20Sopenharmony_ci control bits 1528c2ecf20Sopenharmony_ci */ 1538c2ecf20Sopenharmony_ci#define ENA_TMT_OK 0x80 1548c2ecf20Sopenharmony_ci#define ENA_TMT_REC 0x20 1558c2ecf20Sopenharmony_ci#define ENA_COL 0x04 1568c2ecf20Sopenharmony_ci#define ENA_16_COL 0x02 1578c2ecf20Sopenharmony_ci#define ENA_TBUS_ERR 0x01 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci#define ENA_PKT_RDY 0x80 1608c2ecf20Sopenharmony_ci#define ENA_BUS_ERR 0x40 1618c2ecf20Sopenharmony_ci#define ENA_LEN_ERR 0x08 1628c2ecf20Sopenharmony_ci#define ENA_ALG_ERR 0x04 1638c2ecf20Sopenharmony_ci#define ENA_CRC_ERR 0x02 1648c2ecf20Sopenharmony_ci#define ENA_OVR_FLO 0x01 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci/* flags */ 1678c2ecf20Sopenharmony_ci#define F_TMT_RDY 0x80 /* can accept new packet */ 1688c2ecf20Sopenharmony_ci#define F_NET_BSY 0x40 /* carrier is detected */ 1698c2ecf20Sopenharmony_ci#define F_TMT_OK 0x20 /* send packet successfully */ 1708c2ecf20Sopenharmony_ci#define F_SRT_PKT 0x10 /* short packet error */ 1718c2ecf20Sopenharmony_ci#define F_COL_ERR 0x04 /* collision error */ 1728c2ecf20Sopenharmony_ci#define F_16_COL 0x02 /* 16 collision error */ 1738c2ecf20Sopenharmony_ci#define F_TBUS_ERR 0x01 /* bus read error */ 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci#define F_PKT_RDY 0x80 /* packet(s) in buffer */ 1768c2ecf20Sopenharmony_ci#define F_BUS_ERR 0x40 /* bus read error */ 1778c2ecf20Sopenharmony_ci#define F_LEN_ERR 0x08 /* short packet */ 1788c2ecf20Sopenharmony_ci#define F_ALG_ERR 0x04 /* frame error */ 1798c2ecf20Sopenharmony_ci#define F_CRC_ERR 0x02 /* CRC error */ 1808c2ecf20Sopenharmony_ci#define F_OVR_FLO 0x01 /* overflow error */ 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci#define F_BUF_EMP 0x40 /* receive buffer is empty */ 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci#define F_SKP_PKT 0x05 /* drop packet in buffer */ 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci/* default bitmaps */ 1878c2ecf20Sopenharmony_ci#define D_TX_INTR ( ENA_TMT_OK ) 1888c2ecf20Sopenharmony_ci#define D_RX_INTR ( ENA_PKT_RDY | ENA_LEN_ERR \ 1898c2ecf20Sopenharmony_ci | ENA_ALG_ERR | ENA_CRC_ERR | ENA_OVR_FLO ) 1908c2ecf20Sopenharmony_ci#define TX_STAT_M ( F_TMT_RDY ) 1918c2ecf20Sopenharmony_ci#define RX_STAT_M ( F_PKT_RDY | F_LEN_ERR \ 1928c2ecf20Sopenharmony_ci | F_ALG_ERR | F_CRC_ERR | F_OVR_FLO ) 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci/* commands */ 1958c2ecf20Sopenharmony_ci#define D_TX_MODE 0x06 /* no tests, detect carrier */ 1968c2ecf20Sopenharmony_ci#define ID_MATCHED 0x02 /* (RX_MODE) */ 1978c2ecf20Sopenharmony_ci#define RECV_ALL 0x03 /* (RX_MODE) */ 1988c2ecf20Sopenharmony_ci#define CONFIG0_DFL 0x5a /* 16bit bus, 4K x 2 Tx queues */ 1998c2ecf20Sopenharmony_ci#define CONFIG0_DFL_1 0x5e /* 16bit bus, 8K x 2 Tx queues */ 2008c2ecf20Sopenharmony_ci#define CONFIG0_RST 0xda /* Data Link Controller off (CONFIG_0) */ 2018c2ecf20Sopenharmony_ci#define CONFIG0_RST_1 0xde /* Data Link Controller off (CONFIG_0) */ 2028c2ecf20Sopenharmony_ci#define BANK_0 0xa0 /* bank 0 (CONFIG_1) */ 2038c2ecf20Sopenharmony_ci#define BANK_1 0xa4 /* bank 1 (CONFIG_1) */ 2048c2ecf20Sopenharmony_ci#define BANK_2 0xa8 /* bank 2 (CONFIG_1) */ 2058c2ecf20Sopenharmony_ci#define CHIP_OFF 0x80 /* contrl chip power off (CONFIG_1) */ 2068c2ecf20Sopenharmony_ci#define DO_TX 0x80 /* do transmit packet */ 2078c2ecf20Sopenharmony_ci#define SEND_PKT 0x81 /* send a packet */ 2088c2ecf20Sopenharmony_ci#define AUTO_MODE 0x07 /* Auto skip packet on 16 col detected */ 2098c2ecf20Sopenharmony_ci#define MANU_MODE 0x03 /* Stop and skip packet on 16 col */ 2108c2ecf20Sopenharmony_ci#define TDK_AUTO_MODE 0x47 /* Auto skip packet on 16 col detected */ 2118c2ecf20Sopenharmony_ci#define TDK_MANU_MODE 0x43 /* Stop and skip packet on 16 col */ 2128c2ecf20Sopenharmony_ci#define INTR_OFF 0x0d /* LAN controller ignores interrupts */ 2138c2ecf20Sopenharmony_ci#define INTR_ON 0x1d /* LAN controller will catch interrupts */ 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci#define TX_TIMEOUT ((400*HZ)/1000) 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci#define BANK_0U 0x20 /* bank 0 (CONFIG_1) */ 2188c2ecf20Sopenharmony_ci#define BANK_1U 0x24 /* bank 1 (CONFIG_1) */ 2198c2ecf20Sopenharmony_ci#define BANK_2U 0x28 /* bank 2 (CONFIG_1) */ 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_cistatic const struct net_device_ops fjn_netdev_ops = { 2228c2ecf20Sopenharmony_ci .ndo_open = fjn_open, 2238c2ecf20Sopenharmony_ci .ndo_stop = fjn_close, 2248c2ecf20Sopenharmony_ci .ndo_start_xmit = fjn_start_xmit, 2258c2ecf20Sopenharmony_ci .ndo_tx_timeout = fjn_tx_timeout, 2268c2ecf20Sopenharmony_ci .ndo_set_config = fjn_config, 2278c2ecf20Sopenharmony_ci .ndo_set_rx_mode = set_rx_mode, 2288c2ecf20Sopenharmony_ci .ndo_set_mac_address = eth_mac_addr, 2298c2ecf20Sopenharmony_ci .ndo_validate_addr = eth_validate_addr, 2308c2ecf20Sopenharmony_ci}; 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_cistatic int fmvj18x_probe(struct pcmcia_device *link) 2338c2ecf20Sopenharmony_ci{ 2348c2ecf20Sopenharmony_ci struct local_info *lp; 2358c2ecf20Sopenharmony_ci struct net_device *dev; 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci dev_dbg(&link->dev, "fmvj18x_attach()\n"); 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci /* Make up a FMVJ18x specific data structure */ 2408c2ecf20Sopenharmony_ci dev = alloc_etherdev(sizeof(struct local_info)); 2418c2ecf20Sopenharmony_ci if (!dev) 2428c2ecf20Sopenharmony_ci return -ENOMEM; 2438c2ecf20Sopenharmony_ci lp = netdev_priv(dev); 2448c2ecf20Sopenharmony_ci link->priv = dev; 2458c2ecf20Sopenharmony_ci lp->p_dev = link; 2468c2ecf20Sopenharmony_ci lp->base = NULL; 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci /* The io structure describes IO port mapping */ 2498c2ecf20Sopenharmony_ci link->resource[0]->end = 32; 2508c2ecf20Sopenharmony_ci link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO; 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci /* General socket configuration */ 2538c2ecf20Sopenharmony_ci link->config_flags |= CONF_ENABLE_IRQ; 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci dev->netdev_ops = &fjn_netdev_ops; 2568c2ecf20Sopenharmony_ci dev->watchdog_timeo = TX_TIMEOUT; 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci dev->ethtool_ops = &netdev_ethtool_ops; 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ci return fmvj18x_config(link); 2618c2ecf20Sopenharmony_ci} /* fmvj18x_attach */ 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci/*====================================================================*/ 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_cistatic void fmvj18x_detach(struct pcmcia_device *link) 2668c2ecf20Sopenharmony_ci{ 2678c2ecf20Sopenharmony_ci struct net_device *dev = link->priv; 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci dev_dbg(&link->dev, "fmvj18x_detach\n"); 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci unregister_netdev(dev); 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_ci fmvj18x_release(link); 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ci free_netdev(dev); 2768c2ecf20Sopenharmony_ci} /* fmvj18x_detach */ 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci/*====================================================================*/ 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_cistatic int mfc_try_io_port(struct pcmcia_device *link) 2818c2ecf20Sopenharmony_ci{ 2828c2ecf20Sopenharmony_ci int i, ret; 2838c2ecf20Sopenharmony_ci static const unsigned int serial_base[5] = 2848c2ecf20Sopenharmony_ci { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 }; 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci for (i = 0; i < 5; i++) { 2878c2ecf20Sopenharmony_ci link->resource[1]->start = serial_base[i]; 2888c2ecf20Sopenharmony_ci link->resource[1]->flags |= IO_DATA_PATH_WIDTH_8; 2898c2ecf20Sopenharmony_ci if (link->resource[1]->start == 0) { 2908c2ecf20Sopenharmony_ci link->resource[1]->end = 0; 2918c2ecf20Sopenharmony_ci pr_notice("out of resource for serial\n"); 2928c2ecf20Sopenharmony_ci } 2938c2ecf20Sopenharmony_ci ret = pcmcia_request_io(link); 2948c2ecf20Sopenharmony_ci if (ret == 0) 2958c2ecf20Sopenharmony_ci return ret; 2968c2ecf20Sopenharmony_ci } 2978c2ecf20Sopenharmony_ci return ret; 2988c2ecf20Sopenharmony_ci} 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_cistatic int ungermann_try_io_port(struct pcmcia_device *link) 3018c2ecf20Sopenharmony_ci{ 3028c2ecf20Sopenharmony_ci int ret; 3038c2ecf20Sopenharmony_ci unsigned int ioaddr; 3048c2ecf20Sopenharmony_ci /* 3058c2ecf20Sopenharmony_ci Ungermann-Bass Access/CARD accepts 0x300,0x320,0x340,0x360 3068c2ecf20Sopenharmony_ci 0x380,0x3c0 only for ioport. 3078c2ecf20Sopenharmony_ci */ 3088c2ecf20Sopenharmony_ci for (ioaddr = 0x300; ioaddr < 0x3e0; ioaddr += 0x20) { 3098c2ecf20Sopenharmony_ci link->resource[0]->start = ioaddr; 3108c2ecf20Sopenharmony_ci ret = pcmcia_request_io(link); 3118c2ecf20Sopenharmony_ci if (ret == 0) { 3128c2ecf20Sopenharmony_ci /* calculate ConfigIndex value */ 3138c2ecf20Sopenharmony_ci link->config_index = 3148c2ecf20Sopenharmony_ci ((link->resource[0]->start & 0x0f0) >> 3) | 0x22; 3158c2ecf20Sopenharmony_ci return ret; 3168c2ecf20Sopenharmony_ci } 3178c2ecf20Sopenharmony_ci } 3188c2ecf20Sopenharmony_ci return ret; /* RequestIO failed */ 3198c2ecf20Sopenharmony_ci} 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_cistatic int fmvj18x_ioprobe(struct pcmcia_device *p_dev, void *priv_data) 3228c2ecf20Sopenharmony_ci{ 3238c2ecf20Sopenharmony_ci return 0; /* strange, but that's what the code did already before... */ 3248c2ecf20Sopenharmony_ci} 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_cistatic int fmvj18x_config(struct pcmcia_device *link) 3278c2ecf20Sopenharmony_ci{ 3288c2ecf20Sopenharmony_ci struct net_device *dev = link->priv; 3298c2ecf20Sopenharmony_ci struct local_info *lp = netdev_priv(dev); 3308c2ecf20Sopenharmony_ci int i, ret; 3318c2ecf20Sopenharmony_ci unsigned int ioaddr; 3328c2ecf20Sopenharmony_ci enum cardtype cardtype; 3338c2ecf20Sopenharmony_ci char *card_name = "unknown"; 3348c2ecf20Sopenharmony_ci u8 *buf; 3358c2ecf20Sopenharmony_ci size_t len; 3368c2ecf20Sopenharmony_ci u_char buggybuf[32]; 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci dev_dbg(&link->dev, "fmvj18x_config\n"); 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci link->io_lines = 5; 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_ci len = pcmcia_get_tuple(link, CISTPL_FUNCE, &buf); 3438c2ecf20Sopenharmony_ci kfree(buf); 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci if (len) { 3468c2ecf20Sopenharmony_ci /* Yes, I have CISTPL_FUNCE. Let's check CISTPL_MANFID */ 3478c2ecf20Sopenharmony_ci ret = pcmcia_loop_config(link, fmvj18x_ioprobe, NULL); 3488c2ecf20Sopenharmony_ci if (ret != 0) 3498c2ecf20Sopenharmony_ci goto failed; 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci switch (link->manf_id) { 3528c2ecf20Sopenharmony_ci case MANFID_TDK: 3538c2ecf20Sopenharmony_ci cardtype = TDK; 3548c2ecf20Sopenharmony_ci if (link->card_id == PRODID_TDK_GN3410 || 3558c2ecf20Sopenharmony_ci link->card_id == PRODID_TDK_NP9610 || 3568c2ecf20Sopenharmony_ci link->card_id == PRODID_TDK_MN3200) { 3578c2ecf20Sopenharmony_ci /* MultiFunction Card */ 3588c2ecf20Sopenharmony_ci link->config_base = 0x800; 3598c2ecf20Sopenharmony_ci link->config_index = 0x47; 3608c2ecf20Sopenharmony_ci link->resource[1]->end = 8; 3618c2ecf20Sopenharmony_ci } 3628c2ecf20Sopenharmony_ci break; 3638c2ecf20Sopenharmony_ci case MANFID_NEC: 3648c2ecf20Sopenharmony_ci cardtype = NEC; /* MultiFunction Card */ 3658c2ecf20Sopenharmony_ci link->config_base = 0x800; 3668c2ecf20Sopenharmony_ci link->config_index = 0x47; 3678c2ecf20Sopenharmony_ci link->resource[1]->end = 8; 3688c2ecf20Sopenharmony_ci break; 3698c2ecf20Sopenharmony_ci case MANFID_KME: 3708c2ecf20Sopenharmony_ci cardtype = KME; /* MultiFunction Card */ 3718c2ecf20Sopenharmony_ci link->config_base = 0x800; 3728c2ecf20Sopenharmony_ci link->config_index = 0x47; 3738c2ecf20Sopenharmony_ci link->resource[1]->end = 8; 3748c2ecf20Sopenharmony_ci break; 3758c2ecf20Sopenharmony_ci case MANFID_CONTEC: 3768c2ecf20Sopenharmony_ci cardtype = CONTEC; 3778c2ecf20Sopenharmony_ci break; 3788c2ecf20Sopenharmony_ci case MANFID_FUJITSU: 3798c2ecf20Sopenharmony_ci if (link->config_base == 0x0fe0) 3808c2ecf20Sopenharmony_ci cardtype = MBH10302; 3818c2ecf20Sopenharmony_ci else if (link->card_id == PRODID_FUJITSU_MBH10302) 3828c2ecf20Sopenharmony_ci /* RATOC REX-5588/9822/4886's PRODID are 0004(=MBH10302), 3838c2ecf20Sopenharmony_ci but these are MBH10304 based card. */ 3848c2ecf20Sopenharmony_ci cardtype = MBH10304; 3858c2ecf20Sopenharmony_ci else if (link->card_id == PRODID_FUJITSU_MBH10304) 3868c2ecf20Sopenharmony_ci cardtype = MBH10304; 3878c2ecf20Sopenharmony_ci else 3888c2ecf20Sopenharmony_ci cardtype = LA501; 3898c2ecf20Sopenharmony_ci break; 3908c2ecf20Sopenharmony_ci default: 3918c2ecf20Sopenharmony_ci cardtype = MBH10304; 3928c2ecf20Sopenharmony_ci } 3938c2ecf20Sopenharmony_ci } else { 3948c2ecf20Sopenharmony_ci /* old type card */ 3958c2ecf20Sopenharmony_ci switch (link->manf_id) { 3968c2ecf20Sopenharmony_ci case MANFID_FUJITSU: 3978c2ecf20Sopenharmony_ci if (link->card_id == PRODID_FUJITSU_MBH10304) { 3988c2ecf20Sopenharmony_ci cardtype = XXX10304; /* MBH10304 with buggy CIS */ 3998c2ecf20Sopenharmony_ci link->config_index = 0x20; 4008c2ecf20Sopenharmony_ci } else { 4018c2ecf20Sopenharmony_ci cardtype = MBH10302; /* NextCom NC5310, etc. */ 4028c2ecf20Sopenharmony_ci link->config_index = 1; 4038c2ecf20Sopenharmony_ci } 4048c2ecf20Sopenharmony_ci break; 4058c2ecf20Sopenharmony_ci case MANFID_UNGERMANN: 4068c2ecf20Sopenharmony_ci cardtype = UNGERMANN; 4078c2ecf20Sopenharmony_ci break; 4088c2ecf20Sopenharmony_ci default: 4098c2ecf20Sopenharmony_ci cardtype = MBH10302; 4108c2ecf20Sopenharmony_ci link->config_index = 1; 4118c2ecf20Sopenharmony_ci } 4128c2ecf20Sopenharmony_ci } 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_ci if (link->resource[1]->end != 0) { 4158c2ecf20Sopenharmony_ci ret = mfc_try_io_port(link); 4168c2ecf20Sopenharmony_ci if (ret != 0) goto failed; 4178c2ecf20Sopenharmony_ci } else if (cardtype == UNGERMANN) { 4188c2ecf20Sopenharmony_ci ret = ungermann_try_io_port(link); 4198c2ecf20Sopenharmony_ci if (ret != 0) goto failed; 4208c2ecf20Sopenharmony_ci } else { 4218c2ecf20Sopenharmony_ci ret = pcmcia_request_io(link); 4228c2ecf20Sopenharmony_ci if (ret) 4238c2ecf20Sopenharmony_ci goto failed; 4248c2ecf20Sopenharmony_ci } 4258c2ecf20Sopenharmony_ci ret = pcmcia_request_irq(link, fjn_interrupt); 4268c2ecf20Sopenharmony_ci if (ret) 4278c2ecf20Sopenharmony_ci goto failed; 4288c2ecf20Sopenharmony_ci ret = pcmcia_enable_device(link); 4298c2ecf20Sopenharmony_ci if (ret) 4308c2ecf20Sopenharmony_ci goto failed; 4318c2ecf20Sopenharmony_ci 4328c2ecf20Sopenharmony_ci dev->irq = link->irq; 4338c2ecf20Sopenharmony_ci dev->base_addr = link->resource[0]->start; 4348c2ecf20Sopenharmony_ci 4358c2ecf20Sopenharmony_ci if (resource_size(link->resource[1]) != 0) { 4368c2ecf20Sopenharmony_ci ret = fmvj18x_setup_mfc(link); 4378c2ecf20Sopenharmony_ci if (ret != 0) goto failed; 4388c2ecf20Sopenharmony_ci } 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ci ioaddr = dev->base_addr; 4418c2ecf20Sopenharmony_ci 4428c2ecf20Sopenharmony_ci /* Reset controller */ 4438c2ecf20Sopenharmony_ci if (sram_config == 0) 4448c2ecf20Sopenharmony_ci outb(CONFIG0_RST, ioaddr + CONFIG_0); 4458c2ecf20Sopenharmony_ci else 4468c2ecf20Sopenharmony_ci outb(CONFIG0_RST_1, ioaddr + CONFIG_0); 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci /* Power On chip and select bank 0 */ 4498c2ecf20Sopenharmony_ci if (cardtype == MBH10302) 4508c2ecf20Sopenharmony_ci outb(BANK_0, ioaddr + CONFIG_1); 4518c2ecf20Sopenharmony_ci else 4528c2ecf20Sopenharmony_ci outb(BANK_0U, ioaddr + CONFIG_1); 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_ci /* Set hardware address */ 4558c2ecf20Sopenharmony_ci switch (cardtype) { 4568c2ecf20Sopenharmony_ci case MBH10304: 4578c2ecf20Sopenharmony_ci case TDK: 4588c2ecf20Sopenharmony_ci case LA501: 4598c2ecf20Sopenharmony_ci case CONTEC: 4608c2ecf20Sopenharmony_ci case NEC: 4618c2ecf20Sopenharmony_ci case KME: 4628c2ecf20Sopenharmony_ci if (cardtype == MBH10304) { 4638c2ecf20Sopenharmony_ci card_name = "FMV-J182"; 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_ci len = pcmcia_get_tuple(link, CISTPL_FUNCE, &buf); 4668c2ecf20Sopenharmony_ci if (len < 11) { 4678c2ecf20Sopenharmony_ci kfree(buf); 4688c2ecf20Sopenharmony_ci goto failed; 4698c2ecf20Sopenharmony_ci } 4708c2ecf20Sopenharmony_ci /* Read MACID from CIS */ 4718c2ecf20Sopenharmony_ci for (i = 0; i < 6; i++) 4728c2ecf20Sopenharmony_ci dev->dev_addr[i] = buf[i + 5]; 4738c2ecf20Sopenharmony_ci kfree(buf); 4748c2ecf20Sopenharmony_ci } else { 4758c2ecf20Sopenharmony_ci if (pcmcia_get_mac_from_cis(link, dev)) 4768c2ecf20Sopenharmony_ci goto failed; 4778c2ecf20Sopenharmony_ci if( cardtype == TDK ) { 4788c2ecf20Sopenharmony_ci card_name = "TDK LAK-CD021"; 4798c2ecf20Sopenharmony_ci } else if( cardtype == LA501 ) { 4808c2ecf20Sopenharmony_ci card_name = "LA501"; 4818c2ecf20Sopenharmony_ci } else if( cardtype == NEC ) { 4828c2ecf20Sopenharmony_ci card_name = "PK-UG-J001"; 4838c2ecf20Sopenharmony_ci } else if( cardtype == KME ) { 4848c2ecf20Sopenharmony_ci card_name = "Panasonic"; 4858c2ecf20Sopenharmony_ci } else { 4868c2ecf20Sopenharmony_ci card_name = "C-NET(PC)C"; 4878c2ecf20Sopenharmony_ci } 4888c2ecf20Sopenharmony_ci } 4898c2ecf20Sopenharmony_ci break; 4908c2ecf20Sopenharmony_ci case UNGERMANN: 4918c2ecf20Sopenharmony_ci /* Read MACID from register */ 4928c2ecf20Sopenharmony_ci for (i = 0; i < 6; i++) 4938c2ecf20Sopenharmony_ci dev->dev_addr[i] = inb(ioaddr + UNGERMANN_MAC_ID + i); 4948c2ecf20Sopenharmony_ci card_name = "Access/CARD"; 4958c2ecf20Sopenharmony_ci break; 4968c2ecf20Sopenharmony_ci case XXX10304: 4978c2ecf20Sopenharmony_ci /* Read MACID from Buggy CIS */ 4988c2ecf20Sopenharmony_ci if (fmvj18x_get_hwinfo(link, buggybuf) == -1) { 4998c2ecf20Sopenharmony_ci pr_notice("unable to read hardware net address\n"); 5008c2ecf20Sopenharmony_ci goto failed; 5018c2ecf20Sopenharmony_ci } 5028c2ecf20Sopenharmony_ci for (i = 0 ; i < 6; i++) { 5038c2ecf20Sopenharmony_ci dev->dev_addr[i] = buggybuf[i]; 5048c2ecf20Sopenharmony_ci } 5058c2ecf20Sopenharmony_ci card_name = "FMV-J182"; 5068c2ecf20Sopenharmony_ci break; 5078c2ecf20Sopenharmony_ci case MBH10302: 5088c2ecf20Sopenharmony_ci default: 5098c2ecf20Sopenharmony_ci /* Read MACID from register */ 5108c2ecf20Sopenharmony_ci for (i = 0; i < 6; i++) 5118c2ecf20Sopenharmony_ci dev->dev_addr[i] = inb(ioaddr + MAC_ID + i); 5128c2ecf20Sopenharmony_ci card_name = "FMV-J181"; 5138c2ecf20Sopenharmony_ci break; 5148c2ecf20Sopenharmony_ci } 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_ci lp->cardtype = cardtype; 5178c2ecf20Sopenharmony_ci SET_NETDEV_DEV(dev, &link->dev); 5188c2ecf20Sopenharmony_ci 5198c2ecf20Sopenharmony_ci if (register_netdev(dev) != 0) { 5208c2ecf20Sopenharmony_ci pr_notice("register_netdev() failed\n"); 5218c2ecf20Sopenharmony_ci goto failed; 5228c2ecf20Sopenharmony_ci } 5238c2ecf20Sopenharmony_ci 5248c2ecf20Sopenharmony_ci /* print current configuration */ 5258c2ecf20Sopenharmony_ci netdev_info(dev, "%s, sram %s, port %#3lx, irq %d, hw_addr %pM\n", 5268c2ecf20Sopenharmony_ci card_name, sram_config == 0 ? "4K TX*2" : "8K TX*2", 5278c2ecf20Sopenharmony_ci dev->base_addr, dev->irq, dev->dev_addr); 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_ci return 0; 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_cifailed: 5328c2ecf20Sopenharmony_ci fmvj18x_release(link); 5338c2ecf20Sopenharmony_ci return -ENODEV; 5348c2ecf20Sopenharmony_ci} /* fmvj18x_config */ 5358c2ecf20Sopenharmony_ci/*====================================================================*/ 5368c2ecf20Sopenharmony_ci 5378c2ecf20Sopenharmony_cistatic int fmvj18x_get_hwinfo(struct pcmcia_device *link, u_char *node_id) 5388c2ecf20Sopenharmony_ci{ 5398c2ecf20Sopenharmony_ci u_char __iomem *base; 5408c2ecf20Sopenharmony_ci int i, j; 5418c2ecf20Sopenharmony_ci 5428c2ecf20Sopenharmony_ci /* Allocate a small memory window */ 5438c2ecf20Sopenharmony_ci link->resource[2]->flags |= WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 5448c2ecf20Sopenharmony_ci link->resource[2]->start = 0; link->resource[2]->end = 0; 5458c2ecf20Sopenharmony_ci i = pcmcia_request_window(link, link->resource[2], 0); 5468c2ecf20Sopenharmony_ci if (i != 0) 5478c2ecf20Sopenharmony_ci return -1; 5488c2ecf20Sopenharmony_ci 5498c2ecf20Sopenharmony_ci base = ioremap(link->resource[2]->start, resource_size(link->resource[2])); 5508c2ecf20Sopenharmony_ci if (!base) { 5518c2ecf20Sopenharmony_ci pcmcia_release_window(link, link->resource[2]); 5528c2ecf20Sopenharmony_ci return -1; 5538c2ecf20Sopenharmony_ci } 5548c2ecf20Sopenharmony_ci 5558c2ecf20Sopenharmony_ci pcmcia_map_mem_page(link, link->resource[2], 0); 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_ci /* 5588c2ecf20Sopenharmony_ci * MBH10304 CISTPL_FUNCE_LAN_NODE_ID format 5598c2ecf20Sopenharmony_ci * 22 0d xx xx xx 04 06 yy yy yy yy yy yy ff 5608c2ecf20Sopenharmony_ci * 'xx' is garbage. 5618c2ecf20Sopenharmony_ci * 'yy' is MAC address. 5628c2ecf20Sopenharmony_ci */ 5638c2ecf20Sopenharmony_ci for (i = 0; i < 0x200; i++) { 5648c2ecf20Sopenharmony_ci if (readb(base+i*2) == 0x22) { 5658c2ecf20Sopenharmony_ci if (readb(base+(i-1)*2) == 0xff && 5668c2ecf20Sopenharmony_ci readb(base+(i+5)*2) == 0x04 && 5678c2ecf20Sopenharmony_ci readb(base+(i+6)*2) == 0x06 && 5688c2ecf20Sopenharmony_ci readb(base+(i+13)*2) == 0xff) 5698c2ecf20Sopenharmony_ci break; 5708c2ecf20Sopenharmony_ci } 5718c2ecf20Sopenharmony_ci } 5728c2ecf20Sopenharmony_ci 5738c2ecf20Sopenharmony_ci if (i != 0x200) { 5748c2ecf20Sopenharmony_ci for (j = 0 ; j < 6; j++,i++) { 5758c2ecf20Sopenharmony_ci node_id[j] = readb(base+(i+7)*2); 5768c2ecf20Sopenharmony_ci } 5778c2ecf20Sopenharmony_ci } 5788c2ecf20Sopenharmony_ci 5798c2ecf20Sopenharmony_ci iounmap(base); 5808c2ecf20Sopenharmony_ci j = pcmcia_release_window(link, link->resource[2]); 5818c2ecf20Sopenharmony_ci return (i != 0x200) ? 0 : -1; 5828c2ecf20Sopenharmony_ci 5838c2ecf20Sopenharmony_ci} /* fmvj18x_get_hwinfo */ 5848c2ecf20Sopenharmony_ci/*====================================================================*/ 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_cistatic int fmvj18x_setup_mfc(struct pcmcia_device *link) 5878c2ecf20Sopenharmony_ci{ 5888c2ecf20Sopenharmony_ci int i; 5898c2ecf20Sopenharmony_ci struct net_device *dev = link->priv; 5908c2ecf20Sopenharmony_ci unsigned int ioaddr; 5918c2ecf20Sopenharmony_ci struct local_info *lp = netdev_priv(dev); 5928c2ecf20Sopenharmony_ci 5938c2ecf20Sopenharmony_ci /* Allocate a small memory window */ 5948c2ecf20Sopenharmony_ci link->resource[3]->flags = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 5958c2ecf20Sopenharmony_ci link->resource[3]->start = link->resource[3]->end = 0; 5968c2ecf20Sopenharmony_ci i = pcmcia_request_window(link, link->resource[3], 0); 5978c2ecf20Sopenharmony_ci if (i != 0) 5988c2ecf20Sopenharmony_ci return -1; 5998c2ecf20Sopenharmony_ci 6008c2ecf20Sopenharmony_ci lp->base = ioremap(link->resource[3]->start, 6018c2ecf20Sopenharmony_ci resource_size(link->resource[3])); 6028c2ecf20Sopenharmony_ci if (lp->base == NULL) { 6038c2ecf20Sopenharmony_ci netdev_notice(dev, "ioremap failed\n"); 6048c2ecf20Sopenharmony_ci return -1; 6058c2ecf20Sopenharmony_ci } 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_ci i = pcmcia_map_mem_page(link, link->resource[3], 0); 6088c2ecf20Sopenharmony_ci if (i != 0) { 6098c2ecf20Sopenharmony_ci iounmap(lp->base); 6108c2ecf20Sopenharmony_ci lp->base = NULL; 6118c2ecf20Sopenharmony_ci return -1; 6128c2ecf20Sopenharmony_ci } 6138c2ecf20Sopenharmony_ci 6148c2ecf20Sopenharmony_ci ioaddr = dev->base_addr; 6158c2ecf20Sopenharmony_ci writeb(0x47, lp->base+0x800); /* Config Option Register of LAN */ 6168c2ecf20Sopenharmony_ci writeb(0x0, lp->base+0x802); /* Config and Status Register */ 6178c2ecf20Sopenharmony_ci 6188c2ecf20Sopenharmony_ci writeb(ioaddr & 0xff, lp->base+0x80a); /* I/O Base(Low) of LAN */ 6198c2ecf20Sopenharmony_ci writeb((ioaddr >> 8) & 0xff, lp->base+0x80c); /* I/O Base(High) of LAN */ 6208c2ecf20Sopenharmony_ci 6218c2ecf20Sopenharmony_ci writeb(0x45, lp->base+0x820); /* Config Option Register of Modem */ 6228c2ecf20Sopenharmony_ci writeb(0x8, lp->base+0x822); /* Config and Status Register */ 6238c2ecf20Sopenharmony_ci 6248c2ecf20Sopenharmony_ci return 0; 6258c2ecf20Sopenharmony_ci 6268c2ecf20Sopenharmony_ci} 6278c2ecf20Sopenharmony_ci/*====================================================================*/ 6288c2ecf20Sopenharmony_ci 6298c2ecf20Sopenharmony_cistatic void fmvj18x_release(struct pcmcia_device *link) 6308c2ecf20Sopenharmony_ci{ 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_ci struct net_device *dev = link->priv; 6338c2ecf20Sopenharmony_ci struct local_info *lp = netdev_priv(dev); 6348c2ecf20Sopenharmony_ci u_char __iomem *tmp; 6358c2ecf20Sopenharmony_ci 6368c2ecf20Sopenharmony_ci dev_dbg(&link->dev, "fmvj18x_release\n"); 6378c2ecf20Sopenharmony_ci 6388c2ecf20Sopenharmony_ci if (lp->base != NULL) { 6398c2ecf20Sopenharmony_ci tmp = lp->base; 6408c2ecf20Sopenharmony_ci lp->base = NULL; /* set NULL before iounmap */ 6418c2ecf20Sopenharmony_ci iounmap(tmp); 6428c2ecf20Sopenharmony_ci } 6438c2ecf20Sopenharmony_ci 6448c2ecf20Sopenharmony_ci pcmcia_disable_device(link); 6458c2ecf20Sopenharmony_ci 6468c2ecf20Sopenharmony_ci} 6478c2ecf20Sopenharmony_ci 6488c2ecf20Sopenharmony_cistatic int fmvj18x_suspend(struct pcmcia_device *link) 6498c2ecf20Sopenharmony_ci{ 6508c2ecf20Sopenharmony_ci struct net_device *dev = link->priv; 6518c2ecf20Sopenharmony_ci 6528c2ecf20Sopenharmony_ci if (link->open) 6538c2ecf20Sopenharmony_ci netif_device_detach(dev); 6548c2ecf20Sopenharmony_ci 6558c2ecf20Sopenharmony_ci return 0; 6568c2ecf20Sopenharmony_ci} 6578c2ecf20Sopenharmony_ci 6588c2ecf20Sopenharmony_cistatic int fmvj18x_resume(struct pcmcia_device *link) 6598c2ecf20Sopenharmony_ci{ 6608c2ecf20Sopenharmony_ci struct net_device *dev = link->priv; 6618c2ecf20Sopenharmony_ci 6628c2ecf20Sopenharmony_ci if (link->open) { 6638c2ecf20Sopenharmony_ci fjn_reset(dev); 6648c2ecf20Sopenharmony_ci netif_device_attach(dev); 6658c2ecf20Sopenharmony_ci } 6668c2ecf20Sopenharmony_ci 6678c2ecf20Sopenharmony_ci return 0; 6688c2ecf20Sopenharmony_ci} 6698c2ecf20Sopenharmony_ci 6708c2ecf20Sopenharmony_ci/*====================================================================*/ 6718c2ecf20Sopenharmony_ci 6728c2ecf20Sopenharmony_cistatic const struct pcmcia_device_id fmvj18x_ids[] = { 6738c2ecf20Sopenharmony_ci PCMCIA_DEVICE_MANF_CARD(0x0004, 0x0004), 6748c2ecf20Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12("EAGLE Technology", "NE200 ETHERNET LAN MBH10302 04", 0x528c88c4, 0x74f91e59), 6758c2ecf20Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12("Eiger Labs,Inc", "EPX-10BT PC Card Ethernet 10BT", 0x53af556e, 0x877f9922), 6768c2ecf20Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12("Eiger labs,Inc.", "EPX-10BT PC Card Ethernet 10BT", 0xf47e6c66, 0x877f9922), 6778c2ecf20Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12("FUJITSU", "LAN Card(FMV-J182)", 0x6ee5a3d8, 0x5baf31db), 6788c2ecf20Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12("FUJITSU", "MBH10308", 0x6ee5a3d8, 0x3f04875e), 6798c2ecf20Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12("FUJITSU TOWA", "LA501", 0xb8451188, 0x12939ba2), 6808c2ecf20Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12("HITACHI", "HT-4840-11", 0xf4f43949, 0x773910f4), 6818c2ecf20Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12("NextComK.K.", "NC5310B Ver1.0 ", 0x8cef4d3a, 0x075fc7b6), 6828c2ecf20Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12("NextComK.K.", "NC5310 Ver1.0 ", 0x8cef4d3a, 0xbccf43e6), 6838c2ecf20Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12("RATOC System Inc.", "10BASE_T CARD R280", 0x85c10e17, 0xd9413666), 6848c2ecf20Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12("TDK", "LAC-CD02x", 0x1eae9475, 0x8fa0ee70), 6858c2ecf20Sopenharmony_ci PCMCIA_DEVICE_PROD_ID12("TDK", "LAC-CF010", 0x1eae9475, 0x7683bc9a), 6868c2ecf20Sopenharmony_ci PCMCIA_DEVICE_PROD_ID1("CONTEC Co.,Ltd.", 0x58d8fee2), 6878c2ecf20Sopenharmony_ci PCMCIA_DEVICE_PROD_ID1("PCMCIA LAN MBH10304 ES", 0x2599f454), 6888c2ecf20Sopenharmony_ci PCMCIA_DEVICE_PROD_ID1("PCMCIA MBH10302", 0x8f4005da), 6898c2ecf20Sopenharmony_ci PCMCIA_DEVICE_PROD_ID1("UBKK,V2.0", 0x90888080), 6908c2ecf20Sopenharmony_ci PCMCIA_PFC_DEVICE_PROD_ID12(0, "TDK", "GlobalNetworker 3410/3412", 0x1eae9475, 0xd9a93bed), 6918c2ecf20Sopenharmony_ci PCMCIA_PFC_DEVICE_PROD_ID12(0, "NEC", "PK-UG-J001" ,0x18df0ba0 ,0x831b1064), 6928c2ecf20Sopenharmony_ci PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0105, 0x0d0a), 6938c2ecf20Sopenharmony_ci PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0105, 0x0e0a), 6948c2ecf20Sopenharmony_ci PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0032, 0x0e01), 6958c2ecf20Sopenharmony_ci PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0032, 0x0a05), 6968c2ecf20Sopenharmony_ci PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0032, 0x0b05), 6978c2ecf20Sopenharmony_ci PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0032, 0x1101), 6988c2ecf20Sopenharmony_ci PCMCIA_DEVICE_NULL, 6998c2ecf20Sopenharmony_ci}; 7008c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pcmcia, fmvj18x_ids); 7018c2ecf20Sopenharmony_ci 7028c2ecf20Sopenharmony_cistatic struct pcmcia_driver fmvj18x_cs_driver = { 7038c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 7048c2ecf20Sopenharmony_ci .name = "fmvj18x_cs", 7058c2ecf20Sopenharmony_ci .probe = fmvj18x_probe, 7068c2ecf20Sopenharmony_ci .remove = fmvj18x_detach, 7078c2ecf20Sopenharmony_ci .id_table = fmvj18x_ids, 7088c2ecf20Sopenharmony_ci .suspend = fmvj18x_suspend, 7098c2ecf20Sopenharmony_ci .resume = fmvj18x_resume, 7108c2ecf20Sopenharmony_ci}; 7118c2ecf20Sopenharmony_cimodule_pcmcia_driver(fmvj18x_cs_driver); 7128c2ecf20Sopenharmony_ci 7138c2ecf20Sopenharmony_ci/*====================================================================*/ 7148c2ecf20Sopenharmony_ci 7158c2ecf20Sopenharmony_cistatic irqreturn_t fjn_interrupt(int dummy, void *dev_id) 7168c2ecf20Sopenharmony_ci{ 7178c2ecf20Sopenharmony_ci struct net_device *dev = dev_id; 7188c2ecf20Sopenharmony_ci struct local_info *lp = netdev_priv(dev); 7198c2ecf20Sopenharmony_ci unsigned int ioaddr; 7208c2ecf20Sopenharmony_ci unsigned short tx_stat, rx_stat; 7218c2ecf20Sopenharmony_ci 7228c2ecf20Sopenharmony_ci ioaddr = dev->base_addr; 7238c2ecf20Sopenharmony_ci 7248c2ecf20Sopenharmony_ci /* avoid multiple interrupts */ 7258c2ecf20Sopenharmony_ci outw(0x0000, ioaddr + TX_INTR); 7268c2ecf20Sopenharmony_ci 7278c2ecf20Sopenharmony_ci /* wait for a while */ 7288c2ecf20Sopenharmony_ci udelay(1); 7298c2ecf20Sopenharmony_ci 7308c2ecf20Sopenharmony_ci /* get status */ 7318c2ecf20Sopenharmony_ci tx_stat = inb(ioaddr + TX_STATUS); 7328c2ecf20Sopenharmony_ci rx_stat = inb(ioaddr + RX_STATUS); 7338c2ecf20Sopenharmony_ci 7348c2ecf20Sopenharmony_ci /* clear status */ 7358c2ecf20Sopenharmony_ci outb(tx_stat, ioaddr + TX_STATUS); 7368c2ecf20Sopenharmony_ci outb(rx_stat, ioaddr + RX_STATUS); 7378c2ecf20Sopenharmony_ci 7388c2ecf20Sopenharmony_ci pr_debug("%s: interrupt, rx_status %02x.\n", dev->name, rx_stat); 7398c2ecf20Sopenharmony_ci pr_debug(" tx_status %02x.\n", tx_stat); 7408c2ecf20Sopenharmony_ci 7418c2ecf20Sopenharmony_ci if (rx_stat || (inb(ioaddr + RX_MODE) & F_BUF_EMP) == 0) { 7428c2ecf20Sopenharmony_ci /* there is packet(s) in rx buffer */ 7438c2ecf20Sopenharmony_ci fjn_rx(dev); 7448c2ecf20Sopenharmony_ci } 7458c2ecf20Sopenharmony_ci if (tx_stat & F_TMT_RDY) { 7468c2ecf20Sopenharmony_ci dev->stats.tx_packets += lp->sent ; 7478c2ecf20Sopenharmony_ci lp->sent = 0 ; 7488c2ecf20Sopenharmony_ci if (lp->tx_queue) { 7498c2ecf20Sopenharmony_ci outb(DO_TX | lp->tx_queue, ioaddr + TX_START); 7508c2ecf20Sopenharmony_ci lp->sent = lp->tx_queue ; 7518c2ecf20Sopenharmony_ci lp->tx_queue = 0; 7528c2ecf20Sopenharmony_ci lp->tx_queue_len = 0; 7538c2ecf20Sopenharmony_ci netif_trans_update(dev); 7548c2ecf20Sopenharmony_ci } else { 7558c2ecf20Sopenharmony_ci lp->tx_started = 0; 7568c2ecf20Sopenharmony_ci } 7578c2ecf20Sopenharmony_ci netif_wake_queue(dev); 7588c2ecf20Sopenharmony_ci } 7598c2ecf20Sopenharmony_ci pr_debug("%s: exiting interrupt,\n", dev->name); 7608c2ecf20Sopenharmony_ci pr_debug(" tx_status %02x, rx_status %02x.\n", tx_stat, rx_stat); 7618c2ecf20Sopenharmony_ci 7628c2ecf20Sopenharmony_ci outb(D_TX_INTR, ioaddr + TX_INTR); 7638c2ecf20Sopenharmony_ci outb(D_RX_INTR, ioaddr + RX_INTR); 7648c2ecf20Sopenharmony_ci 7658c2ecf20Sopenharmony_ci if (lp->base != NULL) { 7668c2ecf20Sopenharmony_ci /* Ack interrupt for multifunction card */ 7678c2ecf20Sopenharmony_ci writeb(0x01, lp->base+0x802); 7688c2ecf20Sopenharmony_ci writeb(0x09, lp->base+0x822); 7698c2ecf20Sopenharmony_ci } 7708c2ecf20Sopenharmony_ci 7718c2ecf20Sopenharmony_ci return IRQ_HANDLED; 7728c2ecf20Sopenharmony_ci 7738c2ecf20Sopenharmony_ci} /* fjn_interrupt */ 7748c2ecf20Sopenharmony_ci 7758c2ecf20Sopenharmony_ci/*====================================================================*/ 7768c2ecf20Sopenharmony_ci 7778c2ecf20Sopenharmony_cistatic void fjn_tx_timeout(struct net_device *dev, unsigned int txqueue) 7788c2ecf20Sopenharmony_ci{ 7798c2ecf20Sopenharmony_ci struct local_info *lp = netdev_priv(dev); 7808c2ecf20Sopenharmony_ci unsigned int ioaddr = dev->base_addr; 7818c2ecf20Sopenharmony_ci 7828c2ecf20Sopenharmony_ci netdev_notice(dev, "transmit timed out with status %04x, %s?\n", 7838c2ecf20Sopenharmony_ci htons(inw(ioaddr + TX_STATUS)), 7848c2ecf20Sopenharmony_ci inb(ioaddr + TX_STATUS) & F_TMT_RDY 7858c2ecf20Sopenharmony_ci ? "IRQ conflict" : "network cable problem"); 7868c2ecf20Sopenharmony_ci netdev_notice(dev, "timeout registers: %04x %04x %04x " 7878c2ecf20Sopenharmony_ci "%04x %04x %04x %04x %04x.\n", 7888c2ecf20Sopenharmony_ci htons(inw(ioaddr + 0)), htons(inw(ioaddr + 2)), 7898c2ecf20Sopenharmony_ci htons(inw(ioaddr + 4)), htons(inw(ioaddr + 6)), 7908c2ecf20Sopenharmony_ci htons(inw(ioaddr + 8)), htons(inw(ioaddr + 10)), 7918c2ecf20Sopenharmony_ci htons(inw(ioaddr + 12)), htons(inw(ioaddr + 14))); 7928c2ecf20Sopenharmony_ci dev->stats.tx_errors++; 7938c2ecf20Sopenharmony_ci /* ToDo: We should try to restart the adaptor... */ 7948c2ecf20Sopenharmony_ci local_irq_disable(); 7958c2ecf20Sopenharmony_ci fjn_reset(dev); 7968c2ecf20Sopenharmony_ci 7978c2ecf20Sopenharmony_ci lp->tx_started = 0; 7988c2ecf20Sopenharmony_ci lp->tx_queue = 0; 7998c2ecf20Sopenharmony_ci lp->tx_queue_len = 0; 8008c2ecf20Sopenharmony_ci lp->sent = 0; 8018c2ecf20Sopenharmony_ci lp->open_time = jiffies; 8028c2ecf20Sopenharmony_ci local_irq_enable(); 8038c2ecf20Sopenharmony_ci netif_wake_queue(dev); 8048c2ecf20Sopenharmony_ci} 8058c2ecf20Sopenharmony_ci 8068c2ecf20Sopenharmony_cistatic netdev_tx_t fjn_start_xmit(struct sk_buff *skb, 8078c2ecf20Sopenharmony_ci struct net_device *dev) 8088c2ecf20Sopenharmony_ci{ 8098c2ecf20Sopenharmony_ci struct local_info *lp = netdev_priv(dev); 8108c2ecf20Sopenharmony_ci unsigned int ioaddr = dev->base_addr; 8118c2ecf20Sopenharmony_ci short length = skb->len; 8128c2ecf20Sopenharmony_ci 8138c2ecf20Sopenharmony_ci if (length < ETH_ZLEN) 8148c2ecf20Sopenharmony_ci { 8158c2ecf20Sopenharmony_ci if (skb_padto(skb, ETH_ZLEN)) 8168c2ecf20Sopenharmony_ci return NETDEV_TX_OK; 8178c2ecf20Sopenharmony_ci length = ETH_ZLEN; 8188c2ecf20Sopenharmony_ci } 8198c2ecf20Sopenharmony_ci 8208c2ecf20Sopenharmony_ci netif_stop_queue(dev); 8218c2ecf20Sopenharmony_ci 8228c2ecf20Sopenharmony_ci { 8238c2ecf20Sopenharmony_ci unsigned char *buf = skb->data; 8248c2ecf20Sopenharmony_ci 8258c2ecf20Sopenharmony_ci if (length > ETH_FRAME_LEN) { 8268c2ecf20Sopenharmony_ci netdev_notice(dev, "Attempting to send a large packet (%d bytes)\n", 8278c2ecf20Sopenharmony_ci length); 8288c2ecf20Sopenharmony_ci return NETDEV_TX_BUSY; 8298c2ecf20Sopenharmony_ci } 8308c2ecf20Sopenharmony_ci 8318c2ecf20Sopenharmony_ci netdev_dbg(dev, "Transmitting a packet of length %lu\n", 8328c2ecf20Sopenharmony_ci (unsigned long)skb->len); 8338c2ecf20Sopenharmony_ci dev->stats.tx_bytes += skb->len; 8348c2ecf20Sopenharmony_ci 8358c2ecf20Sopenharmony_ci /* Disable both interrupts. */ 8368c2ecf20Sopenharmony_ci outw(0x0000, ioaddr + TX_INTR); 8378c2ecf20Sopenharmony_ci 8388c2ecf20Sopenharmony_ci /* wait for a while */ 8398c2ecf20Sopenharmony_ci udelay(1); 8408c2ecf20Sopenharmony_ci 8418c2ecf20Sopenharmony_ci outw(length, ioaddr + DATAPORT); 8428c2ecf20Sopenharmony_ci outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1); 8438c2ecf20Sopenharmony_ci 8448c2ecf20Sopenharmony_ci lp->tx_queue++; 8458c2ecf20Sopenharmony_ci lp->tx_queue_len += ((length+3) & ~1); 8468c2ecf20Sopenharmony_ci 8478c2ecf20Sopenharmony_ci if (lp->tx_started == 0) { 8488c2ecf20Sopenharmony_ci /* If the Tx is idle, always trigger a transmit. */ 8498c2ecf20Sopenharmony_ci outb(DO_TX | lp->tx_queue, ioaddr + TX_START); 8508c2ecf20Sopenharmony_ci lp->sent = lp->tx_queue ; 8518c2ecf20Sopenharmony_ci lp->tx_queue = 0; 8528c2ecf20Sopenharmony_ci lp->tx_queue_len = 0; 8538c2ecf20Sopenharmony_ci lp->tx_started = 1; 8548c2ecf20Sopenharmony_ci netif_start_queue(dev); 8558c2ecf20Sopenharmony_ci } else { 8568c2ecf20Sopenharmony_ci if( sram_config == 0 ) { 8578c2ecf20Sopenharmony_ci if (lp->tx_queue_len < (4096 - (ETH_FRAME_LEN +2)) ) 8588c2ecf20Sopenharmony_ci /* Yes, there is room for one more packet. */ 8598c2ecf20Sopenharmony_ci netif_start_queue(dev); 8608c2ecf20Sopenharmony_ci } else { 8618c2ecf20Sopenharmony_ci if (lp->tx_queue_len < (8192 - (ETH_FRAME_LEN +2)) && 8628c2ecf20Sopenharmony_ci lp->tx_queue < 127 ) 8638c2ecf20Sopenharmony_ci /* Yes, there is room for one more packet. */ 8648c2ecf20Sopenharmony_ci netif_start_queue(dev); 8658c2ecf20Sopenharmony_ci } 8668c2ecf20Sopenharmony_ci } 8678c2ecf20Sopenharmony_ci 8688c2ecf20Sopenharmony_ci /* Re-enable interrupts */ 8698c2ecf20Sopenharmony_ci outb(D_TX_INTR, ioaddr + TX_INTR); 8708c2ecf20Sopenharmony_ci outb(D_RX_INTR, ioaddr + RX_INTR); 8718c2ecf20Sopenharmony_ci } 8728c2ecf20Sopenharmony_ci dev_kfree_skb (skb); 8738c2ecf20Sopenharmony_ci 8748c2ecf20Sopenharmony_ci return NETDEV_TX_OK; 8758c2ecf20Sopenharmony_ci} /* fjn_start_xmit */ 8768c2ecf20Sopenharmony_ci 8778c2ecf20Sopenharmony_ci/*====================================================================*/ 8788c2ecf20Sopenharmony_ci 8798c2ecf20Sopenharmony_cistatic void fjn_reset(struct net_device *dev) 8808c2ecf20Sopenharmony_ci{ 8818c2ecf20Sopenharmony_ci struct local_info *lp = netdev_priv(dev); 8828c2ecf20Sopenharmony_ci unsigned int ioaddr = dev->base_addr; 8838c2ecf20Sopenharmony_ci int i; 8848c2ecf20Sopenharmony_ci 8858c2ecf20Sopenharmony_ci netdev_dbg(dev, "fjn_reset() called\n"); 8868c2ecf20Sopenharmony_ci 8878c2ecf20Sopenharmony_ci /* Reset controller */ 8888c2ecf20Sopenharmony_ci if( sram_config == 0 ) 8898c2ecf20Sopenharmony_ci outb(CONFIG0_RST, ioaddr + CONFIG_0); 8908c2ecf20Sopenharmony_ci else 8918c2ecf20Sopenharmony_ci outb(CONFIG0_RST_1, ioaddr + CONFIG_0); 8928c2ecf20Sopenharmony_ci 8938c2ecf20Sopenharmony_ci /* Power On chip and select bank 0 */ 8948c2ecf20Sopenharmony_ci if (lp->cardtype == MBH10302) 8958c2ecf20Sopenharmony_ci outb(BANK_0, ioaddr + CONFIG_1); 8968c2ecf20Sopenharmony_ci else 8978c2ecf20Sopenharmony_ci outb(BANK_0U, ioaddr + CONFIG_1); 8988c2ecf20Sopenharmony_ci 8998c2ecf20Sopenharmony_ci /* Set Tx modes */ 9008c2ecf20Sopenharmony_ci outb(D_TX_MODE, ioaddr + TX_MODE); 9018c2ecf20Sopenharmony_ci /* set Rx modes */ 9028c2ecf20Sopenharmony_ci outb(ID_MATCHED, ioaddr + RX_MODE); 9038c2ecf20Sopenharmony_ci 9048c2ecf20Sopenharmony_ci /* Set hardware address */ 9058c2ecf20Sopenharmony_ci for (i = 0; i < 6; i++) 9068c2ecf20Sopenharmony_ci outb(dev->dev_addr[i], ioaddr + NODE_ID + i); 9078c2ecf20Sopenharmony_ci 9088c2ecf20Sopenharmony_ci /* (re)initialize the multicast table */ 9098c2ecf20Sopenharmony_ci set_rx_mode(dev); 9108c2ecf20Sopenharmony_ci 9118c2ecf20Sopenharmony_ci /* Switch to bank 2 (runtime mode) */ 9128c2ecf20Sopenharmony_ci if (lp->cardtype == MBH10302) 9138c2ecf20Sopenharmony_ci outb(BANK_2, ioaddr + CONFIG_1); 9148c2ecf20Sopenharmony_ci else 9158c2ecf20Sopenharmony_ci outb(BANK_2U, ioaddr + CONFIG_1); 9168c2ecf20Sopenharmony_ci 9178c2ecf20Sopenharmony_ci /* set 16col ctrl bits */ 9188c2ecf20Sopenharmony_ci if( lp->cardtype == TDK || lp->cardtype == CONTEC) 9198c2ecf20Sopenharmony_ci outb(TDK_AUTO_MODE, ioaddr + COL_CTRL); 9208c2ecf20Sopenharmony_ci else 9218c2ecf20Sopenharmony_ci outb(AUTO_MODE, ioaddr + COL_CTRL); 9228c2ecf20Sopenharmony_ci 9238c2ecf20Sopenharmony_ci /* clear Reserved Regs */ 9248c2ecf20Sopenharmony_ci outb(0x00, ioaddr + BMPR12); 9258c2ecf20Sopenharmony_ci outb(0x00, ioaddr + BMPR13); 9268c2ecf20Sopenharmony_ci 9278c2ecf20Sopenharmony_ci /* reset Skip packet reg. */ 9288c2ecf20Sopenharmony_ci outb(0x01, ioaddr + RX_SKIP); 9298c2ecf20Sopenharmony_ci 9308c2ecf20Sopenharmony_ci /* Enable Tx and Rx */ 9318c2ecf20Sopenharmony_ci if( sram_config == 0 ) 9328c2ecf20Sopenharmony_ci outb(CONFIG0_DFL, ioaddr + CONFIG_0); 9338c2ecf20Sopenharmony_ci else 9348c2ecf20Sopenharmony_ci outb(CONFIG0_DFL_1, ioaddr + CONFIG_0); 9358c2ecf20Sopenharmony_ci 9368c2ecf20Sopenharmony_ci /* Init receive pointer ? */ 9378c2ecf20Sopenharmony_ci inw(ioaddr + DATAPORT); 9388c2ecf20Sopenharmony_ci inw(ioaddr + DATAPORT); 9398c2ecf20Sopenharmony_ci 9408c2ecf20Sopenharmony_ci /* Clear all status */ 9418c2ecf20Sopenharmony_ci outb(0xff, ioaddr + TX_STATUS); 9428c2ecf20Sopenharmony_ci outb(0xff, ioaddr + RX_STATUS); 9438c2ecf20Sopenharmony_ci 9448c2ecf20Sopenharmony_ci if (lp->cardtype == MBH10302) 9458c2ecf20Sopenharmony_ci outb(INTR_OFF, ioaddr + LAN_CTRL); 9468c2ecf20Sopenharmony_ci 9478c2ecf20Sopenharmony_ci /* Turn on Rx interrupts */ 9488c2ecf20Sopenharmony_ci outb(D_TX_INTR, ioaddr + TX_INTR); 9498c2ecf20Sopenharmony_ci outb(D_RX_INTR, ioaddr + RX_INTR); 9508c2ecf20Sopenharmony_ci 9518c2ecf20Sopenharmony_ci /* Turn on interrupts from LAN card controller */ 9528c2ecf20Sopenharmony_ci if (lp->cardtype == MBH10302) 9538c2ecf20Sopenharmony_ci outb(INTR_ON, ioaddr + LAN_CTRL); 9548c2ecf20Sopenharmony_ci} /* fjn_reset */ 9558c2ecf20Sopenharmony_ci 9568c2ecf20Sopenharmony_ci/*====================================================================*/ 9578c2ecf20Sopenharmony_ci 9588c2ecf20Sopenharmony_cistatic void fjn_rx(struct net_device *dev) 9598c2ecf20Sopenharmony_ci{ 9608c2ecf20Sopenharmony_ci unsigned int ioaddr = dev->base_addr; 9618c2ecf20Sopenharmony_ci int boguscount = 10; /* 5 -> 10: by agy 19940922 */ 9628c2ecf20Sopenharmony_ci 9638c2ecf20Sopenharmony_ci pr_debug("%s: in rx_packet(), rx_status %02x.\n", 9648c2ecf20Sopenharmony_ci dev->name, inb(ioaddr + RX_STATUS)); 9658c2ecf20Sopenharmony_ci 9668c2ecf20Sopenharmony_ci while ((inb(ioaddr + RX_MODE) & F_BUF_EMP) == 0) { 9678c2ecf20Sopenharmony_ci u_short status = inw(ioaddr + DATAPORT); 9688c2ecf20Sopenharmony_ci 9698c2ecf20Sopenharmony_ci netdev_dbg(dev, "Rxing packet mode %02x status %04x.\n", 9708c2ecf20Sopenharmony_ci inb(ioaddr + RX_MODE), status); 9718c2ecf20Sopenharmony_ci#ifndef final_version 9728c2ecf20Sopenharmony_ci if (status == 0) { 9738c2ecf20Sopenharmony_ci outb(F_SKP_PKT, ioaddr + RX_SKIP); 9748c2ecf20Sopenharmony_ci break; 9758c2ecf20Sopenharmony_ci } 9768c2ecf20Sopenharmony_ci#endif 9778c2ecf20Sopenharmony_ci if ((status & 0xF0) != 0x20) { /* There was an error. */ 9788c2ecf20Sopenharmony_ci dev->stats.rx_errors++; 9798c2ecf20Sopenharmony_ci if (status & F_LEN_ERR) dev->stats.rx_length_errors++; 9808c2ecf20Sopenharmony_ci if (status & F_ALG_ERR) dev->stats.rx_frame_errors++; 9818c2ecf20Sopenharmony_ci if (status & F_CRC_ERR) dev->stats.rx_crc_errors++; 9828c2ecf20Sopenharmony_ci if (status & F_OVR_FLO) dev->stats.rx_over_errors++; 9838c2ecf20Sopenharmony_ci } else { 9848c2ecf20Sopenharmony_ci u_short pkt_len = inw(ioaddr + DATAPORT); 9858c2ecf20Sopenharmony_ci /* Malloc up new buffer. */ 9868c2ecf20Sopenharmony_ci struct sk_buff *skb; 9878c2ecf20Sopenharmony_ci 9888c2ecf20Sopenharmony_ci if (pkt_len > 1550) { 9898c2ecf20Sopenharmony_ci netdev_notice(dev, "The FMV-18x claimed a very large packet, size %d\n", 9908c2ecf20Sopenharmony_ci pkt_len); 9918c2ecf20Sopenharmony_ci outb(F_SKP_PKT, ioaddr + RX_SKIP); 9928c2ecf20Sopenharmony_ci dev->stats.rx_errors++; 9938c2ecf20Sopenharmony_ci break; 9948c2ecf20Sopenharmony_ci } 9958c2ecf20Sopenharmony_ci skb = netdev_alloc_skb(dev, pkt_len + 2); 9968c2ecf20Sopenharmony_ci if (skb == NULL) { 9978c2ecf20Sopenharmony_ci outb(F_SKP_PKT, ioaddr + RX_SKIP); 9988c2ecf20Sopenharmony_ci dev->stats.rx_dropped++; 9998c2ecf20Sopenharmony_ci break; 10008c2ecf20Sopenharmony_ci } 10018c2ecf20Sopenharmony_ci 10028c2ecf20Sopenharmony_ci skb_reserve(skb, 2); 10038c2ecf20Sopenharmony_ci insw(ioaddr + DATAPORT, skb_put(skb, pkt_len), 10048c2ecf20Sopenharmony_ci (pkt_len + 1) >> 1); 10058c2ecf20Sopenharmony_ci skb->protocol = eth_type_trans(skb, dev); 10068c2ecf20Sopenharmony_ci 10078c2ecf20Sopenharmony_ci { 10088c2ecf20Sopenharmony_ci int i; 10098c2ecf20Sopenharmony_ci pr_debug("%s: Rxed packet of length %d: ", 10108c2ecf20Sopenharmony_ci dev->name, pkt_len); 10118c2ecf20Sopenharmony_ci for (i = 0; i < 14; i++) 10128c2ecf20Sopenharmony_ci pr_debug(" %02x", skb->data[i]); 10138c2ecf20Sopenharmony_ci pr_debug(".\n"); 10148c2ecf20Sopenharmony_ci } 10158c2ecf20Sopenharmony_ci 10168c2ecf20Sopenharmony_ci netif_rx(skb); 10178c2ecf20Sopenharmony_ci dev->stats.rx_packets++; 10188c2ecf20Sopenharmony_ci dev->stats.rx_bytes += pkt_len; 10198c2ecf20Sopenharmony_ci } 10208c2ecf20Sopenharmony_ci if (--boguscount <= 0) 10218c2ecf20Sopenharmony_ci break; 10228c2ecf20Sopenharmony_ci } 10238c2ecf20Sopenharmony_ci 10248c2ecf20Sopenharmony_ci /* If any worth-while packets have been received, dev_rint() 10258c2ecf20Sopenharmony_ci has done a netif_wake_queue() for us and will work on them 10268c2ecf20Sopenharmony_ci when we get to the bottom-half routine. */ 10278c2ecf20Sopenharmony_ci/* 10288c2ecf20Sopenharmony_ci if (lp->cardtype != TDK) { 10298c2ecf20Sopenharmony_ci int i; 10308c2ecf20Sopenharmony_ci for (i = 0; i < 20; i++) { 10318c2ecf20Sopenharmony_ci if ((inb(ioaddr + RX_MODE) & F_BUF_EMP) == F_BUF_EMP) 10328c2ecf20Sopenharmony_ci break; 10338c2ecf20Sopenharmony_ci (void)inw(ioaddr + DATAPORT); /+ dummy status read +/ 10348c2ecf20Sopenharmony_ci outb(F_SKP_PKT, ioaddr + RX_SKIP); 10358c2ecf20Sopenharmony_ci } 10368c2ecf20Sopenharmony_ci 10378c2ecf20Sopenharmony_ci if (i > 0) 10388c2ecf20Sopenharmony_ci pr_debug("%s: Exint Rx packet with mode %02x after " 10398c2ecf20Sopenharmony_ci "%d ticks.\n", dev->name, inb(ioaddr + RX_MODE), i); 10408c2ecf20Sopenharmony_ci } 10418c2ecf20Sopenharmony_ci*/ 10428c2ecf20Sopenharmony_ci} /* fjn_rx */ 10438c2ecf20Sopenharmony_ci 10448c2ecf20Sopenharmony_ci/*====================================================================*/ 10458c2ecf20Sopenharmony_ci 10468c2ecf20Sopenharmony_cistatic void netdev_get_drvinfo(struct net_device *dev, 10478c2ecf20Sopenharmony_ci struct ethtool_drvinfo *info) 10488c2ecf20Sopenharmony_ci{ 10498c2ecf20Sopenharmony_ci strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); 10508c2ecf20Sopenharmony_ci strlcpy(info->version, DRV_VERSION, sizeof(info->version)); 10518c2ecf20Sopenharmony_ci snprintf(info->bus_info, sizeof(info->bus_info), 10528c2ecf20Sopenharmony_ci "PCMCIA 0x%lx", dev->base_addr); 10538c2ecf20Sopenharmony_ci} 10548c2ecf20Sopenharmony_ci 10558c2ecf20Sopenharmony_cistatic const struct ethtool_ops netdev_ethtool_ops = { 10568c2ecf20Sopenharmony_ci .get_drvinfo = netdev_get_drvinfo, 10578c2ecf20Sopenharmony_ci}; 10588c2ecf20Sopenharmony_ci 10598c2ecf20Sopenharmony_cistatic int fjn_config(struct net_device *dev, struct ifmap *map){ 10608c2ecf20Sopenharmony_ci return 0; 10618c2ecf20Sopenharmony_ci} 10628c2ecf20Sopenharmony_ci 10638c2ecf20Sopenharmony_cistatic int fjn_open(struct net_device *dev) 10648c2ecf20Sopenharmony_ci{ 10658c2ecf20Sopenharmony_ci struct local_info *lp = netdev_priv(dev); 10668c2ecf20Sopenharmony_ci struct pcmcia_device *link = lp->p_dev; 10678c2ecf20Sopenharmony_ci 10688c2ecf20Sopenharmony_ci pr_debug("fjn_open('%s').\n", dev->name); 10698c2ecf20Sopenharmony_ci 10708c2ecf20Sopenharmony_ci if (!pcmcia_dev_present(link)) 10718c2ecf20Sopenharmony_ci return -ENODEV; 10728c2ecf20Sopenharmony_ci 10738c2ecf20Sopenharmony_ci link->open++; 10748c2ecf20Sopenharmony_ci 10758c2ecf20Sopenharmony_ci fjn_reset(dev); 10768c2ecf20Sopenharmony_ci 10778c2ecf20Sopenharmony_ci lp->tx_started = 0; 10788c2ecf20Sopenharmony_ci lp->tx_queue = 0; 10798c2ecf20Sopenharmony_ci lp->tx_queue_len = 0; 10808c2ecf20Sopenharmony_ci lp->open_time = jiffies; 10818c2ecf20Sopenharmony_ci netif_start_queue(dev); 10828c2ecf20Sopenharmony_ci 10838c2ecf20Sopenharmony_ci return 0; 10848c2ecf20Sopenharmony_ci} /* fjn_open */ 10858c2ecf20Sopenharmony_ci 10868c2ecf20Sopenharmony_ci/*====================================================================*/ 10878c2ecf20Sopenharmony_ci 10888c2ecf20Sopenharmony_cistatic int fjn_close(struct net_device *dev) 10898c2ecf20Sopenharmony_ci{ 10908c2ecf20Sopenharmony_ci struct local_info *lp = netdev_priv(dev); 10918c2ecf20Sopenharmony_ci struct pcmcia_device *link = lp->p_dev; 10928c2ecf20Sopenharmony_ci unsigned int ioaddr = dev->base_addr; 10938c2ecf20Sopenharmony_ci 10948c2ecf20Sopenharmony_ci pr_debug("fjn_close('%s').\n", dev->name); 10958c2ecf20Sopenharmony_ci 10968c2ecf20Sopenharmony_ci lp->open_time = 0; 10978c2ecf20Sopenharmony_ci netif_stop_queue(dev); 10988c2ecf20Sopenharmony_ci 10998c2ecf20Sopenharmony_ci /* Set configuration register 0 to disable Tx and Rx. */ 11008c2ecf20Sopenharmony_ci if( sram_config == 0 ) 11018c2ecf20Sopenharmony_ci outb(CONFIG0_RST ,ioaddr + CONFIG_0); 11028c2ecf20Sopenharmony_ci else 11038c2ecf20Sopenharmony_ci outb(CONFIG0_RST_1 ,ioaddr + CONFIG_0); 11048c2ecf20Sopenharmony_ci 11058c2ecf20Sopenharmony_ci /* Update the statistics -- ToDo. */ 11068c2ecf20Sopenharmony_ci 11078c2ecf20Sopenharmony_ci /* Power-down the chip. Green, green, green! */ 11088c2ecf20Sopenharmony_ci outb(CHIP_OFF ,ioaddr + CONFIG_1); 11098c2ecf20Sopenharmony_ci 11108c2ecf20Sopenharmony_ci /* Set the ethernet adaptor disable IRQ */ 11118c2ecf20Sopenharmony_ci if (lp->cardtype == MBH10302) 11128c2ecf20Sopenharmony_ci outb(INTR_OFF, ioaddr + LAN_CTRL); 11138c2ecf20Sopenharmony_ci 11148c2ecf20Sopenharmony_ci link->open--; 11158c2ecf20Sopenharmony_ci 11168c2ecf20Sopenharmony_ci return 0; 11178c2ecf20Sopenharmony_ci} /* fjn_close */ 11188c2ecf20Sopenharmony_ci 11198c2ecf20Sopenharmony_ci/*====================================================================*/ 11208c2ecf20Sopenharmony_ci 11218c2ecf20Sopenharmony_ci/* 11228c2ecf20Sopenharmony_ci Set the multicast/promiscuous mode for this adaptor. 11238c2ecf20Sopenharmony_ci*/ 11248c2ecf20Sopenharmony_ci 11258c2ecf20Sopenharmony_cistatic void set_rx_mode(struct net_device *dev) 11268c2ecf20Sopenharmony_ci{ 11278c2ecf20Sopenharmony_ci unsigned int ioaddr = dev->base_addr; 11288c2ecf20Sopenharmony_ci u_char mc_filter[8]; /* Multicast hash filter */ 11298c2ecf20Sopenharmony_ci u_long flags; 11308c2ecf20Sopenharmony_ci int i; 11318c2ecf20Sopenharmony_ci 11328c2ecf20Sopenharmony_ci int saved_bank; 11338c2ecf20Sopenharmony_ci int saved_config_0 = inb(ioaddr + CONFIG_0); 11348c2ecf20Sopenharmony_ci 11358c2ecf20Sopenharmony_ci local_irq_save(flags); 11368c2ecf20Sopenharmony_ci 11378c2ecf20Sopenharmony_ci /* Disable Tx and Rx */ 11388c2ecf20Sopenharmony_ci if (sram_config == 0) 11398c2ecf20Sopenharmony_ci outb(CONFIG0_RST, ioaddr + CONFIG_0); 11408c2ecf20Sopenharmony_ci else 11418c2ecf20Sopenharmony_ci outb(CONFIG0_RST_1, ioaddr + CONFIG_0); 11428c2ecf20Sopenharmony_ci 11438c2ecf20Sopenharmony_ci if (dev->flags & IFF_PROMISC) { 11448c2ecf20Sopenharmony_ci memset(mc_filter, 0xff, sizeof(mc_filter)); 11458c2ecf20Sopenharmony_ci outb(3, ioaddr + RX_MODE); /* Enable promiscuous mode */ 11468c2ecf20Sopenharmony_ci } else if (netdev_mc_count(dev) > MC_FILTERBREAK || 11478c2ecf20Sopenharmony_ci (dev->flags & IFF_ALLMULTI)) { 11488c2ecf20Sopenharmony_ci /* Too many to filter perfectly -- accept all multicasts. */ 11498c2ecf20Sopenharmony_ci memset(mc_filter, 0xff, sizeof(mc_filter)); 11508c2ecf20Sopenharmony_ci outb(2, ioaddr + RX_MODE); /* Use normal mode. */ 11518c2ecf20Sopenharmony_ci } else if (netdev_mc_empty(dev)) { 11528c2ecf20Sopenharmony_ci memset(mc_filter, 0x00, sizeof(mc_filter)); 11538c2ecf20Sopenharmony_ci outb(1, ioaddr + RX_MODE); /* Ignore almost all multicasts. */ 11548c2ecf20Sopenharmony_ci } else { 11558c2ecf20Sopenharmony_ci struct netdev_hw_addr *ha; 11568c2ecf20Sopenharmony_ci 11578c2ecf20Sopenharmony_ci memset(mc_filter, 0, sizeof(mc_filter)); 11588c2ecf20Sopenharmony_ci netdev_for_each_mc_addr(ha, dev) { 11598c2ecf20Sopenharmony_ci unsigned int bit = ether_crc_le(ETH_ALEN, ha->addr) >> 26; 11608c2ecf20Sopenharmony_ci mc_filter[bit >> 3] |= (1 << (bit & 7)); 11618c2ecf20Sopenharmony_ci } 11628c2ecf20Sopenharmony_ci outb(2, ioaddr + RX_MODE); /* Use normal mode. */ 11638c2ecf20Sopenharmony_ci } 11648c2ecf20Sopenharmony_ci 11658c2ecf20Sopenharmony_ci /* Switch to bank 1 and set the multicast table. */ 11668c2ecf20Sopenharmony_ci saved_bank = inb(ioaddr + CONFIG_1); 11678c2ecf20Sopenharmony_ci outb(0xe4, ioaddr + CONFIG_1); 11688c2ecf20Sopenharmony_ci 11698c2ecf20Sopenharmony_ci for (i = 0; i < 8; i++) 11708c2ecf20Sopenharmony_ci outb(mc_filter[i], ioaddr + MAR_ADR + i); 11718c2ecf20Sopenharmony_ci outb(saved_bank, ioaddr + CONFIG_1); 11728c2ecf20Sopenharmony_ci 11738c2ecf20Sopenharmony_ci outb(saved_config_0, ioaddr + CONFIG_0); 11748c2ecf20Sopenharmony_ci 11758c2ecf20Sopenharmony_ci local_irq_restore(flags); 11768c2ecf20Sopenharmony_ci} 1177