xref: /openbmc/linux/drivers/net/ethernet/xircom/xirc2ps_cs.c (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
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
mii_idle(unsigned int ioaddr)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
mii_putbit(unsigned int ioaddr,unsigned data)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
mii_getbit(unsigned int ioaddr)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
mii_wbits(unsigned int ioaddr,unsigned data,int len)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
mii_rd(unsigned int ioaddr,u_char phyaddr,u_char phyreg)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
mii_wr(unsigned int ioaddr,u_char phyaddr,u_char phyreg,unsigned data,int len)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
xirc2ps_probe(struct pcmcia_device * link)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
xirc2ps_detach(struct pcmcia_device * link)50359ffb30fSJeff Kirsher xirc2ps_detach(struct pcmcia_device *link)
50459ffb30fSJeff Kirsher {
50559ffb30fSJeff Kirsher     struct net_device *dev = link->priv;
506*e8d20c3dSZheng Wang     struct local_info *local = netdev_priv(dev);
507*e8d20c3dSZheng Wang 
508*e8d20c3dSZheng Wang     netif_carrier_off(dev);
509*e8d20c3dSZheng Wang     netif_tx_disable(dev);
510*e8d20c3dSZheng Wang     cancel_work_sync(&local->tx_timeout_task);
51159ffb30fSJeff Kirsher 
51259ffb30fSJeff Kirsher     dev_dbg(&link->dev, "detach\n");
51359ffb30fSJeff Kirsher 
51459ffb30fSJeff Kirsher     unregister_netdev(dev);
51559ffb30fSJeff Kirsher 
51659ffb30fSJeff Kirsher     xirc2ps_release(link);
51759ffb30fSJeff Kirsher 
51859ffb30fSJeff Kirsher     free_netdev(dev);
51959ffb30fSJeff Kirsher } /* xirc2ps_detach */
52059ffb30fSJeff Kirsher 
52159ffb30fSJeff Kirsher /****************
52259ffb30fSJeff Kirsher  * Detect the type of the card. s is the buffer with the data of tuple 0x20
52359ffb30fSJeff Kirsher  * Returns: 0 := not supported
52459ffb30fSJeff Kirsher  *		       mediaid=11 and prodid=47
52559ffb30fSJeff Kirsher  * Media-Id bits:
52659ffb30fSJeff Kirsher  *  Ethernet	    0x01
52759ffb30fSJeff Kirsher  *  Tokenring	    0x02
52859ffb30fSJeff Kirsher  *  Arcnet	    0x04
52959ffb30fSJeff Kirsher  *  Wireless	    0x08
53059ffb30fSJeff Kirsher  *  Modem	    0x10
53159ffb30fSJeff Kirsher  *  GSM only	    0x20
53259ffb30fSJeff Kirsher  * Prod-Id bits:
53359ffb30fSJeff Kirsher  *  Pocket	    0x10
53459ffb30fSJeff Kirsher  *  External	    0x20
53559ffb30fSJeff Kirsher  *  Creditcard	    0x40
53659ffb30fSJeff Kirsher  *  Cardbus	    0x80
53759ffb30fSJeff Kirsher  *
53859ffb30fSJeff Kirsher  */
53959ffb30fSJeff Kirsher static int
set_card_type(struct pcmcia_device * link)54059ffb30fSJeff Kirsher set_card_type(struct pcmcia_device *link)
54159ffb30fSJeff Kirsher {
54259ffb30fSJeff Kirsher     struct net_device *dev = link->priv;
543f8653464SHimangi Saraogi     struct local_info *local = netdev_priv(dev);
54459ffb30fSJeff Kirsher     u8 *buf;
54559ffb30fSJeff Kirsher     unsigned int cisrev, mediaid, prodid;
54659ffb30fSJeff Kirsher     size_t len;
54759ffb30fSJeff Kirsher 
54859ffb30fSJeff Kirsher     len = pcmcia_get_tuple(link, CISTPL_MANFID, &buf);
54959ffb30fSJeff Kirsher     if (len < 5) {
55059ffb30fSJeff Kirsher 	    dev_err(&link->dev, "invalid CIS -- sorry\n");
55159ffb30fSJeff Kirsher 	    return 0;
55259ffb30fSJeff Kirsher     }
55359ffb30fSJeff Kirsher 
55459ffb30fSJeff Kirsher     cisrev = buf[2];
55559ffb30fSJeff Kirsher     mediaid = buf[3];
55659ffb30fSJeff Kirsher     prodid = buf[4];
55759ffb30fSJeff Kirsher 
55859ffb30fSJeff Kirsher     dev_dbg(&link->dev, "cisrev=%02x mediaid=%02x prodid=%02x\n",
55959ffb30fSJeff Kirsher 	  cisrev, mediaid, prodid);
56059ffb30fSJeff Kirsher 
56159ffb30fSJeff Kirsher     local->mohawk = 0;
56259ffb30fSJeff Kirsher     local->dingo = 0;
56359ffb30fSJeff Kirsher     local->modem = 0;
56459ffb30fSJeff Kirsher     local->card_type = XIR_UNKNOWN;
56559ffb30fSJeff Kirsher     if (!(prodid & 0x40)) {
56659ffb30fSJeff Kirsher 	pr_notice("Oops: Not a creditcard\n");
56759ffb30fSJeff Kirsher 	return 0;
56859ffb30fSJeff Kirsher     }
56959ffb30fSJeff Kirsher     if (!(mediaid & 0x01)) {
57059ffb30fSJeff Kirsher 	pr_notice("Not an Ethernet card\n");
57159ffb30fSJeff Kirsher 	return 0;
57259ffb30fSJeff Kirsher     }
57359ffb30fSJeff Kirsher     if (mediaid & 0x10) {
57459ffb30fSJeff Kirsher 	local->modem = 1;
57559ffb30fSJeff Kirsher 	switch(prodid & 15) {
57659ffb30fSJeff Kirsher 	  case 1: local->card_type = XIR_CEM   ; break;
57759ffb30fSJeff Kirsher 	  case 2: local->card_type = XIR_CEM2  ; break;
57859ffb30fSJeff Kirsher 	  case 3: local->card_type = XIR_CEM3  ; break;
57959ffb30fSJeff Kirsher 	  case 4: local->card_type = XIR_CEM33 ; break;
58059ffb30fSJeff Kirsher 	  case 5: local->card_type = XIR_CEM56M;
58159ffb30fSJeff Kirsher 		  local->mohawk = 1;
58259ffb30fSJeff Kirsher 		  break;
58359ffb30fSJeff Kirsher 	  case 6:
58459ffb30fSJeff Kirsher 	  case 7: /* 7 is the RealPort 10/56 */
58559ffb30fSJeff Kirsher 		  local->card_type = XIR_CEM56 ;
58659ffb30fSJeff Kirsher 		  local->mohawk = 1;
58759ffb30fSJeff Kirsher 		  local->dingo = 1;
58859ffb30fSJeff Kirsher 		  break;
58959ffb30fSJeff Kirsher 	}
59059ffb30fSJeff Kirsher     } else {
59159ffb30fSJeff Kirsher 	switch(prodid & 15) {
59259ffb30fSJeff Kirsher 	  case 1: local->card_type = has_ce2_string(link)? XIR_CE2 : XIR_CE ;
59359ffb30fSJeff Kirsher 		  break;
59459ffb30fSJeff Kirsher 	  case 2: local->card_type = XIR_CE2; break;
59559ffb30fSJeff Kirsher 	  case 3: local->card_type = XIR_CE3;
59659ffb30fSJeff Kirsher 		  local->mohawk = 1;
59759ffb30fSJeff Kirsher 		  break;
59859ffb30fSJeff Kirsher 	}
59959ffb30fSJeff Kirsher     }
60059ffb30fSJeff Kirsher     if (local->card_type == XIR_CE || local->card_type == XIR_CEM) {
60159ffb30fSJeff Kirsher 	pr_notice("Sorry, this is an old CE card\n");
60259ffb30fSJeff Kirsher 	return 0;
60359ffb30fSJeff Kirsher     }
60459ffb30fSJeff Kirsher     if (local->card_type == XIR_UNKNOWN)
60559ffb30fSJeff Kirsher 	pr_notice("unknown card (mediaid=%02x prodid=%02x)\n", mediaid, prodid);
60659ffb30fSJeff Kirsher 
60759ffb30fSJeff Kirsher     return 1;
60859ffb30fSJeff Kirsher }
60959ffb30fSJeff Kirsher 
61059ffb30fSJeff Kirsher /****************
61159ffb30fSJeff Kirsher  * There are some CE2 cards out which claim to be a CE card.
61259ffb30fSJeff Kirsher  * This function looks for a "CE2" in the 3rd version field.
61359ffb30fSJeff Kirsher  * Returns: true if this is a CE2
61459ffb30fSJeff Kirsher  */
61559ffb30fSJeff Kirsher static int
has_ce2_string(struct pcmcia_device * p_dev)61659ffb30fSJeff Kirsher has_ce2_string(struct pcmcia_device * p_dev)
61759ffb30fSJeff Kirsher {
61859ffb30fSJeff Kirsher 	if (p_dev->prod_id[2] && strstr(p_dev->prod_id[2], "CE2"))
61959ffb30fSJeff Kirsher 		return 1;
62059ffb30fSJeff Kirsher 	return 0;
62159ffb30fSJeff Kirsher }
62259ffb30fSJeff Kirsher 
62359ffb30fSJeff Kirsher static int
xirc2ps_config_modem(struct pcmcia_device * p_dev,void * priv_data)62459ffb30fSJeff Kirsher xirc2ps_config_modem(struct pcmcia_device *p_dev, void *priv_data)
62559ffb30fSJeff Kirsher {
62659ffb30fSJeff Kirsher 	unsigned int ioaddr;
62759ffb30fSJeff Kirsher 
62859ffb30fSJeff Kirsher 	if ((p_dev->resource[0]->start & 0xf) == 8)
62959ffb30fSJeff Kirsher 		return -ENODEV;
63059ffb30fSJeff Kirsher 
63159ffb30fSJeff Kirsher 	p_dev->resource[0]->end = 16;
63259ffb30fSJeff Kirsher 	p_dev->resource[1]->end = 8;
63359ffb30fSJeff Kirsher 	p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
63459ffb30fSJeff Kirsher 	p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
63559ffb30fSJeff Kirsher 	p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
63659ffb30fSJeff Kirsher 	p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
63759ffb30fSJeff Kirsher 	p_dev->io_lines = 10;
63859ffb30fSJeff Kirsher 
63959ffb30fSJeff Kirsher 	p_dev->resource[1]->start = p_dev->resource[0]->start;
64059ffb30fSJeff Kirsher 	for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
64159ffb30fSJeff Kirsher 		p_dev->resource[0]->start = ioaddr;
64259ffb30fSJeff Kirsher 		if (!pcmcia_request_io(p_dev))
64359ffb30fSJeff Kirsher 			return 0;
64459ffb30fSJeff Kirsher 	}
64559ffb30fSJeff Kirsher 	return -ENODEV;
64659ffb30fSJeff Kirsher }
64759ffb30fSJeff Kirsher 
64859ffb30fSJeff Kirsher static int
xirc2ps_config_check(struct pcmcia_device * p_dev,void * priv_data)64959ffb30fSJeff Kirsher xirc2ps_config_check(struct pcmcia_device *p_dev, void *priv_data)
65059ffb30fSJeff Kirsher {
65159ffb30fSJeff Kirsher 	int *pass = priv_data;
65259ffb30fSJeff Kirsher 	resource_size_t tmp = p_dev->resource[1]->start;
65359ffb30fSJeff Kirsher 
65459ffb30fSJeff Kirsher 	tmp += (*pass ? (p_dev->config_index & 0x20 ? -24 : 8)
65559ffb30fSJeff Kirsher 		: (p_dev->config_index & 0x20 ?   8 : -24));
65659ffb30fSJeff Kirsher 
65759ffb30fSJeff Kirsher 	if ((p_dev->resource[0]->start & 0xf) == 8)
65859ffb30fSJeff Kirsher 		return -ENODEV;
65959ffb30fSJeff Kirsher 
66059ffb30fSJeff Kirsher 	p_dev->resource[0]->end = 18;
66159ffb30fSJeff Kirsher 	p_dev->resource[1]->end = 8;
66259ffb30fSJeff Kirsher 	p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
66359ffb30fSJeff Kirsher 	p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
66459ffb30fSJeff Kirsher 	p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
66559ffb30fSJeff Kirsher 	p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
66659ffb30fSJeff Kirsher 	p_dev->io_lines = 10;
66759ffb30fSJeff Kirsher 
66859ffb30fSJeff Kirsher 	p_dev->resource[1]->start = p_dev->resource[0]->start;
66959ffb30fSJeff Kirsher 	p_dev->resource[0]->start = tmp;
67059ffb30fSJeff Kirsher 	return pcmcia_request_io(p_dev);
67159ffb30fSJeff Kirsher }
67259ffb30fSJeff Kirsher 
67359ffb30fSJeff Kirsher 
pcmcia_get_mac_ce(struct pcmcia_device * p_dev,tuple_t * tuple,void * priv)67459ffb30fSJeff Kirsher static int pcmcia_get_mac_ce(struct pcmcia_device *p_dev,
67559ffb30fSJeff Kirsher 			     tuple_t *tuple,
67659ffb30fSJeff Kirsher 			     void *priv)
67759ffb30fSJeff Kirsher {
67859ffb30fSJeff Kirsher 	struct net_device *dev = priv;
67959ffb30fSJeff Kirsher 
68059ffb30fSJeff Kirsher 	if (tuple->TupleDataLen != 13)
68159ffb30fSJeff Kirsher 		return -EINVAL;
68259ffb30fSJeff Kirsher 	if ((tuple->TupleData[0] != 2) || (tuple->TupleData[1] != 1) ||
68359ffb30fSJeff Kirsher 		(tuple->TupleData[2] != 6))
68459ffb30fSJeff Kirsher 		return -EINVAL;
68559ffb30fSJeff Kirsher 	/* another try	(James Lehmer's CE2 version 4.1)*/
6864abd7cffSJakub Kicinski 	dev_addr_mod(dev, 2, &tuple->TupleData[2], 4);
68759ffb30fSJeff Kirsher 	return 0;
68859ffb30fSJeff Kirsher };
68959ffb30fSJeff Kirsher 
69059ffb30fSJeff Kirsher 
69159ffb30fSJeff Kirsher static int
xirc2ps_config(struct pcmcia_device * link)69259ffb30fSJeff Kirsher xirc2ps_config(struct pcmcia_device * link)
69359ffb30fSJeff Kirsher {
69459ffb30fSJeff Kirsher     struct net_device *dev = link->priv;
695f8653464SHimangi Saraogi     struct local_info *local = netdev_priv(dev);
69659ffb30fSJeff Kirsher     unsigned int ioaddr;
69759ffb30fSJeff Kirsher     int err;
69859ffb30fSJeff Kirsher     u8 *buf;
69959ffb30fSJeff Kirsher     size_t len;
70059ffb30fSJeff Kirsher 
70159ffb30fSJeff Kirsher     local->dingo_ccr = NULL;
70259ffb30fSJeff Kirsher 
70359ffb30fSJeff Kirsher     dev_dbg(&link->dev, "config\n");
70459ffb30fSJeff Kirsher 
70559ffb30fSJeff Kirsher     /* Is this a valid	card */
70659ffb30fSJeff Kirsher     if (link->has_manf_id == 0) {
70759ffb30fSJeff Kirsher 	pr_notice("manfid not found in CIS\n");
70859ffb30fSJeff Kirsher 	goto failure;
70959ffb30fSJeff Kirsher     }
71059ffb30fSJeff Kirsher 
71159ffb30fSJeff Kirsher     switch (link->manf_id) {
71259ffb30fSJeff Kirsher       case MANFID_XIRCOM:
71359ffb30fSJeff Kirsher 	local->manf_str = "Xircom";
71459ffb30fSJeff Kirsher 	break;
71559ffb30fSJeff Kirsher       case MANFID_ACCTON:
71659ffb30fSJeff Kirsher 	local->manf_str = "Accton";
71759ffb30fSJeff Kirsher 	break;
71859ffb30fSJeff Kirsher       case MANFID_COMPAQ:
71959ffb30fSJeff Kirsher       case MANFID_COMPAQ2:
72059ffb30fSJeff Kirsher 	local->manf_str = "Compaq";
72159ffb30fSJeff Kirsher 	break;
72259ffb30fSJeff Kirsher       case MANFID_INTEL:
72359ffb30fSJeff Kirsher 	local->manf_str = "Intel";
72459ffb30fSJeff Kirsher 	break;
72559ffb30fSJeff Kirsher       case MANFID_TOSHIBA:
72659ffb30fSJeff Kirsher 	local->manf_str = "Toshiba";
72759ffb30fSJeff Kirsher 	break;
72859ffb30fSJeff Kirsher       default:
72959ffb30fSJeff Kirsher 	pr_notice("Unknown Card Manufacturer ID: 0x%04x\n",
73059ffb30fSJeff Kirsher 		  (unsigned)link->manf_id);
73159ffb30fSJeff Kirsher 	goto failure;
73259ffb30fSJeff Kirsher     }
73359ffb30fSJeff Kirsher     dev_dbg(&link->dev, "found %s card\n", local->manf_str);
73459ffb30fSJeff Kirsher 
73559ffb30fSJeff Kirsher     if (!set_card_type(link)) {
73659ffb30fSJeff Kirsher 	pr_notice("this card is not supported\n");
73759ffb30fSJeff Kirsher 	goto failure;
73859ffb30fSJeff Kirsher     }
73959ffb30fSJeff Kirsher 
74059ffb30fSJeff Kirsher     /* get the ethernet address from the CIS */
74159ffb30fSJeff Kirsher     err = pcmcia_get_mac_from_cis(link, dev);
74259ffb30fSJeff Kirsher 
74359ffb30fSJeff Kirsher     /* not found: try to get the node-id from tuple 0x89 */
74459ffb30fSJeff Kirsher     if (err) {
74559ffb30fSJeff Kirsher 	    len = pcmcia_get_tuple(link, 0x89, &buf);
74659ffb30fSJeff Kirsher 	    /* data layout looks like tuple 0x22 */
74759ffb30fSJeff Kirsher 	    if (buf && len == 8) {
7484abd7cffSJakub Kicinski 		    if (*buf == CISTPL_FUNCE_LAN_NODE_ID)
7494abd7cffSJakub Kicinski 			    dev_addr_mod(dev, 2, &buf[2], 4);
7504abd7cffSJakub Kicinski 		    else
75159ffb30fSJeff Kirsher 			    err = -1;
75259ffb30fSJeff Kirsher 	    }
75359ffb30fSJeff Kirsher 	    kfree(buf);
75459ffb30fSJeff Kirsher     }
75559ffb30fSJeff Kirsher 
75659ffb30fSJeff Kirsher     if (err)
75759ffb30fSJeff Kirsher 	err = pcmcia_loop_tuple(link, CISTPL_FUNCE, pcmcia_get_mac_ce, dev);
75859ffb30fSJeff Kirsher 
75959ffb30fSJeff Kirsher     if (err) {
76059ffb30fSJeff Kirsher 	pr_notice("node-id not found in CIS\n");
76159ffb30fSJeff Kirsher 	goto failure;
76259ffb30fSJeff Kirsher     }
76359ffb30fSJeff Kirsher 
76459ffb30fSJeff Kirsher     if (local->modem) {
76559ffb30fSJeff Kirsher 	int pass;
76659ffb30fSJeff Kirsher 	link->config_flags |= CONF_AUTO_SET_IO;
76759ffb30fSJeff Kirsher 
76859ffb30fSJeff Kirsher 	if (local->dingo) {
76959ffb30fSJeff Kirsher 	    /* Take the Modem IO port from the CIS and scan for a free
77059ffb30fSJeff Kirsher 	     * Ethernet port */
77159ffb30fSJeff Kirsher 	    if (!pcmcia_loop_config(link, xirc2ps_config_modem, NULL))
77259ffb30fSJeff Kirsher 		    goto port_found;
77359ffb30fSJeff Kirsher 	} else {
77459ffb30fSJeff Kirsher 	    /* We do 2 passes here: The first one uses the regular mapping and
77559ffb30fSJeff Kirsher 	     * the second tries again, thereby considering that the 32 ports are
77659ffb30fSJeff Kirsher 	     * mirrored every 32 bytes. Actually we use a mirrored port for
77759ffb30fSJeff Kirsher 	     * the Mako if (on the first pass) the COR bit 5 is set.
77859ffb30fSJeff Kirsher 	     */
77959ffb30fSJeff Kirsher 	    for (pass=0; pass < 2; pass++)
78059ffb30fSJeff Kirsher 		    if (!pcmcia_loop_config(link, xirc2ps_config_check,
78159ffb30fSJeff Kirsher 						    &pass))
78259ffb30fSJeff Kirsher 			    goto port_found;
78359ffb30fSJeff Kirsher 	    /* if special option:
78459ffb30fSJeff Kirsher 	     * try to configure as Ethernet only.
78559ffb30fSJeff Kirsher 	     * .... */
78659ffb30fSJeff Kirsher 	}
78759ffb30fSJeff Kirsher 	pr_notice("no ports available\n");
78859ffb30fSJeff Kirsher     } else {
78959ffb30fSJeff Kirsher 	link->io_lines = 10;
79059ffb30fSJeff Kirsher 	link->resource[0]->end = 16;
79159ffb30fSJeff Kirsher 	link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
79259ffb30fSJeff Kirsher 	for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
79359ffb30fSJeff Kirsher 	    link->resource[0]->start = ioaddr;
79459ffb30fSJeff Kirsher 	    if (!(err = pcmcia_request_io(link)))
79559ffb30fSJeff Kirsher 		goto port_found;
79659ffb30fSJeff Kirsher 	}
79759ffb30fSJeff Kirsher 	link->resource[0]->start = 0; /* let CS decide */
79859ffb30fSJeff Kirsher 	if ((err = pcmcia_request_io(link)))
79959ffb30fSJeff Kirsher 	    goto config_error;
80059ffb30fSJeff Kirsher     }
80159ffb30fSJeff Kirsher   port_found:
80259ffb30fSJeff Kirsher 
80359ffb30fSJeff Kirsher     /****************
80459ffb30fSJeff Kirsher      * Now allocate an interrupt line.	Note that this does not
80559ffb30fSJeff Kirsher      * actually assign a handler to the interrupt.
80659ffb30fSJeff Kirsher      */
80759ffb30fSJeff Kirsher     if ((err=pcmcia_request_irq(link, xirc2ps_interrupt)))
80859ffb30fSJeff Kirsher 	goto config_error;
80959ffb30fSJeff Kirsher 
81059ffb30fSJeff Kirsher     link->config_flags |= CONF_ENABLE_IRQ;
81159ffb30fSJeff Kirsher     if (do_sound)
81259ffb30fSJeff Kirsher 	    link->config_flags |= CONF_ENABLE_SPKR;
81359ffb30fSJeff Kirsher 
81459ffb30fSJeff Kirsher     if ((err = pcmcia_enable_device(link)))
81559ffb30fSJeff Kirsher 	goto config_error;
81659ffb30fSJeff Kirsher 
81759ffb30fSJeff Kirsher     if (local->dingo) {
81859ffb30fSJeff Kirsher 	/* Reset the modem's BAR to the correct value
81959ffb30fSJeff Kirsher 	 * This is necessary because in the RequestConfiguration call,
82059ffb30fSJeff Kirsher 	 * the base address of the ethernet port (BasePort1) is written
82159ffb30fSJeff Kirsher 	 * to the BAR registers of the modem.
82259ffb30fSJeff Kirsher 	 */
82359ffb30fSJeff Kirsher 	err = pcmcia_write_config_byte(link, CISREG_IOBASE_0, (u8)
82459ffb30fSJeff Kirsher 				link->resource[1]->start & 0xff);
82559ffb30fSJeff Kirsher 	if (err)
82659ffb30fSJeff Kirsher 	    goto config_error;
82759ffb30fSJeff Kirsher 
82859ffb30fSJeff Kirsher 	err = pcmcia_write_config_byte(link, CISREG_IOBASE_1,
82959ffb30fSJeff Kirsher 				(link->resource[1]->start >> 8) & 0xff);
83059ffb30fSJeff Kirsher 	if (err)
83159ffb30fSJeff Kirsher 	    goto config_error;
83259ffb30fSJeff Kirsher 
83359ffb30fSJeff Kirsher 	/* There is no config entry for the Ethernet part which
83459ffb30fSJeff Kirsher 	 * is at 0x0800. So we allocate a window into the attribute
83559ffb30fSJeff Kirsher 	 * memory and write direct to the CIS registers
83659ffb30fSJeff Kirsher 	 */
83759ffb30fSJeff Kirsher 	link->resource[2]->flags = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM |
83859ffb30fSJeff Kirsher 					WIN_ENABLE;
83959ffb30fSJeff Kirsher 	link->resource[2]->start = link->resource[2]->end = 0;
84059ffb30fSJeff Kirsher 	if ((err = pcmcia_request_window(link, link->resource[2], 0)))
84159ffb30fSJeff Kirsher 	    goto config_error;
84259ffb30fSJeff Kirsher 
84359ffb30fSJeff Kirsher 	local->dingo_ccr = ioremap(link->resource[2]->start, 0x1000) + 0x0800;
84459ffb30fSJeff Kirsher 	if ((err = pcmcia_map_mem_page(link, link->resource[2], 0)))
84559ffb30fSJeff Kirsher 	    goto config_error;
84659ffb30fSJeff Kirsher 
84759ffb30fSJeff Kirsher 	/* Setup the CCRs; there are no infos in the CIS about the Ethernet
84859ffb30fSJeff Kirsher 	 * part.
84959ffb30fSJeff Kirsher 	 */
85059ffb30fSJeff Kirsher 	writeb(0x47, local->dingo_ccr + CISREG_COR);
85159ffb30fSJeff Kirsher 	ioaddr = link->resource[0]->start;
85259ffb30fSJeff Kirsher 	writeb(ioaddr & 0xff	  , local->dingo_ccr + CISREG_IOBASE_0);
85359ffb30fSJeff Kirsher 	writeb((ioaddr >> 8)&0xff , local->dingo_ccr + CISREG_IOBASE_1);
85459ffb30fSJeff Kirsher 
85559ffb30fSJeff Kirsher       #if 0
85659ffb30fSJeff Kirsher 	{
85759ffb30fSJeff Kirsher 	    u_char tmp;
85859ffb30fSJeff Kirsher 	    pr_info("ECOR:");
85959ffb30fSJeff Kirsher 	    for (i=0; i < 7; i++) {
86059ffb30fSJeff Kirsher 		tmp = readb(local->dingo_ccr + i*2);
86159ffb30fSJeff Kirsher 		pr_cont(" %02x", tmp);
86259ffb30fSJeff Kirsher 	    }
86359ffb30fSJeff Kirsher 	    pr_cont("\n");
86459ffb30fSJeff Kirsher 	    pr_info("DCOR:");
86559ffb30fSJeff Kirsher 	    for (i=0; i < 4; i++) {
86659ffb30fSJeff Kirsher 		tmp = readb(local->dingo_ccr + 0x20 + i*2);
86759ffb30fSJeff Kirsher 		pr_cont(" %02x", tmp);
86859ffb30fSJeff Kirsher 	    }
86959ffb30fSJeff Kirsher 	    pr_cont("\n");
87059ffb30fSJeff Kirsher 	    pr_info("SCOR:");
87159ffb30fSJeff Kirsher 	    for (i=0; i < 10; i++) {
87259ffb30fSJeff Kirsher 		tmp = readb(local->dingo_ccr + 0x40 + i*2);
87359ffb30fSJeff Kirsher 		pr_cont(" %02x", tmp);
87459ffb30fSJeff Kirsher 	    }
87559ffb30fSJeff Kirsher 	    pr_cont("\n");
87659ffb30fSJeff Kirsher 	}
87759ffb30fSJeff Kirsher       #endif
87859ffb30fSJeff Kirsher 
87959ffb30fSJeff Kirsher 	writeb(0x01, local->dingo_ccr + 0x20);
88059ffb30fSJeff Kirsher 	writeb(0x0c, local->dingo_ccr + 0x22);
88159ffb30fSJeff Kirsher 	writeb(0x00, local->dingo_ccr + 0x24);
88259ffb30fSJeff Kirsher 	writeb(0x00, local->dingo_ccr + 0x26);
88359ffb30fSJeff Kirsher 	writeb(0x00, local->dingo_ccr + 0x28);
88459ffb30fSJeff Kirsher     }
88559ffb30fSJeff Kirsher 
88659ffb30fSJeff Kirsher     /* The if_port symbol can be set when the module is loaded */
88759ffb30fSJeff Kirsher     local->probe_port=0;
88859ffb30fSJeff Kirsher     if (!if_port) {
88959ffb30fSJeff Kirsher 	local->probe_port = dev->if_port = 1;
89059ffb30fSJeff Kirsher     } else if ((if_port >= 1 && if_port <= 2) ||
89159ffb30fSJeff Kirsher 	       (local->mohawk && if_port==4))
89259ffb30fSJeff Kirsher 	dev->if_port = if_port;
89359ffb30fSJeff Kirsher     else
89459ffb30fSJeff Kirsher 	pr_notice("invalid if_port requested\n");
89559ffb30fSJeff Kirsher 
89659ffb30fSJeff Kirsher     /* we can now register the device with the net subsystem */
89759ffb30fSJeff Kirsher     dev->irq = link->irq;
89859ffb30fSJeff Kirsher     dev->base_addr = link->resource[0]->start;
89959ffb30fSJeff Kirsher 
90059ffb30fSJeff Kirsher     if (local->dingo)
90159ffb30fSJeff Kirsher 	do_reset(dev, 1); /* a kludge to make the cem56 work */
90259ffb30fSJeff Kirsher 
90359ffb30fSJeff Kirsher     SET_NETDEV_DEV(dev, &link->dev);
90459ffb30fSJeff Kirsher 
90559ffb30fSJeff Kirsher     if ((err=register_netdev(dev))) {
90659ffb30fSJeff Kirsher 	pr_notice("register_netdev() failed\n");
90759ffb30fSJeff Kirsher 	goto config_error;
90859ffb30fSJeff Kirsher     }
90959ffb30fSJeff Kirsher 
91059ffb30fSJeff Kirsher     /* give some infos about the hardware */
91159ffb30fSJeff Kirsher     netdev_info(dev, "%s: port %#3lx, irq %d, hwaddr %pM\n",
91259ffb30fSJeff Kirsher 		local->manf_str, (u_long)dev->base_addr, (int)dev->irq,
91359ffb30fSJeff Kirsher 		dev->dev_addr);
91459ffb30fSJeff Kirsher 
91559ffb30fSJeff Kirsher     return 0;
91659ffb30fSJeff Kirsher 
91759ffb30fSJeff Kirsher   config_error:
91859ffb30fSJeff Kirsher     xirc2ps_release(link);
91959ffb30fSJeff Kirsher     return -ENODEV;
92059ffb30fSJeff Kirsher 
92159ffb30fSJeff Kirsher   failure:
92259ffb30fSJeff Kirsher     return -ENODEV;
92359ffb30fSJeff Kirsher } /* xirc2ps_config */
92459ffb30fSJeff Kirsher 
92559ffb30fSJeff Kirsher static void
xirc2ps_release(struct pcmcia_device * link)92659ffb30fSJeff Kirsher xirc2ps_release(struct pcmcia_device *link)
92759ffb30fSJeff Kirsher {
92859ffb30fSJeff Kirsher 	dev_dbg(&link->dev, "release\n");
92959ffb30fSJeff Kirsher 
93059ffb30fSJeff Kirsher 	if (link->resource[2]->end) {
93159ffb30fSJeff Kirsher 		struct net_device *dev = link->priv;
932f8653464SHimangi Saraogi 		struct local_info *local = netdev_priv(dev);
93359ffb30fSJeff Kirsher 		if (local->dingo)
93459ffb30fSJeff Kirsher 			iounmap(local->dingo_ccr - 0x0800);
93559ffb30fSJeff Kirsher 	}
93659ffb30fSJeff Kirsher 	pcmcia_disable_device(link);
93759ffb30fSJeff Kirsher } /* xirc2ps_release */
93859ffb30fSJeff Kirsher 
93959ffb30fSJeff Kirsher /*====================================================================*/
94059ffb30fSJeff Kirsher 
94159ffb30fSJeff Kirsher 
xirc2ps_suspend(struct pcmcia_device * link)94259ffb30fSJeff Kirsher static int xirc2ps_suspend(struct pcmcia_device *link)
94359ffb30fSJeff Kirsher {
94459ffb30fSJeff Kirsher 	struct net_device *dev = link->priv;
94559ffb30fSJeff Kirsher 
94659ffb30fSJeff Kirsher 	if (link->open) {
94759ffb30fSJeff Kirsher 		netif_device_detach(dev);
94859ffb30fSJeff Kirsher 		do_powerdown(dev);
94959ffb30fSJeff Kirsher 	}
95059ffb30fSJeff Kirsher 
95159ffb30fSJeff Kirsher 	return 0;
95259ffb30fSJeff Kirsher }
95359ffb30fSJeff Kirsher 
xirc2ps_resume(struct pcmcia_device * link)95459ffb30fSJeff Kirsher static int xirc2ps_resume(struct pcmcia_device *link)
95559ffb30fSJeff Kirsher {
95659ffb30fSJeff Kirsher 	struct net_device *dev = link->priv;
95759ffb30fSJeff Kirsher 
95859ffb30fSJeff Kirsher 	if (link->open) {
95959ffb30fSJeff Kirsher 		do_reset(dev,1);
96059ffb30fSJeff Kirsher 		netif_device_attach(dev);
96159ffb30fSJeff Kirsher 	}
96259ffb30fSJeff Kirsher 
96359ffb30fSJeff Kirsher 	return 0;
96459ffb30fSJeff Kirsher }
96559ffb30fSJeff Kirsher 
96659ffb30fSJeff Kirsher 
96759ffb30fSJeff Kirsher /*====================================================================*/
96859ffb30fSJeff Kirsher 
96959ffb30fSJeff Kirsher /****************
97059ffb30fSJeff Kirsher  * This is the Interrupt service route.
97159ffb30fSJeff Kirsher  */
97259ffb30fSJeff Kirsher static irqreturn_t
xirc2ps_interrupt(int irq,void * dev_id)97359ffb30fSJeff Kirsher xirc2ps_interrupt(int irq, void *dev_id)
97459ffb30fSJeff Kirsher {
97559ffb30fSJeff Kirsher     struct net_device *dev = (struct net_device *)dev_id;
976f8653464SHimangi Saraogi     struct local_info *lp = netdev_priv(dev);
97759ffb30fSJeff Kirsher     unsigned int ioaddr;
97859ffb30fSJeff Kirsher     u_char saved_page;
97959ffb30fSJeff Kirsher     unsigned bytes_rcvd;
98059ffb30fSJeff Kirsher     unsigned int_status, eth_status, rx_status, tx_status;
98159ffb30fSJeff Kirsher     unsigned rsr, pktlen;
98259ffb30fSJeff Kirsher     ulong start_ticks = jiffies; /* fixme: jiffies rollover every 497 days
98359ffb30fSJeff Kirsher 				  * is this something to worry about?
98459ffb30fSJeff Kirsher 				  * -- on a laptop?
98559ffb30fSJeff Kirsher 				  */
98659ffb30fSJeff Kirsher 
98759ffb30fSJeff Kirsher     if (!netif_device_present(dev))
98859ffb30fSJeff Kirsher 	return IRQ_HANDLED;
98959ffb30fSJeff Kirsher 
99059ffb30fSJeff Kirsher     ioaddr = dev->base_addr;
99159ffb30fSJeff Kirsher     if (lp->mohawk) { /* must disable the interrupt */
99259ffb30fSJeff Kirsher 	PutByte(XIRCREG_CR, 0);
99359ffb30fSJeff Kirsher     }
99459ffb30fSJeff Kirsher 
99559ffb30fSJeff Kirsher     pr_debug("%s: interrupt %d at %#x.\n", dev->name, irq, ioaddr);
99659ffb30fSJeff Kirsher 
99759ffb30fSJeff Kirsher     saved_page = GetByte(XIRCREG_PR);
99859ffb30fSJeff Kirsher     /* Read the ISR to see whats the cause for the interrupt.
99959ffb30fSJeff Kirsher      * This also clears the interrupt flags on CE2 cards
100059ffb30fSJeff Kirsher      */
100159ffb30fSJeff Kirsher     int_status = GetByte(XIRCREG_ISR);
100259ffb30fSJeff Kirsher     bytes_rcvd = 0;
100359ffb30fSJeff Kirsher   loop_entry:
100459ffb30fSJeff Kirsher     if (int_status == 0xff) { /* card may be ejected */
100559ffb30fSJeff Kirsher 	pr_debug("%s: interrupt %d for dead card\n", dev->name, irq);
100659ffb30fSJeff Kirsher 	goto leave;
100759ffb30fSJeff Kirsher     }
100859ffb30fSJeff Kirsher     eth_status = GetByte(XIRCREG_ESR);
100959ffb30fSJeff Kirsher 
101059ffb30fSJeff Kirsher     SelectPage(0x40);
101159ffb30fSJeff Kirsher     rx_status  = GetByte(XIRCREG40_RXST0);
101259ffb30fSJeff Kirsher     PutByte(XIRCREG40_RXST0, (~rx_status & 0xff));
101359ffb30fSJeff Kirsher     tx_status = GetByte(XIRCREG40_TXST0);
101459ffb30fSJeff Kirsher     tx_status |= GetByte(XIRCREG40_TXST1) << 8;
101559ffb30fSJeff Kirsher     PutByte(XIRCREG40_TXST0, 0);
101659ffb30fSJeff Kirsher     PutByte(XIRCREG40_TXST1, 0);
101759ffb30fSJeff Kirsher 
101859ffb30fSJeff Kirsher     pr_debug("%s: ISR=%#2.2x ESR=%#2.2x RSR=%#2.2x TSR=%#4.4x\n",
101959ffb30fSJeff Kirsher 	  dev->name, int_status, eth_status, rx_status, tx_status);
102059ffb30fSJeff Kirsher 
102159ffb30fSJeff Kirsher     /***** receive section ******/
102259ffb30fSJeff Kirsher     SelectPage(0);
102359ffb30fSJeff Kirsher     while (eth_status & FullPktRcvd) {
102459ffb30fSJeff Kirsher 	rsr = GetByte(XIRCREG0_RSR);
102559ffb30fSJeff Kirsher 	if (bytes_rcvd > maxrx_bytes && (rsr & PktRxOk)) {
102659ffb30fSJeff Kirsher 	    /* too many bytes received during this int, drop the rest of the
102759ffb30fSJeff Kirsher 	     * packets */
102859ffb30fSJeff Kirsher 	    dev->stats.rx_dropped++;
102959ffb30fSJeff Kirsher 	    pr_debug("%s: RX drop, too much done\n", dev->name);
103059ffb30fSJeff Kirsher 	} else if (rsr & PktRxOk) {
103159ffb30fSJeff Kirsher 	    struct sk_buff *skb;
103259ffb30fSJeff Kirsher 
103359ffb30fSJeff Kirsher 	    pktlen = GetWord(XIRCREG0_RBC);
103459ffb30fSJeff Kirsher 	    bytes_rcvd += pktlen;
103559ffb30fSJeff Kirsher 
103659ffb30fSJeff Kirsher 	    pr_debug("rsr=%#02x packet_length=%u\n", rsr, pktlen);
103759ffb30fSJeff Kirsher 
1038dae2e9f4SPradeep A. Dalvi 	    /* 1 extra so we can use insw */
1039dae2e9f4SPradeep A. Dalvi 	    skb = netdev_alloc_skb(dev, pktlen + 3);
104059ffb30fSJeff Kirsher 	    if (!skb) {
104159ffb30fSJeff Kirsher 		dev->stats.rx_dropped++;
104259ffb30fSJeff Kirsher 	    } else { /* okay get the packet */
104359ffb30fSJeff Kirsher 		skb_reserve(skb, 2);
104459ffb30fSJeff Kirsher 		if (lp->silicon == 0 ) { /* work around a hardware bug */
104559ffb30fSJeff Kirsher 		    unsigned rhsa; /* receive start address */
104659ffb30fSJeff Kirsher 
104759ffb30fSJeff Kirsher 		    SelectPage(5);
104859ffb30fSJeff Kirsher 		    rhsa = GetWord(XIRCREG5_RHSA0);
104959ffb30fSJeff Kirsher 		    SelectPage(0);
105059ffb30fSJeff Kirsher 		    rhsa += 3; /* skip control infos */
105159ffb30fSJeff Kirsher 		    if (rhsa >= 0x8000)
105259ffb30fSJeff Kirsher 			rhsa = 0;
105359ffb30fSJeff Kirsher 		    if (rhsa + pktlen > 0x8000) {
105459ffb30fSJeff Kirsher 			unsigned i;
105559ffb30fSJeff Kirsher 			u_char *buf = skb_put(skb, pktlen);
105659ffb30fSJeff Kirsher 			for (i=0; i < pktlen ; i++, rhsa++) {
105759ffb30fSJeff Kirsher 			    buf[i] = GetByte(XIRCREG_EDP);
105859ffb30fSJeff Kirsher 			    if (rhsa == 0x8000) {
105959ffb30fSJeff Kirsher 				rhsa = 0;
106059ffb30fSJeff Kirsher 				i--;
106159ffb30fSJeff Kirsher 			    }
106259ffb30fSJeff Kirsher 			}
106359ffb30fSJeff Kirsher 		    } else {
106459ffb30fSJeff Kirsher 			insw(ioaddr+XIRCREG_EDP,
106559ffb30fSJeff Kirsher 				skb_put(skb, pktlen), (pktlen+1)>>1);
106659ffb30fSJeff Kirsher 		    }
106759ffb30fSJeff Kirsher 		}
106859ffb30fSJeff Kirsher 	      #if 0
106959ffb30fSJeff Kirsher 		else if (lp->mohawk) {
107059ffb30fSJeff Kirsher 		    /* To use this 32 bit access we should use
107159ffb30fSJeff Kirsher 		     * a manual optimized loop
107259ffb30fSJeff Kirsher 		     * Also the words are swapped, we can get more
107359ffb30fSJeff Kirsher 		     * performance by using 32 bit access and swapping
107459ffb30fSJeff Kirsher 		     * the words in a register. Will need this for cardbus
107559ffb30fSJeff Kirsher 		     *
107659ffb30fSJeff Kirsher 		     * Note: don't forget to change the ALLOC_SKB to .. +3
107759ffb30fSJeff Kirsher 		     */
107859ffb30fSJeff Kirsher 		    unsigned i;
107959ffb30fSJeff Kirsher 		    u_long *p = skb_put(skb, pktlen);
108059ffb30fSJeff Kirsher 		    register u_long a;
108159ffb30fSJeff Kirsher 		    unsigned int edpreg = ioaddr+XIRCREG_EDP-2;
108259ffb30fSJeff Kirsher 		    for (i=0; i < len ; i += 4, p++) {
108359ffb30fSJeff Kirsher 			a = inl(edpreg);
108459ffb30fSJeff Kirsher 			__asm__("rorl $16,%0\n\t"
108559ffb30fSJeff Kirsher 				:"=q" (a)
108659ffb30fSJeff Kirsher 				: "0" (a));
108759ffb30fSJeff Kirsher 			*p = a;
108859ffb30fSJeff Kirsher 		    }
108959ffb30fSJeff Kirsher 		}
109059ffb30fSJeff Kirsher 	      #endif
109159ffb30fSJeff Kirsher 		else {
109259ffb30fSJeff Kirsher 		    insw(ioaddr+XIRCREG_EDP, skb_put(skb, pktlen),
109359ffb30fSJeff Kirsher 			    (pktlen+1)>>1);
109459ffb30fSJeff Kirsher 		}
109559ffb30fSJeff Kirsher 		skb->protocol = eth_type_trans(skb, dev);
109659ffb30fSJeff Kirsher 		netif_rx(skb);
109759ffb30fSJeff Kirsher 		dev->stats.rx_packets++;
109859ffb30fSJeff Kirsher 		dev->stats.rx_bytes += pktlen;
109959ffb30fSJeff Kirsher 		if (!(rsr & PhyPkt))
110059ffb30fSJeff Kirsher 		    dev->stats.multicast++;
110159ffb30fSJeff Kirsher 	    }
110259ffb30fSJeff Kirsher 	} else { /* bad packet */
110359ffb30fSJeff Kirsher 	    pr_debug("rsr=%#02x\n", rsr);
110459ffb30fSJeff Kirsher 	}
110559ffb30fSJeff Kirsher 	if (rsr & PktTooLong) {
110659ffb30fSJeff Kirsher 	    dev->stats.rx_frame_errors++;
110759ffb30fSJeff Kirsher 	    pr_debug("%s: Packet too long\n", dev->name);
110859ffb30fSJeff Kirsher 	}
110959ffb30fSJeff Kirsher 	if (rsr & CRCErr) {
111059ffb30fSJeff Kirsher 	    dev->stats.rx_crc_errors++;
111159ffb30fSJeff Kirsher 	    pr_debug("%s: CRC error\n", dev->name);
111259ffb30fSJeff Kirsher 	}
111359ffb30fSJeff Kirsher 	if (rsr & AlignErr) {
111459ffb30fSJeff Kirsher 	    dev->stats.rx_fifo_errors++; /* okay ? */
111559ffb30fSJeff Kirsher 	    pr_debug("%s: Alignment error\n", dev->name);
111659ffb30fSJeff Kirsher 	}
111759ffb30fSJeff Kirsher 
111859ffb30fSJeff Kirsher 	/* clear the received/dropped/error packet */
111959ffb30fSJeff Kirsher 	PutWord(XIRCREG0_DO, 0x8000); /* issue cmd: skip_rx_packet */
112059ffb30fSJeff Kirsher 
112159ffb30fSJeff Kirsher 	/* get the new ethernet status */
112259ffb30fSJeff Kirsher 	eth_status = GetByte(XIRCREG_ESR);
112359ffb30fSJeff Kirsher     }
112459ffb30fSJeff Kirsher     if (rx_status & 0x10) { /* Receive overrun */
112559ffb30fSJeff Kirsher 	dev->stats.rx_over_errors++;
112659ffb30fSJeff Kirsher 	PutByte(XIRCREG_CR, ClearRxOvrun);
112759ffb30fSJeff Kirsher 	pr_debug("receive overrun cleared\n");
112859ffb30fSJeff Kirsher     }
112959ffb30fSJeff Kirsher 
113059ffb30fSJeff Kirsher     /***** transmit section ******/
113159ffb30fSJeff Kirsher     if (int_status & PktTxed) {
113259ffb30fSJeff Kirsher 	unsigned n, nn;
113359ffb30fSJeff Kirsher 
113459ffb30fSJeff Kirsher 	n = lp->last_ptr_value;
113559ffb30fSJeff Kirsher 	nn = GetByte(XIRCREG0_PTR);
113659ffb30fSJeff Kirsher 	lp->last_ptr_value = nn;
113759ffb30fSJeff Kirsher 	if (nn < n) /* rollover */
113859ffb30fSJeff Kirsher 	    dev->stats.tx_packets += 256 - n;
113959ffb30fSJeff Kirsher 	else if (n == nn) { /* happens sometimes - don't know why */
114059ffb30fSJeff Kirsher 	    pr_debug("PTR not changed?\n");
114159ffb30fSJeff Kirsher 	} else
114259ffb30fSJeff Kirsher 	    dev->stats.tx_packets += lp->last_ptr_value - n;
114359ffb30fSJeff Kirsher 	netif_wake_queue(dev);
114459ffb30fSJeff Kirsher     }
1145ac5fd4f4SColin Ian King     if (tx_status & 0x0002) {	/* Excessive collisions */
1146ac5fd4f4SColin Ian King 	pr_debug("tx restarted due to excessive collisions\n");
114759ffb30fSJeff Kirsher 	PutByte(XIRCREG_CR, RestartTx);  /* restart transmitter process */
114859ffb30fSJeff Kirsher     }
114959ffb30fSJeff Kirsher     if (tx_status & 0x0040)
115059ffb30fSJeff Kirsher 	dev->stats.tx_aborted_errors++;
115159ffb30fSJeff Kirsher 
115259ffb30fSJeff Kirsher     /* recalculate our work chunk so that we limit the duration of this
115359ffb30fSJeff Kirsher      * ISR to about 1/10 of a second.
115459ffb30fSJeff Kirsher      * Calculate only if we received a reasonable amount of bytes.
115559ffb30fSJeff Kirsher      */
115659ffb30fSJeff Kirsher     if (bytes_rcvd > 1000) {
115759ffb30fSJeff Kirsher 	u_long duration = jiffies - start_ticks;
115859ffb30fSJeff Kirsher 
115959ffb30fSJeff Kirsher 	if (duration >= HZ/10) { /* if more than about 1/10 second */
116059ffb30fSJeff Kirsher 	    maxrx_bytes = (bytes_rcvd * (HZ/10)) / duration;
116159ffb30fSJeff Kirsher 	    if (maxrx_bytes < 2000)
116259ffb30fSJeff Kirsher 		maxrx_bytes = 2000;
116359ffb30fSJeff Kirsher 	    else if (maxrx_bytes > 22000)
116459ffb30fSJeff Kirsher 		maxrx_bytes = 22000;
116559ffb30fSJeff Kirsher 	    pr_debug("set maxrx=%u (rcvd=%u ticks=%lu)\n",
116659ffb30fSJeff Kirsher 		  maxrx_bytes, bytes_rcvd, duration);
116759ffb30fSJeff Kirsher 	} else if (!duration && maxrx_bytes < 22000) {
116859ffb30fSJeff Kirsher 	    /* now much faster */
116959ffb30fSJeff Kirsher 	    maxrx_bytes += 2000;
117059ffb30fSJeff Kirsher 	    if (maxrx_bytes > 22000)
117159ffb30fSJeff Kirsher 		maxrx_bytes = 22000;
117259ffb30fSJeff Kirsher 	    pr_debug("set maxrx=%u\n", maxrx_bytes);
117359ffb30fSJeff Kirsher 	}
117459ffb30fSJeff Kirsher     }
117559ffb30fSJeff Kirsher 
117659ffb30fSJeff Kirsher   leave:
117759ffb30fSJeff Kirsher     if (lockup_hack) {
117859ffb30fSJeff Kirsher 	if (int_status != 0xff && (int_status = GetByte(XIRCREG_ISR)) != 0)
117959ffb30fSJeff Kirsher 	    goto loop_entry;
118059ffb30fSJeff Kirsher     }
118159ffb30fSJeff Kirsher     SelectPage(saved_page);
118259ffb30fSJeff Kirsher     PutByte(XIRCREG_CR, EnableIntr);  /* re-enable interrupts */
118359ffb30fSJeff Kirsher     /* Instead of dropping packets during a receive, we could
118459ffb30fSJeff Kirsher      * force an interrupt with this command:
118559ffb30fSJeff Kirsher      *	  PutByte(XIRCREG_CR, EnableIntr|ForceIntr);
118659ffb30fSJeff Kirsher      */
118759ffb30fSJeff Kirsher     return IRQ_HANDLED;
118859ffb30fSJeff Kirsher } /* xirc2ps_interrupt */
118959ffb30fSJeff Kirsher 
119059ffb30fSJeff Kirsher /*====================================================================*/
119159ffb30fSJeff Kirsher 
119259ffb30fSJeff Kirsher static void
xirc2ps_tx_timeout_task(struct work_struct * work)119359ffb30fSJeff Kirsher xirc2ps_tx_timeout_task(struct work_struct *work)
119459ffb30fSJeff Kirsher {
1195f8653464SHimangi Saraogi 	struct local_info *local =
1196f8653464SHimangi Saraogi 		container_of(work, struct local_info, tx_timeout_task);
119759ffb30fSJeff Kirsher 	struct net_device *dev = local->dev;
119859ffb30fSJeff Kirsher     /* reset the card */
119959ffb30fSJeff Kirsher     do_reset(dev,1);
1200860e9538SFlorian Westphal     netif_trans_update(dev); /* prevent tx timeout */
120159ffb30fSJeff Kirsher     netif_wake_queue(dev);
120259ffb30fSJeff Kirsher }
120359ffb30fSJeff Kirsher 
120459ffb30fSJeff Kirsher static void
xirc_tx_timeout(struct net_device * dev,unsigned int txqueue)12050290bd29SMichael S. Tsirkin xirc_tx_timeout(struct net_device *dev, unsigned int txqueue)
120659ffb30fSJeff Kirsher {
1207f8653464SHimangi Saraogi     struct local_info *lp = netdev_priv(dev);
120859ffb30fSJeff Kirsher     dev->stats.tx_errors++;
120959ffb30fSJeff Kirsher     netdev_notice(dev, "transmit timed out\n");
121059ffb30fSJeff Kirsher     schedule_work(&lp->tx_timeout_task);
121159ffb30fSJeff Kirsher }
121259ffb30fSJeff Kirsher 
121359ffb30fSJeff Kirsher static netdev_tx_t
do_start_xmit(struct sk_buff * skb,struct net_device * dev)121459ffb30fSJeff Kirsher do_start_xmit(struct sk_buff *skb, struct net_device *dev)
121559ffb30fSJeff Kirsher {
1216f8653464SHimangi Saraogi     struct local_info *lp = netdev_priv(dev);
121759ffb30fSJeff Kirsher     unsigned int ioaddr = dev->base_addr;
121859ffb30fSJeff Kirsher     int okay;
121959ffb30fSJeff Kirsher     unsigned freespace;
122059ffb30fSJeff Kirsher     unsigned pktlen = skb->len;
122159ffb30fSJeff Kirsher 
122259ffb30fSJeff Kirsher     pr_debug("do_start_xmit(skb=%p, dev=%p) len=%u\n",
122359ffb30fSJeff Kirsher 	  skb, dev, pktlen);
122459ffb30fSJeff Kirsher 
122559ffb30fSJeff Kirsher 
122659ffb30fSJeff Kirsher     /* adjust the packet length to min. required
122759ffb30fSJeff Kirsher      * and hope that the buffer is large enough
122859ffb30fSJeff Kirsher      * to provide some random data.
122959ffb30fSJeff Kirsher      * fixme: For Mohawk we can change this by sending
123059ffb30fSJeff Kirsher      * a larger packetlen than we actually have; the chip will
123159ffb30fSJeff Kirsher      * pad this in his buffer with random bytes
123259ffb30fSJeff Kirsher      */
123359ffb30fSJeff Kirsher     if (pktlen < ETH_ZLEN)
123459ffb30fSJeff Kirsher     {
123559ffb30fSJeff Kirsher         if (skb_padto(skb, ETH_ZLEN))
123659ffb30fSJeff Kirsher 		return NETDEV_TX_OK;
123759ffb30fSJeff Kirsher 	pktlen = ETH_ZLEN;
123859ffb30fSJeff Kirsher     }
123959ffb30fSJeff Kirsher 
124059ffb30fSJeff Kirsher     netif_stop_queue(dev);
124159ffb30fSJeff Kirsher     SelectPage(0);
124259ffb30fSJeff Kirsher     PutWord(XIRCREG0_TRS, (u_short)pktlen+2);
124359ffb30fSJeff Kirsher     freespace = GetWord(XIRCREG0_TSO);
124459ffb30fSJeff Kirsher     okay = freespace & 0x8000;
124559ffb30fSJeff Kirsher     freespace &= 0x7fff;
124659ffb30fSJeff Kirsher     /* TRS doesn't work - (indeed it is eliminated with sil-rev 1) */
124759ffb30fSJeff Kirsher     okay = pktlen +2 < freespace;
124859ffb30fSJeff Kirsher     pr_debug("%s: avail. tx space=%u%s\n",
124959ffb30fSJeff Kirsher 	  dev->name, freespace, okay ? " (okay)":" (not enough)");
125059ffb30fSJeff Kirsher     if (!okay) { /* not enough space */
125159ffb30fSJeff Kirsher 	return NETDEV_TX_BUSY;  /* upper layer may decide to requeue this packet */
125259ffb30fSJeff Kirsher     }
125359ffb30fSJeff Kirsher     /* send the packet */
125459ffb30fSJeff Kirsher     PutWord(XIRCREG_EDP, (u_short)pktlen);
125559ffb30fSJeff Kirsher     outsw(ioaddr+XIRCREG_EDP, skb->data, pktlen>>1);
125659ffb30fSJeff Kirsher     if (pktlen & 1)
125759ffb30fSJeff Kirsher 	PutByte(XIRCREG_EDP, skb->data[pktlen-1]);
125859ffb30fSJeff Kirsher 
125959ffb30fSJeff Kirsher     if (lp->mohawk)
126059ffb30fSJeff Kirsher 	PutByte(XIRCREG_CR, TransmitPacket|EnableIntr);
126159ffb30fSJeff Kirsher 
126259ffb30fSJeff Kirsher     dev_kfree_skb (skb);
126359ffb30fSJeff Kirsher     dev->stats.tx_bytes += pktlen;
126459ffb30fSJeff Kirsher     netif_start_queue(dev);
126559ffb30fSJeff Kirsher     return NETDEV_TX_OK;
126659ffb30fSJeff Kirsher }
126759ffb30fSJeff Kirsher 
126859ffb30fSJeff Kirsher struct set_address_info {
126959ffb30fSJeff Kirsher 	int reg_nr;
127059ffb30fSJeff Kirsher 	int page_nr;
127159ffb30fSJeff Kirsher 	int mohawk;
127259ffb30fSJeff Kirsher 	unsigned int ioaddr;
127359ffb30fSJeff Kirsher };
127459ffb30fSJeff Kirsher 
set_address(struct set_address_info * sa_info,const char * addr)127576660757SJakub Kicinski static void set_address(struct set_address_info *sa_info, const char *addr)
127659ffb30fSJeff Kirsher {
127759ffb30fSJeff Kirsher 	unsigned int ioaddr = sa_info->ioaddr;
127859ffb30fSJeff Kirsher 	int i;
127959ffb30fSJeff Kirsher 
128059ffb30fSJeff Kirsher 	for (i = 0; i < 6; i++) {
128159ffb30fSJeff Kirsher 		if (sa_info->reg_nr > 15) {
128259ffb30fSJeff Kirsher 			sa_info->reg_nr = 8;
128359ffb30fSJeff Kirsher 			sa_info->page_nr++;
128459ffb30fSJeff Kirsher 			SelectPage(sa_info->page_nr);
128559ffb30fSJeff Kirsher 		}
128659ffb30fSJeff Kirsher 		if (sa_info->mohawk)
128759ffb30fSJeff Kirsher 			PutByte(sa_info->reg_nr++, addr[5 - i]);
128859ffb30fSJeff Kirsher 		else
128959ffb30fSJeff Kirsher 			PutByte(sa_info->reg_nr++, addr[i]);
129059ffb30fSJeff Kirsher 	}
129159ffb30fSJeff Kirsher }
129259ffb30fSJeff Kirsher 
129359ffb30fSJeff Kirsher /****************
129459ffb30fSJeff Kirsher  * Set all addresses: This first one is the individual address,
129559ffb30fSJeff Kirsher  * the next 9 addresses are taken from the multicast list and
129659ffb30fSJeff Kirsher  * the rest is filled with the individual address.
129759ffb30fSJeff Kirsher  */
set_addresses(struct net_device * dev)129859ffb30fSJeff Kirsher static void set_addresses(struct net_device *dev)
129959ffb30fSJeff Kirsher {
130059ffb30fSJeff Kirsher 	unsigned int ioaddr = dev->base_addr;
1301f8653464SHimangi Saraogi 	struct local_info *lp = netdev_priv(dev);
130259ffb30fSJeff Kirsher 	struct netdev_hw_addr *ha;
130359ffb30fSJeff Kirsher 	struct set_address_info sa_info;
130459ffb30fSJeff Kirsher 	int i;
130559ffb30fSJeff Kirsher 
130659ffb30fSJeff Kirsher 	/*
130759ffb30fSJeff Kirsher 	 * Setup the info structure so that by first set_address call it will do
130859ffb30fSJeff Kirsher 	 * SelectPage with the right page number. Hence these ones here.
130959ffb30fSJeff Kirsher 	 */
131059ffb30fSJeff Kirsher 	sa_info.reg_nr = 15 + 1;
131159ffb30fSJeff Kirsher 	sa_info.page_nr = 0x50 - 1;
131259ffb30fSJeff Kirsher 	sa_info.mohawk = lp->mohawk;
131359ffb30fSJeff Kirsher 	sa_info.ioaddr = ioaddr;
131459ffb30fSJeff Kirsher 
131559ffb30fSJeff Kirsher 	set_address(&sa_info, dev->dev_addr);
131659ffb30fSJeff Kirsher 	i = 0;
131759ffb30fSJeff Kirsher 	netdev_for_each_mc_addr(ha, dev) {
131859ffb30fSJeff Kirsher 		if (i++ == 9)
131959ffb30fSJeff Kirsher 			break;
132059ffb30fSJeff Kirsher 		set_address(&sa_info, ha->addr);
132159ffb30fSJeff Kirsher 	}
132259ffb30fSJeff Kirsher 	while (i++ < 9)
132359ffb30fSJeff Kirsher 		set_address(&sa_info, dev->dev_addr);
132459ffb30fSJeff Kirsher 	SelectPage(0);
132559ffb30fSJeff Kirsher }
132659ffb30fSJeff Kirsher 
132759ffb30fSJeff Kirsher /****************
132859ffb30fSJeff Kirsher  * Set or clear the multicast filter for this adaptor.
132959ffb30fSJeff Kirsher  * We can filter up to 9 addresses, if more are requested we set
133059ffb30fSJeff Kirsher  * multicast promiscuous mode.
133159ffb30fSJeff Kirsher  */
133259ffb30fSJeff Kirsher 
133359ffb30fSJeff Kirsher static void
set_multicast_list(struct net_device * dev)133459ffb30fSJeff Kirsher set_multicast_list(struct net_device *dev)
133559ffb30fSJeff Kirsher {
133659ffb30fSJeff Kirsher     unsigned int ioaddr = dev->base_addr;
133759ffb30fSJeff Kirsher     unsigned value;
133859ffb30fSJeff Kirsher 
133959ffb30fSJeff Kirsher     SelectPage(0x42);
134059ffb30fSJeff Kirsher     value = GetByte(XIRCREG42_SWC1) & 0xC0;
134159ffb30fSJeff Kirsher 
134259ffb30fSJeff Kirsher     if (dev->flags & IFF_PROMISC) { /* snoop */
134359ffb30fSJeff Kirsher 	PutByte(XIRCREG42_SWC1, value | 0x06); /* set MPE and PME */
134459ffb30fSJeff Kirsher     } else if (netdev_mc_count(dev) > 9 || (dev->flags & IFF_ALLMULTI)) {
134559ffb30fSJeff Kirsher 	PutByte(XIRCREG42_SWC1, value | 0x02); /* set MPE */
134659ffb30fSJeff Kirsher     } else if (!netdev_mc_empty(dev)) {
134759ffb30fSJeff Kirsher 	/* the chip can filter 9 addresses perfectly */
134859ffb30fSJeff Kirsher 	PutByte(XIRCREG42_SWC1, value | 0x01);
134959ffb30fSJeff Kirsher 	SelectPage(0x40);
135059ffb30fSJeff Kirsher 	PutByte(XIRCREG40_CMD0, Offline);
135159ffb30fSJeff Kirsher 	set_addresses(dev);
135259ffb30fSJeff Kirsher 	SelectPage(0x40);
135359ffb30fSJeff Kirsher 	PutByte(XIRCREG40_CMD0, EnableRecv | Online);
135459ffb30fSJeff Kirsher     } else { /* standard usage */
135559ffb30fSJeff Kirsher 	PutByte(XIRCREG42_SWC1, value | 0x00);
135659ffb30fSJeff Kirsher     }
135759ffb30fSJeff Kirsher     SelectPage(0);
135859ffb30fSJeff Kirsher }
135959ffb30fSJeff Kirsher 
136059ffb30fSJeff Kirsher static int
do_config(struct net_device * dev,struct ifmap * map)136159ffb30fSJeff Kirsher do_config(struct net_device *dev, struct ifmap *map)
136259ffb30fSJeff Kirsher {
1363f8653464SHimangi Saraogi     struct local_info *local = netdev_priv(dev);
136459ffb30fSJeff Kirsher 
136559ffb30fSJeff Kirsher     pr_debug("do_config(%p)\n", dev);
136659ffb30fSJeff Kirsher     if (map->port != 255 && map->port != dev->if_port) {
136759ffb30fSJeff Kirsher 	if (map->port > 4)
136859ffb30fSJeff Kirsher 	    return -EINVAL;
136959ffb30fSJeff Kirsher 	if (!map->port) {
137059ffb30fSJeff Kirsher 	    local->probe_port = 1;
137159ffb30fSJeff Kirsher 	    dev->if_port = 1;
137259ffb30fSJeff Kirsher 	} else {
137359ffb30fSJeff Kirsher 	    local->probe_port = 0;
137459ffb30fSJeff Kirsher 	    dev->if_port = map->port;
137559ffb30fSJeff Kirsher 	}
137659ffb30fSJeff Kirsher 	netdev_info(dev, "switching to %s port\n", if_names[dev->if_port]);
137759ffb30fSJeff Kirsher 	do_reset(dev,1);  /* not the fine way :-) */
137859ffb30fSJeff Kirsher     }
137959ffb30fSJeff Kirsher     return 0;
138059ffb30fSJeff Kirsher }
138159ffb30fSJeff Kirsher 
138259ffb30fSJeff Kirsher /****************
138359ffb30fSJeff Kirsher  * Open the driver
138459ffb30fSJeff Kirsher  */
138559ffb30fSJeff Kirsher static int
do_open(struct net_device * dev)138659ffb30fSJeff Kirsher do_open(struct net_device *dev)
138759ffb30fSJeff Kirsher {
1388f8653464SHimangi Saraogi     struct local_info *lp = netdev_priv(dev);
138959ffb30fSJeff Kirsher     struct pcmcia_device *link = lp->p_dev;
139059ffb30fSJeff Kirsher 
139159ffb30fSJeff Kirsher     dev_dbg(&link->dev, "do_open(%p)\n", dev);
139259ffb30fSJeff Kirsher 
139359ffb30fSJeff Kirsher     /* Check that the PCMCIA card is still here. */
139459ffb30fSJeff Kirsher     /* Physical device present signature. */
139559ffb30fSJeff Kirsher     if (!pcmcia_dev_present(link))
139659ffb30fSJeff Kirsher 	return -ENODEV;
139759ffb30fSJeff Kirsher 
139859ffb30fSJeff Kirsher     /* okay */
139959ffb30fSJeff Kirsher     link->open++;
140059ffb30fSJeff Kirsher 
140159ffb30fSJeff Kirsher     netif_start_queue(dev);
140259ffb30fSJeff Kirsher     do_reset(dev,1);
140359ffb30fSJeff Kirsher 
140459ffb30fSJeff Kirsher     return 0;
140559ffb30fSJeff Kirsher }
140659ffb30fSJeff Kirsher 
netdev_get_drvinfo(struct net_device * dev,struct ethtool_drvinfo * info)140759ffb30fSJeff Kirsher static void netdev_get_drvinfo(struct net_device *dev,
140859ffb30fSJeff Kirsher 			       struct ethtool_drvinfo *info)
140959ffb30fSJeff Kirsher {
1410f029c781SWolfram Sang 	strscpy(info->driver, "xirc2ps_cs", sizeof(info->driver));
14117826d43fSJiri Pirko 	snprintf(info->bus_info, sizeof(info->bus_info), "PCMCIA 0x%lx",
14127826d43fSJiri Pirko 		 dev->base_addr);
141359ffb30fSJeff Kirsher }
141459ffb30fSJeff Kirsher 
141559ffb30fSJeff Kirsher static const struct ethtool_ops netdev_ethtool_ops = {
141659ffb30fSJeff Kirsher 	.get_drvinfo		= netdev_get_drvinfo,
141759ffb30fSJeff Kirsher };
141859ffb30fSJeff Kirsher 
141959ffb30fSJeff Kirsher static int
do_ioctl(struct net_device * dev,struct ifreq * rq,int cmd)142059ffb30fSJeff Kirsher do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
142159ffb30fSJeff Kirsher {
1422f8653464SHimangi Saraogi     struct local_info *local = netdev_priv(dev);
142359ffb30fSJeff Kirsher     unsigned int ioaddr = dev->base_addr;
142459ffb30fSJeff Kirsher     struct mii_ioctl_data *data = if_mii(rq);
142559ffb30fSJeff Kirsher 
142659ffb30fSJeff Kirsher     pr_debug("%s: ioctl(%-.6s, %#04x) %04x %04x %04x %04x\n",
142759ffb30fSJeff Kirsher 	  dev->name, rq->ifr_ifrn.ifrn_name, cmd,
142859ffb30fSJeff Kirsher 	  data->phy_id, data->reg_num, data->val_in, data->val_out);
142959ffb30fSJeff Kirsher 
143059ffb30fSJeff Kirsher     if (!local->mohawk)
143159ffb30fSJeff Kirsher 	return -EOPNOTSUPP;
143259ffb30fSJeff Kirsher 
143359ffb30fSJeff Kirsher     switch(cmd) {
143459ffb30fSJeff Kirsher       case SIOCGMIIPHY:		/* Get the address of the PHY in use. */
143559ffb30fSJeff Kirsher 	data->phy_id = 0;	/* we have only this address */
1436df561f66SGustavo A. R. Silva 	fallthrough;
143759ffb30fSJeff Kirsher       case SIOCGMIIREG:		/* Read the specified MII register. */
143859ffb30fSJeff Kirsher 	data->val_out = mii_rd(ioaddr, data->phy_id & 0x1f,
143959ffb30fSJeff Kirsher 			       data->reg_num & 0x1f);
144059ffb30fSJeff Kirsher 	break;
144159ffb30fSJeff Kirsher       case SIOCSMIIREG:		/* Write the specified MII register */
144259ffb30fSJeff Kirsher 	mii_wr(ioaddr, data->phy_id & 0x1f, data->reg_num & 0x1f, data->val_in,
144359ffb30fSJeff Kirsher 	       16);
144459ffb30fSJeff Kirsher 	break;
144559ffb30fSJeff Kirsher       default:
144659ffb30fSJeff Kirsher 	return -EOPNOTSUPP;
144759ffb30fSJeff Kirsher     }
144859ffb30fSJeff Kirsher     return 0;
144959ffb30fSJeff Kirsher }
145059ffb30fSJeff Kirsher 
145159ffb30fSJeff Kirsher static void
hardreset(struct net_device * dev)145259ffb30fSJeff Kirsher hardreset(struct net_device *dev)
145359ffb30fSJeff Kirsher {
1454f8653464SHimangi Saraogi     struct local_info *local = netdev_priv(dev);
145559ffb30fSJeff Kirsher     unsigned int ioaddr = dev->base_addr;
145659ffb30fSJeff Kirsher 
145759ffb30fSJeff Kirsher     SelectPage(4);
145859ffb30fSJeff Kirsher     udelay(1);
145959ffb30fSJeff Kirsher     PutByte(XIRCREG4_GPR1, 0);	     /* clear bit 0: power down */
146059ffb30fSJeff Kirsher     msleep(40);				     /* wait 40 msec */
146159ffb30fSJeff Kirsher     if (local->mohawk)
146259ffb30fSJeff Kirsher 	PutByte(XIRCREG4_GPR1, 1);	 /* set bit 0: power up */
146359ffb30fSJeff Kirsher     else
146459ffb30fSJeff Kirsher 	PutByte(XIRCREG4_GPR1, 1 | 4);	 /* set bit 0: power up, bit 2: AIC */
146559ffb30fSJeff Kirsher     msleep(20);			     /* wait 20 msec */
146659ffb30fSJeff Kirsher }
146759ffb30fSJeff Kirsher 
146859ffb30fSJeff Kirsher static void
do_reset(struct net_device * dev,int full)146959ffb30fSJeff Kirsher do_reset(struct net_device *dev, int full)
147059ffb30fSJeff Kirsher {
1471f8653464SHimangi Saraogi     struct local_info *local = netdev_priv(dev);
147259ffb30fSJeff Kirsher     unsigned int ioaddr = dev->base_addr;
147359ffb30fSJeff Kirsher     unsigned value;
147459ffb30fSJeff Kirsher 
14755777cbbaSGaurav Singh     pr_debug("%s: do_reset(%p,%d)\n", dev->name, dev, full);
147659ffb30fSJeff Kirsher 
147759ffb30fSJeff Kirsher     hardreset(dev);
147859ffb30fSJeff Kirsher     PutByte(XIRCREG_CR, SoftReset); /* set */
147959ffb30fSJeff Kirsher     msleep(20);			     /* wait 20 msec */
148059ffb30fSJeff Kirsher     PutByte(XIRCREG_CR, 0);	     /* clear */
148159ffb30fSJeff Kirsher     msleep(40);			     /* wait 40 msec */
148259ffb30fSJeff Kirsher     if (local->mohawk) {
148359ffb30fSJeff Kirsher 	SelectPage(4);
148459ffb30fSJeff Kirsher 	/* set pin GP1 and GP2 to output  (0x0c)
148559ffb30fSJeff Kirsher 	 * set GP1 to low to power up the ML6692 (0x00)
148659ffb30fSJeff Kirsher 	 * set GP2 to high to power up the 10Mhz chip  (0x02)
148759ffb30fSJeff Kirsher 	 */
148859ffb30fSJeff Kirsher 	PutByte(XIRCREG4_GPR0, 0x0e);
148959ffb30fSJeff Kirsher     }
149059ffb30fSJeff Kirsher 
149159ffb30fSJeff Kirsher     /* give the circuits some time to power up */
149259ffb30fSJeff Kirsher     msleep(500);			/* about 500ms */
149359ffb30fSJeff Kirsher 
149459ffb30fSJeff Kirsher     local->last_ptr_value = 0;
149559ffb30fSJeff Kirsher     local->silicon = local->mohawk ? (GetByte(XIRCREG4_BOV) & 0x70) >> 4
149659ffb30fSJeff Kirsher 				   : (GetByte(XIRCREG4_BOV) & 0x30) >> 4;
149759ffb30fSJeff Kirsher 
149859ffb30fSJeff Kirsher     if (local->probe_port) {
149959ffb30fSJeff Kirsher 	if (!local->mohawk) {
150059ffb30fSJeff Kirsher 	    SelectPage(4);
150159ffb30fSJeff Kirsher 	    PutByte(XIRCREG4_GPR0, 4);
150259ffb30fSJeff Kirsher 	    local->probe_port = 0;
150359ffb30fSJeff Kirsher 	}
150459ffb30fSJeff Kirsher     } else if (dev->if_port == 2) { /* enable 10Base2 */
150559ffb30fSJeff Kirsher 	SelectPage(0x42);
150659ffb30fSJeff Kirsher 	PutByte(XIRCREG42_SWC1, 0xC0);
150759ffb30fSJeff Kirsher     } else { /* enable 10BaseT */
150859ffb30fSJeff Kirsher 	SelectPage(0x42);
150959ffb30fSJeff Kirsher 	PutByte(XIRCREG42_SWC1, 0x80);
151059ffb30fSJeff Kirsher     }
151159ffb30fSJeff Kirsher     msleep(40);			     /* wait 40 msec to let it complete */
151259ffb30fSJeff Kirsher 
151359ffb30fSJeff Kirsher   #if 0
151459ffb30fSJeff Kirsher     {
151559ffb30fSJeff Kirsher 	SelectPage(0);
151659ffb30fSJeff Kirsher 	value = GetByte(XIRCREG_ESR);	 /* read the ESR */
151759ffb30fSJeff Kirsher 	pr_debug("%s: ESR is: %#02x\n", dev->name, value);
151859ffb30fSJeff Kirsher     }
151959ffb30fSJeff Kirsher   #endif
152059ffb30fSJeff Kirsher 
152159ffb30fSJeff Kirsher     /* setup the ECR */
152259ffb30fSJeff Kirsher     SelectPage(1);
152359ffb30fSJeff Kirsher     PutByte(XIRCREG1_IMR0, 0xff); /* allow all ints */
152459ffb30fSJeff Kirsher     PutByte(XIRCREG1_IMR1, 1	); /* and Set TxUnderrunDetect */
152559ffb30fSJeff Kirsher     value = GetByte(XIRCREG1_ECR);
152659ffb30fSJeff Kirsher   #if 0
152759ffb30fSJeff Kirsher     if (local->mohawk)
152859ffb30fSJeff Kirsher 	value |= DisableLinkPulse;
152959ffb30fSJeff Kirsher     PutByte(XIRCREG1_ECR, value);
153059ffb30fSJeff Kirsher   #endif
153159ffb30fSJeff Kirsher     pr_debug("%s: ECR is: %#02x\n", dev->name, value);
153259ffb30fSJeff Kirsher 
153359ffb30fSJeff Kirsher     SelectPage(0x42);
153459ffb30fSJeff Kirsher     PutByte(XIRCREG42_SWC0, 0x20); /* disable source insertion */
153559ffb30fSJeff Kirsher 
153659ffb30fSJeff Kirsher     if (local->silicon != 1) {
153759ffb30fSJeff Kirsher 	/* set the local memory dividing line.
153859ffb30fSJeff Kirsher 	 * The comments in the sample code say that this is only
153959ffb30fSJeff Kirsher 	 * settable with the scipper version 2 which is revision 0.
154059ffb30fSJeff Kirsher 	 * Always for CE3 cards
154159ffb30fSJeff Kirsher 	 */
154259ffb30fSJeff Kirsher 	SelectPage(2);
154359ffb30fSJeff Kirsher 	PutWord(XIRCREG2_RBS, 0x2000);
154459ffb30fSJeff Kirsher     }
154559ffb30fSJeff Kirsher 
154659ffb30fSJeff Kirsher     if (full)
154759ffb30fSJeff Kirsher 	set_addresses(dev);
154859ffb30fSJeff Kirsher 
154959ffb30fSJeff Kirsher     /* Hardware workaround:
155059ffb30fSJeff Kirsher      * The receive byte pointer after reset is off by 1 so we need
155159ffb30fSJeff Kirsher      * to move the offset pointer back to 0.
155259ffb30fSJeff Kirsher      */
155359ffb30fSJeff Kirsher     SelectPage(0);
155459ffb30fSJeff Kirsher     PutWord(XIRCREG0_DO, 0x2000); /* change offset command, off=0 */
155559ffb30fSJeff Kirsher 
155659ffb30fSJeff Kirsher     /* setup MAC IMRs and clear status registers */
155759ffb30fSJeff Kirsher     SelectPage(0x40);		     /* Bit 7 ... bit 0 */
155859ffb30fSJeff Kirsher     PutByte(XIRCREG40_RMASK0, 0xff); /* ROK, RAB, rsv, RO, CRC, AE, PTL, MP */
155959ffb30fSJeff Kirsher     PutByte(XIRCREG40_TMASK0, 0xff); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */
156059ffb30fSJeff Kirsher     PutByte(XIRCREG40_TMASK1, 0xb0); /* rsv, rsv, PTD, EXT, rsv,rsv,rsv, rsv*/
156159ffb30fSJeff Kirsher     PutByte(XIRCREG40_RXST0,  0x00); /* ROK, RAB, REN, RO, CRC, AE, PTL, MP */
156259ffb30fSJeff Kirsher     PutByte(XIRCREG40_TXST0,  0x00); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */
156359ffb30fSJeff Kirsher     PutByte(XIRCREG40_TXST1,  0x00); /* TEN, rsv, PTD, EXT, retry_counter:4  */
156459ffb30fSJeff Kirsher 
156559ffb30fSJeff Kirsher     if (full && local->mohawk && init_mii(dev)) {
156659ffb30fSJeff Kirsher 	if (dev->if_port == 4 || local->dingo || local->new_mii) {
156759ffb30fSJeff Kirsher 	    netdev_info(dev, "MII selected\n");
156859ffb30fSJeff Kirsher 	    SelectPage(2);
156959ffb30fSJeff Kirsher 	    PutByte(XIRCREG2_MSR, GetByte(XIRCREG2_MSR) | 0x08);
157059ffb30fSJeff Kirsher 	    msleep(20);
157159ffb30fSJeff Kirsher 	} else {
157259ffb30fSJeff Kirsher 	    netdev_info(dev, "MII detected; using 10mbs\n");
157359ffb30fSJeff Kirsher 	    SelectPage(0x42);
157459ffb30fSJeff Kirsher 	    if (dev->if_port == 2) /* enable 10Base2 */
157559ffb30fSJeff Kirsher 		PutByte(XIRCREG42_SWC1, 0xC0);
157659ffb30fSJeff Kirsher 	    else  /* enable 10BaseT */
157759ffb30fSJeff Kirsher 		PutByte(XIRCREG42_SWC1, 0x80);
157859ffb30fSJeff Kirsher 	    msleep(40);			/* wait 40 msec to let it complete */
157959ffb30fSJeff Kirsher 	}
158059ffb30fSJeff Kirsher 	if (full_duplex)
158159ffb30fSJeff Kirsher 	    PutByte(XIRCREG1_ECR, GetByte(XIRCREG1_ECR | FullDuplex));
158259ffb30fSJeff Kirsher     } else {  /* No MII */
158359ffb30fSJeff Kirsher 	SelectPage(0);
158459ffb30fSJeff Kirsher 	value = GetByte(XIRCREG_ESR);	 /* read the ESR */
158559ffb30fSJeff Kirsher 	dev->if_port = (value & MediaSelect) ? 1 : 2;
158659ffb30fSJeff Kirsher     }
158759ffb30fSJeff Kirsher 
158859ffb30fSJeff Kirsher     /* configure the LEDs */
158959ffb30fSJeff Kirsher     SelectPage(2);
159059ffb30fSJeff Kirsher     if (dev->if_port == 1 || dev->if_port == 4) /* TP: Link and Activity */
159159ffb30fSJeff Kirsher 	PutByte(XIRCREG2_LED, 0x3b);
159259ffb30fSJeff Kirsher     else			      /* Coax: Not-Collision and Activity */
159359ffb30fSJeff Kirsher 	PutByte(XIRCREG2_LED, 0x3a);
159459ffb30fSJeff Kirsher 
159559ffb30fSJeff Kirsher     if (local->dingo)
159659ffb30fSJeff Kirsher 	PutByte(0x0b, 0x04); /* 100 Mbit LED */
159759ffb30fSJeff Kirsher 
159859ffb30fSJeff Kirsher     /* enable receiver and put the mac online */
159959ffb30fSJeff Kirsher     if (full) {
160059ffb30fSJeff Kirsher 	set_multicast_list(dev);
160159ffb30fSJeff Kirsher 	SelectPage(0x40);
160259ffb30fSJeff Kirsher 	PutByte(XIRCREG40_CMD0, EnableRecv | Online);
160359ffb30fSJeff Kirsher     }
160459ffb30fSJeff Kirsher 
160559ffb30fSJeff Kirsher     /* setup Ethernet IMR and enable interrupts */
160659ffb30fSJeff Kirsher     SelectPage(1);
160759ffb30fSJeff Kirsher     PutByte(XIRCREG1_IMR0, 0xff);
160859ffb30fSJeff Kirsher     udelay(1);
160959ffb30fSJeff Kirsher     SelectPage(0);
161059ffb30fSJeff Kirsher     PutByte(XIRCREG_CR, EnableIntr);
161159ffb30fSJeff Kirsher     if (local->modem && !local->dingo) { /* do some magic */
161259ffb30fSJeff Kirsher 	if (!(GetByte(0x10) & 0x01))
161359ffb30fSJeff Kirsher 	    PutByte(0x10, 0x11); /* unmask master-int bit */
161459ffb30fSJeff Kirsher     }
161559ffb30fSJeff Kirsher 
161659ffb30fSJeff Kirsher     if (full)
161759ffb30fSJeff Kirsher 	netdev_info(dev, "media %s, silicon revision %d\n",
161859ffb30fSJeff Kirsher 		    if_names[dev->if_port], local->silicon);
161959ffb30fSJeff Kirsher     /* We should switch back to page 0 to avoid a bug in revision 0
162059ffb30fSJeff Kirsher      * where regs with offset below 8 can't be read after an access
162159ffb30fSJeff Kirsher      * to the MAC registers */
162259ffb30fSJeff Kirsher     SelectPage(0);
162359ffb30fSJeff Kirsher }
162459ffb30fSJeff Kirsher 
162559ffb30fSJeff Kirsher /****************
162659ffb30fSJeff Kirsher  * Initialize the Media-Independent-Interface
162759ffb30fSJeff Kirsher  * Returns: True if we have a good MII
162859ffb30fSJeff Kirsher  */
162959ffb30fSJeff Kirsher static int
init_mii(struct net_device * dev)163059ffb30fSJeff Kirsher init_mii(struct net_device *dev)
163159ffb30fSJeff Kirsher {
1632f8653464SHimangi Saraogi     struct local_info *local = netdev_priv(dev);
163359ffb30fSJeff Kirsher     unsigned int ioaddr = dev->base_addr;
163459ffb30fSJeff Kirsher     unsigned control, status, linkpartner;
163559ffb30fSJeff Kirsher     int i;
163659ffb30fSJeff Kirsher 
163759ffb30fSJeff Kirsher     if (if_port == 4 || if_port == 1) { /* force 100BaseT or 10BaseT */
163859ffb30fSJeff Kirsher 	dev->if_port = if_port;
163959ffb30fSJeff Kirsher 	local->probe_port = 0;
164059ffb30fSJeff Kirsher 	return 1;
164159ffb30fSJeff Kirsher     }
164259ffb30fSJeff Kirsher 
164359ffb30fSJeff Kirsher     status = mii_rd(ioaddr,  0, 1);
164459ffb30fSJeff Kirsher     if ((status & 0xff00) != 0x7800)
164559ffb30fSJeff Kirsher 	return 0; /* No MII */
164659ffb30fSJeff Kirsher 
164759ffb30fSJeff Kirsher     local->new_mii = (mii_rd(ioaddr, 0, 2) != 0xffff);
164859ffb30fSJeff Kirsher 
164959ffb30fSJeff Kirsher     if (local->probe_port)
165059ffb30fSJeff Kirsher 	control = 0x1000; /* auto neg */
165159ffb30fSJeff Kirsher     else if (dev->if_port == 4)
165259ffb30fSJeff Kirsher 	control = 0x2000; /* no auto neg, 100mbs mode */
165359ffb30fSJeff Kirsher     else
165459ffb30fSJeff Kirsher 	control = 0x0000; /* no auto neg, 10mbs mode */
165559ffb30fSJeff Kirsher     mii_wr(ioaddr,  0, 0, control, 16);
165659ffb30fSJeff Kirsher     udelay(100);
165759ffb30fSJeff Kirsher     control = mii_rd(ioaddr, 0, 0);
165859ffb30fSJeff Kirsher 
165959ffb30fSJeff Kirsher     if (control & 0x0400) {
166059ffb30fSJeff Kirsher 	netdev_notice(dev, "can't take PHY out of isolation mode\n");
166159ffb30fSJeff Kirsher 	local->probe_port = 0;
166259ffb30fSJeff Kirsher 	return 0;
166359ffb30fSJeff Kirsher     }
166459ffb30fSJeff Kirsher 
166559ffb30fSJeff Kirsher     if (local->probe_port) {
166659ffb30fSJeff Kirsher 	/* according to the DP83840A specs the auto negotiation process
166759ffb30fSJeff Kirsher 	 * may take up to 3.5 sec, so we use this also for our ML6692
166859ffb30fSJeff Kirsher 	 * Fixme: Better to use a timer here!
166959ffb30fSJeff Kirsher 	 */
167059ffb30fSJeff Kirsher 	for (i=0; i < 35; i++) {
167159ffb30fSJeff Kirsher 	    msleep(100);	 /* wait 100 msec */
167259ffb30fSJeff Kirsher 	    status = mii_rd(ioaddr,  0, 1);
167359ffb30fSJeff Kirsher 	    if ((status & 0x0020) && (status & 0x0004))
167459ffb30fSJeff Kirsher 		break;
167559ffb30fSJeff Kirsher 	}
167659ffb30fSJeff Kirsher 
167759ffb30fSJeff Kirsher 	if (!(status & 0x0020)) {
167859ffb30fSJeff Kirsher 	    netdev_info(dev, "autonegotiation failed; using 10mbs\n");
167959ffb30fSJeff Kirsher 	    if (!local->new_mii) {
168059ffb30fSJeff Kirsher 		control = 0x0000;
168159ffb30fSJeff Kirsher 		mii_wr(ioaddr,  0, 0, control, 16);
168259ffb30fSJeff Kirsher 		udelay(100);
168359ffb30fSJeff Kirsher 		SelectPage(0);
168459ffb30fSJeff Kirsher 		dev->if_port = (GetByte(XIRCREG_ESR) & MediaSelect) ? 1 : 2;
168559ffb30fSJeff Kirsher 	    }
168659ffb30fSJeff Kirsher 	} else {
168759ffb30fSJeff Kirsher 	    linkpartner = mii_rd(ioaddr, 0, 5);
168859ffb30fSJeff Kirsher 	    netdev_info(dev, "MII link partner: %04x\n", linkpartner);
168959ffb30fSJeff Kirsher 	    if (linkpartner & 0x0080) {
169059ffb30fSJeff Kirsher 		dev->if_port = 4;
169159ffb30fSJeff Kirsher 	    } else
169259ffb30fSJeff Kirsher 		dev->if_port = 1;
169359ffb30fSJeff Kirsher 	}
169459ffb30fSJeff Kirsher     }
169559ffb30fSJeff Kirsher 
169659ffb30fSJeff Kirsher     return 1;
169759ffb30fSJeff Kirsher }
169859ffb30fSJeff Kirsher 
169959ffb30fSJeff Kirsher static void
do_powerdown(struct net_device * dev)170059ffb30fSJeff Kirsher do_powerdown(struct net_device *dev)
170159ffb30fSJeff Kirsher {
170259ffb30fSJeff Kirsher 
170359ffb30fSJeff Kirsher     unsigned int ioaddr = dev->base_addr;
170459ffb30fSJeff Kirsher 
170559ffb30fSJeff Kirsher     pr_debug("do_powerdown(%p)\n", dev);
170659ffb30fSJeff Kirsher 
170759ffb30fSJeff Kirsher     SelectPage(4);
170859ffb30fSJeff Kirsher     PutByte(XIRCREG4_GPR1, 0);	     /* clear bit 0: power down */
170959ffb30fSJeff Kirsher     SelectPage(0);
171059ffb30fSJeff Kirsher }
171159ffb30fSJeff Kirsher 
171259ffb30fSJeff Kirsher static int
do_stop(struct net_device * dev)171359ffb30fSJeff Kirsher do_stop(struct net_device *dev)
171459ffb30fSJeff Kirsher {
171559ffb30fSJeff Kirsher     unsigned int ioaddr = dev->base_addr;
1716f8653464SHimangi Saraogi     struct local_info *lp = netdev_priv(dev);
171759ffb30fSJeff Kirsher     struct pcmcia_device *link = lp->p_dev;
171859ffb30fSJeff Kirsher 
171959ffb30fSJeff Kirsher     dev_dbg(&link->dev, "do_stop(%p)\n", dev);
172059ffb30fSJeff Kirsher 
172159ffb30fSJeff Kirsher     if (!link)
172259ffb30fSJeff Kirsher 	return -ENODEV;
172359ffb30fSJeff Kirsher 
172459ffb30fSJeff Kirsher     netif_stop_queue(dev);
172559ffb30fSJeff Kirsher 
172659ffb30fSJeff Kirsher     SelectPage(0);
172759ffb30fSJeff Kirsher     PutByte(XIRCREG_CR, 0);  /* disable interrupts */
172859ffb30fSJeff Kirsher     SelectPage(0x01);
172959ffb30fSJeff Kirsher     PutByte(XIRCREG1_IMR0, 0x00); /* forbid all ints */
173059ffb30fSJeff Kirsher     SelectPage(4);
173159ffb30fSJeff Kirsher     PutByte(XIRCREG4_GPR1, 0);	/* clear bit 0: power down */
173259ffb30fSJeff Kirsher     SelectPage(0);
173359ffb30fSJeff Kirsher 
173459ffb30fSJeff Kirsher     link->open--;
173559ffb30fSJeff Kirsher     return 0;
173659ffb30fSJeff Kirsher }
173759ffb30fSJeff Kirsher 
173859ffb30fSJeff Kirsher static const struct pcmcia_device_id xirc2ps_ids[] = {
173959ffb30fSJeff Kirsher 	PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0089, 0x110a),
174059ffb30fSJeff Kirsher 	PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0138, 0x110a),
174159ffb30fSJeff Kirsher 	PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM28", 0x2e3ee845, 0x0ea978ea),
174259ffb30fSJeff Kirsher 	PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM33", 0x2e3ee845, 0x80609023),
174359ffb30fSJeff Kirsher 	PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM56", 0x2e3ee845, 0xa650c32a),
174459ffb30fSJeff Kirsher 	PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "REM10", 0x2e3ee845, 0x76df1d29),
174559ffb30fSJeff Kirsher 	PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "XEM5600", 0x2e3ee845, 0xf1403719),
174659ffb30fSJeff Kirsher 	PCMCIA_PFC_DEVICE_PROD_ID12(0, "Xircom", "CreditCard Ethernet+Modem II", 0x2e3ee845, 0xeca401bf),
174759ffb30fSJeff Kirsher 	PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x010a),
174859ffb30fSJeff Kirsher 	PCMCIA_DEVICE_PROD_ID13("Toshiba Information Systems", "TPCENET", 0x1b3b94fe, 0xf381c1a2),
174959ffb30fSJeff Kirsher 	PCMCIA_DEVICE_PROD_ID13("Xircom", "CE3-10/100", 0x2e3ee845, 0x0ec0ac37),
175059ffb30fSJeff Kirsher 	PCMCIA_DEVICE_PROD_ID13("Xircom", "PS-CE2-10", 0x2e3ee845, 0x947d9073),
175159ffb30fSJeff Kirsher 	PCMCIA_DEVICE_PROD_ID13("Xircom", "R2E-100BTX", 0x2e3ee845, 0x2464a6e3),
175259ffb30fSJeff Kirsher 	PCMCIA_DEVICE_PROD_ID13("Xircom", "RE-10", 0x2e3ee845, 0x3e08d609),
175359ffb30fSJeff Kirsher 	PCMCIA_DEVICE_PROD_ID13("Xircom", "XE2000", 0x2e3ee845, 0xf7188e46),
175459ffb30fSJeff Kirsher 	PCMCIA_DEVICE_PROD_ID12("Compaq", "Ethernet LAN Card", 0x54f7c49c, 0x9fd2f0a2),
175559ffb30fSJeff Kirsher 	PCMCIA_DEVICE_PROD_ID12("Compaq", "Netelligent 10/100 PC Card", 0x54f7c49c, 0xefe96769),
175659ffb30fSJeff Kirsher 	PCMCIA_DEVICE_PROD_ID12("Intel", "EtherExpress(TM) PRO/100 PC Card Mobile Adapter16", 0x816cc815, 0x174397db),
175759ffb30fSJeff Kirsher 	PCMCIA_DEVICE_PROD_ID12("Toshiba", "10/100 Ethernet PC Card", 0x44a09d9c, 0xb44deecf),
175859ffb30fSJeff Kirsher 	/* also matches CFE-10 cards! */
175959ffb30fSJeff Kirsher 	/* PCMCIA_DEVICE_MANF_CARD(0x0105, 0x010a), */
176059ffb30fSJeff Kirsher 	PCMCIA_DEVICE_NULL,
176159ffb30fSJeff Kirsher };
176259ffb30fSJeff Kirsher MODULE_DEVICE_TABLE(pcmcia, xirc2ps_ids);
176359ffb30fSJeff Kirsher 
176459ffb30fSJeff Kirsher 
176559ffb30fSJeff Kirsher static struct pcmcia_driver xirc2ps_cs_driver = {
176659ffb30fSJeff Kirsher 	.owner		= THIS_MODULE,
176759ffb30fSJeff Kirsher 	.name		= "xirc2ps_cs",
176859ffb30fSJeff Kirsher 	.probe		= xirc2ps_probe,
176959ffb30fSJeff Kirsher 	.remove		= xirc2ps_detach,
177059ffb30fSJeff Kirsher 	.id_table       = xirc2ps_ids,
177159ffb30fSJeff Kirsher 	.suspend	= xirc2ps_suspend,
177259ffb30fSJeff Kirsher 	.resume		= xirc2ps_resume,
177359ffb30fSJeff Kirsher };
1774fdd3f29eSH Hartley Sweeten module_pcmcia_driver(xirc2ps_cs_driver);
177559ffb30fSJeff Kirsher 
177659ffb30fSJeff Kirsher #ifndef MODULE
setup_xirc2ps_cs(char * str)177759ffb30fSJeff Kirsher static int __init setup_xirc2ps_cs(char *str)
177859ffb30fSJeff Kirsher {
177959ffb30fSJeff Kirsher 	/* if_port, full_duplex, do_sound, lockup_hack
178059ffb30fSJeff Kirsher 	 */
178159ffb30fSJeff Kirsher 	int ints[10] = { -1 };
178259ffb30fSJeff Kirsher 
1783d3213fbfSDan Carpenter 	str = get_options(str, ARRAY_SIZE(ints), ints);
178459ffb30fSJeff Kirsher 
178559ffb30fSJeff Kirsher #define MAYBE_SET(X,Y) if (ints[0] >= Y && ints[Y] != -1) { X = ints[Y]; }
178659ffb30fSJeff Kirsher 	MAYBE_SET(if_port, 3);
178759ffb30fSJeff Kirsher 	MAYBE_SET(full_duplex, 4);
178859ffb30fSJeff Kirsher 	MAYBE_SET(do_sound, 5);
178959ffb30fSJeff Kirsher 	MAYBE_SET(lockup_hack, 6);
179059ffb30fSJeff Kirsher #undef  MAYBE_SET
179159ffb30fSJeff Kirsher 
179259ffb30fSJeff Kirsher 	return 1;
179359ffb30fSJeff Kirsher }
179459ffb30fSJeff Kirsher 
179559ffb30fSJeff Kirsher __setup("xirc2ps_cs=", setup_xirc2ps_cs);
179659ffb30fSJeff Kirsher #endif
1797