htc_drv_txrx.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  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. (priv->op_flags & OP_PROTECT_ENABLE))
  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_sta *sta;
  199. struct ieee80211_hdr *hdr;
  200. struct ieee80211_tx_info *tx_info;
  201. struct sk_buff *skb = NULL;
  202. __le16 fc;
  203. while ((skb = skb_dequeue(&priv->tx_queue)) != NULL) {
  204. hdr = (struct ieee80211_hdr *) skb->data;
  205. fc = hdr->frame_control;
  206. tx_info = IEEE80211_SKB_CB(skb);
  207. memset(&tx_info->status, 0, sizeof(tx_info->status));
  208. rcu_read_lock();
  209. sta = ieee80211_find_sta(priv->vif, hdr->addr1);
  210. if (!sta) {
  211. rcu_read_unlock();
  212. ieee80211_tx_status(priv->hw, skb);
  213. continue;
  214. }
  215. /* Check if we need to start aggregation */
  216. if (sta && conf_is_ht(&priv->hw->conf) &&
  217. !(skb->protocol == cpu_to_be16(ETH_P_PAE))) {
  218. if (ieee80211_is_data_qos(fc)) {
  219. u8 *qc, tid;
  220. struct ath9k_htc_sta *ista;
  221. qc = ieee80211_get_qos_ctl(hdr);
  222. tid = qc[0] & 0xf;
  223. ista = (struct ath9k_htc_sta *)sta->drv_priv;
  224. if (ath9k_htc_check_tx_aggr(priv, ista, tid)) {
  225. ieee80211_start_tx_ba_session(sta, tid, 0);
  226. spin_lock_bh(&priv->tx_lock);
  227. ista->tid_state[tid] = AGGR_PROGRESS;
  228. spin_unlock_bh(&priv->tx_lock);
  229. }
  230. }
  231. }
  232. rcu_read_unlock();
  233. /* Send status to mac80211 */
  234. ieee80211_tx_status(priv->hw, skb);
  235. }
  236. /* Wake TX queues if needed */
  237. spin_lock_bh(&priv->tx_lock);
  238. if (priv->tx_queues_stop) {
  239. priv->tx_queues_stop = false;
  240. spin_unlock_bh(&priv->tx_lock);
  241. ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
  242. "Waking up TX queues\n");
  243. ieee80211_wake_queues(priv->hw);
  244. return;
  245. }
  246. spin_unlock_bh(&priv->tx_lock);
  247. }
  248. void ath9k_htc_txep(void *drv_priv, struct sk_buff *skb,
  249. enum htc_endpoint_id ep_id, bool txok)
  250. {
  251. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) drv_priv;
  252. struct ath_common *common = ath9k_hw_common(priv->ah);
  253. struct ieee80211_tx_info *tx_info;
  254. if (!skb)
  255. return;
  256. if (ep_id == priv->mgmt_ep) {
  257. skb_pull(skb, sizeof(struct tx_mgmt_hdr));
  258. } else if ((ep_id == priv->data_bk_ep) ||
  259. (ep_id == priv->data_be_ep) ||
  260. (ep_id == priv->data_vi_ep) ||
  261. (ep_id == priv->data_vo_ep)) {
  262. skb_pull(skb, sizeof(struct tx_frame_hdr));
  263. } else {
  264. ath_err(common, "Unsupported TX EPID: %d\n", ep_id);
  265. dev_kfree_skb_any(skb);
  266. return;
  267. }
  268. tx_info = IEEE80211_SKB_CB(skb);
  269. if (txok)
  270. tx_info->flags |= IEEE80211_TX_STAT_ACK;
  271. skb_queue_tail(&priv->tx_queue, skb);
  272. tasklet_schedule(&priv->tx_tasklet);
  273. }
  274. int ath9k_tx_init(struct ath9k_htc_priv *priv)
  275. {
  276. skb_queue_head_init(&priv->tx_queue);
  277. return 0;
  278. }
  279. void ath9k_tx_cleanup(struct ath9k_htc_priv *priv)
  280. {
  281. }
  282. bool ath9k_htc_txq_setup(struct ath9k_htc_priv *priv, int subtype)
  283. {
  284. struct ath_hw *ah = priv->ah;
  285. struct ath_common *common = ath9k_hw_common(ah);
  286. struct ath9k_tx_queue_info qi;
  287. int qnum;
  288. memset(&qi, 0, sizeof(qi));
  289. ATH9K_HTC_INIT_TXQ(subtype);
  290. qnum = ath9k_hw_setuptxqueue(priv->ah, ATH9K_TX_QUEUE_DATA, &qi);
  291. if (qnum == -1)
  292. return false;
  293. if (qnum >= ARRAY_SIZE(priv->hwq_map)) {
  294. ath_err(common, "qnum %u out of range, max %zu!\n",
  295. qnum, ARRAY_SIZE(priv->hwq_map));
  296. ath9k_hw_releasetxqueue(ah, qnum);
  297. return false;
  298. }
  299. priv->hwq_map[subtype] = qnum;
  300. return true;
  301. }
  302. int ath9k_htc_cabq_setup(struct ath9k_htc_priv *priv)
  303. {
  304. struct ath9k_tx_queue_info qi;
  305. memset(&qi, 0, sizeof(qi));
  306. ATH9K_HTC_INIT_TXQ(0);
  307. return ath9k_hw_setuptxqueue(priv->ah, ATH9K_TX_QUEUE_CAB, &qi);
  308. }
  309. /******/
  310. /* RX */
  311. /******/
  312. /*
  313. * Calculate the RX filter to be set in the HW.
  314. */
  315. u32 ath9k_htc_calcrxfilter(struct ath9k_htc_priv *priv)
  316. {
  317. #define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
  318. struct ath_hw *ah = priv->ah;
  319. u32 rfilt;
  320. rfilt = (ath9k_hw_getrxfilter(ah) & RX_FILTER_PRESERVE)
  321. | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
  322. | ATH9K_RX_FILTER_MCAST;
  323. if (priv->rxfilter & FIF_PROBE_REQ)
  324. rfilt |= ATH9K_RX_FILTER_PROBEREQ;
  325. /*
  326. * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station
  327. * mode interface or when in monitor mode. AP mode does not need this
  328. * since it receives all in-BSS frames anyway.
  329. */
  330. if (((ah->opmode != NL80211_IFTYPE_AP) &&
  331. (priv->rxfilter & FIF_PROMISC_IN_BSS)) ||
  332. (ah->opmode == NL80211_IFTYPE_MONITOR))
  333. rfilt |= ATH9K_RX_FILTER_PROM;
  334. if (priv->rxfilter & FIF_CONTROL)
  335. rfilt |= ATH9K_RX_FILTER_CONTROL;
  336. if ((ah->opmode == NL80211_IFTYPE_STATION) &&
  337. !(priv->rxfilter & FIF_BCN_PRBRESP_PROMISC))
  338. rfilt |= ATH9K_RX_FILTER_MYBEACON;
  339. else
  340. rfilt |= ATH9K_RX_FILTER_BEACON;
  341. if (conf_is_ht(&priv->hw->conf))
  342. rfilt |= ATH9K_RX_FILTER_COMP_BAR;
  343. return rfilt;
  344. #undef RX_FILTER_PRESERVE
  345. }
  346. /*
  347. * Recv initialization for opmode change.
  348. */
  349. static void ath9k_htc_opmode_init(struct ath9k_htc_priv *priv)
  350. {
  351. struct ath_hw *ah = priv->ah;
  352. struct ath_common *common = ath9k_hw_common(ah);
  353. u32 rfilt, mfilt[2];
  354. /* configure rx filter */
  355. rfilt = ath9k_htc_calcrxfilter(priv);
  356. ath9k_hw_setrxfilter(ah, rfilt);
  357. /* configure bssid mask */
  358. ath_hw_setbssidmask(common);
  359. /* configure operational mode */
  360. ath9k_hw_setopmode(ah);
  361. /* calculate and install multicast filter */
  362. mfilt[0] = mfilt[1] = ~0;
  363. ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
  364. }
  365. void ath9k_host_rx_init(struct ath9k_htc_priv *priv)
  366. {
  367. ath9k_hw_rxena(priv->ah);
  368. ath9k_htc_opmode_init(priv);
  369. ath9k_hw_startpcureceive(priv->ah, (priv->op_flags & OP_SCANNING));
  370. priv->rx.last_rssi = ATH_RSSI_DUMMY_MARKER;
  371. }
  372. static void ath9k_process_rate(struct ieee80211_hw *hw,
  373. struct ieee80211_rx_status *rxs,
  374. u8 rx_rate, u8 rs_flags)
  375. {
  376. struct ieee80211_supported_band *sband;
  377. enum ieee80211_band band;
  378. unsigned int i = 0;
  379. if (rx_rate & 0x80) {
  380. /* HT rate */
  381. rxs->flag |= RX_FLAG_HT;
  382. if (rs_flags & ATH9K_RX_2040)
  383. rxs->flag |= RX_FLAG_40MHZ;
  384. if (rs_flags & ATH9K_RX_GI)
  385. rxs->flag |= RX_FLAG_SHORT_GI;
  386. rxs->rate_idx = rx_rate & 0x7f;
  387. return;
  388. }
  389. band = hw->conf.channel->band;
  390. sband = hw->wiphy->bands[band];
  391. for (i = 0; i < sband->n_bitrates; i++) {
  392. if (sband->bitrates[i].hw_value == rx_rate) {
  393. rxs->rate_idx = i;
  394. return;
  395. }
  396. if (sband->bitrates[i].hw_value_short == rx_rate) {
  397. rxs->rate_idx = i;
  398. rxs->flag |= RX_FLAG_SHORTPRE;
  399. return;
  400. }
  401. }
  402. }
  403. static bool ath9k_rx_prepare(struct ath9k_htc_priv *priv,
  404. struct ath9k_htc_rxbuf *rxbuf,
  405. struct ieee80211_rx_status *rx_status)
  406. {
  407. struct ieee80211_hdr *hdr;
  408. struct ieee80211_hw *hw = priv->hw;
  409. struct sk_buff *skb = rxbuf->skb;
  410. struct ath_common *common = ath9k_hw_common(priv->ah);
  411. struct ath_htc_rx_status *rxstatus;
  412. int hdrlen, padpos, padsize;
  413. int last_rssi = ATH_RSSI_DUMMY_MARKER;
  414. __le16 fc;
  415. if (skb->len <= HTC_RX_FRAME_HEADER_SIZE) {
  416. ath_err(common, "Corrupted RX frame, dropping\n");
  417. goto rx_next;
  418. }
  419. rxstatus = (struct ath_htc_rx_status *)skb->data;
  420. if (be16_to_cpu(rxstatus->rs_datalen) -
  421. (skb->len - HTC_RX_FRAME_HEADER_SIZE) != 0) {
  422. ath_err(common,
  423. "Corrupted RX data len, dropping (dlen: %d, skblen: %d)\n",
  424. rxstatus->rs_datalen, skb->len);
  425. goto rx_next;
  426. }
  427. /* Get the RX status information */
  428. memcpy(&rxbuf->rxstatus, rxstatus, HTC_RX_FRAME_HEADER_SIZE);
  429. skb_pull(skb, HTC_RX_FRAME_HEADER_SIZE);
  430. hdr = (struct ieee80211_hdr *)skb->data;
  431. fc = hdr->frame_control;
  432. hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  433. padpos = ath9k_cmn_padpos(fc);
  434. padsize = padpos & 3;
  435. if (padsize && skb->len >= padpos+padsize+FCS_LEN) {
  436. memmove(skb->data + padsize, skb->data, padpos);
  437. skb_pull(skb, padsize);
  438. }
  439. memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
  440. if (rxbuf->rxstatus.rs_status != 0) {
  441. if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_CRC)
  442. rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
  443. if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_PHY)
  444. goto rx_next;
  445. if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_DECRYPT) {
  446. /* FIXME */
  447. } else if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_MIC) {
  448. if (ieee80211_is_ctl(fc))
  449. /*
  450. * Sometimes, we get invalid
  451. * MIC failures on valid control frames.
  452. * Remove these mic errors.
  453. */
  454. rxbuf->rxstatus.rs_status &= ~ATH9K_RXERR_MIC;
  455. else
  456. rx_status->flag |= RX_FLAG_MMIC_ERROR;
  457. }
  458. /*
  459. * Reject error frames with the exception of
  460. * decryption and MIC failures. For monitor mode,
  461. * we also ignore the CRC error.
  462. */
  463. if (priv->ah->opmode == NL80211_IFTYPE_MONITOR) {
  464. if (rxbuf->rxstatus.rs_status &
  465. ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
  466. ATH9K_RXERR_CRC))
  467. goto rx_next;
  468. } else {
  469. if (rxbuf->rxstatus.rs_status &
  470. ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
  471. goto rx_next;
  472. }
  473. }
  474. }
  475. if (!(rxbuf->rxstatus.rs_status & ATH9K_RXERR_DECRYPT)) {
  476. u8 keyix;
  477. keyix = rxbuf->rxstatus.rs_keyix;
  478. if (keyix != ATH9K_RXKEYIX_INVALID) {
  479. rx_status->flag |= RX_FLAG_DECRYPTED;
  480. } else if (ieee80211_has_protected(fc) &&
  481. skb->len >= hdrlen + 4) {
  482. keyix = skb->data[hdrlen + 3] >> 6;
  483. if (test_bit(keyix, common->keymap))
  484. rx_status->flag |= RX_FLAG_DECRYPTED;
  485. }
  486. }
  487. ath9k_process_rate(hw, rx_status, rxbuf->rxstatus.rs_rate,
  488. rxbuf->rxstatus.rs_flags);
  489. if (priv->op_flags & OP_ASSOCIATED) {
  490. if (rxbuf->rxstatus.rs_rssi != ATH9K_RSSI_BAD &&
  491. !rxbuf->rxstatus.rs_moreaggr)
  492. ATH_RSSI_LPF(priv->rx.last_rssi,
  493. rxbuf->rxstatus.rs_rssi);
  494. last_rssi = priv->rx.last_rssi;
  495. if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
  496. rxbuf->rxstatus.rs_rssi = ATH_EP_RND(last_rssi,
  497. ATH_RSSI_EP_MULTIPLIER);
  498. if (rxbuf->rxstatus.rs_rssi < 0)
  499. rxbuf->rxstatus.rs_rssi = 0;
  500. if (ieee80211_is_beacon(fc))
  501. priv->ah->stats.avgbrssi = rxbuf->rxstatus.rs_rssi;
  502. }
  503. rx_status->mactime = be64_to_cpu(rxbuf->rxstatus.rs_tstamp);
  504. rx_status->band = hw->conf.channel->band;
  505. rx_status->freq = hw->conf.channel->center_freq;
  506. rx_status->signal = rxbuf->rxstatus.rs_rssi + ATH_DEFAULT_NOISE_FLOOR;
  507. rx_status->antenna = rxbuf->rxstatus.rs_antenna;
  508. rx_status->flag |= RX_FLAG_TSFT;
  509. return true;
  510. rx_next:
  511. return false;
  512. }
  513. /*
  514. * FIXME: Handle FLUSH later on.
  515. */
  516. void ath9k_rx_tasklet(unsigned long data)
  517. {
  518. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
  519. struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
  520. struct ieee80211_rx_status rx_status;
  521. struct sk_buff *skb;
  522. unsigned long flags;
  523. struct ieee80211_hdr *hdr;
  524. do {
  525. spin_lock_irqsave(&priv->rx.rxbuflock, flags);
  526. list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) {
  527. if (tmp_buf->in_process) {
  528. rxbuf = tmp_buf;
  529. break;
  530. }
  531. }
  532. if (rxbuf == NULL) {
  533. spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
  534. break;
  535. }
  536. if (!rxbuf->skb)
  537. goto requeue;
  538. if (!ath9k_rx_prepare(priv, rxbuf, &rx_status)) {
  539. dev_kfree_skb_any(rxbuf->skb);
  540. goto requeue;
  541. }
  542. memcpy(IEEE80211_SKB_RXCB(rxbuf->skb), &rx_status,
  543. sizeof(struct ieee80211_rx_status));
  544. skb = rxbuf->skb;
  545. hdr = (struct ieee80211_hdr *) skb->data;
  546. if (ieee80211_is_beacon(hdr->frame_control) && priv->ps_enabled)
  547. ieee80211_queue_work(priv->hw, &priv->ps_work);
  548. spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
  549. ieee80211_rx(priv->hw, skb);
  550. spin_lock_irqsave(&priv->rx.rxbuflock, flags);
  551. requeue:
  552. rxbuf->in_process = false;
  553. rxbuf->skb = NULL;
  554. list_move_tail(&rxbuf->list, &priv->rx.rxbuf);
  555. rxbuf = NULL;
  556. spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
  557. } while (1);
  558. }
  559. void ath9k_htc_rxep(void *drv_priv, struct sk_buff *skb,
  560. enum htc_endpoint_id ep_id)
  561. {
  562. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)drv_priv;
  563. struct ath_hw *ah = priv->ah;
  564. struct ath_common *common = ath9k_hw_common(ah);
  565. struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
  566. spin_lock(&priv->rx.rxbuflock);
  567. list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) {
  568. if (!tmp_buf->in_process) {
  569. rxbuf = tmp_buf;
  570. break;
  571. }
  572. }
  573. spin_unlock(&priv->rx.rxbuflock);
  574. if (rxbuf == NULL) {
  575. ath_dbg(common, ATH_DBG_ANY,
  576. "No free RX buffer\n");
  577. goto err;
  578. }
  579. spin_lock(&priv->rx.rxbuflock);
  580. rxbuf->skb = skb;
  581. rxbuf->in_process = true;
  582. spin_unlock(&priv->rx.rxbuflock);
  583. tasklet_schedule(&priv->rx_tasklet);
  584. return;
  585. err:
  586. dev_kfree_skb_any(skb);
  587. }
  588. /* FIXME: Locking for cleanup/init */
  589. void ath9k_rx_cleanup(struct ath9k_htc_priv *priv)
  590. {
  591. struct ath9k_htc_rxbuf *rxbuf, *tbuf;
  592. list_for_each_entry_safe(rxbuf, tbuf, &priv->rx.rxbuf, list) {
  593. list_del(&rxbuf->list);
  594. if (rxbuf->skb)
  595. dev_kfree_skb_any(rxbuf->skb);
  596. kfree(rxbuf);
  597. }
  598. }
  599. int ath9k_rx_init(struct ath9k_htc_priv *priv)
  600. {
  601. struct ath_hw *ah = priv->ah;
  602. struct ath_common *common = ath9k_hw_common(ah);
  603. struct ath9k_htc_rxbuf *rxbuf;
  604. int i = 0;
  605. INIT_LIST_HEAD(&priv->rx.rxbuf);
  606. spin_lock_init(&priv->rx.rxbuflock);
  607. for (i = 0; i < ATH9K_HTC_RXBUF; i++) {
  608. rxbuf = kzalloc(sizeof(struct ath9k_htc_rxbuf), GFP_KERNEL);
  609. if (rxbuf == NULL) {
  610. ath_err(common, "Unable to allocate RX buffers\n");
  611. goto err;
  612. }
  613. list_add_tail(&rxbuf->list, &priv->rx.rxbuf);
  614. }
  615. return 0;
  616. err:
  617. ath9k_rx_cleanup(priv);
  618. return -ENOMEM;
  619. }