main.c 36 KB

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