Merge branch 'upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/linville...
[sfrench/cifs-2.6.git] / drivers / net / natsemi.c
index c6172a77a6d793de039fee2db63b374551f6d980..4cf0d3fcb519d741559d9e016178f455a75884c3 100644 (file)
@@ -81,6 +81,8 @@ static const int multicast_filter_limit = 100;
    Setting to > 1518 effectively disables this feature. */
 static int rx_copybreak;
 
+static int dspcfg_workaround = 1;
+
 /* Used to pass the media type, etc.
    Both 'options[]' and 'full_duplex[]' should exist for driver
    interoperability.
@@ -129,7 +131,6 @@ static const char version[] __devinitdata =
   KERN_INFO DRV_NAME " dp8381x driver, version "
       DRV_VERSION ", " DRV_RELDATE "\n"
   KERN_INFO "  originally by Donald Becker <becker@scyld.com>\n"
-  KERN_INFO "  http://www.scyld.com/network/natsemi.html\n"
   KERN_INFO "  2.4.x kernel port by Jeff Garzik, Tjeerd Mulder\n";
 
 MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
@@ -139,12 +140,14 @@ MODULE_LICENSE("GPL");
 module_param(mtu, int, 0);
 module_param(debug, int, 0);
 module_param(rx_copybreak, int, 0);
+module_param(dspcfg_workaround, int, 1);
 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,
        "DP8381x copy breakpoint for copy-only-tiny-frames");
+MODULE_PARM_DESC(dspcfg_workaround, "DP8381x: control DspCfg workaround");
 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)");
@@ -590,6 +593,7 @@ struct netdev_private {
        u32 srr;
        /* expected DSPCFG value */
        u16 dspcfg;
+       int dspcfg_workaround;
        /* parms saved in ethtool format */
        u16     speed;          /* The forced speed, 10Mb, 100Mb, gigabit */
        u8      duplex;         /* Duplex, half or full */
@@ -656,6 +660,56 @@ static int netdev_get_regs(struct net_device *dev, u8 *buf);
 static int netdev_get_eeprom(struct net_device *dev, u8 *buf);
 static const struct ethtool_ops ethtool_ops;
 
