main.c 35 KB

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