htc_drv_txrx.c 18 KB

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