txrx.c 37 KB

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