htc_drv_txrx.c 19 KB

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