Annotation of Gnu-Mach/linux/src/drivers/net/rtl8139.c, revision 1.1.1.3

1.1       root        1: /* rtl8139.c: A RealTek RTL8129/8139 Fast Ethernet driver for Linux. */
                      2: /*
1.1.1.3 ! root        3:        Written and Copyright 1997-2003 by Donald Becker.
        !             4:        This software may be used and distributed according to the terms of
        !             5:        the GNU General Public License (GPL), incorporated herein by reference.
        !             6:        Drivers based on or derived from this code fall under the GPL and must
        !             7:        retain the authorship, copyright and license notice.  This file is not
        !             8:        a complete program and may only be used when the entire operating
        !             9:        system is licensed under the GPL.
1.1       root       10: 
                     11:        This driver is for boards based on the RTL8129 and RTL8139 PCI ethernet
                     12:        chips.
                     13: 
1.1.1.3 ! root       14:        The author may be reached as [email protected], or C/O
        !            15:        Scyld Computing Corporation
        !            16:        410 Severn Ave., Suite 210
        !            17:        Annapolis MD 21403
1.1       root       18: 
                     19:        Support and updates available at
1.1.1.3 ! root       20:        http://www.scyld.com/network/rtl8139.html
1.1       root       21: 
1.1.1.3 ! root       22:        Twister-tuning table provided by Kinston <[email protected]>.
1.1       root       23: */
                     24: 
1.1.1.3 ! root       25: /* These identify the driver base version and may not be removed. */
        !            26: static const char versionA[] =
        !            27: "rtl8139.c:v1.23a 8/24/2003 Donald Becker, [email protected].\n";
        !            28: static const char versionB[] =
        !            29: " http://www.scyld.com/network/rtl8139.html\n";
        !            30: 
        !            31: #ifndef USE_MEM_OPS
        !            32: /* Note: Register access width and timing restrictions apply in MMIO mode.
        !            33:    This updated driver should nominally work, but I/O mode is better tested. */
        !            34: #define USE_IO_OPS
        !            35: #endif
        !            36: 
        !            37: /* The user-configurable values.
        !            38:    These may be modified when a driver module is loaded.*/
        !            39: /* Message enable level: 0..31 = no..all messages.  See NETIF_MSG docs. */
        !            40: static int debug = 2;
1.1       root       41: 
                     42: /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
