htc_drv_txrx.c 18 KB

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