From nobody Thu Dec 18 18:53:26 2025 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 804C5C77B71 for ; Sat, 15 Apr 2023 06:46:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229799AbjDOGqG (ORCPT ); Sat, 15 Apr 2023 02:46:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229774AbjDOGqA (ORCPT ); Sat, 15 Apr 2023 02:46:00 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25C7E728A; Fri, 14 Apr 2023 23:45:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681541154; x=1713077154; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WZl572e0Aj7Ti4/ah2gEM5fYLre/3GyIiGhM4yJzXzc=; b=Y4/YrPkWe4Sz7UBBt4G8xEXVb6I73yUsA67fdht1wYv1TVKIzrbK5AXj INZ8hwBDMSc+sWp763Y/lY9sDyweDWEvie0xwpdAgtt+0hjXDwc2BbiNJ Duc31bKTDTeZE+CXddB0yvqeIH30GBhkcy3aV5gx1lryi68INlUbaC8P4 /BbwdFTs3DN303Wh1a2jXqruFkrGUZTOBOsfruYv5UPShfjDCtAIhkeuB 7UGc07dmnVbqFgpkTw+NGeE3o6o/zgNrxhTEveCPlCjPMMyv/hp1FhqGj Eh23Y5Bl+iVOmLbzJSSINYrzHT8XdeoXJnoBE6HbDKL7x+3F1fzxK3+2H w==; X-IronPort-AV: E=McAfee;i="6600,9927,10680"; a="343379293" X-IronPort-AV: E=Sophos;i="5.99,199,1677571200"; d="scan'208";a="343379293" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Apr 2023 23:45:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10680"; a="754727557" X-IronPort-AV: E=Sophos;i="5.99,199,1677571200"; d="scan'208";a="754727557" Received: from p12ill20yoongsia.png.intel.com ([10.88.227.28]) by fmsmga008.fm.intel.com with ESMTP; 14 Apr 2023 23:45:48 -0700 From: Song Yoong Siang To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Stanislav Fomichev , Alexander Duyck , Jesper Dangaard Brouer , Ong Boon Leong , Jacob Keller Cc: netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, xdp-hints@xdp-project.net, Song Yoong Siang Subject: [PATCH net-next v6 2/3] net: stmmac: add Rx HWTS metadata to XDP receive pkt Date: Sat, 15 Apr 2023 14:45:02 +0800 Message-Id: <20230415064503.3225835-3-yoong.siang.song@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230415064503.3225835-1-yoong.siang.song@intel.com> References: <20230415064503.3225835-1-yoong.siang.song@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add receive hardware timestamp metadata support via kfunc to XDP receive packets. Suggested-by: Stanislav Fomichev Signed-off-by: Song Yoong Siang Acked-by: Stanislav Fomichev Acked-by: Jesper Dangaard Brouer --- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 3 ++ .../net/ethernet/stmicro/stmmac/stmmac_main.c | 40 ++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/eth= ernet/stmicro/stmmac/stmmac.h index ac8ccf851708..07ea5ab0a60b 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h @@ -94,6 +94,9 @@ struct stmmac_rx_buffer { =20 struct stmmac_xdp_buff { struct xdp_buff xdp; + struct stmmac_priv *priv; + struct dma_desc *desc; + struct dma_desc *ndesc; }; =20 struct stmmac_rx_queue { diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/ne= t/ethernet/stmicro/stmmac/stmmac_main.c index 10b9f8912bb2..2bfcc5347d6a 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -5313,10 +5313,15 @@ static int stmmac_rx(struct stmmac_priv *priv, int = limit, u32 queue) =20 xdp_init_buff(&ctx.xdp, buf_sz, &rx_q->xdp_rxq); xdp_prepare_buff(&ctx.xdp, page_address(buf->page), - buf->page_offset, buf1_len, false); + buf->page_offset, buf1_len, true); =20 pre_len =3D ctx.xdp.data_end - ctx.xdp.data_hard_start - buf->page_offset; + + ctx.priv =3D priv; + ctx.desc =3D p; + ctx.ndesc =3D np; + skb =3D stmmac_xdp_run_prog(priv, &ctx.xdp); /* Due xdp_adjust_tail: DMA sync for_device * cover max len CPU touch @@ -7060,6 +7065,37 @@ void stmmac_fpe_handshake(struct stmmac_priv *priv, = bool enable) } } =20 +static int stmmac_xdp_rx_timestamp(const struct xdp_md *_ctx, u64 *timesta= mp) +{ + const struct stmmac_xdp_buff *ctx =3D (void *)_ctx; + struct dma_desc *desc_contains_ts =3D ctx->desc; + struct stmmac_priv *priv =3D ctx->priv; + struct dma_desc *ndesc =3D ctx->ndesc; + struct dma_desc *desc =3D ctx->desc; + u64 ns =3D 0; + + if (!priv->hwts_rx_en) + return -ENODATA; + + /* For GMAC4, the valid timestamp is from CTX next desc. */ + if (priv->plat->has_gmac4 || priv->plat->has_xgmac) + desc_contains_ts =3D ndesc; + + /* Check if timestamp is available */ + if (stmmac_get_rx_timestamp_status(priv, desc, ndesc, priv->adv_ts)) { + stmmac_get_timestamp(priv, desc_contains_ts, priv->adv_ts, &ns); + ns -=3D priv->plat->cdc_error_adj; + *timestamp =3D ns_to_ktime(ns); + return 0; + } + + return -ENODATA; +} + +static const struct xdp_metadata_ops stmmac_xdp_metadata_ops =3D { + .xmo_rx_timestamp =3D stmmac_xdp_rx_timestamp, +}; + /** * stmmac_dvr_probe * @device: device pointer @@ -7167,6 +7203,8 @@ int stmmac_dvr_probe(struct device *device, =20 ndev->netdev_ops =3D &stmmac_netdev_ops; =20 + ndev->xdp_metadata_ops =3D &stmmac_xdp_metadata_ops; + ndev->hw_features =3D NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM; ndev->xdp_features =3D NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT | --=20 2.34.1