429-phylink-add-module-EEPROM-support.patch 3.6 KB

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