txrx.c 41 KB

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