716-v6.9-02-net-phy-add-support-for-scanning-PHY-in-PHY-packages.patch 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. From 385ef48f468696d6d172eb367656a3466fa0408d Mon Sep 17 00:00:00 2001
  2. From: Christian Marangi <[email protected]>
  3. Date: Tue, 6 Feb 2024 18:31:05 +0100
  4. Subject: [PATCH 02/10] net: phy: add support for scanning PHY in PHY packages
  5. nodes
  6. Add support for scanning PHY in PHY package nodes. PHY packages nodes
  7. are just container for actual PHY on the MDIO bus.
  8. Their PHY address defined in the PHY package node are absolute and
  9. reflect the address on the MDIO bus.
  10. mdio_bus.c and of_mdio.c is updated to now support and parse also
  11. PHY package subnode by checking if the node name match
  12. "ethernet-phy-package".
  13. As PHY package reg is mandatory and each PHY in the PHY package must
  14. have a reg, every invalid PHY Package node is ignored and will be
  15. skipped by the autoscan fallback.
  16. Signed-off-by: Christian Marangi <[email protected]>
  17. Reviewed-by: Andrew Lunn <[email protected]>
  18. Signed-off-by: David S. Miller <[email protected]>
  19. ---
  20. drivers/net/mdio/of_mdio.c | 79 +++++++++++++++++++++++++++-----------
  21. drivers/net/phy/mdio_bus.c | 44 +++++++++++++++++----
  22. 2 files changed, 92 insertions(+), 31 deletions(-)
  23. --- a/drivers/net/mdio/of_mdio.c
  24. +++ b/drivers/net/mdio/of_mdio.c
  25. @@ -138,6 +138,53 @@ bool of_mdiobus_child_is_phy(struct devi
  26. }
  27. EXPORT_SYMBOL(of_mdiobus_child_is_phy);
  28. +static int __of_mdiobus_parse_phys(struct mii_bus *mdio, struct device_node *np,
  29. + bool *scanphys)
  30. +{
  31. + struct device_node *child;
  32. + int addr, rc = 0;
  33. +
  34. + /* Loop over the child nodes and register a phy_device for each phy */
  35. + for_each_available_child_of_node(np, child) {
  36. + if (of_node_name_eq(child, "ethernet-phy-package")) {
  37. + /* Ignore invalid ethernet-phy-package node */
  38. + if (!of_find_property(child, "reg", NULL))
  39. + continue;
  40. +
  41. + rc = __of_mdiobus_parse_phys(mdio, child, NULL);
  42. + if (rc && rc != -ENODEV)
  43. + goto exit;
  44. +
  45. + continue;
  46. + }
  47. +
  48. + addr = of_mdio_parse_addr(&mdio->dev, child);
  49. + if (addr < 0) {
  50. + /* Skip scanning for invalid ethernet-phy-package node */
  51. + if (scanphys)
  52. + *scanphys = true;
  53. + continue;
  54. + }
  55. +
  56. + if (of_mdiobus_child_is_phy(child))
  57. + rc = of_mdiobus_register_phy(mdio, child, addr);
  58. + else
  59. + rc = of_mdiobus_register_device(mdio, child, addr);
  60. +
  61. + if (rc == -ENODEV)
  62. + dev_err(&mdio->dev,
  63. + "MDIO device at address %d is missing.\n",
  64. + addr);
  65. + else if (rc)
  66. + goto exit;
  67. + }
  68. +
  69. + return 0;
  70. +exit:
  71. + of_node_put(child);
  72. + return rc;
  73. +}
  74. +
  75. /**
  76. * __of_mdiobus_register - Register mii_bus and create PHYs from the device tree
  77. * @mdio: pointer to mii_bus structure
  78. @@ -179,33 +226,18 @@ int __of_mdiobus_register(struct mii_bus
  79. return rc;
  80. /* Loop over the child nodes and register a phy_device for each phy */
  81. - for_each_available_child_of_node(np, child) {
  82. - addr = of_mdio_parse_addr(&mdio->dev, child);
  83. - if (addr < 0) {
  84. - scanphys = true;
  85. - continue;
  86. - }
  87. -
  88. - if (of_mdiobus_child_is_phy(child))
  89. - rc = of_mdiobus_register_phy(mdio, child, addr);
  90. - else
  91. - rc = of_mdiobus_register_device(mdio, child, addr);
  92. -
  93. - if (rc == -ENODEV)
  94. - dev_err(&mdio->dev,
  95. - "MDIO device at address %d is missing.\n",
  96. - addr);
  97. - else if (rc)
  98. - goto unregister;
  99. - }
  100. + rc = __of_mdiobus_parse_phys(mdio, np, &scanphys);
  101. + if (rc)
  102. + goto unregister;
  103. if (!scanphys)
  104. return 0;
  105. /* auto scan for PHYs with empty reg property */
  106. for_each_available_child_of_node(np, child) {
  107. - /* Skip PHYs with reg property set */
  108. - if (of_property_present(child, "reg"))
  109. + /* Skip PHYs with reg property set or ethernet-phy-package node */
  110. + if (of_property_present(child, "reg") ||
  111. + of_node_name_eq(child, "ethernet-phy-package"))
  112. continue;
  113. for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
  114. @@ -226,15 +258,16 @@ int __of_mdiobus_register(struct mii_bus
  115. if (!rc)
  116. break;
  117. if (rc != -ENODEV)
  118. - goto unregister;
  119. + goto put_unregister;
  120. }
  121. }
  122. }
  123. return 0;
  124. -unregister:
  125. +put_unregister:
  126. of_node_put(child);
  127. +unregister:
  128. mdiobus_unregister(mdio);
  129. return rc;
  130. }
  131. --- a/drivers/net/phy/mdio_bus.c
  132. +++ b/drivers/net/phy/mdio_bus.c
  133. @@ -455,19 +455,34 @@ EXPORT_SYMBOL(of_mdio_find_bus);
  134. * found, set the of_node pointer for the mdio device. This allows
  135. * auto-probed phy devices to be supplied with information passed in
  136. * via DT.
  137. + * If a PHY package is found, PHY is searched also there.
  138. */
  139. -static void of_mdiobus_link_mdiodev(struct mii_bus *bus,
  140. - struct mdio_device *mdiodev)
  141. +static int of_mdiobus_find_phy(struct device *dev, struct mdio_device *mdiodev,
  142. + struct device_node *np)
  143. {
  144. - struct device *dev = &mdiodev->dev;
  145. struct device_node *child;
  146. - if (dev->of_node || !bus->dev.of_node)
  147. - return;
  148. -
  149. - for_each_available_child_of_node(bus->dev.of_node, child) {
  150. + for_each_available_child_of_node(np, child) {
  151. int addr;
  152. + if (of_node_name_eq(child, "ethernet-phy-package")) {
  153. + /* Validate PHY package reg presence */
  154. + if (!of_find_property(child, "reg", NULL)) {
  155. + of_node_put(child);
  156. + return -EINVAL;
  157. + }
  158. +
  159. + if (!of_mdiobus_find_phy(dev, mdiodev, child)) {
  160. + /* The refcount for the PHY package will be
  161. + * incremented later when PHY join the Package.
  162. + */
  163. + of_node_put(child);
  164. + return 0;
  165. + }
  166. +
  167. + continue;
  168. + }
  169. +
  170. addr = of_mdio_parse_addr(dev, child);
  171. if (addr < 0)
  172. continue;
  173. @@ -477,9 +492,22 @@ static void of_mdiobus_link_mdiodev(stru
  174. /* The refcount on "child" is passed to the mdio
  175. * device. Do _not_ use of_node_put(child) here.
  176. */
  177. - return;
  178. + return 0;
  179. }
  180. }
  181. +
  182. + return -ENODEV;
  183. +}
  184. +
  185. +static void of_mdiobus_link_mdiodev(struct mii_bus *bus,
  186. + struct mdio_device *mdiodev)
  187. +{
  188. + struct device *dev = &mdiodev->dev;
  189. +
  190. + if (dev->of_node || !bus->dev.of_node)
  191. + return;
  192. +
  193. + of_mdiobus_find_phy(dev, mdiodev, bus->dev.of_node);
  194. }
  195. #else /* !IS_ENABLED(CONFIG_OF_MDIO) */
  196. static inline void of_mdiobus_link_mdiodev(struct mii_bus *mdio,