272d84f35ea68675828199becff1599850e45f34
[openwrt/staging/wigyori.git] / package / kernel / mac80211 / patches / subsys / 308-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,13 @@ 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 +#if LINUX_VERSION_IS_GEQ(5,10,0)
30 + int (*net_fill_forward_path)(struct ieee80211_hw *hw,
31 + struct ieee80211_vif *vif,
32 + struct ieee80211_sta *sta,
33 + struct net_device_path_ctx *ctx,
34 + struct net_device_path *path);
35 +#endif
36 };
37
38 /**
39 --- a/net/mac80211/driver-ops.h
40 +++ b/net/mac80211/driver-ops.h
41 @@ -1486,4 +1486,28 @@ static inline void drv_twt_teardown_requ
42 trace_drv_return_void(local);
43 }
44
45 +#if LINUX_VERSION_IS_GEQ(5,10,0)
46 +static inline int drv_net_fill_forward_path(struct ieee80211_local *local,
47 + struct ieee80211_sub_if_data *sdata,
48 + struct ieee80211_sta *sta,
49 + struct net_device_path_ctx *ctx,
50 + struct net_device_path *path)
51 +{
52 + int ret = -EOPNOTSUPP;
53 +
54 + sdata = get_bss_sdata(sdata);
55 + if (!check_sdata_in_driver(sdata))
56 + return -EIO;
57 +
58 + trace_drv_net_fill_forward_path(local, sdata, sta);
59 + if (local->ops->net_fill_forward_path)
60 + ret = local->ops->net_fill_forward_path(&local->hw,
61 + &sdata->vif, sta,
62 + ctx, path);
63 + trace_drv_return_int(local, ret);
64 +
65 + return ret;
66 +}
67 +#endif
68 +
69 #endif /* __MAC80211_DRIVER_OPS */
70 --- a/net/mac80211/ieee80211_i.h
71 +++ b/net/mac80211/ieee80211_i.h
72 @@ -1485,7 +1485,7 @@ struct ieee80211_local {
73 };
74
75 static inline struct ieee80211_sub_if_data *
76 -IEEE80211_DEV_TO_SUB_IF(struct net_device *dev)
77 +IEEE80211_DEV_TO_SUB_IF(const struct net_device *dev)
78 {
79 return netdev_priv(dev);
80 }
81 --- a/net/mac80211/iface.c
82 +++ b/net/mac80211/iface.c
83 @@ -822,6 +822,66 @@ static const struct net_device_ops ieee8
84
85 };
86
87 +#if LINUX_VERSION_IS_GEQ(5,10,0)
88 +static int ieee80211_netdev_fill_forward_path(struct net_device_path_ctx *ctx,
89 + struct net_device_path *path)
90 +{
91 + struct ieee80211_sub_if_data *sdata;
92 + struct ieee80211_local *local;
93 + struct sta_info *sta;
94 + int ret = -ENOENT;
95 +
96 + sdata = IEEE80211_DEV_TO_SUB_IF(ctx->dev);
97 + local = sdata->local;
98 +
99 + if (!local->ops->net_fill_forward_path)
100 + return -EOPNOTSUPP;
101 +
102 + rcu_read_lock();
103 + switch (sdata->vif.type) {
104 + case NL80211_IFTYPE_AP_VLAN:
105 + sta = rcu_dereference(sdata->u.vlan.sta);
106 + if (sta)
107 + break;
108 + if (sdata->wdev.use_4addr)
109 + goto out;
110 + if (is_multicast_ether_addr(ctx->daddr))
111 + goto out;
112 + sta = sta_info_get_bss(sdata, ctx->daddr);
113 + break;
114 + case NL80211_IFTYPE_AP:
115 + if (is_multicast_ether_addr(ctx->daddr))
116 + goto out;
117 + sta = sta_info_get(sdata, ctx->daddr);
118 + break;
119 + case NL80211_IFTYPE_STATION:
120 + if (sdata->wdev.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) {
121 + sta = sta_info_get(sdata, ctx->daddr);
122 + if (sta && test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
123 + if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH))
124 + goto out;
125 +
126 + break;
127 + }
128 + }
129 +
130 + sta = sta_info_get(sdata, sdata->u.mgd.bssid);
131 + break;
132 + default:
133 + goto out;
134 + }
135 +
136 + if (!sta)
137 + goto out;
138 +
139 + ret = drv_net_fill_forward_path(local, sdata, &sta->sta, ctx, path);
140 +out:
141 + rcu_read_unlock();
142 +
143 + return ret;
144 +}
145 +#endif
146 +
147 static const struct net_device_ops ieee80211_dataif_8023_ops = {
148 #if LINUX_VERSION_IS_LESS(4,10,0)
149 .ndo_change_mtu = __change_mtu,
150 @@ -839,7 +899,9 @@ static const struct net_device_ops ieee8
151 #else
152 .ndo_get_stats64 = bp_ieee80211_get_stats64,
153 #endif
154 -
155 +#if LINUX_VERSION_IS_GEQ(5,10,0)
156 + .ndo_fill_forward_path = ieee80211_netdev_fill_forward_path,
157 +#endif
158 };
159
160 static bool ieee80211_iftype_supports_hdr_offload(enum nl80211_iftype iftype)
161 --- a/net/mac80211/trace.h
162 +++ b/net/mac80211/trace.h
163 @@ -2892,6 +2892,15 @@ TRACE_EVENT(drv_twt_teardown_request,
164 )
165 );
166
167 +#if LINUX_VERSION_IS_GEQ(5,10,0)
168 +DEFINE_EVENT(sta_event, drv_net_fill_forward_path,
169 + TP_PROTO(struct ieee80211_local *local,
170 + struct ieee80211_sub_if_data *sdata,
171 + struct ieee80211_sta *sta),
172 + TP_ARGS(local, sdata, sta)
173 +);
174 +#endif
175 +
176 #endif /* !__MAC80211_DRIVER_TRACE || TRACE_HEADER_MULTI_READ */
177
178 #undef TRACE_INCLUDE_PATH