1.1.1.3 ! root       43: static int max_interrupt_work = 20;
        !            44: 
        !            45: /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
        !            46:    The RTL chips use a 64 element hash table based on the Ethernet CRC.  It
        !            47:    is efficient to update the hardware filter, but recalculating the table
        !            48:    for a long filter list is painful.  */
        !            49: static int multicast_filter_limit = 32;
        !            50: 
        !            51: /* Used to pass the full-duplex flag, etc. */
        !            52: #define MAX_UNITS 8            /* More are supported, limit only on options */
        !            53: static int options[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
        !            54: static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
        !            55: 
        !            56: /* Operational parameters that are set at compile time. */
1.1       root       57: 
1.1.1.3 ! root       58: /* Maximum size of the in-memory receive ring (smaller if no memory). */
1.1.1.2   root       59: #define RX_BUF_LEN_IDX 2                       /* 0==8K, 1==16K, 2==32K, 3==64K */
1.1       root       60: /* Size of the Tx bounce buffers -- must be at least (dev->mtu+14+4). */
                     61: #define TX_BUF_SIZE    1536
                     62: 
                     63: /* PCI Tuning Parameters
                     64:    Threshold is bytes transferred to chip before transmission starts. */
                     65: #define TX_FIFO_THRESH 256     /* In bytes, rounded down to 32 byte units. */
                     66: 
                     67: /* The following settings are log_2(bytes)-4:  0 == 16 bytes .. 6==1024. */
                     68: #define RX_FIFO_THRESH 4               /* Rx buffer level before first PCI xfer.  */
                     69: #define RX_DMA_BURST   4               /* Maximum PCI burst, '4' is 256 bytes */
1.1.1.3 ! root       70: #define TX_DMA_BURST   4               /* Calculate as 16<<val. */
1.1       root       71: 
                     72: /* Operational parameters that usually are not changed. */
                     73: /* Time in jiffies before concluding the transmitter is hung. */
1.1.1.3 ! root       74: #define TX_TIMEOUT  (6*HZ)
1.1       root       75: 
1.1.1.3 ! root       76: /* Allocation size of Rx buffers with full-sized Ethernet frames.
        !            77:    This is a cross-driver value that is not a limit,
        !            78:    but a way to keep a consistent allocation size among drivers.
        !            79:  */
        !            80: #define PKT_BUF_SZ             1536
        !            81: 
        !            82: 
        !            83: #ifndef __KERNEL__
        !            84: #define __KERNEL__
1.1       root       85: #endif
1.1.1.3 ! root       86: #if !defined(__OPTIMIZE__)
        !            87: #warning  You must compile this file with the correct options!
        !            88: #warning  See the last lines of the source file.
        !            89: #error You must compile this driver with "-O".
        !            90: #endif
        !            91: 
        !            92: #include <linux/config.h>
        !            93: #if defined(CONFIG_SMP) && ! defined(__SMP__)
        !            94: #define __SMP__
        !            95: #endif
        !            96: #if defined(MODULE) && defined(CONFIG_MODVERSIONS) && ! defined(MODVERSIONS)
        !            97: #define MODVERSIONS
        !            98: #endif
        !            99: 
1.1       root      100: #include <linux/version.h>
1.1.1.3 ! root      101: #if defined(MODVERSIONS)
        !           102: #include <linux/modversions.h>
1.1       root      103: #endif
1.1.1.3 ! root      104: #include <linux/module.h>
1.1       root      105: 
                    106: #include <linux/kernel.h>
                    107: #include <linux/string.h>
                    108: #include <linux/timer.h>
                    109: #include <linux/errno.h>
                    110: #include <linux/ioport.h>
1.1.1.3 ! root      111: #if LINUX_VERSION_CODE >= 0x20400
        !           112: #include <linux/slab.h>
        !           113: #else
1.1       root      114: #include <linux/malloc.h>
1.1.1.3 ! root      115: #endif
1.1       root      116: #include <linux/interrupt.h>
                    117: #include <linux/pci.h>
                    118: #include <linux/netdevice.h>
                    119: #include <linux/etherdevice.h>
                    120: #include <linux/skbuff.h>
1.1.1.3 ! root      121: #include <asm/processor.h>             /* Processor type for cache alignment. */
        !           122: #include <asm/bitops.h>
        !           123: #include <asm/io.h>
1.1       root      124: 
1.1.1.3 ! root      125: #if LINUX_VERSION_CODE >= 0x20300
        !           126: #include <linux/spinlock.h>
        !           127: #elif LINUX_VERSION_CODE >= 0x20200
        !           128: #include <asm/spinlock.h>
1.1       root      129: #endif
                    130: 
1.1.1.3 ! root      131: #ifdef INLINE_PCISCAN
        !           132: #include "k_compat.h"
        !           133: #else
        !           134: #include "pci-scan.h"
        !           135: #include "kern_compat.h"
1.1       root      136: #endif
                    137: 
1.1.1.3 ! root      138: #if (LINUX_VERSION_CODE >= 0x20100)  &&  defined(MODULE)
        !           139: char kernel_version[] = UTS_RELEASE;
        !           140: #endif
1.1       root      141: 
                    142: /*
                    143:                                Theory of Operation
                    144: 
                    145: I. Board Compatibility
                    146: 
1.1.1.3 ! root      147: This device driver is designed for the RealTek RTL8129 series, the RealTek
        !           148: Fast Ethernet controllers for PCI and CardBus.  This chip is used on many
        !           149: low-end boards, sometimes with custom chip labels.
1.1       root      150: 
                    151: 
                    152: II. Board-specific settings
                    153: 
                    154: PCI bus devices are configured by the system at boot time, so no jumpers
                    155: need to be set on the board.  The system BIOS will assign the
                    156: PCI INTA signal to a (preferably otherwise unused) system IRQ line.
                    157: Note: Kernel versions earlier than 1.3.73 do not support shared PCI
                    158: interrupt lines.
                    159: 
                    160: III. Driver operation
                    161: 
                    162: IIIa. Rx Ring buffers
                    163: 
                    164: The receive unit uses a single linear ring buffer rather than the more
                    165: common (and more efficient) descriptor-based architecture.  Incoming frames
                    166: are sequentially stored into the Rx region, and the host copies them into
                    167: skbuffs.
                    168: 
                    169: Comment: While it is theoretically possible to process many frames in place,
1.1.1.3 ! root      170: any delay in Rx processing would block the Rx ring and cause us to drop
        !           171: frames.  It would be difficult to design a protocol stack where the data
        !           172: buffer could be recalled by the device driver.
1.1       root      173: 
                    174: IIIb. Tx operation
                    175: 
1.1.1.3 ! root      176: The RTL8129 uses a fixed set of four Tx descriptors in register space.  Tx
        !           177: frames must be 32 bit aligned.  Linux aligns the IP header on word
        !           178: boundaries, and 14 byte ethernet header means that almost all frames will
        !           179: need to be copied to an alignment buffer.  The driver statically allocates
        !           180: alignment the four alignment buffers at open() time.
1.1       root      181: 
                    182: IVb. References
                    183: 
                    184: http://www.realtek.com.tw/cn/cn.html
                    185: http://cesdis.gsfc.nasa.gov/linux/misc/NWay.html
                    186: 
                    187: IVc. Errata
                    188: 
                    189: */
1.1.1.3 ! root      190: 
1.1       root      191: 
1.1.1.3 ! root      192: static void *rtl8139_probe1(struct pci_dev *pdev, void *init_dev,
        !           193:                                                        long ioaddr, int irq, int chip_idx, int find_cnt);
        !           194: static int rtl_pwr_event(void *dev_instance, int event);
        !           195: 
        !           196: enum chip_capability_flags {HAS_MII_XCVR=0x01, HAS_CHIP_XCVR=0x02,
        !           197:                                                        HAS_LNK_CHNG=0x04, HAS_DESC=0x08};
        !           198: #ifdef USE_IO_OPS
        !           199: #define RTL8139_IOTYPE  PCI_USES_MASTER|PCI_USES_IO |PCI_ADDR0
        !           200: #else
        !           201: #define RTL8139_IOTYPE  PCI_USES_MASTER|PCI_USES_MEM|PCI_ADDR1
1.1       root      202: #endif
1.1.1.3 ! root      203: #define RTL8129_CAPS  HAS_MII_XCVR
        !           204: #define RTL8139_CAPS  HAS_CHIP_XCVR|HAS_LNK_CHNG
        !           205: #define RTL8139D_CAPS  HAS_CHIP_XCVR|HAS_LNK_CHNG|HAS_DESC
        !           206: 
        !           207: /* Note: Update the marked constant in _attach() if the RTL8139B entry moves.*/
        !           208: static struct pci_id_info pci_tbl[] = {
        !           209:        {"RealTek RTL8139C+, 64 bit high performance",
        !           210:         { 0x813910ec, 0xffffffff, 0,0, 0x20, 0xff},
        !           211:         RTL8139_IOTYPE, 0x80, RTL8139D_CAPS, },
        !           212:        {"RealTek RTL8139C Fast Ethernet",
        !           213:         { 0x813910ec, 0xffffffff, 0,0, 0x10, 0xff},
        !           214:         RTL8139_IOTYPE, 0x80, RTL8139_CAPS, },
        !           215:        {"RealTek RTL8129 Fast Ethernet", { 0x812910ec, 0xffffffff,},
        !           216:         RTL8139_IOTYPE, 0x80, RTL8129_CAPS, },
        !           217:        {"RealTek RTL8139 Fast Ethernet", { 0x813910ec, 0xffffffff,},
        !           218:         RTL8139_IOTYPE, 0x80, RTL8139_CAPS, },
        !           219:        {"RealTek RTL8139B PCI/CardBus",  { 0x813810ec, 0xffffffff,},
        !           220:         RTL8139_IOTYPE, 0x80, RTL8139_CAPS, },
        !           221:        {"SMC1211TX EZCard 10/100 (RealTek RTL8139)", { 0x12111113, 0xffffffff,},
        !           222:         RTL8139_IOTYPE, 0x80, RTL8139_CAPS, },
        !           223:        {"Accton MPX5030 (RealTek RTL8139)", { 0x12111113, 0xffffffff,},
        !           224:         RTL8139_IOTYPE, 0x80, RTL8139_CAPS, },
        !           225:        {"D-Link DFE-530TX+ (RealTek RTL8139C)",
        !           226:         { 0x13001186, 0xffffffff, 0x13011186, 0xffffffff,},
        !           227:         RTL8139_IOTYPE, 0x100, RTL8139_CAPS, },
        !           228:        {"D-Link DFE-538TX (RealTek RTL8139)", { 0x13001186, 0xffffffff,},
        !           229:         RTL8139_IOTYPE, 0x80, RTL8139_CAPS, },
        !           230:        {"LevelOne FPC-0106Tx (RealTek RTL8139)", { 0x0106018a, 0xffffffff,},
        !           231:         RTL8139_IOTYPE, 0x80, RTL8139_CAPS, },
        !           232:        {"Compaq HNE-300 (RealTek RTL8139c)", { 0x8139021b, 0xffffffff,},
        !           233:         RTL8139_IOTYPE, 0x80, RTL8139_CAPS, },
        !           234:        {"Edimax EP-4103DL CardBus (RealTek RTL8139c)", { 0xab0613d1, 0xffffffff,},
        !           235:         RTL8139_IOTYPE, 0x80, RTL8139_CAPS, },
        !           236:        {"Siemens 1012v2 CardBus (RealTek RTL8139c)", { 0x101202ac, 0xffffffff,},
        !           237:         RTL8139_IOTYPE, 0x80, RTL8139_CAPS, },
        !           238:        {0,},                                           /* 0 terminated list. */
        !           239: };
        !           240: 
        !           241: struct drv_id_info rtl8139_drv_id = {
        !           242:        "realtek", PCI_HOTSWAP, PCI_CLASS_NETWORK_ETHERNET<<8, pci_tbl,
        !           243:        rtl8139_probe1, rtl_pwr_event };
        !           244: 
        !           245: #ifndef USE_IO_OPS
        !           246: #undef inb
        !           247: #undef inw
        !           248: #undef inl
        !           249: #undef outb
        !           250: #undef outw
        !           251: #undef outl
        !           252: #define inb readb
        !           253: #define inw readw
        !           254: #define inl readl
        !           255: #define outb writeb
        !           256: #define outw writew
        !           257: #define outl writel
1.1       root      258: #endif
                    259: 
                    260: /* The rest of these values should never change. */
                    261: #define NUM_TX_DESC    4                       /* Number of Tx descriptor registers. */
                    262: 
                    263: /* Symbolic offsets to registers. */
                    264: enum RTL8129_registers {
                    265:        MAC0=0,                                         /* Ethernet hardware address. */
                    266:        MAR0=8,                                         /* Multicast filter. */
1.1.1.3 ! root      267:        TxStatus0=0x10,                         /* Transmit status (Four 32bit registers). */
1.1       root      268:        TxAddr0=0x20,                           /* Tx descriptors (also four 32bit). */
                    269:        RxBuf=0x30, RxEarlyCnt=0x34, RxEarlyStatus=0x36,
                    270:        ChipCmd=0x37, RxBufPtr=0x38, RxBufAddr=0x3A,
                    271:        IntrMask=0x3C, IntrStatus=0x3E,
                    272:        TxConfig=0x40, RxConfig=0x44,
                    273:        Timer=0x48,                                     /* A general-purpose counter. */
                    274:        RxMissed=0x4C,                          /* 24 bits valid, write clears. */
                    275:        Cfg9346=0x50, Config0=0x51, Config1=0x52,
                    276:        FlashReg=0x54, GPPinData=0x58, GPPinDir=0x59, MII_SMI=0x5A, HltClk=0x5B,
                    277:        MultiIntr=0x5C, TxSummary=0x60,
1.1.1.3 ! root      278:        MII_BMCR=0x62, MII_BMSR=0x64, NWayAdvert=0x66, NWayLPAR=0x68,
        !           279:        NWayExpansion=0x6A,
1.1       root      280:        /* Undocumented registers, but required for proper operation. */
1.1.1.3 ! root      281:        FIFOTMS=0x70,   /* FIFO Control and test. */
1.1       root      282:        CSCR=0x74,      /* Chip Status and Configuration Register. */
                    283:        PARA78=0x78, PARA7c=0x7c,       /* Magic transceiver parameter register. */
                    284: };
                    285: 
                    286: enum ChipCmdBits {
                    287:        CmdReset=0x10, CmdRxEnb=0x08, CmdTxEnb=0x04, RxBufEmpty=0x01, };
                    288: 
                    289: /* Interrupt register bits, using my own meaningful names. */
                    290: enum IntrStatusBits {
                    291:        PCIErr=0x8000, PCSTimeout=0x4000,
                    292:        RxFIFOOver=0x40, RxUnderrun=0x20, RxOverflow=0x10,
                    293:        TxErr=0x08, TxOK=0x04, RxErr=0x02, RxOK=0x01,
                    294: };
                    295: enum TxStatusBits {
                    296:        TxHostOwns=0x2000, TxUnderrun=0x4000, TxStatOK=0x8000,
                    297:        TxOutOfWindow=0x20000000, TxAborted=0x40000000, TxCarrierLost=0x80000000,
                    298: };
                    299: enum RxStatusBits {
                    300:        RxMulticast=0x8000, RxPhysical=0x4000, RxBroadcast=0x2000,
                    301:        RxBadSymbol=0x0020, RxRunt=0x0010, RxTooLong=0x0008, RxCRCErr=0x0004,
                    302:        RxBadAlign=0x0002, RxStatusOK=0x0001,
                    303: };
                    304: 
1.1.1.3 ! root      305: /* Twister tuning parameters from RealTek.
        !           306:    Completely undocumented, but required to tune bad links. */
1.1       root      307: enum CSCRBits {
                    308:        CSCR_LinkOKBit=0x0400, CSCR_LinkChangeBit=0x0800,
                    309:        CSCR_LinkStatusBits=0x0f000, CSCR_LinkDownOffCmd=0x003c0,
                    310:        CSCR_LinkDownCmd=0x0f3c0,
1.1.1.3 ! root      311: };
        !           312: #define PARA78_default 0x78fa8388
        !           313: #define PARA7c_default 0xcb38de43                      /* param[0][3] */
        !           314: #define PARA7c_xxx             0xcb38de43
1.1       root      315: unsigned long param[4][4]={
1.1.1.3 ! root      316:        {0xcb39de43, 0xcb39ce43, 0xfb38de03, 0xcb38de43},
        !           317:        {0xcb39de43, 0xcb39ce43, 0xcb39ce83, 0xcb39ce83},
        !           318:        {0xcb39de43, 0xcb39ce43, 0xcb39ce83, 0xcb39ce83},
        !           319:        {0xbb39de43, 0xbb39ce43, 0xbb39ce83, 0xbb39ce83}
1.1       root      320: };
                    321: 
1.1.1.3 ! root      322: #define PRIV_ALIGN     15      /* Desired alignment mask */
1.1       root      323: struct rtl8129_private {
1.1.1.3 ! root      324:        struct net_device *next_module;
        !           325:        void *priv_addr;                                        /* Unaligned address for kfree */
        !           326: 
        !           327:        int chip_id, drv_flags;
        !           328:        struct pci_dev *pci_dev;
1.1       root      329:        struct net_device_stats stats;
                    330:        struct timer_list timer;        /* Media selection timer. */
1.1.1.3 ! root      331:        int msg_level;
        !           332:        int max_interrupt_work;
        !           333: 
        !           334:        /* Receive state. */
        !           335:        unsigned char *rx_ring;
        !           336:        unsigned int cur_rx;            /* Index into the Rx buffer of next Rx pkt. */
        !           337:        unsigned int rx_buf_len;        /* Size (8K 16K 32K or 64KB) of the Rx ring */
        !           338: 
        !           339:        /* Transmit state. */
        !           340:        unsigned int cur_tx, dirty_tx, tx_flag;
        !           341:        unsigned long tx_full;                          /* The Tx queue is full. */
1.1       root      342:        /* The saved address of a sent-in-place packet/buffer, for skfree(). */
                    343:        struct sk_buff* tx_skbuff[NUM_TX_DESC];
                    344:        unsigned char *tx_buf[NUM_TX_DESC];     /* Tx bounce buffers */
                    345:        unsigned char *tx_bufs;                         /* Tx bounce buffer region. */
1.1.1.3 ! root      346: 
        !           347:        /* Receive filter state. */
        !           348:        unsigned int rx_config;
        !           349:        u32 mc_filter[2];                /* Multicast hash filter */
        !           350:        int cur_rx_mode;
        !           351:        int multicast_filter_limit;
        !           352: 
        !           353:        /* Transceiver state. */
1.1       root      354:        char phys[4];                                           /* MII device addresses. */
1.1.1.3 ! root      355:        u16 advertising;                                        /* NWay media advertisement */
        !           356:        char twistie, twist_row, twist_col;     /* Twister tune state. */
        !           357:        u8      config1;
1.1       root      358:        unsigned int full_duplex:1;                     /* Full-duplex operation requested. */
1.1.1.3 ! root      359:        unsigned int duplex_lock:1;
1.1       root      360:        unsigned int media2:4;                          /* Secondary monitored media port. */
                    361:        unsigned int medialock:1;                       /* Don't sense media type. */
                    362:        unsigned int mediasense:1;                      /* Media sensing in progress. */
1.1.1.3 ! root      363:        unsigned int default_port;                      /* Last dev->if_port value. */
1.1       root      364: };
                    365: 
1.1.1.3 ! root      366: MODULE_AUTHOR("Donald Becker <[email protected]>");
1.1       root      367: MODULE_DESCRIPTION("RealTek RTL8129/8139 Fast Ethernet driver");
1.1.1.3 ! root      368: MODULE_LICENSE("GPL");
        !           369: MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i");
        !           370: MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");
        !           371: MODULE_PARM(multicast_filter_limit, "i");
1.1       root      372: MODULE_PARM(max_interrupt_work, "i");
1.1.1.3 ! root      373: MODULE_PARM(debug, "i");
        !           374: MODULE_PARM_DESC(debug, "Driver message level (0-31)");
        !           375: MODULE_PARM_DESC(options, "Force transceiver type or fixed speed+duplex");
        !           376: MODULE_PARM_DESC(full_duplex, "Non-zero to set forced full duplex.");
        !           377: MODULE_PARM_DESC(multicast_filter_limit,
        !           378:                                 "Multicast addresses before switching to Rx-all-multicast");
        !           379: MODULE_PARM_DESC(max_interrupt_work,
        !           380:                                 "Driver maximum events handled per interrupt");
        !           381: 
        !           382: static int rtl8129_open(struct net_device *dev);
        !           383: static void rtl_hw_start(struct net_device *dev);
        !           384: static int read_eeprom(long ioaddr, int location, int addr_len);
        !           385: static int mdio_read(struct net_device *dev, int phy_id, int location);
        !           386: static void mdio_write(struct net_device *dev, int phy_id, int location, int val);
1.1       root      387: static void rtl8129_timer(unsigned long data);
1.1.1.3 ! root      388: static void rtl8129_tx_timeout(struct net_device *dev);
        !           389: static void rtl8129_init_ring(struct net_device *dev);
        !           390: static int rtl8129_start_xmit(struct sk_buff *skb, struct net_device *dev);
        !           391: static int rtl8129_rx(struct net_device *dev);
1.1       root      392: static void rtl8129_interrupt(int irq, void *dev_instance, struct pt_regs *regs);
1.1.1.3 ! root      393: static void rtl_error(struct net_device *dev, int status, int link_status);
        !           394: static int rtl8129_close(struct net_device *dev);
        !           395: static int mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
        !           396: static struct net_device_stats *rtl8129_get_stats(struct net_device *dev);
        !           397: static inline u32 ether_crc(int length, unsigned char *data);
        !           398: static void set_rx_mode(struct net_device *dev);
1.1       root      399: 
                    400: 
                    401: /* A list of all installed RTL8129 devices, for removing the driver module. */
1.1.1.3 ! root      402: static struct net_device *root_rtl8129_dev = NULL;
1.1       root      403: 
1.1.1.3 ! root      404: #ifndef MODULE
        !           405: int rtl8139_probe(struct net_device *dev)
1.1       root      406: {
1.1.1.3 ! root      407:        static int did_version = 0;                     /* Already printed version info. */
1.1       root      408: 
1.1.1.3 ! root      409:        if (debug >= NETIF_MSG_DRV      /* Emit version even if no cards detected. */
        !           410:                &&  did_version++ == 0)
        !           411:                printk(KERN_INFO "%s" KERN_INFO "%s", versionA, versionB);
        !           412:        return pci_drv_register(&rtl8139_drv_id, dev);
1.1       root      413: }
1.1.1.3 ! root      414: #endif
1.1       root      415: 
1.1.1.3 ! root      416: static void *rtl8139_probe1(struct pci_dev *pdev, void *init_dev,
        !           417:                                                        long ioaddr, int irq, int chip_idx, int found_cnt)
1.1       root      418: {
1.1.1.3 ! root      419:        struct net_device *dev;
        !           420:        struct rtl8129_private *np;
        !           421:        void *priv_mem;
        !           422:        int i, option = found_cnt < MAX_UNITS ? options[found_cnt] : 0;
        !           423:        int config1;
        !           424: 
        !           425:        dev = init_etherdev(init_dev, 0);
        !           426:        if (!dev)
        !           427:                return NULL;
1.1       root      428: 
1.1.1.3 ! root      429:        printk(KERN_INFO "%s: %s at %#lx, IRQ %d, ",
        !           430:                   dev->name, pci_tbl[chip_idx].name, ioaddr, irq);
1.1       root      431: 
                    432:        /* Bring the chip out of low-power mode. */
1.1.1.3 ! root      433:        config1 = inb(ioaddr + Config1);
        !           434:        if (pci_tbl[chip_idx].drv_flags & HAS_MII_XCVR)                 /* rtl8129 chip */
        !           435:                outb(config1 & ~0x03, ioaddr + Config1);
        !           436: 
        !           437:        {
        !           438:                int addr_len = read_eeprom(ioaddr, 0, 8) == 0x8129 ? 8 : 6;
        !           439:                for (i = 0; i < 3; i++)
        !           440:                        ((u16 *)(dev->dev_addr))[i] =
        !           441:                                le16_to_cpu(read_eeprom(ioaddr, i+7, addr_len));
        !           442:        }
1.1       root      443: 
                    444:        for (i = 0; i < 5; i++)
                    445:                printk("%2.2x:", dev->dev_addr[i]);
                    446:        printk("%2.2x.\n", dev->dev_addr[i]);
                    447: 
1.1.1.3 ! root      448:        /* Make certain elements e.g. descriptor lists are aligned. */
        !           449:        priv_mem = kmalloc(sizeof(*np) + PRIV_ALIGN, GFP_KERNEL);
        !           450:        /* Check for the very unlikely case of no memory. */
        !           451:        if (priv_mem == NULL)
        !           452:                return NULL;
1.1       root      453: 
                    454:        /* We do a request_region() to register /proc/ioports info. */
1.1.1.3 ! root      455:        request_region(ioaddr, pci_tbl[chip_idx].io_size, dev->name);
1.1       root      456: 
                    457:        dev->base_addr = ioaddr;
                    458:        dev->irq = irq;
                    459: 
1.1.1.3 ! root      460:        dev->priv = np = (void *)(((long)priv_mem + PRIV_ALIGN) & ~PRIV_ALIGN);
        !           461:        memset(np, 0, sizeof(*np));
        !           462:        np->priv_addr = priv_mem;
1.1       root      463: 
1.1.1.3 ! root      464:        np->next_module = root_rtl8129_dev;
1.1       root      465:        root_rtl8129_dev = dev;
                    466: 
1.1.1.3 ! root      467:        np->pci_dev = pdev;
        !           468:        np->chip_id = chip_idx;
        !           469:        np->drv_flags = pci_tbl[chip_idx].drv_flags;
        !           470:        np->msg_level = (1 << debug) - 1;
        !           471:        np->max_interrupt_work = max_interrupt_work;
        !           472:        np->multicast_filter_limit = multicast_filter_limit;
        !           473: 
        !           474:        np->config1 = config1;
1.1       root      475: 
                    476:        /* Find the connected MII xcvrs.
                    477:           Doing this in open() would allow detecting external xcvrs later, but
                    478:           takes too much time. */
1.1.1.3 ! root      479:        if (np->drv_flags & HAS_MII_XCVR) {
        !           480:                int phy, phy_idx = 0;
        !           481:                for (phy = 0; phy < 32 && phy_idx < sizeof(np->phys); phy++) {
        !           482:                        int mii_status = mdio_read(dev, phy, 1);
        !           483:                        if (mii_status != 0xffff  &&  mii_status != 0x0000) {
        !           484:                                np->phys[phy_idx++] = phy;
        !           485:                                np->advertising = mdio_read(dev, phy, 4);
        !           486:                                printk(KERN_INFO "%s: MII transceiver %d status 0x%4.4x "
        !           487:                                           "advertising %4.4x.\n",
        !           488:                                           dev->name, phy, mii_status, np->advertising);
1.1       root      489:                        }
                    490:                }
                    491:                if (phy_idx == 0) {
                    492:                        printk(KERN_INFO "%s: No MII transceivers found!  Assuming SYM "
                    493:                                   "transceiver.\n",
                    494:                                   dev->name);
1.1.1.3 ! root      495:                        np->phys[0] = 32;
1.1       root      496:                }
1.1.1.3 ! root      497:        } else
        !           498:                np->phys[0] = 32;
1.1       root      499: 
                    500:        /* Put the chip into low-power mode. */
                    501:        outb(0xC0, ioaddr + Cfg9346);
1.1.1.3 ! root      502:        if (np->drv_flags & HAS_MII_XCVR)                       /* rtl8129 chip */
        !           503:                outb(0x03, ioaddr + Config1);
        !           504: 
1.1       root      505:        outb('H', ioaddr + HltClk);             /* 'R' would leave the clock running. */
                    506: 
                    507:        /* The lower four bits are the media type. */
1.1.1.3 ! root      508:        if (option > 0) {
        !           509:                np->full_duplex = (option & 0x220) ? 1 : 0;
        !           510:                np->default_port = option & 0x330;
        !           511:                if (np->default_port)
        !           512:                        np->medialock = 1;
        !           513:        }
        !           514: 
        !           515:        if (found_cnt < MAX_UNITS  &&  full_duplex[found_cnt] > 0)
        !           516:                np->full_duplex = full_duplex[found_cnt];
        !           517: 
        !           518:        if (np->full_duplex) {
        !           519:                printk(KERN_INFO "%s: Media type forced to Full Duplex.\n", dev->name);
        !           520:                /* Changing the MII-advertised media might prevent re-connection. */
        !           521:                np->duplex_lock = 1;
        !           522:        }
        !           523:        if (np->default_port) {
        !           524:                printk(KERN_INFO "  Forcing %dMbs %s-duplex operation.\n",
        !           525:                           (option & 0x300 ? 100 : 10),
        !           526:                           (option & 0x220 ? "full" : "half"));
        !           527:                mdio_write(dev, np->phys[0], 0,
        !           528:                                   ((option & 0x300) ? 0x2000 : 0) |    /* 100mbps? */
        !           529:                                   ((option & 0x220) ? 0x0100 : 0)); /* Full duplex? */
1.1       root      530:        }
                    531: 
1.1.1.3 ! root      532:        /* The rtl81x9-specific entries in the device structure. */
1.1       root      533:        dev->open = &rtl8129_open;
                    534:        dev->hard_start_xmit = &rtl8129_start_xmit;
                    535:        dev->stop = &rtl8129_close;
                    536:        dev->get_stats = &rtl8129_get_stats;
                    537:        dev->set_multicast_list = &set_rx_mode;
1.1.1.3 ! root      538:        dev->do_ioctl = &mii_ioctl;
1.1       root      539: 
                    540:        return dev;
                    541: }
                    542: 
                    543: /* Serial EEPROM section. */
                    544: 
                    545: /*  EEPROM_Ctrl bits. */
                    546: #define EE_SHIFT_CLK   0x04    /* EEPROM shift clock. */
                    547: #define EE_CS                  0x08    /* EEPROM chip select. */
                    548: #define EE_DATA_WRITE  0x02    /* EEPROM chip data in. */
                    549: #define EE_WRITE_0             0x00
                    550: #define EE_WRITE_1             0x02
                    551: #define EE_DATA_READ   0x01    /* EEPROM chip data out. */
                    552: #define EE_ENB                 (0x80 | EE_CS)
                    553: 
                    554: /* Delay between EEPROM clock transitions.
1.1.1.3 ! root      555:    No extra delay is needed with 33Mhz PCI, but 66Mhz may change this.
1.1       root      556:  */
                    557: 
1.1.1.3 ! root      558: #define eeprom_delay() inl(ee_addr)
1.1       root      559: 
                    560: /* The EEPROM commands include the alway-set leading bit. */
1.1.1.3 ! root      561: #define EE_WRITE_CMD   (5)
        !           562: #define EE_READ_CMD            (6)
        !           563: #define EE_ERASE_CMD   (7)
1.1       root      564: 
1.1.1.3 ! root      565: static int read_eeprom(long ioaddr, int location, int addr_len)
1.1       root      566: {
                    567:        int i;
                    568:        unsigned retval = 0;
1.1.1.3 ! root      569:        long ee_addr = ioaddr + Cfg9346;
        !           570:        int read_cmd = location | (EE_READ_CMD << addr_len);
1.1       root      571: 
                    572:        outb(EE_ENB & ~EE_CS, ee_addr);
                    573:        outb(EE_ENB, ee_addr);
                    574: 
                    575:        /* Shift the read command bits out. */
1.1.1.3 ! root      576:        for (i = 4 + addr_len; i >= 0; i--) {
1.1       root      577:                int dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
                    578:                outb(EE_ENB | dataval, ee_addr);
1.1.1.3 ! root      579:                eeprom_delay();
1.1       root      580:                outb(EE_ENB | dataval | EE_SHIFT_CLK, ee_addr);
1.1.1.3 ! root      581:                eeprom_delay();
1.1       root      582:        }
                    583:        outb(EE_ENB, ee_addr);
1.1.1.3 ! root      584:        eeprom_delay();
1.1       root      585: 
                    586:        for (i = 16; i > 0; i--) {
                    587:                outb(EE_ENB | EE_SHIFT_CLK, ee_addr);
1.1.1.3 ! root      588:                eeprom_delay();
1.1       root      589:                retval = (retval << 1) | ((inb(ee_addr) & EE_DATA_READ) ? 1 : 0);
                    590:                outb(EE_ENB, ee_addr);
1.1.1.3 ! root      591:                eeprom_delay();
1.1       root      592:        }
                    593: 
                    594:        /* Terminate the EEPROM access. */
                    595:        outb(~EE_CS, ee_addr);
                    596:        return retval;
                    597: }
                    598: 
                    599: /* MII serial management: mostly bogus for now. */
                    600: /* Read and write the MII management registers using software-generated
                    601:    serial MDIO protocol.
                    602:    The maximum data clock rate is 2.5 Mhz.  The minimum timing is usually
                    603:    met by back-to-back PCI I/O cycles, but we insert a delay to avoid
                    604:    "overclocking" issues. */
                    605: #define MDIO_DIR               0x80
                    606: #define MDIO_DATA_OUT  0x04
                    607: #define MDIO_DATA_IN   0x02
                    608: #define MDIO_CLK               0x01
1.1.1.3 ! root      609: #define MDIO_WRITE0 (MDIO_DIR)
        !           610: #define MDIO_WRITE1 (MDIO_DIR | MDIO_DATA_OUT)
        !           611: 
        !           612: #define mdio_delay(mdio_addr)  inb(mdio_addr)
        !           613: 
        !           614: static char mii_2_8139_map[8] = {MII_BMCR, MII_BMSR, 0, 0, NWayAdvert,
        !           615:                                                                 NWayLPAR, NWayExpansion, 0 };
1.1       root      616: 
                    617: /* Syncronize the MII management interface by shifting 32 one bits out. */
1.1.1.3 ! root      618: static void mdio_sync(long mdio_addr)
1.1       root      619: {
                    620:        int i;
                    621: 
                    622:        for (i = 32; i >= 0; i--) {
1.1.1.3 ! root      623:                outb(MDIO_WRITE1, mdio_addr);
        !           624:                mdio_delay(mdio_addr);
        !           625:                outb(MDIO_WRITE1 | MDIO_CLK, mdio_addr);
        !           626:                mdio_delay(mdio_addr);
1.1       root      627:        }
                    628:        return;
                    629: }
1.1.1.3 ! root      630: static int mdio_read(struct net_device *dev, int phy_id, int location)
1.1       root      631: {
1.1.1.3 ! root      632:        long mdio_addr = dev->base_addr + MII_SMI;
        !           633:        int mii_cmd = (0xf6 << 10) | (phy_id << 5) | location;
1.1       root      634:        int retval = 0;
1.1.1.3 ! root      635:        int i;
1.1       root      636: 
1.1.1.3 ! root      637:        if (phy_id > 31) {      /* Really a 8139.  Use internal registers. */
        !           638:                return location < 8 && mii_2_8139_map[location] ?
        !           639:                        inw(dev->base_addr + mii_2_8139_map[location]) : 0;
        !           640:        }
        !           641:        mdio_sync(mdio_addr);
1.1       root      642:        /* Shift the read command bits out. */
                    643:        for (i = 15; i >= 0; i--) {
1.1.1.3 ! root      644:                int dataval = (mii_cmd & (1 << i)) ? MDIO_DATA_OUT : 0;
1.1       root      645: 
                    646:                outb(MDIO_DIR | dataval, mdio_addr);
1.1.1.3 ! root      647:                mdio_delay(mdio_addr);
1.1       root      648:                outb(MDIO_DIR | dataval | MDIO_CLK, mdio_addr);
1.1.1.3 ! root      649:                mdio_delay(mdio_addr);
1.1       root      650:        }
                    651: 
                    652:        /* Read the two transition, 16 data, and wire-idle bits. */
                    653:        for (i = 19; i > 0; i--) {
                    654:                outb(0, mdio_addr);
1.1.1.3 ! root      655:                mdio_delay(mdio_addr);
1.1       root      656:                retval = (retval << 1) | ((inb(mdio_addr) & MDIO_DATA_IN) ? 1 : 0);
                    657:                outb(MDIO_CLK, mdio_addr);
1.1.1.3 ! root      658:                mdio_delay(mdio_addr);
1.1       root      659:        }
                    660:        return (retval>>1) & 0xffff;
                    661: }
1.1.1.3 ! root      662: 
        !           663: static void mdio_write(struct net_device *dev, int phy_id, int location,
        !           664:                                           int value)
1.1       root      665: {
1.1.1.3 ! root      666:        long mdio_addr = dev->base_addr + MII_SMI;
        !           667:        int mii_cmd = (0x5002 << 16) | (phy_id << 23) | (location<<18) | value;
1.1       root      668:        int i;
                    669: 
1.1.1.3 ! root      670:        if (phy_id > 31) {      /* Really a 8139.  Use internal registers. */
        !           671:                long ioaddr = dev->base_addr;
        !           672:                if (location == 0) {
        !           673:                        outb(0xC0, ioaddr + Cfg9346);
        !           674:                        outw(value, ioaddr + MII_BMCR);
        !           675:                        outb(0x00, ioaddr + Cfg9346);
        !           676:                } else if (location < 8  &&  mii_2_8139_map[location])
        !           677:                        outw(value, ioaddr + mii_2_8139_map[location]);
        !           678:                return;
        !           679:        }
        !           680:        mdio_sync(mdio_addr);
1.1       root      681: 
1.1.1.3 ! root      682:        /* Shift the command bits out. */
        !           683:        for (i = 31; i >= 0; i--) {
        !           684:                int dataval = (mii_cmd & (1 << i)) ? MDIO_WRITE1 : MDIO_WRITE0;
        !           685:                outb(dataval, mdio_addr);
        !           686:                mdio_delay(mdio_addr);
        !           687:                outb(dataval | MDIO_CLK, mdio_addr);
        !           688:                mdio_delay(mdio_addr);
        !           689:        }
        !           690:        /* Clear out extra bits. */
        !           691:        for (i = 2; i > 0; i--) {
        !           692:                outb(0, mdio_addr);
        !           693:                mdio_delay(mdio_addr);
        !           694:                outb(MDIO_CLK, mdio_addr);
        !           695:                mdio_delay(mdio_addr);
1.1       root      696:        }
1.1.1.3 ! root      697:        return;
        !           698: }
        !           699: 
        !           700: 
        !           701: static int rtl8129_open(struct net_device *dev)
        !           702: {
        !           703:        struct rtl8129_private *tp = (struct rtl8129_private *)dev->priv;
        !           704:        long ioaddr = dev->base_addr;
        !           705:        int rx_buf_len_idx;
1.1       root      706: 
                    707:        MOD_INC_USE_COUNT;
                    708: 
1.1.1.3 ! root      709:        /* The Rx ring allocation size is 2^N + delta, which is worst-case for
        !           710:           the kernel binary-buddy allocation.  We allocate the Tx bounce buffers
        !           711:           at the same time to use some of the otherwise wasted space.
        !           712:           The delta of +16 is required for dribble-over because the receiver does
        !           713:           not wrap when the packet terminates just beyond the end of the ring. */
        !           714:        rx_buf_len_idx = RX_BUF_LEN_IDX;
        !           715:        do {
        !           716:                tp->rx_buf_len = 8192 << rx_buf_len_idx;
        !           717:                tp->rx_ring = kmalloc(tp->rx_buf_len + 16 +
        !           718:                                                          (TX_BUF_SIZE * NUM_TX_DESC), GFP_KERNEL);
        !           719:        } while (tp->rx_ring == NULL  &&  --rx_buf_len_idx >= 0);
        !           720: 
        !           721:        if (tp->rx_ring == NULL) {
        !           722:                if (debug > 0)
1.1       root      723:                        printk(KERN_ERR "%s: Couldn't allocate a %d byte receive ring.\n",
1.1.1.3 ! root      724:                                   dev->name, tp->rx_buf_len);
        !           725:                MOD_DEC_USE_COUNT;
1.1       root      726:                return -ENOMEM;
                    727:        }
1.1.1.3 ! root      728:        tp->tx_bufs = tp->rx_ring + tp->rx_buf_len + 16;
        !           729: 
1.1       root      730:        rtl8129_init_ring(dev);
1.1.1.3 ! root      731:        tp->full_duplex = tp->duplex_lock;
        !           732:        tp->tx_flag = (TX_FIFO_THRESH<<11) & 0x003f0000;
        !           733:        tp->rx_config =
        !           734:                (RX_FIFO_THRESH << 13) | (rx_buf_len_idx << 11) | (RX_DMA_BURST<<8);
1.1       root      735: 
1.1.1.3 ! root      736:        if (request_irq(dev->irq, &rtl8129_interrupt, SA_SHIRQ, dev->name, dev)) {
        !           737:                MOD_DEC_USE_COUNT;
        !           738:                return -EAGAIN;
        !           739:        }
        !           740: 
        !           741:        rtl_hw_start(dev);
        !           742:        netif_start_tx_queue(dev);
        !           743: 
        !           744:        if (tp->msg_level & NETIF_MSG_IFUP)
        !           745:                printk(KERN_DEBUG"%s: rtl8129_open() ioaddr %#lx IRQ %d"
        !           746:                           " GP Pins %2.2x %s-duplex.\n",
        !           747:                           dev->name, ioaddr, dev->irq, inb(ioaddr + GPPinData),
        !           748:                           tp->full_duplex ? "full" : "half");
        !           749: 
        !           750:        /* Set the timer to switch to check for link beat and perhaps switch
        !           751:           to an alternate media type. */
        !           752:        init_timer(&tp->timer);
        !           753:        tp->timer.expires = jiffies + 3*HZ;
        !           754:        tp->timer.data = (unsigned long)dev;
        !           755:        tp->timer.function = &rtl8129_timer;
        !           756:        add_timer(&tp->timer);
        !           757: 
        !           758:        return 0;
        !           759: }
        !           760: 
        !           761: /* Start the hardware at open or resume. */
        !           762: static void rtl_hw_start(struct net_device *dev)
        !           763: {
        !           764:        struct rtl8129_private *tp = (struct rtl8129_private *)dev->priv;
        !           765:        long ioaddr = dev->base_addr;
        !           766:        int i;
        !           767: 
        !           768:        /* Soft reset the chip. */
        !           769:        outb(CmdReset, ioaddr + ChipCmd);
1.1       root      770:        /* Check that the chip has finished the reset. */
                    771:        for (i = 1000; i > 0; i--)
                    772:                if ((inb(ioaddr + ChipCmd) & CmdReset) == 0)
                    773:                        break;
1.1.1.3 ! root      774:        /* Restore our idea of the MAC address. */
        !           775:        outb(0xC0, ioaddr + Cfg9346);
        !           776:        outl(cpu_to_le32(*(u32*)(dev->dev_addr + 0)), ioaddr + MAC0 + 0);
        !           777:        outl(cpu_to_le32(*(u32*)(dev->dev_addr + 4)), ioaddr + MAC0 + 4);
1.1       root      778: 
1.1.1.3 ! root      779:        /* Hmmm, do these belong here? */
        !           780:        tp->cur_rx = 0;
1.1       root      781: 
                    782:        /* Must enable Tx/Rx before setting transfer thresholds! */
                    783:        outb(CmdRxEnb | CmdTxEnb, ioaddr + ChipCmd);
1.1.1.3 ! root      784:        outl(tp->rx_config, ioaddr + RxConfig);
        !           785:        /* Check this value: the documentation contradicts ifself.  Is the
        !           786:           IFG correct with bit 28:27 zero, or with |0x03000000 ? */
        !           787:        outl((TX_DMA_BURST<<8), ioaddr + TxConfig);
        !           788: 
        !           789:        /* This is check_duplex() */
        !           790:        if (tp->phys[0] >= 0  ||  (tp->drv_flags & HAS_MII_XCVR)) {
        !           791:                u16 mii_reg5 = mdio_read(dev, tp->phys[0], 5);
1.1       root      792:                if (mii_reg5 == 0xffff)
                    793:                        ;                                       /* Not there */
                    794:                else if ((mii_reg5 & 0x0100) == 0x0100
                    795:                                 || (mii_reg5 & 0x00C0) == 0x0040)
1.1.1.3 ! root      796:                        tp->full_duplex = 1;
        !           797:                if (tp->msg_level & NETIF_MSG_LINK)
1.1       root      798:                        printk(KERN_INFO"%s: Setting %s%s-duplex based on"
                    799:                                   " auto-negotiated partner ability %4.4x.\n", dev->name,
                    800:                                   mii_reg5 == 0 ? "" :
                    801:                                   (mii_reg5 & 0x0180) ? "100mbps " : "10mbps ",
1.1.1.3 ! root      802:                                   tp->full_duplex ? "full" : "half", mii_reg5);
1.1       root      803:        }
                    804: 
1.1.1.3 ! root      805:        if (tp->drv_flags & HAS_MII_XCVR)                       /* rtl8129 chip */
        !           806:                outb(tp->full_duplex ? 0x60 : 0x20, ioaddr + Config1);
1.1       root      807:        outb(0x00, ioaddr + Cfg9346);
                    808: 
                    809:        outl(virt_to_bus(tp->rx_ring), ioaddr + RxBuf);
                    810:        /* Start the chip's Tx and Rx process. */
                    811:        outl(0, ioaddr + RxMissed);
                    812:        set_rx_mode(dev);
                    813:        outb(CmdRxEnb | CmdTxEnb, ioaddr + ChipCmd);
                    814:        /* Enable all known interrupts by setting the interrupt mask. */
                    815:        outw(PCIErr | PCSTimeout | RxUnderrun | RxOverflow | RxFIFOOver
1.1.1.3 ! root      816:                 | TxErr | TxOK | RxErr | RxOK, ioaddr + IntrMask);
1.1       root      817: 
                    818: }
                    819: 
                    820: static void rtl8129_timer(unsigned long data)
                    821: {
1.1.1.3 ! root      822:        struct net_device *dev = (struct net_device *)data;
        !           823:        struct rtl8129_private *np = (struct rtl8129_private *)dev->priv;
        !           824:        long ioaddr = dev->base_addr;
        !           825:        int next_tick = 60*HZ;
        !           826:        int mii_reg5 = mdio_read(dev, np->phys[0], 5);
        !           827: 
        !           828:        if (! np->duplex_lock  &&  mii_reg5 != 0xffff) {
        !           829:                int duplex = (mii_reg5&0x0100) || (mii_reg5 & 0x01C0) == 0x0040;
        !           830:                if (np->full_duplex != duplex) {
        !           831:                        np->full_duplex = duplex;
        !           832:                        printk(KERN_INFO "%s: Using %s-duplex based on MII #%d link"
        !           833:                                   " partner ability of %4.4x.\n", dev->name,
        !           834:                                   np->full_duplex ? "full" : "half", np->phys[0], mii_reg5);
        !           835:                        if (np->drv_flags & HAS_MII_XCVR) {
1.1       root      836:                                outb(0xC0, ioaddr + Cfg9346);
1.1.1.3 ! root      837:                                outb(np->full_duplex ? 0x60 : 0x20, ioaddr + Config1);
1.1       root      838:                                outb(0x00, ioaddr + Cfg9346);
                    839:                        }
1.1.1.3 ! root      840:                }
        !           841:        }
        !           842: #if LINUX_VERSION_CODE < 0x20300
        !           843:        /* Check for bogusness. */
        !           844:        if (inw(ioaddr + IntrStatus) & (TxOK | RxOK)) {
        !           845:                int status = inw(ioaddr + IntrStatus);                  /* Double check */
        !           846:                if (status & (TxOK | RxOK)  &&  ! dev->interrupt) {
        !           847:                        printk(KERN_ERR "%s: RTL8139 Interrupt line blocked, status %x.\n",
        !           848:                                   dev->name, status);
        !           849:                        rtl8129_interrupt(dev->irq, dev, 0);
        !           850:                }
1.1       root      851:        }
1.1.1.3 ! root      852:        if (dev->tbusy  &&  jiffies - dev->trans_start >= 2*TX_TIMEOUT)
        !           853:                rtl8129_tx_timeout(dev);
        !           854: #else
        !           855:        if (netif_queue_paused(dev)  &&
        !           856:                np->cur_tx - np->dirty_tx > 1  &&
        !           857:                (jiffies - dev->trans_start) > TX_TIMEOUT) {
        !           858:                rtl8129_tx_timeout(dev);
        !           859:        }
        !           860: #endif
        !           861: 
        !           862: #if defined(RTL_TUNE_TWISTER)
        !           863:        /* This is a complicated state machine to configure the "twister" for
        !           864:           impedance/echos based on the cable length.
        !           865:           All of this is magic and undocumented.
        !           866:           */
        !           867:        if (np->twistie) switch(np->twistie) {
        !           868:        case 1: {
        !           869:                if (inw(ioaddr + CSCR) & CSCR_LinkOKBit) {
        !           870:                        /* We have link beat, let us tune the twister. */
        !           871:                        outw(CSCR_LinkDownOffCmd, ioaddr + CSCR);
        !           872:                        np->twistie = 2;        /* Change to state 2. */
        !           873:                        next_tick = HZ/10;
        !           874:                } else {
        !           875:                        /* Just put in some reasonable defaults for when beat returns. */
        !           876:                        outw(CSCR_LinkDownCmd, ioaddr + CSCR);
        !           877:                        outl(0x20,ioaddr + FIFOTMS);    /* Turn on cable test mode. */
        !           878:                        outl(PARA78_default ,ioaddr + PARA78);
        !           879:                        outl(PARA7c_default ,ioaddr + PARA7c);
        !           880:                        np->twistie = 0;        /* Bail from future actions. */
        !           881:                }
        !           882:        } break;
        !           883:        case 2: {
        !           884:                /* Read how long it took to hear the echo. */
        !           885:                int linkcase = inw(ioaddr + CSCR) & CSCR_LinkStatusBits;
        !           886:                if (linkcase == 0x7000) np->twist_row = 3;
        !           887:                else if (linkcase == 0x3000) np->twist_row = 2;
        !           888:                else if (linkcase == 0x1000) np->twist_row = 1;
        !           889:                else np->twist_row = 0;
        !           890:                np->twist_col = 0;
        !           891:                np->twistie = 3;        /* Change to state 2. */
        !           892:                next_tick = HZ/10;
        !           893:        } break;
        !           894:        case 3: {
        !           895:                /* Put out four tuning parameters, one per 100msec. */
        !           896:                if (np->twist_col == 0) outw(0, ioaddr + FIFOTMS);
        !           897:                outl(param[(int)np->twist_row][(int)np->twist_col], ioaddr + PARA7c);
        !           898:                next_tick = HZ/10;
        !           899:                if (++np->twist_col >= 4) {
        !           900:                        /* For short cables we are done.
        !           901:                           For long cables (row == 3) check for mistune. */
        !           902:                        np->twistie = (np->twist_row == 3) ? 4 : 0;
        !           903:                }
        !           904:        } break;
        !           905:        case 4: {
        !           906:                /* Special case for long cables: check for mistune. */
        !           907:                if ((inw(ioaddr + CSCR) & CSCR_LinkStatusBits) == 0x7000) {
        !           908:                        np->twistie = 0;
        !           909:                        break;
        !           910:                } else {
        !           911:                        outl(0xfb38de03, ioaddr + PARA7c);
        !           912:                        np->twistie = 5;
        !           913:                        next_tick = HZ/10;
        !           914:                }
        !           915:        } break;
        !           916:        case 5: {
        !           917:                /* Retune for shorter cable (column 2). */
        !           918:                outl(0x20,ioaddr + FIFOTMS);
        !           919:                outl(PARA78_default,  ioaddr + PARA78);
        !           920:                outl(PARA7c_default,  ioaddr + PARA7c);
        !           921:                outl(0x00,ioaddr + FIFOTMS);
        !           922:                np->twist_row = 2;
        !           923:                np->twist_col = 0;
        !           924:                np->twistie = 3;
        !           925:                next_tick = HZ/10;
        !           926:        } break;
        !           927:        }
        !           928: #endif
        !           929: 
        !           930:        if (np->msg_level & NETIF_MSG_TIMER) {
        !           931:                if (np->drv_flags & HAS_MII_XCVR)
1.1       root      932:                        printk(KERN_DEBUG"%s: Media selection tick, GP pins %2.2x.\n",
                    933:                                   dev->name, inb(ioaddr + GPPinData));
                    934:                else
                    935:                        printk(KERN_DEBUG"%s: Media selection tick, Link partner %4.4x.\n",
                    936:                                   dev->name, inw(ioaddr + NWayLPAR));
1.1.1.3 ! root      937:                printk(KERN_DEBUG"%s:  Other registers are IntMask %4.4x "
        !           938:                           "IntStatus %4.4x RxStatus %4.4x.\n",
1.1       root      939:                           dev->name, inw(ioaddr + IntrMask), inw(ioaddr + IntrStatus),
1.1.1.3 ! root      940:                           (int)inl(ioaddr + RxEarlyStatus));
1.1       root      941:                printk(KERN_DEBUG"%s:  Chip config %2.2x %2.2x.\n",
                    942:                           dev->name, inb(ioaddr + Config0), inb(ioaddr + Config1));
                    943:        }
                    944: 
1.1.1.3 ! root      945:        np->timer.expires = jiffies + next_tick;
        !           946:        add_timer(&np->timer);
1.1       root      947: }
                    948: 
1.1.1.3 ! root      949: static void rtl8129_tx_timeout(struct net_device *dev)
1.1       root      950: {
                    951:        struct rtl8129_private *tp = (struct rtl8129_private *)dev->priv;
1.1.1.3 ! root      952:        long ioaddr = dev->base_addr;
        !           953:        int status = inw(ioaddr + IntrStatus);
        !           954:        int mii_reg, i;
        !           955: 
        !           956:        /* Could be wrapped with if (tp->msg_level & NETIF_MSG_TX_ERR) */
        !           957:        printk(KERN_ERR "%s: Transmit timeout, status %2.2x %4.4x "
        !           958:                   "media %2.2x.\n",
        !           959:                   dev->name, inb(ioaddr + ChipCmd), status, inb(ioaddr + GPPinData));
        !           960: 
        !           961:        if (status & (TxOK | RxOK)) {
        !           962:                printk(KERN_ERR "%s: RTL8139 Interrupt line blocked, status %x.\n",
        !           963:                           dev->name, status);
        !           964:        }
1.1       root      965: 
                    966:        /* Disable interrupts by clearing the interrupt mask. */
                    967:        outw(0x0000, ioaddr + IntrMask);
                    968:        /* Emit info to figure out what went wrong. */
1.1.1.3 ! root      969:        printk(KERN_DEBUG "%s: Tx queue start entry %d  dirty entry %d%s.\n",
        !           970:                   dev->name, tp->cur_tx, tp->dirty_tx, tp->tx_full ? ", full" : "");
1.1       root      971:        for (i = 0; i < NUM_TX_DESC; i++)
1.1.1.3 ! root      972:                printk(KERN_DEBUG "%s:  Tx descriptor %d is %8.8x.%s\n",
        !           973:                           dev->name, i, (int)inl(ioaddr + TxStatus0 + i*4),
1.1       root      974:                           i == tp->dirty_tx % NUM_TX_DESC ? " (queue head)" : "");
1.1.1.3 ! root      975:        printk(KERN_DEBUG "%s: MII #%d registers are:", dev->name, tp->phys[0]);
        !           976:        for (mii_reg = 0; mii_reg < 8; mii_reg++)
        !           977:                printk(" %4.4x", mdio_read(dev, tp->phys[0], mii_reg));
        !           978:        printk(".\n");
        !           979: 
        !           980:        /* Stop a shared interrupt from scavenging while we are. */
        !           981:        tp->dirty_tx = tp->cur_tx = 0;
        !           982:        /* Dump the unsent Tx packets. */
        !           983:        for (i = 0; i < NUM_TX_DESC; i++) {
        !           984:                if (tp->tx_skbuff[i]) {
        !           985:                        dev_free_skb(tp->tx_skbuff[i]);
1.1       root      986:                        tp->tx_skbuff[i] = 0;
1.1.1.3 ! root      987:                        tp->stats.tx_dropped++;
1.1       root      988:                }
                    989:        }
1.1.1.3 ! root      990:        rtl_hw_start(dev);
        !           991:        netif_unpause_tx_queue(dev);
        !           992:        tp->tx_full = 0;
1.1       root      993:        return;
                    994: }
                    995: 
                    996: 
                    997: /* Initialize the Rx and Tx rings, along with various 'dev' bits. */
                    998: static void
1.1.1.3 ! root      999: rtl8129_init_ring(struct net_device *dev)
1.1       root     1000: {
                   1001:        struct rtl8129_private *tp = (struct rtl8129_private *)dev->priv;
                   1002:        int i;
                   1003: 
                   1004:        tp->tx_full = 0;
1.1.1.3 ! root     1005:        tp->dirty_tx = tp->cur_tx = 0;
1.1       root     1006: 
                   1007:        for (i = 0; i < NUM_TX_DESC; i++) {
                   1008:                tp->tx_skbuff[i] = 0;
                   1009:                tp->tx_buf[i] = &tp->tx_bufs[i*TX_BUF_SIZE];
                   1010:        }
                   1011: }
                   1012: 
                   1013: static int
1.1.1.3 ! root     1014: rtl8129_start_xmit(struct sk_buff *skb, struct net_device *dev)
1.1       root     1015: {
                   1016:        struct rtl8129_private *tp = (struct rtl8129_private *)dev->priv;
1.1.1.3 ! root     1017:        long ioaddr = dev->base_addr;
1.1       root     1018:        int entry;
                   1019: 
1.1.1.3 ! root     1020:        if (netif_pause_tx_queue(dev) != 0) {
        !          1021:                /* This watchdog code is redundant with the media monitor timer. */
        !          1022:                if (jiffies - dev->trans_start > TX_TIMEOUT)
        !          1023:                        rtl8129_tx_timeout(dev);
1.1       root     1024:                return 1;
                   1025:        }
                   1026: 
                   1027:        /* Calculate the next Tx descriptor entry. */
                   1028:        entry = tp->cur_tx % NUM_TX_DESC;
                   1029: 
                   1030:        tp->tx_skbuff[entry] = skb;
                   1031:        if ((long)skb->data & 3) {                      /* Must use alignment buffer. */
                   1032:                memcpy(tp->tx_buf[entry], skb->data, skb->len);
                   1033:                outl(virt_to_bus(tp->tx_buf[entry]), ioaddr + TxAddr0 + entry*4);
                   1034:        } else
                   1035:                outl(virt_to_bus(skb->data), ioaddr + TxAddr0 + entry*4);
                   1036:        /* Note: the chip doesn't have auto-pad! */
1.1.1.3 ! root     1037:        outl(tp->tx_flag | (skb->len >= ETH_ZLEN ? skb->len : ETH_ZLEN),
        !          1038:                 ioaddr + TxStatus0 + entry*4);
1.1       root     1039: 
1.1.1.3 ! root     1040:        /* There is a race condition here -- we might read dirty_tx, take an
        !          1041:           interrupt that clears the Tx queue, and only then set tx_full.
        !          1042:           So we do this in two phases. */
        !          1043:        if (++tp->cur_tx - tp->dirty_tx >= NUM_TX_DESC) {
        !          1044:                set_bit(0, &tp->tx_full);
        !          1045:                if (tp->cur_tx - (volatile unsigned int)tp->dirty_tx < NUM_TX_DESC) {
        !          1046:                        clear_bit(0, &tp->tx_full);
        !          1047:                        netif_unpause_tx_queue(dev);
        !          1048:                } else
        !          1049:                        netif_stop_tx_queue(dev);
        !          1050:        } else
        !          1051:                netif_unpause_tx_queue(dev);
1.1       root     1052: 
                   1053:        dev->trans_start = jiffies;
1.1.1.3 ! root     1054:        if (tp->msg_level & NETIF_MSG_TX_QUEUED)
        !          1055:                printk(KERN_DEBUG"%s: Queued Tx packet at %p size %d to slot %d.\n",
        !          1056:                           dev->name, skb->data, (int)skb->len, entry);
1.1       root     1057: 
                   1058:        return 0;
                   1059: }
                   1060: 
                   1061: /* The interrupt handler does all of the Rx thread work and cleans up
                   1062:    after the Tx thread. */
                   1063: static void rtl8129_interrupt(int irq, void *dev_instance, struct pt_regs *regs)
                   1064: {
1.1.1.3 ! root     1065:        struct net_device *dev = (struct net_device *)dev_instance;
        !          1066:        struct rtl8129_private *np = (struct rtl8129_private *)dev->priv;
        !          1067:        struct rtl8129_private *tp = np;
        !          1068:        int boguscnt = np->max_interrupt_work;
        !          1069:        long ioaddr = dev->base_addr;
        !          1070:        int link_changed = 0;           /* Grrr, avoid bogus "uninitialized" warning */
        !          1071: 
        !          1072: #if defined(__i386__)  &&  LINUX_VERSION_CODE < 0x20123
        !          1073:        /* A lock to prevent simultaneous entry bug on Intel SMP machines. */
        !          1074:        if (test_and_set_bit(0, (void*)&dev->interrupt)) {
        !          1075:                printk(KERN_ERR"%s: SMP simultaneous entry of an interrupt handler.\n",
        !          1076:                           dev->name);
        !          1077:                dev->interrupt = 0;     /* Avoid halting machine. */
1.1       root     1078:                return;
                   1079:        }
1.1.1.3 ! root     1080: #endif
1.1       root     1081: 
                   1082:        do {
1.1.1.3 ! root     1083:                int status = inw(ioaddr + IntrStatus);
        !          1084:                /* Acknowledge all of the current interrupt sources ASAP, but
        !          1085:                   an first get an additional status bit from CSCR. */
        !          1086:                if (status & RxUnderrun)
        !          1087:                        link_changed = inw(ioaddr+CSCR) & CSCR_LinkChangeBit;
1.1       root     1088:                outw(status, ioaddr + IntrStatus);
                   1089: 
1.1.1.3 ! root     1090:                if (tp->msg_level & NETIF_MSG_INTR)
1.1       root     1091:                        printk(KERN_DEBUG"%s: interrupt  status=%#4.4x new intstat=%#4.4x.\n",
                   1092:                                   dev->name, status, inw(ioaddr + IntrStatus));
                   1093: 
                   1094:                if ((status & (PCIErr|PCSTimeout|RxUnderrun|RxOverflow|RxFIFOOver
                   1095:                                           |TxErr|TxOK|RxErr|RxOK)) == 0)
                   1096:                        break;
                   1097: 
                   1098:                if (status & (RxOK|RxUnderrun|RxOverflow|RxFIFOOver))/* Rx interrupt */
                   1099:                        rtl8129_rx(dev);
                   1100: 
                   1101:                if (status & (TxOK | TxErr)) {
1.1.1.3 ! root     1102:                        unsigned int dirty_tx = tp->dirty_tx;
1.1       root     1103: 
1.1.1.3 ! root     1104:                        while (tp->cur_tx - dirty_tx > 0) {
1.1       root     1105:                                int entry = dirty_tx % NUM_TX_DESC;
1.1.1.3 ! root     1106:                                int txstatus = inl(ioaddr + TxStatus0 + entry*4);
1.1       root     1107: 
1.1.1.3 ! root     1108:                                if ( ! (txstatus & (TxStatOK | TxUnderrun | TxAborted)))
1.1       root     1109:                                        break;                  /* It still hasn't been Txed */
                   1110: 
                   1111:                                /* Note: TxCarrierLost is always asserted at 100mbps. */
                   1112:                                if (txstatus & (TxOutOfWindow | TxAborted)) {
                   1113:                                        /* There was an major error, log it. */
1.1.1.3 ! root     1114:                                        if (tp->msg_level & NETIF_MSG_TX_ERR)
1.1       root     1115:                                                printk(KERN_NOTICE"%s: Transmit error, Tx status %8.8x.\n",
                   1116:                                                           dev->name, txstatus);
                   1117:                                        tp->stats.tx_errors++;
                   1118:                                        if (txstatus&TxAborted) {
                   1119:                                                tp->stats.tx_aborted_errors++;
1.1.1.3 ! root     1120:                                                outl(TX_DMA_BURST << 8, ioaddr + TxConfig);
1.1       root     1121:                                        }
                   1122:                                        if (txstatus&TxCarrierLost) tp->stats.tx_carrier_errors++;
                   1123:                                        if (txstatus&TxOutOfWindow) tp->stats.tx_window_errors++;
                   1124: #ifdef ETHER_STATS
                   1125:                                        if ((txstatus & 0x0f000000) == 0x0f000000)
                   1126:                                                tp->stats.collisions16++;
                   1127: #endif
                   1128:                                } else {
1.1.1.3 ! root     1129:                                        if (tp->msg_level & NETIF_MSG_TX_DONE)
        !          1130:                                                printk(KERN_DEBUG "%s: Transmit done, Tx status"
        !          1131:                                                           " %8.8x.\n", dev->name, txstatus);
1.1       root     1132:                                        if (txstatus & TxUnderrun) {
1.1.1.3 ! root     1133:                                                /* Add 64 to the Tx FIFO threshold. */
        !          1134:                                                if (tp->tx_flag <  0x00300000)
        !          1135:                                                        tp->tx_flag += 0x00020000;
1.1       root     1136:                                                tp->stats.tx_fifo_errors++;
                   1137:                                        }
                   1138:                                        tp->stats.collisions += (txstatus >> 24) & 15;
                   1139: #if LINUX_VERSION_CODE > 0x20119
                   1140:                                        tp->stats.tx_bytes += txstatus & 0x7ff;
                   1141: #endif
                   1142:                                        tp->stats.tx_packets++;
                   1143:                                }
                   1144: 
                   1145:                                /* Free the original skb. */
1.1.1.3 ! root     1146:                                dev_free_skb_irq(tp->tx_skbuff[entry]);
1.1       root     1147:                                tp->tx_skbuff[entry] = 0;
1.1.1.3 ! root     1148:                                if (test_bit(0, &tp->tx_full)) {
        !          1149:                                        /* The ring is no longer full, clear tbusy. */
        !          1150:                                        clear_bit(0, &tp->tx_full);
        !          1151:                                        netif_resume_tx_queue(dev);
        !          1152:                                }
        !          1153:                                dirty_tx++;
1.1       root     1154:                        }
                   1155: 
                   1156: #ifndef final_version
                   1157:                        if (tp->cur_tx - dirty_tx > NUM_TX_DESC) {
                   1158:                                printk(KERN_ERR"%s: Out-of-sync dirty pointer, %d vs. %d, full=%d.\n",
1.1.1.3 ! root     1159:                                           dev->name, dirty_tx, tp->cur_tx, (int)tp->tx_full);
1.1       root     1160:                                dirty_tx += NUM_TX_DESC;
                   1161:                        }
                   1162: #endif
                   1163:                        tp->dirty_tx = dirty_tx;
                   1164:                }
                   1165: 
                   1166:                /* Check uncommon events with one test. */
                   1167:                if (status & (PCIErr|PCSTimeout |RxUnderrun|RxOverflow|RxFIFOOver
                   1168:                                          |TxErr|RxErr)) {
1.1.1.3 ! root     1169:                        if (status == 0xffff)                   /* Missing chip! */
        !          1170:                                break;
        !          1171:                        rtl_error(dev, status, link_changed);
1.1       root     1172:                }
1.1.1.3 ! root     1173: 
1.1       root     1174:                if (--boguscnt < 0) {
                   1175:                        printk(KERN_WARNING"%s: Too much work at interrupt, "
                   1176:                                   "IntrStatus=0x%4.4x.\n",
                   1177:                                   dev->name, status);
                   1178:                        /* Clear all interrupt sources. */
                   1179:                        outw(0xffff, ioaddr + IntrStatus);
                   1180:                        break;
                   1181:                }
                   1182:        } while (1);
                   1183: 
1.1.1.3 ! root     1184:        if (tp->msg_level & NETIF_MSG_INTR)
1.1       root     1185:                printk(KERN_DEBUG"%s: exiting interrupt, intr_status=%#4.4x.\n",
1.1.1.3 ! root     1186:                           dev->name, inw(ioaddr + IntrStatus));
1.1       root     1187: 
1.1.1.3 ! root     1188: #if defined(__i386__)  &&  LINUX_VERSION_CODE < 0x20123
        !          1189:        clear_bit(0, (void*)&dev->interrupt);
        !          1190: #endif
1.1       root     1191:        return;
                   1192: }
                   1193: 
                   1194: /* The data sheet doesn't describe the Rx ring at all, so I'm guessing at the
                   1195:    field alignments and semantics. */
1.1.1.3 ! root     1196: static int rtl8129_rx(struct net_device *dev)
1.1       root     1197: {
                   1198:        struct rtl8129_private *tp = (struct rtl8129_private *)dev->priv;
1.1.1.3 ! root     1199:        long ioaddr = dev->base_addr;
1.1       root     1200:        unsigned char *rx_ring = tp->rx_ring;
                   1201:        u16 cur_rx = tp->cur_rx;
                   1202: 
1.1.1.3 ! root     1203:        if (tp->msg_level & NETIF_MSG_RX_STATUS)
1.1       root     1204:                printk(KERN_DEBUG"%s: In rtl8129_rx(), current %4.4x BufAddr %4.4x,"
                   1205:                           " free to %4.4x, Cmd %2.2x.\n",
                   1206:                           dev->name, cur_rx, inw(ioaddr + RxBufAddr),
                   1207:                           inw(ioaddr + RxBufPtr), inb(ioaddr + ChipCmd));
                   1208: 
1.1.1.3 ! root     1209:        while ((inb(ioaddr + ChipCmd) & RxBufEmpty) == 0) {
        !          1210:                int ring_offset = cur_rx % tp->rx_buf_len;
        !          1211:                u32 rx_status = le32_to_cpu(*(u32*)(rx_ring + ring_offset));
        !          1212:                int rx_size = rx_status >> 16;                          /* Includes the CRC. */
1.1       root     1213: 
1.1.1.3 ! root     1214:                if (tp->msg_level & NETIF_MSG_RX_STATUS) {
1.1       root     1215:                        int i;
1.1.1.3 ! root     1216:                        printk(KERN_DEBUG"%s:  rtl8129_rx() status %4.4x, size %4.4x,"
        !          1217:                                   " cur %4.4x.\n",
1.1       root     1218:                                   dev->name, rx_status, rx_size, cur_rx);
                   1219:                        printk(KERN_DEBUG"%s: Frame contents ", dev->name);
                   1220:                        for (i = 0; i < 70; i++)
                   1221:                                printk(" %2.2x", rx_ring[ring_offset + i]);
                   1222:                        printk(".\n");
                   1223:                }
1.1.1.3 ! root     1224:                if (rx_status & (RxBadSymbol|RxRunt|RxTooLong|RxCRCErr|RxBadAlign)) {
        !          1225:                        if (tp->msg_level & NETIF_MSG_RX_ERR)
1.1       root     1226:                                printk(KERN_DEBUG"%s: Ethernet frame had errors,"
1.1.1.3 ! root     1227:                                           " status %8.8x.\n", dev->name, rx_status);
        !          1228:                        if (rx_status == 0xffffffff) {
        !          1229:                                printk(KERN_NOTICE"%s: Invalid receive status at ring "
        !          1230:                                           "offset %4.4x\n", dev->name, ring_offset);
        !          1231:                                rx_status = 0;
        !          1232:                        }
        !          1233:                        if (rx_status & RxTooLong) {
        !          1234:                                if (tp->msg_level & NETIF_MSG_DRV)
        !          1235:                                        printk(KERN_NOTICE"%s: Oversized Ethernet frame, status"
        !          1236:                                                   " %4.4x!\n",
        !          1237:                                                   dev->name, rx_status);
        !          1238:                                /* A.C.: The chip hangs here.
        !          1239:                                   This should never occur, which means that we are screwed
        !          1240:                                   when it does.
        !          1241:                                 */
        !          1242:                        }
1.1       root     1243:                        tp->stats.rx_errors++;
                   1244:                        if (rx_status & (RxBadSymbol|RxBadAlign))
                   1245:                                tp->stats.rx_frame_errors++;
                   1246:                        if (rx_status & (RxRunt|RxTooLong)) tp->stats.rx_length_errors++;
                   1247:                        if (rx_status & RxCRCErr) tp->stats.rx_crc_errors++;
                   1248:                        /* Reset the receiver, based on RealTek recommendation. (Bug?) */
                   1249:                        tp->cur_rx = 0;
                   1250:                        outb(CmdTxEnb, ioaddr + ChipCmd);
1.1.1.3 ! root     1251:                        /* A.C.: Reset the multicast list. */
        !          1252:                        set_rx_mode(dev);
1.1       root     1253:                        outb(CmdRxEnb | CmdTxEnb, ioaddr + ChipCmd);
                   1254:                } else {
                   1255:                        /* Malloc up new buffer, compatible with net-2e. */
                   1256:                        /* Omit the four octet CRC from the length. */
                   1257:                        struct sk_buff *skb;
1.1.1.3 ! root     1258:                        int pkt_size = rx_size - 4;
1.1       root     1259: 
1.1.1.3 ! root     1260:                        /* Allocate a common-sized skbuff if we are close. */
        !          1261:                        skb = dev_alloc_skb(1400 < pkt_size && pkt_size < PKT_BUF_SZ-2 ?
        !          1262:                                                                PKT_BUF_SZ : pkt_size + 2);
1.1       root     1263:                        if (skb == NULL) {
                   1264:                                printk(KERN_WARNING"%s: Memory squeeze, deferring packet.\n",
                   1265:                                           dev->name);
                   1266:                                /* We should check that some rx space is free.
                   1267:                                   If not, free one and mark stats->rx_dropped++. */
                   1268:                                tp->stats.rx_dropped++;
                   1269:                                break;
                   1270:                        }
                   1271:                        skb->dev = dev;
                   1272:                        skb_reserve(skb, 2);    /* 16 byte align the IP fields. */
1.1.1.3 ! root     1273:                        if (ring_offset + rx_size > tp->rx_buf_len) {
        !          1274:                                int semi_count = tp->rx_buf_len - ring_offset - 4;
        !          1275:                                /* This could presumably use two calls to copy_and_sum()? */
1.1       root     1276:                                memcpy(skb_put(skb, semi_count), &rx_ring[ring_offset + 4],
                   1277:                                           semi_count);
1.1.1.3 ! root     1278:                                memcpy(skb_put(skb, pkt_size-semi_count), rx_ring,
        !          1279:                                           pkt_size-semi_count);
        !          1280:                                if (tp->msg_level & NETIF_MSG_PKTDATA) {
1.1       root     1281:                                        int i;
                   1282:                                        printk(KERN_DEBUG"%s:  Frame wrap @%d",
                   1283:                                                   dev->name, semi_count);
                   1284:                                        for (i = 0; i < 16; i++)
                   1285:                                                printk(" %2.2x", rx_ring[i]);
                   1286:                                        printk(".\n");
                   1287:                                        memset(rx_ring, 0xcc, 16);
                   1288:                                }
1.1.1.3 ! root     1289:                        } else {
        !          1290:                                eth_copy_and_sum(skb, &rx_ring[ring_offset + 4],
        !          1291:                                                                 pkt_size, 0);
        !          1292:                                skb_put(skb, pkt_size);
        !          1293:                        }
1.1       root     1294:                        skb->protocol = eth_type_trans(skb, dev);
                   1295:                        netif_rx(skb);
                   1296: #if LINUX_VERSION_CODE > 0x20119
1.1.1.3 ! root     1297:                        tp->stats.rx_bytes += pkt_size;
1.1       root     1298: #endif
                   1299:                        tp->stats.rx_packets++;
                   1300:                }
                   1301: 
1.1.1.3 ! root     1302:                cur_rx = (cur_rx + rx_size + 4 + 3) & ~3;
1.1       root     1303:                outw(cur_rx - 16, ioaddr + RxBufPtr);
                   1304:        }
1.1.1.3 ! root     1305:        if (tp->msg_level & NETIF_MSG_RX_STATUS)
1.1       root     1306:                printk(KERN_DEBUG"%s: Done rtl8129_rx(), current %4.4x BufAddr %4.4x,"
                   1307:                           " free to %4.4x, Cmd %2.2x.\n",
                   1308:                           dev->name, cur_rx, inw(ioaddr + RxBufAddr),
                   1309:                           inw(ioaddr + RxBufPtr), inb(ioaddr + ChipCmd));
                   1310:        tp->cur_rx = cur_rx;
                   1311:        return 0;
                   1312: }
                   1313: 
1.1.1.3 ! root     1314: /* Error and abnormal or uncommon events handlers. */
        !          1315: static void rtl_error(struct net_device *dev, int status, int link_changed)
        !          1316: {
        !          1317:        struct rtl8129_private *tp = (struct rtl8129_private *)dev->priv;
        !          1318:        long ioaddr = dev->base_addr;
        !          1319: 
        !          1320:        if (tp->msg_level & NETIF_MSG_LINK)
        !          1321:                printk(KERN_NOTICE"%s: Abnormal interrupt, status %8.8x.\n",
        !          1322:                           dev->name, status);
        !          1323: 
        !          1324:        /* Update the error count. */
        !          1325:        tp->stats.rx_missed_errors += inl(ioaddr + RxMissed);
        !          1326:        outl(0, ioaddr + RxMissed);
        !          1327: 
        !          1328:        if (status & RxUnderrun){
        !          1329:                /* This might actually be a link change event. */
        !          1330:                if ((tp->drv_flags & HAS_LNK_CHNG)  &&  link_changed) {
        !          1331:                        /* Really link-change on new chips. */
        !          1332:                        int lpar = inw(ioaddr + NWayLPAR);
        !          1333:                        int duplex = (lpar&0x0100) || (lpar & 0x01C0) == 0x0040
        !          1334:                                || tp->duplex_lock;
        !          1335:                        /* Do not use MII_BMSR as that clears sticky bit. */
        !          1336:                        if (inw(ioaddr + GPPinData) & 0x0004) {
        !          1337:                                netif_link_down(dev);
        !          1338:                        } else
        !          1339:                                netif_link_up(dev);
        !          1340:                        if (tp->msg_level & NETIF_MSG_LINK)
        !          1341:                                printk(KERN_DEBUG "%s: Link changed, link partner "
        !          1342:                                           "%4.4x new duplex %d.\n",
        !          1343:                                           dev->name, lpar, duplex);
        !          1344:                        tp->full_duplex = duplex;
        !          1345:                        /* Only count as errors with no link change. */
        !          1346:                        status &= ~RxUnderrun;
        !          1347:                } else {
        !          1348:                        /* If this does not work, we will do rtl_hw_start(dev); */
        !          1349:                        outb(CmdTxEnb, ioaddr + ChipCmd);
        !          1350:                        set_rx_mode(dev);       /* Reset the multicast list. */
        !          1351:                        outb(CmdRxEnb | CmdTxEnb, ioaddr + ChipCmd);
        !          1352: 
        !          1353:                        tp->stats.rx_errors++;
        !          1354:                        tp->stats.rx_fifo_errors++;
        !          1355:                }
        !          1356:        }
        !          1357:        
        !          1358:        if (status & (RxOverflow | RxErr | RxFIFOOver)) tp->stats.rx_errors++;
        !          1359:        if (status & (PCSTimeout)) tp->stats.rx_length_errors++;
        !          1360:        if (status & RxFIFOOver) tp->stats.rx_fifo_errors++;
        !          1361:        if (status & RxOverflow) {
        !          1362:                tp->stats.rx_over_errors++;
        !          1363:                tp->cur_rx = inw(ioaddr + RxBufAddr) % tp->rx_buf_len;
        !          1364:                outw(tp->cur_rx - 16, ioaddr + RxBufPtr);
        !          1365:        }
        !          1366:        if (status & PCIErr) {
        !          1367:                u32 pci_cmd_status;
        !          1368:                pci_read_config_dword(tp->pci_dev, PCI_COMMAND, &pci_cmd_status);
        !          1369: 
        !          1370:                printk(KERN_ERR "%s: PCI Bus error %4.4x.\n",
        !          1371:                           dev->name, pci_cmd_status);
        !          1372:        }
        !          1373: }
        !          1374: 
1.1       root     1375: static int
1.1.1.3 ! root     1376: rtl8129_close(struct net_device *dev)
1.1       root     1377: {
1.1.1.3 ! root     1378:        long ioaddr = dev->base_addr;
1.1       root     1379:        struct rtl8129_private *tp = (struct rtl8129_private *)dev->priv;
                   1380:        int i;
                   1381: 
1.1.1.3 ! root     1382:        netif_stop_tx_queue(dev);
1.1       root     1383: 
1.1.1.3 ! root     1384:        if (tp->msg_level & NETIF_MSG_IFDOWN)
1.1       root     1385:                printk(KERN_DEBUG"%s: Shutting down ethercard, status was 0x%4.4x.\n",
                   1386:                           dev->name, inw(ioaddr + IntrStatus));
                   1387: 
                   1388:        /* Disable interrupts by clearing the interrupt mask. */
                   1389:        outw(0x0000, ioaddr + IntrMask);
                   1390: 
                   1391:        /* Stop the chip's Tx and Rx DMA processes. */
                   1392:        outb(0x00, ioaddr + ChipCmd);
                   1393: 
                   1394:        /* Update the error counts. */
                   1395:        tp->stats.rx_missed_errors += inl(ioaddr + RxMissed);
                   1396:        outl(0, ioaddr + RxMissed);
                   1397: 
                   1398:        del_timer(&tp->timer);
                   1399: 
                   1400:        free_irq(dev->irq, dev);
                   1401: 
                   1402:        for (i = 0; i < NUM_TX_DESC; i++) {
                   1403:                if (tp->tx_skbuff[i])
1.1.1.3 ! root     1404:                        dev_free_skb(tp->tx_skbuff[i]);
1.1       root     1405:                tp->tx_skbuff[i] = 0;
                   1406:        }
                   1407:        kfree(tp->rx_ring);
1.1.1.3 ! root     1408:        tp->rx_ring = 0;
1.1       root     1409: 
                   1410:        /* Green! Put the chip in low-power mode. */
                   1411:        outb(0xC0, ioaddr + Cfg9346);
1.1.1.3 ! root     1412:        outb(tp->config1 | 0x03, ioaddr + Config1);
1.1       root     1413:        outb('H', ioaddr + HltClk);             /* 'R' would leave the clock running. */
                   1414: 
                   1415:        MOD_DEC_USE_COUNT;
                   1416: 
                   1417:        return 0;
                   1418: }
                   1419: 
1.1.1.3 ! root     1420: /*
        !          1421:   Handle user-level ioctl() calls.
        !          1422:   We must use two numeric constants as the key because some clueless person
        !          1423:   changed value for the symbolic name.
        !          1424: */
        !          1425: static int mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
        !          1426: {
        !          1427:        struct rtl8129_private *np = (struct rtl8129_private *)dev->priv;
        !          1428:        u16 *data = (u16 *)&rq->ifr_data;
        !          1429:        u32 *data32 = (void *)&rq->ifr_data;
        !          1430: 
        !          1431:        switch(cmd) {
        !          1432:        case 0x8947: case 0x89F0:
        !          1433:                /* SIOCGMIIPHY: Get the address of the PHY in use. */
        !          1434:                data[0] = np->phys[0] & 0x3f;
        !          1435:                /* Fall Through */
        !          1436:        case 0x8948: case 0x89F1:
        !          1437:                /* SIOCGMIIREG: Read the specified MII register. */
        !          1438:                data[3] = mdio_read(dev, data[0], data[1] & 0x1f);
        !          1439:                return 0;
        !          1440:        case 0x8949: case 0x89F2:
        !          1441:                /* SIOCSMIIREG: Write the specified MII register */
        !          1442:                if (!capable(CAP_NET_ADMIN))
        !          1443:                        return -EPERM;
        !          1444:                if (data[0] == np->phys[0]) {
        !          1445:                        u16 value = data[2];
        !          1446:                        switch (data[1]) {
        !          1447:                        case 0:
        !          1448:                                /* Check for autonegotiation on or reset. */
        !          1449:                                np->medialock = (value & 0x9000) ? 0 : 1;
        !          1450:                                if (np->medialock)
        !          1451:                                        np->full_duplex = (value & 0x0100) ? 1 : 0;
        !          1452:                                break;
        !          1453:                        case 4: np->advertising = value; break;
        !          1454:                        }
        !          1455:                }
        !          1456:                mdio_write(dev, data[0], data[1] & 0x1f, data[2]);
        !          1457:                return 0;
        !          1458:        case SIOCGPARAMS:
        !          1459:                data32[0] = np->msg_level;
        !          1460:                data32[1] = np->multicast_filter_limit;
        !          1461:                data32[2] = np->max_interrupt_work;
        !          1462:                data32[3] = 0;                  /* No rx_copybreak, always copy. */
        !          1463:                return 0;
        !          1464:        case SIOCSPARAMS:
        !          1465:                if (!capable(CAP_NET_ADMIN))
        !          1466:                        return -EPERM;
        !          1467:                np->msg_level = data32[0];
        !          1468:                np->multicast_filter_limit = data32[1];
        !          1469:                np->max_interrupt_work = data32[2];
        !          1470:                return 0;
        !          1471:        default:
        !          1472:                return -EOPNOTSUPP;
        !          1473:        }
        !          1474: }
        !          1475: 
        !          1476: static struct net_device_stats *
        !          1477: rtl8129_get_stats(struct net_device *dev)
1.1       root     1478: {
                   1479:        struct rtl8129_private *tp = (struct rtl8129_private *)dev->priv;
1.1.1.3 ! root     1480:        long ioaddr = dev->base_addr;
1.1       root     1481: 
1.1.1.3 ! root     1482:        if (netif_running(dev)) {
1.1       root     1483:                tp->stats.rx_missed_errors += inl(ioaddr + RxMissed);
                   1484:                outl(0, ioaddr + RxMissed);
                   1485:        }
                   1486: 
                   1487:        return &tp->stats;
                   1488: }
                   1489: 
                   1490: /* Set or clear the multicast filter for this adaptor.
1.1.1.3 ! root     1491:    This routine is not state sensitive and need not be SMP locked. */
        !          1492: 
        !          1493: static unsigned const ethernet_polynomial = 0x04c11db7U;
        !          1494: static inline u32 ether_crc(int length, unsigned char *data)
1.1       root     1495: {
1.1.1.3 ! root     1496:        int crc = -1;
        !          1497: 
        !          1498:        while (--length >= 0) {
1.1       root     1499:                unsigned char current_octet = *data++;
                   1500:                int bit;
1.1.1.3 ! root     1501:                for (bit = 0; bit < 8; bit++, current_octet >>= 1)
        !          1502:                        crc = (crc << 1) ^
        !          1503:                                ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0);
1.1       root     1504:        }
                   1505:        return crc;
                   1506: }
                   1507: 
