18c2ecf20Sopenharmony_ci/* [xirc2ps_cs.c wk 03.11.99] (1.40 1999/11/18 00:06:03)
28c2ecf20Sopenharmony_ci * Xircom CreditCard Ethernet Adapter IIps driver
38c2ecf20Sopenharmony_ci * Xircom Realport 10/100 (RE-100) driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * This driver supports various Xircom CreditCard Ethernet adapters
68c2ecf20Sopenharmony_ci * including the CE2, CE IIps, RE-10, CEM28, CEM33, CE33, CEM56,
78c2ecf20Sopenharmony_ci * CE3-100, CE3B, RE-100, REM10BT, and REM56G-100.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * 2000-09-24 <psheer@icon.co.za> The Xircom CE3B-100 may not
108c2ecf20Sopenharmony_ci * autodetect the media properly. In this case use the
118c2ecf20Sopenharmony_ci * if_port=1 (for 10BaseT) or if_port=4 (for 100BaseT) options
128c2ecf20Sopenharmony_ci * to force the media type.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * Written originally by Werner Koch based on David Hinds' skeleton of the
158c2ecf20Sopenharmony_ci * PCMCIA driver.
168c2ecf20Sopenharmony_ci *
178c2ecf20Sopenharmony_ci * Copyright (c) 1997,1998 Werner Koch (dd9jn)
188c2ecf20Sopenharmony_ci *
198c2ecf20Sopenharmony_ci * This driver is free software; you can redistribute it and/or modify
208c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by
218c2ecf20Sopenharmony_ci * the Free Software Foundation; either version 2 of the License, or
228c2ecf20Sopenharmony_ci * (at your option) any later version.
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci * It is distributed in the hope that it will be useful,
258c2ecf20Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
268c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
278c2ecf20Sopenharmony_ci * GNU General Public License for more details.
288c2ecf20Sopenharmony_ci *
298c2ecf20Sopenharmony_ci * You should have received a copy of the GNU General Public License
308c2ecf20Sopenharmony_ci * along with this program; if not, see <http://www.gnu.org/licenses/>.
318c2ecf20Sopenharmony_ci *
328c2ecf20Sopenharmony_ci *
338c2ecf20Sopenharmony_ci * ALTERNATIVELY, this driver may be distributed under the terms of
348c2ecf20Sopenharmony_ci * the following license, in which case the provisions of this license
358c2ecf20Sopenharmony_ci * are required INSTEAD OF the GNU General Public License.  (This clause
368c2ecf20Sopenharmony_ci * is necessary due to a potential bad interaction between the GPL and
378c2ecf20Sopenharmony_ci * the restrictions contained in a BSD-style copyright.)
388c2ecf20Sopenharmony_ci *
398c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
408c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions
418c2ecf20Sopenharmony_ci * are met:
428c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
438c2ecf20Sopenharmony_ci *    notice, and the entire permission notice in its entirety,
448c2ecf20Sopenharmony_ci *    including the disclaimer of warranties.
458c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright
468c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer in the
478c2ecf20Sopenharmony_ci *    documentation and/or other materials provided with the distribution.
488c2ecf20Sopenharmony_ci * 3. The name of the author may not be used to endorse or promote
498c2ecf20Sopenharmony_ci *    products derived from this software without specific prior
508c2ecf20Sopenharmony_ci *    written permission.
518c2ecf20Sopenharmony_ci *
528c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
538c2ecf20Sopenharmony_ci * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
548c2ecf20Sopenharmony_ci * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
558c2ecf20Sopenharmony_ci * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
568c2ecf20Sopenharmony_ci * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
578c2ecf20Sopenharmony_ci * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
588c2ecf20Sopenharmony_ci * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
598c2ecf20Sopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
608c2ecf20Sopenharmony_ci * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
618c2ecf20Sopenharmony_ci * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
628c2ecf20Sopenharmony_ci * OF THE POSSIBILITY OF SUCH DAMAGE.
638c2ecf20Sopenharmony_ci */
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci#include <linux/module.h>
688c2ecf20Sopenharmony_ci#include <linux/kernel.h>
698c2ecf20Sopenharmony_ci#include <linux/init.h>
708c2ecf20Sopenharmony_ci#include <linux/ptrace.h>
718c2ecf20Sopenharmony_ci#include <linux/slab.h>
728c2ecf20Sopenharmony_ci#include <linux/string.h>
738c2ecf20Sopenharmony_ci#include <linux/timer.h>
748c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
758c2ecf20Sopenharmony_ci#include <linux/in.h>
768c2ecf20Sopenharmony_ci#include <linux/delay.h>
778c2ecf20Sopenharmony_ci#include <linux/ethtool.h>
788c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
798c2ecf20Sopenharmony_ci#include <linux/etherdevice.h>
808c2ecf20Sopenharmony_ci#include <linux/skbuff.h>
818c2ecf20Sopenharmony_ci#include <linux/if_arp.h>
828c2ecf20Sopenharmony_ci#include <linux/ioport.h>
838c2ecf20Sopenharmony_ci#include <linux/bitops.h>
848c2ecf20Sopenharmony_ci#include <linux/mii.h>
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci#include <pcmcia/cistpl.h>
878c2ecf20Sopenharmony_ci#include <pcmcia/cisreg.h>
888c2ecf20Sopenharmony_ci#include <pcmcia/ciscode.h>
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci#include <asm/io.h>
918c2ecf20Sopenharmony_ci#include <linux/uaccess.h>
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci#ifndef MANFID_COMPAQ
948c2ecf20Sopenharmony_ci  #define MANFID_COMPAQ 	   0x0138
958c2ecf20Sopenharmony_ci  #define MANFID_COMPAQ2	   0x0183  /* is this correct? */
968c2ecf20Sopenharmony_ci#endif
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci#include <pcmcia/ds.h>
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci/* Time in jiffies before concluding Tx hung */
1018c2ecf20Sopenharmony_ci#define TX_TIMEOUT	((400*HZ)/1000)
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci/****************
1048c2ecf20Sopenharmony_ci * Some constants used to access the hardware
1058c2ecf20Sopenharmony_ci */
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci/* Register offsets and value constans */
1088c2ecf20Sopenharmony_ci#define XIRCREG_CR  0	/* Command register (wr) */
1098c2ecf20Sopenharmony_cienum xirc_cr {
1108c2ecf20Sopenharmony_ci    TransmitPacket = 0x01,
1118c2ecf20Sopenharmony_ci    SoftReset = 0x02,
1128c2ecf20Sopenharmony_ci    EnableIntr = 0x04,
1138c2ecf20Sopenharmony_ci    ForceIntr  = 0x08,
1148c2ecf20Sopenharmony_ci    ClearTxFIFO = 0x10,
1158c2ecf20Sopenharmony_ci    ClearRxOvrun = 0x20,
1168c2ecf20Sopenharmony_ci    RestartTx	 = 0x40
1178c2ecf20Sopenharmony_ci};
1188c2ecf20Sopenharmony_ci#define XIRCREG_ESR 0	/* Ethernet status register (rd) */
1198c2ecf20Sopenharmony_cienum xirc_esr {
1208c2ecf20Sopenharmony_ci    FullPktRcvd = 0x01, /* full packet in receive buffer */
1218c2ecf20Sopenharmony_ci    PktRejected = 0x04, /* a packet has been rejected */
1228c2ecf20Sopenharmony_ci    TxPktPend = 0x08,	/* TX Packet Pending */
1238c2ecf20Sopenharmony_ci    IncorPolarity = 0x10,
1248c2ecf20Sopenharmony_ci    MediaSelect = 0x20	/* set if TP, clear if AUI */
1258c2ecf20Sopenharmony_ci};
1268c2ecf20Sopenharmony_ci#define XIRCREG_PR  1	/* Page Register select */
1278c2ecf20Sopenharmony_ci#define XIRCREG_EDP 4	/* Ethernet Data Port Register */
1288c2ecf20Sopenharmony_ci#define XIRCREG_ISR 6	/* Ethernet Interrupt Status Register */
1298c2ecf20Sopenharmony_cienum xirc_isr {
1308c2ecf20Sopenharmony_ci    TxBufOvr = 0x01,	/* TX Buffer Overflow */
1318c2ecf20Sopenharmony_ci    PktTxed  = 0x02,	/* Packet Transmitted */
1328c2ecf20Sopenharmony_ci    MACIntr  = 0x04,	/* MAC Interrupt occurred */
1338c2ecf20Sopenharmony_ci    TxResGrant = 0x08,	/* Tx Reservation Granted */
1348c2ecf20Sopenharmony_ci    RxFullPkt = 0x20,	/* Rx Full Packet */
1358c2ecf20Sopenharmony_ci    RxPktRej  = 0x40,	/* Rx Packet Rejected */
1368c2ecf20Sopenharmony_ci    ForcedIntr= 0x80	/* Forced Interrupt */
1378c2ecf20Sopenharmony_ci};
1388c2ecf20Sopenharmony_ci#define XIRCREG1_IMR0 12 /* Ethernet Interrupt Mask Register (on page 1)*/
1398c2ecf20Sopenharmony_ci#define XIRCREG1_IMR1 13
1408c2ecf20Sopenharmony_ci#define XIRCREG0_TSO  8  /* Transmit Space Open Register (on page 0)*/
1418c2ecf20Sopenharmony_ci#define XIRCREG0_TRS  10 /* Transmit reservation Size Register (page 0)*/
1428c2ecf20Sopenharmony_ci#define XIRCREG0_DO   12 /* Data Offset Register (page 0) (wr) */
1438c2ecf20Sopenharmony_ci#define XIRCREG0_RSR  12 /* Receive Status Register (page 0) (rd) */
1448c2ecf20Sopenharmony_cienum xirc_rsr {
1458c2ecf20Sopenharmony_ci    PhyPkt = 0x01,	/* set:physical packet, clear: multicast packet */
1468c2ecf20Sopenharmony_ci    BrdcstPkt = 0x02,	/* set if it is a broadcast packet */
1478c2ecf20Sopenharmony_ci    PktTooLong = 0x04,	/* set if packet length > 1518 */
1488c2ecf20Sopenharmony_ci    AlignErr = 0x10,	/* incorrect CRC and last octet not complete */
1498c2ecf20Sopenharmony_ci    CRCErr = 0x20,	/* incorrect CRC and last octet is complete */
1508c2ecf20Sopenharmony_ci    PktRxOk = 0x80	/* received ok */
1518c2ecf20Sopenharmony_ci};
1528c2ecf20Sopenharmony_ci#define XIRCREG0_PTR 13 /* packets transmitted register (rd) */
1538c2ecf20Sopenharmony_ci#define XIRCREG0_RBC 14 /* receive byte count regsister (rd) */
1548c2ecf20Sopenharmony_ci#define XIRCREG1_ECR 14 /* ethernet configurationn register */
1558c2ecf20Sopenharmony_cienum xirc_ecr {
1568c2ecf20Sopenharmony_ci    FullDuplex = 0x04,	/* enable full duplex mode */
1578c2ecf20Sopenharmony_ci    LongTPMode = 0x08,	/* adjust for longer lengths of TP cable */
1588c2ecf20Sopenharmony_ci    DisablePolCor = 0x10,/* disable auto polarity correction */
1598c2ecf20Sopenharmony_ci    DisableLinkPulse = 0x20, /* disable link pulse generation */
1608c2ecf20Sopenharmony_ci    DisableAutoTx = 0x40, /* disable auto-transmit */
1618c2ecf20Sopenharmony_ci};
1628c2ecf20Sopenharmony_ci#define XIRCREG2_RBS 8	/* receive buffer start register */
1638c2ecf20Sopenharmony_ci#define XIRCREG2_LED 10 /* LED Configuration register */
1648c2ecf20Sopenharmony_ci/* values for the leds:    Bits 2-0 for led 1
1658c2ecf20Sopenharmony_ci *  0 disabled		   Bits 5-3 for led 2
1668c2ecf20Sopenharmony_ci *  1 collision
1678c2ecf20Sopenharmony_ci *  2 noncollision
1688c2ecf20Sopenharmony_ci *  3 link_detected
1698c2ecf20Sopenharmony_ci *  4 incor_polarity
1708c2ecf20Sopenharmony_ci *  5 jabber
1718c2ecf20Sopenharmony_ci *  6 auto_assertion
1728c2ecf20Sopenharmony_ci *  7 rx_tx_activity
1738c2ecf20Sopenharmony_ci */
1748c2ecf20Sopenharmony_ci#define XIRCREG2_MSR 12 /* Mohawk specific register */
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci#define XIRCREG4_GPR0 8 /* General Purpose Register 0 */
1778c2ecf20Sopenharmony_ci#define XIRCREG4_GPR1 9 /* General Purpose Register 1 */
1788c2ecf20Sopenharmony_ci#define XIRCREG2_GPR2 13 /* General Purpose Register 2 (page2!)*/
1798c2ecf20Sopenharmony_ci#define XIRCREG4_BOV 10 /* Bonding Version Register */
1808c2ecf20Sopenharmony_ci#define XIRCREG4_LMA 12 /* Local Memory Address Register */
1818c2ecf20Sopenharmony_ci#define XIRCREG4_LMD 14 /* Local Memory Data Port */
1828c2ecf20Sopenharmony_ci/* MAC register can only by accessed with 8 bit operations */
1838c2ecf20Sopenharmony_ci#define XIRCREG40_CMD0 8    /* Command Register (wr) */
1848c2ecf20Sopenharmony_cienum xirc_cmd { 	    /* Commands */
1858c2ecf20Sopenharmony_ci    Transmit = 0x01,
1868c2ecf20Sopenharmony_ci    EnableRecv = 0x04,
1878c2ecf20Sopenharmony_ci    DisableRecv = 0x08,
1888c2ecf20Sopenharmony_ci    Abort = 0x10,
1898c2ecf20Sopenharmony_ci    Online = 0x20,
1908c2ecf20Sopenharmony_ci    IntrAck = 0x40,
1918c2ecf20Sopenharmony_ci    Offline = 0x80
1928c2ecf20Sopenharmony_ci};
1938c2ecf20Sopenharmony_ci#define XIRCREG5_RHSA0	10  /* Rx Host Start Address */
1948c2ecf20Sopenharmony_ci#define XIRCREG40_RXST0 9   /* Receive Status Register */
1958c2ecf20Sopenharmony_ci#define XIRCREG40_TXST0 11  /* Transmit Status Register 0 */
1968c2ecf20Sopenharmony_ci#define XIRCREG40_TXST1 12  /* Transmit Status Register 10 */
1978c2ecf20Sopenharmony_ci#define XIRCREG40_RMASK0 13  /* Receive Mask Register */
1988c2ecf20Sopenharmony_ci#define XIRCREG40_TMASK0 14  /* Transmit Mask Register 0 */
1998c2ecf20Sopenharmony_ci#define XIRCREG40_TMASK1 15  /* Transmit Mask Register 0 */
2008c2ecf20Sopenharmony_ci#define XIRCREG42_SWC0	8   /* Software Configuration 0 */
2018c2ecf20Sopenharmony_ci#define XIRCREG42_SWC1	9   /* Software Configuration 1 */
2028c2ecf20Sopenharmony_ci#define XIRCREG42_BOC	10  /* Back-Off Configuration */
2038c2ecf20Sopenharmony_ci#define XIRCREG44_TDR0	8   /* Time Domain Reflectometry 0 */
2048c2ecf20Sopenharmony_ci#define XIRCREG44_TDR1	9   /* Time Domain Reflectometry 1 */
2058c2ecf20Sopenharmony_ci#define XIRCREG44_RXBC_LO 10 /* Rx Byte Count 0 (rd) */
2068c2ecf20Sopenharmony_ci#define XIRCREG44_RXBC_HI 11 /* Rx Byte Count 1 (rd) */
2078c2ecf20Sopenharmony_ci#define XIRCREG45_REV	 15 /* Revision Register (rd) */
2088c2ecf20Sopenharmony_ci#define XIRCREG50_IA	8   /* Individual Address (8-13) */
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_cistatic const char *if_names[] = { "Auto", "10BaseT", "10Base2", "AUI", "100BaseT" };
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci/* card types */
2138c2ecf20Sopenharmony_ci#define XIR_UNKNOWN  0	/* unknown: not supported */
2148c2ecf20Sopenharmony_ci#define XIR_CE	     1	/* (prodid 1) different hardware: not supported */
2158c2ecf20Sopenharmony_ci#define XIR_CE2      2	/* (prodid 2) */
2168c2ecf20Sopenharmony_ci#define XIR_CE3      3	/* (prodid 3) */
2178c2ecf20Sopenharmony_ci#define XIR_CEM      4	/* (prodid 1) different hardware: not supported */
2188c2ecf20Sopenharmony_ci#define XIR_CEM2     5	/* (prodid 2) */
2198c2ecf20Sopenharmony_ci#define XIR_CEM3     6	/* (prodid 3) */
2208c2ecf20Sopenharmony_ci#define XIR_CEM33    7	/* (prodid 4) */
2218c2ecf20Sopenharmony_ci#define XIR_CEM56M   8	/* (prodid 5) */
2228c2ecf20Sopenharmony_ci#define XIR_CEM56    9	/* (prodid 6) */
2238c2ecf20Sopenharmony_ci#define XIR_CM28    10	/* (prodid 3) modem only: not supported here */
2248c2ecf20Sopenharmony_ci#define XIR_CM33    11	/* (prodid 4) modem only: not supported here */
2258c2ecf20Sopenharmony_ci#define XIR_CM56    12	/* (prodid 5) modem only: not supported here */
2268c2ecf20Sopenharmony_ci#define XIR_CG	    13	/* (prodid 1) GSM modem only: not supported */
2278c2ecf20Sopenharmony_ci#define XIR_CBE     14	/* (prodid 1) cardbus ethernet: not supported */
2288c2ecf20Sopenharmony_ci/*====================================================================*/
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci/* Module parameters */
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Xircom PCMCIA ethernet driver");
2338c2ecf20Sopenharmony_ciMODULE_LICENSE("Dual MPL/GPL");
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ciINT_MODULE_PARM(if_port,	0);
2388c2ecf20Sopenharmony_ciINT_MODULE_PARM(full_duplex,	0);
2398c2ecf20Sopenharmony_ciINT_MODULE_PARM(do_sound, 	1);
2408c2ecf20Sopenharmony_ciINT_MODULE_PARM(lockup_hack,	0);  /* anti lockup hack */
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ci/*====================================================================*/
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci/* We do not process more than these number of bytes during one
2458c2ecf20Sopenharmony_ci * interrupt. (Of course we receive complete packets, so this is not
2468c2ecf20Sopenharmony_ci * an exact value).
2478c2ecf20Sopenharmony_ci * Something between 2000..22000; first value gives best interrupt latency,
2488c2ecf20Sopenharmony_ci * the second enables the usage of the complete on-chip buffer. We use the
2498c2ecf20Sopenharmony_ci * high value as the initial value.
2508c2ecf20Sopenharmony_ci */
2518c2ecf20Sopenharmony_cistatic unsigned maxrx_bytes = 22000;
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci/* MII management prototypes */
2548c2ecf20Sopenharmony_cistatic void mii_idle(unsigned int ioaddr);
2558c2ecf20Sopenharmony_cistatic void mii_putbit(unsigned int ioaddr, unsigned data);
2568c2ecf20Sopenharmony_cistatic int  mii_getbit(unsigned int ioaddr);
2578c2ecf20Sopenharmony_cistatic void mii_wbits(unsigned int ioaddr, unsigned data, int len);
2588c2ecf20Sopenharmony_cistatic unsigned mii_rd(unsigned int ioaddr, u_char phyaddr, u_char phyreg);
2598c2ecf20Sopenharmony_cistatic void mii_wr(unsigned int ioaddr, u_char phyaddr, u_char phyreg,
2608c2ecf20Sopenharmony_ci		   unsigned data, int len);
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_cistatic int has_ce2_string(struct pcmcia_device * link);
2638c2ecf20Sopenharmony_cistatic int xirc2ps_config(struct pcmcia_device * link);
2648c2ecf20Sopenharmony_cistatic void xirc2ps_release(struct pcmcia_device * link);
2658c2ecf20Sopenharmony_cistatic void xirc2ps_detach(struct pcmcia_device *p_dev);
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_cistatic irqreturn_t xirc2ps_interrupt(int irq, void *dev_id);
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_cistruct local_info {
2708c2ecf20Sopenharmony_ci	struct net_device	*dev;
2718c2ecf20Sopenharmony_ci	struct pcmcia_device	*p_dev;
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci    int card_type;
2748c2ecf20Sopenharmony_ci    int probe_port;
2758c2ecf20Sopenharmony_ci    int silicon; /* silicon revision. 0=old CE2, 1=Scipper, 4=Mohawk */
2768c2ecf20Sopenharmony_ci    int mohawk;  /* a CE3 type card */
2778c2ecf20Sopenharmony_ci    int dingo;	 /* a CEM56 type card */
2788c2ecf20Sopenharmony_ci    int new_mii; /* has full 10baseT/100baseT MII */
2798c2ecf20Sopenharmony_ci    int modem;	 /* is a multi function card (i.e with a modem) */
2808c2ecf20Sopenharmony_ci    void __iomem *dingo_ccr; /* only used for CEM56 cards */
2818c2ecf20Sopenharmony_ci    unsigned last_ptr_value; /* last packets transmitted value */
2828c2ecf20Sopenharmony_ci    const char *manf_str;
2838c2ecf20Sopenharmony_ci    struct work_struct tx_timeout_task;
2848c2ecf20Sopenharmony_ci};
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_ci/****************
2878c2ecf20Sopenharmony_ci * Some more prototypes
2888c2ecf20Sopenharmony_ci */
2898c2ecf20Sopenharmony_cistatic netdev_tx_t do_start_xmit(struct sk_buff *skb,
2908c2ecf20Sopenharmony_ci				       struct net_device *dev);
2918c2ecf20Sopenharmony_cistatic void xirc_tx_timeout(struct net_device *dev, unsigned int txqueue);
2928c2ecf20Sopenharmony_cistatic void xirc2ps_tx_timeout_task(struct work_struct *work);
2938c2ecf20Sopenharmony_cistatic void set_addresses(struct net_device *dev);
2948c2ecf20Sopenharmony_cistatic void set_multicast_list(struct net_device *dev);
2958c2ecf20Sopenharmony_cistatic int set_card_type(struct pcmcia_device *link);
2968c2ecf20Sopenharmony_cistatic int do_config(struct net_device *dev, struct ifmap *map);
2978c2ecf20Sopenharmony_cistatic int do_open(struct net_device *dev);
2988c2ecf20Sopenharmony_cistatic int do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
2998c2ecf20Sopenharmony_cistatic const struct ethtool_ops netdev_ethtool_ops;
3008c2ecf20Sopenharmony_cistatic void hardreset(struct net_device *dev);
3018c2ecf20Sopenharmony_cistatic void do_reset(struct net_device *dev, int full);
3028c2ecf20Sopenharmony_cistatic int init_mii(struct net_device *dev);
3038c2ecf20Sopenharmony_cistatic void do_powerdown(struct net_device *dev);
3048c2ecf20Sopenharmony_cistatic int do_stop(struct net_device *dev);
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_ci/*=============== Helper functions =========================*/
3078c2ecf20Sopenharmony_ci#define SelectPage(pgnr)   outb((pgnr), ioaddr + XIRCREG_PR)
3088c2ecf20Sopenharmony_ci#define GetByte(reg)	   ((unsigned)inb(ioaddr + (reg)))
3098c2ecf20Sopenharmony_ci#define GetWord(reg)	   ((unsigned)inw(ioaddr + (reg)))
3108c2ecf20Sopenharmony_ci#define PutByte(reg,value) outb((value), ioaddr+(reg))
3118c2ecf20Sopenharmony_ci#define PutWord(reg,value) outw((value), ioaddr+(reg))
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ci/*====== Functions used for debugging =================================*/
3148c2ecf20Sopenharmony_ci#if 0 /* reading regs may change system status */
3158c2ecf20Sopenharmony_cistatic void
3168c2ecf20Sopenharmony_ciPrintRegisters(struct net_device *dev)
3178c2ecf20Sopenharmony_ci{
3188c2ecf20Sopenharmony_ci    unsigned int ioaddr = dev->base_addr;
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_ci    if (pc_debug > 1) {
3218c2ecf20Sopenharmony_ci	int i, page;
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci	printk(KERN_DEBUG pr_fmt("Register  common: "));
3248c2ecf20Sopenharmony_ci	for (i = 0; i < 8; i++)
3258c2ecf20Sopenharmony_ci	    pr_cont(" %2.2x", GetByte(i));
3268c2ecf20Sopenharmony_ci	pr_cont("\n");
3278c2ecf20Sopenharmony_ci	for (page = 0; page <= 8; page++) {
3288c2ecf20Sopenharmony_ci	    printk(KERN_DEBUG pr_fmt("Register page %2x: "), page);
3298c2ecf20Sopenharmony_ci	    SelectPage(page);
3308c2ecf20Sopenharmony_ci	    for (i = 8; i < 16; i++)
3318c2ecf20Sopenharmony_ci		pr_cont(" %2.2x", GetByte(i));
3328c2ecf20Sopenharmony_ci	    pr_cont("\n");
3338c2ecf20Sopenharmony_ci	}
3348c2ecf20Sopenharmony_ci	for (page=0x40 ; page <= 0x5f; page++) {
3358c2ecf20Sopenharmony_ci		if (page == 0x43 || (page >= 0x46 && page <= 0x4f) ||
3368c2ecf20Sopenharmony_ci		    (page >= 0x51 && page <=0x5e))
3378c2ecf20Sopenharmony_ci			continue;
3388c2ecf20Sopenharmony_ci	    printk(KERN_DEBUG pr_fmt("Register page %2x: "), page);
3398c2ecf20Sopenharmony_ci	    SelectPage(page);
3408c2ecf20Sopenharmony_ci	    for (i = 8; i < 16; i++)
3418c2ecf20Sopenharmony_ci		pr_cont(" %2.2x", GetByte(i));
3428c2ecf20Sopenharmony_ci	    pr_cont("\n");
3438c2ecf20Sopenharmony_ci	}
3448c2ecf20Sopenharmony_ci    }
3458c2ecf20Sopenharmony_ci}
3468c2ecf20Sopenharmony_ci#endif /* 0 */
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ci/*============== MII Management functions ===============*/
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ci/****************
3518c2ecf20Sopenharmony_ci * Turn around for read
3528c2ecf20Sopenharmony_ci */
3538c2ecf20Sopenharmony_cistatic void
3548c2ecf20Sopenharmony_cimii_idle(unsigned int ioaddr)
3558c2ecf20Sopenharmony_ci{
3568c2ecf20Sopenharmony_ci    PutByte(XIRCREG2_GPR2, 0x04|0); /* drive MDCK low */
3578c2ecf20Sopenharmony_ci    udelay(1);
3588c2ecf20Sopenharmony_ci    PutByte(XIRCREG2_GPR2, 0x04|1); /* and drive MDCK high */
3598c2ecf20Sopenharmony_ci    udelay(1);
3608c2ecf20Sopenharmony_ci}
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_ci/****************
3638c2ecf20Sopenharmony_ci * Write a bit to MDI/O
3648c2ecf20Sopenharmony_ci */
3658c2ecf20Sopenharmony_cistatic void
3668c2ecf20Sopenharmony_cimii_putbit(unsigned int ioaddr, unsigned data)
3678c2ecf20Sopenharmony_ci{
3688c2ecf20Sopenharmony_ci  #if 1
3698c2ecf20Sopenharmony_ci    if (data) {
3708c2ecf20Sopenharmony_ci	PutByte(XIRCREG2_GPR2, 0x0c|2|0); /* set MDIO */
3718c2ecf20Sopenharmony_ci	udelay(1);
3728c2ecf20Sopenharmony_ci	PutByte(XIRCREG2_GPR2, 0x0c|2|1); /* and drive MDCK high */
3738c2ecf20Sopenharmony_ci	udelay(1);
3748c2ecf20Sopenharmony_ci    } else {
3758c2ecf20Sopenharmony_ci	PutByte(XIRCREG2_GPR2, 0x0c|0|0); /* clear MDIO */
3768c2ecf20Sopenharmony_ci	udelay(1);
3778c2ecf20Sopenharmony_ci	PutByte(XIRCREG2_GPR2, 0x0c|0|1); /* and drive MDCK high */
3788c2ecf20Sopenharmony_ci	udelay(1);
3798c2ecf20Sopenharmony_ci    }
3808c2ecf20Sopenharmony_ci  #else
3818c2ecf20Sopenharmony_ci    if (data) {
3828c2ecf20Sopenharmony_ci	PutWord(XIRCREG2_GPR2-1, 0x0e0e);
3838c2ecf20Sopenharmony_ci	udelay(1);
3848c2ecf20Sopenharmony_ci	PutWord(XIRCREG2_GPR2-1, 0x0f0f);
3858c2ecf20Sopenharmony_ci	udelay(1);
3868c2ecf20Sopenharmony_ci    } else {
3878c2ecf20Sopenharmony_ci	PutWord(XIRCREG2_GPR2-1, 0x0c0c);
3888c2ecf20Sopenharmony_ci	udelay(1);
3898c2ecf20Sopenharmony_ci	PutWord(XIRCREG2_GPR2-1, 0x0d0d);
3908c2ecf20Sopenharmony_ci	udelay(1);
3918c2ecf20Sopenharmony_ci    }
3928c2ecf20Sopenharmony_ci  #endif
3938c2ecf20Sopenharmony_ci}
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ci/****************
3968c2ecf20Sopenharmony_ci * Get a bit from MDI/O
3978c2ecf20Sopenharmony_ci */
3988c2ecf20Sopenharmony_cistatic int
3998c2ecf20Sopenharmony_cimii_getbit(unsigned int ioaddr)
4008c2ecf20Sopenharmony_ci{
4018c2ecf20Sopenharmony_ci    unsigned d;
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci    PutByte(XIRCREG2_GPR2, 4|0); /* drive MDCK low */
4048c2ecf20Sopenharmony_ci    udelay(1);
4058c2ecf20Sopenharmony_ci    d = GetByte(XIRCREG2_GPR2); /* read MDIO */
4068c2ecf20Sopenharmony_ci    PutByte(XIRCREG2_GPR2, 4|1); /* drive MDCK high again */
4078c2ecf20Sopenharmony_ci    udelay(1);
4088c2ecf20Sopenharmony_ci    return d & 0x20; /* read MDIO */
4098c2ecf20Sopenharmony_ci}
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_cistatic void
4128c2ecf20Sopenharmony_cimii_wbits(unsigned int ioaddr, unsigned data, int len)
4138c2ecf20Sopenharmony_ci{
4148c2ecf20Sopenharmony_ci    unsigned m = 1 << (len-1);
4158c2ecf20Sopenharmony_ci    for (; m; m >>= 1)
4168c2ecf20Sopenharmony_ci	mii_putbit(ioaddr, data & m);
4178c2ecf20Sopenharmony_ci}
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_cistatic unsigned
4208c2ecf20Sopenharmony_cimii_rd(unsigned int ioaddr,	u_char phyaddr, u_char phyreg)
4218c2ecf20Sopenharmony_ci{
4228c2ecf20Sopenharmony_ci    int i;
4238c2ecf20Sopenharmony_ci    unsigned data=0, m;
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_ci    SelectPage(2);
4268c2ecf20Sopenharmony_ci    for (i=0; i < 32; i++)		/* 32 bit preamble */
4278c2ecf20Sopenharmony_ci	mii_putbit(ioaddr, 1);
4288c2ecf20Sopenharmony_ci    mii_wbits(ioaddr, 0x06, 4); 	/* Start and opcode for read */
4298c2ecf20Sopenharmony_ci    mii_wbits(ioaddr, phyaddr, 5);	/* PHY address to be accessed */
4308c2ecf20Sopenharmony_ci    mii_wbits(ioaddr, phyreg, 5);	/* PHY register to read */
4318c2ecf20Sopenharmony_ci    mii_idle(ioaddr);			/* turn around */
4328c2ecf20Sopenharmony_ci    mii_getbit(ioaddr);
4338c2ecf20Sopenharmony_ci
4348c2ecf20Sopenharmony_ci    for (m = 1<<15; m; m >>= 1)
4358c2ecf20Sopenharmony_ci	if (mii_getbit(ioaddr))
4368c2ecf20Sopenharmony_ci	    data |= m;
4378c2ecf20Sopenharmony_ci    mii_idle(ioaddr);
4388c2ecf20Sopenharmony_ci    return data;
4398c2ecf20Sopenharmony_ci}
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_cistatic void
4428c2ecf20Sopenharmony_cimii_wr(unsigned int ioaddr, u_char phyaddr, u_char phyreg, unsigned data,
4438c2ecf20Sopenharmony_ci       int len)
4448c2ecf20Sopenharmony_ci{
4458c2ecf20Sopenharmony_ci    int i;
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ci    SelectPage(2);
4488c2ecf20Sopenharmony_ci    for (i=0; i < 32; i++)		/* 32 bit preamble */
4498c2ecf20Sopenharmony_ci	mii_putbit(ioaddr, 1);
4508c2ecf20Sopenharmony_ci    mii_wbits(ioaddr, 0x05, 4); 	/* Start and opcode for write */
4518c2ecf20Sopenharmony_ci    mii_wbits(ioaddr, phyaddr, 5);	/* PHY address to be accessed */
4528c2ecf20Sopenharmony_ci    mii_wbits(ioaddr, phyreg, 5);	/* PHY Register to write */
4538c2ecf20Sopenharmony_ci    mii_putbit(ioaddr, 1);		/* turn around */
4548c2ecf20Sopenharmony_ci    mii_putbit(ioaddr, 0);
4558c2ecf20Sopenharmony_ci    mii_wbits(ioaddr, data, len);	/* And write the data */
4568c2ecf20Sopenharmony_ci    mii_idle(ioaddr);
4578c2ecf20Sopenharmony_ci}
4588c2ecf20Sopenharmony_ci
4598c2ecf20Sopenharmony_ci/*============= Main bulk of functions	=========================*/
4608c2ecf20Sopenharmony_ci
4618c2ecf20Sopenharmony_cistatic const struct net_device_ops netdev_ops = {
4628c2ecf20Sopenharmony_ci	.ndo_open		= do_open,
4638c2ecf20Sopenharmony_ci	.ndo_stop		= do_stop,
4648c2ecf20Sopenharmony_ci	.ndo_start_xmit		= do_start_xmit,
4658c2ecf20Sopenharmony_ci	.ndo_tx_timeout 	= xirc_tx_timeout,
4668c2ecf20Sopenharmony_ci	.ndo_set_config		= do_config,
4678c2ecf20Sopenharmony_ci	.ndo_do_ioctl		= do_ioctl,
4688c2ecf20Sopenharmony_ci	.ndo_set_rx_mode	= set_multicast_list,
4698c2ecf20Sopenharmony_ci	.ndo_set_mac_address 	= eth_mac_addr,
4708c2ecf20Sopenharmony_ci	.ndo_validate_addr	= eth_validate_addr,
4718c2ecf20Sopenharmony_ci};
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_cistatic int
4748c2ecf20Sopenharmony_cixirc2ps_probe(struct pcmcia_device *link)
4758c2ecf20Sopenharmony_ci{
4768c2ecf20Sopenharmony_ci    struct net_device *dev;
4778c2ecf20Sopenharmony_ci    struct local_info *local;
4788c2ecf20Sopenharmony_ci
4798c2ecf20Sopenharmony_ci    dev_dbg(&link->dev, "attach()\n");
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_ci    /* Allocate the device structure */
4828c2ecf20Sopenharmony_ci    dev = alloc_etherdev(sizeof(struct local_info));
4838c2ecf20Sopenharmony_ci    if (!dev)
4848c2ecf20Sopenharmony_ci	    return -ENOMEM;
4858c2ecf20Sopenharmony_ci    local = netdev_priv(dev);
4868c2ecf20Sopenharmony_ci    local->dev = dev;
4878c2ecf20Sopenharmony_ci    local->p_dev = link;
4888c2ecf20Sopenharmony_ci    link->priv = dev;
4898c2ecf20Sopenharmony_ci
4908c2ecf20Sopenharmony_ci    /* General socket configuration */
4918c2ecf20Sopenharmony_ci    link->config_index = 1;
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_ci    /* Fill in card specific entries */
4948c2ecf20Sopenharmony_ci    dev->netdev_ops = &netdev_ops;
4958c2ecf20Sopenharmony_ci    dev->ethtool_ops = &netdev_ethtool_ops;
4968c2ecf20Sopenharmony_ci    dev->watchdog_timeo = TX_TIMEOUT;
4978c2ecf20Sopenharmony_ci    INIT_WORK(&local->tx_timeout_task, xirc2ps_tx_timeout_task);
4988c2ecf20Sopenharmony_ci
4998c2ecf20Sopenharmony_ci    return xirc2ps_config(link);
5008c2ecf20Sopenharmony_ci} /* xirc2ps_attach */
5018c2ecf20Sopenharmony_ci
5028c2ecf20Sopenharmony_cistatic void
5038c2ecf20Sopenharmony_cixirc2ps_detach(struct pcmcia_device *link)
5048c2ecf20Sopenharmony_ci{
5058c2ecf20Sopenharmony_ci    struct net_device *dev = link->priv;
5068c2ecf20Sopenharmony_ci    struct local_info *local = netdev_priv(dev);
5078c2ecf20Sopenharmony_ci
5088c2ecf20Sopenharmony_ci    netif_carrier_off(dev);
5098c2ecf20Sopenharmony_ci    netif_tx_disable(dev);
5108c2ecf20Sopenharmony_ci    cancel_work_sync(&local->tx_timeout_task);
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_ci    dev_dbg(&link->dev, "detach\n");
5138c2ecf20Sopenharmony_ci
5148c2ecf20Sopenharmony_ci    unregister_netdev(dev);
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ci    xirc2ps_release(link);
5178c2ecf20Sopenharmony_ci
5188c2ecf20Sopenharmony_ci    free_netdev(dev);
5198c2ecf20Sopenharmony_ci} /* xirc2ps_detach */
5208c2ecf20Sopenharmony_ci
5218c2ecf20Sopenharmony_ci/****************
5228c2ecf20Sopenharmony_ci * Detect the type of the card. s is the buffer with the data of tuple 0x20
5238c2ecf20Sopenharmony_ci * Returns: 0 := not supported
5248c2ecf20Sopenharmony_ci *		       mediaid=11 and prodid=47
5258c2ecf20Sopenharmony_ci * Media-Id bits:
5268c2ecf20Sopenharmony_ci *  Ethernet	    0x01
5278c2ecf20Sopenharmony_ci *  Tokenring	    0x02
5288c2ecf20Sopenharmony_ci *  Arcnet	    0x04
5298c2ecf20Sopenharmony_ci *  Wireless	    0x08
5308c2ecf20Sopenharmony_ci *  Modem	    0x10
5318c2ecf20Sopenharmony_ci *  GSM only	    0x20
5328c2ecf20Sopenharmony_ci * Prod-Id bits:
5338c2ecf20Sopenharmony_ci *  Pocket	    0x10
5348c2ecf20Sopenharmony_ci *  External	    0x20
5358c2ecf20Sopenharmony_ci *  Creditcard	    0x40
5368c2ecf20Sopenharmony_ci *  Cardbus	    0x80
5378c2ecf20Sopenharmony_ci *
5388c2ecf20Sopenharmony_ci */
5398c2ecf20Sopenharmony_cistatic int
5408c2ecf20Sopenharmony_ciset_card_type(struct pcmcia_device *link)
5418c2ecf20Sopenharmony_ci{
5428c2ecf20Sopenharmony_ci    struct net_device *dev = link->priv;
5438c2ecf20Sopenharmony_ci    struct local_info *local = netdev_priv(dev);
5448c2ecf20Sopenharmony_ci    u8 *buf;
5458c2ecf20Sopenharmony_ci    unsigned int cisrev, mediaid, prodid;
5468c2ecf20Sopenharmony_ci    size_t len;
5478c2ecf20Sopenharmony_ci
5488c2ecf20Sopenharmony_ci    len = pcmcia_get_tuple(link, CISTPL_MANFID, &buf);
5498c2ecf20Sopenharmony_ci    if (len < 5) {
5508c2ecf20Sopenharmony_ci	    dev_err(&link->dev, "invalid CIS -- sorry\n");
5518c2ecf20Sopenharmony_ci	    return 0;
5528c2ecf20Sopenharmony_ci    }
5538c2ecf20Sopenharmony_ci
5548c2ecf20Sopenharmony_ci    cisrev = buf[2];
5558c2ecf20Sopenharmony_ci    mediaid = buf[3];
5568c2ecf20Sopenharmony_ci    prodid = buf[4];
5578c2ecf20Sopenharmony_ci
5588c2ecf20Sopenharmony_ci    dev_dbg(&link->dev, "cisrev=%02x mediaid=%02x prodid=%02x\n",
5598c2ecf20Sopenharmony_ci	  cisrev, mediaid, prodid);
5608c2ecf20Sopenharmony_ci
5618c2ecf20Sopenharmony_ci    local->mohawk = 0;
5628c2ecf20Sopenharmony_ci    local->dingo = 0;
5638c2ecf20Sopenharmony_ci    local->modem = 0;
5648c2ecf20Sopenharmony_ci    local->card_type = XIR_UNKNOWN;
5658c2ecf20Sopenharmony_ci    if (!(prodid & 0x40)) {
5668c2ecf20Sopenharmony_ci	pr_notice("Oops: Not a creditcard\n");
5678c2ecf20Sopenharmony_ci	return 0;
5688c2ecf20Sopenharmony_ci    }
5698c2ecf20Sopenharmony_ci    if (!(mediaid & 0x01)) {
5708c2ecf20Sopenharmony_ci	pr_notice("Not an Ethernet card\n");
5718c2ecf20Sopenharmony_ci	return 0;
5728c2ecf20Sopenharmony_ci    }
5738c2ecf20Sopenharmony_ci    if (mediaid & 0x10) {
5748c2ecf20Sopenharmony_ci	local->modem = 1;
5758c2ecf20Sopenharmony_ci	switch(prodid & 15) {
5768c2ecf20Sopenharmony_ci	  case 1: local->card_type = XIR_CEM   ; break;
5778c2ecf20Sopenharmony_ci	  case 2: local->card_type = XIR_CEM2  ; break;
5788c2ecf20Sopenharmony_ci	  case 3: local->card_type = XIR_CEM3  ; break;
5798c2ecf20Sopenharmony_ci	  case 4: local->card_type = XIR_CEM33 ; break;
5808c2ecf20Sopenharmony_ci	  case 5: local->card_type = XIR_CEM56M;
5818c2ecf20Sopenharmony_ci		  local->mohawk = 1;
5828c2ecf20Sopenharmony_ci		  break;
5838c2ecf20Sopenharmony_ci	  case 6:
5848c2ecf20Sopenharmony_ci	  case 7: /* 7 is the RealPort 10/56 */
5858c2ecf20Sopenharmony_ci		  local->card_type = XIR_CEM56 ;
5868c2ecf20Sopenharmony_ci		  local->mohawk = 1;
5878c2ecf20Sopenharmony_ci		  local->dingo = 1;
5888c2ecf20Sopenharmony_ci		  break;
5898c2ecf20Sopenharmony_ci	}
5908c2ecf20Sopenharmony_ci    } else {
5918c2ecf20Sopenharmony_ci	switch(prodid & 15) {
5928c2ecf20Sopenharmony_ci	  case 1: local->card_type = has_ce2_string(link)? XIR_CE2 : XIR_CE ;
5938c2ecf20Sopenharmony_ci		  break;
5948c2ecf20Sopenharmony_ci	  case 2: local->card_type = XIR_CE2; break;
5958c2ecf20Sopenharmony_ci	  case 3: local->card_type = XIR_CE3;
5968c2ecf20Sopenharmony_ci		  local->mohawk = 1;
5978c2ecf20Sopenharmony_ci		  break;
5988c2ecf20Sopenharmony_ci	}
5998c2ecf20Sopenharmony_ci    }
6008c2ecf20Sopenharmony_ci    if (local->card_type == XIR_CE || local->card_type == XIR_CEM) {
6018c2ecf20Sopenharmony_ci	pr_notice("Sorry, this is an old CE card\n");
6028c2ecf20Sopenharmony_ci	return 0;
6038c2ecf20Sopenharmony_ci    }
6048c2ecf20Sopenharmony_ci    if (local->card_type == XIR_UNKNOWN)
6058c2ecf20Sopenharmony_ci	pr_notice("unknown card (mediaid=%02x prodid=%02x)\n", mediaid, prodid);
6068c2ecf20Sopenharmony_ci
6078c2ecf20Sopenharmony_ci    return 1;
6088c2ecf20Sopenharmony_ci}
6098c2ecf20Sopenharmony_ci
6108c2ecf20Sopenharmony_ci/****************
6118c2ecf20Sopenharmony_ci * There are some CE2 cards out which claim to be a CE card.
6128c2ecf20Sopenharmony_ci * This function looks for a "CE2" in the 3rd version field.
6138c2ecf20Sopenharmony_ci * Returns: true if this is a CE2
6148c2ecf20Sopenharmony_ci */
6158c2ecf20Sopenharmony_cistatic int
6168c2ecf20Sopenharmony_cihas_ce2_string(struct pcmcia_device * p_dev)
6178c2ecf20Sopenharmony_ci{
6188c2ecf20Sopenharmony_ci	if (p_dev->prod_id[2] && strstr(p_dev->prod_id[2], "CE2"))
6198c2ecf20Sopenharmony_ci		return 1;
6208c2ecf20Sopenharmony_ci	return 0;
6218c2ecf20Sopenharmony_ci}
6228c2ecf20Sopenharmony_ci
6238c2ecf20Sopenharmony_cistatic int
6248c2ecf20Sopenharmony_cixirc2ps_config_modem(struct pcmcia_device *p_dev, void *priv_data)
6258c2ecf20Sopenharmony_ci{
6268c2ecf20Sopenharmony_ci	unsigned int ioaddr;
6278c2ecf20Sopenharmony_ci
6288c2ecf20Sopenharmony_ci	if ((p_dev->resource[0]->start & 0xf) == 8)
6298c2ecf20Sopenharmony_ci		return -ENODEV;
6308c2ecf20Sopenharmony_ci
6318c2ecf20Sopenharmony_ci	p_dev->resource[0]->end = 16;
6328c2ecf20Sopenharmony_ci	p_dev->resource[1]->end = 8;
6338c2ecf20Sopenharmony_ci	p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
6348c2ecf20Sopenharmony_ci	p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
6358c2ecf20Sopenharmony_ci	p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
6368c2ecf20Sopenharmony_ci	p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
6378c2ecf20Sopenharmony_ci	p_dev->io_lines = 10;
6388c2ecf20Sopenharmony_ci
6398c2ecf20Sopenharmony_ci	p_dev->resource[1]->start = p_dev->resource[0]->start;
6408c2ecf20Sopenharmony_ci	for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
6418c2ecf20Sopenharmony_ci		p_dev->resource[0]->start = ioaddr;
6428c2ecf20Sopenharmony_ci		if (!pcmcia_request_io(p_dev))
6438c2ecf20Sopenharmony_ci			return 0;
6448c2ecf20Sopenharmony_ci	}
6458c2ecf20Sopenharmony_ci	return -ENODEV;
6468c2ecf20Sopenharmony_ci}
6478c2ecf20Sopenharmony_ci
6488c2ecf20Sopenharmony_cistatic int
6498c2ecf20Sopenharmony_cixirc2ps_config_check(struct pcmcia_device *p_dev, void *priv_data)
6508c2ecf20Sopenharmony_ci{
6518c2ecf20Sopenharmony_ci	int *pass = priv_data;
6528c2ecf20Sopenharmony_ci	resource_size_t tmp = p_dev->resource[1]->start;
6538c2ecf20Sopenharmony_ci
6548c2ecf20Sopenharmony_ci	tmp += (*pass ? (p_dev->config_index & 0x20 ? -24 : 8)
6558c2ecf20Sopenharmony_ci		: (p_dev->config_index & 0x20 ?   8 : -24));
6568c2ecf20Sopenharmony_ci
6578c2ecf20Sopenharmony_ci	if ((p_dev->resource[0]->start & 0xf) == 8)
6588c2ecf20Sopenharmony_ci		return -ENODEV;
6598c2ecf20Sopenharmony_ci
6608c2ecf20Sopenharmony_ci	p_dev->resource[0]->end = 18;
6618c2ecf20Sopenharmony_ci	p_dev->resource[1]->end = 8;
6628c2ecf20Sopenharmony_ci	p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
6638c2ecf20Sopenharmony_ci	p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
6648c2ecf20Sopenharmony_ci	p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
6658c2ecf20Sopenharmony_ci	p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
6668c2ecf20Sopenharmony_ci	p_dev->io_lines = 10;
6678c2ecf20Sopenharmony_ci
6688c2ecf20Sopenharmony_ci	p_dev->resource[1]->start = p_dev->resource[0]->start;
6698c2ecf20Sopenharmony_ci	p_dev->resource[0]->start = tmp;
6708c2ecf20Sopenharmony_ci	return pcmcia_request_io(p_dev);
6718c2ecf20Sopenharmony_ci}
6728c2ecf20Sopenharmony_ci
6738c2ecf20Sopenharmony_ci
6748c2ecf20Sopenharmony_cistatic int pcmcia_get_mac_ce(struct pcmcia_device *p_dev,
6758c2ecf20Sopenharmony_ci			     tuple_t *tuple,
6768c2ecf20Sopenharmony_ci			     void *priv)
6778c2ecf20Sopenharmony_ci{
6788c2ecf20Sopenharmony_ci	struct net_device *dev = priv;
6798c2ecf20Sopenharmony_ci	int i;
6808c2ecf20Sopenharmony_ci
6818c2ecf20Sopenharmony_ci	if (tuple->TupleDataLen != 13)
6828c2ecf20Sopenharmony_ci		return -EINVAL;
6838c2ecf20Sopenharmony_ci	if ((tuple->TupleData[0] != 2) || (tuple->TupleData[1] != 1) ||
6848c2ecf20Sopenharmony_ci		(tuple->TupleData[2] != 6))
6858c2ecf20Sopenharmony_ci		return -EINVAL;
6868c2ecf20Sopenharmony_ci	/* another try	(James Lehmer's CE2 version 4.1)*/
6878c2ecf20Sopenharmony_ci	for (i = 2; i < 6; i++)
6888c2ecf20Sopenharmony_ci		dev->dev_addr[i] = tuple->TupleData[i+2];
6898c2ecf20Sopenharmony_ci	return 0;
6908c2ecf20Sopenharmony_ci};
6918c2ecf20Sopenharmony_ci
6928c2ecf20Sopenharmony_ci
6938c2ecf20Sopenharmony_cistatic int
6948c2ecf20Sopenharmony_cixirc2ps_config(struct pcmcia_device * link)
6958c2ecf20Sopenharmony_ci{
6968c2ecf20Sopenharmony_ci    struct net_device *dev = link->priv;
6978c2ecf20Sopenharmony_ci    struct local_info *local = netdev_priv(dev);
6988c2ecf20Sopenharmony_ci    unsigned int ioaddr;
6998c2ecf20Sopenharmony_ci    int err;
7008c2ecf20Sopenharmony_ci    u8 *buf;
7018c2ecf20Sopenharmony_ci    size_t len;
7028c2ecf20Sopenharmony_ci
7038c2ecf20Sopenharmony_ci    local->dingo_ccr = NULL;
7048c2ecf20Sopenharmony_ci
7058c2ecf20Sopenharmony_ci    dev_dbg(&link->dev, "config\n");
7068c2ecf20Sopenharmony_ci
7078c2ecf20Sopenharmony_ci    /* Is this a valid	card */
7088c2ecf20Sopenharmony_ci    if (link->has_manf_id == 0) {
7098c2ecf20Sopenharmony_ci	pr_notice("manfid not found in CIS\n");
7108c2ecf20Sopenharmony_ci	goto failure;
7118c2ecf20Sopenharmony_ci    }
7128c2ecf20Sopenharmony_ci
7138c2ecf20Sopenharmony_ci    switch (link->manf_id) {
7148c2ecf20Sopenharmony_ci      case MANFID_XIRCOM:
7158c2ecf20Sopenharmony_ci	local->manf_str = "Xircom";
7168c2ecf20Sopenharmony_ci	break;
7178c2ecf20Sopenharmony_ci      case MANFID_ACCTON:
7188c2ecf20Sopenharmony_ci	local->manf_str = "Accton";
7198c2ecf20Sopenharmony_ci	break;
7208c2ecf20Sopenharmony_ci      case MANFID_COMPAQ:
7218c2ecf20Sopenharmony_ci      case MANFID_COMPAQ2:
7228c2ecf20Sopenharmony_ci	local->manf_str = "Compaq";
7238c2ecf20Sopenharmony_ci	break;
7248c2ecf20Sopenharmony_ci      case MANFID_INTEL:
7258c2ecf20Sopenharmony_ci	local->manf_str = "Intel";
7268c2ecf20Sopenharmony_ci	break;
7278c2ecf20Sopenharmony_ci      case MANFID_TOSHIBA:
7288c2ecf20Sopenharmony_ci	local->manf_str = "Toshiba";
7298c2ecf20Sopenharmony_ci	break;
7308c2ecf20Sopenharmony_ci      default:
7318c2ecf20Sopenharmony_ci	pr_notice("Unknown Card Manufacturer ID: 0x%04x\n",
7328c2ecf20Sopenharmony_ci		  (unsigned)link->manf_id);
7338c2ecf20Sopenharmony_ci	goto failure;
7348c2ecf20Sopenharmony_ci    }
7358c2ecf20Sopenharmony_ci    dev_dbg(&link->dev, "found %s card\n", local->manf_str);
7368c2ecf20Sopenharmony_ci
7378c2ecf20Sopenharmony_ci    if (!set_card_type(link)) {
7388c2ecf20Sopenharmony_ci	pr_notice("this card is not supported\n");
7398c2ecf20Sopenharmony_ci	goto failure;
7408c2ecf20Sopenharmony_ci    }
7418c2ecf20Sopenharmony_ci
7428c2ecf20Sopenharmony_ci    /* get the ethernet address from the CIS */
7438c2ecf20Sopenharmony_ci    err = pcmcia_get_mac_from_cis(link, dev);
7448c2ecf20Sopenharmony_ci
7458c2ecf20Sopenharmony_ci    /* not found: try to get the node-id from tuple 0x89 */
7468c2ecf20Sopenharmony_ci    if (err) {
7478c2ecf20Sopenharmony_ci	    len = pcmcia_get_tuple(link, 0x89, &buf);
7488c2ecf20Sopenharmony_ci	    /* data layout looks like tuple 0x22 */
7498c2ecf20Sopenharmony_ci	    if (buf && len == 8) {
7508c2ecf20Sopenharmony_ci		    if (*buf == CISTPL_FUNCE_LAN_NODE_ID) {
7518c2ecf20Sopenharmony_ci			    int i;
7528c2ecf20Sopenharmony_ci			    for (i = 2; i < 6; i++)
7538c2ecf20Sopenharmony_ci				    dev->dev_addr[i] = buf[i+2];
7548c2ecf20Sopenharmony_ci		    } else
7558c2ecf20Sopenharmony_ci			    err = -1;
7568c2ecf20Sopenharmony_ci	    }
7578c2ecf20Sopenharmony_ci	    kfree(buf);
7588c2ecf20Sopenharmony_ci    }
7598c2ecf20Sopenharmony_ci
7608c2ecf20Sopenharmony_ci    if (err)
7618c2ecf20Sopenharmony_ci	err = pcmcia_loop_tuple(link, CISTPL_FUNCE, pcmcia_get_mac_ce, dev);
7628c2ecf20Sopenharmony_ci
7638c2ecf20Sopenharmony_ci    if (err) {
7648c2ecf20Sopenharmony_ci	pr_notice("node-id not found in CIS\n");
7658c2ecf20Sopenharmony_ci	goto failure;
7668c2ecf20Sopenharmony_ci    }
7678c2ecf20Sopenharmony_ci
7688c2ecf20Sopenharmony_ci    if (local->modem) {
7698c2ecf20Sopenharmony_ci	int pass;
7708c2ecf20Sopenharmony_ci	link->config_flags |= CONF_AUTO_SET_IO;
7718c2ecf20Sopenharmony_ci
7728c2ecf20Sopenharmony_ci	if (local->dingo) {
7738c2ecf20Sopenharmony_ci	    /* Take the Modem IO port from the CIS and scan for a free
7748c2ecf20Sopenharmony_ci	     * Ethernet port */
7758c2ecf20Sopenharmony_ci	    if (!pcmcia_loop_config(link, xirc2ps_config_modem, NULL))
7768c2ecf20Sopenharmony_ci		    goto port_found;
7778c2ecf20Sopenharmony_ci	} else {
7788c2ecf20Sopenharmony_ci	    /* We do 2 passes here: The first one uses the regular mapping and
7798c2ecf20Sopenharmony_ci	     * the second tries again, thereby considering that the 32 ports are
7808c2ecf20Sopenharmony_ci	     * mirrored every 32 bytes. Actually we use a mirrored port for
7818c2ecf20Sopenharmony_ci	     * the Mako if (on the first pass) the COR bit 5 is set.
7828c2ecf20Sopenharmony_ci	     */
7838c2ecf20Sopenharmony_ci	    for (pass=0; pass < 2; pass++)
7848c2ecf20Sopenharmony_ci		    if (!pcmcia_loop_config(link, xirc2ps_config_check,
7858c2ecf20Sopenharmony_ci						    &pass))
7868c2ecf20Sopenharmony_ci			    goto port_found;
7878c2ecf20Sopenharmony_ci	    /* if special option:
7888c2ecf20Sopenharmony_ci	     * try to configure as Ethernet only.
7898c2ecf20Sopenharmony_ci	     * .... */
7908c2ecf20Sopenharmony_ci	}
7918c2ecf20Sopenharmony_ci	pr_notice("no ports available\n");
7928c2ecf20Sopenharmony_ci    } else {
7938c2ecf20Sopenharmony_ci	link->io_lines = 10;
7948c2ecf20Sopenharmony_ci	link->resource[0]->end = 16;
7958c2ecf20Sopenharmony_ci	link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
7968c2ecf20Sopenharmony_ci	for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
7978c2ecf20Sopenharmony_ci	    link->resource[0]->start = ioaddr;
7988c2ecf20Sopenharmony_ci	    if (!(err = pcmcia_request_io(link)))
7998c2ecf20Sopenharmony_ci		goto port_found;
8008c2ecf20Sopenharmony_ci	}
8018c2ecf20Sopenharmony_ci	link->resource[0]->start = 0; /* let CS decide */
8028c2ecf20Sopenharmony_ci	if ((err = pcmcia_request_io(link)))
8038c2ecf20Sopenharmony_ci	    goto config_error;
8048c2ecf20Sopenharmony_ci    }
8058c2ecf20Sopenharmony_ci  port_found:
8068c2ecf20Sopenharmony_ci    if (err)
8078c2ecf20Sopenharmony_ci	 goto config_error;
8088c2ecf20Sopenharmony_ci
8098c2ecf20Sopenharmony_ci    /****************
8108c2ecf20Sopenharmony_ci     * Now allocate an interrupt line.	Note that this does not
8118c2ecf20Sopenharmony_ci     * actually assign a handler to the interrupt.
8128c2ecf20Sopenharmony_ci     */
8138c2ecf20Sopenharmony_ci    if ((err=pcmcia_request_irq(link, xirc2ps_interrupt)))
8148c2ecf20Sopenharmony_ci	goto config_error;
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_ci    link->config_flags |= CONF_ENABLE_IRQ;
8178c2ecf20Sopenharmony_ci    if (do_sound)
8188c2ecf20Sopenharmony_ci	    link->config_flags |= CONF_ENABLE_SPKR;
8198c2ecf20Sopenharmony_ci
8208c2ecf20Sopenharmony_ci    if ((err = pcmcia_enable_device(link)))
8218c2ecf20Sopenharmony_ci	goto config_error;
8228c2ecf20Sopenharmony_ci
8238c2ecf20Sopenharmony_ci    if (local->dingo) {
8248c2ecf20Sopenharmony_ci	/* Reset the modem's BAR to the correct value
8258c2ecf20Sopenharmony_ci	 * This is necessary because in the RequestConfiguration call,
8268c2ecf20Sopenharmony_ci	 * the base address of the ethernet port (BasePort1) is written
8278c2ecf20Sopenharmony_ci	 * to the BAR registers of the modem.
8288c2ecf20Sopenharmony_ci	 */
8298c2ecf20Sopenharmony_ci	err = pcmcia_write_config_byte(link, CISREG_IOBASE_0, (u8)
8308c2ecf20Sopenharmony_ci				link->resource[1]->start & 0xff);
8318c2ecf20Sopenharmony_ci	if (err)
8328c2ecf20Sopenharmony_ci	    goto config_error;
8338c2ecf20Sopenharmony_ci
8348c2ecf20Sopenharmony_ci	err = pcmcia_write_config_byte(link, CISREG_IOBASE_1,
8358c2ecf20Sopenharmony_ci				(link->resource[1]->start >> 8) & 0xff);
8368c2ecf20Sopenharmony_ci	if (err)
8378c2ecf20Sopenharmony_ci	    goto config_error;
8388c2ecf20Sopenharmony_ci
8398c2ecf20Sopenharmony_ci	/* There is no config entry for the Ethernet part which
8408c2ecf20Sopenharmony_ci	 * is at 0x0800. So we allocate a window into the attribute
8418c2ecf20Sopenharmony_ci	 * memory and write direct to the CIS registers
8428c2ecf20Sopenharmony_ci	 */
8438c2ecf20Sopenharmony_ci	link->resource[2]->flags = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM |
8448c2ecf20Sopenharmony_ci					WIN_ENABLE;
8458c2ecf20Sopenharmony_ci	link->resource[2]->start = link->resource[2]->end = 0;
8468c2ecf20Sopenharmony_ci	if ((err = pcmcia_request_window(link, link->resource[2], 0)))
8478c2ecf20Sopenharmony_ci	    goto config_error;
8488c2ecf20Sopenharmony_ci
8498c2ecf20Sopenharmony_ci	local->dingo_ccr = ioremap(link->resource[2]->start, 0x1000) + 0x0800;
8508c2ecf20Sopenharmony_ci	if ((err = pcmcia_map_mem_page(link, link->resource[2], 0)))
8518c2ecf20Sopenharmony_ci	    goto config_error;
8528c2ecf20Sopenharmony_ci
8538c2ecf20Sopenharmony_ci	/* Setup the CCRs; there are no infos in the CIS about the Ethernet
8548c2ecf20Sopenharmony_ci	 * part.
8558c2ecf20Sopenharmony_ci	 */
8568c2ecf20Sopenharmony_ci	writeb(0x47, local->dingo_ccr + CISREG_COR);
8578c2ecf20Sopenharmony_ci	ioaddr = link->resource[0]->start;
8588c2ecf20Sopenharmony_ci	writeb(ioaddr & 0xff	  , local->dingo_ccr + CISREG_IOBASE_0);
8598c2ecf20Sopenharmony_ci	writeb((ioaddr >> 8)&0xff , local->dingo_ccr + CISREG_IOBASE_1);
8608c2ecf20Sopenharmony_ci
8618c2ecf20Sopenharmony_ci      #if 0
8628c2ecf20Sopenharmony_ci	{
8638c2ecf20Sopenharmony_ci	    u_char tmp;
8648c2ecf20Sopenharmony_ci	    pr_info("ECOR:");
8658c2ecf20Sopenharmony_ci	    for (i=0; i < 7; i++) {
8668c2ecf20Sopenharmony_ci		tmp = readb(local->dingo_ccr + i*2);
8678c2ecf20Sopenharmony_ci		pr_cont(" %02x", tmp);
8688c2ecf20Sopenharmony_ci	    }
8698c2ecf20Sopenharmony_ci	    pr_cont("\n");
8708c2ecf20Sopenharmony_ci	    pr_info("DCOR:");
8718c2ecf20Sopenharmony_ci	    for (i=0; i < 4; i++) {
8728c2ecf20Sopenharmony_ci		tmp = readb(local->dingo_ccr + 0x20 + i*2);
8738c2ecf20Sopenharmony_ci		pr_cont(" %02x", tmp);
8748c2ecf20Sopenharmony_ci	    }
8758c2ecf20Sopenharmony_ci	    pr_cont("\n");
8768c2ecf20Sopenharmony_ci	    pr_info("SCOR:");
8778c2ecf20Sopenharmony_ci	    for (i=0; i < 10; i++) {
8788c2ecf20Sopenharmony_ci		tmp = readb(local->dingo_ccr + 0x40 + i*2);
8798c2ecf20Sopenharmony_ci		pr_cont(" %02x", tmp);
8808c2ecf20Sopenharmony_ci	    }
8818c2ecf20Sopenharmony_ci	    pr_cont("\n");
8828c2ecf20Sopenharmony_ci	}
8838c2ecf20Sopenharmony_ci      #endif
8848c2ecf20Sopenharmony_ci
8858c2ecf20Sopenharmony_ci	writeb(0x01, local->dingo_ccr + 0x20);
8868c2ecf20Sopenharmony_ci	writeb(0x0c, local->dingo_ccr + 0x22);
8878c2ecf20Sopenharmony_ci	writeb(0x00, local->dingo_ccr + 0x24);
8888c2ecf20Sopenharmony_ci	writeb(0x00, local->dingo_ccr + 0x26);
8898c2ecf20Sopenharmony_ci	writeb(0x00, local->dingo_ccr + 0x28);
8908c2ecf20Sopenharmony_ci    }
8918c2ecf20Sopenharmony_ci
8928c2ecf20Sopenharmony_ci    /* The if_port symbol can be set when the module is loaded */
8938c2ecf20Sopenharmony_ci    local->probe_port=0;
8948c2ecf20Sopenharmony_ci    if (!if_port) {
8958c2ecf20Sopenharmony_ci	local->probe_port = dev->if_port = 1;
8968c2ecf20Sopenharmony_ci    } else if ((if_port >= 1 && if_port <= 2) ||
8978c2ecf20Sopenharmony_ci	       (local->mohawk && if_port==4))
8988c2ecf20Sopenharmony_ci	dev->if_port = if_port;
8998c2ecf20Sopenharmony_ci    else
9008c2ecf20Sopenharmony_ci	pr_notice("invalid if_port requested\n");
9018c2ecf20Sopenharmony_ci
9028c2ecf20Sopenharmony_ci    /* we can now register the device with the net subsystem */
9038c2ecf20Sopenharmony_ci    dev->irq = link->irq;
9048c2ecf20Sopenharmony_ci    dev->base_addr = link->resource[0]->start;
9058c2ecf20Sopenharmony_ci
9068c2ecf20Sopenharmony_ci    if (local->dingo)
9078c2ecf20Sopenharmony_ci	do_reset(dev, 1); /* a kludge to make the cem56 work */
9088c2ecf20Sopenharmony_ci
9098c2ecf20Sopenharmony_ci    SET_NETDEV_DEV(dev, &link->dev);
9108c2ecf20Sopenharmony_ci
9118c2ecf20Sopenharmony_ci    if ((err=register_netdev(dev))) {
9128c2ecf20Sopenharmony_ci	pr_notice("register_netdev() failed\n");
9138c2ecf20Sopenharmony_ci	goto config_error;
9148c2ecf20Sopenharmony_ci    }
9158c2ecf20Sopenharmony_ci
9168c2ecf20Sopenharmony_ci    /* give some infos about the hardware */
9178c2ecf20Sopenharmony_ci    netdev_info(dev, "%s: port %#3lx, irq %d, hwaddr %pM\n",
9188c2ecf20Sopenharmony_ci		local->manf_str, (u_long)dev->base_addr, (int)dev->irq,
9198c2ecf20Sopenharmony_ci		dev->dev_addr);
9208c2ecf20Sopenharmony_ci
9218c2ecf20Sopenharmony_ci    return 0;
9228c2ecf20Sopenharmony_ci
9238c2ecf20Sopenharmony_ci  config_error:
9248c2ecf20Sopenharmony_ci    xirc2ps_release(link);
9258c2ecf20Sopenharmony_ci    return -ENODEV;
9268c2ecf20Sopenharmony_ci
9278c2ecf20Sopenharmony_ci  failure:
9288c2ecf20Sopenharmony_ci    return -ENODEV;
9298c2ecf20Sopenharmony_ci} /* xirc2ps_config */
9308c2ecf20Sopenharmony_ci
9318c2ecf20Sopenharmony_cistatic void
9328c2ecf20Sopenharmony_cixirc2ps_release(struct pcmcia_device *link)
9338c2ecf20Sopenharmony_ci{
9348c2ecf20Sopenharmony_ci	dev_dbg(&link->dev, "release\n");
9358c2ecf20Sopenharmony_ci
9368c2ecf20Sopenharmony_ci	if (link->resource[2]->end) {
9378c2ecf20Sopenharmony_ci		struct net_device *dev = link->priv;
9388c2ecf20Sopenharmony_ci		struct local_info *local = netdev_priv(dev);
9398c2ecf20Sopenharmony_ci		if (local->dingo)
9408c2ecf20Sopenharmony_ci			iounmap(local->dingo_ccr - 0x0800);
9418c2ecf20Sopenharmony_ci	}
9428c2ecf20Sopenharmony_ci	pcmcia_disable_device(link);
9438c2ecf20Sopenharmony_ci} /* xirc2ps_release */
9448c2ecf20Sopenharmony_ci
9458c2ecf20Sopenharmony_ci/*====================================================================*/
9468c2ecf20Sopenharmony_ci
9478c2ecf20Sopenharmony_ci
9488c2ecf20Sopenharmony_cistatic int xirc2ps_suspend(struct pcmcia_device *link)
9498c2ecf20Sopenharmony_ci{
9508c2ecf20Sopenharmony_ci	struct net_device *dev = link->priv;
9518c2ecf20Sopenharmony_ci
9528c2ecf20Sopenharmony_ci	if (link->open) {
9538c2ecf20Sopenharmony_ci		netif_device_detach(dev);
9548c2ecf20Sopenharmony_ci		do_powerdown(dev);
9558c2ecf20Sopenharmony_ci	}
9568c2ecf20Sopenharmony_ci
9578c2ecf20Sopenharmony_ci	return 0;
9588c2ecf20Sopenharmony_ci}
9598c2ecf20Sopenharmony_ci
9608c2ecf20Sopenharmony_cistatic int xirc2ps_resume(struct pcmcia_device *link)
9618c2ecf20Sopenharmony_ci{
9628c2ecf20Sopenharmony_ci	struct net_device *dev = link->priv;
9638c2ecf20Sopenharmony_ci
9648c2ecf20Sopenharmony_ci	if (link->open) {
9658c2ecf20Sopenharmony_ci		do_reset(dev,1);
9668c2ecf20Sopenharmony_ci		netif_device_attach(dev);
9678c2ecf20Sopenharmony_ci	}
9688c2ecf20Sopenharmony_ci
9698c2ecf20Sopenharmony_ci	return 0;
9708c2ecf20Sopenharmony_ci}
9718c2ecf20Sopenharmony_ci
9728c2ecf20Sopenharmony_ci
9738c2ecf20Sopenharmony_ci/*====================================================================*/
9748c2ecf20Sopenharmony_ci
9758c2ecf20Sopenharmony_ci/****************
9768c2ecf20Sopenharmony_ci * This is the Interrupt service route.
9778c2ecf20Sopenharmony_ci */
9788c2ecf20Sopenharmony_cistatic irqreturn_t
9798c2ecf20Sopenharmony_cixirc2ps_interrupt(int irq, void *dev_id)
9808c2ecf20Sopenharmony_ci{
9818c2ecf20Sopenharmony_ci    struct net_device *dev = (struct net_device *)dev_id;
9828c2ecf20Sopenharmony_ci    struct local_info *lp = netdev_priv(dev);
9838c2ecf20Sopenharmony_ci    unsigned int ioaddr;
9848c2ecf20Sopenharmony_ci    u_char saved_page;
9858c2ecf20Sopenharmony_ci    unsigned bytes_rcvd;
9868c2ecf20Sopenharmony_ci    unsigned int_status, eth_status, rx_status, tx_status;
9878c2ecf20Sopenharmony_ci    unsigned rsr, pktlen;
9888c2ecf20Sopenharmony_ci    ulong start_ticks = jiffies; /* fixme: jiffies rollover every 497 days
9898c2ecf20Sopenharmony_ci				  * is this something to worry about?
9908c2ecf20Sopenharmony_ci				  * -- on a laptop?
9918c2ecf20Sopenharmony_ci				  */
9928c2ecf20Sopenharmony_ci
9938c2ecf20Sopenharmony_ci    if (!netif_device_present(dev))
9948c2ecf20Sopenharmony_ci	return IRQ_HANDLED;
9958c2ecf20Sopenharmony_ci
9968c2ecf20Sopenharmony_ci    ioaddr = dev->base_addr;
9978c2ecf20Sopenharmony_ci    if (lp->mohawk) { /* must disable the interrupt */
9988c2ecf20Sopenharmony_ci	PutByte(XIRCREG_CR, 0);
9998c2ecf20Sopenharmony_ci    }
10008c2ecf20Sopenharmony_ci
10018c2ecf20Sopenharmony_ci    pr_debug("%s: interrupt %d at %#x.\n", dev->name, irq, ioaddr);
10028c2ecf20Sopenharmony_ci
10038c2ecf20Sopenharmony_ci    saved_page = GetByte(XIRCREG_PR);
10048c2ecf20Sopenharmony_ci    /* Read the ISR to see whats the cause for the interrupt.
10058c2ecf20Sopenharmony_ci     * This also clears the interrupt flags on CE2 cards
10068c2ecf20Sopenharmony_ci     */
10078c2ecf20Sopenharmony_ci    int_status = GetByte(XIRCREG_ISR);
10088c2ecf20Sopenharmony_ci    bytes_rcvd = 0;
10098c2ecf20Sopenharmony_ci  loop_entry:
10108c2ecf20Sopenharmony_ci    if (int_status == 0xff) { /* card may be ejected */
10118c2ecf20Sopenharmony_ci	pr_debug("%s: interrupt %d for dead card\n", dev->name, irq);
10128c2ecf20Sopenharmony_ci	goto leave;
10138c2ecf20Sopenharmony_ci    }
10148c2ecf20Sopenharmony_ci    eth_status = GetByte(XIRCREG_ESR);
10158c2ecf20Sopenharmony_ci
10168c2ecf20Sopenharmony_ci    SelectPage(0x40);
10178c2ecf20Sopenharmony_ci    rx_status  = GetByte(XIRCREG40_RXST0);
10188c2ecf20Sopenharmony_ci    PutByte(XIRCREG40_RXST0, (~rx_status & 0xff));
10198c2ecf20Sopenharmony_ci    tx_status = GetByte(XIRCREG40_TXST0);
10208c2ecf20Sopenharmony_ci    tx_status |= GetByte(XIRCREG40_TXST1) << 8;
10218c2ecf20Sopenharmony_ci    PutByte(XIRCREG40_TXST0, 0);
10228c2ecf20Sopenharmony_ci    PutByte(XIRCREG40_TXST1, 0);
10238c2ecf20Sopenharmony_ci
10248c2ecf20Sopenharmony_ci    pr_debug("%s: ISR=%#2.2x ESR=%#2.2x RSR=%#2.2x TSR=%#4.4x\n",
10258c2ecf20Sopenharmony_ci	  dev->name, int_status, eth_status, rx_status, tx_status);
10268c2ecf20Sopenharmony_ci
10278c2ecf20Sopenharmony_ci    /***** receive section ******/
10288c2ecf20Sopenharmony_ci    SelectPage(0);
10298c2ecf20Sopenharmony_ci    while (eth_status & FullPktRcvd) {
10308c2ecf20Sopenharmony_ci	rsr = GetByte(XIRCREG0_RSR);
10318c2ecf20Sopenharmony_ci	if (bytes_rcvd > maxrx_bytes && (rsr & PktRxOk)) {
10328c2ecf20Sopenharmony_ci	    /* too many bytes received during this int, drop the rest of the
10338c2ecf20Sopenharmony_ci	     * packets */
10348c2ecf20Sopenharmony_ci	    dev->stats.rx_dropped++;
10358c2ecf20Sopenharmony_ci	    pr_debug("%s: RX drop, too much done\n", dev->name);
10368c2ecf20Sopenharmony_ci	} else if (rsr & PktRxOk) {
10378c2ecf20Sopenharmony_ci	    struct sk_buff *skb;
10388c2ecf20Sopenharmony_ci
10398c2ecf20Sopenharmony_ci	    pktlen = GetWord(XIRCREG0_RBC);
10408c2ecf20Sopenharmony_ci	    bytes_rcvd += pktlen;
10418c2ecf20Sopenharmony_ci
10428c2ecf20Sopenharmony_ci	    pr_debug("rsr=%#02x packet_length=%u\n", rsr, pktlen);
10438c2ecf20Sopenharmony_ci
10448c2ecf20Sopenharmony_ci	    /* 1 extra so we can use insw */
10458c2ecf20Sopenharmony_ci	    skb = netdev_alloc_skb(dev, pktlen + 3);
10468c2ecf20Sopenharmony_ci	    if (!skb) {
10478c2ecf20Sopenharmony_ci		dev->stats.rx_dropped++;
10488c2ecf20Sopenharmony_ci	    } else { /* okay get the packet */
10498c2ecf20Sopenharmony_ci		skb_reserve(skb, 2);
10508c2ecf20Sopenharmony_ci		if (lp->silicon == 0 ) { /* work around a hardware bug */
10518c2ecf20Sopenharmony_ci		    unsigned rhsa; /* receive start address */
10528c2ecf20Sopenharmony_ci
10538c2ecf20Sopenharmony_ci		    SelectPage(5);
10548c2ecf20Sopenharmony_ci		    rhsa = GetWord(XIRCREG5_RHSA0);
10558c2ecf20Sopenharmony_ci		    SelectPage(0);
10568c2ecf20Sopenharmony_ci		    rhsa += 3; /* skip control infos */
10578c2ecf20Sopenharmony_ci		    if (rhsa >= 0x8000)
10588c2ecf20Sopenharmony_ci			rhsa = 0;
10598c2ecf20Sopenharmony_ci		    if (rhsa + pktlen > 0x8000) {
10608c2ecf20Sopenharmony_ci			unsigned i;
10618c2ecf20Sopenharmony_ci			u_char *buf = skb_put(skb, pktlen);
10628c2ecf20Sopenharmony_ci			for (i=0; i < pktlen ; i++, rhsa++) {
10638c2ecf20Sopenharmony_ci			    buf[i] = GetByte(XIRCREG_EDP);
10648c2ecf20Sopenharmony_ci			    if (rhsa == 0x8000) {
10658c2ecf20Sopenharmony_ci				rhsa = 0;
10668c2ecf20Sopenharmony_ci				i--;
10678c2ecf20Sopenharmony_ci			    }
10688c2ecf20Sopenharmony_ci			}
10698c2ecf20Sopenharmony_ci		    } else {
10708c2ecf20Sopenharmony_ci			insw(ioaddr+XIRCREG_EDP,
10718c2ecf20Sopenharmony_ci				skb_put(skb, pktlen), (pktlen+1)>>1);
10728c2ecf20Sopenharmony_ci		    }
10738c2ecf20Sopenharmony_ci		}
10748c2ecf20Sopenharmony_ci	      #if 0
10758c2ecf20Sopenharmony_ci		else if (lp->mohawk) {
10768c2ecf20Sopenharmony_ci		    /* To use this 32 bit access we should use
10778c2ecf20Sopenharmony_ci		     * a manual optimized loop
10788c2ecf20Sopenharmony_ci		     * Also the words are swapped, we can get more
10798c2ecf20Sopenharmony_ci		     * performance by using 32 bit access and swapping
10808c2ecf20Sopenharmony_ci		     * the words in a register. Will need this for cardbus
10818c2ecf20Sopenharmony_ci		     *
10828c2ecf20Sopenharmony_ci		     * Note: don't forget to change the ALLOC_SKB to .. +3
10838c2ecf20Sopenharmony_ci		     */
10848c2ecf20Sopenharmony_ci		    unsigned i;
10858c2ecf20Sopenharmony_ci		    u_long *p = skb_put(skb, pktlen);
10868c2ecf20Sopenharmony_ci		    register u_long a;
10878c2ecf20Sopenharmony_ci		    unsigned int edpreg = ioaddr+XIRCREG_EDP-2;
10888c2ecf20Sopenharmony_ci		    for (i=0; i < len ; i += 4, p++) {
10898c2ecf20Sopenharmony_ci			a = inl(edpreg);
10908c2ecf20Sopenharmony_ci			__asm__("rorl $16,%0\n\t"
10918c2ecf20Sopenharmony_ci				:"=q" (a)
10928c2ecf20Sopenharmony_ci				: "0" (a));
10938c2ecf20Sopenharmony_ci			*p = a;
10948c2ecf20Sopenharmony_ci		    }
10958c2ecf20Sopenharmony_ci		}
10968c2ecf20Sopenharmony_ci	      #endif
10978c2ecf20Sopenharmony_ci		else {
10988c2ecf20Sopenharmony_ci		    insw(ioaddr+XIRCREG_EDP, skb_put(skb, pktlen),
10998c2ecf20Sopenharmony_ci			    (pktlen+1)>>1);
11008c2ecf20Sopenharmony_ci		}
11018c2ecf20Sopenharmony_ci		skb->protocol = eth_type_trans(skb, dev);
11028c2ecf20Sopenharmony_ci		netif_rx(skb);
11038c2ecf20Sopenharmony_ci		dev->stats.rx_packets++;
11048c2ecf20Sopenharmony_ci		dev->stats.rx_bytes += pktlen;
11058c2ecf20Sopenharmony_ci		if (!(rsr & PhyPkt))
11068c2ecf20Sopenharmony_ci		    dev->stats.multicast++;
11078c2ecf20Sopenharmony_ci	    }
11088c2ecf20Sopenharmony_ci	} else { /* bad packet */
11098c2ecf20Sopenharmony_ci	    pr_debug("rsr=%#02x\n", rsr);
11108c2ecf20Sopenharmony_ci	}
11118c2ecf20Sopenharmony_ci	if (rsr & PktTooLong) {
11128c2ecf20Sopenharmony_ci	    dev->stats.rx_frame_errors++;
11138c2ecf20Sopenharmony_ci	    pr_debug("%s: Packet too long\n", dev->name);
11148c2ecf20Sopenharmony_ci	}
11158c2ecf20Sopenharmony_ci	if (rsr & CRCErr) {
11168c2ecf20Sopenharmony_ci	    dev->stats.rx_crc_errors++;
11178c2ecf20Sopenharmony_ci	    pr_debug("%s: CRC error\n", dev->name);
11188c2ecf20Sopenharmony_ci	}
11198c2ecf20Sopenharmony_ci	if (rsr & AlignErr) {
11208c2ecf20Sopenharmony_ci	    dev->stats.rx_fifo_errors++; /* okay ? */
11218c2ecf20Sopenharmony_ci	    pr_debug("%s: Alignment error\n", dev->name);
11228c2ecf20Sopenharmony_ci	}
11238c2ecf20Sopenharmony_ci
11248c2ecf20Sopenharmony_ci	/* clear the received/dropped/error packet */
11258c2ecf20Sopenharmony_ci	PutWord(XIRCREG0_DO, 0x8000); /* issue cmd: skip_rx_packet */
11268c2ecf20Sopenharmony_ci
11278c2ecf20Sopenharmony_ci	/* get the new ethernet status */
11288c2ecf20Sopenharmony_ci	eth_status = GetByte(XIRCREG_ESR);
11298c2ecf20Sopenharmony_ci    }
11308c2ecf20Sopenharmony_ci    if (rx_status & 0x10) { /* Receive overrun */
11318c2ecf20Sopenharmony_ci	dev->stats.rx_over_errors++;
11328c2ecf20Sopenharmony_ci	PutByte(XIRCREG_CR, ClearRxOvrun);
11338c2ecf20Sopenharmony_ci	pr_debug("receive overrun cleared\n");
11348c2ecf20Sopenharmony_ci    }
11358c2ecf20Sopenharmony_ci
11368c2ecf20Sopenharmony_ci    /***** transmit section ******/
11378c2ecf20Sopenharmony_ci    if (int_status & PktTxed) {
11388c2ecf20Sopenharmony_ci	unsigned n, nn;
11398c2ecf20Sopenharmony_ci
11408c2ecf20Sopenharmony_ci	n = lp->last_ptr_value;
11418c2ecf20Sopenharmony_ci	nn = GetByte(XIRCREG0_PTR);
11428c2ecf20Sopenharmony_ci	lp->last_ptr_value = nn;
11438c2ecf20Sopenharmony_ci	if (nn < n) /* rollover */
11448c2ecf20Sopenharmony_ci	    dev->stats.tx_packets += 256 - n;
11458c2ecf20Sopenharmony_ci	else if (n == nn) { /* happens sometimes - don't know why */
11468c2ecf20Sopenharmony_ci	    pr_debug("PTR not changed?\n");
11478c2ecf20Sopenharmony_ci	} else
11488c2ecf20Sopenharmony_ci	    dev->stats.tx_packets += lp->last_ptr_value - n;
11498c2ecf20Sopenharmony_ci	netif_wake_queue(dev);
11508c2ecf20Sopenharmony_ci    }
11518c2ecf20Sopenharmony_ci    if (tx_status & 0x0002) {	/* Excessive collisions */
11528c2ecf20Sopenharmony_ci	pr_debug("tx restarted due to excessive collisions\n");
11538c2ecf20Sopenharmony_ci	PutByte(XIRCREG_CR, RestartTx);  /* restart transmitter process */
11548c2ecf20Sopenharmony_ci    }
11558c2ecf20Sopenharmony_ci    if (tx_status & 0x0040)
11568c2ecf20Sopenharmony_ci	dev->stats.tx_aborted_errors++;
11578c2ecf20Sopenharmony_ci
11588c2ecf20Sopenharmony_ci    /* recalculate our work chunk so that we limit the duration of this
11598c2ecf20Sopenharmony_ci     * ISR to about 1/10 of a second.
11608c2ecf20Sopenharmony_ci     * Calculate only if we received a reasonable amount of bytes.
11618c2ecf20Sopenharmony_ci     */
11628c2ecf20Sopenharmony_ci    if (bytes_rcvd > 1000) {
11638c2ecf20Sopenharmony_ci	u_long duration = jiffies - start_ticks;
11648c2ecf20Sopenharmony_ci
11658c2ecf20Sopenharmony_ci	if (duration >= HZ/10) { /* if more than about 1/10 second */
11668c2ecf20Sopenharmony_ci	    maxrx_bytes = (bytes_rcvd * (HZ/10)) / duration;
11678c2ecf20Sopenharmony_ci	    if (maxrx_bytes < 2000)
11688c2ecf20Sopenharmony_ci		maxrx_bytes = 2000;
11698c2ecf20Sopenharmony_ci	    else if (maxrx_bytes > 22000)
11708c2ecf20Sopenharmony_ci		maxrx_bytes = 22000;
11718c2ecf20Sopenharmony_ci	    pr_debug("set maxrx=%u (rcvd=%u ticks=%lu)\n",
11728c2ecf20Sopenharmony_ci		  maxrx_bytes, bytes_rcvd, duration);
11738c2ecf20Sopenharmony_ci	} else if (!duration && maxrx_bytes < 22000) {
11748c2ecf20Sopenharmony_ci	    /* now much faster */
11758c2ecf20Sopenharmony_ci	    maxrx_bytes += 2000;
11768c2ecf20Sopenharmony_ci	    if (maxrx_bytes > 22000)
11778c2ecf20Sopenharmony_ci		maxrx_bytes = 22000;
11788c2ecf20Sopenharmony_ci	    pr_debug("set maxrx=%u\n", maxrx_bytes);
11798c2ecf20Sopenharmony_ci	}
11808c2ecf20Sopenharmony_ci    }
11818c2ecf20Sopenharmony_ci
11828c2ecf20Sopenharmony_ci  leave:
11838c2ecf20Sopenharmony_ci    if (lockup_hack) {
11848c2ecf20Sopenharmony_ci	if (int_status != 0xff && (int_status = GetByte(XIRCREG_ISR)) != 0)
11858c2ecf20Sopenharmony_ci	    goto loop_entry;
11868c2ecf20Sopenharmony_ci    }
11878c2ecf20Sopenharmony_ci    SelectPage(saved_page);
11888c2ecf20Sopenharmony_ci    PutByte(XIRCREG_CR, EnableIntr);  /* re-enable interrupts */
11898c2ecf20Sopenharmony_ci    /* Instead of dropping packets during a receive, we could
11908c2ecf20Sopenharmony_ci     * force an interrupt with this command:
11918c2ecf20Sopenharmony_ci     *	  PutByte(XIRCREG_CR, EnableIntr|ForceIntr);
11928c2ecf20Sopenharmony_ci     */
11938c2ecf20Sopenharmony_ci    return IRQ_HANDLED;
11948c2ecf20Sopenharmony_ci} /* xirc2ps_interrupt */
11958c2ecf20Sopenharmony_ci
11968c2ecf20Sopenharmony_ci/*====================================================================*/
11978c2ecf20Sopenharmony_ci
11988c2ecf20Sopenharmony_cistatic void
11998c2ecf20Sopenharmony_cixirc2ps_tx_timeout_task(struct work_struct *work)
12008c2ecf20Sopenharmony_ci{
12018c2ecf20Sopenharmony_ci	struct local_info *local =
12028c2ecf20Sopenharmony_ci		container_of(work, struct local_info, tx_timeout_task);
12038c2ecf20Sopenharmony_ci	struct net_device *dev = local->dev;
12048c2ecf20Sopenharmony_ci    /* reset the card */
12058c2ecf20Sopenharmony_ci    do_reset(dev,1);
12068c2ecf20Sopenharmony_ci    netif_trans_update(dev); /* prevent tx timeout */
12078c2ecf20Sopenharmony_ci    netif_wake_queue(dev);
12088c2ecf20Sopenharmony_ci}
12098c2ecf20Sopenharmony_ci
12108c2ecf20Sopenharmony_cistatic void
12118c2ecf20Sopenharmony_cixirc_tx_timeout(struct net_device *dev, unsigned int txqueue)
12128c2ecf20Sopenharmony_ci{
12138c2ecf20Sopenharmony_ci    struct local_info *lp = netdev_priv(dev);
12148c2ecf20Sopenharmony_ci    dev->stats.tx_errors++;
12158c2ecf20Sopenharmony_ci    netdev_notice(dev, "transmit timed out\n");
12168c2ecf20Sopenharmony_ci    schedule_work(&lp->tx_timeout_task);
12178c2ecf20Sopenharmony_ci}
12188c2ecf20Sopenharmony_ci
12198c2ecf20Sopenharmony_cistatic netdev_tx_t
12208c2ecf20Sopenharmony_cido_start_xmit(struct sk_buff *skb, struct net_device *dev)
12218c2ecf20Sopenharmony_ci{
12228c2ecf20Sopenharmony_ci    struct local_info *lp = netdev_priv(dev);
12238c2ecf20Sopenharmony_ci    unsigned int ioaddr = dev->base_addr;
12248c2ecf20Sopenharmony_ci    int okay;
12258c2ecf20Sopenharmony_ci    unsigned freespace;
12268c2ecf20Sopenharmony_ci    unsigned pktlen = skb->len;
12278c2ecf20Sopenharmony_ci
12288c2ecf20Sopenharmony_ci    pr_debug("do_start_xmit(skb=%p, dev=%p) len=%u\n",
12298c2ecf20Sopenharmony_ci	  skb, dev, pktlen);
12308c2ecf20Sopenharmony_ci
12318c2ecf20Sopenharmony_ci
12328c2ecf20Sopenharmony_ci    /* adjust the packet length to min. required
12338c2ecf20Sopenharmony_ci     * and hope that the buffer is large enough
12348c2ecf20Sopenharmony_ci     * to provide some random data.
12358c2ecf20Sopenharmony_ci     * fixme: For Mohawk we can change this by sending
12368c2ecf20Sopenharmony_ci     * a larger packetlen than we actually have; the chip will
12378c2ecf20Sopenharmony_ci     * pad this in his buffer with random bytes
12388c2ecf20Sopenharmony_ci     */
12398c2ecf20Sopenharmony_ci    if (pktlen < ETH_ZLEN)
12408c2ecf20Sopenharmony_ci    {
12418c2ecf20Sopenharmony_ci        if (skb_padto(skb, ETH_ZLEN))
12428c2ecf20Sopenharmony_ci        	return NETDEV_TX_OK;
12438c2ecf20Sopenharmony_ci	pktlen = ETH_ZLEN;
12448c2ecf20Sopenharmony_ci    }
12458c2ecf20Sopenharmony_ci
12468c2ecf20Sopenharmony_ci    netif_stop_queue(dev);
12478c2ecf20Sopenharmony_ci    SelectPage(0);
12488c2ecf20Sopenharmony_ci    PutWord(XIRCREG0_TRS, (u_short)pktlen+2);
12498c2ecf20Sopenharmony_ci    freespace = GetWord(XIRCREG0_TSO);
12508c2ecf20Sopenharmony_ci    okay = freespace & 0x8000;
12518c2ecf20Sopenharmony_ci    freespace &= 0x7fff;
12528c2ecf20Sopenharmony_ci    /* TRS doesn't work - (indeed it is eliminated with sil-rev 1) */
12538c2ecf20Sopenharmony_ci    okay = pktlen +2 < freespace;
12548c2ecf20Sopenharmony_ci    pr_debug("%s: avail. tx space=%u%s\n",
12558c2ecf20Sopenharmony_ci	  dev->name, freespace, okay ? " (okay)":" (not enough)");
12568c2ecf20Sopenharmony_ci    if (!okay) { /* not enough space */
12578c2ecf20Sopenharmony_ci	return NETDEV_TX_BUSY;  /* upper layer may decide to requeue this packet */
12588c2ecf20Sopenharmony_ci    }
12598c2ecf20Sopenharmony_ci    /* send the packet */
12608c2ecf20Sopenharmony_ci    PutWord(XIRCREG_EDP, (u_short)pktlen);
12618c2ecf20Sopenharmony_ci    outsw(ioaddr+XIRCREG_EDP, skb->data, pktlen>>1);
12628c2ecf20Sopenharmony_ci    if (pktlen & 1)
12638c2ecf20Sopenharmony_ci	PutByte(XIRCREG_EDP, skb->data[pktlen-1]);
12648c2ecf20Sopenharmony_ci
12658c2ecf20Sopenharmony_ci    if (lp->mohawk)
12668c2ecf20Sopenharmony_ci	PutByte(XIRCREG_CR, TransmitPacket|EnableIntr);
12678c2ecf20Sopenharmony_ci
12688c2ecf20Sopenharmony_ci    dev_kfree_skb (skb);
12698c2ecf20Sopenharmony_ci    dev->stats.tx_bytes += pktlen;
12708c2ecf20Sopenharmony_ci    netif_start_queue(dev);
12718c2ecf20Sopenharmony_ci    return NETDEV_TX_OK;
12728c2ecf20Sopenharmony_ci}
12738c2ecf20Sopenharmony_ci
12748c2ecf20Sopenharmony_cistruct set_address_info {
12758c2ecf20Sopenharmony_ci	int reg_nr;
12768c2ecf20Sopenharmony_ci	int page_nr;
12778c2ecf20Sopenharmony_ci	int mohawk;
12788c2ecf20Sopenharmony_ci	unsigned int ioaddr;
12798c2ecf20Sopenharmony_ci};
12808c2ecf20Sopenharmony_ci
12818c2ecf20Sopenharmony_cistatic void set_address(struct set_address_info *sa_info, char *addr)
12828c2ecf20Sopenharmony_ci{
12838c2ecf20Sopenharmony_ci	unsigned int ioaddr = sa_info->ioaddr;
12848c2ecf20Sopenharmony_ci	int i;
12858c2ecf20Sopenharmony_ci
12868c2ecf20Sopenharmony_ci	for (i = 0; i < 6; i++) {
12878c2ecf20Sopenharmony_ci		if (sa_info->reg_nr > 15) {
12888c2ecf20Sopenharmony_ci			sa_info->reg_nr = 8;
12898c2ecf20Sopenharmony_ci			sa_info->page_nr++;
12908c2ecf20Sopenharmony_ci			SelectPage(sa_info->page_nr);
12918c2ecf20Sopenharmony_ci		}
12928c2ecf20Sopenharmony_ci		if (sa_info->mohawk)
12938c2ecf20Sopenharmony_ci			PutByte(sa_info->reg_nr++, addr[5 - i]);
12948c2ecf20Sopenharmony_ci		else
12958c2ecf20Sopenharmony_ci			PutByte(sa_info->reg_nr++, addr[i]);
12968c2ecf20Sopenharmony_ci	}
12978c2ecf20Sopenharmony_ci}
12988c2ecf20Sopenharmony_ci
12998c2ecf20Sopenharmony_ci/****************
13008c2ecf20Sopenharmony_ci * Set all addresses: This first one is the individual address,
13018c2ecf20Sopenharmony_ci * the next 9 addresses are taken from the multicast list and
13028c2ecf20Sopenharmony_ci * the rest is filled with the individual address.
13038c2ecf20Sopenharmony_ci */
13048c2ecf20Sopenharmony_cistatic void set_addresses(struct net_device *dev)
13058c2ecf20Sopenharmony_ci{
13068c2ecf20Sopenharmony_ci	unsigned int ioaddr = dev->base_addr;
13078c2ecf20Sopenharmony_ci	struct local_info *lp = netdev_priv(dev);
13088c2ecf20Sopenharmony_ci	struct netdev_hw_addr *ha;
13098c2ecf20Sopenharmony_ci	struct set_address_info sa_info;
13108c2ecf20Sopenharmony_ci	int i;
13118c2ecf20Sopenharmony_ci
13128c2ecf20Sopenharmony_ci	/*
13138c2ecf20Sopenharmony_ci	 * Setup the info structure so that by first set_address call it will do
13148c2ecf20Sopenharmony_ci	 * SelectPage with the right page number. Hence these ones here.
13158c2ecf20Sopenharmony_ci	 */
13168c2ecf20Sopenharmony_ci	sa_info.reg_nr = 15 + 1;
13178c2ecf20Sopenharmony_ci	sa_info.page_nr = 0x50 - 1;
13188c2ecf20Sopenharmony_ci	sa_info.mohawk = lp->mohawk;
13198c2ecf20Sopenharmony_ci	sa_info.ioaddr = ioaddr;
13208c2ecf20Sopenharmony_ci
13218c2ecf20Sopenharmony_ci	set_address(&sa_info, dev->dev_addr);
13228c2ecf20Sopenharmony_ci	i = 0;
13238c2ecf20Sopenharmony_ci	netdev_for_each_mc_addr(ha, dev) {
13248c2ecf20Sopenharmony_ci		if (i++ == 9)
13258c2ecf20Sopenharmony_ci			break;
13268c2ecf20Sopenharmony_ci		set_address(&sa_info, ha->addr);
13278c2ecf20Sopenharmony_ci	}
13288c2ecf20Sopenharmony_ci	while (i++ < 9)
13298c2ecf20Sopenharmony_ci		set_address(&sa_info, dev->dev_addr);
13308c2ecf20Sopenharmony_ci	SelectPage(0);
13318c2ecf20Sopenharmony_ci}
13328c2ecf20Sopenharmony_ci
13338c2ecf20Sopenharmony_ci/****************
13348c2ecf20Sopenharmony_ci * Set or clear the multicast filter for this adaptor.
13358c2ecf20Sopenharmony_ci * We can filter up to 9 addresses, if more are requested we set
13368c2ecf20Sopenharmony_ci * multicast promiscuous mode.
13378c2ecf20Sopenharmony_ci */
13388c2ecf20Sopenharmony_ci
13398c2ecf20Sopenharmony_cistatic void
13408c2ecf20Sopenharmony_ciset_multicast_list(struct net_device *dev)
13418c2ecf20Sopenharmony_ci{
13428c2ecf20Sopenharmony_ci    unsigned int ioaddr = dev->base_addr;
13438c2ecf20Sopenharmony_ci    unsigned value;
13448c2ecf20Sopenharmony_ci
13458c2ecf20Sopenharmony_ci    SelectPage(0x42);
13468c2ecf20Sopenharmony_ci    value = GetByte(XIRCREG42_SWC1) & 0xC0;
13478c2ecf20Sopenharmony_ci
13488c2ecf20Sopenharmony_ci    if (dev->flags & IFF_PROMISC) { /* snoop */
13498c2ecf20Sopenharmony_ci	PutByte(XIRCREG42_SWC1, value | 0x06); /* set MPE and PME */
13508c2ecf20Sopenharmony_ci    } else if (netdev_mc_count(dev) > 9 || (dev->flags & IFF_ALLMULTI)) {
13518c2ecf20Sopenharmony_ci	PutByte(XIRCREG42_SWC1, value | 0x02); /* set MPE */
13528c2ecf20Sopenharmony_ci    } else if (!netdev_mc_empty(dev)) {
13538c2ecf20Sopenharmony_ci	/* the chip can filter 9 addresses perfectly */
13548c2ecf20Sopenharmony_ci	PutByte(XIRCREG42_SWC1, value | 0x01);
13558c2ecf20Sopenharmony_ci	SelectPage(0x40);
13568c2ecf20Sopenharmony_ci	PutByte(XIRCREG40_CMD0, Offline);
13578c2ecf20Sopenharmony_ci	set_addresses(dev);
13588c2ecf20Sopenharmony_ci	SelectPage(0x40);
13598c2ecf20Sopenharmony_ci	PutByte(XIRCREG40_CMD0, EnableRecv | Online);
13608c2ecf20Sopenharmony_ci    } else { /* standard usage */
13618c2ecf20Sopenharmony_ci	PutByte(XIRCREG42_SWC1, value | 0x00);
13628c2ecf20Sopenharmony_ci    }
13638c2ecf20Sopenharmony_ci    SelectPage(0);
13648c2ecf20Sopenharmony_ci}
13658c2ecf20Sopenharmony_ci
13668c2ecf20Sopenharmony_cistatic int
13678c2ecf20Sopenharmony_cido_config(struct net_device *dev, struct ifmap *map)
13688c2ecf20Sopenharmony_ci{
13698c2ecf20Sopenharmony_ci    struct local_info *local = netdev_priv(dev);
13708c2ecf20Sopenharmony_ci
13718c2ecf20Sopenharmony_ci    pr_debug("do_config(%p)\n", dev);
13728c2ecf20Sopenharmony_ci    if (map->port != 255 && map->port != dev->if_port) {
13738c2ecf20Sopenharmony_ci	if (map->port > 4)
13748c2ecf20Sopenharmony_ci	    return -EINVAL;
13758c2ecf20Sopenharmony_ci	if (!map->port) {
13768c2ecf20Sopenharmony_ci	    local->probe_port = 1;
13778c2ecf20Sopenharmony_ci	    dev->if_port = 1;
13788c2ecf20Sopenharmony_ci	} else {
13798c2ecf20Sopenharmony_ci	    local->probe_port = 0;
13808c2ecf20Sopenharmony_ci	    dev->if_port = map->port;
13818c2ecf20Sopenharmony_ci	}
13828c2ecf20Sopenharmony_ci	netdev_info(dev, "switching to %s port\n", if_names[dev->if_port]);
13838c2ecf20Sopenharmony_ci	do_reset(dev,1);  /* not the fine way :-) */
13848c2ecf20Sopenharmony_ci    }
13858c2ecf20Sopenharmony_ci    return 0;
13868c2ecf20Sopenharmony_ci}
13878c2ecf20Sopenharmony_ci
13888c2ecf20Sopenharmony_ci/****************
13898c2ecf20Sopenharmony_ci * Open the driver
13908c2ecf20Sopenharmony_ci */
13918c2ecf20Sopenharmony_cistatic int
13928c2ecf20Sopenharmony_cido_open(struct net_device *dev)
13938c2ecf20Sopenharmony_ci{
13948c2ecf20Sopenharmony_ci    struct local_info *lp = netdev_priv(dev);
13958c2ecf20Sopenharmony_ci    struct pcmcia_device *link = lp->p_dev;
13968c2ecf20Sopenharmony_ci
13978c2ecf20Sopenharmony_ci    dev_dbg(&link->dev, "do_open(%p)\n", dev);
13988c2ecf20Sopenharmony_ci
13998c2ecf20Sopenharmony_ci    /* Check that the PCMCIA card is still here. */
14008c2ecf20Sopenharmony_ci    /* Physical device present signature. */
14018c2ecf20Sopenharmony_ci    if (!pcmcia_dev_present(link))
14028c2ecf20Sopenharmony_ci	return -ENODEV;
14038c2ecf20Sopenharmony_ci
14048c2ecf20Sopenharmony_ci    /* okay */
14058c2ecf20Sopenharmony_ci    link->open++;
14068c2ecf20Sopenharmony_ci
14078c2ecf20Sopenharmony_ci    netif_start_queue(dev);
14088c2ecf20Sopenharmony_ci    do_reset(dev,1);
14098c2ecf20Sopenharmony_ci
14108c2ecf20Sopenharmony_ci    return 0;
14118c2ecf20Sopenharmony_ci}
14128c2ecf20Sopenharmony_ci
14138c2ecf20Sopenharmony_cistatic void netdev_get_drvinfo(struct net_device *dev,
14148c2ecf20Sopenharmony_ci			       struct ethtool_drvinfo *info)
14158c2ecf20Sopenharmony_ci{
14168c2ecf20Sopenharmony_ci	strlcpy(info->driver, "xirc2ps_cs", sizeof(info->driver));
14178c2ecf20Sopenharmony_ci	snprintf(info->bus_info, sizeof(info->bus_info), "PCMCIA 0x%lx",
14188c2ecf20Sopenharmony_ci		 dev->base_addr);
14198c2ecf20Sopenharmony_ci}
14208c2ecf20Sopenharmony_ci
14218c2ecf20Sopenharmony_cistatic const struct ethtool_ops netdev_ethtool_ops = {
14228c2ecf20Sopenharmony_ci	.get_drvinfo		= netdev_get_drvinfo,
14238c2ecf20Sopenharmony_ci};
14248c2ecf20Sopenharmony_ci
14258c2ecf20Sopenharmony_cistatic int
14268c2ecf20Sopenharmony_cido_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
14278c2ecf20Sopenharmony_ci{
14288c2ecf20Sopenharmony_ci    struct local_info *local = netdev_priv(dev);
14298c2ecf20Sopenharmony_ci    unsigned int ioaddr = dev->base_addr;
14308c2ecf20Sopenharmony_ci    struct mii_ioctl_data *data = if_mii(rq);
14318c2ecf20Sopenharmony_ci
14328c2ecf20Sopenharmony_ci    pr_debug("%s: ioctl(%-.6s, %#04x) %04x %04x %04x %04x\n",
14338c2ecf20Sopenharmony_ci	  dev->name, rq->ifr_ifrn.ifrn_name, cmd,
14348c2ecf20Sopenharmony_ci	  data->phy_id, data->reg_num, data->val_in, data->val_out);
14358c2ecf20Sopenharmony_ci
14368c2ecf20Sopenharmony_ci    if (!local->mohawk)
14378c2ecf20Sopenharmony_ci	return -EOPNOTSUPP;
14388c2ecf20Sopenharmony_ci
14398c2ecf20Sopenharmony_ci    switch(cmd) {
14408c2ecf20Sopenharmony_ci      case SIOCGMIIPHY:		/* Get the address of the PHY in use. */
14418c2ecf20Sopenharmony_ci	data->phy_id = 0;	/* we have only this address */
14428c2ecf20Sopenharmony_ci	fallthrough;
14438c2ecf20Sopenharmony_ci      case SIOCGMIIREG:		/* Read the specified MII register. */
14448c2ecf20Sopenharmony_ci	data->val_out = mii_rd(ioaddr, data->phy_id & 0x1f,
14458c2ecf20Sopenharmony_ci			       data->reg_num & 0x1f);
14468c2ecf20Sopenharmony_ci	break;
14478c2ecf20Sopenharmony_ci      case SIOCSMIIREG:		/* Write the specified MII register */
14488c2ecf20Sopenharmony_ci	mii_wr(ioaddr, data->phy_id & 0x1f, data->reg_num & 0x1f, data->val_in,
14498c2ecf20Sopenharmony_ci	       16);
14508c2ecf20Sopenharmony_ci	break;
14518c2ecf20Sopenharmony_ci      default:
14528c2ecf20Sopenharmony_ci	return -EOPNOTSUPP;
14538c2ecf20Sopenharmony_ci    }
14548c2ecf20Sopenharmony_ci    return 0;
14558c2ecf20Sopenharmony_ci}
14568c2ecf20Sopenharmony_ci
14578c2ecf20Sopenharmony_cistatic void
14588c2ecf20Sopenharmony_cihardreset(struct net_device *dev)
14598c2ecf20Sopenharmony_ci{
14608c2ecf20Sopenharmony_ci    struct local_info *local = netdev_priv(dev);
14618c2ecf20Sopenharmony_ci    unsigned int ioaddr = dev->base_addr;
14628c2ecf20Sopenharmony_ci
14638c2ecf20Sopenharmony_ci    SelectPage(4);
14648c2ecf20Sopenharmony_ci    udelay(1);
14658c2ecf20Sopenharmony_ci    PutByte(XIRCREG4_GPR1, 0);	     /* clear bit 0: power down */
14668c2ecf20Sopenharmony_ci    msleep(40);				     /* wait 40 msec */
14678c2ecf20Sopenharmony_ci    if (local->mohawk)
14688c2ecf20Sopenharmony_ci	PutByte(XIRCREG4_GPR1, 1);	 /* set bit 0: power up */
14698c2ecf20Sopenharmony_ci    else
14708c2ecf20Sopenharmony_ci	PutByte(XIRCREG4_GPR1, 1 | 4);	 /* set bit 0: power up, bit 2: AIC */
14718c2ecf20Sopenharmony_ci    msleep(20);			     /* wait 20 msec */
14728c2ecf20Sopenharmony_ci}
14738c2ecf20Sopenharmony_ci
14748c2ecf20Sopenharmony_cistatic void
14758c2ecf20Sopenharmony_cido_reset(struct net_device *dev, int full)
14768c2ecf20Sopenharmony_ci{
14778c2ecf20Sopenharmony_ci    struct local_info *local = netdev_priv(dev);
14788c2ecf20Sopenharmony_ci    unsigned int ioaddr = dev->base_addr;
14798c2ecf20Sopenharmony_ci    unsigned value;
14808c2ecf20Sopenharmony_ci
14818c2ecf20Sopenharmony_ci    pr_debug("%s: do_reset(%p,%d)\n", dev->name, dev, full);
14828c2ecf20Sopenharmony_ci
14838c2ecf20Sopenharmony_ci    hardreset(dev);
14848c2ecf20Sopenharmony_ci    PutByte(XIRCREG_CR, SoftReset); /* set */
14858c2ecf20Sopenharmony_ci    msleep(20);			     /* wait 20 msec */
14868c2ecf20Sopenharmony_ci    PutByte(XIRCREG_CR, 0);	     /* clear */
14878c2ecf20Sopenharmony_ci    msleep(40);			     /* wait 40 msec */
14888c2ecf20Sopenharmony_ci    if (local->mohawk) {
14898c2ecf20Sopenharmony_ci	SelectPage(4);
14908c2ecf20Sopenharmony_ci	/* set pin GP1 and GP2 to output  (0x0c)
14918c2ecf20Sopenharmony_ci	 * set GP1 to low to power up the ML6692 (0x00)
14928c2ecf20Sopenharmony_ci	 * set GP2 to high to power up the 10Mhz chip  (0x02)
14938c2ecf20Sopenharmony_ci	 */
14948c2ecf20Sopenharmony_ci	PutByte(XIRCREG4_GPR0, 0x0e);
14958c2ecf20Sopenharmony_ci    }
14968c2ecf20Sopenharmony_ci
14978c2ecf20Sopenharmony_ci    /* give the circuits some time to power up */
14988c2ecf20Sopenharmony_ci    msleep(500);			/* about 500ms */
14998c2ecf20Sopenharmony_ci
15008c2ecf20Sopenharmony_ci    local->last_ptr_value = 0;
15018c2ecf20Sopenharmony_ci    local->silicon = local->mohawk ? (GetByte(XIRCREG4_BOV) & 0x70) >> 4
15028c2ecf20Sopenharmony_ci				   : (GetByte(XIRCREG4_BOV) & 0x30) >> 4;
15038c2ecf20Sopenharmony_ci
15048c2ecf20Sopenharmony_ci    if (local->probe_port) {
15058c2ecf20Sopenharmony_ci	if (!local->mohawk) {
15068c2ecf20Sopenharmony_ci	    SelectPage(4);
15078c2ecf20Sopenharmony_ci	    PutByte(XIRCREG4_GPR0, 4);
15088c2ecf20Sopenharmony_ci	    local->probe_port = 0;
15098c2ecf20Sopenharmony_ci	}
15108c2ecf20Sopenharmony_ci    } else if (dev->if_port == 2) { /* enable 10Base2 */
15118c2ecf20Sopenharmony_ci	SelectPage(0x42);
15128c2ecf20Sopenharmony_ci	PutByte(XIRCREG42_SWC1, 0xC0);
15138c2ecf20Sopenharmony_ci    } else { /* enable 10BaseT */
15148c2ecf20Sopenharmony_ci	SelectPage(0x42);
15158c2ecf20Sopenharmony_ci	PutByte(XIRCREG42_SWC1, 0x80);
15168c2ecf20Sopenharmony_ci    }
15178c2ecf20Sopenharmony_ci    msleep(40);			     /* wait 40 msec to let it complete */
15188c2ecf20Sopenharmony_ci
15198c2ecf20Sopenharmony_ci  #if 0
15208c2ecf20Sopenharmony_ci    {
15218c2ecf20Sopenharmony_ci	SelectPage(0);
15228c2ecf20Sopenharmony_ci	value = GetByte(XIRCREG_ESR);	 /* read the ESR */
15238c2ecf20Sopenharmony_ci	pr_debug("%s: ESR is: %#02x\n", dev->name, value);
15248c2ecf20Sopenharmony_ci    }
15258c2ecf20Sopenharmony_ci  #endif
15268c2ecf20Sopenharmony_ci
15278c2ecf20Sopenharmony_ci    /* setup the ECR */
15288c2ecf20Sopenharmony_ci    SelectPage(1);
15298c2ecf20Sopenharmony_ci    PutByte(XIRCREG1_IMR0, 0xff); /* allow all ints */
15308c2ecf20Sopenharmony_ci    PutByte(XIRCREG1_IMR1, 1	); /* and Set TxUnderrunDetect */
15318c2ecf20Sopenharmony_ci    value = GetByte(XIRCREG1_ECR);
15328c2ecf20Sopenharmony_ci  #if 0
15338c2ecf20Sopenharmony_ci    if (local->mohawk)
15348c2ecf20Sopenharmony_ci	value |= DisableLinkPulse;
15358c2ecf20Sopenharmony_ci    PutByte(XIRCREG1_ECR, value);
15368c2ecf20Sopenharmony_ci  #endif
15378c2ecf20Sopenharmony_ci    pr_debug("%s: ECR is: %#02x\n", dev->name, value);
15388c2ecf20Sopenharmony_ci
15398c2ecf20Sopenharmony_ci    SelectPage(0x42);
15408c2ecf20Sopenharmony_ci    PutByte(XIRCREG42_SWC0, 0x20); /* disable source insertion */
15418c2ecf20Sopenharmony_ci
15428c2ecf20Sopenharmony_ci    if (local->silicon != 1) {
15438c2ecf20Sopenharmony_ci	/* set the local memory dividing line.
15448c2ecf20Sopenharmony_ci	 * The comments in the sample code say that this is only
15458c2ecf20Sopenharmony_ci	 * settable with the scipper version 2 which is revision 0.
15468c2ecf20Sopenharmony_ci	 * Always for CE3 cards
15478c2ecf20Sopenharmony_ci	 */
15488c2ecf20Sopenharmony_ci	SelectPage(2);
15498c2ecf20Sopenharmony_ci	PutWord(XIRCREG2_RBS, 0x2000);
15508c2ecf20Sopenharmony_ci    }
15518c2ecf20Sopenharmony_ci
15528c2ecf20Sopenharmony_ci    if (full)
15538c2ecf20Sopenharmony_ci	set_addresses(dev);
15548c2ecf20Sopenharmony_ci
15558c2ecf20Sopenharmony_ci    /* Hardware workaround:
15568c2ecf20Sopenharmony_ci     * The receive byte pointer after reset is off by 1 so we need
15578c2ecf20Sopenharmony_ci     * to move the offset pointer back to 0.
15588c2ecf20Sopenharmony_ci     */
15598c2ecf20Sopenharmony_ci    SelectPage(0);
15608c2ecf20Sopenharmony_ci    PutWord(XIRCREG0_DO, 0x2000); /* change offset command, off=0 */
15618c2ecf20Sopenharmony_ci
15628c2ecf20Sopenharmony_ci    /* setup MAC IMRs and clear status registers */
15638c2ecf20Sopenharmony_ci    SelectPage(0x40);		     /* Bit 7 ... bit 0 */
15648c2ecf20Sopenharmony_ci    PutByte(XIRCREG40_RMASK0, 0xff); /* ROK, RAB, rsv, RO, CRC, AE, PTL, MP */
15658c2ecf20Sopenharmony_ci    PutByte(XIRCREG40_TMASK0, 0xff); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */
15668c2ecf20Sopenharmony_ci    PutByte(XIRCREG40_TMASK1, 0xb0); /* rsv, rsv, PTD, EXT, rsv,rsv,rsv, rsv*/
15678c2ecf20Sopenharmony_ci    PutByte(XIRCREG40_RXST0,  0x00); /* ROK, RAB, REN, RO, CRC, AE, PTL, MP */
15688c2ecf20Sopenharmony_ci    PutByte(XIRCREG40_TXST0,  0x00); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */
15698c2ecf20Sopenharmony_ci    PutByte(XIRCREG40_TXST1,  0x00); /* TEN, rsv, PTD, EXT, retry_counter:4  */
15708c2ecf20Sopenharmony_ci
15718c2ecf20Sopenharmony_ci    if (full && local->mohawk && init_mii(dev)) {
15728c2ecf20Sopenharmony_ci	if (dev->if_port == 4 || local->dingo || local->new_mii) {
15738c2ecf20Sopenharmony_ci	    netdev_info(dev, "MII selected\n");
15748c2ecf20Sopenharmony_ci	    SelectPage(2);
15758c2ecf20Sopenharmony_ci	    PutByte(XIRCREG2_MSR, GetByte(XIRCREG2_MSR) | 0x08);
15768c2ecf20Sopenharmony_ci	    msleep(20);
15778c2ecf20Sopenharmony_ci	} else {
15788c2ecf20Sopenharmony_ci	    netdev_info(dev, "MII detected; using 10mbs\n");
15798c2ecf20Sopenharmony_ci	    SelectPage(0x42);
15808c2ecf20Sopenharmony_ci	    if (dev->if_port == 2) /* enable 10Base2 */
15818c2ecf20Sopenharmony_ci		PutByte(XIRCREG42_SWC1, 0xC0);
15828c2ecf20Sopenharmony_ci	    else  /* enable 10BaseT */
15838c2ecf20Sopenharmony_ci		PutByte(XIRCREG42_SWC1, 0x80);
15848c2ecf20Sopenharmony_ci	    msleep(40);			/* wait 40 msec to let it complete */
15858c2ecf20Sopenharmony_ci	}
15868c2ecf20Sopenharmony_ci	if (full_duplex)
15878c2ecf20Sopenharmony_ci	    PutByte(XIRCREG1_ECR, GetByte(XIRCREG1_ECR | FullDuplex));
15888c2ecf20Sopenharmony_ci    } else {  /* No MII */
15898c2ecf20Sopenharmony_ci	SelectPage(0);
15908c2ecf20Sopenharmony_ci	value = GetByte(XIRCREG_ESR);	 /* read the ESR */
15918c2ecf20Sopenharmony_ci	dev->if_port = (value & MediaSelect) ? 1 : 2;
15928c2ecf20Sopenharmony_ci    }
15938c2ecf20Sopenharmony_ci
15948c2ecf20Sopenharmony_ci    /* configure the LEDs */
15958c2ecf20Sopenharmony_ci    SelectPage(2);
15968c2ecf20Sopenharmony_ci    if (dev->if_port == 1 || dev->if_port == 4) /* TP: Link and Activity */
15978c2ecf20Sopenharmony_ci	PutByte(XIRCREG2_LED, 0x3b);
15988c2ecf20Sopenharmony_ci    else			      /* Coax: Not-Collision and Activity */
15998c2ecf20Sopenharmony_ci	PutByte(XIRCREG2_LED, 0x3a);
16008c2ecf20Sopenharmony_ci
16018c2ecf20Sopenharmony_ci    if (local->dingo)
16028c2ecf20Sopenharmony_ci	PutByte(0x0b, 0x04); /* 100 Mbit LED */
16038c2ecf20Sopenharmony_ci
16048c2ecf20Sopenharmony_ci    /* enable receiver and put the mac online */
16058c2ecf20Sopenharmony_ci    if (full) {
16068c2ecf20Sopenharmony_ci	set_multicast_list(dev);
16078c2ecf20Sopenharmony_ci	SelectPage(0x40);
16088c2ecf20Sopenharmony_ci	PutByte(XIRCREG40_CMD0, EnableRecv | Online);
16098c2ecf20Sopenharmony_ci    }
16108c2ecf20Sopenharmony_ci
16118c2ecf20Sopenharmony_ci    /* setup Ethernet IMR and enable interrupts */
16128c2ecf20Sopenharmony_ci    SelectPage(1);
16138c2ecf20Sopenharmony_ci    PutByte(XIRCREG1_IMR0, 0xff);
16148c2ecf20Sopenharmony_ci    udelay(1);
16158c2ecf20Sopenharmony_ci    SelectPage(0);
16168c2ecf20Sopenharmony_ci    PutByte(XIRCREG_CR, EnableIntr);
16178c2ecf20Sopenharmony_ci    if (local->modem && !local->dingo) { /* do some magic */
16188c2ecf20Sopenharmony_ci	if (!(GetByte(0x10) & 0x01))
16198c2ecf20Sopenharmony_ci	    PutByte(0x10, 0x11); /* unmask master-int bit */
16208c2ecf20Sopenharmony_ci    }
16218c2ecf20Sopenharmony_ci
16228c2ecf20Sopenharmony_ci    if (full)
16238c2ecf20Sopenharmony_ci	netdev_info(dev, "media %s, silicon revision %d\n",
16248c2ecf20Sopenharmony_ci		    if_names[dev->if_port], local->silicon);
16258c2ecf20Sopenharmony_ci    /* We should switch back to page 0 to avoid a bug in revision 0
16268c2ecf20Sopenharmony_ci     * where regs with offset below 8 can't be read after an access
16278c2ecf20Sopenharmony_ci     * to the MAC registers */
16288c2ecf20Sopenharmony_ci    SelectPage(0);
16298c2ecf20Sopenharmony_ci}
16308c2ecf20Sopenharmony_ci
16318c2ecf20Sopenharmony_ci/****************
16328c2ecf20Sopenharmony_ci * Initialize the Media-Independent-Interface
16338c2ecf20Sopenharmony_ci * Returns: True if we have a good MII
16348c2ecf20Sopenharmony_ci */
16358c2ecf20Sopenharmony_cistatic int
16368c2ecf20Sopenharmony_ciinit_mii(struct net_device *dev)
16378c2ecf20Sopenharmony_ci{
16388c2ecf20Sopenharmony_ci    struct local_info *local = netdev_priv(dev);
16398c2ecf20Sopenharmony_ci    unsigned int ioaddr = dev->base_addr;
16408c2ecf20Sopenharmony_ci    unsigned control, status, linkpartner;
16418c2ecf20Sopenharmony_ci    int i;
16428c2ecf20Sopenharmony_ci
16438c2ecf20Sopenharmony_ci    if (if_port == 4 || if_port == 1) { /* force 100BaseT or 10BaseT */
16448c2ecf20Sopenharmony_ci	dev->if_port = if_port;
16458c2ecf20Sopenharmony_ci	local->probe_port = 0;
16468c2ecf20Sopenharmony_ci	return 1;
16478c2ecf20Sopenharmony_ci    }
16488c2ecf20Sopenharmony_ci
16498c2ecf20Sopenharmony_ci    status = mii_rd(ioaddr,  0, 1);
16508c2ecf20Sopenharmony_ci    if ((status & 0xff00) != 0x7800)
16518c2ecf20Sopenharmony_ci	return 0; /* No MII */
16528c2ecf20Sopenharmony_ci
16538c2ecf20Sopenharmony_ci    local->new_mii = (mii_rd(ioaddr, 0, 2) != 0xffff);
16548c2ecf20Sopenharmony_ci
16558c2ecf20Sopenharmony_ci    if (local->probe_port)
16568c2ecf20Sopenharmony_ci	control = 0x1000; /* auto neg */
16578c2ecf20Sopenharmony_ci    else if (dev->if_port == 4)
16588c2ecf20Sopenharmony_ci	control = 0x2000; /* no auto neg, 100mbs mode */
16598c2ecf20Sopenharmony_ci    else
16608c2ecf20Sopenharmony_ci	control = 0x0000; /* no auto neg, 10mbs mode */
16618c2ecf20Sopenharmony_ci    mii_wr(ioaddr,  0, 0, control, 16);
16628c2ecf20Sopenharmony_ci    udelay(100);
16638c2ecf20Sopenharmony_ci    control = mii_rd(ioaddr, 0, 0);
16648c2ecf20Sopenharmony_ci
16658c2ecf20Sopenharmony_ci    if (control & 0x0400) {
16668c2ecf20Sopenharmony_ci	netdev_notice(dev, "can't take PHY out of isolation mode\n");
16678c2ecf20Sopenharmony_ci	local->probe_port = 0;
16688c2ecf20Sopenharmony_ci	return 0;
16698c2ecf20Sopenharmony_ci    }
16708c2ecf20Sopenharmony_ci
16718c2ecf20Sopenharmony_ci    if (local->probe_port) {
16728c2ecf20Sopenharmony_ci	/* according to the DP83840A specs the auto negotiation process
16738c2ecf20Sopenharmony_ci	 * may take up to 3.5 sec, so we use this also for our ML6692
16748c2ecf20Sopenharmony_ci	 * Fixme: Better to use a timer here!
16758c2ecf20Sopenharmony_ci	 */
16768c2ecf20Sopenharmony_ci	for (i=0; i < 35; i++) {
16778c2ecf20Sopenharmony_ci	    msleep(100);	 /* wait 100 msec */
16788c2ecf20Sopenharmony_ci	    status = mii_rd(ioaddr,  0, 1);
16798c2ecf20Sopenharmony_ci	    if ((status & 0x0020) && (status & 0x0004))
16808c2ecf20Sopenharmony_ci		break;
16818c2ecf20Sopenharmony_ci	}
16828c2ecf20Sopenharmony_ci
16838c2ecf20Sopenharmony_ci	if (!(status & 0x0020)) {
16848c2ecf20Sopenharmony_ci	    netdev_info(dev, "autonegotiation failed; using 10mbs\n");
16858c2ecf20Sopenharmony_ci	    if (!local->new_mii) {
16868c2ecf20Sopenharmony_ci		control = 0x0000;
16878c2ecf20Sopenharmony_ci		mii_wr(ioaddr,  0, 0, control, 16);
16888c2ecf20Sopenharmony_ci		udelay(100);
16898c2ecf20Sopenharmony_ci		SelectPage(0);
16908c2ecf20Sopenharmony_ci		dev->if_port = (GetByte(XIRCREG_ESR) & MediaSelect) ? 1 : 2;
16918c2ecf20Sopenharmony_ci	    }
16928c2ecf20Sopenharmony_ci	} else {
16938c2ecf20Sopenharmony_ci	    linkpartner = mii_rd(ioaddr, 0, 5);
16948c2ecf20Sopenharmony_ci	    netdev_info(dev, "MII link partner: %04x\n", linkpartner);
16958c2ecf20Sopenharmony_ci	    if (linkpartner & 0x0080) {
16968c2ecf20Sopenharmony_ci		dev->if_port = 4;
16978c2ecf20Sopenharmony_ci	    } else
16988c2ecf20Sopenharmony_ci		dev->if_port = 1;
16998c2ecf20Sopenharmony_ci	}
17008c2ecf20Sopenharmony_ci    }
17018c2ecf20Sopenharmony_ci
17028c2ecf20Sopenharmony_ci    return 1;
17038c2ecf20Sopenharmony_ci}
17048c2ecf20Sopenharmony_ci
17058c2ecf20Sopenharmony_cistatic void
17068c2ecf20Sopenharmony_cido_powerdown(struct net_device *dev)
17078c2ecf20Sopenharmony_ci{
17088c2ecf20Sopenharmony_ci
17098c2ecf20Sopenharmony_ci    unsigned int ioaddr = dev->base_addr;
17108c2ecf20Sopenharmony_ci
17118c2ecf20Sopenharmony_ci    pr_debug("do_powerdown(%p)\n", dev);
17128c2ecf20Sopenharmony_ci
17138c2ecf20Sopenharmony_ci    SelectPage(4);
17148c2ecf20Sopenharmony_ci    PutByte(XIRCREG4_GPR1, 0);	     /* clear bit 0: power down */
17158c2ecf20Sopenharmony_ci    SelectPage(0);
17168c2ecf20Sopenharmony_ci}
17178c2ecf20Sopenharmony_ci
17188c2ecf20Sopenharmony_cistatic int
17198c2ecf20Sopenharmony_cido_stop(struct net_device *dev)
17208c2ecf20Sopenharmony_ci{
17218c2ecf20Sopenharmony_ci    unsigned int ioaddr = dev->base_addr;
17228c2ecf20Sopenharmony_ci    struct local_info *lp = netdev_priv(dev);
17238c2ecf20Sopenharmony_ci    struct pcmcia_device *link = lp->p_dev;
17248c2ecf20Sopenharmony_ci
17258c2ecf20Sopenharmony_ci    dev_dbg(&link->dev, "do_stop(%p)\n", dev);
17268c2ecf20Sopenharmony_ci
17278c2ecf20Sopenharmony_ci    if (!link)
17288c2ecf20Sopenharmony_ci	return -ENODEV;
17298c2ecf20Sopenharmony_ci
17308c2ecf20Sopenharmony_ci    netif_stop_queue(dev);
17318c2ecf20Sopenharmony_ci
17328c2ecf20Sopenharmony_ci    SelectPage(0);
17338c2ecf20Sopenharmony_ci    PutByte(XIRCREG_CR, 0);  /* disable interrupts */
17348c2ecf20Sopenharmony_ci    SelectPage(0x01);
17358c2ecf20Sopenharmony_ci    PutByte(XIRCREG1_IMR0, 0x00); /* forbid all ints */
17368c2ecf20Sopenharmony_ci    SelectPage(4);
17378c2ecf20Sopenharmony_ci    PutByte(XIRCREG4_GPR1, 0);	/* clear bit 0: power down */
17388c2ecf20Sopenharmony_ci    SelectPage(0);
17398c2ecf20Sopenharmony_ci
17408c2ecf20Sopenharmony_ci    link->open--;
17418c2ecf20Sopenharmony_ci    return 0;
17428c2ecf20Sopenharmony_ci}
17438c2ecf20Sopenharmony_ci
17448c2ecf20Sopenharmony_cistatic const struct pcmcia_device_id xirc2ps_ids[] = {
17458c2ecf20Sopenharmony_ci	PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0089, 0x110a),
17468c2ecf20Sopenharmony_ci	PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0138, 0x110a),
17478c2ecf20Sopenharmony_ci	PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM28", 0x2e3ee845, 0x0ea978ea),
17488c2ecf20Sopenharmony_ci	PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM33", 0x2e3ee845, 0x80609023),
17498c2ecf20Sopenharmony_ci	PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM56", 0x2e3ee845, 0xa650c32a),
17508c2ecf20Sopenharmony_ci	PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "REM10", 0x2e3ee845, 0x76df1d29),
17518c2ecf20Sopenharmony_ci	PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "XEM5600", 0x2e3ee845, 0xf1403719),
17528c2ecf20Sopenharmony_ci	PCMCIA_PFC_DEVICE_PROD_ID12(0, "Xircom", "CreditCard Ethernet+Modem II", 0x2e3ee845, 0xeca401bf),
17538c2ecf20Sopenharmony_ci	PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x010a),
17548c2ecf20Sopenharmony_ci	PCMCIA_DEVICE_PROD_ID13("Toshiba Information Systems", "TPCENET", 0x1b3b94fe, 0xf381c1a2),
17558c2ecf20Sopenharmony_ci	PCMCIA_DEVICE_PROD_ID13("Xircom", "CE3-10/100", 0x2e3ee845, 0x0ec0ac37),
17568c2ecf20Sopenharmony_ci	PCMCIA_DEVICE_PROD_ID13("Xircom", "PS-CE2-10", 0x2e3ee845, 0x947d9073),
17578c2ecf20Sopenharmony_ci	PCMCIA_DEVICE_PROD_ID13("Xircom", "R2E-100BTX", 0x2e3ee845, 0x2464a6e3),
17588c2ecf20Sopenharmony_ci	PCMCIA_DEVICE_PROD_ID13("Xircom", "RE-10", 0x2e3ee845, 0x3e08d609),
17598c2ecf20Sopenharmony_ci	PCMCIA_DEVICE_PROD_ID13("Xircom", "XE2000", 0x2e3ee845, 0xf7188e46),
17608c2ecf20Sopenharmony_ci	PCMCIA_DEVICE_PROD_ID12("Compaq", "Ethernet LAN Card", 0x54f7c49c, 0x9fd2f0a2),
17618c2ecf20Sopenharmony_ci	PCMCIA_DEVICE_PROD_ID12("Compaq", "Netelligent 10/100 PC Card", 0x54f7c49c, 0xefe96769),
17628c2ecf20Sopenharmony_ci	PCMCIA_DEVICE_PROD_ID12("Intel", "EtherExpress(TM) PRO/100 PC Card Mobile Adapter16", 0x816cc815, 0x174397db),
17638c2ecf20Sopenharmony_ci	PCMCIA_DEVICE_PROD_ID12("Toshiba", "10/100 Ethernet PC Card", 0x44a09d9c, 0xb44deecf),
17648c2ecf20Sopenharmony_ci	/* also matches CFE-10 cards! */
17658c2ecf20Sopenharmony_ci	/* PCMCIA_DEVICE_MANF_CARD(0x0105, 0x010a), */
17668c2ecf20Sopenharmony_ci	PCMCIA_DEVICE_NULL,
17678c2ecf20Sopenharmony_ci};
17688c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pcmcia, xirc2ps_ids);
17698c2ecf20Sopenharmony_ci
17708c2ecf20Sopenharmony_ci
17718c2ecf20Sopenharmony_cistatic struct pcmcia_driver xirc2ps_cs_driver = {
17728c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,
17738c2ecf20Sopenharmony_ci	.name		= "xirc2ps_cs",
17748c2ecf20Sopenharmony_ci	.probe		= xirc2ps_probe,
17758c2ecf20Sopenharmony_ci	.remove		= xirc2ps_detach,
17768c2ecf20Sopenharmony_ci	.id_table       = xirc2ps_ids,
17778c2ecf20Sopenharmony_ci	.suspend	= xirc2ps_suspend,
17788c2ecf20Sopenharmony_ci	.resume		= xirc2ps_resume,
17798c2ecf20Sopenharmony_ci};
17808c2ecf20Sopenharmony_cimodule_pcmcia_driver(xirc2ps_cs_driver);
17818c2ecf20Sopenharmony_ci
17828c2ecf20Sopenharmony_ci#ifndef MODULE
17838c2ecf20Sopenharmony_cistatic int __init setup_xirc2ps_cs(char *str)
17848c2ecf20Sopenharmony_ci{
17858c2ecf20Sopenharmony_ci	/* if_port, full_duplex, do_sound, lockup_hack
17868c2ecf20Sopenharmony_ci	 */
17878c2ecf20Sopenharmony_ci	int ints[10] = { -1 };
17888c2ecf20Sopenharmony_ci
17898c2ecf20Sopenharmony_ci	str = get_options(str, ARRAY_SIZE(ints), ints);
17908c2ecf20Sopenharmony_ci
17918c2ecf20Sopenharmony_ci#define MAYBE_SET(X,Y) if (ints[0] >= Y && ints[Y] != -1) { X = ints[Y]; }
17928c2ecf20Sopenharmony_ci	MAYBE_SET(if_port, 3);
17938c2ecf20Sopenharmony_ci	MAYBE_SET(full_duplex, 4);
17948c2ecf20Sopenharmony_ci	MAYBE_SET(do_sound, 5);
17958c2ecf20Sopenharmony_ci	MAYBE_SET(lockup_hack, 6);
17968c2ecf20Sopenharmony_ci#undef  MAYBE_SET
17978c2ecf20Sopenharmony_ci
17988c2ecf20Sopenharmony_ci	return 1;
17998c2ecf20Sopenharmony_ci}
18008c2ecf20Sopenharmony_ci
18018c2ecf20Sopenharmony_ci__setup("xirc2ps_cs=", setup_xirc2ps_cs);
18028c2ecf20Sopenharmony_ci#endif
1803