From patchwork Thu Feb 11 16:18:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sven Van Asbroeck X-Patchwork-Id: 12083683 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 83939C433DB for ; Thu, 11 Feb 2021 16:21:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3C76564E92 for ; Thu, 11 Feb 2021 16:21:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231749AbhBKQVl (ORCPT ); Thu, 11 Feb 2021 11:21:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231842AbhBKQTR (ORCPT ); Thu, 11 Feb 2021 11:19:17 -0500 Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92DEFC061793; Thu, 11 Feb 2021 08:18:36 -0800 (PST) Received: by mail-il1-x12d.google.com with SMTP id e1so5587793ilu.0; Thu, 11 Feb 2021 08:18:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3JhYbeminedAPFen2Lv7pKC466eaYWgZBJCcItxz8ow=; b=qyeao1talBnb/refwHkIwD5A6kxZJja/H9P4w+3pn5V2tArxglMY7n0R/xGdHyTa9H GBtTrucZydEOOfZtC5kZjk2x6gjjvs0QoP0W4m9apuIVkk51pqlNmCTHfvfOpG+CQxWO hAHQuuLpU/wjA1Skke4BqBC69h6giIiu9OUg22Bb4BQWoh1GomGl9erivQHNPL3pQX9A hENB6QmBxzk+dtwmTFGRVc3rk/TA5TLXyMAqOvWf4FvAtAiE8TQrhqXbXmIhCacaLAa9 LSccrppwnpfuFUpPWBeFTPSBaFyuid9PSFq+ocX6cQ3BhTr6er8oo87E8VYq1mR6VRD+ 17wQ== 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:mime-version:content-transfer-encoding; bh=3JhYbeminedAPFen2Lv7pKC466eaYWgZBJCcItxz8ow=; b=JzVL6E2JeyJXd1+3gWL659oaNfMuYms3bqWzSzGJ29BsmL2ghT1iL402dYx2LfomYE bXCYC13a6bRnOe3rDu/IUT2maIaR8NbREDwKlc1eG0XWGjlt3xqrYn4xqbRIazz06/yQ BUQaJUIXLt1KZXq2Tx5D/JiIBtKdR2CX+wrK2qQZ6HOiV1tzso7pFttW33aDNFRC5RC0 WfJ4Dh0j+OMxHkxwgAidb2vuglc5JEsx1Hem7b5qipYXJFPfhayVsij/6uAL0CCt2XF6 P60xIj8KQcbiAlOp8s39fYeZiW7aI6isBj6owuyVIdWXVwTyPnlbG7LTX+iey9FCkqco AFxw== X-Gm-Message-State: AOAM532o8EoRiggGD2FoPtgp1kRR55ArRi0cTCY4GmZ50wp7VdtQGpLc tX10GbAeMiianrc3Fni7bh8= X-Google-Smtp-Source: ABdhPJwuZMS5FBmEFEBSFxaDC0pdT6ucstu/IrcREtNrbhF92av4AZRK8pQzNeWXPj3wT+Dd29dk+g== X-Received: by 2002:a92:6e0b:: with SMTP id j11mr6352837ilc.184.1613060315764; Thu, 11 Feb 2021 08:18:35 -0800 (PST) Received: from localhost.localdomain ([198.52.185.246]) by smtp.gmail.com with ESMTPSA id d135sm2729913iog.35.2021.02.11.08.18.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 08:18:35 -0800 (PST) From: Sven Van Asbroeck X-Google-Original-From: Sven Van Asbroeck To: Bryan Whitehead , UNGLinuxDriver@microchip.com, David S Miller , Jakub Kicinski Cc: Sven Van Asbroeck , Andrew Lunn , Alexey Denisov , Sergej Bauer , Tim Harvey , =?utf-8?q?Anders_R=C3=B8nningen?= , Hillf Danton , Christoph Hellwig , Willem de Bruijn , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 1/5] lan743x: boost performance on cpu archs w/o dma cache snooping Date: Thu, 11 Feb 2021 11:18:26 -0500 Message-Id: <20210211161830.17366-2-TheSven73@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210211161830.17366-1-TheSven73@gmail.com> References: <20210211161830.17366-1-TheSven73@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Sven Van Asbroeck The buffers in the lan743x driver's receive ring are always 9K, even when the largest packet that can be received (the mtu) is much smaller. This performs particularly badly on cpu archs without dma cache snooping (such as ARM): each received packet results in a 9K dma_{map|unmap} operation, which is very expensive because cpu caches need to be invalidated. Careful measurement of the driver rx path on armv7 reveals that the cpu spends the majority of its time waiting for cache invalidation. Optimize by keeping the rx ring buffer size as close as possible to the mtu. This limits the amount of cache that requires invalidation. This optimization would normally force us to re-allocate all ring buffers when the mtu is changed - a disruptive event, because it can only happen when the network interface is down. Remove the need to re-allocate all ring buffers by adding support for multi-buffer frames. Now any combination of mtu and ring buffer size will work. When the mtu changes from mtu1 to mtu2, consumed buffers of size mtu1 are lazily replaced by newly allocated buffers of size mtu2. These optimizations double the rx performance on armv7. Third parties report 3x rx speedup on armv8. Tested with iperf3 on a freescale imx6qp + lan7430, both sides set to mtu 1500 bytes, measure rx performance: Before: [ ID] Interval Transfer Bandwidth Retr [ 4] 0.00-20.00 sec 550 MBytes 231 Mbits/sec 0 After: [ ID] Interval Transfer Bandwidth Retr [ 4] 0.00-20.00 sec 1.33 GBytes 570 Mbits/sec 0 Signed-off-by: Sven Van Asbroeck Reviewed-by: Bryan Whitehead --- To: Bryan Whitehead To: UNGLinuxDriver@microchip.com To: "David S. Miller" To: Jakub Kicinski Cc: Andrew Lunn Cc: Alexey Denisov Cc: Sergej Bauer Cc: Tim Harvey Cc: Anders Rønningen Cc: Hillf Danton Cc: Christoph Hellwig Cc: Willem de Bruijn Cc: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org drivers/net/ethernet/microchip/lan743x_main.c | 325 ++++++++---------- drivers/net/ethernet/microchip/lan743x_main.h | 5 +- 2 files changed, 149 insertions(+), 181 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c index f1f6eba4ace4..0c48bb559719 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -1955,15 +1955,6 @@ static int lan743x_rx_next_index(struct lan743x_rx *rx, int index) return ((++index) % rx->ring_size); } -static struct sk_buff *lan743x_rx_allocate_skb(struct lan743x_rx *rx) -{ - int length = 0; - - length = (LAN743X_MAX_FRAME_SIZE + ETH_HLEN + 4 + RX_HEAD_PADDING); - return __netdev_alloc_skb(rx->adapter->netdev, - length, GFP_ATOMIC | GFP_DMA); -} - static void lan743x_rx_update_tail(struct lan743x_rx *rx, int index) { /* update the tail once per 8 descriptors */ @@ -1972,36 +1963,40 @@ static void lan743x_rx_update_tail(struct lan743x_rx *rx, int index) index); } -static int lan743x_rx_init_ring_element(struct lan743x_rx *rx, int index, - struct sk_buff *skb) +static int lan743x_rx_init_ring_element(struct lan743x_rx *rx, int index) { + struct net_device *netdev = rx->adapter->netdev; + struct device *dev = &rx->adapter->pdev->dev; struct lan743x_rx_buffer_info *buffer_info; struct lan743x_rx_descriptor *descriptor; - int length = 0; + struct sk_buff *skb; + dma_addr_t dma_ptr; + int length; + + length = netdev->mtu + ETH_HLEN + 4 + RX_HEAD_PADDING; - length = (LAN743X_MAX_FRAME_SIZE + ETH_HLEN + 4 + RX_HEAD_PADDING); descriptor = &rx->ring_cpu_ptr[index]; buffer_info = &rx->buffer_info[index]; - buffer_info->skb = skb; - if (!(buffer_info->skb)) + skb = __netdev_alloc_skb(netdev, length, GFP_ATOMIC | GFP_DMA); + if (!skb) return -ENOMEM; - buffer_info->dma_ptr = dma_map_single(&rx->adapter->pdev->dev, - buffer_info->skb->data, - length, - DMA_FROM_DEVICE); - if (dma_mapping_error(&rx->adapter->pdev->dev, - buffer_info->dma_ptr)) { - buffer_info->dma_ptr = 0; + dma_ptr = dma_map_single(dev, skb->data, length, DMA_FROM_DEVICE); + if (dma_mapping_error(dev, dma_ptr)) { + dev_kfree_skb_any(skb); return -ENOMEM; } + if (buffer_info->dma_ptr) + dma_unmap_single(dev, buffer_info->dma_ptr, + buffer_info->buffer_length, DMA_FROM_DEVICE); + buffer_info->skb = skb; + buffer_info->dma_ptr = dma_ptr; buffer_info->buffer_length = length; descriptor->data1 = cpu_to_le32(DMA_ADDR_LOW32(buffer_info->dma_ptr)); descriptor->data2 = cpu_to_le32(DMA_ADDR_HIGH32(buffer_info->dma_ptr)); descriptor->data3 = 0; descriptor->data0 = cpu_to_le32((RX_DESC_DATA0_OWN_ | (length & RX_DESC_DATA0_BUF_LENGTH_MASK_))); - skb_reserve(buffer_info->skb, RX_HEAD_PADDING); lan743x_rx_update_tail(rx, index); return 0; @@ -2050,16 +2045,32 @@ static void lan743x_rx_release_ring_element(struct lan743x_rx *rx, int index) memset(buffer_info, 0, sizeof(*buffer_info)); } -static int lan743x_rx_process_packet(struct lan743x_rx *rx) +static struct sk_buff * +lan743x_rx_trim_skb(struct sk_buff *skb, int frame_length) +{ + if (skb_linearize(skb)) { + dev_kfree_skb_irq(skb); + return NULL; + } + frame_length = max_t(int, 0, frame_length - RX_HEAD_PADDING - 2); + if (skb->len > frame_length) { + skb->tail -= skb->len - frame_length; + skb->len = frame_length; + } + return skb; +} + +static int lan743x_rx_process_buffer(struct lan743x_rx *rx) { - struct skb_shared_hwtstamps *hwtstamps = NULL; - int result = RX_PROCESS_RESULT_NOTHING_TO_DO; int current_head_index = le32_to_cpu(*rx->head_cpu_ptr); + struct lan743x_rx_descriptor *descriptor, *desc_ext; + struct net_device *netdev = rx->adapter->netdev; + int result = RX_PROCESS_RESULT_NOTHING_TO_DO; struct lan743x_rx_buffer_info *buffer_info; - struct lan743x_rx_descriptor *descriptor; + int frame_length, buffer_length; int extension_index = -1; - int first_index = -1; - int last_index = -1; + bool is_last, is_first; + struct sk_buff *skb; if (current_head_index < 0 || current_head_index >= rx->ring_size) goto done; @@ -2067,163 +2078,121 @@ static int lan743x_rx_process_packet(struct lan743x_rx *rx) if (rx->last_head < 0 || rx->last_head >= rx->ring_size) goto done; - if (rx->last_head != current_head_index) { - descriptor = &rx->ring_cpu_ptr[rx->last_head]; - if (le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_OWN_) - goto done; + if (rx->last_head == current_head_index) + goto done; - if (!(le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_FS_)) - goto done; + descriptor = &rx->ring_cpu_ptr[rx->last_head]; + if (le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_OWN_) + goto done; + buffer_info = &rx->buffer_info[rx->last_head]; - first_index = rx->last_head; - if (le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_LS_) { - last_index = rx->last_head; - } else { - int index; - - index = lan743x_rx_next_index(rx, first_index); - while (index != current_head_index) { - descriptor = &rx->ring_cpu_ptr[index]; - if (le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_OWN_) - goto done; - - if (le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_LS_) { - last_index = index; - break; - } - index = lan743x_rx_next_index(rx, index); - } - } - if (last_index >= 0) { - descriptor = &rx->ring_cpu_ptr[last_index]; - if (le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_EXT_) { - /* extension is expected to follow */ - int index = lan743x_rx_next_index(rx, - last_index); - if (index != current_head_index) { - descriptor = &rx->ring_cpu_ptr[index]; - if (le32_to_cpu(descriptor->data0) & - RX_DESC_DATA0_OWN_) { - goto done; - } - if (le32_to_cpu(descriptor->data0) & - RX_DESC_DATA0_EXT_) { - extension_index = index; - } else { - goto done; - } - } else { - /* extension is not yet available */ - /* prevent processing of this packet */ - first_index = -1; - last_index = -1; - } - } - } - } - if (first_index >= 0 && last_index >= 0) { - int real_last_index = last_index; - struct sk_buff *skb = NULL; - u32 ts_sec = 0; - u32 ts_nsec = 0; - - /* packet is available */ - if (first_index == last_index) { - /* single buffer packet */ - struct sk_buff *new_skb = NULL; - int packet_length; - - new_skb = lan743x_rx_allocate_skb(rx); - if (!new_skb) { - /* failed to allocate next skb. - * Memory is very low. - * Drop this packet and reuse buffer. - */ - lan743x_rx_reuse_ring_element(rx, first_index); - goto process_extension; - } + is_last = le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_LS_; + is_first = le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_FS_; - buffer_info = &rx->buffer_info[first_index]; - skb = buffer_info->skb; - descriptor = &rx->ring_cpu_ptr[first_index]; - - /* unmap from dma */ - if (buffer_info->dma_ptr) { - dma_unmap_single(&rx->adapter->pdev->dev, - buffer_info->dma_ptr, - buffer_info->buffer_length, - DMA_FROM_DEVICE); - buffer_info->dma_ptr = 0; - buffer_info->buffer_length = 0; - } - buffer_info->skb = NULL; - packet_length = RX_DESC_DATA0_FRAME_LENGTH_GET_ - (le32_to_cpu(descriptor->data0)); - skb_put(skb, packet_length - 4); - skb->protocol = eth_type_trans(skb, - rx->adapter->netdev); - lan743x_rx_init_ring_element(rx, first_index, new_skb); - } else { - int index = first_index; + if (is_last && le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_EXT_) { + /* extension is expected to follow */ + int index = lan743x_rx_next_index(rx, rx->last_head); - /* multi buffer packet not supported */ - /* this should not happen since - * buffers are allocated to be at least jumbo size - */ + if (index == current_head_index) + /* extension not yet available */ + goto done; + desc_ext = &rx->ring_cpu_ptr[index]; + if (le32_to_cpu(desc_ext->data0) & RX_DESC_DATA0_OWN_) + /* extension not yet available */ + goto done; + if (!(le32_to_cpu(desc_ext->data0) & RX_DESC_DATA0_EXT_)) + goto move_forward; + extension_index = index; + } - /* clean up buffers */ - if (first_index <= last_index) { - while ((index >= first_index) && - (index <= last_index)) { - lan743x_rx_reuse_ring_element(rx, - index); - index = lan743x_rx_next_index(rx, - index); - } - } else { - while ((index >= first_index) || - (index <= last_index)) { - lan743x_rx_reuse_ring_element(rx, - index); - index = lan743x_rx_next_index(rx, - index); - } - } - } + /* Only the last buffer in a multi-buffer frame contains the total frame + * length. All other buffers have a zero frame length. The chip + * occasionally sends more buffers than strictly required to reach the + * total frame length. + * Handle this by adding all buffers to the skb in their entirety. + * Once the real frame length is known, trim the skb. + */ + frame_length = + RX_DESC_DATA0_FRAME_LENGTH_GET_(le32_to_cpu(descriptor->data0)); + buffer_length = buffer_info->buffer_length; + + netdev_dbg(netdev, "%s%schunk: %d/%d", + is_first ? "first " : " ", + is_last ? "last " : " ", + frame_length, buffer_length); + + /* save existing skb, allocate new skb and map to dma */ + skb = buffer_info->skb; + if (lan743x_rx_init_ring_element(rx, rx->last_head)) { + /* failed to allocate next skb. + * Memory is very low. + * Drop this packet and reuse buffer. + */ + lan743x_rx_reuse_ring_element(rx, rx->last_head); + /* drop packet that was being assembled */ + dev_kfree_skb_irq(rx->skb_head); + rx->skb_head = NULL; + goto process_extension; + } + + /* add buffers to skb via skb->frag_list */ + if (is_first) { + skb_reserve(skb, RX_HEAD_PADDING); + skb_put(skb, buffer_length - RX_HEAD_PADDING); + if (rx->skb_head) + dev_kfree_skb_irq(rx->skb_head); + rx->skb_head = skb; + } else if (rx->skb_head) { + skb_put(skb, buffer_length); + if (skb_shinfo(rx->skb_head)->frag_list) + rx->skb_tail->next = skb; + else + skb_shinfo(rx->skb_head)->frag_list = skb; + rx->skb_tail = skb; + rx->skb_head->len += skb->len; + rx->skb_head->data_len += skb->len; + rx->skb_head->truesize += skb->truesize; + } else { + /* packet to assemble has already been dropped because one or + * more of its buffers could not be allocated + */ + netdev_dbg(netdev, "drop buffer intended for dropped packet"); + dev_kfree_skb_irq(skb); + } process_extension: - if (extension_index >= 0) { - descriptor = &rx->ring_cpu_ptr[extension_index]; - buffer_info = &rx->buffer_info[extension_index]; - - ts_sec = le32_to_cpu(descriptor->data1); - ts_nsec = (le32_to_cpu(descriptor->data2) & - RX_DESC_DATA2_TS_NS_MASK_); - lan743x_rx_reuse_ring_element(rx, extension_index); - real_last_index = extension_index; - } + if (extension_index >= 0) { + u32 ts_sec; + u32 ts_nsec; - if (!skb) { - result = RX_PROCESS_RESULT_PACKET_DROPPED; - goto move_forward; - } + ts_sec = le32_to_cpu(desc_ext->data1); + ts_nsec = (le32_to_cpu(desc_ext->data2) & + RX_DESC_DATA2_TS_NS_MASK_); + if (rx->skb_head) + skb_hwtstamps(rx->skb_head)->hwtstamp = + ktime_set(ts_sec, ts_nsec); + lan743x_rx_reuse_ring_element(rx, extension_index); + rx->last_head = extension_index; + netdev_dbg(netdev, "process extension"); + } - if (extension_index < 0) - goto pass_packet_to_os; - hwtstamps = skb_hwtstamps(skb); - if (hwtstamps) - hwtstamps->hwtstamp = ktime_set(ts_sec, ts_nsec); + if (is_last && rx->skb_head) + rx->skb_head = lan743x_rx_trim_skb(rx->skb_head, frame_length); -pass_packet_to_os: - /* pass packet to OS */ - napi_gro_receive(&rx->napi, skb); - result = RX_PROCESS_RESULT_PACKET_RECEIVED; + if (is_last && rx->skb_head) { + rx->skb_head->protocol = eth_type_trans(rx->skb_head, + rx->adapter->netdev); + netdev_dbg(netdev, "sending %d byte frame to OS", + rx->skb_head->len); + napi_gro_receive(&rx->napi, rx->skb_head); + rx->skb_head = NULL; + } move_forward: - /* push tail and head forward */ - rx->last_tail = real_last_index; - rx->last_head = lan743x_rx_next_index(rx, real_last_index); - } + /* push tail and head forward */ + rx->last_tail = rx->last_head; + rx->last_head = lan743x_rx_next_index(rx, rx->last_head); + result = RX_PROCESS_RESULT_BUFFER_RECEIVED; done: return result; } @@ -2242,12 +2211,12 @@ static int lan743x_rx_napi_poll(struct napi_struct *napi, int weight) DMAC_INT_BIT_RXFRM_(rx->channel_number)); } for (count = 0; count < weight; count++) { - result = lan743x_rx_process_packet(rx); + result = lan743x_rx_process_buffer(rx); if (result == RX_PROCESS_RESULT_NOTHING_TO_DO) break; } rx->frame_count += count; - if (count == weight || result == RX_PROCESS_RESULT_PACKET_RECEIVED) + if (count == weight || result == RX_PROCESS_RESULT_BUFFER_RECEIVED) return weight; if (!napi_complete_done(napi, count)) @@ -2359,9 +2328,7 @@ static int lan743x_rx_ring_init(struct lan743x_rx *rx) rx->last_head = 0; for (index = 0; index < rx->ring_size; index++) { - struct sk_buff *new_skb = lan743x_rx_allocate_skb(rx); - - ret = lan743x_rx_init_ring_element(rx, index, new_skb); + ret = lan743x_rx_init_ring_element(rx, index); if (ret) goto cleanup; } diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/ethernet/microchip/lan743x_main.h index 751f2bc9ce84..40dfb564c4f7 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.h +++ b/drivers/net/ethernet/microchip/lan743x_main.h @@ -698,6 +698,8 @@ struct lan743x_rx { struct napi_struct napi; u32 frame_count; + + struct sk_buff *skb_head, *skb_tail; }; struct lan743x_adapter { @@ -831,8 +833,7 @@ struct lan743x_rx_buffer_info { #define LAN743X_RX_RING_SIZE (65) #define RX_PROCESS_RESULT_NOTHING_TO_DO (0) -#define RX_PROCESS_RESULT_PACKET_RECEIVED (1) -#define RX_PROCESS_RESULT_PACKET_DROPPED (2) +#define RX_PROCESS_RESULT_BUFFER_RECEIVED (1) u32 lan743x_csr_read(struct lan743x_adapter *adapter, int offset); void lan743x_csr_write(struct lan743x_adapter *adapter, int offset, u32 data); From patchwork Thu Feb 11 16:18:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sven Van Asbroeck X-Patchwork-Id: 12083687 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 0441AC433DB for ; Thu, 11 Feb 2021 16:22:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF06964E8B for ; Thu, 11 Feb 2021 16:22:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231766AbhBKQVz (ORCPT ); Thu, 11 Feb 2021 11:21:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231843AbhBKQTT (ORCPT ); Thu, 11 Feb 2021 11:19:19 -0500 Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1392C061794; Thu, 11 Feb 2021 08:18:37 -0800 (PST) Received: by mail-il1-x131.google.com with SMTP id e1so5587860ilu.0; Thu, 11 Feb 2021 08:18:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Xp4N40JfQ3VVDOWjhEqow9AAoJ4Ma4pLuM+YDtd7UgM=; b=mtj2EYF6jZubD9FqRDnVGO9Nzrt3asJMR6eRmNxbiQmeLXJ41KzQgcAiw75aFbcaIO XPth5rq7hMm1y17IJJZ+zMgqgt2YmiL0V+BsYh+gdSQYKEo7E8/3F+aQY0ktGOEqe/px pFbs9oljojdEg3MJTwUVjVE2TMW3nEH6TxWItZ64TK/v+wpK1FAQmHvvamESNccCdmbU FfYnEFQN9BpDwxA70u2lW30+BCL3OtmUpnEzHJGDHc6vgXwrCFRrv5vnFWEBn3Ya8NEH 3e22qb+GPWZDHlWpSBB8NPYsZGPJdtS3opt+wylkai8fTrVcCOsOgHcaaTsEvLssb7Qi AT/A== 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:mime-version:content-transfer-encoding; bh=Xp4N40JfQ3VVDOWjhEqow9AAoJ4Ma4pLuM+YDtd7UgM=; b=MDo/e9agMYa9sXfMRgrdmcaQ2OGWL3LltQQAVhES0C2q3CDtvOP0NIktM+oDooEFmj YgumdcgiI9ADxuRevlNzn5j4GjlQLzBg7DODb72++dn1gD9Uz8XqBkoDW0sKIzfCA0ZX BAP5zWe7SdyDJkZTilEDDE3saM6DRCc8xE8QPayHS4k3ZLk1hNaSk6SKYSw5FypOZOY7 h9Zx37m3uJXAmDaK9GcUbLJH/oVNCbfvYA3SHnPHHNnMIrjrZCWxdTLXYutiBVf65aUy bjsB1ReK8XI44T2dYjtOVXSir+BCTZ7tzXInNaIYzdKeBYaYcSJNJLWmWxu8m/eMXzBe dUAw== X-Gm-Message-State: AOAM533gRNyb9HPkL07hI4ZVHq1NmxZ1dcNWbX8TA7lEe7qIyLNehYFv qra1uswVInyLFQlGOvJdgfw= X-Google-Smtp-Source: ABdhPJyiRlMHOsnmLmk554WUf5bF1KkI+XEFPfqpzLjvZdMmtjUIkeHE6mkOmWAVM76TZBe0rVi15w== X-Received: by 2002:a92:c00f:: with SMTP id q15mr6330193ild.62.1613060316991; Thu, 11 Feb 2021 08:18:36 -0800 (PST) Received: from localhost.localdomain ([198.52.185.246]) by smtp.gmail.com with ESMTPSA id d135sm2729913iog.35.2021.02.11.08.18.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 08:18:36 -0800 (PST) From: Sven Van Asbroeck X-Google-Original-From: Sven Van Asbroeck To: Bryan Whitehead , UNGLinuxDriver@microchip.com, David S Miller , Jakub Kicinski Cc: Sven Van Asbroeck , Andrew Lunn , Alexey Denisov , Sergej Bauer , Tim Harvey , =?utf-8?q?Anders_R=C3=B8nningen?= , Hillf Danton , Christoph Hellwig , Willem de Bruijn , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 2/5] lan743x: sync only the received area of an rx ring buffer Date: Thu, 11 Feb 2021 11:18:27 -0500 Message-Id: <20210211161830.17366-3-TheSven73@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210211161830.17366-1-TheSven73@gmail.com> References: <20210211161830.17366-1-TheSven73@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Sven Van Asbroeck On cpu architectures w/o dma cache snooping, dma_unmap() is a is a very expensive operation, because its resulting sync needs to invalidate cpu caches. Increase efficiency/performance by syncing only those sections of the lan743x's rx ring buffers that are actually in use. Signed-off-by: Sven Van Asbroeck --- To: Bryan Whitehead To: UNGLinuxDriver@microchip.com To: "David S. Miller" To: Jakub Kicinski Cc: Andrew Lunn Cc: Alexey Denisov Cc: Sergej Bauer Cc: Tim Harvey Cc: Anders Rønningen Cc: Hillf Danton Cc: Christoph Hellwig Cc: Willem de Bruijn Cc: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org drivers/net/ethernet/microchip/lan743x_main.c | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c index 0c48bb559719..36cc67c72851 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -1968,35 +1968,49 @@ static int lan743x_rx_init_ring_element(struct lan743x_rx *rx, int index) struct net_device *netdev = rx->adapter->netdev; struct device *dev = &rx->adapter->pdev->dev; struct lan743x_rx_buffer_info *buffer_info; + unsigned int buffer_length, packet_length; struct lan743x_rx_descriptor *descriptor; struct sk_buff *skb; dma_addr_t dma_ptr; - int length; - length = netdev->mtu + ETH_HLEN + 4 + RX_HEAD_PADDING; + buffer_length = netdev->mtu + ETH_HLEN + 4 + RX_HEAD_PADDING; descriptor = &rx->ring_cpu_ptr[index]; buffer_info = &rx->buffer_info[index]; - skb = __netdev_alloc_skb(netdev, length, GFP_ATOMIC | GFP_DMA); + skb = __netdev_alloc_skb(netdev, buffer_length, GFP_ATOMIC | GFP_DMA); if (!skb) return -ENOMEM; - dma_ptr = dma_map_single(dev, skb->data, length, DMA_FROM_DEVICE); + dma_ptr = dma_map_single(dev, skb->data, buffer_length, DMA_FROM_DEVICE); if (dma_mapping_error(dev, dma_ptr)) { dev_kfree_skb_any(skb); return -ENOMEM; } - if (buffer_info->dma_ptr) - dma_unmap_single(dev, buffer_info->dma_ptr, - buffer_info->buffer_length, DMA_FROM_DEVICE); + if (buffer_info->dma_ptr) { + /* unmap from dma */ + packet_length = RX_DESC_DATA0_FRAME_LENGTH_GET_ + (le32_to_cpu(descriptor->data0)); + if (packet_length == 0 || + packet_length > buffer_info->buffer_length) + /* buffer is part of multi-buffer packet: fully used */ + packet_length = buffer_info->buffer_length; + /* sync used part of buffer only */ + dma_sync_single_for_cpu(dev, buffer_info->dma_ptr, + packet_length, + DMA_FROM_DEVICE); + dma_unmap_single_attrs(dev, buffer_info->dma_ptr, + buffer_info->buffer_length, + DMA_FROM_DEVICE, + DMA_ATTR_SKIP_CPU_SYNC); + } buffer_info->skb = skb; buffer_info->dma_ptr = dma_ptr; - buffer_info->buffer_length = length; + buffer_info->buffer_length = buffer_length; descriptor->data1 = cpu_to_le32(DMA_ADDR_LOW32(buffer_info->dma_ptr)); descriptor->data2 = cpu_to_le32(DMA_ADDR_HIGH32(buffer_info->dma_ptr)); descriptor->data3 = 0; descriptor->data0 = cpu_to_le32((RX_DESC_DATA0_OWN_ | - (length & RX_DESC_DATA0_BUF_LENGTH_MASK_))); + (buffer_length & RX_DESC_DATA0_BUF_LENGTH_MASK_))); lan743x_rx_update_tail(rx, index); return 0; From patchwork Thu Feb 11 16:18:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sven Van Asbroeck X-Patchwork-Id: 12083691 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 610B0C433E0 for ; Thu, 11 Feb 2021 16:23:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B7F864E92 for ; Thu, 11 Feb 2021 16:23:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231883AbhBKQWm (ORCPT ); Thu, 11 Feb 2021 11:22:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231860AbhBKQTb (ORCPT ); Thu, 11 Feb 2021 11:19:31 -0500 Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09E21C061797; Thu, 11 Feb 2021 08:18:39 -0800 (PST) Received: by mail-il1-x129.google.com with SMTP id m20so5514358ilj.13; Thu, 11 Feb 2021 08:18:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=C5Y/YYGLT27TTbQWPy2GuX5CRZJc9WquBjUOYm1/AT0=; b=tWkwSUdxV+qF50Lxp8/LWfJ3wIhNLj8xz5PO9Ww/WuKme3jF8nb6obAf7sdaGQdmBr SQeKvfrELao/Fkxc7bxIxrzkWHhhoK+qf83bD5cDgUBMUzMTQ6bSxzyrQrNG/ZP1Bg+k SAT/YJp0Ux6n6OyuiBZbYfdiZPpu2IAA21BMaEglT/Ou9IPHyWLT4/hnl2bI4cRfSCwP WSOvn/WkxF+FIQ0+g2Oux2BoF5iCFDJFaXskJlPp124uNBe47dI2R87mjGU3W0rEPVtd aRzFzZXgcM4JdwZTfnIO9CiKf1UY2PELT5KywmoZNaKchC4+g6n7WNJOpbyy+aKkfz6/ pE9Q== 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:mime-version:content-transfer-encoding; bh=C5Y/YYGLT27TTbQWPy2GuX5CRZJc9WquBjUOYm1/AT0=; b=HDGArOKZ6GY+Q/BRInP4yyMYxqSNEbif1tmGUGjh54FuUWz9V3qCN+YQdGd4tpAPcC WucNaoica3qy6NUoPoLgnPuqWTIsBn0VoXqhnOEZxfApYLWVWwhxyG7HUopOFeIGeGL6 YMMopB6FNTLPMKV+VPIE8BGasfTX0jhIDSmCFvlfRTUSgzRIM2fIt77ogP7NpicDr1sd /G0hxlrR1W4DIROMF16syu96cvF9jI2KwtO2cTw1gKiCySgK0R3vnNBCW4ERuAJ3u+Vu HXHj6YWBVOyQ6RjOQc9GXp+GTFQiEp2fFeUqIvAJjk8H+utEc3WWns3Om8qs0lbQJuxl p1Pg== X-Gm-Message-State: AOAM532eDMTo9vjOQBWEKfvptA5nr4b2DjzxrJ4y2qotyNGHop7GuHXu tYFsIJA+wHAbd3aSs/hh1p4= X-Google-Smtp-Source: ABdhPJz9J4p6111K+XvJ3TS0WDuNYQjoJfMUq5OIN8RVwWi64WwGIBLWvIo51OF4Y+9XdfBlfyMWPg== X-Received: by 2002:a92:c781:: with SMTP id c1mr6310007ilk.74.1613060318313; Thu, 11 Feb 2021 08:18:38 -0800 (PST) Received: from localhost.localdomain ([198.52.185.246]) by smtp.gmail.com with ESMTPSA id d135sm2729913iog.35.2021.02.11.08.18.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 08:18:37 -0800 (PST) From: Sven Van Asbroeck X-Google-Original-From: Sven Van Asbroeck To: Bryan Whitehead , UNGLinuxDriver@microchip.com, David S Miller , Jakub Kicinski Cc: Sven Van Asbroeck , Andrew Lunn , Alexey Denisov , Sergej Bauer , Tim Harvey , =?utf-8?q?Anders_R=C3=B8nningen?= , Hillf Danton , Christoph Hellwig , Willem de Bruijn , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 3/5] TEST ONLY: lan743x: limit rx ring buffer size to 500 bytes Date: Thu, 11 Feb 2021 11:18:28 -0500 Message-Id: <20210211161830.17366-4-TheSven73@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210211161830.17366-1-TheSven73@gmail.com> References: <20210211161830.17366-1-TheSven73@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Sven Van Asbroeck Signed-off-by: Sven Van Asbroeck --- To: Bryan Whitehead To: UNGLinuxDriver@microchip.com To: "David S. Miller" To: Jakub Kicinski Cc: Andrew Lunn Cc: Alexey Denisov Cc: Sergej Bauer Cc: Tim Harvey Cc: Anders Rønningen Cc: Hillf Danton Cc: Christoph Hellwig Cc: Willem de Bruijn Cc: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org drivers/net/ethernet/microchip/lan743x_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c index 36cc67c72851..90d49231494d 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -1973,7 +1973,7 @@ static int lan743x_rx_init_ring_element(struct lan743x_rx *rx, int index) struct sk_buff *skb; dma_addr_t dma_ptr; - buffer_length = netdev->mtu + ETH_HLEN + 4 + RX_HEAD_PADDING; + buffer_length = 500 + ETH_HLEN + 4 + RX_HEAD_PADDING; descriptor = &rx->ring_cpu_ptr[index]; buffer_info = &rx->buffer_info[index]; From patchwork Thu Feb 11 16:18:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sven Van Asbroeck X-Patchwork-Id: 12083689 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 9EDB6C433E0 for ; Thu, 11 Feb 2021 16:22:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4077B64E92 for ; Thu, 11 Feb 2021 16:22:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231858AbhBKQWX (ORCPT ); Thu, 11 Feb 2021 11:22:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231857AbhBKQTb (ORCPT ); Thu, 11 Feb 2021 11:19:31 -0500 Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C64FC0617A7; Thu, 11 Feb 2021 08:18:40 -0800 (PST) Received: by mail-io1-xd2f.google.com with SMTP id u8so6209631ior.13; Thu, 11 Feb 2021 08:18:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n9Lhs45v53vKs8blqT5xx3avh0Ky4AFVSwRqrogf4Kc=; b=QjgIxtA4Y8mhJo/VAl/qdtaXPMK1H4QqSEx/YPmco/Z4H0okgU6lXaSona8jWzYyRb lwksMVAhj92wSO8wkBqc8l8tRIoCTgGLzDLX9nM2+9cBGvR7y4e0fdJIPubtIBhbWQ0J VxQnN469xBCne+EAjgk2wTwCfFZsXGlDxZA6UoBtR8T+JRGXCstKpbdFwb/6X4EW8ccx Ub+qZChiZr9qytPhO7X2ITT8WJlUuEuqwPDbEtU6wuGQh6qHxDu5ZVOWw1jCjMGcksYT MGZgNyTqlLWy2Vhj1mwmjHF19CnfQxku/EhUcRxAl+FX1myupTO/+v5GL2OHS0ae4ieG jLIw== 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:mime-version:content-transfer-encoding; bh=n9Lhs45v53vKs8blqT5xx3avh0Ky4AFVSwRqrogf4Kc=; b=G94NaEfkbYfQc8eesVPQCpxFVg9msE/5/AWj0FBZxHMZtotYeSzbBh/+TggCqYYwuy C79SrN+TYvF8dNZsvxmqrnF1hANci2saNqAmfAHHhVucmjrepUM+pK0D13w9dnGRZhkM YLdsHsDHsbJahvzWW4TyPwwFViqGqUSpSZrKYbkc5CD7sDraRDTVXFH00FJxscgRmG29 JvRaVbRhw7Zr2STVneDp+mCslEAd/d+JAl50D5l0kzHIO2tNWwxm4ihz0A9EaD9hB5Ln soP4GAbYp+2P1a1yUrJcWFhIMZykEXnpkgd0odDZfQ4/N5ISEIwv8HGX2xlpju+y/K5J NJhQ== X-Gm-Message-State: AOAM531rAO0BvYh/3OEN7xtYg1MXYrF3S4tL1RQE1VuOSqD6zqRGTsvg rs3eJsRJolhFMMZzjehOiz4= X-Google-Smtp-Source: ABdhPJwDwAcCh8k+TeG2+JSo9wEcbcl6UCYhwtkL2cOwP/izDt8c0Odwx6rKjeaTrJ3xoHyl0+BsWA== X-Received: by 2002:a05:6602:24c4:: with SMTP id h4mr6265993ioe.7.1613060319554; Thu, 11 Feb 2021 08:18:39 -0800 (PST) Received: from localhost.localdomain ([198.52.185.246]) by smtp.gmail.com with ESMTPSA id d135sm2729913iog.35.2021.02.11.08.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 08:18:39 -0800 (PST) From: Sven Van Asbroeck X-Google-Original-From: Sven Van Asbroeck To: Bryan Whitehead , UNGLinuxDriver@microchip.com, David S Miller , Jakub Kicinski Cc: Sven Van Asbroeck , Andrew Lunn , Alexey Denisov , Sergej Bauer , Tim Harvey , =?utf-8?q?Anders_R=C3=B8nningen?= , Hillf Danton , Christoph Hellwig , Willem de Bruijn , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 4/5] TEST ONLY: lan743x: skb_alloc failure test Date: Thu, 11 Feb 2021 11:18:29 -0500 Message-Id: <20210211161830.17366-5-TheSven73@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210211161830.17366-1-TheSven73@gmail.com> References: <20210211161830.17366-1-TheSven73@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Sven Van Asbroeck Simulate low-memory in lan743x_rx_allocate_skb(): fail 10 allocations in a row in every 100. Signed-off-by: Sven Van Asbroeck --- To: Bryan Whitehead To: UNGLinuxDriver@microchip.com To: "David S. Miller" To: Jakub Kicinski Cc: Andrew Lunn Cc: Alexey Denisov Cc: Sergej Bauer Cc: Tim Harvey Cc: Anders Rønningen Cc: Hillf Danton Cc: Christoph Hellwig Cc: Willem de Bruijn Cc: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org drivers/net/ethernet/microchip/lan743x_main.c | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c index 90d49231494d..0094ecac5741 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -1963,7 +1963,20 @@ static void lan743x_rx_update_tail(struct lan743x_rx *rx, int index) index); } -static int lan743x_rx_init_ring_element(struct lan743x_rx *rx, int index) +static struct sk_buff * +lan743x_alloc_skb(struct net_device *netdev, int length, bool can_fail) +{ + static int rx_alloc; + int counter = rx_alloc++ % 100; + + if (can_fail && counter >= 20 && counter < 30) + return NULL; + + return __netdev_alloc_skb(netdev, length, GFP_ATOMIC | GFP_DMA); +} + +static int +lan743x_rx_init_ring_element(struct lan743x_rx *rx, int index, bool can_fail) { struct net_device *netdev = rx->adapter->netdev; struct device *dev = &rx->adapter->pdev->dev; @@ -1977,7 +1990,7 @@ static int lan743x_rx_init_ring_element(struct lan743x_rx *rx, int index) descriptor = &rx->ring_cpu_ptr[index]; buffer_info = &rx->buffer_info[index]; - skb = __netdev_alloc_skb(netdev, buffer_length, GFP_ATOMIC | GFP_DMA); + skb = lan743x_alloc_skb(netdev, buffer_length, can_fail); if (!skb) return -ENOMEM; dma_ptr = dma_map_single(dev, skb->data, buffer_length, DMA_FROM_DEVICE); @@ -2137,7 +2150,7 @@ static int lan743x_rx_process_buffer(struct lan743x_rx *rx) /* save existing skb, allocate new skb and map to dma */ skb = buffer_info->skb; - if (lan743x_rx_init_ring_element(rx, rx->last_head)) { + if (lan743x_rx_init_ring_element(rx, rx->last_head, true)) { /* failed to allocate next skb. * Memory is very low. * Drop this packet and reuse buffer. @@ -2342,7 +2355,7 @@ static int lan743x_rx_ring_init(struct lan743x_rx *rx) rx->last_head = 0; for (index = 0; index < rx->ring_size; index++) { - ret = lan743x_rx_init_ring_element(rx, index); + ret = lan743x_rx_init_ring_element(rx, index, false); if (ret) goto cleanup; } From patchwork Thu Feb 11 16:18:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sven Van Asbroeck X-Patchwork-Id: 12083693 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 889EFC433E0 for ; Thu, 11 Feb 2021 16:24:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5667C64E8B for ; Thu, 11 Feb 2021 16:24:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231593AbhBKQYE (ORCPT ); Thu, 11 Feb 2021 11:24:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231359AbhBKQUp (ORCPT ); Thu, 11 Feb 2021 11:20:45 -0500 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 993C4C0617A9; Thu, 11 Feb 2021 08:18:41 -0800 (PST) Received: by mail-io1-xd32.google.com with SMTP id e24so6261415ioc.1; Thu, 11 Feb 2021 08:18:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K5uPwCPOWjfw9QcfeAo+s6B96+MXudquzTFEC9qlVfA=; b=mxh8Gano4tVdhpguaNZWelHqNOmkAq8FmGzX0wxTgCYjQmg/f8HCtqz8yBSrMgb/h2 rzuKKdf6SdJrCKykcLmFFGGb8hf3OimOdSSTm2XGvTJ5MLN0Oiicr3mAU1rN65CVBy2R NTie4EPk5PIx/dqJ0IiWr1J+F95Nj0Fs4e1Uref68ETIamy7C+nyNh/pCT4Dq3RfchV6 HZmToU16BKUcX8zOby3Rs3lpv7ns5+UZLJ2h/bsjqn27KJoZWiB/DDLF05sDCnklxZ5a K6s9xpYNNoPMBo/FhnpVTPO6Ea4jvys/UQdE8dCBmQsmNrogL38O8Ee2vAq27mW/vOkK 7qrw== 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:mime-version:content-transfer-encoding; bh=K5uPwCPOWjfw9QcfeAo+s6B96+MXudquzTFEC9qlVfA=; b=ENVQNdHFNZk0h5kOoQm/bgDQTlmaDI0nNKy/HXwfi2tVI3NMKskK0eZFd4YvK7lG1q 54deMRTrZu0wdpytpBHEtuhyK0cEv3HCyq+WuOieunMjYL5MTO8lzMlgmXUuFa4y7uiU 0Iw6O4EvbUts12mkm43SIYJOw0NWLZakdZeVnaCn9DrvOqY0uJMrXbDcfkWZ22m1RMlI v9hAl2RmiXrhURPztJ3/wKoG1AkjTpjPlWqn4On0Y0XWM9SPhvvPnH7LM7JFuAQV4GhS qLYJGChYGYZjUF5M+4zqr0loqwsRCbHWyPBTOX31gkjj50nIdIYPnhjsgDk1gQEtb60d MfsQ== X-Gm-Message-State: AOAM532AIiQKzy3KQHcQtukYUjUsNiTQvZz9glXHw1ZzVwzjOpkMTXYa Ph4oNjKLcoEROtPqcItpjfk= X-Google-Smtp-Source: ABdhPJzEMaoG8P6yCpQTf3XOCHDJoKcWoMkTVAg+gIl6vGFzU09Gilm1YOBR3bIUAcgyz72dCl5Pig== X-Received: by 2002:a6b:7e41:: with SMTP id k1mr6052264ioq.81.1613060320923; Thu, 11 Feb 2021 08:18:40 -0800 (PST) Received: from localhost.localdomain ([198.52.185.246]) by smtp.gmail.com with ESMTPSA id d135sm2729913iog.35.2021.02.11.08.18.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 08:18:40 -0800 (PST) From: Sven Van Asbroeck X-Google-Original-From: Sven Van Asbroeck To: Bryan Whitehead , UNGLinuxDriver@microchip.com, David S Miller , Jakub Kicinski Cc: Sven Van Asbroeck , Andrew Lunn , Alexey Denisov , Sergej Bauer , Tim Harvey , =?utf-8?q?Anders_R=C3=B8nningen?= , Hillf Danton , Christoph Hellwig , Willem de Bruijn , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 5/5] TEST ONLY: lan743x: skb_trim failure test Date: Thu, 11 Feb 2021 11:18:30 -0500 Message-Id: <20210211161830.17366-6-TheSven73@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210211161830.17366-1-TheSven73@gmail.com> References: <20210211161830.17366-1-TheSven73@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Sven Van Asbroeck Simulate low-memory in lan743x_rx_trim_skb(): fail one allocation in every 100. Signed-off-by: Sven Van Asbroeck --- To: Bryan Whitehead To: UNGLinuxDriver@microchip.com To: "David S. Miller" To: Jakub Kicinski Cc: Andrew Lunn Cc: Alexey Denisov Cc: Sergej Bauer Cc: Tim Harvey Cc: Anders Rønningen Cc: Hillf Danton Cc: Christoph Hellwig Cc: Willem de Bruijn Cc: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org drivers/net/ethernet/microchip/lan743x_main.c | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c index 0094ecac5741..53c2b93b82b4 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -1963,20 +1963,7 @@ static void lan743x_rx_update_tail(struct lan743x_rx *rx, int index) index); } -static struct sk_buff * -lan743x_alloc_skb(struct net_device *netdev, int length, bool can_fail) -{ - static int rx_alloc; - int counter = rx_alloc++ % 100; - - if (can_fail && counter >= 20 && counter < 30) - return NULL; - - return __netdev_alloc_skb(netdev, length, GFP_ATOMIC | GFP_DMA); -} - -static int -lan743x_rx_init_ring_element(struct lan743x_rx *rx, int index, bool can_fail) +static int lan743x_rx_init_ring_element(struct lan743x_rx *rx, int index) { struct net_device *netdev = rx->adapter->netdev; struct device *dev = &rx->adapter->pdev->dev; @@ -1990,7 +1977,7 @@ lan743x_rx_init_ring_element(struct lan743x_rx *rx, int index, bool can_fail) descriptor = &rx->ring_cpu_ptr[index]; buffer_info = &rx->buffer_info[index]; - skb = lan743x_alloc_skb(netdev, buffer_length, can_fail); + skb = __netdev_alloc_skb(netdev, buffer_length, GFP_ATOMIC | GFP_DMA); if (!skb) return -ENOMEM; dma_ptr = dma_map_single(dev, skb->data, buffer_length, DMA_FROM_DEVICE); @@ -2075,6 +2062,13 @@ static void lan743x_rx_release_ring_element(struct lan743x_rx *rx, int index) static struct sk_buff * lan743x_rx_trim_skb(struct sk_buff *skb, int frame_length) { + static int trim_cnt; + + if ((trim_cnt++ % 100) == 77) { + dev_kfree_skb_irq(skb); + return NULL; + } + if (skb_linearize(skb)) { dev_kfree_skb_irq(skb); return NULL; @@ -2150,7 +2144,7 @@ static int lan743x_rx_process_buffer(struct lan743x_rx *rx) /* save existing skb, allocate new skb and map to dma */ skb = buffer_info->skb; - if (lan743x_rx_init_ring_element(rx, rx->last_head, true)) { + if (lan743x_rx_init_ring_element(rx, rx->last_head)) { /* failed to allocate next skb. * Memory is very low. * Drop this packet and reuse buffer. @@ -2355,7 +2349,7 @@ static int lan743x_rx_ring_init(struct lan743x_rx *rx) rx->last_head = 0; for (index = 0; index < rx->ring_size; index++) { - ret = lan743x_rx_init_ring_element(rx, index, false); + ret = lan743x_rx_init_ring_element(rx, index); if (ret) goto cleanup; }