main.c 34 KB

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