Skip to contentSkip to conversation

fix some bugs and add some features in stmmac

PATCH In review Biao Huang 4 participants 16 messages Apr 28, 2019 – Apr 30, 2019

Subsystems (5)
lore
Share & tools
lore

Biao Huang

author
#0 lore raw

cover fix some bugs and add some features in stmmac

This series fix some bugs and add some features in stmmac driver.
5 patches are for common stmmac or dwmac4:
1. update rx tail pointer to fix rx dma hang issue.
2. change condition for mdc clock to fix csr_clk can't be zero issue.
3. write the modified value back to MTL_OPERATION_MODE.
4. add support for hash table size 128/256
5. add mdio clause 45 access from mac device for dwmac4.
1 patche is for dwmac-mediatek:
1. modify csr_clk value to fix mdio read/write fail issue for dwmac-mediatek.

Biao Huang (6):
net: stmmac: update rx tail pointer register to fix rx dma hang
issue.
net: stmmac: fix csr_clk can't be zero issue
net: stmmac: write the modified value back to MTL_OPERATION_MODE
net: stmmac: add support for hash table size 128/256 in dwmac4
net: stmmac: add mdio clause 45 access from mac device for dwmac4
stmmac: dwmac-mediatek: modify csr_clk value to fix mdio read/write
fail

 drivers/net/ethernet/stmicro/stmmac/common.h       |   18 ++-                  
 .../net/ethernet/stmicro/stmmac/dwmac-mediatek.c   |    4 +-                   
 drivers/net/ethernet/stmicro/stmmac/dwmac4.h       |    4 +-                   
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c  |   55 ++++---              
 drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c   |    1 +                    
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  |    9 +-                   
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c  |  167 ++++++++++++++++++-- 
 7 files changed, 213 insertions(+), 45 deletions(-)                            
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH 1/6 net: stmmac: update rx tail pointer register to fix rx dma hang issue.

Currently we will not update the receive descriptor tail pointer in stmmac_rx_refill. Rx dma will think no available descriptors and stop once received packets exceed DMA_RX_SIZE, so that the rx only test will fail.

Update the receive tail pointer in stmmac_rx_refill to add more descriptors to the rx channel, so packets can be received continually

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c |    3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -0
index 97c5e1a..818ad88 100644
@@ -3336,6 +3336,9 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv, u32 queue)
 		entry = STMMAC_GET_ENTRY(entry, DMA_RX_SIZE);
 	}
 	rx_q->dirty_rx = entry;
+	stmmac_set_rx_tail_ptr(priv, priv->ioaddr,
+			       rx_q->dma_rx_phy + (entry * sizeof(struct dma_desc)),
+			       queue);
 }
 
 /**
Signature · 1 line
1.7.9.5
author
#2 lore raw

PATCH 2/6 net: stmmac: fix csr_clk can't be zero issue

In reply to Biao Huang

The specific clk_csr value can be zero, and
stmmac_clk is necessary for MDC clock which can be set dynamically. So, change the condition from plat->clk_csr to plat->stmmac_clk to fix clk_csr can't be zero issue.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 818ad88..9e89b94 100644
@@ -4376,7 +4376,7 @@ int stmmac_dvr_probe(struct device *device,
 	 * set the MDC clock dynamically according to the csr actual
 	 * clock input.
 	 */
-	if (!priv->plat->clk_csr)
+	if (priv->plat->stmmac_clk)
 		stmmac_clk_csr_set(priv);
 	else
 		priv->clk_csr = priv->plat->clk_csr;
Signature · 1 line
1.7.9.5
author
#8 lore raw

PATCH 3/6 net: stmmac: write the modified value back to MTL_OPERATION_MODE

In reply to Biao Huang

The value of MTL_OPERATION_MODE is modified, and should be write back to the register.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +2 -0
index 7e5d5db..b4bb562 100644
@@ -192,6 +192,8 @@ static void dwmac4_prog_mtl_tx_algorithms(struct mac_device_info *hw,
 	default:
 		break;
 	}
