perf/x86: Add support for sampling PEBS machine state registers
[linux/fpc-iii.git] / net / mac80211 / driver-ops.h
blob196d48c68134a08b644fc97f8f1a1fc740ec7bdf
1 #ifndef __MAC80211_DRIVER_OPS
2 #define __MAC80211_DRIVER_OPS
4 #include <net/mac80211.h>
5 #include "ieee80211_i.h"
6 #include "trace.h"
8 static inline bool check_sdata_in_driver(struct ieee80211_sub_if_data *sdata)
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);
15 static inline struct ieee80211_sub_if_data *
16 get_bss_sdata(struct ieee80211_sub_if_data *sdata)
18 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
19 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
20 u.ap);
22 return sdata;
25 static inline void drv_tx(struct ieee80211_local *local,
26 struct ieee80211_tx_control *control,
27 struct sk_buff *skb)
29 local->ops->tx(&local->hw, control, skb);
32 static inline void drv_get_et_strings(struct ieee80211_sub_if_data *sdata,
33 u32 sset, u8 *data)
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);
43 static inline void drv_get_et_stats(struct ieee80211_sub_if_data *sdata,
44 struct ethtool_stats *stats,
45 u64 *data)
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);
55 static inline int drv_get_et_sset_count(struct ieee80211_sub_if_data *sdata,
56 int sset)
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);
66 return rv;
69 static inline int drv_start(struct ieee80211_local *local)
71 int ret;
73 might_sleep();
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;
83 static inline void drv_stop(struct ieee80211_local *local)
85 might_sleep();
87 trace_drv_stop(local);
88 local->ops->stop(&local->hw);
89 trace_drv_return_void(local);
91 /* sync away all work on the tasklet before clearing started */
92 tasklet_disable(&local->tasklet);
93 tasklet_enable(&local->tasklet);
95 barrier();
97 local->started = false;
100 #ifdef CONFIG_PM
101 static inline int drv_suspend(struct ieee80211_local *local,
102 struct cfg80211_wowlan *wowlan)
104 int ret;
106 might_sleep();
108 trace_drv_suspend(local);
109 ret = local->ops->suspend(&local->hw, wowlan);
110 trace_drv_return_int(local, ret);
111 return ret;
114 static inline int drv_resume(struct ieee80211_local *local)
116 int ret;
118 might_sleep();
120 trace_drv_resume(local);
121 ret = local->ops->resume(&local->hw);
122 trace_drv_return_int(local, ret);
123 return ret;
126 static inline void drv_set_wakeup(struct ieee80211_local *local,
127 bool enabled)
129 might_sleep();
131 if (!local->ops->set_wakeup)
132 return;
134 trace_drv_set_wakeup(local, enabled);
135 local->ops->set_wakeup(&local->hw, enabled);
136 trace_drv_return_void(local);
138 #endif
140 static inline int drv_add_interface(struct ieee80211_local *local,
141 struct ieee80211_sub_if_data *sdata)
143 int ret;
145 might_sleep();
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 !(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))))
151 return -EINVAL;
153 trace_drv_add_interface(local, sdata);
154 ret = local->ops->add_interface(&local->hw, &sdata->vif);
155 trace_drv_return_int(local, ret);
157 if (ret == 0)
158 sdata->flags |= IEEE80211_SDATA_IN_DRIVER;
160 return ret;
163 static inline int drv_change_interface(struct ieee80211_local *local,
164 struct ieee80211_sub_if_data *sdata,
165 enum nl80211_iftype type, bool p2p)
167 int ret;
169 might_sleep();
171 if (!check_sdata_in_driver(sdata))
172 return -EIO;
174 trace_drv_change_interface(local, sdata, type, p2p);
175 ret = local->ops->change_interface(&local->hw, &sdata->vif, type, p2p);
176 trace_drv_return_int(local, ret);
177 return ret;
180 static inline void drv_remove_interface(struct ieee80211_local *local,
181 struct ieee80211_sub_if_data *sdata)
183 might_sleep();
185 if (!check_sdata_in_driver(sdata))
186 return;
188 trace_drv_remove_interface(local, sdata);
189 local->ops->remove_interface(&local->hw, &sdata->vif);
190 sdata->flags &= ~IEEE80211_SDATA_IN_DRIVER;
191 trace_drv_return_void(local);
194 static inline int drv_config(struct ieee80211_local *local, u32 changed)
196 int ret;
198 might_sleep();
200 trace_drv_config(local, changed);
201 ret = local->ops->config(&local->hw, changed);
202 trace_drv_return_int(local, ret);
203 return ret;
206 static inline void drv_bss_info_changed(struct ieee80211_local *local,
207 struct ieee80211_sub_if_data *sdata,
208 struct ieee80211_bss_conf *info,
209 u32 changed)
211 might_sleep();
213 if (WARN_ON_ONCE(changed & (BSS_CHANGED_BEACON |
214 BSS_CHANGED_BEACON_ENABLED) &&
215 sdata->vif.type != NL80211_IFTYPE_AP &&
216 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
217 sdata->vif.type != NL80211_IFTYPE_MESH_POINT))
218 return;
220 if (WARN_ON_ONCE(sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE ||
221 sdata->vif.type == NL80211_IFTYPE_MONITOR))
222 return;
224 if (!check_sdata_in_driver(sdata))
225 return;
227 trace_drv_bss_info_changed(local, sdata, info, changed);
228 if (local->ops->bss_info_changed)
229 local->ops->bss_info_changed(&local->hw, &sdata->vif, info, changed);
230 trace_drv_return_void(local);
233 static inline u64 drv_prepare_multicast(struct ieee80211_local *local,
234 struct netdev_hw_addr_list *mc_list)
236 u64 ret = 0;
238 trace_drv_prepare_multicast(local, mc_list->count);
240 if (local->ops->prepare_multicast)
241 ret = local->ops->prepare_multicast(&local->hw, mc_list);
243 trace_drv_return_u64(local, ret);
245 return ret;
248 static inline void drv_configure_filter(struct ieee80211_local *local,
249 unsigned int changed_flags,
250 unsigned int *total_flags,
251 u64 multicast)
253 might_sleep();
255 trace_drv_configure_filter(local, changed_flags, total_flags,
256 multicast);
257 local->ops->configure_filter(&local->hw, changed_flags, total_flags,
258 multicast);
259 trace_drv_return_void(local);
262 static inline int drv_set_tim(struct ieee80211_local *local,
263 struct ieee80211_sta *sta, bool set)
265 int ret = 0;
266 trace_drv_set_tim(local, sta, set);
267 if (local->ops->set_tim)
268 ret = local->ops->set_tim(&local->hw, sta, set);
269 trace_drv_return_int(local, ret);
270 return ret;
273 static inline int drv_set_key(struct ieee80211_local *local,
274 enum set_key_cmd cmd,
275 struct ieee80211_sub_if_data *sdata,
276 struct ieee80211_sta *sta,
277 struct ieee80211_key_conf *key)
279 int ret;
281 might_sleep();
283 sdata = get_bss_sdata(sdata);
284 if (!check_sdata_in_driver(sdata))
285 return -EIO;
287 trace_drv_set_key(local, cmd, sdata, sta, key);
288 ret = local->ops->set_key(&local->hw, cmd, &sdata->vif, sta, key);
289 trace_drv_return_int(local, ret);
290 return ret;
293 static inline void drv_update_tkip_key(struct ieee80211_local *local,
294 struct ieee80211_sub_if_data *sdata,
295 struct ieee80211_key_conf *conf,
296 struct sta_info *sta, u32 iv32,
297 u16 *phase1key)
299 struct ieee80211_sta *ista = NULL;
301 if (sta)
302 ista = &sta->sta;
304 sdata = get_bss_sdata(sdata);
305 if (!check_sdata_in_driver(sdata))
306 return;
308 trace_drv_update_tkip_key(local, sdata, conf, ista, iv32);
309 if (local->ops->update_tkip_key)
310 local->ops->update_tkip_key(&local->hw, &sdata->vif, conf,
311 ista, iv32, phase1key);
312 trace_drv_return_void(local);
315 static inline int drv_hw_scan(struct ieee80211_local *local,
316 struct ieee80211_sub_if_data *sdata,
317 struct ieee80211_scan_request *req)
319 int ret;
321 might_sleep();
323 if (!check_sdata_in_driver(sdata))
324 return -EIO;
326 trace_drv_hw_scan(local, sdata);
327 ret = local->ops->hw_scan(&local->hw, &sdata->vif, req);
328 trace_drv_return_int(local, ret);
329 return ret;
332 static inline void drv_cancel_hw_scan(struct ieee80211_local *local,
333 struct ieee80211_sub_if_data *sdata)
335 might_sleep();
337 if (!check_sdata_in_driver(sdata))
338 return;
340 trace_drv_cancel_hw_scan(local, sdata);
341 local->ops->cancel_hw_scan(&local->hw, &sdata->vif);
342 trace_drv_return_void(local);
345 static inline int
346 drv_sched_scan_start(struct ieee80211_local *local,
347 struct ieee80211_sub_if_data *sdata,
348 struct cfg80211_sched_scan_request *req,
349 struct ieee80211_scan_ies *ies)
351 int ret;
353 might_sleep();
355 if (!check_sdata_in_driver(sdata))
356 return -EIO;
358 trace_drv_sched_scan_start(local, sdata);
359 ret = local->ops->sched_scan_start(&local->hw, &sdata->vif,
360 req, ies);
361 trace_drv_return_int(local, ret);
362 return ret;
365 static inline int drv_sched_scan_stop(struct ieee80211_local *local,
366 struct ieee80211_sub_if_data *sdata)
368 int ret;
370 might_sleep();
372 if (!check_sdata_in_driver(sdata))
373 return -EIO;
375 trace_drv_sched_scan_stop(local, sdata);
376 ret = local->ops->sched_scan_stop(&local->hw, &sdata->vif);
377 trace_drv_return_int(local, ret);
379 return ret;
382 static inline void drv_sw_scan_start(struct ieee80211_local *local)
384 might_sleep();
386 trace_drv_sw_scan_start(local);
387 if (local->ops->sw_scan_start)
388 local->ops->sw_scan_start(&local->hw);
389 trace_drv_return_void(local);
392 static inline void drv_sw_scan_complete(struct ieee80211_local *local)
394 might_sleep();
396 trace_drv_sw_scan_complete(local);
397 if (local->ops->sw_scan_complete)
398 local->ops->sw_scan_complete(&local->hw);
399 trace_drv_return_void(local);
402 static inline int drv_get_stats(struct ieee80211_local *local,
403 struct ieee80211_low_level_stats *stats)
405 int ret = -EOPNOTSUPP;
407 might_sleep();
409 if (local->ops->get_stats)
410 ret = local->ops->get_stats(&local->hw, stats);
411 trace_drv_get_stats(local, stats, ret);
413 return ret;
416 static inline void drv_get_tkip_seq(struct ieee80211_local *local,
417 u8 hw_key_idx, u32 *iv32, u16 *iv16)
419 if (local->ops->get_tkip_seq)
420 local->ops->get_tkip_seq(&local->hw, hw_key_idx, iv32, iv16);
421 trace_drv_get_tkip_seq(local, hw_key_idx, iv32, iv16);
424 static inline int drv_set_frag_threshold(struct ieee80211_local *local,
425 u32 value)
427 int ret = 0;
429 might_sleep();
431 trace_drv_set_frag_threshold(local, value);
432 if (local->ops->set_frag_threshold)
433 ret = local->ops->set_frag_threshold(&local->hw, value);
434 trace_drv_return_int(local, ret);
435 return ret;
438 static inline int drv_set_rts_threshold(struct ieee80211_local *local,
439 u32 value)
441 int ret = 0;
443 might_sleep();
445 trace_drv_set_rts_threshold(local, value);
446 if (local->ops->set_rts_threshold)
447 ret = local->ops->set_rts_threshold(&local->hw, value);
448 trace_drv_return_int(local, ret);
449 return ret;
452 static inline int drv_set_coverage_class(struct ieee80211_local *local,
453 s16 value)
455 int ret = 0;
456 might_sleep();
458 trace_drv_set_coverage_class(local, value);
459 if (local->ops->set_coverage_class)
460 local->ops->set_coverage_class(&local->hw, value);
461 else
462 ret = -EOPNOTSUPP;
464 trace_drv_return_int(local, ret);
465 return ret;
468 static inline void drv_sta_notify(struct ieee80211_local *local,
469 struct ieee80211_sub_if_data *sdata,
470 enum sta_notify_cmd cmd,
471 struct ieee80211_sta *sta)
473 sdata = get_bss_sdata(sdata);
474 if (!check_sdata_in_driver(sdata))
475 return;
477 trace_drv_sta_notify(local, sdata, cmd, sta);
478 if (local->ops->sta_notify)
479 local->ops->sta_notify(&local->hw, &sdata->vif, cmd, sta);
480 trace_drv_return_void(local);
483 static inline int drv_sta_add(struct ieee80211_local *local,
484 struct ieee80211_sub_if_data *sdata,
485 struct ieee80211_sta *sta)
487 int ret = 0;
489 might_sleep();
491 sdata = get_bss_sdata(sdata);
492 if (!check_sdata_in_driver(sdata))
493 return -EIO;
495 trace_drv_sta_add(local, sdata, sta);
496 if (local->ops->sta_add)
497 ret = local->ops->sta_add(&local->hw, &sdata->vif, sta);
499 trace_drv_return_int(local, ret);
501 return ret;
504 static inline void drv_sta_remove(struct ieee80211_local *local,
505 struct ieee80211_sub_if_data *sdata,
506 struct ieee80211_sta *sta)
508 might_sleep();
510 sdata = get_bss_sdata(sdata);
511 if (!check_sdata_in_driver(sdata))
512 return;
514 trace_drv_sta_remove(local, sdata, sta);
515 if (local->ops->sta_remove)
516 local->ops->sta_remove(&local->hw, &sdata->vif, sta);
518 trace_drv_return_void(local);
521 #ifdef CONFIG_MAC80211_DEBUGFS
522 static inline void drv_sta_add_debugfs(struct ieee80211_local *local,
523 struct ieee80211_sub_if_data *sdata,
524 struct ieee80211_sta *sta,
525 struct dentry *dir)
527 might_sleep();
529 sdata = get_bss_sdata(sdata);
530 if (!check_sdata_in_driver(sdata))
531 return;
533 if (local->ops->sta_add_debugfs)
534 local->ops->sta_add_debugfs(&local->hw, &sdata->vif,
535 sta, dir);
538 static inline void drv_sta_remove_debugfs(struct ieee80211_local *local,
539 struct ieee80211_sub_if_data *sdata,
540 struct ieee80211_sta *sta,
541 struct dentry *dir)
543 might_sleep();
545 sdata = get_bss_sdata(sdata);
546 check_sdata_in_driver(sdata);
548 if (local->ops->sta_remove_debugfs)
549 local->ops->sta_remove_debugfs(&local->hw, &sdata->vif,
550 sta, dir);
552 #endif
554 static inline void drv_sta_pre_rcu_remove(struct ieee80211_local *local,
555 struct ieee80211_sub_if_data *sdata,
556 struct sta_info *sta)
558 might_sleep();
560 sdata = get_bss_sdata(sdata);
561 if (!check_sdata_in_driver(sdata))
562 return;
564 trace_drv_sta_pre_rcu_remove(local, sdata, &sta->sta);
565 if (local->ops->sta_pre_rcu_remove)
566 local->ops->sta_pre_rcu_remove(&local->hw, &sdata->vif,
567 &sta->sta);
568 trace_drv_return_void(local);
571 static inline __must_check
572 int drv_sta_state(struct ieee80211_local *local,
573 struct ieee80211_sub_if_data *sdata,
574 struct sta_info *sta,
575 enum ieee80211_sta_state old_state,
576 enum ieee80211_sta_state new_state)
578 int ret = 0;
580 might_sleep();
582 sdata = get_bss_sdata(sdata);
583 if (!check_sdata_in_driver(sdata))
584 return -EIO;
586 trace_drv_sta_state(local, sdata, &sta->sta, old_state, new_state);
587 if (local->ops->sta_state) {
588 ret = local->ops->sta_state(&local->hw, &sdata->vif, &sta->sta,
589 old_state, new_state);
590 } else if (old_state == IEEE80211_STA_AUTH &&
591 new_state == IEEE80211_STA_ASSOC) {
592 ret = drv_sta_add(local, sdata, &sta->sta);
593 if (ret == 0)
594 sta->uploaded = true;
595 } else if (old_state == IEEE80211_STA_ASSOC &&
596 new_state == IEEE80211_STA_AUTH) {
597 drv_sta_remove(local, sdata, &sta->sta);
599 trace_drv_return_int(local, ret);
600 return ret;
603 static inline void drv_sta_rc_update(struct ieee80211_local *local,
604 struct ieee80211_sub_if_data *sdata,
605 struct ieee80211_sta *sta, u32 changed)
607 sdata = get_bss_sdata(sdata);
608 if (!check_sdata_in_driver(sdata))
609 return;
611 WARN_ON(changed & IEEE80211_RC_SUPP_RATES_CHANGED &&
612 (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
613 sdata->vif.type != NL80211_IFTYPE_MESH_POINT));
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);
620 trace_drv_return_void(local);
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)
627 int ret = -EOPNOTSUPP;
629 might_sleep();
631 if (!check_sdata_in_driver(sdata))
632 return -EIO;
634 trace_drv_conf_tx(local, sdata, ac, params);
635 if (local->ops->conf_tx)
636 ret = local->ops->conf_tx(&local->hw, &sdata->vif,
637 ac, params);
638 trace_drv_return_int(local, ret);
639 return ret;
642 static inline u64 drv_get_tsf(struct ieee80211_local *local,
643 struct ieee80211_sub_if_data *sdata)
645 u64 ret = -1ULL;
647 might_sleep();
649 if (!check_sdata_in_driver(sdata))
650 return ret;
652 trace_drv_get_tsf(local, sdata);
653 if (local->ops->get_tsf)
654 ret = local->ops->get_tsf(&local->hw, &sdata->vif);
655 trace_drv_return_u64(local, ret);
656 return ret;
659 static inline void drv_set_tsf(struct ieee80211_local *local,
660 struct ieee80211_sub_if_data *sdata,
661 u64 tsf)
663 might_sleep();
665 if (!check_sdata_in_driver(sdata))
666 return;
668 trace_drv_set_tsf(local, sdata, tsf);
669 if (local->ops->set_tsf)
670 local->ops->set_tsf(&local->hw, &sdata->vif, tsf);
671 trace_drv_return_void(local);
674 static inline void drv_reset_tsf(struct ieee80211_local *local,
675 struct ieee80211_sub_if_data *sdata)
677 might_sleep();
679 if (!check_sdata_in_driver(sdata))
680 return;
682 trace_drv_reset_tsf(local, sdata);
683 if (local->ops->reset_tsf)
684 local->ops->reset_tsf(&local->hw, &sdata->vif);
685 trace_drv_return_void(local);
688 static inline int drv_tx_last_beacon(struct ieee80211_local *local)
690 int ret = 0; /* default unsupported op for less congestion */
692 might_sleep();
694 trace_drv_tx_last_beacon(local);
695 if (local->ops->tx_last_beacon)
696 ret = local->ops->tx_last_beacon(&local->hw);
697 trace_drv_return_int(local, ret);
698 return ret;
701 static inline int drv_ampdu_action(struct ieee80211_local *local,
702 struct ieee80211_sub_if_data *sdata,
703 enum ieee80211_ampdu_mlme_action action,
704 struct ieee80211_sta *sta, u16 tid,
705 u16 *ssn, u8 buf_size)
707 int ret = -EOPNOTSUPP;
709 might_sleep();
711 sdata = get_bss_sdata(sdata);
712 if (!check_sdata_in_driver(sdata))
713 return -EIO;
715 trace_drv_ampdu_action(local, sdata, action, sta, tid, ssn, buf_size);
717 if (local->ops->ampdu_action)
718 ret = local->ops->ampdu_action(&local->hw, &sdata->vif, action,
719 sta, tid, ssn, buf_size);
721 trace_drv_return_int(local, ret);
723 return ret;
726 static inline int drv_get_survey(struct ieee80211_local *local, int idx,
727 struct survey_info *survey)
729 int ret = -EOPNOTSUPP;
731 trace_drv_get_survey(local, idx, survey);
733 if (local->ops->get_survey)
734 ret = local->ops->get_survey(&local->hw, idx, survey);
736 trace_drv_return_int(local, ret);
738 return ret;
741 static inline void drv_rfkill_poll(struct ieee80211_local *local)
743 might_sleep();
745 if (local->ops->rfkill_poll)
746 local->ops->rfkill_poll(&local->hw);
749 static inline void drv_flush(struct ieee80211_local *local,
750 struct ieee80211_sub_if_data *sdata,
751 u32 queues, bool drop)
753 struct ieee80211_vif *vif = sdata ? &sdata->vif : NULL;
755 might_sleep();
757 if (sdata && !check_sdata_in_driver(sdata))
758 return;
760 trace_drv_flush(local, queues, drop);
761 if (local->ops->flush)
762 local->ops->flush(&local->hw, vif, queues, drop);
763 trace_drv_return_void(local);
766 static inline void drv_channel_switch(struct ieee80211_local *local,
767 struct ieee80211_channel_switch *ch_switch)
769 might_sleep();
771 trace_drv_channel_switch(local, ch_switch);
772 local->ops->channel_switch(&local->hw, ch_switch);
773 trace_drv_return_void(local);
777 static inline int drv_set_antenna(struct ieee80211_local *local,
778 u32 tx_ant, u32 rx_ant)
780 int ret = -EOPNOTSUPP;
781 might_sleep();
782 if (local->ops->set_antenna)
783 ret = local->ops->set_antenna(&local->hw, tx_ant, rx_ant);
784 trace_drv_set_antenna(local, tx_ant, rx_ant, ret);
785 return ret;
788 static inline int drv_get_antenna(struct ieee80211_local *local,
789 u32 *tx_ant, u32 *rx_ant)
791 int ret = -EOPNOTSUPP;
792 might_sleep();
793 if (local->ops->get_antenna)
794 ret = local->ops->get_antenna(&local->hw, tx_ant, rx_ant);
795 trace_drv_get_antenna(local, *tx_ant, *rx_ant, ret);
796 return ret;
799 static inline int drv_remain_on_channel(struct ieee80211_local *local,
800 struct ieee80211_sub_if_data *sdata,
801 struct ieee80211_channel *chan,
802 unsigned int duration,
803 enum ieee80211_roc_type type)
805 int ret;
807 might_sleep();
809 trace_drv_remain_on_channel(local, sdata, chan, duration, type);
810 ret = local->ops->remain_on_channel(&local->hw, &sdata->vif,
811 chan, duration, type);
812 trace_drv_return_int(local, ret);
814 return ret;
817 static inline int drv_cancel_remain_on_channel(struct ieee80211_local *local)
819 int ret;
821 might_sleep();
823 trace_drv_cancel_remain_on_channel(local);
824 ret = local->ops->cancel_remain_on_channel(&local->hw);
825 trace_drv_return_int(local, ret);
827 return ret;
830 static inline int drv_set_ringparam(struct ieee80211_local *local,
831 u32 tx, u32 rx)
833 int ret = -ENOTSUPP;
835 might_sleep();
837 trace_drv_set_ringparam(local, tx, rx);
838 if (local->ops->set_ringparam)
839 ret = local->ops->set_ringparam(&local->hw, tx, rx);
840 trace_drv_return_int(local, ret);
842 return ret;
845 static inline void drv_get_ringparam(struct ieee80211_local *local,
846 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
848 might_sleep();
850 trace_drv_get_ringparam(local, tx, tx_max, rx, rx_max);
851 if (local->ops->get_ringparam)
852 local->ops->get_ringparam(&local->hw, tx, tx_max, rx, rx_max);
853 trace_drv_return_void(local);
856 static inline bool drv_tx_frames_pending(struct ieee80211_local *local)
858 bool ret = false;
860 might_sleep();
862 trace_drv_tx_frames_pending(local);
863 if (local->ops->tx_frames_pending)
864 ret = local->ops->tx_frames_pending(&local->hw);
865 trace_drv_return_bool(local, ret);
867 return ret;
870 static inline int drv_set_bitrate_mask(struct ieee80211_local *local,
871 struct ieee80211_sub_if_data *sdata,
872 const struct cfg80211_bitrate_mask *mask)
874 int ret = -EOPNOTSUPP;
876 might_sleep();
878 if (!check_sdata_in_driver(sdata))
879 return -EIO;
881 trace_drv_set_bitrate_mask(local, sdata, mask);
882 if (local->ops->set_bitrate_mask)
883 ret = local->ops->set_bitrate_mask(&local->hw,
884 &sdata->vif, mask);
885 trace_drv_return_int(local, ret);
887 return ret;
890 static inline void drv_set_rekey_data(struct ieee80211_local *local,
891 struct ieee80211_sub_if_data *sdata,
892 struct cfg80211_gtk_rekey_data *data)
894 if (!check_sdata_in_driver(sdata))
895 return;
897 trace_drv_set_rekey_data(local, sdata, data);
898 if (local->ops->set_rekey_data)
899 local->ops->set_rekey_data(&local->hw, &sdata->vif, data);
900 trace_drv_return_void(local);
903 static inline void drv_rssi_callback(struct ieee80211_local *local,
904 struct ieee80211_sub_if_data *sdata,
905 const enum ieee80211_rssi_event event)
907 trace_drv_rssi_callback(local, sdata, event);
908 if (local->ops->rssi_callback)
909 local->ops->rssi_callback(&local->hw, &sdata->vif, event);
910 trace_drv_return_void(local);
913 static inline void
914 drv_release_buffered_frames(struct ieee80211_local *local,
915 struct sta_info *sta, u16 tids, int num_frames,
916 enum ieee80211_frame_release_type reason,
917 bool more_data)
919 trace_drv_release_buffered_frames(local, &sta->sta, tids, num_frames,
920 reason, more_data);
921 if (local->ops->release_buffered_frames)
922 local->ops->release_buffered_frames(&local->hw, &sta->sta, tids,
923 num_frames, reason,
924 more_data);
925 trace_drv_return_void(local);
928 static inline void
929 drv_allow_buffered_frames(struct ieee80211_local *local,
930 struct sta_info *sta, u16 tids, int num_frames,
931 enum ieee80211_frame_release_type reason,
932 bool more_data)
934 trace_drv_allow_buffered_frames(local, &sta->sta, tids, num_frames,
935 reason, more_data);
936 if (local->ops->allow_buffered_frames)
937 local->ops->allow_buffered_frames(&local->hw, &sta->sta,
938 tids, num_frames, reason,
939 more_data);
940 trace_drv_return_void(local);
943 static inline int drv_get_rssi(struct ieee80211_local *local,
944 struct ieee80211_sub_if_data *sdata,
945 struct ieee80211_sta *sta,
946 s8 *rssi_dbm)
948 int ret;
950 might_sleep();
952 ret = local->ops->get_rssi(&local->hw, &sdata->vif, sta, rssi_dbm);
953 trace_drv_get_rssi(local, sta, *rssi_dbm, ret);
955 return ret;
958 static inline void drv_mgd_prepare_tx(struct ieee80211_local *local,
959 struct ieee80211_sub_if_data *sdata)
961 might_sleep();
963 if (!check_sdata_in_driver(sdata))
964 return;
965 WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION);
967 trace_drv_mgd_prepare_tx(local, sdata);
968 if (local->ops->mgd_prepare_tx)
969 local->ops->mgd_prepare_tx(&local->hw, &sdata->vif);
970 trace_drv_return_void(local);
973 static inline void
974 drv_mgd_protect_tdls_discover(struct ieee80211_local *local,
975 struct ieee80211_sub_if_data *sdata)
977 might_sleep();
979 if (!check_sdata_in_driver(sdata))
980 return;
981 WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION);
983 trace_drv_mgd_protect_tdls_discover(local, sdata);
984 if (local->ops->mgd_protect_tdls_discover)
985 local->ops->mgd_protect_tdls_discover(&local->hw, &sdata->vif);
986 trace_drv_return_void(local);
989 static inline int drv_add_chanctx(struct ieee80211_local *local,
990 struct ieee80211_chanctx *ctx)
992 int ret = -EOPNOTSUPP;
994 trace_drv_add_chanctx(local, ctx);
995 if (local->ops->add_chanctx)
996 ret = local->ops->add_chanctx(&local->hw, &ctx->conf);
997 trace_drv_return_int(local, ret);
998 if (!ret)
999 ctx->driver_present = true;
1001 return ret;
1004 static inline void drv_remove_chanctx(struct ieee80211_local *local,
1005 struct ieee80211_chanctx *ctx)
1007 if (WARN_ON(!ctx->driver_present))
1008 return;
1010 trace_drv_remove_chanctx(local, ctx);
1011 if (local->ops->remove_chanctx)
1012 local->ops->remove_chanctx(&local->hw, &ctx->conf);
1013 trace_drv_return_void(local);
1014 ctx->driver_present = false;
1017 static inline void drv_change_chanctx(struct ieee80211_local *local,
1018 struct ieee80211_chanctx *ctx,
1019 u32 changed)
1021 trace_drv_change_chanctx(local, ctx, changed);
1022 if (local->ops->change_chanctx) {
1023 WARN_ON_ONCE(!ctx->driver_present);
1024 local->ops->change_chanctx(&local->hw, &ctx->conf, changed);
1026 trace_drv_return_void(local);
1029 static inline int drv_assign_vif_chanctx(struct ieee80211_local *local,
1030 struct ieee80211_sub_if_data *sdata,
1031 struct ieee80211_chanctx *ctx)
1033 int ret = 0;
1035 if (!check_sdata_in_driver(sdata))
1036 return -EIO;
1038 trace_drv_assign_vif_chanctx(local, sdata, ctx);
1039 if (local->ops->assign_vif_chanctx) {
1040 WARN_ON_ONCE(!ctx->driver_present);
1041 ret = local->ops->assign_vif_chanctx(&local->hw,
1042 &sdata->vif,
1043 &ctx->conf);
1045 trace_drv_return_int(local, ret);
1047 return ret;
1050 static inline void drv_unassign_vif_chanctx(struct ieee80211_local *local,
1051 struct ieee80211_sub_if_data *sdata,
1052 struct ieee80211_chanctx *ctx)
1054 if (!check_sdata_in_driver(sdata))
1055 return;
1057 trace_drv_unassign_vif_chanctx(local, sdata, ctx);
1058 if (local->ops->unassign_vif_chanctx) {
1059 WARN_ON_ONCE(!ctx->driver_present);
1060 local->ops->unassign_vif_chanctx(&local->hw,
1061 &sdata->vif,
1062 &ctx->conf);
1064 trace_drv_return_void(local);
1067 static inline int
1068 drv_switch_vif_chanctx(struct ieee80211_local *local,
1069 struct ieee80211_vif_chanctx_switch *vifs,
1070 int n_vifs,
1071 enum ieee80211_chanctx_switch_mode mode)
1073 int ret = 0;
1074 int i;
1076 if (!local->ops->switch_vif_chanctx)
1077 return -EOPNOTSUPP;
1079 for (i = 0; i < n_vifs; i++) {
1080 struct ieee80211_chanctx *new_ctx =
1081 container_of(vifs[i].new_ctx,
1082 struct ieee80211_chanctx,
1083 conf);
1084 struct ieee80211_chanctx *old_ctx =
1085 container_of(vifs[i].old_ctx,
1086 struct ieee80211_chanctx,
1087 conf);
1089 WARN_ON_ONCE(!old_ctx->driver_present);
1090 WARN_ON_ONCE((mode == CHANCTX_SWMODE_SWAP_CONTEXTS &&
1091 new_ctx->driver_present) ||
1092 (mode == CHANCTX_SWMODE_REASSIGN_VIF &&
1093 !new_ctx->driver_present));
1096 trace_drv_switch_vif_chanctx(local, vifs, n_vifs, mode);
1097 ret = local->ops->switch_vif_chanctx(&local->hw,
1098 vifs, n_vifs, mode);
1099 trace_drv_return_int(local, ret);
1101 if (!ret && mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
1102 for (i = 0; i < n_vifs; i++) {
1103 struct ieee80211_chanctx *new_ctx =
1104 container_of(vifs[i].new_ctx,
1105 struct ieee80211_chanctx,
1106 conf);
1107 struct ieee80211_chanctx *old_ctx =
1108 container_of(vifs[i].old_ctx,
1109 struct ieee80211_chanctx,
1110 conf);
1112 new_ctx->driver_present = true;
1113 old_ctx->driver_present = false;
1117 return ret;
1120 static inline int drv_start_ap(struct ieee80211_local *local,
1121 struct ieee80211_sub_if_data *sdata)
1123 int ret = 0;
1125 if (!check_sdata_in_driver(sdata))
1126 return -EIO;
1128 trace_drv_start_ap(local, sdata, &sdata->vif.bss_conf);
1129 if (local->ops->start_ap)
1130 ret = local->ops->start_ap(&local->hw, &sdata->vif);
1131 trace_drv_return_int(local, ret);
1132 return ret;
1135 static inline void drv_stop_ap(struct ieee80211_local *local,
1136 struct ieee80211_sub_if_data *sdata)
1138 if (!check_sdata_in_driver(sdata))
1139 return;
1141 trace_drv_stop_ap(local, sdata);
1142 if (local->ops->stop_ap)
1143 local->ops->stop_ap(&local->hw, &sdata->vif);
1144 trace_drv_return_void(local);
1147 static inline void drv_restart_complete(struct ieee80211_local *local)
1149 might_sleep();
1151 trace_drv_restart_complete(local);
1152 if (local->ops->restart_complete)
1153 local->ops->restart_complete(&local->hw);
1154 trace_drv_return_void(local);
1157 static inline void
1158 drv_set_default_unicast_key(struct ieee80211_local *local,
1159 struct ieee80211_sub_if_data *sdata,
1160 int key_idx)
1162 if (!check_sdata_in_driver(sdata))
1163 return;
1165 WARN_ON_ONCE(key_idx < -1 || key_idx > 3);
1167 trace_drv_set_default_unicast_key(local, sdata, key_idx);
1168 if (local->ops->set_default_unicast_key)
1169 local->ops->set_default_unicast_key(&local->hw, &sdata->vif,
1170 key_idx);
1171 trace_drv_return_void(local);
1174 #if IS_ENABLED(CONFIG_IPV6)
1175 static inline void drv_ipv6_addr_change(struct ieee80211_local *local,
1176 struct ieee80211_sub_if_data *sdata,
1177 struct inet6_dev *idev)
1179 trace_drv_ipv6_addr_change(local, sdata);
1180 if (local->ops->ipv6_addr_change)
1181 local->ops->ipv6_addr_change(&local->hw, &sdata->vif, idev);
1182 trace_drv_return_void(local);
1184 #endif
1186 static inline void
1187 drv_channel_switch_beacon(struct ieee80211_sub_if_data *sdata,
1188 struct cfg80211_chan_def *chandef)
1190 struct ieee80211_local *local = sdata->local;
1192 if (local->ops->channel_switch_beacon) {
1193 trace_drv_channel_switch_beacon(local, sdata, chandef);
1194 local->ops->channel_switch_beacon(&local->hw, &sdata->vif,
1195 chandef);
1199 static inline int drv_join_ibss(struct ieee80211_local *local,
1200 struct ieee80211_sub_if_data *sdata)
1202 int ret = 0;
1204 might_sleep();
1205 if (!check_sdata_in_driver(sdata))
1206 return -EIO;
1208 trace_drv_join_ibss(local, sdata, &sdata->vif.bss_conf);
1209 if (local->ops->join_ibss)
1210 ret = local->ops->join_ibss(&local->hw, &sdata->vif);
1211 trace_drv_return_int(local, ret);
1212 return ret;
1215 static inline void drv_leave_ibss(struct ieee80211_local *local,
1216 struct ieee80211_sub_if_data *sdata)
1218 might_sleep();
1219 if (!check_sdata_in_driver(sdata))
1220 return;
1222 trace_drv_leave_ibss(local, sdata);
1223 if (local->ops->leave_ibss)
1224 local->ops->leave_ibss(&local->hw, &sdata->vif);
1225 trace_drv_return_void(local);
1228 static inline u32 drv_get_expected_throughput(struct ieee80211_local *local,
1229 struct ieee80211_sta *sta)
1231 u32 ret = 0;
1233 trace_drv_get_expected_throughput(sta);
1234 if (local->ops->get_expected_throughput)
1235 ret = local->ops->get_expected_throughput(sta);
1236 trace_drv_return_u32(local, ret);
1238 return ret;
1241 #endif /* __MAC80211_DRIVER_OPS */