htc_drv_txrx.c 18 KB

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