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. int hdrlen, padpos, padsize;
  369. int last_rssi = ATH_RSSI_DUMMY_MARKER;
  370. __le16 fc;
  371. hdr = (struct ieee80211_hdr *)skb->data;
  372. fc = hdr->frame_control;
  373. hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  374. padpos = ath9k_cmn_padpos(fc);
  375. padsize = padpos & 3;
  376. if (padsize && skb->len >= padpos+padsize+FCS_LEN) {
  377. memmove(skb->data + padsize, skb->data, padpos);
  378. skb_pull(skb, padsize);
  379. }
  380. memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
  381. if (rxbuf->rxstatus.rs_status != 0) {
  382. if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_CRC)
  383. rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
  384. if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_PHY)
  385. goto rx_next;
  386. if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_DECRYPT) {
  387. /* FIXME */
  388. } else if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_MIC) {
  389. if (ieee80211_is_ctl(fc))
  390. /*
  391. * Sometimes, we get invalid
  392. * MIC failures on valid control frames.
  393. * Remove these mic errors.
  394. */
  395. rxbuf->rxstatus.rs_status &= ~ATH9K_RXERR_MIC;
  396. else
  397. rx_status->flag |= RX_FLAG_MMIC_ERROR;
  398. }
  399. /*
  400. * Reject error frames with the exception of
  401. * decryption and MIC failures. For monitor mode,
  402. * we also ignore the CRC error.
  403. */
  404. if (priv->ah->opmode == NL80211_IFTYPE_MONITOR) {
  405. if (rxbuf->rxstatus.rs_status &
  406. ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
  407. ATH9K_RXERR_CRC))
  408. goto rx_next;
  409. } else {
  410. if (rxbuf->rxstatus.rs_status &
  411. ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
  412. goto rx_next;
  413. }
  414. }
  415. }
  416. if (!(rxbuf->rxstatus.rs_status & ATH9K_RXERR_DECRYPT)) {
  417. u8 keyix;
  418. keyix = rxbuf->rxstatus.rs_keyix;
  419. if (keyix != ATH9K_RXKEYIX_INVALID) {
  420. rx_status->flag |= RX_FLAG_DECRYPTED;
  421. } else if (ieee80211_has_protected(fc) &&
  422. skb->len >= hdrlen + 4) {
  423. keyix = skb->data[hdrlen + 3] >> 6;
  424. if (test_bit(keyix, common->keymap))
  425. rx_status->flag |= RX_FLAG_DECRYPTED;
  426. }
  427. }
  428. ath9k_process_rate(hw, rx_status, rxbuf->rxstatus.rs_rate,
  429. rxbuf->rxstatus.rs_flags);
  430. if (priv->op_flags & OP_ASSOCIATED) {
  431. if (rxbuf->rxstatus.rs_rssi != ATH9K_RSSI_BAD &&
  432. !rxbuf->rxstatus.rs_moreaggr)
  433. ATH_RSSI_LPF(priv->rx.last_rssi,
  434. rxbuf->rxstatus.rs_rssi);
  435. last_rssi = priv->rx.last_rssi;
  436. if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
  437. rxbuf->rxstatus.rs_rssi = ATH_EP_RND(last_rssi,
  438. ATH_RSSI_EP_MULTIPLIER);
  439. if (rxbuf->rxstatus.rs_rssi < 0)
  440. rxbuf->rxstatus.rs_rssi = 0;
  441. if (ieee80211_is_beacon(fc))
  442. priv->ah->stats.avgbrssi = rxbuf->rxstatus.rs_rssi;
  443. }
  444. rx_status->mactime = be64_to_cpu(rxbuf->rxstatus.rs_tstamp);
  445. rx_status->band = hw->conf.channel->band;
  446. rx_status->freq = hw->conf.channel->center_freq;
  447. rx_status->signal = rxbuf->rxstatus.rs_rssi + ATH_DEFAULT_NOISE_FLOOR;
  448. rx_status->antenna = rxbuf->rxstatus.rs_antenna;
  449. rx_status->flag |= RX_FLAG_TSFT;
  450. return true;
  451. rx_next:
  452. return false;
  453. }
  454. /*
  455. * FIXME: Handle FLUSH later on.
  456. */
  457. void ath9k_rx_tasklet(unsigned long data)
  458. {
  459. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
  460. struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
  461. struct ieee80211_rx_status rx_status;
  462. struct sk_buff *skb;
  463. unsigned long flags;
  464. struct ieee80211_hdr *hdr;
  465. do {
  466. spin_lock_irqsave(&priv->rx.rxbuflock, flags);
  467. list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) {
  468. if (tmp_buf->in_process) {
  469. rxbuf = tmp_buf;
  470. break;
  471. }
  472. }
  473. if (rxbuf == NULL) {
  474. spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
  475. break;
  476. }
  477. if (!rxbuf->skb)
  478. goto requeue;
  479. if (!ath9k_rx_prepare(priv, rxbuf, &rx_status)) {
  480. dev_kfree_skb_any(rxbuf->skb);
  481. goto requeue;
  482. }
  483. memcpy(IEEE80211_SKB_RXCB(rxbuf->skb), &rx_status,
  484. sizeof(struct ieee80211_rx_status));
  485. skb = rxbuf->skb;
  486. hdr = (struct ieee80211_hdr *) skb->data;
  487. if (ieee80211_is_beacon(hdr->frame_control) && priv->ps_enabled)
  488. ieee80211_queue_work(priv->hw, &priv->ps_work);
  489. spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
  490. ieee80211_rx(priv->hw, skb);
  491. spin_lock_irqsave(&priv->rx.rxbuflock, flags);
  492. requeue:
  493. rxbuf->in_process = false;
  494. rxbuf->skb = NULL;
  495. list_move_tail(&rxbuf->list, &priv->rx.rxbuf);
  496. rxbuf = NULL;
  497. spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
  498. } while (1);
  499. }
  500. void ath9k_htc_rxep(void *drv_priv, struct sk_buff *skb,
  501. enum htc_endpoint_id ep_id)
  502. {
  503. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)drv_priv;
  504. struct ath_hw *ah = priv->ah;
  505. struct ath_common *common = ath9k_hw_common(ah);
  506. struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
  507. struct ath_htc_rx_status *rxstatus;
  508. u32 len = 0;
  509. spin_lock(&priv->rx.rxbuflock);
  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. spin_unlock(&priv->rx.rxbuflock);
  517. if (rxbuf == NULL) {
  518. ath_print(common, ATH_DBG_ANY,
  519. "No free RX buffer\n");
  520. goto err;
  521. }
  522. len = skb->len;
  523. if (len <= HTC_RX_FRAME_HEADER_SIZE) {
  524. ath_print(common, ATH_DBG_FATAL,
  525. "Corrupted RX frame, dropping\n");
  526. goto err;
  527. }
  528. rxstatus = (struct ath_htc_rx_status *)skb->data;
  529. if (be16_to_cpu(rxstatus->rs_datalen) -
  530. (len - HTC_RX_FRAME_HEADER_SIZE) != 0) {
  531. ath_print(common, ATH_DBG_FATAL,
  532. "Corrupted RX data len, dropping "
  533. "(epid: %d, dlen: %d, skblen: %d)\n",
  534. ep_id, rxstatus->rs_datalen, len);
  535. goto err;
  536. }
  537. spin_lock(&priv->rx.rxbuflock);
  538. memcpy(&rxbuf->rxstatus, rxstatus, HTC_RX_FRAME_HEADER_SIZE);
  539. skb_pull(skb, HTC_RX_FRAME_HEADER_SIZE);
  540. rxbuf->skb = skb;
  541. rxbuf->in_process = true;
  542. spin_unlock(&priv->rx.rxbuflock);
  543. tasklet_schedule(&priv->rx_tasklet);
  544. return;
  545. err:
  546. dev_kfree_skb_any(skb);
  547. return;
  548. }
  549. /* FIXME: Locking for cleanup/init */
  550. void ath9k_rx_cleanup(struct ath9k_htc_priv *priv)
  551. {
  552. struct ath9k_htc_rxbuf *rxbuf, *tbuf;
  553. list_for_each_entry_safe(rxbuf, tbuf, &priv->rx.rxbuf, list) {
  554. list_del(&rxbuf->list);
  555. if (rxbuf->skb)
  556. dev_kfree_skb_any(rxbuf->skb);
  557. kfree(rxbuf);
  558. }
  559. }
  560. int ath9k_rx_init(struct ath9k_htc_priv *priv)
  561. {
  562. struct ath_hw *ah = priv->ah;
  563. struct ath_common *common = ath9k_hw_common(ah);
  564. struct ath9k_htc_rxbuf *rxbuf;
  565. int i = 0;
  566. INIT_LIST_HEAD(&priv->rx.rxbuf);
  567. spin_lock_init(&priv->rx.rxbuflock);
  568. for (i = 0; i < ATH9K_HTC_RXBUF; i++) {
  569. rxbuf = kzalloc(sizeof(struct ath9k_htc_rxbuf), GFP_KERNEL);
  570. if (rxbuf == NULL) {
  571. ath_print(common, ATH_DBG_FATAL,
  572. "Unable to allocate RX buffers\n");
  573. goto err;
  574. }
  575. list_add_tail(&rxbuf->list, &priv->rx.rxbuf);
  576. }
  577. return 0;
  578. err:
  579. ath9k_rx_cleanup(priv);
  580. return -ENOMEM;
  581. }