txrx.c 36 KB

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