main.c 35 KB

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