770-v5.15-net-dsa-mt7530-support-MDB-operations.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. From 1f11a07a33bc26997c18b633d63f088bf75d11f2 Mon Sep 17 00:00:00 2001
  2. From: DENG Qingfang <[email protected]>
  3. Date: Tue, 24 Aug 2021 11:37:50 +0800
  4. Subject: [PATCH] net: dsa: mt7530: support MDB operations
  5. This is a partial backport of commit 5a30833b9a16f8d1aa15de06636f9317ca51f9df
  6. ("net: dsa: mt7530: support MDB and bridge flag operations") upstream.
  7. Signed-off-by: DENG Qingfang <[email protected]>
  8. ---
  9. drivers/net/dsa/mt7530.c | 78 ++++++++++++++++++++++++++++++++++++++--
  10. net/dsa/tag_mtk.c | 14 +-------
  11. 2 files changed, 76 insertions(+), 16 deletions(-)
  12. --- a/drivers/net/dsa/mt7530.c
  13. +++ b/drivers/net/dsa/mt7530.c
  14. @@ -1001,9 +1001,6 @@ mt753x_cpu_port_enable(struct dsa_switch
  15. mt7530_write(priv, MT7530_PVC_P(port),
  16. PORT_SPEC_TAG);
  17. - /* Unknown multicast frame forwarding to the cpu port */
  18. - mt7530_rmw(priv, MT7530_MFC, UNM_FFP_MASK, UNM_FFP(BIT(port)));
  19. -
  20. /* Set CPU port number */
  21. if (priv->id == ID_MT7621)
  22. mt7530_rmw(priv, MT7530_MFC, CPU_MASK, CPU_EN | CPU_PORT(port));
  23. @@ -1134,6 +1131,20 @@ mt7530_stp_state_set(struct dsa_switch *
  24. }
  25. static int
  26. +mt7530_port_egress_floods(struct dsa_switch *ds, int port,
  27. + bool unicast, bool multicast)
  28. +{
  29. + struct mt7530_priv *priv = ds->priv;
  30. +
  31. + mt7530_rmw(priv, MT7530_MFC,
  32. + UNU_FFP(BIT(port)) | UNM_FFP(BIT(port)),
  33. + (unicast ? UNU_FFP(BIT(port)) : 0) |
  34. + (multicast ? UNM_FFP(BIT(port)) : 0));
  35. +
  36. + return 0;
  37. +}
  38. +
  39. +static int
  40. mt7530_port_bridge_join(struct dsa_switch *ds, int port,
  41. struct net_device *bridge)
  42. {
  43. @@ -1334,6 +1345,63 @@ err:
  44. }
  45. static int
  46. +mt7530_port_mdb_prepare(struct dsa_switch *ds, int port,
  47. + const struct switchdev_obj_port_mdb *mdb)
  48. +{
  49. + return 0;
  50. +}
  51. +
  52. +static void
  53. +mt7530_port_mdb_add(struct dsa_switch *ds, int port,
  54. + const struct switchdev_obj_port_mdb *mdb)
  55. +{
  56. + struct mt7530_priv *priv = ds->priv;
  57. + const u8 *addr = mdb->addr;
  58. + u16 vid = mdb->vid;
  59. + u8 port_mask = 0;
  60. +
  61. + mutex_lock(&priv->reg_mutex);
  62. +
  63. + mt7530_fdb_write(priv, vid, 0, addr, 0, STATIC_EMP);
  64. + if (!mt7530_fdb_cmd(priv, MT7530_FDB_READ, NULL))
  65. + port_mask = (mt7530_read(priv, MT7530_ATRD) >> PORT_MAP)
  66. + & PORT_MAP_MASK;
  67. +
  68. + port_mask |= BIT(port);
  69. + mt7530_fdb_write(priv, vid, port_mask, addr, -1, STATIC_ENT);
  70. + mt7530_fdb_cmd(priv, MT7530_FDB_WRITE, NULL);
  71. +
  72. + mutex_unlock(&priv->reg_mutex);
  73. +}
  74. +
  75. +static int
  76. +mt7530_port_mdb_del(struct dsa_switch *ds, int port,
  77. + const struct switchdev_obj_port_mdb *mdb)
  78. +{
  79. + struct mt7530_priv *priv = ds->priv;
  80. + const u8 *addr = mdb->addr;
  81. + u16 vid = mdb->vid;
  82. + u8 port_mask = 0;
  83. + int ret;
  84. +
  85. + mutex_lock(&priv->reg_mutex);
  86. +
  87. + mt7530_fdb_write(priv, vid, 0, addr, 0, STATIC_EMP);
  88. + if (!mt7530_fdb_cmd(priv, MT7530_FDB_READ, NULL))
  89. + port_mask = (mt7530_read(priv, MT7530_ATRD) >> PORT_MAP)
  90. + & PORT_MAP_MASK;
  91. +
  92. + port_mask &= ~BIT(port);
  93. + mt7530_fdb_write(priv, vid, port_mask, addr, -1,
  94. + port_mask ? STATIC_ENT : STATIC_EMP);
  95. + ret = mt7530_fdb_cmd(priv, MT7530_FDB_WRITE, NULL);
  96. +
  97. + mutex_unlock(&priv->reg_mutex);
  98. +
  99. + return ret;
  100. +}
  101. +
  102. +static int
  103. mt7530_vlan_cmd(struct mt7530_priv *priv, enum mt7530_vlan_cmd cmd, u16 vid)
  104. {
  105. struct mt7530_dummy_poll p;
  106. @@ -2743,11 +2811,15 @@ static const struct dsa_switch_ops mt753
  107. .port_change_mtu = mt7530_port_change_mtu,
  108. .port_max_mtu = mt7530_port_max_mtu,
  109. .port_stp_state_set = mt7530_stp_state_set,
  110. + .port_egress_floods = mt7530_port_egress_floods,
  111. .port_bridge_join = mt7530_port_bridge_join,
  112. .port_bridge_leave = mt7530_port_bridge_leave,
  113. .port_fdb_add = mt7530_port_fdb_add,
  114. .port_fdb_del = mt7530_port_fdb_del,
  115. .port_fdb_dump = mt7530_port_fdb_dump,
  116. + .port_mdb_prepare = mt7530_port_mdb_prepare,
  117. + .port_mdb_add = mt7530_port_mdb_add,
  118. + .port_mdb_del = mt7530_port_mdb_del,
  119. .port_vlan_filtering = mt7530_port_vlan_filtering,
  120. .port_vlan_prepare = mt7530_port_vlan_prepare,
  121. .port_vlan_add = mt7530_port_vlan_add,
  122. --- a/net/dsa/tag_mtk.c
  123. +++ b/net/dsa/tag_mtk.c
  124. @@ -24,9 +24,6 @@ static struct sk_buff *mtk_tag_xmit(stru
  125. struct dsa_port *dp = dsa_slave_to_port(dev);
  126. u8 xmit_tpid;
  127. u8 *mtk_tag;
  128. - unsigned char *dest = eth_hdr(skb)->h_dest;
  129. - bool is_multicast_skb = is_multicast_ether_addr(dest) &&
  130. - !is_broadcast_ether_addr(dest);
  131. /* Build the special tag after the MAC Source Address. If VLAN header
  132. * is present, it's required that VLAN header and special tag is
  133. @@ -55,10 +52,6 @@ static struct sk_buff *mtk_tag_xmit(stru
  134. mtk_tag[0] = xmit_tpid;
  135. mtk_tag[1] = (1 << dp->index) & MTK_HDR_XMIT_DP_BIT_MASK;
  136. - /* Disable SA learning for multicast frames */
  137. - if (unlikely(is_multicast_skb))
  138. - mtk_tag[1] |= MTK_HDR_XMIT_SA_DIS;
  139. -
  140. /* Tag control information is kept for 802.1Q */
  141. if (xmit_tpid == MTK_HDR_XMIT_UNTAGGED) {
  142. mtk_tag[2] = 0;
  143. @@ -74,9 +67,6 @@ static struct sk_buff *mtk_tag_rcv(struc
  144. u16 hdr;
  145. int port;
  146. __be16 *phdr;
  147. - unsigned char *dest = eth_hdr(skb)->h_dest;
  148. - bool is_multicast_skb = is_multicast_ether_addr(dest) &&
  149. - !is_broadcast_ether_addr(dest);
  150. if (unlikely(!pskb_may_pull(skb, MTK_HDR_LEN)))
  151. return NULL;
  152. @@ -102,9 +92,7 @@ static struct sk_buff *mtk_tag_rcv(struc
  153. if (!skb->dev)
  154. return NULL;
  155. - /* Only unicast or broadcast frames are offloaded */
  156. - if (likely(!is_multicast_skb))
  157. - dsa_default_offload_fwd_mark(skb);
  158. + dsa_default_offload_fwd_mark(skb);
  159. return skb;
  160. }