txrx.c 44 KB

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