From: Frank Li <Frank.li@nxp.com>
To: Wei Fang <wei.fang@nxp.com>
Cc: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
richardcochran@gmail.com, claudiu.manoil@nxp.com,
vladimir.oltean@nxp.com, xiaoning.wang@nxp.com,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, vadim.fedorenko@linux.dev,
shawnguo@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com,
fushi.peng@nxp.com, devicetree@vger.kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
imx@lists.linux.dev, kernel@pengutronix.de
Subject: Re: [PATCH v3 net-next 10/15] net: enetc: save the parsed information of PTP packet to skb->cb
Date: Tue, 12 Aug 2025 11:45:37 -0400 [thread overview]
Message-ID: <aJthobCLg3E/lCzV@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20250812094634.489901-11-wei.fang@nxp.com>
On Tue, Aug 12, 2025 at 05:46:29PM +0800, Wei Fang wrote:
> Currently, the Tx PTP packets are parsed twice in the enetc driver, once
> in enetc_xmit() and once in enetc_map_tx_buffs(). The latter is duplicate
> and is unnecessary, since the parsed information can be saved to skb->cb
> so that enetc_map_tx_buffs() can get the previously parsed data from
> skb->cb. Therefore, add struct enetc_skb_cb as the format of the data
> in the skb->cb buffer to save the parsed information of PTP packet. Use
> saved information in enetc_map_tx_buffs() to avoid parsing data again.
>
> In addition, rename variables offset1 and offset2 in enetc_map_tx_buffs()
> to corr_off and tstamp_off for better readability.
>
> Signed-off-by: Wei Fang <wei.fang@nxp.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
>
> ---
> v2 changes:
> 1. Add description of offset1 and offset2 being renamed in the commit
> message.
> v3 changes:
> 1. Improve the commit message
> 2. Fix the error the patch, there were two "++" in the patch
> ---
> drivers/net/ethernet/freescale/enetc/enetc.c | 65 ++++++++++----------
> drivers/net/ethernet/freescale/enetc/enetc.h | 9 +++
> 2 files changed, 43 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c
> index e4287725832e..54ccd7c57961 100644
> --- a/drivers/net/ethernet/freescale/enetc/enetc.c
> +++ b/drivers/net/ethernet/freescale/enetc/enetc.c
> @@ -225,13 +225,12 @@ static int enetc_map_tx_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb)
> {
> bool do_vlan, do_onestep_tstamp = false, do_twostep_tstamp = false;
> struct enetc_ndev_priv *priv = netdev_priv(tx_ring->ndev);
> + struct enetc_skb_cb *enetc_cb = ENETC_SKB_CB(skb);
> struct enetc_hw *hw = &priv->si->hw;
> struct enetc_tx_swbd *tx_swbd;
> int len = skb_headlen(skb);
> union enetc_tx_bd temp_bd;
> - u8 msgtype, twostep, udp;
> union enetc_tx_bd *txbd;
> - u16 offset1, offset2;
> int i, count = 0;
> skb_frag_t *frag;
> unsigned int f;
> @@ -280,16 +279,10 @@ static int enetc_map_tx_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb)
> count++;
>
> do_vlan = skb_vlan_tag_present(skb);
> - if (skb->cb[0] & ENETC_F_TX_ONESTEP_SYNC_TSTAMP) {
> - if (enetc_ptp_parse(skb, &udp, &msgtype, &twostep, &offset1,
> - &offset2) ||
> - msgtype != PTP_MSGTYPE_SYNC || twostep)
> - WARN_ONCE(1, "Bad packet for one-step timestamping\n");
> - else
> - do_onestep_tstamp = true;
> - } else if (skb->cb[0] & ENETC_F_TX_TSTAMP) {
> + if (enetc_cb->flag & ENETC_F_TX_ONESTEP_SYNC_TSTAMP)
> + do_onestep_tstamp = true;
> + else if (enetc_cb->flag & ENETC_F_TX_TSTAMP)
> do_twostep_tstamp = true;
> - }
>
> tx_swbd->do_twostep_tstamp = do_twostep_tstamp;
> tx_swbd->qbv_en = !!(priv->active_offloads & ENETC_F_QBV);
> @@ -333,6 +326,8 @@ static int enetc_map_tx_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb)
> }
>
> if (do_onestep_tstamp) {
> + u16 tstamp_off = enetc_cb->origin_tstamp_off;
> + u16 corr_off = enetc_cb->correction_off;
> __be32 new_sec_l, new_nsec;
> u32 lo, hi, nsec, val;
> __be16 new_sec_h;
> @@ -362,32 +357,32 @@ static int enetc_map_tx_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb)
> new_sec_h = htons((sec >> 32) & 0xffff);
> new_sec_l = htonl(sec & 0xffffffff);
> new_nsec = htonl(nsec);
> - if (udp) {
> + if (enetc_cb->udp) {
> struct udphdr *uh = udp_hdr(skb);
> __be32 old_sec_l, old_nsec;
> __be16 old_sec_h;
>
> - old_sec_h = *(__be16 *)(data + offset2);
> + old_sec_h = *(__be16 *)(data + tstamp_off);
> inet_proto_csum_replace2(&uh->check, skb, old_sec_h,
> new_sec_h, false);
>
> - old_sec_l = *(__be32 *)(data + offset2 + 2);
> + old_sec_l = *(__be32 *)(data + tstamp_off + 2);
> inet_proto_csum_replace4(&uh->check, skb, old_sec_l,
> new_sec_l, false);
>
> - old_nsec = *(__be32 *)(data + offset2 + 6);
> + old_nsec = *(__be32 *)(data + tstamp_off + 6);
> inet_proto_csum_replace4(&uh->check, skb, old_nsec,
> new_nsec, false);
> }
>
> - *(__be16 *)(data + offset2) = new_sec_h;
> - *(__be32 *)(data + offset2 + 2) = new_sec_l;
> - *(__be32 *)(data + offset2 + 6) = new_nsec;
> + *(__be16 *)(data + tstamp_off) = new_sec_h;
> + *(__be32 *)(data + tstamp_off + 2) = new_sec_l;
> + *(__be32 *)(data + tstamp_off + 6) = new_nsec;
>
> /* Configure single-step register */
> val = ENETC_PM0_SINGLE_STEP_EN;
> - val |= ENETC_SET_SINGLE_STEP_OFFSET(offset1);
> - if (udp)
> + val |= ENETC_SET_SINGLE_STEP_OFFSET(corr_off);
> + if (enetc_cb->udp)
> val |= ENETC_PM0_SINGLE_STEP_CH;
>
> enetc_port_mac_wr(priv->si, ENETC_PM0_SINGLE_STEP,
> @@ -938,12 +933,13 @@ static int enetc_map_tx_tso_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb
> static netdev_tx_t enetc_start_xmit(struct sk_buff *skb,
> struct net_device *ndev)
> {
> + struct enetc_skb_cb *enetc_cb = ENETC_SKB_CB(skb);
> struct enetc_ndev_priv *priv = netdev_priv(ndev);
> struct enetc_bdr *tx_ring;
> int count;
>
> /* Queue one-step Sync packet if already locked */
> - if (skb->cb[0] & ENETC_F_TX_ONESTEP_SYNC_TSTAMP) {
> + if (enetc_cb->flag & ENETC_F_TX_ONESTEP_SYNC_TSTAMP) {
> if (test_and_set_bit_lock(ENETC_TX_ONESTEP_TSTAMP_IN_PROGRESS,
> &priv->flags)) {
> skb_queue_tail(&priv->tx_skbs, skb);
> @@ -1005,24 +1001,29 @@ static netdev_tx_t enetc_start_xmit(struct sk_buff *skb,
>
> netdev_tx_t enetc_xmit(struct sk_buff *skb, struct net_device *ndev)
> {
> + struct enetc_skb_cb *enetc_cb = ENETC_SKB_CB(skb);
> struct enetc_ndev_priv *priv = netdev_priv(ndev);
> u8 udp, msgtype, twostep;
> u16 offset1, offset2;
>
> - /* Mark tx timestamp type on skb->cb[0] if requires */
> + /* Mark tx timestamp type on enetc_cb->flag if requires */
> if ((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
> - (priv->active_offloads & ENETC_F_TX_TSTAMP_MASK)) {
> - skb->cb[0] = priv->active_offloads & ENETC_F_TX_TSTAMP_MASK;
> - } else {
> - skb->cb[0] = 0;
> - }
> + (priv->active_offloads & ENETC_F_TX_TSTAMP_MASK))
> + enetc_cb->flag = priv->active_offloads & ENETC_F_TX_TSTAMP_MASK;
> + else
> + enetc_cb->flag = 0;
>
> /* Fall back to two-step timestamp if not one-step Sync packet */
> - if (skb->cb[0] & ENETC_F_TX_ONESTEP_SYNC_TSTAMP) {
> + if (enetc_cb->flag & ENETC_F_TX_ONESTEP_SYNC_TSTAMP) {
> if (enetc_ptp_parse(skb, &udp, &msgtype, &twostep,
> &offset1, &offset2) ||
> - msgtype != PTP_MSGTYPE_SYNC || twostep != 0)
> - skb->cb[0] = ENETC_F_TX_TSTAMP;
> + msgtype != PTP_MSGTYPE_SYNC || twostep != 0) {
> + enetc_cb->flag = ENETC_F_TX_TSTAMP;
> + } else {
> + enetc_cb->udp = !!udp;
> + enetc_cb->correction_off = offset1;
> + enetc_cb->origin_tstamp_off = offset2;
> + }
> }
>
> return enetc_start_xmit(skb, ndev);
> @@ -1214,7 +1215,9 @@ static bool enetc_clean_tx_ring(struct enetc_bdr *tx_ring, int napi_budget)
> if (xdp_frame) {
> xdp_return_frame(xdp_frame);
> } else if (skb) {
> - if (unlikely(skb->cb[0] & ENETC_F_TX_ONESTEP_SYNC_TSTAMP)) {
> + struct enetc_skb_cb *enetc_cb = ENETC_SKB_CB(skb);
> +
> + if (unlikely(enetc_cb->flag & ENETC_F_TX_ONESTEP_SYNC_TSTAMP)) {
> /* Start work to release lock for next one-step
> * timestamping packet. And send one skb in
> * tx_skbs queue if has.
> diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h
> index 62e8ee4d2f04..ce3fed95091b 100644
> --- a/drivers/net/ethernet/freescale/enetc/enetc.h
> +++ b/drivers/net/ethernet/freescale/enetc/enetc.h
> @@ -54,6 +54,15 @@ struct enetc_tx_swbd {
> u8 qbv_en:1;
> };
>
> +struct enetc_skb_cb {
> + u8 flag;
> + bool udp;
> + u16 correction_off;
> + u16 origin_tstamp_off;
> +};
> +
> +#define ENETC_SKB_CB(skb) ((struct enetc_skb_cb *)((skb)->cb))
> +
> struct enetc_lso_t {
> bool ipv6;
> bool tcp;
> --
> 2.34.1
>
next prev parent reply other threads:[~2025-08-12 15:45 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-12 9:46 [PATCH v3 net-next 00/15] Add NETC Timer PTP driver and add PTP support for i.MX95 Wei Fang
2025-08-12 9:46 ` [PATCH v3 net-next 01/15] dt-bindings: ptp: add NETC Timer PTP clock Wei Fang
2025-08-12 14:36 ` Frank Li
2025-08-14 8:25 ` Krzysztof Kozlowski
2025-08-14 18:50 ` Frank Li
2025-08-15 6:05 ` Krzysztof Kozlowski
2025-08-15 18:11 ` Frank Li
2025-08-15 2:05 ` Wei Fang
2025-08-12 9:46 ` [PATCH v3 net-next 02/15] dt-bindings: net: add ptp-timer property Wei Fang
2025-08-12 11:18 ` Vladimir Oltean
2025-08-12 14:40 ` Frank Li
2025-08-14 8:27 ` Krzysztof Kozlowski
2025-08-12 9:46 ` [PATCH v3 net-next 03/15] dt-bindings: net: add an example for ENETC v4 Wei Fang
2025-08-12 14:38 ` Frank Li
2025-08-13 1:38 ` Wei Fang
2025-08-13 15:10 ` Frank Li
2025-08-14 1:34 ` Wei Fang
2025-08-14 8:29 ` Krzysztof Kozlowski
2025-08-12 9:46 ` [PATCH v3 net-next 04/15] ptp: netc: add NETC V4 Timer PTP driver support Wei Fang
2025-08-12 13:49 ` Vladimir Oltean
2025-08-13 2:21 ` Wei Fang
2025-08-12 15:01 ` Frank Li
2025-08-13 1:46 ` Wei Fang
2025-08-15 18:13 ` Frank Li
2025-08-13 4:45 ` kernel test robot
2025-08-12 9:46 ` [PATCH v3 net-next 05/15] ptp: netc: add PTP_CLK_REQ_PPS support Wei Fang
2025-08-12 15:11 ` Frank Li
2025-08-13 1:59 ` Wei Fang
2025-08-13 15:06 ` Frank Li
2025-08-14 2:22 ` Wei Fang
2025-08-12 9:46 ` [PATCH v3 net-next 06/15] ptp: netc: add periodic pulse output support Wei Fang
2025-08-12 12:03 ` Vladimir Oltean
2025-08-13 1:42 ` Wei Fang
2025-08-12 15:24 ` Frank Li
2025-08-13 2:35 ` kernel test robot
2025-08-12 9:46 ` [PATCH v3 net-next 07/15] ptp: netc: add external trigger stamp support Wei Fang
2025-08-12 15:27 ` Frank Li
2025-08-12 9:46 ` [PATCH v3 net-next 08/15] ptp: netc: add debugfs support to loop back pulse signal Wei Fang
2025-08-12 15:42 ` Frank Li
2025-08-12 9:46 ` [PATCH v3 net-next 09/15] MAINTAINERS: add NETC Timer PTP clock driver section Wei Fang
2025-08-12 9:46 ` [PATCH v3 net-next 10/15] net: enetc: save the parsed information of PTP packet to skb->cb Wei Fang
2025-08-12 15:45 ` Frank Li [this message]
2025-08-12 9:46 ` [PATCH v3 net-next 11/15] net: enetc: extract enetc_update_ptp_sync_msg() to handle PTP Sync packets Wei Fang
2025-08-12 15:52 ` Frank Li
2025-08-13 2:04 ` Wei Fang
2025-08-12 9:46 ` [PATCH v3 net-next 12/15] net: enetc: remove unnecessary CONFIG_FSL_ENETC_PTP_CLOCK check Wei Fang
2025-08-12 9:46 ` [PATCH v3 net-next 13/15] net: enetc: add PTP synchronization support for ENETC v4 Wei Fang
2025-08-12 15:58 ` Frank Li
2025-08-13 2:17 ` Wei Fang
2025-08-13 14:55 ` Frank Li
2025-08-12 9:46 ` [PATCH v3 net-next 14/15] net: enetc: don't update sync packet checksum if checksum offload is used Wei Fang
2025-08-12 9:46 ` [PATCH v3 15/15] arm64: dts: imx95: add standard PCI device compatible string to NETC Timer Wei Fang
2025-08-12 15:59 ` Frank Li
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=aJthobCLg3E/lCzV@lizhi-Precision-Tower-5810 \
--to=frank.li@nxp.com \
--cc=andrew+netdev@lunn.ch \
--cc=claudiu.manoil@nxp.com \
--cc=conor+dt@kernel.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=festevam@gmail.com \
--cc=fushi.peng@nxp.com \
--cc=imx@lists.linux.dev \
--cc=kernel@pengutronix.de \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=robh@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=vadim.fedorenko@linux.dev \
--cc=vladimir.oltean@nxp.com \
--cc=wei.fang@nxp.com \
--cc=xiaoning.wang@nxp.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).