Merge master.kernel.org:/pub/scm/linux/kernel/git/sfrench/cifs-2.6
[pandora-kernel.git] / drivers / net / natsemi.c
index 9df2628..adf29dd 100644 (file)
 
        Support information and updates available at
        http://www.scyld.com/network/netsemi.html
+       [link no longer provides useful info -jgarzik]
 
 
-       Linux kernel modifications:
-
-       Version 1.0.1:
-               - Spinlock fixes
-               - Bug fixes and better intr performance (Tjeerd)
-       Version 1.0.2:
-               - Now reads correct MAC address from eeprom
-       Version 1.0.3:
-               - Eliminate redundant priv->tx_full flag
-               - Call netif_start_queue from dev->tx_timeout
-               - wmb() in start_tx() to flush data
-               - Update Tx locking
-               - Clean up PCI enable (davej)
-       Version 1.0.4:
-               - Merge Donald Becker's natsemi.c version 1.07
-       Version 1.0.5:
-               - { fill me in }
-       Version 1.0.6:
-               * ethtool support (jgarzik)
-               * Proper initialization of the card (which sometimes
-               fails to occur and leaves the card in a non-functional
-               state). (uzi)
-
-               * Some documented register settings to optimize some
-               of the 100Mbit autodetection circuitry in rev C cards. (uzi)
-
-               * Polling of the PHY intr for stuff like link state
-               change and auto- negotiation to finally work properly. (uzi)
-
-               * One-liner removal of a duplicate declaration of
-               netdev_error(). (uzi)
-
-       Version 1.0.7: (Manfred Spraul)
-               * pci dma
-               * SMP locking update
-               * full reset added into tx_timeout
-               * correct multicast hash generation (both big and little endian)
-                       [copied from a natsemi driver version
-                        from Myrio Corporation, Greg Smith]
-               * suspend/resume
-
-       version 1.0.8 (Tim Hockin <thockin@sun.com>)
-               * ETHTOOL_* support
-               * Wake on lan support (Erik Gilling)
-               * MXDMA fixes for serverworks
-               * EEPROM reload
-
-       version 1.0.9 (Manfred Spraul)
-               * Main change: fix lack of synchronize
-               netif_close/netif_suspend against a last interrupt
-               or packet.
-               * do not enable superflous interrupts (e.g. the
-               drivers relies on TxDone - TxIntr not needed)
-               * wait that the hardware has really stopped in close
-               and suspend.
-               * workaround for the (at least) gcc-2.95.1 compiler
-               problem. Also simplifies the code a bit.
-               * disable_irq() in tx_timeout - needed to protect
-               against rx interrupts.
-               * stop the nic before switching into silent rx mode
-               for wol (required according to docu).
-
-       version 1.0.10:
-               * use long for ee_addr (various)
-               * print pointers properly (DaveM)
-               * include asm/irq.h (?)
-
-       version 1.0.11:
-               * check and reset if PHY errors appear (Adrian Sun)
-               * WoL cleanup (Tim Hockin)
-               * Magic number cleanup (Tim Hockin)
-               * Don't reload EEPROM on every reset (Tim Hockin)
-               * Save and restore EEPROM state across reset (Tim Hockin)
-               * MDIO Cleanup (Tim Hockin)
-               * Reformat register offsets/bits (jgarzik)
-
-       version 1.0.12:
-               * ETHTOOL_* further support (Tim Hockin)
-
-       version 1.0.13:
-               * ETHTOOL_[G]EEPROM support (Tim Hockin)
-
-       version 1.0.13:
-               * crc cleanup (Matt Domsch <Matt_Domsch@dell.com>)
-
-       version 1.0.14:
-               * Cleanup some messages and autoneg in ethtool (Tim Hockin)
-
-       version 1.0.15:
-               * Get rid of cable_magic flag
-               * use new (National provided) solution for cable magic issue
-
-       version 1.0.16:
-               * call netdev_rx() for RxErrors (Manfred Spraul)
-               * formatting and cleanups
-               * change options and full_duplex arrays to be zero
-                 initialized
-               * enable only the WoL and PHY interrupts in wol mode
-
-       version 1.0.17:
-               * only do cable_magic on 83815 and early 83816 (Tim Hockin)
-               * create a function for rx refill (Manfred Spraul)
-               * combine drain_ring and init_ring (Manfred Spraul)
-               * oom handling (Manfred Spraul)
-               * hands_off instead of playing with netif_device_{de,a}ttach
-                 (Manfred Spraul)
-               * be sure to write the MAC back to the chip (Manfred Spraul)
-               * lengthen EEPROM timeout, and always warn about timeouts
-                 (Manfred Spraul)
-               * comments update (Manfred)
-               * do the right thing on a phy-reset (Manfred and Tim)
-
        TODO:
        * big endian support with CFG:BEM instead of cpu_to_le32
 */
 #include <asm/uaccess.h>
 
 #define DRV_NAME       "natsemi"
