txrx.c 35 KB

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