linux-bk/drivers/net/fealnx.c History
<<
>>
Prefs
   1/*
   2        Written 1998-2000 by Donald Becker.
   3
   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.
  10
  11        The author may be reached as becker@scyld.com, or C/O
  12        Scyld Computing Corporation
  13        410 Severn Ave., Suite 210
  14        Annapolis MD 21403
  15
  16        Support information and updates available at
  17        http://www.scyld.com/network/pci-skeleton.html
  18
  19        Linux kernel updates:
  20
  21        Version 2.51, Nov 17, 2001 (jgarzik):
  22        - Add ethtool support
  23        - Replace some MII-related magic numbers with constants
  24
  25*/
  26
  27#define DRV_NAME        "fealnx"
  28#define DRV_VERSION     "2.51"
  29#define DRV_RELDATE     "Nov-17-2001"
  30
  31static int debug;               /* 1-> print debug message */
  32static int max_interrupt_work = 20;
  33
  34/* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). */
  35static int multicast_filter_limit = 32;
  36
  37/* Set the copy breakpoint for the copy-only-tiny-frames scheme. */
  38/* Setting to > 1518 effectively disables this feature.          */
  39static int rx_copybreak;
  40
  41/* Used to pass the media type, etc.                            */
  42/* Both 'options[]' and 'full_duplex[]' should exist for driver */
  43/* interoperability.                                            */
  44/* The media type is usually passed in 'options[]'.             */
  45#define MAX_UNITS 8             /* More are supported, limit only on options */
  46static int options[MAX_UNITS] = { -1, -1, -1, -1, -1, -1, -1, -1 };
  47static int full_duplex[MAX_UNITS] = { -1, -1, -1, -1, -1, -1, -1, -1 };
  48
  49/* Operational parameters that are set at compile time.                 */
  50/* Keep the ring sizes a power of two for compile efficiency.           */
  51/* The compiler will convert <unsigned>'%'<2^N> into a bit mask.        */
  52/* Making the Tx ring too large decreases the effectiveness of channel  */
  53/* bonding and packet priority.                                         */
  54/* There are no ill effects from too-large receive rings.               */
  55// 88-12-9 modify,
  56// #define TX_RING_SIZE    16
  57// #define RX_RING_SIZE    32
  58#define TX_RING_SIZE    6
  59#define RX_RING_SIZE    12
  60#define TX_TOTAL_SIZE   TX_RING_SIZE*sizeof(struct fealnx_desc)
  61#define RX_TOTAL_SIZE   RX_RING_SIZE*sizeof(struct fealnx_desc)
  62
  63/* Operational parameters that usually are not changed. */
  64/* Time in jiffies before concluding the transmitter is hung. */
  65#define TX_TIMEOUT      (2*HZ)
  66
  67#define PKT_BUF_SZ      1536    /* Size of each temporary Rx buffer. */
  68
  69
  70/* Include files, designed to support most kernel versions 2.0.0 and later. */
  71#include <linux/module.h>
  72#include <linux/kernel.h>
  73#include <linux/string.h>
  74#include <linux/timer.h>
  75#include <linux/errno.h>
  76#include <linux/ioport.h>
  77#include <linux/slab.h>
  78#include <linux/interrupt.h>
  79#include <linux/pci.h>
  80#include <linux/netdevice.h>
  81#include <linux/etherdevice.h>
  82#include <linux/skbuff.h>
  83#include <linux/init.h>
  84#include <linux/mii.h>
  85#include <linux/ethtool.h>
  86#include <linux/crc32.h>
  87
  88#include <asm/processor.h>      /* Processor type for cache alignment. */
  89#include <asm/bitops.h>
  90#include <asm/io.h>
  91#include <asm/uaccess.h>
  92
  93/* These identify the driver base version and may not be removed. */
  94static char version[] __devinitdata =
  95KERN_INFO DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE "\n";
  96
  97
  98/* This driver was written to use PCI memory space, however some x86 systems
  99   work only with I/O space accesses. */
 100#ifndef __alpha__
 101#define USE_IO_OPS
 102#endif
 103
 104#ifdef USE_IO_OPS
 105#undef readb
 106#undef readw
 107#undef readl
 108#undef writeb
 109#undef writew
 110#undef writel
 111#define readb inb
 112#define readw inw
 113#define readl inl
 114#define writeb outb
 115#define writew outw
 116#define writel outl
 117#endif
 118
 119/* Kernel compatibility defines, some common to David Hinds' PCMCIA package. */
 120/* This is only in the support-all-kernels source code. */
 121
 122#define RUN_AT(x) (jiffies + (x))
 123
 124MODULE_AUTHOR("Myson or whoever");
 125MODULE_DESCRIPTION("Myson MTD-8xx 100/10M Ethernet PCI Adapter Driver");
 126MODULE_LICENSE("GPL");
 127MODULE_PARM(max_interrupt_work, "i");
 128//MODULE_PARM(min_pci_latency, "i");
 129MODULE_PARM(debug, "i");
 130MODULE_PARM(rx_copybreak, "i");
 131MODULE_PARM(multicast_filter_limit, "i");
 132MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i");
 133MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");
 134MODULE_PARM_DESC(max_interrupt_work, "fealnx maximum events handled per interrupt");
 135MODULE_PARM_DESC(debug, "fealnx enable debugging (0-1)");
 136MODULE_PARM_DESC(rx_copybreak, "fealnx copy breakpoint for copy-only-tiny-frames");
 137MODULE_PARM_DESC(multicast_filter_limit, "fealnx maximum number of filtered multicast addresses");
 138MODULE_PARM_DESC(options, "fealnx: Bits 0-3: media type, bit 17: full duplex");
 139MODULE_PARM_DESC(full_duplex, "fealnx full duplex setting(s) (1)");
 140
 141#define MIN_REGION_SIZE 136
 142
 143enum pci_flags_bit {
 144        PCI_USES_IO = 1,
 145        PCI_USES_MEM = 2,
 146        PCI_USES_MASTER = 4,
 147        PCI_ADDR0 = 0x10 << 0,
 148        PCI_ADDR1 = 0x10 << 1,
 149        PCI_ADDR2 = 0x10 << 2,
 150        PCI_ADDR3 = 0x10 << 3,
 151};
 152
 153/* A chip capabilities table, matching the entries in pci_tbl[] above. */
 154enum chip_capability_flags {
 155        HAS_MII_XCVR,
 156        HAS_CHIP_XCVR,
 157};
 158
 159/* 89/6/13 add, */
 160/* for different PHY */
 161enum phy_type_flags {
 162        MysonPHY = 1,
 163        AhdocPHY = 2,
 164        SeeqPHY = 3,
 165        MarvellPHY = 4,
 166        Myson981 = 5,
 167        LevelOnePHY = 6,
 168        OtherPHY = 10,
 169};
 170
 171struct chip_info {
 172        char *chip_name;
 173        int io_size;
 174        int flags;
 175};
 176
 177static struct chip_info skel_netdrv_tbl[] = {
 178        {"100/10M Ethernet PCI Adapter", 136, HAS_MII_XCVR},
 179        {"100/10M Ethernet PCI Adapter", 136, HAS_CHIP_XCVR},
 180        {"1000/100/10M Ethernet PCI Adapter", 136, HAS_MII_XCVR},
 181};
 182
 183/* Offsets to the Command and Status Registers. */
 184enum fealnx_offsets {
 185        PAR0 = 0x0,             /* physical address 0-3 */
 186        PAR1 = 0x04,            /* physical address 4-5 */
 187        MAR0 = 0x08,            /* multicast address 0-3 */
 188        MAR1 = 0x0C,            /* multicast address 4-7 */
 189        FAR0 = 0x10,            /* flow-control address 0-3 */
 190        FAR1 = 0x14,            /* flow-control address 4-5 */
 191        TCRRCR = 0x18,          /* receive & transmit configuration */
 192        BCR = 0x1C,             /* bus command */
 193        TXPDR = 0x20,           /* transmit polling demand */
 194        RXPDR = 0x24,           /* receive polling demand */
 195        RXCWP = 0x28,           /* receive current word pointer */
 196        TXLBA = 0x2C,           /* transmit list base address */
 197        RXLBA = 0x30,           /* receive list base address */
 198        ISR = 0x34,             /* interrupt status */
 199        IMR = 0x38,             /* interrupt mask */
 200        FTH = 0x3C,             /* flow control high/low threshold */
 201        MANAGEMENT = 0x40,      /* bootrom/eeprom and mii management */
 202        TALLY = 0x44,           /* tally counters for crc and mpa */
 203        TSR = 0x48,             /* tally counter for transmit status */
 204        BMCRSR = 0x4c,          /* basic mode control and status */
 205        PHYIDENTIFIER = 0x50,   /* phy identifier */
 206        ANARANLPAR = 0x54,      /* auto-negotiation advertisement and link
 207                                   partner ability */
 208        ANEROCR = 0x58,         /* auto-negotiation expansion and pci conf. */
 209        BPREMRPSR = 0x5c,       /* bypass & receive error mask and phy status */
 210};
 211
 212/* Bits in the interrupt status/enable registers. */
 213/* The bits in the Intr Status/Enable registers, mostly interrupt sources. */
 214enum intr_status_bits {
 215        RFCON = 0x00020000,     /* receive flow control xon packet */
 216        RFCOFF = 0x00010000,    /* receive flow control xoff packet */
 217        LSCStatus = 0x00008000, /* link status change */
 218        ANCStatus = 0x00004000, /* autonegotiation completed */
 219        FBE = 0x00002000,       /* fatal bus error */
 220        FBEMask = 0x00001800,   /* mask bit12-11 */
 221        ParityErr = 0x00000000, /* parity error */
 222        TargetErr = 0x00001000, /* target abort */
 223        MasterErr = 0x00000800, /* master error */
 224        TUNF = 0x00000400,      /* transmit underflow */
 225        ROVF = 0x00000200,      /* receive overflow */
 226        ETI = 0x00000100,       /* transmit early int */
 227        ERI = 0x00000080,       /* receive early int */
 228        CNTOVF = 0x00000040,    /* counter overflow */
 229        RBU = 0x00000020,       /* receive buffer unavailable */
 230        TBU = 0x00000010,       /* transmit buffer unavilable */
 231        TI = 0x00000008,        /* transmit interrupt */
 232        RI = 0x00000004,        /* receive interrupt */
 233        RxErr = 0x00000002,     /* receive error */
 234};
 235
 236/* Bits in the NetworkConfig register. */
 237enum rx_mode_bits {
 238        RxModeMask = 0xe0,
 239        PROM = 0x80,            /* promiscuous mode */
 240        AB = 0x40,              /* accept broadcast */
 241        AM = 0x20,              /* accept mutlicast */
 242        ARP = 0x08,             /* receive runt pkt */
 243        ALP = 0x04,             /* receive long pkt */
 244        SEP = 0x02,             /* receive error pkt */
 245};
 246
 247/* The Tulip Rx and Tx buffer descriptors. */
 248struct fealnx_desc {
 249        s32 status;
 250        s32 control;
 251        u32 buffer;
 252        u32 next_desc;
 253        struct fealnx_desc *next_desc_logical;
 254        struct sk_buff *skbuff;
 255        u32 reserved1;
 256        u32 reserved2;
 257};
 258
 259/* Bits in network_desc.status */
 260enum rx_desc_status_bits {
 261        RXOWN = 0x80000000,     /* own bit */
 262        FLNGMASK = 0x0fff0000,  /* frame length */
 263        FLNGShift = 16,
 264        MARSTATUS = 0x00004000, /* multicast address received */
 265        BARSTATUS = 0x00002000, /* broadcast address received */
 266        PHYSTATUS = 0x00001000, /* physical address received */
 267        RXFSD = 0x00000800,     /* first descriptor */
 268        RXLSD = 0x00000400,     /* last descriptor */
 269        ErrorSummary = 0x80,    /* error summary */
 270        RUNT = 0x40,            /* runt packet received */
 271        LONG = 0x20,            /* long packet received */
 272        FAE = 0x10,             /* frame align error */
 273        CRC = 0x08,             /* crc error */
 274        RXER = 0x04,            /* receive error */
 275};
 276
 277enum rx_desc_control_bits {
 278        RXIC = 0x00800000,      /* interrupt control */
 279        RBSShift = 0,
 280};
 281
 282enum tx_desc_status_bits {
 283        TXOWN = 0x80000000,     /* own bit */
 284        JABTO = 0x00004000,     /* jabber timeout */
 285        CSL = 0x00002000,       /* carrier sense lost */
 286        LC = 0x00001000,        /* late collision */
 287        EC = 0x00000800,        /* excessive collision */
 288        UDF = 0x00000400,       /* fifo underflow */
 289        DFR = 0x00000200,       /* deferred */
 290        HF = 0x00000100,        /* heartbeat fail */
 291        NCRMask = 0x000000ff,   /* collision retry count */
 292        NCRShift = 0,
 293};
 294
 295enum tx_desc_control_bits {
 296        TXIC = 0x80000000,      /* interrupt control */
 297        ETIControl = 0x40000000,        /* early transmit interrupt */
 298        TXLD = 0x20000000,      /* last descriptor */
 299        TXFD = 0x10000000,      /* first descriptor */
 300        CRCEnable = 0x08000000, /* crc control */
 301        PADEnable = 0x04000000, /* padding control */
 302        RetryTxLC = 0x02000000, /* retry late collision */
 303        PKTSMask = 0x3ff800,    /* packet size bit21-11 */
 304        PKTSShift = 11,
 305        TBSMask = 0x000007ff,   /* transmit buffer bit 10-0 */
 306        TBSShift = 0,
 307};
 308
 309/* BootROM/EEPROM/MII Management Register */
 310#define MASK_MIIR_MII_READ       0x00000000
 311#define MASK_MIIR_MII_WRITE      0x00000008
 312#define MASK_MIIR_MII_MDO        0x00000004
 313#define MASK_MIIR_MII_MDI        0x00000002
 314#define MASK_MIIR_MII_MDC        0x00000001
 315
 316/* ST+OP+PHYAD+REGAD+TA */
 317#define OP_READ             0x6000      /* ST:01+OP:10+PHYAD+REGAD+TA:Z0 */
 318#define OP_WRITE            0x5002      /* ST:01+OP:01+PHYAD+REGAD+TA:10 */
 319
 320/* ------------------------------------------------------------------------- */
 321/*      Constants for Myson PHY                                              */
 322/* ------------------------------------------------------------------------- */
 323#define MysonPHYID      0xd0000302
 324/* 89-7-27 add, (begin) */
 325#define MysonPHYID0     0x0302
 326#define StatusRegister  18
 327#define SPEED100        0x0400  // bit10
 328#define FULLMODE        0x0800  // bit11
 329/* 89-7-27 add, (end) */
 330
 331/* ------------------------------------------------------------------------- */
 332/*      Constants for Seeq 80225 PHY                                         */
 333/* ------------------------------------------------------------------------- */
 334#define SeeqPHYID0      0x0016
 335
 336#define MIIRegister18   18
 337#define SPD_DET_100     0x80
 338#define DPLX_DET_FULL   0x40
 339
 340/* ------------------------------------------------------------------------- */
 341/*      Constants for Ahdoc 101 PHY                                          */
 342/* ------------------------------------------------------------------------- */
 343#define AhdocPHYID0     0x0022
 344
 345#define DiagnosticReg   18
 346#define DPLX_FULL       0x0800
 347#define Speed_100       0x0400
 348
 349/* 89/6/13 add, */
 350/* -------------------------------------------------------------------------- */
 351/*      Constants                                                             */
 352/* -------------------------------------------------------------------------- */
 353#define MarvellPHYID0           0x0141
 354#define LevelOnePHYID0          0x0013
 355
 356#define MII1000BaseTControlReg  9
 357#define MII1000BaseTStatusReg   10
 358#define SpecificReg             17
 359
 360/* for 1000BaseT Control Register */
 361#define PHYAbletoPerform1000FullDuplex  0x0200
 362#define PHYAbletoPerform1000HalfDuplex  0x0100
 363#define PHY1000AbilityMask              0x300
 364
 365// for phy specific status register, marvell phy.
 366#define SpeedMask       0x0c000
 367#define Speed_1000M     0x08000
 368#define Speed_100M      0x4000
 369#define Speed_10M       0
 370#define Full_Duplex     0x2000
 371
 372// 89/12/29 add, for phy specific status register, levelone phy, (begin)
 373#define LXT1000_100M    0x08000
 374#define LXT1000_1000M   0x0c000
 375#define LXT1000_Full    0x200
 376// 89/12/29 add, for phy specific status register, levelone phy, (end)
 377
 378/* for 3-in-1 case */
 379#define PS10            0x00080000
 380#define FD              0x00100000
 381#define PS1000          0x00010000
 382#define LinkIsUp2       0x00040000
 383
 384/* for PHY */
 385#define LinkIsUp        0x0004
 386
 387
 388struct netdev_private {
 389        /* Descriptor rings first for alignment. */
 390        struct fealnx_desc *rx_ring;
 391        struct fealnx_desc *tx_ring;
 392
 393        dma_addr_t rx_ring_dma;
 394        dma_addr_t tx_ring_dma;
 395
 396        spinlock_t lock;
 397
 398        struct net_device_stats stats;
 399
 400        /* Media monitoring timer. */
 401        struct timer_list timer;
 402
 403        /* Frequently used values: keep some adjacent for cache effect. */
 404        int flags;
 405        struct pci_dev *pci_dev;
 406        unsigned long crvalue;
 407        unsigned long bcrvalue;
 408        unsigned long imrvalue;
 409        struct fealnx_desc *cur_rx;
 410        struct fealnx_desc *lack_rxbuf;
 411        int really_rx_count;
 412        struct fealnx_desc *cur_tx;
 413        struct fealnx_desc *cur_tx_copy;
 414        int really_tx_count;
 415        int free_tx_count;
 416        unsigned int rx_buf_sz; /* Based on MTU+slack. */
 417
 418        /* These values are keep track of the transceiver/media in use. */
 419        unsigned int linkok;
 420        unsigned int line_speed;
 421        unsigned int duplexmode;
 422        unsigned int default_port:4;    /* Last dev->if_port value. */
 423        unsigned int PHYType;
 424
 425        /* MII transceiver section. */
 426        int mii_cnt;            /* MII device addresses. */
 427        unsigned char phys[2];  /* MII device addresses. */
 428        struct mii_if_info mii;
 429};
 430
 431
 432static int mdio_read(struct net_device *dev, int phy_id, int location);
 433static void mdio_write(struct net_device *dev, int phy_id, int location, int value);
 434static int netdev_open(struct net_device *dev);
 435static void getlinktype(struct net_device *dev);
 436static void getlinkstatus(struct net_device *dev);
 437static void netdev_timer(unsigned long data);
 438static void tx_timeout(struct net_device *dev);
 439static void init_ring(struct net_device *dev);
 440static int start_tx(struct sk_buff *skb, struct net_device *dev);
 441static irqreturn_t intr_handler(int irq, void *dev_instance, struct pt_regs *regs);
 442static int netdev_rx(struct net_device *dev);
 443static void set_rx_mode(struct net_device *dev);
 444static struct net_device_stats *get_stats(struct net_device *dev);
 445static int mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
 446static struct ethtool_ops netdev_ethtool_ops;
 447static int netdev_close(struct net_device *dev);
 448static void reset_rx_descriptors(struct net_device *dev);
 449
 450void stop_nic_tx(long ioaddr, long crvalue)
 451{
 452        writel(crvalue & (~0x40000), ioaddr + TCRRCR);
 453
 454        /* wait for tx stop */
 455        {
 456                int i = 0, delay = 0x1000;
 457
 458                while ((!(readl(ioaddr + TCRRCR) & 0x04000000)) && (i < delay)) {
 459                        ++i;
 460                }
 461        }
 462}
 463
 464
 465void stop_nic_rx(long ioaddr, long crvalue)
 466{
 467        writel(crvalue & (~0x1), ioaddr + TCRRCR);
 468
 469        /* wait for rx stop */
 470        {
 471                int i = 0, delay = 0x1000;
 472
 473                while ((!(readl(ioaddr + TCRRCR) & 0x00008000)) && (i < delay)) {
 474                        ++i;
 475                }
 476        }
 477}
 478
 479
 480
 481static int __devinit fealnx_init_one(struct pci_dev *pdev,
 482                                     const struct pci_device_id *ent)
 483{
 484        struct netdev_private *np;
 485        int i, option, err, irq;
 486        static int card_idx = -1;
 487        char boardname[12];
 488        long ioaddr;
 489        unsigned int chip_id = ent->driver_data;
 490        struct net_device *dev;
 491        void *ring_space;
 492        dma_addr_t ring_dma;
 493        
 494/* when built into the kernel, we only print version if device is found */
 495#ifndef MODULE
 496        static int printed_version;
 497        if (!printed_version++)
 498                printk (version);
 499#endif
 500        
 501        card_idx++;
 502        sprintf(boardname, "fealnx%d", card_idx);
 503        
 504        option = card_idx < MAX_UNITS ? options[card_idx] : 0;
 505
 506        i = pci_enable_device(pdev);
 507        if (i) return i;
 508        pci_set_master(pdev);
 509        
 510#ifdef USE_IO_OPS
 511        ioaddr = pci_resource_len(pdev, 0);
 512#else
 513        ioaddr = pci_resource_len(pdev, 1);
 514#endif
 515        if (ioaddr < MIN_REGION_SIZE) {
 516                printk(KERN_ERR "%s: region size %ld too small, aborting\n",
 517                       boardname, ioaddr);
 518                return -ENODEV;
 519        }
 520
 521        i = pci_request_regions(pdev, boardname);
 522        if (i) return i;
 523        
 524        irq = pdev->irq;
 525
 526#ifdef USE_IO_OPS
 527        ioaddr = pci_resource_start(pdev, 0);
 528#else
 529        ioaddr = (long) ioremap(pci_resource_start(pdev, 1),
 530                                pci_resource_len(pdev, 1));
 531        if (!ioaddr) {
 532                err = -ENOMEM;
 533                goto err_out_res;
 534        }
 535#endif
 536        
 537        dev = alloc_etherdev(sizeof(struct netdev_private));
 538        if (!dev) {
 539                err = -ENOMEM;
 540                goto err_out_unmap;
 541        }
 542        SET_MODULE_OWNER(dev);
 543        SET_NETDEV_DEV(dev, &pdev->dev);
 544
 545        /* read ethernet id */
 546        for (i = 0; i < 6; ++i)
 547                dev->dev_addr[i] = readb(ioaddr + PAR0 + i);
 548
 549        /* Reset the chip to erase previous misconfiguration. */
 550        writel(0x00000001, ioaddr + BCR);
 551
 552        dev->base_addr = ioaddr;
 553        dev->irq = irq;
 554
 555        /* Make certain the descriptor lists are aligned. */
 556        np = dev->priv;
 557        spin_lock_init(&np->lock);
 558        np->pci_dev = pdev;
 559        np->flags = skel_netdrv_tbl[chip_id].flags;
 560        pci_set_drvdata(pdev, dev);
 561        np->mii.dev = dev;
 562        np->mii.mdio_read = mdio_read;
 563        np->mii.mdio_write = mdio_write;
 564        np->mii.phy_id_mask = 0x1f;
 565        np->mii.reg_num_mask = 0x1f;
 566
 567        ring_space = pci_alloc_consistent(pdev, RX_TOTAL_SIZE, &ring_dma);
 568        if (!ring_space) {
 569                err = -ENOMEM;
 570                goto err_out_free_dev;
 571        }
 572        np->rx_ring = (struct fealnx_desc *)ring_space;
 573        np->rx_ring_dma = ring_dma;
 574
 575        ring_space = pci_alloc_consistent(pdev, TX_TOTAL_SIZE, &ring_dma);
 576        if (!ring_space) {
 577                err = -ENOMEM;
 578                goto err_out_free_rx;
 579        }
 580        np->tx_ring = (struct fealnx_desc *)ring_space;
 581        np->tx_ring_dma = ring_dma;
 582
 583        /* find the connected MII xcvrs */
 584        if (np->flags == HAS_MII_XCVR) {
 585                int phy, phy_idx = 0;
 586
 587                for (phy = 1; phy < 32 && phy_idx < 4; phy++) {
 588                        int mii_status = mdio_read(dev, phy, 1);
 589
 590                        if (mii_status != 0xffff && mii_status != 0x0000) {
 591                                np->phys[phy_idx++] = phy;
 592                                printk(KERN_INFO
 593                                       "%s: MII PHY found at address %d, status "
 594                                       "0x%4.4x.\n", dev->name, phy, mii_status);
 595                                /* get phy type */
 596                                {
 597                                        unsigned int data;
 598
 599                                        data = mdio_read(dev, np->phys[0], 2);
 600                                        if (data == SeeqPHYID0)
 601                                                np->PHYType = SeeqPHY;
 602                                        else if (data == AhdocPHYID0)
 603                                                np->PHYType = AhdocPHY;
 604                                        else if (data == MarvellPHYID0)
 605                                                np->PHYType = MarvellPHY;
 606                                        else if (data == MysonPHYID0)
 607                                                np->PHYType = Myson981;
 608                                        else if (data == LevelOnePHYID0)
 609                                                np->PHYType = LevelOnePHY;
 610                                        else
 611                                                np->PHYType = OtherPHY;
 612                                }
 613                        }
 614                }
 615
 616                np->mii_cnt = phy_idx;
 617                if (phy_idx == 0) {
 618                        printk(KERN_WARNING "%s: MII PHY not found -- this device may "
 619                               "not operate correctly.\n", dev->name);
 620                }
 621        } else {
 622                np->phys[0] = 32;
 623/* 89/6/23 add, (begin) */
 624                /* get phy type */
 625                if (readl(dev->base_addr + PHYIDENTIFIER) == MysonPHYID)
 626                        np->PHYType = MysonPHY;
 627                else
 628                        np->PHYType = OtherPHY;
 629        }
 630        np->mii.phy_id = np->phys[0];
 631
 632        if (dev->mem_start)
 633                option = dev->mem_start;
 634
 635        /* The lower four bits are the media type. */
 636        if (option > 0) {
 637                if (option & 0x200)
 638                        np->mii.full_duplex = 1;
 639                np->default_port = option & 15;
 640        }
 641
 642        if (card_idx < MAX_UNITS && full_duplex[card_idx] > 0)
 643                np->mii.full_duplex = full_duplex[card_idx];
 644
 645        if (np->mii.full_duplex) {
 646                printk(KERN_INFO "%s: Media type forced to Full Duplex.\n", dev->name);
 647/* 89/6/13 add, (begin) */
 648//      if (np->PHYType==MarvellPHY)
 649                if ((np->PHYType == MarvellPHY) || (np->PHYType == LevelOnePHY)) {
 650                        unsigned int data;
 651
 652                        data = mdio_read(dev, np->phys[0], 9);
 653                        data = (data & 0xfcff) | 0x0200;
 654                        mdio_write(dev, np->phys[0], 9, data);
 655                }
 656/* 89/6/13 add, (end) */
 657                if (np->flags == HAS_MII_XCVR)
 658                        mdio_write(dev, np->phys[0], MII_ADVERTISE, ADVERTISE_FULL);
 659                else
 660                        writel(ADVERTISE_FULL, dev->base_addr + ANARANLPAR);
 661                np->mii.force_media = 1;
 662        }
 663
 664        /* The chip-specific entries in the device structure. */
 665        dev->open = &netdev_open;
 666        dev->hard_start_xmit = &start_tx;
 667        dev->stop = &netdev_close;
 668        dev->get_stats = &get_stats;
 669        dev->set_multicast_list = &set_rx_mode;
 670        dev->do_ioctl = &mii_ioctl;
 671        dev->ethtool_ops = &netdev_ethtool_ops;
 672        dev->tx_timeout = tx_timeout;
 673        dev->watchdog_timeo = TX_TIMEOUT;
 674        
 675        err = register_netdev(dev);
 676        if (err)
 677                goto err_out_free_tx;
 678
 679        printk(KERN_INFO "%s: %s at 0x%lx, ",
 680               dev->name, skel_netdrv_tbl[chip_id].chip_name, ioaddr);
 681        for (i = 0; i < 5; i++)
 682                printk("%2.2x:", dev->dev_addr[i]);
 683        printk("%2.2x, IRQ %d.\n", dev->dev_addr[i], irq);
 684
 685        return 0;
 686
 687err_out_free_tx:
 688        pci_free_consistent(pdev, TX_TOTAL_SIZE, np->tx_ring, np->tx_ring_dma);
 689err_out_free_rx:
 690        pci_free_consistent(pdev, RX_TOTAL_SIZE, np->rx_ring, np->rx_ring_dma);
 691err_out_free_dev:
 692        free_netdev(dev);
 693err_out_unmap:
 694#ifndef USE_IO_OPS
 695        iounmap((void *)ioaddr);
 696err_out_res:
 697#endif
 698        pci_release_regions(pdev);
 699        return err;
 700}
 701
 702static void __devexit fealnx_remove_one(struct pci_dev *pdev)
 703{
 704        struct net_device *dev = pci_get_drvdata(pdev);
 705
 706        if (dev) {
 707                struct netdev_private *np = dev->priv;
 708
 709                pci_free_consistent(pdev, TX_TOTAL_SIZE, np->tx_ring,
 710                        np->tx_ring_dma);
 711                pci_free_consistent(pdev, RX_TOTAL_SIZE, np->rx_ring,
 712                        np->rx_ring_dma);
 713                unregister_netdev(dev);
 714#ifndef USE_IO_OPS
 715                iounmap((void *)dev->base_addr);
 716#endif
 717                free_netdev(dev);
 718                pci_release_regions(pdev);
 719                pci_set_drvdata(pdev, NULL);
 720        } else
 721                printk(KERN_ERR "fealnx: remove for unknown device\n");
 722}
 723
 724unsigned int m80x_read_tick(void)
 725/* function: Reads the Timer tick count register which decrements by 2 from  */
 726/*           65536 to 0 every 1/36.414 of a second. Each 2 decrements of the *//*           count represents 838 nsec's.                                    */
 727/* input   : none.                                                           */
 728/* output  : none.                                                           */
 729{
 730        unsigned char tmp;
 731        int value;
 732
 733        writeb((char) 0x06, 0x43);      // Command 8254 to latch T0's count
 734
 735        // now read the count.
 736        tmp = (unsigned char) readb(0x40);
 737        value = ((int) tmp) << 8;
 738        tmp = (unsigned char) readb(0x40);
 739        value |= (((int) tmp) & 0xff);
 740        return (value);
 741}
 742
 743
 744void m80x_delay(unsigned int interval)
 745/* function: to wait for a specified time.                                   */
 746/* input   : interval ... the specified time.                                */
 747/* output  : none.                                                           */
 748{
 749        unsigned int interval1, interval2, i = 0;
 750
 751        interval1 = m80x_read_tick();   // get initial value
 752        do {
 753                interval2 = m80x_read_tick();
 754                if (interval1 < interval2)
 755                        interval1 = interval2;
 756                ++i;
 757        } while (((interval1 - interval2) < (ushort) interval) && (i < 65535));
 758}
 759
 760
 761static ulong m80x_send_cmd_to_phy(long miiport, int opcode, int phyad, int regad)
 762{
 763        ulong miir;
 764        int i;
 765        unsigned int mask, data;
 766
 767        /* enable MII output */
 768        miir = (ulong) readl(miiport);
 769        miir &= 0xfffffff0;
 770
 771        miir |= MASK_MIIR_MII_WRITE + MASK_MIIR_MII_MDO;
 772
 773        /* send 32 1's preamble */
 774        for (i = 0; i < 32; i++) {
 775                /* low MDC; MDO is already high (miir) */
 776                miir &= ~MASK_MIIR_MII_MDC;
 777                writel(miir, miiport);
 778
 779                /* high MDC */
 780                miir |= MASK_MIIR_MII_MDC;
 781                writel(miir, miiport);
 782        }
 783
 784        /* calculate ST+OP+PHYAD+REGAD+TA */
 785        data = opcode | (phyad << 7) | (regad << 2);
 786
 787        /* sent out */
 788        mask = 0x8000;
 789        while (mask) {
 790                /* low MDC, prepare MDO */
 791                miir &= ~(MASK_MIIR_MII_MDC + MASK_MIIR_MII_MDO);
 792                if (mask & data)
 793                        miir |= MASK_MIIR_MII_MDO;
 794
 795                writel(miir, miiport);
 796                /* high MDC */
 797                miir |= MASK_MIIR_MII_MDC;
 798                writel(miir, miiport);
 799                m80x_delay(30);
 800
 801                /* next */
 802                mask >>= 1;
 803                if (mask == 0x2 && opcode == OP_READ)
 804                        miir &= ~MASK_MIIR_MII_WRITE;
 805        }
 806        return miir;
 807}
 808
 809
 810static int mdio_read(struct net_device *dev, int phyad, int regad)
 811{
 812        long miiport = dev->base_addr + MANAGEMENT;
 813        ulong miir;
 814        unsigned int mask, data;
 815
 816        miir = m80x_send_cmd_to_phy(miiport, OP_READ, phyad, regad);
 817
 818        /* read data */
 819        mask = 0x8000;
 820        data = 0;
 821        while (mask) {
 822                /* low MDC */
 823                miir &= ~MASK_MIIR_MII_MDC;
 824                writel(miir, miiport);
 825
 826                /* read MDI */
 827                miir = readl(miiport);
 828                if (miir & MASK_MIIR_MII_MDI)
 829                        data |= mask;
 830
 831                /* high MDC, and wait */
 832                miir |= MASK_MIIR_MII_MDC;
 833                writel(miir, miiport);
 834                m80x_delay((int) 30);
 835
 836                /* next */
 837                mask >>= 1;
 838        }
 839
 840        /* low MDC */
 841        miir &= ~MASK_MIIR_MII_MDC;
 842        writel(miir, miiport);
 843
 844        return data & 0xffff;
 845}
 846
 847
 848static void mdio_write(struct net_device *dev, int phyad, int regad, int data)
 849{
 850        long miiport = dev->base_addr + MANAGEMENT;
 851        ulong miir;
 852        unsigned int mask;
 853
 854        miir = m80x_send_cmd_to_phy(miiport, OP_WRITE, phyad, regad);
 855
 856        /* write data */
 857        mask = 0x8000;
 858        while (mask) {
 859                /* low MDC, prepare MDO */
 860                miir &= ~(MASK_MIIR_MII_MDC + MASK_MIIR_MII_MDO);
 861                if (mask & data)
 862                        miir |= MASK_MIIR_MII_MDO;
 863                writel(miir, miiport);
 864
 865                /* high MDC */
 866                miir |= MASK_MIIR_MII_MDC;
 867                writel(miir, miiport);
 868
 869                /* next */
 870                mask >>= 1;
 871        }
 872
 873        /* low MDC */
 874        miir &= ~MASK_MIIR_MII_MDC;
 875        writel(miir, miiport);
 876
 877        return;
 878}
 879
 880
 881static int netdev_open(struct net_device *dev)
 882{
 883        struct netdev_private *np = dev->priv;
 884        long ioaddr = dev->base_addr;
 885
 886        writel(0x00000001, ioaddr + BCR);       /* Reset */
 887
 888        if (request_irq(dev->irq, &intr_handler, SA_SHIRQ, dev->name, dev))
 889                return -EAGAIN;
 890
 891        init_ring(dev);
 892
 893        writel(np->rx_ring_dma, ioaddr + RXLBA);
 894        writel(np->tx_ring_dma, ioaddr + TXLBA);
 895
 896        /* Initialize other registers. */
 897        /* Configure the PCI bus bursts and FIFO thresholds.
 898           486: Set 8 longword burst.
 899           586: no burst limit.
 900           Burst length 5:3
 901           0 0 0   1
 902           0 0 1   4
 903           0 1 0   8
 904           0 1 1   16
 905           1 0 0   32
 906           1 0 1   64
 907           1 1 0   128
 908           1 1 1   256
 909           Wait the specified 50 PCI cycles after a reset by initializing
 910           Tx and Rx queues and the address filter list.
 911           FIXME (Ueimor): optimistic for alpha + posted writes ? */
 912#if defined(__powerpc__) || defined(__sparc__)
 913// 89/9/1 modify, 
 914//   np->bcrvalue=0x04 | 0x0x38;  /* big-endian, 256 burst length */
 915        np->bcrvalue = 0x04 | 0x10;     /* big-endian, tx 8 burst length */
 916        np->crvalue = 0xe00;    /* rx 128 burst length */
 917#elif defined(__alpha__) || defined(__x86_64__)
 918// 89/9/1 modify, 
 919//   np->bcrvalue=0x38;           /* little-endian, 256 burst length */
 920        np->bcrvalue = 0x10;    /* little-endian, 8 burst length */
 921        np->crvalue = 0xe00;    /* rx 128 burst length */
 922#elif defined(__i386__)
 923#if defined(MODULE)
 924// 89/9/1 modify, 
 925//   np->bcrvalue=0x38;           /* little-endian, 256 burst length */
 926        np->bcrvalue = 0x10;    /* little-endian, 8 burst length */
 927        np->crvalue = 0xe00;    /* rx 128 burst length */
 928#else
 929        /* When not a module we can work around broken '486 PCI boards. */
 930#define x86 boot_cpu_data.x86
 931// 89/9/1 modify, 
 932//   np->bcrvalue=(x86 <= 4 ? 0x10 : 0x38);
 933        np->bcrvalue = 0x10;
 934        np->crvalue = (x86 <= 4 ? 0xa00 : 0xe00);
 935        if (x86 <= 4)
 936                printk(KERN_INFO "%s: This is a 386/486 PCI system, setting burst "
 937                       "length to %x.\n", dev->name, (x86 <= 4 ? 0x10 : 0x38));
 938#endif
 939#else
 940// 89/9/1 modify,
 941//   np->bcrvalue=0x38;
 942        np->bcrvalue = 0x10;
 943        np->crvalue = 0xe00;    /* rx 128 burst length */
 944#warning Processor architecture undefined!
 945#endif
 946// 89/12/29 add,
 947// 90/1/16 modify,
 948//   np->imrvalue=FBE|TUNF|CNTOVF|RBU|TI|RI;
 949        np->imrvalue = TUNF | CNTOVF | RBU | TI | RI;
 950        if (np->pci_dev->device == 0x891) {
 951                np->bcrvalue |= 0x200;  /* set PROG bit */
 952                np->crvalue |= 0x02000000;      /* set enhanced bit */
 953                np->imrvalue |= ETI;
 954        }
 955        writel(np->bcrvalue, ioaddr + BCR);
 956
 957        if (dev->if_port == 0)
 958                dev->if_port = np->default_port;
 959
 960        writel(0, dev->base_addr + RXPDR);
 961// 89/9/1 modify,
 962//   np->crvalue = 0x00e40001;    /* tx store and forward, tx/rx enable */
 963        np->crvalue |= 0x00e40001;      /* tx store and forward, tx/rx enable */
 964        np->mii.full_duplex = np->mii.force_media;
 965        getlinkstatus(dev);
 966        if (np->linkok)
 967                getlinktype(dev);
 968        set_rx_mode(dev);
 969
 970        netif_start_queue(dev);
 971
 972        /* Clear and Enable interrupts by setting the interrupt mask. */
 973        writel(FBE | TUNF | CNTOVF | RBU | TI | RI, ioaddr + ISR);
 974        writel(np->imrvalue, ioaddr + IMR);
 975
 976        if (debug)
 977                printk(KERN_DEBUG "%s: Done netdev_open().\n", dev->name);
 978
 979        /* Set the timer to check for link beat. */
 980        init_timer(&np->timer);
 981        np->timer.expires = RUN_AT(3 * HZ);
 982        np->timer.data = (unsigned long) dev;
 983        np->timer.function = &netdev_timer;
 984
 985        /* timer handler */
 986        add_timer(&np->timer);
 987
 988        return 0;
 989}
 990
 991
 992static void getlinkstatus(struct net_device *dev)
 993/* function: Routine will read MII Status Register to get link status.       */
 994/* input   : dev... pointer to the adapter block.                            */
 995/* output  : none.                                                           */
 996{
 997        struct netdev_private *np = dev->priv;
 998        unsigned int i, DelayTime = 0x1000;
 999
1000        np->linkok = 0;
1001
1002        if (np->PHYType == MysonPHY) {
1003                for (i = 0; i < DelayTime; ++i) {
1004                        if (readl(dev->base_addr + BMCRSR) & LinkIsUp2) {
1005                                np->linkok = 1;
1006                                return;
1007                        }
1008                        // delay
1009                        m80x_delay(100);
1010                }
1011        } else {
1012                for (i = 0; i < DelayTime; ++i) {
1013                        if (mdio_read(dev, np->phys[0], MII_BMSR) & BMSR_LSTATUS) {
1014                                np->linkok = 1;
1015                                return;
1016                        }
1017                        // delay
1018                        m80x_delay(100);
1019                }
1020        }
1021}
1022
1023
1024static void getlinktype(struct net_device *dev)
1025{
1026        struct netdev_private *np = dev->priv;
1027
1028        if (np->PHYType == MysonPHY) {  /* 3-in-1 case */
1029                if (readl(dev->base_addr + TCRRCR) & FD)
1030                        np->duplexmode = 2;     /* full duplex */
1031                else
1032                        np->duplexmode = 1;     /* half duplex */
1033                if (readl(dev->base_addr + TCRRCR) & PS10)
1034                        np->line_speed = 1;     /* 10M */
1035                else
1036                        np->line_speed = 2;     /* 100M */
1037        } else {
1038                if (np->PHYType == SeeqPHY) {   /* this PHY is SEEQ 80225 */
1039                        unsigned int data;
1040
1041                        data = mdio_read(dev, np->phys[0], MIIRegister18);
1042                        if (data & SPD_DET_100)
1043                                np->line_speed = 2;     /* 100M */
1044                        else
1045                                np->line_speed = 1;     /* 10M */
1046                        if (data & DPLX_DET_FULL)
1047                                np->duplexmode = 2;     /* full duplex mode */
1048                        else
1049                                np->duplexmode = 1;     /* half duplex mode */
1050                } else if (np->PHYType == AhdocPHY) {
1051                        unsigned int data;
1052
1053                        data = mdio_read(dev, np->phys[0], DiagnosticReg);
1054                        if (data & Speed_100)
1055                                np->line_speed = 2;     /* 100M */
1056                        else
1057                                np->line_speed = 1;     /* 10M */
1058                        if (data & DPLX_FULL)
1059                                np->duplexmode = 2;     /* full duplex mode */
1060                        else
1061                                np->duplexmode = 1;     /* half duplex mode */
1062                }
1063/* 89/6/13 add, (begin) */
1064                else if (np->PHYType == MarvellPHY) {
1065                        unsigned int data;
1066
1067                        data = mdio_read(dev, np->phys[0], SpecificReg);
1068                        if (data & Full_Duplex)
1069                                np->duplexmode = 2;     /* full duplex mode */
1070                        else
1071                                np->duplexmode = 1;     /* half duplex mode */
1072                        data &= SpeedMask;
1073                        if (data == Speed_1000M)
1074                                np->line_speed = 3;     /* 1000M */
1075                        else if (data == Speed_100M)
1076                                np->line_speed = 2;     /* 100M */
1077                        else
1078                                np->line_speed = 1;     /* 10M */
1079                }
1080/* 89/6/13 add, (end) */
1081/* 89/7/27 add, (begin) */
1082                else if (np->PHYType == Myson981) {
1083                        unsigned int data;
1084
1085                        data = mdio_read(dev, np->phys[0], StatusRegister);
1086
1087                        if (data & SPEED100)
1088                                np->line_speed = 2;
1089                        else
1090                                np->line_speed = 1;
1091
1092                        if (data & FULLMODE)
1093                                np->duplexmode = 2;
1094                        else
1095                                np->duplexmode = 1;
1096                }
1097/* 89/7/27 add, (end) */
1098/* 89/12/29 add */
1099                else if (np->PHYType == LevelOnePHY) {
1100                        unsigned int data;
1101
1102                        data = mdio_read(dev, np->phys[0], SpecificReg);
1103                        if (data & LXT1000_Full)
1104                                np->duplexmode = 2;     /* full duplex mode */
1105                        else
1106                                np->duplexmode = 1;     /* half duplex mode */
1107                        data &= SpeedMask;
1108                        if (data == LXT1000_1000M)
1109                                np->line_speed = 3;     /* 1000M */
1110                        else if (data == LXT1000_100M)
1111                                np->line_speed = 2;     /* 100M */
1112                        else
1113                                np->line_speed = 1;     /* 10M */
1114                }
1115                // chage crvalue
1116                // np->crvalue&=(~PS10)&(~FD);
1117                np->crvalue &= (~PS10) & (~FD) & (~PS1000);
1118                if (np->line_speed == 1)
1119                        np->crvalue |= PS10;
1120                else if (np->line_speed == 3)
1121                        np->crvalue |= PS1000;
1122                if (np->duplexmode == 2)
1123                        np->crvalue |= FD;
1124        }
1125}
1126
1127
1128static void allocate_rx_buffers(struct net_device *dev)
1129{
1130        struct netdev_private *np = dev->priv;
1131
1132        /*  allocate skb for rx buffers */
1133        while (np->really_rx_count != RX_RING_SIZE) {
1134                struct sk_buff *skb;
1135
1136                skb = dev_alloc_skb(np->rx_buf_sz);
1137                np->lack_rxbuf->skbuff = skb;
1138
1139                if (skb == NULL)
1140                        break;  /* Better luck next round. */
1141
1142                skb->dev = dev; /* Mark as being used by this device. */
1143                np->lack_rxbuf->buffer = pci_map_single(np->pci_dev, skb->tail,
1144                        np->rx_buf_sz, PCI_DMA_FROMDEVICE);
1145                np->lack_rxbuf = np->lack_rxbuf->next_desc_logical;
1146                ++np->really_rx_count;
1147        }
1148}
1149
1150
1151static void netdev_timer(unsigned long data)
1152{
1153        struct net_device *dev = (struct net_device *) data;
1154        struct netdev_private *np = dev->priv;
1155        long ioaddr = dev->base_addr;
1156        int next_tick = 10 * HZ;
1157        int old_crvalue = np->crvalue;
1158        unsigned int old_linkok = np->linkok;
1159
1160        if (debug)
1161                printk(KERN_DEBUG "%s: Media selection timer tick, status %8.8x "
1162                       "config %8.8x.\n", dev->name, readl(ioaddr + ISR),
1163                       readl(ioaddr + TCRRCR));
1164
1165        if (np->flags == HAS_MII_XCVR) {
1166                getlinkstatus(dev);
1167                if ((old_linkok == 0) && (np->linkok == 1)) {   /* we need to detect the media type again */
1168                        getlinktype(dev);
1169                        if (np->crvalue != old_crvalue) {
1170                                stop_nic_tx(ioaddr, np->crvalue);
1171                                stop_nic_rx(ioaddr, np->crvalue & (~0x40000));
1172                                writel(np->crvalue, ioaddr + TCRRCR);
1173                        }
1174                }
1175        }
1176
1177        allocate_rx_buffers(dev);
1178
1179        np->timer.expires = RUN_AT(next_tick);
1180        add_timer(&np->timer);
1181}
1182
1183
1184static void tx_timeout(struct net_device *dev)
1185{
1186        struct netdev_private *np = dev->priv;
1187        long ioaddr = dev->base_addr;
1188        int i;
1189
1190        printk(KERN_WARNING "%s: Transmit timed out, status %8.8x,"
1191               " resetting...\n", dev->name, readl(ioaddr + ISR));
1192
1193        {
1194
1195                printk(KERN_DEBUG "  Rx ring %p: ", np->rx_ring);
1196                for (i = 0; i < RX_RING_SIZE; i++)
1197                        printk(" %8.8x", (unsigned int) np->rx_ring[i].status);
1198                printk("\n" KERN_DEBUG "  Tx ring %p: ", np->tx_ring);
1199                for (i = 0; i < TX_RING_SIZE; i++)
1200                        printk(" %4.4x", np->tx_ring[i].status);
1201                printk("\n");
1202        }
1203
1204        /* Reinit. Gross */
1205
1206        /* Reset the chip's Tx and Rx processes. */
1207        stop_nic_tx(ioaddr, 0);
1208        reset_rx_descriptors(dev);
1209
1210        /* Disable interrupts by clearing the interrupt mask. */
1211        writel(0x0000, ioaddr + IMR);
1212
1213        /* Reset the chip to erase previous misconfiguration. */
1214        writel(0x00000001, ioaddr + BCR);
1215
1216        /* Ueimor: wait for 50 PCI cycles (and flush posted writes btw). 
1217           We surely wait too long (address+data phase). Who cares ? */
1218        for (i = 0; i < 50; i++) {
1219                readl(ioaddr + BCR);
1220                rmb();
1221        }
1222
1223        writel((np->cur_tx - np->tx_ring)*sizeof(struct fealnx_desc) +
1224                np->tx_ring_dma, ioaddr + TXLBA);
1225        writel((np->cur_rx - np->rx_ring)*sizeof(struct fealnx_desc) +
1226                np->rx_ring_dma, ioaddr + RXLBA);
1227
1228        writel(np->bcrvalue, ioaddr + BCR);
1229
1230        writel(0, dev->base_addr + RXPDR);
1231        set_rx_mode(dev);
1232        /* Clear and Enable interrupts by setting the interrupt mask. */
1233        writel(FBE | TUNF | CNTOVF | RBU | TI | RI, ioaddr + ISR);
1234        writel(np->imrvalue, ioaddr + IMR);
1235
1236        writel(0, dev->base_addr + TXPDR);
1237
1238        dev->trans_start = jiffies;
1239        np->stats.tx_errors++;
1240
1241        return;
1242}
1243
1244
1245/* Initialize the Rx and Tx rings, along with various 'dev' bits. */
1246static void init_ring(struct net_device *dev)
1247{
1248        struct netdev_private *np = dev->priv;
1249        int i;
1250
1251        /* initialize rx variables */
1252        np->rx_buf_sz = (dev->mtu <= 1500 ? PKT_BUF_SZ : dev->mtu + 32);
1253        np->cur_rx = &np->rx_ring[0];
1254        np->lack_rxbuf = NULL;
1255        np->really_rx_count = 0;
1256
1257        /* initial rx descriptors. */
1258        for (i = 0; i < RX_RING_SIZE; i++) {
1259                np->rx_ring[i].status = 0;
1260                np->rx_ring[i].control = np->rx_buf_sz << RBSShift;
1261                np->rx_ring[i].next_desc = np->rx_ring_dma +
1262                        (i + 1)*sizeof(struct fealnx_desc);
1263                np->rx_ring[i].next_desc_logical = &np->rx_ring[i + 1];
1264                np->rx_ring[i].skbuff = NULL;
1265        }
1266
1267        /* for the last rx descriptor */
1268        np->rx_ring[i - 1].next_desc = np->rx_ring_dma;
1269        np->rx_ring[i - 1].next_desc_logical = np->rx_ring;
1270
1271        /* allocate skb for rx buffers */
1272        for (i = 0; i < RX_RING_SIZE; i++) {
1273                struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz);
1274
1275                if (skb == NULL) {
1276                        np->lack_rxbuf = &np->rx_ring[i];
1277                        break;
1278                }
1279
1280                ++np->really_rx_count;
1281                np->rx_ring[i].skbuff = skb;
1282                skb->dev = dev; /* Mark as being used by this device. */
1283                np->rx_ring[i].buffer = pci_map_single(np->pci_dev, skb->tail,
1284                        np->rx_buf_sz, PCI_DMA_FROMDEVICE);
1285                np->rx_ring[i].status = RXOWN;
1286                np->rx_ring[i].control |= RXIC;
1287        }
1288
1289        /* initialize tx variables */
1290        np->cur_tx = &np->tx_ring[0];
1291        np->cur_tx_copy = &np->tx_ring[0];
1292        np->really_tx_count = 0;
1293        np->free_tx_count = TX_RING_SIZE;
1294
1295        for (i = 0; i < TX_RING_SIZE; i++) {
1296                np->tx_ring[i].status = 0;
1297                np->tx_ring[i].next_desc = np->tx_ring_dma +
1298                        (i + 1)*sizeof(struct fealnx_desc);
1299                np->tx_ring[i].next_desc_logical = &np->tx_ring[i + 1];
1300                np->tx_ring[i].skbuff = NULL;
1301        }
1302
1303        /* for the last tx descriptor */
1304        np->tx_ring[i - 1].next_desc = np->tx_ring_dma;
1305        np->tx_ring[i - 1].next_desc_logical = &np->tx_ring[0];
1306
1307        return;
1308}
1309
1310
1311static int start_tx(struct sk_buff *skb, struct net_device *dev)
1312{
1313        struct netdev_private *np = dev->priv;
1314
1315        np->cur_tx_copy->skbuff = skb;
1316
1317#define one_buffer
1318#define BPT 1022
1319#if defined(one_buffer)
1320        np->cur_tx_copy->buffer = pci_map_single(np->pci_dev, skb->data,
1321                skb->len, PCI_DMA_TODEVICE);
1322        np->cur_tx_copy->control = TXIC | TXLD | TXFD | CRCEnable | PADEnable;
1323        np->cur_tx_copy->control |= (skb->len << PKTSShift);    /* pkt size */
1324        np->cur_tx_copy->control |= (skb->len << TBSShift);     /* buffer size */
1325// 89/12/29 add,
1326        if (np->pci_dev->device == 0x891)
1327                np->cur_tx_copy->control |= ETIControl | RetryTxLC;
1328        np->cur_tx_copy->status = TXOWN;
1329        np->cur_tx_copy = np->cur_tx_copy->next_desc_logical;
1330        --np->free_tx_count;
1331#elif defined(two_buffer)
1332        if (skb->len > BPT) {
1333                struct fealnx_desc *next;
1334
1335                /* for the first descriptor */
1336                np->cur_tx_copy->buffer = pci_map_single(np->pci_dev, skb->data,
1337                        BPT, PCI_DMA_TODEVICE);
1338                np->cur_tx_copy->control = TXIC | TXFD | CRCEnable | PADEnable;
1339                np->cur_tx_copy->control |= (skb->len << PKTSShift);    /* pkt size */
1340                np->cur_tx_copy->control |= (BPT << TBSShift);  /* buffer size */
1341
1342                /* for the last descriptor */
1343                next = (struct fealnx *) np->cur_tx_copy.next_desc_logical;
1344                next->skbuff = skb;
1345                next->control = TXIC | TXLD | CRCEnable | PADEnable;
1346                next->control |= (skb->len << PKTSShift);       /* pkt size */
1347                next->control |= ((skb->len - BPT) << TBSShift);        /* buf size */
1348// 89/12/29 add,
1349                if (np->pci_dev->device == 0x891)
1350                        np->cur_tx_copy->control |= ETIControl | RetryTxLC;
1351                next->buffer = pci_map_single(ep->pci_dev, skb->data + BPT,
1352                                skb->len - BPT, PCI_DMA_TODEVICE);
1353
1354                next->status = TXOWN;
1355                np->cur_tx_copy->status = TXOWN;
1356
1357                np->cur_tx_copy = next->next_desc_logical;
1358                np->free_tx_count -= 2;
1359        } else {
1360                np->cur_tx_copy->buffer = pci_map_single(np->pci_dev, skb->data,
1361                        skb->len, PCI_DMA_TODEVICE);
1362                np->cur_tx_copy->control = TXIC | TXLD | TXFD | CRCEnable | PADEnable;
1363                np->cur_tx_copy->control |= (skb->len << PKTSShift);    /* pkt size */
1364                np->cur_tx_copy->control |= (skb->len << TBSShift);     /* buffer size */
1365// 89/12/29 add,
1366                if (np->pci_dev->device == 0x891)
1367                        np->cur_tx_copy->control |= ETIControl | RetryTxLC;
1368                np->cur_tx_copy->status = TXOWN;
1369                np->cur_tx_copy = np->cur_tx_copy->next_desc_logical;
1370                --np->free_tx_count;
1371        }
1372#endif
1373
1374        if (np->free_tx_count < 2)
1375                netif_stop_queue(dev);
1376        ++np->really_tx_count;
1377        writel(0, dev->base_addr + TXPDR);
1378        dev->trans_start = jiffies;
1379
1380        return 0;
1381}
1382
1383
1384void free_one_rx_descriptor(struct netdev_private *np)
1385{
1386        if (np->really_rx_count == RX_RING_SIZE)
1387                np->cur_rx->status = RXOWN;
1388        else {
1389                np->lack_rxbuf->skbuff = np->cur_rx->skbuff;
1390                np->lack_rxbuf->buffer = np->cur_rx->buffer;
1391                np->lack_rxbuf->status = RXOWN;
1392                ++np->really_rx_count;
1393                np->lack_rxbuf = np->lack_rxbuf->next_desc_logical;
1394        }
1395        np->cur_rx = np->cur_rx->next_desc_logical;
1396}
1397
1398
1399void reset_rx_descriptors(struct net_device *dev)
1400{
1401        struct netdev_private *np = dev->priv;
1402
1403        stop_nic_rx(dev->base_addr, np->crvalue);
1404
1405        while (!(np->cur_rx->status & RXOWN))
1406                free_one_rx_descriptor(np);
1407
1408        allocate_rx_buffers(dev);
1409
1410        writel(np->rx_ring_dma + (np->cur_rx - np->rx_ring),
1411                dev->base_addr + RXLBA);
1412        writel(np->crvalue, dev->base_addr + TCRRCR);
1413}
1414
1415
1416/* The interrupt handler does all of the Rx thread work and cleans up
1417   after the Tx thread. */
1418static irqreturn_t intr_handler(int irq, void *dev_instance, struct pt_regs *rgs)
1419{
1420        struct net_device *dev = (struct net_device *) dev_instance;
1421        struct netdev_private *np = dev->priv;
1422        long ioaddr, boguscnt = max_interrupt_work;
1423        unsigned int num_tx = 0;
1424        int handled = 0;
1425
1426        writel(0, dev->base_addr + IMR);
1427
1428        ioaddr = dev->base_addr;
1429        np = (struct netdev_private *) dev->priv;
1430
1431        do {
1432                u32 intr_status = readl(ioaddr + ISR);
1433
1434                /* Acknowledge all of the current interrupt sources ASAP. */
1435                writel(intr_status, ioaddr + ISR);
1436
1437                if (debug)
1438                        printk(KERN_DEBUG "%s: Interrupt, status %4.4x.\n", dev->name,
1439                               intr_status);
1440
1441                if (!(intr_status & np->imrvalue))
1442                        break;
1443
1444                handled = 1;
1445
1446// 90/1/16 delete,
1447//
1448//      if (intr_status & FBE)
1449//      {   /* fatal error */
1450//          stop_nic_tx(ioaddr, 0);
1451//          stop_nic_rx(ioaddr, 0);
1452//          break;
1453//      };
1454
1455                if (intr_status & TUNF)
1456                        writel(0, ioaddr + TXPDR);
1457
1458                if (intr_status & CNTOVF) {
1459                        /* missed pkts */
1460                        np->stats.rx_missed_errors += readl(ioaddr + TALLY) & 0x7fff;
1461
1462                        /* crc error */
1463                        np->stats.rx_crc_errors +=
1464                            (readl(ioaddr + TALLY) & 0x7fff0000) >> 16;
1465                }
1466
1467                if (intr_status & (RI | RBU)) {
1468                        if (intr_status & RI)
1469                                netdev_rx(dev);
1470                        else
1471                                reset_rx_descriptors(dev);
1472                }
1473
1474                while (np->really_tx_count) {
1475                        long tx_status = np->cur_tx->status;
1476                        long tx_control = np->cur_tx->control;
1477
1478                        if (!(tx_control & TXLD)) {     /* this pkt is combined by two tx descriptors */
1479                                struct fealnx_desc *next;
1480
1481                                next = np->cur_tx->next_desc_logical;
1482                                tx_status = next->status;
1483                                tx_control = next->control;
1484                        }
1485
1486                        if (tx_status & TXOWN)
1487                                break;
1488
1489                        if (!(np->crvalue & 0x02000000)) {
1490                                if (tx_status & (CSL | LC | EC | UDF | HF)) {
1491                                        np->stats.tx_errors++;
1492                                        if (tx_status & EC)
1493                                                np->stats.tx_aborted_errors++;
1494                                        if (tx_status & CSL)
1495                                                np->stats.tx_carrier_errors++;
1496                                        if (tx_status & LC)
1497                                                np->stats.tx_window_errors++;
1498                                        if (tx_status & UDF)
1499                                                np->stats.tx_fifo_errors++;
1500                                        if ((tx_status & HF) && np->mii.full_duplex == 0)
1501                                                np->stats.tx_heartbeat_errors++;
1502
1503                                } else {
1504                                        np->stats.tx_bytes +=
1505                                            ((tx_control & PKTSMask) >> PKTSShift);
1506
1507                                        np->stats.collisions +=
1508                                            ((tx_status & NCRMask) >> NCRShift);
1509                                        np->stats.tx_packets++;
1510                                }
1511                        } else {
1512                                np->stats.tx_bytes +=
1513                                    ((tx_control & PKTSMask) >> PKTSShift);
1514                                np->stats.tx_packets++;
1515                        }
1516
1517                        /* Free the original skb. */
1518                        pci_unmap_single(np->pci_dev, np->cur_tx->buffer,
1519                                np->cur_tx->skbuff->len, PCI_DMA_TODEVICE);
1520                        dev_kfree_skb_irq(np->cur_tx->skbuff);
1521                        np->cur_tx->skbuff = NULL;
1522                        --np->really_tx_count;
1523                        if (np->cur_tx->control & TXLD) {
1524                                np->cur_tx = np->cur_tx->next_desc_logical;
1525                                ++np->free_tx_count;
1526                        } else {
1527                                np->cur_tx = np->cur_tx->next_desc_logical;
1528                                np->cur_tx = np->cur_tx->next_desc_logical;
1529                                np->free_tx_count += 2;
1530                        }
1531                        num_tx++;
1532                }               /* end of for loop */
1533                
1534                if (num_tx && np->free_tx_count >= 2)
1535                        netif_wake_queue(dev);
1536
1537                /* read transmit status for enhanced mode only */
1538                if (np->crvalue & 0x02000000) {
1539                        long data;
1540
1541                        data = readl(ioaddr + TSR);
1542                        np->stats.tx_errors += (data & 0xff000000) >> 24;
1543                        np->stats.tx_aborted_errors += (data & 0xff000000) >> 24;
1544                        np->stats.tx_window_errors += (data & 0x00ff0000) >> 16;
1545                        np->stats.collisions += (data & 0x0000ffff);
1546                }
1547
1548                if (--boguscnt < 0) {
1549                        printk(KERN_WARNING "%s: Too much work at interrupt, "
1550                               "status=0x%4.4x.\n", dev->name, intr_status);
1551                        break;
1552                }
1553        } while (1);
1554
1555        /* read the tally counters */
1556        /* missed pkts */
1557        np->stats.rx_missed_errors += readl(ioaddr + TALLY) & 0x7fff;
1558
1559        /* crc error */
1560        np->stats.rx_crc_errors += (readl(ioaddr + TALLY) & 0x7fff0000) >> 16;
1561
1562        if (debug)
1563                printk(KERN_DEBUG "%s: exiting interrupt, status=%#4.4x.\n",
1564                       dev->name, readl(ioaddr + ISR));
1565
1566        writel(np->imrvalue, ioaddr + IMR);
1567
1568        return IRQ_RETVAL(handled);
1569}
1570
1571
1572/* This routine is logically part of the interrupt handler, but separated
1573   for clarity and better register allocation. */
1574static int netdev_rx(struct net_device *dev)
1575{
1576        struct netdev_private *np = dev->priv;
1577
1578        /* If EOP is set on the next entry, it's a new packet. Send it up. */
1579        while (!(np->cur_rx->status & RXOWN)) {
1580                s32 rx_status = np->cur_rx->status;
1581
1582                if (np->really_rx_count == 0)
1583                        break;
1584
1585                if (debug)
1586                        printk(KERN_DEBUG "  netdev_rx() status was %8.8x.\n", rx_status);
1587
1588                if ((!((rx_status & RXFSD) && (rx_status & RXLSD)))
1589                    || (rx_status & ErrorSummary)) {
1590                        if (rx_status & ErrorSummary) { /* there was a fatal error */
1591                                if (debug)
1592                                        printk(KERN_DEBUG
1593                                               "%s: Receive error, Rx status %8.8x.\n",
1594                                               dev->name, rx_status);
1595
1596                                np->stats.rx_errors++;  /* end of a packet. */
1597                                if (rx_status & (LONG | RUNT))
1598                                        np->stats.rx_length_errors++;
1599                                if (rx_status & RXER)
1600                                        np->stats.rx_frame_errors++;
1601                                if (rx_status & CRC)
1602                                        np->stats.rx_crc_errors++;
1603                        } else {
1604                                int need_to_reset = 0;
1605                                int desno = 0;
1606
1607                                if (rx_status & RXFSD) {        /* this pkt is too long, over one rx buffer */
1608                                        struct fealnx_desc *cur;
1609
1610                                        /* check this packet is received completely? */
1611                                        cur = np->cur_rx;
1612                                        while (desno <= np->really_rx_count) {
1613                                                ++desno;
1614                                                if ((!(cur->status & RXOWN))
1615                                                    && (cur->status & RXLSD))
1616                                                        break;
1617                                                /* goto next rx descriptor */
1618                                                cur = cur->next_desc_logical;
1619                                        }
1620                                        if (desno > np->really_rx_count)
1621                                                need_to_reset = 1;
1622                                } else  /* RXLSD did not find, something error */
1623                                        need_to_reset = 1;
1624
1625                                if (need_to_reset == 0) {
1626                                        int i;
1627
1628                                        np->stats.rx_length_errors++;
1629
1630                                        /* free all rx descriptors related this long pkt */
1631                                        for (i = 0; i < desno; ++i)
1632                                                free_one_rx_descriptor(np);
1633                                        continue;
1634                                } else {        /* something error, need to reset this chip */
1635                                        reset_rx_descriptors(dev);
1636                                }
1637                                break;  /* exit the while loop */
1638                        }
1639                } else {        /* this received pkt is ok */
1640
1641                        struct sk_buff *skb;
1642                        /* Omit the four octet CRC from the length. */
1643                        short pkt_len = ((rx_status & FLNGMASK) >> FLNGShift) - 4;
1644
1645#ifndef final_version
1646                        if (debug)
1647                                printk(KERN_DEBUG "  netdev_rx() normal Rx pkt length %d"
1648                                       " status %x.\n", pkt_len, rx_status);
1649#endif
1650                        pci_dma_sync_single(np->pci_dev, np->cur_rx->buffer,
1651                                np->rx_buf_sz, PCI_DMA_FROMDEVICE);
1652                        pci_unmap_single(np->pci_dev, np->cur_rx->buffer,
1653                                np->rx_buf_sz, PCI_DMA_FROMDEVICE);
1654
1655                        /* Check if the packet is long enough to accept without copying
1656                           to a minimally-sized skbuff. */
1657                        if (pkt_len < rx_copybreak &&
1658                            (skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
1659                                skb->dev = dev;
1660                                skb_reserve(skb, 2);    /* 16 byte align the IP header */
1661                                /* Call copy + cksum if available. */
1662
1663#if ! defined(__alpha__)
1664                                eth_copy_and_sum(skb, 
1665                                        np->cur_rx->skbuff->tail, pkt_len, 0);
1666                                skb_put(skb, pkt_len);
1667#else
1668                                memcpy(skb_put(skb, pkt_len),
1669                                        np->cur_rx->skbuff->tail, pkt_len);
1670#endif
1671                        } else {
1672                                skb_put(skb = np->cur_rx->skbuff, pkt_len);
1673                                np->cur_rx->skbuff = NULL;
1674                                if (np->really_rx_count == RX_RING_SIZE)
1675                                        np->lack_rxbuf = np->cur_rx;
1676                                --np->really_rx_count;
1677                        }
1678                        skb->protocol = eth_type_trans(skb, dev);
1679                        netif_rx(skb);
1680                        dev->last_rx = jiffies;
1681                        np->stats.rx_packets++;
1682                        np->stats.rx_bytes += pkt_len;
1683                }
1684
1685                if (np->cur_rx->skbuff == NULL) {
1686                        struct sk_buff *skb;
1687
1688                        skb = dev_alloc_skb(np->rx_buf_sz);
1689
1690                        if (skb != NULL) {
1691                                skb->dev = dev; /* Mark as being used by this device. */
1692                                np->cur_rx->buffer = pci_map_single(np->pci_dev, skb->tail,
1693                                        np->rx_buf_sz, PCI_DMA_FROMDEVICE);
1694                                np->cur_rx->skbuff = skb;
1695                                ++np->really_rx_count;
1696                        }
1697                }
1698
1699                if (np->cur_rx->skbuff != NULL)
1700                        free_one_rx_descriptor(np);
1701        }                       /* end of while loop */
1702
1703        /*  allocate skb for rx buffers */
1704        allocate_rx_buffers(dev);
1705
1706        return 0;
1707}
1708
1709
1710static struct net_device_stats *get_stats(struct net_device *dev)
1711{
1712        long ioaddr = dev->base_addr;
1713        struct netdev_private *np = dev->priv;
1714
1715        /* The chip only need report frame silently dropped. */
1716        if (netif_running(dev)) {
1717                np->stats.rx_missed_errors += readl(ioaddr + TALLY) & 0x7fff;
1718                np->stats.rx_crc_errors += (readl(ioaddr + TALLY) & 0x7fff0000) >> 16;
1719        }
1720
1721        return &np->stats;
1722}
1723
1724static void set_rx_mode(struct net_device *dev)
1725{
1726        struct netdev_private *np = dev->priv;
1727        long ioaddr = dev->base_addr;
1728        u32 mc_filter[2];       /* Multicast hash filter */
1729        u32 rx_mode;
1730
1731        if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
1732                /* Unconditionally log net taps. */
1733                printk(KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
1734                memset(mc_filter, 0xff, sizeof(mc_filter));
1735                rx_mode = PROM | AB | AM;
1736        } else if ((dev->mc_count > multicast_filter_limit)
1737                   || (dev->flags & IFF_ALLMULTI)) {
1738                /* Too many to match, or accept all multicasts. */
1739                memset(mc_filter, 0xff, sizeof(mc_filter));
1740                rx_mode = AB | AM;
1741        } else {
1742                struct dev_mc_list *mclist;
1743                int i;
1744
1745                memset(mc_filter, 0, sizeof(mc_filter));
1746                for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
1747                     i++, mclist = mclist->next) {
1748                        unsigned int bit;
1749                        bit = (ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26) ^ 0x3F;
1750                        mc_filter[bit >> 5] |= (1 << bit);
1751                }
1752                rx_mode = AB | AM;
1753        }
1754
1755        stop_nic_tx(ioaddr, np->crvalue);
1756        stop_nic_rx(ioaddr, np->crvalue & (~0x40000));
1757
1758        writel(mc_filter[0], ioaddr + MAR0);
1759        writel(mc_filter[1], ioaddr + MAR1);
1760        np->crvalue &= ~RxModeMask;
1761        np->crvalue |= rx_mode;
1762        writel(np->crvalue, ioaddr + TCRRCR);
1763}
1764
1765static void netdev_get_drvinfo (struct net_device *dev, struct ethtool_drvinfo *info)
1766{
1767        struct netdev_private *np = dev->priv;
1768
1769        strcpy (info->driver, DRV_NAME);
1770        strcpy (info->version, DRV_VERSION);
1771        strcpy (info->bus_info, pci_name(np->pci_dev));
1772}
1773
1774static int netdev_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
1775{
1776        struct netdev_private *np = dev->priv;
1777        int rc;
1778
1779        spin_lock_irq(&np->lock);
1780        rc = mii_ethtool_gset(&np->mii, cmd);
1781        spin_unlock_irq(&np->lock);
1782
1783        return rc;
1784}
1785
1786static int netdev_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
1787{
1788        struct netdev_private *np = dev->priv;
1789        int rc;
1790
1791        spin_lock_irq(&np->lock);
1792        rc = mii_ethtool_sset(&np->mii, cmd);
1793        spin_unlock_irq(&np->lock);
1794
1795        return rc;
1796}
1797
1798static int netdev_nway_reset(struct net_device *dev)
1799{
1800        struct netdev_private *np = dev->priv;
1801        return mii_nway_restart(&np->mii);
1802}
1803
1804static u32 netdev_get_link(struct net_device *dev)
1805{
1806        struct netdev_private *np = dev->priv;
1807        return mii_link_ok(&np->mii);
1808}
1809
1810static u32 netdev_get_msglevel(struct net_device *dev)
1811{
1812        return debug;
1813}
1814
1815static void netdev_set_msglevel(struct net_device *dev, u32 value)
1816{
1817        debug = value;
1818}
1819
1820static struct ethtool_ops netdev_ethtool_ops = {
1821        .get_drvinfo            = netdev_get_drvinfo,
1822        .get_settings           = netdev_get_settings,
1823        .set_settings           = netdev_set_settings,
1824        .nway_reset             = netdev_nway_reset,
1825        .get_link               = netdev_get_link,
1826        .get_msglevel           = netdev_get_msglevel,
1827        .set_msglevel           = netdev_set_msglevel,
1828        .get_sg                 = ethtool_op_get_sg,
1829        .get_tx_csum            = ethtool_op_get_tx_csum,
1830};
1831
1832static int mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1833{
1834        struct netdev_private *np = dev->priv;
1835        struct mii_ioctl_data *data = (struct mii_ioctl_data *) & rq->ifr_data;
1836        int rc;
1837
1838        if (!netif_running(dev))
1839                return -EINVAL;
1840
1841        spin_lock_irq(&np->lock);
1842        rc = generic_mii_ioctl(&np->mii, data, cmd, NULL);
1843        spin_unlock_irq(&np->lock);
1844
1845        return rc;
1846}
1847
1848
1849static int netdev_close(struct net_device *dev)
1850{
1851        long ioaddr = dev->base_addr;
1852        struct netdev_private *np = dev->priv;
1853        int i;
1854
1855        netif_stop_queue(dev);
1856
1857        /* Disable interrupts by clearing the interrupt mask. */
1858        writel(0x0000, ioaddr + IMR);
1859
1860        /* Stop the chip's Tx and Rx processes. */
1861        stop_nic_tx(ioaddr, 0);
1862        stop_nic_rx(ioaddr, 0);
1863
1864        del_timer_sync(&np->timer);
1865
1866        free_irq(dev->irq, dev);
1867
1868        /* Free all the skbuffs in the Rx queue. */
1869        for (i = 0; i < RX_RING_SIZE; i++) {
1870                struct sk_buff *skb = np->rx_ring[i].skbuff;
1871
1872                np->rx_ring[i].status = 0;
1873                if (skb) {
1874                        pci_unmap_single(np->pci_dev, np->rx_ring[i].buffer,
1875                                np->rx_buf_sz, PCI_DMA_FROMDEVICE);
1876                        dev_kfree_skb(skb);
1877                        np->rx_ring[i].skbuff = NULL;
1878                }
1879        }
1880
1881        for (i = 0; i < TX_RING_SIZE; i++) {
1882                struct sk_buff *skb = np->tx_ring[i].skbuff;
1883
1884                if (skb) {
1885                        pci_unmap_single(np->pci_dev, np->tx_ring[i].buffer,
1886                                skb->len, PCI_DMA_TODEVICE);
1887                        dev_kfree_skb(skb);
1888                        np->tx_ring[i].skbuff = NULL;
1889                }
1890        }
1891
1892        return 0;
1893}
1894
1895static struct pci_device_id fealnx_pci_tbl[] = {
1896        {0x1516, 0x0800, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1897        {0x1516, 0x0803, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
1898        {0x1516, 0x0891, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
1899        {} /* terminate list */
1900};
1901MODULE_DEVICE_TABLE(pci, fealnx_pci_tbl);
1902
1903
1904static struct pci_driver fealnx_driver = {
1905        .name           = "fealnx",
1906        .id_table       = fealnx_pci_tbl,
1907        .probe          = fealnx_init_one,
1908        .remove         = __devexit_p(fealnx_remove_one),
1909};
1910
1911static int __init fealnx_init(void)
1912{
1913/* when a module, this is printed whether or not devices are found in probe */
1914#ifdef MODULE
1915        printk (version);
1916#endif
1917
1918        return pci_module_init(&fealnx_driver);
1919}
1920
1921static void __exit fealnx_exit(void)
1922{
1923        pci_unregister_driver(&fealnx_driver);
1924}
1925
1926module_init(fealnx_init);
1927module_exit(fealnx_exit);
1928
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.