From patchwork Sun Mar 3 19:03:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Piotr Wejman X-Patchwork-Id: 13579874 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 117C6C48BF6 for ; Sun, 3 Mar 2024 19:04:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=spwnvMx42BzJYqZJx1ruZCzhDD5dtlkeYvoBtAIoq3Q=; b=twwUND4KMiRdsD UqjdDtHqs3Tn878qmBWQGfHXSgFhWaewI7CqMkoFivx06DPqBGk0vNnmeTIDe++NC3S78UDq6uYgw l4iIs1iiGlY0rSkoB/pMpi4/S2YbEqo/t6o4IDpYkX9W379AliwVGJOo99UvNgHPzoIIrjJhydgoG 8q8A0cAgwNLdjS7x4m7j3c/MtaKCBjKHmqkqHLxMogXoc0ly8Sa2xwtkwFRlTdSHmcJAPNjDUtIbc 5Alk/M6V7zMGZQUHZhtk2ZY74lv3mnEKasL7j+sD9W0jLFn4yEgZ1iCsbZ0CSULxnGLbnnXZRGmZL O6gjZrxjnCTlJvJB0pbg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rgr7k-00000006WCo-3Am0; Sun, 03 Mar 2024 19:03:48 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rgr7h-00000006WBe-1gFO for linux-arm-kernel@lists.infradead.org; Sun, 03 Mar 2024 19:03:46 +0000 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-412e22315d8so2547165e9.1 for ; Sun, 03 Mar 2024 11:03:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709492623; x=1710097423; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+Q6tqq+YHMrtRDD0QwVDNeMhXDLukwoqe/1azYB8u5U=; b=jecXjHeTmr2qSIxVbD6oa1qWqmJNlyA2c/TKphVAzAb17BbVMAfb6UV9KUsmzFx+ty Fl1/pGJLdJPwoKJWwxwDAuq0cbGF+J5D/aIrdezn2Q32v8mk7Hwn7RWudWleB+dVDGCa EeG3sQOe0r5BQWiaUOYeC+GBNPDz+BHlEQJc4JI7Hu4Zn6llGxwf2SgMUrdoTL9ltlbq nh5cOBul4Atdd6U5oRmLbrWsHezSxp7QJ3TMfAT8XaQhkxyHFfE2j4JwX+WGsy9qh5C4 rFK9rzH3o4Mj5Hbg0xaX8UhW/W4P55MEgx/AXlkeCWfUuSmDl+NMPGpImGhRKNaSYnn1 qWoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709492623; x=1710097423; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+Q6tqq+YHMrtRDD0QwVDNeMhXDLukwoqe/1azYB8u5U=; b=vQXpoLb4Mx5/j3h2KxkiaNoTdIX6nkBRuxhkJa9Ym6dExafzbtZGKf0O4hbAtEt63X 9LfE40mXqzGeIwp7xCCk2kvhQEUQoMrs43NYS0wCIplJuenu3LstN0rFvqMfuh2qqJCx poP9u/xEFw2r7+fWVupavAqZLO+ch0WVGnAYX6sAcjQ4TtvTdtBSAvFdk+5VzU099CMk 1IG4uSZPqfVScvCQq0zF2tdr1pM4OiXx1OtRTurXSys4JRwFb7edE92dC6QKz5xS3K44 Hc3xANmMkxeDLpzZiX5WkD/Qr45RAXVbaiVVvqfECGX2e382PU3lgQg6cBcAN21+kguE CQIw== X-Forwarded-Encrypted: i=1; AJvYcCWRbe6Wezlmk0jW9dUEPiAcS3la6DYU8Pk26xgtzHSA6Q5nIhYsdYfQDgzCqGnbFEyk2rDA9ePqVr2NdJS+VxuO34G78LO2YMous3kcf0gxeP5NLbI= X-Gm-Message-State: AOJu0Yzz0zxzayYGVd1c1AiBco2pkW7u5VaGYJ+90KbLHyKistVIXTsM CxpXn/VQv0dU8WMU3WO40URRSCzMhQeIDaPKsEwDhHkTJdPpNpyx X-Google-Smtp-Source: AGHT+IGg4+GTgKpcocRSHWqddDrc+rrpm/34o839Hkj+OJRCyujj5Z/0OpTcDzfW6PMDiFO0ZbZYoA== X-Received: by 2002:a05:600c:354b:b0:412:bca2:1680 with SMTP id i11-20020a05600c354b00b00412bca21680mr5891715wmq.35.1709492623332; Sun, 03 Mar 2024 11:03:43 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:a92:c660:e318:3b1a:c27a:9905]) by smtp.gmail.com with ESMTPSA id fk6-20020a05600c0cc600b00412e2ccdc97sm1265674wmb.17.2024.03.03.11.03.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 11:03:42 -0800 (PST) From: Piotr Wejman To: Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Piotr Wejman Subject: [PATCH v3] net: stmmac: fix rx queue priority assignment Date: Sun, 3 Mar 2024 20:03:38 +0100 Message-Id: <20240303190339.52496-1-piotrwejman90@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240303_110345_478891_668A63E2 X-CRM114-Status: GOOD ( 16.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The driver should ensure that same priority is not mapped to multiple rx queues. Currently rx_queue_priority() function is adding priorities for a queue without clearing them from others. From DesignWare Cores Ethernet Quality-of-Service Databook, section 17.1.29 MAC_RxQ_Ctrl2: "[...]The software must ensure that the content of this field is mutually exclusive to the PSRQ fields for other queues, that is, the same priority is not mapped to multiple Rx queues[...]" After this patch, rx_queue_priority() function will: - assign desired priorities to a queue - remove those priorities from all other queues The write sequence of CTRL2 and CTRL3 registers is done in the way to ensure this order. Signed-off-by: Piotr Wejman --- Changes in v2: - Add some comments - Apply same changes to dwxgmac2_rx_queue_prio() - Revert "Rename prio argument to prio_mask" - Link to v1: https://lore.kernel.org/netdev/20240219102405.32015-1-piotrwejman90@gmail.com/T/#u Changes in v3: - Fix trailing whitespace - Link to v2: https://lore.kernel.org/netdev/20240226093144.31965-1-piotrwejman90@gmail.com/ .../net/ethernet/stmicro/stmmac/dwmac4_core.c | 42 +++++++++++++++---- .../ethernet/stmicro/stmmac/dwxgmac2_core.c | 40 ++++++++++++++---- 2 files changed, 66 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c index 6b6d0de09619..a0e6d33ca87e 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c @@ -92,19 +92,43 @@ static void dwmac4_rx_queue_priority(struct mac_device_info *hw, u32 prio, u32 queue) { void __iomem *ioaddr = hw->pcsr; - u32 base_register; - u32 value; + u32 clear_mask = 0; + u32 ctrl2, ctrl3; + int i; - base_register = (queue < 4) ? GMAC_RXQ_CTRL2 : GMAC_RXQ_CTRL3; - if (queue >= 4) - queue -= 4; + ctrl2 = readl(ioaddr + GMAC_RXQ_CTRL2); + ctrl3 = readl(ioaddr + GMAC_RXQ_CTRL3); - value = readl(ioaddr + base_register); + /* The software must ensure that the same priority + * is not mapped to multiple Rx queues. + */ + for (i = 0; i < 4; i++) + clear_mask |= ((prio << GMAC_RXQCTRL_PSRQX_SHIFT(i)) & + GMAC_RXQCTRL_PSRQX_MASK(i)); + + ctrl2 &= ~clear_mask; + ctrl3 &= ~clear_mask; + + /* Assign new priorities to a queue and + * clear them from others queues. + * The CTRL2 and CTRL3 registers write sequence is done + * in the way to ensure this order. + */ + if (queue < 4) { + ctrl2 |= (prio << GMAC_RXQCTRL_PSRQX_SHIFT(queue)) & + GMAC_RXQCTRL_PSRQX_MASK(queue); - value &= ~GMAC_RXQCTRL_PSRQX_MASK(queue); - value |= (prio << GMAC_RXQCTRL_PSRQX_SHIFT(queue)) & + writel(ctrl2, ioaddr + GMAC_RXQ_CTRL2); + writel(ctrl3, ioaddr + GMAC_RXQ_CTRL3); + } else { + queue -= 4; + + ctrl3 |= (prio << GMAC_RXQCTRL_PSRQX_SHIFT(queue)) & GMAC_RXQCTRL_PSRQX_MASK(queue); - writel(value, ioaddr + base_register); + + writel(ctrl3, ioaddr + GMAC_RXQ_CTRL3); + writel(ctrl2, ioaddr + GMAC_RXQ_CTRL2); + } } static void dwmac4_tx_queue_priority(struct mac_device_info *hw, diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c index 1af2f89a0504..d15752823d93 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c @@ -105,17 +105,43 @@ static void dwxgmac2_rx_queue_prio(struct mac_device_info *hw, u32 prio, u32 queue) { void __iomem *ioaddr = hw->pcsr; - u32 value, reg; + u32 clear_mask = 0; + u32 ctrl2, ctrl3; + int i; - reg = (queue < 4) ? XGMAC_RXQ_CTRL2 : XGMAC_RXQ_CTRL3; - if (queue >= 4) + ctrl2 = readl(ioaddr + XGMAC_RXQ_CTRL2); + ctrl3 = readl(ioaddr + XGMAC_RXQ_CTRL3); + + /* The software must ensure that the same priority + * is not mapped to multiple Rx queues. + */ + for (i = 0; i < 4; i++) + clear_mask |= ((prio << XGMAC_PSRQ_SHIFT(i)) & + XGMAC_PSRQ(i)); + + ctrl2 &= ~clear_mask; + ctrl3 &= ~clear_mask; + + /* Assign new priorities to a queue and + * clear them from others queues. + * The CTRL2 and CTRL3 registers write sequence is done + * in the way to ensure this order. + */ + if (queue < 4) { + ctrl2 |= (prio << XGMAC_PSRQ_SHIFT(queue)) & + XGMAC_PSRQ(queue); + + writel(ctrl2, ioaddr + XGMAC_RXQ_CTRL2); + writel(ctrl3, ioaddr + XGMAC_RXQ_CTRL3); + } else { queue -= 4; - value = readl(ioaddr + reg); - value &= ~XGMAC_PSRQ(queue); - value |= (prio << XGMAC_PSRQ_SHIFT(queue)) & XGMAC_PSRQ(queue); + ctrl3 |= (prio << XGMAC_PSRQ_SHIFT(queue)) & + XGMAC_PSRQ(queue); - writel(value, ioaddr + reg); + writel(ctrl3, ioaddr + XGMAC_RXQ_CTRL3); + writel(ctrl2, ioaddr + XGMAC_RXQ_CTRL2); + } } static void dwxgmac2_tx_queue_prio(struct mac_device_info *hw, u32 prio,