mac80211: backport support for ndo_fill_forward_path
[openwrt/staging/chunkeey.git] / package / kernel / mac80211 / patches / subsys / 330-mac80211-add-support-for-.ndo_fill_forward_path.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Fri, 12 Nov 2021 12:22:23 +0100
3 Subject: [PATCH] mac80211: add support for .ndo_fill_forward_path
4
5 This allows drivers to provide a destination device + info for flow offload
6 Only supported in combination with 802.3 encap offload
7
8 Signed-off-by: Felix Fietkau <nbd@nbd.name>
9 Tested-by: Lorenzo Bianconi <lorenzo@kernel.org>
10 Link: https://lore.kernel.org/r/20211112112223.1209-1-nbd@nbd.name
11 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
12 ---
13
14 --- a/include/net/mac80211.h
15 +++ b/include/net/mac80211.h
16 @@ -3937,6 +3937,8 @@ struct ieee80211_prep_tx_info {
17 * twt structure.
18 * @twt_teardown_request: Update the hw with TWT teardown request received
19 * from the peer.
20 + * @net_fill_forward_path: Called from .ndo_fill_forward_path in order to
21 + * resolve a path for hardware flow offloading
22 */
23 struct ieee80211_ops {
24 void (*tx)(struct ieee80211_hw *hw,
25 @@ -4265,6 +4267,11 @@ struct ieee80211_ops {
26 struct ieee80211_twt_setup *twt);
27 void (*twt_teardown_request)(struct ieee80211_hw *hw,
28 struct ieee80211_sta *sta, u8 flowid);
29 + int (*net_fill_forward_path)(struct ieee80211_hw *hw,
30 + struct ieee80211_vif *vif,
31 + struct ieee80211_sta *sta,
32 + struct net_device_path_ctx *ctx,
33 + struct net_device_path *path);
34 };
35
36 /**
37 --- a/net/mac80211/driver-ops.h
38 +++ b/net/mac80211/driver-ops.h
39 @@ -1483,4 +1483,26 @@ static inline void drv_twt_teardown_requ
40 trace_drv_return_void(local);
41 }
42
43 +static inline int drv_net_fill_forward_path(struct ieee80211_local *local,
44 + struct ieee80211_sub_if_data *sdata,
45 + struct ieee80211_sta *sta,
46 + struct net_device_path_ctx *ctx,
47 + struct net_device_path *path)
48 +{
49 + int ret = -EOPNOTSUPP;
50 +
51 + sdata = get_bss_sdata(sdata);
52 + if (!check_sdata_in_driver(sdata))
53 + return -EIO;
54 +
55 + trace_drv_net_fill_forward_path(local, sdata, sta);
56 + if (local->ops->net_fill_forward_path)
57 + ret = local->ops->net_fill_forward_path(&local->hw,
58 + &sdata->vif, sta,
59 + ctx, path);
60 + trace_drv_return_int(local, ret);
61 +
62 + return ret;
63 +}
64 +
65 #endif /* __MAC80211_DRIVER_OPS */
66 --- a/net/mac80211/ieee80211_i.h
67 +++ b/net/mac80211/ieee80211_i.h
68 @@ -1465,7 +1465,7 @@ struct ieee80211_local {
69 };
70
71 static inline struct ieee80211_sub_if_data *
72 -IEEE80211_DEV_TO_SUB_IF(struct net_device *dev)
73 +IEEE80211_DEV_TO_SUB_IF(const struct net_device *dev)
74 {
75 return netdev_priv(dev);
76 }
77 --- a/net/mac80211/iface.c
78 +++ b/net/mac80211/iface.c
79 @@ -822,6 +822,66 @@ static const struct net_device_ops ieee8
80
81 };
82
83 +#if LINUX_VERSION_IS_GEQ(5,10,0)
84 +static int ieee80211_netdev_fill_forward_path(struct net_device_path_ctx *ctx,
85 + struct net_device_path *path)
86 +{
87 + struct ieee80211_sub_if_data *sdata;
88 + struct ieee80211_local *local;
89 + struct sta_info *sta;
90 + int ret = -ENOENT;
91 +
92 + sdata = IEEE80211_DEV_TO_SUB_IF(ctx->dev);
93 + local = sdata->local;
94 +
95 + if (!local->ops->net_fill_forward_path)
96 + return -EOPNOTSUPP;
97 +
98 + rcu_read_lock();
99 + switch (sdata->vif.type) {
100 + case NL80211_IFTYPE_AP_VLAN:
101 + sta = rcu_dereference(sdata->u.vlan.sta);
102 + if (sta)
103 + break;
104 + if (sdata->wdev.use_4addr)
105 + goto out;
106 + if (is_multicast_ether_addr(ctx->daddr))
107 + goto out;
108 + sta = sta_info_get_bss(sdata, ctx->daddr);
109 + break;
110 + case NL80211_IFTYPE_AP:
111 + if (is_multicast_ether_addr(ctx->daddr))
112 + goto out;
113 + sta = sta_info_get(sdata, ctx->daddr);
114 + break;
115 + case NL80211_IFTYPE_STATION:
116 + if (sdata->wdev.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) {
117 + sta = sta_info_get(sdata, ctx->daddr);
118 + if (sta && test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
119 + if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH))
120 + goto out;
121 +
122 + break;
123 + }
124 + }
125 +
126 + sta = sta_info_get(sdata, sdata->u.mgd.bssid);
127 + break;
128 + default:
129 + goto out;
130 + }
131 +
132 + if (!sta)
133 + goto out;
134 +
135 + ret = drv_net_fill_forward_path(local, sdata, &sta->sta, ctx, path);
136 +out:
137 + rcu_read_unlock();
138 +
139 + return ret;
140 +}
141 +#endif
142 +
143 static const struct net_device_ops ieee80211_dataif_8023_ops = {
144 #if LINUX_VERSION_IS_LESS(4,10,0)
145 .ndo_change_mtu = __change_mtu,
146 @@ -839,7 +899,9 @@ static const struct net_device_ops ieee8
147 #else
148 .ndo_get_stats64 = bp_ieee80211_get_stats64,
149 #endif
150 -
151 +#if LINUX_VERSION_IS_GEQ(5,10,0)
152 + .ndo_fill_forward_path = ieee80211_netdev_fill_forward_path,
153 +#endif
154 };
155
156 static bool ieee80211_iftype_supports_hdr_offload(enum nl80211_iftype iftype)
157 --- a/net/mac80211/trace.h
158 +++ b/net/mac80211/trace.h
159 @@ -2892,6 +2892,13 @@ TRACE_EVENT(drv_twt_teardown_request,
160 )
161 );
162
163 +DEFINE_EVENT(sta_event, drv_net_fill_forward_path,
164 + TP_PROTO(struct ieee80211_local *local,
165 + struct ieee80211_sub_if_data *sdata,
166 + struct ieee80211_sta *sta),
167 + TP_ARGS(local, sdata, sta)
168 +);
169 +
170 #endif /* !__MAC80211_DRIVER_TRACE || TRACE_HEADER_MULTI_READ */
171
172 #undef TRACE_INCLUDE_PATH