From: Vadim Fedorenko <vfedorenko@novek.ru>
To: Wei Fang <wei.fang@nxp.com>,
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
Cc: fushi.peng@nxp.com, devicetree@vger.kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
imx@lists.linux.dev
Subject: Re: [PATCH net-next 08/12] net: enetc: save the parsed information of PTP packet to skb->cb
Date: Sat, 12 Jul 2025 11:54:16 +0100 [thread overview]
Message-ID: <40a32a8b-11d4-48fb-b626-66239a4797a5@novek.ru> (raw)
In-Reply-To: <20250711065748.250159-9-wei.fang@nxp.com>
On 11.07.2025 07:57, 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, we add struct enetc_skb_cb as the format of the data
> in the skb->cb buffer to save the parsed information of PTP packet.
>
> Signed-off-by: Wei Fang <wei.fang@nxp.com>
> ---
> 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..c1373163a096 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;
This looks like merge conflict artifact...
>
> /* 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;
next prev parent reply other threads:[~2025-07-12 10:54 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-11 6:57 [PATCH net-next 00/12] Add NETC Timer PTP driver and add PTP support for ENETC v4 Wei Fang
2025-07-11 6:57 ` [PATCH net-next 01/12] dt-bindings: ptp: add bindings for NETC Timer Wei Fang
2025-07-11 13:27 ` Andrew Lunn
2025-07-14 2:32 ` Wei Fang
2025-07-14 5:51 ` Krzysztof Kozlowski
2025-07-14 7:32 ` Wei Fang
2025-07-14 7:35 ` Krzysztof Kozlowski
2025-07-14 9:11 ` Wei Fang
2025-07-14 9:14 ` Krzysztof Kozlowski
2025-07-14 9:56 ` Wei Fang
2025-07-14 10:09 ` Krzysztof Kozlowski
2025-07-14 10:20 ` Krzysztof Kozlowski
2025-07-14 10:30 ` Wei Fang
2025-07-14 10:28 ` Wei Fang
2025-07-14 10:31 ` Vladimir Oltean
2025-07-14 10:43 ` Wei Fang
2025-07-14 11:37 ` Vladimir Oltean
2025-07-14 13:22 ` Wei Fang
2025-07-14 13:56 ` Vladimir Oltean
2025-07-14 14:14 ` Vladimir Oltean
2025-07-15 2:52 ` Wei Fang
2025-07-15 7:02 ` Vladimir Oltean
2025-07-15 7:11 ` Wei Fang
2025-07-14 11:24 ` Krzysztof Kozlowski
2025-07-14 13:43 ` Wei Fang
2025-07-14 14:04 ` Krzysztof Kozlowski
2025-07-11 6:57 ` [PATCH net-next 02/12] ptp: netc: add NETC Timer PTP driver support Wei Fang
2025-07-11 13:25 ` Andrew Lunn
2025-07-14 2:29 ` Wei Fang
2025-07-12 10:43 ` Vadim Fedorenko
2025-07-14 2:57 ` Wei Fang
2025-07-12 11:53 ` kernel test robot
2025-07-14 5:55 ` Krzysztof Kozlowski
2025-07-14 10:11 ` Wei Fang
2025-07-11 6:57 ` [PATCH net-next 03/12] ptp: netc: add PPS support Wei Fang
2025-07-12 16:00 ` kernel test robot
2025-07-11 6:57 ` [PATCH net-next 04/12] ptp: netc: add periodic pulse output support Wei Fang
2025-07-11 6:57 ` [PATCH net-next 05/12] ptp: netc: add external trigger stamp support Wei Fang
2025-07-11 6:57 ` [PATCH net-next 06/12] ptp: netc: add debugfs support to loop back pulse signal Wei Fang
2025-07-11 13:33 ` Andrew Lunn
2025-07-14 2:33 ` Wei Fang
2025-07-11 6:57 ` [PATCH net-next 07/12] MAINTAINERS: add NETC Timer PTP clock driver section Wei Fang
2025-07-11 6:57 ` [PATCH net-next 08/12] net: enetc: save the parsed information of PTP packet to skb->cb Wei Fang
2025-07-12 10:54 ` Vadim Fedorenko [this message]
2025-07-14 3:07 ` Wei Fang
2025-07-11 6:57 ` [PATCH net-next 09/12] net: enetc: Add enetc_update_ptp_sync_msg() to process PTP sync packet Wei Fang
2025-07-12 10:58 ` Vadim Fedorenko
2025-07-11 6:57 ` [PATCH net-next 10/12] net: enetc: remove unnecessary CONFIG_FSL_ENETC_PTP_CLOCK check Wei Fang
2025-07-12 11:29 ` Vadim Fedorenko
2025-07-11 6:57 ` [PATCH net-next 11/12] net: enetc: add PTP synchronization support for ENETC v4 Wei Fang
2025-07-12 16:42 ` kernel test robot
2025-07-11 6:57 ` [PATCH net-next 12/12] net: enetc: don't update sync packet checksum if checksum offload is used Wei Fang
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=40a32a8b-11d4-48fb-b626-66239a4797a5@novek.ru \
--to=vfedorenko@novek.ru \
--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=fushi.peng@nxp.com \
--cc=imx@lists.linux.dev \
--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=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).