From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by mail.toke.dk (Postfix) with ESMTPS id E554C9B2F26 for ; Fri, 4 Nov 2022 04:26:00 +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=e95nTNyu Received: by mail-pj1-x1049.google.com with SMTP id om10-20020a17090b3a8a00b002108b078ab1so4775287pjb.9 for ; Thu, 03 Nov 2022 20:26:00 -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=uQ6JlR5MuJ+4TNT/9F0XUiWRUVg6v0604de78bhCMH0=; b=e95nTNyu1/zqYk594Wc2lEyKkIdbtwOKjh9caLsaCAaRuH9Dc6FetzenTjkT1Ud+2m 7hetwgd/CHvIWjr5pMDXS848OuGsVBvWeSi3si8WVYmY9BYbAyA/06KZer6peqFwMwwC yv0AKBrq+xOi3xXMGygdVXCudkOUZnIHThJ3B0/XuV78jWQpnWBT+m/dc7OYF8rdShgU MmcDnsYE8ToJS7DPQ935kHR7rlO+93sKESXrHOehd7hDxkHqPmua2TFOQ0rxAQ7oaqH+ UF19V1roe/y+TgOUwdX9vzD2DfoU9BMDAEfyLjxXA9vK1ik07qeIFXjoj+kH1a0ir1Uz vClw== 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=uQ6JlR5MuJ+4TNT/9F0XUiWRUVg6v0604de78bhCMH0=; b=qkvqyyNFCVyPd/+jcqdXTesLqUk2aRKwBMGZwG663OwFVtk8UGIcWSpBK0rbkK1P/X ++9HdcgQmZcX2sLTZ7R55dmmax1en/zRn0zppDuvG4VanGpi8/5DHhogzqV/7qVU4adb fLa4D8w8wCjzn6Hmtu20uJdaIqsYmrz0xz4zEKXK0AVeN8/VZXZ9FRUeYBFqh9Nsw53z JxDXulnb6/o4lWh6nLDtbhw9OYYhn13LW038+V1BoicB4/joS/euITED5IUWWsHH1mHn e18z0mejAg6jeBOXORR7P3QF+8J7dCj+WFZpe1OHdhL4KJxp+EsL+Vd2qXiygfCdfqEv Dr4w== X-Gm-Message-State: ACrzQf1VksQfUiUXAYLsKLR+Bb9EK4i43KnxD+7jgC5nlmqNMr2LizhG u1Q2/pp8NfyscLDPdxAAELb9cOM= X-Google-Smtp-Source: AMsMyM5KfIChbdj/RzkOJbzKK0JWi/IItAP2XkKFHFa0ViMAPEtrpdpDFmxFkThxRo8fGBWfxcRTA4A= X-Received: from sdf.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5935]) (user=sdf job=sendgmr) by 2002:a17:90b:2496:b0:213:e03d:bc30 with SMTP id nt22-20020a17090b249600b00213e03dbc30mr25753722pjb.109.1667532359345; Thu, 03 Nov 2022 20:25:59 -0700 (PDT) Date: Thu, 3 Nov 2022 20:25:32 -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-15-sdf@google.com> From: Stanislav Fomichev To: bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Message-ID-Hash: XIMXIID32RRBEJE5OFFPVKNUXAKQNSLS X-Message-ID-Hash: XIMXIID32RRBEJE5OFFPVKNUXAKQNSLS X-MailFrom: 3R4ZkYwMKCQg0lnowwotm.kwu5lx-pqv105lx-xzwrmk1.vm1@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 14/14] bnxt: 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 --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 55 +++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index b2e0607a6400..968266844f49 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -1791,8 +1792,53 @@ static void bnxt_deliver_skb(struct bnxt *bp, struct bnxt_napi *bnapi, struct bnxt_xdp_buff { struct xdp_buff xdp; + struct rx_cmp_ext *rxcmp1; + struct bnxt *bp; + u64 r0; }; +struct bnxt_xdp_buff *bnxt_xdp_rx_timestamp(struct bnxt_xdp_buff *ctx) +{ + struct bnxt_ptp_cfg *ptp; + u32 cmpl_ts; + u64 ns, ts; + + if (!ctx->rxcmp1) { + ctx->r0 = 0; + return ctx; + } + + cmpl_ts = le32_to_cpu(ctx->rxcmp1->rx_cmp_timestamp); + if (bnxt_get_rx_ts_p5(ctx->bp, &ts, cmpl_ts) < 0) { + ctx->r0 = 0; + return ctx; + } + + ptp = ctx->bp->ptp_cfg; + + spin_lock_bh(&ptp->ptp_lock); + ns = timecounter_cyc2time(&ptp->tc, ts); + spin_unlock_bh(&ptp->ptp_lock); + + ctx->r0 = (u64)ns_to_ktime(ns); + return ctx; +} + +void bnxt_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 bnxt_xdp_buff, r0), + bnxt_xdp_rx_timestamp); + } +} + /* returns the following: * 1 - 1 packet successfully received * 0 - successful TPA_START, packet not completed yet @@ -1941,6 +1987,14 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, } if (xdp_active) { + if (unlikely((flags & RX_CMP_FLAGS_ITYPES_MASK) == + RX_CMP_FLAGS_ITYPE_PTP_W_TS) || bp->ptp_all_rx_tstamp) { + if (bp->flags & BNXT_FLAG_CHIP_P5) { + bxbuf.rxcmp1 = rxcmp1; + bxbuf.bp = bp; + } + } + if (bnxt_rx_xdp(bp, rxr, cons, bxbuf.xdp, data, &len, event)) { rc = 1; goto next_rx; @@ -13116,6 +13170,7 @@ static const struct net_device_ops bnxt_netdev_ops = { .ndo_bridge_getlink = bnxt_bridge_getlink, .ndo_bridge_setlink = bnxt_bridge_setlink, .ndo_get_devlink_port = bnxt_get_devlink_port, + .ndo_unroll_kfunc = bnxt_unroll_kfunc, }; static void bnxt_remove_one(struct pci_dev *pdev) -- 2.38.1.431.g37b22c650d-goog