aboutsummaryrefslogtreecommitdiff
path: root/drivers/net/wireless/ath/carl9170/carl9170.h
blob: 0cea20e3e250049d58b96466bcfed59927ae158b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
/*
 * Atheros CARL9170 driver
 *
 * Driver specific definitions
 *
 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
 * Copyright 2009, 2010, Christian Lamparter <chunkeey@googlemail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; see the file COPYING.  If not, see
 * http://www.gnu.org/licenses/.
 *
 * This file incorporates work covered by the following copyright and
 * permission notice:
 *    Copyright (c) 2007-2008 Atheros Communications, Inc.
 *
 *    Permission to use, copy, modify, and/or distribute this software for any
 *    purpose with or without fee is hereby granted, provided that the above
 *    copyright notice and this permission notice appear in all copies.
 *
 *    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 *    WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 *    MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 *    ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 *    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 *    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 *    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
#ifndef __CARL9170_H
#define __CARL9170_H

#include <linux/kernel.h>
#include <linux/firmware.h>
#include <linux/completion.h>
#include <linux/spinlock.h>
#include <linux/hw_random.h>
#include <net/cfg80211.h>
#include <net/mac80211.h>
#include <linux/usb.h>
#ifdef CONFIG_CARL9170_LEDS
#include <linux/leds.h>
#endif /* CONFIG_CARL9170_LEDS */
#ifdef CONFIG_CARL9170_WPC
#include <linux/input.h>
#endif /* CONFIG_CARL9170_WPC */
#include "eeprom.h"
#include "wlan.h"
#include "hw.h"
#include "fwdesc.h"
#include "fwcmd.h"
#include "../regd.h"

#ifdef CONFIG_CARL9170_DEBUGFS
#include "debug.h"
#endif /* CONFIG_CARL9170_DEBUGFS */

#define CARL9170FW_NAME	"carl9170-1.fw"

#define PAYLOAD_MAX	(CARL9170_MAX_CMD_LEN / 4 - 1)

static const u8 ar9170_qmap[__AR9170_NUM_TXQ] = { 3, 2, 1, 0 };

enum carl9170_rf_init_mode {
	CARL9170_RFI_NONE,
	CARL9170_RFI_WARM,
	CARL9170_RFI_COLD,
};

#define CARL9170_MAX_RX_BUFFER_SIZE		8192

enum carl9170_device_state {
	CARL9170_UNKNOWN_STATE,
	CARL9170_STOPPED,
	CARL9170_IDLE,
	CARL9170_STARTED,
};

#define CARL9170_NUM_TID		16
#define WME_BA_BMP_SIZE			64
#define CARL9170_TX_USER_RATE_TRIES	3

#define WME_AC_BE   2
#define WME_AC_BK   3
#define WME_AC_VI   1
#define WME_AC_VO   0

#define TID_TO_WME_AC(_tid)				\
	((((_tid) == 0) || ((_tid) == 3)) ? WME_AC_BE :	\
	 (((_tid) == 1) || ((_tid) == 2)) ? WME_AC_BK :	\
	 (((_tid) == 4) || ((_tid) == 5)) ? WME_AC_VI :	\
	 WME_AC_VO)

#define SEQ_DIFF(_start, _seq) \
	(((_start) - (_seq)) & 0x0fff)
#define SEQ_PREV(_seq) \
	(((_seq) - 1) & 0x0fff)
#define SEQ_NEXT(_seq) \
	(((_seq) + 1) & 0x0fff)
#define BAW_WITHIN(_start, _bawsz, _seqno) \
	((((_seqno) - (_start)) & 0xfff) < (_bawsz))

enum carl9170_tid_state {
	CARL9170_TID_STATE_INVALID,
	CARL9170_TID_STATE_KILLED,
	CARL9170_TID_STATE_SHUTDOWN,
	CARL9170_TID_STATE_SUSPEND,
	CARL9170_TID_STATE_PROGRESS,
	CARL9170_TID_STATE_IDLE,
	CARL9170_TID_STATE_XMIT,
};

