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