From patchwork Wed Apr 12 09:42:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Song, Yoong Siang" X-Patchwork-Id: 13208698 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 57E6FC7619A for ; Wed, 12 Apr 2023 09:44:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=bX5tnELbJxKn+qPDU/DB5p6IXEyAG7dIf+GgY8iEDp0=; b=mleQfWSZOKUvxo F0nijTZeYxfWBoW+2+Pwq1MZ8dZXWS8YYpGQgs4pekAC8oOF7dXot72ZfdvYkFhXxxVyhU5pf7upG U1rXALpTUkbM7TM0NH3tglbqKMekaFnyfjQ7hHJa3v+Q+H7VBQo8NpOc7wwHPANKaK/xIuH/Y5XIL ucy6NFDZpQUJlnJRJA8e2PafRFSdF5WgBhMr9Q1KjrCvhnjG3T+n7s2Y/I9MthCQeJEV3W0044T6J mjCZFbCHKT8UzfFDynpNDJ6QjphEZkb65racknbtoa6uUHZr9/KEZHW940PRpFfMm1lmrF4Bfs0k6 l0cuMTdSIzY3V/zCPyYA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pmX0s-002RdE-0n; Wed, 12 Apr 2023 09:43:38 +0000 Received: from mga03.intel.com ([134.134.136.65]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pmX0p-002RaA-2f for linux-arm-kernel@lists.infradead.org; Wed, 12 Apr 2023 09:43:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681292615; x=1712828615; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mhGhk0aFNDU+nvi/Zr0WQsY6I/0lnGV4GKGpzNN0N7A=; b=QfWyPB3qu+tqUp8MCMpyw6hcZC74zAxegTIS9EapkX9oYKnwQ3CpSnlF C5ZGKfYcncWwfUUZlYHe6Wn76zaWlyZGcQRXz0J2a8UvDGZbwHFuUGFi8 E32xMa3adpGTbJWCXYB1gIyz+va1+IL5P785MUcFokk9CAr4n2zIt6dFJ 2ForOI+jGJCSk4J1TutWcsj/0LWlGKTakU+Ky2XvSUKW1qtuo0Mt2bCIO D0xADHVLzBsf2SP9a5NIODKwTelwAeZXoofVQVJx8MbuvXjg7QGPQ0XzA T5wkQeMEv2e2MGZXio7wkQ2nEhtckNxzzX803ZusjGnOwJ6AUlp+TfFv6 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10677"; a="346526432" X-IronPort-AV: E=Sophos;i="5.98,338,1673942400"; d="scan'208";a="346526432" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2023 02:43:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10677"; a="682430956" X-IronPort-AV: E=Sophos;i="5.98,338,1673942400"; d="scan'208";a="682430956" Received: from p12ill20yoongsia.png.intel.com ([10.88.227.28]) by orsmga007.jf.intel.com with ESMTP; 12 Apr 2023 02:43:30 -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 , Ong Boon Leong 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 v3 3/4] net: stmmac: add Rx HWTS metadata to XDP receive pkt Date: Wed, 12 Apr 2023 17:42:34 +0800 Message-Id: <20230412094235.589089-4-yoong.siang.song@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412094235.589089-1-yoong.siang.song@intel.com> References: <20230412094235.589089-1-yoong.siang.song@intel.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230412_024335_926287_2CC24275 X-CRM114-Status: GOOD ( 13.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add receive hardware timestamp metadata support via kfunc to XDP receive packets. Suggested-by: Stanislav Fomichev Signed-off-by: Song Yoong Siang --- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 3 +++ .../net/ethernet/stmicro/stmmac/stmmac_main.c | 26 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h index ac8ccf851708..826ac0ec88c6 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 { struct stmmac_xdp_buff { struct xdp_buff xdp; + struct stmmac_priv *priv; + struct dma_desc *p; + struct dma_desc *np; }; struct stmmac_rx_queue { diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index f7bbdf04d20c..ed660927b628 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -5315,10 +5315,15 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) 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); pre_len = ctx.xdp.data_end - ctx.xdp.data_hard_start - buf->page_offset; + + ctx.priv = priv; + ctx.p = p; + ctx.np = np; + skb = stmmac_xdp_run_prog(priv, &ctx.xdp); /* Due xdp_adjust_tail: DMA sync for_device * cover max len CPU touch @@ -7071,6 +7076,23 @@ void stmmac_fpe_handshake(struct stmmac_priv *priv, bool enable) } } +static int stmmac_xdp_rx_timestamp(const struct xdp_md *_ctx, u64 *timestamp) +{ + const struct stmmac_xdp_buff *ctx = (void *)_ctx; + + *timestamp = 0; + stmmac_get_rx_hwtstamp(ctx->priv, ctx->p, ctx->np, timestamp); + + if (*timestamp) + return 0; + + return -ENODATA; +} + +static const struct xdp_metadata_ops stmmac_xdp_metadata_ops = { + .xmo_rx_timestamp = stmmac_xdp_rx_timestamp, +}; + /** * stmmac_dvr_probe * @device: device pointer @@ -7178,6 +7200,8 @@ int stmmac_dvr_probe(struct device *device, ndev->netdev_ops = &stmmac_netdev_ops; + ndev->xdp_metadata_ops = &stmmac_xdp_metadata_ops; + ndev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM; ndev->xdp_features = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT |