Skip to contentSkip to conversation

igb: introduce ptp_flags variable and use it to replace IGB_FLAG_PTP

PATCH New Jacob Keller 2 participants 13 messages May 24, 2016 – May 27, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/5 igb: introduce ptp_flags variable and use it to replace IGB_FLAG_PTP

Upcoming patches will introduce new PTP specific flags. To avoid cluttering the normal flags variable, introduce PTP specific "ptp_flags" variable for this purpose, and move IGB_FLAG_PTP to become IGB_PTP_ENABLED.

---
 drivers/net/ethernet/intel/igb/igb.h     | 5 ++++-
 drivers/net/ethernet/intel/igb/igb_ptp.c | 7 ++++---
 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/net/ethernet/intel/igb/igb.h +4 -1
index b9609afa5ca3..1e18a9eb16e0 100644
@@ -445,6 +445,7 @@ struct igb_adapter {
 	unsigned long ptp_tx_start;
 	unsigned long last_rx_ptp_check;
 	unsigned long last_rx_timestamp;
+	unsigned int ptp_flags;
 	spinlock_t tmreg_lock;
 	struct cyclecounter cc;
 	struct timecounter tc;
@@ -474,12 +475,14 @@ struct igb_adapter {
 	u16 eee_advert;
 };
 
+/* flags controlling PTP/1588 function */
+#define IGB_PTP_ENABLED		BIT(0)
+
 #define IGB_FLAG_HAS_MSI		BIT(0)
 #define IGB_FLAG_DCA_ENABLED		BIT(1)
 #define IGB_FLAG_QUAD_PORT_A		BIT(2)
 #define IGB_FLAG_QUEUE_PAIRS		BIT(3)
 #define IGB_FLAG_DMAC			BIT(4)
-#define IGB_FLAG_PTP			BIT(5)
 #define IGB_FLAG_RSS_FIELD_IPV4_UDP	BIT(6)
 #define IGB_FLAG_RSS_FIELD_IPV6_UDP	BIT(7)
 #define IGB_FLAG_WOL_SUPPORTED		BIT(8)
drivers/net/ethernet/intel/igb/igb_ptp.c +4 -3
index f097c5a8ab93..504102ba4bfb 100644
@@ -684,6 +684,7 @@ void igb_ptp_rx_hang(struct igb_adapter *adapter)
 	u32 tsyncrxctl = rd32(E1000_TSYNCRXCTL);
 	unsigned long rx_event;
 
+	/* Other hardware uses per-packet timestamps */
 	if (hw->mac.type != e1000_82576)
 		return;
 
@@ -1156,7 +1157,7 @@ void igb_ptp_init(struct igb_adapter *adapter)
 	} else {
 		dev_info(&adapter->pdev->dev, "added PHC on %s\n",
 			 adapter->netdev->name);
-		adapter->flags |= IGB_FLAG_PTP;
+		adapter->ptp_flags |= IGB_PTP_ENABLED;
 	}
 }
 
@@ -1194,7 +1195,7 @@ void igb_ptp_stop(struct igb_adapter *adapter)
 		ptp_clock_unregister(adapter->ptp_clock);
 		dev_info(&adapter->pdev->dev, "removed PHC on %s\n",
 			 adapter->netdev->name);
-		adapter->flags &= ~IGB_FLAG_PTP;
+		adapter->ptp_flags &= ~IGB_PTP_ENABLED;
 	}
 }
 
@@ -1209,7 +1210,7 @@ void igb_ptp_reset(struct igb_adapter *adapter)
 	struct e1000_hw *hw = &adapter->hw;
 	unsigned long flags;
 
-	if (!(adapter->flags & IGB_FLAG_PTP))
+	if (!(adapter->ptp_flags & IGB_PTP_ENABLED))
 		return;
 
 	/* reset the tstamp_config */
Signature · 1 line
2.8.2.820.gd1c5f70
#1 lore raw

PATCH v4 2/5 igb: introduce IGB_PTP_OVERFLOW_CHECK flag

Don't continue to use complex MAC type checks for handling various cases where we have overflow check code. Make this code more obvious by introducing a flag which is enabled for hardware that needs these checks.

