From 7c7f6ea13e849af8381fa3ab0c86a9d959efb05f Mon Sep 17 00:00:00 2001 From: zuoqian Date: Fri, 7 Mar 2025 10:33:53 +0800 Subject: [PATCH 01/27] driver: net: phy: add 'force_phy_mode' to fix Motorcomm RGMII phy failure. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On vpx development boards, when phytium gmac running in RGMII, RGMII0_RXD1 pin is high level by default. this cause Motorcomm RGMII phy recognize its chip mode from UTP_TO_RGMII to FIBER_TO_RGMII,resulting failure. So here,fix it. Signed-off-by: shiguangyuan Signed-off-by: zuoqian --- devices/cadence/macb-6.6-orig.h | 2 ++ devices/cadence/macb_main-6.6-orig.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/devices/cadence/macb-6.6-orig.h b/devices/cadence/macb-6.6-orig.h index 3a5441d..252e6cd 100644 --- a/devices/cadence/macb-6.6-orig.h +++ b/devices/cadence/macb-6.6-orig.h @@ -1342,6 +1342,8 @@ struct macb { int duplex; int use_ncsi; + int force_phy_mode; + u32 caps; unsigned int dma_burst_length; diff --git a/devices/cadence/macb_main-6.6-orig.c b/devices/cadence/macb_main-6.6-orig.c index 18e28ac..d495d26 100644 --- a/devices/cadence/macb_main-6.6-orig.c +++ b/devices/cadence/macb_main-6.6-orig.c @@ -1103,6 +1103,7 @@ static int macb_phylink_connect(struct macb *bp) netdev_err(dev, "no PHY found\n"); return -ENXIO; } + phydev->force_mode = bp->force_phy_mode; /* attach the mac to the phy */ if (phylink_expects_phy(bp->phylink)) @@ -5799,6 +5800,10 @@ static int macb_probe(struct platform_device *pdev) if (err) goto err_out_free_netdev; + if (device_property_read_bool(&pdev->dev, "force-phy-mode")) { + bp->force_phy_mode = 1; + } + err = macb_mii_init(bp); if (err) goto err_out_phy_exit; -- Gitee From 2d4ce35ff78ed939d44687db42c3483b3e924653 Mon Sep 17 00:00:00 2001 From: Li Wencheng Date: Wed, 7 May 2025 17:22:13 +0800 Subject: [PATCH 02/27] net/macb: Fetch q_ptr offset when the queue pointer is lagging Corrected the calculation method of tbqp by explicitly calculating the offset between TBQP and DMA address. Signed-off-by: Li Wencheng Signed-off-by: Wang Yinfeng Change-Id: I765e98a3bbf9cb08cdfe6e1a193394ae16d12dd8 --- devices/cadence/macb_main-6.6-orig.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/devices/cadence/macb_main-6.6-orig.c b/devices/cadence/macb_main-6.6-orig.c index d495d26..e819540 100644 --- a/devices/cadence/macb_main-6.6-orig.c +++ b/devices/cadence/macb_main-6.6-orig.c @@ -2019,7 +2019,8 @@ static void macb_tx_restart(struct macb_queue *queue) if (queue->tx_head == queue->tx_tail) goto out_tx_ptr_unlock; - tbqp = queue_readl(queue, TBQP) / macb_dma_desc_get_size(bp); + tbqp = queue_readl(queue, TBQP) - lower_32_bits(queue->tx_ring_dma); + tbqp = tbqp / macb_dma_desc_get_size(bp); tbqp = macb_adj_dma_desc_idx(bp, macb_tx_ring_wrap(bp, tbqp)); head_idx = macb_adj_dma_desc_idx(bp, macb_tx_ring_wrap(bp, queue->tx_head)); -- Gitee From 2c6faa8192db8819e1a60e73d57d1b75011e42c1 Mon Sep 17 00:00:00 2001 From: zuoqian Date: Tue, 10 Jun 2025 16:41:11 +0800 Subject: [PATCH 03/27] net: macb: Fix 10G to support link status detection Remove bp->link, it is not used. Turn on PCS tx channel in usx pcs_config callback. This makes PCS can enter sync state. Signed-off-by: zuoqian --- devices/cadence/macb-6.6-orig.h | 1 - devices/cadence/macb_main-6.6-orig.c | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/devices/cadence/macb-6.6-orig.h b/devices/cadence/macb-6.6-orig.h index 252e6cd..d8a84e2 100644 --- a/devices/cadence/macb-6.6-orig.h +++ b/devices/cadence/macb-6.6-orig.h @@ -1337,7 +1337,6 @@ struct macb { struct phylink_config phylink_config; struct phylink_pcs phylink_usx_pcs; struct phylink_pcs phylink_sgmii_pcs; - int link; int speed; int duplex; int use_ncsi; diff --git a/devices/cadence/macb_main-6.6-orig.c b/devices/cadence/macb_main-6.6-orig.c index e819540..026082f 100644 --- a/devices/cadence/macb_main-6.6-orig.c +++ b/devices/cadence/macb_main-6.6-orig.c @@ -640,7 +640,7 @@ static int macb_usx_pcs_config(struct phylink_pcs *pcs, struct macb *bp = container_of(pcs, struct macb, phylink_usx_pcs); gem_writel(bp, USX_CONTROL, gem_readl(bp, USX_CONTROL) | - GEM_BIT(SIGNAL_OK)); + GEM_BIT(SIGNAL_OK) | GEM_BIT(TX_EN)); return 0; } @@ -3250,9 +3250,6 @@ static void macb_init_hw(struct macb *bp) if (bp->caps & MACB_CAPS_SEL_CLK) bp->sel_clk_hw(bp, bp->speed); phytium_mac_config(bp); - if (bp->link) - macb_usx_pcs_link_up(&bp->phylink_usx_pcs, 0, - bp->phy_interface, bp->speed, bp->duplex); } else { bp->speed = SPEED_10; bp->duplex = DUPLEX_HALF; -- Gitee From 852063a08e4bf279b6fb9298cf7a027f62909a4b Mon Sep 17 00:00:00 2001 From: zuoqian Date: Wed, 11 Jun 2025 13:59:39 +0800 Subject: [PATCH 04/27] net: macb: fix NULL pointer in fixed-link mode when unbind 10G device When using fixed-link configuration, the mii_bus structure is not created. Added NULL pointer check before accessing mii_bus. [ 257.223408] Unable to handle kernel NULL pointer dereference at virtual address 00000000000004a8 [ 257.232199] Mem abort info: [ 257.234983] ESR = 0x0000000096000004 [ 257.238731] EC = 0x25: DABT (current EL), IL = 32 bits [ 257.244045] SET = 0, FnV = 0 [ 257.247090] EA = 0, S1PTW = 0 [ 257.250228] FSC = 0x04: level 0 translation fault [ 257.255105] Data abort info: [ 257.257982] ISV = 0, ISS = 0x00000004, ISS2 = 0x00000000 [ 257.263464] CM = 0, WnR = 0, TnD = 0, TagAccess = 0 [ 257.268512] GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0 [ 257.273821] user pgtable: 4k pages, 48-bit VAs, pgdp=00000020062ef000 [ 257.280260] [00000000000004a8] pgd=0000000000000000, p4d=0000000000000000 ... [ 257.329752] pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 257.336707] pc : mdiobus_unregister+0x10/0xa0 [ 257.341063] lr : macb_remove+0x38/0x164 [ 257.344894] sp : ffff800082aabb80 [ 257.348199] x29: ffff800082aabb80 x28: ffff001f80a3ab80 x27: 0000000000000000 [ 257.355331] x26: 0000000000000000 x25: 0000000000000000 x24: ffff001f83ddc0e0 [ 257.362462] x23: ffff8000816a6740 x22: 0000000000000000 x21: ffff001f818d8000 [ 257.369592] x20: ffff001f818d8a00 x19: ffff001f8097b810 x18: 0000000000000000 [ 257.376722] x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000000 [ 257.383853] x14: 0000000000000000 x13: 000000000000025d x12: 0000000000000002 [ 257.390983] x11: 0000000000000000 x10: 0000000000000a80 x9 : ffff800082aab8a0 [ 257.398114] x8 : ffff001f80a3b660 x7 : 0000000000000001 x6 : ffff8000816cdd68 [ 257.405244] x5 : ffff001f818d8558 x4 : 0000000000000000 x3 : 0000000000000001 [ 257.412374] x2 : 0000000000000000 x1 : 0000000000000000 x0 : 0000000000000000 [ 257.419505] Call trace: [ 257.421941] mdiobus_unregister+0x10/0xa0 [ 257.425944] macb_remove+0x38/0x164 [ 257.429425] platform_remove+0x4c/0x64 [ 257.433168] device_remove+0x48/0x74 [ 257.436735] device_release_driver_internal+0x1c0/0x218 [ 257.441952] device_driver_detach+0x14/0x1c [ 257.446127] unbind_store+0xac/0xb0 [ 257.449609] drv_attr_store+0x20/0x30 [ 257.453265] sysfs_kf_write+0x40/0x4c [ 257.456921] kernfs_fop_write_iter+0x118/0x1dc [ 257.461357] vfs_write+0x1c0/0x320 [ 257.464752] ksys_write+0x70/0x104 [ 257.468146] __arm64_sys_write+0x18/0x20 ... Signed-off-by: zuoqian --- devices/cadence/macb_main-6.6-orig.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/devices/cadence/macb_main-6.6-orig.c b/devices/cadence/macb_main-6.6-orig.c index 026082f..9777761 100644 --- a/devices/cadence/macb_main-6.6-orig.c +++ b/devices/cadence/macb_main-6.6-orig.c @@ -5840,8 +5840,10 @@ static int macb_probe(struct platform_device *pdev) return 0; err_out_unregister_mdio: - mdiobus_unregister(bp->mii_bus); - mdiobus_free(bp->mii_bus); + if (bp->mii_bus) { + mdiobus_unregister(bp->mii_bus); + mdiobus_free(bp->mii_bus); + } err_out_phy_exit: phy_exit(bp->sgmii_phy); @@ -5869,8 +5871,11 @@ static int macb_remove(struct platform_device *pdev) bp = netdev_priv(dev); unregister_netdev(dev); phy_exit(bp->sgmii_phy); - mdiobus_unregister(bp->mii_bus); - mdiobus_free(bp->mii_bus); + + if (bp->mii_bus) { + mdiobus_unregister(bp->mii_bus); + mdiobus_free(bp->mii_bus); + } tasklet_kill(&bp->hresp_err_tasklet); pm_runtime_disable(&pdev->dev); -- Gitee From e62116b5c0ae982782af9828bf85242a9d07b706 Mon Sep 17 00:00:00 2001 From: Li Wencheng Date: Wed, 7 May 2025 17:22:13 +0800 Subject: [PATCH 05/27] net/macb: Fetch q_ptr offset when the queue pointer is lagging Corrected the calculation method of tbqp by explicitly calculating the offset between TBQP and DMA address. Signed-off-by: Li Wencheng Signed-off-by: Wang Yinfeng Change-Id: I765e98a3bbf9cb08cdfe6e1a193394ae16d12dd8 --- devices/cadence/macb_main-6.6-ethercat.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/devices/cadence/macb_main-6.6-ethercat.c b/devices/cadence/macb_main-6.6-ethercat.c index 5421413..3b2e448 100644 --- a/devices/cadence/macb_main-6.6-ethercat.c +++ b/devices/cadence/macb_main-6.6-ethercat.c @@ -2121,7 +2121,8 @@ static void macb_tx_restart(struct macb_queue *queue) if (queue->tx_head == queue->tx_tail) goto out_tx_ptr_unlock; - tbqp = queue_readl(queue, TBQP) / macb_dma_desc_get_size(bp); + tbqp = queue_readl(queue, TBQP) - lower_32_bits(queue->tx_ring_dma); + tbqp = tbqp / macb_dma_desc_get_size(bp); tbqp = macb_adj_dma_desc_idx(bp, macb_tx_ring_wrap(bp, tbqp)); head_idx = macb_adj_dma_desc_idx(bp, macb_tx_ring_wrap(bp, queue->tx_head)); -- Gitee From 55935463d64d2af7c13186c40fe6e734c31f6995 Mon Sep 17 00:00:00 2001 From: zuoqian Date: Fri, 7 Mar 2025 10:33:53 +0800 Subject: [PATCH 06/27] driver: net: phy: add 'force_phy_mode' to fix Motorcomm RGMII phy failure. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On vpx development boards, when phytium gmac running in RGMII, RGMII0_RXD1 pin is high level by default. this cause Motorcomm RGMII phy recognize its chip mode from UTP_TO_RGMII to FIBER_TO_RGMII,resulting failure. So here,fix it. Signed-off-by: shiguangyuan Signed-off-by: zuoqian --- devices/cadence/macb-6.6-ethercat.h | 2 ++ devices/cadence/macb_main-6.6-ethercat.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/devices/cadence/macb-6.6-ethercat.h b/devices/cadence/macb-6.6-ethercat.h index be5fe46..4877484 100644 --- a/devices/cadence/macb-6.6-ethercat.h +++ b/devices/cadence/macb-6.6-ethercat.h @@ -1344,6 +1344,8 @@ struct macb { int duplex; int use_ncsi; + int force_phy_mode; + u32 caps; unsigned int dma_burst_length; diff --git a/devices/cadence/macb_main-6.6-ethercat.c b/devices/cadence/macb_main-6.6-ethercat.c index 3b2e448..d32126e 100644 --- a/devices/cadence/macb_main-6.6-ethercat.c +++ b/devices/cadence/macb_main-6.6-ethercat.c @@ -1114,6 +1114,7 @@ static int macb_phylink_connect(struct macb *bp) netdev_err(dev, "no PHY found\n"); return -ENXIO; } + phydev->force_mode = bp->force_phy_mode; /* attach the mac to the phy */ if (phylink_expects_phy(bp->phylink)) @@ -6036,6 +6037,10 @@ static int macb_probe(struct platform_device *pdev) if (err) goto err_out_free_netdev; + if (device_property_read_bool(&pdev->dev, "force-phy-mode")) { + bp->force_phy_mode = 1; + } + err = macb_mii_init(bp); if (err) goto err_out_phy_exit; -- Gitee From 59da3f4065181d21523cf6b3d691873ddab16696 Mon Sep 17 00:00:00 2001 From: zuoqian Date: Tue, 10 Jun 2025 16:41:11 +0800 Subject: [PATCH 07/27] net: macb: Fix 10G to support link status detection Remove bp->link, it is not used. Turn on PCS tx channel in usx pcs_config callback. This makes PCS can enter sync state. Signed-off-by: zuoqian --- devices/cadence/macb-6.6-ethercat.h | 1 - devices/cadence/macb_main-6.6-ethercat.c | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/devices/cadence/macb-6.6-ethercat.h b/devices/cadence/macb-6.6-ethercat.h index 4877484..dfe6102 100644 --- a/devices/cadence/macb-6.6-ethercat.h +++ b/devices/cadence/macb-6.6-ethercat.h @@ -1339,7 +1339,6 @@ struct macb { struct phylink_config phylink_config; struct phylink_pcs phylink_usx_pcs; struct phylink_pcs phylink_sgmii_pcs; - int link; int speed; int duplex; int use_ncsi; diff --git a/devices/cadence/macb_main-6.6-ethercat.c b/devices/cadence/macb_main-6.6-ethercat.c index d32126e..e1c69ba 100644 --- a/devices/cadence/macb_main-6.6-ethercat.c +++ b/devices/cadence/macb_main-6.6-ethercat.c @@ -640,7 +640,7 @@ static int macb_usx_pcs_config(struct phylink_pcs *pcs, struct macb *bp = container_of(pcs, struct macb, phylink_usx_pcs); gem_writel(bp, USX_CONTROL, gem_readl(bp, USX_CONTROL) | - GEM_BIT(SIGNAL_OK)); + GEM_BIT(SIGNAL_OK) | GEM_BIT(TX_EN)); return 0; } @@ -3443,9 +3443,6 @@ static void macb_init_hw(struct macb *bp) if (bp->caps & MACB_CAPS_SEL_CLK) bp->sel_clk_hw(bp, bp->speed); phytium_mac_config(bp); - if (bp->link) - macb_usx_pcs_link_up(&bp->phylink_usx_pcs, 0, - bp->phy_interface, bp->speed, bp->duplex); } else { bp->speed = SPEED_10; bp->duplex = DUPLEX_HALF; -- Gitee From a8b6be0451d15183c067a87aa9509cc900135111 Mon Sep 17 00:00:00 2001 From: zuoqian Date: Wed, 11 Jun 2025 13:59:39 +0800 Subject: [PATCH 08/27] net: macb: fix NULL pointer in fixed-link mode when unbind 10G device When using fixed-link configuration, the mii_bus structure is not created. Added NULL pointer check before accessing mii_bus. [ 257.223408] Unable to handle kernel NULL pointer dereference at virtual address 00000000000004a8 [ 257.232199] Mem abort info: [ 257.234983] ESR = 0x0000000096000004 [ 257.238731] EC = 0x25: DABT (current EL), IL = 32 bits [ 257.244045] SET = 0, FnV = 0 [ 257.247090] EA = 0, S1PTW = 0 [ 257.250228] FSC = 0x04: level 0 translation fault [ 257.255105] Data abort info: [ 257.257982] ISV = 0, ISS = 0x00000004, ISS2 = 0x00000000 [ 257.263464] CM = 0, WnR = 0, TnD = 0, TagAccess = 0 [ 257.268512] GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0 [ 257.273821] user pgtable: 4k pages, 48-bit VAs, pgdp=00000020062ef000 [ 257.280260] [00000000000004a8] pgd=0000000000000000, p4d=0000000000000000 ... [ 257.329752] pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 257.336707] pc : mdiobus_unregister+0x10/0xa0 [ 257.341063] lr : macb_remove+0x38/0x164 [ 257.344894] sp : ffff800082aabb80 [ 257.348199] x29: ffff800082aabb80 x28: ffff001f80a3ab80 x27: 0000000000000000 [ 257.355331] x26: 0000000000000000 x25: 0000000000000000 x24: ffff001f83ddc0e0 [ 257.362462] x23: ffff8000816a6740 x22: 0000000000000000 x21: ffff001f818d8000 [ 257.369592] x20: ffff001f818d8a00 x19: ffff001f8097b810 x18: 0000000000000000 [ 257.376722] x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000000 [ 257.383853] x14: 0000000000000000 x13: 000000000000025d x12: 0000000000000002 [ 257.390983] x11: 0000000000000000 x10: 0000000000000a80 x9 : ffff800082aab8a0 [ 257.398114] x8 : ffff001f80a3b660 x7 : 0000000000000001 x6 : ffff8000816cdd68 [ 257.405244] x5 : ffff001f818d8558 x4 : 0000000000000000 x3 : 0000000000000001 [ 257.412374] x2 : 0000000000000000 x1 : 0000000000000000 x0 : 0000000000000000 [ 257.419505] Call trace: [ 257.421941] mdiobus_unregister+0x10/0xa0 [ 257.425944] macb_remove+0x38/0x164 [ 257.429425] platform_remove+0x4c/0x64 [ 257.433168] device_remove+0x48/0x74 [ 257.436735] device_release_driver_internal+0x1c0/0x218 [ 257.441952] device_driver_detach+0x14/0x1c [ 257.446127] unbind_store+0xac/0xb0 [ 257.449609] drv_attr_store+0x20/0x30 [ 257.453265] sysfs_kf_write+0x40/0x4c [ 257.456921] kernfs_fop_write_iter+0x118/0x1dc [ 257.461357] vfs_write+0x1c0/0x320 [ 257.464752] ksys_write+0x70/0x104 [ 257.468146] __arm64_sys_write+0x18/0x20 ... Signed-off-by: zuoqian --- devices/cadence/macb_main-6.6-ethercat.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/devices/cadence/macb_main-6.6-ethercat.c b/devices/cadence/macb_main-6.6-ethercat.c index e1c69ba..fbf02f9 100644 --- a/devices/cadence/macb_main-6.6-ethercat.c +++ b/devices/cadence/macb_main-6.6-ethercat.c @@ -6091,8 +6091,10 @@ static int macb_probe(struct platform_device *pdev) return 0; err_out_unregister_mdio: - mdiobus_unregister(bp->mii_bus); - mdiobus_free(bp->mii_bus); + if (bp->mii_bus) { + mdiobus_unregister(bp->mii_bus); + mdiobus_free(bp->mii_bus); + } err_out_phy_exit: phy_exit(bp->sgmii_phy); @@ -6128,9 +6130,10 @@ static int macb_remove(struct platform_device *pdev) unregister_netdev(dev); phy_exit(bp->sgmii_phy); - mdiobus_unregister(bp->mii_bus); - mdiobus_free(bp->mii_bus); - + if (bp->mii_bus) { + mdiobus_unregister(bp->mii_bus); + mdiobus_free(bp->mii_bus); + } if (!bp->ecdev) { tasklet_kill(&bp->hresp_err_tasklet); pm_runtime_disable(&pdev->dev); -- Gitee From 58454b149e95b15543675abfe2fc999faa85c5e8 Mon Sep 17 00:00:00 2001 From: liutianyu1250 Date: Fri, 20 Jun 2025 10:16:19 +0800 Subject: [PATCH 09/27] net/macb: add check with fixed-link when connect phy When set macb with fixed-link in acpi or devicetree, phy_find_first() can't find phydev. Just like phytmac, not do scan and connect phy when use fixed-link mode. Signed-off-by: liutianyu1250 --- devices/cadence/macb_main-6.6-orig.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/devices/cadence/macb_main-6.6-orig.c b/devices/cadence/macb_main-6.6-orig.c index 9777761..0391a41 100644 --- a/devices/cadence/macb_main-6.6-orig.c +++ b/devices/cadence/macb_main-6.6-orig.c @@ -1080,24 +1080,17 @@ static const struct phylink_mac_ops macb_phylink_ops = { .mac_link_up = macb_mac_link_up, }; -static bool macb_phy_handle_exists(struct device_node *dn) -{ - dn = of_parse_phandle(dn, "phy-handle", 0); - of_node_put(dn); - return dn != NULL; -} - static int macb_phylink_connect(struct macb *bp) { - struct device_node *dn = bp->pdev->dev.of_node; + struct fwnode_handle *fwnode = dev_fwnode(&bp->pdev->dev); struct net_device *dev = bp->dev; struct phy_device *phydev; int ret = 0; - if (dn) - ret = phylink_of_phy_connect(bp->phylink, dn, 0); + if (fwnode) + ret = phylink_fwnode_phy_connect(bp->phylink, fwnode, 0); - if (!dn || (ret && !macb_phy_handle_exists(dn))) { + if (!fwnode || ret) { phydev = phy_find_first(bp->mii_bus); if (!phydev) { netdev_err(dev, "no PHY found\n"); @@ -1106,8 +1099,7 @@ static int macb_phylink_connect(struct macb *bp) phydev->force_mode = bp->force_phy_mode; /* attach the mac to the phy */ - if (phylink_expects_phy(bp->phylink)) - ret = phylink_connect_phy(bp->phylink, phydev); + ret = phylink_connect_phy(bp->phylink, phydev); } if (ret) { -- Gitee From 59bda820027e7178080a23f103f8c568c1e2e2a5 Mon Sep 17 00:00:00 2001 From: liutianyu1250 Date: Fri, 20 Jun 2025 10:16:19 +0800 Subject: [PATCH 10/27] net/macb: add check with fixed-link when connect phy When set macb with fixed-link in acpi or devicetree, phy_find_first() can't find phydev. Just like phytmac, not do scan and connect phy when use fixed-link mode. Signed-off-by: liutianyu1250 --- devices/cadence/macb_main-6.6-ethercat.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/devices/cadence/macb_main-6.6-ethercat.c b/devices/cadence/macb_main-6.6-ethercat.c index fbf02f9..e349601 100644 --- a/devices/cadence/macb_main-6.6-ethercat.c +++ b/devices/cadence/macb_main-6.6-ethercat.c @@ -1091,24 +1091,17 @@ static const struct phylink_mac_ops macb_phylink_ops = { .mac_link_up = macb_mac_link_up, }; -static bool macb_phy_handle_exists(struct device_node *dn) -{ - dn = of_parse_phandle(dn, "phy-handle", 0); - of_node_put(dn); - return dn != NULL; -} - static int macb_phylink_connect(struct macb *bp) { - struct device_node *dn = bp->pdev->dev.of_node; + struct fwnode_handle *fwnode = dev_fwnode(&bp->pdev->dev); struct net_device *dev = bp->dev; struct phy_device *phydev; int ret = 0; - if (dn) - ret = phylink_of_phy_connect(bp->phylink, dn, 0); + if (fwnode) + ret = phylink_fwnode_phy_connect(bp->phylink, fwnode, 0); - if (!dn || (ret && !macb_phy_handle_exists(dn))) { + if (!fwnode || ret) { phydev = phy_find_first(bp->mii_bus); if (!phydev) { netdev_err(dev, "no PHY found\n"); @@ -1117,8 +1110,7 @@ static int macb_phylink_connect(struct macb *bp) phydev->force_mode = bp->force_phy_mode; /* attach the mac to the phy */ - if (phylink_expects_phy(bp->phylink)) - ret = phylink_connect_phy(bp->phylink, phydev); + ret = phylink_connect_phy(bp->phylink, phydev); } if (ret) { -- Gitee From 06e3301c849971eeb951d0f157718ea64eb82718 Mon Sep 17 00:00:00 2001 From: shipinsky Date: Fri, 16 May 2025 14:10:15 +0800 Subject: [PATCH 11/27] net/macb: Print the number of packets received and dropped by a driver module when unloading it --- devices/cadence/macb_main-4.19-ethercat.c | 14 +++++++++----- devices/cadence/macb_main-5.10-ethercat.c | 14 +++++++++----- devices/cadence/macb_main-6.6-ethercat.c | 14 +++++++++----- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/devices/cadence/macb_main-4.19-ethercat.c b/devices/cadence/macb_main-4.19-ethercat.c index 9bcf1d8..320dcba 100644 --- a/devices/cadence/macb_main-4.19-ethercat.c +++ b/devices/cadence/macb_main-4.19-ethercat.c @@ -1437,12 +1437,11 @@ static int gem_rx(struct macb_queue *queue, int budget) !(bp->dev->flags & IFF_PROMISC) && GEM_BFEXT(RX_CSUM, ctrl) & GEM_RX_CSUM_CHECKED_MASK) skb->ip_summed = CHECKSUM_UNNECESSARY; - - bp->dev->stats.rx_packets++; - queue->stats.rx_packets++; - bp->dev->stats.rx_bytes += skb->len; - queue->stats.rx_bytes += skb->len; } + bp->dev->stats.rx_packets++; + queue->stats.rx_packets++; + bp->dev->stats.rx_bytes += skb->len; + queue->stats.rx_bytes += skb->len; gem_ptp_do_rxstamp(bp, skb, desc); @@ -3099,6 +3098,11 @@ static int macb_close(struct net_device *dev) netif_tx_stop_all_queues(dev); for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) napi_disable(&queue->napi); + } else { + printk("%s tx packets %lu\n", __func__, bp->dev->stats.tx_packets); + printk("%s tx dropped packets %lu\n", __func__, bp->dev->stats.tx_dropped); + printk("%s rx packets %lu\n", __func__, bp->dev->stats.rx_packets); + printk("%s rx dropped packets %lu\n", __func__, bp->dev->stats.rx_dropped); } if (dev->phydev) phy_stop(dev->phydev); diff --git a/devices/cadence/macb_main-5.10-ethercat.c b/devices/cadence/macb_main-5.10-ethercat.c index 57c993f..d695e78 100644 --- a/devices/cadence/macb_main-5.10-ethercat.c +++ b/devices/cadence/macb_main-5.10-ethercat.c @@ -1793,12 +1793,11 @@ static int gem_rx(struct macb_queue *queue, struct napi_struct *napi, !(bp->dev->flags & IFF_PROMISC) && GEM_BFEXT(RX_CSUM, ctrl) & GEM_RX_CSUM_CHECKED_MASK) skb->ip_summed = CHECKSUM_UNNECESSARY; - - bp->dev->stats.rx_packets++; - queue->stats.rx_packets++; - bp->dev->stats.rx_bytes += skb->len; - queue->stats.rx_bytes += skb->len; } + bp->dev->stats.rx_packets++; + queue->stats.rx_packets++; + bp->dev->stats.rx_bytes += skb->len; + queue->stats.rx_bytes += skb->len; gem_ptp_do_rxstamp(bp, skb, desc); @@ -3514,6 +3513,11 @@ static int __macb_close(struct net_device *dev) netif_tx_stop_all_queues(dev); for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) napi_disable(&queue->napi); + } else { + printk("%s tx packets %lu\n", __func__, bp->dev->stats.tx_packets); + printk("%s tx dropped packets %lu\n", __func__, bp->dev->stats.tx_dropped); + printk("%s rx packets %lu\n", __func__, bp->dev->stats.rx_packets); + printk("%s rx dropped packets %lu\n", __func__, bp->dev->stats.rx_dropped); } phylink_stop(bp->phylink); phylink_disconnect_phy(bp->phylink); diff --git a/devices/cadence/macb_main-6.6-ethercat.c b/devices/cadence/macb_main-6.6-ethercat.c index e349601..b2390f3 100644 --- a/devices/cadence/macb_main-6.6-ethercat.c +++ b/devices/cadence/macb_main-6.6-ethercat.c @@ -1842,12 +1842,11 @@ static int gem_rx(struct macb_queue *queue, struct napi_struct *napi, !(bp->dev->flags & IFF_PROMISC) && GEM_BFEXT(RX_CSUM, ctrl) & GEM_RX_CSUM_CHECKED_MASK) skb->ip_summed = CHECKSUM_UNNECESSARY; - - bp->dev->stats.rx_packets++; - queue->stats.rx_packets++; - bp->dev->stats.rx_bytes += skb->len; - queue->stats.rx_bytes += skb->len; } + bp->dev->stats.rx_packets++; + queue->stats.rx_packets++; + bp->dev->stats.rx_bytes += skb->len; + queue->stats.rx_bytes += skb->len; gem_ptp_do_rxstamp(bp, skb, desc); @@ -3655,6 +3654,11 @@ static int __macb_close(struct net_device *dev) napi_disable(&queue->napi_rx); napi_disable(&queue->napi_tx); } + } else { + printk("%s tx packets %lu\n", __func__, bp->dev->stats.tx_packets); + printk("%s tx dropped packets %lu\n", __func__, bp->dev->stats.tx_dropped); + printk("%s rx packets %lu\n", __func__, bp->dev->stats.rx_packets); + printk("%s rx dropped packets %lu\n", __func__, bp->dev->stats.rx_dropped); } phylink_stop(bp->phylink); -- Gitee From a220476fee247a9748cce1a9db827d15360feec1 Mon Sep 17 00:00:00 2001 From: shipinsky Date: Tue, 20 May 2025 11:29:50 +0800 Subject: [PATCH 12/27] Log errors in fault cases in EtherCAT CoE --- master/fsm_coe.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/master/fsm_coe.c b/master/fsm_coe.c index 69765cd..d24636f 100644 --- a/master/fsm_coe.c +++ b/master/fsm_coe.c @@ -1614,14 +1614,17 @@ void ec_fsm_coe_down_response( } else { sprintf(subidxstr, ":%02X", request->subindex); } - EC_SLAVE_ERR(slave, "SDO download 0x%04X%s (%zu bytes) aborted.\n", - request->index, subidxstr, request->data_size); + EC_SLAVE_ERR(slave, "%s SDO download 0x%04X%s (%zu bytes) aborted," + " SDO request %#hx, abort SDO transfer request %#hhx.\n", + __func__, request->index, subidxstr, request->data_size, + EC_READ_U16(data) >> 12, EC_READ_U8 (data + 2) >> 5); if (rec_size < 10) { EC_SLAVE_ERR(slave, "Incomplete abort command:\n"); ec_print_data(data, rec_size); } else { fsm->request->abort_code = EC_READ_U32(data + 6); ec_canopen_abort_msg(slave, fsm->request->abort_code); + ec_print_data(data, rec_size); } return; } @@ -1792,14 +1795,17 @@ void ec_fsm_coe_down_seg_response( } else { sprintf(subidxstr, ":%02X", request->subindex); } - EC_SLAVE_ERR(slave, "SDO download 0x%04X%s (%zu bytes) aborted.\n", - request->index, subidxstr, request->data_size); + EC_SLAVE_ERR(slave, "%s SDO download 0x%04X%s (%zu bytes) aborted," + " SDO request %#hx, abort SDO transfer request %#hhx.\n", + __func__, request->index, subidxstr, request->data_size, + EC_READ_U16(data) >> 12, EC_READ_U8 (data + 2) >> 5); if (rec_size < 10) { EC_SLAVE_ERR(slave, "Incomplete abort command:\n"); ec_print_data(data, rec_size); } else { fsm->request->abort_code = EC_READ_U32(data + 6); ec_canopen_abort_msg(slave, fsm->request->abort_code); + ec_print_data(data, rec_size); } return; } @@ -2146,14 +2152,17 @@ void ec_fsm_coe_up_response( if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request EC_READ_U8(data + 2) >> 5 == 0x4) { // abort SDO transfer request - EC_SLAVE_ERR(slave, "SDO upload 0x%04X:%02X aborted.\n", - request->index, request->subindex); + EC_SLAVE_ERR(slave, "%s SDO upload 0x%04X:%02X aborted," + " SDO request %#hx, abort SDO transfer request %#hhx.\n", + __func__, request->index, request->subindex, + EC_READ_U16(data) >> 12, EC_READ_U8 (data + 2) >> 5); if (rec_size >= 10) { request->abort_code = EC_READ_U32(data + 6); ec_canopen_abort_msg(slave, request->abort_code); } else { EC_SLAVE_ERR(slave, "No abort message.\n"); } + ec_print_data(data, rec_size); request->errno = EIO; fsm->state = ec_fsm_coe_error; return; @@ -2161,9 +2170,10 @@ void ec_fsm_coe_up_response( if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response EC_READ_U8(data + 2) >> 5 != 0x2) { // upload response - EC_SLAVE_ERR(slave, "Received unknown response while" - " uploading SDO 0x%04X:%02X.\n", - request->index, request->subindex); + EC_SLAVE_ERR(slave, "%s Received unknown response while" + " uploading SDO 0x%04X:%02X, SDO request %#hx, abort SDO transfer request %#hhx.\n", + __func__, request->index, request->subindex, + EC_READ_U16(data) >> 12, EC_READ_U8 (data + 2) >> 5); ec_print_data(data, rec_size); request->errno = EIO; fsm->state = ec_fsm_coe_error; @@ -2443,10 +2453,13 @@ void ec_fsm_coe_up_seg_response( if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request - EC_SLAVE_ERR(slave, "SDO upload 0x%04X:%02X aborted.\n", - request->index, request->subindex); + EC_SLAVE_ERR(slave, "%s SDO upload 0x%04X:%02X aborted," + " SDO request %#hx, abort SDO transfer request %#hhx.\n", + __func__, request->index, request->subindex, + EC_READ_U16(data) >> 12, EC_READ_U8 (data + 2) >> 5); request->abort_code = EC_READ_U32(data + 6); ec_canopen_abort_msg(slave, request->abort_code); + ec_print_data(data, rec_size); request->errno = EIO; fsm->state = ec_fsm_coe_error; return; -- Gitee From dc3cf8165058ee68b5d462bee1eac94a6ae76941 Mon Sep 17 00:00:00 2001 From: shipinsky Date: Wed, 21 May 2025 15:47:24 +0800 Subject: [PATCH 13/27] net/macb: Print the number of packets received and dropped by hardware when unloading it --- devices/cadence/macb_main-4.19-ethercat.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/devices/cadence/macb_main-4.19-ethercat.c b/devices/cadence/macb_main-4.19-ethercat.c index 320dcba..14e2a75 100644 --- a/devices/cadence/macb_main-4.19-ethercat.c +++ b/devices/cadence/macb_main-4.19-ethercat.c @@ -3087,6 +3087,7 @@ static int macb_open(struct net_device *dev) return 0; } +static void gem_update_stats(struct macb *bp); static int macb_close(struct net_device *dev) { struct macb *bp = netdev_priv(dev); @@ -3099,10 +3100,14 @@ static int macb_close(struct net_device *dev) for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) napi_disable(&queue->napi); } else { + int i; printk("%s tx packets %lu\n", __func__, bp->dev->stats.tx_packets); printk("%s tx dropped packets %lu\n", __func__, bp->dev->stats.tx_dropped); printk("%s rx packets %lu\n", __func__, bp->dev->stats.rx_packets); printk("%s rx dropped packets %lu\n", __func__, bp->dev->stats.rx_dropped); + gem_update_stats(bp); + for (i = 0; i < GEM_STATS_LEN; i++) + printk("%s %llu\n", gem_statistics[i].stat_string, (unsigned long long)bp->ethtool_stats[i]); } if (dev->phydev) phy_stop(dev->phydev); -- Gitee From 9f814804c23cb142a3ec8c77df7500890b1b612a Mon Sep 17 00:00:00 2001 From: shipinsky Date: Thu, 22 May 2025 09:17:58 +0800 Subject: [PATCH 14/27] Optimize log errors in fault cases in EtherCAT CoE --- master/fsm_coe.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/master/fsm_coe.c b/master/fsm_coe.c index d24636f..6c4a0e3 100644 --- a/master/fsm_coe.c +++ b/master/fsm_coe.c @@ -1614,10 +1614,8 @@ void ec_fsm_coe_down_response( } else { sprintf(subidxstr, ":%02X", request->subindex); } - EC_SLAVE_ERR(slave, "%s SDO download 0x%04X%s (%zu bytes) aborted," - " SDO request %#hx, abort SDO transfer request %#hhx.\n", - __func__, request->index, subidxstr, request->data_size, - EC_READ_U16(data) >> 12, EC_READ_U8 (data + 2) >> 5); + EC_SLAVE_ERR(slave, "%s SDO download 0x%04X%s (%zu bytes) aborted.\n", + __func__, request->index, subidxstr, request->data_size); if (rec_size < 10) { EC_SLAVE_ERR(slave, "Incomplete abort command:\n"); ec_print_data(data, rec_size); @@ -1795,10 +1793,8 @@ void ec_fsm_coe_down_seg_response( } else { sprintf(subidxstr, ":%02X", request->subindex); } - EC_SLAVE_ERR(slave, "%s SDO download 0x%04X%s (%zu bytes) aborted," - " SDO request %#hx, abort SDO transfer request %#hhx.\n", - __func__, request->index, subidxstr, request->data_size, - EC_READ_U16(data) >> 12, EC_READ_U8 (data + 2) >> 5); + EC_SLAVE_ERR(slave, "%s SDO download 0x%04X%s (%zu bytes) aborted.\n", + __func__, request->index, subidxstr, request->data_size); if (rec_size < 10) { EC_SLAVE_ERR(slave, "Incomplete abort command:\n"); ec_print_data(data, rec_size); @@ -2152,10 +2148,8 @@ void ec_fsm_coe_up_response( if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request EC_READ_U8(data + 2) >> 5 == 0x4) { // abort SDO transfer request - EC_SLAVE_ERR(slave, "%s SDO upload 0x%04X:%02X aborted," - " SDO request %#hx, abort SDO transfer request %#hhx.\n", - __func__, request->index, request->subindex, - EC_READ_U16(data) >> 12, EC_READ_U8 (data + 2) >> 5); + EC_SLAVE_ERR(slave, "%s SDO upload 0x%04X:%02X aborted.\n", + __func__, request->index, request->subindex); if (rec_size >= 10) { request->abort_code = EC_READ_U32(data + 6); ec_canopen_abort_msg(slave, request->abort_code); @@ -2453,10 +2447,8 @@ void ec_fsm_coe_up_seg_response( if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request - EC_SLAVE_ERR(slave, "%s SDO upload 0x%04X:%02X aborted," - " SDO request %#hx, abort SDO transfer request %#hhx.\n", - __func__, request->index, request->subindex, - EC_READ_U16(data) >> 12, EC_READ_U8 (data + 2) >> 5); + EC_SLAVE_ERR(slave, "%s SDO upload 0x%04X:%02X aborted.\n", + __func__, request->index, request->subindex); request->abort_code = EC_READ_U32(data + 6); ec_canopen_abort_msg(slave, request->abort_code); ec_print_data(data, rec_size); -- Gitee From 8ac7f4eced9bf7399b920edb8403b755bcd1b063 Mon Sep 17 00:00:00 2001 From: shipinsky Date: Thu, 22 May 2025 09:24:05 +0800 Subject: [PATCH 15/27] Optimize log errors in fault cases in EtherCAT CoE --- master/fsm_coe.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/master/fsm_coe.c b/master/fsm_coe.c index 6c4a0e3..7ba727c 100644 --- a/master/fsm_coe.c +++ b/master/fsm_coe.c @@ -2165,7 +2165,8 @@ void ec_fsm_coe_up_response( if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response EC_READ_U8(data + 2) >> 5 != 0x2) { // upload response EC_SLAVE_ERR(slave, "%s Received unknown response while" - " uploading SDO 0x%04X:%02X, SDO request %#hx, abort SDO transfer request %#hhx.\n", + " uploading SDO 0x%04X:%02X, SDO response %#hx," + " upload response %#hhx.\n", __func__, request->index, request->subindex, EC_READ_U16(data) >> 12, EC_READ_U8 (data + 2) >> 5); ec_print_data(data, rec_size); -- Gitee From bd26e4f64eec0b9765709e511ab38b9bcb00bd0c Mon Sep 17 00:00:00 2001 From: shipinsky Date: Thu, 22 May 2025 11:15:26 +0800 Subject: [PATCH 16/27] net/macb: Sync the print of the numbers of packets received and dropped by hardware when unloading module --- devices/cadence/macb_main-5.10-ethercat.c | 4 ++++ devices/cadence/macb_main-6.6-ethercat.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/devices/cadence/macb_main-5.10-ethercat.c b/devices/cadence/macb_main-5.10-ethercat.c index d695e78..5f1febe 100644 --- a/devices/cadence/macb_main-5.10-ethercat.c +++ b/devices/cadence/macb_main-5.10-ethercat.c @@ -3502,6 +3502,7 @@ static int macb_open(struct net_device *dev) return ret; } +static void gem_update_stats(struct macb *bp); static int __macb_close(struct net_device *dev) { struct macb *bp = netdev_priv(dev); @@ -3518,6 +3519,9 @@ static int __macb_close(struct net_device *dev) printk("%s tx dropped packets %lu\n", __func__, bp->dev->stats.tx_dropped); printk("%s rx packets %lu\n", __func__, bp->dev->stats.rx_packets); printk("%s rx dropped packets %lu\n", __func__, bp->dev->stats.rx_dropped); + gem_update_stats(bp); + for (i = 0; i < GEM_STATS_LEN; i++) + printk("%s %llu\n", gem_statistics[i].stat_string, (unsigned long long)ethtool_stats[i]); } phylink_stop(bp->phylink); phylink_disconnect_phy(bp->phylink); diff --git a/devices/cadence/macb_main-6.6-ethercat.c b/devices/cadence/macb_main-6.6-ethercat.c index b2390f3..7068998 100644 --- a/devices/cadence/macb_main-6.6-ethercat.c +++ b/devices/cadence/macb_main-6.6-ethercat.c @@ -3640,6 +3640,7 @@ static int macb_open(struct net_device *dev) return ret; } +static void gem_update_stats(struct macb *bp); static int __macb_close(struct net_device *dev) { struct macb *bp = netdev_priv(dev); @@ -3659,6 +3660,9 @@ static int __macb_close(struct net_device *dev) printk("%s tx dropped packets %lu\n", __func__, bp->dev->stats.tx_dropped); printk("%s rx packets %lu\n", __func__, bp->dev->stats.rx_packets); printk("%s rx dropped packets %lu\n", __func__, bp->dev->stats.rx_dropped); + gem_update_stats(bp); + for (i = 0; i < GEM_STATS_LEN; i++) + printk("%s %llu\n", gem_statistics[i].stat_string, (unsigned long long)ethtool_stats[i]); } phylink_stop(bp->phylink); -- Gitee From 28681ccc04e1613ca126b74ea87ec322a18a4762 Mon Sep 17 00:00:00 2001 From: shipinsky Date: Wed, 18 Jun 2025 15:56:02 +0800 Subject: [PATCH 17/27] Fix compilation issues --- devices/cadence/macb_main-5.10-ethercat.c | 3 ++- devices/cadence/macb_main-6.6-ethercat.c | 11 +++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/devices/cadence/macb_main-5.10-ethercat.c b/devices/cadence/macb_main-5.10-ethercat.c index 5f1febe..894a34d 100644 --- a/devices/cadence/macb_main-5.10-ethercat.c +++ b/devices/cadence/macb_main-5.10-ethercat.c @@ -3515,13 +3515,14 @@ static int __macb_close(struct net_device *dev) for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) napi_disable(&queue->napi); } else { + int i; printk("%s tx packets %lu\n", __func__, bp->dev->stats.tx_packets); printk("%s tx dropped packets %lu\n", __func__, bp->dev->stats.tx_dropped); printk("%s rx packets %lu\n", __func__, bp->dev->stats.rx_packets); printk("%s rx dropped packets %lu\n", __func__, bp->dev->stats.rx_dropped); gem_update_stats(bp); for (i = 0; i < GEM_STATS_LEN; i++) - printk("%s %llu\n", gem_statistics[i].stat_string, (unsigned long long)ethtool_stats[i]); + printk("%s %llu\n", gem_statistics[i].stat_string, (unsigned long long)bp->ethtool_stats[i]); } phylink_stop(bp->phylink); phylink_disconnect_phy(bp->phylink); diff --git a/devices/cadence/macb_main-6.6-ethercat.c b/devices/cadence/macb_main-6.6-ethercat.c index 7068998..44c320b 100644 --- a/devices/cadence/macb_main-6.6-ethercat.c +++ b/devices/cadence/macb_main-6.6-ethercat.c @@ -765,7 +765,7 @@ static void macb_mac_link_down(struct phylink_config *config, unsigned int mode, macb_writel(bp, NCR, ctrl); if (bp->ecdev) { - bp->link = 0; + ecdev_set_link(bp->ecdev, 0); return; } @@ -1063,7 +1063,7 @@ static void macb_mac_link_up(struct phylink_config *config, if (!bp->ecdev) netif_tx_wake_all_queues(ndev); else - bp->link = 1; + ecdev_set_link(bp->ecdev, 1);; } static struct phylink_pcs *macb_mac_select_pcs(struct phylink_config *config, @@ -2221,10 +2221,8 @@ static void ec_poll(struct net_device *dev) ec_tx_poll(queue, 64); } - if (jiffies - bp->ec_watchdog_jiffies >= 2 * HZ) { - ecdev_set_link(bp->ecdev, bp->link ? 1 : 0); + if (jiffies - bp->ec_watchdog_jiffies >= 2 * HZ) bp->ec_watchdog_jiffies = jiffies; - } } static void macb_hresp_error_task(struct tasklet_struct *t) @@ -3656,13 +3654,14 @@ static int __macb_close(struct net_device *dev) napi_disable(&queue->napi_tx); } } else { + int i; printk("%s tx packets %lu\n", __func__, bp->dev->stats.tx_packets); printk("%s tx dropped packets %lu\n", __func__, bp->dev->stats.tx_dropped); printk("%s rx packets %lu\n", __func__, bp->dev->stats.rx_packets); printk("%s rx dropped packets %lu\n", __func__, bp->dev->stats.rx_dropped); gem_update_stats(bp); for (i = 0; i < GEM_STATS_LEN; i++) - printk("%s %llu\n", gem_statistics[i].stat_string, (unsigned long long)ethtool_stats[i]); + printk("%s %llu\n", gem_statistics[i].stat_string, (unsigned long long)bp->ethtool_stats[i]); } phylink_stop(bp->phylink); -- Gitee From bb0ca0797fe97345d98668d2498934331860a0b4 Mon Sep 17 00:00:00 2001 From: Richard Hacker Date: Mon, 18 Nov 2024 10:54:00 +0100 Subject: [PATCH 18/27] Remove unnecessary inline statement causing build -O0 problems Fixes #147 --- lib/slave_config.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/slave_config.c b/lib/slave_config.c index 7bef3a9..58d6c7b 100644 --- a/lib/slave_config.c +++ b/lib/slave_config.c @@ -40,6 +40,7 @@ void ec_slave_config_add_sdo_request(ec_slave_config_t *, ec_sdo_request_t *); void ec_slave_config_add_reg_request(ec_slave_config_t *, ec_reg_request_t *); void ec_slave_config_add_voe_handler(ec_slave_config_t *, ec_voe_handler_t *); +void ec_slave_config_add_soe_request(ec_slave_config_t *, ec_soe_request_t *); /****************************************************************************/ @@ -625,7 +626,7 @@ ec_sdo_request_t *ecrt_slave_config_create_sdo_request(ec_slave_config_t *sc, /****************************************************************************/ -inline void ec_slave_config_add_soe_request(ec_slave_config_t *sc, +void ec_slave_config_add_soe_request(ec_slave_config_t *sc, ec_soe_request_t *req) { if (sc->first_soe_request) { -- Gitee From 60ef9253a56e20da738e8fc3f3fbb664fe0ccca7 Mon Sep 17 00:00:00 2001 From: zhanglin Date: Wed, 30 Aug 2023 18:53:13 +0800 Subject: [PATCH 19/27] Add pdo debug info --- master/slave.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/master/slave.c b/master/slave.c index 880b41d..882899a 100644 --- a/master/slave.c +++ b/master/slave.c @@ -541,8 +541,9 @@ int ec_slave_fetch_sii_pdos( data_size -= 8; data += 8; - EC_SLAVE_DBG(slave, 1, "%s(j %u, entry_count %u, pdo name: %s)\n", - __func__, j, entry_count, pdo->name); + EC_SLAVE_DBG(slave, 1, + "%s(j %u, entry_count %u, data size %lu, pdo name: %s)\n", + __func__, j, entry_count, data_size, pdo->name); for (i = 0; i < entry_count; i++) { if (!(entry = kmalloc(sizeof(ec_pdo_entry_t), GFP_KERNEL))) { EC_SLAVE_ERR(slave, "Failed to allocate PDO entry memory.\n"); @@ -564,6 +565,11 @@ int ec_slave_fetch_sii_pdos( data_size -= 8; data += 8; + EC_SLAVE_DBG(slave, 1, + " %s(i %u, entry->index %u, subindex %u, " + "bit_length %u, name: %s)\n", + __func__, i, entry->index, entry->subindex, entry->bit_length, + entry->name); } // if sync manager index is positive, the PDO is mapped by default -- Gitee From 10521a0bd28fe886d8d065fb1bd0ea022213e37e Mon Sep 17 00:00:00 2001 From: zhanglin Date: Thu, 31 Aug 2023 10:13:42 +0800 Subject: [PATCH 20/27] Convert the index of PDO to hexadecimal --- master/slave.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/master/slave.c b/master/slave.c index 882899a..ab5db39 100644 --- a/master/slave.c +++ b/master/slave.c @@ -566,7 +566,7 @@ int ec_slave_fetch_sii_pdos( data_size -= 8; data += 8; EC_SLAVE_DBG(slave, 1, - " %s(i %u, entry->index %u, subindex %u, " + " %s(i %u, entry->index 0x%x, subindex %u, " "bit_length %u, name: %s)\n", __func__, i, entry->index, entry->subindex, entry->bit_length, entry->name); -- Gitee From 28d3881ef8731425fd0d4ccd964654d9ee22a740 Mon Sep 17 00:00:00 2001 From: zhanglin Date: Thu, 31 Aug 2023 11:22:58 +0800 Subject: [PATCH 21/27] Add pdo debug info --- master/slave.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/master/slave.c b/master/slave.c index ab5db39..3347740 100644 --- a/master/slave.c +++ b/master/slave.c @@ -542,8 +542,10 @@ int ec_slave_fetch_sii_pdos( data_size -= 8; data += 8; EC_SLAVE_DBG(slave, 1, - "%s(j %u, entry_count %u, data size %lu, pdo name: %s)\n", - __func__, j, entry_count, data_size, pdo->name); + "%s(j %u, pdo->index 0x%x, entry_count %u, pdo->sync_index %d, " + "data size %lu, pdo name: %s)\n", + __func__, j, pdo->index, entry_count, pdo->sync_index, + data_size, pdo->name); for (i = 0; i < entry_count; i++) { if (!(entry = kmalloc(sizeof(ec_pdo_entry_t), GFP_KERNEL))) { EC_SLAVE_ERR(slave, "Failed to allocate PDO entry memory.\n"); -- Gitee From e7bb007fa23c89b01624495948e316e7b2be197e Mon Sep 17 00:00:00 2001 From: Li Wencheng Date: Mon, 12 May 2025 13:51:22 +0800 Subject: [PATCH 22/27] net/macb: Slove the compile error in X86 architecture In the x86 architecture, if the CONFIG_OF configuration is not enabled,it will cause the compilation to fail. So we adjust the position of "#if defined (CONFIG_OF)". Mainline: Open-Source Signed-off-by: Li Wencheng Signed-off-by: Wang Yinfeng Change-Id: I658f0ad7da242e22249471529205f659d4738766 --- devices/cadence/macb_main-6.6-orig.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devices/cadence/macb_main-6.6-orig.c b/devices/cadence/macb_main-6.6-orig.c index 0391a41..65c375e 100644 --- a/devices/cadence/macb_main-6.6-orig.c +++ b/devices/cadence/macb_main-6.6-orig.c @@ -4809,7 +4809,6 @@ static const struct macb_usrio_config macb_default_usrio = { .refclk = MACB_BIT(CLKEN), }; -#if defined(CONFIG_OF) /* 1518 rounded up */ #define AT91ETHER_MAX_RBUFF_SZ 0x600 /* max number of receive buffers */ @@ -5526,6 +5525,7 @@ static const struct macb_config phytium_gem2p0_config = { .usrio = &macb_default_usrio, }; +#if defined(CONFIG_OF) static const struct of_device_id macb_dt_ids[] = { { .compatible = "cdns,at91sam9260-macb", .data = &at91sam9260_config }, { .compatible = "cdns,macb" }, -- Gitee From bf73117393ae044ca1b8237057839d169ce71b06 Mon Sep 17 00:00:00 2001 From: zuoqian Date: Mon, 29 Sep 2025 14:06:46 +0800 Subject: [PATCH 23/27] net: macb: fix fixed-link link down ethtool status Signed-off-by: zuoqian --- devices/cadence/macb_main-6.6-orig.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/devices/cadence/macb_main-6.6-orig.c b/devices/cadence/macb_main-6.6-orig.c index 65c375e..c9d554e 100644 --- a/devices/cadence/macb_main-6.6-orig.c +++ b/devices/cadence/macb_main-6.6-orig.c @@ -989,6 +989,9 @@ static void macb_mac_link_up(struct phylink_config *config, macb_set_tx_clk(bp, speed); + bp->speed = speed; + bp->duplex = duplex; + /* Initialize rings & buffers as clearing MACB_BIT(TE) in link down * cleared the pipeline and control registers. */ @@ -3775,8 +3778,13 @@ static int macb_get_link_ksettings(struct net_device *netdev, supported); ethtool_convert_legacy_u32_to_link_mode(kset->link_modes.advertising, advertising); - kset->base.speed = bp->speed; - kset->base.duplex = bp->duplex; + if (netif_carrier_ok(netdev)) { + kset->base.speed = bp->speed; + kset->base.duplex = bp->duplex; + } else { + kset->base.speed = SPEED_UNKNOWN; + kset->base.duplex = DUPLEX_UNKNOWN; + } } else { phylink_ethtool_ksettings_get(bp->phylink, kset); } -- Gitee From 2b0eafb1fdf38593595ca7b9a5ac0a2a71312f78 Mon Sep 17 00:00:00 2001 From: zuoqian Date: Fri, 17 Oct 2025 17:17:42 +0800 Subject: [PATCH 24/27] net: macb: support ipv6 TSO Signed-off-by: zuoqian --- devices/cadence/macb_main-6.6-orig.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devices/cadence/macb_main-6.6-orig.c b/devices/cadence/macb_main-6.6-orig.c index c9d554e..f656e81 100644 --- a/devices/cadence/macb_main-6.6-orig.c +++ b/devices/cadence/macb_main-6.6-orig.c @@ -88,7 +88,7 @@ struct sifive_fu540_macb_mgmt { #define GEM_MAX_TX_LEN (unsigned int)(0x3FC0) #define GEM_MTU_MIN_SIZE ETH_MIN_MTU -#define MACB_NETIF_LSO NETIF_F_TSO +#define MACB_NETIF_LSO (NETIF_F_TSO | NETIF_F_TSO6) #define MACB_WOL_HAS_MAGIC_PACKET (0x1 << 0) #define MACB_WOL_ENABLED (0x1 << 1) -- Gitee From c8b398302ebc2a95d7604465d6bcf6c75c34f92a Mon Sep 17 00:00:00 2001 From: Li Wencheng Date: Mon, 12 May 2025 13:51:22 +0800 Subject: [PATCH 25/27] net/macb: Slove the compile error in X86 architecture In the x86 architecture, if the CONFIG_OF configuration is not enabled,it will cause the compilation to fail. So we adjust the position of "#if defined (CONFIG_OF)". Mainline: Open-Source Signed-off-by: Li Wencheng Signed-off-by: Wang Yinfeng Change-Id: I658f0ad7da242e22249471529205f659d4738766 --- devices/cadence/macb_main-6.6-ethercat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devices/cadence/macb_main-6.6-ethercat.c b/devices/cadence/macb_main-6.6-ethercat.c index 44c320b..7e280d9 100644 --- a/devices/cadence/macb_main-6.6-ethercat.c +++ b/devices/cadence/macb_main-6.6-ethercat.c @@ -5038,7 +5038,6 @@ static const struct macb_usrio_config macb_default_usrio = { .refclk = MACB_BIT(CLKEN), }; -#if defined(CONFIG_OF) /* 1518 rounded up */ #define AT91ETHER_MAX_RBUFF_SZ 0x600 /* max number of receive buffers */ @@ -5755,6 +5754,7 @@ static const struct macb_config phytium_gem2p0_config = { .usrio = &macb_default_usrio, }; +#if defined(CONFIG_OF) static const struct of_device_id macb_dt_ids[] = { { .compatible = "cdns,at91sam9260-macb", .data = &at91sam9260_config }, { .compatible = "cdns,macb" }, -- Gitee From 9a18bf401e8f6ed47a2f108271dcacca2e8fcb62 Mon Sep 17 00:00:00 2001 From: zuoqian Date: Mon, 29 Sep 2025 14:06:46 +0800 Subject: [PATCH 26/27] net: macb: fix fixed-link link down ethtool status Signed-off-by: zuoqian --- devices/cadence/macb_main-6.6-ethercat.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/devices/cadence/macb_main-6.6-ethercat.c b/devices/cadence/macb_main-6.6-ethercat.c index 7e280d9..728a6d7 100644 --- a/devices/cadence/macb_main-6.6-ethercat.c +++ b/devices/cadence/macb_main-6.6-ethercat.c @@ -994,6 +994,9 @@ static void macb_mac_link_up(struct phylink_config *config, macb_set_tx_clk(bp, speed); + bp->speed = speed; + bp->duplex = duplex; + /* Initialize rings & buffers as clearing MACB_BIT(TE) in link down * cleared the pipeline and control registers. */ @@ -4000,8 +4003,13 @@ static int macb_get_link_ksettings(struct net_device *netdev, supported); ethtool_convert_legacy_u32_to_link_mode(kset->link_modes.advertising, advertising); - kset->base.speed = bp->speed; - kset->base.duplex = bp->duplex; + if (netif_carrier_ok(netdev)) { + kset->base.speed = bp->speed; + kset->base.duplex = bp->duplex; + } else { + kset->base.speed = SPEED_UNKNOWN; + kset->base.duplex = DUPLEX_UNKNOWN; + } } else { phylink_ethtool_ksettings_get(bp->phylink, kset); } -- Gitee From 4abaaf533729b95d0272fe1d26ba56691e9f90b6 Mon Sep 17 00:00:00 2001 From: zuoqian Date: Fri, 17 Oct 2025 17:17:42 +0800 Subject: [PATCH 27/27] net: macb: support ipv6 TSO Signed-off-by: zuoqian --- devices/cadence/macb_main-6.6-ethercat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devices/cadence/macb_main-6.6-ethercat.c b/devices/cadence/macb_main-6.6-ethercat.c index 728a6d7..7129ee0 100644 --- a/devices/cadence/macb_main-6.6-ethercat.c +++ b/devices/cadence/macb_main-6.6-ethercat.c @@ -88,7 +88,7 @@ struct sifive_fu540_macb_mgmt { #define GEM_MAX_TX_LEN (unsigned int)(0x3FC0) #define GEM_MTU_MIN_SIZE ETH_MIN_MTU -#define MACB_NETIF_LSO NETIF_F_TSO +#define MACB_NETIF_LSO (NETIF_F_TSO | NETIF_F_TSO6) #define MACB_WOL_HAS_MAGIC_PACKET (0x1 << 0) #define MACB_WOL_ENABLED (0x1 << 1) -- Gitee