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