iwl-agn-lib.c 66 KB

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