Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wirel...
[pandora-kernel.git] / net / mac80211 / driver-ops.h
1 #ifndef __MAC80211_DRIVER_OPS
2 #define __MAC80211_DRIVER_OPS
3
4 #include <net/mac80211.h>
5 #include "ieee80211_i.h"
6 #include "driver-trace.h"
7
8 static inline void check_sdata_in_driver(struct ieee80211_sub_if_data *sdata)
9 {
10         WARN_ON(!(sdata->flags & IEEE80211_SDATA_IN_DRIVER));
11 }
12
13 static inline void drv_tx(struct ieee80211_local *local, struct sk_buff *skb)
14 {
15         local->ops->tx(&local->hw, skb);
16 }
17
18 static inline int drv_start(struct ieee80211_local *local)
19 {
20         int ret;
21
22         might_sleep();
23
24         trace_drv_start(local);
25         local->started = true;
26         smp_mb();
27         ret = local->ops->start(&local->hw);
28         trace_drv_return_int(local, ret);
29         return ret;
30 }
31
32 static inline void drv_stop(struct ieee80211_local *local)
33 {
34         might_sleep();
35
36         trace_drv_stop(local);
37         local->ops->stop(&local->hw);
38         trace_drv_return_void(local);
39
40         /* sync away all work on the tasklet before clearing started */
41         tasklet_disable(&local->tasklet);
42         tasklet_enable(&local->tasklet);
43
44         barrier();
45
46         local->started = false;
47 }
48
49 #ifdef CONFIG_PM
50 static inline int drv_suspend(struct ieee80211_local *local,
51                               struct cfg80211_wowlan *wowlan)
52 {
53         int ret;
54
55         might_sleep();
56
57         trace_drv_suspend(local);
58         ret = local->ops->suspend(&local->hw, wowlan);
59         trace_drv_return_int(local, ret);
60         return ret;
61 }
62
63 static inline int drv_resume(struct ieee80211_local *local)
64 {
65         int ret;
66
67         might_sleep();
68
69         trace_drv_resume(local);
70         ret = local->ops->resume(&local->hw);
71         trace_drv_return_int(local, ret);
72         return ret;
73 }
74 #endif
75
76 static inline int drv_add_interface(struct ieee80211_local *local,
77                                     struct ieee80211_sub_if_data *sdata)
78 {
79         int ret;
80
81         might_sleep();
82
83         if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
84                     sdata->vif.type == NL80211_IFTYPE_MONITOR))
85                 return -EINVAL;
86
87         trace_drv_add_interface(local, sdata);
88         ret = local->ops->add_interface(&local->hw, &sdata->vif);
89         trace_drv_return_int(local, ret);
90
91         if (ret == 0)
92                 sdata->flags |= IEEE80211_SDATA_IN_DRIVER;
93
94         return ret;
95 }
96
97 static inline int drv_change_interface(struct ieee80211_local *local,
98                                        struct ieee80211_sub_if_data *sdata,
99                                        enum nl80211_iftype type, bool p2p)
100 {
101         int ret;
102
103         might_sleep();
104
105         check_sdata_in_driver(sdata);
106
107         trace_drv_change_interface(local, sdata, type, p2p);
108         ret = local->ops->change_interface(&local->hw, &sdata->vif, type, p2p);
109         trace_drv_return_int(local, ret);
110         return ret;
111 }
112
113 static inline void drv_remove_interface(struct ieee80211_local *local,
114                                         struct ieee80211_sub_if_data *sdata)
115 {
116         might_sleep();
117
118         check_sdata_in_driver(sdata);
119
120         trace_drv_remove_interface(local, sdata);
121         local->ops->remove_interface(&local->hw, &sdata->vif);
122         sdata->flags &= ~IEEE80211_SDATA_IN_DRIVER;
123         trace_drv_return_void(local);
124 }
125
126 static inline int drv_config(struct ieee80211_local *local, u32 changed)
127 {
128         int ret;
129
130         might_sleep();
131
132         trace_drv_config(local, changed);
133         ret = local->ops->config(&local->hw, changed);
134         trace_drv_return_int(local, ret);
135         return ret;
136 }
137
138 static inline void drv_bss_info_changed(struct ieee80211_local *local,
139                                         struct ieee80211_sub_if_data *sdata,
140                                         struct ieee80211_bss_conf *info,
141                                         u32 changed)
142 {
143         might_sleep();
144
145         check_sdata_in_driver(sdata);
146
147         trace_drv_bss_info_changed(local, sdata, info, changed);
148         if (local->ops->bss_info_changed)
149                 local->ops->bss_info_changed(&local->hw, &sdata->vif, info, changed);
150         trace_drv_return_void(local);
151 }
152
153 static inline int drv_tx_sync(struct ieee80211_local *local,
154                               struct ieee80211_sub_if_data *sdata,
155                               const u8 *bssid,
156                               enum ieee80211_tx_sync_type type)
157 {
158         int ret = 0;
159
160         might_sleep();
161
162         check_sdata_in_driver(sdata);
163
164         trace_drv_tx_sync(local, sdata, bssid, type);
165         if (local->ops->tx_sync)
166                 ret = local->ops->tx_sync(&local->hw, &sdata->vif,
167                                           bssid, type);
168         trace_drv_return_int(local, ret);
169         return ret;
170 }
171
172 static inline void drv_finish_tx_sync(struct ieee80211_local *local,
173                                       struct ieee80211_sub_if_data *sdata,
174                                       const u8 *bssid,
175                                       enum ieee80211_tx_sync_type type)
176 {
177         might_sleep();
178
179         check_sdata_in_driver(sdata);
180
181         trace_drv_finish_tx_sync(local, sdata, bssid, type);
182         if (local->ops->finish_tx_sync)
183                 local->ops->finish_tx_sync(&local->hw, &sdata->vif,
184                                            bssid, type);
185         trace_drv_return_void(local);
186 }
187
188 static inline u64 drv_prepare_multicast(struct ieee80211_local *local,
189                                         struct netdev_hw_addr_list *mc_list)
190 {
191         u64 ret = 0;
192
193         trace_drv_prepare_multicast(local, mc_list->count);
194
195         if (local->ops->prepare_multicast)
196                 ret = local->ops->prepare_multicast(&local->hw, mc_list);
197
198         trace_drv_return_u64(local, ret);
199
200         return ret;
201 }
202
203 static inline void drv_configure_filter(struct ieee80211_local *local,
204                                         unsigned int changed_flags,
205                                         unsigned int *total_flags,
206                                         u64 multicast)
207 {
208         might_sleep();
209
210         trace_drv_configure_filter(local, changed_flags, total_flags,
211                                    multicast);
212         local->ops->configure_filter(&local->hw, changed_flags, total_flags,
213                                      multicast);
214         trace_drv_return_void(local);
215 }
216
217 static inline int drv_set_tim(struct ieee80211_local *local,
218                               struct ieee80211_sta *sta, bool set)
219 {
220         int ret = 0;
221         trace_drv_set_tim(local, sta, set);
222         if (local->ops->set_tim)
223                 ret = local->ops->set_tim(&local->hw, sta, set);
224         trace_drv_return_int(local, ret);
225         return ret;
226 }
227
228 static inline int drv_set_key(struct ieee80211_local *local,
229                               enum set_key_cmd cmd,
230                               struct ieee80211_sub_if_data *sdata,
231                               struct ieee80211_sta *sta,
232                               struct ieee80211_key_conf *key)
233 {
234         int ret;
235
236         might_sleep();
237
238         check_sdata_in_driver(sdata);
239
240         trace_drv_set_key(local, cmd, sdata, sta, key);
241         ret = local->ops->set_key(&local->hw, cmd, &sdata->vif, sta, key);
242         trace_drv_return_int(local, ret);
243         return ret;
244 }
245
246 static inline void drv_update_tkip_key(struct ieee80211_local *local,
247                                        struct ieee80211_sub_if_data *sdata,
248                                        struct ieee80211_key_conf *conf,
249                                        struct sta_info *sta, u32 iv32,
250                                        u16 *phase1key)
251 {
252         struct ieee80211_sta *ista = NULL;
253
254         if (sta)
255                 ista = &sta->sta;
256
257         check_sdata_in_driver(sdata);
258
259         trace_drv_update_tkip_key(local, sdata, conf, ista, iv32);
260         if (local->ops->update_tkip_key)
261                 local->ops->update_tkip_key(&local->hw, &sdata->vif, conf,
262                                             ista, iv32, phase1key);
263         trace_drv_return_void(local);
264 }
265
266 static inline int drv_hw_scan(struct ieee80211_local *local,
267                               struct ieee80211_sub_if_data *sdata,
268                               struct cfg80211_scan_request *req)
269 {
270         int ret;
271
272         might_sleep();
273
274         check_sdata_in_driver(sdata);
275
276         trace_drv_hw_scan(local, sdata);
277         ret = local->ops->hw_scan(&local->hw, &sdata->vif, req);
278         trace_drv_return_int(local, ret);
279         return ret;
280 }
281
282 static inline void drv_cancel_hw_scan(struct ieee80211_local *local,
283                                       struct ieee80211_sub_if_data *sdata)
284 {
285         might_sleep();
286
287         check_sdata_in_driver(sdata);
288
289         trace_drv_cancel_hw_scan(local, sdata);
290         local->ops->cancel_hw_scan(&local->hw, &sdata->vif);
291         trace_drv_return_void(local);
292 }
293
294 static inline int
295 drv_sched_scan_start(struct ieee80211_local *local,
296                      struct ieee80211_sub_if_data *sdata,
297                      struct cfg80211_sched_scan_request *req,
298                      struct ieee80211_sched_scan_ies *ies)
299 {
300         int ret;
301
302         might_sleep();
303
304         check_sdata_in_driver(sdata);
305
306         trace_drv_sched_scan_start(local, sdata);
307         ret = local->ops->sched_scan_start(&local->hw, &sdata->vif,
308                                               req, ies);
309         trace_drv_return_int(local, ret);
310         return ret;
311 }
312
313 static inline void drv_sched_scan_stop(struct ieee80211_local *local,
314                                        struct ieee80211_sub_if_data *sdata)
315 {
316         might_sleep();
317
318         check_sdata_in_driver(sdata);
319
320         trace_drv_sched_scan_stop(local, sdata);
321         local->ops->sched_scan_stop(&local->hw, &sdata->vif);
322         trace_drv_return_void(local);
323 }
324
325 static inline void drv_sw_scan_start(struct ieee80211_local *local)
326 {
327         might_sleep();
328
329         trace_drv_sw_scan_start(local);
330         if (local->ops->sw_scan_start)
331                 local->ops->sw_scan_start(&local->hw);
332         trace_drv_return_void(local);
333 }
334
335 static inline void drv_sw_scan_complete(struct ieee80211_local *local)
336 {
337         might_sleep();
338
339         trace_drv_sw_scan_complete(local);
340         if (local->ops->sw_scan_complete)
341                 local->ops->sw_scan_complete(&local->hw);
342         trace_drv_return_void(local);
343 }
344
345 static inline int drv_get_stats(struct ieee80211_local *local,
346                                 struct ieee80211_low_level_stats *stats)
347 {
348         int ret = -EOPNOTSUPP;
349
350         might_sleep();
351
352         if (local->ops->get_stats)
353                 ret = local->ops->get_stats(&local->hw, stats);
354         trace_drv_get_stats(local, stats, ret);
355
356         return ret;
357 }
358
359 static inline void drv_get_tkip_seq(struct ieee80211_local *local,
360                                     u8 hw_key_idx, u32 *iv32, u16 *iv16)
361 {
362         if (local->ops->get_tkip_seq)
363                 local->ops->get_tkip_seq(&local->hw, hw_key_idx, iv32, iv16);
364         trace_drv_get_tkip_seq(local, hw_key_idx, iv32, iv16);
365 }
366
367 static inline int drv_set_frag_threshold(struct ieee80211_local *local,
368                                         u32 value)
369 {
370         int ret = 0;
371
372         might_sleep();
373
374         trace_drv_set_frag_threshold(local, value);
375         if (local->ops->set_frag_threshold)
376                 ret = local->ops->set_frag_threshold(&local->hw, value);
377         trace_drv_return_int(local, ret);
378         return ret;
379 }
380
381 static inline int drv_set_rts_threshold(struct ieee80211_local *local,
382                                         u32 value)
383 {
384         int ret = 0;
385
386         might_sleep();
387
388         trace_drv_set_rts_threshold(local, value);
389         if (local->ops->set_rts_threshold)
390                 ret = local->ops->set_rts_threshold(&local->hw, value);
391         trace_drv_return_int(local, ret);
392         return ret;
393 }
394
395 static inline int drv_set_coverage_class(struct ieee80211_local *local,
396                                          u8 value)
397 {
398         int ret = 0;
399         might_sleep();
400
401         trace_drv_set_coverage_class(local, value);
402         if (local->ops->set_coverage_class)
403                 local->ops->set_coverage_class(&local->hw, value);
404         else
405                 ret = -EOPNOTSUPP;
406
407         trace_drv_return_int(local, ret);
408         return ret;
409 }
410
411 static inline void drv_sta_notify(struct ieee80211_local *local,
412                                   struct ieee80211_sub_if_data *sdata,
413                                   enum sta_notify_cmd cmd,
414                                   struct ieee80211_sta *sta)
415 {
416         check_sdata_in_driver(sdata);
417
418         trace_drv_sta_notify(local, sdata, cmd, sta);
419         if (local->ops->sta_notify)
420                 local->ops->sta_notify(&local->hw, &sdata->vif, cmd, sta);
421         trace_drv_return_void(local);
422 }
423
424 static inline int drv_sta_add(struct ieee80211_local *local,
425                               struct ieee80211_sub_if_data *sdata,
426                               struct ieee80211_sta *sta)
427 {
428         int ret = 0;
429
430         might_sleep();
431
432         check_sdata_in_driver(sdata);
433
434         trace_drv_sta_add(local, sdata, sta);
435         if (local->ops->sta_add)
436                 ret = local->ops->sta_add(&local->hw, &sdata->vif, sta);
437
438         trace_drv_return_int(local, ret);
439
440         return ret;
441 }
442
443 static inline void drv_sta_remove(struct ieee80211_local *local,
444                                   struct ieee80211_sub_if_data *sdata,
445                                   struct ieee80211_sta *sta)
446 {
447         might_sleep();
448
449         check_sdata_in_driver(sdata);
450
451         trace_drv_sta_remove(local, sdata, sta);
452         if (local->ops->sta_remove)
453                 local->ops->sta_remove(&local->hw, &sdata->vif, sta);
454
455         trace_drv_return_void(local);
456 }
457
458 static inline int drv_conf_tx(struct ieee80211_local *local,
459                               struct ieee80211_sub_if_data *sdata, u16 queue,
460                               const struct ieee80211_tx_queue_params *params)
461 {
462         int ret = -EOPNOTSUPP;
463
464         might_sleep();
465
466         check_sdata_in_driver(sdata);
467
468         trace_drv_conf_tx(local, sdata, queue, params);
469         if (local->ops->conf_tx)
470                 ret = local->ops->conf_tx(&local->hw, &sdata->vif,
471                                           queue, params);
472         trace_drv_return_int(local, ret);
473         return ret;
474 }
475
476 static inline u64 drv_get_tsf(struct ieee80211_local *local,
477                               struct ieee80211_sub_if_data *sdata)
478 {
479         u64 ret = -1ULL;
480
481         might_sleep();
482
483         check_sdata_in_driver(sdata);
484
485         trace_drv_get_tsf(local, sdata);
486         if (local->ops->get_tsf)
487                 ret = local->ops->get_tsf(&local->hw, &sdata->vif);
488         trace_drv_return_u64(local, ret);
489         return ret;
490 }
491
492 static inline void drv_set_tsf(struct ieee80211_local *local,
493                                struct ieee80211_sub_if_data *sdata,
494                                u64 tsf)
495 {
496         might_sleep();
497
498         check_sdata_in_driver(sdata);
499
500         trace_drv_set_tsf(local, sdata, tsf);
501         if (local->ops->set_tsf)
502                 local->ops->set_tsf(&local->hw, &sdata->vif, tsf);
503         trace_drv_return_void(local);
504 }
505
506 static inline void drv_reset_tsf(struct ieee80211_local *local,
507                                  struct ieee80211_sub_if_data *sdata)
508 {
509         might_sleep();
510
511         check_sdata_in_driver(sdata);
512
513         trace_drv_reset_tsf(local, sdata);
514         if (local->ops->reset_tsf)
515                 local->ops->reset_tsf(&local->hw, &sdata->vif);
516         trace_drv_return_void(local);
517 }
518
519 static inline int drv_tx_last_beacon(struct ieee80211_local *local)
520 {
521         int ret = 0; /* default unsuported op for less congestion */
522
523         might_sleep();
524
525         trace_drv_tx_last_beacon(local);
526         if (local->ops->tx_last_beacon)
527                 ret = local->ops->tx_last_beacon(&local->hw);
528         trace_drv_return_int(local, ret);
529         return ret;
530 }
531
532 static inline int drv_ampdu_action(struct ieee80211_local *local,
533                                    struct ieee80211_sub_if_data *sdata,
534                                    enum ieee80211_ampdu_mlme_action action,
535                                    struct ieee80211_sta *sta, u16 tid,
536                                    u16 *ssn, u8 buf_size)
537 {
538         int ret = -EOPNOTSUPP;
539
540         might_sleep();
541
542         check_sdata_in_driver(sdata);
543
544         trace_drv_ampdu_action(local, sdata, action, sta, tid, ssn, buf_size);
545
546         if (local->ops->ampdu_action)
547                 ret = local->ops->ampdu_action(&local->hw, &sdata->vif, action,
548                                                sta, tid, ssn, buf_size);
549
550         trace_drv_return_int(local, ret);
551
552         return ret;
553 }
554
555 static inline int drv_get_survey(struct ieee80211_local *local, int idx,
556                                 struct survey_info *survey)
557 {
558         int ret = -EOPNOTSUPP;
559
560         trace_drv_get_survey(local, idx, survey);
561
562         if (local->ops->get_survey)
563                 ret = local->ops->get_survey(&local->hw, idx, survey);
564
565         trace_drv_return_int(local, ret);
566
567         return ret;
568 }
569
570 static inline void drv_rfkill_poll(struct ieee80211_local *local)
571 {
572         might_sleep();
573
574         if (local->ops->rfkill_poll)
575                 local->ops->rfkill_poll(&local->hw);
576 }
577
578 static inline void drv_flush(struct ieee80211_local *local, bool drop)
579 {
580         might_sleep();
581
582         trace_drv_flush(local, drop);
583         if (local->ops->flush)
584                 local->ops->flush(&local->hw, drop);
585         trace_drv_return_void(local);
586 }
587
588 static inline void drv_channel_switch(struct ieee80211_local *local,
589                                      struct ieee80211_channel_switch *ch_switch)
590 {
591         might_sleep();
592
593         trace_drv_channel_switch(local, ch_switch);
594         local->ops->channel_switch(&local->hw, ch_switch);
595         trace_drv_return_void(local);
596 }
597
598
599 static inline int drv_set_antenna(struct ieee80211_local *local,
600                                   u32 tx_ant, u32 rx_ant)
601 {
602         int ret = -EOPNOTSUPP;
603         might_sleep();
604         if (local->ops->set_antenna)
605                 ret = local->ops->set_antenna(&local->hw, tx_ant, rx_ant);
606         trace_drv_set_antenna(local, tx_ant, rx_ant, ret);
607         return ret;
608 }
609
610 static inline int drv_get_antenna(struct ieee80211_local *local,
611                                   u32 *tx_ant, u32 *rx_ant)
612 {
613         int ret = -EOPNOTSUPP;
614         might_sleep();
615         if (local->ops->get_antenna)
616                 ret = local->ops->get_antenna(&local->hw, tx_ant, rx_ant);
617         trace_drv_get_antenna(local, *tx_ant, *rx_ant, ret);
618         return ret;
619 }
620
621 static inline int drv_remain_on_channel(struct ieee80211_local *local,
622                                         struct ieee80211_channel *chan,
623                                         enum nl80211_channel_type chantype,
624                                         unsigned int duration)
625 {
626         int ret;
627
628         might_sleep();
629
630         trace_drv_remain_on_channel(local, chan, chantype, duration);
631         ret = local->ops->remain_on_channel(&local->hw, chan, chantype,
632                                             duration);
633         trace_drv_return_int(local, ret);
634
635         return ret;
636 }
637
638 static inline int drv_cancel_remain_on_channel(struct ieee80211_local *local)
639 {
640         int ret;
641
642         might_sleep();
643
644         trace_drv_cancel_remain_on_channel(local);
645         ret = local->ops->cancel_remain_on_channel(&local->hw);
646         trace_drv_return_int(local, ret);
647
648         return ret;
649 }
650
651 static inline int drv_set_ringparam(struct ieee80211_local *local,
652                                     u32 tx, u32 rx)
653 {
654         int ret = -ENOTSUPP;
655
656         might_sleep();
657
658         trace_drv_set_ringparam(local, tx, rx);
659         if (local->ops->set_ringparam)
660                 ret = local->ops->set_ringparam(&local->hw, tx, rx);
661         trace_drv_return_int(local, ret);
662
663         return ret;
664 }
665
666 static inline void drv_get_ringparam(struct ieee80211_local *local,
667                                      u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
668 {
669         might_sleep();
670
671         trace_drv_get_ringparam(local, tx, tx_max, rx, rx_max);
672         if (local->ops->get_ringparam)
673                 local->ops->get_ringparam(&local->hw, tx, tx_max, rx, rx_max);
674         trace_drv_return_void(local);
675 }
676
677 static inline bool drv_tx_frames_pending(struct ieee80211_local *local)
678 {
679         bool ret = false;
680
681         might_sleep();
682
683         trace_drv_tx_frames_pending(local);
684         if (local->ops->tx_frames_pending)
685                 ret = local->ops->tx_frames_pending(&local->hw);
686         trace_drv_return_bool(local, ret);
687
688         return ret;
689 }
690
691 static inline int drv_set_bitrate_mask(struct ieee80211_local *local,
692                                        struct ieee80211_sub_if_data *sdata,
693                                        const struct cfg80211_bitrate_mask *mask)
694 {
695         int ret = -EOPNOTSUPP;
696
697         might_sleep();
698
699         check_sdata_in_driver(sdata);
700
701         trace_drv_set_bitrate_mask(local, sdata, mask);
702         if (local->ops->set_bitrate_mask)
703                 ret = local->ops->set_bitrate_mask(&local->hw,
704                                                    &sdata->vif, mask);
705         trace_drv_return_int(local, ret);
706
707         return ret;
708 }
709
710 static inline void drv_set_rekey_data(struct ieee80211_local *local,
711                                       struct ieee80211_sub_if_data *sdata,
712                                       struct cfg80211_gtk_rekey_data *data)
713 {
714         check_sdata_in_driver(sdata);
715
716         trace_drv_set_rekey_data(local, sdata, data);
717         if (local->ops->set_rekey_data)
718                 local->ops->set_rekey_data(&local->hw, &sdata->vif, data);
719         trace_drv_return_void(local);
720 }
721
722 static inline void drv_rssi_callback(struct ieee80211_local *local,
723                                      const enum ieee80211_rssi_event event)
724 {
725         trace_drv_rssi_callback(local, event);
726         if (local->ops->rssi_callback)
727                 local->ops->rssi_callback(&local->hw, event);
728         trace_drv_return_void(local);
729 }
730
731 static inline void
732 drv_release_buffered_frames(struct ieee80211_local *local,
733                             struct sta_info *sta, u16 tids, int num_frames,
734                             enum ieee80211_frame_release_type reason,
735                             bool more_data)
736 {
737         trace_drv_release_buffered_frames(local, &sta->sta, tids, num_frames,
738                                           reason, more_data);
739         if (local->ops->release_buffered_frames)
740                 local->ops->release_buffered_frames(&local->hw, &sta->sta, tids,
741                                                     num_frames, reason,
742                                                     more_data);
743         trace_drv_return_void(local);
744 }
745
746 static inline void
747 drv_allow_buffered_frames(struct ieee80211_local *local,
748                           struct sta_info *sta, u16 tids, int num_frames,
749                           enum ieee80211_frame_release_type reason,
750                           bool more_data)
751 {
752         trace_drv_allow_buffered_frames(local, &sta->sta, tids, num_frames,
753                                         reason, more_data);
754         if (local->ops->allow_buffered_frames)
755                 local->ops->allow_buffered_frames(&local->hw, &sta->sta,
756                                                   tids, num_frames, reason,
757                                                   more_data);
758         trace_drv_return_void(local);
759 }
760 #endif /* __MAC80211_DRIVER_OPS */