Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3975814pxb; Tue, 25 Jan 2022 00:26:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJyCXZwXERPWLrdh3VSIFH7E0vcrXY/upBsWsFFQqsZtu3OJylNUlHy51483oSfI5iKFoU9x X-Received: by 2002:a05:6402:8c9:: with SMTP id d9mr6591720edz.54.1643099163078; Tue, 25 Jan 2022 00:26:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643099163; cv=none; d=google.com; s=arc-20160816; b=dJvyStR2S/+1flHH7ReLtOxxXxcQwSzQshSZs6mzsz5BsQnTfHpiceMJLpwIM/uEZT vP1OrmMigY8qWRXFzDg69wrjZ3f7Rsaa8P9AiV98LxfG2wuxyXEQFVwWfbGlOK6jOLR2 m4QfnW7js/j8O9yC35lnnNLfmfsyOf9+SzNzX0uw9uXNdAQYWqqkv6puFedkAipDQo9/ K6gezKgzddRs0lnb3biJYAE8nP6uw+5IHuMtHMMYt3gLbRfQd5xpVZqPZKbVznbF4WuY g+WlwOGhV468ezNCFNxARDbdcrQigbsWq1Zkvygngolk/+6eXlT+fNOY9Q/fmJMHh2is zjlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=stakaT/LYuXT4h8wF1JinhA9qU3wVgvsIaIMtMuZLhI=; b=zIjcEPteewC2Tt2EEP09pS8F8yndbXSGnssUv2itJCVILMV8ZGB2QZb1G1gupgjCrm onVTJkw13M3QCF9RVxVFu5kAbLIdheONgvuECwjFwH8H36hcejPCBd1rX3eyBnss3+Ej A5MgjGKS31Fc7485dlnujCkcguk61weTssbZxsq5jW6xHlzYJooYhKFFF9cvEWatKbcy 6BBor0ItwW1gPFGUiPCyxwb2+S6nq99Ks5XFWjDi1WAAsKlbx+uulUCm8lzhdlk7i/PY DcHM0BcNp/8JiuMqqZ02XWWtEikJ9229ZhUTdq2EQB+w9QiPWV9TtdQ8a+BIQuq8Bl2u BbZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LpVDu3+9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v13si10549449edb.457.2022.01.25.00.25.38; Tue, 25 Jan 2022 00:26:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LpVDu3+9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352990AbiAYC14 (ORCPT + 99 others); Mon, 24 Jan 2022 21:27:56 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:48884 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378614AbiAXUHr (ORCPT ); Mon, 24 Jan 2022 15:07:47 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 24B72B81544; Mon, 24 Jan 2022 20:07:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CC40C340E5; Mon, 24 Jan 2022 20:07:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643054864; bh=br/iQTyRsURcetzVqnQpSl1GiGq29hfg10350Q/e9Ew=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LpVDu3+9mWvN2wjDwgkCEgewy4tY/EJVgh8ZVg8lNrIdt7y8iNyKMYR/VrZtZnBpK QVJ5SHPq7Lnl+cseu61w1JafGmOKsz2En5ASKOODQzDGJzZpi5xMaoD1p24UtLATtQ LFy0WgVLvCY7+tSRMiNUjFleU1sYliSLma/8Fg8I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robert Hancock , "David S. Miller" Subject: [PATCH 5.10 527/563] net: axienet: fix for TX busy handling Date: Mon, 24 Jan 2022 19:44:52 +0100 Message-Id: <20220124184042.656055898@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184024.407936072@linuxfoundation.org> References: <20220124184024.407936072@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Robert Hancock commit bb193e3db8b86a63f26889c99e14fd30c9ebd72a upstream. Network driver documentation indicates we should be avoiding returning NETDEV_TX_BUSY from ndo_start_xmit in normal cases, since it requires the packets to be requeued. Instead the queue should be stopped after a packet is added to the TX ring when there may not be enough room for an additional one. Also, when TX ring entries are completed, we should only wake the queue if we know there is room for another full maximally fragmented packet. Print a warning if there is insufficient space at the start of start_xmit, since this should no longer happen. Combined with increasing the default TX ring size (in a subsequent patch), this appears to recover the TX performance lost by previous changes to actually manage the TX ring state properly. Fixes: 8a3b7a252dca9 ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet driver") Signed-off-by: Robert Hancock Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 86 ++++++++++++---------- 1 file changed, 47 insertions(+), 39 deletions(-) --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c @@ -661,6 +661,32 @@ static int axienet_free_tx_chain(struct } /** + * axienet_check_tx_bd_space - Checks if a BD/group of BDs are currently busy + * @lp: Pointer to the axienet_local structure + * @num_frag: The number of BDs to check for + * + * Return: 0, on success + * NETDEV_TX_BUSY, if any of the descriptors are not free + * + * This function is invoked before BDs are allocated and transmission starts. + * This function returns 0 if a BD or group of BDs can be allocated for + * transmission. If the BD or any of the BDs are not free the function + * returns a busy status. This is invoked from axienet_start_xmit. + */ +static inline int axienet_check_tx_bd_space(struct axienet_local *lp, + int num_frag) +{ + struct axidma_bd *cur_p; + + /* Ensure we see all descriptor updates from device or TX IRQ path */ + rmb(); + cur_p = &lp->tx_bd_v[(lp->tx_bd_tail + num_frag) % lp->tx_bd_num]; + if (cur_p->cntrl) + return NETDEV_TX_BUSY; + return 0; +} + +/** * axienet_start_xmit_done - Invoked once a transmit is completed by the * Axi DMA Tx channel. * @ndev: Pointer to the net_device structure @@ -689,33 +715,8 @@ static void axienet_start_xmit_done(stru /* Matches barrier in axienet_start_xmit */ smp_mb(); - netif_wake_queue(ndev); -} - -/** - * axienet_check_tx_bd_space - Checks if a BD/group of BDs are currently busy - * @lp: Pointer to the axienet_local structure - * @num_frag: The number of BDs to check for - * - * Return: 0, on success - * NETDEV_TX_BUSY, if any of the descriptors are not free - * - * This function is invoked before BDs are allocated and transmission starts. - * This function returns 0 if a BD or group of BDs can be allocated for - * transmission. If the BD or any of the BDs are not free the function - * returns a busy status. This is invoked from axienet_start_xmit. - */ -static inline int axienet_check_tx_bd_space(struct axienet_local *lp, - int num_frag) -{ - struct axidma_bd *cur_p; - - /* Ensure we see all descriptor updates from device or TX IRQ path */ - rmb(); - cur_p = &lp->tx_bd_v[(lp->tx_bd_tail + num_frag) % lp->tx_bd_num]; - if (cur_p->cntrl) - return NETDEV_TX_BUSY; - return 0; + if (!axienet_check_tx_bd_space(lp, MAX_SKB_FRAGS + 1)) + netif_wake_queue(ndev); } /** @@ -748,19 +749,14 @@ axienet_start_xmit(struct sk_buff *skb, cur_p = &lp->tx_bd_v[lp->tx_bd_tail]; if (axienet_check_tx_bd_space(lp, num_frag + 1)) { - if (netif_queue_stopped(ndev)) - return NETDEV_TX_BUSY; - + /* Should not happen as last start_xmit call should have + * checked for sufficient space and queue should only be + * woken when sufficient space is available. + */ netif_stop_queue(ndev); - - /* Matches barrier in axienet_start_xmit_done */ - smp_mb(); - - /* Space might have just been freed - check again */ - if (axienet_check_tx_bd_space(lp, num_frag + 1)) - return NETDEV_TX_BUSY; - - netif_wake_queue(ndev); + if (net_ratelimit()) + netdev_warn(ndev, "TX ring unexpectedly full\n"); + return NETDEV_TX_BUSY; } if (skb->ip_summed == CHECKSUM_PARTIAL) { @@ -821,6 +817,18 @@ axienet_start_xmit(struct sk_buff *skb, if (++lp->tx_bd_tail >= lp->tx_bd_num) lp->tx_bd_tail = 0; + /* Stop queue if next transmit may not have space */ + if (axienet_check_tx_bd_space(lp, MAX_SKB_FRAGS + 1)) { + netif_stop_queue(ndev); + + /* Matches barrier in axienet_start_xmit_done */ + smp_mb(); + + /* Space might have just been freed - check again */ + if (!axienet_check_tx_bd_space(lp, MAX_SKB_FRAGS + 1)) + netif_wake_queue(ndev); + } + return NETDEV_TX_OK; }