* [PATH RFC net-next 0/8] Continue towards using linkmode in phylib @ 2018-09-14 21:38 Andrew Lunn 2018-09-14 21:38 ` [PATH RFC net-next 1/8] net: phy: Move linkmode helpers to somewhere public Andrew Lunn ` (8 more replies) 0 siblings, 9 replies; 29+ messages in thread From: Andrew Lunn @ 2018-09-14 21:38 UTC (permalink / raw) To: netdev; +Cc: Florian Fainelli, Andrew Lunn These patches contain some further cleanup and helpers, and the first real patch towards using linkmode bitmaps in phylink. It is RFC because i don't like patch #7 and maybe somebody has a better idea how to do this. Ideally, we want to initialise a linux generic bitmap at compile time. Thanks Andrew Andrew Lunn (8): net: phy: Move linkmode helpers to somewhere public net: phy: Add phydev_warn() net: phy: Add helper to convert MII ADV register to a linkmode net: phy: Add helper for advertise to lcl value net: phy: Add limkmode equivalents to some of the MII ethtool helpers net: ethernet xgbe expand PHY_GBIT_FEAUTRES net: phy: Replace phy driver features u32 with link_mode bitmap net: phy: Add build warning if assumptions get broken drivers/net/dsa/mt7530.c | 6 +- drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c | 15 +- drivers/net/ethernet/freescale/fman/mac.c | 6 +- drivers/net/ethernet/freescale/gianfar.c | 7 +- .../hisilicon/hns3/hns3pf/hclge_main.c | 6 +- drivers/net/ethernet/marvell/pxa168_eth.c | 4 +- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 6 +- drivers/net/ethernet/socionext/sni_ave.c | 5 +- drivers/net/phy/aquantia.c | 12 +- drivers/net/phy/bcm63xx.c | 9 +- drivers/net/phy/marvell.c | 2 +- drivers/net/phy/marvell10g.c | 11 +- drivers/net/phy/microchip_t1.c | 2 +- drivers/net/phy/phy_device.c | 211 +++++++++++++++++- drivers/net/phy/phylink.c | 27 --- include/linux/linkmode.h | 67 ++++++ include/linux/mii.h | 101 +++++++++ include/linux/phy.h | 28 ++- 18 files changed, 421 insertions(+), 104 deletions(-) create mode 100644 include/linux/linkmode.h -- 2.19.0.rc1 ^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATH RFC net-next 1/8] net: phy: Move linkmode helpers to somewhere public 2018-09-14 21:38 [PATH RFC net-next 0/8] Continue towards using linkmode in phylib Andrew Lunn @ 2018-09-14 21:38 ` Andrew Lunn 2018-09-14 22:08 ` Florian Fainelli 2018-09-17 9:48 ` Maxime Chevallier 2018-09-14 21:38 ` [PATH RFC net-next 2/8] net: phy: Add phydev_warn() Andrew Lunn ` (7 subsequent siblings) 8 siblings, 2 replies; 29+ messages in thread From: Andrew Lunn @ 2018-09-14 21:38 UTC (permalink / raw) To: netdev; +Cc: Florian Fainelli, Andrew Lunn phylink has some useful helpers to working with linkmode bitmaps. Move them to there own header so other code can use them. Signed-off-by: Andrew Lunn <andrew@lunn.ch> --- drivers/net/phy/phylink.c | 27 ---------------- include/linux/linkmode.h | 67 +++++++++++++++++++++++++++++++++++++++ include/linux/mii.h | 1 + include/linux/phy.h | 1 + 4 files changed, 69 insertions(+), 27 deletions(-) create mode 100644 include/linux/linkmode.h diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 3ba5cf2a8a5f..95ab492089f2 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -68,33 +68,6 @@ struct phylink { struct sfp_bus *sfp_bus; }; -static inline void linkmode_zero(unsigned long *dst) -{ - bitmap_zero(dst, __ETHTOOL_LINK_MODE_MASK_NBITS); -} - -static inline void linkmode_copy(unsigned long *dst, const unsigned long *src) -{ - bitmap_copy(dst, src, __ETHTOOL_LINK_MODE_MASK_NBITS); -} - -static inline void linkmode_and(unsigned long *dst, const unsigned long *a, - const unsigned long *b) -{ - bitmap_and(dst, a, b, __ETHTOOL_LINK_MODE_MASK_NBITS); -} - -static inline void linkmode_or(unsigned long *dst, const unsigned long *a, - const unsigned long *b) -{ - bitmap_or(dst, a, b, __ETHTOOL_LINK_MODE_MASK_NBITS); -} - -static inline bool linkmode_empty(const unsigned long *src) -{ - return bitmap_empty(src, __ETHTOOL_LINK_MODE_MASK_NBITS); -} - /** * phylink_set_port_modes() - set the port type modes in the ethtool mask * @mask: ethtool link mode mask diff --git a/include/linux/linkmode.h b/include/linux/linkmode.h new file mode 100644 index 000000000000..014fb86c7114 --- /dev/null +++ b/include/linux/linkmode.h @@ -0,0 +1,67 @@ +#ifndef __LINKMODE_H +#define __LINKMODE_H + +#include <linux/bitmap.h> +#include <linux/ethtool.h> +#include <uapi/linux/ethtool.h> + +static inline void linkmode_zero(unsigned long *dst) +{ + bitmap_zero(dst, __ETHTOOL_LINK_MODE_MASK_NBITS); +} + +static inline void linkmode_copy(unsigned long *dst, const unsigned long *src) +{ + bitmap_copy(dst, src, __ETHTOOL_LINK_MODE_MASK_NBITS); +} + +static inline void linkmode_and(unsigned long *dst, const unsigned long *a, + const unsigned long *b) +{ + bitmap_and(dst, a, b, __ETHTOOL_LINK_MODE_MASK_NBITS); +} + +static inline void linkmode_or(unsigned long *dst, const unsigned long *a, + const unsigned long *b) +{ + bitmap_or(dst, a, b, __ETHTOOL_LINK_MODE_MASK_NBITS); +} + +static inline bool linkmode_empty(const unsigned long *src) +{ + return bitmap_empty(src, __ETHTOOL_LINK_MODE_MASK_NBITS); +} + +static inline int linkmode_andnot(unsigned long *dst, const unsigned long *src1, + const unsigned long *src2) +{ + return bitmap_andnot(dst, src1, src2, __ETHTOOL_LINK_MODE_MASK_NBITS); +} + +static inline void linkmode_set_bit(int nr, volatile unsigned long *addr) +{ + __set_bit(nr, addr); +} + +static inline void linkmode_clear_bit(int nr, volatile unsigned long *addr) +{ + __clear_bit(nr, addr); +} + +static inline void linkmode_change_bit(int nr, volatile unsigned long *addr) +{ + __change_bit(nr, addr); +} + +static inline int linkmode_test_bit(int nr, volatile unsigned long *addr) +{ + return test_bit(nr, addr); +} + +static inline int linkmode_equal(const unsigned long *src1, + const unsigned long *src2) +{ + return bitmap_equal(src1, src2, __ETHTOOL_LINK_MODE_MASK_NBITS); +} + +#endif /* __LINKMODE_H */ diff --git a/include/linux/mii.h b/include/linux/mii.h index 55000ee5c6ad..567047ef0309 100644 --- a/include/linux/mii.h +++ b/include/linux/mii.h @@ -10,6 +10,7 @@ #include <linux/if.h> +#include <linux/linkmode.h> #include <uapi/linux/mii.h> struct ethtool_cmd; diff --git a/include/linux/phy.h b/include/linux/phy.h index 192a1fa0c73b..d24cc46748e2 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -19,6 +19,7 @@ #include <linux/compiler.h> #include <linux/spinlock.h> #include <linux/ethtool.h> +#include <linux/linkmode.h> #include <linux/mdio.h> #include <linux/mii.h> #include <linux/module.h> -- 2.19.0.rc1 ^ permalink raw reply related [flat|nested] 29+ messages in thread
* Re: [PATH RFC net-next 1/8] net: phy: Move linkmode helpers to somewhere public 2018-09-14 21:38 ` [PATH RFC net-next 1/8] net: phy: Move linkmode helpers to somewhere public Andrew Lunn @ 2018-09-14 22:08 ` Florian Fainelli 2018-09-16 19:18 ` Andrew Lunn 2018-09-17 9:48 ` Maxime Chevallier 1 sibling, 1 reply; 29+ messages in thread From: Florian Fainelli @ 2018-09-14 22:08 UTC (permalink / raw) To: Andrew Lunn, netdev On 09/14/2018 02:38 PM, Andrew Lunn wrote: > phylink has some useful helpers to working with linkmode bitmaps. > Move them to there own header so other code can use them. Good idea, I wonder if we should create a more specific directory within include/linux/ that can host a variety of PHYLIB, PHYLINK and what not header files, but this could be solved later on. > > Signed-off-by: Andrew Lunn <andrew@lunn.ch> Acked-by: Florian Fainelli <f.fainelli@gmail.com> -- Florian ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATH RFC net-next 1/8] net: phy: Move linkmode helpers to somewhere public 2018-09-14 22:08 ` Florian Fainelli @ 2018-09-16 19:18 ` Andrew Lunn 0 siblings, 0 replies; 29+ messages in thread From: Andrew Lunn @ 2018-09-16 19:18 UTC (permalink / raw) To: Florian Fainelli; +Cc: netdev > Good idea, I wonder if we should create a more specific directory within > include/linux/ that can host a variety of PHYLIB, PHYLINK and what not > header files, but this could be solved later on. I'm leaving it for later. We would also need to figure out a name for this directory. phy is already used by the generic phy subsystem. So i guess we would have to use something like ethernet-phy. Andrew ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATH RFC net-next 1/8] net: phy: Move linkmode helpers to somewhere public 2018-09-14 21:38 ` [PATH RFC net-next 1/8] net: phy: Move linkmode helpers to somewhere public Andrew Lunn 2018-09-14 22:08 ` Florian Fainelli @ 2018-09-17 9:48 ` Maxime Chevallier 1 sibling, 0 replies; 29+ messages in thread From: Maxime Chevallier @ 2018-09-17 9:48 UTC (permalink / raw) To: Andrew Lunn; +Cc: netdev, Florian Fainelli On Fri, 14 Sep 2018 23:38:49 +0200 Andrew Lunn <andrew@lunn.ch> wrote: >phylink has some useful helpers to working with linkmode bitmaps. >Move them to there own header so other code can use them. > >Signed-off-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com> ^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATH RFC net-next 2/8] net: phy: Add phydev_warn() 2018-09-14 21:38 [PATH RFC net-next 0/8] Continue towards using linkmode in phylib Andrew Lunn 2018-09-14 21:38 ` [PATH RFC net-next 1/8] net: phy: Move linkmode helpers to somewhere public Andrew Lunn @ 2018-09-14 21:38 ` Andrew Lunn 2018-09-14 22:10 ` Florian Fainelli 2018-09-17 9:49 ` Maxime Chevallier 2018-09-14 21:38 ` [PATH RFC net-next 3/8] net: phy: Add helper to convert MII ADV register to a linkmode Andrew Lunn ` (6 subsequent siblings) 8 siblings, 2 replies; 29+ messages in thread From: Andrew Lunn @ 2018-09-14 21:38 UTC (permalink / raw) To: netdev; +Cc: Florian Fainelli, Andrew Lunn Not all new style LINK_MODE bits can be converted into old style SUPPORTED bits. We need to warn when such a conversion is attempted. Add a helper for this. Signed-off-by: Andrew Lunn <andrew@lunn.ch> --- include/linux/phy.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/phy.h b/include/linux/phy.h index d24cc46748e2..0ab9f89773fd 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -968,6 +968,9 @@ static inline void phy_device_reset(struct phy_device *phydev, int value) #define phydev_err(_phydev, format, args...) \ dev_err(&_phydev->mdio.dev, format, ##args) +#define phydev_warn(_phydev, format, args...) \ + dev_warn(&_phydev->mdio.dev, format, ##args) + #define phydev_dbg(_phydev, format, args...) \ dev_dbg(&_phydev->mdio.dev, format, ##args) -- 2.19.0.rc1 ^ permalink raw reply related [flat|nested] 29+ messages in thread
* Re: [PATH RFC net-next 2/8] net: phy: Add phydev_warn() 2018-09-14 21:38 ` [PATH RFC net-next 2/8] net: phy: Add phydev_warn() Andrew Lunn @ 2018-09-14 22:10 ` Florian Fainelli 2018-09-14 23:26 ` Andrew Lunn 2018-09-17 9:49 ` Maxime Chevallier 1 sibling, 1 reply; 29+ messages in thread From: Florian Fainelli @ 2018-09-14 22:10 UTC (permalink / raw) To: Andrew Lunn, netdev On 09/14/2018 02:38 PM, Andrew Lunn wrote: > Not all new style LINK_MODE bits can be converted into old style > SUPPORTED bits. We need to warn when such a conversion is attempted. > Add a helper for this. > > Signed-off-by: Andrew Lunn <andrew@lunn.ch> Acked-by: Florian Fainelli <f.fainelli@gmail.com> Do you mind converting drivers/net/phy/marvell10g.c to use it? I would also suggest adding phydev_info() while we are at it and do the two conversions to it that exist in drivers/net/phy/phy_device.c? Thanks! -- Florian ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATH RFC net-next 2/8] net: phy: Add phydev_warn() 2018-09-14 22:10 ` Florian Fainelli @ 2018-09-14 23:26 ` Andrew Lunn 0 siblings, 0 replies; 29+ messages in thread From: Andrew Lunn @ 2018-09-14 23:26 UTC (permalink / raw) To: Florian Fainelli; +Cc: netdev On Fri, Sep 14, 2018 at 03:10:36PM -0700, Florian Fainelli wrote: > On 09/14/2018 02:38 PM, Andrew Lunn wrote: > > Not all new style LINK_MODE bits can be converted into old style > > SUPPORTED bits. We need to warn when such a conversion is attempted. > > Add a helper for this. > > > > Signed-off-by: Andrew Lunn <andrew@lunn.ch> > > Acked-by: Florian Fainelli <f.fainelli@gmail.com> > > Do you mind converting drivers/net/phy/marvell10g.c to use it? I would > also suggest adding phydev_info() while we are at it and do the two > conversions to it that exist in drivers/net/phy/phy_device.c? Yes, we might as well have the full set. Andrew ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATH RFC net-next 2/8] net: phy: Add phydev_warn() 2018-09-14 21:38 ` [PATH RFC net-next 2/8] net: phy: Add phydev_warn() Andrew Lunn 2018-09-14 22:10 ` Florian Fainelli @ 2018-09-17 9:49 ` Maxime Chevallier 1 sibling, 0 replies; 29+ messages in thread From: Maxime Chevallier @ 2018-09-17 9:49 UTC (permalink / raw) To: Andrew Lunn; +Cc: netdev, Florian Fainelli On Fri, 14 Sep 2018 23:38:50 +0200 Andrew Lunn <andrew@lunn.ch> wrote: >Not all new style LINK_MODE bits can be converted into old style >SUPPORTED bits. We need to warn when such a conversion is attempted. >Add a helper for this. > >Signed-off-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com> ^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATH RFC net-next 3/8] net: phy: Add helper to convert MII ADV register to a linkmode 2018-09-14 21:38 [PATH RFC net-next 0/8] Continue towards using linkmode in phylib Andrew Lunn 2018-09-14 21:38 ` [PATH RFC net-next 1/8] net: phy: Move linkmode helpers to somewhere public Andrew Lunn 2018-09-14 21:38 ` [PATH RFC net-next 2/8] net: phy: Add phydev_warn() Andrew Lunn @ 2018-09-14 21:38 ` Andrew Lunn 2018-09-14 22:23 ` Florian Fainelli 2018-09-17 9:50 ` Maxime Chevallier 2018-09-14 21:38 ` [PATH RFC net-next 4/8] net: phy: Add helper for advertise to lcl value Andrew Lunn ` (5 subsequent siblings) 8 siblings, 2 replies; 29+ messages in thread From: Andrew Lunn @ 2018-09-14 21:38 UTC (permalink / raw) To: netdev; +Cc: Florian Fainelli, Andrew Lunn The phy_mii_ioctl can be used to write a value into the MII_ADVERTISE register in the PHY. Since this changes the state of the PHY, we need to make the same change to phydev->advertising. Add a helper which can convert the register value to a linkmode. Signed-off-by: Andrew Lunn <andrew@lunn.ch> --- include/linux/mii.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/include/linux/mii.h b/include/linux/mii.h index 567047ef0309..8c7da9473ad9 100644 --- a/include/linux/mii.h +++ b/include/linux/mii.h @@ -303,6 +303,37 @@ static inline u32 mii_lpa_to_ethtool_lpa_x(u32 lpa) return result | mii_adv_to_ethtool_adv_x(lpa); } +/** + * mii_adv_to_linkmode_adv_t + * @advertising:pointer to destination link mode. + * @adv: value of the MII_ADVERTISE register + * + * A small helper function that translates MII_ADVERTISE bits + * to linkmode advertisement settings. + */ +static inline void mii_adv_to_linkmode_adv_t(unsigned long *advertising, + u32 adv) +{ + linkmode_zero(advertising); + + if (adv & ADVERTISE_10HALF) + linkmode_set_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT, + advertising); + if (adv & ADVERTISE_10FULL) + linkmode_set_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT, + advertising); + if (adv & ADVERTISE_100HALF) + linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, + advertising); + if (adv & ADVERTISE_100FULL) + linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, + advertising); + if (adv & ADVERTISE_PAUSE_CAP) + linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, advertising); + if (adv & ADVERTISE_PAUSE_ASYM) + linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertising); +} + /** * mii_advertise_flowctrl - get flow control advertisement flags * @cap: Flow control capabilities (FLOW_CTRL_RX, FLOW_CTRL_TX or both) -- 2.19.0.rc1 ^ permalink raw reply related [flat|nested] 29+ messages in thread
* Re: [PATH RFC net-next 3/8] net: phy: Add helper to convert MII ADV register to a linkmode 2018-09-14 21:38 ` [PATH RFC net-next 3/8] net: phy: Add helper to convert MII ADV register to a linkmode Andrew Lunn @ 2018-09-14 22:23 ` Florian Fainelli 2018-09-14 23:23 ` Andrew Lunn 2018-09-17 9:50 ` Maxime Chevallier 1 sibling, 1 reply; 29+ messages in thread From: Florian Fainelli @ 2018-09-14 22:23 UTC (permalink / raw) To: Andrew Lunn, netdev On 09/14/2018 02:38 PM, Andrew Lunn wrote: > The phy_mii_ioctl can be used to write a value into the MII_ADVERTISE > register in the PHY. Since this changes the state of the PHY, we need > to make the same change to phydev->advertising. Add a helper which can > convert the register value to a linkmode. It would have been nice if we could eliminate the duplication between mii_adv_to_ethtool_adv_t() and mii_adv_to_linkmode_adv_t() but I don't really see how without changing the former function's signature. Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> > > Signed-off-by: Andrew Lunn <andrew@lunn.ch> > --- > include/linux/mii.h | 31 +++++++++++++++++++++++++++++++ > 1 file changed, 31 insertions(+) > > diff --git a/include/linux/mii.h b/include/linux/mii.h > index 567047ef0309..8c7da9473ad9 100644 > --- a/include/linux/mii.h > +++ b/include/linux/mii.h > @@ -303,6 +303,37 @@ static inline u32 mii_lpa_to_ethtool_lpa_x(u32 lpa) > return result | mii_adv_to_ethtool_adv_x(lpa); > } > > +/** > + * mii_adv_to_linkmode_adv_t > + * @advertising:pointer to destination link mode. > + * @adv: value of the MII_ADVERTISE register > + * > + * A small helper function that translates MII_ADVERTISE bits > + * to linkmode advertisement settings. > + */ > +static inline void mii_adv_to_linkmode_adv_t(unsigned long *advertising, > + u32 adv) > +{ > + linkmode_zero(advertising); > + > + if (adv & ADVERTISE_10HALF) > + linkmode_set_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT, > + advertising); > + if (adv & ADVERTISE_10FULL) > + linkmode_set_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT, > + advertising); > + if (adv & ADVERTISE_100HALF) > + linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, > + advertising); > + if (adv & ADVERTISE_100FULL) > + linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, > + advertising); > + if (adv & ADVERTISE_PAUSE_CAP) > + linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, advertising); > + if (adv & ADVERTISE_PAUSE_ASYM) > + linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertising); > +} > + > /** > * mii_advertise_flowctrl - get flow control advertisement flags > * @cap: Flow control capabilities (FLOW_CTRL_RX, FLOW_CTRL_TX or both) > -- Florian ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATH RFC net-next 3/8] net: phy: Add helper to convert MII ADV register to a linkmode 2018-09-14 22:23 ` Florian Fainelli @ 2018-09-14 23:23 ` Andrew Lunn 0 siblings, 0 replies; 29+ messages in thread From: Andrew Lunn @ 2018-09-14 23:23 UTC (permalink / raw) To: Florian Fainelli; +Cc: netdev On Fri, Sep 14, 2018 at 03:23:14PM -0700, Florian Fainelli wrote: > On 09/14/2018 02:38 PM, Andrew Lunn wrote: > > The phy_mii_ioctl can be used to write a value into the MII_ADVERTISE > > register in the PHY. Since this changes the state of the PHY, we need > > to make the same change to phydev->advertising. Add a helper which can > > convert the register value to a linkmode. > > It would have been nice if we could eliminate the duplication between > mii_adv_to_ethtool_adv_t() and mii_adv_to_linkmode_adv_t() but I don't > really see how without changing the former function's signature. Some of these functions are also used by non-phylib MAC drivers. So the ethtool version cannot be eliminated. And the UAPI for EEE still uses a u32 for which modes EEE is advertised :-( Andrew ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATH RFC net-next 3/8] net: phy: Add helper to convert MII ADV register to a linkmode 2018-09-14 21:38 ` [PATH RFC net-next 3/8] net: phy: Add helper to convert MII ADV register to a linkmode Andrew Lunn 2018-09-14 22:23 ` Florian Fainelli @ 2018-09-17 9:50 ` Maxime Chevallier 1 sibling, 0 replies; 29+ messages in thread From: Maxime Chevallier @ 2018-09-17 9:50 UTC (permalink / raw) To: Andrew Lunn; +Cc: netdev, Florian Fainelli On Fri, 14 Sep 2018 23:38:51 +0200 Andrew Lunn <andrew@lunn.ch> wrote: >The phy_mii_ioctl can be used to write a value into the MII_ADVERTISE >register in the PHY. Since this changes the state of the PHY, we need >to make the same change to phydev->advertising. Add a helper which can >convert the register value to a linkmode. > >Signed-off-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com> ^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATH RFC net-next 4/8] net: phy: Add helper for advertise to lcl value 2018-09-14 21:38 [PATH RFC net-next 0/8] Continue towards using linkmode in phylib Andrew Lunn ` (2 preceding siblings ...) 2018-09-14 21:38 ` [PATH RFC net-next 3/8] net: phy: Add helper to convert MII ADV register to a linkmode Andrew Lunn @ 2018-09-14 21:38 ` Andrew Lunn 2018-09-15 0:27 ` Florian Fainelli 2018-09-17 9:51 ` Maxime Chevallier 2018-09-14 21:38 ` [PATH RFC net-next 5/8] net: phy: Add limkmode equivalents to some of the MII ethtool helpers Andrew Lunn ` (4 subsequent siblings) 8 siblings, 2 replies; 29+ messages in thread From: Andrew Lunn @ 2018-09-14 21:38 UTC (permalink / raw) To: netdev; +Cc: Florian Fainelli, Andrew Lunn Add a helper to convert the local advertising to an LCL capabilities, which is then used to resolve pause flow control settings. Signed-off-by: Andrew Lunn <andrew@lunn.ch> --- drivers/net/dsa/mt7530.c | 6 +----- drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c | 5 +---- drivers/net/ethernet/freescale/fman/mac.c | 6 +----- drivers/net/ethernet/freescale/gianfar.c | 7 +------ .../hisilicon/hns3/hns3pf/hclge_main.c | 6 +----- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 6 +----- drivers/net/ethernet/socionext/sni_ave.c | 5 +---- include/linux/mii.h | 19 +++++++++++++++++++ 8 files changed, 26 insertions(+), 34 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 62e486652e62..a5de9bffe5be 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -658,11 +658,7 @@ static void mt7530_adjust_link(struct dsa_switch *ds, int port, if (phydev->asym_pause) rmt_adv |= LPA_PAUSE_ASYM; - if (phydev->advertising & ADVERTISED_Pause) - lcl_adv |= ADVERTISE_PAUSE_CAP; - if (phydev->advertising & ADVERTISED_Asym_Pause) - lcl_adv |= ADVERTISE_PAUSE_ASYM; - + lcl_adv = ethtool_adv_to_lcl_adv_t(phydev->advertising); flowctrl = mii_resolve_flowctrl_fdx(lcl_adv, rmt_adv); if (flowctrl & FLOW_CTRL_TX) diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c b/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c index 289129011b9f..a7e03e3ecc93 100644 --- a/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c +++ b/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c @@ -1495,10 +1495,7 @@ static void xgbe_phy_phydev_flowctrl(struct xgbe_prv_data *pdata) if (!phy_data->phydev) return; - if (phy_data->phydev->advertising & ADVERTISED_Pause) - lcl_adv |= ADVERTISE_PAUSE_CAP; - if (phy_data->phydev->advertising & ADVERTISED_Asym_Pause) - lcl_adv |= ADVERTISE_PAUSE_ASYM; + lcl_adv = ethtool_adv_to_lcl_adv_t(phy_data->phydev->advertising); if (phy_data->phydev->pause) { XGBE_SET_LP_ADV(lks, Pause); diff --git a/drivers/net/ethernet/freescale/fman/mac.c b/drivers/net/ethernet/freescale/fman/mac.c index a847b9c3b31a..d79e4e009d63 100644 --- a/drivers/net/ethernet/freescale/fman/mac.c +++ b/drivers/net/ethernet/freescale/fman/mac.c @@ -393,11 +393,7 @@ void fman_get_pause_cfg(struct mac_device *mac_dev, bool *rx_pause, */ /* get local capabilities */ - lcl_adv = 0; - if (phy_dev->advertising & ADVERTISED_Pause) - lcl_adv |= ADVERTISE_PAUSE_CAP; - if (phy_dev->advertising & ADVERTISED_Asym_Pause) - lcl_adv |= ADVERTISE_PAUSE_ASYM; + lcl_adv = ethtool_adv_to_lcl_adv_t(phy_dev->advertising); /* get link partner capabilities */ rmt_adv = 0; diff --git a/drivers/net/ethernet/freescale/gianfar.c b/drivers/net/ethernet/freescale/gianfar.c index 40a1a87cd338..a24b242bf752 100644 --- a/drivers/net/ethernet/freescale/gianfar.c +++ b/drivers/net/ethernet/freescale/gianfar.c @@ -3658,12 +3658,7 @@ static u32 gfar_get_flowctrl_cfg(struct gfar_private *priv) if (phydev->asym_pause) rmt_adv |= LPA_PAUSE_ASYM; - lcl_adv = 0; - if (phydev->advertising & ADVERTISED_Pause) - lcl_adv |= ADVERTISE_PAUSE_CAP; - if (phydev->advertising & ADVERTISED_Asym_Pause) - lcl_adv |= ADVERTISE_PAUSE_ASYM; - + lcl_adv = ethtool_adv_to_lcl_adv_t(phydev->advertising); flowctrl = mii_resolve_flowctrl_fdx(lcl_adv, rmt_adv); if (flowctrl & FLOW_CTRL_TX) val |= MACCFG1_TX_FLOW; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c index cf18608669f5..a8088ba2ac9c 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c @@ -5270,11 +5270,7 @@ int hclge_cfg_flowctrl(struct hclge_dev *hdev) if (!phydev->link || !phydev->autoneg) return 0; - if (phydev->advertising & ADVERTISED_Pause) - local_advertising = ADVERTISE_PAUSE_CAP; - - if (phydev->advertising & ADVERTISED_Asym_Pause) - local_advertising |= ADVERTISE_PAUSE_ASYM; + local_advertising = ethtool_adv_to_lcl_adv_t(phydev->advertising); if (phydev->pause) remote_advertising = LPA_PAUSE_CAP; diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c index cc1e9a96a43b..7dbfdac4067a 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c @@ -243,11 +243,7 @@ static void mtk_phy_link_adjust(struct net_device *dev) if (dev->phydev->asym_pause) rmt_adv |= LPA_PAUSE_ASYM; - if (dev->phydev->advertising & ADVERTISED_Pause) - lcl_adv |= ADVERTISE_PAUSE_CAP; - if (dev->phydev->advertising & ADVERTISED_Asym_Pause) - lcl_adv |= ADVERTISE_PAUSE_ASYM; - + lcl_adv = ethtool_adv_to_lcl_adv_t(dev->phydev->advertising); flowctrl = mii_resolve_flowctrl_fdx(lcl_adv, rmt_adv); if (flowctrl & FLOW_CTRL_TX) diff --git a/drivers/net/ethernet/socionext/sni_ave.c b/drivers/net/ethernet/socionext/sni_ave.c index 61e6abb966ac..6feecd4e23e9 100644 --- a/drivers/net/ethernet/socionext/sni_ave.c +++ b/drivers/net/ethernet/socionext/sni_ave.c @@ -1116,11 +1116,8 @@ static void ave_phy_adjust_link(struct net_device *ndev) rmt_adv |= LPA_PAUSE_CAP; if (phydev->asym_pause) rmt_adv |= LPA_PAUSE_ASYM; - if (phydev->advertising & ADVERTISED_Pause) - lcl_adv |= ADVERTISE_PAUSE_CAP; - if (phydev->advertising & ADVERTISED_Asym_Pause) - lcl_adv |= ADVERTISE_PAUSE_ASYM; + lcl_adv = ethtool_adv_to_lcl_adv_t(phydev->advertising); cap = mii_resolve_flowctrl_fdx(lcl_adv, rmt_adv); if (cap & FLOW_CTRL_TX) txcr |= AVE_TXCR_FLOCTR; diff --git a/include/linux/mii.h b/include/linux/mii.h index 8c7da9473ad9..9ed49c8261d0 100644 --- a/include/linux/mii.h +++ b/include/linux/mii.h @@ -334,6 +334,25 @@ static inline void mii_adv_to_linkmode_adv_t(unsigned long *advertising, linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertising); } +/** + * ethtool_adv_to_lcl_adv_t + * @advertising:pointer to ethtool advertising + * + * A small helper function that translates ethtool advertising to LVL + * pause capabilities. + */ +static inline u32 ethtool_adv_to_lcl_adv_t(u32 advertising) +{ + u32 lcl_adv = 0; + + if (advertising & ADVERTISED_Pause) + lcl_adv |= ADVERTISE_PAUSE_CAP; + if (advertising & ADVERTISED_Asym_Pause) + lcl_adv |= ADVERTISE_PAUSE_ASYM; + + return lcl_adv; +} + /** * mii_advertise_flowctrl - get flow control advertisement flags * @cap: Flow control capabilities (FLOW_CTRL_RX, FLOW_CTRL_TX or both) -- 2.19.0.rc1 ^ permalink raw reply related [flat|nested] 29+ messages in thread
* Re: [PATH RFC net-next 4/8] net: phy: Add helper for advertise to lcl value 2018-09-14 21:38 ` [PATH RFC net-next 4/8] net: phy: Add helper for advertise to lcl value Andrew Lunn @ 2018-09-15 0:27 ` Florian Fainelli 2018-09-17 9:51 ` Maxime Chevallier 1 sibling, 0 replies; 29+ messages in thread From: Florian Fainelli @ 2018-09-15 0:27 UTC (permalink / raw) To: Andrew Lunn, netdev On 09/14/2018 02:38 PM, Andrew Lunn wrote: > Add a helper to convert the local advertising to an LCL capabilities, > which is then used to resolve pause flow control settings. > > Signed-off-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> -- Florian ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATH RFC net-next 4/8] net: phy: Add helper for advertise to lcl value 2018-09-14 21:38 ` [PATH RFC net-next 4/8] net: phy: Add helper for advertise to lcl value Andrew Lunn 2018-09-15 0:27 ` Florian Fainelli @ 2018-09-17 9:51 ` Maxime Chevallier 1 sibling, 0 replies; 29+ messages in thread From: Maxime Chevallier @ 2018-09-17 9:51 UTC (permalink / raw) To: Andrew Lunn; +Cc: netdev, Florian Fainelli On Fri, 14 Sep 2018 23:38:52 +0200 Andrew Lunn <andrew@lunn.ch> wrote: >Add a helper to convert the local advertising to an LCL capabilities, >which is then used to resolve pause flow control settings. > >Signed-off-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com> ^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATH RFC net-next 5/8] net: phy: Add limkmode equivalents to some of the MII ethtool helpers 2018-09-14 21:38 [PATH RFC net-next 0/8] Continue towards using linkmode in phylib Andrew Lunn ` (3 preceding siblings ...) 2018-09-14 21:38 ` [PATH RFC net-next 4/8] net: phy: Add helper for advertise to lcl value Andrew Lunn @ 2018-09-14 21:38 ` Andrew Lunn 2018-09-15 0:28 ` Florian Fainelli 2018-09-17 9:53 ` Maxime Chevallier 2018-09-14 21:38 ` [PATH RFC net-next 6/8] net: ethernet xgbe expand PHY_GBIT_FEAUTRES Andrew Lunn ` (3 subsequent siblings) 8 siblings, 2 replies; 29+ messages in thread From: Andrew Lunn @ 2018-09-14 21:38 UTC (permalink / raw) To: netdev; +Cc: Florian Fainelli, Andrew Lunn Add helpers which take a linkmode rather than a u32 ethtool for advertising settings. Signed-off-by: Andrew Lunn <andrew@lunn.ch> --- include/linux/mii.h | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/include/linux/mii.h b/include/linux/mii.h index 9ed49c8261d0..2da85b02e1c0 100644 --- a/include/linux/mii.h +++ b/include/linux/mii.h @@ -132,6 +132,34 @@ static inline u32 ethtool_adv_to_mii_adv_t(u32 ethadv) return result; } +/** + * linkmode_adv_to_mii_adv_t + * @advertising: the linkmode advertisement settings + * + * A small helper function that translates linkmode advertisement + * settings to phy autonegotiation advertisements for the + * MII_ADVERTISE register. + */ +static inline u32 linkmode_adv_to_mii_adv_t(unsigned long *advertising) +{ + u32 result = 0; + + if (linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT, advertising)) + result |= ADVERTISE_10HALF; + if (linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT, advertising)) + result |= ADVERTISE_10FULL; + if (linkmode_test_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, advertising)) + result |= ADVERTISE_100HALF; + if (linkmode_test_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, advertising)) + result |= ADVERTISE_100FULL; + if (linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT, advertising)) + result |= ADVERTISE_PAUSE_CAP; + if (linkmode_test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, advertising)) + result |= ADVERTISE_PAUSE_ASYM; + + return result; +} + /** * mii_adv_to_ethtool_adv_t * @adv: value of the MII_ADVERTISE register @@ -179,6 +207,28 @@ static inline u32 ethtool_adv_to_mii_ctrl1000_t(u32 ethadv) return result; } +/** + * linkmode_adv_to_mii_ctrl1000_t + * advertising: the linkmode advertisement settings + * + * A small helper function that translates linkmode advertisement + * settings to phy autonegotiation advertisements for the + * MII_CTRL1000 register when in 1000T mode. + */ +static inline u32 linkmode_adv_to_mii_ctrl1000_t(unsigned long *advertising) +{ + u32 result = 0; + + if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, + advertising)) + result |= ADVERTISE_1000HALF; + if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, + advertising)) + result |= ADVERTISE_1000FULL; + + return result; +} + /** * mii_ctrl1000_to_ethtool_adv_t * @adv: value of the MII_CTRL1000 register -- 2.19.0.rc1 ^ permalink raw reply related [flat|nested] 29+ messages in thread
* Re: [PATH RFC net-next 5/8] net: phy: Add limkmode equivalents to some of the MII ethtool helpers 2018-09-14 21:38 ` [PATH RFC net-next 5/8] net: phy: Add limkmode equivalents to some of the MII ethtool helpers Andrew Lunn @ 2018-09-15 0:28 ` Florian Fainelli 2018-09-17 9:53 ` Maxime Chevallier 1 sibling, 0 replies; 29+ messages in thread From: Florian Fainelli @ 2018-09-15 0:28 UTC (permalink / raw) To: Andrew Lunn, netdev On 09/14/2018 02:38 PM, Andrew Lunn wrote: > Add helpers which take a linkmode rather than a u32 ethtool for > advertising settings. > > Signed-off-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> -- Florian ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATH RFC net-next 5/8] net: phy: Add limkmode equivalents to some of the MII ethtool helpers 2018-09-14 21:38 ` [PATH RFC net-next 5/8] net: phy: Add limkmode equivalents to some of the MII ethtool helpers Andrew Lunn 2018-09-15 0:28 ` Florian Fainelli @ 2018-09-17 9:53 ` Maxime Chevallier 1 sibling, 0 replies; 29+ messages in thread From: Maxime Chevallier @ 2018-09-17 9:53 UTC (permalink / raw) To: Andrew Lunn; +Cc: netdev, Florian Fainelli On Fri, 14 Sep 2018 23:38:53 +0200 Andrew Lunn <andrew@lunn.ch> wrote: >Add helpers which take a linkmode rather than a u32 ethtool for >advertising settings. > >Signed-off-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com> ^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATH RFC net-next 6/8] net: ethernet xgbe expand PHY_GBIT_FEAUTRES 2018-09-14 21:38 [PATH RFC net-next 0/8] Continue towards using linkmode in phylib Andrew Lunn ` (4 preceding siblings ...) 2018-09-14 21:38 ` [PATH RFC net-next 5/8] net: phy: Add limkmode equivalents to some of the MII ethtool helpers Andrew Lunn @ 2018-09-14 21:38 ` Andrew Lunn 2018-09-15 10:01 ` Sergei Shtylyov 2018-09-14 21:38 ` [PATH RFC net-next 7/8] net: phy: Replace phy driver features u32 with link_mode bitmap Andrew Lunn ` (2 subsequent siblings) 8 siblings, 1 reply; 29+ messages in thread From: Andrew Lunn @ 2018-09-14 21:38 UTC (permalink / raw) To: netdev; +Cc: Florian Fainelli, Andrew Lunn The macro PHY_GBIT_FEAUTRES needs to change into a bitmap in order to support link_modes. Remove its use from xgde by replacing it with its definition. Probably, the current behavior is wrong. It probably should be ANDing not assigning. Signed-off-by: Andrew Lunn <andrew@lunn.ch> --- drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c b/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c index a7e03e3ecc93..d49e76982453 100644 --- a/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c +++ b/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c @@ -878,8 +878,9 @@ static bool xgbe_phy_finisar_phy_quirks(struct xgbe_prv_data *pdata) phy_write(phy_data->phydev, 0x04, 0x0d01); phy_write(phy_data->phydev, 0x00, 0x9140); - phy_data->phydev->supported = PHY_GBIT_FEATURES; - phy_data->phydev->advertising = phy_data->phydev->supported; + phy_data->phydev->supported = (PHY_10BT_FEATURES | + PHY_100BT_FEATURES | + PHY_1000BT_FEATURES); phy_support_asym_pause(phy_data->phydev); netif_dbg(pdata, drv, pdata->netdev, @@ -950,8 +951,9 @@ static bool xgbe_phy_belfuse_phy_quirks(struct xgbe_prv_data *pdata) reg = phy_read(phy_data->phydev, 0x00); phy_write(phy_data->phydev, 0x00, reg & ~0x00800); - phy_data->phydev->supported = PHY_GBIT_FEATURES; - phy_data->phydev->advertising = phy_data->phydev->supported; + phy_data->phydev->supported = (PHY_10BT_FEATURES | + PHY_100BT_FEATURES | + PHY_1000BT_FEATURES); phy_support_asym_pause(phy_data->phydev); netif_dbg(pdata, drv, pdata->netdev, -- 2.19.0.rc1 ^ permalink raw reply related [flat|nested] 29+ messages in thread
* Re: [PATH RFC net-next 6/8] net: ethernet xgbe expand PHY_GBIT_FEAUTRES 2018-09-14 21:38 ` [PATH RFC net-next 6/8] net: ethernet xgbe expand PHY_GBIT_FEAUTRES Andrew Lunn @ 2018-09-15 10:01 ` Sergei Shtylyov 0 siblings, 0 replies; 29+ messages in thread From: Sergei Shtylyov @ 2018-09-15 10:01 UTC (permalink / raw) To: Andrew Lunn, netdev; +Cc: Florian Fainelli On 9/15/2018 12:38 AM, Andrew Lunn wrote: > The macro PHY_GBIT_FEAUTRES needs to change into a bitmap in order to > support link_modes. Remove its use from xgde by replacing it with its > definition. > > Probably, the current behavior is wrong. It probably should be > ANDing not assigning. > > Signed-off-by: Andrew Lunn <andrew@lunn.ch> > --- > drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c b/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c > index a7e03e3ecc93..d49e76982453 100644 > --- a/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c > +++ b/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c > @@ -878,8 +878,9 @@ static bool xgbe_phy_finisar_phy_quirks(struct xgbe_prv_data *pdata) > phy_write(phy_data->phydev, 0x04, 0x0d01); > phy_write(phy_data->phydev, 0x00, 0x9140); > > - phy_data->phydev->supported = PHY_GBIT_FEATURES; > - phy_data->phydev->advertising = phy_data->phydev->supported; > + phy_data->phydev->supported = (PHY_10BT_FEATURES | > + PHY_100BT_FEATURES | > + PHY_1000BT_FEATURES); Parens not necessary here. > phy_support_asym_pause(phy_data->phydev); > > netif_dbg(pdata, drv, pdata->netdev, > @@ -950,8 +951,9 @@ static bool xgbe_phy_belfuse_phy_quirks(struct xgbe_prv_data *pdata) > reg = phy_read(phy_data->phydev, 0x00); > phy_write(phy_data->phydev, 0x00, reg & ~0x00800); > > - phy_data->phydev->supported = PHY_GBIT_FEATURES; > - phy_data->phydev->advertising = phy_data->phydev->supported; > + phy_data->phydev->supported = (PHY_10BT_FEATURES | > + PHY_100BT_FEATURES | > + PHY_1000BT_FEATURES); Here as well. [...] MBR, Sergei ^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATH RFC net-next 7/8] net: phy: Replace phy driver features u32 with link_mode bitmap 2018-09-14 21:38 [PATH RFC net-next 0/8] Continue towards using linkmode in phylib Andrew Lunn ` (5 preceding siblings ...) 2018-09-14 21:38 ` [PATH RFC net-next 6/8] net: ethernet xgbe expand PHY_GBIT_FEAUTRES Andrew Lunn @ 2018-09-14 21:38 ` Andrew Lunn 2018-09-15 21:31 ` Florian Fainelli 2018-09-14 21:38 ` [PATH RFC net-next 8/8] net: phy: Add build warning if assumptions get broken Andrew Lunn 2018-09-17 10:01 ` [PATH RFC net-next 0/8] Continue towards using linkmode in phylib Maxime Chevallier 8 siblings, 1 reply; 29+ messages in thread From: Andrew Lunn @ 2018-09-14 21:38 UTC (permalink / raw) To: netdev; +Cc: Florian Fainelli, Andrew Lunn This is one step in allowing phylib to make use of link_mode bitmaps, instead of u32 for supported and advertised features. Convert the phy drivers to use bitmaps to indicates the features they support. This requires some macro magic in order to construct constant bitmaps used to initialise the driver structures. Some new PHY_*_FEATURES are added, to indicate FIBRE is supported, and that all media ports are supported. This is done since bitmaps cannot be ORed together at compile time. Within phylib, the features bitmap is currently turned back into a u32. The MAC API to phylib needs to be cleaned up before the core of phylib can be converted to using bitmaps instead of u32. Signed-off-by: Andrew Lunn <andrew@lunn.ch> --- drivers/net/ethernet/marvell/pxa168_eth.c | 4 +- drivers/net/phy/aquantia.c | 12 +- drivers/net/phy/bcm63xx.c | 9 +- drivers/net/phy/marvell.c | 2 +- drivers/net/phy/marvell10g.c | 11 +- drivers/net/phy/microchip_t1.c | 2 +- drivers/net/phy/phy_device.c | 204 +++++++++++++++++++++- include/linux/phy.h | 24 ++- 8 files changed, 229 insertions(+), 39 deletions(-) diff --git a/drivers/net/ethernet/marvell/pxa168_eth.c b/drivers/net/ethernet/marvell/pxa168_eth.c index 3a9730612a70..b406395bbb37 100644 --- a/drivers/net/ethernet/marvell/pxa168_eth.c +++ b/drivers/net/ethernet/marvell/pxa168_eth.c @@ -988,8 +988,8 @@ static int pxa168_init_phy(struct net_device *dev) cmd.base.phy_address = pep->phy_addr; cmd.base.speed = pep->phy_speed; cmd.base.duplex = pep->phy_duplex; - ethtool_convert_legacy_u32_to_link_mode(cmd.link_modes.advertising, - PHY_BASIC_FEATURES); + bitmap_copy(cmd.link_modes.advertising, PHY_BASIC_FEATURES, + __ETHTOOL_LINK_MODE_MASK_NBITS); cmd.base.autoneg = AUTONEG_ENABLE; if (cmd.base.speed != 0) diff --git a/drivers/net/phy/aquantia.c b/drivers/net/phy/aquantia.c index 319edc9c8ec7..632472cab3bb 100644 --- a/drivers/net/phy/aquantia.c +++ b/drivers/net/phy/aquantia.c @@ -115,7 +115,7 @@ static struct phy_driver aquantia_driver[] = { .phy_id = PHY_ID_AQ1202, .phy_id_mask = 0xfffffff0, .name = "Aquantia AQ1202", - .features = PHY_AQUANTIA_FEATURES, + .features = PHY_10GBIT_FULL_FEATURES, .flags = PHY_HAS_INTERRUPT, .aneg_done = genphy_c45_aneg_done, .config_aneg = aquantia_config_aneg, @@ -127,7 +127,7 @@ static struct phy_driver aquantia_driver[] = { .phy_id = PHY_ID_AQ2104, .phy_id_mask = 0xfffffff0, .name = "Aquantia AQ2104", - .features = PHY_AQUANTIA_FEATURES, + .features = PHY_10GBIT_FULL_FEATURES, .flags = PHY_HAS_INTERRUPT, .aneg_done = genphy_c45_aneg_done, .config_aneg = aquantia_config_aneg, @@ -139,7 +139,7 @@ static struct phy_driver aquantia_driver[] = { .phy_id = PHY_ID_AQR105, .phy_id_mask = 0xfffffff0, .name = "Aquantia AQR105", - .features = PHY_AQUANTIA_FEATURES, + .features = PHY_10GBIT_FULL_FEATURES, .flags = PHY_HAS_INTERRUPT, .aneg_done = genphy_c45_aneg_done, .config_aneg = aquantia_config_aneg, @@ -151,7 +151,7 @@ static struct phy_driver aquantia_driver[] = { .phy_id = PHY_ID_AQR106, .phy_id_mask = 0xfffffff0, .name = "Aquantia AQR106", - .features = PHY_AQUANTIA_FEATURES, + .features = PHY_10GBIT_FULL_FEATURES, .flags = PHY_HAS_INTERRUPT, .aneg_done = genphy_c45_aneg_done, .config_aneg = aquantia_config_aneg, @@ -163,7 +163,7 @@ static struct phy_driver aquantia_driver[] = { .phy_id = PHY_ID_AQR107, .phy_id_mask = 0xfffffff0, .name = "Aquantia AQR107", - .features = PHY_AQUANTIA_FEATURES, + .features = PHY_10GBIT_FULL_FEATURES, .flags = PHY_HAS_INTERRUPT, .aneg_done = genphy_c45_aneg_done, .config_aneg = aquantia_config_aneg, @@ -175,7 +175,7 @@ static struct phy_driver aquantia_driver[] = { .phy_id = PHY_ID_AQR405, .phy_id_mask = 0xfffffff0, .name = "Aquantia AQR405", - .features = PHY_AQUANTIA_FEATURES, + .features = PHY_10GBIT_FULL_FEATURES, .flags = PHY_HAS_INTERRUPT, .aneg_done = genphy_c45_aneg_done, .config_aneg = aquantia_config_aneg, diff --git a/drivers/net/phy/bcm63xx.c b/drivers/net/phy/bcm63xx.c index cf14613745c9..ff5acf01b877 100644 --- a/drivers/net/phy/bcm63xx.c +++ b/drivers/net/phy/bcm63xx.c @@ -42,6 +42,9 @@ static int bcm63xx_config_init(struct phy_device *phydev) { int reg, err; + /* ASYM_PAUSE bit is marked RO in datasheet, so don't cheat */ + linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->supported), + reg = phy_read(phydev, MII_BCM63XX_IR); if (reg < 0) return reg; @@ -65,8 +68,7 @@ static struct phy_driver bcm63xx_driver[] = { .phy_id = 0x00406000, .phy_id_mask = 0xfffffc00, .name = "Broadcom BCM63XX (1)", - /* ASYM_PAUSE bit is marked RO in datasheet, so don't cheat */ - .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), + .features = PHY_BASIC_FEATURES, .flags = PHY_HAS_INTERRUPT | PHY_IS_INTERNAL, .config_init = bcm63xx_config_init, .ack_interrupt = bcm_phy_ack_intr, @@ -75,8 +77,7 @@ static struct phy_driver bcm63xx_driver[] = { /* same phy as above, with just a different OUI */ .phy_id = 0x002bdc00, .phy_id_mask = 0xfffffc00, - .name = "Broadcom BCM63XX (2)", - .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause), + .features = PHY_BASIC_FEATURES, .flags = PHY_HAS_INTERRUPT | PHY_IS_INTERNAL, .config_init = bcm63xx_config_init, .ack_interrupt = bcm_phy_ack_intr, diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c index f7c69ca34056..de1e900f7253 100644 --- a/drivers/net/phy/marvell.c +++ b/drivers/net/phy/marvell.c @@ -2222,7 +2222,7 @@ static struct phy_driver marvell_drivers[] = { .phy_id = MARVELL_PHY_ID_88E1510, .phy_id_mask = MARVELL_PHY_ID_MASK, .name = "Marvell 88E1510", - .features = PHY_GBIT_FEATURES | SUPPORTED_FIBRE, + .features = PHY_GBIT_FIBRE_FEATURES, .flags = PHY_HAS_INTERRUPT, .probe = &m88e1510_probe, .config_init = &m88e1510_config_init, diff --git a/drivers/net/phy/marvell10g.c b/drivers/net/phy/marvell10g.c index f77a2d9e7f9d..7f4a43c65da6 100644 --- a/drivers/net/phy/marvell10g.c +++ b/drivers/net/phy/marvell10g.c @@ -535,16 +535,7 @@ static struct phy_driver mv3310_drivers[] = { .phy_id = 0x002b09aa, .phy_id_mask = MARVELL_PHY_ID_MASK, .name = "mv88x3310", - .features = SUPPORTED_10baseT_Full | - SUPPORTED_10baseT_Half | - SUPPORTED_100baseT_Full | - SUPPORTED_100baseT_Half | - SUPPORTED_1000baseT_Full | - SUPPORTED_Autoneg | - SUPPORTED_TP | - SUPPORTED_FIBRE | - SUPPORTED_10000baseT_Full | - SUPPORTED_Backplane, + .features = PHY_10GBIT_FEATURES, .soft_reset = gen10g_no_soft_reset, .config_init = mv3310_config_init, .probe = mv3310_probe, diff --git a/drivers/net/phy/microchip_t1.c b/drivers/net/phy/microchip_t1.c index b1917dd1978a..c600a8509d60 100644 --- a/drivers/net/phy/microchip_t1.c +++ b/drivers/net/phy/microchip_t1.c @@ -46,7 +46,7 @@ static struct phy_driver microchip_t1_phy_driver[] = { .phy_id_mask = 0xfffffff0, .name = "Microchip LAN87xx T1", - .features = SUPPORTED_100baseT_Full, + .features = PHY_BASIC_T1_FEATURES, .flags = PHY_HAS_INTERRUPT, .config_init = genphy_config_init, diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index af64a9320fb0..eed61ee1d394 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -29,6 +29,7 @@ #include <linux/module.h> #include <linux/mii.h> #include <linux/ethtool.h> +#include <linux/bitmap.h> #include <linux/phy.h> #include <linux/phy_led_triggers.h> #include <linux/mdio.h> @@ -42,6 +43,191 @@ MODULE_DESCRIPTION("PHY library"); MODULE_AUTHOR("Andy Fleming"); MODULE_LICENSE("GPL"); +#define BIT_IN_RANGE(bit, lower, upper) \ + ((bit) < (lower) ? 0 : ((bit) > (upper) ? 0 : \ + BIT((bit) - (lower)))) + +#define BIT_IN_LONG_ARRAY(bit, index) \ + BIT_IN_RANGE(bit, (BITS_PER_LONG * (index)), \ + (BITS_PER_LONG * ((index) + 1)) - 1) + +#define BIT_IN_LONG_ARRAY_0(bit) BIT_IN_LONG_ARRAY(bit, 0) +#define BIT_IN_LONG_ARRAY_1(bit) BIT_IN_LONG_ARRAY(bit, 1) +#define BIT_IN_LONG_ARRAY_2(bit) BIT_IN_LONG_ARRAY(bit, 2) + +const __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_basic_features) = { + [0] = (BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_Autoneg_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_TP_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_MII_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_10baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_10baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_100baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_100baseT_Full_BIT)), +#if BITS_PER_LONG == 32 + [1] = (BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_Autoneg_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_TP_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_MII_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_10baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_10baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_100baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_100baseT_Full_BIT)), +#endif +}; +EXPORT_SYMBOL_GPL(phy_basic_features); + +const __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_basic_t1_features) = { + [0] = (BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_TP_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_100baseT_Full_BIT)), +#if BITS_PER_LONG == 32 + [1] = (BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_TP_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_100baseT_Full_BIT)), +#endif +}; +EXPORT_SYMBOL_GPL(phy_basic_t1_features); + +const __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_gbit_features) = { + [0] = (BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_Autoneg_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_TP_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_MII_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_10baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_10baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_100baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_100baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_1000baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_1000baseT_Full_BIT)), +#if BITS_PER_LONG == 32 + [1] = (BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_Autoneg_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_TP_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_MII_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_10baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_10baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_100baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_100baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_1000baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_1000baseT_Full_BIT)), +#endif +}; +EXPORT_SYMBOL_GPL(phy_gbit_features); + +const __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_gbit_fibre_features) = { + [0] = (BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_Autoneg_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_TP_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_MII_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_FIBRE_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_10baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_10baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_100baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_100baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_1000baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_1000baseT_Full_BIT)), +#if BITS_PER_LONG == 32 + [1] = (BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_Autoneg_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_TP_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_MII_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_FIBRE_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_10baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_10baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_100baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_100baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_1000baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_1000baseT_Full_BIT)), +#endif +}; +EXPORT_SYMBOL_GPL(phy_gbit_fibre_features); + +const __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_gbit_all_ports_features) = { + [0] = (BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_Autoneg_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_TP_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_MII_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_FIBRE_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_AUI_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_BNC_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_Backplane_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_10baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_10baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_100baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_100baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_1000baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_1000baseT_Full_BIT)), +#if BITS_PER_LONG == 32 + [1] = (BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_Autoneg_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_TP_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_MII_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_FIBRE_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_AUI_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_BNC_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_Backplane_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_10baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_10baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_100baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_100baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_1000baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_1000baseT_Full_BIT)), +#endif +}; +EXPORT_SYMBOL_GPL(phy_gbit_all_ports_features); + +const __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_10gbit_features) = { + [0] = (BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_Autoneg_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_TP_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_MII_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_FIBRE_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_AUI_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_BNC_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_Backplane_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_10baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_10baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_100baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_100baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_1000baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_1000baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_10000baseT_Full_BIT)), +#if BITS_PER_LONG == 32 + [1] = (BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_Autoneg_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_TP_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_MII_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_FIBRE_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_Backplane_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_10baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_10baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_100baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_100baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_1000baseT_Half_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_1000baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_10000baseT_Full_BIT)), +#endif +}; +EXPORT_SYMBOL_GPL(phy_10gbit_features); + +/* No half duplex support */ +const __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_10gbit_full_features) = { + [0] = (BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_Autoneg_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_TP_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_MII_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_FIBRE_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_AUI_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_BNC_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_Backplane_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_10baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_100baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_1000baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_0(ETHTOOL_LINK_MODE_10000baseT_Full_BIT)), +#if BITS_PER_LONG == 32 + [1] = (BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_Autoneg_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_TP_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_MII_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_AUI_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_BNC_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_FIBRE_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_Backplane_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_10baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_100baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_1000baseT_Full_BIT) | + BIT_IN_LONG_ARRAY_1(ETHTOOL_LINK_MODE_10000baseT_Full_BIT)), +#endif +}; +EXPORT_SYMBOL_GPL(phy_10gbit_full_features); + void phy_device_free(struct phy_device *phydev) { put_device(&phydev->mdio.dev); @@ -1938,6 +2124,7 @@ static int phy_probe(struct device *dev) struct phy_device *phydev = to_phy_device(dev); struct device_driver *drv = phydev->mdio.dev.driver; struct phy_driver *phydrv = to_phy_driver(drv); + u32 features; int err = 0; phydev->drv = phydrv; @@ -1958,7 +2145,8 @@ static int phy_probe(struct device *dev) * a controller will attach, and may modify one * or both of these values */ - phydev->supported = phydrv->features; + ethtool_convert_link_mode_to_legacy_u32(&features, phydrv->features); + phydev->supported = features; of_set_phy_supported(phydev); phydev->advertising = phydev->supported; @@ -1978,10 +2166,14 @@ static int phy_probe(struct device *dev) * (e.g. hardware erratum) where the driver wants to set only one * of these bits. */ - if (phydrv->features & (SUPPORTED_Pause | SUPPORTED_Asym_Pause)) { + if (test_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydrv->features) || + test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydrv->features)) { phydev->supported &= ~(SUPPORTED_Pause | SUPPORTED_Asym_Pause); - phydev->supported |= phydrv->features & - (SUPPORTED_Pause | SUPPORTED_Asym_Pause); + if (test_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydrv->features)) + phydev->supported |= SUPPORTED_Pause; + if (test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, + phydrv->features)) + phydev->supported |= SUPPORTED_Asym_Pause; } else { phydev->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause; } @@ -2094,9 +2286,7 @@ static struct phy_driver genphy_driver = { .name = "Generic PHY", .soft_reset = genphy_no_soft_reset, .config_init = genphy_config_init, - .features = PHY_GBIT_FEATURES | SUPPORTED_MII | - SUPPORTED_AUI | SUPPORTED_FIBRE | - SUPPORTED_BNC, + .features = PHY_GBIT_ALL_PORTS_FEATURES, .aneg_done = genphy_aneg_done, .suspend = genphy_suspend, .resume = genphy_resume, diff --git a/include/linux/phy.h b/include/linux/phy.h index 0ab9f89773fd..8343a1999e1b 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -42,13 +42,21 @@ #define PHY_1000BT_FEATURES (SUPPORTED_1000baseT_Half | \ SUPPORTED_1000baseT_Full) -#define PHY_BASIC_FEATURES (PHY_10BT_FEATURES | \ - PHY_100BT_FEATURES | \ - PHY_DEFAULT_FEATURES) - -#define PHY_GBIT_FEATURES (PHY_BASIC_FEATURES | \ - PHY_1000BT_FEATURES) - +extern const __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_basic_features); +extern const __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_basic_t1_features); +extern const __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_gbit_features); +extern const __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_gbit_fibre_features); +extern const __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_gbit_all_ports_features); +extern const __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_10gbit_features); +extern const __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_10gbit_full_features); + +#define PHY_BASIC_FEATURES ((unsigned long *)&phy_basic_features) +#define PHY_BASIC_T1_FEATURES ((unsigned long *)&phy_basic_t1_features) +#define PHY_GBIT_FEATURES ((unsigned long *)&phy_gbit_features) +#define PHY_GBIT_FIBRE_FEATURES ((unsigned long *)&phy_gbit_fibre_features) +#define PHY_GBIT_ALL_PORTS_FEATURES ((unsigned long *)&phy_gbit_all_ports_features) +#define PHY_10GBIT_FEATURES ((unsigned long *)&phy_10gbit_features) +#define PHY_10GBIT_FULL_FEATURES ((unsigned long *)&phy_10gbit_full_features) /* * Set phydev->irq to PHY_POLL if interrupts are not supported, @@ -510,7 +518,7 @@ struct phy_driver { u32 phy_id; char *name; u32 phy_id_mask; - u32 features; + const unsigned long * const features; u32 flags; const void *driver_data; -- 2.19.0.rc1 ^ permalink raw reply related [flat|nested] 29+ messages in thread
* Re: [PATH RFC net-next 7/8] net: phy: Replace phy driver features u32 with link_mode bitmap 2018-09-14 21:38 ` [PATH RFC net-next 7/8] net: phy: Replace phy driver features u32 with link_mode bitmap Andrew Lunn @ 2018-09-15 21:31 ` Florian Fainelli 2018-09-15 22:30 ` Andrew Lunn 0 siblings, 1 reply; 29+ messages in thread From: Florian Fainelli @ 2018-09-15 21:31 UTC (permalink / raw) To: Andrew Lunn, netdev On 09/14/18 14:38, Andrew Lunn wrote: > This is one step in allowing phylib to make use of link_mode bitmaps, > instead of u32 for supported and advertised features. Convert the phy > drivers to use bitmaps to indicates the features they support. This > requires some macro magic in order to construct constant bitmaps used > to initialise the driver structures. > > Some new PHY_*_FEATURES are added, to indicate FIBRE is supported, and > that all media ports are supported. This is done since bitmaps cannot > be ORed together at compile time. > > Within phylib, the features bitmap is currently turned back into a > u32. The MAC API to phylib needs to be cleaned up before the core of > phylib can be converted to using bitmaps instead of u32. Nice! Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> -- Florian ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATH RFC net-next 7/8] net: phy: Replace phy driver features u32 with link_mode bitmap 2018-09-15 21:31 ` Florian Fainelli @ 2018-09-15 22:30 ` Andrew Lunn 2018-09-16 16:20 ` Florian Fainelli 0 siblings, 1 reply; 29+ messages in thread From: Andrew Lunn @ 2018-09-15 22:30 UTC (permalink / raw) To: Florian Fainelli; +Cc: netdev On Sat, Sep 15, 2018 at 02:31:14PM -0700, Florian Fainelli wrote: > > > On 09/14/18 14:38, Andrew Lunn wrote: > > This is one step in allowing phylib to make use of link_mode bitmaps, > > instead of u32 for supported and advertised features. Convert the phy > > drivers to use bitmaps to indicates the features they support. This > > requires some macro magic in order to construct constant bitmaps used > > to initialise the driver structures. > > > > Some new PHY_*_FEATURES are added, to indicate FIBRE is supported, and > > that all media ports are supported. This is done since bitmaps cannot > > be ORed together at compile time. > > > > Within phylib, the features bitmap is currently turned back into a > > u32. The MAC API to phylib needs to be cleaned up before the core of > > phylib can be converted to using bitmaps instead of u32. > > Nice! Hi Florian This is the patch i don't like. I'm hoping somebody can think of a better way to initialise a bitmap. Andrew ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATH RFC net-next 7/8] net: phy: Replace phy driver features u32 with link_mode bitmap 2018-09-15 22:30 ` Andrew Lunn @ 2018-09-16 16:20 ` Florian Fainelli 2018-09-16 17:59 ` Andrew Lunn 0 siblings, 1 reply; 29+ messages in thread From: Florian Fainelli @ 2018-09-16 16:20 UTC (permalink / raw) To: Andrew Lunn; +Cc: netdev Hi Andrew, On September 15, 2018 3:30:53 PM PDT, Andrew Lunn <andrew@lunn.ch> wrote: >On Sat, Sep 15, 2018 at 02:31:14PM -0700, Florian Fainelli wrote: >> >> >> On 09/14/18 14:38, Andrew Lunn wrote: >> > This is one step in allowing phylib to make use of link_mode >bitmaps, >> > instead of u32 for supported and advertised features. Convert the >phy >> > drivers to use bitmaps to indicates the features they support. This >> > requires some macro magic in order to construct constant bitmaps >used >> > to initialise the driver structures. >> > >> > Some new PHY_*_FEATURES are added, to indicate FIBRE is supported, >and >> > that all media ports are supported. This is done since bitmaps >cannot >> > be ORed together at compile time. >> > >> > Within phylib, the features bitmap is currently turned back into a >> > u32. The MAC API to phylib needs to be cleaned up before the core >of >> > phylib can be converted to using bitmaps instead of u32. >> >> Nice! > >Hi Florian > >This is the patch i don't like. I'm hoping somebody can think of a >better way to initialise a bitmap. By that you mean having to determine whether you overflow the capacity of an unsigned long storage type and having to put the bits in either unsigned long [0] or [1]? Being able to eliminate the duplication would also be nice, but I cannot think about a smart solution at compile time that would avoid doing that. -- Florian ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATH RFC net-next 7/8] net: phy: Replace phy driver features u32 with link_mode bitmap 2018-09-16 16:20 ` Florian Fainelli @ 2018-09-16 17:59 ` Andrew Lunn 0 siblings, 0 replies; 29+ messages in thread From: Andrew Lunn @ 2018-09-16 17:59 UTC (permalink / raw) To: Florian Fainelli; +Cc: netdev > By that you mean having to determine whether you overflow the > capacity of an unsigned long storage type and having to put the bits > in either unsigned long [0] or [1]? Being able to eliminate the > duplication would also be nice, but I cannot think about a smart > solution at compile time that would avoid doing that. Hi Florian I've given up on doing it at compile time. I'm working on a run-time solution at the moment, which i think looks better. I will probably split the patchset. Post for merging all but the last two patches, and then an RFC for replacing this patch. Andrew ^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATH RFC net-next 8/8] net: phy: Add build warning if assumptions get broken 2018-09-14 21:38 [PATH RFC net-next 0/8] Continue towards using linkmode in phylib Andrew Lunn ` (6 preceding siblings ...) 2018-09-14 21:38 ` [PATH RFC net-next 7/8] net: phy: Replace phy driver features u32 with link_mode bitmap Andrew Lunn @ 2018-09-14 21:38 ` Andrew Lunn 2018-09-15 21:31 ` Florian Fainelli 2018-09-17 10:01 ` [PATH RFC net-next 0/8] Continue towards using linkmode in phylib Maxime Chevallier 8 siblings, 1 reply; 29+ messages in thread From: Andrew Lunn @ 2018-09-14 21:38 UTC (permalink / raw) To: netdev; +Cc: Florian Fainelli, Andrew Lunn The macro magic to build constant bitmaps of supported PHY features breaks when we have more than 63 ETHTOOL_LINK_MODE bits. Make the breakage loud, not a subtle bug, when we get to that condition. Signed-off-by: Andrew Lunn <andrew@lunn.ch> --- drivers/net/phy/phy_device.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index eed61ee1d394..7bee59c7834b 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -2297,6 +2297,13 @@ static int __init phy_init(void) { int rc; + /* The phy_basic_features, phy_gbit_features etc, above, only + * work for values up to 63. Ensure we get a loud error if + * this threshold is exceeded, and the necessary changes are + * made. + */ + BUILD_BUG_ON(__ETHTOOL_LINK_MODE_LAST > 63); + rc = mdio_bus_init(); if (rc) return rc; -- 2.19.0.rc1 ^ permalink raw reply related [flat|nested] 29+ messages in thread
* Re: [PATH RFC net-next 8/8] net: phy: Add build warning if assumptions get broken 2018-09-14 21:38 ` [PATH RFC net-next 8/8] net: phy: Add build warning if assumptions get broken Andrew Lunn @ 2018-09-15 21:31 ` Florian Fainelli 0 siblings, 0 replies; 29+ messages in thread From: Florian Fainelli @ 2018-09-15 21:31 UTC (permalink / raw) To: Andrew Lunn, netdev On 09/14/18 14:38, Andrew Lunn wrote: > The macro magic to build constant bitmaps of supported PHY features > breaks when we have more than 63 ETHTOOL_LINK_MODE bits. Make the > breakage loud, not a subtle bug, when we get to that condition. > > Signed-off-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> -- Florian ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATH RFC net-next 0/8] Continue towards using linkmode in phylib 2018-09-14 21:38 [PATH RFC net-next 0/8] Continue towards using linkmode in phylib Andrew Lunn ` (7 preceding siblings ...) 2018-09-14 21:38 ` [PATH RFC net-next 8/8] net: phy: Add build warning if assumptions get broken Andrew Lunn @ 2018-09-17 10:01 ` Maxime Chevallier 8 siblings, 0 replies; 29+ messages in thread From: Maxime Chevallier @ 2018-09-17 10:01 UTC (permalink / raw) To: Andrew Lunn; +Cc: netdev, Florian Fainelli Hi Andrew, On Fri, 14 Sep 2018 23:38:48 +0200 Andrew Lunn <andrew@lunn.ch> wrote: >These patches contain some further cleanup and helpers, and the first >real patch towards using linkmode bitmaps in phylink. > >It is RFC because i don't like patch #7 and maybe somebody has a >better idea how to do this. Ideally, we want to initialise a linux >generic bitmap at compile time. Thanks for that series. I've reviewed what I feel confident enough to, I'll be happy to test the runtime "features" listing that I think you plan to implement. Maxime ^ permalink raw reply [flat|nested] 29+ messages in thread
end of thread, other threads:[~2018-09-17 15:28 UTC | newest] Thread overview: 29+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-09-14 21:38 [PATH RFC net-next 0/8] Continue towards using linkmode in phylib Andrew Lunn 2018-09-14 21:38 ` [PATH RFC net-next 1/8] net: phy: Move linkmode helpers to somewhere public Andrew Lunn 2018-09-14 22:08 ` Florian Fainelli 2018-09-16 19:18 ` Andrew Lunn 2018-09-17 9:48 ` Maxime Chevallier 2018-09-14 21:38 ` [PATH RFC net-next 2/8] net: phy: Add phydev_warn() Andrew Lunn 2018-09-14 22:10 ` Florian Fainelli 2018-09-14 23:26 ` Andrew Lunn 2018-09-17 9:49 ` Maxime Chevallier 2018-09-14 21:38 ` [PATH RFC net-next 3/8] net: phy: Add helper to convert MII ADV register to a linkmode Andrew Lunn 2018-09-14 22:23 ` Florian Fainelli 2018-09-14 23:23 ` Andrew Lunn 2018-09-17 9:50 ` Maxime Chevallier 2018-09-14 21:38 ` [PATH RFC net-next 4/8] net: phy: Add helper for advertise to lcl value Andrew Lunn 2018-09-15 0:27 ` Florian Fainelli 2018-09-17 9:51 ` Maxime Chevallier 2018-09-14 21:38 ` [PATH RFC net-next 5/8] net: phy: Add limkmode equivalents to some of the MII ethtool helpers Andrew Lunn 2018-09-15 0:28 ` Florian Fainelli 2018-09-17 9:53 ` Maxime Chevallier 2018-09-14 21:38 ` [PATH RFC net-next 6/8] net: ethernet xgbe expand PHY_GBIT_FEAUTRES Andrew Lunn 2018-09-15 10:01 ` Sergei Shtylyov 2018-09-14 21:38 ` [PATH RFC net-next 7/8] net: phy: Replace phy driver features u32 with link_mode bitmap Andrew Lunn 2018-09-15 21:31 ` Florian Fainelli 2018-09-15 22:30 ` Andrew Lunn 2018-09-16 16:20 ` Florian Fainelli 2018-09-16 17:59 ` Andrew Lunn 2018-09-14 21:38 ` [PATH RFC net-next 8/8] net: phy: Add build warning if assumptions get broken Andrew Lunn 2018-09-15 21:31 ` Florian Fainelli 2018-09-17 10:01 ` [PATH RFC net-next 0/8] Continue towards using linkmode in phylib Maxime Chevallier
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).