]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - net/mac80211/driver-ops.h
Merge tag 'trace-fixes-v4.3-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git...
[karo-tx-linux.git] / net / mac80211 / driver-ops.h
1 #ifndef __MAC80211_DRIVER_OPS
2 #define __MAC80211_DRIVER_OPS
3
4 #include <net/mac80211.h>
5 #include "ieee80211_i.h"
6 #include "trace.h"
7
8 static inline bool check_sdata_in_driver(struct ieee80211_sub_if_data *sdata)
9 {
10         return !WARN(!(sdata->flags & IEEE80211_SDATA_IN_DRIVER),
11                      "%s:  Failed check-sdata-in-driver check, flags: 0x%x\n",
12                      sdata->dev ? sdata->dev->name : sdata->name, sdata->flags);
13 }
14
15 static inline struct ieee80211_sub_if_data *
16 get_bss_sdata(struct ieee80211_sub_if_data *sdata)
17 {
18         if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
19                 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
20                                      u.ap);
21
22         return sdata;
23 }
24
25 static inline void drv_tx(struct ieee80211_local *local,
26                           struct ieee80211_tx_control *control,
27                           struct sk_buff *skb)
28 {
29         local->ops->tx(&local->hw, control, skb);
30 }
31
32 static inline void drv_get_et_strings(struct ieee80211_sub_if_data *sdata,
33                                       u32 sset, u8 *data)
34 {
35         struct ieee80211_local *local = sdata->local;
36         if (local->ops->get_et_strings) {
37                 trace_drv_get_et_strings(local, sset);
38                 local->ops->get_et_strings(&local->hw, &sdata->vif, sset, data);
39                 trace_drv_return_void(local);
40         }
41 }
42
43 static inline void drv_get_et_stats(struct ieee80211_sub_if_data *sdata,
44                                     struct ethtool_stats *stats,
45                                     u64 *data)
46 {
47         struct ieee80211_local *local = sdata->local;
48         if (local->ops->get_et_stats) {
49                 trace_drv_get_et_stats(local);
50                 local->ops->get_et_stats(&local->hw, &sdata->vif, stats, data);
51                 trace_drv_return_void(local);
52         }
53 }
54
55 static inline int drv_get_et_sset_count(struct ieee80211_sub_if_data *sdata,
56                                         int sset)
57 {
58         struct ieee80211_local *local = sdata->local;
59         int rv = 0;
60         if (local->ops->get_et_sset_count) {
61                 trace_drv_get_et_sset_count(local, sset);
62                 rv = local->ops->get_et_sset_count(&local->hw, &sdata->vif,
63                                                    sset);
64                 trace_drv_return_int(local, rv);
65         }
66         return rv;
67 }
68
69 static inline int drv_start(struct ieee80211_local *local)
70 {
71         int ret;
72
73         might_sleep();
74
75         trace_drv_start(local);
76         local->started = true;
77         smp_mb();
78         ret = local->ops->start(&local->hw);
79         trace_drv_return_int(local, ret);
80         return ret;
81 }
82
83 static inline void drv_stop(struct ieee80211_local *local)
84 {
85         might_sleep();
86
87         trace_drv_stop(local);
88         local->ops->stop(&local->hw);
89         trace_drv_return_void(local);
90
91         /* sync away all work on the tasklet before clearing started */
92         tasklet_disable(&local->tasklet);
93         tasklet_enable(&local->tasklet);
94
95         barrier();
96
97         local->started = false;
98 }
99
100 #ifdef CONFIG_PM
101 static inline int drv_suspend(struct ieee80211_local *local,
102                               struct cfg80211_wowlan *wowlan)
103 {
104         int ret;
105
106         might_sleep();
107
108         trace_drv_suspend(local);
109         ret = local->ops->suspend(&local->hw, wowlan);
110         trace_drv_return_int(local, ret);
111         return ret;
112 }
113
114 static inline int drv_resume(struct ieee80211_local *local)
115 {
116         int ret;
117
118         might_sleep();
119
120         trace_drv_resume(local);
121         ret = local->ops->resume(&local->hw);
122         trace_drv_return_int(local, ret);
123         return ret;
124 }
125
126 static inline void drv_set_wakeup(struct ieee80211_local *local,
127                                   bool enabled)
128 {
129         might_sleep();
130
131         if (!local->ops->set_wakeup)
132                 return;
133
134         trace_drv_set_wakeup(local, enabled);
135         local->ops->set_wakeup(&local->hw, enabled);
136         trace_drv_return_void(local);
137 }
138 #endif
139
140 static inline int drv_add_interface(struct ieee80211_local *local,
141                                     struct ieee80211_sub_if_data *sdata)
142 {
143         int ret;
144
145         might_sleep();
146
147         if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
148                     (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
149                      !ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF) &&
150                      !(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))))
151                 return -EINVAL;
152
153         trace_drv_add_interface(local, sdata);
154         ret = local->ops->add_interface(&local->hw, &sdata->vif);
155         trace_drv_return_int(local, ret);
156
157         if (ret == 0)
158                 sdata->flags |= IEEE80211_SDATA_IN_DRIVER;
159
160         return ret;
161 }
162
163 static inline int drv_change_interface(struct ieee80211_local *local,
164                                        struct ieee80211_sub_if_data *sdata,
165                                        enum nl80211_iftype type, bool p2p)
166 {
167         int ret;
168
169         might_sleep();
170
171         if (!check_sdata_in_driver(sdata))
172                 return -EIO;
173
174         trace_drv_change_interface(local, sdata, type, p2p);
175         ret = local->ops->change_interface(&local->hw, &sdata->vif, type, p2p);
176         trace_drv_return_int(local, ret);
177         return ret;
178 }
179
180 static inline void drv_remove_interface(struct ieee80211_local *local,
181                                         struct ieee80211_sub_if_data *sdata)
182 {
183         might_sleep();
184
185         if (!check_sdata_in_driver(sdata))
186                 return;
187
188         trace_drv_remove_interface(local, sdata);
189         local->ops->remove_interface(&local->hw, &sdata->vif);
190         sdata->flags &= ~IEEE80211_SDATA_IN_DRIVER;
191         trace_drv_return_void(local);
192 }
193
194 static inline int drv_config(struct ieee80211_local *local, u32 changed)
195 {
196         int ret;
197
198         might_sleep();
199
200         trace_drv_config(local, changed);
201         ret = local->ops->config(&local->hw, changed);
202         trace_drv_return_int(local, ret);
203         return ret;
204 }
205
206 static inline void drv_bss_info_changed(struct ieee80211_local *local,
207                                         struct ieee80211_sub_if_data *sdata,
208                                         struct ieee80211_bss_conf *info,
209                                         u32 changed)
210 {
211         might_sleep();
212
213         if (WARN_ON_ONCE(changed & (BSS_CHANGED_BEACON |
214                                     BSS_CHANGED_BEACON_ENABLED) &&
215                          sdata->vif.type != NL80211_IFTYPE_AP &&
216                          sdata->vif.type != NL80211_IFTYPE_ADHOC &&
217                          sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
218                          sdata->vif.type != NL80211_IFTYPE_OCB))
219                 return;
220
221         if (WARN_ON_ONCE(sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE ||
222                          sdata->vif.type == NL80211_IFTYPE_MONITOR))
223                 return;
224
225         if (!check_sdata_in_driver(sdata))
226                 return;
227
228         trace_drv_bss_info_changed(local, sdata, info, changed);
229         if (local->ops->bss_info_changed)
230                 local->ops->bss_info_changed(&local->hw, &sdata->vif, info, changed);
231         trace_drv_return_void(local);
232 }
233
234 static inline u64 drv_prepare_multicast(struct ieee80211_local *local,
235                                         struct netdev_hw_addr_list *mc_list)
236 {
237         u64 ret = 0;
238
239         trace_drv_prepare_multicast(local, mc_list->count);
240
241         if (local->ops->prepare_multicast)
242                 ret = local->ops->prepare_multicast(&local->hw, mc_list);
243
244         trace_drv_return_u64(local, ret);
245
246         return ret;
247 }
248
249 static inline void drv_configure_filter(struct ieee80211_local *local,
250                                         unsigned int changed_flags,
251                                         unsigned int *total_flags,
252                                         u64 multicast)
253 {
254         might_sleep();
255
256         trace_drv_configure_filter(local, changed_flags, total_flags,
257                                    multicast);
258         local->ops->configure_filter(&local->hw, changed_flags, total_flags,
259                                      multicast);
260         trace_drv_return_void(local);
261 }
262
263 static inline int drv_set_tim(struct ieee80211_local *local,
264                               struct ieee80211_sta *sta, bool set)
265 {
266         int ret = 0;
267         trace_drv_set_tim(local, sta, set);
268         if (local->ops->set_tim)
269                 ret = local->ops->set_tim(&local->hw, sta, set);
270         trace_drv_return_int(local, ret);
271         return ret;
272 }
273
274 static inline int drv_set_key(struct ieee80211_local *local,
275                               enum set_key_cmd cmd,
276                               struct ieee80211_sub_if_data *sdata,
277                               struct ieee80211_sta *sta,
278                               struct ieee80211_key_conf *key)
279 {
280         int ret;
281
282         might_sleep();
283
284         sdata = get_bss_sdata(sdata);
285         if (!check_sdata_in_driver(sdata))
286                 return -EIO;
287
288         trace_drv_set_key(local, cmd, sdata, sta, key);
289         ret = local->ops->set_key(&local->hw, cmd, &sdata->vif, sta, key);
290         trace_drv_return_int(local, ret);
291         return ret;
292 }
293
294 static inline void drv_update_tkip_key(struct ieee80211_local *local,
295                                        struct ieee80211_sub_if_data *sdata,
296                                        struct ieee80211_key_conf *conf,
297                                        struct sta_info *sta, u32 iv32,
298                                        u16 *phase1key)
299 {
300         struct ieee80211_sta *ista = NULL;
301
302         if (sta)
303                 ista = &sta->sta;
304
305         sdata = get_bss_sdata(sdata);
306         if (!check_sdata_in_driver(sdata))
307                 return;
308
309         trace_drv_update_tkip_key(local, sdata, conf, ista, iv32);
310         if (local->ops->update_tkip_key)
311                 local->ops->update_tkip_key(&local->hw, &sdata->vif, conf,
312                                             ista, iv32, phase1key);
313         trace_drv_return_void(local);
314 }
315
316 static inline int drv_hw_scan(struct ieee80211_local *local,
317                               struct ieee80211_sub_if_data *sdata,
318                               struct ieee80211_scan_request *req)
319 {
320         int ret;
321
322         might_sleep();
323
324         if (!check_sdata_in_driver(sdata))
325                 return -EIO;
326
327         trace_drv_hw_scan(local, sdata);
328         ret = local->ops->hw_scan(&local->hw, &sdata->vif, req);
329         trace_drv_return_int(local, ret);
330         return ret;
331 }
332
333 static inline void drv_cancel_hw_scan(struct ieee80211_local *local,
334                                       struct ieee80211_sub_if_data *sdata)
335 {
336         might_sleep();
337
338         if (!check_sdata_in_driver(sdata))
339                 return;
340
341         trace_drv_cancel_hw_scan(local, sdata);
342         local->ops->cancel_hw_scan(&local->hw, &sdata->vif);
343         trace_drv_return_void(local);
344 }
345
346 static inline int
347 drv_sched_scan_start(struct ieee80211_local *local,
348                      struct ieee80211_sub_if_data *sdata,
349                      struct cfg80211_sched_scan_request *req,
350                      struct ieee80211_scan_ies *ies)
351 {
352         int ret;
353
354         might_sleep();
355
356         if (!check_sdata_in_driver(sdata))
357                 return -EIO;
358
359         trace_drv_sched_scan_start(local, sdata);
360         ret = local->ops->sched_scan_start(&local->hw, &sdata->vif,
361                                               req, ies);
362         trace_drv_return_int(local, ret);
363         return ret;
364 }
365
366 static inline int drv_sched_scan_stop(struct ieee80211_local *local,
367                                       struct ieee80211_sub_if_data *sdata)
368 {
369         int ret;
370
371         might_sleep();
372
373         if (!check_sdata_in_driver(sdata))
374                 return -EIO;
375
376         trace_drv_sched_scan_stop(local, sdata);
377         ret = local->ops->sched_scan_stop(&local->hw, &sdata->vif);
378         trace_drv_return_int(local, ret);
379
380         return ret;
381 }
382
383 static inline void drv_sw_scan_start(struct ieee80211_local *local,
384                                      struct ieee80211_sub_if_data *sdata,
385                                      const u8 *mac_addr)
386 {
387         might_sleep();
388
389         trace_drv_sw_scan_start(local, sdata, mac_addr);
390         if (local->ops->sw_scan_start)
391                 local->ops->sw_scan_start(&local->hw, &sdata->vif, mac_addr);
392         trace_drv_return_void(local);
393 }
394
395 static inline void drv_sw_scan_complete(struct ieee80211_local *local,
396                                         struct ieee80211_sub_if_data *sdata)
397 {
398         might_sleep();
399
400         trace_drv_sw_scan_complete(local, sdata);
401         if (local->ops->sw_scan_complete)
402                 local->ops->sw_scan_complete(&local->hw, &sdata->vif);
403         trace_drv_return_void(local);
404 }
405
406 static inline int drv_get_stats(struct ieee80211_local *local,
407                                 struct ieee80211_low_level_stats *stats)
408 {
409         int ret = -EOPNOTSUPP;
410
411         might_sleep();
412
413         if (local->ops->get_stats)
414                 ret = local->ops->get_stats(&local->hw, stats);
415         trace_drv_get_stats(local, stats, ret);
416
417         return ret;
418 }
419
420 static inline void drv_get_key_seq(struct ieee80211_local *local,
421                                    struct ieee80211_key *key,
422                                    struct ieee80211_key_seq *seq)
423 {
424         if (local->ops->get_key_seq)
425                 local->ops->get_key_seq(&local->hw, &key->conf, seq);
426         trace_drv_get_key_seq(local, &key->conf);
427 }
428
429 static inline int drv_set_frag_threshold(struct ieee80211_local *local,
430                                         u32 value)
431 {
432         int ret = 0;
433
434         might_sleep();
435
436         trace_drv_set_frag_threshold(local, value);
437         if (local->ops->set_frag_threshold)
438                 ret = local->ops->set_frag_threshold(&local->hw, value);
439         trace_drv_return_int(local, ret);
440         return ret;
441 }
442
443 static inline int drv_set_rts_threshold(struct ieee80211_local *local,
444                                         u32 value)
445 {
446         int ret = 0;
447
448         might_sleep();
449
450         trace_drv_set_rts_threshold(local, value);
451         if (local->ops->set_rts_threshold)
452                 ret = local->ops->set_rts_threshold(&local->hw, value);
453         trace_drv_return_int(local, ret);
454         return ret;
455 }
456
457 static inline int drv_set_coverage_class(struct ieee80211_local *local,
458                                          s16 value)
459 {
460         int ret = 0;
461         might_sleep();
462
463         trace_drv_set_coverage_class(local, value);
464         if (local->ops->set_coverage_class)
465                 local->ops->set_coverage_class(&local->hw, value);
466         else
467                 ret = -EOPNOTSUPP;
468
469         trace_drv_return_int(local, ret);
470         return ret;
471 }
472
473 static inline void drv_sta_notify(struct ieee80211_local *local,
474                                   struct ieee80211_sub_if_data *sdata,
475                                   enum sta_notify_cmd cmd,
476                                   struct ieee80211_sta *sta)
477 {
478         sdata = get_bss_sdata(sdata);
479         if (!check_sdata_in_driver(sdata))
480                 return;
481
482         trace_drv_sta_notify(local, sdata, cmd, sta);
483         if (local->ops->sta_notify)
484                 local->ops->sta_notify(&local->hw, &sdata->vif, cmd, sta);
485         trace_drv_return_void(local);
486 }
487
488 static inline int drv_sta_add(struct ieee80211_local *local,
489                               struct ieee80211_sub_if_data *sdata,
490                               struct ieee80211_sta *sta)
491 {
492         int ret = 0;
493
494         might_sleep();
495
496         sdata = get_bss_sdata(sdata);
497         if (!check_sdata_in_driver(sdata))
498                 return -EIO;
499
500         trace_drv_sta_add(local, sdata, sta);
501         if (local->ops->sta_add)
502                 ret = local->ops->sta_add(&local->hw, &sdata->vif, sta);
503
504         trace_drv_return_int(local, ret);
505
506         return ret;
507 }
508
509 static inline void drv_sta_remove(struct ieee80211_local *local,
510                                   struct ieee80211_sub_if_data *sdata,
511                                   struct ieee80211_sta *sta)
512 {
513         might_sleep();
514
515         sdata = get_bss_sdata(sdata);
516         if (!check_sdata_in_driver(sdata))
517                 return;
518
519         trace_drv_sta_remove(local, sdata, sta);
520         if (local->ops->sta_remove)
521                 local->ops->sta_remove(&local->hw, &sdata->vif, sta);
522
523         trace_drv_return_void(local);
524 }
525
526 #ifdef CONFIG_MAC80211_DEBUGFS
527 static inline void drv_sta_add_debugfs(struct ieee80211_local *local,
528                                        struct ieee80211_sub_if_data *sdata,
529                                        struct ieee80211_sta *sta,
530                                        struct dentry *dir)
531 {
532         might_sleep();
533
534         sdata = get_bss_sdata(sdata);
535         if (!check_sdata_in_driver(sdata))
536                 return;
537
538         if (local->ops->sta_add_debugfs)
539                 local->ops->sta_add_debugfs(&local->hw, &sdata->vif,
540                                             sta, dir);
541 }
542
543 static inline void drv_sta_remove_debugfs(struct ieee80211_local *local,
544                                           struct ieee80211_sub_if_data *sdata,
545                                           struct ieee80211_sta *sta,
546                                           struct dentry *dir)
547 {
548         might_sleep();
549
550         sdata = get_bss_sdata(sdata);
551         check_sdata_in_driver(sdata);
552
553         if (local->ops->sta_remove_debugfs)
554                 local->ops->sta_remove_debugfs(&local->hw, &sdata->vif,
555                                                sta, dir);
556 }
557 #endif
558
559 static inline void drv_sta_pre_rcu_remove(struct ieee80211_local *local,
560                                           struct ieee80211_sub_if_data *sdata,
561                                           struct sta_info *sta)
562 {
563         might_sleep();
564
565         sdata = get_bss_sdata(sdata);
566         if (!check_sdata_in_driver(sdata))
567                 return;
568
569         trace_drv_sta_pre_rcu_remove(local, sdata, &sta->sta);
570         if (local->ops->sta_pre_rcu_remove)
571                 local->ops->sta_pre_rcu_remove(&local->hw, &sdata->vif,
572                                                &sta->sta);
573         trace_drv_return_void(local);
574 }
575
576 __must_check
577 int drv_sta_state(struct ieee80211_local *local,
578                   struct ieee80211_sub_if_data *sdata,
579                   struct sta_info *sta,
580                   enum ieee80211_sta_state old_state,
581                   enum ieee80211_sta_state new_state);
582
583 static inline void drv_sta_rc_update(struct ieee80211_local *local,
584                                      struct ieee80211_sub_if_data *sdata,
585                                      struct ieee80211_sta *sta, u32 changed)
586 {
587         sdata = get_bss_sdata(sdata);
588         if (!check_sdata_in_driver(sdata))
589                 return;
590
591         WARN_ON(changed & IEEE80211_RC_SUPP_RATES_CHANGED &&
592                 (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
593                  sdata->vif.type != NL80211_IFTYPE_MESH_POINT));
594
595         trace_drv_sta_rc_update(local, sdata, sta, changed);
596         if (local->ops->sta_rc_update)
597                 local->ops->sta_rc_update(&local->hw, &sdata->vif,
598                                           sta, changed);
599
600         trace_drv_return_void(local);
601 }
602
603 static inline void drv_sta_rate_tbl_update(struct ieee80211_local *local,
604                                            struct ieee80211_sub_if_data *sdata,
605                                            struct ieee80211_sta *sta)
606 {
607         sdata = get_bss_sdata(sdata);
608         if (!check_sdata_in_driver(sdata))
609                 return;
610
611         trace_drv_sta_rate_tbl_update(local, sdata, sta);
612         if (local->ops->sta_rate_tbl_update)
613                 local->ops->sta_rate_tbl_update(&local->hw, &sdata->vif, sta);
614
615         trace_drv_return_void(local);
616 }
617
618 static inline void drv_sta_statistics(struct ieee80211_local *local,
619                                       struct ieee80211_sub_if_data *sdata,
620                                       struct ieee80211_sta *sta,
621                                       struct station_info *sinfo)
622 {
623         sdata = get_bss_sdata(sdata);
624         if (!check_sdata_in_driver(sdata))
625                 return;
626
627         trace_drv_sta_statistics(local, sdata, sta);
628         if (local->ops->sta_statistics)
629                 local->ops->sta_statistics(&local->hw, &sdata->vif, sta, sinfo);
630         trace_drv_return_void(local);
631 }
632
633 static inline int drv_conf_tx(struct ieee80211_local *local,
634                               struct ieee80211_sub_if_data *sdata, u16 ac,
635                               const struct ieee80211_tx_queue_params *params)
636 {
637         int ret = -EOPNOTSUPP;
638
639         might_sleep();
640
641         if (!check_sdata_in_driver(sdata))
642                 return -EIO;
643
644         if (WARN_ONCE(params->cw_min == 0 ||
645                       params->cw_min > params->cw_max,
646                       "%s: invalid CW_min/CW_max: %d/%d\n",
647                       sdata->name, params->cw_min, params->cw_max))
648                 return -EINVAL;
649
650         trace_drv_conf_tx(local, sdata, ac, params);
651         if (local->ops->conf_tx)
652                 ret = local->ops->conf_tx(&local->hw, &sdata->vif,
653                                           ac, params);
654         trace_drv_return_int(local, ret);
655         return ret;
656 }
657
658 static inline u64 drv_get_tsf(struct ieee80211_local *local,
659                               struct ieee80211_sub_if_data *sdata)
660 {
661         u64 ret = -1ULL;
662
663         might_sleep();
664
665         if (!check_sdata_in_driver(sdata))
666                 return ret;
667
668         trace_drv_get_tsf(local, sdata);
669         if (local->ops->get_tsf)
670                 ret = local->ops->get_tsf(&local->hw, &sdata->vif);
671         trace_drv_return_u64(local, ret);
672         return ret;
673 }
674
675 static inline void drv_set_tsf(struct ieee80211_local *local,
676                                struct ieee80211_sub_if_data *sdata,
677                                u64 tsf)
678 {
679         might_sleep();
680
681         if (!check_sdata_in_driver(sdata))
682                 return;
683
684         trace_drv_set_tsf(local, sdata, tsf);
685         if (local->ops->set_tsf)
686                 local->ops->set_tsf(&local->hw, &sdata->vif, tsf);
687         trace_drv_return_void(local);
688 }
689
690 static inline void drv_reset_tsf(struct ieee80211_local *local,
691                                  struct ieee80211_sub_if_data *sdata)
692 {
693         might_sleep();
694
695         if (!check_sdata_in_driver(sdata))
696                 return;
697
698         trace_drv_reset_tsf(local, sdata);
699         if (local->ops->reset_tsf)
700                 local->ops->reset_tsf(&local->hw, &sdata->vif);
701         trace_drv_return_void(local);
702 }
703
704 static inline int drv_tx_last_beacon(struct ieee80211_local *local)
705 {
706         int ret = 0; /* default unsupported op for less congestion */
707
708         might_sleep();
709
710         trace_drv_tx_last_beacon(local);
711         if (local->ops->tx_last_beacon)
712                 ret = local->ops->tx_last_beacon(&local->hw);
713         trace_drv_return_int(local, ret);
714         return ret;
715 }
716
717 static inline int drv_ampdu_action(struct ieee80211_local *local,
718                                    struct ieee80211_sub_if_data *sdata,
719                                    enum ieee80211_ampdu_mlme_action action,
720                                    struct ieee80211_sta *sta, u16 tid,
721                                    u16 *ssn, u8 buf_size)
722 {
723         int ret = -EOPNOTSUPP;
724
725         might_sleep();
726
727         sdata = get_bss_sdata(sdata);
728         if (!check_sdata_in_driver(sdata))
729                 return -EIO;
730
731         trace_drv_ampdu_action(local, sdata, action, sta, tid, ssn, buf_size);
732
733         if (local->ops->ampdu_action)
734                 ret = local->ops->ampdu_action(&local->hw, &sdata->vif, action,
735                                                sta, tid, ssn, buf_size);
736
737         trace_drv_return_int(local, ret);
738
739         return ret;
740 }
741
742 static inline int drv_get_survey(struct ieee80211_local *local, int idx,
743                                 struct survey_info *survey)
744 {
745         int ret = -EOPNOTSUPP;
746
747         trace_drv_get_survey(local, idx, survey);
748
749         if (local->ops->get_survey)
750                 ret = local->ops->get_survey(&local->hw, idx, survey);
751
752         trace_drv_return_int(local, ret);
753
754         return ret;
755 }
756
757 static inline void drv_rfkill_poll(struct ieee80211_local *local)
758 {
759         might_sleep();
760
761         if (local->ops->rfkill_poll)
762                 local->ops->rfkill_poll(&local->hw);
763 }
764
765 static inline void drv_flush(struct ieee80211_local *local,
766                              struct ieee80211_sub_if_data *sdata,
767                              u32 queues, bool drop)
768 {
769         struct ieee80211_vif *vif = sdata ? &sdata->vif : NULL;
770
771         might_sleep();
772
773         if (sdata && !check_sdata_in_driver(sdata))
774                 return;
775
776         trace_drv_flush(local, queues, drop);
777         if (local->ops->flush)
778                 local->ops->flush(&local->hw, vif, queues, drop);
779         trace_drv_return_void(local);
780 }
781
782 static inline void drv_channel_switch(struct ieee80211_local *local,
783                                       struct ieee80211_sub_if_data *sdata,
784                                       struct ieee80211_channel_switch *ch_switch)
785 {
786         might_sleep();
787
788         trace_drv_channel_switch(local, sdata, ch_switch);
789         local->ops->channel_switch(&local->hw, &sdata->vif, ch_switch);
790         trace_drv_return_void(local);
791 }
792
793
794 static inline int drv_set_antenna(struct ieee80211_local *local,
795                                   u32 tx_ant, u32 rx_ant)
796 {
797         int ret = -EOPNOTSUPP;
798         might_sleep();
799         if (local->ops->set_antenna)
800                 ret = local->ops->set_antenna(&local->hw, tx_ant, rx_ant);
801         trace_drv_set_antenna(local, tx_ant, rx_ant, ret);
802         return ret;
803 }
804
805 static inline int drv_get_antenna(struct ieee80211_local *local,
806                                   u32 *tx_ant, u32 *rx_ant)
807 {
808         int ret = -EOPNOTSUPP;
809         might_sleep();
810         if (local->ops->get_antenna)
811                 ret = local->ops->get_antenna(&local->hw, tx_ant, rx_ant);
812         trace_drv_get_antenna(local, *tx_ant, *rx_ant, ret);
813         return ret;
814 }
815
816 static inline int drv_remain_on_channel(struct ieee80211_local *local,
817                                         struct ieee80211_sub_if_data *sdata,
818                                         struct ieee80211_channel *chan,
819                                         unsigned int duration,
820                                         enum ieee80211_roc_type type)
821 {
822         int ret;
823
824         might_sleep();
825
826         trace_drv_remain_on_channel(local, sdata, chan, duration, type);
827         ret = local->ops->remain_on_channel(&local->hw, &sdata->vif,
828                                             chan, duration, type);
829         trace_drv_return_int(local, ret);
830
831         return ret;
832 }
833
834 static inline int drv_cancel_remain_on_channel(struct ieee80211_local *local)
835 {
836         int ret;
837
838         might_sleep();
839
840         trace_drv_cancel_remain_on_channel(local);
841         ret = local->ops->cancel_remain_on_channel(&local->hw);
842         trace_drv_return_int(local, ret);
843
844         return ret;
845 }
846
847 static inline int drv_set_ringparam(struct ieee80211_local *local,
848                                     u32 tx, u32 rx)
849 {
850         int ret = -ENOTSUPP;
851
852         might_sleep();
853
854         trace_drv_set_ringparam(local, tx, rx);
855         if (local->ops->set_ringparam)
856                 ret = local->ops->set_ringparam(&local->hw, tx, rx);
857         trace_drv_return_int(local, ret);
858
859         return ret;
860 }
861
862 static inline void drv_get_ringparam(struct ieee80211_local *local,
863                                      u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
864 {
865         might_sleep();
866
867         trace_drv_get_ringparam(local, tx, tx_max, rx, rx_max);
868         if (local->ops->get_ringparam)
869                 local->ops->get_ringparam(&local->hw, tx, tx_max, rx, rx_max);
870         trace_drv_return_void(local);
871 }
872
873 static inline bool drv_tx_frames_pending(struct ieee80211_local *local)
874 {
875         bool ret = false;
876
877         might_sleep();
878
879         trace_drv_tx_frames_pending(local);
880         if (local->ops->tx_frames_pending)
881                 ret = local->ops->tx_frames_pending(&local->hw);
882         trace_drv_return_bool(local, ret);
883
884         return ret;
885 }
886
887 static inline int drv_set_bitrate_mask(struct ieee80211_local *local,
888                                        struct ieee80211_sub_if_data *sdata,
889                                        const struct cfg80211_bitrate_mask *mask)
890 {
891         int ret = -EOPNOTSUPP;
892
893         might_sleep();
894
895         if (!check_sdata_in_driver(sdata))
896                 return -EIO;
897
898         trace_drv_set_bitrate_mask(local, sdata, mask);
899         if (local->ops->set_bitrate_mask)
900                 ret = local->ops->set_bitrate_mask(&local->hw,
901                                                    &sdata->vif, mask);
902         trace_drv_return_int(local, ret);
903
904         return ret;
905 }
906
907 static inline void drv_set_rekey_data(struct ieee80211_local *local,
908                                       struct ieee80211_sub_if_data *sdata,
909                                       struct cfg80211_gtk_rekey_data *data)
910 {
911         if (!check_sdata_in_driver(sdata))
912                 return;
913
914         trace_drv_set_rekey_data(local, sdata, data);
915         if (local->ops->set_rekey_data)
916                 local->ops->set_rekey_data(&local->hw, &sdata->vif, data);
917         trace_drv_return_void(local);
918 }
919
920 static inline void drv_event_callback(struct ieee80211_local *local,
921                                       struct ieee80211_sub_if_data *sdata,
922                                       const struct ieee80211_event *event)
923 {
924         trace_drv_event_callback(local, sdata, event);
925         if (local->ops->event_callback)
926                 local->ops->event_callback(&local->hw, &sdata->vif, event);
927         trace_drv_return_void(local);
928 }
929
930 static inline void
931 drv_release_buffered_frames(struct ieee80211_local *local,
932                             struct sta_info *sta, u16 tids, int num_frames,
933                             enum ieee80211_frame_release_type reason,
934                             bool more_data)
935 {
936         trace_drv_release_buffered_frames(local, &sta->sta, tids, num_frames,
937                                           reason, more_data);
938         if (local->ops->release_buffered_frames)
939                 local->ops->release_buffered_frames(&local->hw, &sta->sta, tids,
940                                                     num_frames, reason,
941                                                     more_data);
942         trace_drv_return_void(local);
943 }
944
945 static inline void
946 drv_allow_buffered_frames(struct ieee80211_local *local,
947                           struct sta_info *sta, u16 tids, int num_frames,
948                           enum ieee80211_frame_release_type reason,
949                           bool more_data)
950 {
951         trace_drv_allow_buffered_frames(local, &sta->sta, tids, num_frames,
952                                         reason, more_data);
953         if (local->ops->allow_buffered_frames)
954                 local->ops->allow_buffered_frames(&local->hw, &sta->sta,
955                                                   tids, num_frames, reason,
956                                                   more_data);
957         trace_drv_return_void(local);
958 }
959
960 static inline void drv_mgd_prepare_tx(struct ieee80211_local *local,
961                                       struct ieee80211_sub_if_data *sdata)
962 {
963         might_sleep();
964
965         if (!check_sdata_in_driver(sdata))
966                 return;
967         WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION);
968
969         trace_drv_mgd_prepare_tx(local, sdata);
970         if (local->ops->mgd_prepare_tx)
971                 local->ops->mgd_prepare_tx(&local->hw, &sdata->vif);
972         trace_drv_return_void(local);
973 }
974
975 static inline void
976 drv_mgd_protect_tdls_discover(struct ieee80211_local *local,
977                               struct ieee80211_sub_if_data *sdata)
978 {
979         might_sleep();
980
981         if (!check_sdata_in_driver(sdata))
982                 return;
983         WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION);
984
985         trace_drv_mgd_protect_tdls_discover(local, sdata);
986         if (local->ops->mgd_protect_tdls_discover)
987                 local->ops->mgd_protect_tdls_discover(&local->hw, &sdata->vif);
988         trace_drv_return_void(local);
989 }
990
991 static inline int drv_add_chanctx(struct ieee80211_local *local,
992                                   struct ieee80211_chanctx *ctx)
993 {
994         int ret = -EOPNOTSUPP;
995
996         trace_drv_add_chanctx(local, ctx);
997         if (local->ops->add_chanctx)
998                 ret = local->ops->add_chanctx(&local->hw, &ctx->conf);
999         trace_drv_return_int(local, ret);
1000         if (!ret)
1001                 ctx->driver_present = true;
1002
1003         return ret;
1004 }
1005
1006 static inline void drv_remove_chanctx(struct ieee80211_local *local,
1007                                       struct ieee80211_chanctx *ctx)
1008 {
1009         if (WARN_ON(!ctx->driver_present))
1010                 return;
1011
1012         trace_drv_remove_chanctx(local, ctx);
1013         if (local->ops->remove_chanctx)
1014                 local->ops->remove_chanctx(&local->hw, &ctx->conf);
1015         trace_drv_return_void(local);
1016         ctx->driver_present = false;
1017 }
1018
1019 static inline void drv_change_chanctx(struct ieee80211_local *local,
1020                                       struct ieee80211_chanctx *ctx,
1021                                       u32 changed)
1022 {
1023         trace_drv_change_chanctx(local, ctx, changed);
1024         if (local->ops->change_chanctx) {
1025                 WARN_ON_ONCE(!ctx->driver_present);
1026                 local->ops->change_chanctx(&local->hw, &ctx->conf, changed);
1027         }
1028         trace_drv_return_void(local);
1029 }
1030
1031 static inline int drv_assign_vif_chanctx(struct ieee80211_local *local,
1032                                          struct ieee80211_sub_if_data *sdata,
1033                                          struct ieee80211_chanctx *ctx)
1034 {
1035         int ret = 0;
1036
1037         if (!check_sdata_in_driver(sdata))
1038                 return -EIO;
1039
1040         trace_drv_assign_vif_chanctx(local, sdata, ctx);
1041         if (local->ops->assign_vif_chanctx) {
1042                 WARN_ON_ONCE(!ctx->driver_present);
1043                 ret = local->ops->assign_vif_chanctx(&local->hw,
1044                                                      &sdata->vif,
1045                                                      &ctx->conf);
1046         }
1047         trace_drv_return_int(local, ret);
1048
1049         return ret;
1050 }
1051
1052 static inline void drv_unassign_vif_chanctx(struct ieee80211_local *local,
1053                                             struct ieee80211_sub_if_data *sdata,
1054                                             struct ieee80211_chanctx *ctx)
1055 {
1056         if (!check_sdata_in_driver(sdata))
1057                 return;
1058
1059         trace_drv_unassign_vif_chanctx(local, sdata, ctx);
1060         if (local->ops->unassign_vif_chanctx) {
1061                 WARN_ON_ONCE(!ctx->driver_present);
1062                 local->ops->unassign_vif_chanctx(&local->hw,
1063                                                  &sdata->vif,
1064                                                  &ctx->conf);
1065         }
1066         trace_drv_return_void(local);
1067 }
1068
1069 static inline int
1070 drv_switch_vif_chanctx(struct ieee80211_local *local,
1071                        struct ieee80211_vif_chanctx_switch *vifs,
1072                        int n_vifs,
1073                        enum ieee80211_chanctx_switch_mode mode)
1074 {
1075         int ret = 0;
1076         int i;
1077
1078         if (!local->ops->switch_vif_chanctx)
1079                 return -EOPNOTSUPP;
1080
1081         for (i = 0; i < n_vifs; i++) {
1082                 struct ieee80211_chanctx *new_ctx =
1083                         container_of(vifs[i].new_ctx,
1084                                      struct ieee80211_chanctx,
1085                                      conf);
1086                 struct ieee80211_chanctx *old_ctx =
1087                         container_of(vifs[i].old_ctx,
1088                                      struct ieee80211_chanctx,
1089                                      conf);
1090
1091                 WARN_ON_ONCE(!old_ctx->driver_present);
1092                 WARN_ON_ONCE((mode == CHANCTX_SWMODE_SWAP_CONTEXTS &&
1093                               new_ctx->driver_present) ||
1094                              (mode == CHANCTX_SWMODE_REASSIGN_VIF &&
1095                               !new_ctx->driver_present));
1096         }
1097
1098         trace_drv_switch_vif_chanctx(local, vifs, n_vifs, mode);
1099         ret = local->ops->switch_vif_chanctx(&local->hw,
1100                                              vifs, n_vifs, mode);
1101         trace_drv_return_int(local, ret);
1102
1103         if (!ret && mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
1104                 for (i = 0; i < n_vifs; i++) {
1105                         struct ieee80211_chanctx *new_ctx =
1106                                 container_of(vifs[i].new_ctx,
1107                                              struct ieee80211_chanctx,
1108                                              conf);
1109                         struct ieee80211_chanctx *old_ctx =
1110                                 container_of(vifs[i].old_ctx,
1111                                              struct ieee80211_chanctx,
1112                                              conf);
1113
1114                         new_ctx->driver_present = true;
1115                         old_ctx->driver_present = false;
1116                 }
1117         }
1118
1119         return ret;
1120 }
1121
1122 static inline int drv_start_ap(struct ieee80211_local *local,
1123                                struct ieee80211_sub_if_data *sdata)
1124 {
1125         int ret = 0;
1126
1127         if (!check_sdata_in_driver(sdata))
1128                 return -EIO;
1129
1130         trace_drv_start_ap(local, sdata, &sdata->vif.bss_conf);
1131         if (local->ops->start_ap)
1132                 ret = local->ops->start_ap(&local->hw, &sdata->vif);
1133         trace_drv_return_int(local, ret);
1134         return ret;
1135 }
1136
1137 static inline void drv_stop_ap(struct ieee80211_local *local,
1138                                struct ieee80211_sub_if_data *sdata)
1139 {
1140         if (!check_sdata_in_driver(sdata))
1141                 return;
1142
1143         trace_drv_stop_ap(local, sdata);
1144         if (local->ops->stop_ap)
1145                 local->ops->stop_ap(&local->hw, &sdata->vif);
1146         trace_drv_return_void(local);
1147 }
1148
1149 static inline void
1150 drv_reconfig_complete(struct ieee80211_local *local,
1151                       enum ieee80211_reconfig_type reconfig_type)
1152 {
1153         might_sleep();
1154
1155         trace_drv_reconfig_complete(local, reconfig_type);
1156         if (local->ops->reconfig_complete)
1157                 local->ops->reconfig_complete(&local->hw, reconfig_type);
1158         trace_drv_return_void(local);
1159 }
1160
1161 static inline void
1162 drv_set_default_unicast_key(struct ieee80211_local *local,
1163                             struct ieee80211_sub_if_data *sdata,
1164                             int key_idx)
1165 {
1166         if (!check_sdata_in_driver(sdata))
1167                 return;
1168
1169         WARN_ON_ONCE(key_idx < -1 || key_idx > 3);
1170
1171         trace_drv_set_default_unicast_key(local, sdata, key_idx);
1172         if (local->ops->set_default_unicast_key)
1173                 local->ops->set_default_unicast_key(&local->hw, &sdata->vif,
1174                                                     key_idx);
1175         trace_drv_return_void(local);
1176 }
1177
1178 #if IS_ENABLED(CONFIG_IPV6)
1179 static inline void drv_ipv6_addr_change(struct ieee80211_local *local,
1180                                         struct ieee80211_sub_if_data *sdata,
1181                                         struct inet6_dev *idev)
1182 {
1183         trace_drv_ipv6_addr_change(local, sdata);
1184         if (local->ops->ipv6_addr_change)
1185                 local->ops->ipv6_addr_change(&local->hw, &sdata->vif, idev);
1186         trace_drv_return_void(local);
1187 }
1188 #endif
1189
1190 static inline void
1191 drv_channel_switch_beacon(struct ieee80211_sub_if_data *sdata,
1192                           struct cfg80211_chan_def *chandef)
1193 {
1194         struct ieee80211_local *local = sdata->local;
1195
1196         if (local->ops->channel_switch_beacon) {
1197                 trace_drv_channel_switch_beacon(local, sdata, chandef);
1198                 local->ops->channel_switch_beacon(&local->hw, &sdata->vif,
1199                                                   chandef);
1200         }
1201 }
1202
1203 static inline int
1204 drv_pre_channel_switch(struct ieee80211_sub_if_data *sdata,
1205                        struct ieee80211_channel_switch *ch_switch)
1206 {
1207         struct ieee80211_local *local = sdata->local;
1208         int ret = 0;
1209
1210         if (!check_sdata_in_driver(sdata))
1211                 return -EIO;
1212
1213         trace_drv_pre_channel_switch(local, sdata, ch_switch);
1214         if (local->ops->pre_channel_switch)
1215                 ret = local->ops->pre_channel_switch(&local->hw, &sdata->vif,
1216                                                      ch_switch);
1217         trace_drv_return_int(local, ret);
1218         return ret;
1219 }
1220
1221 static inline int
1222 drv_post_channel_switch(struct ieee80211_sub_if_data *sdata)
1223 {
1224         struct ieee80211_local *local = sdata->local;
1225         int ret = 0;
1226
1227         if (!check_sdata_in_driver(sdata))
1228                 return -EIO;
1229
1230         trace_drv_post_channel_switch(local, sdata);
1231         if (local->ops->post_channel_switch)
1232                 ret = local->ops->post_channel_switch(&local->hw, &sdata->vif);
1233         trace_drv_return_int(local, ret);
1234         return ret;
1235 }
1236
1237 static inline int drv_join_ibss(struct ieee80211_local *local,
1238                                 struct ieee80211_sub_if_data *sdata)
1239 {
1240         int ret = 0;
1241
1242         might_sleep();
1243         if (!check_sdata_in_driver(sdata))
1244                 return -EIO;
1245
1246         trace_drv_join_ibss(local, sdata, &sdata->vif.bss_conf);
1247         if (local->ops->join_ibss)
1248                 ret = local->ops->join_ibss(&local->hw, &sdata->vif);
1249         trace_drv_return_int(local, ret);
1250         return ret;
1251 }
1252
1253 static inline void drv_leave_ibss(struct ieee80211_local *local,
1254                                   struct ieee80211_sub_if_data *sdata)
1255 {
1256         might_sleep();
1257         if (!check_sdata_in_driver(sdata))
1258                 return;
1259
1260         trace_drv_leave_ibss(local, sdata);
1261         if (local->ops->leave_ibss)
1262                 local->ops->leave_ibss(&local->hw, &sdata->vif);
1263         trace_drv_return_void(local);
1264 }
1265
1266 static inline u32 drv_get_expected_throughput(struct ieee80211_local *local,
1267                                               struct ieee80211_sta *sta)
1268 {
1269         u32 ret = 0;
1270
1271         trace_drv_get_expected_throughput(sta);
1272         if (local->ops->get_expected_throughput)
1273                 ret = local->ops->get_expected_throughput(sta);
1274         trace_drv_return_u32(local, ret);
1275
1276         return ret;
1277 }
1278
1279 static inline int drv_get_txpower(struct ieee80211_local *local,
1280                                   struct ieee80211_sub_if_data *sdata, int *dbm)
1281 {
1282         int ret;
1283
1284         if (!local->ops->get_txpower)
1285                 return -EOPNOTSUPP;
1286
1287         ret = local->ops->get_txpower(&local->hw, &sdata->vif, dbm);
1288         trace_drv_get_txpower(local, sdata, *dbm, ret);
1289
1290         return ret;
1291 }
1292
1293 static inline int
1294 drv_tdls_channel_switch(struct ieee80211_local *local,
1295                         struct ieee80211_sub_if_data *sdata,
1296                         struct ieee80211_sta *sta, u8 oper_class,
1297                         struct cfg80211_chan_def *chandef,
1298                         struct sk_buff *tmpl_skb, u32 ch_sw_tm_ie)
1299 {
1300         int ret;
1301
1302         might_sleep();
1303         if (!check_sdata_in_driver(sdata))
1304                 return -EIO;
1305
1306         if (!local->ops->tdls_channel_switch)
1307                 return -EOPNOTSUPP;
1308
1309         trace_drv_tdls_channel_switch(local, sdata, sta, oper_class, chandef);
1310         ret = local->ops->tdls_channel_switch(&local->hw, &sdata->vif, sta,
1311                                               oper_class, chandef, tmpl_skb,
1312                                               ch_sw_tm_ie);
1313         trace_drv_return_int(local, ret);
1314         return ret;
1315 }
1316
1317 static inline void
1318 drv_tdls_cancel_channel_switch(struct ieee80211_local *local,
1319                                struct ieee80211_sub_if_data *sdata,
1320                                struct ieee80211_sta *sta)
1321 {
1322         might_sleep();
1323         if (!check_sdata_in_driver(sdata))
1324                 return;
1325
1326         if (!local->ops->tdls_cancel_channel_switch)
1327                 return;
1328
1329         trace_drv_tdls_cancel_channel_switch(local, sdata, sta);
1330         local->ops->tdls_cancel_channel_switch(&local->hw, &sdata->vif, sta);
1331         trace_drv_return_void(local);
1332 }
1333
1334 static inline void
1335 drv_tdls_recv_channel_switch(struct ieee80211_local *local,
1336                              struct ieee80211_sub_if_data *sdata,
1337                              struct ieee80211_tdls_ch_sw_params *params)
1338 {
1339         trace_drv_tdls_recv_channel_switch(local, sdata, params);
1340         if (local->ops->tdls_recv_channel_switch)
1341                 local->ops->tdls_recv_channel_switch(&local->hw, &sdata->vif,
1342                                                      params);
1343         trace_drv_return_void(local);
1344 }
1345
1346 static inline void drv_wake_tx_queue(struct ieee80211_local *local,
1347                                      struct txq_info *txq)
1348 {
1349         struct ieee80211_sub_if_data *sdata = vif_to_sdata(txq->txq.vif);
1350
1351         if (!check_sdata_in_driver(sdata))
1352                 return;
1353
1354         trace_drv_wake_tx_queue(local, sdata, txq);
1355         local->ops->wake_tx_queue(&local->hw, &txq->txq);
1356 }
1357
1358 #endif /* __MAC80211_DRIVER_OPS */