main.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  1. /*
  2. * Copyright (c) 2004-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include "core.h"
  18. #include "hif-ops.h"
  19. #include "cfg80211.h"
  20. #include "target.h"
  21. #include "debug.h"
  22. struct ath6kl_sta *ath6kl_find_sta(struct ath6kl_vif *vif, u8 *node_addr)
  23. {
  24. struct ath6kl *ar = vif->ar;
  25. struct ath6kl_sta *conn = NULL;
  26. u8 i, max_conn;
  27. max_conn = (vif->nw_type == AP_NETWORK) ? AP_MAX_NUM_STA : 0;
  28. for (i = 0; i < max_conn; i++) {
  29. if (memcmp(node_addr, ar->sta_list[i].mac, ETH_ALEN) == 0) {
  30. conn = &ar->sta_list[i];
  31. break;
  32. }
  33. }
  34. return conn;
  35. }
  36. struct ath6kl_sta *ath6kl_find_sta_by_aid(struct ath6kl *ar, u8 aid)
  37. {
  38. struct ath6kl_sta *conn = NULL;
  39. u8 ctr;
  40. for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
  41. if (ar->sta_list[ctr].aid == aid) {
  42. conn = &ar->sta_list[ctr];
  43. break;
  44. }
  45. }
  46. return conn;
  47. }
  48. static void ath6kl_add_new_sta(struct ath6kl_vif *vif, u8 *mac, u16 aid,
  49. u8 *wpaie, size_t ielen, u8 keymgmt,
  50. u8 ucipher, u8 auth, u8 apsd_info)
  51. {
  52. struct ath6kl *ar = vif->ar;
  53. struct ath6kl_sta *sta;
  54. u8 free_slot;
  55. free_slot = aid - 1;
  56. sta = &ar->sta_list[free_slot];
  57. memcpy(sta->mac, mac, ETH_ALEN);
  58. if (ielen <= ATH6KL_MAX_IE)
  59. memcpy(sta->wpa_ie, wpaie, ielen);
  60. sta->aid = aid;
  61. sta->keymgmt = keymgmt;
  62. sta->ucipher = ucipher;
  63. sta->auth = auth;
  64. sta->apsd_info = apsd_info;
  65. ar->sta_list_index = ar->sta_list_index | (1 << free_slot);
  66. ar->ap_stats.sta[free_slot].aid = cpu_to_le32(aid);
  67. aggr_conn_init(vif, vif->aggr_cntxt, sta->aggr_conn);
  68. }
  69. static void ath6kl_sta_cleanup(struct ath6kl *ar, u8 i)
  70. {
  71. struct ath6kl_sta *sta = &ar->sta_list[i];
  72. struct ath6kl_mgmt_buff *entry, *tmp;
  73. /* empty the queued pkts in the PS queue if any */
  74. spin_lock_bh(&sta->psq_lock);
  75. skb_queue_purge(&sta->psq);
  76. skb_queue_purge(&sta->apsdq);
  77. if (sta->mgmt_psq_len != 0) {
  78. list_for_each_entry_safe(entry, tmp, &sta->mgmt_psq, list) {
  79. kfree(entry);
  80. }
  81. INIT_LIST_HEAD(&sta->mgmt_psq);
  82. sta->mgmt_psq_len = 0;
  83. }
  84. spin_unlock_bh(&sta->psq_lock);
  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. ar->sta_list_index = ar->sta_list_index & ~(1 << i);
  92. aggr_reset_state(sta->aggr_conn);
  93. }
  94. static u8 ath6kl_remove_sta(struct ath6kl *ar, u8 *mac, u16 reason)
  95. {
  96. u8 i, removed = 0;
  97. if (is_zero_ether_addr(mac))
  98. return removed;
  99. if (is_broadcast_ether_addr(mac)) {
  100. ath6kl_dbg(ATH6KL_DBG_TRC, "deleting all station\n");
  101. for (i = 0; i < AP_MAX_NUM_STA; i++) {
  102. if (!is_zero_ether_addr(ar->sta_list[i].mac)) {
  103. ath6kl_sta_cleanup(ar, i);
  104. removed = 1;
  105. }
  106. }
  107. } else {
  108. for (i = 0; i < AP_MAX_NUM_STA; i++) {
  109. if (memcmp(ar->sta_list[i].mac, mac, ETH_ALEN) == 0) {
  110. ath6kl_dbg(ATH6KL_DBG_TRC,
  111. "deleting station %pM aid=%d reason=%d\n",
  112. mac, ar->sta_list[i].aid, reason);
  113. ath6kl_sta_cleanup(ar, i);
  114. removed = 1;
  115. break;
  116. }
  117. }
  118. }
  119. return removed;
  120. }
  121. enum htc_endpoint_id ath6kl_ac2_endpoint_id(void *devt, u8 ac)
  122. {
  123. struct ath6kl *ar = devt;
  124. return ar->ac2ep_map[ac];
  125. }
  126. struct ath6kl_cookie *ath6kl_alloc_cookie(struct ath6kl *ar)
  127. {
  128. struct ath6kl_cookie *cookie;
  129. cookie = ar->cookie_list;
  130. if (cookie != NULL) {
  131. ar->cookie_list = cookie->arc_list_next;
  132. ar->cookie_count--;
  133. }
  134. return cookie;
  135. }
  136. void ath6kl_cookie_init(struct ath6kl *ar)
  137. {
  138. u32 i;
  139. ar->cookie_list = NULL;
  140. ar->cookie_count = 0;
  141. memset(ar->cookie_mem, 0, sizeof(ar->cookie_mem));
  142. for (i = 0; i < MAX_COOKIE_NUM; i++)
  143. ath6kl_free_cookie(ar, &ar->cookie_mem[i]);
  144. }
  145. void ath6kl_cookie_cleanup(struct ath6kl *ar)
  146. {
  147. ar->cookie_list = NULL;
  148. ar->cookie_count = 0;
  149. }
  150. void ath6kl_free_cookie(struct ath6kl *ar, struct ath6kl_cookie *cookie)
  151. {
  152. /* Insert first */
  153. if (!ar || !cookie)
  154. return;
  155. cookie->arc_list_next = ar->cookie_list;
  156. ar->cookie_list = cookie;
  157. ar->cookie_count++;
  158. }
  159. /*
  160. * Read from the hardware through its diagnostic window. No cooperation
  161. * from the firmware is required for this.
  162. */
  163. int ath6kl_diag_read32(struct ath6kl *ar, u32 address, u32 *value)
  164. {
  165. int ret;
  166. ret = ath6kl_hif_diag_read32(ar, address, value);
  167. if (ret) {
  168. ath6kl_warn("failed to read32 through diagnose window: %d\n",
  169. ret);
  170. return ret;
  171. }
  172. return 0;
  173. }
  174. /*
  175. * Write to the ATH6KL through its diagnostic window. No cooperation from
  176. * the Target is required for this.
  177. */
  178. int ath6kl_diag_write32(struct ath6kl *ar, u32 address, __le32 value)
  179. {
  180. int ret;
  181. ret = ath6kl_hif_diag_write32(ar, address, value);
  182. if (ret) {
  183. ath6kl_err("failed to write 0x%x during diagnose window to 0x%d\n",
  184. address, value);
  185. return ret;
  186. }
  187. return 0;
  188. }
  189. int ath6kl_diag_read(struct ath6kl *ar, u32 address, void *data, u32 length)
  190. {
  191. u32 count, *buf = data;
  192. int ret;
  193. if (WARN_ON(length % 4))
  194. return -EINVAL;
  195. for (count = 0; count < length / 4; count++, address += 4) {
  196. ret = ath6kl_diag_read32(ar, address, &buf[count]);
  197. if (ret)
  198. return ret;
  199. }
  200. return 0;
  201. }
  202. int ath6kl_diag_write(struct ath6kl *ar, u32 address, void *data, u32 length)
  203. {
  204. u32 count;
  205. __le32 *buf = data;
  206. int ret;
  207. if (WARN_ON(length % 4))
  208. return -EINVAL;
  209. for (count = 0; count < length / 4; count++, address += 4) {
  210. ret = ath6kl_diag_write32(ar, address, buf[count]);
  211. if (ret)
  212. return ret;
  213. }
  214. return 0;
  215. }
  216. int ath6kl_read_fwlogs(struct ath6kl *ar)
  217. {
  218. struct ath6kl_dbglog_hdr debug_hdr;
  219. struct ath6kl_dbglog_buf debug_buf;
  220. u32 address, length, dropped, firstbuf, debug_hdr_addr;
  221. int ret, loop;
  222. u8 *buf;
  223. buf = kmalloc(ATH6KL_FWLOG_PAYLOAD_SIZE, GFP_KERNEL);
  224. if (!buf)
  225. return -ENOMEM;
  226. address = TARG_VTOP(ar->target_type,
  227. ath6kl_get_hi_item_addr(ar,
  228. HI_ITEM(hi_dbglog_hdr)));
  229. ret = ath6kl_diag_read32(ar, address, &debug_hdr_addr);
  230. if (ret)
  231. goto out;
  232. /* Get the contents of the ring buffer */
  233. if (debug_hdr_addr == 0) {
  234. ath6kl_warn("Invalid address for debug_hdr_addr\n");
  235. ret = -EINVAL;
  236. goto out;
  237. }
  238. address = TARG_VTOP(ar->target_type, debug_hdr_addr);
  239. ath6kl_diag_read(ar, address, &debug_hdr, sizeof(debug_hdr));
  240. address = TARG_VTOP(ar->target_type,
  241. le32_to_cpu(debug_hdr.dbuf_addr));
  242. firstbuf = address;
  243. dropped = le32_to_cpu(debug_hdr.dropped);
  244. ath6kl_diag_read(ar, address, &debug_buf, sizeof(debug_buf));
  245. loop = 100;
  246. do {
  247. address = TARG_VTOP(ar->target_type,
  248. le32_to_cpu(debug_buf.buffer_addr));
  249. length = le32_to_cpu(debug_buf.length);
  250. if (length != 0 && (le32_to_cpu(debug_buf.length) <=
  251. le32_to_cpu(debug_buf.bufsize))) {
  252. length = ALIGN(length, 4);
  253. ret = ath6kl_diag_read(ar, address,
  254. buf, length);
  255. if (ret)
  256. goto out;
  257. ath6kl_debug_fwlog_event(ar, buf, length);
  258. }
  259. address = TARG_VTOP(ar->target_type,
  260. le32_to_cpu(debug_buf.next));
  261. ath6kl_diag_read(ar, address, &debug_buf, sizeof(debug_buf));
  262. if (ret)
  263. goto out;
  264. loop--;
  265. if (WARN_ON(loop == 0)) {
  266. ret = -ETIMEDOUT;
  267. goto out;
  268. }
  269. } while (address != firstbuf);
  270. out:
  271. kfree(buf);
  272. return ret;
  273. }
  274. /* FIXME: move to a better place, target.h? */
  275. #define AR6003_RESET_CONTROL_ADDRESS 0x00004000
  276. #define AR6004_RESET_CONTROL_ADDRESS 0x00004000
  277. void ath6kl_reset_device(struct ath6kl *ar, u32 target_type,
  278. bool wait_fot_compltn, bool cold_reset)
  279. {
  280. int status = 0;
  281. u32 address;
  282. __le32 data;
  283. if (target_type != TARGET_TYPE_AR6003 &&
  284. target_type != TARGET_TYPE_AR6004)
  285. return;
  286. data = cold_reset ? cpu_to_le32(RESET_CONTROL_COLD_RST) :
  287. cpu_to_le32(RESET_CONTROL_MBOX_RST);
  288. switch (target_type) {
  289. case TARGET_TYPE_AR6003:
  290. address = AR6003_RESET_CONTROL_ADDRESS;
  291. break;
  292. case TARGET_TYPE_AR6004:
  293. address = AR6004_RESET_CONTROL_ADDRESS;
  294. break;
  295. }
  296. status = ath6kl_diag_write32(ar, address, data);
  297. if (status)
  298. ath6kl_err("failed to reset target\n");
  299. }
  300. static void ath6kl_install_static_wep_keys(struct ath6kl_vif *vif)
  301. {
  302. u8 index;
  303. u8 keyusage;
  304. for (index = 0; index <= WMI_MAX_KEY_INDEX; index++) {
  305. if (vif->wep_key_list[index].key_len) {
  306. keyusage = GROUP_USAGE;
  307. if (index == vif->def_txkey_index)
  308. keyusage |= TX_USAGE;
  309. ath6kl_wmi_addkey_cmd(vif->ar->wmi, vif->fw_vif_idx,
  310. index,
  311. WEP_CRYPT,
  312. keyusage,
  313. vif->wep_key_list[index].key_len,
  314. NULL, 0,
  315. vif->wep_key_list[index].key,
  316. KEY_OP_INIT_VAL, NULL,
  317. NO_SYNC_WMIFLAG);
  318. }
  319. }
  320. }
  321. void ath6kl_connect_ap_mode_bss(struct ath6kl_vif *vif, u16 channel)
  322. {
  323. struct ath6kl *ar = vif->ar;
  324. struct ath6kl_req_key *ik;
  325. int res;
  326. u8 key_rsc[ATH6KL_KEY_SEQ_LEN];
  327. ik = &ar->ap_mode_bkey;
  328. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "AP mode started on %u MHz\n", channel);
  329. switch (vif->auth_mode) {
  330. case NONE_AUTH:
  331. if (vif->prwise_crypto == WEP_CRYPT)
  332. ath6kl_install_static_wep_keys(vif);
  333. if (!ik->valid || ik->key_type != WAPI_CRYPT)
  334. break;
  335. /* for WAPI, we need to set the delayed group key, continue: */
  336. case WPA_PSK_AUTH:
  337. case WPA2_PSK_AUTH:
  338. case (WPA_PSK_AUTH | WPA2_PSK_AUTH):
  339. if (!ik->valid)
  340. break;
  341. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delayed addkey for "
  342. "the initial group key for AP mode\n");
  343. memset(key_rsc, 0, sizeof(key_rsc));
  344. res = ath6kl_wmi_addkey_cmd(
  345. ar->wmi, vif->fw_vif_idx, ik->key_index, ik->key_type,
  346. GROUP_USAGE, ik->key_len, key_rsc, ATH6KL_KEY_SEQ_LEN,
  347. ik->key,
  348. KEY_OP_INIT_VAL, NULL, SYNC_BOTH_WMIFLAG);
  349. if (res) {
  350. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delayed "
  351. "addkey failed: %d\n", res);
  352. }
  353. break;
  354. }
  355. ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx, NONE_BSS_FILTER, 0);
  356. set_bit(CONNECTED, &vif->flags);
  357. netif_carrier_on(vif->ndev);
  358. }
  359. void ath6kl_connect_ap_mode_sta(struct ath6kl_vif *vif, u16 aid, u8 *mac_addr,
  360. u8 keymgmt, u8 ucipher, u8 auth,
  361. u8 assoc_req_len, u8 *assoc_info, u8 apsd_info)
  362. {
  363. u8 *ies = NULL, *wpa_ie = NULL, *pos;
  364. size_t ies_len = 0;
  365. struct station_info sinfo;
  366. ath6kl_dbg(ATH6KL_DBG_TRC, "new station %pM aid=%d\n", mac_addr, aid);
  367. if (assoc_req_len > sizeof(struct ieee80211_hdr_3addr)) {
  368. struct ieee80211_mgmt *mgmt =
  369. (struct ieee80211_mgmt *) assoc_info;
  370. if (ieee80211_is_assoc_req(mgmt->frame_control) &&
  371. assoc_req_len >= sizeof(struct ieee80211_hdr_3addr) +
  372. sizeof(mgmt->u.assoc_req)) {
  373. ies = mgmt->u.assoc_req.variable;
  374. ies_len = assoc_info + assoc_req_len - ies;
  375. } else if (ieee80211_is_reassoc_req(mgmt->frame_control) &&
  376. assoc_req_len >= sizeof(struct ieee80211_hdr_3addr)
  377. + sizeof(mgmt->u.reassoc_req)) {
  378. ies = mgmt->u.reassoc_req.variable;
  379. ies_len = assoc_info + assoc_req_len - ies;
  380. }
  381. }
  382. pos = ies;
  383. while (pos && pos + 1 < ies + ies_len) {
  384. if (pos + 2 + pos[1] > ies + ies_len)
  385. break;
  386. if (pos[0] == WLAN_EID_RSN)
  387. wpa_ie = pos; /* RSN IE */
  388. else if (pos[0] == WLAN_EID_VENDOR_SPECIFIC &&
  389. pos[1] >= 4 &&
  390. pos[2] == 0x00 && pos[3] == 0x50 && pos[4] == 0xf2) {
  391. if (pos[5] == 0x01)
  392. wpa_ie = pos; /* WPA IE */
  393. else if (pos[5] == 0x04) {
  394. wpa_ie = pos; /* WPS IE */
  395. break; /* overrides WPA/RSN IE */
  396. }
  397. } else if (pos[0] == 0x44 && wpa_ie == NULL) {
  398. /*
  399. * Note: WAPI Parameter Set IE re-uses Element ID that
  400. * was officially allocated for BSS AC Access Delay. As
  401. * such, we need to be a bit more careful on when
  402. * parsing the frame. However, BSS AC Access Delay
  403. * element is not supposed to be included in
  404. * (Re)Association Request frames, so this should not
  405. * cause problems.
  406. */
  407. wpa_ie = pos; /* WAPI IE */
  408. break;
  409. }
  410. pos += 2 + pos[1];
  411. }
  412. ath6kl_add_new_sta(vif, mac_addr, aid, wpa_ie,
  413. wpa_ie ? 2 + wpa_ie[1] : 0,
  414. keymgmt, ucipher, auth, apsd_info);
  415. /* send event to application */
  416. memset(&sinfo, 0, sizeof(sinfo));
  417. /* TODO: sinfo.generation */
  418. sinfo.assoc_req_ies = ies;
  419. sinfo.assoc_req_ies_len = ies_len;
  420. sinfo.filled |= STATION_INFO_ASSOC_REQ_IES;
  421. cfg80211_new_sta(vif->ndev, mac_addr, &sinfo, GFP_KERNEL);
  422. netif_wake_queue(vif->ndev);
  423. }
  424. void disconnect_timer_handler(unsigned long ptr)
  425. {
  426. struct net_device *dev = (struct net_device *)ptr;
  427. struct ath6kl_vif *vif = netdev_priv(dev);
  428. ath6kl_init_profile_info(vif);
  429. ath6kl_disconnect(vif);
  430. }
  431. void ath6kl_disconnect(struct ath6kl_vif *vif)
  432. {
  433. if (test_bit(CONNECTED, &vif->flags) ||
  434. test_bit(CONNECT_PEND, &vif->flags)) {
  435. ath6kl_wmi_disconnect_cmd(vif->ar->wmi, vif->fw_vif_idx);
  436. /*
  437. * Disconnect command is issued, clear the connect pending
  438. * flag. The connected flag will be cleared in
  439. * disconnect event notification.
  440. */
  441. clear_bit(CONNECT_PEND, &vif->flags);
  442. }
  443. }
  444. /* WMI Event handlers */
  445. void ath6kl_ready_event(void *devt, u8 *datap, u32 sw_ver, u32 abi_ver)
  446. {
  447. struct ath6kl *ar = devt;
  448. memcpy(ar->mac_addr, datap, ETH_ALEN);
  449. ath6kl_dbg(ATH6KL_DBG_TRC, "%s: mac addr = %pM\n",
  450. __func__, ar->mac_addr);
  451. ar->version.wlan_ver = sw_ver;
  452. ar->version.abi_ver = abi_ver;
  453. snprintf(ar->wiphy->fw_version,
  454. sizeof(ar->wiphy->fw_version),
  455. "%u.%u.%u.%u",
  456. (ar->version.wlan_ver & 0xf0000000) >> 28,
  457. (ar->version.wlan_ver & 0x0f000000) >> 24,
  458. (ar->version.wlan_ver & 0x00ff0000) >> 16,
  459. (ar->version.wlan_ver & 0x0000ffff));
  460. /* indicate to the waiting thread that the ready event was received */
  461. set_bit(WMI_READY, &ar->flag);
  462. wake_up(&ar->event_wq);
  463. }
  464. void ath6kl_scan_complete_evt(struct ath6kl_vif *vif, int status)
  465. {
  466. struct ath6kl *ar = vif->ar;
  467. bool aborted = false;
  468. if (status != WMI_SCAN_STATUS_SUCCESS)
  469. aborted = true;
  470. ath6kl_cfg80211_scan_complete_event(vif, aborted);
  471. if (!ar->usr_bss_filter) {
  472. clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
  473. ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  474. NONE_BSS_FILTER, 0);
  475. }
  476. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "scan complete: %d\n", status);
  477. }
  478. void ath6kl_connect_event(struct ath6kl_vif *vif, u16 channel, u8 *bssid,
  479. u16 listen_int, u16 beacon_int,
  480. enum network_type net_type, u8 beacon_ie_len,
  481. u8 assoc_req_len, u8 assoc_resp_len,
  482. u8 *assoc_info)
  483. {
  484. struct ath6kl *ar = vif->ar;
  485. ath6kl_cfg80211_connect_event(vif, channel, bssid,
  486. listen_int, beacon_int,
  487. net_type, beacon_ie_len,
  488. assoc_req_len, assoc_resp_len,
  489. assoc_info);
  490. memcpy(vif->bssid, bssid, sizeof(vif->bssid));
  491. vif->bss_ch = channel;
  492. if ((vif->nw_type == INFRA_NETWORK))
  493. ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx,
  494. vif->listen_intvl_t, 0);
  495. netif_wake_queue(vif->ndev);
  496. /* Update connect & link status atomically */
  497. spin_lock_bh(&vif->if_lock);
  498. set_bit(CONNECTED, &vif->flags);
  499. clear_bit(CONNECT_PEND, &vif->flags);
  500. netif_carrier_on(vif->ndev);
  501. spin_unlock_bh(&vif->if_lock);
  502. aggr_reset_state(vif->aggr_cntxt->aggr_conn);
  503. vif->reconnect_flag = 0;
  504. if ((vif->nw_type == ADHOC_NETWORK) && ar->ibss_ps_enable) {
  505. memset(ar->node_map, 0, sizeof(ar->node_map));
  506. ar->node_num = 0;
  507. ar->next_ep_id = ENDPOINT_2;
  508. }
  509. if (!ar->usr_bss_filter) {
  510. set_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
  511. ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  512. CURRENT_BSS_FILTER, 0);
  513. }
  514. }
  515. void ath6kl_tkip_micerr_event(struct ath6kl_vif *vif, u8 keyid, bool ismcast)
  516. {
  517. struct ath6kl_sta *sta;
  518. struct ath6kl *ar = vif->ar;
  519. u8 tsc[6];
  520. /*
  521. * For AP case, keyid will have aid of STA which sent pkt with
  522. * MIC error. Use this aid to get MAC & send it to hostapd.
  523. */
  524. if (vif->nw_type == AP_NETWORK) {
  525. sta = ath6kl_find_sta_by_aid(ar, (keyid >> 2));
  526. if (!sta)
  527. return;
  528. ath6kl_dbg(ATH6KL_DBG_TRC,
  529. "ap tkip mic error received from aid=%d\n", keyid);
  530. memset(tsc, 0, sizeof(tsc)); /* FIX: get correct TSC */
  531. cfg80211_michael_mic_failure(vif->ndev, sta->mac,
  532. NL80211_KEYTYPE_PAIRWISE, keyid,
  533. tsc, GFP_KERNEL);
  534. } else
  535. ath6kl_cfg80211_tkip_micerr_event(vif, keyid, ismcast);
  536. }
  537. static void ath6kl_update_target_stats(struct ath6kl_vif *vif, u8 *ptr, u32 len)
  538. {
  539. struct wmi_target_stats *tgt_stats =
  540. (struct wmi_target_stats *) ptr;
  541. struct ath6kl *ar = vif->ar;
  542. struct target_stats *stats = &vif->target_stats;
  543. struct tkip_ccmp_stats *ccmp_stats;
  544. u8 ac;
  545. if (len < sizeof(*tgt_stats))
  546. return;
  547. ath6kl_dbg(ATH6KL_DBG_TRC, "updating target stats\n");
  548. stats->tx_pkt += le32_to_cpu(tgt_stats->stats.tx.pkt);
  549. stats->tx_byte += le32_to_cpu(tgt_stats->stats.tx.byte);
  550. stats->tx_ucast_pkt += le32_to_cpu(tgt_stats->stats.tx.ucast_pkt);
  551. stats->tx_ucast_byte += le32_to_cpu(tgt_stats->stats.tx.ucast_byte);
  552. stats->tx_mcast_pkt += le32_to_cpu(tgt_stats->stats.tx.mcast_pkt);
  553. stats->tx_mcast_byte += le32_to_cpu(tgt_stats->stats.tx.mcast_byte);
  554. stats->tx_bcast_pkt += le32_to_cpu(tgt_stats->stats.tx.bcast_pkt);
  555. stats->tx_bcast_byte += le32_to_cpu(tgt_stats->stats.tx.bcast_byte);
  556. stats->tx_rts_success_cnt +=
  557. le32_to_cpu(tgt_stats->stats.tx.rts_success_cnt);
  558. for (ac = 0; ac < WMM_NUM_AC; ac++)
  559. stats->tx_pkt_per_ac[ac] +=
  560. le32_to_cpu(tgt_stats->stats.tx.pkt_per_ac[ac]);
  561. stats->tx_err += le32_to_cpu(tgt_stats->stats.tx.err);
  562. stats->tx_fail_cnt += le32_to_cpu(tgt_stats->stats.tx.fail_cnt);
  563. stats->tx_retry_cnt += le32_to_cpu(tgt_stats->stats.tx.retry_cnt);
  564. stats->tx_mult_retry_cnt +=
  565. le32_to_cpu(tgt_stats->stats.tx.mult_retry_cnt);
  566. stats->tx_rts_fail_cnt +=
  567. le32_to_cpu(tgt_stats->stats.tx.rts_fail_cnt);
  568. stats->tx_ucast_rate =
  569. ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats->stats.tx.ucast_rate));
  570. stats->rx_pkt += le32_to_cpu(tgt_stats->stats.rx.pkt);
  571. stats->rx_byte += le32_to_cpu(tgt_stats->stats.rx.byte);
  572. stats->rx_ucast_pkt += le32_to_cpu(tgt_stats->stats.rx.ucast_pkt);
  573. stats->rx_ucast_byte += le32_to_cpu(tgt_stats->stats.rx.ucast_byte);
  574. stats->rx_mcast_pkt += le32_to_cpu(tgt_stats->stats.rx.mcast_pkt);
  575. stats->rx_mcast_byte += le32_to_cpu(tgt_stats->stats.rx.mcast_byte);
  576. stats->rx_bcast_pkt += le32_to_cpu(tgt_stats->stats.rx.bcast_pkt);
  577. stats->rx_bcast_byte += le32_to_cpu(tgt_stats->stats.rx.bcast_byte);
  578. stats->rx_frgment_pkt += le32_to_cpu(tgt_stats->stats.rx.frgment_pkt);
  579. stats->rx_err += le32_to_cpu(tgt_stats->stats.rx.err);
  580. stats->rx_crc_err += le32_to_cpu(tgt_stats->stats.rx.crc_err);
  581. stats->rx_key_cache_miss +=
  582. le32_to_cpu(tgt_stats->stats.rx.key_cache_miss);
  583. stats->rx_decrypt_err += le32_to_cpu(tgt_stats->stats.rx.decrypt_err);
  584. stats->rx_dupl_frame += le32_to_cpu(tgt_stats->stats.rx.dupl_frame);
  585. stats->rx_ucast_rate =
  586. ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats->stats.rx.ucast_rate));
  587. ccmp_stats = &tgt_stats->stats.tkip_ccmp_stats;
  588. stats->tkip_local_mic_fail +=
  589. le32_to_cpu(ccmp_stats->tkip_local_mic_fail);
  590. stats->tkip_cnter_measures_invoked +=
  591. le32_to_cpu(ccmp_stats->tkip_cnter_measures_invoked);
  592. stats->tkip_fmt_err += le32_to_cpu(ccmp_stats->tkip_fmt_err);
  593. stats->ccmp_fmt_err += le32_to_cpu(ccmp_stats->ccmp_fmt_err);
  594. stats->ccmp_replays += le32_to_cpu(ccmp_stats->ccmp_replays);
  595. stats->pwr_save_fail_cnt +=
  596. le32_to_cpu(tgt_stats->pm_stats.pwr_save_failure_cnt);
  597. stats->noise_floor_calib =
  598. a_sle32_to_cpu(tgt_stats->noise_floor_calib);
  599. stats->cs_bmiss_cnt +=
  600. le32_to_cpu(tgt_stats->cserv_stats.cs_bmiss_cnt);
  601. stats->cs_low_rssi_cnt +=
  602. le32_to_cpu(tgt_stats->cserv_stats.cs_low_rssi_cnt);
  603. stats->cs_connect_cnt +=
  604. le16_to_cpu(tgt_stats->cserv_stats.cs_connect_cnt);
  605. stats->cs_discon_cnt +=
  606. le16_to_cpu(tgt_stats->cserv_stats.cs_discon_cnt);
  607. stats->cs_ave_beacon_rssi =
  608. a_sle16_to_cpu(tgt_stats->cserv_stats.cs_ave_beacon_rssi);
  609. stats->cs_last_roam_msec =
  610. tgt_stats->cserv_stats.cs_last_roam_msec;
  611. stats->cs_snr = tgt_stats->cserv_stats.cs_snr;
  612. stats->cs_rssi = a_sle16_to_cpu(tgt_stats->cserv_stats.cs_rssi);
  613. stats->lq_val = le32_to_cpu(tgt_stats->lq_val);
  614. stats->wow_pkt_dropped +=
  615. le32_to_cpu(tgt_stats->wow_stats.wow_pkt_dropped);
  616. stats->wow_host_pkt_wakeups +=
  617. tgt_stats->wow_stats.wow_host_pkt_wakeups;
  618. stats->wow_host_evt_wakeups +=
  619. tgt_stats->wow_stats.wow_host_evt_wakeups;
  620. stats->wow_evt_discarded +=
  621. le16_to_cpu(tgt_stats->wow_stats.wow_evt_discarded);
  622. if (test_bit(STATS_UPDATE_PEND, &vif->flags)) {
  623. clear_bit(STATS_UPDATE_PEND, &vif->flags);
  624. wake_up(&ar->event_wq);
  625. }
  626. }
  627. static void ath6kl_add_le32(__le32 *var, __le32 val)
  628. {
  629. *var = cpu_to_le32(le32_to_cpu(*var) + le32_to_cpu(val));
  630. }
  631. void ath6kl_tgt_stats_event(struct ath6kl_vif *vif, u8 *ptr, u32 len)
  632. {
  633. struct wmi_ap_mode_stat *p = (struct wmi_ap_mode_stat *) ptr;
  634. struct ath6kl *ar = vif->ar;
  635. struct wmi_ap_mode_stat *ap = &ar->ap_stats;
  636. struct wmi_per_sta_stat *st_ap, *st_p;
  637. u8 ac;
  638. if (vif->nw_type == AP_NETWORK) {
  639. if (len < sizeof(*p))
  640. return;
  641. for (ac = 0; ac < AP_MAX_NUM_STA; ac++) {
  642. st_ap = &ap->sta[ac];
  643. st_p = &p->sta[ac];
  644. ath6kl_add_le32(&st_ap->tx_bytes, st_p->tx_bytes);
  645. ath6kl_add_le32(&st_ap->tx_pkts, st_p->tx_pkts);
  646. ath6kl_add_le32(&st_ap->tx_error, st_p->tx_error);
  647. ath6kl_add_le32(&st_ap->tx_discard, st_p->tx_discard);
  648. ath6kl_add_le32(&st_ap->rx_bytes, st_p->rx_bytes);
  649. ath6kl_add_le32(&st_ap->rx_pkts, st_p->rx_pkts);
  650. ath6kl_add_le32(&st_ap->rx_error, st_p->rx_error);
  651. ath6kl_add_le32(&st_ap->rx_discard, st_p->rx_discard);
  652. }
  653. } else {
  654. ath6kl_update_target_stats(vif, ptr, len);
  655. }
  656. }
  657. void ath6kl_wakeup_event(void *dev)
  658. {
  659. struct ath6kl *ar = (struct ath6kl *) dev;
  660. wake_up(&ar->event_wq);
  661. }
  662. void ath6kl_txpwr_rx_evt(void *devt, u8 tx_pwr)
  663. {
  664. struct ath6kl *ar = (struct ath6kl *) devt;
  665. ar->tx_pwr = tx_pwr;
  666. wake_up(&ar->event_wq);
  667. }
  668. void ath6kl_pspoll_event(struct ath6kl_vif *vif, u8 aid)
  669. {
  670. struct ath6kl_sta *conn;
  671. struct sk_buff *skb;
  672. bool psq_empty = false;
  673. struct ath6kl *ar = vif->ar;
  674. struct ath6kl_mgmt_buff *mgmt_buf;
  675. conn = ath6kl_find_sta_by_aid(ar, aid);
  676. if (!conn)
  677. return;
  678. /*
  679. * Send out a packet queued on ps queue. When the ps queue
  680. * becomes empty update the PVB for this station.
  681. */
  682. spin_lock_bh(&conn->psq_lock);
  683. psq_empty = skb_queue_empty(&conn->psq) && (conn->mgmt_psq_len == 0);
  684. spin_unlock_bh(&conn->psq_lock);
  685. if (psq_empty)
  686. /* TODO: Send out a NULL data frame */
  687. return;
  688. spin_lock_bh(&conn->psq_lock);
  689. if (conn->mgmt_psq_len > 0) {
  690. mgmt_buf = list_first_entry(&conn->mgmt_psq,
  691. struct ath6kl_mgmt_buff, list);
  692. list_del(&mgmt_buf->list);
  693. conn->mgmt_psq_len--;
  694. spin_unlock_bh(&conn->psq_lock);
  695. conn->sta_flags |= STA_PS_POLLED;
  696. ath6kl_wmi_send_mgmt_cmd(ar->wmi, vif->fw_vif_idx,
  697. mgmt_buf->id, mgmt_buf->freq,
  698. mgmt_buf->wait, mgmt_buf->buf,
  699. mgmt_buf->len, mgmt_buf->no_cck);
  700. conn->sta_flags &= ~STA_PS_POLLED;
  701. kfree(mgmt_buf);
  702. } else {
  703. skb = skb_dequeue(&conn->psq);
  704. spin_unlock_bh(&conn->psq_lock);
  705. conn->sta_flags |= STA_PS_POLLED;
  706. ath6kl_data_tx(skb, vif->ndev);
  707. conn->sta_flags &= ~STA_PS_POLLED;
  708. }
  709. spin_lock_bh(&conn->psq_lock);
  710. psq_empty = skb_queue_empty(&conn->psq) && (conn->mgmt_psq_len == 0);
  711. spin_unlock_bh(&conn->psq_lock);
  712. if (psq_empty)
  713. ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx, conn->aid, 0);
  714. }
  715. void ath6kl_dtimexpiry_event(struct ath6kl_vif *vif)
  716. {
  717. bool mcastq_empty = false;
  718. struct sk_buff *skb;
  719. struct ath6kl *ar = vif->ar;
  720. /*
  721. * If there are no associated STAs, ignore the DTIM expiry event.
  722. * There can be potential race conditions where the last associated
  723. * STA may disconnect & before the host could clear the 'Indicate
  724. * DTIM' request to the firmware, the firmware would have just
  725. * indicated a DTIM expiry event. The race is between 'clear DTIM
  726. * expiry cmd' going from the host to the firmware & the DTIM
  727. * expiry event happening from the firmware to the host.
  728. */
  729. if (!ar->sta_list_index)
  730. return;
  731. spin_lock_bh(&ar->mcastpsq_lock);
  732. mcastq_empty = skb_queue_empty(&ar->mcastpsq);
  733. spin_unlock_bh(&ar->mcastpsq_lock);
  734. if (mcastq_empty)
  735. return;
  736. /* set the STA flag to dtim_expired for the frame to go out */
  737. set_bit(DTIM_EXPIRED, &vif->flags);
  738. spin_lock_bh(&ar->mcastpsq_lock);
  739. while ((skb = skb_dequeue(&ar->mcastpsq)) != NULL) {
  740. spin_unlock_bh(&ar->mcastpsq_lock);
  741. ath6kl_data_tx(skb, vif->ndev);
  742. spin_lock_bh(&ar->mcastpsq_lock);
  743. }
  744. spin_unlock_bh(&ar->mcastpsq_lock);
  745. clear_bit(DTIM_EXPIRED, &vif->flags);
  746. /* clear the LSB of the BitMapCtl field of the TIM IE */
  747. ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx, MCAST_AID, 0);
  748. }
  749. void ath6kl_disconnect_event(struct ath6kl_vif *vif, u8 reason, u8 *bssid,
  750. u8 assoc_resp_len, u8 *assoc_info,
  751. u16 prot_reason_status)
  752. {
  753. struct ath6kl *ar = vif->ar;
  754. if (vif->nw_type == AP_NETWORK) {
  755. if (!ath6kl_remove_sta(ar, bssid, prot_reason_status))
  756. return;
  757. /* if no more associated STAs, empty the mcast PS q */
  758. if (ar->sta_list_index == 0) {
  759. spin_lock_bh(&ar->mcastpsq_lock);
  760. skb_queue_purge(&ar->mcastpsq);
  761. spin_unlock_bh(&ar->mcastpsq_lock);
  762. /* clear the LSB of the TIM IE's BitMapCtl field */
  763. if (test_bit(WMI_READY, &ar->flag))
  764. ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx,
  765. MCAST_AID, 0);
  766. }
  767. if (!is_broadcast_ether_addr(bssid)) {
  768. /* send event to application */
  769. cfg80211_del_sta(vif->ndev, bssid, GFP_KERNEL);
  770. }
  771. if (memcmp(vif->ndev->dev_addr, bssid, ETH_ALEN) == 0) {
  772. memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
  773. clear_bit(CONNECTED, &vif->flags);
  774. }
  775. return;
  776. }
  777. ath6kl_cfg80211_disconnect_event(vif, reason, bssid,
  778. assoc_resp_len, assoc_info,
  779. prot_reason_status);
  780. aggr_reset_state(vif->aggr_cntxt->aggr_conn);
  781. del_timer(&vif->disconnect_timer);
  782. ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "disconnect reason is %d\n", reason);
  783. /*
  784. * If the event is due to disconnect cmd from the host, only they
  785. * the target would stop trying to connect. Under any other
  786. * condition, target would keep trying to connect.
  787. */
  788. if (reason == DISCONNECT_CMD) {
  789. if (!ar->usr_bss_filter && test_bit(WMI_READY, &ar->flag))
  790. ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  791. NONE_BSS_FILTER, 0);
  792. } else {
  793. set_bit(CONNECT_PEND, &vif->flags);
  794. if (((reason == ASSOC_FAILED) &&
  795. (prot_reason_status == 0x11)) ||
  796. ((reason == ASSOC_FAILED) && (prot_reason_status == 0x0) &&
  797. (vif->reconnect_flag == 1))) {
  798. set_bit(CONNECTED, &vif->flags);
  799. return;
  800. }
  801. }
  802. /* update connect & link status atomically */
  803. spin_lock_bh(&vif->if_lock);
  804. clear_bit(CONNECTED, &vif->flags);
  805. netif_carrier_off(vif->ndev);
  806. spin_unlock_bh(&vif->if_lock);
  807. if ((reason != CSERV_DISCONNECT) || (vif->reconnect_flag != 1))
  808. vif->reconnect_flag = 0;
  809. if (reason != CSERV_DISCONNECT)
  810. ar->user_key_ctrl = 0;
  811. netif_stop_queue(vif->ndev);
  812. memset(vif->bssid, 0, sizeof(vif->bssid));
  813. vif->bss_ch = 0;
  814. ath6kl_tx_data_cleanup(ar);
  815. }
  816. struct ath6kl_vif *ath6kl_vif_first(struct ath6kl *ar)
  817. {
  818. struct ath6kl_vif *vif;
  819. spin_lock_bh(&ar->list_lock);
  820. if (list_empty(&ar->vif_list)) {
  821. spin_unlock_bh(&ar->list_lock);
  822. return NULL;
  823. }
  824. vif = list_first_entry(&ar->vif_list, struct ath6kl_vif, list);
  825. spin_unlock_bh(&ar->list_lock);
  826. return vif;
  827. }
  828. static int ath6kl_open(struct net_device *dev)
  829. {
  830. struct ath6kl_vif *vif = netdev_priv(dev);
  831. set_bit(WLAN_ENABLED, &vif->flags);
  832. if (test_bit(CONNECTED, &vif->flags)) {
  833. netif_carrier_on(dev);
  834. netif_wake_queue(dev);
  835. } else
  836. netif_carrier_off(dev);
  837. return 0;
  838. }
  839. static int ath6kl_close(struct net_device *dev)
  840. {
  841. struct ath6kl_vif *vif = netdev_priv(dev);
  842. netif_stop_queue(dev);
  843. ath6kl_cfg80211_stop(vif);
  844. clear_bit(WLAN_ENABLED, &vif->flags);
  845. return 0;
  846. }
  847. static struct net_device_stats *ath6kl_get_stats(struct net_device *dev)
  848. {
  849. struct ath6kl_vif *vif = netdev_priv(dev);
  850. return &vif->net_stats;
  851. }
  852. static int ath6kl_set_features(struct net_device *dev,
  853. netdev_features_t features)
  854. {
  855. struct ath6kl_vif *vif = netdev_priv(dev);
  856. struct ath6kl *ar = vif->ar;
  857. int err = 0;
  858. if ((features & NETIF_F_RXCSUM) &&
  859. (ar->rx_meta_ver != WMI_META_VERSION_2)) {
  860. ar->rx_meta_ver = WMI_META_VERSION_2;
  861. err = ath6kl_wmi_set_rx_frame_format_cmd(ar->wmi,
  862. vif->fw_vif_idx,
  863. ar->rx_meta_ver, 0, 0);
  864. if (err) {
  865. dev->features = features & ~NETIF_F_RXCSUM;
  866. return err;
  867. }
  868. } else if (!(features & NETIF_F_RXCSUM) &&
  869. (ar->rx_meta_ver == WMI_META_VERSION_2)) {
  870. ar->rx_meta_ver = 0;
  871. err = ath6kl_wmi_set_rx_frame_format_cmd(ar->wmi,
  872. vif->fw_vif_idx,
  873. ar->rx_meta_ver, 0, 0);
  874. if (err) {
  875. dev->features = features | NETIF_F_RXCSUM;
  876. return err;
  877. }
  878. }
  879. return err;
  880. }
  881. static void ath6kl_set_multicast_list(struct net_device *ndev)
  882. {
  883. struct ath6kl_vif *vif = netdev_priv(ndev);
  884. bool mc_all_on = false, mc_all_off = false;
  885. int mc_count = netdev_mc_count(ndev);
  886. struct netdev_hw_addr *ha;
  887. bool found;
  888. struct ath6kl_mc_filter *mc_filter, *tmp;
  889. struct list_head mc_filter_new;
  890. int ret;
  891. if (!test_bit(WMI_READY, &vif->ar->flag) ||
  892. !test_bit(WLAN_ENABLED, &vif->flags))
  893. return;
  894. mc_all_on = !!(ndev->flags & IFF_PROMISC) ||
  895. !!(ndev->flags & IFF_ALLMULTI) ||
  896. !!(mc_count > ATH6K_MAX_MC_FILTERS_PER_LIST);
  897. mc_all_off = !(ndev->flags & IFF_MULTICAST) || mc_count == 0;
  898. if (mc_all_on || mc_all_off) {
  899. /* Enable/disable all multicast */
  900. ath6kl_dbg(ATH6KL_DBG_TRC, "%s multicast filter\n",
  901. mc_all_on ? "enabling" : "disabling");
  902. ret = ath6kl_wmi_mcast_filter_cmd(vif->ar->wmi, vif->fw_vif_idx,
  903. mc_all_on);
  904. if (ret)
  905. ath6kl_warn("Failed to %s multicast receive\n",
  906. mc_all_on ? "enable" : "disable");
  907. return;
  908. }
  909. list_for_each_entry_safe(mc_filter, tmp, &vif->mc_filter, list) {
  910. found = false;
  911. netdev_for_each_mc_addr(ha, ndev) {
  912. if (memcmp(ha->addr, mc_filter->hw_addr,
  913. ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE) == 0) {
  914. found = true;
  915. break;
  916. }
  917. }
  918. if (!found) {
  919. /*
  920. * Delete the filter which was previously set
  921. * but not in the new request.
  922. */
  923. ath6kl_dbg(ATH6KL_DBG_TRC,
  924. "Removing %pM from multicast filter\n",
  925. mc_filter->hw_addr);
  926. ret = ath6kl_wmi_add_del_mcast_filter_cmd(vif->ar->wmi,
  927. vif->fw_vif_idx, mc_filter->hw_addr,
  928. false);
  929. if (ret) {
  930. ath6kl_warn("Failed to remove multicast filter:%pM\n",
  931. mc_filter->hw_addr);
  932. return;
  933. }
  934. list_del(&mc_filter->list);
  935. kfree(mc_filter);
  936. }
  937. }
  938. INIT_LIST_HEAD(&mc_filter_new);
  939. netdev_for_each_mc_addr(ha, ndev) {
  940. found = false;
  941. list_for_each_entry(mc_filter, &vif->mc_filter, list) {
  942. if (memcmp(ha->addr, mc_filter->hw_addr,
  943. ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE) == 0) {
  944. found = true;
  945. break;
  946. }
  947. }
  948. if (!found) {
  949. mc_filter = kzalloc(sizeof(struct ath6kl_mc_filter),
  950. GFP_ATOMIC);
  951. if (!mc_filter) {
  952. WARN_ON(1);
  953. goto out;
  954. }
  955. memcpy(mc_filter->hw_addr, ha->addr,
  956. ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE);
  957. /* Set the multicast filter */
  958. ath6kl_dbg(ATH6KL_DBG_TRC,
  959. "Adding %pM to multicast filter list\n",
  960. mc_filter->hw_addr);
  961. ret = ath6kl_wmi_add_del_mcast_filter_cmd(vif->ar->wmi,
  962. vif->fw_vif_idx, mc_filter->hw_addr,
  963. true);
  964. if (ret) {
  965. ath6kl_warn("Failed to add multicast filter :%pM\n",
  966. mc_filter->hw_addr);
  967. kfree(mc_filter);
  968. goto out;
  969. }
  970. list_add_tail(&mc_filter->list, &mc_filter_new);
  971. }
  972. }
  973. out:
  974. list_splice_tail(&mc_filter_new, &vif->mc_filter);
  975. }
  976. static const struct net_device_ops ath6kl_netdev_ops = {
  977. .ndo_open = ath6kl_open,
  978. .ndo_stop = ath6kl_close,
  979. .ndo_start_xmit = ath6kl_data_tx,
  980. .ndo_get_stats = ath6kl_get_stats,
  981. .ndo_set_features = ath6kl_set_features,
  982. .ndo_set_rx_mode = ath6kl_set_multicast_list,
  983. };
  984. void init_netdev(struct net_device *dev)
  985. {
  986. dev->netdev_ops = &ath6kl_netdev_ops;
  987. dev->destructor = free_netdev;
  988. dev->watchdog_timeo = ATH6KL_TX_TIMEOUT;
  989. dev->needed_headroom = ETH_HLEN;
  990. dev->needed_headroom += sizeof(struct ath6kl_llc_snap_hdr) +
  991. sizeof(struct wmi_data_hdr) + HTC_HDR_LENGTH
  992. + WMI_MAX_TX_META_SZ + ATH6KL_HTC_ALIGN_BYTES;
  993. dev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_RXCSUM;
  994. return;
  995. }