From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by mail.toke.dk (Postfix) with ESMTPS id 228FD9B2EC8 for ; Fri, 4 Nov 2022 04:25:53 +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=EIrTEzpC Received: by mail-pl1-x649.google.com with SMTP id e13-20020a17090301cd00b001871e6f8714so2607991plh.14 for ; Thu, 03 Nov 2022 20:25:53 -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=zmaQvtYLsF9TKtg/u36OM0LhcEYMaV9waLpFb4MnS1Q=; b=EIrTEzpC8kZmxoComMULXSMr5kl6knLvkr/D1iegqzP0gJ4OnFl3H2XunCuW5lcAtv S27IgOFxZIaHbAgjmox69AMpTnhy0/qg3qTTdRproJE0WfLdAGVsv4iwsfgBKTg9g+1t ireXoSYPjWIpzxVMFYvL93yoiC+OaZxakfk/+/B9R4HAcpTSmXJXgr1iwjfEhr57xiQB 7/JWMuDJ60+KbCNg/WYP+D58vKiQaQdm2ucoqos+Qy9l55qC/x6L4bHDav7lzYAH7GNR M+ZMh3MgD2bWZ29lKna28omiu/IPSbzriNJeiCuMi9mwIzVWmdutiXLn4+Bywq82ahB2 kpug== 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=zmaQvtYLsF9TKtg/u36OM0LhcEYMaV9waLpFb4MnS1Q=; b=NqbbcFLRYMDmkCSBVqvoFL46l/cCEXxnIwGyNLLVdHiyFjgM+LoyOhx7Z3HcPrTGog Fzsmk0MG7oPiObHKXlfa5ep64lU11VIb69DE8RgP0Z0Zqiu+16XVyYFZh93mrC+oQyCp 8NO/29nvpK38/rPfKXPEQqJsiOVt5n6MOs6VvnHZSMkxC0eaQdLSvOq6qEipsVrD/C9d ZB4cTVCZOWsdTNNH0LHOsOlQQCW5Nr1ZqNrEk/tlOaC3gM/8QvpKBX/onVUPYzsibbzi kgkcF5XU71fr2CYkUC/MHMC7QfrRs+r6AI6NtcaD1/mt0rOumQJ354HVeBCcV/5zB3eM yP9A== X-Gm-Message-State: ACrzQf0LpNUbRkXa9tc8vg4mhFx9HIweTqQTGRf/nU0eCpu2CV26k7V3 hvluvHuAem0gqXod2K9HRpVILQY= X-Google-Smtp-Source: AMsMyM7RzevfVCfpk+v3vHhvFphBW61C6xlIKEHis1h+1wQyUVW4C0FrBXHcsgtDMcGjz6TIwnaxeoQ= X-Received: from sdf.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5935]) (user=sdf job=sendgmr) by 2002:a17:902:c40a:b0:186:ba20:76fa with SMTP id k10-20020a170902c40a00b00186ba2076famr33267866plk.55.1667532351618; Thu, 03 Nov 2022 20:25:51 -0700 (PDT) Date: Thu, 3 Nov 2022 20:25:28 -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-11-sdf@google.com> From: Stanislav Fomichev To: bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Message-ID-Hash: 27VGGTEYRY4WBEPALXFSTQBRUUF74JWK X-Message-ID-Hash: 27VGGTEYRY4WBEPALXFSTQBRUUF74JWK X-MailFrom: 3P4ZkYwMKCf4yjlmuumrk.ius3jv-notzy3jv-vxupkiz.tkz@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 10/14] ice: 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/intel/ice/ice.h | 5 ++ drivers/net/ethernet/intel/ice/ice_main.c | 1 + drivers/net/ethernet/intel/ice/ice_txrx.c | 75 +++++++++++++++++++++++ 3 files changed, 81 insertions(+) diff --git a/drivers/net/ethernet/intel/ice/ice.h b/drivers/net/ethernet/intel/ice/ice.h index f88ee051e71c..c51a392d64a4 100644 --- a/drivers/net/ethernet/intel/ice/ice.h +++ b/drivers/net/ethernet/intel/ice/ice.h @@ -925,6 +925,11 @@ int ice_open_internal(struct net_device *netdev); int ice_stop(struct net_device *netdev); void ice_service_task_schedule(struct ice_pf *pf); +struct bpf_insn; +struct bpf_patch; +void ice_unroll_kfunc(const struct bpf_prog *prog, u32 func_id, + struct bpf_patch *patch); + /** * ice_set_rdma_cap - enable RDMA support * @pf: PF struct diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c index 1f27dc20b4f1..8ddc6851ef86 100644 --- a/drivers/net/ethernet/intel/ice/ice_main.c +++ b/drivers/net/ethernet/intel/ice/ice_main.c @@ -9109,4 +9109,5 @@ static const struct net_device_ops ice_netdev_ops = { .ndo_xdp_xmit = ice_xdp_xmit, .ndo_xsk_wakeup = ice_xsk_wakeup, .ndo_get_devlink_port = ice_get_devlink_port, + .ndo_unroll_kfunc = ice_unroll_kfunc, }; diff --git a/drivers/net/ethernet/intel/ice/ice_txrx.c b/drivers/net/ethernet/intel/ice/ice_txrx.c index 1b6afa168501..e9b5e883753e 100644 --- a/drivers/net/ethernet/intel/ice/ice_txrx.c +++ b/drivers/net/ethernet/intel/ice/ice_txrx.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -1098,8 +1099,80 @@ ice_is_non_eop(struct ice_rx_ring *rx_ring, union ice_32b_rx_flex_desc *rx_desc) struct ice_xdp_buff { struct xdp_buff xdp; + struct ice_rx_ring *rx_ring; + union ice_32b_rx_flex_desc *rx_desc; }; +void ice_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)) { + bpf_patch_append(patch, + /* Loosely based on ice_ptp_rx_hwtstamp. */ + + BPF_MOV64_IMM(BPF_REG_0, 0), + + /* r5 = ((struct ice_xdp_buff *)r1)->rx_ring; */ + BPF_LDX_MEM(BPF_DW, BPF_REG_5, BPF_REG_1, + offsetof(struct ice_xdp_buff, rx_ring)), + /* if (r5 == NULL) return; */ + BPF_JMP_IMM(BPF_JNE, BPF_REG_5, 0, S16_MAX), + + /* r5 = rx_ring->cached_phctime; */ + BPF_LDX_MEM(BPF_DW, BPF_REG_5, BPF_REG_5, + offsetof(struct ice_rx_ring, cached_phctime)), + /* if (r5 == 0) return; */ + BPF_JMP_IMM(BPF_JNE, BPF_REG_5, 0, S16_MAX), + + /* r4 = ((struct ice_xdp_buff *)r1)->rx_desc; */ + BPF_LDX_MEM(BPF_DW, BPF_REG_4, BPF_REG_1, + offsetof(struct ice_xdp_buff, rx_desc)), + + /* r3 = rx_desc->wb.time_stamp_low; */ + BPF_LDX_MEM(BPF_DW, BPF_REG_3, BPF_REG_4, + offsetof(union ice_32b_rx_flex_desc, wb.time_stamp_low)), + /* r3 = r3 & ICE_PTP_TS_VALID; */ + BPF_ALU64_IMM(BPF_AND, BPF_REG_3, 1), + /* if (r3 == 0) return; */ + BPF_JMP_IMM(BPF_JNE, BPF_REG_3, 0, S16_MAX), + + /* r3 = rx_desc->wb.flex_ts.ts_high; */ + BPF_LDX_MEM(BPF_DW, BPF_REG_3, BPF_REG_4, + offsetof(union ice_32b_rx_flex_desc, wb.flex_ts.ts_high)), + + /* r5 == cached_phc_time; */ + /* r3 == in_tstamp */ + + /* r4 = in_tstamp - pch_time_lo; (delta) */ + BPF_MOV32_REG(BPF_REG_4, BPF_REG_3), + BPF_ALU32_REG(BPF_SUB, BPF_REG_4, BPF_REG_5), + + /* if (delta <= U32_MAX / 2) { */ + BPF_JMP_IMM(BPF_JGT, BPF_REG_4, U32_MAX / 2, 3), + + /* return cached_pch_time + delta */ + BPF_MOV64_REG(BPF_REG_0, BPF_REG_4), + BPF_ALU32_REG(BPF_ADD, BPF_REG_0, BPF_REG_5), + BPF_JMP_A(4), + + /* } else { */ + /* r4 = cached_phc_time_lo - in_tstamp; (delta) */ + BPF_MOV64_REG(BPF_REG_4, BPF_REG_5), + BPF_ALU32_REG(BPF_SUB, BPF_REG_4, BPF_REG_3), + + /* return cached_pch_time - delta */ + BPF_MOV64_REG(BPF_REG_0, BPF_REG_5), + BPF_ALU32_REG(BPF_SUB, BPF_REG_0, BPF_REG_4), + /* } */ + ); + } +} + /** * ice_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf * @rx_ring: Rx descriptor ring to transact packets on @@ -1196,6 +1269,8 @@ int ice_clean_rx_irq(struct ice_rx_ring *rx_ring, int budget) /* At larger PAGE_SIZE, frame_sz depend on len size */ ixbuf.xdp.frame_sz = ice_rx_frame_truesize(rx_ring, size); #endif + ixbuf.rx_ring = rx_ring; + ixbuf.rx_desc = rx_desc; if (!xdp_prog) goto construct_skb; -- 2.38.1.431.g37b22c650d-goog