recv.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  1. /*
  2. * Copyright (c) 2008-2011 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 <linux/dma-mapping.h>
  17. #include "ath9k.h"
  18. #include "ar9003_mac.h"
  19. #define SKB_CB_ATHBUF(__skb) (*((struct ath_rxbuf **)__skb->cb))
  20. static inline bool ath9k_check_auto_sleep(struct ath_softc *sc)
  21. {
  22. return sc->ps_enabled &&
  23. (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP);
  24. }
  25. /*
  26. * Setup and link descriptors.
  27. *
  28. * 11N: we can no longer afford to self link the last descriptor.
  29. * MAC acknowledges BA status as long as it copies frames to host
  30. * buffer (or rx fifo). This can incorrectly acknowledge packets
  31. * to a sender if last desc is self-linked.
  32. */
  33. static void ath_rx_buf_link(struct ath_softc *sc, struct ath_rxbuf *bf,
  34. bool flush)
  35. {
  36. struct ath_hw *ah = sc->sc_ah;
  37. struct ath_common *common = ath9k_hw_common(ah);
  38. struct ath_desc *ds;
  39. struct sk_buff *skb;
  40. ds = bf->bf_desc;
  41. ds->ds_link = 0; /* link to null */
  42. ds->ds_data = bf->bf_buf_addr;
  43. /* virtual addr of the beginning of the buffer. */
  44. skb = bf->bf_mpdu;
  45. BUG_ON(skb == NULL);
  46. ds->ds_vdata = skb->data;
  47. /*
  48. * setup rx descriptors. The rx_bufsize here tells the hardware
  49. * how much data it can DMA to us and that we are prepared
  50. * to process
  51. */
  52. ath9k_hw_setuprxdesc(ah, ds,
  53. common->rx_bufsize,
  54. 0);
  55. if (sc->rx.rxlink)
  56. *sc->rx.rxlink = bf->bf_daddr;
  57. else if (!flush)
  58. ath9k_hw_putrxbuf(ah, bf->bf_daddr);
  59. sc->rx.rxlink = &ds->ds_link;
  60. }
  61. static void ath_rx_buf_relink(struct ath_softc *sc, struct ath_rxbuf *bf,
  62. bool flush)
  63. {
  64. if (sc->rx.buf_hold)
  65. ath_rx_buf_link(sc, sc->rx.buf_hold, flush);
  66. sc->rx.buf_hold = bf;
  67. }
  68. static void ath_setdefantenna(struct ath_softc *sc, u32 antenna)
  69. {
  70. /* XXX block beacon interrupts */
  71. ath9k_hw_setantenna(sc->sc_ah, antenna);
  72. sc->rx.defant = antenna;
  73. sc->rx.rxotherant = 0;
  74. }
  75. static void ath_opmode_init(struct ath_softc *sc)
  76. {
  77. struct ath_hw *ah = sc->sc_ah;
  78. struct ath_common *common = ath9k_hw_common(ah);
  79. u32 rfilt, mfilt[2];
  80. /* configure rx filter */
  81. rfilt = ath_calcrxfilter(sc);
  82. ath9k_hw_setrxfilter(ah, rfilt);
  83. /* configure bssid mask */
  84. ath_hw_setbssidmask(common);
  85. /* configure operational mode */
  86. ath9k_hw_setopmode(ah);
  87. /* calculate and install multicast filter */
  88. mfilt[0] = mfilt[1] = ~0;
  89. ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
  90. }
  91. static bool ath_rx_edma_buf_link(struct ath_softc *sc,
  92. enum ath9k_rx_qtype qtype)
  93. {
  94. struct ath_hw *ah = sc->sc_ah;
  95. struct ath_rx_edma *rx_edma;
  96. struct sk_buff *skb;
  97. struct ath_rxbuf *bf;
  98. rx_edma = &sc->rx.rx_edma[qtype];
  99. if (skb_queue_len(&rx_edma->rx_fifo) >= rx_edma->rx_fifo_hwsize)
  100. return false;
  101. bf = list_first_entry(&sc->rx.rxbuf, struct ath_rxbuf, list);
  102. list_del_init(&bf->list);
  103. skb = bf->bf_mpdu;
  104. memset(skb->data, 0, ah->caps.rx_status_len);
  105. dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
  106. ah->caps.rx_status_len, DMA_TO_DEVICE);
  107. SKB_CB_ATHBUF(skb) = bf;
  108. ath9k_hw_addrxbuf_edma(ah, bf->bf_buf_addr, qtype);
  109. __skb_queue_tail(&rx_edma->rx_fifo, skb);
  110. return true;
  111. }
  112. static void ath_rx_addbuffer_edma(struct ath_softc *sc,
  113. enum ath9k_rx_qtype qtype)
  114. {
  115. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  116. struct ath_rxbuf *bf, *tbf;
  117. if (list_empty(&sc->rx.rxbuf)) {
  118. ath_dbg(common, QUEUE, "No free rx buf available\n");
  119. return;
  120. }
  121. list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list)
  122. if (!ath_rx_edma_buf_link(sc, qtype))
  123. break;
  124. }
  125. static void ath_rx_remove_buffer(struct ath_softc *sc,
  126. enum ath9k_rx_qtype qtype)
  127. {
  128. struct ath_rxbuf *bf;
  129. struct ath_rx_edma *rx_edma;
  130. struct sk_buff *skb;
  131. rx_edma = &sc->rx.rx_edma[qtype];
  132. while ((skb = __skb_dequeue(&rx_edma->rx_fifo)) != NULL) {
  133. bf = SKB_CB_ATHBUF(skb);
  134. BUG_ON(!bf);
  135. list_add_tail(&bf->list, &sc->rx.rxbuf);
  136. }
  137. }
  138. static void ath_rx_edma_cleanup(struct ath_softc *sc)
  139. {
  140. struct ath_hw *ah = sc->sc_ah;
  141. struct ath_common *common = ath9k_hw_common(ah);
  142. struct ath_rxbuf *bf;
  143. ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
  144. ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
  145. list_for_each_entry(bf, &sc->rx.rxbuf, list) {
  146. if (bf->bf_mpdu) {
  147. dma_unmap_single(sc->dev, bf->bf_buf_addr,
  148. common->rx_bufsize,
  149. DMA_BIDIRECTIONAL);
  150. dev_kfree_skb_any(bf->bf_mpdu);
  151. bf->bf_buf_addr = 0;
  152. bf->bf_mpdu = NULL;
  153. }
  154. }
  155. }
  156. static void ath_rx_edma_init_queue(struct ath_rx_edma *rx_edma, int size)
  157. {
  158. __skb_queue_head_init(&rx_edma->rx_fifo);
  159. rx_edma->rx_fifo_hwsize = size;
  160. }
  161. static int ath_rx_edma_init(struct ath_softc *sc, int nbufs)
  162. {
  163. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  164. struct ath_hw *ah = sc->sc_ah;
  165. struct sk_buff *skb;
  166. struct ath_rxbuf *bf;
  167. int error = 0, i;
  168. u32 size;
  169. ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
  170. ah->caps.rx_status_len);
  171. ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_LP],
  172. ah->caps.rx_lp_qdepth);
  173. ath_rx_edma_init_queue(&sc->rx.rx_edma[ATH9K_RX_QUEUE_HP],
  174. ah->caps.rx_hp_qdepth);
  175. size = sizeof(struct ath_rxbuf) * nbufs;
  176. bf = devm_kzalloc(sc->dev, size, GFP_KERNEL);
  177. if (!bf)
  178. return -ENOMEM;
  179. INIT_LIST_HEAD(&sc->rx.rxbuf);
  180. for (i = 0; i < nbufs; i++, bf++) {
  181. skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_KERNEL);
  182. if (!skb) {
  183. error = -ENOMEM;
  184. goto rx_init_fail;
  185. }
  186. memset(skb->data, 0, common->rx_bufsize);
  187. bf->bf_mpdu = skb;
  188. bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
  189. common->rx_bufsize,
  190. DMA_BIDIRECTIONAL);
  191. if (unlikely(dma_mapping_error(sc->dev,
  192. bf->bf_buf_addr))) {
  193. dev_kfree_skb_any(skb);
  194. bf->bf_mpdu = NULL;
  195. bf->bf_buf_addr = 0;
  196. ath_err(common,
  197. "dma_mapping_error() on RX init\n");
  198. error = -ENOMEM;
  199. goto rx_init_fail;
  200. }
  201. list_add_tail(&bf->list, &sc->rx.rxbuf);
  202. }
  203. return 0;
  204. rx_init_fail:
  205. ath_rx_edma_cleanup(sc);
  206. return error;
  207. }
  208. static void ath_edma_start_recv(struct ath_softc *sc)
  209. {
  210. ath9k_hw_rxena(sc->sc_ah);
  211. ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_HP);
  212. ath_rx_addbuffer_edma(sc, ATH9K_RX_QUEUE_LP);
  213. ath_opmode_init(sc);
  214. ath9k_hw_startpcureceive(sc->sc_ah, sc->cur_chan->offchannel);
  215. }
  216. static void ath_edma_stop_recv(struct ath_softc *sc)
  217. {
  218. ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_HP);
  219. ath_rx_remove_buffer(sc, ATH9K_RX_QUEUE_LP);
  220. }
  221. int ath_rx_init(struct ath_softc *sc, int nbufs)
  222. {
  223. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  224. struct sk_buff *skb;
  225. struct ath_rxbuf *bf;
  226. int error = 0;
  227. spin_lock_init(&sc->sc_pcu_lock);
  228. common->rx_bufsize = IEEE80211_MAX_MPDU_LEN / 2 +
  229. sc->sc_ah->caps.rx_status_len;
  230. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  231. return ath_rx_edma_init(sc, nbufs);
  232. ath_dbg(common, CONFIG, "cachelsz %u rxbufsize %u\n",
  233. common->cachelsz, common->rx_bufsize);
  234. /* Initialize rx descriptors */
  235. error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf,
  236. "rx", nbufs, 1, 0);
  237. if (error != 0) {
  238. ath_err(common,
  239. "failed to allocate rx descriptors: %d\n",
  240. error);
  241. goto err;
  242. }
  243. list_for_each_entry(bf, &sc->rx.rxbuf, list) {
  244. skb = ath_rxbuf_alloc(common, common->rx_bufsize,
  245. GFP_KERNEL);
  246. if (skb == NULL) {
  247. error = -ENOMEM;
  248. goto err;
  249. }
  250. bf->bf_mpdu = skb;
  251. bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
  252. common->rx_bufsize,
  253. DMA_FROM_DEVICE);
  254. if (unlikely(dma_mapping_error(sc->dev,
  255. bf->bf_buf_addr))) {
  256. dev_kfree_skb_any(skb);
  257. bf->bf_mpdu = NULL;
  258. bf->bf_buf_addr = 0;
  259. ath_err(common,
  260. "dma_mapping_error() on RX init\n");
  261. error = -ENOMEM;
  262. goto err;
  263. }
  264. }
  265. sc->rx.rxlink = NULL;
  266. err:
  267. if (error)
  268. ath_rx_cleanup(sc);
  269. return error;
  270. }
  271. void ath_rx_cleanup(struct ath_softc *sc)
  272. {
  273. struct ath_hw *ah = sc->sc_ah;
  274. struct ath_common *common = ath9k_hw_common(ah);
  275. struct sk_buff *skb;
  276. struct ath_rxbuf *bf;
  277. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
  278. ath_rx_edma_cleanup(sc);
  279. return;
  280. }
  281. list_for_each_entry(bf, &sc->rx.rxbuf, list) {
  282. skb = bf->bf_mpdu;
  283. if (skb) {
  284. dma_unmap_single(sc->dev, bf->bf_buf_addr,
  285. common->rx_bufsize,
  286. DMA_FROM_DEVICE);
  287. dev_kfree_skb(skb);
  288. bf->bf_buf_addr = 0;
  289. bf->bf_mpdu = NULL;
  290. }
  291. }
  292. }
  293. /*
  294. * Calculate the receive filter according to the
  295. * operating mode and state:
  296. *
  297. * o always accept unicast, broadcast, and multicast traffic
  298. * o maintain current state of phy error reception (the hal
  299. * may enable phy error frames for noise immunity work)
  300. * o probe request frames are accepted only when operating in
  301. * hostap, adhoc, or monitor modes
  302. * o enable promiscuous mode according to the interface state
  303. * o accept beacons:
  304. * - when operating in adhoc mode so the 802.11 layer creates
  305. * node table entries for peers,
  306. * - when operating in station mode for collecting rssi data when
  307. * the station is otherwise quiet, or
  308. * - when operating as a repeater so we see repeater-sta beacons
  309. * - when scanning
  310. */
  311. u32 ath_calcrxfilter(struct ath_softc *sc)
  312. {
  313. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  314. u32 rfilt;
  315. if (config_enabled(CONFIG_ATH9K_TX99))
  316. return 0;
  317. rfilt = ATH9K_RX_FILTER_UCAST | ATH9K_RX_FILTER_BCAST
  318. | ATH9K_RX_FILTER_MCAST;
  319. /* if operating on a DFS channel, enable radar pulse detection */
  320. if (sc->hw->conf.radar_enabled)
  321. rfilt |= ATH9K_RX_FILTER_PHYRADAR | ATH9K_RX_FILTER_PHYERR;
  322. spin_lock_bh(&sc->chan_lock);
  323. if (sc->cur_chan->rxfilter & FIF_PROBE_REQ)
  324. rfilt |= ATH9K_RX_FILTER_PROBEREQ;
  325. /*
  326. * Set promiscuous mode when FIF_PROMISC_IN_BSS is enabled for station
  327. * mode interface or when in monitor mode. AP mode does not need this
  328. * since it receives all in-BSS frames anyway.
  329. */
  330. if (sc->sc_ah->is_monitoring)
  331. rfilt |= ATH9K_RX_FILTER_PROM;
  332. if ((sc->cur_chan->rxfilter & FIF_CONTROL) ||
  333. sc->sc_ah->dynack.enabled)
  334. rfilt |= ATH9K_RX_FILTER_CONTROL;
  335. if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) &&
  336. (sc->cur_chan->nvifs <= 1) &&
  337. !(sc->cur_chan->rxfilter & FIF_BCN_PRBRESP_PROMISC))
  338. rfilt |= ATH9K_RX_FILTER_MYBEACON;
  339. else
  340. rfilt |= ATH9K_RX_FILTER_BEACON;
  341. if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
  342. (sc->cur_chan->rxfilter & FIF_PSPOLL))
  343. rfilt |= ATH9K_RX_FILTER_PSPOLL;
  344. if (sc->cur_chandef.width != NL80211_CHAN_WIDTH_20_NOHT)
  345. rfilt |= ATH9K_RX_FILTER_COMP_BAR;
  346. if (sc->cur_chan->nvifs > 1 || (sc->cur_chan->rxfilter & FIF_OTHER_BSS)) {
  347. /* This is needed for older chips */
  348. if (sc->sc_ah->hw_version.macVersion <= AR_SREV_VERSION_9160)
  349. rfilt |= ATH9K_RX_FILTER_PROM;
  350. rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL;
  351. }
  352. if (AR_SREV_9550(sc->sc_ah) || AR_SREV_9531(sc->sc_ah) ||
  353. AR_SREV_9561(sc->sc_ah))
  354. rfilt |= ATH9K_RX_FILTER_4ADDRESS;
  355. if (ath9k_is_chanctx_enabled() &&
  356. test_bit(ATH_OP_SCANNING, &common->op_flags))
  357. rfilt |= ATH9K_RX_FILTER_BEACON;
  358. spin_unlock_bh(&sc->chan_lock);
  359. return rfilt;
  360. }
  361. void ath_startrecv(struct ath_softc *sc)
  362. {
  363. struct ath_hw *ah = sc->sc_ah;
  364. struct ath_rxbuf *bf, *tbf;
  365. if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
  366. ath_edma_start_recv(sc);
  367. return;
  368. }
  369. if (list_empty(&sc->rx.rxbuf))
  370. goto start_recv;
  371. sc->rx.buf_hold = NULL;
  372. sc->rx.rxlink = NULL;
  373. list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
  374. ath_rx_buf_link(sc, bf, false);
  375. }
  376. /* We could have deleted elements so the list may be empty now */
  377. if (list_empty(&sc->rx.rxbuf))
  378. goto start_recv;
  379. bf = list_first_entry(&sc->rx.rxbuf, struct ath_rxbuf, list);
  380. ath9k_hw_putrxbuf(ah, bf->bf_daddr);
  381. ath9k_hw_rxena(ah);
  382. start_recv:
  383. ath_opmode_init(sc);
  384. ath9k_hw_startpcureceive(ah, sc->cur_chan->offchannel);
  385. }
  386. static void ath_flushrecv(struct ath_softc *sc)
  387. {
  388. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  389. ath_rx_tasklet(sc, 1, true);
  390. ath_rx_tasklet(sc, 1, false);
  391. }
  392. bool ath_stoprecv(struct ath_softc *sc)
  393. {
  394. struct ath_hw *ah = sc->sc_ah;
  395. bool stopped, reset = false;
  396. ath9k_hw_abortpcurecv(ah);
  397. ath9k_hw_setrxfilter(ah, 0);
  398. stopped = ath9k_hw_stopdmarecv(ah, &reset);
  399. ath_flushrecv(sc);
  400. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
  401. ath_edma_stop_recv(sc);
  402. else
  403. sc->rx.rxlink = NULL;
  404. if (!(ah->ah_flags & AH_UNPLUGGED) &&
  405. unlikely(!stopped)) {
  406. ath_err(ath9k_hw_common(sc->sc_ah),
  407. "Could not stop RX, we could be "
  408. "confusing the DMA engine when we start RX up\n");
  409. ATH_DBG_WARN_ON_ONCE(!stopped);
  410. }
  411. return stopped && !reset;
  412. }
  413. static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb)
  414. {
  415. /* Check whether the Beacon frame has DTIM indicating buffered bc/mc */
  416. struct ieee80211_mgmt *mgmt;
  417. u8 *pos, *end, id, elen;
  418. struct ieee80211_tim_ie *tim;
  419. mgmt = (struct ieee80211_mgmt *)skb->data;
  420. pos = mgmt->u.beacon.variable;
  421. end = skb->data + skb->len;
  422. while (pos + 2 < end) {
  423. id = *pos++;
  424. elen = *pos++;
  425. if (pos + elen > end)
  426. break;
  427. if (id == WLAN_EID_TIM) {
  428. if (elen < sizeof(*tim))
  429. break;
  430. tim = (struct ieee80211_tim_ie *) pos;
  431. if (tim->dtim_count != 0)
  432. break;
  433. return tim->bitmap_ctrl & 0x01;
  434. }
  435. pos += elen;
  436. }
  437. return false;
  438. }
  439. static void ath_rx_ps_beacon(struct ath_softc *sc, struct sk_buff *skb)
  440. {
  441. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  442. bool skip_beacon = false;
  443. if (skb->len < 24 + 8 + 2 + 2)
  444. return;
  445. sc->ps_flags &= ~PS_WAIT_FOR_BEACON;
  446. if (sc->ps_flags & PS_BEACON_SYNC) {
  447. sc->ps_flags &= ~PS_BEACON_SYNC;
  448. ath_dbg(common, PS,
  449. "Reconfigure beacon timers based on synchronized timestamp\n");
  450. #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
  451. if (ath9k_is_chanctx_enabled()) {
  452. if (sc->cur_chan == &sc->offchannel.chan)
  453. skip_beacon = true;
  454. }
  455. #endif
  456. if (!skip_beacon &&
  457. !(WARN_ON_ONCE(sc->cur_chan->beacon.beacon_interval == 0)))
  458. ath9k_set_beacon(sc);
  459. ath9k_p2p_beacon_sync(sc);
  460. }
  461. if (ath_beacon_dtim_pending_cab(skb)) {
  462. /*
  463. * Remain awake waiting for buffered broadcast/multicast
  464. * frames. If the last broadcast/multicast frame is not
  465. * received properly, the next beacon frame will work as
  466. * a backup trigger for returning into NETWORK SLEEP state,
  467. * so we are waiting for it as well.
  468. */
  469. ath_dbg(common, PS,
  470. "Received DTIM beacon indicating buffered broadcast/multicast frame(s)\n");
  471. sc->ps_flags |= PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON;
  472. return;
  473. }
  474. if (sc->ps_flags & PS_WAIT_FOR_CAB) {
  475. /*
  476. * This can happen if a broadcast frame is dropped or the AP
  477. * fails to send a frame indicating that all CAB frames have
  478. * been delivered.
  479. */
  480. sc->ps_flags &= ~PS_WAIT_FOR_CAB;
  481. ath_dbg(common, PS, "PS wait for CAB frames timed out\n");
  482. }
  483. }
  484. static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb, bool mybeacon)
  485. {
  486. struct ieee80211_hdr *hdr;
  487. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  488. hdr = (struct ieee80211_hdr *)skb->data;
  489. /* Process Beacon and CAB receive in PS state */
  490. if (((sc->ps_flags & PS_WAIT_FOR_BEACON) || ath9k_check_auto_sleep(sc))
  491. && mybeacon) {
  492. ath_rx_ps_beacon(sc, skb);
  493. } else if ((sc->ps_flags & PS_WAIT_FOR_CAB) &&
  494. (ieee80211_is_data(hdr->frame_control) ||
  495. ieee80211_is_action(hdr->frame_control)) &&
  496. is_multicast_ether_addr(hdr->addr1) &&
  497. !ieee80211_has_moredata(hdr->frame_control)) {
  498. /*
  499. * No more broadcast/multicast frames to be received at this
  500. * point.
  501. */
  502. sc->ps_flags &= ~(PS_WAIT_FOR_CAB | PS_WAIT_FOR_BEACON);
  503. ath_dbg(common, PS,
  504. "All PS CAB frames received, back to sleep\n");
  505. } else if ((sc->ps_flags & PS_WAIT_FOR_PSPOLL_DATA) &&
  506. !is_multicast_ether_addr(hdr->addr1) &&
  507. !ieee80211_has_morefrags(hdr->frame_control)) {
  508. sc->ps_flags &= ~PS_WAIT_FOR_PSPOLL_DATA;
  509. ath_dbg(common, PS,
  510. "Going back to sleep after having received PS-Poll data (0x%lx)\n",
  511. sc->ps_flags & (PS_WAIT_FOR_BEACON |
  512. PS_WAIT_FOR_CAB |
  513. PS_WAIT_FOR_PSPOLL_DATA |
  514. PS_WAIT_FOR_TX_ACK));
  515. }
  516. }
  517. static bool ath_edma_get_buffers(struct ath_softc *sc,
  518. enum ath9k_rx_qtype qtype,
  519. struct ath_rx_status *rs,
  520. struct ath_rxbuf **dest)
  521. {
  522. struct ath_rx_edma *rx_edma = &sc->rx.rx_edma[qtype];
  523. struct ath_hw *ah = sc->sc_ah;
  524. struct ath_common *common = ath9k_hw_common(ah);
  525. struct sk_buff *skb;
  526. struct ath_rxbuf *bf;
  527. int ret;
  528. skb = skb_peek(&rx_edma->rx_fifo);
  529. if (!skb)
  530. return false;
  531. bf = SKB_CB_ATHBUF(skb);
  532. BUG_ON(!bf);
  533. dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
  534. common->rx_bufsize, DMA_FROM_DEVICE);
  535. ret = ath9k_hw_process_rxdesc_edma(ah, rs, skb->data);
  536. if (ret == -EINPROGRESS) {
  537. /*let device gain the buffer again*/
  538. dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
  539. common->rx_bufsize, DMA_FROM_DEVICE);
  540. return false;
  541. }
  542. __skb_unlink(skb, &rx_edma->rx_fifo);
  543. if (ret == -EINVAL) {
  544. /* corrupt descriptor, skip this one and the following one */
  545. list_add_tail(&bf->list, &sc->rx.rxbuf);
  546. ath_rx_edma_buf_link(sc, qtype);
  547. skb = skb_peek(&rx_edma->rx_fifo);
  548. if (skb) {
  549. bf = SKB_CB_ATHBUF(skb);
  550. BUG_ON(!bf);
  551. __skb_unlink(skb, &rx_edma->rx_fifo);
  552. list_add_tail(&bf->list, &sc->rx.rxbuf);
  553. ath_rx_edma_buf_link(sc, qtype);
  554. }
  555. bf = NULL;
  556. }
  557. *dest = bf;
  558. return true;
  559. }
  560. static struct ath_rxbuf *ath_edma_get_next_rx_buf(struct ath_softc *sc,
  561. struct ath_rx_status *rs,
  562. enum ath9k_rx_qtype qtype)
  563. {
  564. struct ath_rxbuf *bf = NULL;
  565. while (ath_edma_get_buffers(sc, qtype, rs, &bf)) {
  566. if (!bf)
  567. continue;
  568. return bf;
  569. }
  570. return NULL;
  571. }
  572. static struct ath_rxbuf *ath_get_next_rx_buf(struct ath_softc *sc,
  573. struct ath_rx_status *rs)
  574. {
  575. struct ath_hw *ah = sc->sc_ah;
  576. struct ath_common *common = ath9k_hw_common(ah);
  577. struct ath_desc *ds;
  578. struct ath_rxbuf *bf;
  579. int ret;
  580. if (list_empty(&sc->rx.rxbuf)) {
  581. sc->rx.rxlink = NULL;
  582. return NULL;
  583. }
  584. bf = list_first_entry(&sc->rx.rxbuf, struct ath_rxbuf, list);
  585. if (bf == sc->rx.buf_hold)
  586. return NULL;
  587. ds = bf->bf_desc;
  588. /*
  589. * Must provide the virtual address of the current
  590. * descriptor, the physical address, and the virtual
  591. * address of the next descriptor in the h/w chain.
  592. * This allows the HAL to look ahead to see if the
  593. * hardware is done with a descriptor by checking the
  594. * done bit in the following descriptor and the address
  595. * of the current descriptor the DMA engine is working
  596. * on. All this is necessary because of our use of
  597. * a self-linked list to avoid rx overruns.
  598. */
  599. ret = ath9k_hw_rxprocdesc(ah, ds, rs);
  600. if (ret == -EINPROGRESS) {
  601. struct ath_rx_status trs;
  602. struct ath_rxbuf *tbf;
  603. struct ath_desc *tds;
  604. memset(&trs, 0, sizeof(trs));
  605. if (list_is_last(&bf->list, &sc->rx.rxbuf)) {
  606. sc->rx.rxlink = NULL;
  607. return NULL;
  608. }
  609. tbf = list_entry(bf->list.next, struct ath_rxbuf, list);
  610. /*
  611. * On some hardware the descriptor status words could
  612. * get corrupted, including the done bit. Because of
  613. * this, check if the next descriptor's done bit is
  614. * set or not.
  615. *
  616. * If the next descriptor's done bit is set, the current
  617. * descriptor has been corrupted. Force s/w to discard
  618. * this descriptor and continue...
  619. */
  620. tds = tbf->bf_desc;
  621. ret = ath9k_hw_rxprocdesc(ah, tds, &trs);
  622. if (ret == -EINPROGRESS)
  623. return NULL;
  624. /*
  625. * Re-check previous descriptor, in case it has been filled
  626. * in the mean time.
  627. */
  628. ret = ath9k_hw_rxprocdesc(ah, ds, rs);
  629. if (ret == -EINPROGRESS) {
  630. /*
  631. * mark descriptor as zero-length and set the 'more'
  632. * flag to ensure that both buffers get discarded
  633. */
  634. rs->rs_datalen = 0;
  635. rs->rs_more = true;
  636. }
  637. }
  638. list_del(&bf->list);
  639. if (!bf->bf_mpdu)
  640. return bf;
  641. /*
  642. * Synchronize the DMA transfer with CPU before
  643. * 1. accessing the frame
  644. * 2. requeueing the same buffer to h/w
  645. */
  646. dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
  647. common->rx_bufsize,
  648. DMA_FROM_DEVICE);
  649. return bf;
  650. }
  651. static void ath9k_process_tsf(struct ath_rx_status *rs,
  652. struct ieee80211_rx_status *rxs,
  653. u64 tsf)
  654. {
  655. u32 tsf_lower = tsf & 0xffffffff;
  656. rxs->mactime = (tsf & ~0xffffffffULL) | rs->rs_tstamp;
  657. if (rs->rs_tstamp > tsf_lower &&
  658. unlikely(rs->rs_tstamp - tsf_lower > 0x10000000))
  659. rxs->mactime -= 0x100000000ULL;
  660. if (rs->rs_tstamp < tsf_lower &&
  661. unlikely(tsf_lower - rs->rs_tstamp > 0x10000000))
  662. rxs->mactime += 0x100000000ULL;
  663. }
  664. /*
  665. * For Decrypt or Demic errors, we only mark packet status here and always push
  666. * up the frame up to let mac80211 handle the actual error case, be it no
  667. * decryption key or real decryption error. This let us keep statistics there.
  668. */
  669. static int ath9k_rx_skb_preprocess(struct ath_softc *sc,
  670. struct sk_buff *skb,
  671. struct ath_rx_status *rx_stats,
  672. struct ieee80211_rx_status *rx_status,
  673. bool *decrypt_error, u64 tsf)
  674. {
  675. struct ieee80211_hw *hw = sc->hw;
  676. struct ath_hw *ah = sc->sc_ah;
  677. struct ath_common *common = ath9k_hw_common(ah);
  678. struct ieee80211_hdr *hdr;
  679. bool discard_current = sc->rx.discard_next;
  680. /*
  681. * Discard corrupt descriptors which are marked in
  682. * ath_get_next_rx_buf().
  683. */
  684. if (discard_current)
  685. goto corrupt;
  686. sc->rx.discard_next = false;
  687. /*
  688. * Discard zero-length packets.
  689. */
  690. if (!rx_stats->rs_datalen) {
  691. RX_STAT_INC(rx_len_err);
  692. goto corrupt;
  693. }
  694. /*
  695. * rs_status follows rs_datalen so if rs_datalen is too large
  696. * we can take a hint that hardware corrupted it, so ignore
  697. * those frames.
  698. */
  699. if (rx_stats->rs_datalen > (common->rx_bufsize - ah->caps.rx_status_len)) {
  700. RX_STAT_INC(rx_len_err);
  701. goto corrupt;
  702. }
  703. /* Only use status info from the last fragment */
  704. if (rx_stats->rs_more)
  705. return 0;
  706. /*
  707. * Return immediately if the RX descriptor has been marked
  708. * as corrupt based on the various error bits.
  709. *
  710. * This is different from the other corrupt descriptor
  711. * condition handled above.
  712. */
  713. if (rx_stats->rs_status & ATH9K_RXERR_CORRUPT_DESC)
  714. goto corrupt;
  715. hdr = (struct ieee80211_hdr *) (skb->data + ah->caps.rx_status_len);
  716. ath9k_process_tsf(rx_stats, rx_status, tsf);
  717. ath_debug_stat_rx(sc, rx_stats);
  718. /*
  719. * Process PHY errors and return so that the packet
  720. * can be dropped.
  721. */
  722. if (rx_stats->rs_status & ATH9K_RXERR_PHY) {
  723. ath9k_dfs_process_phyerr(sc, hdr, rx_stats, rx_status->mactime);
  724. if (ath_cmn_process_fft(&sc->spec_priv, hdr, rx_stats, rx_status->mactime))
  725. RX_STAT_INC(rx_spectral);
  726. return -EINVAL;
  727. }
  728. /*
  729. * everything but the rate is checked here, the rate check is done
  730. * separately to avoid doing two lookups for a rate for each frame.
  731. */
  732. spin_lock_bh(&sc->chan_lock);
  733. if (!ath9k_cmn_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error,
  734. sc->cur_chan->rxfilter)) {
  735. spin_unlock_bh(&sc->chan_lock);
  736. return -EINVAL;
  737. }
  738. spin_unlock_bh(&sc->chan_lock);
  739. if (ath_is_mybeacon(common, hdr)) {
  740. RX_STAT_INC(rx_beacons);
  741. rx_stats->is_mybeacon = true;
  742. }
  743. /*
  744. * This shouldn't happen, but have a safety check anyway.
  745. */
  746. if (WARN_ON(!ah->curchan))
  747. return -EINVAL;
  748. if (ath9k_cmn_process_rate(common, hw, rx_stats, rx_status)) {
  749. /*
  750. * No valid hardware bitrate found -- we should not get here
  751. * because hardware has already validated this frame as OK.
  752. */
  753. ath_dbg(common, ANY, "unsupported hw bitrate detected 0x%02x using 1 Mbit\n",
  754. rx_stats->rs_rate);
  755. RX_STAT_INC(rx_rate_err);
  756. return -EINVAL;
  757. }
  758. if (ath9k_is_chanctx_enabled()) {
  759. if (rx_stats->is_mybeacon)
  760. ath_chanctx_beacon_recv_ev(sc,
  761. ATH_CHANCTX_EVENT_BEACON_RECEIVED);
  762. }
  763. ath9k_cmn_process_rssi(common, hw, rx_stats, rx_status);
  764. rx_status->band = ah->curchan->chan->band;
  765. rx_status->freq = ah->curchan->chan->center_freq;
  766. rx_status->antenna = rx_stats->rs_antenna;
  767. rx_status->flag |= RX_FLAG_MACTIME_END;
  768. #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
  769. if (ieee80211_is_data_present(hdr->frame_control) &&
  770. !ieee80211_is_qos_nullfunc(hdr->frame_control))
  771. sc->rx.num_pkts++;
  772. #endif
  773. return 0;
  774. corrupt:
  775. sc->rx.discard_next = rx_stats->rs_more;
  776. return -EINVAL;
  777. }
  778. /*
  779. * Run the LNA combining algorithm only in these cases:
  780. *
  781. * Standalone WLAN cards with both LNA/Antenna diversity
  782. * enabled in the EEPROM.
  783. *
  784. * WLAN+BT cards which are in the supported card list
  785. * in ath_pci_id_table and the user has loaded the
  786. * driver with "bt_ant_diversity" set to true.
  787. */
  788. static void ath9k_antenna_check(struct ath_softc *sc,
  789. struct ath_rx_status *rs)
  790. {
  791. struct ath_hw *ah = sc->sc_ah;
  792. struct ath9k_hw_capabilities *pCap = &ah->caps;
  793. struct ath_common *common = ath9k_hw_common(ah);
  794. if (!(ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB))
  795. return;
  796. /*
  797. * Change the default rx antenna if rx diversity
  798. * chooses the other antenna 3 times in a row.
  799. */
  800. if (sc->rx.defant != rs->rs_antenna) {
  801. if (++sc->rx.rxotherant >= 3)
  802. ath_setdefantenna(sc, rs->rs_antenna);
  803. } else {
  804. sc->rx.rxotherant = 0;
  805. }
  806. if (pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV) {
  807. if (common->bt_ant_diversity)
  808. ath_ant_comb_scan(sc, rs);
  809. } else {
  810. ath_ant_comb_scan(sc, rs);
  811. }
  812. }
  813. static void ath9k_apply_ampdu_details(struct ath_softc *sc,
  814. struct ath_rx_status *rs, struct ieee80211_rx_status *rxs)
  815. {
  816. if (rs->rs_isaggr) {
  817. rxs->flag |= RX_FLAG_AMPDU_DETAILS | RX_FLAG_AMPDU_LAST_KNOWN;
  818. rxs->ampdu_reference = sc->rx.ampdu_ref;
  819. if (!rs->rs_moreaggr) {
  820. rxs->flag |= RX_FLAG_AMPDU_IS_LAST;
  821. sc->rx.ampdu_ref++;
  822. }
  823. if (rs->rs_flags & ATH9K_RX_DELIM_CRC_PRE)
  824. rxs->flag |= RX_FLAG_AMPDU_DELIM_CRC_ERROR;
  825. }
  826. }
  827. int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
  828. {
  829. struct ath_rxbuf *bf;
  830. struct sk_buff *skb = NULL, *requeue_skb, *hdr_skb;
  831. struct ieee80211_rx_status *rxs;
  832. struct ath_hw *ah = sc->sc_ah;
  833. struct ath_common *common = ath9k_hw_common(ah);
  834. struct ieee80211_hw *hw = sc->hw;
  835. int retval;
  836. struct ath_rx_status rs;
  837. enum ath9k_rx_qtype qtype;
  838. bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
  839. int dma_type;
  840. u64 tsf = 0;
  841. unsigned long flags;
  842. dma_addr_t new_buf_addr;
  843. unsigned int budget = 512;
  844. struct ieee80211_hdr *hdr;
  845. if (edma)
  846. dma_type = DMA_BIDIRECTIONAL;
  847. else
  848. dma_type = DMA_FROM_DEVICE;
  849. qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP;
  850. tsf = ath9k_hw_gettsf64(ah);
  851. do {
  852. bool decrypt_error = false;
  853. memset(&rs, 0, sizeof(rs));
  854. if (edma)
  855. bf = ath_edma_get_next_rx_buf(sc, &rs, qtype);
  856. else
  857. bf = ath_get_next_rx_buf(sc, &rs);
  858. if (!bf)
  859. break;
  860. skb = bf->bf_mpdu;
  861. if (!skb)
  862. continue;
  863. /*
  864. * Take frame header from the first fragment and RX status from
  865. * the last one.
  866. */
  867. if (sc->rx.frag)
  868. hdr_skb = sc->rx.frag;
  869. else
  870. hdr_skb = skb;
  871. rxs = IEEE80211_SKB_RXCB(hdr_skb);
  872. memset(rxs, 0, sizeof(struct ieee80211_rx_status));
  873. retval = ath9k_rx_skb_preprocess(sc, hdr_skb, &rs, rxs,
  874. &decrypt_error, tsf);
  875. if (retval)
  876. goto requeue_drop_frag;
  877. /* Ensure we always have an skb to requeue once we are done
  878. * processing the current buffer's skb */
  879. requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC);
  880. /* If there is no memory we ignore the current RX'd frame,
  881. * tell hardware it can give us a new frame using the old
  882. * skb and put it at the tail of the sc->rx.rxbuf list for
  883. * processing. */
  884. if (!requeue_skb) {
  885. RX_STAT_INC(rx_oom_err);
  886. goto requeue_drop_frag;
  887. }
  888. /* We will now give hardware our shiny new allocated skb */
  889. new_buf_addr = dma_map_single(sc->dev, requeue_skb->data,
  890. common->rx_bufsize, dma_type);
  891. if (unlikely(dma_mapping_error(sc->dev, new_buf_addr))) {
  892. dev_kfree_skb_any(requeue_skb);
  893. goto requeue_drop_frag;
  894. }
  895. /* Unmap the frame */
  896. dma_unmap_single(sc->dev, bf->bf_buf_addr,
  897. common->rx_bufsize, dma_type);
  898. bf->bf_mpdu = requeue_skb;
  899. bf->bf_buf_addr = new_buf_addr;
  900. skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len);
  901. if (ah->caps.rx_status_len)
  902. skb_pull(skb, ah->caps.rx_status_len);
  903. if (!rs.rs_more)
  904. ath9k_cmn_rx_skb_postprocess(common, hdr_skb, &rs,
  905. rxs, decrypt_error);
  906. if (rs.rs_more) {
  907. RX_STAT_INC(rx_frags);
  908. /*
  909. * rs_more indicates chained descriptors which can be
  910. * used to link buffers together for a sort of
  911. * scatter-gather operation.
  912. */
  913. if (sc->rx.frag) {
  914. /* too many fragments - cannot handle frame */
  915. dev_kfree_skb_any(sc->rx.frag);
  916. dev_kfree_skb_any(skb);
  917. RX_STAT_INC(rx_too_many_frags_err);
  918. skb = NULL;
  919. }
  920. sc->rx.frag = skb;
  921. goto requeue;
  922. }
  923. if (sc->rx.frag) {
  924. int space = skb->len - skb_tailroom(hdr_skb);
  925. if (pskb_expand_head(hdr_skb, 0, space, GFP_ATOMIC) < 0) {
  926. dev_kfree_skb(skb);
  927. RX_STAT_INC(rx_oom_err);
  928. goto requeue_drop_frag;
  929. }
  930. sc->rx.frag = NULL;
  931. skb_copy_from_linear_data(skb, skb_put(hdr_skb, skb->len),
  932. skb->len);
  933. dev_kfree_skb_any(skb);
  934. skb = hdr_skb;
  935. }
  936. if (rxs->flag & RX_FLAG_MMIC_STRIPPED)
  937. skb_trim(skb, skb->len - 8);
  938. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  939. if ((sc->ps_flags & (PS_WAIT_FOR_BEACON |
  940. PS_WAIT_FOR_CAB |
  941. PS_WAIT_FOR_PSPOLL_DATA)) ||
  942. ath9k_check_auto_sleep(sc))
  943. ath_rx_ps(sc, skb, rs.is_mybeacon);
  944. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  945. ath9k_antenna_check(sc, &rs);
  946. ath9k_apply_ampdu_details(sc, &rs, rxs);
  947. ath_debug_rate_stats(sc, &rs, skb);
  948. hdr = (struct ieee80211_hdr *)skb->data;
  949. if (ieee80211_is_ack(hdr->frame_control))
  950. ath_dynack_sample_ack_ts(sc->sc_ah, skb, rs.rs_tstamp);
  951. ieee80211_rx(hw, skb);
  952. requeue_drop_frag:
  953. if (sc->rx.frag) {
  954. dev_kfree_skb_any(sc->rx.frag);
  955. sc->rx.frag = NULL;
  956. }
  957. requeue:
  958. list_add_tail(&bf->list, &sc->rx.rxbuf);
  959. if (!edma) {
  960. ath_rx_buf_relink(sc, bf, flush);
  961. if (!flush)
  962. ath9k_hw_rxena(ah);
  963. } else if (!flush) {
  964. ath_rx_edma_buf_link(sc, qtype);
  965. }
  966. if (!budget--)
  967. break;
  968. } while (1);
  969. if (!(ah->imask & ATH9K_INT_RXEOL)) {
  970. ah->imask |= (ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
  971. ath9k_hw_set_interrupts(ah);
  972. }
  973. return 0;
  974. }