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
6 Remove the newly added ieee80211_set_vif_encap_ops declaration.
7 No further code changes
9 Signed-off-by: Felix Fietkau <nbd@nbd.name>
12 --- a/net/mac80211/iface.c
13 +++ b/net/mac80211/iface.c
17 static void ieee80211_iface_work(struct work_struct *work);
18 -static void ieee80211_set_vif_encap_ops(struct ieee80211_sub_if_data *sdata);
20 bool __ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata)
22 @@ -349,6 +348,518 @@ static int ieee80211_check_queues(struct
26 +static int ieee80211_open(struct net_device *dev)
28 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
31 + /* fail early if user set an invalid address */
32 + if (!is_valid_ether_addr(dev->dev_addr))
33 + return -EADDRNOTAVAIL;
35 + err = ieee80211_check_concurrent_iface(sdata, sdata->vif.type);
39 + return ieee80211_do_open(&sdata->wdev, true);
42 +static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
45 + struct ieee80211_local *local = sdata->local;
46 + unsigned long flags;
47 + struct sk_buff *skb, *tmp;
48 + u32 hw_reconf_flags = 0;
51 + struct cfg80211_chan_def chandef;
53 + struct cfg80211_nan_func *func;
55 + clear_bit(SDATA_STATE_RUNNING, &sdata->state);
57 + cancel_scan = rcu_access_pointer(local->scan_sdata) == sdata;
59 + ieee80211_scan_cancel(local);
62 + * Stop TX on this interface first.
65 + netif_tx_stop_all_queues(sdata->dev);
67 + ieee80211_roc_purge(local, sdata);
69 + switch (sdata->vif.type) {
70 + case NL80211_IFTYPE_STATION:
71 + ieee80211_mgd_stop(sdata);
73 + case NL80211_IFTYPE_ADHOC:
74 + ieee80211_ibss_stop(sdata);
76 + case NL80211_IFTYPE_MONITOR:
77 + if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES)
79 + list_del_rcu(&sdata->u.mntr.list);
86 + * Remove all stations associated with this interface.
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!)
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
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)));
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);
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--;
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);
125 + del_timer_sync(&local->dynamic_ps_timer);
126 + cancel_work_sync(&local->dynamic_ps_enable_work);
128 + cancel_work_sync(&sdata->recalc_smps);
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;
139 + mutex_unlock(&local->mtx);
140 + sdata_unlock(sdata);
142 + cancel_work_sync(&sdata->csa_finalize_work);
144 + cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
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,
157 + /* APs need special treatment */
158 + if (sdata->vif.type == NL80211_IFTYPE_AP) {
159 + struct ieee80211_sub_if_data *vlan, *tmpsdata;
161 + /* down all dependent devices, that is VLANs */
162 + list_for_each_entry_safe(vlan, tmpsdata, &sdata->u.ap.vlans,
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;
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);
178 + spin_unlock_irqrestore(&ps->bc_buf.lock, flags);
182 + local->open_count--;
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 */
194 + case NL80211_IFTYPE_MONITOR:
195 + if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES) {
196 + local->cooked_mntrs--;
201 + if (local->monitors == 0) {
202 + local->hw.conf.flags &= ~IEEE80211_CONF_MONITOR;
203 + hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR;
206 + ieee80211_adjust_monitor_flags(sdata, -1);
208 + case NL80211_IFTYPE_NAN:
209 + /* clean all the functions */
210 + spin_lock_bh(&sdata->u.nan.func_lock);
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);
216 + idr_destroy(&sdata->u.nan.function_inst_ids);
218 + spin_unlock_bh(&sdata->u.nan.func_lock);
220 + case NL80211_IFTYPE_P2P_DEVICE:
221 + /* relies on synchronize_rcu() below */
222 + RCU_INIT_POINTER(local->p2p_sdata, NULL);
225 + cancel_work_sync(&sdata->work);
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)
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
238 + ieee80211_free_keys(sdata, true);
239 + skb_queue_purge(&sdata->skb_queue);
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);
252 + spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
254 + if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
255 + ieee80211_txq_remove_vlan(local, sdata);
259 + if (local->open_count == 0)
260 + ieee80211_clear_tx_pending(local);
262 + sdata->vif.bss_conf.beacon_int = 0;
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
273 + if (local->suspended) {
274 + WARN_ON(local->wowlan);
275 + WARN_ON(rtnl_dereference(local->monitor_sdata));
279 + switch (sdata->vif.type) {
280 + case NL80211_IFTYPE_AP_VLAN:
282 + case NL80211_IFTYPE_MONITOR:
283 + if (local->monitors == 0)
284 + ieee80211_del_virtual_monitor(local);
286 + mutex_lock(&local->mtx);
287 + ieee80211_recalc_idle(local);
288 + mutex_unlock(&local->mtx);
290 + if (!(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE))
296 + drv_remove_interface(local, sdata);
299 + ieee80211_recalc_ps(local);
302 + flush_delayed_work(&local->scan_work);
304 + if (local->open_count == 0) {
305 + ieee80211_stop_device(local);
307 + /* no reconfiguring after stop! */
311 + /* do after stop to avoid reconfiguring when we stop anyway */
312 + ieee80211_configure_filter(local);
313 + ieee80211_hw_config(local, hw_reconf_flags);
315 + if (local->monitors == local->open_count)
316 + ieee80211_add_virtual_monitor(local);
319 +static int ieee80211_stop(struct net_device *dev)
321 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
323 + ieee80211_do_stop(sdata, true);
328 +static void ieee80211_set_multicast_list(struct net_device *dev)
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;
334 + allmulti = !!(dev->flags & IFF_ALLMULTI);
335 + sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
337 + if (allmulti != sdata_allmulti) {
338 + if (dev->flags & IFF_ALLMULTI)
339 + atomic_inc(&local->iff_allmultis);
341 + atomic_dec(&local->iff_allmultis);
342 + sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
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);
352 + * Called when the netdev is removed or, by the code below, before
353 + * the interface type changes.
355 +static void ieee80211_teardown_sdata(struct ieee80211_sub_if_data *sdata)
359 + /* free extra data */
360 + ieee80211_free_keys(sdata, false);
362 + ieee80211_debugfs_remove_netdev(sdata);
364 + for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
365 + __skb_queue_purge(&sdata->fragments[i].skb_list);
366 + sdata->fragment_next = 0;
368 + if (ieee80211_vif_is_mesh(&sdata->vif))
369 + ieee80211_mesh_teardown_sdata(sdata);
372 +static void ieee80211_uninit(struct net_device *dev)
374 + ieee80211_teardown_sdata(IEEE80211_DEV_TO_SUB_IF(dev));
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,
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,
397 +static u16 ieee80211_netdev_select_queue(struct net_device *dev,
398 + struct sk_buff *skb)
401 + return ieee80211_select_queue(IEEE80211_DEV_TO_SUB_IF(dev), skb);
405 +ieee80211_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
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;
414 + tstats = per_cpu_ptr(netdev_tstats(dev), i);
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));
424 + stats->rx_packets += rx_packets;
425 + stats->tx_packets += tx_packets;
426 + stats->rx_bytes += rx_bytes;
427 + stats->tx_bytes += tx_bytes;
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);
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,
453 + .ndo_get_stats64 = bp_ieee80211_get_stats64,
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,
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,
478 +static u16 ieee80211_monitor_select_queue(struct net_device *dev,
479 + struct sk_buff *skb)
482 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
483 + struct ieee80211_local *local = sdata->local;
484 + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
485 + struct ieee80211_hdr *hdr;
488 + if (local->hw.queues < IEEE80211_NUM_ACS)
491 + /* reset flags and info before parsing radiotap header */
492 + memset(info, 0, sizeof(*info));
494 + if (!ieee80211_parse_tx_radiotap(skb, dev))
495 + return 0; /* doesn't matter, frame will be dropped */
497 + len_rthdr = ieee80211_get_radiotap_len(skb->data);
498 + hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
499 + if (skb->len < len_rthdr + 2 ||
500 + skb->len < len_rthdr + ieee80211_hdrlen(hdr->frame_control))
501 + return 0; /* doesn't matter, frame will be dropped */
503 + return ieee80211_select_queue_80211(sdata, skb, hdr);
506 +static const struct net_device_ops ieee80211_monitorif_ops = {
507 + .ndo_open = ieee80211_open,
508 + .ndo_stop = ieee80211_stop,
509 + .ndo_uninit = ieee80211_uninit,
510 + .ndo_start_xmit = ieee80211_monitor_start_xmit,
511 + .ndo_set_rx_mode = ieee80211_set_multicast_list,
512 + .ndo_set_mac_address = ieee80211_change_mac,
513 + .ndo_select_queue = ieee80211_monitor_select_queue,
514 +#if LINUX_VERSION_IS_GEQ(4,11,0)
515 + .ndo_get_stats64 = ieee80211_get_stats64,
517 + .ndo_get_stats64 = bp_ieee80211_get_stats64,
522 +static const struct net_device_ops ieee80211_dataif_8023_ops = {
523 + .ndo_open = ieee80211_open,
524 + .ndo_stop = ieee80211_stop,
525 + .ndo_uninit = ieee80211_uninit,
526 + .ndo_start_xmit = ieee80211_subif_start_xmit_8023,
527 + .ndo_set_rx_mode = ieee80211_set_multicast_list,
528 + .ndo_set_mac_address = ieee80211_change_mac,
529 + .ndo_select_queue = ieee80211_netdev_select_queue,
530 +#if LINUX_VERSION_IS_GEQ(4,11,0)
531 + .ndo_get_stats64 = ieee80211_get_stats64,
533 + .ndo_get_stats64 = bp_ieee80211_get_stats64,
538 static bool ieee80211_iftype_supports_encap_offload(enum nl80211_iftype iftype)
541 @@ -389,6 +900,31 @@ static bool ieee80211_set_sdata_offload_
545 +static void ieee80211_set_vif_encap_ops(struct ieee80211_sub_if_data *sdata)
547 + struct ieee80211_local *local = sdata->local;
548 + struct ieee80211_sub_if_data *bss = sdata;
551 + if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
555 + bss = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap);
558 + if (!ieee80211_hw_check(&local->hw, SUPPORTS_TX_ENCAP_OFFLOAD) ||
559 + !ieee80211_iftype_supports_encap_offload(bss->vif.type))
562 + enabled = bss->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED;
563 + if (sdata->wdev.use_4addr &&
564 + !(bss->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_4ADDR))
567 + sdata->dev->netdev_ops = enabled ? &ieee80211_dataif_8023_ops :
568 + &ieee80211_dataif_ops;
571 static void ieee80211_recalc_sdata_offload(struct ieee80211_sub_if_data *sdata)
573 @@ -866,518 +1402,6 @@ int ieee80211_do_open(struct wireless_de
577 -static int ieee80211_open(struct net_device *dev)
579 - struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
582 - /* fail early if user set an invalid address */
583 - if (!is_valid_ether_addr(dev->dev_addr))
584 - return -EADDRNOTAVAIL;
586 - err = ieee80211_check_concurrent_iface(sdata, sdata->vif.type);
590 - return ieee80211_do_open(&sdata->wdev, true);
593 -static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
596 - struct ieee80211_local *local = sdata->local;
597 - unsigned long flags;
598 - struct sk_buff *skb, *tmp;
599 - u32 hw_reconf_flags = 0;
601 - struct ps_data *ps;
602 - struct cfg80211_chan_def chandef;
604 - struct cfg80211_nan_func *func;
606 - clear_bit(SDATA_STATE_RUNNING, &sdata->state);
608 - cancel_scan = rcu_access_pointer(local->scan_sdata) == sdata;
610 - ieee80211_scan_cancel(local);
613 - * Stop TX on this interface first.
616 - netif_tx_stop_all_queues(sdata->dev);
618 - ieee80211_roc_purge(local, sdata);
620 - switch (sdata->vif.type) {
621 - case NL80211_IFTYPE_STATION:
622 - ieee80211_mgd_stop(sdata);
624 - case NL80211_IFTYPE_ADHOC:
625 - ieee80211_ibss_stop(sdata);
627 - case NL80211_IFTYPE_MONITOR:
628 - if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES)
630 - list_del_rcu(&sdata->u.mntr.list);
637 - * Remove all stations associated with this interface.
639 - * This must be done before calling ops->remove_interface()
640 - * because otherwise we can later invoke ops->sta_notify()
641 - * whenever the STAs are removed, and that invalidates driver
642 - * assumptions about always getting a vif pointer that is valid
643 - * (because if we remove a STA after ops->remove_interface()
644 - * the driver will have removed the vif info already!)
646 - * In WDS mode a station must exist here and be flushed, for
647 - * AP_VLANs stations may exist since there's nothing else that
648 - * would have removed them, but in other modes there shouldn't
651 - flushed = sta_info_flush(sdata);
652 - WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
653 - ((sdata->vif.type != NL80211_IFTYPE_WDS && flushed > 0) ||
654 - (sdata->vif.type == NL80211_IFTYPE_WDS && flushed != 1)));
656 - /* don't count this interface for allmulti while it is down */
657 - if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
658 - atomic_dec(&local->iff_allmultis);
660 - if (sdata->vif.type == NL80211_IFTYPE_AP) {
661 - local->fif_pspoll--;
662 - local->fif_probe_req--;
663 - } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
664 - local->fif_probe_req--;
668 - netif_addr_lock_bh(sdata->dev);
669 - spin_lock_bh(&local->filter_lock);
670 - __hw_addr_unsync(&local->mc_list, &sdata->dev->mc,
671 - sdata->dev->addr_len);
672 - spin_unlock_bh(&local->filter_lock);
673 - netif_addr_unlock_bh(sdata->dev);
676 - del_timer_sync(&local->dynamic_ps_timer);
677 - cancel_work_sync(&local->dynamic_ps_enable_work);
679 - cancel_work_sync(&sdata->recalc_smps);
681 - mutex_lock(&local->mtx);
682 - sdata->vif.csa_active = false;
683 - if (sdata->vif.type == NL80211_IFTYPE_STATION)
684 - sdata->u.mgd.csa_waiting_bcn = false;
685 - if (sdata->csa_block_tx) {
686 - ieee80211_wake_vif_queues(local, sdata,
687 - IEEE80211_QUEUE_STOP_REASON_CSA);
688 - sdata->csa_block_tx = false;
690 - mutex_unlock(&local->mtx);
691 - sdata_unlock(sdata);
693 - cancel_work_sync(&sdata->csa_finalize_work);
695 - cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
697 - if (sdata->wdev.cac_started) {
698 - chandef = sdata->vif.bss_conf.chandef;
699 - WARN_ON(local->suspended);
700 - mutex_lock(&local->mtx);
701 - ieee80211_vif_release_channel(sdata);
702 - mutex_unlock(&local->mtx);
703 - cfg80211_cac_event(sdata->dev, &chandef,
704 - NL80211_RADAR_CAC_ABORTED,
708 - /* APs need special treatment */
709 - if (sdata->vif.type == NL80211_IFTYPE_AP) {
710 - struct ieee80211_sub_if_data *vlan, *tmpsdata;
712 - /* down all dependent devices, that is VLANs */
713 - list_for_each_entry_safe(vlan, tmpsdata, &sdata->u.ap.vlans,
715 - dev_close(vlan->dev);
716 - WARN_ON(!list_empty(&sdata->u.ap.vlans));
717 - } else if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
718 - /* remove all packets in parent bc_buf pointing to this dev */
719 - ps = &sdata->bss->ps;
721 - spin_lock_irqsave(&ps->bc_buf.lock, flags);
722 - skb_queue_walk_safe(&ps->bc_buf, skb, tmp) {
723 - if (skb->dev == sdata->dev) {
724 - __skb_unlink(skb, &ps->bc_buf);
725 - local->total_ps_buffered--;
726 - ieee80211_free_txskb(&local->hw, skb);
729 - spin_unlock_irqrestore(&ps->bc_buf.lock, flags);
733 - local->open_count--;
735 - switch (sdata->vif.type) {
736 - case NL80211_IFTYPE_AP_VLAN:
737 - mutex_lock(&local->mtx);
738 - list_del(&sdata->u.vlan.list);
739 - mutex_unlock(&local->mtx);
740 - RCU_INIT_POINTER(sdata->vif.chanctx_conf, NULL);
741 - /* see comment in the default case below */
742 - ieee80211_free_keys(sdata, true);
743 - /* no need to tell driver */
745 - case NL80211_IFTYPE_MONITOR:
746 - if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES) {
747 - local->cooked_mntrs--;
752 - if (local->monitors == 0) {
753 - local->hw.conf.flags &= ~IEEE80211_CONF_MONITOR;
754 - hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR;
757 - ieee80211_adjust_monitor_flags(sdata, -1);
759 - case NL80211_IFTYPE_NAN:
760 - /* clean all the functions */
761 - spin_lock_bh(&sdata->u.nan.func_lock);
763 - idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, i) {
764 - idr_remove(&sdata->u.nan.function_inst_ids, i);
765 - cfg80211_free_nan_func(func);
767 - idr_destroy(&sdata->u.nan.function_inst_ids);
769 - spin_unlock_bh(&sdata->u.nan.func_lock);
771 - case NL80211_IFTYPE_P2P_DEVICE:
772 - /* relies on synchronize_rcu() below */
773 - RCU_INIT_POINTER(local->p2p_sdata, NULL);
776 - cancel_work_sync(&sdata->work);
778 - * When we get here, the interface is marked down.
779 - * Free the remaining keys, if there are any
780 - * (which can happen in AP mode if userspace sets
781 - * keys before the interface is operating, and maybe
782 - * also in WDS mode)
784 - * Force the key freeing to always synchronize_net()
785 - * to wait for the RX path in case it is using this
786 - * interface enqueuing frames at this very time on
789 - ieee80211_free_keys(sdata, true);
790 - skb_queue_purge(&sdata->skb_queue);
793 - spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
794 - for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
795 - skb_queue_walk_safe(&local->pending[i], skb, tmp) {
796 - struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
797 - if (info->control.vif == &sdata->vif) {
798 - __skb_unlink(skb, &local->pending[i]);
799 - ieee80211_free_txskb(&local->hw, skb);
803 - spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
805 - if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
806 - ieee80211_txq_remove_vlan(local, sdata);
810 - if (local->open_count == 0)
811 - ieee80211_clear_tx_pending(local);
813 - sdata->vif.bss_conf.beacon_int = 0;
816 - * If the interface goes down while suspended, presumably because
817 - * the device was unplugged and that happens before our resume,
818 - * then the driver is already unconfigured and the remainder of
819 - * this function isn't needed.
820 - * XXX: what about WoWLAN? If the device has software state, e.g.
821 - * memory allocated, it might expect teardown commands from
824 - if (local->suspended) {
825 - WARN_ON(local->wowlan);
826 - WARN_ON(rtnl_dereference(local->monitor_sdata));
830 - switch (sdata->vif.type) {
831 - case NL80211_IFTYPE_AP_VLAN:
833 - case NL80211_IFTYPE_MONITOR:
834 - if (local->monitors == 0)
835 - ieee80211_del_virtual_monitor(local);
837 - mutex_lock(&local->mtx);
838 - ieee80211_recalc_idle(local);
839 - mutex_unlock(&local->mtx);
841 - if (!(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE))
847 - drv_remove_interface(local, sdata);
850 - ieee80211_recalc_ps(local);
853 - flush_delayed_work(&local->scan_work);
855 - if (local->open_count == 0) {
856 - ieee80211_stop_device(local);
858 - /* no reconfiguring after stop! */
862 - /* do after stop to avoid reconfiguring when we stop anyway */
863 - ieee80211_configure_filter(local);
864 - ieee80211_hw_config(local, hw_reconf_flags);
866 - if (local->monitors == local->open_count)
867 - ieee80211_add_virtual_monitor(local);
870 -static int ieee80211_stop(struct net_device *dev)
872 - struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
874 - ieee80211_do_stop(sdata, true);
879 -static void ieee80211_set_multicast_list(struct net_device *dev)
881 - struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
882 - struct ieee80211_local *local = sdata->local;
883 - int allmulti, sdata_allmulti;
885 - allmulti = !!(dev->flags & IFF_ALLMULTI);
886 - sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
888 - if (allmulti != sdata_allmulti) {
889 - if (dev->flags & IFF_ALLMULTI)
890 - atomic_inc(&local->iff_allmultis);
892 - atomic_dec(&local->iff_allmultis);
893 - sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
896 - spin_lock_bh(&local->filter_lock);
897 - __hw_addr_sync(&local->mc_list, &dev->mc, dev->addr_len);
898 - spin_unlock_bh(&local->filter_lock);
899 - ieee80211_queue_work(&local->hw, &local->reconfig_filter);
903 - * Called when the netdev is removed or, by the code below, before
904 - * the interface type changes.
906 -static void ieee80211_teardown_sdata(struct ieee80211_sub_if_data *sdata)
910 - /* free extra data */
911 - ieee80211_free_keys(sdata, false);
913 - ieee80211_debugfs_remove_netdev(sdata);
915 - for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
916 - __skb_queue_purge(&sdata->fragments[i].skb_list);
917 - sdata->fragment_next = 0;
919 - if (ieee80211_vif_is_mesh(&sdata->vif))
920 - ieee80211_mesh_teardown_sdata(sdata);
923 -static void ieee80211_uninit(struct net_device *dev)
925 - ieee80211_teardown_sdata(IEEE80211_DEV_TO_SUB_IF(dev));
928 -#if LINUX_VERSION_IS_GEQ(5,2,0)
929 -static u16 ieee80211_netdev_select_queue(struct net_device *dev,
930 - struct sk_buff *skb,
931 - struct net_device *sb_dev)
932 -#elif LINUX_VERSION_IS_GEQ(4,19,0)
933 -static u16 ieee80211_netdev_select_queue(struct net_device *dev,
934 - struct sk_buff *skb,
935 - struct net_device *sb_dev,
936 - select_queue_fallback_t fallback)
937 -#elif LINUX_VERSION_IS_GEQ(3,14,0) || \
938 - (LINUX_VERSION_CODE == KERNEL_VERSION(3,13,11) && UTS_UBUNTU_RELEASE_ABI > 30)
939 -static u16 ieee80211_netdev_select_queue(struct net_device *dev,
940 - struct sk_buff *skb,
942 - select_queue_fallback_t fallback)
943 -#elif LINUX_VERSION_IS_GEQ(3,13,0)
944 -static u16 ieee80211_netdev_select_queue(struct net_device *dev,
945 - struct sk_buff *skb,
948 -static u16 ieee80211_netdev_select_queue(struct net_device *dev,
949 - struct sk_buff *skb)
952 - return ieee80211_select_queue(IEEE80211_DEV_TO_SUB_IF(dev), skb);
956 -ieee80211_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
960 - for_each_possible_cpu(i) {
961 - const struct pcpu_sw_netstats *tstats;
962 - u64 rx_packets, rx_bytes, tx_packets, tx_bytes;
963 - unsigned int start;
965 - tstats = per_cpu_ptr(netdev_tstats(dev), i);
968 - start = u64_stats_fetch_begin_irq(&tstats->syncp);
969 - rx_packets = tstats->rx_packets;
970 - tx_packets = tstats->tx_packets;
971 - rx_bytes = tstats->rx_bytes;
972 - tx_bytes = tstats->tx_bytes;
973 - } while (u64_stats_fetch_retry_irq(&tstats->syncp, start));
975 - stats->rx_packets += rx_packets;
976 - stats->tx_packets += tx_packets;
977 - stats->rx_bytes += rx_bytes;
978 - stats->tx_bytes += tx_bytes;
981 -#if LINUX_VERSION_IS_LESS(4,11,0)
982 -/* Just declare it here to keep sparse happy */
983 -struct rtnl_link_stats64 *bp_ieee80211_get_stats64(struct net_device *dev,
984 - struct rtnl_link_stats64 *stats);
985 -struct rtnl_link_stats64 *
986 -bp_ieee80211_get_stats64(struct net_device *dev,
987 - struct rtnl_link_stats64 *stats){
988 - ieee80211_get_stats64(dev, stats);
993 -static const struct net_device_ops ieee80211_dataif_ops = {
994 - .ndo_open = ieee80211_open,
995 - .ndo_stop = ieee80211_stop,
996 - .ndo_uninit = ieee80211_uninit,
997 - .ndo_start_xmit = ieee80211_subif_start_xmit,
998 - .ndo_set_rx_mode = ieee80211_set_multicast_list,
999 - .ndo_set_mac_address = ieee80211_change_mac,
1000 - .ndo_select_queue = ieee80211_netdev_select_queue,
1001 -#if LINUX_VERSION_IS_GEQ(4,11,0)
1002 - .ndo_get_stats64 = ieee80211_get_stats64,
1004 - .ndo_get_stats64 = bp_ieee80211_get_stats64,
1009 -#if LINUX_VERSION_IS_GEQ(5,2,0)
1010 -static u16 ieee80211_monitor_select_queue(struct net_device *dev,
1011 - struct sk_buff *skb,
1012 - struct net_device *sb_dev)
1013 -#elif LINUX_VERSION_IS_GEQ(4,19,0)
1014 -static u16 ieee80211_monitor_select_queue(struct net_device *dev,
1015 - struct sk_buff *skb,
1016 - struct net_device *sb_dev,
1017 - select_queue_fallback_t fallback)
1018 -#elif LINUX_VERSION_IS_GEQ(3,14,0) || \
1019 - (LINUX_VERSION_CODE == KERNEL_VERSION(3,13,11) && UTS_UBUNTU_RELEASE_ABI > 30)
1020 -static u16 ieee80211_monitor_select_queue(struct net_device *dev,
1021 - struct sk_buff *skb,
1023 - select_queue_fallback_t fallback)
1024 -#elif LINUX_VERSION_IS_GEQ(3,13,0)
1025 -static u16 ieee80211_monitor_select_queue(struct net_device *dev,
1026 - struct sk_buff *skb,
1029 -static u16 ieee80211_monitor_select_queue(struct net_device *dev,
1030 - struct sk_buff *skb)
1033 - struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1034 - struct ieee80211_local *local = sdata->local;
1035 - struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1036 - struct ieee80211_hdr *hdr;
1039 - if (local->hw.queues < IEEE80211_NUM_ACS)
1042 - /* reset flags and info before parsing radiotap header */
1043 - memset(info, 0, sizeof(*info));
1045 - if (!ieee80211_parse_tx_radiotap(skb, dev))
1046 - return 0; /* doesn't matter, frame will be dropped */
1048 - len_rthdr = ieee80211_get_radiotap_len(skb->data);
1049 - hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
1050 - if (skb->len < len_rthdr + 2 ||
1051 - skb->len < len_rthdr + ieee80211_hdrlen(hdr->frame_control))
1052 - return 0; /* doesn't matter, frame will be dropped */
1054 - return ieee80211_select_queue_80211(sdata, skb, hdr);
1057 -static const struct net_device_ops ieee80211_monitorif_ops = {
1058 - .ndo_open = ieee80211_open,
1059 - .ndo_stop = ieee80211_stop,
1060 - .ndo_uninit = ieee80211_uninit,
1061 - .ndo_start_xmit = ieee80211_monitor_start_xmit,
1062 - .ndo_set_rx_mode = ieee80211_set_multicast_list,
1063 - .ndo_set_mac_address = ieee80211_change_mac,
1064 - .ndo_select_queue = ieee80211_monitor_select_queue,
1065 -#if LINUX_VERSION_IS_GEQ(4,11,0)
1066 - .ndo_get_stats64 = ieee80211_get_stats64,
1068 - .ndo_get_stats64 = bp_ieee80211_get_stats64,
1073 -static const struct net_device_ops ieee80211_dataif_8023_ops = {
1074 - .ndo_open = ieee80211_open,
1075 - .ndo_stop = ieee80211_stop,
1076 - .ndo_uninit = ieee80211_uninit,
1077 - .ndo_start_xmit = ieee80211_subif_start_xmit_8023,
1078 - .ndo_set_rx_mode = ieee80211_set_multicast_list,
1079 - .ndo_set_mac_address = ieee80211_change_mac,
1080 - .ndo_select_queue = ieee80211_netdev_select_queue,
1081 -#if LINUX_VERSION_IS_GEQ(4,11,0)
1082 - .ndo_get_stats64 = ieee80211_get_stats64,
1084 - .ndo_get_stats64 = bp_ieee80211_get_stats64,
1089 static void ieee80211_if_free(struct net_device *dev)
1091 free_percpu(netdev_tstats(dev));
1092 @@ -1408,32 +1432,6 @@ static void ieee80211_if_setup_no_queue(
1096 -static void ieee80211_set_vif_encap_ops(struct ieee80211_sub_if_data *sdata)
1098 - struct ieee80211_local *local = sdata->local;
1099 - struct ieee80211_sub_if_data *bss = sdata;
1102 - if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
1106 - bss = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap);
1109 - if (!ieee80211_hw_check(&local->hw, SUPPORTS_TX_ENCAP_OFFLOAD) ||
1110 - !ieee80211_iftype_supports_encap_offload(bss->vif.type))
1113 - enabled = bss->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED;
1114 - if (sdata->wdev.use_4addr &&
1115 - !(bss->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_4ADDR))
1118 - sdata->dev->netdev_ops = enabled ? &ieee80211_dataif_8023_ops :
1119 - &ieee80211_dataif_ops;
1122 static void ieee80211_iface_work(struct work_struct *work)
1124 struct ieee80211_sub_if_data *sdata =