netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Íñigo Huguet" <ihuguet@redhat.com>
To: ecree.xilinx@gmail.com, habetsm.xilinx@gmail.com
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, netdev@vger.kernel.org,
	"Íñigo Huguet" <ihuguet@redhat.com>
Subject: [PATCH net-next v5 2/3] sfc: support PTP over IPv6/UDP
Date: Mon,  5 Sep 2022 10:23:22 +0200	[thread overview]
Message-ID: <20220905082323.11241-3-ihuguet@redhat.com> (raw)
In-Reply-To: <20220905082323.11241-1-ihuguet@redhat.com>

commit bd4a2697e5e2 ("sfc: use hardware tx timestamps for more than
PTP") added support for hardware timestamping on TX for cards of the
8000 series and newer, in an effort to provide support for other
transports other than IPv4/UDP.

However, timestamping was still not working on RX for these other
transports. This patch add support for PTP over IPv6/UDP.

Tested: sync as master and as slave is correct using ptp4l from linuxptp
package, both with IPv4 and IPv6.

Suggested-by: Edward Cree <ecree.xilinx@gmail.com>
Signed-off-by: Íñigo Huguet <ihuguet@redhat.com>
---
 drivers/net/ethernet/sfc/filter.h | 22 +++++++++++
 drivers/net/ethernet/sfc/ptp.c    | 61 +++++++++++++++++++++++++------
 2 files changed, 71 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/sfc/filter.h b/drivers/net/ethernet/sfc/filter.h
index 4d928839d292..be72e71da027 100644
--- a/drivers/net/ethernet/sfc/filter.h
+++ b/drivers/net/ethernet/sfc/filter.h
@@ -9,6 +9,7 @@
 
 #include <linux/types.h>
 #include <linux/if_ether.h>
+#include <linux/in6.h>
 #include <asm/byteorder.h>
 
 /**
@@ -223,6 +224,27 @@ efx_filter_set_ipv4_local(struct efx_filter_spec *spec, u8 proto,
 	return 0;
 }
 
+/**
+ * efx_filter_set_ipv6_local - specify IPv6 host, transport protocol and port
+ * @spec: Specification to initialise
+ * @proto: Transport layer protocol number
+ * @host: Local host address (network byte order)
+ * @port: Local port (network byte order)
+ */
+static inline int
+efx_filter_set_ipv6_local(struct efx_filter_spec *spec, u8 proto,
+			  const struct in6_addr *host, __be16 port)
+{
+	spec->match_flags |=
+		EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_IP_PROTO |
+		EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_LOC_PORT;
+	spec->ether_type = htons(ETH_P_IPV6);
+	spec->ip_proto = proto;
+	memcpy(spec->loc_host, host, sizeof(spec->loc_host));
+	spec->loc_port = port;
+	return 0;
+}
+
 /**
  * efx_filter_set_ipv4_full - specify IPv4 hosts, transport protocol and ports
  * @spec: Specification to initialise
diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
index 1189ed4ffec2..0f27a08bf2f2 100644
--- a/drivers/net/ethernet/sfc/ptp.c
+++ b/drivers/net/ethernet/sfc/ptp.c
@@ -118,9 +118,11 @@
 
 #define	PTP_MIN_LENGTH		63
 
-#define PTP_RXFILTERS_LEN	2
+#define PTP_RXFILTERS_LEN	4
 
-#define PTP_ADDRESS		0xe0000181	/* 224.0.1.129 */
+#define PTP_ADDR_IPV4		0xe0000181	/* 224.0.1.129 */
+#define PTP_ADDR_IPV6		{0xff, 0x0e, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+				0, 0x01, 0x81}	/* ff0e::181 */
 #define PTP_EVENT_PORT		319
 #define PTP_GENERAL_PORT	320
 
@@ -1297,20 +1299,22 @@ static void efx_ptp_remove_multicast_filters(struct efx_nic *efx)
 	}
 }
 
