From patchwork Sat Mar 5 11:21:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kurt Kanzenbach X-Patchwork-Id: 12770323 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9C3FC433F5 for ; Sat, 5 Mar 2022 11:22:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231570AbiCELW4 (ORCPT ); Sat, 5 Mar 2022 06:22:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231565AbiCELWx (ORCPT ); Sat, 5 Mar 2022 06:22:53 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88CD04C431 for ; Sat, 5 Mar 2022 03:22:03 -0800 (PST) From: Kurt Kanzenbach DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1646479321; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UmHdpLQdC9gCELymJWOCuaaDr/7o88IzL8OY0KJQsVY=; b=jaBPa6twSYuwKugnqJdiAsSRWI0OmeM8rRdhLV5fOif1u58uDe1C+lXrv1kDWhAmp4/CDu tV9+SlqIa0CQJ2/cMQAdXyBECRe31UtW9ppXC5hl0T3J+558jwDri0A0J0LV6Sgb4rVhRq +qb86PamBFMqKiPpS4xIkgsyVvxYaW16e2Nsswshx3pVe9+Zm/fbqB2WGFC9b4XcQY3zP2 unEPTXqa+SBUPKMBG5M8qSvSlIuEdCQlVWR5Um33WwHoHODPzom5YQWxrKGuC/VHv3Jeak 7n1MdgmC2F/1OAL3oaTtgfMO830OZdY7RRYqPS+Rx1J5A7Tl7JzHH+DpjkbpUA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1646479321; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UmHdpLQdC9gCELymJWOCuaaDr/7o88IzL8OY0KJQsVY=; b=iu2TBHfSospxLuP40oOTJt5lWdaxwE+EhZPuYDO+WTbfibza9dtsWmkgurR8J6IWFXT8Zb rkm7Zje6tMW13HDg== 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@vger.kernel.org, Kurt Kanzenbach Subject: [PATCH net-next 1/3] ptp: Add generic PTP is_sync() function Date: Sat, 5 Mar 2022 12:21:25 +0100 Message-Id: <20220305112127.68529-2-kurt@linutronix.de> In-Reply-To: <20220305112127.68529-1-kurt@linutronix.de> References: <20220305112127.68529-1-kurt@linutronix.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 --- 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 = { From patchwork Sat Mar 5 11:21:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kurt Kanzenbach X-Patchwork-Id: 12770325 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75840C433EF for ; Sat, 5 Mar 2022 11:22:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231565AbiCELW5 (ORCPT ); Sat, 5 Mar 2022 06:22:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229480AbiCELWx (ORCPT ); Sat, 5 Mar 2022 06:22:53 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88E0F4C786 for ; Sat, 5 Mar 2022 03:22:03 -0800 (PST) From: Kurt Kanzenbach DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1646479322; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WuOENprYDnP+19P9ik900a+QHoS+q8+h0KL/c7di0fQ=; b=UUmwWLsiORnbb2oK97OX7BxEiNhvkMaa+LygOAPM+gGj30AQaxRRprSHO+hrwdB5v+lEQT sUl0kLDELMuByKZ1vuusofcsy6xuV1VtUYXdJXM/sn7OHdV0COBukTYJ9R7yYmRr2Ih8Tj EOJyTHgXth+K5/2sZ1DO92tjlTu8+LF683Dkc1Vsg05j9YYK2RtQe9q4YjdfkCRhs+J/gq 4rilyS1Elq0NaNyDPx8tIZnaAJQfiu2uE1eKq7nb6tbMzRNm9ETuxm+IE5b1am3t7LxAxc 11kK7JFe3BjNYVDoMRrf0bmnEIiPIlEmIIVS5bNf9gX1gnliahLJmbLjElbu5g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1646479322; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WuOENprYDnP+19P9ik900a+QHoS+q8+h0KL/c7di0fQ=; b=FG7vDjbQdqAZbT8TShczqp7mLRvmeDDc3o0NiDhygbH4kJ+crjt89/WziuNEBQ8lpYogzF r2KTnfE8qomO3WAA== 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@vger.kernel.org, Kurt Kanzenbach Subject: [PATCH net-next 2/3] dp83640: Use generic ptp_msg_is_sync() function Date: Sat, 5 Mar 2022 12:21:26 +0100 Message-Id: <20220305112127.68529-3-kurt@linutronix.de> In-Reply-To: <20220305112127.68529-1-kurt@linutronix.de> References: <20220305112127.68529-1-kurt@linutronix.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Use generic ptp_msg_is_sync() function to avoid code duplication. Signed-off-by: Kurt Kanzenbach --- 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; } From patchwork Sat Mar 5 11:21:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kurt Kanzenbach X-Patchwork-Id: 12770324 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65A64C433F5 for ; Sat, 5 Mar 2022 11:22:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231572AbiCELW5 (ORCPT ); Sat, 5 Mar 2022 06:22:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231510AbiCELWy (ORCPT ); Sat, 5 Mar 2022 06:22:54 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09FD54C789 for ; Sat, 5 Mar 2022 03:22:04 -0800 (PST) From: Kurt Kanzenbach DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1646479322; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WZOt6spQRcdebq/mtE9uDiTLJIwxzfTlt+Y7JO6aRms=; b=j+XZVfex0HCqPgGUqE3RkfXAh1px2VN/yRNNMvyezAd/IFdSihNmbSrKLlFEcU82iA7QPi esnfeLP4YzqapZ/rhZ0JL5NbJWnDHfm7o9GQuT2t3RGSgdZvS5/9WjxQluETpoT289DjOG QNUujrPPzP2sBDlByXqZaP2t77LAQja/9EJQvaNSJLpKm7dT3rNCvekN7xHyqR64FyReab btc5FcQYHD9OeEG6kXF5/yK1xYep6ixN+ONK203W8D17JVpjnwSPKhdztMYesYf02EAYZM J8L+6n2fhWrJuSiTWO5oN9l3fjQ5Ajz8NaVdS/5tJQ+x5JhNMcWq/FdeX1uc5w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1646479322; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WZOt6spQRcdebq/mtE9uDiTLJIwxzfTlt+Y7JO6aRms=; b=jkDYF/hKURac8vP8oJhSeB2tVsDQ88QMev7ROIMNsY47OcKZH86ho0bgtuzcO+7AhGYdj/ iHEzT0aRdmNcg5AA== 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@vger.kernel.org, Kurt Kanzenbach Subject: [PATCH net-next 3/3] micrel: Use generic ptp_msg_is_sync() function Date: Sat, 5 Mar 2022 12:21:27 +0100 Message-Id: <20220305112127.68529-4-kurt@linutronix.de> In-Reply-To: <20220305112127.68529-1-kurt@linutronix.de> References: <20220305112127.68529-1-kurt@linutronix.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Use generic ptp_msg_is_sync() function to avoid code duplication. Signed-off-by: Kurt Kanzenbach --- 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; }