131-phylink-add-hooks-for-SFP-support.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. From 0a0c4b3dd4f34df4532f254a5940b520015d766f Mon Sep 17 00:00:00 2001
  2. From: Russell King <rmk+kernel@arm.linux.org.uk>
  3. Date: Thu, 24 Sep 2015 11:01:13 +0100
  4. Subject: [PATCH 719/744] phylink: add hooks for SFP support
  5. Add support to phylink for SFP, which needs to control and configure
  6. the ethernet MAC link state. Specifically, SFP needs to:
  7. 1. set the negotiation mode between SGMII and 1000base-X
  8. 2. attach and detach the module PHY
  9. 3. prevent the link coming up when errors are reported
  10. In the absence of a PHY, we also need to set the ethtool port type
  11. according to the module plugged in.
  12. Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
  13. Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
  14. ---
  15. drivers/net/phy/phylink.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++
  16. include/linux/phylink.h | 6 ++++
  17. 2 files changed, 88 insertions(+)
  18. --- a/drivers/net/phy/phylink.c
  19. +++ b/drivers/net/phy/phylink.c
  20. @@ -11,6 +11,7 @@
  21. #include <linux/ethtool.h>
  22. #include <linux/export.h>
  23. #include <linux/gpio/consumer.h>
  24. +#include <linux/list.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/of.h>
  27. #include <linux/of_mdio.h>
  28. @@ -29,11 +30,16 @@
  29. (ADVERTISED_TP | ADVERTISED_MII | ADVERTISED_FIBRE | \
  30. ADVERTISED_BNC | ADVERTISED_AUI | ADVERTISED_Backplane)
  31. +static LIST_HEAD(phylinks);
  32. +static DEFINE_MUTEX(phylink_mutex);
  33. +
  34. enum {
  35. PHYLINK_DISABLE_STOPPED,
  36. + PHYLINK_DISABLE_LINK,
  37. };
  38. struct phylink {
  39. + struct list_head node;
  40. struct net_device *netdev;
  41. const struct phylink_mac_ops *ops;
  42. struct mutex config_mutex;
  43. @@ -341,12 +347,20 @@ struct phylink *phylink_create(struct ne
  44. return ERR_PTR(ret);
  45. }
  46. + mutex_lock(&phylink_mutex);
  47. + list_add_tail(&pl->node, &phylinks);
  48. + mutex_unlock(&phylink_mutex);
  49. +
  50. return pl;
  51. }
  52. EXPORT_SYMBOL_GPL(phylink_create);
  53. void phylink_destroy(struct phylink *pl)
  54. {
  55. + mutex_lock(&phylink_mutex);
  56. + list_del(&pl->node);
  57. + mutex_unlock(&phylink_mutex);
  58. +
  59. cancel_work_sync(&pl->resolve);
  60. kfree(pl);
  61. }
  62. @@ -813,4 +827,72 @@ int phylink_mii_ioctl(struct phylink *pl
  63. }
  64. EXPORT_SYMBOL_GPL(phylink_mii_ioctl);
  65. +
  66. +
  67. +void phylink_disable(struct phylink *pl)
  68. +{
  69. + set_bit(PHYLINK_DISABLE_LINK, &pl->phylink_disable_state);
  70. + flush_work(&pl->resolve);
  71. +
  72. + netif_carrier_off(pl->netdev);
  73. +}
  74. +EXPORT_SYMBOL_GPL(phylink_disable);
  75. +
  76. +void phylink_enable(struct phylink *pl)
  77. +{
  78. + clear_bit(PHYLINK_DISABLE_LINK, &pl->phylink_disable_state);
  79. + phylink_run_resolve(pl);
  80. +}
  81. +EXPORT_SYMBOL_GPL(phylink_enable);
  82. +
  83. +void phylink_set_link_port(struct phylink *pl, u32 support, u8 port)
  84. +{
  85. + WARN_ON(support & ~SUPPORTED_INTERFACES);
  86. +
  87. + mutex_lock(&pl->config_mutex);
  88. + pl->link_port_support = support;
  89. + pl->link_port = port;
  90. + mutex_unlock(&pl->config_mutex);
  91. +}
  92. +EXPORT_SYMBOL_GPL(phylink_set_link_port);
  93. +
  94. +int phylink_set_link_an_mode(struct phylink *pl, unsigned int mode)
  95. +{
  96. + int ret = 0;
  97. +
  98. + mutex_lock(&pl->config_mutex);
  99. + if (pl->link_an_mode != mode) {
  100. + ret = phylink_get_support(pl, mode);
  101. + if (ret == 0) {
  102. + if (!test_bit(PHYLINK_DISABLE_STOPPED,
  103. + &pl->phylink_disable_state))
  104. + phylink_mac_config(pl, &pl->link_config);
  105. +
  106. + netdev_info(pl->netdev, "switched to %s link mode\n",
  107. + phylink_an_mode_str(mode));
  108. + }
  109. + }
  110. + mutex_unlock(&pl->config_mutex);
  111. +
  112. + return ret;
  113. +}
  114. +EXPORT_SYMBOL_GPL(phylink_set_link_an_mode);
  115. +
  116. +struct phylink *phylink_lookup_by_netdev(struct net_device *ndev)
  117. +{
  118. + struct phylink *pl, *found = NULL;
  119. +
  120. + mutex_lock(&phylink_mutex);
  121. + list_for_each_entry(pl, &phylinks, node)
  122. + if (pl->netdev == ndev) {
  123. + found = pl;
  124. + break;
  125. + }
  126. +
  127. + mutex_unlock(&phylink_mutex);
  128. +
  129. + return found;
  130. +}
  131. +EXPORT_SYMBOL_GPL(phylink_lookup_by_netdev);
  132. +
  133. MODULE_LICENSE("GPL");
  134. --- a/include/linux/phylink.h
  135. +++ b/include/linux/phylink.h
  136. @@ -67,4 +67,10 @@ int phylink_ethtool_get_settings(struct
  137. int phylink_ethtool_set_settings(struct phylink *, struct ethtool_cmd *);
  138. int phylink_mii_ioctl(struct phylink *, struct ifreq *, int);
  139. +void phylink_set_link_port(struct phylink *pl, u32 support, u8 port);
  140. +int phylink_set_link_an_mode(struct phylink *pl, unsigned int mode);
  141. +void phylink_disable(struct phylink *pl);
  142. +void phylink_enable(struct phylink *pl);
  143. +struct phylink *phylink_lookup_by_netdev(struct net_device *ndev);
  144. +
  145. #endif