1.1.1.3 ! root     1508: /* Bits in RxConfig. */
        !          1509: enum rx_mode_bits {
        !          1510:        AcceptErr=0x20, AcceptRunt=0x10, AcceptBroadcast=0x08,
        !          1511:        AcceptMulticast=0x04, AcceptMyPhys=0x02, AcceptAllPhys=0x01,
        !          1512: };
        !          1513: 
        !          1514: static void set_rx_mode(struct net_device *dev)
1.1       root     1515: {
                   1516:        struct rtl8129_private *tp = (struct rtl8129_private *)dev->priv;
1.1.1.3 ! root     1517:        long ioaddr = dev->base_addr;
        !          1518:        u32 mc_filter[2];                /* Multicast hash filter */
        !          1519:        int i, rx_mode;
        !          1520: 
        !          1521:        if (tp->msg_level & NETIF_MSG_RXFILTER)
        !          1522:                printk(KERN_DEBUG"%s:   set_rx_mode(%4.4x) done -- Rx config %8.8x.\n",
        !          1523:                           dev->name, dev->flags, (int)inl(ioaddr + RxConfig));
1.1       root     1524: 
1.1.1.3 ! root     1525:        /* Note: do not reorder, GCC is clever about common statements. */
        !          1526:        if (dev->flags & IFF_PROMISC) {
1.1       root     1527:                /* Unconditionally log net taps. */
                   1528:                printk(KERN_NOTICE"%s: Promiscuous mode enabled.\n", dev->name);
1.1.1.3 ! root     1529:                rx_mode = AcceptBroadcast|AcceptMulticast|AcceptMyPhys|AcceptAllPhys;
        !          1530:                mc_filter[1] = mc_filter[0] = 0xffffffff;
        !          1531:        } else if ((dev->mc_count > tp->multicast_filter_limit)
        !          1532:                           || (dev->flags & IFF_ALLMULTI)) {
1.1       root     1533:                /* Too many to filter perfectly -- accept all multicasts. */
1.1.1.3 ! root     1534:                rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys;
        !          1535:                mc_filter[1] = mc_filter[0] = 0xffffffff;
1.1       root     1536:        } else {
                   1537:                struct dev_mc_list *mclist;
1.1.1.3 ! root     1538:                rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys;
        !          1539:                mc_filter[1] = mc_filter[0] = 0;
1.1       root     1540:                for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
                   1541:                         i++, mclist = mclist->next)
1.1.1.3 ! root     1542:                        set_bit(ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26, mc_filter);
1.1       root     1543:        }
1.1.1.3 ! root     1544:        /* We can safely update without stopping the chip. */
        !          1545:        outl(tp->rx_config | rx_mode, ioaddr + RxConfig);
        !          1546:        tp->mc_filter[0] = mc_filter[0];
        !          1547:        tp->mc_filter[1] = mc_filter[1];
        !          1548:        outl(mc_filter[0], ioaddr + MAR0 + 0);
        !          1549:        outl(mc_filter[1], ioaddr + MAR0 + 4);
