diff mbox series

[v4,08/11] net: stmmac: dwegmac: Fix channel numbers

Message ID 65b1dc40d509676f81669bbc6b32531b1e6f3441.1692696115.git.chenfeiyang@loongson.cn (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series stmmac: Add Loongson platform support | expand

Checks

Context Check Description
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Feiyang Chen Aug. 22, 2023, 9:41 a.m. UTC
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 <chenfeiyang@loongson.cn>
Signed-off-by: Yinggang Gu <guyinggang@loongson.cn>
---
 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 mbox series

Patch

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 <linux/platform_device.h>
 #include <linux/phy.h>
+#include <linux/bitfield.h>
+#include <linux/bits.h>
 
 #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