From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by mail.toke.dk (Postfix) with ESMTPS id B8F729B2EF8 for ; Fri, 4 Nov 2022 04:25:57 +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=pUb47nZC Received: by mail-pj1-x104a.google.com with SMTP id p1-20020a17090a2c4100b00212733d7aaaso1765530pjm.4 for ; Thu, 03 Nov 2022 20:25:57 -0700 (PDT) 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=pr1ZhtWkdqKAJX2dVOWrymiTIfYnYJdAHUmQmBo7KU0=; b=pUb47nZCqHPch0ZbXm3RBYrl/S5kuOFKP6kAItBRXBXSGcxoSXXOLo6T+Paf/mFNZE zNxClCq49l4SloyIRcf/Fb/yMN6iyrMTVuFG8YWVj8Dk9QUdNZtl8e9nbk588mGXnm9X 4B/wVVv3M45ezuqTVvsO40v4/mstlF8rATeitA7hmhEoV3ymn2H/qgBy2hWj4Se76OML 4HgIvT544624ULyK9J/mgwuVfLeo9T6S1+m7ifgBND6YbcbTBpliimjv2QJnEDVUflCr mjq4T7yF0H4eHxC/xp5T1H00y+hJFw5NKKxfxGmfyLGe5cdD1e+yHoQyaIoTFCDgr7Kr j5Kg== 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=pr1ZhtWkdqKAJX2dVOWrymiTIfYnYJdAHUmQmBo7KU0=; b=HVXk5zOMv9AZ1FXe60P/Q/e6W0bp5QbPy4inOnxuXVni0CSRWJIF6JjK265943jKTI dLIbMceYgdpLHUf/tXRvxq/dp6fe+bus0iTj8J9ESyROYQZ6idEIpNPIIrYpo/IkbVYc +eXse4/szo2mvPsu1ZOH1Jtz73JWjiqWZ+LJEwBsaN9t6Dtj2m6vT5pr9mO9tIHml+co /ScaJCLMxKfNcWtWSaJeEH3ucz0P4s+J++NtKftmCtHlL2T5K9mt9i7eIrdkcZ/2w6oY Adss9iqEeM58So7Ygj9oVwVhNCVnCcDWcAuRn9z1ZNVGXStJJe1B18YWJY60YXnfjzlM GO8g== X-Gm-Message-State: ACrzQf0YixVazCR9wWCBhkAZbUCdM5nex6lHE2Q1BNuyKexh5sYr32MS vMk1VsCwcXWgoJVjyq5pZ4uVViI= X-Google-Smtp-Source: AMsMyM7KE3YzYg5J2ApCRH6vpkXFRIqTcblZWRYi2ncYtzIkrTYu4YQIPzmytaJD6ieO+JZ8yMA+1d8= X-Received: from sdf.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5935]) (user=sdf job=sendgmr) by 2002:a05:6a00:24d0:b0:56c:fa97:a91c with SMTP id d16-20020a056a0024d000b0056cfa97a91cmr33601318pfv.23.1667532355739; Thu, 03 Nov 2022 20:25:55 -0700 (PDT) Date: Thu, 3 Nov 2022 20:25:30 -0700 In-Reply-To: <20221104032532.1615099-1-sdf@google.com> Mime-Version: 1.0 References: <20221104032532.1615099-1-sdf@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221104032532.1615099-13-sdf@google.com> From: Stanislav Fomichev To: bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Message-ID-Hash: PM25YGR4SY57OIUJBMCS3BBDO23D4PA2 X-Message-ID-Hash: PM25YGR4SY57OIUJBMCS3BBDO23D4PA2 X-MailFrom: 3Q4ZkYwMKCQQwhjksskpi.gsq1ht-lmrxw1ht-tvsnigx.rix@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, 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.5 Precedence: list Subject: [xdp-hints] [RFC bpf-next v2 12/14] mxl4: Support rx timestamp metadata for xdp List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: COMPILE-TESTED ONLY! 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 | 1 + drivers/net/ethernet/mellanox/mlx4/en_rx.c | 40 +++++++++++++++++++ include/linux/mlx4/device.h | 7 ++++ 3 files changed, 48 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c index ca4b93a01034..3ef7995950dc 100644 --- a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c +++ b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c @@ -2890,6 +2890,7 @@ 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_unroll_kfunc = mlx4_unroll_kfunc, }; 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..83c89a1db3b8 100644 --- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -663,8 +664,43 @@ 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; + u64 r0; }; +struct mlx4_xdp_buff *mxl4_xdp_rx_timestamp(struct mlx4_xdp_buff *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)); + + ctx->r0 = (u64)ns_to_ktime(nsec); + return ctx; +} + +void mlx4_unroll_kfunc(const struct bpf_prog *prog, u32 func_id, + struct bpf_patch *patch) +{ + if (func_id == xdp_metadata_kfunc_id(XDP_METADATA_KFUNC_EXPORT_TO_SKB)) { + return xdp_metadata_export_to_skb(prog, patch); + } else if (func_id == xdp_metadata_kfunc_id(XDP_METADATA_KFUNC_RX_TIMESTAMP_SUPPORTED)) { + /* return true; */ + bpf_patch_append(patch, BPF_MOV64_IMM(BPF_REG_0, 1)); + } else if (func_id == xdp_metadata_kfunc_id(XDP_METADATA_KFUNC_RX_TIMESTAMP)) { + xdp_kfunc_call_preserving_r1(patch, + offsetof(struct mlx4_xdp_buff, r0), + mxl4_xdp_rx_timestamp); + } +} + 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); @@ -783,6 +819,10 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud xdp_prepare_buff(&mxbuf.xdp, va - frags[0].page_offset, frags[0].page_offset, length, false); orig_data = mxbuf.xdp.data; + if (unlikely(ring->hwtstamp_rx_filter == HWTSTAMP_FILTER_ALL)) { + mxbuf.cqe = cqe; + mxbuf.mdev = priv->mdev; + } 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..a0e4d490b2fb 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 bpf_prog; +struct bpf_insn; +struct bpf_patch; + +void mlx4_unroll_kfunc(const struct bpf_prog *prog, u32 func_id, + struct bpf_patch *patch); #endif /* MLX4_DEVICE_H */ -- 2.38.1.431.g37b22c650d-goog