netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, gospo@redhat.com,
	Alexander Duyck <alexander.h.duyck@intel.com>,
	Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Subject: [net-next-2.6 PATCH 14/15] igb: add additional error handling to the phy code
Date: Mon, 05 Oct 2009 09:35:42 -0700	[thread overview]
Message-ID: <20091005163541.32487.2008.stgit@localhost.localdomain> (raw)
In-Reply-To: <20091005163058.32487.10125.stgit@localhost.localdomain>

From: Alexander Duyck <alexander.h.duyck@intel.com>

This update adds additional exception handling to the phy code to handle
situations where it may be called incorrectly.  In addition it adds some
bounds checking to the cable length checks to prevent an array overrun in
the event that the hardware returned a different value than expected.

Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
---

 drivers/net/igb/e1000_phy.c |   39 +++++++++++++++++++++++++--------------
 1 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/drivers/net/igb/e1000_phy.c b/drivers/net/igb/e1000_phy.c
index 5fe03e1..83b706c 100644
--- a/drivers/net/igb/e1000_phy.c
+++ b/drivers/net/igb/e1000_phy.c
@@ -39,6 +39,9 @@ static s32  igb_wait_autoneg(struct e1000_hw *hw);
 /* Cable length tables */
 static const u16 e1000_m88_cable_length_table[] =
 	{ 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
+#define M88E1000_CABLE_LENGTH_TABLE_SIZE \
+                (sizeof(e1000_m88_cable_length_table) / \
+                 sizeof(e1000_m88_cable_length_table[0]))
 
 static const u16 e1000_igp_2_cable_length_table[] =
     { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
@@ -109,7 +112,10 @@ out:
  **/
 static s32 igb_phy_reset_dsp(struct e1000_hw *hw)
 {
-	s32 ret_val;
+	s32 ret_val = 0;
+
+	if (!(hw->phy.ops.write_reg))
+		goto out;
 
 	ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
 	if (ret_val)
@@ -1059,22 +1065,19 @@ s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw)
 
 	igb_phy_force_speed_duplex_setup(hw, &phy_data);
 
-	/* Reset the phy to commit changes. */
-	phy_data |= MII_CR_RESET;
-
 	ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
 	if (ret_val)
 		goto out;
 
-	udelay(1);
+	/* Reset the phy to commit changes. */
+	ret_val = igb_phy_sw_reset(hw);
+	if (ret_val)
+		goto out;
 
 	if (phy->autoneg_wait_to_complete) {
 		hw_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
 
-		ret_val = igb_phy_has_link(hw,
-						     PHY_FORCE_LIMIT,
-						     100000,
-						     &link);
+		ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link);
 		if (ret_val)
 			goto out;
 
@@ -1084,8 +1087,8 @@ s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw)
 			 * Reset the DSP and cross our fingers.
 			 */
 			ret_val = phy->ops.write_reg(hw,
-						      M88E1000_PHY_PAGE_SELECT,
-						      0x001d);
+						     M88E1000_PHY_PAGE_SELECT,
+						     0x001d);
 			if (ret_val)
 				goto out;
 			ret_val = igb_phy_reset_dsp(hw);
@@ -1095,7 +1098,7 @@ s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw)
 
 		/* Try once more */
 		ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT,
-					     100000, &link);
+					   100000, &link);
 		if (ret_val)
 			goto out;
 	}
@@ -1207,9 +1210,12 @@ static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw,
 s32 igb_set_d3_lplu_state(struct e1000_hw *hw, bool active)
 {
 	struct e1000_phy_info *phy = &hw->phy;
-	s32 ret_val;
+	s32 ret_val = 0;
 	u16 data;
 
+	if (!(hw->phy.ops.read_reg))
+		goto out;
+
 	ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
 	if (ret_val)
 		goto out;
@@ -1495,8 +1501,13 @@ s32 igb_get_cable_length_m88(struct e1000_hw *hw)
 
 	index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
 		M88E1000_PSSR_CABLE_LENGTH_SHIFT;
+	if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1) {
+		ret_val = -E1000_ERR_PHY;
+		goto out;
+	}
+
 	phy->min_cable_length = e1000_m88_cable_length_table[index];
-	phy->max_cable_length = e1000_m88_cable_length_table[index+1];
+	phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
 
 	phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
 


  parent reply	other threads:[~2009-10-05 16:37 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-05 16:31 [net-next-2.6 PATCH 01/15] igb: remove unused temp variable from stats clearing path Jeff Kirsher
2009-10-05 16:31 ` [net-next-2.6 PATCH 02/15] igb: update comments for serdes config and update to handle duplex Jeff Kirsher
2009-10-06 22:20   ` David Miller
2009-10-05 16:32 ` [net-next-2.6 PATCH 03/15] igb: update the approach taken to acquiring and releasing the phy lock Jeff Kirsher
2009-10-06 22:20   ` David Miller
2009-10-05 16:32 ` [net-next-2.6 PATCH 04/15] igb: add locking to reads of the i2c interface Jeff Kirsher
2009-10-06 22:20   ` David Miller
2009-10-05 16:32 ` [net-next-2.6 PATCH 05/15] igb: add combined function for setting rar and pool bits Jeff Kirsher
2009-10-06 22:21   ` David Miller
2009-10-05 16:33 ` [net-next-2.6 PATCH 06/15] igb: make use of the uta to allow for promiscous mode filter Jeff Kirsher
2009-10-06 22:21   ` David Miller
2009-10-05 16:33 ` [net-next-2.6 PATCH 07/15] igb: add support for 82576NS SerDes adapter Jeff Kirsher
2009-10-06 22:21   ` David Miller
2009-10-05 16:33 ` [net-next-2.6 PATCH 08/15] igb: add function to handle mailbox lock Jeff Kirsher
2009-10-06 22:21   ` David Miller
2009-10-05 16:34 ` [net-next-2.6 PATCH 09/15] igb: fix a few items where weren't correctly setup for mbx timeout Jeff Kirsher
2009-10-06 22:21   ` David Miller
2009-10-05 16:34 ` [net-next-2.6 PATCH 10/15] igb: change how we handle alternate mac addresses Jeff Kirsher
2009-10-06 22:21   ` David Miller
2009-10-05 16:34 ` [net-next-2.6 PATCH 11/15] igb: remove microwire support from igb Jeff Kirsher
2009-10-06 22:21   ` David Miller
2009-10-05 16:35 ` [net-next-2.6 PATCH 12/15] igb: move the generic copper link setup code into e1000_phy.c Jeff Kirsher
2009-10-06 22:21   ` David Miller
2009-10-05 16:35 ` [net-next-2.6 PATCH 13/15] igb: add code to retry a phy read in the event of failure on link check Jeff Kirsher
2009-10-06 22:21   ` David Miller
2009-10-05 16:35 ` Jeff Kirsher [this message]
2009-10-06 22:22   ` [net-next-2.6 PATCH 14/15] igb: add additional error handling to the phy code David Miller
2009-10-05 16:36 ` [net-next-2.6 PATCH 15/15] igb: add flushes between RAR writes when setting mac address Jeff Kirsher
2009-10-06 22:22   ` David Miller
2009-10-06 22:20 ` [net-next-2.6 PATCH 01/15] igb: remove unused temp variable from stats clearing path David Miller
2009-10-06 22:20 ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091005163541.32487.2008.stgit@localhost.localdomain \
    --to=jeffrey.t.kirsher@intel.com \
    --cc=alexander.h.duyck@intel.com \
    --cc=davem@davemloft.net \
    --cc=gospo@redhat.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).