Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Atheros AR9170 driver |
| 3 | * |
| 4 | * mac80211 interaction code |
| 5 | * |
| 6 | * Copyright 2008, Johannes Berg <johannes@sipsolutions.net> |
| 7 | * Copyright 2009, Christian Lamparter <chunkeey@web.de> |
| 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 | |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 40 | #include <linux/init.h> |
| 41 | #include <linux/module.h> |
| 42 | #include <linux/etherdevice.h> |
| 43 | #include <net/mac80211.h> |
| 44 | #include "ar9170.h" |
| 45 | #include "hw.h" |
| 46 | #include "cmd.h" |
| 47 | |
| 48 | static int modparam_nohwcrypt; |
| 49 | module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO); |
| 50 | MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption."); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 51 | |
| 52 | #define RATE(_bitrate, _hw_rate, _txpidx, _flags) { \ |
| 53 | .bitrate = (_bitrate), \ |
| 54 | .flags = (_flags), \ |
| 55 | .hw_value = (_hw_rate) | (_txpidx) << 4, \ |
| 56 | } |
| 57 | |
| 58 | static struct ieee80211_rate __ar9170_ratetable[] = { |
| 59 | RATE(10, 0, 0, 0), |
| 60 | RATE(20, 1, 1, IEEE80211_RATE_SHORT_PREAMBLE), |
| 61 | RATE(55, 2, 2, IEEE80211_RATE_SHORT_PREAMBLE), |
| 62 | RATE(110, 3, 3, IEEE80211_RATE_SHORT_PREAMBLE), |
| 63 | RATE(60, 0xb, 0, 0), |
| 64 | RATE(90, 0xf, 0, 0), |
| 65 | RATE(120, 0xa, 0, 0), |
| 66 | RATE(180, 0xe, 0, 0), |
| 67 | RATE(240, 0x9, 0, 0), |
| 68 | RATE(360, 0xd, 1, 0), |
| 69 | RATE(480, 0x8, 2, 0), |
| 70 | RATE(540, 0xc, 3, 0), |
| 71 | }; |
| 72 | #undef RATE |
| 73 | |
| 74 | #define ar9170_g_ratetable (__ar9170_ratetable + 0) |
| 75 | #define ar9170_g_ratetable_size 12 |
| 76 | #define ar9170_a_ratetable (__ar9170_ratetable + 4) |
| 77 | #define ar9170_a_ratetable_size 8 |
| 78 | |
| 79 | /* |
| 80 | * NB: The hw_value is used as an index into the ar9170_phy_freq_params |
| 81 | * array in phy.c so that we don't have to do frequency lookups! |
| 82 | */ |
| 83 | #define CHAN(_freq, _idx) { \ |
| 84 | .center_freq = (_freq), \ |
| 85 | .hw_value = (_idx), \ |
| 86 | .max_power = 18, /* XXX */ \ |
| 87 | } |
| 88 | |
| 89 | static struct ieee80211_channel ar9170_2ghz_chantable[] = { |
| 90 | CHAN(2412, 0), |
| 91 | CHAN(2417, 1), |
| 92 | CHAN(2422, 2), |
| 93 | CHAN(2427, 3), |
| 94 | CHAN(2432, 4), |
| 95 | CHAN(2437, 5), |
| 96 | CHAN(2442, 6), |
| 97 | CHAN(2447, 7), |
| 98 | CHAN(2452, 8), |
| 99 | CHAN(2457, 9), |
| 100 | CHAN(2462, 10), |
| 101 | CHAN(2467, 11), |
| 102 | CHAN(2472, 12), |
| 103 | CHAN(2484, 13), |
| 104 | }; |
| 105 | |
| 106 | static struct ieee80211_channel ar9170_5ghz_chantable[] = { |
| 107 | CHAN(4920, 14), |
| 108 | CHAN(4940, 15), |
| 109 | CHAN(4960, 16), |
| 110 | CHAN(4980, 17), |
| 111 | CHAN(5040, 18), |
| 112 | CHAN(5060, 19), |
| 113 | CHAN(5080, 20), |
| 114 | CHAN(5180, 21), |
| 115 | CHAN(5200, 22), |
| 116 | CHAN(5220, 23), |
| 117 | CHAN(5240, 24), |
| 118 | CHAN(5260, 25), |
| 119 | CHAN(5280, 26), |
| 120 | CHAN(5300, 27), |
| 121 | CHAN(5320, 28), |
| 122 | CHAN(5500, 29), |
| 123 | CHAN(5520, 30), |
| 124 | CHAN(5540, 31), |
| 125 | CHAN(5560, 32), |
| 126 | CHAN(5580, 33), |
| 127 | CHAN(5600, 34), |
| 128 | CHAN(5620, 35), |
| 129 | CHAN(5640, 36), |
| 130 | CHAN(5660, 37), |
| 131 | CHAN(5680, 38), |
| 132 | CHAN(5700, 39), |
| 133 | CHAN(5745, 40), |
| 134 | CHAN(5765, 41), |
| 135 | CHAN(5785, 42), |
| 136 | CHAN(5805, 43), |
| 137 | CHAN(5825, 44), |
| 138 | CHAN(5170, 45), |
| 139 | CHAN(5190, 46), |
| 140 | CHAN(5210, 47), |
| 141 | CHAN(5230, 48), |
| 142 | }; |
| 143 | #undef CHAN |
| 144 | |
Johannes Berg | 9e52b0623 | 2009-04-20 18:27:04 +0200 | [diff] [blame] | 145 | #define AR9170_HT_CAP \ |
| 146 | { \ |
| 147 | .ht_supported = true, \ |
| 148 | .cap = IEEE80211_HT_CAP_MAX_AMSDU | \ |
| 149 | IEEE80211_HT_CAP_SM_PS | \ |
| 150 | IEEE80211_HT_CAP_SUP_WIDTH_20_40 | \ |
| 151 | IEEE80211_HT_CAP_SGI_40 | \ |
| 152 | IEEE80211_HT_CAP_DSSSCCK40 | \ |
| 153 | IEEE80211_HT_CAP_SM_PS, \ |
Christian Lamparter | 083c468 | 2009-04-24 21:35:57 +0200 | [diff] [blame] | 154 | .ampdu_factor = 3, \ |
| 155 | .ampdu_density = 6, \ |
Johannes Berg | 9e52b0623 | 2009-04-20 18:27:04 +0200 | [diff] [blame] | 156 | .mcs = { \ |
| 157 | .rx_mask = { 0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, }, \ |
| 158 | }, \ |
| 159 | } |
| 160 | |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 161 | static struct ieee80211_supported_band ar9170_band_2GHz = { |
| 162 | .channels = ar9170_2ghz_chantable, |
| 163 | .n_channels = ARRAY_SIZE(ar9170_2ghz_chantable), |
| 164 | .bitrates = ar9170_g_ratetable, |
| 165 | .n_bitrates = ar9170_g_ratetable_size, |
Johannes Berg | 9e52b0623 | 2009-04-20 18:27:04 +0200 | [diff] [blame] | 166 | .ht_cap = AR9170_HT_CAP, |
| 167 | }; |
| 168 | |
| 169 | static struct ieee80211_supported_band ar9170_band_5GHz = { |
| 170 | .channels = ar9170_5ghz_chantable, |
| 171 | .n_channels = ARRAY_SIZE(ar9170_5ghz_chantable), |
| 172 | .bitrates = ar9170_a_ratetable, |
| 173 | .n_bitrates = ar9170_a_ratetable_size, |
| 174 | .ht_cap = AR9170_HT_CAP, |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 175 | }; |
| 176 | |
| 177 | #ifdef AR9170_QUEUE_DEBUG |
| 178 | /* |
| 179 | * In case some wants works with AR9170's crazy tx_status queueing techniques. |
| 180 | * He might need this rather useful probing function. |
| 181 | * |
| 182 | * NOTE: caller must hold the queue's spinlock! |
| 183 | */ |
| 184 | |
| 185 | static void ar9170_print_txheader(struct ar9170 *ar, struct sk_buff *skb) |
| 186 | { |
| 187 | struct ar9170_tx_control *txc = (void *) skb->data; |
| 188 | struct ieee80211_hdr *hdr = (void *)txc->frame_data; |
| 189 | |
| 190 | printk(KERN_DEBUG "%s: => FRAME [skb:%p, queue:%d, DA:[%pM] " |
| 191 | "mac_control:%04x, phy_control:%08x]\n", |
| 192 | wiphy_name(ar->hw->wiphy), skb, skb_get_queue_mapping(skb), |
| 193 | ieee80211_get_DA(hdr), le16_to_cpu(txc->mac_control), |
| 194 | le32_to_cpu(txc->phy_control)); |
| 195 | } |
| 196 | |
| 197 | static void ar9170_dump_station_tx_status_queue(struct ar9170 *ar, |
| 198 | struct sk_buff_head *queue) |
| 199 | { |
| 200 | struct sk_buff *skb; |
| 201 | int i = 0; |
| 202 | |
| 203 | printk(KERN_DEBUG "---[ cut here ]---\n"); |
| 204 | printk(KERN_DEBUG "%s: %d entries in tx_status queue.\n", |
| 205 | wiphy_name(ar->hw->wiphy), skb_queue_len(queue)); |
| 206 | |
| 207 | skb_queue_walk(queue, skb) { |
| 208 | struct ar9170_tx_control *txc = (void *) skb->data; |
| 209 | struct ieee80211_hdr *hdr = (void *)txc->frame_data; |
| 210 | |
| 211 | printk(KERN_DEBUG "index:%d => \n", i); |
| 212 | ar9170_print_txheader(ar, skb); |
| 213 | } |
| 214 | printk(KERN_DEBUG "---[ end ]---\n"); |
| 215 | } |
| 216 | #endif /* AR9170_QUEUE_DEBUG */ |
| 217 | |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 218 | void ar9170_handle_tx_status(struct ar9170 *ar, struct sk_buff *skb, |
| 219 | bool valid_status, u16 tx_status) |
| 220 | { |
| 221 | struct ieee80211_tx_info *txinfo; |
| 222 | unsigned int retries = 0, queue = skb_get_queue_mapping(skb); |
| 223 | unsigned long flags; |
| 224 | |
| 225 | spin_lock_irqsave(&ar->tx_stats_lock, flags); |
| 226 | ar->tx_stats[queue].len--; |
| 227 | if (ieee80211_queue_stopped(ar->hw, queue)) |
| 228 | ieee80211_wake_queue(ar->hw, queue); |
| 229 | spin_unlock_irqrestore(&ar->tx_stats_lock, flags); |
| 230 | |
| 231 | txinfo = IEEE80211_SKB_CB(skb); |
| 232 | ieee80211_tx_info_clear_status(txinfo); |
| 233 | |
| 234 | switch (tx_status) { |
| 235 | case AR9170_TX_STATUS_RETRY: |
| 236 | retries = 2; |
| 237 | case AR9170_TX_STATUS_COMPLETE: |
| 238 | txinfo->flags |= IEEE80211_TX_STAT_ACK; |
| 239 | break; |
| 240 | |
| 241 | case AR9170_TX_STATUS_FAILED: |
| 242 | retries = ar->hw->conf.long_frame_max_tx_count; |
| 243 | break; |
| 244 | |
| 245 | default: |
| 246 | printk(KERN_ERR "%s: invalid tx_status response (%x).\n", |
| 247 | wiphy_name(ar->hw->wiphy), tx_status); |
| 248 | break; |
| 249 | } |
| 250 | |
| 251 | if (valid_status) |
| 252 | txinfo->status.rates[0].count = retries + 1; |
| 253 | |
| 254 | skb_pull(skb, sizeof(struct ar9170_tx_control)); |
| 255 | ieee80211_tx_status_irqsafe(ar->hw, skb); |
| 256 | } |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 257 | |
| 258 | static struct sk_buff *ar9170_find_skb_in_queue(struct ar9170 *ar, |
| 259 | const u8 *mac, |
| 260 | const u32 queue, |
| 261 | struct sk_buff_head *q) |
| 262 | { |
| 263 | unsigned long flags; |
| 264 | struct sk_buff *skb; |
| 265 | |
| 266 | spin_lock_irqsave(&q->lock, flags); |
| 267 | skb_queue_walk(q, skb) { |
| 268 | struct ar9170_tx_control *txc = (void *) skb->data; |
| 269 | struct ieee80211_hdr *hdr = (void *) txc->frame_data; |
| 270 | u32 txc_queue = (le32_to_cpu(txc->phy_control) & |
| 271 | AR9170_TX_PHY_QOS_MASK) >> |
| 272 | AR9170_TX_PHY_QOS_SHIFT; |
| 273 | |
| 274 | if ((queue != txc_queue) || |
| 275 | (compare_ether_addr(ieee80211_get_DA(hdr), mac))) |
| 276 | continue; |
| 277 | |
| 278 | __skb_unlink(skb, q); |
| 279 | spin_unlock_irqrestore(&q->lock, flags); |
| 280 | return skb; |
| 281 | } |
| 282 | spin_unlock_irqrestore(&q->lock, flags); |
| 283 | return NULL; |
| 284 | } |
| 285 | |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 286 | static struct sk_buff *ar9170_find_queued_skb(struct ar9170 *ar, const u8 *mac, |
| 287 | const u32 queue) |
| 288 | { |
| 289 | struct ieee80211_sta *sta; |
| 290 | struct sk_buff *skb; |
| 291 | |
| 292 | /* |
| 293 | * Unfortunately, the firmware does not tell to which (queued) frame |
| 294 | * this transmission status report belongs to. |
| 295 | * |
| 296 | * So we have to make risky guesses - with the scarce information |
| 297 | * the firmware provided (-> destination MAC, and phy_control) - |
| 298 | * and hope that we picked the right one... |
| 299 | */ |
| 300 | rcu_read_lock(); |
| 301 | sta = ieee80211_find_sta(ar->hw, mac); |
| 302 | |
| 303 | if (likely(sta)) { |
| 304 | struct ar9170_sta_info *sta_priv = (void *) sta->drv_priv; |
Christian Lamparter | 4a48e2a | 2009-03-23 12:15:43 +0100 | [diff] [blame] | 305 | skb = skb_dequeue(&sta_priv->tx_status[queue]); |
| 306 | rcu_read_unlock(); |
| 307 | if (likely(skb)) |
| 308 | return skb; |
| 309 | } else |
| 310 | rcu_read_unlock(); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 311 | |
Christian Lamparter | 4a48e2a | 2009-03-23 12:15:43 +0100 | [diff] [blame] | 312 | /* scan the waste queue for candidates */ |
| 313 | skb = ar9170_find_skb_in_queue(ar, mac, queue, |
| 314 | &ar->global_tx_status_waste); |
| 315 | if (!skb) { |
| 316 | /* so it still _must_ be in the global list. */ |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 317 | skb = ar9170_find_skb_in_queue(ar, mac, queue, |
Christian Lamparter | 4a48e2a | 2009-03-23 12:15:43 +0100 | [diff] [blame] | 318 | &ar->global_tx_status); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 319 | } |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 320 | |
| 321 | #ifdef AR9170_QUEUE_DEBUG |
| 322 | if (unlikely((!skb) && net_ratelimit())) { |
| 323 | printk(KERN_ERR "%s: ESS:[%pM] does not have any " |
| 324 | "outstanding frames in this queue (%d).\n", |
| 325 | wiphy_name(ar->hw->wiphy), mac, queue); |
| 326 | } |
| 327 | #endif /* AR9170_QUEUE_DEBUG */ |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 328 | return skb; |
| 329 | } |
| 330 | |
| 331 | /* |
| 332 | * This worker tries to keep the global tx_status queue empty. |
| 333 | * So we can guarantee that incoming tx_status reports for |
| 334 | * unregistered stations are always synced with the actual |
| 335 | * frame - which we think - belongs to. |
| 336 | */ |
| 337 | |
| 338 | static void ar9170_tx_status_janitor(struct work_struct *work) |
| 339 | { |
| 340 | struct ar9170 *ar = container_of(work, struct ar9170, |
Christian Lamparter | 4a48e2a | 2009-03-23 12:15:43 +0100 | [diff] [blame] | 341 | tx_status_janitor.work); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 342 | struct sk_buff *skb; |
| 343 | |
Christian Lamparter | 4a48e2a | 2009-03-23 12:15:43 +0100 | [diff] [blame] | 344 | if (unlikely(!IS_STARTED(ar))) |
| 345 | return ; |
| 346 | |
| 347 | mutex_lock(&ar->mutex); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 348 | /* recycle the garbage back to mac80211... one by one. */ |
| 349 | while ((skb = skb_dequeue(&ar->global_tx_status_waste))) { |
| 350 | #ifdef AR9170_QUEUE_DEBUG |
| 351 | printk(KERN_DEBUG "%s: dispose queued frame =>\n", |
| 352 | wiphy_name(ar->hw->wiphy)); |
| 353 | ar9170_print_txheader(ar, skb); |
| 354 | #endif /* AR9170_QUEUE_DEBUG */ |
| 355 | ar9170_handle_tx_status(ar, skb, false, |
| 356 | AR9170_TX_STATUS_FAILED); |
| 357 | } |
| 358 | |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 359 | while ((skb = skb_dequeue(&ar->global_tx_status))) { |
| 360 | #ifdef AR9170_QUEUE_DEBUG |
| 361 | printk(KERN_DEBUG "%s: moving frame into waste queue =>\n", |
| 362 | wiphy_name(ar->hw->wiphy)); |
| 363 | |
| 364 | ar9170_print_txheader(ar, skb); |
| 365 | #endif /* AR9170_QUEUE_DEBUG */ |
| 366 | skb_queue_tail(&ar->global_tx_status_waste, skb); |
| 367 | } |
| 368 | |
| 369 | /* recall the janitor in 100ms - if there's garbage in the can. */ |
| 370 | if (skb_queue_len(&ar->global_tx_status_waste) > 0) |
| 371 | queue_delayed_work(ar->hw->workqueue, &ar->tx_status_janitor, |
| 372 | msecs_to_jiffies(100)); |
Christian Lamparter | 4a48e2a | 2009-03-23 12:15:43 +0100 | [diff] [blame] | 373 | |
| 374 | mutex_unlock(&ar->mutex); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | static void ar9170_handle_command_response(struct ar9170 *ar, |
| 378 | void *buf, u32 len) |
| 379 | { |
| 380 | struct ar9170_cmd_response *cmd = (void *) buf; |
| 381 | |
| 382 | if ((cmd->type & 0xc0) != 0xc0) { |
| 383 | ar->callback_cmd(ar, len, buf); |
| 384 | return; |
| 385 | } |
| 386 | |
| 387 | /* hardware event handlers */ |
| 388 | switch (cmd->type) { |
| 389 | case 0xc1: { |
| 390 | /* |
| 391 | * TX status notification: |
| 392 | * bytes: 0c c1 XX YY M1 M2 M3 M4 M5 M6 R4 R3 R2 R1 S2 S1 |
| 393 | * |
| 394 | * XX always 81 |
| 395 | * YY always 00 |
| 396 | * M1-M6 is the MAC address |
| 397 | * R1-R4 is the transmit rate |
| 398 | * S1-S2 is the transmit status |
| 399 | */ |
| 400 | |
| 401 | struct sk_buff *skb; |
| 402 | u32 queue = (le32_to_cpu(cmd->tx_status.rate) & |
| 403 | AR9170_TX_PHY_QOS_MASK) >> AR9170_TX_PHY_QOS_SHIFT; |
| 404 | |
| 405 | skb = ar9170_find_queued_skb(ar, cmd->tx_status.dst, queue); |
| 406 | if (unlikely(!skb)) |
| 407 | return ; |
| 408 | |
| 409 | ar9170_handle_tx_status(ar, skb, true, |
| 410 | le16_to_cpu(cmd->tx_status.status)); |
| 411 | break; |
| 412 | } |
| 413 | |
| 414 | case 0xc0: |
| 415 | /* |
| 416 | * pre-TBTT event |
| 417 | */ |
| 418 | if (ar->vif && ar->vif->type == NL80211_IFTYPE_AP) |
| 419 | queue_work(ar->hw->workqueue, &ar->beacon_work); |
| 420 | break; |
| 421 | |
| 422 | case 0xc2: |
| 423 | /* |
| 424 | * (IBSS) beacon send notification |
| 425 | * bytes: 04 c2 XX YY B4 B3 B2 B1 |
| 426 | * |
| 427 | * XX always 80 |
| 428 | * YY always 00 |
| 429 | * B1-B4 "should" be the number of send out beacons. |
| 430 | */ |
| 431 | break; |
| 432 | |
| 433 | case 0xc3: |
| 434 | /* End of Atim Window */ |
| 435 | break; |
| 436 | |
| 437 | case 0xc4: |
| 438 | case 0xc5: |
| 439 | /* BlockACK events */ |
| 440 | break; |
| 441 | |
| 442 | case 0xc6: |
| 443 | /* Watchdog Interrupt */ |
| 444 | break; |
| 445 | |
| 446 | case 0xc9: |
| 447 | /* retransmission issue / SIFS/EIFS collision ?! */ |
| 448 | break; |
| 449 | |
| 450 | default: |
| 451 | printk(KERN_INFO "received unhandled event %x\n", cmd->type); |
| 452 | print_hex_dump_bytes("dump:", DUMP_PREFIX_NONE, buf, len); |
| 453 | break; |
| 454 | } |
| 455 | } |
| 456 | |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 457 | static void ar9170_rx_reset_rx_mpdu(struct ar9170 *ar) |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 458 | { |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 459 | memset(&ar->rx_mpdu.plcp, 0, sizeof(struct ar9170_rx_head)); |
| 460 | ar->rx_mpdu.has_plcp = false; |
| 461 | } |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 462 | |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 463 | static int ar9170_nag_limiter(struct ar9170 *ar) |
| 464 | { |
| 465 | bool print_message; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 466 | |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 467 | /* |
| 468 | * we expect all sorts of errors in promiscuous mode. |
| 469 | * don't bother with it, it's OK! |
| 470 | */ |
| 471 | if (ar->sniffer_enabled) |
| 472 | return false; |
| 473 | |
| 474 | /* |
| 475 | * only go for frequent errors! The hardware tends to |
| 476 | * do some stupid thing once in a while under load, in |
| 477 | * noisy environments or just for fun! |
| 478 | */ |
| 479 | if (time_before(jiffies, ar->bad_hw_nagger) && net_ratelimit()) |
| 480 | print_message = true; |
| 481 | else |
| 482 | print_message = false; |
| 483 | |
| 484 | /* reset threshold for "once in a while" */ |
| 485 | ar->bad_hw_nagger = jiffies + HZ / 4; |
| 486 | return print_message; |
| 487 | } |
| 488 | |
| 489 | static int ar9170_rx_mac_status(struct ar9170 *ar, |
| 490 | struct ar9170_rx_head *head, |
| 491 | struct ar9170_rx_macstatus *mac, |
| 492 | struct ieee80211_rx_status *status) |
| 493 | { |
| 494 | u8 error, decrypt; |
| 495 | |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 496 | BUILD_BUG_ON(sizeof(struct ar9170_rx_head) != 12); |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 497 | BUILD_BUG_ON(sizeof(struct ar9170_rx_macstatus) != 4); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 498 | |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 499 | error = mac->error; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 500 | if (error & AR9170_RX_ERROR_MMIC) { |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 501 | status->flag |= RX_FLAG_MMIC_ERROR; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 502 | error &= ~AR9170_RX_ERROR_MMIC; |
| 503 | } |
| 504 | |
| 505 | if (error & AR9170_RX_ERROR_PLCP) { |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 506 | status->flag |= RX_FLAG_FAILED_PLCP_CRC; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 507 | error &= ~AR9170_RX_ERROR_PLCP; |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 508 | |
| 509 | if (!(ar->filter_state & FIF_PLCPFAIL)) |
| 510 | return -EINVAL; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | if (error & AR9170_RX_ERROR_FCS) { |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 514 | status->flag |= RX_FLAG_FAILED_FCS_CRC; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 515 | error &= ~AR9170_RX_ERROR_FCS; |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 516 | |
| 517 | if (!(ar->filter_state & FIF_FCSFAIL)) |
| 518 | return -EINVAL; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 519 | } |
| 520 | |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 521 | decrypt = ar9170_get_decrypt_type(mac); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 522 | if (!(decrypt & AR9170_RX_ENC_SOFTWARE) && |
| 523 | decrypt != AR9170_ENC_ALG_NONE) |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 524 | status->flag |= RX_FLAG_DECRYPTED; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 525 | |
| 526 | /* ignore wrong RA errors */ |
| 527 | error &= ~AR9170_RX_ERROR_WRONG_RA; |
| 528 | |
| 529 | if (error & AR9170_RX_ERROR_DECRYPT) { |
| 530 | error &= ~AR9170_RX_ERROR_DECRYPT; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 531 | /* |
| 532 | * Rx decryption is done in place, |
| 533 | * the original data is lost anyway. |
| 534 | */ |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 535 | |
| 536 | return -EINVAL; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | /* drop any other error frames */ |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 540 | if (unlikely(error)) { |
| 541 | /* TODO: update netdevice's RX dropped/errors statistics */ |
| 542 | |
| 543 | if (ar9170_nag_limiter(ar)) |
| 544 | printk(KERN_DEBUG "%s: received frame with " |
| 545 | "suspicious error code (%#x).\n", |
| 546 | wiphy_name(ar->hw->wiphy), error); |
| 547 | |
| 548 | return -EINVAL; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 549 | } |
| 550 | |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 551 | status->band = ar->channel->band; |
| 552 | status->freq = ar->channel->center_freq; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 553 | |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 554 | switch (mac->status & AR9170_RX_STATUS_MODULATION_MASK) { |
| 555 | case AR9170_RX_STATUS_MODULATION_CCK: |
| 556 | if (mac->status & AR9170_RX_STATUS_SHORT_PREAMBLE) |
| 557 | status->flag |= RX_FLAG_SHORTPRE; |
| 558 | switch (head->plcp[0]) { |
| 559 | case 0x0a: |
| 560 | status->rate_idx = 0; |
| 561 | break; |
| 562 | case 0x14: |
| 563 | status->rate_idx = 1; |
| 564 | break; |
| 565 | case 0x37: |
| 566 | status->rate_idx = 2; |
| 567 | break; |
| 568 | case 0x6e: |
| 569 | status->rate_idx = 3; |
| 570 | break; |
| 571 | default: |
| 572 | if (ar9170_nag_limiter(ar)) |
| 573 | printk(KERN_ERR "%s: invalid plcp cck rate " |
| 574 | "(%x).\n", wiphy_name(ar->hw->wiphy), |
| 575 | head->plcp[0]); |
| 576 | return -EINVAL; |
| 577 | } |
| 578 | break; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 579 | |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 580 | case AR9170_RX_STATUS_MODULATION_OFDM: |
| 581 | switch (head->plcp[0] & 0xf) { |
| 582 | case 0xb: |
| 583 | status->rate_idx = 0; |
| 584 | break; |
| 585 | case 0xf: |
| 586 | status->rate_idx = 1; |
| 587 | break; |
| 588 | case 0xa: |
| 589 | status->rate_idx = 2; |
| 590 | break; |
| 591 | case 0xe: |
| 592 | status->rate_idx = 3; |
| 593 | break; |
| 594 | case 0x9: |
| 595 | status->rate_idx = 4; |
| 596 | break; |
| 597 | case 0xd: |
| 598 | status->rate_idx = 5; |
| 599 | break; |
| 600 | case 0x8: |
| 601 | status->rate_idx = 6; |
| 602 | break; |
| 603 | case 0xc: |
| 604 | status->rate_idx = 7; |
| 605 | break; |
| 606 | default: |
| 607 | if (ar9170_nag_limiter(ar)) |
| 608 | printk(KERN_ERR "%s: invalid plcp ofdm rate " |
| 609 | "(%x).\n", wiphy_name(ar->hw->wiphy), |
| 610 | head->plcp[0]); |
| 611 | return -EINVAL; |
| 612 | } |
| 613 | if (status->band == IEEE80211_BAND_2GHZ) |
| 614 | status->rate_idx += 4; |
| 615 | break; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 616 | |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 617 | case AR9170_RX_STATUS_MODULATION_HT: |
| 618 | if (head->plcp[3] & 0x80) |
| 619 | status->flag |= RX_FLAG_40MHZ; |
| 620 | if (head->plcp[6] & 0x80) |
| 621 | status->flag |= RX_FLAG_SHORT_GI; |
| 622 | |
| 623 | status->rate_idx = clamp(0, 75, head->plcp[6] & 0x7f); |
| 624 | status->flag |= RX_FLAG_HT; |
| 625 | break; |
| 626 | |
| 627 | case AR9170_RX_STATUS_MODULATION_DUPOFDM: |
| 628 | /* XXX */ |
| 629 | if (ar9170_nag_limiter(ar)) |
| 630 | printk(KERN_ERR "%s: invalid modulation\n", |
| 631 | wiphy_name(ar->hw->wiphy)); |
| 632 | return -EINVAL; |
| 633 | } |
| 634 | |
| 635 | return 0; |
| 636 | } |
| 637 | |
| 638 | static void ar9170_rx_phy_status(struct ar9170 *ar, |
| 639 | struct ar9170_rx_phystatus *phy, |
| 640 | struct ieee80211_rx_status *status) |
| 641 | { |
| 642 | int i; |
| 643 | |
| 644 | BUILD_BUG_ON(sizeof(struct ar9170_rx_phystatus) != 20); |
| 645 | |
| 646 | for (i = 0; i < 3; i++) |
| 647 | if (phy->rssi[i] != 0x80) |
| 648 | status->antenna |= BIT(i); |
| 649 | |
| 650 | /* post-process RSSI */ |
| 651 | for (i = 0; i < 7; i++) |
| 652 | if (phy->rssi[i] & 0x80) |
| 653 | phy->rssi[i] = ((phy->rssi[i] & 0x7f) + 1) & 0x7f; |
| 654 | |
| 655 | /* TODO: we could do something with phy_errors */ |
| 656 | status->signal = ar->noise[0] + phy->rssi_combined; |
| 657 | status->noise = ar->noise[0]; |
| 658 | } |
| 659 | |
| 660 | static struct sk_buff *ar9170_rx_copy_data(u8 *buf, int len) |
| 661 | { |
| 662 | struct sk_buff *skb; |
| 663 | int reserved = 0; |
| 664 | struct ieee80211_hdr *hdr = (void *) buf; |
| 665 | |
| 666 | if (ieee80211_is_data_qos(hdr->frame_control)) { |
| 667 | u8 *qc = ieee80211_get_qos_ctl(hdr); |
| 668 | reserved += NET_IP_ALIGN; |
| 669 | |
| 670 | if (*qc & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT) |
| 671 | reserved += NET_IP_ALIGN; |
| 672 | } |
| 673 | |
| 674 | if (ieee80211_has_a4(hdr->frame_control)) |
| 675 | reserved += NET_IP_ALIGN; |
| 676 | |
| 677 | reserved = 32 + (reserved & NET_IP_ALIGN); |
| 678 | |
| 679 | skb = dev_alloc_skb(len + reserved); |
| 680 | if (likely(skb)) { |
| 681 | skb_reserve(skb, reserved); |
| 682 | memcpy(skb_put(skb, len), buf, len); |
| 683 | } |
| 684 | |
| 685 | return skb; |
| 686 | } |
| 687 | |
| 688 | /* |
| 689 | * If the frame alignment is right (or the kernel has |
| 690 | * CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS), and there |
| 691 | * is only a single MPDU in the USB frame, then we could |
| 692 | * submit to mac80211 the SKB directly. However, since |
| 693 | * there may be multiple packets in one SKB in stream |
| 694 | * mode, and we need to observe the proper ordering, |
| 695 | * this is non-trivial. |
| 696 | */ |
| 697 | |
| 698 | static void ar9170_handle_mpdu(struct ar9170 *ar, u8 *buf, int len) |
| 699 | { |
| 700 | struct ar9170_rx_head *head; |
| 701 | struct ar9170_rx_macstatus *mac; |
| 702 | struct ar9170_rx_phystatus *phy = NULL; |
| 703 | struct ieee80211_rx_status status; |
| 704 | struct sk_buff *skb; |
| 705 | int mpdu_len; |
| 706 | |
| 707 | if (unlikely(!IS_STARTED(ar) || len < (sizeof(*mac)))) |
| 708 | return ; |
| 709 | |
| 710 | /* Received MPDU */ |
| 711 | mpdu_len = len - sizeof(*mac); |
| 712 | |
| 713 | mac = (void *)(buf + mpdu_len); |
| 714 | if (unlikely(mac->error & AR9170_RX_ERROR_FATAL)) { |
| 715 | /* this frame is too damaged and can't be used - drop it */ |
| 716 | |
| 717 | return ; |
| 718 | } |
| 719 | |
| 720 | switch (mac->status & AR9170_RX_STATUS_MPDU_MASK) { |
| 721 | case AR9170_RX_STATUS_MPDU_FIRST: |
| 722 | /* first mpdu packet has the plcp header */ |
| 723 | if (likely(mpdu_len >= sizeof(struct ar9170_rx_head))) { |
| 724 | head = (void *) buf; |
| 725 | memcpy(&ar->rx_mpdu.plcp, (void *) buf, |
| 726 | sizeof(struct ar9170_rx_head)); |
| 727 | |
| 728 | mpdu_len -= sizeof(struct ar9170_rx_head); |
| 729 | buf += sizeof(struct ar9170_rx_head); |
| 730 | ar->rx_mpdu.has_plcp = true; |
| 731 | } else { |
| 732 | if (ar9170_nag_limiter(ar)) |
| 733 | printk(KERN_ERR "%s: plcp info is clipped.\n", |
| 734 | wiphy_name(ar->hw->wiphy)); |
| 735 | return ; |
| 736 | } |
| 737 | break; |
| 738 | |
| 739 | case AR9170_RX_STATUS_MPDU_LAST: |
| 740 | /* last mpdu has a extra tail with phy status information */ |
| 741 | |
| 742 | if (likely(mpdu_len >= sizeof(struct ar9170_rx_phystatus))) { |
| 743 | mpdu_len -= sizeof(struct ar9170_rx_phystatus); |
| 744 | phy = (void *)(buf + mpdu_len); |
| 745 | } else { |
| 746 | if (ar9170_nag_limiter(ar)) |
| 747 | printk(KERN_ERR "%s: frame tail is clipped.\n", |
| 748 | wiphy_name(ar->hw->wiphy)); |
| 749 | return ; |
| 750 | } |
| 751 | |
| 752 | case AR9170_RX_STATUS_MPDU_MIDDLE: |
| 753 | /* middle mpdus are just data */ |
| 754 | if (unlikely(!ar->rx_mpdu.has_plcp)) { |
| 755 | if (!ar9170_nag_limiter(ar)) |
| 756 | return ; |
| 757 | |
| 758 | printk(KERN_ERR "%s: rx stream did not start " |
| 759 | "with a first_mpdu frame tag.\n", |
| 760 | wiphy_name(ar->hw->wiphy)); |
| 761 | |
| 762 | return ; |
| 763 | } |
| 764 | |
| 765 | head = &ar->rx_mpdu.plcp; |
| 766 | break; |
| 767 | |
| 768 | case AR9170_RX_STATUS_MPDU_SINGLE: |
| 769 | /* single mpdu - has plcp (head) and phy status (tail) */ |
| 770 | head = (void *) buf; |
| 771 | |
| 772 | mpdu_len -= sizeof(struct ar9170_rx_head); |
| 773 | mpdu_len -= sizeof(struct ar9170_rx_phystatus); |
| 774 | |
| 775 | buf += sizeof(struct ar9170_rx_head); |
| 776 | phy = (void *)(buf + mpdu_len); |
| 777 | break; |
| 778 | |
| 779 | default: |
| 780 | BUG_ON(1); |
| 781 | break; |
| 782 | } |
| 783 | |
| 784 | if (unlikely(mpdu_len < FCS_LEN)) |
| 785 | return ; |
| 786 | |
| 787 | memset(&status, 0, sizeof(status)); |
| 788 | if (unlikely(ar9170_rx_mac_status(ar, head, mac, &status))) |
| 789 | return ; |
| 790 | |
| 791 | if (phy) |
| 792 | ar9170_rx_phy_status(ar, phy, &status); |
| 793 | |
| 794 | skb = ar9170_rx_copy_data(buf, mpdu_len); |
| 795 | if (likely(skb)) |
| 796 | ieee80211_rx_irqsafe(ar->hw, skb, &status); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 797 | } |
| 798 | |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 799 | void ar9170_rx(struct ar9170 *ar, struct sk_buff *skb) |
| 800 | { |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 801 | unsigned int i, tlen, resplen, wlen = 0, clen = 0; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 802 | u8 *tbuf, *respbuf; |
| 803 | |
| 804 | tbuf = skb->data; |
| 805 | tlen = skb->len; |
| 806 | |
| 807 | while (tlen >= 4) { |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 808 | clen = tbuf[1] << 8 | tbuf[0]; |
| 809 | wlen = ALIGN(clen, 4); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 810 | |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 811 | /* check if this is stream has a valid tag.*/ |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 812 | if (tbuf[2] != 0 || tbuf[3] != 0x4e) { |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 813 | /* |
| 814 | * TODO: handle the highly unlikely event that the |
| 815 | * corrupted stream has the TAG at the right position. |
| 816 | */ |
| 817 | |
| 818 | /* check if the frame can be repaired. */ |
| 819 | if (!ar->rx_failover_missing) { |
| 820 | /* this is no "short read". */ |
| 821 | if (ar9170_nag_limiter(ar)) { |
| 822 | printk(KERN_ERR "%s: missing tag!\n", |
| 823 | wiphy_name(ar->hw->wiphy)); |
| 824 | goto err_telluser; |
| 825 | } else |
| 826 | goto err_silent; |
| 827 | } |
| 828 | |
| 829 | if (ar->rx_failover_missing > tlen) { |
| 830 | if (ar9170_nag_limiter(ar)) { |
| 831 | printk(KERN_ERR "%s: possible multi " |
| 832 | "stream corruption!\n", |
| 833 | wiphy_name(ar->hw->wiphy)); |
| 834 | goto err_telluser; |
| 835 | } else |
| 836 | goto err_silent; |
| 837 | } |
| 838 | |
| 839 | memcpy(skb_put(ar->rx_failover, tlen), tbuf, tlen); |
| 840 | ar->rx_failover_missing -= tlen; |
| 841 | |
| 842 | if (ar->rx_failover_missing <= 0) { |
| 843 | /* |
| 844 | * nested ar9170_rx call! |
| 845 | * termination is guranteed, even when the |
| 846 | * combined frame also have a element with |
| 847 | * a bad tag. |
| 848 | */ |
| 849 | |
| 850 | ar->rx_failover_missing = 0; |
| 851 | ar9170_rx(ar, ar->rx_failover); |
| 852 | |
| 853 | skb_reset_tail_pointer(ar->rx_failover); |
| 854 | skb_trim(ar->rx_failover, 0); |
| 855 | } |
| 856 | |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 857 | return ; |
| 858 | } |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 859 | |
| 860 | /* check if stream is clipped */ |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 861 | if (wlen > tlen - 4) { |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 862 | if (ar->rx_failover_missing) { |
| 863 | /* TODO: handle double stream corruption. */ |
| 864 | if (ar9170_nag_limiter(ar)) { |
| 865 | printk(KERN_ERR "%s: double rx stream " |
| 866 | "corruption!\n", |
| 867 | wiphy_name(ar->hw->wiphy)); |
| 868 | goto err_telluser; |
| 869 | } else |
| 870 | goto err_silent; |
| 871 | } |
| 872 | |
| 873 | /* |
| 874 | * save incomplete data set. |
| 875 | * the firmware will resend the missing bits when |
| 876 | * the rx - descriptor comes round again. |
| 877 | */ |
| 878 | |
| 879 | memcpy(skb_put(ar->rx_failover, tlen), tbuf, tlen); |
| 880 | ar->rx_failover_missing = clen - tlen; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 881 | return ; |
| 882 | } |
| 883 | resplen = clen; |
| 884 | respbuf = tbuf + 4; |
| 885 | tbuf += wlen + 4; |
| 886 | tlen -= wlen + 4; |
| 887 | |
| 888 | i = 0; |
| 889 | |
| 890 | /* weird thing, but this is the same in the original driver */ |
| 891 | while (resplen > 2 && i < 12 && |
| 892 | respbuf[0] == 0xff && respbuf[1] == 0xff) { |
| 893 | i += 2; |
| 894 | resplen -= 2; |
| 895 | respbuf += 2; |
| 896 | } |
| 897 | |
| 898 | if (resplen < 4) |
| 899 | continue; |
| 900 | |
| 901 | /* found the 6 * 0xffff marker? */ |
| 902 | if (i == 12) |
| 903 | ar9170_handle_command_response(ar, respbuf, resplen); |
| 904 | else |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 905 | ar9170_handle_mpdu(ar, respbuf, clen); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 906 | } |
| 907 | |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 908 | if (tlen) { |
| 909 | if (net_ratelimit()) |
| 910 | printk(KERN_ERR "%s: %d bytes of unprocessed " |
| 911 | "data left in rx stream!\n", |
| 912 | wiphy_name(ar->hw->wiphy), tlen); |
| 913 | |
| 914 | goto err_telluser; |
| 915 | } |
| 916 | |
| 917 | return ; |
| 918 | |
| 919 | err_telluser: |
| 920 | printk(KERN_ERR "%s: damaged RX stream data [want:%d, " |
| 921 | "data:%d, rx:%d, pending:%d ]\n", |
| 922 | wiphy_name(ar->hw->wiphy), clen, wlen, tlen, |
| 923 | ar->rx_failover_missing); |
| 924 | |
| 925 | if (ar->rx_failover_missing) |
| 926 | print_hex_dump_bytes("rxbuf:", DUMP_PREFIX_OFFSET, |
| 927 | ar->rx_failover->data, |
| 928 | ar->rx_failover->len); |
| 929 | |
| 930 | print_hex_dump_bytes("stream:", DUMP_PREFIX_OFFSET, |
| 931 | skb->data, skb->len); |
| 932 | |
| 933 | printk(KERN_ERR "%s: please check your hardware and cables, if " |
| 934 | "you see this message frequently.\n", |
| 935 | wiphy_name(ar->hw->wiphy)); |
| 936 | |
| 937 | err_silent: |
| 938 | if (ar->rx_failover_missing) { |
| 939 | skb_reset_tail_pointer(ar->rx_failover); |
| 940 | skb_trim(ar->rx_failover, 0); |
| 941 | ar->rx_failover_missing = 0; |
| 942 | } |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 943 | } |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 944 | |
| 945 | #define AR9170_FILL_QUEUE(queue, ai_fs, cwmin, cwmax, _txop) \ |
| 946 | do { \ |
| 947 | queue.aifs = ai_fs; \ |
| 948 | queue.cw_min = cwmin; \ |
| 949 | queue.cw_max = cwmax; \ |
| 950 | queue.txop = _txop; \ |
| 951 | } while (0) |
| 952 | |
| 953 | static int ar9170_op_start(struct ieee80211_hw *hw) |
| 954 | { |
| 955 | struct ar9170 *ar = hw->priv; |
| 956 | int err, i; |
| 957 | |
| 958 | mutex_lock(&ar->mutex); |
| 959 | |
Christian Lamparter | 864cc02 | 2009-05-23 20:28:21 +0200 | [diff] [blame^] | 960 | ar->filter_changed = 0; |
| 961 | |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 962 | /* reinitialize queues statistics */ |
| 963 | memset(&ar->tx_stats, 0, sizeof(ar->tx_stats)); |
| 964 | for (i = 0; i < ARRAY_SIZE(ar->tx_stats); i++) |
| 965 | ar->tx_stats[i].limit = 8; |
| 966 | |
| 967 | /* reset QoS defaults */ |
| 968 | AR9170_FILL_QUEUE(ar->edcf[0], 3, 15, 1023, 0); /* BEST EFFORT*/ |
| 969 | AR9170_FILL_QUEUE(ar->edcf[1], 7, 15, 1023, 0); /* BACKGROUND */ |
| 970 | AR9170_FILL_QUEUE(ar->edcf[2], 2, 7, 15, 94); /* VIDEO */ |
| 971 | AR9170_FILL_QUEUE(ar->edcf[3], 2, 3, 7, 47); /* VOICE */ |
| 972 | AR9170_FILL_QUEUE(ar->edcf[4], 2, 3, 7, 0); /* SPECIAL */ |
| 973 | |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 974 | ar->bad_hw_nagger = jiffies; |
| 975 | |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 976 | err = ar->open(ar); |
| 977 | if (err) |
| 978 | goto out; |
| 979 | |
| 980 | err = ar9170_init_mac(ar); |
| 981 | if (err) |
| 982 | goto out; |
| 983 | |
| 984 | err = ar9170_set_qos(ar); |
| 985 | if (err) |
| 986 | goto out; |
| 987 | |
| 988 | err = ar9170_init_phy(ar, IEEE80211_BAND_2GHZ); |
| 989 | if (err) |
| 990 | goto out; |
| 991 | |
| 992 | err = ar9170_init_rf(ar); |
| 993 | if (err) |
| 994 | goto out; |
| 995 | |
| 996 | /* start DMA */ |
| 997 | err = ar9170_write_reg(ar, 0x1c3d30, 0x100); |
| 998 | if (err) |
| 999 | goto out; |
| 1000 | |
| 1001 | ar->state = AR9170_STARTED; |
| 1002 | |
| 1003 | out: |
| 1004 | mutex_unlock(&ar->mutex); |
| 1005 | return err; |
| 1006 | } |
| 1007 | |
| 1008 | static void ar9170_op_stop(struct ieee80211_hw *hw) |
| 1009 | { |
| 1010 | struct ar9170 *ar = hw->priv; |
| 1011 | |
| 1012 | if (IS_STARTED(ar)) |
| 1013 | ar->state = AR9170_IDLE; |
| 1014 | |
Christian Lamparter | 32c1628 | 2009-03-28 01:46:14 +0100 | [diff] [blame] | 1015 | flush_workqueue(ar->hw->workqueue); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1016 | |
Christian Lamparter | 32c1628 | 2009-03-28 01:46:14 +0100 | [diff] [blame] | 1017 | mutex_lock(&ar->mutex); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1018 | cancel_delayed_work_sync(&ar->tx_status_janitor); |
| 1019 | cancel_work_sync(&ar->filter_config_work); |
| 1020 | cancel_work_sync(&ar->beacon_work); |
| 1021 | skb_queue_purge(&ar->global_tx_status_waste); |
| 1022 | skb_queue_purge(&ar->global_tx_status); |
| 1023 | |
| 1024 | if (IS_ACCEPTING_CMD(ar)) { |
| 1025 | ar9170_set_leds_state(ar, 0); |
| 1026 | |
| 1027 | /* stop DMA */ |
| 1028 | ar9170_write_reg(ar, 0x1c3d30, 0); |
| 1029 | ar->stop(ar); |
| 1030 | } |
| 1031 | |
| 1032 | mutex_unlock(&ar->mutex); |
| 1033 | } |
| 1034 | |
| 1035 | int ar9170_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb) |
| 1036 | { |
| 1037 | struct ar9170 *ar = hw->priv; |
| 1038 | struct ieee80211_hdr *hdr; |
| 1039 | struct ar9170_tx_control *txc; |
| 1040 | struct ieee80211_tx_info *info; |
| 1041 | struct ieee80211_rate *rate = NULL; |
| 1042 | struct ieee80211_tx_rate *txrate; |
| 1043 | unsigned int queue = skb_get_queue_mapping(skb); |
| 1044 | unsigned long flags = 0; |
| 1045 | struct ar9170_sta_info *sta_info = NULL; |
| 1046 | u32 power, chains; |
| 1047 | u16 keytype = 0; |
| 1048 | u16 len, icv = 0; |
| 1049 | int err; |
| 1050 | bool tx_status; |
| 1051 | |
| 1052 | if (unlikely(!IS_STARTED(ar))) |
| 1053 | goto err_free; |
| 1054 | |
| 1055 | hdr = (void *)skb->data; |
| 1056 | info = IEEE80211_SKB_CB(skb); |
| 1057 | len = skb->len; |
| 1058 | |
| 1059 | spin_lock_irqsave(&ar->tx_stats_lock, flags); |
| 1060 | if (ar->tx_stats[queue].limit < ar->tx_stats[queue].len) { |
| 1061 | spin_unlock_irqrestore(&ar->tx_stats_lock, flags); |
| 1062 | return NETDEV_TX_OK; |
| 1063 | } |
| 1064 | |
| 1065 | ar->tx_stats[queue].len++; |
| 1066 | ar->tx_stats[queue].count++; |
| 1067 | if (ar->tx_stats[queue].limit == ar->tx_stats[queue].len) |
| 1068 | ieee80211_stop_queue(hw, queue); |
| 1069 | |
| 1070 | spin_unlock_irqrestore(&ar->tx_stats_lock, flags); |
| 1071 | |
| 1072 | txc = (void *)skb_push(skb, sizeof(*txc)); |
| 1073 | |
| 1074 | tx_status = (((info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE) != 0) || |
| 1075 | ((info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS) != 0)); |
| 1076 | |
| 1077 | if (info->control.hw_key) { |
| 1078 | icv = info->control.hw_key->icv_len; |
| 1079 | |
| 1080 | switch (info->control.hw_key->alg) { |
| 1081 | case ALG_WEP: |
| 1082 | keytype = AR9170_TX_MAC_ENCR_RC4; |
| 1083 | break; |
| 1084 | case ALG_TKIP: |
| 1085 | keytype = AR9170_TX_MAC_ENCR_RC4; |
| 1086 | break; |
| 1087 | case ALG_CCMP: |
| 1088 | keytype = AR9170_TX_MAC_ENCR_AES; |
| 1089 | break; |
| 1090 | default: |
| 1091 | WARN_ON(1); |
| 1092 | goto err_dequeue; |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | /* Length */ |
| 1097 | txc->length = cpu_to_le16(len + icv + 4); |
| 1098 | |
| 1099 | txc->mac_control = cpu_to_le16(AR9170_TX_MAC_HW_DURATION | |
| 1100 | AR9170_TX_MAC_BACKOFF); |
| 1101 | txc->mac_control |= cpu_to_le16(ar9170_qos_hwmap[queue] << |
| 1102 | AR9170_TX_MAC_QOS_SHIFT); |
| 1103 | txc->mac_control |= cpu_to_le16(keytype); |
| 1104 | txc->phy_control = cpu_to_le32(0); |
| 1105 | |
| 1106 | if (info->flags & IEEE80211_TX_CTL_NO_ACK) |
| 1107 | txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_NO_ACK); |
| 1108 | |
| 1109 | if (info->flags & IEEE80211_TX_CTL_AMPDU) |
| 1110 | txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_AGGR); |
| 1111 | |
| 1112 | txrate = &info->control.rates[0]; |
| 1113 | |
| 1114 | if (txrate->flags & IEEE80211_TX_RC_USE_CTS_PROTECT) |
| 1115 | txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_PROT_CTS); |
| 1116 | else if (txrate->flags & IEEE80211_TX_RC_USE_RTS_CTS) |
| 1117 | txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_PROT_RTS); |
| 1118 | |
| 1119 | if (txrate->flags & IEEE80211_TX_RC_GREEN_FIELD) |
| 1120 | txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_GREENFIELD); |
| 1121 | |
| 1122 | if (txrate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) |
| 1123 | txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_SHORT_PREAMBLE); |
| 1124 | |
| 1125 | if (txrate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) |
| 1126 | txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_BW_40MHZ); |
| 1127 | /* this works because 40 MHz is 2 and dup is 3 */ |
| 1128 | if (txrate->flags & IEEE80211_TX_RC_DUP_DATA) |
| 1129 | txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_BW_40MHZ_DUP); |
| 1130 | |
| 1131 | if (txrate->flags & IEEE80211_TX_RC_SHORT_GI) |
| 1132 | txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_SHORT_GI); |
| 1133 | |
| 1134 | if (txrate->flags & IEEE80211_TX_RC_MCS) { |
| 1135 | u32 r = txrate->idx; |
| 1136 | u8 *txpower; |
| 1137 | |
| 1138 | r <<= AR9170_TX_PHY_MCS_SHIFT; |
| 1139 | if (WARN_ON(r & ~AR9170_TX_PHY_MCS_MASK)) |
| 1140 | goto err_dequeue; |
| 1141 | txc->phy_control |= cpu_to_le32(r & AR9170_TX_PHY_MCS_MASK); |
| 1142 | txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_MOD_HT); |
| 1143 | |
| 1144 | if (txrate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) { |
| 1145 | if (info->band == IEEE80211_BAND_5GHZ) |
| 1146 | txpower = ar->power_5G_ht40; |
| 1147 | else |
| 1148 | txpower = ar->power_2G_ht40; |
| 1149 | } else { |
| 1150 | if (info->band == IEEE80211_BAND_5GHZ) |
| 1151 | txpower = ar->power_5G_ht20; |
| 1152 | else |
| 1153 | txpower = ar->power_2G_ht20; |
| 1154 | } |
| 1155 | |
| 1156 | power = txpower[(txrate->idx) & 7]; |
| 1157 | } else { |
| 1158 | u8 *txpower; |
| 1159 | u32 mod; |
| 1160 | u32 phyrate; |
| 1161 | u8 idx = txrate->idx; |
| 1162 | |
| 1163 | if (info->band != IEEE80211_BAND_2GHZ) { |
| 1164 | idx += 4; |
| 1165 | txpower = ar->power_5G_leg; |
| 1166 | mod = AR9170_TX_PHY_MOD_OFDM; |
| 1167 | } else { |
| 1168 | if (idx < 4) { |
| 1169 | txpower = ar->power_2G_cck; |
| 1170 | mod = AR9170_TX_PHY_MOD_CCK; |
| 1171 | } else { |
| 1172 | mod = AR9170_TX_PHY_MOD_OFDM; |
| 1173 | txpower = ar->power_2G_ofdm; |
| 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | rate = &__ar9170_ratetable[idx]; |
| 1178 | |
| 1179 | phyrate = rate->hw_value & 0xF; |
| 1180 | power = txpower[(rate->hw_value & 0x30) >> 4]; |
| 1181 | phyrate <<= AR9170_TX_PHY_MCS_SHIFT; |
| 1182 | |
| 1183 | txc->phy_control |= cpu_to_le32(mod); |
| 1184 | txc->phy_control |= cpu_to_le32(phyrate); |
| 1185 | } |
| 1186 | |
| 1187 | power <<= AR9170_TX_PHY_TX_PWR_SHIFT; |
| 1188 | power &= AR9170_TX_PHY_TX_PWR_MASK; |
| 1189 | txc->phy_control |= cpu_to_le32(power); |
| 1190 | |
| 1191 | /* set TX chains */ |
| 1192 | if (ar->eeprom.tx_mask == 1) { |
| 1193 | chains = AR9170_TX_PHY_TXCHAIN_1; |
| 1194 | } else { |
| 1195 | chains = AR9170_TX_PHY_TXCHAIN_2; |
| 1196 | |
| 1197 | /* >= 36M legacy OFDM - use only one chain */ |
| 1198 | if (rate && rate->bitrate >= 360) |
| 1199 | chains = AR9170_TX_PHY_TXCHAIN_1; |
| 1200 | } |
| 1201 | txc->phy_control |= cpu_to_le32(chains << AR9170_TX_PHY_TXCHAIN_SHIFT); |
| 1202 | |
| 1203 | if (tx_status) { |
| 1204 | txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_RATE_PROBE); |
| 1205 | /* |
| 1206 | * WARNING: |
| 1207 | * Putting the QoS queue bits into an unexplored territory is |
| 1208 | * certainly not elegant. |
| 1209 | * |
| 1210 | * In my defense: This idea provides a reasonable way to |
| 1211 | * smuggle valuable information to the tx_status callback. |
| 1212 | * Also, the idea behind this bit-abuse came straight from |
| 1213 | * the original driver code. |
| 1214 | */ |
| 1215 | |
| 1216 | txc->phy_control |= |
| 1217 | cpu_to_le32(queue << AR9170_TX_PHY_QOS_SHIFT); |
| 1218 | |
| 1219 | if (info->control.sta) { |
| 1220 | sta_info = (void *) info->control.sta->drv_priv; |
Christian Lamparter | 4a48e2a | 2009-03-23 12:15:43 +0100 | [diff] [blame] | 1221 | skb_queue_tail(&sta_info->tx_status[queue], skb); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1222 | } else { |
| 1223 | skb_queue_tail(&ar->global_tx_status, skb); |
| 1224 | |
| 1225 | queue_delayed_work(ar->hw->workqueue, |
| 1226 | &ar->tx_status_janitor, |
| 1227 | msecs_to_jiffies(100)); |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | err = ar->tx(ar, skb, tx_status, 0); |
| 1232 | if (unlikely(tx_status && err)) { |
| 1233 | if (info->control.sta) |
Christian Lamparter | 4a48e2a | 2009-03-23 12:15:43 +0100 | [diff] [blame] | 1234 | skb_unlink(skb, &sta_info->tx_status[queue]); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1235 | else |
| 1236 | skb_unlink(skb, &ar->global_tx_status); |
| 1237 | } |
| 1238 | |
| 1239 | return NETDEV_TX_OK; |
| 1240 | |
| 1241 | err_dequeue: |
| 1242 | spin_lock_irqsave(&ar->tx_stats_lock, flags); |
| 1243 | ar->tx_stats[queue].len--; |
| 1244 | ar->tx_stats[queue].count--; |
| 1245 | spin_unlock_irqrestore(&ar->tx_stats_lock, flags); |
| 1246 | |
| 1247 | err_free: |
| 1248 | dev_kfree_skb(skb); |
| 1249 | return NETDEV_TX_OK; |
| 1250 | } |
| 1251 | |
| 1252 | static int ar9170_op_add_interface(struct ieee80211_hw *hw, |
| 1253 | struct ieee80211_if_init_conf *conf) |
| 1254 | { |
| 1255 | struct ar9170 *ar = hw->priv; |
| 1256 | int err = 0; |
| 1257 | |
| 1258 | mutex_lock(&ar->mutex); |
| 1259 | |
| 1260 | if (ar->vif) { |
| 1261 | err = -EBUSY; |
| 1262 | goto unlock; |
| 1263 | } |
| 1264 | |
| 1265 | ar->vif = conf->vif; |
| 1266 | memcpy(ar->mac_addr, conf->mac_addr, ETH_ALEN); |
| 1267 | |
| 1268 | if (modparam_nohwcrypt || (ar->vif->type != NL80211_IFTYPE_STATION)) { |
| 1269 | ar->rx_software_decryption = true; |
| 1270 | ar->disable_offload = true; |
| 1271 | } |
| 1272 | |
| 1273 | ar->cur_filter = 0; |
| 1274 | ar->want_filter = AR9170_MAC_REG_FTF_DEFAULTS; |
| 1275 | err = ar9170_update_frame_filter(ar); |
| 1276 | if (err) |
| 1277 | goto unlock; |
| 1278 | |
| 1279 | err = ar9170_set_operating_mode(ar); |
| 1280 | |
| 1281 | unlock: |
| 1282 | mutex_unlock(&ar->mutex); |
| 1283 | return err; |
| 1284 | } |
| 1285 | |
| 1286 | static void ar9170_op_remove_interface(struct ieee80211_hw *hw, |
| 1287 | struct ieee80211_if_init_conf *conf) |
| 1288 | { |
| 1289 | struct ar9170 *ar = hw->priv; |
| 1290 | |
| 1291 | mutex_lock(&ar->mutex); |
| 1292 | ar->vif = NULL; |
| 1293 | ar->want_filter = 0; |
| 1294 | ar9170_update_frame_filter(ar); |
| 1295 | ar9170_set_beacon_timers(ar); |
| 1296 | dev_kfree_skb(ar->beacon); |
| 1297 | ar->beacon = NULL; |
| 1298 | ar->sniffer_enabled = false; |
| 1299 | ar->rx_software_decryption = false; |
| 1300 | ar9170_set_operating_mode(ar); |
| 1301 | mutex_unlock(&ar->mutex); |
| 1302 | } |
| 1303 | |
| 1304 | static int ar9170_op_config(struct ieee80211_hw *hw, u32 changed) |
| 1305 | { |
| 1306 | struct ar9170 *ar = hw->priv; |
| 1307 | int err = 0; |
| 1308 | |
| 1309 | mutex_lock(&ar->mutex); |
| 1310 | |
| 1311 | if (changed & IEEE80211_CONF_CHANGE_RADIO_ENABLED) { |
| 1312 | /* TODO */ |
| 1313 | err = 0; |
| 1314 | } |
| 1315 | |
| 1316 | if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) { |
| 1317 | /* TODO */ |
| 1318 | err = 0; |
| 1319 | } |
| 1320 | |
| 1321 | if (changed & IEEE80211_CONF_CHANGE_PS) { |
| 1322 | /* TODO */ |
| 1323 | err = 0; |
| 1324 | } |
| 1325 | |
| 1326 | if (changed & IEEE80211_CONF_CHANGE_POWER) { |
| 1327 | /* TODO */ |
| 1328 | err = 0; |
| 1329 | } |
| 1330 | |
| 1331 | if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) { |
| 1332 | /* |
| 1333 | * is it long_frame_max_tx_count or short_frame_max_tx_count? |
| 1334 | */ |
| 1335 | |
| 1336 | err = ar9170_set_hwretry_limit(ar, |
| 1337 | ar->hw->conf.long_frame_max_tx_count); |
| 1338 | if (err) |
| 1339 | goto out; |
| 1340 | } |
| 1341 | |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 1342 | if (changed & BSS_CHANGED_BEACON_INT) { |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1343 | err = ar9170_set_beacon_timers(ar); |
| 1344 | if (err) |
| 1345 | goto out; |
| 1346 | } |
| 1347 | |
| 1348 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
Christian Lamparter | 29ceff5 | 2009-06-01 21:42:01 +0200 | [diff] [blame] | 1349 | |
| 1350 | /* adjust slot time for 5 GHz */ |
| 1351 | err = ar9170_set_slot_time(ar); |
| 1352 | if (err) |
| 1353 | goto out; |
| 1354 | |
| 1355 | err = ar9170_set_dyn_sifs_ack(ar); |
| 1356 | if (err) |
| 1357 | goto out; |
| 1358 | |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1359 | err = ar9170_set_channel(ar, hw->conf.channel, |
Johannes Berg | 9e52b0623 | 2009-04-20 18:27:04 +0200 | [diff] [blame] | 1360 | AR9170_RFI_NONE, |
| 1361 | nl80211_to_ar9170(hw->conf.channel_type)); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1362 | if (err) |
| 1363 | goto out; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | out: |
| 1367 | mutex_unlock(&ar->mutex); |
| 1368 | return err; |
| 1369 | } |
| 1370 | |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1371 | static void ar9170_set_filters(struct work_struct *work) |
| 1372 | { |
| 1373 | struct ar9170 *ar = container_of(work, struct ar9170, |
| 1374 | filter_config_work); |
| 1375 | int err; |
| 1376 | |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1377 | if (unlikely(!IS_STARTED(ar))) |
Christian Lamparter | 32c1628 | 2009-03-28 01:46:14 +0100 | [diff] [blame] | 1378 | return ; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1379 | |
Christian Lamparter | 32c1628 | 2009-03-28 01:46:14 +0100 | [diff] [blame] | 1380 | mutex_lock(&ar->mutex); |
Christian Lamparter | 864cc02 | 2009-05-23 20:28:21 +0200 | [diff] [blame^] | 1381 | if (test_and_clear_bit(AR9170_FILTER_CHANGED_MODE, |
| 1382 | &ar->filter_changed)) { |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1383 | err = ar9170_set_operating_mode(ar); |
| 1384 | if (err) |
| 1385 | goto unlock; |
| 1386 | } |
| 1387 | |
Christian Lamparter | 864cc02 | 2009-05-23 20:28:21 +0200 | [diff] [blame^] | 1388 | if (test_and_clear_bit(AR9170_FILTER_CHANGED_MULTICAST, |
| 1389 | &ar->filter_changed)) { |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1390 | err = ar9170_update_multicast(ar); |
| 1391 | if (err) |
| 1392 | goto unlock; |
| 1393 | } |
| 1394 | |
Christian Lamparter | 864cc02 | 2009-05-23 20:28:21 +0200 | [diff] [blame^] | 1395 | if (test_and_clear_bit(AR9170_FILTER_CHANGED_FRAMEFILTER, |
| 1396 | &ar->filter_changed)) { |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1397 | err = ar9170_update_frame_filter(ar); |
Christian Lamparter | 864cc02 | 2009-05-23 20:28:21 +0200 | [diff] [blame^] | 1398 | if (err) |
| 1399 | goto unlock; |
| 1400 | } |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1401 | |
| 1402 | unlock: |
| 1403 | mutex_unlock(&ar->mutex); |
| 1404 | } |
| 1405 | |
| 1406 | static void ar9170_op_configure_filter(struct ieee80211_hw *hw, |
| 1407 | unsigned int changed_flags, |
| 1408 | unsigned int *new_flags, |
| 1409 | int mc_count, struct dev_mc_list *mclist) |
| 1410 | { |
| 1411 | struct ar9170 *ar = hw->priv; |
| 1412 | |
| 1413 | /* mask supported flags */ |
| 1414 | *new_flags &= FIF_ALLMULTI | FIF_CONTROL | FIF_BCN_PRBRESP_PROMISC | |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 1415 | FIF_PROMISC_IN_BSS | FIF_FCSFAIL | FIF_PLCPFAIL; |
| 1416 | ar->filter_state = *new_flags; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1417 | /* |
| 1418 | * We can support more by setting the sniffer bit and |
| 1419 | * then checking the error flags, later. |
| 1420 | */ |
| 1421 | |
| 1422 | if (changed_flags & FIF_ALLMULTI) { |
| 1423 | if (*new_flags & FIF_ALLMULTI) { |
| 1424 | ar->want_mc_hash = ~0ULL; |
| 1425 | } else { |
| 1426 | u64 mchash; |
| 1427 | int i; |
| 1428 | |
| 1429 | /* always get broadcast frames */ |
Christian Lamparter | 864cc02 | 2009-05-23 20:28:21 +0200 | [diff] [blame^] | 1430 | mchash = 1ULL << (0xff >> 2); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1431 | |
| 1432 | for (i = 0; i < mc_count; i++) { |
| 1433 | if (WARN_ON(!mclist)) |
| 1434 | break; |
| 1435 | mchash |= 1ULL << (mclist->dmi_addr[5] >> 2); |
| 1436 | mclist = mclist->next; |
| 1437 | } |
| 1438 | ar->want_mc_hash = mchash; |
| 1439 | } |
Christian Lamparter | 864cc02 | 2009-05-23 20:28:21 +0200 | [diff] [blame^] | 1440 | set_bit(AR9170_FILTER_CHANGED_MULTICAST, &ar->filter_changed); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | if (changed_flags & FIF_CONTROL) { |
| 1444 | u32 filter = AR9170_MAC_REG_FTF_PSPOLL | |
| 1445 | AR9170_MAC_REG_FTF_RTS | |
| 1446 | AR9170_MAC_REG_FTF_CTS | |
| 1447 | AR9170_MAC_REG_FTF_ACK | |
| 1448 | AR9170_MAC_REG_FTF_CFE | |
| 1449 | AR9170_MAC_REG_FTF_CFE_ACK; |
| 1450 | |
| 1451 | if (*new_flags & FIF_CONTROL) |
| 1452 | ar->want_filter = ar->cur_filter | filter; |
| 1453 | else |
| 1454 | ar->want_filter = ar->cur_filter & ~filter; |
| 1455 | |
Christian Lamparter | 864cc02 | 2009-05-23 20:28:21 +0200 | [diff] [blame^] | 1456 | set_bit(AR9170_FILTER_CHANGED_FRAMEFILTER, |
| 1457 | &ar->filter_changed); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | if (changed_flags & FIF_PROMISC_IN_BSS) { |
| 1461 | ar->sniffer_enabled = ((*new_flags) & FIF_PROMISC_IN_BSS) != 0; |
Christian Lamparter | 864cc02 | 2009-05-23 20:28:21 +0200 | [diff] [blame^] | 1462 | set_bit(AR9170_FILTER_CHANGED_MODE, |
| 1463 | &ar->filter_changed); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | if (likely(IS_STARTED(ar))) |
| 1467 | queue_work(ar->hw->workqueue, &ar->filter_config_work); |
| 1468 | } |
| 1469 | |
| 1470 | static void ar9170_op_bss_info_changed(struct ieee80211_hw *hw, |
| 1471 | struct ieee80211_vif *vif, |
| 1472 | struct ieee80211_bss_conf *bss_conf, |
| 1473 | u32 changed) |
| 1474 | { |
| 1475 | struct ar9170 *ar = hw->priv; |
| 1476 | int err = 0; |
| 1477 | |
| 1478 | mutex_lock(&ar->mutex); |
| 1479 | |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1480 | if (changed & BSS_CHANGED_BSSID) { |
| 1481 | memcpy(ar->bssid, bss_conf->bssid, ETH_ALEN); |
| 1482 | err = ar9170_set_operating_mode(ar); |
Christian Lamparter | 29ceff5 | 2009-06-01 21:42:01 +0200 | [diff] [blame] | 1483 | if (err) |
| 1484 | goto out; |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | if (changed & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED)) { |
| 1488 | err = ar9170_update_beacon(ar); |
Christian Lamparter | 29ceff5 | 2009-06-01 21:42:01 +0200 | [diff] [blame] | 1489 | if (err) |
| 1490 | goto out; |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1491 | |
Christian Lamparter | 29ceff5 | 2009-06-01 21:42:01 +0200 | [diff] [blame] | 1492 | err = ar9170_set_beacon_timers(ar); |
| 1493 | if (err) |
| 1494 | goto out; |
| 1495 | } |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1496 | |
| 1497 | if (changed & BSS_CHANGED_ASSOC) { |
| 1498 | ar->state = bss_conf->assoc ? AR9170_ASSOCIATED : ar->state; |
| 1499 | |
| 1500 | #ifndef CONFIG_AR9170_LEDS |
| 1501 | /* enable assoc LED. */ |
| 1502 | err = ar9170_set_leds_state(ar, bss_conf->assoc ? 2 : 0); |
| 1503 | #endif /* CONFIG_AR9170_LEDS */ |
| 1504 | } |
| 1505 | |
Christian Lamparter | 29ceff5 | 2009-06-01 21:42:01 +0200 | [diff] [blame] | 1506 | if (changed & BSS_CHANGED_BEACON_INT) { |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 1507 | err = ar9170_set_beacon_timers(ar); |
Christian Lamparter | 29ceff5 | 2009-06-01 21:42:01 +0200 | [diff] [blame] | 1508 | if (err) |
| 1509 | goto out; |
| 1510 | } |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 1511 | |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1512 | if (changed & BSS_CHANGED_HT) { |
| 1513 | /* TODO */ |
| 1514 | err = 0; |
| 1515 | } |
| 1516 | |
| 1517 | if (changed & BSS_CHANGED_ERP_SLOT) { |
Christian Lamparter | 29ceff5 | 2009-06-01 21:42:01 +0200 | [diff] [blame] | 1518 | err = ar9170_set_slot_time(ar); |
| 1519 | if (err) |
| 1520 | goto out; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | if (changed & BSS_CHANGED_BASIC_RATES) { |
Christian Lamparter | 29ceff5 | 2009-06-01 21:42:01 +0200 | [diff] [blame] | 1524 | err = ar9170_set_basic_rates(ar); |
| 1525 | if (err) |
| 1526 | goto out; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1527 | } |
| 1528 | |
Christian Lamparter | 29ceff5 | 2009-06-01 21:42:01 +0200 | [diff] [blame] | 1529 | out: |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1530 | mutex_unlock(&ar->mutex); |
| 1531 | } |
| 1532 | |
| 1533 | static u64 ar9170_op_get_tsf(struct ieee80211_hw *hw) |
| 1534 | { |
| 1535 | struct ar9170 *ar = hw->priv; |
| 1536 | int err; |
| 1537 | u32 tsf_low; |
| 1538 | u32 tsf_high; |
| 1539 | u64 tsf; |
| 1540 | |
| 1541 | mutex_lock(&ar->mutex); |
| 1542 | err = ar9170_read_reg(ar, AR9170_MAC_REG_TSF_L, &tsf_low); |
| 1543 | if (!err) |
| 1544 | err = ar9170_read_reg(ar, AR9170_MAC_REG_TSF_H, &tsf_high); |
| 1545 | mutex_unlock(&ar->mutex); |
| 1546 | |
| 1547 | if (WARN_ON(err)) |
| 1548 | return 0; |
| 1549 | |
| 1550 | tsf = tsf_high; |
| 1551 | tsf = (tsf << 32) | tsf_low; |
| 1552 | return tsf; |
| 1553 | } |
| 1554 | |
| 1555 | static int ar9170_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
| 1556 | struct ieee80211_vif *vif, struct ieee80211_sta *sta, |
| 1557 | struct ieee80211_key_conf *key) |
| 1558 | { |
| 1559 | struct ar9170 *ar = hw->priv; |
| 1560 | int err = 0, i; |
| 1561 | u8 ktype; |
| 1562 | |
| 1563 | if ((!ar->vif) || (ar->disable_offload)) |
| 1564 | return -EOPNOTSUPP; |
| 1565 | |
| 1566 | switch (key->alg) { |
| 1567 | case ALG_WEP: |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 1568 | if (key->keylen == WLAN_KEY_LEN_WEP40) |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1569 | ktype = AR9170_ENC_ALG_WEP64; |
| 1570 | else |
| 1571 | ktype = AR9170_ENC_ALG_WEP128; |
| 1572 | break; |
| 1573 | case ALG_TKIP: |
| 1574 | ktype = AR9170_ENC_ALG_TKIP; |
| 1575 | break; |
| 1576 | case ALG_CCMP: |
| 1577 | ktype = AR9170_ENC_ALG_AESCCMP; |
| 1578 | break; |
| 1579 | default: |
| 1580 | return -EOPNOTSUPP; |
| 1581 | } |
| 1582 | |
| 1583 | mutex_lock(&ar->mutex); |
| 1584 | if (cmd == SET_KEY) { |
| 1585 | if (unlikely(!IS_STARTED(ar))) { |
| 1586 | err = -EOPNOTSUPP; |
| 1587 | goto out; |
| 1588 | } |
| 1589 | |
| 1590 | /* group keys need all-zeroes address */ |
| 1591 | if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) |
| 1592 | sta = NULL; |
| 1593 | |
| 1594 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) { |
| 1595 | for (i = 0; i < 64; i++) |
| 1596 | if (!(ar->usedkeys & BIT(i))) |
| 1597 | break; |
| 1598 | if (i == 64) { |
| 1599 | ar->rx_software_decryption = true; |
| 1600 | ar9170_set_operating_mode(ar); |
| 1601 | err = -ENOSPC; |
| 1602 | goto out; |
| 1603 | } |
| 1604 | } else { |
| 1605 | i = 64 + key->keyidx; |
| 1606 | } |
| 1607 | |
| 1608 | key->hw_key_idx = i; |
| 1609 | |
| 1610 | err = ar9170_upload_key(ar, i, sta ? sta->addr : NULL, ktype, 0, |
| 1611 | key->key, min_t(u8, 16, key->keylen)); |
| 1612 | if (err) |
| 1613 | goto out; |
| 1614 | |
| 1615 | if (key->alg == ALG_TKIP) { |
| 1616 | err = ar9170_upload_key(ar, i, sta ? sta->addr : NULL, |
| 1617 | ktype, 1, key->key + 16, 16); |
| 1618 | if (err) |
| 1619 | goto out; |
| 1620 | |
| 1621 | /* |
| 1622 | * hardware is not capable generating the MMIC |
| 1623 | * for fragmented frames! |
| 1624 | */ |
| 1625 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
| 1626 | } |
| 1627 | |
| 1628 | if (i < 64) |
| 1629 | ar->usedkeys |= BIT(i); |
| 1630 | |
| 1631 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 1632 | } else { |
| 1633 | if (unlikely(!IS_STARTED(ar))) { |
| 1634 | /* The device is gone... together with the key ;-) */ |
| 1635 | err = 0; |
| 1636 | goto out; |
| 1637 | } |
| 1638 | |
| 1639 | err = ar9170_disable_key(ar, key->hw_key_idx); |
| 1640 | if (err) |
| 1641 | goto out; |
| 1642 | |
| 1643 | if (key->hw_key_idx < 64) { |
| 1644 | ar->usedkeys &= ~BIT(key->hw_key_idx); |
| 1645 | } else { |
| 1646 | err = ar9170_upload_key(ar, key->hw_key_idx, NULL, |
| 1647 | AR9170_ENC_ALG_NONE, 0, |
| 1648 | NULL, 0); |
| 1649 | if (err) |
| 1650 | goto out; |
| 1651 | |
| 1652 | if (key->alg == ALG_TKIP) { |
| 1653 | err = ar9170_upload_key(ar, key->hw_key_idx, |
| 1654 | NULL, |
| 1655 | AR9170_ENC_ALG_NONE, 1, |
| 1656 | NULL, 0); |
| 1657 | if (err) |
| 1658 | goto out; |
| 1659 | } |
| 1660 | |
| 1661 | } |
| 1662 | } |
| 1663 | |
| 1664 | ar9170_regwrite_begin(ar); |
| 1665 | ar9170_regwrite(AR9170_MAC_REG_ROLL_CALL_TBL_L, ar->usedkeys); |
| 1666 | ar9170_regwrite(AR9170_MAC_REG_ROLL_CALL_TBL_H, ar->usedkeys >> 32); |
| 1667 | ar9170_regwrite_finish(); |
| 1668 | err = ar9170_regwrite_result(); |
| 1669 | |
| 1670 | out: |
| 1671 | mutex_unlock(&ar->mutex); |
| 1672 | |
| 1673 | return err; |
| 1674 | } |
| 1675 | |
| 1676 | static void ar9170_sta_notify(struct ieee80211_hw *hw, |
| 1677 | struct ieee80211_vif *vif, |
| 1678 | enum sta_notify_cmd cmd, |
| 1679 | struct ieee80211_sta *sta) |
| 1680 | { |
| 1681 | struct ar9170 *ar = hw->priv; |
| 1682 | struct ar9170_sta_info *info = (void *) sta->drv_priv; |
| 1683 | struct sk_buff *skb; |
Christian Lamparter | 4a48e2a | 2009-03-23 12:15:43 +0100 | [diff] [blame] | 1684 | unsigned int i; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1685 | |
| 1686 | switch (cmd) { |
| 1687 | case STA_NOTIFY_ADD: |
Christian Lamparter | 4a48e2a | 2009-03-23 12:15:43 +0100 | [diff] [blame] | 1688 | for (i = 0; i < ar->hw->queues; i++) |
| 1689 | skb_queue_head_init(&info->tx_status[i]); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1690 | break; |
| 1691 | |
| 1692 | case STA_NOTIFY_REMOVE: |
| 1693 | |
| 1694 | /* |
| 1695 | * transfer all outstanding frames that need a tx_status |
Christian Lamparter | 4a48e2a | 2009-03-23 12:15:43 +0100 | [diff] [blame] | 1696 | * reports to the global tx_status queue |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1697 | */ |
| 1698 | |
Christian Lamparter | 4a48e2a | 2009-03-23 12:15:43 +0100 | [diff] [blame] | 1699 | for (i = 0; i < ar->hw->queues; i++) { |
| 1700 | while ((skb = skb_dequeue(&info->tx_status[i]))) { |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1701 | #ifdef AR9170_QUEUE_DEBUG |
Christian Lamparter | 4a48e2a | 2009-03-23 12:15:43 +0100 | [diff] [blame] | 1702 | printk(KERN_DEBUG "%s: queueing frame in " |
| 1703 | "global tx_status queue =>\n", |
| 1704 | wiphy_name(ar->hw->wiphy)); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1705 | |
Christian Lamparter | 4a48e2a | 2009-03-23 12:15:43 +0100 | [diff] [blame] | 1706 | ar9170_print_txheader(ar, skb); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1707 | #endif /* AR9170_QUEUE_DEBUG */ |
Christian Lamparter | 4a48e2a | 2009-03-23 12:15:43 +0100 | [diff] [blame] | 1708 | skb_queue_tail(&ar->global_tx_status, skb); |
| 1709 | } |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1710 | } |
Christian Lamparter | 4a48e2a | 2009-03-23 12:15:43 +0100 | [diff] [blame] | 1711 | queue_delayed_work(ar->hw->workqueue, &ar->tx_status_janitor, |
| 1712 | msecs_to_jiffies(100)); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1713 | break; |
| 1714 | |
| 1715 | default: |
| 1716 | break; |
| 1717 | } |
| 1718 | } |
| 1719 | |
| 1720 | static int ar9170_get_stats(struct ieee80211_hw *hw, |
| 1721 | struct ieee80211_low_level_stats *stats) |
| 1722 | { |
| 1723 | struct ar9170 *ar = hw->priv; |
| 1724 | u32 val; |
| 1725 | int err; |
| 1726 | |
| 1727 | mutex_lock(&ar->mutex); |
| 1728 | err = ar9170_read_reg(ar, AR9170_MAC_REG_TX_RETRY, &val); |
| 1729 | ar->stats.dot11ACKFailureCount += val; |
| 1730 | |
| 1731 | memcpy(stats, &ar->stats, sizeof(*stats)); |
| 1732 | mutex_unlock(&ar->mutex); |
| 1733 | |
| 1734 | return 0; |
| 1735 | } |
| 1736 | |
| 1737 | static int ar9170_get_tx_stats(struct ieee80211_hw *hw, |
| 1738 | struct ieee80211_tx_queue_stats *tx_stats) |
| 1739 | { |
| 1740 | struct ar9170 *ar = hw->priv; |
| 1741 | |
| 1742 | spin_lock_bh(&ar->tx_stats_lock); |
| 1743 | memcpy(tx_stats, ar->tx_stats, sizeof(tx_stats[0]) * hw->queues); |
| 1744 | spin_unlock_bh(&ar->tx_stats_lock); |
| 1745 | |
| 1746 | return 0; |
| 1747 | } |
| 1748 | |
| 1749 | static int ar9170_conf_tx(struct ieee80211_hw *hw, u16 queue, |
| 1750 | const struct ieee80211_tx_queue_params *param) |
| 1751 | { |
| 1752 | struct ar9170 *ar = hw->priv; |
| 1753 | int ret; |
| 1754 | |
| 1755 | mutex_lock(&ar->mutex); |
Christian Lamparter | 4a48e2a | 2009-03-23 12:15:43 +0100 | [diff] [blame] | 1756 | if ((param) && !(queue > ar->hw->queues)) { |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1757 | memcpy(&ar->edcf[ar9170_qos_hwmap[queue]], |
| 1758 | param, sizeof(*param)); |
| 1759 | |
| 1760 | ret = ar9170_set_qos(ar); |
| 1761 | } else |
| 1762 | ret = -EINVAL; |
| 1763 | |
| 1764 | mutex_unlock(&ar->mutex); |
| 1765 | return ret; |
| 1766 | } |
| 1767 | |
Johannes Berg | 9e52b0623 | 2009-04-20 18:27:04 +0200 | [diff] [blame] | 1768 | static int ar9170_ampdu_action(struct ieee80211_hw *hw, |
| 1769 | enum ieee80211_ampdu_mlme_action action, |
| 1770 | struct ieee80211_sta *sta, u16 tid, u16 *ssn) |
| 1771 | { |
| 1772 | switch (action) { |
| 1773 | case IEEE80211_AMPDU_RX_START: |
| 1774 | case IEEE80211_AMPDU_RX_STOP: |
| 1775 | /* |
| 1776 | * Something goes wrong -- RX locks up |
| 1777 | * after a while of receiving aggregated |
| 1778 | * frames -- not enabling for now. |
| 1779 | */ |
| 1780 | return -EOPNOTSUPP; |
| 1781 | default: |
| 1782 | return -EOPNOTSUPP; |
| 1783 | } |
| 1784 | } |
| 1785 | |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1786 | static const struct ieee80211_ops ar9170_ops = { |
| 1787 | .start = ar9170_op_start, |
| 1788 | .stop = ar9170_op_stop, |
| 1789 | .tx = ar9170_op_tx, |
| 1790 | .add_interface = ar9170_op_add_interface, |
| 1791 | .remove_interface = ar9170_op_remove_interface, |
| 1792 | .config = ar9170_op_config, |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1793 | .configure_filter = ar9170_op_configure_filter, |
| 1794 | .conf_tx = ar9170_conf_tx, |
| 1795 | .bss_info_changed = ar9170_op_bss_info_changed, |
| 1796 | .get_tsf = ar9170_op_get_tsf, |
| 1797 | .set_key = ar9170_set_key, |
| 1798 | .sta_notify = ar9170_sta_notify, |
| 1799 | .get_stats = ar9170_get_stats, |
| 1800 | .get_tx_stats = ar9170_get_tx_stats, |
Johannes Berg | 9e52b0623 | 2009-04-20 18:27:04 +0200 | [diff] [blame] | 1801 | .ampdu_action = ar9170_ampdu_action, |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1802 | }; |
| 1803 | |
| 1804 | void *ar9170_alloc(size_t priv_size) |
| 1805 | { |
| 1806 | struct ieee80211_hw *hw; |
| 1807 | struct ar9170 *ar; |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 1808 | struct sk_buff *skb; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1809 | int i; |
| 1810 | |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 1811 | /* |
| 1812 | * this buffer is used for rx stream reconstruction. |
| 1813 | * Under heavy load this device (or the transport layer?) |
| 1814 | * tends to split the streams into seperate rx descriptors. |
| 1815 | */ |
| 1816 | |
| 1817 | skb = __dev_alloc_skb(AR9170_MAX_RX_BUFFER_SIZE, GFP_KERNEL); |
| 1818 | if (!skb) |
| 1819 | goto err_nomem; |
| 1820 | |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1821 | hw = ieee80211_alloc_hw(priv_size, &ar9170_ops); |
| 1822 | if (!hw) |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 1823 | goto err_nomem; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1824 | |
| 1825 | ar = hw->priv; |
| 1826 | ar->hw = hw; |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 1827 | ar->rx_failover = skb; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1828 | |
| 1829 | mutex_init(&ar->mutex); |
| 1830 | spin_lock_init(&ar->cmdlock); |
| 1831 | spin_lock_init(&ar->tx_stats_lock); |
| 1832 | skb_queue_head_init(&ar->global_tx_status); |
| 1833 | skb_queue_head_init(&ar->global_tx_status_waste); |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 1834 | ar9170_rx_reset_rx_mpdu(ar); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1835 | INIT_WORK(&ar->filter_config_work, ar9170_set_filters); |
| 1836 | INIT_WORK(&ar->beacon_work, ar9170_new_beacon); |
| 1837 | INIT_DELAYED_WORK(&ar->tx_status_janitor, ar9170_tx_status_janitor); |
| 1838 | |
| 1839 | /* all hw supports 2.4 GHz, so set channel to 1 by default */ |
| 1840 | ar->channel = &ar9170_2ghz_chantable[0]; |
| 1841 | |
| 1842 | /* first part of wiphy init */ |
| 1843 | ar->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
| 1844 | BIT(NL80211_IFTYPE_WDS) | |
| 1845 | BIT(NL80211_IFTYPE_ADHOC); |
| 1846 | ar->hw->flags |= IEEE80211_HW_RX_INCLUDES_FCS | |
| 1847 | IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING | |
| 1848 | IEEE80211_HW_SIGNAL_DBM | |
| 1849 | IEEE80211_HW_NOISE_DBM; |
| 1850 | |
Christian Lamparter | 4a48e2a | 2009-03-23 12:15:43 +0100 | [diff] [blame] | 1851 | ar->hw->queues = __AR9170_NUM_TXQ; |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1852 | ar->hw->extra_tx_headroom = 8; |
| 1853 | ar->hw->sta_data_size = sizeof(struct ar9170_sta_info); |
| 1854 | |
| 1855 | ar->hw->max_rates = 1; |
| 1856 | ar->hw->max_rate_tries = 3; |
| 1857 | |
| 1858 | for (i = 0; i < ARRAY_SIZE(ar->noise); i++) |
| 1859 | ar->noise[i] = -95; /* ATH_DEFAULT_NOISE_FLOOR */ |
| 1860 | |
| 1861 | return ar; |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 1862 | |
| 1863 | err_nomem: |
| 1864 | kfree_skb(skb); |
| 1865 | return ERR_PTR(-ENOMEM); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1866 | } |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1867 | |
| 1868 | static int ar9170_read_eeprom(struct ar9170 *ar) |
| 1869 | { |
| 1870 | #define RW 8 /* number of words to read at once */ |
| 1871 | #define RB (sizeof(u32) * RW) |
| 1872 | DECLARE_MAC_BUF(mbuf); |
| 1873 | u8 *eeprom = (void *)&ar->eeprom; |
| 1874 | u8 *addr = ar->eeprom.mac_address; |
| 1875 | __le32 offsets[RW]; |
| 1876 | int i, j, err, bands = 0; |
| 1877 | |
| 1878 | BUILD_BUG_ON(sizeof(ar->eeprom) & 3); |
| 1879 | |
| 1880 | BUILD_BUG_ON(RB > AR9170_MAX_CMD_LEN - 4); |
| 1881 | #ifndef __CHECKER__ |
| 1882 | /* don't want to handle trailing remains */ |
| 1883 | BUILD_BUG_ON(sizeof(ar->eeprom) % RB); |
| 1884 | #endif |
| 1885 | |
| 1886 | for (i = 0; i < sizeof(ar->eeprom)/RB; i++) { |
| 1887 | for (j = 0; j < RW; j++) |
| 1888 | offsets[j] = cpu_to_le32(AR9170_EEPROM_START + |
| 1889 | RB * i + 4 * j); |
| 1890 | |
| 1891 | err = ar->exec_cmd(ar, AR9170_CMD_RREG, |
| 1892 | RB, (u8 *) &offsets, |
| 1893 | RB, eeprom + RB * i); |
| 1894 | if (err) |
| 1895 | return err; |
| 1896 | } |
| 1897 | |
| 1898 | #undef RW |
| 1899 | #undef RB |
| 1900 | |
| 1901 | if (ar->eeprom.length == cpu_to_le16(0xFFFF)) |
| 1902 | return -ENODATA; |
| 1903 | |
| 1904 | if (ar->eeprom.operating_flags & AR9170_OPFLAG_2GHZ) { |
| 1905 | ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &ar9170_band_2GHz; |
| 1906 | bands++; |
| 1907 | } |
| 1908 | if (ar->eeprom.operating_flags & AR9170_OPFLAG_5GHZ) { |
| 1909 | ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &ar9170_band_5GHz; |
| 1910 | bands++; |
| 1911 | } |
| 1912 | /* |
| 1913 | * I measured this, a bandswitch takes roughly |
| 1914 | * 135 ms and a frequency switch about 80. |
| 1915 | * |
| 1916 | * FIXME: measure these values again once EEPROM settings |
| 1917 | * are used, that will influence them! |
| 1918 | */ |
| 1919 | if (bands == 2) |
| 1920 | ar->hw->channel_change_time = 135 * 1000; |
| 1921 | else |
| 1922 | ar->hw->channel_change_time = 80 * 1000; |
| 1923 | |
Christian Lamparter | 1878f77 | 2009-03-30 22:30:32 -0400 | [diff] [blame] | 1924 | ar->regulatory.current_rd = le16_to_cpu(ar->eeprom.reg_domain[0]); |
| 1925 | ar->regulatory.current_rd_ext = le16_to_cpu(ar->eeprom.reg_domain[1]); |
| 1926 | |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1927 | /* second part of wiphy init */ |
| 1928 | SET_IEEE80211_PERM_ADDR(ar->hw, addr); |
| 1929 | |
| 1930 | return bands ? 0 : -EINVAL; |
| 1931 | } |
| 1932 | |
Christian Lamparter | 1878f77 | 2009-03-30 22:30:32 -0400 | [diff] [blame] | 1933 | static int ar9170_reg_notifier(struct wiphy *wiphy, |
| 1934 | struct regulatory_request *request) |
| 1935 | { |
| 1936 | struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); |
| 1937 | struct ar9170 *ar = hw->priv; |
| 1938 | |
| 1939 | return ath_reg_notifier_apply(wiphy, request, &ar->regulatory); |
| 1940 | } |
| 1941 | |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1942 | int ar9170_register(struct ar9170 *ar, struct device *pdev) |
| 1943 | { |
| 1944 | int err; |
| 1945 | |
| 1946 | /* try to read EEPROM, init MAC addr */ |
| 1947 | err = ar9170_read_eeprom(ar); |
| 1948 | if (err) |
| 1949 | goto err_out; |
| 1950 | |
Christian Lamparter | 1878f77 | 2009-03-30 22:30:32 -0400 | [diff] [blame] | 1951 | err = ath_regd_init(&ar->regulatory, ar->hw->wiphy, |
| 1952 | ar9170_reg_notifier); |
Luis R. Rodriguez | 85efc86 | 2009-04-13 21:41:46 -0400 | [diff] [blame] | 1953 | if (err) |
| 1954 | goto err_out; |
Christian Lamparter | 1878f77 | 2009-03-30 22:30:32 -0400 | [diff] [blame] | 1955 | |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1956 | err = ieee80211_register_hw(ar->hw); |
| 1957 | if (err) |
| 1958 | goto err_out; |
| 1959 | |
Christian Lamparter | 1878f77 | 2009-03-30 22:30:32 -0400 | [diff] [blame] | 1960 | if (!ath_is_world_regd(&ar->regulatory)) |
| 1961 | regulatory_hint(ar->hw->wiphy, ar->regulatory.alpha2); |
| 1962 | |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1963 | err = ar9170_init_leds(ar); |
| 1964 | if (err) |
| 1965 | goto err_unreg; |
| 1966 | |
| 1967 | #ifdef CONFIG_AR9170_LEDS |
| 1968 | err = ar9170_register_leds(ar); |
| 1969 | if (err) |
| 1970 | goto err_unreg; |
| 1971 | #endif /* CONFIG_AR9170_LEDS */ |
| 1972 | |
| 1973 | dev_info(pdev, "Atheros AR9170 is registered as '%s'\n", |
| 1974 | wiphy_name(ar->hw->wiphy)); |
| 1975 | |
| 1976 | return err; |
| 1977 | |
| 1978 | err_unreg: |
| 1979 | ieee80211_unregister_hw(ar->hw); |
| 1980 | |
| 1981 | err_out: |
| 1982 | return err; |
| 1983 | } |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1984 | |
| 1985 | void ar9170_unregister(struct ar9170 *ar) |
| 1986 | { |
| 1987 | #ifdef CONFIG_AR9170_LEDS |
| 1988 | ar9170_unregister_leds(ar); |
| 1989 | #endif /* CONFIG_AR9170_LEDS */ |
| 1990 | |
Christian Lamparter | cca84799 | 2009-04-19 01:28:12 +0200 | [diff] [blame] | 1991 | kfree_skb(ar->rx_failover); |
Christian Lamparter | e9348cd | 2009-03-21 23:05:13 +0100 | [diff] [blame] | 1992 | ieee80211_unregister_hw(ar->hw); |
| 1993 | mutex_destroy(&ar->mutex); |
| 1994 | } |