main.c 40 KB

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