e1000: fix concurrent accesses to PHY from watchdog and ethtool
authorMaxime Bizon <mbizon@freebox.fr>
Sat, 20 Oct 2012 14:53:40 +0000 (14:53 +0000)
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>
Thu, 1 Nov 2012 10:11:13 +0000 (03:11 -0700)
The e1000 driver currently does not protect concurrent accesses to the PHY
from both the ethtool callbacks, and from the e1000_watchdog function. This
patchs adds a new spinlock which is used by e1000_{read,write}_phy_reg in
order to serialize concurrent accesses to the PHY.

Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
Signed-off-by: Florian Fainelli <ffainelli@freebox.fr>
Tested-by: Aaron Brown <aaron.f.brown@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
drivers/net/ethernet/intel/e1000/e1000_hw.c

index 3d6839528761c77462f0fee647d8fab1984913ef..8fedd2451538c255d0238a7f367bbb2d402aa2c8 100644 (file)
@@ -107,6 +107,7 @@ u16 e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] = {
 };
 
 static DEFINE_SPINLOCK(e1000_eeprom_lock);
+static DEFINE_SPINLOCK(e1000_phy_lock);
 
 /**
  * e1000_set_phy_type - Set the phy type member in the hw struct.
@@ -2830,19 +2831,25 @@ static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
 s32 e1000_read_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 *phy_data)
 {
        u32 ret_val;
+       unsigned long flags;
 
        e_dbg("e1000_read_phy_reg");
 
+       spin_lock_irqsave(&e1000_phy_lock, flags);
+
        if ((hw->phy_type == e1000_phy_igp) &&
            (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
                ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
                                                 (u16) reg_addr);
-               if (ret_val)
+               if (ret_val) {
+                       spin_unlock_irqrestore(&e1000_phy_lock, flags);
                        return ret_val;
+               }
        }
 
        ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
                                        phy_data);
+       spin_unlock_irqrestore(&e1000_phy_lock, flags);
 
        return ret_val;
 }
@@ -2965,19 +2972,25 @@ static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
 s32 e1000_write_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 phy_data)
 {
        u32 ret_val;
+       unsigned long flags;
 
        e_dbg("e1000_write_phy_reg");
 
+       spin_lock_irqsave(&e1000_phy_lock, flags);
+
        if ((hw->phy_type == e1000_phy_igp) &&
            (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
                ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
                                                 (u16) reg_addr);
-               if (ret_val)
+               if (ret_val) {
+                       spin_unlock_irqrestore(&e1000_phy_lock, flags);
                        return ret_val;
+               }
        }
 
        ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
                                         phy_data);
+       spin_unlock_irqrestore(&e1000_phy_lock, flags);
 
        return ret_val;
 }