#define CARL9170_BAW_BITS (2 * WME_BA_BMP_SIZE)
#define CARL9170_BAW_SIZE (BITS_TO_LONGS(CARL9170_BAW_BITS))
#define CARL9170_BAW_LEN (DIV_ROUND_UP(CARL9170_BAW_BITS, BITS_PER_BYTE))

struct carl9170_sta_tid {
	/* must be the first entry! */
	struct list_head list;

	/* temporary list for RCU unlink procedure */
	struct list_head tmp_list;

	/* lock for the following data structures */
	spinlock_t lock;

	unsigned int counter;
	enum carl9170_tid_state state;
	u8 tid;		/* TID number ( 0 - 15 ) */
	u16 max;	/* max. AMPDU size */

	u16 snx;	/* awaiting _next_ frame */
	u16 hsn;	/* highest _queued_ sequence */
	u16 bsn;	/* base of the tx/agg bitmap */
	unsigned long bitmap[CARL9170_BAW_SIZE];

	/* Preaggregation reorder queue */
	struct sk_buff_head queue;
};

#define CARL9170_QUEUE_TIMEOUT		256
#define CARL9170_BUMP_QUEUE		1000
#define CARL9170_TX_TIMEOUT		2500
#define CARL9170_JANITOR_DELAY		128
#define CARL9170_QUEUE_STUCK_TIMEOUT	5500
#define CARL9170_STAT_WORK		30000

#define CARL9170_NUM_TX_AGG_MAX		30

/*
 * Tradeoff between stability/latency and speed.
 *
 * AR9170_TXQ_DEPTH is devised by dividing the amount of available
 * tx buffers with the size of a full ethernet frame + overhead.
 *
 * Naturally: The higher the limit, the faster the device CAN send.
 * However, even a slight over-commitment at the wrong time and the
 * hardware is doomed to send all already-queued frames at suboptimal
 * rates. This in turn leads to an enormous amount of unsuccessful
 * retries => Latency goes up, whereas the throughput goes down. CRASH!
 */
#define CARL9170_NUM_TX_LIMIT_HARD	((AR9170_TXQ_DEPTH * 3) / 2)
#define CARL9170_NUM_TX_LIMIT_SOFT	(AR9170_TXQ_DEPTH)

struct carl9170_tx_queue_stats {
	unsigned int count;
	unsigned int limit;
	unsigned int len;
};

struct carl9170_vif {
	unsigned int id;
	struct ieee80211_vif __rcu *vif;
};

struct carl9170_vif_info {
	struct list_head list;
	bool active;
	unsigned int id;
	struct sk_buff *beacon;
	bool enable_beacon;
};

#define AR9170_NUM_RX_URBS	16
#define AR9170_NUM_RX_URBS_MUL	2
#define AR9170_NUM_TX_URBS	8
#define AR9170_NUM_RX_URBS_POOL (AR9170_NUM_RX_URBS_MUL * AR9170_NUM_RX_URBS)

enum carl9170_device_features {
	CARL9170_WPS_BUTTON		= BIT(0),
	CARL9170_ONE_LED		= BIT(1),
};

#ifdef CONFIG_CARL9170_LEDS
struct ar9170;

struct carl9170_led {
	struct ar9170 *ar;
	struct led_classdev l;
	char name[32];
	unsigned int toggled;
	bool last_state;
	bool registered;
};
#endif /* CONFIG_CARL9170_LEDS */

enum carl9170_restart_reasons {
	CARL9170_RR_NO_REASON = 0,
	CARL9170_RR_FATAL_FIRMWARE_ERROR,
	CARL9170_RR_TOO_MANY_FIRMWARE_ERRORS,
	CARL9170_RR_WATCHDOG,
	CARL9170_RR_STUCK_TX,
	CARL9170_RR_UNRESPONSIVE_DEVICE,
	CARL9170_RR_COMMAND_TIMEOUT,
	CARL9170_RR_TOO_MANY_PHY_ERRORS,
	CARL9170_RR_LOST_RSP,
	CARL9170_RR_INVALID_RSP,
	CARL9170_RR_USER_REQUEST,

