txrx.c 35 KB

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