1.1       root     1550:        return;
                   1551: }
                   1552: 
                   1553: 
1.1.1.3 ! root     1554: static int rtl_pwr_event(void *dev_instance, int event)
        !          1555: {
        !          1556:        struct net_device *dev = dev_instance;
        !          1557:        struct rtl8129_private *np = (struct rtl8129_private *)dev->priv;
        !          1558:        long ioaddr = dev->base_addr;
        !          1559: 
        !          1560:        if (np->msg_level & NETIF_MSG_LINK)
        !          1561:                printk("%s: Handling power event %d.\n", dev->name, event);
        !          1562:        switch(event) {
        !          1563:        case DRV_ATTACH:
        !          1564:                MOD_INC_USE_COUNT;
        !          1565:                break;
        !          1566:        case DRV_SUSPEND:
        !          1567:                netif_device_detach(dev);
        !          1568:                /* Disable interrupts, stop Tx and Rx. */
        !          1569:                outw(0x0000, ioaddr + IntrMask);
        !          1570:                outb(0x00, ioaddr + ChipCmd);
        !          1571:                /* Update the error counts. */
        !          1572:                np->stats.rx_missed_errors += inl(ioaddr + RxMissed);
        !          1573:                outl(0, ioaddr + RxMissed);
        !          1574:                break;
        !          1575:        case DRV_RESUME:
        !          1576:                netif_device_attach(dev);
        !          1577:                rtl_hw_start(dev);
        !          1578:                break;
        !          1579:        case DRV_DETACH: {
        !          1580:                struct net_device **devp, **next;
        !          1581:                if (dev->flags & IFF_UP) {
        !          1582:                        dev_close(dev);
        !          1583:                        dev->flags &= ~(IFF_UP|IFF_RUNNING);
        !          1584:                }
        !          1585:                unregister_netdev(dev);
        !          1586:                release_region(dev->base_addr, pci_tbl[np->chip_id].io_size);
        !          1587: #ifndef USE_IO_OPS
        !          1588:                iounmap((char *)dev->base_addr);
        !          1589: #endif
        !          1590:                for (devp = &root_rtl8129_dev; *devp; devp = next) {
        !          1591:                        next = &((struct rtl8129_private *)(*devp)->priv)->next_module;
        !          1592:                        if (*devp == dev) {
        !          1593:                                *devp = *next;
        !          1594:                                break;
        !          1595:                        }
        !          1596:                }
        !          1597:                if (np->priv_addr)
        !          1598:                        kfree(np->priv_addr);
        !          1599:                kfree(dev);
        !          1600:                MOD_DEC_USE_COUNT;
        !          1601:                break;
        !          1602:        }
        !          1603:        }
1.1       root     1604: 
1.1.1.3 ! root     1605:        return 0;
        !          1606: }
        !          1607: 
        !          1608: #ifdef CARDBUS
        !          1609: 
        !          1610: #include <pcmcia/driver_ops.h>
        !          1611: 
        !          1612: static dev_node_t *rtl8139_attach(dev_locator_t *loc)
