iwl-agn-lib.c 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033
  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->status))
  359. queue_work(priv->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->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->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->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 trans_send_cmd_pdu(&priv->trans, 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 = priv->hw_params.valid_rx_ant;
  685. u8 rate;
  686. bool is_active = false;
  687. int chan_mod;
  688. u8 active_chains;
  689. u8 scan_tx_antennas = priv->hw_params.valid_tx_ant;
  690. int ret;
  691. lockdep_assert_held(&priv->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->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 |= priv->hw_params.valid_rx_ant << RXON_RX_CHAIN_VALID_POS;
  860. rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS;
  861. rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_SEL_POS;
  862. rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS;
  863. scan->rx_chain = cpu_to_le16(rx_chain);
  864. switch (priv->scan_type) {
  865. case IWL_SCAN_NORMAL:
  866. cmd_len = iwl_fill_probe_req(priv,
  867. (struct ieee80211_mgmt *)scan->data,
  868. vif->addr,
  869. priv->scan_request->ie,
  870. priv->scan_request->ie_len,
  871. IWL_MAX_SCAN_SIZE - sizeof(*scan));
  872. break;
  873. case IWL_SCAN_RADIO_RESET:
  874. case IWL_SCAN_ROC:
  875. /* use bcast addr, will not be transmitted but must be valid */
  876. cmd_len = iwl_fill_probe_req(priv,
  877. (struct ieee80211_mgmt *)scan->data,
  878. iwl_bcast_addr, NULL, 0,
  879. IWL_MAX_SCAN_SIZE - sizeof(*scan));
  880. break;
  881. default:
  882. BUG();
  883. }
  884. scan->tx_cmd.len = cpu_to_le16(cmd_len);
  885. scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK |
  886. RXON_FILTER_BCON_AWARE_MSK);
  887. switch (priv->scan_type) {
  888. case IWL_SCAN_RADIO_RESET:
  889. scan->channel_count =
  890. iwl_get_single_channel_for_scan(priv, vif, band,
  891. (void *)&scan->data[cmd_len]);
  892. break;
  893. case IWL_SCAN_NORMAL:
  894. scan->channel_count =
  895. iwl_get_channels_for_scan(priv, vif, band,
  896. is_active, n_probes,
  897. (void *)&scan->data[cmd_len]);
  898. break;
  899. case IWL_SCAN_ROC: {
  900. struct iwl_scan_channel *scan_ch;
  901. scan->channel_count = 1;
  902. scan_ch = (void *)&scan->data[cmd_len];
  903. scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
  904. scan_ch->channel =
  905. cpu_to_le16(priv->hw_roc_channel->hw_value);
  906. scan_ch->active_dwell =
  907. scan_ch->passive_dwell =
  908. cpu_to_le16(priv->hw_roc_duration);
  909. /* Set txpower levels to defaults */
  910. scan_ch->dsp_atten = 110;
  911. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  912. * power level:
  913. * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
  914. */
  915. if (priv->hw_roc_channel->band == IEEE80211_BAND_5GHZ)
  916. scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
  917. else
  918. scan_ch->tx_gain = ((1 << 5) | (5 << 3));
  919. }
  920. break;
  921. }
  922. if (scan->channel_count == 0) {
  923. IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
  924. return -EIO;
  925. }
  926. cmd.len[0] += le16_to_cpu(scan->tx_cmd.len) +
  927. scan->channel_count * sizeof(struct iwl_scan_channel);
  928. cmd.data[0] = scan;
  929. cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
  930. scan->len = cpu_to_le16(cmd.len[0]);
  931. /* set scan bit here for PAN params */
  932. set_bit(STATUS_SCAN_HW, &priv->status);
  933. ret = iwlagn_set_pan_params(priv);
  934. if (ret)
  935. return ret;
  936. ret = trans_send_cmd(&priv->trans, &cmd);
  937. if (ret) {
  938. clear_bit(STATUS_SCAN_HW, &priv->status);
  939. iwlagn_set_pan_params(priv);
  940. }
  941. return ret;
  942. }
  943. int iwlagn_manage_ibss_station(struct iwl_priv *priv,
  944. struct ieee80211_vif *vif, bool add)
  945. {
  946. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  947. if (add)
  948. return iwlagn_add_bssid_station(priv, vif_priv->ctx,
  949. vif->bss_conf.bssid,
  950. &vif_priv->ibss_bssid_sta_id);
  951. return iwl_remove_station(priv, vif_priv->ibss_bssid_sta_id,
  952. vif->bss_conf.bssid);
  953. }
  954. void iwl_free_tfds_in_queue(struct iwl_priv *priv,
  955. int sta_id, int tid, int freed)
  956. {
  957. lockdep_assert_held(&priv->sta_lock);
  958. if (priv->stations[sta_id].tid[tid].tfds_in_queue >= freed)
  959. priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
  960. else {
  961. IWL_DEBUG_TX(priv, "free more than tfds_in_queue (%u:%d)\n",
  962. priv->stations[sta_id].tid[tid].tfds_in_queue,
  963. freed);
  964. priv->stations[sta_id].tid[tid].tfds_in_queue = 0;
  965. }
  966. }
  967. #define IWL_FLUSH_WAIT_MS 2000
  968. int iwlagn_wait_tx_queue_empty(struct iwl_priv *priv)
  969. {
  970. struct iwl_tx_queue *txq;
  971. struct iwl_queue *q;
  972. int cnt;
  973. unsigned long now = jiffies;
  974. int ret = 0;
  975. /* waiting for all the tx frames complete might take a while */
  976. for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
  977. if (cnt == priv->cmd_queue)
  978. continue;
  979. txq = &priv->txq[cnt];
  980. q = &txq->q;
  981. while (q->read_ptr != q->write_ptr && !time_after(jiffies,
  982. now + msecs_to_jiffies(IWL_FLUSH_WAIT_MS)))
  983. msleep(1);
  984. if (q->read_ptr != q->write_ptr) {
  985. IWL_ERR(priv, "fail to flush all tx fifo queues\n");
  986. ret = -ETIMEDOUT;
  987. break;
  988. }
  989. }
  990. return ret;
  991. }
  992. #define IWL_TX_QUEUE_MSK 0xfffff
  993. /**
  994. * iwlagn_txfifo_flush: send REPLY_TXFIFO_FLUSH command to uCode
  995. *
  996. * pre-requirements:
  997. * 1. acquire mutex before calling
  998. * 2. make sure rf is on and not in exit state
  999. */
  1000. int iwlagn_txfifo_flush(struct iwl_priv *priv, u16 flush_control)
  1001. {
  1002. struct iwl_txfifo_flush_cmd flush_cmd;
  1003. struct iwl_host_cmd cmd = {
  1004. .id = REPLY_TXFIFO_FLUSH,
  1005. .len = { sizeof(struct iwl_txfifo_flush_cmd), },
  1006. .flags = CMD_SYNC,
  1007. .data = { &flush_cmd, },
  1008. };
  1009. might_sleep();
  1010. memset(&flush_cmd, 0, sizeof(flush_cmd));
  1011. if (flush_control & BIT(IWL_RXON_CTX_BSS))
  1012. flush_cmd.fifo_control = IWL_SCD_VO_MSK | IWL_SCD_VI_MSK |
  1013. IWL_SCD_BE_MSK | IWL_SCD_BK_MSK |
  1014. IWL_SCD_MGMT_MSK;
  1015. if ((flush_control & BIT(IWL_RXON_CTX_PAN)) &&
  1016. (priv->valid_contexts != BIT(IWL_RXON_CTX_BSS)))
  1017. flush_cmd.fifo_control |= IWL_PAN_SCD_VO_MSK |
  1018. IWL_PAN_SCD_VI_MSK | IWL_PAN_SCD_BE_MSK |
  1019. IWL_PAN_SCD_BK_MSK | IWL_PAN_SCD_MGMT_MSK |
  1020. IWL_PAN_SCD_MULTICAST_MSK;
  1021. if (priv->cfg->sku & EEPROM_SKU_CAP_11N_ENABLE)
  1022. flush_cmd.fifo_control |= IWL_AGG_TX_QUEUE_MSK;
  1023. IWL_DEBUG_INFO(priv, "fifo queue control: 0X%x\n",
  1024. flush_cmd.fifo_control);
  1025. flush_cmd.flush_control = cpu_to_le16(flush_control);
  1026. return trans_send_cmd(&priv->trans, &cmd);
  1027. }
  1028. void iwlagn_dev_txfifo_flush(struct iwl_priv *priv, u16 flush_control)
  1029. {
  1030. mutex_lock(&priv->mutex);
  1031. ieee80211_stop_queues(priv->hw);
  1032. if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) {
  1033. IWL_ERR(priv, "flush request fail\n");
  1034. goto done;
  1035. }
  1036. IWL_DEBUG_INFO(priv, "wait transmit/flush all frames\n");
  1037. iwlagn_wait_tx_queue_empty(priv);
  1038. done:
  1039. ieee80211_wake_queues(priv->hw);
  1040. mutex_unlock(&priv->mutex);
  1041. }
  1042. /*
  1043. * BT coex
  1044. */
  1045. /*
  1046. * Macros to access the lookup table.
  1047. *
  1048. * The lookup table has 7 inputs: bt3_prio, bt3_txrx, bt_rf_act, wifi_req,
  1049. * wifi_prio, wifi_txrx and wifi_sh_ant_req.
  1050. *
  1051. * It has three outputs: WLAN_ACTIVE, WLAN_KILL and ANT_SWITCH
  1052. *
  1053. * The format is that "registers" 8 through 11 contain the WLAN_ACTIVE bits
  1054. * one after another in 32-bit registers, and "registers" 0 through 7 contain
  1055. * the WLAN_KILL and ANT_SWITCH bits interleaved (in that order).
  1056. *
  1057. * These macros encode that format.
  1058. */
  1059. #define LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, wifi_req, wifi_prio, \
  1060. wifi_txrx, wifi_sh_ant_req) \
  1061. (bt3_prio | (bt3_txrx << 1) | (bt_rf_act << 2) | (wifi_req << 3) | \
  1062. (wifi_prio << 4) | (wifi_txrx << 5) | (wifi_sh_ant_req << 6))
  1063. #define LUT_PTA_WLAN_ACTIVE_OP(lut, op, val) \
  1064. lut[8 + ((val) >> 5)] op (cpu_to_le32(BIT((val) & 0x1f)))
  1065. #define LUT_TEST_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1066. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1067. (!!(LUT_PTA_WLAN_ACTIVE_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, \
  1068. bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
  1069. wifi_sh_ant_req))))
  1070. #define LUT_SET_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1071. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1072. LUT_PTA_WLAN_ACTIVE_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, \
  1073. bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
  1074. wifi_sh_ant_req))
  1075. #define LUT_CLEAR_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, \
  1076. wifi_req, wifi_prio, wifi_txrx, \
  1077. wifi_sh_ant_req) \
  1078. LUT_PTA_WLAN_ACTIVE_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, \
  1079. bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
  1080. wifi_sh_ant_req))
  1081. #define LUT_WLAN_KILL_OP(lut, op, val) \
  1082. lut[(val) >> 4] op (cpu_to_le32(BIT(((val) << 1) & 0x1e)))
  1083. #define LUT_TEST_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1084. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1085. (!!(LUT_WLAN_KILL_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1086. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))))
  1087. #define LUT_SET_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1088. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1089. LUT_WLAN_KILL_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1090. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  1091. #define LUT_CLEAR_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1092. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1093. LUT_WLAN_KILL_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1094. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  1095. #define LUT_ANT_SWITCH_OP(lut, op, val) \
  1096. lut[(val) >> 4] op (cpu_to_le32(BIT((((val) << 1) & 0x1e) + 1)))
  1097. #define LUT_TEST_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1098. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1099. (!!(LUT_ANT_SWITCH_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1100. wifi_req, wifi_prio, wifi_txrx, \
  1101. wifi_sh_ant_req))))
  1102. #define LUT_SET_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1103. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1104. LUT_ANT_SWITCH_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1105. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  1106. #define LUT_CLEAR_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
  1107. wifi_prio, wifi_txrx, wifi_sh_ant_req) \
  1108. LUT_ANT_SWITCH_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
  1109. wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
  1110. static const __le32 iwlagn_def_3w_lookup[12] = {
  1111. cpu_to_le32(0xaaaaaaaa),
  1112. cpu_to_le32(0xaaaaaaaa),
  1113. cpu_to_le32(0xaeaaaaaa),
  1114. cpu_to_le32(0xaaaaaaaa),
  1115. cpu_to_le32(0xcc00ff28),
  1116. cpu_to_le32(0x0000aaaa),
  1117. cpu_to_le32(0xcc00aaaa),
  1118. cpu_to_le32(0x0000aaaa),
  1119. cpu_to_le32(0xc0004000),
  1120. cpu_to_le32(0x00004000),
  1121. cpu_to_le32(0xf0005000),
  1122. cpu_to_le32(0xf0005000),
  1123. };
  1124. static const __le32 iwlagn_concurrent_lookup[12] = {
  1125. cpu_to_le32(0xaaaaaaaa),
  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(0x00000000),
  1134. cpu_to_le32(0x00000000),
  1135. cpu_to_le32(0x00000000),
  1136. cpu_to_le32(0x00000000),
  1137. };
  1138. void iwlagn_send_advance_bt_config(struct iwl_priv *priv)
  1139. {
  1140. struct iwl_basic_bt_cmd basic = {
  1141. .max_kill = IWLAGN_BT_MAX_KILL_DEFAULT,
  1142. .bt3_timer_t7_value = IWLAGN_BT3_T7_DEFAULT,
  1143. .bt3_prio_sample_time = IWLAGN_BT3_PRIO_SAMPLE_DEFAULT,
  1144. .bt3_timer_t2_value = IWLAGN_BT3_T2_DEFAULT,
  1145. };
  1146. struct iwl6000_bt_cmd bt_cmd_6000;
  1147. struct iwl2000_bt_cmd bt_cmd_2000;
  1148. int ret;
  1149. BUILD_BUG_ON(sizeof(iwlagn_def_3w_lookup) !=
  1150. sizeof(basic.bt3_lookup_table));
  1151. if (priv->cfg->bt_params) {
  1152. if (priv->cfg->bt_params->bt_session_2) {
  1153. bt_cmd_2000.prio_boost = cpu_to_le32(
  1154. priv->cfg->bt_params->bt_prio_boost);
  1155. bt_cmd_2000.tx_prio_boost = 0;
  1156. bt_cmd_2000.rx_prio_boost = 0;
  1157. } else {
  1158. bt_cmd_6000.prio_boost =
  1159. priv->cfg->bt_params->bt_prio_boost;
  1160. bt_cmd_6000.tx_prio_boost = 0;
  1161. bt_cmd_6000.rx_prio_boost = 0;
  1162. }
  1163. } else {
  1164. IWL_ERR(priv, "failed to construct BT Coex Config\n");
  1165. return;
  1166. }
  1167. basic.kill_ack_mask = priv->kill_ack_mask;
  1168. basic.kill_cts_mask = priv->kill_cts_mask;
  1169. basic.valid = priv->bt_valid;
  1170. /*
  1171. * Configure BT coex mode to "no coexistence" when the
  1172. * user disabled BT coexistence, we have no interface
  1173. * (might be in monitor mode), or the interface is in
  1174. * IBSS mode (no proper uCode support for coex then).
  1175. */
  1176. if (!iwlagn_mod_params.bt_coex_active ||
  1177. priv->iw_mode == NL80211_IFTYPE_ADHOC) {
  1178. basic.flags = IWLAGN_BT_FLAG_COEX_MODE_DISABLED;
  1179. } else {
  1180. basic.flags = IWLAGN_BT_FLAG_COEX_MODE_3W <<
  1181. IWLAGN_BT_FLAG_COEX_MODE_SHIFT;
  1182. if (!priv->bt_enable_pspoll)
  1183. basic.flags |= IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE;
  1184. else
  1185. basic.flags &= ~IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE;
  1186. if (priv->bt_ch_announce)
  1187. basic.flags |= IWLAGN_BT_FLAG_CHANNEL_INHIBITION;
  1188. IWL_DEBUG_COEX(priv, "BT coex flag: 0X%x\n", basic.flags);
  1189. }
  1190. priv->bt_enable_flag = basic.flags;
  1191. if (priv->bt_full_concurrent)
  1192. memcpy(basic.bt3_lookup_table, iwlagn_concurrent_lookup,
  1193. sizeof(iwlagn_concurrent_lookup));
  1194. else
  1195. memcpy(basic.bt3_lookup_table, iwlagn_def_3w_lookup,
  1196. sizeof(iwlagn_def_3w_lookup));
  1197. IWL_DEBUG_COEX(priv, "BT coex %s in %s mode\n",
  1198. basic.flags ? "active" : "disabled",
  1199. priv->bt_full_concurrent ?
  1200. "full concurrency" : "3-wire");
  1201. if (priv->cfg->bt_params->bt_session_2) {
  1202. memcpy(&bt_cmd_2000.basic, &basic,
  1203. sizeof(basic));
  1204. ret = trans_send_cmd_pdu(&priv->trans, REPLY_BT_CONFIG,
  1205. CMD_SYNC, sizeof(bt_cmd_2000), &bt_cmd_2000);
  1206. } else {
  1207. memcpy(&bt_cmd_6000.basic, &basic,
  1208. sizeof(basic));
  1209. ret = trans_send_cmd_pdu(&priv->trans, REPLY_BT_CONFIG,
  1210. CMD_SYNC, sizeof(bt_cmd_6000), &bt_cmd_6000);
  1211. }
  1212. if (ret)
  1213. IWL_ERR(priv, "failed to send BT Coex Config\n");
  1214. }
  1215. void iwlagn_bt_adjust_rssi_monitor(struct iwl_priv *priv, bool rssi_ena)
  1216. {
  1217. struct iwl_rxon_context *ctx, *found_ctx = NULL;
  1218. bool found_ap = false;
  1219. lockdep_assert_held(&priv->mutex);
  1220. /* Check whether AP or GO mode is active. */
  1221. if (rssi_ena) {
  1222. for_each_context(priv, ctx) {
  1223. if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_AP &&
  1224. iwl_is_associated_ctx(ctx)) {
  1225. found_ap = true;
  1226. break;
  1227. }
  1228. }
  1229. }
  1230. /*
  1231. * If disable was received or If GO/AP mode, disable RSSI
  1232. * measurements.
  1233. */
  1234. if (!rssi_ena || found_ap) {
  1235. if (priv->cur_rssi_ctx) {
  1236. ctx = priv->cur_rssi_ctx;
  1237. ieee80211_disable_rssi_reports(ctx->vif);
  1238. priv->cur_rssi_ctx = NULL;
  1239. }
  1240. return;
  1241. }
  1242. /*
  1243. * If rssi measurements need to be enabled, consider all cases now.
  1244. * Figure out how many contexts are active.
  1245. */
  1246. for_each_context(priv, ctx) {
  1247. if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION &&
  1248. iwl_is_associated_ctx(ctx)) {
  1249. found_ctx = ctx;
  1250. break;
  1251. }
  1252. }
  1253. /*
  1254. * rssi monitor already enabled for the correct interface...nothing
  1255. * to do.
  1256. */
  1257. if (found_ctx == priv->cur_rssi_ctx)
  1258. return;
  1259. /*
  1260. * Figure out if rssi monitor is currently enabled, and needs
  1261. * to be changed. If rssi monitor is already enabled, disable
  1262. * it first else just enable rssi measurements on the
  1263. * interface found above.
  1264. */
  1265. if (priv->cur_rssi_ctx) {
  1266. ctx = priv->cur_rssi_ctx;
  1267. if (ctx->vif)
  1268. ieee80211_disable_rssi_reports(ctx->vif);
  1269. }
  1270. priv->cur_rssi_ctx = found_ctx;
  1271. if (!found_ctx)
  1272. return;
  1273. ieee80211_enable_rssi_reports(found_ctx->vif,
  1274. IWLAGN_BT_PSP_MIN_RSSI_THRESHOLD,
  1275. IWLAGN_BT_PSP_MAX_RSSI_THRESHOLD);
  1276. }
  1277. static bool iwlagn_bt_traffic_is_sco(struct iwl_bt_uart_msg *uart_msg)
  1278. {
  1279. return BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3 >>
  1280. BT_UART_MSG_FRAME3SCOESCO_POS;
  1281. }
  1282. static void iwlagn_bt_traffic_change_work(struct work_struct *work)
  1283. {
  1284. struct iwl_priv *priv =
  1285. container_of(work, struct iwl_priv, bt_traffic_change_work);
  1286. struct iwl_rxon_context *ctx;
  1287. int smps_request = -1;
  1288. if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) {
  1289. /* bt coex disabled */
  1290. return;
  1291. }
  1292. /*
  1293. * Note: bt_traffic_load can be overridden by scan complete and
  1294. * coex profile notifications. Ignore that since only bad consequence
  1295. * can be not matching debug print with actual state.
  1296. */
  1297. IWL_DEBUG_COEX(priv, "BT traffic load changes: %d\n",
  1298. priv->bt_traffic_load);
  1299. switch (priv->bt_traffic_load) {
  1300. case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
  1301. if (priv->bt_status)
  1302. smps_request = IEEE80211_SMPS_DYNAMIC;
  1303. else
  1304. smps_request = IEEE80211_SMPS_AUTOMATIC;
  1305. break;
  1306. case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
  1307. smps_request = IEEE80211_SMPS_DYNAMIC;
  1308. break;
  1309. case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
  1310. case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
  1311. smps_request = IEEE80211_SMPS_STATIC;
  1312. break;
  1313. default:
  1314. IWL_ERR(priv, "Invalid BT traffic load: %d\n",
  1315. priv->bt_traffic_load);
  1316. break;
  1317. }
  1318. mutex_lock(&priv->mutex);
  1319. /*
  1320. * We can not send command to firmware while scanning. When the scan
  1321. * complete we will schedule this work again. We do check with mutex
  1322. * locked to prevent new scan request to arrive. We do not check
  1323. * STATUS_SCANNING to avoid race when queue_work two times from
  1324. * different notifications, but quit and not perform any work at all.
  1325. */
  1326. if (test_bit(STATUS_SCAN_HW, &priv->status))
  1327. goto out;
  1328. iwl_update_chain_flags(priv);
  1329. if (smps_request != -1) {
  1330. priv->current_ht_config.smps = smps_request;
  1331. for_each_context(priv, ctx) {
  1332. if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION)
  1333. ieee80211_request_smps(ctx->vif, smps_request);
  1334. }
  1335. }
  1336. /*
  1337. * Dynamic PS poll related functionality. Adjust RSSI measurements if
  1338. * necessary.
  1339. */
  1340. iwlagn_bt_coex_rssi_monitor(priv);
  1341. out:
  1342. mutex_unlock(&priv->mutex);
  1343. }
  1344. /*
  1345. * If BT sco traffic, and RSSI monitor is enabled, move measurements to the
  1346. * correct interface or disable it if this is the last interface to be
  1347. * removed.
  1348. */
  1349. void iwlagn_bt_coex_rssi_monitor(struct iwl_priv *priv)
  1350. {
  1351. if (priv->bt_is_sco &&
  1352. priv->bt_traffic_load == IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS)
  1353. iwlagn_bt_adjust_rssi_monitor(priv, true);
  1354. else
  1355. iwlagn_bt_adjust_rssi_monitor(priv, false);
  1356. }
  1357. static void iwlagn_print_uartmsg(struct iwl_priv *priv,
  1358. struct iwl_bt_uart_msg *uart_msg)
  1359. {
  1360. IWL_DEBUG_COEX(priv, "Message Type = 0x%X, SSN = 0x%X, "
  1361. "Update Req = 0x%X",
  1362. (BT_UART_MSG_FRAME1MSGTYPE_MSK & uart_msg->frame1) >>
  1363. BT_UART_MSG_FRAME1MSGTYPE_POS,
  1364. (BT_UART_MSG_FRAME1SSN_MSK & uart_msg->frame1) >>
  1365. BT_UART_MSG_FRAME1SSN_POS,
  1366. (BT_UART_MSG_FRAME1UPDATEREQ_MSK & uart_msg->frame1) >>
  1367. BT_UART_MSG_FRAME1UPDATEREQ_POS);
  1368. IWL_DEBUG_COEX(priv, "Open connections = 0x%X, Traffic load = 0x%X, "
  1369. "Chl_SeqN = 0x%X, In band = 0x%X",
  1370. (BT_UART_MSG_FRAME2OPENCONNECTIONS_MSK & uart_msg->frame2) >>
  1371. BT_UART_MSG_FRAME2OPENCONNECTIONS_POS,
  1372. (BT_UART_MSG_FRAME2TRAFFICLOAD_MSK & uart_msg->frame2) >>
  1373. BT_UART_MSG_FRAME2TRAFFICLOAD_POS,
  1374. (BT_UART_MSG_FRAME2CHLSEQN_MSK & uart_msg->frame2) >>
  1375. BT_UART_MSG_FRAME2CHLSEQN_POS,
  1376. (BT_UART_MSG_FRAME2INBAND_MSK & uart_msg->frame2) >>
  1377. BT_UART_MSG_FRAME2INBAND_POS);
  1378. IWL_DEBUG_COEX(priv, "SCO/eSCO = 0x%X, Sniff = 0x%X, A2DP = 0x%X, "
  1379. "ACL = 0x%X, Master = 0x%X, OBEX = 0x%X",
  1380. (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3) >>
  1381. BT_UART_MSG_FRAME3SCOESCO_POS,
  1382. (BT_UART_MSG_FRAME3SNIFF_MSK & uart_msg->frame3) >>
  1383. BT_UART_MSG_FRAME3SNIFF_POS,
  1384. (BT_UART_MSG_FRAME3A2DP_MSK & uart_msg->frame3) >>
  1385. BT_UART_MSG_FRAME3A2DP_POS,
  1386. (BT_UART_MSG_FRAME3ACL_MSK & uart_msg->frame3) >>
  1387. BT_UART_MSG_FRAME3ACL_POS,
  1388. (BT_UART_MSG_FRAME3MASTER_MSK & uart_msg->frame3) >>
  1389. BT_UART_MSG_FRAME3MASTER_POS,
  1390. (BT_UART_MSG_FRAME3OBEX_MSK & uart_msg->frame3) >>
  1391. BT_UART_MSG_FRAME3OBEX_POS);
  1392. IWL_DEBUG_COEX(priv, "Idle duration = 0x%X",
  1393. (BT_UART_MSG_FRAME4IDLEDURATION_MSK & uart_msg->frame4) >>
  1394. BT_UART_MSG_FRAME4IDLEDURATION_POS);
  1395. IWL_DEBUG_COEX(priv, "Tx Activity = 0x%X, Rx Activity = 0x%X, "
  1396. "eSCO Retransmissions = 0x%X",
  1397. (BT_UART_MSG_FRAME5TXACTIVITY_MSK & uart_msg->frame5) >>
  1398. BT_UART_MSG_FRAME5TXACTIVITY_POS,
  1399. (BT_UART_MSG_FRAME5RXACTIVITY_MSK & uart_msg->frame5) >>
  1400. BT_UART_MSG_FRAME5RXACTIVITY_POS,
  1401. (BT_UART_MSG_FRAME5ESCORETRANSMIT_MSK & uart_msg->frame5) >>
  1402. BT_UART_MSG_FRAME5ESCORETRANSMIT_POS);
  1403. IWL_DEBUG_COEX(priv, "Sniff Interval = 0x%X, Discoverable = 0x%X",
  1404. (BT_UART_MSG_FRAME6SNIFFINTERVAL_MSK & uart_msg->frame6) >>
  1405. BT_UART_MSG_FRAME6SNIFFINTERVAL_POS,
  1406. (BT_UART_MSG_FRAME6DISCOVERABLE_MSK & uart_msg->frame6) >>
  1407. BT_UART_MSG_FRAME6DISCOVERABLE_POS);
  1408. IWL_DEBUG_COEX(priv, "Sniff Activity = 0x%X, Page = "
  1409. "0x%X, Inquiry = 0x%X, Connectable = 0x%X",
  1410. (BT_UART_MSG_FRAME7SNIFFACTIVITY_MSK & uart_msg->frame7) >>
  1411. BT_UART_MSG_FRAME7SNIFFACTIVITY_POS,
  1412. (BT_UART_MSG_FRAME7PAGE_MSK & uart_msg->frame7) >>
  1413. BT_UART_MSG_FRAME7PAGE_POS,
  1414. (BT_UART_MSG_FRAME7INQUIRY_MSK & uart_msg->frame7) >>
  1415. BT_UART_MSG_FRAME7INQUIRY_POS,
  1416. (BT_UART_MSG_FRAME7CONNECTABLE_MSK & uart_msg->frame7) >>
  1417. BT_UART_MSG_FRAME7CONNECTABLE_POS);
  1418. }
  1419. static void iwlagn_set_kill_msk(struct iwl_priv *priv,
  1420. struct iwl_bt_uart_msg *uart_msg)
  1421. {
  1422. u8 kill_msk;
  1423. static const __le32 bt_kill_ack_msg[2] = {
  1424. IWLAGN_BT_KILL_ACK_MASK_DEFAULT,
  1425. IWLAGN_BT_KILL_ACK_CTS_MASK_SCO };
  1426. static const __le32 bt_kill_cts_msg[2] = {
  1427. IWLAGN_BT_KILL_CTS_MASK_DEFAULT,
  1428. IWLAGN_BT_KILL_ACK_CTS_MASK_SCO };
  1429. kill_msk = (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3)
  1430. ? 1 : 0;
  1431. if (priv->kill_ack_mask != bt_kill_ack_msg[kill_msk] ||
  1432. priv->kill_cts_mask != bt_kill_cts_msg[kill_msk]) {
  1433. priv->bt_valid |= IWLAGN_BT_VALID_KILL_ACK_MASK;
  1434. priv->kill_ack_mask = bt_kill_ack_msg[kill_msk];
  1435. priv->bt_valid |= IWLAGN_BT_VALID_KILL_CTS_MASK;
  1436. priv->kill_cts_mask = bt_kill_cts_msg[kill_msk];
  1437. /* schedule to send runtime bt_config */
  1438. queue_work(priv->workqueue, &priv->bt_runtime_config);
  1439. }
  1440. }
  1441. void iwlagn_bt_coex_profile_notif(struct iwl_priv *priv,
  1442. struct iwl_rx_mem_buffer *rxb)
  1443. {
  1444. unsigned long flags;
  1445. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1446. struct iwl_bt_coex_profile_notif *coex = &pkt->u.bt_coex_profile_notif;
  1447. struct iwl_bt_uart_msg *uart_msg = &coex->last_bt_uart_msg;
  1448. if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) {
  1449. /* bt coex disabled */
  1450. return;
  1451. }
  1452. IWL_DEBUG_COEX(priv, "BT Coex notification:\n");
  1453. IWL_DEBUG_COEX(priv, " status: %d\n", coex->bt_status);
  1454. IWL_DEBUG_COEX(priv, " traffic load: %d\n", coex->bt_traffic_load);
  1455. IWL_DEBUG_COEX(priv, " CI compliance: %d\n",
  1456. coex->bt_ci_compliance);
  1457. iwlagn_print_uartmsg(priv, uart_msg);
  1458. priv->last_bt_traffic_load = priv->bt_traffic_load;
  1459. priv->bt_is_sco = iwlagn_bt_traffic_is_sco(uart_msg);
  1460. if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
  1461. if (priv->bt_status != coex->bt_status ||
  1462. priv->last_bt_traffic_load != coex->bt_traffic_load) {
  1463. if (coex->bt_status) {
  1464. /* BT on */
  1465. if (!priv->bt_ch_announce)
  1466. priv->bt_traffic_load =
  1467. IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
  1468. else
  1469. priv->bt_traffic_load =
  1470. coex->bt_traffic_load;
  1471. } else {
  1472. /* BT off */
  1473. priv->bt_traffic_load =
  1474. IWL_BT_COEX_TRAFFIC_LOAD_NONE;
  1475. }
  1476. priv->bt_status = coex->bt_status;
  1477. queue_work(priv->workqueue,
  1478. &priv->bt_traffic_change_work);
  1479. }
  1480. }
  1481. iwlagn_set_kill_msk(priv, uart_msg);
  1482. /* FIXME: based on notification, adjust the prio_boost */
  1483. spin_lock_irqsave(&priv->lock, flags);
  1484. priv->bt_ci_compliance = coex->bt_ci_compliance;
  1485. spin_unlock_irqrestore(&priv->lock, flags);
  1486. }
  1487. void iwlagn_bt_rx_handler_setup(struct iwl_priv *priv)
  1488. {
  1489. priv->rx_handlers[REPLY_BT_COEX_PROFILE_NOTIF] =
  1490. iwlagn_bt_coex_profile_notif;
  1491. }
  1492. void iwlagn_bt_setup_deferred_work(struct iwl_priv *priv)
  1493. {
  1494. INIT_WORK(&priv->bt_traffic_change_work,
  1495. iwlagn_bt_traffic_change_work);
  1496. }
  1497. void iwlagn_bt_cancel_deferred_work(struct iwl_priv *priv)
  1498. {
  1499. cancel_work_sync(&priv->bt_traffic_change_work);
  1500. }
  1501. static bool is_single_rx_stream(struct iwl_priv *priv)
  1502. {
  1503. return priv->current_ht_config.smps == IEEE80211_SMPS_STATIC ||
  1504. priv->current_ht_config.single_chain_sufficient;
  1505. }
  1506. #define IWL_NUM_RX_CHAINS_MULTIPLE 3
  1507. #define IWL_NUM_RX_CHAINS_SINGLE 2
  1508. #define IWL_NUM_IDLE_CHAINS_DUAL 2
  1509. #define IWL_NUM_IDLE_CHAINS_SINGLE 1
  1510. /*
  1511. * Determine how many receiver/antenna chains to use.
  1512. *
  1513. * More provides better reception via diversity. Fewer saves power
  1514. * at the expense of throughput, but only when not in powersave to
  1515. * start with.
  1516. *
  1517. * MIMO (dual stream) requires at least 2, but works better with 3.
  1518. * This does not determine *which* chains to use, just how many.
  1519. */
  1520. static int iwl_get_active_rx_chain_count(struct iwl_priv *priv)
  1521. {
  1522. if (priv->cfg->bt_params &&
  1523. priv->cfg->bt_params->advanced_bt_coexist &&
  1524. (priv->bt_full_concurrent ||
  1525. priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) {
  1526. /*
  1527. * only use chain 'A' in bt high traffic load or
  1528. * full concurrency mode
  1529. */
  1530. return IWL_NUM_RX_CHAINS_SINGLE;
  1531. }
  1532. /* # of Rx chains to use when expecting MIMO. */
  1533. if (is_single_rx_stream(priv))
  1534. return IWL_NUM_RX_CHAINS_SINGLE;
  1535. else
  1536. return IWL_NUM_RX_CHAINS_MULTIPLE;
  1537. }
  1538. /*
  1539. * When we are in power saving mode, unless device support spatial
  1540. * multiplexing power save, use the active count for rx chain count.
  1541. */
  1542. static int iwl_get_idle_rx_chain_count(struct iwl_priv *priv, int active_cnt)
  1543. {
  1544. /* # Rx chains when idling, depending on SMPS mode */
  1545. switch (priv->current_ht_config.smps) {
  1546. case IEEE80211_SMPS_STATIC:
  1547. case IEEE80211_SMPS_DYNAMIC:
  1548. return IWL_NUM_IDLE_CHAINS_SINGLE;
  1549. case IEEE80211_SMPS_OFF:
  1550. return active_cnt;
  1551. default:
  1552. WARN(1, "invalid SMPS mode %d",
  1553. priv->current_ht_config.smps);
  1554. return active_cnt;
  1555. }
  1556. }
  1557. /* up to 4 chains */
  1558. static u8 iwl_count_chain_bitmap(u32 chain_bitmap)
  1559. {
  1560. u8 res;
  1561. res = (chain_bitmap & BIT(0)) >> 0;
  1562. res += (chain_bitmap & BIT(1)) >> 1;
  1563. res += (chain_bitmap & BIT(2)) >> 2;
  1564. res += (chain_bitmap & BIT(3)) >> 3;
  1565. return res;
  1566. }
  1567. /**
  1568. * iwlagn_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
  1569. *
  1570. * Selects how many and which Rx receivers/antennas/chains to use.
  1571. * This should not be used for scan command ... it puts data in wrong place.
  1572. */
  1573. void iwlagn_set_rxon_chain(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  1574. {
  1575. bool is_single = is_single_rx_stream(priv);
  1576. bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->status);
  1577. u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt;
  1578. u32 active_chains;
  1579. u16 rx_chain;
  1580. /* Tell uCode which antennas are actually connected.
  1581. * Before first association, we assume all antennas are connected.
  1582. * Just after first association, iwl_chain_noise_calibration()
  1583. * checks which antennas actually *are* connected. */
  1584. if (priv->chain_noise_data.active_chains)
  1585. active_chains = priv->chain_noise_data.active_chains;
  1586. else
  1587. active_chains = priv->hw_params.valid_rx_ant;
  1588. if (priv->cfg->bt_params &&
  1589. priv->cfg->bt_params->advanced_bt_coexist &&
  1590. (priv->bt_full_concurrent ||
  1591. priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) {
  1592. /*
  1593. * only use chain 'A' in bt high traffic load or
  1594. * full concurrency mode
  1595. */
  1596. active_chains = first_antenna(active_chains);
  1597. }
  1598. rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS;
  1599. /* How many receivers should we use? */
  1600. active_rx_cnt = iwl_get_active_rx_chain_count(priv);
  1601. idle_rx_cnt = iwl_get_idle_rx_chain_count(priv, active_rx_cnt);
  1602. /* correct rx chain count according hw settings
  1603. * and chain noise calibration
  1604. */
  1605. valid_rx_cnt = iwl_count_chain_bitmap(active_chains);
  1606. if (valid_rx_cnt < active_rx_cnt)
  1607. active_rx_cnt = valid_rx_cnt;
  1608. if (valid_rx_cnt < idle_rx_cnt)
  1609. idle_rx_cnt = valid_rx_cnt;
  1610. rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS;
  1611. rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS;
  1612. ctx->staging.rx_chain = cpu_to_le16(rx_chain);
  1613. if (!is_single && (active_rx_cnt >= IWL_NUM_RX_CHAINS_SINGLE) && is_cam)
  1614. ctx->staging.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
  1615. else
  1616. ctx->staging.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
  1617. IWL_DEBUG_ASSOC(priv, "rx_chain=0x%X active=%d idle=%d\n",
  1618. ctx->staging.rx_chain,
  1619. active_rx_cnt, idle_rx_cnt);
  1620. WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 ||
  1621. active_rx_cnt < idle_rx_cnt);
  1622. }
  1623. u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant, u8 valid)
  1624. {
  1625. int i;
  1626. u8 ind = ant;
  1627. if (priv->band == IEEE80211_BAND_2GHZ &&
  1628. priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)
  1629. return 0;
  1630. for (i = 0; i < RATE_ANT_NUM - 1; i++) {
  1631. ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0;
  1632. if (valid & BIT(ind))
  1633. return ind;
  1634. }
  1635. return ant;
  1636. }
  1637. static const char *get_csr_string(int cmd)
  1638. {
  1639. switch (cmd) {
  1640. IWL_CMD(CSR_HW_IF_CONFIG_REG);
  1641. IWL_CMD(CSR_INT_COALESCING);
  1642. IWL_CMD(CSR_INT);
  1643. IWL_CMD(CSR_INT_MASK);
  1644. IWL_CMD(CSR_FH_INT_STATUS);
  1645. IWL_CMD(CSR_GPIO_IN);
  1646. IWL_CMD(CSR_RESET);
  1647. IWL_CMD(CSR_GP_CNTRL);
  1648. IWL_CMD(CSR_HW_REV);
  1649. IWL_CMD(CSR_EEPROM_REG);
  1650. IWL_CMD(CSR_EEPROM_GP);
  1651. IWL_CMD(CSR_OTP_GP_REG);
  1652. IWL_CMD(CSR_GIO_REG);
  1653. IWL_CMD(CSR_GP_UCODE_REG);
  1654. IWL_CMD(CSR_GP_DRIVER_REG);
  1655. IWL_CMD(CSR_UCODE_DRV_GP1);
  1656. IWL_CMD(CSR_UCODE_DRV_GP2);
  1657. IWL_CMD(CSR_LED_REG);
  1658. IWL_CMD(CSR_DRAM_INT_TBL_REG);
  1659. IWL_CMD(CSR_GIO_CHICKEN_BITS);
  1660. IWL_CMD(CSR_ANA_PLL_CFG);
  1661. IWL_CMD(CSR_HW_REV_WA_REG);
  1662. IWL_CMD(CSR_DBG_HPET_MEM_REG);
  1663. default:
  1664. return "UNKNOWN";
  1665. }
  1666. }
  1667. void iwl_dump_csr(struct iwl_priv *priv)
  1668. {
  1669. int i;
  1670. static const u32 csr_tbl[] = {
  1671. CSR_HW_IF_CONFIG_REG,
  1672. CSR_INT_COALESCING,
  1673. CSR_INT,
  1674. CSR_INT_MASK,
  1675. CSR_FH_INT_STATUS,
  1676. CSR_GPIO_IN,
  1677. CSR_RESET,
  1678. CSR_GP_CNTRL,
  1679. CSR_HW_REV,
  1680. CSR_EEPROM_REG,
  1681. CSR_EEPROM_GP,
  1682. CSR_OTP_GP_REG,
  1683. CSR_GIO_REG,
  1684. CSR_GP_UCODE_REG,
  1685. CSR_GP_DRIVER_REG,
  1686. CSR_UCODE_DRV_GP1,
  1687. CSR_UCODE_DRV_GP2,
  1688. CSR_LED_REG,
  1689. CSR_DRAM_INT_TBL_REG,
  1690. CSR_GIO_CHICKEN_BITS,
  1691. CSR_ANA_PLL_CFG,
  1692. CSR_HW_REV_WA_REG,
  1693. CSR_DBG_HPET_MEM_REG
  1694. };
  1695. IWL_ERR(priv, "CSR values:\n");
  1696. IWL_ERR(priv, "(2nd byte of CSR_INT_COALESCING is "
  1697. "CSR_INT_PERIODIC_REG)\n");
  1698. for (i = 0; i < ARRAY_SIZE(csr_tbl); i++) {
  1699. IWL_ERR(priv, " %25s: 0X%08x\n",
  1700. get_csr_string(csr_tbl[i]),
  1701. iwl_read32(priv, csr_tbl[i]));
  1702. }
  1703. }
  1704. static const char *get_fh_string(int cmd)
  1705. {
  1706. switch (cmd) {
  1707. IWL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG);
  1708. IWL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG);
  1709. IWL_CMD(FH_RSCSR_CHNL0_WPTR);
  1710. IWL_CMD(FH_MEM_RCSR_CHNL0_CONFIG_REG);
  1711. IWL_CMD(FH_MEM_RSSR_SHARED_CTRL_REG);
  1712. IWL_CMD(FH_MEM_RSSR_RX_STATUS_REG);
  1713. IWL_CMD(FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV);
  1714. IWL_CMD(FH_TSSR_TX_STATUS_REG);
  1715. IWL_CMD(FH_TSSR_TX_ERROR_REG);
  1716. default:
  1717. return "UNKNOWN";
  1718. }
  1719. }
  1720. int iwl_dump_fh(struct iwl_priv *priv, char **buf, bool display)
  1721. {
  1722. int i;
  1723. #ifdef CONFIG_IWLWIFI_DEBUG
  1724. int pos = 0;
  1725. size_t bufsz = 0;
  1726. #endif
  1727. static const u32 fh_tbl[] = {
  1728. FH_RSCSR_CHNL0_STTS_WPTR_REG,
  1729. FH_RSCSR_CHNL0_RBDCB_BASE_REG,
  1730. FH_RSCSR_CHNL0_WPTR,
  1731. FH_MEM_RCSR_CHNL0_CONFIG_REG,
  1732. FH_MEM_RSSR_SHARED_CTRL_REG,
  1733. FH_MEM_RSSR_RX_STATUS_REG,
  1734. FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV,
  1735. FH_TSSR_TX_STATUS_REG,
  1736. FH_TSSR_TX_ERROR_REG
  1737. };
  1738. #ifdef CONFIG_IWLWIFI_DEBUG
  1739. if (display) {
  1740. bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40;
  1741. *buf = kmalloc(bufsz, GFP_KERNEL);
  1742. if (!*buf)
  1743. return -ENOMEM;
  1744. pos += scnprintf(*buf + pos, bufsz - pos,
  1745. "FH register values:\n");
  1746. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
  1747. pos += scnprintf(*buf + pos, bufsz - pos,
  1748. " %34s: 0X%08x\n",
  1749. get_fh_string(fh_tbl[i]),
  1750. iwl_read_direct32(priv, fh_tbl[i]));
  1751. }
  1752. return pos;
  1753. }
  1754. #endif
  1755. IWL_ERR(priv, "FH register values:\n");
  1756. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
  1757. IWL_ERR(priv, " %34s: 0X%08x\n",
  1758. get_fh_string(fh_tbl[i]),
  1759. iwl_read_direct32(priv, fh_tbl[i]));
  1760. }
  1761. return 0;
  1762. }
  1763. /* notification wait support */
  1764. void iwlagn_init_notification_wait(struct iwl_priv *priv,
  1765. struct iwl_notification_wait *wait_entry,
  1766. u8 cmd,
  1767. void (*fn)(struct iwl_priv *priv,
  1768. struct iwl_rx_packet *pkt,
  1769. void *data),
  1770. void *fn_data)
  1771. {
  1772. wait_entry->fn = fn;
  1773. wait_entry->fn_data = fn_data;
  1774. wait_entry->cmd = cmd;
  1775. wait_entry->triggered = false;
  1776. wait_entry->aborted = false;
  1777. spin_lock_bh(&priv->notif_wait_lock);
  1778. list_add(&wait_entry->list, &priv->notif_waits);
  1779. spin_unlock_bh(&priv->notif_wait_lock);
  1780. }
  1781. int iwlagn_wait_notification(struct iwl_priv *priv,
  1782. struct iwl_notification_wait *wait_entry,
  1783. unsigned long timeout)
  1784. {
  1785. int ret;
  1786. ret = wait_event_timeout(priv->notif_waitq,
  1787. wait_entry->triggered || wait_entry->aborted,
  1788. timeout);
  1789. spin_lock_bh(&priv->notif_wait_lock);
  1790. list_del(&wait_entry->list);
  1791. spin_unlock_bh(&priv->notif_wait_lock);
  1792. if (wait_entry->aborted)
  1793. return -EIO;
  1794. /* return value is always >= 0 */
  1795. if (ret <= 0)
  1796. return -ETIMEDOUT;
  1797. return 0;
  1798. }
  1799. void iwlagn_remove_notification(struct iwl_priv *priv,
  1800. struct iwl_notification_wait *wait_entry)
  1801. {
  1802. spin_lock_bh(&priv->notif_wait_lock);
  1803. list_del(&wait_entry->list);
  1804. spin_unlock_bh(&priv->notif_wait_lock);
  1805. }