From patchwork Tue Mar 16 02:31:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Nelson X-Patchwork-Id: 12141075 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 X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2B75C433E6 for ; Tue, 16 Mar 2021 02:32:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9464C65033 for ; Tue, 16 Mar 2021 02:32:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234539AbhCPCbx (ORCPT ); Mon, 15 Mar 2021 22:31:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234552AbhCPCbr (ORCPT ); Mon, 15 Mar 2021 22:31:47 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A563FC06174A for ; Mon, 15 Mar 2021 19:31:47 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id j6so16232006plx.6 for ; Mon, 15 Mar 2021 19:31:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pensando.io; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=V8uLGXlgaaRgU797WF6VONApVvF3LFLDbEvPRTYcduY=; b=OvDrzj9BycyYbJzZ6nDhRJ5V52AiDGoht9Ntym4whvzQXxdMitAvmCgd4QHOnDF35l TUOPpkw/vBKwgmGjuTR5nO+voAlF8TqArLXCDRSbsY9DZB8DWtsRgp4HXGIzDSu6iLoZ hkWYGFGvISHuFM0RM7vbOGsrvaO7zKP6vhpGqlHAoMwKypU/QgMLjKSXjcXOB+9+T5O+ xPEUgk9pcssVBwgt3KUhzzCyoOfO4IfEy3SqA5CYCNaTaQjEj2y8BsNcXGZOLkopiG9Z M0BvEdgCV4TUfaRen10m7PuUFzAUANE4oeIVOHKpARIY3WA1XNiGRMt4s0aqrFlJmy3P 5D3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=V8uLGXlgaaRgU797WF6VONApVvF3LFLDbEvPRTYcduY=; b=OyLEATJ7BJmzTqb+RquCoNiEpPg8kvlJhCq+UfTeicqGxpjmSyvor5AmQR4Wybbq3L mUeJHnEMqO5tYrGmmFjodFfazS9hULEvJ0EO6cc3HEoRfCCdcYP1LfcWG6OJ5DP0z9ea 36vjZV0Dw+v1+MS8thpdjmtz1/UaOgnAzDcGJo247D70necV9zaEgjQ5RXFW8ek+kSiL DVR1ji0CTDLpFz4R3rBR5Q2lfPo2/ByjyWM/KH72rhQD7GyigKgSF/VL2aon8OaYdv1F HBM3sddNodjSmuoycA69Bgq4DMlATd6ixu18p8duz2x8ejPW1zIVnokNWHI6KKIxmsmW sxpA== X-Gm-Message-State: AOAM530zwL1Cytv1QnjoiNqmi5etIk00XUF7m+XsMwTuGju6W5qStpI3 sZmnYOUW8eClv9v8kT0cmGV3T4QWpS/UBg== X-Google-Smtp-Source: ABdhPJyesjmHpu152uLIldS6vtMXEfin/t2QgCNGze1r6ydkCfhrB1c0AwJAfxk8v4cjMAolobLFiw== X-Received: by 2002:a17:90a:e298:: with SMTP id d24mr2275978pjz.171.1615861906837; Mon, 15 Mar 2021 19:31:46 -0700 (PDT) Received: from driver-dev1.pensando.io ([12.226.153.42]) by smtp.gmail.com with ESMTPSA id t18sm8687743pgg.33.2021.03.15.19.31.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 19:31:46 -0700 (PDT) From: Shannon Nelson To: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org Cc: drivers@pensando.io, Shannon Nelson Subject: [PATCH net-next 1/4] ionic: simplify TSO descriptor mapping Date: Mon, 15 Mar 2021 19:31:33 -0700 Message-Id: <20210316023136.22702-2-snelson@pensando.io> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210316023136.22702-1-snelson@pensando.io> References: <20210316023136.22702-1-snelson@pensando.io> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org One issue with the original TSO code was that it was working too hard to deal with skb layouts that were never going to show up, such as an skb->data that was longer than a single descriptor's length. The other issue was trying to arrange the fragment dma mapping at the same time as figuring out the descriptors needed. There was just too much going on at the same time. Now we do the dma mapping first, which sets up the buffers with skb->data in buf[0] and the remaining frags in buf[1..n-1]. Next we spread the bufs across the descriptors needed, where each descriptor gets up to mss number of bytes. Signed-off-by: Shannon Nelson --- .../net/ethernet/pensando/ionic/ionic_dev.h | 5 +- .../net/ethernet/pensando/ionic/ionic_txrx.c | 237 +++++++++--------- 2 files changed, 117 insertions(+), 125 deletions(-) diff --git a/drivers/net/ethernet/pensando/ionic/ionic_dev.h b/drivers/net/ethernet/pensando/ionic/ionic_dev.h index 339824cfd618..d0c969a6d43e 100644 --- a/drivers/net/ethernet/pensando/ionic/ionic_dev.h +++ b/drivers/net/ethernet/pensando/ionic/ionic_dev.h @@ -179,8 +179,11 @@ struct ionic_buf_info { struct page *page; dma_addr_t dma_addr; u32 page_offset; + u32 len; }; +#define IONIC_MAX_FRAGS (1 + IONIC_TX_MAX_SG_ELEMS_V1) + struct ionic_desc_info { union { void *desc; @@ -194,7 +197,7 @@ struct ionic_desc_info { struct ionic_rxq_sg_desc *rxq_sgl_desc; }; unsigned int nbufs; - struct ionic_buf_info bufs[IONIC_RX_MAX_SG_ELEMS + 1]; + struct ionic_buf_info bufs[IONIC_MAX_FRAGS]; ionic_desc_cb cb; void *cb_arg; }; diff --git a/drivers/net/ethernet/pensando/ionic/ionic_txrx.c b/drivers/net/ethernet/pensando/ionic/ionic_txrx.c index c63e6e7aa47b..639000a2e495 100644 --- a/drivers/net/ethernet/pensando/ionic/ionic_txrx.c +++ b/drivers/net/ethernet/pensando/ionic/ionic_txrx.c @@ -605,12 +605,51 @@ static dma_addr_t ionic_tx_map_frag(struct ionic_queue *q, return dma_addr; } +static int ionic_tx_map_tso(struct ionic_queue *q, struct sk_buff *skb, + struct ionic_buf_info *buf_info) +{ + struct device *dev = q->dev; + dma_addr_t dma_addr; + skb_frag_t *frag; + int frag_idx; + + dma_addr = ionic_tx_map_single(q, skb->data, skb_headlen(skb)); + if (dma_mapping_error(dev, dma_addr)) + return -EIO; + buf_info->dma_addr = dma_addr; + buf_info->len = skb_headlen(skb); + buf_info++; + + for (frag_idx = 0; frag_idx < skb_shinfo(skb)->nr_frags; frag_idx++, buf_info++) { + frag = &skb_shinfo(skb)->frags[frag_idx]; + dma_addr = ionic_tx_map_frag(q, frag, 0, skb_frag_size(frag)); + if (dma_mapping_error(dev, dma_addr)) + goto dma_fail; + buf_info->dma_addr = dma_addr; + buf_info->len = skb_frag_size(frag); + } + + return 0; + +dma_fail: + /* unwind the frag mappings and the head mapping */ + while (frag_idx > 0) { + frag_idx--; + buf_info--; + dma_unmap_page(dev, buf_info->dma_addr, + buf_info->len, DMA_TO_DEVICE); + } + dma_unmap_single(dev, buf_info->dma_addr, buf_info->len, DMA_TO_DEVICE); + return -EIO; +} + static void ionic_tx_clean(struct ionic_queue *q, struct ionic_desc_info *desc_info, struct ionic_cq_info *cq_info, void *cb_arg) { struct ionic_txq_sg_desc *sg_desc = desc_info->sg_desc; + struct ionic_buf_info *buf_info = desc_info->bufs; struct ionic_txq_sg_elem *elem = sg_desc->elems; struct ionic_tx_stats *stats = q_to_tx_stats(q); struct ionic_txq_desc *desc = desc_info->desc; @@ -623,20 +662,22 @@ static void ionic_tx_clean(struct ionic_queue *q, decode_txq_desc_cmd(le64_to_cpu(desc->cmd), &opcode, &flags, &nsge, &addr); - /* use unmap_single only if either this is not TSO, - * or this is first descriptor of a TSO - */ - if (opcode != IONIC_TXQ_DESC_OPCODE_TSO || - flags & IONIC_TXQ_DESC_FLAG_TSO_SOT) + if (opcode != IONIC_TXQ_DESC_OPCODE_TSO) { dma_unmap_single(dev, (dma_addr_t)addr, le16_to_cpu(desc->len), DMA_TO_DEVICE); - else - dma_unmap_page(dev, (dma_addr_t)addr, - le16_to_cpu(desc->len), DMA_TO_DEVICE); - - for (i = 0; i < nsge; i++, elem++) - dma_unmap_page(dev, (dma_addr_t)le64_to_cpu(elem->addr), - le16_to_cpu(elem->len), DMA_TO_DEVICE); + for (i = 0; i < nsge; i++, elem++) + dma_unmap_page(dev, (dma_addr_t)le64_to_cpu(elem->addr), + le16_to_cpu(elem->len), DMA_TO_DEVICE); + } else { + if (flags & IONIC_TXQ_DESC_FLAG_TSO_EOT) { + dma_unmap_single(dev, (dma_addr_t)buf_info->dma_addr, + buf_info->len, DMA_TO_DEVICE); + buf_info++; + for (i = 1; i < desc_info->nbufs; i++, buf_info++) + dma_unmap_page(dev, (dma_addr_t)buf_info->dma_addr, + buf_info->len, DMA_TO_DEVICE); + } + } if (cb_arg) { struct sk_buff *skb = cb_arg; @@ -794,29 +835,23 @@ static struct ionic_txq_desc *ionic_tx_tso_next(struct ionic_queue *q, static int ionic_tx_tso(struct ionic_queue *q, struct sk_buff *skb) { + struct ionic_buf_info buf_info[IONIC_MAX_FRAGS] = {{0}}; struct ionic_tx_stats *stats = q_to_tx_stats(q); - struct ionic_desc_info *rewind_desc_info; struct ionic_txq_sg_elem *elem; - struct device *dev = q->dev; struct ionic_txq_desc *desc; - unsigned int frag_left = 0; - unsigned int offset = 0; - u16 abort = q->head_idx; - unsigned int len_left; + unsigned int chunk_len; + unsigned int frag_rem; + unsigned int frag_idx; + unsigned int tso_rem; + unsigned int seg_rem; dma_addr_t desc_addr; + dma_addr_t frag_addr; unsigned int hdrlen; unsigned int nfrags; - unsigned int seglen; - u64 total_bytes = 0; - u64 total_pkts = 0; - u16 rewind = abort; - unsigned int left; unsigned int len; unsigned int mss; - skb_frag_t *frag; bool start, done; bool outer_csum; - dma_addr_t addr; bool has_vlan; u16 desc_len; u8 desc_nsge; @@ -824,9 +859,12 @@ static int ionic_tx_tso(struct ionic_queue *q, struct sk_buff *skb) bool encap; int err; + if (unlikely(ionic_tx_map_tso(q, skb, buf_info))) + return -EIO; + + len = skb->len; mss = skb_shinfo(skb)->gso_size; nfrags = skb_shinfo(skb)->nr_frags; - len_left = skb->len - skb_headlen(skb); outer_csum = (skb_shinfo(skb)->gso_type & SKB_GSO_GRE_CSUM) || (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_TUNNEL_CSUM); has_vlan = !!skb_vlan_tag_present(skb); @@ -851,117 +889,68 @@ static int ionic_tx_tso(struct ionic_queue *q, struct sk_buff *skb) else hdrlen = skb_transport_offset(skb) + tcp_hdrlen(skb); - seglen = hdrlen + mss; - left = skb_headlen(skb); + tso_rem = len; + seg_rem = min(tso_rem, hdrlen + mss); - desc = ionic_tx_tso_next(q, &elem); - start = true; + frag_idx = 0; + frag_addr = 0; + frag_rem = 0; - /* Chop skb->data up into desc segments */ + start = true; - while (left > 0) { - len = min(seglen, left); - frag_left = seglen - len; - desc_addr = ionic_tx_map_single(q, skb->data + offset, len); - if (dma_mapping_error(dev, desc_addr)) - goto err_out_abort; - desc_len = len; + while (tso_rem > 0) { + desc = NULL; + elem = NULL; + desc_addr = 0; + desc_len = 0; desc_nsge = 0; - left -= len; - offset += len; - if (nfrags > 0 && frag_left > 0) - continue; - done = (nfrags == 0 && left == 0); - ionic_tx_tso_post(q, desc, skb, - desc_addr, desc_nsge, desc_len, - hdrlen, mss, - outer_csum, - vlan_tci, has_vlan, - start, done); - total_pkts++; - total_bytes += start ? len : len + hdrlen; - desc = ionic_tx_tso_next(q, &elem); - start = false; - seglen = mss; - } - - /* Chop skb frags into desc segments */ - - for (frag = skb_shinfo(skb)->frags; len_left; frag++) { - offset = 0; - left = skb_frag_size(frag); - len_left -= left; - nfrags--; - stats->frags++; - - while (left > 0) { - if (frag_left > 0) { - len = min(frag_left, left); - frag_left -= len; - addr = ionic_tx_map_frag(q, frag, offset, len); - if (dma_mapping_error(dev, addr)) - goto err_out_abort; - elem->addr = cpu_to_le64(addr); - elem->len = cpu_to_le16(len); - elem++; - desc_nsge++; - left -= len; - offset += len; - if (nfrags > 0 && frag_left > 0) - continue; - done = (nfrags == 0 && left == 0); - ionic_tx_tso_post(q, desc, skb, desc_addr, - desc_nsge, desc_len, - hdrlen, mss, outer_csum, - vlan_tci, has_vlan, - start, done); - total_pkts++; - total_bytes += start ? len : len + hdrlen; + /* loop until a full tcp segment can be created */ + while (seg_rem > 0) { + /* if the fragment is exhausted get the next one */ + if (frag_rem == 0) { + /* grab the next fragment */ + frag_addr = buf_info[frag_idx].dma_addr; + frag_rem = buf_info[frag_idx].len; + frag_idx++; + } + chunk_len = min(frag_rem, seg_rem); + if (!desc) { + /* fill main descriptor */ desc = ionic_tx_tso_next(q, &elem); - start = false; + desc_addr = frag_addr; + desc_len = chunk_len; } else { - len = min(mss, left); - frag_left = mss - len; - desc_addr = ionic_tx_map_frag(q, frag, - offset, len); - if (dma_mapping_error(dev, desc_addr)) - goto err_out_abort; - desc_len = len; - desc_nsge = 0; - left -= len; - offset += len; - if (nfrags > 0 && frag_left > 0) - continue; - done = (nfrags == 0 && left == 0); - ionic_tx_tso_post(q, desc, skb, desc_addr, - desc_nsge, desc_len, - hdrlen, mss, outer_csum, - vlan_tci, has_vlan, - start, done); - total_pkts++; - total_bytes += start ? len : len + hdrlen; - desc = ionic_tx_tso_next(q, &elem); - start = false; + /* fill sg descriptor */ + elem->addr = cpu_to_le64(frag_addr); + elem->len = cpu_to_le16(chunk_len); + elem++; + desc_nsge++; } + frag_addr += chunk_len; + frag_rem -= chunk_len; + tso_rem -= chunk_len; + seg_rem -= chunk_len; + } + seg_rem = min(tso_rem, mss); + done = (tso_rem == 0); + if (done) { + memcpy(&q->info[q->head_idx].bufs, buf_info, sizeof(buf_info)); + q->info[q->head_idx].nbufs = nfrags + 1; } + /* post descriptor */ + ionic_tx_tso_post(q, desc, skb, + desc_addr, desc_nsge, desc_len, + hdrlen, mss, outer_csum, vlan_tci, has_vlan, + start, done); + start = false; } - stats->pkts += total_pkts; - stats->bytes += total_bytes; + stats->pkts += DIV_ROUND_UP(len - hdrlen, mss); + stats->bytes += len; stats->tso++; - stats->tso_bytes += total_bytes; + stats->tso_bytes = len; return 0; - -err_out_abort: - while (rewind != q->head_idx) { - rewind_desc_info = &q->info[rewind]; - ionic_tx_clean(q, rewind_desc_info, NULL, NULL); - rewind = (rewind + 1) & (q->num_descs - 1); - } - q->head_idx = abort; - - return -ENOMEM; } static int ionic_tx_calc_csum(struct ionic_queue *q, struct sk_buff *skb) From patchwork Tue Mar 16 02:31:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Nelson X-Patchwork-Id: 12141079 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 X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39FE2C43381 for ; Tue, 16 Mar 2021 02:32:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0F49A6503D for ; Tue, 16 Mar 2021 02:32:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234633AbhCPCby (ORCPT ); Mon, 15 Mar 2021 22:31:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234593AbhCPCbt (ORCPT ); Mon, 15 Mar 2021 22:31:49 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15493C06174A for ; Mon, 15 Mar 2021 19:31:49 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id n10so21627233pgl.10 for ; Mon, 15 Mar 2021 19:31:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pensando.io; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=56pbCXUCTIMwBCnBXwsN4mUu3TR1rVl3IjVXaBpHfgs=; b=PUqbPkrgrw9wuKWmPkv5NxyPBSG7+Cyl5Xs2F+aRDO8OK6AYMIE284eARFcPC1c3FO DCJqZjYbSj8KIjOUImDk3kvXi/4Cxxva3LAJfRwckapUYxdFEc4pvts4VcKQlR5Tays4 /2e+3k1SLTWvzJ7IT6toArY4/Z2x9sYxhW6qlxdNfLWeOcPJTPPxPoeqmfVi8y3tgJ4P uMplLgHd/76UmV5IyeZ1Hhevkg1nQ4NzF3hDBSokv/Eiz+dJ+FxjvGECMdsDi6cmD29y CDUfB5wei5xw3aXrkCvOjY+ooPvztqvZum9sQJD5W6CBUgGiCalDNGyt30FuX3qMsFp2 MbCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=56pbCXUCTIMwBCnBXwsN4mUu3TR1rVl3IjVXaBpHfgs=; b=NabRFW8OFHAkTseyRUDNB+iv6uKW97fK+WwpskjHgG+sHnFvfXI9gYKd1Sh3Ymmw2S mY2nM9ZOynjW3i8TPQpmYyfHVC2bJfDIRJU9avQfbElD7V7BXQUS1yUpsnj2YugTLwax Us4M5fnGp8Gu1qAwbBQ92r6UR5MieZw956efUkfNrg0I4eBsl5Pl50SZSsc+N27bZ36p qzAgpANmUdUqmzbHsiENWmDDU9wdkIobAifJ9S5iaDkNh5Vro/W9AbpM9a98M3wi2Bmt 1DR3B+ahtdkZcq2uugTa4ijAv1trmj1UxGUdEkfCpnvoixaqAnq8QLxcWwYGSlCS/bys uOqA== X-Gm-Message-State: AOAM531fuX3ZgdPnoopIkydQVm+3nhpTj8VLx5lehv6gbR5RKRoJIRhn DnFz0qKDe3Vy55OC1/jzREVLGb6h8BJZ9w== X-Google-Smtp-Source: ABdhPJxo+XBGxeAR/uJAzrU3XrjOttxFy+l/2oUnTntOkv9V+fVpgM4b7SUKxOrdQSeJwrL1t2D/8Q== X-Received: by 2002:a63:1312:: with SMTP id i18mr1841291pgl.108.1615861908237; Mon, 15 Mar 2021 19:31:48 -0700 (PDT) Received: from driver-dev1.pensando.io ([12.226.153.42]) by smtp.gmail.com with ESMTPSA id t18sm8687743pgg.33.2021.03.15.19.31.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 19:31:47 -0700 (PDT) From: Shannon Nelson To: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org Cc: drivers@pensando.io, Shannon Nelson Subject: [PATCH net-next 2/4] ionic: generic tx skb mapping Date: Mon, 15 Mar 2021 19:31:34 -0700 Message-Id: <20210316023136.22702-3-snelson@pensando.io> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210316023136.22702-1-snelson@pensando.io> References: <20210316023136.22702-1-snelson@pensando.io> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Make the new ionic_tx_map_tso() usable by the non-TSO paths, and pull the call up a level into ionic_tx() before calling the csum or no-csum routines. Signed-off-by: Shannon Nelson --- .../net/ethernet/pensando/ionic/ionic_txrx.c | 142 +++++++++--------- 1 file changed, 68 insertions(+), 74 deletions(-) diff --git a/drivers/net/ethernet/pensando/ionic/ionic_txrx.c b/drivers/net/ethernet/pensando/ionic/ionic_txrx.c index 639000a2e495..1d27d6cad504 100644 --- a/drivers/net/ethernet/pensando/ionic/ionic_txrx.c +++ b/drivers/net/ethernet/pensando/ionic/ionic_txrx.c @@ -605,11 +605,13 @@ static dma_addr_t ionic_tx_map_frag(struct ionic_queue *q, return dma_addr; } -static int ionic_tx_map_tso(struct ionic_queue *q, struct sk_buff *skb, - struct ionic_buf_info *buf_info) +static int ionic_tx_map_skb(struct ionic_queue *q, struct sk_buff *skb, + struct ionic_desc_info *desc_info) { + struct ionic_buf_info *buf_info = desc_info->bufs; struct device *dev = q->dev; dma_addr_t dma_addr; + unsigned int nfrags; skb_frag_t *frag; int frag_idx; @@ -620,15 +622,19 @@ static int ionic_tx_map_tso(struct ionic_queue *q, struct sk_buff *skb, buf_info->len = skb_headlen(skb); buf_info++; - for (frag_idx = 0; frag_idx < skb_shinfo(skb)->nr_frags; frag_idx++, buf_info++) { - frag = &skb_shinfo(skb)->frags[frag_idx]; + frag = skb_shinfo(skb)->frags; + nfrags = skb_shinfo(skb)->nr_frags; + for (frag_idx = 0; frag_idx < nfrags; frag_idx++, frag++) { dma_addr = ionic_tx_map_frag(q, frag, 0, skb_frag_size(frag)); if (dma_mapping_error(dev, dma_addr)) goto dma_fail; buf_info->dma_addr = dma_addr; buf_info->len = skb_frag_size(frag); + buf_info++; } + desc_info->nbufs = 1 + nfrags; + return 0; dma_fail: @@ -814,40 +820,29 @@ static void ionic_tx_tso_post(struct ionic_queue *q, struct ionic_txq_desc *desc desc->hdr_len = cpu_to_le16(hdrlen); desc->mss = cpu_to_le16(mss); - if (done) { + if (start) { skb_tx_timestamp(skb); netdev_tx_sent_queue(q_to_ndq(q), skb->len); - ionic_txq_post(q, !netdev_xmit_more(), ionic_tx_clean, skb); + ionic_txq_post(q, false, ionic_tx_clean, skb); } else { - ionic_txq_post(q, false, ionic_tx_clean, NULL); + ionic_txq_post(q, done, NULL, NULL); } } -static struct ionic_txq_desc *ionic_tx_tso_next(struct ionic_queue *q, - struct ionic_txq_sg_elem **elem) -{ - struct ionic_txq_sg_desc *sg_desc = q->info[q->head_idx].txq_sg_desc; - struct ionic_txq_desc *desc = q->info[q->head_idx].txq_desc; - - *elem = sg_desc->elems; - return desc; -} - static int ionic_tx_tso(struct ionic_queue *q, struct sk_buff *skb) { - struct ionic_buf_info buf_info[IONIC_MAX_FRAGS] = {{0}}; struct ionic_tx_stats *stats = q_to_tx_stats(q); + struct ionic_desc_info *desc_info; + struct ionic_buf_info *buf_info; struct ionic_txq_sg_elem *elem; struct ionic_txq_desc *desc; unsigned int chunk_len; unsigned int frag_rem; - unsigned int frag_idx; unsigned int tso_rem; unsigned int seg_rem; dma_addr_t desc_addr; dma_addr_t frag_addr; unsigned int hdrlen; - unsigned int nfrags; unsigned int len; unsigned int mss; bool start, done; @@ -859,12 +854,14 @@ static int ionic_tx_tso(struct ionic_queue *q, struct sk_buff *skb) bool encap; int err; - if (unlikely(ionic_tx_map_tso(q, skb, buf_info))) + desc_info = &q->info[q->head_idx]; + buf_info = desc_info->bufs; + + if (unlikely(ionic_tx_map_skb(q, skb, desc_info))) return -EIO; len = skb->len; mss = skb_shinfo(skb)->gso_size; - nfrags = skb_shinfo(skb)->nr_frags; outer_csum = (skb_shinfo(skb)->gso_type & SKB_GSO_GRE_CSUM) || (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_TUNNEL_CSUM); has_vlan = !!skb_vlan_tag_present(skb); @@ -892,7 +889,6 @@ static int ionic_tx_tso(struct ionic_queue *q, struct sk_buff *skb) tso_rem = len; seg_rem = min(tso_rem, hdrlen + mss); - frag_idx = 0; frag_addr = 0; frag_rem = 0; @@ -904,19 +900,20 @@ static int ionic_tx_tso(struct ionic_queue *q, struct sk_buff *skb) desc_addr = 0; desc_len = 0; desc_nsge = 0; - /* loop until a full tcp segment can be created */ + /* use fragments until we have enough to post a single descriptor */ while (seg_rem > 0) { - /* if the fragment is exhausted get the next one */ + /* if the fragment is exhausted then move to the next one */ if (frag_rem == 0) { /* grab the next fragment */ - frag_addr = buf_info[frag_idx].dma_addr; - frag_rem = buf_info[frag_idx].len; - frag_idx++; + frag_addr = buf_info->dma_addr; + frag_rem = buf_info->len; + buf_info++; } chunk_len = min(frag_rem, seg_rem); if (!desc) { /* fill main descriptor */ - desc = ionic_tx_tso_next(q, &elem); + desc = desc_info->txq_desc; + elem = desc_info->txq_sg_desc->elems; desc_addr = frag_addr; desc_len = chunk_len; } else { @@ -933,16 +930,15 @@ static int ionic_tx_tso(struct ionic_queue *q, struct sk_buff *skb) } seg_rem = min(tso_rem, mss); done = (tso_rem == 0); - if (done) { - memcpy(&q->info[q->head_idx].bufs, buf_info, sizeof(buf_info)); - q->info[q->head_idx].nbufs = nfrags + 1; - } /* post descriptor */ ionic_tx_tso_post(q, desc, skb, desc_addr, desc_nsge, desc_len, hdrlen, mss, outer_csum, vlan_tci, has_vlan, start, done); start = false; + /* Buffer information is stored with the first tso descriptor */ + desc_info = &q->info[q->head_idx]; + desc_info->nbufs = 0; } stats->pkts += DIV_ROUND_UP(len - hdrlen, mss); @@ -953,12 +949,12 @@ static int ionic_tx_tso(struct ionic_queue *q, struct sk_buff *skb) return 0; } -static int ionic_tx_calc_csum(struct ionic_queue *q, struct sk_buff *skb) +static int ionic_tx_calc_csum(struct ionic_queue *q, struct sk_buff *skb, + struct ionic_desc_info *desc_info) { - struct ionic_txq_desc *desc = q->info[q->head_idx].txq_desc; + struct ionic_txq_desc *desc = desc_info->txq_desc; + struct ionic_buf_info *buf_info = desc_info->bufs; struct ionic_tx_stats *stats = q_to_tx_stats(q); - struct device *dev = q->dev; - dma_addr_t dma_addr; bool has_vlan; u8 flags = 0; bool encap; @@ -967,23 +963,22 @@ static int ionic_tx_calc_csum(struct ionic_queue *q, struct sk_buff *skb) has_vlan = !!skb_vlan_tag_present(skb); encap = skb->encapsulation; - dma_addr = ionic_tx_map_single(q, skb->data, skb_headlen(skb)); - if (dma_mapping_error(dev, dma_addr)) - return -ENOMEM; - flags |= has_vlan ? IONIC_TXQ_DESC_FLAG_VLAN : 0; flags |= encap ? IONIC_TXQ_DESC_FLAG_ENCAP : 0; cmd = encode_txq_desc_cmd(IONIC_TXQ_DESC_OPCODE_CSUM_PARTIAL, - flags, skb_shinfo(skb)->nr_frags, dma_addr); + flags, skb_shinfo(skb)->nr_frags, + buf_info->dma_addr); desc->cmd = cpu_to_le64(cmd); - desc->len = cpu_to_le16(skb_headlen(skb)); - desc->csum_start = cpu_to_le16(skb_checksum_start_offset(skb)); - desc->csum_offset = cpu_to_le16(skb->csum_offset); + desc->len = cpu_to_le16(buf_info->len); if (has_vlan) { desc->vlan_tci = cpu_to_le16(skb_vlan_tag_get(skb)); stats->vlan_inserted++; + } else { + desc->vlan_tci = 0; } + desc->csum_start = cpu_to_le16(skb_checksum_start_offset(skb)); + desc->csum_offset = cpu_to_le16(skb->csum_offset); if (skb_csum_is_sctp(skb)) stats->crc32_csum++; @@ -993,12 +988,12 @@ static int ionic_tx_calc_csum(struct ionic_queue *q, struct sk_buff *skb) return 0; } -static int ionic_tx_calc_no_csum(struct ionic_queue *q, struct sk_buff *skb) +static int ionic_tx_calc_no_csum(struct ionic_queue *q, struct sk_buff *skb, + struct ionic_desc_info *desc_info) { - struct ionic_txq_desc *desc = q->info[q->head_idx].txq_desc; + struct ionic_txq_desc *desc = desc_info->txq_desc; + struct ionic_buf_info *buf_info = desc_info->bufs; struct ionic_tx_stats *stats = q_to_tx_stats(q); - struct device *dev = q->dev; - dma_addr_t dma_addr; bool has_vlan; u8 flags = 0; bool encap; @@ -1007,67 +1002,66 @@ static int ionic_tx_calc_no_csum(struct ionic_queue *q, struct sk_buff *skb) has_vlan = !!skb_vlan_tag_present(skb); encap = skb->encapsulation; - dma_addr = ionic_tx_map_single(q, skb->data, skb_headlen(skb)); - if (dma_mapping_error(dev, dma_addr)) - return -ENOMEM; - flags |= has_vlan ? IONIC_TXQ_DESC_FLAG_VLAN : 0; flags |= encap ? IONIC_TXQ_DESC_FLAG_ENCAP : 0; cmd = encode_txq_desc_cmd(IONIC_TXQ_DESC_OPCODE_CSUM_NONE, - flags, skb_shinfo(skb)->nr_frags, dma_addr); + flags, skb_shinfo(skb)->nr_frags, + buf_info->dma_addr); desc->cmd = cpu_to_le64(cmd); - desc->len = cpu_to_le16(skb_headlen(skb)); + desc->len = cpu_to_le16(buf_info->len); if (has_vlan) { desc->vlan_tci = cpu_to_le16(skb_vlan_tag_get(skb)); stats->vlan_inserted++; + } else { + desc->vlan_tci = 0; } + desc->csum_start = 0; + desc->csum_offset = 0; stats->csum_none++; return 0; } -static int ionic_tx_skb_frags(struct ionic_queue *q, struct sk_buff *skb) +static int ionic_tx_skb_frags(struct ionic_queue *q, struct sk_buff *skb, + struct ionic_desc_info *desc_info) { - struct ionic_txq_sg_desc *sg_desc = q->info[q->head_idx].txq_sg_desc; - unsigned int len_left = skb->len - skb_headlen(skb); + struct ionic_txq_sg_desc *sg_desc = desc_info->txq_sg_desc; + struct ionic_buf_info *buf_info = &desc_info->bufs[1]; struct ionic_txq_sg_elem *elem = sg_desc->elems; struct ionic_tx_stats *stats = q_to_tx_stats(q); - struct device *dev = q->dev; - dma_addr_t dma_addr; - skb_frag_t *frag; - u16 len; + unsigned int i; - for (frag = skb_shinfo(skb)->frags; len_left; frag++, elem++) { - len = skb_frag_size(frag); - elem->len = cpu_to_le16(len); - dma_addr = ionic_tx_map_frag(q, frag, 0, len); - if (dma_mapping_error(dev, dma_addr)) - return -ENOMEM; - elem->addr = cpu_to_le64(dma_addr); - len_left -= len; - stats->frags++; + for (i = 0; i < skb_shinfo(skb)->nr_frags; i++, buf_info++, elem++) { + elem->addr = cpu_to_le64(buf_info->dma_addr); + elem->len = cpu_to_le16(buf_info->len); } + stats->frags += skb_shinfo(skb)->nr_frags; + return 0; } static int ionic_tx(struct ionic_queue *q, struct sk_buff *skb) { + struct ionic_desc_info *desc_info = &q->info[q->head_idx]; struct ionic_tx_stats *stats = q_to_tx_stats(q); int err; + if (unlikely(ionic_tx_map_skb(q, skb, desc_info))) + return -EIO; + /* set up the initial descriptor */ if (skb->ip_summed == CHECKSUM_PARTIAL) - err = ionic_tx_calc_csum(q, skb); + err = ionic_tx_calc_csum(q, skb, desc_info); else - err = ionic_tx_calc_no_csum(q, skb); + err = ionic_tx_calc_no_csum(q, skb, desc_info); if (err) return err; /* add frags */ - err = ionic_tx_skb_frags(q, skb); + err = ionic_tx_skb_frags(q, skb, desc_info); if (err) return err; From patchwork Tue Mar 16 02:31:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Nelson X-Patchwork-Id: 12141083 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 X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7EE9C433DB for ; Tue, 16 Mar 2021 02:32:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D1D36503B for ; Tue, 16 Mar 2021 02:32:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234653AbhCPCcZ (ORCPT ); Mon, 15 Mar 2021 22:32:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230286AbhCPCcA (ORCPT ); Mon, 15 Mar 2021 22:32:00 -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 36F0EC06174A for ; Mon, 15 Mar 2021 19:31:50 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id f8so2728562plg.10 for ; Mon, 15 Mar 2021 19:31:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pensando.io; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fc9j82bUmoIt25oGNXmDahnI+4tMb7EVHwyfDKYoviY=; b=kVGkGKkJtrn8EdcBN8VscFhyKaZfpYalbfZirb1+O+K88Gv6YbyWXNmNK1TDM2xDiI 2Vz+IPQPvo9CNd1m6f9gPt1T6oLWr7imTy5vGgjRwQ3eQhicmSij4GJ+8X0WmeJtT9WI 84nKYdcVIR8sxjufMzhT5QHhz9nDl8wZMVcwKNqCT0P657g0eeta/BjKOQ0wafDAnGbA lDK5VlYP3GdsLvw2AfcjIdpCSx5/BrFG51hy/Owe3LBMxVq9vbzu4sjeZTvFlm9mS2HS MgIob/TMGc5M3GcW4XIohDoxPCMryCqeIZYtDvI8ok7GS7xK8xTDwG7P53DSaf62hDJI dwRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fc9j82bUmoIt25oGNXmDahnI+4tMb7EVHwyfDKYoviY=; b=rgtwBNRgU7mc9fcAA33Pn01n4j6JPfonfQxeCKbxpxznR3jv/x0NrlsEvjXBnAAl0I 6iM61h3bIRKN0hc8I1RJx79RhIg3UdYbOShoZZnz+za9wLXh9Fo1U9UMNgwUxs6aUOY/ DipnVUnBpdo1OKrPi2dwTBnCyozRXORg9VivvVM+CC3A8lCa5gOMrvRp0nGiCBW8jkMy SVM+sXjssPsP347lH4bmTb81GPpCqq5u0TG0eNKPJk5tL7kwqB45TpYTB87XE/edVc0k qVcMr3sCUQMokZ49BHQP+zAjDW68/snEjJd6EpWFEhhF7bpvedTpc60L+kBX5HhTnDd1 MWLg== X-Gm-Message-State: AOAM530Lvo6hJQ5nyJSINxwCjlPTThkB0szErMjIJ7UhRvnPLgtKGNTD VZcvKKz9VnWD2jvd1euxpcqAuD/GfL7ubw== X-Google-Smtp-Source: ABdhPJxQRIByJ//CdL+MnG3RSdKl7UYhhaxkxAY3rxZtneTuPan1pZRIgoyCYBnkUlP/kQ++sfTikg== X-Received: by 2002:a17:90a:d497:: with SMTP id s23mr2274670pju.148.1615861909522; Mon, 15 Mar 2021 19:31:49 -0700 (PDT) Received: from driver-dev1.pensando.io ([12.226.153.42]) by smtp.gmail.com with ESMTPSA id t18sm8687743pgg.33.2021.03.15.19.31.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 19:31:49 -0700 (PDT) From: Shannon Nelson To: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org Cc: drivers@pensando.io, Shannon Nelson Subject: [PATCH net-next 3/4] ionic: simplify tx clean Date: Mon, 15 Mar 2021 19:31:35 -0700 Message-Id: <20210316023136.22702-4-snelson@pensando.io> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210316023136.22702-1-snelson@pensando.io> References: <20210316023136.22702-1-snelson@pensando.io> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The descriptor mappings are set up the same way whether or not it is a TSO, so we don't need separate logic for the two cases. Signed-off-by: Shannon Nelson --- .../net/ethernet/pensando/ionic/ionic_txrx.c | 30 +++++-------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/drivers/net/ethernet/pensando/ionic/ionic_txrx.c b/drivers/net/ethernet/pensando/ionic/ionic_txrx.c index 1d27d6cad504..f841ccb5adfd 100644 --- a/drivers/net/ethernet/pensando/ionic/ionic_txrx.c +++ b/drivers/net/ethernet/pensando/ionic/ionic_txrx.c @@ -654,35 +654,19 @@ static void ionic_tx_clean(struct ionic_queue *q, struct ionic_cq_info *cq_info, void *cb_arg) { - struct ionic_txq_sg_desc *sg_desc = desc_info->sg_desc; struct ionic_buf_info *buf_info = desc_info->bufs; - struct ionic_txq_sg_elem *elem = sg_desc->elems; struct ionic_tx_stats *stats = q_to_tx_stats(q); - struct ionic_txq_desc *desc = desc_info->desc; struct device *dev = q->dev; - u8 opcode, flags, nsge; u16 queue_index; unsigned int i; - u64 addr; - - decode_txq_desc_cmd(le64_to_cpu(desc->cmd), - &opcode, &flags, &nsge, &addr); - if (opcode != IONIC_TXQ_DESC_OPCODE_TSO) { - dma_unmap_single(dev, (dma_addr_t)addr, - le16_to_cpu(desc->len), DMA_TO_DEVICE); - for (i = 0; i < nsge; i++, elem++) - dma_unmap_page(dev, (dma_addr_t)le64_to_cpu(elem->addr), - le16_to_cpu(elem->len), DMA_TO_DEVICE); - } else { - if (flags & IONIC_TXQ_DESC_FLAG_TSO_EOT) { - dma_unmap_single(dev, (dma_addr_t)buf_info->dma_addr, - buf_info->len, DMA_TO_DEVICE); - buf_info++; - for (i = 1; i < desc_info->nbufs; i++, buf_info++) - dma_unmap_page(dev, (dma_addr_t)buf_info->dma_addr, - buf_info->len, DMA_TO_DEVICE); - } + if (desc_info->nbufs) { + dma_unmap_single(dev, (dma_addr_t)buf_info->dma_addr, + buf_info->len, DMA_TO_DEVICE); + buf_info++; + for (i = 1; i < desc_info->nbufs; i++, buf_info++) + dma_unmap_page(dev, (dma_addr_t)buf_info->dma_addr, + buf_info->len, DMA_TO_DEVICE); } if (cb_arg) { From patchwork Tue Mar 16 02:31:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Nelson X-Patchwork-Id: 12141081 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 X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B74EC4332D for ; Tue, 16 Mar 2021 02:32:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 46C9765055 for ; Tue, 16 Mar 2021 02:32:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234637AbhCPCb6 (ORCPT ); Mon, 15 Mar 2021 22:31:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234594AbhCPCbv (ORCPT ); Mon, 15 Mar 2021 22:31:51 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56D5AC061756 for ; Mon, 15 Mar 2021 19:31:51 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id t37so10821143pga.11 for ; Mon, 15 Mar 2021 19:31:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pensando.io; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=i8GkXn5ZP5S4E5t52lY5YVK+VfG9zlsLyHRTeIs78mw=; b=FQY/fuJRv6xiZWb3DbhhO3nUmcvO+TnCvEk2ZnogREU34HQjqhC2lqo+1RY+nuXnHX heC3YcNGFkwBsF/42l0kKNE+8duOqIBwj1/Tkwg/86A+S8hjclIq5dzTsjnhMoBgsgBE q4mZk1j1Q1t/5biMnJazI6V6s0K7urEeR9+RDiYCQBKhwi+CumdyphSaJ5nJPygeNIhR SDwMu6Vf+rDip9XkmbyyECmSB9GxbNkR1vbTxGHrReDPSauFuz7sJ+FEMnNVYu55Yg5e sHCwogeDB+Pc6bP0lscgMvBAN5I1EVz0BnNgVgwK8Kel6bxWaqWXpMHT8mgDn4H1F1nm sLfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=i8GkXn5ZP5S4E5t52lY5YVK+VfG9zlsLyHRTeIs78mw=; b=M7PYjyIPL9UcBBeRvUj1uNJwBUKrX4cqO5G6dT4XB9M2NlZQS4NBfRcahYb5on8UDZ QB3iEr6d+WUg+lRKv+qUPoN9hy/PosKv36cxHJpLZP8/s8jZTHC6Zq/vGLqZicpGzwI8 2X3IT3icHBG01WYah/RuHljydCptPCVImILOdEmT8+HD1tpYHAgimAuig+PImpGzSX6P r/+reA7NK3BEFNsiPlAoSEyukADVy1MOywep55UfPEXtFfC3nEYgpXqPDuKaxcMmFJ8T 9pNlyHXveASwJv4fyhWF9wOGT6nkSjXb4B10B1vsnm//v4gLnBQwjspBhQjRRlaNhxu0 q1SA== X-Gm-Message-State: AOAM530ZPxlPyzHUq8iGWbMh/Cn6JKAvT0LNqzHzehYr/wwX7QrkeDe0 fSz9YKjTIrbbsoc0nnuX7lSQ32by45phYg== X-Google-Smtp-Source: ABdhPJyAPZdm9bl+eNDJNmEF9idCICsN57816NnSO7uqdPgFmHboEhBzJRTFAlg3ObTZXwTKfnVINQ== X-Received: by 2002:a63:4956:: with SMTP id y22mr1849743pgk.309.1615861910612; Mon, 15 Mar 2021 19:31:50 -0700 (PDT) Received: from driver-dev1.pensando.io ([12.226.153.42]) by smtp.gmail.com with ESMTPSA id t18sm8687743pgg.33.2021.03.15.19.31.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 19:31:50 -0700 (PDT) From: Shannon Nelson To: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org Cc: drivers@pensando.io, Shannon Nelson Subject: [PATCH net-next 4/4] ionic: aggregate Tx byte counting calls Date: Mon, 15 Mar 2021 19:31:36 -0700 Message-Id: <20210316023136.22702-5-snelson@pensando.io> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210316023136.22702-1-snelson@pensando.io> References: <20210316023136.22702-1-snelson@pensando.io> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Gather the Tx packet and byte counts and call netdev_tx_completed_queue() only once per clean cycle. Signed-off-by: Shannon Nelson --- .../net/ethernet/pensando/ionic/ionic_dev.h | 1 + .../net/ethernet/pensando/ionic/ionic_txrx.c | 27 ++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/pensando/ionic/ionic_dev.h b/drivers/net/ethernet/pensando/ionic/ionic_dev.h index d0c969a6d43e..ca7e55455165 100644 --- a/drivers/net/ethernet/pensando/ionic/ionic_dev.h +++ b/drivers/net/ethernet/pensando/ionic/ionic_dev.h @@ -196,6 +196,7 @@ struct ionic_desc_info { struct ionic_txq_sg_desc *txq_sg_desc; struct ionic_rxq_sg_desc *rxq_sgl_desc; }; + unsigned int bytes; unsigned int nbufs; struct ionic_buf_info bufs[IONIC_MAX_FRAGS]; ionic_desc_cb cb; diff --git a/drivers/net/ethernet/pensando/ionic/ionic_txrx.c b/drivers/net/ethernet/pensando/ionic/ionic_txrx.c index f841ccb5adfd..03e00a6c413a 100644 --- a/drivers/net/ethernet/pensando/ionic/ionic_txrx.c +++ b/drivers/net/ethernet/pensando/ionic/ionic_txrx.c @@ -671,7 +671,6 @@ static void ionic_tx_clean(struct ionic_queue *q, if (cb_arg) { struct sk_buff *skb = cb_arg; - u32 len = skb->len; queue_index = skb_get_queue_mapping(skb); if (unlikely(__netif_subqueue_stopped(q->lif->netdev, @@ -679,9 +678,11 @@ static void ionic_tx_clean(struct ionic_queue *q, netif_wake_subqueue(q->lif->netdev, queue_index); q->wake++; } - dev_kfree_skb_any(skb); + + desc_info->bytes = skb->len; stats->clean++; - netdev_tx_completed_queue(q_to_ndq(q), 1, len); + + dev_consume_skb_any(skb); } } @@ -690,6 +691,8 @@ static bool ionic_tx_service(struct ionic_cq *cq, struct ionic_cq_info *cq_info) struct ionic_txq_comp *comp = cq_info->txcq; struct ionic_queue *q = cq->bound_q; struct ionic_desc_info *desc_info; + int bytes = 0; + int pkts = 0; u16 index; if (!color_match(comp->color, cq->done_color)) @@ -700,13 +703,21 @@ static bool ionic_tx_service(struct ionic_cq *cq, struct ionic_cq_info *cq_info) */ do { desc_info = &q->info[q->tail_idx]; + desc_info->bytes = 0; index = q->tail_idx; q->tail_idx = (q->tail_idx + 1) & (q->num_descs - 1); ionic_tx_clean(q, desc_info, cq_info, desc_info->cb_arg); + if (desc_info->cb_arg) { + pkts++; + bytes += desc_info->bytes; + } desc_info->cb = NULL; desc_info->cb_arg = NULL; } while (index != le16_to_cpu(comp->comp_index)); + if (pkts && bytes) + netdev_tx_completed_queue(q_to_ndq(q), pkts, bytes); + return true; } @@ -725,15 +736,25 @@ void ionic_tx_flush(struct ionic_cq *cq) void ionic_tx_empty(struct ionic_queue *q) { struct ionic_desc_info *desc_info; + int bytes = 0; + int pkts = 0; /* walk the not completed tx entries, if any */ while (q->head_idx != q->tail_idx) { desc_info = &q->info[q->tail_idx]; + desc_info->bytes = 0; q->tail_idx = (q->tail_idx + 1) & (q->num_descs - 1); ionic_tx_clean(q, desc_info, NULL, desc_info->cb_arg); + if (desc_info->cb_arg) { + pkts++; + bytes += desc_info->bytes; + } desc_info->cb = NULL; desc_info->cb_arg = NULL; } + + if (pkts && bytes) + netdev_tx_completed_queue(q_to_ndq(q), pkts, bytes); } static int ionic_tx_tcp_inner_pseudo_csum(struct sk_buff *skb)