txrx.c 34 KB

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