From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by mail.toke.dk (Postfix) with ESMTPS id 17FAA9C45C6 for ; Mon, 21 Nov 2022 19:26:07 +0100 (CET) Authentication-Results: mail.toke.dk; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=hbR+Vdv0 Received: by mail-pg1-x54a.google.com with SMTP id 186-20020a6301c3000000b0046fa202f720so7320811pgb.20 for ; Mon, 21 Nov 2022 10:26:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=pgA8r6q+vHqw+YrYOl3aP+dNQ95F67luBXwFSR2T9OY=; b=hbR+Vdv0kdy8wD7qfjR+qjrEvtkWb5nrEFaFlg28TgCv4WVOMdFGkmCXsEn/M+HnOz ncaJfwM2yKCRhfmoQZ3IeagvNaNrnjSoB8O4PxgEvS4DkTBVPaYJoMnQspR9PPga21zm 1Wi/+eN6rz26LJkaMY63IIWuNJBXRb4AU6kKZwMqUDr5A8htVNKHRuAoBtCSXbhZUwIY oDyc5KyTIWFCoPRiLEbvz4MRH/up9wZ8fI6lvIGokdb8elM/fPnQLEZcLFagO628craY BGfqcIGoeAuEL5+CUJgHXbtNLGCJPPOrKFvcirLDNX78dWvV69yLu4wXotUmJiAVXLQM IlrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pgA8r6q+vHqw+YrYOl3aP+dNQ95F67luBXwFSR2T9OY=; b=4kLVr7HRTWbNqnosjwxY7TO5Yx+zqnjVKgssSyq7ljucFg5Ula+vNwyMDnBUmb6hBa 2pIttBhS9nSaVpUGtabtg9Wpkj0hn0eeESURoHlCHXb/gA/eOoWEN/x4a9vV+Vd5t4e9 sxBgZjk5hxQQ9cuHt3KoLJHOYHlrlYXdoHvvsgRyr/h3MjlpE2DxTUZQr8adnxpPADgQ kFxtxnh4MWKD6OIVlUx18sn2pVklo3TRyknPITwzQ31abv+z4ECDWRbW2qKx9BITTWFG yzngnevM7q90dtQYNNT+z3RUY6d3i09v2P5uVVoPvkEWIyp6oHm2JJZhy1etFgHk/5el xmdw== X-Gm-Message-State: ANoB5pkd5b3uoDcM1q6L2i8+AwFpkE1I5yEco2ozPjYed3KoJkPNE121 JMAn8OTOYuG88r9vWMFP5MJk0zs= X-Google-Smtp-Source: AA0mqf7n2thXFA68LqvTVLbekOytw+rcf5+iC2F8qRSb4JAMHqx5uoXQ/b2Fe+aTVqOn2NwBeTq8XCE= X-Received: from sdf.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5935]) (user=sdf job=sendgmr) by 2002:aa7:8709:0:b0:572:2189:84ef with SMTP id b9-20020aa78709000000b00572218984efmr923589pfo.28.1669055166038; Mon, 21 Nov 2022 10:26:06 -0800 (PST) Date: Mon, 21 Nov 2022 10:25:51 -0800 In-Reply-To: <20221121182552.2152891-1-sdf@google.com> Mime-Version: 1.0 References: <20221121182552.2152891-1-sdf@google.com> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog Message-ID: <20221121182552.2152891-8-sdf@google.com> From: Stanislav Fomichev To: bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Message-ID-Hash: OPNN44JIPETMOZTDWLRT3VFYDQJJNAPD X-Message-ID-Hash: OPNN44JIPETMOZTDWLRT3VFYDQJJNAPD X-MailFrom: 3vsJ7YwMKCVUF023BB381.zB9K0C-45AGFK0C-CEB61zG.A1G@flex--sdf.bounces.google.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, Tariq Toukan , David Ahern , Jakub Kicinski , Willem de Bruijn , Jesper Dangaard Brouer , Anatoly Burakov , Alexander Lobakin , Magnus Karlsson , Maryam Tahhan , xdp-hints@xdp-project.net, netdev@vger.kernel.org X-Mailman-Version: 3.3.7 Precedence: list Subject: [xdp-hints] [PATCH bpf-next v2 7/8] mxl4: Support RX XDP metadata List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: RX timestamp and hash for now. Tested using the prog from the next patch. Also enabling xdp metadata support; don't see why it's disabled, there is enough headroom.. Cc: Tariq Toukan Cc: John Fastabend Cc: David Ahern Cc: Martin KaFai Lau Cc: Jakub Kicinski Cc: Willem de Bruijn Cc: Jesper Dangaard Brouer Cc: Anatoly Burakov Cc: Alexander Lobakin Cc: Magnus Karlsson Cc: Maryam Tahhan Cc: xdp-hints@xdp-project.net Cc: netdev@vger.kernel.org Signed-off-by: Stanislav Fomichev --- .../net/ethernet/mellanox/mlx4/en_netdev.c | 10 ++++ drivers/net/ethernet/mellanox/mlx4/en_rx.c | 48 ++++++++++++++++++- include/linux/mlx4/device.h | 7 +++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c index 8800d3f1f55c..1cb63746a851 100644 --- a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c +++ b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c @@ -2855,6 +2855,11 @@ static const struct net_device_ops mlx4_netdev_ops = { .ndo_features_check = mlx4_en_features_check, .ndo_set_tx_maxrate = mlx4_en_set_tx_maxrate, .ndo_bpf = mlx4_xdp, + + .ndo_xdp_rx_timestamp_supported = mlx4_xdp_rx_timestamp_supported, + .ndo_xdp_rx_timestamp = mlx4_xdp_rx_timestamp, + .ndo_xdp_rx_hash_supported = mlx4_xdp_rx_hash_supported, + .ndo_xdp_rx_hash = mlx4_xdp_rx_hash, }; static const struct net_device_ops mlx4_netdev_ops_master = { @@ -2887,6 +2892,11 @@ static const struct net_device_ops mlx4_netdev_ops_master = { .ndo_features_check = mlx4_en_features_check, .ndo_set_tx_maxrate = mlx4_en_set_tx_maxrate, .ndo_bpf = mlx4_xdp, + + .ndo_xdp_rx_timestamp_supported = mlx4_xdp_rx_timestamp_supported, + .ndo_xdp_rx_timestamp = mlx4_xdp_rx_timestamp, + .ndo_xdp_rx_hash_supported = mlx4_xdp_rx_hash_supported, + .ndo_xdp_rx_hash = mlx4_xdp_rx_hash, }; struct mlx4_en_bond { diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ethernet/mellanox/mlx4/en_rx.c index 467356633172..fd14d59f6cbf 100644 --- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c @@ -663,8 +663,50 @@ static int check_csum(struct mlx4_cqe *cqe, struct sk_buff *skb, void *va, struct mlx4_xdp_buff { struct xdp_buff xdp; + struct mlx4_cqe *cqe; + struct mlx4_en_dev *mdev; + struct mlx4_en_rx_ring *ring; + struct net_device *dev; }; +bool mlx4_xdp_rx_timestamp_supported(const struct xdp_md *ctx) +{ + struct mlx4_xdp_buff *_ctx = (void *)ctx; + + return _ctx->ring->hwtstamp_rx_filter == HWTSTAMP_FILTER_ALL; +} + +u64 mlx4_xdp_rx_timestamp(const struct xdp_md *ctx) +{ + struct mlx4_xdp_buff *_ctx = (void *)ctx; + unsigned int seq; + u64 timestamp; + u64 nsec; + + timestamp = mlx4_en_get_cqe_ts(_ctx->cqe); + + do { + seq = read_seqbegin(&_ctx->mdev->clock_lock); + nsec = timecounter_cyc2time(&_ctx->mdev->clock, timestamp); + } while (read_seqretry(&_ctx->mdev->clock_lock, seq)); + + return ns_to_ktime(nsec); +} + +bool mlx4_xdp_rx_hash_supported(const struct xdp_md *ctx) +{ + struct mlx4_xdp_buff *_ctx = (void *)ctx; + + return _ctx->dev->features & NETIF_F_RXHASH; +} + +u32 mlx4_xdp_rx_hash(const struct xdp_md *ctx) +{ + struct mlx4_xdp_buff *_ctx = (void *)ctx; + + return be32_to_cpu(_ctx->cqe->immed_rss_invalid); +} + int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int budget) { struct mlx4_en_priv *priv = netdev_priv(dev); @@ -781,8 +823,12 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud DMA_FROM_DEVICE); xdp_prepare_buff(&mxbuf.xdp, va - frags[0].page_offset, - frags[0].page_offset, length, false); + frags[0].page_offset, length, true); orig_data = mxbuf.xdp.data; + mxbuf.cqe = cqe; + mxbuf.mdev = priv->mdev; + mxbuf.ring = ring; + mxbuf.dev = dev; act = bpf_prog_run_xdp(xdp_prog, &mxbuf.xdp); diff --git a/include/linux/mlx4/device.h b/include/linux/mlx4/device.h index 6646634a0b9d..d5904da1d490 100644 --- a/include/linux/mlx4/device.h +++ b/include/linux/mlx4/device.h @@ -1585,4 +1585,11 @@ static inline int mlx4_get_num_reserved_uar(struct mlx4_dev *dev) /* The first 128 UARs are used for EQ doorbells */ return (128 >> (PAGE_SHIFT - dev->uar_page_shift)); } + +struct xdp_md; +bool mlx4_xdp_rx_timestamp_supported(const struct xdp_md *ctx); +u64 mlx4_xdp_rx_timestamp(const struct xdp_md *ctx); +bool mlx4_xdp_rx_hash_supported(const struct xdp_md *ctx); +u32 mlx4_xdp_rx_hash(const struct xdp_md *ctx); + #endif /* MLX4_DEVICE_H */ -- 2.38.1.584.g0f3c55d4c2-goog