1 /*
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 <linux/hw_random.h>
47 #include <net/cfg80211.h>
48 #include <net/mac80211.h>
49 #include <linux/usb.h>
50 #ifdef CONFIG_CARL9170_LEDS
51 #include <linux/leds.h>
52 #endif /* CONFIG_CARL9170_LEDS */
53 #ifdef CONFIG_CARL9170_WPC
54 #include <linux/input.h>
55 #endif /* CONFIG_CARL9170_WPC */
56 #include "eeprom.h"
57 #include "wlan.h"
58 #include "hw.h"
59 #include "fwdesc.h"
60 #include "fwcmd.h"
61 #include "../regd.h"
62 
63 #ifdef CONFIG_CARL9170_DEBUGFS
64 #include "debug.h"
65 #endif /* CONFIG_CARL9170_DEBUGFS */
66 
67 #define CARL9170FW_NAME	"carl9170-1.fw"
68 
69 #define PAYLOAD_MAX	(CARL9170_MAX_CMD_LEN / 4 - 1)
70 
71 static const u8 ar9170_qmap[__AR9170_NUM_TXQ] = { 3, 2, 1, 0 };
72 
73 #define CARL9170_MAX_RX_BUFFER_SIZE		8192
74 
75 enum carl9170_device_state {
76 	CARL9170_UNKNOWN_STATE,
77 	CARL9170_STOPPED,
78 	CARL9170_IDLE,
79 	CARL9170_STARTED,
80 };
81 
82 #define WME_BA_BMP_SIZE			64
83 #define CARL9170_TX_USER_RATE_TRIES	3
84 
85 #define TID_TO_WME_AC(_tid)				\
86 	((((_tid) == 0) || ((_tid) == 3)) ? IEEE80211_AC_BE :	\
87 	 (((_tid) == 1) || ((_tid) == 2)) ? IEEE80211_AC_BK :	\
88 	 (((_tid) == 4) || ((_tid) == 5)) ? IEEE80211_AC_VI :	\
89 	 IEEE80211_AC_VO)
90 
91 #define SEQ_DIFF(_start, _seq) \
92 	(((_start) - (_seq)) & 0x0fff)
93 #define SEQ_PREV(_seq) \
94 	(((_seq) - 1) & 0x0fff)
95 #define SEQ_NEXT(_seq) \
96 	(((_seq) + 1) & 0x0fff)
97 #define BAW_WITHIN(_start, _bawsz, _seqno) \
98 	((((_seqno) - (_start)) & 0xfff) < (_bawsz))
99 
100 enum carl9170_tid_state {
101 	CARL9170_TID_STATE_INVALID,
102 	CARL9170_TID_STATE_KILLED,
103 	CARL9170_TID_STATE_SHUTDOWN,
104 	CARL9170_TID_STATE_SUSPEND,
105 	CARL9170_TID_STATE_PROGRESS,
106 	CARL9170_TID_STATE_IDLE,
107 	CARL9170_TID_STATE_XMIT,
108 };
109 
110 #define CARL9170_BAW_BITS (2 * WME_BA_BMP_SIZE)
111 #define CARL9170_BAW_SIZE (BITS_TO_LONGS(CARL9170_BAW_BITS))
112 #define CARL9170_BAW_LEN (DIV_ROUND_UP(CARL9170_BAW_BITS, BITS_PER_BYTE))
113 
114 struct carl9170_sta_tid {
115 	/* must be the first entry! */
116 	struct list_head list;
117 
118 	/* temporary list for RCU unlink procedure */
119 	struct list_head tmp_list;
120 
121 	/* lock for the following data structures */
122 	spinlock_t lock;
123 
124 	unsigned int counter;
125 	enum carl9170_tid_state state;
126 	u8 tid;		/* TID number ( 0 - 15 ) */
127 	u16 max;	/* max. AMPDU size */
128 
129 	u16 snx;	/* awaiting _next_ frame */
130 	u16 hsn;	/* highest _queued_ sequence */
131 	u16 bsn;	/* base of the tx/agg bitmap */
132 	unsigned long bitmap[CARL9170_BAW_SIZE];
133 
134 	/* Preaggregation reorder queue */
135 	struct sk_buff_head queue;
136 
137 	struct ieee80211_sta *sta;
138 	struct ieee80211_vif *vif;
139 };
140 
141 #define CARL9170_QUEUE_TIMEOUT		256
142 #define CARL9170_BUMP_QUEUE		1000
143 #define CARL9170_TX_TIMEOUT		2500
144 #define CARL9170_JANITOR_DELAY		128
145 #define CARL9170_QUEUE_STUCK_TIMEOUT	5500
146 #define CARL9170_STAT_WORK		30000
147 
148 #define CARL9170_NUM_TX_AGG_MAX		30
149 
150 /*
151  * Tradeoff between stability/latency and speed.
152  *
153  * AR9170_TXQ_DEPTH is devised by dividing the amount of available
154  * tx buffers with the size of a full ethernet frame + overhead.
155  *
156  * Naturally: The higher the limit, the faster the device CAN send.
157  * However, even a slight over-commitment at the wrong time and the
158  * hardware is doomed to send all already-queued frames at suboptimal
159  * rates. This in turn leads to an enormous amount of unsuccessful
160  * retries => Latency goes up, whereas the throughput goes down. CRASH!
161  */
162 #define CARL9170_NUM_TX_LIMIT_HARD	((AR9170_TXQ_DEPTH * 3) / 2)
163 #define CARL9170_NUM_TX_LIMIT_SOFT	(AR9170_TXQ_DEPTH)
164 
165 struct carl9170_tx_queue_stats {
166 	unsigned int count;
167 	unsigned int limit;
168 	unsigned int len;
169 };
170 
171 struct carl9170_vif {
172 	unsigned int id;
173 	struct ieee80211_vif __rcu *vif;
174 };
175 
176 struct carl9170_vif_info {
177 	struct list_head list;
178 	bool active;
179 	unsigned int id;
180 	struct sk_buff *beacon;
181 	bool enable_beacon;
182 };
183 
184 #define AR9170_NUM_RX_URBS	16
185 #define AR9170_NUM_RX_URBS_MUL	2
186 #define AR9170_NUM_TX_URBS	8
187 #define AR9170_NUM_RX_URBS_POOL (AR9170_NUM_RX_URBS_MUL * AR9170_NUM_RX_URBS)
188 
189 enum carl9170_device_features {
190 	CARL9170_WPS_BUTTON		= BIT(0),
191 	CARL9170_ONE_LED		= BIT(1),
192 };
193 
194 #ifdef CONFIG_CARL9170_LEDS
195 struct ar9170;
196 
197 struct carl9170_led {
198 	struct ar9170 *ar;
199 	struct led_classdev l;
200 	char name[32];
201 	unsigned int toggled;
202 	bool last_state;
203 	bool registered;
204 };
205 #endif /* CONFIG_CARL9170_LEDS */
206 
207 enum carl9170_restart_reasons {
208 	CARL9170_RR_NO_REASON = 0,
209 	CARL9170_RR_FATAL_FIRMWARE_ERROR,
210 	CARL9170_RR_TOO_MANY_FIRMWARE_ERRORS,
211 	CARL9170_RR_WATCHDOG,
212 	CARL9170_RR_STUCK_TX,
213 	CARL9170_RR_UNRESPONSIVE_DEVICE,
214 	CARL9170_RR_COMMAND_TIMEOUT,
215 	CARL9170_RR_TOO_MANY_PHY_ERRORS,
216 	CARL9170_RR_LOST_RSP,
217 	CARL9170_RR_INVALID_RSP,
218 	CARL9170_RR_USER_REQUEST,
219 
220 	__CARL9170_RR_LAST,
221 };
222 
223 enum carl9170_erp_modes {
224 	CARL9170_ERP_INVALID,
225 	CARL9170_ERP_AUTO,
226 	CARL9170_ERP_MAC80211,
227 	CARL9170_ERP_OFF,
228 	CARL9170_ERP_CTS,
229 	CARL9170_ERP_RTS,
230 	__CARL9170_ERP_NUM,
231 };
232 
233 struct ar9170 {
234 	struct ath_common common;
235 	struct ieee80211_hw *hw;
236 	struct mutex mutex;
237 	enum carl9170_device_state state;
238 	spinlock_t state_lock;
239 	enum carl9170_restart_reasons last_reason;
240 	bool registered;
241 
242 	/* USB */
243 	struct usb_device *udev;
244 	struct usb_interface *intf;
245 	struct usb_anchor rx_anch;
246 	struct usb_anchor rx_work;
247 	struct usb_anchor rx_pool;
248 	struct usb_anchor tx_wait;
249 	struct usb_anchor tx_anch;
250 	struct usb_anchor tx_cmd;
251 	struct usb_anchor tx_err;
252 	struct tasklet_struct usb_tasklet;
253 	atomic_t tx_cmd_urbs;
254 	atomic_t tx_anch_urbs;
255 	atomic_t rx_anch_urbs;
256 	atomic_t rx_work_urbs;
257 	atomic_t rx_pool_urbs;
258 	kernel_ulong_t features;
259 
260 	/* firmware settings */
261 	struct completion fw_load_wait;
262 	struct completion fw_boot_wait;
263 	struct {
264 		const struct carl9170fw_desc_head *desc;
265 		const struct firmware *fw;
266 		unsigned int offset;
267 		unsigned int address;
268 		unsigned int cmd_bufs;
269 		unsigned int api_version;
270 		unsigned int vif_num;
271 		unsigned int err_counter;
272 		unsigned int bug_counter;
273 		u32 beacon_addr;
274 		unsigned int beacon_max_len;
275 		bool rx_stream;
276 		bool tx_stream;
277 		bool rx_filter;
278 		bool hw_counters;
279 		unsigned int mem_blocks;
280 		unsigned int mem_block_size;
281 		unsigned int rx_size;
282 		unsigned int tx_seq_table;
283 		bool ba_filter;
284 		bool disable_offload_fw;
285 	} fw;
286 
287 	/* interface configuration combinations */
288 	struct ieee80211_iface_limit if_comb_limits[1];
289 	struct ieee80211_iface_combination if_combs[1];
290 
291 	/* reset / stuck frames/queue detection */
292 	struct work_struct restart_work;
293 	struct work_struct ping_work;
294 	unsigned int restart_counter;
295 	unsigned long queue_stop_timeout[__AR9170_NUM_TXQ];
296 	unsigned long max_queue_stop_timeout[__AR9170_NUM_TXQ];
297 	bool needs_full_reset;
298 	bool force_usb_reset;
299 	atomic_t pending_restarts;
300 
301 	/* interface mode settings */
302 	struct list_head vif_list;
303 	unsigned long vif_bitmap;
304 	unsigned int vifs;
305 	struct carl9170_vif vif_priv[AR9170_MAX_VIRTUAL_MAC];
306 
307 	/* beaconing */
308 	spinlock_t beacon_lock;
309 	unsigned int global_pretbtt;
310 	unsigned int global_beacon_int;
311 	struct carl9170_vif_info __rcu *beacon_iter;
312 	unsigned int beacon_enabled;
313 
314 	/* cryptographic engine */
315 	u64 usedkeys;
316 	bool rx_software_decryption;
317 	bool disable_offload;
318 
319 	/* filter settings */
320 	u64 cur_mc_hash;
321 	u32 cur_filter;
322 	unsigned int filter_state;
323 	unsigned int rx_filter_caps;
324 	bool sniffer_enabled;
325 
326 	/* MAC */
327 	enum carl9170_erp_modes erp_mode;
328 
329 	/* PHY */
330 	struct ieee80211_channel *channel;
331 	unsigned int num_channels;
332 	int noise[4];
333 	unsigned int chan_fail;
334 	unsigned int total_chan_fail;
335 	u8 heavy_clip;
336 	u8 ht_settings;
337 	struct {
338 		u64 active;	/* usec */
339 		u64 cca;	/* usec */
340 		u64 tx_time;	/* usec */
341 		u64 rx_total;
342 		u64 rx_overrun;
343 	} tally;
344 	struct delayed_work stat_work;
345 	struct survey_info *survey;
346 
347 	/* power calibration data */
348 	u8 power_5G_leg[4];
349 	u8 power_2G_cck[4];
350 	u8 power_2G_ofdm[4];
351 	u8 power_5G_ht20[8];
352 	u8 power_5G_ht40[8];
353 	u8 power_2G_ht20[8];
354 	u8 power_2G_ht40[8];
355 
356 #ifdef CONFIG_CARL9170_LEDS
357 	/* LED */
358 	struct delayed_work led_work;
359 	struct carl9170_led leds[AR9170_NUM_LEDS];
360 #endif /* CONFIG_CARL9170_LEDS */
361 
362 	/* qos queue settings */
363 	spinlock_t tx_stats_lock;
364 	struct carl9170_tx_queue_stats tx_stats[__AR9170_NUM_TXQ];
365 	struct ieee80211_tx_queue_params edcf[5];
366 	struct completion tx_flush;
367 
368 	/* CMD */
369 	int cmd_seq;
370 	int readlen;
371 	u8 *readbuf;
372 	spinlock_t cmd_lock;
373 	struct completion cmd_wait;
374 	union {
375 		__le32 cmd_buf[PAYLOAD_MAX + 1];
376 		struct carl9170_cmd cmd;
377 		struct carl9170_rsp rsp;
378 	};
379 
380 	/* statistics */
381 	unsigned int tx_dropped;
382 	unsigned int tx_ack_failures;
383 	unsigned int tx_fcs_errors;
384 	unsigned int rx_dropped;
385 
386 	/* EEPROM */
387 	struct ar9170_eeprom eeprom;
388 
389 	/* tx queuing */
390 	struct sk_buff_head tx_pending[__AR9170_NUM_TXQ];
391 	struct sk_buff_head tx_status[__AR9170_NUM_TXQ];
392 	struct delayed_work tx_janitor;
393 	unsigned long tx_janitor_last_run;
394 	bool tx_schedule;
395 
396 	/* tx ampdu */
397 	struct work_struct ampdu_work;
398 	spinlock_t tx_ampdu_list_lock;
399 	struct carl9170_sta_tid __rcu *tx_ampdu_iter;
400 	struct list_head tx_ampdu_list;
401 	atomic_t tx_ampdu_upload;
402 	atomic_t tx_ampdu_scheduler;
403 	atomic_t tx_total_pending;
404 	atomic_t tx_total_queued;
405 	unsigned int tx_ampdu_list_len;
406 	int current_density;
407 	int current_factor;
408 	bool tx_ampdu_schedule;
409 
410 	/* internal memory management */
411 	spinlock_t mem_lock;
412 	unsigned long *mem_bitmap;
413 	atomic_t mem_free_blocks;
414 	atomic_t mem_allocs;
415 
416 	/* rxstream mpdu merge */
417 	struct ar9170_rx_head rx_plcp;
418 	bool rx_has_plcp;
419 	struct sk_buff *rx_failover;
420 	int rx_failover_missing;
421 	u32 ampdu_ref;
422 
423 	/* FIFO for collecting outstanding BlockAckRequest */
424 	struct list_head bar_list[__AR9170_NUM_TXQ];
425 	spinlock_t bar_list_lock[__AR9170_NUM_TXQ];
426 
427 #ifdef CONFIG_CARL9170_WPC
428 	struct {
429 		bool pbc_state;
430 		struct input_dev *pbc;
431 		char name[32];
432 		char phys[32];
433 	} wps;
434 #endif /* CONFIG_CARL9170_WPC */
435 
436 #ifdef CONFIG_CARL9170_DEBUGFS
437 	struct carl9170_debug debug;
438 	struct dentry *debug_dir;
439 #endif /* CONFIG_CARL9170_DEBUGFS */
440 
441 	/* PSM */
442 	struct work_struct ps_work;
443 	struct {
444 		unsigned int dtim_counter;
445 		unsigned long last_beacon;
446 		unsigned long last_action;
447 		unsigned long last_slept;
448 		unsigned int sleep_ms;
449 		unsigned int off_override;
450 		bool state;
451 	} ps;
452 
453 #ifdef CONFIG_CARL9170_HWRNG
454 # define CARL9170_HWRNG_CACHE_SIZE	CARL9170_MAX_CMD_PAYLOAD_LEN
455 	struct {
456 		struct hwrng rng;
457 		bool initialized;
458 		char name[30 + 1];
459 		u16 cache[CARL9170_HWRNG_CACHE_SIZE / sizeof(u16)];
460 		unsigned int cache_idx;
461 	} rng;
462 #endif /* CONFIG_CARL9170_HWRNG */
463 };
464 
465 enum carl9170_ps_off_override_reasons {
466 	PS_OFF_VIF	= BIT(0),
467 	PS_OFF_BCN	= BIT(1),
468 };
469 
470 struct carl9170_bar_list_entry {
471 	struct list_head list;
472 	struct rcu_head head;
473 	struct sk_buff *skb;
474 };
475 
476 struct carl9170_ba_stats {
477 	u8 ampdu_len;
478 	u8 ampdu_ack_len;
479 	bool clear;
480 	bool req;
481 };
482 
483 struct carl9170_sta_info {
484 	bool ht_sta;
485 	bool sleeping;
486 	atomic_t pending_frames;
487 	unsigned int ampdu_max_len;
488 	struct carl9170_sta_tid __rcu *agg[IEEE80211_NUM_TIDS];
489 	struct carl9170_ba_stats stats[IEEE80211_NUM_TIDS];
490 };
491 
492 struct carl9170_tx_info {
493 	unsigned long timeout;
494 	struct ar9170 *ar;
495 	struct kref ref;
496 };
497 
498 #define CHK_DEV_STATE(a, s)	(((struct ar9170 *)a)->state >= (s))
499 #define IS_INITIALIZED(a)	(CHK_DEV_STATE(a, CARL9170_STOPPED))
500 #define IS_ACCEPTING_CMD(a)	(CHK_DEV_STATE(a, CARL9170_IDLE))
501 #define IS_STARTED(a)		(CHK_DEV_STATE(a, CARL9170_STARTED))
502 
503 static inline void __carl9170_set_state(struct ar9170 *ar,
504 	enum carl9170_device_state newstate)
505 {
506 	ar->state = newstate;
507 }
508 
509 static inline void carl9170_set_state(struct ar9170 *ar,
510 	enum carl9170_device_state newstate)
511 {
512 	unsigned long flags;
513 
514 	spin_lock_irqsave(&ar->state_lock, flags);
515 	__carl9170_set_state(ar, newstate);
516 	spin_unlock_irqrestore(&ar->state_lock, flags);
517 }
518 
519 static inline void carl9170_set_state_when(struct ar9170 *ar,
520 	enum carl9170_device_state min, enum carl9170_device_state newstate)
521 {
522 	unsigned long flags;
523 
524 	spin_lock_irqsave(&ar->state_lock, flags);
525 	if (CHK_DEV_STATE(ar, min))
526 		__carl9170_set_state(ar, newstate);
527 	spin_unlock_irqrestore(&ar->state_lock, flags);
528 }
529 
530 /* exported interface */
531 void *carl9170_alloc(size_t priv_size);
532 int carl9170_register(struct ar9170 *ar);
533 void carl9170_unregister(struct ar9170 *ar);
534 void carl9170_free(struct ar9170 *ar);
535 void carl9170_restart(struct ar9170 *ar, const enum carl9170_restart_reasons r);
536 void carl9170_ps_check(struct ar9170 *ar);
537 
538 /* USB back-end */
539 int carl9170_usb_open(struct ar9170 *ar);
540 void carl9170_usb_stop(struct ar9170 *ar);
541 void carl9170_usb_tx(struct ar9170 *ar, struct sk_buff *skb);
542 void carl9170_usb_handle_tx_err(struct ar9170 *ar);
543 int carl9170_exec_cmd(struct ar9170 *ar, const enum carl9170_cmd_oids,
544 		      u32 plen, void *payload, u32 rlen, void *resp);
545 int __carl9170_exec_cmd(struct ar9170 *ar, struct carl9170_cmd *cmd,
546 			const bool free_buf);
547 int carl9170_usb_restart(struct ar9170 *ar);
548 void carl9170_usb_reset(struct ar9170 *ar);
549 
550 /* MAC */
551 int carl9170_init_mac(struct ar9170 *ar);
552 int carl9170_set_qos(struct ar9170 *ar);
553 int carl9170_update_multicast(struct ar9170 *ar, const u64 mc_hast);
554 int carl9170_mod_virtual_mac(struct ar9170 *ar, const unsigned int id,
555 			     const u8 *mac);
556 int carl9170_set_operating_mode(struct ar9170 *ar);
557 int carl9170_set_beacon_timers(struct ar9170 *ar);
558 int carl9170_set_dyn_sifs_ack(struct ar9170 *ar);
559 int carl9170_set_rts_cts_rate(struct ar9170 *ar);
560 int carl9170_set_ampdu_settings(struct ar9170 *ar);
561 int carl9170_set_slot_time(struct ar9170 *ar);
562 int carl9170_set_mac_rates(struct ar9170 *ar);
563 int carl9170_set_hwretry_limit(struct ar9170 *ar, const u32 max_retry);
564 int carl9170_upload_key(struct ar9170 *ar, const u8 id, const u8 *mac,
565 	const u8 ktype, const u8 keyidx, const u8 *keydata, const int keylen);
566 int carl9170_disable_key(struct ar9170 *ar, const u8 id);
567 int carl9170_set_mac_tpc(struct ar9170 *ar, struct ieee80211_channel *channel);
568 
569 /* RX */
570 void carl9170_rx(struct ar9170 *ar, void *buf, unsigned int len);
571 void carl9170_handle_command_response(struct ar9170 *ar, void *buf, u32 len);
572 
573 /* TX */
574 void carl9170_op_tx(struct ieee80211_hw *hw,
575 		    struct ieee80211_tx_control *control,
576 		    struct sk_buff *skb);
577 void carl9170_tx_janitor(struct work_struct *work);
578 void carl9170_tx_process_status(struct ar9170 *ar,
579 				const struct carl9170_rsp *cmd);
580 void carl9170_tx_status(struct ar9170 *ar, struct sk_buff *skb,
581 			const bool success);
582 void carl9170_tx_callback(struct ar9170 *ar, struct sk_buff *skb);
583 void carl9170_tx_drop(struct ar9170 *ar, struct sk_buff *skb);
584 void carl9170_tx_scheduler(struct ar9170 *ar);
585 void carl9170_tx_get_skb(struct sk_buff *skb);
586 int carl9170_tx_put_skb(struct sk_buff *skb);
587 int carl9170_update_beacon(struct ar9170 *ar, const bool submit);
588 
589 /* LEDs */
590 #ifdef CONFIG_CARL9170_LEDS
591 int carl9170_led_register(struct ar9170 *ar);
592 void carl9170_led_unregister(struct ar9170 *ar);
593 #endif /* CONFIG_CARL9170_LEDS */
594 int carl9170_led_init(struct ar9170 *ar);
595 int carl9170_led_set_state(struct ar9170 *ar, const u32 led_state);
596 
597 /* PHY / RF */
598 int carl9170_set_channel(struct ar9170 *ar, struct ieee80211_channel *channel,
599 			 enum nl80211_channel_type bw);
600 int carl9170_get_noisefloor(struct ar9170 *ar);
601 
602 /* FW */
603 int carl9170_parse_firmware(struct ar9170 *ar);
604 
605 extern struct ieee80211_rate __carl9170_ratetable[];
606 extern int modparam_noht;
607 
608 static inline struct ar9170 *carl9170_get_priv(struct carl9170_vif *carl_vif)
609 {
610 	return container_of(carl_vif, struct ar9170,
611 			    vif_priv[carl_vif->id]);
612 }
613 
614 static inline struct ieee80211_hdr *carl9170_get_hdr(struct sk_buff *skb)
615 {
616 	return (void *)((struct _carl9170_tx_superframe *)
617 		skb->data)->frame_data;
618 }
619 
620 static inline u16 get_seq_h(struct ieee80211_hdr *hdr)
621 {
622 	return le16_to_cpu(hdr->seq_ctrl) >> 4;
623 }
624 
625 static inline u16 carl9170_get_seq(struct sk_buff *skb)
626 {
627 	return get_seq_h(carl9170_get_hdr(skb));
628 }
629 
630 static inline u16 get_tid_h(struct ieee80211_hdr *hdr)
631 {
632 	return (ieee80211_get_qos_ctl(hdr))[0] & IEEE80211_QOS_CTL_TID_MASK;
633 }
634 
635 static inline u16 carl9170_get_tid(struct sk_buff *skb)
636 {
637 	return get_tid_h(carl9170_get_hdr(skb));
638 }
639 
640 static inline struct ieee80211_vif *
641 carl9170_get_vif(struct carl9170_vif_info *priv)
642 {
643 	return container_of((void *)priv, struct ieee80211_vif, drv_priv);
644 }
645 
646 /* Protected by ar->mutex or RCU */
647 static inline struct ieee80211_vif *carl9170_get_main_vif(struct ar9170 *ar)
648 {
649 	struct carl9170_vif_info *cvif;
650 
651 	list_for_each_entry_rcu(cvif, &ar->vif_list, list) {
652 		if (cvif->active)
653 			return carl9170_get_vif(cvif);
654 	}
655 
656 	return NULL;
657 }
658 
659 static inline bool is_main_vif(struct ar9170 *ar, struct ieee80211_vif *vif)
660 {
661 	bool ret;
662 
663 	rcu_read_lock();
664 	ret = (carl9170_get_main_vif(ar) == vif);
665 	rcu_read_unlock();
666 	return ret;
667 }
668 
669 #endif /* __CARL9170_H */
670