Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3685354pxb; Mon, 24 Jan 2022 15:18:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJzZgKRXyZW3TJ/UFbyKNS5P7Ze2nJrtnmRMSKalAwUzAiW2F0EVBNGOhQBLH9yXk8Tl6Z3T X-Received: by 2002:a17:902:ecc4:b0:14a:15a7:c3d3 with SMTP id a4-20020a170902ecc400b0014a15a7c3d3mr16271974plh.117.1643066337307; Mon, 24 Jan 2022 15:18:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643066337; cv=none; d=google.com; s=arc-20160816; b=IsTMbXr5B4HbYYL3yywuz+Vc8A02x6DbRlYqzEztyYVd4jV8znBHYSKgEJVYyTngfV 6Amzny18yg88zn4v1V4VdB2v0+v8rYOlJt+INzN9MUOdhT1oVXkxQgJ4ksrRMHeLIn9n mBhfosrzEmR22XwnL8rh8O3IrWMEo5zAy9WU7IFY90TxIg0nwntOfd4TB2loxsngBisW ewARBYYIgG2dJNglRzh7yMD9F9C6rkqnkH4wxGN7gstfsyRHkUW9fo8yyQ5WJd7gbpSH Vsfmtc5cigx5fjP5FVU6QsnYtx3ouO97TYhOQKB3IafhDatmMkmRzE4C8WavTcLP1pRY edFw== 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=EBSDcpPojeDOFyIF6WIDH2CryUXzZ3D6nmFybwEVkwtS0yTHKn7LNqQgo9veGYkTG+ NTQsJEHypSR/iDXgg/SAS4WjnPJUeKNw4wL7lmQMTvYaj8YJ8GXkeJf880PBd//49tGh sCnBh0OZjonJoWcCyaKXAuaoY8o/NJ1oK+ItF7ZVm3VPXqAUtgybNruCf1YPbkFjqpmo NhFiVzqNWgF+WWug8SIPqE1421exX1MDCItClJ3q6Gp+nQzQ7++9R8qu1scl48sCtdR5 ceENs1EgIICR+vWiUWTFG0fon6BvykfGhWlQDidBC/jKohhg8PpV0auXgyYbHLwtDHFf kIDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="D35QV/GT"; 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 f13si14388662pgv.730.2022.01.24.15.18.45; Mon, 24 Jan 2022 15:18:57 -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="D35QV/GT"; 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 S1845208AbiAXXLn (ORCPT + 99 others); Mon, 24 Jan 2022 18:11:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1584523AbiAXWVX (ORCPT ); Mon, 24 Jan 2022 17:21:23 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F12DC0424C9; Mon, 24 Jan 2022 12:49:54 -0800 (PST) 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 17A2CB80FA1; Mon, 24 Jan 2022 20:49:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43D11C340E5; Mon, 24 Jan 2022 20:49:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643057391; bh=br/iQTyRsURcetzVqnQpSl1GiGq29hfg10350Q/e9Ew=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D35QV/GT57oa5jGhfItNSeAitLj//R3L2ltxbXXmE2+E4mQxm67h5UZhWKycc9NEZ V+liwIBCPdxOAB7zc4KgEAkvMkW7TVjrElT0MvG/BeD+hNxFMevV71r7p5V+AC+Qhe +GJbgWnR7+kxGvePaMgfgAWxCirQk4wlmYFT98sk= 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.15 798/846] net: axienet: fix for TX busy handling Date: Mon, 24 Jan 2022 19:45:15 +0100 Message-Id: <20220124184128.477699424@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@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; }