-static int efx_ptp_insert_ipv4_filter(struct efx_nic *efx, u16 port)
+static void efx_ptp_init_filter(struct efx_nic *efx,
+				struct efx_filter_spec *rxfilter)
 {
-	struct efx_ptp_data *ptp = efx->ptp_data;
-	struct efx_filter_spec rxfilter;
-	int rc;
+	struct efx_channel *channel = efx->ptp_data->channel;
+	struct efx_rx_queue *queue = efx_channel_get_rx_queue(channel);
 
-	efx_filter_init_rx(&rxfilter, EFX_FILTER_PRI_REQUIRED, 0,
-			   efx_rx_queue_index(
-				   efx_channel_get_rx_queue(ptp->channel)));
+	efx_filter_init_rx(rxfilter, EFX_FILTER_PRI_REQUIRED, 0,
+			   efx_rx_queue_index(queue));
+}
 
-	efx_filter_set_ipv4_local(&rxfilter, IPPROTO_UDP, htonl(PTP_ADDRESS),
-				  htons(port));
+static int efx_ptp_insert_filter(struct efx_nic *efx,
+				 struct efx_filter_spec *rxfilter)
+{
+	struct efx_ptp_data *ptp = efx->ptp_data;
 
-	rc = efx_filter_insert_filter(efx, &rxfilter, true);
+	int rc = efx_filter_insert_filter(efx, rxfilter, true);
 	if (rc < 0)
 		return rc;
 	ptp->rxfilters[ptp->rxfilters_count] = rc;
@@ -1318,6 +1322,26 @@ static int efx_ptp_insert_ipv4_filter(struct efx_nic *efx, u16 port)
 	return 0;
 }
 
