htc_drv_txrx.c 17 KB

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