]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/r8169.c
r8169: fix early spinlock use
[linux-2.6-omap-h63xx.git] / drivers / net / r8169.c
index 1822491f19cbcf4b47ad3956c715f25176848c3a..59fbc64d7c479636b033b60f8dc6e4a44046423c 100644 (file)
@@ -36,7 +36,7 @@
 #define assert(expr) \
        if (!(expr)) {                                  \
                printk( "Assertion failed! %s,%s,%s,line=%d\n", \
-               #expr,__FILE__,__FUNCTION__,__LINE__);          \
+               #expr,__FILE__,__func__,__LINE__);              \
        }
 #define dprintk(fmt, args...) \
        do { printk(KERN_DEBUG PFX fmt, ## args); } while (0)
@@ -759,6 +759,7 @@ static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
                tp->features |= RTL_FEATURE_WOL;
        else
                tp->features &= ~RTL_FEATURE_WOL;
+       device_set_wakeup_enable(&tp->pci_dev->dev, wol->wolopts);
 
        spin_unlock_irq(&tp->lock);
 
@@ -1710,6 +1711,74 @@ static void rtl_disable_msi(struct pci_dev *pdev, struct rtl8169_private *tp)
        }
 }
 
+static int rtl_eeprom_read(struct pci_dev *pdev, int cap, int addr, __le32 *val)
+{
+       int ret, count = 100;
+       u16 status = 0;
+       u32 value;
+
+       ret = pci_write_config_word(pdev, cap + PCI_VPD_ADDR, addr);
+       if (ret < 0)
+               return ret;
+
+       do {
+               udelay(10);
+               ret = pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &status);
+               if (ret < 0)
+                       return ret;
+       } while (!(status & PCI_VPD_ADDR_F) && --count);
+
+       if (!(status & PCI_VPD_ADDR_F))
+               return -ETIMEDOUT;
+
+       ret = pci_read_config_dword(pdev, cap + PCI_VPD_DATA, &value);
+       if (ret < 0)
+               return ret;
+
+       *val = cpu_to_le32(value);
+
+       return 0;
+}
+
+static void rtl_init_mac_address(struct rtl8169_private *tp,
+                                void __iomem *ioaddr)
+{
+       struct pci_dev *pdev = tp->pci_dev;
+       u8 cfg1;
+       int vpd_cap;
+       u8 mac[8];
+       DECLARE_MAC_BUF(buf);
+
+       cfg1 = RTL_R8(Config1);
+       if (!(cfg1  & VPD)) {
+               dprintk("VPD access not enabled, enabling\n");
+               RTL_W8(Cfg9346, Cfg9346_Unlock);
+               RTL_W8(Config1, cfg1 | VPD);
+               RTL_W8(Cfg9346, Cfg9346_Lock);
+       }
+
+       vpd_cap = pci_find_capability(pdev, PCI_CAP_ID_VPD);
+       if (!vpd_cap)
+               return;
+
+       /* MAC address is stored in EEPROM at offset 0x0e
+        * Realtek says: "The VPD address does not have to be a DWORD-aligned
+        * address as defined in the PCI 2.2 Specifications, but the VPD data
+        * is always consecutive 4-byte data starting from the VPD address
+        * specified."
+        */
+       if (rtl_eeprom_read(pdev, vpd_cap, 0x000e, (__le32*)&mac[0]) < 0 ||
+           rtl_eeprom_read(pdev, vpd_cap, 0x0012, (__le32*)&mac[4]) < 0) {
+               dprintk("Reading MAC address from EEPROM failed\n");
+               return;
+       }
+
+       dprintk("MAC address found in EEPROM: %s\n", print_mac(buf, mac));
+
+       /* Write MAC address */
+       rtl_rar_set(tp, mac);
+}
+
 static int __devinit
 rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
@@ -1857,6 +1926,10 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        RTL_W8(Cfg9346, Cfg9346_Unlock);
        RTL_W8(Config1, RTL_R8(Config1) | PMEnable);
        RTL_W8(Config5, RTL_R8(Config5) & PMEStatus);
