Skip to contentSkip to conversation

Macb/gem network driver does not build anymore on recent xenomai/kernels

PATCH In review François Legal 2 participants 4 messages Jun 29, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Macb/gem network driver does not build anymore on recent xenomai/kernels

Subject: [PATCH] Make macb/gem RT driver to be built against linux >= 5.0 kernels

PHY layer in upstream has changed a little after 5.0 in the way autonegociation capabilities are encoded. MACB platform data tend to disappear after 5.2 upstream.
Plus, ioctl prototype has changed in xenomai. RTMACB driver does not build anymore.

---
 kernel/drivers/net/drivers/macb.c    | 50 +++++++++++++++++++++-------
 kernel/drivers/net/drivers/rt_macb.h |  2 +-
 2 files changed, 39 insertions(+), 13 deletions(-)
kernel/drivers/net/drivers/macb.c +38 -12
index 77957d906..2f3b43601 100644
@@ -132,6 +132,7 @@ void rtmacb_get_hwaddr(struct macb *bp)
 		bottom = macb_or_gem_readl(bp, SA1B + i * 8);
 		top = macb_or_gem_readl(bp, SA1T + i * 8);
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 2, 0)
 		if (pdata && pdata->rev_eth_addr) {
 			addr[5] = bottom & 0xff;
 			addr[4] = (bottom >> 8) & 0xff;
@@ -139,7 +140,9 @@ void rtmacb_get_hwaddr(struct macb *bp)
 			addr[2] = (bottom >> 24) & 0xff;
 			addr[1] = top & 0xff;
 			addr[0] = (top & 0xff00) >> 8;
-		} else {
+		} else
+#endif
+		{
 			addr[0] = bottom & 0xff;
 			addr[1] = (bottom >> 8) & 0xff;
 			addr[2] = (bottom >> 16) & 0xff;
@@ -311,10 +314,14 @@ static int macb_mii_probe(struct rtnet_device *dev)
 {
 	struct macb *bp = rtnetdev_priv(dev);
 	struct macb_dummy_netdev_priv *p;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 2, 0)
 	struct macb_platform_data *pdata;
+	int phy_irq;
+#endif
 	struct phy_device *phydev;
 	struct net_device *dummy;
-	int phy_irq;
+    struct ethtool_link_ksettings bitmap;
+    struct ethtool_link_ksettings bitmap_phy;
 	int ret;
 
 	phydev = phy_find_first(bp->mii_bus);
@@ -323,6 +330,7 @@ static int macb_mii_probe(struct rtnet_device *dev)
 		return -ENXIO;
 	}
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 2, 0)
 	pdata = dev_get_platdata(&bp->pdev->dev);
 	if (pdata && gpio_is_valid(pdata->phy_irq_pin)) {
 		ret = devm_gpio_request(&bp->pdev->dev, pdata->phy_irq_pin, "phy int");
@@ -331,6 +339,7 @@ static int macb_mii_probe(struct rtnet_device *dev)
 			phydev->irq = (phy_irq < 0) ? PHY_POLL : phy_irq;
 		}
 	}
+#endif
 
 	dummy = alloc_etherdev(sizeof(*p));
 	p = netdev_priv(dummy);
@@ -346,12 +355,19 @@ static int macb_mii_probe(struct rtnet_device *dev)
 	}
 
 	/* mask with MAC supported features */
-	if (macb_is_gem(bp))
-		phydev->supported &= PHY_GBIT_FEATURES;
-	else
-		phydev->supported &= PHY_BASIC_FEATURES;
+	if (macb_is_gem(bp)) {
+        ethtool_convert_legacy_u32_to_link_mode(bitmap.link_modes.supported, *PHY_GBIT_FEATURES);
+        memcpy (bitmap_phy.link_modes.supported, phydev->supported, sizeof (bitmap_phy.link_modes.supported));
+        ethtool_intersect_link_masks(& bitmap_phy, & bitmap);
+        memcpy (phydev->supported, bitmap_phy.link_modes.supported, sizeof (phydev->supported));
+	} else {
+        ethtool_convert_legacy_u32_to_link_mode(bitmap.link_modes.supported, *PHY_BASIC_FEATURES);
+        memcpy (bitmap_phy.link_modes.supported, phydev->supported, sizeof (bitmap_phy.link_modes.supported));
+        ethtool_intersect_link_masks(& bitmap_phy, & bitmap);
+        memcpy (phydev->supported, bitmap_phy.link_modes.supported, sizeof (phydev->supported));
+	}
 
