blob: 93c00b802b9eb4d51b7ea5e7798d1bf666bcb1d3 [file] [log] [blame]
developer599cda42022-05-24 15:13:31 +08001diff --git a/include/linux/mdio.h b/include/linux/mdio.h
2index 0f1f784de..006d1c1e9 100644
3--- a/include/linux/mdio.h
4+++ b/include/linux/mdio.h
5@@ -7,8 +7,17 @@
6 #define __LINUX_MDIO_H__
7
8 #include <uapi/linux/mdio.h>
9+#include <linux/bitfield.h>
10 #include <linux/mod_devicetable.h>
11
12+/* Or MII_ADDR_C45 into regnum for read/write on mii_bus to enable the 21 bit
13+ * IEEE 802.3ae clause 45 addressing mode used by 10GIGE phy chips.
14+ */
15+#define MII_ADDR_C45 (1<<30)
16+#define MII_DEVADDR_C45_SHIFT 16
17+#define MII_DEVADDR_C45_MASK GENMASK(20, 16)
18+#define MII_REGADDR_C45_MASK GENMASK(15, 0)
19+
20 struct gpio_desc;
21 struct mii_bus;
22
23@@ -325,6 +334,46 @@ int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum);
24 int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);
25 int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val);
26
27+static inline u32 mdiobus_c45_addr(int devad, u16 regnum)
28+{
29+ return MII_ADDR_C45 | devad << MII_DEVADDR_C45_SHIFT | regnum;
30+}
31+
32+static inline u16 mdiobus_c45_regad(u32 regnum)
33+{
34+ return FIELD_GET(MII_REGADDR_C45_MASK, regnum);
35+}
36+
37+static inline u16 mdiobus_c45_devad(u32 regnum)
38+{
39+ return FIELD_GET(MII_DEVADDR_C45_MASK, regnum);
40+}
41+
42+static inline int __mdiobus_c45_read(struct mii_bus *bus, int prtad, int devad,
43+ u16 regnum)
44+{
45+ return __mdiobus_read(bus, prtad, mdiobus_c45_addr(devad, regnum));
46+}
47+
48+static inline int __mdiobus_c45_write(struct mii_bus *bus, int prtad, int devad,
49+ u16 regnum, u16 val)
50+{
51+ return __mdiobus_write(bus, prtad, mdiobus_c45_addr(devad, regnum),
52+ val);
53+}
54+
55+static inline int mdiobus_c45_read(struct mii_bus *bus, int prtad, int devad,
56+ u16 regnum)
57+{
58+ return mdiobus_read(bus, prtad, mdiobus_c45_addr(devad, regnum));
59+}
60+
61+static inline int mdiobus_c45_write(struct mii_bus *bus, int prtad, int devad,
62+ u16 regnum, u16 val)
63+{
64+ return mdiobus_write(bus, prtad, mdiobus_c45_addr(devad, regnum), val);
65+}
66+
67 int mdiobus_register_device(struct mdio_device *mdiodev);
68 int mdiobus_unregister_device(struct mdio_device *mdiodev);
69 bool mdiobus_is_registered_device(struct mii_bus *bus, int addr);
70--
712.18.0
72