igb: introduce igb_thermal_sensor_event for sensor checking
authorStefan Assmann <sassmann@kpanic.de>
Tue, 5 Apr 2011 04:27:15 +0000 (04:27 +0000)
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>
Thu, 14 Apr 2011 02:16:44 +0000 (19:16 -0700)
The code for thermal sensor checking should be wrapped into a function.

Signed-off-by: Stefan Assmann <sassmann@kpanic.de>
Tested-by: Jeff Pieper <jeffrey.e.pieper@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
drivers/net/igb/igb_main.c

index 0dfd1b93829e5933b76d64ac3eb1a5c08b32cef5..cdfd5727105123bbd1d2357a19d578ce58df46a4 100644 (file)
@@ -3532,6 +3532,25 @@ bool igb_has_link(struct igb_adapter *adapter)
        return link_active;
 }
 
+static bool igb_thermal_sensor_event(struct e1000_hw *hw, u32 event)
+{
+       bool ret = false;
+       u32 ctrl_ext, thstat;
+
+       /* check for thermal sensor event on i350, copper only */
+       if (hw->mac.type == e1000_i350) {
+               thstat = rd32(E1000_THSTAT);
+               ctrl_ext = rd32(E1000_CTRL_EXT);
+
+               if ((hw->phy.media_type == e1000_media_type_copper) &&
+                   !(ctrl_ext & E1000_CTRL_EXT_LINK_MODE_SGMII)) {
+                       ret = !!(thstat & event);
+               }
+       }
+
+       return ret;
+}
+
 /**
  * igb_watchdog - Timer Call-back
  * @data: pointer to adapter cast into an unsigned long
@@ -3550,7 +3569,7 @@ static void igb_watchdog_task(struct work_struct *work)
                                                    watchdog_task);
        struct e1000_hw *hw = &adapter->hw;
        struct net_device *netdev = adapter->netdev;
-       u32 link, ctrl_ext, thstat;
+       u32 link;
        int i;
 
        link = igb_has_link(adapter);
@@ -3574,25 +3593,14 @@ static void igb_watchdog_task(struct work_struct *work)
                               ((ctrl & E1000_CTRL_RFCE) ?  "RX" :
                               ((ctrl & E1000_CTRL_TFCE) ?  "TX" : "None")));
 
-                       /* check for thermal sensor event on i350,
-                        * copper only */
-                       if (hw->mac.type == e1000_i350) {
-                               thstat = rd32(E1000_THSTAT);
-                               ctrl_ext = rd32(E1000_CTRL_EXT);
-                               if ((hw->phy.media_type ==
-                                    e1000_media_type_copper) && !(ctrl_ext &
-                                    E1000_CTRL_EXT_LINK_MODE_SGMII)) {
-                                       if (thstat &
-                                           E1000_THSTAT_LINK_THROTTLE) {
-                                               printk(KERN_INFO "igb: %s The "
-                                                      "network adapter link "
-                                                      "speed was downshifted "
-                                                      "because it "
-                                                      "overheated.\n",
-                                                      netdev->name);
-                                       }
-                               }
+                       /* check for thermal sensor event */
+                       if (igb_thermal_sensor_event(hw, E1000_THSTAT_LINK_THROTTLE)) {
+                               printk(KERN_INFO "igb: %s The network adapter "
+                                                "link speed was downshifted "
+                                                "because it overheated.\n",
+                                                netdev->name);
                        }
+
                        /* adjust timeout factor according to speed/duplex */
                        adapter->tx_timeout_factor = 1;
                        switch (adapter->link_speed) {
@@ -3618,22 +3626,15 @@ static void igb_watchdog_task(struct work_struct *work)
                if (netif_carrier_ok(netdev)) {
                        adapter->link_speed = 0;
                        adapter->link_duplex = 0;
-                       /* check for thermal sensor event on i350
-                        * copper only*/
-                       if (hw->mac.type == e1000_i350) {
-                               thstat = rd32(E1000_THSTAT);
-                               ctrl_ext = rd32(E1000_CTRL_EXT);
-                               if ((hw->phy.media_type ==
-                                    e1000_media_type_copper) && !(ctrl_ext &
-                                    E1000_CTRL_EXT_LINK_MODE_SGMII)) {
-                                       if (thstat & E1000_THSTAT_PWR_DOWN) {
-                                               printk(KERN_ERR "igb: %s The "
-                                               "network adapter was stopped "
-                                               "because it overheated.\n",
+
+                       /* check for thermal sensor event */
+                       if (igb_thermal_sensor_event(hw, E1000_THSTAT_PWR_DOWN)) {
+                               printk(KERN_ERR "igb: %s The network adapter "
+                                               "was stopped because it "
+                                               "overheated.\n",
                                                netdev->name);
-                                       }
-                               }
                        }
+
                        /* Links status message must follow this format */
                        printk(KERN_INFO "igb: %s NIC Link is Down\n",
                               netdev->name);