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. #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. if (ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
  340. ath_hw_setbssidmask(common);
  341. /* configure operational mode */
  342. ath9k_hw_setopmode(ah);
  343. /* calculate and install multicast filter */
  344. mfilt[0] = mfilt[1] = ~0;
  345. ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
  346. }
  347. void ath9k_host_rx_init(struct ath9k_htc_priv *priv)
  348. {
  349. ath9k_hw_rxena(priv->ah);
  350. ath9k_htc_opmode_init(priv);
  351. ath9k_hw_startpcureceive(priv->ah, (priv->op_flags & OP_SCANNING));
  352. priv->rx.last_rssi = ATH_RSSI_DUMMY_MARKER;
  353. }
  354. static void ath9k_process_rate(struct ieee80211_hw *hw,
  355. struct ieee80211_rx_status *rxs,
  356. u8 rx_rate, u8 rs_flags)
  357. {
  358. struct ieee80211_supported_band *sband;
  359. enum ieee80211_band band;
  360. unsigned int i = 0;
  361. if (rx_rate & 0x80) {
  362. /* HT rate */
  363. rxs->flag |= RX_FLAG_HT;
  364. if (rs_flags & ATH9K_RX_2040)
  365. rxs->flag |= RX_FLAG_40MHZ;
  366. if (rs_flags & ATH9K_RX_GI)
  367. rxs->flag |= RX_FLAG_SHORT_GI;
  368. rxs->rate_idx = rx_rate & 0x7f;
  369. return;
  370. }
  371. band = hw->conf.channel->band;
  372. sband = hw->wiphy->bands[band];
  373. for (i = 0; i < sband->n_bitrates; i++) {
  374. if (sband->bitrates[i].hw_value == rx_rate) {
  375. rxs->rate_idx = i;
  376. return;
  377. }
  378. if (sband->bitrates[i].hw_value_short == rx_rate) {
  379. rxs->rate_idx = i;
  380. rxs->flag |= RX_FLAG_SHORTPRE;
  381. return;
  382. }
  383. }
  384. }
  385. static bool ath9k_rx_prepare(struct ath9k_htc_priv *priv,
  386. struct ath9k_htc_rxbuf *rxbuf,
  387. struct ieee80211_rx_status *rx_status)
  388. {
  389. struct ieee80211_hdr *hdr;
  390. struct ieee80211_hw *hw = priv->hw;
  391. struct sk_buff *skb = rxbuf->skb;
  392. struct ath_common *common = ath9k_hw_common(priv->ah);
  393. struct ath_htc_rx_status *rxstatus;
  394. int hdrlen, padpos, padsize;
  395. int last_rssi = ATH_RSSI_DUMMY_MARKER;
  396. __le16 fc;
  397. if (skb->len <= HTC_RX_FRAME_HEADER_SIZE) {
  398. ath_print(common, ATH_DBG_FATAL,
  399. "Corrupted RX frame, dropping\n");
  400. goto rx_next;
  401. }
  402. rxstatus = (struct ath_htc_rx_status *)skb->data;
  403. if (be16_to_cpu(rxstatus->rs_datalen) -
  404. (skb->len - HTC_RX_FRAME_HEADER_SIZE) != 0) {
  405. ath_print(common, ATH_DBG_FATAL,
  406. "Corrupted RX data len, dropping "
  407. "(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_print(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_print(common, ATH_DBG_FATAL,
  595. "Unable to allocate RX buffers\n");
  596. goto err;
  597. }
  598. list_add_tail(&rxbuf->list, &priv->rx.rxbuf);
  599. }
  600. return 0;
  601. err:
  602. ath9k_rx_cleanup(priv);
  603. return -ENOMEM;
  604. }