749-net-phylink-split-phylink_sfp_module_insert.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. From 36569971241ae6b81376da4937d2c8760122d10b Mon Sep 17 00:00:00 2001
  2. From: Russell King <[email protected]>
  3. Date: Thu, 21 Nov 2019 17:58:58 +0000
  4. Subject: [PATCH 652/660] net: phylink: split phylink_sfp_module_insert()
  5. Split out the configuration step from phylink_sfp_module_insert() so
  6. we can re-use this later.
  7. Signed-off-by: Russell King <[email protected]>
  8. ---
  9. drivers/net/phy/phylink.c | 47 +++++++++++++++++++++++----------------
  10. 1 file changed, 28 insertions(+), 19 deletions(-)
  11. --- a/drivers/net/phy/phylink.c
  12. +++ b/drivers/net/phy/phylink.c
  13. @@ -1688,25 +1688,21 @@ static void phylink_sfp_detach(void *ups
  14. pl->netdev->sfp_bus = NULL;
  15. }
  16. -static int phylink_sfp_module_insert(void *upstream,
  17. - const struct sfp_eeprom_id *id)
  18. +static int phylink_sfp_config(struct phylink *pl, u8 mode, u8 port,
  19. + const unsigned long *supported,
  20. + const unsigned long *advertising)
  21. {
  22. - struct phylink *pl = upstream;
  23. - __ETHTOOL_DECLARE_LINK_MODE_MASK(support) = { 0, };
  24. __ETHTOOL_DECLARE_LINK_MODE_MASK(support1);
  25. + __ETHTOOL_DECLARE_LINK_MODE_MASK(support);
  26. struct phylink_link_state config;
  27. phy_interface_t iface;
  28. - int ret = 0;
  29. bool changed;
  30. - u8 port;
  31. + int ret;
  32. - ASSERT_RTNL();
  33. -
  34. - sfp_parse_support(pl->sfp_bus, id, support);
  35. - port = sfp_parse_port(pl->sfp_bus, id, support);
  36. + linkmode_copy(support, supported);
  37. memset(&config, 0, sizeof(config));
  38. - linkmode_copy(config.advertising, support);
  39. + linkmode_copy(config.advertising, advertising);
  40. config.interface = PHY_INTERFACE_MODE_NA;
  41. config.speed = SPEED_UNKNOWN;
  42. config.duplex = DUPLEX_UNKNOWN;
  43. @@ -1721,8 +1717,6 @@ static int phylink_sfp_module_insert(voi
  44. return ret;
  45. }
  46. - linkmode_copy(support1, support);
  47. -
  48. iface = sfp_select_interface(pl->sfp_bus, config.advertising);
  49. if (iface == PHY_INTERFACE_MODE_NA) {
  50. phylink_err(pl,
  51. @@ -1732,18 +1726,18 @@ static int phylink_sfp_module_insert(voi
  52. }
  53. config.interface = iface;
  54. + linkmode_copy(support1, support);
  55. ret = phylink_validate(pl, support1, &config);
  56. if (ret) {
  57. phylink_err(pl, "validation of %s/%s with support %*pb failed: %d\n",
  58. - phylink_an_mode_str(MLO_AN_INBAND),
  59. + phylink_an_mode_str(mode),
  60. phy_modes(config.interface),
  61. __ETHTOOL_LINK_MODE_MASK_NBITS, support, ret);
  62. return ret;
  63. }
  64. phylink_dbg(pl, "requesting link mode %s/%s with support %*pb\n",
  65. - phylink_an_mode_str(MLO_AN_INBAND),
  66. - phy_modes(config.interface),
  67. + phylink_an_mode_str(mode), phy_modes(config.interface),
  68. __ETHTOOL_LINK_MODE_MASK_NBITS, support);
  69. if (phy_interface_mode_is_8023z(iface) && pl->phydev)
  70. @@ -1756,15 +1750,15 @@ static int phylink_sfp_module_insert(voi
  71. linkmode_copy(pl->link_config.advertising, config.advertising);
  72. }
  73. - if (pl->cur_link_an_mode != MLO_AN_INBAND ||
  74. + if (pl->cur_link_an_mode != mode ||
  75. pl->link_config.interface != config.interface) {
  76. pl->link_config.interface = config.interface;
  77. - pl->cur_link_an_mode = MLO_AN_INBAND;
  78. + pl->cur_link_an_mode = mode;
  79. changed = true;
  80. phylink_info(pl, "switched to %s/%s link mode\n",
  81. - phylink_an_mode_str(MLO_AN_INBAND),
  82. + phylink_an_mode_str(mode),
  83. phy_modes(config.interface));
  84. }
  85. @@ -1777,6 +1771,21 @@ static int phylink_sfp_module_insert(voi
  86. return ret;
  87. }
  88. +static int phylink_sfp_module_insert(void *upstream,
  89. + const struct sfp_eeprom_id *id)
  90. +{
  91. + struct phylink *pl = upstream;
  92. + __ETHTOOL_DECLARE_LINK_MODE_MASK(support) = { 0, };
  93. + u8 port;
  94. +
  95. + ASSERT_RTNL();
  96. +
  97. + sfp_parse_support(pl->sfp_bus, id, support);
  98. + port = sfp_parse_port(pl->sfp_bus, id, support);
  99. +
  100. + return phylink_sfp_config(pl, MLO_AN_INBAND, port, support, support);
  101. +}
  102. +
  103. static int phylink_sfp_module_start(void *upstream)
  104. {
  105. struct phylink *pl = upstream;