	__CARL9170_RR_LAST,
};

enum carl9170_erp_modes {
	CARL9170_ERP_INVALID,
	CARL9170_ERP_AUTO,
	CARL9170_ERP_MAC80211,
	CARL9170_ERP_OFF,
	CARL9170_ERP_CTS,
	CARL9170_ERP_RTS,
	__CARL9170_ERP_NUM,
};

struct ar9170 {
	struct ath_common common;
	struct ieee80211_hw *hw;
	struct mutex mutex;
	enum carl9170_device_state state;
	spinlock_t state_lock;
	enum carl9170_restart_reasons last_reason;
	bool registered;

	/* USB */
	struct usb_device *udev;
	struct usb_interface *intf;
	struct usb_anchor rx_anch;
	struct usb_anchor rx_work;
	struct usb_anchor rx_pool;
	struct usb_anchor tx_wait;
	struct usb_anchor tx_anch;
	struct usb_anchor tx_cmd;
	struct usb_anchor tx_err;
	struct tasklet_struct usb_tasklet;
	atomic_t tx_cmd_urbs;
	atomic_t tx_anch_urbs;
	atomic_t rx_anch_urbs;
	atomic_t rx_work_urbs;
	atomic_t rx_pool_urbs;
	kernel_ulong_t features;

	/* firmware settings */
	struct completion fw_load_wait;
	struct completion fw_boot_wait;
	struct {
		const struct carl9170fw_desc_head *desc;
		const struct firmware *fw;
		unsigned int offset;
		unsigned int address;
		unsigned int cmd_bufs;
		unsigned int api_version;
		unsigned int vif_num;
		unsigned int err_counter;
		unsigned int bug_counter;
		u32 beacon_addr;
		unsigned int beacon_max_len;
		bool rx_stream;
		bool tx_stream;
		bool rx_filter;
		bool hw_counters;
		unsigned int mem_blocks;
		unsigned int mem_block_size;
		unsigned int rx_size;
		unsigned int tx_seq_table;
	} fw;

	/* interface configuration combinations */
	struct ieee80211_iface_limit if_comb_limits[1];
	struct ieee80211_iface_combination if_combs[1];

	/* reset / stuck frames/queue detection */
	struct work_struct restart_work;
	struct work_struct ping_work;
	unsigned int restart_counter;
	unsigned long queue_stop_timeout[__AR9170_NUM_TXQ];
	unsigned long max_queue_stop_timeout[__AR9170_NUM_TXQ];
	bool needs_full_reset;
	atomic_t pending_restarts;

	/* interface mode settings */
	struct list_head vif_list;
	unsigned long vif_bitmap;
	unsigned int vifs;
	struct carl9170_vif vif_priv[AR9170_MAX_VIRTUAL_MAC];

	/* beaconing */
	spinlock_t beacon_lock;
	unsigned int global_pretbtt;
	unsigned int global_beacon_int;
	struct carl9170_vif_info __rcu *beacon_iter;
	unsigned int beacon_enabled;

	/* cryptographic engine */
	u64 usedkeys;
	bool rx_software_decryption;
	bool disable_offload;

	/* filter settings */
	u64 cur_mc_hash;
	u32 cur_filter;
	unsigned int filter_state;
	unsigned int rx_filter_caps;
	bool sniffer_enabled;

	/* MAC */
	enum carl9170_erp_modes erp_mode;

	/* PHY */
	struct ieee80211_channel *channel;
	unsigned int num_channels;
	int noise[4];
	unsigned int chan_fail;
	unsigned int total_chan_fail;
	u8 heavy_clip;
	u8 ht_settings;
	struct {
		u64 active;	/* usec */
		u64 cca;	/* usec */
		u64 tx_time;	/* usec */
		u64 rx_total;
		u64 rx_overrun;
	} tally;
	struct delayed_work stat_work;
	struct survey_info *survey;

