txrx.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803
  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. /*
  19. * tid - tid_mux0..tid_mux3
  20. * aid - tid_mux4..tid_mux7
  21. */
  22. #define ATH6KL_TID_MASK 0xf
  23. #define ATH6KL_AID_SHIFT 4
  24. static inline u8 ath6kl_get_tid(u8 tid_mux)
  25. {
  26. return tid_mux & ATH6KL_TID_MASK;
  27. }
  28. static inline u8 ath6kl_get_aid(u8 tid_mux)
  29. {
  30. return tid_mux >> ATH6KL_AID_SHIFT;
  31. }
  32. static u8 ath6kl_ibss_map_epid(struct sk_buff *skb, struct net_device *dev,
  33. u32 *map_no)
  34. {
  35. struct ath6kl *ar = ath6kl_priv(dev);
  36. struct ethhdr *eth_hdr;
  37. u32 i, ep_map = -1;
  38. u8 *datap;
  39. *map_no = 0;
  40. datap = skb->data;
  41. eth_hdr = (struct ethhdr *) (datap + sizeof(struct wmi_data_hdr));
  42. if (is_multicast_ether_addr(eth_hdr->h_dest))
  43. return ENDPOINT_2;
  44. for (i = 0; i < ar->node_num; i++) {
  45. if (memcmp(eth_hdr->h_dest, ar->node_map[i].mac_addr,
  46. ETH_ALEN) == 0) {
  47. *map_no = i + 1;
  48. ar->node_map[i].tx_pend++;
  49. return ar->node_map[i].ep_id;
  50. }
  51. if ((ep_map == -1) && !ar->node_map[i].tx_pend)
  52. ep_map = i;
  53. }
  54. if (ep_map == -1) {
  55. ep_map = ar->node_num;
  56. ar->node_num++;
  57. if (ar->node_num > MAX_NODE_NUM)
  58. return ENDPOINT_UNUSED;
  59. }
  60. memcpy(ar->node_map[ep_map].mac_addr, eth_hdr->h_dest, ETH_ALEN);
  61. for (i = ENDPOINT_2; i <= ENDPOINT_5; i++) {
  62. if (!ar->tx_pending[i]) {
  63. ar->node_map[ep_map].ep_id = i;
  64. break;
  65. }
  66. /*
  67. * No free endpoint is available, start redistribution on
  68. * the inuse endpoints.
  69. */
  70. if (i == ENDPOINT_5) {
  71. ar->node_map[ep_map].ep_id = ar->next_ep_id;
  72. ar->next_ep_id++;
  73. if (ar->next_ep_id > ENDPOINT_5)
  74. ar->next_ep_id = ENDPOINT_2;
  75. }
  76. }
  77. *map_no = ep_map + 1;
  78. ar->node_map[ep_map].tx_pend++;
  79. return ar->node_map[ep_map].ep_id;
  80. }
  81. static bool ath6kl_process_uapsdq(struct ath6kl_sta *conn,
  82. struct ath6kl_vif *vif,
  83. struct sk_buff *skb,
  84. u32 *flags)
  85. {
  86. struct ath6kl *ar = vif->ar;
  87. bool is_apsdq_empty = false;
  88. struct ethhdr *datap = (struct ethhdr *) skb->data;
  89. u8 up = 0, traffic_class, *ip_hdr;
  90. u16 ether_type;
  91. struct ath6kl_llc_snap_hdr *llc_hdr;
  92. if (conn->sta_flags & STA_PS_APSD_TRIGGER) {
  93. /*
  94. * This tx is because of a uAPSD trigger, determine
  95. * more and EOSP bit. Set EOSP if queue is empty
  96. * or sufficient frames are delivered for this trigger.
  97. */
  98. spin_lock_bh(&conn->psq_lock);
  99. if (!skb_queue_empty(&conn->apsdq))
  100. *flags |= WMI_DATA_HDR_FLAGS_MORE;
  101. else if (conn->sta_flags & STA_PS_APSD_EOSP)
  102. *flags |= WMI_DATA_HDR_FLAGS_EOSP;
  103. *flags |= WMI_DATA_HDR_FLAGS_UAPSD;
  104. spin_unlock_bh(&conn->psq_lock);
  105. return false;
  106. } else if (!conn->apsd_info)
  107. return false;
  108. if (test_bit(WMM_ENABLED, &vif->flags)) {
  109. ether_type = be16_to_cpu(datap->h_proto);
  110. if (is_ethertype(ether_type)) {
  111. /* packet is in DIX format */
  112. ip_hdr = (u8 *)(datap + 1);
  113. } else {
  114. /* packet is in 802.3 format */
  115. llc_hdr = (struct ath6kl_llc_snap_hdr *)
  116. (datap + 1);
  117. ether_type = be16_to_cpu(llc_hdr->eth_type);
  118. ip_hdr = (u8 *)(llc_hdr + 1);
  119. }
  120. if (ether_type == IP_ETHERTYPE)
  121. up = ath6kl_wmi_determine_user_priority(
  122. ip_hdr, 0);
  123. }
  124. traffic_class = ath6kl_wmi_get_traffic_class(up);
  125. if ((conn->apsd_info & (1 << traffic_class)) == 0)
  126. return false;
  127. /* Queue the frames if the STA is sleeping */
  128. spin_lock_bh(&conn->psq_lock);
  129. is_apsdq_empty = skb_queue_empty(&conn->apsdq);
  130. skb_queue_tail(&conn->apsdq, skb);
  131. spin_unlock_bh(&conn->psq_lock);
  132. /*
  133. * If this is the first pkt getting queued
  134. * for this STA, update the PVB for this STA
  135. */
  136. if (is_apsdq_empty) {
  137. ath6kl_wmi_set_apsd_bfrd_traf(ar->wmi,
  138. vif->fw_vif_idx,
  139. conn->aid, 1, 0);
  140. }
  141. *flags |= WMI_DATA_HDR_FLAGS_UAPSD;
  142. return true;
  143. }
  144. static bool ath6kl_process_psq(struct ath6kl_sta *conn,
  145. struct ath6kl_vif *vif,
  146. struct sk_buff *skb,
  147. u32 *flags)
  148. {
  149. bool is_psq_empty = false;
  150. struct ath6kl *ar = vif->ar;
  151. if (conn->sta_flags & STA_PS_POLLED) {
  152. spin_lock_bh(&conn->psq_lock);
  153. if (!skb_queue_empty(&conn->psq))
  154. *flags |= WMI_DATA_HDR_FLAGS_MORE;
  155. spin_unlock_bh(&conn->psq_lock);
  156. return false;
  157. }
  158. /* Queue the frames if the STA is sleeping */
  159. spin_lock_bh(&conn->psq_lock);
  160. is_psq_empty = skb_queue_empty(&conn->psq);
  161. skb_queue_tail(&conn->psq, skb);
  162. spin_unlock_bh(&conn->psq_lock);
  163. /*
  164. * If this is the first pkt getting queued
  165. * for this STA, update the PVB for this
  166. * STA.
  167. */
  168. if (is_psq_empty)
  169. ath6kl_wmi_set_pvb_cmd(ar->wmi,
  170. vif->fw_vif_idx,
  171. conn->aid, 1);
  172. return true;
  173. }
  174. static bool ath6kl_powersave_ap(struct ath6kl_vif *vif, struct sk_buff *skb,
  175. u32 *flags)
  176. {
  177. struct ethhdr *datap = (struct ethhdr *) skb->data;
  178. struct ath6kl_sta *conn = NULL;
  179. bool ps_queued = false;
  180. struct ath6kl *ar = vif->ar;
  181. if (is_multicast_ether_addr(datap->h_dest)) {
  182. u8 ctr = 0;
  183. bool q_mcast = false;
  184. for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
  185. if (ar->sta_list[ctr].sta_flags & STA_PS_SLEEP) {
  186. q_mcast = true;
  187. break;
  188. }
  189. }
  190. if (q_mcast) {
  191. /*
  192. * If this transmit is not because of a Dtim Expiry
  193. * q it.
  194. */
  195. if (!test_bit(DTIM_EXPIRED, &vif->flags)) {
  196. bool is_mcastq_empty = false;
  197. spin_lock_bh(&ar->mcastpsq_lock);
  198. is_mcastq_empty =
  199. skb_queue_empty(&ar->mcastpsq);
  200. skb_queue_tail(&ar->mcastpsq, skb);
  201. spin_unlock_bh(&ar->mcastpsq_lock);
  202. /*
  203. * If this is the first Mcast pkt getting
  204. * queued indicate to the target to set the
  205. * BitmapControl LSB of the TIM IE.
  206. */
  207. if (is_mcastq_empty)
  208. ath6kl_wmi_set_pvb_cmd(ar->wmi,
  209. vif->fw_vif_idx,
  210. MCAST_AID, 1);
  211. ps_queued = true;
  212. } else {
  213. /*
  214. * This transmit is because of Dtim expiry.
  215. * Determine if MoreData bit has to be set.
  216. */
  217. spin_lock_bh(&ar->mcastpsq_lock);
  218. if (!skb_queue_empty(&ar->mcastpsq))
  219. *flags |= WMI_DATA_HDR_FLAGS_MORE;
  220. spin_unlock_bh(&ar->mcastpsq_lock);
  221. }
  222. }
  223. } else {
  224. conn = ath6kl_find_sta(vif, datap->h_dest);
  225. if (!conn) {
  226. dev_kfree_skb(skb);
  227. /* Inform the caller that the skb is consumed */
  228. return true;
  229. }
  230. if (conn->sta_flags & STA_PS_SLEEP) {
  231. ps_queued = ath6kl_process_uapsdq(conn,
  232. vif, skb, flags);
  233. if (!(*flags & WMI_DATA_HDR_FLAGS_UAPSD))
  234. ps_queued = ath6kl_process_psq(conn,
  235. vif, skb, flags);
  236. }
  237. }
  238. return ps_queued;
  239. }
  240. /* Tx functions */
  241. int ath6kl_control_tx(void *devt, struct sk_buff *skb,
  242. enum htc_endpoint_id eid)
  243. {
  244. struct ath6kl *ar = devt;
  245. int status = 0;
  246. struct ath6kl_cookie *cookie = NULL;
  247. spin_lock_bh(&ar->lock);
  248. ath6kl_dbg(ATH6KL_DBG_WLAN_TX,
  249. "%s: skb=0x%p, len=0x%x eid =%d\n", __func__,
  250. skb, skb->len, eid);
  251. if (test_bit(WMI_CTRL_EP_FULL, &ar->flag) && (eid == ar->ctrl_ep)) {
  252. /*
  253. * Control endpoint is full, don't allocate resources, we
  254. * are just going to drop this packet.
  255. */
  256. cookie = NULL;
  257. ath6kl_err("wmi ctrl ep full, dropping pkt : 0x%p, len:%d\n",
  258. skb, skb->len);
  259. } else
  260. cookie = ath6kl_alloc_cookie(ar);
  261. if (cookie == NULL) {
  262. spin_unlock_bh(&ar->lock);
  263. status = -ENOMEM;
  264. goto fail_ctrl_tx;
  265. }
  266. ar->tx_pending[eid]++;
  267. if (eid != ar->ctrl_ep)
  268. ar->total_tx_data_pend++;
  269. spin_unlock_bh(&ar->lock);
  270. cookie->skb = skb;
  271. cookie->map_no = 0;
  272. set_htc_pkt_info(&cookie->htc_pkt, cookie, skb->data, skb->len,
  273. eid, ATH6KL_CONTROL_PKT_TAG);
  274. /*
  275. * This interface is asynchronous, if there is an error, cleanup
  276. * will happen in the TX completion callback.
  277. */
  278. ath6kl_htc_tx(ar->htc_target, &cookie->htc_pkt);
  279. return 0;
  280. fail_ctrl_tx:
  281. dev_kfree_skb(skb);
  282. return status;
  283. }
  284. int ath6kl_data_tx(struct sk_buff *skb, struct net_device *dev)
  285. {
  286. struct ath6kl *ar = ath6kl_priv(dev);
  287. struct ath6kl_cookie *cookie = NULL;
  288. enum htc_endpoint_id eid = ENDPOINT_UNUSED;
  289. struct ath6kl_vif *vif = netdev_priv(dev);
  290. u32 map_no = 0;
  291. u16 htc_tag = ATH6KL_DATA_PKT_TAG;
  292. u8 ac = 99 ; /* initialize to unmapped ac */
  293. bool chk_adhoc_ps_mapping = false;
  294. int ret;
  295. struct wmi_tx_meta_v2 meta_v2;
  296. void *meta;
  297. u8 csum_start = 0, csum_dest = 0, csum = skb->ip_summed;
  298. u8 meta_ver = 0;
  299. u32 flags = 0;
  300. ath6kl_dbg(ATH6KL_DBG_WLAN_TX,
  301. "%s: skb=0x%p, data=0x%p, len=0x%x\n", __func__,
  302. skb, skb->data, skb->len);
  303. /* If target is not associated */
  304. if (!test_bit(CONNECTED, &vif->flags)) {
  305. dev_kfree_skb(skb);
  306. return 0;
  307. }
  308. if (!test_bit(WMI_READY, &ar->flag))
  309. goto fail_tx;
  310. /* AP mode Power saving processing */
  311. if (vif->nw_type == AP_NETWORK) {
  312. if (ath6kl_powersave_ap(vif, skb, &flags))
  313. return 0;
  314. }
  315. if (test_bit(WMI_ENABLED, &ar->flag)) {
  316. if ((dev->features & NETIF_F_IP_CSUM) &&
  317. (csum == CHECKSUM_PARTIAL)) {
  318. csum_start = skb->csum_start -
  319. (skb_network_header(skb) - skb->head) +
  320. sizeof(struct ath6kl_llc_snap_hdr);
  321. csum_dest = skb->csum_offset + csum_start;
  322. }
  323. if (skb_headroom(skb) < dev->needed_headroom) {
  324. struct sk_buff *tmp_skb = skb;
  325. skb = skb_realloc_headroom(skb, dev->needed_headroom);
  326. kfree_skb(tmp_skb);
  327. if (skb == NULL) {
  328. vif->net_stats.tx_dropped++;
  329. return 0;
  330. }
  331. }
  332. if (ath6kl_wmi_dix_2_dot3(ar->wmi, skb)) {
  333. ath6kl_err("ath6kl_wmi_dix_2_dot3 failed\n");
  334. goto fail_tx;
  335. }
  336. if ((dev->features & NETIF_F_IP_CSUM) &&
  337. (csum == CHECKSUM_PARTIAL)) {
  338. meta_v2.csum_start = csum_start;
  339. meta_v2.csum_dest = csum_dest;
  340. /* instruct target to calculate checksum */
  341. meta_v2.csum_flags = WMI_META_V2_FLAG_CSUM_OFFLOAD;
  342. meta_ver = WMI_META_VERSION_2;
  343. meta = &meta_v2;
  344. } else {
  345. meta_ver = 0;
  346. meta = NULL;
  347. }
  348. ret = ath6kl_wmi_data_hdr_add(ar->wmi, skb,
  349. DATA_MSGTYPE, flags, 0,
  350. meta_ver,
  351. meta, vif->fw_vif_idx);
  352. if (ret) {
  353. ath6kl_warn("failed to add wmi data header:%d\n"
  354. , ret);
  355. goto fail_tx;
  356. }
  357. if ((vif->nw_type == ADHOC_NETWORK) &&
  358. ar->ibss_ps_enable && test_bit(CONNECTED, &vif->flags))
  359. chk_adhoc_ps_mapping = true;
  360. else {
  361. /* get the stream mapping */
  362. ret = ath6kl_wmi_implicit_create_pstream(ar->wmi,
  363. vif->fw_vif_idx, skb,
  364. 0, test_bit(WMM_ENABLED, &vif->flags), &ac);
  365. if (ret)
  366. goto fail_tx;
  367. }
  368. } else
  369. goto fail_tx;
  370. spin_lock_bh(&ar->lock);
  371. if (chk_adhoc_ps_mapping)
  372. eid = ath6kl_ibss_map_epid(skb, dev, &map_no);
  373. else
  374. eid = ar->ac2ep_map[ac];
  375. if (eid == 0 || eid == ENDPOINT_UNUSED) {
  376. ath6kl_err("eid %d is not mapped!\n", eid);
  377. spin_unlock_bh(&ar->lock);
  378. goto fail_tx;
  379. }
  380. /* allocate resource for this packet */
  381. cookie = ath6kl_alloc_cookie(ar);
  382. if (!cookie) {
  383. spin_unlock_bh(&ar->lock);
  384. goto fail_tx;
  385. }
  386. /* update counts while the lock is held */
  387. ar->tx_pending[eid]++;
  388. ar->total_tx_data_pend++;
  389. spin_unlock_bh(&ar->lock);
  390. if (!IS_ALIGNED((unsigned long) skb->data - HTC_HDR_LENGTH, 4) &&
  391. skb_cloned(skb)) {
  392. /*
  393. * We will touch (move the buffer data to align it. Since the
  394. * skb buffer is cloned and not only the header is changed, we
  395. * have to copy it to allow the changes. Since we are copying
  396. * the data here, we may as well align it by reserving suitable
  397. * headroom to avoid the memmove in ath6kl_htc_tx_buf_align().
  398. */
  399. struct sk_buff *nskb;
  400. nskb = skb_copy_expand(skb, HTC_HDR_LENGTH, 0, GFP_ATOMIC);
  401. if (nskb == NULL)
  402. goto fail_tx;
  403. kfree_skb(skb);
  404. skb = nskb;
  405. }
  406. cookie->skb = skb;
  407. cookie->map_no = map_no;
  408. set_htc_pkt_info(&cookie->htc_pkt, cookie, skb->data, skb->len,
  409. eid, htc_tag);
  410. ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, __func__, "tx ",
  411. skb->data, skb->len);
  412. /*
  413. * HTC interface is asynchronous, if this fails, cleanup will
  414. * happen in the ath6kl_tx_complete callback.
  415. */
  416. ath6kl_htc_tx(ar->htc_target, &cookie->htc_pkt);
  417. return 0;
  418. fail_tx:
  419. dev_kfree_skb(skb);
  420. vif->net_stats.tx_dropped++;
  421. vif->net_stats.tx_aborted_errors++;
  422. return 0;
  423. }
  424. /* indicate tx activity or inactivity on a WMI stream */
  425. void ath6kl_indicate_tx_activity(void *devt, u8 traffic_class, bool active)
  426. {
  427. struct ath6kl *ar = devt;
  428. enum htc_endpoint_id eid;
  429. int i;
  430. eid = ar->ac2ep_map[traffic_class];
  431. if (!test_bit(WMI_ENABLED, &ar->flag))
  432. goto notify_htc;
  433. spin_lock_bh(&ar->lock);
  434. ar->ac_stream_active[traffic_class] = active;
  435. if (active) {
  436. /*
  437. * Keep track of the active stream with the highest
  438. * priority.
  439. */
  440. if (ar->ac_stream_pri_map[traffic_class] >
  441. ar->hiac_stream_active_pri)
  442. /* set the new highest active priority */
  443. ar->hiac_stream_active_pri =
  444. ar->ac_stream_pri_map[traffic_class];
  445. } else {
  446. /*
  447. * We may have to search for the next active stream
  448. * that is the highest priority.
  449. */
  450. if (ar->hiac_stream_active_pri ==
  451. ar->ac_stream_pri_map[traffic_class]) {
  452. /*
  453. * The highest priority stream just went inactive
  454. * reset and search for the "next" highest "active"
  455. * priority stream.
  456. */
  457. ar->hiac_stream_active_pri = 0;
  458. for (i = 0; i < WMM_NUM_AC; i++) {
  459. if (ar->ac_stream_active[i] &&
  460. (ar->ac_stream_pri_map[i] >
  461. ar->hiac_stream_active_pri))
  462. /*
  463. * Set the new highest active
  464. * priority.
  465. */
  466. ar->hiac_stream_active_pri =
  467. ar->ac_stream_pri_map[i];
  468. }
  469. }
  470. }
  471. spin_unlock_bh(&ar->lock);
  472. notify_htc:
  473. /* notify HTC, this may cause credit distribution changes */
  474. ath6kl_htc_indicate_activity_change(ar->htc_target, eid, active);
  475. }
  476. enum htc_send_full_action ath6kl_tx_queue_full(struct htc_target *target,
  477. struct htc_packet *packet)
  478. {
  479. struct ath6kl *ar = target->dev->ar;
  480. struct ath6kl_vif *vif;
  481. enum htc_endpoint_id endpoint = packet->endpoint;
  482. enum htc_send_full_action action = HTC_SEND_FULL_KEEP;
  483. if (endpoint == ar->ctrl_ep) {
  484. /*
  485. * Under normal WMI if this is getting full, then something
  486. * is running rampant the host should not be exhausting the
  487. * WMI queue with too many commands the only exception to
  488. * this is during testing using endpointping.
  489. */
  490. set_bit(WMI_CTRL_EP_FULL, &ar->flag);
  491. ath6kl_err("wmi ctrl ep is full\n");
  492. return action;
  493. }
  494. if (packet->info.tx.tag == ATH6KL_CONTROL_PKT_TAG)
  495. return action;
  496. /*
  497. * The last MAX_HI_COOKIE_NUM "batch" of cookies are reserved for
  498. * the highest active stream.
  499. */
  500. if (ar->ac_stream_pri_map[ar->ep2ac_map[endpoint]] <
  501. ar->hiac_stream_active_pri &&
  502. ar->cookie_count <= MAX_HI_COOKIE_NUM)
  503. /*
  504. * Give preference to the highest priority stream by
  505. * dropping the packets which overflowed.
  506. */
  507. action = HTC_SEND_FULL_DROP;
  508. /* FIXME: Locking */
  509. spin_lock_bh(&ar->list_lock);
  510. list_for_each_entry(vif, &ar->vif_list, list) {
  511. if (vif->nw_type == ADHOC_NETWORK ||
  512. action != HTC_SEND_FULL_DROP) {
  513. spin_unlock_bh(&ar->list_lock);
  514. set_bit(NETQ_STOPPED, &vif->flags);
  515. netif_stop_queue(vif->ndev);
  516. return action;
  517. }
  518. }
  519. spin_unlock_bh(&ar->list_lock);
  520. return action;
  521. }
  522. /* TODO this needs to be looked at */
  523. static void ath6kl_tx_clear_node_map(struct ath6kl_vif *vif,
  524. enum htc_endpoint_id eid, u32 map_no)
  525. {
  526. struct ath6kl *ar = vif->ar;
  527. u32 i;
  528. if (vif->nw_type != ADHOC_NETWORK)
  529. return;
  530. if (!ar->ibss_ps_enable)
  531. return;
  532. if (eid == ar->ctrl_ep)
  533. return;
  534. if (map_no == 0)
  535. return;
  536. map_no--;
  537. ar->node_map[map_no].tx_pend--;
  538. if (ar->node_map[map_no].tx_pend)
  539. return;
  540. if (map_no != (ar->node_num - 1))
  541. return;
  542. for (i = ar->node_num; i > 0; i--) {
  543. if (ar->node_map[i - 1].tx_pend)
  544. break;
  545. memset(&ar->node_map[i - 1], 0,
  546. sizeof(struct ath6kl_node_mapping));
  547. ar->node_num--;
  548. }
  549. }
  550. void ath6kl_tx_complete(void *context, struct list_head *packet_queue)
  551. {
  552. struct ath6kl *ar = context;
  553. struct sk_buff_head skb_queue;
  554. struct htc_packet *packet;
  555. struct sk_buff *skb;
  556. struct ath6kl_cookie *ath6kl_cookie;
  557. u32 map_no = 0;
  558. int status;
  559. enum htc_endpoint_id eid;
  560. bool wake_event = false;
  561. bool flushing[ATH6KL_VIF_MAX] = {false};
  562. u8 if_idx;
  563. struct ath6kl_vif *vif;
  564. skb_queue_head_init(&skb_queue);
  565. /* lock the driver as we update internal state */
  566. spin_lock_bh(&ar->lock);
  567. /* reap completed packets */
  568. while (!list_empty(packet_queue)) {
  569. packet = list_first_entry(packet_queue, struct htc_packet,
  570. list);
  571. list_del(&packet->list);
  572. ath6kl_cookie = (struct ath6kl_cookie *)packet->pkt_cntxt;
  573. if (!ath6kl_cookie)
  574. goto fatal;
  575. status = packet->status;
  576. skb = ath6kl_cookie->skb;
  577. eid = packet->endpoint;
  578. map_no = ath6kl_cookie->map_no;
  579. if (!skb || !skb->data)
  580. goto fatal;
  581. __skb_queue_tail(&skb_queue, skb);
  582. if (!status && (packet->act_len != skb->len))
  583. goto fatal;
  584. ar->tx_pending[eid]--;
  585. if (eid != ar->ctrl_ep)
  586. ar->total_tx_data_pend--;
  587. if (eid == ar->ctrl_ep) {
  588. if (test_bit(WMI_CTRL_EP_FULL, &ar->flag))
  589. clear_bit(WMI_CTRL_EP_FULL, &ar->flag);
  590. if (ar->tx_pending[eid] == 0)
  591. wake_event = true;
  592. }
  593. if (eid == ar->ctrl_ep) {
  594. if_idx = wmi_cmd_hdr_get_if_idx(
  595. (struct wmi_cmd_hdr *) packet->buf);
  596. } else {
  597. if_idx = wmi_data_hdr_get_if_idx(
  598. (struct wmi_data_hdr *) packet->buf);
  599. }
  600. vif = ath6kl_get_vif_by_index(ar, if_idx);
  601. if (!vif) {
  602. ath6kl_free_cookie(ar, ath6kl_cookie);
  603. continue;
  604. }
  605. if (status) {
  606. if (status == -ECANCELED)
  607. /* a packet was flushed */
  608. flushing[if_idx] = true;
  609. vif->net_stats.tx_errors++;
  610. if (status != -ENOSPC && status != -ECANCELED)
  611. ath6kl_warn("tx complete error: %d\n", status);
  612. ath6kl_dbg(ATH6KL_DBG_WLAN_TX,
  613. "%s: skb=0x%p data=0x%p len=0x%x eid=%d %s\n",
  614. __func__, skb, packet->buf, packet->act_len,
  615. eid, "error!");
  616. } else {
  617. ath6kl_dbg(ATH6KL_DBG_WLAN_TX,
  618. "%s: skb=0x%p data=0x%p len=0x%x eid=%d %s\n",
  619. __func__, skb, packet->buf, packet->act_len,
  620. eid, "OK");
  621. flushing[if_idx] = false;
  622. vif->net_stats.tx_packets++;
  623. vif->net_stats.tx_bytes += skb->len;
  624. }
  625. ath6kl_tx_clear_node_map(vif, eid, map_no);
  626. ath6kl_free_cookie(ar, ath6kl_cookie);
  627. if (test_bit(NETQ_STOPPED, &vif->flags))
  628. clear_bit(NETQ_STOPPED, &vif->flags);
  629. }
  630. spin_unlock_bh(&ar->lock);
  631. __skb_queue_purge(&skb_queue);
  632. /* FIXME: Locking */
  633. spin_lock_bh(&ar->list_lock);
  634. list_for_each_entry(vif, &ar->vif_list, list) {
  635. if (test_bit(CONNECTED, &vif->flags) &&
  636. !flushing[vif->fw_vif_idx]) {
  637. spin_unlock_bh(&ar->list_lock);
  638. netif_wake_queue(vif->ndev);
  639. spin_lock_bh(&ar->list_lock);
  640. }
  641. }
  642. spin_unlock_bh(&ar->list_lock);
  643. if (wake_event)
  644. wake_up(&ar->event_wq);
  645. return;
  646. fatal:
  647. WARN_ON(1);
  648. spin_unlock_bh(&ar->lock);
  649. return;
  650. }
  651. void ath6kl_tx_data_cleanup(struct ath6kl *ar)
  652. {
  653. int i;
  654. /* flush all the data (non-control) streams */
  655. for (i = 0; i < WMM_NUM_AC; i++)
  656. ath6kl_htc_flush_txep(ar->htc_target, ar->ac2ep_map[i],
  657. ATH6KL_DATA_PKT_TAG);
  658. }
  659. /* Rx functions */
  660. static void ath6kl_deliver_frames_to_nw_stack(struct net_device *dev,
  661. struct sk_buff *skb)
  662. {
  663. if (!skb)
  664. return;
  665. skb->dev = dev;
  666. if (!(skb->dev->flags & IFF_UP)) {
  667. dev_kfree_skb(skb);
  668. return;
  669. }
  670. skb->protocol = eth_type_trans(skb, skb->dev);
  671. netif_rx_ni(skb);
  672. }
  673. static void ath6kl_alloc_netbufs(struct sk_buff_head *q, u16 num)
  674. {
  675. struct sk_buff *skb;
  676. while (num) {
  677. skb = ath6kl_buf_alloc(ATH6KL_BUFFER_SIZE);
  678. if (!skb) {
  679. ath6kl_err("netbuf allocation failed\n");
  680. return;
  681. }
  682. skb_queue_tail(q, skb);
  683. num--;
  684. }
  685. }
  686. static struct sk_buff *aggr_get_free_skb(struct aggr_info *p_aggr)
  687. {
  688. struct sk_buff *skb = NULL;
  689. if (skb_queue_len(&p_aggr->rx_amsdu_freeq) <
  690. (AGGR_NUM_OF_FREE_NETBUFS >> 2))
  691. ath6kl_alloc_netbufs(&p_aggr->rx_amsdu_freeq,
  692. AGGR_NUM_OF_FREE_NETBUFS);
  693. skb = skb_dequeue(&p_aggr->rx_amsdu_freeq);
  694. return skb;
  695. }
  696. void ath6kl_rx_refill(struct htc_target *target, enum htc_endpoint_id endpoint)
  697. {
  698. struct ath6kl *ar = target->dev->ar;
  699. struct sk_buff *skb;
  700. int rx_buf;
  701. int n_buf_refill;
  702. struct htc_packet *packet;
  703. struct list_head queue;
  704. n_buf_refill = ATH6KL_MAX_RX_BUFFERS -
  705. ath6kl_htc_get_rxbuf_num(ar->htc_target, endpoint);
  706. if (n_buf_refill <= 0)
  707. return;
  708. INIT_LIST_HEAD(&queue);
  709. ath6kl_dbg(ATH6KL_DBG_WLAN_RX,
  710. "%s: providing htc with %d buffers at eid=%d\n",
  711. __func__, n_buf_refill, endpoint);
  712. for (rx_buf = 0; rx_buf < n_buf_refill; rx_buf++) {
  713. skb = ath6kl_buf_alloc(ATH6KL_BUFFER_SIZE);
  714. if (!skb)
  715. break;
  716. packet = (struct htc_packet *) skb->head;
  717. if (!IS_ALIGNED((unsigned long) skb->data, 4))
  718. skb->data = PTR_ALIGN(skb->data - 4, 4);
  719. set_htc_rxpkt_info(packet, skb, skb->data,
  720. ATH6KL_BUFFER_SIZE, endpoint);
  721. list_add_tail(&packet->list, &queue);
  722. }
  723. if (!list_empty(&queue))
  724. ath6kl_htc_add_rxbuf_multiple(ar->htc_target, &queue);
  725. }
  726. void ath6kl_refill_amsdu_rxbufs(struct ath6kl *ar, int count)
  727. {
  728. struct htc_packet *packet;
  729. struct sk_buff *skb;
  730. while (count) {
  731. skb = ath6kl_buf_alloc(ATH6KL_AMSDU_BUFFER_SIZE);
  732. if (!skb)
  733. return;
  734. packet = (struct htc_packet *) skb->head;
  735. if (!IS_ALIGNED((unsigned long) skb->data, 4))
  736. skb->data = PTR_ALIGN(skb->data - 4, 4);
  737. set_htc_rxpkt_info(packet, skb, skb->data,
  738. ATH6KL_AMSDU_BUFFER_SIZE, 0);
  739. spin_lock_bh(&ar->lock);
  740. list_add_tail(&packet->list, &ar->amsdu_rx_buffer_queue);
  741. spin_unlock_bh(&ar->lock);
  742. count--;
  743. }
  744. }
  745. /*
  746. * Callback to allocate a receive buffer for a pending packet. We use a
  747. * pre-allocated list of buffers of maximum AMSDU size (4K).
  748. */
  749. struct htc_packet *ath6kl_alloc_amsdu_rxbuf(struct htc_target *target,
  750. enum htc_endpoint_id endpoint,
  751. int len)
  752. {
  753. struct ath6kl *ar = target->dev->ar;
  754. struct htc_packet *packet = NULL;
  755. struct list_head *pkt_pos;
  756. int refill_cnt = 0, depth = 0;
  757. ath6kl_dbg(ATH6KL_DBG_WLAN_RX, "%s: eid=%d, len:%d\n",
  758. __func__, endpoint, len);
  759. if ((len <= ATH6KL_BUFFER_SIZE) ||
  760. (len > ATH6KL_AMSDU_BUFFER_SIZE))
  761. return NULL;
  762. spin_lock_bh(&ar->lock);
  763. if (list_empty(&ar->amsdu_rx_buffer_queue)) {
  764. spin_unlock_bh(&ar->lock);
  765. refill_cnt = ATH6KL_MAX_AMSDU_RX_BUFFERS;
  766. goto refill_buf;
  767. }
  768. packet = list_first_entry(&ar->amsdu_rx_buffer_queue,
  769. struct htc_packet, list);
  770. list_del(&packet->list);
  771. list_for_each(pkt_pos, &ar->amsdu_rx_buffer_queue)
  772. depth++;
  773. refill_cnt = ATH6KL_MAX_AMSDU_RX_BUFFERS - depth;
  774. spin_unlock_bh(&ar->lock);
  775. /* set actual endpoint ID */
  776. packet->endpoint = endpoint;
  777. refill_buf:
  778. if (refill_cnt >= ATH6KL_AMSDU_REFILL_THRESHOLD)
  779. ath6kl_refill_amsdu_rxbufs(ar, refill_cnt);
  780. return packet;
  781. }
  782. static void aggr_slice_amsdu(struct aggr_info *p_aggr,
  783. struct rxtid *rxtid, struct sk_buff *skb)
  784. {
  785. struct sk_buff *new_skb;
  786. struct ethhdr *hdr;
  787. u16 frame_8023_len, payload_8023_len, mac_hdr_len, amsdu_len;
  788. u8 *framep;
  789. mac_hdr_len = sizeof(struct ethhdr);
  790. framep = skb->data + mac_hdr_len;
  791. amsdu_len = skb->len - mac_hdr_len;
  792. while (amsdu_len > mac_hdr_len) {
  793. hdr = (struct ethhdr *) framep;
  794. payload_8023_len = ntohs(hdr->h_proto);
  795. if (payload_8023_len < MIN_MSDU_SUBFRAME_PAYLOAD_LEN ||
  796. payload_8023_len > MAX_MSDU_SUBFRAME_PAYLOAD_LEN) {
  797. ath6kl_err("802.3 AMSDU frame bound check failed. len %d\n",
  798. payload_8023_len);
  799. break;
  800. }
  801. frame_8023_len = payload_8023_len + mac_hdr_len;
  802. new_skb = aggr_get_free_skb(p_aggr);
  803. if (!new_skb) {
  804. ath6kl_err("no buffer available\n");
  805. break;
  806. }
  807. memcpy(new_skb->data, framep, frame_8023_len);
  808. skb_put(new_skb, frame_8023_len);
  809. if (ath6kl_wmi_dot3_2_dix(new_skb)) {
  810. ath6kl_err("dot3_2_dix error\n");
  811. dev_kfree_skb(new_skb);
  812. break;
  813. }
  814. skb_queue_tail(&rxtid->q, new_skb);
  815. /* Is this the last subframe within this aggregate ? */
  816. if ((amsdu_len - frame_8023_len) == 0)
  817. break;
  818. /* Add the length of A-MSDU subframe padding bytes -
  819. * Round to nearest word.
  820. */
  821. frame_8023_len = ALIGN(frame_8023_len, 4);
  822. framep += frame_8023_len;
  823. amsdu_len -= frame_8023_len;
  824. }
  825. dev_kfree_skb(skb);
  826. }
  827. static void aggr_deque_frms(struct aggr_info_conn *agg_conn, u8 tid,
  828. u16 seq_no, u8 order)
  829. {
  830. struct sk_buff *skb;
  831. struct rxtid *rxtid;
  832. struct skb_hold_q *node;
  833. u16 idx, idx_end, seq_end;
  834. struct rxtid_stats *stats;
  835. rxtid = &agg_conn->rx_tid[tid];
  836. stats = &agg_conn->stat[tid];
  837. idx = AGGR_WIN_IDX(rxtid->seq_next, rxtid->hold_q_sz);
  838. /*
  839. * idx_end is typically the last possible frame in the window,
  840. * but changes to 'the' seq_no, when BAR comes. If seq_no
  841. * is non-zero, we will go up to that and stop.
  842. * Note: last seq no in current window will occupy the same
  843. * index position as index that is just previous to start.
  844. * An imp point : if win_sz is 7, for seq_no space of 4095,
  845. * then, there would be holes when sequence wrap around occurs.
  846. * Target should judiciously choose the win_sz, based on
  847. * this condition. For 4095, (TID_WINDOW_SZ = 2 x win_sz
  848. * 2, 4, 8, 16 win_sz works fine).
  849. * We must deque from "idx" to "idx_end", including both.
  850. */
  851. seq_end = seq_no ? seq_no : rxtid->seq_next;
  852. idx_end = AGGR_WIN_IDX(seq_end, rxtid->hold_q_sz);
  853. spin_lock_bh(&rxtid->lock);
  854. do {
  855. node = &rxtid->hold_q[idx];
  856. if ((order == 1) && (!node->skb))
  857. break;
  858. if (node->skb) {
  859. if (node->is_amsdu)
  860. aggr_slice_amsdu(agg_conn->aggr_info, rxtid,
  861. node->skb);
  862. else
  863. skb_queue_tail(&rxtid->q, node->skb);
  864. node->skb = NULL;
  865. } else
  866. stats->num_hole++;
  867. rxtid->seq_next = ATH6KL_NEXT_SEQ_NO(rxtid->seq_next);
  868. idx = AGGR_WIN_IDX(rxtid->seq_next, rxtid->hold_q_sz);
  869. } while (idx != idx_end);
  870. spin_unlock_bh(&rxtid->lock);
  871. stats->num_delivered += skb_queue_len(&rxtid->q);
  872. while ((skb = skb_dequeue(&rxtid->q)))
  873. ath6kl_deliver_frames_to_nw_stack(agg_conn->dev, skb);
  874. }
  875. static bool aggr_process_recv_frm(struct aggr_info_conn *agg_conn, u8 tid,
  876. u16 seq_no,
  877. bool is_amsdu, struct sk_buff *frame)
  878. {
  879. struct rxtid *rxtid;
  880. struct rxtid_stats *stats;
  881. struct sk_buff *skb;
  882. struct skb_hold_q *node;
  883. u16 idx, st, cur, end;
  884. bool is_queued = false;
  885. u16 extended_end;
  886. rxtid = &agg_conn->rx_tid[tid];
  887. stats = &agg_conn->stat[tid];
  888. stats->num_into_aggr++;
  889. if (!rxtid->aggr) {
  890. if (is_amsdu) {
  891. aggr_slice_amsdu(agg_conn->aggr_info, rxtid, frame);
  892. is_queued = true;
  893. stats->num_amsdu++;
  894. while ((skb = skb_dequeue(&rxtid->q)))
  895. ath6kl_deliver_frames_to_nw_stack(agg_conn->dev,
  896. skb);
  897. }
  898. return is_queued;
  899. }
  900. /* Check the incoming sequence no, if it's in the window */
  901. st = rxtid->seq_next;
  902. cur = seq_no;
  903. end = (st + rxtid->hold_q_sz-1) & ATH6KL_MAX_SEQ_NO;
  904. if (((st < end) && (cur < st || cur > end)) ||
  905. ((st > end) && (cur > end) && (cur < st))) {
  906. extended_end = (end + rxtid->hold_q_sz - 1) &
  907. ATH6KL_MAX_SEQ_NO;
  908. if (((end < extended_end) &&
  909. (cur < end || cur > extended_end)) ||
  910. ((end > extended_end) && (cur > extended_end) &&
  911. (cur < end))) {
  912. aggr_deque_frms(agg_conn, tid, 0, 0);
  913. if (cur >= rxtid->hold_q_sz - 1)
  914. rxtid->seq_next = cur - (rxtid->hold_q_sz - 1);
  915. else
  916. rxtid->seq_next = ATH6KL_MAX_SEQ_NO -
  917. (rxtid->hold_q_sz - 2 - cur);
  918. } else {
  919. /*
  920. * Dequeue only those frames that are outside the
  921. * new shifted window.
  922. */
  923. if (cur >= rxtid->hold_q_sz - 1)
  924. st = cur - (rxtid->hold_q_sz - 1);
  925. else
  926. st = ATH6KL_MAX_SEQ_NO -
  927. (rxtid->hold_q_sz - 2 - cur);
  928. aggr_deque_frms(agg_conn, tid, st, 0);
  929. }
  930. stats->num_oow++;
  931. }
  932. idx = AGGR_WIN_IDX(seq_no, rxtid->hold_q_sz);
  933. node = &rxtid->hold_q[idx];
  934. spin_lock_bh(&rxtid->lock);
  935. /*
  936. * Is the cur frame duplicate or something beyond our window(hold_q
  937. * -> which is 2x, already)?
  938. *
  939. * 1. Duplicate is easy - drop incoming frame.
  940. * 2. Not falling in current sliding window.
  941. * 2a. is the frame_seq_no preceding current tid_seq_no?
  942. * -> drop the frame. perhaps sender did not get our ACK.
  943. * this is taken care of above.
  944. * 2b. is the frame_seq_no beyond window(st, TID_WINDOW_SZ);
  945. * -> Taken care of it above, by moving window forward.
  946. */
  947. dev_kfree_skb(node->skb);
  948. stats->num_dups++;
  949. node->skb = frame;
  950. is_queued = true;
  951. node->is_amsdu = is_amsdu;
  952. node->seq_no = seq_no;
  953. if (node->is_amsdu)
  954. stats->num_amsdu++;
  955. else
  956. stats->num_mpdu++;
  957. spin_unlock_bh(&rxtid->lock);
  958. aggr_deque_frms(agg_conn, tid, 0, 1);
  959. if (agg_conn->timer_scheduled)
  960. rxtid->progress = true;
  961. else
  962. for (idx = 0 ; idx < rxtid->hold_q_sz; idx++) {
  963. if (rxtid->hold_q[idx].skb) {
  964. /*
  965. * There is a frame in the queue and no
  966. * timer so start a timer to ensure that
  967. * the frame doesn't remain stuck
  968. * forever.
  969. */
  970. agg_conn->timer_scheduled = true;
  971. mod_timer(&agg_conn->timer,
  972. (jiffies +
  973. HZ * (AGGR_RX_TIMEOUT) / 1000));
  974. rxtid->progress = false;
  975. rxtid->timer_mon = true;
  976. break;
  977. }
  978. }
  979. return is_queued;
  980. }
  981. static void ath6kl_uapsd_trigger_frame_rx(struct ath6kl_vif *vif,
  982. struct ath6kl_sta *conn)
  983. {
  984. struct ath6kl *ar = vif->ar;
  985. bool is_apsdq_empty, is_apsdq_empty_at_start;
  986. u32 num_frames_to_deliver, flags;
  987. struct sk_buff *skb = NULL;
  988. /*
  989. * If the APSD q for this STA is not empty, dequeue and
  990. * send a pkt from the head of the q. Also update the
  991. * More data bit in the WMI_DATA_HDR if there are
  992. * more pkts for this STA in the APSD q.
  993. * If there are no more pkts for this STA,
  994. * update the APSD bitmap for this STA.
  995. */
  996. num_frames_to_deliver = (conn->apsd_info >> ATH6KL_APSD_NUM_OF_AC) &
  997. ATH6KL_APSD_FRAME_MASK;
  998. /*
  999. * Number of frames to send in a service period is
  1000. * indicated by the station
  1001. * in the QOS_INFO of the association request
  1002. * If it is zero, send all frames
  1003. */
  1004. if (!num_frames_to_deliver)
  1005. num_frames_to_deliver = ATH6KL_APSD_ALL_FRAME;
  1006. spin_lock_bh(&conn->psq_lock);
  1007. is_apsdq_empty = skb_queue_empty(&conn->apsdq);
  1008. spin_unlock_bh(&conn->psq_lock);
  1009. is_apsdq_empty_at_start = is_apsdq_empty;
  1010. while ((!is_apsdq_empty) && (num_frames_to_deliver)) {
  1011. spin_lock_bh(&conn->psq_lock);
  1012. skb = skb_dequeue(&conn->apsdq);
  1013. is_apsdq_empty = skb_queue_empty(&conn->apsdq);
  1014. spin_unlock_bh(&conn->psq_lock);
  1015. /*
  1016. * Set the STA flag to Trigger delivery,
  1017. * so that the frame will go out
  1018. */
  1019. conn->sta_flags |= STA_PS_APSD_TRIGGER;
  1020. num_frames_to_deliver--;
  1021. /* Last frame in the service period, set EOSP or queue empty */
  1022. if ((is_apsdq_empty) || (!num_frames_to_deliver))
  1023. conn->sta_flags |= STA_PS_APSD_EOSP;
  1024. ath6kl_data_tx(skb, vif->ndev);
  1025. conn->sta_flags &= ~(STA_PS_APSD_TRIGGER);
  1026. conn->sta_flags &= ~(STA_PS_APSD_EOSP);
  1027. }
  1028. if (is_apsdq_empty) {
  1029. if (is_apsdq_empty_at_start)
  1030. flags = WMI_AP_APSD_NO_DELIVERY_FRAMES;
  1031. else
  1032. flags = 0;
  1033. ath6kl_wmi_set_apsd_bfrd_traf(ar->wmi,
  1034. vif->fw_vif_idx,
  1035. conn->aid, 0, flags);
  1036. }
  1037. return;
  1038. }
  1039. void ath6kl_rx(struct htc_target *target, struct htc_packet *packet)
  1040. {
  1041. struct ath6kl *ar = target->dev->ar;
  1042. struct sk_buff *skb = packet->pkt_cntxt;
  1043. struct wmi_rx_meta_v2 *meta;
  1044. struct wmi_data_hdr *dhdr;
  1045. int min_hdr_len;
  1046. u8 meta_type, dot11_hdr = 0;
  1047. int status = packet->status;
  1048. enum htc_endpoint_id ept = packet->endpoint;
  1049. bool is_amsdu, prev_ps, ps_state = false;
  1050. bool trig_state = false;
  1051. struct ath6kl_sta *conn = NULL;
  1052. struct sk_buff *skb1 = NULL;
  1053. struct ethhdr *datap = NULL;
  1054. struct ath6kl_vif *vif;
  1055. struct aggr_info_conn *aggr_conn;
  1056. u16 seq_no, offset;
  1057. u8 tid, if_idx;
  1058. ath6kl_dbg(ATH6KL_DBG_WLAN_RX,
  1059. "%s: ar=0x%p eid=%d, skb=0x%p, data=0x%p, len=0x%x status:%d",
  1060. __func__, ar, ept, skb, packet->buf,
  1061. packet->act_len, status);
  1062. if (status || !(skb->data + HTC_HDR_LENGTH)) {
  1063. dev_kfree_skb(skb);
  1064. return;
  1065. }
  1066. skb_put(skb, packet->act_len + HTC_HDR_LENGTH);
  1067. skb_pull(skb, HTC_HDR_LENGTH);
  1068. if (ept == ar->ctrl_ep) {
  1069. if_idx =
  1070. wmi_cmd_hdr_get_if_idx((struct wmi_cmd_hdr *) skb->data);
  1071. } else {
  1072. if_idx =
  1073. wmi_data_hdr_get_if_idx((struct wmi_data_hdr *) skb->data);
  1074. }
  1075. vif = ath6kl_get_vif_by_index(ar, if_idx);
  1076. if (!vif) {
  1077. dev_kfree_skb(skb);
  1078. return;
  1079. }
  1080. /*
  1081. * Take lock to protect buffer counts and adaptive power throughput
  1082. * state.
  1083. */
  1084. spin_lock_bh(&vif->if_lock);
  1085. vif->net_stats.rx_packets++;
  1086. vif->net_stats.rx_bytes += packet->act_len;
  1087. spin_unlock_bh(&vif->if_lock);
  1088. ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, __func__, "rx ",
  1089. skb->data, skb->len);
  1090. skb->dev = vif->ndev;
  1091. if (!test_bit(WMI_ENABLED, &ar->flag)) {
  1092. if (EPPING_ALIGNMENT_PAD > 0)
  1093. skb_pull(skb, EPPING_ALIGNMENT_PAD);
  1094. ath6kl_deliver_frames_to_nw_stack(vif->ndev, skb);
  1095. return;
  1096. }
  1097. ath6kl_check_wow_status(ar);
  1098. if (ept == ar->ctrl_ep) {
  1099. ath6kl_wmi_control_rx(ar->wmi, skb);
  1100. return;
  1101. }
  1102. min_hdr_len = sizeof(struct ethhdr) + sizeof(struct wmi_data_hdr) +
  1103. sizeof(struct ath6kl_llc_snap_hdr);
  1104. dhdr = (struct wmi_data_hdr *) skb->data;
  1105. /*
  1106. * In the case of AP mode we may receive NULL data frames
  1107. * that do not have LLC hdr. They are 16 bytes in size.
  1108. * Allow these frames in the AP mode.
  1109. */
  1110. if (vif->nw_type != AP_NETWORK &&
  1111. ((packet->act_len < min_hdr_len) ||
  1112. (packet->act_len > WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH))) {
  1113. ath6kl_info("frame len is too short or too long\n");
  1114. vif->net_stats.rx_errors++;
  1115. vif->net_stats.rx_length_errors++;
  1116. dev_kfree_skb(skb);
  1117. return;
  1118. }
  1119. /* Get the Power save state of the STA */
  1120. if (vif->nw_type == AP_NETWORK) {
  1121. meta_type = wmi_data_hdr_get_meta(dhdr);
  1122. ps_state = !!((dhdr->info >> WMI_DATA_HDR_PS_SHIFT) &
  1123. WMI_DATA_HDR_PS_MASK);
  1124. offset = sizeof(struct wmi_data_hdr);
  1125. trig_state = !!(le16_to_cpu(dhdr->info3) & WMI_DATA_HDR_TRIG);
  1126. switch (meta_type) {
  1127. case 0:
  1128. break;
  1129. case WMI_META_VERSION_1:
  1130. offset += sizeof(struct wmi_rx_meta_v1);
  1131. break;
  1132. case WMI_META_VERSION_2:
  1133. offset += sizeof(struct wmi_rx_meta_v2);
  1134. break;
  1135. default:
  1136. break;
  1137. }
  1138. datap = (struct ethhdr *) (skb->data + offset);
  1139. conn = ath6kl_find_sta(vif, datap->h_source);
  1140. if (!conn) {
  1141. dev_kfree_skb(skb);
  1142. return;
  1143. }
  1144. /*
  1145. * If there is a change in PS state of the STA,
  1146. * take appropriate steps:
  1147. *
  1148. * 1. If Sleep-->Awake, flush the psq for the STA
  1149. * Clear the PVB for the STA.
  1150. * 2. If Awake-->Sleep, Starting queueing frames
  1151. * the STA.
  1152. */
  1153. prev_ps = !!(conn->sta_flags & STA_PS_SLEEP);
  1154. if (ps_state)
  1155. conn->sta_flags |= STA_PS_SLEEP;
  1156. else
  1157. conn->sta_flags &= ~STA_PS_SLEEP;
  1158. /* Accept trigger only when the station is in sleep */
  1159. if ((conn->sta_flags & STA_PS_SLEEP) && trig_state)
  1160. ath6kl_uapsd_trigger_frame_rx(vif, conn);
  1161. if (prev_ps ^ !!(conn->sta_flags & STA_PS_SLEEP)) {
  1162. if (!(conn->sta_flags & STA_PS_SLEEP)) {
  1163. struct sk_buff *skbuff = NULL;
  1164. bool is_apsdq_empty;
  1165. spin_lock_bh(&conn->psq_lock);
  1166. while ((skbuff = skb_dequeue(&conn->psq))) {
  1167. spin_unlock_bh(&conn->psq_lock);
  1168. ath6kl_data_tx(skbuff, vif->ndev);
  1169. spin_lock_bh(&conn->psq_lock);
  1170. }
  1171. is_apsdq_empty = skb_queue_empty(&conn->apsdq);
  1172. while ((skbuff = skb_dequeue(&conn->apsdq))) {
  1173. spin_unlock_bh(&conn->psq_lock);
  1174. ath6kl_data_tx(skbuff, vif->ndev);
  1175. spin_lock_bh(&conn->psq_lock);
  1176. }
  1177. spin_unlock_bh(&conn->psq_lock);
  1178. if (!is_apsdq_empty)
  1179. ath6kl_wmi_set_apsd_bfrd_traf(
  1180. ar->wmi,
  1181. vif->fw_vif_idx,
  1182. conn->aid, 0, 0);
  1183. /* Clear the PVB for this STA */
  1184. ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx,
  1185. conn->aid, 0);
  1186. }
  1187. }
  1188. /* drop NULL data frames here */
  1189. if ((packet->act_len < min_hdr_len) ||
  1190. (packet->act_len >
  1191. WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH)) {
  1192. dev_kfree_skb(skb);
  1193. return;
  1194. }
  1195. }
  1196. is_amsdu = wmi_data_hdr_is_amsdu(dhdr) ? true : false;
  1197. tid = wmi_data_hdr_get_up(dhdr);
  1198. seq_no = wmi_data_hdr_get_seqno(dhdr);
  1199. meta_type = wmi_data_hdr_get_meta(dhdr);
  1200. dot11_hdr = wmi_data_hdr_get_dot11(dhdr);
  1201. skb_pull(skb, sizeof(struct wmi_data_hdr));
  1202. switch (meta_type) {
  1203. case WMI_META_VERSION_1:
  1204. skb_pull(skb, sizeof(struct wmi_rx_meta_v1));
  1205. break;
  1206. case WMI_META_VERSION_2:
  1207. meta = (struct wmi_rx_meta_v2 *) skb->data;
  1208. if (meta->csum_flags & 0x1) {
  1209. skb->ip_summed = CHECKSUM_COMPLETE;
  1210. skb->csum = (__force __wsum) meta->csum;
  1211. }
  1212. skb_pull(skb, sizeof(struct wmi_rx_meta_v2));
  1213. break;
  1214. default:
  1215. break;
  1216. }
  1217. if (dot11_hdr)
  1218. status = ath6kl_wmi_dot11_hdr_remove(ar->wmi, skb);
  1219. else if (!is_amsdu)
  1220. status = ath6kl_wmi_dot3_2_dix(skb);
  1221. if (status) {
  1222. /*
  1223. * Drop frames that could not be processed (lack of
  1224. * memory, etc.)
  1225. */
  1226. dev_kfree_skb(skb);
  1227. return;
  1228. }
  1229. if (!(vif->ndev->flags & IFF_UP)) {
  1230. dev_kfree_skb(skb);
  1231. return;
  1232. }
  1233. if (vif->nw_type == AP_NETWORK) {
  1234. datap = (struct ethhdr *) skb->data;
  1235. if (is_multicast_ether_addr(datap->h_dest))
  1236. /*
  1237. * Bcast/Mcast frames should be sent to the
  1238. * OS stack as well as on the air.
  1239. */
  1240. skb1 = skb_copy(skb, GFP_ATOMIC);
  1241. else {
  1242. /*
  1243. * Search for a connected STA with dstMac
  1244. * as the Mac address. If found send the
  1245. * frame to it on the air else send the
  1246. * frame up the stack.
  1247. */
  1248. conn = ath6kl_find_sta(vif, datap->h_dest);
  1249. if (conn && ar->intra_bss) {
  1250. skb1 = skb;
  1251. skb = NULL;
  1252. } else if (conn && !ar->intra_bss) {
  1253. dev_kfree_skb(skb);
  1254. skb = NULL;
  1255. }
  1256. }
  1257. if (skb1)
  1258. ath6kl_data_tx(skb1, vif->ndev);
  1259. if (skb == NULL) {
  1260. /* nothing to deliver up the stack */
  1261. return;
  1262. }
  1263. }
  1264. datap = (struct ethhdr *) skb->data;
  1265. if (is_unicast_ether_addr(datap->h_dest)) {
  1266. if (vif->nw_type == AP_NETWORK) {
  1267. conn = ath6kl_find_sta(vif, datap->h_source);
  1268. if (!conn)
  1269. return;
  1270. aggr_conn = conn->aggr_conn;
  1271. } else
  1272. aggr_conn = vif->aggr_cntxt->aggr_conn;
  1273. if (aggr_process_recv_frm(aggr_conn, tid, seq_no,
  1274. is_amsdu, skb)) {
  1275. /* aggregation code will handle the skb */
  1276. return;
  1277. }
  1278. }
  1279. ath6kl_deliver_frames_to_nw_stack(vif->ndev, skb);
  1280. }
  1281. static void aggr_timeout(unsigned long arg)
  1282. {
  1283. u8 i, j;
  1284. struct aggr_info_conn *aggr_conn = (struct aggr_info_conn *) arg;
  1285. struct rxtid *rxtid;
  1286. struct rxtid_stats *stats;
  1287. for (i = 0; i < NUM_OF_TIDS; i++) {
  1288. rxtid = &aggr_conn->rx_tid[i];
  1289. stats = &aggr_conn->stat[i];
  1290. if (!rxtid->aggr || !rxtid->timer_mon || rxtid->progress)
  1291. continue;
  1292. stats->num_timeouts++;
  1293. ath6kl_dbg(ATH6KL_DBG_AGGR,
  1294. "aggr timeout (st %d end %d)\n",
  1295. rxtid->seq_next,
  1296. ((rxtid->seq_next + rxtid->hold_q_sz-1) &
  1297. ATH6KL_MAX_SEQ_NO));
  1298. aggr_deque_frms(aggr_conn, i, 0, 0);
  1299. }
  1300. aggr_conn->timer_scheduled = false;
  1301. for (i = 0; i < NUM_OF_TIDS; i++) {
  1302. rxtid = &aggr_conn->rx_tid[i];
  1303. if (rxtid->aggr && rxtid->hold_q) {
  1304. for (j = 0; j < rxtid->hold_q_sz; j++) {
  1305. if (rxtid->hold_q[j].skb) {
  1306. aggr_conn->timer_scheduled = true;
  1307. rxtid->timer_mon = true;
  1308. rxtid->progress = false;
  1309. break;
  1310. }
  1311. }
  1312. if (j >= rxtid->hold_q_sz)
  1313. rxtid->timer_mon = false;
  1314. }
  1315. }
  1316. if (aggr_conn->timer_scheduled)
  1317. mod_timer(&aggr_conn->timer,
  1318. jiffies + msecs_to_jiffies(AGGR_RX_TIMEOUT));
  1319. }
  1320. static void aggr_delete_tid_state(struct aggr_info_conn *aggr_conn, u8 tid)
  1321. {
  1322. struct rxtid *rxtid;
  1323. struct rxtid_stats *stats;
  1324. if (!aggr_conn || tid >= NUM_OF_TIDS)
  1325. return;
  1326. rxtid = &aggr_conn->rx_tid[tid];
  1327. stats = &aggr_conn->stat[tid];
  1328. if (rxtid->aggr)
  1329. aggr_deque_frms(aggr_conn, tid, 0, 0);
  1330. rxtid->aggr = false;
  1331. rxtid->progress = false;
  1332. rxtid->timer_mon = false;
  1333. rxtid->win_sz = 0;
  1334. rxtid->seq_next = 0;
  1335. rxtid->hold_q_sz = 0;
  1336. kfree(rxtid->hold_q);
  1337. rxtid->hold_q = NULL;
  1338. memset(stats, 0, sizeof(struct rxtid_stats));
  1339. }
  1340. void aggr_recv_addba_req_evt(struct ath6kl_vif *vif, u8 tid_mux, u16 seq_no,
  1341. u8 win_sz)
  1342. {
  1343. struct ath6kl_sta *sta;
  1344. struct aggr_info_conn *aggr_conn = NULL;
  1345. struct rxtid *rxtid;
  1346. struct rxtid_stats *stats;
  1347. u16 hold_q_size;
  1348. u8 tid, aid;
  1349. if (vif->nw_type == AP_NETWORK) {
  1350. aid = ath6kl_get_aid(tid_mux);
  1351. sta = ath6kl_find_sta_by_aid(vif->ar, aid);
  1352. if (sta)
  1353. aggr_conn = sta->aggr_conn;
  1354. } else
  1355. aggr_conn = vif->aggr_cntxt->aggr_conn;
  1356. if (!aggr_conn)
  1357. return;
  1358. tid = ath6kl_get_tid(tid_mux);
  1359. if (tid >= NUM_OF_TIDS)
  1360. return;
  1361. rxtid = &aggr_conn->rx_tid[tid];
  1362. stats = &aggr_conn->stat[tid];
  1363. if (win_sz < AGGR_WIN_SZ_MIN || win_sz > AGGR_WIN_SZ_MAX)
  1364. ath6kl_dbg(ATH6KL_DBG_WLAN_RX, "%s: win_sz %d, tid %d\n",
  1365. __func__, win_sz, tid);
  1366. if (rxtid->aggr)
  1367. aggr_delete_tid_state(aggr_conn, tid);
  1368. rxtid->seq_next = seq_no;
  1369. hold_q_size = TID_WINDOW_SZ(win_sz) * sizeof(struct skb_hold_q);
  1370. rxtid->hold_q = kzalloc(hold_q_size, GFP_KERNEL);
  1371. if (!rxtid->hold_q)
  1372. return;
  1373. rxtid->win_sz = win_sz;
  1374. rxtid->hold_q_sz = TID_WINDOW_SZ(win_sz);
  1375. if (!skb_queue_empty(&rxtid->q))
  1376. return;
  1377. rxtid->aggr = true;
  1378. }
  1379. void aggr_conn_init(struct ath6kl_vif *vif, struct aggr_info *aggr_info,
  1380. struct aggr_info_conn *aggr_conn)
  1381. {
  1382. struct rxtid *rxtid;
  1383. u8 i;
  1384. aggr_conn->aggr_sz = AGGR_SZ_DEFAULT;
  1385. aggr_conn->dev = vif->ndev;
  1386. init_timer(&aggr_conn->timer);
  1387. aggr_conn->timer.function = aggr_timeout;
  1388. aggr_conn->timer.data = (unsigned long) aggr_conn;
  1389. aggr_conn->aggr_info = aggr_info;
  1390. aggr_conn->timer_scheduled = false;
  1391. for (i = 0; i < NUM_OF_TIDS; i++) {
  1392. rxtid = &aggr_conn->rx_tid[i];
  1393. rxtid->aggr = false;
  1394. rxtid->progress = false;
  1395. rxtid->timer_mon = false;
  1396. skb_queue_head_init(&rxtid->q);
  1397. spin_lock_init(&rxtid->lock);
  1398. }
  1399. }
  1400. struct aggr_info *aggr_init(struct ath6kl_vif *vif)
  1401. {
  1402. struct aggr_info *p_aggr = NULL;
  1403. p_aggr = kzalloc(sizeof(struct aggr_info), GFP_KERNEL);
  1404. if (!p_aggr) {
  1405. ath6kl_err("failed to alloc memory for aggr_node\n");
  1406. return NULL;
  1407. }
  1408. p_aggr->aggr_conn = kzalloc(sizeof(struct aggr_info_conn), GFP_KERNEL);
  1409. if (!p_aggr->aggr_conn) {
  1410. ath6kl_err("failed to alloc memory for connection specific aggr info\n");
  1411. kfree(p_aggr);
  1412. return NULL;
  1413. }
  1414. aggr_conn_init(vif, p_aggr, p_aggr->aggr_conn);
  1415. skb_queue_head_init(&p_aggr->rx_amsdu_freeq);
  1416. ath6kl_alloc_netbufs(&p_aggr->rx_amsdu_freeq, AGGR_NUM_OF_FREE_NETBUFS);
  1417. return p_aggr;
  1418. }
  1419. void aggr_recv_delba_req_evt(struct ath6kl_vif *vif, u8 tid_mux)
  1420. {
  1421. struct ath6kl_sta *sta;
  1422. struct rxtid *rxtid;
  1423. struct aggr_info_conn *aggr_conn = NULL;
  1424. u8 tid, aid;
  1425. if (vif->nw_type == AP_NETWORK) {
  1426. aid = ath6kl_get_aid(tid_mux);
  1427. sta = ath6kl_find_sta_by_aid(vif->ar, aid);
  1428. if (sta)
  1429. aggr_conn = sta->aggr_conn;
  1430. } else
  1431. aggr_conn = vif->aggr_cntxt->aggr_conn;
  1432. if (!aggr_conn)
  1433. return;
  1434. tid = ath6kl_get_tid(tid_mux);
  1435. if (tid >= NUM_OF_TIDS)
  1436. return;
  1437. rxtid = &aggr_conn->rx_tid[tid];
  1438. if (rxtid->aggr)
  1439. aggr_delete_tid_state(aggr_conn, tid);
  1440. }
  1441. void aggr_reset_state(struct aggr_info_conn *aggr_conn)
  1442. {
  1443. u8 tid;
  1444. if (!aggr_conn)
  1445. return;
  1446. if (aggr_conn->timer_scheduled) {
  1447. del_timer(&aggr_conn->timer);
  1448. aggr_conn->timer_scheduled = false;
  1449. }
  1450. for (tid = 0; tid < NUM_OF_TIDS; tid++)
  1451. aggr_delete_tid_state(aggr_conn, tid);
  1452. }
  1453. /* clean up our amsdu buffer list */
  1454. void ath6kl_cleanup_amsdu_rxbufs(struct ath6kl *ar)
  1455. {
  1456. struct htc_packet *packet, *tmp_pkt;
  1457. spin_lock_bh(&ar->lock);
  1458. if (list_empty(&ar->amsdu_rx_buffer_queue)) {
  1459. spin_unlock_bh(&ar->lock);
  1460. return;
  1461. }
  1462. list_for_each_entry_safe(packet, tmp_pkt, &ar->amsdu_rx_buffer_queue,
  1463. list) {
  1464. list_del(&packet->list);
  1465. spin_unlock_bh(&ar->lock);
  1466. dev_kfree_skb(packet->pkt_cntxt);
  1467. spin_lock_bh(&ar->lock);
  1468. }
  1469. spin_unlock_bh(&ar->lock);
  1470. }
  1471. void aggr_module_destroy(struct aggr_info *aggr_info)
  1472. {
  1473. if (!aggr_info)
  1474. return;
  1475. aggr_reset_state(aggr_info->aggr_conn);
  1476. skb_queue_purge(&aggr_info->rx_amsdu_freeq);
  1477. kfree(aggr_info->aggr_conn);
  1478. kfree(aggr_info);
  1479. }