1.1       root     1613: {
1.1.1.3 ! root     1614:        struct net_device *dev;
        !          1615:        u16 dev_id;
        !          1616:        u32 pciaddr;
        !          1617:        u8 bus, devfn, irq;
        !          1618:        long hostaddr;
        !          1619:        /* Note: the chip index should match the 8139B pci_tbl[] entry. */
        !          1620:        int chip_idx = 2;
        !          1621: 
        !          1622:        if (loc->bus != LOC_PCI) return NULL;
        !          1623:        bus = loc->b.pci.bus; devfn = loc->b.pci.devfn;
        !          1624:        printk(KERN_DEBUG "rtl8139_attach(bus %d, function %d)\n", bus, devfn);
        !          1625: #ifdef USE_IO_OPS
        !          1626:        pcibios_read_config_dword(bus, devfn, PCI_BASE_ADDRESS_0, &pciaddr);
        !          1627:        hostaddr = pciaddr & PCI_BASE_ADDRESS_IO_MASK;
        !          1628: #else
        !          1629:        pcibios_read_config_dword(bus, devfn, PCI_BASE_ADDRESS_1, &pciaddr);
        !          1630:        hostaddr = (long)ioremap(pciaddr & PCI_BASE_ADDRESS_MEM_MASK,
        !          1631:                                                         pci_tbl[chip_idx].io_size);
        !          1632: #endif
        !          1633:        pcibios_read_config_byte(bus, devfn, PCI_INTERRUPT_LINE, &irq);
        !          1634:        pcibios_read_config_word(bus, devfn, PCI_DEVICE_ID, &dev_id);
        !          1635:        if (hostaddr == 0 || irq == 0) {
        !          1636:                printk(KERN_ERR "The %s interface at %d/%d was not assigned an %s.\n"
        !          1637:                           KERN_ERR "  It will not be activated.\n",
        !          1638:                           pci_tbl[chip_idx].name, bus, devfn,
        !          1639:                           hostaddr == 0 ? "address" : "IRQ");
        !          1640:                return NULL;
        !          1641:        }
        !          1642:        dev = rtl8139_probe1(pci_find_slot(bus, devfn), NULL,
        !          1643:                                                 hostaddr, irq, chip_idx, 0);
        !          1644:        if (dev) {
        !          1645:                dev_node_t *node = kmalloc(sizeof(dev_node_t), GFP_KERNEL);
        !          1646:                strcpy(node->dev_name, dev->name);
        !          1647:                node->major = node->minor = 0;
        !          1648:                node->next = NULL;
        !          1649:                MOD_INC_USE_COUNT;
        !          1650:                return node;
        !          1651:        }
        !          1652:        return NULL;
        !          1653: }
