txrx.c 36 KB

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