htc_drv_txrx.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  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(priv, IEEE80211_AC_VO);
  97. epid = priv->data_vo_ep;
  98. break;
  99. case 1:
  100. TX_QSTAT_INC(priv, IEEE80211_AC_VI);
  101. epid = priv->data_vi_ep;
  102. break;
  103. case 2:
  104. TX_QSTAT_INC(priv, IEEE80211_AC_BE);
  105. epid = priv->data_be_ep;
  106. break;
  107. case 3:
  108. default:
  109. TX_QSTAT_INC(priv, 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. /* Transmit all frames that should not be reordered relative
  260. * to each other using the same priority. For other QoS data
  261. * frames extract the priority from the header.
  262. */
  263. if (!(tx_info->control.flags & IEEE80211_TX_CTRL_DONT_REORDER) &&
  264. ieee80211_is_data_qos(hdr->frame_control)) {
  265. qc = ieee80211_get_qos_ctl(hdr);
  266. tx_hdr.tidno = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
  267. }
  268. /* Check for RTS protection */
  269. if (priv->hw->wiphy->rts_threshold != (u32) -1)
  270. if (skb->len > priv->hw->wiphy->rts_threshold)
  271. flags |= ATH9K_HTC_TX_RTSCTS;
  272. /* CTS-to-self */
  273. if (!(flags & ATH9K_HTC_TX_RTSCTS) &&
  274. (vif && vif->bss_conf.use_cts_prot))
  275. flags |= ATH9K_HTC_TX_CTSONLY;
  276. tx_hdr.flags = cpu_to_be32(flags);
  277. tx_hdr.key_type = ath9k_cmn_get_hw_crypto_keytype(skb);
  278. if (tx_hdr.key_type == ATH9K_KEY_TYPE_CLEAR)
  279. tx_hdr.keyix = (u8) ATH9K_TXKEYIX_INVALID;
  280. else
  281. tx_hdr.keyix = tx_info->control.hw_key->hw_key_idx;
  282. tx_fhdr = skb_push(skb, sizeof(tx_hdr));
  283. memcpy(tx_fhdr, (u8 *) &tx_hdr, sizeof(tx_hdr));
  284. if (is_cab) {
  285. CAB_STAT_INC(priv);
  286. tx_ctl->epid = priv->cab_ep;
  287. return;
  288. }
  289. qnum = skb_get_queue_mapping(skb);
  290. tx_ctl->epid = get_htc_epid(priv, qnum);
  291. }
  292. int ath9k_htc_tx_start(struct ath9k_htc_priv *priv,
  293. struct ieee80211_sta *sta,
  294. struct sk_buff *skb,
  295. u8 slot, bool is_cab)
  296. {
  297. struct ieee80211_hdr *hdr;
  298. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  299. struct ieee80211_vif *vif = tx_info->control.vif;
  300. struct ath9k_htc_sta *ista;
  301. struct ath9k_htc_vif *avp = NULL;
  302. u8 sta_idx, vif_idx;
  303. hdr = (struct ieee80211_hdr *) skb->data;
  304. /*
  305. * Find out on which interface this packet has to be
  306. * sent out.
  307. */
  308. if (vif) {
  309. avp = (struct ath9k_htc_vif *) vif->drv_priv;
  310. vif_idx = avp->index;
  311. } else {
  312. if (!priv->ah->is_monitoring) {
  313. ath_dbg(ath9k_hw_common(priv->ah), XMIT,
  314. "VIF is null, but no monitor interface !\n");
  315. return -EINVAL;
  316. }
  317. vif_idx = priv->mon_vif_idx;
  318. }
  319. /*
  320. * Find out which station this packet is destined for.
  321. */
  322. if (sta) {
  323. ista = (struct ath9k_htc_sta *) sta->drv_priv;
  324. sta_idx = ista->index;
  325. } else {
  326. sta_idx = priv->vif_sta_pos[vif_idx];
  327. }
  328. if (ieee80211_is_data(hdr->frame_control))
  329. ath9k_htc_tx_data(priv, vif, skb,
  330. sta_idx, vif_idx, slot, is_cab);
  331. else
  332. ath9k_htc_tx_mgmt(priv, avp, skb,
  333. sta_idx, vif_idx, slot);
  334. return htc_send(priv->htc, skb);
  335. }
  336. static inline bool __ath9k_htc_check_tx_aggr(struct ath9k_htc_priv *priv,
  337. struct ath9k_htc_sta *ista, u8 tid)
  338. {
  339. bool ret = false;
  340. spin_lock_bh(&priv->tx.tx_lock);
  341. if ((tid < ATH9K_HTC_MAX_TID) && (ista->tid_state[tid] == AGGR_STOP))
  342. ret = true;
  343. spin_unlock_bh(&priv->tx.tx_lock);
  344. return ret;
  345. }
  346. static void ath9k_htc_check_tx_aggr(struct ath9k_htc_priv *priv,
  347. struct ieee80211_vif *vif,
  348. struct sk_buff *skb)
  349. {
  350. struct ieee80211_sta *sta;
  351. struct ieee80211_hdr *hdr;
  352. __le16 fc;
  353. hdr = (struct ieee80211_hdr *) skb->data;
  354. fc = hdr->frame_control;
  355. rcu_read_lock();
  356. sta = ieee80211_find_sta(vif, hdr->addr1);
  357. if (!sta) {
  358. rcu_read_unlock();
  359. return;
  360. }
  361. if (sta && conf_is_ht(&priv->hw->conf) &&
  362. !(skb->protocol == cpu_to_be16(ETH_P_PAE))) {
  363. if (ieee80211_is_data_qos(fc)) {
  364. u8 *qc, tid;
  365. struct ath9k_htc_sta *ista;
  366. qc = ieee80211_get_qos_ctl(hdr);
  367. tid = qc[0] & 0xf;
  368. ista = (struct ath9k_htc_sta *)sta->drv_priv;
  369. if (__ath9k_htc_check_tx_aggr(priv, ista, tid)) {
  370. ieee80211_start_tx_ba_session(sta, tid, 0);
  371. spin_lock_bh(&priv->tx.tx_lock);
  372. ista->tid_state[tid] = AGGR_PROGRESS;
  373. spin_unlock_bh(&priv->tx.tx_lock);
  374. }
  375. }
  376. }
  377. rcu_read_unlock();
  378. }
  379. static void ath9k_htc_tx_process(struct ath9k_htc_priv *priv,
  380. struct sk_buff *skb,
  381. struct __wmi_event_txstatus *txs)
  382. {
  383. struct ieee80211_vif *vif;
  384. struct ath9k_htc_tx_ctl *tx_ctl;
  385. struct ieee80211_tx_info *tx_info;
  386. struct ieee80211_tx_rate *rate;
  387. struct ieee80211_conf *cur_conf = &priv->hw->conf;
  388. bool txok;
  389. int slot;
  390. int hdrlen, padsize;
  391. slot = strip_drv_header(priv, skb);
  392. if (slot < 0) {
  393. dev_kfree_skb_any(skb);
  394. return;
  395. }
  396. tx_ctl = HTC_SKB_CB(skb);
  397. txok = tx_ctl->txok;
  398. tx_info = IEEE80211_SKB_CB(skb);
  399. vif = tx_info->control.vif;
  400. rate = &tx_info->status.rates[0];
  401. memset(&tx_info->status, 0, sizeof(tx_info->status));
  402. /*
  403. * URB submission failed for this frame, it never reached
  404. * the target.
  405. */
  406. if (!txok || !vif || !txs)
  407. goto send_mac80211;
  408. if (txs->ts_flags & ATH9K_HTC_TXSTAT_ACK) {
  409. tx_info->flags |= IEEE80211_TX_STAT_ACK;
  410. if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
  411. tx_info->flags |= IEEE80211_TX_STAT_AMPDU;
  412. }
  413. if (txs->ts_flags & ATH9K_HTC_TXSTAT_FILT)
  414. tx_info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
  415. if (txs->ts_flags & ATH9K_HTC_TXSTAT_RTC_CTS)
  416. rate->flags |= IEEE80211_TX_RC_USE_RTS_CTS;
  417. rate->count = 1;
  418. rate->idx = MS(txs->ts_rate, ATH9K_HTC_TXSTAT_RATE);
  419. if (txs->ts_flags & ATH9K_HTC_TXSTAT_MCS) {
  420. rate->flags |= IEEE80211_TX_RC_MCS;
  421. if (txs->ts_flags & ATH9K_HTC_TXSTAT_CW40)
  422. rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
  423. if (txs->ts_flags & ATH9K_HTC_TXSTAT_SGI)
  424. rate->flags |= IEEE80211_TX_RC_SHORT_GI;
  425. } else {
  426. if (cur_conf->chandef.chan->band == NL80211_BAND_5GHZ)
  427. rate->idx += 4; /* No CCK rates */
  428. }
  429. ath9k_htc_check_tx_aggr(priv, vif, skb);
  430. send_mac80211:
  431. spin_lock_bh(&priv->tx.tx_lock);
  432. if (WARN_ON(--priv->tx.queued_cnt < 0))
  433. priv->tx.queued_cnt = 0;
  434. spin_unlock_bh(&priv->tx.tx_lock);
  435. ath9k_htc_tx_clear_slot(priv, slot);
  436. /* Remove padding before handing frame back to mac80211 */
  437. hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  438. padsize = hdrlen & 3;
  439. if (padsize && skb->len > hdrlen + padsize) {
  440. memmove(skb->data + padsize, skb->data, hdrlen);
  441. skb_pull(skb, padsize);
  442. }
  443. /* Send status to mac80211 */
  444. ieee80211_tx_status_skb(priv->hw, skb);
  445. }
  446. static inline void ath9k_htc_tx_drainq(struct ath9k_htc_priv *priv,
  447. struct sk_buff_head *queue)
  448. {
  449. struct sk_buff *skb;
  450. while ((skb = skb_dequeue(queue)) != NULL) {
  451. ath9k_htc_tx_process(priv, skb, NULL);
  452. }
  453. }
  454. void ath9k_htc_tx_drain(struct ath9k_htc_priv *priv)
  455. {
  456. struct ath9k_htc_tx_event *event, *tmp;
  457. spin_lock_bh(&priv->tx.tx_lock);
  458. priv->tx.flags |= ATH9K_HTC_OP_TX_DRAIN;
  459. spin_unlock_bh(&priv->tx.tx_lock);
  460. /*
  461. * Ensure that all pending TX frames are flushed,
  462. * and that the TX completion/failed tasklets is killed.
  463. */
  464. htc_stop(priv->htc);
  465. tasklet_kill(&priv->wmi->wmi_event_tasklet);
  466. tasklet_kill(&priv->tx_failed_tasklet);
  467. ath9k_htc_tx_drainq(priv, &priv->tx.mgmt_ep_queue);
  468. ath9k_htc_tx_drainq(priv, &priv->tx.cab_ep_queue);
  469. ath9k_htc_tx_drainq(priv, &priv->tx.data_be_queue);
  470. ath9k_htc_tx_drainq(priv, &priv->tx.data_bk_queue);
  471. ath9k_htc_tx_drainq(priv, &priv->tx.data_vi_queue);
  472. ath9k_htc_tx_drainq(priv, &priv->tx.data_vo_queue);
  473. ath9k_htc_tx_drainq(priv, &priv->tx.tx_failed);
  474. /*
  475. * The TX cleanup timer has already been killed.
  476. */
  477. spin_lock_bh(&priv->wmi->event_lock);
  478. list_for_each_entry_safe(event, tmp, &priv->wmi->pending_tx_events, list) {
  479. list_del(&event->list);
  480. kfree(event);
  481. }
  482. spin_unlock_bh(&priv->wmi->event_lock);
  483. spin_lock_bh(&priv->tx.tx_lock);
  484. priv->tx.flags &= ~ATH9K_HTC_OP_TX_DRAIN;
  485. spin_unlock_bh(&priv->tx.tx_lock);
  486. }
  487. void ath9k_tx_failed_tasklet(struct tasklet_struct *t)
  488. {
  489. struct ath9k_htc_priv *priv = from_tasklet(priv, t, tx_failed_tasklet);
  490. spin_lock(&priv->tx.tx_lock);
  491. if (priv->tx.flags & ATH9K_HTC_OP_TX_DRAIN) {
  492. spin_unlock(&priv->tx.tx_lock);
  493. return;
  494. }
  495. spin_unlock(&priv->tx.tx_lock);
  496. ath9k_htc_tx_drainq(priv, &priv->tx.tx_failed);
  497. }
  498. static inline bool check_cookie(struct ath9k_htc_priv *priv,
  499. struct sk_buff *skb,
  500. u8 cookie, u8 epid)
  501. {
  502. u8 fcookie = 0;
  503. if (epid == priv->mgmt_ep) {
  504. struct tx_mgmt_hdr *hdr;
  505. hdr = (struct tx_mgmt_hdr *) skb->data;
  506. fcookie = hdr->cookie;
  507. } else if ((epid == priv->data_bk_ep) ||
  508. (epid == priv->data_be_ep) ||
  509. (epid == priv->data_vi_ep) ||
  510. (epid == priv->data_vo_ep) ||
  511. (epid == priv->cab_ep)) {
  512. struct tx_frame_hdr *hdr;
  513. hdr = (struct tx_frame_hdr *) skb->data;
  514. fcookie = hdr->cookie;
  515. }
  516. if (fcookie == cookie)
  517. return true;
  518. return false;
  519. }
  520. static struct sk_buff* ath9k_htc_tx_get_packet(struct ath9k_htc_priv *priv,
  521. struct __wmi_event_txstatus *txs)
  522. {
  523. struct ath_common *common = ath9k_hw_common(priv->ah);
  524. struct sk_buff_head *epid_queue;
  525. struct sk_buff *skb, *tmp;
  526. unsigned long flags;
  527. u8 epid = MS(txs->ts_rate, ATH9K_HTC_TXSTAT_EPID);
  528. epid_queue = get_htc_epid_queue(priv, epid);
  529. if (!epid_queue)
  530. return NULL;
  531. spin_lock_irqsave(&epid_queue->lock, flags);
  532. skb_queue_walk_safe(epid_queue, skb, tmp) {
  533. if (check_cookie(priv, skb, txs->cookie, epid)) {
  534. __skb_unlink(skb, epid_queue);
  535. spin_unlock_irqrestore(&epid_queue->lock, flags);
  536. return skb;
  537. }
  538. }
  539. spin_unlock_irqrestore(&epid_queue->lock, flags);
  540. ath_dbg(common, XMIT, "No matching packet for cookie: %d, epid: %d\n",
  541. txs->cookie, epid);
  542. return NULL;
  543. }
  544. void ath9k_htc_txstatus(struct ath9k_htc_priv *priv, void *wmi_event)
  545. {
  546. struct wmi_event_txstatus *txs = wmi_event;
  547. struct __wmi_event_txstatus *__txs;
  548. struct sk_buff *skb;
  549. struct ath9k_htc_tx_event *tx_pend;
  550. int i;
  551. if (WARN_ON_ONCE(txs->cnt > HTC_MAX_TX_STATUS))
  552. return;
  553. for (i = 0; i < txs->cnt; i++) {
  554. __txs = &txs->txstatus[i];
  555. skb = ath9k_htc_tx_get_packet(priv, __txs);
  556. if (!skb) {
  557. /*
  558. * Store this event, so that the TX cleanup
  559. * routine can check later for the needed packet.
  560. */
  561. tx_pend = kzalloc_obj(struct ath9k_htc_tx_event,
  562. GFP_ATOMIC);
  563. if (!tx_pend)
  564. continue;
  565. memcpy(&tx_pend->txs, __txs,
  566. sizeof(struct __wmi_event_txstatus));
  567. spin_lock(&priv->wmi->event_lock);
  568. list_add_tail(&tx_pend->list,
  569. &priv->wmi->pending_tx_events);
  570. spin_unlock(&priv->wmi->event_lock);
  571. continue;
  572. }
  573. ath9k_htc_tx_process(priv, skb, __txs);
  574. }
  575. /* Wake TX queues if needed */
  576. ath9k_htc_check_wake_queues(priv);
  577. }
  578. void ath9k_htc_txep(void *drv_priv, struct sk_buff *skb,
  579. enum htc_endpoint_id ep_id, bool txok)
  580. {
  581. struct ath9k_htc_priv *priv = drv_priv;
  582. struct ath9k_htc_tx_ctl *tx_ctl;
  583. struct sk_buff_head *epid_queue;
  584. tx_ctl = HTC_SKB_CB(skb);
  585. tx_ctl->txok = txok;
  586. tx_ctl->timestamp = jiffies;
  587. if (!txok) {
  588. skb_queue_tail(&priv->tx.tx_failed, skb);
  589. tasklet_schedule(&priv->tx_failed_tasklet);
  590. return;
  591. }
  592. epid_queue = get_htc_epid_queue(priv, ep_id);
  593. if (!epid_queue) {
  594. dev_kfree_skb_any(skb);
  595. return;
  596. }
  597. skb_queue_tail(epid_queue, skb);
  598. }
  599. static inline bool check_packet(struct ath9k_htc_priv *priv, struct sk_buff *skb)
  600. {
  601. struct ath_common *common = ath9k_hw_common(priv->ah);
  602. struct ath9k_htc_tx_ctl *tx_ctl;
  603. tx_ctl = HTC_SKB_CB(skb);
  604. if (time_after(jiffies,
  605. tx_ctl->timestamp +
  606. msecs_to_jiffies(ATH9K_HTC_TX_TIMEOUT_INTERVAL))) {
  607. ath_dbg(common, XMIT, "Dropping a packet due to TX timeout\n");
  608. return true;
  609. }
  610. return false;
  611. }
  612. static void ath9k_htc_tx_cleanup_queue(struct ath9k_htc_priv *priv,
  613. struct sk_buff_head *epid_queue)
  614. {
  615. bool process = false;
  616. unsigned long flags;
  617. struct sk_buff *skb, *tmp;
  618. struct sk_buff_head queue;
  619. skb_queue_head_init(&queue);
  620. spin_lock_irqsave(&epid_queue->lock, flags);
  621. skb_queue_walk_safe(epid_queue, skb, tmp) {
  622. if (check_packet(priv, skb)) {
  623. __skb_unlink(skb, epid_queue);
  624. __skb_queue_tail(&queue, skb);
  625. process = true;
  626. }
  627. }
  628. spin_unlock_irqrestore(&epid_queue->lock, flags);
  629. if (process) {
  630. skb_queue_walk_safe(&queue, skb, tmp) {
  631. __skb_unlink(skb, &queue);
  632. ath9k_htc_tx_process(priv, skb, NULL);
  633. }
  634. }
  635. }
  636. void ath9k_htc_tx_cleanup_timer(struct timer_list *t)
  637. {
  638. struct ath9k_htc_priv *priv = timer_container_of(priv, t,
  639. tx.cleanup_timer);
  640. struct ath_common *common = ath9k_hw_common(priv->ah);
  641. struct ath9k_htc_tx_event *event, *tmp;
  642. struct sk_buff *skb;
  643. spin_lock(&priv->wmi->event_lock);
  644. list_for_each_entry_safe(event, tmp, &priv->wmi->pending_tx_events, list) {
  645. skb = ath9k_htc_tx_get_packet(priv, &event->txs);
  646. if (skb) {
  647. ath_dbg(common, XMIT,
  648. "Found packet for cookie: %d, epid: %d\n",
  649. event->txs.cookie,
  650. MS(event->txs.ts_rate, ATH9K_HTC_TXSTAT_EPID));
  651. ath9k_htc_tx_process(priv, skb, &event->txs);
  652. list_del(&event->list);
  653. kfree(event);
  654. continue;
  655. }
  656. if (++event->count >= ATH9K_HTC_TX_TIMEOUT_COUNT) {
  657. list_del(&event->list);
  658. kfree(event);
  659. }
  660. }
  661. spin_unlock(&priv->wmi->event_lock);
  662. /*
  663. * Check if status-pending packets have to be cleaned up.
  664. */
  665. ath9k_htc_tx_cleanup_queue(priv, &priv->tx.mgmt_ep_queue);
  666. ath9k_htc_tx_cleanup_queue(priv, &priv->tx.cab_ep_queue);
  667. ath9k_htc_tx_cleanup_queue(priv, &priv->tx.data_be_queue);
  668. ath9k_htc_tx_cleanup_queue(priv, &priv->tx.data_bk_queue);
  669. ath9k_htc_tx_cleanup_queue(priv, &priv->tx.data_vi_queue);
  670. ath9k_htc_tx_cleanup_queue(priv, &priv->tx.data_vo_queue);
  671. /* Wake TX queues if needed */
  672. ath9k_htc_check_wake_queues(priv);
  673. mod_timer(&priv->tx.cleanup_timer,
  674. jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
  675. }
  676. int ath9k_tx_init(struct ath9k_htc_priv *priv)
  677. {
  678. skb_queue_head_init(&priv->tx.mgmt_ep_queue);
  679. skb_queue_head_init(&priv->tx.cab_ep_queue);
  680. skb_queue_head_init(&priv->tx.data_be_queue);
  681. skb_queue_head_init(&priv->tx.data_bk_queue);
  682. skb_queue_head_init(&priv->tx.data_vi_queue);
  683. skb_queue_head_init(&priv->tx.data_vo_queue);
  684. skb_queue_head_init(&priv->tx.tx_failed);
  685. return 0;
  686. }
  687. void ath9k_tx_cleanup(struct ath9k_htc_priv *priv)
  688. {
  689. }
  690. bool ath9k_htc_txq_setup(struct ath9k_htc_priv *priv, int subtype)
  691. {
  692. struct ath_hw *ah = priv->ah;
  693. struct ath_common *common = ath9k_hw_common(ah);
  694. struct ath9k_tx_queue_info qi;
  695. int qnum;
  696. memset(&qi, 0, sizeof(qi));
  697. ATH9K_HTC_INIT_TXQ(subtype);
  698. qnum = ath9k_hw_setuptxqueue(priv->ah, ATH9K_TX_QUEUE_DATA, &qi);
  699. if (qnum == -1)
  700. return false;
  701. if (qnum >= ARRAY_SIZE(priv->hwq_map)) {
  702. ath_err(common, "qnum %u out of range, max %zu!\n",
  703. qnum, ARRAY_SIZE(priv->hwq_map));
  704. ath9k_hw_releasetxqueue(ah, qnum);
  705. return false;
  706. }
  707. priv->hwq_map[subtype] = qnum;
  708. return true;
  709. }
  710. int ath9k_htc_cabq_setup(struct ath9k_htc_priv *priv)
  711. {
  712. struct ath9k_tx_queue_info qi;
  713. memset(&qi, 0, sizeof(qi));
  714. ATH9K_HTC_INIT_TXQ(0);
  715. return ath9k_hw_setuptxqueue(priv->ah, ATH9K_TX_QUEUE_CAB, &qi);
  716. }
  717. /******/
  718. /* RX */
  719. /******/
  720. /*
  721. * Calculate the RX filter to be set in the HW.
  722. */
  723. u32 ath9k_htc_calcrxfilter(struct ath9k_htc_priv *priv)
  724. {
  725. #define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
  726. struct ath_hw *ah = priv->ah;
  727. u32 rfilt;
  728. rfilt = (ath9k_hw_getrxfilter(ah) & RX_FILTER_PRESERVE)
  729. | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
  730. | ATH9K_RX_FILTER_MCAST;
  731. if (priv->rxfilter & FIF_PROBE_REQ)
  732. rfilt |= ATH9K_RX_FILTER_PROBEREQ;
  733. if (ah->is_monitoring)
  734. rfilt |= ATH9K_RX_FILTER_PROM;
  735. if (priv->rxfilter & FIF_CONTROL)
  736. rfilt |= ATH9K_RX_FILTER_CONTROL;
  737. if ((ah->opmode == NL80211_IFTYPE_STATION) &&
  738. (priv->nvifs <= 1) &&
  739. !(priv->rxfilter & FIF_BCN_PRBRESP_PROMISC))
  740. rfilt |= ATH9K_RX_FILTER_MYBEACON;
  741. else
  742. rfilt |= ATH9K_RX_FILTER_BEACON;
  743. if (conf_is_ht(&priv->hw->conf)) {
  744. rfilt |= ATH9K_RX_FILTER_COMP_BAR;
  745. rfilt |= ATH9K_RX_FILTER_UNCOMP_BA_BAR;
  746. }
  747. if (priv->rxfilter & FIF_PSPOLL)
  748. rfilt |= ATH9K_RX_FILTER_PSPOLL;
  749. if (priv->nvifs > 1 ||
  750. priv->rxfilter & (FIF_OTHER_BSS | FIF_MCAST_ACTION))
  751. rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL;
  752. return rfilt;
  753. #undef RX_FILTER_PRESERVE
  754. }
  755. /*
  756. * Recv initialization for opmode change.
  757. */
  758. static void ath9k_htc_opmode_init(struct ath9k_htc_priv *priv)
  759. {
  760. struct ath_hw *ah = priv->ah;
  761. u32 rfilt, mfilt[2];
  762. /* configure rx filter */
  763. rfilt = ath9k_htc_calcrxfilter(priv);
  764. ath9k_hw_setrxfilter(ah, rfilt);
  765. /* calculate and install multicast filter */
  766. mfilt[0] = mfilt[1] = ~0;
  767. ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
  768. }
  769. void ath9k_host_rx_init(struct ath9k_htc_priv *priv)
  770. {
  771. struct ath_common *common = ath9k_hw_common(priv->ah);
  772. ath9k_hw_rxena(priv->ah);
  773. ath9k_htc_opmode_init(priv);
  774. ath9k_hw_startpcureceive(priv->ah, test_bit(ATH_OP_SCANNING, &common->op_flags));
  775. }
  776. static inline void convert_htc_flag(struct ath_rx_status *rx_stats,
  777. struct ath_htc_rx_status *rxstatus)
  778. {
  779. rx_stats->enc_flags = 0;
  780. rx_stats->bw = RATE_INFO_BW_20;
  781. if (rxstatus->rs_flags & ATH9K_RX_2040)
  782. rx_stats->bw = RATE_INFO_BW_40;
  783. if (rxstatus->rs_flags & ATH9K_RX_GI)
  784. rx_stats->enc_flags |= RX_ENC_FLAG_SHORT_GI;
  785. }
  786. static void rx_status_htc_to_ath(struct ath_rx_status *rx_stats,
  787. struct ath_htc_rx_status *rxstatus)
  788. {
  789. rx_stats->rs_datalen = be16_to_cpu(rxstatus->rs_datalen);
  790. rx_stats->rs_status = rxstatus->rs_status;
  791. rx_stats->rs_phyerr = rxstatus->rs_phyerr;
  792. rx_stats->rs_rssi = rxstatus->rs_rssi;
  793. rx_stats->rs_keyix = rxstatus->rs_keyix;
  794. rx_stats->rs_rate = rxstatus->rs_rate;
  795. rx_stats->rs_antenna = rxstatus->rs_antenna;
  796. rx_stats->rs_more = rxstatus->rs_more;
  797. memcpy(rx_stats->rs_rssi_ctl, rxstatus->rs_rssi_ctl,
  798. sizeof(rx_stats->rs_rssi_ctl));
  799. memcpy(rx_stats->rs_rssi_ext, rxstatus->rs_rssi_ext,
  800. sizeof(rx_stats->rs_rssi_ext));
  801. rx_stats->rs_isaggr = rxstatus->rs_isaggr;
  802. rx_stats->rs_moreaggr = rxstatus->rs_moreaggr;
  803. rx_stats->rs_num_delims = rxstatus->rs_num_delims;
  804. convert_htc_flag(rx_stats, rxstatus);
  805. }
  806. static bool ath9k_rx_prepare(struct ath9k_htc_priv *priv,
  807. struct ath9k_htc_rxbuf *rxbuf,
  808. struct ieee80211_rx_status *rx_status)
  809. {
  810. struct ieee80211_hdr *hdr;
  811. struct ieee80211_hw *hw = priv->hw;
  812. struct sk_buff *skb = rxbuf->skb;
  813. struct ath_common *common = ath9k_hw_common(priv->ah);
  814. struct ath_hw *ah = common->ah;
  815. struct ath_htc_rx_status *rxstatus;
  816. struct ath_rx_status rx_stats;
  817. bool decrypt_error = false;
  818. u16 rs_datalen;
  819. bool is_phyerr;
  820. if (skb->len < HTC_RX_FRAME_HEADER_SIZE) {
  821. ath_err(common, "Corrupted RX frame, dropping (len: %d)\n",
  822. skb->len);
  823. goto rx_next;
  824. }
  825. rxstatus = (struct ath_htc_rx_status *)skb->data;
  826. rs_datalen = be16_to_cpu(rxstatus->rs_datalen);
  827. if (unlikely(rs_datalen -
  828. (skb->len - HTC_RX_FRAME_HEADER_SIZE) != 0)) {
  829. ath_err(common,
  830. "Corrupted RX data len, dropping (dlen: %d, skblen: %d)\n",
  831. rs_datalen, skb->len);
  832. goto rx_next;
  833. }
  834. is_phyerr = rxstatus->rs_status & ATH9K_RXERR_PHY;
  835. /*
  836. * Discard zero-length packets and packets smaller than an ACK
  837. * which are not PHY_ERROR (short radar pulses have a length of 3)
  838. */
  839. if (unlikely(!rs_datalen || (rs_datalen < 10 && !is_phyerr))) {
  840. ath_dbg(common, ANY,
  841. "Short RX data len, dropping (dlen: %d)\n",
  842. rs_datalen);
  843. goto rx_next;
  844. }
  845. if (rxstatus->rs_keyix >= ATH_KEYMAX &&
  846. rxstatus->rs_keyix != ATH9K_RXKEYIX_INVALID) {
  847. ath_dbg(common, ANY,
  848. "Invalid keyix, dropping (keyix: %d)\n",
  849. rxstatus->rs_keyix);
  850. goto rx_next;
  851. }
  852. /* Get the RX status information */
  853. memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
  854. /* Copy everything from ath_htc_rx_status (HTC_RX_FRAME_HEADER).
  855. * After this, we can drop this part of skb. */
  856. rx_status_htc_to_ath(&rx_stats, rxstatus);
  857. ath9k_htc_err_stat_rx(priv, &rx_stats);
  858. rx_status->mactime = be64_to_cpu(rxstatus->rs_tstamp);
  859. skb_pull(skb, HTC_RX_FRAME_HEADER_SIZE);
  860. /*
  861. * everything but the rate is checked here, the rate check is done
  862. * separately to avoid doing two lookups for a rate for each frame.
  863. */
  864. hdr = (struct ieee80211_hdr *)skb->data;
  865. /*
  866. * Process PHY errors and return so that the packet
  867. * can be dropped.
  868. */
  869. if (unlikely(is_phyerr)) {
  870. /* TODO: Not using DFS processing now. */
  871. if (ath_cmn_process_fft(&priv->spec_priv, hdr,
  872. &rx_stats, rx_status->mactime)) {
  873. /* TODO: Code to collect spectral scan statistics */
  874. }
  875. goto rx_next;
  876. }
  877. if (!ath9k_cmn_rx_accept(common, hdr, rx_status, &rx_stats,
  878. &decrypt_error, priv->rxfilter))
  879. goto rx_next;
  880. ath9k_cmn_rx_skb_postprocess(common, skb, &rx_stats,
  881. rx_status, decrypt_error);
  882. if (ath9k_cmn_process_rate(common, hw, &rx_stats, rx_status))
  883. goto rx_next;
  884. rx_stats.is_mybeacon = ath_is_mybeacon(common, hdr);
  885. ath9k_cmn_process_rssi(common, hw, &rx_stats, rx_status);
  886. rx_status->band = ah->curchan->chan->band;
  887. rx_status->freq = ah->curchan->chan->center_freq;
  888. rx_status->antenna = rx_stats.rs_antenna;
  889. rx_status->flag |= RX_FLAG_MACTIME_END;
  890. return true;
  891. rx_next:
  892. return false;
  893. }
  894. /*
  895. * FIXME: Handle FLUSH later on.
  896. */
  897. void ath9k_rx_tasklet(struct tasklet_struct *t)
  898. {
  899. struct ath9k_htc_priv *priv = from_tasklet(priv, t, rx_tasklet);
  900. struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
  901. struct ieee80211_rx_status rx_status;
  902. struct sk_buff *skb;
  903. unsigned long flags;
  904. struct ieee80211_hdr *hdr;
  905. do {
  906. spin_lock_irqsave(&priv->rx.rxbuflock, flags);
  907. list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) {
  908. if (tmp_buf->in_process) {
  909. rxbuf = tmp_buf;
  910. break;
  911. }
  912. }
  913. if (rxbuf == NULL) {
  914. spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
  915. break;
  916. }
  917. if (!rxbuf->skb)
  918. goto requeue;
  919. if (!ath9k_rx_prepare(priv, rxbuf, &rx_status)) {
  920. dev_kfree_skb_any(rxbuf->skb);
  921. goto requeue;
  922. }
  923. memcpy(IEEE80211_SKB_RXCB(rxbuf->skb), &rx_status,
  924. sizeof(struct ieee80211_rx_status));
  925. skb = rxbuf->skb;
  926. hdr = (struct ieee80211_hdr *) skb->data;
  927. if (ieee80211_is_beacon(hdr->frame_control) && priv->ps_enabled)
  928. ieee80211_queue_work(priv->hw, &priv->ps_work);
  929. spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
  930. ieee80211_rx(priv->hw, skb);
  931. spin_lock_irqsave(&priv->rx.rxbuflock, flags);
  932. requeue:
  933. rxbuf->in_process = false;
  934. rxbuf->skb = NULL;
  935. list_move_tail(&rxbuf->list, &priv->rx.rxbuf);
  936. rxbuf = NULL;
  937. spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
  938. } while (1);
  939. }
  940. void ath9k_htc_rxep(void *drv_priv, struct sk_buff *skb,
  941. enum htc_endpoint_id ep_id)
  942. {
  943. struct ath9k_htc_priv *priv = drv_priv;
  944. struct ath_hw *ah = priv->ah;
  945. struct ath_common *common = ath9k_hw_common(ah);
  946. struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
  947. unsigned long flags;
  948. /* Check if ath9k_rx_init() completed. */
  949. if (!data_race(priv->rx.initialized))
  950. goto err;
  951. spin_lock_irqsave(&priv->rx.rxbuflock, flags);
  952. list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) {
  953. if (!tmp_buf->in_process) {
  954. rxbuf = tmp_buf;
  955. break;
  956. }
  957. }
  958. spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
  959. if (rxbuf == NULL) {
  960. ath_dbg(common, ANY, "No free RX buffer\n");
  961. goto err;
  962. }
  963. spin_lock_irqsave(&priv->rx.rxbuflock, flags);
  964. rxbuf->skb = skb;
  965. rxbuf->in_process = true;
  966. spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
  967. tasklet_schedule(&priv->rx_tasklet);
  968. return;
  969. err:
  970. dev_kfree_skb_any(skb);
  971. }
  972. /* FIXME: Locking for cleanup/init */
  973. void ath9k_rx_cleanup(struct ath9k_htc_priv *priv)
  974. {
  975. struct ath9k_htc_rxbuf *rxbuf, *tbuf;
  976. list_for_each_entry_safe(rxbuf, tbuf, &priv->rx.rxbuf, list) {
  977. list_del(&rxbuf->list);
  978. if (rxbuf->skb)
  979. dev_kfree_skb_any(rxbuf->skb);
  980. kfree(rxbuf);
  981. }
  982. }
  983. int ath9k_rx_init(struct ath9k_htc_priv *priv)
  984. {
  985. int i = 0;
  986. INIT_LIST_HEAD(&priv->rx.rxbuf);
  987. spin_lock_init(&priv->rx.rxbuflock);
  988. for (i = 0; i < ATH9K_HTC_RXBUF; i++) {
  989. struct ath9k_htc_rxbuf *rxbuf =
  990. kzalloc_obj(struct ath9k_htc_rxbuf);
  991. if (rxbuf == NULL)
  992. goto err;
  993. list_add_tail(&rxbuf->list, &priv->rx.rxbuf);
  994. }
  995. /* Allow ath9k_htc_rxep() to operate. */
  996. smp_wmb();
  997. priv->rx.initialized = true;
  998. return 0;
  999. err:
  1000. ath9k_rx_cleanup(priv);
  1001. return -ENOMEM;
  1002. }