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