	/* power calibration data */
	u8 power_5G_leg[4];
	u8 power_2G_cck[4];
	u8 power_2G_ofdm[4];
	u8 power_5G_ht20[8];
	u8 power_5G_ht40[8];
	u8 power_2G_ht20[8];
	u8 power_2G_ht40[8];

#ifdef CONFIG_CARL9170_LEDS
	/* LED */
	struct delayed_work led_work;
	struct carl9170_led leds[AR9170_NUM_LEDS];
#endif /* CONFIG_CARL9170_LEDS */

	/* qos queue settings */
	spinlock_t tx_stats_lock;
	struct carl9170_tx_queue_stats tx_stats[__AR9170_NUM_TXQ];
	struct ieee80211_tx_queue_params edcf[5];
	struct completion tx_flush;

	/* CMD */
	int cmd_seq;
	int readlen;
	u8 *readbuf;
	spinlock_t cmd_lock;
	struct completion cmd_wait;
	union {
		__le32 cmd_buf[PAYLOAD_MAX + 1];
		struct carl9170_cmd cmd;
		struct carl9170_rsp rsp;
	};

	/* statistics */
	unsigned int tx_dropped;
	unsigned int tx_ack_failures;
	unsigned int tx_fcs_errors;
	unsigned int rx_dropped;

	/* EEPROM */
	struct ar9170_eeprom eeprom;

	/* tx queuing */
	struct sk_buff_head tx_pending[__AR9170_NUM_TXQ];
	struct sk_buff_head tx_status[__AR9170_NUM_TXQ];
	struct delayed_work tx_janitor;
	unsigned long tx_janitor_last_run;
	bool tx_schedule;

	/* tx ampdu */
	struct work_struct ampdu_work;
	spinlock_t tx_ampdu_list_lock;
	struct carl9170_sta_tid __rcu *tx_ampdu_iter;
	struct list_head tx_ampdu_list;
	atomic_t tx_ampdu_upload;
	atomic_t tx_ampdu_scheduler;
	atomic_t tx_total_pending;
	atomic_t tx_total_queued;
	unsigned int tx_ampdu_list_len;
	int current_density;
	int current_factor;
	bool tx_ampdu_schedule;

	/* internal memory management */
	spinlock_t mem_lock;
	unsigned long *mem_bitmap;
	atomic_t mem_free_blocks;
	atomic_t mem_allocs;

	/* rxstream mpdu merge */
	struct ar9170_rx_head rx_plcp;
	bool rx_has_plcp;
	struct sk_buff *rx_failover;
	int rx_failover_missing;

#ifdef CONFIG_CARL9170_WPC
	struct {
		bool pbc_state;
		struct input_dev *pbc;
		char name[32];
		char phys[32];
	} wps;
#endif /* CONFIG_CARL9170_WPC */

#ifdef CONFIG_CARL9170_DEBUGFS
	struct carl9170_debug debug;
	struct dentry *debug_dir;
#endif /* CONFIG_CARL9170_DEBUGFS */

	/* PSM */
	struct work_struct ps_work;
	struct {
		unsigned int dtim_counter;
		unsigned long last_beacon;
		unsigned long last_action;
		unsigned long last_slept;
		unsigned int sleep_ms;
		unsigned int off_override;
		bool state;
	} ps;

#ifdef CONFIG_CARL9170_HWRNG
# define CARL9170_HWRNG_CACHE_SIZE	CARL9170_MAX_CMD_PAYLOAD_LEN
	struct {
		struct hwrng rng;
		bool initialized;
		char name[30 + 1];
		u16 cache[CARL9170_HWRNG_CACHE_SIZE / sizeof(u16)];
		unsigned int cache_idx;
	} rng;
#endif /* CONFIG_CARL9170_HWRNG */
};

enum carl9170_ps_off_override_reasons {
	PS_OFF_VIF	= BIT(0),
	PS_OFF_BCN	= BIT(1),
};

