0600-net-phylink-propagate-resolved-link-config-via-mac_l.patch 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. From: Russell King <[email protected]>
  2. Date: Wed, 26 Feb 2020 10:23:41 +0000
  3. Subject: [PATCH] net: phylink: propagate resolved link config via
  4. mac_link_up()
  5. Propagate the resolved link parameters via the mac_link_up() call for
  6. MACs that do not automatically track their PCS state. We propagate the
  7. link parameters via function arguments so that inappropriate members
  8. of struct phylink_link_state can't be accessed, and creating a new
  9. structure just for this adds needless complexity to the API.
  10. Tested-by: Andre Przywara <[email protected]>
  11. Tested-by: Alexandre Belloni <[email protected]>
  12. Tested-by: Vladimir Oltean <[email protected]>
  13. Signed-off-by: Russell King <[email protected]>
  14. Signed-off-by: David S. Miller <[email protected]>
  15. ---
  16. --- a/Documentation/networking/sfp-phylink.rst
  17. +++ b/Documentation/networking/sfp-phylink.rst
  18. @@ -74,10 +74,13 @@ phylib to the sfp/phylink support. Plea
  19. this documentation.
  20. 1. Optionally split the network driver's phylib update function into
  21. - three parts dealing with link-down, link-up and reconfiguring the
  22. - MAC settings. This can be done as a separate preparation commit.
  23. + two parts dealing with link-down and link-up. This can be done as
  24. + a separate preparation commit.
  25. - An example of this preparation can be found in git commit fc548b991fb0.
  26. + An older example of this preparation can be found in git commit
  27. + fc548b991fb0, although this was splitting into three parts; the
  28. + link-up part now includes configuring the MAC for the link settings.
  29. + Please see :c:func:`mac_link_up` for more information on this.
  30. 2. Replace::
  31. @@ -207,6 +210,14 @@ this documentation.
  32. using. This is particularly important for in-band negotiation
  33. methods such as 1000base-X and SGMII.
  34. + The :c:func:`mac_link_up` method is used to inform the MAC that the
  35. + link has come up. The call includes the negotiation mode and interface
  36. + for reference only. The finalised link parameters are also supplied
  37. + (speed, duplex and flow control/pause enablement settings) which
  38. + should be used to configure the MAC when the MAC and PCS are not
  39. + tightly integrated, or when the settings are not coming from in-band
  40. + negotiation.
  41. +
  42. The :c:func:`mac_config` method is used to update the MAC with the
  43. requested state, and must avoid unnecessarily taking the link down
  44. when making changes to the MAC configuration. This means the
  45. --- a/drivers/net/ethernet/marvell/mvneta.c
  46. +++ b/drivers/net/ethernet/marvell/mvneta.c
  47. @@ -3653,9 +3653,11 @@ static void mvneta_mac_link_down(struct
  48. mvneta_set_eee(pp, false);
  49. }
  50. -static void mvneta_mac_link_up(struct phylink_config *config, unsigned int mode,
  51. - phy_interface_t interface,
  52. - struct phy_device *phy)
  53. +static void mvneta_mac_link_up(struct phylink_config *config,
  54. + struct phy_device *phy,
  55. + unsigned int mode, phy_interface_t interface,
  56. + int speed, int duplex,
  57. + bool tx_pause, bool rx_pause)
  58. {
  59. struct net_device *ndev = to_net_dev(config->dev);
  60. struct mvneta_port *pp = netdev_priv(ndev);
  61. --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
  62. +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
  63. @@ -58,8 +58,11 @@ static struct {
  64. */
  65. static void mvpp2_mac_config(struct phylink_config *config, unsigned int mode,
  66. const struct phylink_link_state *state);
  67. -static void mvpp2_mac_link_up(struct phylink_config *config, unsigned int mode,
  68. - phy_interface_t interface, struct phy_device *phy);
  69. +static void mvpp2_mac_link_up(struct phylink_config *config,
  70. + struct phy_device *phy,
  71. + unsigned int mode, phy_interface_t interface,
  72. + int speed, int duplex,
  73. + bool tx_pause, bool rx_pause);
  74. /* Queue modes */
  75. #define MVPP2_QDIST_SINGLE_MODE 0
  76. @@ -3467,8 +3470,9 @@ static void mvpp2_start_dev(struct mvpp2
  77. .interface = port->phy_interface,
  78. };
  79. mvpp2_mac_config(&port->phylink_config, MLO_AN_INBAND, &state);
  80. - mvpp2_mac_link_up(&port->phylink_config, MLO_AN_INBAND,
  81. - port->phy_interface, NULL);
  82. + mvpp2_mac_link_up(&port->phylink_config, NULL,
  83. + MLO_AN_INBAND, port->phy_interface,
  84. + SPEED_UNKNOWN, DUPLEX_UNKNOWN, false, false);
  85. }
  86. netif_tx_start_all_queues(port->dev);
  87. @@ -5126,8 +5130,11 @@ static void mvpp2_mac_config(struct phyl
  88. mvpp2_port_enable(port);
  89. }
  90. -static void mvpp2_mac_link_up(struct phylink_config *config, unsigned int mode,
  91. - phy_interface_t interface, struct phy_device *phy)
  92. +static void mvpp2_mac_link_up(struct phylink_config *config,
  93. + struct phy_device *phy,
  94. + unsigned int mode, phy_interface_t interface,
  95. + int speed, int duplex,
  96. + bool tx_pause, bool rx_pause)
  97. {
  98. struct mvpp2_port *port = mvpp2_phylink_to_port(config);
  99. u32 val;
  100. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  101. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  102. @@ -449,9 +449,10 @@ static void mtk_mac_link_down(struct phy
  103. mtk_w32(mac->hw, mcr, MTK_MAC_MCR(mac->id));
  104. }
  105. -static void mtk_mac_link_up(struct phylink_config *config, unsigned int mode,
  106. - phy_interface_t interface,
  107. - struct phy_device *phy)
  108. +static void mtk_mac_link_up(struct phylink_config *config,
  109. + struct phy_device *phy,
  110. + unsigned int mode, phy_interface_t interface,
  111. + int speed, int duplex, bool tx_pause, bool rx_pause)
  112. {
  113. struct mtk_mac *mac = container_of(config, struct mtk_mac,
  114. phylink_config);
  115. --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
  116. +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
  117. @@ -925,8 +925,10 @@ static void stmmac_mac_link_down(struct
  118. }
  119. static void stmmac_mac_link_up(struct phylink_config *config,
  120. + struct phy_device *phy,
  121. unsigned int mode, phy_interface_t interface,
  122. - struct phy_device *phy)
  123. + int speed, int duplex,
  124. + bool tx_pause, bool rx_pause)
  125. {
  126. struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev));
  127. --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
  128. +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
  129. @@ -1499,9 +1499,10 @@ static void axienet_mac_link_down(struct
  130. }
  131. static void axienet_mac_link_up(struct phylink_config *config,
  132. - unsigned int mode,
  133. - phy_interface_t interface,
  134. - struct phy_device *phy)
  135. + struct phy_device *phy,
  136. + unsigned int mode, phy_interface_t interface,
  137. + int speed, int duplex,
  138. + bool tx_pause, bool rx_pause)
  139. {
  140. /* nothing meaningful to do */
  141. }
  142. --- a/drivers/net/phy/phylink.c
  143. +++ b/drivers/net/phy/phylink.c
  144. @@ -447,8 +447,11 @@ static void phylink_mac_link_up(struct p
  145. struct net_device *ndev = pl->netdev;
  146. pl->cur_interface = link_state.interface;
  147. - pl->ops->mac_link_up(pl->config, pl->cur_link_an_mode,
  148. - pl->cur_interface, pl->phydev);
  149. + pl->ops->mac_link_up(pl->config, pl->phydev,
  150. + pl->cur_link_an_mode, pl->cur_interface,
  151. + link_state.speed, link_state.duplex,
  152. + !!(link_state.pause & MLO_PAUSE_TX),
  153. + !!(link_state.pause & MLO_PAUSE_RX));
  154. if (ndev)
  155. netif_carrier_on(ndev);
  156. --- a/include/linux/phylink.h
  157. +++ b/include/linux/phylink.h
  158. @@ -91,9 +91,10 @@ struct phylink_mac_ops {
  159. void (*mac_an_restart)(struct phylink_config *config);
  160. void (*mac_link_down)(struct phylink_config *config, unsigned int mode,
  161. phy_interface_t interface);
  162. - void (*mac_link_up)(struct phylink_config *config, unsigned int mode,
  163. - phy_interface_t interface,
  164. - struct phy_device *phy);
  165. + void (*mac_link_up)(struct phylink_config *config,
  166. + struct phy_device *phy, unsigned int mode,
  167. + phy_interface_t interface, int speed, int duplex,
  168. + bool tx_pause, bool rx_pause);
  169. };
  170. #if 0 /* For kernel-doc purposes only. */
  171. @@ -217,19 +218,34 @@ void mac_link_down(struct phylink_config
  172. /**
  173. * mac_link_up() - allow the link to come up
  174. * @config: a pointer to a &struct phylink_config.
  175. + * @phy: any attached phy
  176. * @mode: link autonegotiation mode
  177. * @interface: link &typedef phy_interface_t mode
  178. - * @phy: any attached phy
  179. + * @speed: link speed
  180. + * @duplex: link duplex
  181. + * @tx_pause: link transmit pause enablement status
  182. + * @rx_pause: link receive pause enablement status
  183. + *
  184. + * Configure the MAC for an established link.
  185. + *
  186. + * @speed, @duplex, @tx_pause and @rx_pause indicate the finalised link
  187. + * settings, and should be used to configure the MAC block appropriately
  188. + * where these settings are not automatically conveyed from the PCS block,
  189. + * or if in-band negotiation (as defined by phylink_autoneg_inband(@mode))
  190. + * is disabled.
  191. + *
  192. + * Note that when 802.3z in-band negotiation is in use, it is possible
  193. + * that the user wishes to override the pause settings, and this should
  194. + * be allowed when considering the implementation of this method.
  195. *
  196. - * If @mode is not an in-band negotiation mode (as defined by
  197. - * phylink_autoneg_inband()), allow the link to come up. If @phy
  198. - * is non-%NULL, configure Energy Efficient Ethernet by calling
  199. + * If in-band negotiation mode is disabled, allow the link to come up. If
  200. + * @phy is non-%NULL, configure Energy Efficient Ethernet by calling
  201. * phy_init_eee() and perform appropriate MAC configuration for EEE.
  202. * Interface type selection must be done in mac_config().
  203. */
  204. -void mac_link_up(struct phylink_config *config, unsigned int mode,
  205. - phy_interface_t interface,
  206. - struct phy_device *phy);
  207. +void mac_link_up(struct phylink_config *config, struct phy_device *phy,
  208. + unsigned int mode, phy_interface_t interface,
  209. + int speed, int duplex, bool tx_pause, bool rx_pause);
  210. #endif
  211. struct phylink *phylink_create(struct phylink_config *, struct fwnode_handle *,
  212. --- a/net/dsa/port.c
  213. +++ b/net/dsa/port.c
  214. @@ -529,9 +529,11 @@ void dsa_port_phylink_mac_link_down(stru
  215. EXPORT_SYMBOL_GPL(dsa_port_phylink_mac_link_down);
  216. void dsa_port_phylink_mac_link_up(struct phylink_config *config,
  217. + struct phy_device *phydev,
  218. unsigned int mode,
  219. phy_interface_t interface,
  220. - struct phy_device *phydev)
  221. + int speed, int duplex,
  222. + bool tx_pause, bool rx_pause)
  223. {
  224. struct dsa_port *dp = container_of(config, struct dsa_port, pl_config);
  225. struct dsa_switch *ds = dp->ds;