blob: 237d0cda1bcb053b40f994a9cbfcee51db3347ab [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>
Christian Lamparter00044f12011-08-15 20:09:54 +020046#include <linux/hw_random.h>
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +020047#include <net/cfg80211.h>
48#include <net/mac80211.h>
49#include <linux/usb.h>
50#ifdef CONFIG_CARL9170_LEDS
51#include <linux/leds.h>
Hauke Mehrtens8e7ce892010-10-23 19:51:32 +020052#endif /* CONFIG_CARL9170_LEDS */
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +020053#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
Christian Lamparter85ee5122011-06-30 20:27:47 +020071static const u8 ar9170_qmap[__AR9170_NUM_TXQ] = { 3, 2, 1, 0 };
72
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +020073#define CARL9170_MAX_RX_BUFFER_SIZE 8192
74
75enum carl9170_device_state {
76 CARL9170_UNKNOWN_STATE,
77 CARL9170_STOPPED,
78 CARL9170_IDLE,
79 CARL9170_STARTED,
80};
81
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +020082#define WME_BA_BMP_SIZE 64
83#define CARL9170_TX_USER_RATE_TRIES 3
84
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +020085#define TID_TO_WME_AC(_tid) \
Christian Lamparter558925f2012-12-20 02:44:29 +010086 ((((_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)
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +020090
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
100enum 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
114struct 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;
Christian Lamparter9ad86ed2013-06-12 21:35:39 +0200136
137 struct ieee80211_sta *sta;
138 struct ieee80211_vif *vif;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200139};
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
Christian Lamparteracf17712011-08-15 19:50:48 +0200146#define CARL9170_STAT_WORK 30000
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200147
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
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300159 * rates. This in turn leads to an enormous amount of unsuccessful
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200160 * 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
165struct carl9170_tx_queue_stats {
166 unsigned int count;
167 unsigned int limit;
168 unsigned int len;
169};
170
171struct carl9170_vif {
172 unsigned int id;
Pavel Roskin70126f62011-07-19 18:02:15 -0400173 struct ieee80211_vif __rcu *vif;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200174};
175
176struct 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
189enum carl9170_device_features {
190 CARL9170_WPS_BUTTON = BIT(0),
191 CARL9170_ONE_LED = BIT(1),
192};
193
194#ifdef CONFIG_CARL9170_LEDS
195struct ar9170;
196
197struct 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
207enum 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,
Christian Lampartere4a668c2010-10-29 23:26:13 +0200213 CARL9170_RR_UNRESPONSIVE_DEVICE,
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200214 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
223enum 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
233struct 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;
Ronald Wahl671796d2014-08-07 14:15:50 +0200259 bool usb_ep_cmd_is_bulk;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200260
261 /* firmware settings */
262 struct completion fw_load_wait;
263 struct completion fw_boot_wait;
264 struct {
265 const struct carl9170fw_desc_head *desc;
266 const struct firmware *fw;
267 unsigned int offset;
268 unsigned int address;
269 unsigned int cmd_bufs;
270 unsigned int api_version;
271 unsigned int vif_num;
272 unsigned int err_counter;
273 unsigned int bug_counter;
274 u32 beacon_addr;
275 unsigned int beacon_max_len;
276 bool rx_stream;
277 bool tx_stream;
Christian Lamparter5c895692010-09-28 23:00:59 +0200278 bool rx_filter;
Christian Lamparter7ccc83b2011-08-15 18:45:54 +0200279 bool hw_counters;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200280 unsigned int mem_blocks;
281 unsigned int mem_block_size;
282 unsigned int rx_size;
Christian Lamparteraa324522011-01-23 00:18:28 +0100283 unsigned int tx_seq_table;
Christian Lamparterc9122c02012-07-07 21:13:59 +0200284 bool ba_filter;
Christian Lamparter7a5c7302012-12-17 16:30:05 +0100285 bool disable_offload_fw;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200286 } fw;
287
Christian Lamparterdf649622011-05-14 02:42:38 +0200288 /* interface configuration combinations */
289 struct ieee80211_iface_limit if_comb_limits[1];
290 struct ieee80211_iface_combination if_combs[1];
291
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200292 /* reset / stuck frames/queue detection */
293 struct work_struct restart_work;
Christian Lampartere4a668c2010-10-29 23:26:13 +0200294 struct work_struct ping_work;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200295 unsigned int restart_counter;
296 unsigned long queue_stop_timeout[__AR9170_NUM_TXQ];
297 unsigned long max_queue_stop_timeout[__AR9170_NUM_TXQ];
298 bool needs_full_reset;
Ronald Wahl5bcbc3f2012-10-08 14:17:07 +0200299 bool force_usb_reset;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200300 atomic_t pending_restarts;
301
302 /* interface mode settings */
303 struct list_head vif_list;
304 unsigned long vif_bitmap;
305 unsigned int vifs;
306 struct carl9170_vif vif_priv[AR9170_MAX_VIRTUAL_MAC];
307
308 /* beaconing */
309 spinlock_t beacon_lock;
310 unsigned int global_pretbtt;
311 unsigned int global_beacon_int;
Pavel Roskin70126f62011-07-19 18:02:15 -0400312 struct carl9170_vif_info __rcu *beacon_iter;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200313 unsigned int beacon_enabled;
314
315 /* cryptographic engine */
316 u64 usedkeys;
317 bool rx_software_decryption;
318 bool disable_offload;
319
320 /* filter settings */
321 u64 cur_mc_hash;
322 u32 cur_filter;
323 unsigned int filter_state;
Christian Lamparter5c895692010-09-28 23:00:59 +0200324 unsigned int rx_filter_caps;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200325 bool sniffer_enabled;
326
327 /* MAC */
328 enum carl9170_erp_modes erp_mode;
329
330 /* PHY */
331 struct ieee80211_channel *channel;
Christian Lamparteracf17712011-08-15 19:50:48 +0200332 unsigned int num_channels;
Christian Lamparter9adc9e02010-09-17 22:42:37 +0200333 int noise[4];
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200334 unsigned int chan_fail;
335 unsigned int total_chan_fail;
336 u8 heavy_clip;
Christian Lamparter73576112010-09-17 23:09:19 +0200337 u8 ht_settings;
Christian Lamparteracf17712011-08-15 19:50:48 +0200338 struct {
339 u64 active; /* usec */
340 u64 cca; /* usec */
341 u64 tx_time; /* usec */
342 u64 rx_total;
343 u64 rx_overrun;
344 } tally;
345 struct delayed_work stat_work;
346 struct survey_info *survey;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200347
348 /* power calibration data */
349 u8 power_5G_leg[4];
350 u8 power_2G_cck[4];
351 u8 power_2G_ofdm[4];
352 u8 power_5G_ht20[8];
353 u8 power_5G_ht40[8];
354 u8 power_2G_ht20[8];
355 u8 power_2G_ht40[8];
356
357#ifdef CONFIG_CARL9170_LEDS
358 /* LED */
359 struct delayed_work led_work;
360 struct carl9170_led leds[AR9170_NUM_LEDS];
361#endif /* CONFIG_CARL9170_LEDS */
362
363 /* qos queue settings */
364 spinlock_t tx_stats_lock;
365 struct carl9170_tx_queue_stats tx_stats[__AR9170_NUM_TXQ];
366 struct ieee80211_tx_queue_params edcf[5];
367 struct completion tx_flush;
368
369 /* CMD */
370 int cmd_seq;
371 int readlen;
372 u8 *readbuf;
373 spinlock_t cmd_lock;
374 struct completion cmd_wait;
375 union {
376 __le32 cmd_buf[PAYLOAD_MAX + 1];
377 struct carl9170_cmd cmd;
378 struct carl9170_rsp rsp;
379 };
380
381 /* statistics */
382 unsigned int tx_dropped;
383 unsigned int tx_ack_failures;
384 unsigned int tx_fcs_errors;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200385 unsigned int rx_dropped;
386
387 /* EEPROM */
388 struct ar9170_eeprom eeprom;
389
390 /* tx queuing */
391 struct sk_buff_head tx_pending[__AR9170_NUM_TXQ];
392 struct sk_buff_head tx_status[__AR9170_NUM_TXQ];
393 struct delayed_work tx_janitor;
394 unsigned long tx_janitor_last_run;
395 bool tx_schedule;
396
397 /* tx ampdu */
398 struct work_struct ampdu_work;
399 spinlock_t tx_ampdu_list_lock;
Pavel Roskin70126f62011-07-19 18:02:15 -0400400 struct carl9170_sta_tid __rcu *tx_ampdu_iter;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200401 struct list_head tx_ampdu_list;
402 atomic_t tx_ampdu_upload;
403 atomic_t tx_ampdu_scheduler;
404 atomic_t tx_total_pending;
405 atomic_t tx_total_queued;
406 unsigned int tx_ampdu_list_len;
407 int current_density;
408 int current_factor;
409 bool tx_ampdu_schedule;
410
411 /* internal memory management */
412 spinlock_t mem_lock;
413 unsigned long *mem_bitmap;
414 atomic_t mem_free_blocks;
415 atomic_t mem_allocs;
416
417 /* rxstream mpdu merge */
418 struct ar9170_rx_head rx_plcp;
419 bool rx_has_plcp;
420 struct sk_buff *rx_failover;
421 int rx_failover_missing;
Christian Lamparter33dd7692012-07-31 21:12:16 +0000422 u32 ampdu_ref;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200423
Christian Lamparterc9122c02012-07-07 21:13:59 +0200424 /* FIFO for collecting outstanding BlockAckRequest */
425 struct list_head bar_list[__AR9170_NUM_TXQ];
426 spinlock_t bar_list_lock[__AR9170_NUM_TXQ];
427
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200428#ifdef CONFIG_CARL9170_WPC
429 struct {
430 bool pbc_state;
431 struct input_dev *pbc;
432 char name[32];
433 char phys[32];
434 } wps;
435#endif /* CONFIG_CARL9170_WPC */
436
437#ifdef CONFIG_CARL9170_DEBUGFS
438 struct carl9170_debug debug;
439 struct dentry *debug_dir;
440#endif /* CONFIG_CARL9170_DEBUGFS */
441
442 /* PSM */
443 struct work_struct ps_work;
444 struct {
445 unsigned int dtim_counter;
446 unsigned long last_beacon;
447 unsigned long last_action;
448 unsigned long last_slept;
449 unsigned int sleep_ms;
450 unsigned int off_override;
451 bool state;
452 } ps;
Christian Lamparter00044f12011-08-15 20:09:54 +0200453
454#ifdef CONFIG_CARL9170_HWRNG
455# define CARL9170_HWRNG_CACHE_SIZE CARL9170_MAX_CMD_PAYLOAD_LEN
456 struct {
457 struct hwrng rng;
458 bool initialized;
459 char name[30 + 1];
460 u16 cache[CARL9170_HWRNG_CACHE_SIZE / sizeof(u16)];
461 unsigned int cache_idx;
462 } rng;
463#endif /* CONFIG_CARL9170_HWRNG */
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200464};
465
466enum carl9170_ps_off_override_reasons {
467 PS_OFF_VIF = BIT(0),
468 PS_OFF_BCN = BIT(1),
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200469};
470
Christian Lamparterc9122c02012-07-07 21:13:59 +0200471struct carl9170_bar_list_entry {
472 struct list_head list;
473 struct rcu_head head;
474 struct sk_buff *skb;
475};
476
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200477struct carl9170_ba_stats {
478 u8 ampdu_len;
479 u8 ampdu_ack_len;
480 bool clear;
Christian Lamparter24047e22011-03-29 13:43:14 +0200481 bool req;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200482};
483
484struct carl9170_sta_info {
485 bool ht_sta;
Christian Lampartercaf1eae2011-04-24 17:44:19 +0200486 bool sleeping;
487 atomic_t pending_frames;
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200488 unsigned int ampdu_max_len;
Christian Lamparter558925f2012-12-20 02:44:29 +0100489 struct carl9170_sta_tid __rcu *agg[IEEE80211_NUM_TIDS];
490 struct carl9170_ba_stats stats[IEEE80211_NUM_TIDS];
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200491};
492
493struct carl9170_tx_info {
494 unsigned long timeout;
495 struct ar9170 *ar;
496 struct kref ref;
497};
498
499#define CHK_DEV_STATE(a, s) (((struct ar9170 *)a)->state >= (s))
500#define IS_INITIALIZED(a) (CHK_DEV_STATE(a, CARL9170_STOPPED))
501#define IS_ACCEPTING_CMD(a) (CHK_DEV_STATE(a, CARL9170_IDLE))
502#define IS_STARTED(a) (CHK_DEV_STATE(a, CARL9170_STARTED))
503
504static inline void __carl9170_set_state(struct ar9170 *ar,
505 enum carl9170_device_state newstate)
506{
507 ar->state = newstate;
508}
509
510static inline void carl9170_set_state(struct ar9170 *ar,
511 enum carl9170_device_state newstate)
512{
513 unsigned long flags;
514
515 spin_lock_irqsave(&ar->state_lock, flags);
516 __carl9170_set_state(ar, newstate);
517 spin_unlock_irqrestore(&ar->state_lock, flags);
518}
519
520static inline void carl9170_set_state_when(struct ar9170 *ar,
521 enum carl9170_device_state min, enum carl9170_device_state newstate)
522{
523 unsigned long flags;
524
525 spin_lock_irqsave(&ar->state_lock, flags);
526 if (CHK_DEV_STATE(ar, min))
527 __carl9170_set_state(ar, newstate);
528 spin_unlock_irqrestore(&ar->state_lock, flags);
529}
530
531/* exported interface */
532void *carl9170_alloc(size_t priv_size);
533int carl9170_register(struct ar9170 *ar);
534void carl9170_unregister(struct ar9170 *ar);
535void carl9170_free(struct ar9170 *ar);
536void carl9170_restart(struct ar9170 *ar, const enum carl9170_restart_reasons r);
537void carl9170_ps_check(struct ar9170 *ar);
538
539/* USB back-end */
540int carl9170_usb_open(struct ar9170 *ar);
541void carl9170_usb_stop(struct ar9170 *ar);
542void carl9170_usb_tx(struct ar9170 *ar, struct sk_buff *skb);
543void carl9170_usb_handle_tx_err(struct ar9170 *ar);
544int carl9170_exec_cmd(struct ar9170 *ar, const enum carl9170_cmd_oids,
545 u32 plen, void *payload, u32 rlen, void *resp);
546int __carl9170_exec_cmd(struct ar9170 *ar, struct carl9170_cmd *cmd,
547 const bool free_buf);
548int carl9170_usb_restart(struct ar9170 *ar);
549void carl9170_usb_reset(struct ar9170 *ar);
550
551/* MAC */
552int carl9170_init_mac(struct ar9170 *ar);
553int carl9170_set_qos(struct ar9170 *ar);
554int carl9170_update_multicast(struct ar9170 *ar, const u64 mc_hast);
555int carl9170_mod_virtual_mac(struct ar9170 *ar, const unsigned int id,
556 const u8 *mac);
557int carl9170_set_operating_mode(struct ar9170 *ar);
558int carl9170_set_beacon_timers(struct ar9170 *ar);
559int carl9170_set_dyn_sifs_ack(struct ar9170 *ar);
560int carl9170_set_rts_cts_rate(struct ar9170 *ar);
561int carl9170_set_ampdu_settings(struct ar9170 *ar);
562int carl9170_set_slot_time(struct ar9170 *ar);
563int carl9170_set_mac_rates(struct ar9170 *ar);
564int carl9170_set_hwretry_limit(struct ar9170 *ar, const u32 max_retry);
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200565int carl9170_upload_key(struct ar9170 *ar, const u8 id, const u8 *mac,
566 const u8 ktype, const u8 keyidx, const u8 *keydata, const int keylen);
567int carl9170_disable_key(struct ar9170 *ar, const u8 id);
Christian Lamparter67e43de2012-01-21 16:59:10 +0100568int carl9170_set_mac_tpc(struct ar9170 *ar, struct ieee80211_channel *channel);
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200569
570/* RX */
571void carl9170_rx(struct ar9170 *ar, void *buf, unsigned int len);
572void carl9170_handle_command_response(struct ar9170 *ar, void *buf, u32 len);
573
574/* TX */
Thomas Huehn36323f82012-07-23 21:33:42 +0200575void carl9170_op_tx(struct ieee80211_hw *hw,
576 struct ieee80211_tx_control *control,
577 struct sk_buff *skb);
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200578void carl9170_tx_janitor(struct work_struct *work);
579void carl9170_tx_process_status(struct ar9170 *ar,
580 const struct carl9170_rsp *cmd);
581void carl9170_tx_status(struct ar9170 *ar, struct sk_buff *skb,
582 const bool success);
583void carl9170_tx_callback(struct ar9170 *ar, struct sk_buff *skb);
584void carl9170_tx_drop(struct ar9170 *ar, struct sk_buff *skb);
585void carl9170_tx_scheduler(struct ar9170 *ar);
586void carl9170_tx_get_skb(struct sk_buff *skb);
587int carl9170_tx_put_skb(struct sk_buff *skb);
Christian Lamparter943c3392011-07-16 17:25:14 +0200588int carl9170_update_beacon(struct ar9170 *ar, const bool submit);
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200589
590/* LEDs */
591#ifdef CONFIG_CARL9170_LEDS
592int carl9170_led_register(struct ar9170 *ar);
593void carl9170_led_unregister(struct ar9170 *ar);
594#endif /* CONFIG_CARL9170_LEDS */
595int carl9170_led_init(struct ar9170 *ar);
596int carl9170_led_set_state(struct ar9170 *ar, const u32 led_state);
597
598/* PHY / RF */
599int carl9170_set_channel(struct ar9170 *ar, struct ieee80211_channel *channel,
Christian Lamparter56771e52013-03-25 17:15:17 +0100600 enum nl80211_channel_type bw);
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200601int carl9170_get_noisefloor(struct ar9170 *ar);
602
603/* FW */
604int carl9170_parse_firmware(struct ar9170 *ar);
Christian Lamparterfe8ee9a2010-09-06 00:48:55 +0200605
606extern struct ieee80211_rate __carl9170_ratetable[];
607extern int modparam_noht;
608
609static inline struct ar9170 *carl9170_get_priv(struct carl9170_vif *carl_vif)
610{
611 return container_of(carl_vif, struct ar9170,
612 vif_priv[carl_vif->id]);
613}
614
615static inline struct ieee80211_hdr *carl9170_get_hdr(struct sk_buff *skb)
616{
617 return (void *)((struct _carl9170_tx_superframe *)
618 skb->data)->frame_data;
619}
620
621static inline u16 get_seq_h(struct ieee80211_hdr *hdr)
622{
623 return le16_to_cpu(hdr->seq_ctrl) >> 4;
624}
625
626static inline u16 carl9170_get_seq(struct sk_buff *skb)
627{
628 return get_seq_h(carl9170_get_hdr(skb));
629}
630
631static inline u16 get_tid_h(struct ieee80211_hdr *hdr)
632{
633 return (ieee80211_get_qos_ctl(hdr))[0] & IEEE80211_QOS_CTL_TID_MASK;
634}
635
636static inline u16 carl9170_get_tid(struct sk_buff *skb)
637{
638 return get_tid_h(carl9170_get_hdr(skb));
639}
640
641static inline struct ieee80211_vif *
642carl9170_get_vif(struct carl9170_vif_info *priv)
643{
644 return container_of((void *)priv, struct ieee80211_vif, drv_priv);
645}
646
647/* Protected by ar->mutex or RCU */
648static inline struct ieee80211_vif *carl9170_get_main_vif(struct ar9170 *ar)
649{
650 struct carl9170_vif_info *cvif;
651
652 list_for_each_entry_rcu(cvif, &ar->vif_list, list) {
653 if (cvif->active)
654 return carl9170_get_vif(cvif);
655 }
656
657 return NULL;
658}
659
660static inline bool is_main_vif(struct ar9170 *ar, struct ieee80211_vif *vif)
661{
662 bool ret;
663
664 rcu_read_lock();
665 ret = (carl9170_get_main_vif(ar) == vif);
666 rcu_read_unlock();
667 return ret;
668}
669
670#endif /* __CARL9170_H */