---
 drivers/net/ethernet/intel/igb/igb.h     |  1 +
 drivers/net/ethernet/intel/igb/igb_ptp.c | 21 ++++++++-------------
 2 files changed, 9 insertions(+), 13 deletions(-)
drivers/net/ethernet/intel/igb/igb.h +1 -0
index 1e18a9eb16e0..38daaaba0cdb 100644
@@ -477,6 +477,7 @@ struct igb_adapter {
 
 /* flags controlling PTP/1588 function */
 #define IGB_PTP_ENABLED		BIT(0)
+#define IGB_PTP_OVERFLOW_CHECK	BIT(1)
 
 #define IGB_FLAG_HAS_MSI		BIT(0)
 #define IGB_FLAG_DCA_ENABLED		BIT(1)
drivers/net/ethernet/intel/igb/igb_ptp.c +8 -13
index 504102ba4bfb..88d367d5a78d 100644
@@ -1067,6 +1067,7 @@ void igb_ptp_init(struct igb_adapter *adapter)
 		adapter->cc.shift = IGB_82576_TSYNC_SHIFT;
 		/* Dial the nominal frequency. */
 		wr32(E1000_TIMINCA, INCPERIOD_82576 | INCVALUE_82576);
+		adapter->ptp_flags |= IGB_PTP_OVERFLOW_CHECK;
 		break;
 	case e1000_82580:
 	case e1000_i354:
@@ -1087,6 +1088,7 @@ void igb_ptp_init(struct igb_adapter *adapter)
 		adapter->cc.shift = 0;
 		/* Enable the timer functions by clearing bit 31. */
 		wr32(E1000_TSAUXC, 0x0);
+		adapter->ptp_flags |= IGB_PTP_OVERFLOW_CHECK;
 		break;
 	case e1000_i210:
 	case e1000_i211:
@@ -1132,7 +1134,9 @@ void igb_ptp_init(struct igb_adapter *adapter)
 	} else {
 		timecounter_init(&adapter->tc, &adapter->cc,
 				 ktime_to_ns(ktime_get_real()));
+	}
 