-	phydev->advertising = phydev->supported;
+	memcpy (phydev->advertising, phydev->supported, sizeof (phydev->supported));
 
 	bp->link = 0;
 	bp->speed = 0;
@@ -385,11 +401,13 @@ int rtmacb_mii_init(struct macb *bp)
 	bp->mii_bus->parent = &bp->pdev->dev;
 	pdata = dev_get_platdata(&bp->pdev->dev);
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)
 	bp->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
 	if (!bp->mii_bus->irq) {
 		err = -ENOMEM;
 		goto err_out_free_mdiobus;
 	}
+#endif
 
 	np = bp->pdev->dev.of_node;
 	if (np) {
@@ -434,8 +452,10 @@ int rtmacb_mii_init(struct macb *bp)
 err_out_unregister_bus:
 	mdiobus_unregister(bp->mii_bus);
 err_out_free_mdio_irq:
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)
 	kfree(bp->mii_bus->irq);
 err_out_free_mdiobus:
+#endif
 	mdiobus_free(bp->mii_bus);
 err_out:
 	return err;
@@ -1532,7 +1552,7 @@ struct net_device_stats *rtmacb_get_stats(struct rtnet_device *dev)
 }
 EXPORT_SYMBOL_GPL(rtmacb_get_stats);
 
-int rtmacb_ioctl(struct rtnet_device *dev, unsigned cmd, void *rq)
+int rtmacb_ioctl(struct rtnet_device *dev, struct ifreq *rq, int cmd)
 {
 	struct macb *bp = rtnetdev_priv(dev);
 	struct phy_device *phydev = bp->phy_dev;
@@ -1551,7 +1571,7 @@ EXPORT_SYMBOL_GPL(rtmacb_ioctl);
 static const struct of_device_id macb_dt_ids[] = {
 	{ .compatible = "cdns,at32ap7000-macb" },
 	{ .compatible = "cdns,at91sam9260-macb" },
-	{ .compatible = "cdns,macb" },
+	{ .compatible = "cdns,macb_rt" },
 	{ .compatible = "cdns,pc302-gem" },
 	{ .compatible = "cdns,gem" },
 	{ .compatible = "atmel,sama5d3-gem" },
@@ -1562,7 +1582,9 @@ MODULE_DEVICE_TABLE(of, macb_dt_ids);
 
 static int __init macb_probe(struct platform_device *pdev)
 {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 2, 0)
 	struct macb_platform_data *pdata;
+#endif
 	struct resource *regs;
 	struct rtnet_device *dev;
 	struct macb *bp;
@@ -1695,12 +1717,13 @@ static int __init macb_probe(struct platform_device *pdev)
 	if (err)
 #else
 	mac = of_get_mac_address(pdev->dev.of_node);
-	if (mac)
+	if (! IS_ERR_OR_NULL(mac))
 		memcpy(bp->dev->dev_addr, mac, ETH_ALEN);
 	else
 #endif
 		rtmacb_get_hwaddr(bp);
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 2, 0)
 	err = of_get_phy_mode(pdev->dev.of_node);
 	if (err < 0) {
 		pdata = dev_get_platdata(&pdev->dev);
@@ -1711,6 +1734,7 @@ static int __init macb_probe(struct platform_device *pdev)
 	} else {
 		bp->phy_interface = err;
 	}
+#endif
 
 	if (bp->phy_interface == PHY_INTERFACE_MODE_RGMII)
 		macb_or_gem_writel(bp, USRIO, GEM_BIT(RGMII));
@@ -1748,7 +1772,7 @@ static int __init macb_probe(struct platform_device *pdev)
 
 	phydev = bp->phy_dev;
 	rtdev_info(dev, "attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
-		    phydev->drv->name, dev_name(&phydev->dev), phydev->irq);
+		    phydev->drv->name, dev_name(&phydev->mdio.dev), phydev->irq);
 
 	return 0;
 
@@ -1783,7 +1807,9 @@ static int __exit macb_remove(struct platform_device *pdev)
 		mdiobus_unregister(bp->mii_bus);
 		if (bp->phy_phony_net_device)
 			free_netdev(bp->phy_phony_net_device);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)
 		kfree(bp->mii_bus->irq);
+#endif
 		rt_rtdev_disconnect(dev);
 		rtdm_irq_free(&bp->irq_handle);
 		mdiobus_free(bp->mii_bus);
