1*59ffb30fSJeff Kirsher /* [xirc2ps_cs.c wk 03.11.99] (1.40 1999/11/18 00:06:03) 2*59ffb30fSJeff Kirsher * Xircom CreditCard Ethernet Adapter IIps driver 3*59ffb30fSJeff Kirsher * Xircom Realport 10/100 (RE-100) driver 4*59ffb30fSJeff Kirsher * 5*59ffb30fSJeff Kirsher * This driver supports various Xircom CreditCard Ethernet adapters 6*59ffb30fSJeff Kirsher * including the CE2, CE IIps, RE-10, CEM28, CEM33, CE33, CEM56, 7*59ffb30fSJeff Kirsher * CE3-100, CE3B, RE-100, REM10BT, and REM56G-100. 8*59ffb30fSJeff Kirsher * 9*59ffb30fSJeff Kirsher * 2000-09-24 <psheer@icon.co.za> The Xircom CE3B-100 may not 10*59ffb30fSJeff Kirsher * autodetect the media properly. In this case use the 11*59ffb30fSJeff Kirsher * if_port=1 (for 10BaseT) or if_port=4 (for 100BaseT) options 12*59ffb30fSJeff Kirsher * to force the media type. 13*59ffb30fSJeff Kirsher * 14*59ffb30fSJeff Kirsher * Written originally by Werner Koch based on David Hinds' skeleton of the 15*59ffb30fSJeff Kirsher * PCMCIA driver. 16*59ffb30fSJeff Kirsher * 17*59ffb30fSJeff Kirsher * Copyright (c) 1997,1998 Werner Koch (dd9jn) 18*59ffb30fSJeff Kirsher * 19*59ffb30fSJeff Kirsher * This driver is free software; you can redistribute it and/or modify 20*59ffb30fSJeff Kirsher * it under the terms of the GNU General Public License as published by 21*59ffb30fSJeff Kirsher * the Free Software Foundation; either version 2 of the License, or 22*59ffb30fSJeff Kirsher * (at your option) any later version. 23*59ffb30fSJeff Kirsher * 24*59ffb30fSJeff Kirsher * It is distributed in the hope that it will be useful, 25*59ffb30fSJeff Kirsher * but WITHOUT ANY WARRANTY; without even the implied warranty of 26*59ffb30fSJeff Kirsher * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27*59ffb30fSJeff Kirsher * GNU General Public License for more details. 28*59ffb30fSJeff Kirsher * 29*59ffb30fSJeff Kirsher * You should have received a copy of the GNU General Public License 30*59ffb30fSJeff Kirsher * along with this program; if not, write to the Free Software 31*59ffb30fSJeff Kirsher * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 32*59ffb30fSJeff Kirsher * 33*59ffb30fSJeff Kirsher * 34*59ffb30fSJeff Kirsher * ALTERNATIVELY, this driver may be distributed under the terms of 35*59ffb30fSJeff Kirsher * the following license, in which case the provisions of this license 36*59ffb30fSJeff Kirsher * are required INSTEAD OF the GNU General Public License. (This clause 37*59ffb30fSJeff Kirsher * is necessary due to a potential bad interaction between the GPL and 38*59ffb30fSJeff Kirsher * the restrictions contained in a BSD-style copyright.) 39*59ffb30fSJeff Kirsher * 40*59ffb30fSJeff Kirsher * Redistribution and use in source and binary forms, with or without 41*59ffb30fSJeff Kirsher * modification, are permitted provided that the following conditions 42*59ffb30fSJeff Kirsher * are met: 43*59ffb30fSJeff Kirsher * 1. Redistributions of source code must retain the above copyright 44*59ffb30fSJeff Kirsher * notice, and the entire permission notice in its entirety, 45*59ffb30fSJeff Kirsher * including the disclaimer of warranties. 46*59ffb30fSJeff Kirsher * 2. Redistributions in binary form must reproduce the above copyright 47*59ffb30fSJeff Kirsher * notice, this list of conditions and the following disclaimer in the 48*59ffb30fSJeff Kirsher * documentation and/or other materials provided with the distribution. 49*59ffb30fSJeff Kirsher * 3. The name of the author may not be used to endorse or promote 50*59ffb30fSJeff Kirsher * products derived from this software without specific prior 51*59ffb30fSJeff Kirsher * written permission. 52*59ffb30fSJeff Kirsher * 53*59ffb30fSJeff Kirsher * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 54*59ffb30fSJeff Kirsher * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 55*59ffb30fSJeff Kirsher * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 56*59ffb30fSJeff Kirsher * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 57*59ffb30fSJeff Kirsher * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 58*59ffb30fSJeff Kirsher * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 59*59ffb30fSJeff Kirsher * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 60*59ffb30fSJeff Kirsher * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 61*59ffb30fSJeff Kirsher * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 62*59ffb30fSJeff Kirsher * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 63*59ffb30fSJeff Kirsher * OF THE POSSIBILITY OF SUCH DAMAGE. 64*59ffb30fSJeff Kirsher */ 65*59ffb30fSJeff Kirsher 66*59ffb30fSJeff Kirsher #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 67*59ffb30fSJeff Kirsher 68*59ffb30fSJeff Kirsher #include <linux/module.h> 69*59ffb30fSJeff Kirsher #include <linux/kernel.h> 70*59ffb30fSJeff Kirsher #include <linux/init.h> 71*59ffb30fSJeff Kirsher #include <linux/ptrace.h> 72*59ffb30fSJeff Kirsher #include <linux/slab.h> 73*59ffb30fSJeff Kirsher #include <linux/string.h> 74*59ffb30fSJeff Kirsher #include <linux/timer.h> 75*59ffb30fSJeff Kirsher #include <linux/interrupt.h> 76*59ffb30fSJeff Kirsher #include <linux/in.h> 77*59ffb30fSJeff Kirsher #include <linux/delay.h> 78*59ffb30fSJeff Kirsher #include <linux/ethtool.h> 79*59ffb30fSJeff Kirsher #include <linux/netdevice.h> 80*59ffb30fSJeff Kirsher #include <linux/etherdevice.h> 81*59ffb30fSJeff Kirsher #include <linux/skbuff.h> 82*59ffb30fSJeff Kirsher #include <linux/if_arp.h> 83*59ffb30fSJeff Kirsher #include <linux/ioport.h> 84*59ffb30fSJeff Kirsher #include <linux/bitops.h> 85*59ffb30fSJeff Kirsher #include <linux/mii.h> 86*59ffb30fSJeff Kirsher 87*59ffb30fSJeff Kirsher #include <pcmcia/cistpl.h> 88*59ffb30fSJeff Kirsher #include <pcmcia/cisreg.h> 89*59ffb30fSJeff Kirsher #include <pcmcia/ciscode.h> 90*59ffb30fSJeff Kirsher 91*59ffb30fSJeff Kirsher #include <asm/io.h> 92*59ffb30fSJeff Kirsher #include <asm/system.h> 93*59ffb30fSJeff Kirsher #include <asm/uaccess.h> 94*59ffb30fSJeff Kirsher 95*59ffb30fSJeff Kirsher #ifndef MANFID_COMPAQ 96*59ffb30fSJeff Kirsher #define MANFID_COMPAQ 0x0138 97*59ffb30fSJeff Kirsher #define MANFID_COMPAQ2 0x0183 /* is this correct? */ 98*59ffb30fSJeff Kirsher #endif 99*59ffb30fSJeff Kirsher 100*59ffb30fSJeff Kirsher #include <pcmcia/ds.h> 101*59ffb30fSJeff Kirsher 102*59ffb30fSJeff Kirsher /* Time in jiffies before concluding Tx hung */ 103*59ffb30fSJeff Kirsher #define TX_TIMEOUT ((400*HZ)/1000) 104*59ffb30fSJeff Kirsher 105*59ffb30fSJeff Kirsher /**************** 106*59ffb30fSJeff Kirsher * Some constants used to access the hardware 107*59ffb30fSJeff Kirsher */ 108*59ffb30fSJeff Kirsher 109*59ffb30fSJeff Kirsher /* Register offsets and value constans */ 110*59ffb30fSJeff Kirsher #define XIRCREG_CR 0 /* Command register (wr) */ 111*59ffb30fSJeff Kirsher enum xirc_cr { 112*59ffb30fSJeff Kirsher TransmitPacket = 0x01, 113*59ffb30fSJeff Kirsher SoftReset = 0x02, 114*59ffb30fSJeff Kirsher EnableIntr = 0x04, 115*59ffb30fSJeff Kirsher ForceIntr = 0x08, 116*59ffb30fSJeff Kirsher ClearTxFIFO = 0x10, 117*59ffb30fSJeff Kirsher ClearRxOvrun = 0x20, 118*59ffb30fSJeff Kirsher RestartTx = 0x40 119*59ffb30fSJeff Kirsher }; 120*59ffb30fSJeff Kirsher #define XIRCREG_ESR 0 /* Ethernet status register (rd) */ 121*59ffb30fSJeff Kirsher enum xirc_esr { 122*59ffb30fSJeff Kirsher FullPktRcvd = 0x01, /* full packet in receive buffer */ 123*59ffb30fSJeff Kirsher PktRejected = 0x04, /* a packet has been rejected */ 124*59ffb30fSJeff Kirsher TxPktPend = 0x08, /* TX Packet Pending */ 125*59ffb30fSJeff Kirsher IncorPolarity = 0x10, 126*59ffb30fSJeff Kirsher MediaSelect = 0x20 /* set if TP, clear if AUI */ 127*59ffb30fSJeff Kirsher }; 128*59ffb30fSJeff Kirsher #define XIRCREG_PR 1 /* Page Register select */ 129*59ffb30fSJeff Kirsher #define XIRCREG_EDP 4 /* Ethernet Data Port Register */ 130*59ffb30fSJeff Kirsher #define XIRCREG_ISR 6 /* Ethernet Interrupt Status Register */ 131*59ffb30fSJeff Kirsher enum xirc_isr { 132*59ffb30fSJeff Kirsher TxBufOvr = 0x01, /* TX Buffer Overflow */ 133*59ffb30fSJeff Kirsher PktTxed = 0x02, /* Packet Transmitted */ 134*59ffb30fSJeff Kirsher MACIntr = 0x04, /* MAC Interrupt occurred */ 135*59ffb30fSJeff Kirsher TxResGrant = 0x08, /* Tx Reservation Granted */ 136*59ffb30fSJeff Kirsher RxFullPkt = 0x20, /* Rx Full Packet */ 137*59ffb30fSJeff Kirsher RxPktRej = 0x40, /* Rx Packet Rejected */ 138*59ffb30fSJeff Kirsher ForcedIntr= 0x80 /* Forced Interrupt */ 139*59ffb30fSJeff Kirsher }; 140*59ffb30fSJeff Kirsher #define XIRCREG1_IMR0 12 /* Ethernet Interrupt Mask Register (on page 1)*/ 141*59ffb30fSJeff Kirsher #define XIRCREG1_IMR1 13 142*59ffb30fSJeff Kirsher #define XIRCREG0_TSO 8 /* Transmit Space Open Register (on page 0)*/ 143*59ffb30fSJeff Kirsher #define XIRCREG0_TRS 10 /* Transmit reservation Size Register (page 0)*/ 144*59ffb30fSJeff Kirsher #define XIRCREG0_DO 12 /* Data Offset Register (page 0) (wr) */ 145*59ffb30fSJeff Kirsher #define XIRCREG0_RSR 12 /* Receive Status Register (page 0) (rd) */ 146*59ffb30fSJeff Kirsher enum xirc_rsr { 147*59ffb30fSJeff Kirsher PhyPkt = 0x01, /* set:physical packet, clear: multicast packet */ 148*59ffb30fSJeff Kirsher BrdcstPkt = 0x02, /* set if it is a broadcast packet */ 149*59ffb30fSJeff Kirsher PktTooLong = 0x04, /* set if packet length > 1518 */ 150*59ffb30fSJeff Kirsher AlignErr = 0x10, /* incorrect CRC and last octet not complete */ 151*59ffb30fSJeff Kirsher CRCErr = 0x20, /* incorrect CRC and last octet is complete */ 152*59ffb30fSJeff Kirsher PktRxOk = 0x80 /* received ok */ 153*59ffb30fSJeff Kirsher }; 154*59ffb30fSJeff Kirsher #define XIRCREG0_PTR 13 /* packets transmitted register (rd) */ 155*59ffb30fSJeff Kirsher #define XIRCREG0_RBC 14 /* receive byte count regsister (rd) */ 156*59ffb30fSJeff Kirsher #define XIRCREG1_ECR 14 /* ethernet configurationn register */ 157*59ffb30fSJeff Kirsher enum xirc_ecr { 158*59ffb30fSJeff Kirsher FullDuplex = 0x04, /* enable full duplex mode */ 159*59ffb30fSJeff Kirsher LongTPMode = 0x08, /* adjust for longer lengths of TP cable */ 160*59ffb30fSJeff Kirsher DisablePolCor = 0x10,/* disable auto polarity correction */ 161*59ffb30fSJeff Kirsher DisableLinkPulse = 0x20, /* disable link pulse generation */ 162*59ffb30fSJeff Kirsher DisableAutoTx = 0x40, /* disable auto-transmit */ 163*59ffb30fSJeff Kirsher }; 164*59ffb30fSJeff Kirsher #define XIRCREG2_RBS 8 /* receive buffer start register */ 165*59ffb30fSJeff Kirsher #define XIRCREG2_LED 10 /* LED Configuration register */ 166*59ffb30fSJeff Kirsher /* values for the leds: Bits 2-0 for led 1 167*59ffb30fSJeff Kirsher * 0 disabled Bits 5-3 for led 2 168*59ffb30fSJeff Kirsher * 1 collision 169*59ffb30fSJeff Kirsher * 2 noncollision 170*59ffb30fSJeff Kirsher * 3 link_detected 171*59ffb30fSJeff Kirsher * 4 incor_polarity 172*59ffb30fSJeff Kirsher * 5 jabber 173*59ffb30fSJeff Kirsher * 6 auto_assertion 174*59ffb30fSJeff Kirsher * 7 rx_tx_activity 175*59ffb30fSJeff Kirsher */ 176*59ffb30fSJeff Kirsher #define XIRCREG2_MSR 12 /* Mohawk specific register */ 177*59ffb30fSJeff Kirsher 178*59ffb30fSJeff Kirsher #define XIRCREG4_GPR0 8 /* General Purpose Register 0 */ 179*59ffb30fSJeff Kirsher #define XIRCREG4_GPR1 9 /* General Purpose Register 1 */ 180*59ffb30fSJeff Kirsher #define XIRCREG2_GPR2 13 /* General Purpose Register 2 (page2!)*/ 181*59ffb30fSJeff Kirsher #define XIRCREG4_BOV 10 /* Bonding Version Register */ 182*59ffb30fSJeff Kirsher #define XIRCREG4_LMA 12 /* Local Memory Address Register */ 183*59ffb30fSJeff Kirsher #define XIRCREG4_LMD 14 /* Local Memory Data Port */ 184*59ffb30fSJeff Kirsher /* MAC register can only by accessed with 8 bit operations */ 185*59ffb30fSJeff Kirsher #define XIRCREG40_CMD0 8 /* Command Register (wr) */ 186*59ffb30fSJeff Kirsher enum xirc_cmd { /* Commands */ 187*59ffb30fSJeff Kirsher Transmit = 0x01, 188*59ffb30fSJeff Kirsher EnableRecv = 0x04, 189*59ffb30fSJeff Kirsher DisableRecv = 0x08, 190*59ffb30fSJeff Kirsher Abort = 0x10, 191*59ffb30fSJeff Kirsher Online = 0x20, 192*59ffb30fSJeff Kirsher IntrAck = 0x40, 193*59ffb30fSJeff Kirsher Offline = 0x80 194*59ffb30fSJeff Kirsher }; 195*59ffb30fSJeff Kirsher #define XIRCREG5_RHSA0 10 /* Rx Host Start Address */ 196*59ffb30fSJeff Kirsher #define XIRCREG40_RXST0 9 /* Receive Status Register */ 197*59ffb30fSJeff Kirsher #define XIRCREG40_TXST0 11 /* Transmit Status Register 0 */ 198*59ffb30fSJeff Kirsher #define XIRCREG40_TXST1 12 /* Transmit Status Register 10 */ 199*59ffb30fSJeff Kirsher #define XIRCREG40_RMASK0 13 /* Receive Mask Register */ 200*59ffb30fSJeff Kirsher #define XIRCREG40_TMASK0 14 /* Transmit Mask Register 0 */ 201*59ffb30fSJeff Kirsher #define XIRCREG40_TMASK1 15 /* Transmit Mask Register 0 */ 202*59ffb30fSJeff Kirsher #define XIRCREG42_SWC0 8 /* Software Configuration 0 */ 203*59ffb30fSJeff Kirsher #define XIRCREG42_SWC1 9 /* Software Configuration 1 */ 204*59ffb30fSJeff Kirsher #define XIRCREG42_BOC 10 /* Back-Off Configuration */ 205*59ffb30fSJeff Kirsher #define XIRCREG44_TDR0 8 /* Time Domain Reflectometry 0 */ 206*59ffb30fSJeff Kirsher #define XIRCREG44_TDR1 9 /* Time Domain Reflectometry 1 */ 207*59ffb30fSJeff Kirsher #define XIRCREG44_RXBC_LO 10 /* Rx Byte Count 0 (rd) */ 208*59ffb30fSJeff Kirsher #define XIRCREG44_RXBC_HI 11 /* Rx Byte Count 1 (rd) */ 209*59ffb30fSJeff Kirsher #define XIRCREG45_REV 15 /* Revision Register (rd) */ 210*59ffb30fSJeff Kirsher #define XIRCREG50_IA 8 /* Individual Address (8-13) */ 211*59ffb30fSJeff Kirsher 212*59ffb30fSJeff Kirsher static const char *if_names[] = { "Auto", "10BaseT", "10Base2", "AUI", "100BaseT" }; 213*59ffb30fSJeff Kirsher 214*59ffb30fSJeff Kirsher /* card types */ 215*59ffb30fSJeff Kirsher #define XIR_UNKNOWN 0 /* unknown: not supported */ 216*59ffb30fSJeff Kirsher #define XIR_CE 1 /* (prodid 1) different hardware: not supported */ 217*59ffb30fSJeff Kirsher #define XIR_CE2 2 /* (prodid 2) */ 218*59ffb30fSJeff Kirsher #define XIR_CE3 3 /* (prodid 3) */ 219*59ffb30fSJeff Kirsher #define XIR_CEM 4 /* (prodid 1) different hardware: not supported */ 220*59ffb30fSJeff Kirsher #define XIR_CEM2 5 /* (prodid 2) */ 221*59ffb30fSJeff Kirsher #define XIR_CEM3 6 /* (prodid 3) */ 222*59ffb30fSJeff Kirsher #define XIR_CEM33 7 /* (prodid 4) */ 223*59ffb30fSJeff Kirsher #define XIR_CEM56M 8 /* (prodid 5) */ 224*59ffb30fSJeff Kirsher #define XIR_CEM56 9 /* (prodid 6) */ 225*59ffb30fSJeff Kirsher #define XIR_CM28 10 /* (prodid 3) modem only: not supported here */ 226*59ffb30fSJeff Kirsher #define XIR_CM33 11 /* (prodid 4) modem only: not supported here */ 227*59ffb30fSJeff Kirsher #define XIR_CM56 12 /* (prodid 5) modem only: not supported here */ 228*59ffb30fSJeff Kirsher #define XIR_CG 13 /* (prodid 1) GSM modem only: not supported */ 229*59ffb30fSJeff Kirsher #define XIR_CBE 14 /* (prodid 1) cardbus ethernet: not supported */ 230*59ffb30fSJeff Kirsher /*====================================================================*/ 231*59ffb30fSJeff Kirsher 232*59ffb30fSJeff Kirsher /* Module parameters */ 233*59ffb30fSJeff Kirsher 234*59ffb30fSJeff Kirsher MODULE_DESCRIPTION("Xircom PCMCIA ethernet driver"); 235*59ffb30fSJeff Kirsher MODULE_LICENSE("Dual MPL/GPL"); 236*59ffb30fSJeff Kirsher 237*59ffb30fSJeff Kirsher #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0) 238*59ffb30fSJeff Kirsher 239*59ffb30fSJeff Kirsher INT_MODULE_PARM(if_port, 0); 240*59ffb30fSJeff Kirsher INT_MODULE_PARM(full_duplex, 0); 241*59ffb30fSJeff Kirsher INT_MODULE_PARM(do_sound, 1); 242*59ffb30fSJeff Kirsher INT_MODULE_PARM(lockup_hack, 0); /* anti lockup hack */ 243*59ffb30fSJeff Kirsher 244*59ffb30fSJeff Kirsher /*====================================================================*/ 245*59ffb30fSJeff Kirsher 246*59ffb30fSJeff Kirsher /* We do not process more than these number of bytes during one 247*59ffb30fSJeff Kirsher * interrupt. (Of course we receive complete packets, so this is not 248*59ffb30fSJeff Kirsher * an exact value). 249*59ffb30fSJeff Kirsher * Something between 2000..22000; first value gives best interrupt latency, 250*59ffb30fSJeff Kirsher * the second enables the usage of the complete on-chip buffer. We use the 251*59ffb30fSJeff Kirsher * high value as the initial value. 252*59ffb30fSJeff Kirsher */ 253*59ffb30fSJeff Kirsher static unsigned maxrx_bytes = 22000; 254*59ffb30fSJeff Kirsher 255*59ffb30fSJeff Kirsher /* MII management prototypes */ 256*59ffb30fSJeff Kirsher static void mii_idle(unsigned int ioaddr); 257*59ffb30fSJeff Kirsher static void mii_putbit(unsigned int ioaddr, unsigned data); 258*59ffb30fSJeff Kirsher static int mii_getbit(unsigned int ioaddr); 259*59ffb30fSJeff Kirsher static void mii_wbits(unsigned int ioaddr, unsigned data, int len); 260*59ffb30fSJeff Kirsher static unsigned mii_rd(unsigned int ioaddr, u_char phyaddr, u_char phyreg); 261*59ffb30fSJeff Kirsher static void mii_wr(unsigned int ioaddr, u_char phyaddr, u_char phyreg, 262*59ffb30fSJeff Kirsher unsigned data, int len); 263*59ffb30fSJeff Kirsher 264*59ffb30fSJeff Kirsher static int has_ce2_string(struct pcmcia_device * link); 265*59ffb30fSJeff Kirsher static int xirc2ps_config(struct pcmcia_device * link); 266*59ffb30fSJeff Kirsher static void xirc2ps_release(struct pcmcia_device * link); 267*59ffb30fSJeff Kirsher static void xirc2ps_detach(struct pcmcia_device *p_dev); 268*59ffb30fSJeff Kirsher 269*59ffb30fSJeff Kirsher static irqreturn_t xirc2ps_interrupt(int irq, void *dev_id); 270*59ffb30fSJeff Kirsher 271*59ffb30fSJeff Kirsher typedef struct local_info_t { 272*59ffb30fSJeff Kirsher struct net_device *dev; 273*59ffb30fSJeff Kirsher struct pcmcia_device *p_dev; 274*59ffb30fSJeff Kirsher 275*59ffb30fSJeff Kirsher int card_type; 276*59ffb30fSJeff Kirsher int probe_port; 277*59ffb30fSJeff Kirsher int silicon; /* silicon revision. 0=old CE2, 1=Scipper, 4=Mohawk */ 278*59ffb30fSJeff Kirsher int mohawk; /* a CE3 type card */ 279*59ffb30fSJeff Kirsher int dingo; /* a CEM56 type card */ 280*59ffb30fSJeff Kirsher int new_mii; /* has full 10baseT/100baseT MII */ 281*59ffb30fSJeff Kirsher int modem; /* is a multi function card (i.e with a modem) */ 282*59ffb30fSJeff Kirsher void __iomem *dingo_ccr; /* only used for CEM56 cards */ 283*59ffb30fSJeff Kirsher unsigned last_ptr_value; /* last packets transmitted value */ 284*59ffb30fSJeff Kirsher const char *manf_str; 285*59ffb30fSJeff Kirsher struct work_struct tx_timeout_task; 286*59ffb30fSJeff Kirsher } local_info_t; 287*59ffb30fSJeff Kirsher 288*59ffb30fSJeff Kirsher /**************** 289*59ffb30fSJeff Kirsher * Some more prototypes 290*59ffb30fSJeff Kirsher */ 291*59ffb30fSJeff Kirsher static netdev_tx_t do_start_xmit(struct sk_buff *skb, 292*59ffb30fSJeff Kirsher struct net_device *dev); 293*59ffb30fSJeff Kirsher static void xirc_tx_timeout(struct net_device *dev); 294*59ffb30fSJeff Kirsher static void xirc2ps_tx_timeout_task(struct work_struct *work); 295*59ffb30fSJeff Kirsher static void set_addresses(struct net_device *dev); 296*59ffb30fSJeff Kirsher static void set_multicast_list(struct net_device *dev); 297*59ffb30fSJeff Kirsher static int set_card_type(struct pcmcia_device *link); 298*59ffb30fSJeff Kirsher static int do_config(struct net_device *dev, struct ifmap *map); 299*59ffb30fSJeff Kirsher static int do_open(struct net_device *dev); 300*59ffb30fSJeff Kirsher static int do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 301*59ffb30fSJeff Kirsher static const struct ethtool_ops netdev_ethtool_ops; 302*59ffb30fSJeff Kirsher static void hardreset(struct net_device *dev); 303*59ffb30fSJeff Kirsher static void do_reset(struct net_device *dev, int full); 304*59ffb30fSJeff Kirsher static int init_mii(struct net_device *dev); 305*59ffb30fSJeff Kirsher static void do_powerdown(struct net_device *dev); 306*59ffb30fSJeff Kirsher static int do_stop(struct net_device *dev); 307*59ffb30fSJeff Kirsher 308*59ffb30fSJeff Kirsher /*=============== Helper functions =========================*/ 309*59ffb30fSJeff Kirsher #define SelectPage(pgnr) outb((pgnr), ioaddr + XIRCREG_PR) 310*59ffb30fSJeff Kirsher #define GetByte(reg) ((unsigned)inb(ioaddr + (reg))) 311*59ffb30fSJeff Kirsher #define GetWord(reg) ((unsigned)inw(ioaddr + (reg))) 312*59ffb30fSJeff Kirsher #define PutByte(reg,value) outb((value), ioaddr+(reg)) 313*59ffb30fSJeff Kirsher #define PutWord(reg,value) outw((value), ioaddr+(reg)) 314*59ffb30fSJeff Kirsher 315*59ffb30fSJeff Kirsher /*====== Functions used for debugging =================================*/ 316*59ffb30fSJeff Kirsher #if 0 /* reading regs may change system status */ 317*59ffb30fSJeff Kirsher static void 318*59ffb30fSJeff Kirsher PrintRegisters(struct net_device *dev) 319*59ffb30fSJeff Kirsher { 320*59ffb30fSJeff Kirsher unsigned int ioaddr = dev->base_addr; 321*59ffb30fSJeff Kirsher 322*59ffb30fSJeff Kirsher if (pc_debug > 1) { 323*59ffb30fSJeff Kirsher int i, page; 324*59ffb30fSJeff Kirsher 325*59ffb30fSJeff Kirsher printk(KERN_DEBUG pr_fmt("Register common: ")); 326*59ffb30fSJeff Kirsher for (i = 0; i < 8; i++) 327*59ffb30fSJeff Kirsher pr_cont(" %2.2x", GetByte(i)); 328*59ffb30fSJeff Kirsher pr_cont("\n"); 329*59ffb30fSJeff Kirsher for (page = 0; page <= 8; page++) { 330*59ffb30fSJeff Kirsher printk(KERN_DEBUG pr_fmt("Register page %2x: "), page); 331*59ffb30fSJeff Kirsher SelectPage(page); 332*59ffb30fSJeff Kirsher for (i = 8; i < 16; i++) 333*59ffb30fSJeff Kirsher pr_cont(" %2.2x", GetByte(i)); 334*59ffb30fSJeff Kirsher pr_cont("\n"); 335*59ffb30fSJeff Kirsher } 336*59ffb30fSJeff Kirsher for (page=0x40 ; page <= 0x5f; page++) { 337*59ffb30fSJeff Kirsher if (page == 0x43 || (page >= 0x46 && page <= 0x4f) || 338*59ffb30fSJeff Kirsher (page >= 0x51 && page <=0x5e)) 339*59ffb30fSJeff Kirsher continue; 340*59ffb30fSJeff Kirsher printk(KERN_DEBUG pr_fmt("Register page %2x: "), page); 341*59ffb30fSJeff Kirsher SelectPage(page); 342*59ffb30fSJeff Kirsher for (i = 8; i < 16; i++) 343*59ffb30fSJeff Kirsher pr_cont(" %2.2x", GetByte(i)); 344*59ffb30fSJeff Kirsher pr_cont("\n"); 345*59ffb30fSJeff Kirsher } 346*59ffb30fSJeff Kirsher } 347*59ffb30fSJeff Kirsher } 348*59ffb30fSJeff Kirsher #endif /* 0 */ 349*59ffb30fSJeff Kirsher 350*59ffb30fSJeff Kirsher /*============== MII Management functions ===============*/ 351*59ffb30fSJeff Kirsher 352*59ffb30fSJeff Kirsher /**************** 353*59ffb30fSJeff Kirsher * Turn around for read 354*59ffb30fSJeff Kirsher */ 355*59ffb30fSJeff Kirsher static void 356*59ffb30fSJeff Kirsher mii_idle(unsigned int ioaddr) 357*59ffb30fSJeff Kirsher { 358*59ffb30fSJeff Kirsher PutByte(XIRCREG2_GPR2, 0x04|0); /* drive MDCK low */ 359*59ffb30fSJeff Kirsher udelay(1); 360*59ffb30fSJeff Kirsher PutByte(XIRCREG2_GPR2, 0x04|1); /* and drive MDCK high */ 361*59ffb30fSJeff Kirsher udelay(1); 362*59ffb30fSJeff Kirsher } 363*59ffb30fSJeff Kirsher 364*59ffb30fSJeff Kirsher /**************** 365*59ffb30fSJeff Kirsher * Write a bit to MDI/O 366*59ffb30fSJeff Kirsher */ 367*59ffb30fSJeff Kirsher static void 368*59ffb30fSJeff Kirsher mii_putbit(unsigned int ioaddr, unsigned data) 369*59ffb30fSJeff Kirsher { 370*59ffb30fSJeff Kirsher #if 1 371*59ffb30fSJeff Kirsher if (data) { 372*59ffb30fSJeff Kirsher PutByte(XIRCREG2_GPR2, 0x0c|2|0); /* set MDIO */ 373*59ffb30fSJeff Kirsher udelay(1); 374*59ffb30fSJeff Kirsher PutByte(XIRCREG2_GPR2, 0x0c|2|1); /* and drive MDCK high */ 375*59ffb30fSJeff Kirsher udelay(1); 376*59ffb30fSJeff Kirsher } else { 377*59ffb30fSJeff Kirsher PutByte(XIRCREG2_GPR2, 0x0c|0|0); /* clear MDIO */ 378*59ffb30fSJeff Kirsher udelay(1); 379*59ffb30fSJeff Kirsher PutByte(XIRCREG2_GPR2, 0x0c|0|1); /* and drive MDCK high */ 380*59ffb30fSJeff Kirsher udelay(1); 381*59ffb30fSJeff Kirsher } 382*59ffb30fSJeff Kirsher #else 383*59ffb30fSJeff Kirsher if (data) { 384*59ffb30fSJeff Kirsher PutWord(XIRCREG2_GPR2-1, 0x0e0e); 385*59ffb30fSJeff Kirsher udelay(1); 386*59ffb30fSJeff Kirsher PutWord(XIRCREG2_GPR2-1, 0x0f0f); 387*59ffb30fSJeff Kirsher udelay(1); 388*59ffb30fSJeff Kirsher } else { 389*59ffb30fSJeff Kirsher PutWord(XIRCREG2_GPR2-1, 0x0c0c); 390*59ffb30fSJeff Kirsher udelay(1); 391*59ffb30fSJeff Kirsher PutWord(XIRCREG2_GPR2-1, 0x0d0d); 392*59ffb30fSJeff Kirsher udelay(1); 393*59ffb30fSJeff Kirsher } 394*59ffb30fSJeff Kirsher #endif 395*59ffb30fSJeff Kirsher } 396*59ffb30fSJeff Kirsher 397*59ffb30fSJeff Kirsher /**************** 398*59ffb30fSJeff Kirsher * Get a bit from MDI/O 399*59ffb30fSJeff Kirsher */ 400*59ffb30fSJeff Kirsher static int 401*59ffb30fSJeff Kirsher mii_getbit(unsigned int ioaddr) 402*59ffb30fSJeff Kirsher { 403*59ffb30fSJeff Kirsher unsigned d; 404*59ffb30fSJeff Kirsher 405*59ffb30fSJeff Kirsher PutByte(XIRCREG2_GPR2, 4|0); /* drive MDCK low */ 406*59ffb30fSJeff Kirsher udelay(1); 407*59ffb30fSJeff Kirsher d = GetByte(XIRCREG2_GPR2); /* read MDIO */ 408*59ffb30fSJeff Kirsher PutByte(XIRCREG2_GPR2, 4|1); /* drive MDCK high again */ 409*59ffb30fSJeff Kirsher udelay(1); 410*59ffb30fSJeff Kirsher return d & 0x20; /* read MDIO */ 411*59ffb30fSJeff Kirsher } 412*59ffb30fSJeff Kirsher 413*59ffb30fSJeff Kirsher static void 414*59ffb30fSJeff Kirsher mii_wbits(unsigned int ioaddr, unsigned data, int len) 415*59ffb30fSJeff Kirsher { 416*59ffb30fSJeff Kirsher unsigned m = 1 << (len-1); 417*59ffb30fSJeff Kirsher for (; m; m >>= 1) 418*59ffb30fSJeff Kirsher mii_putbit(ioaddr, data & m); 419*59ffb30fSJeff Kirsher } 420*59ffb30fSJeff Kirsher 421*59ffb30fSJeff Kirsher static unsigned 422*59ffb30fSJeff Kirsher mii_rd(unsigned int ioaddr, u_char phyaddr, u_char phyreg) 423*59ffb30fSJeff Kirsher { 424*59ffb30fSJeff Kirsher int i; 425*59ffb30fSJeff Kirsher unsigned data=0, m; 426*59ffb30fSJeff Kirsher 427*59ffb30fSJeff Kirsher SelectPage(2); 428*59ffb30fSJeff Kirsher for (i=0; i < 32; i++) /* 32 bit preamble */ 429*59ffb30fSJeff Kirsher mii_putbit(ioaddr, 1); 430*59ffb30fSJeff Kirsher mii_wbits(ioaddr, 0x06, 4); /* Start and opcode for read */ 431*59ffb30fSJeff Kirsher mii_wbits(ioaddr, phyaddr, 5); /* PHY address to be accessed */ 432*59ffb30fSJeff Kirsher mii_wbits(ioaddr, phyreg, 5); /* PHY register to read */ 433*59ffb30fSJeff Kirsher mii_idle(ioaddr); /* turn around */ 434*59ffb30fSJeff Kirsher mii_getbit(ioaddr); 435*59ffb30fSJeff Kirsher 436*59ffb30fSJeff Kirsher for (m = 1<<15; m; m >>= 1) 437*59ffb30fSJeff Kirsher if (mii_getbit(ioaddr)) 438*59ffb30fSJeff Kirsher data |= m; 439*59ffb30fSJeff Kirsher mii_idle(ioaddr); 440*59ffb30fSJeff Kirsher return data; 441*59ffb30fSJeff Kirsher } 442*59ffb30fSJeff Kirsher 443*59ffb30fSJeff Kirsher static void 444*59ffb30fSJeff Kirsher mii_wr(unsigned int ioaddr, u_char phyaddr, u_char phyreg, unsigned data, 445*59ffb30fSJeff Kirsher int len) 446*59ffb30fSJeff Kirsher { 447*59ffb30fSJeff Kirsher int i; 448*59ffb30fSJeff Kirsher 449*59ffb30fSJeff Kirsher SelectPage(2); 450*59ffb30fSJeff Kirsher for (i=0; i < 32; i++) /* 32 bit preamble */ 451*59ffb30fSJeff Kirsher mii_putbit(ioaddr, 1); 452*59ffb30fSJeff Kirsher mii_wbits(ioaddr, 0x05, 4); /* Start and opcode for write */ 453*59ffb30fSJeff Kirsher mii_wbits(ioaddr, phyaddr, 5); /* PHY address to be accessed */ 454*59ffb30fSJeff Kirsher mii_wbits(ioaddr, phyreg, 5); /* PHY Register to write */ 455*59ffb30fSJeff Kirsher mii_putbit(ioaddr, 1); /* turn around */ 456*59ffb30fSJeff Kirsher mii_putbit(ioaddr, 0); 457*59ffb30fSJeff Kirsher mii_wbits(ioaddr, data, len); /* And write the data */ 458*59ffb30fSJeff Kirsher mii_idle(ioaddr); 459*59ffb30fSJeff Kirsher } 460*59ffb30fSJeff Kirsher 461*59ffb30fSJeff Kirsher /*============= Main bulk of functions =========================*/ 462*59ffb30fSJeff Kirsher 463*59ffb30fSJeff Kirsher static const struct net_device_ops netdev_ops = { 464*59ffb30fSJeff Kirsher .ndo_open = do_open, 465*59ffb30fSJeff Kirsher .ndo_stop = do_stop, 466*59ffb30fSJeff Kirsher .ndo_start_xmit = do_start_xmit, 467*59ffb30fSJeff Kirsher .ndo_tx_timeout = xirc_tx_timeout, 468*59ffb30fSJeff Kirsher .ndo_set_config = do_config, 469*59ffb30fSJeff Kirsher .ndo_do_ioctl = do_ioctl, 470*59ffb30fSJeff Kirsher .ndo_set_multicast_list = set_multicast_list, 471*59ffb30fSJeff Kirsher .ndo_change_mtu = eth_change_mtu, 472*59ffb30fSJeff Kirsher .ndo_set_mac_address = eth_mac_addr, 473*59ffb30fSJeff Kirsher .ndo_validate_addr = eth_validate_addr, 474*59ffb30fSJeff Kirsher }; 475*59ffb30fSJeff Kirsher 476*59ffb30fSJeff Kirsher static int 477*59ffb30fSJeff Kirsher xirc2ps_probe(struct pcmcia_device *link) 478*59ffb30fSJeff Kirsher { 479*59ffb30fSJeff Kirsher struct net_device *dev; 480*59ffb30fSJeff Kirsher local_info_t *local; 481*59ffb30fSJeff Kirsher 482*59ffb30fSJeff Kirsher dev_dbg(&link->dev, "attach()\n"); 483*59ffb30fSJeff Kirsher 484*59ffb30fSJeff Kirsher /* Allocate the device structure */ 485*59ffb30fSJeff Kirsher dev = alloc_etherdev(sizeof(local_info_t)); 486*59ffb30fSJeff Kirsher if (!dev) 487*59ffb30fSJeff Kirsher return -ENOMEM; 488*59ffb30fSJeff Kirsher local = netdev_priv(dev); 489*59ffb30fSJeff Kirsher local->dev = dev; 490*59ffb30fSJeff Kirsher local->p_dev = link; 491*59ffb30fSJeff Kirsher link->priv = dev; 492*59ffb30fSJeff Kirsher 493*59ffb30fSJeff Kirsher /* General socket configuration */ 494*59ffb30fSJeff Kirsher link->config_index = 1; 495*59ffb30fSJeff Kirsher 496*59ffb30fSJeff Kirsher /* Fill in card specific entries */ 497*59ffb30fSJeff Kirsher dev->netdev_ops = &netdev_ops; 498*59ffb30fSJeff Kirsher dev->ethtool_ops = &netdev_ethtool_ops; 499*59ffb30fSJeff Kirsher dev->watchdog_timeo = TX_TIMEOUT; 500*59ffb30fSJeff Kirsher INIT_WORK(&local->tx_timeout_task, xirc2ps_tx_timeout_task); 501*59ffb30fSJeff Kirsher 502*59ffb30fSJeff Kirsher return xirc2ps_config(link); 503*59ffb30fSJeff Kirsher } /* xirc2ps_attach */ 504*59ffb30fSJeff Kirsher 505*59ffb30fSJeff Kirsher static void 506*59ffb30fSJeff Kirsher xirc2ps_detach(struct pcmcia_device *link) 507*59ffb30fSJeff Kirsher { 508*59ffb30fSJeff Kirsher struct net_device *dev = link->priv; 509*59ffb30fSJeff Kirsher 510*59ffb30fSJeff Kirsher dev_dbg(&link->dev, "detach\n"); 511*59ffb30fSJeff Kirsher 512*59ffb30fSJeff Kirsher unregister_netdev(dev); 513*59ffb30fSJeff Kirsher 514*59ffb30fSJeff Kirsher xirc2ps_release(link); 515*59ffb30fSJeff Kirsher 516*59ffb30fSJeff Kirsher free_netdev(dev); 517*59ffb30fSJeff Kirsher } /* xirc2ps_detach */ 518*59ffb30fSJeff Kirsher 519*59ffb30fSJeff Kirsher /**************** 520*59ffb30fSJeff Kirsher * Detect the type of the card. s is the buffer with the data of tuple 0x20 521*59ffb30fSJeff Kirsher * Returns: 0 := not supported 522*59ffb30fSJeff Kirsher * mediaid=11 and prodid=47 523*59ffb30fSJeff Kirsher * Media-Id bits: 524*59ffb30fSJeff Kirsher * Ethernet 0x01 525*59ffb30fSJeff Kirsher * Tokenring 0x02 526*59ffb30fSJeff Kirsher * Arcnet 0x04 527*59ffb30fSJeff Kirsher * Wireless 0x08 528*59ffb30fSJeff Kirsher * Modem 0x10 529*59ffb30fSJeff Kirsher * GSM only 0x20 530*59ffb30fSJeff Kirsher * Prod-Id bits: 531*59ffb30fSJeff Kirsher * Pocket 0x10 532*59ffb30fSJeff Kirsher * External 0x20 533*59ffb30fSJeff Kirsher * Creditcard 0x40 534*59ffb30fSJeff Kirsher * Cardbus 0x80 535*59ffb30fSJeff Kirsher * 536*59ffb30fSJeff Kirsher */ 537*59ffb30fSJeff Kirsher static int 538*59ffb30fSJeff Kirsher set_card_type(struct pcmcia_device *link) 539*59ffb30fSJeff Kirsher { 540*59ffb30fSJeff Kirsher struct net_device *dev = link->priv; 541*59ffb30fSJeff Kirsher local_info_t *local = netdev_priv(dev); 542*59ffb30fSJeff Kirsher u8 *buf; 543*59ffb30fSJeff Kirsher unsigned int cisrev, mediaid, prodid; 544*59ffb30fSJeff Kirsher size_t len; 545*59ffb30fSJeff Kirsher 546*59ffb30fSJeff Kirsher len = pcmcia_get_tuple(link, CISTPL_MANFID, &buf); 547*59ffb30fSJeff Kirsher if (len < 5) { 548*59ffb30fSJeff Kirsher dev_err(&link->dev, "invalid CIS -- sorry\n"); 549*59ffb30fSJeff Kirsher return 0; 550*59ffb30fSJeff Kirsher } 551*59ffb30fSJeff Kirsher 552*59ffb30fSJeff Kirsher cisrev = buf[2]; 553*59ffb30fSJeff Kirsher mediaid = buf[3]; 554*59ffb30fSJeff Kirsher prodid = buf[4]; 555*59ffb30fSJeff Kirsher 556*59ffb30fSJeff Kirsher dev_dbg(&link->dev, "cisrev=%02x mediaid=%02x prodid=%02x\n", 557*59ffb30fSJeff Kirsher cisrev, mediaid, prodid); 558*59ffb30fSJeff Kirsher 559*59ffb30fSJeff Kirsher local->mohawk = 0; 560*59ffb30fSJeff Kirsher local->dingo = 0; 561*59ffb30fSJeff Kirsher local->modem = 0; 562*59ffb30fSJeff Kirsher local->card_type = XIR_UNKNOWN; 563*59ffb30fSJeff Kirsher if (!(prodid & 0x40)) { 564*59ffb30fSJeff Kirsher pr_notice("Oops: Not a creditcard\n"); 565*59ffb30fSJeff Kirsher return 0; 566*59ffb30fSJeff Kirsher } 567*59ffb30fSJeff Kirsher if (!(mediaid & 0x01)) { 568*59ffb30fSJeff Kirsher pr_notice("Not an Ethernet card\n"); 569*59ffb30fSJeff Kirsher return 0; 570*59ffb30fSJeff Kirsher } 571*59ffb30fSJeff Kirsher if (mediaid & 0x10) { 572*59ffb30fSJeff Kirsher local->modem = 1; 573*59ffb30fSJeff Kirsher switch(prodid & 15) { 574*59ffb30fSJeff Kirsher case 1: local->card_type = XIR_CEM ; break; 575*59ffb30fSJeff Kirsher case 2: local->card_type = XIR_CEM2 ; break; 576*59ffb30fSJeff Kirsher case 3: local->card_type = XIR_CEM3 ; break; 577*59ffb30fSJeff Kirsher case 4: local->card_type = XIR_CEM33 ; break; 578*59ffb30fSJeff Kirsher case 5: local->card_type = XIR_CEM56M; 579*59ffb30fSJeff Kirsher local->mohawk = 1; 580*59ffb30fSJeff Kirsher break; 581*59ffb30fSJeff Kirsher case 6: 582*59ffb30fSJeff Kirsher case 7: /* 7 is the RealPort 10/56 */ 583*59ffb30fSJeff Kirsher local->card_type = XIR_CEM56 ; 584*59ffb30fSJeff Kirsher local->mohawk = 1; 585*59ffb30fSJeff Kirsher local->dingo = 1; 586*59ffb30fSJeff Kirsher break; 587*59ffb30fSJeff Kirsher } 588*59ffb30fSJeff Kirsher } else { 589*59ffb30fSJeff Kirsher switch(prodid & 15) { 590*59ffb30fSJeff Kirsher case 1: local->card_type = has_ce2_string(link)? XIR_CE2 : XIR_CE ; 591*59ffb30fSJeff Kirsher break; 592*59ffb30fSJeff Kirsher case 2: local->card_type = XIR_CE2; break; 593*59ffb30fSJeff Kirsher case 3: local->card_type = XIR_CE3; 594*59ffb30fSJeff Kirsher local->mohawk = 1; 595*59ffb30fSJeff Kirsher break; 596*59ffb30fSJeff Kirsher } 597*59ffb30fSJeff Kirsher } 598*59ffb30fSJeff Kirsher if (local->card_type == XIR_CE || local->card_type == XIR_CEM) { 599*59ffb30fSJeff Kirsher pr_notice("Sorry, this is an old CE card\n"); 600*59ffb30fSJeff Kirsher return 0; 601*59ffb30fSJeff Kirsher } 602*59ffb30fSJeff Kirsher if (local->card_type == XIR_UNKNOWN) 603*59ffb30fSJeff Kirsher pr_notice("unknown card (mediaid=%02x prodid=%02x)\n", mediaid, prodid); 604*59ffb30fSJeff Kirsher 605*59ffb30fSJeff Kirsher return 1; 606*59ffb30fSJeff Kirsher } 607*59ffb30fSJeff Kirsher 608*59ffb30fSJeff Kirsher /**************** 609*59ffb30fSJeff Kirsher * There are some CE2 cards out which claim to be a CE card. 610*59ffb30fSJeff Kirsher * This function looks for a "CE2" in the 3rd version field. 611*59ffb30fSJeff Kirsher * Returns: true if this is a CE2 612*59ffb30fSJeff Kirsher */ 613*59ffb30fSJeff Kirsher static int 614*59ffb30fSJeff Kirsher has_ce2_string(struct pcmcia_device * p_dev) 615*59ffb30fSJeff Kirsher { 616*59ffb30fSJeff Kirsher if (p_dev->prod_id[2] && strstr(p_dev->prod_id[2], "CE2")) 617*59ffb30fSJeff Kirsher return 1; 618*59ffb30fSJeff Kirsher return 0; 619*59ffb30fSJeff Kirsher } 620*59ffb30fSJeff Kirsher 621*59ffb30fSJeff Kirsher static int 622*59ffb30fSJeff Kirsher xirc2ps_config_modem(struct pcmcia_device *p_dev, void *priv_data) 623*59ffb30fSJeff Kirsher { 624*59ffb30fSJeff Kirsher unsigned int ioaddr; 625*59ffb30fSJeff Kirsher 626*59ffb30fSJeff Kirsher if ((p_dev->resource[0]->start & 0xf) == 8) 627*59ffb30fSJeff Kirsher return -ENODEV; 628*59ffb30fSJeff Kirsher 629*59ffb30fSJeff Kirsher p_dev->resource[0]->end = 16; 630*59ffb30fSJeff Kirsher p_dev->resource[1]->end = 8; 631*59ffb30fSJeff Kirsher p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH; 632*59ffb30fSJeff Kirsher p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16; 633*59ffb30fSJeff Kirsher p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH; 634*59ffb30fSJeff Kirsher p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8; 635*59ffb30fSJeff Kirsher p_dev->io_lines = 10; 636*59ffb30fSJeff Kirsher 637*59ffb30fSJeff Kirsher p_dev->resource[1]->start = p_dev->resource[0]->start; 638*59ffb30fSJeff Kirsher for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) { 639*59ffb30fSJeff Kirsher p_dev->resource[0]->start = ioaddr; 640*59ffb30fSJeff Kirsher if (!pcmcia_request_io(p_dev)) 641*59ffb30fSJeff Kirsher return 0; 642*59ffb30fSJeff Kirsher } 643*59ffb30fSJeff Kirsher return -ENODEV; 644*59ffb30fSJeff Kirsher } 645*59ffb30fSJeff Kirsher 646*59ffb30fSJeff Kirsher static int 647*59ffb30fSJeff Kirsher xirc2ps_config_check(struct pcmcia_device *p_dev, void *priv_data) 648*59ffb30fSJeff Kirsher { 649*59ffb30fSJeff Kirsher int *pass = priv_data; 650*59ffb30fSJeff Kirsher resource_size_t tmp = p_dev->resource[1]->start; 651*59ffb30fSJeff Kirsher 652*59ffb30fSJeff Kirsher tmp += (*pass ? (p_dev->config_index & 0x20 ? -24 : 8) 653*59ffb30fSJeff Kirsher : (p_dev->config_index & 0x20 ? 8 : -24)); 654*59ffb30fSJeff Kirsher 655*59ffb30fSJeff Kirsher if ((p_dev->resource[0]->start & 0xf) == 8) 656*59ffb30fSJeff Kirsher return -ENODEV; 657*59ffb30fSJeff Kirsher 658*59ffb30fSJeff Kirsher p_dev->resource[0]->end = 18; 659*59ffb30fSJeff Kirsher p_dev->resource[1]->end = 8; 660*59ffb30fSJeff Kirsher p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH; 661*59ffb30fSJeff Kirsher p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16; 662*59ffb30fSJeff Kirsher p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH; 663*59ffb30fSJeff Kirsher p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8; 664*59ffb30fSJeff Kirsher p_dev->io_lines = 10; 665*59ffb30fSJeff Kirsher 666*59ffb30fSJeff Kirsher p_dev->resource[1]->start = p_dev->resource[0]->start; 667*59ffb30fSJeff Kirsher p_dev->resource[0]->start = tmp; 668*59ffb30fSJeff Kirsher return pcmcia_request_io(p_dev); 669*59ffb30fSJeff Kirsher } 670*59ffb30fSJeff Kirsher 671*59ffb30fSJeff Kirsher 672*59ffb30fSJeff Kirsher static int pcmcia_get_mac_ce(struct pcmcia_device *p_dev, 673*59ffb30fSJeff Kirsher tuple_t *tuple, 674*59ffb30fSJeff Kirsher void *priv) 675*59ffb30fSJeff Kirsher { 676*59ffb30fSJeff Kirsher struct net_device *dev = priv; 677*59ffb30fSJeff Kirsher int i; 678*59ffb30fSJeff Kirsher 679*59ffb30fSJeff Kirsher if (tuple->TupleDataLen != 13) 680*59ffb30fSJeff Kirsher return -EINVAL; 681*59ffb30fSJeff Kirsher if ((tuple->TupleData[0] != 2) || (tuple->TupleData[1] != 1) || 682*59ffb30fSJeff Kirsher (tuple->TupleData[2] != 6)) 683*59ffb30fSJeff Kirsher return -EINVAL; 684*59ffb30fSJeff Kirsher /* another try (James Lehmer's CE2 version 4.1)*/ 685*59ffb30fSJeff Kirsher for (i = 2; i < 6; i++) 686*59ffb30fSJeff Kirsher dev->dev_addr[i] = tuple->TupleData[i+2]; 687*59ffb30fSJeff Kirsher return 0; 688*59ffb30fSJeff Kirsher }; 689*59ffb30fSJeff Kirsher 690*59ffb30fSJeff Kirsher 691*59ffb30fSJeff Kirsher static int 692*59ffb30fSJeff Kirsher xirc2ps_config(struct pcmcia_device * link) 693*59ffb30fSJeff Kirsher { 694*59ffb30fSJeff Kirsher struct net_device *dev = link->priv; 695*59ffb30fSJeff Kirsher local_info_t *local = netdev_priv(dev); 696*59ffb30fSJeff Kirsher unsigned int ioaddr; 697*59ffb30fSJeff Kirsher int err; 698*59ffb30fSJeff Kirsher u8 *buf; 699*59ffb30fSJeff Kirsher size_t len; 700*59ffb30fSJeff Kirsher 701*59ffb30fSJeff Kirsher local->dingo_ccr = NULL; 702*59ffb30fSJeff Kirsher 703*59ffb30fSJeff Kirsher dev_dbg(&link->dev, "config\n"); 704*59ffb30fSJeff Kirsher 705*59ffb30fSJeff Kirsher /* Is this a valid card */ 706*59ffb30fSJeff Kirsher if (link->has_manf_id == 0) { 707*59ffb30fSJeff Kirsher pr_notice("manfid not found in CIS\n"); 708*59ffb30fSJeff Kirsher goto failure; 709*59ffb30fSJeff Kirsher } 710*59ffb30fSJeff Kirsher 711*59ffb30fSJeff Kirsher switch (link->manf_id) { 712*59ffb30fSJeff Kirsher case MANFID_XIRCOM: 713*59ffb30fSJeff Kirsher local->manf_str = "Xircom"; 714*59ffb30fSJeff Kirsher break; 715*59ffb30fSJeff Kirsher case MANFID_ACCTON: 716*59ffb30fSJeff Kirsher local->manf_str = "Accton"; 717*59ffb30fSJeff Kirsher break; 718*59ffb30fSJeff Kirsher case MANFID_COMPAQ: 719*59ffb30fSJeff Kirsher case MANFID_COMPAQ2: 720*59ffb30fSJeff Kirsher local->manf_str = "Compaq"; 721*59ffb30fSJeff Kirsher break; 722*59ffb30fSJeff Kirsher case MANFID_INTEL: 723*59ffb30fSJeff Kirsher local->manf_str = "Intel"; 724*59ffb30fSJeff Kirsher break; 725*59ffb30fSJeff Kirsher case MANFID_TOSHIBA: 726*59ffb30fSJeff Kirsher local->manf_str = "Toshiba"; 727*59ffb30fSJeff Kirsher break; 728*59ffb30fSJeff Kirsher default: 729*59ffb30fSJeff Kirsher pr_notice("Unknown Card Manufacturer ID: 0x%04x\n", 730*59ffb30fSJeff Kirsher (unsigned)link->manf_id); 731*59ffb30fSJeff Kirsher goto failure; 732*59ffb30fSJeff Kirsher } 733*59ffb30fSJeff Kirsher dev_dbg(&link->dev, "found %s card\n", local->manf_str); 734*59ffb30fSJeff Kirsher 735*59ffb30fSJeff Kirsher if (!set_card_type(link)) { 736*59ffb30fSJeff Kirsher pr_notice("this card is not supported\n"); 737*59ffb30fSJeff Kirsher goto failure; 738*59ffb30fSJeff Kirsher } 739*59ffb30fSJeff Kirsher 740*59ffb30fSJeff Kirsher /* get the ethernet address from the CIS */ 741*59ffb30fSJeff Kirsher err = pcmcia_get_mac_from_cis(link, dev); 742*59ffb30fSJeff Kirsher 743*59ffb30fSJeff Kirsher /* not found: try to get the node-id from tuple 0x89 */ 744*59ffb30fSJeff Kirsher if (err) { 745*59ffb30fSJeff Kirsher len = pcmcia_get_tuple(link, 0x89, &buf); 746*59ffb30fSJeff Kirsher /* data layout looks like tuple 0x22 */ 747*59ffb30fSJeff Kirsher if (buf && len == 8) { 748*59ffb30fSJeff Kirsher if (*buf == CISTPL_FUNCE_LAN_NODE_ID) { 749*59ffb30fSJeff Kirsher int i; 750*59ffb30fSJeff Kirsher for (i = 2; i < 6; i++) 751*59ffb30fSJeff Kirsher dev->dev_addr[i] = buf[i+2]; 752*59ffb30fSJeff Kirsher } else 753*59ffb30fSJeff Kirsher err = -1; 754*59ffb30fSJeff Kirsher } 755*59ffb30fSJeff Kirsher kfree(buf); 756*59ffb30fSJeff Kirsher } 757*59ffb30fSJeff Kirsher 758*59ffb30fSJeff Kirsher if (err) 759*59ffb30fSJeff Kirsher err = pcmcia_loop_tuple(link, CISTPL_FUNCE, pcmcia_get_mac_ce, dev); 760*59ffb30fSJeff Kirsher 761*59ffb30fSJeff Kirsher if (err) { 762*59ffb30fSJeff Kirsher pr_notice("node-id not found in CIS\n"); 763*59ffb30fSJeff Kirsher goto failure; 764*59ffb30fSJeff Kirsher } 765*59ffb30fSJeff Kirsher 766*59ffb30fSJeff Kirsher if (local->modem) { 767*59ffb30fSJeff Kirsher int pass; 768*59ffb30fSJeff Kirsher link->config_flags |= CONF_AUTO_SET_IO; 769*59ffb30fSJeff Kirsher 770*59ffb30fSJeff Kirsher if (local->dingo) { 771*59ffb30fSJeff Kirsher /* Take the Modem IO port from the CIS and scan for a free 772*59ffb30fSJeff Kirsher * Ethernet port */ 773*59ffb30fSJeff Kirsher if (!pcmcia_loop_config(link, xirc2ps_config_modem, NULL)) 774*59ffb30fSJeff Kirsher goto port_found; 775*59ffb30fSJeff Kirsher } else { 776*59ffb30fSJeff Kirsher /* We do 2 passes here: The first one uses the regular mapping and 777*59ffb30fSJeff Kirsher * the second tries again, thereby considering that the 32 ports are 778*59ffb30fSJeff Kirsher * mirrored every 32 bytes. Actually we use a mirrored port for 779*59ffb30fSJeff Kirsher * the Mako if (on the first pass) the COR bit 5 is set. 780*59ffb30fSJeff Kirsher */ 781*59ffb30fSJeff Kirsher for (pass=0; pass < 2; pass++) 782*59ffb30fSJeff Kirsher if (!pcmcia_loop_config(link, xirc2ps_config_check, 783*59ffb30fSJeff Kirsher &pass)) 784*59ffb30fSJeff Kirsher goto port_found; 785*59ffb30fSJeff Kirsher /* if special option: 786*59ffb30fSJeff Kirsher * try to configure as Ethernet only. 787*59ffb30fSJeff Kirsher * .... */ 788*59ffb30fSJeff Kirsher } 789*59ffb30fSJeff Kirsher pr_notice("no ports available\n"); 790*59ffb30fSJeff Kirsher } else { 791*59ffb30fSJeff Kirsher link->io_lines = 10; 792*59ffb30fSJeff Kirsher link->resource[0]->end = 16; 793*59ffb30fSJeff Kirsher link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16; 794*59ffb30fSJeff Kirsher for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) { 795*59ffb30fSJeff Kirsher link->resource[0]->start = ioaddr; 796*59ffb30fSJeff Kirsher if (!(err = pcmcia_request_io(link))) 797*59ffb30fSJeff Kirsher goto port_found; 798*59ffb30fSJeff Kirsher } 799*59ffb30fSJeff Kirsher link->resource[0]->start = 0; /* let CS decide */ 800*59ffb30fSJeff Kirsher if ((err = pcmcia_request_io(link))) 801*59ffb30fSJeff Kirsher goto config_error; 802*59ffb30fSJeff Kirsher } 803*59ffb30fSJeff Kirsher port_found: 804*59ffb30fSJeff Kirsher if (err) 805*59ffb30fSJeff Kirsher goto config_error; 806*59ffb30fSJeff Kirsher 807*59ffb30fSJeff Kirsher /**************** 808*59ffb30fSJeff Kirsher * Now allocate an interrupt line. Note that this does not 809*59ffb30fSJeff Kirsher * actually assign a handler to the interrupt. 810*59ffb30fSJeff Kirsher */ 811*59ffb30fSJeff Kirsher if ((err=pcmcia_request_irq(link, xirc2ps_interrupt))) 812*59ffb30fSJeff Kirsher goto config_error; 813*59ffb30fSJeff Kirsher 814*59ffb30fSJeff Kirsher link->config_flags |= CONF_ENABLE_IRQ; 815*59ffb30fSJeff Kirsher if (do_sound) 816*59ffb30fSJeff Kirsher link->config_flags |= CONF_ENABLE_SPKR; 817*59ffb30fSJeff Kirsher 818*59ffb30fSJeff Kirsher if ((err = pcmcia_enable_device(link))) 819*59ffb30fSJeff Kirsher goto config_error; 820*59ffb30fSJeff Kirsher 821*59ffb30fSJeff Kirsher if (local->dingo) { 822*59ffb30fSJeff Kirsher /* Reset the modem's BAR to the correct value 823*59ffb30fSJeff Kirsher * This is necessary because in the RequestConfiguration call, 824*59ffb30fSJeff Kirsher * the base address of the ethernet port (BasePort1) is written 825*59ffb30fSJeff Kirsher * to the BAR registers of the modem. 826*59ffb30fSJeff Kirsher */ 827*59ffb30fSJeff Kirsher err = pcmcia_write_config_byte(link, CISREG_IOBASE_0, (u8) 828*59ffb30fSJeff Kirsher link->resource[1]->start & 0xff); 829*59ffb30fSJeff Kirsher if (err) 830*59ffb30fSJeff Kirsher goto config_error; 831*59ffb30fSJeff Kirsher 832*59ffb30fSJeff Kirsher err = pcmcia_write_config_byte(link, CISREG_IOBASE_1, 833*59ffb30fSJeff Kirsher (link->resource[1]->start >> 8) & 0xff); 834*59ffb30fSJeff Kirsher if (err) 835*59ffb30fSJeff Kirsher goto config_error; 836*59ffb30fSJeff Kirsher 837*59ffb30fSJeff Kirsher /* There is no config entry for the Ethernet part which 838*59ffb30fSJeff Kirsher * is at 0x0800. So we allocate a window into the attribute 839*59ffb30fSJeff Kirsher * memory and write direct to the CIS registers 840*59ffb30fSJeff Kirsher */ 841*59ffb30fSJeff Kirsher link->resource[2]->flags = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | 842*59ffb30fSJeff Kirsher WIN_ENABLE; 843*59ffb30fSJeff Kirsher link->resource[2]->start = link->resource[2]->end = 0; 844*59ffb30fSJeff Kirsher if ((err = pcmcia_request_window(link, link->resource[2], 0))) 845*59ffb30fSJeff Kirsher goto config_error; 846*59ffb30fSJeff Kirsher 847*59ffb30fSJeff Kirsher local->dingo_ccr = ioremap(link->resource[2]->start, 0x1000) + 0x0800; 848*59ffb30fSJeff Kirsher if ((err = pcmcia_map_mem_page(link, link->resource[2], 0))) 849*59ffb30fSJeff Kirsher goto config_error; 850*59ffb30fSJeff Kirsher 851*59ffb30fSJeff Kirsher /* Setup the CCRs; there are no infos in the CIS about the Ethernet 852*59ffb30fSJeff Kirsher * part. 853*59ffb30fSJeff Kirsher */ 854*59ffb30fSJeff Kirsher writeb(0x47, local->dingo_ccr + CISREG_COR); 855*59ffb30fSJeff Kirsher ioaddr = link->resource[0]->start; 856*59ffb30fSJeff Kirsher writeb(ioaddr & 0xff , local->dingo_ccr + CISREG_IOBASE_0); 857*59ffb30fSJeff Kirsher writeb((ioaddr >> 8)&0xff , local->dingo_ccr + CISREG_IOBASE_1); 858*59ffb30fSJeff Kirsher 859*59ffb30fSJeff Kirsher #if 0 860*59ffb30fSJeff Kirsher { 861*59ffb30fSJeff Kirsher u_char tmp; 862*59ffb30fSJeff Kirsher pr_info("ECOR:"); 863*59ffb30fSJeff Kirsher for (i=0; i < 7; i++) { 864*59ffb30fSJeff Kirsher tmp = readb(local->dingo_ccr + i*2); 865*59ffb30fSJeff Kirsher pr_cont(" %02x", tmp); 866*59ffb30fSJeff Kirsher } 867*59ffb30fSJeff Kirsher pr_cont("\n"); 868*59ffb30fSJeff Kirsher pr_info("DCOR:"); 869*59ffb30fSJeff Kirsher for (i=0; i < 4; i++) { 870*59ffb30fSJeff Kirsher tmp = readb(local->dingo_ccr + 0x20 + i*2); 871*59ffb30fSJeff Kirsher pr_cont(" %02x", tmp); 872*59ffb30fSJeff Kirsher } 873*59ffb30fSJeff Kirsher pr_cont("\n"); 874*59ffb30fSJeff Kirsher pr_info("SCOR:"); 875*59ffb30fSJeff Kirsher for (i=0; i < 10; i++) { 876*59ffb30fSJeff Kirsher tmp = readb(local->dingo_ccr + 0x40 + i*2); 877*59ffb30fSJeff Kirsher pr_cont(" %02x", tmp); 878*59ffb30fSJeff Kirsher } 879*59ffb30fSJeff Kirsher pr_cont("\n"); 880*59ffb30fSJeff Kirsher } 881*59ffb30fSJeff Kirsher #endif 882*59ffb30fSJeff Kirsher 883*59ffb30fSJeff Kirsher writeb(0x01, local->dingo_ccr + 0x20); 884*59ffb30fSJeff Kirsher writeb(0x0c, local->dingo_ccr + 0x22); 885*59ffb30fSJeff Kirsher writeb(0x00, local->dingo_ccr + 0x24); 886*59ffb30fSJeff Kirsher writeb(0x00, local->dingo_ccr + 0x26); 887*59ffb30fSJeff Kirsher writeb(0x00, local->dingo_ccr + 0x28); 888*59ffb30fSJeff Kirsher } 889*59ffb30fSJeff Kirsher 890*59ffb30fSJeff Kirsher /* The if_port symbol can be set when the module is loaded */ 891*59ffb30fSJeff Kirsher local->probe_port=0; 892*59ffb30fSJeff Kirsher if (!if_port) { 893*59ffb30fSJeff Kirsher local->probe_port = dev->if_port = 1; 894*59ffb30fSJeff Kirsher } else if ((if_port >= 1 && if_port <= 2) || 895*59ffb30fSJeff Kirsher (local->mohawk && if_port==4)) 896*59ffb30fSJeff Kirsher dev->if_port = if_port; 897*59ffb30fSJeff Kirsher else 898*59ffb30fSJeff Kirsher pr_notice("invalid if_port requested\n"); 899*59ffb30fSJeff Kirsher 900*59ffb30fSJeff Kirsher /* we can now register the device with the net subsystem */ 901*59ffb30fSJeff Kirsher dev->irq = link->irq; 902*59ffb30fSJeff Kirsher dev->base_addr = link->resource[0]->start; 903*59ffb30fSJeff Kirsher 904*59ffb30fSJeff Kirsher if (local->dingo) 905*59ffb30fSJeff Kirsher do_reset(dev, 1); /* a kludge to make the cem56 work */ 906*59ffb30fSJeff Kirsher 907*59ffb30fSJeff Kirsher SET_NETDEV_DEV(dev, &link->dev); 908*59ffb30fSJeff Kirsher 909*59ffb30fSJeff Kirsher if ((err=register_netdev(dev))) { 910*59ffb30fSJeff Kirsher pr_notice("register_netdev() failed\n"); 911*59ffb30fSJeff Kirsher goto config_error; 912*59ffb30fSJeff Kirsher } 913*59ffb30fSJeff Kirsher 914*59ffb30fSJeff Kirsher /* give some infos about the hardware */ 915*59ffb30fSJeff Kirsher netdev_info(dev, "%s: port %#3lx, irq %d, hwaddr %pM\n", 916*59ffb30fSJeff Kirsher local->manf_str, (u_long)dev->base_addr, (int)dev->irq, 917*59ffb30fSJeff Kirsher dev->dev_addr); 918*59ffb30fSJeff Kirsher 919*59ffb30fSJeff Kirsher return 0; 920*59ffb30fSJeff Kirsher 921*59ffb30fSJeff Kirsher config_error: 922*59ffb30fSJeff Kirsher xirc2ps_release(link); 923*59ffb30fSJeff Kirsher return -ENODEV; 924*59ffb30fSJeff Kirsher 925*59ffb30fSJeff Kirsher failure: 926*59ffb30fSJeff Kirsher return -ENODEV; 927*59ffb30fSJeff Kirsher } /* xirc2ps_config */ 928*59ffb30fSJeff Kirsher 929*59ffb30fSJeff Kirsher static void 930*59ffb30fSJeff Kirsher xirc2ps_release(struct pcmcia_device *link) 931*59ffb30fSJeff Kirsher { 932*59ffb30fSJeff Kirsher dev_dbg(&link->dev, "release\n"); 933*59ffb30fSJeff Kirsher 934*59ffb30fSJeff Kirsher if (link->resource[2]->end) { 935*59ffb30fSJeff Kirsher struct net_device *dev = link->priv; 936*59ffb30fSJeff Kirsher local_info_t *local = netdev_priv(dev); 937*59ffb30fSJeff Kirsher if (local->dingo) 938*59ffb30fSJeff Kirsher iounmap(local->dingo_ccr - 0x0800); 939*59ffb30fSJeff Kirsher } 940*59ffb30fSJeff Kirsher pcmcia_disable_device(link); 941*59ffb30fSJeff Kirsher } /* xirc2ps_release */ 942*59ffb30fSJeff Kirsher 943*59ffb30fSJeff Kirsher /*====================================================================*/ 944*59ffb30fSJeff Kirsher 945*59ffb30fSJeff Kirsher 946*59ffb30fSJeff Kirsher static int xirc2ps_suspend(struct pcmcia_device *link) 947*59ffb30fSJeff Kirsher { 948*59ffb30fSJeff Kirsher struct net_device *dev = link->priv; 949*59ffb30fSJeff Kirsher 950*59ffb30fSJeff Kirsher if (link->open) { 951*59ffb30fSJeff Kirsher netif_device_detach(dev); 952*59ffb30fSJeff Kirsher do_powerdown(dev); 953*59ffb30fSJeff Kirsher } 954*59ffb30fSJeff Kirsher 955*59ffb30fSJeff Kirsher return 0; 956*59ffb30fSJeff Kirsher } 957*59ffb30fSJeff Kirsher 958*59ffb30fSJeff Kirsher static int xirc2ps_resume(struct pcmcia_device *link) 959*59ffb30fSJeff Kirsher { 960*59ffb30fSJeff Kirsher struct net_device *dev = link->priv; 961*59ffb30fSJeff Kirsher 962*59ffb30fSJeff Kirsher if (link->open) { 963*59ffb30fSJeff Kirsher do_reset(dev,1); 964*59ffb30fSJeff Kirsher netif_device_attach(dev); 965*59ffb30fSJeff Kirsher } 966*59ffb30fSJeff Kirsher 967*59ffb30fSJeff Kirsher return 0; 968*59ffb30fSJeff Kirsher } 969*59ffb30fSJeff Kirsher 970*59ffb30fSJeff Kirsher 971*59ffb30fSJeff Kirsher /*====================================================================*/ 972*59ffb30fSJeff Kirsher 973*59ffb30fSJeff Kirsher /**************** 974*59ffb30fSJeff Kirsher * This is the Interrupt service route. 975*59ffb30fSJeff Kirsher */ 976*59ffb30fSJeff Kirsher static irqreturn_t 977*59ffb30fSJeff Kirsher xirc2ps_interrupt(int irq, void *dev_id) 978*59ffb30fSJeff Kirsher { 979*59ffb30fSJeff Kirsher struct net_device *dev = (struct net_device *)dev_id; 980*59ffb30fSJeff Kirsher local_info_t *lp = netdev_priv(dev); 981*59ffb30fSJeff Kirsher unsigned int ioaddr; 982*59ffb30fSJeff Kirsher u_char saved_page; 983*59ffb30fSJeff Kirsher unsigned bytes_rcvd; 984*59ffb30fSJeff Kirsher unsigned int_status, eth_status, rx_status, tx_status; 985*59ffb30fSJeff Kirsher unsigned rsr, pktlen; 986*59ffb30fSJeff Kirsher ulong start_ticks = jiffies; /* fixme: jiffies rollover every 497 days 987*59ffb30fSJeff Kirsher * is this something to worry about? 988*59ffb30fSJeff Kirsher * -- on a laptop? 989*59ffb30fSJeff Kirsher */ 990*59ffb30fSJeff Kirsher 991*59ffb30fSJeff Kirsher if (!netif_device_present(dev)) 992*59ffb30fSJeff Kirsher return IRQ_HANDLED; 993*59ffb30fSJeff Kirsher 994*59ffb30fSJeff Kirsher ioaddr = dev->base_addr; 995*59ffb30fSJeff Kirsher if (lp->mohawk) { /* must disable the interrupt */ 996*59ffb30fSJeff Kirsher PutByte(XIRCREG_CR, 0); 997*59ffb30fSJeff Kirsher } 998*59ffb30fSJeff Kirsher 999*59ffb30fSJeff Kirsher pr_debug("%s: interrupt %d at %#x.\n", dev->name, irq, ioaddr); 1000*59ffb30fSJeff Kirsher 1001*59ffb30fSJeff Kirsher saved_page = GetByte(XIRCREG_PR); 1002*59ffb30fSJeff Kirsher /* Read the ISR to see whats the cause for the interrupt. 1003*59ffb30fSJeff Kirsher * This also clears the interrupt flags on CE2 cards 1004*59ffb30fSJeff Kirsher */ 1005*59ffb30fSJeff Kirsher int_status = GetByte(XIRCREG_ISR); 1006*59ffb30fSJeff Kirsher bytes_rcvd = 0; 1007*59ffb30fSJeff Kirsher loop_entry: 1008*59ffb30fSJeff Kirsher if (int_status == 0xff) { /* card may be ejected */ 1009*59ffb30fSJeff Kirsher pr_debug("%s: interrupt %d for dead card\n", dev->name, irq); 1010*59ffb30fSJeff Kirsher goto leave; 1011*59ffb30fSJeff Kirsher } 1012*59ffb30fSJeff Kirsher eth_status = GetByte(XIRCREG_ESR); 1013*59ffb30fSJeff Kirsher 1014*59ffb30fSJeff Kirsher SelectPage(0x40); 1015*59ffb30fSJeff Kirsher rx_status = GetByte(XIRCREG40_RXST0); 1016*59ffb30fSJeff Kirsher PutByte(XIRCREG40_RXST0, (~rx_status & 0xff)); 1017*59ffb30fSJeff Kirsher tx_status = GetByte(XIRCREG40_TXST0); 1018*59ffb30fSJeff Kirsher tx_status |= GetByte(XIRCREG40_TXST1) << 8; 1019*59ffb30fSJeff Kirsher PutByte(XIRCREG40_TXST0, 0); 1020*59ffb30fSJeff Kirsher PutByte(XIRCREG40_TXST1, 0); 1021*59ffb30fSJeff Kirsher 1022*59ffb30fSJeff Kirsher pr_debug("%s: ISR=%#2.2x ESR=%#2.2x RSR=%#2.2x TSR=%#4.4x\n", 1023*59ffb30fSJeff Kirsher dev->name, int_status, eth_status, rx_status, tx_status); 1024*59ffb30fSJeff Kirsher 1025*59ffb30fSJeff Kirsher /***** receive section ******/ 1026*59ffb30fSJeff Kirsher SelectPage(0); 1027*59ffb30fSJeff Kirsher while (eth_status & FullPktRcvd) { 1028*59ffb30fSJeff Kirsher rsr = GetByte(XIRCREG0_RSR); 1029*59ffb30fSJeff Kirsher if (bytes_rcvd > maxrx_bytes && (rsr & PktRxOk)) { 1030*59ffb30fSJeff Kirsher /* too many bytes received during this int, drop the rest of the 1031*59ffb30fSJeff Kirsher * packets */ 1032*59ffb30fSJeff Kirsher dev->stats.rx_dropped++; 1033*59ffb30fSJeff Kirsher pr_debug("%s: RX drop, too much done\n", dev->name); 1034*59ffb30fSJeff Kirsher } else if (rsr & PktRxOk) { 1035*59ffb30fSJeff Kirsher struct sk_buff *skb; 1036*59ffb30fSJeff Kirsher 1037*59ffb30fSJeff Kirsher pktlen = GetWord(XIRCREG0_RBC); 1038*59ffb30fSJeff Kirsher bytes_rcvd += pktlen; 1039*59ffb30fSJeff Kirsher 1040*59ffb30fSJeff Kirsher pr_debug("rsr=%#02x packet_length=%u\n", rsr, pktlen); 1041*59ffb30fSJeff Kirsher 1042*59ffb30fSJeff Kirsher skb = dev_alloc_skb(pktlen+3); /* 1 extra so we can use insw */ 1043*59ffb30fSJeff Kirsher if (!skb) { 1044*59ffb30fSJeff Kirsher pr_notice("low memory, packet dropped (size=%u)\n", pktlen); 1045*59ffb30fSJeff Kirsher dev->stats.rx_dropped++; 1046*59ffb30fSJeff Kirsher } else { /* okay get the packet */ 1047*59ffb30fSJeff Kirsher skb_reserve(skb, 2); 1048*59ffb30fSJeff Kirsher if (lp->silicon == 0 ) { /* work around a hardware bug */ 1049*59ffb30fSJeff Kirsher unsigned rhsa; /* receive start address */ 1050*59ffb30fSJeff Kirsher 1051*59ffb30fSJeff Kirsher SelectPage(5); 1052*59ffb30fSJeff Kirsher rhsa = GetWord(XIRCREG5_RHSA0); 1053*59ffb30fSJeff Kirsher SelectPage(0); 1054*59ffb30fSJeff Kirsher rhsa += 3; /* skip control infos */ 1055*59ffb30fSJeff Kirsher if (rhsa >= 0x8000) 1056*59ffb30fSJeff Kirsher rhsa = 0; 1057*59ffb30fSJeff Kirsher if (rhsa + pktlen > 0x8000) { 1058*59ffb30fSJeff Kirsher unsigned i; 1059*59ffb30fSJeff Kirsher u_char *buf = skb_put(skb, pktlen); 1060*59ffb30fSJeff Kirsher for (i=0; i < pktlen ; i++, rhsa++) { 1061*59ffb30fSJeff Kirsher buf[i] = GetByte(XIRCREG_EDP); 1062*59ffb30fSJeff Kirsher if (rhsa == 0x8000) { 1063*59ffb30fSJeff Kirsher rhsa = 0; 1064*59ffb30fSJeff Kirsher i--; 1065*59ffb30fSJeff Kirsher } 1066*59ffb30fSJeff Kirsher } 1067*59ffb30fSJeff Kirsher } else { 1068*59ffb30fSJeff Kirsher insw(ioaddr+XIRCREG_EDP, 1069*59ffb30fSJeff Kirsher skb_put(skb, pktlen), (pktlen+1)>>1); 1070*59ffb30fSJeff Kirsher } 1071*59ffb30fSJeff Kirsher } 1072*59ffb30fSJeff Kirsher #if 0 1073*59ffb30fSJeff Kirsher else if (lp->mohawk) { 1074*59ffb30fSJeff Kirsher /* To use this 32 bit access we should use 1075*59ffb30fSJeff Kirsher * a manual optimized loop 1076*59ffb30fSJeff Kirsher * Also the words are swapped, we can get more 1077*59ffb30fSJeff Kirsher * performance by using 32 bit access and swapping 1078*59ffb30fSJeff Kirsher * the words in a register. Will need this for cardbus 1079*59ffb30fSJeff Kirsher * 1080*59ffb30fSJeff Kirsher * Note: don't forget to change the ALLOC_SKB to .. +3 1081*59ffb30fSJeff Kirsher */ 1082*59ffb30fSJeff Kirsher unsigned i; 1083*59ffb30fSJeff Kirsher u_long *p = skb_put(skb, pktlen); 1084*59ffb30fSJeff Kirsher register u_long a; 1085*59ffb30fSJeff Kirsher unsigned int edpreg = ioaddr+XIRCREG_EDP-2; 1086*59ffb30fSJeff Kirsher for (i=0; i < len ; i += 4, p++) { 1087*59ffb30fSJeff Kirsher a = inl(edpreg); 1088*59ffb30fSJeff Kirsher __asm__("rorl $16,%0\n\t" 1089*59ffb30fSJeff Kirsher :"=q" (a) 1090*59ffb30fSJeff Kirsher : "0" (a)); 1091*59ffb30fSJeff Kirsher *p = a; 1092*59ffb30fSJeff Kirsher } 1093*59ffb30fSJeff Kirsher } 1094*59ffb30fSJeff Kirsher #endif 1095*59ffb30fSJeff Kirsher else { 1096*59ffb30fSJeff Kirsher insw(ioaddr+XIRCREG_EDP, skb_put(skb, pktlen), 1097*59ffb30fSJeff Kirsher (pktlen+1)>>1); 1098*59ffb30fSJeff Kirsher } 1099*59ffb30fSJeff Kirsher skb->protocol = eth_type_trans(skb, dev); 1100*59ffb30fSJeff Kirsher netif_rx(skb); 1101*59ffb30fSJeff Kirsher dev->stats.rx_packets++; 1102*59ffb30fSJeff Kirsher dev->stats.rx_bytes += pktlen; 1103*59ffb30fSJeff Kirsher if (!(rsr & PhyPkt)) 1104*59ffb30fSJeff Kirsher dev->stats.multicast++; 1105*59ffb30fSJeff Kirsher } 1106*59ffb30fSJeff Kirsher } else { /* bad packet */ 1107*59ffb30fSJeff Kirsher pr_debug("rsr=%#02x\n", rsr); 1108*59ffb30fSJeff Kirsher } 1109*59ffb30fSJeff Kirsher if (rsr & PktTooLong) { 1110*59ffb30fSJeff Kirsher dev->stats.rx_frame_errors++; 1111*59ffb30fSJeff Kirsher pr_debug("%s: Packet too long\n", dev->name); 1112*59ffb30fSJeff Kirsher } 1113*59ffb30fSJeff Kirsher if (rsr & CRCErr) { 1114*59ffb30fSJeff Kirsher dev->stats.rx_crc_errors++; 1115*59ffb30fSJeff Kirsher pr_debug("%s: CRC error\n", dev->name); 1116*59ffb30fSJeff Kirsher } 1117*59ffb30fSJeff Kirsher if (rsr & AlignErr) { 1118*59ffb30fSJeff Kirsher dev->stats.rx_fifo_errors++; /* okay ? */ 1119*59ffb30fSJeff Kirsher pr_debug("%s: Alignment error\n", dev->name); 1120*59ffb30fSJeff Kirsher } 1121*59ffb30fSJeff Kirsher 1122*59ffb30fSJeff Kirsher /* clear the received/dropped/error packet */ 1123*59ffb30fSJeff Kirsher PutWord(XIRCREG0_DO, 0x8000); /* issue cmd: skip_rx_packet */ 1124*59ffb30fSJeff Kirsher 1125*59ffb30fSJeff Kirsher /* get the new ethernet status */ 1126*59ffb30fSJeff Kirsher eth_status = GetByte(XIRCREG_ESR); 1127*59ffb30fSJeff Kirsher } 1128*59ffb30fSJeff Kirsher if (rx_status & 0x10) { /* Receive overrun */ 1129*59ffb30fSJeff Kirsher dev->stats.rx_over_errors++; 1130*59ffb30fSJeff Kirsher PutByte(XIRCREG_CR, ClearRxOvrun); 1131*59ffb30fSJeff Kirsher pr_debug("receive overrun cleared\n"); 1132*59ffb30fSJeff Kirsher } 1133*59ffb30fSJeff Kirsher 1134*59ffb30fSJeff Kirsher /***** transmit section ******/ 1135*59ffb30fSJeff Kirsher if (int_status & PktTxed) { 1136*59ffb30fSJeff Kirsher unsigned n, nn; 1137*59ffb30fSJeff Kirsher 1138*59ffb30fSJeff Kirsher n = lp->last_ptr_value; 1139*59ffb30fSJeff Kirsher nn = GetByte(XIRCREG0_PTR); 1140*59ffb30fSJeff Kirsher lp->last_ptr_value = nn; 1141*59ffb30fSJeff Kirsher if (nn < n) /* rollover */ 1142*59ffb30fSJeff Kirsher dev->stats.tx_packets += 256 - n; 1143*59ffb30fSJeff Kirsher else if (n == nn) { /* happens sometimes - don't know why */ 1144*59ffb30fSJeff Kirsher pr_debug("PTR not changed?\n"); 1145*59ffb30fSJeff Kirsher } else 1146*59ffb30fSJeff Kirsher dev->stats.tx_packets += lp->last_ptr_value - n; 1147*59ffb30fSJeff Kirsher netif_wake_queue(dev); 1148*59ffb30fSJeff Kirsher } 1149*59ffb30fSJeff Kirsher if (tx_status & 0x0002) { /* Execessive collissions */ 1150*59ffb30fSJeff Kirsher pr_debug("tx restarted due to execssive collissions\n"); 1151*59ffb30fSJeff Kirsher PutByte(XIRCREG_CR, RestartTx); /* restart transmitter process */ 1152*59ffb30fSJeff Kirsher } 1153*59ffb30fSJeff Kirsher if (tx_status & 0x0040) 1154*59ffb30fSJeff Kirsher dev->stats.tx_aborted_errors++; 1155*59ffb30fSJeff Kirsher 1156*59ffb30fSJeff Kirsher /* recalculate our work chunk so that we limit the duration of this 1157*59ffb30fSJeff Kirsher * ISR to about 1/10 of a second. 1158*59ffb30fSJeff Kirsher * Calculate only if we received a reasonable amount of bytes. 1159*59ffb30fSJeff Kirsher */ 1160*59ffb30fSJeff Kirsher if (bytes_rcvd > 1000) { 1161*59ffb30fSJeff Kirsher u_long duration = jiffies - start_ticks; 1162*59ffb30fSJeff Kirsher 1163*59ffb30fSJeff Kirsher if (duration >= HZ/10) { /* if more than about 1/10 second */ 1164*59ffb30fSJeff Kirsher maxrx_bytes = (bytes_rcvd * (HZ/10)) / duration; 1165*59ffb30fSJeff Kirsher if (maxrx_bytes < 2000) 1166*59ffb30fSJeff Kirsher maxrx_bytes = 2000; 1167*59ffb30fSJeff Kirsher else if (maxrx_bytes > 22000) 1168*59ffb30fSJeff Kirsher maxrx_bytes = 22000; 1169*59ffb30fSJeff Kirsher pr_debug("set maxrx=%u (rcvd=%u ticks=%lu)\n", 1170*59ffb30fSJeff Kirsher maxrx_bytes, bytes_rcvd, duration); 1171*59ffb30fSJeff Kirsher } else if (!duration && maxrx_bytes < 22000) { 1172*59ffb30fSJeff Kirsher /* now much faster */ 1173*59ffb30fSJeff Kirsher maxrx_bytes += 2000; 1174*59ffb30fSJeff Kirsher if (maxrx_bytes > 22000) 1175*59ffb30fSJeff Kirsher maxrx_bytes = 22000; 1176*59ffb30fSJeff Kirsher pr_debug("set maxrx=%u\n", maxrx_bytes); 1177*59ffb30fSJeff Kirsher } 1178*59ffb30fSJeff Kirsher } 1179*59ffb30fSJeff Kirsher 1180*59ffb30fSJeff Kirsher leave: 1181*59ffb30fSJeff Kirsher if (lockup_hack) { 1182*59ffb30fSJeff Kirsher if (int_status != 0xff && (int_status = GetByte(XIRCREG_ISR)) != 0) 1183*59ffb30fSJeff Kirsher goto loop_entry; 1184*59ffb30fSJeff Kirsher } 1185*59ffb30fSJeff Kirsher SelectPage(saved_page); 1186*59ffb30fSJeff Kirsher PutByte(XIRCREG_CR, EnableIntr); /* re-enable interrupts */ 1187*59ffb30fSJeff Kirsher /* Instead of dropping packets during a receive, we could 1188*59ffb30fSJeff Kirsher * force an interrupt with this command: 1189*59ffb30fSJeff Kirsher * PutByte(XIRCREG_CR, EnableIntr|ForceIntr); 1190*59ffb30fSJeff Kirsher */ 1191*59ffb30fSJeff Kirsher return IRQ_HANDLED; 1192*59ffb30fSJeff Kirsher } /* xirc2ps_interrupt */ 1193*59ffb30fSJeff Kirsher 1194*59ffb30fSJeff Kirsher /*====================================================================*/ 1195*59ffb30fSJeff Kirsher 1196*59ffb30fSJeff Kirsher static void 1197*59ffb30fSJeff Kirsher xirc2ps_tx_timeout_task(struct work_struct *work) 1198*59ffb30fSJeff Kirsher { 1199*59ffb30fSJeff Kirsher local_info_t *local = 1200*59ffb30fSJeff Kirsher container_of(work, local_info_t, tx_timeout_task); 1201*59ffb30fSJeff Kirsher struct net_device *dev = local->dev; 1202*59ffb30fSJeff Kirsher /* reset the card */ 1203*59ffb30fSJeff Kirsher do_reset(dev,1); 1204*59ffb30fSJeff Kirsher dev->trans_start = jiffies; /* prevent tx timeout */ 1205*59ffb30fSJeff Kirsher netif_wake_queue(dev); 1206*59ffb30fSJeff Kirsher } 1207*59ffb30fSJeff Kirsher 1208*59ffb30fSJeff Kirsher static void 1209*59ffb30fSJeff Kirsher xirc_tx_timeout(struct net_device *dev) 1210*59ffb30fSJeff Kirsher { 1211*59ffb30fSJeff Kirsher local_info_t *lp = netdev_priv(dev); 1212*59ffb30fSJeff Kirsher dev->stats.tx_errors++; 1213*59ffb30fSJeff Kirsher netdev_notice(dev, "transmit timed out\n"); 1214*59ffb30fSJeff Kirsher schedule_work(&lp->tx_timeout_task); 1215*59ffb30fSJeff Kirsher } 1216*59ffb30fSJeff Kirsher 1217*59ffb30fSJeff Kirsher static netdev_tx_t 1218*59ffb30fSJeff Kirsher do_start_xmit(struct sk_buff *skb, struct net_device *dev) 1219*59ffb30fSJeff Kirsher { 1220*59ffb30fSJeff Kirsher local_info_t *lp = netdev_priv(dev); 1221*59ffb30fSJeff Kirsher unsigned int ioaddr = dev->base_addr; 1222*59ffb30fSJeff Kirsher int okay; 1223*59ffb30fSJeff Kirsher unsigned freespace; 1224*59ffb30fSJeff Kirsher unsigned pktlen = skb->len; 1225*59ffb30fSJeff Kirsher 1226*59ffb30fSJeff Kirsher pr_debug("do_start_xmit(skb=%p, dev=%p) len=%u\n", 1227*59ffb30fSJeff Kirsher skb, dev, pktlen); 1228*59ffb30fSJeff Kirsher 1229*59ffb30fSJeff Kirsher 1230*59ffb30fSJeff Kirsher /* adjust the packet length to min. required 1231*59ffb30fSJeff Kirsher * and hope that the buffer is large enough 1232*59ffb30fSJeff Kirsher * to provide some random data. 1233*59ffb30fSJeff Kirsher * fixme: For Mohawk we can change this by sending 1234*59ffb30fSJeff Kirsher * a larger packetlen than we actually have; the chip will 1235*59ffb30fSJeff Kirsher * pad this in his buffer with random bytes 1236*59ffb30fSJeff Kirsher */ 1237*59ffb30fSJeff Kirsher if (pktlen < ETH_ZLEN) 1238*59ffb30fSJeff Kirsher { 1239*59ffb30fSJeff Kirsher if (skb_padto(skb, ETH_ZLEN)) 1240*59ffb30fSJeff Kirsher return NETDEV_TX_OK; 1241*59ffb30fSJeff Kirsher pktlen = ETH_ZLEN; 1242*59ffb30fSJeff Kirsher } 1243*59ffb30fSJeff Kirsher 1244*59ffb30fSJeff Kirsher netif_stop_queue(dev); 1245*59ffb30fSJeff Kirsher SelectPage(0); 1246*59ffb30fSJeff Kirsher PutWord(XIRCREG0_TRS, (u_short)pktlen+2); 1247*59ffb30fSJeff Kirsher freespace = GetWord(XIRCREG0_TSO); 1248*59ffb30fSJeff Kirsher okay = freespace & 0x8000; 1249*59ffb30fSJeff Kirsher freespace &= 0x7fff; 1250*59ffb30fSJeff Kirsher /* TRS doesn't work - (indeed it is eliminated with sil-rev 1) */ 1251*59ffb30fSJeff Kirsher okay = pktlen +2 < freespace; 1252*59ffb30fSJeff Kirsher pr_debug("%s: avail. tx space=%u%s\n", 1253*59ffb30fSJeff Kirsher dev->name, freespace, okay ? " (okay)":" (not enough)"); 1254*59ffb30fSJeff Kirsher if (!okay) { /* not enough space */ 1255*59ffb30fSJeff Kirsher return NETDEV_TX_BUSY; /* upper layer may decide to requeue this packet */ 1256*59ffb30fSJeff Kirsher } 1257*59ffb30fSJeff Kirsher /* send the packet */ 1258*59ffb30fSJeff Kirsher PutWord(XIRCREG_EDP, (u_short)pktlen); 1259*59ffb30fSJeff Kirsher outsw(ioaddr+XIRCREG_EDP, skb->data, pktlen>>1); 1260*59ffb30fSJeff Kirsher if (pktlen & 1) 1261*59ffb30fSJeff Kirsher PutByte(XIRCREG_EDP, skb->data[pktlen-1]); 1262*59ffb30fSJeff Kirsher 1263*59ffb30fSJeff Kirsher if (lp->mohawk) 1264*59ffb30fSJeff Kirsher PutByte(XIRCREG_CR, TransmitPacket|EnableIntr); 1265*59ffb30fSJeff Kirsher 1266*59ffb30fSJeff Kirsher dev_kfree_skb (skb); 1267*59ffb30fSJeff Kirsher dev->stats.tx_bytes += pktlen; 1268*59ffb30fSJeff Kirsher netif_start_queue(dev); 1269*59ffb30fSJeff Kirsher return NETDEV_TX_OK; 1270*59ffb30fSJeff Kirsher } 1271*59ffb30fSJeff Kirsher 1272*59ffb30fSJeff Kirsher struct set_address_info { 1273*59ffb30fSJeff Kirsher int reg_nr; 1274*59ffb30fSJeff Kirsher int page_nr; 1275*59ffb30fSJeff Kirsher int mohawk; 1276*59ffb30fSJeff Kirsher unsigned int ioaddr; 1277*59ffb30fSJeff Kirsher }; 1278*59ffb30fSJeff Kirsher 1279*59ffb30fSJeff Kirsher static void set_address(struct set_address_info *sa_info, char *addr) 1280*59ffb30fSJeff Kirsher { 1281*59ffb30fSJeff Kirsher unsigned int ioaddr = sa_info->ioaddr; 1282*59ffb30fSJeff Kirsher int i; 1283*59ffb30fSJeff Kirsher 1284*59ffb30fSJeff Kirsher for (i = 0; i < 6; i++) { 1285*59ffb30fSJeff Kirsher if (sa_info->reg_nr > 15) { 1286*59ffb30fSJeff Kirsher sa_info->reg_nr = 8; 1287*59ffb30fSJeff Kirsher sa_info->page_nr++; 1288*59ffb30fSJeff Kirsher SelectPage(sa_info->page_nr); 1289*59ffb30fSJeff Kirsher } 1290*59ffb30fSJeff Kirsher if (sa_info->mohawk) 1291*59ffb30fSJeff Kirsher PutByte(sa_info->reg_nr++, addr[5 - i]); 1292*59ffb30fSJeff Kirsher else 1293*59ffb30fSJeff Kirsher PutByte(sa_info->reg_nr++, addr[i]); 1294*59ffb30fSJeff Kirsher } 1295*59ffb30fSJeff Kirsher } 1296*59ffb30fSJeff Kirsher 1297*59ffb30fSJeff Kirsher /**************** 1298*59ffb30fSJeff Kirsher * Set all addresses: This first one is the individual address, 1299*59ffb30fSJeff Kirsher * the next 9 addresses are taken from the multicast list and 1300*59ffb30fSJeff Kirsher * the rest is filled with the individual address. 1301*59ffb30fSJeff Kirsher */ 1302*59ffb30fSJeff Kirsher static void set_addresses(struct net_device *dev) 1303*59ffb30fSJeff Kirsher { 1304*59ffb30fSJeff Kirsher unsigned int ioaddr = dev->base_addr; 1305*59ffb30fSJeff Kirsher local_info_t *lp = netdev_priv(dev); 1306*59ffb30fSJeff Kirsher struct netdev_hw_addr *ha; 1307*59ffb30fSJeff Kirsher struct set_address_info sa_info; 1308*59ffb30fSJeff Kirsher int i; 1309*59ffb30fSJeff Kirsher 1310*59ffb30fSJeff Kirsher /* 1311*59ffb30fSJeff Kirsher * Setup the info structure so that by first set_address call it will do 1312*59ffb30fSJeff Kirsher * SelectPage with the right page number. Hence these ones here. 1313*59ffb30fSJeff Kirsher */ 1314*59ffb30fSJeff Kirsher sa_info.reg_nr = 15 + 1; 1315*59ffb30fSJeff Kirsher sa_info.page_nr = 0x50 - 1; 1316*59ffb30fSJeff Kirsher sa_info.mohawk = lp->mohawk; 1317*59ffb30fSJeff Kirsher sa_info.ioaddr = ioaddr; 1318*59ffb30fSJeff Kirsher 1319*59ffb30fSJeff Kirsher set_address(&sa_info, dev->dev_addr); 1320*59ffb30fSJeff Kirsher i = 0; 1321*59ffb30fSJeff Kirsher netdev_for_each_mc_addr(ha, dev) { 1322*59ffb30fSJeff Kirsher if (i++ == 9) 1323*59ffb30fSJeff Kirsher break; 1324*59ffb30fSJeff Kirsher set_address(&sa_info, ha->addr); 1325*59ffb30fSJeff Kirsher } 1326*59ffb30fSJeff Kirsher while (i++ < 9) 1327*59ffb30fSJeff Kirsher set_address(&sa_info, dev->dev_addr); 1328*59ffb30fSJeff Kirsher SelectPage(0); 1329*59ffb30fSJeff Kirsher } 1330*59ffb30fSJeff Kirsher 1331*59ffb30fSJeff Kirsher /**************** 1332*59ffb30fSJeff Kirsher * Set or clear the multicast filter for this adaptor. 1333*59ffb30fSJeff Kirsher * We can filter up to 9 addresses, if more are requested we set 1334*59ffb30fSJeff Kirsher * multicast promiscuous mode. 1335*59ffb30fSJeff Kirsher */ 1336*59ffb30fSJeff Kirsher 1337*59ffb30fSJeff Kirsher static void 1338*59ffb30fSJeff Kirsher set_multicast_list(struct net_device *dev) 1339*59ffb30fSJeff Kirsher { 1340*59ffb30fSJeff Kirsher unsigned int ioaddr = dev->base_addr; 1341*59ffb30fSJeff Kirsher unsigned value; 1342*59ffb30fSJeff Kirsher 1343*59ffb30fSJeff Kirsher SelectPage(0x42); 1344*59ffb30fSJeff Kirsher value = GetByte(XIRCREG42_SWC1) & 0xC0; 1345*59ffb30fSJeff Kirsher 1346*59ffb30fSJeff Kirsher if (dev->flags & IFF_PROMISC) { /* snoop */ 1347*59ffb30fSJeff Kirsher PutByte(XIRCREG42_SWC1, value | 0x06); /* set MPE and PME */ 1348*59ffb30fSJeff Kirsher } else if (netdev_mc_count(dev) > 9 || (dev->flags & IFF_ALLMULTI)) { 1349*59ffb30fSJeff Kirsher PutByte(XIRCREG42_SWC1, value | 0x02); /* set MPE */ 1350*59ffb30fSJeff Kirsher } else if (!netdev_mc_empty(dev)) { 1351*59ffb30fSJeff Kirsher /* the chip can filter 9 addresses perfectly */ 1352*59ffb30fSJeff Kirsher PutByte(XIRCREG42_SWC1, value | 0x01); 1353*59ffb30fSJeff Kirsher SelectPage(0x40); 1354*59ffb30fSJeff Kirsher PutByte(XIRCREG40_CMD0, Offline); 1355*59ffb30fSJeff Kirsher set_addresses(dev); 1356*59ffb30fSJeff Kirsher SelectPage(0x40); 1357*59ffb30fSJeff Kirsher PutByte(XIRCREG40_CMD0, EnableRecv | Online); 1358*59ffb30fSJeff Kirsher } else { /* standard usage */ 1359*59ffb30fSJeff Kirsher PutByte(XIRCREG42_SWC1, value | 0x00); 1360*59ffb30fSJeff Kirsher } 1361*59ffb30fSJeff Kirsher SelectPage(0); 1362*59ffb30fSJeff Kirsher } 1363*59ffb30fSJeff Kirsher 1364*59ffb30fSJeff Kirsher static int 1365*59ffb30fSJeff Kirsher do_config(struct net_device *dev, struct ifmap *map) 1366*59ffb30fSJeff Kirsher { 1367*59ffb30fSJeff Kirsher local_info_t *local = netdev_priv(dev); 1368*59ffb30fSJeff Kirsher 1369*59ffb30fSJeff Kirsher pr_debug("do_config(%p)\n", dev); 1370*59ffb30fSJeff Kirsher if (map->port != 255 && map->port != dev->if_port) { 1371*59ffb30fSJeff Kirsher if (map->port > 4) 1372*59ffb30fSJeff Kirsher return -EINVAL; 1373*59ffb30fSJeff Kirsher if (!map->port) { 1374*59ffb30fSJeff Kirsher local->probe_port = 1; 1375*59ffb30fSJeff Kirsher dev->if_port = 1; 1376*59ffb30fSJeff Kirsher } else { 1377*59ffb30fSJeff Kirsher local->probe_port = 0; 1378*59ffb30fSJeff Kirsher dev->if_port = map->port; 1379*59ffb30fSJeff Kirsher } 1380*59ffb30fSJeff Kirsher netdev_info(dev, "switching to %s port\n", if_names[dev->if_port]); 1381*59ffb30fSJeff Kirsher do_reset(dev,1); /* not the fine way :-) */ 1382*59ffb30fSJeff Kirsher } 1383*59ffb30fSJeff Kirsher return 0; 1384*59ffb30fSJeff Kirsher } 1385*59ffb30fSJeff Kirsher 1386*59ffb30fSJeff Kirsher /**************** 1387*59ffb30fSJeff Kirsher * Open the driver 1388*59ffb30fSJeff Kirsher */ 1389*59ffb30fSJeff Kirsher static int 1390*59ffb30fSJeff Kirsher do_open(struct net_device *dev) 1391*59ffb30fSJeff Kirsher { 1392*59ffb30fSJeff Kirsher local_info_t *lp = netdev_priv(dev); 1393*59ffb30fSJeff Kirsher struct pcmcia_device *link = lp->p_dev; 1394*59ffb30fSJeff Kirsher 1395*59ffb30fSJeff Kirsher dev_dbg(&link->dev, "do_open(%p)\n", dev); 1396*59ffb30fSJeff Kirsher 1397*59ffb30fSJeff Kirsher /* Check that the PCMCIA card is still here. */ 1398*59ffb30fSJeff Kirsher /* Physical device present signature. */ 1399*59ffb30fSJeff Kirsher if (!pcmcia_dev_present(link)) 1400*59ffb30fSJeff Kirsher return -ENODEV; 1401*59ffb30fSJeff Kirsher 1402*59ffb30fSJeff Kirsher /* okay */ 1403*59ffb30fSJeff Kirsher link->open++; 1404*59ffb30fSJeff Kirsher 1405*59ffb30fSJeff Kirsher netif_start_queue(dev); 1406*59ffb30fSJeff Kirsher do_reset(dev,1); 1407*59ffb30fSJeff Kirsher 1408*59ffb30fSJeff Kirsher return 0; 1409*59ffb30fSJeff Kirsher } 1410*59ffb30fSJeff Kirsher 1411*59ffb30fSJeff Kirsher static void netdev_get_drvinfo(struct net_device *dev, 1412*59ffb30fSJeff Kirsher struct ethtool_drvinfo *info) 1413*59ffb30fSJeff Kirsher { 1414*59ffb30fSJeff Kirsher strcpy(info->driver, "xirc2ps_cs"); 1415*59ffb30fSJeff Kirsher sprintf(info->bus_info, "PCMCIA 0x%lx", dev->base_addr); 1416*59ffb30fSJeff Kirsher } 1417*59ffb30fSJeff Kirsher 1418*59ffb30fSJeff Kirsher static const struct ethtool_ops netdev_ethtool_ops = { 1419*59ffb30fSJeff Kirsher .get_drvinfo = netdev_get_drvinfo, 1420*59ffb30fSJeff Kirsher }; 1421*59ffb30fSJeff Kirsher 1422*59ffb30fSJeff Kirsher static int 1423*59ffb30fSJeff Kirsher do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 1424*59ffb30fSJeff Kirsher { 1425*59ffb30fSJeff Kirsher local_info_t *local = netdev_priv(dev); 1426*59ffb30fSJeff Kirsher unsigned int ioaddr = dev->base_addr; 1427*59ffb30fSJeff Kirsher struct mii_ioctl_data *data = if_mii(rq); 1428*59ffb30fSJeff Kirsher 1429*59ffb30fSJeff Kirsher pr_debug("%s: ioctl(%-.6s, %#04x) %04x %04x %04x %04x\n", 1430*59ffb30fSJeff Kirsher dev->name, rq->ifr_ifrn.ifrn_name, cmd, 1431*59ffb30fSJeff Kirsher data->phy_id, data->reg_num, data->val_in, data->val_out); 1432*59ffb30fSJeff Kirsher 1433*59ffb30fSJeff Kirsher if (!local->mohawk) 1434*59ffb30fSJeff Kirsher return -EOPNOTSUPP; 1435*59ffb30fSJeff Kirsher 1436*59ffb30fSJeff Kirsher switch(cmd) { 1437*59ffb30fSJeff Kirsher case SIOCGMIIPHY: /* Get the address of the PHY in use. */ 1438*59ffb30fSJeff Kirsher data->phy_id = 0; /* we have only this address */ 1439*59ffb30fSJeff Kirsher /* fall through */ 1440*59ffb30fSJeff Kirsher case SIOCGMIIREG: /* Read the specified MII register. */ 1441*59ffb30fSJeff Kirsher data->val_out = mii_rd(ioaddr, data->phy_id & 0x1f, 1442*59ffb30fSJeff Kirsher data->reg_num & 0x1f); 1443*59ffb30fSJeff Kirsher break; 1444*59ffb30fSJeff Kirsher case SIOCSMIIREG: /* Write the specified MII register */ 1445*59ffb30fSJeff Kirsher mii_wr(ioaddr, data->phy_id & 0x1f, data->reg_num & 0x1f, data->val_in, 1446*59ffb30fSJeff Kirsher 16); 1447*59ffb30fSJeff Kirsher break; 1448*59ffb30fSJeff Kirsher default: 1449*59ffb30fSJeff Kirsher return -EOPNOTSUPP; 1450*59ffb30fSJeff Kirsher } 1451*59ffb30fSJeff Kirsher return 0; 1452*59ffb30fSJeff Kirsher } 1453*59ffb30fSJeff Kirsher 1454*59ffb30fSJeff Kirsher static void 1455*59ffb30fSJeff Kirsher hardreset(struct net_device *dev) 1456*59ffb30fSJeff Kirsher { 1457*59ffb30fSJeff Kirsher local_info_t *local = netdev_priv(dev); 1458*59ffb30fSJeff Kirsher unsigned int ioaddr = dev->base_addr; 1459*59ffb30fSJeff Kirsher 1460*59ffb30fSJeff Kirsher SelectPage(4); 1461*59ffb30fSJeff Kirsher udelay(1); 1462*59ffb30fSJeff Kirsher PutByte(XIRCREG4_GPR1, 0); /* clear bit 0: power down */ 1463*59ffb30fSJeff Kirsher msleep(40); /* wait 40 msec */ 1464*59ffb30fSJeff Kirsher if (local->mohawk) 1465*59ffb30fSJeff Kirsher PutByte(XIRCREG4_GPR1, 1); /* set bit 0: power up */ 1466*59ffb30fSJeff Kirsher else 1467*59ffb30fSJeff Kirsher PutByte(XIRCREG4_GPR1, 1 | 4); /* set bit 0: power up, bit 2: AIC */ 1468*59ffb30fSJeff Kirsher msleep(20); /* wait 20 msec */ 1469*59ffb30fSJeff Kirsher } 1470*59ffb30fSJeff Kirsher 1471*59ffb30fSJeff Kirsher static void 1472*59ffb30fSJeff Kirsher do_reset(struct net_device *dev, int full) 1473*59ffb30fSJeff Kirsher { 1474*59ffb30fSJeff Kirsher local_info_t *local = netdev_priv(dev); 1475*59ffb30fSJeff Kirsher unsigned int ioaddr = dev->base_addr; 1476*59ffb30fSJeff Kirsher unsigned value; 1477*59ffb30fSJeff Kirsher 1478*59ffb30fSJeff Kirsher pr_debug("%s: do_reset(%p,%d)\n", dev? dev->name:"eth?", dev, full); 1479*59ffb30fSJeff Kirsher 1480*59ffb30fSJeff Kirsher hardreset(dev); 1481*59ffb30fSJeff Kirsher PutByte(XIRCREG_CR, SoftReset); /* set */ 1482*59ffb30fSJeff Kirsher msleep(20); /* wait 20 msec */ 1483*59ffb30fSJeff Kirsher PutByte(XIRCREG_CR, 0); /* clear */ 1484*59ffb30fSJeff Kirsher msleep(40); /* wait 40 msec */ 1485*59ffb30fSJeff Kirsher if (local->mohawk) { 1486*59ffb30fSJeff Kirsher SelectPage(4); 1487*59ffb30fSJeff Kirsher /* set pin GP1 and GP2 to output (0x0c) 1488*59ffb30fSJeff Kirsher * set GP1 to low to power up the ML6692 (0x00) 1489*59ffb30fSJeff Kirsher * set GP2 to high to power up the 10Mhz chip (0x02) 1490*59ffb30fSJeff Kirsher */ 1491*59ffb30fSJeff Kirsher PutByte(XIRCREG4_GPR0, 0x0e); 1492*59ffb30fSJeff Kirsher } 1493*59ffb30fSJeff Kirsher 1494*59ffb30fSJeff Kirsher /* give the circuits some time to power up */ 1495*59ffb30fSJeff Kirsher msleep(500); /* about 500ms */ 1496*59ffb30fSJeff Kirsher 1497*59ffb30fSJeff Kirsher local->last_ptr_value = 0; 1498*59ffb30fSJeff Kirsher local->silicon = local->mohawk ? (GetByte(XIRCREG4_BOV) & 0x70) >> 4 1499*59ffb30fSJeff Kirsher : (GetByte(XIRCREG4_BOV) & 0x30) >> 4; 1500*59ffb30fSJeff Kirsher 1501*59ffb30fSJeff Kirsher if (local->probe_port) { 1502*59ffb30fSJeff Kirsher if (!local->mohawk) { 1503*59ffb30fSJeff Kirsher SelectPage(4); 1504*59ffb30fSJeff Kirsher PutByte(XIRCREG4_GPR0, 4); 1505*59ffb30fSJeff Kirsher local->probe_port = 0; 1506*59ffb30fSJeff Kirsher } 1507*59ffb30fSJeff Kirsher } else if (dev->if_port == 2) { /* enable 10Base2 */ 1508*59ffb30fSJeff Kirsher SelectPage(0x42); 1509*59ffb30fSJeff Kirsher PutByte(XIRCREG42_SWC1, 0xC0); 1510*59ffb30fSJeff Kirsher } else { /* enable 10BaseT */ 1511*59ffb30fSJeff Kirsher SelectPage(0x42); 1512*59ffb30fSJeff Kirsher PutByte(XIRCREG42_SWC1, 0x80); 1513*59ffb30fSJeff Kirsher } 1514*59ffb30fSJeff Kirsher msleep(40); /* wait 40 msec to let it complete */ 1515*59ffb30fSJeff Kirsher 1516*59ffb30fSJeff Kirsher #if 0 1517*59ffb30fSJeff Kirsher { 1518*59ffb30fSJeff Kirsher SelectPage(0); 1519*59ffb30fSJeff Kirsher value = GetByte(XIRCREG_ESR); /* read the ESR */ 1520*59ffb30fSJeff Kirsher pr_debug("%s: ESR is: %#02x\n", dev->name, value); 1521*59ffb30fSJeff Kirsher } 1522*59ffb30fSJeff Kirsher #endif 1523*59ffb30fSJeff Kirsher 1524*59ffb30fSJeff Kirsher /* setup the ECR */ 1525*59ffb30fSJeff Kirsher SelectPage(1); 1526*59ffb30fSJeff Kirsher PutByte(XIRCREG1_IMR0, 0xff); /* allow all ints */ 1527*59ffb30fSJeff Kirsher PutByte(XIRCREG1_IMR1, 1 ); /* and Set TxUnderrunDetect */ 1528*59ffb30fSJeff Kirsher value = GetByte(XIRCREG1_ECR); 1529*59ffb30fSJeff Kirsher #if 0 1530*59ffb30fSJeff Kirsher if (local->mohawk) 1531*59ffb30fSJeff Kirsher value |= DisableLinkPulse; 1532*59ffb30fSJeff Kirsher PutByte(XIRCREG1_ECR, value); 1533*59ffb30fSJeff Kirsher #endif 1534*59ffb30fSJeff Kirsher pr_debug("%s: ECR is: %#02x\n", dev->name, value); 1535*59ffb30fSJeff Kirsher 1536*59ffb30fSJeff Kirsher SelectPage(0x42); 1537*59ffb30fSJeff Kirsher PutByte(XIRCREG42_SWC0, 0x20); /* disable source insertion */ 1538*59ffb30fSJeff Kirsher 1539*59ffb30fSJeff Kirsher if (local->silicon != 1) { 1540*59ffb30fSJeff Kirsher /* set the local memory dividing line. 1541*59ffb30fSJeff Kirsher * The comments in the sample code say that this is only 1542*59ffb30fSJeff Kirsher * settable with the scipper version 2 which is revision 0. 1543*59ffb30fSJeff Kirsher * Always for CE3 cards 1544*59ffb30fSJeff Kirsher */ 1545*59ffb30fSJeff Kirsher SelectPage(2); 1546*59ffb30fSJeff Kirsher PutWord(XIRCREG2_RBS, 0x2000); 1547*59ffb30fSJeff Kirsher } 1548*59ffb30fSJeff Kirsher 1549*59ffb30fSJeff Kirsher if (full) 1550*59ffb30fSJeff Kirsher set_addresses(dev); 1551*59ffb30fSJeff Kirsher 1552*59ffb30fSJeff Kirsher /* Hardware workaround: 1553*59ffb30fSJeff Kirsher * The receive byte pointer after reset is off by 1 so we need 1554*59ffb30fSJeff Kirsher * to move the offset pointer back to 0. 1555*59ffb30fSJeff Kirsher */ 1556*59ffb30fSJeff Kirsher SelectPage(0); 1557*59ffb30fSJeff Kirsher PutWord(XIRCREG0_DO, 0x2000); /* change offset command, off=0 */ 1558*59ffb30fSJeff Kirsher 1559*59ffb30fSJeff Kirsher /* setup MAC IMRs and clear status registers */ 1560*59ffb30fSJeff Kirsher SelectPage(0x40); /* Bit 7 ... bit 0 */ 1561*59ffb30fSJeff Kirsher PutByte(XIRCREG40_RMASK0, 0xff); /* ROK, RAB, rsv, RO, CRC, AE, PTL, MP */ 1562*59ffb30fSJeff Kirsher PutByte(XIRCREG40_TMASK0, 0xff); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */ 1563*59ffb30fSJeff Kirsher PutByte(XIRCREG40_TMASK1, 0xb0); /* rsv, rsv, PTD, EXT, rsv,rsv,rsv, rsv*/ 1564*59ffb30fSJeff Kirsher PutByte(XIRCREG40_RXST0, 0x00); /* ROK, RAB, REN, RO, CRC, AE, PTL, MP */ 1565*59ffb30fSJeff Kirsher PutByte(XIRCREG40_TXST0, 0x00); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */ 1566*59ffb30fSJeff Kirsher PutByte(XIRCREG40_TXST1, 0x00); /* TEN, rsv, PTD, EXT, retry_counter:4 */ 1567*59ffb30fSJeff Kirsher 1568*59ffb30fSJeff Kirsher if (full && local->mohawk && init_mii(dev)) { 1569*59ffb30fSJeff Kirsher if (dev->if_port == 4 || local->dingo || local->new_mii) { 1570*59ffb30fSJeff Kirsher netdev_info(dev, "MII selected\n"); 1571*59ffb30fSJeff Kirsher SelectPage(2); 1572*59ffb30fSJeff Kirsher PutByte(XIRCREG2_MSR, GetByte(XIRCREG2_MSR) | 0x08); 1573*59ffb30fSJeff Kirsher msleep(20); 1574*59ffb30fSJeff Kirsher } else { 1575*59ffb30fSJeff Kirsher netdev_info(dev, "MII detected; using 10mbs\n"); 1576*59ffb30fSJeff Kirsher SelectPage(0x42); 1577*59ffb30fSJeff Kirsher if (dev->if_port == 2) /* enable 10Base2 */ 1578*59ffb30fSJeff Kirsher PutByte(XIRCREG42_SWC1, 0xC0); 1579*59ffb30fSJeff Kirsher else /* enable 10BaseT */ 1580*59ffb30fSJeff Kirsher PutByte(XIRCREG42_SWC1, 0x80); 1581*59ffb30fSJeff Kirsher msleep(40); /* wait 40 msec to let it complete */ 1582*59ffb30fSJeff Kirsher } 1583*59ffb30fSJeff Kirsher if (full_duplex) 1584*59ffb30fSJeff Kirsher PutByte(XIRCREG1_ECR, GetByte(XIRCREG1_ECR | FullDuplex)); 1585*59ffb30fSJeff Kirsher } else { /* No MII */ 1586*59ffb30fSJeff Kirsher SelectPage(0); 1587*59ffb30fSJeff Kirsher value = GetByte(XIRCREG_ESR); /* read the ESR */ 1588*59ffb30fSJeff Kirsher dev->if_port = (value & MediaSelect) ? 1 : 2; 1589*59ffb30fSJeff Kirsher } 1590*59ffb30fSJeff Kirsher 1591*59ffb30fSJeff Kirsher /* configure the LEDs */ 1592*59ffb30fSJeff Kirsher SelectPage(2); 1593*59ffb30fSJeff Kirsher if (dev->if_port == 1 || dev->if_port == 4) /* TP: Link and Activity */ 1594*59ffb30fSJeff Kirsher PutByte(XIRCREG2_LED, 0x3b); 1595*59ffb30fSJeff Kirsher else /* Coax: Not-Collision and Activity */ 1596*59ffb30fSJeff Kirsher PutByte(XIRCREG2_LED, 0x3a); 1597*59ffb30fSJeff Kirsher 1598*59ffb30fSJeff Kirsher if (local->dingo) 1599*59ffb30fSJeff Kirsher PutByte(0x0b, 0x04); /* 100 Mbit LED */ 1600*59ffb30fSJeff Kirsher 1601*59ffb30fSJeff Kirsher /* enable receiver and put the mac online */ 1602*59ffb30fSJeff Kirsher if (full) { 1603*59ffb30fSJeff Kirsher set_multicast_list(dev); 1604*59ffb30fSJeff Kirsher SelectPage(0x40); 1605*59ffb30fSJeff Kirsher PutByte(XIRCREG40_CMD0, EnableRecv | Online); 1606*59ffb30fSJeff Kirsher } 1607*59ffb30fSJeff Kirsher 1608*59ffb30fSJeff Kirsher /* setup Ethernet IMR and enable interrupts */ 1609*59ffb30fSJeff Kirsher SelectPage(1); 1610*59ffb30fSJeff Kirsher PutByte(XIRCREG1_IMR0, 0xff); 1611*59ffb30fSJeff Kirsher udelay(1); 1612*59ffb30fSJeff Kirsher SelectPage(0); 1613*59ffb30fSJeff Kirsher PutByte(XIRCREG_CR, EnableIntr); 1614*59ffb30fSJeff Kirsher if (local->modem && !local->dingo) { /* do some magic */ 1615*59ffb30fSJeff Kirsher if (!(GetByte(0x10) & 0x01)) 1616*59ffb30fSJeff Kirsher PutByte(0x10, 0x11); /* unmask master-int bit */ 1617*59ffb30fSJeff Kirsher } 1618*59ffb30fSJeff Kirsher 1619*59ffb30fSJeff Kirsher if (full) 1620*59ffb30fSJeff Kirsher netdev_info(dev, "media %s, silicon revision %d\n", 1621*59ffb30fSJeff Kirsher if_names[dev->if_port], local->silicon); 1622*59ffb30fSJeff Kirsher /* We should switch back to page 0 to avoid a bug in revision 0 1623*59ffb30fSJeff Kirsher * where regs with offset below 8 can't be read after an access 1624*59ffb30fSJeff Kirsher * to the MAC registers */ 1625*59ffb30fSJeff Kirsher SelectPage(0); 1626*59ffb30fSJeff Kirsher } 1627*59ffb30fSJeff Kirsher 1628*59ffb30fSJeff Kirsher /**************** 1629*59ffb30fSJeff Kirsher * Initialize the Media-Independent-Interface 1630*59ffb30fSJeff Kirsher * Returns: True if we have a good MII 1631*59ffb30fSJeff Kirsher */ 1632*59ffb30fSJeff Kirsher static int 1633*59ffb30fSJeff Kirsher init_mii(struct net_device *dev) 1634*59ffb30fSJeff Kirsher { 1635*59ffb30fSJeff Kirsher local_info_t *local = netdev_priv(dev); 1636*59ffb30fSJeff Kirsher unsigned int ioaddr = dev->base_addr; 1637*59ffb30fSJeff Kirsher unsigned control, status, linkpartner; 1638*59ffb30fSJeff Kirsher int i; 1639*59ffb30fSJeff Kirsher 1640*59ffb30fSJeff Kirsher if (if_port == 4 || if_port == 1) { /* force 100BaseT or 10BaseT */ 1641*59ffb30fSJeff Kirsher dev->if_port = if_port; 1642*59ffb30fSJeff Kirsher local->probe_port = 0; 1643*59ffb30fSJeff Kirsher return 1; 1644*59ffb30fSJeff Kirsher } 1645*59ffb30fSJeff Kirsher 1646*59ffb30fSJeff Kirsher status = mii_rd(ioaddr, 0, 1); 1647*59ffb30fSJeff Kirsher if ((status & 0xff00) != 0x7800) 1648*59ffb30fSJeff Kirsher return 0; /* No MII */ 1649*59ffb30fSJeff Kirsher 1650*59ffb30fSJeff Kirsher local->new_mii = (mii_rd(ioaddr, 0, 2) != 0xffff); 1651*59ffb30fSJeff Kirsher 1652*59ffb30fSJeff Kirsher if (local->probe_port) 1653*59ffb30fSJeff Kirsher control = 0x1000; /* auto neg */ 1654*59ffb30fSJeff Kirsher else if (dev->if_port == 4) 1655*59ffb30fSJeff Kirsher control = 0x2000; /* no auto neg, 100mbs mode */ 1656*59ffb30fSJeff Kirsher else 1657*59ffb30fSJeff Kirsher control = 0x0000; /* no auto neg, 10mbs mode */ 1658*59ffb30fSJeff Kirsher mii_wr(ioaddr, 0, 0, control, 16); 1659*59ffb30fSJeff Kirsher udelay(100); 1660*59ffb30fSJeff Kirsher control = mii_rd(ioaddr, 0, 0); 1661*59ffb30fSJeff Kirsher 1662*59ffb30fSJeff Kirsher if (control & 0x0400) { 1663*59ffb30fSJeff Kirsher netdev_notice(dev, "can't take PHY out of isolation mode\n"); 1664*59ffb30fSJeff Kirsher local->probe_port = 0; 1665*59ffb30fSJeff Kirsher return 0; 1666*59ffb30fSJeff Kirsher } 1667*59ffb30fSJeff Kirsher 1668*59ffb30fSJeff Kirsher if (local->probe_port) { 1669*59ffb30fSJeff Kirsher /* according to the DP83840A specs the auto negotiation process 1670*59ffb30fSJeff Kirsher * may take up to 3.5 sec, so we use this also for our ML6692 1671*59ffb30fSJeff Kirsher * Fixme: Better to use a timer here! 1672*59ffb30fSJeff Kirsher */ 1673*59ffb30fSJeff Kirsher for (i=0; i < 35; i++) { 1674*59ffb30fSJeff Kirsher msleep(100); /* wait 100 msec */ 1675*59ffb30fSJeff Kirsher status = mii_rd(ioaddr, 0, 1); 1676*59ffb30fSJeff Kirsher if ((status & 0x0020) && (status & 0x0004)) 1677*59ffb30fSJeff Kirsher break; 1678*59ffb30fSJeff Kirsher } 1679*59ffb30fSJeff Kirsher 1680*59ffb30fSJeff Kirsher if (!(status & 0x0020)) { 1681*59ffb30fSJeff Kirsher netdev_info(dev, "autonegotiation failed; using 10mbs\n"); 1682*59ffb30fSJeff Kirsher if (!local->new_mii) { 1683*59ffb30fSJeff Kirsher control = 0x0000; 1684*59ffb30fSJeff Kirsher mii_wr(ioaddr, 0, 0, control, 16); 1685*59ffb30fSJeff Kirsher udelay(100); 1686*59ffb30fSJeff Kirsher SelectPage(0); 1687*59ffb30fSJeff Kirsher dev->if_port = (GetByte(XIRCREG_ESR) & MediaSelect) ? 1 : 2; 1688*59ffb30fSJeff Kirsher } 1689*59ffb30fSJeff Kirsher } else { 1690*59ffb30fSJeff Kirsher linkpartner = mii_rd(ioaddr, 0, 5); 1691*59ffb30fSJeff Kirsher netdev_info(dev, "MII link partner: %04x\n", linkpartner); 1692*59ffb30fSJeff Kirsher if (linkpartner & 0x0080) { 1693*59ffb30fSJeff Kirsher dev->if_port = 4; 1694*59ffb30fSJeff Kirsher } else 1695*59ffb30fSJeff Kirsher dev->if_port = 1; 1696*59ffb30fSJeff Kirsher } 1697*59ffb30fSJeff Kirsher } 1698*59ffb30fSJeff Kirsher 1699*59ffb30fSJeff Kirsher return 1; 1700*59ffb30fSJeff Kirsher } 1701*59ffb30fSJeff Kirsher 1702*59ffb30fSJeff Kirsher static void 1703*59ffb30fSJeff Kirsher do_powerdown(struct net_device *dev) 1704*59ffb30fSJeff Kirsher { 1705*59ffb30fSJeff Kirsher 1706*59ffb30fSJeff Kirsher unsigned int ioaddr = dev->base_addr; 1707*59ffb30fSJeff Kirsher 1708*59ffb30fSJeff Kirsher pr_debug("do_powerdown(%p)\n", dev); 1709*59ffb30fSJeff Kirsher 1710*59ffb30fSJeff Kirsher SelectPage(4); 1711*59ffb30fSJeff Kirsher PutByte(XIRCREG4_GPR1, 0); /* clear bit 0: power down */ 1712*59ffb30fSJeff Kirsher SelectPage(0); 1713*59ffb30fSJeff Kirsher } 1714*59ffb30fSJeff Kirsher 1715*59ffb30fSJeff Kirsher static int 1716*59ffb30fSJeff Kirsher do_stop(struct net_device *dev) 1717*59ffb30fSJeff Kirsher { 1718*59ffb30fSJeff Kirsher unsigned int ioaddr = dev->base_addr; 1719*59ffb30fSJeff Kirsher local_info_t *lp = netdev_priv(dev); 1720*59ffb30fSJeff Kirsher struct pcmcia_device *link = lp->p_dev; 1721*59ffb30fSJeff Kirsher 1722*59ffb30fSJeff Kirsher dev_dbg(&link->dev, "do_stop(%p)\n", dev); 1723*59ffb30fSJeff Kirsher 1724*59ffb30fSJeff Kirsher if (!link) 1725*59ffb30fSJeff Kirsher return -ENODEV; 1726*59ffb30fSJeff Kirsher 1727*59ffb30fSJeff Kirsher netif_stop_queue(dev); 1728*59ffb30fSJeff Kirsher 1729*59ffb30fSJeff Kirsher SelectPage(0); 1730*59ffb30fSJeff Kirsher PutByte(XIRCREG_CR, 0); /* disable interrupts */ 1731*59ffb30fSJeff Kirsher SelectPage(0x01); 1732*59ffb30fSJeff Kirsher PutByte(XIRCREG1_IMR0, 0x00); /* forbid all ints */ 1733*59ffb30fSJeff Kirsher SelectPage(4); 1734*59ffb30fSJeff Kirsher PutByte(XIRCREG4_GPR1, 0); /* clear bit 0: power down */ 1735*59ffb30fSJeff Kirsher SelectPage(0); 1736*59ffb30fSJeff Kirsher 1737*59ffb30fSJeff Kirsher link->open--; 1738*59ffb30fSJeff Kirsher return 0; 1739*59ffb30fSJeff Kirsher } 1740*59ffb30fSJeff Kirsher 1741*59ffb30fSJeff Kirsher static const struct pcmcia_device_id xirc2ps_ids[] = { 1742*59ffb30fSJeff Kirsher PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0089, 0x110a), 1743*59ffb30fSJeff Kirsher PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0138, 0x110a), 1744*59ffb30fSJeff Kirsher PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM28", 0x2e3ee845, 0x0ea978ea), 1745*59ffb30fSJeff Kirsher PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM33", 0x2e3ee845, 0x80609023), 1746*59ffb30fSJeff Kirsher PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM56", 0x2e3ee845, 0xa650c32a), 1747*59ffb30fSJeff Kirsher PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "REM10", 0x2e3ee845, 0x76df1d29), 1748*59ffb30fSJeff Kirsher PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "XEM5600", 0x2e3ee845, 0xf1403719), 1749*59ffb30fSJeff Kirsher PCMCIA_PFC_DEVICE_PROD_ID12(0, "Xircom", "CreditCard Ethernet+Modem II", 0x2e3ee845, 0xeca401bf), 1750*59ffb30fSJeff Kirsher PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x010a), 1751*59ffb30fSJeff Kirsher PCMCIA_DEVICE_PROD_ID13("Toshiba Information Systems", "TPCENET", 0x1b3b94fe, 0xf381c1a2), 1752*59ffb30fSJeff Kirsher PCMCIA_DEVICE_PROD_ID13("Xircom", "CE3-10/100", 0x2e3ee845, 0x0ec0ac37), 1753*59ffb30fSJeff Kirsher PCMCIA_DEVICE_PROD_ID13("Xircom", "PS-CE2-10", 0x2e3ee845, 0x947d9073), 1754*59ffb30fSJeff Kirsher PCMCIA_DEVICE_PROD_ID13("Xircom", "R2E-100BTX", 0x2e3ee845, 0x2464a6e3), 1755*59ffb30fSJeff Kirsher PCMCIA_DEVICE_PROD_ID13("Xircom", "RE-10", 0x2e3ee845, 0x3e08d609), 1756*59ffb30fSJeff Kirsher PCMCIA_DEVICE_PROD_ID13("Xircom", "XE2000", 0x2e3ee845, 0xf7188e46), 1757*59ffb30fSJeff Kirsher PCMCIA_DEVICE_PROD_ID12("Compaq", "Ethernet LAN Card", 0x54f7c49c, 0x9fd2f0a2), 1758*59ffb30fSJeff Kirsher PCMCIA_DEVICE_PROD_ID12("Compaq", "Netelligent 10/100 PC Card", 0x54f7c49c, 0xefe96769), 1759*59ffb30fSJeff Kirsher PCMCIA_DEVICE_PROD_ID12("Intel", "EtherExpress(TM) PRO/100 PC Card Mobile Adapter16", 0x816cc815, 0x174397db), 1760*59ffb30fSJeff Kirsher PCMCIA_DEVICE_PROD_ID12("Toshiba", "10/100 Ethernet PC Card", 0x44a09d9c, 0xb44deecf), 1761*59ffb30fSJeff Kirsher /* also matches CFE-10 cards! */ 1762*59ffb30fSJeff Kirsher /* PCMCIA_DEVICE_MANF_CARD(0x0105, 0x010a), */ 1763*59ffb30fSJeff Kirsher PCMCIA_DEVICE_NULL, 1764*59ffb30fSJeff Kirsher }; 1765*59ffb30fSJeff Kirsher MODULE_DEVICE_TABLE(pcmcia, xirc2ps_ids); 1766*59ffb30fSJeff Kirsher 1767*59ffb30fSJeff Kirsher 1768*59ffb30fSJeff Kirsher static struct pcmcia_driver xirc2ps_cs_driver = { 1769*59ffb30fSJeff Kirsher .owner = THIS_MODULE, 1770*59ffb30fSJeff Kirsher .name = "xirc2ps_cs", 1771*59ffb30fSJeff Kirsher .probe = xirc2ps_probe, 1772*59ffb30fSJeff Kirsher .remove = xirc2ps_detach, 1773*59ffb30fSJeff Kirsher .id_table = xirc2ps_ids, 1774*59ffb30fSJeff Kirsher .suspend = xirc2ps_suspend, 1775*59ffb30fSJeff Kirsher .resume = xirc2ps_resume, 1776*59ffb30fSJeff Kirsher }; 1777*59ffb30fSJeff Kirsher 1778*59ffb30fSJeff Kirsher static int __init 1779*59ffb30fSJeff Kirsher init_xirc2ps_cs(void) 1780*59ffb30fSJeff Kirsher { 1781*59ffb30fSJeff Kirsher return pcmcia_register_driver(&xirc2ps_cs_driver); 1782*59ffb30fSJeff Kirsher } 1783*59ffb30fSJeff Kirsher 1784*59ffb30fSJeff Kirsher static void __exit 1785*59ffb30fSJeff Kirsher exit_xirc2ps_cs(void) 1786*59ffb30fSJeff Kirsher { 1787*59ffb30fSJeff Kirsher pcmcia_unregister_driver(&xirc2ps_cs_driver); 1788*59ffb30fSJeff Kirsher } 1789*59ffb30fSJeff Kirsher 1790*59ffb30fSJeff Kirsher module_init(init_xirc2ps_cs); 1791*59ffb30fSJeff Kirsher module_exit(exit_xirc2ps_cs); 1792*59ffb30fSJeff Kirsher 1793*59ffb30fSJeff Kirsher #ifndef MODULE 1794*59ffb30fSJeff Kirsher static int __init setup_xirc2ps_cs(char *str) 1795*59ffb30fSJeff Kirsher { 1796*59ffb30fSJeff Kirsher /* if_port, full_duplex, do_sound, lockup_hack 1797*59ffb30fSJeff Kirsher */ 1798*59ffb30fSJeff Kirsher int ints[10] = { -1 }; 1799*59ffb30fSJeff Kirsher 1800*59ffb30fSJeff Kirsher str = get_options(str, 9, ints); 1801*59ffb30fSJeff Kirsher 1802*59ffb30fSJeff Kirsher #define MAYBE_SET(X,Y) if (ints[0] >= Y && ints[Y] != -1) { X = ints[Y]; } 1803*59ffb30fSJeff Kirsher MAYBE_SET(if_port, 3); 1804*59ffb30fSJeff Kirsher MAYBE_SET(full_duplex, 4); 1805*59ffb30fSJeff Kirsher MAYBE_SET(do_sound, 5); 1806*59ffb30fSJeff Kirsher MAYBE_SET(lockup_hack, 6); 1807*59ffb30fSJeff Kirsher #undef MAYBE_SET 1808*59ffb30fSJeff Kirsher 1809*59ffb30fSJeff Kirsher return 1; 1810*59ffb30fSJeff Kirsher } 1811*59ffb30fSJeff Kirsher 1812*59ffb30fSJeff Kirsher __setup("xirc2ps_cs=", setup_xirc2ps_cs); 1813*59ffb30fSJeff Kirsher #endif 1814