+	if (adapter->ptp_flags & IGB_PTP_OVERFLOW_CHECK) {
 		INIT_DELAYED_WORK(&adapter->ptp_overflow_work,
 				  igb_ptp_overflow_check);
 
@@ -1169,20 +1173,11 @@ void igb_ptp_init(struct igb_adapter *adapter)
  **/
 void igb_ptp_stop(struct igb_adapter *adapter)
 {
-	switch (adapter->hw.mac.type) {
-	case e1000_82576:
-	case e1000_82580:
-	case e1000_i354:
-	case e1000_i350:
-		cancel_delayed_work_sync(&adapter->ptp_overflow_work);
-		break;
-	case e1000_i210:
-	case e1000_i211:
-		/* No delayed work to cancel. */
-		break;
-	default:
+	if (!(adapter->ptp_flags & IGB_PTP_ENABLED))
 		return;
-	}
+
+	if (adapter->ptp_flags & IGB_PTP_OVERFLOW_CHECK)
+		cancel_delayed_work_sync(&adapter->ptp_overflow_work);
 
 	cancel_work_sync(&adapter->ptp_tx_work);
 	if (adapter->ptp_tx_skb) {
Signature · 1 line
2.8.2.820.gd1c5f70
#3 lore raw

PATCH v4 3/5 igb: re-use igb_ptp_reset in igb_ptp_init

In reply to Jacob Keller

Modify igb_ptp_init to take advantage of igb_ptp_reset, and remove duplicated work that was occurring in both igb_ptp_reset and igb_ptp_init.

In total, resetting the TSAUXC register, and resetting the system time both happen in igb_ptp_reset already. igb_ptp_reset now also takes care of starting the delayed work item for overflow checks, as well.

---
 drivers/net/ethernet/intel/igb/igb_main.c |  3 +-
 drivers/net/ethernet/intel/igb/igb_ptp.c  | 48 +++++++++++--------------------
 2 files changed, 18 insertions(+), 33 deletions(-)
drivers/net/ethernet/intel/igb/igb_main.c +2 -1
index 21727692bef6..0321f0884fa0 100644
@@ -2027,7 +2027,8 @@ void igb_reset(struct igb_adapter *adapter)
 	wr32(E1000_VET, ETHERNET_IEEE_VLAN_TYPE);
 
 	/* Re-enable PTP, where applicable. */
-	igb_ptp_reset(adapter);
+	if (adapter->ptp_flags & IGB_PTP_ENABLED)
+		igb_ptp_reset(adapter);
 
 	igb_get_phy_info(hw);
 }
drivers/net/ethernet/intel/igb/igb_ptp.c +16 -32

97 lines not on this page · raw message

Signature · 1 line
2.8.2.820.gd1c5f70
#5 lore raw

PATCH v4 4/5 igb: implement igb_ptp_suspend

In reply to Jacob Keller

Make igb_ptp_stop take advantage of this new function to reduce code duplication.

---
 drivers/net/ethernet/intel/igb/igb.h     |  1 +
 drivers/net/ethernet/intel/igb/igb_ptp.c | 22 +++++++++++++++++-----
 2 files changed, 18 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/igb/igb.h +1 -0
index 38daaaba0cdb..5387b3a96489 100644
@@ -550,6 +550,7 @@ void igb_set_fw_version(struct igb_adapter *);
 void igb_ptp_init(struct igb_adapter *adapter);
 void igb_ptp_stop(struct igb_adapter *adapter);
 void igb_ptp_reset(struct igb_adapter *adapter);
+void igb_ptp_suspend(struct igb_adapter *adapter);
 void igb_ptp_rx_hang(struct igb_adapter *adapter);
 void igb_ptp_rx_rgtstamp(struct igb_q_vector *q_vector, struct sk_buff *skb);
 void igb_ptp_rx_pktstamp(struct igb_q_vector *q_vector, unsigned char *va,
drivers/net/ethernet/intel/igb/igb_ptp.c +17 -5
index 907c225d9b20..e61b647f5f2a 100644
@@ -1147,12 +1147,13 @@ void igb_ptp_init(struct igb_adapter *adapter)
 }
 
 /**
- * igb_ptp_stop - Disable PTP device and stop the overflow check.
- * @adapter: Board private structure.
+ * igb_ptp_suspend - Disable PTP work items and prepare for suspend
+ * @adapter: Board private structure
  *
- * This function stops the PTP support and cancels the delayed work.
- **/
-void igb_ptp_stop(struct igb_adapter *adapter)
+ * This function stops the overflow check work and PTP Tx timestamp work, and
+ * will prepare the device for OS suspend.
+ */
+void igb_ptp_suspend(struct igb_adapter *adapter)
 {
 	if (!(adapter->ptp_flags & IGB_PTP_ENABLED))
 		return;
@@ -1166,6 +1167,17 @@ void igb_ptp_stop(struct igb_adapter *adapter)
 		adapter->ptp_tx_skb = NULL;
 		clear_bit_unlock(__IGB_PTP_TX_IN_PROGRESS, &adapter->state);
 	}
+}
+
+/**
+ * igb_ptp_stop - Disable PTP device and stop the overflow check.
+ * @adapter: Board private structure.
+ *
+ * This function stops the PTP support and cancels the delayed work.
+ **/
+void igb_ptp_stop(struct igb_adapter *adapter)
+{
+	igb_ptp_suspend(adapter);
 
 	if (adapter->ptp_clock) {
 		ptp_clock_unregister(adapter->ptp_clock);
Signature · 1 line
2.8.2.820.gd1c5f70
#7 lore raw

PATCH v4 5/5 igb: call igb_ptp_suspend during suspend/resume cycle

In reply to Jacob Keller

Properly stop the extra workqueue items and ensure that we resume cleanly. This is better than using igb_ptp_init and igb_ptp_stop since these functions destroy the PHC device, which will cause other problems if we do so. Since igb_ptp_reset now re-schedules the work-queue item we don't need an equivalent igb_ptp_resume in the resume workflow.

---
 drivers/net/ethernet/intel/igb/igb_main.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/intel/igb/igb_main.c +2 -0
index 0321f0884fa0..beb3c1dac8af 100644
@@ -7528,6 +7528,8 @@ static int __igb_shutdown(struct pci_dev *pdev, bool *enable_wake,
 	if (netif_running(netdev))
 		__igb_close(netdev, true);
 
+	igb_ptp_suspend(adapter);
+
 	igb_clear_interrupt_scheme(adapter);
 
 #ifdef CONFIG_PM
Signature · 1 line
2.8.2.820.gd1c5f70
#9 lore raw

PATCH v4 1/5 igb: introduce ptp_flags variable and use it to replace IGB_FLAG_PTP

In reply to Jacob Keller
Quoted 8 lines · Jacob Keller

Upcoming patches will introduce new PTP specific flags. To avoid cluttering the normal flags variable, introduce PTP specific "ptp_flags"
variable for this purpose, and move IGB_FLAG_PTP to become IGB_PTP_ENABLED.

---

For reference, I attached the interseries difference between v3 and v4.

Thanks,
Jake
-------------- next part --------------
A non-text attachment was scrubbed...
Name: interdiff-v3-v4.patch
Type: text/x-patch
Size: 1396 bytes
Desc: interdiff-v3-v4.patch
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20160524/a104e891/attachment.bin>

#10 lore raw

PATCH v4 1/5 igb: introduce ptp_flags variable and use it to replace IGB_FLAG_PTP

In reply to Jacob Keller
Quoted 12 lines

From: Intel-wired-lan [mailto:intel-wired-lan-bounces at lists.osuosl.org] On Behalf Of Jacob Keller
Sent: Tuesday, May 24, 2016 1:56 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH v4 1/5] igb: introduce ptp_flags variable and use it to replace IGB_FLAG_PTP

Upcoming patches will introduce new PTP specific flags. To avoid cluttering the normal flags variable, introduce PTP specific "ptp_flags" variable for this purpose, and move IGB_FLAG_PTP to become IGB_PTP_ENABLED.

Quoted 6 lines
---
 drivers/net/ethernet/intel/igb/igb.h     | 5 ++++-
 drivers/net/ethernet/intel/igb/igb_ptp.c | 7 ++++---
 2 files changed, 8 insertions(+), 4 deletions(-)

On a quick check this (v3) series resolves both the issues I described earlier. All the systems I saw problem on are now happily bouncing ptp4l packets across the wire for more than a minute or two. Given it would blow up almost immediately before those issues seem to be gone. Now to put it through the rest of its paces ;)

#11 lore raw

PATCH v4 1/5 igb: introduce ptp_flags variable and use it to replace IGB_FLAG_PTP

Quoted 22 lines · Aaron F
Quoted 16 lines

From: Intel-wired-lan [mailto:intel-wired-lan-bounces at lists.osuosl. org] On
Behalf Of Jacob Keller
Sent: Tuesday, May 24, 2016 1:56 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH v4 1/5] igb: introduce ptp_flags variable
and use it to replace IGB_FLAG_PTP

Upcoming patches will introduce new PTP specific flags. To avoid cluttering the normal flags variable, introduce PTP specific "ptp_flags"
variable for this purpose, and move IGB_FLAG_PTP to become IGB_PTP_ENABLED.

Quoted 6 lines

---
?drivers/net/ethernet/intel/igb/igb.h?????| 5 ++++- ?drivers/net/ethernet/intel/igb/igb_ptp.c | 7 ++++--- ?2 files changed, 8 insertions(+), 4 deletions(-)

Quoted 5 lines

On a quick check this (v3) series resolves both the issues I described earlier.??All the systems I saw problem on are now happily bouncing ptp4l packets across the wire for more than a minute or two.??Given it would blow up almost immediately before those issues seem to be gone.??Now to put it through the rest of its paces ;)

