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