Skip to contentSkip to conversation

e1000e: PCIm function state support

PATCH Superseded Vitaly Lifshits 3 participants 6 messages Aug 4, 2019 – Aug 8, 2019

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 e1000e: PCIm function state support

Due to commit: 5d8682588605 ("[misc] mei: me: allow runtime pm for platform with D0i3")
when disconnecting the cable and reconnecting it the NIC enters DMoff state. This caused wrong link indication and duplex mismatch.

Checking PCIm function state and performing PHY reset after exiting DMoff state in watchdog task, solves this issue.

---

V2: Fix typos in commit message
V3: Fix minor typo
V4: Address community comments

---
 drivers/net/ethernet/intel/e1000e/defines.h |  4 ++++
 drivers/net/ethernet/intel/e1000e/netdev.c  | 20 +++++++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/e1000e/defines.h +4 -0
index fd550dee4982..4cff73cbd032 100644
@@ -222,6 +222,10 @@
 #define E1000_STATUS_PHYRA      0x00000400      /* PHY Reset Asserted */
 #define E1000_STATUS_GIO_MASTER_ENABLE	0x00080000	/* Master Req status */
 
+/* PCIm function state */
+#define E1000_STATUS_PCIM_STATE	0x40000000
+#define PCIM_DMOFF_EXIT_TIMEOUT 100
+
 #define HALF_DUPLEX 1
 #define FULL_DUPLEX 2
 
drivers/net/ethernet/intel/e1000e/netdev.c +19 -1
index b5fed6177ad6..2d29c0d0be1b 100644
@@ -5162,7 +5162,7 @@ static void e1000_watchdog_task(struct work_struct *work)
 	struct e1000_phy_info *phy = &adapter->hw.phy;
 	struct e1000_ring *tx_ring = adapter->tx_ring;
 	struct e1000_hw *hw = &adapter->hw;
-	u32 link, tctl;
+	u32 link, tctl, pcim_state, tries = 0;
 
 	if (test_bit(__E1000_DOWN, &adapter->state))
 		return;
@@ -5187,6 +5187,24 @@ static void e1000_watchdog_task(struct work_struct *work)
 			/* Cancel scheduled suspend requests. */
 			pm_runtime_resume(netdev->dev.parent);
 
