From patchwork Fri Jul 29 07:32:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitris Michailidis X-Patchwork-Id: 12932073 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D4FBC19F2B for ; Fri, 29 Jul 2022 07:33:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233985AbiG2HdE (ORCPT ); Fri, 29 Jul 2022 03:33:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234826AbiG2HdD (ORCPT ); Fri, 29 Jul 2022 03:33:03 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79BB47C1B4 for ; Fri, 29 Jul 2022 00:33:02 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id r186so3405072pgr.2 for ; Fri, 29 Jul 2022 00:33:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fungible.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=yFHFgyPkmeP63Zp6lsFBIOMH+WFI4z2Il/CBc4HwPPw=; b=Gaycs6hUp21BQ+pfnv/oplxHvaB3avAszaxPyn0whnxSTAUjZzqyNEsfp6yG0B/yfJ zFVvtqmpTbjt4iUi7AxNEYCKWGgiKaPsSoQT34xi2ZUpT3b4FHwvrRuuYbmWgLOcMhD0 ZE8FOcTOQ0J4fH9rFzgMD0NLbwTgbcO5lseoI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yFHFgyPkmeP63Zp6lsFBIOMH+WFI4z2Il/CBc4HwPPw=; b=43eFqyYIJvxLJRAM5rQer3JyfQpJ7vXbKY5XTFnu6x9jtso471dA+d5hhdKoHfpdw2 Mjw8tgxFuTtj3O4/Fc9axE+Ar1Nc+5F61ll6p1EUeAuWla3vKdXjBkbZ76kH2rfu4eev AR6f/5Edl5r0DyTL8fSxfoWk7A+hhZW4ET1sJ5CZCepsMktZ38B+LD+oUOBu+oP/x2Rk G6jm0Ow+Xubk/W0fpLYa7xH+T6zPxD/YImcIRvPPkgoayUZS17rN81jGHSQ5cLCVV9Ch wnhTzQ1glsDv5MHIRDXbzaGWYhPwZurm9RmppzU5XLCrkf6uRZO6w8cpO72telbyrTqP uSVg== X-Gm-Message-State: AJIora/We77fBTFxWNqxzcRQD77tngTKWD5fJrQIpfbCLYrUen8RU4Id i5f5wXP6WxLh+jvpUx/7CQuvfw== X-Google-Smtp-Source: AGRyM1upa+E4uQwOAQPa0hiS96AH1BxKX6JSE2JMy8LqwSrgPbQ6S978B729TP38S6Xgee8o/2Aa2A== X-Received: by 2002:a05:6a00:1948:b0:525:45e3:2eb7 with SMTP id s8-20020a056a00194800b0052545e32eb7mr2510721pfk.77.1659079981773; Fri, 29 Jul 2022 00:33:01 -0700 (PDT) Received: from cab09-qa-09.fungible.local ([12.190.10.11]) by smtp.gmail.com with ESMTPSA id w71-20020a627b4a000000b005289ffefe82sm2074226pfc.130.2022.07.29.00.33.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 00:33:01 -0700 (PDT) From: Dimitris Michailidis X-Google-Original-From: Dimitris Michailidis To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, lorenzo@kernel.org, hawk@kernel.org, netdev@vger.kernel.org, d.michailidis@fungible.com Subject: [PATCH net-next 1/4] net/funeth: Unify skb/XDP Tx packet unmapping. Date: Fri, 29 Jul 2022 00:32:54 -0700 Message-Id: <20220729073257.2721-2-dmichail@fungible.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220729073257.2721-1-dmichail@fungible.com> References: <20220729073257.2721-1-dmichail@fungible.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Current XDP unmapping is a subset of its skb analog, dealing with only one buffer. In preparation for multi-frag XDP rename the skb function and use it also for XDP. The XDP version is removed. Signed-off-by: Dimitris Michailidis --- .../net/ethernet/fungible/funeth/funeth_tx.c | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/drivers/net/ethernet/fungible/funeth/funeth_tx.c b/drivers/net/ethernet/fungible/funeth/funeth_tx.c index 54bdeb65a2bd..83fe825ce11d 100644 --- a/drivers/net/ethernet/fungible/funeth/funeth_tx.c +++ b/drivers/net/ethernet/fungible/funeth/funeth_tx.c @@ -371,7 +371,7 @@ static u16 txq_hw_head(const struct funeth_txq *q) /* Unmap the Tx packet starting at the given descriptor index and * return the number of Tx descriptors it occupied. */ -static unsigned int unmap_skb(const struct funeth_txq *q, unsigned int idx) +static unsigned int fun_unmap_pkt(const struct funeth_txq *q, unsigned int idx) { const struct fun_eth_tx_req *req = fun_tx_desc_addr(q, idx); unsigned int ngle = req->dataop.ngather; @@ -419,7 +419,7 @@ static bool fun_txq_reclaim(struct funeth_txq *q, int budget) rmb(); do { - unsigned int pkt_desc = unmap_skb(q, reclaim_idx); + unsigned int pkt_desc = fun_unmap_pkt(q, reclaim_idx); struct sk_buff *skb = q->info[reclaim_idx].skb; trace_funeth_tx_free(q, reclaim_idx, pkt_desc, head); @@ -461,20 +461,10 @@ int fun_txq_napi_poll(struct napi_struct *napi, int budget) return 0; } -static void fun_xdp_unmap(const struct funeth_txq *q, unsigned int idx) -{ - const struct fun_eth_tx_req *req = fun_tx_desc_addr(q, idx); - const struct fun_dataop_gl *gle; - - gle = (const struct fun_dataop_gl *)req->dataop.imm; - dma_unmap_single(q->dma_dev, be64_to_cpu(gle->sgl_data), - be32_to_cpu(gle->sgl_len), DMA_TO_DEVICE); -} - -/* Reclaim up to @budget completed Tx descriptors from a TX XDP queue. */ +/* Reclaim up to @budget completed Tx packets from a TX XDP queue. */ static unsigned int fun_xdpq_clean(struct funeth_txq *q, unsigned int budget) { - unsigned int npkts = 0, head, reclaim_idx; + unsigned int npkts = 0, ndesc = 0, head, reclaim_idx; for (head = txq_hw_head(q), reclaim_idx = q->cons_cnt & q->mask; head != reclaim_idx && npkts < budget; head = txq_hw_head(q)) { @@ -486,17 +476,19 @@ static unsigned int fun_xdpq_clean(struct funeth_txq *q, unsigned int budget) rmb(); do { - fun_xdp_unmap(q, reclaim_idx); + unsigned int pkt_desc = fun_unmap_pkt(q, reclaim_idx); + xdp_return_frame(q->info[reclaim_idx].xdpf); - trace_funeth_tx_free(q, reclaim_idx, 1, head); + trace_funeth_tx_free(q, reclaim_idx, pkt_desc, head); - reclaim_idx = (reclaim_idx + 1) & q->mask; + reclaim_idx = (reclaim_idx + pkt_desc) & q->mask; + ndesc += pkt_desc; npkts++; } while (reclaim_idx != head && npkts < budget); } - q->cons_cnt += npkts; + q->cons_cnt += ndesc; return npkts; } @@ -584,7 +576,7 @@ static void fun_txq_purge(struct funeth_txq *q) while (q->cons_cnt != q->prod_cnt) { unsigned int idx = q->cons_cnt & q->mask; - q->cons_cnt += unmap_skb(q, idx); + q->cons_cnt += fun_unmap_pkt(q, idx); dev_kfree_skb_any(q->info[idx].skb); } netdev_tx_reset_queue(q->ndq); @@ -595,9 +587,8 @@ static void fun_xdpq_purge(struct funeth_txq *q) while (q->cons_cnt != q->prod_cnt) { unsigned int idx = q->cons_cnt & q->mask; - fun_xdp_unmap(q, idx); + q->cons_cnt += fun_unmap_pkt(q, idx); xdp_return_frame(q->info[idx].xdpf); - q->cons_cnt++; } } From patchwork Fri Jul 29 07:32:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitris Michailidis X-Patchwork-Id: 12932075 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58C5BC00144 for ; Fri, 29 Jul 2022 07:33:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234871AbiG2HdQ (ORCPT ); Fri, 29 Jul 2022 03:33:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234851AbiG2HdE (ORCPT ); Fri, 29 Jul 2022 03:33:04 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D2A97B37F for ; Fri, 29 Jul 2022 00:33:03 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id f7so4180972pjp.0 for ; Fri, 29 Jul 2022 00:33:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fungible.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=VdV2WBdLv2Rqn9KEbE5gARCWHWcca5+mdWom9/fO9HE=; b=UBRR+tix0d3RwgpOfTRwrJNlMpgxcpRuTMP2aP+69Uj/vymtAQuuy2ShuHPEdHtUgx Zf7+KoQJ0ER22T9kSG15WVzn4KFTbuPrRoeQGDldKNj+03opM+LKBUaYMSTVUdXOlhhe m/l+vmKXreb2QKhi905kaIBfPPi00R42l6y+M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VdV2WBdLv2Rqn9KEbE5gARCWHWcca5+mdWom9/fO9HE=; b=RFv1T++PR57733PLHIUtl7Fye+MFDeDadyLXPiN7yiILqkwRjyS0gKOiZhwl0ZEq4L lRsKkjAy3g99AOh4f3pKZFSY7wplsu8t31r9DecbbVTwkGpiTr8pOGe0aBMbc99pBrBc fZrT4zOmohIBeYX+QHJDOzt5FSVbxgON1VICHivoYVnJlS9ABV6YK4x7kvhgHGLHKCLr gRfO45t5U6+UgxfvAdA0o317HQj6Fq3Bai8FDBiR5FzkKSCOKLKHV0SIrlo9/uLbyjB9 K0pE1pKREyj8BSe+CJmUkrCGhMm4Y74/IWaGqlmJSZFq6BgHiqoqXFtic7uIigGSjHSW 2ABQ== X-Gm-Message-State: ACgBeo1FkRqN3zIV5yd6weZprCnBPZff7ie8pCHPfNIiR6i11McYI4oZ ag/q0ZfAcLjTXu5XIqw5BojgDA== X-Google-Smtp-Source: AA6agR4B61PmVIf6KgntYRNJc2WAk2YbkCN+REBshIZC5W2Io15ltGX/6vPpVVe12+nd6CJ62GP9oQ== X-Received: by 2002:a17:90b:2791:b0:1f3:c48:19d5 with SMTP id pw17-20020a17090b279100b001f30c4819d5mr2627475pjb.219.1659079983070; Fri, 29 Jul 2022 00:33:03 -0700 (PDT) Received: from cab09-qa-09.fungible.local ([12.190.10.11]) by smtp.gmail.com with ESMTPSA id w71-20020a627b4a000000b005289ffefe82sm2074226pfc.130.2022.07.29.00.33.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 00:33:02 -0700 (PDT) From: Dimitris Michailidis X-Google-Original-From: Dimitris Michailidis To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, lorenzo@kernel.org, hawk@kernel.org, netdev@vger.kernel.org, d.michailidis@fungible.com Subject: [PATCH net-next 2/4] net/funeth: Unify skb/XDP gather list writing. Date: Fri, 29 Jul 2022 00:32:55 -0700 Message-Id: <20220729073257.2721-3-dmichail@fungible.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220729073257.2721-1-dmichail@fungible.com> References: <20220729073257.2721-1-dmichail@fungible.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Extract the Tx gather list writing code that skbs use into a utility function and use it also for XDP. Signed-off-by: Dimitris Michailidis --- .../net/ethernet/fungible/funeth/funeth_tx.c | 46 +++++++++++++------ 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/drivers/net/ethernet/fungible/funeth/funeth_tx.c b/drivers/net/ethernet/fungible/funeth/funeth_tx.c index 83fe825ce11d..a815432a3d3a 100644 --- a/drivers/net/ethernet/fungible/funeth/funeth_tx.c +++ b/drivers/net/ethernet/fungible/funeth/funeth_tx.c @@ -71,6 +71,33 @@ static unsigned int tx_req_ndesc(const struct fun_eth_tx_req *req) return DIV_ROUND_UP(req->len8, FUNETH_SQE_SIZE / 8); } +/* Write a gather list to the Tx descriptor at @req from @ngle address/length + * pairs. + */ +static struct fun_dataop_gl *fun_write_gl(const struct funeth_txq *q, + struct fun_eth_tx_req *req, + const dma_addr_t *addrs, + const unsigned int *lens, + unsigned int ngle) +{ + struct fun_dataop_gl *gle; + unsigned int i; + + req->len8 = (sizeof(*req) + ngle * sizeof(*gle)) / 8; + + for (i = 0, gle = (struct fun_dataop_gl *)req->dataop.imm; + i < ngle && txq_to_end(q, gle); i++, gle++) + fun_dataop_gl_init(gle, 0, 0, lens[i], addrs[i]); + + if (txq_to_end(q, gle) == 0) { + gle = (struct fun_dataop_gl *)q->desc; + for ( ; i < ngle; i++, gle++) + fun_dataop_gl_init(gle, 0, 0, lens[i], addrs[i]); + } + + return gle; +} + static __be16 tcp_hdr_doff_flags(const struct tcphdr *th) { return *(__be16 *)&tcp_flag_word(th); @@ -129,8 +156,8 @@ static unsigned int write_pkt_desc(struct sk_buff *skb, struct funeth_txq *q, struct fun_eth_tx_req *req; struct fun_dataop_gl *gle; const struct tcphdr *th; - unsigned int ngle, i; unsigned int l4_hlen; + unsigned int ngle; u16 flags; if (unlikely(map_skb(skb, q->dma_dev, addrs, lens))) { @@ -243,18 +270,9 @@ static unsigned int write_pkt_desc(struct sk_buff *skb, struct funeth_txq *q, } ngle = shinfo->nr_frags + 1; - req->len8 = (sizeof(*req) + ngle * sizeof(*gle)) / 8; req->dataop = FUN_DATAOP_HDR_INIT(ngle, 0, ngle, 0, skb->len); - for (i = 0, gle = (struct fun_dataop_gl *)req->dataop.imm; - i < ngle && txq_to_end(q, gle); i++, gle++) - fun_dataop_gl_init(gle, 0, 0, lens[i], addrs[i]); - - if (txq_to_end(q, gle) == 0) { - gle = (struct fun_dataop_gl *)q->desc; - for ( ; i < ngle; i++, gle++) - fun_dataop_gl_init(gle, 0, 0, lens[i], addrs[i]); - } + gle = fun_write_gl(q, req, addrs, lens, ngle); if (IS_ENABLED(CONFIG_TLS_DEVICE) && unlikely(tls_len)) { struct fun_eth_tls *tls = (struct fun_eth_tls *)gle; @@ -495,7 +513,6 @@ static unsigned int fun_xdpq_clean(struct funeth_txq *q, unsigned int budget) bool fun_xdp_tx(struct funeth_txq *q, struct xdp_frame *xdpf) { struct fun_eth_tx_req *req; - struct fun_dataop_gl *gle; unsigned int idx, len; dma_addr_t dma; @@ -517,7 +534,7 @@ bool fun_xdp_tx(struct funeth_txq *q, struct xdp_frame *xdpf) idx = q->prod_cnt & q->mask; req = fun_tx_desc_addr(q, idx); req->op = FUN_ETH_OP_TX; - req->len8 = (sizeof(*req) + sizeof(*gle)) / 8; + req->len8 = 0; req->flags = 0; req->suboff8 = offsetof(struct fun_eth_tx_req, dataop); req->repr_idn = 0; @@ -525,8 +542,7 @@ bool fun_xdp_tx(struct funeth_txq *q, struct xdp_frame *xdpf) fun_eth_offload_init(&req->offload, 0, 0, 0, 0, 0, 0, 0, 0); req->dataop = FUN_DATAOP_HDR_INIT(1, 0, 1, 0, len); - gle = (struct fun_dataop_gl *)req->dataop.imm; - fun_dataop_gl_init(gle, 0, 0, len, dma); + fun_write_gl(q, req, &dma, &len, 1); q->info[idx].xdpf = xdpf; From patchwork Fri Jul 29 07:32:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitris Michailidis X-Patchwork-Id: 12932077 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 093B6C19F2A for ; Fri, 29 Jul 2022 07:33:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234856AbiG2HdR (ORCPT ); Fri, 29 Jul 2022 03:33:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234826AbiG2HdG (ORCPT ); Fri, 29 Jul 2022 03:33:06 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D52FE7C1B4 for ; Fri, 29 Jul 2022 00:33:04 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id v18so3861373plo.8 for ; Fri, 29 Jul 2022 00:33:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fungible.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=u8OlrK9CxkZkoEa+ZDP5BCimtxxw5V1cQqD54DOitVI=; b=S/wq1nqmNQBZhA/uSa7ry5CaNu+PCZidQaYTFXTWzjCA47rwy2ARYblCqiopj+g2ZG +GchPXZekrVrUS4F7585pci98xOSa8Iaz0bTjFGPrFk+/8tu1g3psfXuygnHUTsVgc3+ ciH2PQKPuTJSuhXLlUmXFf3Xln+2WBTfyXqMA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u8OlrK9CxkZkoEa+ZDP5BCimtxxw5V1cQqD54DOitVI=; b=QM4fCRHITEQ8p1htYw+Pg9kgI6FXal8Gx36x/U/r7YUvXoJX2Los01CylWgwywlQfB yHK5GpEU7oyAeXzUXiItZX/5lwo3yb/FxrsnaM0MkSIhwwCwZP7clmJbzjZ+lJAFJPqN OUy+j24C9U5MdpzTWn+NUpoV+PYLxEU/SD6j6ADQ0IX+ppp4vFbZNDxVxCtNDMKJ8P5L av5IImdMoBmzCHLYU2NbhFt1aqOVEfX/+qfa+sJgixgcbV5b38AA8t8vx345TptVFLPh +i7VujsEjdZVzkmPoxCSSDTGQ34tsH/UypbZUnErV+TciUgEoNcb0X+mqUHLeNbZE5e5 RrdQ== X-Gm-Message-State: ACgBeo33+LynKWWg+ZBnKHkHNEhVYvhBDaOQ9b9pUAImthgsWxDsOrkV Y3+VJD2P9fQQ3OZ6zV2gAeKfSA== X-Google-Smtp-Source: AA6agR7o44Uyv9IfJiuRqLe1tmovIuT/RSq2umHTfK0aMy913JLWBNSZleK5RGMjYaVzv2plw0DFGQ== X-Received: by 2002:a17:902:7c88:b0:16c:5301:8a52 with SMTP id y8-20020a1709027c8800b0016c53018a52mr2681023pll.95.1659079984354; Fri, 29 Jul 2022 00:33:04 -0700 (PDT) Received: from cab09-qa-09.fungible.local ([12.190.10.11]) by smtp.gmail.com with ESMTPSA id w71-20020a627b4a000000b005289ffefe82sm2074226pfc.130.2022.07.29.00.33.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 00:33:03 -0700 (PDT) From: Dimitris Michailidis X-Google-Original-From: Dimitris Michailidis To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, lorenzo@kernel.org, hawk@kernel.org, netdev@vger.kernel.org, d.michailidis@fungible.com Subject: [PATCH net-next 3/4] net/funeth: Unify skb/XDP packet mapping. Date: Fri, 29 Jul 2022 00:32:56 -0700 Message-Id: <20220729073257.2721-4-dmichail@fungible.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220729073257.2721-1-dmichail@fungible.com> References: <20220729073257.2721-1-dmichail@fungible.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Instead of passing an skb to the mapping function pass an skb_shared_info plus an additional address/length pair. This makes it usable for both skbs and XDP. Call it from the XDP path and adjust the skb path. Signed-off-by: Dimitris Michailidis --- .../net/ethernet/fungible/funeth/funeth_tx.c | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/drivers/net/ethernet/fungible/funeth/funeth_tx.c b/drivers/net/ethernet/fungible/funeth/funeth_tx.c index a815432a3d3a..3128db8586ef 100644 --- a/drivers/net/ethernet/fungible/funeth/funeth_tx.c +++ b/drivers/net/ethernet/fungible/funeth/funeth_tx.c @@ -16,23 +16,24 @@ #define FUN_XDP_CLEAN_BATCH 16 /* DMA-map a packet and return the (length, DMA_address) pairs for its - * segments. If a mapping error occurs -ENOMEM is returned. + * segments. If a mapping error occurs -ENOMEM is returned. The packet + * consists of an skb_shared_info and one additional address/length pair. */ -static int map_skb(const struct sk_buff *skb, struct device *dev, - dma_addr_t *addr, unsigned int *len) +static int fun_map_pkt(struct device *dev, const struct skb_shared_info *si, + void *data, unsigned int data_len, + dma_addr_t *addr, unsigned int *len) { - const struct skb_shared_info *si; const skb_frag_t *fp, *end; - *len = skb_headlen(skb); - *addr = dma_map_single(dev, skb->data, *len, DMA_TO_DEVICE); + *len = data_len; + *addr = dma_map_single(dev, data, *len, DMA_TO_DEVICE); if (dma_mapping_error(dev, *addr)) return -ENOMEM; - si = skb_shinfo(skb); - end = &si->frags[si->nr_frags]; + if (!si) + return 0; - for (fp = si->frags; fp < end; fp++) { + for (fp = si->frags, end = fp + si->nr_frags; fp < end; fp++) { *++len = skb_frag_size(fp); *++addr = skb_frag_dma_map(dev, fp, 0, *len, DMA_TO_DEVICE); if (dma_mapping_error(dev, *addr)) @@ -44,7 +45,7 @@ static int map_skb(const struct sk_buff *skb, struct device *dev, while (fp-- > si->frags) dma_unmap_page(dev, *--addr, skb_frag_size(fp), DMA_TO_DEVICE); - dma_unmap_single(dev, addr[-1], skb_headlen(skb), DMA_TO_DEVICE); + dma_unmap_single(dev, addr[-1], data_len, DMA_TO_DEVICE); return -ENOMEM; } @@ -160,7 +161,9 @@ static unsigned int write_pkt_desc(struct sk_buff *skb, struct funeth_txq *q, unsigned int ngle; u16 flags; - if (unlikely(map_skb(skb, q->dma_dev, addrs, lens))) { + shinfo = skb_shinfo(skb); + if (unlikely(fun_map_pkt(q->dma_dev, shinfo, skb->data, + skb_headlen(skb), addrs, lens))) { FUN_QSTAT_INC(q, tx_map_err); return 0; } @@ -173,7 +176,6 @@ static unsigned int write_pkt_desc(struct sk_buff *skb, struct funeth_txq *q, req->repr_idn = 0; req->encap_proto = 0; - shinfo = skb_shinfo(skb); if (likely(shinfo->gso_size)) { if (skb->encapsulation) { u16 ol4_ofst; @@ -512,6 +514,7 @@ static unsigned int fun_xdpq_clean(struct funeth_txq *q, unsigned int budget) bool fun_xdp_tx(struct funeth_txq *q, struct xdp_frame *xdpf) { + const struct skb_shared_info *si = NULL; struct fun_eth_tx_req *req; unsigned int idx, len; dma_addr_t dma; @@ -524,9 +527,8 @@ bool fun_xdp_tx(struct funeth_txq *q, struct xdp_frame *xdpf) return false; } - len = xdpf->len; - dma = dma_map_single(q->dma_dev, xdpf->data, len, DMA_TO_DEVICE); - if (unlikely(dma_mapping_error(q->dma_dev, dma))) { + if (unlikely(fun_map_pkt(q->dma_dev, si, xdpf->data, xdpf->len, &dma, + &len))) { FUN_QSTAT_INC(q, tx_map_err); return false; } From patchwork Fri Jul 29 07:32:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitris Michailidis X-Patchwork-Id: 12932076 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F3B7C19F2C for ; Fri, 29 Jul 2022 07:33:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234859AbiG2HdT (ORCPT ); Fri, 29 Jul 2022 03:33:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234853AbiG2HdG (ORCPT ); Fri, 29 Jul 2022 03:33:06 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DB518049C for ; Fri, 29 Jul 2022 00:33:06 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id o14-20020a17090a4b4e00b001f2f2b61be5so4462731pjl.4 for ; Fri, 29 Jul 2022 00:33:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fungible.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=aoRspL2CzLa1KmMEczzCf80IIXkBL7hQgE8psDki5Wo=; b=PkG9q1UxgWVzsp6h2MUVEhrFgShuMeEM6V7ZT2R5B6LW/GFVtvt+TpvKB3Nx+2iCPi 7F299UKQWWpWVjsqjJoS7FVZTX3mTW4qA7TFKbWVS9AyTDTcJwEcv7xxwc22s5IqiAVL 1zyZtVqaCWACjmeJQfmysX/LJSdjQYcRvtmuA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aoRspL2CzLa1KmMEczzCf80IIXkBL7hQgE8psDki5Wo=; b=MPYOLlqeo8ZK5Z3aZ0AKKOKc0uzyfMbZ9Nl+LZGTpyFwJ2OxRLMJLprFAz8yH0E3/R q2Jf9LhvWpsp6mQgZs1SH4FfMuD0PMsAAezPlm4H/cC7WJ6fgnRvO9YrZnXSItQUY4rt vkyJlEMKaKF/Dm3p1e2vJeFIPLTx60R9pcdhRv2PdzyhmNESRPy1Xxdd0hI0irHZjJKB a+G2W4oXuaeqSuz6/3VLeXuba/GG5lrgKLTJD5CegCYEDvp1Ry9d7vJ/N3to0UfyjKl+ hs11yqgpiyJ51CII9aE9ZHrKSapogykV613J1/zxqkcZJ5TjpEzjfQrmPMCCVvkGghmK yayQ== X-Gm-Message-State: ACgBeo2t6twNOPSvhuL/5YLCTYoJDCeF1LdMVx94ENDaZBYCpmXlMZ02 YFMVVCXoDgIKHzPE4VIM3LA35Q== X-Google-Smtp-Source: AA6agR6Q4dljgMgZX9kzG88o1qNXDlAv2XNPMUxS6k7+fIlvZ0E8MA8AuPnJPDDe2o33qSU6UqaSZA== X-Received: by 2002:a17:902:9b97:b0:16d:5fba:57d7 with SMTP id y23-20020a1709029b9700b0016d5fba57d7mr2549122plp.109.1659079985598; Fri, 29 Jul 2022 00:33:05 -0700 (PDT) Received: from cab09-qa-09.fungible.local ([12.190.10.11]) by smtp.gmail.com with ESMTPSA id w71-20020a627b4a000000b005289ffefe82sm2074226pfc.130.2022.07.29.00.33.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 00:33:05 -0700 (PDT) From: Dimitris Michailidis X-Google-Original-From: Dimitris Michailidis To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, lorenzo@kernel.org, hawk@kernel.org, netdev@vger.kernel.org, d.michailidis@fungible.com Subject: [PATCH net-next 4/4] net/funeth: Tx handling of XDP with fragments. Date: Fri, 29 Jul 2022 00:32:57 -0700 Message-Id: <20220729073257.2721-5-dmichail@fungible.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220729073257.2721-1-dmichail@fungible.com> References: <20220729073257.2721-1-dmichail@fungible.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org By now all the functions fun_xdp_tx() calls are shared with the skb path and thus are fragment-capable. Update fun_xdp_tx(), that up to now has been passing just one buffer, to check for fragments and call accordingly. This makes XDP_TX and ndo_xdp_xmit fragment-capable. Signed-off-by: Dimitris Michailidis --- .../net/ethernet/fungible/funeth/funeth_tx.c | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/fungible/funeth/funeth_tx.c b/drivers/net/ethernet/fungible/funeth/funeth_tx.c index 3128db8586ef..706d81e39a54 100644 --- a/drivers/net/ethernet/fungible/funeth/funeth_tx.c +++ b/drivers/net/ethernet/fungible/funeth/funeth_tx.c @@ -514,21 +514,31 @@ static unsigned int fun_xdpq_clean(struct funeth_txq *q, unsigned int budget) bool fun_xdp_tx(struct funeth_txq *q, struct xdp_frame *xdpf) { + unsigned int idx, nfrags = 1, ndesc = 1, tot_len = xdpf->len; const struct skb_shared_info *si = NULL; + unsigned int lens[MAX_SKB_FRAGS + 1]; + dma_addr_t dma[MAX_SKB_FRAGS + 1]; struct fun_eth_tx_req *req; - unsigned int idx, len; - dma_addr_t dma; if (fun_txq_avail(q) < FUN_XDP_CLEAN_THRES) fun_xdpq_clean(q, FUN_XDP_CLEAN_BATCH); - if (!unlikely(fun_txq_avail(q))) { + if (unlikely(xdp_frame_has_frags(xdpf))) { + si = xdp_get_shared_info_from_frame(xdpf); + tot_len = xdp_get_frame_len(xdpf); + nfrags += si->nr_frags; + ndesc = DIV_ROUND_UP((sizeof(*req) + nfrags * + sizeof(struct fun_dataop_gl)), + FUNETH_SQE_SIZE); + } + + if (unlikely(fun_txq_avail(q) < ndesc)) { FUN_QSTAT_INC(q, tx_xdp_full); return false; } - if (unlikely(fun_map_pkt(q->dma_dev, si, xdpf->data, xdpf->len, &dma, - &len))) { + if (unlikely(fun_map_pkt(q->dma_dev, si, xdpf->data, xdpf->len, dma, + lens))) { FUN_QSTAT_INC(q, tx_map_err); return false; } @@ -542,19 +552,19 @@ bool fun_xdp_tx(struct funeth_txq *q, struct xdp_frame *xdpf) req->repr_idn = 0; req->encap_proto = 0; fun_eth_offload_init(&req->offload, 0, 0, 0, 0, 0, 0, 0, 0); - req->dataop = FUN_DATAOP_HDR_INIT(1, 0, 1, 0, len); + req->dataop = FUN_DATAOP_HDR_INIT(nfrags, 0, nfrags, 0, tot_len); - fun_write_gl(q, req, &dma, &len, 1); + fun_write_gl(q, req, dma, lens, nfrags); q->info[idx].xdpf = xdpf; u64_stats_update_begin(&q->syncp); - q->stats.tx_bytes += len; + q->stats.tx_bytes += tot_len; q->stats.tx_pkts++; u64_stats_update_end(&q->syncp); - trace_funeth_tx(q, len, idx, 1); - q->prod_cnt++; + trace_funeth_tx(q, tot_len, idx, nfrags); + q->prod_cnt += ndesc; return true; }