2
0

703-15-v5.18-net-phy-phylink-fix-DSA-mac_select_pcs-introduction.patch 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. From 1054457006d4a14de4ae4132030e33d7eedaeba1 Mon Sep 17 00:00:00 2001
  2. From: "Russell King (Oracle)" <[email protected]>
  3. Date: Mon, 21 Feb 2022 17:10:52 +0000
  4. Subject: [PATCH] net: phy: phylink: fix DSA mac_select_pcs() introduction
  5. Vladimir Oltean reports that probing on DSA drivers that aren't yet
  6. populating supported_interfaces now fails. Fix this by allowing
  7. phylink to detect whether DSA actually provides an underlying
  8. mac_select_pcs() implementation.
  9. Reported-by: Vladimir Oltean <[email protected]>
  10. Fixes: bde018222c6b ("net: dsa: add support for phylink mac_select_pcs()")
  11. Signed-off-by: Russell King (Oracle) <[email protected]>
  12. Tested-by: Vladimir Oltean <[email protected]>
  13. Link: https://lore.kernel.org/r/[email protected]
  14. Signed-off-by: Jakub Kicinski <[email protected]>
  15. ---
  16. drivers/net/phy/phylink.c | 14 +++++++++++---
  17. net/dsa/port.c | 2 +-
  18. 2 files changed, 12 insertions(+), 4 deletions(-)
  19. --- a/drivers/net/phy/phylink.c
  20. +++ b/drivers/net/phy/phylink.c
  21. @@ -74,6 +74,7 @@ struct phylink {
  22. struct work_struct resolve;
  23. bool mac_link_dropped;
  24. + bool using_mac_select_pcs;
  25. struct sfp_bus *sfp_bus;
  26. bool sfp_may_have_phy;
  27. @@ -163,7 +164,7 @@ static int phylink_validate_mac_and_pcs(
  28. int ret;
  29. /* Get the PCS for this interface mode */
  30. - if (pl->mac_ops->mac_select_pcs) {
  31. + if (pl->using_mac_select_pcs) {
  32. pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface);
  33. if (IS_ERR(pcs))
  34. return PTR_ERR(pcs);
  35. @@ -790,7 +791,7 @@ static void phylink_major_config(struct
  36. phylink_dbg(pl, "major config %s\n", phy_modes(state->interface));
  37. - if (pl->mac_ops->mac_select_pcs) {
  38. + if (pl->using_mac_select_pcs) {
  39. pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface);
  40. if (IS_ERR(pcs)) {
  41. phylink_err(pl,
  42. @@ -1192,11 +1193,17 @@ struct phylink *phylink_create(struct ph
  43. phy_interface_t iface,
  44. const struct phylink_mac_ops *mac_ops)
  45. {
  46. + bool using_mac_select_pcs = false;
  47. struct phylink *pl;
  48. int ret;
  49. - /* Validate the supplied configuration */
  50. if (mac_ops->mac_select_pcs &&
  51. + mac_ops->mac_select_pcs(config, PHY_INTERFACE_MODE_NA) !=
  52. + ERR_PTR(-EOPNOTSUPP))
  53. + using_mac_select_pcs = true;
  54. +
  55. + /* Validate the supplied configuration */
  56. + if (using_mac_select_pcs &&
  57. phy_interface_empty(config->supported_interfaces)) {
  58. dev_err(config->dev,
  59. "phylink: error: empty supported_interfaces but mac_select_pcs() method present\n");
  60. @@ -1220,6 +1227,7 @@ struct phylink *phylink_create(struct ph
  61. return ERR_PTR(-EINVAL);
  62. }
  63. + pl->using_mac_select_pcs = using_mac_select_pcs;
  64. pl->phy_state.interface = iface;
  65. pl->link_interface = iface;
  66. if (iface == PHY_INTERFACE_MODE_MOCA)
  67. --- a/net/dsa/port.c
  68. +++ b/net/dsa/port.c
  69. @@ -1033,8 +1033,8 @@ dsa_port_phylink_mac_select_pcs(struct p
  70. phy_interface_t interface)
  71. {
  72. struct dsa_port *dp = container_of(config, struct dsa_port, pl_config);
  73. + struct phylink_pcs *pcs = ERR_PTR(-EOPNOTSUPP);
  74. struct dsa_switch *ds = dp->ds;
  75. - struct phylink_pcs *pcs = NULL;
  76. if (ds->ops->phylink_mac_select_pcs)
  77. pcs = ds->ops->phylink_mac_select_pcs(ds, dp->index, interface);