htc_drv_txrx.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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. int ath_htc_txq_update(struct ath9k_htc_priv *priv, int qnum,
  51. struct ath9k_tx_queue_info *qinfo)
  52. {
  53. struct ath_hw *ah = priv->ah;
  54. int error = 0;
  55. struct ath9k_tx_queue_info qi;
  56. ath9k_hw_get_txq_props(ah, qnum, &qi);
  57. qi.tqi_aifs = qinfo->tqi_aifs;
  58. qi.tqi_cwmin = qinfo->tqi_cwmin / 2; /* XXX */
  59. qi.tqi_cwmax = qinfo->tqi_cwmax;
  60. qi.tqi_burstTime = qinfo->tqi_burstTime;
  61. qi.tqi_readyTime = qinfo->tqi_readyTime;
  62. if (!ath9k_hw_set_txq_props(ah, qnum, &qi)) {
  63. ath_err(ath9k_hw_common(ah),
  64. "Unable to update hardware queue %u!\n", qnum);
  65. error = -EIO;
  66. } else {
  67. ath9k_hw_resettxqueue(ah, qnum);
  68. }
  69. return error;
  70. }
  71. int ath9k_htc_tx_start(struct ath9k_htc_priv *priv, struct sk_buff *skb)
  72. {
  73. struct ieee80211_hdr *hdr;
  74. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  75. struct ieee80211_sta *sta = tx_info->control.sta;
  76. struct ieee80211_vif *vif = tx_info->control.vif;
  77. struct ath9k_htc_sta *ista;
  78. struct ath9k_htc_vif *avp;
  79. struct ath9k_htc_tx_ctl tx_ctl;
  80. enum htc_endpoint_id epid;
  81. u16 qnum;
  82. __le16 fc;
  83. u8 *tx_fhdr;
  84. u8 sta_idx, vif_idx;
  85. hdr = (struct ieee80211_hdr *) skb->data;
  86. fc = hdr->frame_control;
  87. /*
  88. * Find out on which interface this packet has to be
  89. * sent out.
  90. */
  91. if (vif) {
  92. avp = (struct ath9k_htc_vif *) vif->drv_priv;
  93. vif_idx = avp->index;
  94. } else {
  95. if (!priv->ah->is_monitoring) {
  96. ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
  97. "VIF is null, but no monitor interface !\n");
  98. return -EINVAL;
  99. }
  100. vif_idx = priv->mon_vif_idx;
  101. }
  102. /*
  103. * Find out which station this packet is destined for.
  104. */
  105. if (sta) {
  106. ista = (struct ath9k_htc_sta *) sta->drv_priv;
  107. sta_idx = ista->index;
  108. } else {
  109. sta_idx = priv->vif_sta_pos[vif_idx];
  110. }
  111. memset(&tx_ctl, 0, sizeof(struct ath9k_htc_tx_ctl));
  112. if (ieee80211_is_data(fc)) {
  113. struct tx_frame_hdr tx_hdr;
  114. u32 flags = 0;
  115. u8 *qc;
  116. memset(&tx_hdr, 0, sizeof(struct tx_frame_hdr));
  117. tx_hdr.node_idx = sta_idx;
  118. tx_hdr.vif_idx = vif_idx;
  119. if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
  120. tx_ctl.type = ATH9K_HTC_AMPDU;
  121. tx_hdr.data_type = ATH9K_HTC_AMPDU;
  122. } else {
  123. tx_ctl.type = ATH9K_HTC_NORMAL;
  124. tx_hdr.data_type = ATH9K_HTC_NORMAL;
  125. }
  126. if (ieee80211_is_data_qos(fc)) {
  127. qc = ieee80211_get_qos_ctl(hdr);
  128. tx_hdr.tidno = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
  129. }
  130. /* Check for RTS protection */
  131. if (priv->hw->wiphy->rts_threshold != (u32) -1)
  132. if (skb->len > priv->hw->wiphy->rts_threshold)
  133. flags |= ATH9K_HTC_TX_RTSCTS;
  134. /* CTS-to-self */
  135. if (!(flags & ATH9K_HTC_TX_RTSCTS) &&
  136. (vif && vif->bss_conf.use_cts_prot))
  137. flags |= ATH9K_HTC_TX_CTSONLY;
  138. tx_hdr.flags = cpu_to_be32(flags);
  139. tx_hdr.key_type = ath9k_cmn_get_hw_crypto_keytype(skb);
  140. if (tx_hdr.key_type == ATH9K_KEY_TYPE_CLEAR)
  141. tx_hdr.keyix = (u8) ATH9K_TXKEYIX_INVALID;
  142. else
  143. tx_hdr.keyix = tx_info->control.hw_key->hw_key_idx;
  144. tx_fhdr = skb_push(skb, sizeof(tx_hdr));
  145. memcpy(tx_fhdr, (u8 *) &tx_hdr, sizeof(tx_hdr));
  146. qnum = skb_get_queue_mapping(skb);
  147. switch (qnum) {
  148. case 0:
  149. TX_QSTAT_INC(WME_AC_VO);
  150. epid = priv->data_vo_ep;
  151. break;
  152. case 1:
  153. TX_QSTAT_INC(WME_AC_VI);
  154. epid = priv->data_vi_ep;
  155. break;
  156. case 2:
  157. TX_QSTAT_INC(WME_AC_BE);
  158. epid = priv->data_be_ep;
  159. break;
  160. case 3:
  161. default:
  162. TX_QSTAT_INC(WME_AC_BK);
  163. epid = priv->data_bk_ep;
  164. break;
  165. }
  166. } else {
  167. struct tx_mgmt_hdr mgmt_hdr;
  168. memset(&mgmt_hdr, 0, sizeof(struct tx_mgmt_hdr));
  169. tx_ctl.type = ATH9K_HTC_NORMAL;
  170. mgmt_hdr.node_idx = sta_idx;
  171. mgmt_hdr.vif_idx = vif_idx;
  172. mgmt_hdr.tidno = 0;
  173. mgmt_hdr.flags = 0;
  174. mgmt_hdr.key_type = ath9k_cmn_get_hw_crypto_keytype(skb);
  175. if (mgmt_hdr.key_type == ATH9K_KEY_TYPE_CLEAR)
  176. mgmt_hdr.keyix = (u8) ATH9K_TXKEYIX_INVALID;
  177. else
  178. mgmt_hdr.keyix = tx_info->control.hw_key->hw_key_idx;
  179. tx_fhdr = skb_push(skb, sizeof(mgmt_hdr));
  180. memcpy(tx_fhdr, (u8 *) &mgmt_hdr, sizeof(mgmt_hdr));
  181. epid = priv->mgmt_ep;
  182. }
  183. return htc_send(priv->htc, skb, epid, &tx_ctl);
  184. }
  185. static bool ath9k_htc_check_tx_aggr(struct ath9k_htc_priv *priv,
  186. struct ath9k_htc_sta *ista, u8 tid)
  187. {
  188. bool ret = false;
  189. spin_lock_bh(&priv->tx_lock);
  190. if ((tid < ATH9K_HTC_MAX_TID) && (ista->tid_state[tid] == AGGR_STOP))
  191. ret = true;
  192. spin_unlock_bh(&priv->tx_lock);
  193. return ret;
  194. }
  195. void ath9k_tx_tasklet(unsigned long data)
  196. {
  197. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
  198. struct ieee80211_vif *vif;
  199. struct ieee80211_sta *sta;
  200. struct ieee80211_hdr *hdr;
  201. struct ieee80211_tx_info *tx_info;
  202. struct sk_buff *skb = NULL;
  203. __le16 fc;
  204. while ((skb = skb_dequeue(&priv->tx_queue)) != NULL) {
  205. hdr = (struct ieee80211_hdr *) skb->data;
  206. fc = hdr->frame_control;
  207. tx_info = IEEE80211_SKB_CB(skb);
  208. vif = tx_info->control.vif;
  209. memset(&tx_info->status, 0, sizeof(tx_info->status));
  210. if (!vif)
  211. goto send_mac80211;
  212. rcu_read_lock();
  213. sta = ieee80211_find_sta(vif, hdr->addr1);
  214. if (!sta) {
  215. rcu_read_unlock();
  216. ieee80211_tx_status(priv->hw, skb);
  217. continue;
  218. }
  219. /* Check if we need to start aggregation */
  220. if (sta && conf_is_ht(&priv->hw->conf) &&
  221. !(skb->protocol == cpu_to_be16(ETH_P_PAE))) {
  222. if (ieee80211_is_data_qos(fc)) {
  223. u8 *qc, tid;
  224. struct ath9k_htc_sta *ista;
  225. qc = ieee80211_get_qos_ctl(hdr);
  226. tid = qc[0] & 0xf;
  227. ista = (struct ath9k_htc_sta *)sta->drv_priv;
  228. if (ath9k_htc_check_tx_aggr(priv, ista, tid)) {
  229. ieee80211_start_tx_ba_session(sta, tid, 0);
  230. spin_lock_bh(&priv->tx_lock);
  231. ista->tid_state[tid] = AGGR_PROGRESS;
  232. spin_unlock_bh(&priv->tx_lock);
  233. }
  234. }
  235. }
  236. rcu_read_unlock();
  237. send_mac80211:
  238. /* Send status to mac80211 */
  239. ieee80211_tx_status(priv->hw, skb);
  240. }
  241. /* Wake TX queues if needed */
  242. spin_lock_bh(&priv->tx_lock);
  243. if (priv->tx_queues_stop) {
  244. priv->tx_queues_stop = false;
  245. spin_unlock_bh(&priv->tx_lock);
  246. ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
  247. "Waking up TX queues\n");
  248. ieee80211_wake_queues(priv->hw);
  249. return;
  250. }
  251. spin_unlock_bh(&priv->tx_lock);
  252. }
  253. void ath9k_htc_txep(void *drv_priv, struct sk_buff *skb,
  254. enum htc_endpoint_id ep_id, bool txok)
  255. {
  256. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) drv_priv;
  257. struct ath_common *common = ath9k_hw_common(priv->ah);
  258. struct ieee80211_tx_info *tx_info;
  259. if (!skb)
  260. return;
  261. if (ep_id == priv->mgmt_ep) {
  262. skb_pull(skb, sizeof(struct tx_mgmt_hdr));
  263. } else if ((ep_id == priv->data_bk_ep) ||
  264. (ep_id == priv->data_be_ep) ||
  265. (ep_id == priv->data_vi_ep) ||
  266. (ep_id == priv->data_vo_ep)) {
  267. skb_pull(skb, sizeof(struct tx_frame_hdr));
  268. } else {
  269. ath_err(common, "Unsupported TX EPID: %d\n", ep_id);
  270. dev_kfree_skb_any(skb);
  271. return;
  272. }
  273. tx_info = IEEE80211_SKB_CB(skb);
  274. if (txok)
  275. tx_info->flags |= IEEE80211_TX_STAT_ACK;
  276. skb_queue_tail(&priv->tx_queue, skb);
  277. tasklet_schedule(&priv->tx_tasklet);
  278. }
  279. int ath9k_tx_init(struct ath9k_htc_priv *priv)
  280. {
  281. skb_queue_head_init(&priv->tx_queue);
  282. return 0;
  283. }
  284. void ath9k_tx_cleanup(struct ath9k_htc_priv *priv)
  285. {
  286. }
  287. bool ath9k_htc_txq_setup(struct ath9k_htc_priv *priv, int subtype)
  288. {
  289. struct ath_hw *ah = priv->ah;
  290. struct ath_common *common = ath9k_hw_common(ah);
  291. struct ath9k_tx_queue_info qi;
  292. int qnum;
  293. memset(&qi, 0, sizeof(qi));
  294. ATH9K_HTC_INIT_TXQ(subtype);
  295. qnum = ath9k_hw_setuptxqueue(priv->ah, ATH9K_TX_QUEUE_DATA, &qi);
  296. if (qnum == -1)
  297. return false;
  298. if (qnum >= ARRAY_SIZE(priv->hwq_map)) {
  299. ath_err(common, "qnum %u out of range, max %zu!\n",
  300. qnum, ARRAY_SIZE(priv->hwq_map));
  301. ath9k_hw_releasetxqueue(ah, qnum);
  302. return false;
  303. }
  304. priv->hwq_map[subtype] = qnum;
  305. return true;
  306. }
  307. int ath9k_htc_cabq_setup(struct ath9k_htc_priv *priv)
  308. {
  309. struct ath9k_tx_queue_info qi;
  310. memset(&qi, 0, sizeof(qi));
  311. ATH9K_HTC_INIT_TXQ(0);
  312. return ath9k_hw_setuptxqueue(priv->ah, ATH9K_TX_QUEUE_CAB, &qi);
  313. }
  314. /******/
  315. /* RX */
  316. /******/
  317. /*
  318. * Calculate the RX filter to be set in the HW.
  319. */
  320. u32 ath9k_htc_calcrxfilter(struct ath9k_htc_priv *priv)
  321. {
  322. #define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
  323. struct ath_hw *ah = priv->ah;
  324. u32 rfilt;
  325. rfilt = (ath9k_hw_getrxfilter(ah) & RX_FILTER_PRESERVE)
  326. | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
  327. | ATH9K_RX_FILTER_MCAST;
  328. if (priv->rxfilter & FIF_PROBE_REQ)
  329. rfilt |= ATH9K_RX_FILTER_PROBEREQ;
  330. /*
  331. * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station
  332. * mode interface or when in monitor mode. AP mode does not need this
  333. * since it receives all in-BSS frames anyway.
  334. */
  335. if (((ah->opmode != NL80211_IFTYPE_AP) &&
  336. (priv->rxfilter & FIF_PROMISC_IN_BSS)) ||
  337. ah->is_monitoring)
  338. rfilt |= ATH9K_RX_FILTER_PROM;
  339. if (priv->rxfilter & FIF_CONTROL)
  340. rfilt |= ATH9K_RX_FILTER_CONTROL;
  341. if ((ah->opmode == NL80211_IFTYPE_STATION) &&
  342. !(priv->rxfilter & FIF_BCN_PRBRESP_PROMISC))
  343. rfilt |= ATH9K_RX_FILTER_MYBEACON;
  344. else
  345. rfilt |= ATH9K_RX_FILTER_BEACON;
  346. if (conf_is_ht(&priv->hw->conf)) {
  347. rfilt |= ATH9K_RX_FILTER_COMP_BAR;
  348. rfilt |= ATH9K_RX_FILTER_UNCOMP_BA_BAR;
  349. }
  350. if (priv->rxfilter & FIF_PSPOLL)
  351. rfilt |= ATH9K_RX_FILTER_PSPOLL;
  352. return rfilt;
  353. #undef RX_FILTER_PRESERVE
  354. }
  355. /*
  356. * Recv initialization for opmode change.
  357. */
  358. static void ath9k_htc_opmode_init(struct ath9k_htc_priv *priv)
  359. {
  360. struct ath_hw *ah = priv->ah;
  361. u32 rfilt, mfilt[2];
  362. /* configure rx filter */
  363. rfilt = ath9k_htc_calcrxfilter(priv);
  364. ath9k_hw_setrxfilter(ah, rfilt);
  365. /* calculate and install multicast filter */
  366. mfilt[0] = mfilt[1] = ~0;
  367. ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
  368. }
  369. void ath9k_host_rx_init(struct ath9k_htc_priv *priv)
  370. {
  371. ath9k_hw_rxena(priv->ah);
  372. ath9k_htc_opmode_init(priv);
  373. ath9k_hw_startpcureceive(priv->ah, (priv->op_flags & OP_SCANNING));
  374. priv->rx.last_rssi = ATH_RSSI_DUMMY_MARKER;
  375. }
  376. static void ath9k_process_rate(struct ieee80211_hw *hw,
  377. struct ieee80211_rx_status *rxs,
  378. u8 rx_rate, u8 rs_flags)
  379. {
  380. struct ieee80211_supported_band *sband;
  381. enum ieee80211_band band;
  382. unsigned int i = 0;
  383. if (rx_rate & 0x80) {
  384. /* HT rate */
  385. rxs->flag |= RX_FLAG_HT;
  386. if (rs_flags & ATH9K_RX_2040)
  387. rxs->flag |= RX_FLAG_40MHZ;
  388. if (rs_flags & ATH9K_RX_GI)
  389. rxs->flag |= RX_FLAG_SHORT_GI;
  390. rxs->rate_idx = rx_rate & 0x7f;
  391. return;
  392. }
  393. band = hw->conf.channel->band;
  394. sband = hw->wiphy->bands[band];
  395. for (i = 0; i < sband->n_bitrates; i++) {
  396. if (sband->bitrates[i].hw_value == rx_rate) {
  397. rxs->rate_idx = i;
  398. return;
  399. }
  400. if (sband->bitrates[i].hw_value_short == rx_rate) {
  401. rxs->rate_idx = i;
  402. rxs->flag |= RX_FLAG_SHORTPRE;
  403. return;
  404. }
  405. }
  406. }
  407. static bool ath9k_rx_prepare(struct ath9k_htc_priv *priv,
  408. struct ath9k_htc_rxbuf *rxbuf,
  409. struct ieee80211_rx_status *rx_status)
  410. {
  411. struct ieee80211_hdr *hdr;
  412. struct ieee80211_hw *hw = priv->hw;
  413. struct sk_buff *skb = rxbuf->skb;
  414. struct ath_common *common = ath9k_hw_common(priv->ah);
  415. struct ath_htc_rx_status *rxstatus;
  416. int hdrlen, padpos, padsize;
  417. int last_rssi = ATH_RSSI_DUMMY_MARKER;
  418. __le16 fc;
  419. if (skb->len <= HTC_RX_FRAME_HEADER_SIZE) {
  420. ath_err(common, "Corrupted RX frame, dropping\n");
  421. goto rx_next;
  422. }
  423. rxstatus = (struct ath_htc_rx_status *)skb->data;
  424. if (be16_to_cpu(rxstatus->rs_datalen) -
  425. (skb->len - HTC_RX_FRAME_HEADER_SIZE) != 0) {
  426. ath_err(common,
  427. "Corrupted RX data len, dropping (dlen: %d, skblen: %d)\n",
  428. rxstatus->rs_datalen, skb->len);
  429. goto rx_next;
  430. }
  431. /* Get the RX status information */
  432. memcpy(&rxbuf->rxstatus, rxstatus, HTC_RX_FRAME_HEADER_SIZE);
  433. skb_pull(skb, HTC_RX_FRAME_HEADER_SIZE);
  434. hdr = (struct ieee80211_hdr *)skb->data;
  435. fc = hdr->frame_control;
  436. hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  437. padpos = ath9k_cmn_padpos(fc);
  438. padsize = padpos & 3;
  439. if (padsize && skb->len >= padpos+padsize+FCS_LEN) {
  440. memmove(skb->data + padsize, skb->data, padpos);
  441. skb_pull(skb, padsize);
  442. }
  443. memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
  444. if (rxbuf->rxstatus.rs_status != 0) {
  445. if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_CRC)
  446. rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
  447. if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_PHY)
  448. goto rx_next;
  449. if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_DECRYPT) {
  450. /* FIXME */
  451. } else if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_MIC) {
  452. if (ieee80211_is_ctl(fc))
  453. /*
  454. * Sometimes, we get invalid
  455. * MIC failures on valid control frames.
  456. * Remove these mic errors.
  457. */
  458. rxbuf->rxstatus.rs_status &= ~ATH9K_RXERR_MIC;
  459. else
  460. rx_status->flag |= RX_FLAG_MMIC_ERROR;
  461. }
  462. /*
  463. * Reject error frames with the exception of
  464. * decryption and MIC failures. For monitor mode,
  465. * we also ignore the CRC error.
  466. */
  467. if (priv->ah->opmode == NL80211_IFTYPE_MONITOR) {
  468. if (rxbuf->rxstatus.rs_status &
  469. ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
  470. ATH9K_RXERR_CRC))
  471. goto rx_next;
  472. } else {
  473. if (rxbuf->rxstatus.rs_status &
  474. ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
  475. goto rx_next;
  476. }
  477. }
  478. }
  479. if (!(rxbuf->rxstatus.rs_status & ATH9K_RXERR_DECRYPT)) {
  480. u8 keyix;
  481. keyix = rxbuf->rxstatus.rs_keyix;
  482. if (keyix != ATH9K_RXKEYIX_INVALID) {
  483. rx_status->flag |= RX_FLAG_DECRYPTED;
  484. } else if (ieee80211_has_protected(fc) &&
  485. skb->len >= hdrlen + 4) {
  486. keyix = skb->data[hdrlen + 3] >> 6;
  487. if (test_bit(keyix, common->keymap))
  488. rx_status->flag |= RX_FLAG_DECRYPTED;
  489. }
  490. }
  491. ath9k_process_rate(hw, rx_status, rxbuf->rxstatus.rs_rate,
  492. rxbuf->rxstatus.rs_flags);
  493. if (rxbuf->rxstatus.rs_rssi != ATH9K_RSSI_BAD &&
  494. !rxbuf->rxstatus.rs_moreaggr)
  495. ATH_RSSI_LPF(priv->rx.last_rssi,
  496. rxbuf->rxstatus.rs_rssi);
  497. last_rssi = priv->rx.last_rssi;
  498. if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
  499. rxbuf->rxstatus.rs_rssi = ATH_EP_RND(last_rssi,
  500. ATH_RSSI_EP_MULTIPLIER);
  501. if (rxbuf->rxstatus.rs_rssi < 0)
  502. rxbuf->rxstatus.rs_rssi = 0;
  503. if (ieee80211_is_beacon(fc))
  504. priv->ah->stats.avgbrssi = rxbuf->rxstatus.rs_rssi;
  505. rx_status->mactime = be64_to_cpu(rxbuf->rxstatus.rs_tstamp);
  506. rx_status->band = hw->conf.channel->band;
  507. rx_status->freq = hw->conf.channel->center_freq;
  508. rx_status->signal = rxbuf->rxstatus.rs_rssi + ATH_DEFAULT_NOISE_FLOOR;
  509. rx_status->antenna = rxbuf->rxstatus.rs_antenna;
  510. rx_status->flag |= RX_FLAG_MACTIME_MPDU;
  511. return true;
  512. rx_next:
  513. return false;
  514. }
  515. /*
  516. * FIXME: Handle FLUSH later on.
  517. */
  518. void ath9k_rx_tasklet(unsigned long data)
  519. {
  520. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
  521. struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
  522. struct ieee80211_rx_status rx_status;
  523. struct sk_buff *skb;
  524. unsigned long flags;
  525. struct ieee80211_hdr *hdr;
  526. do {
  527. spin_lock_irqsave(&priv->rx.rxbuflock, flags);
  528. list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) {
  529. if (tmp_buf->in_process) {
  530. rxbuf = tmp_buf;
  531. break;
  532. }
  533. }
  534. if (rxbuf == NULL) {
  535. spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
  536. break;
  537. }
  538. if (!rxbuf->skb)
  539. goto requeue;
  540. if (!ath9k_rx_prepare(priv, rxbuf, &rx_status)) {
  541. dev_kfree_skb_any(rxbuf->skb);
  542. goto requeue;
  543. }
  544. memcpy(IEEE80211_SKB_RXCB(rxbuf->skb), &rx_status,
  545. sizeof(struct ieee80211_rx_status));
  546. skb = rxbuf->skb;
  547. hdr = (struct ieee80211_hdr *) skb->data;
  548. if (ieee80211_is_beacon(hdr->frame_control) && priv->ps_enabled)
  549. ieee80211_queue_work(priv->hw, &priv->ps_work);
  550. spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
  551. ieee80211_rx(priv->hw, skb);
  552. spin_lock_irqsave(&priv->rx.rxbuflock, flags);
  553. requeue:
  554. rxbuf->in_process = false;
  555. rxbuf->skb = NULL;
  556. list_move_tail(&rxbuf->list, &priv->rx.rxbuf);
  557. rxbuf = NULL;
  558. spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
  559. } while (1);
  560. }
  561. void ath9k_htc_rxep(void *drv_priv, struct sk_buff *skb,
  562. enum htc_endpoint_id ep_id)
  563. {
  564. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)drv_priv;
  565. struct ath_hw *ah = priv->ah;
  566. struct ath_common *common = ath9k_hw_common(ah);
  567. struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
  568. spin_lock(&priv->rx.rxbuflock);
  569. list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) {
  570. if (!tmp_buf->in_process) {
  571. rxbuf = tmp_buf;
  572. break;
  573. }
  574. }
  575. spin_unlock(&priv->rx.rxbuflock);
  576. if (rxbuf == NULL) {
  577. ath_dbg(common, ATH_DBG_ANY,
  578. "No free RX buffer\n");
  579. goto err;
  580. }
  581. spin_lock(&priv->rx.rxbuflock);
  582. rxbuf->skb = skb;
  583. rxbuf->in_process = true;
  584. spin_unlock(&priv->rx.rxbuflock);
  585. tasklet_schedule(&priv->rx_tasklet);
  586. return;
  587. err:
  588. dev_kfree_skb_any(skb);
  589. }
  590. /* FIXME: Locking for cleanup/init */
  591. void ath9k_rx_cleanup(struct ath9k_htc_priv *priv)
  592. {
  593. struct ath9k_htc_rxbuf *rxbuf, *tbuf;
  594. list_for_each_entry_safe(rxbuf, tbuf, &priv->rx.rxbuf, list) {
  595. list_del(&rxbuf->list);
  596. if (rxbuf->skb)
  597. dev_kfree_skb_any(rxbuf->skb);
  598. kfree(rxbuf);
  599. }
  600. }
  601. int ath9k_rx_init(struct ath9k_htc_priv *priv)
  602. {
  603. struct ath_hw *ah = priv->ah;
  604. struct ath_common *common = ath9k_hw_common(ah);
  605. struct ath9k_htc_rxbuf *rxbuf;
  606. int i = 0;
  607. INIT_LIST_HEAD(&priv->rx.rxbuf);
  608. spin_lock_init(&priv->rx.rxbuflock);
  609. for (i = 0; i < ATH9K_HTC_RXBUF; i++) {
  610. rxbuf = kzalloc(sizeof(struct ath9k_htc_rxbuf), GFP_KERNEL);
  611. if (rxbuf == NULL) {
  612. ath_err(common, "Unable to allocate RX buffers\n");
  613. goto err;
  614. }
  615. list_add_tail(&rxbuf->list, &priv->rx.rxbuf);
  616. }
  617. return 0;
  618. err:
  619. ath9k_rx_cleanup(priv);
  620. return -ENOMEM;
  621. }