txrx.c 41 KB

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