blob: f7dbdaa74c63187d6290a352efbe8d24caf965f4 [file] [log] [blame]
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +02001/*
2 * Atheros CARL9170 driver
3 *
4 * Driver specific definitions
5 *
6 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
7 * Copyright 2009, 2010, Christian Lamparter <chunkeey@googlemail.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; see the file COPYING. If not, see
21 * http://www.gnu.org/licenses/.
22 *
23 * This file incorporates work covered by the following copyright and
24 * permission notice:
25 * Copyright (c) 2007-2008 Atheros Communications, Inc.
26 *
27 * Permission to use, copy, modify, and/or distribute this software for any
28 * purpose with or without fee is hereby granted, provided that the above
29 * copyright notice and this permission notice appear in all copies.
30 *
31 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
32 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
33 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
34 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
35 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
36 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
37 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
38 */
39#ifndef __CARL9170_H
40#define __CARL9170_H
41
42#include <linux/kernel.h>
43#include <linux/firmware.h>
44#include <linux/completion.h>
45#include <linux/spinlock.h>
46#include <net/cfg80211.h>
47#include <net/mac80211.h>
48#include <linux/usb.h>
49#ifdef CONFIG_CARL9170_LEDS
50#include <linux/leds.h>
Hauke Mehrtens8e7ce892010-10-23 19:51:32 +020051#endif /* CONFIG_CARL9170_LEDS */
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +020052#ifdef CONFIG_CARL9170_WPC
53#include <linux/input.h>
54#endif /* CONFIG_CARL9170_WPC */
55#include "eeprom.h"
56#include "wlan.h"
57#include "hw.h"
58#include "fwdesc.h"
59#include "fwcmd.h"
60#include "../regd.h"
61
62#ifdef CONFIG_CARL9170_DEBUGFS
63#include "debug.h"
64#endif /* CONFIG_CARL9170_DEBUGFS */
65
66#define CARL9170FW_NAME "carl9170-1.fw"
67
68#define PAYLOAD_MAX (CARL9170_MAX_CMD_LEN / 4 - 1)
69
Christian Lamparter85ee5122011-06-30 20:27:47 +020070static const u8 ar9170_qmap[__AR9170_NUM_TXQ] = { 3, 2, 1, 0 };
71
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +020072enum carl9170_rf_init_mode {
73 CARL9170_RFI_NONE,
74 CARL9170_RFI_WARM,
75 CARL9170_RFI_COLD,
76};
77
78#define CARL9170_MAX_RX_BUFFER_SIZE 8192
79
80enum carl9170_device_state {
81 CARL9170_UNKNOWN_STATE,
82 CARL9170_STOPPED,
83 CARL9170_IDLE,
84 CARL9170_STARTED,
85};
86
87#define CARL9170_NUM_TID 16
88#define WME_BA_BMP_SIZE 64
89#define CARL9170_TX_USER_RATE_TRIES 3
90
91#define WME_AC_BE 2
92#define WME_AC_BK 3
93#define WME_AC_VI 1
94#define WME_AC_VO 0
95
96#define TID_TO_WME_AC(_tid) \
97 ((((_tid) == 0) || ((_tid) == 3)) ? WME_AC_BE : \
98 (((_tid) == 1) || ((_tid) == 2)) ? WME_AC_BK : \
99 (((_tid) == 4) || ((_tid) == 5)) ? WME_AC_VI : \
100 WME_AC_VO)
101
102#define SEQ_DIFF(_start, _seq) \
103 (((_start) - (_seq)) & 0x0fff)
104#define SEQ_PREV(_seq) \
105 (((_seq) - 1) & 0x0fff)
106#define SEQ_NEXT(_seq) \
107 (((_seq) + 1) & 0x0fff)
108#define BAW_WITHIN(_start, _bawsz, _seqno) \
109 ((((_seqno) - (_start)) & 0xfff) < (_bawsz))
110
111enum carl9170_tid_state {
112 CARL9170_TID_STATE_INVALID,
113 CARL9170_TID_STATE_KILLED,
114 CARL9170_TID_STATE_SHUTDOWN,
115 CARL9170_TID_STATE_SUSPEND,
116 CARL9170_TID_STATE_PROGRESS,
117 CARL9170_TID_STATE_IDLE,
118 CARL9170_TID_STATE_XMIT,
119};
120
121#define CARL9170_BAW_BITS (2 * WME_BA_BMP_SIZE)
122#define CARL9170_BAW_SIZE (BITS_TO_LONGS(CARL9170_BAW_BITS))
123#define CARL9170_BAW_LEN (DIV_ROUND_UP(CARL9170_BAW_BITS, BITS_PER_BYTE))
124
125struct carl9170_sta_tid {
126 /* must be the first entry! */
127 struct list_head list;
128
129 /* temporary list for RCU unlink procedure */
130 struct list_head tmp_list;
131
132 /* lock for the following data structures */
133 spinlock_t lock;
134
135 unsigned int counter;
136 enum carl9170_tid_state state;
137 u8 tid; /* TID number ( 0 - 15 ) */
138 u16 max; /* max. AMPDU size */
139
140 u16 snx; /* awaiting _next_ frame */
141 u16 hsn; /* highest _queued_ sequence */
142 u16 bsn; /* base of the tx/agg bitmap */
143 unsigned long bitmap[CARL9170_BAW_SIZE];
144
145 /* Preaggregation reorder queue */
146 struct sk_buff_head queue;
147};
148
149#define CARL9170_QUEUE_TIMEOUT 256
150#define CARL9170_BUMP_QUEUE 1000
151#define CARL9170_TX_TIMEOUT 2500
152#define CARL9170_JANITOR_DELAY 128
153#define CARL9170_QUEUE_STUCK_TIMEOUT 5500
154
155#define CARL9170_NUM_TX_AGG_MAX 30
156
157/*
158 * Tradeoff between stability/latency and speed.
159 *
160 * AR9170_TXQ_DEPTH is devised by dividing the amount of available
161 * tx buffers with the size of a full ethernet frame + overhead.
162 *
163 * Naturally: The higher the limit, the faster the device CAN send.
164 * However, even a slight over-commitment at the wrong time and the
165 * hardware is doomed to send all already-queued frames at suboptimal
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300166 * rates. This in turn leads to an enormous amount of unsuccessful
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200167 * retries => Latency goes up, whereas the throughput goes down. CRASH!
168 */
169#define CARL9170_NUM_TX_LIMIT_HARD ((AR9170_TXQ_DEPTH * 3) / 2)
170#define CARL9170_NUM_TX_LIMIT_SOFT (AR9170_TXQ_DEPTH)
171
172struct carl9170_tx_queue_stats {
173 unsigned int count;
174 unsigned int limit;
175 unsigned int len;
176};
177
178struct carl9170_vif {
179 unsigned int id;
Pavel Roskin70126f62011-07-19 18:02:15 -0400180 struct ieee80211_vif __rcu *vif;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200181};
182
183struct carl9170_vif_info {
184 struct list_head list;
185 bool active;
186 unsigned int id;
187 struct sk_buff *beacon;
188 bool enable_beacon;
189};
190
191#define AR9170_NUM_RX_URBS 16
192#define AR9170_NUM_RX_URBS_MUL 2
193#define AR9170_NUM_TX_URBS 8
194#define AR9170_NUM_RX_URBS_POOL (AR9170_NUM_RX_URBS_MUL * AR9170_NUM_RX_URBS)
195
196enum carl9170_device_features {
197 CARL9170_WPS_BUTTON = BIT(0),
198 CARL9170_ONE_LED = BIT(1),
199};
200
201#ifdef CONFIG_CARL9170_LEDS
202struct ar9170;
203
204struct carl9170_led {
205 struct ar9170 *ar;
206 struct led_classdev l;
207 char name[32];
208 unsigned int toggled;
209 bool last_state;
210 bool registered;
211};
212#endif /* CONFIG_CARL9170_LEDS */
213
214enum carl9170_restart_reasons {
215 CARL9170_RR_NO_REASON = 0,
216 CARL9170_RR_FATAL_FIRMWARE_ERROR,
217 CARL9170_RR_TOO_MANY_FIRMWARE_ERRORS,
218 CARL9170_RR_WATCHDOG,
219 CARL9170_RR_STUCK_TX,
Christian Lampartere4a668c2010-10-29 23:26:13 +0200220 CARL9170_RR_UNRESPONSIVE_DEVICE,
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200221 CARL9170_RR_COMMAND_TIMEOUT,
222 CARL9170_RR_TOO_MANY_PHY_ERRORS,
223 CARL9170_RR_LOST_RSP,
224 CARL9170_RR_INVALID_RSP,
225 CARL9170_RR_USER_REQUEST,
226
227 __CARL9170_RR_LAST,
228};
229
230enum carl9170_erp_modes {
231 CARL9170_ERP_INVALID,
232 CARL9170_ERP_AUTO,
233 CARL9170_ERP_MAC80211,
234 CARL9170_ERP_OFF,
235 CARL9170_ERP_CTS,
236 CARL9170_ERP_RTS,
237 __CARL9170_ERP_NUM,
238};
239
240struct ar9170 {
241 struct ath_common common;
242 struct ieee80211_hw *hw;
243 struct mutex mutex;
244 enum carl9170_device_state state;
245 spinlock_t state_lock;
246 enum carl9170_restart_reasons last_reason;
247 bool registered;
248
249 /* USB */
250 struct usb_device *udev;
251 struct usb_interface *intf;
252 struct usb_anchor rx_anch;
253 struct usb_anchor rx_work;
254 struct usb_anchor rx_pool;
255 struct usb_anchor tx_wait;
256 struct usb_anchor tx_anch;
257 struct usb_anchor tx_cmd;
258 struct usb_anchor tx_err;
259 struct tasklet_struct usb_tasklet;
260 atomic_t tx_cmd_urbs;
261 atomic_t tx_anch_urbs;
262 atomic_t rx_anch_urbs;
263 atomic_t rx_work_urbs;
264 atomic_t rx_pool_urbs;
265 kernel_ulong_t features;
266
267 /* firmware settings */
268 struct completion fw_load_wait;
269 struct completion fw_boot_wait;
270 struct {
271 const struct carl9170fw_desc_head *desc;
272 const struct firmware *fw;
273 unsigned int offset;
274 unsigned int address;
275 unsigned int cmd_bufs;
276 unsigned int api_version;
277 unsigned int vif_num;
278 unsigned int err_counter;
279 unsigned int bug_counter;
280 u32 beacon_addr;
281 unsigned int beacon_max_len;
282 bool rx_stream;
283 bool tx_stream;
Christian Lamparter5c895692010-09-28 23:00:59 +0200284 bool rx_filter;
Christian Lamparter7ccc83b2011-08-15 18:45:54 +0200285 bool hw_counters;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200286 unsigned int mem_blocks;
287 unsigned int mem_block_size;
288 unsigned int rx_size;
Christian Lamparteraa324522011-01-23 00:18:28 +0100289 unsigned int tx_seq_table;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200290 } fw;
291
Christian Lamparterdf649622011-05-14 02:42:38 +0200292 /* interface configuration combinations */
293 struct ieee80211_iface_limit if_comb_limits[1];
294 struct ieee80211_iface_combination if_combs[1];
295
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200296 /* reset / stuck frames/queue detection */
297 struct work_struct restart_work;
Christian Lampartere4a668c2010-10-29 23:26:13 +0200298 struct work_struct ping_work;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200299 unsigned int restart_counter;
300 unsigned long queue_stop_timeout[__AR9170_NUM_TXQ];
301 unsigned long max_queue_stop_timeout[__AR9170_NUM_TXQ];
302 bool needs_full_reset;
303 atomic_t pending_restarts;
304
305 /* interface mode settings */
306 struct list_head vif_list;
307 unsigned long vif_bitmap;
308 unsigned int vifs;
309 struct carl9170_vif vif_priv[AR9170_MAX_VIRTUAL_MAC];
310
311 /* beaconing */
312 spinlock_t beacon_lock;
313 unsigned int global_pretbtt;
314 unsigned int global_beacon_int;
Pavel Roskin70126f62011-07-19 18:02:15 -0400315 struct carl9170_vif_info __rcu *beacon_iter;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200316 unsigned int beacon_enabled;
317
318 /* cryptographic engine */
319 u64 usedkeys;
320 bool rx_software_decryption;
321 bool disable_offload;
322
323 /* filter settings */
324 u64 cur_mc_hash;
325 u32 cur_filter;
326 unsigned int filter_state;
Christian Lamparter5c895692010-09-28 23:00:59 +0200327 unsigned int rx_filter_caps;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200328 bool sniffer_enabled;
329
330 /* MAC */
331 enum carl9170_erp_modes erp_mode;
332
333 /* PHY */
334 struct ieee80211_channel *channel;
Christian Lamparter9adc9e02010-09-17 22:42:37 +0200335 int noise[4];
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200336 unsigned int chan_fail;
337 unsigned int total_chan_fail;
338 u8 heavy_clip;
Christian Lamparter73576112010-09-17 23:09:19 +0200339 u8 ht_settings;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200340
341 /* power calibration data */
342 u8 power_5G_leg[4];
343 u8 power_2G_cck[4];
344 u8 power_2G_ofdm[4];
345 u8 power_5G_ht20[8];
346 u8 power_5G_ht40[8];
347 u8 power_2G_ht20[8];
348 u8 power_2G_ht40[8];
349
350#ifdef CONFIG_CARL9170_LEDS
351 /* LED */
352 struct delayed_work led_work;
353 struct carl9170_led leds[AR9170_NUM_LEDS];
354#endif /* CONFIG_CARL9170_LEDS */
355
356 /* qos queue settings */
357 spinlock_t tx_stats_lock;
358 struct carl9170_tx_queue_stats tx_stats[__AR9170_NUM_TXQ];
359 struct ieee80211_tx_queue_params edcf[5];
360 struct completion tx_flush;
361
362 /* CMD */
363 int cmd_seq;
364 int readlen;
365 u8 *readbuf;
366 spinlock_t cmd_lock;
367 struct completion cmd_wait;
368 union {
369 __le32 cmd_buf[PAYLOAD_MAX + 1];
370 struct carl9170_cmd cmd;
371 struct carl9170_rsp rsp;
372 };
373
374 /* statistics */
375 unsigned int tx_dropped;
376 unsigned int tx_ack_failures;
377 unsigned int tx_fcs_errors;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200378 unsigned int rx_dropped;
379
380 /* EEPROM */
381 struct ar9170_eeprom eeprom;
382
383 /* tx queuing */
384 struct sk_buff_head tx_pending[__AR9170_NUM_TXQ];
385 struct sk_buff_head tx_status[__AR9170_NUM_TXQ];
386 struct delayed_work tx_janitor;
387 unsigned long tx_janitor_last_run;
388 bool tx_schedule;
389
390 /* tx ampdu */
391 struct work_struct ampdu_work;
392 spinlock_t tx_ampdu_list_lock;
Pavel Roskin70126f62011-07-19 18:02:15 -0400393 struct carl9170_sta_tid __rcu *tx_ampdu_iter;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200394 struct list_head tx_ampdu_list;
395 atomic_t tx_ampdu_upload;
396 atomic_t tx_ampdu_scheduler;
397 atomic_t tx_total_pending;
398 atomic_t tx_total_queued;
399 unsigned int tx_ampdu_list_len;
400 int current_density;
401 int current_factor;
402 bool tx_ampdu_schedule;
403
404 /* internal memory management */
405 spinlock_t mem_lock;
406 unsigned long *mem_bitmap;
407 atomic_t mem_free_blocks;
408 atomic_t mem_allocs;
409
410 /* rxstream mpdu merge */
411 struct ar9170_rx_head rx_plcp;
412 bool rx_has_plcp;
413 struct sk_buff *rx_failover;
414 int rx_failover_missing;
415
416#ifdef CONFIG_CARL9170_WPC
417 struct {
418 bool pbc_state;
419 struct input_dev *pbc;
420 char name[32];
421 char phys[32];
422 } wps;
423#endif /* CONFIG_CARL9170_WPC */
424
425#ifdef CONFIG_CARL9170_DEBUGFS
426 struct carl9170_debug debug;
427 struct dentry *debug_dir;
428#endif /* CONFIG_CARL9170_DEBUGFS */
429
430 /* PSM */
431 struct work_struct ps_work;
432 struct {
433 unsigned int dtim_counter;
434 unsigned long last_beacon;
435 unsigned long last_action;
436 unsigned long last_slept;
437 unsigned int sleep_ms;
438 unsigned int off_override;
439 bool state;
440 } ps;
441};
442
443enum carl9170_ps_off_override_reasons {
444 PS_OFF_VIF = BIT(0),
445 PS_OFF_BCN = BIT(1),
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200446};
447
448struct carl9170_ba_stats {
449 u8 ampdu_len;
450 u8 ampdu_ack_len;
451 bool clear;
Christian Lamparter24047e22011-03-29 13:43:14 +0200452 bool req;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200453};
454
455struct carl9170_sta_info {
456 bool ht_sta;
Christian Lampartercaf1eae2011-04-24 17:44:19 +0200457 bool sleeping;
458 atomic_t pending_frames;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200459 unsigned int ampdu_max_len;
Pavel Roskin70126f62011-07-19 18:02:15 -0400460 struct carl9170_sta_tid __rcu *agg[CARL9170_NUM_TID];
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200461 struct carl9170_ba_stats stats[CARL9170_NUM_TID];
462};
463
464struct carl9170_tx_info {
465 unsigned long timeout;
466 struct ar9170 *ar;
467 struct kref ref;
468};
469
470#define CHK_DEV_STATE(a, s) (((struct ar9170 *)a)->state >= (s))
471#define IS_INITIALIZED(a) (CHK_DEV_STATE(a, CARL9170_STOPPED))
472#define IS_ACCEPTING_CMD(a) (CHK_DEV_STATE(a, CARL9170_IDLE))
473#define IS_STARTED(a) (CHK_DEV_STATE(a, CARL9170_STARTED))
474
475static inline void __carl9170_set_state(struct ar9170 *ar,
476 enum carl9170_device_state newstate)
477{
478 ar->state = newstate;
479}
480
481static inline void carl9170_set_state(struct ar9170 *ar,
482 enum carl9170_device_state newstate)
483{
484 unsigned long flags;
485
486 spin_lock_irqsave(&ar->state_lock, flags);
487 __carl9170_set_state(ar, newstate);
488 spin_unlock_irqrestore(&ar->state_lock, flags);
489}
490
491static inline void carl9170_set_state_when(struct ar9170 *ar,
492 enum carl9170_device_state min, enum carl9170_device_state newstate)
493{
494 unsigned long flags;
495
496 spin_lock_irqsave(&ar->state_lock, flags);
497 if (CHK_DEV_STATE(ar, min))
498 __carl9170_set_state(ar, newstate);
499 spin_unlock_irqrestore(&ar->state_lock, flags);
500}
501
502/* exported interface */
503void *carl9170_alloc(size_t priv_size);
504int carl9170_register(struct ar9170 *ar);
505void carl9170_unregister(struct ar9170 *ar);
506void carl9170_free(struct ar9170 *ar);
507void carl9170_restart(struct ar9170 *ar, const enum carl9170_restart_reasons r);
508void carl9170_ps_check(struct ar9170 *ar);
509
510/* USB back-end */
511int carl9170_usb_open(struct ar9170 *ar);
512void carl9170_usb_stop(struct ar9170 *ar);
513void carl9170_usb_tx(struct ar9170 *ar, struct sk_buff *skb);
514void carl9170_usb_handle_tx_err(struct ar9170 *ar);
515int carl9170_exec_cmd(struct ar9170 *ar, const enum carl9170_cmd_oids,
516 u32 plen, void *payload, u32 rlen, void *resp);
517int __carl9170_exec_cmd(struct ar9170 *ar, struct carl9170_cmd *cmd,
518 const bool free_buf);
519int carl9170_usb_restart(struct ar9170 *ar);
520void carl9170_usb_reset(struct ar9170 *ar);
521
522/* MAC */
523int carl9170_init_mac(struct ar9170 *ar);
524int carl9170_set_qos(struct ar9170 *ar);
525int carl9170_update_multicast(struct ar9170 *ar, const u64 mc_hast);
526int carl9170_mod_virtual_mac(struct ar9170 *ar, const unsigned int id,
527 const u8 *mac);
528int carl9170_set_operating_mode(struct ar9170 *ar);
529int carl9170_set_beacon_timers(struct ar9170 *ar);
530int carl9170_set_dyn_sifs_ack(struct ar9170 *ar);
531int carl9170_set_rts_cts_rate(struct ar9170 *ar);
532int carl9170_set_ampdu_settings(struct ar9170 *ar);
533int carl9170_set_slot_time(struct ar9170 *ar);
534int carl9170_set_mac_rates(struct ar9170 *ar);
535int carl9170_set_hwretry_limit(struct ar9170 *ar, const u32 max_retry);
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200536int carl9170_upload_key(struct ar9170 *ar, const u8 id, const u8 *mac,
537 const u8 ktype, const u8 keyidx, const u8 *keydata, const int keylen);
538int carl9170_disable_key(struct ar9170 *ar, const u8 id);
539
540/* RX */
541void carl9170_rx(struct ar9170 *ar, void *buf, unsigned int len);
542void carl9170_handle_command_response(struct ar9170 *ar, void *buf, u32 len);
543
544/* TX */
Johannes Berg7bb45682011-02-24 14:42:06 +0100545void carl9170_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200546void carl9170_tx_janitor(struct work_struct *work);
547void carl9170_tx_process_status(struct ar9170 *ar,
548 const struct carl9170_rsp *cmd);
549void carl9170_tx_status(struct ar9170 *ar, struct sk_buff *skb,
550 const bool success);
551void carl9170_tx_callback(struct ar9170 *ar, struct sk_buff *skb);
552void carl9170_tx_drop(struct ar9170 *ar, struct sk_buff *skb);
553void carl9170_tx_scheduler(struct ar9170 *ar);
554void carl9170_tx_get_skb(struct sk_buff *skb);
555int carl9170_tx_put_skb(struct sk_buff *skb);
Christian Lamparter943c3392011-07-16 17:25:14 +0200556int carl9170_update_beacon(struct ar9170 *ar, const bool submit);
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200557
558/* LEDs */
559#ifdef CONFIG_CARL9170_LEDS
560int carl9170_led_register(struct ar9170 *ar);
561void carl9170_led_unregister(struct ar9170 *ar);
562#endif /* CONFIG_CARL9170_LEDS */
563int carl9170_led_init(struct ar9170 *ar);
564int carl9170_led_set_state(struct ar9170 *ar, const u32 led_state);
565
566/* PHY / RF */
567int carl9170_set_channel(struct ar9170 *ar, struct ieee80211_channel *channel,
568 enum nl80211_channel_type bw, enum carl9170_rf_init_mode rfi);
569int carl9170_get_noisefloor(struct ar9170 *ar);
570
571/* FW */
572int carl9170_parse_firmware(struct ar9170 *ar);
573int carl9170_fw_fix_eeprom(struct ar9170 *ar);
574
575extern struct ieee80211_rate __carl9170_ratetable[];
576extern int modparam_noht;
577
578static inline struct ar9170 *carl9170_get_priv(struct carl9170_vif *carl_vif)
579{
580 return container_of(carl_vif, struct ar9170,
581 vif_priv[carl_vif->id]);
582}
583
584static inline struct ieee80211_hdr *carl9170_get_hdr(struct sk_buff *skb)
585{
586 return (void *)((struct _carl9170_tx_superframe *)
587 skb->data)->frame_data;
588}
589
590static inline u16 get_seq_h(struct ieee80211_hdr *hdr)
591{
592 return le16_to_cpu(hdr->seq_ctrl) >> 4;
593}
594
595static inline u16 carl9170_get_seq(struct sk_buff *skb)
596{
597 return get_seq_h(carl9170_get_hdr(skb));
598}
599
600static inline u16 get_tid_h(struct ieee80211_hdr *hdr)
601{
602 return (ieee80211_get_qos_ctl(hdr))[0] & IEEE80211_QOS_CTL_TID_MASK;
603}
604
605static inline u16 carl9170_get_tid(struct sk_buff *skb)
606{
607 return get_tid_h(carl9170_get_hdr(skb));
608}
609
610static inline struct ieee80211_vif *
611carl9170_get_vif(struct carl9170_vif_info *priv)
612{
613 return container_of((void *)priv, struct ieee80211_vif, drv_priv);
614}
615
616/* Protected by ar->mutex or RCU */
617static inline struct ieee80211_vif *carl9170_get_main_vif(struct ar9170 *ar)
618{
619 struct carl9170_vif_info *cvif;
620
621 list_for_each_entry_rcu(cvif, &ar->vif_list, list) {
622 if (cvif->active)
623 return carl9170_get_vif(cvif);
624 }
625
626 return NULL;
627}
628
629static inline bool is_main_vif(struct ar9170 *ar, struct ieee80211_vif *vif)
630{
631 bool ret;
632
633 rcu_read_lock();
634 ret = (carl9170_get_main_vif(ar) == vif);
635 rcu_read_unlock();
636 return ret;
637}
638
639#endif /* __CARL9170_H */