705-02-v5.19-net-dsa-mt7530-populate-supported_interfaces-and-mac.patch 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. From a1da54bcd664fc27169386db966575675ac3ccb0 Mon Sep 17 00:00:00 2001
  2. From: "Russell King (Oracle)" <[email protected]>
  3. Date: Mon, 11 Apr 2022 10:46:01 +0100
  4. Subject: [PATCH 02/13] net: dsa: mt7530: populate supported_interfaces and
  5. mac_capabilities
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. Populate the supported interfaces and MAC capabilities for mt7530,
  10. mt7531 and mt7621 DSA switches. Filling this in will enable phylink
  11. to pre-check the PHY interface mode against the the supported
  12. interfaces bitmap prior to calling the validate function, and will
  13. eventually allow us to convert to using the generic validation.
  14. Tested-by: Marek Behún <[email protected]>
  15. Signed-off-by: Russell King (Oracle) <[email protected]>
  16. Signed-off-by: Paolo Abeni <[email protected]>
  17. ---
  18. drivers/net/dsa/mt7530.c | 74 ++++++++++++++++++++++++++++++++++++++++
  19. drivers/net/dsa/mt7530.h | 2 ++
  20. 2 files changed, 76 insertions(+)
  21. --- a/drivers/net/dsa/mt7530.c
  22. +++ b/drivers/net/dsa/mt7530.c
  23. @@ -2499,6 +2499,32 @@ mt7531_setup(struct dsa_switch *ds)
  24. return 0;
  25. }
  26. +static void mt7530_mac_port_get_caps(struct dsa_switch *ds, int port,
  27. + struct phylink_config *config)
  28. +{
  29. + switch (port) {
  30. + case 0 ... 4: /* Internal phy */
  31. + __set_bit(PHY_INTERFACE_MODE_GMII,
  32. + config->supported_interfaces);
  33. + break;
  34. +
  35. + case 5: /* 2nd cpu port with phy of port 0 or 4 / external phy */
  36. + phy_interface_set_rgmii(config->supported_interfaces);
  37. + __set_bit(PHY_INTERFACE_MODE_MII,
  38. + config->supported_interfaces);
  39. + __set_bit(PHY_INTERFACE_MODE_GMII,
  40. + config->supported_interfaces);
  41. + break;
  42. +
  43. + case 6: /* 1st cpu port */
  44. + __set_bit(PHY_INTERFACE_MODE_RGMII,
  45. + config->supported_interfaces);
  46. + __set_bit(PHY_INTERFACE_MODE_TRGMII,
  47. + config->supported_interfaces);
  48. + break;
  49. + }
  50. +}
  51. +
  52. static bool
  53. mt7530_phy_mode_supported(struct dsa_switch *ds, int port,
  54. const struct phylink_link_state *state)
  55. @@ -2535,6 +2561,37 @@ static bool mt7531_is_rgmii_port(struct
  56. return (port == 5) && (priv->p5_intf_sel != P5_INTF_SEL_GMAC5_SGMII);
  57. }
  58. +static void mt7531_mac_port_get_caps(struct dsa_switch *ds, int port,
  59. + struct phylink_config *config)
  60. +{
  61. + struct mt7530_priv *priv = ds->priv;
  62. +
  63. + switch (port) {
  64. + case 0 ... 4: /* Internal phy */
  65. + __set_bit(PHY_INTERFACE_MODE_GMII,
  66. + config->supported_interfaces);
  67. + break;
  68. +
  69. + case 5: /* 2nd cpu port supports either rgmii or sgmii/8023z */
  70. + if (mt7531_is_rgmii_port(priv, port)) {
  71. + phy_interface_set_rgmii(config->supported_interfaces);
  72. + break;
  73. + }
  74. + fallthrough;
  75. +
  76. + case 6: /* 1st cpu port supports sgmii/8023z only */
  77. + __set_bit(PHY_INTERFACE_MODE_SGMII,
  78. + config->supported_interfaces);
  79. + __set_bit(PHY_INTERFACE_MODE_1000BASEX,
  80. + config->supported_interfaces);
  81. + __set_bit(PHY_INTERFACE_MODE_2500BASEX,
  82. + config->supported_interfaces);
  83. +
  84. + config->mac_capabilities |= MAC_2500FD;
  85. + break;
  86. + }
  87. +}
  88. +
  89. static bool
  90. mt7531_phy_mode_supported(struct dsa_switch *ds, int port,
  91. const struct phylink_link_state *state)
  92. @@ -3011,6 +3068,18 @@ mt7531_cpu_port_config(struct dsa_switch
  93. return 0;
  94. }
  95. +static void mt753x_phylink_get_caps(struct dsa_switch *ds, int port,
  96. + struct phylink_config *config)
  97. +{
  98. + struct mt7530_priv *priv = ds->priv;
  99. +
  100. + /* This switch only supports full-duplex at 1Gbps */
  101. + config->mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
  102. + MAC_10 | MAC_100 | MAC_1000FD;
  103. +
  104. + priv->info->mac_port_get_caps(ds, port, config);
  105. +}
  106. +
  107. static void
  108. mt7530_mac_port_validate(struct dsa_switch *ds, int port,
  109. unsigned long *supported)
  110. @@ -3246,6 +3315,7 @@ static const struct dsa_switch_ops mt753
  111. .port_vlan_del = mt7530_port_vlan_del,
  112. .port_mirror_add = mt753x_port_mirror_add,
  113. .port_mirror_del = mt753x_port_mirror_del,
  114. + .phylink_get_caps = mt753x_phylink_get_caps,
  115. .phylink_validate = mt753x_phylink_validate,
  116. .phylink_mac_link_state = mt753x_phylink_mac_link_state,
  117. .phylink_mac_config = mt753x_phylink_mac_config,
  118. @@ -3263,6 +3333,7 @@ static const struct mt753x_info mt753x_t
  119. .phy_read = mt7530_phy_read,
  120. .phy_write = mt7530_phy_write,
  121. .pad_setup = mt7530_pad_clk_setup,
  122. + .mac_port_get_caps = mt7530_mac_port_get_caps,
  123. .phy_mode_supported = mt7530_phy_mode_supported,
  124. .mac_port_validate = mt7530_mac_port_validate,
  125. .mac_port_get_state = mt7530_phylink_mac_link_state,
  126. @@ -3274,6 +3345,7 @@ static const struct mt753x_info mt753x_t
  127. .phy_read = mt7530_phy_read,
  128. .phy_write = mt7530_phy_write,
  129. .pad_setup = mt7530_pad_clk_setup,
  130. + .mac_port_get_caps = mt7530_mac_port_get_caps,
  131. .phy_mode_supported = mt7530_phy_mode_supported,
  132. .mac_port_validate = mt7530_mac_port_validate,
  133. .mac_port_get_state = mt7530_phylink_mac_link_state,
  134. @@ -3286,6 +3358,7 @@ static const struct mt753x_info mt753x_t
  135. .phy_write = mt7531_ind_phy_write,
  136. .pad_setup = mt7531_pad_setup,
  137. .cpu_port_config = mt7531_cpu_port_config,
  138. + .mac_port_get_caps = mt7531_mac_port_get_caps,
  139. .phy_mode_supported = mt7531_phy_mode_supported,
  140. .mac_port_validate = mt7531_mac_port_validate,
  141. .mac_port_get_state = mt7531_phylink_mac_link_state,
  142. @@ -3348,6 +3421,7 @@ mt7530_probe(struct mdio_device *mdiodev
  143. */
  144. if (!priv->info->sw_setup || !priv->info->pad_setup ||
  145. !priv->info->phy_read || !priv->info->phy_write ||
  146. + !priv->info->mac_port_get_caps ||
  147. !priv->info->phy_mode_supported ||
  148. !priv->info->mac_port_validate ||
  149. !priv->info->mac_port_get_state || !priv->info->mac_port_config)
  150. --- a/drivers/net/dsa/mt7530.h
  151. +++ b/drivers/net/dsa/mt7530.h
  152. @@ -796,6 +796,8 @@ struct mt753x_info {
  153. int (*phy_write)(struct mt7530_priv *priv, int port, int regnum, u16 val);
  154. int (*pad_setup)(struct dsa_switch *ds, phy_interface_t interface);
  155. int (*cpu_port_config)(struct dsa_switch *ds, int port);
  156. + void (*mac_port_get_caps)(struct dsa_switch *ds, int port,
  157. + struct phylink_config *config);
  158. bool (*phy_mode_supported)(struct dsa_switch *ds, int port,
  159. const struct phylink_link_state *state);
  160. void (*mac_port_validate)(struct dsa_switch *ds, int port,