htc_drv_txrx.c 19 KB

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