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
5 This allows drivers to provide a destination device + info for flow offload
6 Only supported in combination with 802.3 encap offload
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>
14 --- a/include/net/mac80211.h
15 +++ b/include/net/mac80211.h
16 @@ -3937,6 +3937,8 @@ struct ieee80211_prep_tx_info {
18 * @twt_teardown_request: Update the hw with TWT teardown request received
20 + * @net_fill_forward_path: Called from .ndo_fill_forward_path in order to
21 + * resolve a path for hardware flow offloading
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);
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);
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)
49 + int ret = -EOPNOTSUPP;
51 + sdata = get_bss_sdata(sdata);
52 + if (!check_sdata_in_driver(sdata))
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,
60 + trace_drv_return_int(local, ret);
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 {
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)
75 return netdev_priv(dev);
77 --- a/net/mac80211/iface.c
78 +++ b/net/mac80211/iface.c
79 @@ -822,6 +822,66 @@ static const struct net_device_ops ieee8
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)
87 + struct ieee80211_sub_if_data *sdata;
88 + struct ieee80211_local *local;
89 + struct sta_info *sta;
92 + sdata = IEEE80211_DEV_TO_SUB_IF(ctx->dev);
93 + local = sdata->local;
95 + if (!local->ops->net_fill_forward_path)
99 + switch (sdata->vif.type) {
100 + case NL80211_IFTYPE_AP_VLAN:
101 + sta = rcu_dereference(sdata->u.vlan.sta);
104 + if (sdata->wdev.use_4addr)
106 + if (is_multicast_ether_addr(ctx->daddr))
108 + sta = sta_info_get_bss(sdata, ctx->daddr);
110 + case NL80211_IFTYPE_AP:
111 + if (is_multicast_ether_addr(ctx->daddr))
113 + sta = sta_info_get(sdata, ctx->daddr);
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))
126 + sta = sta_info_get(sdata, sdata->u.mgd.bssid);
135 + ret = drv_net_fill_forward_path(local, sdata, &sta->sta, ctx, path);
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
148 .ndo_get_stats64 = bp_ieee80211_get_stats64,
151 +#if LINUX_VERSION_IS_GEQ(5,10,0)
152 + .ndo_fill_forward_path = ieee80211_netdev_fill_forward_path,
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,
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)
170 #endif /* !__MAC80211_DRIVER_TRACE || TRACE_HEADER_MULTI_READ */
172 #undef TRACE_INCLUDE_PATH