@@ -1801,7 +1827,7 @@ static int __exit macb_remove(struct platform_device *pdev)
 static struct platform_driver macb_driver = {
 	.remove		= __exit_p(macb_remove),
 	.driver		= {
-		.name		= "macb",
+		.name		= "rtmacb",
 		.owner	= THIS_MODULE,
 		.of_match_table	= of_match_ptr(macb_dt_ids),
 	},
kernel/drivers/net/drivers/rt_macb.h +1 -1
index 53b9607ae..a16985941 100644
@@ -611,7 +611,7 @@ struct macb {
 extern const struct ethtool_ops macb_ethtool_ops;
 
 int rtmacb_mii_init(struct macb *bp);
-int rtmacb_ioctl(struct rtnet_device *dev, unsigned cmd, void *arg);
+int rtmacb_ioctl(struct rtnet_device *dev, struct ifreq *rq, int cmd);
 struct net_device_stats *rtmacb_get_stats(struct rtnet_device *dev);
 void rtmacb_set_hwaddr(struct macb *bp);
 void rtmacb_get_hwaddr(struct macb *bp);

--
2.20.1

#1 lore raw

Hi,

Quoted 1 line · François Legal

Subject: [PATCH] Make macb/gem RT driver to be built against linux >= 5.0 kernels

^^ this line can be removed. We have the mail subject, that's sufficient.

In addition, could you please run checkpatch on your patch? There are a lot of warnings that should be addressed (especially regarding line endings, code style, ...)

Looking forward to a v2.

Best regards,
Florian

Quoted 7 lines

PHY layer in upstream has changed a little after 5.0 in the way autonegociation capabilities are encoded. MACB platform data tend to disappear after 5.2 upstream.
Plus, ioctl prototype has changed in xenomai. RTMACB driver does not build anymore.

---

#2 lore raw
Quoted 12 lines · Florian Bezdeka

Hi,

Quoted 1 line · François Legal

Subject: [PATCH] Make macb/gem RT driver to be built against linux >= 5.0 kernels

^^ this line can be removed. We have the mail subject, that's sufficient.

In addition, could you please run checkpatch on your patch? There are a lot of warnings that should be addressed (especially regarding line endings, code style, ...)

Yes, sorry, it's been a while since I last posted a patch here.
Can I assume warnings like
WARNING: LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged #193: FILE: kernel/drivers/net/drivers/macb.c:1810:
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)

WARNING: Comparisons should place the constant on the right side of the test #193: FILE: kernel/drivers/net/drivers/macb.c:1810:
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)

from checkpatch can be ignored (I copied existing code from the file to conditionnalise some code)

?

Otherwise, v2 is ready.

François

Quoted 13 lines

Looking forward to a v2.

Best regards,
Florian

Quoted 7 lines

PHY layer in upstream has changed a little after 5.0 in the way autonegociation capabilities are encoded. MACB platform data tend to disappear after 5.2 upstream.
Plus, ioctl prototype has changed in xenomai. RTMACB driver does not build anymore.

---

#3 lore raw
Quoted 21 lines · François Legal
Quoted 12 lines · Florian Bezdeka

Hi,

Quoted 1 line · François Legal

Subject: [PATCH] Make macb/gem RT driver to be built against linux >= 5.0 kernels

^^ this line can be removed. We have the mail subject, that's sufficient.

In addition, could you please run checkpatch on your patch? There are a lot of warnings that should be addressed (especially regarding line endings, code style, ...)

Yes, sorry, it's been a while since I last posted a patch here.
Can I assume warnings like
WARNING: LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged #193: FILE: kernel/drivers/net/drivers/macb.c:1810:
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)

Quoted 3 lines

WARNING: Comparisons should place the constant on the right side of the test #193: FILE: kernel/drivers/net/drivers/macb.c:1810:
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)

4.5.0 dates back to the ipipe. master/next branch of Xenomai already removed ipipe support and went ahead with dovetail (Linux >= 5.10) only. We don't care about such old kernels anymore.

You should be able to remove this #if machinery here and only provide the "new code".

Quoted 22 lines

from checkpatch can be ignored (I copied existing code from the file to conditionnalise some code)

?

Otherwise, v2 is ready.

François

Quoted 13 lines

Looking forward to a v2.

Best regards,
Florian

Quoted 7 lines

PHY layer in upstream has changed a little after 5.0 in the way autonegociation capabilities are encoded. MACB platform data tend to disappear after 5.2 upstream.
Plus, ioctl prototype has changed in xenomai. RTMACB driver does not build anymore.

---