730-09-v6.3-net-ethernet-mtk_eth_soc-fix-VLAN-rx-hardware-accele.patch 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. From: Felix Fietkau <[email protected]>
  2. Date: Fri, 28 Oct 2022 11:01:12 +0200
  3. Subject: [PATCH] net: ethernet: mtk_eth_soc: fix VLAN rx hardware
  4. acceleration
  5. - enable VLAN untagging for PDMA rx
  6. - make it possible to disable the feature via ethtool
  7. - pass VLAN tag to the DSA driver
  8. - untag special tag on PDMA only if no non-DSA devices are in use
  9. - disable special tag untagging on 7986 for now, since it's not working yet
  10. Signed-off-by: Felix Fietkau <[email protected]>
  11. ---
  12. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  13. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  14. @@ -23,6 +23,7 @@
  15. #include <linux/jhash.h>
  16. #include <linux/bitfield.h>
  17. #include <net/dsa.h>
  18. +#include <net/dst_metadata.h>
  19. #include "mtk_eth_soc.h"
  20. #include "mtk_wed.h"
  21. @@ -1973,16 +1974,22 @@ static int mtk_poll_rx(struct napi_struc
  22. htons(RX_DMA_VPID(trxd.rxd4)),
  23. RX_DMA_VID(trxd.rxd4));
  24. } else if (trxd.rxd2 & RX_DMA_VTAG) {
  25. - __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
  26. + __vlan_hwaccel_put_tag(skb, htons(RX_DMA_VPID(trxd.rxd3)),
  27. RX_DMA_VID(trxd.rxd3));
  28. }
  29. + }
  30. +
  31. + /* When using VLAN untagging in combination with DSA, the
  32. + * hardware treats the MTK special tag as a VLAN and untags it.
  33. + */
  34. + if (skb_vlan_tag_present(skb) && netdev_uses_dsa(netdev)) {
  35. + unsigned int port = ntohs(skb->vlan_proto) & GENMASK(2, 0);
  36. - /* If the device is attached to a dsa switch, the special
  37. - * tag inserted in VLAN field by hw switch can * be offloaded
  38. - * by RX HW VLAN offload. Clear vlan info.
  39. - */
  40. - if (netdev_uses_dsa(netdev))
  41. - __vlan_hwaccel_clear_tag(skb);
  42. + if (port < ARRAY_SIZE(eth->dsa_meta) &&
  43. + eth->dsa_meta[port])
  44. + skb_dst_set_noref(skb, &eth->dsa_meta[port]->dst);
  45. +
  46. + __vlan_hwaccel_clear_tag(skb);
  47. }
  48. skb_record_rx_queue(skb, 0);
  49. @@ -2802,15 +2809,30 @@ static netdev_features_t mtk_fix_feature
  50. static int mtk_set_features(struct net_device *dev, netdev_features_t features)
  51. {
  52. - int err = 0;
  53. + struct mtk_mac *mac = netdev_priv(dev);
  54. + struct mtk_eth *eth = mac->hw;
  55. + netdev_features_t diff = dev->features ^ features;
  56. + int i;
  57. +
  58. + if ((diff & NETIF_F_LRO) && !(features & NETIF_F_LRO))
  59. + mtk_hwlro_netdev_disable(dev);
  60. - if (!((dev->features ^ features) & NETIF_F_LRO))
  61. + /* Set RX VLAN offloading */
  62. + if (!(diff & NETIF_F_HW_VLAN_CTAG_RX))
  63. return 0;
  64. - if (!(features & NETIF_F_LRO))
  65. - mtk_hwlro_netdev_disable(dev);
  66. + mtk_w32(eth, !!(features & NETIF_F_HW_VLAN_CTAG_RX),
  67. + MTK_CDMP_EG_CTRL);
  68. - return err;
  69. + /* sync features with other MAC */
  70. + for (i = 0; i < MTK_MAC_COUNT; i++) {
  71. + if (!eth->netdev[i] || eth->netdev[i] == dev)
  72. + continue;
  73. + eth->netdev[i]->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
  74. + eth->netdev[i]->features |= features & NETIF_F_HW_VLAN_CTAG_RX;
  75. + }
  76. +
  77. + return 0;
  78. }
  79. /* wait for DMA to finish whatever it is doing before we start using it again */
  80. @@ -3107,11 +3129,45 @@ found:
  81. return NOTIFY_DONE;
  82. }
  83. +static bool mtk_uses_dsa(struct net_device *dev)
  84. +{
  85. +#if IS_ENABLED(CONFIG_NET_DSA)
  86. + return netdev_uses_dsa(dev) &&
  87. + dev->dsa_ptr->tag_ops->proto == DSA_TAG_PROTO_MTK;
  88. +#else
  89. + return false;
  90. +#endif
  91. +}
  92. +
  93. static int mtk_open(struct net_device *dev)
  94. {
  95. struct mtk_mac *mac = netdev_priv(dev);
  96. struct mtk_eth *eth = mac->hw;
  97. - int err;
  98. + int i, err;
  99. +
  100. + if (mtk_uses_dsa(dev) && !eth->prog) {
  101. + for (i = 0; i < ARRAY_SIZE(eth->dsa_meta); i++) {
  102. + struct metadata_dst *md_dst = eth->dsa_meta[i];
  103. +
  104. + if (md_dst)
  105. + continue;
  106. +
  107. + md_dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX,
  108. + GFP_KERNEL);
  109. + if (!md_dst)
  110. + return -ENOMEM;
  111. +
  112. + md_dst->u.port_info.port_id = i;
  113. + eth->dsa_meta[i] = md_dst;
  114. + }
  115. + } else {
  116. + /* Hardware special tag parsing needs to be disabled if at least
  117. + * one MAC does not use DSA.
  118. + */
  119. + u32 val = mtk_r32(eth, MTK_CDMP_IG_CTRL);
  120. + val &= ~MTK_CDMP_STAG_EN;
  121. + mtk_w32(eth, val, MTK_CDMP_IG_CTRL);
  122. + }
  123. err = phylink_of_phy_connect(mac->phylink, mac->of_node, 0);
  124. if (err) {
  125. @@ -3634,6 +3690,10 @@ static int mtk_hw_init(struct mtk_eth *e
  126. */
  127. val = mtk_r32(eth, MTK_CDMQ_IG_CTRL);
  128. mtk_w32(eth, val | MTK_CDMQ_STAG_EN, MTK_CDMQ_IG_CTRL);
  129. + if (!MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
  130. + val = mtk_r32(eth, MTK_CDMP_IG_CTRL);
  131. + mtk_w32(eth, val | MTK_CDMP_STAG_EN, MTK_CDMP_IG_CTRL);
  132. + }
  133. /* Enable RX VLan Offloading */
  134. mtk_w32(eth, 1, MTK_CDMP_EG_CTRL);
  135. @@ -3850,6 +3910,12 @@ static int mtk_free_dev(struct mtk_eth *
  136. free_netdev(eth->netdev[i]);
  137. }
  138. + for (i = 0; i < ARRAY_SIZE(eth->dsa_meta); i++) {
  139. + if (!eth->dsa_meta[i])
  140. + break;
  141. + metadata_dst_free(eth->dsa_meta[i]);
  142. + }
  143. +
  144. return 0;
  145. }
  146. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  147. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  148. @@ -22,6 +22,9 @@
  149. #include <linux/bpf_trace.h>
  150. #include "mtk_ppe.h"
  151. +#define MTK_MAX_DSA_PORTS 7
  152. +#define MTK_DSA_PORT_MASK GENMASK(2, 0)
  153. +
  154. #define MTK_QDMA_NUM_QUEUES 16
  155. #define MTK_QDMA_PAGE_SIZE 2048
  156. #define MTK_MAX_RX_LENGTH 1536
  157. @@ -105,6 +108,9 @@
  158. #define MTK_CDMQ_IG_CTRL 0x1400
  159. #define MTK_CDMQ_STAG_EN BIT(0)
  160. +/* CDMQ Exgress Control Register */
  161. +#define MTK_CDMQ_EG_CTRL 0x1404
  162. +
  163. /* CDMP Ingress Control Register */
  164. #define MTK_CDMP_IG_CTRL 0x400
  165. #define MTK_CDMP_STAG_EN BIT(0)
  166. @@ -1160,6 +1166,8 @@ struct mtk_eth {
  167. int ip_align;
  168. + struct metadata_dst *dsa_meta[MTK_MAX_DSA_PORTS];
  169. +
  170. struct mtk_ppe *ppe[2];
  171. struct rhashtable flow_table;