struct carl9170_ba_stats {
	u8 ampdu_len;
	u8 ampdu_ack_len;
	bool clear;
	bool req;
};

struct carl9170_sta_info {
	bool ht_sta;
	bool sleeping;
	atomic_t pending_frames;
	unsigned int ampdu_max_len;
	struct carl9170_sta_tid __rcu *agg[CARL9170_NUM_TID];
	struct carl9170_ba_stats stats[CARL9170_NUM_TID];
};

struct carl9170_tx_info {
	unsigned long timeout;
	struct ar9170 *ar;
	struct kref ref;
};

#define CHK_DEV_STATE(a, s)	(((struct ar9170 *)a)->state >= (s))
#define IS_INITIALIZED(a)	(CHK_DEV_STATE(a, CARL9170_STOPPED))
#define IS_ACCEPTING_CMD(a)	(CHK_DEV_STATE(a, CARL9170_IDLE))
#define IS_STARTED(a)		(CHK_DEV_STATE(a, CARL9170_STARTED))

static inline void __carl9170_set_state(struct ar9170 *ar,
	enum carl9170_device_state newstate)
{
	ar->state = newstate;
}

static inline void carl9170_set_state(struct ar9170 *ar,
	enum carl9170_device_state newstate)
{
	unsigned long flags;

	spin_lock_irqsave(&ar->state_lock, flags);
	__carl9170_set_state(ar, newstate);
	spin_unlock_irqrestore(&ar->state_lock, flags);
}

static inline void carl9170_set_state_when(struct ar9170 *ar,
	enum carl9170_device_state min, enum carl9170_device_state newstate)
{
	unsigned long flags;

	spin_lock_irqsave(&ar->state_lock, flags);
	if (CHK_DEV_STATE(ar, min))
		__carl9170_set_state(ar, newstate);
	spin_unlock_irqrestore(&ar->state_lock, flags);
}

/* exported interface */
void *carl9170_alloc(size_t priv_size);
int carl9170_register(struct ar9170 *ar);
void carl9170_unregister(struct ar9170 *ar);
void carl9170_free(struct ar9170 *ar);
void carl9170_restart(struct ar9170 *ar, const enum carl9170_restart_reasons r);
void carl9170_ps_check(struct ar9170 *ar);

/* USB back-end */
int carl9170_usb_open(struct ar9170 *ar);
void carl9170_usb_stop(struct ar9170 *ar);
void carl9170_usb_tx(struct ar9170 *ar, struct sk_buff *skb);
void carl9170_usb_handle_tx_err(struct ar9170 *ar);
int carl9170_exec_cmd(struct ar9170 *ar, const enum carl9170_cmd_oids,
		      u32 plen, void *payload, u32 rlen, void *resp);
int __carl9170_exec_cmd(struct ar9170 *ar, struct carl9170_cmd *cmd,
			const bool free_buf);
int carl9170_usb_restart(struct ar9170 *ar);
void carl9170_usb_reset(struct ar9170 *ar);

/* MAC */
int carl9170_init_mac(struct ar9170 *ar);
int carl9170_set_qos(struct ar9170 *ar);
int carl9170_update_multicast(struct ar9170 *ar, const u64 mc_hast);
int carl9170_mod_virtual_mac(struct ar9170 *ar, const unsigned int id,
			     const u8 *mac);
int carl9170_set_operating_mode(struct ar9170 *ar);
int carl9170_set_beacon_timers(struct ar9170 *ar);
int carl9170_set_dyn_sifs_ack(struct ar9170 *ar);
int carl9170_set_rts_cts_rate(struct ar9170 *ar);
int carl9170_set_ampdu_settings(struct ar9170 *ar);
int carl9170_set_slot_time(struct ar9170 *ar);
int carl9170_set_mac_rates(struct ar9170 *ar);
int carl9170_set_hwretry_limit(struct ar9170 *ar, const u32 max_retry);
int carl9170_upload_key(struct ar9170 *ar, const u8 id, const u8 *mac,
	const u8 ktype, const u8 keyidx, const u8 *keydata, const int keylen);