Thanks.

Regards,
Jake

#12 lore raw

PATCH v4 1/5 igb: introduce ptp_flags variable and use it to replace IGB_FLAG_PTP

In reply to Jacob Keller
Quoted 12 lines

From: Intel-wired-lan [mailto:intel-wired-lan-bounces at lists.osuosl.org] On Behalf Of Jacob Keller
Sent: Tuesday, May 24, 2016 1:56 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH v4 1/5] igb: introduce ptp_flags variable and use it to replace IGB_FLAG_PTP

Upcoming patches will introduce new PTP specific flags. To avoid cluttering the normal flags variable, introduce PTP specific "ptp_flags" variable for this purpose, and move IGB_FLAG_PTP to become IGB_PTP_ENABLED.

Quoted 6 lines
---
 drivers/net/ethernet/intel/igb/igb.h     | 5 ++++-
 drivers/net/ethernet/intel/igb/igb_ptp.c | 7 ++++---
 2 files changed, 8 insertions(+), 4 deletions(-)
#2 lore raw

PATCH v4 2/5 igb: introduce IGB_PTP_OVERFLOW_CHECK flag

In reply to Jacob Keller
Quoted 12 lines

From: Intel-wired-lan [mailto:intel-wired-lan-bounces at lists.osuosl.org] On Behalf Of Jacob Keller
Sent: Tuesday, May 24, 2016 1:56 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH v4 2/5] igb: introduce IGB_PTP_OVERFLOW_CHECK flag

