716-v5.4-net-sfp-move-fwnode-parsing-into-sfp-bus-layer.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. From 4054955f0da08c81d42220cb445820d474f1ac92 Mon Sep 17 00:00:00 2001
  2. From: Russell King <[email protected]>
  3. Date: Sat, 14 Sep 2019 14:21:22 +0100
  4. Subject: [PATCH 614/660] net: sfp: move fwnode parsing into sfp-bus layer
  5. Rather than parsing the sfp firmware node in phylink, parse it in the
  6. sfp-bus code, so we can re-use this code for PHYs without having to
  7. duplicate the parsing.
  8. Signed-off-by: Russell King <[email protected]>
  9. ---
  10. drivers/net/phy/phylink.c | 21 ++++---------
  11. drivers/net/phy/sfp-bus.c | 65 +++++++++++++++++++++++++--------------
  12. include/linux/sfp.h | 10 +++---
  13. 3 files changed, 53 insertions(+), 43 deletions(-)
  14. --- a/drivers/net/phy/phylink.c
  15. +++ b/drivers/net/phy/phylink.c
  16. @@ -538,26 +538,17 @@ static const struct sfp_upstream_ops sfp
  17. static int phylink_register_sfp(struct phylink *pl,
  18. struct fwnode_handle *fwnode)
  19. {
  20. - struct fwnode_reference_args ref;
  21. + struct sfp_bus *bus;
  22. int ret;
  23. - if (!fwnode)
  24. - return 0;
  25. -
  26. - ret = fwnode_property_get_reference_args(fwnode, "sfp", NULL,
  27. - 0, 0, &ref);
  28. - if (ret < 0) {
  29. - if (ret == -ENOENT)
  30. - return 0;
  31. -
  32. - netdev_err(pl->netdev, "unable to parse \"sfp\" node: %d\n",
  33. - ret);
  34. + bus = sfp_register_upstream_node(fwnode, pl, &sfp_phylink_ops);
  35. + if (IS_ERR(bus)) {
  36. + ret = PTR_ERR(bus);
  37. + netdev_err(pl->netdev, "unable to attach SFP bus: %d\n", ret);
  38. return ret;
  39. }
  40. - pl->sfp_bus = sfp_register_upstream(ref.fwnode, pl, &sfp_phylink_ops);
  41. - if (!pl->sfp_bus)
  42. - return -ENOMEM;
  43. + pl->sfp_bus = bus;
  44. return 0;
  45. }
  46. --- a/drivers/net/phy/sfp-bus.c
  47. +++ b/drivers/net/phy/sfp-bus.c
  48. @@ -3,6 +3,7 @@
  49. #include <linux/list.h>
  50. #include <linux/mutex.h>
  51. #include <linux/phylink.h>
  52. +#include <linux/property.h>
  53. #include <linux/rtnetlink.h>
  54. #include <linux/slab.h>
  55. @@ -444,45 +445,63 @@ static void sfp_upstream_clear(struct sf
  56. }
  57. /**
  58. - * sfp_register_upstream() - Register the neighbouring device
  59. - * @fwnode: firmware node for the SFP bus
  60. + * sfp_register_upstream_node() - parse and register the neighbouring device
  61. + * @fwnode: firmware node for the parent device (MAC or PHY)
  62. * @upstream: the upstream private data
  63. * @ops: the upstream's &struct sfp_upstream_ops
  64. *
  65. - * Register the upstream device (eg, PHY) with the SFP bus. MAC drivers
  66. - * should use phylink, which will call this function for them. Returns
  67. - * a pointer to the allocated &struct sfp_bus.
  68. + * Parse the parent device's firmware node for a SFP bus, and register the
  69. + * SFP bus using sfp_register_upstream().
  70. *
  71. - * On error, returns %NULL.
  72. + * Returns: on success, a pointer to the sfp_bus structure,
  73. + * %NULL if no SFP is specified,
  74. + * on failure, an error pointer value:
  75. + * corresponding to the errors detailed for
  76. + * fwnode_property_get_reference_args().
  77. + * %-ENOMEM if we failed to allocate the bus.
  78. + * an error from the upstream's connect_phy() method.
  79. */
  80. -struct sfp_bus *sfp_register_upstream(struct fwnode_handle *fwnode,
  81. - void *upstream,
  82. - const struct sfp_upstream_ops *ops)
  83. -{
  84. - struct sfp_bus *bus = sfp_bus_get(fwnode);
  85. - int ret = 0;
  86. -
  87. - if (bus) {
  88. - rtnl_lock();
  89. - bus->upstream_ops = ops;
  90. - bus->upstream = upstream;
  91. +struct sfp_bus *sfp_register_upstream_node(struct fwnode_handle *fwnode,
  92. + void *upstream,
  93. + const struct sfp_upstream_ops *ops)
  94. +{
  95. + struct fwnode_reference_args ref;
  96. + struct sfp_bus *bus;
  97. + int ret;
  98. - if (bus->sfp) {
  99. - ret = sfp_register_bus(bus);
  100. - if (ret)
  101. - sfp_upstream_clear(bus);
  102. - }
  103. - rtnl_unlock();
  104. + ret = fwnode_property_get_reference_args(fwnode, "sfp", NULL,
  105. + 0, 0, &ref);
  106. + if (ret == -ENOENT)
  107. + return NULL;
  108. + else if (ret < 0)
  109. + return ERR_PTR(ret);
  110. +
  111. + bus = sfp_bus_get(ref.fwnode);
  112. + fwnode_handle_put(ref.fwnode);
  113. + if (!bus)
  114. + return ERR_PTR(-ENOMEM);
  115. +
  116. + rtnl_lock();
  117. + bus->upstream_ops = ops;
  118. + bus->upstream = upstream;
  119. +
  120. + if (bus->sfp) {
  121. + ret = sfp_register_bus(bus);
  122. + if (ret)
  123. + sfp_upstream_clear(bus);
  124. + } else {
  125. + ret = 0;
  126. }
  127. + rtnl_unlock();
  128. if (ret) {
  129. sfp_bus_put(bus);
  130. - bus = NULL;
  131. + bus = ERR_PTR(ret);
  132. }
  133. return bus;
  134. }
  135. -EXPORT_SYMBOL_GPL(sfp_register_upstream);
  136. +EXPORT_SYMBOL_GPL(sfp_register_upstream_node);
  137. /**
  138. * sfp_unregister_upstream() - Unregister sfp bus
  139. --- a/include/linux/sfp.h
  140. +++ b/include/linux/sfp.h
  141. @@ -508,9 +508,9 @@ int sfp_get_module_eeprom(struct sfp_bus
  142. u8 *data);
  143. void sfp_upstream_start(struct sfp_bus *bus);
  144. void sfp_upstream_stop(struct sfp_bus *bus);
  145. -struct sfp_bus *sfp_register_upstream(struct fwnode_handle *fwnode,
  146. - void *upstream,
  147. - const struct sfp_upstream_ops *ops);
  148. +struct sfp_bus *sfp_register_upstream_node(struct fwnode_handle *fwnode,
  149. + void *upstream,
  150. + const struct sfp_upstream_ops *ops);
  151. void sfp_unregister_upstream(struct sfp_bus *bus);
  152. #else
  153. static inline int sfp_parse_port(struct sfp_bus *bus,
  154. @@ -553,11 +553,11 @@ static inline void sfp_upstream_stop(str
  155. {
  156. }
  157. -static inline struct sfp_bus *sfp_register_upstream(
  158. +static inline struct sfp_bus *sfp_register_upstream_node(
  159. struct fwnode_handle *fwnode, void *upstream,
  160. const struct sfp_upstream_ops *ops)
  161. {
  162. - return (struct sfp_bus *)-1;
  163. + return NULL;
  164. }
  165. static inline void sfp_unregister_upstream(struct sfp_bus *bus)