+static int efx_ptp_insert_ipv4_filter(struct efx_nic *efx, u16 port)
+{
+	struct efx_filter_spec rxfilter;
+
+	efx_ptp_init_filter(efx, &rxfilter);
+	efx_filter_set_ipv4_local(&rxfilter, IPPROTO_UDP, htonl(PTP_ADDR_IPV4),
+				  htons(port));
+	return efx_ptp_insert_filter(efx, &rxfilter);
+}
+
+static int efx_ptp_insert_ipv6_filter(struct efx_nic *efx, u16 port)
+{
+	const struct in6_addr addr = {{PTP_ADDR_IPV6}};
+	struct efx_filter_spec rxfilter;
+
+	efx_ptp_init_filter(efx, &rxfilter);
+	efx_filter_set_ipv6_local(&rxfilter, IPPROTO_UDP, &addr, htons(port));
+	return efx_ptp_insert_filter(efx, &rxfilter);
+}
+
 static int efx_ptp_insert_multicast_filters(struct efx_nic *efx)
 {
 	struct efx_ptp_data *ptp = efx->ptp_data;
@@ -1337,6 +1361,19 @@ static int efx_ptp_insert_multicast_filters(struct efx_nic *efx)
 	if (rc < 0)
 		goto fail;
 
+	/* if the NIC supports hw timestamps by the MAC, we can support
+	 * PTP over IPv6
+	 */
+	if (efx_ptp_use_mac_tx_timestamps(efx)) {
+		rc = efx_ptp_insert_ipv6_filter(efx, PTP_EVENT_PORT);
+		if (rc < 0)
+			goto fail;
+
+		rc = efx_ptp_insert_ipv6_filter(efx, PTP_GENERAL_PORT);
+		if (rc < 0)
+			goto fail;
+	}
+
 	return 0;
 
 fail:
-- 
2.34.1


  parent reply	other threads:[~2022-09-05  8:23 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-09  9:19 [PATCH net-next 0/3] sfc: add support for PTP over IPv6 and 802.3 Íñigo Huguet
2022-08-09  9:20 ` [PATCH net-next 1/3] sfc: allow more flexible way of adding filters for PTP Íñigo Huguet
2022-08-09 13:21   ` Edward Cree
2022-08-09  9:20 ` [PATCH net-next 2/3] sfc: support PTP over IPv6/UDP Íñigo Huguet
2022-08-09 13:21   ` Edward Cree
2022-08-09  9:20 ` [PATCH net-next 3/3] sfc: support PTP over Ethernet Íñigo Huguet
2022-08-09 13:22   ` Edward Cree
2022-08-19  8:19 ` [PATCH net-next v2 0/3] sfc: add support for PTP over IPv6 and 802.3 Íñigo Huguet
2022-08-19  8:19   ` [PATCH net-next v2 1/3] sfc: allow more flexible way of adding filters for PTP Íñigo Huguet
2022-08-19 19:38     ` kernel test robot
2022-08-19 21:19     ` kernel test robot
2022-08-19  8:20   ` [PATCH net-next v2 2/3] sfc: support PTP over IPv6/UDP Íñigo Huguet
2022-08-19  8:20   ` [PATCH net-next v2 3/3] sfc: support PTP over Ethernet Íñigo Huguet
2022-08-25  9:02   ` [PATCH net-next v3 0/3] sfc: add support for PTP over IPv6 and 802.3 Íñigo Huguet
2022-08-25  9:02     ` [PATCH net-next v3 1/3] sfc: allow more flexible way of adding filters for PTP Íñigo Huguet
2022-08-25  9:02     ` [PATCH net-next v3 2/3] sfc: support PTP over IPv6/UDP Íñigo Huguet
2022-08-26  1:32       ` Jakub Kicinski
2022-08-26  6:39         ` Íñigo Huguet
2022-08-26 23:27           ` Jakub Kicinski
2022-08-29  7:03             ` Íñigo Huguet
2022-08-30  0:28               ` Jakub Kicinski
2022-08-30  6:11                 ` Íñigo Huguet
2022-08-30 15:47           ` Edward Cree
2022-08-25  9:02     ` [PATCH net-next v3 3/3] sfc: support PTP over Ethernet Íñigo Huguet
2022-08-25 16:16     ` [PATCH net-next v3 0/3] sfc: add support for PTP over IPv6 and 802.3 Andrew Lunn
2022-08-26  6:58       ` Íñigo Huguet
2022-08-26 12:52         ` Andrew Lunn
2022-08-29  7:09           ` Íñigo Huguet
2022-08-29 14:38             ` Richard Cochran
2022-08-29 16:15               ` Andrew Lunn
2022-08-30  0:30                 ` Jakub Kicinski
2022-08-31 10:16     ` [PATCH net-next v4 " Íñigo Huguet
2022-08-31 10:16       ` [PATCH net-next v4 1/3] sfc: allow more flexible way of adding filters for PTP Íñigo Huguet
2022-08-31 15:17         ` Edward Cree
2022-08-31 10:16       ` [PATCH net-next v4 2/3] sfc: support PTP over IPv6/UDP Íñigo Huguet
2022-08-31 15:49         ` Edward Cree
2022-08-31 10:16       ` [PATCH net-next v4 3/3] sfc: support PTP over Ethernet Íñigo Huguet
2022-08-31 13:47       ` [PATCH net-next v4 0/3] sfc: add support for PTP over IPv6 and 802.3 Richard Cochran
2022-09-05  8:23       ` [PATCH net-next v5 " Íñigo Huguet
2022-09-05  8:23         ` [PATCH net-next v5 1/3] sfc: allow more flexible way of adding filters for PTP Íñigo Huguet
2022-09-05  8:23         ` Íñigo Huguet [this message]
2022-09-05  8:23         ` [PATCH net-next v5 3/3] sfc: support PTP over Ethernet Íñigo Huguet
2022-09-05 16:08         ` [PATCH net-next v5 0/3] sfc: add support for PTP over IPv6 and 802.3 Edward Cree
2022-09-07 11:40         ` patchwork-bot+netdevbpf

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=20220905082323.11241-3-ihuguet@redhat.com \
    --to=ihuguet@redhat.com \
    --cc=davem@davemloft.net \
    --cc=ecree.xilinx@gmail.com \
    --cc=edumazet@google.com \
    --cc=habetsm.xilinx@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /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).