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