main.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353
  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. /* WMI Event handlers */
  666. static const char *get_hw_id_string(u32 id)
  667. {
  668. switch (id) {
  669. case AR6003_REV1_VERSION:
  670. return "1.0";
  671. case AR6003_REV2_VERSION:
  672. return "2.0";
  673. case AR6003_REV3_VERSION:
  674. return "2.1.1";
  675. default:
  676. return "unknown";
  677. }
  678. }
  679. void ath6kl_ready_event(void *devt, u8 *datap, u32 sw_ver, u32 abi_ver)
  680. {
  681. struct ath6kl *ar = devt;
  682. struct net_device *dev = ar->net_dev;
  683. memcpy(dev->dev_addr, datap, ETH_ALEN);
  684. ath6kl_dbg(ATH6KL_DBG_TRC, "%s: mac addr = %pM\n",
  685. __func__, dev->dev_addr);
  686. ar->version.wlan_ver = sw_ver;
  687. ar->version.abi_ver = abi_ver;
  688. snprintf(ar->wdev->wiphy->fw_version,
  689. sizeof(ar->wdev->wiphy->fw_version),
  690. "%u.%u.%u.%u",
  691. (ar->version.wlan_ver & 0xf0000000) >> 28,
  692. (ar->version.wlan_ver & 0x0f000000) >> 24,
  693. (ar->version.wlan_ver & 0x00ff0000) >> 16,
  694. (ar->version.wlan_ver & 0x0000ffff));
  695. /* indicate to the waiting thread that the ready event was received */
  696. set_bit(WMI_READY, &ar->flag);
  697. wake_up(&ar->event_wq);
  698. ath6kl_info("hw %s fw %s\n",
  699. get_hw_id_string(ar->wdev->wiphy->hw_version),
  700. ar->wdev->wiphy->fw_version);
  701. }
  702. void ath6kl_scan_complete_evt(struct ath6kl *ar, int status)
  703. {
  704. ath6kl_cfg80211_scan_complete_event(ar, status);
  705. if (!ar->usr_bss_filter)
  706. ath6kl_wmi_bssfilter_cmd(ar->wmi, NONE_BSS_FILTER, 0);
  707. ath6kl_dbg(ATH6KL_DBG_WLAN_SCAN, "scan complete: %d\n", status);
  708. }
  709. void ath6kl_connect_event(struct ath6kl *ar, u16 channel, u8 *bssid,
  710. u16 listen_int, u16 beacon_int,
  711. enum network_type net_type, u8 beacon_ie_len,
  712. u8 assoc_req_len, u8 assoc_resp_len,
  713. u8 *assoc_info)
  714. {
  715. unsigned long flags;
  716. if (ar->nw_type == AP_NETWORK) {
  717. ath6kl_connect_ap_mode(ar, channel, bssid, listen_int,
  718. beacon_int, assoc_resp_len,
  719. assoc_info);
  720. return;
  721. }
  722. ath6kl_cfg80211_connect_event(ar, channel, bssid,
  723. listen_int, beacon_int,
  724. net_type, beacon_ie_len,
  725. assoc_req_len, assoc_resp_len,
  726. assoc_info);
  727. memcpy(ar->bssid, bssid, sizeof(ar->bssid));
  728. ar->bss_ch = channel;
  729. if ((ar->nw_type == INFRA_NETWORK))
  730. ath6kl_wmi_listeninterval_cmd(ar->wmi, ar->listen_intvl_t,
  731. ar->listen_intvl_b);
  732. netif_wake_queue(ar->net_dev);
  733. /* Update connect & link status atomically */
  734. spin_lock_irqsave(&ar->lock, flags);
  735. set_bit(CONNECTED, &ar->flag);
  736. clear_bit(CONNECT_PEND, &ar->flag);
  737. netif_carrier_on(ar->net_dev);
  738. spin_unlock_irqrestore(&ar->lock, flags);
  739. aggr_reset_state(ar->aggr_cntxt);
  740. ar->reconnect_flag = 0;
  741. if ((ar->nw_type == ADHOC_NETWORK) && ar->ibss_ps_enable) {
  742. memset(ar->node_map, 0, sizeof(ar->node_map));
  743. ar->node_num = 0;
  744. ar->next_ep_id = ENDPOINT_2;
  745. }
  746. if (!ar->usr_bss_filter)
  747. ath6kl_wmi_bssfilter_cmd(ar->wmi, NONE_BSS_FILTER, 0);
  748. }
  749. void ath6kl_tkip_micerr_event(struct ath6kl *ar, u8 keyid, bool ismcast)
  750. {
  751. struct ath6kl_sta *sta;
  752. u8 tsc[6];
  753. /*
  754. * For AP case, keyid will have aid of STA which sent pkt with
  755. * MIC error. Use this aid to get MAC & send it to hostapd.
  756. */
  757. if (ar->nw_type == AP_NETWORK) {
  758. sta = ath6kl_find_sta_by_aid(ar, (keyid >> 2));
  759. if (!sta)
  760. return;
  761. ath6kl_dbg(ATH6KL_DBG_TRC,
  762. "ap tkip mic error received from aid=%d\n", keyid);
  763. memset(tsc, 0, sizeof(tsc)); /* FIX: get correct TSC */
  764. cfg80211_michael_mic_failure(ar->net_dev, sta->mac,
  765. NL80211_KEYTYPE_PAIRWISE, keyid,
  766. tsc, GFP_KERNEL);
  767. } else
  768. ath6kl_cfg80211_tkip_micerr_event(ar, keyid, ismcast);
  769. }
  770. static void ath6kl_update_target_stats(struct ath6kl *ar, u8 *ptr, u32 len)
  771. {
  772. struct wmi_target_stats *tgt_stats =
  773. (struct wmi_target_stats *) ptr;
  774. struct target_stats *stats = &ar->target_stats;
  775. struct tkip_ccmp_stats *ccmp_stats;
  776. struct bss *conn_bss = NULL;
  777. struct cserv_stats *c_stats;
  778. u8 ac;
  779. if (len < sizeof(*tgt_stats))
  780. return;
  781. /* update the RSSI of the connected bss */
  782. if (test_bit(CONNECTED, &ar->flag)) {
  783. conn_bss = ath6kl_wmi_find_node(ar->wmi, ar->bssid);
  784. if (conn_bss) {
  785. c_stats = &tgt_stats->cserv_stats;
  786. conn_bss->ni_rssi =
  787. a_sle16_to_cpu(c_stats->cs_ave_beacon_rssi);
  788. conn_bss->ni_snr =
  789. tgt_stats->cserv_stats.cs_ave_beacon_snr;
  790. ath6kl_wmi_node_return(ar->wmi, conn_bss);
  791. }
  792. }
  793. ath6kl_dbg(ATH6KL_DBG_TRC, "updating target stats\n");
  794. stats->tx_pkt += le32_to_cpu(tgt_stats->stats.tx.pkt);
  795. stats->tx_byte += le32_to_cpu(tgt_stats->stats.tx.byte);
  796. stats->tx_ucast_pkt += le32_to_cpu(tgt_stats->stats.tx.ucast_pkt);
  797. stats->tx_ucast_byte += le32_to_cpu(tgt_stats->stats.tx.ucast_byte);
  798. stats->tx_mcast_pkt += le32_to_cpu(tgt_stats->stats.tx.mcast_pkt);
  799. stats->tx_mcast_byte += le32_to_cpu(tgt_stats->stats.tx.mcast_byte);
  800. stats->tx_bcast_pkt += le32_to_cpu(tgt_stats->stats.tx.bcast_pkt);
  801. stats->tx_bcast_byte += le32_to_cpu(tgt_stats->stats.tx.bcast_byte);
  802. stats->tx_rts_success_cnt +=
  803. le32_to_cpu(tgt_stats->stats.tx.rts_success_cnt);
  804. for (ac = 0; ac < WMM_NUM_AC; ac++)
  805. stats->tx_pkt_per_ac[ac] +=
  806. le32_to_cpu(tgt_stats->stats.tx.pkt_per_ac[ac]);
  807. stats->tx_err += le32_to_cpu(tgt_stats->stats.tx.err);
  808. stats->tx_fail_cnt += le32_to_cpu(tgt_stats->stats.tx.fail_cnt);
  809. stats->tx_retry_cnt += le32_to_cpu(tgt_stats->stats.tx.retry_cnt);
  810. stats->tx_mult_retry_cnt +=
  811. le32_to_cpu(tgt_stats->stats.tx.mult_retry_cnt);
  812. stats->tx_rts_fail_cnt +=
  813. le32_to_cpu(tgt_stats->stats.tx.rts_fail_cnt);
  814. stats->tx_ucast_rate =
  815. ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats->stats.tx.ucast_rate));
  816. stats->rx_pkt += le32_to_cpu(tgt_stats->stats.rx.pkt);
  817. stats->rx_byte += le32_to_cpu(tgt_stats->stats.rx.byte);
  818. stats->rx_ucast_pkt += le32_to_cpu(tgt_stats->stats.rx.ucast_pkt);
  819. stats->rx_ucast_byte += le32_to_cpu(tgt_stats->stats.rx.ucast_byte);
  820. stats->rx_mcast_pkt += le32_to_cpu(tgt_stats->stats.rx.mcast_pkt);
  821. stats->rx_mcast_byte += le32_to_cpu(tgt_stats->stats.rx.mcast_byte);
  822. stats->rx_bcast_pkt += le32_to_cpu(tgt_stats->stats.rx.bcast_pkt);
  823. stats->rx_bcast_byte += le32_to_cpu(tgt_stats->stats.rx.bcast_byte);
  824. stats->rx_frgment_pkt += le32_to_cpu(tgt_stats->stats.rx.frgment_pkt);
  825. stats->rx_err += le32_to_cpu(tgt_stats->stats.rx.err);
  826. stats->rx_crc_err += le32_to_cpu(tgt_stats->stats.rx.crc_err);
  827. stats->rx_key_cache_miss +=
  828. le32_to_cpu(tgt_stats->stats.rx.key_cache_miss);
  829. stats->rx_decrypt_err += le32_to_cpu(tgt_stats->stats.rx.decrypt_err);
  830. stats->rx_dupl_frame += le32_to_cpu(tgt_stats->stats.rx.dupl_frame);
  831. stats->rx_ucast_rate =
  832. ath6kl_wmi_get_rate(a_sle32_to_cpu(tgt_stats->stats.rx.ucast_rate));
  833. ccmp_stats = &tgt_stats->stats.tkip_ccmp_stats;
  834. stats->tkip_local_mic_fail +=
  835. le32_to_cpu(ccmp_stats->tkip_local_mic_fail);
  836. stats->tkip_cnter_measures_invoked +=
  837. le32_to_cpu(ccmp_stats->tkip_cnter_measures_invoked);
  838. stats->tkip_fmt_err += le32_to_cpu(ccmp_stats->tkip_fmt_err);
  839. stats->ccmp_fmt_err += le32_to_cpu(ccmp_stats->ccmp_fmt_err);
  840. stats->ccmp_replays += le32_to_cpu(ccmp_stats->ccmp_replays);
  841. stats->pwr_save_fail_cnt +=
  842. le32_to_cpu(tgt_stats->pm_stats.pwr_save_failure_cnt);
  843. stats->noise_floor_calib =
  844. a_sle32_to_cpu(tgt_stats->noise_floor_calib);
  845. stats->cs_bmiss_cnt +=
  846. le32_to_cpu(tgt_stats->cserv_stats.cs_bmiss_cnt);
  847. stats->cs_low_rssi_cnt +=
  848. le32_to_cpu(tgt_stats->cserv_stats.cs_low_rssi_cnt);
  849. stats->cs_connect_cnt +=
  850. le16_to_cpu(tgt_stats->cserv_stats.cs_connect_cnt);
  851. stats->cs_discon_cnt +=
  852. le16_to_cpu(tgt_stats->cserv_stats.cs_discon_cnt);
  853. stats->cs_ave_beacon_rssi =
  854. a_sle16_to_cpu(tgt_stats->cserv_stats.cs_ave_beacon_rssi);
  855. stats->cs_last_roam_msec =
  856. tgt_stats->cserv_stats.cs_last_roam_msec;
  857. stats->cs_snr = tgt_stats->cserv_stats.cs_snr;
  858. stats->cs_rssi = a_sle16_to_cpu(tgt_stats->cserv_stats.cs_rssi);
  859. stats->lq_val = le32_to_cpu(tgt_stats->lq_val);
  860. stats->wow_pkt_dropped +=
  861. le32_to_cpu(tgt_stats->wow_stats.wow_pkt_dropped);
  862. stats->wow_host_pkt_wakeups +=
  863. tgt_stats->wow_stats.wow_host_pkt_wakeups;
  864. stats->wow_host_evt_wakeups +=
  865. tgt_stats->wow_stats.wow_host_evt_wakeups;
  866. stats->wow_evt_discarded +=
  867. le16_to_cpu(tgt_stats->wow_stats.wow_evt_discarded);
  868. if (test_bit(STATS_UPDATE_PEND, &ar->flag)) {
  869. clear_bit(STATS_UPDATE_PEND, &ar->flag);
  870. wake_up(&ar->event_wq);
  871. }
  872. }
  873. static void ath6kl_add_le32(__le32 *var, __le32 val)
  874. {
  875. *var = cpu_to_le32(le32_to_cpu(*var) + le32_to_cpu(val));
  876. }
  877. void ath6kl_tgt_stats_event(struct ath6kl *ar, u8 *ptr, u32 len)
  878. {
  879. struct wmi_ap_mode_stat *p = (struct wmi_ap_mode_stat *) ptr;
  880. struct wmi_ap_mode_stat *ap = &ar->ap_stats;
  881. struct wmi_per_sta_stat *st_ap, *st_p;
  882. u8 ac;
  883. if (ar->nw_type == AP_NETWORK) {
  884. if (len < sizeof(*p))
  885. return;
  886. for (ac = 0; ac < AP_MAX_NUM_STA; ac++) {
  887. st_ap = &ap->sta[ac];
  888. st_p = &p->sta[ac];
  889. ath6kl_add_le32(&st_ap->tx_bytes, st_p->tx_bytes);
  890. ath6kl_add_le32(&st_ap->tx_pkts, st_p->tx_pkts);
  891. ath6kl_add_le32(&st_ap->tx_error, st_p->tx_error);
  892. ath6kl_add_le32(&st_ap->tx_discard, st_p->tx_discard);
  893. ath6kl_add_le32(&st_ap->rx_bytes, st_p->rx_bytes);
  894. ath6kl_add_le32(&st_ap->rx_pkts, st_p->rx_pkts);
  895. ath6kl_add_le32(&st_ap->rx_error, st_p->rx_error);
  896. ath6kl_add_le32(&st_ap->rx_discard, st_p->rx_discard);
  897. }
  898. } else {
  899. ath6kl_update_target_stats(ar, ptr, len);
  900. }
  901. }
  902. void ath6kl_wakeup_event(void *dev)
  903. {
  904. struct ath6kl *ar = (struct ath6kl *) dev;
  905. wake_up(&ar->event_wq);
  906. }
  907. void ath6kl_txpwr_rx_evt(void *devt, u8 tx_pwr)
  908. {
  909. struct ath6kl *ar = (struct ath6kl *) devt;
  910. ar->tx_pwr = tx_pwr;
  911. wake_up(&ar->event_wq);
  912. }
  913. void ath6kl_pspoll_event(struct ath6kl *ar, u8 aid)
  914. {
  915. struct ath6kl_sta *conn;
  916. struct sk_buff *skb;
  917. bool psq_empty = false;
  918. conn = ath6kl_find_sta_by_aid(ar, aid);
  919. if (!conn)
  920. return;
  921. /*
  922. * Send out a packet queued on ps queue. When the ps queue
  923. * becomes empty update the PVB for this station.
  924. */
  925. spin_lock_bh(&conn->psq_lock);
  926. psq_empty = skb_queue_empty(&conn->psq);
  927. spin_unlock_bh(&conn->psq_lock);
  928. if (psq_empty)
  929. /* TODO: Send out a NULL data frame */
  930. return;
  931. spin_lock_bh(&conn->psq_lock);
  932. skb = skb_dequeue(&conn->psq);
  933. spin_unlock_bh(&conn->psq_lock);
  934. conn->sta_flags |= STA_PS_POLLED;
  935. ath6kl_data_tx(skb, ar->net_dev);
  936. conn->sta_flags &= ~STA_PS_POLLED;
  937. spin_lock_bh(&conn->psq_lock);
  938. psq_empty = skb_queue_empty(&conn->psq);
  939. spin_unlock_bh(&conn->psq_lock);
  940. if (psq_empty)
  941. ath6kl_wmi_set_pvb_cmd(ar->wmi, conn->aid, 0);
  942. }
  943. void ath6kl_dtimexpiry_event(struct ath6kl *ar)
  944. {
  945. bool mcastq_empty = false;
  946. struct sk_buff *skb;
  947. /*
  948. * If there are no associated STAs, ignore the DTIM expiry event.
  949. * There can be potential race conditions where the last associated
  950. * STA may disconnect & before the host could clear the 'Indicate
  951. * DTIM' request to the firmware, the firmware would have just
  952. * indicated a DTIM expiry event. The race is between 'clear DTIM
  953. * expiry cmd' going from the host to the firmware & the DTIM
  954. * expiry event happening from the firmware to the host.
  955. */
  956. if (!ar->sta_list_index)
  957. return;
  958. spin_lock_bh(&ar->mcastpsq_lock);
  959. mcastq_empty = skb_queue_empty(&ar->mcastpsq);
  960. spin_unlock_bh(&ar->mcastpsq_lock);
  961. if (mcastq_empty)
  962. return;
  963. /* set the STA flag to dtim_expired for the frame to go out */
  964. set_bit(DTIM_EXPIRED, &ar->flag);
  965. spin_lock_bh(&ar->mcastpsq_lock);
  966. while ((skb = skb_dequeue(&ar->mcastpsq)) != NULL) {
  967. spin_unlock_bh(&ar->mcastpsq_lock);
  968. ath6kl_data_tx(skb, ar->net_dev);
  969. spin_lock_bh(&ar->mcastpsq_lock);
  970. }
  971. spin_unlock_bh(&ar->mcastpsq_lock);
  972. clear_bit(DTIM_EXPIRED, &ar->flag);
  973. /* clear the LSB of the BitMapCtl field of the TIM IE */
  974. ath6kl_wmi_set_pvb_cmd(ar->wmi, MCAST_AID, 0);
  975. }
  976. void ath6kl_disconnect_event(struct ath6kl *ar, u8 reason, u8 *bssid,
  977. u8 assoc_resp_len, u8 *assoc_info,
  978. u16 prot_reason_status)
  979. {
  980. struct bss *wmi_ssid_node = NULL;
  981. unsigned long flags;
  982. if (ar->nw_type == AP_NETWORK) {
  983. if (!ath6kl_remove_sta(ar, bssid, prot_reason_status))
  984. return;
  985. /* if no more associated STAs, empty the mcast PS q */
  986. if (ar->sta_list_index == 0) {
  987. spin_lock_bh(&ar->mcastpsq_lock);
  988. skb_queue_purge(&ar->mcastpsq);
  989. spin_unlock_bh(&ar->mcastpsq_lock);
  990. /* clear the LSB of the TIM IE's BitMapCtl field */
  991. if (test_bit(WMI_READY, &ar->flag))
  992. ath6kl_wmi_set_pvb_cmd(ar->wmi, MCAST_AID, 0);
  993. }
  994. if (!is_broadcast_ether_addr(bssid)) {
  995. /* send event to application */
  996. cfg80211_del_sta(ar->net_dev, bssid, GFP_KERNEL);
  997. }
  998. clear_bit(CONNECTED, &ar->flag);
  999. return;
  1000. }
  1001. ath6kl_cfg80211_disconnect_event(ar, reason, bssid,
  1002. assoc_resp_len, assoc_info,
  1003. prot_reason_status);
  1004. aggr_reset_state(ar->aggr_cntxt);
  1005. del_timer(&ar->disconnect_timer);
  1006. ath6kl_dbg(ATH6KL_DBG_WLAN_CONNECT,
  1007. "disconnect reason is %d\n", reason);
  1008. /*
  1009. * If the event is due to disconnect cmd from the host, only they
  1010. * the target would stop trying to connect. Under any other
  1011. * condition, target would keep trying to connect.
  1012. */
  1013. if (reason == DISCONNECT_CMD) {
  1014. if (!ar->usr_bss_filter && test_bit(WMI_READY, &ar->flag))
  1015. ath6kl_wmi_bssfilter_cmd(ar->wmi, NONE_BSS_FILTER, 0);
  1016. } else {
  1017. set_bit(CONNECT_PEND, &ar->flag);
  1018. if (((reason == ASSOC_FAILED) &&
  1019. (prot_reason_status == 0x11)) ||
  1020. ((reason == ASSOC_FAILED) && (prot_reason_status == 0x0)
  1021. && (ar->reconnect_flag == 1))) {
  1022. set_bit(CONNECTED, &ar->flag);
  1023. return;
  1024. }
  1025. }
  1026. if ((reason == NO_NETWORK_AVAIL) && test_bit(WMI_READY, &ar->flag)) {
  1027. ath6kl_wmi_node_free(ar->wmi, bssid);
  1028. /*
  1029. * In case any other same SSID nodes are present remove it,
  1030. * since those nodes also not available now.
  1031. */
  1032. do {
  1033. /*
  1034. * Find the nodes based on SSID and remove it
  1035. *
  1036. * Note: This case will not work out for
  1037. * Hidden-SSID
  1038. */
  1039. wmi_ssid_node = ath6kl_wmi_find_ssid_node(ar->wmi,
  1040. ar->ssid,
  1041. ar->ssid_len,
  1042. false,
  1043. true);
  1044. if (wmi_ssid_node)
  1045. ath6kl_wmi_node_free(ar->wmi,
  1046. wmi_ssid_node->ni_macaddr);
  1047. } while (wmi_ssid_node);
  1048. }
  1049. /* update connect & link status atomically */
  1050. spin_lock_irqsave(&ar->lock, flags);
  1051. clear_bit(CONNECTED, &ar->flag);
  1052. netif_carrier_off(ar->net_dev);
  1053. spin_unlock_irqrestore(&ar->lock, flags);
  1054. if ((reason != CSERV_DISCONNECT) || (ar->reconnect_flag != 1))
  1055. ar->reconnect_flag = 0;
  1056. if (reason != CSERV_DISCONNECT)
  1057. ar->user_key_ctrl = 0;
  1058. netif_stop_queue(ar->net_dev);
  1059. memset(ar->bssid, 0, sizeof(ar->bssid));
  1060. ar->bss_ch = 0;
  1061. ath6kl_tx_data_cleanup(ar);
  1062. }
  1063. static int ath6kl_open(struct net_device *dev)
  1064. {
  1065. struct ath6kl *ar = ath6kl_priv(dev);
  1066. unsigned long flags;
  1067. spin_lock_irqsave(&ar->lock, flags);
  1068. set_bit(WLAN_ENABLED, &ar->flag);
  1069. if (test_bit(CONNECTED, &ar->flag)) {
  1070. netif_carrier_on(dev);
  1071. netif_wake_queue(dev);
  1072. } else
  1073. netif_carrier_off(dev);
  1074. spin_unlock_irqrestore(&ar->lock, flags);
  1075. return 0;
  1076. }
  1077. static int ath6kl_close(struct net_device *dev)
  1078. {
  1079. struct ath6kl *ar = ath6kl_priv(dev);
  1080. netif_stop_queue(dev);
  1081. ath6kl_disconnect(ar);
  1082. if (test_bit(WMI_READY, &ar->flag)) {
  1083. if (ath6kl_wmi_scanparams_cmd(ar->wmi, 0xFFFF, 0, 0, 0, 0, 0, 0,
  1084. 0, 0, 0))
  1085. return -EIO;
  1086. clear_bit(WLAN_ENABLED, &ar->flag);
  1087. }
  1088. ath6kl_cfg80211_scan_complete_event(ar, -ECANCELED);
  1089. return 0;
  1090. }
  1091. static struct net_device_stats *ath6kl_get_stats(struct net_device *dev)
  1092. {
  1093. struct ath6kl *ar = ath6kl_priv(dev);
  1094. return &ar->net_stats;
  1095. }
  1096. static struct net_device_ops ath6kl_netdev_ops = {
  1097. .ndo_open = ath6kl_open,
  1098. .ndo_stop = ath6kl_close,
  1099. .ndo_start_xmit = ath6kl_data_tx,
  1100. .ndo_get_stats = ath6kl_get_stats,
  1101. };
  1102. void init_netdev(struct net_device *dev)
  1103. {
  1104. dev->netdev_ops = &ath6kl_netdev_ops;
  1105. dev->watchdog_timeo = ATH6KL_TX_TIMEOUT;
  1106. dev->needed_headroom = ETH_HLEN;
  1107. dev->needed_headroom += sizeof(struct ath6kl_llc_snap_hdr) +
  1108. sizeof(struct wmi_data_hdr) + HTC_HDR_LENGTH
  1109. + WMI_MAX_TX_META_SZ + ATH6KL_HTC_ALIGN_BYTES;
  1110. return;
  1111. }