+
+	writel(value, ioaddr + MTL_OPERATION_MODE);
 }
 
 static void dwmac4_set_mtl_tx_queue_weight(struct mac_device_info *hw,
Signature · 1 line
1.7.9.5
author
#9 lore raw

PATCH 4/6 net: stmmac: add support for hash table size 128/256 in dwmac4

In reply to Biao Huang

1. get hash table size in hw feature reigster, and add support for taller hash table(128/256) in dwmac4.
2. only clear PR/HMC/PM bits of GMAC_PACKET_FILTER, to avoid side effect to functions of other bits.

---
 drivers/net/ethernet/stmicro/stmmac/common.h      |    7 +--
 drivers/net/ethernet/stmicro/stmmac/dwmac4.h      |    4 +-
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c |   50 ++++++++++++---------
 drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c  |    1 +
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c |    4 ++
 5 files changed, 40 insertions(+), 26 deletions(-)
drivers/net/ethernet/stmicro/stmmac/common.h +4 -3
index 272b9ca6..709dcec 100644
@@ -335,6 +335,7 @@ struct dma_features {
 	/* 802.3az - Energy-Efficient Ethernet (EEE) */
 	unsigned int eee;
 	unsigned int av;
+	unsigned int hash_tb_sz;
 	unsigned int tsoen;
 	/* TX and RX csum */
 	unsigned int tx_coe;
@@ -427,9 +428,9 @@ struct mac_device_info {
 	struct mii_regs mii;	/* MII register Addresses */
 	struct mac_link link;
 	void __iomem *pcsr;     /* vpointer to device CSRs */
-	int multicast_filter_bins;
-	int unicast_filter_entries;
-	int mcast_bits_log2;
+	unsigned int multicast_filter_bins;
+	unsigned int unicast_filter_entries;
+	unsigned int mcast_bits_log2;
 	unsigned int rx_csum;
 	unsigned int pcs;
 	unsigned int pmt;
drivers/net/ethernet/stmicro/stmmac/dwmac4.h +2 -2
index eb013d5..a5eb7df 100644
@@ -18,8 +18,7 @@
 /*  MAC registers */
 #define GMAC_CONFIG			0x00000000
 #define GMAC_PACKET_FILTER		0x00000008
-#define GMAC_HASH_TAB_0_31		0x00000010
-#define GMAC_HASH_TAB_32_63		0x00000014
+#define GMAC_HASH_TAB(x)		(0x10 + x * 4)
 #define GMAC_RX_FLOW_CTRL		0x00000090
 #define GMAC_QX_TX_FLOW_CTRL(x)		(0x70 + x * 4)
 #define GMAC_TXQ_PRTY_MAP0		0x98
@@ -181,6 +180,7 @@ enum power_event {
 #define GMAC_HW_FEAT_MIISEL		BIT(0)
 
 /* MAC HW features1 bitmap */
+#define GMAC_HW_HASH_TB_SZ		GENMASK(25, 24)
 #define GMAC_HW_FEAT_AVSEL		BIT(20)
 #define GMAC_HW_TSOEN			BIT(18)
 #define GMAC_HW_TXFIFOSIZE		GENMASK(10, 6)
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +29 -21

70 lines not on this page · raw message

drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c +1 -0
index edb6053..59afb53 100644
@@ -354,6 +354,7 @@ static void dwmac4_get_hw_feature(void __iomem *ioaddr,
 
 	/* MAC HW feature1 */
 	hw_cap = readl(ioaddr + GMAC_HW_FEATURE1);
+	dma_cap->hash_tb_sz = (hw_cap & GMAC_HW_HASH_TB_SZ) >> 24;
 	dma_cap->av = (hw_cap & GMAC_HW_FEAT_AVSEL) >> 20;
 	dma_cap->tsoen = (hw_cap & GMAC_HW_TSOEN) >> 18;
 	/* RX and TX FIFO sizes are encoded as log2(n / 128). Undo that by
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +4 -0
index 9e89b94..792f459 100644
@@ -4162,6 +4162,10 @@ static int stmmac_hw_init(struct stmmac_priv *priv)
 		priv->plat->enh_desc = priv->dma_cap.enh_desc;
 		priv->plat->pmt = priv->dma_cap.pmt_remote_wake_up;
 		priv->hw->pmt = priv->plat->pmt;
+		if (priv->dma_cap.hash_tb_sz) {
+			priv->hw->multicast_filter_bins = BIT(priv->dma_cap.hash_tb_sz) * 32;
+			priv->hw->mcast_bits_log2 = ilog2(priv->hw->multicast_filter_bins);
+		}
 
 		/* TXCOE doesn't work in thresh DMA mode */
 		if (priv->plat->force_thresh_dma_mode)
Signature · 1 line
1.7.9.5
author
#10 lore raw

PATCH 5/6 net: stmmac: add mdio clause 45 access from mac device for dwmac4

In reply to Biao Huang

add clause 45 mdio read and write from mac device for dwmac4.

---
 drivers/net/ethernet/stmicro/stmmac/common.h      |   11 +-
 drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c |    3 +
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c |  167 +++++++++++++++++++--
 3 files changed, 165 insertions(+), 16 deletions(-)
drivers/net/ethernet/stmicro/stmmac/common.h +7 -4
index 709dcec..06573b3 100644
@@ -410,12 +410,15 @@ struct mac_link {
 struct mii_regs {
 	unsigned int addr;	/* MII Address */
 	unsigned int data;	/* MII Data */
-	unsigned int addr_shift;	/* MII address shift */
-	unsigned int reg_shift;		/* MII reg shift */
-	unsigned int addr_mask;		/* MII address mask */
-	unsigned int reg_mask;		/* MII reg mask */
+	unsigned int addr_shift;	/* PHY address shift */
+	unsigned int cl45_reg_shift;	/* CL45 reg address shift */
+	unsigned int reg_shift;		/* CL22 reg/CL45 dev shift */
+	unsigned int addr_mask;		/* PHY address mask */
+	unsigned int cl45_reg_mask;	/* CL45 reg mask */
+	unsigned int reg_mask;		/* CL22 reg/CL45 dev mask */
 	unsigned int clk_csr_shift;
 	unsigned int clk_csr_mask;
+	unsigned int cl45_en;	/* CL45 Enable*/
 };
 
 struct mac_device_info {
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +3 -0
index a60390b..b71342c 100644
@@ -837,6 +837,9 @@ int dwmac4_setup(struct stmmac_priv *priv)
 	mac->mii.reg_mask = GENMASK(20, 16);
 	mac->mii.clk_csr_shift = 8;
 	mac->mii.clk_csr_mask = GENMASK(11, 8);
+	mac->mii.cl45_reg_shift = 16;
+	mac->mii.cl45_reg_mask = GENMASK(31, 16);
+	mac->mii.cl45_en = BIT(1);
 
 	return 0;
 }
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +155 -12

192 lines not on this page · raw message

Signature · 1 line
1.7.9.5
author
#14 lore raw

PATCH 6/6 stmmac: dwmac-mediatek: modify csr_clk value to fix mdio read/write fail

In reply to Biao Huang

The frequency of csr clock is 66.5MHz, so the csr_clk value should be 0. Modify the csr_clk value to fix mdio read/write fail issue.

---
 .../net/ethernet/stmicro/stmmac/dwmac-mediatek.c   |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c +2 -2
index bf25629..6b12d0f 100644
@@ -346,8 +346,8 @@ static int mediatek_dwmac_probe(struct platform_device *pdev)
 		return PTR_ERR(plat_dat);
 
 	plat_dat->interface = priv_plat->phy_mode;
-	/* clk_csr_i = 250-300MHz & MDC = clk_csr_i/124 */
-	plat_dat->clk_csr = 5;
+	/* clk_csr_i = 60-100MHz & MDC = clk_csr_i/42 */
+	plat_dat->clk_csr = 0;
 	plat_dat->has_gmac4 = 1;
 	plat_dat->has_gmac = 0;
 	plat_dat->pmt = 0;
Signature · 1 line
1.7.9.5
maintainer
#15 lore raw
In reply to Biao Huang

From: Biao Huang <[email protected]>
Date: Sun, 28 Apr 2019 14:30:03 +0800

Quoted 1 line

This series fix some bugs and add some features in stmmac driver.

Please do not mix feature additions and bug fixes.

Bug fixes should target my 'net' tree.

New features should target my 'net-next' tree.

#11 lore raw

Re: [PATCH 5/6] net: stmmac: add mdio clause 45 access from mac device for dwmac4

In reply to Biao Huang

drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c static int stmmac_mdio_write(struct mii_bus *bus, int phyaddr, int phyreg, · line 260

Quoted 13 lines · Biao Huang
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +13 -0
+static int stmmac_c45_read(struct mii_bus *bus, int phyaddr,
+			   int devad, int prtad)
+{
+	struct net_device *ndev = bus->priv;
+	struct stmmac_priv *priv = netdev_priv(ndev);
+	unsigned int mii_address = priv->hw->mii.addr;
+	unsigned int mii_data = priv->hw->mii.data;
+	u32 v, value;
+	int data;
+
+	if (readl_poll_timeout(priv->ioaddr + mii_address, v, !(v & MII_BUSY),
+			       100, 10000))
+		return -EBUSY;

Hi Biao

readl_poll_timeout() returns an error code. It is better to return that, than make up some other error code. Yes, i know the C22 read returns EBUSY, but we don't need to copy that behaviour into C45.

drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c static int stmmac_mdio_write(struct mii_bus *bus, int phyaddr, int phyreg, · line 268

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +8 -0
+
+	value = 0;
+	value |= (prtad << priv->hw->mii.cl45_reg_shift)
+			& priv->hw->mii.cl45_reg_mask;
+	writel(value, priv->ioaddr + mii_data);
+
+	/* delay 2ms to avoid error value of get_phy_c45_devs_in_pkg */
+	mdelay(2);

Please could you explain this a bit more?

Andrew

author
#12 lore raw

Re: [PATCH 5/6] net: stmmac: add mdio clause 45 access from mac device for dwmac4

Hi Andrew,

Quoted 17 lines · Andrew Lunn

drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c static int stmmac_mdio_write(struct mii_bus *bus, int phyaddr, int phyreg, · line 260

Quoted 13 lines · Biao Huang
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +13 -0
+static int stmmac_c45_read(struct mii_bus *bus, int phyaddr,
+			   int devad, int prtad)
+{
+	struct net_device *ndev = bus->priv;
+	struct stmmac_priv *priv = netdev_priv(ndev);
+	unsigned int mii_address = priv->hw->mii.addr;
+	unsigned int mii_data = priv->hw->mii.data;
+	u32 v, value;
+	int data;
+
+	if (readl_poll_timeout(priv->ioaddr + mii_address, v, !(v & MII_BUSY),
+			       100, 10000))
+		return -EBUSY;

Hi Biao

Quoted 4 lines

readl_poll_timeout() returns an error code. It is better to return that, than make up some other error code. Yes, i know the C22 read returns EBUSY, but we don't need to copy that behaviour into C45.

OK, will return error code here.

Quoted 10 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c static int stmmac_mdio_write(struct mii_bus *bus, int phyaddr, int phyreg, · line 268

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +8 -0
+
+	value = 0;
+	value |= (prtad << priv->hw->mii.cl45_reg_shift)
+			& priv->hw->mii.cl45_reg_mask;
+	writel(value, priv->ioaddr + mii_data);
+
+	/* delay 2ms to avoid error value of get_phy_c45_devs_in_pkg */
+	mdelay(2);

Please could you explain this a bit more?

when of_mdiobus_register is invoked,
the C22 PHY addr information will be obtained in device tree(reg = xx, no need through mdiobus),
but C45 PHY addr should be got through mdiobus->read according to current flow.

    of_mdiobus_register -->
    of_mdiobus_register_phy -->
    get_phy_device -->
    get_phy_id -->
    get_phy_c45_ids -->
    get_phy_c45_devs_in_pkg

In my platform, mdio bus read will return 0xffff or 0x0000 for C45 in of_mdiobus_register callstack, and that's not the expected value. So that the mdiobus register fails.

We took some time to find that only after adding 2ms delay here, the read action will be stable and return the expected value.

did you try C45 support in your platform? I can't tell whether it's a common or specified issue.

our version is 4.21a.

Quoted 2 lines

Andrew

#3 lore raw

Re: [PATCH 2/6] net: stmmac: fix csr_clk can't be zero issue

In reply to Biao Huang

Hi

Quoted 16 lines · Biao Huang

The specific clk_csr value can be zero, and
stmmac_clk is necessary for MDC clock which can be set dynamically. So, change the condition from plat->clk_csr to plat->stmmac_clk to fix clk_csr can't be zero issue.

---
  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
index 818ad88..9e89b94 100644

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c int stmmac_dvr_probe(struct device *device, · line 4382

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
@@ -4376,7 +4376,7 @@ int stmmac_dvr_probe(struct device *device,
  	 * set the MDC clock dynamically according to the csr actual
  	 * clock input.
  	 */
-	if (!priv->plat->clk_csr)
+	if (priv->plat->stmmac_clk)
  		stmmac_clk_csr_set(priv);
  	else
  		priv->clk_csr = priv->plat->clk_csr;

So, as soon as stmmac_clk will be declared, it is no longer possible to fix a CSR through the device tree ?

author
#4 lore raw

Re: [PATCH 2/6] net: stmmac: fix csr_clk can't be zero issue

Hi,

Quoted 22 lines · Alexandre Torgue

Hi

Quoted 19 lines · Biao Huang

The specific clk_csr value can be zero, and
stmmac_clk is necessary for MDC clock which can be set dynamically. So, change the condition from plat->clk_csr to plat->stmmac_clk to fix clk_csr can't be zero issue.

---
  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -1
index 818ad88..9e89b94 100644
@@ -4376,7 +4376,7 @@ int stmmac_dvr_probe(struct device *device,
  	 * set the MDC clock dynamically according to the csr actual
  	 * clock input.
  	 */
-	if (!priv->plat->clk_csr)
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c int stmmac_dvr_probe(struct device *device, · line 4382

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -0
+	if (priv->plat->stmmac_clk)
  		stmmac_clk_csr_set(priv);
  	else
  		priv->clk_csr = priv->plat->clk_csr;

So, as soon as stmmac_clk will be declared, it is no longer possible to fix a CSR through the device tree ?

let's focus on the condition:
1. clk_csr may be zero, it should not be the condition. or the clk_csr = 0 will jump to the wrong block.
2. Since stmmac_clk_csr_set will get_clk_rate from stmmac_clk, the plat->stmmac_clk is a more proper condition.

In some case, it's impossible to get the clk rate of stmmac_clk, so it's better to remain the clk_csr flow.

#5 lore raw

Re: [PATCH 2/6] net: stmmac: fix csr_clk can't be zero issue

Quoted 34 lines · biao huang

Hi,

Quoted 22 lines · Alexandre Torgue

Hi

Quoted 19 lines · Biao Huang

The specific clk_csr value can be zero, and
stmmac_clk is necessary for MDC clock which can be set dynamically. So, change the condition from plat->clk_csr to plat->stmmac_clk to fix clk_csr can't be zero issue.

---
   drivers/net/ethernet/stmicro/stmmac/stmmac_main.c |    2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -1
index 818ad88..9e89b94 100644
@@ -4376,7 +4376,7 @@ int stmmac_dvr_probe(struct device *device,
   	 * set the MDC clock dynamically according to the csr actual
   	 * clock input.
   	 */
-	if (!priv->plat->clk_csr)
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c int stmmac_dvr_probe(struct device *device, · line 4382

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -0
+	if (priv->plat->stmmac_clk)
   		stmmac_clk_csr_set(priv);
   	else
   		priv->clk_csr = priv->plat->clk_csr;

So, as soon as stmmac_clk will be declared, it is no longer possible to fix a CSR through the device tree ?

Quoted 6 lines

let's focus on the condition:
1. clk_csr may be zero, it should not be the condition. or the clk_csr = 0 will jump to the wrong block.
2. Since stmmac_clk_csr_set will get_clk_rate from stmmac_clk, the plat->stmmac_clk is a more proper condition.

Ok, but here you remove one possibility: stmmac_clk and clk_csr defined. no ?

Other way could be the following code + initialize priv->plat->clk_csr with a non null value before read it in device tree (in stmmac_platform).

if (priv->plat->clk_csr >= 0)

	priv->clk_csr = priv->plat->clk_csr;
else
	stmmac_clk_csr_set(priv);
Quoted 5 lines

In some case, it's impossible to get the clk rate of stmmac_clk, so it's better to remain the clk_csr flow.

#13 lore raw

Re: [PATCH 5/6] net: stmmac: add mdio clause 45 access from mac device for dwmac4

In reply to biao huang
Quoted 33 lines
Quoted 6 lines

Hi Biao

readl_poll_timeout() returns an error code. It is better to return that, than make up some other error code. Yes, i know the C22 read returns EBUSY, but we don't need to copy that behaviour into C45.

OK, will return error code here.

Quoted 10 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c static int stmmac_mdio_write(struct mii_bus *bus, int phyaddr, int phyreg, · line 268

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +8 -0
+
+	value = 0;
+	value |= (prtad << priv->hw->mii.cl45_reg_shift)
+			& priv->hw->mii.cl45_reg_mask;
+	writel(value, priv->ioaddr + mii_data);
+
+	/* delay 2ms to avoid error value of get_phy_c45_devs_in_pkg */
+	mdelay(2);

Please could you explain this a bit more?

when of_mdiobus_register is invoked,
the C22 PHY addr information will be obtained in device tree(reg = xx, no need through mdiobus),
but C45 PHY addr should be got through mdiobus->read according to current flow.

    of_mdiobus_register -->
    of_mdiobus_register_phy -->
    get_phy_device -->
    get_phy_id -->
    get_phy_c45_ids -->
    get_phy_c45_devs_in_pkg

In my platform, mdio bus read will return 0xffff or 0x0000 for C45 in of_mdiobus_register callstack, and that's not the expected value. So that the mdiobus register fails.

Quoted 5 lines

We took some time to find that only after adding 2ms delay here, the read action will be stable and return the expected value.

did you try C45 support in your platform? I can't tell whether it's a common or specified issue.

It sounds like you need to put a logic analyser on the bus and see if it performs a C22 transaction, or an invalid transaction, without the 2ms pause.

This sounds like a 'silicon' bug. There should not be a need to pause here. And the comment should talk about this silicon bug, not get_phy_c45_devs_in_pkg(). It will fail for all accesses, not just those for get_phy_c45_devs_in_pkg().

Andrew

author
#6 lore raw

Re: [PATCH 2/6] net: stmmac: fix csr_clk can't be zero issue

In reply to Alexandre Torgue
Quoted 46 lines · Alexandre Torgue
Quoted 34 lines · biao huang

Hi,

Quoted 22 lines · Alexandre Torgue

Hi

Quoted 19 lines · Biao Huang

The specific clk_csr value can be zero, and
stmmac_clk is necessary for MDC clock which can be set dynamically. So, change the condition from plat->clk_csr to plat->stmmac_clk to fix clk_csr can't be zero issue.

---
   drivers/net/ethernet/stmicro/stmmac/stmmac_main.c |    2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -1
index 818ad88..9e89b94 100644
@@ -4376,7 +4376,7 @@ int stmmac_dvr_probe(struct device *device,
   	 * set the MDC clock dynamically according to the csr actual
   	 * clock input.
   	 */
-	if (!priv->plat->clk_csr)
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c int stmmac_dvr_probe(struct device *device, · line 4382

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -0
+	if (priv->plat->stmmac_clk)
   		stmmac_clk_csr_set(priv);
   	else
   		priv->clk_csr = priv->plat->clk_csr;

So, as soon as stmmac_clk will be declared, it is no longer possible to fix a CSR through the device tree ?

Quoted 6 lines

let's focus on the condition:
1. clk_csr may be zero, it should not be the condition. or the clk_csr = 0 will jump to the wrong block.
2. Since stmmac_clk_csr_set will get_clk_rate from stmmac_clk, the plat->stmmac_clk is a more proper condition.

Ok, but here you remove one possibility: stmmac_clk and clk_csr defined. no ?

Quoted 13 lines

Other way could be the following code + initialize priv->plat->clk_csr with a non null value before read it in device tree (in stmmac_platform).

if (priv->plat->clk_csr >= 0)

	priv->clk_csr = priv->plat->clk_csr;
else
	stmmac_clk_csr_set(priv);
Quoted 3 lines

In some case, it's impossible to get the clk rate of stmmac_clk, so it's better to remain the clk_csr flow.

Agree.

Maybe we should initialize plat->clk_csr to -1
in stmmac_probe_config_dt:

plat->clk_csr = -1;
/* Get clk_csr from device tree */ of_property_read_u32(np, "clk_csr", &plat->clk_csr);

Then the condition can write as you proposed:
if (priv->plat->clk_csr >= 0)
priv->clk_csr = priv->plat->clk_csr;
else
stmmac_clk_csr_set(priv);

Quoted 2 lines
Quoted 2 lines
#7 lore raw

Re: [PATCH 2/6] net: stmmac: fix csr_clk can't be zero issue

Quoted 68 lines · biao huang
Quoted 46 lines · Alexandre Torgue
Quoted 34 lines · biao huang

Hi,

Quoted 22 lines · Alexandre Torgue

Hi

Quoted 19 lines · Biao Huang

The specific clk_csr value can be zero, and
stmmac_clk is necessary for MDC clock which can be set dynamically. So, change the condition from plat->clk_csr to plat->stmmac_clk to fix clk_csr can't be zero issue.

---
    drivers/net/ethernet/stmicro/stmmac/stmmac_main.c |    2 +-
    1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -1
index 818ad88..9e89b94 100644
@@ -4376,7 +4376,7 @@ int stmmac_dvr_probe(struct device *device,
    	 * set the MDC clock dynamically according to the csr actual
    	 * clock input.
    	 */
-	if (!priv->plat->clk_csr)
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c int stmmac_dvr_probe(struct device *device, · line 4382

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -0
+	if (priv->plat->stmmac_clk)
    		stmmac_clk_csr_set(priv);
    	else
    		priv->clk_csr = priv->plat->clk_csr;

So, as soon as stmmac_clk will be declared, it is no longer possible to fix a CSR through the device tree ?

Quoted 6 lines

let's focus on the condition:
1. clk_csr may be zero, it should not be the condition. or the clk_csr = 0 will jump to the wrong block.
2. Since stmmac_clk_csr_set will get_clk_rate from stmmac_clk, the plat->stmmac_clk is a more proper condition.

Ok, but here you remove one possibility: stmmac_clk and clk_csr defined. no ?

Quoted 12 lines

Other way could be the following code + initialize priv->plat->clk_csr with a non null value before read it in device tree (in stmmac_platform).

if (priv->plat->clk_csr >= 0)

	priv->clk_csr = priv->plat->clk_csr;
else
	stmmac_clk_csr_set(priv);
Quoted 3 lines

In some case, it's impossible to get the clk rate of stmmac_clk, so it's better to remain the clk_csr flow.

Agree.

Maybe we should initialize plat->clk_csr to -1
in stmmac_probe_config_dt:

plat->clk_csr = -1;
/* Get clk_csr from device tree */ of_property_read_u32(np, "clk_csr", &plat->clk_csr);

Quoted 6 lines

Then the condition can write as you proposed:
if (priv->plat->clk_csr >= 0)
priv->clk_csr = priv->plat->clk_csr;
else
stmmac_clk_csr_set(priv);

Yes, I agree.
Thanks
Alex

Quoted 4 lines
Quoted 2 lines
Quoted 2 lines