Skip to contentSkip to conversation

PPS and SDP support for i225

PATCH Superseded Ederson de Souza 3 participants 7 messages Feb 12, 2021 – Feb 18, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover PPS and SDP support for i225

The i225 device has some PHC Hardware Clock features such as Pulse Per Seconds interrupts or Software Defined Pins signals. This series add support to some of them.

Ederson de Souza (2):
igc: Enable internal i225 PPS
igc: enable auxiliary PHC functions for the i225

 drivers/net/ethernet/intel/igc/igc.h         |  13 +
 drivers/net/ethernet/intel/igc/igc_defines.h |  63 ++++
 drivers/net/ethernet/intel/igc/igc_main.c    |  63 +++-
 drivers/net/ethernet/intel/igc/igc_ptp.c     | 294 ++++++++++++++++++-
 drivers/net/ethernet/intel/igc/igc_regs.h    |  10 +
 5 files changed, 440 insertions(+), 3 deletions(-)
Signature · 1 line
2.30.0
#1 lore raw

PATCH 1/2 igc: Enable internal i225 PPS

The i225 device can produce one interrupt on the full second. This patch allows using this interrupt to generate an internal PPS event for adjusting the kernel system time.

---
 drivers/net/ethernet/intel/igc/igc.h      |  2 ++
 drivers/net/ethernet/intel/igc/igc_main.c |  8 +++++++
 drivers/net/ethernet/intel/igc/igc_ptp.c  | 28 ++++++++++++++++++++++-
 3 files changed, 37 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/igc/igc.h +2 -0
index 415cfea27718..fa81cec80711 100644
@@ -224,6 +224,8 @@ struct igc_adapter {
 	char fw_version[32];
 
 	struct bpf_prog *xdp_prog;
+
+	bool pps_sys_wrap_on;
 };
 
 void igc_up(struct igc_adapter *adapter);
