txrx.c 37 KB

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