Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1847915rwl; Wed, 12 Apr 2023 20:32:16 -0700 (PDT) X-Google-Smtp-Source: AKy350ajHix2hlh88LzUmHBbKQfxtzG6zbKuFuu0AskZbiEokU0E/EhPz/xW9gAwoSF9AyYkEOkM X-Received: by 2002:a17:906:844e:b0:92f:924b:e8f4 with SMTP id e14-20020a170906844e00b0092f924be8f4mr1120003ejy.4.1681356736089; Wed, 12 Apr 2023 20:32:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681356736; cv=none; d=google.com; s=arc-20160816; b=m+HpRyThdwEutCTBTIuE5yN/gzUWg9XDCH+gNx0w7IzQXLs4bjq+YSXZkaPRg/1x4m DuO9sfqcnZYCYYDKDMicc8oUmN4AHa4P3I5H4lriFck3X99EKGSbPJRouvr+ulkunuXH Bfvug5BIHdZtBkqMAPI5WLZpMSbUGE9dkx72Mqy6g6Vcb6p3aGW6d3tkn4kAs4dXydiI D5C5ByFhMGXAKKtghTh07SLwv+fe4EmZtZujNcMRAS7CVi3X6y/vOWIoPoTQ+MY6lwEW dMO4kBh26E0C34NhkMXrJGN5YIFNVNI5K2/oifz4XezQ4c+rQFWhl73xmxiJYbYAv5Up 0dwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VRa/DTmQavB9+sgJbw4iP/c84d2R5vjDx/dXA/ywuEE=; b=AEKqY3cHx+m7mcYqH/I8Chqlc7JxnT/f0sryCHZdmUKj4WuBzWm2rejA2BGXwt+J/M r+ekQuO4Yf0jn/0WVqMOOzvSB6mTkMMc55f/fdrD+txiu81Q4IpZ2nuIXGDv+bYfbATh 9kbPnsSO9NjLcz5viKoZH1eDCLzJR3etHGlww4e1GE6P3tbfuY41yHGumJLcGaW9GaNc TCdF2v9X8sehdmrWkle8Yp9jxTPtcZhs8b9u++4KIexk6rhIVHDY6tUtPfrgehhySd8E F3ow6r95rCBTksw+NMkozGZwnrAMVUKFP0thesOdkpiI63D338fd4eQ9NhO+O/T/5wmA GKTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=brhemA7L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id az17-20020a170907905100b0093b06c911aasi653258ejc.463.2023.04.12.20.31.51; Wed, 12 Apr 2023 20:32:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=brhemA7L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229599AbjDMD06 (ORCPT + 99 others); Wed, 12 Apr 2023 23:26:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229838AbjDMD0q (ORCPT ); Wed, 12 Apr 2023 23:26:46 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 478A183D8; Wed, 12 Apr 2023 20:26:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1681356398; x=1712892398; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TbjWbgkXZyRJmhXzWEr6PAioc/rwjJEJL/AlqKlt9RE=; b=brhemA7LyTaiDSwxujiwecjnYdjjl86ek+AdBtecLESPgcr9LuHutfys Z6uoinlaBFt6lNabEaSaGAas2rXX2a2O7WhGnP1bZPnMfPBXnDAVAnY/0 2Mv2pBY2cFjiZdAWn7OZ3vyNhh0R/fgWm0ByaLsb/YZKplcwzA2IigJCY 29uxbfEIIpgXE8q3Ed+AzCgsWDflc6v+8IcVA/G3bSzAjC/X5AG+51h6U 8kuX3AdbMavu/T7xINGQtf9eZGjFyzfMzFF47PKL0Z9d0gF52kFgDPaIf h9mhjOnkS5flM9Ev9gq1n6zefjxf12ZnLQHT2l13tQX0gTLAkT3N+qHV9 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10678"; a="332781681" X-IronPort-AV: E=Sophos;i="5.98,339,1673942400"; d="scan'208";a="332781681" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2023 20:26:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10678"; a="800597050" X-IronPort-AV: E=Sophos;i="5.98,339,1673942400"; d="scan'208";a="800597050" Received: from p12ill20yoongsia.png.intel.com ([10.88.227.28]) by fmsmga002.fm.intel.com with ESMTP; 12 Apr 2023 20:26:25 -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 v4 2/3] net: stmmac: add Rx HWTS metadata to XDP receive pkt Date: Thu, 13 Apr 2023 11:25:40 +0800 Message-Id: <20230413032541.885238-3-yoong.siang.song@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230413032541.885238-1-yoong.siang.song@intel.com> References: <20230413032541.885238-1-yoong.siang.song@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 | 40 ++++++++++++++++++- 2 files changed, 42 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 6ffce52ca837..831a3e22e0d8 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) 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 @@ -7060,6 +7065,37 @@ 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; + struct stmmac_priv *priv = ctx->priv; + struct dma_desc *desc = ctx->p; + struct dma_desc *np = ctx->np; + struct dma_desc *p = ctx->p; + u64 ns = 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 = np; + + /* Check if timestamp is available */ + if (stmmac_get_rx_timestamp_status(priv, p, np, priv->adv_ts)) { + stmmac_get_timestamp(priv, desc, priv->adv_ts, &ns); + ns -= priv->plat->cdc_error_adj; + *timestamp = ns_to_ktime(ns); + 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 @@ -7167,6 +7203,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 | -- 2.34.1