drivers/net/ethernet/intel/igc/igc_main.c +8 -0
index c363f7fd1aaa..5e3b6ac00b3a 100644
@@ -4599,9 +4599,17 @@ igc_features_check(struct sk_buff *skb, struct net_device *dev,
 static void igc_tsync_interrupt(struct igc_adapter *adapter)
 {
 	struct igc_hw *hw = &adapter->hw;
+	struct ptp_clock_event event;
 	u32 tsicr = rd32(IGC_TSICR);
 	u32 ack = 0;
 
+	if (tsicr & IGC_TSICR_SYS_WRAP) {
+		event.type = PTP_CLOCK_PPS;
+		if (adapter->ptp_caps.pps)
+			ptp_clock_event(adapter->ptp_clock, &event);
+		ack |= IGC_TSICR_SYS_WRAP;
+	}
+
 	if (tsicr & IGC_TSICR_TXTS) {
 		/* retrieve hardware timestamp */
 		schedule_work(&adapter->ptp_tx_work);
drivers/net/ethernet/intel/igc/igc_ptp.c +27 -1
index 7301a7b3fadc..868cd51909e9 100644
@@ -123,6 +123,29 @@ static int igc_ptp_settime_i225(struct ptp_clock_info *ptp,
 static int igc_ptp_feature_enable_i225(struct ptp_clock_info *ptp,
 				       struct ptp_clock_request *rq, int on)
 {
+	struct igc_adapter *igc =
+		container_of(ptp, struct igc_adapter, ptp_caps);
+	struct igc_hw *hw = &igc->hw;
+	unsigned long flags;
+	u32 tsim;
+
+	switch (rq->type) {
+	case PTP_CLK_REQ_PPS:
+		spin_lock_irqsave(&igc->tmreg_lock, flags);
+		tsim = rd32(IGC_TSIM);
+		if (on)
+			tsim |= IGC_TSICR_SYS_WRAP;
+		else
+			tsim &= ~IGC_TSICR_SYS_WRAP;
+		igc->pps_sys_wrap_on = !!on;
+		wr32(IGC_TSIM, tsim);
+		spin_unlock_irqrestore(&igc->tmreg_lock, flags);
+		return 0;
+
+	default:
+		break;
+	}
+
 	return -EOPNOTSUPP;
 }
 
@@ -497,6 +520,7 @@ void igc_ptp_init(struct igc_adapter *adapter)
 		adapter->ptp_caps.gettimex64 = igc_ptp_gettimex64_i225;
 		adapter->ptp_caps.settime64 = igc_ptp_settime_i225;
 		adapter->ptp_caps.enable = igc_ptp_feature_enable_i225;
+		adapter->ptp_caps.pps = 1;
 		break;
 	default:
 		adapter->ptp_clock = NULL;
@@ -598,7 +622,9 @@ void igc_ptp_reset(struct igc_adapter *adapter)
 	case igc_i225:
 		wr32(IGC_TSAUXC, 0x0);
 		wr32(IGC_TSSDP, 0x0);
-		wr32(IGC_TSIM, IGC_TSICR_INTERRUPTS);
+		wr32(IGC_TSIM,
+		     IGC_TSICR_INTERRUPTS |
+		     (adapter->pps_sys_wrap_on ? IGC_TSICR_SYS_WRAP : 0));
 		wr32(IGC_IMS, IGC_IMS_TS);
 		break;
 	default:
Signature · 1 line
2.30.0
#2 lore raw

PATCH 1/2 igc: Enable internal i225 PPS

Dear Ederson,

Am 12.02.21 um 02:42 schrieb Ederson de Souza:

Quoted 1 line

The i225 device can produce one interrupt on the full second. This patch

Please reference the spec.

Quoted 2 lines

allows using this interrupt to generate an internal PPS event for adjusting the kernel system time.

How can this be tested?

A more elaborate description of the implementation would be useful in commit messages.

Quoted 85 lines
---
  drivers/net/ethernet/intel/igc/igc.h      |  2 ++
  drivers/net/ethernet/intel/igc/igc_main.c |  8 +++++++
  drivers/net/ethernet/intel/igc/igc_ptp.c  | 28 ++++++++++++++++++++++-
  3 files changed, 37 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/igc/igc.h +2 -0
index 415cfea27718..fa81cec80711 100644
@@ -224,6 +224,8 @@ struct igc_adapter {
  	char fw_version[32];
 
  	struct bpf_prog *xdp_prog;
+
+	bool pps_sys_wrap_on;
  };
 
  void igc_up(struct igc_adapter *adapter);
drivers/net/ethernet/intel/igc/igc_main.c +8 -0
index c363f7fd1aaa..5e3b6ac00b3a 100644
@@ -4599,9 +4599,17 @@ igc_features_check(struct sk_buff *skb, struct net_device *dev,
  static void igc_tsync_interrupt(struct igc_adapter *adapter)
  {
  	struct igc_hw *hw = &adapter->hw;
+	struct ptp_clock_event event;
  	u32 tsicr = rd32(IGC_TSICR);
  	u32 ack = 0;
 
+	if (tsicr & IGC_TSICR_SYS_WRAP) {
+		event.type = PTP_CLOCK_PPS;
+		if (adapter->ptp_caps.pps)
+			ptp_clock_event(adapter->ptp_clock, &event);
+		ack |= IGC_TSICR_SYS_WRAP;
+	}
+
  	if (tsicr & IGC_TSICR_TXTS) {
  		/* retrieve hardware timestamp */
  		schedule_work(&adapter->ptp_tx_work);
drivers/net/ethernet/intel/igc/igc_ptp.c +24 -0
index 7301a7b3fadc..868cd51909e9 100644
@@ -123,6 +123,29 @@ static int igc_ptp_settime_i225(struct ptp_clock_info *ptp,
  static int igc_ptp_feature_enable_i225(struct ptp_clock_info *ptp,
  				       struct ptp_clock_request *rq, int on)
  {
+	struct igc_adapter *igc =
+		container_of(ptp, struct igc_adapter, ptp_caps);
+	struct igc_hw *hw = &igc->hw;
+	unsigned long flags;
+	u32 tsim;
+
+	switch (rq->type) {
+	case PTP_CLK_REQ_PPS:
+		spin_lock_irqsave(&igc->tmreg_lock, flags);
+		tsim = rd32(IGC_TSIM);
+		if (on)
+			tsim |= IGC_TSICR_SYS_WRAP;
+		else
+			tsim &= ~IGC_TSICR_SYS_WRAP;
+		igc->pps_sys_wrap_on = !!on;
+		wr32(IGC_TSIM, tsim);
+		spin_unlock_irqrestore(&igc->tmreg_lock, flags);
+		return 0;
+
+	default:
+		break;
+	}
+
  	return -EOPNOTSUPP;
  }
 
@@ -497,6 +520,7 @@ void igc_ptp_init(struct igc_adapter *adapter)
  		adapter->ptp_caps.gettimex64 = igc_ptp_gettimex64_i225;
  		adapter->ptp_caps.settime64 = igc_ptp_settime_i225;
  		adapter->ptp_caps.enable = igc_ptp_feature_enable_i225;
+		adapter->ptp_caps.pps = 1;
  		break;
  	default:
  		adapter->ptp_clock = NULL;

drivers/net/ethernet/intel/igc/igc_ptp.c void igc_ptp_reset(struct igc_adapter *adapter) · line 630

Quoted 10 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +3 -1
@@ -598,7 +622,9 @@ void igc_ptp_reset(struct igc_adapter *adapter)
  	case igc_i225:
  		wr32(IGC_TSAUXC, 0x0);
  		wr32(IGC_TSSDP, 0x0);
-		wr32(IGC_TSIM, IGC_TSICR_INTERRUPTS);
+		wr32(IGC_TSIM,
+		     IGC_TSICR_INTERRUPTS |
+		     (adapter->pps_sys_wrap_on ? IGC_TSICR_SYS_WRAP : 0));
  		wr32(IGC_IMS, IGC_IMS_TS);
  		break;
  	default:

Otherwise, this looks good.

Kind regards,

Paul

#3 lore raw

PATCH 2/2 igc: enable auxiliary PHC functions for the i225

In reply to Ederson de Souza

The i225 device offers a number of special PTP Hardware Clock features on the Software Defined Pins (SDPs). This patch adds support for two of the possible functions, namely time stamping external events, and periodic output signals.

The assignment of PHC functions to the four SDP can be freely chosen by the user.

While i225 allows up to four timers to be used to source the time used on the external events or output signals, this patch uses only one of those timers.

---
 drivers/net/ethernet/intel/igc/igc.h         |  11 +
 drivers/net/ethernet/intel/igc/igc_defines.h |  63 +++++
 drivers/net/ethernet/intel/igc/igc_main.c    |  55 +++-
 drivers/net/ethernet/intel/igc/igc_ptp.c     | 268 ++++++++++++++++++-
 drivers/net/ethernet/intel/igc/igc_regs.h    |  10 +
 5 files changed, 404 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/igc/igc.h +11 -0
index fa81cec80711..53f3cef3820d 100644
@@ -28,6 +28,11 @@ void igc_ethtool_set_ops(struct net_device *);
 #define MAX_ETYPE_FILTER		8
 #define IGC_RETA_SIZE			128
 
+/* SDP support */
+#define IGC_N_EXTTS	2
+#define IGC_N_PEROUT	2
+#define IGC_N_SDP	4
+
 enum igc_mac_filter_type {
 	IGC_MAC_FILTER_TYPE_DST = 0,
 	IGC_MAC_FILTER_TYPE_SRC
@@ -226,6 +231,12 @@ struct igc_adapter {
 	struct bpf_prog *xdp_prog;
 
 	bool pps_sys_wrap_on;
+
+	struct ptp_pin_desc sdp_config[IGC_N_SDP];
+	struct {
+		struct timespec64 start;
+		struct timespec64 period;
+	} perout[IGC_N_PEROUT];
 };
 
 void igc_up(struct igc_adapter *adapter);
drivers/net/ethernet/intel/igc/igc_defines.h +63 -0

81 lines not on this page · raw message

drivers/net/ethernet/intel/igc/igc_main.c +53 -2

69 lines not on this page · raw message

drivers/net/ethernet/intel/igc/igc_ptp.c +267 -1

303 lines not on this page · raw message

drivers/net/ethernet/intel/igc/igc_regs.h +10 -0
index 3e5cb7aef9da..dd7f7d5e8325 100644
@@ -192,6 +192,16 @@
 #define IGC_TSYNCTXCTL	0x0B614  /* Tx Time Sync Control register - RW */
 #define IGC_TSYNCRXCFG	0x05F50  /* Time Sync Rx Configuration - RW */
 #define IGC_TSSDP	0x0003C  /* Time Sync SDP Configuration Register - RW */
+#define IGC_TRGTTIML0  0x0B644 /* Target Time Register 0 Low  - RW */
+#define IGC_TRGTTIMH0  0x0B648 /* Target Time Register 0 High - RW */
+#define IGC_TRGTTIML1  0x0B64C /* Target Time Register 1 Low  - RW */
+#define IGC_TRGTTIMH1  0x0B650 /* Target Time Register 1 High - RW */
+#define IGC_FREQOUT0   0x0B654 /* Frequency Out 0 Control Register - RW */
+#define IGC_FREQOUT1   0x0B658 /* Frequency Out 1 Control Register - RW */
+#define IGC_AUXSTMPL0  0x0B65C /* Auxiliary Time Stamp 0 Register Low  - RO */
+#define IGC_AUXSTMPH0  0x0B660 /* Auxiliary Time Stamp 0 Register High - RO */
+#define IGC_AUXSTMPL1  0x0B664 /* Auxiliary Time Stamp 1 Register Low  - RO */
+#define IGC_AUXSTMPH1  0x0B668 /* Auxiliary Time Stamp 1 Register High - RO */
 
 #define IGC_IMIR(_i)	(0x05A80 + ((_i) * 4))  /* Immediate Interrupt */
 #define IGC_IMIREXT(_i)	(0x05AA0 + ((_i) * 4))  /* Immediate INTR Ext*/
Signature · 1 line
2.30.0
#4 lore raw

PATCH 2/2 igc: enable auxiliary PHC functions for the i225

Dear Ederson,

Am 12.02.21 um 02:42 schrieb Ederson de Souza:

Quoted 11 lines

The i225 device offers a number of special PTP Hardware Clock features on the Software Defined Pins (SDPs). This patch adds support for two of the possible functions, namely time stamping external events, and periodic output signals.

The assignment of PHC functions to the four SDP can be freely chosen by the user.

While i225 allows up to four timers to be used to source the time used on the external events or output signals, this patch uses only one of those timers.

Why is that? Because it?s simpler to implement? Please add the reason to the commit message.

It?d be also great, if you mentioned the datasheet name and revision used for implementing this.

Kind regards,

Paul

#5 lore raw

PATCH 2/2 igc: enable auxiliary PHC functions for the i225

Quoted 22 lines · Paul Menzel

Dear Ederson,

Am 12.02.21 um 02:42 schrieb Ederson de Souza:

Quoted 12 lines

The i225 device offers a number of special PTP Hardware Clock features on
the Software Defined Pins (SDPs). This patch adds support for two of the
possible functions, namely time stamping external events, and periodic
output signals.

The assignment of PHC functions to the four SDP can be freely chosen by
the user.

Quoted 5 lines

While i225 allows up to four timers to be used to source the time used
on the external events or output signals, this patch uses only one of
those timers.

Quoted 3 lines

Why is that? Because it?s simpler to implement? Please add the reason to
the commit message.

I've applied this patch so testing can be done, but I agree with Paul. Some detail on why only one timer is being used would be nice.

Also, there are quite a few check/warnings from checkpatch that look like they can easily be remedied.

Thanks,
Tony

#6 lore raw

PATCH 2/2 igc: enable auxiliary PHC functions for the i225

Quoted 27 lines · Anthony L
Quoted 22 lines · Paul Menzel

Dear Ederson,

Am 12.02.21 um 02:42 schrieb Ederson de Souza:

Quoted 12 lines

The i225 device offers a number of special PTP Hardware Clock features on
the Software Defined Pins (SDPs). This patch adds support for two of the
possible functions, namely time stamping external events, and periodic
output signals.

The assignment of PHC functions to the four SDP can be freely chosen by
the user.

Quoted 5 lines

While i225 allows up to four timers to be used to source the time used
on the external events or output signals, this patch uses only one of
those timers.

Quoted 3 lines

Why is that? Because it?s simpler to implement? Please add the reason to
the commit message.

Quoted 5 lines

I've applied this patch so testing can be done, but I agree with Paul. Some detail on why only one timer is being used would be nice.

Also, there are quite a few check/warnings from checkpatch that look like they can easily be remedied.

Sure, I'll address the review comments and checks and send a v2 soon. Thanks for the reviews!

Quoted 3 lines

Thanks,
Tony