diff mbox series

[net-next,1/2] net: phy: add helpers for handling C45 10GBT AN register values

Message ID 5c217a09-dac8-d8db-3a38-c9a621ae55a6@gmail.com
State Superseded
Delegated to: David Miller
Headers show
Series net: phy: add helpers for handling C45 10GBT AN register values | expand

Commit Message

Heiner Kallweit Feb. 15, 2019, 8:57 p.m. UTC
Similar to the existing helpers for the Clause 22 registers add helpers
to deal with converting Clause 45 advertisement registers to / from
link mode bitmaps.

Note that these helpers are defined in linux/mdio.h, not like the
Clause 22 helpers in linux/mii.h. Reason is that the Clause 45 register
constants are defined in uapi/linux/mdio.h. And uapi/linux/mdio.h
includes linux/mii.h before defining the C45 register constants.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 include/linux/mdio.h | 63 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

Comments

Andrew Lunn Feb. 16, 2019, 4 p.m. UTC | #1
On Fri, Feb 15, 2019 at 09:57:49PM +0100, Heiner Kallweit wrote:
> Similar to the existing helpers for the Clause 22 registers add helpers
> to deal with converting Clause 45 advertisement registers to / from
> link mode bitmaps.
> 
> Note that these helpers are defined in linux/mdio.h, not like the
> Clause 22 helpers in linux/mii.h. Reason is that the Clause 45 register
> constants are defined in uapi/linux/mdio.h. And uapi/linux/mdio.h
> includes linux/mii.h before defining the C45 register constants.

Hi Heiner

You add three helpers, but the followup patch only uses one of them.
Maybe you should wait until you have real uses of the other two?
Or just add the one helper.

      Andrew
Heiner Kallweit Feb. 16, 2019, 4:07 p.m. UTC | #2
On 16.02.2019 17:00, Andrew Lunn wrote:
> On Fri, Feb 15, 2019 at 09:57:49PM +0100, Heiner Kallweit wrote:
>> Similar to the existing helpers for the Clause 22 registers add helpers
>> to deal with converting Clause 45 advertisement registers to / from
>> link mode bitmaps.
>>
>> Note that these helpers are defined in linux/mdio.h, not like the
>> Clause 22 helpers in linux/mii.h. Reason is that the Clause 45 register
>> constants are defined in uapi/linux/mdio.h. And uapi/linux/mdio.h
>> includes linux/mii.h before defining the C45 register constants.
> 
> Hi Heiner
> 
> You add three helpers, but the followup patch only uses one of them.
> Maybe you should wait until you have real uses of the other two?
> Or just add the one helper.
> 
Ah, right. I created all helpers but at least one user isn't ready yet.
I'll resend the series with just the helper being used now.

>       Andrew
> 
Heiner
diff mbox series

Patch

diff --git a/include/linux/mdio.h b/include/linux/mdio.h
index bfa711416..ce0d5ddbf 100644
--- a/include/linux/mdio.h
+++ b/include/linux/mdio.h
@@ -261,6 +261,69 @@  static inline u16 ethtool_adv_to_mmd_eee_adv_t(u32 adv)
 	return reg;
 }
 
+/**
+ * linkmode_adv_to_mii_10gbt_adv_t
+ * @advertising: the linkmode advertisement settings
+ *
+ * A small helper function that translates linkmode advertisement
+ * settings to phy autonegotiation advertisements for the C45
+ * 10GBASE-T AN CONTROL (7.32) register.
+ */
+static inline u32 linkmode_adv_to_mii_10gbt_adv_t(unsigned long *advertising)
+{
+	u32 result = 0;
+
+	if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
+			      advertising))
+		result |= MDIO_AN_10GBT_CTRL_ADV2_5G;
+	if (linkmode_test_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
+			      advertising))
+		result |= MDIO_AN_10GBT_CTRL_ADV5G;
+	if (linkmode_test_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
+			      advertising))
+		result |= MDIO_AN_10GBT_CTRL_ADV10G;
+
+	return result;
+}
+
+/**
+ * mii_10gbt_stat_mod_linkmode_lpa_t
+ * @advertising: target the linkmode advertisement settings
+ * @adv: value of the C45 10GBASE-T AN STATUS register
+ *
+ * A small helper function that translates C45 10GBASE-T AN STATUS register bits
+ * to linkmode advertisement settings. Other bits in advertising aren't changed.
+ */
+static inline void mii_10gbt_stat_mod_linkmode_lpa_t(unsigned long *advertising,
+						     u32 lpa)
+{
+	linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
+			 advertising, lpa & MDIO_AN_10GBT_STAT_LP2_5G);
+	linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
+			 advertising, lpa & MDIO_AN_10GBT_STAT_LP5G);
+	linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
+			 advertising, lpa & MDIO_AN_10GBT_STAT_LP10G);
+}
+
+/**
+ * mii_10gbt_adv_mod_linkmode_adv_t
+ * @advertising:pointer to destination link mode.
+ * @adv: value of the C45 10GBASE-T AN CONTROL register
+ *
+ * A small helper function that translates the C45 10GBASE-T AN CONTROL
+ * register to linkmode advertisement settings. Leaves other bits unchanged.
+ */
+static inline void mii_10gbt_adv_mod_linkmode_adv_t(unsigned long *advertising,
+						    u32 adv)
+{
+	linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
+			 advertising, adv & MDIO_AN_10GBT_CTRL_ADV2_5G);
+	linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
+			 advertising, adv & MDIO_AN_10GBT_CTRL_ADV5G);
+	linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
+			 advertising, adv & MDIO_AN_10GBT_CTRL_ADV10G);
+}
+
 int __mdiobus_read(struct mii_bus *bus, int addr, u32 regnum);
 int __mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val);