Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright(c) 2003 - 2007 Intel Corporation. All rights reserved. |
| 4 | * |
| 5 | * Portions of this file are derived from the ipw3945 project, as well |
| 6 | * as portions of the ieee80211 subsystem header files. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of version 2 of the GNU General Public License as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution in the |
| 22 | * file called LICENSE. |
| 23 | * |
| 24 | * Contact Information: |
| 25 | * James P. Ketrenos <ipw2100-admin@linux.intel.com> |
| 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
| 30 | /* |
| 31 | * NOTE: This file (iwl-base.c) is used to build to multiple hardware targets |
| 32 | * by defining IWL to either 3945 or 4965. The Makefile used when building |
| 33 | * the base targets will create base-3945.o and base-4965.o |
| 34 | * |
| 35 | * The eventual goal is to move as many of the #if IWL / #endif blocks out of |
| 36 | * this file and into the hardware specific implementation files (iwl-XXXX.c) |
| 37 | * and leave only the common (non #ifdef sprinkled) code in this file |
| 38 | */ |
| 39 | |
| 40 | #include <linux/kernel.h> |
| 41 | #include <linux/module.h> |
| 42 | #include <linux/version.h> |
| 43 | #include <linux/init.h> |
| 44 | #include <linux/pci.h> |
| 45 | #include <linux/dma-mapping.h> |
| 46 | #include <linux/delay.h> |
| 47 | #include <linux/skbuff.h> |
| 48 | #include <linux/netdevice.h> |
| 49 | #include <linux/wireless.h> |
| 50 | #include <linux/firmware.h> |
| 51 | #include <linux/skbuff.h> |
| 52 | #include <linux/netdevice.h> |
| 53 | #include <linux/etherdevice.h> |
| 54 | #include <linux/if_arp.h> |
| 55 | |
| 56 | #include <net/ieee80211_radiotap.h> |
| 57 | #include <net/mac80211.h> |
| 58 | |
| 59 | #include <asm/div64.h> |
| 60 | |
Zhu Yi | 1156b2c | 2007-09-25 19:34:09 -0700 | [diff] [blame] | 61 | #define IWL 4965 |
| 62 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 63 | #include "iwlwifi.h" |
| 64 | #include "iwl-4965.h" |
| 65 | #include "iwl-helpers.h" |
| 66 | |
| 67 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 68 | u32 iwl_debug_level; |
| 69 | #endif |
| 70 | |
| 71 | /****************************************************************************** |
| 72 | * |
| 73 | * module boiler plate |
| 74 | * |
| 75 | ******************************************************************************/ |
| 76 | |
| 77 | /* module parameters */ |
| 78 | int iwl_param_disable_hw_scan; |
| 79 | int iwl_param_debug; |
| 80 | int iwl_param_disable; /* def: enable radio */ |
| 81 | int iwl_param_antenna; /* def: 0 = both antennas (use diversity) */ |
| 82 | int iwl_param_hwcrypto; /* def: using software encryption */ |
| 83 | int iwl_param_qos_enable = 1; |
| 84 | int iwl_param_queues_num = IWL_MAX_NUM_QUEUES; |
| 85 | |
| 86 | /* |
| 87 | * module name, copyright, version, etc. |
| 88 | * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk |
| 89 | */ |
| 90 | |
| 91 | #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux" |
| 92 | |
| 93 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 94 | #define VD "d" |
| 95 | #else |
| 96 | #define VD |
| 97 | #endif |
| 98 | |
| 99 | #ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT |
| 100 | #define VS "s" |
| 101 | #else |
| 102 | #define VS |
| 103 | #endif |
| 104 | |
| 105 | #define IWLWIFI_VERSION "0.1.15k" VD VS |
| 106 | #define DRV_COPYRIGHT "Copyright(c) 2003-2007 Intel Corporation" |
| 107 | #define DRV_VERSION IWLWIFI_VERSION |
| 108 | |
| 109 | /* Change firmware file name, using "-" and incrementing number, |
| 110 | * *only* when uCode interface or architecture changes so that it |
| 111 | * is not compatible with earlier drivers. |
| 112 | * This number will also appear in << 8 position of 1st dword of uCode file */ |
| 113 | #define IWL4965_UCODE_API "-1" |
| 114 | |
| 115 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 116 | MODULE_VERSION(DRV_VERSION); |
| 117 | MODULE_AUTHOR(DRV_COPYRIGHT); |
| 118 | MODULE_LICENSE("GPL"); |
| 119 | |
| 120 | __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr) |
| 121 | { |
| 122 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 123 | int hdr_len = ieee80211_get_hdrlen(fc); |
| 124 | |
| 125 | if ((fc & 0x00cc) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA)) |
| 126 | return (__le16 *) ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN); |
| 127 | return NULL; |
| 128 | } |
| 129 | |
| 130 | static const struct ieee80211_hw_mode *iwl_get_hw_mode( |
| 131 | struct iwl_priv *priv, int mode) |
| 132 | { |
| 133 | int i; |
| 134 | |
| 135 | for (i = 0; i < 3; i++) |
| 136 | if (priv->modes[i].mode == mode) |
| 137 | return &priv->modes[i]; |
| 138 | |
| 139 | return NULL; |
| 140 | } |
| 141 | |
| 142 | static int iwl_is_empty_essid(const char *essid, int essid_len) |
| 143 | { |
| 144 | /* Single white space is for Linksys APs */ |
| 145 | if (essid_len == 1 && essid[0] == ' ') |
| 146 | return 1; |
| 147 | |
| 148 | /* Otherwise, if the entire essid is 0, we assume it is hidden */ |
| 149 | while (essid_len) { |
| 150 | essid_len--; |
| 151 | if (essid[essid_len] != '\0') |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | return 1; |
| 156 | } |
| 157 | |
| 158 | static const char *iwl_escape_essid(const char *essid, u8 essid_len) |
| 159 | { |
| 160 | static char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
| 161 | const char *s = essid; |
| 162 | char *d = escaped; |
| 163 | |
| 164 | if (iwl_is_empty_essid(essid, essid_len)) { |
| 165 | memcpy(escaped, "<hidden>", sizeof("<hidden>")); |
| 166 | return escaped; |
| 167 | } |
| 168 | |
| 169 | essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE); |
| 170 | while (essid_len--) { |
| 171 | if (*s == '\0') { |
| 172 | *d++ = '\\'; |
| 173 | *d++ = '0'; |
| 174 | s++; |
| 175 | } else |
| 176 | *d++ = *s++; |
| 177 | } |
| 178 | *d = '\0'; |
| 179 | return escaped; |
| 180 | } |
| 181 | |
| 182 | static void iwl_print_hex_dump(int level, void *p, u32 len) |
| 183 | { |
| 184 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 185 | if (!(iwl_debug_level & level)) |
| 186 | return; |
| 187 | |
| 188 | print_hex_dump(KERN_DEBUG, "iwl data: ", DUMP_PREFIX_OFFSET, 16, 1, |
| 189 | p, len, 1); |
| 190 | #endif |
| 191 | } |
| 192 | |
| 193 | /*************** DMA-QUEUE-GENERAL-FUNCTIONS ***** |
| 194 | * DMA services |
| 195 | * |
| 196 | * Theory of operation |
| 197 | * |
| 198 | * A queue is a circular buffers with 'Read' and 'Write' pointers. |
| 199 | * 2 empty entries always kept in the buffer to protect from overflow. |
| 200 | * |
| 201 | * For Tx queue, there are low mark and high mark limits. If, after queuing |
| 202 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 203 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
| 204 | * Tx queue resumed. |
| 205 | * |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 206 | * The IWL operates with six queues, one receive queue in the device's |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 207 | * sram, one transmit queue for sending commands to the device firmware, |
| 208 | * and four transmit queues for data. |
| 209 | ***************************************************/ |
| 210 | |
| 211 | static int iwl_queue_space(const struct iwl_queue *q) |
| 212 | { |
| 213 | int s = q->last_used - q->first_empty; |
| 214 | |
| 215 | if (q->last_used > q->first_empty) |
| 216 | s -= q->n_bd; |
| 217 | |
| 218 | if (s <= 0) |
| 219 | s += q->n_window; |
| 220 | /* keep some reserve to not confuse empty and full situations */ |
| 221 | s -= 2; |
| 222 | if (s < 0) |
| 223 | s = 0; |
| 224 | return s; |
| 225 | } |
| 226 | |
| 227 | /* XXX: n_bd must be power-of-two size */ |
| 228 | static inline int iwl_queue_inc_wrap(int index, int n_bd) |
| 229 | { |
| 230 | return ++index & (n_bd - 1); |
| 231 | } |
| 232 | |
| 233 | /* XXX: n_bd must be power-of-two size */ |
| 234 | static inline int iwl_queue_dec_wrap(int index, int n_bd) |
| 235 | { |
| 236 | return --index & (n_bd - 1); |
| 237 | } |
| 238 | |
| 239 | static inline int x2_queue_used(const struct iwl_queue *q, int i) |
| 240 | { |
| 241 | return q->first_empty > q->last_used ? |
| 242 | (i >= q->last_used && i < q->first_empty) : |
| 243 | !(i < q->last_used && i >= q->first_empty); |
| 244 | } |
| 245 | |
| 246 | static inline u8 get_cmd_index(struct iwl_queue *q, u32 index, int is_huge) |
| 247 | { |
| 248 | if (is_huge) |
| 249 | return q->n_window; |
| 250 | |
| 251 | return index & (q->n_window - 1); |
| 252 | } |
| 253 | |
| 254 | static int iwl_queue_init(struct iwl_priv *priv, struct iwl_queue *q, |
| 255 | int count, int slots_num, u32 id) |
| 256 | { |
| 257 | q->n_bd = count; |
| 258 | q->n_window = slots_num; |
| 259 | q->id = id; |
| 260 | |
| 261 | /* count must be power-of-two size, otherwise iwl_queue_inc_wrap |
| 262 | * and iwl_queue_dec_wrap are broken. */ |
| 263 | BUG_ON(!is_power_of_2(count)); |
| 264 | |
| 265 | /* slots_num must be power-of-two size, otherwise |
| 266 | * get_cmd_index is broken. */ |
| 267 | BUG_ON(!is_power_of_2(slots_num)); |
| 268 | |
| 269 | q->low_mark = q->n_window / 4; |
| 270 | if (q->low_mark < 4) |
| 271 | q->low_mark = 4; |
| 272 | |
| 273 | q->high_mark = q->n_window / 8; |
| 274 | if (q->high_mark < 2) |
| 275 | q->high_mark = 2; |
| 276 | |
| 277 | q->first_empty = q->last_used = 0; |
| 278 | |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | static int iwl_tx_queue_alloc(struct iwl_priv *priv, |
| 283 | struct iwl_tx_queue *txq, u32 id) |
| 284 | { |
| 285 | struct pci_dev *dev = priv->pci_dev; |
| 286 | |
| 287 | if (id != IWL_CMD_QUEUE_NUM) { |
| 288 | txq->txb = kmalloc(sizeof(txq->txb[0]) * |
| 289 | TFD_QUEUE_SIZE_MAX, GFP_KERNEL); |
| 290 | if (!txq->txb) { |
| 291 | IWL_ERROR("kmalloc for auxilary BD " |
| 292 | "structures failed\n"); |
| 293 | goto error; |
| 294 | } |
| 295 | } else |
| 296 | txq->txb = NULL; |
| 297 | |
| 298 | txq->bd = pci_alloc_consistent(dev, |
| 299 | sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX, |
| 300 | &txq->q.dma_addr); |
| 301 | |
| 302 | if (!txq->bd) { |
| 303 | IWL_ERROR("pci_alloc_consistent(%zd) failed\n", |
| 304 | sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX); |
| 305 | goto error; |
| 306 | } |
| 307 | txq->q.id = id; |
| 308 | |
| 309 | return 0; |
| 310 | |
| 311 | error: |
| 312 | if (txq->txb) { |
| 313 | kfree(txq->txb); |
| 314 | txq->txb = NULL; |
| 315 | } |
| 316 | |
| 317 | return -ENOMEM; |
| 318 | } |
| 319 | |
| 320 | int iwl_tx_queue_init(struct iwl_priv *priv, |
| 321 | struct iwl_tx_queue *txq, int slots_num, u32 txq_id) |
| 322 | { |
| 323 | struct pci_dev *dev = priv->pci_dev; |
| 324 | int len; |
| 325 | int rc = 0; |
| 326 | |
| 327 | /* alocate command space + one big command for scan since scan |
| 328 | * command is very huge the system will not have two scan at the |
| 329 | * same time */ |
| 330 | len = sizeof(struct iwl_cmd) * slots_num; |
| 331 | if (txq_id == IWL_CMD_QUEUE_NUM) |
| 332 | len += IWL_MAX_SCAN_SIZE; |
| 333 | txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd); |
| 334 | if (!txq->cmd) |
| 335 | return -ENOMEM; |
| 336 | |
| 337 | rc = iwl_tx_queue_alloc(priv, txq, txq_id); |
| 338 | if (rc) { |
| 339 | pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); |
| 340 | |
| 341 | return -ENOMEM; |
| 342 | } |
| 343 | txq->need_update = 0; |
| 344 | |
| 345 | /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise |
| 346 | * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */ |
| 347 | BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1)); |
| 348 | iwl_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id); |
| 349 | |
| 350 | iwl_hw_tx_queue_init(priv, txq); |
| 351 | |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * iwl_tx_queue_free - Deallocate DMA queue. |
| 357 | * @txq: Transmit queue to deallocate. |
| 358 | * |
| 359 | * Empty queue by removing and destroying all BD's. |
| 360 | * Free all buffers. txq itself is not freed. |
| 361 | * |
| 362 | */ |
| 363 | void iwl_tx_queue_free(struct iwl_priv *priv, struct iwl_tx_queue *txq) |
| 364 | { |
| 365 | struct iwl_queue *q = &txq->q; |
| 366 | struct pci_dev *dev = priv->pci_dev; |
| 367 | int len; |
| 368 | |
| 369 | if (q->n_bd == 0) |
| 370 | return; |
| 371 | |
| 372 | /* first, empty all BD's */ |
| 373 | for (; q->first_empty != q->last_used; |
| 374 | q->last_used = iwl_queue_inc_wrap(q->last_used, q->n_bd)) |
| 375 | iwl_hw_txq_free_tfd(priv, txq); |
| 376 | |
| 377 | len = sizeof(struct iwl_cmd) * q->n_window; |
| 378 | if (q->id == IWL_CMD_QUEUE_NUM) |
| 379 | len += IWL_MAX_SCAN_SIZE; |
| 380 | |
| 381 | pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); |
| 382 | |
| 383 | /* free buffers belonging to queue itself */ |
| 384 | if (txq->q.n_bd) |
| 385 | pci_free_consistent(dev, sizeof(struct iwl_tfd_frame) * |
| 386 | txq->q.n_bd, txq->bd, txq->q.dma_addr); |
| 387 | |
| 388 | if (txq->txb) { |
| 389 | kfree(txq->txb); |
| 390 | txq->txb = NULL; |
| 391 | } |
| 392 | |
| 393 | /* 0 fill whole structure */ |
| 394 | memset(txq, 0, sizeof(*txq)); |
| 395 | } |
| 396 | |
| 397 | const u8 BROADCAST_ADDR[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; |
| 398 | |
| 399 | /*************** STATION TABLE MANAGEMENT **** |
| 400 | * |
| 401 | * NOTE: This needs to be overhauled to better synchronize between |
| 402 | * how the iwl-4965.c is using iwl_hw_find_station vs. iwl-3945.c |
| 403 | * |
| 404 | * mac80211 should also be examined to determine if sta_info is duplicating |
| 405 | * the functionality provided here |
| 406 | */ |
| 407 | |
| 408 | /**************************************************************/ |
| 409 | |
| 410 | static u8 iwl_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap) |
| 411 | { |
| 412 | int index = IWL_INVALID_STATION; |
| 413 | int i; |
| 414 | unsigned long flags; |
| 415 | |
| 416 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 417 | |
| 418 | if (is_ap) |
| 419 | index = IWL_AP_ID; |
| 420 | else if (is_broadcast_ether_addr(addr)) |
| 421 | index = priv->hw_setting.bcast_sta_id; |
| 422 | else |
| 423 | for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) |
| 424 | if (priv->stations[i].used && |
| 425 | !compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 426 | addr)) { |
| 427 | index = i; |
| 428 | break; |
| 429 | } |
| 430 | |
| 431 | if (unlikely(index == IWL_INVALID_STATION)) |
| 432 | goto out; |
| 433 | |
| 434 | if (priv->stations[index].used) { |
| 435 | priv->stations[index].used = 0; |
| 436 | priv->num_stations--; |
| 437 | } |
| 438 | |
| 439 | BUG_ON(priv->num_stations < 0); |
| 440 | |
| 441 | out: |
| 442 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 443 | return 0; |
| 444 | } |
| 445 | |
| 446 | static void iwl_clear_stations_table(struct iwl_priv *priv) |
| 447 | { |
| 448 | unsigned long flags; |
| 449 | |
| 450 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 451 | |
| 452 | priv->num_stations = 0; |
| 453 | memset(priv->stations, 0, sizeof(priv->stations)); |
| 454 | |
| 455 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 456 | } |
| 457 | |
| 458 | u8 iwl_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags) |
| 459 | { |
| 460 | int i; |
| 461 | int index = IWL_INVALID_STATION; |
| 462 | struct iwl_station_entry *station; |
| 463 | unsigned long flags_spin; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 464 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 465 | |
| 466 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 467 | if (is_ap) |
| 468 | index = IWL_AP_ID; |
| 469 | else if (is_broadcast_ether_addr(addr)) |
| 470 | index = priv->hw_setting.bcast_sta_id; |
| 471 | else |
| 472 | for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) { |
| 473 | if (!compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 474 | addr)) { |
| 475 | index = i; |
| 476 | break; |
| 477 | } |
| 478 | |
| 479 | if (!priv->stations[i].used && |
| 480 | index == IWL_INVALID_STATION) |
| 481 | index = i; |
| 482 | } |
| 483 | |
| 484 | |
| 485 | /* These twh conditions has the same outcome but keep them separate |
| 486 | since they have different meaning */ |
| 487 | if (unlikely(index == IWL_INVALID_STATION)) { |
| 488 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 489 | return index; |
| 490 | } |
| 491 | |
| 492 | if (priv->stations[index].used && |
| 493 | !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) { |
| 494 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 495 | return index; |
| 496 | } |
| 497 | |
| 498 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 499 | IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index, print_mac(mac, addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 500 | station = &priv->stations[index]; |
| 501 | station->used = 1; |
| 502 | priv->num_stations++; |
| 503 | |
| 504 | memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd)); |
| 505 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
| 506 | station->sta.mode = 0; |
| 507 | station->sta.sta.sta_id = index; |
| 508 | station->sta.station_flags = 0; |
| 509 | |
| 510 | #ifdef CONFIG_IWLWIFI_HT |
| 511 | /* BCAST station and IBSS stations do not work in HT mode */ |
| 512 | if (index != priv->hw_setting.bcast_sta_id && |
| 513 | priv->iw_mode != IEEE80211_IF_TYPE_IBSS) |
| 514 | iwl4965_set_ht_add_station(priv, index); |
| 515 | #endif /*CONFIG_IWLWIFI_HT*/ |
| 516 | |
| 517 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 518 | iwl_send_add_station(priv, &station->sta, flags); |
| 519 | return index; |
| 520 | |
| 521 | } |
| 522 | |
| 523 | /*************** DRIVER STATUS FUNCTIONS *****/ |
| 524 | |
| 525 | static inline int iwl_is_ready(struct iwl_priv *priv) |
| 526 | { |
| 527 | /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are |
| 528 | * set but EXIT_PENDING is not */ |
| 529 | return test_bit(STATUS_READY, &priv->status) && |
| 530 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) && |
| 531 | !test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 532 | } |
| 533 | |
| 534 | static inline int iwl_is_alive(struct iwl_priv *priv) |
| 535 | { |
| 536 | return test_bit(STATUS_ALIVE, &priv->status); |
| 537 | } |
| 538 | |
| 539 | static inline int iwl_is_init(struct iwl_priv *priv) |
| 540 | { |
| 541 | return test_bit(STATUS_INIT, &priv->status); |
| 542 | } |
| 543 | |
| 544 | static inline int iwl_is_rfkill(struct iwl_priv *priv) |
| 545 | { |
| 546 | return test_bit(STATUS_RF_KILL_HW, &priv->status) || |
| 547 | test_bit(STATUS_RF_KILL_SW, &priv->status); |
| 548 | } |
| 549 | |
| 550 | static inline int iwl_is_ready_rf(struct iwl_priv *priv) |
| 551 | { |
| 552 | |
| 553 | if (iwl_is_rfkill(priv)) |
| 554 | return 0; |
| 555 | |
| 556 | return iwl_is_ready(priv); |
| 557 | } |
| 558 | |
| 559 | /*************** HOST COMMAND QUEUE FUNCTIONS *****/ |
| 560 | |
| 561 | #define IWL_CMD(x) case x : return #x |
| 562 | |
| 563 | static const char *get_cmd_string(u8 cmd) |
| 564 | { |
| 565 | switch (cmd) { |
| 566 | IWL_CMD(REPLY_ALIVE); |
| 567 | IWL_CMD(REPLY_ERROR); |
| 568 | IWL_CMD(REPLY_RXON); |
| 569 | IWL_CMD(REPLY_RXON_ASSOC); |
| 570 | IWL_CMD(REPLY_QOS_PARAM); |
| 571 | IWL_CMD(REPLY_RXON_TIMING); |
| 572 | IWL_CMD(REPLY_ADD_STA); |
| 573 | IWL_CMD(REPLY_REMOVE_STA); |
| 574 | IWL_CMD(REPLY_REMOVE_ALL_STA); |
| 575 | IWL_CMD(REPLY_TX); |
| 576 | IWL_CMD(REPLY_RATE_SCALE); |
| 577 | IWL_CMD(REPLY_LEDS_CMD); |
| 578 | IWL_CMD(REPLY_TX_LINK_QUALITY_CMD); |
| 579 | IWL_CMD(RADAR_NOTIFICATION); |
| 580 | IWL_CMD(REPLY_QUIET_CMD); |
| 581 | IWL_CMD(REPLY_CHANNEL_SWITCH); |
| 582 | IWL_CMD(CHANNEL_SWITCH_NOTIFICATION); |
| 583 | IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD); |
| 584 | IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION); |
| 585 | IWL_CMD(POWER_TABLE_CMD); |
| 586 | IWL_CMD(PM_SLEEP_NOTIFICATION); |
| 587 | IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC); |
| 588 | IWL_CMD(REPLY_SCAN_CMD); |
| 589 | IWL_CMD(REPLY_SCAN_ABORT_CMD); |
| 590 | IWL_CMD(SCAN_START_NOTIFICATION); |
| 591 | IWL_CMD(SCAN_RESULTS_NOTIFICATION); |
| 592 | IWL_CMD(SCAN_COMPLETE_NOTIFICATION); |
| 593 | IWL_CMD(BEACON_NOTIFICATION); |
| 594 | IWL_CMD(REPLY_TX_BEACON); |
| 595 | IWL_CMD(WHO_IS_AWAKE_NOTIFICATION); |
| 596 | IWL_CMD(QUIET_NOTIFICATION); |
| 597 | IWL_CMD(REPLY_TX_PWR_TABLE_CMD); |
| 598 | IWL_CMD(MEASURE_ABORT_NOTIFICATION); |
| 599 | IWL_CMD(REPLY_BT_CONFIG); |
| 600 | IWL_CMD(REPLY_STATISTICS_CMD); |
| 601 | IWL_CMD(STATISTICS_NOTIFICATION); |
| 602 | IWL_CMD(REPLY_CARD_STATE_CMD); |
| 603 | IWL_CMD(CARD_STATE_NOTIFICATION); |
| 604 | IWL_CMD(MISSED_BEACONS_NOTIFICATION); |
| 605 | IWL_CMD(REPLY_CT_KILL_CONFIG_CMD); |
| 606 | IWL_CMD(SENSITIVITY_CMD); |
| 607 | IWL_CMD(REPLY_PHY_CALIBRATION_CMD); |
| 608 | IWL_CMD(REPLY_RX_PHY_CMD); |
| 609 | IWL_CMD(REPLY_RX_MPDU_CMD); |
| 610 | IWL_CMD(REPLY_4965_RX); |
| 611 | IWL_CMD(REPLY_COMPRESSED_BA); |
| 612 | default: |
| 613 | return "UNKNOWN"; |
| 614 | |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | #define HOST_COMPLETE_TIMEOUT (HZ / 2) |
| 619 | |
| 620 | /** |
| 621 | * iwl_enqueue_hcmd - enqueue a uCode command |
| 622 | * @priv: device private data point |
| 623 | * @cmd: a point to the ucode command structure |
| 624 | * |
| 625 | * The function returns < 0 values to indicate the operation is |
| 626 | * failed. On success, it turns the index (> 0) of command in the |
| 627 | * command queue. |
| 628 | */ |
| 629 | static int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd) |
| 630 | { |
| 631 | struct iwl_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; |
| 632 | struct iwl_queue *q = &txq->q; |
| 633 | struct iwl_tfd_frame *tfd; |
| 634 | u32 *control_flags; |
| 635 | struct iwl_cmd *out_cmd; |
| 636 | u32 idx; |
| 637 | u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr)); |
| 638 | dma_addr_t phys_addr; |
| 639 | int ret; |
| 640 | unsigned long flags; |
| 641 | |
| 642 | /* If any of the command structures end up being larger than |
| 643 | * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then |
| 644 | * we will need to increase the size of the TFD entries */ |
| 645 | BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) && |
| 646 | !(cmd->meta.flags & CMD_SIZE_HUGE)); |
| 647 | |
| 648 | if (iwl_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) { |
| 649 | IWL_ERROR("No space for Tx\n"); |
| 650 | return -ENOSPC; |
| 651 | } |
| 652 | |
| 653 | spin_lock_irqsave(&priv->hcmd_lock, flags); |
| 654 | |
| 655 | tfd = &txq->bd[q->first_empty]; |
| 656 | memset(tfd, 0, sizeof(*tfd)); |
| 657 | |
| 658 | control_flags = (u32 *) tfd; |
| 659 | |
| 660 | idx = get_cmd_index(q, q->first_empty, cmd->meta.flags & CMD_SIZE_HUGE); |
| 661 | out_cmd = &txq->cmd[idx]; |
| 662 | |
| 663 | out_cmd->hdr.cmd = cmd->id; |
| 664 | memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta)); |
| 665 | memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len); |
| 666 | |
| 667 | /* At this point, the out_cmd now has all of the incoming cmd |
| 668 | * information */ |
| 669 | |
| 670 | out_cmd->hdr.flags = 0; |
| 671 | out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) | |
| 672 | INDEX_TO_SEQ(q->first_empty)); |
| 673 | if (out_cmd->meta.flags & CMD_SIZE_HUGE) |
| 674 | out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME); |
| 675 | |
| 676 | phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx + |
| 677 | offsetof(struct iwl_cmd, hdr); |
| 678 | iwl_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size); |
| 679 | |
| 680 | IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, " |
| 681 | "%d bytes at %d[%d]:%d\n", |
| 682 | get_cmd_string(out_cmd->hdr.cmd), |
| 683 | out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence), |
| 684 | fix_size, q->first_empty, idx, IWL_CMD_QUEUE_NUM); |
| 685 | |
| 686 | txq->need_update = 1; |
| 687 | ret = iwl4965_tx_queue_update_wr_ptr(priv, txq, 0); |
| 688 | q->first_empty = iwl_queue_inc_wrap(q->first_empty, q->n_bd); |
| 689 | iwl_tx_queue_update_write_ptr(priv, txq); |
| 690 | |
| 691 | spin_unlock_irqrestore(&priv->hcmd_lock, flags); |
| 692 | return ret ? ret : idx; |
| 693 | } |
| 694 | |
| 695 | int iwl_send_cmd_async(struct iwl_priv *priv, struct iwl_host_cmd *cmd) |
| 696 | { |
| 697 | int ret; |
| 698 | |
| 699 | BUG_ON(!(cmd->meta.flags & CMD_ASYNC)); |
| 700 | |
| 701 | /* An asynchronous command can not expect an SKB to be set. */ |
| 702 | BUG_ON(cmd->meta.flags & CMD_WANT_SKB); |
| 703 | |
| 704 | /* An asynchronous command MUST have a callback. */ |
| 705 | BUG_ON(!cmd->meta.u.callback); |
| 706 | |
| 707 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 708 | return -EBUSY; |
| 709 | |
| 710 | ret = iwl_enqueue_hcmd(priv, cmd); |
| 711 | if (ret < 0) { |
| 712 | IWL_ERROR("Error sending %s: iwl_enqueue_hcmd failed: %d\n", |
| 713 | get_cmd_string(cmd->id), ret); |
| 714 | return ret; |
| 715 | } |
| 716 | return 0; |
| 717 | } |
| 718 | |
| 719 | int iwl_send_cmd_sync(struct iwl_priv *priv, struct iwl_host_cmd *cmd) |
| 720 | { |
| 721 | int cmd_idx; |
| 722 | int ret; |
| 723 | static atomic_t entry = ATOMIC_INIT(0); /* reentrance protection */ |
| 724 | |
| 725 | BUG_ON(cmd->meta.flags & CMD_ASYNC); |
| 726 | |
| 727 | /* A synchronous command can not have a callback set. */ |
| 728 | BUG_ON(cmd->meta.u.callback != NULL); |
| 729 | |
| 730 | if (atomic_xchg(&entry, 1)) { |
| 731 | IWL_ERROR("Error sending %s: Already sending a host command\n", |
| 732 | get_cmd_string(cmd->id)); |
| 733 | return -EBUSY; |
| 734 | } |
| 735 | |
| 736 | set_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 737 | |
| 738 | if (cmd->meta.flags & CMD_WANT_SKB) |
| 739 | cmd->meta.source = &cmd->meta; |
| 740 | |
| 741 | cmd_idx = iwl_enqueue_hcmd(priv, cmd); |
| 742 | if (cmd_idx < 0) { |
| 743 | ret = cmd_idx; |
| 744 | IWL_ERROR("Error sending %s: iwl_enqueue_hcmd failed: %d\n", |
| 745 | get_cmd_string(cmd->id), ret); |
| 746 | goto out; |
| 747 | } |
| 748 | |
| 749 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 750 | !test_bit(STATUS_HCMD_ACTIVE, &priv->status), |
| 751 | HOST_COMPLETE_TIMEOUT); |
| 752 | if (!ret) { |
| 753 | if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) { |
| 754 | IWL_ERROR("Error sending %s: time out after %dms.\n", |
| 755 | get_cmd_string(cmd->id), |
| 756 | jiffies_to_msecs(HOST_COMPLETE_TIMEOUT)); |
| 757 | |
| 758 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 759 | ret = -ETIMEDOUT; |
| 760 | goto cancel; |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 765 | IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n", |
| 766 | get_cmd_string(cmd->id)); |
| 767 | ret = -ECANCELED; |
| 768 | goto fail; |
| 769 | } |
| 770 | if (test_bit(STATUS_FW_ERROR, &priv->status)) { |
| 771 | IWL_DEBUG_INFO("Command %s failed: FW Error\n", |
| 772 | get_cmd_string(cmd->id)); |
| 773 | ret = -EIO; |
| 774 | goto fail; |
| 775 | } |
| 776 | if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) { |
| 777 | IWL_ERROR("Error: Response NULL in '%s'\n", |
| 778 | get_cmd_string(cmd->id)); |
| 779 | ret = -EIO; |
| 780 | goto out; |
| 781 | } |
| 782 | |
| 783 | ret = 0; |
| 784 | goto out; |
| 785 | |
| 786 | cancel: |
| 787 | if (cmd->meta.flags & CMD_WANT_SKB) { |
| 788 | struct iwl_cmd *qcmd; |
| 789 | |
| 790 | /* Cancel the CMD_WANT_SKB flag for the cmd in the |
| 791 | * TX cmd queue. Otherwise in case the cmd comes |
| 792 | * in later, it will possibly set an invalid |
| 793 | * address (cmd->meta.source). */ |
| 794 | qcmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx]; |
| 795 | qcmd->meta.flags &= ~CMD_WANT_SKB; |
| 796 | } |
| 797 | fail: |
| 798 | if (cmd->meta.u.skb) { |
| 799 | dev_kfree_skb_any(cmd->meta.u.skb); |
| 800 | cmd->meta.u.skb = NULL; |
| 801 | } |
| 802 | out: |
| 803 | atomic_set(&entry, 0); |
| 804 | return ret; |
| 805 | } |
| 806 | |
| 807 | int iwl_send_cmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd) |
| 808 | { |
| 809 | /* A command can not be asynchronous AND expect an SKB to be set. */ |
| 810 | BUG_ON((cmd->meta.flags & CMD_ASYNC) && |
| 811 | (cmd->meta.flags & CMD_WANT_SKB)); |
| 812 | |
| 813 | if (cmd->meta.flags & CMD_ASYNC) |
| 814 | return iwl_send_cmd_async(priv, cmd); |
| 815 | |
| 816 | return iwl_send_cmd_sync(priv, cmd); |
| 817 | } |
| 818 | |
| 819 | int iwl_send_cmd_pdu(struct iwl_priv *priv, u8 id, u16 len, const void *data) |
| 820 | { |
| 821 | struct iwl_host_cmd cmd = { |
| 822 | .id = id, |
| 823 | .len = len, |
| 824 | .data = data, |
| 825 | }; |
| 826 | |
| 827 | return iwl_send_cmd_sync(priv, &cmd); |
| 828 | } |
| 829 | |
| 830 | static int __must_check iwl_send_cmd_u32(struct iwl_priv *priv, u8 id, u32 val) |
| 831 | { |
| 832 | struct iwl_host_cmd cmd = { |
| 833 | .id = id, |
| 834 | .len = sizeof(val), |
| 835 | .data = &val, |
| 836 | }; |
| 837 | |
| 838 | return iwl_send_cmd_sync(priv, &cmd); |
| 839 | } |
| 840 | |
| 841 | int iwl_send_statistics_request(struct iwl_priv *priv) |
| 842 | { |
| 843 | return iwl_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0); |
| 844 | } |
| 845 | |
| 846 | /** |
| 847 | * iwl_rxon_add_station - add station into station table. |
| 848 | * |
| 849 | * there is only one AP station with id= IWL_AP_ID |
| 850 | * NOTE: mutex must be held before calling the this fnction |
| 851 | */ |
| 852 | static int iwl_rxon_add_station(struct iwl_priv *priv, |
| 853 | const u8 *addr, int is_ap) |
| 854 | { |
| 855 | u8 rc; |
| 856 | |
| 857 | /* Remove this station if it happens to already exist */ |
| 858 | iwl_remove_station(priv, addr, is_ap); |
| 859 | |
| 860 | rc = iwl_add_station(priv, addr, is_ap, 0); |
| 861 | |
| 862 | iwl4965_add_station(priv, addr, is_ap); |
| 863 | |
| 864 | return rc; |
| 865 | } |
| 866 | |
| 867 | /** |
| 868 | * iwl_set_rxon_channel - Set the phymode and channel values in staging RXON |
| 869 | * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz |
| 870 | * @channel: Any channel valid for the requested phymode |
| 871 | |
| 872 | * In addition to setting the staging RXON, priv->phymode is also set. |
| 873 | * |
| 874 | * NOTE: Does not commit to the hardware; it sets appropriate bit fields |
| 875 | * in the staging RXON flag structure based on the phymode |
| 876 | */ |
| 877 | static int iwl_set_rxon_channel(struct iwl_priv *priv, u8 phymode, u16 channel) |
| 878 | { |
| 879 | if (!iwl_get_channel_info(priv, phymode, channel)) { |
| 880 | IWL_DEBUG_INFO("Could not set channel to %d [%d]\n", |
| 881 | channel, phymode); |
| 882 | return -EINVAL; |
| 883 | } |
| 884 | |
| 885 | if ((le16_to_cpu(priv->staging_rxon.channel) == channel) && |
| 886 | (priv->phymode == phymode)) |
| 887 | return 0; |
| 888 | |
| 889 | priv->staging_rxon.channel = cpu_to_le16(channel); |
| 890 | if (phymode == MODE_IEEE80211A) |
| 891 | priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK; |
| 892 | else |
| 893 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 894 | |
| 895 | priv->phymode = phymode; |
| 896 | |
| 897 | IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, phymode); |
| 898 | |
| 899 | return 0; |
| 900 | } |
| 901 | |
| 902 | /** |
| 903 | * iwl_check_rxon_cmd - validate RXON structure is valid |
| 904 | * |
| 905 | * NOTE: This is really only useful during development and can eventually |
| 906 | * be #ifdef'd out once the driver is stable and folks aren't actively |
| 907 | * making changes |
| 908 | */ |
| 909 | static int iwl_check_rxon_cmd(struct iwl_rxon_cmd *rxon) |
| 910 | { |
| 911 | int error = 0; |
| 912 | int counter = 1; |
| 913 | |
| 914 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { |
| 915 | error |= le32_to_cpu(rxon->flags & |
| 916 | (RXON_FLG_TGJ_NARROW_BAND_MSK | |
| 917 | RXON_FLG_RADAR_DETECT_MSK)); |
| 918 | if (error) |
| 919 | IWL_WARNING("check 24G fields %d | %d\n", |
| 920 | counter++, error); |
| 921 | } else { |
| 922 | error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ? |
| 923 | 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK); |
| 924 | if (error) |
| 925 | IWL_WARNING("check 52 fields %d | %d\n", |
| 926 | counter++, error); |
| 927 | error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK); |
| 928 | if (error) |
| 929 | IWL_WARNING("check 52 CCK %d | %d\n", |
| 930 | counter++, error); |
| 931 | } |
| 932 | error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1; |
| 933 | if (error) |
| 934 | IWL_WARNING("check mac addr %d | %d\n", counter++, error); |
| 935 | |
| 936 | /* make sure basic rates 6Mbps and 1Mbps are supported */ |
| 937 | error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) && |
| 938 | ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0)); |
| 939 | if (error) |
| 940 | IWL_WARNING("check basic rate %d | %d\n", counter++, error); |
| 941 | |
| 942 | error |= (le16_to_cpu(rxon->assoc_id) > 2007); |
| 943 | if (error) |
| 944 | IWL_WARNING("check assoc id %d | %d\n", counter++, error); |
| 945 | |
| 946 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
| 947 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)); |
| 948 | if (error) |
| 949 | IWL_WARNING("check CCK and short slot %d | %d\n", |
| 950 | counter++, error); |
| 951 | |
| 952 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
| 953 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)); |
| 954 | if (error) |
| 955 | IWL_WARNING("check CCK & auto detect %d | %d\n", |
| 956 | counter++, error); |
| 957 | |
| 958 | error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
| 959 | RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK); |
| 960 | if (error) |
| 961 | IWL_WARNING("check TGG and auto detect %d | %d\n", |
| 962 | counter++, error); |
| 963 | |
| 964 | if (error) |
| 965 | IWL_WARNING("Tuning to channel %d\n", |
| 966 | le16_to_cpu(rxon->channel)); |
| 967 | |
| 968 | if (error) { |
| 969 | IWL_ERROR("Not a valid iwl_rxon_assoc_cmd field values\n"); |
| 970 | return -1; |
| 971 | } |
| 972 | return 0; |
| 973 | } |
| 974 | |
| 975 | /** |
| 976 | * iwl_full_rxon_required - determine if RXON_ASSOC can be used in RXON commit |
| 977 | * @priv: staging_rxon is comapred to active_rxon |
| 978 | * |
| 979 | * If the RXON structure is changing sufficient to require a new |
| 980 | * tune or to clear and reset the RXON_FILTER_ASSOC_MSK then return 1 |
| 981 | * to indicate a new tune is required. |
| 982 | */ |
| 983 | static int iwl_full_rxon_required(struct iwl_priv *priv) |
| 984 | { |
| 985 | |
| 986 | /* These items are only settable from the full RXON command */ |
| 987 | if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) || |
| 988 | compare_ether_addr(priv->staging_rxon.bssid_addr, |
| 989 | priv->active_rxon.bssid_addr) || |
| 990 | compare_ether_addr(priv->staging_rxon.node_addr, |
| 991 | priv->active_rxon.node_addr) || |
| 992 | compare_ether_addr(priv->staging_rxon.wlap_bssid_addr, |
| 993 | priv->active_rxon.wlap_bssid_addr) || |
| 994 | (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) || |
| 995 | (priv->staging_rxon.channel != priv->active_rxon.channel) || |
| 996 | (priv->staging_rxon.air_propagation != |
| 997 | priv->active_rxon.air_propagation) || |
| 998 | (priv->staging_rxon.ofdm_ht_single_stream_basic_rates != |
| 999 | priv->active_rxon.ofdm_ht_single_stream_basic_rates) || |
| 1000 | (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates != |
| 1001 | priv->active_rxon.ofdm_ht_dual_stream_basic_rates) || |
| 1002 | (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) || |
| 1003 | (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id)) |
| 1004 | return 1; |
| 1005 | |
| 1006 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can |
| 1007 | * be updated with the RXON_ASSOC command -- however only some |
| 1008 | * flag transitions are allowed using RXON_ASSOC */ |
| 1009 | |
| 1010 | /* Check if we are not switching bands */ |
| 1011 | if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) != |
| 1012 | (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)) |
| 1013 | return 1; |
| 1014 | |
| 1015 | /* Check if we are switching association toggle */ |
| 1016 | if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) != |
| 1017 | (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) |
| 1018 | return 1; |
| 1019 | |
| 1020 | return 0; |
| 1021 | } |
| 1022 | |
| 1023 | static int iwl_send_rxon_assoc(struct iwl_priv *priv) |
| 1024 | { |
| 1025 | int rc = 0; |
| 1026 | struct iwl_rx_packet *res = NULL; |
| 1027 | struct iwl_rxon_assoc_cmd rxon_assoc; |
| 1028 | struct iwl_host_cmd cmd = { |
| 1029 | .id = REPLY_RXON_ASSOC, |
| 1030 | .len = sizeof(rxon_assoc), |
| 1031 | .meta.flags = CMD_WANT_SKB, |
| 1032 | .data = &rxon_assoc, |
| 1033 | }; |
| 1034 | const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon; |
| 1035 | const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon; |
| 1036 | |
| 1037 | if ((rxon1->flags == rxon2->flags) && |
| 1038 | (rxon1->filter_flags == rxon2->filter_flags) && |
| 1039 | (rxon1->cck_basic_rates == rxon2->cck_basic_rates) && |
| 1040 | (rxon1->ofdm_ht_single_stream_basic_rates == |
| 1041 | rxon2->ofdm_ht_single_stream_basic_rates) && |
| 1042 | (rxon1->ofdm_ht_dual_stream_basic_rates == |
| 1043 | rxon2->ofdm_ht_dual_stream_basic_rates) && |
| 1044 | (rxon1->rx_chain == rxon2->rx_chain) && |
| 1045 | (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) { |
| 1046 | IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n"); |
| 1047 | return 0; |
| 1048 | } |
| 1049 | |
| 1050 | rxon_assoc.flags = priv->staging_rxon.flags; |
| 1051 | rxon_assoc.filter_flags = priv->staging_rxon.filter_flags; |
| 1052 | rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates; |
| 1053 | rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates; |
| 1054 | rxon_assoc.reserved = 0; |
| 1055 | rxon_assoc.ofdm_ht_single_stream_basic_rates = |
| 1056 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates; |
| 1057 | rxon_assoc.ofdm_ht_dual_stream_basic_rates = |
| 1058 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates; |
| 1059 | rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain; |
| 1060 | |
| 1061 | rc = iwl_send_cmd_sync(priv, &cmd); |
| 1062 | if (rc) |
| 1063 | return rc; |
| 1064 | |
| 1065 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
| 1066 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1067 | IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n"); |
| 1068 | rc = -EIO; |
| 1069 | } |
| 1070 | |
| 1071 | priv->alloc_rxb_skb--; |
| 1072 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1073 | |
| 1074 | return rc; |
| 1075 | } |
| 1076 | |
| 1077 | /** |
| 1078 | * iwl_commit_rxon - commit staging_rxon to hardware |
| 1079 | * |
| 1080 | * The RXON command in staging_rxon is commited to the hardware and |
| 1081 | * the active_rxon structure is updated with the new data. This |
| 1082 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 1083 | * a HW tune is required based on the RXON structure changes. |
| 1084 | */ |
| 1085 | static int iwl_commit_rxon(struct iwl_priv *priv) |
| 1086 | { |
| 1087 | /* cast away the const for active_rxon in this function */ |
| 1088 | struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1089 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1090 | int rc = 0; |
| 1091 | |
| 1092 | if (!iwl_is_alive(priv)) |
| 1093 | return -1; |
| 1094 | |
| 1095 | /* always get timestamp with Rx frame */ |
| 1096 | priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK; |
| 1097 | |
| 1098 | rc = iwl_check_rxon_cmd(&priv->staging_rxon); |
| 1099 | if (rc) { |
| 1100 | IWL_ERROR("Invalid RXON configuration. Not committing.\n"); |
| 1101 | return -EINVAL; |
| 1102 | } |
| 1103 | |
| 1104 | /* If we don't need to send a full RXON, we can use |
| 1105 | * iwl_rxon_assoc_cmd which is used to reconfigure filter |
| 1106 | * and other flags for the current radio configuration. */ |
| 1107 | if (!iwl_full_rxon_required(priv)) { |
| 1108 | rc = iwl_send_rxon_assoc(priv); |
| 1109 | if (rc) { |
| 1110 | IWL_ERROR("Error setting RXON_ASSOC " |
| 1111 | "configuration (%d).\n", rc); |
| 1112 | return rc; |
| 1113 | } |
| 1114 | |
| 1115 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 1116 | |
| 1117 | return 0; |
| 1118 | } |
| 1119 | |
| 1120 | /* station table will be cleared */ |
| 1121 | priv->assoc_station_added = 0; |
| 1122 | |
| 1123 | #ifdef CONFIG_IWLWIFI_SENSITIVITY |
| 1124 | priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT; |
| 1125 | if (!priv->error_recovering) |
| 1126 | priv->start_calib = 0; |
| 1127 | |
| 1128 | iwl4965_init_sensitivity(priv, CMD_ASYNC, 1); |
| 1129 | #endif /* CONFIG_IWLWIFI_SENSITIVITY */ |
| 1130 | |
| 1131 | /* If we are currently associated and the new config requires |
| 1132 | * an RXON_ASSOC and the new config wants the associated mask enabled, |
| 1133 | * we must clear the associated from the active configuration |
| 1134 | * before we apply the new config */ |
| 1135 | if (iwl_is_associated(priv) && |
| 1136 | (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) { |
| 1137 | IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); |
| 1138 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 1139 | |
| 1140 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON, |
| 1141 | sizeof(struct iwl_rxon_cmd), |
| 1142 | &priv->active_rxon); |
| 1143 | |
| 1144 | /* If the mask clearing failed then we set |
| 1145 | * active_rxon back to what it was previously */ |
| 1146 | if (rc) { |
| 1147 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 1148 | IWL_ERROR("Error clearing ASSOC_MSK on current " |
| 1149 | "configuration (%d).\n", rc); |
| 1150 | return rc; |
| 1151 | } |
| 1152 | |
| 1153 | /* The RXON bit toggling will have cleared out the |
| 1154 | * station table in the uCode, so blank it in the driver |
| 1155 | * as well */ |
| 1156 | iwl_clear_stations_table(priv); |
| 1157 | } else if (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) { |
| 1158 | /* When switching from non-associated to associated, the |
| 1159 | * uCode clears out the station table; so clear it in the |
| 1160 | * driver as well */ |
| 1161 | iwl_clear_stations_table(priv); |
| 1162 | } |
| 1163 | |
| 1164 | IWL_DEBUG_INFO("Sending RXON\n" |
| 1165 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
| 1166 | "* channel = %d\n" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1167 | "* bssid = %s\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1168 | ((priv->staging_rxon.filter_flags & |
| 1169 | RXON_FILTER_ASSOC_MSK) ? "" : "out"), |
| 1170 | le16_to_cpu(priv->staging_rxon.channel), |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1171 | print_mac(mac, priv->staging_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1172 | |
| 1173 | /* Apply the new configuration */ |
| 1174 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON, |
| 1175 | sizeof(struct iwl_rxon_cmd), &priv->staging_rxon); |
| 1176 | if (rc) { |
| 1177 | IWL_ERROR("Error setting new configuration (%d).\n", rc); |
| 1178 | return rc; |
| 1179 | } |
| 1180 | |
| 1181 | #ifdef CONFIG_IWLWIFI_SENSITIVITY |
| 1182 | if (!priv->error_recovering) |
| 1183 | priv->start_calib = 0; |
| 1184 | |
| 1185 | priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT; |
| 1186 | iwl4965_init_sensitivity(priv, CMD_ASYNC, 1); |
| 1187 | #endif /* CONFIG_IWLWIFI_SENSITIVITY */ |
| 1188 | |
| 1189 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 1190 | |
| 1191 | /* If we issue a new RXON command which required a tune then we must |
| 1192 | * send a new TXPOWER command or we won't be able to Tx any frames */ |
| 1193 | rc = iwl_hw_reg_send_txpower(priv); |
| 1194 | if (rc) { |
| 1195 | IWL_ERROR("Error setting Tx power (%d).\n", rc); |
| 1196 | return rc; |
| 1197 | } |
| 1198 | |
| 1199 | /* Add the broadcast address so we can send broadcast frames */ |
| 1200 | if (iwl_rxon_add_station(priv, BROADCAST_ADDR, 0) == |
| 1201 | IWL_INVALID_STATION) { |
| 1202 | IWL_ERROR("Error adding BROADCAST address for transmit.\n"); |
| 1203 | return -EIO; |
| 1204 | } |
| 1205 | |
| 1206 | /* If we have set the ASSOC_MSK and we are in BSS mode then |
| 1207 | * add the IWL_AP_ID to the station rate table */ |
| 1208 | if (iwl_is_associated(priv) && |
| 1209 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { |
| 1210 | if (iwl_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1) |
| 1211 | == IWL_INVALID_STATION) { |
| 1212 | IWL_ERROR("Error adding AP address for transmit.\n"); |
| 1213 | return -EIO; |
| 1214 | } |
| 1215 | priv->assoc_station_added = 1; |
| 1216 | } |
| 1217 | |
| 1218 | return 0; |
| 1219 | } |
| 1220 | |
| 1221 | static int iwl_send_bt_config(struct iwl_priv *priv) |
| 1222 | { |
| 1223 | struct iwl_bt_cmd bt_cmd = { |
| 1224 | .flags = 3, |
| 1225 | .lead_time = 0xAA, |
| 1226 | .max_kill = 1, |
| 1227 | .kill_ack_mask = 0, |
| 1228 | .kill_cts_mask = 0, |
| 1229 | }; |
| 1230 | |
| 1231 | return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
| 1232 | sizeof(struct iwl_bt_cmd), &bt_cmd); |
| 1233 | } |
| 1234 | |
| 1235 | static int iwl_send_scan_abort(struct iwl_priv *priv) |
| 1236 | { |
| 1237 | int rc = 0; |
| 1238 | struct iwl_rx_packet *res; |
| 1239 | struct iwl_host_cmd cmd = { |
| 1240 | .id = REPLY_SCAN_ABORT_CMD, |
| 1241 | .meta.flags = CMD_WANT_SKB, |
| 1242 | }; |
| 1243 | |
| 1244 | /* If there isn't a scan actively going on in the hardware |
| 1245 | * then we are in between scan bands and not actually |
| 1246 | * actively scanning, so don't send the abort command */ |
| 1247 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 1248 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1249 | return 0; |
| 1250 | } |
| 1251 | |
| 1252 | rc = iwl_send_cmd_sync(priv, &cmd); |
| 1253 | if (rc) { |
| 1254 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1255 | return rc; |
| 1256 | } |
| 1257 | |
| 1258 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
| 1259 | if (res->u.status != CAN_ABORT_STATUS) { |
| 1260 | /* The scan abort will return 1 for success or |
| 1261 | * 2 for "failure". A failure condition can be |
| 1262 | * due to simply not being in an active scan which |
| 1263 | * can occur if we send the scan abort before we |
| 1264 | * the microcode has notified us that a scan is |
| 1265 | * completed. */ |
| 1266 | IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status); |
| 1267 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1268 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 1269 | } |
| 1270 | |
| 1271 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1272 | |
| 1273 | return rc; |
| 1274 | } |
| 1275 | |
| 1276 | static int iwl_card_state_sync_callback(struct iwl_priv *priv, |
| 1277 | struct iwl_cmd *cmd, |
| 1278 | struct sk_buff *skb) |
| 1279 | { |
| 1280 | return 1; |
| 1281 | } |
| 1282 | |
| 1283 | /* |
| 1284 | * CARD_STATE_CMD |
| 1285 | * |
| 1286 | * Use: Sets the internal card state to enable, disable, or halt |
| 1287 | * |
| 1288 | * When in the 'enable' state the card operates as normal. |
| 1289 | * When in the 'disable' state, the card enters into a low power mode. |
| 1290 | * When in the 'halt' state, the card is shut down and must be fully |
| 1291 | * restarted to come back on. |
| 1292 | */ |
| 1293 | static int iwl_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag) |
| 1294 | { |
| 1295 | struct iwl_host_cmd cmd = { |
| 1296 | .id = REPLY_CARD_STATE_CMD, |
| 1297 | .len = sizeof(u32), |
| 1298 | .data = &flags, |
| 1299 | .meta.flags = meta_flag, |
| 1300 | }; |
| 1301 | |
| 1302 | if (meta_flag & CMD_ASYNC) |
| 1303 | cmd.meta.u.callback = iwl_card_state_sync_callback; |
| 1304 | |
| 1305 | return iwl_send_cmd(priv, &cmd); |
| 1306 | } |
| 1307 | |
| 1308 | static int iwl_add_sta_sync_callback(struct iwl_priv *priv, |
| 1309 | struct iwl_cmd *cmd, struct sk_buff *skb) |
| 1310 | { |
| 1311 | struct iwl_rx_packet *res = NULL; |
| 1312 | |
| 1313 | if (!skb) { |
| 1314 | IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n"); |
| 1315 | return 1; |
| 1316 | } |
| 1317 | |
| 1318 | res = (struct iwl_rx_packet *)skb->data; |
| 1319 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1320 | IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n", |
| 1321 | res->hdr.flags); |
| 1322 | return 1; |
| 1323 | } |
| 1324 | |
| 1325 | switch (res->u.add_sta.status) { |
| 1326 | case ADD_STA_SUCCESS_MSK: |
| 1327 | break; |
| 1328 | default: |
| 1329 | break; |
| 1330 | } |
| 1331 | |
| 1332 | /* We didn't cache the SKB; let the caller free it */ |
| 1333 | return 1; |
| 1334 | } |
| 1335 | |
| 1336 | int iwl_send_add_station(struct iwl_priv *priv, |
| 1337 | struct iwl_addsta_cmd *sta, u8 flags) |
| 1338 | { |
| 1339 | struct iwl_rx_packet *res = NULL; |
| 1340 | int rc = 0; |
| 1341 | struct iwl_host_cmd cmd = { |
| 1342 | .id = REPLY_ADD_STA, |
| 1343 | .len = sizeof(struct iwl_addsta_cmd), |
| 1344 | .meta.flags = flags, |
| 1345 | .data = sta, |
| 1346 | }; |
| 1347 | |
| 1348 | if (flags & CMD_ASYNC) |
| 1349 | cmd.meta.u.callback = iwl_add_sta_sync_callback; |
| 1350 | else |
| 1351 | cmd.meta.flags |= CMD_WANT_SKB; |
| 1352 | |
| 1353 | rc = iwl_send_cmd(priv, &cmd); |
| 1354 | |
| 1355 | if (rc || (flags & CMD_ASYNC)) |
| 1356 | return rc; |
| 1357 | |
| 1358 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
| 1359 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1360 | IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n", |
| 1361 | res->hdr.flags); |
| 1362 | rc = -EIO; |
| 1363 | } |
| 1364 | |
| 1365 | if (rc == 0) { |
| 1366 | switch (res->u.add_sta.status) { |
| 1367 | case ADD_STA_SUCCESS_MSK: |
| 1368 | IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n"); |
| 1369 | break; |
| 1370 | default: |
| 1371 | rc = -EIO; |
| 1372 | IWL_WARNING("REPLY_ADD_STA failed\n"); |
| 1373 | break; |
| 1374 | } |
| 1375 | } |
| 1376 | |
| 1377 | priv->alloc_rxb_skb--; |
| 1378 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1379 | |
| 1380 | return rc; |
| 1381 | } |
| 1382 | |
| 1383 | static int iwl_update_sta_key_info(struct iwl_priv *priv, |
| 1384 | struct ieee80211_key_conf *keyconf, |
| 1385 | u8 sta_id) |
| 1386 | { |
| 1387 | unsigned long flags; |
| 1388 | __le16 key_flags = 0; |
| 1389 | |
| 1390 | switch (keyconf->alg) { |
| 1391 | case ALG_CCMP: |
| 1392 | key_flags |= STA_KEY_FLG_CCMP; |
| 1393 | key_flags |= cpu_to_le16( |
| 1394 | keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 1395 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 1396 | break; |
| 1397 | case ALG_TKIP: |
| 1398 | case ALG_WEP: |
| 1399 | return -EINVAL; |
| 1400 | default: |
| 1401 | return -EINVAL; |
| 1402 | } |
| 1403 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1404 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; |
| 1405 | priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; |
| 1406 | memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, |
| 1407 | keyconf->keylen); |
| 1408 | |
| 1409 | memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, |
| 1410 | keyconf->keylen); |
| 1411 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 1412 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1413 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1414 | |
| 1415 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1416 | |
| 1417 | IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n"); |
| 1418 | iwl_send_add_station(priv, &priv->stations[sta_id].sta, 0); |
| 1419 | return 0; |
| 1420 | } |
| 1421 | |
| 1422 | static int iwl_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id) |
| 1423 | { |
| 1424 | unsigned long flags; |
| 1425 | |
| 1426 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1427 | memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl_hw_key)); |
| 1428 | memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl_keyinfo)); |
| 1429 | priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC; |
| 1430 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1431 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1432 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1433 | |
| 1434 | IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n"); |
| 1435 | iwl_send_add_station(priv, &priv->stations[sta_id].sta, 0); |
| 1436 | return 0; |
| 1437 | } |
| 1438 | |
| 1439 | static void iwl_clear_free_frames(struct iwl_priv *priv) |
| 1440 | { |
| 1441 | struct list_head *element; |
| 1442 | |
| 1443 | IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n", |
| 1444 | priv->frames_count); |
| 1445 | |
| 1446 | while (!list_empty(&priv->free_frames)) { |
| 1447 | element = priv->free_frames.next; |
| 1448 | list_del(element); |
| 1449 | kfree(list_entry(element, struct iwl_frame, list)); |
| 1450 | priv->frames_count--; |
| 1451 | } |
| 1452 | |
| 1453 | if (priv->frames_count) { |
| 1454 | IWL_WARNING("%d frames still in use. Did we lose one?\n", |
| 1455 | priv->frames_count); |
| 1456 | priv->frames_count = 0; |
| 1457 | } |
| 1458 | } |
| 1459 | |
| 1460 | static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv) |
| 1461 | { |
| 1462 | struct iwl_frame *frame; |
| 1463 | struct list_head *element; |
| 1464 | if (list_empty(&priv->free_frames)) { |
| 1465 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 1466 | if (!frame) { |
| 1467 | IWL_ERROR("Could not allocate frame!\n"); |
| 1468 | return NULL; |
| 1469 | } |
| 1470 | |
| 1471 | priv->frames_count++; |
| 1472 | return frame; |
| 1473 | } |
| 1474 | |
| 1475 | element = priv->free_frames.next; |
| 1476 | list_del(element); |
| 1477 | return list_entry(element, struct iwl_frame, list); |
| 1478 | } |
| 1479 | |
| 1480 | static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame) |
| 1481 | { |
| 1482 | memset(frame, 0, sizeof(*frame)); |
| 1483 | list_add(&frame->list, &priv->free_frames); |
| 1484 | } |
| 1485 | |
| 1486 | unsigned int iwl_fill_beacon_frame(struct iwl_priv *priv, |
| 1487 | struct ieee80211_hdr *hdr, |
| 1488 | const u8 *dest, int left) |
| 1489 | { |
| 1490 | |
| 1491 | if (!iwl_is_associated(priv) || !priv->ibss_beacon || |
| 1492 | ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) && |
| 1493 | (priv->iw_mode != IEEE80211_IF_TYPE_AP))) |
| 1494 | return 0; |
| 1495 | |
| 1496 | if (priv->ibss_beacon->len > left) |
| 1497 | return 0; |
| 1498 | |
| 1499 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); |
| 1500 | |
| 1501 | return priv->ibss_beacon->len; |
| 1502 | } |
| 1503 | |
| 1504 | int iwl_rate_index_from_plcp(int plcp) |
| 1505 | { |
| 1506 | int i = 0; |
| 1507 | |
| 1508 | if (plcp & RATE_MCS_HT_MSK) { |
| 1509 | i = (plcp & 0xff); |
| 1510 | |
| 1511 | if (i >= IWL_RATE_MIMO_6M_PLCP) |
| 1512 | i = i - IWL_RATE_MIMO_6M_PLCP; |
| 1513 | |
| 1514 | i += IWL_FIRST_OFDM_RATE; |
| 1515 | /* skip 9M not supported in ht*/ |
| 1516 | if (i >= IWL_RATE_9M_INDEX) |
| 1517 | i += 1; |
| 1518 | if ((i >= IWL_FIRST_OFDM_RATE) && |
| 1519 | (i <= IWL_LAST_OFDM_RATE)) |
| 1520 | return i; |
| 1521 | } else { |
| 1522 | for (i = 0; i < ARRAY_SIZE(iwl_rates); i++) |
| 1523 | if (iwl_rates[i].plcp == (plcp &0xFF)) |
| 1524 | return i; |
| 1525 | } |
| 1526 | return -1; |
| 1527 | } |
| 1528 | |
| 1529 | static u8 iwl_rate_get_lowest_plcp(int rate_mask) |
| 1530 | { |
| 1531 | u8 i; |
| 1532 | |
| 1533 | for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; |
| 1534 | i = iwl_rates[i].next_ieee) { |
| 1535 | if (rate_mask & (1 << i)) |
| 1536 | return iwl_rates[i].plcp; |
| 1537 | } |
| 1538 | |
| 1539 | return IWL_RATE_INVALID; |
| 1540 | } |
| 1541 | |
| 1542 | static int iwl_send_beacon_cmd(struct iwl_priv *priv) |
| 1543 | { |
| 1544 | struct iwl_frame *frame; |
| 1545 | unsigned int frame_size; |
| 1546 | int rc; |
| 1547 | u8 rate; |
| 1548 | |
| 1549 | frame = iwl_get_free_frame(priv); |
| 1550 | |
| 1551 | if (!frame) { |
| 1552 | IWL_ERROR("Could not obtain free frame buffer for beacon " |
| 1553 | "command.\n"); |
| 1554 | return -ENOMEM; |
| 1555 | } |
| 1556 | |
| 1557 | if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) { |
| 1558 | rate = iwl_rate_get_lowest_plcp(priv->active_rate_basic & |
| 1559 | 0xFF0); |
| 1560 | if (rate == IWL_INVALID_RATE) |
| 1561 | rate = IWL_RATE_6M_PLCP; |
| 1562 | } else { |
| 1563 | rate = iwl_rate_get_lowest_plcp(priv->active_rate_basic & 0xF); |
| 1564 | if (rate == IWL_INVALID_RATE) |
| 1565 | rate = IWL_RATE_1M_PLCP; |
| 1566 | } |
| 1567 | |
| 1568 | frame_size = iwl_hw_get_beacon_cmd(priv, frame, rate); |
| 1569 | |
| 1570 | rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
| 1571 | &frame->u.cmd[0]); |
| 1572 | |
| 1573 | iwl_free_frame(priv, frame); |
| 1574 | |
| 1575 | return rc; |
| 1576 | } |
| 1577 | |
| 1578 | /****************************************************************************** |
| 1579 | * |
| 1580 | * EEPROM related functions |
| 1581 | * |
| 1582 | ******************************************************************************/ |
| 1583 | |
| 1584 | static void get_eeprom_mac(struct iwl_priv *priv, u8 *mac) |
| 1585 | { |
| 1586 | memcpy(mac, priv->eeprom.mac_address, 6); |
| 1587 | } |
| 1588 | |
| 1589 | /** |
| 1590 | * iwl_eeprom_init - read EEPROM contents |
| 1591 | * |
| 1592 | * Load the EEPROM from adapter into priv->eeprom |
| 1593 | * |
| 1594 | * NOTE: This routine uses the non-debug IO access functions. |
| 1595 | */ |
| 1596 | int iwl_eeprom_init(struct iwl_priv *priv) |
| 1597 | { |
| 1598 | u16 *e = (u16 *)&priv->eeprom; |
| 1599 | u32 gp = iwl_read32(priv, CSR_EEPROM_GP); |
| 1600 | u32 r; |
| 1601 | int sz = sizeof(priv->eeprom); |
| 1602 | int rc; |
| 1603 | int i; |
| 1604 | u16 addr; |
| 1605 | |
| 1606 | /* The EEPROM structure has several padding buffers within it |
| 1607 | * and when adding new EEPROM maps is subject to programmer errors |
| 1608 | * which may be very difficult to identify without explicitly |
| 1609 | * checking the resulting size of the eeprom map. */ |
| 1610 | BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE); |
| 1611 | |
| 1612 | if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) { |
| 1613 | IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp); |
| 1614 | return -ENOENT; |
| 1615 | } |
| 1616 | |
| 1617 | rc = iwl_eeprom_aqcuire_semaphore(priv); |
| 1618 | if (rc < 0) { |
| 1619 | IWL_ERROR("Failed to aqcuire EEPROM semaphore.\n"); |
| 1620 | return -ENOENT; |
| 1621 | } |
| 1622 | |
| 1623 | /* eeprom is an array of 16bit values */ |
| 1624 | for (addr = 0; addr < sz; addr += sizeof(u16)) { |
| 1625 | _iwl_write32(priv, CSR_EEPROM_REG, addr << 1); |
| 1626 | _iwl_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD); |
| 1627 | |
| 1628 | for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT; |
| 1629 | i += IWL_EEPROM_ACCESS_DELAY) { |
| 1630 | r = _iwl_read_restricted(priv, CSR_EEPROM_REG); |
| 1631 | if (r & CSR_EEPROM_REG_READ_VALID_MSK) |
| 1632 | break; |
| 1633 | udelay(IWL_EEPROM_ACCESS_DELAY); |
| 1634 | } |
| 1635 | |
| 1636 | if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) { |
| 1637 | IWL_ERROR("Time out reading EEPROM[%d]", addr); |
| 1638 | rc = -ETIMEDOUT; |
| 1639 | goto done; |
| 1640 | } |
| 1641 | e[addr / 2] = le16_to_cpu(r >> 16); |
| 1642 | } |
| 1643 | rc = 0; |
| 1644 | |
| 1645 | done: |
| 1646 | iwl_eeprom_release_semaphore(priv); |
| 1647 | return rc; |
| 1648 | } |
| 1649 | |
| 1650 | /****************************************************************************** |
| 1651 | * |
| 1652 | * Misc. internal state and helper functions |
| 1653 | * |
| 1654 | ******************************************************************************/ |
| 1655 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 1656 | |
| 1657 | /** |
| 1658 | * iwl_report_frame - dump frame to syslog during debug sessions |
| 1659 | * |
| 1660 | * hack this function to show different aspects of received frames, |
| 1661 | * including selective frame dumps. |
| 1662 | * group100 parameter selects whether to show 1 out of 100 good frames. |
| 1663 | * |
| 1664 | * TODO: ieee80211_hdr stuff is common to 3945 and 4965, so frame type |
| 1665 | * info output is okay, but some of this stuff (e.g. iwl_rx_frame_stats) |
| 1666 | * is 3945-specific and gives bad output for 4965. Need to split the |
| 1667 | * functionality, keep common stuff here. |
| 1668 | */ |
| 1669 | void iwl_report_frame(struct iwl_priv *priv, |
| 1670 | struct iwl_rx_packet *pkt, |
| 1671 | struct ieee80211_hdr *header, int group100) |
| 1672 | { |
| 1673 | u32 to_us; |
| 1674 | u32 print_summary = 0; |
| 1675 | u32 print_dump = 0; /* set to 1 to dump all frames' contents */ |
| 1676 | u32 hundred = 0; |
| 1677 | u32 dataframe = 0; |
| 1678 | u16 fc; |
| 1679 | u16 seq_ctl; |
| 1680 | u16 channel; |
| 1681 | u16 phy_flags; |
| 1682 | int rate_sym; |
| 1683 | u16 length; |
| 1684 | u16 status; |
| 1685 | u16 bcn_tmr; |
| 1686 | u32 tsf_low; |
| 1687 | u64 tsf; |
| 1688 | u8 rssi; |
| 1689 | u8 agc; |
| 1690 | u16 sig_avg; |
| 1691 | u16 noise_diff; |
| 1692 | struct iwl_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt); |
| 1693 | struct iwl_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt); |
| 1694 | struct iwl_rx_frame_end *rx_end = IWL_RX_END(pkt); |
| 1695 | u8 *data = IWL_RX_DATA(pkt); |
| 1696 | |
| 1697 | /* MAC header */ |
| 1698 | fc = le16_to_cpu(header->frame_control); |
| 1699 | seq_ctl = le16_to_cpu(header->seq_ctrl); |
| 1700 | |
| 1701 | /* metadata */ |
| 1702 | channel = le16_to_cpu(rx_hdr->channel); |
| 1703 | phy_flags = le16_to_cpu(rx_hdr->phy_flags); |
| 1704 | rate_sym = rx_hdr->rate; |
| 1705 | length = le16_to_cpu(rx_hdr->len); |
| 1706 | |
| 1707 | /* end-of-frame status and timestamp */ |
| 1708 | status = le32_to_cpu(rx_end->status); |
| 1709 | bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp); |
| 1710 | tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff; |
| 1711 | tsf = le64_to_cpu(rx_end->timestamp); |
| 1712 | |
| 1713 | /* signal statistics */ |
| 1714 | rssi = rx_stats->rssi; |
| 1715 | agc = rx_stats->agc; |
| 1716 | sig_avg = le16_to_cpu(rx_stats->sig_avg); |
| 1717 | noise_diff = le16_to_cpu(rx_stats->noise_diff); |
| 1718 | |
| 1719 | to_us = !compare_ether_addr(header->addr1, priv->mac_addr); |
| 1720 | |
| 1721 | /* if data frame is to us and all is good, |
| 1722 | * (optionally) print summary for only 1 out of every 100 */ |
| 1723 | if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) == |
| 1724 | (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) { |
| 1725 | dataframe = 1; |
| 1726 | if (!group100) |
| 1727 | print_summary = 1; /* print each frame */ |
| 1728 | else if (priv->framecnt_to_us < 100) { |
| 1729 | priv->framecnt_to_us++; |
| 1730 | print_summary = 0; |
| 1731 | } else { |
| 1732 | priv->framecnt_to_us = 0; |
| 1733 | print_summary = 1; |
| 1734 | hundred = 1; |
| 1735 | } |
| 1736 | } else { |
| 1737 | /* print summary for all other frames */ |
| 1738 | print_summary = 1; |
| 1739 | } |
| 1740 | |
| 1741 | if (print_summary) { |
| 1742 | char *title; |
| 1743 | u32 rate; |
| 1744 | |
| 1745 | if (hundred) |
| 1746 | title = "100Frames"; |
| 1747 | else if (fc & IEEE80211_FCTL_RETRY) |
| 1748 | title = "Retry"; |
| 1749 | else if (ieee80211_is_assoc_response(fc)) |
| 1750 | title = "AscRsp"; |
| 1751 | else if (ieee80211_is_reassoc_response(fc)) |
| 1752 | title = "RasRsp"; |
| 1753 | else if (ieee80211_is_probe_response(fc)) { |
| 1754 | title = "PrbRsp"; |
| 1755 | print_dump = 1; /* dump frame contents */ |
| 1756 | } else if (ieee80211_is_beacon(fc)) { |
| 1757 | title = "Beacon"; |
| 1758 | print_dump = 1; /* dump frame contents */ |
| 1759 | } else if (ieee80211_is_atim(fc)) |
| 1760 | title = "ATIM"; |
| 1761 | else if (ieee80211_is_auth(fc)) |
| 1762 | title = "Auth"; |
| 1763 | else if (ieee80211_is_deauth(fc)) |
| 1764 | title = "DeAuth"; |
| 1765 | else if (ieee80211_is_disassoc(fc)) |
| 1766 | title = "DisAssoc"; |
| 1767 | else |
| 1768 | title = "Frame"; |
| 1769 | |
| 1770 | rate = iwl_rate_index_from_plcp(rate_sym); |
| 1771 | if (rate == -1) |
| 1772 | rate = 0; |
| 1773 | else |
| 1774 | rate = iwl_rates[rate].ieee / 2; |
| 1775 | |
| 1776 | /* print frame summary. |
| 1777 | * MAC addresses show just the last byte (for brevity), |
| 1778 | * but you can hack it to show more, if you'd like to. */ |
| 1779 | if (dataframe) |
| 1780 | IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, " |
| 1781 | "len=%u, rssi=%d, chnl=%d, rate=%u, \n", |
| 1782 | title, fc, header->addr1[5], |
| 1783 | length, rssi, channel, rate); |
| 1784 | else { |
| 1785 | /* src/dst addresses assume managed mode */ |
| 1786 | IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, " |
| 1787 | "src=0x%02x, rssi=%u, tim=%lu usec, " |
| 1788 | "phy=0x%02x, chnl=%d\n", |
| 1789 | title, fc, header->addr1[5], |
| 1790 | header->addr3[5], rssi, |
| 1791 | tsf_low - priv->scan_start_tsf, |
| 1792 | phy_flags, channel); |
| 1793 | } |
| 1794 | } |
| 1795 | if (print_dump) |
| 1796 | iwl_print_hex_dump(IWL_DL_RX, data, length); |
| 1797 | } |
| 1798 | #endif |
| 1799 | |
| 1800 | static void iwl_unset_hw_setting(struct iwl_priv *priv) |
| 1801 | { |
| 1802 | if (priv->hw_setting.shared_virt) |
| 1803 | pci_free_consistent(priv->pci_dev, |
| 1804 | sizeof(struct iwl_shared), |
| 1805 | priv->hw_setting.shared_virt, |
| 1806 | priv->hw_setting.shared_phys); |
| 1807 | } |
| 1808 | |
| 1809 | /** |
| 1810 | * iwl_supported_rate_to_ie - fill in the supported rate in IE field |
| 1811 | * |
| 1812 | * return : set the bit for each supported rate insert in ie |
| 1813 | */ |
| 1814 | static u16 iwl_supported_rate_to_ie(u8 *ie, u16 supported_rate, |
| 1815 | u16 basic_rate, int max_count) |
| 1816 | { |
| 1817 | u16 ret_rates = 0, bit; |
| 1818 | int i; |
| 1819 | u8 *rates; |
| 1820 | |
| 1821 | rates = &(ie[1]); |
| 1822 | |
| 1823 | for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { |
| 1824 | if (bit & supported_rate) { |
| 1825 | ret_rates |= bit; |
| 1826 | rates[*ie] = iwl_rates[i].ieee | |
| 1827 | ((bit & basic_rate) ? 0x80 : 0x00); |
| 1828 | *ie = *ie + 1; |
| 1829 | if (*ie >= max_count) |
| 1830 | break; |
| 1831 | } |
| 1832 | } |
| 1833 | |
| 1834 | return ret_rates; |
| 1835 | } |
| 1836 | |
| 1837 | #ifdef CONFIG_IWLWIFI_HT |
| 1838 | void static iwl_set_ht_capab(struct ieee80211_hw *hw, |
| 1839 | struct ieee80211_ht_capability *ht_cap, |
| 1840 | u8 use_wide_chan); |
| 1841 | #endif |
| 1842 | |
| 1843 | /** |
| 1844 | * iwl_fill_probe_req - fill in all required fields and IE for probe request |
| 1845 | */ |
| 1846 | static u16 iwl_fill_probe_req(struct iwl_priv *priv, |
| 1847 | struct ieee80211_mgmt *frame, |
| 1848 | int left, int is_direct) |
| 1849 | { |
| 1850 | int len = 0; |
| 1851 | u8 *pos = NULL; |
| 1852 | u16 ret_rates; |
| 1853 | |
| 1854 | /* Make sure there is enough space for the probe request, |
| 1855 | * two mandatory IEs and the data */ |
| 1856 | left -= 24; |
| 1857 | if (left < 0) |
| 1858 | return 0; |
| 1859 | len += 24; |
| 1860 | |
| 1861 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
| 1862 | memcpy(frame->da, BROADCAST_ADDR, ETH_ALEN); |
| 1863 | memcpy(frame->sa, priv->mac_addr, ETH_ALEN); |
| 1864 | memcpy(frame->bssid, BROADCAST_ADDR, ETH_ALEN); |
| 1865 | frame->seq_ctrl = 0; |
| 1866 | |
| 1867 | /* fill in our indirect SSID IE */ |
| 1868 | /* ...next IE... */ |
| 1869 | |
| 1870 | left -= 2; |
| 1871 | if (left < 0) |
| 1872 | return 0; |
| 1873 | len += 2; |
| 1874 | pos = &(frame->u.probe_req.variable[0]); |
| 1875 | *pos++ = WLAN_EID_SSID; |
| 1876 | *pos++ = 0; |
| 1877 | |
| 1878 | /* fill in our direct SSID IE... */ |
| 1879 | if (is_direct) { |
| 1880 | /* ...next IE... */ |
| 1881 | left -= 2 + priv->essid_len; |
| 1882 | if (left < 0) |
| 1883 | return 0; |
| 1884 | /* ... fill it in... */ |
| 1885 | *pos++ = WLAN_EID_SSID; |
| 1886 | *pos++ = priv->essid_len; |
| 1887 | memcpy(pos, priv->essid, priv->essid_len); |
| 1888 | pos += priv->essid_len; |
| 1889 | len += 2 + priv->essid_len; |
| 1890 | } |
| 1891 | |
| 1892 | /* fill in supported rate */ |
| 1893 | /* ...next IE... */ |
| 1894 | left -= 2; |
| 1895 | if (left < 0) |
| 1896 | return 0; |
| 1897 | /* ... fill it in... */ |
| 1898 | *pos++ = WLAN_EID_SUPP_RATES; |
| 1899 | *pos = 0; |
| 1900 | ret_rates = priv->active_rate = priv->rates_mask; |
| 1901 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 1902 | |
| 1903 | iwl_supported_rate_to_ie(pos, priv->active_rate, |
| 1904 | priv->active_rate_basic, left); |
| 1905 | len += 2 + *pos; |
| 1906 | pos += (*pos) + 1; |
| 1907 | ret_rates = ~ret_rates & priv->active_rate; |
| 1908 | |
| 1909 | if (ret_rates == 0) |
| 1910 | goto fill_end; |
| 1911 | |
| 1912 | /* fill in supported extended rate */ |
| 1913 | /* ...next IE... */ |
| 1914 | left -= 2; |
| 1915 | if (left < 0) |
| 1916 | return 0; |
| 1917 | /* ... fill it in... */ |
| 1918 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 1919 | *pos = 0; |
| 1920 | iwl_supported_rate_to_ie(pos, ret_rates, priv->active_rate_basic, left); |
| 1921 | if (*pos > 0) |
| 1922 | len += 2 + *pos; |
| 1923 | |
| 1924 | #ifdef CONFIG_IWLWIFI_HT |
| 1925 | if (is_direct && priv->is_ht_enabled) { |
| 1926 | u8 use_wide_chan = 1; |
| 1927 | |
| 1928 | if (priv->channel_width != IWL_CHANNEL_WIDTH_40MHZ) |
| 1929 | use_wide_chan = 0; |
| 1930 | pos += (*pos) + 1; |
| 1931 | *pos++ = WLAN_EID_HT_CAPABILITY; |
| 1932 | *pos++ = sizeof(struct ieee80211_ht_capability); |
| 1933 | iwl_set_ht_capab(NULL, (struct ieee80211_ht_capability *)pos, |
| 1934 | use_wide_chan); |
| 1935 | len += 2 + sizeof(struct ieee80211_ht_capability); |
| 1936 | } |
| 1937 | #endif /*CONFIG_IWLWIFI_HT */ |
| 1938 | |
| 1939 | fill_end: |
| 1940 | return (u16)len; |
| 1941 | } |
| 1942 | |
| 1943 | /* |
| 1944 | * QoS support |
| 1945 | */ |
| 1946 | #ifdef CONFIG_IWLWIFI_QOS |
| 1947 | static int iwl_send_qos_params_command(struct iwl_priv *priv, |
| 1948 | struct iwl_qosparam_cmd *qos) |
| 1949 | { |
| 1950 | |
| 1951 | return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
| 1952 | sizeof(struct iwl_qosparam_cmd), qos); |
| 1953 | } |
| 1954 | |
| 1955 | static void iwl_reset_qos(struct iwl_priv *priv) |
| 1956 | { |
| 1957 | u16 cw_min = 15; |
| 1958 | u16 cw_max = 1023; |
| 1959 | u8 aifs = 2; |
| 1960 | u8 is_legacy = 0; |
| 1961 | unsigned long flags; |
| 1962 | int i; |
| 1963 | |
| 1964 | spin_lock_irqsave(&priv->lock, flags); |
| 1965 | priv->qos_data.qos_active = 0; |
| 1966 | |
| 1967 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) { |
| 1968 | if (priv->qos_data.qos_enable) |
| 1969 | priv->qos_data.qos_active = 1; |
| 1970 | if (!(priv->active_rate & 0xfff0)) { |
| 1971 | cw_min = 31; |
| 1972 | is_legacy = 1; |
| 1973 | } |
| 1974 | } else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 1975 | if (priv->qos_data.qos_enable) |
| 1976 | priv->qos_data.qos_active = 1; |
| 1977 | } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) { |
| 1978 | cw_min = 31; |
| 1979 | is_legacy = 1; |
| 1980 | } |
| 1981 | |
| 1982 | if (priv->qos_data.qos_active) |
| 1983 | aifs = 3; |
| 1984 | |
| 1985 | priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min); |
| 1986 | priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max); |
| 1987 | priv->qos_data.def_qos_parm.ac[0].aifsn = aifs; |
| 1988 | priv->qos_data.def_qos_parm.ac[0].edca_txop = 0; |
| 1989 | priv->qos_data.def_qos_parm.ac[0].reserved1 = 0; |
| 1990 | |
| 1991 | if (priv->qos_data.qos_active) { |
| 1992 | i = 1; |
| 1993 | priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min); |
| 1994 | priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max); |
| 1995 | priv->qos_data.def_qos_parm.ac[i].aifsn = 7; |
| 1996 | priv->qos_data.def_qos_parm.ac[i].edca_txop = 0; |
| 1997 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 1998 | |
| 1999 | i = 2; |
| 2000 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 2001 | cpu_to_le16((cw_min + 1) / 2 - 1); |
| 2002 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 2003 | cpu_to_le16(cw_max); |
| 2004 | priv->qos_data.def_qos_parm.ac[i].aifsn = 2; |
| 2005 | if (is_legacy) |
| 2006 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 2007 | cpu_to_le16(6016); |
| 2008 | else |
| 2009 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 2010 | cpu_to_le16(3008); |
| 2011 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 2012 | |
| 2013 | i = 3; |
| 2014 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 2015 | cpu_to_le16((cw_min + 1) / 4 - 1); |
| 2016 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 2017 | cpu_to_le16((cw_max + 1) / 2 - 1); |
| 2018 | priv->qos_data.def_qos_parm.ac[i].aifsn = 2; |
| 2019 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 2020 | if (is_legacy) |
| 2021 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 2022 | cpu_to_le16(3264); |
| 2023 | else |
| 2024 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 2025 | cpu_to_le16(1504); |
| 2026 | } else { |
| 2027 | for (i = 1; i < 4; i++) { |
| 2028 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 2029 | cpu_to_le16(cw_min); |
| 2030 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 2031 | cpu_to_le16(cw_max); |
| 2032 | priv->qos_data.def_qos_parm.ac[i].aifsn = aifs; |
| 2033 | priv->qos_data.def_qos_parm.ac[i].edca_txop = 0; |
| 2034 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 2035 | } |
| 2036 | } |
| 2037 | IWL_DEBUG_QOS("set QoS to default \n"); |
| 2038 | |
| 2039 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2040 | } |
| 2041 | |
| 2042 | static void iwl_activate_qos(struct iwl_priv *priv, u8 force) |
| 2043 | { |
| 2044 | unsigned long flags; |
| 2045 | |
| 2046 | if (priv == NULL) |
| 2047 | return; |
| 2048 | |
| 2049 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 2050 | return; |
| 2051 | |
| 2052 | if (!priv->qos_data.qos_enable) |
| 2053 | return; |
| 2054 | |
| 2055 | spin_lock_irqsave(&priv->lock, flags); |
| 2056 | priv->qos_data.def_qos_parm.qos_flags = 0; |
| 2057 | |
| 2058 | if (priv->qos_data.qos_cap.q_AP.queue_request && |
| 2059 | !priv->qos_data.qos_cap.q_AP.txop_request) |
| 2060 | priv->qos_data.def_qos_parm.qos_flags |= |
| 2061 | QOS_PARAM_FLG_TXOP_TYPE_MSK; |
| 2062 | |
| 2063 | if (priv->qos_data.qos_active) |
| 2064 | priv->qos_data.def_qos_parm.qos_flags |= |
| 2065 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 2066 | |
| 2067 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2068 | |
| 2069 | if (force || iwl_is_associated(priv)) { |
| 2070 | IWL_DEBUG_QOS("send QoS cmd with Qos active %d \n", |
| 2071 | priv->qos_data.qos_active); |
| 2072 | |
| 2073 | iwl_send_qos_params_command(priv, |
| 2074 | &(priv->qos_data.def_qos_parm)); |
| 2075 | } |
| 2076 | } |
| 2077 | |
| 2078 | #endif /* CONFIG_IWLWIFI_QOS */ |
| 2079 | /* |
| 2080 | * Power management (not Tx power!) functions |
| 2081 | */ |
| 2082 | #define MSEC_TO_USEC 1024 |
| 2083 | |
| 2084 | #define NOSLP __constant_cpu_to_le16(0), 0, 0 |
| 2085 | #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0 |
| 2086 | #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC) |
| 2087 | #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \ |
| 2088 | __constant_cpu_to_le32(X1), \ |
| 2089 | __constant_cpu_to_le32(X2), \ |
| 2090 | __constant_cpu_to_le32(X3), \ |
| 2091 | __constant_cpu_to_le32(X4)} |
| 2092 | |
| 2093 | |
| 2094 | /* default power management (not Tx power) table values */ |
| 2095 | /* for tim 0-10 */ |
| 2096 | static struct iwl_power_vec_entry range_0[IWL_POWER_AC] = { |
| 2097 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 2098 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0}, |
| 2099 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0}, |
| 2100 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0}, |
| 2101 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1}, |
| 2102 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1} |
| 2103 | }; |
| 2104 | |
| 2105 | /* for tim > 10 */ |
| 2106 | static struct iwl_power_vec_entry range_1[IWL_POWER_AC] = { |
| 2107 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 2108 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), |
| 2109 | SLP_VEC(1, 2, 3, 4, 0xFF)}, 0}, |
| 2110 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), |
| 2111 | SLP_VEC(2, 4, 6, 7, 0xFF)}, 0}, |
| 2112 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), |
| 2113 | SLP_VEC(2, 6, 9, 9, 0xFF)}, 0}, |
| 2114 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0}, |
| 2115 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), |
| 2116 | SLP_VEC(4, 7, 10, 10, 0xFF)}, 0} |
| 2117 | }; |
| 2118 | |
| 2119 | int iwl_power_init_handle(struct iwl_priv *priv) |
| 2120 | { |
| 2121 | int rc = 0, i; |
| 2122 | struct iwl_power_mgr *pow_data; |
| 2123 | int size = sizeof(struct iwl_power_vec_entry) * IWL_POWER_AC; |
| 2124 | u16 pci_pm; |
| 2125 | |
| 2126 | IWL_DEBUG_POWER("Initialize power \n"); |
| 2127 | |
| 2128 | pow_data = &(priv->power_data); |
| 2129 | |
| 2130 | memset(pow_data, 0, sizeof(*pow_data)); |
| 2131 | |
| 2132 | pow_data->active_index = IWL_POWER_RANGE_0; |
| 2133 | pow_data->dtim_val = 0xffff; |
| 2134 | |
| 2135 | memcpy(&pow_data->pwr_range_0[0], &range_0[0], size); |
| 2136 | memcpy(&pow_data->pwr_range_1[0], &range_1[0], size); |
| 2137 | |
| 2138 | rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm); |
| 2139 | if (rc != 0) |
| 2140 | return 0; |
| 2141 | else { |
| 2142 | struct iwl_powertable_cmd *cmd; |
| 2143 | |
| 2144 | IWL_DEBUG_POWER("adjust power command flags\n"); |
| 2145 | |
| 2146 | for (i = 0; i < IWL_POWER_AC; i++) { |
| 2147 | cmd = &pow_data->pwr_range_0[i].cmd; |
| 2148 | |
| 2149 | if (pci_pm & 0x1) |
| 2150 | cmd->flags &= ~IWL_POWER_PCI_PM_MSK; |
| 2151 | else |
| 2152 | cmd->flags |= IWL_POWER_PCI_PM_MSK; |
| 2153 | } |
| 2154 | } |
| 2155 | return rc; |
| 2156 | } |
| 2157 | |
| 2158 | static int iwl_update_power_cmd(struct iwl_priv *priv, |
| 2159 | struct iwl_powertable_cmd *cmd, u32 mode) |
| 2160 | { |
| 2161 | int rc = 0, i; |
| 2162 | u8 skip; |
| 2163 | u32 max_sleep = 0; |
| 2164 | struct iwl_power_vec_entry *range; |
| 2165 | u8 period = 0; |
| 2166 | struct iwl_power_mgr *pow_data; |
| 2167 | |
| 2168 | if (mode > IWL_POWER_INDEX_5) { |
| 2169 | IWL_DEBUG_POWER("Error invalid power mode \n"); |
| 2170 | return -1; |
| 2171 | } |
| 2172 | pow_data = &(priv->power_data); |
| 2173 | |
| 2174 | if (pow_data->active_index == IWL_POWER_RANGE_0) |
| 2175 | range = &pow_data->pwr_range_0[0]; |
| 2176 | else |
| 2177 | range = &pow_data->pwr_range_1[1]; |
| 2178 | |
| 2179 | memcpy(cmd, &range[mode].cmd, sizeof(struct iwl_powertable_cmd)); |
| 2180 | |
| 2181 | #ifdef IWL_MAC80211_DISABLE |
| 2182 | if (priv->assoc_network != NULL) { |
| 2183 | unsigned long flags; |
| 2184 | |
| 2185 | period = priv->assoc_network->tim.tim_period; |
| 2186 | } |
| 2187 | #endif /*IWL_MAC80211_DISABLE */ |
| 2188 | skip = range[mode].no_dtim; |
| 2189 | |
| 2190 | if (period == 0) { |
| 2191 | period = 1; |
| 2192 | skip = 0; |
| 2193 | } |
| 2194 | |
| 2195 | if (skip == 0) { |
| 2196 | max_sleep = period; |
| 2197 | cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 2198 | } else { |
| 2199 | __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]; |
| 2200 | max_sleep = (le32_to_cpu(slp_itrvl) / period) * period; |
| 2201 | cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 2202 | } |
| 2203 | |
| 2204 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) { |
| 2205 | if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep) |
| 2206 | cmd->sleep_interval[i] = cpu_to_le32(max_sleep); |
| 2207 | } |
| 2208 | |
| 2209 | IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags); |
| 2210 | IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout)); |
| 2211 | IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout)); |
| 2212 | IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n", |
| 2213 | le32_to_cpu(cmd->sleep_interval[0]), |
| 2214 | le32_to_cpu(cmd->sleep_interval[1]), |
| 2215 | le32_to_cpu(cmd->sleep_interval[2]), |
| 2216 | le32_to_cpu(cmd->sleep_interval[3]), |
| 2217 | le32_to_cpu(cmd->sleep_interval[4])); |
| 2218 | |
| 2219 | return rc; |
| 2220 | } |
| 2221 | |
| 2222 | static int iwl_send_power_mode(struct iwl_priv *priv, u32 mode) |
| 2223 | { |
| 2224 | u32 final_mode = mode; |
| 2225 | int rc; |
| 2226 | struct iwl_powertable_cmd cmd; |
| 2227 | |
| 2228 | /* If on battery, set to 3, |
| 2229 | * if plugged into AC power, set to CAM ("continuosly aware mode"), |
| 2230 | * else user level */ |
| 2231 | switch (mode) { |
| 2232 | case IWL_POWER_BATTERY: |
| 2233 | final_mode = IWL_POWER_INDEX_3; |
| 2234 | break; |
| 2235 | case IWL_POWER_AC: |
| 2236 | final_mode = IWL_POWER_MODE_CAM; |
| 2237 | break; |
| 2238 | default: |
| 2239 | final_mode = mode; |
| 2240 | break; |
| 2241 | } |
| 2242 | |
| 2243 | cmd.keep_alive_beacons = 0; |
| 2244 | |
| 2245 | iwl_update_power_cmd(priv, &cmd, final_mode); |
| 2246 | |
| 2247 | rc = iwl_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd); |
| 2248 | |
| 2249 | if (final_mode == IWL_POWER_MODE_CAM) |
| 2250 | clear_bit(STATUS_POWER_PMI, &priv->status); |
| 2251 | else |
| 2252 | set_bit(STATUS_POWER_PMI, &priv->status); |
| 2253 | |
| 2254 | return rc; |
| 2255 | } |
| 2256 | |
| 2257 | int iwl_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *header) |
| 2258 | { |
| 2259 | /* Filter incoming packets to determine if they are targeted toward |
| 2260 | * this network, discarding packets coming from ourselves */ |
| 2261 | switch (priv->iw_mode) { |
| 2262 | case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */ |
| 2263 | /* packets from our adapter are dropped (echo) */ |
| 2264 | if (!compare_ether_addr(header->addr2, priv->mac_addr)) |
| 2265 | return 0; |
| 2266 | /* {broad,multi}cast packets to our IBSS go through */ |
| 2267 | if (is_multicast_ether_addr(header->addr1)) |
| 2268 | return !compare_ether_addr(header->addr3, priv->bssid); |
| 2269 | /* packets to our adapter go through */ |
| 2270 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 2271 | case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */ |
| 2272 | /* packets from our adapter are dropped (echo) */ |
| 2273 | if (!compare_ether_addr(header->addr3, priv->mac_addr)) |
| 2274 | return 0; |
| 2275 | /* {broad,multi}cast packets to our BSS go through */ |
| 2276 | if (is_multicast_ether_addr(header->addr1)) |
| 2277 | return !compare_ether_addr(header->addr2, priv->bssid); |
| 2278 | /* packets to our adapter go through */ |
| 2279 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 2280 | } |
| 2281 | |
| 2282 | return 1; |
| 2283 | } |
| 2284 | |
| 2285 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 2286 | |
| 2287 | const char *iwl_get_tx_fail_reason(u32 status) |
| 2288 | { |
| 2289 | switch (status & TX_STATUS_MSK) { |
| 2290 | case TX_STATUS_SUCCESS: |
| 2291 | return "SUCCESS"; |
| 2292 | TX_STATUS_ENTRY(SHORT_LIMIT); |
| 2293 | TX_STATUS_ENTRY(LONG_LIMIT); |
| 2294 | TX_STATUS_ENTRY(FIFO_UNDERRUN); |
| 2295 | TX_STATUS_ENTRY(MGMNT_ABORT); |
| 2296 | TX_STATUS_ENTRY(NEXT_FRAG); |
| 2297 | TX_STATUS_ENTRY(LIFE_EXPIRE); |
| 2298 | TX_STATUS_ENTRY(DEST_PS); |
| 2299 | TX_STATUS_ENTRY(ABORTED); |
| 2300 | TX_STATUS_ENTRY(BT_RETRY); |
| 2301 | TX_STATUS_ENTRY(STA_INVALID); |
| 2302 | TX_STATUS_ENTRY(FRAG_DROPPED); |
| 2303 | TX_STATUS_ENTRY(TID_DISABLE); |
| 2304 | TX_STATUS_ENTRY(FRAME_FLUSHED); |
| 2305 | TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL); |
| 2306 | TX_STATUS_ENTRY(TX_LOCKED); |
| 2307 | TX_STATUS_ENTRY(NO_BEACON_ON_RADAR); |
| 2308 | } |
| 2309 | |
| 2310 | return "UNKNOWN"; |
| 2311 | } |
| 2312 | |
| 2313 | /** |
| 2314 | * iwl_scan_cancel - Cancel any currently executing HW scan |
| 2315 | * |
| 2316 | * NOTE: priv->mutex is not required before calling this function |
| 2317 | */ |
| 2318 | static int iwl_scan_cancel(struct iwl_priv *priv) |
| 2319 | { |
| 2320 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 2321 | clear_bit(STATUS_SCANNING, &priv->status); |
| 2322 | return 0; |
| 2323 | } |
| 2324 | |
| 2325 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 2326 | if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2327 | IWL_DEBUG_SCAN("Queuing scan abort.\n"); |
| 2328 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 2329 | queue_work(priv->workqueue, &priv->abort_scan); |
| 2330 | |
| 2331 | } else |
| 2332 | IWL_DEBUG_SCAN("Scan abort already in progress.\n"); |
| 2333 | |
| 2334 | return test_bit(STATUS_SCANNING, &priv->status); |
| 2335 | } |
| 2336 | |
| 2337 | return 0; |
| 2338 | } |
| 2339 | |
| 2340 | /** |
| 2341 | * iwl_scan_cancel_timeout - Cancel any currently executing HW scan |
| 2342 | * @ms: amount of time to wait (in milliseconds) for scan to abort |
| 2343 | * |
| 2344 | * NOTE: priv->mutex must be held before calling this function |
| 2345 | */ |
| 2346 | static int iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms) |
| 2347 | { |
| 2348 | unsigned long now = jiffies; |
| 2349 | int ret; |
| 2350 | |
| 2351 | ret = iwl_scan_cancel(priv); |
| 2352 | if (ret && ms) { |
| 2353 | mutex_unlock(&priv->mutex); |
| 2354 | while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && |
| 2355 | test_bit(STATUS_SCANNING, &priv->status)) |
| 2356 | msleep(1); |
| 2357 | mutex_lock(&priv->mutex); |
| 2358 | |
| 2359 | return test_bit(STATUS_SCANNING, &priv->status); |
| 2360 | } |
| 2361 | |
| 2362 | return ret; |
| 2363 | } |
| 2364 | |
| 2365 | static void iwl_sequence_reset(struct iwl_priv *priv) |
| 2366 | { |
| 2367 | /* Reset ieee stats */ |
| 2368 | |
| 2369 | /* We don't reset the net_device_stats (ieee->stats) on |
| 2370 | * re-association */ |
| 2371 | |
| 2372 | priv->last_seq_num = -1; |
| 2373 | priv->last_frag_num = -1; |
| 2374 | priv->last_packet_time = 0; |
| 2375 | |
| 2376 | iwl_scan_cancel(priv); |
| 2377 | } |
| 2378 | |
| 2379 | #define MAX_UCODE_BEACON_INTERVAL 4096 |
| 2380 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) |
| 2381 | |
| 2382 | static __le16 iwl_adjust_beacon_interval(u16 beacon_val) |
| 2383 | { |
| 2384 | u16 new_val = 0; |
| 2385 | u16 beacon_factor = 0; |
| 2386 | |
| 2387 | beacon_factor = |
| 2388 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 2389 | / MAX_UCODE_BEACON_INTERVAL; |
| 2390 | new_val = beacon_val / beacon_factor; |
| 2391 | |
| 2392 | return cpu_to_le16(new_val); |
| 2393 | } |
| 2394 | |
| 2395 | static void iwl_setup_rxon_timing(struct iwl_priv *priv) |
| 2396 | { |
| 2397 | u64 interval_tm_unit; |
| 2398 | u64 tsf, result; |
| 2399 | unsigned long flags; |
| 2400 | struct ieee80211_conf *conf = NULL; |
| 2401 | u16 beacon_int = 0; |
| 2402 | |
| 2403 | conf = ieee80211_get_hw_conf(priv->hw); |
| 2404 | |
| 2405 | spin_lock_irqsave(&priv->lock, flags); |
| 2406 | priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp1); |
| 2407 | priv->rxon_timing.timestamp.dw[0] = cpu_to_le32(priv->timestamp0); |
| 2408 | |
| 2409 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 2410 | |
| 2411 | tsf = priv->timestamp1; |
| 2412 | tsf = ((tsf << 32) | priv->timestamp0); |
| 2413 | |
| 2414 | beacon_int = priv->beacon_int; |
| 2415 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2416 | |
| 2417 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) { |
| 2418 | if (beacon_int == 0) { |
| 2419 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 2420 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 2421 | } else { |
| 2422 | priv->rxon_timing.beacon_interval = |
| 2423 | cpu_to_le16(beacon_int); |
| 2424 | priv->rxon_timing.beacon_interval = |
| 2425 | iwl_adjust_beacon_interval( |
| 2426 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2427 | } |
| 2428 | |
| 2429 | priv->rxon_timing.atim_window = 0; |
| 2430 | } else { |
| 2431 | priv->rxon_timing.beacon_interval = |
| 2432 | iwl_adjust_beacon_interval(conf->beacon_int); |
| 2433 | /* TODO: we need to get atim_window from upper stack |
| 2434 | * for now we set to 0 */ |
| 2435 | priv->rxon_timing.atim_window = 0; |
| 2436 | } |
| 2437 | |
| 2438 | interval_tm_unit = |
| 2439 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 2440 | result = do_div(tsf, interval_tm_unit); |
| 2441 | priv->rxon_timing.beacon_init_val = |
| 2442 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 2443 | |
| 2444 | IWL_DEBUG_ASSOC |
| 2445 | ("beacon interval %d beacon timer %d beacon tim %d\n", |
| 2446 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 2447 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 2448 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 2449 | } |
| 2450 | |
| 2451 | static int iwl_scan_initiate(struct iwl_priv *priv) |
| 2452 | { |
| 2453 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 2454 | IWL_ERROR("APs don't scan.\n"); |
| 2455 | return 0; |
| 2456 | } |
| 2457 | |
| 2458 | if (!iwl_is_ready_rf(priv)) { |
| 2459 | IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); |
| 2460 | return -EIO; |
| 2461 | } |
| 2462 | |
| 2463 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 2464 | IWL_DEBUG_SCAN("Scan already in progress.\n"); |
| 2465 | return -EAGAIN; |
| 2466 | } |
| 2467 | |
| 2468 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2469 | IWL_DEBUG_SCAN("Scan request while abort pending. " |
| 2470 | "Queuing.\n"); |
| 2471 | return -EAGAIN; |
| 2472 | } |
| 2473 | |
| 2474 | IWL_DEBUG_INFO("Starting scan...\n"); |
| 2475 | priv->scan_bands = 2; |
| 2476 | set_bit(STATUS_SCANNING, &priv->status); |
| 2477 | priv->scan_start = jiffies; |
| 2478 | priv->scan_pass_start = priv->scan_start; |
| 2479 | |
| 2480 | queue_work(priv->workqueue, &priv->request_scan); |
| 2481 | |
| 2482 | return 0; |
| 2483 | } |
| 2484 | |
| 2485 | static int iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt) |
| 2486 | { |
| 2487 | struct iwl_rxon_cmd *rxon = &priv->staging_rxon; |
| 2488 | |
| 2489 | if (hw_decrypt) |
| 2490 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 2491 | else |
| 2492 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 2493 | |
| 2494 | return 0; |
| 2495 | } |
| 2496 | |
| 2497 | static void iwl_set_flags_for_phymode(struct iwl_priv *priv, u8 phymode) |
| 2498 | { |
| 2499 | if (phymode == MODE_IEEE80211A) { |
| 2500 | priv->staging_rxon.flags &= |
| 2501 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 2502 | | RXON_FLG_CCK_MSK); |
| 2503 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 2504 | } else { |
| 2505 | /* Copied from iwl_bg_post_associate() */ |
| 2506 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 2507 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 2508 | else |
| 2509 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 2510 | |
| 2511 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 2512 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 2513 | |
| 2514 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 2515 | priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 2516 | priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK; |
| 2517 | } |
| 2518 | } |
| 2519 | |
| 2520 | /* |
| 2521 | * initilize rxon structure with default values fromm eeprom |
| 2522 | */ |
| 2523 | static void iwl_connection_init_rx_config(struct iwl_priv *priv) |
| 2524 | { |
| 2525 | const struct iwl_channel_info *ch_info; |
| 2526 | |
| 2527 | memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); |
| 2528 | |
| 2529 | switch (priv->iw_mode) { |
| 2530 | case IEEE80211_IF_TYPE_AP: |
| 2531 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP; |
| 2532 | break; |
| 2533 | |
| 2534 | case IEEE80211_IF_TYPE_STA: |
| 2535 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS; |
| 2536 | priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
| 2537 | break; |
| 2538 | |
| 2539 | case IEEE80211_IF_TYPE_IBSS: |
| 2540 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS; |
| 2541 | priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2542 | priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
| 2543 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 2544 | break; |
| 2545 | |
| 2546 | case IEEE80211_IF_TYPE_MNTR: |
| 2547 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; |
| 2548 | priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | |
| 2549 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; |
| 2550 | break; |
| 2551 | } |
| 2552 | |
| 2553 | #if 0 |
| 2554 | /* TODO: Figure out when short_preamble would be set and cache from |
| 2555 | * that */ |
| 2556 | if (!hw_to_local(priv->hw)->short_preamble) |
| 2557 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2558 | else |
| 2559 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2560 | #endif |
| 2561 | |
| 2562 | ch_info = iwl_get_channel_info(priv, priv->phymode, |
| 2563 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2564 | |
| 2565 | if (!ch_info) |
| 2566 | ch_info = &priv->channel_info[0]; |
| 2567 | |
| 2568 | /* |
| 2569 | * in some case A channels are all non IBSS |
| 2570 | * in this case force B/G channel |
| 2571 | */ |
| 2572 | if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && |
| 2573 | !(is_channel_ibss(ch_info))) |
| 2574 | ch_info = &priv->channel_info[0]; |
| 2575 | |
| 2576 | priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); |
| 2577 | if (is_channel_a_band(ch_info)) |
| 2578 | priv->phymode = MODE_IEEE80211A; |
| 2579 | else |
| 2580 | priv->phymode = MODE_IEEE80211G; |
| 2581 | |
| 2582 | iwl_set_flags_for_phymode(priv, priv->phymode); |
| 2583 | |
| 2584 | priv->staging_rxon.ofdm_basic_rates = |
| 2585 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2586 | priv->staging_rxon.cck_basic_rates = |
| 2587 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2588 | |
| 2589 | priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK | |
| 2590 | RXON_FLG_CHANNEL_MODE_PURE_40_MSK); |
| 2591 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 2592 | memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN); |
| 2593 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff; |
| 2594 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff; |
| 2595 | iwl4965_set_rxon_chain(priv); |
| 2596 | } |
| 2597 | |
| 2598 | static int iwl_set_mode(struct iwl_priv *priv, int mode) |
| 2599 | { |
| 2600 | if (!iwl_is_ready_rf(priv)) |
| 2601 | return -EAGAIN; |
| 2602 | |
| 2603 | if (mode == IEEE80211_IF_TYPE_IBSS) { |
| 2604 | const struct iwl_channel_info *ch_info; |
| 2605 | |
| 2606 | ch_info = iwl_get_channel_info(priv, |
| 2607 | priv->phymode, |
| 2608 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2609 | |
| 2610 | if (!ch_info || !is_channel_ibss(ch_info)) { |
| 2611 | IWL_ERROR("channel %d not IBSS channel\n", |
| 2612 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2613 | return -EINVAL; |
| 2614 | } |
| 2615 | } |
| 2616 | |
| 2617 | cancel_delayed_work(&priv->scan_check); |
| 2618 | if (iwl_scan_cancel_timeout(priv, 100)) { |
| 2619 | IWL_WARNING("Aborted scan still in progress after 100ms\n"); |
| 2620 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 2621 | return -EAGAIN; |
| 2622 | } |
| 2623 | |
| 2624 | priv->iw_mode = mode; |
| 2625 | |
| 2626 | iwl_connection_init_rx_config(priv); |
| 2627 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 2628 | |
| 2629 | iwl_clear_stations_table(priv); |
| 2630 | |
| 2631 | iwl_commit_rxon(priv); |
| 2632 | |
| 2633 | return 0; |
| 2634 | } |
| 2635 | |
| 2636 | static void iwl_build_tx_cmd_hwcrypto(struct iwl_priv *priv, |
| 2637 | struct ieee80211_tx_control *ctl, |
| 2638 | struct iwl_cmd *cmd, |
| 2639 | struct sk_buff *skb_frag, |
| 2640 | int last_frag) |
| 2641 | { |
| 2642 | struct iwl_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo; |
| 2643 | |
| 2644 | switch (keyinfo->alg) { |
| 2645 | case ALG_CCMP: |
| 2646 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM; |
| 2647 | memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen); |
| 2648 | IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n"); |
| 2649 | break; |
| 2650 | |
| 2651 | case ALG_TKIP: |
| 2652 | #if 0 |
| 2653 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP; |
| 2654 | |
| 2655 | if (last_frag) |
| 2656 | memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8, |
| 2657 | 8); |
| 2658 | else |
| 2659 | memset(cmd->cmd.tx.tkip_mic.byte, 0, 8); |
| 2660 | #endif |
| 2661 | break; |
| 2662 | |
| 2663 | case ALG_WEP: |
| 2664 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP | |
| 2665 | (ctl->key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT; |
| 2666 | |
| 2667 | if (keyinfo->keylen == 13) |
| 2668 | cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128; |
| 2669 | |
| 2670 | memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen); |
| 2671 | |
| 2672 | IWL_DEBUG_TX("Configuring packet for WEP encryption " |
| 2673 | "with key %d\n", ctl->key_idx); |
| 2674 | break; |
| 2675 | |
| 2676 | case ALG_NONE: |
| 2677 | IWL_DEBUG_TX("Tx packet in the clear (encrypt requested).\n"); |
| 2678 | break; |
| 2679 | |
| 2680 | default: |
| 2681 | printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg); |
| 2682 | break; |
| 2683 | } |
| 2684 | } |
| 2685 | |
| 2686 | /* |
| 2687 | * handle build REPLY_TX command notification. |
| 2688 | */ |
| 2689 | static void iwl_build_tx_cmd_basic(struct iwl_priv *priv, |
| 2690 | struct iwl_cmd *cmd, |
| 2691 | struct ieee80211_tx_control *ctrl, |
| 2692 | struct ieee80211_hdr *hdr, |
| 2693 | int is_unicast, u8 std_id) |
| 2694 | { |
| 2695 | __le16 *qc; |
| 2696 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 2697 | __le32 tx_flags = cmd->cmd.tx.tx_flags; |
| 2698 | |
| 2699 | cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 2700 | if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) { |
| 2701 | tx_flags |= TX_CMD_FLG_ACK_MSK; |
| 2702 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) |
| 2703 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2704 | if (ieee80211_is_probe_response(fc) && |
| 2705 | !(le16_to_cpu(hdr->seq_ctrl) & 0xf)) |
| 2706 | tx_flags |= TX_CMD_FLG_TSF_MSK; |
| 2707 | } else { |
| 2708 | tx_flags &= (~TX_CMD_FLG_ACK_MSK); |
| 2709 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2710 | } |
| 2711 | |
| 2712 | cmd->cmd.tx.sta_id = std_id; |
| 2713 | if (ieee80211_get_morefrag(hdr)) |
| 2714 | tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; |
| 2715 | |
| 2716 | qc = ieee80211_get_qos_ctrl(hdr); |
| 2717 | if (qc) { |
| 2718 | cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf); |
| 2719 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; |
| 2720 | } else |
| 2721 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2722 | |
| 2723 | if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) { |
| 2724 | tx_flags |= TX_CMD_FLG_RTS_MSK; |
| 2725 | tx_flags &= ~TX_CMD_FLG_CTS_MSK; |
| 2726 | } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) { |
| 2727 | tx_flags &= ~TX_CMD_FLG_RTS_MSK; |
| 2728 | tx_flags |= TX_CMD_FLG_CTS_MSK; |
| 2729 | } |
| 2730 | |
| 2731 | if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK)) |
| 2732 | tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK; |
| 2733 | |
| 2734 | tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); |
| 2735 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { |
| 2736 | if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ || |
| 2737 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) |
| 2738 | cmd->cmd.tx.timeout.pm_frame_timeout = |
| 2739 | cpu_to_le16(3); |
| 2740 | else |
| 2741 | cmd->cmd.tx.timeout.pm_frame_timeout = |
| 2742 | cpu_to_le16(2); |
| 2743 | } else |
| 2744 | cmd->cmd.tx.timeout.pm_frame_timeout = 0; |
| 2745 | |
| 2746 | cmd->cmd.tx.driver_txop = 0; |
| 2747 | cmd->cmd.tx.tx_flags = tx_flags; |
| 2748 | cmd->cmd.tx.next_frame_len = 0; |
| 2749 | } |
| 2750 | |
| 2751 | static int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr) |
| 2752 | { |
| 2753 | int sta_id; |
| 2754 | u16 fc = le16_to_cpu(hdr->frame_control); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2755 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2756 | |
| 2757 | /* If this frame is broadcast or not data then use the broadcast |
| 2758 | * station id */ |
| 2759 | if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || |
| 2760 | is_multicast_ether_addr(hdr->addr1)) |
| 2761 | return priv->hw_setting.bcast_sta_id; |
| 2762 | |
| 2763 | switch (priv->iw_mode) { |
| 2764 | |
| 2765 | /* If this frame is part of a BSS network (we're a station), then |
| 2766 | * we use the AP's station id */ |
| 2767 | case IEEE80211_IF_TYPE_STA: |
| 2768 | return IWL_AP_ID; |
| 2769 | |
| 2770 | /* If we are an AP, then find the station, or use BCAST */ |
| 2771 | case IEEE80211_IF_TYPE_AP: |
| 2772 | sta_id = iwl_hw_find_station(priv, hdr->addr1); |
| 2773 | if (sta_id != IWL_INVALID_STATION) |
| 2774 | return sta_id; |
| 2775 | return priv->hw_setting.bcast_sta_id; |
| 2776 | |
| 2777 | /* If this frame is part of a IBSS network, then we use the |
| 2778 | * target specific station id */ |
| 2779 | case IEEE80211_IF_TYPE_IBSS: |
| 2780 | sta_id = iwl_hw_find_station(priv, hdr->addr1); |
| 2781 | if (sta_id != IWL_INVALID_STATION) |
| 2782 | return sta_id; |
| 2783 | |
| 2784 | sta_id = iwl_add_station(priv, hdr->addr1, 0, CMD_ASYNC); |
| 2785 | |
| 2786 | if (sta_id != IWL_INVALID_STATION) |
| 2787 | return sta_id; |
| 2788 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2789 | IWL_DEBUG_DROP("Station %s not in station map. " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2790 | "Defaulting to broadcast...\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2791 | print_mac(mac, hdr->addr1)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2792 | iwl_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); |
| 2793 | return priv->hw_setting.bcast_sta_id; |
| 2794 | |
| 2795 | default: |
| 2796 | IWL_WARNING("Unkown mode of operation: %d", priv->iw_mode); |
| 2797 | return priv->hw_setting.bcast_sta_id; |
| 2798 | } |
| 2799 | } |
| 2800 | |
| 2801 | /* |
| 2802 | * start REPLY_TX command process |
| 2803 | */ |
| 2804 | static int iwl_tx_skb(struct iwl_priv *priv, |
| 2805 | struct sk_buff *skb, struct ieee80211_tx_control *ctl) |
| 2806 | { |
| 2807 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 2808 | struct iwl_tfd_frame *tfd; |
| 2809 | u32 *control_flags; |
| 2810 | int txq_id = ctl->queue; |
| 2811 | struct iwl_tx_queue *txq = NULL; |
| 2812 | struct iwl_queue *q = NULL; |
| 2813 | dma_addr_t phys_addr; |
| 2814 | dma_addr_t txcmd_phys; |
| 2815 | struct iwl_cmd *out_cmd = NULL; |
| 2816 | u16 len, idx, len_org; |
| 2817 | u8 id, hdr_len, unicast; |
| 2818 | u8 sta_id; |
| 2819 | u16 seq_number = 0; |
| 2820 | u16 fc; |
| 2821 | __le16 *qc; |
| 2822 | u8 wait_write_ptr = 0; |
| 2823 | unsigned long flags; |
| 2824 | int rc; |
| 2825 | |
| 2826 | spin_lock_irqsave(&priv->lock, flags); |
| 2827 | if (iwl_is_rfkill(priv)) { |
| 2828 | IWL_DEBUG_DROP("Dropping - RF KILL\n"); |
| 2829 | goto drop_unlock; |
| 2830 | } |
| 2831 | |
| 2832 | if (!priv->interface_id) { |
| 2833 | IWL_DEBUG_DROP("Dropping - !priv->interface_id\n"); |
| 2834 | goto drop_unlock; |
| 2835 | } |
| 2836 | |
| 2837 | if ((ctl->tx_rate & 0xFF) == IWL_INVALID_RATE) { |
| 2838 | IWL_ERROR("ERROR: No TX rate available.\n"); |
| 2839 | goto drop_unlock; |
| 2840 | } |
| 2841 | |
| 2842 | unicast = !is_multicast_ether_addr(hdr->addr1); |
| 2843 | id = 0; |
| 2844 | |
| 2845 | fc = le16_to_cpu(hdr->frame_control); |
| 2846 | |
| 2847 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 2848 | if (ieee80211_is_auth(fc)) |
| 2849 | IWL_DEBUG_TX("Sending AUTH frame\n"); |
| 2850 | else if (ieee80211_is_assoc_request(fc)) |
| 2851 | IWL_DEBUG_TX("Sending ASSOC frame\n"); |
| 2852 | else if (ieee80211_is_reassoc_request(fc)) |
| 2853 | IWL_DEBUG_TX("Sending REASSOC frame\n"); |
| 2854 | #endif |
| 2855 | |
| 2856 | if (!iwl_is_associated(priv) && |
| 2857 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) { |
| 2858 | IWL_DEBUG_DROP("Dropping - !iwl_is_associated\n"); |
| 2859 | goto drop_unlock; |
| 2860 | } |
| 2861 | |
| 2862 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2863 | |
| 2864 | hdr_len = ieee80211_get_hdrlen(fc); |
| 2865 | sta_id = iwl_get_sta_id(priv, hdr); |
| 2866 | if (sta_id == IWL_INVALID_STATION) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2867 | DECLARE_MAC_BUF(mac); |
| 2868 | |
| 2869 | IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n", |
| 2870 | print_mac(mac, hdr->addr1)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2871 | goto drop; |
| 2872 | } |
| 2873 | |
| 2874 | IWL_DEBUG_RATE("station Id %d\n", sta_id); |
| 2875 | |
| 2876 | qc = ieee80211_get_qos_ctrl(hdr); |
| 2877 | if (qc) { |
| 2878 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 2879 | seq_number = priv->stations[sta_id].tid[tid].seq_number & |
| 2880 | IEEE80211_SCTL_SEQ; |
| 2881 | hdr->seq_ctrl = cpu_to_le16(seq_number) | |
| 2882 | (hdr->seq_ctrl & |
| 2883 | __constant_cpu_to_le16(IEEE80211_SCTL_FRAG)); |
| 2884 | seq_number += 0x10; |
| 2885 | #ifdef CONFIG_IWLWIFI_HT |
| 2886 | #ifdef CONFIG_IWLWIFI_HT_AGG |
| 2887 | /* aggregation is on for this <sta,tid> */ |
| 2888 | if (ctl->flags & IEEE80211_TXCTL_HT_MPDU_AGG) |
| 2889 | txq_id = priv->stations[sta_id].tid[tid].agg.txq_id; |
| 2890 | #endif /* CONFIG_IWLWIFI_HT_AGG */ |
| 2891 | #endif /* CONFIG_IWLWIFI_HT */ |
| 2892 | } |
| 2893 | txq = &priv->txq[txq_id]; |
| 2894 | q = &txq->q; |
| 2895 | |
| 2896 | spin_lock_irqsave(&priv->lock, flags); |
| 2897 | |
| 2898 | tfd = &txq->bd[q->first_empty]; |
| 2899 | memset(tfd, 0, sizeof(*tfd)); |
| 2900 | control_flags = (u32 *) tfd; |
| 2901 | idx = get_cmd_index(q, q->first_empty, 0); |
| 2902 | |
| 2903 | memset(&(txq->txb[q->first_empty]), 0, sizeof(struct iwl_tx_info)); |
| 2904 | txq->txb[q->first_empty].skb[0] = skb; |
| 2905 | memcpy(&(txq->txb[q->first_empty].status.control), |
| 2906 | ctl, sizeof(struct ieee80211_tx_control)); |
| 2907 | out_cmd = &txq->cmd[idx]; |
| 2908 | memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); |
| 2909 | memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx)); |
| 2910 | out_cmd->hdr.cmd = REPLY_TX; |
| 2911 | out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) | |
| 2912 | INDEX_TO_SEQ(q->first_empty))); |
| 2913 | /* copy frags header */ |
| 2914 | memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len); |
| 2915 | |
| 2916 | /* hdr = (struct ieee80211_hdr *)out_cmd->cmd.tx.hdr; */ |
| 2917 | len = priv->hw_setting.tx_cmd_len + |
| 2918 | sizeof(struct iwl_cmd_header) + hdr_len; |
| 2919 | |
| 2920 | len_org = len; |
| 2921 | len = (len + 3) & ~3; |
| 2922 | |
| 2923 | if (len_org != len) |
| 2924 | len_org = 1; |
| 2925 | else |
| 2926 | len_org = 0; |
| 2927 | |
| 2928 | txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl_cmd) * idx + |
| 2929 | offsetof(struct iwl_cmd, hdr); |
| 2930 | |
| 2931 | iwl_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); |
| 2932 | |
| 2933 | if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)) |
| 2934 | iwl_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0); |
| 2935 | |
| 2936 | /* 802.11 null functions have no payload... */ |
| 2937 | len = skb->len - hdr_len; |
| 2938 | if (len) { |
| 2939 | phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len, |
| 2940 | len, PCI_DMA_TODEVICE); |
| 2941 | iwl_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len); |
| 2942 | } |
| 2943 | |
| 2944 | if (len_org) |
| 2945 | out_cmd->cmd.tx.tx_flags |= TX_CMD_FLG_MH_PAD_MSK; |
| 2946 | |
| 2947 | len = (u16)skb->len; |
| 2948 | out_cmd->cmd.tx.len = cpu_to_le16(len); |
| 2949 | |
| 2950 | /* TODO need this for burst mode later on */ |
| 2951 | iwl_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id); |
| 2952 | |
| 2953 | /* set is_hcca to 0; it probably will never be implemented */ |
| 2954 | iwl_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0); |
| 2955 | |
| 2956 | iwl4965_tx_cmd(priv, out_cmd, sta_id, txcmd_phys, |
| 2957 | hdr, hdr_len, ctl, NULL); |
| 2958 | |
| 2959 | if (!ieee80211_get_morefrag(hdr)) { |
| 2960 | txq->need_update = 1; |
| 2961 | if (qc) { |
| 2962 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 2963 | priv->stations[sta_id].tid[tid].seq_number = seq_number; |
| 2964 | } |
| 2965 | } else { |
| 2966 | wait_write_ptr = 1; |
| 2967 | txq->need_update = 0; |
| 2968 | } |
| 2969 | |
| 2970 | iwl_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload, |
| 2971 | sizeof(out_cmd->cmd.tx)); |
| 2972 | |
| 2973 | iwl_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr, |
| 2974 | ieee80211_get_hdrlen(fc)); |
| 2975 | |
| 2976 | iwl4965_tx_queue_update_wr_ptr(priv, txq, len); |
| 2977 | |
| 2978 | q->first_empty = iwl_queue_inc_wrap(q->first_empty, q->n_bd); |
| 2979 | rc = iwl_tx_queue_update_write_ptr(priv, txq); |
| 2980 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2981 | |
| 2982 | if (rc) |
| 2983 | return rc; |
| 2984 | |
| 2985 | if ((iwl_queue_space(q) < q->high_mark) |
| 2986 | && priv->mac80211_registered) { |
| 2987 | if (wait_write_ptr) { |
| 2988 | spin_lock_irqsave(&priv->lock, flags); |
| 2989 | txq->need_update = 1; |
| 2990 | iwl_tx_queue_update_write_ptr(priv, txq); |
| 2991 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2992 | } |
| 2993 | |
| 2994 | ieee80211_stop_queue(priv->hw, ctl->queue); |
| 2995 | } |
| 2996 | |
| 2997 | return 0; |
| 2998 | |
| 2999 | drop_unlock: |
| 3000 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3001 | drop: |
| 3002 | return -1; |
| 3003 | } |
| 3004 | |
| 3005 | static void iwl_set_rate(struct iwl_priv *priv) |
| 3006 | { |
| 3007 | const struct ieee80211_hw_mode *hw = NULL; |
| 3008 | struct ieee80211_rate *rate; |
| 3009 | int i; |
| 3010 | |
| 3011 | hw = iwl_get_hw_mode(priv, priv->phymode); |
| 3012 | |
| 3013 | priv->active_rate = 0; |
| 3014 | priv->active_rate_basic = 0; |
| 3015 | |
| 3016 | IWL_DEBUG_RATE("Setting rates for 802.11%c\n", |
| 3017 | hw->mode == MODE_IEEE80211A ? |
| 3018 | 'a' : ((hw->mode == MODE_IEEE80211B) ? 'b' : 'g')); |
| 3019 | |
| 3020 | for (i = 0; i < hw->num_rates; i++) { |
| 3021 | rate = &(hw->rates[i]); |
| 3022 | if ((rate->val < IWL_RATE_COUNT) && |
| 3023 | (rate->flags & IEEE80211_RATE_SUPPORTED)) { |
| 3024 | IWL_DEBUG_RATE("Adding rate index %d (plcp %d)%s\n", |
| 3025 | rate->val, iwl_rates[rate->val].plcp, |
| 3026 | (rate->flags & IEEE80211_RATE_BASIC) ? |
| 3027 | "*" : ""); |
| 3028 | priv->active_rate |= (1 << rate->val); |
| 3029 | if (rate->flags & IEEE80211_RATE_BASIC) |
| 3030 | priv->active_rate_basic |= (1 << rate->val); |
| 3031 | } else |
| 3032 | IWL_DEBUG_RATE("Not adding rate %d (plcp %d)\n", |
| 3033 | rate->val, iwl_rates[rate->val].plcp); |
| 3034 | } |
| 3035 | |
| 3036 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", |
| 3037 | priv->active_rate, priv->active_rate_basic); |
| 3038 | |
| 3039 | /* |
| 3040 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) |
| 3041 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for |
| 3042 | * OFDM |
| 3043 | */ |
| 3044 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) |
| 3045 | priv->staging_rxon.cck_basic_rates = |
| 3046 | ((priv->active_rate_basic & |
| 3047 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; |
| 3048 | else |
| 3049 | priv->staging_rxon.cck_basic_rates = |
| 3050 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 3051 | |
| 3052 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) |
| 3053 | priv->staging_rxon.ofdm_basic_rates = |
| 3054 | ((priv->active_rate_basic & |
| 3055 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> |
| 3056 | IWL_FIRST_OFDM_RATE) & 0xFF; |
| 3057 | else |
| 3058 | priv->staging_rxon.ofdm_basic_rates = |
| 3059 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 3060 | } |
| 3061 | |
| 3062 | static void iwl_radio_kill_sw(struct iwl_priv *priv, int disable_radio) |
| 3063 | { |
| 3064 | unsigned long flags; |
| 3065 | |
| 3066 | if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status)) |
| 3067 | return; |
| 3068 | |
| 3069 | IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n", |
| 3070 | disable_radio ? "OFF" : "ON"); |
| 3071 | |
| 3072 | if (disable_radio) { |
| 3073 | iwl_scan_cancel(priv); |
| 3074 | /* FIXME: This is a workaround for AP */ |
| 3075 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 3076 | spin_lock_irqsave(&priv->lock, flags); |
| 3077 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
| 3078 | CSR_UCODE_SW_BIT_RFKILL); |
| 3079 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3080 | iwl_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0); |
| 3081 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3082 | } |
| 3083 | return; |
| 3084 | } |
| 3085 | |
| 3086 | spin_lock_irqsave(&priv->lock, flags); |
| 3087 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 3088 | |
| 3089 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3090 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3091 | |
| 3092 | /* wake up ucode */ |
| 3093 | msleep(10); |
| 3094 | |
| 3095 | spin_lock_irqsave(&priv->lock, flags); |
| 3096 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 3097 | if (!iwl_grab_restricted_access(priv)) |
| 3098 | iwl_release_restricted_access(priv); |
| 3099 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3100 | |
| 3101 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 3102 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 3103 | "disabled by HW switch\n"); |
| 3104 | return; |
| 3105 | } |
| 3106 | |
| 3107 | queue_work(priv->workqueue, &priv->restart); |
| 3108 | return; |
| 3109 | } |
| 3110 | |
| 3111 | void iwl_set_decrypted_flag(struct iwl_priv *priv, struct sk_buff *skb, |
| 3112 | u32 decrypt_res, struct ieee80211_rx_status *stats) |
| 3113 | { |
| 3114 | u16 fc = |
| 3115 | le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control); |
| 3116 | |
| 3117 | if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK) |
| 3118 | return; |
| 3119 | |
| 3120 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 3121 | return; |
| 3122 | |
| 3123 | IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res); |
| 3124 | switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) { |
| 3125 | case RX_RES_STATUS_SEC_TYPE_TKIP: |
| 3126 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 3127 | RX_RES_STATUS_BAD_ICV_MIC) |
| 3128 | stats->flag |= RX_FLAG_MMIC_ERROR; |
| 3129 | case RX_RES_STATUS_SEC_TYPE_WEP: |
| 3130 | case RX_RES_STATUS_SEC_TYPE_CCMP: |
| 3131 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 3132 | RX_RES_STATUS_DECRYPT_OK) { |
| 3133 | IWL_DEBUG_RX("hw decrypt successfully!!!\n"); |
| 3134 | stats->flag |= RX_FLAG_DECRYPTED; |
| 3135 | } |
| 3136 | break; |
| 3137 | |
| 3138 | default: |
| 3139 | break; |
| 3140 | } |
| 3141 | } |
| 3142 | |
| 3143 | void iwl_handle_data_packet_monitor(struct iwl_priv *priv, |
| 3144 | struct iwl_rx_mem_buffer *rxb, |
| 3145 | void *data, short len, |
| 3146 | struct ieee80211_rx_status *stats, |
| 3147 | u16 phy_flags) |
| 3148 | { |
| 3149 | struct iwl_rt_rx_hdr *iwl_rt; |
| 3150 | |
| 3151 | /* First cache any information we need before we overwrite |
| 3152 | * the information provided in the skb from the hardware */ |
| 3153 | s8 signal = stats->ssi; |
| 3154 | s8 noise = 0; |
| 3155 | int rate = stats->rate; |
| 3156 | u64 tsf = stats->mactime; |
| 3157 | __le16 phy_flags_hw = cpu_to_le16(phy_flags); |
| 3158 | |
| 3159 | /* We received data from the HW, so stop the watchdog */ |
| 3160 | if (len > IWL_RX_BUF_SIZE - sizeof(*iwl_rt)) { |
| 3161 | IWL_DEBUG_DROP("Dropping too large packet in monitor\n"); |
| 3162 | return; |
| 3163 | } |
| 3164 | |
| 3165 | /* copy the frame data to write after where the radiotap header goes */ |
| 3166 | iwl_rt = (void *)rxb->skb->data; |
| 3167 | memmove(iwl_rt->payload, data, len); |
| 3168 | |
| 3169 | iwl_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 3170 | iwl_rt->rt_hdr.it_pad = 0; /* always good to zero */ |
| 3171 | |
| 3172 | /* total header + data */ |
| 3173 | iwl_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*iwl_rt)); |
| 3174 | |
| 3175 | /* Set the size of the skb to the size of the frame */ |
| 3176 | skb_put(rxb->skb, sizeof(*iwl_rt) + len); |
| 3177 | |
| 3178 | /* Big bitfield of all the fields we provide in radiotap */ |
| 3179 | iwl_rt->rt_hdr.it_present = |
| 3180 | cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) | |
| 3181 | (1 << IEEE80211_RADIOTAP_FLAGS) | |
| 3182 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 3183 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 3184 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | |
| 3185 | (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | |
| 3186 | (1 << IEEE80211_RADIOTAP_ANTENNA)); |
| 3187 | |
| 3188 | /* Zero the flags, we'll add to them as we go */ |
| 3189 | iwl_rt->rt_flags = 0; |
| 3190 | |
| 3191 | iwl_rt->rt_tsf = cpu_to_le64(tsf); |
| 3192 | |
| 3193 | /* Convert to dBm */ |
| 3194 | iwl_rt->rt_dbmsignal = signal; |
| 3195 | iwl_rt->rt_dbmnoise = noise; |
| 3196 | |
| 3197 | /* Convert the channel frequency and set the flags */ |
| 3198 | iwl_rt->rt_channelMHz = cpu_to_le16(stats->freq); |
| 3199 | if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK)) |
| 3200 | iwl_rt->rt_chbitmask = |
| 3201 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); |
| 3202 | else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK) |
| 3203 | iwl_rt->rt_chbitmask = |
| 3204 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); |
| 3205 | else /* 802.11g */ |
| 3206 | iwl_rt->rt_chbitmask = |
| 3207 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ)); |
| 3208 | |
| 3209 | rate = iwl_rate_index_from_plcp(rate); |
| 3210 | if (rate == -1) |
| 3211 | iwl_rt->rt_rate = 0; |
| 3212 | else |
| 3213 | iwl_rt->rt_rate = iwl_rates[rate].ieee; |
| 3214 | |
| 3215 | /* antenna number */ |
| 3216 | iwl_rt->rt_antenna = |
| 3217 | le16_to_cpu(phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK) >> 4; |
| 3218 | |
| 3219 | /* set the preamble flag if we have it */ |
| 3220 | if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK) |
| 3221 | iwl_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; |
| 3222 | |
| 3223 | IWL_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); |
| 3224 | |
| 3225 | stats->flag |= RX_FLAG_RADIOTAP; |
| 3226 | ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats); |
| 3227 | rxb->skb = NULL; |
| 3228 | } |
| 3229 | |
| 3230 | |
| 3231 | #define IWL_PACKET_RETRY_TIME HZ |
| 3232 | |
| 3233 | int is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header) |
| 3234 | { |
| 3235 | u16 sc = le16_to_cpu(header->seq_ctrl); |
| 3236 | u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 3237 | u16 frag = sc & IEEE80211_SCTL_FRAG; |
| 3238 | u16 *last_seq, *last_frag; |
| 3239 | unsigned long *last_time; |
| 3240 | |
| 3241 | switch (priv->iw_mode) { |
| 3242 | case IEEE80211_IF_TYPE_IBSS:{ |
| 3243 | struct list_head *p; |
| 3244 | struct iwl_ibss_seq *entry = NULL; |
| 3245 | u8 *mac = header->addr2; |
| 3246 | int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1); |
| 3247 | |
| 3248 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
| 3249 | entry = |
| 3250 | list_entry(p, struct iwl_ibss_seq, list); |
| 3251 | if (!compare_ether_addr(entry->mac, mac)) |
| 3252 | break; |
| 3253 | } |
| 3254 | if (p == &priv->ibss_mac_hash[index]) { |
| 3255 | entry = kzalloc(sizeof(*entry), GFP_ATOMIC); |
| 3256 | if (!entry) { |
| 3257 | IWL_ERROR |
| 3258 | ("Cannot malloc new mac entry\n"); |
| 3259 | return 0; |
| 3260 | } |
| 3261 | memcpy(entry->mac, mac, ETH_ALEN); |
| 3262 | entry->seq_num = seq; |
| 3263 | entry->frag_num = frag; |
| 3264 | entry->packet_time = jiffies; |
| 3265 | list_add(&entry->list, |
| 3266 | &priv->ibss_mac_hash[index]); |
| 3267 | return 0; |
| 3268 | } |
| 3269 | last_seq = &entry->seq_num; |
| 3270 | last_frag = &entry->frag_num; |
| 3271 | last_time = &entry->packet_time; |
| 3272 | break; |
| 3273 | } |
| 3274 | case IEEE80211_IF_TYPE_STA: |
| 3275 | last_seq = &priv->last_seq_num; |
| 3276 | last_frag = &priv->last_frag_num; |
| 3277 | last_time = &priv->last_packet_time; |
| 3278 | break; |
| 3279 | default: |
| 3280 | return 0; |
| 3281 | } |
| 3282 | if ((*last_seq == seq) && |
| 3283 | time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) { |
| 3284 | if (*last_frag == frag) |
| 3285 | goto drop; |
| 3286 | if (*last_frag + 1 != frag) |
| 3287 | /* out-of-order fragment */ |
| 3288 | goto drop; |
| 3289 | } else |
| 3290 | *last_seq = seq; |
| 3291 | |
| 3292 | *last_frag = frag; |
| 3293 | *last_time = jiffies; |
| 3294 | return 0; |
| 3295 | |
| 3296 | drop: |
| 3297 | return 1; |
| 3298 | } |
| 3299 | |
| 3300 | #ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT |
| 3301 | |
| 3302 | #include "iwl-spectrum.h" |
| 3303 | |
| 3304 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 3305 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 3306 | #define TIME_UNIT 1024 |
| 3307 | |
| 3308 | /* |
| 3309 | * extended beacon time format |
| 3310 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 3311 | * the high 1 byte is the beacon counts |
| 3312 | * the lower 3 bytes is the time in usec within one beacon interval |
| 3313 | */ |
| 3314 | |
| 3315 | static u32 iwl_usecs_to_beacons(u32 usec, u32 beacon_interval) |
| 3316 | { |
| 3317 | u32 quot; |
| 3318 | u32 rem; |
| 3319 | u32 interval = beacon_interval * 1024; |
| 3320 | |
| 3321 | if (!interval || !usec) |
| 3322 | return 0; |
| 3323 | |
| 3324 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 3325 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 3326 | |
| 3327 | return (quot << 24) + rem; |
| 3328 | } |
| 3329 | |
| 3330 | /* base is usually what we get from ucode with each received frame, |
| 3331 | * the same as HW timer counter counting down |
| 3332 | */ |
| 3333 | |
| 3334 | static __le32 iwl_add_beacon_time(u32 base, u32 addon, u32 beacon_interval) |
| 3335 | { |
| 3336 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 3337 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 3338 | u32 interval = beacon_interval * TIME_UNIT; |
| 3339 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 3340 | (addon & BEACON_TIME_MASK_HIGH); |
| 3341 | |
| 3342 | if (base_low > addon_low) |
| 3343 | res += base_low - addon_low; |
| 3344 | else if (base_low < addon_low) { |
| 3345 | res += interval + base_low - addon_low; |
| 3346 | res += (1 << 24); |
| 3347 | } else |
| 3348 | res += (1 << 24); |
| 3349 | |
| 3350 | return cpu_to_le32(res); |
| 3351 | } |
| 3352 | |
| 3353 | static int iwl_get_measurement(struct iwl_priv *priv, |
| 3354 | struct ieee80211_measurement_params *params, |
| 3355 | u8 type) |
| 3356 | { |
| 3357 | struct iwl_spectrum_cmd spectrum; |
| 3358 | struct iwl_rx_packet *res; |
| 3359 | struct iwl_host_cmd cmd = { |
| 3360 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 3361 | .data = (void *)&spectrum, |
| 3362 | .meta.flags = CMD_WANT_SKB, |
| 3363 | }; |
| 3364 | u32 add_time = le64_to_cpu(params->start_time); |
| 3365 | int rc; |
| 3366 | int spectrum_resp_status; |
| 3367 | int duration = le16_to_cpu(params->duration); |
| 3368 | |
| 3369 | if (iwl_is_associated(priv)) |
| 3370 | add_time = |
| 3371 | iwl_usecs_to_beacons( |
| 3372 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 3373 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 3374 | |
| 3375 | memset(&spectrum, 0, sizeof(spectrum)); |
| 3376 | |
| 3377 | spectrum.channel_count = cpu_to_le16(1); |
| 3378 | spectrum.flags = |
| 3379 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 3380 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 3381 | cmd.len = sizeof(spectrum); |
| 3382 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 3383 | |
| 3384 | if (iwl_is_associated(priv)) |
| 3385 | spectrum.start_time = |
| 3386 | iwl_add_beacon_time(priv->last_beacon_time, |
| 3387 | add_time, |
| 3388 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 3389 | else |
| 3390 | spectrum.start_time = 0; |
| 3391 | |
| 3392 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 3393 | spectrum.channels[0].channel = params->channel; |
| 3394 | spectrum.channels[0].type = type; |
| 3395 | if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 3396 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 3397 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 3398 | |
| 3399 | rc = iwl_send_cmd_sync(priv, &cmd); |
| 3400 | if (rc) |
| 3401 | return rc; |
| 3402 | |
| 3403 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
| 3404 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 3405 | IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n"); |
| 3406 | rc = -EIO; |
| 3407 | } |
| 3408 | |
| 3409 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 3410 | switch (spectrum_resp_status) { |
| 3411 | case 0: /* Command will be handled */ |
| 3412 | if (res->u.spectrum.id != 0xff) { |
| 3413 | IWL_DEBUG_INFO |
| 3414 | ("Replaced existing measurement: %d\n", |
| 3415 | res->u.spectrum.id); |
| 3416 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 3417 | } |
| 3418 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 3419 | rc = 0; |
| 3420 | break; |
| 3421 | |
| 3422 | case 1: /* Command will not be handled */ |
| 3423 | rc = -EAGAIN; |
| 3424 | break; |
| 3425 | } |
| 3426 | |
| 3427 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 3428 | |
| 3429 | return rc; |
| 3430 | } |
| 3431 | #endif |
| 3432 | |
| 3433 | static void iwl_txstatus_to_ieee(struct iwl_priv *priv, |
| 3434 | struct iwl_tx_info *tx_sta) |
| 3435 | { |
| 3436 | |
| 3437 | tx_sta->status.ack_signal = 0; |
| 3438 | tx_sta->status.excessive_retries = 0; |
| 3439 | tx_sta->status.queue_length = 0; |
| 3440 | tx_sta->status.queue_number = 0; |
| 3441 | |
| 3442 | if (in_interrupt()) |
| 3443 | ieee80211_tx_status_irqsafe(priv->hw, |
| 3444 | tx_sta->skb[0], &(tx_sta->status)); |
| 3445 | else |
| 3446 | ieee80211_tx_status(priv->hw, |
| 3447 | tx_sta->skb[0], &(tx_sta->status)); |
| 3448 | |
| 3449 | tx_sta->skb[0] = NULL; |
| 3450 | } |
| 3451 | |
| 3452 | /** |
| 3453 | * iwl_tx_queue_reclaim - Reclaim Tx queue entries no more used by NIC. |
| 3454 | * |
| 3455 | * When FW advances 'R' index, all entries between old and |
| 3456 | * new 'R' index need to be reclaimed. As result, some free space |
| 3457 | * forms. If there is enough free space (> low mark), wake Tx queue. |
| 3458 | */ |
| 3459 | int iwl_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index) |
| 3460 | { |
| 3461 | struct iwl_tx_queue *txq = &priv->txq[txq_id]; |
| 3462 | struct iwl_queue *q = &txq->q; |
| 3463 | int nfreed = 0; |
| 3464 | |
| 3465 | if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) { |
| 3466 | IWL_ERROR("Read index for DMA queue txq id (%d), index %d, " |
| 3467 | "is out of range [0-%d] %d %d.\n", txq_id, |
| 3468 | index, q->n_bd, q->first_empty, q->last_used); |
| 3469 | return 0; |
| 3470 | } |
| 3471 | |
| 3472 | for (index = iwl_queue_inc_wrap(index, q->n_bd); |
| 3473 | q->last_used != index; |
| 3474 | q->last_used = iwl_queue_inc_wrap(q->last_used, q->n_bd)) { |
| 3475 | if (txq_id != IWL_CMD_QUEUE_NUM) { |
| 3476 | iwl_txstatus_to_ieee(priv, |
| 3477 | &(txq->txb[txq->q.last_used])); |
| 3478 | iwl_hw_txq_free_tfd(priv, txq); |
| 3479 | } else if (nfreed > 1) { |
| 3480 | IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index, |
| 3481 | q->first_empty, q->last_used); |
| 3482 | queue_work(priv->workqueue, &priv->restart); |
| 3483 | } |
| 3484 | nfreed++; |
| 3485 | } |
| 3486 | |
| 3487 | if (iwl_queue_space(q) > q->low_mark && (txq_id >= 0) && |
| 3488 | (txq_id != IWL_CMD_QUEUE_NUM) && |
| 3489 | priv->mac80211_registered) |
| 3490 | ieee80211_wake_queue(priv->hw, txq_id); |
| 3491 | |
| 3492 | |
| 3493 | return nfreed; |
| 3494 | } |
| 3495 | |
| 3496 | static int iwl_is_tx_success(u32 status) |
| 3497 | { |
| 3498 | status &= TX_STATUS_MSK; |
| 3499 | return (status == TX_STATUS_SUCCESS) |
| 3500 | || (status == TX_STATUS_DIRECT_DONE); |
| 3501 | } |
| 3502 | |
| 3503 | /****************************************************************************** |
| 3504 | * |
| 3505 | * Generic RX handler implementations |
| 3506 | * |
| 3507 | ******************************************************************************/ |
| 3508 | #ifdef CONFIG_IWLWIFI_HT |
| 3509 | #ifdef CONFIG_IWLWIFI_HT_AGG |
| 3510 | |
| 3511 | static inline int iwl_get_ra_sta_id(struct iwl_priv *priv, |
| 3512 | struct ieee80211_hdr *hdr) |
| 3513 | { |
| 3514 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) |
| 3515 | return IWL_AP_ID; |
| 3516 | else { |
| 3517 | u8 *da = ieee80211_get_DA(hdr); |
| 3518 | return iwl_hw_find_station(priv, da); |
| 3519 | } |
| 3520 | } |
| 3521 | |
| 3522 | static struct ieee80211_hdr *iwl_tx_queue_get_hdr( |
| 3523 | struct iwl_priv *priv, int txq_id, int idx) |
| 3524 | { |
| 3525 | if (priv->txq[txq_id].txb[idx].skb[0]) |
| 3526 | return (struct ieee80211_hdr *)priv->txq[txq_id]. |
| 3527 | txb[idx].skb[0]->data; |
| 3528 | return NULL; |
| 3529 | } |
| 3530 | |
| 3531 | static inline u32 iwl_get_scd_ssn(struct iwl_tx_resp *tx_resp) |
| 3532 | { |
| 3533 | __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status + |
| 3534 | tx_resp->frame_count); |
| 3535 | return le32_to_cpu(*scd_ssn) & MAX_SN; |
| 3536 | |
| 3537 | } |
| 3538 | static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv, |
| 3539 | struct iwl_ht_agg *agg, |
| 3540 | struct iwl_tx_resp *tx_resp, |
| 3541 | u16 start_idx) |
| 3542 | { |
| 3543 | u32 status; |
| 3544 | __le32 *frame_status = &tx_resp->status; |
| 3545 | struct ieee80211_tx_status *tx_status = NULL; |
| 3546 | struct ieee80211_hdr *hdr = NULL; |
| 3547 | int i, sh; |
| 3548 | int txq_id, idx; |
| 3549 | u16 seq; |
| 3550 | |
| 3551 | if (agg->wait_for_ba) |
| 3552 | IWL_DEBUG_TX_REPLY("got tx repsons w/o back\n"); |
| 3553 | |
| 3554 | agg->frame_count = tx_resp->frame_count; |
| 3555 | agg->start_idx = start_idx; |
| 3556 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
| 3557 | agg->bitmap0 = agg->bitmap1 = 0; |
| 3558 | |
| 3559 | if (agg->frame_count == 1) { |
| 3560 | struct iwl_tx_queue *txq ; |
| 3561 | status = le32_to_cpu(frame_status[0]); |
| 3562 | |
| 3563 | txq_id = agg->txq_id; |
| 3564 | txq = &priv->txq[txq_id]; |
| 3565 | /* FIXME: code repetition */ |
| 3566 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d \n", |
| 3567 | agg->frame_count, agg->start_idx); |
| 3568 | |
| 3569 | tx_status = &(priv->txq[txq_id].txb[txq->q.last_used].status); |
| 3570 | tx_status->retry_count = tx_resp->failure_frame; |
| 3571 | tx_status->queue_number = status & 0xff; |
| 3572 | tx_status->queue_length = tx_resp->bt_kill_count; |
| 3573 | tx_status->queue_length |= tx_resp->failure_rts; |
| 3574 | |
| 3575 | tx_status->flags = iwl_is_tx_success(status)? |
| 3576 | IEEE80211_TX_STATUS_ACK : 0; |
| 3577 | tx_status->control.tx_rate = |
| 3578 | iwl_hw_get_rate_n_flags(tx_resp->rate_n_flags); |
| 3579 | /* FIXME: code repetition end */ |
| 3580 | |
| 3581 | IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n", |
| 3582 | status & 0xff, tx_resp->failure_frame); |
| 3583 | IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", |
| 3584 | iwl_hw_get_rate_n_flags(tx_resp->rate_n_flags)); |
| 3585 | |
| 3586 | agg->wait_for_ba = 0; |
| 3587 | } else { |
| 3588 | u64 bitmap = 0; |
| 3589 | int start = agg->start_idx; |
| 3590 | |
| 3591 | for (i = 0; i < agg->frame_count; i++) { |
| 3592 | u16 sc; |
| 3593 | status = le32_to_cpu(frame_status[i]); |
| 3594 | seq = status >> 16; |
| 3595 | idx = SEQ_TO_INDEX(seq); |
| 3596 | txq_id = SEQ_TO_QUEUE(seq); |
| 3597 | |
| 3598 | if (status & (AGG_TX_STATE_FEW_BYTES_MSK | |
| 3599 | AGG_TX_STATE_ABORT_MSK)) |
| 3600 | continue; |
| 3601 | |
| 3602 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n", |
| 3603 | agg->frame_count, txq_id, idx); |
| 3604 | |
| 3605 | hdr = iwl_tx_queue_get_hdr(priv, txq_id, idx); |
| 3606 | |
| 3607 | sc = le16_to_cpu(hdr->seq_ctrl); |
| 3608 | if (idx != (SEQ_TO_SN(sc) & 0xff)) { |
| 3609 | IWL_ERROR("BUG_ON idx doesn't match seq control" |
| 3610 | " idx=%d, seq_idx=%d, seq=%d\n", |
| 3611 | idx, SEQ_TO_SN(sc), |
| 3612 | hdr->seq_ctrl); |
| 3613 | return -1; |
| 3614 | } |
| 3615 | |
| 3616 | IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n", |
| 3617 | i, idx, SEQ_TO_SN(sc)); |
| 3618 | |
| 3619 | sh = idx - start; |
| 3620 | if (sh > 64) { |
| 3621 | sh = (start - idx) + 0xff; |
| 3622 | bitmap = bitmap << sh; |
| 3623 | sh = 0; |
| 3624 | start = idx; |
| 3625 | } else if (sh < -64) |
| 3626 | sh = 0xff - (start - idx); |
| 3627 | else if (sh < 0) { |
| 3628 | sh = start - idx; |
| 3629 | start = idx; |
| 3630 | bitmap = bitmap << sh; |
| 3631 | sh = 0; |
| 3632 | } |
| 3633 | bitmap |= (1 << sh); |
| 3634 | IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n", |
| 3635 | start, (u32)(bitmap & 0xFFFFFFFF)); |
| 3636 | } |
| 3637 | |
| 3638 | agg->bitmap0 = bitmap & 0xFFFFFFFF; |
| 3639 | agg->bitmap1 = bitmap >> 32; |
| 3640 | agg->start_idx = start; |
| 3641 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
| 3642 | IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%x\n", |
| 3643 | agg->frame_count, agg->start_idx, |
| 3644 | agg->bitmap0); |
| 3645 | |
| 3646 | if (bitmap) |
| 3647 | agg->wait_for_ba = 1; |
| 3648 | } |
| 3649 | return 0; |
| 3650 | } |
| 3651 | #endif |
| 3652 | #endif |
| 3653 | |
| 3654 | static void iwl_rx_reply_tx(struct iwl_priv *priv, |
| 3655 | struct iwl_rx_mem_buffer *rxb) |
| 3656 | { |
| 3657 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
| 3658 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 3659 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 3660 | int index = SEQ_TO_INDEX(sequence); |
| 3661 | struct iwl_tx_queue *txq = &priv->txq[txq_id]; |
| 3662 | struct ieee80211_tx_status *tx_status; |
| 3663 | struct iwl_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; |
| 3664 | u32 status = le32_to_cpu(tx_resp->status); |
| 3665 | #ifdef CONFIG_IWLWIFI_HT |
| 3666 | #ifdef CONFIG_IWLWIFI_HT_AGG |
| 3667 | int tid, sta_id; |
| 3668 | #endif |
| 3669 | #endif |
| 3670 | |
| 3671 | if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) { |
| 3672 | IWL_ERROR("Read index for DMA queue txq_id (%d) index %d " |
| 3673 | "is out of range [0-%d] %d %d\n", txq_id, |
| 3674 | index, txq->q.n_bd, txq->q.first_empty, |
| 3675 | txq->q.last_used); |
| 3676 | return; |
| 3677 | } |
| 3678 | |
| 3679 | #ifdef CONFIG_IWLWIFI_HT |
| 3680 | #ifdef CONFIG_IWLWIFI_HT_AGG |
| 3681 | if (txq->sched_retry) { |
| 3682 | const u32 scd_ssn = iwl_get_scd_ssn(tx_resp); |
| 3683 | struct ieee80211_hdr *hdr = |
| 3684 | iwl_tx_queue_get_hdr(priv, txq_id, index); |
| 3685 | struct iwl_ht_agg *agg = NULL; |
| 3686 | __le16 *qc = ieee80211_get_qos_ctrl(hdr); |
| 3687 | |
| 3688 | if (qc == NULL) { |
| 3689 | IWL_ERROR("BUG_ON qc is null!!!!\n"); |
| 3690 | return; |
| 3691 | } |
| 3692 | |
| 3693 | tid = le16_to_cpu(*qc) & 0xf; |
| 3694 | |
| 3695 | sta_id = iwl_get_ra_sta_id(priv, hdr); |
| 3696 | if (unlikely(sta_id == IWL_INVALID_STATION)) { |
| 3697 | IWL_ERROR("Station not known for\n"); |
| 3698 | return; |
| 3699 | } |
| 3700 | |
| 3701 | agg = &priv->stations[sta_id].tid[tid].agg; |
| 3702 | |
| 3703 | iwl4965_tx_status_reply_tx(priv, agg, tx_resp, index); |
| 3704 | |
| 3705 | if ((tx_resp->frame_count == 1) && |
| 3706 | !iwl_is_tx_success(status)) { |
| 3707 | /* TODO: send BAR */ |
| 3708 | } |
| 3709 | |
| 3710 | if ((txq->q.last_used != (scd_ssn & 0xff))) { |
| 3711 | index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd); |
| 3712 | IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn " |
| 3713 | "%d index %d\n", scd_ssn , index); |
| 3714 | iwl_tx_queue_reclaim(priv, txq_id, index); |
| 3715 | } |
| 3716 | } else { |
| 3717 | #endif /* CONFIG_IWLWIFI_HT_AGG */ |
| 3718 | #endif /* CONFIG_IWLWIFI_HT */ |
| 3719 | tx_status = &(txq->txb[txq->q.last_used].status); |
| 3720 | |
| 3721 | tx_status->retry_count = tx_resp->failure_frame; |
| 3722 | tx_status->queue_number = status; |
| 3723 | tx_status->queue_length = tx_resp->bt_kill_count; |
| 3724 | tx_status->queue_length |= tx_resp->failure_rts; |
| 3725 | |
| 3726 | tx_status->flags = |
| 3727 | iwl_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0; |
| 3728 | |
| 3729 | tx_status->control.tx_rate = |
| 3730 | iwl_hw_get_rate_n_flags(tx_resp->rate_n_flags); |
| 3731 | |
| 3732 | IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x " |
| 3733 | "retries %d\n", txq_id, iwl_get_tx_fail_reason(status), |
| 3734 | status, le32_to_cpu(tx_resp->rate_n_flags), |
| 3735 | tx_resp->failure_frame); |
| 3736 | |
| 3737 | IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index); |
| 3738 | if (index != -1) |
| 3739 | iwl_tx_queue_reclaim(priv, txq_id, index); |
| 3740 | #ifdef CONFIG_IWLWIFI_HT |
| 3741 | #ifdef CONFIG_IWLWIFI_HT_AGG |
| 3742 | } |
| 3743 | #endif /* CONFIG_IWLWIFI_HT_AGG */ |
| 3744 | #endif /* CONFIG_IWLWIFI_HT */ |
| 3745 | |
| 3746 | if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK)) |
| 3747 | IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n"); |
| 3748 | } |
| 3749 | |
| 3750 | |
| 3751 | static void iwl_rx_reply_alive(struct iwl_priv *priv, |
| 3752 | struct iwl_rx_mem_buffer *rxb) |
| 3753 | { |
| 3754 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
| 3755 | struct iwl_alive_resp *palive; |
| 3756 | struct delayed_work *pwork; |
| 3757 | |
| 3758 | palive = &pkt->u.alive_frame; |
| 3759 | |
| 3760 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " |
| 3761 | "0x%01X 0x%01X\n", |
| 3762 | palive->is_valid, palive->ver_type, |
| 3763 | palive->ver_subtype); |
| 3764 | |
| 3765 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
| 3766 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
| 3767 | memcpy(&priv->card_alive_init, |
| 3768 | &pkt->u.alive_frame, |
| 3769 | sizeof(struct iwl_init_alive_resp)); |
| 3770 | pwork = &priv->init_alive_start; |
| 3771 | } else { |
| 3772 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 3773 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
| 3774 | sizeof(struct iwl_alive_resp)); |
| 3775 | pwork = &priv->alive_start; |
| 3776 | } |
| 3777 | |
| 3778 | /* We delay the ALIVE response by 5ms to |
| 3779 | * give the HW RF Kill time to activate... */ |
| 3780 | if (palive->is_valid == UCODE_VALID_OK) |
| 3781 | queue_delayed_work(priv->workqueue, pwork, |
| 3782 | msecs_to_jiffies(5)); |
| 3783 | else |
| 3784 | IWL_WARNING("uCode did not respond OK.\n"); |
| 3785 | } |
| 3786 | |
| 3787 | static void iwl_rx_reply_add_sta(struct iwl_priv *priv, |
| 3788 | struct iwl_rx_mem_buffer *rxb) |
| 3789 | { |
| 3790 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
| 3791 | |
| 3792 | IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status); |
| 3793 | return; |
| 3794 | } |
| 3795 | |
| 3796 | static void iwl_rx_reply_error(struct iwl_priv *priv, |
| 3797 | struct iwl_rx_mem_buffer *rxb) |
| 3798 | { |
| 3799 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
| 3800 | |
| 3801 | IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) " |
| 3802 | "seq 0x%04X ser 0x%08X\n", |
| 3803 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 3804 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 3805 | pkt->u.err_resp.cmd_id, |
| 3806 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 3807 | le32_to_cpu(pkt->u.err_resp.error_info)); |
| 3808 | } |
| 3809 | |
| 3810 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 3811 | |
| 3812 | static void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb) |
| 3813 | { |
| 3814 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
| 3815 | struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon; |
| 3816 | struct iwl_csa_notification *csa = &(pkt->u.csa_notif); |
| 3817 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
| 3818 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); |
| 3819 | rxon->channel = csa->channel; |
| 3820 | priv->staging_rxon.channel = csa->channel; |
| 3821 | } |
| 3822 | |
| 3823 | static void iwl_rx_spectrum_measure_notif(struct iwl_priv *priv, |
| 3824 | struct iwl_rx_mem_buffer *rxb) |
| 3825 | { |
| 3826 | #ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT |
| 3827 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
| 3828 | struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif); |
| 3829 | |
| 3830 | if (!report->state) { |
| 3831 | IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO, |
| 3832 | "Spectrum Measure Notification: Start\n"); |
| 3833 | return; |
| 3834 | } |
| 3835 | |
| 3836 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 3837 | priv->measurement_status |= MEASUREMENT_READY; |
| 3838 | #endif |
| 3839 | } |
| 3840 | |
| 3841 | static void iwl_rx_pm_sleep_notif(struct iwl_priv *priv, |
| 3842 | struct iwl_rx_mem_buffer *rxb) |
| 3843 | { |
| 3844 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 3845 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
| 3846 | struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif); |
| 3847 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
| 3848 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 3849 | #endif |
| 3850 | } |
| 3851 | |
| 3852 | static void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv, |
| 3853 | struct iwl_rx_mem_buffer *rxb) |
| 3854 | { |
| 3855 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
| 3856 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
| 3857 | "notification for %s:\n", |
| 3858 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); |
| 3859 | iwl_print_hex_dump(IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len)); |
| 3860 | } |
| 3861 | |
| 3862 | static void iwl_bg_beacon_update(struct work_struct *work) |
| 3863 | { |
| 3864 | struct iwl_priv *priv = |
| 3865 | container_of(work, struct iwl_priv, beacon_update); |
| 3866 | struct sk_buff *beacon; |
| 3867 | |
| 3868 | /* Pull updated AP beacon from mac80211. will fail if not in AP mode */ |
| 3869 | beacon = ieee80211_beacon_get(priv->hw, priv->interface_id, NULL); |
| 3870 | |
| 3871 | if (!beacon) { |
| 3872 | IWL_ERROR("update beacon failed\n"); |
| 3873 | return; |
| 3874 | } |
| 3875 | |
| 3876 | mutex_lock(&priv->mutex); |
| 3877 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 3878 | if (priv->ibss_beacon) |
| 3879 | dev_kfree_skb(priv->ibss_beacon); |
| 3880 | |
| 3881 | priv->ibss_beacon = beacon; |
| 3882 | mutex_unlock(&priv->mutex); |
| 3883 | |
| 3884 | iwl_send_beacon_cmd(priv); |
| 3885 | } |
| 3886 | |
| 3887 | static void iwl_rx_beacon_notif(struct iwl_priv *priv, |
| 3888 | struct iwl_rx_mem_buffer *rxb) |
| 3889 | { |
| 3890 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 3891 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
| 3892 | struct iwl_beacon_notif *beacon = &(pkt->u.beacon_status); |
| 3893 | u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags); |
| 3894 | |
| 3895 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " |
| 3896 | "tsf %d %d rate %d\n", |
| 3897 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 3898 | beacon->beacon_notify_hdr.failure_frame, |
| 3899 | le32_to_cpu(beacon->ibss_mgr_status), |
| 3900 | le32_to_cpu(beacon->high_tsf), |
| 3901 | le32_to_cpu(beacon->low_tsf), rate); |
| 3902 | #endif |
| 3903 | |
| 3904 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 3905 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 3906 | queue_work(priv->workqueue, &priv->beacon_update); |
| 3907 | } |
| 3908 | |
| 3909 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
| 3910 | static void iwl_rx_reply_scan(struct iwl_priv *priv, |
| 3911 | struct iwl_rx_mem_buffer *rxb) |
| 3912 | { |
| 3913 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 3914 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
| 3915 | struct iwl_scanreq_notification *notif = |
| 3916 | (struct iwl_scanreq_notification *)pkt->u.raw; |
| 3917 | |
| 3918 | IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); |
| 3919 | #endif |
| 3920 | } |
| 3921 | |
| 3922 | /* Service SCAN_START_NOTIFICATION (0x82) */ |
| 3923 | static void iwl_rx_scan_start_notif(struct iwl_priv *priv, |
| 3924 | struct iwl_rx_mem_buffer *rxb) |
| 3925 | { |
| 3926 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
| 3927 | struct iwl_scanstart_notification *notif = |
| 3928 | (struct iwl_scanstart_notification *)pkt->u.raw; |
| 3929 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
| 3930 | IWL_DEBUG_SCAN("Scan start: " |
| 3931 | "%d [802.11%s] " |
| 3932 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", |
| 3933 | notif->channel, |
| 3934 | notif->band ? "bg" : "a", |
| 3935 | notif->tsf_high, |
| 3936 | notif->tsf_low, notif->status, notif->beacon_timer); |
| 3937 | } |
| 3938 | |
| 3939 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ |
| 3940 | static void iwl_rx_scan_results_notif(struct iwl_priv *priv, |
| 3941 | struct iwl_rx_mem_buffer *rxb) |
| 3942 | { |
| 3943 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
| 3944 | struct iwl_scanresults_notification *notif = |
| 3945 | (struct iwl_scanresults_notification *)pkt->u.raw; |
| 3946 | |
| 3947 | IWL_DEBUG_SCAN("Scan ch.res: " |
| 3948 | "%d [802.11%s] " |
| 3949 | "(TSF: 0x%08X:%08X) - %d " |
| 3950 | "elapsed=%lu usec (%dms since last)\n", |
| 3951 | notif->channel, |
| 3952 | notif->band ? "bg" : "a", |
| 3953 | le32_to_cpu(notif->tsf_high), |
| 3954 | le32_to_cpu(notif->tsf_low), |
| 3955 | le32_to_cpu(notif->statistics[0]), |
| 3956 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf, |
| 3957 | jiffies_to_msecs(elapsed_jiffies |
| 3958 | (priv->last_scan_jiffies, jiffies))); |
| 3959 | |
| 3960 | priv->last_scan_jiffies = jiffies; |
| 3961 | } |
| 3962 | |
| 3963 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ |
| 3964 | static void iwl_rx_scan_complete_notif(struct iwl_priv *priv, |
| 3965 | struct iwl_rx_mem_buffer *rxb) |
| 3966 | { |
| 3967 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
| 3968 | struct iwl_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
| 3969 | |
| 3970 | IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
| 3971 | scan_notif->scanned_channels, |
| 3972 | scan_notif->tsf_low, |
| 3973 | scan_notif->tsf_high, scan_notif->status); |
| 3974 | |
| 3975 | /* The HW is no longer scanning */ |
| 3976 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 3977 | |
| 3978 | /* The scan completion notification came in, so kill that timer... */ |
| 3979 | cancel_delayed_work(&priv->scan_check); |
| 3980 | |
| 3981 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
| 3982 | (priv->scan_bands == 2) ? "2.4" : "5.2", |
| 3983 | jiffies_to_msecs(elapsed_jiffies |
| 3984 | (priv->scan_pass_start, jiffies))); |
| 3985 | |
| 3986 | /* Remove this scanned band from the list |
| 3987 | * of pending bands to scan */ |
| 3988 | priv->scan_bands--; |
| 3989 | |
| 3990 | /* If a request to abort was given, or the scan did not succeed |
| 3991 | * then we reset the scan state machine and terminate, |
| 3992 | * re-queuing another scan if one has been requested */ |
| 3993 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 3994 | IWL_DEBUG_INFO("Aborted scan completed.\n"); |
| 3995 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 3996 | } else { |
| 3997 | /* If there are more bands on this scan pass reschedule */ |
| 3998 | if (priv->scan_bands > 0) |
| 3999 | goto reschedule; |
| 4000 | } |
| 4001 | |
| 4002 | priv->last_scan_jiffies = jiffies; |
| 4003 | IWL_DEBUG_INFO("Setting scan to off\n"); |
| 4004 | |
| 4005 | clear_bit(STATUS_SCANNING, &priv->status); |
| 4006 | |
| 4007 | IWL_DEBUG_INFO("Scan took %dms\n", |
| 4008 | jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies))); |
| 4009 | |
| 4010 | queue_work(priv->workqueue, &priv->scan_completed); |
| 4011 | |
| 4012 | return; |
| 4013 | |
| 4014 | reschedule: |
| 4015 | priv->scan_pass_start = jiffies; |
| 4016 | queue_work(priv->workqueue, &priv->request_scan); |
| 4017 | } |
| 4018 | |
| 4019 | /* Handle notification from uCode that card's power state is changing |
| 4020 | * due to software, hardware, or critical temperature RFKILL */ |
| 4021 | static void iwl_rx_card_state_notif(struct iwl_priv *priv, |
| 4022 | struct iwl_rx_mem_buffer *rxb) |
| 4023 | { |
| 4024 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
| 4025 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 4026 | unsigned long status = priv->status; |
| 4027 | |
| 4028 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", |
| 4029 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 4030 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 4031 | |
| 4032 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | |
| 4033 | RF_CARD_DISABLED)) { |
| 4034 | |
| 4035 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
| 4036 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 4037 | |
| 4038 | if (!iwl_grab_restricted_access(priv)) { |
| 4039 | iwl_write_restricted( |
| 4040 | priv, HBUS_TARG_MBX_C, |
| 4041 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 4042 | |
| 4043 | iwl_release_restricted_access(priv); |
| 4044 | } |
| 4045 | |
| 4046 | if (!(flags & RXON_CARD_DISABLED)) { |
| 4047 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
| 4048 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 4049 | if (!iwl_grab_restricted_access(priv)) { |
| 4050 | iwl_write_restricted( |
| 4051 | priv, HBUS_TARG_MBX_C, |
| 4052 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 4053 | |
| 4054 | iwl_release_restricted_access(priv); |
| 4055 | } |
| 4056 | } |
| 4057 | |
| 4058 | if (flags & RF_CARD_DISABLED) { |
| 4059 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
| 4060 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
| 4061 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 4062 | if (!iwl_grab_restricted_access(priv)) |
| 4063 | iwl_release_restricted_access(priv); |
| 4064 | } |
| 4065 | } |
| 4066 | |
| 4067 | if (flags & HW_CARD_DISABLED) |
| 4068 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 4069 | else |
| 4070 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 4071 | |
| 4072 | |
| 4073 | if (flags & SW_CARD_DISABLED) |
| 4074 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 4075 | else |
| 4076 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 4077 | |
| 4078 | if (!(flags & RXON_CARD_DISABLED)) |
| 4079 | iwl_scan_cancel(priv); |
| 4080 | |
| 4081 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 4082 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 4083 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 4084 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 4085 | queue_work(priv->workqueue, &priv->rf_kill); |
| 4086 | else |
| 4087 | wake_up_interruptible(&priv->wait_command_queue); |
| 4088 | } |
| 4089 | |
| 4090 | /** |
| 4091 | * iwl_setup_rx_handlers - Initialize Rx handler callbacks |
| 4092 | * |
| 4093 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 4094 | * to the host. |
| 4095 | * |
| 4096 | * This function chains into the hardware specific files for them to setup |
| 4097 | * any hardware specific handlers as well. |
| 4098 | */ |
| 4099 | static void iwl_setup_rx_handlers(struct iwl_priv *priv) |
| 4100 | { |
| 4101 | priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive; |
| 4102 | priv->rx_handlers[REPLY_ADD_STA] = iwl_rx_reply_add_sta; |
| 4103 | priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error; |
| 4104 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa; |
| 4105 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
| 4106 | iwl_rx_spectrum_measure_notif; |
| 4107 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif; |
| 4108 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
| 4109 | iwl_rx_pm_debug_statistics_notif; |
| 4110 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif; |
| 4111 | |
| 4112 | /* NOTE: iwl_rx_statistics is different based on whether |
| 4113 | * the build is for the 3945 or the 4965. See the |
| 4114 | * corresponding implementation in iwl-XXXX.c |
| 4115 | * |
| 4116 | * The same handler is used for both the REPLY to a |
| 4117 | * discrete statistics request from the host as well as |
| 4118 | * for the periodic statistics notification from the uCode |
| 4119 | */ |
| 4120 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_hw_rx_statistics; |
| 4121 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_hw_rx_statistics; |
| 4122 | |
| 4123 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl_rx_reply_scan; |
| 4124 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl_rx_scan_start_notif; |
| 4125 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
| 4126 | iwl_rx_scan_results_notif; |
| 4127 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
| 4128 | iwl_rx_scan_complete_notif; |
| 4129 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif; |
| 4130 | priv->rx_handlers[REPLY_TX] = iwl_rx_reply_tx; |
| 4131 | |
| 4132 | /* Setup hardware specific Rx handlers */ |
| 4133 | iwl_hw_rx_handler_setup(priv); |
| 4134 | } |
| 4135 | |
| 4136 | /** |
| 4137 | * iwl_tx_cmd_complete - Pull unused buffers off the queue and reclaim them |
| 4138 | * @rxb: Rx buffer to reclaim |
| 4139 | * |
| 4140 | * If an Rx buffer has an async callback associated with it the callback |
| 4141 | * will be executed. The attached skb (if present) will only be freed |
| 4142 | * if the callback returns 1 |
| 4143 | */ |
| 4144 | static void iwl_tx_cmd_complete(struct iwl_priv *priv, |
| 4145 | struct iwl_rx_mem_buffer *rxb) |
| 4146 | { |
| 4147 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
| 4148 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 4149 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 4150 | int index = SEQ_TO_INDEX(sequence); |
| 4151 | int huge = sequence & SEQ_HUGE_FRAME; |
| 4152 | int cmd_index; |
| 4153 | struct iwl_cmd *cmd; |
| 4154 | |
| 4155 | /* If a Tx command is being handled and it isn't in the actual |
| 4156 | * command queue then there a command routing bug has been introduced |
| 4157 | * in the queue management code. */ |
| 4158 | if (txq_id != IWL_CMD_QUEUE_NUM) |
| 4159 | IWL_ERROR("Error wrong command queue %d command id 0x%X\n", |
| 4160 | txq_id, pkt->hdr.cmd); |
| 4161 | BUG_ON(txq_id != IWL_CMD_QUEUE_NUM); |
| 4162 | |
| 4163 | cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge); |
| 4164 | cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; |
| 4165 | |
| 4166 | /* Input error checking is done when commands are added to queue. */ |
| 4167 | if (cmd->meta.flags & CMD_WANT_SKB) { |
| 4168 | cmd->meta.source->u.skb = rxb->skb; |
| 4169 | rxb->skb = NULL; |
| 4170 | } else if (cmd->meta.u.callback && |
| 4171 | !cmd->meta.u.callback(priv, cmd, rxb->skb)) |
| 4172 | rxb->skb = NULL; |
| 4173 | |
| 4174 | iwl_tx_queue_reclaim(priv, txq_id, index); |
| 4175 | |
| 4176 | if (!(cmd->meta.flags & CMD_ASYNC)) { |
| 4177 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 4178 | wake_up_interruptible(&priv->wait_command_queue); |
| 4179 | } |
| 4180 | } |
| 4181 | |
| 4182 | /************************** RX-FUNCTIONS ****************************/ |
| 4183 | /* |
| 4184 | * Rx theory of operation |
| 4185 | * |
| 4186 | * The host allocates 32 DMA target addresses and passes the host address |
| 4187 | * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is |
| 4188 | * 0 to 31 |
| 4189 | * |
| 4190 | * Rx Queue Indexes |
| 4191 | * The host/firmware share two index registers for managing the Rx buffers. |
| 4192 | * |
| 4193 | * The READ index maps to the first position that the firmware may be writing |
| 4194 | * to -- the driver can read up to (but not including) this position and get |
| 4195 | * good data. |
| 4196 | * The READ index is managed by the firmware once the card is enabled. |
| 4197 | * |
| 4198 | * The WRITE index maps to the last position the driver has read from -- the |
| 4199 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 4200 | * |
| 4201 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if |
| 4202 | * WRITE = READ. |
| 4203 | * |
| 4204 | * During initialization the host sets up the READ queue position to the first |
| 4205 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 4206 | * |
| 4207 | * When the firmware places a packet in a buffer it will advance the READ index |
| 4208 | * and fire the RX interrupt. The driver can then query the READ index and |
| 4209 | * process as many packets as possible, moving the WRITE index forward as it |
| 4210 | * resets the Rx queue buffers with new memory. |
| 4211 | * |
| 4212 | * The management in the driver is as follows: |
| 4213 | * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When |
| 4214 | * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled |
| 4215 | * to replensish the iwl->rxq->rx_free. |
| 4216 | * + In iwl_rx_replenish (scheduled) if 'processed' != 'read' then the |
| 4217 | * iwl->rxq is replenished and the READ INDEX is updated (updating the |
| 4218 | * 'processed' and 'read' driver indexes as well) |
| 4219 | * + A received packet is processed and handed to the kernel network stack, |
| 4220 | * detached from the iwl->rxq. The driver 'processed' index is updated. |
| 4221 | * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free |
| 4222 | * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ |
| 4223 | * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there |
| 4224 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 4225 | * |
| 4226 | * |
| 4227 | * Driver sequence: |
| 4228 | * |
| 4229 | * iwl_rx_queue_alloc() Allocates rx_free |
| 4230 | * iwl_rx_replenish() Replenishes rx_free list from rx_used, and calls |
| 4231 | * iwl_rx_queue_restock |
| 4232 | * iwl_rx_queue_restock() Moves available buffers from rx_free into Rx |
| 4233 | * queue, updates firmware pointers, and updates |
| 4234 | * the WRITE index. If insufficient rx_free buffers |
| 4235 | * are available, schedules iwl_rx_replenish |
| 4236 | * |
| 4237 | * -- enable interrupts -- |
| 4238 | * ISR - iwl_rx() Detach iwl_rx_mem_buffers from pool up to the |
| 4239 | * READ INDEX, detaching the SKB from the pool. |
| 4240 | * Moves the packet buffer from queue to rx_used. |
| 4241 | * Calls iwl_rx_queue_restock to refill any empty |
| 4242 | * slots. |
| 4243 | * ... |
| 4244 | * |
| 4245 | */ |
| 4246 | |
| 4247 | /** |
| 4248 | * iwl_rx_queue_space - Return number of free slots available in queue. |
| 4249 | */ |
| 4250 | static int iwl_rx_queue_space(const struct iwl_rx_queue *q) |
| 4251 | { |
| 4252 | int s = q->read - q->write; |
| 4253 | if (s <= 0) |
| 4254 | s += RX_QUEUE_SIZE; |
| 4255 | /* keep some buffer to not confuse full and empty queue */ |
| 4256 | s -= 2; |
| 4257 | if (s < 0) |
| 4258 | s = 0; |
| 4259 | return s; |
| 4260 | } |
| 4261 | |
| 4262 | /** |
| 4263 | * iwl_rx_queue_update_write_ptr - Update the write pointer for the RX queue |
| 4264 | * |
| 4265 | * NOTE: This function has 3945 and 4965 specific code sections |
| 4266 | * but is declared in base due to the majority of the |
| 4267 | * implementation being the same (only a numeric constant is |
| 4268 | * different) |
| 4269 | * |
| 4270 | */ |
| 4271 | int iwl_rx_queue_update_write_ptr(struct iwl_priv *priv, struct iwl_rx_queue *q) |
| 4272 | { |
| 4273 | u32 reg = 0; |
| 4274 | int rc = 0; |
| 4275 | unsigned long flags; |
| 4276 | |
| 4277 | spin_lock_irqsave(&q->lock, flags); |
| 4278 | |
| 4279 | if (q->need_update == 0) |
| 4280 | goto exit_unlock; |
| 4281 | |
| 4282 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
| 4283 | reg = iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 4284 | |
| 4285 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
| 4286 | iwl_set_bit(priv, CSR_GP_CNTRL, |
| 4287 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 4288 | goto exit_unlock; |
| 4289 | } |
| 4290 | |
| 4291 | rc = iwl_grab_restricted_access(priv); |
| 4292 | if (rc) |
| 4293 | goto exit_unlock; |
| 4294 | |
| 4295 | iwl_write_restricted(priv, FH_RSCSR_CHNL0_WPTR, |
| 4296 | q->write & ~0x7); |
| 4297 | iwl_release_restricted_access(priv); |
| 4298 | } else |
| 4299 | iwl_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7); |
| 4300 | |
| 4301 | |
| 4302 | q->need_update = 0; |
| 4303 | |
| 4304 | exit_unlock: |
| 4305 | spin_unlock_irqrestore(&q->lock, flags); |
| 4306 | return rc; |
| 4307 | } |
| 4308 | |
| 4309 | /** |
| 4310 | * iwl_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer pointer. |
| 4311 | * |
| 4312 | * NOTE: This function has 3945 and 4965 specific code paths in it. |
| 4313 | */ |
| 4314 | static inline __le32 iwl_dma_addr2rbd_ptr(struct iwl_priv *priv, |
| 4315 | dma_addr_t dma_addr) |
| 4316 | { |
| 4317 | return cpu_to_le32((u32)(dma_addr >> 8)); |
| 4318 | } |
| 4319 | |
| 4320 | |
| 4321 | /** |
| 4322 | * iwl_rx_queue_restock - refill RX queue from pre-allocated pool |
| 4323 | * |
| 4324 | * If there are slots in the RX queue that need to be restocked, |
| 4325 | * and we have free pre-allocated buffers, fill the ranks as much |
| 4326 | * as we can pulling from rx_free. |
| 4327 | * |
| 4328 | * This moves the 'write' index forward to catch up with 'processed', and |
| 4329 | * also updates the memory address in the firmware to reference the new |
| 4330 | * target buffer. |
| 4331 | */ |
| 4332 | int iwl_rx_queue_restock(struct iwl_priv *priv) |
| 4333 | { |
| 4334 | struct iwl_rx_queue *rxq = &priv->rxq; |
| 4335 | struct list_head *element; |
| 4336 | struct iwl_rx_mem_buffer *rxb; |
| 4337 | unsigned long flags; |
| 4338 | int write, rc; |
| 4339 | |
| 4340 | spin_lock_irqsave(&rxq->lock, flags); |
| 4341 | write = rxq->write & ~0x7; |
| 4342 | while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) { |
| 4343 | element = rxq->rx_free.next; |
| 4344 | rxb = list_entry(element, struct iwl_rx_mem_buffer, list); |
| 4345 | list_del(element); |
| 4346 | rxq->bd[rxq->write] = iwl_dma_addr2rbd_ptr(priv, rxb->dma_addr); |
| 4347 | rxq->queue[rxq->write] = rxb; |
| 4348 | rxq->write = (rxq->write + 1) & RX_QUEUE_MASK; |
| 4349 | rxq->free_count--; |
| 4350 | } |
| 4351 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4352 | /* If the pre-allocated buffer pool is dropping low, schedule to |
| 4353 | * refill it */ |
| 4354 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 4355 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 4356 | |
| 4357 | |
| 4358 | /* If we've added more space for the firmware to place data, tell it */ |
| 4359 | if ((write != (rxq->write & ~0x7)) |
| 4360 | || (abs(rxq->write - rxq->read) > 7)) { |
| 4361 | spin_lock_irqsave(&rxq->lock, flags); |
| 4362 | rxq->need_update = 1; |
| 4363 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4364 | rc = iwl_rx_queue_update_write_ptr(priv, rxq); |
| 4365 | if (rc) |
| 4366 | return rc; |
| 4367 | } |
| 4368 | |
| 4369 | return 0; |
| 4370 | } |
| 4371 | |
| 4372 | /** |
| 4373 | * iwl_rx_replensih - Move all used packet from rx_used to rx_free |
| 4374 | * |
| 4375 | * When moving to rx_free an SKB is allocated for the slot. |
| 4376 | * |
| 4377 | * Also restock the Rx queue via iwl_rx_queue_restock. |
| 4378 | * This is called as a scheduled work item (except for during intialization) |
| 4379 | */ |
| 4380 | void iwl_rx_replenish(void *data) |
| 4381 | { |
| 4382 | struct iwl_priv *priv = data; |
| 4383 | struct iwl_rx_queue *rxq = &priv->rxq; |
| 4384 | struct list_head *element; |
| 4385 | struct iwl_rx_mem_buffer *rxb; |
| 4386 | unsigned long flags; |
| 4387 | spin_lock_irqsave(&rxq->lock, flags); |
| 4388 | while (!list_empty(&rxq->rx_used)) { |
| 4389 | element = rxq->rx_used.next; |
| 4390 | rxb = list_entry(element, struct iwl_rx_mem_buffer, list); |
| 4391 | rxb->skb = |
| 4392 | alloc_skb(IWL_RX_BUF_SIZE, __GFP_NOWARN | GFP_ATOMIC); |
| 4393 | if (!rxb->skb) { |
| 4394 | if (net_ratelimit()) |
| 4395 | printk(KERN_CRIT DRV_NAME |
| 4396 | ": Can not allocate SKB buffers\n"); |
| 4397 | /* We don't reschedule replenish work here -- we will |
| 4398 | * call the restock method and if it still needs |
| 4399 | * more buffers it will schedule replenish */ |
| 4400 | break; |
| 4401 | } |
| 4402 | priv->alloc_rxb_skb++; |
| 4403 | list_del(element); |
| 4404 | rxb->dma_addr = |
| 4405 | pci_map_single(priv->pci_dev, rxb->skb->data, |
| 4406 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 4407 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 4408 | rxq->free_count++; |
| 4409 | } |
| 4410 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4411 | |
| 4412 | spin_lock_irqsave(&priv->lock, flags); |
| 4413 | iwl_rx_queue_restock(priv); |
| 4414 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4415 | } |
| 4416 | |
| 4417 | /* Assumes that the skb field of the buffers in 'pool' is kept accurate. |
| 4418 | * If an SKB has been detached, the POOL needs to have it's SKB set to NULL |
| 4419 | * This free routine walks the list of POOL entries and if SKB is set to |
| 4420 | * non NULL it is unmapped and freed |
| 4421 | */ |
| 4422 | void iwl_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq) |
| 4423 | { |
| 4424 | int i; |
| 4425 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
| 4426 | if (rxq->pool[i].skb != NULL) { |
| 4427 | pci_unmap_single(priv->pci_dev, |
| 4428 | rxq->pool[i].dma_addr, |
| 4429 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 4430 | dev_kfree_skb(rxq->pool[i].skb); |
| 4431 | } |
| 4432 | } |
| 4433 | |
| 4434 | pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd, |
| 4435 | rxq->dma_addr); |
| 4436 | rxq->bd = NULL; |
| 4437 | } |
| 4438 | |
| 4439 | int iwl_rx_queue_alloc(struct iwl_priv *priv) |
| 4440 | { |
| 4441 | struct iwl_rx_queue *rxq = &priv->rxq; |
| 4442 | struct pci_dev *dev = priv->pci_dev; |
| 4443 | int i; |
| 4444 | |
| 4445 | spin_lock_init(&rxq->lock); |
| 4446 | INIT_LIST_HEAD(&rxq->rx_free); |
| 4447 | INIT_LIST_HEAD(&rxq->rx_used); |
| 4448 | rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr); |
| 4449 | if (!rxq->bd) |
| 4450 | return -ENOMEM; |
| 4451 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 4452 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
| 4453 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 4454 | /* Set us so that we have processed and used all buffers, but have |
| 4455 | * not restocked the Rx queue with fresh buffers */ |
| 4456 | rxq->read = rxq->write = 0; |
| 4457 | rxq->free_count = 0; |
| 4458 | rxq->need_update = 0; |
| 4459 | return 0; |
| 4460 | } |
| 4461 | |
| 4462 | void iwl_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq) |
| 4463 | { |
| 4464 | unsigned long flags; |
| 4465 | int i; |
| 4466 | spin_lock_irqsave(&rxq->lock, flags); |
| 4467 | INIT_LIST_HEAD(&rxq->rx_free); |
| 4468 | INIT_LIST_HEAD(&rxq->rx_used); |
| 4469 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 4470 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 4471 | /* In the reset function, these buffers may have been allocated |
| 4472 | * to an SKB, so we need to unmap and free potential storage */ |
| 4473 | if (rxq->pool[i].skb != NULL) { |
| 4474 | pci_unmap_single(priv->pci_dev, |
| 4475 | rxq->pool[i].dma_addr, |
| 4476 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 4477 | priv->alloc_rxb_skb--; |
| 4478 | dev_kfree_skb(rxq->pool[i].skb); |
| 4479 | rxq->pool[i].skb = NULL; |
| 4480 | } |
| 4481 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 4482 | } |
| 4483 | |
| 4484 | /* Set us so that we have processed and used all buffers, but have |
| 4485 | * not restocked the Rx queue with fresh buffers */ |
| 4486 | rxq->read = rxq->write = 0; |
| 4487 | rxq->free_count = 0; |
| 4488 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4489 | } |
| 4490 | |
| 4491 | /* Convert linear signal-to-noise ratio into dB */ |
| 4492 | static u8 ratio2dB[100] = { |
| 4493 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 4494 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 4495 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 4496 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 4497 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 4498 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 4499 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 4500 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 4501 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 4502 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 4503 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 4504 | }; |
| 4505 | |
| 4506 | /* Calculates a relative dB value from a ratio of linear |
| 4507 | * (i.e. not dB) signal levels. |
| 4508 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
| 4509 | int iwl_calc_db_from_ratio(int sig_ratio) |
| 4510 | { |
| 4511 | /* Anything above 1000:1 just report as 60 dB */ |
| 4512 | if (sig_ratio > 1000) |
| 4513 | return 60; |
| 4514 | |
| 4515 | /* Above 100:1, divide by 10 and use table, |
| 4516 | * add 20 dB to make up for divide by 10 */ |
| 4517 | if (sig_ratio > 100) |
| 4518 | return (20 + (int)ratio2dB[sig_ratio/10]); |
| 4519 | |
| 4520 | /* We shouldn't see this */ |
| 4521 | if (sig_ratio < 1) |
| 4522 | return 0; |
| 4523 | |
| 4524 | /* Use table for ratios 1:1 - 99:1 */ |
| 4525 | return (int)ratio2dB[sig_ratio]; |
| 4526 | } |
| 4527 | |
| 4528 | #define PERFECT_RSSI (-20) /* dBm */ |
| 4529 | #define WORST_RSSI (-95) /* dBm */ |
| 4530 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) |
| 4531 | |
| 4532 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). |
| 4533 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info |
| 4534 | * about formulas used below. */ |
| 4535 | int iwl_calc_sig_qual(int rssi_dbm, int noise_dbm) |
| 4536 | { |
| 4537 | int sig_qual; |
| 4538 | int degradation = PERFECT_RSSI - rssi_dbm; |
| 4539 | |
| 4540 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) |
| 4541 | * as indicator; formula is (signal dbm - noise dbm). |
| 4542 | * SNR at or above 40 is a great signal (100%). |
| 4543 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. |
| 4544 | * Weakest usable signal is usually 10 - 15 dB SNR. */ |
| 4545 | if (noise_dbm) { |
| 4546 | if (rssi_dbm - noise_dbm >= 40) |
| 4547 | return 100; |
| 4548 | else if (rssi_dbm < noise_dbm) |
| 4549 | return 0; |
| 4550 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; |
| 4551 | |
| 4552 | /* Else use just the signal level. |
| 4553 | * This formula is a least squares fit of data points collected and |
| 4554 | * compared with a reference system that had a percentage (%) display |
| 4555 | * for signal quality. */ |
| 4556 | } else |
| 4557 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * |
| 4558 | (15 * RSSI_RANGE + 62 * degradation)) / |
| 4559 | (RSSI_RANGE * RSSI_RANGE); |
| 4560 | |
| 4561 | if (sig_qual > 100) |
| 4562 | sig_qual = 100; |
| 4563 | else if (sig_qual < 1) |
| 4564 | sig_qual = 0; |
| 4565 | |
| 4566 | return sig_qual; |
| 4567 | } |
| 4568 | |
| 4569 | /** |
| 4570 | * iwl_rx_handle - Main entry function for receiving responses from the uCode |
| 4571 | * |
| 4572 | * Uses the priv->rx_handlers callback function array to invoke |
| 4573 | * the appropriate handlers, including command responses, |
| 4574 | * frame-received notifications, and other notifications. |
| 4575 | */ |
| 4576 | static void iwl_rx_handle(struct iwl_priv *priv) |
| 4577 | { |
| 4578 | struct iwl_rx_mem_buffer *rxb; |
| 4579 | struct iwl_rx_packet *pkt; |
| 4580 | struct iwl_rx_queue *rxq = &priv->rxq; |
| 4581 | u32 r, i; |
| 4582 | int reclaim; |
| 4583 | unsigned long flags; |
| 4584 | |
| 4585 | r = iwl_hw_get_rx_read(priv); |
| 4586 | i = rxq->read; |
| 4587 | |
| 4588 | /* Rx interrupt, but nothing sent from uCode */ |
| 4589 | if (i == r) |
| 4590 | IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i); |
| 4591 | |
| 4592 | while (i != r) { |
| 4593 | rxb = rxq->queue[i]; |
| 4594 | |
| 4595 | /* If an RXB doesn't have a queue slot associated with it |
| 4596 | * then a bug has been introduced in the queue refilling |
| 4597 | * routines -- catch it here */ |
| 4598 | BUG_ON(rxb == NULL); |
| 4599 | |
| 4600 | rxq->queue[i] = NULL; |
| 4601 | |
| 4602 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
| 4603 | IWL_RX_BUF_SIZE, |
| 4604 | PCI_DMA_FROMDEVICE); |
| 4605 | pkt = (struct iwl_rx_packet *)rxb->skb->data; |
| 4606 | |
| 4607 | /* Reclaim a command buffer only if this packet is a response |
| 4608 | * to a (driver-originated) command. |
| 4609 | * If the packet (e.g. Rx frame) originated from uCode, |
| 4610 | * there is no command buffer to reclaim. |
| 4611 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 4612 | * but apparently a few don't get set; catch them here. */ |
| 4613 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 4614 | (pkt->hdr.cmd != REPLY_RX_PHY_CMD) && |
| 4615 | (pkt->hdr.cmd != REPLY_4965_RX) && |
Zhu Yi | cfe0170 | 2007-09-27 11:27:31 +0800 | [diff] [blame] | 4616 | (pkt->hdr.cmd != REPLY_COMPRESSED_BA) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4617 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 4618 | (pkt->hdr.cmd != REPLY_TX); |
| 4619 | |
| 4620 | /* Based on type of command response or notification, |
| 4621 | * handle those that need handling via function in |
| 4622 | * rx_handlers table. See iwl_setup_rx_handlers() */ |
| 4623 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
| 4624 | IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR, |
| 4625 | "r = %d, i = %d, %s, 0x%02x\n", r, i, |
| 4626 | get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
| 4627 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 4628 | } else { |
| 4629 | /* No handling needed */ |
| 4630 | IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR, |
| 4631 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 4632 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 4633 | pkt->hdr.cmd); |
| 4634 | } |
| 4635 | |
| 4636 | if (reclaim) { |
| 4637 | /* Invoke any callbacks, transfer the skb to caller, |
| 4638 | * and fire off the (possibly) blocking iwl_send_cmd() |
| 4639 | * as we reclaim the driver command queue */ |
| 4640 | if (rxb && rxb->skb) |
| 4641 | iwl_tx_cmd_complete(priv, rxb); |
| 4642 | else |
| 4643 | IWL_WARNING("Claim null rxb?\n"); |
| 4644 | } |
| 4645 | |
| 4646 | /* For now we just don't re-use anything. We can tweak this |
| 4647 | * later to try and re-use notification packets and SKBs that |
| 4648 | * fail to Rx correctly */ |
| 4649 | if (rxb->skb != NULL) { |
| 4650 | priv->alloc_rxb_skb--; |
| 4651 | dev_kfree_skb_any(rxb->skb); |
| 4652 | rxb->skb = NULL; |
| 4653 | } |
| 4654 | |
| 4655 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
| 4656 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 4657 | spin_lock_irqsave(&rxq->lock, flags); |
| 4658 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 4659 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4660 | i = (i + 1) & RX_QUEUE_MASK; |
| 4661 | } |
| 4662 | |
| 4663 | /* Backtrack one entry */ |
| 4664 | priv->rxq.read = i; |
| 4665 | iwl_rx_queue_restock(priv); |
| 4666 | } |
| 4667 | |
| 4668 | int iwl_tx_queue_update_write_ptr(struct iwl_priv *priv, |
| 4669 | struct iwl_tx_queue *txq) |
| 4670 | { |
| 4671 | u32 reg = 0; |
| 4672 | int rc = 0; |
| 4673 | int txq_id = txq->q.id; |
| 4674 | |
| 4675 | if (txq->need_update == 0) |
| 4676 | return rc; |
| 4677 | |
| 4678 | /* if we're trying to save power */ |
| 4679 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
| 4680 | /* wake up nic if it's powered down ... |
| 4681 | * uCode will wake up, and interrupt us again, so next |
| 4682 | * time we'll skip this part. */ |
| 4683 | reg = iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 4684 | |
| 4685 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
| 4686 | IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg); |
| 4687 | iwl_set_bit(priv, CSR_GP_CNTRL, |
| 4688 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 4689 | return rc; |
| 4690 | } |
| 4691 | |
| 4692 | /* restore this queue's parameters in nic hardware. */ |
| 4693 | rc = iwl_grab_restricted_access(priv); |
| 4694 | if (rc) |
| 4695 | return rc; |
| 4696 | iwl_write_restricted(priv, HBUS_TARG_WRPTR, |
| 4697 | txq->q.first_empty | (txq_id << 8)); |
| 4698 | iwl_release_restricted_access(priv); |
| 4699 | |
| 4700 | /* else not in power-save mode, uCode will never sleep when we're |
| 4701 | * trying to tx (during RFKILL, we're not trying to tx). */ |
| 4702 | } else |
| 4703 | iwl_write32(priv, HBUS_TARG_WRPTR, |
| 4704 | txq->q.first_empty | (txq_id << 8)); |
| 4705 | |
| 4706 | txq->need_update = 0; |
| 4707 | |
| 4708 | return rc; |
| 4709 | } |
| 4710 | |
| 4711 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 4712 | static void iwl_print_rx_config_cmd(struct iwl_rxon_cmd *rxon) |
| 4713 | { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4714 | DECLARE_MAC_BUF(mac); |
| 4715 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4716 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
| 4717 | iwl_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
| 4718 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 4719 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 4720 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", |
| 4721 | le32_to_cpu(rxon->filter_flags)); |
| 4722 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); |
| 4723 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", |
| 4724 | rxon->ofdm_basic_rates); |
| 4725 | IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4726 | IWL_DEBUG_RADIO("u8[6] node_addr: %s\n", |
| 4727 | print_mac(mac, rxon->node_addr)); |
| 4728 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n", |
| 4729 | print_mac(mac, rxon->bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4730 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
| 4731 | } |
| 4732 | #endif |
| 4733 | |
| 4734 | static void iwl_enable_interrupts(struct iwl_priv *priv) |
| 4735 | { |
| 4736 | IWL_DEBUG_ISR("Enabling interrupts\n"); |
| 4737 | set_bit(STATUS_INT_ENABLED, &priv->status); |
| 4738 | iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
| 4739 | } |
| 4740 | |
| 4741 | static inline void iwl_disable_interrupts(struct iwl_priv *priv) |
| 4742 | { |
| 4743 | clear_bit(STATUS_INT_ENABLED, &priv->status); |
| 4744 | |
| 4745 | /* disable interrupts from uCode/NIC to host */ |
| 4746 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
| 4747 | |
| 4748 | /* acknowledge/clear/reset any interrupts still pending |
| 4749 | * from uCode or flow handler (Rx/Tx DMA) */ |
| 4750 | iwl_write32(priv, CSR_INT, 0xffffffff); |
| 4751 | iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); |
| 4752 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
| 4753 | } |
| 4754 | |
| 4755 | static const char *desc_lookup(int i) |
| 4756 | { |
| 4757 | switch (i) { |
| 4758 | case 1: |
| 4759 | return "FAIL"; |
| 4760 | case 2: |
| 4761 | return "BAD_PARAM"; |
| 4762 | case 3: |
| 4763 | return "BAD_CHECKSUM"; |
| 4764 | case 4: |
| 4765 | return "NMI_INTERRUPT"; |
| 4766 | case 5: |
| 4767 | return "SYSASSERT"; |
| 4768 | case 6: |
| 4769 | return "FATAL_ERROR"; |
| 4770 | } |
| 4771 | |
| 4772 | return "UNKNOWN"; |
| 4773 | } |
| 4774 | |
| 4775 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 4776 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 4777 | |
| 4778 | static void iwl_dump_nic_error_log(struct iwl_priv *priv) |
| 4779 | { |
| 4780 | u32 data2, line; |
| 4781 | u32 desc, time, count, base, data1; |
| 4782 | u32 blink1, blink2, ilink1, ilink2; |
| 4783 | int rc; |
| 4784 | |
| 4785 | base = le32_to_cpu(priv->card_alive.error_event_table_ptr); |
| 4786 | |
| 4787 | if (!iwl_hw_valid_rtc_data_addr(base)) { |
| 4788 | IWL_ERROR("Not valid error log pointer 0x%08X\n", base); |
| 4789 | return; |
| 4790 | } |
| 4791 | |
| 4792 | rc = iwl_grab_restricted_access(priv); |
| 4793 | if (rc) { |
| 4794 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 4795 | return; |
| 4796 | } |
| 4797 | |
| 4798 | count = iwl_read_restricted_mem(priv, base); |
| 4799 | |
| 4800 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
| 4801 | IWL_ERROR("Start IWL Error Log Dump:\n"); |
| 4802 | IWL_ERROR("Status: 0x%08lX, Config: %08X count: %d\n", |
| 4803 | priv->status, priv->config, count); |
| 4804 | } |
| 4805 | |
| 4806 | desc = iwl_read_restricted_mem(priv, base + 1 * sizeof(u32)); |
| 4807 | blink1 = iwl_read_restricted_mem(priv, base + 3 * sizeof(u32)); |
| 4808 | blink2 = iwl_read_restricted_mem(priv, base + 4 * sizeof(u32)); |
| 4809 | ilink1 = iwl_read_restricted_mem(priv, base + 5 * sizeof(u32)); |
| 4810 | ilink2 = iwl_read_restricted_mem(priv, base + 6 * sizeof(u32)); |
| 4811 | data1 = iwl_read_restricted_mem(priv, base + 7 * sizeof(u32)); |
| 4812 | data2 = iwl_read_restricted_mem(priv, base + 8 * sizeof(u32)); |
| 4813 | line = iwl_read_restricted_mem(priv, base + 9 * sizeof(u32)); |
| 4814 | time = iwl_read_restricted_mem(priv, base + 11 * sizeof(u32)); |
| 4815 | |
| 4816 | IWL_ERROR("Desc Time " |
| 4817 | "data1 data2 line\n"); |
| 4818 | IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n", |
| 4819 | desc_lookup(desc), desc, time, data1, data2, line); |
| 4820 | IWL_ERROR("blink1 blink2 ilink1 ilink2\n"); |
| 4821 | IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2, |
| 4822 | ilink1, ilink2); |
| 4823 | |
| 4824 | iwl_release_restricted_access(priv); |
| 4825 | } |
| 4826 | |
| 4827 | #define EVENT_START_OFFSET (4 * sizeof(u32)) |
| 4828 | |
| 4829 | /** |
| 4830 | * iwl_print_event_log - Dump error event log to syslog |
| 4831 | * |
| 4832 | * NOTE: Must be called with iwl_grab_restricted_access() already obtained! |
| 4833 | */ |
| 4834 | static void iwl_print_event_log(struct iwl_priv *priv, u32 start_idx, |
| 4835 | u32 num_events, u32 mode) |
| 4836 | { |
| 4837 | u32 i; |
| 4838 | u32 base; /* SRAM byte address of event log header */ |
| 4839 | u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ |
| 4840 | u32 ptr; /* SRAM byte address of log data */ |
| 4841 | u32 ev, time, data; /* event log data */ |
| 4842 | |
| 4843 | if (num_events == 0) |
| 4844 | return; |
| 4845 | |
| 4846 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
| 4847 | |
| 4848 | if (mode == 0) |
| 4849 | event_size = 2 * sizeof(u32); |
| 4850 | else |
| 4851 | event_size = 3 * sizeof(u32); |
| 4852 | |
| 4853 | ptr = base + EVENT_START_OFFSET + (start_idx * event_size); |
| 4854 | |
| 4855 | /* "time" is actually "data" for mode 0 (no timestamp). |
| 4856 | * place event id # at far right for easier visual parsing. */ |
| 4857 | for (i = 0; i < num_events; i++) { |
| 4858 | ev = iwl_read_restricted_mem(priv, ptr); |
| 4859 | ptr += sizeof(u32); |
| 4860 | time = iwl_read_restricted_mem(priv, ptr); |
| 4861 | ptr += sizeof(u32); |
| 4862 | if (mode == 0) |
| 4863 | IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */ |
| 4864 | else { |
| 4865 | data = iwl_read_restricted_mem(priv, ptr); |
| 4866 | ptr += sizeof(u32); |
| 4867 | IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev); |
| 4868 | } |
| 4869 | } |
| 4870 | } |
| 4871 | |
| 4872 | static void iwl_dump_nic_event_log(struct iwl_priv *priv) |
| 4873 | { |
| 4874 | int rc; |
| 4875 | u32 base; /* SRAM byte address of event log header */ |
| 4876 | u32 capacity; /* event log capacity in # entries */ |
| 4877 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ |
| 4878 | u32 num_wraps; /* # times uCode wrapped to top of log */ |
| 4879 | u32 next_entry; /* index of next entry to be written by uCode */ |
| 4880 | u32 size; /* # entries that we'll print */ |
| 4881 | |
| 4882 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
| 4883 | if (!iwl_hw_valid_rtc_data_addr(base)) { |
| 4884 | IWL_ERROR("Invalid event log pointer 0x%08X\n", base); |
| 4885 | return; |
| 4886 | } |
| 4887 | |
| 4888 | rc = iwl_grab_restricted_access(priv); |
| 4889 | if (rc) { |
| 4890 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 4891 | return; |
| 4892 | } |
| 4893 | |
| 4894 | /* event log header */ |
| 4895 | capacity = iwl_read_restricted_mem(priv, base); |
| 4896 | mode = iwl_read_restricted_mem(priv, base + (1 * sizeof(u32))); |
| 4897 | num_wraps = iwl_read_restricted_mem(priv, base + (2 * sizeof(u32))); |
| 4898 | next_entry = iwl_read_restricted_mem(priv, base + (3 * sizeof(u32))); |
| 4899 | |
| 4900 | size = num_wraps ? capacity : next_entry; |
| 4901 | |
| 4902 | /* bail out if nothing in log */ |
| 4903 | if (size == 0) { |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 4904 | IWL_ERROR("Start IWL Event Log Dump: nothing in log\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4905 | iwl_release_restricted_access(priv); |
| 4906 | return; |
| 4907 | } |
| 4908 | |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 4909 | IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4910 | size, num_wraps); |
| 4911 | |
| 4912 | /* if uCode has wrapped back to top of log, start at the oldest entry, |
| 4913 | * i.e the next one that uCode would fill. */ |
| 4914 | if (num_wraps) |
| 4915 | iwl_print_event_log(priv, next_entry, |
| 4916 | capacity - next_entry, mode); |
| 4917 | |
| 4918 | /* (then/else) start at top of log */ |
| 4919 | iwl_print_event_log(priv, 0, next_entry, mode); |
| 4920 | |
| 4921 | iwl_release_restricted_access(priv); |
| 4922 | } |
| 4923 | |
| 4924 | /** |
| 4925 | * iwl_irq_handle_error - called for HW or SW error interrupt from card |
| 4926 | */ |
| 4927 | static void iwl_irq_handle_error(struct iwl_priv *priv) |
| 4928 | { |
| 4929 | /* Set the FW error flag -- cleared on iwl_down */ |
| 4930 | set_bit(STATUS_FW_ERROR, &priv->status); |
| 4931 | |
| 4932 | /* Cancel currently queued command. */ |
| 4933 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 4934 | |
| 4935 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 4936 | if (iwl_debug_level & IWL_DL_FW_ERRORS) { |
| 4937 | iwl_dump_nic_error_log(priv); |
| 4938 | iwl_dump_nic_event_log(priv); |
| 4939 | iwl_print_rx_config_cmd(&priv->staging_rxon); |
| 4940 | } |
| 4941 | #endif |
| 4942 | |
| 4943 | wake_up_interruptible(&priv->wait_command_queue); |
| 4944 | |
| 4945 | /* Keep the restart process from trying to send host |
| 4946 | * commands by clearing the INIT status bit */ |
| 4947 | clear_bit(STATUS_READY, &priv->status); |
| 4948 | |
| 4949 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 4950 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS, |
| 4951 | "Restarting adapter due to uCode error.\n"); |
| 4952 | |
| 4953 | if (iwl_is_associated(priv)) { |
| 4954 | memcpy(&priv->recovery_rxon, &priv->active_rxon, |
| 4955 | sizeof(priv->recovery_rxon)); |
| 4956 | priv->error_recovering = 1; |
| 4957 | } |
| 4958 | queue_work(priv->workqueue, &priv->restart); |
| 4959 | } |
| 4960 | } |
| 4961 | |
| 4962 | static void iwl_error_recovery(struct iwl_priv *priv) |
| 4963 | { |
| 4964 | unsigned long flags; |
| 4965 | |
| 4966 | memcpy(&priv->staging_rxon, &priv->recovery_rxon, |
| 4967 | sizeof(priv->staging_rxon)); |
| 4968 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 4969 | iwl_commit_rxon(priv); |
| 4970 | |
| 4971 | iwl_rxon_add_station(priv, priv->bssid, 1); |
| 4972 | |
| 4973 | spin_lock_irqsave(&priv->lock, flags); |
| 4974 | priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); |
| 4975 | priv->error_recovering = 0; |
| 4976 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4977 | } |
| 4978 | |
| 4979 | static void iwl_irq_tasklet(struct iwl_priv *priv) |
| 4980 | { |
| 4981 | u32 inta, handled = 0; |
| 4982 | u32 inta_fh; |
| 4983 | unsigned long flags; |
| 4984 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 4985 | u32 inta_mask; |
| 4986 | #endif |
| 4987 | |
| 4988 | spin_lock_irqsave(&priv->lock, flags); |
| 4989 | |
| 4990 | /* Ack/clear/reset pending uCode interrupts. |
| 4991 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 4992 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
| 4993 | inta = iwl_read32(priv, CSR_INT); |
| 4994 | iwl_write32(priv, CSR_INT, inta); |
| 4995 | |
| 4996 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 4997 | * Any new interrupts that happen after this, either while we're |
| 4998 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
| 4999 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
| 5000 | iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
| 5001 | |
| 5002 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 5003 | if (iwl_debug_level & IWL_DL_ISR) { |
| 5004 | inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 5005 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 5006 | inta, inta_mask, inta_fh); |
| 5007 | } |
| 5008 | #endif |
| 5009 | |
| 5010 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 5011 | * atomic, make sure that inta covers all the interrupts that |
| 5012 | * we've discovered, even if FH interrupt came in just after |
| 5013 | * reading CSR_INT. */ |
| 5014 | if (inta_fh & CSR_FH_INT_RX_MASK) |
| 5015 | inta |= CSR_INT_BIT_FH_RX; |
| 5016 | if (inta_fh & CSR_FH_INT_TX_MASK) |
| 5017 | inta |= CSR_INT_BIT_FH_TX; |
| 5018 | |
| 5019 | /* Now service all interrupt bits discovered above. */ |
| 5020 | if (inta & CSR_INT_BIT_HW_ERR) { |
| 5021 | IWL_ERROR("Microcode HW error detected. Restarting.\n"); |
| 5022 | |
| 5023 | /* Tell the device to stop sending interrupts */ |
| 5024 | iwl_disable_interrupts(priv); |
| 5025 | |
| 5026 | iwl_irq_handle_error(priv); |
| 5027 | |
| 5028 | handled |= CSR_INT_BIT_HW_ERR; |
| 5029 | |
| 5030 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5031 | |
| 5032 | return; |
| 5033 | } |
| 5034 | |
| 5035 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 5036 | if (iwl_debug_level & (IWL_DL_ISR)) { |
| 5037 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
| 5038 | if (inta & CSR_INT_BIT_MAC_CLK_ACTV) |
| 5039 | IWL_DEBUG_ISR("Microcode started or stopped.\n"); |
| 5040 | |
| 5041 | /* Alive notification via Rx interrupt will do the real work */ |
| 5042 | if (inta & CSR_INT_BIT_ALIVE) |
| 5043 | IWL_DEBUG_ISR("Alive interrupt\n"); |
| 5044 | } |
| 5045 | #endif |
| 5046 | /* Safely ignore these bits for debug checks below */ |
| 5047 | inta &= ~(CSR_INT_BIT_MAC_CLK_ACTV | CSR_INT_BIT_ALIVE); |
| 5048 | |
| 5049 | /* HW RF KILL switch toggled (4965 only) */ |
| 5050 | if (inta & CSR_INT_BIT_RF_KILL) { |
| 5051 | int hw_rf_kill = 0; |
| 5052 | if (!(iwl_read32(priv, CSR_GP_CNTRL) & |
| 5053 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 5054 | hw_rf_kill = 1; |
| 5055 | |
| 5056 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL | IWL_DL_ISR, |
| 5057 | "RF_KILL bit toggled to %s.\n", |
| 5058 | hw_rf_kill ? "disable radio":"enable radio"); |
| 5059 | |
| 5060 | /* Queue restart only if RF_KILL switch was set to "kill" |
| 5061 | * when we loaded driver, and is now set to "enable". |
| 5062 | * After we're Alive, RF_KILL gets handled by |
| 5063 | * iwl_rx_card_state_notif() */ |
| 5064 | if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) |
| 5065 | queue_work(priv->workqueue, &priv->restart); |
| 5066 | |
| 5067 | handled |= CSR_INT_BIT_RF_KILL; |
| 5068 | } |
| 5069 | |
| 5070 | /* Chip got too hot and stopped itself (4965 only) */ |
| 5071 | if (inta & CSR_INT_BIT_CT_KILL) { |
| 5072 | IWL_ERROR("Microcode CT kill error detected.\n"); |
| 5073 | handled |= CSR_INT_BIT_CT_KILL; |
| 5074 | } |
| 5075 | |
| 5076 | /* Error detected by uCode */ |
| 5077 | if (inta & CSR_INT_BIT_SW_ERR) { |
| 5078 | IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n", |
| 5079 | inta); |
| 5080 | iwl_irq_handle_error(priv); |
| 5081 | handled |= CSR_INT_BIT_SW_ERR; |
| 5082 | } |
| 5083 | |
| 5084 | /* uCode wakes up after power-down sleep */ |
| 5085 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 5086 | IWL_DEBUG_ISR("Wakeup interrupt\n"); |
| 5087 | iwl_rx_queue_update_write_ptr(priv, &priv->rxq); |
| 5088 | iwl_tx_queue_update_write_ptr(priv, &priv->txq[0]); |
| 5089 | iwl_tx_queue_update_write_ptr(priv, &priv->txq[1]); |
| 5090 | iwl_tx_queue_update_write_ptr(priv, &priv->txq[2]); |
| 5091 | iwl_tx_queue_update_write_ptr(priv, &priv->txq[3]); |
| 5092 | iwl_tx_queue_update_write_ptr(priv, &priv->txq[4]); |
| 5093 | iwl_tx_queue_update_write_ptr(priv, &priv->txq[5]); |
| 5094 | |
| 5095 | handled |= CSR_INT_BIT_WAKEUP; |
| 5096 | } |
| 5097 | |
| 5098 | /* All uCode command responses, including Tx command responses, |
| 5099 | * Rx "responses" (frame-received notification), and other |
| 5100 | * notifications from uCode come through here*/ |
| 5101 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
| 5102 | iwl_rx_handle(priv); |
| 5103 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 5104 | } |
| 5105 | |
| 5106 | if (inta & CSR_INT_BIT_FH_TX) { |
| 5107 | IWL_DEBUG_ISR("Tx interrupt\n"); |
| 5108 | handled |= CSR_INT_BIT_FH_TX; |
| 5109 | } |
| 5110 | |
| 5111 | if (inta & ~handled) |
| 5112 | IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
| 5113 | |
| 5114 | if (inta & ~CSR_INI_SET_MASK) { |
| 5115 | IWL_WARNING("Disabled INTA bits 0x%08x were pending\n", |
| 5116 | inta & ~CSR_INI_SET_MASK); |
| 5117 | IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh); |
| 5118 | } |
| 5119 | |
| 5120 | /* Re-enable all interrupts */ |
| 5121 | iwl_enable_interrupts(priv); |
| 5122 | |
| 5123 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 5124 | if (iwl_debug_level & (IWL_DL_ISR)) { |
| 5125 | inta = iwl_read32(priv, CSR_INT); |
| 5126 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
| 5127 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
| 5128 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 5129 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 5130 | } |
| 5131 | #endif |
| 5132 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5133 | } |
| 5134 | |
| 5135 | static irqreturn_t iwl_isr(int irq, void *data) |
| 5136 | { |
| 5137 | struct iwl_priv *priv = data; |
| 5138 | u32 inta, inta_mask; |
| 5139 | u32 inta_fh; |
| 5140 | if (!priv) |
| 5141 | return IRQ_NONE; |
| 5142 | |
| 5143 | spin_lock(&priv->lock); |
| 5144 | |
| 5145 | /* Disable (but don't clear!) interrupts here to avoid |
| 5146 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 5147 | * If we have something to service, the tasklet will re-enable ints. |
| 5148 | * If we *don't* have something, we'll re-enable before leaving here. */ |
| 5149 | inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 5150 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
| 5151 | |
| 5152 | /* Discover which interrupts are active/pending */ |
| 5153 | inta = iwl_read32(priv, CSR_INT); |
| 5154 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
| 5155 | |
| 5156 | /* Ignore interrupt if there's nothing in NIC to service. |
| 5157 | * This may be due to IRQ shared with another device, |
| 5158 | * or due to sporadic interrupts thrown from our NIC. */ |
| 5159 | if (!inta && !inta_fh) { |
| 5160 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); |
| 5161 | goto none; |
| 5162 | } |
| 5163 | |
| 5164 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
| 5165 | /* Hardware disappeared */ |
| 5166 | IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta); |
| 5167 | goto none; |
| 5168 | } |
| 5169 | |
| 5170 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 5171 | inta, inta_mask, inta_fh); |
| 5172 | |
| 5173 | /* iwl_irq_tasklet() will service interrupts and re-enable them */ |
| 5174 | tasklet_schedule(&priv->irq_tasklet); |
| 5175 | spin_unlock(&priv->lock); |
| 5176 | |
| 5177 | return IRQ_HANDLED; |
| 5178 | |
| 5179 | none: |
| 5180 | /* re-enable interrupts here since we don't have anything to service. */ |
| 5181 | iwl_enable_interrupts(priv); |
| 5182 | spin_unlock(&priv->lock); |
| 5183 | return IRQ_NONE; |
| 5184 | } |
| 5185 | |
| 5186 | /************************** EEPROM BANDS **************************** |
| 5187 | * |
| 5188 | * The iwl_eeprom_band definitions below provide the mapping from the |
| 5189 | * EEPROM contents to the specific channel number supported for each |
| 5190 | * band. |
| 5191 | * |
| 5192 | * For example, iwl_priv->eeprom.band_3_channels[4] from the band_3 |
| 5193 | * definition below maps to physical channel 42 in the 5.2GHz spectrum. |
| 5194 | * The specific geography and calibration information for that channel |
| 5195 | * is contained in the eeprom map itself. |
| 5196 | * |
| 5197 | * During init, we copy the eeprom information and channel map |
| 5198 | * information into priv->channel_info_24/52 and priv->channel_map_24/52 |
| 5199 | * |
| 5200 | * channel_map_24/52 provides the index in the channel_info array for a |
| 5201 | * given channel. We have to have two separate maps as there is channel |
| 5202 | * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and |
| 5203 | * band_2 |
| 5204 | * |
| 5205 | * A value of 0xff stored in the channel_map indicates that the channel |
| 5206 | * is not supported by the hardware at all. |
| 5207 | * |
| 5208 | * A value of 0xfe in the channel_map indicates that the channel is not |
| 5209 | * valid for Tx with the current hardware. This means that |
| 5210 | * while the system can tune and receive on a given channel, it may not |
| 5211 | * be able to associate or transmit any frames on that |
| 5212 | * channel. There is no corresponding channel information for that |
| 5213 | * entry. |
| 5214 | * |
| 5215 | *********************************************************************/ |
| 5216 | |
| 5217 | /* 2.4 GHz */ |
| 5218 | static const u8 iwl_eeprom_band_1[14] = { |
| 5219 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 |
| 5220 | }; |
| 5221 | |
| 5222 | /* 5.2 GHz bands */ |
| 5223 | static const u8 iwl_eeprom_band_2[] = { |
| 5224 | 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16 |
| 5225 | }; |
| 5226 | |
| 5227 | static const u8 iwl_eeprom_band_3[] = { /* 5205-5320MHz */ |
| 5228 | 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64 |
| 5229 | }; |
| 5230 | |
| 5231 | static const u8 iwl_eeprom_band_4[] = { /* 5500-5700MHz */ |
| 5232 | 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 |
| 5233 | }; |
| 5234 | |
| 5235 | static const u8 iwl_eeprom_band_5[] = { /* 5725-5825MHz */ |
| 5236 | 145, 149, 153, 157, 161, 165 |
| 5237 | }; |
| 5238 | |
| 5239 | static u8 iwl_eeprom_band_6[] = { /* 2.4 FAT channel */ |
| 5240 | 1, 2, 3, 4, 5, 6, 7 |
| 5241 | }; |
| 5242 | |
| 5243 | static u8 iwl_eeprom_band_7[] = { /* 5.2 FAT channel */ |
| 5244 | 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157 |
| 5245 | }; |
| 5246 | |
| 5247 | static void iwl_init_band_reference(const struct iwl_priv *priv, int band, |
| 5248 | int *eeprom_ch_count, |
| 5249 | const struct iwl_eeprom_channel |
| 5250 | **eeprom_ch_info, |
| 5251 | const u8 **eeprom_ch_index) |
| 5252 | { |
| 5253 | switch (band) { |
| 5254 | case 1: /* 2.4GHz band */ |
| 5255 | *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_1); |
| 5256 | *eeprom_ch_info = priv->eeprom.band_1_channels; |
| 5257 | *eeprom_ch_index = iwl_eeprom_band_1; |
| 5258 | break; |
| 5259 | case 2: /* 5.2GHz band */ |
| 5260 | *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_2); |
| 5261 | *eeprom_ch_info = priv->eeprom.band_2_channels; |
| 5262 | *eeprom_ch_index = iwl_eeprom_band_2; |
| 5263 | break; |
| 5264 | case 3: /* 5.2GHz band */ |
| 5265 | *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_3); |
| 5266 | *eeprom_ch_info = priv->eeprom.band_3_channels; |
| 5267 | *eeprom_ch_index = iwl_eeprom_band_3; |
| 5268 | break; |
| 5269 | case 4: /* 5.2GHz band */ |
| 5270 | *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_4); |
| 5271 | *eeprom_ch_info = priv->eeprom.band_4_channels; |
| 5272 | *eeprom_ch_index = iwl_eeprom_band_4; |
| 5273 | break; |
| 5274 | case 5: /* 5.2GHz band */ |
| 5275 | *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_5); |
| 5276 | *eeprom_ch_info = priv->eeprom.band_5_channels; |
| 5277 | *eeprom_ch_index = iwl_eeprom_band_5; |
| 5278 | break; |
| 5279 | case 6: |
| 5280 | *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_6); |
| 5281 | *eeprom_ch_info = priv->eeprom.band_24_channels; |
| 5282 | *eeprom_ch_index = iwl_eeprom_band_6; |
| 5283 | break; |
| 5284 | case 7: |
| 5285 | *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_7); |
| 5286 | *eeprom_ch_info = priv->eeprom.band_52_channels; |
| 5287 | *eeprom_ch_index = iwl_eeprom_band_7; |
| 5288 | break; |
| 5289 | default: |
| 5290 | BUG(); |
| 5291 | return; |
| 5292 | } |
| 5293 | } |
| 5294 | |
| 5295 | const struct iwl_channel_info *iwl_get_channel_info(const struct iwl_priv *priv, |
| 5296 | int phymode, u16 channel) |
| 5297 | { |
| 5298 | int i; |
| 5299 | |
| 5300 | switch (phymode) { |
| 5301 | case MODE_IEEE80211A: |
| 5302 | for (i = 14; i < priv->channel_count; i++) { |
| 5303 | if (priv->channel_info[i].channel == channel) |
| 5304 | return &priv->channel_info[i]; |
| 5305 | } |
| 5306 | break; |
| 5307 | |
| 5308 | case MODE_IEEE80211B: |
| 5309 | case MODE_IEEE80211G: |
| 5310 | if (channel >= 1 && channel <= 14) |
| 5311 | return &priv->channel_info[channel - 1]; |
| 5312 | break; |
| 5313 | |
| 5314 | } |
| 5315 | |
| 5316 | return NULL; |
| 5317 | } |
| 5318 | |
| 5319 | #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \ |
| 5320 | ? # x " " : "") |
| 5321 | |
| 5322 | static int iwl_init_channel_map(struct iwl_priv *priv) |
| 5323 | { |
| 5324 | int eeprom_ch_count = 0; |
| 5325 | const u8 *eeprom_ch_index = NULL; |
| 5326 | const struct iwl_eeprom_channel *eeprom_ch_info = NULL; |
| 5327 | int band, ch; |
| 5328 | struct iwl_channel_info *ch_info; |
| 5329 | |
| 5330 | if (priv->channel_count) { |
| 5331 | IWL_DEBUG_INFO("Channel map already initialized.\n"); |
| 5332 | return 0; |
| 5333 | } |
| 5334 | |
| 5335 | if (priv->eeprom.version < 0x2f) { |
| 5336 | IWL_WARNING("Unsupported EEPROM version: 0x%04X\n", |
| 5337 | priv->eeprom.version); |
| 5338 | return -EINVAL; |
| 5339 | } |
| 5340 | |
| 5341 | IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n"); |
| 5342 | |
| 5343 | priv->channel_count = |
| 5344 | ARRAY_SIZE(iwl_eeprom_band_1) + |
| 5345 | ARRAY_SIZE(iwl_eeprom_band_2) + |
| 5346 | ARRAY_SIZE(iwl_eeprom_band_3) + |
| 5347 | ARRAY_SIZE(iwl_eeprom_band_4) + |
| 5348 | ARRAY_SIZE(iwl_eeprom_band_5); |
| 5349 | |
| 5350 | IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count); |
| 5351 | |
| 5352 | priv->channel_info = kzalloc(sizeof(struct iwl_channel_info) * |
| 5353 | priv->channel_count, GFP_KERNEL); |
| 5354 | if (!priv->channel_info) { |
| 5355 | IWL_ERROR("Could not allocate channel_info\n"); |
| 5356 | priv->channel_count = 0; |
| 5357 | return -ENOMEM; |
| 5358 | } |
| 5359 | |
| 5360 | ch_info = priv->channel_info; |
| 5361 | |
| 5362 | /* Loop through the 5 EEPROM bands adding them in order to the |
| 5363 | * channel map we maintain (that contains additional information than |
| 5364 | * what just in the EEPROM) */ |
| 5365 | for (band = 1; band <= 5; band++) { |
| 5366 | |
| 5367 | iwl_init_band_reference(priv, band, &eeprom_ch_count, |
| 5368 | &eeprom_ch_info, &eeprom_ch_index); |
| 5369 | |
| 5370 | /* Loop through each band adding each of the channels */ |
| 5371 | for (ch = 0; ch < eeprom_ch_count; ch++) { |
| 5372 | ch_info->channel = eeprom_ch_index[ch]; |
| 5373 | ch_info->phymode = (band == 1) ? MODE_IEEE80211B : |
| 5374 | MODE_IEEE80211A; |
| 5375 | |
| 5376 | /* permanently store EEPROM's channel regulatory flags |
| 5377 | * and max power in channel info database. */ |
| 5378 | ch_info->eeprom = eeprom_ch_info[ch]; |
| 5379 | |
| 5380 | /* Copy the run-time flags so they are there even on |
| 5381 | * invalid channels */ |
| 5382 | ch_info->flags = eeprom_ch_info[ch].flags; |
| 5383 | |
| 5384 | if (!(is_channel_valid(ch_info))) { |
| 5385 | IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - " |
| 5386 | "No traffic\n", |
| 5387 | ch_info->channel, |
| 5388 | ch_info->flags, |
| 5389 | is_channel_a_band(ch_info) ? |
| 5390 | "5.2" : "2.4"); |
| 5391 | ch_info++; |
| 5392 | continue; |
| 5393 | } |
| 5394 | |
| 5395 | /* Initialize regulatory-based run-time data */ |
| 5396 | ch_info->max_power_avg = ch_info->curr_txpow = |
| 5397 | eeprom_ch_info[ch].max_power_avg; |
| 5398 | ch_info->scan_power = eeprom_ch_info[ch].max_power_avg; |
| 5399 | ch_info->min_power = 0; |
| 5400 | |
| 5401 | IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x" |
| 5402 | " %ddBm): Ad-Hoc %ssupported\n", |
| 5403 | ch_info->channel, |
| 5404 | is_channel_a_band(ch_info) ? |
| 5405 | "5.2" : "2.4", |
| 5406 | CHECK_AND_PRINT(IBSS), |
| 5407 | CHECK_AND_PRINT(ACTIVE), |
| 5408 | CHECK_AND_PRINT(RADAR), |
| 5409 | CHECK_AND_PRINT(WIDE), |
| 5410 | CHECK_AND_PRINT(NARROW), |
| 5411 | CHECK_AND_PRINT(DFS), |
| 5412 | eeprom_ch_info[ch].flags, |
| 5413 | eeprom_ch_info[ch].max_power_avg, |
| 5414 | ((eeprom_ch_info[ch]. |
| 5415 | flags & EEPROM_CHANNEL_IBSS) |
| 5416 | && !(eeprom_ch_info[ch]. |
| 5417 | flags & EEPROM_CHANNEL_RADAR)) |
| 5418 | ? "" : "not "); |
| 5419 | |
| 5420 | /* Set the user_txpower_limit to the highest power |
| 5421 | * supported by any channel */ |
| 5422 | if (eeprom_ch_info[ch].max_power_avg > |
| 5423 | priv->user_txpower_limit) |
| 5424 | priv->user_txpower_limit = |
| 5425 | eeprom_ch_info[ch].max_power_avg; |
| 5426 | |
| 5427 | ch_info++; |
| 5428 | } |
| 5429 | } |
| 5430 | |
| 5431 | for (band = 6; band <= 7; band++) { |
| 5432 | int phymode; |
| 5433 | u8 fat_extension_chan; |
| 5434 | |
| 5435 | iwl_init_band_reference(priv, band, &eeprom_ch_count, |
| 5436 | &eeprom_ch_info, &eeprom_ch_index); |
| 5437 | |
| 5438 | phymode = (band == 6) ? MODE_IEEE80211B : MODE_IEEE80211A; |
| 5439 | /* Loop through each band adding each of the channels */ |
| 5440 | for (ch = 0; ch < eeprom_ch_count; ch++) { |
| 5441 | |
| 5442 | if ((band == 6) && |
| 5443 | ((eeprom_ch_index[ch] == 5) || |
| 5444 | (eeprom_ch_index[ch] == 6) || |
| 5445 | (eeprom_ch_index[ch] == 7))) |
| 5446 | fat_extension_chan = HT_IE_EXT_CHANNEL_MAX; |
| 5447 | else |
| 5448 | fat_extension_chan = HT_IE_EXT_CHANNEL_ABOVE; |
| 5449 | |
| 5450 | iwl4965_set_fat_chan_info(priv, phymode, |
| 5451 | eeprom_ch_index[ch], |
| 5452 | &(eeprom_ch_info[ch]), |
| 5453 | fat_extension_chan); |
| 5454 | |
| 5455 | iwl4965_set_fat_chan_info(priv, phymode, |
| 5456 | (eeprom_ch_index[ch] + 4), |
| 5457 | &(eeprom_ch_info[ch]), |
| 5458 | HT_IE_EXT_CHANNEL_BELOW); |
| 5459 | } |
| 5460 | } |
| 5461 | |
| 5462 | return 0; |
| 5463 | } |
| 5464 | |
| 5465 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
| 5466 | * sending probe req. This should be set long enough to hear probe responses |
| 5467 | * from more than one AP. */ |
| 5468 | #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 5469 | #define IWL_ACTIVE_DWELL_TIME_52 (10) |
| 5470 | |
| 5471 | /* For faster active scanning, scan will move to the next channel if fewer than |
| 5472 | * PLCP_QUIET_THRESH packets are heard on this channel within |
| 5473 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell |
| 5474 | * time if it's a quiet channel (nothing responded to our probe, and there's |
| 5475 | * no other traffic). |
| 5476 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ |
| 5477 | #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ |
| 5478 | #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */ |
| 5479 | |
| 5480 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
| 5481 | * Must be set longer than active dwell time. |
| 5482 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ |
| 5483 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 5484 | #define IWL_PASSIVE_DWELL_TIME_52 (10) |
| 5485 | #define IWL_PASSIVE_DWELL_BASE (100) |
| 5486 | #define IWL_CHANNEL_TUNE_TIME 5 |
| 5487 | |
| 5488 | static inline u16 iwl_get_active_dwell_time(struct iwl_priv *priv, int phymode) |
| 5489 | { |
| 5490 | if (phymode == MODE_IEEE80211A) |
| 5491 | return IWL_ACTIVE_DWELL_TIME_52; |
| 5492 | else |
| 5493 | return IWL_ACTIVE_DWELL_TIME_24; |
| 5494 | } |
| 5495 | |
| 5496 | static u16 iwl_get_passive_dwell_time(struct iwl_priv *priv, int phymode) |
| 5497 | { |
| 5498 | u16 active = iwl_get_active_dwell_time(priv, phymode); |
| 5499 | u16 passive = (phymode != MODE_IEEE80211A) ? |
| 5500 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
| 5501 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; |
| 5502 | |
| 5503 | if (iwl_is_associated(priv)) { |
| 5504 | /* If we're associated, we clamp the maximum passive |
| 5505 | * dwell time to be 98% of the beacon interval (minus |
| 5506 | * 2 * channel tune time) */ |
| 5507 | passive = priv->beacon_int; |
| 5508 | if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) |
| 5509 | passive = IWL_PASSIVE_DWELL_BASE; |
| 5510 | passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; |
| 5511 | } |
| 5512 | |
| 5513 | if (passive <= active) |
| 5514 | passive = active + 1; |
| 5515 | |
| 5516 | return passive; |
| 5517 | } |
| 5518 | |
| 5519 | static int iwl_get_channels_for_scan(struct iwl_priv *priv, int phymode, |
| 5520 | u8 is_active, u8 direct_mask, |
| 5521 | struct iwl_scan_channel *scan_ch) |
| 5522 | { |
| 5523 | const struct ieee80211_channel *channels = NULL; |
| 5524 | const struct ieee80211_hw_mode *hw_mode; |
| 5525 | const struct iwl_channel_info *ch_info; |
| 5526 | u16 passive_dwell = 0; |
| 5527 | u16 active_dwell = 0; |
| 5528 | int added, i; |
| 5529 | |
| 5530 | hw_mode = iwl_get_hw_mode(priv, phymode); |
| 5531 | if (!hw_mode) |
| 5532 | return 0; |
| 5533 | |
| 5534 | channels = hw_mode->channels; |
| 5535 | |
| 5536 | active_dwell = iwl_get_active_dwell_time(priv, phymode); |
| 5537 | passive_dwell = iwl_get_passive_dwell_time(priv, phymode); |
| 5538 | |
| 5539 | for (i = 0, added = 0; i < hw_mode->num_channels; i++) { |
| 5540 | if (channels[i].chan == |
| 5541 | le16_to_cpu(priv->active_rxon.channel)) { |
| 5542 | if (iwl_is_associated(priv)) { |
| 5543 | IWL_DEBUG_SCAN |
| 5544 | ("Skipping current channel %d\n", |
| 5545 | le16_to_cpu(priv->active_rxon.channel)); |
| 5546 | continue; |
| 5547 | } |
| 5548 | } else if (priv->only_active_channel) |
| 5549 | continue; |
| 5550 | |
| 5551 | scan_ch->channel = channels[i].chan; |
| 5552 | |
| 5553 | ch_info = iwl_get_channel_info(priv, phymode, scan_ch->channel); |
| 5554 | if (!is_channel_valid(ch_info)) { |
| 5555 | IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", |
| 5556 | scan_ch->channel); |
| 5557 | continue; |
| 5558 | } |
| 5559 | |
| 5560 | if (!is_active || is_channel_passive(ch_info) || |
| 5561 | !(channels[i].flag & IEEE80211_CHAN_W_ACTIVE_SCAN)) |
| 5562 | scan_ch->type = 0; /* passive */ |
| 5563 | else |
| 5564 | scan_ch->type = 1; /* active */ |
| 5565 | |
| 5566 | if (scan_ch->type & 1) |
| 5567 | scan_ch->type |= (direct_mask << 1); |
| 5568 | |
| 5569 | if (is_channel_narrow(ch_info)) |
| 5570 | scan_ch->type |= (1 << 7); |
| 5571 | |
| 5572 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 5573 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
| 5574 | |
| 5575 | /* Set power levels to defaults */ |
| 5576 | scan_ch->tpc.dsp_atten = 110; |
| 5577 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 5578 | |
| 5579 | /*scan_pwr_info->tpc.tx_gain; */ |
| 5580 | if (phymode == MODE_IEEE80211A) |
| 5581 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 5582 | else { |
| 5583 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 5584 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
| 5585 | * power level |
| 5586 | scan_ch->tpc.tx_gain = ((1<<5) | (2 << 3)) | 3; |
| 5587 | */ |
| 5588 | } |
| 5589 | |
| 5590 | IWL_DEBUG_SCAN("Scanning %d [%s %d]\n", |
| 5591 | scan_ch->channel, |
| 5592 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 5593 | (scan_ch->type & 1) ? |
| 5594 | active_dwell : passive_dwell); |
| 5595 | |
| 5596 | scan_ch++; |
| 5597 | added++; |
| 5598 | } |
| 5599 | |
| 5600 | IWL_DEBUG_SCAN("total channels to scan %d \n", added); |
| 5601 | return added; |
| 5602 | } |
| 5603 | |
| 5604 | static void iwl_reset_channel_flag(struct iwl_priv *priv) |
| 5605 | { |
| 5606 | int i, j; |
| 5607 | for (i = 0; i < 3; i++) { |
| 5608 | struct ieee80211_hw_mode *hw_mode = (void *)&priv->modes[i]; |
| 5609 | for (j = 0; j < hw_mode->num_channels; j++) |
| 5610 | hw_mode->channels[j].flag = hw_mode->channels[j].val; |
| 5611 | } |
| 5612 | } |
| 5613 | |
| 5614 | static void iwl_init_hw_rates(struct iwl_priv *priv, |
| 5615 | struct ieee80211_rate *rates) |
| 5616 | { |
| 5617 | int i; |
| 5618 | |
| 5619 | for (i = 0; i < IWL_RATE_COUNT; i++) { |
| 5620 | rates[i].rate = iwl_rates[i].ieee * 5; |
| 5621 | rates[i].val = i; /* Rate scaling will work on indexes */ |
| 5622 | rates[i].val2 = i; |
| 5623 | rates[i].flags = IEEE80211_RATE_SUPPORTED; |
| 5624 | /* Only OFDM have the bits-per-symbol set */ |
| 5625 | if ((i <= IWL_LAST_OFDM_RATE) && (i >= IWL_FIRST_OFDM_RATE)) |
| 5626 | rates[i].flags |= IEEE80211_RATE_OFDM; |
| 5627 | else { |
| 5628 | /* |
| 5629 | * If CCK 1M then set rate flag to CCK else CCK_2 |
| 5630 | * which is CCK | PREAMBLE2 |
| 5631 | */ |
| 5632 | rates[i].flags |= (iwl_rates[i].plcp == 10) ? |
| 5633 | IEEE80211_RATE_CCK : IEEE80211_RATE_CCK_2; |
| 5634 | } |
| 5635 | |
| 5636 | /* Set up which ones are basic rates... */ |
| 5637 | if (IWL_BASIC_RATES_MASK & (1 << i)) |
| 5638 | rates[i].flags |= IEEE80211_RATE_BASIC; |
| 5639 | } |
| 5640 | |
| 5641 | iwl4965_init_hw_rates(priv, rates); |
| 5642 | } |
| 5643 | |
| 5644 | /** |
| 5645 | * iwl_init_geos - Initialize mac80211's geo/channel info based from eeprom |
| 5646 | */ |
| 5647 | static int iwl_init_geos(struct iwl_priv *priv) |
| 5648 | { |
| 5649 | struct iwl_channel_info *ch; |
| 5650 | struct ieee80211_hw_mode *modes; |
| 5651 | struct ieee80211_channel *channels; |
| 5652 | struct ieee80211_channel *geo_ch; |
| 5653 | struct ieee80211_rate *rates; |
| 5654 | int i = 0; |
| 5655 | enum { |
| 5656 | A = 0, |
| 5657 | B = 1, |
| 5658 | G = 2, |
| 5659 | A_11N = 3, |
| 5660 | G_11N = 4, |
| 5661 | }; |
| 5662 | int mode_count = 5; |
| 5663 | |
| 5664 | if (priv->modes) { |
| 5665 | IWL_DEBUG_INFO("Geography modes already initialized.\n"); |
| 5666 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 5667 | return 0; |
| 5668 | } |
| 5669 | |
| 5670 | modes = kzalloc(sizeof(struct ieee80211_hw_mode) * mode_count, |
| 5671 | GFP_KERNEL); |
| 5672 | if (!modes) |
| 5673 | return -ENOMEM; |
| 5674 | |
| 5675 | channels = kzalloc(sizeof(struct ieee80211_channel) * |
| 5676 | priv->channel_count, GFP_KERNEL); |
| 5677 | if (!channels) { |
| 5678 | kfree(modes); |
| 5679 | return -ENOMEM; |
| 5680 | } |
| 5681 | |
| 5682 | rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_MAX_RATES + 1)), |
| 5683 | GFP_KERNEL); |
| 5684 | if (!rates) { |
| 5685 | kfree(modes); |
| 5686 | kfree(channels); |
| 5687 | return -ENOMEM; |
| 5688 | } |
| 5689 | |
| 5690 | /* 0 = 802.11a |
| 5691 | * 1 = 802.11b |
| 5692 | * 2 = 802.11g |
| 5693 | */ |
| 5694 | |
| 5695 | /* 5.2GHz channels start after the 2.4GHz channels */ |
| 5696 | modes[A].mode = MODE_IEEE80211A; |
| 5697 | modes[A].channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)]; |
| 5698 | modes[A].rates = rates; |
| 5699 | modes[A].num_rates = 8; /* just OFDM */ |
| 5700 | modes[A].rates = &rates[4]; |
| 5701 | modes[A].num_channels = 0; |
| 5702 | |
| 5703 | modes[B].mode = MODE_IEEE80211B; |
| 5704 | modes[B].channels = channels; |
| 5705 | modes[B].rates = rates; |
| 5706 | modes[B].num_rates = 4; /* just CCK */ |
| 5707 | modes[B].num_channels = 0; |
| 5708 | |
| 5709 | modes[G].mode = MODE_IEEE80211G; |
| 5710 | modes[G].channels = channels; |
| 5711 | modes[G].rates = rates; |
| 5712 | modes[G].num_rates = 12; /* OFDM & CCK */ |
| 5713 | modes[G].num_channels = 0; |
| 5714 | |
| 5715 | modes[G_11N].mode = MODE_IEEE80211G; |
| 5716 | modes[G_11N].channels = channels; |
| 5717 | modes[G_11N].num_rates = 13; /* OFDM & CCK */ |
| 5718 | modes[G_11N].rates = rates; |
| 5719 | modes[G_11N].num_channels = 0; |
| 5720 | |
| 5721 | modes[A_11N].mode = MODE_IEEE80211A; |
| 5722 | modes[A_11N].channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)]; |
| 5723 | modes[A_11N].rates = &rates[4]; |
| 5724 | modes[A_11N].num_rates = 9; /* just OFDM */ |
| 5725 | modes[A_11N].num_channels = 0; |
| 5726 | |
| 5727 | priv->ieee_channels = channels; |
| 5728 | priv->ieee_rates = rates; |
| 5729 | |
| 5730 | iwl_init_hw_rates(priv, rates); |
| 5731 | |
| 5732 | for (i = 0, geo_ch = channels; i < priv->channel_count; i++) { |
| 5733 | ch = &priv->channel_info[i]; |
| 5734 | |
| 5735 | if (!is_channel_valid(ch)) { |
| 5736 | IWL_DEBUG_INFO("Channel %d [%sGHz] is restricted -- " |
| 5737 | "skipping.\n", |
| 5738 | ch->channel, is_channel_a_band(ch) ? |
| 5739 | "5.2" : "2.4"); |
| 5740 | continue; |
| 5741 | } |
| 5742 | |
| 5743 | if (is_channel_a_band(ch)) { |
| 5744 | geo_ch = &modes[A].channels[modes[A].num_channels++]; |
| 5745 | modes[A_11N].num_channels++; |
| 5746 | } else { |
| 5747 | geo_ch = &modes[B].channels[modes[B].num_channels++]; |
| 5748 | modes[G].num_channels++; |
| 5749 | modes[G_11N].num_channels++; |
| 5750 | } |
| 5751 | |
| 5752 | geo_ch->freq = ieee80211chan2mhz(ch->channel); |
| 5753 | geo_ch->chan = ch->channel; |
| 5754 | geo_ch->power_level = ch->max_power_avg; |
| 5755 | geo_ch->antenna_max = 0xff; |
| 5756 | |
| 5757 | if (is_channel_valid(ch)) { |
| 5758 | geo_ch->flag = IEEE80211_CHAN_W_SCAN; |
| 5759 | if (ch->flags & EEPROM_CHANNEL_IBSS) |
| 5760 | geo_ch->flag |= IEEE80211_CHAN_W_IBSS; |
| 5761 | |
| 5762 | if (ch->flags & EEPROM_CHANNEL_ACTIVE) |
| 5763 | geo_ch->flag |= IEEE80211_CHAN_W_ACTIVE_SCAN; |
| 5764 | |
| 5765 | if (ch->flags & EEPROM_CHANNEL_RADAR) |
| 5766 | geo_ch->flag |= IEEE80211_CHAN_W_RADAR_DETECT; |
| 5767 | |
| 5768 | if (ch->max_power_avg > priv->max_channel_txpower_limit) |
| 5769 | priv->max_channel_txpower_limit = |
| 5770 | ch->max_power_avg; |
| 5771 | } |
| 5772 | |
| 5773 | geo_ch->val = geo_ch->flag; |
| 5774 | } |
| 5775 | |
| 5776 | if ((modes[A].num_channels == 0) && priv->is_abg) { |
| 5777 | printk(KERN_INFO DRV_NAME |
| 5778 | ": Incorrectly detected BG card as ABG. Please send " |
| 5779 | "your PCI ID 0x%04X:0x%04X to maintainer.\n", |
| 5780 | priv->pci_dev->device, priv->pci_dev->subsystem_device); |
| 5781 | priv->is_abg = 0; |
| 5782 | } |
| 5783 | |
| 5784 | printk(KERN_INFO DRV_NAME |
| 5785 | ": Tunable channels: %d 802.11bg, %d 802.11a channels\n", |
| 5786 | modes[G].num_channels, modes[A].num_channels); |
| 5787 | |
| 5788 | /* |
| 5789 | * NOTE: We register these in preference of order -- the |
| 5790 | * stack doesn't currently (as of 7.0.6 / Apr 24 '07) pick |
| 5791 | * a phymode based on rates or AP capabilities but seems to |
| 5792 | * configure it purely on if the channel being configured |
| 5793 | * is supported by a mode -- and the first match is taken |
| 5794 | */ |
| 5795 | |
| 5796 | if (modes[G].num_channels) |
| 5797 | ieee80211_register_hwmode(priv->hw, &modes[G]); |
| 5798 | if (modes[B].num_channels) |
| 5799 | ieee80211_register_hwmode(priv->hw, &modes[B]); |
| 5800 | if (modes[A].num_channels) |
| 5801 | ieee80211_register_hwmode(priv->hw, &modes[A]); |
| 5802 | |
| 5803 | priv->modes = modes; |
| 5804 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 5805 | |
| 5806 | return 0; |
| 5807 | } |
| 5808 | |
| 5809 | /****************************************************************************** |
| 5810 | * |
| 5811 | * uCode download functions |
| 5812 | * |
| 5813 | ******************************************************************************/ |
| 5814 | |
| 5815 | static void iwl_dealloc_ucode_pci(struct iwl_priv *priv) |
| 5816 | { |
| 5817 | if (priv->ucode_code.v_addr != NULL) { |
| 5818 | pci_free_consistent(priv->pci_dev, |
| 5819 | priv->ucode_code.len, |
| 5820 | priv->ucode_code.v_addr, |
| 5821 | priv->ucode_code.p_addr); |
| 5822 | priv->ucode_code.v_addr = NULL; |
| 5823 | } |
| 5824 | if (priv->ucode_data.v_addr != NULL) { |
| 5825 | pci_free_consistent(priv->pci_dev, |
| 5826 | priv->ucode_data.len, |
| 5827 | priv->ucode_data.v_addr, |
| 5828 | priv->ucode_data.p_addr); |
| 5829 | priv->ucode_data.v_addr = NULL; |
| 5830 | } |
| 5831 | if (priv->ucode_data_backup.v_addr != NULL) { |
| 5832 | pci_free_consistent(priv->pci_dev, |
| 5833 | priv->ucode_data_backup.len, |
| 5834 | priv->ucode_data_backup.v_addr, |
| 5835 | priv->ucode_data_backup.p_addr); |
| 5836 | priv->ucode_data_backup.v_addr = NULL; |
| 5837 | } |
| 5838 | if (priv->ucode_init.v_addr != NULL) { |
| 5839 | pci_free_consistent(priv->pci_dev, |
| 5840 | priv->ucode_init.len, |
| 5841 | priv->ucode_init.v_addr, |
| 5842 | priv->ucode_init.p_addr); |
| 5843 | priv->ucode_init.v_addr = NULL; |
| 5844 | } |
| 5845 | if (priv->ucode_init_data.v_addr != NULL) { |
| 5846 | pci_free_consistent(priv->pci_dev, |
| 5847 | priv->ucode_init_data.len, |
| 5848 | priv->ucode_init_data.v_addr, |
| 5849 | priv->ucode_init_data.p_addr); |
| 5850 | priv->ucode_init_data.v_addr = NULL; |
| 5851 | } |
| 5852 | if (priv->ucode_boot.v_addr != NULL) { |
| 5853 | pci_free_consistent(priv->pci_dev, |
| 5854 | priv->ucode_boot.len, |
| 5855 | priv->ucode_boot.v_addr, |
| 5856 | priv->ucode_boot.p_addr); |
| 5857 | priv->ucode_boot.v_addr = NULL; |
| 5858 | } |
| 5859 | } |
| 5860 | |
| 5861 | /** |
| 5862 | * iwl_verify_inst_full - verify runtime uCode image in card vs. host, |
| 5863 | * looking at all data. |
| 5864 | */ |
| 5865 | static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 * image, u32 len) |
| 5866 | { |
| 5867 | u32 val; |
| 5868 | u32 save_len = len; |
| 5869 | int rc = 0; |
| 5870 | u32 errcnt; |
| 5871 | |
| 5872 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 5873 | |
| 5874 | rc = iwl_grab_restricted_access(priv); |
| 5875 | if (rc) |
| 5876 | return rc; |
| 5877 | |
| 5878 | iwl_write_restricted(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND); |
| 5879 | |
| 5880 | errcnt = 0; |
| 5881 | for (; len > 0; len -= sizeof(u32), image++) { |
| 5882 | /* read data comes through single port, auto-incr addr */ |
| 5883 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 5884 | * if IWL_DL_IO is set */ |
| 5885 | val = _iwl_read_restricted(priv, HBUS_TARG_MEM_RDAT); |
| 5886 | if (val != le32_to_cpu(*image)) { |
| 5887 | IWL_ERROR("uCode INST section is invalid at " |
| 5888 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 5889 | save_len - len, val, le32_to_cpu(*image)); |
| 5890 | rc = -EIO; |
| 5891 | errcnt++; |
| 5892 | if (errcnt >= 20) |
| 5893 | break; |
| 5894 | } |
| 5895 | } |
| 5896 | |
| 5897 | iwl_release_restricted_access(priv); |
| 5898 | |
| 5899 | if (!errcnt) |
| 5900 | IWL_DEBUG_INFO |
| 5901 | ("ucode image in INSTRUCTION memory is good\n"); |
| 5902 | |
| 5903 | return rc; |
| 5904 | } |
| 5905 | |
| 5906 | |
| 5907 | /** |
| 5908 | * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host, |
| 5909 | * using sample data 100 bytes apart. If these sample points are good, |
| 5910 | * it's a pretty good bet that everything between them is good, too. |
| 5911 | */ |
| 5912 | static int iwl_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len) |
| 5913 | { |
| 5914 | u32 val; |
| 5915 | int rc = 0; |
| 5916 | u32 errcnt = 0; |
| 5917 | u32 i; |
| 5918 | |
| 5919 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 5920 | |
| 5921 | rc = iwl_grab_restricted_access(priv); |
| 5922 | if (rc) |
| 5923 | return rc; |
| 5924 | |
| 5925 | for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) { |
| 5926 | /* read data comes through single port, auto-incr addr */ |
| 5927 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 5928 | * if IWL_DL_IO is set */ |
| 5929 | iwl_write_restricted(priv, HBUS_TARG_MEM_RADDR, |
| 5930 | i + RTC_INST_LOWER_BOUND); |
| 5931 | val = _iwl_read_restricted(priv, HBUS_TARG_MEM_RDAT); |
| 5932 | if (val != le32_to_cpu(*image)) { |
| 5933 | #if 0 /* Enable this if you want to see details */ |
| 5934 | IWL_ERROR("uCode INST section is invalid at " |
| 5935 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 5936 | i, val, *image); |
| 5937 | #endif |
| 5938 | rc = -EIO; |
| 5939 | errcnt++; |
| 5940 | if (errcnt >= 3) |
| 5941 | break; |
| 5942 | } |
| 5943 | } |
| 5944 | |
| 5945 | iwl_release_restricted_access(priv); |
| 5946 | |
| 5947 | return rc; |
| 5948 | } |
| 5949 | |
| 5950 | |
| 5951 | /** |
| 5952 | * iwl_verify_ucode - determine which instruction image is in SRAM, |
| 5953 | * and verify its contents |
| 5954 | */ |
| 5955 | static int iwl_verify_ucode(struct iwl_priv *priv) |
| 5956 | { |
| 5957 | __le32 *image; |
| 5958 | u32 len; |
| 5959 | int rc = 0; |
| 5960 | |
| 5961 | /* Try bootstrap */ |
| 5962 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 5963 | len = priv->ucode_boot.len; |
| 5964 | rc = iwl_verify_inst_sparse(priv, image, len); |
| 5965 | if (rc == 0) { |
| 5966 | IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n"); |
| 5967 | return 0; |
| 5968 | } |
| 5969 | |
| 5970 | /* Try initialize */ |
| 5971 | image = (__le32 *)priv->ucode_init.v_addr; |
| 5972 | len = priv->ucode_init.len; |
| 5973 | rc = iwl_verify_inst_sparse(priv, image, len); |
| 5974 | if (rc == 0) { |
| 5975 | IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n"); |
| 5976 | return 0; |
| 5977 | } |
| 5978 | |
| 5979 | /* Try runtime/protocol */ |
| 5980 | image = (__le32 *)priv->ucode_code.v_addr; |
| 5981 | len = priv->ucode_code.len; |
| 5982 | rc = iwl_verify_inst_sparse(priv, image, len); |
| 5983 | if (rc == 0) { |
| 5984 | IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n"); |
| 5985 | return 0; |
| 5986 | } |
| 5987 | |
| 5988 | IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n"); |
| 5989 | |
| 5990 | /* Show first several data entries in instruction SRAM. |
| 5991 | * Selection of bootstrap image is arbitrary. */ |
| 5992 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 5993 | len = priv->ucode_boot.len; |
| 5994 | rc = iwl_verify_inst_full(priv, image, len); |
| 5995 | |
| 5996 | return rc; |
| 5997 | } |
| 5998 | |
| 5999 | |
| 6000 | /* check contents of special bootstrap uCode SRAM */ |
| 6001 | static int iwl_verify_bsm(struct iwl_priv *priv) |
| 6002 | { |
| 6003 | __le32 *image = priv->ucode_boot.v_addr; |
| 6004 | u32 len = priv->ucode_boot.len; |
| 6005 | u32 reg; |
| 6006 | u32 val; |
| 6007 | |
| 6008 | IWL_DEBUG_INFO("Begin verify bsm\n"); |
| 6009 | |
| 6010 | /* verify BSM SRAM contents */ |
| 6011 | val = iwl_read_restricted_reg(priv, BSM_WR_DWCOUNT_REG); |
| 6012 | for (reg = BSM_SRAM_LOWER_BOUND; |
| 6013 | reg < BSM_SRAM_LOWER_BOUND + len; |
| 6014 | reg += sizeof(u32), image ++) { |
| 6015 | val = iwl_read_restricted_reg(priv, reg); |
| 6016 | if (val != le32_to_cpu(*image)) { |
| 6017 | IWL_ERROR("BSM uCode verification failed at " |
| 6018 | "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n", |
| 6019 | BSM_SRAM_LOWER_BOUND, |
| 6020 | reg - BSM_SRAM_LOWER_BOUND, len, |
| 6021 | val, le32_to_cpu(*image)); |
| 6022 | return -EIO; |
| 6023 | } |
| 6024 | } |
| 6025 | |
| 6026 | IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n"); |
| 6027 | |
| 6028 | return 0; |
| 6029 | } |
| 6030 | |
| 6031 | /** |
| 6032 | * iwl_load_bsm - Load bootstrap instructions |
| 6033 | * |
| 6034 | * BSM operation: |
| 6035 | * |
| 6036 | * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program |
| 6037 | * in special SRAM that does not power down during RFKILL. When powering back |
| 6038 | * up after power-saving sleeps (or during initial uCode load), the BSM loads |
| 6039 | * the bootstrap program into the on-board processor, and starts it. |
| 6040 | * |
| 6041 | * The bootstrap program loads (via DMA) instructions and data for a new |
| 6042 | * program from host DRAM locations indicated by the host driver in the |
| 6043 | * BSM_DRAM_* registers. Once the new program is loaded, it starts |
| 6044 | * automatically. |
| 6045 | * |
| 6046 | * When initializing the NIC, the host driver points the BSM to the |
| 6047 | * "initialize" uCode image. This uCode sets up some internal data, then |
| 6048 | * notifies host via "initialize alive" that it is complete. |
| 6049 | * |
| 6050 | * The host then replaces the BSM_DRAM_* pointer values to point to the |
| 6051 | * normal runtime uCode instructions and a backup uCode data cache buffer |
| 6052 | * (filled initially with starting data values for the on-board processor), |
| 6053 | * then triggers the "initialize" uCode to load and launch the runtime uCode, |
| 6054 | * which begins normal operation. |
| 6055 | * |
| 6056 | * When doing a power-save shutdown, runtime uCode saves data SRAM into |
| 6057 | * the backup data cache in DRAM before SRAM is powered down. |
| 6058 | * |
| 6059 | * When powering back up, the BSM loads the bootstrap program. This reloads |
| 6060 | * the runtime uCode instructions and the backup data cache into SRAM, |
| 6061 | * and re-launches the runtime uCode from where it left off. |
| 6062 | */ |
| 6063 | static int iwl_load_bsm(struct iwl_priv *priv) |
| 6064 | { |
| 6065 | __le32 *image = priv->ucode_boot.v_addr; |
| 6066 | u32 len = priv->ucode_boot.len; |
| 6067 | dma_addr_t pinst; |
| 6068 | dma_addr_t pdata; |
| 6069 | u32 inst_len; |
| 6070 | u32 data_len; |
| 6071 | int rc; |
| 6072 | int i; |
| 6073 | u32 done; |
| 6074 | u32 reg_offset; |
| 6075 | |
| 6076 | IWL_DEBUG_INFO("Begin load bsm\n"); |
| 6077 | |
| 6078 | /* make sure bootstrap program is no larger than BSM's SRAM size */ |
| 6079 | if (len > IWL_MAX_BSM_SIZE) |
| 6080 | return -EINVAL; |
| 6081 | |
| 6082 | /* Tell bootstrap uCode where to find the "Initialize" uCode |
| 6083 | * in host DRAM ... bits 31:0 for 3945, bits 35:4 for 4965. |
| 6084 | * NOTE: iwl_initialize_alive_start() will replace these values, |
| 6085 | * after the "initialize" uCode has run, to point to |
| 6086 | * runtime/protocol instructions and backup data cache. */ |
| 6087 | pinst = priv->ucode_init.p_addr >> 4; |
| 6088 | pdata = priv->ucode_init_data.p_addr >> 4; |
| 6089 | inst_len = priv->ucode_init.len; |
| 6090 | data_len = priv->ucode_init_data.len; |
| 6091 | |
| 6092 | rc = iwl_grab_restricted_access(priv); |
| 6093 | if (rc) |
| 6094 | return rc; |
| 6095 | |
| 6096 | iwl_write_restricted_reg(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 6097 | iwl_write_restricted_reg(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 6098 | iwl_write_restricted_reg(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len); |
| 6099 | iwl_write_restricted_reg(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len); |
| 6100 | |
| 6101 | /* Fill BSM memory with bootstrap instructions */ |
| 6102 | for (reg_offset = BSM_SRAM_LOWER_BOUND; |
| 6103 | reg_offset < BSM_SRAM_LOWER_BOUND + len; |
| 6104 | reg_offset += sizeof(u32), image++) |
| 6105 | _iwl_write_restricted_reg(priv, reg_offset, |
| 6106 | le32_to_cpu(*image)); |
| 6107 | |
| 6108 | rc = iwl_verify_bsm(priv); |
| 6109 | if (rc) { |
| 6110 | iwl_release_restricted_access(priv); |
| 6111 | return rc; |
| 6112 | } |
| 6113 | |
| 6114 | /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */ |
| 6115 | iwl_write_restricted_reg(priv, BSM_WR_MEM_SRC_REG, 0x0); |
| 6116 | iwl_write_restricted_reg(priv, BSM_WR_MEM_DST_REG, |
| 6117 | RTC_INST_LOWER_BOUND); |
| 6118 | iwl_write_restricted_reg(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32)); |
| 6119 | |
| 6120 | /* Load bootstrap code into instruction SRAM now, |
| 6121 | * to prepare to load "initialize" uCode */ |
| 6122 | iwl_write_restricted_reg(priv, BSM_WR_CTRL_REG, |
| 6123 | BSM_WR_CTRL_REG_BIT_START); |
| 6124 | |
| 6125 | /* Wait for load of bootstrap uCode to finish */ |
| 6126 | for (i = 0; i < 100; i++) { |
| 6127 | done = iwl_read_restricted_reg(priv, BSM_WR_CTRL_REG); |
| 6128 | if (!(done & BSM_WR_CTRL_REG_BIT_START)) |
| 6129 | break; |
| 6130 | udelay(10); |
| 6131 | } |
| 6132 | if (i < 100) |
| 6133 | IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i); |
| 6134 | else { |
| 6135 | IWL_ERROR("BSM write did not complete!\n"); |
| 6136 | return -EIO; |
| 6137 | } |
| 6138 | |
| 6139 | /* Enable future boot loads whenever power management unit triggers it |
| 6140 | * (e.g. when powering back up after power-save shutdown) */ |
| 6141 | iwl_write_restricted_reg(priv, BSM_WR_CTRL_REG, |
| 6142 | BSM_WR_CTRL_REG_BIT_START_EN); |
| 6143 | |
| 6144 | iwl_release_restricted_access(priv); |
| 6145 | |
| 6146 | return 0; |
| 6147 | } |
| 6148 | |
| 6149 | static void iwl_nic_start(struct iwl_priv *priv) |
| 6150 | { |
| 6151 | /* Remove all resets to allow NIC to operate */ |
| 6152 | iwl_write32(priv, CSR_RESET, 0); |
| 6153 | } |
| 6154 | |
| 6155 | /** |
| 6156 | * iwl_read_ucode - Read uCode images from disk file. |
| 6157 | * |
| 6158 | * Copy into buffers for card to fetch via bus-mastering |
| 6159 | */ |
| 6160 | static int iwl_read_ucode(struct iwl_priv *priv) |
| 6161 | { |
| 6162 | struct iwl_ucode *ucode; |
| 6163 | int rc = 0; |
| 6164 | const struct firmware *ucode_raw; |
| 6165 | const char *name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode"; |
| 6166 | u8 *src; |
| 6167 | size_t len; |
| 6168 | u32 ver, inst_size, data_size, init_size, init_data_size, boot_size; |
| 6169 | |
| 6170 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 6171 | * request_firmware() is synchronous, file is in memory on return. */ |
| 6172 | rc = request_firmware(&ucode_raw, name, &priv->pci_dev->dev); |
| 6173 | if (rc < 0) { |
| 6174 | IWL_ERROR("%s firmware file req failed: Reason %d\n", name, rc); |
| 6175 | goto error; |
| 6176 | } |
| 6177 | |
| 6178 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", |
| 6179 | name, ucode_raw->size); |
| 6180 | |
| 6181 | /* Make sure that we got at least our header! */ |
| 6182 | if (ucode_raw->size < sizeof(*ucode)) { |
| 6183 | IWL_ERROR("File size way too small!\n"); |
| 6184 | rc = -EINVAL; |
| 6185 | goto err_release; |
| 6186 | } |
| 6187 | |
| 6188 | /* Data from ucode file: header followed by uCode images */ |
| 6189 | ucode = (void *)ucode_raw->data; |
| 6190 | |
| 6191 | ver = le32_to_cpu(ucode->ver); |
| 6192 | inst_size = le32_to_cpu(ucode->inst_size); |
| 6193 | data_size = le32_to_cpu(ucode->data_size); |
| 6194 | init_size = le32_to_cpu(ucode->init_size); |
| 6195 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 6196 | boot_size = le32_to_cpu(ucode->boot_size); |
| 6197 | |
| 6198 | IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver); |
| 6199 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", |
| 6200 | inst_size); |
| 6201 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", |
| 6202 | data_size); |
| 6203 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", |
| 6204 | init_size); |
| 6205 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", |
| 6206 | init_data_size); |
| 6207 | IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", |
| 6208 | boot_size); |
| 6209 | |
| 6210 | /* Verify size of file vs. image size info in file's header */ |
| 6211 | if (ucode_raw->size < sizeof(*ucode) + |
| 6212 | inst_size + data_size + init_size + |
| 6213 | init_data_size + boot_size) { |
| 6214 | |
| 6215 | IWL_DEBUG_INFO("uCode file size %d too small\n", |
| 6216 | (int)ucode_raw->size); |
| 6217 | rc = -EINVAL; |
| 6218 | goto err_release; |
| 6219 | } |
| 6220 | |
| 6221 | /* Verify that uCode images will fit in card's SRAM */ |
| 6222 | if (inst_size > IWL_MAX_INST_SIZE) { |
| 6223 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in card\n", |
| 6224 | (int)inst_size); |
| 6225 | rc = -EINVAL; |
| 6226 | goto err_release; |
| 6227 | } |
| 6228 | |
| 6229 | if (data_size > IWL_MAX_DATA_SIZE) { |
| 6230 | IWL_DEBUG_INFO("uCode data len %d too large to fit in card\n", |
| 6231 | (int)data_size); |
| 6232 | rc = -EINVAL; |
| 6233 | goto err_release; |
| 6234 | } |
| 6235 | if (init_size > IWL_MAX_INST_SIZE) { |
| 6236 | IWL_DEBUG_INFO |
| 6237 | ("uCode init instr len %d too large to fit in card\n", |
| 6238 | (int)init_size); |
| 6239 | rc = -EINVAL; |
| 6240 | goto err_release; |
| 6241 | } |
| 6242 | if (init_data_size > IWL_MAX_DATA_SIZE) { |
| 6243 | IWL_DEBUG_INFO |
| 6244 | ("uCode init data len %d too large to fit in card\n", |
| 6245 | (int)init_data_size); |
| 6246 | rc = -EINVAL; |
| 6247 | goto err_release; |
| 6248 | } |
| 6249 | if (boot_size > IWL_MAX_BSM_SIZE) { |
| 6250 | IWL_DEBUG_INFO |
| 6251 | ("uCode boot instr len %d too large to fit in bsm\n", |
| 6252 | (int)boot_size); |
| 6253 | rc = -EINVAL; |
| 6254 | goto err_release; |
| 6255 | } |
| 6256 | |
| 6257 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 6258 | |
| 6259 | /* Runtime instructions and 2 copies of data: |
| 6260 | * 1) unmodified from disk |
| 6261 | * 2) backup cache for save/restore during power-downs */ |
| 6262 | priv->ucode_code.len = inst_size; |
| 6263 | priv->ucode_code.v_addr = |
| 6264 | pci_alloc_consistent(priv->pci_dev, |
| 6265 | priv->ucode_code.len, |
| 6266 | &(priv->ucode_code.p_addr)); |
| 6267 | |
| 6268 | priv->ucode_data.len = data_size; |
| 6269 | priv->ucode_data.v_addr = |
| 6270 | pci_alloc_consistent(priv->pci_dev, |
| 6271 | priv->ucode_data.len, |
| 6272 | &(priv->ucode_data.p_addr)); |
| 6273 | |
| 6274 | priv->ucode_data_backup.len = data_size; |
| 6275 | priv->ucode_data_backup.v_addr = |
| 6276 | pci_alloc_consistent(priv->pci_dev, |
| 6277 | priv->ucode_data_backup.len, |
| 6278 | &(priv->ucode_data_backup.p_addr)); |
| 6279 | |
| 6280 | |
| 6281 | /* Initialization instructions and data */ |
| 6282 | priv->ucode_init.len = init_size; |
| 6283 | priv->ucode_init.v_addr = |
| 6284 | pci_alloc_consistent(priv->pci_dev, |
| 6285 | priv->ucode_init.len, |
| 6286 | &(priv->ucode_init.p_addr)); |
| 6287 | |
| 6288 | priv->ucode_init_data.len = init_data_size; |
| 6289 | priv->ucode_init_data.v_addr = |
| 6290 | pci_alloc_consistent(priv->pci_dev, |
| 6291 | priv->ucode_init_data.len, |
| 6292 | &(priv->ucode_init_data.p_addr)); |
| 6293 | |
| 6294 | /* Bootstrap (instructions only, no data) */ |
| 6295 | priv->ucode_boot.len = boot_size; |
| 6296 | priv->ucode_boot.v_addr = |
| 6297 | pci_alloc_consistent(priv->pci_dev, |
| 6298 | priv->ucode_boot.len, |
| 6299 | &(priv->ucode_boot.p_addr)); |
| 6300 | |
| 6301 | if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr || |
| 6302 | !priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr || |
| 6303 | !priv->ucode_boot.v_addr || !priv->ucode_data_backup.v_addr) |
| 6304 | goto err_pci_alloc; |
| 6305 | |
| 6306 | /* Copy images into buffers for card's bus-master reads ... */ |
| 6307 | |
| 6308 | /* Runtime instructions (first block of data in file) */ |
| 6309 | src = &ucode->data[0]; |
| 6310 | len = priv->ucode_code.len; |
| 6311 | IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %d\n", |
| 6312 | (int)len); |
| 6313 | memcpy(priv->ucode_code.v_addr, src, len); |
| 6314 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
| 6315 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 6316 | |
| 6317 | /* Runtime data (2nd block) |
| 6318 | * NOTE: Copy into backup buffer will be done in iwl_up() */ |
| 6319 | src = &ucode->data[inst_size]; |
| 6320 | len = priv->ucode_data.len; |
| 6321 | IWL_DEBUG_INFO("Copying (but not loading) uCode data len %d\n", |
| 6322 | (int)len); |
| 6323 | memcpy(priv->ucode_data.v_addr, src, len); |
| 6324 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 6325 | |
| 6326 | /* Initialization instructions (3rd block) */ |
| 6327 | if (init_size) { |
| 6328 | src = &ucode->data[inst_size + data_size]; |
| 6329 | len = priv->ucode_init.len; |
| 6330 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %d\n", |
| 6331 | (int)len); |
| 6332 | memcpy(priv->ucode_init.v_addr, src, len); |
| 6333 | } |
| 6334 | |
| 6335 | /* Initialization data (4th block) */ |
| 6336 | if (init_data_size) { |
| 6337 | src = &ucode->data[inst_size + data_size + init_size]; |
| 6338 | len = priv->ucode_init_data.len; |
| 6339 | IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n", |
| 6340 | (int)len); |
| 6341 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 6342 | } |
| 6343 | |
| 6344 | /* Bootstrap instructions (5th block) */ |
| 6345 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 6346 | len = priv->ucode_boot.len; |
| 6347 | IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n", |
| 6348 | (int)len); |
| 6349 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 6350 | |
| 6351 | /* We have our copies now, allow OS release its copies */ |
| 6352 | release_firmware(ucode_raw); |
| 6353 | return 0; |
| 6354 | |
| 6355 | err_pci_alloc: |
| 6356 | IWL_ERROR("failed to allocate pci memory\n"); |
| 6357 | rc = -ENOMEM; |
| 6358 | iwl_dealloc_ucode_pci(priv); |
| 6359 | |
| 6360 | err_release: |
| 6361 | release_firmware(ucode_raw); |
| 6362 | |
| 6363 | error: |
| 6364 | return rc; |
| 6365 | } |
| 6366 | |
| 6367 | |
| 6368 | /** |
| 6369 | * iwl_set_ucode_ptrs - Set uCode address location |
| 6370 | * |
| 6371 | * Tell initialization uCode where to find runtime uCode. |
| 6372 | * |
| 6373 | * BSM registers initially contain pointers to initialization uCode. |
| 6374 | * We need to replace them to load runtime uCode inst and data, |
| 6375 | * and to save runtime data when powering down. |
| 6376 | */ |
| 6377 | static int iwl_set_ucode_ptrs(struct iwl_priv *priv) |
| 6378 | { |
| 6379 | dma_addr_t pinst; |
| 6380 | dma_addr_t pdata; |
| 6381 | int rc = 0; |
| 6382 | unsigned long flags; |
| 6383 | |
| 6384 | /* bits 35:4 for 4965 */ |
| 6385 | pinst = priv->ucode_code.p_addr >> 4; |
| 6386 | pdata = priv->ucode_data_backup.p_addr >> 4; |
| 6387 | |
| 6388 | spin_lock_irqsave(&priv->lock, flags); |
| 6389 | rc = iwl_grab_restricted_access(priv); |
| 6390 | if (rc) { |
| 6391 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6392 | return rc; |
| 6393 | } |
| 6394 | |
| 6395 | /* Tell bootstrap uCode where to find image to load */ |
| 6396 | iwl_write_restricted_reg(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 6397 | iwl_write_restricted_reg(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 6398 | iwl_write_restricted_reg(priv, BSM_DRAM_DATA_BYTECOUNT_REG, |
| 6399 | priv->ucode_data.len); |
| 6400 | |
| 6401 | /* Inst bytecount must be last to set up, bit 31 signals uCode |
| 6402 | * that all new ptr/size info is in place */ |
| 6403 | iwl_write_restricted_reg(priv, BSM_DRAM_INST_BYTECOUNT_REG, |
| 6404 | priv->ucode_code.len | BSM_DRAM_INST_LOAD); |
| 6405 | |
| 6406 | iwl_release_restricted_access(priv); |
| 6407 | |
| 6408 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6409 | |
| 6410 | IWL_DEBUG_INFO("Runtime uCode pointers are set.\n"); |
| 6411 | |
| 6412 | return rc; |
| 6413 | } |
| 6414 | |
| 6415 | /** |
| 6416 | * iwl_init_alive_start - Called after REPLY_ALIVE notification receieved |
| 6417 | * |
| 6418 | * Called after REPLY_ALIVE notification received from "initialize" uCode. |
| 6419 | * |
| 6420 | * The 4965 "initialize" ALIVE reply contains calibration data for: |
| 6421 | * Voltage, temperature, and MIMO tx gain correction, now stored in priv |
| 6422 | * (3945 does not contain this data). |
| 6423 | * |
| 6424 | * Tell "initialize" uCode to go ahead and load the runtime uCode. |
| 6425 | */ |
| 6426 | static void iwl_init_alive_start(struct iwl_priv *priv) |
| 6427 | { |
| 6428 | /* Check alive response for "valid" sign from uCode */ |
| 6429 | if (priv->card_alive_init.is_valid != UCODE_VALID_OK) { |
| 6430 | /* We had an error bringing up the hardware, so take it |
| 6431 | * all the way back down so we can try again */ |
| 6432 | IWL_DEBUG_INFO("Initialize Alive failed.\n"); |
| 6433 | goto restart; |
| 6434 | } |
| 6435 | |
| 6436 | /* Bootstrap uCode has loaded initialize uCode ... verify inst image. |
| 6437 | * This is a paranoid check, because we would not have gotten the |
| 6438 | * "initialize" alive if code weren't properly loaded. */ |
| 6439 | if (iwl_verify_ucode(priv)) { |
| 6440 | /* Runtime instruction load was bad; |
| 6441 | * take it all the way back down so we can try again */ |
| 6442 | IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n"); |
| 6443 | goto restart; |
| 6444 | } |
| 6445 | |
| 6446 | /* Calculate temperature */ |
| 6447 | priv->temperature = iwl4965_get_temperature(priv); |
| 6448 | |
| 6449 | /* Send pointers to protocol/runtime uCode image ... init code will |
| 6450 | * load and launch runtime uCode, which will send us another "Alive" |
| 6451 | * notification. */ |
| 6452 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
| 6453 | if (iwl_set_ucode_ptrs(priv)) { |
| 6454 | /* Runtime instruction load won't happen; |
| 6455 | * take it all the way back down so we can try again */ |
| 6456 | IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n"); |
| 6457 | goto restart; |
| 6458 | } |
| 6459 | return; |
| 6460 | |
| 6461 | restart: |
| 6462 | queue_work(priv->workqueue, &priv->restart); |
| 6463 | } |
| 6464 | |
| 6465 | |
| 6466 | /** |
| 6467 | * iwl_alive_start - called after REPLY_ALIVE notification received |
| 6468 | * from protocol/runtime uCode (initialization uCode's |
| 6469 | * Alive gets handled by iwl_init_alive_start()). |
| 6470 | */ |
| 6471 | static void iwl_alive_start(struct iwl_priv *priv) |
| 6472 | { |
| 6473 | int rc = 0; |
| 6474 | |
| 6475 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 6476 | |
| 6477 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 6478 | /* We had an error bringing up the hardware, so take it |
| 6479 | * all the way back down so we can try again */ |
| 6480 | IWL_DEBUG_INFO("Alive failed.\n"); |
| 6481 | goto restart; |
| 6482 | } |
| 6483 | |
| 6484 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 6485 | * This is a paranoid check, because we would not have gotten the |
| 6486 | * "runtime" alive if code weren't properly loaded. */ |
| 6487 | if (iwl_verify_ucode(priv)) { |
| 6488 | /* Runtime instruction load was bad; |
| 6489 | * take it all the way back down so we can try again */ |
| 6490 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); |
| 6491 | goto restart; |
| 6492 | } |
| 6493 | |
| 6494 | iwl_clear_stations_table(priv); |
| 6495 | |
| 6496 | rc = iwl4965_alive_notify(priv); |
| 6497 | if (rc) { |
| 6498 | IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n", |
| 6499 | rc); |
| 6500 | goto restart; |
| 6501 | } |
| 6502 | |
| 6503 | /* After the ALIVE response, we can process host commands */ |
| 6504 | set_bit(STATUS_ALIVE, &priv->status); |
| 6505 | |
| 6506 | /* Clear out the uCode error bit if it is set */ |
| 6507 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 6508 | |
| 6509 | rc = iwl_init_channel_map(priv); |
| 6510 | if (rc) { |
| 6511 | IWL_ERROR("initializing regulatory failed: %d\n", rc); |
| 6512 | return; |
| 6513 | } |
| 6514 | |
| 6515 | iwl_init_geos(priv); |
| 6516 | |
| 6517 | if (iwl_is_rfkill(priv)) |
| 6518 | return; |
| 6519 | |
| 6520 | if (!priv->mac80211_registered) { |
| 6521 | /* Unlock so any user space entry points can call back into |
| 6522 | * the driver without a deadlock... */ |
| 6523 | mutex_unlock(&priv->mutex); |
| 6524 | iwl_rate_control_register(priv->hw); |
| 6525 | rc = ieee80211_register_hw(priv->hw); |
| 6526 | priv->hw->conf.beacon_int = 100; |
| 6527 | mutex_lock(&priv->mutex); |
| 6528 | |
| 6529 | if (rc) { |
| 6530 | IWL_ERROR("Failed to register network " |
| 6531 | "device (error %d)\n", rc); |
| 6532 | return; |
| 6533 | } |
| 6534 | |
| 6535 | priv->mac80211_registered = 1; |
| 6536 | |
| 6537 | iwl_reset_channel_flag(priv); |
| 6538 | } else |
| 6539 | ieee80211_start_queues(priv->hw); |
| 6540 | |
| 6541 | priv->active_rate = priv->rates_mask; |
| 6542 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 6543 | |
| 6544 | iwl_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode)); |
| 6545 | |
| 6546 | if (iwl_is_associated(priv)) { |
| 6547 | struct iwl_rxon_cmd *active_rxon = |
| 6548 | (struct iwl_rxon_cmd *)(&priv->active_rxon); |
| 6549 | |
| 6550 | memcpy(&priv->staging_rxon, &priv->active_rxon, |
| 6551 | sizeof(priv->staging_rxon)); |
| 6552 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 6553 | } else { |
| 6554 | /* Initialize our rx_config data */ |
| 6555 | iwl_connection_init_rx_config(priv); |
| 6556 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 6557 | } |
| 6558 | |
| 6559 | /* Configure BT coexistence */ |
| 6560 | iwl_send_bt_config(priv); |
| 6561 | |
| 6562 | /* Configure the adapter for unassociated operation */ |
| 6563 | iwl_commit_rxon(priv); |
| 6564 | |
| 6565 | /* At this point, the NIC is initialized and operational */ |
| 6566 | priv->notif_missed_beacons = 0; |
| 6567 | set_bit(STATUS_READY, &priv->status); |
| 6568 | |
| 6569 | iwl4965_rf_kill_ct_config(priv); |
| 6570 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
| 6571 | |
| 6572 | if (priv->error_recovering) |
| 6573 | iwl_error_recovery(priv); |
| 6574 | |
| 6575 | return; |
| 6576 | |
| 6577 | restart: |
| 6578 | queue_work(priv->workqueue, &priv->restart); |
| 6579 | } |
| 6580 | |
| 6581 | static void iwl_cancel_deferred_work(struct iwl_priv *priv); |
| 6582 | |
| 6583 | static void __iwl_down(struct iwl_priv *priv) |
| 6584 | { |
| 6585 | unsigned long flags; |
| 6586 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6587 | struct ieee80211_conf *conf = NULL; |
| 6588 | |
| 6589 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); |
| 6590 | |
| 6591 | conf = ieee80211_get_hw_conf(priv->hw); |
| 6592 | |
| 6593 | if (!exit_pending) |
| 6594 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6595 | |
| 6596 | iwl_clear_stations_table(priv); |
| 6597 | |
| 6598 | /* Unblock any waiting calls */ |
| 6599 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 6600 | |
| 6601 | iwl_cancel_deferred_work(priv); |
| 6602 | |
| 6603 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 6604 | * exiting the module */ |
| 6605 | if (!exit_pending) |
| 6606 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6607 | |
| 6608 | /* stop and reset the on-board processor */ |
| 6609 | iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
| 6610 | |
| 6611 | /* tell the device to stop sending interrupts */ |
| 6612 | iwl_disable_interrupts(priv); |
| 6613 | |
| 6614 | if (priv->mac80211_registered) |
| 6615 | ieee80211_stop_queues(priv->hw); |
| 6616 | |
| 6617 | /* If we have not previously called iwl_init() then |
| 6618 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
| 6619 | if (!iwl_is_init(priv)) { |
| 6620 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 6621 | STATUS_RF_KILL_HW | |
| 6622 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 6623 | STATUS_RF_KILL_SW | |
| 6624 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 6625 | STATUS_IN_SUSPEND; |
| 6626 | goto exit; |
| 6627 | } |
| 6628 | |
| 6629 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 6630 | * SUSPEND bits and continue taking the NIC down. */ |
| 6631 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 6632 | STATUS_RF_KILL_HW | |
| 6633 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 6634 | STATUS_RF_KILL_SW | |
| 6635 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 6636 | STATUS_IN_SUSPEND | |
| 6637 | test_bit(STATUS_FW_ERROR, &priv->status) << |
| 6638 | STATUS_FW_ERROR; |
| 6639 | |
| 6640 | spin_lock_irqsave(&priv->lock, flags); |
| 6641 | iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 6642 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6643 | |
| 6644 | iwl_hw_txq_ctx_stop(priv); |
| 6645 | iwl_hw_rxq_stop(priv); |
| 6646 | |
| 6647 | spin_lock_irqsave(&priv->lock, flags); |
| 6648 | if (!iwl_grab_restricted_access(priv)) { |
| 6649 | iwl_write_restricted_reg(priv, APMG_CLK_DIS_REG, |
| 6650 | APMG_CLK_VAL_DMA_CLK_RQT); |
| 6651 | iwl_release_restricted_access(priv); |
| 6652 | } |
| 6653 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6654 | |
| 6655 | udelay(5); |
| 6656 | |
| 6657 | iwl_hw_nic_stop_master(priv); |
| 6658 | iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); |
| 6659 | iwl_hw_nic_reset(priv); |
| 6660 | |
| 6661 | exit: |
| 6662 | memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp)); |
| 6663 | |
| 6664 | if (priv->ibss_beacon) |
| 6665 | dev_kfree_skb(priv->ibss_beacon); |
| 6666 | priv->ibss_beacon = NULL; |
| 6667 | |
| 6668 | /* clear out any free frames */ |
| 6669 | iwl_clear_free_frames(priv); |
| 6670 | } |
| 6671 | |
| 6672 | static void iwl_down(struct iwl_priv *priv) |
| 6673 | { |
| 6674 | mutex_lock(&priv->mutex); |
| 6675 | __iwl_down(priv); |
| 6676 | mutex_unlock(&priv->mutex); |
| 6677 | } |
| 6678 | |
| 6679 | #define MAX_HW_RESTARTS 5 |
| 6680 | |
| 6681 | static int __iwl_up(struct iwl_priv *priv) |
| 6682 | { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 6683 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6684 | int rc, i; |
| 6685 | u32 hw_rf_kill = 0; |
| 6686 | |
| 6687 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 6688 | IWL_WARNING("Exit pending; will not bring the NIC up\n"); |
| 6689 | return -EIO; |
| 6690 | } |
| 6691 | |
| 6692 | if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { |
| 6693 | IWL_WARNING("Radio disabled by SW RF kill (module " |
| 6694 | "parameter)\n"); |
| 6695 | return 0; |
| 6696 | } |
| 6697 | |
| 6698 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
| 6699 | |
| 6700 | rc = iwl_hw_nic_init(priv); |
| 6701 | if (rc) { |
| 6702 | IWL_ERROR("Unable to int nic\n"); |
| 6703 | return rc; |
| 6704 | } |
| 6705 | |
| 6706 | /* make sure rfkill handshake bits are cleared */ |
| 6707 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 6708 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
| 6709 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 6710 | |
| 6711 | /* clear (again), then enable host interrupts */ |
| 6712 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
| 6713 | iwl_enable_interrupts(priv); |
| 6714 | |
| 6715 | /* really make sure rfkill handshake bits are cleared */ |
| 6716 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 6717 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 6718 | |
| 6719 | /* Copy original ucode data image from disk into backup cache. |
| 6720 | * This will be used to initialize the on-board processor's |
| 6721 | * data SRAM for a clean start when the runtime program first loads. */ |
| 6722 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
| 6723 | priv->ucode_data.len); |
| 6724 | |
| 6725 | /* If platform's RF_KILL switch is set to KILL, |
| 6726 | * wait for BIT_INT_RF_KILL interrupt before loading uCode |
| 6727 | * and getting things started */ |
| 6728 | if (!(iwl_read32(priv, CSR_GP_CNTRL) & |
| 6729 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 6730 | hw_rf_kill = 1; |
| 6731 | |
| 6732 | if (test_bit(STATUS_RF_KILL_HW, &priv->status) || hw_rf_kill) { |
| 6733 | IWL_WARNING("Radio disabled by HW RF Kill switch\n"); |
| 6734 | return 0; |
| 6735 | } |
| 6736 | |
| 6737 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 6738 | |
| 6739 | iwl_clear_stations_table(priv); |
| 6740 | |
| 6741 | /* load bootstrap state machine, |
| 6742 | * load bootstrap program into processor's memory, |
| 6743 | * prepare to load the "initialize" uCode */ |
| 6744 | rc = iwl_load_bsm(priv); |
| 6745 | |
| 6746 | if (rc) { |
| 6747 | IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc); |
| 6748 | continue; |
| 6749 | } |
| 6750 | |
| 6751 | /* start card; "initialize" will load runtime ucode */ |
| 6752 | iwl_nic_start(priv); |
| 6753 | |
| 6754 | /* MAC Address location in EEPROM same for 3945/4965 */ |
| 6755 | get_eeprom_mac(priv, priv->mac_addr); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 6756 | IWL_DEBUG_INFO("MAC address: %s\n", |
| 6757 | print_mac(mac, priv->mac_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6758 | |
| 6759 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 6760 | |
| 6761 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
| 6762 | |
| 6763 | return 0; |
| 6764 | } |
| 6765 | |
| 6766 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6767 | __iwl_down(priv); |
| 6768 | |
| 6769 | /* tried to restart and config the device for as long as our |
| 6770 | * patience could withstand */ |
| 6771 | IWL_ERROR("Unable to initialize device after %d attempts.\n", i); |
| 6772 | return -EIO; |
| 6773 | } |
| 6774 | |
| 6775 | |
| 6776 | /***************************************************************************** |
| 6777 | * |
| 6778 | * Workqueue callbacks |
| 6779 | * |
| 6780 | *****************************************************************************/ |
| 6781 | |
| 6782 | static void iwl_bg_init_alive_start(struct work_struct *data) |
| 6783 | { |
| 6784 | struct iwl_priv *priv = |
| 6785 | container_of(data, struct iwl_priv, init_alive_start.work); |
| 6786 | |
| 6787 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6788 | return; |
| 6789 | |
| 6790 | mutex_lock(&priv->mutex); |
| 6791 | iwl_init_alive_start(priv); |
| 6792 | mutex_unlock(&priv->mutex); |
| 6793 | } |
| 6794 | |
| 6795 | static void iwl_bg_alive_start(struct work_struct *data) |
| 6796 | { |
| 6797 | struct iwl_priv *priv = |
| 6798 | container_of(data, struct iwl_priv, alive_start.work); |
| 6799 | |
| 6800 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6801 | return; |
| 6802 | |
| 6803 | mutex_lock(&priv->mutex); |
| 6804 | iwl_alive_start(priv); |
| 6805 | mutex_unlock(&priv->mutex); |
| 6806 | } |
| 6807 | |
| 6808 | static void iwl_bg_rf_kill(struct work_struct *work) |
| 6809 | { |
| 6810 | struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill); |
| 6811 | |
| 6812 | wake_up_interruptible(&priv->wait_command_queue); |
| 6813 | |
| 6814 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6815 | return; |
| 6816 | |
| 6817 | mutex_lock(&priv->mutex); |
| 6818 | |
| 6819 | if (!iwl_is_rfkill(priv)) { |
| 6820 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL, |
| 6821 | "HW and/or SW RF Kill no longer active, restarting " |
| 6822 | "device\n"); |
| 6823 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6824 | queue_work(priv->workqueue, &priv->restart); |
| 6825 | } else { |
| 6826 | |
| 6827 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 6828 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 6829 | "disabled by SW switch\n"); |
| 6830 | else |
| 6831 | IWL_WARNING("Radio Frequency Kill Switch is On:\n" |
| 6832 | "Kill switch must be turned off for " |
| 6833 | "wireless networking to work.\n"); |
| 6834 | } |
| 6835 | mutex_unlock(&priv->mutex); |
| 6836 | } |
| 6837 | |
| 6838 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
| 6839 | |
| 6840 | static void iwl_bg_scan_check(struct work_struct *data) |
| 6841 | { |
| 6842 | struct iwl_priv *priv = |
| 6843 | container_of(data, struct iwl_priv, scan_check.work); |
| 6844 | |
| 6845 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6846 | return; |
| 6847 | |
| 6848 | mutex_lock(&priv->mutex); |
| 6849 | if (test_bit(STATUS_SCANNING, &priv->status) || |
| 6850 | test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 6851 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, |
| 6852 | "Scan completion watchdog resetting adapter (%dms)\n", |
| 6853 | jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); |
| 6854 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6855 | queue_work(priv->workqueue, &priv->restart); |
| 6856 | } |
| 6857 | mutex_unlock(&priv->mutex); |
| 6858 | } |
| 6859 | |
| 6860 | static void iwl_bg_request_scan(struct work_struct *data) |
| 6861 | { |
| 6862 | struct iwl_priv *priv = |
| 6863 | container_of(data, struct iwl_priv, request_scan); |
| 6864 | struct iwl_host_cmd cmd = { |
| 6865 | .id = REPLY_SCAN_CMD, |
| 6866 | .len = sizeof(struct iwl_scan_cmd), |
| 6867 | .meta.flags = CMD_SIZE_HUGE, |
| 6868 | }; |
| 6869 | int rc = 0; |
| 6870 | struct iwl_scan_cmd *scan; |
| 6871 | struct ieee80211_conf *conf = NULL; |
| 6872 | u8 direct_mask; |
| 6873 | int phymode; |
| 6874 | |
| 6875 | conf = ieee80211_get_hw_conf(priv->hw); |
| 6876 | |
| 6877 | mutex_lock(&priv->mutex); |
| 6878 | |
| 6879 | if (!iwl_is_ready(priv)) { |
| 6880 | IWL_WARNING("request scan called when driver not ready.\n"); |
| 6881 | goto done; |
| 6882 | } |
| 6883 | |
| 6884 | /* Make sure the scan wasn't cancelled before this queued work |
| 6885 | * was given the chance to run... */ |
| 6886 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 6887 | goto done; |
| 6888 | |
| 6889 | /* This should never be called or scheduled if there is currently |
| 6890 | * a scan active in the hardware. */ |
| 6891 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 6892 | IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. " |
| 6893 | "Ignoring second request.\n"); |
| 6894 | rc = -EIO; |
| 6895 | goto done; |
| 6896 | } |
| 6897 | |
| 6898 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 6899 | IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n"); |
| 6900 | goto done; |
| 6901 | } |
| 6902 | |
| 6903 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 6904 | IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 6905 | goto done; |
| 6906 | } |
| 6907 | |
| 6908 | if (iwl_is_rfkill(priv)) { |
| 6909 | IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 6910 | goto done; |
| 6911 | } |
| 6912 | |
| 6913 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 6914 | IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n"); |
| 6915 | goto done; |
| 6916 | } |
| 6917 | |
| 6918 | if (!priv->scan_bands) { |
| 6919 | IWL_DEBUG_HC("Aborting scan due to no requested bands\n"); |
| 6920 | goto done; |
| 6921 | } |
| 6922 | |
| 6923 | if (!priv->scan) { |
| 6924 | priv->scan = kmalloc(sizeof(struct iwl_scan_cmd) + |
| 6925 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
| 6926 | if (!priv->scan) { |
| 6927 | rc = -ENOMEM; |
| 6928 | goto done; |
| 6929 | } |
| 6930 | } |
| 6931 | scan = priv->scan; |
| 6932 | memset(scan, 0, sizeof(struct iwl_scan_cmd) + IWL_MAX_SCAN_SIZE); |
| 6933 | |
| 6934 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 6935 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 6936 | |
| 6937 | if (iwl_is_associated(priv)) { |
| 6938 | u16 interval = 0; |
| 6939 | u32 extra; |
| 6940 | u32 suspend_time = 100; |
| 6941 | u32 scan_suspend_time = 100; |
| 6942 | unsigned long flags; |
| 6943 | |
| 6944 | IWL_DEBUG_INFO("Scanning while associated...\n"); |
| 6945 | |
| 6946 | spin_lock_irqsave(&priv->lock, flags); |
| 6947 | interval = priv->beacon_int; |
| 6948 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6949 | |
| 6950 | scan->suspend_time = 0; |
| 6951 | scan->max_out_time = cpu_to_le32(600 * 1024); |
| 6952 | if (!interval) |
| 6953 | interval = suspend_time; |
| 6954 | |
| 6955 | extra = (suspend_time / interval) << 22; |
| 6956 | scan_suspend_time = (extra | |
| 6957 | ((suspend_time % interval) * 1024)); |
| 6958 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 6959 | IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n", |
| 6960 | scan_suspend_time, interval); |
| 6961 | } |
| 6962 | |
| 6963 | /* We should add the ability for user to lock to PASSIVE ONLY */ |
| 6964 | if (priv->one_direct_scan) { |
| 6965 | IWL_DEBUG_SCAN |
| 6966 | ("Kicking off one direct scan for '%s'\n", |
| 6967 | iwl_escape_essid(priv->direct_ssid, |
| 6968 | priv->direct_ssid_len)); |
| 6969 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 6970 | scan->direct_scan[0].len = priv->direct_ssid_len; |
| 6971 | memcpy(scan->direct_scan[0].ssid, |
| 6972 | priv->direct_ssid, priv->direct_ssid_len); |
| 6973 | direct_mask = 1; |
| 6974 | } else if (!iwl_is_associated(priv)) { |
| 6975 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 6976 | scan->direct_scan[0].len = priv->essid_len; |
| 6977 | memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len); |
| 6978 | direct_mask = 1; |
| 6979 | } else |
| 6980 | direct_mask = 0; |
| 6981 | |
| 6982 | /* We don't build a direct scan probe request; the uCode will do |
| 6983 | * that based on the direct_mask added to each channel entry */ |
| 6984 | scan->tx_cmd.len = cpu_to_le16( |
| 6985 | iwl_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data, |
| 6986 | IWL_MAX_SCAN_SIZE - sizeof(scan), 0)); |
| 6987 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
| 6988 | scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id; |
| 6989 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 6990 | |
| 6991 | /* flags + rate selection */ |
| 6992 | |
| 6993 | scan->tx_cmd.tx_flags |= cpu_to_le32(0x200); |
| 6994 | |
| 6995 | switch (priv->scan_bands) { |
| 6996 | case 2: |
| 6997 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 6998 | scan->tx_cmd.rate_n_flags = |
| 6999 | iwl_hw_set_rate_n_flags(IWL_RATE_1M_PLCP, |
| 7000 | RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK); |
| 7001 | |
| 7002 | scan->good_CRC_th = 0; |
| 7003 | phymode = MODE_IEEE80211G; |
| 7004 | break; |
| 7005 | |
| 7006 | case 1: |
| 7007 | scan->tx_cmd.rate_n_flags = |
| 7008 | iwl_hw_set_rate_n_flags(IWL_RATE_6M_PLCP, |
| 7009 | RATE_MCS_ANT_B_MSK); |
| 7010 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
| 7011 | phymode = MODE_IEEE80211A; |
| 7012 | break; |
| 7013 | |
| 7014 | default: |
| 7015 | IWL_WARNING("Invalid scan band count\n"); |
| 7016 | goto done; |
| 7017 | } |
| 7018 | |
| 7019 | /* select Rx chains */ |
| 7020 | |
| 7021 | /* Force use of chains B and C (0x6) for scan Rx. |
| 7022 | * Avoid A (0x1) because of its off-channel reception on A-band. |
| 7023 | * MIMO is not used here, but value is required to make uCode happy. */ |
| 7024 | scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK | |
| 7025 | cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) | |
| 7026 | (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) | |
| 7027 | (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS)); |
| 7028 | |
| 7029 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) |
| 7030 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; |
| 7031 | |
| 7032 | if (direct_mask) |
| 7033 | IWL_DEBUG_SCAN |
| 7034 | ("Initiating direct scan for %s.\n", |
| 7035 | iwl_escape_essid(priv->essid, priv->essid_len)); |
| 7036 | else |
| 7037 | IWL_DEBUG_SCAN("Initiating indirect scan.\n"); |
| 7038 | |
| 7039 | scan->channel_count = |
| 7040 | iwl_get_channels_for_scan( |
| 7041 | priv, phymode, 1, /* active */ |
| 7042 | direct_mask, |
| 7043 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
| 7044 | |
| 7045 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
| 7046 | scan->channel_count * sizeof(struct iwl_scan_channel); |
| 7047 | cmd.data = scan; |
| 7048 | scan->len = cpu_to_le16(cmd.len); |
| 7049 | |
| 7050 | set_bit(STATUS_SCAN_HW, &priv->status); |
| 7051 | rc = iwl_send_cmd_sync(priv, &cmd); |
| 7052 | if (rc) |
| 7053 | goto done; |
| 7054 | |
| 7055 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 7056 | IWL_SCAN_CHECK_WATCHDOG); |
| 7057 | |
| 7058 | mutex_unlock(&priv->mutex); |
| 7059 | return; |
| 7060 | |
| 7061 | done: |
| 7062 | /* inform mac80211 sacn aborted */ |
| 7063 | queue_work(priv->workqueue, &priv->scan_completed); |
| 7064 | mutex_unlock(&priv->mutex); |
| 7065 | } |
| 7066 | |
| 7067 | static void iwl_bg_up(struct work_struct *data) |
| 7068 | { |
| 7069 | struct iwl_priv *priv = container_of(data, struct iwl_priv, up); |
| 7070 | |
| 7071 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7072 | return; |
| 7073 | |
| 7074 | mutex_lock(&priv->mutex); |
| 7075 | __iwl_up(priv); |
| 7076 | mutex_unlock(&priv->mutex); |
| 7077 | } |
| 7078 | |
| 7079 | static void iwl_bg_restart(struct work_struct *data) |
| 7080 | { |
| 7081 | struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); |
| 7082 | |
| 7083 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7084 | return; |
| 7085 | |
| 7086 | iwl_down(priv); |
| 7087 | queue_work(priv->workqueue, &priv->up); |
| 7088 | } |
| 7089 | |
| 7090 | static void iwl_bg_rx_replenish(struct work_struct *data) |
| 7091 | { |
| 7092 | struct iwl_priv *priv = |
| 7093 | container_of(data, struct iwl_priv, rx_replenish); |
| 7094 | |
| 7095 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7096 | return; |
| 7097 | |
| 7098 | mutex_lock(&priv->mutex); |
| 7099 | iwl_rx_replenish(priv); |
| 7100 | mutex_unlock(&priv->mutex); |
| 7101 | } |
| 7102 | |
| 7103 | static void iwl_bg_post_associate(struct work_struct *data) |
| 7104 | { |
| 7105 | struct iwl_priv *priv = container_of(data, struct iwl_priv, |
| 7106 | post_associate.work); |
| 7107 | |
| 7108 | int rc = 0; |
| 7109 | struct ieee80211_conf *conf = NULL; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7110 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7111 | |
| 7112 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 7113 | IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__); |
| 7114 | return; |
| 7115 | } |
| 7116 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7117 | IWL_DEBUG_ASSOC("Associated as %d to: %s\n", |
| 7118 | priv->assoc_id, |
| 7119 | print_mac(mac, priv->active_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7120 | |
| 7121 | |
| 7122 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7123 | return; |
| 7124 | |
| 7125 | mutex_lock(&priv->mutex); |
| 7126 | |
| 7127 | conf = ieee80211_get_hw_conf(priv->hw); |
| 7128 | |
| 7129 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 7130 | iwl_commit_rxon(priv); |
| 7131 | |
| 7132 | memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); |
| 7133 | iwl_setup_rxon_timing(priv); |
| 7134 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
| 7135 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 7136 | if (rc) |
| 7137 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 7138 | "Attempting to continue.\n"); |
| 7139 | |
| 7140 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 7141 | |
| 7142 | #ifdef CONFIG_IWLWIFI_HT |
| 7143 | if (priv->is_ht_enabled && priv->current_assoc_ht.is_ht) |
| 7144 | iwl4965_set_rxon_ht(priv, &priv->current_assoc_ht); |
| 7145 | else { |
| 7146 | priv->active_rate_ht[0] = 0; |
| 7147 | priv->active_rate_ht[1] = 0; |
| 7148 | priv->current_channel_width = IWL_CHANNEL_WIDTH_20MHZ; |
| 7149 | } |
| 7150 | #endif /* CONFIG_IWLWIFI_HT*/ |
| 7151 | iwl4965_set_rxon_chain(priv); |
| 7152 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 7153 | |
| 7154 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", |
| 7155 | priv->assoc_id, priv->beacon_int); |
| 7156 | |
| 7157 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7158 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7159 | else |
| 7160 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7161 | |
| 7162 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 7163 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 7164 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 7165 | else |
| 7166 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 7167 | |
| 7168 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 7169 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 7170 | |
| 7171 | } |
| 7172 | |
| 7173 | iwl_commit_rxon(priv); |
| 7174 | |
| 7175 | switch (priv->iw_mode) { |
| 7176 | case IEEE80211_IF_TYPE_STA: |
| 7177 | iwl_rate_scale_init(priv->hw, IWL_AP_ID); |
| 7178 | break; |
| 7179 | |
| 7180 | case IEEE80211_IF_TYPE_IBSS: |
| 7181 | |
| 7182 | /* clear out the station table */ |
| 7183 | iwl_clear_stations_table(priv); |
| 7184 | |
| 7185 | iwl_rxon_add_station(priv, BROADCAST_ADDR, 0); |
| 7186 | iwl_rxon_add_station(priv, priv->bssid, 0); |
| 7187 | iwl_rate_scale_init(priv->hw, IWL_STA_ID); |
| 7188 | iwl_send_beacon_cmd(priv); |
| 7189 | |
| 7190 | break; |
| 7191 | |
| 7192 | default: |
| 7193 | IWL_ERROR("%s Should not be called in %d mode\n", |
| 7194 | __FUNCTION__, priv->iw_mode); |
| 7195 | break; |
| 7196 | } |
| 7197 | |
| 7198 | iwl_sequence_reset(priv); |
| 7199 | |
| 7200 | #ifdef CONFIG_IWLWIFI_SENSITIVITY |
| 7201 | /* Enable Rx differential gain and sensitivity calibrations */ |
| 7202 | iwl4965_chain_noise_reset(priv); |
| 7203 | priv->start_calib = 1; |
| 7204 | #endif /* CONFIG_IWLWIFI_SENSITIVITY */ |
| 7205 | |
| 7206 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 7207 | priv->assoc_station_added = 1; |
| 7208 | |
| 7209 | #ifdef CONFIG_IWLWIFI_QOS |
| 7210 | iwl_activate_qos(priv, 0); |
| 7211 | #endif /* CONFIG_IWLWIFI_QOS */ |
| 7212 | mutex_unlock(&priv->mutex); |
| 7213 | } |
| 7214 | |
| 7215 | static void iwl_bg_abort_scan(struct work_struct *work) |
| 7216 | { |
| 7217 | struct iwl_priv *priv = container_of(work, struct iwl_priv, |
| 7218 | abort_scan); |
| 7219 | |
| 7220 | if (!iwl_is_ready(priv)) |
| 7221 | return; |
| 7222 | |
| 7223 | mutex_lock(&priv->mutex); |
| 7224 | |
| 7225 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 7226 | iwl_send_scan_abort(priv); |
| 7227 | |
| 7228 | mutex_unlock(&priv->mutex); |
| 7229 | } |
| 7230 | |
| 7231 | static void iwl_bg_scan_completed(struct work_struct *work) |
| 7232 | { |
| 7233 | struct iwl_priv *priv = |
| 7234 | container_of(work, struct iwl_priv, scan_completed); |
| 7235 | |
| 7236 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n"); |
| 7237 | |
| 7238 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7239 | return; |
| 7240 | |
| 7241 | ieee80211_scan_completed(priv->hw); |
| 7242 | |
| 7243 | /* Since setting the TXPOWER may have been deferred while |
| 7244 | * performing the scan, fire one off */ |
| 7245 | mutex_lock(&priv->mutex); |
| 7246 | iwl_hw_reg_send_txpower(priv); |
| 7247 | mutex_unlock(&priv->mutex); |
| 7248 | } |
| 7249 | |
| 7250 | /***************************************************************************** |
| 7251 | * |
| 7252 | * mac80211 entry point functions |
| 7253 | * |
| 7254 | *****************************************************************************/ |
| 7255 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7256 | static int iwl_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7257 | { |
| 7258 | struct iwl_priv *priv = hw->priv; |
| 7259 | |
| 7260 | IWL_DEBUG_MAC80211("enter\n"); |
| 7261 | |
| 7262 | /* we should be verifying the device is ready to be opened */ |
| 7263 | mutex_lock(&priv->mutex); |
| 7264 | |
| 7265 | priv->is_open = 1; |
| 7266 | |
| 7267 | if (!iwl_is_rfkill(priv)) |
| 7268 | ieee80211_start_queues(priv->hw); |
| 7269 | |
| 7270 | mutex_unlock(&priv->mutex); |
| 7271 | IWL_DEBUG_MAC80211("leave\n"); |
| 7272 | return 0; |
| 7273 | } |
| 7274 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7275 | static void iwl_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7276 | { |
| 7277 | struct iwl_priv *priv = hw->priv; |
| 7278 | |
| 7279 | IWL_DEBUG_MAC80211("enter\n"); |
| 7280 | priv->is_open = 0; |
| 7281 | /*netif_stop_queue(dev); */ |
| 7282 | flush_workqueue(priv->workqueue); |
| 7283 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7284 | } |
| 7285 | |
| 7286 | static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb, |
| 7287 | struct ieee80211_tx_control *ctl) |
| 7288 | { |
| 7289 | struct iwl_priv *priv = hw->priv; |
| 7290 | |
| 7291 | IWL_DEBUG_MAC80211("enter\n"); |
| 7292 | |
| 7293 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { |
| 7294 | IWL_DEBUG_MAC80211("leave - monitor\n"); |
| 7295 | return -1; |
| 7296 | } |
| 7297 | |
| 7298 | IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len, |
| 7299 | ctl->tx_rate); |
| 7300 | |
| 7301 | if (iwl_tx_skb(priv, skb, ctl)) |
| 7302 | dev_kfree_skb_any(skb); |
| 7303 | |
| 7304 | IWL_DEBUG_MAC80211("leave\n"); |
| 7305 | return 0; |
| 7306 | } |
| 7307 | |
| 7308 | static int iwl_mac_add_interface(struct ieee80211_hw *hw, |
| 7309 | struct ieee80211_if_init_conf *conf) |
| 7310 | { |
| 7311 | struct iwl_priv *priv = hw->priv; |
| 7312 | unsigned long flags; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7313 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7314 | |
| 7315 | IWL_DEBUG_MAC80211("enter: id %d, type %d\n", conf->if_id, conf->type); |
| 7316 | if (conf->mac_addr) |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7317 | IWL_DEBUG_MAC80211("enter: MAC %s\n", |
| 7318 | print_mac(mac, conf->mac_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7319 | |
| 7320 | if (priv->interface_id) { |
| 7321 | IWL_DEBUG_MAC80211("leave - interface_id != 0\n"); |
| 7322 | return 0; |
| 7323 | } |
| 7324 | |
| 7325 | spin_lock_irqsave(&priv->lock, flags); |
| 7326 | priv->interface_id = conf->if_id; |
| 7327 | |
| 7328 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7329 | |
| 7330 | mutex_lock(&priv->mutex); |
| 7331 | iwl_set_mode(priv, conf->type); |
| 7332 | |
| 7333 | IWL_DEBUG_MAC80211("leave\n"); |
| 7334 | mutex_unlock(&priv->mutex); |
| 7335 | |
| 7336 | return 0; |
| 7337 | } |
| 7338 | |
| 7339 | /** |
| 7340 | * iwl_mac_config - mac80211 config callback |
| 7341 | * |
| 7342 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 7343 | * be set inappropriately and the driver currently sets the hardware up to |
| 7344 | * use it whenever needed. |
| 7345 | */ |
| 7346 | static int iwl_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf) |
| 7347 | { |
| 7348 | struct iwl_priv *priv = hw->priv; |
| 7349 | const struct iwl_channel_info *ch_info; |
| 7350 | unsigned long flags; |
| 7351 | |
| 7352 | mutex_lock(&priv->mutex); |
| 7353 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel); |
| 7354 | |
| 7355 | if (!iwl_is_ready(priv)) { |
| 7356 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 7357 | mutex_unlock(&priv->mutex); |
| 7358 | return -EIO; |
| 7359 | } |
| 7360 | |
| 7361 | /* TODO: Figure out how to get ieee80211_local->sta_scanning w/ only |
| 7362 | * what is exposed through include/ declrations */ |
| 7363 | if (unlikely(!iwl_param_disable_hw_scan && |
| 7364 | test_bit(STATUS_SCANNING, &priv->status))) { |
| 7365 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 7366 | mutex_unlock(&priv->mutex); |
| 7367 | return 0; |
| 7368 | } |
| 7369 | |
| 7370 | spin_lock_irqsave(&priv->lock, flags); |
| 7371 | |
| 7372 | ch_info = iwl_get_channel_info(priv, conf->phymode, conf->channel); |
| 7373 | if (!is_channel_valid(ch_info)) { |
| 7374 | IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n", |
| 7375 | conf->channel, conf->phymode); |
| 7376 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
| 7377 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7378 | mutex_unlock(&priv->mutex); |
| 7379 | return -EINVAL; |
| 7380 | } |
| 7381 | |
| 7382 | #ifdef CONFIG_IWLWIFI_HT |
| 7383 | /* if we are switching fron ht to 2.4 clear flags |
| 7384 | * from any ht related info since 2.4 does not |
| 7385 | * support ht */ |
| 7386 | if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel) |
| 7387 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 7388 | && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) |
| 7389 | #endif |
| 7390 | ) |
| 7391 | priv->staging_rxon.flags = 0; |
| 7392 | #endif /* CONFIG_IWLWIFI_HT */ |
| 7393 | |
| 7394 | iwl_set_rxon_channel(priv, conf->phymode, conf->channel); |
| 7395 | |
| 7396 | iwl_set_flags_for_phymode(priv, conf->phymode); |
| 7397 | |
| 7398 | /* The list of supported rates and rate mask can be different |
| 7399 | * for each phymode; since the phymode may have changed, reset |
| 7400 | * the rate mask to what mac80211 lists */ |
| 7401 | iwl_set_rate(priv); |
| 7402 | |
| 7403 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7404 | |
| 7405 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 7406 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
| 7407 | iwl_hw_channel_switch(priv, conf->channel); |
| 7408 | mutex_unlock(&priv->mutex); |
| 7409 | return 0; |
| 7410 | } |
| 7411 | #endif |
| 7412 | |
| 7413 | iwl_radio_kill_sw(priv, !conf->radio_enabled); |
| 7414 | |
| 7415 | if (!conf->radio_enabled) { |
| 7416 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); |
| 7417 | mutex_unlock(&priv->mutex); |
| 7418 | return 0; |
| 7419 | } |
| 7420 | |
| 7421 | if (iwl_is_rfkill(priv)) { |
| 7422 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
| 7423 | mutex_unlock(&priv->mutex); |
| 7424 | return -EIO; |
| 7425 | } |
| 7426 | |
| 7427 | iwl_set_rate(priv); |
| 7428 | |
| 7429 | if (memcmp(&priv->active_rxon, |
| 7430 | &priv->staging_rxon, sizeof(priv->staging_rxon))) |
| 7431 | iwl_commit_rxon(priv); |
| 7432 | else |
| 7433 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); |
| 7434 | |
| 7435 | IWL_DEBUG_MAC80211("leave\n"); |
| 7436 | |
| 7437 | mutex_unlock(&priv->mutex); |
| 7438 | |
| 7439 | return 0; |
| 7440 | } |
| 7441 | |
| 7442 | static void iwl_config_ap(struct iwl_priv *priv) |
| 7443 | { |
| 7444 | int rc = 0; |
| 7445 | |
| 7446 | if (priv->status & STATUS_EXIT_PENDING) |
| 7447 | return; |
| 7448 | |
| 7449 | /* The following should be done only at AP bring up */ |
| 7450 | if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) { |
| 7451 | |
| 7452 | /* RXON - unassoc (to set timing command) */ |
| 7453 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 7454 | iwl_commit_rxon(priv); |
| 7455 | |
| 7456 | /* RXON Timing */ |
| 7457 | memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); |
| 7458 | iwl_setup_rxon_timing(priv); |
| 7459 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
| 7460 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 7461 | if (rc) |
| 7462 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 7463 | "Attempting to continue.\n"); |
| 7464 | |
| 7465 | iwl4965_set_rxon_chain(priv); |
| 7466 | |
| 7467 | /* FIXME: what should be the assoc_id for AP? */ |
| 7468 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 7469 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7470 | priv->staging_rxon.flags |= |
| 7471 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7472 | else |
| 7473 | priv->staging_rxon.flags &= |
| 7474 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7475 | |
| 7476 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 7477 | if (priv->assoc_capability & |
| 7478 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 7479 | priv->staging_rxon.flags |= |
| 7480 | RXON_FLG_SHORT_SLOT_MSK; |
| 7481 | else |
| 7482 | priv->staging_rxon.flags &= |
| 7483 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 7484 | |
| 7485 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 7486 | priv->staging_rxon.flags &= |
| 7487 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 7488 | } |
| 7489 | /* restore RXON assoc */ |
| 7490 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 7491 | iwl_commit_rxon(priv); |
| 7492 | #ifdef CONFIG_IWLWIFI_QOS |
| 7493 | iwl_activate_qos(priv, 1); |
| 7494 | #endif |
| 7495 | iwl_rxon_add_station(priv, BROADCAST_ADDR, 0); |
Zhu Yi | e1493de | 2007-09-27 11:27:32 +0800 | [diff] [blame^] | 7496 | } |
| 7497 | iwl_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7498 | |
| 7499 | /* FIXME - we need to add code here to detect a totally new |
| 7500 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 7501 | * clear sta table, add BCAST sta... */ |
| 7502 | } |
| 7503 | |
| 7504 | static int iwl_mac_config_interface(struct ieee80211_hw *hw, int if_id, |
| 7505 | struct ieee80211_if_conf *conf) |
| 7506 | { |
| 7507 | struct iwl_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7508 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7509 | unsigned long flags; |
| 7510 | int rc; |
| 7511 | |
| 7512 | if (conf == NULL) |
| 7513 | return -EIO; |
| 7514 | |
| 7515 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 7516 | (!conf->beacon || !conf->ssid_len)) { |
| 7517 | IWL_DEBUG_MAC80211 |
| 7518 | ("Leaving in AP mode because HostAPD is not ready.\n"); |
| 7519 | return 0; |
| 7520 | } |
| 7521 | |
| 7522 | mutex_lock(&priv->mutex); |
| 7523 | |
| 7524 | IWL_DEBUG_MAC80211("enter: interface id %d\n", if_id); |
| 7525 | if (conf->bssid) |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7526 | IWL_DEBUG_MAC80211("bssid: %s\n", |
| 7527 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7528 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7529 | /* |
| 7530 | * very dubious code was here; the probe filtering flag is never set: |
| 7531 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7532 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 7533 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7534 | */ |
| 7535 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7536 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 7537 | mutex_unlock(&priv->mutex); |
| 7538 | return 0; |
| 7539 | } |
| 7540 | |
| 7541 | if (priv->interface_id != if_id) { |
| 7542 | IWL_DEBUG_MAC80211("leave - interface_id != if_id\n"); |
| 7543 | mutex_unlock(&priv->mutex); |
| 7544 | return 0; |
| 7545 | } |
| 7546 | |
| 7547 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 7548 | if (!conf->bssid) { |
| 7549 | conf->bssid = priv->mac_addr; |
| 7550 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7551 | IWL_DEBUG_MAC80211("bssid was set to: %s\n", |
| 7552 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7553 | } |
| 7554 | if (priv->ibss_beacon) |
| 7555 | dev_kfree_skb(priv->ibss_beacon); |
| 7556 | |
| 7557 | priv->ibss_beacon = conf->beacon; |
| 7558 | } |
| 7559 | |
| 7560 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 7561 | !is_multicast_ether_addr(conf->bssid)) { |
| 7562 | /* If there is currently a HW scan going on in the background |
| 7563 | * then we need to cancel it else the RXON below will fail. */ |
| 7564 | if (iwl_scan_cancel_timeout(priv, 100)) { |
| 7565 | IWL_WARNING("Aborted scan still in progress " |
| 7566 | "after 100ms\n"); |
| 7567 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 7568 | mutex_unlock(&priv->mutex); |
| 7569 | return -EAGAIN; |
| 7570 | } |
| 7571 | memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
| 7572 | |
| 7573 | /* TODO: Audit driver for usage of these members and see |
| 7574 | * if mac80211 deprecates them (priv->bssid looks like it |
| 7575 | * shouldn't be there, but I haven't scanned the IBSS code |
| 7576 | * to verify) - jpk */ |
| 7577 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 7578 | |
| 7579 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
| 7580 | iwl_config_ap(priv); |
| 7581 | else { |
| 7582 | priv->staging_rxon.filter_flags |= |
| 7583 | RXON_FILTER_ASSOC_MSK; |
| 7584 | rc = iwl_commit_rxon(priv); |
| 7585 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc) |
| 7586 | iwl_rxon_add_station( |
| 7587 | priv, priv->active_rxon.bssid_addr, 1); |
| 7588 | } |
| 7589 | |
| 7590 | } else { |
| 7591 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 7592 | iwl_commit_rxon(priv); |
| 7593 | } |
| 7594 | |
| 7595 | spin_lock_irqsave(&priv->lock, flags); |
| 7596 | if (!conf->ssid_len) |
| 7597 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 7598 | else |
| 7599 | memcpy(priv->essid, conf->ssid, conf->ssid_len); |
| 7600 | |
| 7601 | priv->essid_len = conf->ssid_len; |
| 7602 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7603 | |
| 7604 | IWL_DEBUG_MAC80211("leave\n"); |
| 7605 | mutex_unlock(&priv->mutex); |
| 7606 | |
| 7607 | return 0; |
| 7608 | } |
| 7609 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7610 | static void iwl_configure_filter(struct ieee80211_hw *hw, |
| 7611 | unsigned int changed_flags, |
| 7612 | unsigned int *total_flags, |
| 7613 | int mc_count, struct dev_addr_list *mc_list) |
| 7614 | { |
| 7615 | /* |
| 7616 | * XXX: dummy |
| 7617 | * see also iwl_connection_init_rx_config |
| 7618 | */ |
| 7619 | *total_flags = 0; |
| 7620 | } |
| 7621 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7622 | static void iwl_mac_remove_interface(struct ieee80211_hw *hw, |
| 7623 | struct ieee80211_if_init_conf *conf) |
| 7624 | { |
| 7625 | struct iwl_priv *priv = hw->priv; |
| 7626 | |
| 7627 | IWL_DEBUG_MAC80211("enter\n"); |
| 7628 | |
| 7629 | mutex_lock(&priv->mutex); |
| 7630 | if (priv->interface_id == conf->if_id) { |
| 7631 | priv->interface_id = 0; |
| 7632 | memset(priv->bssid, 0, ETH_ALEN); |
| 7633 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 7634 | priv->essid_len = 0; |
| 7635 | } |
| 7636 | mutex_unlock(&priv->mutex); |
| 7637 | |
| 7638 | IWL_DEBUG_MAC80211("leave\n"); |
| 7639 | |
| 7640 | } |
| 7641 | |
| 7642 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 7643 | static int iwl_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len) |
| 7644 | { |
| 7645 | int rc = 0; |
| 7646 | unsigned long flags; |
| 7647 | struct iwl_priv *priv = hw->priv; |
| 7648 | |
| 7649 | IWL_DEBUG_MAC80211("enter\n"); |
| 7650 | |
| 7651 | spin_lock_irqsave(&priv->lock, flags); |
| 7652 | |
| 7653 | if (!iwl_is_ready_rf(priv)) { |
| 7654 | rc = -EIO; |
| 7655 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); |
| 7656 | goto out_unlock; |
| 7657 | } |
| 7658 | |
| 7659 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */ |
| 7660 | rc = -EIO; |
| 7661 | IWL_ERROR("ERROR: APs don't scan\n"); |
| 7662 | goto out_unlock; |
| 7663 | } |
| 7664 | |
| 7665 | /* if we just finished scan ask for delay */ |
| 7666 | if (priv->last_scan_jiffies && |
| 7667 | time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN, |
| 7668 | jiffies)) { |
| 7669 | rc = -EAGAIN; |
| 7670 | goto out_unlock; |
| 7671 | } |
| 7672 | if (len) { |
| 7673 | IWL_DEBUG_SCAN("direct scan for " |
| 7674 | "%s [%d]\n ", |
| 7675 | iwl_escape_essid(ssid, len), (int)len); |
| 7676 | |
| 7677 | priv->one_direct_scan = 1; |
| 7678 | priv->direct_ssid_len = (u8) |
| 7679 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); |
| 7680 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); |
| 7681 | } |
| 7682 | |
| 7683 | rc = iwl_scan_initiate(priv); |
| 7684 | |
| 7685 | IWL_DEBUG_MAC80211("leave\n"); |
| 7686 | |
| 7687 | out_unlock: |
| 7688 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7689 | |
| 7690 | return rc; |
| 7691 | } |
| 7692 | |
Johannes Berg | ea49c35 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 7693 | static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7694 | const u8 *local_addr, const u8 *addr, |
| 7695 | struct ieee80211_key_conf *key) |
| 7696 | { |
| 7697 | struct iwl_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7698 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7699 | int rc = 0; |
| 7700 | u8 sta_id; |
| 7701 | |
| 7702 | IWL_DEBUG_MAC80211("enter\n"); |
| 7703 | |
| 7704 | if (!iwl_param_hwcrypto) { |
| 7705 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
| 7706 | return -EOPNOTSUPP; |
| 7707 | } |
| 7708 | |
| 7709 | if (is_zero_ether_addr(addr)) |
| 7710 | /* only support pairwise keys */ |
| 7711 | return -EOPNOTSUPP; |
| 7712 | |
| 7713 | sta_id = iwl_hw_find_station(priv, addr); |
| 7714 | if (sta_id == IWL_INVALID_STATION) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7715 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 7716 | print_mac(mac, addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7717 | return -EINVAL; |
| 7718 | } |
| 7719 | |
| 7720 | mutex_lock(&priv->mutex); |
| 7721 | |
| 7722 | switch (cmd) { |
| 7723 | case SET_KEY: |
| 7724 | rc = iwl_update_sta_key_info(priv, key, sta_id); |
| 7725 | if (!rc) { |
| 7726 | iwl_set_rxon_hwcrypto(priv, 1); |
| 7727 | iwl_commit_rxon(priv); |
| 7728 | key->hw_key_idx = sta_id; |
| 7729 | IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n"); |
| 7730 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 7731 | } |
| 7732 | break; |
| 7733 | case DISABLE_KEY: |
| 7734 | rc = iwl_clear_sta_key_info(priv, sta_id); |
| 7735 | if (!rc) { |
| 7736 | iwl_set_rxon_hwcrypto(priv, 0); |
| 7737 | iwl_commit_rxon(priv); |
| 7738 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); |
| 7739 | } |
| 7740 | break; |
| 7741 | default: |
| 7742 | rc = -EINVAL; |
| 7743 | } |
| 7744 | |
| 7745 | IWL_DEBUG_MAC80211("leave\n"); |
| 7746 | mutex_unlock(&priv->mutex); |
| 7747 | |
| 7748 | return rc; |
| 7749 | } |
| 7750 | |
| 7751 | static int iwl_mac_conf_tx(struct ieee80211_hw *hw, int queue, |
| 7752 | const struct ieee80211_tx_queue_params *params) |
| 7753 | { |
| 7754 | struct iwl_priv *priv = hw->priv; |
| 7755 | #ifdef CONFIG_IWLWIFI_QOS |
| 7756 | unsigned long flags; |
| 7757 | int q; |
| 7758 | #endif /* CONFIG_IWL_QOS */ |
| 7759 | |
| 7760 | IWL_DEBUG_MAC80211("enter\n"); |
| 7761 | |
| 7762 | if (!iwl_is_ready_rf(priv)) { |
| 7763 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 7764 | return -EIO; |
| 7765 | } |
| 7766 | |
| 7767 | if (queue >= AC_NUM) { |
| 7768 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); |
| 7769 | return 0; |
| 7770 | } |
| 7771 | |
| 7772 | #ifdef CONFIG_IWLWIFI_QOS |
| 7773 | if (!priv->qos_data.qos_enable) { |
| 7774 | priv->qos_data.qos_active = 0; |
| 7775 | IWL_DEBUG_MAC80211("leave - qos not enabled\n"); |
| 7776 | return 0; |
| 7777 | } |
| 7778 | q = AC_NUM - 1 - queue; |
| 7779 | |
| 7780 | spin_lock_irqsave(&priv->lock, flags); |
| 7781 | |
| 7782 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 7783 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 7784 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 7785 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
| 7786 | cpu_to_le16((params->burst_time * 100)); |
| 7787 | |
| 7788 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 7789 | priv->qos_data.qos_active = 1; |
| 7790 | |
| 7791 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7792 | |
| 7793 | mutex_lock(&priv->mutex); |
| 7794 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
| 7795 | iwl_activate_qos(priv, 1); |
| 7796 | else if (priv->assoc_id && iwl_is_associated(priv)) |
| 7797 | iwl_activate_qos(priv, 0); |
| 7798 | |
| 7799 | mutex_unlock(&priv->mutex); |
| 7800 | |
| 7801 | #endif /*CONFIG_IWLWIFI_QOS */ |
| 7802 | |
| 7803 | IWL_DEBUG_MAC80211("leave\n"); |
| 7804 | return 0; |
| 7805 | } |
| 7806 | |
| 7807 | static int iwl_mac_get_tx_stats(struct ieee80211_hw *hw, |
| 7808 | struct ieee80211_tx_queue_stats *stats) |
| 7809 | { |
| 7810 | struct iwl_priv *priv = hw->priv; |
| 7811 | int i, avail; |
| 7812 | struct iwl_tx_queue *txq; |
| 7813 | struct iwl_queue *q; |
| 7814 | unsigned long flags; |
| 7815 | |
| 7816 | IWL_DEBUG_MAC80211("enter\n"); |
| 7817 | |
| 7818 | if (!iwl_is_ready_rf(priv)) { |
| 7819 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 7820 | return -EIO; |
| 7821 | } |
| 7822 | |
| 7823 | spin_lock_irqsave(&priv->lock, flags); |
| 7824 | |
| 7825 | for (i = 0; i < AC_NUM; i++) { |
| 7826 | txq = &priv->txq[i]; |
| 7827 | q = &txq->q; |
| 7828 | avail = iwl_queue_space(q); |
| 7829 | |
| 7830 | stats->data[i].len = q->n_window - avail; |
| 7831 | stats->data[i].limit = q->n_window - q->high_mark; |
| 7832 | stats->data[i].count = q->n_window; |
| 7833 | |
| 7834 | } |
| 7835 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7836 | |
| 7837 | IWL_DEBUG_MAC80211("leave\n"); |
| 7838 | |
| 7839 | return 0; |
| 7840 | } |
| 7841 | |
| 7842 | static int iwl_mac_get_stats(struct ieee80211_hw *hw, |
| 7843 | struct ieee80211_low_level_stats *stats) |
| 7844 | { |
| 7845 | IWL_DEBUG_MAC80211("enter\n"); |
| 7846 | IWL_DEBUG_MAC80211("leave\n"); |
| 7847 | |
| 7848 | return 0; |
| 7849 | } |
| 7850 | |
| 7851 | static u64 iwl_mac_get_tsf(struct ieee80211_hw *hw) |
| 7852 | { |
| 7853 | IWL_DEBUG_MAC80211("enter\n"); |
| 7854 | IWL_DEBUG_MAC80211("leave\n"); |
| 7855 | |
| 7856 | return 0; |
| 7857 | } |
| 7858 | |
| 7859 | static void iwl_mac_reset_tsf(struct ieee80211_hw *hw) |
| 7860 | { |
| 7861 | struct iwl_priv *priv = hw->priv; |
| 7862 | unsigned long flags; |
| 7863 | |
| 7864 | mutex_lock(&priv->mutex); |
| 7865 | IWL_DEBUG_MAC80211("enter\n"); |
| 7866 | |
| 7867 | priv->lq_mngr.lq_ready = 0; |
| 7868 | #ifdef CONFIG_IWLWIFI_HT |
| 7869 | spin_lock_irqsave(&priv->lock, flags); |
| 7870 | memset(&priv->current_assoc_ht, 0, sizeof(struct sta_ht_info)); |
| 7871 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7872 | #ifdef CONFIG_IWLWIFI_HT_AGG |
| 7873 | /* if (priv->lq_mngr.agg_ctrl.granted_ba) |
| 7874 | iwl4965_turn_off_agg(priv, TID_ALL_SPECIFIED);*/ |
| 7875 | |
| 7876 | memset(&(priv->lq_mngr.agg_ctrl), 0, sizeof(struct iwl_agg_control)); |
| 7877 | priv->lq_mngr.agg_ctrl.tid_traffic_load_threshold = 10; |
| 7878 | priv->lq_mngr.agg_ctrl.ba_timeout = 5000; |
| 7879 | priv->lq_mngr.agg_ctrl.auto_agg = 1; |
| 7880 | |
| 7881 | if (priv->lq_mngr.agg_ctrl.auto_agg) |
| 7882 | priv->lq_mngr.agg_ctrl.requested_ba = TID_ALL_ENABLED; |
| 7883 | #endif /*CONFIG_IWLWIFI_HT_AGG */ |
| 7884 | #endif /* CONFIG_IWLWIFI_HT */ |
| 7885 | |
| 7886 | #ifdef CONFIG_IWLWIFI_QOS |
| 7887 | iwl_reset_qos(priv); |
| 7888 | #endif |
| 7889 | |
| 7890 | cancel_delayed_work(&priv->post_associate); |
| 7891 | |
| 7892 | spin_lock_irqsave(&priv->lock, flags); |
| 7893 | priv->assoc_id = 0; |
| 7894 | priv->assoc_capability = 0; |
| 7895 | priv->call_post_assoc_from_beacon = 0; |
| 7896 | priv->assoc_station_added = 0; |
| 7897 | |
| 7898 | /* new association get rid of ibss beacon skb */ |
| 7899 | if (priv->ibss_beacon) |
| 7900 | dev_kfree_skb(priv->ibss_beacon); |
| 7901 | |
| 7902 | priv->ibss_beacon = NULL; |
| 7903 | |
| 7904 | priv->beacon_int = priv->hw->conf.beacon_int; |
| 7905 | priv->timestamp1 = 0; |
| 7906 | priv->timestamp0 = 0; |
| 7907 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 7908 | priv->beacon_int = 0; |
| 7909 | |
| 7910 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7911 | |
| 7912 | /* Per mac80211.h: This is only used in IBSS mode... */ |
| 7913 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
| 7914 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
| 7915 | mutex_unlock(&priv->mutex); |
| 7916 | return; |
| 7917 | } |
| 7918 | |
| 7919 | if (!iwl_is_ready_rf(priv)) { |
| 7920 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 7921 | mutex_unlock(&priv->mutex); |
| 7922 | return; |
| 7923 | } |
| 7924 | |
| 7925 | priv->only_active_channel = 0; |
| 7926 | |
| 7927 | iwl_set_rate(priv); |
| 7928 | |
| 7929 | mutex_unlock(&priv->mutex); |
| 7930 | |
| 7931 | IWL_DEBUG_MAC80211("leave\n"); |
| 7932 | |
| 7933 | } |
| 7934 | |
| 7935 | static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb, |
| 7936 | struct ieee80211_tx_control *control) |
| 7937 | { |
| 7938 | struct iwl_priv *priv = hw->priv; |
| 7939 | unsigned long flags; |
| 7940 | |
| 7941 | mutex_lock(&priv->mutex); |
| 7942 | IWL_DEBUG_MAC80211("enter\n"); |
| 7943 | |
| 7944 | if (!iwl_is_ready_rf(priv)) { |
| 7945 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 7946 | mutex_unlock(&priv->mutex); |
| 7947 | return -EIO; |
| 7948 | } |
| 7949 | |
| 7950 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
| 7951 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); |
| 7952 | mutex_unlock(&priv->mutex); |
| 7953 | return -EIO; |
| 7954 | } |
| 7955 | |
| 7956 | spin_lock_irqsave(&priv->lock, flags); |
| 7957 | |
| 7958 | if (priv->ibss_beacon) |
| 7959 | dev_kfree_skb(priv->ibss_beacon); |
| 7960 | |
| 7961 | priv->ibss_beacon = skb; |
| 7962 | |
| 7963 | priv->assoc_id = 0; |
| 7964 | |
| 7965 | IWL_DEBUG_MAC80211("leave\n"); |
| 7966 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7967 | |
| 7968 | #ifdef CONFIG_IWLWIFI_QOS |
| 7969 | iwl_reset_qos(priv); |
| 7970 | #endif |
| 7971 | |
| 7972 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 7973 | |
| 7974 | mutex_unlock(&priv->mutex); |
| 7975 | |
| 7976 | return 0; |
| 7977 | } |
| 7978 | |
| 7979 | #ifdef CONFIG_IWLWIFI_HT |
| 7980 | union ht_cap_info { |
| 7981 | struct { |
| 7982 | u16 advanced_coding_cap :1; |
| 7983 | u16 supported_chan_width_set :1; |
| 7984 | u16 mimo_power_save_mode :2; |
| 7985 | u16 green_field :1; |
| 7986 | u16 short_GI20 :1; |
| 7987 | u16 short_GI40 :1; |
| 7988 | u16 tx_stbc :1; |
| 7989 | u16 rx_stbc :1; |
| 7990 | u16 beam_forming :1; |
| 7991 | u16 delayed_ba :1; |
| 7992 | u16 maximal_amsdu_size :1; |
| 7993 | u16 cck_mode_at_40MHz :1; |
| 7994 | u16 psmp_support :1; |
| 7995 | u16 stbc_ctrl_frame_support :1; |
| 7996 | u16 sig_txop_protection_support :1; |
| 7997 | }; |
| 7998 | u16 val; |
| 7999 | } __attribute__ ((packed)); |
| 8000 | |
| 8001 | union ht_param_info{ |
| 8002 | struct { |
| 8003 | u8 max_rx_ampdu_factor :2; |
| 8004 | u8 mpdu_density :3; |
| 8005 | u8 reserved :3; |
| 8006 | }; |
| 8007 | u8 val; |
| 8008 | } __attribute__ ((packed)); |
| 8009 | |
| 8010 | union ht_exra_param_info { |
| 8011 | struct { |
| 8012 | u8 ext_chan_offset :2; |
| 8013 | u8 tx_chan_width :1; |
| 8014 | u8 rifs_mode :1; |
| 8015 | u8 controlled_access_only :1; |
| 8016 | u8 service_interval_granularity :3; |
| 8017 | }; |
| 8018 | u8 val; |
| 8019 | } __attribute__ ((packed)); |
| 8020 | |
| 8021 | union ht_operation_mode{ |
| 8022 | struct { |
| 8023 | u16 op_mode :2; |
| 8024 | u16 non_GF :1; |
| 8025 | u16 reserved :13; |
| 8026 | }; |
| 8027 | u16 val; |
| 8028 | } __attribute__ ((packed)); |
| 8029 | |
| 8030 | |
| 8031 | static int sta_ht_info_init(struct ieee80211_ht_capability *ht_cap, |
| 8032 | struct ieee80211_ht_additional_info *ht_extra, |
| 8033 | struct sta_ht_info *ht_info_ap, |
| 8034 | struct sta_ht_info *ht_info) |
| 8035 | { |
| 8036 | union ht_cap_info cap; |
| 8037 | union ht_operation_mode op_mode; |
| 8038 | union ht_param_info param_info; |
| 8039 | union ht_exra_param_info extra_param_info; |
| 8040 | |
| 8041 | IWL_DEBUG_MAC80211("enter: \n"); |
| 8042 | |
| 8043 | if (!ht_info) { |
| 8044 | IWL_DEBUG_MAC80211("leave: ht_info is NULL\n"); |
| 8045 | return -1; |
| 8046 | } |
| 8047 | |
| 8048 | if (ht_cap) { |
| 8049 | cap.val = (u16) le16_to_cpu(ht_cap->capabilities_info); |
| 8050 | param_info.val = ht_cap->mac_ht_params_info; |
| 8051 | ht_info->is_ht = 1; |
| 8052 | if (cap.short_GI20) |
| 8053 | ht_info->sgf |= 0x1; |
| 8054 | if (cap.short_GI40) |
| 8055 | ht_info->sgf |= 0x2; |
| 8056 | ht_info->is_green_field = cap.green_field; |
| 8057 | ht_info->max_amsdu_size = cap.maximal_amsdu_size; |
| 8058 | ht_info->supported_chan_width = cap.supported_chan_width_set; |
| 8059 | ht_info->tx_mimo_ps_mode = cap.mimo_power_save_mode; |
| 8060 | memcpy(ht_info->supp_rates, ht_cap->supported_mcs_set, 16); |
| 8061 | |
| 8062 | ht_info->ampdu_factor = param_info.max_rx_ampdu_factor; |
| 8063 | ht_info->mpdu_density = param_info.mpdu_density; |
| 8064 | |
| 8065 | IWL_DEBUG_MAC80211("SISO mask 0x%X MIMO mask 0x%X \n", |
| 8066 | ht_cap->supported_mcs_set[0], |
| 8067 | ht_cap->supported_mcs_set[1]); |
| 8068 | |
| 8069 | if (ht_info_ap) { |
| 8070 | ht_info->control_channel = ht_info_ap->control_channel; |
| 8071 | ht_info->extension_chan_offset = |
| 8072 | ht_info_ap->extension_chan_offset; |
| 8073 | ht_info->tx_chan_width = ht_info_ap->tx_chan_width; |
| 8074 | ht_info->operating_mode = ht_info_ap->operating_mode; |
| 8075 | } |
| 8076 | |
| 8077 | if (ht_extra) { |
| 8078 | extra_param_info.val = ht_extra->ht_param; |
| 8079 | ht_info->control_channel = ht_extra->control_chan; |
| 8080 | ht_info->extension_chan_offset = |
| 8081 | extra_param_info.ext_chan_offset; |
| 8082 | ht_info->tx_chan_width = extra_param_info.tx_chan_width; |
| 8083 | op_mode.val = (u16) |
| 8084 | le16_to_cpu(ht_extra->operation_mode); |
| 8085 | ht_info->operating_mode = op_mode.op_mode; |
| 8086 | IWL_DEBUG_MAC80211("control channel %d\n", |
| 8087 | ht_extra->control_chan); |
| 8088 | } |
| 8089 | } else |
| 8090 | ht_info->is_ht = 0; |
| 8091 | |
| 8092 | IWL_DEBUG_MAC80211("leave\n"); |
| 8093 | return 0; |
| 8094 | } |
| 8095 | |
| 8096 | static int iwl_mac_conf_ht(struct ieee80211_hw *hw, |
| 8097 | struct ieee80211_ht_capability *ht_cap, |
| 8098 | struct ieee80211_ht_additional_info *ht_extra) |
| 8099 | { |
| 8100 | struct iwl_priv *priv = hw->priv; |
| 8101 | int rs; |
| 8102 | |
| 8103 | IWL_DEBUG_MAC80211("enter: \n"); |
| 8104 | |
| 8105 | rs = sta_ht_info_init(ht_cap, ht_extra, NULL, &priv->current_assoc_ht); |
| 8106 | iwl4965_set_rxon_chain(priv); |
| 8107 | |
| 8108 | if (priv && priv->assoc_id && |
| 8109 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { |
| 8110 | unsigned long flags; |
| 8111 | |
| 8112 | spin_lock_irqsave(&priv->lock, flags); |
| 8113 | if (priv->beacon_int) |
| 8114 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 8115 | else |
| 8116 | priv->call_post_assoc_from_beacon = 1; |
| 8117 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8118 | } |
| 8119 | |
| 8120 | IWL_DEBUG_MAC80211("leave: control channel %d\n", |
| 8121 | ht_extra->control_chan); |
| 8122 | return rs; |
| 8123 | |
| 8124 | } |
| 8125 | |
| 8126 | static void iwl_set_ht_capab(struct ieee80211_hw *hw, |
| 8127 | struct ieee80211_ht_capability *ht_cap, |
| 8128 | u8 use_wide_chan) |
| 8129 | { |
| 8130 | union ht_cap_info cap; |
| 8131 | union ht_param_info param_info; |
| 8132 | |
| 8133 | memset(&cap, 0, sizeof(union ht_cap_info)); |
| 8134 | memset(¶m_info, 0, sizeof(union ht_param_info)); |
| 8135 | |
| 8136 | cap.maximal_amsdu_size = HT_IE_MAX_AMSDU_SIZE_4K; |
| 8137 | cap.green_field = 1; |
| 8138 | cap.short_GI20 = 1; |
| 8139 | cap.short_GI40 = 1; |
| 8140 | cap.supported_chan_width_set = use_wide_chan; |
| 8141 | cap.mimo_power_save_mode = 0x3; |
| 8142 | |
| 8143 | param_info.max_rx_ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF; |
| 8144 | param_info.mpdu_density = CFG_HT_MPDU_DENSITY_DEF; |
| 8145 | ht_cap->capabilities_info = (__le16) cpu_to_le16(cap.val); |
| 8146 | ht_cap->mac_ht_params_info = (u8) param_info.val; |
| 8147 | |
| 8148 | ht_cap->supported_mcs_set[0] = 0xff; |
| 8149 | ht_cap->supported_mcs_set[1] = 0xff; |
| 8150 | ht_cap->supported_mcs_set[4] = |
| 8151 | (cap.supported_chan_width_set) ? 0x1: 0x0; |
| 8152 | } |
| 8153 | |
| 8154 | static void iwl_mac_get_ht_capab(struct ieee80211_hw *hw, |
| 8155 | struct ieee80211_ht_capability *ht_cap) |
| 8156 | { |
| 8157 | u8 use_wide_channel = 1; |
| 8158 | struct iwl_priv *priv = hw->priv; |
| 8159 | |
| 8160 | IWL_DEBUG_MAC80211("enter: \n"); |
| 8161 | if (priv->channel_width != IWL_CHANNEL_WIDTH_40MHZ) |
| 8162 | use_wide_channel = 0; |
| 8163 | |
| 8164 | /* no fat tx allowed on 2.4GHZ */ |
| 8165 | if (priv->phymode != MODE_IEEE80211A) |
| 8166 | use_wide_channel = 0; |
| 8167 | |
| 8168 | iwl_set_ht_capab(hw, ht_cap, use_wide_channel); |
| 8169 | IWL_DEBUG_MAC80211("leave: \n"); |
| 8170 | } |
| 8171 | #endif /*CONFIG_IWLWIFI_HT*/ |
| 8172 | |
| 8173 | /***************************************************************************** |
| 8174 | * |
| 8175 | * sysfs attributes |
| 8176 | * |
| 8177 | *****************************************************************************/ |
| 8178 | |
| 8179 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 8180 | |
| 8181 | /* |
| 8182 | * The following adds a new attribute to the sysfs representation |
| 8183 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 8184 | * used for controlling the debug level. |
| 8185 | * |
| 8186 | * See the level definitions in iwl for details. |
| 8187 | */ |
| 8188 | |
| 8189 | static ssize_t show_debug_level(struct device_driver *d, char *buf) |
| 8190 | { |
| 8191 | return sprintf(buf, "0x%08X\n", iwl_debug_level); |
| 8192 | } |
| 8193 | static ssize_t store_debug_level(struct device_driver *d, |
| 8194 | const char *buf, size_t count) |
| 8195 | { |
| 8196 | char *p = (char *)buf; |
| 8197 | u32 val; |
| 8198 | |
| 8199 | val = simple_strtoul(p, &p, 0); |
| 8200 | if (p == buf) |
| 8201 | printk(KERN_INFO DRV_NAME |
| 8202 | ": %s is not in hex or decimal form.\n", buf); |
| 8203 | else |
| 8204 | iwl_debug_level = val; |
| 8205 | |
| 8206 | return strnlen(buf, count); |
| 8207 | } |
| 8208 | |
| 8209 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 8210 | show_debug_level, store_debug_level); |
| 8211 | |
| 8212 | #endif /* CONFIG_IWLWIFI_DEBUG */ |
| 8213 | |
| 8214 | static ssize_t show_rf_kill(struct device *d, |
| 8215 | struct device_attribute *attr, char *buf) |
| 8216 | { |
| 8217 | /* |
| 8218 | * 0 - RF kill not enabled |
| 8219 | * 1 - SW based RF kill active (sysfs) |
| 8220 | * 2 - HW based RF kill active |
| 8221 | * 3 - Both HW and SW based RF kill active |
| 8222 | */ |
| 8223 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
| 8224 | int val = (test_bit(STATUS_RF_KILL_SW, &priv->status) ? 0x1 : 0x0) | |
| 8225 | (test_bit(STATUS_RF_KILL_HW, &priv->status) ? 0x2 : 0x0); |
| 8226 | |
| 8227 | return sprintf(buf, "%i\n", val); |
| 8228 | } |
| 8229 | |
| 8230 | static ssize_t store_rf_kill(struct device *d, |
| 8231 | struct device_attribute *attr, |
| 8232 | const char *buf, size_t count) |
| 8233 | { |
| 8234 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
| 8235 | |
| 8236 | mutex_lock(&priv->mutex); |
| 8237 | iwl_radio_kill_sw(priv, buf[0] == '1'); |
| 8238 | mutex_unlock(&priv->mutex); |
| 8239 | |
| 8240 | return count; |
| 8241 | } |
| 8242 | |
| 8243 | static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill); |
| 8244 | |
| 8245 | static ssize_t show_temperature(struct device *d, |
| 8246 | struct device_attribute *attr, char *buf) |
| 8247 | { |
| 8248 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
| 8249 | |
| 8250 | if (!iwl_is_alive(priv)) |
| 8251 | return -EAGAIN; |
| 8252 | |
| 8253 | return sprintf(buf, "%d\n", iwl_hw_get_temperature(priv)); |
| 8254 | } |
| 8255 | |
| 8256 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 8257 | |
| 8258 | static ssize_t show_rs_window(struct device *d, |
| 8259 | struct device_attribute *attr, |
| 8260 | char *buf) |
| 8261 | { |
| 8262 | struct iwl_priv *priv = d->driver_data; |
| 8263 | return iwl_fill_rs_info(priv->hw, buf, IWL_AP_ID); |
| 8264 | } |
| 8265 | static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL); |
| 8266 | |
| 8267 | static ssize_t show_tx_power(struct device *d, |
| 8268 | struct device_attribute *attr, char *buf) |
| 8269 | { |
| 8270 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
| 8271 | return sprintf(buf, "%d\n", priv->user_txpower_limit); |
| 8272 | } |
| 8273 | |
| 8274 | static ssize_t store_tx_power(struct device *d, |
| 8275 | struct device_attribute *attr, |
| 8276 | const char *buf, size_t count) |
| 8277 | { |
| 8278 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
| 8279 | char *p = (char *)buf; |
| 8280 | u32 val; |
| 8281 | |
| 8282 | val = simple_strtoul(p, &p, 10); |
| 8283 | if (p == buf) |
| 8284 | printk(KERN_INFO DRV_NAME |
| 8285 | ": %s is not in decimal form.\n", buf); |
| 8286 | else |
| 8287 | iwl_hw_reg_set_txpower(priv, val); |
| 8288 | |
| 8289 | return count; |
| 8290 | } |
| 8291 | |
| 8292 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 8293 | |
| 8294 | static ssize_t show_flags(struct device *d, |
| 8295 | struct device_attribute *attr, char *buf) |
| 8296 | { |
| 8297 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
| 8298 | |
| 8299 | return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); |
| 8300 | } |
| 8301 | |
| 8302 | static ssize_t store_flags(struct device *d, |
| 8303 | struct device_attribute *attr, |
| 8304 | const char *buf, size_t count) |
| 8305 | { |
| 8306 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
| 8307 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 8308 | |
| 8309 | mutex_lock(&priv->mutex); |
| 8310 | if (le32_to_cpu(priv->staging_rxon.flags) != flags) { |
| 8311 | /* Cancel any currently running scans... */ |
| 8312 | if (iwl_scan_cancel_timeout(priv, 100)) |
| 8313 | IWL_WARNING("Could not cancel scan.\n"); |
| 8314 | else { |
| 8315 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", |
| 8316 | flags); |
| 8317 | priv->staging_rxon.flags = cpu_to_le32(flags); |
| 8318 | iwl_commit_rxon(priv); |
| 8319 | } |
| 8320 | } |
| 8321 | mutex_unlock(&priv->mutex); |
| 8322 | |
| 8323 | return count; |
| 8324 | } |
| 8325 | |
| 8326 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 8327 | |
| 8328 | static ssize_t show_filter_flags(struct device *d, |
| 8329 | struct device_attribute *attr, char *buf) |
| 8330 | { |
| 8331 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
| 8332 | |
| 8333 | return sprintf(buf, "0x%04X\n", |
| 8334 | le32_to_cpu(priv->active_rxon.filter_flags)); |
| 8335 | } |
| 8336 | |
| 8337 | static ssize_t store_filter_flags(struct device *d, |
| 8338 | struct device_attribute *attr, |
| 8339 | const char *buf, size_t count) |
| 8340 | { |
| 8341 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
| 8342 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 8343 | |
| 8344 | mutex_lock(&priv->mutex); |
| 8345 | if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { |
| 8346 | /* Cancel any currently running scans... */ |
| 8347 | if (iwl_scan_cancel_timeout(priv, 100)) |
| 8348 | IWL_WARNING("Could not cancel scan.\n"); |
| 8349 | else { |
| 8350 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " |
| 8351 | "0x%04X\n", filter_flags); |
| 8352 | priv->staging_rxon.filter_flags = |
| 8353 | cpu_to_le32(filter_flags); |
| 8354 | iwl_commit_rxon(priv); |
| 8355 | } |
| 8356 | } |
| 8357 | mutex_unlock(&priv->mutex); |
| 8358 | |
| 8359 | return count; |
| 8360 | } |
| 8361 | |
| 8362 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 8363 | store_filter_flags); |
| 8364 | |
| 8365 | static ssize_t show_tune(struct device *d, |
| 8366 | struct device_attribute *attr, char *buf) |
| 8367 | { |
| 8368 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
| 8369 | |
| 8370 | return sprintf(buf, "0x%04X\n", |
| 8371 | (priv->phymode << 8) | |
| 8372 | le16_to_cpu(priv->active_rxon.channel)); |
| 8373 | } |
| 8374 | |
| 8375 | static void iwl_set_flags_for_phymode(struct iwl_priv *priv, u8 phymode); |
| 8376 | |
| 8377 | static ssize_t store_tune(struct device *d, |
| 8378 | struct device_attribute *attr, |
| 8379 | const char *buf, size_t count) |
| 8380 | { |
| 8381 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
| 8382 | char *p = (char *)buf; |
| 8383 | u16 tune = simple_strtoul(p, &p, 0); |
| 8384 | u8 phymode = (tune >> 8) & 0xff; |
| 8385 | u16 channel = tune & 0xff; |
| 8386 | |
| 8387 | IWL_DEBUG_INFO("Tune request to:%d channel:%d\n", phymode, channel); |
| 8388 | |
| 8389 | mutex_lock(&priv->mutex); |
| 8390 | if ((le16_to_cpu(priv->staging_rxon.channel) != channel) || |
| 8391 | (priv->phymode != phymode)) { |
| 8392 | const struct iwl_channel_info *ch_info; |
| 8393 | |
| 8394 | ch_info = iwl_get_channel_info(priv, phymode, channel); |
| 8395 | if (!ch_info) { |
| 8396 | IWL_WARNING("Requested invalid phymode/channel " |
| 8397 | "combination: %d %d\n", phymode, channel); |
| 8398 | mutex_unlock(&priv->mutex); |
| 8399 | return -EINVAL; |
| 8400 | } |
| 8401 | |
| 8402 | /* Cancel any currently running scans... */ |
| 8403 | if (iwl_scan_cancel_timeout(priv, 100)) |
| 8404 | IWL_WARNING("Could not cancel scan.\n"); |
| 8405 | else { |
| 8406 | IWL_DEBUG_INFO("Committing phymode and " |
| 8407 | "rxon.channel = %d %d\n", |
| 8408 | phymode, channel); |
| 8409 | |
| 8410 | iwl_set_rxon_channel(priv, phymode, channel); |
| 8411 | iwl_set_flags_for_phymode(priv, phymode); |
| 8412 | |
| 8413 | iwl_set_rate(priv); |
| 8414 | iwl_commit_rxon(priv); |
| 8415 | } |
| 8416 | } |
| 8417 | mutex_unlock(&priv->mutex); |
| 8418 | |
| 8419 | return count; |
| 8420 | } |
| 8421 | |
| 8422 | static DEVICE_ATTR(tune, S_IWUSR | S_IRUGO, show_tune, store_tune); |
| 8423 | |
| 8424 | #ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT |
| 8425 | |
| 8426 | static ssize_t show_measurement(struct device *d, |
| 8427 | struct device_attribute *attr, char *buf) |
| 8428 | { |
| 8429 | struct iwl_priv *priv = dev_get_drvdata(d); |
| 8430 | struct iwl_spectrum_notification measure_report; |
| 8431 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
| 8432 | u8 *data = (u8 *) & measure_report; |
| 8433 | unsigned long flags; |
| 8434 | |
| 8435 | spin_lock_irqsave(&priv->lock, flags); |
| 8436 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 8437 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8438 | return 0; |
| 8439 | } |
| 8440 | memcpy(&measure_report, &priv->measure_report, size); |
| 8441 | priv->measurement_status = 0; |
| 8442 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8443 | |
| 8444 | while (size && (PAGE_SIZE - len)) { |
| 8445 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 8446 | PAGE_SIZE - len, 1); |
| 8447 | len = strlen(buf); |
| 8448 | if (PAGE_SIZE - len) |
| 8449 | buf[len++] = '\n'; |
| 8450 | |
| 8451 | ofs += 16; |
| 8452 | size -= min(size, 16U); |
| 8453 | } |
| 8454 | |
| 8455 | return len; |
| 8456 | } |
| 8457 | |
| 8458 | static ssize_t store_measurement(struct device *d, |
| 8459 | struct device_attribute *attr, |
| 8460 | const char *buf, size_t count) |
| 8461 | { |
| 8462 | struct iwl_priv *priv = dev_get_drvdata(d); |
| 8463 | struct ieee80211_measurement_params params = { |
| 8464 | .channel = le16_to_cpu(priv->active_rxon.channel), |
| 8465 | .start_time = cpu_to_le64(priv->last_tsf), |
| 8466 | .duration = cpu_to_le16(1), |
| 8467 | }; |
| 8468 | u8 type = IWL_MEASURE_BASIC; |
| 8469 | u8 buffer[32]; |
| 8470 | u8 channel; |
| 8471 | |
| 8472 | if (count) { |
| 8473 | char *p = buffer; |
| 8474 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 8475 | channel = simple_strtoul(p, NULL, 0); |
| 8476 | if (channel) |
| 8477 | params.channel = channel; |
| 8478 | |
| 8479 | p = buffer; |
| 8480 | while (*p && *p != ' ') |
| 8481 | p++; |
| 8482 | if (*p) |
| 8483 | type = simple_strtoul(p + 1, NULL, 0); |
| 8484 | } |
| 8485 | |
| 8486 | IWL_DEBUG_INFO("Invoking measurement of type %d on " |
| 8487 | "channel %d (for '%s')\n", type, params.channel, buf); |
| 8488 | iwl_get_measurement(priv, ¶ms, type); |
| 8489 | |
| 8490 | return count; |
| 8491 | } |
| 8492 | |
| 8493 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 8494 | show_measurement, store_measurement); |
| 8495 | #endif /* CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT */ |
| 8496 | |
| 8497 | static ssize_t store_retry_rate(struct device *d, |
| 8498 | struct device_attribute *attr, |
| 8499 | const char *buf, size_t count) |
| 8500 | { |
| 8501 | struct iwl_priv *priv = dev_get_drvdata(d); |
| 8502 | |
| 8503 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 8504 | if (priv->retry_rate <= 0) |
| 8505 | priv->retry_rate = 1; |
| 8506 | |
| 8507 | return count; |
| 8508 | } |
| 8509 | |
| 8510 | static ssize_t show_retry_rate(struct device *d, |
| 8511 | struct device_attribute *attr, char *buf) |
| 8512 | { |
| 8513 | struct iwl_priv *priv = dev_get_drvdata(d); |
| 8514 | return sprintf(buf, "%d", priv->retry_rate); |
| 8515 | } |
| 8516 | |
| 8517 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 8518 | store_retry_rate); |
| 8519 | |
| 8520 | static ssize_t store_power_level(struct device *d, |
| 8521 | struct device_attribute *attr, |
| 8522 | const char *buf, size_t count) |
| 8523 | { |
| 8524 | struct iwl_priv *priv = dev_get_drvdata(d); |
| 8525 | int rc; |
| 8526 | int mode; |
| 8527 | |
| 8528 | mode = simple_strtoul(buf, NULL, 0); |
| 8529 | mutex_lock(&priv->mutex); |
| 8530 | |
| 8531 | if (!iwl_is_ready(priv)) { |
| 8532 | rc = -EAGAIN; |
| 8533 | goto out; |
| 8534 | } |
| 8535 | |
| 8536 | if ((mode < 1) || (mode > IWL_POWER_LIMIT) || (mode == IWL_POWER_AC)) |
| 8537 | mode = IWL_POWER_AC; |
| 8538 | else |
| 8539 | mode |= IWL_POWER_ENABLED; |
| 8540 | |
| 8541 | if (mode != priv->power_mode) { |
| 8542 | rc = iwl_send_power_mode(priv, IWL_POWER_LEVEL(mode)); |
| 8543 | if (rc) { |
| 8544 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); |
| 8545 | goto out; |
| 8546 | } |
| 8547 | priv->power_mode = mode; |
| 8548 | } |
| 8549 | |
| 8550 | rc = count; |
| 8551 | |
| 8552 | out: |
| 8553 | mutex_unlock(&priv->mutex); |
| 8554 | return rc; |
| 8555 | } |
| 8556 | |
| 8557 | #define MAX_WX_STRING 80 |
| 8558 | |
| 8559 | /* Values are in microsecond */ |
| 8560 | static const s32 timeout_duration[] = { |
| 8561 | 350000, |
| 8562 | 250000, |
| 8563 | 75000, |
| 8564 | 37000, |
| 8565 | 25000, |
| 8566 | }; |
| 8567 | static const s32 period_duration[] = { |
| 8568 | 400000, |
| 8569 | 700000, |
| 8570 | 1000000, |
| 8571 | 1000000, |
| 8572 | 1000000 |
| 8573 | }; |
| 8574 | |
| 8575 | static ssize_t show_power_level(struct device *d, |
| 8576 | struct device_attribute *attr, char *buf) |
| 8577 | { |
| 8578 | struct iwl_priv *priv = dev_get_drvdata(d); |
| 8579 | int level = IWL_POWER_LEVEL(priv->power_mode); |
| 8580 | char *p = buf; |
| 8581 | |
| 8582 | p += sprintf(p, "%d ", level); |
| 8583 | switch (level) { |
| 8584 | case IWL_POWER_MODE_CAM: |
| 8585 | case IWL_POWER_AC: |
| 8586 | p += sprintf(p, "(AC)"); |
| 8587 | break; |
| 8588 | case IWL_POWER_BATTERY: |
| 8589 | p += sprintf(p, "(BATTERY)"); |
| 8590 | break; |
| 8591 | default: |
| 8592 | p += sprintf(p, |
| 8593 | "(Timeout %dms, Period %dms)", |
| 8594 | timeout_duration[level - 1] / 1000, |
| 8595 | period_duration[level - 1] / 1000); |
| 8596 | } |
| 8597 | |
| 8598 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
| 8599 | p += sprintf(p, " OFF\n"); |
| 8600 | else |
| 8601 | p += sprintf(p, " \n"); |
| 8602 | |
| 8603 | return (p - buf + 1); |
| 8604 | |
| 8605 | } |
| 8606 | |
| 8607 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, |
| 8608 | store_power_level); |
| 8609 | |
| 8610 | static ssize_t show_channels(struct device *d, |
| 8611 | struct device_attribute *attr, char *buf) |
| 8612 | { |
| 8613 | struct iwl_priv *priv = dev_get_drvdata(d); |
| 8614 | int len = 0, i; |
| 8615 | struct ieee80211_channel *channels = NULL; |
| 8616 | const struct ieee80211_hw_mode *hw_mode = NULL; |
| 8617 | int count = 0; |
| 8618 | |
| 8619 | if (!iwl_is_ready(priv)) |
| 8620 | return -EAGAIN; |
| 8621 | |
| 8622 | hw_mode = iwl_get_hw_mode(priv, MODE_IEEE80211G); |
| 8623 | if (!hw_mode) |
| 8624 | hw_mode = iwl_get_hw_mode(priv, MODE_IEEE80211B); |
| 8625 | if (hw_mode) { |
| 8626 | channels = hw_mode->channels; |
| 8627 | count = hw_mode->num_channels; |
| 8628 | } |
| 8629 | |
| 8630 | len += |
| 8631 | sprintf(&buf[len], |
| 8632 | "Displaying %d channels in 2.4GHz band " |
| 8633 | "(802.11bg):\n", count); |
| 8634 | |
| 8635 | for (i = 0; i < count; i++) |
| 8636 | len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n", |
| 8637 | channels[i].chan, |
| 8638 | channels[i].power_level, |
| 8639 | channels[i]. |
| 8640 | flag & IEEE80211_CHAN_W_RADAR_DETECT ? |
| 8641 | " (IEEE 802.11h required)" : "", |
| 8642 | (!(channels[i].flag & IEEE80211_CHAN_W_IBSS) |
| 8643 | || (channels[i]. |
| 8644 | flag & |
| 8645 | IEEE80211_CHAN_W_RADAR_DETECT)) ? "" : |
| 8646 | ", IBSS", |
| 8647 | channels[i]. |
| 8648 | flag & IEEE80211_CHAN_W_ACTIVE_SCAN ? |
| 8649 | "active/passive" : "passive only"); |
| 8650 | |
| 8651 | hw_mode = iwl_get_hw_mode(priv, MODE_IEEE80211A); |
| 8652 | if (hw_mode) { |
| 8653 | channels = hw_mode->channels; |
| 8654 | count = hw_mode->num_channels; |
| 8655 | } else { |
| 8656 | channels = NULL; |
| 8657 | count = 0; |
| 8658 | } |
| 8659 | |
| 8660 | len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band " |
| 8661 | "(802.11a):\n", count); |
| 8662 | |
| 8663 | for (i = 0; i < count; i++) |
| 8664 | len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n", |
| 8665 | channels[i].chan, |
| 8666 | channels[i].power_level, |
| 8667 | channels[i]. |
| 8668 | flag & IEEE80211_CHAN_W_RADAR_DETECT ? |
| 8669 | " (IEEE 802.11h required)" : "", |
| 8670 | (!(channels[i].flag & IEEE80211_CHAN_W_IBSS) |
| 8671 | || (channels[i]. |
| 8672 | flag & |
| 8673 | IEEE80211_CHAN_W_RADAR_DETECT)) ? "" : |
| 8674 | ", IBSS", |
| 8675 | channels[i]. |
| 8676 | flag & IEEE80211_CHAN_W_ACTIVE_SCAN ? |
| 8677 | "active/passive" : "passive only"); |
| 8678 | |
| 8679 | return len; |
| 8680 | } |
| 8681 | |
| 8682 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 8683 | |
| 8684 | static ssize_t show_statistics(struct device *d, |
| 8685 | struct device_attribute *attr, char *buf) |
| 8686 | { |
| 8687 | struct iwl_priv *priv = dev_get_drvdata(d); |
| 8688 | u32 size = sizeof(struct iwl_notif_statistics); |
| 8689 | u32 len = 0, ofs = 0; |
| 8690 | u8 *data = (u8 *) & priv->statistics; |
| 8691 | int rc = 0; |
| 8692 | |
| 8693 | if (!iwl_is_alive(priv)) |
| 8694 | return -EAGAIN; |
| 8695 | |
| 8696 | mutex_lock(&priv->mutex); |
| 8697 | rc = iwl_send_statistics_request(priv); |
| 8698 | mutex_unlock(&priv->mutex); |
| 8699 | |
| 8700 | if (rc) { |
| 8701 | len = sprintf(buf, |
| 8702 | "Error sending statistics request: 0x%08X\n", rc); |
| 8703 | return len; |
| 8704 | } |
| 8705 | |
| 8706 | while (size && (PAGE_SIZE - len)) { |
| 8707 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 8708 | PAGE_SIZE - len, 1); |
| 8709 | len = strlen(buf); |
| 8710 | if (PAGE_SIZE - len) |
| 8711 | buf[len++] = '\n'; |
| 8712 | |
| 8713 | ofs += 16; |
| 8714 | size -= min(size, 16U); |
| 8715 | } |
| 8716 | |
| 8717 | return len; |
| 8718 | } |
| 8719 | |
| 8720 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 8721 | |
| 8722 | static ssize_t show_antenna(struct device *d, |
| 8723 | struct device_attribute *attr, char *buf) |
| 8724 | { |
| 8725 | struct iwl_priv *priv = dev_get_drvdata(d); |
| 8726 | |
| 8727 | if (!iwl_is_alive(priv)) |
| 8728 | return -EAGAIN; |
| 8729 | |
| 8730 | return sprintf(buf, "%d\n", priv->antenna); |
| 8731 | } |
| 8732 | |
| 8733 | static ssize_t store_antenna(struct device *d, |
| 8734 | struct device_attribute *attr, |
| 8735 | const char *buf, size_t count) |
| 8736 | { |
| 8737 | int ant; |
| 8738 | struct iwl_priv *priv = dev_get_drvdata(d); |
| 8739 | |
| 8740 | if (count == 0) |
| 8741 | return 0; |
| 8742 | |
| 8743 | if (sscanf(buf, "%1i", &ant) != 1) { |
| 8744 | IWL_DEBUG_INFO("not in hex or decimal form.\n"); |
| 8745 | return count; |
| 8746 | } |
| 8747 | |
| 8748 | if ((ant >= 0) && (ant <= 2)) { |
| 8749 | IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant); |
| 8750 | priv->antenna = (enum iwl_antenna)ant; |
| 8751 | } else |
| 8752 | IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant); |
| 8753 | |
| 8754 | |
| 8755 | return count; |
| 8756 | } |
| 8757 | |
| 8758 | static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna); |
| 8759 | |
| 8760 | static ssize_t show_status(struct device *d, |
| 8761 | struct device_attribute *attr, char *buf) |
| 8762 | { |
| 8763 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
| 8764 | if (!iwl_is_alive(priv)) |
| 8765 | return -EAGAIN; |
| 8766 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 8767 | } |
| 8768 | |
| 8769 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 8770 | |
| 8771 | static ssize_t dump_error_log(struct device *d, |
| 8772 | struct device_attribute *attr, |
| 8773 | const char *buf, size_t count) |
| 8774 | { |
| 8775 | char *p = (char *)buf; |
| 8776 | |
| 8777 | if (p[0] == '1') |
| 8778 | iwl_dump_nic_error_log((struct iwl_priv *)d->driver_data); |
| 8779 | |
| 8780 | return strnlen(buf, count); |
| 8781 | } |
| 8782 | |
| 8783 | static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log); |
| 8784 | |
| 8785 | static ssize_t dump_event_log(struct device *d, |
| 8786 | struct device_attribute *attr, |
| 8787 | const char *buf, size_t count) |
| 8788 | { |
| 8789 | char *p = (char *)buf; |
| 8790 | |
| 8791 | if (p[0] == '1') |
| 8792 | iwl_dump_nic_event_log((struct iwl_priv *)d->driver_data); |
| 8793 | |
| 8794 | return strnlen(buf, count); |
| 8795 | } |
| 8796 | |
| 8797 | static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); |
| 8798 | |
| 8799 | /***************************************************************************** |
| 8800 | * |
| 8801 | * driver setup and teardown |
| 8802 | * |
| 8803 | *****************************************************************************/ |
| 8804 | |
| 8805 | static void iwl_setup_deferred_work(struct iwl_priv *priv) |
| 8806 | { |
| 8807 | priv->workqueue = create_workqueue(DRV_NAME); |
| 8808 | |
| 8809 | init_waitqueue_head(&priv->wait_command_queue); |
| 8810 | |
| 8811 | INIT_WORK(&priv->up, iwl_bg_up); |
| 8812 | INIT_WORK(&priv->restart, iwl_bg_restart); |
| 8813 | INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish); |
| 8814 | INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed); |
| 8815 | INIT_WORK(&priv->request_scan, iwl_bg_request_scan); |
| 8816 | INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan); |
| 8817 | INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill); |
| 8818 | INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update); |
| 8819 | INIT_DELAYED_WORK(&priv->post_associate, iwl_bg_post_associate); |
| 8820 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start); |
| 8821 | INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start); |
| 8822 | INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check); |
| 8823 | |
| 8824 | iwl_hw_setup_deferred_work(priv); |
| 8825 | |
| 8826 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
| 8827 | iwl_irq_tasklet, (unsigned long)priv); |
| 8828 | } |
| 8829 | |
| 8830 | static void iwl_cancel_deferred_work(struct iwl_priv *priv) |
| 8831 | { |
| 8832 | iwl_hw_cancel_deferred_work(priv); |
| 8833 | |
| 8834 | cancel_delayed_work(&priv->scan_check); |
| 8835 | cancel_delayed_work(&priv->alive_start); |
| 8836 | cancel_delayed_work(&priv->post_associate); |
| 8837 | cancel_work_sync(&priv->beacon_update); |
| 8838 | } |
| 8839 | |
| 8840 | static struct attribute *iwl_sysfs_entries[] = { |
| 8841 | &dev_attr_antenna.attr, |
| 8842 | &dev_attr_channels.attr, |
| 8843 | &dev_attr_dump_errors.attr, |
| 8844 | &dev_attr_dump_events.attr, |
| 8845 | &dev_attr_flags.attr, |
| 8846 | &dev_attr_filter_flags.attr, |
| 8847 | #ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT |
| 8848 | &dev_attr_measurement.attr, |
| 8849 | #endif |
| 8850 | &dev_attr_power_level.attr, |
| 8851 | &dev_attr_retry_rate.attr, |
| 8852 | &dev_attr_rf_kill.attr, |
| 8853 | &dev_attr_rs_window.attr, |
| 8854 | &dev_attr_statistics.attr, |
| 8855 | &dev_attr_status.attr, |
| 8856 | &dev_attr_temperature.attr, |
| 8857 | &dev_attr_tune.attr, |
| 8858 | &dev_attr_tx_power.attr, |
| 8859 | |
| 8860 | NULL |
| 8861 | }; |
| 8862 | |
| 8863 | static struct attribute_group iwl_attribute_group = { |
| 8864 | .name = NULL, /* put in device directory */ |
| 8865 | .attrs = iwl_sysfs_entries, |
| 8866 | }; |
| 8867 | |
| 8868 | static struct ieee80211_ops iwl_hw_ops = { |
| 8869 | .tx = iwl_mac_tx, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 8870 | .start = iwl_mac_start, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8871 | .stop = iwl_mac_stop, |
| 8872 | .add_interface = iwl_mac_add_interface, |
| 8873 | .remove_interface = iwl_mac_remove_interface, |
| 8874 | .config = iwl_mac_config, |
| 8875 | .config_interface = iwl_mac_config_interface, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 8876 | .configure_filter = iwl_configure_filter, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8877 | .set_key = iwl_mac_set_key, |
| 8878 | .get_stats = iwl_mac_get_stats, |
| 8879 | .get_tx_stats = iwl_mac_get_tx_stats, |
| 8880 | .conf_tx = iwl_mac_conf_tx, |
| 8881 | .get_tsf = iwl_mac_get_tsf, |
| 8882 | .reset_tsf = iwl_mac_reset_tsf, |
| 8883 | .beacon_update = iwl_mac_beacon_update, |
| 8884 | #ifdef CONFIG_IWLWIFI_HT |
| 8885 | .conf_ht = iwl_mac_conf_ht, |
| 8886 | .get_ht_capab = iwl_mac_get_ht_capab, |
| 8887 | #ifdef CONFIG_IWLWIFI_HT_AGG |
| 8888 | .ht_tx_agg_start = iwl_mac_ht_tx_agg_start, |
| 8889 | .ht_tx_agg_stop = iwl_mac_ht_tx_agg_stop, |
| 8890 | .ht_rx_agg_start = iwl_mac_ht_rx_agg_start, |
| 8891 | .ht_rx_agg_stop = iwl_mac_ht_rx_agg_stop, |
| 8892 | #endif /* CONFIG_IWLWIFI_HT_AGG */ |
| 8893 | #endif /* CONFIG_IWLWIFI_HT */ |
| 8894 | .hw_scan = iwl_mac_hw_scan |
| 8895 | }; |
| 8896 | |
| 8897 | static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 8898 | { |
| 8899 | int err = 0; |
| 8900 | struct iwl_priv *priv; |
| 8901 | struct ieee80211_hw *hw; |
| 8902 | int i; |
| 8903 | |
| 8904 | if (iwl_param_disable_hw_scan) { |
| 8905 | IWL_DEBUG_INFO("Disabling hw_scan\n"); |
| 8906 | iwl_hw_ops.hw_scan = NULL; |
| 8907 | } |
| 8908 | |
| 8909 | if ((iwl_param_queues_num > IWL_MAX_NUM_QUEUES) || |
| 8910 | (iwl_param_queues_num < IWL_MIN_NUM_QUEUES)) { |
| 8911 | IWL_ERROR("invalid queues_num, should be between %d and %d\n", |
| 8912 | IWL_MIN_NUM_QUEUES, IWL_MAX_NUM_QUEUES); |
| 8913 | err = -EINVAL; |
| 8914 | goto out; |
| 8915 | } |
| 8916 | |
| 8917 | /* mac80211 allocates memory for this device instance, including |
| 8918 | * space for this driver's private structure */ |
| 8919 | hw = ieee80211_alloc_hw(sizeof(struct iwl_priv), &iwl_hw_ops); |
| 8920 | if (hw == NULL) { |
| 8921 | IWL_ERROR("Can not allocate network device\n"); |
| 8922 | err = -ENOMEM; |
| 8923 | goto out; |
| 8924 | } |
| 8925 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 8926 | |
| 8927 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); |
| 8928 | priv = hw->priv; |
| 8929 | priv->hw = hw; |
| 8930 | |
| 8931 | priv->pci_dev = pdev; |
| 8932 | priv->antenna = (enum iwl_antenna)iwl_param_antenna; |
| 8933 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 8934 | iwl_debug_level = iwl_param_debug; |
| 8935 | atomic_set(&priv->restrict_refcnt, 0); |
| 8936 | #endif |
| 8937 | priv->retry_rate = 1; |
| 8938 | |
| 8939 | priv->ibss_beacon = NULL; |
| 8940 | |
| 8941 | /* Tell mac80211 and its clients (e.g. Wireless Extensions) |
| 8942 | * the range of signal quality values that we'll provide. |
| 8943 | * Negative values for level/noise indicate that we'll provide dBm. |
| 8944 | * For WE, at least, non-0 values here *enable* display of values |
| 8945 | * in app (iwconfig). */ |
| 8946 | hw->max_rssi = -20; /* signal level, negative indicates dBm */ |
| 8947 | hw->max_noise = -20; /* noise level, negative indicates dBm */ |
| 8948 | hw->max_signal = 100; /* link quality indication (%) */ |
| 8949 | |
| 8950 | /* Tell mac80211 our Tx characteristics */ |
| 8951 | hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE; |
| 8952 | |
| 8953 | hw->queues = 4; |
| 8954 | #ifdef CONFIG_IWLWIFI_HT |
| 8955 | #ifdef CONFIG_IWLWIFI_HT_AGG |
| 8956 | hw->queues = 16; |
| 8957 | #endif /* CONFIG_IWLWIFI_HT_AGG */ |
| 8958 | #endif /* CONFIG_IWLWIFI_HT */ |
| 8959 | |
| 8960 | spin_lock_init(&priv->lock); |
| 8961 | spin_lock_init(&priv->power_data.lock); |
| 8962 | spin_lock_init(&priv->sta_lock); |
| 8963 | spin_lock_init(&priv->hcmd_lock); |
| 8964 | spin_lock_init(&priv->lq_mngr.lock); |
| 8965 | |
| 8966 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) |
| 8967 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); |
| 8968 | |
| 8969 | INIT_LIST_HEAD(&priv->free_frames); |
| 8970 | |
| 8971 | mutex_init(&priv->mutex); |
| 8972 | if (pci_enable_device(pdev)) { |
| 8973 | err = -ENODEV; |
| 8974 | goto out_ieee80211_free_hw; |
| 8975 | } |
| 8976 | |
| 8977 | pci_set_master(pdev); |
| 8978 | |
| 8979 | iwl_clear_stations_table(priv); |
| 8980 | |
| 8981 | priv->data_retry_limit = -1; |
| 8982 | priv->ieee_channels = NULL; |
| 8983 | priv->ieee_rates = NULL; |
| 8984 | priv->phymode = -1; |
| 8985 | |
| 8986 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 8987 | if (!err) |
| 8988 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 8989 | if (err) { |
| 8990 | printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); |
| 8991 | goto out_pci_disable_device; |
| 8992 | } |
| 8993 | |
| 8994 | pci_set_drvdata(pdev, priv); |
| 8995 | err = pci_request_regions(pdev, DRV_NAME); |
| 8996 | if (err) |
| 8997 | goto out_pci_disable_device; |
| 8998 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 8999 | * PCI Tx retries from interfering with C3 CPU state */ |
| 9000 | pci_write_config_byte(pdev, 0x41, 0x00); |
| 9001 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 9002 | if (!priv->hw_base) { |
| 9003 | err = -ENODEV; |
| 9004 | goto out_pci_release_regions; |
| 9005 | } |
| 9006 | |
| 9007 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", |
| 9008 | (unsigned long long) pci_resource_len(pdev, 0)); |
| 9009 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); |
| 9010 | |
| 9011 | /* Initialize module parameter values here */ |
| 9012 | |
| 9013 | if (iwl_param_disable) { |
| 9014 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 9015 | IWL_DEBUG_INFO("Radio disabled.\n"); |
| 9016 | } |
| 9017 | |
| 9018 | priv->iw_mode = IEEE80211_IF_TYPE_STA; |
| 9019 | |
| 9020 | priv->ps_mode = 0; |
| 9021 | priv->use_ant_b_for_management_frame = 1; /* start with ant B */ |
| 9022 | priv->is_ht_enabled = 1; |
| 9023 | priv->channel_width = IWL_CHANNEL_WIDTH_40MHZ; |
| 9024 | priv->valid_antenna = 0x7; /* assume all 3 connected */ |
| 9025 | priv->ps_mode = IWL_MIMO_PS_NONE; |
| 9026 | priv->cck_power_index_compensation = iwl_read32( |
| 9027 | priv, CSR_HW_REV_WA_REG); |
| 9028 | |
| 9029 | iwl4965_set_rxon_chain(priv); |
| 9030 | |
| 9031 | printk(KERN_INFO DRV_NAME |
| 9032 | ": Detected Intel Wireless WiFi Link 4965AGN\n"); |
| 9033 | |
| 9034 | /* Device-specific setup */ |
| 9035 | if (iwl_hw_set_hw_setting(priv)) { |
| 9036 | IWL_ERROR("failed to set hw settings\n"); |
| 9037 | mutex_unlock(&priv->mutex); |
| 9038 | goto out_iounmap; |
| 9039 | } |
| 9040 | |
| 9041 | #ifdef CONFIG_IWLWIFI_QOS |
| 9042 | if (iwl_param_qos_enable) |
| 9043 | priv->qos_data.qos_enable = 1; |
| 9044 | |
| 9045 | iwl_reset_qos(priv); |
| 9046 | |
| 9047 | priv->qos_data.qos_active = 0; |
| 9048 | priv->qos_data.qos_cap.val = 0; |
| 9049 | #endif /* CONFIG_IWLWIFI_QOS */ |
| 9050 | |
| 9051 | iwl_set_rxon_channel(priv, MODE_IEEE80211G, 6); |
| 9052 | iwl_setup_deferred_work(priv); |
| 9053 | iwl_setup_rx_handlers(priv); |
| 9054 | |
| 9055 | priv->rates_mask = IWL_RATES_MASK; |
| 9056 | /* If power management is turned on, default to AC mode */ |
| 9057 | priv->power_mode = IWL_POWER_AC; |
| 9058 | priv->user_txpower_limit = IWL_DEFAULT_TX_POWER; |
| 9059 | |
| 9060 | pci_enable_msi(pdev); |
| 9061 | |
| 9062 | err = request_irq(pdev->irq, iwl_isr, IRQF_SHARED, DRV_NAME, priv); |
| 9063 | if (err) { |
| 9064 | IWL_ERROR("Error allocating IRQ %d\n", pdev->irq); |
| 9065 | goto out_disable_msi; |
| 9066 | } |
| 9067 | |
| 9068 | mutex_lock(&priv->mutex); |
| 9069 | |
| 9070 | err = sysfs_create_group(&pdev->dev.kobj, &iwl_attribute_group); |
| 9071 | if (err) { |
| 9072 | IWL_ERROR("failed to create sysfs device attributes\n"); |
| 9073 | mutex_unlock(&priv->mutex); |
| 9074 | goto out_release_irq; |
| 9075 | } |
| 9076 | |
| 9077 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 9078 | * ucode filename and max sizes are card-specific. */ |
| 9079 | err = iwl_read_ucode(priv); |
| 9080 | if (err) { |
| 9081 | IWL_ERROR("Could not read microcode: %d\n", err); |
| 9082 | mutex_unlock(&priv->mutex); |
| 9083 | goto out_pci_alloc; |
| 9084 | } |
| 9085 | |
| 9086 | mutex_unlock(&priv->mutex); |
| 9087 | |
| 9088 | IWL_DEBUG_INFO("Queing UP work.\n"); |
| 9089 | |
| 9090 | queue_work(priv->workqueue, &priv->up); |
| 9091 | |
| 9092 | return 0; |
| 9093 | |
| 9094 | out_pci_alloc: |
| 9095 | iwl_dealloc_ucode_pci(priv); |
| 9096 | |
| 9097 | sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group); |
| 9098 | |
| 9099 | out_release_irq: |
| 9100 | free_irq(pdev->irq, priv); |
| 9101 | |
| 9102 | out_disable_msi: |
| 9103 | pci_disable_msi(pdev); |
| 9104 | destroy_workqueue(priv->workqueue); |
| 9105 | priv->workqueue = NULL; |
| 9106 | iwl_unset_hw_setting(priv); |
| 9107 | |
| 9108 | out_iounmap: |
| 9109 | pci_iounmap(pdev, priv->hw_base); |
| 9110 | out_pci_release_regions: |
| 9111 | pci_release_regions(pdev); |
| 9112 | out_pci_disable_device: |
| 9113 | pci_disable_device(pdev); |
| 9114 | pci_set_drvdata(pdev, NULL); |
| 9115 | out_ieee80211_free_hw: |
| 9116 | ieee80211_free_hw(priv->hw); |
| 9117 | out: |
| 9118 | return err; |
| 9119 | } |
| 9120 | |
| 9121 | static void iwl_pci_remove(struct pci_dev *pdev) |
| 9122 | { |
| 9123 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
| 9124 | struct list_head *p, *q; |
| 9125 | int i; |
| 9126 | |
| 9127 | if (!priv) |
| 9128 | return; |
| 9129 | |
| 9130 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); |
| 9131 | |
| 9132 | mutex_lock(&priv->mutex); |
| 9133 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 9134 | __iwl_down(priv); |
| 9135 | mutex_unlock(&priv->mutex); |
| 9136 | |
| 9137 | /* Free MAC hash list for ADHOC */ |
| 9138 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) { |
| 9139 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
| 9140 | list_del(p); |
| 9141 | kfree(list_entry(p, struct iwl_ibss_seq, list)); |
| 9142 | } |
| 9143 | } |
| 9144 | |
| 9145 | sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group); |
| 9146 | |
| 9147 | iwl_dealloc_ucode_pci(priv); |
| 9148 | |
| 9149 | if (priv->rxq.bd) |
| 9150 | iwl_rx_queue_free(priv, &priv->rxq); |
| 9151 | iwl_hw_txq_ctx_free(priv); |
| 9152 | |
| 9153 | iwl_unset_hw_setting(priv); |
| 9154 | iwl_clear_stations_table(priv); |
| 9155 | |
| 9156 | if (priv->mac80211_registered) { |
| 9157 | ieee80211_unregister_hw(priv->hw); |
| 9158 | iwl_rate_control_unregister(priv->hw); |
| 9159 | } |
| 9160 | |
| 9161 | /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes |
| 9162 | * priv->workqueue... so we can't take down the workqueue |
| 9163 | * until now... */ |
| 9164 | destroy_workqueue(priv->workqueue); |
| 9165 | priv->workqueue = NULL; |
| 9166 | |
| 9167 | free_irq(pdev->irq, priv); |
| 9168 | pci_disable_msi(pdev); |
| 9169 | pci_iounmap(pdev, priv->hw_base); |
| 9170 | pci_release_regions(pdev); |
| 9171 | pci_disable_device(pdev); |
| 9172 | pci_set_drvdata(pdev, NULL); |
| 9173 | |
| 9174 | kfree(priv->channel_info); |
| 9175 | |
| 9176 | kfree(priv->ieee_channels); |
| 9177 | kfree(priv->ieee_rates); |
| 9178 | |
| 9179 | if (priv->ibss_beacon) |
| 9180 | dev_kfree_skb(priv->ibss_beacon); |
| 9181 | |
| 9182 | ieee80211_free_hw(priv->hw); |
| 9183 | } |
| 9184 | |
| 9185 | #ifdef CONFIG_PM |
| 9186 | |
| 9187 | static int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state) |
| 9188 | { |
| 9189 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
| 9190 | |
| 9191 | mutex_lock(&priv->mutex); |
| 9192 | |
| 9193 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 9194 | |
| 9195 | /* Take down the device; powers it off, etc. */ |
| 9196 | __iwl_down(priv); |
| 9197 | |
| 9198 | if (priv->mac80211_registered) |
| 9199 | ieee80211_stop_queues(priv->hw); |
| 9200 | |
| 9201 | pci_save_state(pdev); |
| 9202 | pci_disable_device(pdev); |
| 9203 | pci_set_power_state(pdev, PCI_D3hot); |
| 9204 | |
| 9205 | mutex_unlock(&priv->mutex); |
| 9206 | |
| 9207 | return 0; |
| 9208 | } |
| 9209 | |
| 9210 | static void iwl_resume(struct iwl_priv *priv) |
| 9211 | { |
| 9212 | unsigned long flags; |
| 9213 | |
| 9214 | /* The following it a temporary work around due to the |
| 9215 | * suspend / resume not fully initializing the NIC correctly. |
| 9216 | * Without all of the following, resume will not attempt to take |
| 9217 | * down the NIC (it shouldn't really need to) and will just try |
| 9218 | * and bring the NIC back up. However that fails during the |
| 9219 | * ucode verification process. This then causes iwl_down to be |
| 9220 | * called *after* iwl_hw_nic_init() has succeeded -- which |
| 9221 | * then lets the next init sequence succeed. So, we've |
| 9222 | * replicated all of that NIC init code here... */ |
| 9223 | |
| 9224 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
| 9225 | |
| 9226 | iwl_hw_nic_init(priv); |
| 9227 | |
| 9228 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 9229 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
| 9230 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 9231 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
| 9232 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 9233 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 9234 | |
| 9235 | /* tell the device to stop sending interrupts */ |
| 9236 | iwl_disable_interrupts(priv); |
| 9237 | |
| 9238 | spin_lock_irqsave(&priv->lock, flags); |
| 9239 | iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 9240 | |
| 9241 | if (!iwl_grab_restricted_access(priv)) { |
| 9242 | iwl_write_restricted_reg(priv, APMG_CLK_DIS_REG, |
| 9243 | APMG_CLK_VAL_DMA_CLK_RQT); |
| 9244 | iwl_release_restricted_access(priv); |
| 9245 | } |
| 9246 | spin_unlock_irqrestore(&priv->lock, flags); |
| 9247 | |
| 9248 | udelay(5); |
| 9249 | |
| 9250 | iwl_hw_nic_reset(priv); |
| 9251 | |
| 9252 | /* Bring the device back up */ |
| 9253 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
| 9254 | queue_work(priv->workqueue, &priv->up); |
| 9255 | } |
| 9256 | |
| 9257 | static int iwl_pci_resume(struct pci_dev *pdev) |
| 9258 | { |
| 9259 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
| 9260 | int err; |
| 9261 | |
| 9262 | printk(KERN_INFO "Coming out of suspend...\n"); |
| 9263 | |
| 9264 | mutex_lock(&priv->mutex); |
| 9265 | |
| 9266 | pci_set_power_state(pdev, PCI_D0); |
| 9267 | err = pci_enable_device(pdev); |
| 9268 | pci_restore_state(pdev); |
| 9269 | |
| 9270 | /* |
| 9271 | * Suspend/Resume resets the PCI configuration space, so we have to |
| 9272 | * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries |
| 9273 | * from interfering with C3 CPU state. pci_restore_state won't help |
| 9274 | * here since it only restores the first 64 bytes pci config header. |
| 9275 | */ |
| 9276 | pci_write_config_byte(pdev, 0x41, 0x00); |
| 9277 | |
| 9278 | iwl_resume(priv); |
| 9279 | mutex_unlock(&priv->mutex); |
| 9280 | |
| 9281 | return 0; |
| 9282 | } |
| 9283 | |
| 9284 | #endif /* CONFIG_PM */ |
| 9285 | |
| 9286 | /***************************************************************************** |
| 9287 | * |
| 9288 | * driver and module entry point |
| 9289 | * |
| 9290 | *****************************************************************************/ |
| 9291 | |
| 9292 | static struct pci_driver iwl_driver = { |
| 9293 | .name = DRV_NAME, |
| 9294 | .id_table = iwl_hw_card_ids, |
| 9295 | .probe = iwl_pci_probe, |
| 9296 | .remove = __devexit_p(iwl_pci_remove), |
| 9297 | #ifdef CONFIG_PM |
| 9298 | .suspend = iwl_pci_suspend, |
| 9299 | .resume = iwl_pci_resume, |
| 9300 | #endif |
| 9301 | }; |
| 9302 | |
| 9303 | static int __init iwl_init(void) |
| 9304 | { |
| 9305 | |
| 9306 | int ret; |
| 9307 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 9308 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
| 9309 | ret = pci_register_driver(&iwl_driver); |
| 9310 | if (ret) { |
| 9311 | IWL_ERROR("Unable to initialize PCI module\n"); |
| 9312 | return ret; |
| 9313 | } |
| 9314 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 9315 | ret = driver_create_file(&iwl_driver.driver, &driver_attr_debug_level); |
| 9316 | if (ret) { |
| 9317 | IWL_ERROR("Unable to create driver sysfs file\n"); |
| 9318 | pci_unregister_driver(&iwl_driver); |
| 9319 | return ret; |
| 9320 | } |
| 9321 | #endif |
| 9322 | |
| 9323 | return ret; |
| 9324 | } |
| 9325 | |
| 9326 | static void __exit iwl_exit(void) |
| 9327 | { |
| 9328 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 9329 | driver_remove_file(&iwl_driver.driver, &driver_attr_debug_level); |
| 9330 | #endif |
| 9331 | pci_unregister_driver(&iwl_driver); |
| 9332 | } |
| 9333 | |
| 9334 | module_param_named(antenna, iwl_param_antenna, int, 0444); |
| 9335 | MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])"); |
| 9336 | module_param_named(disable, iwl_param_disable, int, 0444); |
| 9337 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
| 9338 | module_param_named(hwcrypto, iwl_param_hwcrypto, int, 0444); |
| 9339 | MODULE_PARM_DESC(hwcrypto, |
| 9340 | "using hardware crypto engine (default 0 [software])\n"); |
| 9341 | module_param_named(debug, iwl_param_debug, int, 0444); |
| 9342 | MODULE_PARM_DESC(debug, "debug output mask"); |
| 9343 | module_param_named(disable_hw_scan, iwl_param_disable_hw_scan, int, 0444); |
| 9344 | MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)"); |
| 9345 | |
| 9346 | module_param_named(queues_num, iwl_param_queues_num, int, 0444); |
| 9347 | MODULE_PARM_DESC(queues_num, "number of hw queues."); |
| 9348 | |
| 9349 | /* QoS */ |
| 9350 | module_param_named(qos_enable, iwl_param_qos_enable, int, 0444); |
| 9351 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionality"); |
| 9352 | |
| 9353 | module_exit(iwl_exit); |
| 9354 | module_init(iwl_init); |