Skip to contentSkip to conversation

PPS and SDP support for i225

PATCH New Ederson de Souza 2 participants 5 messages Feb 19, 2021 – Apr 11, 2021

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

v2 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.

Changes from v1:
- Addressed some checkpatch issues. However, most of them were about using BIT macro in code blocks whose readability would get worse in case I used it. Think of a some (1 << X) in the middle of (2 << Y).

- Added more information on commit messages - trying to highlight some implementation details. However, the datasheet that is reference for these changes is not public yet, so I didn't mention it. As a workaround, I mention that most of it is the same as i210.

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     | 295 ++++++++++++++++++-
 drivers/net/ethernet/intel/igc/igc_regs.h    |  10 +
 5 files changed, 441 insertions(+), 3 deletions(-)
Signature · 1 line
2.30.1
#1 lore raw

PATCH v2 1/2 igc: Enable internal i225 PPS

The i225 device can produce one interrupt on the full second, much like i210 - from where this patch is inspired.

This patch sets up the full second interruption on the i225 and when receiving it, it sends a PPS event to PTP (Precision Time Protocol) kernel subsystem.

The PTP subsystem exposes the PPS events via ioctl and sysfs, and one can use the testptp tool (tools/testing/selftests/ptp) to check that the events are being generated.

---
 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..98a6ce322f67 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.1
#2 lore raw

PATCH v2 1/2 igc: Enable internal i225 PPS

Quoted 11 lines · Ederson de Souza

The i225 device can produce one interrupt on the full second, much like i210 - from where this patch is inspired.

This patch sets up the full second interruption on the i225 and when receiving it, it sends a PPS event to PTP (Precision Time Protocol) kernel subsystem.

The PTP subsystem exposes the PPS events via ioctl and sysfs, and one can use the testptp tool (tools/testing/selftests/ptp) to check that the events are being generated.

Quoted 7 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(-)
#3 lore raw

PATCH v2 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) - much like i210, which is used as inspiration for this patch. It enables two 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.

For the external events time stamping, when the SDP (configured as input by user) level changes, an interrupt is generated and the kernel Precision Time Protocol (PTP) is informed.

For the periodic output signals, the i225 is configured to generate them (so the SDP level will change periodically) and the driver also has to keep updating the time of the next level change. However, this work is not necessary for some frequencies as the i225 takes care of them (namely, anything with a half-cycle of 500ms, 250ms, 125ms or < 70ms).

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. Main reason is to keep it simple, as it's not clear how these extra timers would be exposed to users. Note that currently a NIC can expose a single PTP device.

---
 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     | 269 ++++++++++++++++++-
 drivers/net/ethernet/intel/igc/igc_regs.h    |  10 +
 5 files changed, 405 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 +268 -1

304 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.1
#4 lore raw

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

Quoted 24 lines · Ederson de Souza

The i225 device offers a number of special PTP Hardware Clock features on the Software Defined Pins (SDPs) - much like i210, which is used as inspiration for this patch. It enables two 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.

For the external events time stamping, when the SDP (configured as input by user) level changes, an interrupt is generated and the kernel Precision Time Protocol (PTP) is informed.

For the periodic output signals, the i225 is configured to generate them (so the SDP level will change periodically) and the driver also has to keep updating the time of the next level change. However, this work is not necessary for some frequencies as the i225 takes care of them (namely, anything with a half-cycle of 500ms, 250ms, 125ms or < 70ms).

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. Main reason is to keep it simple, as it's not clear how these extra timers would be exposed to users. Note that currently a NIC can expose a single PTP device.

Quoted 9 lines
---
  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     | 269 ++++++++++++++++++-
  drivers/net/ethernet/intel/igc/igc_regs.h    |  10 +
  5 files changed, 405 insertions(+), 3 deletions(-)