source of highlighter
plain | download
    1 From 988efaff712d78d1bd806ecac6e3a910a8a877db Mon Sep 17 00:00:00 2001
    2 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= <kabel@kernel.org>
    3 Date: Thu, 29 Sep 2022 18:03:05 +0200
    4 Subject: [PATCH net-next 05/12] net: phylink: pass supported host PHY
    5  interface modes to phylib for SFP's PHYs
    6 MIME-Version: 1.0
    7 Content-Type: text/plain; charset=UTF-8
    8 Content-Transfer-Encoding: 8bit
    9 
   10 Pass the supported PHY interface types to phylib if the PHY we are
   11 connecting is inside a SFP, so that the PHY driver can select an
   12 appropriate host configuration mode for their interface according to
   13 the host capabilities.
   14 
   15 Signed-off-by: Marek BehĂșn <kabel@kernel.org>
   16 ---
   17  drivers/net/phy/phylink.c | 17 +++++++++++++++++
   18  include/linux/phy.h       |  4 ++++
   19  2 files changed, 21 insertions(+)
   20 
   21 diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
   22 index f6e9231f0cbe..9ff8eb516666 100644
   23 --- a/drivers/net/phy/phylink.c
   24 +++ b/drivers/net/phy/phylink.c
   25 @@ -2814,6 +2814,8 @@ static const phy_interface_t phylink_sfp_interface_preference[] = {
   26         PHY_INTERFACE_MODE_100BASEX,
   27  };
   28  
   29 +static DECLARE_PHY_INTERFACE_MASK(phylink_sfp_interfaces);
   30 +
   31  static phy_interface_t phylink_choose_sfp_interface(struct phylink *pl,
   32                                                     const unsigned long *intf)
   33  {
   34 @@ -3091,6 +3093,10 @@ static int phylink_sfp_connect_phy(void *upstream, struct phy_device *phy)
   35         else
   36                 mode = MLO_AN_INBAND;
   37  
   38 +       /* Set the PHY's host supported interfaces */
   39 +       phy_interface_and(phy->host_interfaces, phylink_sfp_interfaces,
   40 +                         pl->config->supported_interfaces);
   41 +
   42         /* Do the initial configuration */
   43         ret = phylink_sfp_config_phy(pl, mode, phy);
   44         if (ret < 0)
   45 @@ -3444,4 +3450,15 @@ void phylink_mii_c45_pcs_get_state(struct mdio_device *pcs,
   46  }
   47  EXPORT_SYMBOL_GPL(phylink_mii_c45_pcs_get_state);
   48  
   49 +static int __init phylink_init(void)
   50 +{
   51 +       for (int i = 0; i < ARRAY_SIZE(phylink_sfp_interface_preference); ++i)
   52 +               __set_bit(phylink_sfp_interface_preference[i],
   53 +                         phylink_sfp_interfaces);
   54 +
   55 +       return 0;
   56 +}
   57 +
   58 +module_init(phylink_init);
   59 +
   60  MODULE_LICENSE("GPL v2");
   61 diff --git a/include/linux/phy.h b/include/linux/phy.h
   62 index 9c66f357f489..d65fc76fe0ae 100644
   63 --- a/include/linux/phy.h
   64 +++ b/include/linux/phy.h
   65 @@ -571,6 +571,7 @@ struct macsec_ops;
   66   * @advertising: Currently advertised linkmodes
   67   * @adv_old: Saved advertised while power saving for WoL
   68   * @lp_advertising: Current link partner advertised linkmodes
   69 + * @host_interfaces: PHY interface modes supported by host
   70   * @eee_broken_modes: Energy efficient ethernet modes which should be prohibited
   71   * @autoneg: Flag autoneg being used
   72   * @rate_matching: Current rate matching mode
   73 @@ -670,6 +671,9 @@ struct phy_device {
   74         /* used with phy_speed_down */
   75         __ETHTOOL_DECLARE_LINK_MODE_MASK(adv_old);
   76  
   77 +       /* Host supported PHY interface types. Should be ignored if empty. */
   78 +       DECLARE_PHY_INTERFACE_MASK(host_interfaces);
   79 +
   80         /* Energy efficient ethernet modes which should be prohibited */
   81         u32 eee_broken_modes;
   82  
   83 -- 
   84 2.35.1
   85