+       if ((RTL_R8(Config3) & (LinkUp | MagicPacket)) != 0)
+               tp->features |= RTL_FEATURE_WOL;
+       if ((RTL_R8(Config5) & (UWF | BWF | MWF)) != 0)
+               tp->features |= RTL_FEATURE_WOL;
        tp->features |= rtl_try_msi(pdev, ioaddr, cfg);
        RTL_W8(Cfg9346, Cfg9346_Lock);
 
@@ -1879,7 +1952,11 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                dev->do_ioctl = rtl8169_ioctl;
        }
 
-       /* Get MAC address.  FIXME: read EEPROM */
+       spin_lock_init(&tp->lock);
+
+       rtl_init_mac_address(tp, ioaddr);
+
+       /* Get MAC address */
        for (i = 0; i < MAC_ADDR_LEN; i++)
                dev->dev_addr[i] = RTL_R8(MAC0 + i);
        memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
@@ -1919,8 +1996,6 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        tp->timer.data = (unsigned long) dev;
        tp->timer.function = rtl8169_phy_timer;
 
-       spin_lock_init(&tp->lock);
-
        rc = register_netdev(dev);
        if (rc < 0)
                goto err_out_msi_5;
@@ -1942,6 +2017,7 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        }
 
        rtl8169_init_phy(dev, tp);
+       device_set_wakeup_enable(&pdev->dev, tp->features & RTL_FEATURE_WOL);
 
 out:
        return rc;
@@ -2286,8 +2362,6 @@ static void rtl_hw_start_8168(struct net_device *dev)
 
        RTL_R8(IntrMask);
 
-       RTL_W32(RxMissed, 0);
-
        rtl_set_rx_mode(dev);
 
        RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
@@ -2412,8 +2486,6 @@ static void rtl_hw_start_8101(struct net_device *dev)
 
        RTL_R8(IntrMask);
 
-       RTL_W32(RxMissed, 0);
-
        rtl_set_rx_mode(dev);
 
        RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
@@ -3191,6 +3263,17 @@ static int rtl8169_poll(struct napi_struct *napi, int budget)
        return work_done;
 }
 
+static void rtl8169_rx_missed(struct net_device *dev, void __iomem *ioaddr)
+{
+       struct rtl8169_private *tp = netdev_priv(dev);
+
+       if (tp->mac_version > RTL_GIGA_MAC_VER_06)
+               return;
+
+       dev->stats.rx_missed_errors += (RTL_R32(RxMissed) & 0xffffff);
+       RTL_W32(RxMissed, 0);
+}
+
 static void rtl8169_down(struct net_device *dev)
 {
        struct rtl8169_private *tp = netdev_priv(dev);
@@ -3208,9 +3291,7 @@ core_down:
 
        rtl8169_asic_down(ioaddr);
 
-       /* Update the error counts. */
-       dev->stats.rx_missed_errors += RTL_R32(RxMissed);
-       RTL_W32(RxMissed, 0);
+       rtl8169_rx_missed(dev, ioaddr);
 
        spin_unlock_irq(&tp->lock);
 
@@ -3332,8 +3413,7 @@ static struct net_device_stats *rtl8169_get_stats(struct net_device *dev)
 
        if (netif_running(dev)) {
                spin_lock_irqsave(&tp->lock, flags);
-               dev->stats.rx_missed_errors += RTL_R32(RxMissed);
-               RTL_W32(RxMissed, 0);
+               rtl8169_rx_missed(dev, ioaddr);
                spin_unlock_irqrestore(&tp->lock, flags);
        }
 
@@ -3358,8 +3438,7 @@ static int rtl8169_suspend(struct pci_dev *pdev, pm_message_t state)
 
        rtl8169_asic_down(ioaddr);
 
-       dev->stats.rx_missed_errors += RTL_R32(RxMissed);
-       RTL_W32(RxMissed, 0);
+       rtl8169_rx_missed(dev, ioaddr);
 
        spin_unlock_irq(&tp->lock);