Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'net-macb-eyeq5-support'

says:

====================
net: macb: EyeQ5 support

This series' goal is adding support to the MACB driver for EyeQ5 GEM.
The specifics for this compatible are:

- HW cannot add dummy bytes at the start of IP packets for alignment
purposes. The behavior can be detected using DCFG6 so it isn't
attached to compatible data.

- The hardware LSO/TSO is known to be buggy: add a compatible
capability flag to force disable it.

- At init, we have to wiggle two syscon registers that configure the
PHY integration.

In past attempts [0] we did it in macb_config->init() using a syscon
regmap. That was far from ideal so now a generic PHY driver
abstracts that away. We reuse the bp->sgmii_phy field used by some
compatibles.

We have to add a phy_set_mode() call as the PHY power on sequence
depends on whether we do RGMII or SGMII.

[0]: https://lore.kernel.org/lkml/20250627-macb-v2-15-ff8207d0bb77@bootlin.com/

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
---
Changes in v3:
- Drop Fixes: trailer on [2/5]. We don't fix any platform using the
driver currently.
- Improve [5/5] commit message; add info about how an unconditional
phy_set_mode_ext() won't break existing platforms.
- Hardbreak 82 characters line in [2/5]; warning by patchwork.
- Trailers:
- 1x Acked-by: Conor Dooley on [1/5].
- 2x Reviewed-by: Andrew Lunn on [1/5] and [4/5].
- 2x Reviewed-by: Maxime Chevallier on [4/5] and [5/5].
- Link to v2: https://lore.kernel.org/r/20251022-macb-eyeq5-v2-0-7c140abb0581@bootlin.com

Changes in v2:
- Drop non net-next patches.
- Re-run get_maintainers.pl to shorten the To/Cc list.
- Rebase upon latest net-next; no changes. Tested on HW.
- Link to v1: https://lore.kernel.org/r/20251021-macb-eyeq5-v1-0-3b0b5a9d2f85@bootlin.com

Past versions of the MACB EyeQ5 patches:
- March 2025: [PATCH net-next 00/13] Support the Cadence MACB/GEM
instances on Mobileye EyeQ5 SoCs
https://lore.kernel.org/lkml/20250321-macb-v1-0-537b7e37971d@bootlin.com/
- June 2025: [PATCH net-next v2 00/18] Support the Cadence MACB/GEM
instances on Mobileye EyeQ5 SoCs
https://lore.kernel.org/lkml/20250627-macb-v2-0-ff8207d0bb77@bootlin.com/
- August 2025: [PATCH net v3 00/16] net: macb: various fixes & cleanup
https://lore.kernel.org/lkml/20250808-macb-fixes-v3-0-08f1fcb5179f@bootlin.com/

---
Théo Lebrun (5):
dt-bindings: net: cdns,macb: add Mobileye EyeQ5 ethernet interface
net: macb: match skb_reserve(skb, NET_IP_ALIGN) with HW alignment
net: macb: add no LSO capability (MACB_CAPS_NO_LSO)
net: macb: rename bp->sgmii_phy field to bp->phy
net: macb: Add "mobileye,eyeq5-gem" compatible

.../devicetree/bindings/net/cdns,macb.yaml | 10 +++
drivers/net/ethernet/cadence/macb.h | 6 +-
drivers/net/ethernet/cadence/macb_main.c | 94 +++++++++++++++++-----
3 files changed, 91 insertions(+), 19 deletions(-)
---
base-commit: 61b7ade9ba8c3b16867e25411b5f7cf1abe35879
change-id: 20251020-macb-eyeq5-fe2c0d1edc75

Best regards,
====================

Link: https://patch.msgid.link/20251023-macb-eyeq5-v3-0-af509422c204@bootlin.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

