408-sfp-move-module-eeprom-ethtool-access-into-netdev-co.patch 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. From c47beb7e3f8575dfd7d58240a72c4e4e66ce5449 Mon Sep 17 00:00:00 2001
  2. From: Russell King <rmk+kernel@armlinux.org.uk>
  3. Date: Fri, 14 Apr 2017 15:26:32 +0100
  4. Subject: sfp: move module eeprom ethtool access into netdev core ethtool
  5. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
  6. ---
  7. drivers/net/ethernet/marvell/mvneta.c | 18 ------------------
  8. drivers/net/phy/phylink.c | 28 ----------------------------
  9. drivers/net/phy/sfp-bus.c | 6 ++----
  10. include/linux/netdevice.h | 2 ++
  11. include/linux/phylink.h | 3 ---
  12. net/core/ethtool.c | 7 +++++++
  13. 6 files changed, 11 insertions(+), 53 deletions(-)
  14. --- a/drivers/net/ethernet/marvell/mvneta.c
  15. +++ b/drivers/net/ethernet/marvell/mvneta.c
  16. @@ -4051,22 +4051,6 @@ static int mvneta_ethtool_set_wol(struct
  17. return ret;
  18. }
  19. -static int mvneta_ethtool_get_module_info(struct net_device *dev,
  20. - struct ethtool_modinfo *modinfo)
  21. -{
  22. - struct mvneta_port *pp = netdev_priv(dev);
  23. -
  24. - return phylink_ethtool_get_module_info(pp->phylink, modinfo);
  25. -}
  26. -
  27. -static int mvneta_ethtool_get_module_eeprom(struct net_device *dev,
  28. - struct ethtool_eeprom *ee, u8 *buf)
  29. -{
  30. - struct mvneta_port *pp = netdev_priv(dev);
  31. -
  32. - return phylink_ethtool_get_module_eeprom(pp->phylink, ee, buf);
  33. -}
  34. -
  35. static int mvneta_ethtool_get_eee(struct net_device *dev,
  36. struct ethtool_eee *eee)
  37. {
  38. @@ -4151,8 +4135,6 @@ static const struct ethtool_ops mvneta_e
  39. .set_link_ksettings = mvneta_ethtool_set_link_ksettings,
  40. .get_wol = mvneta_ethtool_get_wol,
  41. .set_wol = mvneta_ethtool_set_wol,
  42. - .get_module_info = mvneta_ethtool_get_module_info,
  43. - .get_module_eeprom = mvneta_ethtool_get_module_eeprom,
  44. .get_eee = mvneta_ethtool_get_eee,
  45. .set_eee = mvneta_ethtool_set_eee,
  46. };
  47. --- a/drivers/net/phy/phylink.c
  48. +++ b/drivers/net/phy/phylink.c
  49. @@ -1065,34 +1065,6 @@ int phylink_ethtool_set_pauseparam(struc
  50. }
  51. EXPORT_SYMBOL_GPL(phylink_ethtool_set_pauseparam);
  52. -int phylink_ethtool_get_module_info(struct phylink *pl,
  53. - struct ethtool_modinfo *modinfo)
  54. -{
  55. - int ret = -EOPNOTSUPP;
  56. -
  57. - WARN_ON(!lockdep_rtnl_is_held());
  58. -
  59. - if (pl->sfp_bus)
  60. - ret = sfp_get_module_info(pl->sfp_bus, modinfo);
  61. -
  62. - return ret;
  63. -}
  64. -EXPORT_SYMBOL_GPL(phylink_ethtool_get_module_info);
  65. -
  66. -int phylink_ethtool_get_module_eeprom(struct phylink *pl,
  67. - struct ethtool_eeprom *ee, u8 *buf)
  68. -{
  69. - int ret = -EOPNOTSUPP;
  70. -
  71. - WARN_ON(!lockdep_rtnl_is_held());
  72. -
  73. - if (pl->sfp_bus)
  74. - ret = sfp_get_module_eeprom(pl->sfp_bus, ee, buf);
  75. -
  76. - return ret;
  77. -}
  78. -EXPORT_SYMBOL_GPL(phylink_ethtool_get_module_eeprom);
  79. -
  80. int phylink_init_eee(struct phylink *pl, bool clk_stop_enable)
  81. {
  82. int ret = -EPROTONOSUPPORT;
  83. --- a/drivers/net/phy/sfp-bus.c
  84. +++ b/drivers/net/phy/sfp-bus.c
  85. @@ -279,6 +279,7 @@ static int sfp_register_bus(struct sfp_b
  86. bus->socket_ops->attach(bus->sfp);
  87. if (bus->started)
  88. bus->socket_ops->start(bus->sfp);
  89. + bus->netdev->sfp_bus = bus;
  90. bus->registered = true;
  91. return 0;
  92. }
  93. @@ -294,14 +295,13 @@ static void sfp_unregister_bus(struct sf
  94. if (bus->phydev && ops && ops->disconnect_phy)
  95. ops->disconnect_phy(bus->upstream);
  96. }
  97. + bus->netdev->sfp_bus = NULL;
  98. bus->registered = false;
  99. }
  100. int sfp_get_module_info(struct sfp_bus *bus, struct ethtool_modinfo *modinfo)
  101. {
  102. - if (!bus->registered)
  103. - return -ENOIOCTLCMD;
  104. return bus->socket_ops->module_info(bus->sfp, modinfo);
  105. }
  106. EXPORT_SYMBOL_GPL(sfp_get_module_info);
  107. @@ -309,8 +309,6 @@ EXPORT_SYMBOL_GPL(sfp_get_module_info);
  108. int sfp_get_module_eeprom(struct sfp_bus *bus, struct ethtool_eeprom *ee,
  109. u8 *data)
  110. {
  111. - if (!bus->registered)
  112. - return -ENOIOCTLCMD;
  113. return bus->socket_ops->module_eeprom(bus->sfp, ee, data);
  114. }
  115. EXPORT_SYMBOL_GPL(sfp_get_module_eeprom);
  116. --- a/include/linux/netdevice.h
  117. +++ b/include/linux/netdevice.h
  118. @@ -57,6 +57,7 @@ struct device;
  119. struct phy_device;
  120. struct dsa_switch_tree;
  121. +struct sfp_bus;
  122. /* 802.11 specific */
  123. struct wireless_dev;
  124. /* 802.15.4 specific */
  125. @@ -1943,6 +1944,7 @@ struct net_device {
  126. struct netprio_map __rcu *priomap;
  127. #endif
  128. struct phy_device *phydev;
  129. + struct sfp_bus *sfp_bus;
  130. struct lock_class_key *qdisc_tx_busylock;
  131. struct lock_class_key *qdisc_running_key;
  132. bool proto_down;
  133. --- a/include/linux/phylink.h
  134. +++ b/include/linux/phylink.h
  135. @@ -125,9 +125,6 @@ void phylink_ethtool_get_pauseparam(stru
  136. struct ethtool_pauseparam *);
  137. int phylink_ethtool_set_pauseparam(struct phylink *,
  138. struct ethtool_pauseparam *);
  139. -int phylink_ethtool_get_module_info(struct phylink *, struct ethtool_modinfo *);
  140. -int phylink_ethtool_get_module_eeprom(struct phylink *,
  141. - struct ethtool_eeprom *, u8 *);
  142. int phylink_init_eee(struct phylink *, bool);
  143. int phylink_get_eee_err(struct phylink *);
  144. int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *);
  145. --- a/net/core/ethtool.c
  146. +++ b/net/core/ethtool.c
  147. @@ -22,6 +22,7 @@
  148. #include <linux/bitops.h>
  149. #include <linux/uaccess.h>
  150. #include <linux/vmalloc.h>
  151. +#include <linux/sfp.h>
  152. #include <linux/slab.h>
  153. #include <linux/rtnetlink.h>
  154. #include <linux/sched/signal.h>
  155. @@ -2215,6 +2216,9 @@ static int __ethtool_get_module_info(str
  156. const struct ethtool_ops *ops = dev->ethtool_ops;
  157. struct phy_device *phydev = dev->phydev;
  158. + if (dev->sfp_bus)
  159. + return sfp_get_module_info(dev->sfp_bus, modinfo);
  160. +
  161. if (phydev && phydev->drv && phydev->drv->module_info)
  162. return phydev->drv->module_info(phydev, modinfo);
  163. @@ -2249,6 +2253,9 @@ static int __ethtool_get_module_eeprom(s
  164. const struct ethtool_ops *ops = dev->ethtool_ops;
  165. struct phy_device *phydev = dev->phydev;
  166. + if (dev->sfp_bus)
  167. + return sfp_get_module_eeprom(dev->sfp_bus, ee, data);
  168. +
  169. if (phydev && phydev->drv && phydev->drv->module_eeprom)
  170. return phydev->drv->module_eeprom(phydev, ee, data);