txrx.c 44 KB

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