144-phylink-add-module-EEPROM-support.patch 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. From 5419ccb638aa5c353ea88815e98953d9fc02e6ca Mon Sep 17 00:00:00 2001
  2. From: Russell King <rmk+kernel@arm.linux.org.uk>
  3. Date: Thu, 1 Oct 2015 23:10:05 +0100
  4. Subject: [PATCH 732/744] phylink: add module EEPROM support
  5. Add support for reading module EEPROMs through phylink.
  6. Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
  7. Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
  8. ---
  9. drivers/net/phy/phylink.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++
  10. include/linux/phylink.h | 12 +++++++++
  11. 2 files changed, 78 insertions(+)
  12. --- a/drivers/net/phy/phylink.c
  13. +++ b/drivers/net/phy/phylink.c
  14. @@ -60,6 +60,9 @@ struct phylink {
  15. struct work_struct resolve;
  16. bool mac_link_up;
  17. +
  18. + const struct phylink_module_ops *module_ops;
  19. + void *module_data;
  20. };
  21. static const char *phylink_an_mode_str(unsigned int mode)
  22. @@ -819,6 +822,36 @@ int phylink_ethtool_set_pauseparam(struc
  23. }
  24. EXPORT_SYMBOL_GPL(phylink_ethtool_set_pauseparam);
  25. +int phylink_ethtool_get_module_info(struct phylink *pl,
  26. + struct ethtool_modinfo *modinfo)
  27. +{
  28. + int ret = -EOPNOTSUPP;
  29. +
  30. + mutex_lock(&pl->config_mutex);
  31. + if (pl->module_ops)
  32. + ret = pl->module_ops->get_module_info(pl->module_data,
  33. + modinfo);
  34. + mutex_unlock(&pl->config_mutex);
  35. +
  36. + return ret;
  37. +}
  38. +EXPORT_SYMBOL_GPL(phylink_ethtool_get_module_info);
  39. +
  40. +int phylink_ethtool_get_module_eeprom(struct phylink *pl,
  41. + struct ethtool_eeprom *ee, u8 *buf)
  42. +{
  43. + int ret = -EOPNOTSUPP;
  44. +
  45. + mutex_lock(&pl->config_mutex);
  46. + if (pl->module_ops)
  47. + ret = pl->module_ops->get_module_eeprom(pl->module_data, ee,
  48. + buf);
  49. + mutex_unlock(&pl->config_mutex);
  50. +
  51. + return ret;
  52. +}
  53. +EXPORT_SYMBOL_GPL(phylink_ethtool_get_module_eeprom);
  54. +
  55. int phylink_init_eee(struct phylink *pl, bool clk_stop_enable)
  56. {
  57. int ret = -EPROTONOSUPPORT;
  58. @@ -1016,6 +1049,39 @@ EXPORT_SYMBOL_GPL(phylink_mii_ioctl);
  59. +int phylink_register_module(struct phylink *pl, void *data,
  60. + const struct phylink_module_ops *ops)
  61. +{
  62. + int ret = -EBUSY;
  63. +
  64. + mutex_lock(&pl->config_mutex);
  65. + if (!pl->module_ops) {
  66. + pl->module_ops = ops;
  67. + pl->module_data = data;
  68. + ret = 0;
  69. + }
  70. + mutex_unlock(&pl->config_mutex);
  71. +
  72. + return ret;
  73. +}
  74. +EXPORT_SYMBOL_GPL(phylink_register_module);
  75. +
  76. +int phylink_unregister_module(struct phylink *pl, void *data)
  77. +{
  78. + int ret = -EINVAL;
  79. +
  80. + mutex_lock(&pl->config_mutex);
  81. + if (pl->module_data == data) {
  82. + pl->module_ops = NULL;
  83. + pl->module_data = NULL;
  84. + ret = 0;
  85. + }
  86. + mutex_unlock(&pl->config_mutex);
  87. +
  88. + return ret;
  89. +}
  90. +EXPORT_SYMBOL_GPL(phylink_unregister_module);
  91. +
  92. void phylink_disable(struct phylink *pl)
  93. {
  94. set_bit(PHYLINK_DISABLE_LINK, &pl->phylink_disable_state);
  95. --- a/include/linux/phylink.h
  96. +++ b/include/linux/phylink.h
  97. @@ -55,6 +55,11 @@ struct phylink_mac_ops {
  98. struct phy_device *);
  99. };
  100. +struct phylink_module_ops {
  101. + int (*get_module_info)(void *, struct ethtool_modinfo *);
  102. + int (*get_module_eeprom)(void *, struct ethtool_eeprom *, u8 *);
  103. +};
  104. +
  105. struct phylink *phylink_create(struct net_device *, struct device_node *,
  106. phy_interface_t iface, const struct phylink_mac_ops *ops);
  107. void phylink_destroy(struct phylink *);
  108. @@ -75,12 +80,19 @@ void phylink_ethtool_get_pauseparam(stru
  109. struct ethtool_pauseparam *);
  110. int phylink_ethtool_set_pauseparam(struct phylink *,
  111. struct ethtool_pauseparam *);
  112. +int phylink_ethtool_get_module_info(struct phylink *, struct ethtool_modinfo *);
  113. +int phylink_ethtool_get_module_eeprom(struct phylink *,
  114. + struct ethtool_eeprom *, u8 *);
  115. int phylink_init_eee(struct phylink *, bool);
  116. int phylink_get_eee_err(struct phylink *);
  117. int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *);
  118. int phylink_ethtool_set_eee(struct phylink *, struct ethtool_eee *);
  119. int phylink_mii_ioctl(struct phylink *, struct ifreq *, int);
  120. +int phylink_register_module(struct phylink *, void *,
  121. + const struct phylink_module_ops *);
  122. +int phylink_unregister_module(struct phylink *, void *);
  123. +
  124. void phylink_set_link_port(struct phylink *pl, u32 support, u8 port);
  125. int phylink_set_link_an_mode(struct phylink *pl, unsigned int mode);
  126. void phylink_disable(struct phylink *pl);