htc_drv_txrx.c 18 KB

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