htc_drv_txrx.c 30 KB

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