htc_drv_txrx.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  1. /*
  2. * Copyright (c) 2010-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 "htc.h"
  17. /******/
  18. /* TX */
  19. /******/
  20. static const int subtype_txq_to_hwq[] = {
  21. [IEEE80211_AC_BE] = ATH_TXQ_AC_BE,
  22. [IEEE80211_AC_BK] = ATH_TXQ_AC_BK,
  23. [IEEE80211_AC_VI] = ATH_TXQ_AC_VI,
  24. [IEEE80211_AC_VO] = ATH_TXQ_AC_VO,
  25. };
  26. #define ATH9K_HTC_INIT_TXQ(subtype) do { \
  27. qi.tqi_subtype = subtype_txq_to_hwq[subtype]; \
  28. qi.tqi_aifs = ATH9K_TXQ_USEDEFAULT; \
  29. qi.tqi_cwmin = ATH9K_TXQ_USEDEFAULT; \
  30. qi.tqi_cwmax = ATH9K_TXQ_USEDEFAULT; \
  31. qi.tqi_physCompBuf = 0; \
  32. qi.tqi_qflags = TXQ_FLAG_TXEOLINT_ENABLE | \
  33. TXQ_FLAG_TXDESCINT_ENABLE; \
  34. } while (0)
  35. int get_hw_qnum(u16 queue, int *hwq_map)
  36. {
  37. switch (queue) {
  38. case 0:
  39. return hwq_map[IEEE80211_AC_VO];
  40. case 1:
  41. return hwq_map[IEEE80211_AC_VI];
  42. case 2:
  43. return hwq_map[IEEE80211_AC_BE];
  44. case 3:
  45. return hwq_map[IEEE80211_AC_BK];
  46. default:
  47. return hwq_map[IEEE80211_AC_BE];
  48. }
  49. }
  50. void ath9k_htc_check_stop_queues(struct ath9k_htc_priv *priv)
  51. {
  52. spin_lock_bh(&priv->tx.tx_lock);
  53. priv->tx.queued_cnt++;
  54. if ((priv->tx.queued_cnt >= ATH9K_HTC_TX_THRESHOLD) &&
  55. !(priv->tx.flags & ATH9K_HTC_OP_TX_QUEUES_STOP)) {
  56. priv->tx.flags |= ATH9K_HTC_OP_TX_QUEUES_STOP;
  57. ieee80211_stop_queues(priv->hw);
  58. }
  59. spin_unlock_bh(&priv->tx.tx_lock);
  60. }
  61. void ath9k_htc_check_wake_queues(struct ath9k_htc_priv *priv)
  62. {
  63. spin_lock_bh(&priv->tx.tx_lock);
  64. if ((priv->tx.queued_cnt < ATH9K_HTC_TX_THRESHOLD) &&
  65. (priv->tx.flags & ATH9K_HTC_OP_TX_QUEUES_STOP)) {
  66. priv->tx.flags &= ~ATH9K_HTC_OP_TX_QUEUES_STOP;
  67. ieee80211_wake_queues(priv->hw);
  68. }
  69. spin_unlock_bh(&priv->tx.tx_lock);
  70. }
  71. int ath9k_htc_tx_get_slot(struct ath9k_htc_priv *priv)
  72. {
  73. int slot;
  74. spin_lock_bh(&priv->tx.tx_lock);
  75. slot = find_first_zero_bit(priv->tx.tx_slot, MAX_TX_BUF_NUM);
  76. if (slot >= MAX_TX_BUF_NUM) {
  77. spin_unlock_bh(&priv->tx.tx_lock);
  78. return -ENOBUFS;
  79. }
  80. __set_bit(slot, priv->tx.tx_slot);
  81. spin_unlock_bh(&priv->tx.tx_lock);
  82. return slot;
  83. }
  84. void ath9k_htc_tx_clear_slot(struct ath9k_htc_priv *priv, int slot)
  85. {
  86. spin_lock_bh(&priv->tx.tx_lock);
  87. __clear_bit(slot, priv->tx.tx_slot);
  88. spin_unlock_bh(&priv->tx.tx_lock);
  89. }
  90. static inline enum htc_endpoint_id get_htc_epid(struct ath9k_htc_priv *priv,
  91. u16 qnum)
  92. {
  93. enum htc_endpoint_id epid;
  94. switch (qnum) {
  95. case 0:
  96. TX_QSTAT_INC(IEEE80211_AC_VO);
  97. epid = priv->data_vo_ep;
  98. break;
  99. case 1:
  100. TX_QSTAT_INC(IEEE80211_AC_VI);
  101. epid = priv->data_vi_ep;
  102. break;
  103. case 2:
  104. TX_QSTAT_INC(IEEE80211_AC_BE);
  105. epid = priv->data_be_ep;
  106. break;
  107. case 3:
  108. default:
  109. TX_QSTAT_INC(IEEE80211_AC_BK);
  110. epid = priv->data_bk_ep;
  111. break;
  112. }
  113. return epid;
  114. }
  115. static inline struct sk_buff_head*
  116. get_htc_epid_queue(struct ath9k_htc_priv *priv, u8 epid)
  117. {
  118. struct ath_common *common = ath9k_hw_common(priv->ah);
  119. struct sk_buff_head *epid_queue = NULL;
  120. if (epid == priv->mgmt_ep)
  121. epid_queue = &priv->tx.mgmt_ep_queue;
  122. else if (epid == priv->cab_ep)
  123. epid_queue = &priv->tx.cab_ep_queue;
  124. else if (epid == priv->data_be_ep)
  125. epid_queue = &priv->tx.data_be_queue;
  126. else if (epid == priv->data_bk_ep)
  127. epid_queue = &priv->tx.data_bk_queue;
  128. else if (epid == priv->data_vi_ep)
  129. epid_queue = &priv->tx.data_vi_queue;
  130. else if (epid == priv->data_vo_ep)
  131. epid_queue = &priv->tx.data_vo_queue;
  132. else
  133. ath_err(common, "Invalid EPID: %d\n", epid);
  134. return epid_queue;
  135. }
  136. /*
  137. * Removes the driver header and returns the TX slot number
  138. */
  139. static inline int strip_drv_header(struct ath9k_htc_priv *priv,
  140. struct sk_buff *skb)
  141. {
  142. struct ath_common *common = ath9k_hw_common(priv->ah);
  143. struct ath9k_htc_tx_ctl *tx_ctl;
  144. int slot;
  145. tx_ctl = HTC_SKB_CB(skb);
  146. if (tx_ctl->epid == priv->mgmt_ep) {
  147. struct tx_mgmt_hdr *tx_mhdr =
  148. (struct tx_mgmt_hdr *)skb->data;
  149. slot = tx_mhdr->cookie;
  150. skb_pull(skb, sizeof(struct tx_mgmt_hdr));
  151. } else if ((tx_ctl->epid == priv->data_bk_ep) ||
  152. (tx_ctl->epid == priv->data_be_ep) ||
  153. (tx_ctl->epid == priv->data_vi_ep) ||
  154. (tx_ctl->epid == priv->data_vo_ep) ||
  155. (tx_ctl->epid == priv->cab_ep)) {
  156. struct tx_frame_hdr *tx_fhdr =
  157. (struct tx_frame_hdr *)skb->data;
  158. slot = tx_fhdr->cookie;
  159. skb_pull(skb, sizeof(struct tx_frame_hdr));
  160. } else {
  161. ath_err(common, "Unsupported EPID: %d\n", tx_ctl->epid);
  162. slot = -EINVAL;
  163. }
  164. return slot;
  165. }
  166. int ath_htc_txq_update(struct ath9k_htc_priv *priv, int qnum,
  167. struct ath9k_tx_queue_info *qinfo)
  168. {
  169. struct ath_hw *ah = priv->ah;
  170. int error = 0;
  171. struct ath9k_tx_queue_info qi;
  172. ath9k_hw_get_txq_props(ah, qnum, &qi);
  173. qi.tqi_aifs = qinfo->tqi_aifs;
  174. qi.tqi_cwmin = qinfo->tqi_cwmin / 2; /* XXX */
  175. qi.tqi_cwmax = qinfo->tqi_cwmax;
  176. qi.tqi_burstTime = qinfo->tqi_burstTime;
  177. qi.tqi_readyTime = qinfo->tqi_readyTime;
  178. if (!ath9k_hw_set_txq_props(ah, qnum, &qi)) {
  179. ath_err(ath9k_hw_common(ah),
  180. "Unable to update hardware queue %u!\n", qnum);
  181. error = -EIO;
  182. } else {
  183. ath9k_hw_resettxqueue(ah, qnum);
  184. }
  185. return error;
  186. }
  187. static void ath9k_htc_tx_mgmt(struct ath9k_htc_priv *priv,
  188. struct ath9k_htc_vif *avp,
  189. struct sk_buff *skb,
  190. u8 sta_idx, u8 vif_idx, u8 slot)
  191. {
  192. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  193. struct ieee80211_mgmt *mgmt;
  194. struct ieee80211_hdr *hdr;
  195. struct tx_mgmt_hdr mgmt_hdr;
  196. struct ath9k_htc_tx_ctl *tx_ctl;
  197. u8 *tx_fhdr;
  198. tx_ctl = HTC_SKB_CB(skb);
  199. hdr = (struct ieee80211_hdr *) skb->data;
  200. memset(tx_ctl, 0, sizeof(*tx_ctl));
  201. memset(&mgmt_hdr, 0, sizeof(struct tx_mgmt_hdr));
  202. /*
  203. * Set the TSF adjust value for probe response
  204. * frame also.
  205. */
  206. if (avp && unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
  207. mgmt = (struct ieee80211_mgmt *)skb->data;
  208. mgmt->u.probe_resp.timestamp = avp->tsfadjust;
  209. }
  210. tx_ctl->type = ATH9K_HTC_MGMT;
  211. mgmt_hdr.node_idx = sta_idx;
  212. mgmt_hdr.vif_idx = vif_idx;
  213. mgmt_hdr.tidno = 0;
  214. mgmt_hdr.flags = 0;
  215. mgmt_hdr.cookie = slot;
  216. mgmt_hdr.key_type = ath9k_cmn_get_hw_crypto_keytype(skb);
  217. if (mgmt_hdr.key_type == ATH9K_KEY_TYPE_CLEAR)
  218. mgmt_hdr.keyix = (u8) ATH9K_TXKEYIX_INVALID;
  219. else
  220. mgmt_hdr.keyix = tx_info->control.hw_key->hw_key_idx;
  221. tx_fhdr = skb_push(skb, sizeof(mgmt_hdr));
  222. memcpy(tx_fhdr, (u8 *) &mgmt_hdr, sizeof(mgmt_hdr));
  223. tx_ctl->epid = priv->mgmt_ep;
  224. }
  225. static void ath9k_htc_tx_data(struct ath9k_htc_priv *priv,
  226. struct ieee80211_vif *vif,
  227. struct sk_buff *skb,
  228. u8 sta_idx, u8 vif_idx, u8 slot,
  229. bool is_cab)
  230. {
  231. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  232. struct ieee80211_hdr *hdr;
  233. struct ath9k_htc_tx_ctl *tx_ctl;
  234. struct tx_frame_hdr tx_hdr;
  235. u32 flags = 0;
  236. u8 *qc, *tx_fhdr;
  237. u16 qnum;
  238. tx_ctl = HTC_SKB_CB(skb);
  239. hdr = (struct ieee80211_hdr *) skb->data;
  240. memset(tx_ctl, 0, sizeof(*tx_ctl));
  241. memset(&tx_hdr, 0, sizeof(struct tx_frame_hdr));
  242. tx_hdr.node_idx = sta_idx;
  243. tx_hdr.vif_idx = vif_idx;
  244. tx_hdr.cookie = slot;
  245. /*
  246. * This is a bit redundant but it helps to get
  247. * the per-packet index quickly when draining the
  248. * TX queue in the HIF layer. Otherwise we would
  249. * have to parse the packet contents ...
  250. */
  251. tx_ctl->sta_idx = sta_idx;
  252. if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
  253. tx_ctl->type = ATH9K_HTC_AMPDU;
  254. tx_hdr.data_type = ATH9K_HTC_AMPDU;
  255. } else {
  256. tx_ctl->type = ATH9K_HTC_NORMAL;
  257. tx_hdr.data_type = ATH9K_HTC_NORMAL;
  258. }
  259. if (ieee80211_is_data_qos(hdr->frame_control)) {
  260. qc = ieee80211_get_qos_ctl(hdr);
  261. tx_hdr.tidno = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
  262. }
  263. /* Check for RTS protection */
  264. if (priv->hw->wiphy->rts_threshold != (u32) -1)
  265. if (skb->len > priv->hw->wiphy->rts_threshold)
  266. flags |= ATH9K_HTC_TX_RTSCTS;
  267. /* CTS-to-self */
  268. if (!(flags & ATH9K_HTC_TX_RTSCTS) &&
  269. (vif && vif->bss_conf.use_cts_prot))
  270. flags |= ATH9K_HTC_TX_CTSONLY;
  271. tx_hdr.flags = cpu_to_be32(flags);
  272. tx_hdr.key_type = ath9k_cmn_get_hw_crypto_keytype(skb);
  273. if (tx_hdr.key_type == ATH9K_KEY_TYPE_CLEAR)
  274. tx_hdr.keyix = (u8) ATH9K_TXKEYIX_INVALID;
  275. else
  276. tx_hdr.keyix = tx_info->control.hw_key->hw_key_idx;
  277. tx_fhdr = skb_push(skb, sizeof(tx_hdr));
  278. memcpy(tx_fhdr, (u8 *) &tx_hdr, sizeof(tx_hdr));
  279. if (is_cab) {
  280. CAB_STAT_INC;
  281. tx_ctl->epid = priv->cab_ep;
  282. return;
  283. }
  284. qnum = skb_get_queue_mapping(skb);
  285. tx_ctl->epid = get_htc_epid(priv, qnum);
  286. }
  287. int ath9k_htc_tx_start(struct ath9k_htc_priv *priv,
  288. struct ieee80211_sta *sta,
  289. struct sk_buff *skb,
  290. u8 slot, bool is_cab)
  291. {
  292. struct ieee80211_hdr *hdr;
  293. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  294. struct ieee80211_vif *vif = tx_info->control.vif;
  295. struct ath9k_htc_sta *ista;
  296. struct ath9k_htc_vif *avp = NULL;
  297. u8 sta_idx, vif_idx;
  298. hdr = (struct ieee80211_hdr *) skb->data;
  299. /*
  300. * Find out on which interface this packet has to be
  301. * sent out.
  302. */
  303. if (vif) {
  304. avp = (struct ath9k_htc_vif *) vif->drv_priv;
  305. vif_idx = avp->index;
  306. } else {
  307. if (!priv->ah->is_monitoring) {
  308. ath_dbg(ath9k_hw_common(priv->ah), XMIT,
  309. "VIF is null, but no monitor interface !\n");
  310. return -EINVAL;
  311. }
  312. vif_idx = priv->mon_vif_idx;
  313. }
  314. /*
  315. * Find out which station this packet is destined for.
  316. */
  317. if (sta) {
  318. ista = (struct ath9k_htc_sta *) sta->drv_priv;
  319. sta_idx = ista->index;
  320. } else {
  321. sta_idx = priv->vif_sta_pos[vif_idx];
  322. }
  323. if (ieee80211_is_data(hdr->frame_control))
  324. ath9k_htc_tx_data(priv, vif, skb,
  325. sta_idx, vif_idx, slot, is_cab);
  326. else
  327. ath9k_htc_tx_mgmt(priv, avp, skb,
  328. sta_idx, vif_idx, slot);
  329. return htc_send(priv->htc, skb);
  330. }
  331. static inline bool __ath9k_htc_check_tx_aggr(struct ath9k_htc_priv *priv,
  332. struct ath9k_htc_sta *ista, u8 tid)
  333. {
  334. bool ret = false;
  335. spin_lock_bh(&priv->tx.tx_lock);
  336. if ((tid < ATH9K_HTC_MAX_TID) && (ista->tid_state[tid] == AGGR_STOP))
  337. ret = true;
  338. spin_unlock_bh(&priv->tx.tx_lock);
  339. return ret;
  340. }
  341. static void ath9k_htc_check_tx_aggr(struct ath9k_htc_priv *priv,
  342. struct ieee80211_vif *vif,
  343. struct sk_buff *skb)
  344. {
  345. struct ieee80211_sta *sta;
  346. struct ieee80211_hdr *hdr;
  347. __le16 fc;
  348. hdr = (struct ieee80211_hdr *) skb->data;
  349. fc = hdr->frame_control;
  350. rcu_read_lock();
  351. sta = ieee80211_find_sta(vif, hdr->addr1);
  352. if (!sta) {
  353. rcu_read_unlock();
  354. return;
  355. }
  356. if (sta && conf_is_ht(&priv->hw->conf) &&
  357. !(skb->protocol == cpu_to_be16(ETH_P_PAE))) {
  358. if (ieee80211_is_data_qos(fc)) {
  359. u8 *qc, tid;
  360. struct ath9k_htc_sta *ista;
  361. qc = ieee80211_get_qos_ctl(hdr);
  362. tid = qc[0] & 0xf;
  363. ista = (struct ath9k_htc_sta *)sta->drv_priv;
  364. if (__ath9k_htc_check_tx_aggr(priv, ista, tid)) {
  365. ieee80211_start_tx_ba_session(sta, tid, 0);
  366. spin_lock_bh(&priv->tx.tx_lock);
  367. ista->tid_state[tid] = AGGR_PROGRESS;
  368. spin_unlock_bh(&priv->tx.tx_lock);
  369. }
  370. }
  371. }
  372. rcu_read_unlock();
  373. }
  374. static void ath9k_htc_tx_process(struct ath9k_htc_priv *priv,
  375. struct sk_buff *skb,
  376. struct __wmi_event_txstatus *txs)
  377. {
  378. struct ieee80211_vif *vif;
  379. struct ath9k_htc_tx_ctl *tx_ctl;
  380. struct ieee80211_tx_info *tx_info;
  381. struct ieee80211_tx_rate *rate;
  382. struct ieee80211_conf *cur_conf = &priv->hw->conf;
  383. bool txok;
  384. int slot;
  385. slot = strip_drv_header(priv, skb);
  386. if (slot < 0) {
  387. dev_kfree_skb_any(skb);
  388. return;
  389. }
  390. tx_ctl = HTC_SKB_CB(skb);
  391. txok = tx_ctl->txok;
  392. tx_info = IEEE80211_SKB_CB(skb);
  393. vif = tx_info->control.vif;
  394. rate = &tx_info->status.rates[0];
  395. memset(&tx_info->status, 0, sizeof(tx_info->status));
  396. /*
  397. * URB submission failed for this frame, it never reached
  398. * the target.
  399. */
  400. if (!txok || !vif || !txs)
  401. goto send_mac80211;
  402. if (txs->ts_flags & ATH9K_HTC_TXSTAT_ACK)
  403. tx_info->flags |= IEEE80211_TX_STAT_ACK;
  404. if (txs->ts_flags & ATH9K_HTC_TXSTAT_FILT)
  405. tx_info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
  406. if (txs->ts_flags & ATH9K_HTC_TXSTAT_RTC_CTS)
  407. rate->flags |= IEEE80211_TX_RC_USE_RTS_CTS;
  408. rate->count = 1;
  409. rate->idx = MS(txs->ts_rate, ATH9K_HTC_TXSTAT_RATE);
  410. if (txs->ts_flags & ATH9K_HTC_TXSTAT_MCS) {
  411. rate->flags |= IEEE80211_TX_RC_MCS;
  412. if (txs->ts_flags & ATH9K_HTC_TXSTAT_CW40)
  413. rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
  414. if (txs->ts_flags & ATH9K_HTC_TXSTAT_SGI)
  415. rate->flags |= IEEE80211_TX_RC_SHORT_GI;
  416. } else {
  417. if (cur_conf->channel->band == IEEE80211_BAND_5GHZ)
  418. rate->idx += 4; /* No CCK rates */
  419. }
  420. ath9k_htc_check_tx_aggr(priv, vif, skb);
  421. send_mac80211:
  422. spin_lock_bh(&priv->tx.tx_lock);
  423. if (WARN_ON(--priv->tx.queued_cnt < 0))
  424. priv->tx.queued_cnt = 0;
  425. spin_unlock_bh(&priv->tx.tx_lock);
  426. ath9k_htc_tx_clear_slot(priv, slot);
  427. /* Send status to mac80211 */
  428. ieee80211_tx_status(priv->hw, skb);
  429. }
  430. static inline void ath9k_htc_tx_drainq(struct ath9k_htc_priv *priv,
  431. struct sk_buff_head *queue)
  432. {
  433. struct sk_buff *skb;
  434. while ((skb = skb_dequeue(queue)) != NULL) {
  435. ath9k_htc_tx_process(priv, skb, NULL);
  436. }
  437. }
  438. void ath9k_htc_tx_drain(struct ath9k_htc_priv *priv)
  439. {
  440. struct ath9k_htc_tx_event *event, *tmp;
  441. spin_lock_bh(&priv->tx.tx_lock);
  442. priv->tx.flags |= ATH9K_HTC_OP_TX_DRAIN;
  443. spin_unlock_bh(&priv->tx.tx_lock);
  444. /*
  445. * Ensure that all pending TX frames are flushed,
  446. * and that the TX completion/failed tasklets is killed.
  447. */
  448. htc_stop(priv->htc);
  449. tasklet_kill(&priv->wmi->wmi_event_tasklet);
  450. tasklet_kill(&priv->tx_failed_tasklet);
  451. ath9k_htc_tx_drainq(priv, &priv->tx.mgmt_ep_queue);
  452. ath9k_htc_tx_drainq(priv, &priv->tx.cab_ep_queue);
  453. ath9k_htc_tx_drainq(priv, &priv->tx.data_be_queue);
  454. ath9k_htc_tx_drainq(priv, &priv->tx.data_bk_queue);
  455. ath9k_htc_tx_drainq(priv, &priv->tx.data_vi_queue);
  456. ath9k_htc_tx_drainq(priv, &priv->tx.data_vo_queue);
  457. ath9k_htc_tx_drainq(priv, &priv->tx.tx_failed);
  458. /*
  459. * The TX cleanup timer has already been killed.
  460. */
  461. spin_lock_bh(&priv->wmi->event_lock);
  462. list_for_each_entry_safe(event, tmp, &priv->wmi->pending_tx_events, list) {
  463. list_del(&event->list);
  464. kfree(event);
  465. }
  466. spin_unlock_bh(&priv->wmi->event_lock);
  467. spin_lock_bh(&priv->tx.tx_lock);
  468. priv->tx.flags &= ~ATH9K_HTC_OP_TX_DRAIN;
  469. spin_unlock_bh(&priv->tx.tx_lock);
  470. }
  471. void ath9k_tx_failed_tasklet(unsigned long data)
  472. {
  473. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
  474. spin_lock_bh(&priv->tx.tx_lock);
  475. if (priv->tx.flags & ATH9K_HTC_OP_TX_DRAIN) {
  476. spin_unlock_bh(&priv->tx.tx_lock);
  477. return;
  478. }
  479. spin_unlock_bh(&priv->tx.tx_lock);
  480. ath9k_htc_tx_drainq(priv, &priv->tx.tx_failed);
  481. }
  482. static inline bool check_cookie(struct ath9k_htc_priv *priv,
  483. struct sk_buff *skb,
  484. u8 cookie, u8 epid)
  485. {
  486. u8 fcookie = 0;
  487. if (epid == priv->mgmt_ep) {
  488. struct tx_mgmt_hdr *hdr;
  489. hdr = (struct tx_mgmt_hdr *) skb->data;
  490. fcookie = hdr->cookie;
  491. } else if ((epid == priv->data_bk_ep) ||
  492. (epid == priv->data_be_ep) ||
  493. (epid == priv->data_vi_ep) ||
  494. (epid == priv->data_vo_ep) ||
  495. (epid == priv->cab_ep)) {
  496. struct tx_frame_hdr *hdr;
  497. hdr = (struct tx_frame_hdr *) skb->data;
  498. fcookie = hdr->cookie;
  499. }
  500. if (fcookie == cookie)
  501. return true;
  502. return false;
  503. }
  504. static struct sk_buff* ath9k_htc_tx_get_packet(struct ath9k_htc_priv *priv,
  505. struct __wmi_event_txstatus *txs)
  506. {
  507. struct ath_common *common = ath9k_hw_common(priv->ah);
  508. struct sk_buff_head *epid_queue;
  509. struct sk_buff *skb, *tmp;
  510. unsigned long flags;
  511. u8 epid = MS(txs->ts_rate, ATH9K_HTC_TXSTAT_EPID);
  512. epid_queue = get_htc_epid_queue(priv, epid);
  513. if (!epid_queue)
  514. return NULL;
  515. spin_lock_irqsave(&epid_queue->lock, flags);
  516. skb_queue_walk_safe(epid_queue, skb, tmp) {
  517. if (check_cookie(priv, skb, txs->cookie, epid)) {
  518. __skb_unlink(skb, epid_queue);
  519. spin_unlock_irqrestore(&epid_queue->lock, flags);
  520. return skb;
  521. }
  522. }
  523. spin_unlock_irqrestore(&epid_queue->lock, flags);
  524. ath_dbg(common, XMIT, "No matching packet for cookie: %d, epid: %d\n",
  525. txs->cookie, epid);
  526. return NULL;
  527. }
  528. void ath9k_htc_txstatus(struct ath9k_htc_priv *priv, void *wmi_event)
  529. {
  530. struct wmi_event_txstatus *txs = (struct wmi_event_txstatus *)wmi_event;
  531. struct __wmi_event_txstatus *__txs;
  532. struct sk_buff *skb;
  533. struct ath9k_htc_tx_event *tx_pend;
  534. int i;
  535. for (i = 0; i < txs->cnt; i++) {
  536. WARN_ON(txs->cnt > HTC_MAX_TX_STATUS);
  537. __txs = &txs->txstatus[i];
  538. skb = ath9k_htc_tx_get_packet(priv, __txs);
  539. if (!skb) {
  540. /*
  541. * Store this event, so that the TX cleanup
  542. * routine can check later for the needed packet.
  543. */
  544. tx_pend = kzalloc(sizeof(struct ath9k_htc_tx_event),
  545. GFP_ATOMIC);
  546. if (!tx_pend)
  547. continue;
  548. memcpy(&tx_pend->txs, __txs,
  549. sizeof(struct __wmi_event_txstatus));
  550. spin_lock(&priv->wmi->event_lock);
  551. list_add_tail(&tx_pend->list,
  552. &priv->wmi->pending_tx_events);
  553. spin_unlock(&priv->wmi->event_lock);
  554. continue;
  555. }
  556. ath9k_htc_tx_process(priv, skb, __txs);
  557. }
  558. /* Wake TX queues if needed */
  559. ath9k_htc_check_wake_queues(priv);
  560. }
  561. void ath9k_htc_txep(void *drv_priv, struct sk_buff *skb,
  562. enum htc_endpoint_id ep_id, bool txok)
  563. {
  564. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) drv_priv;
  565. struct ath9k_htc_tx_ctl *tx_ctl;
  566. struct sk_buff_head *epid_queue;
  567. tx_ctl = HTC_SKB_CB(skb);
  568. tx_ctl->txok = txok;
  569. tx_ctl->timestamp = jiffies;
  570. if (!txok) {
  571. skb_queue_tail(&priv->tx.tx_failed, skb);
  572. tasklet_schedule(&priv->tx_failed_tasklet);
  573. return;
  574. }
  575. epid_queue = get_htc_epid_queue(priv, ep_id);
  576. if (!epid_queue) {
  577. dev_kfree_skb_any(skb);
  578. return;
  579. }
  580. skb_queue_tail(epid_queue, skb);
  581. }
  582. static inline bool check_packet(struct ath9k_htc_priv *priv, struct sk_buff *skb)
  583. {
  584. struct ath_common *common = ath9k_hw_common(priv->ah);
  585. struct ath9k_htc_tx_ctl *tx_ctl;
  586. tx_ctl = HTC_SKB_CB(skb);
  587. if (time_after(jiffies,
  588. tx_ctl->timestamp +
  589. msecs_to_jiffies(ATH9K_HTC_TX_TIMEOUT_INTERVAL))) {
  590. ath_dbg(common, XMIT, "Dropping a packet due to TX timeout\n");
  591. return true;
  592. }
  593. return false;
  594. }
  595. static void ath9k_htc_tx_cleanup_queue(struct ath9k_htc_priv *priv,
  596. struct sk_buff_head *epid_queue)
  597. {
  598. bool process = false;
  599. unsigned long flags;
  600. struct sk_buff *skb, *tmp;
  601. struct sk_buff_head queue;
  602. skb_queue_head_init(&queue);
  603. spin_lock_irqsave(&epid_queue->lock, flags);
  604. skb_queue_walk_safe(epid_queue, skb, tmp) {
  605. if (check_packet(priv, skb)) {
  606. __skb_unlink(skb, epid_queue);
  607. __skb_queue_tail(&queue, skb);
  608. process = true;
  609. }
  610. }
  611. spin_unlock_irqrestore(&epid_queue->lock, flags);
  612. if (process) {
  613. skb_queue_walk_safe(&queue, skb, tmp) {
  614. __skb_unlink(skb, &queue);
  615. ath9k_htc_tx_process(priv, skb, NULL);
  616. }
  617. }
  618. }
  619. void ath9k_htc_tx_cleanup_timer(unsigned long data)
  620. {
  621. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) data;
  622. struct ath_common *common = ath9k_hw_common(priv->ah);
  623. struct ath9k_htc_tx_event *event, *tmp;
  624. struct sk_buff *skb;
  625. spin_lock(&priv->wmi->event_lock);
  626. list_for_each_entry_safe(event, tmp, &priv->wmi->pending_tx_events, list) {
  627. skb = ath9k_htc_tx_get_packet(priv, &event->txs);
  628. if (skb) {
  629. ath_dbg(common, XMIT,
  630. "Found packet for cookie: %d, epid: %d\n",
  631. event->txs.cookie,
  632. MS(event->txs.ts_rate, ATH9K_HTC_TXSTAT_EPID));
  633. ath9k_htc_tx_process(priv, skb, &event->txs);
  634. list_del(&event->list);
  635. kfree(event);
  636. continue;
  637. }
  638. if (++event->count >= ATH9K_HTC_TX_TIMEOUT_COUNT) {
  639. list_del(&event->list);
  640. kfree(event);
  641. }
  642. }
  643. spin_unlock(&priv->wmi->event_lock);
  644. /*
  645. * Check if status-pending packets have to be cleaned up.
  646. */
  647. ath9k_htc_tx_cleanup_queue(priv, &priv->tx.mgmt_ep_queue);
  648. ath9k_htc_tx_cleanup_queue(priv, &priv->tx.cab_ep_queue);
  649. ath9k_htc_tx_cleanup_queue(priv, &priv->tx.data_be_queue);
  650. ath9k_htc_tx_cleanup_queue(priv, &priv->tx.data_bk_queue);
  651. ath9k_htc_tx_cleanup_queue(priv, &priv->tx.data_vi_queue);
  652. ath9k_htc_tx_cleanup_queue(priv, &priv->tx.data_vo_queue);
  653. /* Wake TX queues if needed */
  654. ath9k_htc_check_wake_queues(priv);
  655. mod_timer(&priv->tx.cleanup_timer,
  656. jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
  657. }
  658. int ath9k_tx_init(struct ath9k_htc_priv *priv)
  659. {
  660. skb_queue_head_init(&priv->tx.mgmt_ep_queue);
  661. skb_queue_head_init(&priv->tx.cab_ep_queue);
  662. skb_queue_head_init(&priv->tx.data_be_queue);
  663. skb_queue_head_init(&priv->tx.data_bk_queue);
  664. skb_queue_head_init(&priv->tx.data_vi_queue);
  665. skb_queue_head_init(&priv->tx.data_vo_queue);
  666. skb_queue_head_init(&priv->tx.tx_failed);
  667. return 0;
  668. }
  669. void ath9k_tx_cleanup(struct ath9k_htc_priv *priv)
  670. {
  671. }
  672. bool ath9k_htc_txq_setup(struct ath9k_htc_priv *priv, int subtype)
  673. {
  674. struct ath_hw *ah = priv->ah;
  675. struct ath_common *common = ath9k_hw_common(ah);
  676. struct ath9k_tx_queue_info qi;
  677. int qnum;
  678. memset(&qi, 0, sizeof(qi));
  679. ATH9K_HTC_INIT_TXQ(subtype);
  680. qnum = ath9k_hw_setuptxqueue(priv->ah, ATH9K_TX_QUEUE_DATA, &qi);
  681. if (qnum == -1)
  682. return false;
  683. if (qnum >= ARRAY_SIZE(priv->hwq_map)) {
  684. ath_err(common, "qnum %u out of range, max %zu!\n",
  685. qnum, ARRAY_SIZE(priv->hwq_map));
  686. ath9k_hw_releasetxqueue(ah, qnum);
  687. return false;
  688. }
  689. priv->hwq_map[subtype] = qnum;
  690. return true;
  691. }
  692. int ath9k_htc_cabq_setup(struct ath9k_htc_priv *priv)
  693. {
  694. struct ath9k_tx_queue_info qi;
  695. memset(&qi, 0, sizeof(qi));
  696. ATH9K_HTC_INIT_TXQ(0);
  697. return ath9k_hw_setuptxqueue(priv->ah, ATH9K_TX_QUEUE_CAB, &qi);
  698. }
  699. /******/
  700. /* RX */
  701. /******/
  702. /*
  703. * Calculate the RX filter to be set in the HW.
  704. */
  705. u32 ath9k_htc_calcrxfilter(struct ath9k_htc_priv *priv)
  706. {
  707. #define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
  708. struct ath_hw *ah = priv->ah;
  709. u32 rfilt;
  710. rfilt = (ath9k_hw_getrxfilter(ah) & RX_FILTER_PRESERVE)
  711. | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
  712. | ATH9K_RX_FILTER_MCAST;
  713. if (priv->rxfilter & FIF_PROBE_REQ)
  714. rfilt |= ATH9K_RX_FILTER_PROBEREQ;
  715. /*
  716. * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station
  717. * mode interface or when in monitor mode. AP mode does not need this
  718. * since it receives all in-BSS frames anyway.
  719. */
  720. if (((ah->opmode != NL80211_IFTYPE_AP) &&
  721. (priv->rxfilter & FIF_PROMISC_IN_BSS)) ||
  722. ah->is_monitoring)
  723. rfilt |= ATH9K_RX_FILTER_PROM;
  724. if (priv->rxfilter & FIF_CONTROL)
  725. rfilt |= ATH9K_RX_FILTER_CONTROL;
  726. if ((ah->opmode == NL80211_IFTYPE_STATION) &&
  727. (priv->nvifs <= 1) &&
  728. !(priv->rxfilter & FIF_BCN_PRBRESP_PROMISC))
  729. rfilt |= ATH9K_RX_FILTER_MYBEACON;
  730. else
  731. rfilt |= ATH9K_RX_FILTER_BEACON;
  732. if (conf_is_ht(&priv->hw->conf)) {
  733. rfilt |= ATH9K_RX_FILTER_COMP_BAR;
  734. rfilt |= ATH9K_RX_FILTER_UNCOMP_BA_BAR;
  735. }
  736. if (priv->rxfilter & FIF_PSPOLL)
  737. rfilt |= ATH9K_RX_FILTER_PSPOLL;
  738. if (priv->nvifs > 1)
  739. rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL;
  740. return rfilt;
  741. #undef RX_FILTER_PRESERVE
  742. }
  743. /*
  744. * Recv initialization for opmode change.
  745. */
  746. static void ath9k_htc_opmode_init(struct ath9k_htc_priv *priv)
  747. {
  748. struct ath_hw *ah = priv->ah;
  749. u32 rfilt, mfilt[2];
  750. /* configure rx filter */
  751. rfilt = ath9k_htc_calcrxfilter(priv);
  752. ath9k_hw_setrxfilter(ah, rfilt);
  753. /* calculate and install multicast filter */
  754. mfilt[0] = mfilt[1] = ~0;
  755. ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
  756. }
  757. void ath9k_host_rx_init(struct ath9k_htc_priv *priv)
  758. {
  759. ath9k_hw_rxena(priv->ah);
  760. ath9k_htc_opmode_init(priv);
  761. ath9k_hw_startpcureceive(priv->ah, test_bit(OP_SCANNING, &priv->op_flags));
  762. priv->rx.last_rssi = ATH_RSSI_DUMMY_MARKER;
  763. }
  764. static void ath9k_process_rate(struct ieee80211_hw *hw,
  765. struct ieee80211_rx_status *rxs,
  766. u8 rx_rate, u8 rs_flags)
  767. {
  768. struct ieee80211_supported_band *sband;
  769. enum ieee80211_band band;
  770. unsigned int i = 0;
  771. if (rx_rate & 0x80) {
  772. /* HT rate */
  773. rxs->flag |= RX_FLAG_HT;
  774. if (rs_flags & ATH9K_RX_2040)
  775. rxs->flag |= RX_FLAG_40MHZ;
  776. if (rs_flags & ATH9K_RX_GI)
  777. rxs->flag |= RX_FLAG_SHORT_GI;
  778. rxs->rate_idx = rx_rate & 0x7f;
  779. return;
  780. }
  781. band = hw->conf.channel->band;
  782. sband = hw->wiphy->bands[band];
  783. for (i = 0; i < sband->n_bitrates; i++) {
  784. if (sband->bitrates[i].hw_value == rx_rate) {
  785. rxs->rate_idx = i;
  786. return;
  787. }
  788. if (sband->bitrates[i].hw_value_short == rx_rate) {
  789. rxs->rate_idx = i;
  790. rxs->flag |= RX_FLAG_SHORTPRE;
  791. return;
  792. }
  793. }
  794. }
  795. static bool ath9k_rx_prepare(struct ath9k_htc_priv *priv,
  796. struct ath9k_htc_rxbuf *rxbuf,
  797. struct ieee80211_rx_status *rx_status)
  798. {
  799. struct ieee80211_hdr *hdr;
  800. struct ieee80211_hw *hw = priv->hw;
  801. struct sk_buff *skb = rxbuf->skb;
  802. struct ath_common *common = ath9k_hw_common(priv->ah);
  803. struct ath_htc_rx_status *rxstatus;
  804. int hdrlen, padpos, padsize;
  805. int last_rssi = ATH_RSSI_DUMMY_MARKER;
  806. __le16 fc;
  807. if (skb->len < HTC_RX_FRAME_HEADER_SIZE) {
  808. ath_err(common, "Corrupted RX frame, dropping (len: %d)\n",
  809. skb->len);
  810. goto rx_next;
  811. }
  812. rxstatus = (struct ath_htc_rx_status *)skb->data;
  813. if (be16_to_cpu(rxstatus->rs_datalen) -
  814. (skb->len - HTC_RX_FRAME_HEADER_SIZE) != 0) {
  815. ath_err(common,
  816. "Corrupted RX data len, dropping (dlen: %d, skblen: %d)\n",
  817. rxstatus->rs_datalen, skb->len);
  818. goto rx_next;
  819. }
  820. ath9k_htc_err_stat_rx(priv, rxstatus);
  821. /* Get the RX status information */
  822. memcpy(&rxbuf->rxstatus, rxstatus, HTC_RX_FRAME_HEADER_SIZE);
  823. skb_pull(skb, HTC_RX_FRAME_HEADER_SIZE);
  824. hdr = (struct ieee80211_hdr *)skb->data;
  825. fc = hdr->frame_control;
  826. hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  827. padpos = ath9k_cmn_padpos(fc);
  828. padsize = padpos & 3;
  829. if (padsize && skb->len >= padpos+padsize+FCS_LEN) {
  830. memmove(skb->data + padsize, skb->data, padpos);
  831. skb_pull(skb, padsize);
  832. }
  833. memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
  834. if (rxbuf->rxstatus.rs_status != 0) {
  835. if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_CRC)
  836. rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
  837. if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_PHY)
  838. goto rx_next;
  839. if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_DECRYPT) {
  840. /* FIXME */
  841. } else if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_MIC) {
  842. if (ieee80211_is_ctl(fc))
  843. /*
  844. * Sometimes, we get invalid
  845. * MIC failures on valid control frames.
  846. * Remove these mic errors.
  847. */
  848. rxbuf->rxstatus.rs_status &= ~ATH9K_RXERR_MIC;
  849. else
  850. rx_status->flag |= RX_FLAG_MMIC_ERROR;
  851. }
  852. /*
  853. * Reject error frames with the exception of
  854. * decryption and MIC failures. For monitor mode,
  855. * we also ignore the CRC error.
  856. */
  857. if (priv->ah->opmode == NL80211_IFTYPE_MONITOR) {
  858. if (rxbuf->rxstatus.rs_status &
  859. ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
  860. ATH9K_RXERR_CRC))
  861. goto rx_next;
  862. } else {
  863. if (rxbuf->rxstatus.rs_status &
  864. ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
  865. goto rx_next;
  866. }
  867. }
  868. }
  869. if (!(rxbuf->rxstatus.rs_status & ATH9K_RXERR_DECRYPT)) {
  870. u8 keyix;
  871. keyix = rxbuf->rxstatus.rs_keyix;
  872. if (keyix != ATH9K_RXKEYIX_INVALID) {
  873. rx_status->flag |= RX_FLAG_DECRYPTED;
  874. } else if (ieee80211_has_protected(fc) &&
  875. skb->len >= hdrlen + 4) {
  876. keyix = skb->data[hdrlen + 3] >> 6;
  877. if (test_bit(keyix, common->keymap))
  878. rx_status->flag |= RX_FLAG_DECRYPTED;
  879. }
  880. }
  881. ath9k_process_rate(hw, rx_status, rxbuf->rxstatus.rs_rate,
  882. rxbuf->rxstatus.rs_flags);
  883. if (rxbuf->rxstatus.rs_rssi != ATH9K_RSSI_BAD &&
  884. !rxbuf->rxstatus.rs_moreaggr)
  885. ATH_RSSI_LPF(priv->rx.last_rssi,
  886. rxbuf->rxstatus.rs_rssi);
  887. last_rssi = priv->rx.last_rssi;
  888. if (ieee80211_is_beacon(hdr->frame_control) &&
  889. !is_zero_ether_addr(common->curbssid) &&
  890. ether_addr_equal(hdr->addr3, common->curbssid)) {
  891. s8 rssi = rxbuf->rxstatus.rs_rssi;
  892. if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
  893. rssi = ATH_EP_RND(last_rssi, ATH_RSSI_EP_MULTIPLIER);
  894. if (rssi < 0)
  895. rssi = 0;
  896. priv->ah->stats.avgbrssi = rssi;
  897. }
  898. rx_status->mactime = be64_to_cpu(rxbuf->rxstatus.rs_tstamp);
  899. rx_status->band = hw->conf.channel->band;
  900. rx_status->freq = hw->conf.channel->center_freq;
  901. rx_status->signal = rxbuf->rxstatus.rs_rssi + ATH_DEFAULT_NOISE_FLOOR;
  902. rx_status->antenna = rxbuf->rxstatus.rs_antenna;
  903. rx_status->flag |= RX_FLAG_MACTIME_END;
  904. return true;
  905. rx_next:
  906. return false;
  907. }
  908. /*
  909. * FIXME: Handle FLUSH later on.
  910. */
  911. void ath9k_rx_tasklet(unsigned long data)
  912. {
  913. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
  914. struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
  915. struct ieee80211_rx_status rx_status;
  916. struct sk_buff *skb;
  917. unsigned long flags;
  918. struct ieee80211_hdr *hdr;
  919. do {
  920. spin_lock_irqsave(&priv->rx.rxbuflock, flags);
  921. list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) {
  922. if (tmp_buf->in_process) {
  923. rxbuf = tmp_buf;
  924. break;
  925. }
  926. }
  927. if (rxbuf == NULL) {
  928. spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
  929. break;
  930. }
  931. if (!rxbuf->skb)
  932. goto requeue;
  933. if (!ath9k_rx_prepare(priv, rxbuf, &rx_status)) {
  934. dev_kfree_skb_any(rxbuf->skb);
  935. goto requeue;
  936. }
  937. memcpy(IEEE80211_SKB_RXCB(rxbuf->skb), &rx_status,
  938. sizeof(struct ieee80211_rx_status));
  939. skb = rxbuf->skb;
  940. hdr = (struct ieee80211_hdr *) skb->data;
  941. if (ieee80211_is_beacon(hdr->frame_control) && priv->ps_enabled)
  942. ieee80211_queue_work(priv->hw, &priv->ps_work);
  943. spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
  944. ieee80211_rx(priv->hw, skb);
  945. spin_lock_irqsave(&priv->rx.rxbuflock, flags);
  946. requeue:
  947. rxbuf->in_process = false;
  948. rxbuf->skb = NULL;
  949. list_move_tail(&rxbuf->list, &priv->rx.rxbuf);
  950. rxbuf = NULL;
  951. spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
  952. } while (1);
  953. }
  954. void ath9k_htc_rxep(void *drv_priv, struct sk_buff *skb,
  955. enum htc_endpoint_id ep_id)
  956. {
  957. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)drv_priv;
  958. struct ath_hw *ah = priv->ah;
  959. struct ath_common *common = ath9k_hw_common(ah);
  960. struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
  961. spin_lock(&priv->rx.rxbuflock);
  962. list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) {
  963. if (!tmp_buf->in_process) {
  964. rxbuf = tmp_buf;
  965. break;
  966. }
  967. }
  968. spin_unlock(&priv->rx.rxbuflock);
  969. if (rxbuf == NULL) {
  970. ath_dbg(common, ANY, "No free RX buffer\n");
  971. goto err;
  972. }
  973. spin_lock(&priv->rx.rxbuflock);
  974. rxbuf->skb = skb;
  975. rxbuf->in_process = true;
  976. spin_unlock(&priv->rx.rxbuflock);
  977. tasklet_schedule(&priv->rx_tasklet);
  978. return;
  979. err:
  980. dev_kfree_skb_any(skb);
  981. }
  982. /* FIXME: Locking for cleanup/init */
  983. void ath9k_rx_cleanup(struct ath9k_htc_priv *priv)
  984. {
  985. struct ath9k_htc_rxbuf *rxbuf, *tbuf;
  986. list_for_each_entry_safe(rxbuf, tbuf, &priv->rx.rxbuf, list) {
  987. list_del(&rxbuf->list);
  988. if (rxbuf->skb)
  989. dev_kfree_skb_any(rxbuf->skb);
  990. kfree(rxbuf);
  991. }
  992. }
  993. int ath9k_rx_init(struct ath9k_htc_priv *priv)
  994. {
  995. int i = 0;
  996. INIT_LIST_HEAD(&priv->rx.rxbuf);
  997. spin_lock_init(&priv->rx.rxbuflock);
  998. for (i = 0; i < ATH9K_HTC_RXBUF; i++) {
  999. struct ath9k_htc_rxbuf *rxbuf =
  1000. kzalloc(sizeof(struct ath9k_htc_rxbuf), GFP_KERNEL);
  1001. if (rxbuf == NULL)
  1002. goto err;
  1003. list_add_tail(&rxbuf->list, &priv->rx.rxbuf);
  1004. }
  1005. return 0;
  1006. err:
  1007. ath9k_rx_cleanup(priv);
  1008. return -ENOMEM;
  1009. }