txrx.c 34 KB

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