Linux 3.3-rc6
[linux/fpc-iii.git] / net / mac80211 / driver-ops.h
blobe8960ae3986126aadd0b4254909d7b9b45fd07c9
1 #ifndef __MAC80211_DRIVER_OPS
2 #define __MAC80211_DRIVER_OPS
4 #include <net/mac80211.h>
5 #include "ieee80211_i.h"
6 #include "driver-trace.h"
8 static inline void check_sdata_in_driver(struct ieee80211_sub_if_data *sdata)
10 WARN_ON(!(sdata->flags & IEEE80211_SDATA_IN_DRIVER));
13 static inline struct ieee80211_sub_if_data *
14 get_bss_sdata(struct ieee80211_sub_if_data *sdata)
16 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
17 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
18 u.ap);
20 return sdata;
23 static inline void drv_tx(struct ieee80211_local *local, struct sk_buff *skb)
25 local->ops->tx(&local->hw, skb);
28 static inline void drv_tx_frags(struct ieee80211_local *local,
29 struct ieee80211_vif *vif,
30 struct ieee80211_sta *sta,
31 struct sk_buff_head *skbs)
33 local->ops->tx_frags(&local->hw, vif, sta, skbs);
36 static inline int drv_start(struct ieee80211_local *local)
38 int ret;
40 might_sleep();
42 trace_drv_start(local);
43 local->started = true;
44 smp_mb();
45 ret = local->ops->start(&local->hw);
46 trace_drv_return_int(local, ret);
47 return ret;
50 static inline void drv_stop(struct ieee80211_local *local)
52 might_sleep();
54 trace_drv_stop(local);
55 local->ops->stop(&local->hw);
56 trace_drv_return_void(local);
58 /* sync away all work on the tasklet before clearing started */
59 tasklet_disable(&local->tasklet);
60 tasklet_enable(&local->tasklet);
62 barrier();
64 local->started = false;
67 #ifdef CONFIG_PM
68 static inline int drv_suspend(struct ieee80211_local *local,
69 struct cfg80211_wowlan *wowlan)
71 int ret;
73 might_sleep();
75 trace_drv_suspend(local);
76 ret = local->ops->suspend(&local->hw, wowlan);
77 trace_drv_return_int(local, ret);
78 return ret;
81 static inline int drv_resume(struct ieee80211_local *local)
83 int ret;
85 might_sleep();
87 trace_drv_resume(local);
88 ret = local->ops->resume(&local->hw);
89 trace_drv_return_int(local, ret);
90 return ret;
92 #endif
94 static inline int drv_add_interface(struct ieee80211_local *local,
95 struct ieee80211_sub_if_data *sdata)
97 int ret;
99 might_sleep();
101 if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
102 sdata->vif.type == NL80211_IFTYPE_MONITOR))
103 return -EINVAL;
105 trace_drv_add_interface(local, sdata);
106 ret = local->ops->add_interface(&local->hw, &sdata->vif);
107 trace_drv_return_int(local, ret);
109 if (ret == 0)
110 sdata->flags |= IEEE80211_SDATA_IN_DRIVER;
112 return ret;
115 static inline int drv_change_interface(struct ieee80211_local *local,
116 struct ieee80211_sub_if_data *sdata,
117 enum nl80211_iftype type, bool p2p)
119 int ret;
121 might_sleep();
123 check_sdata_in_driver(sdata);
125 trace_drv_change_interface(local, sdata, type, p2p);
126 ret = local->ops->change_interface(&local->hw, &sdata->vif, type, p2p);
127 trace_drv_return_int(local, ret);
128 return ret;
131 static inline void drv_remove_interface(struct ieee80211_local *local,
132 struct ieee80211_sub_if_data *sdata)
134 might_sleep();
136 check_sdata_in_driver(sdata);
138 trace_drv_remove_interface(local, sdata);
139 local->ops->remove_interface(&local->hw, &sdata->vif);
140 sdata->flags &= ~IEEE80211_SDATA_IN_DRIVER;
141 trace_drv_return_void(local);
144 static inline int drv_config(struct ieee80211_local *local, u32 changed)
146 int ret;
148 might_sleep();
150 trace_drv_config(local, changed);
151 ret = local->ops->config(&local->hw, changed);
152 trace_drv_return_int(local, ret);
153 return ret;
156 static inline void drv_bss_info_changed(struct ieee80211_local *local,
157 struct ieee80211_sub_if_data *sdata,
158 struct ieee80211_bss_conf *info,
159 u32 changed)
161 might_sleep();
163 check_sdata_in_driver(sdata);
165 trace_drv_bss_info_changed(local, sdata, info, changed);
166 if (local->ops->bss_info_changed)
167 local->ops->bss_info_changed(&local->hw, &sdata->vif, info, changed);
168 trace_drv_return_void(local);
171 static inline int drv_tx_sync(struct ieee80211_local *local,
172 struct ieee80211_sub_if_data *sdata,
173 const u8 *bssid,
174 enum ieee80211_tx_sync_type type)
176 int ret = 0;
178 might_sleep();
180 check_sdata_in_driver(sdata);
182 trace_drv_tx_sync(local, sdata, bssid, type);
183 if (local->ops->tx_sync)
184 ret = local->ops->tx_sync(&local->hw, &sdata->vif,
185 bssid, type);
186 trace_drv_return_int(local, ret);
187 return ret;
190 static inline void drv_finish_tx_sync(struct ieee80211_local *local,
191 struct ieee80211_sub_if_data *sdata,
192 const u8 *bssid,
193 enum ieee80211_tx_sync_type type)
195 might_sleep();
197 check_sdata_in_driver(sdata);
199 trace_drv_finish_tx_sync(local, sdata, bssid, type);
200 if (local->ops->finish_tx_sync)
201 local->ops->finish_tx_sync(&local->hw, &sdata->vif,
202 bssid, type);
203 trace_drv_return_void(local);
206 static inline u64 drv_prepare_multicast(struct ieee80211_local *local,
207 struct netdev_hw_addr_list *mc_list)
209 u64 ret = 0;
211 trace_drv_prepare_multicast(local, mc_list->count);
213 if (local->ops->prepare_multicast)
214 ret = local->ops->prepare_multicast(&local->hw, mc_list);
216 trace_drv_return_u64(local, ret);
218 return ret;
221 static inline void drv_configure_filter(struct ieee80211_local *local,
222 unsigned int changed_flags,
223 unsigned int *total_flags,
224 u64 multicast)
226 might_sleep();
228 trace_drv_configure_filter(local, changed_flags, total_flags,
229 multicast);
230 local->ops->configure_filter(&local->hw, changed_flags, total_flags,
231 multicast);
232 trace_drv_return_void(local);
235 static inline int drv_set_tim(struct ieee80211_local *local,
236 struct ieee80211_sta *sta, bool set)
238 int ret = 0;
239 trace_drv_set_tim(local, sta, set);
240 if (local->ops->set_tim)
241 ret = local->ops->set_tim(&local->hw, sta, set);
242 trace_drv_return_int(local, ret);
243 return ret;
246 static inline int drv_set_key(struct ieee80211_local *local,
247 enum set_key_cmd cmd,
248 struct ieee80211_sub_if_data *sdata,
249 struct ieee80211_sta *sta,
250 struct ieee80211_key_conf *key)
252 int ret;
254 might_sleep();
256 check_sdata_in_driver(sdata);
258 trace_drv_set_key(local, cmd, sdata, sta, key);
259 ret = local->ops->set_key(&local->hw, cmd, &sdata->vif, sta, key);
260 trace_drv_return_int(local, ret);
261 return ret;
264 static inline void drv_update_tkip_key(struct ieee80211_local *local,
265 struct ieee80211_sub_if_data *sdata,
266 struct ieee80211_key_conf *conf,
267 struct sta_info *sta, u32 iv32,
268 u16 *phase1key)
270 struct ieee80211_sta *ista = NULL;
272 if (sta)
273 ista = &sta->sta;
275 check_sdata_in_driver(sdata);
277 trace_drv_update_tkip_key(local, sdata, conf, ista, iv32);
278 if (local->ops->update_tkip_key)
279 local->ops->update_tkip_key(&local->hw, &sdata->vif, conf,
280 ista, iv32, phase1key);
281 trace_drv_return_void(local);
284 static inline int drv_hw_scan(struct ieee80211_local *local,
285 struct ieee80211_sub_if_data *sdata,
286 struct cfg80211_scan_request *req)
288 int ret;
290 might_sleep();
292 check_sdata_in_driver(sdata);
294 trace_drv_hw_scan(local, sdata);
295 ret = local->ops->hw_scan(&local->hw, &sdata->vif, req);
296 trace_drv_return_int(local, ret);
297 return ret;
300 static inline void drv_cancel_hw_scan(struct ieee80211_local *local,
301 struct ieee80211_sub_if_data *sdata)
303 might_sleep();
305 check_sdata_in_driver(sdata);
307 trace_drv_cancel_hw_scan(local, sdata);
308 local->ops->cancel_hw_scan(&local->hw, &sdata->vif);
309 trace_drv_return_void(local);
312 static inline int
313 drv_sched_scan_start(struct ieee80211_local *local,
314 struct ieee80211_sub_if_data *sdata,
315 struct cfg80211_sched_scan_request *req,
316 struct ieee80211_sched_scan_ies *ies)
318 int ret;
320 might_sleep();
322 check_sdata_in_driver(sdata);
324 trace_drv_sched_scan_start(local, sdata);
325 ret = local->ops->sched_scan_start(&local->hw, &sdata->vif,
326 req, ies);
327 trace_drv_return_int(local, ret);
328 return ret;
331 static inline void drv_sched_scan_stop(struct ieee80211_local *local,
332 struct ieee80211_sub_if_data *sdata)
334 might_sleep();
336 check_sdata_in_driver(sdata);
338 trace_drv_sched_scan_stop(local, sdata);
339 local->ops->sched_scan_stop(&local->hw, &sdata->vif);
340 trace_drv_return_void(local);
343 static inline void drv_sw_scan_start(struct ieee80211_local *local)
345 might_sleep();
347 trace_drv_sw_scan_start(local);
348 if (local->ops->sw_scan_start)
349 local->ops->sw_scan_start(&local->hw);
350 trace_drv_return_void(local);
353 static inline void drv_sw_scan_complete(struct ieee80211_local *local)
355 might_sleep();
357 trace_drv_sw_scan_complete(local);
358 if (local->ops->sw_scan_complete)
359 local->ops->sw_scan_complete(&local->hw);
360 trace_drv_return_void(local);
363 static inline int drv_get_stats(struct ieee80211_local *local,
364 struct ieee80211_low_level_stats *stats)
366 int ret = -EOPNOTSUPP;
368 might_sleep();
370 if (local->ops->get_stats)
371 ret = local->ops->get_stats(&local->hw, stats);
372 trace_drv_get_stats(local, stats, ret);
374 return ret;
377 static inline void drv_get_tkip_seq(struct ieee80211_local *local,
378 u8 hw_key_idx, u32 *iv32, u16 *iv16)
380 if (local->ops->get_tkip_seq)
381 local->ops->get_tkip_seq(&local->hw, hw_key_idx, iv32, iv16);
382 trace_drv_get_tkip_seq(local, hw_key_idx, iv32, iv16);
385 static inline int drv_set_frag_threshold(struct ieee80211_local *local,
386 u32 value)
388 int ret = 0;
390 might_sleep();
392 trace_drv_set_frag_threshold(local, value);
393 if (local->ops->set_frag_threshold)
394 ret = local->ops->set_frag_threshold(&local->hw, value);
395 trace_drv_return_int(local, ret);
396 return ret;
399 static inline int drv_set_rts_threshold(struct ieee80211_local *local,
400 u32 value)
402 int ret = 0;
404 might_sleep();
406 trace_drv_set_rts_threshold(local, value);
407 if (local->ops->set_rts_threshold)
408 ret = local->ops->set_rts_threshold(&local->hw, value);
409 trace_drv_return_int(local, ret);
410 return ret;
413 static inline int drv_set_coverage_class(struct ieee80211_local *local,
414 u8 value)
416 int ret = 0;
417 might_sleep();
419 trace_drv_set_coverage_class(local, value);
420 if (local->ops->set_coverage_class)
421 local->ops->set_coverage_class(&local->hw, value);
422 else
423 ret = -EOPNOTSUPP;
425 trace_drv_return_int(local, ret);
426 return ret;
429 static inline void drv_sta_notify(struct ieee80211_local *local,
430 struct ieee80211_sub_if_data *sdata,
431 enum sta_notify_cmd cmd,
432 struct ieee80211_sta *sta)
434 sdata = get_bss_sdata(sdata);
435 check_sdata_in_driver(sdata);
437 trace_drv_sta_notify(local, sdata, cmd, sta);
438 if (local->ops->sta_notify)
439 local->ops->sta_notify(&local->hw, &sdata->vif, cmd, sta);
440 trace_drv_return_void(local);
443 static inline int drv_sta_add(struct ieee80211_local *local,
444 struct ieee80211_sub_if_data *sdata,
445 struct ieee80211_sta *sta)
447 int ret = 0;
449 might_sleep();
451 sdata = get_bss_sdata(sdata);
452 check_sdata_in_driver(sdata);
454 trace_drv_sta_add(local, sdata, sta);
455 if (local->ops->sta_add)
456 ret = local->ops->sta_add(&local->hw, &sdata->vif, sta);
458 trace_drv_return_int(local, ret);
460 return ret;
463 static inline void drv_sta_remove(struct ieee80211_local *local,
464 struct ieee80211_sub_if_data *sdata,
465 struct ieee80211_sta *sta)
467 might_sleep();
469 sdata = get_bss_sdata(sdata);
470 check_sdata_in_driver(sdata);
472 trace_drv_sta_remove(local, sdata, sta);
473 if (local->ops->sta_remove)
474 local->ops->sta_remove(&local->hw, &sdata->vif, sta);
476 trace_drv_return_void(local);
479 static inline int drv_conf_tx(struct ieee80211_local *local,
480 struct ieee80211_sub_if_data *sdata, u16 queue,
481 const struct ieee80211_tx_queue_params *params)
483 int ret = -EOPNOTSUPP;
485 might_sleep();
487 check_sdata_in_driver(sdata);
489 trace_drv_conf_tx(local, sdata, queue, params);
490 if (local->ops->conf_tx)
491 ret = local->ops->conf_tx(&local->hw, &sdata->vif,
492 queue, params);
493 trace_drv_return_int(local, ret);
494 return ret;
497 static inline u64 drv_get_tsf(struct ieee80211_local *local,
498 struct ieee80211_sub_if_data *sdata)
500 u64 ret = -1ULL;
502 might_sleep();
504 check_sdata_in_driver(sdata);
506 trace_drv_get_tsf(local, sdata);
507 if (local->ops->get_tsf)
508 ret = local->ops->get_tsf(&local->hw, &sdata->vif);
509 trace_drv_return_u64(local, ret);
510 return ret;
513 static inline void drv_set_tsf(struct ieee80211_local *local,
514 struct ieee80211_sub_if_data *sdata,
515 u64 tsf)
517 might_sleep();
519 check_sdata_in_driver(sdata);
521 trace_drv_set_tsf(local, sdata, tsf);
522 if (local->ops->set_tsf)
523 local->ops->set_tsf(&local->hw, &sdata->vif, tsf);
524 trace_drv_return_void(local);
527 static inline void drv_reset_tsf(struct ieee80211_local *local,
528 struct ieee80211_sub_if_data *sdata)
530 might_sleep();
532 check_sdata_in_driver(sdata);
534 trace_drv_reset_tsf(local, sdata);
535 if (local->ops->reset_tsf)
536 local->ops->reset_tsf(&local->hw, &sdata->vif);
537 trace_drv_return_void(local);
540 static inline int drv_tx_last_beacon(struct ieee80211_local *local)
542 int ret = 0; /* default unsuported op for less congestion */
544 might_sleep();
546 trace_drv_tx_last_beacon(local);
547 if (local->ops->tx_last_beacon)
548 ret = local->ops->tx_last_beacon(&local->hw);
549 trace_drv_return_int(local, ret);
550 return ret;
553 static inline int drv_ampdu_action(struct ieee80211_local *local,
554 struct ieee80211_sub_if_data *sdata,
555 enum ieee80211_ampdu_mlme_action action,
556 struct ieee80211_sta *sta, u16 tid,
557 u16 *ssn, u8 buf_size)
559 int ret = -EOPNOTSUPP;
561 might_sleep();
563 sdata = get_bss_sdata(sdata);
564 check_sdata_in_driver(sdata);
566 trace_drv_ampdu_action(local, sdata, action, sta, tid, ssn, buf_size);
568 if (local->ops->ampdu_action)
569 ret = local->ops->ampdu_action(&local->hw, &sdata->vif, action,
570 sta, tid, ssn, buf_size);
572 trace_drv_return_int(local, ret);
574 return ret;
577 static inline int drv_get_survey(struct ieee80211_local *local, int idx,
578 struct survey_info *survey)
580 int ret = -EOPNOTSUPP;
582 trace_drv_get_survey(local, idx, survey);
584 if (local->ops->get_survey)
585 ret = local->ops->get_survey(&local->hw, idx, survey);
587 trace_drv_return_int(local, ret);
589 return ret;
592 static inline void drv_rfkill_poll(struct ieee80211_local *local)
594 might_sleep();
596 if (local->ops->rfkill_poll)
597 local->ops->rfkill_poll(&local->hw);
600 static inline void drv_flush(struct ieee80211_local *local, bool drop)
602 might_sleep();
604 trace_drv_flush(local, drop);
605 if (local->ops->flush)
606 local->ops->flush(&local->hw, drop);
607 trace_drv_return_void(local);
610 static inline void drv_channel_switch(struct ieee80211_local *local,
611 struct ieee80211_channel_switch *ch_switch)
613 might_sleep();
615 trace_drv_channel_switch(local, ch_switch);
616 local->ops->channel_switch(&local->hw, ch_switch);
617 trace_drv_return_void(local);
621 static inline int drv_set_antenna(struct ieee80211_local *local,
622 u32 tx_ant, u32 rx_ant)
624 int ret = -EOPNOTSUPP;
625 might_sleep();
626 if (local->ops->set_antenna)
627 ret = local->ops->set_antenna(&local->hw, tx_ant, rx_ant);
628 trace_drv_set_antenna(local, tx_ant, rx_ant, ret);
629 return ret;
632 static inline int drv_get_antenna(struct ieee80211_local *local,
633 u32 *tx_ant, u32 *rx_ant)
635 int ret = -EOPNOTSUPP;
636 might_sleep();
637 if (local->ops->get_antenna)
638 ret = local->ops->get_antenna(&local->hw, tx_ant, rx_ant);
639 trace_drv_get_antenna(local, *tx_ant, *rx_ant, ret);
640 return ret;
643 static inline int drv_remain_on_channel(struct ieee80211_local *local,
644 struct ieee80211_channel *chan,
645 enum nl80211_channel_type chantype,
646 unsigned int duration)
648 int ret;
650 might_sleep();
652 trace_drv_remain_on_channel(local, chan, chantype, duration);
653 ret = local->ops->remain_on_channel(&local->hw, chan, chantype,
654 duration);
655 trace_drv_return_int(local, ret);
657 return ret;
660 static inline int drv_cancel_remain_on_channel(struct ieee80211_local *local)
662 int ret;
664 might_sleep();
666 trace_drv_cancel_remain_on_channel(local);
667 ret = local->ops->cancel_remain_on_channel(&local->hw);
668 trace_drv_return_int(local, ret);
670 return ret;
673 static inline int drv_set_ringparam(struct ieee80211_local *local,
674 u32 tx, u32 rx)
676 int ret = -ENOTSUPP;
678 might_sleep();
680 trace_drv_set_ringparam(local, tx, rx);
681 if (local->ops->set_ringparam)
682 ret = local->ops->set_ringparam(&local->hw, tx, rx);
683 trace_drv_return_int(local, ret);
685 return ret;
688 static inline void drv_get_ringparam(struct ieee80211_local *local,
689 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
691 might_sleep();
693 trace_drv_get_ringparam(local, tx, tx_max, rx, rx_max);
694 if (local->ops->get_ringparam)
695 local->ops->get_ringparam(&local->hw, tx, tx_max, rx, rx_max);
696 trace_drv_return_void(local);
699 static inline bool drv_tx_frames_pending(struct ieee80211_local *local)
701 bool ret = false;
703 might_sleep();
705 trace_drv_tx_frames_pending(local);
706 if (local->ops->tx_frames_pending)
707 ret = local->ops->tx_frames_pending(&local->hw);
708 trace_drv_return_bool(local, ret);
710 return ret;
713 static inline int drv_set_bitrate_mask(struct ieee80211_local *local,
714 struct ieee80211_sub_if_data *sdata,
715 const struct cfg80211_bitrate_mask *mask)
717 int ret = -EOPNOTSUPP;
719 might_sleep();
721 check_sdata_in_driver(sdata);
723 trace_drv_set_bitrate_mask(local, sdata, mask);
724 if (local->ops->set_bitrate_mask)
725 ret = local->ops->set_bitrate_mask(&local->hw,
726 &sdata->vif, mask);
727 trace_drv_return_int(local, ret);
729 return ret;
732 static inline void drv_set_rekey_data(struct ieee80211_local *local,
733 struct ieee80211_sub_if_data *sdata,
734 struct cfg80211_gtk_rekey_data *data)
736 check_sdata_in_driver(sdata);
738 trace_drv_set_rekey_data(local, sdata, data);
739 if (local->ops->set_rekey_data)
740 local->ops->set_rekey_data(&local->hw, &sdata->vif, data);
741 trace_drv_return_void(local);
744 static inline void drv_rssi_callback(struct ieee80211_local *local,
745 const enum ieee80211_rssi_event event)
747 trace_drv_rssi_callback(local, event);
748 if (local->ops->rssi_callback)
749 local->ops->rssi_callback(&local->hw, event);
750 trace_drv_return_void(local);
753 static inline void
754 drv_release_buffered_frames(struct ieee80211_local *local,
755 struct sta_info *sta, u16 tids, int num_frames,
756 enum ieee80211_frame_release_type reason,
757 bool more_data)
759 trace_drv_release_buffered_frames(local, &sta->sta, tids, num_frames,
760 reason, more_data);
761 if (local->ops->release_buffered_frames)
762 local->ops->release_buffered_frames(&local->hw, &sta->sta, tids,
763 num_frames, reason,
764 more_data);
765 trace_drv_return_void(local);
768 static inline void
769 drv_allow_buffered_frames(struct ieee80211_local *local,
770 struct sta_info *sta, u16 tids, int num_frames,
771 enum ieee80211_frame_release_type reason,
772 bool more_data)
774 trace_drv_allow_buffered_frames(local, &sta->sta, tids, num_frames,
775 reason, more_data);
776 if (local->ops->allow_buffered_frames)
777 local->ops->allow_buffered_frames(&local->hw, &sta->sta,
778 tids, num_frames, reason,
779 more_data);
780 trace_drv_return_void(local);
782 #endif /* __MAC80211_DRIVER_OPS */