0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0019
0020 #include "core.h"
0021 #include "hif-ops.h"
0022 #include "cfg80211.h"
0023 #include "target.h"
0024 #include "debug.h"
0025
0026 struct ath6kl_sta *ath6kl_find_sta(struct ath6kl_vif *vif, u8 *node_addr)
0027 {
0028 struct ath6kl *ar = vif->ar;
0029 struct ath6kl_sta *conn = NULL;
0030 u8 i, max_conn;
0031
0032 if (is_zero_ether_addr(node_addr))
0033 return NULL;
0034
0035 max_conn = (vif->nw_type == AP_NETWORK) ? AP_MAX_NUM_STA : 0;
0036
0037 for (i = 0; i < max_conn; i++) {
0038 if (memcmp(node_addr, ar->sta_list[i].mac, ETH_ALEN) == 0) {
0039 conn = &ar->sta_list[i];
0040 break;
0041 }
0042 }
0043
0044 return conn;
0045 }
0046
0047 struct ath6kl_sta *ath6kl_find_sta_by_aid(struct ath6kl *ar, u8 aid)
0048 {
0049 struct ath6kl_sta *conn = NULL;
0050 u8 ctr;
0051
0052 for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
0053 if (ar->sta_list[ctr].aid == aid) {
0054 conn = &ar->sta_list[ctr];
0055 break;
0056 }
0057 }
0058 return conn;
0059 }
0060
0061 static void ath6kl_add_new_sta(struct ath6kl_vif *vif, u8 *mac, u16 aid,
0062 u8 *wpaie, size_t ielen, u8 keymgmt,
0063 u8 ucipher, u8 auth, u8 apsd_info)
0064 {
0065 struct ath6kl *ar = vif->ar;
0066 struct ath6kl_sta *sta;
0067 u8 free_slot;
0068
0069 free_slot = aid - 1;
0070
0071 sta = &ar->sta_list[free_slot];
0072 memcpy(sta->mac, mac, ETH_ALEN);
0073 if (ielen <= ATH6KL_MAX_IE)
0074 memcpy(sta->wpa_ie, wpaie, ielen);
0075 sta->aid = aid;
0076 sta->keymgmt = keymgmt;
0077 sta->ucipher = ucipher;
0078 sta->auth = auth;
0079 sta->apsd_info = apsd_info;
0080
0081 ar->sta_list_index = ar->sta_list_index | (1 << free_slot);
0082 ar->ap_stats.sta[free_slot].aid = cpu_to_le32(aid);
0083 aggr_conn_init(vif, vif->aggr_cntxt, sta->aggr_conn);
0084 }
0085
0086 static void ath6kl_sta_cleanup(struct ath6kl *ar, u8 i)
0087 {
0088 struct ath6kl_sta *sta = &ar->sta_list[i];
0089 struct ath6kl_mgmt_buff *entry, *tmp;
0090
0091
0092 spin_lock_bh(&sta->psq_lock);
0093 skb_queue_purge(&sta->psq);
0094 skb_queue_purge(&sta->apsdq);
0095
0096 if (sta->mgmt_psq_len != 0) {
0097 list_for_each_entry_safe(entry, tmp, &sta->mgmt_psq, list) {
0098 kfree(entry);
0099 }
0100 INIT_LIST_HEAD(&sta->mgmt_psq);
0101 sta->mgmt_psq_len = 0;
0102 }
0103
0104 spin_unlock_bh(&sta->psq_lock);
0105
0106 memset(&ar->ap_stats.sta[sta->aid - 1], 0,
0107 sizeof(struct wmi_per_sta_stat));
0108 eth_zero_addr(sta->mac);
0109 memset(sta->wpa_ie, 0, ATH6KL_MAX_IE);
0110 sta->aid = 0;
0111 sta->sta_flags = 0;
0112
0113 ar->sta_list_index = ar->sta_list_index & ~(1 << i);
0114 aggr_reset_state(sta->aggr_conn);
0115 }
0116
0117 static u8 ath6kl_remove_sta(struct ath6kl *ar, u8 *mac, u16 reason)
0118 {
0119 u8 i, removed = 0;
0120
0121 if (is_zero_ether_addr(mac))
0122 return removed;
0123
0124 if (is_broadcast_ether_addr(mac)) {
0125 ath6kl_dbg(ATH6KL_DBG_TRC, "deleting all station\n");
0126
0127 for (i = 0; i < AP_MAX_NUM_STA; i++) {
0128 if (!is_zero_ether_addr(ar->sta_list[i].mac)) {
0129 ath6kl_sta_cleanup(ar, i);
0130 removed = 1;
0131 }
0132 }
0133 } else {
0134 for (i = 0; i < AP_MAX_NUM_STA; i++) {
0135 if (memcmp(ar->sta_list[i].mac, mac, ETH_ALEN) == 0) {
0136 ath6kl_dbg(ATH6KL_DBG_TRC,
0137 "deleting station %pM aid=%d reason=%d\n",
0138 mac, ar->sta_list[i].aid, reason);
0139 ath6kl_sta_cleanup(ar, i);
0140 removed = 1;
0141 break;
0142 }
0143 }
0144 }
0145
0146 return removed;
0147 }
0148
0149 enum htc_endpoint_id ath6kl_ac2_endpoint_id(void *devt, u8 ac)
0150 {
0151 struct ath6kl *ar = devt;
0152 return ar->ac2ep_map[ac];
0153 }
0154
0155 struct ath6kl_cookie *ath6kl_alloc_cookie(struct ath6kl *ar)
0156 {
0157 struct ath6kl_cookie *cookie;
0158
0159 cookie = ar->cookie_list;
0160 if (cookie != NULL) {
0161 ar->cookie_list = cookie->arc_list_next;
0162 ar->cookie_count--;
0163 }
0164
0165 return cookie;
0166 }
0167
0168 void ath6kl_cookie_init(struct ath6kl *ar)
0169 {
0170 u32 i;
0171
0172 ar->cookie_list = NULL;
0173 ar->cookie_count = 0;
0174
0175 memset(ar->cookie_mem, 0, sizeof(ar->cookie_mem));
0176
0177 for (i = 0; i < MAX_COOKIE_NUM; i++)
0178 ath6kl_free_cookie(ar, &ar->cookie_mem[i]);
0179 }
0180
0181 void ath6kl_cookie_cleanup(struct ath6kl *ar)
0182 {
0183 ar->cookie_list = NULL;
0184 ar->cookie_count = 0;
0185 }
0186
0187 void ath6kl_free_cookie(struct ath6kl *ar, struct ath6kl_cookie *cookie)
0188 {
0189
0190
0191 if (!ar || !cookie)
0192 return;
0193
0194 cookie->arc_list_next = ar->cookie_list;
0195 ar->cookie_list = cookie;
0196 ar->cookie_count++;
0197 }
0198
0199
0200
0201
0202
0203 int ath6kl_diag_read32(struct ath6kl *ar, u32 address, u32 *value)
0204 {
0205 int ret;
0206
0207 ret = ath6kl_hif_diag_read32(ar, address, value);
0208 if (ret) {
0209 ath6kl_warn("failed to read32 through diagnose window: %d\n",
0210 ret);
0211 return ret;
0212 }
0213
0214 return 0;
0215 }
0216
0217
0218
0219
0220
0221 int ath6kl_diag_write32(struct ath6kl *ar, u32 address, __le32 value)
0222 {
0223 int ret;
0224
0225 ret = ath6kl_hif_diag_write32(ar, address, value);
0226
0227 if (ret) {
0228 ath6kl_err("failed to write 0x%x during diagnose window to 0x%x\n",
0229 address, value);
0230 return ret;
0231 }
0232
0233 return 0;
0234 }
0235
0236 int ath6kl_diag_read(struct ath6kl *ar, u32 address, void *data, u32 length)
0237 {
0238 u32 count, *buf = data;
0239 int ret;
0240
0241 if (WARN_ON(length % 4))
0242 return -EINVAL;
0243
0244 for (count = 0; count < length / 4; count++, address += 4) {
0245 ret = ath6kl_diag_read32(ar, address, &buf[count]);
0246 if (ret)
0247 return ret;
0248 }
0249
0250 return 0;
0251 }
0252
0253 int ath6kl_diag_write(struct ath6kl *ar, u32 address, void *data, u32 length)
0254 {
0255 u32 count;
0256 __le32 *buf = data;
0257 int ret;
0258
0259 if (WARN_ON(length % 4))
0260 return -EINVAL;
0261
0262 for (count = 0; count < length / 4; count++, address += 4) {
0263 ret = ath6kl_diag_write32(ar, address, buf[count]);
0264 if (ret)
0265 return ret;
0266 }
0267
0268 return 0;
0269 }
0270
0271 int ath6kl_read_fwlogs(struct ath6kl *ar)
0272 {
0273 struct ath6kl_dbglog_hdr debug_hdr;
0274 struct ath6kl_dbglog_buf debug_buf;
0275 u32 address, length, firstbuf, debug_hdr_addr;
0276 int ret, loop;
0277 u8 *buf;
0278
0279 buf = kmalloc(ATH6KL_FWLOG_PAYLOAD_SIZE, GFP_KERNEL);
0280 if (!buf)
0281 return -ENOMEM;
0282
0283 address = TARG_VTOP(ar->target_type,
0284 ath6kl_get_hi_item_addr(ar,
0285 HI_ITEM(hi_dbglog_hdr)));
0286
0287 ret = ath6kl_diag_read32(ar, address, &debug_hdr_addr);
0288 if (ret)
0289 goto out;
0290
0291
0292 if (debug_hdr_addr == 0) {
0293 ath6kl_warn("Invalid address for debug_hdr_addr\n");
0294 ret = -EINVAL;
0295 goto out;
0296 }
0297
0298 address = TARG_VTOP(ar->target_type, debug_hdr_addr);
0299 ret = ath6kl_diag_read(ar, address, &debug_hdr, sizeof(debug_hdr));
0300 if (ret)
0301 goto out;
0302
0303 address = TARG_VTOP(ar->target_type,
0304 le32_to_cpu(debug_hdr.dbuf_addr));
0305 firstbuf = address;
0306 ret = ath6kl_diag_read(ar, address, &debug_buf, sizeof(debug_buf));
0307 if (ret)
0308 goto out;
0309
0310 loop = 100;
0311
0312 do {
0313 address = TARG_VTOP(ar->target_type,
0314 le32_to_cpu(debug_buf.buffer_addr));
0315 length = le32_to_cpu(debug_buf.length);
0316
0317 if (length != 0 && (le32_to_cpu(debug_buf.length) <=
0318 le32_to_cpu(debug_buf.bufsize))) {
0319 length = ALIGN(length, 4);
0320
0321 ret = ath6kl_diag_read(ar, address,
0322 buf, length);
0323 if (ret)
0324 goto out;
0325
0326 ath6kl_debug_fwlog_event(ar, buf, length);
0327 }
0328
0329 address = TARG_VTOP(ar->target_type,
0330 le32_to_cpu(debug_buf.next));
0331 ret = ath6kl_diag_read(ar, address, &debug_buf,
0332 sizeof(debug_buf));
0333 if (ret)
0334 goto out;
0335
0336 loop--;
0337
0338 if (WARN_ON(loop == 0)) {
0339 ret = -ETIMEDOUT;
0340 goto out;
0341 }
0342 } while (address != firstbuf);
0343
0344 out:
0345 kfree(buf);
0346
0347 return ret;
0348 }
0349
0350 static void ath6kl_install_static_wep_keys(struct ath6kl_vif *vif)
0351 {
0352 u8 index;
0353 u8 keyusage;
0354
0355 for (index = 0; index <= WMI_MAX_KEY_INDEX; index++) {
0356 if (vif->wep_key_list[index].key_len) {
0357 keyusage = GROUP_USAGE;
0358 if (index == vif->def_txkey_index)
0359 keyusage |= TX_USAGE;
0360
0361 ath6kl_wmi_addkey_cmd(vif->ar->wmi, vif->fw_vif_idx,
0362 index,
0363 WEP_CRYPT,
0364 keyusage,
0365 vif->wep_key_list[index].key_len,
0366 NULL, 0,
0367 vif->wep_key_list[index].key,
0368 KEY_OP_INIT_VAL, NULL,
0369 NO_SYNC_WMIFLAG);
0370 }
0371 }
0372 }
0373
0374 void ath6kl_connect_ap_mode_bss(struct ath6kl_vif *vif, u16 channel)
0375 {
0376 struct ath6kl *ar = vif->ar;
0377 struct ath6kl_req_key *ik;
0378 int res;
0379 u8 key_rsc[ATH6KL_KEY_SEQ_LEN];
0380
0381 ik = &ar->ap_mode_bkey;
0382
0383 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "AP mode started on %u MHz\n", channel);
0384
0385 switch (vif->auth_mode) {
0386 case NONE_AUTH:
0387 if (vif->prwise_crypto == WEP_CRYPT)
0388 ath6kl_install_static_wep_keys(vif);
0389 if (!ik->valid || ik->key_type != WAPI_CRYPT)
0390 break;
0391
0392 fallthrough;
0393 case WPA_PSK_AUTH:
0394 case WPA2_PSK_AUTH:
0395 case (WPA_PSK_AUTH | WPA2_PSK_AUTH):
0396 if (!ik->valid)
0397 break;
0398
0399 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
0400 "Delayed addkey for the initial group key for AP mode\n");
0401 memset(key_rsc, 0, sizeof(key_rsc));
0402 res = ath6kl_wmi_addkey_cmd(
0403 ar->wmi, vif->fw_vif_idx, ik->key_index, ik->key_type,
0404 GROUP_USAGE, ik->key_len, key_rsc, ATH6KL_KEY_SEQ_LEN,
0405 ik->key,
0406 KEY_OP_INIT_VAL, NULL, SYNC_BOTH_WMIFLAG);
0407 if (res) {
0408 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
0409 "Delayed addkey failed: %d\n", res);
0410 }
0411 break;
0412 }
0413
0414 if (ar->last_ch != channel)
0415
0416 ath6kl_cfg80211_ch_switch_notify(vif, channel, WMI_11G_HT20);
0417
0418 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx, NONE_BSS_FILTER, 0);
0419 set_bit(CONNECTED, &vif->flags);
0420 netif_carrier_on(vif->ndev);
0421 }
0422
0423 void ath6kl_connect_ap_mode_sta(struct ath6kl_vif *vif, u16 aid, u8 *mac_addr,
0424 u8 keymgmt, u8 ucipher, u8 auth,
0425 u8 assoc_req_len, u8 *assoc_info, u8 apsd_info)
0426 {
0427 u8 *ies = NULL, *wpa_ie = NULL, *pos;
0428 size_t ies_len = 0;
0429 struct station_info *sinfo;
0430
0431 ath6kl_dbg(ATH6KL_DBG_TRC, "new station %pM aid=%d\n", mac_addr, aid);
0432
0433 if (aid < 1 || aid > AP_MAX_NUM_STA)
0434 return;
0435
0436 if (assoc_req_len > sizeof(struct ieee80211_hdr_3addr)) {
0437 struct ieee80211_mgmt *mgmt =
0438 (struct ieee80211_mgmt *) assoc_info;
0439 if (ieee80211_is_assoc_req(mgmt->frame_control) &&
0440 assoc_req_len >= sizeof(struct ieee80211_hdr_3addr) +
0441 sizeof(mgmt->u.assoc_req)) {
0442 ies = mgmt->u.assoc_req.variable;
0443 ies_len = assoc_info + assoc_req_len - ies;
0444 } else if (ieee80211_is_reassoc_req(mgmt->frame_control) &&
0445 assoc_req_len >= sizeof(struct ieee80211_hdr_3addr)
0446 + sizeof(mgmt->u.reassoc_req)) {
0447 ies = mgmt->u.reassoc_req.variable;
0448 ies_len = assoc_info + assoc_req_len - ies;
0449 }
0450 }
0451
0452 pos = ies;
0453 while (pos && pos + 1 < ies + ies_len) {
0454 if (pos + 2 + pos[1] > ies + ies_len)
0455 break;
0456 if (pos[0] == WLAN_EID_RSN)
0457 wpa_ie = pos;
0458 else if (pos[0] == WLAN_EID_VENDOR_SPECIFIC &&
0459 pos[1] >= 4 &&
0460 pos[2] == 0x00 && pos[3] == 0x50 && pos[4] == 0xf2) {
0461 if (pos[5] == 0x01)
0462 wpa_ie = pos;
0463 else if (pos[5] == 0x04) {
0464 wpa_ie = pos;
0465 break;
0466 }
0467 } else if (pos[0] == 0x44 && wpa_ie == NULL) {
0468
0469
0470
0471
0472
0473
0474
0475
0476
0477 wpa_ie = pos;
0478 break;
0479 }
0480 pos += 2 + pos[1];
0481 }
0482
0483 ath6kl_add_new_sta(vif, mac_addr, aid, wpa_ie,
0484 wpa_ie ? 2 + wpa_ie[1] : 0,
0485 keymgmt, ucipher, auth, apsd_info);
0486
0487
0488 sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL);
0489 if (!sinfo)
0490 return;
0491
0492
0493
0494 sinfo->assoc_req_ies = ies;
0495 sinfo->assoc_req_ies_len = ies_len;
0496
0497 cfg80211_new_sta(vif->ndev, mac_addr, sinfo, GFP_KERNEL);
0498
0499 netif_wake_queue(vif->ndev);
0500
0501 kfree(sinfo);
0502 }
0503
0504 void disconnect_timer_handler(struct timer_list *t)
0505 {
0506 struct ath6kl_vif *vif = from_timer(vif, t, disconnect_timer);
0507
0508 ath6kl_init_profile_info(vif);
0509 ath6kl_disconnect(vif);
0510 }
0511
0512 void ath6kl_disconnect(struct ath6kl_vif *vif)
0513 {
0514 if (test_bit(CONNECTED, &vif->flags) ||
0515 test_bit(CONNECT_PEND, &vif->flags)) {
0516 ath6kl_wmi_disconnect_cmd(vif->ar->wmi, vif->fw_vif_idx);
0517
0518
0519
0520
0521
0522 clear_bit(CONNECT_PEND, &vif->flags);
0523 }
0524 }
0525
0526
0527
0528 void ath6kl_ready_event(void *devt, u8 *datap, u32 sw_ver, u32 abi_ver,
0529 enum wmi_phy_cap cap)
0530 {
0531 struct ath6kl *ar = devt;
0532
0533 memcpy(ar->mac_addr, datap, ETH_ALEN);
0534
0535 ath6kl_dbg(ATH6KL_DBG_BOOT,
0536 "ready event mac addr %pM sw_ver 0x%x abi_ver 0x%x cap 0x%x\n",
0537 ar->mac_addr, sw_ver, abi_ver, cap);
0538
0539 ar->version.wlan_ver = sw_ver;
0540 ar->version.abi_ver = abi_ver;
0541 ar->hw.cap = cap;
0542
0543 if (strlen(ar->wiphy->fw_version) == 0) {
0544 snprintf(ar->wiphy->fw_version,
0545 sizeof(ar->wiphy->fw_version),
0546 "%u.%u.%u.%u",
0547 (ar->version.wlan_ver & 0xf0000000) >> 28,
0548 (ar->version.wlan_ver & 0x0f000000) >> 24,
0549 (ar->version.wlan_ver & 0x00ff0000) >> 16,
0550 (ar->version.wlan_ver & 0x0000ffff));
0551 }
0552
0553
0554 set_bit(WMI_READY, &ar->flag);
0555 wake_up(&ar->event_wq);
0556 }
0557
0558 void ath6kl_scan_complete_evt(struct ath6kl_vif *vif, int status)
0559 {
0560 struct ath6kl *ar = vif->ar;
0561 bool aborted = false;
0562
0563 if (status != WMI_SCAN_STATUS_SUCCESS)
0564 aborted = true;
0565
0566 ath6kl_cfg80211_scan_complete_event(vif, aborted);
0567
0568 if (!ar->usr_bss_filter) {
0569 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
0570 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
0571 NONE_BSS_FILTER, 0);
0572 }
0573
0574 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "scan complete: %d\n", status);
0575 }
0576
0577 static int ath6kl_commit_ch_switch(struct ath6kl_vif *vif, u16 channel)
0578 {
0579 struct ath6kl *ar = vif->ar;
0580
0581 vif->profile.ch = cpu_to_le16(channel);
0582
0583 switch (vif->nw_type) {
0584 case AP_NETWORK:
0585
0586
0587
0588
0589 if (vif->rsn_capab &&
0590 test_bit(ATH6KL_FW_CAPABILITY_RSN_CAP_OVERRIDE,
0591 ar->fw_capabilities))
0592 ath6kl_wmi_set_ie_cmd(ar->wmi, vif->fw_vif_idx,
0593 WLAN_EID_RSN, WMI_RSN_IE_CAPB,
0594 (const u8 *) &vif->rsn_capab,
0595 sizeof(vif->rsn_capab));
0596
0597 return ath6kl_wmi_ap_profile_commit(ar->wmi, vif->fw_vif_idx,
0598 &vif->profile);
0599 default:
0600 ath6kl_err("won't switch channels nw_type=%d\n", vif->nw_type);
0601 return -ENOTSUPP;
0602 }
0603 }
0604
0605 static void ath6kl_check_ch_switch(struct ath6kl *ar, u16 channel)
0606 {
0607 struct ath6kl_vif *vif;
0608 int res = 0;
0609
0610 if (!ar->want_ch_switch)
0611 return;
0612
0613 spin_lock_bh(&ar->list_lock);
0614 list_for_each_entry(vif, &ar->vif_list, list) {
0615 if (ar->want_ch_switch & (1 << vif->fw_vif_idx))
0616 res = ath6kl_commit_ch_switch(vif, channel);
0617
0618
0619 ar->want_ch_switch &= ~(1 << vif->fw_vif_idx);
0620
0621 if (res)
0622 ath6kl_err("channel switch failed nw_type %d res %d\n",
0623 vif->nw_type, res);
0624 }
0625 spin_unlock_bh(&ar->list_lock);
0626 }
0627
0628 void ath6kl_connect_event(struct ath6kl_vif *vif, u16 channel, u8 *bssid,
0629 u16 listen_int, u16 beacon_int,
0630 enum network_type net_type, u8 beacon_ie_len,
0631 u8 assoc_req_len, u8 assoc_resp_len,
0632 u8 *assoc_info)
0633 {
0634 struct ath6kl *ar = vif->ar;
0635
0636 ath6kl_cfg80211_connect_event(vif, channel, bssid,
0637 listen_int, beacon_int,
0638 net_type, beacon_ie_len,
0639 assoc_req_len, assoc_resp_len,
0640 assoc_info);
0641
0642 memcpy(vif->bssid, bssid, sizeof(vif->bssid));
0643 vif->bss_ch = channel;
0644
0645 if (vif->nw_type == INFRA_NETWORK) {
0646 ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx,
0647 vif->listen_intvl_t, 0);
0648 ath6kl_check_ch_switch(ar, channel);
0649 }
0650
0651 netif_wake_queue(vif->ndev);
0652
0653
0654 spin_lock_bh(&vif->if_lock);
0655 set_bit(CONNECTED, &vif->flags);
0656 clear_bit(CONNECT_PEND, &vif->flags);
0657 netif_carrier_on(vif->ndev);
0658 spin_unlock_bh(&vif->if_lock);
0659
0660 aggr_reset_state(vif->aggr_cntxt->aggr_conn);
0661 vif->reconnect_flag = 0;
0662
0663 if ((vif->nw_type == ADHOC_NETWORK) && ar->ibss_ps_enable) {
0664 memset(ar->node_map, 0, sizeof(ar->node_map));
0665 ar->node_num = 0;
0666 ar->next_ep_id = ENDPOINT_2;
0667 }
0668
0669 if (!ar->usr_bss_filter) {
0670 set_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
0671 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
0672 CURRENT_BSS_FILTER, 0);
0673 }
0674 }
0675
0676 void ath6kl_tkip_micerr_event(struct ath6kl_vif *vif, u8 keyid, bool ismcast)
0677 {
0678 struct ath6kl_sta *sta;
0679 struct ath6kl *ar = vif->ar;
0680 u8 tsc[6];
0681
0682
0683
0684
0685
0686 if (vif->nw_type == AP_NETWORK) {
0687 sta = ath6kl_find_sta_by_aid(ar, (keyid >> 2));
0688 if (!sta)
0689 return;
0690
0691 ath6kl_dbg(ATH6KL_DBG_TRC,
0692 "ap tkip mic error received from aid=%d\n", keyid);
0693
0694 memset(tsc, 0, sizeof(tsc));
0695 cfg80211_michael_mic_failure(vif->ndev, sta->mac,
0696 NL80211_KEYTYPE_PAIRWISE, keyid,
0697 tsc, GFP_KERNEL);
0698 } else {
0699 ath6kl_cfg80211_tkip_micerr_event(vif, keyid, ismcast);
0700 }
0701 }
0702
0703 static void ath6kl_update_target_stats(struct ath6kl_vif *vif, u8 *ptr, u32 len)
0704 {
0705 struct wmi_target_stats *tgt_stats =
0706 (struct wmi_target_stats *) ptr;
0707 struct ath6kl *ar = vif->ar;
0708 struct target_stats *stats = &vif->target_stats;
0709 struct tkip_ccmp_stats *ccmp_stats;
0710 s32 rate;
0711 u8 ac;
0712
0713 if (len < sizeof(*tgt_stats))
0714 return;
0715
0716 ath6kl_dbg(ATH6KL_DBG_TRC, "updating target stats\n");
0717
0718 stats->tx_pkt += le32_to_cpu(tgt_stats->stats.tx.pkt);
0719 stats->tx_byte += le32_to_cpu(tgt_stats->stats.tx.byte);
0720 stats->tx_ucast_pkt += le32_to_cpu(tgt_stats->stats.tx.ucast_pkt);
0721 stats->tx_ucast_byte += le32_to_cpu(tgt_stats->stats.tx.ucast_byte);
0722 stats->tx_mcast_pkt += le32_to_cpu(tgt_stats->stats.tx.mcast_pkt);
0723 stats->tx_mcast_byte += le32_to_cpu(tgt_stats->stats.tx.mcast_byte);
0724 stats->tx_bcast_pkt += le32_to_cpu(tgt_stats->stats.tx.bcast_pkt);
0725 stats->tx_bcast_byte += le32_to_cpu(tgt_stats->stats.tx.bcast_byte);
0726 stats->tx_rts_success_cnt +=
0727 le32_to_cpu(tgt_stats->stats.tx.rts_success_cnt);
0728
0729 for (ac = 0; ac < WMM_NUM_AC; ac++)
0730 stats->tx_pkt_per_ac[ac] +=
0731 le32_to_cpu(tgt_stats->stats.tx.pkt_per_ac[ac]);
0732
0733 stats->tx_err += le32_to_cpu(tgt_stats->stats.tx.err);
0734 stats->tx_fail_cnt += le32_to_cpu(tgt_stats->stats.tx.fail_cnt);
0735 stats->tx_retry_cnt += le32_to_cpu(tgt_stats->stats.tx.retry_cnt);
0736 stats->tx_mult_retry_cnt +=
0737 le32_to_cpu(tgt_stats->stats.tx.mult_retry_cnt);
0738 stats->tx_rts_fail_cnt +=
0739 le32_to_cpu(tgt_stats->stats.tx.rts_fail_cnt);
0740
0741 rate = a_sle32_to_cpu(tgt_stats->stats.tx.ucast_rate);
0742 stats->tx_ucast_rate = ath6kl_wmi_get_rate(ar->wmi, rate);
0743
0744 stats->rx_pkt += le32_to_cpu(tgt_stats->stats.rx.pkt);
0745 stats->rx_byte += le32_to_cpu(tgt_stats->stats.rx.byte);
0746 stats->rx_ucast_pkt += le32_to_cpu(tgt_stats->stats.rx.ucast_pkt);
0747 stats->rx_ucast_byte += le32_to_cpu(tgt_stats->stats.rx.ucast_byte);
0748 stats->rx_mcast_pkt += le32_to_cpu(tgt_stats->stats.rx.mcast_pkt);
0749 stats->rx_mcast_byte += le32_to_cpu(tgt_stats->stats.rx.mcast_byte);
0750 stats->rx_bcast_pkt += le32_to_cpu(tgt_stats->stats.rx.bcast_pkt);
0751 stats->rx_bcast_byte += le32_to_cpu(tgt_stats->stats.rx.bcast_byte);
0752 stats->rx_frgment_pkt += le32_to_cpu(tgt_stats->stats.rx.frgment_pkt);
0753 stats->rx_err += le32_to_cpu(tgt_stats->stats.rx.err);
0754 stats->rx_crc_err += le32_to_cpu(tgt_stats->stats.rx.crc_err);
0755 stats->rx_key_cache_miss +=
0756 le32_to_cpu(tgt_stats->stats.rx.key_cache_miss);
0757 stats->rx_decrypt_err += le32_to_cpu(tgt_stats->stats.rx.decrypt_err);
0758 stats->rx_dupl_frame += le32_to_cpu(tgt_stats->stats.rx.dupl_frame);
0759
0760 rate = a_sle32_to_cpu(tgt_stats->stats.rx.ucast_rate);
0761 stats->rx_ucast_rate = ath6kl_wmi_get_rate(ar->wmi, rate);
0762
0763 ccmp_stats = &tgt_stats->stats.tkip_ccmp_stats;
0764
0765 stats->tkip_local_mic_fail +=
0766 le32_to_cpu(ccmp_stats->tkip_local_mic_fail);
0767 stats->tkip_cnter_measures_invoked +=
0768 le32_to_cpu(ccmp_stats->tkip_cnter_measures_invoked);
0769 stats->tkip_fmt_err += le32_to_cpu(ccmp_stats->tkip_fmt_err);
0770
0771 stats->ccmp_fmt_err += le32_to_cpu(ccmp_stats->ccmp_fmt_err);
0772 stats->ccmp_replays += le32_to_cpu(ccmp_stats->ccmp_replays);
0773
0774 stats->pwr_save_fail_cnt +=
0775 le32_to_cpu(tgt_stats->pm_stats.pwr_save_failure_cnt);
0776 stats->noise_floor_calib =
0777 a_sle32_to_cpu(tgt_stats->noise_floor_calib);
0778
0779 stats->cs_bmiss_cnt +=
0780 le32_to_cpu(tgt_stats->cserv_stats.cs_bmiss_cnt);
0781 stats->cs_low_rssi_cnt +=
0782 le32_to_cpu(tgt_stats->cserv_stats.cs_low_rssi_cnt);
0783 stats->cs_connect_cnt +=
0784 le16_to_cpu(tgt_stats->cserv_stats.cs_connect_cnt);
0785 stats->cs_discon_cnt +=
0786 le16_to_cpu(tgt_stats->cserv_stats.cs_discon_cnt);
0787
0788 stats->cs_ave_beacon_rssi =
0789 a_sle16_to_cpu(tgt_stats->cserv_stats.cs_ave_beacon_rssi);
0790
0791 stats->cs_last_roam_msec =
0792 tgt_stats->cserv_stats.cs_last_roam_msec;
0793 stats->cs_snr = tgt_stats->cserv_stats.cs_snr;
0794 stats->cs_rssi = a_sle16_to_cpu(tgt_stats->cserv_stats.cs_rssi);
0795
0796 stats->lq_val = le32_to_cpu(tgt_stats->lq_val);
0797
0798 stats->wow_pkt_dropped +=
0799 le32_to_cpu(tgt_stats->wow_stats.wow_pkt_dropped);
0800 stats->wow_host_pkt_wakeups +=
0801 tgt_stats->wow_stats.wow_host_pkt_wakeups;
0802 stats->wow_host_evt_wakeups +=
0803 tgt_stats->wow_stats.wow_host_evt_wakeups;
0804 stats->wow_evt_discarded +=
0805 le16_to_cpu(tgt_stats->wow_stats.wow_evt_discarded);
0806
0807 stats->arp_received = le32_to_cpu(tgt_stats->arp_stats.arp_received);
0808 stats->arp_replied = le32_to_cpu(tgt_stats->arp_stats.arp_replied);
0809 stats->arp_matched = le32_to_cpu(tgt_stats->arp_stats.arp_matched);
0810
0811 if (test_bit(STATS_UPDATE_PEND, &vif->flags)) {
0812 clear_bit(STATS_UPDATE_PEND, &vif->flags);
0813 wake_up(&ar->event_wq);
0814 }
0815 }
0816
0817 static void ath6kl_add_le32(__le32 *var, __le32 val)
0818 {
0819 *var = cpu_to_le32(le32_to_cpu(*var) + le32_to_cpu(val));
0820 }
0821
0822 void ath6kl_tgt_stats_event(struct ath6kl_vif *vif, u8 *ptr, u32 len)
0823 {
0824 struct wmi_ap_mode_stat *p = (struct wmi_ap_mode_stat *) ptr;
0825 struct ath6kl *ar = vif->ar;
0826 struct wmi_ap_mode_stat *ap = &ar->ap_stats;
0827 struct wmi_per_sta_stat *st_ap, *st_p;
0828 u8 ac;
0829
0830 if (vif->nw_type == AP_NETWORK) {
0831 if (len < sizeof(*p))
0832 return;
0833
0834 for (ac = 0; ac < AP_MAX_NUM_STA; ac++) {
0835 st_ap = &ap->sta[ac];
0836 st_p = &p->sta[ac];
0837
0838 ath6kl_add_le32(&st_ap->tx_bytes, st_p->tx_bytes);
0839 ath6kl_add_le32(&st_ap->tx_pkts, st_p->tx_pkts);
0840 ath6kl_add_le32(&st_ap->tx_error, st_p->tx_error);
0841 ath6kl_add_le32(&st_ap->tx_discard, st_p->tx_discard);
0842 ath6kl_add_le32(&st_ap->rx_bytes, st_p->rx_bytes);
0843 ath6kl_add_le32(&st_ap->rx_pkts, st_p->rx_pkts);
0844 ath6kl_add_le32(&st_ap->rx_error, st_p->rx_error);
0845 ath6kl_add_le32(&st_ap->rx_discard, st_p->rx_discard);
0846 }
0847
0848 } else {
0849 ath6kl_update_target_stats(vif, ptr, len);
0850 }
0851 }
0852
0853 void ath6kl_wakeup_event(void *dev)
0854 {
0855 struct ath6kl *ar = (struct ath6kl *) dev;
0856
0857 wake_up(&ar->event_wq);
0858 }
0859
0860 void ath6kl_txpwr_rx_evt(void *devt, u8 tx_pwr)
0861 {
0862 struct ath6kl *ar = (struct ath6kl *) devt;
0863
0864 ar->tx_pwr = tx_pwr;
0865 wake_up(&ar->event_wq);
0866 }
0867
0868 void ath6kl_pspoll_event(struct ath6kl_vif *vif, u8 aid)
0869 {
0870 struct ath6kl_sta *conn;
0871 struct sk_buff *skb;
0872 bool psq_empty = false;
0873 struct ath6kl *ar = vif->ar;
0874 struct ath6kl_mgmt_buff *mgmt_buf;
0875
0876 conn = ath6kl_find_sta_by_aid(ar, aid);
0877
0878 if (!conn)
0879 return;
0880
0881
0882
0883
0884 spin_lock_bh(&conn->psq_lock);
0885 psq_empty = skb_queue_empty(&conn->psq) && (conn->mgmt_psq_len == 0);
0886 spin_unlock_bh(&conn->psq_lock);
0887
0888 if (psq_empty)
0889
0890 return;
0891
0892 spin_lock_bh(&conn->psq_lock);
0893 if (conn->mgmt_psq_len > 0) {
0894 mgmt_buf = list_first_entry(&conn->mgmt_psq,
0895 struct ath6kl_mgmt_buff, list);
0896 list_del(&mgmt_buf->list);
0897 conn->mgmt_psq_len--;
0898 spin_unlock_bh(&conn->psq_lock);
0899
0900 conn->sta_flags |= STA_PS_POLLED;
0901 ath6kl_wmi_send_mgmt_cmd(ar->wmi, vif->fw_vif_idx,
0902 mgmt_buf->id, mgmt_buf->freq,
0903 mgmt_buf->wait, mgmt_buf->buf,
0904 mgmt_buf->len, mgmt_buf->no_cck);
0905 conn->sta_flags &= ~STA_PS_POLLED;
0906 kfree(mgmt_buf);
0907 } else {
0908 skb = skb_dequeue(&conn->psq);
0909 spin_unlock_bh(&conn->psq_lock);
0910
0911 conn->sta_flags |= STA_PS_POLLED;
0912 ath6kl_data_tx(skb, vif->ndev);
0913 conn->sta_flags &= ~STA_PS_POLLED;
0914 }
0915
0916 spin_lock_bh(&conn->psq_lock);
0917 psq_empty = skb_queue_empty(&conn->psq) && (conn->mgmt_psq_len == 0);
0918 spin_unlock_bh(&conn->psq_lock);
0919
0920 if (psq_empty)
0921 ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx, conn->aid, 0);
0922 }
0923
0924 void ath6kl_dtimexpiry_event(struct ath6kl_vif *vif)
0925 {
0926 bool mcastq_empty = false;
0927 struct sk_buff *skb;
0928 struct ath6kl *ar = vif->ar;
0929
0930
0931
0932
0933
0934
0935
0936
0937
0938
0939 if (!ar->sta_list_index)
0940 return;
0941
0942 spin_lock_bh(&ar->mcastpsq_lock);
0943 mcastq_empty = skb_queue_empty(&ar->mcastpsq);
0944 spin_unlock_bh(&ar->mcastpsq_lock);
0945
0946 if (mcastq_empty)
0947 return;
0948
0949
0950 set_bit(DTIM_EXPIRED, &vif->flags);
0951
0952 spin_lock_bh(&ar->mcastpsq_lock);
0953 while ((skb = skb_dequeue(&ar->mcastpsq)) != NULL) {
0954 spin_unlock_bh(&ar->mcastpsq_lock);
0955
0956 ath6kl_data_tx(skb, vif->ndev);
0957
0958 spin_lock_bh(&ar->mcastpsq_lock);
0959 }
0960 spin_unlock_bh(&ar->mcastpsq_lock);
0961
0962 clear_bit(DTIM_EXPIRED, &vif->flags);
0963
0964
0965 ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx, MCAST_AID, 0);
0966 }
0967
0968 void ath6kl_disconnect_event(struct ath6kl_vif *vif, u8 reason, u8 *bssid,
0969 u8 assoc_resp_len, u8 *assoc_info,
0970 u16 prot_reason_status)
0971 {
0972 struct ath6kl *ar = vif->ar;
0973
0974 if (vif->nw_type == AP_NETWORK) {
0975
0976 if (reason == BSS_DISCONNECTED &&
0977 prot_reason_status == WMI_AP_REASON_STA_ROAM) {
0978 ar->want_ch_switch |= 1 << vif->fw_vif_idx;
0979
0980 ar->last_ch = le16_to_cpu(vif->profile.ch);
0981 }
0982
0983 if (prot_reason_status == WMI_AP_REASON_MAX_STA) {
0984
0985 cfg80211_conn_failed(vif->ndev, bssid,
0986 NL80211_CONN_FAIL_MAX_CLIENTS,
0987 GFP_KERNEL);
0988 }
0989
0990 if (prot_reason_status == WMI_AP_REASON_ACL) {
0991
0992 cfg80211_conn_failed(vif->ndev, bssid,
0993 NL80211_CONN_FAIL_BLOCKED_CLIENT,
0994 GFP_KERNEL);
0995 }
0996
0997 if (!ath6kl_remove_sta(ar, bssid, prot_reason_status))
0998 return;
0999
1000
1001 if (ar->sta_list_index == 0) {
1002 spin_lock_bh(&ar->mcastpsq_lock);
1003 skb_queue_purge(&ar->mcastpsq);
1004 spin_unlock_bh(&ar->mcastpsq_lock);
1005
1006
1007 if (test_bit(WMI_READY, &ar->flag))
1008 ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx,
1009 MCAST_AID, 0);
1010 }
1011
1012 if (!is_broadcast_ether_addr(bssid)) {
1013
1014 cfg80211_del_sta(vif->ndev, bssid, GFP_KERNEL);
1015 }
1016
1017 if (memcmp(vif->ndev->dev_addr, bssid, ETH_ALEN) == 0) {
1018 memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
1019 clear_bit(CONNECTED, &vif->flags);
1020 }
1021 return;
1022 }
1023
1024 ath6kl_cfg80211_disconnect_event(vif, reason, bssid,
1025 assoc_resp_len, assoc_info,
1026 prot_reason_status);
1027
1028 aggr_reset_state(vif->aggr_cntxt->aggr_conn);
1029
1030 del_timer(&vif->disconnect_timer);
1031
1032 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "disconnect reason is %d\n", reason);
1033
1034
1035
1036
1037
1038
1039 if (reason == DISCONNECT_CMD) {
1040 if (!ar->usr_bss_filter && test_bit(WMI_READY, &ar->flag))
1041 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
1042 NONE_BSS_FILTER, 0);
1043 } else {
1044 set_bit(CONNECT_PEND, &vif->flags);
1045 if (((reason == ASSOC_FAILED) &&
1046 (prot_reason_status == 0x11)) ||
1047 ((reason == ASSOC_FAILED) && (prot_reason_status == 0x0) &&
1048 (vif->reconnect_flag == 1))) {
1049 set_bit(CONNECTED, &vif->flags);
1050 return;
1051 }
1052 }
1053
1054
1055 ath6kl_check_ch_switch(ar, ar->last_ch);
1056
1057
1058 spin_lock_bh(&vif->if_lock);
1059 clear_bit(CONNECTED, &vif->flags);
1060 netif_carrier_off(vif->ndev);
1061 spin_unlock_bh(&vif->if_lock);
1062
1063 if ((reason != CSERV_DISCONNECT) || (vif->reconnect_flag != 1))
1064 vif->reconnect_flag = 0;
1065
1066 if (reason != CSERV_DISCONNECT)
1067 ar->user_key_ctrl = 0;
1068
1069 netif_stop_queue(vif->ndev);
1070 memset(vif->bssid, 0, sizeof(vif->bssid));
1071 vif->bss_ch = 0;
1072
1073 ath6kl_tx_data_cleanup(ar);
1074 }
1075
1076 struct ath6kl_vif *ath6kl_vif_first(struct ath6kl *ar)
1077 {
1078 struct ath6kl_vif *vif;
1079
1080 spin_lock_bh(&ar->list_lock);
1081 if (list_empty(&ar->vif_list)) {
1082 spin_unlock_bh(&ar->list_lock);
1083 return NULL;
1084 }
1085
1086 vif = list_first_entry(&ar->vif_list, struct ath6kl_vif, list);
1087
1088 spin_unlock_bh(&ar->list_lock);
1089
1090 return vif;
1091 }
1092
1093 static int ath6kl_open(struct net_device *dev)
1094 {
1095 struct ath6kl_vif *vif = netdev_priv(dev);
1096
1097 set_bit(WLAN_ENABLED, &vif->flags);
1098
1099 if (test_bit(CONNECTED, &vif->flags)) {
1100 netif_carrier_on(dev);
1101 netif_wake_queue(dev);
1102 } else {
1103 netif_carrier_off(dev);
1104 }
1105
1106 return 0;
1107 }
1108
1109 static int ath6kl_close(struct net_device *dev)
1110 {
1111 struct ath6kl_vif *vif = netdev_priv(dev);
1112
1113 netif_stop_queue(dev);
1114
1115 ath6kl_cfg80211_stop(vif);
1116
1117 clear_bit(WLAN_ENABLED, &vif->flags);
1118
1119 return 0;
1120 }
1121
1122 static int ath6kl_set_features(struct net_device *dev,
1123 netdev_features_t features)
1124 {
1125 struct ath6kl_vif *vif = netdev_priv(dev);
1126 struct ath6kl *ar = vif->ar;
1127 int err = 0;
1128
1129 if ((features & NETIF_F_RXCSUM) &&
1130 (ar->rx_meta_ver != WMI_META_VERSION_2)) {
1131 ar->rx_meta_ver = WMI_META_VERSION_2;
1132 err = ath6kl_wmi_set_rx_frame_format_cmd(ar->wmi,
1133 vif->fw_vif_idx,
1134 ar->rx_meta_ver, 0, 0);
1135 if (err) {
1136 dev->features = features & ~NETIF_F_RXCSUM;
1137 return err;
1138 }
1139 } else if (!(features & NETIF_F_RXCSUM) &&
1140 (ar->rx_meta_ver == WMI_META_VERSION_2)) {
1141 ar->rx_meta_ver = 0;
1142 err = ath6kl_wmi_set_rx_frame_format_cmd(ar->wmi,
1143 vif->fw_vif_idx,
1144 ar->rx_meta_ver, 0, 0);
1145 if (err) {
1146 dev->features = features | NETIF_F_RXCSUM;
1147 return err;
1148 }
1149 }
1150
1151 return err;
1152 }
1153
1154 static void ath6kl_set_multicast_list(struct net_device *ndev)
1155 {
1156 struct ath6kl_vif *vif = netdev_priv(ndev);
1157 bool mc_all_on = false;
1158 int mc_count = netdev_mc_count(ndev);
1159 struct netdev_hw_addr *ha;
1160 bool found;
1161 struct ath6kl_mc_filter *mc_filter, *tmp;
1162 struct list_head mc_filter_new;
1163 int ret;
1164
1165 if (!test_bit(WMI_READY, &vif->ar->flag) ||
1166 !test_bit(WLAN_ENABLED, &vif->flags))
1167 return;
1168
1169
1170 mc_all_on = !!(ndev->flags & IFF_PROMISC) ||
1171 !!(ndev->flags & IFF_ALLMULTI) ||
1172 !!(mc_count > ATH6K_MAX_MC_FILTERS_PER_LIST);
1173
1174 if (mc_all_on)
1175 set_bit(NETDEV_MCAST_ALL_ON, &vif->flags);
1176 else
1177 clear_bit(NETDEV_MCAST_ALL_ON, &vif->flags);
1178
1179 if (test_bit(ATH6KL_FW_CAPABILITY_WOW_MULTICAST_FILTER,
1180 vif->ar->fw_capabilities)) {
1181 mc_all_on = mc_all_on || (vif->ar->state == ATH6KL_STATE_ON);
1182 }
1183
1184 if (!(ndev->flags & IFF_MULTICAST)) {
1185 mc_all_on = false;
1186 set_bit(NETDEV_MCAST_ALL_OFF, &vif->flags);
1187 } else {
1188 clear_bit(NETDEV_MCAST_ALL_OFF, &vif->flags);
1189 }
1190
1191
1192 ath6kl_dbg(ATH6KL_DBG_TRC, "%s multicast-all filter\n",
1193 mc_all_on ? "enabling" : "disabling");
1194
1195 ret = ath6kl_wmi_mcast_filter_cmd(vif->ar->wmi, vif->fw_vif_idx,
1196 mc_all_on);
1197 if (ret) {
1198 ath6kl_warn("Failed to %s multicast-all receive\n",
1199 mc_all_on ? "enable" : "disable");
1200 return;
1201 }
1202
1203 if (test_bit(NETDEV_MCAST_ALL_ON, &vif->flags))
1204 return;
1205
1206
1207 list_for_each_entry_safe(mc_filter, tmp, &vif->mc_filter, list) {
1208 found = false;
1209 netdev_for_each_mc_addr(ha, ndev) {
1210 if (memcmp(ha->addr, mc_filter->hw_addr,
1211 ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE) == 0) {
1212 found = true;
1213 break;
1214 }
1215 }
1216
1217 if (!found) {
1218
1219
1220
1221
1222 ath6kl_dbg(ATH6KL_DBG_TRC,
1223 "Removing %pM from multicast filter\n",
1224 mc_filter->hw_addr);
1225 ret = ath6kl_wmi_add_del_mcast_filter_cmd(vif->ar->wmi,
1226 vif->fw_vif_idx, mc_filter->hw_addr,
1227 false);
1228 if (ret) {
1229 ath6kl_warn("Failed to remove multicast filter:%pM\n",
1230 mc_filter->hw_addr);
1231 return;
1232 }
1233
1234 list_del(&mc_filter->list);
1235 kfree(mc_filter);
1236 }
1237 }
1238
1239 INIT_LIST_HEAD(&mc_filter_new);
1240
1241 netdev_for_each_mc_addr(ha, ndev) {
1242 found = false;
1243 list_for_each_entry(mc_filter, &vif->mc_filter, list) {
1244 if (memcmp(ha->addr, mc_filter->hw_addr,
1245 ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE) == 0) {
1246 found = true;
1247 break;
1248 }
1249 }
1250
1251 if (!found) {
1252 mc_filter = kzalloc(sizeof(struct ath6kl_mc_filter),
1253 GFP_ATOMIC);
1254 if (!mc_filter) {
1255 WARN_ON(1);
1256 goto out;
1257 }
1258
1259 memcpy(mc_filter->hw_addr, ha->addr,
1260 ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE);
1261
1262 ath6kl_dbg(ATH6KL_DBG_TRC,
1263 "Adding %pM to multicast filter list\n",
1264 mc_filter->hw_addr);
1265 ret = ath6kl_wmi_add_del_mcast_filter_cmd(vif->ar->wmi,
1266 vif->fw_vif_idx, mc_filter->hw_addr,
1267 true);
1268 if (ret) {
1269 ath6kl_warn("Failed to add multicast filter :%pM\n",
1270 mc_filter->hw_addr);
1271 kfree(mc_filter);
1272 goto out;
1273 }
1274
1275 list_add_tail(&mc_filter->list, &mc_filter_new);
1276 }
1277 }
1278
1279 out:
1280 list_splice_tail(&mc_filter_new, &vif->mc_filter);
1281 }
1282
1283 static const struct net_device_ops ath6kl_netdev_ops = {
1284 .ndo_open = ath6kl_open,
1285 .ndo_stop = ath6kl_close,
1286 .ndo_start_xmit = ath6kl_data_tx,
1287 .ndo_set_features = ath6kl_set_features,
1288 .ndo_set_rx_mode = ath6kl_set_multicast_list,
1289 };
1290
1291 void init_netdev(struct net_device *dev)
1292 {
1293 struct ath6kl *ar = ath6kl_priv(dev);
1294
1295 dev->netdev_ops = &ath6kl_netdev_ops;
1296 dev->needs_free_netdev = true;
1297 dev->watchdog_timeo = ATH6KL_TX_TIMEOUT;
1298
1299 dev->needed_headroom = ETH_HLEN;
1300 dev->needed_headroom += roundup(sizeof(struct ath6kl_llc_snap_hdr) +
1301 sizeof(struct wmi_data_hdr) +
1302 HTC_HDR_LENGTH +
1303 WMI_MAX_TX_META_SZ +
1304 ATH6KL_HTC_ALIGN_BYTES, 4);
1305
1306 if (!test_bit(ATH6KL_FW_CAPABILITY_NO_IP_CHECKSUM,
1307 ar->fw_capabilities))
1308 dev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_RXCSUM;
1309
1310 return;
1311 }