From patchwork Wed May 9 16:24:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Salil Mehta X-Patchwork-Id: 135307 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp5842187lji; Wed, 9 May 2018 09:26:34 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr6/cMN6JrVdS0mNArXRc1xrE4JKjBty4dslvFzBL4DA2aFduRw1Pm8Hgp2eO1QC+H6ms6s X-Received: by 10.98.220.78 with SMTP id t75mr44371064pfg.139.1525883194386; Wed, 09 May 2018 09:26:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525883194; cv=none; d=google.com; s=arc-20160816; b=ZGyV901sdH6yGc2pz9V7AB+lfPDlZjWMYxwYFZi4yATm/On09dzafrSkHLdk/Q2ICe AZboFxpc+hpuJAFnz0JKjLDD8ogI/yrhjQXswitZYG82JpUYlfGH2kX7kC0XtOWvSZzD sfih3qcDJwSTjmgc68vEnCWA5pbTznrDLiGoIZ8f4oaDC0OeKsJFF09+H9W9en3OnT4O +GTP++pcRAFqnVHOxgHsPmbG/PNt5aythtlZihs1a2wKzA8gcNuebRBl3SqDPrbI4Ak+ RaWJL7iJHokrcnQgWi9mhFeCPMrjcOl6WC4dYxfubxh4XN3UtHqZxN170HpxZGpm83cJ cZaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=ZOMrEfqghoLZ0BJkARNzMkmzZkBuBytprGPd8FuoFJ0=; b=gDHGh8V33rtwLzPMeyodg6BHlw0CaYLYwXcYKpAD7CWO4k4FTUZKpPkHFq4OHRjyLx al7fjQAqEBR0XZ0hnm1sE7enouSz490llwbVK35IvD+MAJBfn6U7kIushHkZcvTXVoCs 9+VsoTtfzREA/FDNkCtd7AEOjukDG4Pf5cJjXc9JjTOTvjzgtDpDC0EGFvDPWCbSicQa B//mmTNsnw7Lgbs4TiYyYxTgFOEXmM5Dmdp7pZMrV0bzQ0L2don/qwTKH9AG5/8isAYg 9o5GjA3d1Jwj3GN6eT7q4T0gLKnC2Vc/qaLYKlwMnUU7VpOVs50wPYluKsetVSziaiXw hDJw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b6-v6si27073142plm.153.2018.05.09.09.26.34; Wed, 09 May 2018 09:26:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965571AbeEIQ0W (ORCPT + 29 others); Wed, 9 May 2018 12:26:22 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:42813 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S965513AbeEIQ0R (ORCPT ); Wed, 9 May 2018 12:26:17 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 884E8CB17C4DD; Thu, 10 May 2018 00:26:14 +0800 (CST) Received: from S00293818-DELL1.china.huawei.com (10.202.227.234) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.361.1; Thu, 10 May 2018 00:26:05 +0800 From: Salil Mehta To: CC: , , , , , , , Yunsheng Lin Subject: [PATCH net-next 3/4] net: hns3: fix for cleaning ring problem Date: Wed, 9 May 2018 17:24:40 +0100 Message-ID: <20180509162441.18068-4-salil.mehta@huawei.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20180509162441.18068-1-salil.mehta@huawei.com> References: <20180509162441.18068-1-salil.mehta@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.202.227.234] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yunsheng Lin The head or tail in hardware is not longer valid when resetting, current hns3_clear_all_ring use them to clean the ring, which will cause problem during resetting. This patch fixes it by using next_to_use and next_to_clean in the ring struct. Fixes: 76ad4f0ee747 ("net: hns3: Add support of HNS3 Ethernet Driver for hip08 SoC") Signed-off-by: Yunsheng Lin Signed-off-by: Peng Li Signed-off-by: Salil Mehta --- drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 34 ++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) -- 2.7.4 diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c index bd8e14b..4031174 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -3203,9 +3203,35 @@ static void hns3_recover_hw_addr(struct net_device *ndev) hns3_nic_mc_sync(ndev, ha->addr); } -static void hns3_drop_skb_data(struct hns3_enet_ring *ring, struct sk_buff *skb) +static void hns3_clear_tx_ring(struct hns3_enet_ring *ring) { - dev_kfree_skb_any(skb); + if (!HNAE3_IS_TX_RING(ring)) + return; + + while (ring->next_to_clean != ring->next_to_use) { + hns3_free_buffer_detach(ring, ring->next_to_clean); + ring_ptr_move_fw(ring, next_to_clean); + } +} + +static void hns3_clear_rx_ring(struct hns3_enet_ring *ring) +{ + if (HNAE3_IS_TX_RING(ring)) + return; + + while (ring->next_to_use != ring->next_to_clean) { + /* When a buffer is not reused, it's memory has been + * freed in hns3_handle_rx_bd or will be freed by + * stack, so only need to unmap the buffer here. + */ + if (!ring->desc_cb[ring->next_to_use].reuse_flag) { + hns3_unmap_buffer(ring, + &ring->desc_cb[ring->next_to_use]); + ring->desc_cb[ring->next_to_use].dma = 0; + } + + ring_ptr_move_fw(ring, next_to_use); + } } static void hns3_clear_all_ring(struct hnae3_handle *h) @@ -3219,13 +3245,13 @@ static void hns3_clear_all_ring(struct hnae3_handle *h) struct hns3_enet_ring *ring; ring = priv->ring_data[i].ring; - hns3_clean_tx_ring(ring, ring->desc_num); + hns3_clear_tx_ring(ring); dev_queue = netdev_get_tx_queue(ndev, priv->ring_data[i].queue_index); netdev_tx_reset_queue(dev_queue); ring = priv->ring_data[i + h->kinfo.num_tqps].ring; - hns3_clean_rx_ring(ring, ring->desc_num, hns3_drop_skb_data); + hns3_clear_rx_ring(ring); } }