htc_drv_txrx.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220
  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. void ath9k_htc_check_stop_queues(struct ath9k_htc_priv *priv)
  51. {
  52. spin_lock_bh(&priv->tx.tx_lock);
  53. priv->tx.queued_cnt++;
  54. if ((priv->tx.queued_cnt >= ATH9K_HTC_TX_THRESHOLD) &&
  55. !(priv->tx.flags & ATH9K_HTC_OP_TX_QUEUES_STOP)) {
  56. priv->tx.flags |= ATH9K_HTC_OP_TX_QUEUES_STOP;
  57. ieee80211_stop_queues(priv->hw);
  58. }
  59. spin_unlock_bh(&priv->tx.tx_lock);
  60. }
  61. void ath9k_htc_check_wake_queues(struct ath9k_htc_priv *priv)
  62. {
  63. spin_lock_bh(&priv->tx.tx_lock);
  64. if ((priv->tx.queued_cnt < ATH9K_HTC_TX_THRESHOLD) &&
  65. (priv->tx.flags & ATH9K_HTC_OP_TX_QUEUES_STOP)) {
  66. priv->tx.flags &= ~ATH9K_HTC_OP_TX_QUEUES_STOP;
  67. ieee80211_wake_queues(priv->hw);
  68. }
  69. spin_unlock_bh(&priv->tx.tx_lock);
  70. }
  71. int ath9k_htc_tx_get_slot(struct ath9k_htc_priv *priv)
  72. {
  73. int slot;
  74. spin_lock_bh(&priv->tx.tx_lock);
  75. slot = find_first_zero_bit(priv->tx.tx_slot, MAX_TX_BUF_NUM);
  76. if (slot >= MAX_TX_BUF_NUM) {
  77. spin_unlock_bh(&priv->tx.tx_lock);
  78. return -ENOBUFS;
  79. }
  80. __set_bit(slot, priv->tx.tx_slot);
  81. spin_unlock_bh(&priv->tx.tx_lock);
  82. return slot;
  83. }
  84. void ath9k_htc_tx_clear_slot(struct ath9k_htc_priv *priv, int slot)
  85. {
  86. spin_lock_bh(&priv->tx.tx_lock);
  87. __clear_bit(slot, priv->tx.tx_slot);
  88. spin_unlock_bh(&priv->tx.tx_lock);
  89. }
  90. static inline enum htc_endpoint_id get_htc_epid(struct ath9k_htc_priv *priv,
  91. u16 qnum)
  92. {
  93. enum htc_endpoint_id epid;
  94. switch (qnum) {
  95. case 0:
  96. TX_QSTAT_INC(WME_AC_VO);
  97. epid = priv->data_vo_ep;
  98. break;
  99. case 1:
  100. TX_QSTAT_INC(WME_AC_VI);
  101. epid = priv->data_vi_ep;
  102. break;
  103. case 2:
  104. TX_QSTAT_INC(WME_AC_BE);
  105. epid = priv->data_be_ep;
  106. break;
  107. case 3:
  108. default:
  109. TX_QSTAT_INC(WME_AC_BK);
  110. epid = priv->data_bk_ep;
  111. break;
  112. }
  113. return epid;
  114. }
  115. static inline struct sk_buff_head*
  116. get_htc_epid_queue(struct ath9k_htc_priv *priv, u8 epid)
  117. {
  118. struct ath_common *common = ath9k_hw_common(priv->ah);
  119. struct sk_buff_head *epid_queue = NULL;
  120. if (epid == priv->mgmt_ep)
  121. epid_queue = &priv->tx.mgmt_ep_queue;
  122. else if (epid == priv->cab_ep)
  123. epid_queue = &priv->tx.cab_ep_queue;
  124. else if (epid == priv->data_be_ep)
  125. epid_queue = &priv->tx.data_be_queue;
  126. else if (epid == priv->data_bk_ep)
  127. epid_queue = &priv->tx.data_bk_queue;
  128. else if (epid == priv->data_vi_ep)
  129. epid_queue = &priv->tx.data_vi_queue;
  130. else if (epid == priv->data_vo_ep)
  131. epid_queue = &priv->tx.data_vo_queue;
  132. else
  133. ath_err(common, "Invalid EPID: %d\n", epid);
  134. return epid_queue;
  135. }
  136. /*
  137. * Removes the driver header and returns the TX slot number
  138. */
  139. static inline int strip_drv_header(struct ath9k_htc_priv *priv,
  140. struct sk_buff *skb)
  141. {
  142. struct ath_common *common = ath9k_hw_common(priv->ah);
  143. struct ath9k_htc_tx_ctl *tx_ctl;
  144. int slot;
  145. tx_ctl = HTC_SKB_CB(skb);
  146. if (tx_ctl->epid == priv->mgmt_ep) {
  147. struct tx_mgmt_hdr *tx_mhdr =
  148. (struct tx_mgmt_hdr *)skb->data;
  149. slot = tx_mhdr->cookie;
  150. skb_pull(skb, sizeof(struct tx_mgmt_hdr));
  151. } else if ((tx_ctl->epid == priv->data_bk_ep) ||
  152. (tx_ctl->epid == priv->data_be_ep) ||
  153. (tx_ctl->epid == priv->data_vi_ep) ||
  154. (tx_ctl->epid == priv->data_vo_ep) ||
  155. (tx_ctl->epid == priv->cab_ep)) {
  156. struct tx_frame_hdr *tx_fhdr =
  157. (struct tx_frame_hdr *)skb->data;
  158. slot = tx_fhdr->cookie;
  159. skb_pull(skb, sizeof(struct tx_frame_hdr));
  160. } else {
  161. ath_err(common, "Unsupported EPID: %d\n", tx_ctl->epid);
  162. slot = -EINVAL;
  163. }
  164. return slot;
  165. }
  166. int ath_htc_txq_update(struct ath9k_htc_priv *priv, int qnum,
  167. struct ath9k_tx_queue_info *qinfo)
  168. {
  169. struct ath_hw *ah = priv->ah;
  170. int error = 0;
  171. struct ath9k_tx_queue_info qi;
  172. ath9k_hw_get_txq_props(ah, qnum, &qi);
  173. qi.tqi_aifs = qinfo->tqi_aifs;
  174. qi.tqi_cwmin = qinfo->tqi_cwmin / 2; /* XXX */
  175. qi.tqi_cwmax = qinfo->tqi_cwmax;
  176. qi.tqi_burstTime = qinfo->tqi_burstTime;
  177. qi.tqi_readyTime = qinfo->tqi_readyTime;
  178. if (!ath9k_hw_set_txq_props(ah, qnum, &qi)) {
  179. ath_err(ath9k_hw_common(ah),
  180. "Unable to update hardware queue %u!\n", qnum);
  181. error = -EIO;
  182. } else {
  183. ath9k_hw_resettxqueue(ah, qnum);
  184. }
  185. return error;
  186. }
  187. static void ath9k_htc_tx_mgmt(struct ath9k_htc_priv *priv,
  188. struct ath9k_htc_vif *avp,
  189. struct sk_buff *skb,
  190. u8 sta_idx, u8 vif_idx, u8 slot)
  191. {
  192. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  193. struct ieee80211_mgmt *mgmt;
  194. struct ieee80211_hdr *hdr;
  195. struct tx_mgmt_hdr mgmt_hdr;
  196. struct ath9k_htc_tx_ctl *tx_ctl;
  197. u8 *tx_fhdr;
  198. tx_ctl = HTC_SKB_CB(skb);
  199. hdr = (struct ieee80211_hdr *) skb->data;
  200. memset(tx_ctl, 0, sizeof(*tx_ctl));
  201. memset(&mgmt_hdr, 0, sizeof(struct tx_mgmt_hdr));
  202. /*
  203. * Set the TSF adjust value for probe response
  204. * frame also.
  205. */
  206. if (avp && unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
  207. mgmt = (struct ieee80211_mgmt *)skb->data;
  208. mgmt->u.probe_resp.timestamp = avp->tsfadjust;
  209. }
  210. tx_ctl->type = ATH9K_HTC_MGMT;
  211. mgmt_hdr.node_idx = sta_idx;
  212. mgmt_hdr.vif_idx = vif_idx;
  213. mgmt_hdr.tidno = 0;
  214. mgmt_hdr.flags = 0;
  215. mgmt_hdr.cookie = slot;
  216. mgmt_hdr.key_type = ath9k_cmn_get_hw_crypto_keytype(skb);
  217. if (mgmt_hdr.key_type == ATH9K_KEY_TYPE_CLEAR)
  218. mgmt_hdr.keyix = (u8) ATH9K_TXKEYIX_INVALID;
  219. else
  220. mgmt_hdr.keyix = tx_info->control.hw_key->hw_key_idx;
  221. tx_fhdr = skb_push(skb, sizeof(mgmt_hdr));
  222. memcpy(tx_fhdr, (u8 *) &mgmt_hdr, sizeof(mgmt_hdr));
  223. tx_ctl->epid = priv->mgmt_ep;
  224. }
  225. static void ath9k_htc_tx_data(struct ath9k_htc_priv *priv,
  226. struct ieee80211_vif *vif,
  227. struct sk_buff *skb,
  228. u8 sta_idx, u8 vif_idx, u8 slot,
  229. bool is_cab)
  230. {
  231. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  232. struct ieee80211_hdr *hdr;
  233. struct ath9k_htc_tx_ctl *tx_ctl;
  234. struct tx_frame_hdr tx_hdr;
  235. u32 flags = 0;
  236. u8 *qc, *tx_fhdr;
  237. u16 qnum;
  238. tx_ctl = HTC_SKB_CB(skb);
  239. hdr = (struct ieee80211_hdr *) skb->data;
  240. memset(tx_ctl, 0, sizeof(*tx_ctl));
  241. memset(&tx_hdr, 0, sizeof(struct tx_frame_hdr));
  242. tx_hdr.node_idx = sta_idx;
  243. tx_hdr.vif_idx = vif_idx;
  244. tx_hdr.cookie = slot;
  245. /*
  246. * This is a bit redundant but it helps to get
  247. * the per-packet index quickly when draining the
  248. * TX queue in the HIF layer. Otherwise we would
  249. * have to parse the packet contents ...
  250. */
  251. tx_ctl->sta_idx = sta_idx;
  252. if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
  253. tx_ctl->type = ATH9K_HTC_AMPDU;
  254. tx_hdr.data_type = ATH9K_HTC_AMPDU;
  255. } else {
  256. tx_ctl->type = ATH9K_HTC_NORMAL;
  257. tx_hdr.data_type = ATH9K_HTC_NORMAL;
  258. }
  259. if (ieee80211_is_data_qos(hdr->frame_control)) {
  260. qc = ieee80211_get_qos_ctl(hdr);
  261. tx_hdr.tidno = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
  262. }
  263. /* Check for RTS protection */
  264. if (priv->hw->wiphy->rts_threshold != (u32) -1)
  265. if (skb->len > priv->hw->wiphy->rts_threshold)
  266. flags |= ATH9K_HTC_TX_RTSCTS;
  267. /* CTS-to-self */
  268. if (!(flags & ATH9K_HTC_TX_RTSCTS) &&
  269. (vif && vif->bss_conf.use_cts_prot))
  270. flags |= ATH9K_HTC_TX_CTSONLY;
  271. tx_hdr.flags = cpu_to_be32(flags);
  272. tx_hdr.key_type = ath9k_cmn_get_hw_crypto_keytype(skb);
  273. if (tx_hdr.key_type == ATH9K_KEY_TYPE_CLEAR)
  274. tx_hdr.keyix = (u8) ATH9K_TXKEYIX_INVALID;
  275. else
  276. tx_hdr.keyix = tx_info->control.hw_key->hw_key_idx;
  277. tx_fhdr = skb_push(skb, sizeof(tx_hdr));
  278. memcpy(tx_fhdr, (u8 *) &tx_hdr, sizeof(tx_hdr));
  279. if (is_cab) {
  280. CAB_STAT_INC;
  281. tx_ctl->epid = priv->cab_ep;
  282. return;
  283. }
  284. qnum = skb_get_queue_mapping(skb);
  285. tx_ctl->epid = get_htc_epid(priv, qnum);
  286. }
  287. int ath9k_htc_tx_start(struct ath9k_htc_priv *priv,
  288. struct sk_buff *skb,
  289. u8 slot, bool is_cab)
  290. {
  291. struct ieee80211_hdr *hdr;
  292. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  293. struct ieee80211_sta *sta = tx_info->control.sta;
  294. struct ieee80211_vif *vif = tx_info->control.vif;
  295. struct ath9k_htc_sta *ista;
  296. struct ath9k_htc_vif *avp = NULL;
  297. u8 sta_idx, vif_idx;
  298. hdr = (struct ieee80211_hdr *) skb->data;
  299. /*
  300. * Find out on which interface this packet has to be
  301. * sent out.
  302. */
  303. if (vif) {
  304. avp = (struct ath9k_htc_vif *) vif->drv_priv;
  305. vif_idx = avp->index;
  306. } else {
  307. if (!priv->ah->is_monitoring) {
  308. ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
  309. "VIF is null, but no monitor interface !\n");
  310. return -EINVAL;
  311. }
  312. vif_idx = priv->mon_vif_idx;
  313. }
  314. /*
  315. * Find out which station this packet is destined for.
  316. */
  317. if (sta) {
  318. ista = (struct ath9k_htc_sta *) sta->drv_priv;
  319. sta_idx = ista->index;
  320. } else {
  321. sta_idx = priv->vif_sta_pos[vif_idx];
  322. }
  323. if (ieee80211_is_data(hdr->frame_control))
  324. ath9k_htc_tx_data(priv, vif, skb,
  325. sta_idx, vif_idx, slot, is_cab);
  326. else
  327. ath9k_htc_tx_mgmt(priv, avp, skb,
  328. sta_idx, vif_idx, slot);
  329. return htc_send(priv->htc, skb);
  330. }
  331. static inline bool __ath9k_htc_check_tx_aggr(struct ath9k_htc_priv *priv,
  332. struct ath9k_htc_sta *ista, u8 tid)
  333. {
  334. bool ret = false;
  335. spin_lock_bh(&priv->tx.tx_lock);
  336. if ((tid < ATH9K_HTC_MAX_TID) && (ista->tid_state[tid] == AGGR_STOP))
  337. ret = true;
  338. spin_unlock_bh(&priv->tx.tx_lock);
  339. return ret;
  340. }
  341. static void ath9k_htc_check_tx_aggr(struct ath9k_htc_priv *priv,
  342. struct ieee80211_vif *vif,
  343. struct sk_buff *skb)
  344. {
  345. struct ieee80211_sta *sta;
  346. struct ieee80211_hdr *hdr;
  347. __le16 fc;
  348. hdr = (struct ieee80211_hdr *) skb->data;
  349. fc = hdr->frame_control;
  350. rcu_read_lock();
  351. sta = ieee80211_find_sta(vif, hdr->addr1);
  352. if (!sta) {
  353. rcu_read_unlock();
  354. return;
  355. }
  356. if (sta && conf_is_ht(&priv->hw->conf) &&
  357. !(skb->protocol == cpu_to_be16(ETH_P_PAE))) {
  358. if (ieee80211_is_data_qos(fc)) {
  359. u8 *qc, tid;
  360. struct ath9k_htc_sta *ista;
  361. qc = ieee80211_get_qos_ctl(hdr);
  362. tid = qc[0] & 0xf;
  363. ista = (struct ath9k_htc_sta *)sta->drv_priv;
  364. if (__ath9k_htc_check_tx_aggr(priv, ista, tid)) {
  365. ieee80211_start_tx_ba_session(sta, tid, 0);
  366. spin_lock_bh(&priv->tx.tx_lock);
  367. ista->tid_state[tid] = AGGR_PROGRESS;
  368. spin_unlock_bh(&priv->tx.tx_lock);
  369. }
  370. }
  371. }
  372. rcu_read_unlock();
  373. }
  374. static void ath9k_htc_tx_process(struct ath9k_htc_priv *priv,
  375. struct sk_buff *skb,
  376. struct __wmi_event_txstatus *txs)
  377. {
  378. struct ieee80211_vif *vif;
  379. struct ath9k_htc_tx_ctl *tx_ctl;
  380. struct ieee80211_tx_info *tx_info;
  381. struct ieee80211_tx_rate *rate;
  382. struct ieee80211_conf *cur_conf = &priv->hw->conf;
  383. bool txok;
  384. int slot;
  385. slot = strip_drv_header(priv, skb);
  386. if (slot < 0) {
  387. dev_kfree_skb_any(skb);
  388. return;
  389. }
  390. tx_ctl = HTC_SKB_CB(skb);
  391. txok = tx_ctl->txok;
  392. tx_info = IEEE80211_SKB_CB(skb);
  393. vif = tx_info->control.vif;
  394. rate = &tx_info->status.rates[0];
  395. memset(&tx_info->status, 0, sizeof(tx_info->status));
  396. /*
  397. * URB submission failed for this frame, it never reached
  398. * the target.
  399. */
  400. if (!txok || !vif || !txs)
  401. goto send_mac80211;
  402. if (txs->ts_flags & ATH9K_HTC_TXSTAT_ACK)
  403. tx_info->flags |= IEEE80211_TX_STAT_ACK;
  404. if (txs->ts_flags & ATH9K_HTC_TXSTAT_FILT)
  405. tx_info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
  406. if (txs->ts_flags & ATH9K_HTC_TXSTAT_RTC_CTS)
  407. rate->flags |= IEEE80211_TX_RC_USE_RTS_CTS;
  408. rate->count = 1;
  409. rate->idx = MS(txs->ts_rate, ATH9K_HTC_TXSTAT_RATE);
  410. if (txs->ts_flags & ATH9K_HTC_TXSTAT_MCS) {
  411. rate->flags |= IEEE80211_TX_RC_MCS;
  412. if (txs->ts_flags & ATH9K_HTC_TXSTAT_CW40)
  413. rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
  414. if (txs->ts_flags & ATH9K_HTC_TXSTAT_SGI)
  415. rate->flags |= IEEE80211_TX_RC_SHORT_GI;
  416. } else {
  417. if (cur_conf->channel->band == IEEE80211_BAND_5GHZ)
  418. rate->idx += 4; /* No CCK rates */
  419. }
  420. ath9k_htc_check_tx_aggr(priv, vif, skb);
  421. send_mac80211:
  422. spin_lock_bh(&priv->tx.tx_lock);
  423. if (WARN_ON(--priv->tx.queued_cnt < 0))
  424. priv->tx.queued_cnt = 0;
  425. spin_unlock_bh(&priv->tx.tx_lock);
  426. ath9k_htc_tx_clear_slot(priv, slot);
  427. /* Send status to mac80211 */
  428. ieee80211_tx_status(priv->hw, skb);
  429. }
  430. static inline void ath9k_htc_tx_drainq(struct ath9k_htc_priv *priv,
  431. struct sk_buff_head *queue)
  432. {
  433. struct sk_buff *skb;
  434. while ((skb = skb_dequeue(queue)) != NULL) {
  435. ath9k_htc_tx_process(priv, skb, NULL);
  436. }
  437. }
  438. void ath9k_htc_tx_drain(struct ath9k_htc_priv *priv)
  439. {
  440. struct ath9k_htc_tx_event *event, *tmp;
  441. spin_lock_bh(&priv->tx.tx_lock);
  442. priv->tx.flags |= ATH9K_HTC_OP_TX_DRAIN;
  443. spin_unlock_bh(&priv->tx.tx_lock);
  444. /*
  445. * Ensure that all pending TX frames are flushed,
  446. * and that the TX completion/failed tasklets is killed.
  447. */
  448. htc_stop(priv->htc);
  449. tasklet_kill(&priv->wmi->wmi_event_tasklet);
  450. tasklet_kill(&priv->tx_failed_tasklet);
  451. ath9k_htc_tx_drainq(priv, &priv->tx.mgmt_ep_queue);
  452. ath9k_htc_tx_drainq(priv, &priv->tx.cab_ep_queue);
  453. ath9k_htc_tx_drainq(priv, &priv->tx.data_be_queue);
  454. ath9k_htc_tx_drainq(priv, &priv->tx.data_bk_queue);
  455. ath9k_htc_tx_drainq(priv, &priv->tx.data_vi_queue);
  456. ath9k_htc_tx_drainq(priv, &priv->tx.data_vo_queue);
  457. ath9k_htc_tx_drainq(priv, &priv->tx.tx_failed);
  458. /*
  459. * The TX cleanup timer has already been killed.
  460. */
  461. spin_lock_bh(&priv->wmi->event_lock);
  462. list_for_each_entry_safe(event, tmp, &priv->wmi->pending_tx_events, list) {
  463. list_del(&event->list);
  464. kfree(event);
  465. }
  466. spin_unlock_bh(&priv->wmi->event_lock);
  467. spin_lock_bh(&priv->tx.tx_lock);
  468. priv->tx.flags &= ~ATH9K_HTC_OP_TX_DRAIN;
  469. spin_unlock_bh(&priv->tx.tx_lock);
  470. }
  471. void ath9k_tx_failed_tasklet(unsigned long data)
  472. {
  473. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
  474. spin_lock_bh(&priv->tx.tx_lock);
  475. if (priv->tx.flags & ATH9K_HTC_OP_TX_DRAIN) {
  476. spin_unlock_bh(&priv->tx.tx_lock);
  477. return;
  478. }
  479. spin_unlock_bh(&priv->tx.tx_lock);
  480. ath9k_htc_tx_drainq(priv, &priv->tx.tx_failed);
  481. }
  482. static inline bool check_cookie(struct ath9k_htc_priv *priv,
  483. struct sk_buff *skb,
  484. u8 cookie, u8 epid)
  485. {
  486. u8 fcookie = 0;
  487. if (epid == priv->mgmt_ep) {
  488. struct tx_mgmt_hdr *hdr;
  489. hdr = (struct tx_mgmt_hdr *) skb->data;
  490. fcookie = hdr->cookie;
  491. } else if ((epid == priv->data_bk_ep) ||
  492. (epid == priv->data_be_ep) ||
  493. (epid == priv->data_vi_ep) ||
  494. (epid == priv->data_vo_ep) ||
  495. (epid == priv->cab_ep)) {
  496. struct tx_frame_hdr *hdr;
  497. hdr = (struct tx_frame_hdr *) skb->data;
  498. fcookie = hdr->cookie;
  499. }
  500. if (fcookie == cookie)
  501. return true;
  502. return false;
  503. }
  504. static struct sk_buff* ath9k_htc_tx_get_packet(struct ath9k_htc_priv *priv,
  505. struct __wmi_event_txstatus *txs)
  506. {
  507. struct ath_common *common = ath9k_hw_common(priv->ah);
  508. struct sk_buff_head *epid_queue;
  509. struct sk_buff *skb, *tmp;
  510. unsigned long flags;
  511. u8 epid = MS(txs->ts_rate, ATH9K_HTC_TXSTAT_EPID);
  512. epid_queue = get_htc_epid_queue(priv, epid);
  513. if (!epid_queue)
  514. return NULL;
  515. spin_lock_irqsave(&epid_queue->lock, flags);
  516. skb_queue_walk_safe(epid_queue, skb, tmp) {
  517. if (check_cookie(priv, skb, txs->cookie, epid)) {
  518. __skb_unlink(skb, epid_queue);
  519. spin_unlock_irqrestore(&epid_queue->lock, flags);
  520. return skb;
  521. }
  522. }
  523. spin_unlock_irqrestore(&epid_queue->lock, flags);
  524. ath_dbg(common, ATH_DBG_XMIT,
  525. "No matching packet for cookie: %d, epid: %d\n",
  526. txs->cookie, epid);
  527. return NULL;
  528. }
  529. void ath9k_htc_txstatus(struct ath9k_htc_priv *priv, void *wmi_event)
  530. {
  531. struct wmi_event_txstatus *txs = (struct wmi_event_txstatus *)wmi_event;
  532. struct __wmi_event_txstatus *__txs;
  533. struct sk_buff *skb;
  534. struct ath9k_htc_tx_event *tx_pend;
  535. int i;
  536. for (i = 0; i < txs->cnt; i++) {
  537. WARN_ON(txs->cnt > HTC_MAX_TX_STATUS);
  538. __txs = &txs->txstatus[i];
  539. skb = ath9k_htc_tx_get_packet(priv, __txs);
  540. if (!skb) {
  541. /*
  542. * Store this event, so that the TX cleanup
  543. * routine can check later for the needed packet.
  544. */
  545. tx_pend = kzalloc(sizeof(struct ath9k_htc_tx_event),
  546. GFP_ATOMIC);
  547. if (!tx_pend)
  548. continue;
  549. memcpy(&tx_pend->txs, __txs,
  550. sizeof(struct __wmi_event_txstatus));
  551. spin_lock(&priv->wmi->event_lock);
  552. list_add_tail(&tx_pend->list,
  553. &priv->wmi->pending_tx_events);
  554. spin_unlock(&priv->wmi->event_lock);
  555. continue;
  556. }
  557. ath9k_htc_tx_process(priv, skb, __txs);
  558. }
  559. /* Wake TX queues if needed */
  560. ath9k_htc_check_wake_queues(priv);
  561. }
  562. void ath9k_htc_txep(void *drv_priv, struct sk_buff *skb,
  563. enum htc_endpoint_id ep_id, bool txok)
  564. {
  565. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) drv_priv;
  566. struct ath9k_htc_tx_ctl *tx_ctl;
  567. struct sk_buff_head *epid_queue;
  568. tx_ctl = HTC_SKB_CB(skb);
  569. tx_ctl->txok = txok;
  570. tx_ctl->timestamp = jiffies;
  571. if (!txok) {
  572. skb_queue_tail(&priv->tx.tx_failed, skb);
  573. tasklet_schedule(&priv->tx_failed_tasklet);
  574. return;
  575. }
  576. epid_queue = get_htc_epid_queue(priv, ep_id);
  577. if (!epid_queue) {
  578. dev_kfree_skb_any(skb);
  579. return;
  580. }
  581. skb_queue_tail(epid_queue, skb);
  582. }
  583. static inline bool check_packet(struct ath9k_htc_priv *priv, struct sk_buff *skb)
  584. {
  585. struct ath_common *common = ath9k_hw_common(priv->ah);
  586. struct ath9k_htc_tx_ctl *tx_ctl;
  587. tx_ctl = HTC_SKB_CB(skb);
  588. if (time_after(jiffies,
  589. tx_ctl->timestamp +
  590. msecs_to_jiffies(ATH9K_HTC_TX_TIMEOUT_INTERVAL))) {
  591. ath_dbg(common, ATH_DBG_XMIT,
  592. "Dropping a packet due to TX timeout\n");
  593. return true;
  594. }
  595. return false;
  596. }
  597. static void ath9k_htc_tx_cleanup_queue(struct ath9k_htc_priv *priv,
  598. struct sk_buff_head *epid_queue)
  599. {
  600. bool process = false;
  601. unsigned long flags;
  602. struct sk_buff *skb, *tmp;
  603. struct sk_buff_head queue;
  604. skb_queue_head_init(&queue);
  605. spin_lock_irqsave(&epid_queue->lock, flags);
  606. skb_queue_walk_safe(epid_queue, skb, tmp) {
  607. if (check_packet(priv, skb)) {
  608. __skb_unlink(skb, epid_queue);
  609. __skb_queue_tail(&queue, skb);
  610. process = true;
  611. }
  612. }
  613. spin_unlock_irqrestore(&epid_queue->lock, flags);
  614. if (process) {
  615. skb_queue_walk_safe(&queue, skb, tmp) {
  616. __skb_unlink(skb, &queue);
  617. ath9k_htc_tx_process(priv, skb, NULL);
  618. }
  619. }
  620. }
  621. void ath9k_htc_tx_cleanup_timer(unsigned long data)
  622. {
  623. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) data;
  624. struct ath_common *common = ath9k_hw_common(priv->ah);
  625. struct ath9k_htc_tx_event *event, *tmp;
  626. struct sk_buff *skb;
  627. spin_lock(&priv->wmi->event_lock);
  628. list_for_each_entry_safe(event, tmp, &priv->wmi->pending_tx_events, list) {
  629. skb = ath9k_htc_tx_get_packet(priv, &event->txs);
  630. if (skb) {
  631. ath_dbg(common, ATH_DBG_XMIT,
  632. "Found packet for cookie: %d, epid: %d\n",
  633. event->txs.cookie,
  634. MS(event->txs.ts_rate, ATH9K_HTC_TXSTAT_EPID));
  635. ath9k_htc_tx_process(priv, skb, &event->txs);
  636. list_del(&event->list);
  637. kfree(event);
  638. continue;
  639. }
  640. if (++event->count >= ATH9K_HTC_TX_TIMEOUT_COUNT) {
  641. list_del(&event->list);
  642. kfree(event);
  643. }
  644. }
  645. spin_unlock(&priv->wmi->event_lock);
  646. /*
  647. * Check if status-pending packets have to be cleaned up.
  648. */
  649. ath9k_htc_tx_cleanup_queue(priv, &priv->tx.mgmt_ep_queue);
  650. ath9k_htc_tx_cleanup_queue(priv, &priv->tx.cab_ep_queue);
  651. ath9k_htc_tx_cleanup_queue(priv, &priv->tx.data_be_queue);
  652. ath9k_htc_tx_cleanup_queue(priv, &priv->tx.data_bk_queue);
  653. ath9k_htc_tx_cleanup_queue(priv, &priv->tx.data_vi_queue);
  654. ath9k_htc_tx_cleanup_queue(priv, &priv->tx.data_vo_queue);
  655. /* Wake TX queues if needed */
  656. ath9k_htc_check_wake_queues(priv);
  657. mod_timer(&priv->tx.cleanup_timer,
  658. jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL));
  659. }
  660. int ath9k_tx_init(struct ath9k_htc_priv *priv)
  661. {
  662. skb_queue_head_init(&priv->tx.mgmt_ep_queue);
  663. skb_queue_head_init(&priv->tx.cab_ep_queue);
  664. skb_queue_head_init(&priv->tx.data_be_queue);
  665. skb_queue_head_init(&priv->tx.data_bk_queue);
  666. skb_queue_head_init(&priv->tx.data_vi_queue);
  667. skb_queue_head_init(&priv->tx.data_vo_queue);
  668. skb_queue_head_init(&priv->tx.tx_failed);
  669. return 0;
  670. }
  671. void ath9k_tx_cleanup(struct ath9k_htc_priv *priv)
  672. {
  673. }
  674. bool ath9k_htc_txq_setup(struct ath9k_htc_priv *priv, int subtype)
  675. {
  676. struct ath_hw *ah = priv->ah;
  677. struct ath_common *common = ath9k_hw_common(ah);
  678. struct ath9k_tx_queue_info qi;
  679. int qnum;
  680. memset(&qi, 0, sizeof(qi));
  681. ATH9K_HTC_INIT_TXQ(subtype);
  682. qnum = ath9k_hw_setuptxqueue(priv->ah, ATH9K_TX_QUEUE_DATA, &qi);
  683. if (qnum == -1)
  684. return false;
  685. if (qnum >= ARRAY_SIZE(priv->hwq_map)) {
  686. ath_err(common, "qnum %u out of range, max %zu!\n",
  687. qnum, ARRAY_SIZE(priv->hwq_map));
  688. ath9k_hw_releasetxqueue(ah, qnum);
  689. return false;
  690. }
  691. priv->hwq_map[subtype] = qnum;
  692. return true;
  693. }
  694. int ath9k_htc_cabq_setup(struct ath9k_htc_priv *priv)
  695. {
  696. struct ath9k_tx_queue_info qi;
  697. memset(&qi, 0, sizeof(qi));
  698. ATH9K_HTC_INIT_TXQ(0);
  699. return ath9k_hw_setuptxqueue(priv->ah, ATH9K_TX_QUEUE_CAB, &qi);
  700. }
  701. /******/
  702. /* RX */
  703. /******/
  704. /*
  705. * Calculate the RX filter to be set in the HW.
  706. */
  707. u32 ath9k_htc_calcrxfilter(struct ath9k_htc_priv *priv)
  708. {
  709. #define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
  710. struct ath_hw *ah = priv->ah;
  711. u32 rfilt;
  712. rfilt = (ath9k_hw_getrxfilter(ah) & RX_FILTER_PRESERVE)
  713. | ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
  714. | ATH9K_RX_FILTER_MCAST;
  715. if (priv->rxfilter & FIF_PROBE_REQ)
  716. rfilt |= ATH9K_RX_FILTER_PROBEREQ;
  717. /*
  718. * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station
  719. * mode interface or when in monitor mode. AP mode does not need this
  720. * since it receives all in-BSS frames anyway.
  721. */
  722. if (((ah->opmode != NL80211_IFTYPE_AP) &&
  723. (priv->rxfilter & FIF_PROMISC_IN_BSS)) ||
  724. ah->is_monitoring)
  725. rfilt |= ATH9K_RX_FILTER_PROM;
  726. if (priv->rxfilter & FIF_CONTROL)
  727. rfilt |= ATH9K_RX_FILTER_CONTROL;
  728. if ((ah->opmode == NL80211_IFTYPE_STATION) &&
  729. !(priv->rxfilter & FIF_BCN_PRBRESP_PROMISC))
  730. rfilt |= ATH9K_RX_FILTER_MYBEACON;
  731. else
  732. rfilt |= ATH9K_RX_FILTER_BEACON;
  733. if (conf_is_ht(&priv->hw->conf)) {
  734. rfilt |= ATH9K_RX_FILTER_COMP_BAR;
  735. rfilt |= ATH9K_RX_FILTER_UNCOMP_BA_BAR;
  736. }
  737. if (priv->rxfilter & FIF_PSPOLL)
  738. rfilt |= ATH9K_RX_FILTER_PSPOLL;
  739. return rfilt;
  740. #undef RX_FILTER_PRESERVE
  741. }
  742. /*
  743. * Recv initialization for opmode change.
  744. */
  745. static void ath9k_htc_opmode_init(struct ath9k_htc_priv *priv)
  746. {
  747. struct ath_hw *ah = priv->ah;
  748. u32 rfilt, mfilt[2];
  749. /* configure rx filter */
  750. rfilt = ath9k_htc_calcrxfilter(priv);
  751. ath9k_hw_setrxfilter(ah, rfilt);
  752. /* calculate and install multicast filter */
  753. mfilt[0] = mfilt[1] = ~0;
  754. ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
  755. }
  756. void ath9k_host_rx_init(struct ath9k_htc_priv *priv)
  757. {
  758. ath9k_hw_rxena(priv->ah);
  759. ath9k_htc_opmode_init(priv);
  760. ath9k_hw_startpcureceive(priv->ah, (priv->op_flags & OP_SCANNING));
  761. priv->rx.last_rssi = ATH_RSSI_DUMMY_MARKER;
  762. }
  763. static void ath9k_process_rate(struct ieee80211_hw *hw,
  764. struct ieee80211_rx_status *rxs,
  765. u8 rx_rate, u8 rs_flags)
  766. {
  767. struct ieee80211_supported_band *sband;
  768. enum ieee80211_band band;
  769. unsigned int i = 0;
  770. if (rx_rate & 0x80) {
  771. /* HT rate */
  772. rxs->flag |= RX_FLAG_HT;
  773. if (rs_flags & ATH9K_RX_2040)
  774. rxs->flag |= RX_FLAG_40MHZ;
  775. if (rs_flags & ATH9K_RX_GI)
  776. rxs->flag |= RX_FLAG_SHORT_GI;
  777. rxs->rate_idx = rx_rate & 0x7f;
  778. return;
  779. }
  780. band = hw->conf.channel->band;
  781. sband = hw->wiphy->bands[band];
  782. for (i = 0; i < sband->n_bitrates; i++) {
  783. if (sband->bitrates[i].hw_value == rx_rate) {
  784. rxs->rate_idx = i;
  785. return;
  786. }
  787. if (sband->bitrates[i].hw_value_short == rx_rate) {
  788. rxs->rate_idx = i;
  789. rxs->flag |= RX_FLAG_SHORTPRE;
  790. return;
  791. }
  792. }
  793. }
  794. static bool ath9k_rx_prepare(struct ath9k_htc_priv *priv,
  795. struct ath9k_htc_rxbuf *rxbuf,
  796. struct ieee80211_rx_status *rx_status)
  797. {
  798. struct ieee80211_hdr *hdr;
  799. struct ieee80211_hw *hw = priv->hw;
  800. struct sk_buff *skb = rxbuf->skb;
  801. struct ath_common *common = ath9k_hw_common(priv->ah);
  802. struct ath_htc_rx_status *rxstatus;
  803. int hdrlen, padpos, padsize;
  804. int last_rssi = ATH_RSSI_DUMMY_MARKER;
  805. __le16 fc;
  806. if (skb->len < HTC_RX_FRAME_HEADER_SIZE) {
  807. ath_err(common, "Corrupted RX frame, dropping (len: %d)\n",
  808. skb->len);
  809. goto rx_next;
  810. }
  811. rxstatus = (struct ath_htc_rx_status *)skb->data;
  812. if (be16_to_cpu(rxstatus->rs_datalen) -
  813. (skb->len - HTC_RX_FRAME_HEADER_SIZE) != 0) {
  814. ath_err(common,
  815. "Corrupted RX data len, dropping (dlen: %d, skblen: %d)\n",
  816. rxstatus->rs_datalen, skb->len);
  817. goto rx_next;
  818. }
  819. ath9k_htc_err_stat_rx(priv, rxstatus);
  820. /* Get the RX status information */
  821. memcpy(&rxbuf->rxstatus, rxstatus, HTC_RX_FRAME_HEADER_SIZE);
  822. skb_pull(skb, HTC_RX_FRAME_HEADER_SIZE);
  823. hdr = (struct ieee80211_hdr *)skb->data;
  824. fc = hdr->frame_control;
  825. hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  826. padpos = ath9k_cmn_padpos(fc);
  827. padsize = padpos & 3;
  828. if (padsize && skb->len >= padpos+padsize+FCS_LEN) {
  829. memmove(skb->data + padsize, skb->data, padpos);
  830. skb_pull(skb, padsize);
  831. }
  832. memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
  833. if (rxbuf->rxstatus.rs_status != 0) {
  834. if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_CRC)
  835. rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
  836. if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_PHY)
  837. goto rx_next;
  838. if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_DECRYPT) {
  839. /* FIXME */
  840. } else if (rxbuf->rxstatus.rs_status & ATH9K_RXERR_MIC) {
  841. if (ieee80211_is_ctl(fc))
  842. /*
  843. * Sometimes, we get invalid
  844. * MIC failures on valid control frames.
  845. * Remove these mic errors.
  846. */
  847. rxbuf->rxstatus.rs_status &= ~ATH9K_RXERR_MIC;
  848. else
  849. rx_status->flag |= RX_FLAG_MMIC_ERROR;
  850. }
  851. /*
  852. * Reject error frames with the exception of
  853. * decryption and MIC failures. For monitor mode,
  854. * we also ignore the CRC error.
  855. */
  856. if (priv->ah->opmode == NL80211_IFTYPE_MONITOR) {
  857. if (rxbuf->rxstatus.rs_status &
  858. ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
  859. ATH9K_RXERR_CRC))
  860. goto rx_next;
  861. } else {
  862. if (rxbuf->rxstatus.rs_status &
  863. ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
  864. goto rx_next;
  865. }
  866. }
  867. }
  868. if (!(rxbuf->rxstatus.rs_status & ATH9K_RXERR_DECRYPT)) {
  869. u8 keyix;
  870. keyix = rxbuf->rxstatus.rs_keyix;
  871. if (keyix != ATH9K_RXKEYIX_INVALID) {
  872. rx_status->flag |= RX_FLAG_DECRYPTED;
  873. } else if (ieee80211_has_protected(fc) &&
  874. skb->len >= hdrlen + 4) {
  875. keyix = skb->data[hdrlen + 3] >> 6;
  876. if (test_bit(keyix, common->keymap))
  877. rx_status->flag |= RX_FLAG_DECRYPTED;
  878. }
  879. }
  880. ath9k_process_rate(hw, rx_status, rxbuf->rxstatus.rs_rate,
  881. rxbuf->rxstatus.rs_flags);
  882. if (rxbuf->rxstatus.rs_rssi != ATH9K_RSSI_BAD &&
  883. !rxbuf->rxstatus.rs_moreaggr)
  884. ATH_RSSI_LPF(priv->rx.last_rssi,
  885. rxbuf->rxstatus.rs_rssi);
  886. last_rssi = priv->rx.last_rssi;
  887. if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
  888. rxbuf->rxstatus.rs_rssi = ATH_EP_RND(last_rssi,
  889. ATH_RSSI_EP_MULTIPLIER);
  890. if (rxbuf->rxstatus.rs_rssi < 0)
  891. rxbuf->rxstatus.rs_rssi = 0;
  892. if (ieee80211_is_beacon(fc))
  893. priv->ah->stats.avgbrssi = rxbuf->rxstatus.rs_rssi;
  894. rx_status->mactime = be64_to_cpu(rxbuf->rxstatus.rs_tstamp);
  895. rx_status->band = hw->conf.channel->band;
  896. rx_status->freq = hw->conf.channel->center_freq;
  897. rx_status->signal = rxbuf->rxstatus.rs_rssi + ATH_DEFAULT_NOISE_FLOOR;
  898. rx_status->antenna = rxbuf->rxstatus.rs_antenna;
  899. rx_status->flag |= RX_FLAG_MACTIME_MPDU;
  900. return true;
  901. rx_next:
  902. return false;
  903. }
  904. /*
  905. * FIXME: Handle FLUSH later on.
  906. */
  907. void ath9k_rx_tasklet(unsigned long data)
  908. {
  909. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)data;
  910. struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
  911. struct ieee80211_rx_status rx_status;
  912. struct sk_buff *skb;
  913. unsigned long flags;
  914. struct ieee80211_hdr *hdr;
  915. do {
  916. spin_lock_irqsave(&priv->rx.rxbuflock, flags);
  917. list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) {
  918. if (tmp_buf->in_process) {
  919. rxbuf = tmp_buf;
  920. break;
  921. }
  922. }
  923. if (rxbuf == NULL) {
  924. spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
  925. break;
  926. }
  927. if (!rxbuf->skb)
  928. goto requeue;
  929. if (!ath9k_rx_prepare(priv, rxbuf, &rx_status)) {
  930. dev_kfree_skb_any(rxbuf->skb);
  931. goto requeue;
  932. }
  933. memcpy(IEEE80211_SKB_RXCB(rxbuf->skb), &rx_status,
  934. sizeof(struct ieee80211_rx_status));
  935. skb = rxbuf->skb;
  936. hdr = (struct ieee80211_hdr *) skb->data;
  937. if (ieee80211_is_beacon(hdr->frame_control) && priv->ps_enabled)
  938. ieee80211_queue_work(priv->hw, &priv->ps_work);
  939. spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
  940. ieee80211_rx(priv->hw, skb);
  941. spin_lock_irqsave(&priv->rx.rxbuflock, flags);
  942. requeue:
  943. rxbuf->in_process = false;
  944. rxbuf->skb = NULL;
  945. list_move_tail(&rxbuf->list, &priv->rx.rxbuf);
  946. rxbuf = NULL;
  947. spin_unlock_irqrestore(&priv->rx.rxbuflock, flags);
  948. } while (1);
  949. }
  950. void ath9k_htc_rxep(void *drv_priv, struct sk_buff *skb,
  951. enum htc_endpoint_id ep_id)
  952. {
  953. struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *)drv_priv;
  954. struct ath_hw *ah = priv->ah;
  955. struct ath_common *common = ath9k_hw_common(ah);
  956. struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
  957. spin_lock(&priv->rx.rxbuflock);
  958. list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) {
  959. if (!tmp_buf->in_process) {
  960. rxbuf = tmp_buf;
  961. break;
  962. }
  963. }
  964. spin_unlock(&priv->rx.rxbuflock);
  965. if (rxbuf == NULL) {
  966. ath_dbg(common, ATH_DBG_ANY,
  967. "No free RX buffer\n");
  968. goto err;
  969. }
  970. spin_lock(&priv->rx.rxbuflock);
  971. rxbuf->skb = skb;
  972. rxbuf->in_process = true;
  973. spin_unlock(&priv->rx.rxbuflock);
  974. tasklet_schedule(&priv->rx_tasklet);
  975. return;
  976. err:
  977. dev_kfree_skb_any(skb);
  978. }
  979. /* FIXME: Locking for cleanup/init */
  980. void ath9k_rx_cleanup(struct ath9k_htc_priv *priv)
  981. {
  982. struct ath9k_htc_rxbuf *rxbuf, *tbuf;
  983. list_for_each_entry_safe(rxbuf, tbuf, &priv->rx.rxbuf, list) {
  984. list_del(&rxbuf->list);
  985. if (rxbuf->skb)
  986. dev_kfree_skb_any(rxbuf->skb);
  987. kfree(rxbuf);
  988. }
  989. }
  990. int ath9k_rx_init(struct ath9k_htc_priv *priv)
  991. {
  992. struct ath_hw *ah = priv->ah;
  993. struct ath_common *common = ath9k_hw_common(ah);
  994. struct ath9k_htc_rxbuf *rxbuf;
  995. int i = 0;
  996. INIT_LIST_HEAD(&priv->rx.rxbuf);
  997. spin_lock_init(&priv->rx.rxbuflock);
  998. for (i = 0; i < ATH9K_HTC_RXBUF; i++) {
  999. rxbuf = kzalloc(sizeof(struct ath9k_htc_rxbuf), GFP_KERNEL);
  1000. if (rxbuf == NULL) {
  1001. ath_err(common, "Unable to allocate RX buffers\n");
  1002. goto err;
  1003. }
  1004. list_add_tail(&rxbuf->list, &priv->rx.rxbuf);
  1005. }
  1006. return 0;
  1007. err:
  1008. ath9k_rx_cleanup(priv);
  1009. return -ENOMEM;
  1010. }