htc_drv_txrx.c 18 KB

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