mac80211: update encap offload patches to the latest version
[openwrt/openwrt.git] / package / kernel / mac80211 / patches / subsys / 327-mac80211-reorganize-code-to-remove-a-forward-declara.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Tue, 8 Sep 2020 12:16:26 +0200
3 Subject: [PATCH] mac80211: reorganize code to remove a forward
4 declaration
5
6 Remove the newly added ieee80211_set_vif_encap_ops declaration.
7 No further code changes
8
9 Signed-off-by: Felix Fietkau <nbd@nbd.name>
10 ---
11
12 --- a/net/mac80211/iface.c
13 +++ b/net/mac80211/iface.c
14 @@ -43,7 +43,6 @@
15 */
16
17 static void ieee80211_iface_work(struct work_struct *work);
18 -static void ieee80211_set_vif_encap_ops(struct ieee80211_sub_if_data *sdata);
19
20 bool __ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata)
21 {
22 @@ -349,6 +348,511 @@ static int ieee80211_check_queues(struct
23 return 0;
24 }
25
26 +static int ieee80211_open(struct net_device *dev)
27 +{
28 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
29 + int err;
30 +
31 + /* fail early if user set an invalid address */
32 + if (!is_valid_ether_addr(dev->dev_addr))
33 + return -EADDRNOTAVAIL;
34 +
35 + err = ieee80211_check_concurrent_iface(sdata, sdata->vif.type);
36 + if (err)
37 + return err;
38 +
39 + return ieee80211_do_open(&sdata->wdev, true);
40 +}
41 +
42 +static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
43 + bool going_down)
44 +{
45 + struct ieee80211_local *local = sdata->local;
46 + unsigned long flags;
47 + struct sk_buff *skb, *tmp;
48 + u32 hw_reconf_flags = 0;
49 + int i, flushed;
50 + struct ps_data *ps;
51 + struct cfg80211_chan_def chandef;
52 + bool cancel_scan;
53 + struct cfg80211_nan_func *func;
54 +
55 + clear_bit(SDATA_STATE_RUNNING, &sdata->state);
56 +
57 + cancel_scan = rcu_access_pointer(local->scan_sdata) == sdata;
58 + if (cancel_scan)
59 + ieee80211_scan_cancel(local);
60 +
61 + /*
62 + * Stop TX on this interface first.
63 + */
64 + if (sdata->dev)
65 + netif_tx_stop_all_queues(sdata->dev);
66 +
67 + ieee80211_roc_purge(local, sdata);
68 +
69 + switch (sdata->vif.type) {
70 + case NL80211_IFTYPE_STATION:
71 + ieee80211_mgd_stop(sdata);
72 + break;
73 + case NL80211_IFTYPE_ADHOC:
74 + ieee80211_ibss_stop(sdata);
75 + break;
76 + case NL80211_IFTYPE_MONITOR:
77 + if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES)
78 + break;
79 + list_del_rcu(&sdata->u.mntr.list);
80 + break;
81 + default:
82 + break;
83 + }
84 +
85 + /*
86 + * Remove all stations associated with this interface.
87 + *
88 + * This must be done before calling ops->remove_interface()
89 + * because otherwise we can later invoke ops->sta_notify()
90 + * whenever the STAs are removed, and that invalidates driver
91 + * assumptions about always getting a vif pointer that is valid
92 + * (because if we remove a STA after ops->remove_interface()
93 + * the driver will have removed the vif info already!)
94 + *
95 + * In WDS mode a station must exist here and be flushed, for
96 + * AP_VLANs stations may exist since there's nothing else that
97 + * would have removed them, but in other modes there shouldn't
98 + * be any stations.
99 + */
100 + flushed = sta_info_flush(sdata);
101 + WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
102 + ((sdata->vif.type != NL80211_IFTYPE_WDS && flushed > 0) ||
103 + (sdata->vif.type == NL80211_IFTYPE_WDS && flushed != 1)));
104 +
105 + /* don't count this interface for allmulti while it is down */
106 + if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
107 + atomic_dec(&local->iff_allmultis);
108 +
109 + if (sdata->vif.type == NL80211_IFTYPE_AP) {
110 + local->fif_pspoll--;
111 + local->fif_probe_req--;
112 + } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
113 + local->fif_probe_req--;
114 + }
115 +
116 + if (sdata->dev) {
117 + netif_addr_lock_bh(sdata->dev);
118 + spin_lock_bh(&local->filter_lock);
119 + __hw_addr_unsync(&local->mc_list, &sdata->dev->mc,
120 + sdata->dev->addr_len);
121 + spin_unlock_bh(&local->filter_lock);
122 + netif_addr_unlock_bh(sdata->dev);
123 + }
124 +
125 + del_timer_sync(&local->dynamic_ps_timer);
126 + cancel_work_sync(&local->dynamic_ps_enable_work);
127 +
128 + cancel_work_sync(&sdata->recalc_smps);
129 + sdata_lock(sdata);
130 + mutex_lock(&local->mtx);
131 + sdata->vif.csa_active = false;
132 + if (sdata->vif.type == NL80211_IFTYPE_STATION)
133 + sdata->u.mgd.csa_waiting_bcn = false;
134 + if (sdata->csa_block_tx) {
135 + ieee80211_wake_vif_queues(local, sdata,
136 + IEEE80211_QUEUE_STOP_REASON_CSA);
137 + sdata->csa_block_tx = false;
138 + }
139 + mutex_unlock(&local->mtx);
140 + sdata_unlock(sdata);
141 +
142 + cancel_work_sync(&sdata->csa_finalize_work);
143 +
144 + cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
145 +
146 + if (sdata->wdev.cac_started) {
147 + chandef = sdata->vif.bss_conf.chandef;
148 + WARN_ON(local->suspended);
149 + mutex_lock(&local->mtx);
150 + ieee80211_vif_release_channel(sdata);
151 + mutex_unlock(&local->mtx);
152 + cfg80211_cac_event(sdata->dev, &chandef,
153 + NL80211_RADAR_CAC_ABORTED,
154 + GFP_KERNEL);
155 + }
156 +
157 + /* APs need special treatment */
158 + if (sdata->vif.type == NL80211_IFTYPE_AP) {
159 + struct ieee80211_sub_if_data *vlan, *tmpsdata;
160 +
161 + /* down all dependent devices, that is VLANs */
162 + list_for_each_entry_safe(vlan, tmpsdata, &sdata->u.ap.vlans,
163 + u.vlan.list)
164 + dev_close(vlan->dev);
165 + WARN_ON(!list_empty(&sdata->u.ap.vlans));
166 + } else if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
167 + /* remove all packets in parent bc_buf pointing to this dev */
168 + ps = &sdata->bss->ps;
169 +
170 + spin_lock_irqsave(&ps->bc_buf.lock, flags);
171 + skb_queue_walk_safe(&ps->bc_buf, skb, tmp) {
172 + if (skb->dev == sdata->dev) {
173 + __skb_unlink(skb, &ps->bc_buf);
174 + local->total_ps_buffered--;
175 + ieee80211_free_txskb(&local->hw, skb);
176 + }
177 + }
178 + spin_unlock_irqrestore(&ps->bc_buf.lock, flags);
179 + }
180 +
181 + if (going_down)
182 + local->open_count--;
183 +
184 + switch (sdata->vif.type) {
185 + case NL80211_IFTYPE_AP_VLAN:
186 + mutex_lock(&local->mtx);
187 + list_del(&sdata->u.vlan.list);
188 + mutex_unlock(&local->mtx);
189 + RCU_INIT_POINTER(sdata->vif.chanctx_conf, NULL);
190 + /* see comment in the default case below */
191 + ieee80211_free_keys(sdata, true);
192 + /* no need to tell driver */
193 + break;
194 + case NL80211_IFTYPE_MONITOR:
195 + if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES) {
196 + local->cooked_mntrs--;
197 + break;
198 + }
199 +
200 + local->monitors--;
201 + if (local->monitors == 0) {
202 + local->hw.conf.flags &= ~IEEE80211_CONF_MONITOR;
203 + hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR;
204 + }
205 +
206 + ieee80211_adjust_monitor_flags(sdata, -1);
207 + break;
208 + case NL80211_IFTYPE_NAN:
209 + /* clean all the functions */
210 + spin_lock_bh(&sdata->u.nan.func_lock);
211 +
212 + idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, i) {
213 + idr_remove(&sdata->u.nan.function_inst_ids, i);
214 + cfg80211_free_nan_func(func);
215 + }
216 + idr_destroy(&sdata->u.nan.function_inst_ids);
217 +
218 + spin_unlock_bh(&sdata->u.nan.func_lock);
219 + break;
220 + case NL80211_IFTYPE_P2P_DEVICE:
221 + /* relies on synchronize_rcu() below */
222 + RCU_INIT_POINTER(local->p2p_sdata, NULL);
223 + /* fall through */
224 + default:
225 + cancel_work_sync(&sdata->work);
226 + /*
227 + * When we get here, the interface is marked down.
228 + * Free the remaining keys, if there are any
229 + * (which can happen in AP mode if userspace sets
230 + * keys before the interface is operating, and maybe
231 + * also in WDS mode)
232 + *
233 + * Force the key freeing to always synchronize_net()
234 + * to wait for the RX path in case it is using this
235 + * interface enqueuing frames at this very time on
236 + * another CPU.
237 + */
238 + ieee80211_free_keys(sdata, true);
239 + skb_queue_purge(&sdata->skb_queue);
240 + }
241 +
242 + spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
243 + for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
244 + skb_queue_walk_safe(&local->pending[i], skb, tmp) {
245 + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
246 + if (info->control.vif == &sdata->vif) {
247 + __skb_unlink(skb, &local->pending[i]);
248 + ieee80211_free_txskb(&local->hw, skb);
249 + }
250 + }
251 + }
252 + spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
253 +
254 + if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
255 + ieee80211_txq_remove_vlan(local, sdata);
256 +
257 + sdata->bss = NULL;
258 +
259 + if (local->open_count == 0)
260 + ieee80211_clear_tx_pending(local);
261 +
262 + sdata->vif.bss_conf.beacon_int = 0;
263 +
264 + /*
265 + * If the interface goes down while suspended, presumably because
266 + * the device was unplugged and that happens before our resume,
267 + * then the driver is already unconfigured and the remainder of
268 + * this function isn't needed.
269 + * XXX: what about WoWLAN? If the device has software state, e.g.
270 + * memory allocated, it might expect teardown commands from
271 + * mac80211 here?
272 + */
273 + if (local->suspended) {
274 + WARN_ON(local->wowlan);
275 + WARN_ON(rtnl_dereference(local->monitor_sdata));
276 + return;
277 + }
278 +
279 + switch (sdata->vif.type) {
280 + case NL80211_IFTYPE_AP_VLAN:
281 + break;
282 + case NL80211_IFTYPE_MONITOR:
283 + if (local->monitors == 0)
284 + ieee80211_del_virtual_monitor(local);
285 +
286 + mutex_lock(&local->mtx);
287 + ieee80211_recalc_idle(local);
288 + mutex_unlock(&local->mtx);
289 +
290 + if (!(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE))
291 + break;
292 +
293 + /* fall through */
294 + default:
295 + if (going_down)
296 + drv_remove_interface(local, sdata);
297 + }
298 +
299 + ieee80211_recalc_ps(local);
300 +
301 + if (cancel_scan)
302 + flush_delayed_work(&local->scan_work);
303 +
304 + if (local->open_count == 0) {
305 + ieee80211_stop_device(local);
306 +
307 + /* no reconfiguring after stop! */
308 + return;
309 + }
310 +
311 + /* do after stop to avoid reconfiguring when we stop anyway */
312 + ieee80211_configure_filter(local);
313 + ieee80211_hw_config(local, hw_reconf_flags);
314 +
315 + if (local->monitors == local->open_count)
316 + ieee80211_add_virtual_monitor(local);
317 +}
318 +
319 +static int ieee80211_stop(struct net_device *dev)
320 +{
321 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
322 +
323 + ieee80211_do_stop(sdata, true);
324 +
325 + return 0;
326 +}
327 +
328 +static void ieee80211_set_multicast_list(struct net_device *dev)
329 +{
330 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
331 + struct ieee80211_local *local = sdata->local;
332 + int allmulti, sdata_allmulti;
333 +
334 + allmulti = !!(dev->flags & IFF_ALLMULTI);
335 + sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
336 +
337 + if (allmulti != sdata_allmulti) {
338 + if (dev->flags & IFF_ALLMULTI)
339 + atomic_inc(&local->iff_allmultis);
340 + else
341 + atomic_dec(&local->iff_allmultis);
342 + sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
343 + }
344 +
345 + spin_lock_bh(&local->filter_lock);
346 + __hw_addr_sync(&local->mc_list, &dev->mc, dev->addr_len);
347 + spin_unlock_bh(&local->filter_lock);
348 + ieee80211_queue_work(&local->hw, &local->reconfig_filter);
349 +}
350 +
351 +/*
352 + * Called when the netdev is removed or, by the code below, before
353 + * the interface type changes.
354 + */
355 +static void ieee80211_teardown_sdata(struct ieee80211_sub_if_data *sdata)
356 +{
357 + int i;
358 +
359 + /* free extra data */
360 + ieee80211_free_keys(sdata, false);
361 +
362 + ieee80211_debugfs_remove_netdev(sdata);
363 +
364 + for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
365 + __skb_queue_purge(&sdata->fragments[i].skb_list);
366 + sdata->fragment_next = 0;
367 +
368 + if (ieee80211_vif_is_mesh(&sdata->vif))
369 + ieee80211_mesh_teardown_sdata(sdata);
370 +}
371 +
372 +static void ieee80211_uninit(struct net_device *dev)
373 +{
374 + ieee80211_teardown_sdata(IEEE80211_DEV_TO_SUB_IF(dev));
375 +}
376 +
377 +#if LINUX_VERSION_IS_GEQ(5,2,0)
378 +static u16 ieee80211_netdev_select_queue(struct net_device *dev,
379 + struct sk_buff *skb,
380 + struct net_device *sb_dev)
381 +#elif LINUX_VERSION_IS_GEQ(4,19,0)
382 +static u16 ieee80211_netdev_select_queue(struct net_device *dev,
383 + struct sk_buff *skb,
384 + struct net_device *sb_dev,
385 + select_queue_fallback_t fallback)
386 +#elif LINUX_VERSION_IS_GEQ(3,14,0) || \
387 + (LINUX_VERSION_CODE == KERNEL_VERSION(3,13,11) && UTS_UBUNTU_RELEASE_ABI > 30)
388 +static u16 ieee80211_netdev_select_queue(struct net_device *dev,
389 + struct sk_buff *skb,
390 + void *accel_priv,
391 + select_queue_fallback_t fallback)
392 +#elif LINUX_VERSION_IS_GEQ(3,13,0)
393 +static u16 ieee80211_netdev_select_queue(struct net_device *dev,
394 + struct sk_buff *skb,
395 + void *accel_priv)
396 +#else
397 +static u16 ieee80211_netdev_select_queue(struct net_device *dev,
398 + struct sk_buff *skb)
399 +#endif
400 +{
401 + return ieee80211_select_queue(IEEE80211_DEV_TO_SUB_IF(dev), skb);
402 +}
403 +
404 +static void
405 +ieee80211_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
406 +{
407 + int i;
408 +
409 + for_each_possible_cpu(i) {
410 + const struct pcpu_sw_netstats *tstats;
411 + u64 rx_packets, rx_bytes, tx_packets, tx_bytes;
412 + unsigned int start;
413 +
414 + tstats = per_cpu_ptr(netdev_tstats(dev), i);
415 +
416 + do {
417 + start = u64_stats_fetch_begin_irq(&tstats->syncp);
418 + rx_packets = tstats->rx_packets;
419 + tx_packets = tstats->tx_packets;
420 + rx_bytes = tstats->rx_bytes;
421 + tx_bytes = tstats->tx_bytes;
422 + } while (u64_stats_fetch_retry_irq(&tstats->syncp, start));
423 +
424 + stats->rx_packets += rx_packets;
425 + stats->tx_packets += tx_packets;
426 + stats->rx_bytes += rx_bytes;
427 + stats->tx_bytes += tx_bytes;
428 + }
429 +}
430 +#if LINUX_VERSION_IS_LESS(4,11,0)
431 +/* Just declare it here to keep sparse happy */
432 +struct rtnl_link_stats64 *bp_ieee80211_get_stats64(struct net_device *dev,
433 + struct rtnl_link_stats64 *stats);
434 +struct rtnl_link_stats64 *
435 +bp_ieee80211_get_stats64(struct net_device *dev,
436 + struct rtnl_link_stats64 *stats){
437 + ieee80211_get_stats64(dev, stats);
438 + return stats;
439 +}
440 +#endif
441 +
442 +static const struct net_device_ops ieee80211_dataif_ops = {
443 + .ndo_open = ieee80211_open,
444 + .ndo_stop = ieee80211_stop,
445 + .ndo_uninit = ieee80211_uninit,
446 + .ndo_start_xmit = ieee80211_subif_start_xmit,
447 + .ndo_set_rx_mode = ieee80211_set_multicast_list,
448 + .ndo_set_mac_address = ieee80211_change_mac,
449 + .ndo_select_queue = ieee80211_netdev_select_queue,
450 +#if LINUX_VERSION_IS_GEQ(4,11,0)
451 + .ndo_get_stats64 = ieee80211_get_stats64,
452 +#else
453 + .ndo_get_stats64 = bp_ieee80211_get_stats64,
454 +#endif
455 +
456 +};
457 +
458 +#if LINUX_VERSION_IS_GEQ(5,2,0)
459 +static u16 ieee80211_monitor_select_queue(struct net_device *dev,
460 + struct sk_buff *skb,
461 + struct net_device *sb_dev)
462 +#elif LINUX_VERSION_IS_GEQ(4,19,0)
463 +static u16 ieee80211_monitor_select_queue(struct net_device *dev,
464 + struct sk_buff *skb,
465 + struct net_device *sb_dev,
466 + select_queue_fallback_t fallback)
467 +#elif LINUX_VERSION_IS_GEQ(3,14,0) || \
468 + (LINUX_VERSION_CODE == KERNEL_VERSION(3,13,11) && UTS_UBUNTU_RELEASE_ABI > 30)
469 +static u16 ieee80211_monitor_select_queue(struct net_device *dev,
470 + struct sk_buff *skb,
471 + void *accel_priv,
472 + select_queue_fallback_t fallback)
473 +#elif LINUX_VERSION_IS_GEQ(3,13,0)
474 +static u16 ieee80211_monitor_select_queue(struct net_device *dev,
475 + struct sk_buff *skb,
476 + void *accel_priv)
477 +#else
478 +static u16 ieee80211_monitor_select_queue(struct net_device *dev,
479 + struct sk_buff *skb)
480 +#endif
481 +{
482 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
483 + struct ieee80211_local *local = sdata->local;
484 + struct ieee80211_hdr *hdr;
485 + struct ieee80211_radiotap_header *rtap = (void *)skb->data;
486 +
487 + if (local->hw.queues < IEEE80211_NUM_ACS)
488 + return 0;
489 +
490 + if (skb->len < 4 ||
491 + skb->len < le16_to_cpu(rtap->it_len) + 2 /* frame control */)
492 + return 0; /* doesn't matter, frame will be dropped */
493 +
494 + hdr = (void *)((u8 *)skb->data + le16_to_cpu(rtap->it_len));
495 +
496 + return ieee80211_select_queue_80211(sdata, skb, hdr);
497 +}
498 +
499 +static const struct net_device_ops ieee80211_monitorif_ops = {
500 + .ndo_open = ieee80211_open,
501 + .ndo_stop = ieee80211_stop,
502 + .ndo_uninit = ieee80211_uninit,
503 + .ndo_start_xmit = ieee80211_monitor_start_xmit,
504 + .ndo_set_rx_mode = ieee80211_set_multicast_list,
505 + .ndo_set_mac_address = ieee80211_change_mac,
506 + .ndo_select_queue = ieee80211_monitor_select_queue,
507 +#if LINUX_VERSION_IS_GEQ(4,11,0)
508 + .ndo_get_stats64 = ieee80211_get_stats64,
509 +#else
510 + .ndo_get_stats64 = bp_ieee80211_get_stats64,
511 +#endif
512 +
513 +};
514 +
515 +static const struct net_device_ops ieee80211_dataif_8023_ops = {
516 + .ndo_open = ieee80211_open,
517 + .ndo_stop = ieee80211_stop,
518 + .ndo_uninit = ieee80211_uninit,
519 + .ndo_start_xmit = ieee80211_subif_start_xmit_8023,
520 + .ndo_set_rx_mode = ieee80211_set_multicast_list,
521 + .ndo_set_mac_address = ieee80211_change_mac,
522 + .ndo_select_queue = ieee80211_netdev_select_queue,
523 +#if LINUX_VERSION_IS_GEQ(4,11,0)
524 + .ndo_get_stats64 = ieee80211_get_stats64,
525 +#else
526 + .ndo_get_stats64 = bp_ieee80211_get_stats64,
527 +#endif
528 +
529 +};
530 +
531 static bool ieee80211_iftype_supports_encap_offload(enum nl80211_iftype iftype)
532 {
533 switch (iftype) {
534 @@ -389,6 +893,31 @@ static bool ieee80211_set_sdata_offload_
535 return true;
536 }
537
538 +static void ieee80211_set_vif_encap_ops(struct ieee80211_sub_if_data *sdata)
539 +{
540 + struct ieee80211_local *local = sdata->local;
541 + struct ieee80211_sub_if_data *bss = sdata;
542 + bool enabled;
543 +
544 + if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
545 + if (!sdata->bss)
546 + return;
547 +
548 + bss = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap);
549 + }
550 +
551 + if (!ieee80211_hw_check(&local->hw, SUPPORTS_TX_ENCAP_OFFLOAD) ||
552 + !ieee80211_iftype_supports_encap_offload(bss->vif.type))
553 + return;
554 +
555 + enabled = bss->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED;
556 + if (sdata->wdev.use_4addr &&
557 + !(bss->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_4ADDR))
558 + enabled = false;
559 +
560 + sdata->dev->netdev_ops = enabled ? &ieee80211_dataif_8023_ops :
561 + &ieee80211_dataif_ops;
562 +}
563
564 static void ieee80211_recalc_sdata_offload(struct ieee80211_sub_if_data *sdata)
565 {
566 @@ -866,511 +1395,6 @@ int ieee80211_do_open(struct wireless_de
567 return res;
568 }
569
570 -static int ieee80211_open(struct net_device *dev)
571 -{
572 - struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
573 - int err;
574 -
575 - /* fail early if user set an invalid address */
576 - if (!is_valid_ether_addr(dev->dev_addr))
577 - return -EADDRNOTAVAIL;
578 -
579 - err = ieee80211_check_concurrent_iface(sdata, sdata->vif.type);
580 - if (err)
581 - return err;
582 -
583 - return ieee80211_do_open(&sdata->wdev, true);
584 -}
585 -
586 -static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
587 - bool going_down)
588 -{
589 - struct ieee80211_local *local = sdata->local;
590 - unsigned long flags;
591 - struct sk_buff *skb, *tmp;
592 - u32 hw_reconf_flags = 0;
593 - int i, flushed;
594 - struct ps_data *ps;
595 - struct cfg80211_chan_def chandef;
596 - bool cancel_scan;
597 - struct cfg80211_nan_func *func;
598 -
599 - clear_bit(SDATA_STATE_RUNNING, &sdata->state);
600 -
601 - cancel_scan = rcu_access_pointer(local->scan_sdata) == sdata;
602 - if (cancel_scan)
603 - ieee80211_scan_cancel(local);
604 -
605 - /*
606 - * Stop TX on this interface first.
607 - */
608 - if (sdata->dev)
609 - netif_tx_stop_all_queues(sdata->dev);
610 -
611 - ieee80211_roc_purge(local, sdata);
612 -
613 - switch (sdata->vif.type) {
614 - case NL80211_IFTYPE_STATION:
615 - ieee80211_mgd_stop(sdata);
616 - break;
617 - case NL80211_IFTYPE_ADHOC:
618 - ieee80211_ibss_stop(sdata);
619 - break;
620 - case NL80211_IFTYPE_MONITOR:
621 - if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES)
622 - break;
623 - list_del_rcu(&sdata->u.mntr.list);
624 - break;
625 - default:
626 - break;
627 - }
628 -
629 - /*
630 - * Remove all stations associated with this interface.
631 - *
632 - * This must be done before calling ops->remove_interface()
633 - * because otherwise we can later invoke ops->sta_notify()
634 - * whenever the STAs are removed, and that invalidates driver
635 - * assumptions about always getting a vif pointer that is valid
636 - * (because if we remove a STA after ops->remove_interface()
637 - * the driver will have removed the vif info already!)
638 - *
639 - * In WDS mode a station must exist here and be flushed, for
640 - * AP_VLANs stations may exist since there's nothing else that
641 - * would have removed them, but in other modes there shouldn't
642 - * be any stations.
643 - */
644 - flushed = sta_info_flush(sdata);
645 - WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
646 - ((sdata->vif.type != NL80211_IFTYPE_WDS && flushed > 0) ||
647 - (sdata->vif.type == NL80211_IFTYPE_WDS && flushed != 1)));
648 -
649 - /* don't count this interface for allmulti while it is down */
650 - if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
651 - atomic_dec(&local->iff_allmultis);
652 -
653 - if (sdata->vif.type == NL80211_IFTYPE_AP) {
654 - local->fif_pspoll--;
655 - local->fif_probe_req--;
656 - } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
657 - local->fif_probe_req--;
658 - }
659 -
660 - if (sdata->dev) {
661 - netif_addr_lock_bh(sdata->dev);
662 - spin_lock_bh(&local->filter_lock);
663 - __hw_addr_unsync(&local->mc_list, &sdata->dev->mc,
664 - sdata->dev->addr_len);
665 - spin_unlock_bh(&local->filter_lock);
666 - netif_addr_unlock_bh(sdata->dev);
667 - }
668 -
669 - del_timer_sync(&local->dynamic_ps_timer);
670 - cancel_work_sync(&local->dynamic_ps_enable_work);
671 -
672 - cancel_work_sync(&sdata->recalc_smps);
673 - sdata_lock(sdata);
674 - mutex_lock(&local->mtx);
675 - sdata->vif.csa_active = false;
676 - if (sdata->vif.type == NL80211_IFTYPE_STATION)
677 - sdata->u.mgd.csa_waiting_bcn = false;
678 - if (sdata->csa_block_tx) {
679 - ieee80211_wake_vif_queues(local, sdata,
680 - IEEE80211_QUEUE_STOP_REASON_CSA);
681 - sdata->csa_block_tx = false;
682 - }
683 - mutex_unlock(&local->mtx);
684 - sdata_unlock(sdata);
685 -
686 - cancel_work_sync(&sdata->csa_finalize_work);
687 -
688 - cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
689 -
690 - if (sdata->wdev.cac_started) {
691 - chandef = sdata->vif.bss_conf.chandef;
692 - WARN_ON(local->suspended);
693 - mutex_lock(&local->mtx);
694 - ieee80211_vif_release_channel(sdata);
695 - mutex_unlock(&local->mtx);
696 - cfg80211_cac_event(sdata->dev, &chandef,
697 - NL80211_RADAR_CAC_ABORTED,
698 - GFP_KERNEL);
699 - }
700 -
701 - /* APs need special treatment */
702 - if (sdata->vif.type == NL80211_IFTYPE_AP) {
703 - struct ieee80211_sub_if_data *vlan, *tmpsdata;
704 -
705 - /* down all dependent devices, that is VLANs */
706 - list_for_each_entry_safe(vlan, tmpsdata, &sdata->u.ap.vlans,
707 - u.vlan.list)
708 - dev_close(vlan->dev);
709 - WARN_ON(!list_empty(&sdata->u.ap.vlans));
710 - } else if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
711 - /* remove all packets in parent bc_buf pointing to this dev */
712 - ps = &sdata->bss->ps;
713 -
714 - spin_lock_irqsave(&ps->bc_buf.lock, flags);
715 - skb_queue_walk_safe(&ps->bc_buf, skb, tmp) {
716 - if (skb->dev == sdata->dev) {
717 - __skb_unlink(skb, &ps->bc_buf);
718 - local->total_ps_buffered--;
719 - ieee80211_free_txskb(&local->hw, skb);
720 - }
721 - }
722 - spin_unlock_irqrestore(&ps->bc_buf.lock, flags);
723 - }
724 -
725 - if (going_down)
726 - local->open_count--;
727 -
728 - switch (sdata->vif.type) {
729 - case NL80211_IFTYPE_AP_VLAN:
730 - mutex_lock(&local->mtx);
731 - list_del(&sdata->u.vlan.list);
732 - mutex_unlock(&local->mtx);
733 - RCU_INIT_POINTER(sdata->vif.chanctx_conf, NULL);
734 - /* see comment in the default case below */
735 - ieee80211_free_keys(sdata, true);
736 - /* no need to tell driver */
737 - break;
738 - case NL80211_IFTYPE_MONITOR:
739 - if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES) {
740 - local->cooked_mntrs--;
741 - break;
742 - }
743 -
744 - local->monitors--;
745 - if (local->monitors == 0) {
746 - local->hw.conf.flags &= ~IEEE80211_CONF_MONITOR;
747 - hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR;
748 - }
749 -
750 - ieee80211_adjust_monitor_flags(sdata, -1);
751 - break;
752 - case NL80211_IFTYPE_NAN:
753 - /* clean all the functions */
754 - spin_lock_bh(&sdata->u.nan.func_lock);
755 -
756 - idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, i) {
757 - idr_remove(&sdata->u.nan.function_inst_ids, i);
758 - cfg80211_free_nan_func(func);
759 - }
760 - idr_destroy(&sdata->u.nan.function_inst_ids);
761 -
762 - spin_unlock_bh(&sdata->u.nan.func_lock);
763 - break;
764 - case NL80211_IFTYPE_P2P_DEVICE:
765 - /* relies on synchronize_rcu() below */
766 - RCU_INIT_POINTER(local->p2p_sdata, NULL);
767 - /* fall through */
768 - default:
769 - cancel_work_sync(&sdata->work);
770 - /*
771 - * When we get here, the interface is marked down.
772 - * Free the remaining keys, if there are any
773 - * (which can happen in AP mode if userspace sets
774 - * keys before the interface is operating, and maybe
775 - * also in WDS mode)
776 - *
777 - * Force the key freeing to always synchronize_net()
778 - * to wait for the RX path in case it is using this
779 - * interface enqueuing frames at this very time on
780 - * another CPU.
781 - */
782 - ieee80211_free_keys(sdata, true);
783 - skb_queue_purge(&sdata->skb_queue);
784 - }
785 -
786 - spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
787 - for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
788 - skb_queue_walk_safe(&local->pending[i], skb, tmp) {
789 - struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
790 - if (info->control.vif == &sdata->vif) {
791 - __skb_unlink(skb, &local->pending[i]);
792 - ieee80211_free_txskb(&local->hw, skb);
793 - }
794 - }
795 - }
796 - spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
797 -
798 - if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
799 - ieee80211_txq_remove_vlan(local, sdata);
800 -
801 - sdata->bss = NULL;
802 -
803 - if (local->open_count == 0)
804 - ieee80211_clear_tx_pending(local);
805 -
806 - sdata->vif.bss_conf.beacon_int = 0;
807 -
808 - /*
809 - * If the interface goes down while suspended, presumably because
810 - * the device was unplugged and that happens before our resume,
811 - * then the driver is already unconfigured and the remainder of
812 - * this function isn't needed.
813 - * XXX: what about WoWLAN? If the device has software state, e.g.
814 - * memory allocated, it might expect teardown commands from
815 - * mac80211 here?
816 - */
817 - if (local->suspended) {
818 - WARN_ON(local->wowlan);
819 - WARN_ON(rtnl_dereference(local->monitor_sdata));
820 - return;
821 - }
822 -
823 - switch (sdata->vif.type) {
824 - case NL80211_IFTYPE_AP_VLAN:
825 - break;
826 - case NL80211_IFTYPE_MONITOR:
827 - if (local->monitors == 0)
828 - ieee80211_del_virtual_monitor(local);
829 -
830 - mutex_lock(&local->mtx);
831 - ieee80211_recalc_idle(local);
832 - mutex_unlock(&local->mtx);
833 -
834 - if (!(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE))
835 - break;
836 -
837 - /* fall through */
838 - default:
839 - if (going_down)
840 - drv_remove_interface(local, sdata);
841 - }
842 -
843 - ieee80211_recalc_ps(local);
844 -
845 - if (cancel_scan)
846 - flush_delayed_work(&local->scan_work);
847 -
848 - if (local->open_count == 0) {
849 - ieee80211_stop_device(local);
850 -
851 - /* no reconfiguring after stop! */
852 - return;
853 - }
854 -
855 - /* do after stop to avoid reconfiguring when we stop anyway */
856 - ieee80211_configure_filter(local);
857 - ieee80211_hw_config(local, hw_reconf_flags);
858 -
859 - if (local->monitors == local->open_count)
860 - ieee80211_add_virtual_monitor(local);
861 -}
862 -
863 -static int ieee80211_stop(struct net_device *dev)
864 -{
865 - struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
866 -
867 - ieee80211_do_stop(sdata, true);
868 -
869 - return 0;
870 -}
871 -
872 -static void ieee80211_set_multicast_list(struct net_device *dev)
873 -{
874 - struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
875 - struct ieee80211_local *local = sdata->local;
876 - int allmulti, sdata_allmulti;
877 -
878 - allmulti = !!(dev->flags & IFF_ALLMULTI);
879 - sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
880 -
881 - if (allmulti != sdata_allmulti) {
882 - if (dev->flags & IFF_ALLMULTI)
883 - atomic_inc(&local->iff_allmultis);
884 - else
885 - atomic_dec(&local->iff_allmultis);
886 - sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
887 - }
888 -
889 - spin_lock_bh(&local->filter_lock);
890 - __hw_addr_sync(&local->mc_list, &dev->mc, dev->addr_len);
891 - spin_unlock_bh(&local->filter_lock);
892 - ieee80211_queue_work(&local->hw, &local->reconfig_filter);
893 -}
894 -
895 -/*
896 - * Called when the netdev is removed or, by the code below, before
897 - * the interface type changes.
898 - */
899 -static void ieee80211_teardown_sdata(struct ieee80211_sub_if_data *sdata)
900 -{
901 - int i;
902 -
903 - /* free extra data */
904 - ieee80211_free_keys(sdata, false);
905 -
906 - ieee80211_debugfs_remove_netdev(sdata);
907 -
908 - for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
909 - __skb_queue_purge(&sdata->fragments[i].skb_list);
910 - sdata->fragment_next = 0;
911 -
912 - if (ieee80211_vif_is_mesh(&sdata->vif))
913 - ieee80211_mesh_teardown_sdata(sdata);
914 -}
915 -
916 -static void ieee80211_uninit(struct net_device *dev)
917 -{
918 - ieee80211_teardown_sdata(IEEE80211_DEV_TO_SUB_IF(dev));
919 -}
920 -
921 -#if LINUX_VERSION_IS_GEQ(5,2,0)
922 -static u16 ieee80211_netdev_select_queue(struct net_device *dev,
923 - struct sk_buff *skb,
924 - struct net_device *sb_dev)
925 -#elif LINUX_VERSION_IS_GEQ(4,19,0)
926 -static u16 ieee80211_netdev_select_queue(struct net_device *dev,
927 - struct sk_buff *skb,
928 - struct net_device *sb_dev,
929 - select_queue_fallback_t fallback)
930 -#elif LINUX_VERSION_IS_GEQ(3,14,0) || \
931 - (LINUX_VERSION_CODE == KERNEL_VERSION(3,13,11) && UTS_UBUNTU_RELEASE_ABI > 30)
932 -static u16 ieee80211_netdev_select_queue(struct net_device *dev,
933 - struct sk_buff *skb,
934 - void *accel_priv,
935 - select_queue_fallback_t fallback)
936 -#elif LINUX_VERSION_IS_GEQ(3,13,0)
937 -static u16 ieee80211_netdev_select_queue(struct net_device *dev,
938 - struct sk_buff *skb,
939 - void *accel_priv)
940 -#else
941 -static u16 ieee80211_netdev_select_queue(struct net_device *dev,
942 - struct sk_buff *skb)
943 -#endif
944 -{
945 - return ieee80211_select_queue(IEEE80211_DEV_TO_SUB_IF(dev), skb);
946 -}
947 -
948 -static void
949 -ieee80211_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
950 -{
951 - int i;
952 -
953 - for_each_possible_cpu(i) {
954 - const struct pcpu_sw_netstats *tstats;
955 - u64 rx_packets, rx_bytes, tx_packets, tx_bytes;
956 - unsigned int start;
957 -
958 - tstats = per_cpu_ptr(netdev_tstats(dev), i);
959 -
960 - do {
961 - start = u64_stats_fetch_begin_irq(&tstats->syncp);
962 - rx_packets = tstats->rx_packets;
963 - tx_packets = tstats->tx_packets;
964 - rx_bytes = tstats->rx_bytes;
965 - tx_bytes = tstats->tx_bytes;
966 - } while (u64_stats_fetch_retry_irq(&tstats->syncp, start));
967 -
968 - stats->rx_packets += rx_packets;
969 - stats->tx_packets += tx_packets;
970 - stats->rx_bytes += rx_bytes;
971 - stats->tx_bytes += tx_bytes;
972 - }
973 -}
974 -#if LINUX_VERSION_IS_LESS(4,11,0)
975 -/* Just declare it here to keep sparse happy */
976 -struct rtnl_link_stats64 *bp_ieee80211_get_stats64(struct net_device *dev,
977 - struct rtnl_link_stats64 *stats);
978 -struct rtnl_link_stats64 *
979 -bp_ieee80211_get_stats64(struct net_device *dev,
980 - struct rtnl_link_stats64 *stats){
981 - ieee80211_get_stats64(dev, stats);
982 - return stats;
983 -}
984 -#endif
985 -
986 -static const struct net_device_ops ieee80211_dataif_ops = {
987 - .ndo_open = ieee80211_open,
988 - .ndo_stop = ieee80211_stop,
989 - .ndo_uninit = ieee80211_uninit,
990 - .ndo_start_xmit = ieee80211_subif_start_xmit,
991 - .ndo_set_rx_mode = ieee80211_set_multicast_list,
992 - .ndo_set_mac_address = ieee80211_change_mac,
993 - .ndo_select_queue = ieee80211_netdev_select_queue,
994 -#if LINUX_VERSION_IS_GEQ(4,11,0)
995 - .ndo_get_stats64 = ieee80211_get_stats64,
996 -#else
997 - .ndo_get_stats64 = bp_ieee80211_get_stats64,
998 -#endif
999 -
1000 -};
1001 -
1002 -#if LINUX_VERSION_IS_GEQ(5,2,0)
1003 -static u16 ieee80211_monitor_select_queue(struct net_device *dev,
1004 - struct sk_buff *skb,
1005 - struct net_device *sb_dev)
1006 -#elif LINUX_VERSION_IS_GEQ(4,19,0)
1007 -static u16 ieee80211_monitor_select_queue(struct net_device *dev,
1008 - struct sk_buff *skb,
1009 - struct net_device *sb_dev,
1010 - select_queue_fallback_t fallback)
1011 -#elif LINUX_VERSION_IS_GEQ(3,14,0) || \
1012 - (LINUX_VERSION_CODE == KERNEL_VERSION(3,13,11) && UTS_UBUNTU_RELEASE_ABI > 30)
1013 -static u16 ieee80211_monitor_select_queue(struct net_device *dev,
1014 - struct sk_buff *skb,
1015 - void *accel_priv,
1016 - select_queue_fallback_t fallback)
1017 -#elif LINUX_VERSION_IS_GEQ(3,13,0)
1018 -static u16 ieee80211_monitor_select_queue(struct net_device *dev,
1019 - struct sk_buff *skb,
1020 - void *accel_priv)
1021 -#else
1022 -static u16 ieee80211_monitor_select_queue(struct net_device *dev,
1023 - struct sk_buff *skb)
1024 -#endif
1025 -{
1026 - struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1027 - struct ieee80211_local *local = sdata->local;
1028 - struct ieee80211_hdr *hdr;
1029 - struct ieee80211_radiotap_header *rtap = (void *)skb->data;
1030 -
1031 - if (local->hw.queues < IEEE80211_NUM_ACS)
1032 - return 0;
1033 -
1034 - if (skb->len < 4 ||
1035 - skb->len < le16_to_cpu(rtap->it_len) + 2 /* frame control */)
1036 - return 0; /* doesn't matter, frame will be dropped */
1037 -
1038 - hdr = (void *)((u8 *)skb->data + le16_to_cpu(rtap->it_len));
1039 -
1040 - return ieee80211_select_queue_80211(sdata, skb, hdr);
1041 -}
1042 -
1043 -static const struct net_device_ops ieee80211_monitorif_ops = {
1044 - .ndo_open = ieee80211_open,
1045 - .ndo_stop = ieee80211_stop,
1046 - .ndo_uninit = ieee80211_uninit,
1047 - .ndo_start_xmit = ieee80211_monitor_start_xmit,
1048 - .ndo_set_rx_mode = ieee80211_set_multicast_list,
1049 - .ndo_set_mac_address = ieee80211_change_mac,
1050 - .ndo_select_queue = ieee80211_monitor_select_queue,
1051 -#if LINUX_VERSION_IS_GEQ(4,11,0)
1052 - .ndo_get_stats64 = ieee80211_get_stats64,
1053 -#else
1054 - .ndo_get_stats64 = bp_ieee80211_get_stats64,
1055 -#endif
1056 -
1057 -};
1058 -
1059 -static const struct net_device_ops ieee80211_dataif_8023_ops = {
1060 - .ndo_open = ieee80211_open,
1061 - .ndo_stop = ieee80211_stop,
1062 - .ndo_uninit = ieee80211_uninit,
1063 - .ndo_start_xmit = ieee80211_subif_start_xmit_8023,
1064 - .ndo_set_rx_mode = ieee80211_set_multicast_list,
1065 - .ndo_set_mac_address = ieee80211_change_mac,
1066 - .ndo_select_queue = ieee80211_netdev_select_queue,
1067 -#if LINUX_VERSION_IS_GEQ(4,11,0)
1068 - .ndo_get_stats64 = ieee80211_get_stats64,
1069 -#else
1070 - .ndo_get_stats64 = bp_ieee80211_get_stats64,
1071 -#endif
1072 -
1073 -};
1074 -
1075 static void ieee80211_if_free(struct net_device *dev)
1076 {
1077 free_percpu(netdev_tstats(dev));
1078 @@ -1401,32 +1425,6 @@ static void ieee80211_if_setup_no_queue(
1079 #endif
1080 }
1081
1082 -static void ieee80211_set_vif_encap_ops(struct ieee80211_sub_if_data *sdata)
1083 -{
1084 - struct ieee80211_local *local = sdata->local;
1085 - struct ieee80211_sub_if_data *bss = sdata;
1086 - bool enabled;
1087 -
1088 - if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
1089 - if (!sdata->bss)
1090 - return;
1091 -
1092 - bss = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap);
1093 - }
1094 -
1095 - if (!ieee80211_hw_check(&local->hw, SUPPORTS_TX_ENCAP_OFFLOAD) ||
1096 - !ieee80211_iftype_supports_encap_offload(bss->vif.type))
1097 - return;
1098 -
1099 - enabled = bss->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED;
1100 - if (sdata->wdev.use_4addr &&
1101 - !(bss->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_4ADDR))
1102 - enabled = false;
1103 -
1104 - sdata->dev->netdev_ops = enabled ? &ieee80211_dataif_8023_ops :
1105 - &ieee80211_dataif_ops;
1106 -}
1107 -
1108 static void ieee80211_iface_work(struct work_struct *work)
1109 {
1110 struct ieee80211_sub_if_data *sdata =