From patchwork Mon Feb 26 09:31:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Piotr Wejman X-Patchwork-Id: 13571713 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 A1F42C48BF6 for ; Mon, 26 Feb 2024 09:34:29 +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=gakbBcqZ2umbZZ2+8AkE/GqQichI1ay8CeUWWKCH1DE=; b=BK2torNYnaueou WqkHPLhNhmLaqwr7FbjnwIwU31CCidJPFG1M0Fwkj2ft4p+h75xxDeQQ/SWSdjY87BiwYMZkeyBYV wJ8nev3S9XYPmZYGqaLa4cxn2kFJAJjybmHPRmX+xi3vmcTH6r4apSR+ORxJcIoneEPZ+eOKLL70D oJobjQdVRcYDD6i0IgtEs0/2FTzvaGTplS44gH/KnP7peEbhHND42Icun7BgTL+73NywMbpbfHOJA X/RK3Uk8rS5Xvw3iEAxbfeNknM9BCqDydkJonYSQ65BDE/ICbwvyVoDKwU3TnH3+yvoeKtm4LNz9i 3VhC1ltuAuuqliXj2/mw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reXNG-0000000HMnj-1ptG; Mon, 26 Feb 2024 09:34:14 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reXNC-0000000HMmb-3cUk for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 09:34:12 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-412a8d9402eso421255e9.0 for ; Mon, 26 Feb 2024 01:34:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708940048; x=1709544848; 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=yLtF7BizwZvfZN5GuZUignuLCSNDd+sax5JxYiM+LhA=; b=g9gQq9UUy4T5pn+SPKbNr+Cgj8tCwbUlDkGJ+FytZHNFO6Y4kK/q8z/W+tpg03/IWZ kVUT595Oyx+wgBNZKrqLc49JZFL63QvF8I8U6FpujRdpVNI7c1wd2wBETS80BELlDK8z eZVtni4qSIJEfG40lsGMsLlymieNdKNP8npLbnPBjYiUNcL6PWSTYYXUgRucN2qnqigX SE6GITS+GfXhzsn5ypcDDCxo49QwaY6hXw8oa5KRG0UW98T+3taOJvLPaPrJJZmkFe1b CC+bo85vtmrFaeuXbA6jc1hDIVbdW4yNyWHeAGwKoyFgACO2U5vvZBnwmwQOnTTVyPUh rAqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708940048; x=1709544848; 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=yLtF7BizwZvfZN5GuZUignuLCSNDd+sax5JxYiM+LhA=; b=JfPkywAT4eiFR917Ljs2yCZfigJAz3rB+JU31X+os6GQlO/zTBbPA7WEjbO6qDROhI LYlhBGzvTvncLVs1cToPDXv6BXk0V8d4F4nEHpN6PhvQYlUFiIMxzfOA6dWYV9uWQY9M lohtJGRx0ro/MkqvGlK2/672kQ+0KxCZwgrUpierSE6b8fPlFb4Z2kTjckotIICRBrPY AmiDebZz5tpxNndLT65YfOF7NUUR1rE01OL4Dl1Hog+v/IKMRsWdoo3YvjRR1JyYxgP+ L/WQGLUHR590fLABo6g/pdAPMnfqCLW2biXcpWwVH35eEhy7gmvL9idr+jO49s8N5xof i4hQ== X-Forwarded-Encrypted: i=1; AJvYcCVc1gin7yd3IRNdz0MBjFn4JyratqMfkCc0cqS7T2YnREOuRhkRc+Mzd/zNwtHywUqhO4epDCdTP1uiE9xyiZsmkC92zNVnnhDT6eHCLo61CvaqVX8= X-Gm-Message-State: AOJu0YwX5L8OVpKyYktxAb2X9rxbZPNa3hoUT322qpsa5fjvwUinbl12 w3lw3u4pOR5x7aulhCFfEmHNq5SyIODJTHfyFlAdBuiihQomjFbUmmwrZehjmNE= X-Google-Smtp-Source: AGHT+IEi6GB9us55+eZ6PLrMscsWzljtbO5rOv8g03rm2DGHxEr4TSML+Pwaf/AFQXl8ljBVN2nDEQ== X-Received: by 2002:a05:6000:1752:b0:33d:3cd3:5ffd with SMTP id m18-20020a056000175200b0033d3cd35ffdmr5624541wrf.22.1708940047938; Mon, 26 Feb 2024 01:34:07 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:a92:c660:e2e4:db7a:f447:614]) by smtp.gmail.com with ESMTPSA id bj20-20020a0560001e1400b0033db0c866f7sm7749527wrb.11.2024.02.26.01.34.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:34:07 -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 v2] net: stmmac: fix rx queue priority assignment Date: Mon, 26 Feb 2024 10:31:44 +0100 Message-Id: <20240226093144.31965-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-20240226_013410_946368_F5EB993A X-CRM114-Status: GOOD ( 16.59 ) 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 .../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..76ec0c1da250 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); + + /* 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)); - value = readl(ioaddr + base_register); + ctrl2 &= ~clear_mask; + ctrl3 &= ~clear_mask; - value &= ~GMAC_RXQCTRL_PSRQX_MASK(queue); - value |= (prio << GMAC_RXQCTRL_PSRQX_SHIFT(queue)) & + /* 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); - writel(value, ioaddr + base_register); + + 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(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..7ad73e1d353e 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,