From patchwork Tue Aug 22 09:41:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feiyang Chen X-Patchwork-Id: 13360433 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12C5A8F74 for ; Tue, 22 Aug 2023 09:41:26 +0000 (UTC) Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A17931A5 for ; Tue, 22 Aug 2023 02:41:24 -0700 (PDT) Received: from loongson.cn (unknown [112.20.109.102]) by gateway (Coremail) with SMTP id _____8CxyOjCguRkQOAaAA--.19223S3; Tue, 22 Aug 2023 17:41:22 +0800 (CST) Received: from localhost.localdomain (unknown [112.20.109.102]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Ax3c7AguRkqTVgAA--.38684S2; Tue, 22 Aug 2023 17:41:21 +0800 (CST) From: Feiyang Chen To: andrew@lunn.ch, hkallweit1@gmail.com, peppe.cavallaro@st.com, alexandre.torgue@foss.st.com, joabreu@synopsys.com, chenhuacai@loongson.cn Cc: Feiyang Chen , linux@armlinux.org.uk, dongbiao@loongson.cn, guyinggang@loongson.cn, siyanteng@loongson.cn, loongson-kernel@lists.loongnix.cn, netdev@vger.kernel.org, loongarch@lists.linux.dev, chris.chenfeiyang@gmail.com Subject: [PATCH v4 08/11] net: stmmac: dwegmac: Fix channel numbers Date: Tue, 22 Aug 2023 17:41:16 +0800 Message-Id: <65b1dc40d509676f81669bbc6b32531b1e6f3441.1692696115.git.chenfeiyang@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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wCI42IY6xIIjxv20xvE14v26F1j6w1UMIIF0xvE2Ix0cI 8IcVCY1x0267AKxVWxJVW8Jr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2 jsIE14v26F4j6r4UJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73Uj IFyTuYvjxUgBOJUUUUU X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Some Loongson platforms cannot obtain the TX and RX number of channels. Add the dwegmac_flag for them and specify the number of channels. Signed-off-by: Feiyang Chen Signed-off-by: Yinggang Gu --- drivers/net/ethernet/stmicro/stmmac/dwegmac_dma.c | 10 ++++++++-- drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 1 + include/linux/stmmac.h | 5 +++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwegmac_dma.c b/drivers/net/ethernet/stmicro/stmmac/dwegmac_dma.c index 9bb0564fbeff..157f0e3687be 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwegmac_dma.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwegmac_dma.c @@ -479,8 +479,14 @@ static int dwegmac_get_hw_feature(struct stmmac_priv *priv, dma_cap->rx_coe_type2 = (hw_cap & DMA_HW_FEAT_RXTYP2COE) >> 18; dma_cap->rxfifo_over_2048 = (hw_cap & DMA_HW_FEAT_RXFIFOSIZE) >> 19; /* TX and RX number of channels */ - dma_cap->number_rx_channel = (hw_cap & DMA_HW_FEAT_RXCHCNT) >> 20; - dma_cap->number_tx_channel = (hw_cap & DMA_HW_FEAT_TXCHCNT) >> 22; + if (FIELD_GET(DWEGMAC_FIX_CHANNEL_NUM, priv->plat->dwegmac_flags) && + ((hw_cap & (DMA_HW_FEAT_RXCHCNT | DMA_HW_FEAT_TXCHCNT)) >> 20) == 0) { + dma_cap->number_rx_channel = 8; + dma_cap->number_tx_channel = 8; + } else { + dma_cap->number_rx_channel = (hw_cap & DMA_HW_FEAT_RXCHCNT) >> 20; + dma_cap->number_tx_channel = (hw_cap & DMA_HW_FEAT_TXCHCNT) >> 22; + } /* Alternate (enhanced) DESC mode */ dma_cap->enh_desc = (hw_cap & DMA_HW_FEAT_ENHDESSEL) >> 24; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c index 0748bafd3aec..9fb27fc94d2a 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c @@ -175,6 +175,7 @@ static int loongson_gmac_config(struct pci_dev *pdev, switch (version & 0xff) { case DWEGMAC_CORE_1_00: ret = loongson_dwmac_config_multi_msi(pdev, plat, res, np, 8); + plat->dwegmac_flags |= FIELD_PREP(DWEGMAC_FIX_CHANNEL_NUM, 1); break; default: ret = loongson_dwmac_config_single_irq(pdev, plat, res, np); diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h index 75da4c7eb85c..e4088d2a0f39 100644 --- a/include/linux/stmmac.h +++ b/include/linux/stmmac.h @@ -14,6 +14,8 @@ #include #include +#include +#include #define MTL_MAX_RX_QUEUES 8 #define MTL_MAX_TX_QUEUES 8 @@ -205,6 +207,8 @@ struct dwmac4_addrs { u32 mtl_low_cred_offset; }; +#define DWEGMAC_FIX_CHANNEL_NUM BIT(0) + struct plat_stmmacenet_data { int bus_id; int phy_addr; @@ -297,5 +301,6 @@ struct plat_stmmacenet_data { bool has_integrated_pcs; int has_egmac; u32 irq_flags; + unsigned int dwegmac_flags; }; #endif