netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/3] ptp: Add generic is_sync() function
@ 2022-03-05 11:21 Kurt Kanzenbach
  2022-03-05 11:21 ` [PATCH net-next 1/3] ptp: Add generic PTP " Kurt Kanzenbach
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Kurt Kanzenbach @ 2022-03-05 11:21 UTC (permalink / raw)
  To: Richard Cochran, David S. Miller, Jakub Kicinski
  Cc: Andrew Lunn, Heiner Kallweit, Russell King, Yonghong Song,
	Daniel Borkmann, Andrii Nakryiko, Divya Koppera, Horatiu Vultur,
	netdev, Kurt Kanzenbach

Hi,

as multiple PHY drivers such as micrel or TI dp83640 need to inspect whether a
given skb represents a PTP Sync message, provide a generic function for it. This
avoids code duplication and can be reused by future PHY IEEE 1588 implementations.

Thanks,
Kurt

Kurt Kanzenbach (3):
  ptp: Add generic PTP is_sync() function
  dp83640: Use generic ptp_msg_is_sync() function
  micrel: Use generic ptp_msg_is_sync() function

 drivers/net/phy/dp83640.c    | 13 +------------
 drivers/net/phy/micrel.c     | 13 +------------
 include/linux/ptp_classify.h | 15 +++++++++++++++
 net/core/ptp_classifier.c    | 12 ++++++++++++
 4 files changed, 29 insertions(+), 24 deletions(-)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next 1/3] ptp: Add generic PTP is_sync() function
  2022-03-05 11:21 [PATCH net-next 0/3] ptp: Add generic is_sync() function Kurt Kanzenbach
@ 2022-03-05 11:21 ` Kurt Kanzenbach
  2022-03-05 11:21 ` [PATCH net-next 2/3] dp83640: Use generic ptp_msg_is_sync() function Kurt Kanzenbach
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Kurt Kanzenbach @ 2022-03-05 11:21 UTC (permalink / raw)
  To: Richard Cochran, David S. Miller, Jakub Kicinski
  Cc: Andrew Lunn, Heiner Kallweit, Russell King, Yonghong Song,
	Daniel Borkmann, Andrii Nakryiko, Divya Koppera, Horatiu Vultur,
	netdev, Kurt Kanzenbach

PHY drivers such as micrel or dp83640 need to analyze whether a given
skb is a PTP sync message for one step functionality.

In order to avoid code duplication introduce a generic function and
move it to ptp classify.

Signed-off-by: Kurt Kanzenbach <kurt@linutronix.de>
---
 include/linux/ptp_classify.h | 15 +++++++++++++++
 net/core/ptp_classifier.c    | 12 ++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/include/linux/ptp_classify.h b/include/linux/ptp_classify.h
index 9afd34a2d36c..fefa7790dc46 100644
--- a/include/linux/ptp_classify.h
+++ b/include/linux/ptp_classify.h
@@ -126,6 +126,17 @@ static inline u8 ptp_get_msgtype(const struct ptp_header *hdr,
 	return msgtype;
 }
 
+/**
+ * ptp_msg_is_sync - Evaluates whether the given skb is a PTP Sync message
+ * @skb: packet buffer
+ * @type: type of the packet (see ptp_classify_raw())
+ *
+ * This function evaluates whether the given skb is a PTP Sync message.
+ *
+ * Return: true if sync message, false otherwise
+ */
+bool ptp_msg_is_sync(struct sk_buff *skb, unsigned int type);
+
 void __init ptp_classifier_init(void);
 #else
 static inline void ptp_classifier_init(void)
@@ -148,5 +159,9 @@ static inline u8 ptp_get_msgtype(const struct ptp_header *hdr,
 	 */
 	return PTP_MSGTYPE_SYNC;
 }
+static inline bool ptp_msg_is_sync(struct sk_buff *skb, unsigned int type)
+{
+	return false;
+}
 #endif
 #endif /* _PTP_CLASSIFY_H_ */
diff --git a/net/core/ptp_classifier.c b/net/core/ptp_classifier.c
index dd4cf01d1e0a..598041b0499e 100644
--- a/net/core/ptp_classifier.c
+++ b/net/core/ptp_classifier.c
@@ -137,6 +137,18 @@ struct ptp_header *ptp_parse_header(struct sk_buff *skb, unsigned int type)
 }
 EXPORT_SYMBOL_GPL(ptp_parse_header);
 
+bool ptp_msg_is_sync(struct sk_buff *skb, unsigned int type)
+{
+	struct ptp_header *hdr;
+
+	hdr = ptp_parse_header(skb, type);
+	if (!hdr)
+		return false;
+
+	return ptp_get_msgtype(hdr, type) == PTP_MSGTYPE_SYNC;
+}
+EXPORT_SYMBOL_GPL(ptp_msg_is_sync);
+
 void __init ptp_classifier_init(void)
 {
 	static struct sock_filter ptp_filter[] __initdata = {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next 2/3] dp83640: Use generic ptp_msg_is_sync() function
  2022-03-05 11:21 [PATCH net-next 0/3] ptp: Add generic is_sync() function Kurt Kanzenbach
  2022-03-05 11:21 ` [PATCH net-next 1/3] ptp: Add generic PTP " Kurt Kanzenbach
