txrx.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869
  1. /*
  2. * Copyright (c) 2004-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  18. #include "core.h"
  19. #include "debug.h"
  20. #include "htc-ops.h"
  21. #include "trace.h"
  22. /*
  23. * tid - tid_mux0..tid_mux3
  24. * aid - tid_mux4..tid_mux7
  25. */
  26. #define ATH6KL_TID_MASK 0xf
  27. #define ATH6KL_AID_SHIFT 4
  28. static inline u8 ath6kl_get_tid(u8 tid_mux)
  29. {
  30. return tid_mux & ATH6KL_TID_MASK;
  31. }
  32. static inline u8 ath6kl_get_aid(u8 tid_mux)
  33. {
  34. return tid_mux >> ATH6KL_AID_SHIFT;
  35. }
  36. static u8 ath6kl_ibss_map_epid(struct sk_buff *skb, struct net_device *dev,
  37. u32 *map_no)
  38. {
  39. struct ath6kl *ar = ath6kl_priv(dev);
  40. struct ethhdr *eth_hdr;
  41. u32 i, ep_map = -1;
  42. u8 *datap;
  43. *map_no = 0;
  44. datap = skb->data;
  45. eth_hdr = (struct ethhdr *) (datap + sizeof(struct wmi_data_hdr));
  46. if (is_multicast_ether_addr(eth_hdr->h_dest))
  47. return ENDPOINT_2;
  48. for (i = 0; i < ar->node_num; i++) {
  49. if (memcmp(eth_hdr->h_dest, ar->node_map[i].mac_addr,
  50. ETH_ALEN) == 0) {
  51. *map_no = i + 1;
  52. ar->node_map[i].tx_pend++;
  53. return ar->node_map[i].ep_id;
  54. }
  55. if ((ep_map == -1) && !ar->node_map[i].tx_pend)
  56. ep_map = i;
  57. }
  58. if (ep_map == -1) {
  59. ep_map = ar->node_num;
  60. ar->node_num++;
  61. if (ar->node_num > MAX_NODE_NUM)
  62. return ENDPOINT_UNUSED;
  63. }
  64. memcpy(ar->node_map[ep_map].mac_addr, eth_hdr->h_dest, ETH_ALEN);
  65. for (i = ENDPOINT_2; i <= ENDPOINT_5; i++) {
  66. if (!ar->tx_pending[i]) {
  67. ar->node_map[ep_map].ep_id = i;
  68. break;
  69. }
  70. /*
  71. * No free endpoint is available, start redistribution on
  72. * the inuse endpoints.
  73. */
  74. if (i == ENDPOINT_5) {
  75. ar->node_map[ep_map].ep_id = ar->next_ep_id;
  76. ar->next_ep_id++;
  77. if (ar->next_ep_id > ENDPOINT_5)
  78. ar->next_ep_id = ENDPOINT_2;
  79. }
  80. }
  81. *map_no = ep_map + 1;
  82. ar->node_map[ep_map].tx_pend++;
  83. return ar->node_map[ep_map].ep_id;
  84. }
  85. static bool ath6kl_process_uapsdq(struct ath6kl_sta *conn,
  86. struct ath6kl_vif *vif,
  87. struct sk_buff *skb,
  88. u32 *flags)
  89. {
  90. struct ath6kl *ar = vif->ar;
  91. bool is_apsdq_empty = false;
  92. struct ethhdr *datap = (struct ethhdr *) skb->data;
  93. u8 up = 0, traffic_class, *ip_hdr;
  94. u16 ether_type;
  95. struct ath6kl_llc_snap_hdr *llc_hdr;
  96. if (conn->sta_flags & STA_PS_APSD_TRIGGER) {
  97. /*
  98. * This tx is because of a uAPSD trigger, determine
  99. * more and EOSP bit. Set EOSP if queue is empty
  100. * or sufficient frames are delivered for this trigger.
  101. */
  102. spin_lock_bh(&conn->psq_lock);
  103. if (!skb_queue_empty(&conn->apsdq))
  104. *flags |= WMI_DATA_HDR_FLAGS_MORE;
  105. else if (conn->sta_flags & STA_PS_APSD_EOSP)
  106. *flags |= WMI_DATA_HDR_FLAGS_EOSP;
  107. *flags |= WMI_DATA_HDR_FLAGS_UAPSD;
  108. spin_unlock_bh(&conn->psq_lock);
  109. return false;
  110. } else if (!conn->apsd_info) {
  111. return false;
  112. }
  113. if (test_bit(WMM_ENABLED, &vif->flags)) {
  114. ether_type = be16_to_cpu(datap->h_proto);
  115. if (is_ethertype(ether_type)) {
  116. /* packet is in DIX format */
  117. ip_hdr = (u8 *)(datap + 1);
  118. } else {
  119. /* packet is in 802.3 format */
  120. llc_hdr = (struct ath6kl_llc_snap_hdr *)
  121. (datap + 1);
  122. ether_type = be16_to_cpu(llc_hdr->eth_type);
  123. ip_hdr = (u8 *)(llc_hdr + 1);
  124. }
  125. if (ether_type == IP_ETHERTYPE)
  126. up = ath6kl_wmi_determine_user_priority(
  127. ip_hdr, 0);
  128. }
  129. traffic_class = ath6kl_wmi_get_traffic_class(up);
  130. if ((conn->apsd_info & (1 << traffic_class)) == 0)
  131. return false;
  132. /* Queue the frames if the STA is sleeping */
  133. spin_lock_bh(&conn->psq_lock);
  134. is_apsdq_empty = skb_queue_empty(&conn->apsdq);
  135. skb_queue_tail(&conn->apsdq, skb);
  136. spin_unlock_bh(&conn->psq_lock);
  137. /*
  138. * If this is the first pkt getting queued
  139. * for this STA, update the PVB for this STA
  140. */
  141. if (is_apsdq_empty) {
  142. ath6kl_wmi_set_apsd_bfrd_traf(ar->wmi,
  143. vif->fw_vif_idx,
  144. conn->aid, 1, 0);
  145. }
  146. *flags |= WMI_DATA_HDR_FLAGS_UAPSD;
  147. return true;
  148. }
  149. static bool ath6kl_process_psq(struct ath6kl_sta *conn,
  150. struct ath6kl_vif *vif,
  151. struct sk_buff *skb,
  152. u32 *flags)
  153. {
  154. bool is_psq_empty = false;
  155. struct ath6kl *ar = vif->ar;
  156. if (conn->sta_flags & STA_PS_POLLED) {
  157. spin_lock_bh(&conn->psq_lock);
  158. if (!skb_queue_empty(&conn->psq))
  159. *flags |= WMI_DATA_HDR_FLAGS_MORE;
  160. spin_unlock_bh(&conn->psq_lock);
  161. return false;
  162. }
  163. /* Queue the frames if the STA is sleeping */
  164. spin_lock_bh(&conn->psq_lock);
  165. is_psq_empty = skb_queue_empty(&conn->psq);
  166. skb_queue_tail(&conn->psq, skb);
  167. spin_unlock_bh(&conn->psq_lock);
  168. /*
  169. * If this is the first pkt getting queued
  170. * for this STA, update the PVB for this
  171. * STA.
  172. */
  173. if (is_psq_empty)
  174. ath6kl_wmi_set_pvb_cmd(ar->wmi,
  175. vif->fw_vif_idx,
  176. conn->aid, 1);
  177. return true;
  178. }
  179. static bool ath6kl_powersave_ap(struct ath6kl_vif *vif, struct sk_buff *skb,
  180. u32 *flags)
  181. {
  182. struct ethhdr *datap = (struct ethhdr *) skb->data;
  183. struct ath6kl_sta *conn = NULL;
  184. bool ps_queued = false;
  185. struct ath6kl *ar = vif->ar;
  186. if (is_multicast_ether_addr(datap->h_dest)) {
  187. u8 ctr = 0;
  188. bool q_mcast = false;
  189. for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
  190. if (ar->sta_list[ctr].sta_flags & STA_PS_SLEEP) {
  191. q_mcast = true;
  192. break;
  193. }
  194. }
  195. if (q_mcast) {
  196. /*
  197. * If this transmit is not because of a Dtim Expiry
  198. * q it.
  199. */
  200. if (!test_bit(DTIM_EXPIRED, &vif->flags)) {
  201. bool is_mcastq_empty = false;
  202. spin_lock_bh(&ar->mcastpsq_lock);
  203. is_mcastq_empty =
  204. skb_queue_empty(&ar->mcastpsq);
  205. skb_queue_tail(&ar->mcastpsq, skb);
  206. spin_unlock_bh(&ar->mcastpsq_lock);
  207. /*
  208. * If this is the first Mcast pkt getting
  209. * queued indicate to the target to set the
  210. * BitmapControl LSB of the TIM IE.
  211. */
  212. if (is_mcastq_empty)
  213. ath6kl_wmi_set_pvb_cmd(ar->wmi,
  214. vif->fw_vif_idx,
  215. MCAST_AID, 1);
  216. ps_queued = true;
  217. } else {
  218. /*
  219. * This transmit is because of Dtim expiry.
  220. * Determine if MoreData bit has to be set.
  221. */
  222. spin_lock_bh(&ar->mcastpsq_lock);
  223. if (!skb_queue_empty(&ar->mcastpsq))
  224. *flags |= WMI_DATA_HDR_FLAGS_MORE;
  225. spin_unlock_bh(&ar->mcastpsq_lock);
  226. }
  227. }
  228. } else {
  229. conn = ath6kl_find_sta(vif, datap->h_dest);
  230. if (!conn) {
  231. dev_kfree_skb(skb);
  232. /* Inform the caller that the skb is consumed */
  233. return true;
  234. }
  235. if (conn->sta_flags & STA_PS_SLEEP) {
  236. ps_queued = ath6kl_process_uapsdq(conn,
  237. vif, skb, flags);
  238. if (!(*flags & WMI_DATA_HDR_FLAGS_UAPSD))
  239. ps_queued = ath6kl_process_psq(conn,
  240. vif, skb, flags);
  241. }
  242. }
  243. return ps_queued;
  244. }
  245. /* Tx functions */
  246. int ath6kl_control_tx(void *devt, struct sk_buff *skb,
  247. enum htc_endpoint_id eid)
  248. {
  249. struct ath6kl *ar = devt;
  250. int status = 0;
  251. struct ath6kl_cookie *cookie = NULL;
  252. trace_ath6kl_wmi_cmd(skb->data, skb->len);
  253. if (WARN_ON_ONCE(ar->state == ATH6KL_STATE_WOW)) {
  254. dev_kfree_skb(skb);
  255. return -EACCES;
  256. }
  257. if (WARN_ON_ONCE(eid == ENDPOINT_UNUSED ||
  258. eid >= ENDPOINT_MAX)) {
  259. status = -EINVAL;
  260. goto fail_ctrl_tx;
  261. }
  262. spin_lock_bh(&ar->lock);
  263. ath6kl_dbg(ATH6KL_DBG_WLAN_TX,
  264. "%s: skb=0x%p, len=0x%x eid =%d\n", __func__,
  265. skb, skb->len, eid);
  266. if (test_bit(WMI_CTRL_EP_FULL, &ar->flag) && (eid == ar->ctrl_ep)) {
  267. /*
  268. * Control endpoint is full, don't allocate resources, we
  269. * are just going to drop this packet.
  270. */
  271. cookie = NULL;
  272. ath6kl_err("wmi ctrl ep full, dropping pkt : 0x%p, len:%d\n",
  273. skb, skb->len);
  274. } else {
  275. cookie = ath6kl_alloc_cookie(ar);
  276. }
  277. if (cookie == NULL) {
  278. spin_unlock_bh(&ar->lock);
  279. status = -ENOMEM;
  280. goto fail_ctrl_tx;
  281. }
  282. ar->tx_pending[eid]++;
  283. if (eid != ar->ctrl_ep)
  284. ar->total_tx_data_pend++;
  285. spin_unlock_bh(&ar->lock);
  286. cookie->skb = skb;
  287. cookie->map_no = 0;
  288. set_htc_pkt_info(&cookie->htc_pkt, cookie, skb->data, skb->len,
  289. eid, ATH6KL_CONTROL_PKT_TAG);
  290. cookie->htc_pkt.skb = skb;
  291. /*
  292. * This interface is asynchronous, if there is an error, cleanup
  293. * will happen in the TX completion callback.
  294. */
  295. ath6kl_htc_tx(ar->htc_target, &cookie->htc_pkt);
  296. return 0;
  297. fail_ctrl_tx:
  298. dev_kfree_skb(skb);
  299. return status;
  300. }
  301. netdev_tx_t ath6kl_data_tx(struct sk_buff *skb, struct net_device *dev)
  302. {
  303. struct ath6kl *ar = ath6kl_priv(dev);
  304. struct ath6kl_cookie *cookie = NULL;
  305. enum htc_endpoint_id eid = ENDPOINT_UNUSED;
  306. struct ath6kl_vif *vif = netdev_priv(dev);
  307. u32 map_no = 0;
  308. u16 htc_tag = ATH6KL_DATA_PKT_TAG;
  309. u8 ac = 99; /* initialize to unmapped ac */
  310. bool chk_adhoc_ps_mapping = false;
  311. int ret;
  312. struct wmi_tx_meta_v2 meta_v2;
  313. void *meta;
  314. u8 csum_start = 0, csum_dest = 0, csum = skb->ip_summed;
  315. u8 meta_ver = 0;
  316. u32 flags = 0;
  317. ath6kl_dbg(ATH6KL_DBG_WLAN_TX,
  318. "%s: skb=0x%p, data=0x%p, len=0x%x\n", __func__,
  319. skb, skb->data, skb->len);
  320. /* If target is not associated */
  321. if (!test_bit(CONNECTED, &vif->flags))
  322. goto fail_tx;
  323. if (WARN_ON_ONCE(ar->state != ATH6KL_STATE_ON))
  324. goto fail_tx;
  325. if (!test_bit(WMI_READY, &ar->flag))
  326. goto fail_tx;
  327. /* AP mode Power saving processing */
  328. if (vif->nw_type == AP_NETWORK) {
  329. if (ath6kl_powersave_ap(vif, skb, &flags))
  330. return 0;
  331. }
  332. if (test_bit(WMI_ENABLED, &ar->flag)) {
  333. if ((dev->features & NETIF_F_IP_CSUM) &&
  334. (csum == CHECKSUM_PARTIAL)) {
  335. csum_start = skb->csum_start -
  336. (skb_network_header(skb) - skb->head) +
  337. sizeof(struct ath6kl_llc_snap_hdr);
  338. csum_dest = skb->csum_offset + csum_start;
  339. }
  340. if (skb_cow_head(skb, dev->needed_headroom)) {
  341. dev->stats.tx_dropped++;
  342. kfree_skb(skb);
  343. return 0;
  344. }
  345. if (ath6kl_wmi_dix_2_dot3(ar->wmi, skb)) {
  346. ath6kl_err("ath6kl_wmi_dix_2_dot3 failed\n");
  347. goto fail_tx;
  348. }
  349. if ((dev->features & NETIF_F_IP_CSUM) &&
  350. (csum == CHECKSUM_PARTIAL)) {
  351. meta_v2.csum_start = csum_start;
  352. meta_v2.csum_dest = csum_dest;
  353. /* instruct target to calculate checksum */
  354. meta_v2.csum_flags = WMI_META_V2_FLAG_CSUM_OFFLOAD;
  355. meta_ver = WMI_META_VERSION_2;
  356. meta = &meta_v2;
  357. } else {
  358. meta_ver = 0;
  359. meta = NULL;
  360. }
  361. ret = ath6kl_wmi_data_hdr_add(ar->wmi, skb,
  362. DATA_MSGTYPE, flags, 0,
  363. meta_ver,
  364. meta, vif->fw_vif_idx);
  365. if (ret) {
  366. ath6kl_warn("failed to add wmi data header:%d\n"
  367. , ret);
  368. goto fail_tx;
  369. }
  370. if ((vif->nw_type == ADHOC_NETWORK) &&
  371. ar->ibss_ps_enable && test_bit(CONNECTED, &vif->flags))
  372. chk_adhoc_ps_mapping = true;
  373. else {
  374. /* get the stream mapping */
  375. ret = ath6kl_wmi_implicit_create_pstream(ar->wmi,
  376. vif->fw_vif_idx, skb,
  377. 0, test_bit(WMM_ENABLED, &vif->flags), &ac);
  378. if (ret)
  379. goto fail_tx;
  380. }
  381. } else {
  382. goto fail_tx;
  383. }
  384. spin_lock_bh(&ar->lock);
  385. if (chk_adhoc_ps_mapping)
  386. eid = ath6kl_ibss_map_epid(skb, dev, &map_no);
  387. else
  388. eid = ar->ac2ep_map[ac];
  389. if (eid == 0 || eid == ENDPOINT_UNUSED) {
  390. ath6kl_err("eid %d is not mapped!\n", eid);
  391. spin_unlock_bh(&ar->lock);
  392. goto fail_tx;
  393. }
  394. /* allocate resource for this packet */
  395. cookie = ath6kl_alloc_cookie(ar);
  396. if (!cookie) {
  397. spin_unlock_bh(&ar->lock);
  398. goto fail_tx;
  399. }
  400. /* update counts while the lock is held */
  401. ar->tx_pending[eid]++;
  402. ar->total_tx_data_pend++;
  403. spin_unlock_bh(&ar->lock);
  404. if (!IS_ALIGNED((unsigned long) skb->data - HTC_HDR_LENGTH, 4) &&
  405. skb_cloned(skb)) {
  406. /*
  407. * We will touch (move the buffer data to align it. Since the
  408. * skb buffer is cloned and not only the header is changed, we
  409. * have to copy it to allow the changes. Since we are copying
  410. * the data here, we may as well align it by reserving suitable
  411. * headroom to avoid the memmove in ath6kl_htc_tx_buf_align().
  412. */
  413. struct sk_buff *nskb;
  414. nskb = skb_copy_expand(skb, HTC_HDR_LENGTH, 0, GFP_ATOMIC);
  415. if (nskb == NULL)
  416. goto fail_tx;
  417. kfree_skb(skb);
  418. skb = nskb;
  419. }
  420. cookie->skb = skb;
  421. cookie->map_no = map_no;
  422. set_htc_pkt_info(&cookie->htc_pkt, cookie, skb->data, skb->len,
  423. eid, htc_tag);
  424. cookie->htc_pkt.skb = skb;
  425. ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, __func__, "tx ",
  426. skb->data, skb->len);
  427. /*
  428. * HTC interface is asynchronous, if this fails, cleanup will
  429. * happen in the ath6kl_tx_complete callback.
  430. */
  431. ath6kl_htc_tx(ar->htc_target, &cookie->htc_pkt);
  432. return 0;
  433. fail_tx:
  434. dev_kfree_skb(skb);
  435. dev->stats.tx_dropped++;
  436. dev->stats.tx_aborted_errors++;
  437. return 0;
  438. }
  439. /* indicate tx activity or inactivity on a WMI stream */
  440. void ath6kl_indicate_tx_activity(void *devt, u8 traffic_class, bool active)
  441. {
  442. struct ath6kl *ar = devt;
  443. enum htc_endpoint_id eid;
  444. int i;
  445. eid = ar->ac2ep_map[traffic_class];
  446. if (!test_bit(WMI_ENABLED, &ar->flag))
  447. goto notify_htc;
  448. spin_lock_bh(&ar->lock);
  449. ar->ac_stream_active[traffic_class] = active;
  450. if (active) {
  451. /*
  452. * Keep track of the active stream with the highest
  453. * priority.
  454. */
  455. if (ar->ac_stream_pri_map[traffic_class] >
  456. ar->hiac_stream_active_pri)
  457. /* set the new highest active priority */
  458. ar->hiac_stream_active_pri =
  459. ar->ac_stream_pri_map[traffic_class];
  460. } else {
  461. /*
  462. * We may have to search for the next active stream
  463. * that is the highest priority.
  464. */
  465. if (ar->hiac_stream_active_pri ==
  466. ar->ac_stream_pri_map[traffic_class]) {
  467. /*
  468. * The highest priority stream just went inactive
  469. * reset and search for the "next" highest "active"
  470. * priority stream.
  471. */
  472. ar->hiac_stream_active_pri = 0;
  473. for (i = 0; i < WMM_NUM_AC; i++) {
  474. if (ar->ac_stream_active[i] &&
  475. (ar->ac_stream_pri_map[i] >
  476. ar->hiac_stream_active_pri))
  477. /*
  478. * Set the new highest active
  479. * priority.
  480. */
  481. ar->hiac_stream_active_pri =
  482. ar->ac_stream_pri_map[i];
  483. }
  484. }
  485. }
  486. spin_unlock_bh(&ar->lock);
  487. notify_htc:
  488. /* notify HTC, this may cause credit distribution changes */
  489. ath6kl_htc_activity_changed(ar->htc_target, eid, active);
  490. }
  491. enum htc_send_full_action ath6kl_tx_queue_full(struct htc_target *target,
  492. struct htc_packet *packet)
  493. {
  494. struct ath6kl *ar = target->dev->ar;
  495. struct ath6kl_vif *vif;
  496. enum htc_endpoint_id endpoint = packet->endpoint;
  497. enum htc_send_full_action action = HTC_SEND_FULL_KEEP;
  498. if (endpoint == ar->ctrl_ep) {
  499. /*
  500. * Under normal WMI if this is getting full, then something
  501. * is running rampant the host should not be exhausting the
  502. * WMI queue with too many commands the only exception to
  503. * this is during testing using endpointping.
  504. */
  505. set_bit(WMI_CTRL_EP_FULL, &ar->flag);
  506. ath6kl_err("wmi ctrl ep is full\n");
  507. ath6kl_recovery_err_notify(ar, ATH6KL_FW_EP_FULL);
  508. return action;
  509. }
  510. if (packet->info.tx.tag == ATH6KL_CONTROL_PKT_TAG)
  511. return action;
  512. /*
  513. * The last MAX_HI_COOKIE_NUM "batch" of cookies are reserved for
  514. * the highest active stream.
  515. */
  516. if (ar->ac_stream_pri_map[ar->ep2ac_map[endpoint]] <
  517. ar->hiac_stream_active_pri &&
  518. ar->cookie_count <=
  519. target->endpoint[endpoint].tx_drop_packet_threshold)
  520. /*
  521. * Give preference to the highest priority stream by
  522. * dropping the packets which overflowed.
  523. */
  524. action = HTC_SEND_FULL_DROP;
  525. /* FIXME: Locking */
  526. spin_lock_bh(&ar->list_lock);
  527. list_for_each_entry(vif, &ar->vif_list, list) {
  528. if (vif->nw_type == ADHOC_NETWORK ||
  529. action != HTC_SEND_FULL_DROP) {
  530. spin_unlock_bh(&ar->list_lock);
  531. set_bit(NETQ_STOPPED, &vif->flags);
  532. netif_stop_queue(vif->ndev);
  533. return action;
  534. }
  535. }
  536. spin_unlock_bh(&ar->list_lock);
  537. return action;
  538. }
  539. /* TODO this needs to be looked at */
  540. static void ath6kl_tx_clear_node_map(struct ath6kl_vif *vif,
  541. enum htc_endpoint_id eid, u32 map_no)
  542. {
  543. struct ath6kl *ar = vif->ar;
  544. u32 i;
  545. if (vif->nw_type != ADHOC_NETWORK)
  546. return;
  547. if (!ar->ibss_ps_enable)
  548. return;
  549. if (eid == ar->ctrl_ep)
  550. return;
  551. if (map_no == 0)
  552. return;
  553. map_no--;
  554. ar->node_map[map_no].tx_pend--;
  555. if (ar->node_map[map_no].tx_pend)
  556. return;
  557. if (map_no != (ar->node_num - 1))
  558. return;
  559. for (i = ar->node_num; i > 0; i--) {
  560. if (ar->node_map[i - 1].tx_pend)
  561. break;
  562. memset(&ar->node_map[i - 1], 0,
  563. sizeof(struct ath6kl_node_mapping));
  564. ar->node_num--;
  565. }
  566. }
  567. void ath6kl_tx_complete(struct htc_target *target,
  568. struct list_head *packet_queue)
  569. {
  570. struct ath6kl *ar = target->dev->ar;
  571. struct sk_buff_head skb_queue;
  572. struct htc_packet *packet;
  573. struct sk_buff *skb;
  574. struct ath6kl_cookie *ath6kl_cookie;
  575. u32 map_no = 0;
  576. int status;
  577. enum htc_endpoint_id eid;
  578. bool wake_event = false;
  579. bool flushing[ATH6KL_VIF_MAX] = {false};
  580. u8 if_idx;
  581. struct ath6kl_vif *vif;
  582. skb_queue_head_init(&skb_queue);
  583. /* lock the driver as we update internal state */
  584. spin_lock_bh(&ar->lock);
  585. /* reap completed packets */
  586. while (!list_empty(packet_queue)) {
  587. packet = list_first_entry(packet_queue, struct htc_packet,
  588. list);
  589. list_del(&packet->list);
  590. if (WARN_ON_ONCE(packet->endpoint == ENDPOINT_UNUSED ||
  591. packet->endpoint >= ENDPOINT_MAX))
  592. continue;
  593. ath6kl_cookie = (struct ath6kl_cookie *)packet->pkt_cntxt;
  594. if (WARN_ON_ONCE(!ath6kl_cookie))
  595. continue;
  596. status = packet->status;
  597. skb = ath6kl_cookie->skb;
  598. eid = packet->endpoint;
  599. map_no = ath6kl_cookie->map_no;
  600. if (WARN_ON_ONCE(!skb || !skb->data)) {
  601. dev_kfree_skb(skb);
  602. ath6kl_free_cookie(ar, ath6kl_cookie);
  603. continue;
  604. }
  605. __skb_queue_tail(&skb_queue, skb);
  606. if (WARN_ON_ONCE(!status && (packet->act_len != skb->len))) {
  607. ath6kl_free_cookie(ar, ath6kl_cookie);
  608. continue;
  609. }
  610. ar->tx_pending[eid]--;
  611. if (eid != ar->ctrl_ep)
  612. ar->total_tx_data_pend--;
  613. if (eid == ar->ctrl_ep) {
  614. if (test_bit(WMI_CTRL_EP_FULL, &ar->flag))
  615. clear_bit(WMI_CTRL_EP_FULL, &ar->flag);
  616. if (ar->tx_pending[eid] == 0)
  617. wake_event = true;
  618. }
  619. if (eid == ar->ctrl_ep) {
  620. if_idx = wmi_cmd_hdr_get_if_idx(
  621. (struct wmi_cmd_hdr *) packet->buf);
  622. } else {
  623. if_idx = wmi_data_hdr_get_if_idx(
  624. (struct wmi_data_hdr *) packet->buf);
  625. }
  626. vif = ath6kl_get_vif_by_index(ar, if_idx);
  627. if (!vif) {
  628. ath6kl_free_cookie(ar, ath6kl_cookie);
  629. continue;
  630. }
  631. if (status) {
  632. if (status == -ECANCELED)
  633. /* a packet was flushed */
  634. flushing[if_idx] = true;
  635. vif->ndev->stats.tx_errors++;
  636. if (status != -ENOSPC && status != -ECANCELED)
  637. ath6kl_warn("tx complete error: %d\n", status);
  638. ath6kl_dbg(ATH6KL_DBG_WLAN_TX,
  639. "%s: skb=0x%p data=0x%p len=0x%x eid=%d %s\n",
  640. __func__, skb, packet->buf, packet->act_len,
  641. eid, "error!");
  642. } else {
  643. ath6kl_dbg(ATH6KL_DBG_WLAN_TX,
  644. "%s: skb=0x%p data=0x%p len=0x%x eid=%d %s\n",
  645. __func__, skb, packet->buf, packet->act_len,
  646. eid, "OK");
  647. flushing[if_idx] = false;
  648. vif->ndev->stats.tx_packets++;
  649. vif->ndev->stats.tx_bytes += skb->len;
  650. }
  651. ath6kl_tx_clear_node_map(vif, eid, map_no);
  652. ath6kl_free_cookie(ar, ath6kl_cookie);
  653. if (test_bit(NETQ_STOPPED, &vif->flags))
  654. clear_bit(NETQ_STOPPED, &vif->flags);
  655. }
  656. spin_unlock_bh(&ar->lock);
  657. __skb_queue_purge(&skb_queue);
  658. /* FIXME: Locking */
  659. spin_lock_bh(&ar->list_lock);
  660. list_for_each_entry(vif, &ar->vif_list, list) {
  661. if (test_bit(CONNECTED, &vif->flags) &&
  662. !flushing[vif->fw_vif_idx]) {
  663. spin_unlock_bh(&ar->list_lock);
  664. netif_wake_queue(vif->ndev);
  665. spin_lock_bh(&ar->list_lock);
  666. }
  667. }
  668. spin_unlock_bh(&ar->list_lock);
  669. if (wake_event)
  670. wake_up(&ar->event_wq);
  671. return;
  672. }
  673. void ath6kl_tx_data_cleanup(struct ath6kl *ar)
  674. {
  675. int i;
  676. /* flush all the data (non-control) streams */
  677. for (i = 0; i < WMM_NUM_AC; i++)
  678. ath6kl_htc_flush_txep(ar->htc_target, ar->ac2ep_map[i],
  679. ATH6KL_DATA_PKT_TAG);
  680. }
  681. /* Rx functions */
  682. static void ath6kl_deliver_frames_to_nw_stack(struct net_device *dev,
  683. struct sk_buff *skb)
  684. {
  685. if (!skb)
  686. return;
  687. skb->dev = dev;
  688. if (!(skb->dev->flags & IFF_UP)) {
  689. dev_kfree_skb(skb);
  690. return;
  691. }
  692. skb->protocol = eth_type_trans(skb, skb->dev);
  693. netif_rx(skb);
  694. }
  695. static void ath6kl_alloc_netbufs(struct sk_buff_head *q, u16 num)
  696. {
  697. struct sk_buff *skb;
  698. while (num) {
  699. skb = ath6kl_buf_alloc(ATH6KL_BUFFER_SIZE);
  700. if (!skb) {
  701. ath6kl_err("netbuf allocation failed\n");
  702. return;
  703. }
  704. skb_queue_tail(q, skb);
  705. num--;
  706. }
  707. }
  708. static struct sk_buff *aggr_get_free_skb(struct aggr_info *p_aggr)
  709. {
  710. struct sk_buff *skb = NULL;
  711. if (skb_queue_len(&p_aggr->rx_amsdu_freeq) <
  712. (AGGR_NUM_OF_FREE_NETBUFS >> 2))
  713. ath6kl_alloc_netbufs(&p_aggr->rx_amsdu_freeq,
  714. AGGR_NUM_OF_FREE_NETBUFS);
  715. skb = skb_dequeue(&p_aggr->rx_amsdu_freeq);
  716. return skb;
  717. }
  718. void ath6kl_rx_refill(struct htc_target *target, enum htc_endpoint_id endpoint)
  719. {
  720. struct ath6kl *ar = target->dev->ar;
  721. struct sk_buff *skb;
  722. int rx_buf;
  723. int n_buf_refill;
  724. struct htc_packet *packet;
  725. struct list_head queue;
  726. n_buf_refill = ATH6KL_MAX_RX_BUFFERS -
  727. ath6kl_htc_get_rxbuf_num(ar->htc_target, endpoint);
  728. if (n_buf_refill <= 0)
  729. return;
  730. INIT_LIST_HEAD(&queue);
  731. ath6kl_dbg(ATH6KL_DBG_WLAN_RX,
  732. "%s: providing htc with %d buffers at eid=%d\n",
  733. __func__, n_buf_refill, endpoint);
  734. for (rx_buf = 0; rx_buf < n_buf_refill; rx_buf++) {
  735. skb = ath6kl_buf_alloc(ATH6KL_BUFFER_SIZE);
  736. if (!skb)
  737. break;
  738. packet = (struct htc_packet *) skb->head;
  739. if (!IS_ALIGNED((unsigned long) skb->data, 4)) {
  740. size_t len = skb_headlen(skb);
  741. skb->data = PTR_ALIGN(skb->data - 4, 4);
  742. skb_set_tail_pointer(skb, len);
  743. }
  744. set_htc_rxpkt_info(packet, skb, skb->data,
  745. ATH6KL_BUFFER_SIZE, endpoint);
  746. packet->skb = skb;
  747. list_add_tail(&packet->list, &queue);
  748. }
  749. if (!list_empty(&queue))
  750. ath6kl_htc_add_rxbuf_multiple(ar->htc_target, &queue);
  751. }
  752. void ath6kl_refill_amsdu_rxbufs(struct ath6kl *ar, int count)
  753. {
  754. struct htc_packet *packet;
  755. struct sk_buff *skb;
  756. while (count) {
  757. skb = ath6kl_buf_alloc(ATH6KL_AMSDU_BUFFER_SIZE);
  758. if (!skb)
  759. return;
  760. packet = (struct htc_packet *) skb->head;
  761. if (!IS_ALIGNED((unsigned long) skb->data, 4)) {
  762. size_t len = skb_headlen(skb);
  763. skb->data = PTR_ALIGN(skb->data - 4, 4);
  764. skb_set_tail_pointer(skb, len);
  765. }
  766. set_htc_rxpkt_info(packet, skb, skb->data,
  767. ATH6KL_AMSDU_BUFFER_SIZE, 0);
  768. packet->skb = skb;
  769. spin_lock_bh(&ar->lock);
  770. list_add_tail(&packet->list, &ar->amsdu_rx_buffer_queue);
  771. spin_unlock_bh(&ar->lock);
  772. count--;
  773. }
  774. }
  775. /*
  776. * Callback to allocate a receive buffer for a pending packet. We use a
  777. * pre-allocated list of buffers of maximum AMSDU size (4K).
  778. */
  779. struct htc_packet *ath6kl_alloc_amsdu_rxbuf(struct htc_target *target,
  780. enum htc_endpoint_id endpoint,
  781. int len)
  782. {
  783. struct ath6kl *ar = target->dev->ar;
  784. struct htc_packet *packet = NULL;
  785. struct list_head *pkt_pos;
  786. int refill_cnt = 0, depth = 0;
  787. ath6kl_dbg(ATH6KL_DBG_WLAN_RX, "%s: eid=%d, len:%d\n",
  788. __func__, endpoint, len);
  789. if ((len <= ATH6KL_BUFFER_SIZE) ||
  790. (len > ATH6KL_AMSDU_BUFFER_SIZE))
  791. return NULL;
  792. spin_lock_bh(&ar->lock);
  793. if (list_empty(&ar->amsdu_rx_buffer_queue)) {
  794. spin_unlock_bh(&ar->lock);
  795. refill_cnt = ATH6KL_MAX_AMSDU_RX_BUFFERS;
  796. goto refill_buf;
  797. }
  798. packet = list_first_entry(&ar->amsdu_rx_buffer_queue,
  799. struct htc_packet, list);
  800. list_del(&packet->list);
  801. list_for_each(pkt_pos, &ar->amsdu_rx_buffer_queue)
  802. depth++;
  803. refill_cnt = ATH6KL_MAX_AMSDU_RX_BUFFERS - depth;
  804. spin_unlock_bh(&ar->lock);
  805. /* set actual endpoint ID */
  806. packet->endpoint = endpoint;
  807. refill_buf:
  808. if (refill_cnt >= ATH6KL_AMSDU_REFILL_THRESHOLD)
  809. ath6kl_refill_amsdu_rxbufs(ar, refill_cnt);
  810. return packet;
  811. }
  812. static void aggr_slice_amsdu(struct aggr_info *p_aggr,
  813. struct rxtid *rxtid, struct sk_buff *skb)
  814. {
  815. struct sk_buff *new_skb;
  816. struct ethhdr *hdr;
  817. u16 frame_8023_len, payload_8023_len, mac_hdr_len, amsdu_len;
  818. u8 *framep;
  819. mac_hdr_len = sizeof(struct ethhdr);
  820. framep = skb->data + mac_hdr_len;
  821. amsdu_len = skb->len - mac_hdr_len;
  822. while (amsdu_len > mac_hdr_len) {
  823. hdr = (struct ethhdr *) framep;
  824. payload_8023_len = be16_to_cpu(hdr->h_proto);
  825. if (payload_8023_len < MIN_MSDU_SUBFRAME_PAYLOAD_LEN ||
  826. payload_8023_len > MAX_MSDU_SUBFRAME_PAYLOAD_LEN) {
  827. ath6kl_err("802.3 AMSDU frame bound check failed. len %d\n",
  828. payload_8023_len);
  829. break;
  830. }
  831. frame_8023_len = payload_8023_len + mac_hdr_len;
  832. new_skb = aggr_get_free_skb(p_aggr);
  833. if (!new_skb) {
  834. ath6kl_err("no buffer available\n");
  835. break;
  836. }
  837. memcpy(new_skb->data, framep, frame_8023_len);
  838. skb_put(new_skb, frame_8023_len);
  839. if (ath6kl_wmi_dot3_2_dix(new_skb)) {
  840. ath6kl_err("dot3_2_dix error\n");
  841. dev_kfree_skb(new_skb);
  842. break;
  843. }
  844. skb_queue_tail(&rxtid->q, new_skb);
  845. /* Is this the last subframe within this aggregate ? */
  846. if ((amsdu_len - frame_8023_len) == 0)
  847. break;
  848. /* Add the length of A-MSDU subframe padding bytes -
  849. * Round to nearest word.
  850. */
  851. frame_8023_len = ALIGN(frame_8023_len, 4);
  852. framep += frame_8023_len;
  853. amsdu_len -= frame_8023_len;
  854. }
  855. dev_kfree_skb(skb);
  856. }
  857. static void aggr_deque_frms(struct aggr_info_conn *agg_conn, u8 tid,
  858. u16 seq_no, u8 order)
  859. {
  860. struct sk_buff *skb;
  861. struct rxtid *rxtid;
  862. struct skb_hold_q *node;
  863. u16 idx, idx_end, seq_end;
  864. struct rxtid_stats *stats;
  865. rxtid = &agg_conn->rx_tid[tid];
  866. stats = &agg_conn->stat[tid];
  867. spin_lock_bh(&rxtid->lock);
  868. idx = AGGR_WIN_IDX(rxtid->seq_next, rxtid->hold_q_sz);
  869. /*
  870. * idx_end is typically the last possible frame in the window,
  871. * but changes to 'the' seq_no, when BAR comes. If seq_no
  872. * is non-zero, we will go up to that and stop.
  873. * Note: last seq no in current window will occupy the same
  874. * index position as index that is just previous to start.
  875. * An imp point : if win_sz is 7, for seq_no space of 4095,
  876. * then, there would be holes when sequence wrap around occurs.
  877. * Target should judiciously choose the win_sz, based on
  878. * this condition. For 4095, (TID_WINDOW_SZ = 2 x win_sz
  879. * 2, 4, 8, 16 win_sz works fine).
  880. * We must deque from "idx" to "idx_end", including both.
  881. */
  882. seq_end = seq_no ? seq_no : rxtid->seq_next;
  883. idx_end = AGGR_WIN_IDX(seq_end, rxtid->hold_q_sz);
  884. do {
  885. node = &rxtid->hold_q[idx];
  886. if ((order == 1) && (!node->skb))
  887. break;
  888. if (node->skb) {
  889. if (node->is_amsdu)
  890. aggr_slice_amsdu(agg_conn->aggr_info, rxtid,
  891. node->skb);
  892. else
  893. skb_queue_tail(&rxtid->q, node->skb);
  894. node->skb = NULL;
  895. } else {
  896. stats->num_hole++;
  897. }
  898. rxtid->seq_next = ATH6KL_NEXT_SEQ_NO(rxtid->seq_next);
  899. idx = AGGR_WIN_IDX(rxtid->seq_next, rxtid->hold_q_sz);
  900. } while (idx != idx_end);
  901. spin_unlock_bh(&rxtid->lock);
  902. stats->num_delivered += skb_queue_len(&rxtid->q);
  903. while ((skb = skb_dequeue(&rxtid->q)))
  904. ath6kl_deliver_frames_to_nw_stack(agg_conn->dev, skb);
  905. }
  906. static bool aggr_process_recv_frm(struct aggr_info_conn *agg_conn, u8 tid,
  907. u16 seq_no,
  908. bool is_amsdu, struct sk_buff *frame)
  909. {
  910. struct rxtid *rxtid;
  911. struct rxtid_stats *stats;
  912. struct sk_buff *skb;
  913. struct skb_hold_q *node;
  914. u16 idx, st, cur, end;
  915. bool is_queued = false;
  916. u16 extended_end;
  917. rxtid = &agg_conn->rx_tid[tid];
  918. stats = &agg_conn->stat[tid];
  919. stats->num_into_aggr++;
  920. if (!rxtid->aggr) {
  921. if (is_amsdu) {
  922. aggr_slice_amsdu(agg_conn->aggr_info, rxtid, frame);
  923. is_queued = true;
  924. stats->num_amsdu++;
  925. while ((skb = skb_dequeue(&rxtid->q)))
  926. ath6kl_deliver_frames_to_nw_stack(agg_conn->dev,
  927. skb);
  928. }
  929. return is_queued;
  930. }
  931. /* Check the incoming sequence no, if it's in the window */
  932. st = rxtid->seq_next;
  933. cur = seq_no;
  934. end = (st + rxtid->hold_q_sz-1) & ATH6KL_MAX_SEQ_NO;
  935. if (((st < end) && (cur < st || cur > end)) ||
  936. ((st > end) && (cur > end) && (cur < st))) {
  937. extended_end = (end + rxtid->hold_q_sz - 1) &
  938. ATH6KL_MAX_SEQ_NO;
  939. if (((end < extended_end) &&
  940. (cur < end || cur > extended_end)) ||
  941. ((end > extended_end) && (cur > extended_end) &&
  942. (cur < end))) {
  943. aggr_deque_frms(agg_conn, tid, 0, 0);
  944. spin_lock_bh(&rxtid->lock);
  945. if (cur >= rxtid->hold_q_sz - 1)
  946. rxtid->seq_next = cur - (rxtid->hold_q_sz - 1);
  947. else
  948. rxtid->seq_next = ATH6KL_MAX_SEQ_NO -
  949. (rxtid->hold_q_sz - 2 - cur);
  950. spin_unlock_bh(&rxtid->lock);
  951. } else {
  952. /*
  953. * Dequeue only those frames that are outside the
  954. * new shifted window.
  955. */
  956. if (cur >= rxtid->hold_q_sz - 1)
  957. st = cur - (rxtid->hold_q_sz - 1);
  958. else
  959. st = ATH6KL_MAX_SEQ_NO -
  960. (rxtid->hold_q_sz - 2 - cur);
  961. aggr_deque_frms(agg_conn, tid, st, 0);
  962. }
  963. stats->num_oow++;
  964. }
  965. idx = AGGR_WIN_IDX(seq_no, rxtid->hold_q_sz);
  966. node = &rxtid->hold_q[idx];
  967. spin_lock_bh(&rxtid->lock);
  968. /*
  969. * Is the cur frame duplicate or something beyond our window(hold_q
  970. * -> which is 2x, already)?
  971. *
  972. * 1. Duplicate is easy - drop incoming frame.
  973. * 2. Not falling in current sliding window.
  974. * 2a. is the frame_seq_no preceding current tid_seq_no?
  975. * -> drop the frame. perhaps sender did not get our ACK.
  976. * this is taken care of above.
  977. * 2b. is the frame_seq_no beyond window(st, TID_WINDOW_SZ);
  978. * -> Taken care of it above, by moving window forward.
  979. */
  980. dev_kfree_skb(node->skb);
  981. stats->num_dups++;
  982. node->skb = frame;
  983. is_queued = true;
  984. node->is_amsdu = is_amsdu;
  985. node->seq_no = seq_no;
  986. if (node->is_amsdu)
  987. stats->num_amsdu++;
  988. else
  989. stats->num_mpdu++;
  990. spin_unlock_bh(&rxtid->lock);
  991. aggr_deque_frms(agg_conn, tid, 0, 1);
  992. if (agg_conn->timer_scheduled)
  993. return is_queued;
  994. spin_lock_bh(&rxtid->lock);
  995. for (idx = 0; idx < rxtid->hold_q_sz; idx++) {
  996. if (rxtid->hold_q[idx].skb) {
  997. /*
  998. * There is a frame in the queue and no
  999. * timer so start a timer to ensure that
  1000. * the frame doesn't remain stuck
  1001. * forever.
  1002. */
  1003. agg_conn->timer_scheduled = true;
  1004. mod_timer(&agg_conn->timer,
  1005. (jiffies + (HZ * AGGR_RX_TIMEOUT) / 1000));
  1006. rxtid->timer_mon = true;
  1007. break;
  1008. }
  1009. }
  1010. spin_unlock_bh(&rxtid->lock);
  1011. return is_queued;
  1012. }
  1013. static void ath6kl_uapsd_trigger_frame_rx(struct ath6kl_vif *vif,
  1014. struct ath6kl_sta *conn)
  1015. {
  1016. struct ath6kl *ar = vif->ar;
  1017. bool is_apsdq_empty, is_apsdq_empty_at_start;
  1018. u32 num_frames_to_deliver, flags;
  1019. struct sk_buff *skb = NULL;
  1020. /*
  1021. * If the APSD q for this STA is not empty, dequeue and
  1022. * send a pkt from the head of the q. Also update the
  1023. * More data bit in the WMI_DATA_HDR if there are
  1024. * more pkts for this STA in the APSD q.
  1025. * If there are no more pkts for this STA,
  1026. * update the APSD bitmap for this STA.
  1027. */
  1028. num_frames_to_deliver = (conn->apsd_info >> ATH6KL_APSD_NUM_OF_AC) &
  1029. ATH6KL_APSD_FRAME_MASK;
  1030. /*
  1031. * Number of frames to send in a service period is
  1032. * indicated by the station
  1033. * in the QOS_INFO of the association request
  1034. * If it is zero, send all frames
  1035. */
  1036. if (!num_frames_to_deliver)
  1037. num_frames_to_deliver = ATH6KL_APSD_ALL_FRAME;
  1038. spin_lock_bh(&conn->psq_lock);
  1039. is_apsdq_empty = skb_queue_empty(&conn->apsdq);
  1040. spin_unlock_bh(&conn->psq_lock);
  1041. is_apsdq_empty_at_start = is_apsdq_empty;
  1042. while ((!is_apsdq_empty) && (num_frames_to_deliver)) {
  1043. spin_lock_bh(&conn->psq_lock);
  1044. skb = skb_dequeue(&conn->apsdq);
  1045. is_apsdq_empty = skb_queue_empty(&conn->apsdq);
  1046. spin_unlock_bh(&conn->psq_lock);
  1047. /*
  1048. * Set the STA flag to Trigger delivery,
  1049. * so that the frame will go out
  1050. */
  1051. conn->sta_flags |= STA_PS_APSD_TRIGGER;
  1052. num_frames_to_deliver--;
  1053. /* Last frame in the service period, set EOSP or queue empty */
  1054. if ((is_apsdq_empty) || (!num_frames_to_deliver))
  1055. conn->sta_flags |= STA_PS_APSD_EOSP;
  1056. ath6kl_data_tx(skb, vif->ndev);
  1057. conn->sta_flags &= ~(STA_PS_APSD_TRIGGER);
  1058. conn->sta_flags &= ~(STA_PS_APSD_EOSP);
  1059. }
  1060. if (is_apsdq_empty) {
  1061. if (is_apsdq_empty_at_start)
  1062. flags = WMI_AP_APSD_NO_DELIVERY_FRAMES;
  1063. else
  1064. flags = 0;
  1065. ath6kl_wmi_set_apsd_bfrd_traf(ar->wmi,
  1066. vif->fw_vif_idx,
  1067. conn->aid, 0, flags);
  1068. }
  1069. return;
  1070. }
  1071. void ath6kl_rx(struct htc_target *target, struct htc_packet *packet)
  1072. {
  1073. struct ath6kl *ar = target->dev->ar;
  1074. struct sk_buff *skb = packet->pkt_cntxt;
  1075. struct wmi_rx_meta_v2 *meta;
  1076. struct wmi_data_hdr *dhdr;
  1077. int min_hdr_len;
  1078. u8 meta_type, dot11_hdr = 0;
  1079. u8 pad_before_data_start;
  1080. int status = packet->status;
  1081. enum htc_endpoint_id ept = packet->endpoint;
  1082. bool is_amsdu, prev_ps, ps_state = false;
  1083. bool trig_state = false;
  1084. struct ath6kl_sta *conn = NULL;
  1085. struct sk_buff *skb1 = NULL;
  1086. struct ethhdr *datap = NULL;
  1087. struct ath6kl_vif *vif;
  1088. struct aggr_info_conn *aggr_conn;
  1089. u16 seq_no, offset;
  1090. u8 tid, if_idx;
  1091. ath6kl_dbg(ATH6KL_DBG_WLAN_RX,
  1092. "%s: ar=0x%p eid=%d, skb=0x%p, data=0x%p, len=0x%x status:%d",
  1093. __func__, ar, ept, skb, packet->buf,
  1094. packet->act_len, status);
  1095. if (status || packet->act_len < HTC_HDR_LENGTH) {
  1096. dev_kfree_skb(skb);
  1097. return;
  1098. }
  1099. skb_put(skb, packet->act_len + HTC_HDR_LENGTH);
  1100. skb_pull(skb, HTC_HDR_LENGTH);
  1101. ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, __func__, "rx ",
  1102. skb->data, skb->len);
  1103. if (ept == ar->ctrl_ep) {
  1104. if (test_bit(WMI_ENABLED, &ar->flag)) {
  1105. ath6kl_check_wow_status(ar);
  1106. ath6kl_wmi_control_rx(ar->wmi, skb);
  1107. return;
  1108. }
  1109. if_idx =
  1110. wmi_cmd_hdr_get_if_idx((struct wmi_cmd_hdr *) skb->data);
  1111. } else {
  1112. if_idx =
  1113. wmi_data_hdr_get_if_idx((struct wmi_data_hdr *) skb->data);
  1114. }
  1115. vif = ath6kl_get_vif_by_index(ar, if_idx);
  1116. if (!vif) {
  1117. dev_kfree_skb(skb);
  1118. return;
  1119. }
  1120. /*
  1121. * Take lock to protect buffer counts and adaptive power throughput
  1122. * state.
  1123. */
  1124. spin_lock_bh(&vif->if_lock);
  1125. vif->ndev->stats.rx_packets++;
  1126. vif->ndev->stats.rx_bytes += packet->act_len;
  1127. spin_unlock_bh(&vif->if_lock);
  1128. skb->dev = vif->ndev;
  1129. if (!test_bit(WMI_ENABLED, &ar->flag)) {
  1130. if (EPPING_ALIGNMENT_PAD > 0)
  1131. skb_pull(skb, EPPING_ALIGNMENT_PAD);
  1132. ath6kl_deliver_frames_to_nw_stack(vif->ndev, skb);
  1133. return;
  1134. }
  1135. ath6kl_check_wow_status(ar);
  1136. min_hdr_len = sizeof(struct ethhdr) + sizeof(struct wmi_data_hdr) +
  1137. sizeof(struct ath6kl_llc_snap_hdr);
  1138. dhdr = (struct wmi_data_hdr *) skb->data;
  1139. /*
  1140. * In the case of AP mode we may receive NULL data frames
  1141. * that do not have LLC hdr. They are 16 bytes in size.
  1142. * Allow these frames in the AP mode.
  1143. */
  1144. if (vif->nw_type != AP_NETWORK &&
  1145. ((packet->act_len < min_hdr_len) ||
  1146. (packet->act_len > WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH))) {
  1147. ath6kl_info("frame len is too short or too long\n");
  1148. vif->ndev->stats.rx_errors++;
  1149. vif->ndev->stats.rx_length_errors++;
  1150. dev_kfree_skb(skb);
  1151. return;
  1152. }
  1153. pad_before_data_start =
  1154. (le16_to_cpu(dhdr->info3) >> WMI_DATA_HDR_PAD_BEFORE_DATA_SHIFT)
  1155. & WMI_DATA_HDR_PAD_BEFORE_DATA_MASK;
  1156. /* Get the Power save state of the STA */
  1157. if (vif->nw_type == AP_NETWORK) {
  1158. meta_type = wmi_data_hdr_get_meta(dhdr);
  1159. ps_state = !!((dhdr->info >> WMI_DATA_HDR_PS_SHIFT) &
  1160. WMI_DATA_HDR_PS_MASK);
  1161. offset = sizeof(struct wmi_data_hdr) + pad_before_data_start;
  1162. trig_state = !!(le16_to_cpu(dhdr->info3) & WMI_DATA_HDR_TRIG);
  1163. switch (meta_type) {
  1164. case 0:
  1165. break;
  1166. case WMI_META_VERSION_1:
  1167. offset += sizeof(struct wmi_rx_meta_v1);
  1168. break;
  1169. case WMI_META_VERSION_2:
  1170. offset += sizeof(struct wmi_rx_meta_v2);
  1171. break;
  1172. default:
  1173. break;
  1174. }
  1175. datap = (struct ethhdr *) (skb->data + offset);
  1176. conn = ath6kl_find_sta(vif, datap->h_source);
  1177. if (!conn) {
  1178. dev_kfree_skb(skb);
  1179. return;
  1180. }
  1181. /*
  1182. * If there is a change in PS state of the STA,
  1183. * take appropriate steps:
  1184. *
  1185. * 1. If Sleep-->Awake, flush the psq for the STA
  1186. * Clear the PVB for the STA.
  1187. * 2. If Awake-->Sleep, Starting queueing frames
  1188. * the STA.
  1189. */
  1190. prev_ps = !!(conn->sta_flags & STA_PS_SLEEP);
  1191. if (ps_state)
  1192. conn->sta_flags |= STA_PS_SLEEP;
  1193. else
  1194. conn->sta_flags &= ~STA_PS_SLEEP;
  1195. /* Accept trigger only when the station is in sleep */
  1196. if ((conn->sta_flags & STA_PS_SLEEP) && trig_state)
  1197. ath6kl_uapsd_trigger_frame_rx(vif, conn);
  1198. if (prev_ps ^ !!(conn->sta_flags & STA_PS_SLEEP)) {
  1199. if (!(conn->sta_flags & STA_PS_SLEEP)) {
  1200. struct sk_buff *skbuff = NULL;
  1201. bool is_apsdq_empty;
  1202. struct ath6kl_mgmt_buff *mgmt;
  1203. u8 idx;
  1204. spin_lock_bh(&conn->psq_lock);
  1205. while (conn->mgmt_psq_len > 0) {
  1206. mgmt = list_first_entry(
  1207. &conn->mgmt_psq,
  1208. struct ath6kl_mgmt_buff,
  1209. list);
  1210. list_del(&mgmt->list);
  1211. conn->mgmt_psq_len--;
  1212. spin_unlock_bh(&conn->psq_lock);
  1213. idx = vif->fw_vif_idx;
  1214. ath6kl_wmi_send_mgmt_cmd(ar->wmi,
  1215. idx,
  1216. mgmt->id,
  1217. mgmt->freq,
  1218. mgmt->wait,
  1219. mgmt->buf,
  1220. mgmt->len,
  1221. mgmt->no_cck);
  1222. kfree(mgmt);
  1223. spin_lock_bh(&conn->psq_lock);
  1224. }
  1225. conn->mgmt_psq_len = 0;
  1226. while ((skbuff = skb_dequeue(&conn->psq))) {
  1227. spin_unlock_bh(&conn->psq_lock);
  1228. ath6kl_data_tx(skbuff, vif->ndev);
  1229. spin_lock_bh(&conn->psq_lock);
  1230. }
  1231. is_apsdq_empty = skb_queue_empty(&conn->apsdq);
  1232. while ((skbuff = skb_dequeue(&conn->apsdq))) {
  1233. spin_unlock_bh(&conn->psq_lock);
  1234. ath6kl_data_tx(skbuff, vif->ndev);
  1235. spin_lock_bh(&conn->psq_lock);
  1236. }
  1237. spin_unlock_bh(&conn->psq_lock);
  1238. if (!is_apsdq_empty)
  1239. ath6kl_wmi_set_apsd_bfrd_traf(
  1240. ar->wmi,
  1241. vif->fw_vif_idx,
  1242. conn->aid, 0, 0);
  1243. /* Clear the PVB for this STA */
  1244. ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx,
  1245. conn->aid, 0);
  1246. }
  1247. }
  1248. /* drop NULL data frames here */
  1249. if ((packet->act_len < min_hdr_len) ||
  1250. (packet->act_len >
  1251. WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH)) {
  1252. dev_kfree_skb(skb);
  1253. return;
  1254. }
  1255. }
  1256. is_amsdu = wmi_data_hdr_is_amsdu(dhdr) ? true : false;
  1257. tid = wmi_data_hdr_get_up(dhdr);
  1258. seq_no = wmi_data_hdr_get_seqno(dhdr);
  1259. meta_type = wmi_data_hdr_get_meta(dhdr);
  1260. dot11_hdr = wmi_data_hdr_get_dot11(dhdr);
  1261. skb_pull(skb, sizeof(struct wmi_data_hdr));
  1262. switch (meta_type) {
  1263. case WMI_META_VERSION_1:
  1264. skb_pull(skb, sizeof(struct wmi_rx_meta_v1));
  1265. break;
  1266. case WMI_META_VERSION_2:
  1267. meta = (struct wmi_rx_meta_v2 *) skb->data;
  1268. if (meta->csum_flags & 0x1) {
  1269. skb->ip_summed = CHECKSUM_COMPLETE;
  1270. skb->csum = (__force __wsum) meta->csum;
  1271. }
  1272. skb_pull(skb, sizeof(struct wmi_rx_meta_v2));
  1273. break;
  1274. default:
  1275. break;
  1276. }
  1277. skb_pull(skb, pad_before_data_start);
  1278. if (dot11_hdr)
  1279. status = ath6kl_wmi_dot11_hdr_remove(ar->wmi, skb);
  1280. else if (!is_amsdu)
  1281. status = ath6kl_wmi_dot3_2_dix(skb);
  1282. if (status) {
  1283. /*
  1284. * Drop frames that could not be processed (lack of
  1285. * memory, etc.)
  1286. */
  1287. dev_kfree_skb(skb);
  1288. return;
  1289. }
  1290. if (!(vif->ndev->flags & IFF_UP)) {
  1291. dev_kfree_skb(skb);
  1292. return;
  1293. }
  1294. if (vif->nw_type == AP_NETWORK) {
  1295. datap = (struct ethhdr *) skb->data;
  1296. if (is_multicast_ether_addr(datap->h_dest))
  1297. /*
  1298. * Bcast/Mcast frames should be sent to the
  1299. * OS stack as well as on the air.
  1300. */
  1301. skb1 = skb_copy(skb, GFP_ATOMIC);
  1302. else {
  1303. /*
  1304. * Search for a connected STA with dstMac
  1305. * as the Mac address. If found send the
  1306. * frame to it on the air else send the
  1307. * frame up the stack.
  1308. */
  1309. conn = ath6kl_find_sta(vif, datap->h_dest);
  1310. if (conn && ar->intra_bss) {
  1311. skb1 = skb;
  1312. skb = NULL;
  1313. } else if (conn && !ar->intra_bss) {
  1314. dev_kfree_skb(skb);
  1315. skb = NULL;
  1316. }
  1317. }
  1318. if (skb1)
  1319. ath6kl_data_tx(skb1, vif->ndev);
  1320. if (skb == NULL) {
  1321. /* nothing to deliver up the stack */
  1322. return;
  1323. }
  1324. }
  1325. datap = (struct ethhdr *) skb->data;
  1326. if (is_unicast_ether_addr(datap->h_dest)) {
  1327. if (vif->nw_type == AP_NETWORK) {
  1328. conn = ath6kl_find_sta(vif, datap->h_source);
  1329. if (!conn)
  1330. return;
  1331. aggr_conn = conn->aggr_conn;
  1332. } else {
  1333. aggr_conn = vif->aggr_cntxt->aggr_conn;
  1334. }
  1335. if (aggr_process_recv_frm(aggr_conn, tid, seq_no,
  1336. is_amsdu, skb)) {
  1337. /* aggregation code will handle the skb */
  1338. return;
  1339. }
  1340. } else if (!is_broadcast_ether_addr(datap->h_dest)) {
  1341. vif->ndev->stats.multicast++;
  1342. }
  1343. ath6kl_deliver_frames_to_nw_stack(vif->ndev, skb);
  1344. }
  1345. static void aggr_timeout(struct timer_list *t)
  1346. {
  1347. u8 i, j;
  1348. struct aggr_info_conn *aggr_conn = from_timer(aggr_conn, t, timer);
  1349. struct rxtid *rxtid;
  1350. struct rxtid_stats *stats;
  1351. for (i = 0; i < NUM_OF_TIDS; i++) {
  1352. rxtid = &aggr_conn->rx_tid[i];
  1353. stats = &aggr_conn->stat[i];
  1354. if (!rxtid->aggr || !rxtid->timer_mon)
  1355. continue;
  1356. stats->num_timeouts++;
  1357. ath6kl_dbg(ATH6KL_DBG_AGGR,
  1358. "aggr timeout (st %d end %d)\n",
  1359. rxtid->seq_next,
  1360. ((rxtid->seq_next + rxtid->hold_q_sz-1) &
  1361. ATH6KL_MAX_SEQ_NO));
  1362. aggr_deque_frms(aggr_conn, i, 0, 0);
  1363. }
  1364. aggr_conn->timer_scheduled = false;
  1365. for (i = 0; i < NUM_OF_TIDS; i++) {
  1366. rxtid = &aggr_conn->rx_tid[i];
  1367. if (rxtid->aggr && rxtid->hold_q) {
  1368. spin_lock_bh(&rxtid->lock);
  1369. for (j = 0; j < rxtid->hold_q_sz; j++) {
  1370. if (rxtid->hold_q[j].skb) {
  1371. aggr_conn->timer_scheduled = true;
  1372. rxtid->timer_mon = true;
  1373. break;
  1374. }
  1375. }
  1376. spin_unlock_bh(&rxtid->lock);
  1377. if (j >= rxtid->hold_q_sz)
  1378. rxtid->timer_mon = false;
  1379. }
  1380. }
  1381. if (aggr_conn->timer_scheduled)
  1382. mod_timer(&aggr_conn->timer,
  1383. jiffies + msecs_to_jiffies(AGGR_RX_TIMEOUT));
  1384. }
  1385. static void aggr_delete_tid_state(struct aggr_info_conn *aggr_conn, u8 tid)
  1386. {
  1387. struct rxtid *rxtid;
  1388. struct rxtid_stats *stats;
  1389. if (!aggr_conn || tid >= NUM_OF_TIDS)
  1390. return;
  1391. rxtid = &aggr_conn->rx_tid[tid];
  1392. stats = &aggr_conn->stat[tid];
  1393. if (rxtid->aggr)
  1394. aggr_deque_frms(aggr_conn, tid, 0, 0);
  1395. rxtid->aggr = false;
  1396. rxtid->timer_mon = false;
  1397. rxtid->win_sz = 0;
  1398. rxtid->seq_next = 0;
  1399. rxtid->hold_q_sz = 0;
  1400. kfree(rxtid->hold_q);
  1401. rxtid->hold_q = NULL;
  1402. memset(stats, 0, sizeof(struct rxtid_stats));
  1403. }
  1404. void aggr_recv_addba_req_evt(struct ath6kl_vif *vif, u8 tid_mux, u16 seq_no,
  1405. u8 win_sz)
  1406. {
  1407. struct ath6kl_sta *sta;
  1408. struct aggr_info_conn *aggr_conn = NULL;
  1409. struct rxtid *rxtid;
  1410. u16 hold_q_size;
  1411. u8 tid, aid;
  1412. if (vif->nw_type == AP_NETWORK) {
  1413. aid = ath6kl_get_aid(tid_mux);
  1414. sta = ath6kl_find_sta_by_aid(vif->ar, aid);
  1415. if (sta)
  1416. aggr_conn = sta->aggr_conn;
  1417. } else {
  1418. aggr_conn = vif->aggr_cntxt->aggr_conn;
  1419. }
  1420. if (!aggr_conn)
  1421. return;
  1422. tid = ath6kl_get_tid(tid_mux);
  1423. if (tid >= NUM_OF_TIDS)
  1424. return;
  1425. rxtid = &aggr_conn->rx_tid[tid];
  1426. if (win_sz < AGGR_WIN_SZ_MIN || win_sz > AGGR_WIN_SZ_MAX)
  1427. ath6kl_dbg(ATH6KL_DBG_WLAN_RX, "%s: win_sz %d, tid %d\n",
  1428. __func__, win_sz, tid);
  1429. if (rxtid->aggr)
  1430. aggr_delete_tid_state(aggr_conn, tid);
  1431. rxtid->seq_next = seq_no;
  1432. hold_q_size = TID_WINDOW_SZ(win_sz) * sizeof(struct skb_hold_q);
  1433. rxtid->hold_q = kzalloc(hold_q_size, GFP_KERNEL);
  1434. if (!rxtid->hold_q)
  1435. return;
  1436. rxtid->win_sz = win_sz;
  1437. rxtid->hold_q_sz = TID_WINDOW_SZ(win_sz);
  1438. if (!skb_queue_empty(&rxtid->q))
  1439. return;
  1440. rxtid->aggr = true;
  1441. }
  1442. void aggr_conn_init(struct ath6kl_vif *vif, struct aggr_info *aggr_info,
  1443. struct aggr_info_conn *aggr_conn)
  1444. {
  1445. struct rxtid *rxtid;
  1446. u8 i;
  1447. aggr_conn->aggr_sz = AGGR_SZ_DEFAULT;
  1448. aggr_conn->dev = vif->ndev;
  1449. timer_setup(&aggr_conn->timer, aggr_timeout, 0);
  1450. aggr_conn->aggr_info = aggr_info;
  1451. aggr_conn->timer_scheduled = false;
  1452. for (i = 0; i < NUM_OF_TIDS; i++) {
  1453. rxtid = &aggr_conn->rx_tid[i];
  1454. rxtid->aggr = false;
  1455. rxtid->timer_mon = false;
  1456. skb_queue_head_init(&rxtid->q);
  1457. spin_lock_init(&rxtid->lock);
  1458. }
  1459. }
  1460. struct aggr_info *aggr_init(struct ath6kl_vif *vif)
  1461. {
  1462. struct aggr_info *p_aggr = NULL;
  1463. p_aggr = kzalloc(sizeof(struct aggr_info), GFP_KERNEL);
  1464. if (!p_aggr) {
  1465. ath6kl_err("failed to alloc memory for aggr_node\n");
  1466. return NULL;
  1467. }
  1468. p_aggr->aggr_conn = kzalloc(sizeof(struct aggr_info_conn), GFP_KERNEL);
  1469. if (!p_aggr->aggr_conn) {
  1470. ath6kl_err("failed to alloc memory for connection specific aggr info\n");
  1471. kfree(p_aggr);
  1472. return NULL;
  1473. }
  1474. aggr_conn_init(vif, p_aggr, p_aggr->aggr_conn);
  1475. skb_queue_head_init(&p_aggr->rx_amsdu_freeq);
  1476. ath6kl_alloc_netbufs(&p_aggr->rx_amsdu_freeq, AGGR_NUM_OF_FREE_NETBUFS);
  1477. return p_aggr;
  1478. }
  1479. void aggr_recv_delba_req_evt(struct ath6kl_vif *vif, u8 tid_mux)
  1480. {
  1481. struct ath6kl_sta *sta;
  1482. struct rxtid *rxtid;
  1483. struct aggr_info_conn *aggr_conn = NULL;
  1484. u8 tid, aid;
  1485. if (vif->nw_type == AP_NETWORK) {
  1486. aid = ath6kl_get_aid(tid_mux);
  1487. sta = ath6kl_find_sta_by_aid(vif->ar, aid);
  1488. if (sta)
  1489. aggr_conn = sta->aggr_conn;
  1490. } else {
  1491. aggr_conn = vif->aggr_cntxt->aggr_conn;
  1492. }
  1493. if (!aggr_conn)
  1494. return;
  1495. tid = ath6kl_get_tid(tid_mux);
  1496. if (tid >= NUM_OF_TIDS)
  1497. return;
  1498. rxtid = &aggr_conn->rx_tid[tid];
  1499. if (rxtid->aggr)
  1500. aggr_delete_tid_state(aggr_conn, tid);
  1501. }
  1502. void aggr_reset_state(struct aggr_info_conn *aggr_conn)
  1503. {
  1504. u8 tid;
  1505. if (!aggr_conn)
  1506. return;
  1507. if (aggr_conn->timer_scheduled) {
  1508. del_timer(&aggr_conn->timer);
  1509. aggr_conn->timer_scheduled = false;
  1510. }
  1511. for (tid = 0; tid < NUM_OF_TIDS; tid++)
  1512. aggr_delete_tid_state(aggr_conn, tid);
  1513. }
  1514. /* clean up our amsdu buffer list */
  1515. void ath6kl_cleanup_amsdu_rxbufs(struct ath6kl *ar)
  1516. {
  1517. struct htc_packet *packet, *tmp_pkt;
  1518. spin_lock_bh(&ar->lock);
  1519. if (list_empty(&ar->amsdu_rx_buffer_queue)) {
  1520. spin_unlock_bh(&ar->lock);
  1521. return;
  1522. }
  1523. list_for_each_entry_safe(packet, tmp_pkt, &ar->amsdu_rx_buffer_queue,
  1524. list) {
  1525. list_del(&packet->list);
  1526. spin_unlock_bh(&ar->lock);
  1527. dev_kfree_skb(packet->pkt_cntxt);
  1528. spin_lock_bh(&ar->lock);
  1529. }
  1530. spin_unlock_bh(&ar->lock);
  1531. }
  1532. void aggr_module_destroy(struct aggr_info *aggr_info)
  1533. {
  1534. if (!aggr_info)
  1535. return;
  1536. aggr_reset_state(aggr_info->aggr_conn);
  1537. skb_queue_purge(&aggr_info->rx_amsdu_freeq);
  1538. kfree(aggr_info->aggr_conn);
  1539. kfree(aggr_info);
  1540. }