+#define NATSEMI_ATTR(_name) \
+static ssize_t natsemi_show_##_name(struct device *dev, \
+         struct device_attribute *attr, char *buf); \
+        static ssize_t natsemi_set_##_name(struct device *dev, \
+               struct device_attribute *attr, \
+               const char *buf, size_t count); \
+        static DEVICE_ATTR(_name, 0644, natsemi_show_##_name, natsemi_set_##_name)
+
+#define NATSEMI_CREATE_FILE(_dev, _name) \
+         device_create_file(&_dev->dev, &dev_attr_##_name)
+#define NATSEMI_REMOVE_FILE(_dev, _name) \
+         device_create_file(&_dev->dev, &dev_attr_##_name)
+
+NATSEMI_ATTR(dspcfg_workaround);
+
+static ssize_t natsemi_show_dspcfg_workaround(struct device *dev,
+                                             struct device_attribute *attr, 
+                                             char *buf)
+{
+       struct netdev_private *np = netdev_priv(to_net_dev(dev));
+
+       return sprintf(buf, "%s\n", np->dspcfg_workaround ? "on" : "off");
+}
+
+static ssize_t natsemi_set_dspcfg_workaround(struct device *dev,
+                                            struct device_attribute *attr,
+                                            const char *buf, size_t count)
+{
+       struct netdev_private *np = netdev_priv(to_net_dev(dev));
+       int new_setting;
+       u32 flags;
+
+        /* Find out the new setting */
+        if (!strncmp("on", buf, count - 1) || !strncmp("1", buf, count - 1))
+                new_setting = 1;
+        else if (!strncmp("off", buf, count - 1)
+                 || !strncmp("0", buf, count - 1))
+               new_setting = 0;
+       else
+                 return count; 
+
+       spin_lock_irqsave(&np->lock, flags);
+
+       np->dspcfg_workaround = new_setting;
+
+       spin_unlock_irqrestore(&np->lock, flags);
+
+       return count;
+}
+
 static inline void __iomem *ns_ioaddr(struct net_device *dev)
 {
        return (void __iomem *) dev->base_addr;
@@ -820,6 +874,7 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
                np->ignore_phy = 1;
        else
                np->ignore_phy = 0;
+       np->dspcfg_workaround = dspcfg_workaround;
 
        /* Initial port:
         * - If configured to ignore the PHY set up for external.
@@ -899,6 +954,9 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
        if (i)
                goto err_register_netdev;
 
+       if (NATSEMI_CREATE_FILE(pdev, dspcfg_workaround))
+               goto err_create_file;
+
        if (netif_msg_drv(np)) {
                printk(KERN_INFO "natsemi %s: %s at %#08lx (%s), ",
                        dev->name, natsemi_pci_info[chip_idx].name, iostart,
@@ -915,6 +973,9 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
        }
        return 0;
 
+ err_create_file:
+       unregister_netdev(dev);
+
  err_register_netdev:
        iounmap(ioaddr);
 
@@ -1712,7 +1773,7 @@ static void init_registers(struct net_device *dev)
 
        /* Enable interrupts by setting the interrupt mask. */
        writel(DEFAULT_INTR, ioaddr + IntrMask);
-       writel(1, ioaddr + IntrEnable);
+       natsemi_irq_enable(dev);
 
        writel(RxOn | TxOn, ioaddr + ChipCmd);
        writel(StatsClear, ioaddr + StatsCtrl); /* Clear Stats */
@@ -1727,7 +1788,8 @@ static void init_registers(struct net_device *dev)
  *    It seems that a reference set for this chip went out with incorrect info,
  *    and there exist boards that aren't quite right.  An unexpected voltage
  *    drop can cause the PHY to get itself in a weird state (basically reset).
- *    NOTE: this only seems to affect revC chips.
+ *    NOTE: this only seems to affect revC chips.  The user can disable
+ *    this check via dspcfg_workaround sysfs option.
  * 3) check of death of the RX path due to OOM
  */
 static void netdev_timer(unsigned long data)
@@ -1753,10 +1815,10 @@ static void netdev_timer(unsigned long data)
                writew(1, ioaddr+PGSEL);
                dspcfg = readw(ioaddr+DSPCFG);
                writew(0, ioaddr+PGSEL);
-               if (dspcfg != np->dspcfg) {
+               if (np->dspcfg_workaround && dspcfg != np->dspcfg) {
                        if (!netif_queue_stopped(dev)) {
                                spin_unlock_irq(&np->lock);
-                               if (netif_msg_hw(np))
+                               if (netif_msg_drv(np))
                                        printk(KERN_NOTICE "%s: possible phy reset: "
                                                "re-initializing\n", dev->name);
                                disable_irq(dev->irq);
@@ -2119,28 +2181,35 @@ static irqreturn_t intr_handler(int irq, void *dev_instance)
        struct netdev_private *np = netdev_priv(dev);
        void __iomem * ioaddr = ns_ioaddr(dev);
 
-       if (np->hands_off)
+       /* Reading IntrStatus automatically acknowledges so don't do
+        * that while interrupts are disabled, (for example, while a
+        * poll is scheduled).  */
+       if (np->hands_off || !readl(ioaddr + IntrEnable))
                return IRQ_NONE;
 
-       /* Reading automatically acknowledges. */
        np->intr_status = readl(ioaddr + IntrStatus);
 
+       if (!np->intr_status)
+               return IRQ_NONE;
+
        if (netif_msg_intr(np))
                printk(KERN_DEBUG
                       "%s: Interrupt, status %#08x, mask %#08x.\n",
                       dev->name, np->intr_status,
                       readl(ioaddr + IntrMask));
 
-       if (!np->intr_status)
-               return IRQ_NONE;
-
        prefetch(&np->rx_skbuff[np->cur_rx % RX_RING_SIZE]);
 
        if (netif_rx_schedule_prep(dev)) {
                /* Disable interrupts and register for poll */
                natsemi_irq_disable(dev);
                __netif_rx_schedule(dev);
-       }
+       } else
+               printk(KERN_WARNING
+                      "%s: Ignoring interrupt, status %#08x, mask %#08x.\n",
+                      dev->name, np->intr_status,
+                      readl(ioaddr + IntrMask));
+
        return IRQ_HANDLED;
 }
 
@@ -2156,6 +2225,20 @@ static int natsemi_poll(struct net_device *dev, int *budget)
        int work_done = 0;
 
        do {
+               if (netif_msg_intr(np))
+                       printk(KERN_DEBUG
+                              "%s: Poll, status %#08x, mask %#08x.\n",
+                              dev->name, np->intr_status,
+                              readl(ioaddr + IntrMask));
+
+               /* netdev_rx() may read IntrStatus again if the RX state
+                * machine falls over so do it first. */
+               if (np->intr_status &
+                   (IntrRxDone | IntrRxIntr | RxStatusFIFOOver |
+                    IntrRxErr | IntrRxOverrun)) {
+                       netdev_rx(dev, &work_done, work_to_do);
+               }
+
                if (np->intr_status &
                    (IntrTxDone | IntrTxIntr | IntrTxIdle | IntrTxErr)) {
                        spin_lock(&np->lock);
@@ -2167,12 +2250,6 @@ static int natsemi_poll(struct net_device *dev, int *budget)
                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;
 
@@ -2274,7 +2351,6 @@ static void netdev_rx(struct net_device *dev, int *work_done, int work_to_do)
                         * without copying to a minimally-sized skbuff. */
                        if (pkt_len < rx_copybreak
                            && (skb = dev_alloc_skb(pkt_len + RX_OFFSET)) != NULL) {
-                               skb->dev = dev;
                                /* 16 byte align the IP header */
                                skb_reserve(skb, RX_OFFSET);
                                pci_dma_sync_single_for_cpu(np->pci_dev,
@@ -2399,19 +2475,8 @@ static struct net_device_stats *get_stats(struct net_device *dev)
 #ifdef CONFIG_NET_POLL_CONTROLLER
 static void natsemi_poll_controller(struct net_device *dev)
 {
-       struct netdev_private *np = netdev_priv(dev);
-
        disable_irq(dev->irq);
-
-       /*
-        * A real interrupt might have already reached us at this point
-        * but NAPI might still haven't called us back.  As the interrupt
-        * status register is cleared by reading, we should prevent an
-        * interrupt loss in this case...
-        */
-       if (!np->intr_status)
-               intr_handler(dev->irq, dev);
-
+       intr_handler(dev->irq, dev);
        enable_irq(dev->irq);
 }
 #endif
@@ -3071,7 +3136,7 @@ static void enable_wol_mode(struct net_device *dev, int enable_intr)
                 * Could be used to send a netlink message.
                 */
                writel(WOLPkt | LinkChange, ioaddr + IntrMask);
-               writel(1, ioaddr + IntrEnable);
+               natsemi_irq_enable(dev);
        }
 }
 
@@ -3154,6 +3219,7 @@ static void __devexit natsemi_remove1 (struct pci_dev *pdev)
        struct net_device *dev = pci_get_drvdata(pdev);
        void __iomem * ioaddr = ns_ioaddr(dev);
 
+       NATSEMI_REMOVE_FILE(pdev, dspcfg_workaround);
        unregister_netdev (dev);
        pci_release_regions (pdev);
        iounmap(ioaddr);
@@ -3202,7 +3268,7 @@ static int natsemi_suspend (struct pci_dev *pdev, pm_message_t state)
                disable_irq(dev->irq);
                spin_lock_irq(&np->lock);
 
-               writel(0, ioaddr + IntrEnable);
+               natsemi_irq_disable(dev);
                np->hands_off = 1;
                natsemi_stop_rxtx(dev);
                netif_stop_queue(dev);