iwl-agn-lib.c 58 KB

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