Skip to content

Commit

Permalink
mdio-netlink: Restore compatibility with kernels older than 5.8
Browse files Browse the repository at this point in the history
The fixed commit added support for kernels newer than 5.7, but broke
support for older kernels. This change backports the C45 wrappers
needed to make those versions viable again.

Fixes: 6cfdfd0
  • Loading branch information
wkz committed Jul 15, 2023
1 parent 8ca980a commit 0dbfca1
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions kernel/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@

#include <linux/version.h>

#if LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0)
#include <linux/device.h>
#include <linux/phy.h>

static inline u32 mdiobus_c45_addr(int devad, u16 regnum)
{
return MII_ADDR_C45 | devad << MII_DEVADDR_C45_SHIFT | regnum;
}

static inline int __mdiobus_c45_read(struct mii_bus *bus, int prtad, int devad,
u16 regnum)
{
return __mdiobus_read(bus, prtad, mdiobus_c45_addr(devad, regnum));
}

static inline int __mdiobus_c45_write(struct mii_bus *bus, int prtad, int devad,
u16 regnum, u16 val)
{
return __mdiobus_write(bus, prtad, mdiobus_c45_addr(devad, regnum),
val);
}

#endif /* < 5.8.0 */

#if LINUX_VERSION_CODE < KERNEL_VERSION(5,7,0)
#include <linux/device.h>
#include <linux/phy.h>
Expand All @@ -21,7 +45,7 @@ static inline int _mdio_find_bus_match(struct device *dev, const void *data)
{
return dev->parent && device_match_name(dev->parent, data);
}
#endif
#endif /* < 5.4.0 */

/**
* mdio_find_bus - Given the name of a mdiobus, find the mii_bus.
Expand All @@ -46,6 +70,6 @@ static inline struct mii_bus *mdio_find_bus(const char *mdio_name)
put_device(d);
return p ? to_mii_bus(p) : NULL;
}
#endif
#endif /* < 5.7.0 */

#endif /* _COMPAT_H_ */

0 comments on commit 0dbfca1

Please sign in to comment.