Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004-2011 Atheros Communications Inc. |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
| 17 | #include "core.h" |
| 18 | #include "hif-ops.h" |
| 19 | #include "cfg80211.h" |
| 20 | #include "target.h" |
| 21 | #include "debug.h" |
| 22 | |
| 23 | struct ath6kl_sta *ath6kl_find_sta(struct ath6kl *ar, u8 *node_addr) |
| 24 | { |
| 25 | struct ath6kl_sta *conn = NULL; |
| 26 | u8 i, max_conn; |
| 27 | |
| 28 | max_conn = (ar->nw_type == AP_NETWORK) ? AP_MAX_NUM_STA : 0; |
| 29 | |
| 30 | for (i = 0; i < max_conn; i++) { |
| 31 | if (memcmp(node_addr, ar->sta_list[i].mac, ETH_ALEN) == 0) { |
| 32 | conn = &ar->sta_list[i]; |
| 33 | break; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | return conn; |
| 38 | } |
| 39 | |
| 40 | struct ath6kl_sta *ath6kl_find_sta_by_aid(struct ath6kl *ar, u8 aid) |
| 41 | { |
| 42 | struct ath6kl_sta *conn = NULL; |
| 43 | u8 ctr; |
| 44 | |
| 45 | for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) { |
| 46 | if (ar->sta_list[ctr].aid == aid) { |
| 47 | conn = &ar->sta_list[ctr]; |
| 48 | break; |
| 49 | } |
| 50 | } |
| 51 | return conn; |
| 52 | } |
| 53 | |
| 54 | static void ath6kl_add_new_sta(struct ath6kl *ar, u8 *mac, u16 aid, u8 *wpaie, |
| 55 | u8 ielen, u8 keymgmt, u8 ucipher, u8 auth) |
| 56 | { |
| 57 | struct ath6kl_sta *sta; |
| 58 | u8 free_slot; |
| 59 | |
| 60 | free_slot = aid - 1; |
| 61 | |
| 62 | sta = &ar->sta_list[free_slot]; |
| 63 | memcpy(sta->mac, mac, ETH_ALEN); |
Jouni Malinen | 3c774bb | 2011-08-30 21:57:51 +0300 | [diff] [blame] | 64 | if (ielen <= ATH6KL_MAX_IE) |
| 65 | memcpy(sta->wpa_ie, wpaie, ielen); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 66 | sta->aid = aid; |
| 67 | sta->keymgmt = keymgmt; |
| 68 | sta->ucipher = ucipher; |
| 69 | sta->auth = auth; |
| 70 | |
| 71 | ar->sta_list_index = ar->sta_list_index | (1 << free_slot); |
| 72 | ar->ap_stats.sta[free_slot].aid = cpu_to_le32(aid); |
| 73 | } |
| 74 | |
| 75 | static void ath6kl_sta_cleanup(struct ath6kl *ar, u8 i) |
| 76 | { |
| 77 | struct ath6kl_sta *sta = &ar->sta_list[i]; |
| 78 | |
| 79 | /* empty the queued pkts in the PS queue if any */ |
| 80 | spin_lock_bh(&sta->psq_lock); |
| 81 | skb_queue_purge(&sta->psq); |
| 82 | spin_unlock_bh(&sta->psq_lock); |
| 83 | |
| 84 | memset(&ar->ap_stats.sta[sta->aid - 1], 0, |
| 85 | sizeof(struct wmi_per_sta_stat)); |
| 86 | memset(sta->mac, 0, ETH_ALEN); |
| 87 | memset(sta->wpa_ie, 0, ATH6KL_MAX_IE); |
| 88 | sta->aid = 0; |
| 89 | sta->sta_flags = 0; |
| 90 | |
| 91 | ar->sta_list_index = ar->sta_list_index & ~(1 << i); |
| 92 | |
| 93 | } |
| 94 | |
| 95 | static u8 ath6kl_remove_sta(struct ath6kl *ar, u8 *mac, u16 reason) |
| 96 | { |
| 97 | u8 i, removed = 0; |
| 98 | |
| 99 | if (is_zero_ether_addr(mac)) |
| 100 | return removed; |
| 101 | |
| 102 | if (is_broadcast_ether_addr(mac)) { |
| 103 | ath6kl_dbg(ATH6KL_DBG_TRC, "deleting all station\n"); |
| 104 | |
| 105 | for (i = 0; i < AP_MAX_NUM_STA; i++) { |
| 106 | if (!is_zero_ether_addr(ar->sta_list[i].mac)) { |
| 107 | ath6kl_sta_cleanup(ar, i); |
| 108 | removed = 1; |
| 109 | } |
| 110 | } |
| 111 | } else { |
| 112 | for (i = 0; i < AP_MAX_NUM_STA; i++) { |
| 113 | if (memcmp(ar->sta_list[i].mac, mac, ETH_ALEN) == 0) { |
| 114 | ath6kl_dbg(ATH6KL_DBG_TRC, |
| 115 | "deleting station %pM aid=%d reason=%d\n", |
| 116 | mac, ar->sta_list[i].aid, reason); |
| 117 | ath6kl_sta_cleanup(ar, i); |
| 118 | removed = 1; |
| 119 | break; |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | return removed; |
| 125 | } |
| 126 | |
| 127 | enum htc_endpoint_id ath6kl_ac2_endpoint_id(void *devt, u8 ac) |
| 128 | { |
| 129 | struct ath6kl *ar = devt; |
| 130 | return ar->ac2ep_map[ac]; |
| 131 | } |
| 132 | |
| 133 | struct ath6kl_cookie *ath6kl_alloc_cookie(struct ath6kl *ar) |
| 134 | { |
| 135 | struct ath6kl_cookie *cookie; |
| 136 | |
| 137 | cookie = ar->cookie_list; |
| 138 | if (cookie != NULL) { |
| 139 | ar->cookie_list = cookie->arc_list_next; |
| 140 | ar->cookie_count--; |
| 141 | } |
| 142 | |
| 143 | return cookie; |
| 144 | } |
| 145 | |
| 146 | void ath6kl_cookie_init(struct ath6kl *ar) |
| 147 | { |
| 148 | u32 i; |
| 149 | |
| 150 | ar->cookie_list = NULL; |
| 151 | ar->cookie_count = 0; |
| 152 | |
| 153 | memset(ar->cookie_mem, 0, sizeof(ar->cookie_mem)); |
| 154 | |
| 155 | for (i = 0; i < MAX_COOKIE_NUM; i++) |
| 156 | ath6kl_free_cookie(ar, &ar->cookie_mem[i]); |
| 157 | } |
| 158 | |
| 159 | void ath6kl_cookie_cleanup(struct ath6kl *ar) |
| 160 | { |
| 161 | ar->cookie_list = NULL; |
| 162 | ar->cookie_count = 0; |
| 163 | } |
| 164 | |
| 165 | void ath6kl_free_cookie(struct ath6kl *ar, struct ath6kl_cookie *cookie) |
| 166 | { |
| 167 | /* Insert first */ |
| 168 | |
| 169 | if (!ar || !cookie) |
| 170 | return; |
| 171 | |
| 172 | cookie->arc_list_next = ar->cookie_list; |
| 173 | ar->cookie_list = cookie; |
| 174 | ar->cookie_count++; |
| 175 | } |
| 176 | |
| 177 | /* set the window address register (using 4-byte register access ). */ |
| 178 | static int ath6kl_set_addrwin_reg(struct ath6kl *ar, u32 reg_addr, u32 addr) |
| 179 | { |
| 180 | int status; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 181 | s32 i; |
Vasanthakumar Thiagarajan | b142b91 | 2011-08-31 15:48:15 +0530 | [diff] [blame] | 182 | __le32 addr_val; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 183 | |
| 184 | /* |
| 185 | * Write bytes 1,2,3 of the register to set the upper address bytes, |
| 186 | * the LSB is written last to initiate the access cycle |
| 187 | */ |
| 188 | |
| 189 | for (i = 1; i <= 3; i++) { |
| 190 | /* |
| 191 | * Fill the buffer with the address byte value we want to |
Vasanthakumar Thiagarajan | b142b91 | 2011-08-31 15:48:15 +0530 | [diff] [blame] | 192 | * hit 4 times. No need to worry about endianness as the |
| 193 | * same byte is copied to all four bytes of addr_val at |
| 194 | * any time. |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 195 | */ |
Vasanthakumar Thiagarajan | b142b91 | 2011-08-31 15:48:15 +0530 | [diff] [blame] | 196 | memset((u8 *)&addr_val, ((u8 *)&addr)[i], 4); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 197 | |
| 198 | /* |
| 199 | * Hit each byte of the register address with a 4-byte |
| 200 | * write operation to the same address, this is a harmless |
| 201 | * operation. |
| 202 | */ |
Vasanthakumar Thiagarajan | b142b91 | 2011-08-31 15:48:15 +0530 | [diff] [blame] | 203 | status = hif_read_write_sync(ar, reg_addr + i, (u8 *)&addr_val, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 204 | 4, HIF_WR_SYNC_BYTE_FIX); |
| 205 | if (status) |
| 206 | break; |
| 207 | } |
| 208 | |
| 209 | if (status) { |
| 210 | ath6kl_err("failed to write initial bytes of 0x%x to window reg: 0x%X\n", |
| 211 | addr, reg_addr); |
| 212 | return status; |
| 213 | } |
| 214 | |
| 215 | /* |
| 216 | * Write the address register again, this time write the whole |
| 217 | * 4-byte value. The effect here is that the LSB write causes the |
| 218 | * cycle to start, the extra 3 byte write to bytes 1,2,3 has no |
| 219 | * effect since we are writing the same values again |
| 220 | */ |
Vasanthakumar Thiagarajan | b142b91 | 2011-08-31 15:48:15 +0530 | [diff] [blame] | 221 | addr_val = cpu_to_le32(addr); |
| 222 | status = hif_read_write_sync(ar, reg_addr, |
| 223 | (u8 *)&(addr_val), |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 224 | 4, HIF_WR_SYNC_BYTE_INC); |
| 225 | |
| 226 | if (status) { |
| 227 | ath6kl_err("failed to write 0x%x to window reg: 0x%X\n", |
| 228 | addr, reg_addr); |
| 229 | return status; |
| 230 | } |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | /* |
Kalle Valo | addb44b | 2011-09-02 10:32:05 +0300 | [diff] [blame] | 236 | * Read from the hardware through its diagnostic window. No cooperation |
| 237 | * from the firmware is required for this. |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 238 | */ |
Kalle Valo | addb44b | 2011-09-02 10:32:05 +0300 | [diff] [blame] | 239 | int ath6kl_diag_read32(struct ath6kl *ar, u32 address, u32 *value) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 240 | { |
Kalle Valo | addb44b | 2011-09-02 10:32:05 +0300 | [diff] [blame] | 241 | int ret; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 242 | |
| 243 | /* set window register to start read cycle */ |
Kalle Valo | addb44b | 2011-09-02 10:32:05 +0300 | [diff] [blame] | 244 | ret = ath6kl_set_addrwin_reg(ar, WINDOW_READ_ADDR_ADDRESS, address); |
| 245 | if (ret) |
| 246 | return ret; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 247 | |
| 248 | /* read the data */ |
Kalle Valo | addb44b | 2011-09-02 10:32:05 +0300 | [diff] [blame] | 249 | ret = hif_read_write_sync(ar, WINDOW_DATA_ADDRESS, (u8 *) value, |
| 250 | sizeof(*value), HIF_RD_SYNC_BYTE_INC); |
| 251 | if (ret) { |
| 252 | ath6kl_warn("failed to read32 through diagnose window: %d\n", |
| 253 | ret); |
| 254 | return ret; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 255 | } |
| 256 | |
Kalle Valo | addb44b | 2011-09-02 10:32:05 +0300 | [diff] [blame] | 257 | return 0; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 258 | } |
| 259 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 260 | /* |
| 261 | * Write to the ATH6KL through its diagnostic window. No cooperation from |
| 262 | * the Target is required for this. |
| 263 | */ |
Vasanthakumar Thiagarajan | f9ea075 | 2011-09-05 11:19:46 +0300 | [diff] [blame^] | 264 | int ath6kl_diag_write32(struct ath6kl *ar, u32 address, __le32 value) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 265 | { |
Kalle Valo | addb44b | 2011-09-02 10:32:05 +0300 | [diff] [blame] | 266 | int ret; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 267 | |
| 268 | /* set write data */ |
Kalle Valo | addb44b | 2011-09-02 10:32:05 +0300 | [diff] [blame] | 269 | ret = hif_read_write_sync(ar, WINDOW_DATA_ADDRESS, (u8 *) &value, |
| 270 | sizeof(value), HIF_WR_SYNC_BYTE_INC); |
| 271 | if (ret) { |
| 272 | ath6kl_err("failed to write 0x%x during diagnose window to 0x%d\n", |
| 273 | address, value); |
| 274 | return ret; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | /* set window register, which starts the write cycle */ |
| 278 | return ath6kl_set_addrwin_reg(ar, WINDOW_WRITE_ADDR_ADDRESS, |
Kalle Valo | addb44b | 2011-09-02 10:32:05 +0300 | [diff] [blame] | 279 | address); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 280 | } |
| 281 | |
Kalle Valo | addb44b | 2011-09-02 10:32:05 +0300 | [diff] [blame] | 282 | int ath6kl_diag_read(struct ath6kl *ar, u32 address, void *data, u32 length) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 283 | { |
Kalle Valo | addb44b | 2011-09-02 10:32:05 +0300 | [diff] [blame] | 284 | u32 count, *buf = data; |
| 285 | int ret; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 286 | |
Kalle Valo | addb44b | 2011-09-02 10:32:05 +0300 | [diff] [blame] | 287 | if (WARN_ON(length % 4)) |
| 288 | return -EINVAL; |
| 289 | |
| 290 | for (count = 0; count < length / 4; count++, address += 4) { |
| 291 | ret = ath6kl_diag_read32(ar, address, &buf[count]); |
| 292 | if (ret) |
| 293 | return ret; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 294 | } |
| 295 | |
Kalle Valo | addb44b | 2011-09-02 10:32:05 +0300 | [diff] [blame] | 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | int ath6kl_diag_write(struct ath6kl *ar, u32 address, void *data, u32 length) |
| 300 | { |
Vasanthakumar Thiagarajan | f9ea075 | 2011-09-05 11:19:46 +0300 | [diff] [blame^] | 301 | u32 count; |
| 302 | __le32 *buf = data; |
Kalle Valo | addb44b | 2011-09-02 10:32:05 +0300 | [diff] [blame] | 303 | int ret; |
| 304 | |
| 305 | if (WARN_ON(length % 4)) |
| 306 | return -EINVAL; |
| 307 | |
| 308 | for (count = 0; count < length / 4; count++, address += 4) { |
| 309 | ret = ath6kl_diag_write32(ar, address, buf[count]); |
| 310 | if (ret) |
| 311 | return ret; |
| 312 | } |
| 313 | |
| 314 | return 0; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 315 | } |
| 316 | |
Kalle Valo | bc07ddb | 2011-09-02 10:32:05 +0300 | [diff] [blame] | 317 | int ath6kl_read_fwlogs(struct ath6kl *ar) |
| 318 | { |
| 319 | struct ath6kl_dbglog_hdr debug_hdr; |
| 320 | struct ath6kl_dbglog_buf debug_buf; |
| 321 | u32 address, length, dropped, firstbuf, debug_hdr_addr; |
| 322 | int ret = 0, loop; |
| 323 | u8 *buf; |
| 324 | |
| 325 | buf = kmalloc(ATH6KL_FWLOG_PAYLOAD_SIZE, GFP_KERNEL); |
| 326 | if (!buf) |
| 327 | return -ENOMEM; |
| 328 | |
| 329 | address = TARG_VTOP(ar->target_type, |
| 330 | ath6kl_get_hi_item_addr(ar, |
| 331 | HI_ITEM(hi_dbglog_hdr))); |
| 332 | |
| 333 | ret = ath6kl_diag_read32(ar, address, &debug_hdr_addr); |
| 334 | if (ret) |
| 335 | goto out; |
| 336 | |
| 337 | /* Get the contents of the ring buffer */ |
| 338 | if (debug_hdr_addr == 0) { |
| 339 | ath6kl_warn("Invalid address for debug_hdr_addr\n"); |
| 340 | ret = -EINVAL; |
| 341 | goto out; |
| 342 | } |
| 343 | |
| 344 | address = TARG_VTOP(ar->target_type, debug_hdr_addr); |
| 345 | ath6kl_diag_read(ar, address, &debug_hdr, sizeof(debug_hdr)); |
| 346 | |
| 347 | address = TARG_VTOP(ar->target_type, |
| 348 | le32_to_cpu(debug_hdr.dbuf_addr)); |
| 349 | firstbuf = address; |
| 350 | dropped = le32_to_cpu(debug_hdr.dropped); |
| 351 | ath6kl_diag_read(ar, address, &debug_buf, sizeof(debug_buf)); |
| 352 | |
| 353 | loop = 100; |
| 354 | |
| 355 | do { |
| 356 | address = TARG_VTOP(ar->target_type, |
| 357 | le32_to_cpu(debug_buf.buffer_addr)); |
| 358 | length = le32_to_cpu(debug_buf.length); |
| 359 | |
| 360 | if (length != 0 && (le32_to_cpu(debug_buf.length) <= |
| 361 | le32_to_cpu(debug_buf.bufsize))) { |
| 362 | length = ALIGN(length, 4); |
| 363 | |
| 364 | ret = ath6kl_diag_read(ar, address, |
| 365 | buf, length); |
| 366 | if (ret) |
| 367 | goto out; |
| 368 | |
| 369 | ath6kl_debug_fwlog_event(ar, buf, length); |
| 370 | } |
| 371 | |
| 372 | address = TARG_VTOP(ar->target_type, |
| 373 | le32_to_cpu(debug_buf.next)); |
| 374 | ath6kl_diag_read(ar, address, &debug_buf, sizeof(debug_buf)); |
| 375 | if (ret) |
| 376 | goto out; |
| 377 | |
| 378 | loop--; |
| 379 | |
| 380 | if (WARN_ON(loop == 0)) { |
| 381 | ret = -ETIMEDOUT; |
| 382 | goto out; |
| 383 | } |
| 384 | } while (address != firstbuf); |
| 385 | |
| 386 | out: |
| 387 | kfree(buf); |
| 388 | |
| 389 | return ret; |
| 390 | } |
| 391 | |
Kevin Fang | 31024d9 | 2011-07-11 17:14:13 +0800 | [diff] [blame] | 392 | /* FIXME: move to a better place, target.h? */ |
| 393 | #define AR6003_RESET_CONTROL_ADDRESS 0x00004000 |
| 394 | #define AR6004_RESET_CONTROL_ADDRESS 0x00004000 |
| 395 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 396 | static void ath6kl_reset_device(struct ath6kl *ar, u32 target_type, |
| 397 | bool wait_fot_compltn, bool cold_reset) |
| 398 | { |
| 399 | int status = 0; |
| 400 | u32 address; |
Vasanthakumar Thiagarajan | f9ea075 | 2011-09-05 11:19:46 +0300 | [diff] [blame^] | 401 | __le32 data; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 402 | |
Kevin Fang | 31024d9 | 2011-07-11 17:14:13 +0800 | [diff] [blame] | 403 | if (target_type != TARGET_TYPE_AR6003 && |
| 404 | target_type != TARGET_TYPE_AR6004) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 405 | return; |
| 406 | |
Vasanthakumar Thiagarajan | f9ea075 | 2011-09-05 11:19:46 +0300 | [diff] [blame^] | 407 | data = cold_reset ? cpu_to_le32(RESET_CONTROL_COLD_RST) : |
| 408 | cpu_to_le32(RESET_CONTROL_MBOX_RST); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 409 | |
Kevin Fang | 31024d9 | 2011-07-11 17:14:13 +0800 | [diff] [blame] | 410 | switch (target_type) { |
| 411 | case TARGET_TYPE_AR6003: |
| 412 | address = AR6003_RESET_CONTROL_ADDRESS; |
| 413 | break; |
| 414 | case TARGET_TYPE_AR6004: |
| 415 | address = AR6004_RESET_CONTROL_ADDRESS; |
| 416 | break; |
| 417 | default: |
| 418 | address = AR6003_RESET_CONTROL_ADDRESS; |
| 419 | break; |
| 420 | } |
| 421 | |
Kalle Valo | addb44b | 2011-09-02 10:32:05 +0300 | [diff] [blame] | 422 | status = ath6kl_diag_write32(ar, address, data); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 423 | |
| 424 | if (status) |
| 425 | ath6kl_err("failed to reset target\n"); |
| 426 | } |
| 427 | |
| 428 | void ath6kl_stop_endpoint(struct net_device *dev, bool keep_profile, |
| 429 | bool get_dbglogs) |
| 430 | { |
| 431 | struct ath6kl *ar = ath6kl_priv(dev); |
| 432 | static u8 bcast_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
| 433 | bool discon_issued; |
| 434 | |
| 435 | netif_stop_queue(dev); |
| 436 | |
| 437 | /* disable the target and the interrupts associated with it */ |
| 438 | if (test_bit(WMI_READY, &ar->flag)) { |
| 439 | discon_issued = (test_bit(CONNECTED, &ar->flag) || |
| 440 | test_bit(CONNECT_PEND, &ar->flag)); |
| 441 | ath6kl_disconnect(ar); |
| 442 | if (!keep_profile) |
| 443 | ath6kl_init_profile_info(ar); |
| 444 | |
| 445 | del_timer(&ar->disconnect_timer); |
| 446 | |
| 447 | clear_bit(WMI_READY, &ar->flag); |
| 448 | ath6kl_wmi_shutdown(ar->wmi); |
| 449 | clear_bit(WMI_ENABLED, &ar->flag); |
| 450 | ar->wmi = NULL; |
| 451 | |
| 452 | /* |
| 453 | * After wmi_shudown all WMI events will be dropped. We |
| 454 | * need to cleanup the buffers allocated in AP mode and |
| 455 | * give disconnect notification to stack, which usually |
| 456 | * happens in the disconnect_event. Simulate the disconnect |
| 457 | * event by calling the function directly. Sometimes |
| 458 | * disconnect_event will be received when the debug logs |
| 459 | * are collected. |
| 460 | */ |
| 461 | if (discon_issued) |
| 462 | ath6kl_disconnect_event(ar, DISCONNECT_CMD, |
| 463 | (ar->nw_type & AP_NETWORK) ? |
| 464 | bcast_mac : ar->bssid, |
| 465 | 0, NULL, 0); |
| 466 | |
| 467 | ar->user_key_ctrl = 0; |
| 468 | |
| 469 | } else { |
| 470 | ath6kl_dbg(ATH6KL_DBG_TRC, |
| 471 | "%s: wmi is not ready 0x%p 0x%p\n", |
| 472 | __func__, ar, ar->wmi); |
| 473 | |
| 474 | /* Shut down WMI if we have started it */ |
| 475 | if (test_bit(WMI_ENABLED, &ar->flag)) { |
| 476 | ath6kl_dbg(ATH6KL_DBG_TRC, |
| 477 | "%s: shut down wmi\n", __func__); |
| 478 | ath6kl_wmi_shutdown(ar->wmi); |
| 479 | clear_bit(WMI_ENABLED, &ar->flag); |
| 480 | ar->wmi = NULL; |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | if (ar->htc_target) { |
| 485 | ath6kl_dbg(ATH6KL_DBG_TRC, "%s: shut down htc\n", __func__); |
Kalle Valo | ad226ec | 2011-08-10 09:49:12 +0300 | [diff] [blame] | 486 | ath6kl_htc_stop(ar->htc_target); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | /* |
| 490 | * Try to reset the device if we can. The driver may have been |
| 491 | * configure NOT to reset the target during a debug session. |
| 492 | */ |
| 493 | ath6kl_dbg(ATH6KL_DBG_TRC, |
| 494 | "attempting to reset target on instance destroy\n"); |
| 495 | ath6kl_reset_device(ar, ar->target_type, true, true); |
| 496 | } |
| 497 | |
| 498 | static void ath6kl_install_static_wep_keys(struct ath6kl *ar) |
| 499 | { |
| 500 | u8 index; |
| 501 | u8 keyusage; |
| 502 | |
| 503 | for (index = WMI_MIN_KEY_INDEX; index <= WMI_MAX_KEY_INDEX; index++) { |
| 504 | if (ar->wep_key_list[index].key_len) { |
| 505 | keyusage = GROUP_USAGE; |
| 506 | if (index == ar->def_txkey_index) |
| 507 | keyusage |= TX_USAGE; |
| 508 | |
| 509 | ath6kl_wmi_addkey_cmd(ar->wmi, |
| 510 | index, |
| 511 | WEP_CRYPT, |
| 512 | keyusage, |
| 513 | ar->wep_key_list[index].key_len, |
| 514 | NULL, |
| 515 | ar->wep_key_list[index].key, |
| 516 | KEY_OP_INIT_VAL, NULL, |
| 517 | NO_SYNC_WMIFLAG); |
| 518 | } |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | static void ath6kl_connect_ap_mode(struct ath6kl *ar, u16 channel, u8 *bssid, |
| 523 | u16 listen_int, u16 beacon_int, |
Jouni Malinen | 3c774bb | 2011-08-30 21:57:51 +0300 | [diff] [blame] | 524 | u8 assoc_req_len, u8 *assoc_info) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 525 | { |
| 526 | struct net_device *dev = ar->net_dev; |
Jouni Malinen | 3c774bb | 2011-08-30 21:57:51 +0300 | [diff] [blame] | 527 | u8 *ies = NULL, *wpa_ie = NULL, *pos; |
| 528 | size_t ies_len = 0; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 529 | struct station_info sinfo; |
| 530 | struct ath6kl_req_key *ik; |
Jouni Malinen | 9a5b131 | 2011-08-30 21:57:52 +0300 | [diff] [blame] | 531 | int res; |
| 532 | u8 key_rsc[ATH6KL_KEY_SEQ_LEN]; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 533 | |
| 534 | if (memcmp(dev->dev_addr, bssid, ETH_ALEN) == 0) { |
| 535 | ik = &ar->ap_mode_bkey; |
| 536 | |
Jouni Malinen | 9a5b131 | 2011-08-30 21:57:52 +0300 | [diff] [blame] | 537 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "AP mode started on %u MHz\n", |
| 538 | channel); |
| 539 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 540 | switch (ar->auth_mode) { |
| 541 | case NONE_AUTH: |
| 542 | if (ar->prwise_crypto == WEP_CRYPT) |
| 543 | ath6kl_install_static_wep_keys(ar); |
| 544 | break; |
| 545 | case WPA_PSK_AUTH: |
| 546 | case WPA2_PSK_AUTH: |
| 547 | case (WPA_PSK_AUTH|WPA2_PSK_AUTH): |
Jouni Malinen | 9a5b131 | 2011-08-30 21:57:52 +0300 | [diff] [blame] | 548 | if (!ik->valid) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 549 | break; |
Jouni Malinen | 9a5b131 | 2011-08-30 21:57:52 +0300 | [diff] [blame] | 550 | |
| 551 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delayed addkey for " |
| 552 | "the initial group key for AP mode\n"); |
| 553 | memset(key_rsc, 0, sizeof(key_rsc)); |
| 554 | res = ath6kl_wmi_addkey_cmd( |
| 555 | ar->wmi, ik->key_index, ik->key_type, |
| 556 | GROUP_USAGE, ik->key_len, key_rsc, ik->key, |
| 557 | KEY_OP_INIT_VAL, NULL, SYNC_BOTH_WMIFLAG); |
| 558 | if (res) { |
| 559 | ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delayed " |
| 560 | "addkey failed: %d\n", res); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 561 | } |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 562 | break; |
| 563 | } |
Jouni Malinen | 9a5b131 | 2011-08-30 21:57:52 +0300 | [diff] [blame] | 564 | |
| 565 | ath6kl_wmi_bssfilter_cmd(ar->wmi, NONE_BSS_FILTER, 0); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 566 | set_bit(CONNECTED, &ar->flag); |
Jouni Malinen | 9a5b131 | 2011-08-30 21:57:52 +0300 | [diff] [blame] | 567 | netif_carrier_on(ar->net_dev); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 568 | return; |
| 569 | } |
| 570 | |
| 571 | ath6kl_dbg(ATH6KL_DBG_TRC, "new station %pM aid=%d\n", |
| 572 | bssid, channel); |
| 573 | |
Jouni Malinen | 3c774bb | 2011-08-30 21:57:51 +0300 | [diff] [blame] | 574 | if (assoc_req_len > sizeof(struct ieee80211_hdr_3addr)) { |
| 575 | struct ieee80211_mgmt *mgmt = |
| 576 | (struct ieee80211_mgmt *) assoc_info; |
| 577 | if (ieee80211_is_assoc_req(mgmt->frame_control) && |
| 578 | assoc_req_len >= sizeof(struct ieee80211_hdr_3addr) + |
| 579 | sizeof(mgmt->u.assoc_req)) { |
| 580 | ies = mgmt->u.assoc_req.variable; |
| 581 | ies_len = assoc_info + assoc_req_len - ies; |
| 582 | } else if (ieee80211_is_reassoc_req(mgmt->frame_control) && |
| 583 | assoc_req_len >= sizeof(struct ieee80211_hdr_3addr) |
| 584 | + sizeof(mgmt->u.reassoc_req)) { |
| 585 | ies = mgmt->u.reassoc_req.variable; |
| 586 | ies_len = assoc_info + assoc_req_len - ies; |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | pos = ies; |
| 591 | while (pos && pos + 1 < ies + ies_len) { |
| 592 | if (pos + 2 + pos[1] > ies + ies_len) |
| 593 | break; |
| 594 | if (pos[0] == WLAN_EID_RSN) |
| 595 | wpa_ie = pos; /* RSN IE */ |
| 596 | else if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && |
| 597 | pos[1] >= 4 && |
| 598 | pos[2] == 0x00 && pos[3] == 0x50 && pos[4] == 0xf2) { |
| 599 | if (pos[5] == 0x01) |
| 600 | wpa_ie = pos; /* WPA IE */ |
| 601 | else if (pos[5] == 0x04) { |
| 602 | wpa_ie = pos; /* WPS IE */ |
| 603 | break; /* overrides WPA/RSN IE */ |
| 604 | } |
| 605 | } |
| 606 | pos += 2 + pos[1]; |
| 607 | } |
| 608 | |
| 609 | ath6kl_add_new_sta(ar, bssid, channel, wpa_ie, |
| 610 | wpa_ie ? 2 + wpa_ie[1] : 0, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 611 | listen_int & 0xFF, beacon_int, |
| 612 | (listen_int >> 8) & 0xFF); |
| 613 | |
| 614 | /* send event to application */ |
| 615 | memset(&sinfo, 0, sizeof(sinfo)); |
| 616 | |
| 617 | /* TODO: sinfo.generation */ |
Jouni Malinen | 3c774bb | 2011-08-30 21:57:51 +0300 | [diff] [blame] | 618 | |
| 619 | sinfo.assoc_req_ies = ies; |
| 620 | sinfo.assoc_req_ies_len = ies_len; |
| 621 | sinfo.filled |= STATION_INFO_ASSOC_REQ_IES; |
| 622 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 623 | cfg80211_new_sta(ar->net_dev, bssid, &sinfo, GFP_KERNEL); |
| 624 | |
| 625 | netif_wake_queue(ar->net_dev); |
| 626 | |
| 627 | return; |
| 628 | } |
| 629 | |
| 630 | /* Functions for Tx credit handling */ |
| 631 | void ath6k_credit_init(struct htc_credit_state_info *cred_info, |
| 632 | struct list_head *ep_list, |
| 633 | int tot_credits) |
| 634 | { |
| 635 | struct htc_endpoint_credit_dist *cur_ep_dist; |
| 636 | int count; |
| 637 | |
| 638 | cred_info->cur_free_credits = tot_credits; |
| 639 | cred_info->total_avail_credits = tot_credits; |
| 640 | |
| 641 | list_for_each_entry(cur_ep_dist, ep_list, list) { |
| 642 | if (cur_ep_dist->endpoint == ENDPOINT_0) |
| 643 | continue; |
| 644 | |
| 645 | cur_ep_dist->cred_min = cur_ep_dist->cred_per_msg; |
| 646 | |
| 647 | if (tot_credits > 4) |
| 648 | if ((cur_ep_dist->svc_id == WMI_DATA_BK_SVC) || |
| 649 | (cur_ep_dist->svc_id == WMI_DATA_BE_SVC)) { |
| 650 | ath6kl_deposit_credit_to_ep(cred_info, |
| 651 | cur_ep_dist, |
| 652 | cur_ep_dist->cred_min); |
| 653 | cur_ep_dist->dist_flags |= HTC_EP_ACTIVE; |
| 654 | } |
| 655 | |
| 656 | if (cur_ep_dist->svc_id == WMI_CONTROL_SVC) { |
| 657 | ath6kl_deposit_credit_to_ep(cred_info, cur_ep_dist, |
| 658 | cur_ep_dist->cred_min); |
| 659 | /* |
| 660 | * Control service is always marked active, it |
| 661 | * never goes inactive EVER. |
| 662 | */ |
| 663 | cur_ep_dist->dist_flags |= HTC_EP_ACTIVE; |
| 664 | } else if (cur_ep_dist->svc_id == WMI_DATA_BK_SVC) |
| 665 | /* this is the lowest priority data endpoint */ |
| 666 | cred_info->lowestpri_ep_dist = cur_ep_dist->list; |
| 667 | |
| 668 | /* |
| 669 | * Streams have to be created (explicit | implicit) for all |
| 670 | * kinds of traffic. BE endpoints are also inactive in the |
| 671 | * beginning. When BE traffic starts it creates implicit |
| 672 | * streams that redistributes credits. |
| 673 | * |
| 674 | * Note: all other endpoints have minimums set but are |
| 675 | * initially given NO credits. credits will be distributed |
| 676 | * as traffic activity demands |
| 677 | */ |
| 678 | } |
| 679 | |
| 680 | WARN_ON(cred_info->cur_free_credits <= 0); |
| 681 | |
| 682 | list_for_each_entry(cur_ep_dist, ep_list, list) { |
| 683 | if (cur_ep_dist->endpoint == ENDPOINT_0) |
| 684 | continue; |
| 685 | |
| 686 | if (cur_ep_dist->svc_id == WMI_CONTROL_SVC) |
| 687 | cur_ep_dist->cred_norm = cur_ep_dist->cred_per_msg; |
| 688 | else { |
| 689 | /* |
| 690 | * For the remaining data endpoints, we assume that |
| 691 | * each cred_per_msg are the same. We use a simple |
| 692 | * calculation here, we take the remaining credits |
| 693 | * and determine how many max messages this can |
| 694 | * cover and then set each endpoint's normal value |
| 695 | * equal to 3/4 this amount. |
| 696 | */ |
| 697 | count = (cred_info->cur_free_credits / |
| 698 | cur_ep_dist->cred_per_msg) |
| 699 | * cur_ep_dist->cred_per_msg; |
| 700 | count = (count * 3) >> 2; |
| 701 | count = max(count, cur_ep_dist->cred_per_msg); |
| 702 | cur_ep_dist->cred_norm = count; |
| 703 | |
| 704 | } |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | /* initialize and setup credit distribution */ |
| 709 | int ath6k_setup_credit_dist(void *htc_handle, |
| 710 | struct htc_credit_state_info *cred_info) |
| 711 | { |
| 712 | u16 servicepriority[5]; |
| 713 | |
| 714 | memset(cred_info, 0, sizeof(struct htc_credit_state_info)); |
| 715 | |
| 716 | servicepriority[0] = WMI_CONTROL_SVC; /* highest */ |
| 717 | servicepriority[1] = WMI_DATA_VO_SVC; |
| 718 | servicepriority[2] = WMI_DATA_VI_SVC; |
| 719 | servicepriority[3] = WMI_DATA_BE_SVC; |
| 720 | servicepriority[4] = WMI_DATA_BK_SVC; /* lowest */ |
| 721 | |
| 722 | /* set priority list */ |
Kalle Valo | ad226ec | 2011-08-10 09:49:12 +0300 | [diff] [blame] | 723 | ath6kl_htc_set_credit_dist(htc_handle, cred_info, servicepriority, 5); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 724 | |
| 725 | return 0; |
| 726 | } |
| 727 | |
| 728 | /* reduce an ep's credits back to a set limit */ |
| 729 | static void ath6k_reduce_credits(struct htc_credit_state_info *cred_info, |
| 730 | struct htc_endpoint_credit_dist *ep_dist, |
| 731 | int limit) |
| 732 | { |
| 733 | int credits; |
| 734 | |
| 735 | ep_dist->cred_assngd = limit; |
| 736 | |
| 737 | if (ep_dist->credits <= limit) |
| 738 | return; |
| 739 | |
| 740 | credits = ep_dist->credits - limit; |
| 741 | ep_dist->credits -= credits; |
| 742 | cred_info->cur_free_credits += credits; |
| 743 | } |
| 744 | |
| 745 | static void ath6k_credit_update(struct htc_credit_state_info *cred_info, |
| 746 | struct list_head *epdist_list) |
| 747 | { |
| 748 | struct htc_endpoint_credit_dist *cur_dist_list; |
| 749 | |
| 750 | list_for_each_entry(cur_dist_list, epdist_list, list) { |
| 751 | if (cur_dist_list->endpoint == ENDPOINT_0) |
| 752 | continue; |
| 753 | |
| 754 | if (cur_dist_list->cred_to_dist > 0) { |
| 755 | cur_dist_list->credits += |
| 756 | cur_dist_list->cred_to_dist; |
| 757 | cur_dist_list->cred_to_dist = 0; |
| 758 | if (cur_dist_list->credits > |
| 759 | cur_dist_list->cred_assngd) |
| 760 | ath6k_reduce_credits(cred_info, |
| 761 | cur_dist_list, |
| 762 | cur_dist_list->cred_assngd); |
| 763 | |
| 764 | if (cur_dist_list->credits > |
| 765 | cur_dist_list->cred_norm) |
| 766 | ath6k_reduce_credits(cred_info, cur_dist_list, |
| 767 | cur_dist_list->cred_norm); |
| 768 | |
| 769 | if (!(cur_dist_list->dist_flags & HTC_EP_ACTIVE)) { |
| 770 | if (cur_dist_list->txq_depth == 0) |
| 771 | ath6k_reduce_credits(cred_info, |
| 772 | cur_dist_list, 0); |
| 773 | } |
| 774 | } |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | /* |
| 779 | * HTC has an endpoint that needs credits, ep_dist is the endpoint in |
| 780 | * question. |
| 781 | */ |
| 782 | void ath6k_seek_credits(struct htc_credit_state_info *cred_info, |
| 783 | struct htc_endpoint_credit_dist *ep_dist) |
| 784 | { |
| 785 | struct htc_endpoint_credit_dist *curdist_list; |
| 786 | int credits = 0; |
| 787 | int need; |
| 788 | |
| 789 | if (ep_dist->svc_id == WMI_CONTROL_SVC) |
| 790 | goto out; |
| 791 | |
| 792 | if ((ep_dist->svc_id == WMI_DATA_VI_SVC) || |
| 793 | (ep_dist->svc_id == WMI_DATA_VO_SVC)) |
| 794 | if ((ep_dist->cred_assngd >= ep_dist->cred_norm)) |
| 795 | goto out; |
| 796 | |
| 797 | /* |
| 798 | * For all other services, we follow a simple algorithm of: |
| 799 | * |
| 800 | * 1. checking the free pool for credits |
| 801 | * 2. checking lower priority endpoints for credits to take |
| 802 | */ |
| 803 | |
| 804 | credits = min(cred_info->cur_free_credits, ep_dist->seek_cred); |
| 805 | |
| 806 | if (credits >= ep_dist->seek_cred) |
| 807 | goto out; |
| 808 | |
| 809 | /* |
| 810 | * We don't have enough in the free pool, try taking away from |
| 811 | * lower priority services The rule for taking away credits: |
| 812 | * |
| 813 | * 1. Only take from lower priority endpoints |
| 814 | * 2. Only take what is allocated above the minimum (never |
| 815 | * starve an endpoint completely) |
| 816 | * 3. Only take what you need. |
| 817 | */ |
| 818 | |
| 819 | list_for_each_entry_reverse(curdist_list, |
| 820 | &cred_info->lowestpri_ep_dist, |
| 821 | list) { |
| 822 | if (curdist_list == ep_dist) |
| 823 | break; |
| 824 | |
| 825 | need = ep_dist->seek_cred - cred_info->cur_free_credits; |
| 826 | |
| 827 | if ((curdist_list->cred_assngd - need) >= |
| 828 | curdist_list->cred_min) { |
| 829 | /* |
| 830 | * The current one has been allocated more than |
| 831 | * it's minimum and it has enough credits assigned |
| 832 | * above it's minimum to fulfill our need try to |
| 833 | * take away just enough to fulfill our need. |
| 834 | */ |
| 835 | ath6k_reduce_credits(cred_info, curdist_list, |
| 836 | curdist_list->cred_assngd - need); |
| 837 | |
| 838 | if (cred_info->cur_free_credits >= |
| 839 | ep_dist->seek_cred) |
| 840 | break; |
| 841 | } |
| 842 | |
| 843 | if (curdist_list->endpoint == ENDPOINT_0) |
| 844 | break; |
| 845 | } |
| 846 | |
| 847 | credits = min(cred_info->cur_free_credits, ep_dist->seek_cred); |
| 848 | |
| 849 | out: |
| 850 | /* did we find some credits? */ |
| 851 | if (credits) |
| 852 | ath6kl_deposit_credit_to_ep(cred_info, ep_dist, credits); |
| 853 | |
| 854 | ep_dist->seek_cred = 0; |
| 855 | } |
| 856 | |
| 857 | /* redistribute credits based on activity change */ |
| 858 | static void ath6k_redistribute_credits(struct htc_credit_state_info *info, |
| 859 | struct list_head *ep_dist_list) |
| 860 | { |
| 861 | struct htc_endpoint_credit_dist *curdist_list; |
| 862 | |
| 863 | list_for_each_entry(curdist_list, ep_dist_list, list) { |
| 864 | if (curdist_list->endpoint == ENDPOINT_0) |
| 865 | continue; |
| 866 | |
| 867 | if ((curdist_list->svc_id == WMI_DATA_BK_SVC) || |
| 868 | (curdist_list->svc_id == WMI_DATA_BE_SVC)) |
| 869 | curdist_list->dist_flags |= HTC_EP_ACTIVE; |
| 870 | |
| 871 | if ((curdist_list->svc_id != WMI_CONTROL_SVC) && |
| 872 | !(curdist_list->dist_flags & HTC_EP_ACTIVE)) { |
| 873 | if (curdist_list->txq_depth == 0) |
| 874 | ath6k_reduce_credits(info, |
| 875 | curdist_list, 0); |
| 876 | else |
| 877 | ath6k_reduce_credits(info, |
| 878 | curdist_list, |
| 879 | curdist_list->cred_min); |
| 880 | } |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | /* |
| 885 | * |
| 886 | * This function is invoked whenever endpoints require credit |
| 887 | * distributions. A lock is held while this function is invoked, this |
| 888 | * function shall NOT block. The ep_dist_list is a list of distribution |
| 889 | * structures in prioritized order as defined by the call to the |
| 890 | * htc_set_credit_dist() api. |
| 891 | */ |
| 892 | void ath6k_credit_distribute(struct htc_credit_state_info *cred_info, |
| 893 | struct list_head *ep_dist_list, |
| 894 | enum htc_credit_dist_reason reason) |
| 895 | { |
| 896 | switch (reason) { |
| 897 | case HTC_CREDIT_DIST_SEND_COMPLETE: |
| 898 | ath6k_credit_update(cred_info, ep_dist_list); |
| 899 | break; |
| 900 | case HTC_CREDIT_DIST_ACTIVITY_CHANGE: |
| 901 | ath6k_redistribute_credits(cred_info, ep_dist_list); |
| 902 | break; |
| 903 | default: |
| 904 | break; |
| 905 | } |
| 906 | |
| 907 | WARN_ON(cred_info->cur_free_credits > cred_info->total_avail_credits); |
| 908 | WARN_ON(cred_info->cur_free_credits < 0); |
| 909 | } |
| 910 | |
| 911 | void disconnect_timer_handler(unsigned long ptr) |
| 912 | { |
| 913 | struct net_device *dev = (struct net_device *)ptr; |
| 914 | struct ath6kl *ar = ath6kl_priv(dev); |
| 915 | |
| 916 | ath6kl_init_profile_info(ar); |
| 917 | ath6kl_disconnect(ar); |
| 918 | } |
| 919 | |
| 920 | void ath6kl_disconnect(struct ath6kl *ar) |
| 921 | { |
| 922 | if (test_bit(CONNECTED, &ar->flag) || |
| 923 | test_bit(CONNECT_PEND, &ar->flag)) { |
| 924 | ath6kl_wmi_disconnect_cmd(ar->wmi); |
| 925 | /* |
| 926 | * Disconnect command is issued, clear the connect pending |
| 927 | * flag. The connected flag will be cleared in |
| 928 | * disconnect event notification. |
| 929 | */ |
| 930 | clear_bit(CONNECT_PEND, &ar->flag); |
| 931 | } |
| 932 | } |
| 933 | |
Kalle Valo | abcb344 | 2011-07-22 08:26:20 +0300 | [diff] [blame] | 934 | void ath6kl_deep_sleep_enable(struct ath6kl *ar) |
| 935 | { |
| 936 | switch (ar->sme_state) { |
| 937 | case SME_CONNECTING: |
| 938 | cfg80211_connect_result(ar->net_dev, ar->bssid, NULL, 0, |
| 939 | NULL, 0, |
| 940 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
| 941 | GFP_KERNEL); |
| 942 | break; |
| 943 | case SME_CONNECTED: |
| 944 | default: |
| 945 | /* |
| 946 | * FIXME: oddly enough smeState is in DISCONNECTED during |
| 947 | * suspend, why? Need to send disconnected event in that |
| 948 | * state. |
| 949 | */ |
| 950 | cfg80211_disconnected(ar->net_dev, 0, NULL, 0, GFP_KERNEL); |
| 951 | break; |
| 952 | } |
| 953 | |
| 954 | if (test_bit(CONNECTED, &ar->flag) || |
| 955 | test_bit(CONNECT_PEND, &ar->flag)) |
| 956 | ath6kl_wmi_disconnect_cmd(ar->wmi); |
| 957 | |
| 958 | ar->sme_state = SME_DISCONNECTED; |
| 959 | |
| 960 | /* disable scanning */ |
| 961 | if (ath6kl_wmi_scanparams_cmd(ar->wmi, 0xFFFF, 0, 0, 0, 0, 0, 0, 0, |
| 962 | 0, 0) != 0) |
| 963 | printk(KERN_WARNING "ath6kl: failed to disable scan " |
| 964 | "during suspend\n"); |
| 965 | |
| 966 | ath6kl_cfg80211_scan_complete_event(ar, -ECANCELED); |
| 967 | } |
| 968 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 969 | /* WMI Event handlers */ |
| 970 | |
| 971 | static const char *get_hw_id_string(u32 id) |
| 972 | { |
| 973 | switch (id) { |
| 974 | case AR6003_REV1_VERSION: |
| 975 | return "1.0"; |
| 976 | case AR6003_REV2_VERSION: |
| 977 | return "2.0"; |
| 978 | case AR6003_REV3_VERSION: |
| 979 | return "2.1.1"; |
| 980 | default: |
| 981 | return "unknown"; |
| 982 | } |
| 983 | } |
| 984 | |
| 985 | void ath6kl_ready_event(void *devt, u8 *datap, u32 sw_ver, u32 abi_ver) |
| 986 | { |
| 987 | struct ath6kl *ar = devt; |
| 988 | struct net_device *dev = ar->net_dev; |
| 989 | |
| 990 | memcpy(dev->dev_addr, datap, ETH_ALEN); |
| 991 | ath6kl_dbg(ATH6KL_DBG_TRC, "%s: mac addr = %pM\n", |
| 992 | __func__, dev->dev_addr); |
| 993 | |
| 994 | ar->version.wlan_ver = sw_ver; |
| 995 | ar->version.abi_ver = abi_ver; |
| 996 | |
| 997 | snprintf(ar->wdev->wiphy->fw_version, |
| 998 | sizeof(ar->wdev->wiphy->fw_version), |
| 999 | "%u.%u.%u.%u", |
| 1000 | (ar->version.wlan_ver & 0xf0000000) >> 28, |
| 1001 | (ar->version.wlan_ver & 0x0f000000) >> 24, |
| 1002 | (ar->version.wlan_ver & 0x00ff0000) >> 16, |
| 1003 | (ar->version.wlan_ver & 0x0000ffff)); |
| 1004 | |
| 1005 | /* indicate to the waiting thread that the ready event was received */ |
| 1006 | set_bit(WMI_READY, &ar->flag); |
| 1007 | wake_up(&ar->event_wq); |
| 1008 | |
Kalle Valo | 003353b0d | 2011-09-01 10:14:21 +0300 | [diff] [blame] | 1009 | ath6kl_info("hw %s fw %s%s\n", |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1010 | get_hw_id_string(ar->wdev->wiphy->hw_version), |
Kalle Valo | 003353b0d | 2011-09-01 10:14:21 +0300 | [diff] [blame] | 1011 | ar->wdev->wiphy->fw_version, |
| 1012 | test_bit(TESTMODE, &ar->flag) ? " testmode" : ""); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | void ath6kl_scan_complete_evt(struct ath6kl *ar, int status) |
| 1016 | { |
| 1017 | ath6kl_cfg80211_scan_complete_event(ar, status); |
| 1018 | |
| 1019 | if (!ar->usr_bss_filter) |
| 1020 | ath6kl_wmi_bssfilter_cmd(ar->wmi, NONE_BSS_FILTER, 0); |
| 1021 | |
| 1022 | ath6kl_dbg(ATH6KL_DBG_WLAN_SCAN, "scan complete: %d\n", status); |
| 1023 | } |
| 1024 | |
| 1025 | void ath6kl_connect_event(struct ath6kl *ar, u16 channel, u8 *bssid, |
| 1026 | u16 listen_int, u16 beacon_int, |
| 1027 | enum network_type net_type, u8 beacon_ie_len, |
| 1028 | u8 assoc_req_len, u8 assoc_resp_len, |
| 1029 | u8 *assoc_info) |
| 1030 | { |
| 1031 | unsigned long flags; |
| 1032 | |
| 1033 | if (ar->nw_type == AP_NETWORK) { |
| 1034 | ath6kl_connect_ap_mode(ar, channel, bssid, listen_int, |
Jouni Malinen | 3c774bb | 2011-08-30 21:57:51 +0300 | [diff] [blame] | 1035 | beacon_int, assoc_req_len, |
| 1036 | assoc_info + beacon_ie_len); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1037 | return; |
| 1038 | } |
| 1039 | |
| 1040 | ath6kl_cfg80211_connect_event(ar, channel, bssid, |
| 1041 | listen_int, beacon_int, |
| 1042 | net_type, beacon_ie_len, |
| 1043 | assoc_req_len, assoc_resp_len, |
| 1044 | assoc_info); |
| 1045 | |
| 1046 | memcpy(ar->bssid, bssid, sizeof(ar->bssid)); |
| 1047 | ar->bss_ch = channel; |
| 1048 | |
| 1049 | if ((ar->nw_type == INFRA_NETWORK)) |
| 1050 | ath6kl_wmi_listeninterval_cmd(ar->wmi, ar->listen_intvl_t, |
| 1051 | ar->listen_intvl_b); |
| 1052 | |
| 1053 | netif_wake_queue(ar->net_dev); |
| 1054 | |
| 1055 | /* Update connect & link status atomically */ |
| 1056 | spin_lock_irqsave(&ar->lock, flags); |
| 1057 | set_bit(CONNECTED, &ar->flag); |
| 1058 | clear_bit(CONNECT_PEND, &ar->flag); |
| 1059 | netif_carrier_on(ar->net_dev); |
| 1060 | spin_unlock_irqrestore(&ar->lock, flags); |
| 1061 | |
| 1062 | aggr_reset_state(ar->aggr_cntxt); |
| 1063 | ar->reconnect_flag = 0; |
| 1064 | |
| 1065 | if ((ar->nw_type == ADHOC_NETWORK) && ar->ibss_ps_enable) { |
| 1066 | memset(ar->node_map, 0, sizeof(ar->node_map)); |
| 1067 | ar->node_num = 0; |
| 1068 | ar->next_ep_id = ENDPOINT_2; |
| 1069 | } |
| 1070 | |
| 1071 | if (!ar->usr_bss_filter) |
| 1072 | ath6kl_wmi_bssfilter_cmd(ar->wmi, NONE_BSS_FILTER, 0); |
| 1073 | } |
| 1074 | |
| 1075 | void ath6kl_tkip_micerr_event(struct ath6kl *ar, u8 keyid, bool ismcast) |
| 1076 | { |
| 1077 | struct ath6kl_sta *sta; |
| 1078 | u8 tsc[6]; |
| 1079 | /* |
| 1080 | * For AP case, keyid will have aid of STA which sent pkt with |
| 1081 | * MIC error. Use this aid to get MAC & send it to hostapd. |
| 1082 | */ |
| 1083 | if (ar->nw_type == AP_NETWORK) { |
| 1084 | sta = ath6kl_find_sta_by_aid(ar, (keyid >> 2)); |
| 1085 | if (!sta) |
| 1086 | return; |
| 1087 | |
| 1088 | ath6kl_dbg(ATH6KL_DBG_TRC, |
| 1089 | "ap tkip mic error received from aid=%d\n", keyid); |
| 1090 | |
| 1091 | memset(tsc, 0, sizeof(tsc)); /* FIX: get correct TSC */ |
| 1092 | cfg80211_michael_mic_failure(ar->net_dev, sta->mac, |
| 1093 | NL80211_KEYTYPE_PAIRWISE, keyid, |
| 1094 | tsc, GFP_KERNEL); |
| 1095 | } else |
| 1096 | ath6kl_cfg80211_tkip_micerr_event(ar, keyid, ismcast); |
| 1097 | |
| 1098 | } |
| 1099 | |
| 1100 | static void ath6kl_update_target_stats(struct ath6kl *ar, u8 *ptr, u32 len) |
| 1101 | { |
| 1102 | struct wmi_target_stats *tgt_stats = |
| 1103 | (struct wmi_target_stats *) ptr; |
| 1104 | struct target_stats *stats = &ar->target_stats; |
| 1105 | struct tkip_ccmp_stats *ccmp_stats; |
| 1106 | struct bss *conn_bss = NULL; |
| 1107 | struct cserv_stats *c_stats; |
| 1108 | u8 ac; |
| 1109 | |
| 1110 | if (len < sizeof(*tgt_stats)) |
| 1111 | return; |
| 1112 | |
| 1113 | /* update the RSSI of the connected bss */ |
| 1114 | if (test_bit(CONNECTED, &ar->flag)) { |
| 1115 | conn_bss = ath6kl_wmi_find_node(ar->wmi, ar->bssid); |
| 1116 | if (conn_bss) { |
| 1117 | c_stats = &tgt_stats->cserv_stats; |
| 1118 | conn_bss->ni_rssi = |
| 1119 | a_sle16_to_cpu(c_stats->cs_ave_beacon_rssi); |
| 1120 | conn_bss->ni_snr = |
| 1121 | tgt_stats->cserv_stats.cs_ave_beacon_snr; |
| 1122 | ath6kl_wmi_node_return(ar->wmi, conn_bss); |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | ath6kl_dbg(ATH6KL_DBG_TRC, "updating target stats\n"); |
| 1127 | |
| 1128 | stats->tx_pkt += le32_to_cpu(tgt_stats->stats.tx.pkt); |
| 1129 | stats->tx_byte += le32_to_cpu(tgt_stats->stats.tx.byte); |
| 1130 | stats->tx_ucast_pkt += le32_to_cpu(tgt_stats->stats.tx.ucast_pkt); |
| 1131 | stats->tx_ucast_byte += le32_to_cpu(tgt_stats->stats.tx.ucast_byte); |
| 1132 | stats->tx_mcast_pkt += le32_to_cpu(tgt_stats->stats.tx.mcast_pkt); |
| 1133 | stats->tx_mcast_byte += le32_to_cpu(tgt_stats->stats.tx.mcast_byte); |
| 1134 | stats->tx_bcast_pkt += le32_to_cpu(tgt_stats->stats.tx.bcast_pkt); |
| 1135 | stats->tx_bcast_byte += le32_to_cpu(tgt_stats->stats.tx.bcast_byte); |
| 1136 | stats->tx_rts_success_cnt += |
| 1137 | le32_to_cpu(tgt_stats->stats.tx.rts_success_cnt); |
| 1138 | |
| 1139 | for (ac = 0; ac < WMM_NUM_AC; ac++) |
| 1140 | stats->tx_pkt_per_ac[ac] += |
| 1141 | le32_to_cpu(tgt_stats->stats.tx.pkt_per_ac[ac]); |
| 1142 | |
| 1143 | stats->tx_err += le32_to_cpu(tgt_stats->stats.tx.err); |
| 1144 | stats->tx_fail_cnt += le32_to_cpu(tgt_stats->stats.tx.fail_cnt); |
| 1145 | stats->tx_retry_cnt += le32_to_cpu(tgt_stats->stats.tx.retry_cnt); |
| 1146 | stats->tx_mult_retry_cnt += |
| 1147 | le32_to_cpu(tgt_stats->stats.tx.mult_retry_cnt); |
| 1148 | stats->tx_rts_fail_cnt += |
| 1149 | le32_to_cpu(tgt_stats->stats.tx.rts_fail_cnt); |
| 1150 | stats->tx_ucast_rate = |
| 1151 | ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats->stats.tx.ucast_rate)); |
| 1152 | |
| 1153 | stats->rx_pkt += le32_to_cpu(tgt_stats->stats.rx.pkt); |
| 1154 | stats->rx_byte += le32_to_cpu(tgt_stats->stats.rx.byte); |
| 1155 | stats->rx_ucast_pkt += le32_to_cpu(tgt_stats->stats.rx.ucast_pkt); |
| 1156 | stats->rx_ucast_byte += le32_to_cpu(tgt_stats->stats.rx.ucast_byte); |
| 1157 | stats->rx_mcast_pkt += le32_to_cpu(tgt_stats->stats.rx.mcast_pkt); |
| 1158 | stats->rx_mcast_byte += le32_to_cpu(tgt_stats->stats.rx.mcast_byte); |
| 1159 | stats->rx_bcast_pkt += le32_to_cpu(tgt_stats->stats.rx.bcast_pkt); |
| 1160 | stats->rx_bcast_byte += le32_to_cpu(tgt_stats->stats.rx.bcast_byte); |
| 1161 | stats->rx_frgment_pkt += le32_to_cpu(tgt_stats->stats.rx.frgment_pkt); |
| 1162 | stats->rx_err += le32_to_cpu(tgt_stats->stats.rx.err); |
| 1163 | stats->rx_crc_err += le32_to_cpu(tgt_stats->stats.rx.crc_err); |
| 1164 | stats->rx_key_cache_miss += |
| 1165 | le32_to_cpu(tgt_stats->stats.rx.key_cache_miss); |
| 1166 | stats->rx_decrypt_err += le32_to_cpu(tgt_stats->stats.rx.decrypt_err); |
| 1167 | stats->rx_dupl_frame += le32_to_cpu(tgt_stats->stats.rx.dupl_frame); |
| 1168 | stats->rx_ucast_rate = |
| 1169 | ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats->stats.rx.ucast_rate)); |
| 1170 | |
| 1171 | ccmp_stats = &tgt_stats->stats.tkip_ccmp_stats; |
| 1172 | |
| 1173 | stats->tkip_local_mic_fail += |
| 1174 | le32_to_cpu(ccmp_stats->tkip_local_mic_fail); |
| 1175 | stats->tkip_cnter_measures_invoked += |
| 1176 | le32_to_cpu(ccmp_stats->tkip_cnter_measures_invoked); |
| 1177 | stats->tkip_fmt_err += le32_to_cpu(ccmp_stats->tkip_fmt_err); |
| 1178 | |
| 1179 | stats->ccmp_fmt_err += le32_to_cpu(ccmp_stats->ccmp_fmt_err); |
| 1180 | stats->ccmp_replays += le32_to_cpu(ccmp_stats->ccmp_replays); |
| 1181 | |
| 1182 | stats->pwr_save_fail_cnt += |
| 1183 | le32_to_cpu(tgt_stats->pm_stats.pwr_save_failure_cnt); |
| 1184 | stats->noise_floor_calib = |
| 1185 | a_sle32_to_cpu(tgt_stats->noise_floor_calib); |
| 1186 | |
| 1187 | stats->cs_bmiss_cnt += |
| 1188 | le32_to_cpu(tgt_stats->cserv_stats.cs_bmiss_cnt); |
| 1189 | stats->cs_low_rssi_cnt += |
| 1190 | le32_to_cpu(tgt_stats->cserv_stats.cs_low_rssi_cnt); |
| 1191 | stats->cs_connect_cnt += |
| 1192 | le16_to_cpu(tgt_stats->cserv_stats.cs_connect_cnt); |
| 1193 | stats->cs_discon_cnt += |
| 1194 | le16_to_cpu(tgt_stats->cserv_stats.cs_discon_cnt); |
| 1195 | |
| 1196 | stats->cs_ave_beacon_rssi = |
| 1197 | a_sle16_to_cpu(tgt_stats->cserv_stats.cs_ave_beacon_rssi); |
| 1198 | |
| 1199 | stats->cs_last_roam_msec = |
| 1200 | tgt_stats->cserv_stats.cs_last_roam_msec; |
| 1201 | stats->cs_snr = tgt_stats->cserv_stats.cs_snr; |
| 1202 | stats->cs_rssi = a_sle16_to_cpu(tgt_stats->cserv_stats.cs_rssi); |
| 1203 | |
| 1204 | stats->lq_val = le32_to_cpu(tgt_stats->lq_val); |
| 1205 | |
| 1206 | stats->wow_pkt_dropped += |
| 1207 | le32_to_cpu(tgt_stats->wow_stats.wow_pkt_dropped); |
| 1208 | stats->wow_host_pkt_wakeups += |
| 1209 | tgt_stats->wow_stats.wow_host_pkt_wakeups; |
| 1210 | stats->wow_host_evt_wakeups += |
| 1211 | tgt_stats->wow_stats.wow_host_evt_wakeups; |
| 1212 | stats->wow_evt_discarded += |
| 1213 | le16_to_cpu(tgt_stats->wow_stats.wow_evt_discarded); |
| 1214 | |
| 1215 | if (test_bit(STATS_UPDATE_PEND, &ar->flag)) { |
| 1216 | clear_bit(STATS_UPDATE_PEND, &ar->flag); |
| 1217 | wake_up(&ar->event_wq); |
| 1218 | } |
| 1219 | } |
| 1220 | |
| 1221 | static void ath6kl_add_le32(__le32 *var, __le32 val) |
| 1222 | { |
| 1223 | *var = cpu_to_le32(le32_to_cpu(*var) + le32_to_cpu(val)); |
| 1224 | } |
| 1225 | |
| 1226 | void ath6kl_tgt_stats_event(struct ath6kl *ar, u8 *ptr, u32 len) |
| 1227 | { |
| 1228 | struct wmi_ap_mode_stat *p = (struct wmi_ap_mode_stat *) ptr; |
| 1229 | struct wmi_ap_mode_stat *ap = &ar->ap_stats; |
| 1230 | struct wmi_per_sta_stat *st_ap, *st_p; |
| 1231 | u8 ac; |
| 1232 | |
| 1233 | if (ar->nw_type == AP_NETWORK) { |
| 1234 | if (len < sizeof(*p)) |
| 1235 | return; |
| 1236 | |
| 1237 | for (ac = 0; ac < AP_MAX_NUM_STA; ac++) { |
| 1238 | st_ap = &ap->sta[ac]; |
| 1239 | st_p = &p->sta[ac]; |
| 1240 | |
| 1241 | ath6kl_add_le32(&st_ap->tx_bytes, st_p->tx_bytes); |
| 1242 | ath6kl_add_le32(&st_ap->tx_pkts, st_p->tx_pkts); |
| 1243 | ath6kl_add_le32(&st_ap->tx_error, st_p->tx_error); |
| 1244 | ath6kl_add_le32(&st_ap->tx_discard, st_p->tx_discard); |
| 1245 | ath6kl_add_le32(&st_ap->rx_bytes, st_p->rx_bytes); |
| 1246 | ath6kl_add_le32(&st_ap->rx_pkts, st_p->rx_pkts); |
| 1247 | ath6kl_add_le32(&st_ap->rx_error, st_p->rx_error); |
| 1248 | ath6kl_add_le32(&st_ap->rx_discard, st_p->rx_discard); |
| 1249 | } |
| 1250 | |
| 1251 | } else { |
| 1252 | ath6kl_update_target_stats(ar, ptr, len); |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | void ath6kl_wakeup_event(void *dev) |
| 1257 | { |
| 1258 | struct ath6kl *ar = (struct ath6kl *) dev; |
| 1259 | |
| 1260 | wake_up(&ar->event_wq); |
| 1261 | } |
| 1262 | |
| 1263 | void ath6kl_txpwr_rx_evt(void *devt, u8 tx_pwr) |
| 1264 | { |
| 1265 | struct ath6kl *ar = (struct ath6kl *) devt; |
| 1266 | |
| 1267 | ar->tx_pwr = tx_pwr; |
| 1268 | wake_up(&ar->event_wq); |
| 1269 | } |
| 1270 | |
| 1271 | void ath6kl_pspoll_event(struct ath6kl *ar, u8 aid) |
| 1272 | { |
| 1273 | struct ath6kl_sta *conn; |
| 1274 | struct sk_buff *skb; |
| 1275 | bool psq_empty = false; |
| 1276 | |
| 1277 | conn = ath6kl_find_sta_by_aid(ar, aid); |
| 1278 | |
| 1279 | if (!conn) |
| 1280 | return; |
| 1281 | /* |
| 1282 | * Send out a packet queued on ps queue. When the ps queue |
| 1283 | * becomes empty update the PVB for this station. |
| 1284 | */ |
| 1285 | spin_lock_bh(&conn->psq_lock); |
| 1286 | psq_empty = skb_queue_empty(&conn->psq); |
| 1287 | spin_unlock_bh(&conn->psq_lock); |
| 1288 | |
| 1289 | if (psq_empty) |
| 1290 | /* TODO: Send out a NULL data frame */ |
| 1291 | return; |
| 1292 | |
| 1293 | spin_lock_bh(&conn->psq_lock); |
| 1294 | skb = skb_dequeue(&conn->psq); |
| 1295 | spin_unlock_bh(&conn->psq_lock); |
| 1296 | |
| 1297 | conn->sta_flags |= STA_PS_POLLED; |
| 1298 | ath6kl_data_tx(skb, ar->net_dev); |
| 1299 | conn->sta_flags &= ~STA_PS_POLLED; |
| 1300 | |
| 1301 | spin_lock_bh(&conn->psq_lock); |
| 1302 | psq_empty = skb_queue_empty(&conn->psq); |
| 1303 | spin_unlock_bh(&conn->psq_lock); |
| 1304 | |
| 1305 | if (psq_empty) |
| 1306 | ath6kl_wmi_set_pvb_cmd(ar->wmi, conn->aid, 0); |
| 1307 | } |
| 1308 | |
| 1309 | void ath6kl_dtimexpiry_event(struct ath6kl *ar) |
| 1310 | { |
| 1311 | bool mcastq_empty = false; |
| 1312 | struct sk_buff *skb; |
| 1313 | |
| 1314 | /* |
| 1315 | * If there are no associated STAs, ignore the DTIM expiry event. |
| 1316 | * There can be potential race conditions where the last associated |
| 1317 | * STA may disconnect & before the host could clear the 'Indicate |
| 1318 | * DTIM' request to the firmware, the firmware would have just |
| 1319 | * indicated a DTIM expiry event. The race is between 'clear DTIM |
| 1320 | * expiry cmd' going from the host to the firmware & the DTIM |
| 1321 | * expiry event happening from the firmware to the host. |
| 1322 | */ |
| 1323 | if (!ar->sta_list_index) |
| 1324 | return; |
| 1325 | |
| 1326 | spin_lock_bh(&ar->mcastpsq_lock); |
| 1327 | mcastq_empty = skb_queue_empty(&ar->mcastpsq); |
| 1328 | spin_unlock_bh(&ar->mcastpsq_lock); |
| 1329 | |
| 1330 | if (mcastq_empty) |
| 1331 | return; |
| 1332 | |
| 1333 | /* set the STA flag to dtim_expired for the frame to go out */ |
| 1334 | set_bit(DTIM_EXPIRED, &ar->flag); |
| 1335 | |
| 1336 | spin_lock_bh(&ar->mcastpsq_lock); |
| 1337 | while ((skb = skb_dequeue(&ar->mcastpsq)) != NULL) { |
| 1338 | spin_unlock_bh(&ar->mcastpsq_lock); |
| 1339 | |
| 1340 | ath6kl_data_tx(skb, ar->net_dev); |
| 1341 | |
| 1342 | spin_lock_bh(&ar->mcastpsq_lock); |
| 1343 | } |
| 1344 | spin_unlock_bh(&ar->mcastpsq_lock); |
| 1345 | |
| 1346 | clear_bit(DTIM_EXPIRED, &ar->flag); |
| 1347 | |
| 1348 | /* clear the LSB of the BitMapCtl field of the TIM IE */ |
| 1349 | ath6kl_wmi_set_pvb_cmd(ar->wmi, MCAST_AID, 0); |
| 1350 | } |
| 1351 | |
| 1352 | void ath6kl_disconnect_event(struct ath6kl *ar, u8 reason, u8 *bssid, |
| 1353 | u8 assoc_resp_len, u8 *assoc_info, |
| 1354 | u16 prot_reason_status) |
| 1355 | { |
| 1356 | struct bss *wmi_ssid_node = NULL; |
| 1357 | unsigned long flags; |
| 1358 | |
| 1359 | if (ar->nw_type == AP_NETWORK) { |
| 1360 | if (!ath6kl_remove_sta(ar, bssid, prot_reason_status)) |
| 1361 | return; |
| 1362 | |
| 1363 | /* if no more associated STAs, empty the mcast PS q */ |
| 1364 | if (ar->sta_list_index == 0) { |
| 1365 | spin_lock_bh(&ar->mcastpsq_lock); |
| 1366 | skb_queue_purge(&ar->mcastpsq); |
| 1367 | spin_unlock_bh(&ar->mcastpsq_lock); |
| 1368 | |
| 1369 | /* clear the LSB of the TIM IE's BitMapCtl field */ |
| 1370 | if (test_bit(WMI_READY, &ar->flag)) |
| 1371 | ath6kl_wmi_set_pvb_cmd(ar->wmi, MCAST_AID, 0); |
| 1372 | } |
| 1373 | |
| 1374 | if (!is_broadcast_ether_addr(bssid)) { |
| 1375 | /* send event to application */ |
| 1376 | cfg80211_del_sta(ar->net_dev, bssid, GFP_KERNEL); |
| 1377 | } |
| 1378 | |
Edward Lu | a587526 | 2011-08-30 21:58:08 +0300 | [diff] [blame] | 1379 | if (memcmp(ar->net_dev->dev_addr, bssid, ETH_ALEN) == 0) |
| 1380 | clear_bit(CONNECTED, &ar->flag); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1381 | return; |
| 1382 | } |
| 1383 | |
| 1384 | ath6kl_cfg80211_disconnect_event(ar, reason, bssid, |
| 1385 | assoc_resp_len, assoc_info, |
| 1386 | prot_reason_status); |
| 1387 | |
| 1388 | aggr_reset_state(ar->aggr_cntxt); |
| 1389 | |
| 1390 | del_timer(&ar->disconnect_timer); |
| 1391 | |
| 1392 | ath6kl_dbg(ATH6KL_DBG_WLAN_CONNECT, |
| 1393 | "disconnect reason is %d\n", reason); |
| 1394 | |
| 1395 | /* |
| 1396 | * If the event is due to disconnect cmd from the host, only they |
| 1397 | * the target would stop trying to connect. Under any other |
| 1398 | * condition, target would keep trying to connect. |
| 1399 | */ |
| 1400 | if (reason == DISCONNECT_CMD) { |
| 1401 | if (!ar->usr_bss_filter && test_bit(WMI_READY, &ar->flag)) |
| 1402 | ath6kl_wmi_bssfilter_cmd(ar->wmi, NONE_BSS_FILTER, 0); |
| 1403 | } else { |
| 1404 | set_bit(CONNECT_PEND, &ar->flag); |
| 1405 | if (((reason == ASSOC_FAILED) && |
| 1406 | (prot_reason_status == 0x11)) || |
| 1407 | ((reason == ASSOC_FAILED) && (prot_reason_status == 0x0) |
| 1408 | && (ar->reconnect_flag == 1))) { |
| 1409 | set_bit(CONNECTED, &ar->flag); |
| 1410 | return; |
| 1411 | } |
| 1412 | } |
| 1413 | |
| 1414 | if ((reason == NO_NETWORK_AVAIL) && test_bit(WMI_READY, &ar->flag)) { |
| 1415 | ath6kl_wmi_node_free(ar->wmi, bssid); |
| 1416 | |
| 1417 | /* |
| 1418 | * In case any other same SSID nodes are present remove it, |
| 1419 | * since those nodes also not available now. |
| 1420 | */ |
| 1421 | do { |
| 1422 | /* |
| 1423 | * Find the nodes based on SSID and remove it |
| 1424 | * |
| 1425 | * Note: This case will not work out for |
| 1426 | * Hidden-SSID |
| 1427 | */ |
| 1428 | wmi_ssid_node = ath6kl_wmi_find_ssid_node(ar->wmi, |
| 1429 | ar->ssid, |
| 1430 | ar->ssid_len, |
| 1431 | false, |
| 1432 | true); |
| 1433 | |
| 1434 | if (wmi_ssid_node) |
| 1435 | ath6kl_wmi_node_free(ar->wmi, |
| 1436 | wmi_ssid_node->ni_macaddr); |
| 1437 | |
| 1438 | } while (wmi_ssid_node); |
| 1439 | } |
| 1440 | |
| 1441 | /* update connect & link status atomically */ |
| 1442 | spin_lock_irqsave(&ar->lock, flags); |
| 1443 | clear_bit(CONNECTED, &ar->flag); |
| 1444 | netif_carrier_off(ar->net_dev); |
| 1445 | spin_unlock_irqrestore(&ar->lock, flags); |
| 1446 | |
| 1447 | if ((reason != CSERV_DISCONNECT) || (ar->reconnect_flag != 1)) |
| 1448 | ar->reconnect_flag = 0; |
| 1449 | |
| 1450 | if (reason != CSERV_DISCONNECT) |
| 1451 | ar->user_key_ctrl = 0; |
| 1452 | |
| 1453 | netif_stop_queue(ar->net_dev); |
| 1454 | memset(ar->bssid, 0, sizeof(ar->bssid)); |
| 1455 | ar->bss_ch = 0; |
| 1456 | |
| 1457 | ath6kl_tx_data_cleanup(ar); |
| 1458 | } |
| 1459 | |
| 1460 | static int ath6kl_open(struct net_device *dev) |
| 1461 | { |
| 1462 | struct ath6kl *ar = ath6kl_priv(dev); |
| 1463 | unsigned long flags; |
| 1464 | |
| 1465 | spin_lock_irqsave(&ar->lock, flags); |
| 1466 | |
Raja Mani | 575b5f3 | 2011-07-19 19:27:33 +0530 | [diff] [blame] | 1467 | set_bit(WLAN_ENABLED, &ar->flag); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1468 | |
| 1469 | if (test_bit(CONNECTED, &ar->flag)) { |
| 1470 | netif_carrier_on(dev); |
| 1471 | netif_wake_queue(dev); |
| 1472 | } else |
| 1473 | netif_carrier_off(dev); |
| 1474 | |
| 1475 | spin_unlock_irqrestore(&ar->lock, flags); |
| 1476 | |
| 1477 | return 0; |
| 1478 | } |
| 1479 | |
| 1480 | static int ath6kl_close(struct net_device *dev) |
| 1481 | { |
| 1482 | struct ath6kl *ar = ath6kl_priv(dev); |
| 1483 | |
| 1484 | netif_stop_queue(dev); |
| 1485 | |
| 1486 | ath6kl_disconnect(ar); |
| 1487 | |
| 1488 | if (test_bit(WMI_READY, &ar->flag)) { |
| 1489 | if (ath6kl_wmi_scanparams_cmd(ar->wmi, 0xFFFF, 0, 0, 0, 0, 0, 0, |
| 1490 | 0, 0, 0)) |
| 1491 | return -EIO; |
| 1492 | |
Raja Mani | 575b5f3 | 2011-07-19 19:27:33 +0530 | [diff] [blame] | 1493 | clear_bit(WLAN_ENABLED, &ar->flag); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | ath6kl_cfg80211_scan_complete_event(ar, -ECANCELED); |
| 1497 | |
| 1498 | return 0; |
| 1499 | } |
| 1500 | |
| 1501 | static struct net_device_stats *ath6kl_get_stats(struct net_device *dev) |
| 1502 | { |
| 1503 | struct ath6kl *ar = ath6kl_priv(dev); |
| 1504 | |
| 1505 | return &ar->net_stats; |
| 1506 | } |
| 1507 | |
| 1508 | static struct net_device_ops ath6kl_netdev_ops = { |
| 1509 | .ndo_open = ath6kl_open, |
| 1510 | .ndo_stop = ath6kl_close, |
| 1511 | .ndo_start_xmit = ath6kl_data_tx, |
| 1512 | .ndo_get_stats = ath6kl_get_stats, |
| 1513 | }; |
| 1514 | |
| 1515 | void init_netdev(struct net_device *dev) |
| 1516 | { |
| 1517 | dev->netdev_ops = &ath6kl_netdev_ops; |
| 1518 | dev->watchdog_timeo = ATH6KL_TX_TIMEOUT; |
| 1519 | |
| 1520 | dev->needed_headroom = ETH_HLEN; |
| 1521 | dev->needed_headroom += sizeof(struct ath6kl_llc_snap_hdr) + |
| 1522 | sizeof(struct wmi_data_hdr) + HTC_HDR_LENGTH |
Vasanthakumar Thiagarajan | 1df94a8 | 2011-08-17 18:45:10 +0530 | [diff] [blame] | 1523 | + WMI_MAX_TX_META_SZ + ATH6KL_HTC_ALIGN_BYTES; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1524 | |
| 1525 | return; |
| 1526 | } |