linux-bk/drivers/net/tulip/xircom_tulip_cb.c
<<
>>
Prefs
   1/* xircom_tulip_cb.c: A Xircom CBE-100 ethernet driver for Linux. */
   2/*
   3        Written/copyright 1994-1999 by Donald Becker.
   4
   5        This software may be used and distributed according to the terms
   6        of the GNU General Public License, incorporated herein by reference.
   7
   8        The author may be reached as becker@scyld.com, or C/O
   9        Scyld Computing Corporation
  10        410 Severn Ave., Suite 210
  11        Annapolis MD 21403
  12
  13        -----------------------------------------------------------
  14
  15        Linux kernel-specific changes:
  16
  17        LK1.0 (Ion Badulescu)
  18        - Major cleanup
  19        - Use 2.4 PCI API
  20        - Support ethtool
  21        - Rewrite perfect filter/hash code
  22        - Use interrupts for media changes
  23
  24        LK1.1 (Ion Badulescu)
  25        - Disallow negotiation of unsupported full-duplex modes
  26*/
  27
  28#define DRV_NAME        "xircom_tulip_cb"
  29#define DRV_VERSION     "0.91+LK1.1"
  30#define DRV_RELDATE     "October 11, 2001"
  31
  32#define CARDBUS 1
  33
  34/* A few user-configurable values. */
  35
  36/* Maximum events (Rx packets, etc.) to handle at each interrupt. */
  37static int max_interrupt_work = 25;
  38
  39#define MAX_UNITS 4
  40/* Used to pass the full-duplex flag, etc. */
  41static int full_duplex[MAX_UNITS];
  42static int options[MAX_UNITS];
  43static int mtu[MAX_UNITS];                      /* Jumbo MTU for interfaces. */
  44
  45/* Keep the ring sizes a power of two for efficiency.
  46   Making the Tx ring too large decreases the effectiveness of channel
  47   bonding and packet priority.
  48   There are no ill effects from too-large receive rings. */
  49#define TX_RING_SIZE    16
  50#define RX_RING_SIZE    32
  51
  52/* Set the copy breakpoint for the copy-only-tiny-buffer Rx structure. */
  53#ifdef __alpha__
  54static int rx_copybreak = 1518;
  55#else
  56static int rx_copybreak = 100;
  57#endif
  58
  59/*
  60  Set the bus performance register.
  61        Typical: Set 16 longword cache alignment, no burst limit.
  62        Cache alignment bits 15:14           Burst length 13:8
  63                0000    No alignment  0x00000000 unlimited              0800 8 longwords
  64                4000    8  longwords            0100 1 longword         1000 16 longwords
  65                8000    16 longwords            0200 2 longwords        2000 32 longwords
  66                C000    32  longwords           0400 4 longwords
  67        Warning: many older 486 systems are broken and require setting 0x00A04800
  68           8 longword cache alignment, 8 longword burst.
  69        ToDo: Non-Intel setting could be better.
  70*/
  71
  72#if defined(__alpha__) || defined(__ia64__) || defined(__x86_64__)
  73static int csr0 = 0x01A00000 | 0xE000;
  74#elif defined(__powerpc__)
  75static int csr0 = 0x01B00000 | 0x8000;
  76#elif defined(__sparc__)
  77static int csr0 = 0x01B00080 | 0x8000;
  78#elif defined(__i386__)
  79static int csr0 = 0x01A00000 | 0x8000;
  80#else
  81#warning Processor architecture undefined!
  82static int csr0 = 0x00A00000 | 0x4800;
  83#endif
  84
  85/* Operational parameters that usually are not changed. */
  86/* Time in jiffies before concluding the transmitter is hung. */
  87#define TX_TIMEOUT              (4 * HZ)
  88#define PKT_BUF_SZ              1536                    /* Size of each temporary Rx buffer.*/
  89#define PKT_SETUP_SZ            192                     /* Size of the setup frame */
  90
  91/* PCI registers */
  92#define PCI_POWERMGMT   0x40
  93
  94#include <linux/config.h>
  95#include <linux/module.h>
  96#include <linux/kernel.h>
  97#include <linux/pci.h>
  98#include <linux/netdevice.h>
  99#include <linux/etherdevice.h>
 100#include <linux/delay.h>
 101#include <linux/init.h>
 102#include <linux/mii.h>
 103#include <linux/ethtool.h>
 104#include <linux/crc32.h>
 105
 106#include <asm/io.h>
 107#include <asm/processor.h>      /* Processor type for cache alignment. */
 108#include <asm/uaccess.h>
 109
 110
 111/* These identify the driver base version and may not be removed. */
 112static char version[] __devinitdata =
 113KERN_INFO DRV_NAME ".c derived from tulip.c:v0.91 4/14/99 becker@scyld.com\n"
 114KERN_INFO " unofficial 2.4.x kernel port, version " DRV_VERSION ", " DRV_RELDATE "\n";
 115
 116MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
 117MODULE_DESCRIPTION("Xircom CBE-100 ethernet driver");
 118MODULE_LICENSE("GPL v2");
 119
 120MODULE_PARM(debug, "i");
 121MODULE_PARM(max_interrupt_work, "i");
 122MODULE_PARM(rx_copybreak, "i");
 123MODULE_PARM(csr0, "i");
 124MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i");
 125MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");
 126
 127#define RUN_AT(x) (jiffies + (x))
 128
 129#define xircom_debug debug
 130#ifdef XIRCOM_DEBUG
 131static int xircom_debug = XIRCOM_DEBUG;
 132#else
 133static int xircom_debug = 1;
 134#endif
 135
 136/*
 137                                Theory of Operation
 138
 139I. Board Compatibility
 140
 141This device driver was forked from the driver for the DECchip "Tulip",
 142Digital's single-chip ethernet controllers for PCI.  It supports Xircom's
 143almost-Tulip-compatible CBE-100 CardBus adapters.
 144
 145II. Board-specific settings
 146
 147PCI bus devices are configured by the system at boot time, so no jumpers
 148need to be set on the board.  The system BIOS preferably should assign the
 149PCI INTA signal to an otherwise unused system IRQ line.
 150
 151III. Driver operation
 152
 153IIIa. Ring buffers
 154
 155The Xircom can use either ring buffers or lists of Tx and Rx descriptors.
 156This driver uses statically allocated rings of Rx and Tx descriptors, set at
 157compile time by RX/TX_RING_SIZE.  This version of the driver allocates skbuffs
 158for the Rx ring buffers at open() time and passes the skb->data field to the
 159Xircom as receive data buffers.  When an incoming frame is less than
 160RX_COPYBREAK bytes long, a fresh skbuff is allocated and the frame is
 161copied to the new skbuff.  When the incoming frame is larger, the skbuff is
 162passed directly up the protocol stack and replaced by a newly allocated
 163skbuff.
 164
 165The RX_COPYBREAK value is chosen to trade-off the memory wasted by
 166using a full-sized skbuff for small frames vs. the copying costs of larger
 167frames.  For small frames the copying cost is negligible (esp. considering
 168that we are pre-loading the cache with immediately useful header
 169information).  For large frames the copying cost is non-trivial, and the
 170larger copy might flush the cache of useful data.  A subtle aspect of this
 171choice is that the Xircom only receives into longword aligned buffers, thus
 172the IP header at offset 14 isn't longword aligned for further processing.
 173Copied frames are put into the new skbuff at an offset of "+2", thus copying
 174has the beneficial effect of aligning the IP header and preloading the
 175cache.
 176
 177IIIC. Synchronization
 178The driver runs as two independent, single-threaded flows of control.  One
 179is the send-packet routine, which enforces single-threaded use by the
 180dev->tbusy flag.  The other thread is the interrupt handler, which is single
 181threaded by the hardware and other software.
 182
 183The send packet thread has partial control over the Tx ring and 'dev->tbusy'
 184flag.  It sets the tbusy flag whenever it's queuing a Tx packet. If the next
 185queue slot is empty, it clears the tbusy flag when finished otherwise it sets
 186the 'tp->tx_full' flag.
 187
 188The interrupt handler has exclusive control over the Rx ring and records stats
 189from the Tx ring.  (The Tx-done interrupt can't be selectively turned off, so
 190we can't avoid the interrupt overhead by having the Tx routine reap the Tx
 191stats.)  After reaping the stats, it marks the queue entry as empty by setting
 192the 'base' to zero.      Iff the 'tp->tx_full' flag is set, it clears both the
 193tx_full and tbusy flags.
 194
 195IV. Notes
 196
 197IVb. References
 198
 199http://cesdis.gsfc.nasa.gov/linux/misc/NWay.html
 200http://www.digital.com  (search for current 21*4* datasheets and "21X4 SROM")
 201http://www.national.com/pf/DP/DP83840A.html
 202
 203IVc. Errata
 204
 205*/
 206
 207/* A full-duplex map for media types. */
 208enum MediaIs {
 209        MediaIsFD = 1, MediaAlwaysFD=2, MediaIsMII=4, MediaIsFx=8,
 210        MediaIs100=16};
 211static const char media_cap[] =
 212{0,0,0,16,  3,19,16,24,  27,4,7,5, 0,20,23,20 };
 213
 214/* Offsets to the Command and Status Registers, "CSRs".  All accesses
 215   must be longword instructions and quadword aligned. */
 216enum xircom_offsets {
 217        CSR0=0,    CSR1=0x08, CSR2=0x10, CSR3=0x18, CSR4=0x20, CSR5=0x28,
 218        CSR6=0x30, CSR7=0x38, CSR8=0x40, CSR9=0x48, CSR10=0x50, CSR11=0x58,
 219        CSR12=0x60, CSR13=0x68, CSR14=0x70, CSR15=0x78, CSR16=0x04, };
 220
 221/* The bits in the CSR5 status registers, mostly interrupt sources. */
 222enum status_bits {
 223        LinkChange=0x08000000,
 224        NormalIntr=0x10000, NormalIntrMask=0x00014045,
 225        AbnormalIntr=0x8000, AbnormalIntrMask=0x0a00a5a2,
 226        ReservedIntrMask=0xe0001a18,
 227        EarlyRxIntr=0x4000, BusErrorIntr=0x2000,
 228        EarlyTxIntr=0x400, RxDied=0x100, RxNoBuf=0x80, RxIntr=0x40,
 229        TxFIFOUnderflow=0x20, TxNoBuf=0x04, TxDied=0x02, TxIntr=0x01,
 230};
 231
 232enum csr0_control_bits {
 233        EnableMWI=0x01000000, EnableMRL=0x00800000,
 234        EnableMRM=0x00200000, EqualBusPrio=0x02,
 235        SoftwareReset=0x01,
 236};
 237
 238enum csr6_control_bits {
 239        ReceiveAllBit=0x40000000, AllMultiBit=0x80, PromiscBit=0x40,
 240        HashFilterBit=0x01, FullDuplexBit=0x0200,
 241        TxThresh10=0x400000, TxStoreForw=0x200000,
 242        TxThreshMask=0xc000, TxThreshShift=14,
 243        EnableTx=0x2000, EnableRx=0x02,
 244        ReservedZeroMask=0x8d930134, ReservedOneMask=0x320c0000,
 245        EnableTxRx=(EnableTx | EnableRx),
 246};
 247
 248
 249enum tbl_flag {
 250        HAS_MII=1, HAS_ACPI=2,
 251};
 252static struct xircom_chip_table {
 253        char *chip_name;
 254        int valid_intrs;                        /* CSR7 interrupt enable settings */
 255        int flags;
 256} xircom_tbl[] = {
 257  { "Xircom Cardbus Adapter",
 258        LinkChange | NormalIntr | AbnormalIntr | BusErrorIntr |
 259        RxDied | RxNoBuf | RxIntr | TxFIFOUnderflow | TxNoBuf | TxDied | TxIntr,
 260        HAS_MII | HAS_ACPI, },
 261  { NULL, },
 262};
 263/* This matches the table above. */
 264enum chips {
 265        X3201_3,
 266};
 267
 268
 269/* The Xircom Rx and Tx buffer descriptors. */
 270struct xircom_rx_desc {
 271        s32 status;
 272        s32 length;
 273        u32 buffer1, buffer2;
 274};
 275
 276struct xircom_tx_desc {
 277        s32 status;
 278        s32 length;
 279        u32 buffer1, buffer2;                           /* We use only buffer 1.  */
 280};
 281
 282enum tx_desc0_status_bits {
 283        Tx0DescOwned=0x80000000, Tx0DescError=0x8000, Tx0NoCarrier=0x0800,
 284        Tx0LateColl=0x0200, Tx0ManyColl=0x0100, Tx0Underflow=0x02,
 285};
 286enum tx_desc1_status_bits {
 287        Tx1ComplIntr=0x80000000, Tx1LastSeg=0x40000000, Tx1FirstSeg=0x20000000,
 288        Tx1SetupPkt=0x08000000, Tx1DisableCRC=0x04000000, Tx1RingWrap=0x02000000,
 289        Tx1ChainDesc=0x01000000, Tx1NoPad=0x800000, Tx1HashSetup=0x400000,
 290        Tx1WholePkt=(Tx1FirstSeg | Tx1LastSeg),
 291};
 292enum rx_desc0_status_bits {
 293        Rx0DescOwned=0x80000000, Rx0DescError=0x8000, Rx0NoSpace=0x4000,
 294        Rx0Runt=0x0800, Rx0McastPkt=0x0400, Rx0FirstSeg=0x0200, Rx0LastSeg=0x0100,
 295        Rx0HugeFrame=0x80, Rx0CRCError=0x02,
 296        Rx0WholePkt=(Rx0FirstSeg | Rx0LastSeg),
 297};
 298enum rx_desc1_status_bits {
 299        Rx1RingWrap=0x02000000, Rx1ChainDesc=0x01000000,
 300};
 301
 302struct xircom_private {
 303        struct xircom_rx_desc rx_ring[RX_RING_SIZE];
 304        struct xircom_tx_desc tx_ring[TX_RING_SIZE];
 305        /* The saved address of a sent-in-place packet/buffer, for skfree(). */
 306        struct sk_buff* tx_skbuff[TX_RING_SIZE];
 307#ifdef CARDBUS
 308        /* The X3201-3 requires 4-byte aligned tx bufs */
 309        struct sk_buff* tx_aligned_skbuff[TX_RING_SIZE];
 310#endif
 311        /* The addresses of receive-in-place skbuffs. */
 312        struct sk_buff* rx_skbuff[RX_RING_SIZE];
 313        u16 setup_frame[PKT_SETUP_SZ / sizeof(u16)];    /* Pseudo-Tx frame to init address table. */
 314        int chip_id;
 315        struct net_device_stats stats;
 316        unsigned int cur_rx, cur_tx;            /* The next free ring entry */
 317        unsigned int dirty_rx, dirty_tx;        /* The ring entries to be free()ed. */
 318        unsigned int tx_full:1;                         /* The Tx queue is full. */
 319        unsigned int speed100:1;
 320        unsigned int full_duplex:1;                     /* Full-duplex operation requested. */
 321        unsigned int autoneg:1;
 322        unsigned int default_port:4;            /* Last dev->if_port value. */
 323        unsigned int open:1;
 324        unsigned int csr0;                                      /* CSR0 setting. */
 325        unsigned int csr6;                                      /* Current CSR6 control settings. */
 326        u16 to_advertise;                                       /* NWay capabilities advertised.  */
 327        u16 advertising[4];
 328        signed char phys[4], mii_cnt;           /* MII device addresses. */
 329        int saved_if_port;
 330        struct pci_dev *pdev;
 331        spinlock_t lock;
 332};
 333
 334static int mdio_read(struct net_device *dev, int phy_id, int location);
 335static void mdio_write(struct net_device *dev, int phy_id, int location, int value);
 336static void xircom_up(struct net_device *dev);
 337static void xircom_down(struct net_device *dev);
 338static int xircom_open(struct net_device *dev);
 339static void xircom_tx_timeout(struct net_device *dev);
 340static void xircom_init_ring(struct net_device *dev);
 341static int xircom_start_xmit(struct sk_buff *skb, struct net_device *dev);
 342static int xircom_rx(struct net_device *dev);
 343static irqreturn_t xircom_interrupt(int irq, void *dev_instance, struct pt_regs *regs);
 344static int xircom_close(struct net_device *dev);
 345static struct net_device_stats *xircom_get_stats(struct net_device *dev);
 346static int xircom_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
 347static void set_rx_mode(struct net_device *dev);
 348static void check_duplex(struct net_device *dev);
 349
 350
 351/* The Xircom cards are picky about when certain bits in CSR6 can be
 352   manipulated.  Keith Owens <kaos@ocs.com.au>. */
 353static void outl_CSR6(u32 newcsr6, long ioaddr)
 354{
 355        const int strict_bits =
 356                TxThresh10 | TxStoreForw | TxThreshMask | EnableTxRx | FullDuplexBit;
 357    int csr5, csr5_22_20, csr5_19_17, currcsr6, attempts = 200;
 358    unsigned long flags;
 359    save_flags(flags);
 360    cli();
 361        /* mask out the reserved bits that always read 0 on the Xircom cards */
 362        newcsr6 &= ~ReservedZeroMask;
 363        /* or in the reserved bits that always read 1 */
 364        newcsr6 |= ReservedOneMask;
 365    currcsr6 = inl(ioaddr + CSR6);
 366    if (((newcsr6 & strict_bits) == (currcsr6 & strict_bits)) ||
 367        ((currcsr6 & ~EnableTxRx) == 0)) {
 368                outl(newcsr6, ioaddr + CSR6);   /* safe */
 369                restore_flags(flags);
 370                return;
 371    }
 372    /* make sure the transmitter and receiver are stopped first */
 373    currcsr6 &= ~EnableTxRx;
 374    while (1) {
 375                csr5 = inl(ioaddr + CSR5);
 376                if (csr5 == 0xffffffff)
 377                        break;  /* cannot read csr5, card removed? */
 378                csr5_22_20 = csr5 & 0x700000;
 379                csr5_19_17 = csr5 & 0x0e0000;
 380                if ((csr5_22_20 == 0 || csr5_22_20 == 0x600000) &&
 381                        (csr5_19_17 == 0 || csr5_19_17 == 0x80000 || csr5_19_17 == 0xc0000))
 382                        break;  /* both are stopped or suspended */
 383                if (!--attempts) {
 384                        printk(KERN_INFO DRV_NAME ": outl_CSR6 too many attempts,"
 385                                   "csr5=0x%08x\n", csr5);
 386                        outl(newcsr6, ioaddr + CSR6);  /* unsafe but do it anyway */
 387                        restore_flags(flags);
 388                        return;
 389                }
 390                outl(currcsr6, ioaddr + CSR6);
 391                udelay(1);
 392    }
 393    /* now it is safe to change csr6 */
 394    outl(newcsr6, ioaddr + CSR6);
 395    restore_flags(flags);
 396}
 397
 398
 399static void __devinit read_mac_address(struct net_device *dev)
 400{
 401        long ioaddr = dev->base_addr;
 402        int i, j;
 403        unsigned char tuple, link, data_id, data_count;
 404
 405        /* Xircom has its address stored in the CIS;
 406         * we access it through the boot rom interface for now
 407         * this might not work, as the CIS is not parsed but I
 408         * (danilo) use the offset I found on my card's CIS !!!
 409         *
 410         * Doug Ledford: I changed this routine around so that it
 411         * walks the CIS memory space, parsing the config items, and
 412         * finds the proper lan_node_id tuple and uses the data
 413         * stored there.
 414         */
 415        outl(1 << 12, ioaddr + CSR9); /* enable boot rom access */
 416        for (i = 0x100; i < 0x1f7; i += link+2) {
 417                outl(i, ioaddr + CSR10);
 418                tuple = inl(ioaddr + CSR9) & 0xff;
 419                outl(i + 1, ioaddr + CSR10);
 420                link = inl(ioaddr + CSR9) & 0xff;
 421                outl(i + 2, ioaddr + CSR10);
 422                data_id = inl(ioaddr + CSR9) & 0xff;
 423                outl(i + 3, ioaddr + CSR10);
 424                data_count = inl(ioaddr + CSR9) & 0xff;
 425                if ( (tuple == 0x22) &&
 426                         (data_id == 0x04) && (data_count == 0x06) ) {
 427                        /*
 428                         * This is it.  We have the data we want.
 429                         */
 430                        for (j = 0; j < 6; j++) {
 431                                outl(i + j + 4, ioaddr + CSR10);
 432                                dev->dev_addr[j] = inl(ioaddr + CSR9) & 0xff;
 433                        }
 434                        break;
 435                } else if (link == 0) {
 436                        break;
 437                }
 438        }
 439}
 440
 441
 442/*
 443 * locate the MII interfaces and initialize them.
 444 * we disable full-duplex modes here,
 445 * because we don't know how to handle them.
 446 */
 447static void find_mii_transceivers(struct net_device *dev)
 448{
 449        struct xircom_private *tp = dev->priv;
 450        int phy, phy_idx;
 451
 452        if (media_cap[tp->default_port] & MediaIsMII) {
 453                u16 media2advert[] = { 0x20, 0x40, 0x03e0, 0x60, 0x80, 0x100, 0x200 };
 454                tp->to_advertise = media2advert[tp->default_port - 9];
 455        } else
 456                tp->to_advertise =
 457                        /*ADVERTISE_100BASE4 | ADVERTISE_100FULL |*/ ADVERTISE_100HALF |
 458                        /*ADVERTISE_10FULL |*/ ADVERTISE_10HALF | ADVERTISE_CSMA;
 459
 460        /* Find the connected MII xcvrs.
 461           Doing this in open() would allow detecting external xcvrs later,
 462           but takes much time. */
 463        for (phy = 0, phy_idx = 0; phy < 32 && phy_idx < sizeof(tp->phys); phy++) {
 464                int mii_status = mdio_read(dev, phy, MII_BMSR);
 465                if ((mii_status & (BMSR_100BASE4 | BMSR_100HALF | BMSR_10HALF)) == BMSR_100BASE4 ||
 466                        ((mii_status & BMSR_100BASE4) == 0 &&
 467                         (mii_status & (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL | BMSR_10HALF)) != 0)) {
 468                        int mii_reg0 = mdio_read(dev, phy, MII_BMCR);
 469                        int mii_advert = mdio_read(dev, phy, MII_ADVERTISE);
 470                        int reg4 = ((mii_status >> 6) & tp->to_advertise) | ADVERTISE_CSMA;
 471                        tp->phys[phy_idx] = phy;
 472                        tp->advertising[phy_idx++] = reg4;
 473                        printk(KERN_INFO "%s:  MII transceiver #%d "
 474                                   "config %4.4x status %4.4x advertising %4.4x.\n",
 475                                   dev->name, phy, mii_reg0, mii_status, mii_advert);
 476                }
 477        }
 478        tp->mii_cnt = phy_idx;
 479        if (phy_idx == 0) {
 480                printk(KERN_INFO "%s: ***WARNING***: No MII transceiver found!\n",
 481                           dev->name);
 482                tp->phys[0] = 0;
 483        }
 484}
 485
 486
 487/*
 488 * To quote Arjan van de Ven:
 489 *   transceiver_voodoo() enables the external UTP plug thingy.
 490 *   it's called voodoo as I stole this code and cannot cross-reference
 491 *   it with the specification.
 492 * Actually it seems to go like this:
 493 * - GPIO2 enables the MII itself so we can talk to it. The MII gets reset
 494 *   so any prior MII settings are lost.
 495 * - GPIO0 enables the TP port so the MII can talk to the network.
 496 * - a software reset will reset both GPIO pins.
 497 * I also moved the software reset here, because doing it in xircom_up()
 498 * required enabling the GPIO pins each time, which reset the MII each time.
 499 * Thus we couldn't control the MII -- which sucks because we don't know
 500 * how to handle full-duplex modes so we *must* disable them.
 501 */
 502static void transceiver_voodoo(struct net_device *dev)
 503{
 504        struct xircom_private *tp = dev->priv;
 505        long ioaddr = dev->base_addr;
 506
 507        /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */
 508        outl(SoftwareReset, ioaddr + CSR0);
 509        udelay(2);
 510
 511        /* Deassert reset. */
 512        outl(tp->csr0, ioaddr + CSR0);
 513
 514        /* Reset the xcvr interface and turn on heartbeat. */
 515        outl(0x0008, ioaddr + CSR15);
 516        udelay(5);  /* The delays are Xircom-recommended to give the
 517                                 * chipset time to reset the actual hardware
 518                                 * on the PCMCIA card
 519                                 */
 520        outl(0xa8050000, ioaddr + CSR15);
 521        udelay(5);
 522        outl(0xa00f0000, ioaddr + CSR15);
 523        udelay(5);
 524
 525        outl_CSR6(0, ioaddr);
 526        //outl_CSR6(FullDuplexBit, ioaddr);
 527}
 528
 529
 530static int __devinit xircom_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
 531{
 532        struct net_device *dev;
 533        struct xircom_private *tp;
 534        static int board_idx = -1;
 535        int chip_idx = id->driver_data;
 536        long ioaddr;
 537        int i;
 538        u8 chip_rev;
 539
 540/* when built into the kernel, we only print version if device is found */
 541#ifndef MODULE
 542        static int printed_version;
 543        if (!printed_version++)
 544                printk(version);
 545#endif
 546
 547        //printk(KERN_INFO "xircom_init_one(%s)\n", pci_name(pdev));
 548
 549        board_idx++;
 550
 551        if (pci_enable_device(pdev))
 552                return -ENODEV;
 553
 554        pci_set_master(pdev);
 555
 556        ioaddr = pci_resource_start(pdev, 0);
 557        dev = alloc_etherdev(sizeof(*tp));
 558        if (!dev) {
 559                printk (KERN_ERR DRV_NAME "%d: cannot alloc etherdev, aborting\n", board_idx);
 560                return -ENOMEM;
 561        }
 562        SET_MODULE_OWNER(dev);
 563        SET_NETDEV_DEV(dev, &pdev->dev);
 564
 565        dev->base_addr = ioaddr;
 566        dev->irq = pdev->irq;
 567
 568        if (pci_request_regions(pdev, dev->name)) {
 569                printk (KERN_ERR DRV_NAME " %d: cannot reserve PCI resources, aborting\n", board_idx);
 570                goto err_out_free_netdev;
 571        }
 572
 573        /* Bring the chip out of sleep mode.
 574           Caution: Snooze mode does not work with some boards! */
 575        if (xircom_tbl[chip_idx].flags & HAS_ACPI)
 576                pci_write_config_dword(pdev, PCI_POWERMGMT, 0);
 577
 578        /* Stop the chip's Tx and Rx processes. */
 579        outl_CSR6(inl(ioaddr + CSR6) & ~EnableTxRx, ioaddr);
 580        /* Clear the missed-packet counter. */
 581        (volatile int)inl(ioaddr + CSR8);
 582
 583        tp = dev->priv;
 584
 585        tp->lock = SPIN_LOCK_UNLOCKED;
 586        tp->pdev = pdev;
 587        tp->chip_id = chip_idx;
 588        /* BugFixes: The 21143-TD hangs with PCI Write-and-Invalidate cycles. */
 589        /* XXX: is this necessary for Xircom? */
 590        tp->csr0 = csr0 & ~EnableMWI;
 591
 592        pci_set_drvdata(pdev, dev);
 593
 594        /* The lower four bits are the media type. */
 595        if (board_idx >= 0 && board_idx < MAX_UNITS) {
 596                tp->default_port = options[board_idx] & 15;
 597                if ((options[board_idx] & 0x90) || full_duplex[board_idx] > 0)
 598                        tp->full_duplex = 1;
 599                if (mtu[board_idx] > 0)
 600                        dev->mtu = mtu[board_idx];
 601        }
 602        if (dev->mem_start)
 603                tp->default_port = dev->mem_start;
 604        if (tp->default_port) {
 605                if (media_cap[tp->default_port] & MediaAlwaysFD)
 606                        tp->full_duplex = 1;
 607        }
 608        if (tp->full_duplex)
 609                tp->autoneg = 0;
 610        else
 611                tp->autoneg = 1;
 612        tp->speed100 = 1;
 613
 614        /* The Xircom-specific entries in the device structure. */
 615        dev->open = &xircom_open;
 616        dev->hard_start_xmit = &xircom_start_xmit;
 617        dev->stop = &xircom_close;
 618        dev->get_stats = &xircom_get_stats;
 619        dev->do_ioctl = &xircom_ioctl;
 620#ifdef HAVE_MULTICAST
 621        dev->set_multicast_list = &set_rx_mode;
 622#endif
 623        dev->tx_timeout = xircom_tx_timeout;
 624        dev->watchdog_timeo = TX_TIMEOUT;
 625
 626        transceiver_voodoo(dev);
 627
 628        read_mac_address(dev);
 629
 630        if (register_netdev(dev))
 631                goto err_out_cleardev;
 632
 633        pci_read_config_byte(pdev, PCI_REVISION_ID, &chip_rev);
 634        printk(KERN_INFO "%s: %s rev %d at %#3lx,",
 635               dev->name, xircom_tbl[chip_idx].chip_name, chip_rev, ioaddr);
 636        for (i = 0; i < 6; i++)
 637                printk("%c%2.2X", i ? ':' : ' ', dev->dev_addr[i]);
 638        printk(", IRQ %d.\n", dev->irq);
 639
 640        if (xircom_tbl[chip_idx].flags & HAS_MII) {
 641                find_mii_transceivers(dev);
 642                check_duplex(dev);
 643        }
 644
 645        return 0;
 646
 647err_out_cleardev:
 648        pci_set_drvdata(pdev, NULL);
 649        pci_release_regions(pdev);
 650err_out_free_netdev:
 651        unregister_netdev(dev);
 652        kfree(dev);
 653        return -ENODEV;
 654}
 655
 656
 657/* MII transceiver control section.
 658   Read and write the MII registers using software-generated serial
 659   MDIO protocol.  See the MII specifications or DP83840A data sheet
 660   for details. */
 661
 662/* The maximum data clock rate is 2.5 Mhz.  The minimum timing is usually
 663   met by back-to-back PCI I/O cycles, but we insert a delay to avoid
 664   "overclocking" issues or future 66Mhz PCI. */
 665#define mdio_delay() inl(mdio_addr)
 666
 667/* Read and write the MII registers using software-generated serial
 668   MDIO protocol.  It is just different enough from the EEPROM protocol
 669   to not share code.  The maxium data clock rate is 2.5 Mhz. */
 670#define MDIO_SHIFT_CLK  0x10000
 671#define MDIO_DATA_WRITE0 0x00000
 672#define MDIO_DATA_WRITE1 0x20000
 673#define MDIO_ENB                0x00000         /* Ignore the 0x02000 databook setting. */
 674#define MDIO_ENB_IN             0x40000
 675#define MDIO_DATA_READ  0x80000
 676
 677static int mdio_read(struct net_device *dev, int phy_id, int location)
 678{
 679        int i;
 680        int read_cmd = (0xf6 << 10) | (phy_id << 5) | location;
 681        int retval = 0;
 682        long ioaddr = dev->base_addr;
 683        long mdio_addr = ioaddr + CSR9;
 684
 685        /* Establish sync by sending at least 32 logic ones. */
 686        for (i = 32; i >= 0; i--) {
 687                outl(MDIO_ENB | MDIO_DATA_WRITE1, mdio_addr);
 688                mdio_delay();
 689                outl(MDIO_ENB | MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
 690                mdio_delay();
 691        }
 692        /* Shift the read command bits out. */
 693        for (i = 15; i >= 0; i--) {
 694                int dataval = (read_cmd & (1 << i)) ? MDIO_DATA_WRITE1 : 0;
 695
 696                outl(MDIO_ENB | dataval, mdio_addr);
 697                mdio_delay();
 698                outl(MDIO_ENB | dataval | MDIO_SHIFT_CLK, mdio_addr);
 699                mdio_delay();
 700        }
 701        /* Read the two transition, 16 data, and wire-idle bits. */
 702        for (i = 19; i > 0; i--) {
 703                outl(MDIO_ENB_IN, mdio_addr);
 704                mdio_delay();
 705                retval = (retval << 1) | ((inl(mdio_addr) & MDIO_DATA_READ) ? 1 : 0);
 706                outl(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
 707                mdio_delay();
 708        }
 709        return (retval>>1) & 0xffff;
 710}
 711
 712
 713static void mdio_write(struct net_device *dev, int phy_id, int location, int value)
 714{
 715        int i;
 716        int cmd = (0x5002 << 16) | (phy_id << 23) | (location << 18) | value;
 717        long ioaddr = dev->base_addr;
 718        long mdio_addr = ioaddr + CSR9;
 719
 720        /* Establish sync by sending 32 logic ones. */
 721        for (i = 32; i >= 0; i--) {
 722                outl(MDIO_ENB | MDIO_DATA_WRITE1, mdio_addr);
 723                mdio_delay();
 724                outl(MDIO_ENB | MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
 725                mdio_delay();
 726        }
 727        /* Shift the command bits out. */
 728        for (i = 31; i >= 0; i--) {
 729                int dataval = (cmd & (1 << i)) ? MDIO_DATA_WRITE1 : 0;
 730                outl(MDIO_ENB | dataval, mdio_addr);
 731                mdio_delay();
 732                outl(MDIO_ENB | dataval | MDIO_SHIFT_CLK, mdio_addr);
 733                mdio_delay();
 734        }
 735        /* Clear out extra bits. */
 736        for (i = 2; i > 0; i--) {
 737                outl(MDIO_ENB_IN, mdio_addr);
 738                mdio_delay();
 739                outl(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
 740                mdio_delay();
 741        }
 742        return;
 743}
 744
 745
 746static void
 747xircom_up(struct net_device *dev)
 748{
 749        struct xircom_private *tp = dev->priv;
 750        long ioaddr = dev->base_addr;
 751        int i;
 752
 753        /* Clear the tx ring */
 754        for (i = 0; i < TX_RING_SIZE; i++) {
 755                tp->tx_skbuff[i] = 0;
 756                tp->tx_ring[i].status = 0;
 757        }
 758
 759        if (xircom_debug > 1)
 760                printk(KERN_DEBUG "%s: xircom_up() irq %d.\n", dev->name, dev->irq);
 761
 762        outl(virt_to_bus(tp->rx_ring), ioaddr + CSR3);
 763        outl(virt_to_bus(tp->tx_ring), ioaddr + CSR4);
 764
 765        tp->saved_if_port = dev->if_port;
 766        if (dev->if_port == 0)
 767                dev->if_port = tp->default_port;
 768
 769        tp->csr6 = TxThresh10 /*| FullDuplexBit*/;                                              /* XXX: why 10 and not 100? */
 770
 771        set_rx_mode(dev);
 772
 773        /* Start the chip's Tx to process setup frame. */
 774        outl_CSR6(tp->csr6, ioaddr);
 775        outl_CSR6(tp->csr6 | EnableTx, ioaddr);
 776
 777        /* Acknowledge all outstanding interrupts sources */
 778        outl(xircom_tbl[tp->chip_id].valid_intrs, ioaddr + CSR5);
 779        /* Enable interrupts by setting the interrupt mask. */
 780        outl(xircom_tbl[tp->chip_id].valid_intrs, ioaddr + CSR7);
 781        /* Enable Rx */
 782        outl_CSR6(tp->csr6 | EnableTxRx, ioaddr);
 783        /* Rx poll demand */
 784        outl(0, ioaddr + CSR2);
 785
 786        /* Tell the net layer we're ready */
 787        netif_start_queue (dev);
 788
 789        if (xircom_debug > 2) {
 790                printk(KERN_DEBUG "%s: Done xircom_up(), CSR0 %8.8x, CSR5 %8.8x CSR6 %8.8x.\n",
 791                           dev->name, inl(ioaddr + CSR0), inl(ioaddr + CSR5),
 792                           inl(ioaddr + CSR6));
 793        }
 794}
 795
 796
 797static int
 798xircom_open(struct net_device *dev)
 799{
 800        struct xircom_private *tp = dev->priv;
 801
 802        if (request_irq(dev->irq, &xircom_interrupt, SA_SHIRQ, dev->name, dev))
 803                return -EAGAIN;
 804
 805        xircom_init_ring(dev);
 806
 807        xircom_up(dev);
 808        tp->open = 1;
 809
 810        return 0;
 811}
 812
 813
 814static void xircom_tx_timeout(struct net_device *dev)
 815{
 816        struct xircom_private *tp = dev->priv;
 817        long ioaddr = dev->base_addr;
 818
 819        if (media_cap[dev->if_port] & MediaIsMII) {
 820                /* Do nothing -- the media monitor should handle this. */
 821                if (xircom_debug > 1)
 822                        printk(KERN_WARNING "%s: Transmit timeout using MII device.\n",
 823                                   dev->name);
 824        }
 825
 826#if defined(way_too_many_messages)
 827        if (xircom_debug > 3) {
 828                int i;
 829                for (i = 0; i < RX_RING_SIZE; i++) {
 830                        u8 *buf = (u8 *)(tp->rx_ring[i].buffer1);
 831                        int j;
 832                        printk(KERN_DEBUG "%2d: %8.8x %8.8x %8.8x %8.8x  "
 833                                   "%2.2x %2.2x %2.2x.\n",
 834                                   i, (unsigned int)tp->rx_ring[i].status,
 835                                   (unsigned int)tp->rx_ring[i].length,
 836                                   (unsigned int)tp->rx_ring[i].buffer1,
 837                                   (unsigned int)tp->rx_ring[i].buffer2,
 838                                   buf[0], buf[1], buf[2]);
 839                        for (j = 0; buf[j] != 0xee && j < 1600; j++)
 840                                if (j < 100) printk(" %2.2x", buf[j]);
 841                        printk(" j=%d.\n", j);
 842                }
 843                printk(KERN_DEBUG "  Rx ring %8.8x: ", (int)tp->rx_ring);
 844                for (i = 0; i < RX_RING_SIZE; i++)
 845                        printk(" %8.8x", (unsigned int)tp->rx_ring[i].status);
 846                printk("\n" KERN_DEBUG "  Tx ring %8.8x: ", (int)tp->tx_ring);
 847                for (i = 0; i < TX_RING_SIZE; i++)
 848                        printk(" %8.8x", (unsigned int)tp->tx_ring[i].status);
 849                printk("\n");
 850        }
 851#endif
 852
 853        /* Stop and restart the chip's Tx/Rx processes . */
 854        outl_CSR6(tp->csr6 | EnableRx, ioaddr);
 855        outl_CSR6(tp->csr6 | EnableTxRx, ioaddr);
 856        /* Trigger an immediate transmit demand. */
 857        outl(0, ioaddr + CSR1);
 858
 859        dev->trans_start = jiffies;
 860        netif_wake_queue (dev);
 861        tp->stats.tx_errors++;
 862}
 863
 864
 865/* Initialize the Rx and Tx rings, along with various 'dev' bits. */
 866static void xircom_init_ring(struct net_device *dev)
 867{
 868        struct xircom_private *tp = dev->priv;
 869        int i;
 870
 871        tp->tx_full = 0;
 872        tp->cur_rx = tp->cur_tx = 0;
 873        tp->dirty_rx = tp->dirty_tx = 0;
 874
 875        for (i = 0; i < RX_RING_SIZE; i++) {
 876                tp->rx_ring[i].status = 0;
 877                tp->rx_ring[i].length = PKT_BUF_SZ;
 878                tp->rx_ring[i].buffer2 = virt_to_bus(&tp->rx_ring[i+1]);
 879                tp->rx_skbuff[i] = NULL;
 880        }
 881        /* Mark the last entry as wrapping the ring. */
 882        tp->rx_ring[i-1].length = PKT_BUF_SZ | Rx1RingWrap;
 883        tp->rx_ring[i-1].buffer2 = virt_to_bus(&tp->rx_ring[0]);
 884
 885        for (i = 0; i < RX_RING_SIZE; i++) {
 886                /* Note the receive buffer must be longword aligned.
 887                   dev_alloc_skb() provides 16 byte alignment.  But do *not*
 888                   use skb_reserve() to align the IP header! */
 889                struct sk_buff *skb = dev_alloc_skb(PKT_BUF_SZ);
 890                tp->rx_skbuff[i] = skb;
 891                if (skb == NULL)
 892                        break;
 893                skb->dev = dev;                 /* Mark as being used by this device. */
 894                tp->rx_ring[i].status = Rx0DescOwned;   /* Owned by Xircom chip */
 895                tp->rx_ring[i].buffer1 = virt_to_bus(skb->tail);
 896        }
 897        tp->dirty_rx = (unsigned int)(i - RX_RING_SIZE);
 898
 899        /* The Tx buffer descriptor is filled in as needed, but we
 900           do need to clear the ownership bit. */
 901        for (i = 0; i < TX_RING_SIZE; i++) {
 902                tp->tx_skbuff[i] = 0;
 903                tp->tx_ring[i].status = 0;
 904                tp->tx_ring[i].buffer2 = virt_to_bus(&tp->tx_ring[i+1]);
 905#ifdef CARDBUS
 906                if (tp->chip_id == X3201_3)
 907                        tp->tx_aligned_skbuff[i] = dev_alloc_skb(PKT_BUF_SZ);
 908#endif /* CARDBUS */
 909        }
 910        tp->tx_ring[i-1].buffer2 = virt_to_bus(&tp->tx_ring[0]);
 911}
 912
 913
 914static int
 915xircom_start_xmit(struct sk_buff *skb, struct net_device *dev)
 916{
 917        struct xircom_private *tp = dev->priv;
 918        int entry;
 919        u32 flag;
 920
 921        /* Caution: the write order is important here, set the base address
 922           with the "ownership" bits last. */
 923
 924        /* Calculate the next Tx descriptor entry. */
 925        entry = tp->cur_tx % TX_RING_SIZE;
 926
 927        tp->tx_skbuff[entry] = skb;
 928#ifdef CARDBUS
 929        if (tp->chip_id == X3201_3) {
 930                memcpy(tp->tx_aligned_skbuff[entry]->data,skb->data,skb->len);
 931                tp->tx_ring[entry].buffer1 = virt_to_bus(tp->tx_aligned_skbuff[entry]->data);
 932        } else
 933#endif
 934                tp->tx_ring[entry].buffer1 = virt_to_bus(skb->data);
 935
 936        if (tp->cur_tx - tp->dirty_tx < TX_RING_SIZE/2) {/* Typical path */
 937                flag = Tx1WholePkt; /* No interrupt */
 938        } else if (tp->cur_tx - tp->dirty_tx == TX_RING_SIZE/2) {
 939                flag = Tx1WholePkt | Tx1ComplIntr; /* Tx-done intr. */
 940        } else if (tp->cur_tx - tp->dirty_tx < TX_RING_SIZE - 2) {
 941                flag = Tx1WholePkt; /* No Tx-done intr. */
 942        } else {
 943                /* Leave room for set_rx_mode() to fill entries. */
 944                flag = Tx1WholePkt | Tx1ComplIntr; /* Tx-done intr. */
 945                tp->tx_full = 1;
 946        }
 947        if (entry == TX_RING_SIZE - 1)
 948                flag |= Tx1WholePkt | Tx1ComplIntr | Tx1RingWrap;
 949
 950        tp->tx_ring[entry].length = skb->len | flag;
 951        tp->tx_ring[entry].status = Tx0DescOwned;       /* Pass ownership to the chip. */
 952        tp->cur_tx++;
 953        if (tp->tx_full)
 954                netif_stop_queue (dev);
 955        else
 956                netif_wake_queue (dev);
 957
 958        /* Trigger an immediate transmit demand. */
 959        outl(0, dev->base_addr + CSR1);
 960
 961        dev->trans_start = jiffies;
 962
 963        return 0;
 964}
 965
 966
 967static void xircom_media_change(struct net_device *dev)
 968{
 969        struct xircom_private *tp = dev->priv;
 970        long ioaddr = dev->base_addr;
 971        u16 reg0, reg1, reg4, reg5;
 972        u32 csr6 = inl(ioaddr + CSR6), newcsr6;
 973
 974        /* reset status first */
 975        mdio_read(dev, tp->phys[0], MII_BMCR);
 976        mdio_read(dev, tp->phys[0], MII_BMSR);
 977
 978        reg0 = mdio_read(dev, tp->phys[0], MII_BMCR);
 979        reg1 = mdio_read(dev, tp->phys[0], MII_BMSR);
 980
 981        if (reg1 & BMSR_LSTATUS) {
 982                /* link is up */
 983                if (reg0 & BMCR_ANENABLE) {
 984                        /* autonegotiation is enabled */
 985                        reg4 = mdio_read(dev, tp->phys[0], MII_ADVERTISE);
 986                        reg5 = mdio_read(dev, tp->phys[0], MII_LPA);
 987                        if (reg4 & ADVERTISE_100FULL && reg5 & LPA_100FULL) {
 988                                tp->speed100 = 1;
 989                                tp->full_duplex = 1;
 990                        } else if (reg4 & ADVERTISE_100HALF && reg5 & LPA_100HALF) {
 991                                tp->speed100 = 1;
 992                                tp->full_duplex = 0;
 993                        } else if (reg4 & ADVERTISE_10FULL && reg5 & LPA_10FULL) {
 994                                tp->speed100 = 0;
 995                                tp->full_duplex = 1;
 996                        } else {
 997                                tp->speed100 = 0;
 998                                tp->full_duplex = 0;
 999                        }
1000                } else {
1001                        /* autonegotiation is disabled */
1002                        if (reg0 & BMCR_SPEED100)
1003                                tp->speed100 = 1;
1004                        else
1005                                tp->speed100 = 0;
1006                        if (reg0 & BMCR_FULLDPLX)
1007                                tp->full_duplex = 1;
1008                        else
1009                                tp->full_duplex = 0;
1010                }
1011                printk(KERN_DEBUG "%s: Link is up, running at %sMbit %s-duplex\n",
1012                       dev->name,
1013                       tp->speed100 ? "100" : "10",
1014                       tp->full_duplex ? "full" : "half");
1015                newcsr6 = csr6 & ~FullDuplexBit;
1016                if (tp->full_duplex)
1017                        newcsr6 |= FullDuplexBit;
1018                if (newcsr6 != csr6)
1019                        outl_CSR6(newcsr6, ioaddr + CSR6);
1020        } else {
1021                printk(KERN_DEBUG "%s: Link is down\n", dev->name);
1022        }
1023}
1024
1025
1026static void check_duplex(struct net_device *dev)
1027{
1028        struct xircom_private *tp = dev->priv;
1029        u16 reg0;
1030
1031        mdio_write(dev, tp->phys[0], MII_BMCR, BMCR_RESET);
1032        udelay(500);
1033        while (mdio_read(dev, tp->phys[0], MII_BMCR) & BMCR_RESET);
1034
1035        reg0 = mdio_read(dev, tp->phys[0], MII_BMCR);
1036        mdio_write(dev, tp->phys[0], MII_ADVERTISE, tp->advertising[0]);
1037
1038        if (tp->autoneg) {
1039                reg0 &= ~(BMCR_SPEED100 | BMCR_FULLDPLX);
1040                reg0 |= BMCR_ANENABLE | BMCR_ANRESTART;
1041        } else {
1042                reg0 &= ~(BMCR_ANENABLE | BMCR_ANRESTART);
1043                if (tp->speed100)
1044                        reg0 |= BMCR_SPEED100;
1045                if (tp->full_duplex)
1046                        reg0 |= BMCR_FULLDPLX;
1047                printk(KERN_DEBUG "%s: Link forced to %sMbit %s-duplex\n",
1048                       dev->name,
1049                       tp->speed100 ? "100" : "10",
1050                       tp->full_duplex ? "full" : "half");
1051        }
1052        mdio_write(dev, tp->phys[0], MII_BMCR, reg0);
1053}
1054
1055
1056/* The interrupt handler does all of the Rx thread work and cleans up
1057   after the Tx thread. */
1058static irqreturn_t xircom_interrupt(int irq, void *dev_instance, struct pt_regs *regs)
1059{
1060        struct net_device *dev = dev_instance;
1061        struct xircom_private *tp = dev->priv;
1062        long ioaddr = dev->base_addr;
1063        int csr5, work_budget = max_interrupt_work;
1064        int handled = 0;
1065
1066        spin_lock (&tp->lock);
1067
1068        do {
1069                csr5 = inl(ioaddr + CSR5);
1070                /* Acknowledge all of the current interrupt sources ASAP. */
1071                outl(csr5 & 0x0001ffff, ioaddr + CSR5);
1072
1073                if (xircom_debug > 4)
1074                        printk(KERN_DEBUG "%s: interrupt  csr5=%#8.8x new csr5=%#8.8x.\n",
1075                                   dev->name, csr5, inl(dev->base_addr + CSR5));
1076
1077                if (csr5 == 0xffffffff)
1078                        break;  /* all bits set, assume PCMCIA card removed */
1079
1080                if ((csr5 & (NormalIntr|AbnormalIntr)) == 0)
1081                        break;
1082
1083                handled = 1;
1084
1085                if (csr5 & (RxIntr | RxNoBuf))
1086                        work_budget -= xircom_rx(dev);
1087
1088                if (csr5 & (TxNoBuf | TxDied | TxIntr)) {
1089                        unsigned int dirty_tx;
1090
1091                        for (dirty_tx = tp->dirty_tx; tp->cur_tx - dirty_tx > 0;
1092                                 dirty_tx++) {
1093                                int entry = dirty_tx % TX_RING_SIZE;
1094                                int status = tp->tx_ring[entry].status;
1095
1096                                if (status < 0)
1097                                        break;                  /* It still hasn't been Txed */
1098                                /* Check for Rx filter setup frames. */
1099                                if (tp->tx_skbuff[entry] == NULL)
1100                                  continue;
1101
1102                                if (status & Tx0DescError) {
1103                                        /* There was an major error, log it. */
1104#ifndef final_version
1105                                        if (xircom_debug > 1)
1106                                                printk(KERN_DEBUG "%s: Transmit error, Tx status %8.8x.\n",
1107                                                           dev->name, status);
1108#endif
1109                                        tp->stats.tx_errors++;
1110                                        if (status & Tx0ManyColl) {
1111                                                tp->stats.tx_aborted_errors++;
1112                                        }
1113                                        if (status & Tx0NoCarrier) tp->stats.tx_carrier_errors++;
1114                                        if (status & Tx0LateColl) tp->stats.tx_window_errors++;
1115                                        if (status & Tx0Underflow) tp->stats.tx_fifo_errors++;
1116                                } else {
1117                                        tp->stats.tx_bytes += tp->tx_ring[entry].length & 0x7ff;
1118                                        tp->stats.collisions += (status >> 3) & 15;
1119                                        tp->stats.tx_packets++;
1120                                }
1121
1122                                /* Free the original skb. */
1123                                dev_kfree_skb_irq(tp->tx_skbuff[entry]);
1124                                tp->tx_skbuff[entry] = 0;
1125                        }
1126
1127#ifndef final_version
1128                        if (tp->cur_tx - dirty_tx > TX_RING_SIZE) {
1129                                printk(KERN_ERR "%s: Out-of-sync dirty pointer, %d vs. %d, full=%d.\n",
1130                                           dev->name, dirty_tx, tp->cur_tx, tp->tx_full);
1131                                dirty_tx += TX_RING_SIZE;
1132                        }
1133#endif
1134
1135                        if (tp->tx_full &&
1136                            tp->cur_tx - dirty_tx  < TX_RING_SIZE - 2)
1137                                /* The ring is no longer full */
1138                                tp->tx_full = 0;
1139
1140                        if (tp->tx_full)
1141                                netif_stop_queue (dev);
1142                        else
1143                                netif_wake_queue (dev);
1144
1145                        tp->dirty_tx = dirty_tx;
1146                        if (csr5 & TxDied) {
1147                                if (xircom_debug > 2)
1148                                        printk(KERN_WARNING "%s: The transmitter stopped."
1149                                                   "  CSR5 is %x, CSR6 %x, new CSR6 %x.\n",
1150                                                   dev->name, csr5, inl(ioaddr + CSR6), tp->csr6);
1151                                outl_CSR6(tp->csr6 | EnableRx, ioaddr);
1152                                outl_CSR6(tp->csr6 | EnableTxRx, ioaddr);
1153                        }
1154                }
1155
1156                /* Log errors. */
1157                if (csr5 & AbnormalIntr) {      /* Abnormal error summary bit. */
1158                        if (csr5 & LinkChange)
1159                                xircom_media_change(dev);
1160                        if (csr5 & TxFIFOUnderflow) {
1161                                if ((tp->csr6 & TxThreshMask) != TxThreshMask)
1162                                        tp->csr6 += (1 << TxThreshShift);       /* Bump up the Tx threshold */
1163                                else
1164                                        tp->csr6 |= TxStoreForw;  /* Store-n-forward. */
1165                                /* Restart the transmit process. */
1166                                outl_CSR6(tp->csr6 | EnableRx, ioaddr);
1167                                outl_CSR6(tp->csr6 | EnableTxRx, ioaddr);
1168                        }
1169                        if (csr5 & RxDied) {            /* Missed a Rx frame. */
1170                                tp->stats.rx_errors++;
1171                                tp->stats.rx_missed_errors += inl(ioaddr + CSR8) & 0xffff;
1172                                outl_CSR6(tp->csr6 | EnableTxRx, ioaddr);
1173                        }
1174                        /* Clear all error sources, included undocumented ones! */
1175                        outl(0x0800f7ba, ioaddr + CSR5);
1176                }
1177                if (--work_budget < 0) {
1178                        if (xircom_debug > 1)
1179                                printk(KERN_WARNING "%s: Too much work during an interrupt, "
1180                                           "csr5=0x%8.8x.\n", dev->name, csr5);
1181                        /* Acknowledge all interrupt sources. */
1182                        outl(0x8001ffff, ioaddr + CSR5);
1183                        break;
1184                }
1185        } while (1);
1186
1187        if (xircom_debug > 3)
1188                printk(KERN_DEBUG "%s: exiting interrupt, csr5=%#4.4x.\n",
1189                           dev->name, inl(ioaddr + CSR5));
1190
1191        spin_unlock (&tp->lock);
1192        return IRQ_RETVAL(handled);
1193}
1194
1195
1196static int
1197xircom_rx(struct net_device *dev)
1198{
1199        struct xircom_private *tp = dev->priv;
1200        int entry = tp->cur_rx % RX_RING_SIZE;
1201        int rx_work_limit = tp->dirty_rx + RX_RING_SIZE - tp->cur_rx;
1202        int work_done = 0;
1203
1204        if (xircom_debug > 4)
1205                printk(KERN_DEBUG " In xircom_rx(), entry %d %8.8x.\n", entry,
1206                           tp->rx_ring[entry].status);
1207        /* If we own the next entry, it's a new packet. Send it up. */
1208        while (tp->rx_ring[entry].status >= 0) {
1209                s32 status = tp->rx_ring[entry].status;
1210
1211                if (xircom_debug > 5)
1212                        printk(KERN_DEBUG " In xircom_rx(), entry %d %8.8x.\n", entry,
1213                                   tp->rx_ring[entry].status);
1214                if (--rx_work_limit < 0)
1215                        break;
1216                if ((status & 0x38008300) != 0x0300) {
1217                        if ((status & 0x38000300) != 0x0300) {
1218                                /* Ignore earlier buffers. */
1219                                if ((status & 0xffff) != 0x7fff) {
1220                                        if (xircom_debug > 1)
1221                                                printk(KERN_WARNING "%s: Oversized Ethernet frame "
1222                                                           "spanned multiple buffers, status %8.8x!\n",
1223                                                           dev->name, status);
1224                                        tp->stats.rx_length_errors++;
1225                                }
1226                        } else if (status & Rx0DescError) {
1227                                /* There was a fatal error. */
1228                                if (xircom_debug > 2)
1229                                        printk(KERN_DEBUG "%s: Receive error, Rx status %8.8x.\n",
1230                                                   dev->name, status);
1231                                tp->stats.rx_errors++; /* end of a packet.*/
1232                                if (status & (Rx0Runt | Rx0HugeFrame)) tp->stats.rx_length_errors++;
1233                                if (status & Rx0CRCError) tp->stats.rx_crc_errors++;
1234                        }
1235                } else {
1236                        /* Omit the four octet CRC from the length. */
1237                        short pkt_len = ((status >> 16) & 0x7ff) - 4;
1238                        struct sk_buff *skb;
1239
1240#ifndef final_version
1241                        if (pkt_len > 1518) {
1242                                printk(KERN_WARNING "%s: Bogus packet size of %d (%#x).\n",
1243                                           dev->name, pkt_len, pkt_len);
1244                                pkt_len = 1518;
1245                                tp->stats.rx_length_errors++;
1246                        }
1247#endif
1248                        /* Check if the packet is long enough to accept without copying
1249                           to a minimally-sized skbuff. */
1250                        if (pkt_len < rx_copybreak
1251                                && (skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
1252                                skb->dev = dev;
1253                                skb_reserve(skb, 2);    /* 16 byte align the IP header */
1254#if ! defined(__alpha__)
1255                                eth_copy_and_sum(skb, bus_to_virt(tp->rx_ring[entry].buffer1),
1256                                                                 pkt_len, 0);
1257                                skb_put(skb, pkt_len);
1258#else
1259                                memcpy(skb_put(skb, pkt_len),
1260                                           bus_to_virt(tp->rx_ring[entry].buffer1), pkt_len);
1261#endif
1262                                work_done++;
1263                        } else {        /* Pass up the skb already on the Rx ring. */
1264                                skb_put(skb = tp->rx_skbuff[entry], pkt_len);
1265                                tp->rx_skbuff[entry] = NULL;
1266                        }
1267                        skb->protocol = eth_type_trans(skb, dev);
1268                        netif_rx(skb);
1269                        dev->last_rx = jiffies;
1270                        tp->stats.rx_packets++;
1271                        tp->stats.rx_bytes += pkt_len;
1272                }
1273                entry = (++tp->cur_rx) % RX_RING_SIZE;
1274        }
1275
1276        /* Refill the Rx ring buffers. */
1277        for (; tp->cur_rx - tp->dirty_rx > 0; tp->dirty_rx++) {
1278                entry = tp->dirty_rx % RX_RING_SIZE;
1279                if (tp->rx_skbuff[entry] == NULL) {
1280                        struct sk_buff *skb;
1281                        skb = tp->rx_skbuff[entry] = dev_alloc_skb(PKT_BUF_SZ);
1282                        if (skb == NULL)
1283                                break;
1284                        skb->dev = dev;                 /* Mark as being used by this device. */
1285                        tp->rx_ring[entry].buffer1 = virt_to_bus(skb->tail);
1286                        work_done++;
1287                }
1288                tp->rx_ring[entry].status = Rx0DescOwned;
1289        }
1290
1291        return work_done;
1292}
1293
1294
1295static void
1296xircom_down(struct net_device *dev)
1297{
1298        long ioaddr = dev->base_addr;
1299        struct xircom_private *tp = dev->priv;
1300
1301        /* Disable interrupts by clearing the interrupt mask. */
1302        outl(0, ioaddr + CSR7);
1303        /* Stop the chip's Tx and Rx processes. */
1304        outl_CSR6(inl(ioaddr + CSR6) & ~EnableTxRx, ioaddr);
1305
1306        if (inl(ioaddr + CSR6) != 0xffffffff)
1307                tp->stats.rx_missed_errors += inl(ioaddr + CSR8) & 0xffff;
1308
1309        dev->if_port = tp->saved_if_port;
1310}
1311
1312
1313static int
1314xircom_close(struct net_device *dev)
1315{
1316        long ioaddr = dev->base_addr;
1317        struct xircom_private *tp = dev->priv;
1318        int i;
1319
1320        if (xircom_debug > 1)
1321                printk(KERN_DEBUG "%s: Shutting down ethercard, status was %2.2x.\n",
1322                           dev->name, inl(ioaddr + CSR5));
1323
1324        netif_stop_queue(dev);
1325
1326        if (netif_device_present(dev))
1327                xircom_down(dev);
1328
1329        free_irq(dev->irq, dev);
1330
1331        /* Free all the skbuffs in the Rx queue. */
1332        for (i = 0; i < RX_RING_SIZE; i++) {
1333                struct sk_buff *skb = tp->rx_skbuff[i];
1334                tp->rx_skbuff[i] = 0;
1335                tp->rx_ring[i].status = 0;              /* Not owned by Xircom chip. */
1336                tp->rx_ring[i].length = 0;
1337                tp->rx_ring[i].buffer1 = 0xBADF00D0; /* An invalid address. */
1338                if (skb) {
1339                        dev_kfree_skb(skb);
1340                }
1341        }
1342        for (i = 0; i < TX_RING_SIZE; i++) {
1343                if (tp->tx_skbuff[i])
1344                        dev_kfree_skb(tp->tx_skbuff[i]);
1345                tp->tx_skbuff[i] = 0;
1346        }
1347
1348        tp->open = 0;
1349        return 0;
1350}
1351
1352
1353static struct net_device_stats *xircom_get_stats(struct net_device *dev)
1354{
1355        struct xircom_private *tp = dev->priv;
1356        long ioaddr = dev->base_addr;
1357
1358        if (netif_device_present(dev))
1359                tp->stats.rx_missed_errors += inl(ioaddr + CSR8) & 0xffff;
1360
1361        return &tp->stats;
1362}
1363
1364
1365static int xircom_ethtool_ioctl(struct net_device *dev, void *useraddr)
1366{
1367        struct ethtool_cmd ecmd;
1368        struct xircom_private *tp = dev->priv;
1369
1370        if (copy_from_user(&ecmd, useraddr, sizeof(ecmd)))
1371                return -EFAULT;
1372
1373        switch (ecmd.cmd) {
1374        case ETHTOOL_GSET:
1375                ecmd.supported =
1376                        SUPPORTED_10baseT_Half |
1377                        SUPPORTED_10baseT_Full |
1378                        SUPPORTED_100baseT_Half |
1379                        SUPPORTED_100baseT_Full |
1380                        SUPPORTED_Autoneg |
1381                        SUPPORTED_MII;
1382
1383                ecmd.advertising = ADVERTISED_MII;
1384                if (tp->advertising[0] & ADVERTISE_10HALF)
1385                        ecmd.advertising |= ADVERTISED_10baseT_Half;
1386                if (tp->advertising[0] & ADVERTISE_10FULL)
1387                        ecmd.advertising |= ADVERTISED_10baseT_Full;
1388                if (tp->advertising[0] & ADVERTISE_100HALF)
1389                        ecmd.advertising |= ADVERTISED_100baseT_Half;
1390                if (tp->advertising[0] & ADVERTISE_100FULL)
1391                        ecmd.advertising |= ADVERTISED_100baseT_Full;
1392                if (tp->autoneg) {
1393                        ecmd.advertising |= ADVERTISED_Autoneg;
1394                        ecmd.autoneg = AUTONEG_ENABLE;
1395                } else
1396                        ecmd.autoneg = AUTONEG_DISABLE;
1397
1398                ecmd.port = PORT_MII;
1399                ecmd.transceiver = XCVR_INTERNAL;
1400                ecmd.phy_address = tp->phys[0];
1401                ecmd.speed = tp->speed100 ? SPEED_100 : SPEED_10;
1402                ecmd.duplex = tp->full_duplex ? DUPLEX_FULL : DUPLEX_HALF;
1403                ecmd.maxtxpkt = TX_RING_SIZE / 2;
1404                ecmd.maxrxpkt = 0;
1405
1406                if (copy_to_user(useraddr, &ecmd, sizeof(ecmd)))
1407                        return -EFAULT;
1408                return 0;
1409
1410        case ETHTOOL_SSET: {
1411                u16 autoneg, speed100, full_duplex;
1412
1413                autoneg = (ecmd.autoneg == AUTONEG_ENABLE);
1414                speed100 = (ecmd.speed == SPEED_100);
1415                full_duplex = (ecmd.duplex == DUPLEX_FULL);
1416
1417                tp->autoneg = autoneg;
1418                if (speed100 != tp->speed100 ||
1419                    full_duplex != tp->full_duplex) {
1420                        tp->speed100 = speed100;
1421                        tp->full_duplex = full_duplex;
1422                        /* change advertising bits */
1423                        tp->advertising[0] &= ~(ADVERTISE_10HALF |
1424                                             ADVERTISE_10FULL |
1425                                             ADVERTISE_100HALF |
1426                                             ADVERTISE_100FULL |
1427                                             ADVERTISE_100BASE4);
1428                        if (speed100) {
1429                                if (full_duplex)
1430                                        tp->advertising[0] |= ADVERTISE_100FULL;
1431                                else
1432                                        tp->advertising[0] |= ADVERTISE_100HALF;
1433                        } else {
1434                                if (full_duplex)
1435                                        tp->advertising[0] |= ADVERTISE_10FULL;
1436                                else
1437                                        tp->advertising[0] |= ADVERTISE_10HALF;
1438                        }
1439                }
1440                check_duplex(dev);
1441                return 0;
1442        }
1443
1444        case ETHTOOL_GDRVINFO: {
1445                struct ethtool_drvinfo info;
1446                memset(&info, 0, sizeof(info));
1447                info.cmd = ecmd.cmd;
1448                strcpy(info.driver, DRV_NAME);
1449                strcpy(info.version, DRV_VERSION);
1450                *info.fw_version = 0;
1451                strcpy(info.bus_info, pci_name(tp->pdev));
1452                if (copy_to_user(useraddr, &info, sizeof(info)))
1453                       return -EFAULT;
1454                return 0;
1455        }
1456
1457        default:
1458                return -EOPNOTSUPP;
1459        }
1460}
1461
1462
1463/* Provide ioctl() calls to examine the MII xcvr state. */
1464static int xircom_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1465{
1466        struct xircom_private *tp = dev->priv;
1467        u16 *data = (u16 *)&rq->ifr_data;
1468        int phy = tp->phys[0] & 0x1f;
1469        unsigned long flags;
1470
1471        switch(cmd) {
1472        case SIOCETHTOOL:
1473                return xircom_ethtool_ioctl(dev, (void *) rq->ifr_data);
1474
1475        /* Legacy mii-diag interface */
1476        case SIOCGMIIPHY:               /* Get address of MII PHY in use. */
1477                if (tp->mii_cnt)
1478                        data[0] = phy;
1479                else
1480                        return -ENODEV;
1481                return 0;
1482        case SIOCGMIIREG:               /* Read MII PHY register. */
1483                save_flags(flags);
1484                cli();
1485                data[3] = mdio_read(dev, data[0] & 0x1f, data[1] & 0x1f);
1486                restore_flags(flags);
1487                return 0;
1488        case SIOCSMIIREG:               /* Write MII PHY register. */
1489                if (!capable(CAP_NET_ADMIN))
1490                        return -EPERM;
1491                save_flags(flags);
1492                cli();
1493                if (data[0] == tp->phys[0]) {
1494                        u16 value = data[2];
1495                        switch (data[1]) {
1496                        case 0:
1497                                if (value & (BMCR_RESET | BMCR_ANENABLE))
1498                                        /* Autonegotiation. */
1499                                        tp->autoneg = 1;
1500                                else {
1501                                        tp->full_duplex = (value & BMCR_FULLDPLX) ? 1 : 0;
1502                                        tp->autoneg = 0;
1503                                }
1504                                break;
1505                        case 4:
1506                                tp->advertising[0] = value;
1507                                break;
1508                        }
1509                        check_duplex(dev);
1510                }
1511                mdio_write(dev, data[0] & 0x1f, data[1] & 0x1f, data[2]);
1512                restore_flags(flags);
1513                return 0;
1514        default:
1515                return -EOPNOTSUPP;
1516        }
1517
1518        return -EOPNOTSUPP;
1519}
1520
1521/* Set or clear the multicast filter for this adaptor.
1522   Note that we only use exclusion around actually queueing the
1523   new frame, not around filling tp->setup_frame.  This is non-deterministic
1524   when re-entered but still correct. */
1525static void set_rx_mode(struct net_device *dev)
1526{
1527        struct xircom_private *tp = dev->priv;
1528        struct dev_mc_list *mclist;
1529        long ioaddr = dev->base_addr;
1530        int csr6 = inl(ioaddr + CSR6);
1531        u16 *eaddrs, *setup_frm;
1532        u32 tx_flags;
1533        int i;
1534
1535        tp->csr6 &= ~(AllMultiBit | PromiscBit | HashFilterBit);
1536        csr6 &= ~(AllMultiBit | PromiscBit | HashFilterBit);
1537        if (dev->flags & IFF_PROMISC) {                 /* Set promiscuous. */
1538                tp->csr6 |= PromiscBit;
1539                csr6 |= PromiscBit;
1540                goto out;
1541        }
1542
1543        if ((dev->mc_count > 1000) || (dev->flags & IFF_ALLMULTI)) {
1544                /* Too many to filter well -- accept all multicasts. */
1545                tp->csr6 |= AllMultiBit;
1546                csr6 |= AllMultiBit;
1547                goto out;
1548        }
1549
1550        tx_flags = Tx1WholePkt | Tx1SetupPkt | PKT_SETUP_SZ;
1551
1552        /* Note that only the low-address shortword of setup_frame is valid! */
1553        setup_frm = tp->setup_frame;
1554        mclist = dev->mc_list;
1555
1556        /* Fill the first entry with our physical address. */
1557        eaddrs = (u16 *)dev->dev_addr;
1558        *setup_frm = cpu_to_le16(eaddrs[0]); setup_frm += 2;
1559        *setup_frm = cpu_to_le16(eaddrs[1]); setup_frm += 2;
1560        *setup_frm = cpu_to_le16(eaddrs[2]); setup_frm += 2;
1561
1562        if (dev->mc_count > 14) { /* Must use a multicast hash table. */
1563                u32 *hash_table = (u32 *)(tp->setup_frame + 4 * 12);
1564                u32 hash, hash2;
1565
1566                tx_flags |= Tx1HashSetup;
1567                tp->csr6 |= HashFilterBit;
1568                csr6 |= HashFilterBit;
1569
1570                /* Fill the unused 3 entries with the broadcast address.
1571                   At least one entry *must* contain the broadcast address!!!*/
1572                for (i = 0; i < 3; i++) {
1573                        *setup_frm = 0xffff; setup_frm += 2;
1574                        *setup_frm = 0xffff; setup_frm += 2;
1575                        *setup_frm = 0xffff; setup_frm += 2;
1576                }
1577
1578                /* Truly brain-damaged hash filter layout */
1579                /* XXX: not sure if I should take the last or the first 9 bits */
1580                for (i = 0; i < dev->mc_count; i++, mclist = mclist->next) {
1581                        u32 *hptr;
1582                        hash = ether_crc(ETH_ALEN, mclist->dmi_addr) & 0x1ff;
1583                        if (hash < 384) {
1584                                hash2 = hash + ((hash >> 4) << 4) +
1585                                        ((hash >> 5) << 5);
1586                        } else {
1587                                hash -= 384;
1588                                hash2 = 64 + hash + (hash >> 4) * 80;
1589                        }
1590                        hptr = &hash_table[hash2 & ~0x1f];
1591                        *hptr |= cpu_to_le32(1 << (hash2 & 0x1f));
1592                }
1593        } else {
1594                /* We have <= 14 mcast addresses so we can use Xircom's
1595                   wonderful 16-address perfect filter. */
1596                for (i = 0; i < dev->mc_count; i++, mclist = mclist->next) {
1597                        eaddrs = (u16 *)mclist->dmi_addr;
1598                        *setup_frm = cpu_to_le16(eaddrs[0]); setup_frm += 2;
1599                        *setup_frm = cpu_to_le16(eaddrs[1]); setup_frm += 2;
1600                        *setup_frm = cpu_to_le16(eaddrs[2]); setup_frm += 2;
1601                }
1602                /* Fill the unused entries with the broadcast address.
1603                   At least one entry *must* contain the broadcast address!!!*/
1604                for (; i < 15; i++) {
1605                        *setup_frm = 0xffff; setup_frm += 2;
1606                        *setup_frm = 0xffff; setup_frm += 2;
1607                        *setup_frm = 0xffff; setup_frm += 2;
1608                }
1609        }
1610
1611        /* Now add this frame to the Tx list. */
1612        if (tp->cur_tx - tp->dirty_tx > TX_RING_SIZE - 2) {
1613                /* Same setup recently queued, we need not add it. */
1614                /* XXX: Huh? All it means is that the Tx list is full...*/
1615        } else {
1616                unsigned long flags;
1617                unsigned int entry;
1618                int dummy = -1;
1619
1620                save_flags(flags); cli();
1621                entry = tp->cur_tx++ % TX_RING_SIZE;
1622
1623                if (entry != 0) {
1624                        /* Avoid a chip errata by prefixing a dummy entry. */
1625                        tp->tx_skbuff[entry] = 0;
1626                        tp->tx_ring[entry].length =
1627                                (entry == TX_RING_SIZE - 1) ? Tx1RingWrap : 0;
1628                        tp->tx_ring[entry].buffer1 = 0;
1629                        /* race with chip, set Tx0DescOwned later */
1630                        dummy = entry;
1631                        entry = tp->cur_tx++ % TX_RING_SIZE;
1632                }
1633
1634                tp->tx_skbuff[entry] = 0;
1635                /* Put the setup frame on the Tx list. */
1636                if (entry == TX_RING_SIZE - 1)
1637                        tx_flags |= Tx1RingWrap;                /* Wrap ring. */
1638                tp->tx_ring[entry].length = tx_flags;
1639                tp->tx_ring[entry].buffer1 = virt_to_bus(tp->setup_frame);
1640                tp->tx_ring[entry].status = Tx0DescOwned;
1641                if (tp->cur_tx - tp->dirty_tx >= TX_RING_SIZE - 2) {
1642                        tp->tx_full = 1;
1643                        netif_stop_queue (dev);
1644                }
1645                if (dummy >= 0)
1646                        tp->tx_ring[dummy].status = Tx0DescOwned;
1647                restore_flags(flags);
1648                /* Trigger an immediate transmit demand. */
1649                outl(0, ioaddr + CSR1);
1650        }
1651
1652out:
1653        outl_CSR6(csr6, ioaddr);
1654}
1655
1656
1657static struct pci_device_id xircom_pci_table[] = {
1658  { 0x115D, 0x0003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, X3201_3 },
1659  {0},
1660};
1661MODULE_DEVICE_TABLE(pci, xircom_pci_table);
1662
1663
1664#ifdef CONFIG_PM
1665static int xircom_suspend(struct pci_dev *pdev, u32 state)
1666{
1667        struct net_device *dev = pci_get_drvdata(pdev);
1668        struct xircom_private *tp = dev->priv;
1669        printk(KERN_INFO "xircom_suspend(%s)\n", dev->name);
1670        if (tp->open)
1671                xircom_down(dev);
1672        return 0;
1673}
1674
1675
1676static int xircom_resume(struct pci_dev *pdev)
1677{
1678        struct net_device *dev = pci_get_drvdata(pdev);
1679        struct xircom_private *tp = dev->priv;
1680        printk(KERN_INFO "xircom_resume(%s)\n", dev->name);
1681
1682        /* Bring the chip out of sleep mode.
1683           Caution: Snooze mode does not work with some boards! */
1684        if (xircom_tbl[tp->chip_id].flags & HAS_ACPI)
1685                pci_write_config_dword(tp->pdev, PCI_POWERMGMT, 0);
1686
1687        transceiver_voodoo(dev);
1688        if (xircom_tbl[tp->chip_id].flags & HAS_MII)
1689                check_duplex(dev);
1690
1691        if (tp->open)
1692                xircom_up(dev);
1693        return 0;
1694}
1695#endif /* CONFIG_PM */
1696
1697
1698static void __devexit xircom_remove_one(struct pci_dev *pdev)
1699{
1700        struct net_device *dev = pci_get_drvdata(pdev);
1701
1702        printk(KERN_INFO "xircom_remove_one(%s)\n", dev->name);
1703        unregister_netdev(dev);
1704        pci_release_regions(pdev);
1705        free_netdev(dev);
1706        pci_set_drvdata(pdev, NULL);
1707}
1708
1709
1710static struct pci_driver xircom_driver = {
1711        .name           = DRV_NAME,
1712        .id_table       = xircom_pci_table,
1713        .probe          = xircom_init_one,
1714        .remove         = __devexit_p(xircom_remove_one),
1715#ifdef CONFIG_PM
1716        .suspend        = xircom_suspend,
1717        .resume         = xircom_resume
1718#endif /* CONFIG_PM */
1719};
1720
1721
1722static int __init xircom_init(void)
1723{
1724/* when a module, this is printed whether or not devices are found in probe */
1725#ifdef MODULE
1726        printk(version);
1727#endif
1728        return pci_module_init(&xircom_driver);
1729}
1730
1731
1732static void __exit xircom_exit(void)
1733{
1734        pci_unregister_driver(&xircom_driver);
1735}
1736
1737module_init(xircom_init)
1738module_exit(xircom_exit)
1739
1740/*
1741 * Local variables:
1742 *  c-indent-level: 4
1743 *  c-basic-offset: 4
1744 *  tab-width: 4
1745 * End:
1746 */
1747
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.