htc_drv_txrx.c 18 KB

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