@ 2022-03-05 11:21 ` Kurt Kanzenbach
  2022-03-05 11:21 ` [PATCH net-next 3/3] micrel: " Kurt Kanzenbach
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Kurt Kanzenbach @ 2022-03-05 11:21 UTC (permalink / raw)
  To: Richard Cochran, David S. Miller, Jakub Kicinski
  Cc: Andrew Lunn, Heiner Kallweit, Russell King, Yonghong Song,
	Daniel Borkmann, Andrii Nakryiko, Divya Koppera, Horatiu Vultur,
	netdev, Kurt Kanzenbach

Use generic ptp_msg_is_sync() function to avoid code duplication.

Signed-off-by: Kurt Kanzenbach <kurt@linutronix.de>
---
 drivers/net/phy/dp83640.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c
index c2d1a85ec559..ecfd34882d96 100644
--- a/drivers/net/phy/dp83640.c
+++ b/drivers/net/phy/dp83640.c
@@ -970,17 +970,6 @@ static void decode_status_frame(struct dp83640_private *dp83640,
 	}
 }
 
-static int is_sync(struct sk_buff *skb, int type)
-{
-	struct ptp_header *hdr;
-
-	hdr = ptp_parse_header(skb, type);
-	if (!hdr)
-		return 0;
-
-	return ptp_get_msgtype(hdr, type) == PTP_MSGTYPE_SYNC;
-}
-
 static void dp83640_free_clocks(void)
 {
 	struct dp83640_clock *clock;
@@ -1396,7 +1385,7 @@ static void dp83640_txtstamp(struct mii_timestamper *mii_ts,
 	switch (dp83640->hwts_tx_en) {
 
 	case HWTSTAMP_TX_ONESTEP_SYNC:
-		if (is_sync(skb, type)) {
+		if (ptp_msg_is_sync(skb, type)) {
 			kfree_skb(skb);
 			return;
 		}
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next 3/3] micrel: Use generic ptp_msg_is_sync() function
  2022-03-05 11:21 [PATCH net-next 0/3] ptp: Add generic is_sync() function Kurt Kanzenbach
  2022-03-05 11:21 ` [PATCH net-next 1/3] ptp: Add generic PTP " Kurt Kanzenbach
  2022-03-05 11:21 ` [PATCH net-next 2/3] dp83640: Use generic ptp_msg_is_sync() function Kurt Kanzenbach
@ 2022-03-05 11:21 ` Kurt Kanzenbach
  2022-03-07  7:38   ` Divya.Koppera
  2022-03-06  0:07 ` [PATCH net-next 0/3] ptp: Add generic is_sync() function Richard Cochran
  2022-03-07 11:40 ` patchwork-bot+netdevbpf
  4 siblings, 1 reply; 7+ messages in thread
From: Kurt Kanzenbach @ 2022-03-05 11:21 UTC (permalink / raw)
  To: Richard Cochran, David S. Miller, Jakub Kicinski
  Cc: Andrew Lunn, Heiner Kallweit, Russell King, Yonghong Song,
	Daniel Borkmann, Andrii Nakryiko, Divya Koppera, Horatiu Vultur,
	netdev, Kurt Kanzenbach

Use generic ptp_msg_is_sync() function to avoid code duplication.

Signed-off-by: Kurt Kanzenbach <kurt@linutronix.de>
---
 drivers/net/phy/micrel.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 81a76322254c..9e6b29b23935 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -1976,17 +1976,6 @@ static int lan8814_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr)
 	return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? -EFAULT : 0;
 }
 
-static bool is_sync(struct sk_buff *skb, int type)
-{
-	struct ptp_header *hdr;
-
-	hdr = ptp_parse_header(skb, type);
-	if (!hdr)
-		return false;
-
-	return ((ptp_get_msgtype(hdr, type) & 0xf) == 0);
-}
-
 static void lan8814_txtstamp(struct mii_timestamper *mii_ts,
 			     struct sk_buff *skb, int type)
 {
@@ -1994,7 +1983,7 @@ static void lan8814_txtstamp(struct mii_timestamper *mii_ts,
 
 	switch (ptp_priv->hwts_tx_type) {
 	case HWTSTAMP_TX_ONESTEP_SYNC:
-		if (is_sync(skb, type)) {
+		if (ptp_msg_is_sync(skb, type)) {
 			kfree_skb(skb);
 			return;
 		}
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next 0/3] ptp: Add generic is_sync() function
  2022-03-05 11:21 [PATCH net-next 0/3] ptp: Add generic is_sync() function Kurt Kanzenbach
                   ` (2 preceding siblings ...)
  2022-03-05 11:21 ` [PATCH net-next 3/3] micrel: " Kurt Kanzenbach
@ 2022-03-06  0:07 ` Richard Cochran
  2022-03-07 11:40 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 7+ messages in thread
From: Richard Cochran @ 2022-03-06  0:07 UTC (permalink / raw)
  To: Kurt Kanzenbach
  Cc: David S. Miller, Jakub Kicinski, Andrew Lunn, Heiner Kallweit,
	Russell King, Yonghong Song, Daniel Borkmann, Andrii Nakryiko,
	Divya Koppera, Horatiu Vultur, netdev

On Sat, Mar 05, 2022 at 12:21:24PM +0100, Kurt Kanzenbach wrote:
> Hi,
> 
> as multiple PHY drivers such as micrel or TI dp83640 need to inspect whether a
> given skb represents a PTP Sync message, provide a generic function for it. This
> avoids code duplication and can be reused by future PHY IEEE 1588 implementations.
> 
> Thanks,
> Kurt
> 
> Kurt Kanzenbach (3):
>   ptp: Add generic PTP is_sync() function
>   dp83640: Use generic ptp_msg_is_sync() function
>   micrel: Use generic ptp_msg_is_sync() function

For the series:

Acked-by: Richard Cochran <richardcochran@gmail.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH net-next 3/3] micrel: Use generic ptp_msg_is_sync() function
  2022-03-05 11:21 ` [PATCH net-next 3/3] micrel: " Kurt Kanzenbach
@ 2022-03-07  7:38   ` Divya.Koppera
  0 siblings, 0 replies; 7+ messages in thread
From: Divya.Koppera @ 2022-03-07  7:38 UTC (permalink / raw)
  To: kurt, richardcochran, davem, kuba
  Cc: andrew, hkallweit1, linux, yhs, daniel, andrii, Horatiu.Vultur, netdev

> -----Original Message-----
> From: Kurt Kanzenbach <kurt@linutronix.de>
> Sent: Saturday, March 5, 2022 4:51 PM
> To: Richard Cochran <richardcochran@gmail.com>; David S. Miller
> <davem@davemloft.net>; Jakub Kicinski <kuba@kernel.org>
> Cc: Andrew Lunn <andrew@lunn.ch>; Heiner Kallweit
> <hkallweit1@gmail.com>; Russell King <linux@armlinux.org.uk>; Yonghong
> Song <yhs@fb.com>; Daniel Borkmann <daniel@iogearbox.net>; Andrii
> Nakryiko <andrii@kernel.org>; Divya Koppera - I30481
> <Divya.Koppera@microchip.com>; Horatiu Vultur - M31836
> <Horatiu.Vultur@microchip.com>; netdev@vger.kernel.org; Kurt Kanzenbach
> <kurt@linutronix.de>
> Subject: [PATCH net-next 3/3] micrel: Use generic ptp_msg_is_sync() function
> 
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the
> content is safe
> 
> Use generic ptp_msg_is_sync() function to avoid code duplication.
> 
> Signed-off-by: Kurt Kanzenbach <kurt@linutronix.de>
> ---
>  drivers/net/phy/micrel.c | 13 +------------
>  1 file changed, 1 insertion(+), 12 deletions(-)
> 
> diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index
> 81a76322254c..9e6b29b23935 100644
> --- a/drivers/net/phy/micrel.c
> +++ b/drivers/net/phy/micrel.c
> @@ -1976,17 +1976,6 @@ static int lan8814_hwtstamp(struct
> mii_timestamper *mii_ts, struct ifreq *ifr)
>         return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? -EFAULT : 0;  }
> 
> -static bool is_sync(struct sk_buff *skb, int type) -{
> -       struct ptp_header *hdr;
> -
> -       hdr = ptp_parse_header(skb, type);
> -       if (!hdr)
> -               return false;
> -
> -       return ((ptp_get_msgtype(hdr, type) & 0xf) == 0);
> -}
> -
>  static void lan8814_txtstamp(struct mii_timestamper *mii_ts,
>                              struct sk_buff *skb, int type)  { @@ -1994,7 +1983,7 @@ static
> void lan8814_txtstamp(struct mii_timestamper *mii_ts,
> 
>         switch (ptp_priv->hwts_tx_type) {
>         case HWTSTAMP_TX_ONESTEP_SYNC:
> -               if (is_sync(skb, type)) {
> +               if (ptp_msg_is_sync(skb, type)) {
>                         kfree_skb(skb);
>                         return;
>                 }
> --
> 2.30.2

For the patch:

Tested-and-reviewed-by: Divya Koppera <Divya.Koppera@microchip.com>




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next 0/3] ptp: Add generic is_sync() function
  2022-03-05 11:21 [PATCH net-next 0/3] ptp: Add generic is_sync() function Kurt Kanzenbach
                   ` (3 preceding siblings ...)
  2022-03-06  0:07 ` [PATCH net-next 0/3] ptp: Add generic is_sync() function Richard Cochran
@ 2022-03-07 11:40 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-03-07 11:40 UTC (permalink / raw)
  To: Kurt Kanzenbach
  Cc: richardcochran, davem, kuba, andrew, hkallweit1, linux, yhs,
	daniel, andrii, Divya.Koppera, horatiu.vultur, netdev

Hello:

This series was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:

On Sat,  5 Mar 2022 12:21:24 +0100 you wrote:
> Hi,
> 
> as multiple PHY drivers such as micrel or TI dp83640 need to inspect whether a
> given skb represents a PTP Sync message, provide a generic function for it. This
> avoids code duplication and can be reused by future PHY IEEE 1588 implementations.
> 
> Thanks,
> Kurt
> 
> [...]

Here is the summary with links:
  - [net-next,1/3] ptp: Add generic PTP is_sync() function
    https://git.kernel.org/netdev/net-next/c/f72de02ebece
  - [net-next,2/3] dp83640: Use generic ptp_msg_is_sync() function
    https://git.kernel.org/netdev/net-next/c/1246b229c6e8
  - [net-next,3/3] micrel: Use generic ptp_msg_is_sync() function
    https://git.kernel.org/netdev/net-next/c/3914a9c07e8c

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-03-07 11:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-05 11:21 [PATCH net-next 0/3] ptp: Add generic is_sync() function Kurt Kanzenbach
2022-03-05 11:21 ` [PATCH net-next 1/3] ptp: Add generic PTP " Kurt Kanzenbach
2022-03-05 11:21 ` [PATCH net-next 2/3] dp83640: Use generic ptp_msg_is_sync() function Kurt Kanzenbach
2022-03-05 11:21 ` [PATCH net-next 3/3] micrel: " Kurt Kanzenbach
2022-03-07  7:38   ` Divya.Koppera
2022-03-06  0:07 ` [PATCH net-next 0/3] ptp: Add generic is_sync() function Richard Cochran
2022-03-07 11:40 ` patchwork-bot+netdevbpf

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