Don't continue to use complex MAC type checks for handling various cases where we have overflow check code. Make this code more obvious by introducing a flag which is enabled for hardware that needs these checks.

Quoted 6 lines
---
 drivers/net/ethernet/intel/igb/igb.h     |  1 +
 drivers/net/ethernet/intel/igb/igb_ptp.c | 21 ++++++++-------------
 2 files changed, 9 insertions(+), 13 deletions(-)
#4 lore raw

PATCH v4 3/5 igb: re-use igb_ptp_reset in igb_ptp_init

In reply to Jacob Keller
Quoted 15 lines

From: Intel-wired-lan [mailto:intel-wired-lan-bounces at lists.osuosl.org] On Behalf Of Jacob Keller
Sent: Tuesday, May 24, 2016 1:56 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH v4 3/5] igb: re-use igb_ptp_reset in igb_ptp_init

Modify igb_ptp_init to take advantage of igb_ptp_reset, and remove duplicated work that was occurring in both igb_ptp_reset and igb_ptp_init.

In total, resetting the TSAUXC register, and resetting the system time both happen in igb_ptp_reset already. igb_ptp_reset now also takes care of starting the delayed work item for overflow checks, as well.

Quoted 6 lines
---
 drivers/net/ethernet/intel/igb/igb_main.c |  3 +-
 drivers/net/ethernet/intel/igb/igb_ptp.c  | 48 +++++++++++--------------------
 2 files changed, 18 insertions(+), 33 deletions(-)
#6 lore raw

PATCH v4 4/5 igb: implement igb_ptp_suspend

In reply to Jacob Keller
Quoted 6 lines

From: Intel-wired-lan [mailto:intel-wired-lan-bounces at lists.osuosl.org] On Behalf Of Jacob Keller
Sent: Tuesday, May 24, 2016 1:57 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH v4 4/5] igb: implement igb_ptp_suspend

Quoted 9 lines

Make igb_ptp_stop take advantage of this new function to reduce code duplication.

---
 drivers/net/ethernet/intel/igb/igb.h     |  1 +
 drivers/net/ethernet/intel/igb/igb_ptp.c | 22 +++++++++++++++++-----
 2 files changed, 18 insertions(+), 5 deletions(-)
#8 lore raw

PATCH v4 5/5 igb: call igb_ptp_suspend during suspend/resume cycle

In reply to Jacob Keller
Quoted 13 lines

From: Intel-wired-lan [mailto:intel-wired-lan-bounces at lists.osuosl.org] On Behalf Of Jacob Keller
Sent: Tuesday, May 24, 2016 1:57 PM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH v4 5/5] igb: call igb_ptp_suspend during suspend/resume cycle

Properly stop the extra workqueue items and ensure that we resume cleanly. This is better than using igb_ptp_init and igb_ptp_stop since these functions destroy the PHC device, which will cause other problems if we do so. Since igb_ptp_reset now re-schedules the work-queue item we don't need an equivalent igb_ptp_resume in the resume workflow.

Quoted 5 lines
---
 drivers/net/ethernet/intel/igb/igb_main.c | 2 ++
 1 file changed, 2 insertions(+)