linux-old/drivers/net/winbond-840.c
<<
>>
Prefs
   1/* winbond-840.c: A Linux PCI network adapter device driver. */
   2/*
   3        Written 1998-2001 by Donald Becker.
   4
   5        This software may be used and distributed according to the terms of
   6        the GNU General Public License (GPL), incorporated herein by reference.
   7        Drivers based on or derived from this code fall under the GPL and must
   8        retain the authorship, copyright and license notice.  This file is not
   9        a complete program and may only be used when the entire operating
  10        system is licensed under the GPL.
  11
  12        The author may be reached as becker@scyld.com, or C/O
  13        Scyld Computing Corporation
  14        410 Severn Ave., Suite 210
  15        Annapolis MD 21403
  16
  17        Support and updates available at
  18        http://www.scyld.com/network/drivers.html
  19
  20        Do not remove the copyright information.
  21        Do not change the version information unless an improvement has been made.
  22        Merely removing my name, as Compex has done in the past, does not count
  23        as an improvement.
  24
  25        Changelog:
  26        * ported to 2.4
  27                ???
  28        * spin lock update, memory barriers, new style dma mappings
  29                limit each tx buffer to < 1024 bytes
  30                remove DescIntr from Rx descriptors (that's an Tx flag)
  31                remove next pointer from Tx descriptors
  32                synchronize tx_q_bytes
  33                software reset in tx_timeout
  34                        Copyright (C) 2000 Manfred Spraul
  35        * further cleanups
  36                power management.
  37                support for big endian descriptors
  38                        Copyright (C) 2001 Manfred Spraul
  39        * ethtool support (jgarzik)
  40        * Replace some MII-related magic numbers with constants (jgarzik)
  41  
  42        TODO:
  43        * enable pci_power_off
  44        * Wake-On-LAN
  45*/
  46  
  47#define DRV_NAME        "winbond-840"
  48#define DRV_VERSION     "1.01-d"
  49#define DRV_RELDATE     "Nov-17-2001"
  50
  51
  52/* Automatically extracted configuration info:
  53probe-func: winbond840_probe
  54config-in: tristate 'Winbond W89c840 Ethernet support' CONFIG_WINBOND_840
  55
  56c-help-name: Winbond W89c840 PCI Ethernet support
  57c-help-symbol: CONFIG_WINBOND_840
  58c-help: This driver is for the Winbond W89c840 chip.  It also works with
  59c-help: the TX9882 chip on the Compex RL100-ATX board.
  60c-help: More specific information and updates are available from 
  61c-help: http://www.scyld.com/network/drivers.html
  62*/
  63
  64/* The user-configurable values.
  65   These may be modified when a driver module is loaded.*/
  66
  67static int debug = 1;                   /* 1 normal messages, 0 quiet .. 7 verbose. */
  68static int max_interrupt_work = 20;
  69/* Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
  70   The '840 uses a 64 element hash table based on the Ethernet CRC.  */
  71static int multicast_filter_limit = 32;
  72
  73/* Set the copy breakpoint for the copy-only-tiny-frames scheme.
  74   Setting to > 1518 effectively disables this feature. */
  75static int rx_copybreak;
  76
  77/* Used to pass the media type, etc.
  78   Both 'options[]' and 'full_duplex[]' should exist for driver
  79   interoperability.
  80   The media type is usually passed in 'options[]'.
  81*/
  82#define MAX_UNITS 8             /* More are supported, limit only on options */
  83static int options[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
  84static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
  85
  86/* Operational parameters that are set at compile time. */
  87
  88/* Keep the ring sizes a power of two for compile efficiency.
  89   The compiler will convert <unsigned>'%'<2^N> into a bit mask.
  90   Making the Tx ring too large decreases the effectiveness of channel
  91   bonding and packet priority.
  92   There are no ill effects from too-large receive rings. */
  93#define TX_RING_SIZE    16
  94#define TX_QUEUE_LEN    10              /* Limit ring entries actually used.  */
  95#define TX_QUEUE_LEN_RESTART    5
  96#define RX_RING_SIZE    32
  97
  98#define TX_BUFLIMIT     (1024-128)
  99
 100/* The presumed FIFO size for working around the Tx-FIFO-overflow bug.
 101   To avoid overflowing we don't queue again until we have room for a
 102   full-size packet.
 103 */
 104#define TX_FIFO_SIZE (2048)
 105#define TX_BUG_FIFO_LIMIT (TX_FIFO_SIZE-1514-16)
 106
 107
 108/* Operational parameters that usually are not changed. */
 109/* Time in jiffies before concluding the transmitter is hung. */
 110#define TX_TIMEOUT  (2*HZ)
 111
 112#define PKT_BUF_SZ              1536                    /* Size of each temporary Rx buffer.*/
 113
 114#ifndef __KERNEL__
 115#define __KERNEL__
 116#endif
 117#if !defined(__OPTIMIZE__)
 118#warning  You must compile this file with the correct options!
 119#warning  See the last lines of the source file.
 120#error You must compile this driver with "-O".
 121#endif
 122
 123/* Include files, designed to support most kernel versions 2.0.0 and later. */
 124#include <linux/module.h>
 125#include <linux/kernel.h>
 126#include <linux/string.h>
 127#include <linux/timer.h>
 128#include <linux/errno.h>
 129#include <linux/ioport.h>
 130#include <linux/slab.h>
 131#include <linux/interrupt.h>
 132#include <linux/pci.h>
 133#include <linux/netdevice.h>
 134#include <linux/etherdevice.h>
 135#include <linux/skbuff.h>
 136#include <linux/init.h>
 137#include <linux/delay.h>
 138#include <linux/ethtool.h>
 139#include <linux/mii.h>
 140#include <linux/rtnetlink.h>
 141#include <linux/crc32.h>
 142#include <asm/uaccess.h>
 143#include <asm/processor.h>              /* Processor type for cache alignment. */
 144#include <asm/bitops.h>
 145#include <asm/io.h>
 146#include <asm/irq.h>
 147
 148/* These identify the driver base version and may not be removed. */
 149static char version[] __devinitdata =
 150KERN_INFO DRV_NAME ".c:v" DRV_VERSION " (2.4 port) " DRV_RELDATE "  Donald Becker <becker@scyld.com>\n"
 151KERN_INFO "  http://www.scyld.com/network/drivers.html\n";
 152
 153MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
 154MODULE_DESCRIPTION("Winbond W89c840 Ethernet driver");
 155MODULE_LICENSE("GPL");
 156
 157MODULE_PARM(max_interrupt_work, "i");
 158MODULE_PARM(debug, "i");
 159MODULE_PARM(rx_copybreak, "i");
 160MODULE_PARM(multicast_filter_limit, "i");
 161MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i");
 162MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");
 163MODULE_PARM_DESC(max_interrupt_work, "winbond-840 maximum events handled per interrupt");
 164MODULE_PARM_DESC(debug, "winbond-840 debug level (0-6)");
 165MODULE_PARM_DESC(rx_copybreak, "winbond-840 copy breakpoint for copy-only-tiny-frames");
 166MODULE_PARM_DESC(multicast_filter_limit, "winbond-840 maximum number of filtered multicast addresses");
 167MODULE_PARM_DESC(options, "winbond-840: Bits 0-3: media type, bit 17: full duplex");
 168MODULE_PARM_DESC(full_duplex, "winbond-840 full duplex setting(s) (1)");
 169
 170/*
 171                                Theory of Operation
 172
 173I. Board Compatibility
 174
 175This driver is for the Winbond w89c840 chip.
 176
 177II. Board-specific settings
 178
 179None.
 180
 181III. Driver operation
 182
 183This chip is very similar to the Digital 21*4* "Tulip" family.  The first
 184twelve registers and the descriptor format are nearly identical.  Read a
 185Tulip manual for operational details.
 186
 187A significant difference is that the multicast filter and station address are
 188stored in registers rather than loaded through a pseudo-transmit packet.
 189
 190Unlike the Tulip, transmit buffers are limited to 1KB.  To transmit a
 191full-sized packet we must use both data buffers in a descriptor.  Thus the
 192driver uses ring mode where descriptors are implicitly sequential in memory,
 193rather than using the second descriptor address as a chain pointer to
 194subsequent descriptors.
 195
 196IV. Notes
 197
 198If you are going to almost clone a Tulip, why not go all the way and avoid
 199the need for a new driver?
 200
 201IVb. References
 202
 203http://www.scyld.com/expert/100mbps.html
 204http://www.scyld.com/expert/NWay.html
 205http://www.winbond.com.tw/
 206
 207IVc. Errata
 208
 209A horrible bug exists in the transmit FIFO.  Apparently the chip doesn't
 210correctly detect a full FIFO, and queuing more than 2048 bytes may result in
 211silent data corruption.
 212
 213Test with 'ping -s 10000' on a fast computer.
 214
 215*/
 216
 217
 218
 219/*
 220  PCI probe table.
 221*/
 222enum pci_id_flags_bits {
 223        /* Set PCI command register bits before calling probe1(). */
 224        PCI_USES_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4,
 225        /* Read and map the single following PCI BAR. */
 226        PCI_ADDR0=0<<4, PCI_ADDR1=1<<4, PCI_ADDR2=2<<4, PCI_ADDR3=3<<4,
 227        PCI_ADDR_64BITS=0x100, PCI_NO_ACPI_WAKE=0x200, PCI_NO_MIN_LATENCY=0x400,
 228};
 229enum chip_capability_flags {
 230        CanHaveMII=1, HasBrokenTx=2, AlwaysFDX=4, FDXOnNoMII=8,};
 231#ifdef USE_IO_OPS
 232#define W840_FLAGS (PCI_USES_IO | PCI_ADDR0 | PCI_USES_MASTER)
 233#else
 234#define W840_FLAGS (PCI_USES_MEM | PCI_ADDR1 | PCI_USES_MASTER)
 235#endif
 236
 237static struct pci_device_id w840_pci_tbl[] = {
 238        { 0x1050, 0x0840, PCI_ANY_ID, 0x8153,     0, 0, 0 },
 239        { 0x1050, 0x0840, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
 240        { 0x11f6, 0x2011, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
 241        { 0, }
 242};
 243MODULE_DEVICE_TABLE(pci, w840_pci_tbl);
 244
 245struct pci_id_info {
 246        const char *name;
 247        struct match_info {
 248                int     pci, pci_mask, subsystem, subsystem_mask;
 249                int revision, revision_mask;                            /* Only 8 bits. */
 250        } id;
 251        enum pci_id_flags_bits pci_flags;
 252        int io_size;                            /* Needed for I/O region check or ioremap(). */
 253        int drv_flags;                          /* Driver use, intended as capability flags. */
 254};
 255static struct pci_id_info pci_id_tbl[] = {
 256        {"Winbond W89c840",                     /* Sometime a Level-One switch card. */
 257         { 0x08401050, 0xffffffff, 0x81530000, 0xffff0000 },
 258         W840_FLAGS, 128, CanHaveMII | HasBrokenTx | FDXOnNoMII},
 259        {"Winbond W89c840", { 0x08401050, 0xffffffff, },
 260         W840_FLAGS, 128, CanHaveMII | HasBrokenTx},
 261        {"Compex RL100-ATX", { 0x201111F6, 0xffffffff,},
 262         W840_FLAGS, 128, CanHaveMII | HasBrokenTx},
 263        {0,},                                           /* 0 terminated list. */
 264};
 265
 266/* This driver was written to use PCI memory space, however some x86 systems
 267   work only with I/O space accesses.  Pass -DUSE_IO_OPS to use PCI I/O space
 268   accesses instead of memory space. */
 269
 270#ifdef USE_IO_OPS
 271#undef readb
 272#undef readw
 273#undef readl
 274#undef writeb
 275#undef writew
 276#undef writel
 277#define readb inb
 278#define readw inw
 279#define readl inl
 280#define writeb outb
 281#define writew outw
 282#define writel outl
 283#endif
 284
 285/* Offsets to the Command and Status Registers, "CSRs".
 286   While similar to the Tulip, these registers are longword aligned.
 287   Note: It's not useful to define symbolic names for every register bit in
 288   the device.  The name can only partially document the semantics and make
 289   the driver longer and more difficult to read.
 290*/
 291enum w840_offsets {
 292        PCIBusCfg=0x00, TxStartDemand=0x04, RxStartDemand=0x08,
 293        RxRingPtr=0x0C, TxRingPtr=0x10,
 294        IntrStatus=0x14, NetworkConfig=0x18, IntrEnable=0x1C,
 295        RxMissed=0x20, EECtrl=0x24, MIICtrl=0x24, BootRom=0x28, GPTimer=0x2C,
 296        CurRxDescAddr=0x30, CurRxBufAddr=0x34,                  /* Debug use */
 297        MulticastFilter0=0x38, MulticastFilter1=0x3C, StationAddr=0x40,
 298        CurTxDescAddr=0x4C, CurTxBufAddr=0x50,
 299};
 300
 301/* Bits in the interrupt status/enable registers. */
 302/* The bits in the Intr Status/Enable registers, mostly interrupt sources. */
 303enum intr_status_bits {
 304        NormalIntr=0x10000, AbnormalIntr=0x8000,
 305        IntrPCIErr=0x2000, TimerInt=0x800,
 306        IntrRxDied=0x100, RxNoBuf=0x80, IntrRxDone=0x40,
 307        TxFIFOUnderflow=0x20, RxErrIntr=0x10,
 308        TxIdle=0x04, IntrTxStopped=0x02, IntrTxDone=0x01,
 309};
 310
 311/* Bits in the NetworkConfig register. */
 312enum rx_mode_bits {
 313        AcceptErr=0x80, AcceptRunt=0x40,
 314        AcceptBroadcast=0x20, AcceptMulticast=0x10,
 315        AcceptAllPhys=0x08, AcceptMyPhys=0x02,
 316};
 317
 318enum mii_reg_bits {
 319        MDIO_ShiftClk=0x10000, MDIO_DataIn=0x80000, MDIO_DataOut=0x20000,
 320        MDIO_EnbOutput=0x40000, MDIO_EnbIn = 0x00000,
 321};
 322
 323/* The Tulip Rx and Tx buffer descriptors. */
 324struct w840_rx_desc {
 325        s32 status;
 326        s32 length;
 327        u32 buffer1;
 328        u32 buffer2;
 329};
 330
 331struct w840_tx_desc {
 332        s32 status;
 333        s32 length;
 334        u32 buffer1, buffer2;
 335};
 336
 337/* Bits in network_desc.status */
 338enum desc_status_bits {
 339        DescOwn=0x80000000, DescEndRing=0x02000000, DescUseLink=0x01000000,
 340        DescWholePkt=0x60000000, DescStartPkt=0x20000000, DescEndPkt=0x40000000,
 341        DescIntr=0x80000000,
 342};
 343
 344#define MII_CNT         1 /* winbond only supports one MII */
 345struct netdev_private {
 346        struct w840_rx_desc *rx_ring;
 347        dma_addr_t      rx_addr[RX_RING_SIZE];
 348        struct w840_tx_desc *tx_ring;
 349        dma_addr_t      tx_addr[TX_RING_SIZE];
 350        dma_addr_t ring_dma_addr;
 351        /* The addresses of receive-in-place skbuffs. */
 352        struct sk_buff* rx_skbuff[RX_RING_SIZE];
 353        /* The saved address of a sent-in-place packet/buffer, for later free(). */
 354        struct sk_buff* tx_skbuff[TX_RING_SIZE];
 355        struct net_device_stats stats;
 356        struct timer_list timer;        /* Media monitoring timer. */
 357        /* Frequently used values: keep some adjacent for cache effect. */
 358        spinlock_t lock;
 359        int chip_id, drv_flags;
 360        struct pci_dev *pci_dev;
 361        int csr6;
 362        struct w840_rx_desc *rx_head_desc;
 363        unsigned int cur_rx, dirty_rx;          /* Producer/consumer ring indices */
 364        unsigned int rx_buf_sz;                         /* Based on MTU+slack. */
 365        unsigned int cur_tx, dirty_tx;
 366        unsigned int tx_q_bytes;
 367        unsigned int tx_full;                           /* The Tx queue is full. */
 368        /* MII transceiver section. */
 369        int mii_cnt;                                            /* MII device addresses. */
 370        unsigned char phys[MII_CNT];            /* MII device addresses, but only the first is used */
 371        u32 mii;
 372        struct mii_if_info mii_if;
 373};
 374
 375static int  eeprom_read(long ioaddr, int location);
 376static int  mdio_read(struct net_device *dev, int phy_id, int location);
 377static void mdio_write(struct net_device *dev, int phy_id, int location, int value);
 378static int  netdev_open(struct net_device *dev);
 379static int  update_link(struct net_device *dev);
 380static void netdev_timer(unsigned long data);
 381static void init_rxtx_rings(struct net_device *dev);
 382static void free_rxtx_rings(struct netdev_private *np);
 383static void init_registers(struct net_device *dev);
 384static void tx_timeout(struct net_device *dev);
 385static int alloc_ringdesc(struct net_device *dev);
 386static void free_ringdesc(struct netdev_private *np);
 387static int  start_tx(struct sk_buff *skb, struct net_device *dev);
 388static irqreturn_t intr_handler(int irq, void *dev_instance, struct pt_regs *regs);
 389static void netdev_error(struct net_device *dev, int intr_status);
 390static int  netdev_rx(struct net_device *dev);
 391static u32 __set_rx_mode(struct net_device *dev);
 392static void set_rx_mode(struct net_device *dev);
 393static struct net_device_stats *get_stats(struct net_device *dev);
 394static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
 395static struct ethtool_ops netdev_ethtool_ops;
 396static int  netdev_close(struct net_device *dev);
 397
 398
 399
 400static int __devinit w840_probe1 (struct pci_dev *pdev,
 401                                  const struct pci_device_id *ent)
 402{
 403        struct net_device *dev;
 404        struct netdev_private *np;
 405        static int find_cnt;
 406        int chip_idx = ent->driver_data;
 407        int irq;
 408        int i, option = find_cnt < MAX_UNITS ? options[find_cnt] : 0;
 409        long ioaddr;
 410
 411        i = pci_enable_device(pdev);
 412        if (i) return i;
 413
 414        pci_set_master(pdev);
 415
 416        irq = pdev->irq;
 417
 418        if (pci_set_dma_mask(pdev,0xFFFFffff)) {
 419                printk(KERN_WARNING "Winbond-840: Device %s disabled due to DMA limitations.\n",
 420                       pci_name(pdev));
 421                return -EIO;
 422        }
 423        dev = alloc_etherdev(sizeof(*np));
 424        if (!dev)
 425                return -ENOMEM;
 426        SET_MODULE_OWNER(dev);
 427
 428        if (pci_request_regions(pdev, DRV_NAME))
 429                goto err_out_netdev;
 430
 431#ifdef USE_IO_OPS
 432        ioaddr = pci_resource_start(pdev, 0);
 433#else
 434        ioaddr = pci_resource_start(pdev, 1);
 435        ioaddr = (long) ioremap (ioaddr, pci_id_tbl[chip_idx].io_size);
 436        if (!ioaddr)
 437                goto err_out_free_res;
 438#endif
 439
 440        for (i = 0; i < 3; i++)
 441                ((u16 *)dev->dev_addr)[i] = le16_to_cpu(eeprom_read(ioaddr, i));
 442
 443        /* Reset the chip to erase previous misconfiguration.
 444           No hold time required! */
 445        writel(0x00000001, ioaddr + PCIBusCfg);
 446
 447        dev->base_addr = ioaddr;
 448        dev->irq = irq;
 449
 450        np = dev->priv;
 451        np->pci_dev = pdev;
 452        np->chip_id = chip_idx;
 453        np->drv_flags = pci_id_tbl[chip_idx].drv_flags;
 454        spin_lock_init(&np->lock);
 455        np->mii_if.dev = dev;
 456        np->mii_if.mdio_read = mdio_read;
 457        np->mii_if.mdio_write = mdio_write;
 458        
 459        pci_set_drvdata(pdev, dev);
 460
 461        if (dev->mem_start)
 462                option = dev->mem_start;
 463
 464        /* The lower four bits are the media type. */
 465        if (option > 0) {
 466                if (option & 0x200)
 467                        np->mii_if.full_duplex = 1;
 468                if (option & 15)
 469                        printk(KERN_INFO "%s: ignoring user supplied media type %d",
 470                                dev->name, option & 15);
 471        }
 472        if (find_cnt < MAX_UNITS  &&  full_duplex[find_cnt] > 0)
 473                np->mii_if.full_duplex = 1;
 474
 475        if (np->mii_if.full_duplex)
 476                np->mii_if.force_media = 1;
 477
 478        /* The chip-specific entries in the device structure. */
 479        dev->open = &netdev_open;
 480        dev->hard_start_xmit = &start_tx;
 481        dev->stop = &netdev_close;
 482        dev->get_stats = &get_stats;
 483        dev->set_multicast_list = &set_rx_mode;
 484        dev->do_ioctl = &netdev_ioctl;
 485        dev->ethtool_ops = &netdev_ethtool_ops;
 486        dev->tx_timeout = &tx_timeout;
 487        dev->watchdog_timeo = TX_TIMEOUT;
 488
 489        i = register_netdev(dev);
 490        if (i)
 491                goto err_out_cleardev;
 492
 493        printk(KERN_INFO "%s: %s at 0x%lx, ",
 494                   dev->name, pci_id_tbl[chip_idx].name, ioaddr);
 495        for (i = 0; i < 5; i++)
 496                        printk("%2.2x:", dev->dev_addr[i]);
 497        printk("%2.2x, IRQ %d.\n", dev->dev_addr[i], irq);
 498
 499        if (np->drv_flags & CanHaveMII) {
 500                int phy, phy_idx = 0;
 501                for (phy = 1; phy < 32 && phy_idx < MII_CNT; phy++) {
 502                        int mii_status = mdio_read(dev, phy, MII_BMSR);
 503                        if (mii_status != 0xffff  &&  mii_status != 0x0000) {
 504                                np->phys[phy_idx++] = phy;
 505                                np->mii_if.advertising = mdio_read(dev, phy, MII_ADVERTISE);
 506                                np->mii = (mdio_read(dev, phy, MII_PHYSID1) << 16)+
 507                                                mdio_read(dev, phy, MII_PHYSID2);
 508                                printk(KERN_INFO "%s: MII PHY %8.8xh found at address %d, status "
 509                                           "0x%4.4x advertising %4.4x.\n",
 510                                           dev->name, np->mii, phy, mii_status, np->mii_if.advertising);
 511                        }
 512                }
 513                np->mii_cnt = phy_idx;
 514                np->mii_if.phy_id = np->phys[0];
 515                if (phy_idx == 0) {
 516                                printk(KERN_WARNING "%s: MII PHY not found -- this device may "
 517                                           "not operate correctly.\n", dev->name);
 518                }
 519        }
 520
 521        find_cnt++;
 522        return 0;
 523
 524err_out_cleardev:
 525        pci_set_drvdata(pdev, NULL);
 526#ifndef USE_IO_OPS
 527        iounmap((void *)ioaddr);
 528err_out_free_res:
 529#endif
 530        pci_release_regions(pdev);
 531err_out_netdev:
 532        kfree (dev);
 533        return -ENODEV;
 534}
 535
 536
 537/* Read the EEPROM and MII Management Data I/O (MDIO) interfaces.  These are
 538   often serial bit streams generated by the host processor.
 539   The example below is for the common 93c46 EEPROM, 64 16 bit words. */
 540
 541/* Delay between EEPROM clock transitions.
 542   No extra delay is needed with 33Mhz PCI, but future 66Mhz access may need
 543   a delay.  Note that pre-2.0.34 kernels had a cache-alignment bug that
 544   made udelay() unreliable.
 545   The old method of using an ISA access as a delay, __SLOW_DOWN_IO__, is
 546   depricated.
 547*/
 548#define eeprom_delay(ee_addr)   readl(ee_addr)
 549
 550enum EEPROM_Ctrl_Bits {
 551        EE_ShiftClk=0x02, EE_Write0=0x801, EE_Write1=0x805,
 552        EE_ChipSelect=0x801, EE_DataIn=0x08,
 553};
 554
 555/* The EEPROM commands include the alway-set leading bit. */
 556enum EEPROM_Cmds {
 557        EE_WriteCmd=(5 << 6), EE_ReadCmd=(6 << 6), EE_EraseCmd=(7 << 6),
 558};
 559
 560static int eeprom_read(long addr, int location)
 561{
 562        int i;
 563        int retval = 0;
 564        long ee_addr = addr + EECtrl;
 565        int read_cmd = location | EE_ReadCmd;
 566        writel(EE_ChipSelect, ee_addr);
 567
 568        /* Shift the read command bits out. */
 569        for (i = 10; i >= 0; i--) {
 570                short dataval = (read_cmd & (1 << i)) ? EE_Write1 : EE_Write0;
 571                writel(dataval, ee_addr);
 572                eeprom_delay(ee_addr);
 573                writel(dataval | EE_ShiftClk, ee_addr);
 574                eeprom_delay(ee_addr);
 575        }
 576        writel(EE_ChipSelect, ee_addr);
 577        eeprom_delay(ee_addr);
 578
 579        for (i = 16; i > 0; i--) {
 580                writel(EE_ChipSelect | EE_ShiftClk, ee_addr);
 581                eeprom_delay(ee_addr);
 582                retval = (retval << 1) | ((readl(ee_addr) & EE_DataIn) ? 1 : 0);
 583                writel(EE_ChipSelect, ee_addr);
 584                eeprom_delay(ee_addr);
 585        }
 586
 587        /* Terminate the EEPROM access. */
 588        writel(0, ee_addr);
 589        return retval;
 590}
 591
 592/*  MII transceiver control section.
 593        Read and write the MII registers using software-generated serial
 594        MDIO protocol.  See the MII specifications or DP83840A data sheet
 595        for details.
 596
 597        The maximum data clock rate is 2.5 Mhz.  The minimum timing is usually
 598        met by back-to-back 33Mhz PCI cycles. */
 599#define mdio_delay(mdio_addr) readl(mdio_addr)
 600
 601/* Set iff a MII transceiver on any interface requires mdio preamble.
 602   This only set with older transceivers, so the extra
 603   code size of a per-interface flag is not worthwhile. */
 604static char mii_preamble_required = 1;
 605
 606#define MDIO_WRITE0 (MDIO_EnbOutput)
 607#define MDIO_WRITE1 (MDIO_DataOut | MDIO_EnbOutput)
 608
 609/* Generate the preamble required for initial synchronization and
 610   a few older transceivers. */
 611static void mdio_sync(long mdio_addr)
 612{
 613        int bits = 32;
 614
 615        /* Establish sync by sending at least 32 logic ones. */
 616        while (--bits >= 0) {
 617                writel(MDIO_WRITE1, mdio_addr);
 618                mdio_delay(mdio_addr);
 619                writel(MDIO_WRITE1 | MDIO_ShiftClk, mdio_addr);
 620                mdio_delay(mdio_addr);
 621        }
 622}
 623
 624static int mdio_read(struct net_device *dev, int phy_id, int location)
 625{
 626        long mdio_addr = dev->base_addr + MIICtrl;
 627        int mii_cmd = (0xf6 << 10) | (phy_id << 5) | location;
 628        int i, retval = 0;
 629
 630        if (mii_preamble_required)
 631                mdio_sync(mdio_addr);
 632
 633        /* Shift the read command bits out. */
 634        for (i = 15; i >= 0; i--) {
 635                int dataval = (mii_cmd & (1 << i)) ? MDIO_WRITE1 : MDIO_WRITE0;
 636
 637                writel(dataval, mdio_addr);
 638                mdio_delay(mdio_addr);
 639                writel(dataval | MDIO_ShiftClk, mdio_addr);
 640                mdio_delay(mdio_addr);
 641        }
 642        /* Read the two transition, 16 data, and wire-idle bits. */
 643        for (i = 20; i > 0; i--) {
 644                writel(MDIO_EnbIn, mdio_addr);
 645                mdio_delay(mdio_addr);
 646                retval = (retval << 1) | ((readl(mdio_addr) & MDIO_DataIn) ? 1 : 0);
 647                writel(MDIO_EnbIn | MDIO_ShiftClk, mdio_addr);
 648                mdio_delay(mdio_addr);
 649        }
 650        return (retval>>1) & 0xffff;
 651}
 652
 653static void mdio_write(struct net_device *dev, int phy_id, int location, int value)
 654{
 655        struct netdev_private *np = dev->priv;
 656        long mdio_addr = dev->base_addr + MIICtrl;
 657        int mii_cmd = (0x5002 << 16) | (phy_id << 23) | (location<<18) | value;
 658        int i;
 659
 660        if (location == 4  &&  phy_id == np->phys[0])
 661                np->mii_if.advertising = value;
 662
 663        if (mii_preamble_required)
 664                mdio_sync(mdio_addr);
 665
 666        /* Shift the command bits out. */
 667        for (i = 31; i >= 0; i--) {
 668                int dataval = (mii_cmd & (1 << i)) ? MDIO_WRITE1 : MDIO_WRITE0;
 669
 670                writel(dataval, mdio_addr);
 671                mdio_delay(mdio_addr);
 672                writel(dataval | MDIO_ShiftClk, mdio_addr);
 673                mdio_delay(mdio_addr);
 674        }
 675        /* Clear out extra bits. */
 676        for (i = 2; i > 0; i--) {
 677                writel(MDIO_EnbIn, mdio_addr);
 678                mdio_delay(mdio_addr);
 679                writel(MDIO_EnbIn | MDIO_ShiftClk, mdio_addr);
 680                mdio_delay(mdio_addr);
 681        }
 682        return;
 683}
 684
 685
 686static int netdev_open(struct net_device *dev)
 687{
 688        struct netdev_private *np = dev->priv;
 689        long ioaddr = dev->base_addr;
 690        int i;
 691
 692        writel(0x00000001, ioaddr + PCIBusCfg);         /* Reset */
 693
 694        netif_device_detach(dev);
 695        i = request_irq(dev->irq, &intr_handler, SA_SHIRQ, dev->name, dev);
 696        if (i)
 697                goto out_err;
 698
 699        if (debug > 1)
 700                printk(KERN_DEBUG "%s: w89c840_open() irq %d.\n",
 701                           dev->name, dev->irq);
 702
 703        if((i=alloc_ringdesc(dev)))
 704                goto out_err;
 705
 706        spin_lock_irq(&np->lock);
 707        netif_device_attach(dev);
 708        init_registers(dev);
 709        spin_unlock_irq(&np->lock);
 710
 711        netif_start_queue(dev);
 712        if (debug > 2)
 713                printk(KERN_DEBUG "%s: Done netdev_open().\n", dev->name);
 714
 715        /* Set the timer to check for link beat. */
 716        init_timer(&np->timer);
 717        np->timer.expires = jiffies + 1*HZ;
 718        np->timer.data = (unsigned long)dev;
 719        np->timer.function = &netdev_timer;                             /* timer handler */
 720        add_timer(&np->timer);
 721        return 0;
 722out_err:
 723        netif_device_attach(dev);
 724        return i;
 725}
 726
 727#define MII_DAVICOM_DM9101      0x0181b800
 728
 729static int update_link(struct net_device *dev)
 730{
 731        struct netdev_private *np = dev->priv;
 732        int duplex, fasteth, result, mii_reg;
 733
 734        /* BSMR */
 735        mii_reg = mdio_read(dev, np->phys[0], MII_BMSR);
 736
 737        if (mii_reg == 0xffff)
 738                return np->csr6;
 739        /* reread: the link status bit is sticky */
 740        mii_reg = mdio_read(dev, np->phys[0], MII_BMSR);
 741        if (!(mii_reg & 0x4)) {
 742                if (netif_carrier_ok(dev)) {
 743                        if (debug)
 744                                printk(KERN_INFO "%s: MII #%d reports no link. Disabling watchdog.\n",
 745                                        dev->name, np->phys[0]);
 746                        netif_carrier_off(dev);
 747                }
 748                return np->csr6;
 749        }
 750        if (!netif_carrier_ok(dev)) {
 751                if (debug)
 752                        printk(KERN_INFO "%s: MII #%d link is back. Enabling watchdog.\n",
 753                                dev->name, np->phys[0]);
 754                netif_carrier_on(dev);
 755        }
 756        
 757        if ((np->mii & ~0xf) == MII_DAVICOM_DM9101) {
 758                /* If the link partner doesn't support autonegotiation
 759                 * the MII detects it's abilities with the "parallel detection".
 760                 * Some MIIs update the LPA register to the result of the parallel
 761                 * detection, some don't.
 762                 * The Davicom PHY [at least 0181b800] doesn't.
 763                 * Instead bit 9 and 13 of the BMCR are updated to the result
 764                 * of the negotiation..
 765                 */
 766                mii_reg = mdio_read(dev, np->phys[0], MII_BMCR);
 767                duplex = mii_reg & BMCR_FULLDPLX;
 768                fasteth = mii_reg & BMCR_SPEED100;
 769        } else {
 770                int negotiated;
 771                mii_reg = mdio_read(dev, np->phys[0], MII_LPA);
 772                negotiated = mii_reg & np->mii_if.advertising;
 773
 774                duplex = (negotiated & LPA_100FULL) || ((negotiated & 0x02C0) == LPA_10FULL);
 775                fasteth = negotiated & 0x380;
 776        }
 777        duplex |= np->mii_if.force_media;
 778        /* remove fastether and fullduplex */
 779        result = np->csr6 & ~0x20000200;
 780        if (duplex)
 781                result |= 0x200;
 782        if (fasteth)
 783                result |= 0x20000000;
 784        if (result != np->csr6 && debug)
 785                printk(KERN_INFO "%s: Setting %dMBit-%s-duplex based on MII#%d\n",
 786                                 dev->name, fasteth ? 100 : 10, 
 787                                duplex ? "full" : "half", np->phys[0]);
 788        return result;
 789}
 790
 791#define RXTX_TIMEOUT    2000
 792static inline void update_csr6(struct net_device *dev, int new)
 793{
 794        struct netdev_private *np = dev->priv;
 795        long ioaddr = dev->base_addr;
 796        int limit = RXTX_TIMEOUT;
 797
 798        if (!netif_device_present(dev))
 799                new = 0;
 800        if (new==np->csr6)
 801                return;
 802        /* stop both Tx and Rx processes */
 803        writel(np->csr6 & ~0x2002, ioaddr + NetworkConfig);
 804        /* wait until they have really stopped */
 805        for (;;) {
 806                int csr5 = readl(ioaddr + IntrStatus);
 807                int t;
 808
 809                t = (csr5 >> 17) & 0x07;
 810                if (t==0||t==1) {
 811                        /* rx stopped */
 812                        t = (csr5 >> 20) & 0x07;
 813                        if (t==0||t==1)
 814                                break;
 815                }
 816
 817                limit--;
 818                if(!limit) {
 819                        printk(KERN_INFO "%s: couldn't stop rxtx, IntrStatus %xh.\n",
 820                                        dev->name, csr5);
 821                        break;
 822                }
 823                udelay(1);
 824        }
 825        np->csr6 = new;
 826        /* and restart them with the new configuration */
 827        writel(np->csr6, ioaddr + NetworkConfig);
 828        if (new & 0x200)
 829                np->mii_if.full_duplex = 1;
 830}
 831
 832static void netdev_timer(unsigned long data)
 833{
 834        struct net_device *dev = (struct net_device *)data;
 835        struct netdev_private *np = dev->priv;
 836        long ioaddr = dev->base_addr;
 837
 838        if (debug > 2)
 839                printk(KERN_DEBUG "%s: Media selection timer tick, status %8.8x "
 840                           "config %8.8x.\n",
 841                           dev->name, (int)readl(ioaddr + IntrStatus),
 842                           (int)readl(ioaddr + NetworkConfig));
 843        spin_lock_irq(&np->lock);
 844        update_csr6(dev, update_link(dev));
 845        spin_unlock_irq(&np->lock);
 846        np->timer.expires = jiffies + 10*HZ;
 847        add_timer(&np->timer);
 848}
 849
 850static void init_rxtx_rings(struct net_device *dev)
 851{
 852        struct netdev_private *np = dev->priv;
 853        int i;
 854
 855        np->rx_head_desc = &np->rx_ring[0];
 856        np->tx_ring = (struct w840_tx_desc*)&np->rx_ring[RX_RING_SIZE];
 857
 858        /* Initial all Rx descriptors. */
 859        for (i = 0; i < RX_RING_SIZE; i++) {
 860                np->rx_ring[i].length = np->rx_buf_sz;
 861                np->rx_ring[i].status = 0;
 862                np->rx_skbuff[i] = 0;
 863        }
 864        /* Mark the last entry as wrapping the ring. */
 865        np->rx_ring[i-1].length |= DescEndRing;
 866
 867        /* Fill in the Rx buffers.  Handle allocation failure gracefully. */
 868        for (i = 0; i < RX_RING_SIZE; i++) {
 869                struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz);
 870                np->rx_skbuff[i] = skb;
 871                if (skb == NULL)
 872                        break;
 873                skb->dev = dev;                 /* Mark as being used by this device. */
 874                np->rx_addr[i] = pci_map_single(np->pci_dev,skb->tail,
 875                                        skb->len,PCI_DMA_FROMDEVICE);
 876
 877                np->rx_ring[i].buffer1 = np->rx_addr[i];
 878                np->rx_ring[i].status = DescOwn;
 879        }
 880
 881        np->cur_rx = 0;
 882        np->dirty_rx = (unsigned int)(i - RX_RING_SIZE);
 883
 884        /* Initialize the Tx descriptors */
 885        for (i = 0; i < TX_RING_SIZE; i++) {
 886                np->tx_skbuff[i] = 0;
 887                np->tx_ring[i].status = 0;
 888        }
 889        np->tx_full = 0;
 890        np->tx_q_bytes = np->dirty_tx = np->cur_tx = 0;
 891
 892        writel(np->ring_dma_addr, dev->base_addr + RxRingPtr);
 893        writel(np->ring_dma_addr+sizeof(struct w840_rx_desc)*RX_RING_SIZE,
 894                dev->base_addr + TxRingPtr);
 895
 896}
 897
 898static void free_rxtx_rings(struct netdev_private* np)
 899{
 900        int i;
 901        /* Free all the skbuffs in the Rx queue. */
 902        for (i = 0; i < RX_RING_SIZE; i++) {
 903                np->rx_ring[i].status = 0;
 904                if (np->rx_skbuff[i]) {
 905                        pci_unmap_single(np->pci_dev,
 906                                                np->rx_addr[i],
 907                                                np->rx_skbuff[i]->len,
 908                                                PCI_DMA_FROMDEVICE);
 909                        dev_kfree_skb(np->rx_skbuff[i]);
 910                }
 911                np->rx_skbuff[i] = 0;
 912        }
 913        for (i = 0; i < TX_RING_SIZE; i++) {
 914                if (np->tx_skbuff[i]) {
 915                        pci_unmap_single(np->pci_dev,
 916                                                np->tx_addr[i],
 917                                                np->tx_skbuff[i]->len,
 918                                                PCI_DMA_TODEVICE);
 919                        dev_kfree_skb(np->tx_skbuff[i]);
 920                }
 921                np->tx_skbuff[i] = 0;
 922        }
 923}
 924
 925static void init_registers(struct net_device *dev)
 926{
 927        struct netdev_private *np = dev->priv;
 928        long ioaddr = dev->base_addr;
 929        int i;
 930
 931        for (i = 0; i < 6; i++)
 932                writeb(dev->dev_addr[i], ioaddr + StationAddr + i);
 933
 934        /* Initialize other registers. */
 935#ifdef __BIG_ENDIAN
 936        i = (1<<20);    /* Big-endian descriptors */
 937#else
 938        i = 0;
 939#endif
 940        i |= (0x04<<2);         /* skip length 4 u32 */
 941        i |= 0x02;              /* give Rx priority */
 942
 943        /* Configure the PCI bus bursts and FIFO thresholds.
 944           486: Set 8 longword cache alignment, 8 longword burst.
 945           586: Set 16 longword cache alignment, no burst limit.
 946           Cache alignment bits 15:14        Burst length 13:8
 947                0000    <not allowed>           0000 align to cache     0800 8 longwords
 948                4000    8  longwords            0100 1 longword         1000 16 longwords
 949                8000    16 longwords            0200 2 longwords        2000 32 longwords
 950                C000    32  longwords           0400 4 longwords */
 951
 952#if defined (__i386__) && !defined(MODULE)
 953        /* When not a module we can work around broken '486 PCI boards. */
 954        if (boot_cpu_data.x86 <= 4) {
 955                i |= 0x4800;
 956                printk(KERN_INFO "%s: This is a 386/486 PCI system, setting cache "
 957                           "alignment to 8 longwords.\n", dev->name);
 958        } else {
 959                i |= 0xE000;
 960        }
 961#elif defined(__powerpc__) || defined(__i386__) || defined(__alpha__) || defined(__ia64__) || defined(__x86_64__)
 962        i |= 0xE000;
 963#elif defined(__sparc__)
 964        i |= 0x4800;
 965#else
 966#warning Processor architecture undefined
 967        i |= 0x4800;
 968#endif
 969        writel(i, ioaddr + PCIBusCfg);
 970
 971        np->csr6 = 0;
 972        /* 128 byte Tx threshold; 
 973                Transmit on; Receive on; */
 974        update_csr6(dev, 0x00022002 | update_link(dev) | __set_rx_mode(dev));
 975
 976        /* Clear and Enable interrupts by setting the interrupt mask. */
 977        writel(0x1A0F5, ioaddr + IntrStatus);
 978        writel(0x1A0F5, ioaddr + IntrEnable);
 979
 980        writel(0, ioaddr + RxStartDemand);
 981}
 982
 983static void tx_timeout(struct net_device *dev)
 984{
 985        struct netdev_private *np = dev->priv;
 986        long ioaddr = dev->base_addr;
 987
 988        printk(KERN_WARNING "%s: Transmit timed out, status %8.8x,"
 989                   " resetting...\n", dev->name, (int)readl(ioaddr + IntrStatus));
 990
 991        {
 992                int i;
 993                printk(KERN_DEBUG "  Rx ring %p: ", np->rx_ring);
 994                for (i = 0; i < RX_RING_SIZE; i++)
 995                        printk(" %8.8x", (unsigned int)np->rx_ring[i].status);
 996                printk("\n"KERN_DEBUG"  Tx ring %p: ", np->tx_ring);
 997                for (i = 0; i < TX_RING_SIZE; i++)
 998                        printk(" %8.8x", np->tx_ring[i].status);
 999                printk("\n");
1000        }
1001        printk(KERN_DEBUG "Tx cur %d Tx dirty %d Tx Full %d, q bytes %d.\n",
1002                                np->cur_tx, np->dirty_tx, np->tx_full, np->tx_q_bytes);
1003        printk(KERN_DEBUG "Tx Descriptor addr %xh.\n",readl(ioaddr+0x4C));
1004
1005        disable_irq(dev->irq);
1006        spin_lock_irq(&np->lock);
1007        /*
1008         * Under high load dirty_tx and the internal tx descriptor pointer
1009         * come out of sync, thus perform a software reset and reinitialize
1010         * everything.
1011         */
1012
1013        writel(1, dev->base_addr+PCIBusCfg);
1014        udelay(1);
1015
1016        free_rxtx_rings(np);
1017        init_rxtx_rings(dev);
1018        init_registers(dev);
1019        spin_unlock_irq(&np->lock);
1020        enable_irq(dev->irq);
1021
1022        netif_wake_queue(dev);
1023        dev->trans_start = jiffies;
1024        np->stats.tx_errors++;
1025        return;
1026}
1027
1028/* Initialize the Rx and Tx rings, along with various 'dev' bits. */
1029static int alloc_ringdesc(struct net_device *dev)
1030{
1031        struct netdev_private *np = dev->priv;
1032
1033        np->rx_buf_sz = (dev->mtu <= 1500 ? PKT_BUF_SZ : dev->mtu + 32);
1034
1035        np->rx_ring = pci_alloc_consistent(np->pci_dev,
1036                        sizeof(struct w840_rx_desc)*RX_RING_SIZE +
1037                        sizeof(struct w840_tx_desc)*TX_RING_SIZE,
1038                        &np->ring_dma_addr);
1039        if(!np->rx_ring)
1040                return -ENOMEM;
1041        init_rxtx_rings(dev);
1042        return 0;
1043}
1044
1045static void free_ringdesc(struct netdev_private *np)
1046{
1047        pci_free_consistent(np->pci_dev,
1048                        sizeof(struct w840_rx_desc)*RX_RING_SIZE +
1049                        sizeof(struct w840_tx_desc)*TX_RING_SIZE,
1050                        np->rx_ring, np->ring_dma_addr);
1051
1052}
1053
1054static int start_tx(struct sk_buff *skb, struct net_device *dev)
1055{
1056        struct netdev_private *np = dev->priv;
1057        unsigned entry;
1058
1059        /* Caution: the write order is important here, set the field
1060           with the "ownership" bits last. */
1061
1062        /* Calculate the next Tx descriptor entry. */
1063        entry = np->cur_tx % TX_RING_SIZE;
1064
1065        np->tx_addr[entry] = pci_map_single(np->pci_dev,
1066                                skb->data,skb->len, PCI_DMA_TODEVICE);
1067        np->tx_skbuff[entry] = skb;
1068
1069        np->tx_ring[entry].buffer1 = np->tx_addr[entry];
1070        if (skb->len < TX_BUFLIMIT) {
1071                np->tx_ring[entry].length = DescWholePkt | skb->len;
1072        } else {
1073                int len = skb->len - TX_BUFLIMIT;
1074
1075                np->tx_ring[entry].buffer2 = np->tx_addr[entry]+TX_BUFLIMIT;
1076                np->tx_ring[entry].length = DescWholePkt | (len << 11) | TX_BUFLIMIT;
1077        }
1078        if(entry == TX_RING_SIZE-1)
1079                np->tx_ring[entry].length |= DescEndRing;
1080
1081        /* Now acquire the irq spinlock.
1082         * The difficult race is the the ordering between
1083         * increasing np->cur_tx and setting DescOwn:
1084         * - if np->cur_tx is increased first the interrupt
1085         *   handler could consider the packet as transmitted
1086         *   since DescOwn is cleared.
1087         * - If DescOwn is set first the NIC could report the
1088         *   packet as sent, but the interrupt handler would ignore it
1089         *   since the np->cur_tx was not yet increased.
1090         */
1091        spin_lock_irq(&np->lock);
1092        np->cur_tx++;
1093
1094        wmb(); /* flush length, buffer1, buffer2 */
1095        np->tx_ring[entry].status = DescOwn;
1096        wmb(); /* flush status and kick the hardware */
1097        writel(0, dev->base_addr + TxStartDemand);
1098        np->tx_q_bytes += skb->len;
1099        /* Work around horrible bug in the chip by marking the queue as full
1100           when we do not have FIFO room for a maximum sized packet. */
1101        if (np->cur_tx - np->dirty_tx > TX_QUEUE_LEN ||
1102                ((np->drv_flags & HasBrokenTx) && np->tx_q_bytes > TX_BUG_FIFO_LIMIT)) {
1103                netif_stop_queue(dev);
1104                wmb();
1105                np->tx_full = 1;
1106        }
1107        spin_unlock_irq(&np->lock);
1108
1109        dev->trans_start = jiffies;
1110
1111        if (debug > 4) {
1112                printk(KERN_DEBUG "%s: Transmit frame #%d queued in slot %d.\n",
1113                           dev->name, np->cur_tx, entry);
1114        }
1115        return 0;
1116}
1117
1118static void netdev_tx_done(struct net_device *dev)
1119{
1120        struct netdev_private *np = dev->priv;
1121        for (; np->cur_tx - np->dirty_tx > 0; np->dirty_tx++) {
1122                int entry = np->dirty_tx % TX_RING_SIZE;
1123                int tx_status = np->tx_ring[entry].status;
1124
1125                if (tx_status < 0)
1126                        break;
1127                if (tx_status & 0x8000) {       /* There was an error, log it. */
1128#ifndef final_version
1129                        if (debug > 1)
1130                                printk(KERN_DEBUG "%s: Transmit error, Tx status %8.8x.\n",
1131                                           dev->name, tx_status);
1132#endif
1133                        np->stats.tx_errors++;
1134                        if (tx_status & 0x0104) np->stats.tx_aborted_errors++;
1135                        if (tx_status & 0x0C80) np->stats.tx_carrier_errors++;
1136                        if (tx_status & 0x0200) np->stats.tx_window_errors++;
1137                        if (tx_status & 0x0002) np->stats.tx_fifo_errors++;
1138                        if ((tx_status & 0x0080) && np->mii_if.full_duplex == 0)
1139                                np->stats.tx_heartbeat_errors++;
1140                } else {
1141#ifndef final_version
1142                        if (debug > 3)
1143                                printk(KERN_DEBUG "%s: Transmit slot %d ok, Tx status %8.8x.\n",
1144                                           dev->name, entry, tx_status);
1145#endif
1146                        np->stats.tx_bytes += np->tx_skbuff[entry]->len;
1147                        np->stats.collisions += (tx_status >> 3) & 15;
1148                        np->stats.tx_packets++;
1149                }
1150                /* Free the original skb. */
1151                pci_unmap_single(np->pci_dev,np->tx_addr[entry],
1152                                        np->tx_skbuff[entry]->len,
1153                                        PCI_DMA_TODEVICE);
1154                np->tx_q_bytes -= np->tx_skbuff[entry]->len;
1155                dev_kfree_skb_irq(np->tx_skbuff[entry]);
1156                np->tx_skbuff[entry] = 0;
1157        }
1158        if (np->tx_full &&
1159                np->cur_tx - np->dirty_tx < TX_QUEUE_LEN_RESTART &&
1160                np->tx_q_bytes < TX_BUG_FIFO_LIMIT) {
1161                /* The ring is no longer full, clear tbusy. */
1162                np->tx_full = 0;
1163                wmb();
1164                netif_wake_queue(dev);
1165        }
1166}
1167
1168/* The interrupt handler does all of the Rx thread work and cleans up
1169   after the Tx thread. */
1170static irqreturn_t intr_handler(int irq, void *dev_instance, struct pt_regs *rgs)
1171{
1172        struct net_device *dev = (struct net_device *)dev_instance;
1173        struct netdev_private *np = dev->priv;
1174        long ioaddr = dev->base_addr;
1175        int work_limit = max_interrupt_work;
1176        int handled = 0;
1177
1178        if (!netif_device_present(dev))
1179                return IRQ_NONE;
1180        do {
1181                u32 intr_status = readl(ioaddr + IntrStatus);
1182
1183                /* Acknowledge all of the current interrupt sources ASAP. */
1184                writel(intr_status & 0x001ffff, ioaddr + IntrStatus);
1185
1186                if (debug > 4)
1187                        printk(KERN_DEBUG "%s: Interrupt, status %4.4x.\n",
1188                                   dev->name, intr_status);
1189
1190                if ((intr_status & (NormalIntr|AbnormalIntr)) == 0)
1191                        break;
1192
1193                handled = 1;
1194
1195                if (intr_status & (IntrRxDone | RxNoBuf))
1196                        netdev_rx(dev);
1197                if (intr_status & RxNoBuf)
1198                        writel(0, ioaddr + RxStartDemand);
1199
1200                if (intr_status & (TxIdle | IntrTxDone) &&
1201                        np->cur_tx != np->dirty_tx) {
1202                        spin_lock(&np->lock);
1203                        netdev_tx_done(dev);
1204                        spin_unlock(&np->lock);
1205                }
1206
1207                /* Abnormal error summary/uncommon events handlers. */
1208                if (intr_status & (AbnormalIntr | TxFIFOUnderflow | IntrPCIErr |
1209                                                   TimerInt | IntrTxStopped))
1210                        netdev_error(dev, intr_status);
1211
1212                if (--work_limit < 0) {
1213                        printk(KERN_WARNING "%s: Too much work at interrupt, "
1214                                   "status=0x%4.4x.\n", dev->name, intr_status);
1215                        /* Set the timer to re-enable the other interrupts after
1216                           10*82usec ticks. */
1217                        spin_lock(&np->lock);
1218                        if (netif_device_present(dev)) {
1219                                writel(AbnormalIntr | TimerInt, ioaddr + IntrEnable);
1220                                writel(10, ioaddr + GPTimer);
1221                        }
1222                        spin_unlock(&np->lock);
1223                        break;
1224                }
1225        } while (1);
1226
1227        if (debug > 3)
1228                printk(KERN_DEBUG "%s: exiting interrupt, status=%#4.4x.\n",
1229                           dev->name, (int)readl(ioaddr + IntrStatus));
1230        return IRQ_RETVAL(handled);
1231}
1232
1233/* This routine is logically part of the interrupt handler, but separated
1234   for clarity and better register allocation. */
1235static int netdev_rx(struct net_device *dev)
1236{
1237        struct netdev_private *np = dev->priv;
1238        int entry = np->cur_rx % RX_RING_SIZE;
1239        int work_limit = np->dirty_rx + RX_RING_SIZE - np->cur_rx;
1240
1241        if (debug > 4) {
1242                printk(KERN_DEBUG " In netdev_rx(), entry %d status %4.4x.\n",
1243                           entry, np->rx_ring[entry].status);
1244        }
1245
1246        /* If EOP is set on the next entry, it's a new packet. Send it up. */
1247        while (--work_limit >= 0) {
1248                struct w840_rx_desc *desc = np->rx_head_desc;
1249                s32 status = desc->status;
1250
1251                if (debug > 4)
1252                        printk(KERN_DEBUG "  netdev_rx() status was %8.8x.\n",
1253                                   status);
1254                if (status < 0)
1255                        break;
1256                if ((status & 0x38008300) != 0x0300) {
1257                        if ((status & 0x38000300) != 0x0300) {
1258                                /* Ingore earlier buffers. */
1259                                if ((status & 0xffff) != 0x7fff) {
1260                                        printk(KERN_WARNING "%s: Oversized Ethernet frame spanned "
1261                                                   "multiple buffers, entry %#x status %4.4x!\n",
1262                                                   dev->name, np->cur_rx, status);
1263                                        np->stats.rx_length_errors++;
1264                                }
1265                        } else if (status & 0x8000) {
1266                                /* There was a fatal error. */
1267                                if (debug > 2)
1268                                        printk(KERN_DEBUG "%s: Receive error, Rx status %8.8x.\n",
1269                                                   dev->name, status);
1270                                np->stats.rx_errors++; /* end of a packet.*/
1271                                if (status & 0x0890) np->stats.rx_length_errors++;
1272                                if (status & 0x004C) np->stats.rx_frame_errors++;
1273                                if (status & 0x0002) np->stats.rx_crc_errors++;
1274                        }
1275                } else {
1276                        struct sk_buff *skb;
1277                        /* Omit the four octet CRC from the length. */
1278                        int pkt_len = ((status >> 16) & 0x7ff) - 4;
1279
1280#ifndef final_version
1281                        if (debug > 4)
1282                                printk(KERN_DEBUG "  netdev_rx() normal Rx pkt length %d"
1283                                           " status %x.\n", pkt_len, status);
1284#endif
1285                        /* Check if the packet is long enough to accept without copying
1286                           to a minimally-sized skbuff. */
1287                        if (pkt_len < rx_copybreak
1288                                && (skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
1289                                skb->dev = dev;
1290                                skb_reserve(skb, 2);    /* 16 byte align the IP header */
1291                                pci_dma_sync_single(np->pci_dev,np->rx_addr[entry],
1292                                                        np->rx_skbuff[entry]->len,
1293                                                        PCI_DMA_FROMDEVICE);
1294                                /* Call copy + cksum if available. */
1295#if HAS_IP_COPYSUM
1296                                eth_copy_and_sum(skb, np->rx_skbuff[entry]->tail, pkt_len, 0);
1297                                skb_put(skb, pkt_len);
1298#else
1299                                memcpy(skb_put(skb, pkt_len), np->rx_skbuff[entry]->tail,
1300                                           pkt_len);
1301#endif
1302                        } else {
1303                                pci_unmap_single(np->pci_dev,np->rx_addr[entry],
1304                                                        np->rx_skbuff[entry]->len,
1305                                                        PCI_DMA_FROMDEVICE);
1306                                skb_put(skb = np->rx_skbuff[entry], pkt_len);
1307                                np->rx_skbuff[entry] = NULL;
1308                        }
1309#ifndef final_version                           /* Remove after testing. */
1310                        /* You will want this info for the initial debug. */
1311                        if (debug > 5)
1312                                printk(KERN_DEBUG "  Rx data %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:"
1313                                           "%2.2x %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x %2.2x%2.2x "
1314                                           "%d.%d.%d.%d.\n",
1315                                           skb->data[0], skb->data[1], skb->data[2], skb->data[3],
1316                                           skb->data[4], skb->data[5], skb->data[6], skb->data[7],
1317                                           skb->data[8], skb->data[9], skb->data[10],
1318                                           skb->data[11], skb->data[12], skb->data[13],
1319                                           skb->data[14], skb->data[15], skb->data[16],
1320                                           skb->data[17]);
1321#endif
1322                        skb->protocol = eth_type_trans(skb, dev);
1323                        netif_rx(skb);
1324                        dev->last_rx = jiffies;
1325                        np->stats.rx_packets++;
1326                        np->stats.rx_bytes += pkt_len;
1327                }
1328                entry = (++np->cur_rx) % RX_RING_SIZE;
1329                np->rx_head_desc = &np->rx_ring[entry];
1330        }
1331
1332        /* Refill the Rx ring buffers. */
1333        for (; np->cur_rx - np->dirty_rx > 0; np->dirty_rx++) {
1334                struct sk_buff *skb;
1335                entry = np->dirty_rx % RX_RING_SIZE;
1336                if (np->rx_skbuff[entry] == NULL) {
1337                        skb = dev_alloc_skb(np->rx_buf_sz);
1338                        np->rx_skbuff[entry] = skb;
1339                        if (skb == NULL)
1340                                break;                  /* Better luck next round. */
1341                        skb->dev = dev;                 /* Mark as being used by this device. */
1342                        np->rx_addr[entry] = pci_map_single(np->pci_dev,
1343                                                        skb->tail,
1344                                                        skb->len, PCI_DMA_FROMDEVICE);
1345                        np->rx_ring[entry].buffer1 = np->rx_addr[entry];
1346                }
1347                wmb();
1348                np->rx_ring[entry].status = DescOwn;
1349        }
1350
1351        return 0;
1352}
1353
1354static void netdev_error(struct net_device *dev, int intr_status)
1355{
1356        long ioaddr = dev->base_addr;
1357        struct netdev_private *np = dev->priv;
1358
1359        if (debug > 2)
1360                printk(KERN_DEBUG "%s: Abnormal event, %8.8x.\n",
1361                           dev->name, intr_status);
1362        if (intr_status == 0xffffffff)
1363                return;
1364        spin_lock(&np->lock);
1365        if (intr_status & TxFIFOUnderflow) {
1366                int new;
1367                /* Bump up the Tx threshold */
1368#if 0
1369                /* This causes lots of dropped packets,
1370                 * and under high load even tx_timeouts
1371                 */
1372                new = np->csr6 + 0x4000;
1373#else
1374                new = (np->csr6 >> 14)&0x7f;
1375                if (new < 64)
1376                        new *= 2;
1377                 else
1378                        new = 127; /* load full packet before starting */
1379                new = (np->csr6 & ~(0x7F << 14)) | (new<<14);
1380#endif
1381                printk(KERN_DEBUG "%s: Tx underflow, new csr6 %8.8x.\n",
1382                           dev->name, new);
1383                update_csr6(dev, new);
1384        }
1385        if (intr_status & IntrRxDied) {         /* Missed a Rx frame. */
1386                np->stats.rx_errors++;
1387        }
1388        if (intr_status & TimerInt) {
1389                /* Re-enable other interrupts. */
1390                if (netif_device_present(dev))
1391                        writel(0x1A0F5, ioaddr + IntrEnable);
1392        }
1393        np->stats.rx_missed_errors += readl(ioaddr + RxMissed) & 0xffff;
1394        writel(0, ioaddr + RxStartDemand);
1395        spin_unlock(&np->lock);
1396}
1397
1398static struct net_device_stats *get_stats(struct net_device *dev)
1399{
1400        long ioaddr = dev->base_addr;
1401        struct netdev_private *np = dev->priv;
1402
1403        /* The chip only need report frame silently dropped. */
1404        spin_lock_irq(&np->lock);
1405        if (netif_running(dev) && netif_device_present(dev))
1406                np->stats.rx_missed_errors += readl(ioaddr + RxMissed) & 0xffff;
1407        spin_unlock_irq(&np->lock);
1408
1409        return &np->stats;
1410}
1411
1412
1413static u32 __set_rx_mode(struct net_device *dev)
1414{
1415        long ioaddr = dev->base_addr;
1416        u32 mc_filter[2];                       /* Multicast hash filter */
1417        u32 rx_mode;
1418
1419        if (dev->flags & IFF_PROMISC) {                 /* Set promiscuous. */
1420                /* Unconditionally log net taps. */
1421                printk(KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
1422                memset(mc_filter, 0xff, sizeof(mc_filter));
1423                rx_mode = AcceptBroadcast | AcceptMulticast | AcceptAllPhys
1424                        | AcceptMyPhys;
1425        } else if ((dev->mc_count > multicast_filter_limit)
1426                           ||  (dev->flags & IFF_ALLMULTI)) {
1427                /* Too many to match, or accept all multicasts. */
1428                memset(mc_filter, 0xff, sizeof(mc_filter));
1429                rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys;
1430        } else {
1431                struct dev_mc_list *mclist;
1432                int i;
1433                memset(mc_filter, 0, sizeof(mc_filter));
1434                for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
1435                         i++, mclist = mclist->next) {
1436                        int filterbit = (ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26) ^ 0x3F;
1437                        filterbit &= 0x3f;
1438                        mc_filter[filterbit >> 5] |= cpu_to_le32(1 << (filterbit & 31));
1439                }
1440                rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys;
1441        }
1442        writel(mc_filter[0], ioaddr + MulticastFilter0);
1443        writel(mc_filter[1], ioaddr + MulticastFilter1);
1444        return rx_mode;
1445}
1446
1447static void set_rx_mode(struct net_device *dev)
1448{
1449        struct netdev_private *np = dev->priv;
1450        u32 rx_mode = __set_rx_mode(dev);
1451        spin_lock_irq(&np->lock);
1452        update_csr6(dev, (np->csr6 & ~0x00F8) | rx_mode);
1453        spin_unlock_irq(&np->lock);
1454}
1455
1456static void netdev_get_drvinfo (struct net_device *dev, struct ethtool_drvinfo *info)
1457{
1458        struct netdev_private *np = dev->priv;
1459
1460        strcpy (info->driver, DRV_NAME);
1461        strcpy (info->version, DRV_VERSION);
1462        strcpy (info->bus_info, pci_name(np->pci_dev));
1463}
1464
1465static int netdev_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
1466{
1467        struct netdev_private *np = dev->priv;
1468        int rc;
1469
1470        spin_lock_irq(&np->lock);
1471        rc = mii_ethtool_gset(&np->mii_if, cmd);
1472        spin_unlock_irq(&np->lock);
1473
1474        return rc;
1475}
1476
1477static int netdev_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
1478{
1479        struct netdev_private *np = dev->priv;
1480        int rc;
1481
1482        spin_lock_irq(&np->lock);
1483        rc = mii_ethtool_sset(&np->mii_if, cmd);
1484        spin_unlock_irq(&np->lock);
1485
1486        return rc;
1487}
1488
1489static int netdev_nway_reset(struct net_device *dev)
1490{
1491        struct netdev_private *np = dev->priv;
1492        return mii_nway_restart(&np->mii_if);
1493}
1494
1495static u32 netdev_get_link(struct net_device *dev)
1496{
1497        struct netdev_private *np = dev->priv;
1498        return mii_link_ok(&np->mii_if);
1499}
1500
1501static u32 netdev_get_msglevel(struct net_device *dev)
1502{
1503        return debug;
1504}
1505
1506static void netdev_set_msglevel(struct net_device *dev, u32 value)
1507{
1508        debug = value;
1509}
1510
1511static struct ethtool_ops netdev_ethtool_ops = {
1512        .get_drvinfo            = netdev_get_drvinfo,
1513        .get_settings           = netdev_get_settings,
1514        .set_settings           = netdev_set_settings,
1515        .nway_reset             = netdev_nway_reset,
1516        .get_link               = netdev_get_link,
1517        .get_msglevel           = netdev_get_msglevel,
1518        .set_msglevel           = netdev_set_msglevel,
1519        .get_sg                 = ethtool_op_get_sg,
1520        .get_tx_csum            = ethtool_op_get_tx_csum,
1521};
1522
1523static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1524{
1525        struct mii_ioctl_data *data = (struct mii_ioctl_data *)&rq->ifr_data;
1526        struct netdev_private *np = dev->priv;
1527
1528        switch(cmd) {
1529        case SIOCGMIIPHY:               /* Get address of MII PHY in use. */
1530        case SIOCDEVPRIVATE:            /* for binary compat, remove in 2.5 */
1531                data->phy_id = ((struct netdev_private *)dev->priv)->phys[0] & 0x1f;
1532                /* Fall Through */
1533
1534        case SIOCGMIIREG:               /* Read MII PHY register. */
1535        case SIOCDEVPRIVATE+1:          /* for binary compat, remove in 2.5 */
1536                spin_lock_irq(&np->lock);
1537                data->val_out = mdio_read(dev, data->phy_id & 0x1f, data->reg_num & 0x1f);
1538                spin_unlock_irq(&np->lock);
1539                return 0;
1540
1541        case SIOCSMIIREG:               /* Write MII PHY register. */
1542        case SIOCDEVPRIVATE+2:          /* for binary compat, remove in 2.5 */
1543                if (!capable(CAP_NET_ADMIN))
1544                        return -EPERM;
1545                spin_lock_irq(&np->lock);
1546                mdio_write(dev, data->phy_id & 0x1f, data->reg_num & 0x1f, data->val_in);
1547                spin_unlock_irq(&np->lock);
1548                return 0;
1549        default:
1550                return -EOPNOTSUPP;
1551        }
1552}
1553
1554static int netdev_close(struct net_device *dev)
1555{
1556        long ioaddr = dev->base_addr;
1557        struct netdev_private *np = dev->priv;
1558
1559        netif_stop_queue(dev);
1560
1561        if (debug > 1) {
1562                printk(KERN_DEBUG "%s: Shutting down ethercard, status was %8.8x "
1563                           "Config %8.8x.\n", dev->name, (int)readl(ioaddr + IntrStatus),
1564                           (int)readl(ioaddr + NetworkConfig));
1565                printk(KERN_DEBUG "%s: Queue pointers were Tx %d / %d,  Rx %d / %d.\n",
1566                           dev->name, np->cur_tx, np->dirty_tx, np->cur_rx, np->dirty_rx);
1567        }
1568
1569        /* Stop the chip's Tx and Rx processes. */
1570        spin_lock_irq(&np->lock);
1571        netif_device_detach(dev);
1572        update_csr6(dev, 0);
1573        writel(0x0000, ioaddr + IntrEnable);
1574        spin_unlock_irq(&np->lock);
1575
1576        free_irq(dev->irq, dev);
1577        wmb();
1578        netif_device_attach(dev);
1579
1580        if (readl(ioaddr + NetworkConfig) != 0xffffffff)
1581                np->stats.rx_missed_errors += readl(ioaddr + RxMissed) & 0xffff;
1582
1583#ifdef __i386__
1584        if (debug > 2) {
1585                int i;
1586
1587                printk(KERN_DEBUG"  Tx ring at %8.8x:\n",
1588                           (int)np->tx_ring);
1589                for (i = 0; i < TX_RING_SIZE; i++)
1590                        printk(KERN_DEBUG " #%d desc. %4.4x %4.4x %8.8x.\n",
1591                                   i, np->tx_ring[i].length,
1592                                   np->tx_ring[i].status, np->tx_ring[i].buffer1);
1593                printk("\n"KERN_DEBUG "  Rx ring %8.8x:\n",
1594                           (int)np->rx_ring);
1595                for (i = 0; i < RX_RING_SIZE; i++) {
1596                        printk(KERN_DEBUG " #%d desc. %4.4x %4.4x %8.8x\n",
1597                                   i, np->rx_ring[i].length,
1598                                   np->rx_ring[i].status, np->rx_ring[i].buffer1);
1599                }
1600        }
1601#endif /* __i386__ debugging only */
1602
1603        del_timer_sync(&np->timer);
1604
1605        free_rxtx_rings(np);
1606        free_ringdesc(np);
1607
1608        return 0;
1609}
1610
1611static void __devexit w840_remove1 (struct pci_dev *pdev)
1612{
1613        struct net_device *dev = pci_get_drvdata(pdev);
1614        
1615        /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
1616        if (dev) {
1617                unregister_netdev(dev);
1618                pci_release_regions(pdev);
1619#ifndef USE_IO_OPS
1620                iounmap((char *)(dev->base_addr));
1621#endif
1622                kfree(dev);
1623        }
1624
1625        pci_set_drvdata(pdev, NULL);
1626}
1627
1628#ifdef CONFIG_PM
1629
1630/*
1631 * suspend/resume synchronization:
1632 * - open, close, do_ioctl:
1633 *      rtnl_lock, & netif_device_detach after the rtnl_unlock.
1634 * - get_stats:
1635 *      spin_lock_irq(np->lock), doesn't touch hw if not present
1636 * - hard_start_xmit:
1637 *      netif_stop_queue + spin_unlock_wait(&dev->xmit_lock);
1638 * - tx_timeout:
1639 *      netif_device_detach + spin_unlock_wait(&dev->xmit_lock);
1640 * - set_multicast_list
1641 *      netif_device_detach + spin_unlock_wait(&dev->xmit_lock);
1642 * - interrupt handler
1643 *      doesn't touch hw if not present, synchronize_irq waits for
1644 *      running instances of the interrupt handler.
1645 *
1646 * Disabling hw requires clearing csr6 & IntrEnable.
1647 * update_csr6 & all function that write IntrEnable check netif_device_present
1648 * before settings any bits.
1649 *
1650 * Detach must occur under spin_unlock_irq(), interrupts from a detached
1651 * device would cause an irq storm.
1652 */
1653static int w840_suspend (struct pci_dev *pdev, u32 state)
1654{
1655        struct net_device *dev = pci_get_drvdata (pdev);
1656        struct netdev_private *np = dev->priv;
1657        long ioaddr = dev->base_addr;
1658
1659        rtnl_lock();
1660        if (netif_running (dev)) {
1661                del_timer_sync(&np->timer);
1662
1663                spin_lock_irq(&np->lock);
1664                netif_device_detach(dev);
1665                update_csr6(dev, 0);
1666                writel(0, ioaddr + IntrEnable);
1667                netif_stop_queue(dev);
1668                spin_unlock_irq(&np->lock);
1669
1670                spin_unlock_wait(&dev->xmit_lock);
1671                synchronize_irq();
1672        
1673                np->stats.rx_missed_errors += readl(ioaddr + RxMissed) & 0xffff;
1674
1675                /* no more hardware accesses behind this line. */
1676
1677                if (np->csr6) BUG();
1678                if (readl(ioaddr + IntrEnable)) BUG();
1679
1680                /* pci_power_off(pdev, -1); */
1681
1682                free_rxtx_rings(np);
1683        } else {
1684                netif_device_detach(dev);
1685        }
1686        rtnl_unlock();
1687        return 0;
1688}
1689
1690static int w840_resume (struct pci_dev *pdev)
1691{
1692        struct net_device *dev = pci_get_drvdata (pdev);
1693        struct netdev_private *np = dev->priv;
1694
1695        rtnl_lock();
1696        if (netif_device_present(dev))
1697                goto out; /* device not suspended */
1698        if (netif_running(dev)) {
1699                pci_enable_device(pdev);
1700        /*      pci_power_on(pdev); */
1701
1702                spin_lock_irq(&np->lock);
1703                writel(1, dev->base_addr+PCIBusCfg);
1704                readl(dev->base_addr+PCIBusCfg);
1705                udelay(1);
1706                netif_device_attach(dev);
1707                init_rxtx_rings(dev);
1708                init_registers(dev);
1709                spin_unlock_irq(&np->lock);
1710
1711                netif_wake_queue(dev);
1712
1713                mod_timer(&np->timer, jiffies + 1*HZ);
1714        } else {
1715                netif_device_attach(dev);
1716        }
1717out:
1718        rtnl_unlock();
1719        return 0;
1720}
1721#endif
1722
1723static struct pci_driver w840_driver = {
1724        .name           = DRV_NAME,
1725        .id_table       = w840_pci_tbl,
1726        .probe          = w840_probe1,
1727        .remove         = __devexit_p(w840_remove1),
1728#ifdef CONFIG_PM
1729        .suspend        = w840_suspend,
1730        .resume         = w840_resume,
1731#endif
1732};
1733
1734static int __init w840_init(void)
1735{
1736/* when a module, this is printed whether or not devices are found in probe */
1737#ifdef MODULE
1738        printk(version);
1739#endif
1740        return pci_module_init(&w840_driver);
1741}
1742
1743static void __exit w840_exit(void)
1744{
1745        pci_unregister_driver(&w840_driver);
1746}
1747
1748module_init(w840_init);
1749module_exit(w840_exit);
1750
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.