htc_drv_txrx.c 18 KB

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