159ffb30fSJeff Kirsher /* [xirc2ps_cs.c wk 03.11.99] (1.40 1999/11/18 00:06:03) 259ffb30fSJeff Kirsher * Xircom CreditCard Ethernet Adapter IIps driver 359ffb30fSJeff Kirsher * Xircom Realport 10/100 (RE-100) driver 459ffb30fSJeff Kirsher * 559ffb30fSJeff Kirsher * This driver supports various Xircom CreditCard Ethernet adapters 659ffb30fSJeff Kirsher * including the CE2, CE IIps, RE-10, CEM28, CEM33, CE33, CEM56, 759ffb30fSJeff Kirsher * CE3-100, CE3B, RE-100, REM10BT, and REM56G-100. 859ffb30fSJeff Kirsher * 959ffb30fSJeff Kirsher * 2000-09-24 <psheer@icon.co.za> The Xircom CE3B-100 may not 1059ffb30fSJeff Kirsher * autodetect the media properly. In this case use the 1159ffb30fSJeff Kirsher * if_port=1 (for 10BaseT) or if_port=4 (for 100BaseT) options 1259ffb30fSJeff Kirsher * to force the media type. 1359ffb30fSJeff Kirsher * 1459ffb30fSJeff Kirsher * Written originally by Werner Koch based on David Hinds' skeleton of the 1559ffb30fSJeff Kirsher * PCMCIA driver. 1659ffb30fSJeff Kirsher * 1759ffb30fSJeff Kirsher * Copyright (c) 1997,1998 Werner Koch (dd9jn) 1859ffb30fSJeff Kirsher * 1959ffb30fSJeff Kirsher * This driver is free software; you can redistribute it and/or modify 2059ffb30fSJeff Kirsher * it under the terms of the GNU General Public License as published by 2159ffb30fSJeff Kirsher * the Free Software Foundation; either version 2 of the License, or 2259ffb30fSJeff Kirsher * (at your option) any later version. 2359ffb30fSJeff Kirsher * 2459ffb30fSJeff Kirsher * It is distributed in the hope that it will be useful, 2559ffb30fSJeff Kirsher * but WITHOUT ANY WARRANTY; without even the implied warranty of 2659ffb30fSJeff Kirsher * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2759ffb30fSJeff Kirsher * GNU General Public License for more details. 2859ffb30fSJeff Kirsher * 2959ffb30fSJeff Kirsher * You should have received a copy of the GNU General Public License 300ab75ae8SJeff Kirsher * along with this program; if not, see <http://www.gnu.org/licenses/>. 3159ffb30fSJeff Kirsher * 3259ffb30fSJeff Kirsher * 3359ffb30fSJeff Kirsher * ALTERNATIVELY, this driver may be distributed under the terms of 3459ffb30fSJeff Kirsher * the following license, in which case the provisions of this license 3559ffb30fSJeff Kirsher * are required INSTEAD OF the GNU General Public License. (This clause 3659ffb30fSJeff Kirsher * is necessary due to a potential bad interaction between the GPL and 3759ffb30fSJeff Kirsher * the restrictions contained in a BSD-style copyright.) 3859ffb30fSJeff Kirsher * 3959ffb30fSJeff Kirsher * Redistribution and use in source and binary forms, with or without 4059ffb30fSJeff Kirsher * modification, are permitted provided that the following conditions 4159ffb30fSJeff Kirsher * are met: 4259ffb30fSJeff Kirsher * 1. Redistributions of source code must retain the above copyright 4359ffb30fSJeff Kirsher * notice, and the entire permission notice in its entirety, 4459ffb30fSJeff Kirsher * including the disclaimer of warranties. 4559ffb30fSJeff Kirsher * 2. Redistributions in binary form must reproduce the above copyright 4659ffb30fSJeff Kirsher * notice, this list of conditions and the following disclaimer in the 4759ffb30fSJeff Kirsher * documentation and/or other materials provided with the distribution. 4859ffb30fSJeff Kirsher * 3. The name of the author may not be used to endorse or promote 4959ffb30fSJeff Kirsher * products derived from this software without specific prior 5059ffb30fSJeff Kirsher * written permission. 5159ffb30fSJeff Kirsher * 5259ffb30fSJeff Kirsher * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 5359ffb30fSJeff Kirsher * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 5459ffb30fSJeff Kirsher * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 5559ffb30fSJeff Kirsher * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 5659ffb30fSJeff Kirsher * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 5759ffb30fSJeff Kirsher * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 5859ffb30fSJeff Kirsher * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 5959ffb30fSJeff Kirsher * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 6059ffb30fSJeff Kirsher * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 6159ffb30fSJeff Kirsher * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 6259ffb30fSJeff Kirsher * OF THE POSSIBILITY OF SUCH DAMAGE. 6359ffb30fSJeff Kirsher */ 6459ffb30fSJeff Kirsher 6559ffb30fSJeff Kirsher #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 6659ffb30fSJeff Kirsher 6759ffb30fSJeff Kirsher #include <linux/module.h> 6859ffb30fSJeff Kirsher #include <linux/kernel.h> 6959ffb30fSJeff Kirsher #include <linux/init.h> 7059ffb30fSJeff Kirsher #include <linux/ptrace.h> 7159ffb30fSJeff Kirsher #include <linux/slab.h> 7259ffb30fSJeff Kirsher #include <linux/string.h> 7359ffb30fSJeff Kirsher #include <linux/timer.h> 7459ffb30fSJeff Kirsher #include <linux/interrupt.h> 7559ffb30fSJeff Kirsher #include <linux/in.h> 7659ffb30fSJeff Kirsher #include <linux/delay.h> 7759ffb30fSJeff Kirsher #include <linux/ethtool.h> 7859ffb30fSJeff Kirsher #include <linux/netdevice.h> 7959ffb30fSJeff Kirsher #include <linux/etherdevice.h> 8059ffb30fSJeff Kirsher #include <linux/skbuff.h> 8159ffb30fSJeff Kirsher #include <linux/if_arp.h> 8259ffb30fSJeff Kirsher #include <linux/ioport.h> 8359ffb30fSJeff Kirsher #include <linux/bitops.h> 8459ffb30fSJeff Kirsher #include <linux/mii.h> 8559ffb30fSJeff Kirsher 8659ffb30fSJeff Kirsher #include <pcmcia/cistpl.h> 8759ffb30fSJeff Kirsher #include <pcmcia/cisreg.h> 8859ffb30fSJeff Kirsher #include <pcmcia/ciscode.h> 8959ffb30fSJeff Kirsher 9059ffb30fSJeff Kirsher #include <asm/io.h> 917c0f6ba6SLinus Torvalds #include <linux/uaccess.h> 9259ffb30fSJeff Kirsher 9359ffb30fSJeff Kirsher #ifndef MANFID_COMPAQ 9459ffb30fSJeff Kirsher #define MANFID_COMPAQ 0x0138 9559ffb30fSJeff Kirsher #define MANFID_COMPAQ2 0x0183 /* is this correct? */ 9659ffb30fSJeff Kirsher #endif 9759ffb30fSJeff Kirsher 9859ffb30fSJeff Kirsher #include <pcmcia/ds.h> 9959ffb30fSJeff Kirsher 10059ffb30fSJeff Kirsher /* Time in jiffies before concluding Tx hung */ 10159ffb30fSJeff Kirsher #define TX_TIMEOUT ((400*HZ)/1000) 10259ffb30fSJeff Kirsher 10359ffb30fSJeff Kirsher /**************** 10459ffb30fSJeff Kirsher * Some constants used to access the hardware 10559ffb30fSJeff Kirsher */ 10659ffb30fSJeff Kirsher 10759ffb30fSJeff Kirsher /* Register offsets and value constans */ 10859ffb30fSJeff Kirsher #define XIRCREG_CR 0 /* Command register (wr) */ 10959ffb30fSJeff Kirsher enum xirc_cr { 11059ffb30fSJeff Kirsher TransmitPacket = 0x01, 11159ffb30fSJeff Kirsher SoftReset = 0x02, 11259ffb30fSJeff Kirsher EnableIntr = 0x04, 11359ffb30fSJeff Kirsher ForceIntr = 0x08, 11459ffb30fSJeff Kirsher ClearTxFIFO = 0x10, 11559ffb30fSJeff Kirsher ClearRxOvrun = 0x20, 11659ffb30fSJeff Kirsher RestartTx = 0x40 11759ffb30fSJeff Kirsher }; 11859ffb30fSJeff Kirsher #define XIRCREG_ESR 0 /* Ethernet status register (rd) */ 11959ffb30fSJeff Kirsher enum xirc_esr { 12059ffb30fSJeff Kirsher FullPktRcvd = 0x01, /* full packet in receive buffer */ 12159ffb30fSJeff Kirsher PktRejected = 0x04, /* a packet has been rejected */ 12259ffb30fSJeff Kirsher TxPktPend = 0x08, /* TX Packet Pending */ 12359ffb30fSJeff Kirsher IncorPolarity = 0x10, 12459ffb30fSJeff Kirsher MediaSelect = 0x20 /* set if TP, clear if AUI */ 12559ffb30fSJeff Kirsher }; 12659ffb30fSJeff Kirsher #define XIRCREG_PR 1 /* Page Register select */ 12759ffb30fSJeff Kirsher #define XIRCREG_EDP 4 /* Ethernet Data Port Register */ 12859ffb30fSJeff Kirsher #define XIRCREG_ISR 6 /* Ethernet Interrupt Status Register */ 12959ffb30fSJeff Kirsher enum xirc_isr { 13059ffb30fSJeff Kirsher TxBufOvr = 0x01, /* TX Buffer Overflow */ 13159ffb30fSJeff Kirsher PktTxed = 0x02, /* Packet Transmitted */ 13259ffb30fSJeff Kirsher MACIntr = 0x04, /* MAC Interrupt occurred */ 13359ffb30fSJeff Kirsher TxResGrant = 0x08, /* Tx Reservation Granted */ 13459ffb30fSJeff Kirsher RxFullPkt = 0x20, /* Rx Full Packet */ 13559ffb30fSJeff Kirsher RxPktRej = 0x40, /* Rx Packet Rejected */ 13659ffb30fSJeff Kirsher ForcedIntr= 0x80 /* Forced Interrupt */ 13759ffb30fSJeff Kirsher }; 13859ffb30fSJeff Kirsher #define XIRCREG1_IMR0 12 /* Ethernet Interrupt Mask Register (on page 1)*/ 13959ffb30fSJeff Kirsher #define XIRCREG1_IMR1 13 14059ffb30fSJeff Kirsher #define XIRCREG0_TSO 8 /* Transmit Space Open Register (on page 0)*/ 14159ffb30fSJeff Kirsher #define XIRCREG0_TRS 10 /* Transmit reservation Size Register (page 0)*/ 14259ffb30fSJeff Kirsher #define XIRCREG0_DO 12 /* Data Offset Register (page 0) (wr) */ 14359ffb30fSJeff Kirsher #define XIRCREG0_RSR 12 /* Receive Status Register (page 0) (rd) */ 14459ffb30fSJeff Kirsher enum xirc_rsr { 14559ffb30fSJeff Kirsher PhyPkt = 0x01, /* set:physical packet, clear: multicast packet */ 14659ffb30fSJeff Kirsher BrdcstPkt = 0x02, /* set if it is a broadcast packet */ 14759ffb30fSJeff Kirsher PktTooLong = 0x04, /* set if packet length > 1518 */ 14859ffb30fSJeff Kirsher AlignErr = 0x10, /* incorrect CRC and last octet not complete */ 14959ffb30fSJeff Kirsher CRCErr = 0x20, /* incorrect CRC and last octet is complete */ 15059ffb30fSJeff Kirsher PktRxOk = 0x80 /* received ok */ 15159ffb30fSJeff Kirsher }; 15259ffb30fSJeff Kirsher #define XIRCREG0_PTR 13 /* packets transmitted register (rd) */ 15359ffb30fSJeff Kirsher #define XIRCREG0_RBC 14 /* receive byte count regsister (rd) */ 15459ffb30fSJeff Kirsher #define XIRCREG1_ECR 14 /* ethernet configurationn register */ 15559ffb30fSJeff Kirsher enum xirc_ecr { 15659ffb30fSJeff Kirsher FullDuplex = 0x04, /* enable full duplex mode */ 15759ffb30fSJeff Kirsher LongTPMode = 0x08, /* adjust for longer lengths of TP cable */ 15859ffb30fSJeff Kirsher DisablePolCor = 0x10,/* disable auto polarity correction */ 15959ffb30fSJeff Kirsher DisableLinkPulse = 0x20, /* disable link pulse generation */ 16059ffb30fSJeff Kirsher DisableAutoTx = 0x40, /* disable auto-transmit */ 16159ffb30fSJeff Kirsher }; 16259ffb30fSJeff Kirsher #define XIRCREG2_RBS 8 /* receive buffer start register */ 16359ffb30fSJeff Kirsher #define XIRCREG2_LED 10 /* LED Configuration register */ 16459ffb30fSJeff Kirsher /* values for the leds: Bits 2-0 for led 1 16559ffb30fSJeff Kirsher * 0 disabled Bits 5-3 for led 2 16659ffb30fSJeff Kirsher * 1 collision 16759ffb30fSJeff Kirsher * 2 noncollision 16859ffb30fSJeff Kirsher * 3 link_detected 16959ffb30fSJeff Kirsher * 4 incor_polarity 17059ffb30fSJeff Kirsher * 5 jabber 17159ffb30fSJeff Kirsher * 6 auto_assertion 17259ffb30fSJeff Kirsher * 7 rx_tx_activity 17359ffb30fSJeff Kirsher */ 17459ffb30fSJeff Kirsher #define XIRCREG2_MSR 12 /* Mohawk specific register */ 17559ffb30fSJeff Kirsher 17659ffb30fSJeff Kirsher #define XIRCREG4_GPR0 8 /* General Purpose Register 0 */ 17759ffb30fSJeff Kirsher #define XIRCREG4_GPR1 9 /* General Purpose Register 1 */ 17859ffb30fSJeff Kirsher #define XIRCREG2_GPR2 13 /* General Purpose Register 2 (page2!)*/ 17959ffb30fSJeff Kirsher #define XIRCREG4_BOV 10 /* Bonding Version Register */ 18059ffb30fSJeff Kirsher #define XIRCREG4_LMA 12 /* Local Memory Address Register */ 18159ffb30fSJeff Kirsher #define XIRCREG4_LMD 14 /* Local Memory Data Port */ 18259ffb30fSJeff Kirsher /* MAC register can only by accessed with 8 bit operations */ 18359ffb30fSJeff Kirsher #define XIRCREG40_CMD0 8 /* Command Register (wr) */ 18459ffb30fSJeff Kirsher enum xirc_cmd { /* Commands */ 18559ffb30fSJeff Kirsher Transmit = 0x01, 18659ffb30fSJeff Kirsher EnableRecv = 0x04, 18759ffb30fSJeff Kirsher DisableRecv = 0x08, 18859ffb30fSJeff Kirsher Abort = 0x10, 18959ffb30fSJeff Kirsher Online = 0x20, 19059ffb30fSJeff Kirsher IntrAck = 0x40, 19159ffb30fSJeff Kirsher Offline = 0x80 19259ffb30fSJeff Kirsher }; 19359ffb30fSJeff Kirsher #define XIRCREG5_RHSA0 10 /* Rx Host Start Address */ 19459ffb30fSJeff Kirsher #define XIRCREG40_RXST0 9 /* Receive Status Register */ 19559ffb30fSJeff Kirsher #define XIRCREG40_TXST0 11 /* Transmit Status Register 0 */ 19659ffb30fSJeff Kirsher #define XIRCREG40_TXST1 12 /* Transmit Status Register 10 */ 19759ffb30fSJeff Kirsher #define XIRCREG40_RMASK0 13 /* Receive Mask Register */ 19859ffb30fSJeff Kirsher #define XIRCREG40_TMASK0 14 /* Transmit Mask Register 0 */ 19959ffb30fSJeff Kirsher #define XIRCREG40_TMASK1 15 /* Transmit Mask Register 0 */ 20059ffb30fSJeff Kirsher #define XIRCREG42_SWC0 8 /* Software Configuration 0 */ 20159ffb30fSJeff Kirsher #define XIRCREG42_SWC1 9 /* Software Configuration 1 */ 20259ffb30fSJeff Kirsher #define XIRCREG42_BOC 10 /* Back-Off Configuration */ 20359ffb30fSJeff Kirsher #define XIRCREG44_TDR0 8 /* Time Domain Reflectometry 0 */ 20459ffb30fSJeff Kirsher #define XIRCREG44_TDR1 9 /* Time Domain Reflectometry 1 */ 20559ffb30fSJeff Kirsher #define XIRCREG44_RXBC_LO 10 /* Rx Byte Count 0 (rd) */ 20659ffb30fSJeff Kirsher #define XIRCREG44_RXBC_HI 11 /* Rx Byte Count 1 (rd) */ 20759ffb30fSJeff Kirsher #define XIRCREG45_REV 15 /* Revision Register (rd) */ 20859ffb30fSJeff Kirsher #define XIRCREG50_IA 8 /* Individual Address (8-13) */ 20959ffb30fSJeff Kirsher 21059ffb30fSJeff Kirsher static const char *if_names[] = { "Auto", "10BaseT", "10Base2", "AUI", "100BaseT" }; 21159ffb30fSJeff Kirsher 21259ffb30fSJeff Kirsher /* card types */ 21359ffb30fSJeff Kirsher #define XIR_UNKNOWN 0 /* unknown: not supported */ 21459ffb30fSJeff Kirsher #define XIR_CE 1 /* (prodid 1) different hardware: not supported */ 21559ffb30fSJeff Kirsher #define XIR_CE2 2 /* (prodid 2) */ 21659ffb30fSJeff Kirsher #define XIR_CE3 3 /* (prodid 3) */ 21759ffb30fSJeff Kirsher #define XIR_CEM 4 /* (prodid 1) different hardware: not supported */ 21859ffb30fSJeff Kirsher #define XIR_CEM2 5 /* (prodid 2) */ 21959ffb30fSJeff Kirsher #define XIR_CEM3 6 /* (prodid 3) */ 22059ffb30fSJeff Kirsher #define XIR_CEM33 7 /* (prodid 4) */ 22159ffb30fSJeff Kirsher #define XIR_CEM56M 8 /* (prodid 5) */ 22259ffb30fSJeff Kirsher #define XIR_CEM56 9 /* (prodid 6) */ 22359ffb30fSJeff Kirsher #define XIR_CM28 10 /* (prodid 3) modem only: not supported here */ 22459ffb30fSJeff Kirsher #define XIR_CM33 11 /* (prodid 4) modem only: not supported here */ 22559ffb30fSJeff Kirsher #define XIR_CM56 12 /* (prodid 5) modem only: not supported here */ 22659ffb30fSJeff Kirsher #define XIR_CG 13 /* (prodid 1) GSM modem only: not supported */ 22759ffb30fSJeff Kirsher #define XIR_CBE 14 /* (prodid 1) cardbus ethernet: not supported */ 22859ffb30fSJeff Kirsher /*====================================================================*/ 22959ffb30fSJeff Kirsher 23059ffb30fSJeff Kirsher /* Module parameters */ 23159ffb30fSJeff Kirsher 23259ffb30fSJeff Kirsher MODULE_DESCRIPTION("Xircom PCMCIA ethernet driver"); 23359ffb30fSJeff Kirsher MODULE_LICENSE("Dual MPL/GPL"); 23459ffb30fSJeff Kirsher 23559ffb30fSJeff Kirsher #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0) 23659ffb30fSJeff Kirsher 23759ffb30fSJeff Kirsher INT_MODULE_PARM(if_port, 0); 23859ffb30fSJeff Kirsher INT_MODULE_PARM(full_duplex, 0); 23959ffb30fSJeff Kirsher INT_MODULE_PARM(do_sound, 1); 24059ffb30fSJeff Kirsher INT_MODULE_PARM(lockup_hack, 0); /* anti lockup hack */ 24159ffb30fSJeff Kirsher 24259ffb30fSJeff Kirsher /*====================================================================*/ 24359ffb30fSJeff Kirsher 24459ffb30fSJeff Kirsher /* We do not process more than these number of bytes during one 24559ffb30fSJeff Kirsher * interrupt. (Of course we receive complete packets, so this is not 24659ffb30fSJeff Kirsher * an exact value). 24759ffb30fSJeff Kirsher * Something between 2000..22000; first value gives best interrupt latency, 24859ffb30fSJeff Kirsher * the second enables the usage of the complete on-chip buffer. We use the 24959ffb30fSJeff Kirsher * high value as the initial value. 25059ffb30fSJeff Kirsher */ 25159ffb30fSJeff Kirsher static unsigned maxrx_bytes = 22000; 25259ffb30fSJeff Kirsher 25359ffb30fSJeff Kirsher /* MII management prototypes */ 25459ffb30fSJeff Kirsher static void mii_idle(unsigned int ioaddr); 25559ffb30fSJeff Kirsher static void mii_putbit(unsigned int ioaddr, unsigned data); 25659ffb30fSJeff Kirsher static int mii_getbit(unsigned int ioaddr); 25759ffb30fSJeff Kirsher static void mii_wbits(unsigned int ioaddr, unsigned data, int len); 25859ffb30fSJeff Kirsher static unsigned mii_rd(unsigned int ioaddr, u_char phyaddr, u_char phyreg); 25959ffb30fSJeff Kirsher static void mii_wr(unsigned int ioaddr, u_char phyaddr, u_char phyreg, 26059ffb30fSJeff Kirsher unsigned data, int len); 26159ffb30fSJeff Kirsher 26259ffb30fSJeff Kirsher static int has_ce2_string(struct pcmcia_device * link); 26359ffb30fSJeff Kirsher static int xirc2ps_config(struct pcmcia_device * link); 26459ffb30fSJeff Kirsher static void xirc2ps_release(struct pcmcia_device * link); 26559ffb30fSJeff Kirsher static void xirc2ps_detach(struct pcmcia_device *p_dev); 26659ffb30fSJeff Kirsher 26759ffb30fSJeff Kirsher static irqreturn_t xirc2ps_interrupt(int irq, void *dev_id); 26859ffb30fSJeff Kirsher 269f8653464SHimangi Saraogi struct local_info { 27059ffb30fSJeff Kirsher struct net_device *dev; 27159ffb30fSJeff Kirsher struct pcmcia_device *p_dev; 27259ffb30fSJeff Kirsher 27359ffb30fSJeff Kirsher int card_type; 27459ffb30fSJeff Kirsher int probe_port; 27559ffb30fSJeff Kirsher int silicon; /* silicon revision. 0=old CE2, 1=Scipper, 4=Mohawk */ 27659ffb30fSJeff Kirsher int mohawk; /* a CE3 type card */ 27759ffb30fSJeff Kirsher int dingo; /* a CEM56 type card */ 27859ffb30fSJeff Kirsher int new_mii; /* has full 10baseT/100baseT MII */ 27959ffb30fSJeff Kirsher int modem; /* is a multi function card (i.e with a modem) */ 28059ffb30fSJeff Kirsher void __iomem *dingo_ccr; /* only used for CEM56 cards */ 28159ffb30fSJeff Kirsher unsigned last_ptr_value; /* last packets transmitted value */ 28259ffb30fSJeff Kirsher const char *manf_str; 28359ffb30fSJeff Kirsher struct work_struct tx_timeout_task; 284f8653464SHimangi Saraogi }; 28559ffb30fSJeff Kirsher 28659ffb30fSJeff Kirsher /**************** 28759ffb30fSJeff Kirsher * Some more prototypes 28859ffb30fSJeff Kirsher */ 28959ffb30fSJeff Kirsher static netdev_tx_t do_start_xmit(struct sk_buff *skb, 29059ffb30fSJeff Kirsher struct net_device *dev); 2910290bd29SMichael S. Tsirkin static void xirc_tx_timeout(struct net_device *dev, unsigned int txqueue); 29259ffb30fSJeff Kirsher static void xirc2ps_tx_timeout_task(struct work_struct *work); 29359ffb30fSJeff Kirsher static void set_addresses(struct net_device *dev); 29459ffb30fSJeff Kirsher static void set_multicast_list(struct net_device *dev); 29559ffb30fSJeff Kirsher static int set_card_type(struct pcmcia_device *link); 29659ffb30fSJeff Kirsher static int do_config(struct net_device *dev, struct ifmap *map); 29759ffb30fSJeff Kirsher static int do_open(struct net_device *dev); 29859ffb30fSJeff Kirsher static int do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 29959ffb30fSJeff Kirsher static const struct ethtool_ops netdev_ethtool_ops; 30059ffb30fSJeff Kirsher static void hardreset(struct net_device *dev); 30159ffb30fSJeff Kirsher static void do_reset(struct net_device *dev, int full); 30259ffb30fSJeff Kirsher static int init_mii(struct net_device *dev); 30359ffb30fSJeff Kirsher static void do_powerdown(struct net_device *dev); 30459ffb30fSJeff Kirsher static int do_stop(struct net_device *dev); 30559ffb30fSJeff Kirsher 30659ffb30fSJeff Kirsher /*=============== Helper functions =========================*/ 30759ffb30fSJeff Kirsher #define SelectPage(pgnr) outb((pgnr), ioaddr + XIRCREG_PR) 30859ffb30fSJeff Kirsher #define GetByte(reg) ((unsigned)inb(ioaddr + (reg))) 30959ffb30fSJeff Kirsher #define GetWord(reg) ((unsigned)inw(ioaddr + (reg))) 31059ffb30fSJeff Kirsher #define PutByte(reg,value) outb((value), ioaddr+(reg)) 31159ffb30fSJeff Kirsher #define PutWord(reg,value) outw((value), ioaddr+(reg)) 31259ffb30fSJeff Kirsher 31359ffb30fSJeff Kirsher /*====== Functions used for debugging =================================*/ 31459ffb30fSJeff Kirsher #if 0 /* reading regs may change system status */ 31559ffb30fSJeff Kirsher static void 31659ffb30fSJeff Kirsher PrintRegisters(struct net_device *dev) 31759ffb30fSJeff Kirsher { 31859ffb30fSJeff Kirsher unsigned int ioaddr = dev->base_addr; 31959ffb30fSJeff Kirsher 32059ffb30fSJeff Kirsher if (pc_debug > 1) { 32159ffb30fSJeff Kirsher int i, page; 32259ffb30fSJeff Kirsher 32359ffb30fSJeff Kirsher printk(KERN_DEBUG pr_fmt("Register common: ")); 32459ffb30fSJeff Kirsher for (i = 0; i < 8; i++) 32559ffb30fSJeff Kirsher pr_cont(" %2.2x", GetByte(i)); 32659ffb30fSJeff Kirsher pr_cont("\n"); 32759ffb30fSJeff Kirsher for (page = 0; page <= 8; page++) { 32859ffb30fSJeff Kirsher printk(KERN_DEBUG pr_fmt("Register page %2x: "), page); 32959ffb30fSJeff Kirsher SelectPage(page); 33059ffb30fSJeff Kirsher for (i = 8; i < 16; i++) 33159ffb30fSJeff Kirsher pr_cont(" %2.2x", GetByte(i)); 33259ffb30fSJeff Kirsher pr_cont("\n"); 33359ffb30fSJeff Kirsher } 33459ffb30fSJeff Kirsher for (page=0x40 ; page <= 0x5f; page++) { 33559ffb30fSJeff Kirsher if (page == 0x43 || (page >= 0x46 && page <= 0x4f) || 33659ffb30fSJeff Kirsher (page >= 0x51 && page <=0x5e)) 33759ffb30fSJeff Kirsher continue; 33859ffb30fSJeff Kirsher printk(KERN_DEBUG pr_fmt("Register page %2x: "), page); 33959ffb30fSJeff Kirsher SelectPage(page); 34059ffb30fSJeff Kirsher for (i = 8; i < 16; i++) 34159ffb30fSJeff Kirsher pr_cont(" %2.2x", GetByte(i)); 34259ffb30fSJeff Kirsher pr_cont("\n"); 34359ffb30fSJeff Kirsher } 34459ffb30fSJeff Kirsher } 34559ffb30fSJeff Kirsher } 34659ffb30fSJeff Kirsher #endif /* 0 */ 34759ffb30fSJeff Kirsher 34859ffb30fSJeff Kirsher /*============== MII Management functions ===============*/ 34959ffb30fSJeff Kirsher 35059ffb30fSJeff Kirsher /**************** 35159ffb30fSJeff Kirsher * Turn around for read 35259ffb30fSJeff Kirsher */ 35359ffb30fSJeff Kirsher static void 35459ffb30fSJeff Kirsher mii_idle(unsigned int ioaddr) 35559ffb30fSJeff Kirsher { 35659ffb30fSJeff Kirsher PutByte(XIRCREG2_GPR2, 0x04|0); /* drive MDCK low */ 35759ffb30fSJeff Kirsher udelay(1); 35859ffb30fSJeff Kirsher PutByte(XIRCREG2_GPR2, 0x04|1); /* and drive MDCK high */ 35959ffb30fSJeff Kirsher udelay(1); 36059ffb30fSJeff Kirsher } 36159ffb30fSJeff Kirsher 36259ffb30fSJeff Kirsher /**************** 36359ffb30fSJeff Kirsher * Write a bit to MDI/O 36459ffb30fSJeff Kirsher */ 36559ffb30fSJeff Kirsher static void 36659ffb30fSJeff Kirsher mii_putbit(unsigned int ioaddr, unsigned data) 36759ffb30fSJeff Kirsher { 36859ffb30fSJeff Kirsher #if 1 36959ffb30fSJeff Kirsher if (data) { 37059ffb30fSJeff Kirsher PutByte(XIRCREG2_GPR2, 0x0c|2|0); /* set MDIO */ 37159ffb30fSJeff Kirsher udelay(1); 37259ffb30fSJeff Kirsher PutByte(XIRCREG2_GPR2, 0x0c|2|1); /* and drive MDCK high */ 37359ffb30fSJeff Kirsher udelay(1); 37459ffb30fSJeff Kirsher } else { 37559ffb30fSJeff Kirsher PutByte(XIRCREG2_GPR2, 0x0c|0|0); /* clear MDIO */ 37659ffb30fSJeff Kirsher udelay(1); 37759ffb30fSJeff Kirsher PutByte(XIRCREG2_GPR2, 0x0c|0|1); /* and drive MDCK high */ 37859ffb30fSJeff Kirsher udelay(1); 37959ffb30fSJeff Kirsher } 38059ffb30fSJeff Kirsher #else 38159ffb30fSJeff Kirsher if (data) { 38259ffb30fSJeff Kirsher PutWord(XIRCREG2_GPR2-1, 0x0e0e); 38359ffb30fSJeff Kirsher udelay(1); 38459ffb30fSJeff Kirsher PutWord(XIRCREG2_GPR2-1, 0x0f0f); 38559ffb30fSJeff Kirsher udelay(1); 38659ffb30fSJeff Kirsher } else { 38759ffb30fSJeff Kirsher PutWord(XIRCREG2_GPR2-1, 0x0c0c); 38859ffb30fSJeff Kirsher udelay(1); 38959ffb30fSJeff Kirsher PutWord(XIRCREG2_GPR2-1, 0x0d0d); 39059ffb30fSJeff Kirsher udelay(1); 39159ffb30fSJeff Kirsher } 39259ffb30fSJeff Kirsher #endif 39359ffb30fSJeff Kirsher } 39459ffb30fSJeff Kirsher 39559ffb30fSJeff Kirsher /**************** 39659ffb30fSJeff Kirsher * Get a bit from MDI/O 39759ffb30fSJeff Kirsher */ 39859ffb30fSJeff Kirsher static int 39959ffb30fSJeff Kirsher mii_getbit(unsigned int ioaddr) 40059ffb30fSJeff Kirsher { 40159ffb30fSJeff Kirsher unsigned d; 40259ffb30fSJeff Kirsher 40359ffb30fSJeff Kirsher PutByte(XIRCREG2_GPR2, 4|0); /* drive MDCK low */ 40459ffb30fSJeff Kirsher udelay(1); 40559ffb30fSJeff Kirsher d = GetByte(XIRCREG2_GPR2); /* read MDIO */ 40659ffb30fSJeff Kirsher PutByte(XIRCREG2_GPR2, 4|1); /* drive MDCK high again */ 40759ffb30fSJeff Kirsher udelay(1); 40859ffb30fSJeff Kirsher return d & 0x20; /* read MDIO */ 40959ffb30fSJeff Kirsher } 41059ffb30fSJeff Kirsher 41159ffb30fSJeff Kirsher static void 41259ffb30fSJeff Kirsher mii_wbits(unsigned int ioaddr, unsigned data, int len) 41359ffb30fSJeff Kirsher { 41459ffb30fSJeff Kirsher unsigned m = 1 << (len-1); 41559ffb30fSJeff Kirsher for (; m; m >>= 1) 41659ffb30fSJeff Kirsher mii_putbit(ioaddr, data & m); 41759ffb30fSJeff Kirsher } 41859ffb30fSJeff Kirsher 41959ffb30fSJeff Kirsher static unsigned 42059ffb30fSJeff Kirsher mii_rd(unsigned int ioaddr, u_char phyaddr, u_char phyreg) 42159ffb30fSJeff Kirsher { 42259ffb30fSJeff Kirsher int i; 42359ffb30fSJeff Kirsher unsigned data=0, m; 42459ffb30fSJeff Kirsher 42559ffb30fSJeff Kirsher SelectPage(2); 42659ffb30fSJeff Kirsher for (i=0; i < 32; i++) /* 32 bit preamble */ 42759ffb30fSJeff Kirsher mii_putbit(ioaddr, 1); 42859ffb30fSJeff Kirsher mii_wbits(ioaddr, 0x06, 4); /* Start and opcode for read */ 42959ffb30fSJeff Kirsher mii_wbits(ioaddr, phyaddr, 5); /* PHY address to be accessed */ 43059ffb30fSJeff Kirsher mii_wbits(ioaddr, phyreg, 5); /* PHY register to read */ 43159ffb30fSJeff Kirsher mii_idle(ioaddr); /* turn around */ 43259ffb30fSJeff Kirsher mii_getbit(ioaddr); 43359ffb30fSJeff Kirsher 43459ffb30fSJeff Kirsher for (m = 1<<15; m; m >>= 1) 43559ffb30fSJeff Kirsher if (mii_getbit(ioaddr)) 43659ffb30fSJeff Kirsher data |= m; 43759ffb30fSJeff Kirsher mii_idle(ioaddr); 43859ffb30fSJeff Kirsher return data; 43959ffb30fSJeff Kirsher } 44059ffb30fSJeff Kirsher 44159ffb30fSJeff Kirsher static void 44259ffb30fSJeff Kirsher mii_wr(unsigned int ioaddr, u_char phyaddr, u_char phyreg, unsigned data, 44359ffb30fSJeff Kirsher int len) 44459ffb30fSJeff Kirsher { 44559ffb30fSJeff Kirsher int i; 44659ffb30fSJeff Kirsher 44759ffb30fSJeff Kirsher SelectPage(2); 44859ffb30fSJeff Kirsher for (i=0; i < 32; i++) /* 32 bit preamble */ 44959ffb30fSJeff Kirsher mii_putbit(ioaddr, 1); 45059ffb30fSJeff Kirsher mii_wbits(ioaddr, 0x05, 4); /* Start and opcode for write */ 45159ffb30fSJeff Kirsher mii_wbits(ioaddr, phyaddr, 5); /* PHY address to be accessed */ 45259ffb30fSJeff Kirsher mii_wbits(ioaddr, phyreg, 5); /* PHY Register to write */ 45359ffb30fSJeff Kirsher mii_putbit(ioaddr, 1); /* turn around */ 45459ffb30fSJeff Kirsher mii_putbit(ioaddr, 0); 45559ffb30fSJeff Kirsher mii_wbits(ioaddr, data, len); /* And write the data */ 45659ffb30fSJeff Kirsher mii_idle(ioaddr); 45759ffb30fSJeff Kirsher } 45859ffb30fSJeff Kirsher 45959ffb30fSJeff Kirsher /*============= Main bulk of functions =========================*/ 46059ffb30fSJeff Kirsher 46159ffb30fSJeff Kirsher static const struct net_device_ops netdev_ops = { 46259ffb30fSJeff Kirsher .ndo_open = do_open, 46359ffb30fSJeff Kirsher .ndo_stop = do_stop, 46459ffb30fSJeff Kirsher .ndo_start_xmit = do_start_xmit, 46559ffb30fSJeff Kirsher .ndo_tx_timeout = xirc_tx_timeout, 46659ffb30fSJeff Kirsher .ndo_set_config = do_config, 467a7605370SArnd Bergmann .ndo_eth_ioctl = do_ioctl, 468afc4b13dSJiri Pirko .ndo_set_rx_mode = set_multicast_list, 46959ffb30fSJeff Kirsher .ndo_set_mac_address = eth_mac_addr, 47059ffb30fSJeff Kirsher .ndo_validate_addr = eth_validate_addr, 47159ffb30fSJeff Kirsher }; 47259ffb30fSJeff Kirsher 47359ffb30fSJeff Kirsher static int 47459ffb30fSJeff Kirsher xirc2ps_probe(struct pcmcia_device *link) 47559ffb30fSJeff Kirsher { 47659ffb30fSJeff Kirsher struct net_device *dev; 477f8653464SHimangi Saraogi struct local_info *local; 47859ffb30fSJeff Kirsher 47959ffb30fSJeff Kirsher dev_dbg(&link->dev, "attach()\n"); 48059ffb30fSJeff Kirsher 48159ffb30fSJeff Kirsher /* Allocate the device structure */ 482f8653464SHimangi Saraogi dev = alloc_etherdev(sizeof(struct local_info)); 48359ffb30fSJeff Kirsher if (!dev) 48459ffb30fSJeff Kirsher return -ENOMEM; 48559ffb30fSJeff Kirsher local = netdev_priv(dev); 48659ffb30fSJeff Kirsher local->dev = dev; 48759ffb30fSJeff Kirsher local->p_dev = link; 48859ffb30fSJeff Kirsher link->priv = dev; 48959ffb30fSJeff Kirsher 49059ffb30fSJeff Kirsher /* General socket configuration */ 49159ffb30fSJeff Kirsher link->config_index = 1; 49259ffb30fSJeff Kirsher 49359ffb30fSJeff Kirsher /* Fill in card specific entries */ 49459ffb30fSJeff Kirsher dev->netdev_ops = &netdev_ops; 49559ffb30fSJeff Kirsher dev->ethtool_ops = &netdev_ethtool_ops; 49659ffb30fSJeff Kirsher dev->watchdog_timeo = TX_TIMEOUT; 49759ffb30fSJeff Kirsher INIT_WORK(&local->tx_timeout_task, xirc2ps_tx_timeout_task); 49859ffb30fSJeff Kirsher 49959ffb30fSJeff Kirsher return xirc2ps_config(link); 50059ffb30fSJeff Kirsher } /* xirc2ps_attach */ 50159ffb30fSJeff Kirsher 50259ffb30fSJeff Kirsher static void 50359ffb30fSJeff Kirsher xirc2ps_detach(struct pcmcia_device *link) 50459ffb30fSJeff Kirsher { 50559ffb30fSJeff Kirsher struct net_device *dev = link->priv; 50659ffb30fSJeff Kirsher 50759ffb30fSJeff Kirsher dev_dbg(&link->dev, "detach\n"); 50859ffb30fSJeff Kirsher 50959ffb30fSJeff Kirsher unregister_netdev(dev); 51059ffb30fSJeff Kirsher 51159ffb30fSJeff Kirsher xirc2ps_release(link); 51259ffb30fSJeff Kirsher 51359ffb30fSJeff Kirsher free_netdev(dev); 51459ffb30fSJeff Kirsher } /* xirc2ps_detach */ 51559ffb30fSJeff Kirsher 51659ffb30fSJeff Kirsher /**************** 51759ffb30fSJeff Kirsher * Detect the type of the card. s is the buffer with the data of tuple 0x20 51859ffb30fSJeff Kirsher * Returns: 0 := not supported 51959ffb30fSJeff Kirsher * mediaid=11 and prodid=47 52059ffb30fSJeff Kirsher * Media-Id bits: 52159ffb30fSJeff Kirsher * Ethernet 0x01 52259ffb30fSJeff Kirsher * Tokenring 0x02 52359ffb30fSJeff Kirsher * Arcnet 0x04 52459ffb30fSJeff Kirsher * Wireless 0x08 52559ffb30fSJeff Kirsher * Modem 0x10 52659ffb30fSJeff Kirsher * GSM only 0x20 52759ffb30fSJeff Kirsher * Prod-Id bits: 52859ffb30fSJeff Kirsher * Pocket 0x10 52959ffb30fSJeff Kirsher * External 0x20 53059ffb30fSJeff Kirsher * Creditcard 0x40 53159ffb30fSJeff Kirsher * Cardbus 0x80 53259ffb30fSJeff Kirsher * 53359ffb30fSJeff Kirsher */ 53459ffb30fSJeff Kirsher static int 53559ffb30fSJeff Kirsher set_card_type(struct pcmcia_device *link) 53659ffb30fSJeff Kirsher { 53759ffb30fSJeff Kirsher struct net_device *dev = link->priv; 538f8653464SHimangi Saraogi struct local_info *local = netdev_priv(dev); 53959ffb30fSJeff Kirsher u8 *buf; 54059ffb30fSJeff Kirsher unsigned int cisrev, mediaid, prodid; 54159ffb30fSJeff Kirsher size_t len; 54259ffb30fSJeff Kirsher 54359ffb30fSJeff Kirsher len = pcmcia_get_tuple(link, CISTPL_MANFID, &buf); 54459ffb30fSJeff Kirsher if (len < 5) { 54559ffb30fSJeff Kirsher dev_err(&link->dev, "invalid CIS -- sorry\n"); 54659ffb30fSJeff Kirsher return 0; 54759ffb30fSJeff Kirsher } 54859ffb30fSJeff Kirsher 54959ffb30fSJeff Kirsher cisrev = buf[2]; 55059ffb30fSJeff Kirsher mediaid = buf[3]; 55159ffb30fSJeff Kirsher prodid = buf[4]; 55259ffb30fSJeff Kirsher 55359ffb30fSJeff Kirsher dev_dbg(&link->dev, "cisrev=%02x mediaid=%02x prodid=%02x\n", 55459ffb30fSJeff Kirsher cisrev, mediaid, prodid); 55559ffb30fSJeff Kirsher 55659ffb30fSJeff Kirsher local->mohawk = 0; 55759ffb30fSJeff Kirsher local->dingo = 0; 55859ffb30fSJeff Kirsher local->modem = 0; 55959ffb30fSJeff Kirsher local->card_type = XIR_UNKNOWN; 56059ffb30fSJeff Kirsher if (!(prodid & 0x40)) { 56159ffb30fSJeff Kirsher pr_notice("Oops: Not a creditcard\n"); 56259ffb30fSJeff Kirsher return 0; 56359ffb30fSJeff Kirsher } 56459ffb30fSJeff Kirsher if (!(mediaid & 0x01)) { 56559ffb30fSJeff Kirsher pr_notice("Not an Ethernet card\n"); 56659ffb30fSJeff Kirsher return 0; 56759ffb30fSJeff Kirsher } 56859ffb30fSJeff Kirsher if (mediaid & 0x10) { 56959ffb30fSJeff Kirsher local->modem = 1; 57059ffb30fSJeff Kirsher switch(prodid & 15) { 57159ffb30fSJeff Kirsher case 1: local->card_type = XIR_CEM ; break; 57259ffb30fSJeff Kirsher case 2: local->card_type = XIR_CEM2 ; break; 57359ffb30fSJeff Kirsher case 3: local->card_type = XIR_CEM3 ; break; 57459ffb30fSJeff Kirsher case 4: local->card_type = XIR_CEM33 ; break; 57559ffb30fSJeff Kirsher case 5: local->card_type = XIR_CEM56M; 57659ffb30fSJeff Kirsher local->mohawk = 1; 57759ffb30fSJeff Kirsher break; 57859ffb30fSJeff Kirsher case 6: 57959ffb30fSJeff Kirsher case 7: /* 7 is the RealPort 10/56 */ 58059ffb30fSJeff Kirsher local->card_type = XIR_CEM56 ; 58159ffb30fSJeff Kirsher local->mohawk = 1; 58259ffb30fSJeff Kirsher local->dingo = 1; 58359ffb30fSJeff Kirsher break; 58459ffb30fSJeff Kirsher } 58559ffb30fSJeff Kirsher } else { 58659ffb30fSJeff Kirsher switch(prodid & 15) { 58759ffb30fSJeff Kirsher case 1: local->card_type = has_ce2_string(link)? XIR_CE2 : XIR_CE ; 58859ffb30fSJeff Kirsher break; 58959ffb30fSJeff Kirsher case 2: local->card_type = XIR_CE2; break; 59059ffb30fSJeff Kirsher case 3: local->card_type = XIR_CE3; 59159ffb30fSJeff Kirsher local->mohawk = 1; 59259ffb30fSJeff Kirsher break; 59359ffb30fSJeff Kirsher } 59459ffb30fSJeff Kirsher } 59559ffb30fSJeff Kirsher if (local->card_type == XIR_CE || local->card_type == XIR_CEM) { 59659ffb30fSJeff Kirsher pr_notice("Sorry, this is an old CE card\n"); 59759ffb30fSJeff Kirsher return 0; 59859ffb30fSJeff Kirsher } 59959ffb30fSJeff Kirsher if (local->card_type == XIR_UNKNOWN) 60059ffb30fSJeff Kirsher pr_notice("unknown card (mediaid=%02x prodid=%02x)\n", mediaid, prodid); 60159ffb30fSJeff Kirsher 60259ffb30fSJeff Kirsher return 1; 60359ffb30fSJeff Kirsher } 60459ffb30fSJeff Kirsher 60559ffb30fSJeff Kirsher /**************** 60659ffb30fSJeff Kirsher * There are some CE2 cards out which claim to be a CE card. 60759ffb30fSJeff Kirsher * This function looks for a "CE2" in the 3rd version field. 60859ffb30fSJeff Kirsher * Returns: true if this is a CE2 60959ffb30fSJeff Kirsher */ 61059ffb30fSJeff Kirsher static int 61159ffb30fSJeff Kirsher has_ce2_string(struct pcmcia_device * p_dev) 61259ffb30fSJeff Kirsher { 61359ffb30fSJeff Kirsher if (p_dev->prod_id[2] && strstr(p_dev->prod_id[2], "CE2")) 61459ffb30fSJeff Kirsher return 1; 61559ffb30fSJeff Kirsher return 0; 61659ffb30fSJeff Kirsher } 61759ffb30fSJeff Kirsher 61859ffb30fSJeff Kirsher static int 61959ffb30fSJeff Kirsher xirc2ps_config_modem(struct pcmcia_device *p_dev, void *priv_data) 62059ffb30fSJeff Kirsher { 62159ffb30fSJeff Kirsher unsigned int ioaddr; 62259ffb30fSJeff Kirsher 62359ffb30fSJeff Kirsher if ((p_dev->resource[0]->start & 0xf) == 8) 62459ffb30fSJeff Kirsher return -ENODEV; 62559ffb30fSJeff Kirsher 62659ffb30fSJeff Kirsher p_dev->resource[0]->end = 16; 62759ffb30fSJeff Kirsher p_dev->resource[1]->end = 8; 62859ffb30fSJeff Kirsher p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH; 62959ffb30fSJeff Kirsher p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16; 63059ffb30fSJeff Kirsher p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH; 63159ffb30fSJeff Kirsher p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8; 63259ffb30fSJeff Kirsher p_dev->io_lines = 10; 63359ffb30fSJeff Kirsher 63459ffb30fSJeff Kirsher p_dev->resource[1]->start = p_dev->resource[0]->start; 63559ffb30fSJeff Kirsher for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) { 63659ffb30fSJeff Kirsher p_dev->resource[0]->start = ioaddr; 63759ffb30fSJeff Kirsher if (!pcmcia_request_io(p_dev)) 63859ffb30fSJeff Kirsher return 0; 63959ffb30fSJeff Kirsher } 64059ffb30fSJeff Kirsher return -ENODEV; 64159ffb30fSJeff Kirsher } 64259ffb30fSJeff Kirsher 64359ffb30fSJeff Kirsher static int 64459ffb30fSJeff Kirsher xirc2ps_config_check(struct pcmcia_device *p_dev, void *priv_data) 64559ffb30fSJeff Kirsher { 64659ffb30fSJeff Kirsher int *pass = priv_data; 64759ffb30fSJeff Kirsher resource_size_t tmp = p_dev->resource[1]->start; 64859ffb30fSJeff Kirsher 64959ffb30fSJeff Kirsher tmp += (*pass ? (p_dev->config_index & 0x20 ? -24 : 8) 65059ffb30fSJeff Kirsher : (p_dev->config_index & 0x20 ? 8 : -24)); 65159ffb30fSJeff Kirsher 65259ffb30fSJeff Kirsher if ((p_dev->resource[0]->start & 0xf) == 8) 65359ffb30fSJeff Kirsher return -ENODEV; 65459ffb30fSJeff Kirsher 65559ffb30fSJeff Kirsher p_dev->resource[0]->end = 18; 65659ffb30fSJeff Kirsher p_dev->resource[1]->end = 8; 65759ffb30fSJeff Kirsher p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH; 65859ffb30fSJeff Kirsher p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16; 65959ffb30fSJeff Kirsher p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH; 66059ffb30fSJeff Kirsher p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8; 66159ffb30fSJeff Kirsher p_dev->io_lines = 10; 66259ffb30fSJeff Kirsher 66359ffb30fSJeff Kirsher p_dev->resource[1]->start = p_dev->resource[0]->start; 66459ffb30fSJeff Kirsher p_dev->resource[0]->start = tmp; 66559ffb30fSJeff Kirsher return pcmcia_request_io(p_dev); 66659ffb30fSJeff Kirsher } 66759ffb30fSJeff Kirsher 66859ffb30fSJeff Kirsher 66959ffb30fSJeff Kirsher static int pcmcia_get_mac_ce(struct pcmcia_device *p_dev, 67059ffb30fSJeff Kirsher tuple_t *tuple, 67159ffb30fSJeff Kirsher void *priv) 67259ffb30fSJeff Kirsher { 67359ffb30fSJeff Kirsher struct net_device *dev = priv; 67459ffb30fSJeff Kirsher int i; 67559ffb30fSJeff Kirsher 67659ffb30fSJeff Kirsher if (tuple->TupleDataLen != 13) 67759ffb30fSJeff Kirsher return -EINVAL; 67859ffb30fSJeff Kirsher if ((tuple->TupleData[0] != 2) || (tuple->TupleData[1] != 1) || 67959ffb30fSJeff Kirsher (tuple->TupleData[2] != 6)) 68059ffb30fSJeff Kirsher return -EINVAL; 68159ffb30fSJeff Kirsher /* another try (James Lehmer's CE2 version 4.1)*/ 68259ffb30fSJeff Kirsher for (i = 2; i < 6; i++) 68359ffb30fSJeff Kirsher dev->dev_addr[i] = tuple->TupleData[i+2]; 68459ffb30fSJeff Kirsher return 0; 68559ffb30fSJeff Kirsher }; 68659ffb30fSJeff Kirsher 68759ffb30fSJeff Kirsher 68859ffb30fSJeff Kirsher static int 68959ffb30fSJeff Kirsher xirc2ps_config(struct pcmcia_device * link) 69059ffb30fSJeff Kirsher { 69159ffb30fSJeff Kirsher struct net_device *dev = link->priv; 692f8653464SHimangi Saraogi struct local_info *local = netdev_priv(dev); 69359ffb30fSJeff Kirsher unsigned int ioaddr; 69459ffb30fSJeff Kirsher int err; 69559ffb30fSJeff Kirsher u8 *buf; 69659ffb30fSJeff Kirsher size_t len; 69759ffb30fSJeff Kirsher 69859ffb30fSJeff Kirsher local->dingo_ccr = NULL; 69959ffb30fSJeff Kirsher 70059ffb30fSJeff Kirsher dev_dbg(&link->dev, "config\n"); 70159ffb30fSJeff Kirsher 70259ffb30fSJeff Kirsher /* Is this a valid card */ 70359ffb30fSJeff Kirsher if (link->has_manf_id == 0) { 70459ffb30fSJeff Kirsher pr_notice("manfid not found in CIS\n"); 70559ffb30fSJeff Kirsher goto failure; 70659ffb30fSJeff Kirsher } 70759ffb30fSJeff Kirsher 70859ffb30fSJeff Kirsher switch (link->manf_id) { 70959ffb30fSJeff Kirsher case MANFID_XIRCOM: 71059ffb30fSJeff Kirsher local->manf_str = "Xircom"; 71159ffb30fSJeff Kirsher break; 71259ffb30fSJeff Kirsher case MANFID_ACCTON: 71359ffb30fSJeff Kirsher local->manf_str = "Accton"; 71459ffb30fSJeff Kirsher break; 71559ffb30fSJeff Kirsher case MANFID_COMPAQ: 71659ffb30fSJeff Kirsher case MANFID_COMPAQ2: 71759ffb30fSJeff Kirsher local->manf_str = "Compaq"; 71859ffb30fSJeff Kirsher break; 71959ffb30fSJeff Kirsher case MANFID_INTEL: 72059ffb30fSJeff Kirsher local->manf_str = "Intel"; 72159ffb30fSJeff Kirsher break; 72259ffb30fSJeff Kirsher case MANFID_TOSHIBA: 72359ffb30fSJeff Kirsher local->manf_str = "Toshiba"; 72459ffb30fSJeff Kirsher break; 72559ffb30fSJeff Kirsher default: 72659ffb30fSJeff Kirsher pr_notice("Unknown Card Manufacturer ID: 0x%04x\n", 72759ffb30fSJeff Kirsher (unsigned)link->manf_id); 72859ffb30fSJeff Kirsher goto failure; 72959ffb30fSJeff Kirsher } 73059ffb30fSJeff Kirsher dev_dbg(&link->dev, "found %s card\n", local->manf_str); 73159ffb30fSJeff Kirsher 73259ffb30fSJeff Kirsher if (!set_card_type(link)) { 73359ffb30fSJeff Kirsher pr_notice("this card is not supported\n"); 73459ffb30fSJeff Kirsher goto failure; 73559ffb30fSJeff Kirsher } 73659ffb30fSJeff Kirsher 73759ffb30fSJeff Kirsher /* get the ethernet address from the CIS */ 73859ffb30fSJeff Kirsher err = pcmcia_get_mac_from_cis(link, dev); 73959ffb30fSJeff Kirsher 74059ffb30fSJeff Kirsher /* not found: try to get the node-id from tuple 0x89 */ 74159ffb30fSJeff Kirsher if (err) { 74259ffb30fSJeff Kirsher len = pcmcia_get_tuple(link, 0x89, &buf); 74359ffb30fSJeff Kirsher /* data layout looks like tuple 0x22 */ 74459ffb30fSJeff Kirsher if (buf && len == 8) { 74559ffb30fSJeff Kirsher if (*buf == CISTPL_FUNCE_LAN_NODE_ID) { 74659ffb30fSJeff Kirsher int i; 74759ffb30fSJeff Kirsher for (i = 2; i < 6; i++) 74859ffb30fSJeff Kirsher dev->dev_addr[i] = buf[i+2]; 74959ffb30fSJeff Kirsher } else 75059ffb30fSJeff Kirsher err = -1; 75159ffb30fSJeff Kirsher } 75259ffb30fSJeff Kirsher kfree(buf); 75359ffb30fSJeff Kirsher } 75459ffb30fSJeff Kirsher 75559ffb30fSJeff Kirsher if (err) 75659ffb30fSJeff Kirsher err = pcmcia_loop_tuple(link, CISTPL_FUNCE, pcmcia_get_mac_ce, dev); 75759ffb30fSJeff Kirsher 75859ffb30fSJeff Kirsher if (err) { 75959ffb30fSJeff Kirsher pr_notice("node-id not found in CIS\n"); 76059ffb30fSJeff Kirsher goto failure; 76159ffb30fSJeff Kirsher } 76259ffb30fSJeff Kirsher 76359ffb30fSJeff Kirsher if (local->modem) { 76459ffb30fSJeff Kirsher int pass; 76559ffb30fSJeff Kirsher link->config_flags |= CONF_AUTO_SET_IO; 76659ffb30fSJeff Kirsher 76759ffb30fSJeff Kirsher if (local->dingo) { 76859ffb30fSJeff Kirsher /* Take the Modem IO port from the CIS and scan for a free 76959ffb30fSJeff Kirsher * Ethernet port */ 77059ffb30fSJeff Kirsher if (!pcmcia_loop_config(link, xirc2ps_config_modem, NULL)) 77159ffb30fSJeff Kirsher goto port_found; 77259ffb30fSJeff Kirsher } else { 77359ffb30fSJeff Kirsher /* We do 2 passes here: The first one uses the regular mapping and 77459ffb30fSJeff Kirsher * the second tries again, thereby considering that the 32 ports are 77559ffb30fSJeff Kirsher * mirrored every 32 bytes. Actually we use a mirrored port for 77659ffb30fSJeff Kirsher * the Mako if (on the first pass) the COR bit 5 is set. 77759ffb30fSJeff Kirsher */ 77859ffb30fSJeff Kirsher for (pass=0; pass < 2; pass++) 77959ffb30fSJeff Kirsher if (!pcmcia_loop_config(link, xirc2ps_config_check, 78059ffb30fSJeff Kirsher &pass)) 78159ffb30fSJeff Kirsher goto port_found; 78259ffb30fSJeff Kirsher /* if special option: 78359ffb30fSJeff Kirsher * try to configure as Ethernet only. 78459ffb30fSJeff Kirsher * .... */ 78559ffb30fSJeff Kirsher } 78659ffb30fSJeff Kirsher pr_notice("no ports available\n"); 78759ffb30fSJeff Kirsher } else { 78859ffb30fSJeff Kirsher link->io_lines = 10; 78959ffb30fSJeff Kirsher link->resource[0]->end = 16; 79059ffb30fSJeff Kirsher link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16; 79159ffb30fSJeff Kirsher for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) { 79259ffb30fSJeff Kirsher link->resource[0]->start = ioaddr; 79359ffb30fSJeff Kirsher if (!(err = pcmcia_request_io(link))) 79459ffb30fSJeff Kirsher goto port_found; 79559ffb30fSJeff Kirsher } 79659ffb30fSJeff Kirsher link->resource[0]->start = 0; /* let CS decide */ 79759ffb30fSJeff Kirsher if ((err = pcmcia_request_io(link))) 79859ffb30fSJeff Kirsher goto config_error; 79959ffb30fSJeff Kirsher } 80059ffb30fSJeff Kirsher port_found: 80159ffb30fSJeff Kirsher 80259ffb30fSJeff Kirsher /**************** 80359ffb30fSJeff Kirsher * Now allocate an interrupt line. Note that this does not 80459ffb30fSJeff Kirsher * actually assign a handler to the interrupt. 80559ffb30fSJeff Kirsher */ 80659ffb30fSJeff Kirsher if ((err=pcmcia_request_irq(link, xirc2ps_interrupt))) 80759ffb30fSJeff Kirsher goto config_error; 80859ffb30fSJeff Kirsher 80959ffb30fSJeff Kirsher link->config_flags |= CONF_ENABLE_IRQ; 81059ffb30fSJeff Kirsher if (do_sound) 81159ffb30fSJeff Kirsher link->config_flags |= CONF_ENABLE_SPKR; 81259ffb30fSJeff Kirsher 81359ffb30fSJeff Kirsher if ((err = pcmcia_enable_device(link))) 81459ffb30fSJeff Kirsher goto config_error; 81559ffb30fSJeff Kirsher 81659ffb30fSJeff Kirsher if (local->dingo) { 81759ffb30fSJeff Kirsher /* Reset the modem's BAR to the correct value 81859ffb30fSJeff Kirsher * This is necessary because in the RequestConfiguration call, 81959ffb30fSJeff Kirsher * the base address of the ethernet port (BasePort1) is written 82059ffb30fSJeff Kirsher * to the BAR registers of the modem. 82159ffb30fSJeff Kirsher */ 82259ffb30fSJeff Kirsher err = pcmcia_write_config_byte(link, CISREG_IOBASE_0, (u8) 82359ffb30fSJeff Kirsher link->resource[1]->start & 0xff); 82459ffb30fSJeff Kirsher if (err) 82559ffb30fSJeff Kirsher goto config_error; 82659ffb30fSJeff Kirsher 82759ffb30fSJeff Kirsher err = pcmcia_write_config_byte(link, CISREG_IOBASE_1, 82859ffb30fSJeff Kirsher (link->resource[1]->start >> 8) & 0xff); 82959ffb30fSJeff Kirsher if (err) 83059ffb30fSJeff Kirsher goto config_error; 83159ffb30fSJeff Kirsher 83259ffb30fSJeff Kirsher /* There is no config entry for the Ethernet part which 83359ffb30fSJeff Kirsher * is at 0x0800. So we allocate a window into the attribute 83459ffb30fSJeff Kirsher * memory and write direct to the CIS registers 83559ffb30fSJeff Kirsher */ 83659ffb30fSJeff Kirsher link->resource[2]->flags = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | 83759ffb30fSJeff Kirsher WIN_ENABLE; 83859ffb30fSJeff Kirsher link->resource[2]->start = link->resource[2]->end = 0; 83959ffb30fSJeff Kirsher if ((err = pcmcia_request_window(link, link->resource[2], 0))) 84059ffb30fSJeff Kirsher goto config_error; 84159ffb30fSJeff Kirsher 84259ffb30fSJeff Kirsher local->dingo_ccr = ioremap(link->resource[2]->start, 0x1000) + 0x0800; 84359ffb30fSJeff Kirsher if ((err = pcmcia_map_mem_page(link, link->resource[2], 0))) 84459ffb30fSJeff Kirsher goto config_error; 84559ffb30fSJeff Kirsher 84659ffb30fSJeff Kirsher /* Setup the CCRs; there are no infos in the CIS about the Ethernet 84759ffb30fSJeff Kirsher * part. 84859ffb30fSJeff Kirsher */ 84959ffb30fSJeff Kirsher writeb(0x47, local->dingo_ccr + CISREG_COR); 85059ffb30fSJeff Kirsher ioaddr = link->resource[0]->start; 85159ffb30fSJeff Kirsher writeb(ioaddr & 0xff , local->dingo_ccr + CISREG_IOBASE_0); 85259ffb30fSJeff Kirsher writeb((ioaddr >> 8)&0xff , local->dingo_ccr + CISREG_IOBASE_1); 85359ffb30fSJeff Kirsher 85459ffb30fSJeff Kirsher #if 0 85559ffb30fSJeff Kirsher { 85659ffb30fSJeff Kirsher u_char tmp; 85759ffb30fSJeff Kirsher pr_info("ECOR:"); 85859ffb30fSJeff Kirsher for (i=0; i < 7; i++) { 85959ffb30fSJeff Kirsher tmp = readb(local->dingo_ccr + i*2); 86059ffb30fSJeff Kirsher pr_cont(" %02x", tmp); 86159ffb30fSJeff Kirsher } 86259ffb30fSJeff Kirsher pr_cont("\n"); 86359ffb30fSJeff Kirsher pr_info("DCOR:"); 86459ffb30fSJeff Kirsher for (i=0; i < 4; i++) { 86559ffb30fSJeff Kirsher tmp = readb(local->dingo_ccr + 0x20 + i*2); 86659ffb30fSJeff Kirsher pr_cont(" %02x", tmp); 86759ffb30fSJeff Kirsher } 86859ffb30fSJeff Kirsher pr_cont("\n"); 86959ffb30fSJeff Kirsher pr_info("SCOR:"); 87059ffb30fSJeff Kirsher for (i=0; i < 10; i++) { 87159ffb30fSJeff Kirsher tmp = readb(local->dingo_ccr + 0x40 + i*2); 87259ffb30fSJeff Kirsher pr_cont(" %02x", tmp); 87359ffb30fSJeff Kirsher } 87459ffb30fSJeff Kirsher pr_cont("\n"); 87559ffb30fSJeff Kirsher } 87659ffb30fSJeff Kirsher #endif 87759ffb30fSJeff Kirsher 87859ffb30fSJeff Kirsher writeb(0x01, local->dingo_ccr + 0x20); 87959ffb30fSJeff Kirsher writeb(0x0c, local->dingo_ccr + 0x22); 88059ffb30fSJeff Kirsher writeb(0x00, local->dingo_ccr + 0x24); 88159ffb30fSJeff Kirsher writeb(0x00, local->dingo_ccr + 0x26); 88259ffb30fSJeff Kirsher writeb(0x00, local->dingo_ccr + 0x28); 88359ffb30fSJeff Kirsher } 88459ffb30fSJeff Kirsher 88559ffb30fSJeff Kirsher /* The if_port symbol can be set when the module is loaded */ 88659ffb30fSJeff Kirsher local->probe_port=0; 88759ffb30fSJeff Kirsher if (!if_port) { 88859ffb30fSJeff Kirsher local->probe_port = dev->if_port = 1; 88959ffb30fSJeff Kirsher } else if ((if_port >= 1 && if_port <= 2) || 89059ffb30fSJeff Kirsher (local->mohawk && if_port==4)) 89159ffb30fSJeff Kirsher dev->if_port = if_port; 89259ffb30fSJeff Kirsher else 89359ffb30fSJeff Kirsher pr_notice("invalid if_port requested\n"); 89459ffb30fSJeff Kirsher 89559ffb30fSJeff Kirsher /* we can now register the device with the net subsystem */ 89659ffb30fSJeff Kirsher dev->irq = link->irq; 89759ffb30fSJeff Kirsher dev->base_addr = link->resource[0]->start; 89859ffb30fSJeff Kirsher 89959ffb30fSJeff Kirsher if (local->dingo) 90059ffb30fSJeff Kirsher do_reset(dev, 1); /* a kludge to make the cem56 work */ 90159ffb30fSJeff Kirsher 90259ffb30fSJeff Kirsher SET_NETDEV_DEV(dev, &link->dev); 90359ffb30fSJeff Kirsher 90459ffb30fSJeff Kirsher if ((err=register_netdev(dev))) { 90559ffb30fSJeff Kirsher pr_notice("register_netdev() failed\n"); 90659ffb30fSJeff Kirsher goto config_error; 90759ffb30fSJeff Kirsher } 90859ffb30fSJeff Kirsher 90959ffb30fSJeff Kirsher /* give some infos about the hardware */ 91059ffb30fSJeff Kirsher netdev_info(dev, "%s: port %#3lx, irq %d, hwaddr %pM\n", 91159ffb30fSJeff Kirsher local->manf_str, (u_long)dev->base_addr, (int)dev->irq, 91259ffb30fSJeff Kirsher dev->dev_addr); 91359ffb30fSJeff Kirsher 91459ffb30fSJeff Kirsher return 0; 91559ffb30fSJeff Kirsher 91659ffb30fSJeff Kirsher config_error: 91759ffb30fSJeff Kirsher xirc2ps_release(link); 91859ffb30fSJeff Kirsher return -ENODEV; 91959ffb30fSJeff Kirsher 92059ffb30fSJeff Kirsher failure: 92159ffb30fSJeff Kirsher return -ENODEV; 92259ffb30fSJeff Kirsher } /* xirc2ps_config */ 92359ffb30fSJeff Kirsher 92459ffb30fSJeff Kirsher static void 92559ffb30fSJeff Kirsher xirc2ps_release(struct pcmcia_device *link) 92659ffb30fSJeff Kirsher { 92759ffb30fSJeff Kirsher dev_dbg(&link->dev, "release\n"); 92859ffb30fSJeff Kirsher 92959ffb30fSJeff Kirsher if (link->resource[2]->end) { 93059ffb30fSJeff Kirsher struct net_device *dev = link->priv; 931f8653464SHimangi Saraogi struct local_info *local = netdev_priv(dev); 93259ffb30fSJeff Kirsher if (local->dingo) 93359ffb30fSJeff Kirsher iounmap(local->dingo_ccr - 0x0800); 93459ffb30fSJeff Kirsher } 93559ffb30fSJeff Kirsher pcmcia_disable_device(link); 93659ffb30fSJeff Kirsher } /* xirc2ps_release */ 93759ffb30fSJeff Kirsher 93859ffb30fSJeff Kirsher /*====================================================================*/ 93959ffb30fSJeff Kirsher 94059ffb30fSJeff Kirsher 94159ffb30fSJeff Kirsher static int xirc2ps_suspend(struct pcmcia_device *link) 94259ffb30fSJeff Kirsher { 94359ffb30fSJeff Kirsher struct net_device *dev = link->priv; 94459ffb30fSJeff Kirsher 94559ffb30fSJeff Kirsher if (link->open) { 94659ffb30fSJeff Kirsher netif_device_detach(dev); 94759ffb30fSJeff Kirsher do_powerdown(dev); 94859ffb30fSJeff Kirsher } 94959ffb30fSJeff Kirsher 95059ffb30fSJeff Kirsher return 0; 95159ffb30fSJeff Kirsher } 95259ffb30fSJeff Kirsher 95359ffb30fSJeff Kirsher static int xirc2ps_resume(struct pcmcia_device *link) 95459ffb30fSJeff Kirsher { 95559ffb30fSJeff Kirsher struct net_device *dev = link->priv; 95659ffb30fSJeff Kirsher 95759ffb30fSJeff Kirsher if (link->open) { 95859ffb30fSJeff Kirsher do_reset(dev,1); 95959ffb30fSJeff Kirsher netif_device_attach(dev); 96059ffb30fSJeff Kirsher } 96159ffb30fSJeff Kirsher 96259ffb30fSJeff Kirsher return 0; 96359ffb30fSJeff Kirsher } 96459ffb30fSJeff Kirsher 96559ffb30fSJeff Kirsher 96659ffb30fSJeff Kirsher /*====================================================================*/ 96759ffb30fSJeff Kirsher 96859ffb30fSJeff Kirsher /**************** 96959ffb30fSJeff Kirsher * This is the Interrupt service route. 97059ffb30fSJeff Kirsher */ 97159ffb30fSJeff Kirsher static irqreturn_t 97259ffb30fSJeff Kirsher xirc2ps_interrupt(int irq, void *dev_id) 97359ffb30fSJeff Kirsher { 97459ffb30fSJeff Kirsher struct net_device *dev = (struct net_device *)dev_id; 975f8653464SHimangi Saraogi struct local_info *lp = netdev_priv(dev); 97659ffb30fSJeff Kirsher unsigned int ioaddr; 97759ffb30fSJeff Kirsher u_char saved_page; 97859ffb30fSJeff Kirsher unsigned bytes_rcvd; 97959ffb30fSJeff Kirsher unsigned int_status, eth_status, rx_status, tx_status; 98059ffb30fSJeff Kirsher unsigned rsr, pktlen; 98159ffb30fSJeff Kirsher ulong start_ticks = jiffies; /* fixme: jiffies rollover every 497 days 98259ffb30fSJeff Kirsher * is this something to worry about? 98359ffb30fSJeff Kirsher * -- on a laptop? 98459ffb30fSJeff Kirsher */ 98559ffb30fSJeff Kirsher 98659ffb30fSJeff Kirsher if (!netif_device_present(dev)) 98759ffb30fSJeff Kirsher return IRQ_HANDLED; 98859ffb30fSJeff Kirsher 98959ffb30fSJeff Kirsher ioaddr = dev->base_addr; 99059ffb30fSJeff Kirsher if (lp->mohawk) { /* must disable the interrupt */ 99159ffb30fSJeff Kirsher PutByte(XIRCREG_CR, 0); 99259ffb30fSJeff Kirsher } 99359ffb30fSJeff Kirsher 99459ffb30fSJeff Kirsher pr_debug("%s: interrupt %d at %#x.\n", dev->name, irq, ioaddr); 99559ffb30fSJeff Kirsher 99659ffb30fSJeff Kirsher saved_page = GetByte(XIRCREG_PR); 99759ffb30fSJeff Kirsher /* Read the ISR to see whats the cause for the interrupt. 99859ffb30fSJeff Kirsher * This also clears the interrupt flags on CE2 cards 99959ffb30fSJeff Kirsher */ 100059ffb30fSJeff Kirsher int_status = GetByte(XIRCREG_ISR); 100159ffb30fSJeff Kirsher bytes_rcvd = 0; 100259ffb30fSJeff Kirsher loop_entry: 100359ffb30fSJeff Kirsher if (int_status == 0xff) { /* card may be ejected */ 100459ffb30fSJeff Kirsher pr_debug("%s: interrupt %d for dead card\n", dev->name, irq); 100559ffb30fSJeff Kirsher goto leave; 100659ffb30fSJeff Kirsher } 100759ffb30fSJeff Kirsher eth_status = GetByte(XIRCREG_ESR); 100859ffb30fSJeff Kirsher 100959ffb30fSJeff Kirsher SelectPage(0x40); 101059ffb30fSJeff Kirsher rx_status = GetByte(XIRCREG40_RXST0); 101159ffb30fSJeff Kirsher PutByte(XIRCREG40_RXST0, (~rx_status & 0xff)); 101259ffb30fSJeff Kirsher tx_status = GetByte(XIRCREG40_TXST0); 101359ffb30fSJeff Kirsher tx_status |= GetByte(XIRCREG40_TXST1) << 8; 101459ffb30fSJeff Kirsher PutByte(XIRCREG40_TXST0, 0); 101559ffb30fSJeff Kirsher PutByte(XIRCREG40_TXST1, 0); 101659ffb30fSJeff Kirsher 101759ffb30fSJeff Kirsher pr_debug("%s: ISR=%#2.2x ESR=%#2.2x RSR=%#2.2x TSR=%#4.4x\n", 101859ffb30fSJeff Kirsher dev->name, int_status, eth_status, rx_status, tx_status); 101959ffb30fSJeff Kirsher 102059ffb30fSJeff Kirsher /***** receive section ******/ 102159ffb30fSJeff Kirsher SelectPage(0); 102259ffb30fSJeff Kirsher while (eth_status & FullPktRcvd) { 102359ffb30fSJeff Kirsher rsr = GetByte(XIRCREG0_RSR); 102459ffb30fSJeff Kirsher if (bytes_rcvd > maxrx_bytes && (rsr & PktRxOk)) { 102559ffb30fSJeff Kirsher /* too many bytes received during this int, drop the rest of the 102659ffb30fSJeff Kirsher * packets */ 102759ffb30fSJeff Kirsher dev->stats.rx_dropped++; 102859ffb30fSJeff Kirsher pr_debug("%s: RX drop, too much done\n", dev->name); 102959ffb30fSJeff Kirsher } else if (rsr & PktRxOk) { 103059ffb30fSJeff Kirsher struct sk_buff *skb; 103159ffb30fSJeff Kirsher 103259ffb30fSJeff Kirsher pktlen = GetWord(XIRCREG0_RBC); 103359ffb30fSJeff Kirsher bytes_rcvd += pktlen; 103459ffb30fSJeff Kirsher 103559ffb30fSJeff Kirsher pr_debug("rsr=%#02x packet_length=%u\n", rsr, pktlen); 103659ffb30fSJeff Kirsher 1037dae2e9f4SPradeep A. Dalvi /* 1 extra so we can use insw */ 1038dae2e9f4SPradeep A. Dalvi skb = netdev_alloc_skb(dev, pktlen + 3); 103959ffb30fSJeff Kirsher if (!skb) { 104059ffb30fSJeff Kirsher dev->stats.rx_dropped++; 104159ffb30fSJeff Kirsher } else { /* okay get the packet */ 104259ffb30fSJeff Kirsher skb_reserve(skb, 2); 104359ffb30fSJeff Kirsher if (lp->silicon == 0 ) { /* work around a hardware bug */ 104459ffb30fSJeff Kirsher unsigned rhsa; /* receive start address */ 104559ffb30fSJeff Kirsher 104659ffb30fSJeff Kirsher SelectPage(5); 104759ffb30fSJeff Kirsher rhsa = GetWord(XIRCREG5_RHSA0); 104859ffb30fSJeff Kirsher SelectPage(0); 104959ffb30fSJeff Kirsher rhsa += 3; /* skip control infos */ 105059ffb30fSJeff Kirsher if (rhsa >= 0x8000) 105159ffb30fSJeff Kirsher rhsa = 0; 105259ffb30fSJeff Kirsher if (rhsa + pktlen > 0x8000) { 105359ffb30fSJeff Kirsher unsigned i; 105459ffb30fSJeff Kirsher u_char *buf = skb_put(skb, pktlen); 105559ffb30fSJeff Kirsher for (i=0; i < pktlen ; i++, rhsa++) { 105659ffb30fSJeff Kirsher buf[i] = GetByte(XIRCREG_EDP); 105759ffb30fSJeff Kirsher if (rhsa == 0x8000) { 105859ffb30fSJeff Kirsher rhsa = 0; 105959ffb30fSJeff Kirsher i--; 106059ffb30fSJeff Kirsher } 106159ffb30fSJeff Kirsher } 106259ffb30fSJeff Kirsher } else { 106359ffb30fSJeff Kirsher insw(ioaddr+XIRCREG_EDP, 106459ffb30fSJeff Kirsher skb_put(skb, pktlen), (pktlen+1)>>1); 106559ffb30fSJeff Kirsher } 106659ffb30fSJeff Kirsher } 106759ffb30fSJeff Kirsher #if 0 106859ffb30fSJeff Kirsher else if (lp->mohawk) { 106959ffb30fSJeff Kirsher /* To use this 32 bit access we should use 107059ffb30fSJeff Kirsher * a manual optimized loop 107159ffb30fSJeff Kirsher * Also the words are swapped, we can get more 107259ffb30fSJeff Kirsher * performance by using 32 bit access and swapping 107359ffb30fSJeff Kirsher * the words in a register. Will need this for cardbus 107459ffb30fSJeff Kirsher * 107559ffb30fSJeff Kirsher * Note: don't forget to change the ALLOC_SKB to .. +3 107659ffb30fSJeff Kirsher */ 107759ffb30fSJeff Kirsher unsigned i; 107859ffb30fSJeff Kirsher u_long *p = skb_put(skb, pktlen); 107959ffb30fSJeff Kirsher register u_long a; 108059ffb30fSJeff Kirsher unsigned int edpreg = ioaddr+XIRCREG_EDP-2; 108159ffb30fSJeff Kirsher for (i=0; i < len ; i += 4, p++) { 108259ffb30fSJeff Kirsher a = inl(edpreg); 108359ffb30fSJeff Kirsher __asm__("rorl $16,%0\n\t" 108459ffb30fSJeff Kirsher :"=q" (a) 108559ffb30fSJeff Kirsher : "0" (a)); 108659ffb30fSJeff Kirsher *p = a; 108759ffb30fSJeff Kirsher } 108859ffb30fSJeff Kirsher } 108959ffb30fSJeff Kirsher #endif 109059ffb30fSJeff Kirsher else { 109159ffb30fSJeff Kirsher insw(ioaddr+XIRCREG_EDP, skb_put(skb, pktlen), 109259ffb30fSJeff Kirsher (pktlen+1)>>1); 109359ffb30fSJeff Kirsher } 109459ffb30fSJeff Kirsher skb->protocol = eth_type_trans(skb, dev); 109559ffb30fSJeff Kirsher netif_rx(skb); 109659ffb30fSJeff Kirsher dev->stats.rx_packets++; 109759ffb30fSJeff Kirsher dev->stats.rx_bytes += pktlen; 109859ffb30fSJeff Kirsher if (!(rsr & PhyPkt)) 109959ffb30fSJeff Kirsher dev->stats.multicast++; 110059ffb30fSJeff Kirsher } 110159ffb30fSJeff Kirsher } else { /* bad packet */ 110259ffb30fSJeff Kirsher pr_debug("rsr=%#02x\n", rsr); 110359ffb30fSJeff Kirsher } 110459ffb30fSJeff Kirsher if (rsr & PktTooLong) { 110559ffb30fSJeff Kirsher dev->stats.rx_frame_errors++; 110659ffb30fSJeff Kirsher pr_debug("%s: Packet too long\n", dev->name); 110759ffb30fSJeff Kirsher } 110859ffb30fSJeff Kirsher if (rsr & CRCErr) { 110959ffb30fSJeff Kirsher dev->stats.rx_crc_errors++; 111059ffb30fSJeff Kirsher pr_debug("%s: CRC error\n", dev->name); 111159ffb30fSJeff Kirsher } 111259ffb30fSJeff Kirsher if (rsr & AlignErr) { 111359ffb30fSJeff Kirsher dev->stats.rx_fifo_errors++; /* okay ? */ 111459ffb30fSJeff Kirsher pr_debug("%s: Alignment error\n", dev->name); 111559ffb30fSJeff Kirsher } 111659ffb30fSJeff Kirsher 111759ffb30fSJeff Kirsher /* clear the received/dropped/error packet */ 111859ffb30fSJeff Kirsher PutWord(XIRCREG0_DO, 0x8000); /* issue cmd: skip_rx_packet */ 111959ffb30fSJeff Kirsher 112059ffb30fSJeff Kirsher /* get the new ethernet status */ 112159ffb30fSJeff Kirsher eth_status = GetByte(XIRCREG_ESR); 112259ffb30fSJeff Kirsher } 112359ffb30fSJeff Kirsher if (rx_status & 0x10) { /* Receive overrun */ 112459ffb30fSJeff Kirsher dev->stats.rx_over_errors++; 112559ffb30fSJeff Kirsher PutByte(XIRCREG_CR, ClearRxOvrun); 112659ffb30fSJeff Kirsher pr_debug("receive overrun cleared\n"); 112759ffb30fSJeff Kirsher } 112859ffb30fSJeff Kirsher 112959ffb30fSJeff Kirsher /***** transmit section ******/ 113059ffb30fSJeff Kirsher if (int_status & PktTxed) { 113159ffb30fSJeff Kirsher unsigned n, nn; 113259ffb30fSJeff Kirsher 113359ffb30fSJeff Kirsher n = lp->last_ptr_value; 113459ffb30fSJeff Kirsher nn = GetByte(XIRCREG0_PTR); 113559ffb30fSJeff Kirsher lp->last_ptr_value = nn; 113659ffb30fSJeff Kirsher if (nn < n) /* rollover */ 113759ffb30fSJeff Kirsher dev->stats.tx_packets += 256 - n; 113859ffb30fSJeff Kirsher else if (n == nn) { /* happens sometimes - don't know why */ 113959ffb30fSJeff Kirsher pr_debug("PTR not changed?\n"); 114059ffb30fSJeff Kirsher } else 114159ffb30fSJeff Kirsher dev->stats.tx_packets += lp->last_ptr_value - n; 114259ffb30fSJeff Kirsher netif_wake_queue(dev); 114359ffb30fSJeff Kirsher } 1144ac5fd4f4SColin Ian King if (tx_status & 0x0002) { /* Excessive collisions */ 1145ac5fd4f4SColin Ian King pr_debug("tx restarted due to excessive collisions\n"); 114659ffb30fSJeff Kirsher PutByte(XIRCREG_CR, RestartTx); /* restart transmitter process */ 114759ffb30fSJeff Kirsher } 114859ffb30fSJeff Kirsher if (tx_status & 0x0040) 114959ffb30fSJeff Kirsher dev->stats.tx_aborted_errors++; 115059ffb30fSJeff Kirsher 115159ffb30fSJeff Kirsher /* recalculate our work chunk so that we limit the duration of this 115259ffb30fSJeff Kirsher * ISR to about 1/10 of a second. 115359ffb30fSJeff Kirsher * Calculate only if we received a reasonable amount of bytes. 115459ffb30fSJeff Kirsher */ 115559ffb30fSJeff Kirsher if (bytes_rcvd > 1000) { 115659ffb30fSJeff Kirsher u_long duration = jiffies - start_ticks; 115759ffb30fSJeff Kirsher 115859ffb30fSJeff Kirsher if (duration >= HZ/10) { /* if more than about 1/10 second */ 115959ffb30fSJeff Kirsher maxrx_bytes = (bytes_rcvd * (HZ/10)) / duration; 116059ffb30fSJeff Kirsher if (maxrx_bytes < 2000) 116159ffb30fSJeff Kirsher maxrx_bytes = 2000; 116259ffb30fSJeff Kirsher else if (maxrx_bytes > 22000) 116359ffb30fSJeff Kirsher maxrx_bytes = 22000; 116459ffb30fSJeff Kirsher pr_debug("set maxrx=%u (rcvd=%u ticks=%lu)\n", 116559ffb30fSJeff Kirsher maxrx_bytes, bytes_rcvd, duration); 116659ffb30fSJeff Kirsher } else if (!duration && maxrx_bytes < 22000) { 116759ffb30fSJeff Kirsher /* now much faster */ 116859ffb30fSJeff Kirsher maxrx_bytes += 2000; 116959ffb30fSJeff Kirsher if (maxrx_bytes > 22000) 117059ffb30fSJeff Kirsher maxrx_bytes = 22000; 117159ffb30fSJeff Kirsher pr_debug("set maxrx=%u\n", maxrx_bytes); 117259ffb30fSJeff Kirsher } 117359ffb30fSJeff Kirsher } 117459ffb30fSJeff Kirsher 117559ffb30fSJeff Kirsher leave: 117659ffb30fSJeff Kirsher if (lockup_hack) { 117759ffb30fSJeff Kirsher if (int_status != 0xff && (int_status = GetByte(XIRCREG_ISR)) != 0) 117859ffb30fSJeff Kirsher goto loop_entry; 117959ffb30fSJeff Kirsher } 118059ffb30fSJeff Kirsher SelectPage(saved_page); 118159ffb30fSJeff Kirsher PutByte(XIRCREG_CR, EnableIntr); /* re-enable interrupts */ 118259ffb30fSJeff Kirsher /* Instead of dropping packets during a receive, we could 118359ffb30fSJeff Kirsher * force an interrupt with this command: 118459ffb30fSJeff Kirsher * PutByte(XIRCREG_CR, EnableIntr|ForceIntr); 118559ffb30fSJeff Kirsher */ 118659ffb30fSJeff Kirsher return IRQ_HANDLED; 118759ffb30fSJeff Kirsher } /* xirc2ps_interrupt */ 118859ffb30fSJeff Kirsher 118959ffb30fSJeff Kirsher /*====================================================================*/ 119059ffb30fSJeff Kirsher 119159ffb30fSJeff Kirsher static void 119259ffb30fSJeff Kirsher xirc2ps_tx_timeout_task(struct work_struct *work) 119359ffb30fSJeff Kirsher { 1194f8653464SHimangi Saraogi struct local_info *local = 1195f8653464SHimangi Saraogi container_of(work, struct local_info, tx_timeout_task); 119659ffb30fSJeff Kirsher struct net_device *dev = local->dev; 119759ffb30fSJeff Kirsher /* reset the card */ 119859ffb30fSJeff Kirsher do_reset(dev,1); 1199860e9538SFlorian Westphal netif_trans_update(dev); /* prevent tx timeout */ 120059ffb30fSJeff Kirsher netif_wake_queue(dev); 120159ffb30fSJeff Kirsher } 120259ffb30fSJeff Kirsher 120359ffb30fSJeff Kirsher static void 12040290bd29SMichael S. Tsirkin xirc_tx_timeout(struct net_device *dev, unsigned int txqueue) 120559ffb30fSJeff Kirsher { 1206f8653464SHimangi Saraogi struct local_info *lp = netdev_priv(dev); 120759ffb30fSJeff Kirsher dev->stats.tx_errors++; 120859ffb30fSJeff Kirsher netdev_notice(dev, "transmit timed out\n"); 120959ffb30fSJeff Kirsher schedule_work(&lp->tx_timeout_task); 121059ffb30fSJeff Kirsher } 121159ffb30fSJeff Kirsher 121259ffb30fSJeff Kirsher static netdev_tx_t 121359ffb30fSJeff Kirsher do_start_xmit(struct sk_buff *skb, struct net_device *dev) 121459ffb30fSJeff Kirsher { 1215f8653464SHimangi Saraogi struct local_info *lp = netdev_priv(dev); 121659ffb30fSJeff Kirsher unsigned int ioaddr = dev->base_addr; 121759ffb30fSJeff Kirsher int okay; 121859ffb30fSJeff Kirsher unsigned freespace; 121959ffb30fSJeff Kirsher unsigned pktlen = skb->len; 122059ffb30fSJeff Kirsher 122159ffb30fSJeff Kirsher pr_debug("do_start_xmit(skb=%p, dev=%p) len=%u\n", 122259ffb30fSJeff Kirsher skb, dev, pktlen); 122359ffb30fSJeff Kirsher 122459ffb30fSJeff Kirsher 122559ffb30fSJeff Kirsher /* adjust the packet length to min. required 122659ffb30fSJeff Kirsher * and hope that the buffer is large enough 122759ffb30fSJeff Kirsher * to provide some random data. 122859ffb30fSJeff Kirsher * fixme: For Mohawk we can change this by sending 122959ffb30fSJeff Kirsher * a larger packetlen than we actually have; the chip will 123059ffb30fSJeff Kirsher * pad this in his buffer with random bytes 123159ffb30fSJeff Kirsher */ 123259ffb30fSJeff Kirsher if (pktlen < ETH_ZLEN) 123359ffb30fSJeff Kirsher { 123459ffb30fSJeff Kirsher if (skb_padto(skb, ETH_ZLEN)) 123559ffb30fSJeff Kirsher return NETDEV_TX_OK; 123659ffb30fSJeff Kirsher pktlen = ETH_ZLEN; 123759ffb30fSJeff Kirsher } 123859ffb30fSJeff Kirsher 123959ffb30fSJeff Kirsher netif_stop_queue(dev); 124059ffb30fSJeff Kirsher SelectPage(0); 124159ffb30fSJeff Kirsher PutWord(XIRCREG0_TRS, (u_short)pktlen+2); 124259ffb30fSJeff Kirsher freespace = GetWord(XIRCREG0_TSO); 124359ffb30fSJeff Kirsher okay = freespace & 0x8000; 124459ffb30fSJeff Kirsher freespace &= 0x7fff; 124559ffb30fSJeff Kirsher /* TRS doesn't work - (indeed it is eliminated with sil-rev 1) */ 124659ffb30fSJeff Kirsher okay = pktlen +2 < freespace; 124759ffb30fSJeff Kirsher pr_debug("%s: avail. tx space=%u%s\n", 124859ffb30fSJeff Kirsher dev->name, freespace, okay ? " (okay)":" (not enough)"); 124959ffb30fSJeff Kirsher if (!okay) { /* not enough space */ 125059ffb30fSJeff Kirsher return NETDEV_TX_BUSY; /* upper layer may decide to requeue this packet */ 125159ffb30fSJeff Kirsher } 125259ffb30fSJeff Kirsher /* send the packet */ 125359ffb30fSJeff Kirsher PutWord(XIRCREG_EDP, (u_short)pktlen); 125459ffb30fSJeff Kirsher outsw(ioaddr+XIRCREG_EDP, skb->data, pktlen>>1); 125559ffb30fSJeff Kirsher if (pktlen & 1) 125659ffb30fSJeff Kirsher PutByte(XIRCREG_EDP, skb->data[pktlen-1]); 125759ffb30fSJeff Kirsher 125859ffb30fSJeff Kirsher if (lp->mohawk) 125959ffb30fSJeff Kirsher PutByte(XIRCREG_CR, TransmitPacket|EnableIntr); 126059ffb30fSJeff Kirsher 126159ffb30fSJeff Kirsher dev_kfree_skb (skb); 126259ffb30fSJeff Kirsher dev->stats.tx_bytes += pktlen; 126359ffb30fSJeff Kirsher netif_start_queue(dev); 126459ffb30fSJeff Kirsher return NETDEV_TX_OK; 126559ffb30fSJeff Kirsher } 126659ffb30fSJeff Kirsher 126759ffb30fSJeff Kirsher struct set_address_info { 126859ffb30fSJeff Kirsher int reg_nr; 126959ffb30fSJeff Kirsher int page_nr; 127059ffb30fSJeff Kirsher int mohawk; 127159ffb30fSJeff Kirsher unsigned int ioaddr; 127259ffb30fSJeff Kirsher }; 127359ffb30fSJeff Kirsher 1274*76660757SJakub Kicinski static void set_address(struct set_address_info *sa_info, const char *addr) 127559ffb30fSJeff Kirsher { 127659ffb30fSJeff Kirsher unsigned int ioaddr = sa_info->ioaddr; 127759ffb30fSJeff Kirsher int i; 127859ffb30fSJeff Kirsher 127959ffb30fSJeff Kirsher for (i = 0; i < 6; i++) { 128059ffb30fSJeff Kirsher if (sa_info->reg_nr > 15) { 128159ffb30fSJeff Kirsher sa_info->reg_nr = 8; 128259ffb30fSJeff Kirsher sa_info->page_nr++; 128359ffb30fSJeff Kirsher SelectPage(sa_info->page_nr); 128459ffb30fSJeff Kirsher } 128559ffb30fSJeff Kirsher if (sa_info->mohawk) 128659ffb30fSJeff Kirsher PutByte(sa_info->reg_nr++, addr[5 - i]); 128759ffb30fSJeff Kirsher else 128859ffb30fSJeff Kirsher PutByte(sa_info->reg_nr++, addr[i]); 128959ffb30fSJeff Kirsher } 129059ffb30fSJeff Kirsher } 129159ffb30fSJeff Kirsher 129259ffb30fSJeff Kirsher /**************** 129359ffb30fSJeff Kirsher * Set all addresses: This first one is the individual address, 129459ffb30fSJeff Kirsher * the next 9 addresses are taken from the multicast list and 129559ffb30fSJeff Kirsher * the rest is filled with the individual address. 129659ffb30fSJeff Kirsher */ 129759ffb30fSJeff Kirsher static void set_addresses(struct net_device *dev) 129859ffb30fSJeff Kirsher { 129959ffb30fSJeff Kirsher unsigned int ioaddr = dev->base_addr; 1300f8653464SHimangi Saraogi struct local_info *lp = netdev_priv(dev); 130159ffb30fSJeff Kirsher struct netdev_hw_addr *ha; 130259ffb30fSJeff Kirsher struct set_address_info sa_info; 130359ffb30fSJeff Kirsher int i; 130459ffb30fSJeff Kirsher 130559ffb30fSJeff Kirsher /* 130659ffb30fSJeff Kirsher * Setup the info structure so that by first set_address call it will do 130759ffb30fSJeff Kirsher * SelectPage with the right page number. Hence these ones here. 130859ffb30fSJeff Kirsher */ 130959ffb30fSJeff Kirsher sa_info.reg_nr = 15 + 1; 131059ffb30fSJeff Kirsher sa_info.page_nr = 0x50 - 1; 131159ffb30fSJeff Kirsher sa_info.mohawk = lp->mohawk; 131259ffb30fSJeff Kirsher sa_info.ioaddr = ioaddr; 131359ffb30fSJeff Kirsher 131459ffb30fSJeff Kirsher set_address(&sa_info, dev->dev_addr); 131559ffb30fSJeff Kirsher i = 0; 131659ffb30fSJeff Kirsher netdev_for_each_mc_addr(ha, dev) { 131759ffb30fSJeff Kirsher if (i++ == 9) 131859ffb30fSJeff Kirsher break; 131959ffb30fSJeff Kirsher set_address(&sa_info, ha->addr); 132059ffb30fSJeff Kirsher } 132159ffb30fSJeff Kirsher while (i++ < 9) 132259ffb30fSJeff Kirsher set_address(&sa_info, dev->dev_addr); 132359ffb30fSJeff Kirsher SelectPage(0); 132459ffb30fSJeff Kirsher } 132559ffb30fSJeff Kirsher 132659ffb30fSJeff Kirsher /**************** 132759ffb30fSJeff Kirsher * Set or clear the multicast filter for this adaptor. 132859ffb30fSJeff Kirsher * We can filter up to 9 addresses, if more are requested we set 132959ffb30fSJeff Kirsher * multicast promiscuous mode. 133059ffb30fSJeff Kirsher */ 133159ffb30fSJeff Kirsher 133259ffb30fSJeff Kirsher static void 133359ffb30fSJeff Kirsher set_multicast_list(struct net_device *dev) 133459ffb30fSJeff Kirsher { 133559ffb30fSJeff Kirsher unsigned int ioaddr = dev->base_addr; 133659ffb30fSJeff Kirsher unsigned value; 133759ffb30fSJeff Kirsher 133859ffb30fSJeff Kirsher SelectPage(0x42); 133959ffb30fSJeff Kirsher value = GetByte(XIRCREG42_SWC1) & 0xC0; 134059ffb30fSJeff Kirsher 134159ffb30fSJeff Kirsher if (dev->flags & IFF_PROMISC) { /* snoop */ 134259ffb30fSJeff Kirsher PutByte(XIRCREG42_SWC1, value | 0x06); /* set MPE and PME */ 134359ffb30fSJeff Kirsher } else if (netdev_mc_count(dev) > 9 || (dev->flags & IFF_ALLMULTI)) { 134459ffb30fSJeff Kirsher PutByte(XIRCREG42_SWC1, value | 0x02); /* set MPE */ 134559ffb30fSJeff Kirsher } else if (!netdev_mc_empty(dev)) { 134659ffb30fSJeff Kirsher /* the chip can filter 9 addresses perfectly */ 134759ffb30fSJeff Kirsher PutByte(XIRCREG42_SWC1, value | 0x01); 134859ffb30fSJeff Kirsher SelectPage(0x40); 134959ffb30fSJeff Kirsher PutByte(XIRCREG40_CMD0, Offline); 135059ffb30fSJeff Kirsher set_addresses(dev); 135159ffb30fSJeff Kirsher SelectPage(0x40); 135259ffb30fSJeff Kirsher PutByte(XIRCREG40_CMD0, EnableRecv | Online); 135359ffb30fSJeff Kirsher } else { /* standard usage */ 135459ffb30fSJeff Kirsher PutByte(XIRCREG42_SWC1, value | 0x00); 135559ffb30fSJeff Kirsher } 135659ffb30fSJeff Kirsher SelectPage(0); 135759ffb30fSJeff Kirsher } 135859ffb30fSJeff Kirsher 135959ffb30fSJeff Kirsher static int 136059ffb30fSJeff Kirsher do_config(struct net_device *dev, struct ifmap *map) 136159ffb30fSJeff Kirsher { 1362f8653464SHimangi Saraogi struct local_info *local = netdev_priv(dev); 136359ffb30fSJeff Kirsher 136459ffb30fSJeff Kirsher pr_debug("do_config(%p)\n", dev); 136559ffb30fSJeff Kirsher if (map->port != 255 && map->port != dev->if_port) { 136659ffb30fSJeff Kirsher if (map->port > 4) 136759ffb30fSJeff Kirsher return -EINVAL; 136859ffb30fSJeff Kirsher if (!map->port) { 136959ffb30fSJeff Kirsher local->probe_port = 1; 137059ffb30fSJeff Kirsher dev->if_port = 1; 137159ffb30fSJeff Kirsher } else { 137259ffb30fSJeff Kirsher local->probe_port = 0; 137359ffb30fSJeff Kirsher dev->if_port = map->port; 137459ffb30fSJeff Kirsher } 137559ffb30fSJeff Kirsher netdev_info(dev, "switching to %s port\n", if_names[dev->if_port]); 137659ffb30fSJeff Kirsher do_reset(dev,1); /* not the fine way :-) */ 137759ffb30fSJeff Kirsher } 137859ffb30fSJeff Kirsher return 0; 137959ffb30fSJeff Kirsher } 138059ffb30fSJeff Kirsher 138159ffb30fSJeff Kirsher /**************** 138259ffb30fSJeff Kirsher * Open the driver 138359ffb30fSJeff Kirsher */ 138459ffb30fSJeff Kirsher static int 138559ffb30fSJeff Kirsher do_open(struct net_device *dev) 138659ffb30fSJeff Kirsher { 1387f8653464SHimangi Saraogi struct local_info *lp = netdev_priv(dev); 138859ffb30fSJeff Kirsher struct pcmcia_device *link = lp->p_dev; 138959ffb30fSJeff Kirsher 139059ffb30fSJeff Kirsher dev_dbg(&link->dev, "do_open(%p)\n", dev); 139159ffb30fSJeff Kirsher 139259ffb30fSJeff Kirsher /* Check that the PCMCIA card is still here. */ 139359ffb30fSJeff Kirsher /* Physical device present signature. */ 139459ffb30fSJeff Kirsher if (!pcmcia_dev_present(link)) 139559ffb30fSJeff Kirsher return -ENODEV; 139659ffb30fSJeff Kirsher 139759ffb30fSJeff Kirsher /* okay */ 139859ffb30fSJeff Kirsher link->open++; 139959ffb30fSJeff Kirsher 140059ffb30fSJeff Kirsher netif_start_queue(dev); 140159ffb30fSJeff Kirsher do_reset(dev,1); 140259ffb30fSJeff Kirsher 140359ffb30fSJeff Kirsher return 0; 140459ffb30fSJeff Kirsher } 140559ffb30fSJeff Kirsher 140659ffb30fSJeff Kirsher static void netdev_get_drvinfo(struct net_device *dev, 140759ffb30fSJeff Kirsher struct ethtool_drvinfo *info) 140859ffb30fSJeff Kirsher { 140968aad78cSRick Jones strlcpy(info->driver, "xirc2ps_cs", sizeof(info->driver)); 14107826d43fSJiri Pirko snprintf(info->bus_info, sizeof(info->bus_info), "PCMCIA 0x%lx", 14117826d43fSJiri Pirko dev->base_addr); 141259ffb30fSJeff Kirsher } 141359ffb30fSJeff Kirsher 141459ffb30fSJeff Kirsher static const struct ethtool_ops netdev_ethtool_ops = { 141559ffb30fSJeff Kirsher .get_drvinfo = netdev_get_drvinfo, 141659ffb30fSJeff Kirsher }; 141759ffb30fSJeff Kirsher 141859ffb30fSJeff Kirsher static int 141959ffb30fSJeff Kirsher do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 142059ffb30fSJeff Kirsher { 1421f8653464SHimangi Saraogi struct local_info *local = netdev_priv(dev); 142259ffb30fSJeff Kirsher unsigned int ioaddr = dev->base_addr; 142359ffb30fSJeff Kirsher struct mii_ioctl_data *data = if_mii(rq); 142459ffb30fSJeff Kirsher 142559ffb30fSJeff Kirsher pr_debug("%s: ioctl(%-.6s, %#04x) %04x %04x %04x %04x\n", 142659ffb30fSJeff Kirsher dev->name, rq->ifr_ifrn.ifrn_name, cmd, 142759ffb30fSJeff Kirsher data->phy_id, data->reg_num, data->val_in, data->val_out); 142859ffb30fSJeff Kirsher 142959ffb30fSJeff Kirsher if (!local->mohawk) 143059ffb30fSJeff Kirsher return -EOPNOTSUPP; 143159ffb30fSJeff Kirsher 143259ffb30fSJeff Kirsher switch(cmd) { 143359ffb30fSJeff Kirsher case SIOCGMIIPHY: /* Get the address of the PHY in use. */ 143459ffb30fSJeff Kirsher data->phy_id = 0; /* we have only this address */ 1435df561f66SGustavo A. R. Silva fallthrough; 143659ffb30fSJeff Kirsher case SIOCGMIIREG: /* Read the specified MII register. */ 143759ffb30fSJeff Kirsher data->val_out = mii_rd(ioaddr, data->phy_id & 0x1f, 143859ffb30fSJeff Kirsher data->reg_num & 0x1f); 143959ffb30fSJeff Kirsher break; 144059ffb30fSJeff Kirsher case SIOCSMIIREG: /* Write the specified MII register */ 144159ffb30fSJeff Kirsher mii_wr(ioaddr, data->phy_id & 0x1f, data->reg_num & 0x1f, data->val_in, 144259ffb30fSJeff Kirsher 16); 144359ffb30fSJeff Kirsher break; 144459ffb30fSJeff Kirsher default: 144559ffb30fSJeff Kirsher return -EOPNOTSUPP; 144659ffb30fSJeff Kirsher } 144759ffb30fSJeff Kirsher return 0; 144859ffb30fSJeff Kirsher } 144959ffb30fSJeff Kirsher 145059ffb30fSJeff Kirsher static void 145159ffb30fSJeff Kirsher hardreset(struct net_device *dev) 145259ffb30fSJeff Kirsher { 1453f8653464SHimangi Saraogi struct local_info *local = netdev_priv(dev); 145459ffb30fSJeff Kirsher unsigned int ioaddr = dev->base_addr; 145559ffb30fSJeff Kirsher 145659ffb30fSJeff Kirsher SelectPage(4); 145759ffb30fSJeff Kirsher udelay(1); 145859ffb30fSJeff Kirsher PutByte(XIRCREG4_GPR1, 0); /* clear bit 0: power down */ 145959ffb30fSJeff Kirsher msleep(40); /* wait 40 msec */ 146059ffb30fSJeff Kirsher if (local->mohawk) 146159ffb30fSJeff Kirsher PutByte(XIRCREG4_GPR1, 1); /* set bit 0: power up */ 146259ffb30fSJeff Kirsher else 146359ffb30fSJeff Kirsher PutByte(XIRCREG4_GPR1, 1 | 4); /* set bit 0: power up, bit 2: AIC */ 146459ffb30fSJeff Kirsher msleep(20); /* wait 20 msec */ 146559ffb30fSJeff Kirsher } 146659ffb30fSJeff Kirsher 146759ffb30fSJeff Kirsher static void 146859ffb30fSJeff Kirsher do_reset(struct net_device *dev, int full) 146959ffb30fSJeff Kirsher { 1470f8653464SHimangi Saraogi struct local_info *local = netdev_priv(dev); 147159ffb30fSJeff Kirsher unsigned int ioaddr = dev->base_addr; 147259ffb30fSJeff Kirsher unsigned value; 147359ffb30fSJeff Kirsher 14745777cbbaSGaurav Singh pr_debug("%s: do_reset(%p,%d)\n", dev->name, dev, full); 147559ffb30fSJeff Kirsher 147659ffb30fSJeff Kirsher hardreset(dev); 147759ffb30fSJeff Kirsher PutByte(XIRCREG_CR, SoftReset); /* set */ 147859ffb30fSJeff Kirsher msleep(20); /* wait 20 msec */ 147959ffb30fSJeff Kirsher PutByte(XIRCREG_CR, 0); /* clear */ 148059ffb30fSJeff Kirsher msleep(40); /* wait 40 msec */ 148159ffb30fSJeff Kirsher if (local->mohawk) { 148259ffb30fSJeff Kirsher SelectPage(4); 148359ffb30fSJeff Kirsher /* set pin GP1 and GP2 to output (0x0c) 148459ffb30fSJeff Kirsher * set GP1 to low to power up the ML6692 (0x00) 148559ffb30fSJeff Kirsher * set GP2 to high to power up the 10Mhz chip (0x02) 148659ffb30fSJeff Kirsher */ 148759ffb30fSJeff Kirsher PutByte(XIRCREG4_GPR0, 0x0e); 148859ffb30fSJeff Kirsher } 148959ffb30fSJeff Kirsher 149059ffb30fSJeff Kirsher /* give the circuits some time to power up */ 149159ffb30fSJeff Kirsher msleep(500); /* about 500ms */ 149259ffb30fSJeff Kirsher 149359ffb30fSJeff Kirsher local->last_ptr_value = 0; 149459ffb30fSJeff Kirsher local->silicon = local->mohawk ? (GetByte(XIRCREG4_BOV) & 0x70) >> 4 149559ffb30fSJeff Kirsher : (GetByte(XIRCREG4_BOV) & 0x30) >> 4; 149659ffb30fSJeff Kirsher 149759ffb30fSJeff Kirsher if (local->probe_port) { 149859ffb30fSJeff Kirsher if (!local->mohawk) { 149959ffb30fSJeff Kirsher SelectPage(4); 150059ffb30fSJeff Kirsher PutByte(XIRCREG4_GPR0, 4); 150159ffb30fSJeff Kirsher local->probe_port = 0; 150259ffb30fSJeff Kirsher } 150359ffb30fSJeff Kirsher } else if (dev->if_port == 2) { /* enable 10Base2 */ 150459ffb30fSJeff Kirsher SelectPage(0x42); 150559ffb30fSJeff Kirsher PutByte(XIRCREG42_SWC1, 0xC0); 150659ffb30fSJeff Kirsher } else { /* enable 10BaseT */ 150759ffb30fSJeff Kirsher SelectPage(0x42); 150859ffb30fSJeff Kirsher PutByte(XIRCREG42_SWC1, 0x80); 150959ffb30fSJeff Kirsher } 151059ffb30fSJeff Kirsher msleep(40); /* wait 40 msec to let it complete */ 151159ffb30fSJeff Kirsher 151259ffb30fSJeff Kirsher #if 0 151359ffb30fSJeff Kirsher { 151459ffb30fSJeff Kirsher SelectPage(0); 151559ffb30fSJeff Kirsher value = GetByte(XIRCREG_ESR); /* read the ESR */ 151659ffb30fSJeff Kirsher pr_debug("%s: ESR is: %#02x\n", dev->name, value); 151759ffb30fSJeff Kirsher } 151859ffb30fSJeff Kirsher #endif 151959ffb30fSJeff Kirsher 152059ffb30fSJeff Kirsher /* setup the ECR */ 152159ffb30fSJeff Kirsher SelectPage(1); 152259ffb30fSJeff Kirsher PutByte(XIRCREG1_IMR0, 0xff); /* allow all ints */ 152359ffb30fSJeff Kirsher PutByte(XIRCREG1_IMR1, 1 ); /* and Set TxUnderrunDetect */ 152459ffb30fSJeff Kirsher value = GetByte(XIRCREG1_ECR); 152559ffb30fSJeff Kirsher #if 0 152659ffb30fSJeff Kirsher if (local->mohawk) 152759ffb30fSJeff Kirsher value |= DisableLinkPulse; 152859ffb30fSJeff Kirsher PutByte(XIRCREG1_ECR, value); 152959ffb30fSJeff Kirsher #endif 153059ffb30fSJeff Kirsher pr_debug("%s: ECR is: %#02x\n", dev->name, value); 153159ffb30fSJeff Kirsher 153259ffb30fSJeff Kirsher SelectPage(0x42); 153359ffb30fSJeff Kirsher PutByte(XIRCREG42_SWC0, 0x20); /* disable source insertion */ 153459ffb30fSJeff Kirsher 153559ffb30fSJeff Kirsher if (local->silicon != 1) { 153659ffb30fSJeff Kirsher /* set the local memory dividing line. 153759ffb30fSJeff Kirsher * The comments in the sample code say that this is only 153859ffb30fSJeff Kirsher * settable with the scipper version 2 which is revision 0. 153959ffb30fSJeff Kirsher * Always for CE3 cards 154059ffb30fSJeff Kirsher */ 154159ffb30fSJeff Kirsher SelectPage(2); 154259ffb30fSJeff Kirsher PutWord(XIRCREG2_RBS, 0x2000); 154359ffb30fSJeff Kirsher } 154459ffb30fSJeff Kirsher 154559ffb30fSJeff Kirsher if (full) 154659ffb30fSJeff Kirsher set_addresses(dev); 154759ffb30fSJeff Kirsher 154859ffb30fSJeff Kirsher /* Hardware workaround: 154959ffb30fSJeff Kirsher * The receive byte pointer after reset is off by 1 so we need 155059ffb30fSJeff Kirsher * to move the offset pointer back to 0. 155159ffb30fSJeff Kirsher */ 155259ffb30fSJeff Kirsher SelectPage(0); 155359ffb30fSJeff Kirsher PutWord(XIRCREG0_DO, 0x2000); /* change offset command, off=0 */ 155459ffb30fSJeff Kirsher 155559ffb30fSJeff Kirsher /* setup MAC IMRs and clear status registers */ 155659ffb30fSJeff Kirsher SelectPage(0x40); /* Bit 7 ... bit 0 */ 155759ffb30fSJeff Kirsher PutByte(XIRCREG40_RMASK0, 0xff); /* ROK, RAB, rsv, RO, CRC, AE, PTL, MP */ 155859ffb30fSJeff Kirsher PutByte(XIRCREG40_TMASK0, 0xff); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */ 155959ffb30fSJeff Kirsher PutByte(XIRCREG40_TMASK1, 0xb0); /* rsv, rsv, PTD, EXT, rsv,rsv,rsv, rsv*/ 156059ffb30fSJeff Kirsher PutByte(XIRCREG40_RXST0, 0x00); /* ROK, RAB, REN, RO, CRC, AE, PTL, MP */ 156159ffb30fSJeff Kirsher PutByte(XIRCREG40_TXST0, 0x00); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */ 156259ffb30fSJeff Kirsher PutByte(XIRCREG40_TXST1, 0x00); /* TEN, rsv, PTD, EXT, retry_counter:4 */ 156359ffb30fSJeff Kirsher 156459ffb30fSJeff Kirsher if (full && local->mohawk && init_mii(dev)) { 156559ffb30fSJeff Kirsher if (dev->if_port == 4 || local->dingo || local->new_mii) { 156659ffb30fSJeff Kirsher netdev_info(dev, "MII selected\n"); 156759ffb30fSJeff Kirsher SelectPage(2); 156859ffb30fSJeff Kirsher PutByte(XIRCREG2_MSR, GetByte(XIRCREG2_MSR) | 0x08); 156959ffb30fSJeff Kirsher msleep(20); 157059ffb30fSJeff Kirsher } else { 157159ffb30fSJeff Kirsher netdev_info(dev, "MII detected; using 10mbs\n"); 157259ffb30fSJeff Kirsher SelectPage(0x42); 157359ffb30fSJeff Kirsher if (dev->if_port == 2) /* enable 10Base2 */ 157459ffb30fSJeff Kirsher PutByte(XIRCREG42_SWC1, 0xC0); 157559ffb30fSJeff Kirsher else /* enable 10BaseT */ 157659ffb30fSJeff Kirsher PutByte(XIRCREG42_SWC1, 0x80); 157759ffb30fSJeff Kirsher msleep(40); /* wait 40 msec to let it complete */ 157859ffb30fSJeff Kirsher } 157959ffb30fSJeff Kirsher if (full_duplex) 158059ffb30fSJeff Kirsher PutByte(XIRCREG1_ECR, GetByte(XIRCREG1_ECR | FullDuplex)); 158159ffb30fSJeff Kirsher } else { /* No MII */ 158259ffb30fSJeff Kirsher SelectPage(0); 158359ffb30fSJeff Kirsher value = GetByte(XIRCREG_ESR); /* read the ESR */ 158459ffb30fSJeff Kirsher dev->if_port = (value & MediaSelect) ? 1 : 2; 158559ffb30fSJeff Kirsher } 158659ffb30fSJeff Kirsher 158759ffb30fSJeff Kirsher /* configure the LEDs */ 158859ffb30fSJeff Kirsher SelectPage(2); 158959ffb30fSJeff Kirsher if (dev->if_port == 1 || dev->if_port == 4) /* TP: Link and Activity */ 159059ffb30fSJeff Kirsher PutByte(XIRCREG2_LED, 0x3b); 159159ffb30fSJeff Kirsher else /* Coax: Not-Collision and Activity */ 159259ffb30fSJeff Kirsher PutByte(XIRCREG2_LED, 0x3a); 159359ffb30fSJeff Kirsher 159459ffb30fSJeff Kirsher if (local->dingo) 159559ffb30fSJeff Kirsher PutByte(0x0b, 0x04); /* 100 Mbit LED */ 159659ffb30fSJeff Kirsher 159759ffb30fSJeff Kirsher /* enable receiver and put the mac online */ 159859ffb30fSJeff Kirsher if (full) { 159959ffb30fSJeff Kirsher set_multicast_list(dev); 160059ffb30fSJeff Kirsher SelectPage(0x40); 160159ffb30fSJeff Kirsher PutByte(XIRCREG40_CMD0, EnableRecv | Online); 160259ffb30fSJeff Kirsher } 160359ffb30fSJeff Kirsher 160459ffb30fSJeff Kirsher /* setup Ethernet IMR and enable interrupts */ 160559ffb30fSJeff Kirsher SelectPage(1); 160659ffb30fSJeff Kirsher PutByte(XIRCREG1_IMR0, 0xff); 160759ffb30fSJeff Kirsher udelay(1); 160859ffb30fSJeff Kirsher SelectPage(0); 160959ffb30fSJeff Kirsher PutByte(XIRCREG_CR, EnableIntr); 161059ffb30fSJeff Kirsher if (local->modem && !local->dingo) { /* do some magic */ 161159ffb30fSJeff Kirsher if (!(GetByte(0x10) & 0x01)) 161259ffb30fSJeff Kirsher PutByte(0x10, 0x11); /* unmask master-int bit */ 161359ffb30fSJeff Kirsher } 161459ffb30fSJeff Kirsher 161559ffb30fSJeff Kirsher if (full) 161659ffb30fSJeff Kirsher netdev_info(dev, "media %s, silicon revision %d\n", 161759ffb30fSJeff Kirsher if_names[dev->if_port], local->silicon); 161859ffb30fSJeff Kirsher /* We should switch back to page 0 to avoid a bug in revision 0 161959ffb30fSJeff Kirsher * where regs with offset below 8 can't be read after an access 162059ffb30fSJeff Kirsher * to the MAC registers */ 162159ffb30fSJeff Kirsher SelectPage(0); 162259ffb30fSJeff Kirsher } 162359ffb30fSJeff Kirsher 162459ffb30fSJeff Kirsher /**************** 162559ffb30fSJeff Kirsher * Initialize the Media-Independent-Interface 162659ffb30fSJeff Kirsher * Returns: True if we have a good MII 162759ffb30fSJeff Kirsher */ 162859ffb30fSJeff Kirsher static int 162959ffb30fSJeff Kirsher init_mii(struct net_device *dev) 163059ffb30fSJeff Kirsher { 1631f8653464SHimangi Saraogi struct local_info *local = netdev_priv(dev); 163259ffb30fSJeff Kirsher unsigned int ioaddr = dev->base_addr; 163359ffb30fSJeff Kirsher unsigned control, status, linkpartner; 163459ffb30fSJeff Kirsher int i; 163559ffb30fSJeff Kirsher 163659ffb30fSJeff Kirsher if (if_port == 4 || if_port == 1) { /* force 100BaseT or 10BaseT */ 163759ffb30fSJeff Kirsher dev->if_port = if_port; 163859ffb30fSJeff Kirsher local->probe_port = 0; 163959ffb30fSJeff Kirsher return 1; 164059ffb30fSJeff Kirsher } 164159ffb30fSJeff Kirsher 164259ffb30fSJeff Kirsher status = mii_rd(ioaddr, 0, 1); 164359ffb30fSJeff Kirsher if ((status & 0xff00) != 0x7800) 164459ffb30fSJeff Kirsher return 0; /* No MII */ 164559ffb30fSJeff Kirsher 164659ffb30fSJeff Kirsher local->new_mii = (mii_rd(ioaddr, 0, 2) != 0xffff); 164759ffb30fSJeff Kirsher 164859ffb30fSJeff Kirsher if (local->probe_port) 164959ffb30fSJeff Kirsher control = 0x1000; /* auto neg */ 165059ffb30fSJeff Kirsher else if (dev->if_port == 4) 165159ffb30fSJeff Kirsher control = 0x2000; /* no auto neg, 100mbs mode */ 165259ffb30fSJeff Kirsher else 165359ffb30fSJeff Kirsher control = 0x0000; /* no auto neg, 10mbs mode */ 165459ffb30fSJeff Kirsher mii_wr(ioaddr, 0, 0, control, 16); 165559ffb30fSJeff Kirsher udelay(100); 165659ffb30fSJeff Kirsher control = mii_rd(ioaddr, 0, 0); 165759ffb30fSJeff Kirsher 165859ffb30fSJeff Kirsher if (control & 0x0400) { 165959ffb30fSJeff Kirsher netdev_notice(dev, "can't take PHY out of isolation mode\n"); 166059ffb30fSJeff Kirsher local->probe_port = 0; 166159ffb30fSJeff Kirsher return 0; 166259ffb30fSJeff Kirsher } 166359ffb30fSJeff Kirsher 166459ffb30fSJeff Kirsher if (local->probe_port) { 166559ffb30fSJeff Kirsher /* according to the DP83840A specs the auto negotiation process 166659ffb30fSJeff Kirsher * may take up to 3.5 sec, so we use this also for our ML6692 166759ffb30fSJeff Kirsher * Fixme: Better to use a timer here! 166859ffb30fSJeff Kirsher */ 166959ffb30fSJeff Kirsher for (i=0; i < 35; i++) { 167059ffb30fSJeff Kirsher msleep(100); /* wait 100 msec */ 167159ffb30fSJeff Kirsher status = mii_rd(ioaddr, 0, 1); 167259ffb30fSJeff Kirsher if ((status & 0x0020) && (status & 0x0004)) 167359ffb30fSJeff Kirsher break; 167459ffb30fSJeff Kirsher } 167559ffb30fSJeff Kirsher 167659ffb30fSJeff Kirsher if (!(status & 0x0020)) { 167759ffb30fSJeff Kirsher netdev_info(dev, "autonegotiation failed; using 10mbs\n"); 167859ffb30fSJeff Kirsher if (!local->new_mii) { 167959ffb30fSJeff Kirsher control = 0x0000; 168059ffb30fSJeff Kirsher mii_wr(ioaddr, 0, 0, control, 16); 168159ffb30fSJeff Kirsher udelay(100); 168259ffb30fSJeff Kirsher SelectPage(0); 168359ffb30fSJeff Kirsher dev->if_port = (GetByte(XIRCREG_ESR) & MediaSelect) ? 1 : 2; 168459ffb30fSJeff Kirsher } 168559ffb30fSJeff Kirsher } else { 168659ffb30fSJeff Kirsher linkpartner = mii_rd(ioaddr, 0, 5); 168759ffb30fSJeff Kirsher netdev_info(dev, "MII link partner: %04x\n", linkpartner); 168859ffb30fSJeff Kirsher if (linkpartner & 0x0080) { 168959ffb30fSJeff Kirsher dev->if_port = 4; 169059ffb30fSJeff Kirsher } else 169159ffb30fSJeff Kirsher dev->if_port = 1; 169259ffb30fSJeff Kirsher } 169359ffb30fSJeff Kirsher } 169459ffb30fSJeff Kirsher 169559ffb30fSJeff Kirsher return 1; 169659ffb30fSJeff Kirsher } 169759ffb30fSJeff Kirsher 169859ffb30fSJeff Kirsher static void 169959ffb30fSJeff Kirsher do_powerdown(struct net_device *dev) 170059ffb30fSJeff Kirsher { 170159ffb30fSJeff Kirsher 170259ffb30fSJeff Kirsher unsigned int ioaddr = dev->base_addr; 170359ffb30fSJeff Kirsher 170459ffb30fSJeff Kirsher pr_debug("do_powerdown(%p)\n", dev); 170559ffb30fSJeff Kirsher 170659ffb30fSJeff Kirsher SelectPage(4); 170759ffb30fSJeff Kirsher PutByte(XIRCREG4_GPR1, 0); /* clear bit 0: power down */ 170859ffb30fSJeff Kirsher SelectPage(0); 170959ffb30fSJeff Kirsher } 171059ffb30fSJeff Kirsher 171159ffb30fSJeff Kirsher static int 171259ffb30fSJeff Kirsher do_stop(struct net_device *dev) 171359ffb30fSJeff Kirsher { 171459ffb30fSJeff Kirsher unsigned int ioaddr = dev->base_addr; 1715f8653464SHimangi Saraogi struct local_info *lp = netdev_priv(dev); 171659ffb30fSJeff Kirsher struct pcmcia_device *link = lp->p_dev; 171759ffb30fSJeff Kirsher 171859ffb30fSJeff Kirsher dev_dbg(&link->dev, "do_stop(%p)\n", dev); 171959ffb30fSJeff Kirsher 172059ffb30fSJeff Kirsher if (!link) 172159ffb30fSJeff Kirsher return -ENODEV; 172259ffb30fSJeff Kirsher 172359ffb30fSJeff Kirsher netif_stop_queue(dev); 172459ffb30fSJeff Kirsher 172559ffb30fSJeff Kirsher SelectPage(0); 172659ffb30fSJeff Kirsher PutByte(XIRCREG_CR, 0); /* disable interrupts */ 172759ffb30fSJeff Kirsher SelectPage(0x01); 172859ffb30fSJeff Kirsher PutByte(XIRCREG1_IMR0, 0x00); /* forbid all ints */ 172959ffb30fSJeff Kirsher SelectPage(4); 173059ffb30fSJeff Kirsher PutByte(XIRCREG4_GPR1, 0); /* clear bit 0: power down */ 173159ffb30fSJeff Kirsher SelectPage(0); 173259ffb30fSJeff Kirsher 173359ffb30fSJeff Kirsher link->open--; 173459ffb30fSJeff Kirsher return 0; 173559ffb30fSJeff Kirsher } 173659ffb30fSJeff Kirsher 173759ffb30fSJeff Kirsher static const struct pcmcia_device_id xirc2ps_ids[] = { 173859ffb30fSJeff Kirsher PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0089, 0x110a), 173959ffb30fSJeff Kirsher PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0138, 0x110a), 174059ffb30fSJeff Kirsher PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM28", 0x2e3ee845, 0x0ea978ea), 174159ffb30fSJeff Kirsher PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM33", 0x2e3ee845, 0x80609023), 174259ffb30fSJeff Kirsher PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM56", 0x2e3ee845, 0xa650c32a), 174359ffb30fSJeff Kirsher PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "REM10", 0x2e3ee845, 0x76df1d29), 174459ffb30fSJeff Kirsher PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "XEM5600", 0x2e3ee845, 0xf1403719), 174559ffb30fSJeff Kirsher PCMCIA_PFC_DEVICE_PROD_ID12(0, "Xircom", "CreditCard Ethernet+Modem II", 0x2e3ee845, 0xeca401bf), 174659ffb30fSJeff Kirsher PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x010a), 174759ffb30fSJeff Kirsher PCMCIA_DEVICE_PROD_ID13("Toshiba Information Systems", "TPCENET", 0x1b3b94fe, 0xf381c1a2), 174859ffb30fSJeff Kirsher PCMCIA_DEVICE_PROD_ID13("Xircom", "CE3-10/100", 0x2e3ee845, 0x0ec0ac37), 174959ffb30fSJeff Kirsher PCMCIA_DEVICE_PROD_ID13("Xircom", "PS-CE2-10", 0x2e3ee845, 0x947d9073), 175059ffb30fSJeff Kirsher PCMCIA_DEVICE_PROD_ID13("Xircom", "R2E-100BTX", 0x2e3ee845, 0x2464a6e3), 175159ffb30fSJeff Kirsher PCMCIA_DEVICE_PROD_ID13("Xircom", "RE-10", 0x2e3ee845, 0x3e08d609), 175259ffb30fSJeff Kirsher PCMCIA_DEVICE_PROD_ID13("Xircom", "XE2000", 0x2e3ee845, 0xf7188e46), 175359ffb30fSJeff Kirsher PCMCIA_DEVICE_PROD_ID12("Compaq", "Ethernet LAN Card", 0x54f7c49c, 0x9fd2f0a2), 175459ffb30fSJeff Kirsher PCMCIA_DEVICE_PROD_ID12("Compaq", "Netelligent 10/100 PC Card", 0x54f7c49c, 0xefe96769), 175559ffb30fSJeff Kirsher PCMCIA_DEVICE_PROD_ID12("Intel", "EtherExpress(TM) PRO/100 PC Card Mobile Adapter16", 0x816cc815, 0x174397db), 175659ffb30fSJeff Kirsher PCMCIA_DEVICE_PROD_ID12("Toshiba", "10/100 Ethernet PC Card", 0x44a09d9c, 0xb44deecf), 175759ffb30fSJeff Kirsher /* also matches CFE-10 cards! */ 175859ffb30fSJeff Kirsher /* PCMCIA_DEVICE_MANF_CARD(0x0105, 0x010a), */ 175959ffb30fSJeff Kirsher PCMCIA_DEVICE_NULL, 176059ffb30fSJeff Kirsher }; 176159ffb30fSJeff Kirsher MODULE_DEVICE_TABLE(pcmcia, xirc2ps_ids); 176259ffb30fSJeff Kirsher 176359ffb30fSJeff Kirsher 176459ffb30fSJeff Kirsher static struct pcmcia_driver xirc2ps_cs_driver = { 176559ffb30fSJeff Kirsher .owner = THIS_MODULE, 176659ffb30fSJeff Kirsher .name = "xirc2ps_cs", 176759ffb30fSJeff Kirsher .probe = xirc2ps_probe, 176859ffb30fSJeff Kirsher .remove = xirc2ps_detach, 176959ffb30fSJeff Kirsher .id_table = xirc2ps_ids, 177059ffb30fSJeff Kirsher .suspend = xirc2ps_suspend, 177159ffb30fSJeff Kirsher .resume = xirc2ps_resume, 177259ffb30fSJeff Kirsher }; 1773fdd3f29eSH Hartley Sweeten module_pcmcia_driver(xirc2ps_cs_driver); 177459ffb30fSJeff Kirsher 177559ffb30fSJeff Kirsher #ifndef MODULE 177659ffb30fSJeff Kirsher static int __init setup_xirc2ps_cs(char *str) 177759ffb30fSJeff Kirsher { 177859ffb30fSJeff Kirsher /* if_port, full_duplex, do_sound, lockup_hack 177959ffb30fSJeff Kirsher */ 178059ffb30fSJeff Kirsher int ints[10] = { -1 }; 178159ffb30fSJeff Kirsher 1782d3213fbfSDan Carpenter str = get_options(str, ARRAY_SIZE(ints), ints); 178359ffb30fSJeff Kirsher 178459ffb30fSJeff Kirsher #define MAYBE_SET(X,Y) if (ints[0] >= Y && ints[Y] != -1) { X = ints[Y]; } 178559ffb30fSJeff Kirsher MAYBE_SET(if_port, 3); 178659ffb30fSJeff Kirsher MAYBE_SET(full_duplex, 4); 178759ffb30fSJeff Kirsher MAYBE_SET(do_sound, 5); 178859ffb30fSJeff Kirsher MAYBE_SET(lockup_hack, 6); 178959ffb30fSJeff Kirsher #undef MAYBE_SET 179059ffb30fSJeff Kirsher 179159ffb30fSJeff Kirsher return 1; 179259ffb30fSJeff Kirsher } 179359ffb30fSJeff Kirsher 179459ffb30fSJeff Kirsher __setup("xirc2ps_cs=", setup_xirc2ps_cs); 179559ffb30fSJeff Kirsher #endif 1796