+			/* Checking if MAC is in DMoff state*/
+			pcim_state = er32(STATUS);
+			while (pcim_state & E1000_STATUS_PCIM_STATE) {
+				if (tries++ == PCIM_DMOFF_EXIT_TIMEOUT) {
+					e_dbg("Error in exiting dmoff\n");
+					e_err("PCIm DMoff timeout expired\n");
+					break;
+				}
+				usleep_range(10000, 20000);
+				pcim_state = er32(STATUS);
+
+				/* If MAC entered DMoff state, PHY reset is
+				 * needed after exiting it
+				 */
+				if (!(pcim_state & E1000_STATUS_PCIM_STATE))
+					e1000_phy_hw_reset(&adapter->hw);
+			}
+
 			/* update snapshot of PHY registers on LSC */
 			e1000_phy_read_status(adapter);
 			mac->ops.get_link_up_info(&adapter->hw,
Signature · 1 line
2.11.0
#1 lore raw

PATCH v4 1/1 e1000e: PCIm function state support

Quoted 65 lines · Vitaly Lifshits

Due to commit: 5d8682588605 ("[misc] mei: me: allow runtime pm for platform with D0i3")
when disconnecting the cable and reconnecting it the NIC enters DMoff state. This caused wrong link indication and duplex mismatch.

Checking PCIm function state and performing PHY reset after exiting DMoff state in watchdog task, solves this issue.

---

V2: Fix typos in commit message
V3: Fix minor typo
V4: Address community comments

---
  drivers/net/ethernet/intel/e1000e/defines.h |  4 ++++
  drivers/net/ethernet/intel/e1000e/netdev.c  | 20 +++++++++++++++++++-
  2 files changed, 23 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/e1000e/defines.h +4 -0
index fd550dee4982..4cff73cbd032 100644
@@ -222,6 +222,10 @@
  #define E1000_STATUS_PHYRA      0x00000400      /* PHY Reset Asserted */
  #define E1000_STATUS_GIO_MASTER_ENABLE	0x00080000	/* Master Req status */
 
+/* PCIm function state */
+#define E1000_STATUS_PCIM_STATE	0x40000000
+#define PCIM_DMOFF_EXIT_TIMEOUT 100
+
  #define HALF_DUPLEX 1
  #define FULL_DUPLEX 2
 
drivers/net/ethernet/intel/e1000e/netdev.c +12 -1
index b5fed6177ad6..2d29c0d0be1b 100644
@@ -5162,7 +5162,7 @@ static void e1000_watchdog_task(struct work_struct *work)
  	struct e1000_phy_info *phy = &adapter->hw.phy;
  	struct e1000_ring *tx_ring = adapter->tx_ring;
  	struct e1000_hw *hw = &adapter->hw;
-	u32 link, tctl;
+	u32 link, tctl, pcim_state, tries = 0;
 
  	if (test_bit(__E1000_DOWN, &adapter->state))
  		return;
@@ -5187,6 +5187,24 @@ static void e1000_watchdog_task(struct work_struct *work)
  			/* Cancel scheduled suspend requests. */
  			pm_runtime_resume(netdev->dev.parent);
 
+			/* Checking if MAC is in DMoff state*/
+			pcim_state = er32(STATUS);
+			while (pcim_state & E1000_STATUS_PCIM_STATE) {
+				if (tries++ == PCIM_DMOFF_EXIT_TIMEOUT) {
+					e_dbg("Error in exiting dmoff\n");
+					e_err("PCIm DMoff timeout expired\n");
+					break;
+				}
+				usleep_range(10000, 20000);
+				pcim_state = er32(STATUS);
+

drivers/net/ethernet/intel/e1000e/netdev.c static void e1000_watchdog_task(struct work_struct *work) · line 5210

Quoted 10 lines
drivers/net/ethernet/intel/e1000e/netdev.c +7 -0
+				/* If MAC entered DMoff state, PHY reset is
+				 * needed after exiting it
+				 */
+				if (!(pcim_state & E1000_STATUS_PCIM_STATE))
+					e1000_phy_hw_reset(&adapter->hw);
+			}
+
  			/* update snapshot of PHY registers on LSC */
  			e1000_phy_read_status(adapter);
  			mac->ops.get_link_up_info(&adapter->hw,
#2 lore raw

PATCH v4 1/1 e1000e: PCIm function state support

In reply to Vitaly Lifshits

Dear Vitaly,

Thank you for the updated version.

Quoted 5 lines · Vitaly Lifshits

Due to commit: 5d8682588605 ("[misc] mei: me: allow runtime pm for platform with D0i3")
when disconnecting the cable and reconnecting it the NIC enters DMoff state. This caused wrong link indication and duplex mismatch.

*and* should fit on the line above.

Quoted 20 lines

Checking PCIm function state and performing PHY reset after exiting DMoff state in watchdog task, solves this issue.

---

V2: Fix typos in commit message
V3: Fix minor typo
V4: Address community comments

---
  drivers/net/ethernet/intel/e1000e/defines.h |  4 ++++
  drivers/net/ethernet/intel/e1000e/netdev.c  | 20 +++++++++++++++++++-
  2 files changed, 23 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/e1000e/defines.h +0 -0
index fd550dee4982..4cff73cbd032 100644

drivers/net/ethernet/intel/e1000e/defines.h line 227

Quoted 6 lines
drivers/net/ethernet/intel/e1000e/defines.h +3 -0
@@ -222,6 +222,10 @@
  #define E1000_STATUS_PHYRA      0x00000400      /* PHY Reset Asserted */
  #define E1000_STATUS_GIO_MASTER_ENABLE	0x00080000	/* Master Req status */
 
+/* PCIm function state */
+#define E1000_STATUS_PCIM_STATE	0x40000000
+#define PCIM_DMOFF_EXIT_TIMEOUT 100

Align the values?

Quoted 18 lines
drivers/net/ethernet/intel/e1000e/defines.h +1 -0
+
  #define HALF_DUPLEX 1
  #define FULL_DUPLEX 2
 
drivers/net/ethernet/intel/e1000e/netdev.c +1 -1
index b5fed6177ad6..2d29c0d0be1b 100644
@@ -5162,7 +5162,7 @@ static void e1000_watchdog_task(struct work_struct *work)
  	struct e1000_phy_info *phy = &adapter->hw.phy;
  	struct e1000_ring *tx_ring = adapter->tx_ring;
  	struct e1000_hw *hw = &adapter->hw;
-	u32 link, tctl;
+	u32 link, tctl, pcim_state, tries = 0;
 
  	if (test_bit(__E1000_DOWN, &adapter->state))
  		return;

drivers/net/ethernet/intel/e1000e/netdev.c static void e1000_watchdog_task(struct work_struct *work) · line 5190

Quoted 4 lines
drivers/net/ethernet/intel/e1000e/netdev.c +1 -0
@@ -5187,6 +5187,24 @@ static void e1000_watchdog_task(struct work_struct *work)
  			/* Cancel scheduled suspend requests. */
  			pm_runtime_resume(netdev->dev.parent);
 
+			/* Checking if MAC is in DMoff state*/

s/Checking/Check/

Quoted 5 lines
drivers/net/ethernet/intel/e1000e/netdev.c +5 -0
+			pcim_state = er32(STATUS);
+			while (pcim_state & E1000_STATUS_PCIM_STATE) {
+				if (tries++ == PCIM_DMOFF_EXIT_TIMEOUT) {
+					e_dbg("Error in exiting dmoff\n");
+					e_err("PCIm DMoff timeout expired\n");

drivers/net/ethernet/intel/e1000e/netdev.c static void e1000_watchdog_task(struct work_struct *work) · line 5205

Quoted 10 lines
drivers/net/ethernet/intel/e1000e/netdev.c +10 -0
+					break;
+				}
+				usleep_range(10000, 20000);
+				pcim_state = er32(STATUS);
+
+				/* If MAC entered DMoff state, PHY reset is
+				 * needed after exiting it
+				 */
+				if (!(pcim_state & E1000_STATUS_PCIM_STATE))
+					e1000_phy_hw_reset(&adapter->hw);

I still believe, the if statement should be moved *outside* the loop.

drivers/net/ethernet/intel/e1000e/netdev.c static void e1000_watchdog_task(struct work_struct *work) · line 5210

Quoted 5 lines
drivers/net/ethernet/intel/e1000e/netdev.c +2 -0
+			}
+
  			/* update snapshot of PHY registers on LSC */
  			e1000_phy_read_status(adapter);
  			mac->ops.get_link_up_info(&adapter->hw,

Kind regards,

Paul

#3 lore raw

PATCH v4 1/1 e1000e: PCIm function state support

Dear Paul,

Thank you again for your comments.
I sent a new version for my patch (V5).

Quoted 86 lines · Paul Menzel

Dear Vitaly,

Thank you for the updated version.

Quoted 5 lines · Vitaly Lifshits

Due to commit: 5d8682588605 ("[misc] mei: me: allow runtime pm for platform with D0i3")
when disconnecting the cable and reconnecting it the NIC enters DMoff state. This caused wrong link indication and duplex mismatch.

*and* should fit on the line above.

Quoted 26 lines

Checking PCIm function state and performing PHY reset after exiting DMoff state in watchdog task, solves this issue.

---

V2: Fix typos in commit message
V3: Fix minor typo
V4: Address community comments
---
? drivers/net/ethernet/intel/e1000e/defines.h |? 4 ++++
? drivers/net/ethernet/intel/e1000e/netdev.c? | 20 +++++++++++++++++++- ? 2 files changed, 23 insertions(+), 1 deletion(-)

drivers/net/ethernet/intel/e1000e/defines.h +0 -0
index fd550dee4982..4cff73cbd032 100644
@@ -222,6 +222,10 @@

? #define E1000_STATUS_PHYRA????? 0x00000400????? /* PHY Reset Asserted */
? #define E1000_STATUS_GIO_MASTER_ENABLE??? 0x00080000??? /* Master Req status */
? +/* PCIm function state */

drivers/net/ethernet/intel/e1000e/defines.h

Quoted 2 lines
drivers/net/ethernet/intel/e1000e/defines.h +2 -0
+#define E1000_STATUS_PCIM_STATE??? 0x40000000
+#define PCIM_DMOFF_EXIT_TIMEOUT 100

Align the values?

Quoted 19 lines

+
? #define HALF_DUPLEX 1
? #define FULL_DUPLEX 2
? diff --git a/drivers/net/ethernet/intel/e1000e/netdev.c b/drivers/net/ethernet/intel/e1000e/netdev.c index b5fed6177ad6..2d29c0d0be1b 100644

drivers/net/ethernet/intel/e1000e/netdev.c +1 -1
@@ -5162,7 +5162,7 @@ static void e1000_watchdog_task(struct 
 work_struct *work)
 ????? struct e1000_phy_info *phy = &adapter->hw.phy;
 ????? struct e1000_ring *tx_ring = adapter->tx_ring;
 ????? struct e1000_hw *hw = &adapter->hw;
-??? u32 link, tctl;
+??? u32 link, tctl, pcim_state, tries = 0;
 ? ????? if (test_bit(__E1000_DOWN, &adapter->state))
 ????????? return;
@@ -5187,6 +5187,24 @@ static void e1000_watchdog_task(struct 
 work_struct *work)
Quoted 3 lines

????????????? /* Cancel scheduled suspend requests. */ ????????????? pm_runtime_resume(netdev->dev.parent); ? +??????????? /* Checking if MAC is in DMoff state*/

s/Checking/Check/

Quoted 7 lines

+??????????? pcim_state = er32(STATUS); +??????????? while (pcim_state & E1000_STATUS_PCIM_STATE) { +??????????????? if (tries++ == PCIM_DMOFF_EXIT_TIMEOUT) { +??????????????????? e_dbg("Error in exiting dmoff\n"); +??????????????????? e_err("PCIm DMoff timeout expired\n"); +??????????????????? break;
+??????????????? }

Quoted 8 lines

+??????????????? usleep_range(10000, 20000); +??????????????? pcim_state = er32(STATUS);
+
+??????????????? /* If MAC entered DMoff state, PHY reset is +???????????????? * needed after exiting it +???????????????? */
+??????????????? if (!(pcim_state & E1000_STATUS_PCIM_STATE)) +??????????????????? e1000_phy_hw_reset(&adapter->hw);

Quoted 1 line

I still believe, the if statement should be moved *outside* the loop.

The if statement has to stay in the loop since the PHY reset is needed only if the MAC entered DMoff state.

Quoted 11 lines
Quoted 6 lines

+??????????? }
+
????????????? /* update snapshot of PHY registers on LSC */ ????????????? e1000_phy_read_status(adapter); ????????????? mac->ops.get_link_up_info(&adapter->hw,

Kind regards,

Paul

Thanks,

Vitaly

#4 lore raw

PATCH v4 1/1 e1000e: PCIm function state support

Dear Vitaly,

Quoted 2 lines · Vitaly

Thank you again for your comments.
I sent a new version for my patch (V5).

Thank you very much for incorporating them.

Quoted 3 lines · Paul Menzel
Quoted 2 lines · Vitaly Lifshits

[?]

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

+??????????? pcim_state = er32(STATUS); +??????????? while (pcim_state & E1000_STATUS_PCIM_STATE) { +??????????????? if (tries++ == PCIM_DMOFF_EXIT_TIMEOUT) {

By the way, can?t there be the unit appended to the macro name PCIM_DMOFF_EXIT_TIMEOUT?

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

+??????????????????? e_dbg("Error in exiting dmoff\n"); +??????????????????? e_err("PCIm DMoff timeout expired\n");

It?s not a hold-up, but why do you print two messages? I?d just print the error message.

    e_err("Failed to exit PCIm DMoff: Time-out (%i iterations) expired", PCIM_DMOFF_EXIT_TIMEOUT);

Or: e_err("Exiting PCIm DMoff timed out after %i iterations.", PCIM_DMOFF_EXIT_TIMEOUT);

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

+??????????????????? break;
+??????????????? }
+??????????????? usleep_range(10000, 20000); +??????????????? pcim_state = er32(STATUS);
+
+??????????????? /* If MAC entered DMoff state, PHY reset is +???????????????? * needed after exiting it +???????????????? */
+??????????????? if (!(pcim_state & E1000_STATUS_PCIM_STATE)) +??????????????????? e1000_phy_hw_reset(&adapter->hw);

Quoted 4 lines
Quoted 1 line

I still believe, the if statement should be moved *outside* the loop.

The if statement has to stay in the loop since the PHY reset is needed only if the MAC entered DMoff state.

Thank you. Now I finally saw it. It?s about, when the loop is never entered. I associated a while loop in my head normally with the assumption, that the condition is true in the beginning.

For the record, the code below is more intuitive for me.

```
if (pcim_state & E1000_STATUS_PCIM_STATE) {
/* MAC in DMoff state */
	do {
		if (tries++ == PCIM_DMOFF_EXIT_TIMEOUT) {
			e_dbg("Error in exiting dmoff\n");
			e_err("PCIm DMoff timeout expired\n");
			break;
		}
		usleep_range(10000, 20000);
		pcim_state = er32(STATUS);
	} while (pcim_state & E1000_STATUS_PCIM_STATE);

	e1000_phy_hw_reset(&adapter->hw);
}
```
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

+??????????? }
+
????????????? /* update snapshot of PHY registers on LSC */ ????????????? e1000_phy_read_status(adapter); ????????????? mac->ops.get_link_up_info(&adapter->hw,

Anyway, I do not want to hold up anything.

Kind regards,

Paul

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5174 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20190807/6dc6dc31/attachment-0001.p7s>

#5 lore raw

PATCH v4 1/1 e1000e: PCIm function state support

Dear Vitaly,

Quoted 47 lines · Paul Menzel
Quoted 3 lines · Vitaly
Quoted 1 line · Paul Menzel

On 04.08.19 09:40, Vitaly Lifshits wrote:

[?]

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

+??????????? pcim_state = er32(STATUS); +??????????? while (pcim_state & E1000_STATUS_PCIM_STATE) { +??????????????? if (tries++ == PCIM_DMOFF_EXIT_TIMEOUT) {

By the way, can?t there be the unit appended to the macro name PCIM_DMOFF_EXIT_TIMEOUT?

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

+??????????????????? e_dbg("Error in exiting dmoff\n"); +??????????????????? e_err("PCIm DMoff timeout expired\n");

It?s not a hold-up, but why do you print two messages? I?d just print the error message.

    e_err("Failed to exit PCIm DMoff: Time-out (%i iterations) expired", PCIM_DMOFF_EXIT_TIMEOUT);

Or: e_err("Exiting PCIm DMoff timed out after %i iterations.", PCIM_DMOFF_EXIT_TIMEOUT);

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

+??????????????????? break;
+??????????????? }
+??????????????? usleep_range(10000, 20000); +??????????????? pcim_state = er32(STATUS);
+
+??????????????? /* If MAC entered DMoff state, PHY reset is +???????????????? * needed after exiting it +???????????????? */
+??????????????? if (!(pcim_state & E1000_STATUS_PCIM_STATE)) +??????????????????? e1000_phy_hw_reset(&adapter->hw);

Quoted 4 lines
Quoted 1 line

I still believe, the if statement should be moved *outside* the loop.

The if statement has to stay in the loop since the PHY reset is needed only if the MAC entered DMoff state.

Thank you. Now I finally saw it. It?s about, when the loop is never entered. I associated a while loop in my head normally with the assumption, that the condition is true in the beginning.

For the record, the code below is more intuitive for me.

Quoted 16 lines
```
if (pcim_state & E1000_STATUS_PCIM_STATE) {
/* MAC in DMoff state */
	do {
		if (tries++ == PCIM_DMOFF_EXIT_TIMEOUT) {
			e_dbg("Error in exiting dmoff\n");
			e_err("PCIm DMoff timeout expired\n");
			break;
		}
		usleep_range(10000, 20000);
		pcim_state = er32(STATUS);
	} while (pcim_state & E1000_STATUS_PCIM_STATE);

	e1000_phy_hw_reset(&adapter->hw);
}
```

Sleeping a night over this, this is still not equivalent to your code, as this would reset after timing out, which your code does not. So, the if condition has to be added for that call.

```
[?]
unsigned int tries = 0; /* u32 not needed */
[?]

if (pcim_state & E1000_STATUS_PCIM_STATE) {
/* MAC in DMoff state */
	do {
		usleep_range(10000, 20000);
		pcim_state = er32(STATUS);
	} while ((pcim_state & E1000_STATUS_PCIM_STATE) && (++tries < PCIM_DMOFF_EXIT_TIMEOUT));

	if (tries == PCIM_DMOFF_EXIT_TIMEOUT)
		e_err("Exiting PCIm DMoff timed out after %i iterations.", PCIM_DMOFF_EXIT_TIMEOUT);
	else
		e1000_phy_hw_reset(&adapter->hw);
}
```
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

+??????????? }
+
????????????? /* update snapshot of PHY registers on LSC */ ????????????? e1000_phy_read_status(adapter); ????????????? mac->ops.get_link_up_info(&adapter->hw,

Anyway, I do not want to hold up anything.

Kind regards,

Paul

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5174 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20190808/4e617491/attachment.p7s>