+91 -19
+10
Documentation/devicetree/bindings/net/cdns,macb.yaml
··· 57 57 - cdns,np4-macb # NP4 SoC devices 58 58 - microchip,sama7g5-emac # Microchip SAMA7G5 ethernet interface 59 59 - microchip,sama7g5-gem # Microchip SAMA7G5 gigabit ethernet interface 60 + - mobileye,eyeq5-gem # Mobileye EyeQ5 SoCs 60 61 - raspberrypi,rp1-gem # Raspberry Pi RP1 gigabit ethernet interface 61 62 - sifive,fu540-c000-gem # SiFive FU540-C000 SoC 62 63 ··· 183 182 properties: 184 183 reg: 185 184 maxItems: 1 185 + 186 + - if: 187 + properties: 188 + compatible: 189 + contains: 190 + const: mobileye,eyeq5-gem 191 + then: 192 + required: 193 + - phys 186 194 187 195 unevaluatedProperties: false 188 196
+5 -1
drivers/net/ethernet/cadence/macb.h
··· 537 537 /* Bitfields in DCFG6. */ 538 538 #define GEM_PBUF_LSO_OFFSET 27 539 539 #define GEM_PBUF_LSO_SIZE 1 540 + #define GEM_PBUF_RSC_OFFSET 26 541 + #define GEM_PBUF_RSC_SIZE 1 540 542 #define GEM_PBUF_CUTTHRU_OFFSET 25 541 543 #define GEM_PBUF_CUTTHRU_SIZE 1 542 544 #define GEM_DAW64_OFFSET 23 ··· 777 775 #define MACB_CAPS_MACB_IS_GEM BIT(20) 778 776 #define MACB_CAPS_DMA_64B BIT(21) 779 777 #define MACB_CAPS_DMA_PTP BIT(22) 778 + #define MACB_CAPS_RSC BIT(23) 779 + #define MACB_CAPS_NO_LSO BIT(24) 780 780 781 781 /* LSO settings */ 782 782 #define MACB_LSO_UFO_ENABLE 0x01 ··· 1341 1337 1342 1338 struct macb_ptp_info *ptp_info; /* macb-ptp interface */ 1343 1339 1344 - struct phy *sgmii_phy; /* for ZynqMP SGMII mode */ 1340 + struct phy *phy; 1345 1341 1346 1342 spinlock_t tsu_clk_lock; /* gem tsu clock locking */ 1347 1343 unsigned int tsu_rate;
+76 -18
drivers/net/ethernet/cadence/macb_main.c
··· 1300 1300 dma_wmb(); 1301 1301 macb_set_addr(bp, desc, paddr); 1302 1302 1303 - /* properly align Ethernet header */ 1304 - skb_reserve(skb, NET_IP_ALIGN); 1303 + /* Properly align Ethernet header. 1304 + * 1305 + * Hardware can add dummy bytes if asked using the RBOF 1306 + * field inside the NCFGR register. That feature isn't 1307 + * available if hardware is RSC capable. 1308 + * 1309 + * We cannot fallback to doing the 2-byte shift before 1310 + * DMA mapping because the address field does not allow 1311 + * setting the low 2/3 bits. 1312 + * It is 3 bits if HW_DMA_CAP_PTP, else 2 bits. 1313 + */ 1314 + if (!(bp->caps & MACB_CAPS_RSC)) 1315 + skb_reserve(skb, NET_IP_ALIGN); 1305 1316 } else { 1306 1317 desc->ctrl = 0; 1307 1318 dma_wmb(); ··· 2784 2773 macb_set_hwaddr(bp); 2785 2774 2786 2775 config = macb_mdc_clk_div(bp); 2787 - config |= MACB_BF(RBOF, NET_IP_ALIGN); /* Make eth data aligned */ 2776 + /* Make eth data aligned. 2777 + * If RSC capable, that offset is ignored by HW. 2778 + */ 2779 + if (!(bp->caps & MACB_CAPS_RSC)) 2780 + config |= MACB_BF(RBOF, NET_IP_ALIGN); 2788 2781 config |= MACB_BIT(DRFCS); /* Discard Rx FCS */ 2789 2782 if (bp->caps & MACB_CAPS_JUMBO) 2790 2783 config |= MACB_BIT(JFRAME); /* Enable jumbo frames */ ··· 2965 2950 2966 2951 macb_init_hw(bp); 2967 2952 2968 - err = phy_power_on(bp->sgmii_phy); 2953 + err = phy_set_mode_ext(bp->phy, PHY_MODE_ETHERNET, bp->phy_interface); 2954 + if (err) 2955 + goto reset_hw; 2956 + 2957 + err = phy_power_on(bp->phy); 2969 2958 if (err) 2970 2959 goto reset_hw; 2971 2960 ··· 2985 2966 return 0; 2986 2967 2987 2968 phy_off: 2988 - phy_power_off(bp->sgmii_phy); 2969 + phy_power_off(bp->phy); 2989 2970 2990 2971 reset_hw: 2991 2972 macb_reset_hw(bp); ··· 3017 2998 phylink_stop(bp->phylink); 3018 2999 phylink_disconnect_phy(bp->phylink); 3019 3000 3020 - phy_power_off(bp->sgmii_phy); 3001 + phy_power_off(bp->phy); 3021 3002 3022 3003 spin_lock_irqsave(&bp->lock, flags); 3023 3004 macb_reset_hw(bp); ··· 4340 4321 dcfg = gem_readl(bp, DCFG2); 4341 4322 if ((dcfg & (GEM_BIT(RX_PKT_BUFF) | GEM_BIT(TX_PKT_BUFF))) == 0) 4342 4323 bp->caps |= MACB_CAPS_FIFO_MODE; 4324 + if (GEM_BFEXT(PBUF_RSC, gem_readl(bp, DCFG6))) 4325 + bp->caps |= MACB_CAPS_RSC; 4343 4326 if (gem_has_ptp(bp)) { 4344 4327 if (!GEM_BFEXT(TSU, gem_readl(bp, DCFG5))) 4345 4328 dev_err(&bp->pdev->dev, ··· 4568 4547 /* Set features */ 4569 4548 dev->hw_features = NETIF_F_SG; 4570 4549 4571 - /* Check LSO capability */ 4572 - if (GEM_BFEXT(PBUF_LSO, gem_readl(bp, DCFG6))) 4550 + /* Check LSO capability; runtime detection can be overridden by a cap 4551 + * flag if the hardware is known to be buggy 4552 + */ 4553 + if (!(bp->caps & MACB_CAPS_NO_LSO) && 4554 + GEM_BFEXT(PBUF_LSO, gem_readl(bp, DCFG6))) 4573 4555 dev->hw_features |= MACB_NETIF_LSO; 4574 4556 4575 4557 /* Checksum offload is only available on gem with packet buffer */ ··· 5145 5121 5146 5122 if (bp->phy_interface == PHY_INTERFACE_MODE_SGMII) { 5147 5123 /* Ensure PHY device used in SGMII mode is ready */ 5148 - bp->sgmii_phy = devm_phy_optional_get(&pdev->dev, NULL); 5124 + bp->phy = devm_phy_optional_get(&pdev->dev, NULL); 5149 5125 5150 - if (IS_ERR(bp->sgmii_phy)) 5151 - return dev_err_probe(&pdev->dev, PTR_ERR(bp->sgmii_phy), 5126 + if (IS_ERR(bp->phy)) 5127 + return dev_err_probe(&pdev->dev, PTR_ERR(bp->phy), 5152 5128 "failed to get SGMII PHY\n"); 5153 5129 5154 - ret = phy_init(bp->sgmii_phy); 5130 + ret = phy_init(bp->phy); 5155 5131 if (ret) 5156 5132 return dev_err_probe(&pdev->dev, ret, 5157 5133 "failed to init SGMII PHY\n"); ··· 5180 5156 /* Fully reset controller at hardware level if mapped in device tree */ 5181 5157 ret = device_reset_optional(&pdev->dev); 5182 5158 if (ret) { 5183 - phy_exit(bp->sgmii_phy); 5159 + phy_exit(bp->phy); 5184 5160 return dev_err_probe(&pdev->dev, ret, "failed to reset controller"); 5185 5161 } 5186 5162 ··· 5188 5164 5189 5165 err_out_phy_exit: 5190 5166 if (ret) 5191 - phy_exit(bp->sgmii_phy); 5167 + phy_exit(bp->phy); 5192 5168 5169 + return ret; 5170 + } 5171 + 5172 + static int eyeq5_init(struct platform_device *pdev) 5173 + { 5174 + struct net_device *netdev = platform_get_drvdata(pdev); 5175 + struct macb *bp = netdev_priv(netdev); 5176 + struct device *dev = &pdev->dev; 5177 + int ret; 5178 + 5179 + bp->phy = devm_phy_get(dev, NULL); 5180 + if (IS_ERR(bp->phy)) 5181 + return dev_err_probe(dev, PTR_ERR(bp->phy), 5182 + "failed to get PHY\n"); 5183 + 5184 + ret = phy_init(bp->phy); 5185 + if (ret) 5186 + return dev_err_probe(dev, ret, "failed to init PHY\n"); 5187 + 5188 + ret = macb_init(pdev); 5189 + if (ret) 5190 + phy_exit(bp->phy); 5193 5191 return ret; 5194 5192 } 5195 5193 ··· 5369 5323 .usrio = &macb_default_usrio, 5370 5324 }; 5371 5325 5326 + static const struct macb_config eyeq5_config = { 5327 + .caps = MACB_CAPS_GIGABIT_MODE_AVAILABLE | MACB_CAPS_JUMBO | 5328 + MACB_CAPS_GEM_HAS_PTP | MACB_CAPS_QUEUE_DISABLE | 5329 + MACB_CAPS_NO_LSO, 5330 + .dma_burst_length = 16, 5331 + .clk_init = macb_clk_init, 5332 + .init = eyeq5_init, 5333 + .jumbo_max_len = 10240, 5334 + .usrio = &macb_default_usrio, 5335 + }; 5336 + 5372 5337 static const struct macb_config raspberrypi_rp1_config = { 5373 5338 .caps = MACB_CAPS_GIGABIT_MODE_AVAILABLE | MACB_CAPS_CLK_HW_CHG | 5374 5339 MACB_CAPS_JUMBO | ··· 5411 5354 { .compatible = "microchip,mpfs-macb", .data = &mpfs_config }, 5412 5355 { .compatible = "microchip,sama7g5-gem", .data = &sama7g5_gem_config }, 5413 5356 { .compatible = "microchip,sama7g5-emac", .data = &sama7g5_emac_config }, 5357 + { .compatible = "mobileye,eyeq5-gem", .data = &eyeq5_config }, 5414 5358 { .compatible = "raspberrypi,rp1-gem", .data = &raspberrypi_rp1_config }, 5415 5359 { .compatible = "xlnx,zynqmp-gem", .data = &zynqmp_config}, 5416 5360 { .compatible = "xlnx,zynq-gem", .data = &zynq_config }, ··· 5632 5574 mdiobus_free(bp->mii_bus); 5633 5575 5634 5576 err_out_phy_exit: 5635 - phy_exit(bp->sgmii_phy); 5577 + phy_exit(bp->phy); 5636 5578 5637 5579 err_out_free_netdev: 5638 5580 free_netdev(dev); ··· 5656 5598 if (dev) { 5657 5599 bp = netdev_priv(dev); 5658 5600 unregister_netdev(dev); 5659 - phy_exit(bp->sgmii_phy); 5601 + phy_exit(bp->phy); 5660 5602 mdiobus_unregister(bp->mii_bus); 5661 5603 mdiobus_free(bp->mii_bus); 5662 5604 ··· 5683 5625 u32 tmp; 5684 5626 5685 5627 if (!device_may_wakeup(&bp->dev->dev)) 5686 - phy_exit(bp->sgmii_phy); 5628 + phy_exit(bp->phy); 5687 5629 5688 5630 if (!netif_running(netdev)) 5689 5631 return 0; ··· 5812 5754 int err; 5813 5755 5814 5756 if (!device_may_wakeup(&bp->dev->dev)) 5815 - phy_init(bp->sgmii_phy); 5757 + phy_init(bp->phy); 5816 5758 5817 5759 if (!netif_running(netdev)) 5818 5760 return 0;