iwl-agn-lib.c 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2011 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. #include "iwl-trans.h"
  42. #include "iwl-shared.h"
  43. static inline u32 iwlagn_get_scd_ssn(struct iwlagn_tx_resp *tx_resp)
  44. {
  45. return le32_to_cpup((__le32 *)&tx_resp->status +
  46. tx_resp->frame_count) & MAX_SN;
  47. }
  48. static void iwlagn_count_tx_err_status(struct iwl_priv *priv, u16 status)
  49. {
  50. status &= TX_STATUS_MSK;
  51. switch (status) {
  52. case TX_STATUS_POSTPONE_DELAY:
  53. priv->reply_tx_stats.pp_delay++;
  54. break;
  55. case TX_STATUS_POSTPONE_FEW_BYTES:
  56. priv->reply_tx_stats.pp_few_bytes++;
  57. break;
  58. case TX_STATUS_POSTPONE_BT_PRIO:
  59. priv->reply_tx_stats.pp_bt_prio++;
  60. break;
  61. case TX_STATUS_POSTPONE_QUIET_PERIOD:
  62. priv->reply_tx_stats.pp_quiet_period++;
  63. break;
  64. case TX_STATUS_POSTPONE_CALC_TTAK:
  65. priv->reply_tx_stats.pp_calc_ttak++;
  66. break;
  67. case TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY:
  68. priv->reply_tx_stats.int_crossed_retry++;
  69. break;
  70. case TX_STATUS_FAIL_SHORT_LIMIT:
  71. priv->reply_tx_stats.short_limit++;
  72. break;
  73. case TX_STATUS_FAIL_LONG_LIMIT:
  74. priv->reply_tx_stats.long_limit++;
  75. break;
  76. case TX_STATUS_FAIL_FIFO_UNDERRUN:
  77. priv->reply_tx_stats.fifo_underrun++;
  78. break;
  79. case TX_STATUS_FAIL_DRAIN_FLOW:
  80. priv->reply_tx_stats.drain_flow++;
  81. break;
  82. case TX_STATUS_FAIL_RFKILL_FLUSH:
  83. priv->reply_tx_stats.rfkill_flush++;
  84. break;
  85. case TX_STATUS_FAIL_LIFE_EXPIRE:
  86. priv->reply_tx_stats.life_expire++;
  87. break;
  88. case TX_STATUS_FAIL_DEST_PS:
  89. priv->reply_tx_stats.dest_ps++;
  90. break;
  91. case TX_STATUS_FAIL_HOST_ABORTED:
  92. priv->reply_tx_stats.host_abort++;
  93. break;
  94. case TX_STATUS_FAIL_BT_RETRY:
  95. priv->reply_tx_stats.bt_retry++;
  96. break;
  97. case TX_STATUS_FAIL_STA_INVALID:
  98. priv->reply_tx_stats.sta_invalid++;
  99. break;
  100. case TX_STATUS_FAIL_FRAG_DROPPED:
  101. priv->reply_tx_stats.frag_drop++;
  102. break;
  103. case TX_STATUS_FAIL_TID_DISABLE:
  104. priv->reply_tx_stats.tid_disable++;
  105. break;
  106. case TX_STATUS_FAIL_FIFO_FLUSHED:
  107. priv->reply_tx_stats.fifo_flush++;
  108. break;
  109. case TX_STATUS_FAIL_INSUFFICIENT_CF_POLL:
  110. priv->reply_tx_stats.insuff_cf_poll++;
  111. break;
  112. case TX_STATUS_FAIL_PASSIVE_NO_RX:
  113. priv->reply_tx_stats.fail_hw_drop++;
  114. break;
  115. case TX_STATUS_FAIL_NO_BEACON_ON_RADAR:
  116. priv->reply_tx_stats.sta_color_mismatch++;
  117. break;
  118. default:
  119. priv->reply_tx_stats.unknown++;
  120. break;
  121. }
  122. }
  123. static void iwlagn_count_agg_tx_err_status(struct iwl_priv *priv, u16 status)
  124. {
  125. status &= AGG_TX_STATUS_MSK;
  126. switch (status) {
  127. case AGG_TX_STATE_UNDERRUN_MSK:
  128. priv->reply_agg_tx_stats.underrun++;
  129. break;
  130. case AGG_TX_STATE_BT_PRIO_MSK:
  131. priv->reply_agg_tx_stats.bt_prio++;
  132. break;
  133. case AGG_TX_STATE_FEW_BYTES_MSK:
  134. priv->reply_agg_tx_stats.few_bytes++;
  135. break;
  136. case AGG_TX_STATE_ABORT_MSK:
  137. priv->reply_agg_tx_stats.abort++;
  138. break;
  139. case AGG_TX_STATE_LAST_SENT_TTL_MSK:
  140. priv->reply_agg_tx_stats.last_sent_ttl++;
  141. break;
  142. case AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK:
  143. priv->reply_agg_tx_stats.last_sent_try++;
  144. break;
  145. case AGG_TX_STATE_LAST_SENT_BT_KILL_MSK:
  146. priv->reply_agg_tx_stats.last_sent_bt_kill++;
  147. break;
  148. case AGG_TX_STATE_SCD_QUERY_MSK:
  149. priv->reply_agg_tx_stats.scd_query++;
  150. break;
  151. case AGG_TX_STATE_TEST_BAD_CRC32_MSK:
  152. priv->reply_agg_tx_stats.bad_crc32++;
  153. break;
  154. case AGG_TX_STATE_RESPONSE_MSK:
  155. priv->reply_agg_tx_stats.response++;
  156. break;
  157. case AGG_TX_STATE_DUMP_TX_MSK:
  158. priv->reply_agg_tx_stats.dump_tx++;
  159. break;
  160. case AGG_TX_STATE_DELAY_TX_MSK:
  161. priv->reply_agg_tx_stats.delay_tx++;
  162. break;
  163. default:
  164. priv->reply_agg_tx_stats.unknown++;
  165. break;
  166. }
  167. }
  168. static void iwlagn_set_tx_status(struct iwl_priv *priv,
  169. struct ieee80211_tx_info *info,
  170. struct iwl_rxon_context *ctx,
  171. struct iwlagn_tx_resp *tx_resp,
  172. int txq_id, bool is_agg)
  173. {
  174. u16 status = le16_to_cpu(tx_resp->status.status);
  175. info->status.rates[0].count = tx_resp->failure_frame + 1;
  176. if (is_agg)
  177. info->flags &= ~IEEE80211_TX_CTL_AMPDU;
  178. info->flags |= iwl_tx_status_to_mac80211(status);
  179. iwlagn_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags),
  180. info);
  181. if (!iwl_is_tx_success(status))
  182. iwlagn_count_tx_err_status(priv, status);
  183. if (status == TX_STATUS_FAIL_PASSIVE_NO_RX &&
  184. iwl_is_associated_ctx(ctx) && ctx->vif &&
  185. ctx->vif->type == NL80211_IFTYPE_STATION) {
  186. ctx->last_tx_rejected = true;
  187. iwl_stop_queue(priv, &priv->txq[txq_id]);
  188. }
  189. IWL_DEBUG_TX_REPLY(priv, "TXQ %d status %s (0x%08x) rate_n_flags "
  190. "0x%x retries %d\n",
  191. txq_id,
  192. iwl_get_tx_fail_reason(status), status,
  193. le32_to_cpu(tx_resp->rate_n_flags),
  194. tx_resp->failure_frame);
  195. }
  196. #ifdef CONFIG_IWLWIFI_DEBUG
  197. #define AGG_TX_STATE_FAIL(x) case AGG_TX_STATE_ ## x: return #x
  198. const char *iwl_get_agg_tx_fail_reason(u16 status)
  199. {
  200. status &= AGG_TX_STATUS_MSK;
  201. switch (status) {
  202. case AGG_TX_STATE_TRANSMITTED:
  203. return "SUCCESS";
  204. AGG_TX_STATE_FAIL(UNDERRUN_MSK);
  205. AGG_TX_STATE_FAIL(BT_PRIO_MSK);
  206. AGG_TX_STATE_FAIL(FEW_BYTES_MSK);
  207. AGG_TX_STATE_FAIL(ABORT_MSK);
  208. AGG_TX_STATE_FAIL(LAST_SENT_TTL_MSK);
  209. AGG_TX_STATE_FAIL(LAST_SENT_TRY_CNT_MSK);
  210. AGG_TX_STATE_FAIL(LAST_SENT_BT_KILL_MSK);
  211. AGG_TX_STATE_FAIL(SCD_QUERY_MSK);
  212. AGG_TX_STATE_FAIL(TEST_BAD_CRC32_MSK);
  213. AGG_TX_STATE_FAIL(RESPONSE_MSK);
  214. AGG_TX_STATE_FAIL(DUMP_TX_MSK);
  215. AGG_TX_STATE_FAIL(DELAY_TX_MSK);
  216. }
  217. return "UNKNOWN";
  218. }
  219. #endif /* CONFIG_IWLWIFI_DEBUG */
  220. static int iwlagn_tx_status_reply_tx(struct iwl_priv *priv,
  221. struct iwl_ht_agg *agg,
  222. struct iwlagn_tx_resp *tx_resp,
  223. int txq_id, u16 start_idx)
  224. {
  225. u16 status;
  226. struct agg_tx_status *frame_status = &tx_resp->status;
  227. struct ieee80211_hdr *hdr = NULL;
  228. int i, sh, idx;
  229. u16 seq;
  230. if (agg->wait_for_ba)
  231. IWL_DEBUG_TX_REPLY(priv, "got tx response w/o block-ack\n");
  232. agg->frame_count = tx_resp->frame_count;
  233. agg->start_idx = start_idx;
  234. agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
  235. agg->bitmap = 0;
  236. /* # frames attempted by Tx command */
  237. if (agg->frame_count == 1) {
  238. struct iwl_tx_info *txb;
  239. /* Only one frame was attempted; no block-ack will arrive */
  240. idx = start_idx;
  241. IWL_DEBUG_TX_REPLY(priv, "FrameCnt = %d, StartIdx=%d idx=%d\n",
  242. agg->frame_count, agg->start_idx, idx);
  243. txb = &priv->txq[txq_id].txb[idx];
  244. iwlagn_set_tx_status(priv, IEEE80211_SKB_CB(txb->skb),
  245. txb->ctx, tx_resp, txq_id, true);
  246. agg->wait_for_ba = 0;
  247. } else {
  248. /* Two or more frames were attempted; expect block-ack */
  249. u64 bitmap = 0;
  250. /*
  251. * Start is the lowest frame sent. It may not be the first
  252. * frame in the batch; we figure this out dynamically during
  253. * the following loop.
  254. */
  255. int start = agg->start_idx;
  256. /* Construct bit-map of pending frames within Tx window */
  257. for (i = 0; i < agg->frame_count; i++) {
  258. u16 sc;
  259. status = le16_to_cpu(frame_status[i].status);
  260. seq = le16_to_cpu(frame_status[i].sequence);
  261. idx = SEQ_TO_INDEX(seq);
  262. txq_id = SEQ_TO_QUEUE(seq);
  263. if (status & AGG_TX_STATUS_MSK)
  264. iwlagn_count_agg_tx_err_status(priv, status);
  265. if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
  266. AGG_TX_STATE_ABORT_MSK))
  267. continue;
  268. IWL_DEBUG_TX_REPLY(priv, "FrameCnt = %d, txq_id=%d idx=%d\n",
  269. agg->frame_count, txq_id, idx);
  270. IWL_DEBUG_TX_REPLY(priv, "status %s (0x%08x), "
  271. "try-count (0x%08x)\n",
  272. iwl_get_agg_tx_fail_reason(status),
  273. status & AGG_TX_STATUS_MSK,
  274. status & AGG_TX_TRY_MSK);
  275. hdr = iwl_tx_queue_get_hdr(priv, txq_id, idx);
  276. if (!hdr) {
  277. IWL_ERR(priv,
  278. "BUG_ON idx doesn't point to valid skb"
  279. " idx=%d, txq_id=%d\n", idx, txq_id);
  280. return -1;
  281. }
  282. sc = le16_to_cpu(hdr->seq_ctrl);
  283. if (idx != (SEQ_TO_SN(sc) & 0xff)) {
  284. IWL_ERR(priv,
  285. "BUG_ON idx doesn't match seq control"
  286. " idx=%d, seq_idx=%d, seq=%d\n",
  287. idx, SEQ_TO_SN(sc),
  288. hdr->seq_ctrl);
  289. return -1;
  290. }
  291. IWL_DEBUG_TX_REPLY(priv, "AGG Frame i=%d idx %d seq=%d\n",
  292. i, idx, SEQ_TO_SN(sc));
  293. /*
  294. * sh -> how many frames ahead of the starting frame is
  295. * the current one?
  296. *
  297. * Note that all frames sent in the batch must be in a
  298. * 64-frame window, so this number should be in [0,63].
  299. * If outside of this window, then we've found a new
  300. * "first" frame in the batch and need to change start.
  301. */
  302. sh = idx - start;
  303. /*
  304. * If >= 64, out of window. start must be at the front
  305. * of the circular buffer, idx must be near the end of
  306. * the buffer, and idx is the new "first" frame. Shift
  307. * the indices around.
  308. */
  309. if (sh >= 64) {
  310. /* Shift bitmap by start - idx, wrapped */
  311. sh = 0x100 - idx + start;
  312. bitmap = bitmap << sh;
  313. /* Now idx is the new start so sh = 0 */
  314. sh = 0;
  315. start = idx;
  316. /*
  317. * If <= -64 then wraps the 256-pkt circular buffer
  318. * (e.g., start = 255 and idx = 0, sh should be 1)
  319. */
  320. } else if (sh <= -64) {
  321. sh = 0x100 - start + idx;
  322. /*
  323. * If < 0 but > -64, out of window. idx is before start
  324. * but not wrapped. Shift the indices around.
  325. */
  326. } else if (sh < 0) {
  327. /* Shift by how far start is ahead of idx */
  328. sh = start - idx;
  329. bitmap = bitmap << sh;
  330. /* Now idx is the new start so sh = 0 */
  331. start = idx;
  332. sh = 0;
  333. }
  334. /* Sequence number start + sh was sent in this batch */
  335. bitmap |= 1ULL << sh;
  336. IWL_DEBUG_TX_REPLY(priv, "start=%d bitmap=0x%llx\n",
  337. start, (unsigned long long)bitmap);
  338. }
  339. /*
  340. * Store the bitmap and possibly the new start, if we wrapped
  341. * the buffer above
  342. */
  343. agg->bitmap = bitmap;
  344. agg->start_idx = start;
  345. IWL_DEBUG_TX_REPLY(priv, "Frames %d start_idx=%d bitmap=0x%llx\n",
  346. agg->frame_count, agg->start_idx,
  347. (unsigned long long)agg->bitmap);
  348. if (bitmap)
  349. agg->wait_for_ba = 1;
  350. }
  351. return 0;
  352. }
  353. void iwl_check_abort_status(struct iwl_priv *priv,
  354. u8 frame_count, u32 status)
  355. {
  356. if (frame_count == 1 && status == TX_STATUS_FAIL_RFKILL_FLUSH) {
  357. IWL_ERR(priv, "Tx flush command to flush out all frames\n");
  358. if (!test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  359. queue_work(priv->shrd->workqueue, &priv->tx_flush);
  360. }
  361. }
  362. void iwlagn_rx_reply_tx(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
  363. {
  364. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  365. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  366. int txq_id = SEQ_TO_QUEUE(sequence);
  367. int index = SEQ_TO_INDEX(sequence);
  368. struct iwl_tx_queue *txq = &priv->txq[txq_id];
  369. struct ieee80211_tx_info *info;
  370. struct iwlagn_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
  371. struct ieee80211_hdr *hdr;
  372. struct iwl_tx_info *txb;
  373. u32 status = le16_to_cpu(tx_resp->status.status);
  374. int tid;
  375. int sta_id;
  376. int freed;
  377. unsigned long flags;
  378. if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) {
  379. IWL_ERR(priv, "%s: Read index for DMA queue txq_id (%d) "
  380. "index %d is out of range [0-%d] %d %d\n", __func__,
  381. txq_id, index, txq->q.n_bd, txq->q.write_ptr,
  382. txq->q.read_ptr);
  383. return;
  384. }
  385. txq->time_stamp = jiffies;
  386. txb = &txq->txb[txq->q.read_ptr];
  387. info = IEEE80211_SKB_CB(txb->skb);
  388. memset(&info->status, 0, sizeof(info->status));
  389. tid = (tx_resp->ra_tid & IWLAGN_TX_RES_TID_MSK) >>
  390. IWLAGN_TX_RES_TID_POS;
  391. sta_id = (tx_resp->ra_tid & IWLAGN_TX_RES_RA_MSK) >>
  392. IWLAGN_TX_RES_RA_POS;
  393. spin_lock_irqsave(&priv->shrd->sta_lock, flags);
  394. hdr = (void *)txb->skb->data;
  395. if (!ieee80211_is_data_qos(hdr->frame_control))
  396. priv->last_seq_ctl = tx_resp->seq_ctl;
  397. if (txq->sched_retry) {
  398. const u32 scd_ssn = iwlagn_get_scd_ssn(tx_resp);
  399. struct iwl_ht_agg *agg;
  400. agg = &priv->stations[sta_id].tid[tid].agg;
  401. /*
  402. * If the BT kill count is non-zero, we'll get this
  403. * notification again.
  404. */
  405. if (tx_resp->bt_kill_count && tx_resp->frame_count == 1 &&
  406. priv->cfg->bt_params &&
  407. priv->cfg->bt_params->advanced_bt_coexist) {
  408. IWL_DEBUG_COEX(priv, "receive reply tx with bt_kill\n");
  409. }
  410. iwlagn_tx_status_reply_tx(priv, agg, tx_resp, txq_id, index);
  411. /* check if BAR is needed */
  412. if ((tx_resp->frame_count == 1) && !iwl_is_tx_success(status))
  413. info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
  414. if (txq->q.read_ptr != (scd_ssn & 0xff)) {
  415. index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
  416. IWL_DEBUG_TX_REPLY(priv, "Retry scheduler reclaim "
  417. "scd_ssn=%d idx=%d txq=%d swq=%d\n",
  418. scd_ssn , index, txq_id, txq->swq_id);
  419. freed = iwlagn_tx_queue_reclaim(priv, txq_id, index);
  420. iwl_free_tfds_in_queue(priv, sta_id, tid, freed);
  421. if (priv->mac80211_registered &&
  422. (iwl_queue_space(&txq->q) > txq->q.low_mark) &&
  423. (agg->state != IWL_EMPTYING_HW_QUEUE_DELBA))
  424. iwl_wake_queue(priv, txq);
  425. }
  426. } else {
  427. iwlagn_set_tx_status(priv, info, txb->ctx, tx_resp,
  428. txq_id, false);
  429. freed = iwlagn_tx_queue_reclaim(priv, txq_id, index);
  430. iwl_free_tfds_in_queue(priv, sta_id, tid, freed);
  431. if (priv->mac80211_registered &&
  432. iwl_queue_space(&txq->q) > txq->q.low_mark &&
  433. status != TX_STATUS_FAIL_PASSIVE_NO_RX)
  434. iwl_wake_queue(priv, txq);
  435. }
  436. iwlagn_txq_check_empty(priv, sta_id, tid, txq_id);
  437. iwl_check_abort_status(priv, tx_resp->frame_count, status);
  438. spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
  439. }
  440. int iwlagn_hw_valid_rtc_data_addr(u32 addr)
  441. {
  442. return (addr >= IWLAGN_RTC_DATA_LOWER_BOUND) &&
  443. (addr < IWLAGN_RTC_DATA_UPPER_BOUND);
  444. }
  445. int iwlagn_send_tx_power(struct iwl_priv *priv)
  446. {
  447. struct iwlagn_tx_power_dbm_cmd tx_power_cmd;
  448. u8 tx_ant_cfg_cmd;
  449. if (WARN_ONCE(test_bit(STATUS_SCAN_HW, &priv->shrd->status),
  450. "TX Power requested while scanning!\n"))
  451. return -EAGAIN;
  452. /* half dBm need to multiply */
  453. tx_power_cmd.global_lmt = (s8)(2 * priv->tx_power_user_lmt);
  454. if (priv->tx_power_lmt_in_half_dbm &&
  455. priv->tx_power_lmt_in_half_dbm < tx_power_cmd.global_lmt) {
  456. /*
  457. * For the newer devices which using enhanced/extend tx power
  458. * table in EEPROM, the format is in half dBm. driver need to
  459. * convert to dBm format before report to mac80211.
  460. * By doing so, there is a possibility of 1/2 dBm resolution
  461. * lost. driver will perform "round-up" operation before
  462. * reporting, but it will cause 1/2 dBm tx power over the
  463. * regulatory limit. Perform the checking here, if the
  464. * "tx_power_user_lmt" is higher than EEPROM value (in
  465. * half-dBm format), lower the tx power based on EEPROM
  466. */
  467. tx_power_cmd.global_lmt = priv->tx_power_lmt_in_half_dbm;
  468. }
  469. tx_power_cmd.flags = IWLAGN_TX_POWER_NO_CLOSED;
  470. tx_power_cmd.srv_chan_lmt = IWLAGN_TX_POWER_AUTO;
  471. if (IWL_UCODE_API(priv->ucode_ver) == 1)
  472. tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD_V1;
  473. else
  474. tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD;
  475. return iwl_trans_send_cmd_pdu(trans(priv), tx_ant_cfg_cmd, CMD_SYNC,
  476. sizeof(tx_power_cmd), &tx_power_cmd);
  477. }
  478. void iwlagn_temperature(struct iwl_priv *priv)
  479. {
  480. /* store temperature from correct statistics (in Celsius) */
  481. priv->temperature = le32_to_cpu(priv->statistics.common.temperature);
  482. iwl_tt_handler(priv);
  483. }
  484. u16 iwlagn_eeprom_calib_version(struct iwl_priv *priv)
  485. {
  486. struct iwl_eeprom_calib_hdr {
  487. u8 version;
  488. u8 pa_type;
  489. u16 voltage;
  490. } *hdr;
  491. hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv,
  492. EEPROM_CALIB_ALL);
  493. return hdr->version;
  494. }
  495. /*
  496. * EEPROM
  497. */
  498. static u32 eeprom_indirect_address(const struct iwl_priv *priv, u32 address)
  499. {
  500. u16 offset = 0;
  501. if ((address & INDIRECT_ADDRESS) == 0)
  502. return address;
  503. switch (address & INDIRECT_TYPE_MSK) {
  504. case INDIRECT_HOST:
  505. offset = iwl_eeprom_query16(priv, EEPROM_LINK_HOST);
  506. break;
  507. case INDIRECT_GENERAL:
  508. offset = iwl_eeprom_query16(priv, EEPROM_LINK_GENERAL);
  509. break;
  510. case INDIRECT_REGULATORY:
  511. offset = iwl_eeprom_query16(priv, EEPROM_LINK_REGULATORY);
  512. break;
  513. case INDIRECT_TXP_LIMIT:
  514. offset = iwl_eeprom_query16(priv, EEPROM_LINK_TXP_LIMIT);
  515. break;
  516. case INDIRECT_TXP_LIMIT_SIZE:
  517. offset = iwl_eeprom_query16(priv, EEPROM_LINK_TXP_LIMIT_SIZE);
  518. break;
  519. case INDIRECT_CALIBRATION:
  520. offset = iwl_eeprom_query16(priv, EEPROM_LINK_CALIBRATION);
  521. break;
  522. case INDIRECT_PROCESS_ADJST:
  523. offset = iwl_eeprom_query16(priv, EEPROM_LINK_PROCESS_ADJST);
  524. break;
  525. case INDIRECT_OTHERS:
  526. offset = iwl_eeprom_query16(priv, EEPROM_LINK_OTHERS);
  527. break;
  528. default:
  529. IWL_ERR(priv, "illegal indirect type: 0x%X\n",
  530. address & INDIRECT_TYPE_MSK);
  531. break;
  532. }
  533. /* translate the offset from words to byte */
  534. return (address & ADDRESS_MSK) + (offset << 1);
  535. }
  536. const u8 *iwl_eeprom_query_addr(const struct iwl_priv *priv, size_t offset)
  537. {
  538. u32 address = eeprom_indirect_address(priv, offset);
  539. BUG_ON(address >= priv->cfg->base_params->eeprom_size);
  540. return &priv->eeprom[address];
  541. }
  542. struct iwl_mod_params iwlagn_mod_params = {
  543. .amsdu_size_8K = 1,
  544. .restart_fw = 1,
  545. .plcp_check = true,
  546. .bt_coex_active = true,
  547. .no_sleep_autoadjust = true,
  548. .power_level = IWL_POWER_INDEX_1,
  549. .bt_ch_announce = 1,
  550. .wanted_ucode_alternative = 1,
  551. /* the rest are 0 by default */
  552. };
  553. int iwlagn_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band)
  554. {
  555. int idx = 0;
  556. int band_offset = 0;
  557. /* HT rate format: mac80211 wants an MCS number, which is just LSB */
  558. if (rate_n_flags & RATE_MCS_HT_MSK) {
  559. idx = (rate_n_flags & 0xff);
  560. return idx;
  561. /* Legacy rate format, search for match in table */
  562. } else {
  563. if (band == IEEE80211_BAND_5GHZ)
  564. band_offset = IWL_FIRST_OFDM_RATE;
  565. for (idx = band_offset; idx < IWL_RATE_COUNT_LEGACY; idx++)
  566. if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
  567. return idx - band_offset;
  568. }
  569. return -1;
  570. }
  571. static int iwl_get_single_channel_for_scan(struct iwl_priv *priv,
  572. struct ieee80211_vif *vif,
  573. enum ieee80211_band band,
  574. struct iwl_scan_channel *scan_ch)
  575. {
  576. const struct ieee80211_supported_band *sband;
  577. u16 passive_dwell = 0;
  578. u16 active_dwell = 0;
  579. int added = 0;
  580. u16 channel = 0;
  581. sband = iwl_get_hw_mode(priv, band);
  582. if (!sband) {
  583. IWL_ERR(priv, "invalid band\n");
  584. return added;
  585. }
  586. active_dwell = iwl_get_active_dwell_time(priv, band, 0);
  587. passive_dwell = iwl_get_passive_dwell_time(priv, band, vif);
  588. if (passive_dwell <= active_dwell)
  589. passive_dwell = active_dwell + 1;
  590. channel = iwl_get_single_channel_number(priv, band);
  591. if (channel) {
  592. scan_ch->channel = cpu_to_le16(channel);
  593. scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
  594. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  595. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  596. /* Set txpower levels to defaults */
  597. scan_ch->dsp_atten = 110;
  598. if (band == IEEE80211_BAND_5GHZ)
  599. scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
  600. else
  601. scan_ch->tx_gain = ((1 << 5) | (5 << 3));
  602. added++;
  603. } else
  604. IWL_ERR(priv, "no valid channel found\n");
  605. return added;
  606. }
  607. static int iwl_get_channels_for_scan(struct iwl_priv *priv,
  608. struct ieee80211_vif *vif,
  609. enum ieee80211_band band,
  610. u8 is_active, u8 n_probes,
  611. struct iwl_scan_channel *scan_ch)
  612. {
  613. struct ieee80211_channel *chan;
  614. const struct ieee80211_supported_band *sband;
  615. const struct iwl_channel_info *ch_info;
  616. u16 passive_dwell = 0;
  617. u16 active_dwell = 0;
  618. int added, i;
  619. u16 channel;
  620. sband = iwl_get_hw_mode(priv, band);
  621. if (!sband)
  622. return 0;
  623. active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
  624. passive_dwell = iwl_get_passive_dwell_time(priv, band, vif);
  625. if (passive_dwell <= active_dwell)
  626. passive_dwell = active_dwell + 1;
  627. for (i = 0, added = 0; i < priv->scan_request->n_channels; i++) {
  628. chan = priv->scan_request->channels[i];
  629. if (chan->band != band)
  630. continue;
  631. channel = chan->hw_value;
  632. scan_ch->channel = cpu_to_le16(channel);
  633. ch_info = iwl_get_channel_info(priv, band, channel);
  634. if (!is_channel_valid(ch_info)) {
  635. IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
  636. channel);
  637. continue;
  638. }
  639. if (!is_active || is_channel_passive(ch_info) ||
  640. (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN))
  641. scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
  642. else
  643. scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE;
  644. if (n_probes)
  645. scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes);
  646. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  647. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  648. /* Set txpower levels to defaults */
  649. scan_ch->dsp_atten = 110;
  650. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  651. * power level:
  652. * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
  653. */
  654. if (band == IEEE80211_BAND_5GHZ)
  655. scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
  656. else
  657. scan_ch->tx_gain = ((1 << 5) | (5 << 3));
  658. IWL_DEBUG_SCAN(priv, "Scanning ch=%d prob=0x%X [%s %d]\n",
  659. channel, le32_to_cpu(scan_ch->type),
  660. (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ?
  661. "ACTIVE" : "PASSIVE",
  662. (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ?
  663. active_dwell : passive_dwell);
  664. scan_ch++;
  665. added++;
  666. }
  667. IWL_DEBUG_SCAN(priv, "total channels to scan %d\n", added);
  668. return added;
  669. }
  670. int iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
  671. {
  672. struct iwl_host_cmd cmd = {
  673. .id = REPLY_SCAN_CMD,
  674. .len = { sizeof(struct iwl_scan_cmd), },
  675. .flags = CMD_SYNC,
  676. };
  677. struct iwl_scan_cmd *scan;
  678. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  679. u32 rate_flags = 0;
  680. u16 cmd_len;
  681. u16 rx_chain = 0;
  682. enum ieee80211_band band;
  683. u8 n_probes = 0;
  684. u8 rx_ant = hw_params(priv).valid_rx_ant;
  685. u8 rate;
  686. bool is_active = false;
  687. int chan_mod;
  688. u8 active_chains;
  689. u8 scan_tx_antennas = hw_params(priv).valid_tx_ant;
  690. int ret;
  691. lockdep_assert_held(&priv->shrd->mutex);
  692. if (vif)
  693. ctx = iwl_rxon_ctx_from_vif(vif);
  694. if (!priv->scan_cmd) {
  695. priv->scan_cmd = kmalloc(sizeof(struct iwl_scan_cmd) +
  696. IWL_MAX_SCAN_SIZE, GFP_KERNEL);
  697. if (!priv->scan_cmd) {
  698. IWL_DEBUG_SCAN(priv,
  699. "fail to allocate memory for scan\n");
  700. return -ENOMEM;
  701. }
  702. }
  703. scan = priv->scan_cmd;
  704. memset(scan, 0, sizeof(struct iwl_scan_cmd) + IWL_MAX_SCAN_SIZE);
  705. scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
  706. scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
  707. if (priv->scan_type != IWL_SCAN_ROC &&
  708. iwl_is_any_associated(priv)) {
  709. u16 interval = 0;
  710. u32 extra;
  711. u32 suspend_time = 100;
  712. u32 scan_suspend_time = 100;
  713. IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
  714. switch (priv->scan_type) {
  715. case IWL_SCAN_ROC:
  716. WARN_ON(1);
  717. break;
  718. case IWL_SCAN_RADIO_RESET:
  719. interval = 0;
  720. break;
  721. case IWL_SCAN_NORMAL:
  722. interval = vif->bss_conf.beacon_int;
  723. break;
  724. }
  725. scan->suspend_time = 0;
  726. scan->max_out_time = cpu_to_le32(200 * 1024);
  727. if (!interval)
  728. interval = suspend_time;
  729. extra = (suspend_time / interval) << 22;
  730. scan_suspend_time = (extra |
  731. ((suspend_time % interval) * 1024));
  732. scan->suspend_time = cpu_to_le32(scan_suspend_time);
  733. IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
  734. scan_suspend_time, interval);
  735. } else if (priv->scan_type == IWL_SCAN_ROC) {
  736. scan->suspend_time = 0;
  737. scan->max_out_time = 0;
  738. scan->quiet_time = 0;
  739. scan->quiet_plcp_th = 0;
  740. }
  741. switch (priv->scan_type) {
  742. case IWL_SCAN_RADIO_RESET:
  743. IWL_DEBUG_SCAN(priv, "Start internal passive scan.\n");
  744. break;
  745. case IWL_SCAN_NORMAL:
  746. if (priv->scan_request->n_ssids) {
  747. int i, p = 0;
  748. IWL_DEBUG_SCAN(priv, "Kicking off active scan\n");
  749. for (i = 0; i < priv->scan_request->n_ssids; i++) {
  750. /* always does wildcard anyway */
  751. if (!priv->scan_request->ssids[i].ssid_len)
  752. continue;
  753. scan->direct_scan[p].id = WLAN_EID_SSID;
  754. scan->direct_scan[p].len =
  755. priv->scan_request->ssids[i].ssid_len;
  756. memcpy(scan->direct_scan[p].ssid,
  757. priv->scan_request->ssids[i].ssid,
  758. priv->scan_request->ssids[i].ssid_len);
  759. n_probes++;
  760. p++;
  761. }
  762. is_active = true;
  763. } else
  764. IWL_DEBUG_SCAN(priv, "Start passive scan.\n");
  765. break;
  766. case IWL_SCAN_ROC:
  767. IWL_DEBUG_SCAN(priv, "Start ROC scan.\n");
  768. break;
  769. }
  770. scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
  771. scan->tx_cmd.sta_id = ctx->bcast_sta_id;
  772. scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  773. switch (priv->scan_band) {
  774. case IEEE80211_BAND_2GHZ:
  775. scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
  776. chan_mod = le32_to_cpu(
  777. priv->contexts[IWL_RXON_CTX_BSS].active.flags &
  778. RXON_FLG_CHANNEL_MODE_MSK)
  779. >> RXON_FLG_CHANNEL_MODE_POS;
  780. if (chan_mod == CHANNEL_MODE_PURE_40) {
  781. rate = IWL_RATE_6M_PLCP;
  782. } else {
  783. rate = IWL_RATE_1M_PLCP;
  784. rate_flags = RATE_MCS_CCK_MSK;
  785. }
  786. /*
  787. * Internal scans are passive, so we can indiscriminately set
  788. * the BT ignore flag on 2.4 GHz since it applies to TX only.
  789. */
  790. if (priv->cfg->bt_params &&
  791. priv->cfg->bt_params->advanced_bt_coexist)
  792. scan->tx_cmd.tx_flags |= TX_CMD_FLG_IGNORE_BT;
  793. break;
  794. case IEEE80211_BAND_5GHZ:
  795. rate = IWL_RATE_6M_PLCP;
  796. break;
  797. default:
  798. IWL_WARN(priv, "Invalid scan band\n");
  799. return -EIO;
  800. }
  801. /*
  802. * If active scanning is requested but a certain channel is
  803. * marked passive, we can do active scanning if we detect
  804. * transmissions.
  805. *
  806. * There is an issue with some firmware versions that triggers
  807. * a sysassert on a "good CRC threshold" of zero (== disabled),
  808. * on a radar channel even though this means that we should NOT
  809. * send probes.
  810. *
  811. * The "good CRC threshold" is the number of frames that we
  812. * need to receive during our dwell time on a channel before
  813. * sending out probes -- setting this to a huge value will
  814. * mean we never reach it, but at the same time work around
  815. * the aforementioned issue. Thus use IWL_GOOD_CRC_TH_NEVER
  816. * here instead of IWL_GOOD_CRC_TH_DISABLED.
  817. *
  818. * This was fixed in later versions along with some other
  819. * scan changes, and the threshold behaves as a flag in those
  820. * versions.
  821. */
  822. if (priv->new_scan_threshold_behaviour)
  823. scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT :
  824. IWL_GOOD_CRC_TH_DISABLED;
  825. else
  826. scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT :
  827. IWL_GOOD_CRC_TH_NEVER;
  828. band = priv->scan_band;
  829. if (priv->cfg->scan_rx_antennas[band])
  830. rx_ant = priv->cfg->scan_rx_antennas[band];
  831. if (band == IEEE80211_BAND_2GHZ &&
  832. priv->cfg->bt_params &&
  833. priv->cfg->bt_params->advanced_bt_coexist) {
  834. /* transmit 2.4 GHz probes only on first antenna */
  835. scan_tx_antennas = first_antenna(scan_tx_antennas);
  836. }
  837. priv->scan_tx_ant[band] = iwl_toggle_tx_ant(priv, priv->scan_tx_ant[band],
  838. scan_tx_antennas);
  839. rate_flags |= iwl_ant_idx_to_flags(priv->scan_tx_ant[band]);
  840. scan->tx_cmd.rate_n_flags = iwl_hw_set_rate_n_flags(rate, rate_flags);
  841. /* In power save mode use one chain, otherwise use all chains */
  842. if (test_bit(STATUS_POWER_PMI, &priv->shrd->status)) {
  843. /* rx_ant has been set to all valid chains previously */
  844. active_chains = rx_ant &
  845. ((u8)(priv->chain_noise_data.active_chains));
  846. if (!active_chains)
  847. active_chains = rx_ant;
  848. IWL_DEBUG_SCAN(priv, "chain_noise_data.active_chains: %u\n",
  849. priv->chain_noise_data.active_chains);
  850. rx_ant = first_antenna(active_chains);
  851. }
  852. if (priv->cfg->bt_params &&
  853. priv->cfg->bt_params->advanced_bt_coexist &&
  854. priv->bt_full_concurrent) {
  855. /* operated as 1x1 in full concurrency mode */
  856. rx_ant = first_antenna(rx_ant);
  857. }
  858. /* MIMO is not used here, but value is required */
  859. rx_chain |=
  860. hw_params(priv).valid_rx_ant << RXON_RX_CHAIN_VALID_POS;
  861. rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS;
  862. rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_SEL_POS;
  863. rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS;
  864. scan->rx_chain = cpu_to_le16(rx_chain);
  865. switch (priv->scan_type) {
  866. case IWL_SCAN_NORMAL:
  867. cmd_len = iwl_fill_probe_req(priv,
  868. (struct ieee80211_mgmt *)scan->data,
  869. vif->addr,
  870. priv->scan_request->ie,
  871. priv->scan_request->ie_len,
  872. IWL_MAX_SCAN_SIZE - sizeof(*scan));
  873. break;
  874. case IWL_SCAN_RADIO_RESET:
  875. case IWL_SCAN_ROC:
  876. /* use bcast addr, will not be transmitted but must be valid */
  877. cmd_len = iwl_fill_probe_req(priv,
  878. (struct ieee80211_mgmt *)scan->data,
  879. iwl_bcast_addr, NULL, 0,
  880. IWL_MAX_SCAN_SIZE - sizeof(*scan));
  881. break;
  882. default:
  883. BUG();
  884. }
  885. scan->tx_cmd.len = cpu_to_le16(cmd_len);
  886. scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK |
  887. RXON_FILTER_BCON_AWARE_MSK);
  888. switch (priv->scan_type) {
  889. case IWL_SCAN_RADIO_RESET:
  890. scan->channel_count =
  891. iwl_get_single_channel_for_scan(priv, vif, band,
  892. (void *)&scan->data[cmd_len]);
  893. break;
  894. case IWL_SCAN_NORMAL:
  895. scan->channel_count =
  896. iwl_get_channels_for_scan(priv, vif, band,
  897. is_active, n_probes,
  898. (void *)&scan->data[cmd_len]);
  899. break;
  900. case IWL_SCAN_ROC: {
  901. struct iwl_scan_channel *scan_ch;
  902. scan->channel_count = 1;
  903. scan_ch = (void *)&scan->data[cmd_len];
  904. scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
  905. scan_ch->channel =
  906. cpu_to_le16(priv->hw_roc_channel->hw_value);
  907. scan_ch->active_dwell =
  908. scan_ch->passive_dwell =
  909. cpu_to_le16(priv->hw_roc_duration);
  910. /* Set txpower levels to defaults */
  911. scan_ch->dsp_atten = 110;
  912. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  913. * power level:
  914. * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
  915. */
  916. if (priv->hw_roc_channel->band == IEEE80211_BAND_5GHZ)
  917. scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
  918. else
  919. scan_ch->tx_gain = ((1 << 5) | (5 << 3));
  920. }
  921. break;
  922. }
  923. if (scan->channel_count == 0) {
  924. IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
  925. return -EIO;
  926. }
  927. cmd.len[0] += le16_to_cpu(scan->tx_cmd.len) +
  928. scan->channel_count * sizeof(struct iwl_scan_channel);
  929. cmd.data[0] = scan;
  930. cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
  931. scan->len = cpu_to_le16(cmd.len[0]);
  932. /* set scan bit here for PAN params */
  933. set_bit(STATUS_SCAN_HW, &priv->shrd->status);
  934. ret = iwlagn_set_pan_params(priv);
  935. if (ret)
  936. return ret;
  937. ret = iwl_trans_send_cmd(trans(priv), &cmd);
  938. if (ret) {
  939. clear_bit(STATUS_SCAN_HW, &priv->shrd->status);
  940. iwlagn_set_pan_params(priv);
  941. }
  942. return ret;
  943. }
  944. int iwlagn_manage_ibss_station(struct iwl_priv *priv,
  945. struct ieee80211_vif *vif, bool add)
  946. {
  947. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  948. if (add)
  949. return iwlagn_add_bssid_station(priv, vif_priv->ctx,
  950. vif->bss_conf.bssid,
  951. &vif_priv->ibss_bssid_sta_id);
  952. return iwl_remove_station(priv, vif_priv->ibss_bssid_sta_id,
  953. vif->bss_conf.bssid);
  954. }
  955. void iwl_free_tfds_in_queue(struct iwl_priv *priv,
  956. int sta_id, int tid, int freed)
  957. {
  958. lockdep_assert_held(&priv->shrd->sta_lock);
  959. if (priv->stations[sta_id].tid[tid].tfds_in_queue >= freed)
  960. priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
  961. else {
  962. IWL_DEBUG_TX(priv, "free more than tfds_in_queue (%u:%d)\n",
  963. priv->stations[sta_id].tid[tid].tfds_in_queue,
  964. freed);
  965. priv->stations[sta_id].tid[tid].tfds_in_queue = 0;
  966. }
  967. }
  968. #define IWL_FLUSH_WAIT_MS 2000
  969. int iwlagn_wait_tx_queue_empty(struct iwl_priv *priv)
  970. {
  971. struct iwl_tx_queue *txq;
  972. struct iwl_queue *q;
  973. int cnt;
  974. unsigned long now = jiffies;
  975. int ret = 0;
  976. /* waiting for all the tx frames complete might take a while */
  977. for (cnt = 0; cnt < hw_params(priv).max_txq_num; cnt++) {
  978. if (cnt == priv->shrd->cmd_queue)
  979. continue;
  980. txq = &priv->txq[cnt];
  981. q = &txq->q;
  982. while (q->read_ptr != q->write_ptr && !time_after(jiffies,
  983. now + msecs_to_jiffies(IWL_FLUSH_WAIT_MS)))
  984. msleep(1);
  985. if (q->read_ptr != q->write_ptr) {
  986. IWL_ERR(priv, "fail to flush all tx fifo queues\n");
  987. ret = -ETIMEDOUT;
  988. break;
  989. }
  990. }
  991. return ret;
  992. }
  993. #define IWL_TX_QUEUE_MSK 0xfffff
  994. /**
  995. * iwlagn_txfifo_flush: send REPLY_TXFIFO_FLUSH command to uCode
  996. *
  997. * pre-requirements:
  998. * 1. acquire mutex before calling
  999. * 2. make sure rf is on and not in exit state
  1000. */
  1001. int iwlagn_txfifo_flush(struct iwl_priv *priv, u16 flush_control)
  1002. {
  1003. struct iwl_txfifo_flush_cmd flush_cmd;
  1004. struct iwl_host_cmd cmd = {
  1005. .id = REPLY_TXFIFO_FLUSH,
  1006. .len = { sizeof(struct iwl_txfifo_flush_cmd), },
  1007. .flags = CMD_SYNC,
  1008. .data = { &flush_cmd, },
  1009. };
  1010. might_sleep();
  1011. memset(&flush_cmd, 0, sizeof(flush_cmd));
  1012. if (flush_control & BIT(IWL_RXON_CTX_BSS))
  1013. flush_cmd.fifo_control = IWL_SCD_VO_MSK | IWL_SCD_VI_MSK |
  1014. IWL_SCD_BE_MSK | IWL_SCD_BK_MSK |
  1015. IWL_SCD_MGMT_MSK;
  1016. if ((flush_control & BIT(IWL_RXON_CTX_PAN)) &&
  1017. (priv->valid_contexts != BIT(IWL_RXON_CTX_BSS)))
  1018. flush_cmd.fifo_control |= IWL_PAN_SCD_VO_MSK |
  1019. IWL_PAN_SCD_VI_MSK | IWL_PAN_SCD_BE_MSK |
  1020. IWL_PAN_SCD_BK_MSK | IWL_PAN_SCD_MGMT_MSK |
  1021. IWL_PAN_SCD_MULTICAST_MSK;
  1022. if (priv->cfg->sku & EEPROM_SKU_CAP_11N_ENABLE)
  1023. flush_cmd.fifo_control |= IWL_AGG_TX_QUEUE_MSK;
  1024. IWL_DEBUG_INFO(priv, "fifo queue control: 0X%x\n",
  1025. flush_cmd.fifo_control);
  1026. flush_cmd.flush_control = cpu_to_le16(flush_control);
  1027. return iwl_trans_send_cmd(trans(priv), &cmd);
  1028. }
  1029. void iwlagn_dev_txfifo_flush(struct iwl_priv *priv, u16 flush_control)
  1030. {
  1031. mutex_lock(&priv->shrd->mutex);
  1032. ieee80211_stop_queues(priv->hw);
  1033. if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) {
  1034. IWL_ERR(priv, "flush request fail\n");
  1035. goto done;
  1036. }
  1037. IWL_DEBUG_INFO(priv, "wait transmit/flush all frames\n");
  1038. iwlagn_wait_tx_queue_empty(priv);
  1039. done:
  1040. ieee80211_wake_queues(priv->hw);
  1041. mutex_unlock(&priv->shrd->mutex);
  1042. }
  1043. /*
  1044. * BT coex
  1045. */
  1046. /*
  1047. * Macros to access the lookup table.
  1048. *
  1049. * The lookup table has 7 inputs: bt3_prio, bt3_txrx, bt_rf_act, wifi_req,
  1050. * wifi_prio, wifi_txrx and wifi_sh_ant_req.
  1051. *
  1052. * It has three outputs: WLAN_ACTIVE, WLAN_KILL and ANT_SWITCH
  1053. *
  1054. * The format is that "registers" 8 through 11 contain the WLAN_ACTIVE bits
  1055. * one after another in 32-bit registers, and "registers" 0 through 7 contain
  1056. * the WLAN_KILL and ANT_SWITCH bits interleaved (in that order).
  1057. *
  1058. * These macros encode that format.
  1059. */
  1060. #define LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, wifi_req, wifi_prio, \
  1061. wifi_txrx, wifi_sh_ant_req) \
  1062. (bt3_prio | (bt3_txrx << 1) | (bt_rf_act << 2) | (wifi_req << 3) | \
  1063. (wifi_prio << 4) | (wifi_txrx << 5) | (wifi_sh_ant_req << 6))
  1064. #define LUT_PTA_WLAN_ACTIVE_OP(lut, op, val) \
  1065. lut[8 + ((val) >> 5)] op (cpu_to_le32(BIT((val) & 0x1f)))
  1066. #define LUT_TEST_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1067. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1068. (!!(LUT_PTA_WLAN_ACTIVE_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, \
  1069. bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
  1070. wifi_sh_ant_req))))
  1071. #define LUT_SET_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1072. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1073. LUT_PTA_WLAN_ACTIVE_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, \
  1074. bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
  1075. wifi_sh_ant_req))
  1076. #define LUT_CLEAR_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, \
  1077. wifi_req, wifi_prio, wifi_txrx, \
  1078. wifi_sh_ant_req) \
  1079. LUT_PTA_WLAN_ACTIVE_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, \
  1080. bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
  1081. wifi_sh_ant_req))
  1082. #define LUT_WLAN_KILL_OP(lut, op, val) \
  1083. lut[(val) >> 4] op (cpu_to_le32(BIT(((val) << 1) & 0x1e)))
  1084. #define LUT_TEST_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1085. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1086. (!!(LUT_WLAN_KILL_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1087. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))))
  1088. #define LUT_SET_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1089. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1090. LUT_WLAN_KILL_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1091. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  1092. #define LUT_CLEAR_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1093. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1094. LUT_WLAN_KILL_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1095. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  1096. #define LUT_ANT_SWITCH_OP(lut, op, val) \
  1097. lut[(val) >> 4] op (cpu_to_le32(BIT((((val) << 1) & 0x1e) + 1)))
  1098. #define LUT_TEST_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1099. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1100. (!!(LUT_ANT_SWITCH_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1101. wifi_req, wifi_prio, wifi_txrx, \
  1102. wifi_sh_ant_req))))
  1103. #define LUT_SET_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1104. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1105. LUT_ANT_SWITCH_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1106. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  1107. #define LUT_CLEAR_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1108. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1109. LUT_ANT_SWITCH_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1110. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  1111. static const __le32 iwlagn_def_3w_lookup[12] = {
  1112. cpu_to_le32(0xaaaaaaaa),
  1113. cpu_to_le32(0xaaaaaaaa),
  1114. cpu_to_le32(0xaeaaaaaa),
  1115. cpu_to_le32(0xaaaaaaaa),
  1116. cpu_to_le32(0xcc00ff28),
  1117. cpu_to_le32(0x0000aaaa),
  1118. cpu_to_le32(0xcc00aaaa),
  1119. cpu_to_le32(0x0000aaaa),
  1120. cpu_to_le32(0xc0004000),
  1121. cpu_to_le32(0x00004000),
  1122. cpu_to_le32(0xf0005000),
  1123. cpu_to_le32(0xf0005000),
  1124. };
  1125. static const __le32 iwlagn_concurrent_lookup[12] = {
  1126. cpu_to_le32(0xaaaaaaaa),
  1127. cpu_to_le32(0xaaaaaaaa),
  1128. cpu_to_le32(0xaaaaaaaa),
  1129. cpu_to_le32(0xaaaaaaaa),
  1130. cpu_to_le32(0xaaaaaaaa),
  1131. cpu_to_le32(0xaaaaaaaa),
  1132. cpu_to_le32(0xaaaaaaaa),
  1133. cpu_to_le32(0xaaaaaaaa),
  1134. cpu_to_le32(0x00000000),
  1135. cpu_to_le32(0x00000000),
  1136. cpu_to_le32(0x00000000),
  1137. cpu_to_le32(0x00000000),
  1138. };
  1139. void iwlagn_send_advance_bt_config(struct iwl_priv *priv)
  1140. {
  1141. struct iwl_basic_bt_cmd basic = {
  1142. .max_kill = IWLAGN_BT_MAX_KILL_DEFAULT,
  1143. .bt3_timer_t7_value = IWLAGN_BT3_T7_DEFAULT,
  1144. .bt3_prio_sample_time = IWLAGN_BT3_PRIO_SAMPLE_DEFAULT,
  1145. .bt3_timer_t2_value = IWLAGN_BT3_T2_DEFAULT,
  1146. };
  1147. struct iwl6000_bt_cmd bt_cmd_6000;
  1148. struct iwl2000_bt_cmd bt_cmd_2000;
  1149. int ret;
  1150. BUILD_BUG_ON(sizeof(iwlagn_def_3w_lookup) !=
  1151. sizeof(basic.bt3_lookup_table));
  1152. if (priv->cfg->bt_params) {
  1153. if (priv->cfg->bt_params->bt_session_2) {
  1154. bt_cmd_2000.prio_boost = cpu_to_le32(
  1155. priv->cfg->bt_params->bt_prio_boost);
  1156. bt_cmd_2000.tx_prio_boost = 0;
  1157. bt_cmd_2000.rx_prio_boost = 0;
  1158. } else {
  1159. bt_cmd_6000.prio_boost =
  1160. priv->cfg->bt_params->bt_prio_boost;
  1161. bt_cmd_6000.tx_prio_boost = 0;
  1162. bt_cmd_6000.rx_prio_boost = 0;
  1163. }
  1164. } else {
  1165. IWL_ERR(priv, "failed to construct BT Coex Config\n");
  1166. return;
  1167. }
  1168. basic.kill_ack_mask = priv->kill_ack_mask;
  1169. basic.kill_cts_mask = priv->kill_cts_mask;
  1170. basic.valid = priv->bt_valid;
  1171. /*
  1172. * Configure BT coex mode to "no coexistence" when the
  1173. * user disabled BT coexistence, we have no interface
  1174. * (might be in monitor mode), or the interface is in
  1175. * IBSS mode (no proper uCode support for coex then).
  1176. */
  1177. if (!iwlagn_mod_params.bt_coex_active ||
  1178. priv->iw_mode == NL80211_IFTYPE_ADHOC) {
  1179. basic.flags = IWLAGN_BT_FLAG_COEX_MODE_DISABLED;
  1180. } else {
  1181. basic.flags = IWLAGN_BT_FLAG_COEX_MODE_3W <<
  1182. IWLAGN_BT_FLAG_COEX_MODE_SHIFT;
  1183. if (!priv->bt_enable_pspoll)
  1184. basic.flags |= IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE;
  1185. else
  1186. basic.flags &= ~IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE;
  1187. if (priv->bt_ch_announce)
  1188. basic.flags |= IWLAGN_BT_FLAG_CHANNEL_INHIBITION;
  1189. IWL_DEBUG_COEX(priv, "BT coex flag: 0X%x\n", basic.flags);
  1190. }
  1191. priv->bt_enable_flag = basic.flags;
  1192. if (priv->bt_full_concurrent)
  1193. memcpy(basic.bt3_lookup_table, iwlagn_concurrent_lookup,
  1194. sizeof(iwlagn_concurrent_lookup));
  1195. else
  1196. memcpy(basic.bt3_lookup_table, iwlagn_def_3w_lookup,
  1197. sizeof(iwlagn_def_3w_lookup));
  1198. IWL_DEBUG_COEX(priv, "BT coex %s in %s mode\n",
  1199. basic.flags ? "active" : "disabled",
  1200. priv->bt_full_concurrent ?
  1201. "full concurrency" : "3-wire");
  1202. if (priv->cfg->bt_params->bt_session_2) {
  1203. memcpy(&bt_cmd_2000.basic, &basic,
  1204. sizeof(basic));
  1205. ret = iwl_trans_send_cmd_pdu(trans(priv), REPLY_BT_CONFIG,
  1206. CMD_SYNC, sizeof(bt_cmd_2000), &bt_cmd_2000);
  1207. } else {
  1208. memcpy(&bt_cmd_6000.basic, &basic,
  1209. sizeof(basic));
  1210. ret = iwl_trans_send_cmd_pdu(trans(priv), REPLY_BT_CONFIG,
  1211. CMD_SYNC, sizeof(bt_cmd_6000), &bt_cmd_6000);
  1212. }
  1213. if (ret)
  1214. IWL_ERR(priv, "failed to send BT Coex Config\n");
  1215. }
  1216. void iwlagn_bt_adjust_rssi_monitor(struct iwl_priv *priv, bool rssi_ena)
  1217. {
  1218. struct iwl_rxon_context *ctx, *found_ctx = NULL;
  1219. bool found_ap = false;
  1220. lockdep_assert_held(&priv->shrd->mutex);
  1221. /* Check whether AP or GO mode is active. */
  1222. if (rssi_ena) {
  1223. for_each_context(priv, ctx) {
  1224. if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_AP &&
  1225. iwl_is_associated_ctx(ctx)) {
  1226. found_ap = true;
  1227. break;
  1228. }
  1229. }
  1230. }
  1231. /*
  1232. * If disable was received or If GO/AP mode, disable RSSI
  1233. * measurements.
  1234. */
  1235. if (!rssi_ena || found_ap) {
  1236. if (priv->cur_rssi_ctx) {
  1237. ctx = priv->cur_rssi_ctx;
  1238. ieee80211_disable_rssi_reports(ctx->vif);
  1239. priv->cur_rssi_ctx = NULL;
  1240. }
  1241. return;
  1242. }
  1243. /*
  1244. * If rssi measurements need to be enabled, consider all cases now.
  1245. * Figure out how many contexts are active.
  1246. */
  1247. for_each_context(priv, ctx) {
  1248. if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION &&
  1249. iwl_is_associated_ctx(ctx)) {
  1250. found_ctx = ctx;
  1251. break;
  1252. }
  1253. }
  1254. /*
  1255. * rssi monitor already enabled for the correct interface...nothing
  1256. * to do.
  1257. */
  1258. if (found_ctx == priv->cur_rssi_ctx)
  1259. return;
  1260. /*
  1261. * Figure out if rssi monitor is currently enabled, and needs
  1262. * to be changed. If rssi monitor is already enabled, disable
  1263. * it first else just enable rssi measurements on the
  1264. * interface found above.
  1265. */
  1266. if (priv->cur_rssi_ctx) {
  1267. ctx = priv->cur_rssi_ctx;
  1268. if (ctx->vif)
  1269. ieee80211_disable_rssi_reports(ctx->vif);
  1270. }
  1271. priv->cur_rssi_ctx = found_ctx;
  1272. if (!found_ctx)
  1273. return;
  1274. ieee80211_enable_rssi_reports(found_ctx->vif,
  1275. IWLAGN_BT_PSP_MIN_RSSI_THRESHOLD,
  1276. IWLAGN_BT_PSP_MAX_RSSI_THRESHOLD);
  1277. }
  1278. static bool iwlagn_bt_traffic_is_sco(struct iwl_bt_uart_msg *uart_msg)
  1279. {
  1280. return BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3 >>
  1281. BT_UART_MSG_FRAME3SCOESCO_POS;
  1282. }
  1283. static void iwlagn_bt_traffic_change_work(struct work_struct *work)
  1284. {
  1285. struct iwl_priv *priv =
  1286. container_of(work, struct iwl_priv, bt_traffic_change_work);
  1287. struct iwl_rxon_context *ctx;
  1288. int smps_request = -1;
  1289. if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) {
  1290. /* bt coex disabled */
  1291. return;
  1292. }
  1293. /*
  1294. * Note: bt_traffic_load can be overridden by scan complete and
  1295. * coex profile notifications. Ignore that since only bad consequence
  1296. * can be not matching debug print with actual state.
  1297. */
  1298. IWL_DEBUG_COEX(priv, "BT traffic load changes: %d\n",
  1299. priv->bt_traffic_load);
  1300. switch (priv->bt_traffic_load) {
  1301. case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
  1302. if (priv->bt_status)
  1303. smps_request = IEEE80211_SMPS_DYNAMIC;
  1304. else
  1305. smps_request = IEEE80211_SMPS_AUTOMATIC;
  1306. break;
  1307. case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
  1308. smps_request = IEEE80211_SMPS_DYNAMIC;
  1309. break;
  1310. case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
  1311. case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
  1312. smps_request = IEEE80211_SMPS_STATIC;
  1313. break;
  1314. default:
  1315. IWL_ERR(priv, "Invalid BT traffic load: %d\n",
  1316. priv->bt_traffic_load);
  1317. break;
  1318. }
  1319. mutex_lock(&priv->shrd->mutex);
  1320. /*
  1321. * We can not send command to firmware while scanning. When the scan
  1322. * complete we will schedule this work again. We do check with mutex
  1323. * locked to prevent new scan request to arrive. We do not check
  1324. * STATUS_SCANNING to avoid race when queue_work two times from
  1325. * different notifications, but quit and not perform any work at all.
  1326. */
  1327. if (test_bit(STATUS_SCAN_HW, &priv->shrd->status))
  1328. goto out;
  1329. iwl_update_chain_flags(priv);
  1330. if (smps_request != -1) {
  1331. priv->current_ht_config.smps = smps_request;
  1332. for_each_context(priv, ctx) {
  1333. if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION)
  1334. ieee80211_request_smps(ctx->vif, smps_request);
  1335. }
  1336. }
  1337. /*
  1338. * Dynamic PS poll related functionality. Adjust RSSI measurements if
  1339. * necessary.
  1340. */
  1341. iwlagn_bt_coex_rssi_monitor(priv);
  1342. out:
  1343. mutex_unlock(&priv->shrd->mutex);
  1344. }
  1345. /*
  1346. * If BT sco traffic, and RSSI monitor is enabled, move measurements to the
  1347. * correct interface or disable it if this is the last interface to be
  1348. * removed.
  1349. */
  1350. void iwlagn_bt_coex_rssi_monitor(struct iwl_priv *priv)
  1351. {
  1352. if (priv->bt_is_sco &&
  1353. priv->bt_traffic_load == IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS)
  1354. iwlagn_bt_adjust_rssi_monitor(priv, true);
  1355. else
  1356. iwlagn_bt_adjust_rssi_monitor(priv, false);
  1357. }
  1358. static void iwlagn_print_uartmsg(struct iwl_priv *priv,
  1359. struct iwl_bt_uart_msg *uart_msg)
  1360. {
  1361. IWL_DEBUG_COEX(priv, "Message Type = 0x%X, SSN = 0x%X, "
  1362. "Update Req = 0x%X",
  1363. (BT_UART_MSG_FRAME1MSGTYPE_MSK & uart_msg->frame1) >>
  1364. BT_UART_MSG_FRAME1MSGTYPE_POS,
  1365. (BT_UART_MSG_FRAME1SSN_MSK & uart_msg->frame1) >>
  1366. BT_UART_MSG_FRAME1SSN_POS,
  1367. (BT_UART_MSG_FRAME1UPDATEREQ_MSK & uart_msg->frame1) >>
  1368. BT_UART_MSG_FRAME1UPDATEREQ_POS);
  1369. IWL_DEBUG_COEX(priv, "Open connections = 0x%X, Traffic load = 0x%X, "
  1370. "Chl_SeqN = 0x%X, In band = 0x%X",
  1371. (BT_UART_MSG_FRAME2OPENCONNECTIONS_MSK & uart_msg->frame2) >>
  1372. BT_UART_MSG_FRAME2OPENCONNECTIONS_POS,
  1373. (BT_UART_MSG_FRAME2TRAFFICLOAD_MSK & uart_msg->frame2) >>
  1374. BT_UART_MSG_FRAME2TRAFFICLOAD_POS,
  1375. (BT_UART_MSG_FRAME2CHLSEQN_MSK & uart_msg->frame2) >>
  1376. BT_UART_MSG_FRAME2CHLSEQN_POS,
  1377. (BT_UART_MSG_FRAME2INBAND_MSK & uart_msg->frame2) >>
  1378. BT_UART_MSG_FRAME2INBAND_POS);
  1379. IWL_DEBUG_COEX(priv, "SCO/eSCO = 0x%X, Sniff = 0x%X, A2DP = 0x%X, "
  1380. "ACL = 0x%X, Master = 0x%X, OBEX = 0x%X",
  1381. (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3) >>
  1382. BT_UART_MSG_FRAME3SCOESCO_POS,
  1383. (BT_UART_MSG_FRAME3SNIFF_MSK & uart_msg->frame3) >>
  1384. BT_UART_MSG_FRAME3SNIFF_POS,
  1385. (BT_UART_MSG_FRAME3A2DP_MSK & uart_msg->frame3) >>
  1386. BT_UART_MSG_FRAME3A2DP_POS,
  1387. (BT_UART_MSG_FRAME3ACL_MSK & uart_msg->frame3) >>
  1388. BT_UART_MSG_FRAME3ACL_POS,
  1389. (BT_UART_MSG_FRAME3MASTER_MSK & uart_msg->frame3) >>
  1390. BT_UART_MSG_FRAME3MASTER_POS,
  1391. (BT_UART_MSG_FRAME3OBEX_MSK & uart_msg->frame3) >>
  1392. BT_UART_MSG_FRAME3OBEX_POS);
  1393. IWL_DEBUG_COEX(priv, "Idle duration = 0x%X",
  1394. (BT_UART_MSG_FRAME4IDLEDURATION_MSK & uart_msg->frame4) >>
  1395. BT_UART_MSG_FRAME4IDLEDURATION_POS);
  1396. IWL_DEBUG_COEX(priv, "Tx Activity = 0x%X, Rx Activity = 0x%X, "
  1397. "eSCO Retransmissions = 0x%X",
  1398. (BT_UART_MSG_FRAME5TXACTIVITY_MSK & uart_msg->frame5) >>
  1399. BT_UART_MSG_FRAME5TXACTIVITY_POS,
  1400. (BT_UART_MSG_FRAME5RXACTIVITY_MSK & uart_msg->frame5) >>
  1401. BT_UART_MSG_FRAME5RXACTIVITY_POS,
  1402. (BT_UART_MSG_FRAME5ESCORETRANSMIT_MSK & uart_msg->frame5) >>
  1403. BT_UART_MSG_FRAME5ESCORETRANSMIT_POS);
  1404. IWL_DEBUG_COEX(priv, "Sniff Interval = 0x%X, Discoverable = 0x%X",
  1405. (BT_UART_MSG_FRAME6SNIFFINTERVAL_MSK & uart_msg->frame6) >>
  1406. BT_UART_MSG_FRAME6SNIFFINTERVAL_POS,
  1407. (BT_UART_MSG_FRAME6DISCOVERABLE_MSK & uart_msg->frame6) >>
  1408. BT_UART_MSG_FRAME6DISCOVERABLE_POS);
  1409. IWL_DEBUG_COEX(priv, "Sniff Activity = 0x%X, Page = "
  1410. "0x%X, Inquiry = 0x%X, Connectable = 0x%X",
  1411. (BT_UART_MSG_FRAME7SNIFFACTIVITY_MSK & uart_msg->frame7) >>
  1412. BT_UART_MSG_FRAME7SNIFFACTIVITY_POS,
  1413. (BT_UART_MSG_FRAME7PAGE_MSK & uart_msg->frame7) >>
  1414. BT_UART_MSG_FRAME7PAGE_POS,
  1415. (BT_UART_MSG_FRAME7INQUIRY_MSK & uart_msg->frame7) >>
  1416. BT_UART_MSG_FRAME7INQUIRY_POS,
  1417. (BT_UART_MSG_FRAME7CONNECTABLE_MSK & uart_msg->frame7) >>
  1418. BT_UART_MSG_FRAME7CONNECTABLE_POS);
  1419. }
  1420. static void iwlagn_set_kill_msk(struct iwl_priv *priv,
  1421. struct iwl_bt_uart_msg *uart_msg)
  1422. {
  1423. u8 kill_msk;
  1424. static const __le32 bt_kill_ack_msg[2] = {
  1425. IWLAGN_BT_KILL_ACK_MASK_DEFAULT,
  1426. IWLAGN_BT_KILL_ACK_CTS_MASK_SCO };
  1427. static const __le32 bt_kill_cts_msg[2] = {
  1428. IWLAGN_BT_KILL_CTS_MASK_DEFAULT,
  1429. IWLAGN_BT_KILL_ACK_CTS_MASK_SCO };
  1430. kill_msk = (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3)
  1431. ? 1 : 0;
  1432. if (priv->kill_ack_mask != bt_kill_ack_msg[kill_msk] ||
  1433. priv->kill_cts_mask != bt_kill_cts_msg[kill_msk]) {
  1434. priv->bt_valid |= IWLAGN_BT_VALID_KILL_ACK_MASK;
  1435. priv->kill_ack_mask = bt_kill_ack_msg[kill_msk];
  1436. priv->bt_valid |= IWLAGN_BT_VALID_KILL_CTS_MASK;
  1437. priv->kill_cts_mask = bt_kill_cts_msg[kill_msk];
  1438. /* schedule to send runtime bt_config */
  1439. queue_work(priv->shrd->workqueue, &priv->bt_runtime_config);
  1440. }
  1441. }
  1442. void iwlagn_bt_coex_profile_notif(struct iwl_priv *priv,
  1443. struct iwl_rx_mem_buffer *rxb)
  1444. {
  1445. unsigned long flags;
  1446. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1447. struct iwl_bt_coex_profile_notif *coex = &pkt->u.bt_coex_profile_notif;
  1448. struct iwl_bt_uart_msg *uart_msg = &coex->last_bt_uart_msg;
  1449. if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) {
  1450. /* bt coex disabled */
  1451. return;
  1452. }
  1453. IWL_DEBUG_COEX(priv, "BT Coex notification:\n");
  1454. IWL_DEBUG_COEX(priv, " status: %d\n", coex->bt_status);
  1455. IWL_DEBUG_COEX(priv, " traffic load: %d\n", coex->bt_traffic_load);
  1456. IWL_DEBUG_COEX(priv, " CI compliance: %d\n",
  1457. coex->bt_ci_compliance);
  1458. iwlagn_print_uartmsg(priv, uart_msg);
  1459. priv->last_bt_traffic_load = priv->bt_traffic_load;
  1460. priv->bt_is_sco = iwlagn_bt_traffic_is_sco(uart_msg);
  1461. if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
  1462. if (priv->bt_status != coex->bt_status ||
  1463. priv->last_bt_traffic_load != coex->bt_traffic_load) {
  1464. if (coex->bt_status) {
  1465. /* BT on */
  1466. if (!priv->bt_ch_announce)
  1467. priv->bt_traffic_load =
  1468. IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
  1469. else
  1470. priv->bt_traffic_load =
  1471. coex->bt_traffic_load;
  1472. } else {
  1473. /* BT off */
  1474. priv->bt_traffic_load =
  1475. IWL_BT_COEX_TRAFFIC_LOAD_NONE;
  1476. }
  1477. priv->bt_status = coex->bt_status;
  1478. queue_work(priv->shrd->workqueue,
  1479. &priv->bt_traffic_change_work);
  1480. }
  1481. }
  1482. iwlagn_set_kill_msk(priv, uart_msg);
  1483. /* FIXME: based on notification, adjust the prio_boost */
  1484. spin_lock_irqsave(&priv->shrd->lock, flags);
  1485. priv->bt_ci_compliance = coex->bt_ci_compliance;
  1486. spin_unlock_irqrestore(&priv->shrd->lock, flags);
  1487. }
  1488. void iwlagn_bt_rx_handler_setup(struct iwl_priv *priv)
  1489. {
  1490. priv->rx_handlers[REPLY_BT_COEX_PROFILE_NOTIF] =
  1491. iwlagn_bt_coex_profile_notif;
  1492. }
  1493. void iwlagn_bt_setup_deferred_work(struct iwl_priv *priv)
  1494. {
  1495. INIT_WORK(&priv->bt_traffic_change_work,
  1496. iwlagn_bt_traffic_change_work);
  1497. }
  1498. void iwlagn_bt_cancel_deferred_work(struct iwl_priv *priv)
  1499. {
  1500. cancel_work_sync(&priv->bt_traffic_change_work);
  1501. }
  1502. static bool is_single_rx_stream(struct iwl_priv *priv)
  1503. {
  1504. return priv->current_ht_config.smps == IEEE80211_SMPS_STATIC ||
  1505. priv->current_ht_config.single_chain_sufficient;
  1506. }
  1507. #define IWL_NUM_RX_CHAINS_MULTIPLE 3
  1508. #define IWL_NUM_RX_CHAINS_SINGLE 2
  1509. #define IWL_NUM_IDLE_CHAINS_DUAL 2
  1510. #define IWL_NUM_IDLE_CHAINS_SINGLE 1
  1511. /*
  1512. * Determine how many receiver/antenna chains to use.
  1513. *
  1514. * More provides better reception via diversity. Fewer saves power
  1515. * at the expense of throughput, but only when not in powersave to
  1516. * start with.
  1517. *
  1518. * MIMO (dual stream) requires at least 2, but works better with 3.
  1519. * This does not determine *which* chains to use, just how many.
  1520. */
  1521. static int iwl_get_active_rx_chain_count(struct iwl_priv *priv)
  1522. {
  1523. if (priv->cfg->bt_params &&
  1524. priv->cfg->bt_params->advanced_bt_coexist &&
  1525. (priv->bt_full_concurrent ||
  1526. priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) {
  1527. /*
  1528. * only use chain 'A' in bt high traffic load or
  1529. * full concurrency mode
  1530. */
  1531. return IWL_NUM_RX_CHAINS_SINGLE;
  1532. }
  1533. /* # of Rx chains to use when expecting MIMO. */
  1534. if (is_single_rx_stream(priv))
  1535. return IWL_NUM_RX_CHAINS_SINGLE;
  1536. else
  1537. return IWL_NUM_RX_CHAINS_MULTIPLE;
  1538. }
  1539. /*
  1540. * When we are in power saving mode, unless device support spatial
  1541. * multiplexing power save, use the active count for rx chain count.
  1542. */
  1543. static int iwl_get_idle_rx_chain_count(struct iwl_priv *priv, int active_cnt)
  1544. {
  1545. /* # Rx chains when idling, depending on SMPS mode */
  1546. switch (priv->current_ht_config.smps) {
  1547. case IEEE80211_SMPS_STATIC:
  1548. case IEEE80211_SMPS_DYNAMIC:
  1549. return IWL_NUM_IDLE_CHAINS_SINGLE;
  1550. case IEEE80211_SMPS_OFF:
  1551. return active_cnt;
  1552. default:
  1553. WARN(1, "invalid SMPS mode %d",
  1554. priv->current_ht_config.smps);
  1555. return active_cnt;
  1556. }
  1557. }
  1558. /* up to 4 chains */
  1559. static u8 iwl_count_chain_bitmap(u32 chain_bitmap)
  1560. {
  1561. u8 res;
  1562. res = (chain_bitmap & BIT(0)) >> 0;
  1563. res += (chain_bitmap & BIT(1)) >> 1;
  1564. res += (chain_bitmap & BIT(2)) >> 2;
  1565. res += (chain_bitmap & BIT(3)) >> 3;
  1566. return res;
  1567. }
  1568. /**
  1569. * iwlagn_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
  1570. *
  1571. * Selects how many and which Rx receivers/antennas/chains to use.
  1572. * This should not be used for scan command ... it puts data in wrong place.
  1573. */
  1574. void iwlagn_set_rxon_chain(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  1575. {
  1576. bool is_single = is_single_rx_stream(priv);
  1577. bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->shrd->status);
  1578. u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt;
  1579. u32 active_chains;
  1580. u16 rx_chain;
  1581. /* Tell uCode which antennas are actually connected.
  1582. * Before first association, we assume all antennas are connected.
  1583. * Just after first association, iwl_chain_noise_calibration()
  1584. * checks which antennas actually *are* connected. */
  1585. if (priv->chain_noise_data.active_chains)
  1586. active_chains = priv->chain_noise_data.active_chains;
  1587. else
  1588. active_chains = hw_params(priv).valid_rx_ant;
  1589. if (priv->cfg->bt_params &&
  1590. priv->cfg->bt_params->advanced_bt_coexist &&
  1591. (priv->bt_full_concurrent ||
  1592. priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) {
  1593. /*
  1594. * only use chain 'A' in bt high traffic load or
  1595. * full concurrency mode
  1596. */
  1597. active_chains = first_antenna(active_chains);
  1598. }
  1599. rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS;
  1600. /* How many receivers should we use? */
  1601. active_rx_cnt = iwl_get_active_rx_chain_count(priv);
  1602. idle_rx_cnt = iwl_get_idle_rx_chain_count(priv, active_rx_cnt);
  1603. /* correct rx chain count according hw settings
  1604. * and chain noise calibration
  1605. */
  1606. valid_rx_cnt = iwl_count_chain_bitmap(active_chains);
  1607. if (valid_rx_cnt < active_rx_cnt)
  1608. active_rx_cnt = valid_rx_cnt;
  1609. if (valid_rx_cnt < idle_rx_cnt)
  1610. idle_rx_cnt = valid_rx_cnt;
  1611. rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS;
  1612. rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS;
  1613. ctx->staging.rx_chain = cpu_to_le16(rx_chain);
  1614. if (!is_single && (active_rx_cnt >= IWL_NUM_RX_CHAINS_SINGLE) && is_cam)
  1615. ctx->staging.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
  1616. else
  1617. ctx->staging.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
  1618. IWL_DEBUG_ASSOC(priv, "rx_chain=0x%X active=%d idle=%d\n",
  1619. ctx->staging.rx_chain,
  1620. active_rx_cnt, idle_rx_cnt);
  1621. WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 ||
  1622. active_rx_cnt < idle_rx_cnt);
  1623. }
  1624. u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant, u8 valid)
  1625. {
  1626. int i;
  1627. u8 ind = ant;
  1628. if (priv->band == IEEE80211_BAND_2GHZ &&
  1629. priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)
  1630. return 0;
  1631. for (i = 0; i < RATE_ANT_NUM - 1; i++) {
  1632. ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0;
  1633. if (valid & BIT(ind))
  1634. return ind;
  1635. }
  1636. return ant;
  1637. }
  1638. static const char *get_csr_string(int cmd)
  1639. {
  1640. switch (cmd) {
  1641. IWL_CMD(CSR_HW_IF_CONFIG_REG);
  1642. IWL_CMD(CSR_INT_COALESCING);
  1643. IWL_CMD(CSR_INT);
  1644. IWL_CMD(CSR_INT_MASK);
  1645. IWL_CMD(CSR_FH_INT_STATUS);
  1646. IWL_CMD(CSR_GPIO_IN);
  1647. IWL_CMD(CSR_RESET);
  1648. IWL_CMD(CSR_GP_CNTRL);
  1649. IWL_CMD(CSR_HW_REV);
  1650. IWL_CMD(CSR_EEPROM_REG);
  1651. IWL_CMD(CSR_EEPROM_GP);
  1652. IWL_CMD(CSR_OTP_GP_REG);
  1653. IWL_CMD(CSR_GIO_REG);
  1654. IWL_CMD(CSR_GP_UCODE_REG);
  1655. IWL_CMD(CSR_GP_DRIVER_REG);
  1656. IWL_CMD(CSR_UCODE_DRV_GP1);
  1657. IWL_CMD(CSR_UCODE_DRV_GP2);
  1658. IWL_CMD(CSR_LED_REG);
  1659. IWL_CMD(CSR_DRAM_INT_TBL_REG);
  1660. IWL_CMD(CSR_GIO_CHICKEN_BITS);
  1661. IWL_CMD(CSR_ANA_PLL_CFG);
  1662. IWL_CMD(CSR_HW_REV_WA_REG);
  1663. IWL_CMD(CSR_DBG_HPET_MEM_REG);
  1664. default:
  1665. return "UNKNOWN";
  1666. }
  1667. }
  1668. void iwl_dump_csr(struct iwl_priv *priv)
  1669. {
  1670. int i;
  1671. static const u32 csr_tbl[] = {
  1672. CSR_HW_IF_CONFIG_REG,
  1673. CSR_INT_COALESCING,
  1674. CSR_INT,
  1675. CSR_INT_MASK,
  1676. CSR_FH_INT_STATUS,
  1677. CSR_GPIO_IN,
  1678. CSR_RESET,
  1679. CSR_GP_CNTRL,
  1680. CSR_HW_REV,
  1681. CSR_EEPROM_REG,
  1682. CSR_EEPROM_GP,
  1683. CSR_OTP_GP_REG,
  1684. CSR_GIO_REG,
  1685. CSR_GP_UCODE_REG,
  1686. CSR_GP_DRIVER_REG,
  1687. CSR_UCODE_DRV_GP1,
  1688. CSR_UCODE_DRV_GP2,
  1689. CSR_LED_REG,
  1690. CSR_DRAM_INT_TBL_REG,
  1691. CSR_GIO_CHICKEN_BITS,
  1692. CSR_ANA_PLL_CFG,
  1693. CSR_HW_REV_WA_REG,
  1694. CSR_DBG_HPET_MEM_REG
  1695. };
  1696. IWL_ERR(priv, "CSR values:\n");
  1697. IWL_ERR(priv, "(2nd byte of CSR_INT_COALESCING is "
  1698. "CSR_INT_PERIODIC_REG)\n");
  1699. for (i = 0; i < ARRAY_SIZE(csr_tbl); i++) {
  1700. IWL_ERR(priv, " %25s: 0X%08x\n",
  1701. get_csr_string(csr_tbl[i]),
  1702. iwl_read32(priv, csr_tbl[i]));
  1703. }
  1704. }
  1705. static const char *get_fh_string(int cmd)
  1706. {
  1707. switch (cmd) {
  1708. IWL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG);
  1709. IWL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG);
  1710. IWL_CMD(FH_RSCSR_CHNL0_WPTR);
  1711. IWL_CMD(FH_MEM_RCSR_CHNL0_CONFIG_REG);
  1712. IWL_CMD(FH_MEM_RSSR_SHARED_CTRL_REG);
  1713. IWL_CMD(FH_MEM_RSSR_RX_STATUS_REG);
  1714. IWL_CMD(FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV);
  1715. IWL_CMD(FH_TSSR_TX_STATUS_REG);
  1716. IWL_CMD(FH_TSSR_TX_ERROR_REG);
  1717. default:
  1718. return "UNKNOWN";
  1719. }
  1720. }
  1721. int iwl_dump_fh(struct iwl_priv *priv, char **buf, bool display)
  1722. {
  1723. int i;
  1724. #ifdef CONFIG_IWLWIFI_DEBUG
  1725. int pos = 0;
  1726. size_t bufsz = 0;
  1727. #endif
  1728. static const u32 fh_tbl[] = {
  1729. FH_RSCSR_CHNL0_STTS_WPTR_REG,
  1730. FH_RSCSR_CHNL0_RBDCB_BASE_REG,
  1731. FH_RSCSR_CHNL0_WPTR,
  1732. FH_MEM_RCSR_CHNL0_CONFIG_REG,
  1733. FH_MEM_RSSR_SHARED_CTRL_REG,
  1734. FH_MEM_RSSR_RX_STATUS_REG,
  1735. FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV,
  1736. FH_TSSR_TX_STATUS_REG,
  1737. FH_TSSR_TX_ERROR_REG
  1738. };
  1739. #ifdef CONFIG_IWLWIFI_DEBUG
  1740. if (display) {
  1741. bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40;
  1742. *buf = kmalloc(bufsz, GFP_KERNEL);
  1743. if (!*buf)
  1744. return -ENOMEM;
  1745. pos += scnprintf(*buf + pos, bufsz - pos,
  1746. "FH register values:\n");
  1747. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
  1748. pos += scnprintf(*buf + pos, bufsz - pos,
  1749. " %34s: 0X%08x\n",
  1750. get_fh_string(fh_tbl[i]),
  1751. iwl_read_direct32(priv, fh_tbl[i]));
  1752. }
  1753. return pos;
  1754. }
  1755. #endif
  1756. IWL_ERR(priv, "FH register values:\n");
  1757. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
  1758. IWL_ERR(priv, " %34s: 0X%08x\n",
  1759. get_fh_string(fh_tbl[i]),
  1760. iwl_read_direct32(priv, fh_tbl[i]));
  1761. }
  1762. return 0;
  1763. }
  1764. /* notification wait support */
  1765. void iwlagn_init_notification_wait(struct iwl_priv *priv,
  1766. struct iwl_notification_wait *wait_entry,
  1767. u8 cmd,
  1768. void (*fn)(struct iwl_priv *priv,
  1769. struct iwl_rx_packet *pkt,
  1770. void *data),
  1771. void *fn_data)
  1772. {
  1773. wait_entry->fn = fn;
  1774. wait_entry->fn_data = fn_data;
  1775. wait_entry->cmd = cmd;
  1776. wait_entry->triggered = false;
  1777. wait_entry->aborted = false;
  1778. spin_lock_bh(&priv->notif_wait_lock);
  1779. list_add(&wait_entry->list, &priv->notif_waits);
  1780. spin_unlock_bh(&priv->notif_wait_lock);
  1781. }
  1782. int iwlagn_wait_notification(struct iwl_priv *priv,
  1783. struct iwl_notification_wait *wait_entry,
  1784. unsigned long timeout)
  1785. {
  1786. int ret;
  1787. ret = wait_event_timeout(priv->notif_waitq,
  1788. wait_entry->triggered || wait_entry->aborted,
  1789. timeout);
  1790. spin_lock_bh(&priv->notif_wait_lock);
  1791. list_del(&wait_entry->list);
  1792. spin_unlock_bh(&priv->notif_wait_lock);
  1793. if (wait_entry->aborted)
  1794. return -EIO;
  1795. /* return value is always >= 0 */
  1796. if (ret <= 0)
  1797. return -ETIMEDOUT;
  1798. return 0;
  1799. }
  1800. void iwlagn_remove_notification(struct iwl_priv *priv,
  1801. struct iwl_notification_wait *wait_entry)
  1802. {
  1803. spin_lock_bh(&priv->notif_wait_lock);
  1804. list_del(&wait_entry->list);
  1805. spin_unlock_bh(&priv->notif_wait_lock);
  1806. }