int carl9170_disable_key(struct ar9170 *ar, const u8 id);
int carl9170_set_mac_tpc(struct ar9170 *ar, struct ieee80211_channel *channel);

/* RX */
void carl9170_rx(struct ar9170 *ar, void *buf, unsigned int len);
void carl9170_handle_command_response(struct ar9170 *ar, void *buf, u32 len);

/* TX */
void carl9170_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
void carl9170_tx_janitor(struct work_struct *work);
void carl9170_tx_process_status(struct ar9170 *ar,
				const struct carl9170_rsp *cmd);
void carl9170_tx_status(struct ar9170 *ar, struct sk_buff *skb,
			const bool success);
void carl9170_tx_callback(struct ar9170 *ar, struct sk_buff *skb);
void carl9170_tx_drop(struct ar9170 *ar, struct sk_buff *skb);
void carl9170_tx_scheduler(struct ar9170 *ar);
void carl9170_tx_get_skb(struct sk_buff *skb);
int carl9170_tx_put_skb(struct sk_buff *skb);
int carl9170_update_beacon(struct ar9170 *ar, const bool submit);

/* LEDs */
#ifdef CONFIG_CARL9170_LEDS
int carl9170_led_register(struct ar9170 *ar);
void carl9170_led_unregister(struct ar9170 *ar);
#endif /* CONFIG_CARL9170_LEDS */
int carl9170_led_init(struct ar9170 *ar);
int carl9170_led_set_state(struct ar9170 *ar, const u32 led_state);

/* PHY / RF */
int carl9170_set_channel(struct ar9170 *ar, struct ieee80211_channel *channel,
	enum nl80211_channel_type bw, enum carl9170_rf_init_mode rfi);
int carl9170_get_noisefloor(struct ar9170 *ar);

/* FW */
int carl9170_parse_firmware(struct ar9170 *ar);

extern struct ieee80211_rate __carl9170_ratetable[];
extern int modparam_noht;

static inline struct ar9170 *carl9170_get_priv(struct carl9170_vif *carl_vif)
{
	return container_of(carl_vif, struct ar9170,
			    vif_priv[carl_vif->id]);
}

static inline struct ieee80211_hdr *carl9170_get_hdr(struct sk_buff *skb)
{
	return (void *)((struct _carl9170_tx_superframe *)
		skb->data)->frame_data;
}

static inline u16 get_seq_h(struct ieee80211_hdr *hdr)
{
	return le16_to_cpu(hdr->seq_ctrl) >> 4;
}

static inline u16 carl9170_get_seq(struct sk_buff *skb)
{
	return get_seq_h(carl9170_get_hdr(skb));
}

static inline u16 get_tid_h(struct ieee80211_hdr *hdr)
{
	return (ieee80211_get_qos_ctl(hdr))[0] & IEEE80211_QOS_CTL_TID_MASK;
}

static inline u16 carl9170_get_tid(struct sk_buff *skb)
{
	return get_tid_h(carl9170_get_hdr(skb));
}

static inline struct ieee80211_vif *
carl9170_get_vif(struct carl9170_vif_info *priv)
{
	return container_of((void *)priv, struct ieee80211_vif, drv_priv);
}

/* Protected by ar->mutex or RCU */
static inline struct ieee80211_vif *carl9170_get_main_vif(struct ar9170 *ar)
{
	struct carl9170_vif_info *cvif;

	list_for_each_entry_rcu(cvif, &ar->vif_list, list) {
		if (cvif->active)
			return carl9170_get_vif(cvif);
	}

	return NULL;
}

static inline bool is_main_vif(struct ar9170 *ar, struct ieee80211_vif *vif)
{
	bool ret;

	rcu_read_lock();
	ret = (carl9170_get_main_vif(ar) == vif);
	rcu_read_unlock();
	return ret;
}

#endif /* __CARL9170_H */