Received: by 10.213.65.68 with SMTP id h4csp1803379imn; Thu, 29 Mar 2018 11:19:21 -0700 (PDT) X-Google-Smtp-Source: AIpwx49nMaQF3GbPOuo/7eSX/zyaQPMPI1y83o19PNgZbLz4h2GMtNjB+jLGn9T6DrW+cRHeuxtW X-Received: by 10.99.109.198 with SMTP id i189mr6260233pgc.328.1522347561714; Thu, 29 Mar 2018 11:19:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522347561; cv=none; d=google.com; s=arc-20160816; b=C1TyODg3GGKCIxRFZT9yNhAgLISfEtHp9XghxI+JzDY6UfPGQhwNEUpzygwTjWDm2f /k7Bepp7iEcHMiG31oGifryp2vBT6kXHWZ9rR+YjIacerPM8E/L6MkeupBf0pow9tE0v ViWcoVPYOnly1pP0LW9vAbs+4oh6v4alIs2lGEhKVIU3Jene5fDPscYuQAa4iVBaJNOM fkYMA8YCq+rg6BEHxJEwy04dhqj9rEbYYbWjKBNa3GbWvAVPnrQXur9xd72AKnJcmd3g d9geUH7VUtqZE9j0z6SRIg+AuLUW316gKlQ5cabnSeziGq4rAjJ1eTV/L+NgrDqgGFpa HP5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=/NFH2srUFQ4Uc1y7i1PPVxZUt56L3hkDzaeyoXXaEz0=; b=HdAHkbM+RdmTBx6PSLwsZSJc6nxiMzLZZJkmIbzZRN52+JL2BbFYy1V3UOs8y0ZnAN 5caUdkNp44tljeU2f31vTe9QPghkIdazKvhnJLkRntgh9yrEEvEBlVnY/RRF0gdZJFMU ZsdQ8LP3k8mpBs5FTuLaxkGZPDasqOy8MpC1Net3ZUFCkrWFTFdavfwZRSdWO/zcvRkv a4Z6vVwFKz9QjZkC5UBNeouxXOydSXwE0FQqQ6JMAhOkSM7xMGs84hPj6lqai1Wf7co+ d4Vy+S1kB7SEe7AMnywpbJgYtXPwKt/tNyoo/370rGwcHzXqsO33GairOcqFwNnU5Si6 akrA== 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 k6si4692992pff.267.2018.03.29.11.19.07; Thu, 29 Mar 2018 11:19:21 -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 S1753871AbeC2SRw (ORCPT + 99 others); Thu, 29 Mar 2018 14:17:52 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:59854 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753876AbeC2SHC (ORCPT ); Thu, 29 Mar 2018 14:07:02 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 023FE982; Thu, 29 Mar 2018 18:07:01 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Florian Fainelli , "David S. Miller" Subject: [PATCH 4.9 26/28] net: systemport: Rewrite __bcm_sysport_tx_reclaim() Date: Thu, 29 Mar 2018 20:00:45 +0200 Message-Id: <20180329175736.551698073@linuxfoundation.org> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180329175733.447823703@linuxfoundation.org> References: <20180329175733.447823703@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Florian Fainelli [ Upstream commit 484d802d0f2f29c335563fcac2a8facf174a1bbc ] There is no need for complex checking between the last consumed index and current consumed index, a simple subtraction will do. This also eliminates the possibility of a permanent transmit queue stall under the following conditions: - one CPU bursts ring->size worth of traffic (up to 256 buffers), to the point where we run out of free descriptors, so we stop the transmit queue at the end of bcm_sysport_xmit() - because of our locking, we have the transmit process disable interrupts which means we can be blocking the TX reclamation process - when TX reclamation finally runs, we will be computing the difference between ring->c_index (last consumed index by SW) and what the HW reports through its register - this register is masked with (ring->size - 1) = 0xff, which will lead to stripping the upper bits of the index (register is 16-bits wide) - we will be computing last_tx_cn as 0, which means there is no work to be done, and we never wake-up the transmit queue, leaving it permanently disabled A practical example is e.g: ring->c_index aka last_c_index = 12, we pushed 256 entries, HW consumer index = 268, we mask it with 0xff = 12, so last_tx_cn == 0, nothing happens. Fixes: 80105befdb4b ("net: systemport: add Broadcom SYSTEMPORT Ethernet MAC driver") Signed-off-by: Florian Fainelli Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/broadcom/bcmsysport.c | 33 +++++++++++++---------------- drivers/net/ethernet/broadcom/bcmsysport.h | 2 - 2 files changed, 16 insertions(+), 19 deletions(-) --- a/drivers/net/ethernet/broadcom/bcmsysport.c +++ b/drivers/net/ethernet/broadcom/bcmsysport.c @@ -707,37 +707,33 @@ static unsigned int __bcm_sysport_tx_rec struct bcm_sysport_tx_ring *ring) { struct net_device *ndev = priv->netdev; - unsigned int c_index, last_c_index, last_tx_cn, num_tx_cbs; unsigned int pkts_compl = 0, bytes_compl = 0; + unsigned int txbds_processed = 0; struct bcm_sysport_cb *cb; + unsigned int txbds_ready; + unsigned int c_index; u32 hw_ind; /* Compute how many descriptors have been processed since last call */ hw_ind = tdma_readl(priv, TDMA_DESC_RING_PROD_CONS_INDEX(ring->index)); c_index = (hw_ind >> RING_CONS_INDEX_SHIFT) & RING_CONS_INDEX_MASK; - ring->p_index = (hw_ind & RING_PROD_INDEX_MASK); - - last_c_index = ring->c_index; - num_tx_cbs = ring->size; - - c_index &= (num_tx_cbs - 1); - - if (c_index >= last_c_index) - last_tx_cn = c_index - last_c_index; - else - last_tx_cn = num_tx_cbs - last_c_index + c_index; + txbds_ready = (c_index - ring->c_index) & RING_CONS_INDEX_MASK; netif_dbg(priv, tx_done, ndev, - "ring=%d c_index=%d last_tx_cn=%d last_c_index=%d\n", - ring->index, c_index, last_tx_cn, last_c_index); + "ring=%d old_c_index=%u c_index=%u txbds_ready=%u\n", + ring->index, ring->c_index, c_index, txbds_ready); - while (last_tx_cn-- > 0) { - cb = ring->cbs + last_c_index; + while (txbds_processed < txbds_ready) { + cb = &ring->cbs[ring->clean_index]; bcm_sysport_tx_reclaim_one(priv, cb, &bytes_compl, &pkts_compl); ring->desc_count++; - last_c_index++; - last_c_index &= (num_tx_cbs - 1); + txbds_processed++; + + if (likely(ring->clean_index < ring->size - 1)) + ring->clean_index++; + else + ring->clean_index = 0; } ring->c_index = c_index; @@ -1207,6 +1203,7 @@ static int bcm_sysport_init_tx_ring(stru netif_tx_napi_add(priv->netdev, &ring->napi, bcm_sysport_tx_poll, 64); ring->index = index; ring->size = size; + ring->clean_index = 0; ring->alloc_size = ring->size; ring->desc_cpu = p; ring->desc_count = ring->size; --- a/drivers/net/ethernet/broadcom/bcmsysport.h +++ b/drivers/net/ethernet/broadcom/bcmsysport.h @@ -638,7 +638,7 @@ struct bcm_sysport_tx_ring { unsigned int desc_count; /* Number of descriptors */ unsigned int curr_desc; /* Current descriptor */ unsigned int c_index; /* Last consumer index */ - unsigned int p_index; /* Current producer index */ + unsigned int clean_index; /* Current clean index */ struct bcm_sysport_cb *cbs; /* Transmit control blocks */ struct dma_desc *desc_cpu; /* CPU view of the descriptor */ struct bcm_sysport_priv *priv; /* private context backpointer */