iwl-agn-lib.c 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2010 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  19. * USA
  20. *
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #include <linux/etherdevice.h>
  30. #include <linux/kernel.h>
  31. #include <linux/module.h>
  32. #include <linux/init.h>
  33. #include <linux/sched.h>
  34. #include "iwl-dev.h"
  35. #include "iwl-core.h"
  36. #include "iwl-io.h"
  37. #include "iwl-helpers.h"
  38. #include "iwl-agn-hw.h"
  39. #include "iwl-agn.h"
  40. #include "iwl-sta.h"
  41. static inline u32 iwlagn_get_scd_ssn(struct iwlagn_tx_resp *tx_resp)
  42. {
  43. return le32_to_cpup((__le32 *)&tx_resp->status +
  44. tx_resp->frame_count) & MAX_SN;
  45. }
  46. static void iwlagn_count_tx_err_status(struct iwl_priv *priv, u16 status)
  47. {
  48. status &= TX_STATUS_MSK;
  49. switch (status) {
  50. case TX_STATUS_POSTPONE_DELAY:
  51. priv->_agn.reply_tx_stats.pp_delay++;
  52. break;
  53. case TX_STATUS_POSTPONE_FEW_BYTES:
  54. priv->_agn.reply_tx_stats.pp_few_bytes++;
  55. break;
  56. case TX_STATUS_POSTPONE_BT_PRIO:
  57. priv->_agn.reply_tx_stats.pp_bt_prio++;
  58. break;
  59. case TX_STATUS_POSTPONE_QUIET_PERIOD:
  60. priv->_agn.reply_tx_stats.pp_quiet_period++;
  61. break;
  62. case TX_STATUS_POSTPONE_CALC_TTAK:
  63. priv->_agn.reply_tx_stats.pp_calc_ttak++;
  64. break;
  65. case TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY:
  66. priv->_agn.reply_tx_stats.int_crossed_retry++;
  67. break;
  68. case TX_STATUS_FAIL_SHORT_LIMIT:
  69. priv->_agn.reply_tx_stats.short_limit++;
  70. break;
  71. case TX_STATUS_FAIL_LONG_LIMIT:
  72. priv->_agn.reply_tx_stats.long_limit++;
  73. break;
  74. case TX_STATUS_FAIL_FIFO_UNDERRUN:
  75. priv->_agn.reply_tx_stats.fifo_underrun++;
  76. break;
  77. case TX_STATUS_FAIL_DRAIN_FLOW:
  78. priv->_agn.reply_tx_stats.drain_flow++;
  79. break;
  80. case TX_STATUS_FAIL_RFKILL_FLUSH:
  81. priv->_agn.reply_tx_stats.rfkill_flush++;
  82. break;
  83. case TX_STATUS_FAIL_LIFE_EXPIRE:
  84. priv->_agn.reply_tx_stats.life_expire++;
  85. break;
  86. case TX_STATUS_FAIL_DEST_PS:
  87. priv->_agn.reply_tx_stats.dest_ps++;
  88. break;
  89. case TX_STATUS_FAIL_HOST_ABORTED:
  90. priv->_agn.reply_tx_stats.host_abort++;
  91. break;
  92. case TX_STATUS_FAIL_BT_RETRY:
  93. priv->_agn.reply_tx_stats.bt_retry++;
  94. break;
  95. case TX_STATUS_FAIL_STA_INVALID:
  96. priv->_agn.reply_tx_stats.sta_invalid++;
  97. break;
  98. case TX_STATUS_FAIL_FRAG_DROPPED:
  99. priv->_agn.reply_tx_stats.frag_drop++;
  100. break;
  101. case TX_STATUS_FAIL_TID_DISABLE:
  102. priv->_agn.reply_tx_stats.tid_disable++;
  103. break;
  104. case TX_STATUS_FAIL_FIFO_FLUSHED:
  105. priv->_agn.reply_tx_stats.fifo_flush++;
  106. break;
  107. case TX_STATUS_FAIL_INSUFFICIENT_CF_POLL:
  108. priv->_agn.reply_tx_stats.insuff_cf_poll++;
  109. break;
  110. case TX_STATUS_FAIL_PASSIVE_NO_RX:
  111. priv->_agn.reply_tx_stats.fail_hw_drop++;
  112. break;
  113. case TX_STATUS_FAIL_NO_BEACON_ON_RADAR:
  114. priv->_agn.reply_tx_stats.sta_color_mismatch++;
  115. break;
  116. default:
  117. priv->_agn.reply_tx_stats.unknown++;
  118. break;
  119. }
  120. }
  121. static void iwlagn_count_agg_tx_err_status(struct iwl_priv *priv, u16 status)
  122. {
  123. status &= AGG_TX_STATUS_MSK;
  124. switch (status) {
  125. case AGG_TX_STATE_UNDERRUN_MSK:
  126. priv->_agn.reply_agg_tx_stats.underrun++;
  127. break;
  128. case AGG_TX_STATE_BT_PRIO_MSK:
  129. priv->_agn.reply_agg_tx_stats.bt_prio++;
  130. break;
  131. case AGG_TX_STATE_FEW_BYTES_MSK:
  132. priv->_agn.reply_agg_tx_stats.few_bytes++;
  133. break;
  134. case AGG_TX_STATE_ABORT_MSK:
  135. priv->_agn.reply_agg_tx_stats.abort++;
  136. break;
  137. case AGG_TX_STATE_LAST_SENT_TTL_MSK:
  138. priv->_agn.reply_agg_tx_stats.last_sent_ttl++;
  139. break;
  140. case AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK:
  141. priv->_agn.reply_agg_tx_stats.last_sent_try++;
  142. break;
  143. case AGG_TX_STATE_LAST_SENT_BT_KILL_MSK:
  144. priv->_agn.reply_agg_tx_stats.last_sent_bt_kill++;
  145. break;
  146. case AGG_TX_STATE_SCD_QUERY_MSK:
  147. priv->_agn.reply_agg_tx_stats.scd_query++;
  148. break;
  149. case AGG_TX_STATE_TEST_BAD_CRC32_MSK:
  150. priv->_agn.reply_agg_tx_stats.bad_crc32++;
  151. break;
  152. case AGG_TX_STATE_RESPONSE_MSK:
  153. priv->_agn.reply_agg_tx_stats.response++;
  154. break;
  155. case AGG_TX_STATE_DUMP_TX_MSK:
  156. priv->_agn.reply_agg_tx_stats.dump_tx++;
  157. break;
  158. case AGG_TX_STATE_DELAY_TX_MSK:
  159. priv->_agn.reply_agg_tx_stats.delay_tx++;
  160. break;
  161. default:
  162. priv->_agn.reply_agg_tx_stats.unknown++;
  163. break;
  164. }
  165. }
  166. static void iwlagn_set_tx_status(struct iwl_priv *priv,
  167. struct ieee80211_tx_info *info,
  168. struct iwlagn_tx_resp *tx_resp,
  169. int txq_id, bool is_agg)
  170. {
  171. u16 status = le16_to_cpu(tx_resp->status.status);
  172. info->status.rates[0].count = tx_resp->failure_frame + 1;
  173. if (is_agg)
  174. info->flags &= ~IEEE80211_TX_CTL_AMPDU;
  175. info->flags |= iwl_tx_status_to_mac80211(status);
  176. iwlagn_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags),
  177. info);
  178. if (!iwl_is_tx_success(status))
  179. iwlagn_count_tx_err_status(priv, status);
  180. IWL_DEBUG_TX_REPLY(priv, "TXQ %d status %s (0x%08x) rate_n_flags "
  181. "0x%x retries %d\n",
  182. txq_id,
  183. iwl_get_tx_fail_reason(status), status,
  184. le32_to_cpu(tx_resp->rate_n_flags),
  185. tx_resp->failure_frame);
  186. }
  187. #ifdef CONFIG_IWLWIFI_DEBUG
  188. #define AGG_TX_STATE_FAIL(x) case AGG_TX_STATE_ ## x: return #x
  189. const char *iwl_get_agg_tx_fail_reason(u16 status)
  190. {
  191. status &= AGG_TX_STATUS_MSK;
  192. switch (status) {
  193. case AGG_TX_STATE_TRANSMITTED:
  194. return "SUCCESS";
  195. AGG_TX_STATE_FAIL(UNDERRUN_MSK);
  196. AGG_TX_STATE_FAIL(BT_PRIO_MSK);
  197. AGG_TX_STATE_FAIL(FEW_BYTES_MSK);
  198. AGG_TX_STATE_FAIL(ABORT_MSK);
  199. AGG_TX_STATE_FAIL(LAST_SENT_TTL_MSK);
  200. AGG_TX_STATE_FAIL(LAST_SENT_TRY_CNT_MSK);
  201. AGG_TX_STATE_FAIL(LAST_SENT_BT_KILL_MSK);
  202. AGG_TX_STATE_FAIL(SCD_QUERY_MSK);
  203. AGG_TX_STATE_FAIL(TEST_BAD_CRC32_MSK);
  204. AGG_TX_STATE_FAIL(RESPONSE_MSK);
  205. AGG_TX_STATE_FAIL(DUMP_TX_MSK);
  206. AGG_TX_STATE_FAIL(DELAY_TX_MSK);
  207. }
  208. return "UNKNOWN";
  209. }
  210. #endif /* CONFIG_IWLWIFI_DEBUG */
  211. static int iwlagn_tx_status_reply_tx(struct iwl_priv *priv,
  212. struct iwl_ht_agg *agg,
  213. struct iwlagn_tx_resp *tx_resp,
  214. int txq_id, u16 start_idx)
  215. {
  216. u16 status;
  217. struct agg_tx_status *frame_status = &tx_resp->status;
  218. struct ieee80211_hdr *hdr = NULL;
  219. int i, sh, idx;
  220. u16 seq;
  221. if (agg->wait_for_ba)
  222. IWL_DEBUG_TX_REPLY(priv, "got tx response w/o block-ack\n");
  223. agg->frame_count = tx_resp->frame_count;
  224. agg->start_idx = start_idx;
  225. agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
  226. agg->bitmap = 0;
  227. /* # frames attempted by Tx command */
  228. if (agg->frame_count == 1) {
  229. /* Only one frame was attempted; no block-ack will arrive */
  230. idx = start_idx;
  231. IWL_DEBUG_TX_REPLY(priv, "FrameCnt = %d, StartIdx=%d idx=%d\n",
  232. agg->frame_count, agg->start_idx, idx);
  233. iwlagn_set_tx_status(priv,
  234. IEEE80211_SKB_CB(
  235. priv->txq[txq_id].txb[idx].skb),
  236. tx_resp, txq_id, true);
  237. agg->wait_for_ba = 0;
  238. } else {
  239. /* Two or more frames were attempted; expect block-ack */
  240. u64 bitmap = 0;
  241. /*
  242. * Start is the lowest frame sent. It may not be the first
  243. * frame in the batch; we figure this out dynamically during
  244. * the following loop.
  245. */
  246. int start = agg->start_idx;
  247. /* Construct bit-map of pending frames within Tx window */
  248. for (i = 0; i < agg->frame_count; i++) {
  249. u16 sc;
  250. status = le16_to_cpu(frame_status[i].status);
  251. seq = le16_to_cpu(frame_status[i].sequence);
  252. idx = SEQ_TO_INDEX(seq);
  253. txq_id = SEQ_TO_QUEUE(seq);
  254. if (status & AGG_TX_STATUS_MSK)
  255. iwlagn_count_agg_tx_err_status(priv, status);
  256. if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
  257. AGG_TX_STATE_ABORT_MSK))
  258. continue;
  259. IWL_DEBUG_TX_REPLY(priv, "FrameCnt = %d, txq_id=%d idx=%d\n",
  260. agg->frame_count, txq_id, idx);
  261. IWL_DEBUG_TX_REPLY(priv, "status %s (0x%08x), "
  262. "try-count (0x%08x)\n",
  263. iwl_get_agg_tx_fail_reason(status),
  264. status & AGG_TX_STATUS_MSK,
  265. status & AGG_TX_TRY_MSK);
  266. hdr = iwl_tx_queue_get_hdr(priv, txq_id, idx);
  267. if (!hdr) {
  268. IWL_ERR(priv,
  269. "BUG_ON idx doesn't point to valid skb"
  270. " idx=%d, txq_id=%d\n", idx, txq_id);
  271. return -1;
  272. }
  273. sc = le16_to_cpu(hdr->seq_ctrl);
  274. if (idx != (SEQ_TO_SN(sc) & 0xff)) {
  275. IWL_ERR(priv,
  276. "BUG_ON idx doesn't match seq control"
  277. " idx=%d, seq_idx=%d, seq=%d\n",
  278. idx, SEQ_TO_SN(sc),
  279. hdr->seq_ctrl);
  280. return -1;
  281. }
  282. IWL_DEBUG_TX_REPLY(priv, "AGG Frame i=%d idx %d seq=%d\n",
  283. i, idx, SEQ_TO_SN(sc));
  284. /*
  285. * sh -> how many frames ahead of the starting frame is
  286. * the current one?
  287. *
  288. * Note that all frames sent in the batch must be in a
  289. * 64-frame window, so this number should be in [0,63].
  290. * If outside of this window, then we've found a new
  291. * "first" frame in the batch and need to change start.
  292. */
  293. sh = idx - start;
  294. /*
  295. * If >= 64, out of window. start must be at the front
  296. * of the circular buffer, idx must be near the end of
  297. * the buffer, and idx is the new "first" frame. Shift
  298. * the indices around.
  299. */
  300. if (sh >= 64) {
  301. /* Shift bitmap by start - idx, wrapped */
  302. sh = 0x100 - idx + start;
  303. bitmap = bitmap << sh;
  304. /* Now idx is the new start so sh = 0 */
  305. sh = 0;
  306. start = idx;
  307. /*
  308. * If <= -64 then wraps the 256-pkt circular buffer
  309. * (e.g., start = 255 and idx = 0, sh should be 1)
  310. */
  311. } else if (sh <= -64) {
  312. sh = 0x100 - start + idx;
  313. /*
  314. * If < 0 but > -64, out of window. idx is before start
  315. * but not wrapped. Shift the indices around.
  316. */
  317. } else if (sh < 0) {
  318. /* Shift by how far start is ahead of idx */
  319. sh = start - idx;
  320. bitmap = bitmap << sh;
  321. /* Now idx is the new start so sh = 0 */
  322. start = idx;
  323. sh = 0;
  324. }
  325. /* Sequence number start + sh was sent in this batch */
  326. bitmap |= 1ULL << sh;
  327. IWL_DEBUG_TX_REPLY(priv, "start=%d bitmap=0x%llx\n",
  328. start, (unsigned long long)bitmap);
  329. }
  330. /*
  331. * Store the bitmap and possibly the new start, if we wrapped
  332. * the buffer above
  333. */
  334. agg->bitmap = bitmap;
  335. agg->start_idx = start;
  336. IWL_DEBUG_TX_REPLY(priv, "Frames %d start_idx=%d bitmap=0x%llx\n",
  337. agg->frame_count, agg->start_idx,
  338. (unsigned long long)agg->bitmap);
  339. if (bitmap)
  340. agg->wait_for_ba = 1;
  341. }
  342. return 0;
  343. }
  344. void iwl_check_abort_status(struct iwl_priv *priv,
  345. u8 frame_count, u32 status)
  346. {
  347. if (frame_count == 1 && status == TX_STATUS_FAIL_RFKILL_FLUSH) {
  348. IWL_ERR(priv, "Tx flush command to flush out all frames\n");
  349. if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
  350. queue_work(priv->workqueue, &priv->tx_flush);
  351. }
  352. }
  353. static void iwlagn_rx_reply_tx(struct iwl_priv *priv,
  354. struct iwl_rx_mem_buffer *rxb)
  355. {
  356. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  357. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  358. int txq_id = SEQ_TO_QUEUE(sequence);
  359. int index = SEQ_TO_INDEX(sequence);
  360. struct iwl_tx_queue *txq = &priv->txq[txq_id];
  361. struct ieee80211_tx_info *info;
  362. struct iwlagn_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
  363. u32 status = le16_to_cpu(tx_resp->status.status);
  364. int tid;
  365. int sta_id;
  366. int freed;
  367. unsigned long flags;
  368. if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) {
  369. IWL_ERR(priv, "Read index for DMA queue txq_id (%d) index %d "
  370. "is out of range [0-%d] %d %d\n", txq_id,
  371. index, txq->q.n_bd, txq->q.write_ptr,
  372. txq->q.read_ptr);
  373. return;
  374. }
  375. txq->time_stamp = jiffies;
  376. info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb);
  377. memset(&info->status, 0, sizeof(info->status));
  378. tid = (tx_resp->ra_tid & IWLAGN_TX_RES_TID_MSK) >>
  379. IWLAGN_TX_RES_TID_POS;
  380. sta_id = (tx_resp->ra_tid & IWLAGN_TX_RES_RA_MSK) >>
  381. IWLAGN_TX_RES_RA_POS;
  382. spin_lock_irqsave(&priv->sta_lock, flags);
  383. if (txq->sched_retry) {
  384. const u32 scd_ssn = iwlagn_get_scd_ssn(tx_resp);
  385. struct iwl_ht_agg *agg;
  386. agg = &priv->stations[sta_id].tid[tid].agg;
  387. /*
  388. * If the BT kill count is non-zero, we'll get this
  389. * notification again.
  390. */
  391. if (tx_resp->bt_kill_count && tx_resp->frame_count == 1 &&
  392. priv->cfg->bt_params &&
  393. priv->cfg->bt_params->advanced_bt_coexist) {
  394. IWL_WARN(priv, "receive reply tx with bt_kill\n");
  395. }
  396. iwlagn_tx_status_reply_tx(priv, agg, tx_resp, txq_id, index);
  397. /* check if BAR is needed */
  398. if ((tx_resp->frame_count == 1) && !iwl_is_tx_success(status))
  399. info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
  400. if (txq->q.read_ptr != (scd_ssn & 0xff)) {
  401. index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
  402. IWL_DEBUG_TX_REPLY(priv, "Retry scheduler reclaim "
  403. "scd_ssn=%d idx=%d txq=%d swq=%d\n",
  404. scd_ssn , index, txq_id, txq->swq_id);
  405. freed = iwlagn_tx_queue_reclaim(priv, txq_id, index);
  406. iwl_free_tfds_in_queue(priv, sta_id, tid, freed);
  407. if (priv->mac80211_registered &&
  408. (iwl_queue_space(&txq->q) > txq->q.low_mark) &&
  409. (agg->state != IWL_EMPTYING_HW_QUEUE_DELBA))
  410. iwl_wake_queue(priv, txq);
  411. }
  412. } else {
  413. iwlagn_set_tx_status(priv, info, tx_resp, txq_id, false);
  414. freed = iwlagn_tx_queue_reclaim(priv, txq_id, index);
  415. iwl_free_tfds_in_queue(priv, sta_id, tid, freed);
  416. if (priv->mac80211_registered &&
  417. (iwl_queue_space(&txq->q) > txq->q.low_mark))
  418. iwl_wake_queue(priv, txq);
  419. }
  420. iwlagn_txq_check_empty(priv, sta_id, tid, txq_id);
  421. iwl_check_abort_status(priv, tx_resp->frame_count, status);
  422. spin_unlock_irqrestore(&priv->sta_lock, flags);
  423. }
  424. void iwlagn_rx_handler_setup(struct iwl_priv *priv)
  425. {
  426. /* init calibration handlers */
  427. priv->rx_handlers[CALIBRATION_RES_NOTIFICATION] =
  428. iwlagn_rx_calib_result;
  429. priv->rx_handlers[CALIBRATION_COMPLETE_NOTIFICATION] =
  430. iwlagn_rx_calib_complete;
  431. priv->rx_handlers[REPLY_TX] = iwlagn_rx_reply_tx;
  432. /* set up notification wait support */
  433. spin_lock_init(&priv->_agn.notif_wait_lock);
  434. INIT_LIST_HEAD(&priv->_agn.notif_waits);
  435. init_waitqueue_head(&priv->_agn.notif_waitq);
  436. }
  437. void iwlagn_setup_deferred_work(struct iwl_priv *priv)
  438. {
  439. /* in agn, the tx power calibration is done in uCode */
  440. priv->disable_tx_power_cal = 1;
  441. }
  442. int iwlagn_hw_valid_rtc_data_addr(u32 addr)
  443. {
  444. return (addr >= IWLAGN_RTC_DATA_LOWER_BOUND) &&
  445. (addr < IWLAGN_RTC_DATA_UPPER_BOUND);
  446. }
  447. int iwlagn_send_tx_power(struct iwl_priv *priv)
  448. {
  449. struct iwlagn_tx_power_dbm_cmd tx_power_cmd;
  450. u8 tx_ant_cfg_cmd;
  451. if (WARN_ONCE(test_bit(STATUS_SCAN_HW, &priv->status),
  452. "TX Power requested while scanning!\n"))
  453. return -EAGAIN;
  454. /* half dBm need to multiply */
  455. tx_power_cmd.global_lmt = (s8)(2 * priv->tx_power_user_lmt);
  456. if (priv->tx_power_lmt_in_half_dbm &&
  457. priv->tx_power_lmt_in_half_dbm < tx_power_cmd.global_lmt) {
  458. /*
  459. * For the newer devices which using enhanced/extend tx power
  460. * table in EEPROM, the format is in half dBm. driver need to
  461. * convert to dBm format before report to mac80211.
  462. * By doing so, there is a possibility of 1/2 dBm resolution
  463. * lost. driver will perform "round-up" operation before
  464. * reporting, but it will cause 1/2 dBm tx power over the
  465. * regulatory limit. Perform the checking here, if the
  466. * "tx_power_user_lmt" is higher than EEPROM value (in
  467. * half-dBm format), lower the tx power based on EEPROM
  468. */
  469. tx_power_cmd.global_lmt = priv->tx_power_lmt_in_half_dbm;
  470. }
  471. tx_power_cmd.flags = IWLAGN_TX_POWER_NO_CLOSED;
  472. tx_power_cmd.srv_chan_lmt = IWLAGN_TX_POWER_AUTO;
  473. if (IWL_UCODE_API(priv->ucode_ver) == 1)
  474. tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD_V1;
  475. else
  476. tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD;
  477. return iwl_send_cmd_pdu(priv, tx_ant_cfg_cmd, sizeof(tx_power_cmd),
  478. &tx_power_cmd);
  479. }
  480. void iwlagn_temperature(struct iwl_priv *priv)
  481. {
  482. /* store temperature from correct statistics (in Celsius) */
  483. priv->temperature = le32_to_cpu((iwl_bt_statistics(priv)) ?
  484. priv->_agn.statistics_bt.general.common.temperature :
  485. priv->_agn.statistics.general.common.temperature);
  486. iwl_tt_handler(priv);
  487. }
  488. u16 iwlagn_eeprom_calib_version(struct iwl_priv *priv)
  489. {
  490. struct iwl_eeprom_calib_hdr {
  491. u8 version;
  492. u8 pa_type;
  493. u16 voltage;
  494. } *hdr;
  495. hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv,
  496. EEPROM_CALIB_ALL);
  497. return hdr->version;
  498. }
  499. /*
  500. * EEPROM
  501. */
  502. static u32 eeprom_indirect_address(const struct iwl_priv *priv, u32 address)
  503. {
  504. u16 offset = 0;
  505. if ((address & INDIRECT_ADDRESS) == 0)
  506. return address;
  507. switch (address & INDIRECT_TYPE_MSK) {
  508. case INDIRECT_HOST:
  509. offset = iwl_eeprom_query16(priv, EEPROM_LINK_HOST);
  510. break;
  511. case INDIRECT_GENERAL:
  512. offset = iwl_eeprom_query16(priv, EEPROM_LINK_GENERAL);
  513. break;
  514. case INDIRECT_REGULATORY:
  515. offset = iwl_eeprom_query16(priv, EEPROM_LINK_REGULATORY);
  516. break;
  517. case INDIRECT_TXP_LIMIT:
  518. offset = iwl_eeprom_query16(priv, EEPROM_LINK_TXP_LIMIT);
  519. break;
  520. case INDIRECT_TXP_LIMIT_SIZE:
  521. offset = iwl_eeprom_query16(priv, EEPROM_LINK_TXP_LIMIT_SIZE);
  522. break;
  523. case INDIRECT_CALIBRATION:
  524. offset = iwl_eeprom_query16(priv, EEPROM_LINK_CALIBRATION);
  525. break;
  526. case INDIRECT_PROCESS_ADJST:
  527. offset = iwl_eeprom_query16(priv, EEPROM_LINK_PROCESS_ADJST);
  528. break;
  529. case INDIRECT_OTHERS:
  530. offset = iwl_eeprom_query16(priv, EEPROM_LINK_OTHERS);
  531. break;
  532. default:
  533. IWL_ERR(priv, "illegal indirect type: 0x%X\n",
  534. address & INDIRECT_TYPE_MSK);
  535. break;
  536. }
  537. /* translate the offset from words to byte */
  538. return (address & ADDRESS_MSK) + (offset << 1);
  539. }
  540. const u8 *iwlagn_eeprom_query_addr(const struct iwl_priv *priv,
  541. size_t offset)
  542. {
  543. u32 address = eeprom_indirect_address(priv, offset);
  544. BUG_ON(address >= priv->cfg->base_params->eeprom_size);
  545. return &priv->eeprom[address];
  546. }
  547. struct iwl_mod_params iwlagn_mod_params = {
  548. .amsdu_size_8K = 1,
  549. .restart_fw = 1,
  550. .plcp_check = true,
  551. /* the rest are 0 by default */
  552. };
  553. void iwlagn_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
  554. {
  555. unsigned long flags;
  556. int i;
  557. spin_lock_irqsave(&rxq->lock, flags);
  558. INIT_LIST_HEAD(&rxq->rx_free);
  559. INIT_LIST_HEAD(&rxq->rx_used);
  560. /* Fill the rx_used queue with _all_ of the Rx buffers */
  561. for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
  562. /* In the reset function, these buffers may have been allocated
  563. * to an SKB, so we need to unmap and free potential storage */
  564. if (rxq->pool[i].page != NULL) {
  565. pci_unmap_page(priv->pci_dev, rxq->pool[i].page_dma,
  566. PAGE_SIZE << priv->hw_params.rx_page_order,
  567. PCI_DMA_FROMDEVICE);
  568. __iwl_free_pages(priv, rxq->pool[i].page);
  569. rxq->pool[i].page = NULL;
  570. }
  571. list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
  572. }
  573. for (i = 0; i < RX_QUEUE_SIZE; i++)
  574. rxq->queue[i] = NULL;
  575. /* Set us so that we have processed and used all buffers, but have
  576. * not restocked the Rx queue with fresh buffers */
  577. rxq->read = rxq->write = 0;
  578. rxq->write_actual = 0;
  579. rxq->free_count = 0;
  580. spin_unlock_irqrestore(&rxq->lock, flags);
  581. }
  582. int iwlagn_rx_init(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
  583. {
  584. u32 rb_size;
  585. const u32 rfdnlog = RX_QUEUE_SIZE_LOG; /* 256 RBDs */
  586. u32 rb_timeout = 0; /* FIXME: RX_RB_TIMEOUT for all devices? */
  587. if (!priv->cfg->base_params->use_isr_legacy)
  588. rb_timeout = RX_RB_TIMEOUT;
  589. if (priv->cfg->mod_params->amsdu_size_8K)
  590. rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K;
  591. else
  592. rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K;
  593. /* Stop Rx DMA */
  594. iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
  595. /* Reset driver's Rx queue write index */
  596. iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_WPTR_REG, 0);
  597. /* Tell device where to find RBD circular buffer in DRAM */
  598. iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_BASE_REG,
  599. (u32)(rxq->bd_dma >> 8));
  600. /* Tell device where in DRAM to update its Rx status */
  601. iwl_write_direct32(priv, FH_RSCSR_CHNL0_STTS_WPTR_REG,
  602. rxq->rb_stts_dma >> 4);
  603. /* Enable Rx DMA
  604. * FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY is set because of HW bug in
  605. * the credit mechanism in 5000 HW RX FIFO
  606. * Direct rx interrupts to hosts
  607. * Rx buffer size 4 or 8k
  608. * RB timeout 0x10
  609. * 256 RBDs
  610. */
  611. iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG,
  612. FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL |
  613. FH_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY |
  614. FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL |
  615. FH_RCSR_CHNL0_RX_CONFIG_SINGLE_FRAME_MSK |
  616. rb_size|
  617. (rb_timeout << FH_RCSR_RX_CONFIG_REG_IRQ_RBTH_POS)|
  618. (rfdnlog << FH_RCSR_RX_CONFIG_RBDCB_SIZE_POS));
  619. /* Set interrupt coalescing timer to default (2048 usecs) */
  620. iwl_write8(priv, CSR_INT_COALESCING, IWL_HOST_INT_TIMEOUT_DEF);
  621. return 0;
  622. }
  623. static void iwlagn_set_pwr_vmain(struct iwl_priv *priv)
  624. {
  625. /*
  626. * (for documentation purposes)
  627. * to set power to V_AUX, do:
  628. if (pci_pme_capable(priv->pci_dev, PCI_D3cold))
  629. iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
  630. APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
  631. ~APMG_PS_CTRL_MSK_PWR_SRC);
  632. */
  633. iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
  634. APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
  635. ~APMG_PS_CTRL_MSK_PWR_SRC);
  636. }
  637. int iwlagn_hw_nic_init(struct iwl_priv *priv)
  638. {
  639. unsigned long flags;
  640. struct iwl_rx_queue *rxq = &priv->rxq;
  641. int ret;
  642. /* nic_init */
  643. spin_lock_irqsave(&priv->lock, flags);
  644. priv->cfg->ops->lib->apm_ops.init(priv);
  645. /* Set interrupt coalescing calibration timer to default (512 usecs) */
  646. iwl_write8(priv, CSR_INT_COALESCING, IWL_HOST_INT_CALIB_TIMEOUT_DEF);
  647. spin_unlock_irqrestore(&priv->lock, flags);
  648. iwlagn_set_pwr_vmain(priv);
  649. priv->cfg->ops->lib->apm_ops.config(priv);
  650. /* Allocate the RX queue, or reset if it is already allocated */
  651. if (!rxq->bd) {
  652. ret = iwl_rx_queue_alloc(priv);
  653. if (ret) {
  654. IWL_ERR(priv, "Unable to initialize Rx queue\n");
  655. return -ENOMEM;
  656. }
  657. } else
  658. iwlagn_rx_queue_reset(priv, rxq);
  659. iwlagn_rx_replenish(priv);
  660. iwlagn_rx_init(priv, rxq);
  661. spin_lock_irqsave(&priv->lock, flags);
  662. rxq->need_update = 1;
  663. iwl_rx_queue_update_write_ptr(priv, rxq);
  664. spin_unlock_irqrestore(&priv->lock, flags);
  665. /* Allocate or reset and init all Tx and Command queues */
  666. if (!priv->txq) {
  667. ret = iwlagn_txq_ctx_alloc(priv);
  668. if (ret)
  669. return ret;
  670. } else
  671. iwlagn_txq_ctx_reset(priv);
  672. if (priv->cfg->base_params->shadow_reg_enable) {
  673. /* enable shadow regs in HW */
  674. iwl_set_bit(priv, CSR_MAC_SHADOW_REG_CTRL,
  675. 0x800FFFFF);
  676. }
  677. set_bit(STATUS_INIT, &priv->status);
  678. return 0;
  679. }
  680. /**
  681. * iwlagn_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
  682. */
  683. static inline __le32 iwlagn_dma_addr2rbd_ptr(struct iwl_priv *priv,
  684. dma_addr_t dma_addr)
  685. {
  686. return cpu_to_le32((u32)(dma_addr >> 8));
  687. }
  688. /**
  689. * iwlagn_rx_queue_restock - refill RX queue from pre-allocated pool
  690. *
  691. * If there are slots in the RX queue that need to be restocked,
  692. * and we have free pre-allocated buffers, fill the ranks as much
  693. * as we can, pulling from rx_free.
  694. *
  695. * This moves the 'write' index forward to catch up with 'processed', and
  696. * also updates the memory address in the firmware to reference the new
  697. * target buffer.
  698. */
  699. void iwlagn_rx_queue_restock(struct iwl_priv *priv)
  700. {
  701. struct iwl_rx_queue *rxq = &priv->rxq;
  702. struct list_head *element;
  703. struct iwl_rx_mem_buffer *rxb;
  704. unsigned long flags;
  705. spin_lock_irqsave(&rxq->lock, flags);
  706. while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
  707. /* The overwritten rxb must be a used one */
  708. rxb = rxq->queue[rxq->write];
  709. BUG_ON(rxb && rxb->page);
  710. /* Get next free Rx buffer, remove from free list */
  711. element = rxq->rx_free.next;
  712. rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
  713. list_del(element);
  714. /* Point to Rx buffer via next RBD in circular buffer */
  715. rxq->bd[rxq->write] = iwlagn_dma_addr2rbd_ptr(priv,
  716. rxb->page_dma);
  717. rxq->queue[rxq->write] = rxb;
  718. rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
  719. rxq->free_count--;
  720. }
  721. spin_unlock_irqrestore(&rxq->lock, flags);
  722. /* If the pre-allocated buffer pool is dropping low, schedule to
  723. * refill it */
  724. if (rxq->free_count <= RX_LOW_WATERMARK)
  725. queue_work(priv->workqueue, &priv->rx_replenish);
  726. /* If we've added more space for the firmware to place data, tell it.
  727. * Increment device's write pointer in multiples of 8. */
  728. if (rxq->write_actual != (rxq->write & ~0x7)) {
  729. spin_lock_irqsave(&rxq->lock, flags);
  730. rxq->need_update = 1;
  731. spin_unlock_irqrestore(&rxq->lock, flags);
  732. iwl_rx_queue_update_write_ptr(priv, rxq);
  733. }
  734. }
  735. /**
  736. * iwlagn_rx_replenish - Move all used packet from rx_used to rx_free
  737. *
  738. * When moving to rx_free an SKB is allocated for the slot.
  739. *
  740. * Also restock the Rx queue via iwl_rx_queue_restock.
  741. * This is called as a scheduled work item (except for during initialization)
  742. */
  743. void iwlagn_rx_allocate(struct iwl_priv *priv, gfp_t priority)
  744. {
  745. struct iwl_rx_queue *rxq = &priv->rxq;
  746. struct list_head *element;
  747. struct iwl_rx_mem_buffer *rxb;
  748. struct page *page;
  749. unsigned long flags;
  750. gfp_t gfp_mask = priority;
  751. while (1) {
  752. spin_lock_irqsave(&rxq->lock, flags);
  753. if (list_empty(&rxq->rx_used)) {
  754. spin_unlock_irqrestore(&rxq->lock, flags);
  755. return;
  756. }
  757. spin_unlock_irqrestore(&rxq->lock, flags);
  758. if (rxq->free_count > RX_LOW_WATERMARK)
  759. gfp_mask |= __GFP_NOWARN;
  760. if (priv->hw_params.rx_page_order > 0)
  761. gfp_mask |= __GFP_COMP;
  762. /* Alloc a new receive buffer */
  763. page = alloc_pages(gfp_mask, priv->hw_params.rx_page_order);
  764. if (!page) {
  765. if (net_ratelimit())
  766. IWL_DEBUG_INFO(priv, "alloc_pages failed, "
  767. "order: %d\n",
  768. priv->hw_params.rx_page_order);
  769. if ((rxq->free_count <= RX_LOW_WATERMARK) &&
  770. net_ratelimit())
  771. IWL_CRIT(priv, "Failed to alloc_pages with %s. Only %u free buffers remaining.\n",
  772. priority == GFP_ATOMIC ? "GFP_ATOMIC" : "GFP_KERNEL",
  773. rxq->free_count);
  774. /* We don't reschedule replenish work here -- we will
  775. * call the restock method and if it still needs
  776. * more buffers it will schedule replenish */
  777. return;
  778. }
  779. spin_lock_irqsave(&rxq->lock, flags);
  780. if (list_empty(&rxq->rx_used)) {
  781. spin_unlock_irqrestore(&rxq->lock, flags);
  782. __free_pages(page, priv->hw_params.rx_page_order);
  783. return;
  784. }
  785. element = rxq->rx_used.next;
  786. rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
  787. list_del(element);
  788. spin_unlock_irqrestore(&rxq->lock, flags);
  789. BUG_ON(rxb->page);
  790. rxb->page = page;
  791. /* Get physical address of the RB */
  792. rxb->page_dma = pci_map_page(priv->pci_dev, page, 0,
  793. PAGE_SIZE << priv->hw_params.rx_page_order,
  794. PCI_DMA_FROMDEVICE);
  795. /* dma address must be no more than 36 bits */
  796. BUG_ON(rxb->page_dma & ~DMA_BIT_MASK(36));
  797. /* and also 256 byte aligned! */
  798. BUG_ON(rxb->page_dma & DMA_BIT_MASK(8));
  799. spin_lock_irqsave(&rxq->lock, flags);
  800. list_add_tail(&rxb->list, &rxq->rx_free);
  801. rxq->free_count++;
  802. priv->alloc_rxb_page++;
  803. spin_unlock_irqrestore(&rxq->lock, flags);
  804. }
  805. }
  806. void iwlagn_rx_replenish(struct iwl_priv *priv)
  807. {
  808. unsigned long flags;
  809. iwlagn_rx_allocate(priv, GFP_KERNEL);
  810. spin_lock_irqsave(&priv->lock, flags);
  811. iwlagn_rx_queue_restock(priv);
  812. spin_unlock_irqrestore(&priv->lock, flags);
  813. }
  814. void iwlagn_rx_replenish_now(struct iwl_priv *priv)
  815. {
  816. iwlagn_rx_allocate(priv, GFP_ATOMIC);
  817. iwlagn_rx_queue_restock(priv);
  818. }
  819. /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
  820. * If an SKB has been detached, the POOL needs to have its SKB set to NULL
  821. * This free routine walks the list of POOL entries and if SKB is set to
  822. * non NULL it is unmapped and freed
  823. */
  824. void iwlagn_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
  825. {
  826. int i;
  827. for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
  828. if (rxq->pool[i].page != NULL) {
  829. pci_unmap_page(priv->pci_dev, rxq->pool[i].page_dma,
  830. PAGE_SIZE << priv->hw_params.rx_page_order,
  831. PCI_DMA_FROMDEVICE);
  832. __iwl_free_pages(priv, rxq->pool[i].page);
  833. rxq->pool[i].page = NULL;
  834. }
  835. }
  836. dma_free_coherent(&priv->pci_dev->dev, 4 * RX_QUEUE_SIZE, rxq->bd,
  837. rxq->bd_dma);
  838. dma_free_coherent(&priv->pci_dev->dev, sizeof(struct iwl_rb_status),
  839. rxq->rb_stts, rxq->rb_stts_dma);
  840. rxq->bd = NULL;
  841. rxq->rb_stts = NULL;
  842. }
  843. int iwlagn_rxq_stop(struct iwl_priv *priv)
  844. {
  845. /* stop Rx DMA */
  846. iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
  847. iwl_poll_direct_bit(priv, FH_MEM_RSSR_RX_STATUS_REG,
  848. FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE, 1000);
  849. return 0;
  850. }
  851. int iwlagn_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band)
  852. {
  853. int idx = 0;
  854. int band_offset = 0;
  855. /* HT rate format: mac80211 wants an MCS number, which is just LSB */
  856. if (rate_n_flags & RATE_MCS_HT_MSK) {
  857. idx = (rate_n_flags & 0xff);
  858. return idx;
  859. /* Legacy rate format, search for match in table */
  860. } else {
  861. if (band == IEEE80211_BAND_5GHZ)
  862. band_offset = IWL_FIRST_OFDM_RATE;
  863. for (idx = band_offset; idx < IWL_RATE_COUNT_LEGACY; idx++)
  864. if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
  865. return idx - band_offset;
  866. }
  867. return -1;
  868. }
  869. /* Calc max signal level (dBm) among 3 possible receivers */
  870. static inline int iwlagn_calc_rssi(struct iwl_priv *priv,
  871. struct iwl_rx_phy_res *rx_resp)
  872. {
  873. return priv->cfg->ops->utils->calc_rssi(priv, rx_resp);
  874. }
  875. static u32 iwlagn_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in)
  876. {
  877. u32 decrypt_out = 0;
  878. if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
  879. RX_RES_STATUS_STATION_FOUND)
  880. decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
  881. RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
  882. decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
  883. /* packet was not encrypted */
  884. if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
  885. RX_RES_STATUS_SEC_TYPE_NONE)
  886. return decrypt_out;
  887. /* packet was encrypted with unknown alg */
  888. if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
  889. RX_RES_STATUS_SEC_TYPE_ERR)
  890. return decrypt_out;
  891. /* decryption was not done in HW */
  892. if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
  893. RX_MPDU_RES_STATUS_DEC_DONE_MSK)
  894. return decrypt_out;
  895. switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
  896. case RX_RES_STATUS_SEC_TYPE_CCMP:
  897. /* alg is CCM: check MIC only */
  898. if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
  899. /* Bad MIC */
  900. decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
  901. else
  902. decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
  903. break;
  904. case RX_RES_STATUS_SEC_TYPE_TKIP:
  905. if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
  906. /* Bad TTAK */
  907. decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
  908. break;
  909. }
  910. /* fall through if TTAK OK */
  911. default:
  912. if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
  913. decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
  914. else
  915. decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
  916. break;
  917. }
  918. IWL_DEBUG_RX(priv, "decrypt_in:0x%x decrypt_out = 0x%x\n",
  919. decrypt_in, decrypt_out);
  920. return decrypt_out;
  921. }
  922. static void iwlagn_pass_packet_to_mac80211(struct iwl_priv *priv,
  923. struct ieee80211_hdr *hdr,
  924. u16 len,
  925. u32 ampdu_status,
  926. struct iwl_rx_mem_buffer *rxb,
  927. struct ieee80211_rx_status *stats)
  928. {
  929. struct sk_buff *skb;
  930. __le16 fc = hdr->frame_control;
  931. /* We only process data packets if the interface is open */
  932. if (unlikely(!priv->is_open)) {
  933. IWL_DEBUG_DROP_LIMIT(priv,
  934. "Dropping packet while interface is not open.\n");
  935. return;
  936. }
  937. /* In case of HW accelerated crypto and bad decryption, drop */
  938. if (!priv->cfg->mod_params->sw_crypto &&
  939. iwl_set_decrypted_flag(priv, hdr, ampdu_status, stats))
  940. return;
  941. skb = dev_alloc_skb(128);
  942. if (!skb) {
  943. IWL_ERR(priv, "dev_alloc_skb failed\n");
  944. return;
  945. }
  946. skb_add_rx_frag(skb, 0, rxb->page, (void *)hdr - rxb_addr(rxb), len);
  947. iwl_update_stats(priv, false, fc, len);
  948. memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats));
  949. ieee80211_rx(priv->hw, skb);
  950. priv->alloc_rxb_page--;
  951. rxb->page = NULL;
  952. }
  953. /* Called for REPLY_RX (legacy ABG frames), or
  954. * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
  955. void iwlagn_rx_reply_rx(struct iwl_priv *priv,
  956. struct iwl_rx_mem_buffer *rxb)
  957. {
  958. struct ieee80211_hdr *header;
  959. struct ieee80211_rx_status rx_status;
  960. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  961. struct iwl_rx_phy_res *phy_res;
  962. __le32 rx_pkt_status;
  963. struct iwl_rx_mpdu_res_start *amsdu;
  964. u32 len;
  965. u32 ampdu_status;
  966. u32 rate_n_flags;
  967. /**
  968. * REPLY_RX and REPLY_RX_MPDU_CMD are handled differently.
  969. * REPLY_RX: physical layer info is in this buffer
  970. * REPLY_RX_MPDU_CMD: physical layer info was sent in separate
  971. * command and cached in priv->last_phy_res
  972. *
  973. * Here we set up local variables depending on which command is
  974. * received.
  975. */
  976. if (pkt->hdr.cmd == REPLY_RX) {
  977. phy_res = (struct iwl_rx_phy_res *)pkt->u.raw;
  978. header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*phy_res)
  979. + phy_res->cfg_phy_cnt);
  980. len = le16_to_cpu(phy_res->byte_count);
  981. rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*phy_res) +
  982. phy_res->cfg_phy_cnt + len);
  983. ampdu_status = le32_to_cpu(rx_pkt_status);
  984. } else {
  985. if (!priv->_agn.last_phy_res_valid) {
  986. IWL_ERR(priv, "MPDU frame without cached PHY data\n");
  987. return;
  988. }
  989. phy_res = &priv->_agn.last_phy_res;
  990. amsdu = (struct iwl_rx_mpdu_res_start *)pkt->u.raw;
  991. header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*amsdu));
  992. len = le16_to_cpu(amsdu->byte_count);
  993. rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*amsdu) + len);
  994. ampdu_status = iwlagn_translate_rx_status(priv,
  995. le32_to_cpu(rx_pkt_status));
  996. }
  997. if ((unlikely(phy_res->cfg_phy_cnt > 20))) {
  998. IWL_DEBUG_DROP(priv, "dsp size out of range [0,20]: %d/n",
  999. phy_res->cfg_phy_cnt);
  1000. return;
  1001. }
  1002. if (!(rx_pkt_status & RX_RES_STATUS_NO_CRC32_ERROR) ||
  1003. !(rx_pkt_status & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
  1004. IWL_DEBUG_RX(priv, "Bad CRC or FIFO: 0x%08X.\n",
  1005. le32_to_cpu(rx_pkt_status));
  1006. return;
  1007. }
  1008. /* This will be used in several places later */
  1009. rate_n_flags = le32_to_cpu(phy_res->rate_n_flags);
  1010. /* rx_status carries information about the packet to mac80211 */
  1011. rx_status.mactime = le64_to_cpu(phy_res->timestamp);
  1012. rx_status.band = (phy_res->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
  1013. IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
  1014. rx_status.freq =
  1015. ieee80211_channel_to_frequency(le16_to_cpu(phy_res->channel),
  1016. rx_status.band);
  1017. rx_status.rate_idx =
  1018. iwlagn_hwrate_to_mac80211_idx(rate_n_flags, rx_status.band);
  1019. rx_status.flag = 0;
  1020. /* TSF isn't reliable. In order to allow smooth user experience,
  1021. * this W/A doesn't propagate it to the mac80211 */
  1022. /*rx_status.flag |= RX_FLAG_MACTIME_MPDU;*/
  1023. priv->ucode_beacon_time = le32_to_cpu(phy_res->beacon_time_stamp);
  1024. /* Find max signal strength (dBm) among 3 antenna/receiver chains */
  1025. rx_status.signal = iwlagn_calc_rssi(priv, phy_res);
  1026. iwl_dbg_log_rx_data_frame(priv, len, header);
  1027. IWL_DEBUG_STATS_LIMIT(priv, "Rssi %d, TSF %llu\n",
  1028. rx_status.signal, (unsigned long long)rx_status.mactime);
  1029. /*
  1030. * "antenna number"
  1031. *
  1032. * It seems that the antenna field in the phy flags value
  1033. * is actually a bit field. This is undefined by radiotap,
  1034. * it wants an actual antenna number but I always get "7"
  1035. * for most legacy frames I receive indicating that the
  1036. * same frame was received on all three RX chains.
  1037. *
  1038. * I think this field should be removed in favor of a
  1039. * new 802.11n radiotap field "RX chains" that is defined
  1040. * as a bitmask.
  1041. */
  1042. rx_status.antenna =
  1043. (le16_to_cpu(phy_res->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK)
  1044. >> RX_RES_PHY_FLAGS_ANTENNA_POS;
  1045. /* set the preamble flag if appropriate */
  1046. if (phy_res->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
  1047. rx_status.flag |= RX_FLAG_SHORTPRE;
  1048. /* Set up the HT phy flags */
  1049. if (rate_n_flags & RATE_MCS_HT_MSK)
  1050. rx_status.flag |= RX_FLAG_HT;
  1051. if (rate_n_flags & RATE_MCS_HT40_MSK)
  1052. rx_status.flag |= RX_FLAG_40MHZ;
  1053. if (rate_n_flags & RATE_MCS_SGI_MSK)
  1054. rx_status.flag |= RX_FLAG_SHORT_GI;
  1055. iwlagn_pass_packet_to_mac80211(priv, header, len, ampdu_status,
  1056. rxb, &rx_status);
  1057. }
  1058. /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
  1059. * This will be used later in iwl_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
  1060. void iwlagn_rx_reply_rx_phy(struct iwl_priv *priv,
  1061. struct iwl_rx_mem_buffer *rxb)
  1062. {
  1063. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1064. priv->_agn.last_phy_res_valid = true;
  1065. memcpy(&priv->_agn.last_phy_res, pkt->u.raw,
  1066. sizeof(struct iwl_rx_phy_res));
  1067. }
  1068. static int iwl_get_single_channel_for_scan(struct iwl_priv *priv,
  1069. struct ieee80211_vif *vif,
  1070. enum ieee80211_band band,
  1071. struct iwl_scan_channel *scan_ch)
  1072. {
  1073. const struct ieee80211_supported_band *sband;
  1074. u16 passive_dwell = 0;
  1075. u16 active_dwell = 0;
  1076. int added = 0;
  1077. u16 channel = 0;
  1078. sband = iwl_get_hw_mode(priv, band);
  1079. if (!sband) {
  1080. IWL_ERR(priv, "invalid band\n");
  1081. return added;
  1082. }
  1083. active_dwell = iwl_get_active_dwell_time(priv, band, 0);
  1084. passive_dwell = iwl_get_passive_dwell_time(priv, band, vif);
  1085. if (passive_dwell <= active_dwell)
  1086. passive_dwell = active_dwell + 1;
  1087. channel = iwl_get_single_channel_number(priv, band);
  1088. if (channel) {
  1089. scan_ch->channel = cpu_to_le16(channel);
  1090. scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
  1091. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  1092. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  1093. /* Set txpower levels to defaults */
  1094. scan_ch->dsp_atten = 110;
  1095. if (band == IEEE80211_BAND_5GHZ)
  1096. scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
  1097. else
  1098. scan_ch->tx_gain = ((1 << 5) | (5 << 3));
  1099. added++;
  1100. } else
  1101. IWL_ERR(priv, "no valid channel found\n");
  1102. return added;
  1103. }
  1104. static int iwl_get_channels_for_scan(struct iwl_priv *priv,
  1105. struct ieee80211_vif *vif,
  1106. enum ieee80211_band band,
  1107. u8 is_active, u8 n_probes,
  1108. struct iwl_scan_channel *scan_ch)
  1109. {
  1110. struct ieee80211_channel *chan;
  1111. const struct ieee80211_supported_band *sband;
  1112. const struct iwl_channel_info *ch_info;
  1113. u16 passive_dwell = 0;
  1114. u16 active_dwell = 0;
  1115. int added, i;
  1116. u16 channel;
  1117. sband = iwl_get_hw_mode(priv, band);
  1118. if (!sband)
  1119. return 0;
  1120. active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
  1121. passive_dwell = iwl_get_passive_dwell_time(priv, band, vif);
  1122. if (passive_dwell <= active_dwell)
  1123. passive_dwell = active_dwell + 1;
  1124. for (i = 0, added = 0; i < priv->scan_request->n_channels; i++) {
  1125. chan = priv->scan_request->channels[i];
  1126. if (chan->band != band)
  1127. continue;
  1128. channel = chan->hw_value;
  1129. scan_ch->channel = cpu_to_le16(channel);
  1130. ch_info = iwl_get_channel_info(priv, band, channel);
  1131. if (!is_channel_valid(ch_info)) {
  1132. IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
  1133. channel);
  1134. continue;
  1135. }
  1136. if (!is_active || is_channel_passive(ch_info) ||
  1137. (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN))
  1138. scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
  1139. else
  1140. scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE;
  1141. if (n_probes)
  1142. scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes);
  1143. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  1144. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  1145. /* Set txpower levels to defaults */
  1146. scan_ch->dsp_atten = 110;
  1147. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  1148. * power level:
  1149. * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
  1150. */
  1151. if (band == IEEE80211_BAND_5GHZ)
  1152. scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
  1153. else
  1154. scan_ch->tx_gain = ((1 << 5) | (5 << 3));
  1155. IWL_DEBUG_SCAN(priv, "Scanning ch=%d prob=0x%X [%s %d]\n",
  1156. channel, le32_to_cpu(scan_ch->type),
  1157. (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ?
  1158. "ACTIVE" : "PASSIVE",
  1159. (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ?
  1160. active_dwell : passive_dwell);
  1161. scan_ch++;
  1162. added++;
  1163. }
  1164. IWL_DEBUG_SCAN(priv, "total channels to scan %d\n", added);
  1165. return added;
  1166. }
  1167. int iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
  1168. {
  1169. struct iwl_host_cmd cmd = {
  1170. .id = REPLY_SCAN_CMD,
  1171. .len = sizeof(struct iwl_scan_cmd),
  1172. .flags = CMD_SIZE_HUGE,
  1173. };
  1174. struct iwl_scan_cmd *scan;
  1175. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  1176. u32 rate_flags = 0;
  1177. u16 cmd_len;
  1178. u16 rx_chain = 0;
  1179. enum ieee80211_band band;
  1180. u8 n_probes = 0;
  1181. u8 rx_ant = priv->hw_params.valid_rx_ant;
  1182. u8 rate;
  1183. bool is_active = false;
  1184. int chan_mod;
  1185. u8 active_chains;
  1186. u8 scan_tx_antennas = priv->hw_params.valid_tx_ant;
  1187. int ret;
  1188. lockdep_assert_held(&priv->mutex);
  1189. if (vif)
  1190. ctx = iwl_rxon_ctx_from_vif(vif);
  1191. if (!priv->scan_cmd) {
  1192. priv->scan_cmd = kmalloc(sizeof(struct iwl_scan_cmd) +
  1193. IWL_MAX_SCAN_SIZE, GFP_KERNEL);
  1194. if (!priv->scan_cmd) {
  1195. IWL_DEBUG_SCAN(priv,
  1196. "fail to allocate memory for scan\n");
  1197. return -ENOMEM;
  1198. }
  1199. }
  1200. scan = priv->scan_cmd;
  1201. memset(scan, 0, sizeof(struct iwl_scan_cmd) + IWL_MAX_SCAN_SIZE);
  1202. scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
  1203. scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
  1204. if (iwl_is_any_associated(priv)) {
  1205. u16 interval = 0;
  1206. u32 extra;
  1207. u32 suspend_time = 100;
  1208. u32 scan_suspend_time = 100;
  1209. IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
  1210. if (priv->is_internal_short_scan)
  1211. interval = 0;
  1212. else
  1213. interval = vif->bss_conf.beacon_int;
  1214. scan->suspend_time = 0;
  1215. scan->max_out_time = cpu_to_le32(200 * 1024);
  1216. if (!interval)
  1217. interval = suspend_time;
  1218. extra = (suspend_time / interval) << 22;
  1219. scan_suspend_time = (extra |
  1220. ((suspend_time % interval) * 1024));
  1221. scan->suspend_time = cpu_to_le32(scan_suspend_time);
  1222. IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
  1223. scan_suspend_time, interval);
  1224. }
  1225. if (priv->is_internal_short_scan) {
  1226. IWL_DEBUG_SCAN(priv, "Start internal passive scan.\n");
  1227. } else if (priv->scan_request->n_ssids) {
  1228. int i, p = 0;
  1229. IWL_DEBUG_SCAN(priv, "Kicking off active scan\n");
  1230. for (i = 0; i < priv->scan_request->n_ssids; i++) {
  1231. /* always does wildcard anyway */
  1232. if (!priv->scan_request->ssids[i].ssid_len)
  1233. continue;
  1234. scan->direct_scan[p].id = WLAN_EID_SSID;
  1235. scan->direct_scan[p].len =
  1236. priv->scan_request->ssids[i].ssid_len;
  1237. memcpy(scan->direct_scan[p].ssid,
  1238. priv->scan_request->ssids[i].ssid,
  1239. priv->scan_request->ssids[i].ssid_len);
  1240. n_probes++;
  1241. p++;
  1242. }
  1243. is_active = true;
  1244. } else
  1245. IWL_DEBUG_SCAN(priv, "Start passive scan.\n");
  1246. scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
  1247. scan->tx_cmd.sta_id = ctx->bcast_sta_id;
  1248. scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  1249. switch (priv->scan_band) {
  1250. case IEEE80211_BAND_2GHZ:
  1251. scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
  1252. chan_mod = le32_to_cpu(
  1253. priv->contexts[IWL_RXON_CTX_BSS].active.flags &
  1254. RXON_FLG_CHANNEL_MODE_MSK)
  1255. >> RXON_FLG_CHANNEL_MODE_POS;
  1256. if (chan_mod == CHANNEL_MODE_PURE_40) {
  1257. rate = IWL_RATE_6M_PLCP;
  1258. } else {
  1259. rate = IWL_RATE_1M_PLCP;
  1260. rate_flags = RATE_MCS_CCK_MSK;
  1261. }
  1262. /*
  1263. * Internal scans are passive, so we can indiscriminately set
  1264. * the BT ignore flag on 2.4 GHz since it applies to TX only.
  1265. */
  1266. if (priv->cfg->bt_params &&
  1267. priv->cfg->bt_params->advanced_bt_coexist)
  1268. scan->tx_cmd.tx_flags |= TX_CMD_FLG_IGNORE_BT;
  1269. break;
  1270. case IEEE80211_BAND_5GHZ:
  1271. rate = IWL_RATE_6M_PLCP;
  1272. break;
  1273. default:
  1274. IWL_WARN(priv, "Invalid scan band\n");
  1275. return -EIO;
  1276. }
  1277. /*
  1278. * If active scanning is requested but a certain channel is
  1279. * marked passive, we can do active scanning if we detect
  1280. * transmissions.
  1281. *
  1282. * There is an issue with some firmware versions that triggers
  1283. * a sysassert on a "good CRC threshold" of zero (== disabled),
  1284. * on a radar channel even though this means that we should NOT
  1285. * send probes.
  1286. *
  1287. * The "good CRC threshold" is the number of frames that we
  1288. * need to receive during our dwell time on a channel before
  1289. * sending out probes -- setting this to a huge value will
  1290. * mean we never reach it, but at the same time work around
  1291. * the aforementioned issue. Thus use IWL_GOOD_CRC_TH_NEVER
  1292. * here instead of IWL_GOOD_CRC_TH_DISABLED.
  1293. */
  1294. scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT :
  1295. IWL_GOOD_CRC_TH_NEVER;
  1296. band = priv->scan_band;
  1297. if (priv->cfg->scan_rx_antennas[band])
  1298. rx_ant = priv->cfg->scan_rx_antennas[band];
  1299. if (band == IEEE80211_BAND_2GHZ &&
  1300. priv->cfg->bt_params &&
  1301. priv->cfg->bt_params->advanced_bt_coexist) {
  1302. /* transmit 2.4 GHz probes only on first antenna */
  1303. scan_tx_antennas = first_antenna(scan_tx_antennas);
  1304. }
  1305. priv->scan_tx_ant[band] = iwl_toggle_tx_ant(priv, priv->scan_tx_ant[band],
  1306. scan_tx_antennas);
  1307. rate_flags |= iwl_ant_idx_to_flags(priv->scan_tx_ant[band]);
  1308. scan->tx_cmd.rate_n_flags = iwl_hw_set_rate_n_flags(rate, rate_flags);
  1309. /* In power save mode use one chain, otherwise use all chains */
  1310. if (test_bit(STATUS_POWER_PMI, &priv->status)) {
  1311. /* rx_ant has been set to all valid chains previously */
  1312. active_chains = rx_ant &
  1313. ((u8)(priv->chain_noise_data.active_chains));
  1314. if (!active_chains)
  1315. active_chains = rx_ant;
  1316. IWL_DEBUG_SCAN(priv, "chain_noise_data.active_chains: %u\n",
  1317. priv->chain_noise_data.active_chains);
  1318. rx_ant = first_antenna(active_chains);
  1319. }
  1320. if (priv->cfg->bt_params &&
  1321. priv->cfg->bt_params->advanced_bt_coexist &&
  1322. priv->bt_full_concurrent) {
  1323. /* operated as 1x1 in full concurrency mode */
  1324. rx_ant = first_antenna(rx_ant);
  1325. }
  1326. /* MIMO is not used here, but value is required */
  1327. rx_chain |= priv->hw_params.valid_rx_ant << RXON_RX_CHAIN_VALID_POS;
  1328. rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS;
  1329. rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_SEL_POS;
  1330. rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS;
  1331. scan->rx_chain = cpu_to_le16(rx_chain);
  1332. if (!priv->is_internal_short_scan) {
  1333. cmd_len = iwl_fill_probe_req(priv,
  1334. (struct ieee80211_mgmt *)scan->data,
  1335. vif->addr,
  1336. priv->scan_request->ie,
  1337. priv->scan_request->ie_len,
  1338. IWL_MAX_SCAN_SIZE - sizeof(*scan));
  1339. } else {
  1340. /* use bcast addr, will not be transmitted but must be valid */
  1341. cmd_len = iwl_fill_probe_req(priv,
  1342. (struct ieee80211_mgmt *)scan->data,
  1343. iwl_bcast_addr, NULL, 0,
  1344. IWL_MAX_SCAN_SIZE - sizeof(*scan));
  1345. }
  1346. scan->tx_cmd.len = cpu_to_le16(cmd_len);
  1347. scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK |
  1348. RXON_FILTER_BCON_AWARE_MSK);
  1349. if (priv->is_internal_short_scan) {
  1350. scan->channel_count =
  1351. iwl_get_single_channel_for_scan(priv, vif, band,
  1352. (void *)&scan->data[le16_to_cpu(
  1353. scan->tx_cmd.len)]);
  1354. } else {
  1355. scan->channel_count =
  1356. iwl_get_channels_for_scan(priv, vif, band,
  1357. is_active, n_probes,
  1358. (void *)&scan->data[le16_to_cpu(
  1359. scan->tx_cmd.len)]);
  1360. }
  1361. if (scan->channel_count == 0) {
  1362. IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
  1363. return -EIO;
  1364. }
  1365. cmd.len += le16_to_cpu(scan->tx_cmd.len) +
  1366. scan->channel_count * sizeof(struct iwl_scan_channel);
  1367. cmd.data = scan;
  1368. scan->len = cpu_to_le16(cmd.len);
  1369. /* set scan bit here for PAN params */
  1370. set_bit(STATUS_SCAN_HW, &priv->status);
  1371. if (priv->cfg->ops->hcmd->set_pan_params) {
  1372. ret = priv->cfg->ops->hcmd->set_pan_params(priv);
  1373. if (ret)
  1374. return ret;
  1375. }
  1376. ret = iwl_send_cmd_sync(priv, &cmd);
  1377. if (ret) {
  1378. clear_bit(STATUS_SCAN_HW, &priv->status);
  1379. if (priv->cfg->ops->hcmd->set_pan_params)
  1380. priv->cfg->ops->hcmd->set_pan_params(priv);
  1381. }
  1382. return ret;
  1383. }
  1384. int iwlagn_manage_ibss_station(struct iwl_priv *priv,
  1385. struct ieee80211_vif *vif, bool add)
  1386. {
  1387. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  1388. if (add)
  1389. return iwlagn_add_bssid_station(priv, vif_priv->ctx,
  1390. vif->bss_conf.bssid,
  1391. &vif_priv->ibss_bssid_sta_id);
  1392. return iwl_remove_station(priv, vif_priv->ibss_bssid_sta_id,
  1393. vif->bss_conf.bssid);
  1394. }
  1395. void iwl_free_tfds_in_queue(struct iwl_priv *priv,
  1396. int sta_id, int tid, int freed)
  1397. {
  1398. lockdep_assert_held(&priv->sta_lock);
  1399. if (priv->stations[sta_id].tid[tid].tfds_in_queue >= freed)
  1400. priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
  1401. else {
  1402. IWL_DEBUG_TX(priv, "free more than tfds_in_queue (%u:%d)\n",
  1403. priv->stations[sta_id].tid[tid].tfds_in_queue,
  1404. freed);
  1405. priv->stations[sta_id].tid[tid].tfds_in_queue = 0;
  1406. }
  1407. }
  1408. #define IWL_FLUSH_WAIT_MS 2000
  1409. int iwlagn_wait_tx_queue_empty(struct iwl_priv *priv)
  1410. {
  1411. struct iwl_tx_queue *txq;
  1412. struct iwl_queue *q;
  1413. int cnt;
  1414. unsigned long now = jiffies;
  1415. int ret = 0;
  1416. /* waiting for all the tx frames complete might take a while */
  1417. for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
  1418. if (cnt == priv->cmd_queue)
  1419. continue;
  1420. txq = &priv->txq[cnt];
  1421. q = &txq->q;
  1422. while (q->read_ptr != q->write_ptr && !time_after(jiffies,
  1423. now + msecs_to_jiffies(IWL_FLUSH_WAIT_MS)))
  1424. msleep(1);
  1425. if (q->read_ptr != q->write_ptr) {
  1426. IWL_ERR(priv, "fail to flush all tx fifo queues\n");
  1427. ret = -ETIMEDOUT;
  1428. break;
  1429. }
  1430. }
  1431. return ret;
  1432. }
  1433. #define IWL_TX_QUEUE_MSK 0xfffff
  1434. /**
  1435. * iwlagn_txfifo_flush: send REPLY_TXFIFO_FLUSH command to uCode
  1436. *
  1437. * pre-requirements:
  1438. * 1. acquire mutex before calling
  1439. * 2. make sure rf is on and not in exit state
  1440. */
  1441. int iwlagn_txfifo_flush(struct iwl_priv *priv, u16 flush_control)
  1442. {
  1443. struct iwl_txfifo_flush_cmd flush_cmd;
  1444. struct iwl_host_cmd cmd = {
  1445. .id = REPLY_TXFIFO_FLUSH,
  1446. .len = sizeof(struct iwl_txfifo_flush_cmd),
  1447. .flags = CMD_SYNC,
  1448. .data = &flush_cmd,
  1449. };
  1450. might_sleep();
  1451. memset(&flush_cmd, 0, sizeof(flush_cmd));
  1452. flush_cmd.fifo_control = IWL_TX_FIFO_VO_MSK | IWL_TX_FIFO_VI_MSK |
  1453. IWL_TX_FIFO_BE_MSK | IWL_TX_FIFO_BK_MSK;
  1454. if (priv->cfg->sku & IWL_SKU_N)
  1455. flush_cmd.fifo_control |= IWL_AGG_TX_QUEUE_MSK;
  1456. IWL_DEBUG_INFO(priv, "fifo queue control: 0X%x\n",
  1457. flush_cmd.fifo_control);
  1458. flush_cmd.flush_control = cpu_to_le16(flush_control);
  1459. return iwl_send_cmd(priv, &cmd);
  1460. }
  1461. void iwlagn_dev_txfifo_flush(struct iwl_priv *priv, u16 flush_control)
  1462. {
  1463. mutex_lock(&priv->mutex);
  1464. ieee80211_stop_queues(priv->hw);
  1465. if (priv->cfg->ops->lib->txfifo_flush(priv, IWL_DROP_ALL)) {
  1466. IWL_ERR(priv, "flush request fail\n");
  1467. goto done;
  1468. }
  1469. IWL_DEBUG_INFO(priv, "wait transmit/flush all frames\n");
  1470. iwlagn_wait_tx_queue_empty(priv);
  1471. done:
  1472. ieee80211_wake_queues(priv->hw);
  1473. mutex_unlock(&priv->mutex);
  1474. }
  1475. /*
  1476. * BT coex
  1477. */
  1478. /*
  1479. * Macros to access the lookup table.
  1480. *
  1481. * The lookup table has 7 inputs: bt3_prio, bt3_txrx, bt_rf_act, wifi_req,
  1482. * wifi_prio, wifi_txrx and wifi_sh_ant_req.
  1483. *
  1484. * It has three outputs: WLAN_ACTIVE, WLAN_KILL and ANT_SWITCH
  1485. *
  1486. * The format is that "registers" 8 through 11 contain the WLAN_ACTIVE bits
  1487. * one after another in 32-bit registers, and "registers" 0 through 7 contain
  1488. * the WLAN_KILL and ANT_SWITCH bits interleaved (in that order).
  1489. *
  1490. * These macros encode that format.
  1491. */
  1492. #define LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, wifi_req, wifi_prio, \
  1493. wifi_txrx, wifi_sh_ant_req) \
  1494. (bt3_prio | (bt3_txrx << 1) | (bt_rf_act << 2) | (wifi_req << 3) | \
  1495. (wifi_prio << 4) | (wifi_txrx << 5) | (wifi_sh_ant_req << 6))
  1496. #define LUT_PTA_WLAN_ACTIVE_OP(lut, op, val) \
  1497. lut[8 + ((val) >> 5)] op (cpu_to_le32(BIT((val) & 0x1f)))
  1498. #define LUT_TEST_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1499. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1500. (!!(LUT_PTA_WLAN_ACTIVE_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, \
  1501. bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
  1502. wifi_sh_ant_req))))
  1503. #define LUT_SET_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1504. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1505. LUT_PTA_WLAN_ACTIVE_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, \
  1506. bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
  1507. wifi_sh_ant_req))
  1508. #define LUT_CLEAR_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, \
  1509. wifi_req, wifi_prio, wifi_txrx, \
  1510. wifi_sh_ant_req) \
  1511. LUT_PTA_WLAN_ACTIVE_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, \
  1512. bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
  1513. wifi_sh_ant_req))
  1514. #define LUT_WLAN_KILL_OP(lut, op, val) \
  1515. lut[(val) >> 4] op (cpu_to_le32(BIT(((val) << 1) & 0x1e)))
  1516. #define LUT_TEST_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1517. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1518. (!!(LUT_WLAN_KILL_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1519. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))))
  1520. #define LUT_SET_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1521. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1522. LUT_WLAN_KILL_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1523. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  1524. #define LUT_CLEAR_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1525. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1526. LUT_WLAN_KILL_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1527. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  1528. #define LUT_ANT_SWITCH_OP(lut, op, val) \
  1529. lut[(val) >> 4] op (cpu_to_le32(BIT((((val) << 1) & 0x1e) + 1)))
  1530. #define LUT_TEST_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1531. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1532. (!!(LUT_ANT_SWITCH_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1533. wifi_req, wifi_prio, wifi_txrx, \
  1534. wifi_sh_ant_req))))
  1535. #define LUT_SET_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1536. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1537. LUT_ANT_SWITCH_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1538. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  1539. #define LUT_CLEAR_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1540. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1541. LUT_ANT_SWITCH_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1542. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  1543. static const __le32 iwlagn_def_3w_lookup[12] = {
  1544. cpu_to_le32(0xaaaaaaaa),
  1545. cpu_to_le32(0xaaaaaaaa),
  1546. cpu_to_le32(0xaeaaaaaa),
  1547. cpu_to_le32(0xaaaaaaaa),
  1548. cpu_to_le32(0xcc00ff28),
  1549. cpu_to_le32(0x0000aaaa),
  1550. cpu_to_le32(0xcc00aaaa),
  1551. cpu_to_le32(0x0000aaaa),
  1552. cpu_to_le32(0xc0004000),
  1553. cpu_to_le32(0x00004000),
  1554. cpu_to_le32(0xf0005000),
  1555. cpu_to_le32(0xf0005000),
  1556. };
  1557. static const __le32 iwlagn_concurrent_lookup[12] = {
  1558. cpu_to_le32(0xaaaaaaaa),
  1559. cpu_to_le32(0xaaaaaaaa),
  1560. cpu_to_le32(0xaaaaaaaa),
  1561. cpu_to_le32(0xaaaaaaaa),
  1562. cpu_to_le32(0xaaaaaaaa),
  1563. cpu_to_le32(0xaaaaaaaa),
  1564. cpu_to_le32(0xaaaaaaaa),
  1565. cpu_to_le32(0xaaaaaaaa),
  1566. cpu_to_le32(0x00000000),
  1567. cpu_to_le32(0x00000000),
  1568. cpu_to_le32(0x00000000),
  1569. cpu_to_le32(0x00000000),
  1570. };
  1571. void iwlagn_send_advance_bt_config(struct iwl_priv *priv)
  1572. {
  1573. struct iwl_basic_bt_cmd basic = {
  1574. .max_kill = IWLAGN_BT_MAX_KILL_DEFAULT,
  1575. .bt3_timer_t7_value = IWLAGN_BT3_T7_DEFAULT,
  1576. .bt3_prio_sample_time = IWLAGN_BT3_PRIO_SAMPLE_DEFAULT,
  1577. .bt3_timer_t2_value = IWLAGN_BT3_T2_DEFAULT,
  1578. };
  1579. struct iwl6000_bt_cmd bt_cmd_6000;
  1580. struct iwl2000_bt_cmd bt_cmd_2000;
  1581. int ret;
  1582. BUILD_BUG_ON(sizeof(iwlagn_def_3w_lookup) !=
  1583. sizeof(basic.bt3_lookup_table));
  1584. if (priv->cfg->bt_params) {
  1585. if (priv->cfg->bt_params->bt_session_2) {
  1586. bt_cmd_2000.prio_boost = cpu_to_le32(
  1587. priv->cfg->bt_params->bt_prio_boost);
  1588. bt_cmd_2000.tx_prio_boost = 0;
  1589. bt_cmd_2000.rx_prio_boost = 0;
  1590. } else {
  1591. bt_cmd_6000.prio_boost =
  1592. priv->cfg->bt_params->bt_prio_boost;
  1593. bt_cmd_6000.tx_prio_boost = 0;
  1594. bt_cmd_6000.rx_prio_boost = 0;
  1595. }
  1596. } else {
  1597. IWL_ERR(priv, "failed to construct BT Coex Config\n");
  1598. return;
  1599. }
  1600. basic.kill_ack_mask = priv->kill_ack_mask;
  1601. basic.kill_cts_mask = priv->kill_cts_mask;
  1602. basic.valid = priv->bt_valid;
  1603. /*
  1604. * Configure BT coex mode to "no coexistence" when the
  1605. * user disabled BT coexistence, we have no interface
  1606. * (might be in monitor mode), or the interface is in
  1607. * IBSS mode (no proper uCode support for coex then).
  1608. */
  1609. if (!bt_coex_active || priv->iw_mode == NL80211_IFTYPE_ADHOC) {
  1610. basic.flags = IWLAGN_BT_FLAG_COEX_MODE_DISABLED;
  1611. } else {
  1612. basic.flags = IWLAGN_BT_FLAG_COEX_MODE_3W <<
  1613. IWLAGN_BT_FLAG_COEX_MODE_SHIFT;
  1614. if (priv->cfg->bt_params &&
  1615. priv->cfg->bt_params->bt_sco_disable)
  1616. basic.flags |= IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE;
  1617. if (priv->bt_ch_announce)
  1618. basic.flags |= IWLAGN_BT_FLAG_CHANNEL_INHIBITION;
  1619. IWL_DEBUG_INFO(priv, "BT coex flag: 0X%x\n", basic.flags);
  1620. }
  1621. priv->bt_enable_flag = basic.flags;
  1622. if (priv->bt_full_concurrent)
  1623. memcpy(basic.bt3_lookup_table, iwlagn_concurrent_lookup,
  1624. sizeof(iwlagn_concurrent_lookup));
  1625. else
  1626. memcpy(basic.bt3_lookup_table, iwlagn_def_3w_lookup,
  1627. sizeof(iwlagn_def_3w_lookup));
  1628. IWL_DEBUG_INFO(priv, "BT coex %s in %s mode\n",
  1629. basic.flags ? "active" : "disabled",
  1630. priv->bt_full_concurrent ?
  1631. "full concurrency" : "3-wire");
  1632. if (priv->cfg->bt_params->bt_session_2) {
  1633. memcpy(&bt_cmd_2000.basic, &basic,
  1634. sizeof(basic));
  1635. ret = iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  1636. sizeof(bt_cmd_2000), &bt_cmd_2000);
  1637. } else {
  1638. memcpy(&bt_cmd_6000.basic, &basic,
  1639. sizeof(basic));
  1640. ret = iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  1641. sizeof(bt_cmd_6000), &bt_cmd_6000);
  1642. }
  1643. if (ret)
  1644. IWL_ERR(priv, "failed to send BT Coex Config\n");
  1645. }
  1646. static void iwlagn_bt_traffic_change_work(struct work_struct *work)
  1647. {
  1648. struct iwl_priv *priv =
  1649. container_of(work, struct iwl_priv, bt_traffic_change_work);
  1650. struct iwl_rxon_context *ctx;
  1651. int smps_request = -1;
  1652. if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) {
  1653. /* bt coex disabled */
  1654. return;
  1655. }
  1656. /*
  1657. * Note: bt_traffic_load can be overridden by scan complete and
  1658. * coex profile notifications. Ignore that since only bad consequence
  1659. * can be not matching debug print with actual state.
  1660. */
  1661. IWL_DEBUG_INFO(priv, "BT traffic load changes: %d\n",
  1662. priv->bt_traffic_load);
  1663. switch (priv->bt_traffic_load) {
  1664. case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
  1665. if (priv->bt_status)
  1666. smps_request = IEEE80211_SMPS_DYNAMIC;
  1667. else
  1668. smps_request = IEEE80211_SMPS_AUTOMATIC;
  1669. break;
  1670. case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
  1671. smps_request = IEEE80211_SMPS_DYNAMIC;
  1672. break;
  1673. case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
  1674. case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
  1675. smps_request = IEEE80211_SMPS_STATIC;
  1676. break;
  1677. default:
  1678. IWL_ERR(priv, "Invalid BT traffic load: %d\n",
  1679. priv->bt_traffic_load);
  1680. break;
  1681. }
  1682. mutex_lock(&priv->mutex);
  1683. /*
  1684. * We can not send command to firmware while scanning. When the scan
  1685. * complete we will schedule this work again. We do check with mutex
  1686. * locked to prevent new scan request to arrive. We do not check
  1687. * STATUS_SCANNING to avoid race when queue_work two times from
  1688. * different notifications, but quit and not perform any work at all.
  1689. */
  1690. if (test_bit(STATUS_SCAN_HW, &priv->status))
  1691. goto out;
  1692. if (priv->cfg->ops->lib->update_chain_flags)
  1693. priv->cfg->ops->lib->update_chain_flags(priv);
  1694. if (smps_request != -1) {
  1695. for_each_context(priv, ctx) {
  1696. if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION)
  1697. ieee80211_request_smps(ctx->vif, smps_request);
  1698. }
  1699. }
  1700. out:
  1701. mutex_unlock(&priv->mutex);
  1702. }
  1703. static void iwlagn_print_uartmsg(struct iwl_priv *priv,
  1704. struct iwl_bt_uart_msg *uart_msg)
  1705. {
  1706. IWL_DEBUG_NOTIF(priv, "Message Type = 0x%X, SSN = 0x%X, "
  1707. "Update Req = 0x%X",
  1708. (BT_UART_MSG_FRAME1MSGTYPE_MSK & uart_msg->frame1) >>
  1709. BT_UART_MSG_FRAME1MSGTYPE_POS,
  1710. (BT_UART_MSG_FRAME1SSN_MSK & uart_msg->frame1) >>
  1711. BT_UART_MSG_FRAME1SSN_POS,
  1712. (BT_UART_MSG_FRAME1UPDATEREQ_MSK & uart_msg->frame1) >>
  1713. BT_UART_MSG_FRAME1UPDATEREQ_POS);
  1714. IWL_DEBUG_NOTIF(priv, "Open connections = 0x%X, Traffic load = 0x%X, "
  1715. "Chl_SeqN = 0x%X, In band = 0x%X",
  1716. (BT_UART_MSG_FRAME2OPENCONNECTIONS_MSK & uart_msg->frame2) >>
  1717. BT_UART_MSG_FRAME2OPENCONNECTIONS_POS,
  1718. (BT_UART_MSG_FRAME2TRAFFICLOAD_MSK & uart_msg->frame2) >>
  1719. BT_UART_MSG_FRAME2TRAFFICLOAD_POS,
  1720. (BT_UART_MSG_FRAME2CHLSEQN_MSK & uart_msg->frame2) >>
  1721. BT_UART_MSG_FRAME2CHLSEQN_POS,
  1722. (BT_UART_MSG_FRAME2INBAND_MSK & uart_msg->frame2) >>
  1723. BT_UART_MSG_FRAME2INBAND_POS);
  1724. IWL_DEBUG_NOTIF(priv, "SCO/eSCO = 0x%X, Sniff = 0x%X, A2DP = 0x%X, "
  1725. "ACL = 0x%X, Master = 0x%X, OBEX = 0x%X",
  1726. (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3) >>
  1727. BT_UART_MSG_FRAME3SCOESCO_POS,
  1728. (BT_UART_MSG_FRAME3SNIFF_MSK & uart_msg->frame3) >>
  1729. BT_UART_MSG_FRAME3SNIFF_POS,
  1730. (BT_UART_MSG_FRAME3A2DP_MSK & uart_msg->frame3) >>
  1731. BT_UART_MSG_FRAME3A2DP_POS,
  1732. (BT_UART_MSG_FRAME3ACL_MSK & uart_msg->frame3) >>
  1733. BT_UART_MSG_FRAME3ACL_POS,
  1734. (BT_UART_MSG_FRAME3MASTER_MSK & uart_msg->frame3) >>
  1735. BT_UART_MSG_FRAME3MASTER_POS,
  1736. (BT_UART_MSG_FRAME3OBEX_MSK & uart_msg->frame3) >>
  1737. BT_UART_MSG_FRAME3OBEX_POS);
  1738. IWL_DEBUG_NOTIF(priv, "Idle duration = 0x%X",
  1739. (BT_UART_MSG_FRAME4IDLEDURATION_MSK & uart_msg->frame4) >>
  1740. BT_UART_MSG_FRAME4IDLEDURATION_POS);
  1741. IWL_DEBUG_NOTIF(priv, "Tx Activity = 0x%X, Rx Activity = 0x%X, "
  1742. "eSCO Retransmissions = 0x%X",
  1743. (BT_UART_MSG_FRAME5TXACTIVITY_MSK & uart_msg->frame5) >>
  1744. BT_UART_MSG_FRAME5TXACTIVITY_POS,
  1745. (BT_UART_MSG_FRAME5RXACTIVITY_MSK & uart_msg->frame5) >>
  1746. BT_UART_MSG_FRAME5RXACTIVITY_POS,
  1747. (BT_UART_MSG_FRAME5ESCORETRANSMIT_MSK & uart_msg->frame5) >>
  1748. BT_UART_MSG_FRAME5ESCORETRANSMIT_POS);
  1749. IWL_DEBUG_NOTIF(priv, "Sniff Interval = 0x%X, Discoverable = 0x%X",
  1750. (BT_UART_MSG_FRAME6SNIFFINTERVAL_MSK & uart_msg->frame6) >>
  1751. BT_UART_MSG_FRAME6SNIFFINTERVAL_POS,
  1752. (BT_UART_MSG_FRAME6DISCOVERABLE_MSK & uart_msg->frame6) >>
  1753. BT_UART_MSG_FRAME6DISCOVERABLE_POS);
  1754. IWL_DEBUG_NOTIF(priv, "Sniff Activity = 0x%X, Page = "
  1755. "0x%X, Inquiry = 0x%X, Connectable = 0x%X",
  1756. (BT_UART_MSG_FRAME7SNIFFACTIVITY_MSK & uart_msg->frame7) >>
  1757. BT_UART_MSG_FRAME7SNIFFACTIVITY_POS,
  1758. (BT_UART_MSG_FRAME7PAGE_MSK & uart_msg->frame7) >>
  1759. BT_UART_MSG_FRAME7PAGE_POS,
  1760. (BT_UART_MSG_FRAME7INQUIRY_MSK & uart_msg->frame7) >>
  1761. BT_UART_MSG_FRAME7INQUIRY_POS,
  1762. (BT_UART_MSG_FRAME7CONNECTABLE_MSK & uart_msg->frame7) >>
  1763. BT_UART_MSG_FRAME7CONNECTABLE_POS);
  1764. }
  1765. static void iwlagn_set_kill_msk(struct iwl_priv *priv,
  1766. struct iwl_bt_uart_msg *uart_msg)
  1767. {
  1768. u8 kill_msk;
  1769. static const __le32 bt_kill_ack_msg[2] = {
  1770. IWLAGN_BT_KILL_ACK_MASK_DEFAULT,
  1771. IWLAGN_BT_KILL_ACK_CTS_MASK_SCO };
  1772. static const __le32 bt_kill_cts_msg[2] = {
  1773. IWLAGN_BT_KILL_CTS_MASK_DEFAULT,
  1774. IWLAGN_BT_KILL_ACK_CTS_MASK_SCO };
  1775. kill_msk = (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3)
  1776. ? 1 : 0;
  1777. if (priv->kill_ack_mask != bt_kill_ack_msg[kill_msk] ||
  1778. priv->kill_cts_mask != bt_kill_cts_msg[kill_msk]) {
  1779. priv->bt_valid |= IWLAGN_BT_VALID_KILL_ACK_MASK;
  1780. priv->kill_ack_mask = bt_kill_ack_msg[kill_msk];
  1781. priv->bt_valid |= IWLAGN_BT_VALID_KILL_CTS_MASK;
  1782. priv->kill_cts_mask = bt_kill_cts_msg[kill_msk];
  1783. /* schedule to send runtime bt_config */
  1784. queue_work(priv->workqueue, &priv->bt_runtime_config);
  1785. }
  1786. }
  1787. void iwlagn_bt_coex_profile_notif(struct iwl_priv *priv,
  1788. struct iwl_rx_mem_buffer *rxb)
  1789. {
  1790. unsigned long flags;
  1791. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1792. struct iwl_bt_coex_profile_notif *coex = &pkt->u.bt_coex_profile_notif;
  1793. struct iwl_bt_uart_msg *uart_msg = &coex->last_bt_uart_msg;
  1794. if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) {
  1795. /* bt coex disabled */
  1796. return;
  1797. }
  1798. IWL_DEBUG_NOTIF(priv, "BT Coex notification:\n");
  1799. IWL_DEBUG_NOTIF(priv, " status: %d\n", coex->bt_status);
  1800. IWL_DEBUG_NOTIF(priv, " traffic load: %d\n", coex->bt_traffic_load);
  1801. IWL_DEBUG_NOTIF(priv, " CI compliance: %d\n",
  1802. coex->bt_ci_compliance);
  1803. iwlagn_print_uartmsg(priv, uart_msg);
  1804. priv->last_bt_traffic_load = priv->bt_traffic_load;
  1805. if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
  1806. if (priv->bt_status != coex->bt_status ||
  1807. priv->last_bt_traffic_load != coex->bt_traffic_load) {
  1808. if (coex->bt_status) {
  1809. /* BT on */
  1810. if (!priv->bt_ch_announce)
  1811. priv->bt_traffic_load =
  1812. IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
  1813. else
  1814. priv->bt_traffic_load =
  1815. coex->bt_traffic_load;
  1816. } else {
  1817. /* BT off */
  1818. priv->bt_traffic_load =
  1819. IWL_BT_COEX_TRAFFIC_LOAD_NONE;
  1820. }
  1821. priv->bt_status = coex->bt_status;
  1822. queue_work(priv->workqueue,
  1823. &priv->bt_traffic_change_work);
  1824. }
  1825. }
  1826. iwlagn_set_kill_msk(priv, uart_msg);
  1827. /* FIXME: based on notification, adjust the prio_boost */
  1828. spin_lock_irqsave(&priv->lock, flags);
  1829. priv->bt_ci_compliance = coex->bt_ci_compliance;
  1830. spin_unlock_irqrestore(&priv->lock, flags);
  1831. }
  1832. void iwlagn_bt_rx_handler_setup(struct iwl_priv *priv)
  1833. {
  1834. iwlagn_rx_handler_setup(priv);
  1835. priv->rx_handlers[REPLY_BT_COEX_PROFILE_NOTIF] =
  1836. iwlagn_bt_coex_profile_notif;
  1837. }
  1838. void iwlagn_bt_setup_deferred_work(struct iwl_priv *priv)
  1839. {
  1840. iwlagn_setup_deferred_work(priv);
  1841. INIT_WORK(&priv->bt_traffic_change_work,
  1842. iwlagn_bt_traffic_change_work);
  1843. }
  1844. void iwlagn_bt_cancel_deferred_work(struct iwl_priv *priv)
  1845. {
  1846. cancel_work_sync(&priv->bt_traffic_change_work);
  1847. }
  1848. static bool is_single_rx_stream(struct iwl_priv *priv)
  1849. {
  1850. return priv->current_ht_config.smps == IEEE80211_SMPS_STATIC ||
  1851. priv->current_ht_config.single_chain_sufficient;
  1852. }
  1853. #define IWL_NUM_RX_CHAINS_MULTIPLE 3
  1854. #define IWL_NUM_RX_CHAINS_SINGLE 2
  1855. #define IWL_NUM_IDLE_CHAINS_DUAL 2
  1856. #define IWL_NUM_IDLE_CHAINS_SINGLE 1
  1857. /*
  1858. * Determine how many receiver/antenna chains to use.
  1859. *
  1860. * More provides better reception via diversity. Fewer saves power
  1861. * at the expense of throughput, but only when not in powersave to
  1862. * start with.
  1863. *
  1864. * MIMO (dual stream) requires at least 2, but works better with 3.
  1865. * This does not determine *which* chains to use, just how many.
  1866. */
  1867. static int iwl_get_active_rx_chain_count(struct iwl_priv *priv)
  1868. {
  1869. if (priv->cfg->bt_params &&
  1870. priv->cfg->bt_params->advanced_bt_coexist &&
  1871. (priv->bt_full_concurrent ||
  1872. priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) {
  1873. /*
  1874. * only use chain 'A' in bt high traffic load or
  1875. * full concurrency mode
  1876. */
  1877. return IWL_NUM_RX_CHAINS_SINGLE;
  1878. }
  1879. /* # of Rx chains to use when expecting MIMO. */
  1880. if (is_single_rx_stream(priv))
  1881. return IWL_NUM_RX_CHAINS_SINGLE;
  1882. else
  1883. return IWL_NUM_RX_CHAINS_MULTIPLE;
  1884. }
  1885. /*
  1886. * When we are in power saving mode, unless device support spatial
  1887. * multiplexing power save, use the active count for rx chain count.
  1888. */
  1889. static int iwl_get_idle_rx_chain_count(struct iwl_priv *priv, int active_cnt)
  1890. {
  1891. /* # Rx chains when idling, depending on SMPS mode */
  1892. switch (priv->current_ht_config.smps) {
  1893. case IEEE80211_SMPS_STATIC:
  1894. case IEEE80211_SMPS_DYNAMIC:
  1895. return IWL_NUM_IDLE_CHAINS_SINGLE;
  1896. case IEEE80211_SMPS_OFF:
  1897. return active_cnt;
  1898. default:
  1899. WARN(1, "invalid SMPS mode %d",
  1900. priv->current_ht_config.smps);
  1901. return active_cnt;
  1902. }
  1903. }
  1904. /* up to 4 chains */
  1905. static u8 iwl_count_chain_bitmap(u32 chain_bitmap)
  1906. {
  1907. u8 res;
  1908. res = (chain_bitmap & BIT(0)) >> 0;
  1909. res += (chain_bitmap & BIT(1)) >> 1;
  1910. res += (chain_bitmap & BIT(2)) >> 2;
  1911. res += (chain_bitmap & BIT(3)) >> 3;
  1912. return res;
  1913. }
  1914. /**
  1915. * iwlagn_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
  1916. *
  1917. * Selects how many and which Rx receivers/antennas/chains to use.
  1918. * This should not be used for scan command ... it puts data in wrong place.
  1919. */
  1920. void iwlagn_set_rxon_chain(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  1921. {
  1922. bool is_single = is_single_rx_stream(priv);
  1923. bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->status);
  1924. u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt;
  1925. u32 active_chains;
  1926. u16 rx_chain;
  1927. /* Tell uCode which antennas are actually connected.
  1928. * Before first association, we assume all antennas are connected.
  1929. * Just after first association, iwl_chain_noise_calibration()
  1930. * checks which antennas actually *are* connected. */
  1931. if (priv->chain_noise_data.active_chains)
  1932. active_chains = priv->chain_noise_data.active_chains;
  1933. else
  1934. active_chains = priv->hw_params.valid_rx_ant;
  1935. if (priv->cfg->bt_params &&
  1936. priv->cfg->bt_params->advanced_bt_coexist &&
  1937. (priv->bt_full_concurrent ||
  1938. priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) {
  1939. /*
  1940. * only use chain 'A' in bt high traffic load or
  1941. * full concurrency mode
  1942. */
  1943. active_chains = first_antenna(active_chains);
  1944. }
  1945. rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS;
  1946. /* How many receivers should we use? */
  1947. active_rx_cnt = iwl_get_active_rx_chain_count(priv);
  1948. idle_rx_cnt = iwl_get_idle_rx_chain_count(priv, active_rx_cnt);
  1949. /* correct rx chain count according hw settings
  1950. * and chain noise calibration
  1951. */
  1952. valid_rx_cnt = iwl_count_chain_bitmap(active_chains);
  1953. if (valid_rx_cnt < active_rx_cnt)
  1954. active_rx_cnt = valid_rx_cnt;
  1955. if (valid_rx_cnt < idle_rx_cnt)
  1956. idle_rx_cnt = valid_rx_cnt;
  1957. rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS;
  1958. rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS;
  1959. ctx->staging.rx_chain = cpu_to_le16(rx_chain);
  1960. if (!is_single && (active_rx_cnt >= IWL_NUM_RX_CHAINS_SINGLE) && is_cam)
  1961. ctx->staging.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
  1962. else
  1963. ctx->staging.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
  1964. IWL_DEBUG_ASSOC(priv, "rx_chain=0x%X active=%d idle=%d\n",
  1965. ctx->staging.rx_chain,
  1966. active_rx_cnt, idle_rx_cnt);
  1967. WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 ||
  1968. active_rx_cnt < idle_rx_cnt);
  1969. }
  1970. u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant, u8 valid)
  1971. {
  1972. int i;
  1973. u8 ind = ant;
  1974. if (priv->band == IEEE80211_BAND_2GHZ &&
  1975. priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)
  1976. return 0;
  1977. for (i = 0; i < RATE_ANT_NUM - 1; i++) {
  1978. ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0;
  1979. if (valid & BIT(ind))
  1980. return ind;
  1981. }
  1982. return ant;
  1983. }
  1984. static const char *get_csr_string(int cmd)
  1985. {
  1986. switch (cmd) {
  1987. IWL_CMD(CSR_HW_IF_CONFIG_REG);
  1988. IWL_CMD(CSR_INT_COALESCING);
  1989. IWL_CMD(CSR_INT);
  1990. IWL_CMD(CSR_INT_MASK);
  1991. IWL_CMD(CSR_FH_INT_STATUS);
  1992. IWL_CMD(CSR_GPIO_IN);
  1993. IWL_CMD(CSR_RESET);
  1994. IWL_CMD(CSR_GP_CNTRL);
  1995. IWL_CMD(CSR_HW_REV);
  1996. IWL_CMD(CSR_EEPROM_REG);
  1997. IWL_CMD(CSR_EEPROM_GP);
  1998. IWL_CMD(CSR_OTP_GP_REG);
  1999. IWL_CMD(CSR_GIO_REG);
  2000. IWL_CMD(CSR_GP_UCODE_REG);
  2001. IWL_CMD(CSR_GP_DRIVER_REG);
  2002. IWL_CMD(CSR_UCODE_DRV_GP1);
  2003. IWL_CMD(CSR_UCODE_DRV_GP2);
  2004. IWL_CMD(CSR_LED_REG);
  2005. IWL_CMD(CSR_DRAM_INT_TBL_REG);
  2006. IWL_CMD(CSR_GIO_CHICKEN_BITS);
  2007. IWL_CMD(CSR_ANA_PLL_CFG);
  2008. IWL_CMD(CSR_HW_REV_WA_REG);
  2009. IWL_CMD(CSR_DBG_HPET_MEM_REG);
  2010. default:
  2011. return "UNKNOWN";
  2012. }
  2013. }
  2014. void iwl_dump_csr(struct iwl_priv *priv)
  2015. {
  2016. int i;
  2017. static const u32 csr_tbl[] = {
  2018. CSR_HW_IF_CONFIG_REG,
  2019. CSR_INT_COALESCING,
  2020. CSR_INT,
  2021. CSR_INT_MASK,
  2022. CSR_FH_INT_STATUS,
  2023. CSR_GPIO_IN,
  2024. CSR_RESET,
  2025. CSR_GP_CNTRL,
  2026. CSR_HW_REV,
  2027. CSR_EEPROM_REG,
  2028. CSR_EEPROM_GP,
  2029. CSR_OTP_GP_REG,
  2030. CSR_GIO_REG,
  2031. CSR_GP_UCODE_REG,
  2032. CSR_GP_DRIVER_REG,
  2033. CSR_UCODE_DRV_GP1,
  2034. CSR_UCODE_DRV_GP2,
  2035. CSR_LED_REG,
  2036. CSR_DRAM_INT_TBL_REG,
  2037. CSR_GIO_CHICKEN_BITS,
  2038. CSR_ANA_PLL_CFG,
  2039. CSR_HW_REV_WA_REG,
  2040. CSR_DBG_HPET_MEM_REG
  2041. };
  2042. IWL_ERR(priv, "CSR values:\n");
  2043. IWL_ERR(priv, "(2nd byte of CSR_INT_COALESCING is "
  2044. "CSR_INT_PERIODIC_REG)\n");
  2045. for (i = 0; i < ARRAY_SIZE(csr_tbl); i++) {
  2046. IWL_ERR(priv, " %25s: 0X%08x\n",
  2047. get_csr_string(csr_tbl[i]),
  2048. iwl_read32(priv, csr_tbl[i]));
  2049. }
  2050. }
  2051. static const char *get_fh_string(int cmd)
  2052. {
  2053. switch (cmd) {
  2054. IWL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG);
  2055. IWL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG);
  2056. IWL_CMD(FH_RSCSR_CHNL0_WPTR);
  2057. IWL_CMD(FH_MEM_RCSR_CHNL0_CONFIG_REG);
  2058. IWL_CMD(FH_MEM_RSSR_SHARED_CTRL_REG);
  2059. IWL_CMD(FH_MEM_RSSR_RX_STATUS_REG);
  2060. IWL_CMD(FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV);
  2061. IWL_CMD(FH_TSSR_TX_STATUS_REG);
  2062. IWL_CMD(FH_TSSR_TX_ERROR_REG);
  2063. default:
  2064. return "UNKNOWN";
  2065. }
  2066. }
  2067. int iwl_dump_fh(struct iwl_priv *priv, char **buf, bool display)
  2068. {
  2069. int i;
  2070. #ifdef CONFIG_IWLWIFI_DEBUG
  2071. int pos = 0;
  2072. size_t bufsz = 0;
  2073. #endif
  2074. static const u32 fh_tbl[] = {
  2075. FH_RSCSR_CHNL0_STTS_WPTR_REG,
  2076. FH_RSCSR_CHNL0_RBDCB_BASE_REG,
  2077. FH_RSCSR_CHNL0_WPTR,
  2078. FH_MEM_RCSR_CHNL0_CONFIG_REG,
  2079. FH_MEM_RSSR_SHARED_CTRL_REG,
  2080. FH_MEM_RSSR_RX_STATUS_REG,
  2081. FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV,
  2082. FH_TSSR_TX_STATUS_REG,
  2083. FH_TSSR_TX_ERROR_REG
  2084. };
  2085. #ifdef CONFIG_IWLWIFI_DEBUG
  2086. if (display) {
  2087. bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40;
  2088. *buf = kmalloc(bufsz, GFP_KERNEL);
  2089. if (!*buf)
  2090. return -ENOMEM;
  2091. pos += scnprintf(*buf + pos, bufsz - pos,
  2092. "FH register values:\n");
  2093. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
  2094. pos += scnprintf(*buf + pos, bufsz - pos,
  2095. " %34s: 0X%08x\n",
  2096. get_fh_string(fh_tbl[i]),
  2097. iwl_read_direct32(priv, fh_tbl[i]));
  2098. }
  2099. return pos;
  2100. }
  2101. #endif
  2102. IWL_ERR(priv, "FH register values:\n");
  2103. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
  2104. IWL_ERR(priv, " %34s: 0X%08x\n",
  2105. get_fh_string(fh_tbl[i]),
  2106. iwl_read_direct32(priv, fh_tbl[i]));
  2107. }
  2108. return 0;
  2109. }
  2110. /* notification wait support */
  2111. void iwlagn_init_notification_wait(struct iwl_priv *priv,
  2112. struct iwl_notification_wait *wait_entry,
  2113. void (*fn)(struct iwl_priv *priv,
  2114. struct iwl_rx_packet *pkt),
  2115. u8 cmd)
  2116. {
  2117. wait_entry->fn = fn;
  2118. wait_entry->cmd = cmd;
  2119. wait_entry->triggered = false;
  2120. spin_lock_bh(&priv->_agn.notif_wait_lock);
  2121. list_add(&wait_entry->list, &priv->_agn.notif_waits);
  2122. spin_unlock_bh(&priv->_agn.notif_wait_lock);
  2123. }
  2124. signed long iwlagn_wait_notification(struct iwl_priv *priv,
  2125. struct iwl_notification_wait *wait_entry,
  2126. unsigned long timeout)
  2127. {
  2128. int ret;
  2129. ret = wait_event_timeout(priv->_agn.notif_waitq,
  2130. &wait_entry->triggered,
  2131. timeout);
  2132. spin_lock_bh(&priv->_agn.notif_wait_lock);
  2133. list_del(&wait_entry->list);
  2134. spin_unlock_bh(&priv->_agn.notif_wait_lock);
  2135. return ret;
  2136. }
  2137. void iwlagn_remove_notification(struct iwl_priv *priv,
  2138. struct iwl_notification_wait *wait_entry)
  2139. {
  2140. spin_lock_bh(&priv->_agn.notif_wait_lock);
  2141. list_del(&wait_entry->list);
  2142. spin_unlock_bh(&priv->_agn.notif_wait_lock);
  2143. }