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