mac80211: Deinline drv_switch_vif_chanctx()
[cascardo/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 int drv_add_interface(struct ieee80211_local *local,
141                       struct ieee80211_sub_if_data *sdata);
142
143 int drv_change_interface(struct ieee80211_local *local,
144                          struct ieee80211_sub_if_data *sdata,
145                          enum nl80211_iftype type, bool p2p);
146
147 void drv_remove_interface(struct ieee80211_local *local,
148                           struct ieee80211_sub_if_data *sdata);
149
150 static inline int drv_config(struct ieee80211_local *local, u32 changed)
151 {
152         int ret;
153
154         might_sleep();
155
156         trace_drv_config(local, changed);
157         ret = local->ops->config(&local->hw, changed);
158         trace_drv_return_int(local, ret);
159         return ret;
160 }
161
162 static inline void drv_bss_info_changed(struct ieee80211_local *local,
163                                         struct ieee80211_sub_if_data *sdata,
164                                         struct ieee80211_bss_conf *info,
165                                         u32 changed)
166 {
167         might_sleep();
168
169         if (WARN_ON_ONCE(changed & (BSS_CHANGED_BEACON |
170                                     BSS_CHANGED_BEACON_ENABLED) &&
171                          sdata->vif.type != NL80211_IFTYPE_AP &&
172                          sdata->vif.type != NL80211_IFTYPE_ADHOC &&
173                          sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
174                          sdata->vif.type != NL80211_IFTYPE_OCB))
175                 return;
176
177         if (WARN_ON_ONCE(sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE ||
178                          sdata->vif.type == NL80211_IFTYPE_MONITOR))
179                 return;
180
181         if (!check_sdata_in_driver(sdata))
182                 return;
183
184         trace_drv_bss_info_changed(local, sdata, info, changed);
185         if (local->ops->bss_info_changed)
186                 local->ops->bss_info_changed(&local->hw, &sdata->vif, info, changed);
187         trace_drv_return_void(local);
188 }
189
190 static inline u64 drv_prepare_multicast(struct ieee80211_local *local,
191                                         struct netdev_hw_addr_list *mc_list)
192 {
193         u64 ret = 0;
194
195         trace_drv_prepare_multicast(local, mc_list->count);
196
197         if (local->ops->prepare_multicast)
198                 ret = local->ops->prepare_multicast(&local->hw, mc_list);
199
200         trace_drv_return_u64(local, ret);
201
202         return ret;
203 }
204
205 static inline void drv_configure_filter(struct ieee80211_local *local,
206                                         unsigned int changed_flags,
207                                         unsigned int *total_flags,
208                                         u64 multicast)
209 {
210         might_sleep();
211
212         trace_drv_configure_filter(local, changed_flags, total_flags,
213                                    multicast);
214         local->ops->configure_filter(&local->hw, changed_flags, total_flags,
215                                      multicast);
216         trace_drv_return_void(local);
217 }
218
219 static inline void drv_config_iface_filter(struct ieee80211_local *local,
220                                            struct ieee80211_sub_if_data *sdata,
221                                            unsigned int filter_flags,
222                                            unsigned int changed_flags)
223 {
224         might_sleep();
225
226         trace_drv_config_iface_filter(local, sdata, filter_flags,
227                                       changed_flags);
228         if (local->ops->config_iface_filter)
229                 local->ops->config_iface_filter(&local->hw, &sdata->vif,
230                                                 filter_flags,
231                                                 changed_flags);
232         trace_drv_return_void(local);
233 }
234
235 static inline int drv_set_tim(struct ieee80211_local *local,
236                               struct ieee80211_sta *sta, bool set)
237 {
238         int ret = 0;
239         trace_drv_set_tim(local, sta, set);
240         if (local->ops->set_tim)
241                 ret = local->ops->set_tim(&local->hw, sta, set);
242         trace_drv_return_int(local, ret);
243         return ret;
244 }
245
246 static inline int drv_set_key(struct ieee80211_local *local,
247                               enum set_key_cmd cmd,
248                               struct ieee80211_sub_if_data *sdata,
249                               struct ieee80211_sta *sta,
250                               struct ieee80211_key_conf *key)
251 {
252         int ret;
253
254         might_sleep();
255
256         sdata = get_bss_sdata(sdata);
257         if (!check_sdata_in_driver(sdata))
258                 return -EIO;
259
260         trace_drv_set_key(local, cmd, sdata, sta, key);
261         ret = local->ops->set_key(&local->hw, cmd, &sdata->vif, sta, key);
262         trace_drv_return_int(local, ret);
263         return ret;
264 }
265
266 static inline void drv_update_tkip_key(struct ieee80211_local *local,
267                                        struct ieee80211_sub_if_data *sdata,
268                                        struct ieee80211_key_conf *conf,
269                                        struct sta_info *sta, u32 iv32,
270                                        u16 *phase1key)
271 {
272         struct ieee80211_sta *ista = NULL;
273
274         if (sta)
275                 ista = &sta->sta;
276
277         sdata = get_bss_sdata(sdata);
278         if (!check_sdata_in_driver(sdata))
279                 return;
280
281         trace_drv_update_tkip_key(local, sdata, conf, ista, iv32);
282         if (local->ops->update_tkip_key)
283                 local->ops->update_tkip_key(&local->hw, &sdata->vif, conf,
284                                             ista, iv32, phase1key);
285         trace_drv_return_void(local);
286 }
287
288 static inline int drv_hw_scan(struct ieee80211_local *local,
289                               struct ieee80211_sub_if_data *sdata,
290                               struct ieee80211_scan_request *req)
291 {
292         int ret;
293
294         might_sleep();
295
296         if (!check_sdata_in_driver(sdata))
297                 return -EIO;
298
299         trace_drv_hw_scan(local, sdata);
300         ret = local->ops->hw_scan(&local->hw, &sdata->vif, req);
301         trace_drv_return_int(local, ret);
302         return ret;
303 }
304
305 static inline void drv_cancel_hw_scan(struct ieee80211_local *local,
306                                       struct ieee80211_sub_if_data *sdata)
307 {
308         might_sleep();
309
310         if (!check_sdata_in_driver(sdata))
311                 return;
312
313         trace_drv_cancel_hw_scan(local, sdata);
314         local->ops->cancel_hw_scan(&local->hw, &sdata->vif);
315         trace_drv_return_void(local);
316 }
317
318 static inline int
319 drv_sched_scan_start(struct ieee80211_local *local,
320                      struct ieee80211_sub_if_data *sdata,
321                      struct cfg80211_sched_scan_request *req,
322                      struct ieee80211_scan_ies *ies)
323 {
324         int ret;
325
326         might_sleep();
327
328         if (!check_sdata_in_driver(sdata))
329                 return -EIO;
330
331         trace_drv_sched_scan_start(local, sdata);
332         ret = local->ops->sched_scan_start(&local->hw, &sdata->vif,
333                                               req, ies);
334         trace_drv_return_int(local, ret);
335         return ret;
336 }
337
338 static inline int drv_sched_scan_stop(struct ieee80211_local *local,
339                                       struct ieee80211_sub_if_data *sdata)
340 {
341         int ret;
342
343         might_sleep();
344
345         if (!check_sdata_in_driver(sdata))
346                 return -EIO;
347
348         trace_drv_sched_scan_stop(local, sdata);
349         ret = local->ops->sched_scan_stop(&local->hw, &sdata->vif);
350         trace_drv_return_int(local, ret);
351
352         return ret;
353 }
354
355 static inline void drv_sw_scan_start(struct ieee80211_local *local,
356                                      struct ieee80211_sub_if_data *sdata,
357                                      const u8 *mac_addr)
358 {
359         might_sleep();
360
361         trace_drv_sw_scan_start(local, sdata, mac_addr);
362         if (local->ops->sw_scan_start)
363                 local->ops->sw_scan_start(&local->hw, &sdata->vif, mac_addr);
364         trace_drv_return_void(local);
365 }
366
367 static inline void drv_sw_scan_complete(struct ieee80211_local *local,
368                                         struct ieee80211_sub_if_data *sdata)
369 {
370         might_sleep();
371
372         trace_drv_sw_scan_complete(local, sdata);
373         if (local->ops->sw_scan_complete)
374                 local->ops->sw_scan_complete(&local->hw, &sdata->vif);
375         trace_drv_return_void(local);
376 }
377
378 static inline int drv_get_stats(struct ieee80211_local *local,
379                                 struct ieee80211_low_level_stats *stats)
380 {
381         int ret = -EOPNOTSUPP;
382
383         might_sleep();
384
385         if (local->ops->get_stats)
386                 ret = local->ops->get_stats(&local->hw, stats);
387         trace_drv_get_stats(local, stats, ret);
388
389         return ret;
390 }
391
392 static inline void drv_get_key_seq(struct ieee80211_local *local,
393                                    struct ieee80211_key *key,
394                                    struct ieee80211_key_seq *seq)
395 {
396         if (local->ops->get_key_seq)
397                 local->ops->get_key_seq(&local->hw, &key->conf, seq);
398         trace_drv_get_key_seq(local, &key->conf);
399 }
400
401 static inline int drv_set_frag_threshold(struct ieee80211_local *local,
402                                         u32 value)
403 {
404         int ret = 0;
405
406         might_sleep();
407
408         trace_drv_set_frag_threshold(local, value);
409         if (local->ops->set_frag_threshold)
410                 ret = local->ops->set_frag_threshold(&local->hw, value);
411         trace_drv_return_int(local, ret);
412         return ret;
413 }
414
415 static inline int drv_set_rts_threshold(struct ieee80211_local *local,
416                                         u32 value)
417 {
418         int ret = 0;
419
420         might_sleep();
421
422         trace_drv_set_rts_threshold(local, value);
423         if (local->ops->set_rts_threshold)
424                 ret = local->ops->set_rts_threshold(&local->hw, value);
425         trace_drv_return_int(local, ret);
426         return ret;
427 }
428
429 static inline int drv_set_coverage_class(struct ieee80211_local *local,
430                                          s16 value)
431 {
432         int ret = 0;
433         might_sleep();
434
435         trace_drv_set_coverage_class(local, value);
436         if (local->ops->set_coverage_class)
437                 local->ops->set_coverage_class(&local->hw, value);
438         else
439                 ret = -EOPNOTSUPP;
440
441         trace_drv_return_int(local, ret);
442         return ret;
443 }
444
445 static inline void drv_sta_notify(struct ieee80211_local *local,
446                                   struct ieee80211_sub_if_data *sdata,
447                                   enum sta_notify_cmd cmd,
448                                   struct ieee80211_sta *sta)
449 {
450         sdata = get_bss_sdata(sdata);
451         if (!check_sdata_in_driver(sdata))
452                 return;
453
454         trace_drv_sta_notify(local, sdata, cmd, sta);
455         if (local->ops->sta_notify)
456                 local->ops->sta_notify(&local->hw, &sdata->vif, cmd, sta);
457         trace_drv_return_void(local);
458 }
459
460 static inline int drv_sta_add(struct ieee80211_local *local,
461                               struct ieee80211_sub_if_data *sdata,
462                               struct ieee80211_sta *sta)
463 {
464         int ret = 0;
465
466         might_sleep();
467
468         sdata = get_bss_sdata(sdata);
469         if (!check_sdata_in_driver(sdata))
470                 return -EIO;
471
472         trace_drv_sta_add(local, sdata, sta);
473         if (local->ops->sta_add)
474                 ret = local->ops->sta_add(&local->hw, &sdata->vif, sta);
475
476         trace_drv_return_int(local, ret);
477
478         return ret;
479 }
480
481 static inline void drv_sta_remove(struct ieee80211_local *local,
482                                   struct ieee80211_sub_if_data *sdata,
483                                   struct ieee80211_sta *sta)
484 {
485         might_sleep();
486
487         sdata = get_bss_sdata(sdata);
488         if (!check_sdata_in_driver(sdata))
489                 return;
490
491         trace_drv_sta_remove(local, sdata, sta);
492         if (local->ops->sta_remove)
493                 local->ops->sta_remove(&local->hw, &sdata->vif, sta);
494
495         trace_drv_return_void(local);
496 }
497
498 #ifdef CONFIG_MAC80211_DEBUGFS
499 static inline void drv_sta_add_debugfs(struct ieee80211_local *local,
500                                        struct ieee80211_sub_if_data *sdata,
501                                        struct ieee80211_sta *sta,
502                                        struct dentry *dir)
503 {
504         might_sleep();
505
506         sdata = get_bss_sdata(sdata);
507         if (!check_sdata_in_driver(sdata))
508                 return;
509
510         if (local->ops->sta_add_debugfs)
511                 local->ops->sta_add_debugfs(&local->hw, &sdata->vif,
512                                             sta, dir);
513 }
514
515 static inline void drv_sta_remove_debugfs(struct ieee80211_local *local,
516                                           struct ieee80211_sub_if_data *sdata,
517                                           struct ieee80211_sta *sta,
518                                           struct dentry *dir)
519 {
520         might_sleep();
521
522         sdata = get_bss_sdata(sdata);
523         check_sdata_in_driver(sdata);
524
525         if (local->ops->sta_remove_debugfs)
526                 local->ops->sta_remove_debugfs(&local->hw, &sdata->vif,
527                                                sta, dir);
528 }
529 #endif
530
531 static inline void drv_sta_pre_rcu_remove(struct ieee80211_local *local,
532                                           struct ieee80211_sub_if_data *sdata,
533                                           struct sta_info *sta)
534 {
535         might_sleep();
536
537         sdata = get_bss_sdata(sdata);
538         if (!check_sdata_in_driver(sdata))
539                 return;
540
541         trace_drv_sta_pre_rcu_remove(local, sdata, &sta->sta);
542         if (local->ops->sta_pre_rcu_remove)
543                 local->ops->sta_pre_rcu_remove(&local->hw, &sdata->vif,
544                                                &sta->sta);
545         trace_drv_return_void(local);
546 }
547
548 __must_check
549 int drv_sta_state(struct ieee80211_local *local,
550                   struct ieee80211_sub_if_data *sdata,
551                   struct sta_info *sta,
552                   enum ieee80211_sta_state old_state,
553                   enum ieee80211_sta_state new_state);
554
555 void drv_sta_rc_update(struct ieee80211_local *local,
556                        struct ieee80211_sub_if_data *sdata,
557                        struct ieee80211_sta *sta, u32 changed);
558
559 static inline void drv_sta_rate_tbl_update(struct ieee80211_local *local,
560                                            struct ieee80211_sub_if_data *sdata,
561                                            struct ieee80211_sta *sta)
562 {
563         sdata = get_bss_sdata(sdata);
564         if (!check_sdata_in_driver(sdata))
565                 return;
566
567         trace_drv_sta_rate_tbl_update(local, sdata, sta);
568         if (local->ops->sta_rate_tbl_update)
569                 local->ops->sta_rate_tbl_update(&local->hw, &sdata->vif, sta);
570
571         trace_drv_return_void(local);
572 }
573
574 static inline void drv_sta_statistics(struct ieee80211_local *local,
575                                       struct ieee80211_sub_if_data *sdata,
576                                       struct ieee80211_sta *sta,
577                                       struct station_info *sinfo)
578 {
579         sdata = get_bss_sdata(sdata);
580         if (!check_sdata_in_driver(sdata))
581                 return;
582
583         trace_drv_sta_statistics(local, sdata, sta);
584         if (local->ops->sta_statistics)
585                 local->ops->sta_statistics(&local->hw, &sdata->vif, sta, sinfo);
586         trace_drv_return_void(local);
587 }
588
589 int drv_conf_tx(struct ieee80211_local *local,
590                 struct ieee80211_sub_if_data *sdata, u16 ac,
591                 const struct ieee80211_tx_queue_params *params);
592
593 static inline u64 drv_get_tsf(struct ieee80211_local *local,
594                               struct ieee80211_sub_if_data *sdata)
595 {
596         u64 ret = -1ULL;
597
598         might_sleep();
599
600         if (!check_sdata_in_driver(sdata))
601                 return ret;
602
603         trace_drv_get_tsf(local, sdata);
604         if (local->ops->get_tsf)
605                 ret = local->ops->get_tsf(&local->hw, &sdata->vif);
606         trace_drv_return_u64(local, ret);
607         return ret;
608 }
609
610 static inline void drv_set_tsf(struct ieee80211_local *local,
611                                struct ieee80211_sub_if_data *sdata,
612                                u64 tsf)
613 {
614         might_sleep();
615
616         if (!check_sdata_in_driver(sdata))
617                 return;
618
619         trace_drv_set_tsf(local, sdata, tsf);
620         if (local->ops->set_tsf)
621                 local->ops->set_tsf(&local->hw, &sdata->vif, tsf);
622         trace_drv_return_void(local);
623 }
624
625 static inline void drv_reset_tsf(struct ieee80211_local *local,
626                                  struct ieee80211_sub_if_data *sdata)
627 {
628         might_sleep();
629
630         if (!check_sdata_in_driver(sdata))
631                 return;
632
633         trace_drv_reset_tsf(local, sdata);
634         if (local->ops->reset_tsf)
635                 local->ops->reset_tsf(&local->hw, &sdata->vif);
636         trace_drv_return_void(local);
637 }
638
639 static inline int drv_tx_last_beacon(struct ieee80211_local *local)
640 {
641         int ret = 0; /* default unsupported op for less congestion */
642
643         might_sleep();
644
645         trace_drv_tx_last_beacon(local);
646         if (local->ops->tx_last_beacon)
647                 ret = local->ops->tx_last_beacon(&local->hw);
648         trace_drv_return_int(local, ret);
649         return ret;
650 }
651
652 static inline int drv_ampdu_action(struct ieee80211_local *local,
653                                    struct ieee80211_sub_if_data *sdata,
654                                    enum ieee80211_ampdu_mlme_action action,
655                                    struct ieee80211_sta *sta, u16 tid,
656                                    u16 *ssn, u8 buf_size, bool amsdu)
657 {
658         int ret = -EOPNOTSUPP;
659
660         might_sleep();
661
662         sdata = get_bss_sdata(sdata);
663         if (!check_sdata_in_driver(sdata))
664                 return -EIO;
665
666         trace_drv_ampdu_action(local, sdata, action, sta, tid,
667                                ssn, buf_size, amsdu);
668
669         if (local->ops->ampdu_action)
670                 ret = local->ops->ampdu_action(&local->hw, &sdata->vif, action,
671                                                sta, tid, ssn, buf_size, amsdu);
672
673         trace_drv_return_int(local, ret);
674
675         return ret;
676 }
677
678 static inline int drv_get_survey(struct ieee80211_local *local, int idx,
679                                 struct survey_info *survey)
680 {
681         int ret = -EOPNOTSUPP;
682
683         trace_drv_get_survey(local, idx, survey);
684
685         if (local->ops->get_survey)
686                 ret = local->ops->get_survey(&local->hw, idx, survey);
687
688         trace_drv_return_int(local, ret);
689
690         return ret;
691 }
692
693 static inline void drv_rfkill_poll(struct ieee80211_local *local)
694 {
695         might_sleep();
696
697         if (local->ops->rfkill_poll)
698                 local->ops->rfkill_poll(&local->hw);
699 }
700
701 static inline void drv_flush(struct ieee80211_local *local,
702                              struct ieee80211_sub_if_data *sdata,
703                              u32 queues, bool drop)
704 {
705         struct ieee80211_vif *vif = sdata ? &sdata->vif : NULL;
706
707         might_sleep();
708
709         if (sdata && !check_sdata_in_driver(sdata))
710                 return;
711
712         trace_drv_flush(local, queues, drop);
713         if (local->ops->flush)
714                 local->ops->flush(&local->hw, vif, queues, drop);
715         trace_drv_return_void(local);
716 }
717
718 static inline void drv_channel_switch(struct ieee80211_local *local,
719                                       struct ieee80211_sub_if_data *sdata,
720                                       struct ieee80211_channel_switch *ch_switch)
721 {
722         might_sleep();
723
724         trace_drv_channel_switch(local, sdata, ch_switch);
725         local->ops->channel_switch(&local->hw, &sdata->vif, ch_switch);
726         trace_drv_return_void(local);
727 }
728
729
730 static inline int drv_set_antenna(struct ieee80211_local *local,
731                                   u32 tx_ant, u32 rx_ant)
732 {
733         int ret = -EOPNOTSUPP;
734         might_sleep();
735         if (local->ops->set_antenna)
736                 ret = local->ops->set_antenna(&local->hw, tx_ant, rx_ant);
737         trace_drv_set_antenna(local, tx_ant, rx_ant, ret);
738         return ret;
739 }
740
741 static inline int drv_get_antenna(struct ieee80211_local *local,
742                                   u32 *tx_ant, u32 *rx_ant)
743 {
744         int ret = -EOPNOTSUPP;
745         might_sleep();
746         if (local->ops->get_antenna)
747                 ret = local->ops->get_antenna(&local->hw, tx_ant, rx_ant);
748         trace_drv_get_antenna(local, *tx_ant, *rx_ant, ret);
749         return ret;
750 }
751
752 static inline int drv_remain_on_channel(struct ieee80211_local *local,
753                                         struct ieee80211_sub_if_data *sdata,
754                                         struct ieee80211_channel *chan,
755                                         unsigned int duration,
756                                         enum ieee80211_roc_type type)
757 {
758         int ret;
759
760         might_sleep();
761
762         trace_drv_remain_on_channel(local, sdata, chan, duration, type);
763         ret = local->ops->remain_on_channel(&local->hw, &sdata->vif,
764                                             chan, duration, type);
765         trace_drv_return_int(local, ret);
766
767         return ret;
768 }
769
770 static inline int drv_cancel_remain_on_channel(struct ieee80211_local *local)
771 {
772         int ret;
773
774         might_sleep();
775
776         trace_drv_cancel_remain_on_channel(local);
777         ret = local->ops->cancel_remain_on_channel(&local->hw);
778         trace_drv_return_int(local, ret);
779
780         return ret;
781 }
782
783 static inline int drv_set_ringparam(struct ieee80211_local *local,
784                                     u32 tx, u32 rx)
785 {
786         int ret = -ENOTSUPP;
787
788         might_sleep();
789
790         trace_drv_set_ringparam(local, tx, rx);
791         if (local->ops->set_ringparam)
792                 ret = local->ops->set_ringparam(&local->hw, tx, rx);
793         trace_drv_return_int(local, ret);
794
795         return ret;
796 }
797
798 static inline void drv_get_ringparam(struct ieee80211_local *local,
799                                      u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
800 {
801         might_sleep();
802
803         trace_drv_get_ringparam(local, tx, tx_max, rx, rx_max);
804         if (local->ops->get_ringparam)
805                 local->ops->get_ringparam(&local->hw, tx, tx_max, rx, rx_max);
806         trace_drv_return_void(local);
807 }
808
809 static inline bool drv_tx_frames_pending(struct ieee80211_local *local)
810 {
811         bool ret = false;
812
813         might_sleep();
814
815         trace_drv_tx_frames_pending(local);
816         if (local->ops->tx_frames_pending)
817                 ret = local->ops->tx_frames_pending(&local->hw);
818         trace_drv_return_bool(local, ret);
819
820         return ret;
821 }
822
823 static inline int drv_set_bitrate_mask(struct ieee80211_local *local,
824                                        struct ieee80211_sub_if_data *sdata,
825                                        const struct cfg80211_bitrate_mask *mask)
826 {
827         int ret = -EOPNOTSUPP;
828
829         might_sleep();
830
831         if (!check_sdata_in_driver(sdata))
832                 return -EIO;
833
834         trace_drv_set_bitrate_mask(local, sdata, mask);
835         if (local->ops->set_bitrate_mask)
836                 ret = local->ops->set_bitrate_mask(&local->hw,
837                                                    &sdata->vif, mask);
838         trace_drv_return_int(local, ret);
839
840         return ret;
841 }
842
843 static inline void drv_set_rekey_data(struct ieee80211_local *local,
844                                       struct ieee80211_sub_if_data *sdata,
845                                       struct cfg80211_gtk_rekey_data *data)
846 {
847         if (!check_sdata_in_driver(sdata))
848                 return;
849
850         trace_drv_set_rekey_data(local, sdata, data);
851         if (local->ops->set_rekey_data)
852                 local->ops->set_rekey_data(&local->hw, &sdata->vif, data);
853         trace_drv_return_void(local);
854 }
855
856 static inline void drv_event_callback(struct ieee80211_local *local,
857                                       struct ieee80211_sub_if_data *sdata,
858                                       const struct ieee80211_event *event)
859 {
860         trace_drv_event_callback(local, sdata, event);
861         if (local->ops->event_callback)
862                 local->ops->event_callback(&local->hw, &sdata->vif, event);
863         trace_drv_return_void(local);
864 }
865
866 static inline void
867 drv_release_buffered_frames(struct ieee80211_local *local,
868                             struct sta_info *sta, u16 tids, int num_frames,
869                             enum ieee80211_frame_release_type reason,
870                             bool more_data)
871 {
872         trace_drv_release_buffered_frames(local, &sta->sta, tids, num_frames,
873                                           reason, more_data);
874         if (local->ops->release_buffered_frames)
875                 local->ops->release_buffered_frames(&local->hw, &sta->sta, tids,
876                                                     num_frames, reason,
877                                                     more_data);
878         trace_drv_return_void(local);
879 }
880
881 static inline void
882 drv_allow_buffered_frames(struct ieee80211_local *local,
883                           struct sta_info *sta, u16 tids, int num_frames,
884                           enum ieee80211_frame_release_type reason,
885                           bool more_data)
886 {
887         trace_drv_allow_buffered_frames(local, &sta->sta, tids, num_frames,
888                                         reason, more_data);
889         if (local->ops->allow_buffered_frames)
890                 local->ops->allow_buffered_frames(&local->hw, &sta->sta,
891                                                   tids, num_frames, reason,
892                                                   more_data);
893         trace_drv_return_void(local);
894 }
895
896 static inline void drv_mgd_prepare_tx(struct ieee80211_local *local,
897                                       struct ieee80211_sub_if_data *sdata)
898 {
899         might_sleep();
900
901         if (!check_sdata_in_driver(sdata))
902                 return;
903         WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION);
904
905         trace_drv_mgd_prepare_tx(local, sdata);
906         if (local->ops->mgd_prepare_tx)
907                 local->ops->mgd_prepare_tx(&local->hw, &sdata->vif);
908         trace_drv_return_void(local);
909 }
910
911 static inline void
912 drv_mgd_protect_tdls_discover(struct ieee80211_local *local,
913                               struct ieee80211_sub_if_data *sdata)
914 {
915         might_sleep();
916
917         if (!check_sdata_in_driver(sdata))
918                 return;
919         WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION);
920
921         trace_drv_mgd_protect_tdls_discover(local, sdata);
922         if (local->ops->mgd_protect_tdls_discover)
923                 local->ops->mgd_protect_tdls_discover(&local->hw, &sdata->vif);
924         trace_drv_return_void(local);
925 }
926
927 static inline int drv_add_chanctx(struct ieee80211_local *local,
928                                   struct ieee80211_chanctx *ctx)
929 {
930         int ret = -EOPNOTSUPP;
931
932         trace_drv_add_chanctx(local, ctx);
933         if (local->ops->add_chanctx)
934                 ret = local->ops->add_chanctx(&local->hw, &ctx->conf);
935         trace_drv_return_int(local, ret);
936         if (!ret)
937                 ctx->driver_present = true;
938
939         return ret;
940 }
941
942 static inline void drv_remove_chanctx(struct ieee80211_local *local,
943                                       struct ieee80211_chanctx *ctx)
944 {
945         if (WARN_ON(!ctx->driver_present))
946                 return;
947
948         trace_drv_remove_chanctx(local, ctx);
949         if (local->ops->remove_chanctx)
950                 local->ops->remove_chanctx(&local->hw, &ctx->conf);
951         trace_drv_return_void(local);
952         ctx->driver_present = false;
953 }
954
955 static inline void drv_change_chanctx(struct ieee80211_local *local,
956                                       struct ieee80211_chanctx *ctx,
957                                       u32 changed)
958 {
959         trace_drv_change_chanctx(local, ctx, changed);
960         if (local->ops->change_chanctx) {
961                 WARN_ON_ONCE(!ctx->driver_present);
962                 local->ops->change_chanctx(&local->hw, &ctx->conf, changed);
963         }
964         trace_drv_return_void(local);
965 }
966
967 static inline int drv_assign_vif_chanctx(struct ieee80211_local *local,
968                                          struct ieee80211_sub_if_data *sdata,
969                                          struct ieee80211_chanctx *ctx)
970 {
971         int ret = 0;
972
973         if (!check_sdata_in_driver(sdata))
974                 return -EIO;
975
976         trace_drv_assign_vif_chanctx(local, sdata, ctx);
977         if (local->ops->assign_vif_chanctx) {
978                 WARN_ON_ONCE(!ctx->driver_present);
979                 ret = local->ops->assign_vif_chanctx(&local->hw,
980                                                      &sdata->vif,
981                                                      &ctx->conf);
982         }
983         trace_drv_return_int(local, ret);
984
985         return ret;
986 }
987
988 static inline void drv_unassign_vif_chanctx(struct ieee80211_local *local,
989                                             struct ieee80211_sub_if_data *sdata,
990                                             struct ieee80211_chanctx *ctx)
991 {
992         if (!check_sdata_in_driver(sdata))
993                 return;
994
995         trace_drv_unassign_vif_chanctx(local, sdata, ctx);
996         if (local->ops->unassign_vif_chanctx) {
997                 WARN_ON_ONCE(!ctx->driver_present);
998                 local->ops->unassign_vif_chanctx(&local->hw,
999                                                  &sdata->vif,
1000                                                  &ctx->conf);
1001         }
1002         trace_drv_return_void(local);
1003 }
1004
1005 int drv_switch_vif_chanctx(struct ieee80211_local *local,
1006                            struct ieee80211_vif_chanctx_switch *vifs,
1007                            int n_vifs, enum ieee80211_chanctx_switch_mode mode);
1008
1009 static inline int drv_start_ap(struct ieee80211_local *local,
1010                                struct ieee80211_sub_if_data *sdata)
1011 {
1012         int ret = 0;
1013
1014         if (!check_sdata_in_driver(sdata))
1015                 return -EIO;
1016
1017         trace_drv_start_ap(local, sdata, &sdata->vif.bss_conf);
1018         if (local->ops->start_ap)
1019                 ret = local->ops->start_ap(&local->hw, &sdata->vif);
1020         trace_drv_return_int(local, ret);
1021         return ret;
1022 }
1023
1024 static inline void drv_stop_ap(struct ieee80211_local *local,
1025                                struct ieee80211_sub_if_data *sdata)
1026 {
1027         if (!check_sdata_in_driver(sdata))
1028                 return;
1029
1030         trace_drv_stop_ap(local, sdata);
1031         if (local->ops->stop_ap)
1032                 local->ops->stop_ap(&local->hw, &sdata->vif);
1033         trace_drv_return_void(local);
1034 }
1035
1036 static inline void
1037 drv_reconfig_complete(struct ieee80211_local *local,
1038                       enum ieee80211_reconfig_type reconfig_type)
1039 {
1040         might_sleep();
1041
1042         trace_drv_reconfig_complete(local, reconfig_type);
1043         if (local->ops->reconfig_complete)
1044                 local->ops->reconfig_complete(&local->hw, reconfig_type);
1045         trace_drv_return_void(local);
1046 }
1047
1048 static inline void
1049 drv_set_default_unicast_key(struct ieee80211_local *local,
1050                             struct ieee80211_sub_if_data *sdata,
1051                             int key_idx)
1052 {
1053         if (!check_sdata_in_driver(sdata))
1054                 return;
1055
1056         WARN_ON_ONCE(key_idx < -1 || key_idx > 3);
1057
1058         trace_drv_set_default_unicast_key(local, sdata, key_idx);
1059         if (local->ops->set_default_unicast_key)
1060                 local->ops->set_default_unicast_key(&local->hw, &sdata->vif,
1061                                                     key_idx);
1062         trace_drv_return_void(local);
1063 }
1064
1065 #if IS_ENABLED(CONFIG_IPV6)
1066 static inline void drv_ipv6_addr_change(struct ieee80211_local *local,
1067                                         struct ieee80211_sub_if_data *sdata,
1068                                         struct inet6_dev *idev)
1069 {
1070         trace_drv_ipv6_addr_change(local, sdata);
1071         if (local->ops->ipv6_addr_change)
1072                 local->ops->ipv6_addr_change(&local->hw, &sdata->vif, idev);
1073         trace_drv_return_void(local);
1074 }
1075 #endif
1076
1077 static inline void
1078 drv_channel_switch_beacon(struct ieee80211_sub_if_data *sdata,
1079                           struct cfg80211_chan_def *chandef)
1080 {
1081         struct ieee80211_local *local = sdata->local;
1082
1083         if (local->ops->channel_switch_beacon) {
1084                 trace_drv_channel_switch_beacon(local, sdata, chandef);
1085                 local->ops->channel_switch_beacon(&local->hw, &sdata->vif,
1086                                                   chandef);
1087         }
1088 }
1089
1090 static inline int
1091 drv_pre_channel_switch(struct ieee80211_sub_if_data *sdata,
1092                        struct ieee80211_channel_switch *ch_switch)
1093 {
1094         struct ieee80211_local *local = sdata->local;
1095         int ret = 0;
1096
1097         if (!check_sdata_in_driver(sdata))
1098                 return -EIO;
1099
1100         trace_drv_pre_channel_switch(local, sdata, ch_switch);
1101         if (local->ops->pre_channel_switch)
1102                 ret = local->ops->pre_channel_switch(&local->hw, &sdata->vif,
1103                                                      ch_switch);
1104         trace_drv_return_int(local, ret);
1105         return ret;
1106 }
1107
1108 static inline int
1109 drv_post_channel_switch(struct ieee80211_sub_if_data *sdata)
1110 {
1111         struct ieee80211_local *local = sdata->local;
1112         int ret = 0;
1113
1114         if (!check_sdata_in_driver(sdata))
1115                 return -EIO;
1116
1117         trace_drv_post_channel_switch(local, sdata);
1118         if (local->ops->post_channel_switch)
1119                 ret = local->ops->post_channel_switch(&local->hw, &sdata->vif);
1120         trace_drv_return_int(local, ret);
1121         return ret;
1122 }
1123
1124 static inline int drv_join_ibss(struct ieee80211_local *local,
1125                                 struct ieee80211_sub_if_data *sdata)
1126 {
1127         int ret = 0;
1128
1129         might_sleep();
1130         if (!check_sdata_in_driver(sdata))
1131                 return -EIO;
1132
1133         trace_drv_join_ibss(local, sdata, &sdata->vif.bss_conf);
1134         if (local->ops->join_ibss)
1135                 ret = local->ops->join_ibss(&local->hw, &sdata->vif);
1136         trace_drv_return_int(local, ret);
1137         return ret;
1138 }
1139
1140 static inline void drv_leave_ibss(struct ieee80211_local *local,
1141                                   struct ieee80211_sub_if_data *sdata)
1142 {
1143         might_sleep();
1144         if (!check_sdata_in_driver(sdata))
1145                 return;
1146
1147         trace_drv_leave_ibss(local, sdata);
1148         if (local->ops->leave_ibss)
1149                 local->ops->leave_ibss(&local->hw, &sdata->vif);
1150         trace_drv_return_void(local);
1151 }
1152
1153 static inline u32 drv_get_expected_throughput(struct ieee80211_local *local,
1154                                               struct ieee80211_sta *sta)
1155 {
1156         u32 ret = 0;
1157
1158         trace_drv_get_expected_throughput(sta);
1159         if (local->ops->get_expected_throughput)
1160                 ret = local->ops->get_expected_throughput(sta);
1161         trace_drv_return_u32(local, ret);
1162
1163         return ret;
1164 }
1165
1166 static inline int drv_get_txpower(struct ieee80211_local *local,
1167                                   struct ieee80211_sub_if_data *sdata, int *dbm)
1168 {
1169         int ret;
1170
1171         if (!local->ops->get_txpower)
1172                 return -EOPNOTSUPP;
1173
1174         ret = local->ops->get_txpower(&local->hw, &sdata->vif, dbm);
1175         trace_drv_get_txpower(local, sdata, *dbm, ret);
1176
1177         return ret;
1178 }
1179
1180 static inline int
1181 drv_tdls_channel_switch(struct ieee80211_local *local,
1182                         struct ieee80211_sub_if_data *sdata,
1183                         struct ieee80211_sta *sta, u8 oper_class,
1184                         struct cfg80211_chan_def *chandef,
1185                         struct sk_buff *tmpl_skb, u32 ch_sw_tm_ie)
1186 {
1187         int ret;
1188
1189         might_sleep();
1190         if (!check_sdata_in_driver(sdata))
1191                 return -EIO;
1192
1193         if (!local->ops->tdls_channel_switch)
1194                 return -EOPNOTSUPP;
1195
1196         trace_drv_tdls_channel_switch(local, sdata, sta, oper_class, chandef);
1197         ret = local->ops->tdls_channel_switch(&local->hw, &sdata->vif, sta,
1198                                               oper_class, chandef, tmpl_skb,
1199                                               ch_sw_tm_ie);
1200         trace_drv_return_int(local, ret);
1201         return ret;
1202 }
1203
1204 static inline void
1205 drv_tdls_cancel_channel_switch(struct ieee80211_local *local,
1206                                struct ieee80211_sub_if_data *sdata,
1207                                struct ieee80211_sta *sta)
1208 {
1209         might_sleep();
1210         if (!check_sdata_in_driver(sdata))
1211                 return;
1212
1213         if (!local->ops->tdls_cancel_channel_switch)
1214                 return;
1215
1216         trace_drv_tdls_cancel_channel_switch(local, sdata, sta);
1217         local->ops->tdls_cancel_channel_switch(&local->hw, &sdata->vif, sta);
1218         trace_drv_return_void(local);
1219 }
1220
1221 static inline void
1222 drv_tdls_recv_channel_switch(struct ieee80211_local *local,
1223                              struct ieee80211_sub_if_data *sdata,
1224                              struct ieee80211_tdls_ch_sw_params *params)
1225 {
1226         trace_drv_tdls_recv_channel_switch(local, sdata, params);
1227         if (local->ops->tdls_recv_channel_switch)
1228                 local->ops->tdls_recv_channel_switch(&local->hw, &sdata->vif,
1229                                                      params);
1230         trace_drv_return_void(local);
1231 }
1232
1233 static inline void drv_wake_tx_queue(struct ieee80211_local *local,
1234                                      struct txq_info *txq)
1235 {
1236         struct ieee80211_sub_if_data *sdata = vif_to_sdata(txq->txq.vif);
1237
1238         if (!check_sdata_in_driver(sdata))
1239                 return;
1240
1241         trace_drv_wake_tx_queue(local, sdata, txq);
1242         local->ops->wake_tx_queue(&local->hw, &txq->txq);
1243 }
1244
1245 #endif /* __MAC80211_DRIVER_OPS */