1.1       root     1654: 
1.1.1.3 ! root     1655: static void rtl8139_detach(dev_node_t *node)
        !          1656: {
        !          1657:        struct net_device **devp, **next;
        !          1658:        printk(KERN_INFO "rtl8139_detach(%s)\n", node->dev_name);
        !          1659:        for (devp = &root_rtl8129_dev; *devp; devp = next) {
        !          1660:                next = &((struct rtl8129_private *)(*devp)->priv)->next_module;
        !          1661:                if (strcmp((*devp)->name, node->dev_name) == 0) break;
        !          1662:        }
        !          1663:        if (*devp) {
        !          1664:                struct rtl8129_private *np =
        !          1665:                        (struct rtl8129_private *)(*devp)->priv;
        !          1666:                unregister_netdev(*devp);
        !          1667:                release_region((*devp)->base_addr, pci_tbl[np->chip_id].io_size);
        !          1668: #ifndef USE_IO_OPS
        !          1669:                iounmap((char *)(*devp)->base_addr);
        !          1670: #endif
        !          1671:                kfree(*devp);
        !          1672:                if (np->priv_addr)
        !          1673:                        kfree(np->priv_addr);
        !          1674:                *devp = *next;
        !          1675:                kfree(node);
        !          1676:                MOD_DEC_USE_COUNT;
        !          1677:        }
        !          1678: }
