txrx.c 35 KB

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