htc_drv_txrx.c 17 KB

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