blob: 5bfbd835762d6967a6d033c9949acdf3d8e13571 [file] [log] [blame]
developerd5c8ff12023-03-28 11:56:21 +08001From 5b031e66dae802df853596a99c1ce73ad7761d09 Mon Sep 17 00:00:00 2001
2From: Sujuan Chen <sujuan.chen@mediatek.com>
3Date: Tue, 28 Mar 2023 10:53:31 +0800
4Subject: [PATCH] mac80211: mtk: add support for letting drivers register tc
5 offload support
6
7On newer MediaTek SoCs (e.g. MT7986), WLAN->WLAN or WLAN->Ethernet flows can
8be offloaded by the SoC. In order to support that, the .ndo_setup_tc op is
9needed.
10
11Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com>
12---
13 include/net/mac80211.h | 9 +++++++++
14 net/mac80211/driver-ops.h | 17 +++++++++++++++++
15 net/mac80211/ieee80211_i.h | 3 ++-
16 net/mac80211/iface.c | 17 +++++++++++++++++
17 net/mac80211/trace.h | 25 +++++++++++++++++++++++++
18 5 files changed, 70 insertions(+), 1 deletion(-)
19
20diff --git a/include/net/mac80211.h b/include/net/mac80211.h
21index cb1d544..2d998be 100755
22--- a/include/net/mac80211.h
23+++ b/include/net/mac80211.h
24@@ -3980,6 +3980,10 @@ struct ieee80211_prep_tx_info {
25 * resolve a path for hardware flow offloading
26 * @net_fill_receive_path: Called from .ndo_fill_receive_path in order to
27 * get a path for hardware flow offloading
28+ * @net_setup_tc: Called from .ndo_setup_tc in order to prepare hardware
29+ * flow offloading for flows originating from the vif.
30+ * Note that the driver must not assume that the vif driver_data is valid
31+ * at this point, since the callback can be called during netdev teardown.
32 */
33 struct ieee80211_ops {
34 void (*tx)(struct ieee80211_hw *hw,
35@@ -4318,6 +4322,11 @@ struct ieee80211_ops {
36 int (*net_fill_receive_path)(struct ieee80211_hw *hw,
37 struct net_device_path_ctx *ctx,
38 struct net_device_path *path);
39+ int (*net_setup_tc)(struct ieee80211_hw *hw,
40+ struct ieee80211_vif *vif,
41+ struct net_device *dev,
42+ enum tc_setup_type type,
43+ void *type_data);
44 };
45
46 /**
47diff --git a/net/mac80211/driver-ops.h b/net/mac80211/driver-ops.h
48index 27da75e..79f408f 100644
49--- a/net/mac80211/driver-ops.h
50+++ b/net/mac80211/driver-ops.h
51@@ -1521,4 +1521,21 @@ static inline int drv_net_fill_receive_path(struct ieee80211_local *local,
52 return ret;
53 }
54
55+static inline int drv_net_setup_tc(struct ieee80211_local *local,
56+ struct ieee80211_sub_if_data *sdata,
57+ struct net_device *dev,
58+ enum tc_setup_type type, void *type_data)
59+{
60+ int ret = -EOPNOTSUPP;
61+
62+ sdata = get_bss_sdata(sdata);
63+ trace_drv_net_setup_tc(local, sdata, type);
64+ if (local->ops->net_setup_tc)
65+ ret = local->ops->net_setup_tc(&local->hw, &sdata->vif, dev,
66+ type, type_data);
67+ trace_drv_return_int(local, ret);
68+
69+ return ret;
70+}
71+
72 #endif /* __MAC80211_DRIVER_OPS */
73diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
74index 2519c14..fe7a03a 100644
75--- a/net/mac80211/ieee80211_i.h
76+++ b/net/mac80211/ieee80211_i.h
77@@ -1822,7 +1822,8 @@ void ieee80211_color_aging_work(struct work_struct *work);
78 /* interface handling */
79 #define MAC80211_SUPPORTED_FEATURES_TX (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | \
80 NETIF_F_HW_CSUM | NETIF_F_SG | \
81- NETIF_F_HIGHDMA | NETIF_F_GSO_SOFTWARE)
82+ NETIF_F_HIGHDMA | NETIF_F_GSO_SOFTWARE | \
83+ NETIF_F_HW_TC)
84 #define MAC80211_SUPPORTED_FEATURES_RX (NETIF_F_RXCSUM)
85 #define MAC80211_SUPPORTED_FEATURES (MAC80211_SUPPORTED_FEATURES_TX | \
86 MAC80211_SUPPORTED_FEATURES_RX)
87diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
88index 8a4f4e1..f3bf837 100644
89--- a/net/mac80211/iface.c
90+++ b/net/mac80211/iface.c
91@@ -773,6 +773,21 @@ static int __change_mtu(struct net_device *ndev, int new_mtu){
92 }
93 #endif
94
95+static int ieee80211_netdev_setup_tc(struct net_device *dev,
96+ enum tc_setup_type type, void *type_data)
97+{
98+ struct ieee80211_sub_if_data *sdata;
99+ struct ieee80211_local *local;
100+
101+ sdata = IEEE80211_DEV_TO_SUB_IF(dev);
102+ local = sdata->local;
103+
104+ if (!local->ops->net_setup_tc)
105+ return -EOPNOTSUPP;
106+
107+ return drv_net_setup_tc(local, sdata, dev, type, type_data);
108+}
109+
110 static const struct net_device_ops ieee80211_dataif_ops = {
111 #if LINUX_VERSION_IS_LESS(4,10,0)
112 .ndo_change_mtu = __change_mtu,
113@@ -790,6 +805,7 @@ static const struct net_device_ops ieee80211_dataif_ops = {
114 #else
115 .ndo_get_stats64 = bp_ieee80211_get_stats64,
116 #endif
117+ .ndo_setup_tc = ieee80211_netdev_setup_tc,
118
119 };
120
121@@ -953,6 +969,7 @@ static const struct net_device_ops ieee80211_dataif_8023_ops = {
122 #endif
123 .ndo_fill_forward_path = ieee80211_netdev_fill_forward_path,
124 .ndo_fill_receive_path = ieee80211_netdev_fill_receive_path,
125+ .ndo_setup_tc = ieee80211_netdev_setup_tc,
126 };
127
128 static bool ieee80211_iftype_supports_hdr_offload(enum nl80211_iftype iftype)
129diff --git a/net/mac80211/trace.h b/net/mac80211/trace.h
130index 737ab86..25d3e30 100644
131--- a/net/mac80211/trace.h
132+++ b/net/mac80211/trace.h
133@@ -2899,6 +2899,31 @@ DEFINE_EVENT(sta_event, drv_net_fill_forward_path,
134 TP_ARGS(local, sdata, sta)
135 );
136
137+TRACE_EVENT(drv_net_setup_tc,
138+ TP_PROTO(struct ieee80211_local *local,
139+ struct ieee80211_sub_if_data *sdata,
140+ u8 type),
141+
142+ TP_ARGS(local, sdata, type),
143+
144+ TP_STRUCT__entry(
145+ LOCAL_ENTRY
146+ VIF_ENTRY
147+ __field(u8, type)
148+ ),
149+
150+ TP_fast_assign(
151+ LOCAL_ASSIGN;
152+ VIF_ASSIGN;
153+ __entry->type = type;
154+ ),
155+
156+ TP_printk(
157+ LOCAL_PR_FMT VIF_PR_FMT " type:%d\n",
158+ LOCAL_PR_ARG, VIF_PR_ARG, __entry->type
159+ )
160+);
161+
162 TRACE_EVENT(bss_color_bitmap,
163 TP_PROTO(u8 color,
164 u64 color_bitmap),
165--
1662.18.0
167