0bfb10cdb01453f790fa5d1b572a91066877eacd
[openwrt/staging/adrian.git] /
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,518 @@ 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 + fallthrough;
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 + fallthrough;
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_tx_info *info = IEEE80211_SKB_CB(skb);
485 + struct ieee80211_hdr *hdr;
486 + int len_rthdr;
487 +
488 + if (local->hw.queues < IEEE80211_NUM_ACS)
489 + return 0;
490 +
491 + /* reset flags and info before parsing radiotap header */
492 + memset(info, 0, sizeof(*info));
493 +
494 + if (!ieee80211_parse_tx_radiotap(skb, dev))
495 + return 0; /* doesn't matter, frame will be dropped */
496 +
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 */
502 +
503 + return ieee80211_select_queue_80211(sdata, skb, hdr);
504 +}
505 +
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,
516 +#else
517 + .ndo_get_stats64 = bp_ieee80211_get_stats64,
518 +#endif
519 +
520 +};
521 +
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,
532 +#else
533 + .ndo_get_stats64 = bp_ieee80211_get_stats64,
534 +#endif
535 +
536 +};
537 +
538 static bool ieee80211_iftype_supports_encap_offload(enum nl80211_iftype iftype)
539 {
540 switch (iftype) {
541 @@ -389,6 +900,31 @@ static bool ieee80211_set_sdata_offload_
542 return true;
543 }
544
545 +static void ieee80211_set_vif_encap_ops(struct ieee80211_sub_if_data *sdata)
546 +{
547 + struct ieee80211_local *local = sdata->local;
548 + struct ieee80211_sub_if_data *bss = sdata;
549 + bool enabled;
550 +
551 + if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
552 + if (!sdata->bss)
553 + return;
554 +
555 + bss = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap);
556 + }
557 +
558 + if (!ieee80211_hw_check(&local->hw, SUPPORTS_TX_ENCAP_OFFLOAD) ||
559 + !ieee80211_iftype_supports_encap_offload(bss->vif.type))
560 + return;
561 +
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))
565 + enabled = false;
566 +
567 + sdata->dev->netdev_ops = enabled ? &ieee80211_dataif_8023_ops :
568 + &ieee80211_dataif_ops;
569 +}
570
571 static void ieee80211_recalc_sdata_offload(struct ieee80211_sub_if_data *sdata)
572 {
573 @@ -866,518 +1402,6 @@ int ieee80211_do_open(struct wireless_de
574 return res;
575 }
576
577 -static int ieee80211_open(struct net_device *dev)
578 -{
579 - struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
580 - int err;
581 -
582 - /* fail early if user set an invalid address */
583 - if (!is_valid_ether_addr(dev->dev_addr))
584 - return -EADDRNOTAVAIL;
585 -
586 - err = ieee80211_check_concurrent_iface(sdata, sdata->vif.type);
587 - if (err)
588 - return err;
589 -
590 - return ieee80211_do_open(&sdata->wdev, true);
591 -}
592 -
593 -static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
594 - bool going_down)
595 -{
596 - struct ieee80211_local *local = sdata->local;
597 - unsigned long flags;
598 - struct sk_buff *skb, *tmp;
599 - u32 hw_reconf_flags = 0;
600 - int i, flushed;
601 - struct ps_data *ps;
602 - struct cfg80211_chan_def chandef;
603 - bool cancel_scan;
604 - struct cfg80211_nan_func *func;
605 -
606 - clear_bit(SDATA_STATE_RUNNING, &sdata->state);
607 -
608 - cancel_scan = rcu_access_pointer(local->scan_sdata) == sdata;
609 - if (cancel_scan)
610 - ieee80211_scan_cancel(local);
611 -
612 - /*
613 - * Stop TX on this interface first.
614 - */
615 - if (sdata->dev)
616 - netif_tx_stop_all_queues(sdata->dev);
617 -
618 - ieee80211_roc_purge(local, sdata);
619 -
620 - switch (sdata->vif.type) {
621 - case NL80211_IFTYPE_STATION:
622 - ieee80211_mgd_stop(sdata);
623 - break;
624 - case NL80211_IFTYPE_ADHOC:
625 - ieee80211_ibss_stop(sdata);
626 - break;
627 - case NL80211_IFTYPE_MONITOR:
628 - if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES)
629 - break;
630 - list_del_rcu(&sdata->u.mntr.list);
631 - break;
632 - default:
633 - break;
634 - }
635 -
636 - /*
637 - * Remove all stations associated with this interface.
638 - *
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!)
645 - *
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
649 - * be any stations.
650 - */
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)));
655 -
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);
659 -
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--;
665 - }
666 -
667 - if (sdata->dev) {
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);
674 - }
675 -
676 - del_timer_sync(&local->dynamic_ps_timer);
677 - cancel_work_sync(&local->dynamic_ps_enable_work);
678 -
679 - cancel_work_sync(&sdata->recalc_smps);
680 - sdata_lock(sdata);
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;
689 - }
690 - mutex_unlock(&local->mtx);
691 - sdata_unlock(sdata);
692 -
693 - cancel_work_sync(&sdata->csa_finalize_work);
694 -
695 - cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
696 -
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,
705 - GFP_KERNEL);
706 - }
707 -
708 - /* APs need special treatment */
709 - if (sdata->vif.type == NL80211_IFTYPE_AP) {
710 - struct ieee80211_sub_if_data *vlan, *tmpsdata;
711 -
712 - /* down all dependent devices, that is VLANs */
713 - list_for_each_entry_safe(vlan, tmpsdata, &sdata->u.ap.vlans,
714 - u.vlan.list)
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;
720 -
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);
727 - }
728 - }
729 - spin_unlock_irqrestore(&ps->bc_buf.lock, flags);
730 - }
731 -
732 - if (going_down)
733 - local->open_count--;
734 -
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 */
744 - break;
745 - case NL80211_IFTYPE_MONITOR:
746 - if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES) {
747 - local->cooked_mntrs--;
748 - break;
749 - }
750 -
751 - local->monitors--;
752 - if (local->monitors == 0) {
753 - local->hw.conf.flags &= ~IEEE80211_CONF_MONITOR;
754 - hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR;
755 - }
756 -
757 - ieee80211_adjust_monitor_flags(sdata, -1);
758 - break;
759 - case NL80211_IFTYPE_NAN:
760 - /* clean all the functions */
761 - spin_lock_bh(&sdata->u.nan.func_lock);
762 -
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);
766 - }
767 - idr_destroy(&sdata->u.nan.function_inst_ids);
768 -
769 - spin_unlock_bh(&sdata->u.nan.func_lock);
770 - break;
771 - case NL80211_IFTYPE_P2P_DEVICE:
772 - /* relies on synchronize_rcu() below */
773 - RCU_INIT_POINTER(local->p2p_sdata, NULL);
774 - fallthrough;
775 - default:
776 - cancel_work_sync(&sdata->work);
777 - /*
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)
783 - *
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
787 - * another CPU.
788 - */
789 - ieee80211_free_keys(sdata, true);
790 - skb_queue_purge(&sdata->skb_queue);
791 - }
792 -
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);
800 - }
801 - }
802 - }
803 - spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
804 -
805 - if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
806 - ieee80211_txq_remove_vlan(local, sdata);
807 -
808 - sdata->bss = NULL;
809 -
810 - if (local->open_count == 0)
811 - ieee80211_clear_tx_pending(local);
812 -
813 - sdata->vif.bss_conf.beacon_int = 0;
814 -
815 - /*
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
822 - * mac80211 here?
823 - */
824 - if (local->suspended) {
825 - WARN_ON(local->wowlan);
826 - WARN_ON(rtnl_dereference(local->monitor_sdata));
827 - return;
828 - }
829 -
830 - switch (sdata->vif.type) {
831 - case NL80211_IFTYPE_AP_VLAN:
832 - break;
833 - case NL80211_IFTYPE_MONITOR:
834 - if (local->monitors == 0)
835 - ieee80211_del_virtual_monitor(local);
836 -
837 - mutex_lock(&local->mtx);
838 - ieee80211_recalc_idle(local);
839 - mutex_unlock(&local->mtx);
840 -
841 - if (!(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE))
842 - break;
843 -
844 - fallthrough;
845 - default:
846 - if (going_down)
847 - drv_remove_interface(local, sdata);
848 - }
849 -
850 - ieee80211_recalc_ps(local);
851 -
852 - if (cancel_scan)
853 - flush_delayed_work(&local->scan_work);
854 -
855 - if (local->open_count == 0) {
856 - ieee80211_stop_device(local);
857 -
858 - /* no reconfiguring after stop! */
859 - return;
860 - }
861 -
862 - /* do after stop to avoid reconfiguring when we stop anyway */
863 - ieee80211_configure_filter(local);
864 - ieee80211_hw_config(local, hw_reconf_flags);
865 -
866 - if (local->monitors == local->open_count)
867 - ieee80211_add_virtual_monitor(local);
868 -}
869 -
870 -static int ieee80211_stop(struct net_device *dev)
871 -{
872 - struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
873 -
874 - ieee80211_do_stop(sdata, true);
875 -
876 - return 0;
877 -}
878 -
879 -static void ieee80211_set_multicast_list(struct net_device *dev)
880 -{
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;
884 -
885 - allmulti = !!(dev->flags & IFF_ALLMULTI);
886 - sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
887 -
888 - if (allmulti != sdata_allmulti) {
889 - if (dev->flags & IFF_ALLMULTI)
890 - atomic_inc(&local->iff_allmultis);
891 - else
892 - atomic_dec(&local->iff_allmultis);
893 - sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
894 - }
895 -
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);
900 -}
901 -
902 -/*
903 - * Called when the netdev is removed or, by the code below, before
904 - * the interface type changes.
905 - */
906 -static void ieee80211_teardown_sdata(struct ieee80211_sub_if_data *sdata)
907 -{
908 - int i;
909 -
910 - /* free extra data */
911 - ieee80211_free_keys(sdata, false);
912 -
913 - ieee80211_debugfs_remove_netdev(sdata);
914 -
915 - for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
916 - __skb_queue_purge(&sdata->fragments[i].skb_list);
917 - sdata->fragment_next = 0;
918 -
919 - if (ieee80211_vif_is_mesh(&sdata->vif))
920 - ieee80211_mesh_teardown_sdata(sdata);
921 -}
922 -
923 -static void ieee80211_uninit(struct net_device *dev)
924 -{
925 - ieee80211_teardown_sdata(IEEE80211_DEV_TO_SUB_IF(dev));
926 -}
927 -
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,
941 - void *accel_priv,
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,
946 - void *accel_priv)
947 -#else
948 -static u16 ieee80211_netdev_select_queue(struct net_device *dev,
949 - struct sk_buff *skb)
950 -#endif
951 -{
952 - return ieee80211_select_queue(IEEE80211_DEV_TO_SUB_IF(dev), skb);
953 -}
954 -
955 -static void
956 -ieee80211_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
957 -{
958 - int i;
959 -
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;
964 -
965 - tstats = per_cpu_ptr(netdev_tstats(dev), i);
966 -
967 - do {
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));
974 -
975 - stats->rx_packets += rx_packets;
976 - stats->tx_packets += tx_packets;
977 - stats->rx_bytes += rx_bytes;
978 - stats->tx_bytes += tx_bytes;
979 - }
980 -}
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);
989 - return stats;
990 -}
991 -#endif
992 -
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,
1003 -#else
1004 - .ndo_get_stats64 = bp_ieee80211_get_stats64,
1005 -#endif
1006 -
1007 -};
1008 -
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,
1022 - void *accel_priv,
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,
1027 - void *accel_priv)
1028 -#else
1029 -static u16 ieee80211_monitor_select_queue(struct net_device *dev,
1030 - struct sk_buff *skb)
1031 -#endif
1032 -{
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;
1037 - int len_rthdr;
1038 -
1039 - if (local->hw.queues < IEEE80211_NUM_ACS)
1040 - return 0;
1041 -
1042 - /* reset flags and info before parsing radiotap header */
1043 - memset(info, 0, sizeof(*info));
1044 -
1045 - if (!ieee80211_parse_tx_radiotap(skb, dev))
1046 - return 0; /* doesn't matter, frame will be dropped */
1047 -
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 */
1053 -
1054 - return ieee80211_select_queue_80211(sdata, skb, hdr);
1055 -}
1056 -
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,
1067 -#else
1068 - .ndo_get_stats64 = bp_ieee80211_get_stats64,
1069 -#endif
1070 -
1071 -};
1072 -
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,
1083 -#else
1084 - .ndo_get_stats64 = bp_ieee80211_get_stats64,
1085 -#endif
1086 -
1087 -};
1088 -
1089 static void ieee80211_if_free(struct net_device *dev)
1090 {
1091 free_percpu(netdev_tstats(dev));
1092 @@ -1408,32 +1432,6 @@ static void ieee80211_if_setup_no_queue(
1093 #endif
1094 }
1095
1096 -static void ieee80211_set_vif_encap_ops(struct ieee80211_sub_if_data *sdata)
1097 -{
1098 - struct ieee80211_local *local = sdata->local;
1099 - struct ieee80211_sub_if_data *bss = sdata;
1100 - bool enabled;
1101 -
1102 - if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
1103 - if (!sdata->bss)
1104 - return;
1105 -
1106 - bss = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap);
1107 - }
1108 -
1109 - if (!ieee80211_hw_check(&local->hw, SUPPORTS_TX_ENCAP_OFFLOAD) ||
1110 - !ieee80211_iftype_supports_encap_offload(bss->vif.type))
1111 - return;
1112 -
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))
1116 - enabled = false;
1117 -
1118 - sdata->dev->netdev_ops = enabled ? &ieee80211_dataif_8023_ops :
1119 - &ieee80211_dataif_ops;
1120 -}
1121 -
1122 static void ieee80211_iface_work(struct work_struct *work)
1123 {
1124 struct ieee80211_sub_if_data *sdata =