1.1       root     1679: 
1.1.1.3 ! root     1680: struct driver_operations realtek_ops = {
        !          1681:        "realtek_cb",
        !          1682:        rtl8139_attach, /*rtl8139_suspend*/0, /*rtl8139_resume*/0, rtl8139_detach
        !          1683: };
1.1       root     1684: 
1.1.1.3 ! root     1685: #endif  /* Cardbus support */
        !          1686: 
        !          1687: #ifdef MODULE
        !          1688: int init_module(void)
        !          1689: {
        !          1690:        if (debug >= NETIF_MSG_DRV)     /* Emit version even if no cards detected. */
        !          1691:                printk(KERN_INFO "%s" KERN_INFO "%s", versionA, versionB);
        !          1692: #ifdef CARDBUS
        !          1693:        register_driver(&realtek_ops);
        !          1694:        return 0;
        !          1695: #else
        !          1696:        return pci_drv_register(&rtl8139_drv_id, NULL);
        !          1697: #endif
1.1       root     1698: }
                   1699: 
1.1.1.3 ! root     1700: void cleanup_module(void)
1.1       root     1701: {
1.1.1.3 ! root     1702:        struct net_device *next_dev;
        !          1703: 
        !          1704: #ifdef CARDBUS
        !          1705:        unregister_driver(&realtek_ops);
        !          1706: #else
        !          1707:        pci_drv_unregister(&rtl8139_drv_id);
        !          1708: #endif
1.1       root     1709: 
                   1710:        while (root_rtl8129_dev) {
1.1.1.3 ! root     1711:                struct rtl8129_private *np = (void *)(root_rtl8129_dev->priv);
1.1       root     1712:                unregister_netdev(root_rtl8129_dev);
1.1.1.3 ! root     1713:                release_region(root_rtl8129_dev->base_addr,
        !          1714:                                           pci_tbl[np->chip_id].io_size);
        !          1715: #ifndef USE_IO_OPS
        !          1716:                iounmap((char *)(root_rtl8129_dev->base_addr));
        !          1717: #endif
        !          1718:                next_dev = np->next_module;
        !          1719:                if (np->priv_addr)
        !          1720:                        kfree(np->priv_addr);
1.1       root     1721:                kfree(root_rtl8129_dev);
                   1722:                root_rtl8129_dev = next_dev;
                   1723:        }
                   1724: }
                   1725: 
                   1726: #endif  /* MODULE */
                   1727: 
                   1728: /*
                   1729:  * Local variables:
1.1.1.3 ! root     1730:  *  compile-command: "make KERNVER=`uname -r` rtl8139.o"
        !          1731:  *  compile-cmd: "gcc -DMODULE -Wall -Wstrict-prototypes -O6 -c rtl8139.c"
        !          1732:  *  cardbus-compile-command: "gcc -DCARDBUS -DMODULE -Wall -Wstrict-prototypes -O6 -c rtl8139.c -o realtek_cb.o -I/usr/src/pcmcia/include/"
1.1       root     1733:  *  c-indent-level: 4
                   1734:  *  c-basic-offset: 4
                   1735:  *  tab-width: 4
                   1736:  * End:
                   1737:  */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.