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