-#define DRV_VERSION    "1.07+LK1.0.17"
-#define DRV_RELDATE    "Sep 27, 2002"
+#define DRV_VERSION    "2.1"
+#define DRV_RELDATE    "Sept 11, 2006"
 
 #define RX_OFFSET      2
 
@@ -254,9 +143,9 @@ module_param_array(options, int, NULL, 0);
 module_param_array(full_duplex, int, NULL, 0);
 MODULE_PARM_DESC(mtu, "DP8381x MTU (all boards)");
 MODULE_PARM_DESC(debug, "DP8381x default debug level");
-MODULE_PARM_DESC(rx_copybreak, 
+MODULE_PARM_DESC(rx_copybreak,
        "DP8381x copy breakpoint for copy-only-tiny-frames");
-MODULE_PARM_DESC(options, 
+MODULE_PARM_DESC(options,
        "DP8381x: Bits 0-3: media type, bit 17: full duplex");
 MODULE_PARM_DESC(full_duplex, "DP8381x full duplex setting(s) (1)");
 
@@ -355,17 +244,22 @@ enum {
        MII_EN_SCRM     = 0x0004,       /* enable scrambler (tp) */
 };
 
+enum {
+       NATSEMI_FLAG_IGNORE_PHY         = 0x1,
+};
+
 /* array of board data directly indexed by pci_tbl[x].driver_data */
 static const struct {
        const char *name;
        unsigned long flags;
        unsigned int eeprom_size;
 } natsemi_pci_info[] __devinitdata = {
+       { "Aculab E1/T1 PMXc cPCI carrier card", NATSEMI_FLAG_IGNORE_PHY, 128 },
        { "NatSemi DP8381[56]", 0, 24 },
 };
 
 static const struct pci_device_id natsemi_pci_tbl[] __devinitdata = {
+       { PCI_VENDOR_ID_NS, 0x0020, 0x12d9,     0x000c,     0, 0, 0 },
        { PCI_VENDOR_ID_NS, 0x0020, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
        { }     /* terminate list */
 };
@@ -525,7 +419,7 @@ enum TxConfig_bits {
        TxCarrierIgn            = 0x80000000
 };
 
-/* 
+/*
  * Tx Configuration:
  * - 256 byte DMA burst length
  * - fill threshold 512 bytes (i.e. restart DMA when 512 bytes are free)
@@ -679,6 +573,8 @@ struct netdev_private {
        u32 intr_status;
        /* Do not touch the nic registers */
        int hands_off;
+       /* Don't pay attention to the reported link state. */
+       int ignore_phy;
        /* external phy that is used: only valid if dev->if_port != PORT_TP */
        int mii;
        int phy_addr_external;
@@ -734,7 +630,7 @@ static void free_ring(struct net_device *dev);
 static void reinit_ring(struct net_device *dev);
 static void init_registers(struct net_device *dev);
 static int start_tx(struct sk_buff *skb, struct net_device *dev);
-static irqreturn_t intr_handler(int irq, void *dev_instance, struct pt_regs *regs);
+static irqreturn_t intr_handler(int irq, void *dev_instance);
 static void netdev_error(struct net_device *dev, int intr_status);
 static int natsemi_poll(struct net_device *dev, int *budget);
 static void netdev_rx(struct net_device *dev, int *work_done, int work_to_do);
@@ -758,7 +654,7 @@ static void enable_wol_mode(struct net_device *dev, int enable_intr);
 static int netdev_close(struct net_device *dev);
 static int netdev_get_regs(struct net_device *dev, u8 *buf);
 static int netdev_get_eeprom(struct net_device *dev, u8 *buf);
-static struct ethtool_ops ethtool_ops;
+static const struct ethtool_ops ethtool_ops;
 
 static inline void __iomem *ns_ioaddr(struct net_device *dev)
 {
@@ -783,7 +679,7 @@ static void move_int_phy(struct net_device *dev, int addr)
        void __iomem *ioaddr = ns_ioaddr(dev);
        int target = 31;
 
-       /* 
+       /*
         * The internal phy is visible on the external mii bus. Therefore we must
         * move it away before we can send commands to an external phy.
         * There are two addresses we must avoid:
@@ -807,7 +703,10 @@ static void __devinit natsemi_init_media (struct net_device *dev)
        struct netdev_private *np = netdev_priv(dev);
        u32 tmp;
 
-       netif_carrier_off(dev);
+       if (np->ignore_phy)
+               netif_carrier_on(dev);
+       else
+               netif_carrier_off(dev);
 
        /* get the initial settings from hardware */
        tmp            = mdio_read(dev, MII_BMCR);
@@ -917,8 +816,13 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
        np->hands_off = 0;
        np->intr_status = 0;
        np->eeprom_size = natsemi_pci_info[chip_idx].eeprom_size;
+       if (natsemi_pci_info[chip_idx].flags & NATSEMI_FLAG_IGNORE_PHY)
+               np->ignore_phy = 1;
+       else
+               np->ignore_phy = 0;
 
        /* Initial port:
+        * - If configured to ignore the PHY set up for external.
         * - If the nic was configured to use an external phy and if find_mii
         *   finds a phy: use external port, first phy that replies.
         * - Otherwise: internal port.
@@ -926,7 +830,7 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
         * The address would be used to access a phy over the mii bus, but
         * the internal phy is accessed through mapped registers.
         */
-       if (readl(ioaddr + ChipConfig) & CfgExtPhy)
+       if (np->ignore_phy || readl(ioaddr + ChipConfig) & CfgExtPhy)
                dev->if_port = PORT_MII;
        else
                dev->if_port = PORT_TP;
@@ -936,7 +840,9 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
 
        if (dev->if_port != PORT_TP) {
                np->phy_addr_external = find_mii(dev);
-               if (np->phy_addr_external == PHY_ADDR_NONE) {
+               /* If we're ignoring the PHY it doesn't matter if we can't
+                * find one. */
+               if (!np->ignore_phy && np->phy_addr_external == PHY_ADDR_NONE) {
                        dev->if_port = PORT_TP;
                        np->phy_addr_external = PHY_ADDR_INTERNAL;
                }
@@ -1002,6 +908,8 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
                printk("%02x, IRQ %d", dev->dev_addr[i], irq);
                if (dev->if_port == PORT_TP)
                        printk(", port TP.\n");
+               else if (np->ignore_phy)
+                       printk(", port MII, ignoring PHY\n");
                else
                        printk(", port MII, phy ad %d.\n", np->phy_addr_external);
        }
@@ -1206,7 +1114,7 @@ static void init_phy_fixup(struct net_device *dev)
                        tmp |= BMCR_SPEED100;
                if (np->duplex == DUPLEX_FULL)
                        tmp |= BMCR_FULLDPLX;
-               /* 
+               /*
                 * Note: there is no good way to inform the link partner
                 * that our capabilities changed. The user has to unplug
                 * and replug the network cable after some changes, e.g.
@@ -1347,7 +1255,7 @@ static int switch_port_internal(struct net_device *dev)
        writel(cfg, ioaddr + ChipConfig);
        readl(ioaddr + ChipConfig);
        udelay(1);
-       
+
        /* 2) reset the internal phy: */
        bmcr = readw(ioaddr+BasicControl+(MII_BMCR<<2));
        writel(bmcr | BMCR_RESET, ioaddr+BasicControl+(MII_BMCR<<2));
@@ -1387,7 +1295,7 @@ static int find_mii(struct net_device *dev)
 
        /* Switch to external phy */
        did_switch = switch_port_external(dev);
-               
+
        /* Scan the possible phy addresses:
         *
         * PHY address 0 means that the phy is in isolate mode. Not yet
@@ -1682,9 +1590,13 @@ static void check_link(struct net_device *dev)
 {
        struct netdev_private *np = netdev_priv(dev);
        void __iomem * ioaddr = ns_ioaddr(dev);
-       int duplex;
+       int duplex = np->duplex;
        u16 bmsr;
-       
+
+       /* If we are ignoring the PHY then don't try reading it. */
+       if (np->ignore_phy)
+               goto propagate_state;
+
        /* The link status field is latched: it remains low after a temporary
         * link failure until it's read. We need the current link status,
         * thus read twice.
@@ -1696,7 +1608,7 @@ static void check_link(struct net_device *dev)
                if (netif_carrier_ok(dev)) {
                        if (netif_msg_link(np))
                                printk(KERN_NOTICE "%s: link down.\n",
-                                       dev->name);
+                                      dev->name);
                        netif_carrier_off(dev);
                        undo_cable_magic(dev);
                }
@@ -1720,6 +1632,7 @@ static void check_link(struct net_device *dev)
                        duplex = 1;
        }
 
+propagate_state:
        /* if duplex is set then bit 28 must be set, too */
        if (duplex ^ !!(np->rx_config & RxAcceptTx)) {
                if (netif_msg_link(np))
@@ -2199,7 +2112,7 @@ static void netdev_tx_done(struct net_device *dev)
 
 /* The interrupt handler doesn't actually handle interrupts itself, it
  * schedules a NAPI poll if there is anything to do. */
-static irqreturn_t intr_handler(int irq, void *dev_instance, struct pt_regs *rgs)
+static irqreturn_t intr_handler(int irq, void *dev_instance)
 {
        struct net_device *dev = dev_instance;
        struct netdev_private *np = netdev_priv(dev);
@@ -2207,7 +2120,7 @@ static irqreturn_t intr_handler(int irq, void *dev_instance, struct pt_regs *rgs
 
        if (np->hands_off)
                return IRQ_NONE;
-       
+
        /* Reading automatically acknowledges. */
        np->intr_status = readl(ioaddr + IntrStatus);
 
@@ -2217,7 +2130,7 @@ static irqreturn_t intr_handler(int irq, void *dev_instance, struct pt_regs *rgs
                       dev->name, np->intr_status,
                       readl(ioaddr + IntrMask));
 
-       if (!np->intr_status) 
+       if (!np->intr_status)
                return IRQ_NONE;
 
        prefetch(&np->rx_skbuff[np->cur_rx % RX_RING_SIZE]);
@@ -2252,13 +2165,13 @@ static int natsemi_poll(struct net_device *dev, int *budget)
                /* Abnormal error summary/uncommon events handlers. */
                if (np->intr_status & IntrAbnormalSummary)
                        netdev_error(dev, np->intr_status);
-               
+
                if (np->intr_status &
                    (IntrRxDone | IntrRxIntr | RxStatusFIFOOver |
                     IntrRxErr | IntrRxOverrun)) {
                        netdev_rx(dev, &work_done, work_to_do);
                }
-               
+
                *budget -= work_done;
                dev->quota -= work_done;
 
@@ -2484,7 +2397,7 @@ static struct net_device_stats *get_stats(struct net_device *dev)
 static void natsemi_poll_controller(struct net_device *dev)
 {
        disable_irq(dev->irq);
-       intr_handler(dev->irq, dev, NULL);
+       intr_handler(dev->irq, dev);
        enable_irq(dev->irq);
 }
 #endif
@@ -2498,9 +2411,6 @@ static void __set_rx_mode(struct net_device *dev)
        u32 rx_mode;
 
        if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
-               /* Unconditionally log net taps. */
-               printk(KERN_NOTICE "%s: Promiscuous mode enabled.\n",
-                       dev->name);
                rx_mode = RxFilterEnable | AcceptBroadcast
                        | AcceptAllMulticast | AcceptAllPhys | AcceptMyPhys;
        } else if ((dev->mc_count > multicast_filter_limit)
@@ -2687,7 +2597,7 @@ static int get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8
        return res;
 }
 
-static struct ethtool_ops ethtool_ops = {
+static const struct ethtool_ops ethtool_ops = {
        .get_drvinfo = get_drvinfo,
        .get_regs_len = get_regs_len,
        .get_eeprom_len = get_eeprom_len,
@@ -2858,7 +2768,7 @@ static int netdev_get_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
         * phy, even if the internal phy is used. This is necessary
         * to work around a deficiency of the ethtool interface:
         * It's only possible to query the settings of the active
-        * port. Therefore 
+        * port. Therefore
         * # ethtool -s ethX port mii
         * actually sends an ioctl to switch to port mii with the
         * settings that are used for the current active port.
@@ -2932,6 +2842,15 @@ static int netdev_set_ecmd(struct net_device *dev, struct ethtool_cmd *ecmd)
                return -EINVAL;
        }
 
+       /*
+        * If we're ignoring the PHY then autoneg and the internal
+        * transciever are really not going to work so don't let the
+        * user select them.
+        */
+       if (np->ignore_phy && (ecmd->autoneg == AUTONEG_ENABLE ||
+                              ecmd->port == PORT_TP))
+               return -EINVAL;
+
        /*
         * maxtxpkt, maxrxpkt: ignored for now.
         *
@@ -3357,7 +3276,7 @@ static int __init natsemi_init_mod (void)
        printk(version);
 #endif
 
-       return pci_module_init (&natsemi_driver);
+       return pci_register_driver(&natsemi_driver);
 }
 
 static void __exit natsemi_exit_mod (void)