iwl-agn.c 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of version 2 of the GNU General Public License as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  30. #include <linux/kernel.h>
  31. #include <linux/module.h>
  32. #include <linux/init.h>
  33. #include <linux/slab.h>
  34. #include <linux/delay.h>
  35. #include <linux/sched.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/netdevice.h>
  38. #include <linux/etherdevice.h>
  39. #include <linux/if_arp.h>
  40. #include <net/mac80211.h>
  41. #include <asm/div64.h>
  42. #include "iwl-eeprom.h"
  43. #include "iwl-dev.h"
  44. #include "iwl-core.h"
  45. #include "iwl-io.h"
  46. #include "iwl-agn-calib.h"
  47. #include "iwl-agn.h"
  48. #include "iwl-shared.h"
  49. #include "iwl-trans.h"
  50. #include "iwl-op-mode.h"
  51. /******************************************************************************
  52. *
  53. * module boiler plate
  54. *
  55. ******************************************************************************/
  56. /*
  57. * module name, copyright, version, etc.
  58. */
  59. #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
  60. #ifdef CONFIG_IWLWIFI_DEBUG
  61. #define VD "d"
  62. #else
  63. #define VD
  64. #endif
  65. #define DRV_VERSION IWLWIFI_VERSION VD
  66. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  67. MODULE_VERSION(DRV_VERSION);
  68. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  69. MODULE_LICENSE("GPL");
  70. MODULE_ALIAS("iwlagn");
  71. void iwl_update_chain_flags(struct iwl_priv *priv)
  72. {
  73. struct iwl_rxon_context *ctx;
  74. for_each_context(priv, ctx) {
  75. iwlagn_set_rxon_chain(priv, ctx);
  76. if (ctx->active.rx_chain != ctx->staging.rx_chain)
  77. iwlagn_commit_rxon(priv, ctx);
  78. }
  79. }
  80. /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
  81. static void iwl_set_beacon_tim(struct iwl_priv *priv,
  82. struct iwl_tx_beacon_cmd *tx_beacon_cmd,
  83. u8 *beacon, u32 frame_size)
  84. {
  85. u16 tim_idx;
  86. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
  87. /*
  88. * The index is relative to frame start but we start looking at the
  89. * variable-length part of the beacon.
  90. */
  91. tim_idx = mgmt->u.beacon.variable - beacon;
  92. /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
  93. while ((tim_idx < (frame_size - 2)) &&
  94. (beacon[tim_idx] != WLAN_EID_TIM))
  95. tim_idx += beacon[tim_idx+1] + 2;
  96. /* If TIM field was found, set variables */
  97. if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
  98. tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
  99. tx_beacon_cmd->tim_size = beacon[tim_idx+1];
  100. } else
  101. IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
  102. }
  103. int iwlagn_send_beacon_cmd(struct iwl_priv *priv)
  104. {
  105. struct iwl_tx_beacon_cmd *tx_beacon_cmd;
  106. struct iwl_host_cmd cmd = {
  107. .id = REPLY_TX_BEACON,
  108. .flags = CMD_SYNC,
  109. };
  110. struct ieee80211_tx_info *info;
  111. u32 frame_size;
  112. u32 rate_flags;
  113. u32 rate;
  114. /*
  115. * We have to set up the TX command, the TX Beacon command, and the
  116. * beacon contents.
  117. */
  118. lockdep_assert_held(&priv->mutex);
  119. if (!priv->beacon_ctx) {
  120. IWL_ERR(priv, "trying to build beacon w/o beacon context!\n");
  121. return 0;
  122. }
  123. if (WARN_ON(!priv->beacon_skb))
  124. return -EINVAL;
  125. /* Allocate beacon command */
  126. if (!priv->beacon_cmd)
  127. priv->beacon_cmd = kzalloc(sizeof(*tx_beacon_cmd), GFP_KERNEL);
  128. tx_beacon_cmd = priv->beacon_cmd;
  129. if (!tx_beacon_cmd)
  130. return -ENOMEM;
  131. frame_size = priv->beacon_skb->len;
  132. /* Set up TX command fields */
  133. tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
  134. tx_beacon_cmd->tx.sta_id = priv->beacon_ctx->bcast_sta_id;
  135. tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  136. tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
  137. TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
  138. /* Set up TX beacon command fields */
  139. iwl_set_beacon_tim(priv, tx_beacon_cmd, priv->beacon_skb->data,
  140. frame_size);
  141. /* Set up packet rate and flags */
  142. info = IEEE80211_SKB_CB(priv->beacon_skb);
  143. /*
  144. * Let's set up the rate at least somewhat correctly;
  145. * it will currently not actually be used by the uCode,
  146. * it uses the broadcast station's rate instead.
  147. */
  148. if (info->control.rates[0].idx < 0 ||
  149. info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
  150. rate = 0;
  151. else
  152. rate = info->control.rates[0].idx;
  153. priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
  154. priv->hw_params.valid_tx_ant);
  155. rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
  156. /* In mac80211, rates for 5 GHz start at 0 */
  157. if (info->band == IEEE80211_BAND_5GHZ)
  158. rate += IWL_FIRST_OFDM_RATE;
  159. else if (rate >= IWL_FIRST_CCK_RATE && rate <= IWL_LAST_CCK_RATE)
  160. rate_flags |= RATE_MCS_CCK_MSK;
  161. tx_beacon_cmd->tx.rate_n_flags =
  162. iwl_hw_set_rate_n_flags(rate, rate_flags);
  163. /* Submit command */
  164. cmd.len[0] = sizeof(*tx_beacon_cmd);
  165. cmd.data[0] = tx_beacon_cmd;
  166. cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
  167. cmd.len[1] = frame_size;
  168. cmd.data[1] = priv->beacon_skb->data;
  169. cmd.dataflags[1] = IWL_HCMD_DFL_NOCOPY;
  170. return iwl_dvm_send_cmd(priv, &cmd);
  171. }
  172. static void iwl_bg_beacon_update(struct work_struct *work)
  173. {
  174. struct iwl_priv *priv =
  175. container_of(work, struct iwl_priv, beacon_update);
  176. struct sk_buff *beacon;
  177. mutex_lock(&priv->mutex);
  178. if (!priv->beacon_ctx) {
  179. IWL_ERR(priv, "updating beacon w/o beacon context!\n");
  180. goto out;
  181. }
  182. if (priv->beacon_ctx->vif->type != NL80211_IFTYPE_AP) {
  183. /*
  184. * The ucode will send beacon notifications even in
  185. * IBSS mode, but we don't want to process them. But
  186. * we need to defer the type check to here due to
  187. * requiring locking around the beacon_ctx access.
  188. */
  189. goto out;
  190. }
  191. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  192. beacon = ieee80211_beacon_get(priv->hw, priv->beacon_ctx->vif);
  193. if (!beacon) {
  194. IWL_ERR(priv, "update beacon failed -- keeping old\n");
  195. goto out;
  196. }
  197. /* new beacon skb is allocated every time; dispose previous.*/
  198. dev_kfree_skb(priv->beacon_skb);
  199. priv->beacon_skb = beacon;
  200. iwlagn_send_beacon_cmd(priv);
  201. out:
  202. mutex_unlock(&priv->mutex);
  203. }
  204. static void iwl_bg_bt_runtime_config(struct work_struct *work)
  205. {
  206. struct iwl_priv *priv =
  207. container_of(work, struct iwl_priv, bt_runtime_config);
  208. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  209. return;
  210. /* dont send host command if rf-kill is on */
  211. if (!iwl_is_ready_rf(priv))
  212. return;
  213. iwlagn_send_advance_bt_config(priv);
  214. }
  215. static void iwl_bg_bt_full_concurrency(struct work_struct *work)
  216. {
  217. struct iwl_priv *priv =
  218. container_of(work, struct iwl_priv, bt_full_concurrency);
  219. struct iwl_rxon_context *ctx;
  220. mutex_lock(&priv->mutex);
  221. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  222. goto out;
  223. /* dont send host command if rf-kill is on */
  224. if (!iwl_is_ready_rf(priv))
  225. goto out;
  226. IWL_DEBUG_INFO(priv, "BT coex in %s mode\n",
  227. priv->bt_full_concurrent ?
  228. "full concurrency" : "3-wire");
  229. /*
  230. * LQ & RXON updated cmds must be sent before BT Config cmd
  231. * to avoid 3-wire collisions
  232. */
  233. for_each_context(priv, ctx) {
  234. iwlagn_set_rxon_chain(priv, ctx);
  235. iwlagn_commit_rxon(priv, ctx);
  236. }
  237. iwlagn_send_advance_bt_config(priv);
  238. out:
  239. mutex_unlock(&priv->mutex);
  240. }
  241. int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
  242. {
  243. struct iwl_statistics_cmd statistics_cmd = {
  244. .configuration_flags =
  245. clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
  246. };
  247. if (flags & CMD_ASYNC)
  248. return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
  249. CMD_ASYNC,
  250. sizeof(struct iwl_statistics_cmd),
  251. &statistics_cmd);
  252. else
  253. return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
  254. CMD_SYNC,
  255. sizeof(struct iwl_statistics_cmd),
  256. &statistics_cmd);
  257. }
  258. /**
  259. * iwl_bg_statistics_periodic - Timer callback to queue statistics
  260. *
  261. * This callback is provided in order to send a statistics request.
  262. *
  263. * This timer function is continually reset to execute within
  264. * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
  265. * was received. We need to ensure we receive the statistics in order
  266. * to update the temperature used for calibrating the TXPOWER.
  267. */
  268. static void iwl_bg_statistics_periodic(unsigned long data)
  269. {
  270. struct iwl_priv *priv = (struct iwl_priv *)data;
  271. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  272. return;
  273. /* dont send host command if rf-kill is on */
  274. if (!iwl_is_ready_rf(priv))
  275. return;
  276. iwl_send_statistics_request(priv, CMD_ASYNC, false);
  277. }
  278. static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base,
  279. u32 start_idx, u32 num_events,
  280. u32 capacity, u32 mode)
  281. {
  282. u32 i;
  283. u32 ptr; /* SRAM byte address of log data */
  284. u32 ev, time, data; /* event log data */
  285. unsigned long reg_flags;
  286. if (mode == 0)
  287. ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32));
  288. else
  289. ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32));
  290. /* Make sure device is powered up for SRAM reads */
  291. spin_lock_irqsave(&trans(priv)->reg_lock, reg_flags);
  292. if (unlikely(!iwl_grab_nic_access(trans(priv)))) {
  293. spin_unlock_irqrestore(&trans(priv)->reg_lock, reg_flags);
  294. return;
  295. }
  296. /* Set starting address; reads will auto-increment */
  297. iwl_write32(trans(priv), HBUS_TARG_MEM_RADDR, ptr);
  298. /*
  299. * Refuse to read more than would have fit into the log from
  300. * the current start_idx. This used to happen due to the race
  301. * described below, but now WARN because the code below should
  302. * prevent it from happening here.
  303. */
  304. if (WARN_ON(num_events > capacity - start_idx))
  305. num_events = capacity - start_idx;
  306. /*
  307. * "time" is actually "data" for mode 0 (no timestamp).
  308. * place event id # at far right for easier visual parsing.
  309. */
  310. for (i = 0; i < num_events; i++) {
  311. ev = iwl_read32(trans(priv), HBUS_TARG_MEM_RDAT);
  312. time = iwl_read32(trans(priv), HBUS_TARG_MEM_RDAT);
  313. if (mode == 0) {
  314. trace_iwlwifi_dev_ucode_cont_event(
  315. trans(priv)->dev, 0, time, ev);
  316. } else {
  317. data = iwl_read32(trans(priv), HBUS_TARG_MEM_RDAT);
  318. trace_iwlwifi_dev_ucode_cont_event(
  319. trans(priv)->dev, time, data, ev);
  320. }
  321. }
  322. /* Allow device to power down */
  323. iwl_release_nic_access(trans(priv));
  324. spin_unlock_irqrestore(&trans(priv)->reg_lock, reg_flags);
  325. }
  326. static void iwl_continuous_event_trace(struct iwl_priv *priv)
  327. {
  328. u32 capacity; /* event log capacity in # entries */
  329. struct {
  330. u32 capacity;
  331. u32 mode;
  332. u32 wrap_counter;
  333. u32 write_counter;
  334. } __packed read;
  335. u32 base; /* SRAM byte address of event log header */
  336. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  337. u32 num_wraps; /* # times uCode wrapped to top of log */
  338. u32 next_entry; /* index of next entry to be written by uCode */
  339. base = priv->device_pointers.log_event_table;
  340. if (iwlagn_hw_valid_rtc_data_addr(base)) {
  341. iwl_read_targ_mem_words(trans(priv), base, &read, sizeof(read));
  342. capacity = read.capacity;
  343. mode = read.mode;
  344. num_wraps = read.wrap_counter;
  345. next_entry = read.write_counter;
  346. } else
  347. return;
  348. /*
  349. * Unfortunately, the uCode doesn't use temporary variables.
  350. * Therefore, it can happen that we read next_entry == capacity,
  351. * which really means next_entry == 0.
  352. */
  353. if (unlikely(next_entry == capacity))
  354. next_entry = 0;
  355. /*
  356. * Additionally, the uCode increases the write pointer before
  357. * the wraps counter, so if the write pointer is smaller than
  358. * the old write pointer (wrap occurred) but we read that no
  359. * wrap occurred, we actually read between the next_entry and
  360. * num_wraps update (this does happen in practice!!) -- take
  361. * that into account by increasing num_wraps.
  362. */
  363. if (unlikely(next_entry < priv->event_log.next_entry &&
  364. num_wraps == priv->event_log.num_wraps))
  365. num_wraps++;
  366. if (num_wraps == priv->event_log.num_wraps) {
  367. iwl_print_cont_event_trace(
  368. priv, base, priv->event_log.next_entry,
  369. next_entry - priv->event_log.next_entry,
  370. capacity, mode);
  371. priv->event_log.non_wraps_count++;
  372. } else {
  373. if (num_wraps - priv->event_log.num_wraps > 1)
  374. priv->event_log.wraps_more_count++;
  375. else
  376. priv->event_log.wraps_once_count++;
  377. trace_iwlwifi_dev_ucode_wrap_event(trans(priv)->dev,
  378. num_wraps - priv->event_log.num_wraps,
  379. next_entry, priv->event_log.next_entry);
  380. if (next_entry < priv->event_log.next_entry) {
  381. iwl_print_cont_event_trace(
  382. priv, base, priv->event_log.next_entry,
  383. capacity - priv->event_log.next_entry,
  384. capacity, mode);
  385. iwl_print_cont_event_trace(
  386. priv, base, 0, next_entry, capacity, mode);
  387. } else {
  388. iwl_print_cont_event_trace(
  389. priv, base, next_entry,
  390. capacity - next_entry,
  391. capacity, mode);
  392. iwl_print_cont_event_trace(
  393. priv, base, 0, next_entry, capacity, mode);
  394. }
  395. }
  396. priv->event_log.num_wraps = num_wraps;
  397. priv->event_log.next_entry = next_entry;
  398. }
  399. /**
  400. * iwl_bg_ucode_trace - Timer callback to log ucode event
  401. *
  402. * The timer is continually set to execute every
  403. * UCODE_TRACE_PERIOD milliseconds after the last timer expired
  404. * this function is to perform continuous uCode event logging operation
  405. * if enabled
  406. */
  407. static void iwl_bg_ucode_trace(unsigned long data)
  408. {
  409. struct iwl_priv *priv = (struct iwl_priv *)data;
  410. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  411. return;
  412. if (priv->event_log.ucode_trace) {
  413. iwl_continuous_event_trace(priv);
  414. /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
  415. mod_timer(&priv->ucode_trace,
  416. jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
  417. }
  418. }
  419. static void iwl_bg_tx_flush(struct work_struct *work)
  420. {
  421. struct iwl_priv *priv =
  422. container_of(work, struct iwl_priv, tx_flush);
  423. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  424. return;
  425. /* do nothing if rf-kill is on */
  426. if (!iwl_is_ready_rf(priv))
  427. return;
  428. IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n");
  429. iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
  430. }
  431. /*
  432. * queue/FIFO/AC mapping definitions
  433. */
  434. #define IWL_TX_FIFO_BK 0 /* shared */
  435. #define IWL_TX_FIFO_BE 1
  436. #define IWL_TX_FIFO_VI 2 /* shared */
  437. #define IWL_TX_FIFO_VO 3
  438. #define IWL_TX_FIFO_BK_IPAN IWL_TX_FIFO_BK
  439. #define IWL_TX_FIFO_BE_IPAN 4
  440. #define IWL_TX_FIFO_VI_IPAN IWL_TX_FIFO_VI
  441. #define IWL_TX_FIFO_VO_IPAN 5
  442. /* re-uses the VO FIFO, uCode will properly flush/schedule */
  443. #define IWL_TX_FIFO_AUX 5
  444. #define IWL_TX_FIFO_UNUSED -1
  445. #define IWLAGN_CMD_FIFO_NUM 7
  446. /*
  447. * This queue number is required for proper operation
  448. * because the ucode will stop/start the scheduler as
  449. * required.
  450. */
  451. #define IWL_IPAN_MCAST_QUEUE 8
  452. static const u8 iwlagn_default_queue_to_tx_fifo[] = {
  453. IWL_TX_FIFO_VO,
  454. IWL_TX_FIFO_VI,
  455. IWL_TX_FIFO_BE,
  456. IWL_TX_FIFO_BK,
  457. IWLAGN_CMD_FIFO_NUM,
  458. };
  459. static const u8 iwlagn_ipan_queue_to_tx_fifo[] = {
  460. IWL_TX_FIFO_VO,
  461. IWL_TX_FIFO_VI,
  462. IWL_TX_FIFO_BE,
  463. IWL_TX_FIFO_BK,
  464. IWL_TX_FIFO_BK_IPAN,
  465. IWL_TX_FIFO_BE_IPAN,
  466. IWL_TX_FIFO_VI_IPAN,
  467. IWL_TX_FIFO_VO_IPAN,
  468. IWL_TX_FIFO_BE_IPAN,
  469. IWLAGN_CMD_FIFO_NUM,
  470. IWL_TX_FIFO_AUX,
  471. };
  472. static const u8 iwlagn_bss_ac_to_fifo[] = {
  473. IWL_TX_FIFO_VO,
  474. IWL_TX_FIFO_VI,
  475. IWL_TX_FIFO_BE,
  476. IWL_TX_FIFO_BK,
  477. };
  478. static const u8 iwlagn_bss_ac_to_queue[] = {
  479. 0, 1, 2, 3,
  480. };
  481. static const u8 iwlagn_pan_ac_to_fifo[] = {
  482. IWL_TX_FIFO_VO_IPAN,
  483. IWL_TX_FIFO_VI_IPAN,
  484. IWL_TX_FIFO_BE_IPAN,
  485. IWL_TX_FIFO_BK_IPAN,
  486. };
  487. static const u8 iwlagn_pan_ac_to_queue[] = {
  488. 7, 6, 5, 4,
  489. };
  490. static const u8 iwlagn_bss_queue_to_ac[] = {
  491. IEEE80211_AC_VO,
  492. IEEE80211_AC_VI,
  493. IEEE80211_AC_BE,
  494. IEEE80211_AC_BK,
  495. };
  496. static const u8 iwlagn_pan_queue_to_ac[] = {
  497. IEEE80211_AC_VO,
  498. IEEE80211_AC_VI,
  499. IEEE80211_AC_BE,
  500. IEEE80211_AC_BK,
  501. IEEE80211_AC_BK,
  502. IEEE80211_AC_BE,
  503. IEEE80211_AC_VI,
  504. IEEE80211_AC_VO,
  505. };
  506. static void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags)
  507. {
  508. int i;
  509. /*
  510. * The default context is always valid,
  511. * the PAN context depends on uCode.
  512. */
  513. priv->valid_contexts = BIT(IWL_RXON_CTX_BSS);
  514. if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN)
  515. priv->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
  516. for (i = 0; i < NUM_IWL_RXON_CTX; i++)
  517. priv->contexts[i].ctxid = i;
  518. priv->contexts[IWL_RXON_CTX_BSS].always_active = true;
  519. priv->contexts[IWL_RXON_CTX_BSS].is_active = true;
  520. priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
  521. priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
  522. priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
  523. priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
  524. priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
  525. priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
  526. priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
  527. priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
  528. BIT(NL80211_IFTYPE_ADHOC);
  529. priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
  530. BIT(NL80211_IFTYPE_STATION);
  531. priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP;
  532. priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
  533. priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
  534. priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
  535. memcpy(priv->contexts[IWL_RXON_CTX_BSS].ac_to_queue,
  536. iwlagn_bss_ac_to_queue, sizeof(iwlagn_bss_ac_to_queue));
  537. memcpy(priv->contexts[IWL_RXON_CTX_BSS].ac_to_fifo,
  538. iwlagn_bss_ac_to_fifo, sizeof(iwlagn_bss_ac_to_fifo));
  539. priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON;
  540. priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd =
  541. REPLY_WIPAN_RXON_TIMING;
  542. priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd =
  543. REPLY_WIPAN_RXON_ASSOC;
  544. priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM;
  545. priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN;
  546. priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY;
  547. priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID;
  548. priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION;
  549. priv->contexts[IWL_RXON_CTX_PAN].interface_modes =
  550. BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
  551. if (ucode_flags & IWL_UCODE_TLV_FLAGS_P2P)
  552. priv->contexts[IWL_RXON_CTX_PAN].interface_modes |=
  553. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  554. BIT(NL80211_IFTYPE_P2P_GO);
  555. priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP;
  556. priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA;
  557. priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P;
  558. memcpy(priv->contexts[IWL_RXON_CTX_PAN].ac_to_queue,
  559. iwlagn_pan_ac_to_queue, sizeof(iwlagn_pan_ac_to_queue));
  560. memcpy(priv->contexts[IWL_RXON_CTX_PAN].ac_to_fifo,
  561. iwlagn_pan_ac_to_fifo, sizeof(iwlagn_pan_ac_to_fifo));
  562. priv->contexts[IWL_RXON_CTX_PAN].mcast_queue = IWL_IPAN_MCAST_QUEUE;
  563. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  564. }
  565. static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
  566. {
  567. struct iwl_ct_kill_config cmd;
  568. struct iwl_ct_kill_throttling_config adv_cmd;
  569. int ret = 0;
  570. iwl_write32(trans(priv), CSR_UCODE_DRV_GP1_CLR,
  571. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  572. priv->thermal_throttle.ct_kill_toggle = false;
  573. if (cfg(priv)->base_params->support_ct_kill_exit) {
  574. adv_cmd.critical_temperature_enter =
  575. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  576. adv_cmd.critical_temperature_exit =
  577. cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
  578. ret = iwl_dvm_send_cmd_pdu(priv,
  579. REPLY_CT_KILL_CONFIG_CMD,
  580. CMD_SYNC, sizeof(adv_cmd), &adv_cmd);
  581. if (ret)
  582. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  583. else
  584. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  585. "succeeded, critical temperature enter is %d,"
  586. "exit is %d\n",
  587. priv->hw_params.ct_kill_threshold,
  588. priv->hw_params.ct_kill_exit_threshold);
  589. } else {
  590. cmd.critical_temperature_R =
  591. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  592. ret = iwl_dvm_send_cmd_pdu(priv,
  593. REPLY_CT_KILL_CONFIG_CMD,
  594. CMD_SYNC, sizeof(cmd), &cmd);
  595. if (ret)
  596. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  597. else
  598. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  599. "succeeded, "
  600. "critical temperature is %d\n",
  601. priv->hw_params.ct_kill_threshold);
  602. }
  603. }
  604. static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
  605. {
  606. struct iwl_calib_cfg_cmd calib_cfg_cmd;
  607. struct iwl_host_cmd cmd = {
  608. .id = CALIBRATION_CFG_CMD,
  609. .len = { sizeof(struct iwl_calib_cfg_cmd), },
  610. .data = { &calib_cfg_cmd, },
  611. };
  612. memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
  613. calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_RT_CFG_ALL;
  614. calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg);
  615. return iwl_dvm_send_cmd(priv, &cmd);
  616. }
  617. static int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant)
  618. {
  619. struct iwl_tx_ant_config_cmd tx_ant_cmd = {
  620. .valid = cpu_to_le32(valid_tx_ant),
  621. };
  622. if (IWL_UCODE_API(priv->fw->ucode_ver) > 1) {
  623. IWL_DEBUG_HC(priv, "select valid tx ant: %u\n", valid_tx_ant);
  624. return iwl_dvm_send_cmd_pdu(priv,
  625. TX_ANT_CONFIGURATION_CMD,
  626. CMD_SYNC,
  627. sizeof(struct iwl_tx_ant_config_cmd),
  628. &tx_ant_cmd);
  629. } else {
  630. IWL_DEBUG_HC(priv, "TX_ANT_CONFIGURATION_CMD not supported\n");
  631. return -EOPNOTSUPP;
  632. }
  633. }
  634. static void iwl_send_bt_config(struct iwl_priv *priv)
  635. {
  636. struct iwl_bt_cmd bt_cmd = {
  637. .lead_time = BT_LEAD_TIME_DEF,
  638. .max_kill = BT_MAX_KILL_DEF,
  639. .kill_ack_mask = 0,
  640. .kill_cts_mask = 0,
  641. };
  642. if (!iwlagn_mod_params.bt_coex_active)
  643. bt_cmd.flags = BT_COEX_DISABLE;
  644. else
  645. bt_cmd.flags = BT_COEX_ENABLE;
  646. priv->bt_enable_flag = bt_cmd.flags;
  647. IWL_DEBUG_INFO(priv, "BT coex %s\n",
  648. (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
  649. if (iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  650. CMD_SYNC, sizeof(struct iwl_bt_cmd), &bt_cmd))
  651. IWL_ERR(priv, "failed to send BT Coex Config\n");
  652. }
  653. /**
  654. * iwl_alive_start - called after REPLY_ALIVE notification received
  655. * from protocol/runtime uCode (initialization uCode's
  656. * Alive gets handled by iwl_init_alive_start()).
  657. */
  658. int iwl_alive_start(struct iwl_priv *priv)
  659. {
  660. int ret = 0;
  661. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  662. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  663. /* After the ALIVE response, we can send host commands to the uCode */
  664. set_bit(STATUS_ALIVE, &priv->status);
  665. if (iwl_is_rfkill(priv))
  666. return -ERFKILL;
  667. if (priv->event_log.ucode_trace) {
  668. /* start collecting data now */
  669. mod_timer(&priv->ucode_trace, jiffies);
  670. }
  671. /* download priority table before any calibration request */
  672. if (cfg(priv)->bt_params &&
  673. cfg(priv)->bt_params->advanced_bt_coexist) {
  674. /* Configure Bluetooth device coexistence support */
  675. if (cfg(priv)->bt_params->bt_sco_disable)
  676. priv->bt_enable_pspoll = false;
  677. else
  678. priv->bt_enable_pspoll = true;
  679. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  680. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  681. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  682. iwlagn_send_advance_bt_config(priv);
  683. priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS;
  684. priv->cur_rssi_ctx = NULL;
  685. iwl_send_prio_tbl(priv);
  686. /* FIXME: w/a to force change uCode BT state machine */
  687. ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
  688. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  689. if (ret)
  690. return ret;
  691. ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
  692. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  693. if (ret)
  694. return ret;
  695. } else {
  696. /*
  697. * default is 2-wire BT coexexistence support
  698. */
  699. iwl_send_bt_config(priv);
  700. }
  701. /*
  702. * Perform runtime calibrations, including DC calibration.
  703. */
  704. iwlagn_send_calib_cfg_rt(priv, IWL_CALIB_CFG_DC_IDX);
  705. ieee80211_wake_queues(priv->hw);
  706. /* Configure Tx antenna selection based on H/W config */
  707. iwlagn_send_tx_ant_config(priv, priv->hw_params.valid_tx_ant);
  708. if (iwl_is_associated_ctx(ctx) && !priv->wowlan) {
  709. struct iwl_rxon_cmd *active_rxon =
  710. (struct iwl_rxon_cmd *)&ctx->active;
  711. /* apply any changes in staging */
  712. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  713. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  714. } else {
  715. struct iwl_rxon_context *tmp;
  716. /* Initialize our rx_config data */
  717. for_each_context(priv, tmp)
  718. iwl_connection_init_rx_config(priv, tmp);
  719. iwlagn_set_rxon_chain(priv, ctx);
  720. }
  721. if (!priv->wowlan) {
  722. /* WoWLAN ucode will not reply in the same way, skip it */
  723. iwl_reset_run_time_calib(priv);
  724. }
  725. set_bit(STATUS_READY, &priv->status);
  726. /* Configure the adapter for unassociated operation */
  727. ret = iwlagn_commit_rxon(priv, ctx);
  728. if (ret)
  729. return ret;
  730. /* At this point, the NIC is initialized and operational */
  731. iwl_rf_kill_ct_config(priv);
  732. IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
  733. return iwl_power_update_mode(priv, true);
  734. }
  735. /**
  736. * iwl_clear_driver_stations - clear knowledge of all stations from driver
  737. * @priv: iwl priv struct
  738. *
  739. * This is called during iwl_down() to make sure that in the case
  740. * we're coming there from a hardware restart mac80211 will be
  741. * able to reconfigure stations -- if we're getting there in the
  742. * normal down flow then the stations will already be cleared.
  743. */
  744. static void iwl_clear_driver_stations(struct iwl_priv *priv)
  745. {
  746. struct iwl_rxon_context *ctx;
  747. spin_lock_bh(&priv->sta_lock);
  748. memset(priv->stations, 0, sizeof(priv->stations));
  749. priv->num_stations = 0;
  750. priv->ucode_key_table = 0;
  751. for_each_context(priv, ctx) {
  752. /*
  753. * Remove all key information that is not stored as part
  754. * of station information since mac80211 may not have had
  755. * a chance to remove all the keys. When device is
  756. * reconfigured by mac80211 after an error all keys will
  757. * be reconfigured.
  758. */
  759. memset(ctx->wep_keys, 0, sizeof(ctx->wep_keys));
  760. ctx->key_mapping_keys = 0;
  761. }
  762. spin_unlock_bh(&priv->sta_lock);
  763. }
  764. void iwl_down(struct iwl_priv *priv)
  765. {
  766. int exit_pending;
  767. IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
  768. lockdep_assert_held(&priv->mutex);
  769. iwl_scan_cancel_timeout(priv, 200);
  770. /*
  771. * If active, scanning won't cancel it, so say it expired.
  772. * No race since we hold the mutex here and a new one
  773. * can't come in at this time.
  774. */
  775. ieee80211_remain_on_channel_expired(priv->hw);
  776. exit_pending =
  777. test_and_set_bit(STATUS_EXIT_PENDING, &priv->status);
  778. iwl_clear_ucode_stations(priv, NULL);
  779. iwl_dealloc_bcast_stations(priv);
  780. iwl_clear_driver_stations(priv);
  781. /* reset BT coex data */
  782. priv->bt_status = 0;
  783. priv->cur_rssi_ctx = NULL;
  784. priv->bt_is_sco = 0;
  785. if (cfg(priv)->bt_params)
  786. priv->bt_traffic_load =
  787. cfg(priv)->bt_params->bt_init_traffic_load;
  788. else
  789. priv->bt_traffic_load = 0;
  790. priv->bt_full_concurrent = false;
  791. priv->bt_ci_compliance = 0;
  792. /* Wipe out the EXIT_PENDING status bit if we are not actually
  793. * exiting the module */
  794. if (!exit_pending)
  795. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  796. if (priv->mac80211_registered)
  797. ieee80211_stop_queues(priv->hw);
  798. priv->ucode_loaded = false;
  799. iwl_trans_stop_device(trans(priv));
  800. /* Clear out all status bits but a few that are stable across reset */
  801. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  802. STATUS_RF_KILL_HW |
  803. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  804. STATUS_GEO_CONFIGURED |
  805. test_bit(STATUS_FW_ERROR, &priv->status) <<
  806. STATUS_FW_ERROR |
  807. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  808. STATUS_EXIT_PENDING;
  809. dev_kfree_skb(priv->beacon_skb);
  810. priv->beacon_skb = NULL;
  811. }
  812. /*****************************************************************************
  813. *
  814. * Workqueue callbacks
  815. *
  816. *****************************************************************************/
  817. static void iwl_bg_run_time_calib_work(struct work_struct *work)
  818. {
  819. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  820. run_time_calib_work);
  821. mutex_lock(&priv->mutex);
  822. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  823. test_bit(STATUS_SCANNING, &priv->status)) {
  824. mutex_unlock(&priv->mutex);
  825. return;
  826. }
  827. if (priv->start_calib) {
  828. iwl_chain_noise_calibration(priv);
  829. iwl_sensitivity_calibration(priv);
  830. }
  831. mutex_unlock(&priv->mutex);
  832. }
  833. void iwlagn_prepare_restart(struct iwl_priv *priv)
  834. {
  835. struct iwl_rxon_context *ctx;
  836. bool bt_full_concurrent;
  837. u8 bt_ci_compliance;
  838. u8 bt_load;
  839. u8 bt_status;
  840. bool bt_is_sco;
  841. int i;
  842. lockdep_assert_held(&priv->mutex);
  843. for_each_context(priv, ctx)
  844. ctx->vif = NULL;
  845. priv->is_open = 0;
  846. /*
  847. * __iwl_down() will clear the BT status variables,
  848. * which is correct, but when we restart we really
  849. * want to keep them so restore them afterwards.
  850. *
  851. * The restart process will later pick them up and
  852. * re-configure the hw when we reconfigure the BT
  853. * command.
  854. */
  855. bt_full_concurrent = priv->bt_full_concurrent;
  856. bt_ci_compliance = priv->bt_ci_compliance;
  857. bt_load = priv->bt_traffic_load;
  858. bt_status = priv->bt_status;
  859. bt_is_sco = priv->bt_is_sco;
  860. iwl_down(priv);
  861. priv->bt_full_concurrent = bt_full_concurrent;
  862. priv->bt_ci_compliance = bt_ci_compliance;
  863. priv->bt_traffic_load = bt_load;
  864. priv->bt_status = bt_status;
  865. priv->bt_is_sco = bt_is_sco;
  866. /* reset all queues */
  867. for (i = 0; i < IEEE80211_NUM_ACS; i++)
  868. atomic_set(&priv->ac_stop_count[i], 0);
  869. for (i = IWLAGN_FIRST_AMPDU_QUEUE; i < IWL_MAX_HW_QUEUES; i++)
  870. priv->queue_to_ac[i] = IWL_INVALID_AC;
  871. memset(priv->agg_q_alloc, 0, sizeof(priv->agg_q_alloc));
  872. }
  873. static void iwl_bg_restart(struct work_struct *data)
  874. {
  875. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  876. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  877. return;
  878. if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
  879. mutex_lock(&priv->mutex);
  880. iwlagn_prepare_restart(priv);
  881. mutex_unlock(&priv->mutex);
  882. iwl_cancel_deferred_work(priv);
  883. ieee80211_restart_hw(priv->hw);
  884. } else {
  885. WARN_ON(1);
  886. }
  887. }
  888. void iwlagn_disable_roc(struct iwl_priv *priv)
  889. {
  890. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
  891. lockdep_assert_held(&priv->mutex);
  892. if (!priv->hw_roc_setup)
  893. return;
  894. ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
  895. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  896. priv->hw_roc_channel = NULL;
  897. memset(ctx->staging.node_addr, 0, ETH_ALEN);
  898. iwlagn_commit_rxon(priv, ctx);
  899. ctx->is_active = false;
  900. priv->hw_roc_setup = false;
  901. }
  902. static void iwlagn_disable_roc_work(struct work_struct *work)
  903. {
  904. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  905. hw_roc_disable_work.work);
  906. mutex_lock(&priv->mutex);
  907. iwlagn_disable_roc(priv);
  908. mutex_unlock(&priv->mutex);
  909. }
  910. /*****************************************************************************
  911. *
  912. * driver setup and teardown
  913. *
  914. *****************************************************************************/
  915. static void iwl_setup_deferred_work(struct iwl_priv *priv)
  916. {
  917. priv->workqueue = create_singlethread_workqueue(DRV_NAME);
  918. INIT_WORK(&priv->restart, iwl_bg_restart);
  919. INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
  920. INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
  921. INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
  922. INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
  923. INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
  924. INIT_DELAYED_WORK(&priv->hw_roc_disable_work,
  925. iwlagn_disable_roc_work);
  926. iwl_setup_scan_deferred_work(priv);
  927. if (cfg(priv)->bt_params)
  928. iwlagn_bt_setup_deferred_work(priv);
  929. init_timer(&priv->statistics_periodic);
  930. priv->statistics_periodic.data = (unsigned long)priv;
  931. priv->statistics_periodic.function = iwl_bg_statistics_periodic;
  932. init_timer(&priv->ucode_trace);
  933. priv->ucode_trace.data = (unsigned long)priv;
  934. priv->ucode_trace.function = iwl_bg_ucode_trace;
  935. }
  936. void iwl_cancel_deferred_work(struct iwl_priv *priv)
  937. {
  938. if (cfg(priv)->bt_params)
  939. iwlagn_bt_cancel_deferred_work(priv);
  940. cancel_work_sync(&priv->run_time_calib_work);
  941. cancel_work_sync(&priv->beacon_update);
  942. iwl_cancel_scan_deferred_work(priv);
  943. cancel_work_sync(&priv->bt_full_concurrency);
  944. cancel_work_sync(&priv->bt_runtime_config);
  945. cancel_delayed_work_sync(&priv->hw_roc_disable_work);
  946. del_timer_sync(&priv->statistics_periodic);
  947. del_timer_sync(&priv->ucode_trace);
  948. }
  949. static void iwl_init_hw_rates(struct ieee80211_rate *rates)
  950. {
  951. int i;
  952. for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
  953. rates[i].bitrate = iwl_rates[i].ieee * 5;
  954. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  955. rates[i].hw_value_short = i;
  956. rates[i].flags = 0;
  957. if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
  958. /*
  959. * If CCK != 1M then set short preamble rate flag.
  960. */
  961. rates[i].flags |=
  962. (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
  963. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  964. }
  965. }
  966. }
  967. #define MAX_BIT_RATE_40_MHZ 150 /* Mbps */
  968. #define MAX_BIT_RATE_20_MHZ 72 /* Mbps */
  969. static void iwl_init_ht_hw_capab(const struct iwl_priv *priv,
  970. struct ieee80211_sta_ht_cap *ht_info,
  971. enum ieee80211_band band)
  972. {
  973. u16 max_bit_rate = 0;
  974. u8 rx_chains_num = priv->hw_params.rx_chains_num;
  975. u8 tx_chains_num = priv->hw_params.tx_chains_num;
  976. ht_info->cap = 0;
  977. memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
  978. ht_info->ht_supported = true;
  979. if (cfg(priv)->ht_params &&
  980. cfg(priv)->ht_params->ht_greenfield_support)
  981. ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
  982. ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
  983. max_bit_rate = MAX_BIT_RATE_20_MHZ;
  984. if (priv->hw_params.ht40_channel & BIT(band)) {
  985. ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  986. ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
  987. ht_info->mcs.rx_mask[4] = 0x01;
  988. max_bit_rate = MAX_BIT_RATE_40_MHZ;
  989. }
  990. if (iwlagn_mod_params.amsdu_size_8K)
  991. ht_info->cap |= IEEE80211_HT_CAP_MAX_AMSDU;
  992. ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
  993. ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
  994. ht_info->mcs.rx_mask[0] = 0xFF;
  995. if (rx_chains_num >= 2)
  996. ht_info->mcs.rx_mask[1] = 0xFF;
  997. if (rx_chains_num >= 3)
  998. ht_info->mcs.rx_mask[2] = 0xFF;
  999. /* Highest supported Rx data rate */
  1000. max_bit_rate *= rx_chains_num;
  1001. WARN_ON(max_bit_rate & ~IEEE80211_HT_MCS_RX_HIGHEST_MASK);
  1002. ht_info->mcs.rx_highest = cpu_to_le16(max_bit_rate);
  1003. /* Tx MCS capabilities */
  1004. ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  1005. if (tx_chains_num != rx_chains_num) {
  1006. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
  1007. ht_info->mcs.tx_params |= ((tx_chains_num - 1) <<
  1008. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
  1009. }
  1010. }
  1011. /**
  1012. * iwl_init_geos - Initialize mac80211's geo/channel info based from eeprom
  1013. */
  1014. static int iwl_init_geos(struct iwl_priv *priv)
  1015. {
  1016. struct iwl_channel_info *ch;
  1017. struct ieee80211_supported_band *sband;
  1018. struct ieee80211_channel *channels;
  1019. struct ieee80211_channel *geo_ch;
  1020. struct ieee80211_rate *rates;
  1021. int i = 0;
  1022. s8 max_tx_power = IWLAGN_TX_POWER_TARGET_POWER_MIN;
  1023. if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
  1024. priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
  1025. IWL_DEBUG_INFO(priv, "Geography modes already initialized.\n");
  1026. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  1027. return 0;
  1028. }
  1029. channels = kcalloc(priv->channel_count,
  1030. sizeof(struct ieee80211_channel), GFP_KERNEL);
  1031. if (!channels)
  1032. return -ENOMEM;
  1033. rates = kcalloc(IWL_RATE_COUNT_LEGACY, sizeof(struct ieee80211_rate),
  1034. GFP_KERNEL);
  1035. if (!rates) {
  1036. kfree(channels);
  1037. return -ENOMEM;
  1038. }
  1039. /* 5.2GHz channels start after the 2.4GHz channels */
  1040. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  1041. sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
  1042. /* just OFDM */
  1043. sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
  1044. sband->n_bitrates = IWL_RATE_COUNT_LEGACY - IWL_FIRST_OFDM_RATE;
  1045. if (priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE)
  1046. iwl_init_ht_hw_capab(priv, &sband->ht_cap,
  1047. IEEE80211_BAND_5GHZ);
  1048. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  1049. sband->channels = channels;
  1050. /* OFDM & CCK */
  1051. sband->bitrates = rates;
  1052. sband->n_bitrates = IWL_RATE_COUNT_LEGACY;
  1053. if (priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE)
  1054. iwl_init_ht_hw_capab(priv, &sband->ht_cap,
  1055. IEEE80211_BAND_2GHZ);
  1056. priv->ieee_channels = channels;
  1057. priv->ieee_rates = rates;
  1058. for (i = 0; i < priv->channel_count; i++) {
  1059. ch = &priv->channel_info[i];
  1060. /* FIXME: might be removed if scan is OK */
  1061. if (!is_channel_valid(ch))
  1062. continue;
  1063. sband = &priv->bands[ch->band];
  1064. geo_ch = &sband->channels[sband->n_channels++];
  1065. geo_ch->center_freq =
  1066. ieee80211_channel_to_frequency(ch->channel, ch->band);
  1067. geo_ch->max_power = ch->max_power_avg;
  1068. geo_ch->max_antenna_gain = 0xff;
  1069. geo_ch->hw_value = ch->channel;
  1070. if (is_channel_valid(ch)) {
  1071. if (!(ch->flags & EEPROM_CHANNEL_IBSS))
  1072. geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
  1073. if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
  1074. geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
  1075. if (ch->flags & EEPROM_CHANNEL_RADAR)
  1076. geo_ch->flags |= IEEE80211_CHAN_RADAR;
  1077. geo_ch->flags |= ch->ht40_extension_channel;
  1078. if (ch->max_power_avg > max_tx_power)
  1079. max_tx_power = ch->max_power_avg;
  1080. } else {
  1081. geo_ch->flags |= IEEE80211_CHAN_DISABLED;
  1082. }
  1083. IWL_DEBUG_INFO(priv, "Channel %d Freq=%d[%sGHz] %s flag=0x%X\n",
  1084. ch->channel, geo_ch->center_freq,
  1085. is_channel_a_band(ch) ? "5.2" : "2.4",
  1086. geo_ch->flags & IEEE80211_CHAN_DISABLED ?
  1087. "restricted" : "valid",
  1088. geo_ch->flags);
  1089. }
  1090. priv->tx_power_device_lmt = max_tx_power;
  1091. priv->tx_power_user_lmt = max_tx_power;
  1092. priv->tx_power_next = max_tx_power;
  1093. if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
  1094. priv->hw_params.sku & EEPROM_SKU_CAP_BAND_52GHZ) {
  1095. IWL_INFO(priv, "Incorrectly detected BG card as ABG. "
  1096. "Please send your %s to maintainer.\n",
  1097. trans(priv)->hw_id_str);
  1098. priv->hw_params.sku &= ~EEPROM_SKU_CAP_BAND_52GHZ;
  1099. }
  1100. IWL_INFO(priv, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
  1101. priv->bands[IEEE80211_BAND_2GHZ].n_channels,
  1102. priv->bands[IEEE80211_BAND_5GHZ].n_channels);
  1103. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  1104. return 0;
  1105. }
  1106. /*
  1107. * iwl_free_geos - undo allocations in iwl_init_geos
  1108. */
  1109. static void iwl_free_geos(struct iwl_priv *priv)
  1110. {
  1111. kfree(priv->ieee_channels);
  1112. kfree(priv->ieee_rates);
  1113. clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
  1114. }
  1115. static int iwl_init_drv(struct iwl_priv *priv)
  1116. {
  1117. int ret;
  1118. spin_lock_init(&priv->sta_lock);
  1119. mutex_init(&priv->mutex);
  1120. INIT_LIST_HEAD(&priv->calib_results);
  1121. priv->ieee_channels = NULL;
  1122. priv->ieee_rates = NULL;
  1123. priv->band = IEEE80211_BAND_2GHZ;
  1124. priv->plcp_delta_threshold =
  1125. cfg(priv)->base_params->plcp_delta_threshold;
  1126. priv->iw_mode = NL80211_IFTYPE_STATION;
  1127. priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
  1128. priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
  1129. priv->agg_tids_count = 0;
  1130. priv->ucode_owner = IWL_OWNERSHIP_DRIVER;
  1131. priv->rx_statistics_jiffies = jiffies;
  1132. /* Choose which receivers/antennas to use */
  1133. iwlagn_set_rxon_chain(priv, &priv->contexts[IWL_RXON_CTX_BSS]);
  1134. iwl_init_scan_params(priv);
  1135. /* init bt coex */
  1136. if (cfg(priv)->bt_params &&
  1137. cfg(priv)->bt_params->advanced_bt_coexist) {
  1138. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  1139. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  1140. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  1141. priv->bt_on_thresh = BT_ON_THRESHOLD_DEF;
  1142. priv->bt_duration = BT_DURATION_LIMIT_DEF;
  1143. priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
  1144. }
  1145. ret = iwl_init_channel_map(priv);
  1146. if (ret) {
  1147. IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
  1148. goto err;
  1149. }
  1150. ret = iwl_init_geos(priv);
  1151. if (ret) {
  1152. IWL_ERR(priv, "initializing geos failed: %d\n", ret);
  1153. goto err_free_channel_map;
  1154. }
  1155. iwl_init_hw_rates(priv->ieee_rates);
  1156. return 0;
  1157. err_free_channel_map:
  1158. iwl_free_channel_map(priv);
  1159. err:
  1160. return ret;
  1161. }
  1162. static void iwl_uninit_drv(struct iwl_priv *priv)
  1163. {
  1164. iwl_free_geos(priv);
  1165. iwl_free_channel_map(priv);
  1166. kfree(priv->scan_cmd);
  1167. kfree(priv->beacon_cmd);
  1168. kfree(rcu_dereference_raw(priv->noa_data));
  1169. iwl_calib_free_results(priv);
  1170. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1171. kfree(priv->wowlan_sram);
  1172. #endif
  1173. }
  1174. static void iwl_set_hw_params(struct iwl_priv *priv)
  1175. {
  1176. if (cfg(priv)->ht_params)
  1177. priv->hw_params.use_rts_for_aggregation =
  1178. cfg(priv)->ht_params->use_rts_for_aggregation;
  1179. if (iwlagn_mod_params.disable_11n & IWL_DISABLE_HT_ALL)
  1180. priv->hw_params.sku &= ~EEPROM_SKU_CAP_11N_ENABLE;
  1181. /* Device-specific setup */
  1182. priv->lib->set_hw_params(priv);
  1183. }
  1184. static void iwl_debug_config(struct iwl_priv *priv)
  1185. {
  1186. dev_printk(KERN_INFO, trans(priv)->dev, "CONFIG_IWLWIFI_DEBUG "
  1187. #ifdef CONFIG_IWLWIFI_DEBUG
  1188. "enabled\n");
  1189. #else
  1190. "disabled\n");
  1191. #endif
  1192. dev_printk(KERN_INFO, trans(priv)->dev, "CONFIG_IWLWIFI_DEBUGFS "
  1193. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1194. "enabled\n");
  1195. #else
  1196. "disabled\n");
  1197. #endif
  1198. dev_printk(KERN_INFO, trans(priv)->dev, "CONFIG_IWLWIFI_DEVICE_TRACING "
  1199. #ifdef CONFIG_IWLWIFI_DEVICE_TRACING
  1200. "enabled\n");
  1201. #else
  1202. "disabled\n");
  1203. #endif
  1204. dev_printk(KERN_INFO, trans(priv)->dev, "CONFIG_IWLWIFI_DEVICE_TESTMODE "
  1205. #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
  1206. "enabled\n");
  1207. #else
  1208. "disabled\n");
  1209. #endif
  1210. dev_printk(KERN_INFO, trans(priv)->dev, "CONFIG_IWLWIFI_P2P "
  1211. #ifdef CONFIG_IWLWIFI_P2P
  1212. "enabled\n");
  1213. #else
  1214. "disabled\n");
  1215. #endif
  1216. }
  1217. static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
  1218. const struct iwl_fw *fw)
  1219. {
  1220. struct iwl_priv *priv;
  1221. struct ieee80211_hw *hw;
  1222. struct iwl_op_mode *op_mode;
  1223. u16 num_mac;
  1224. u32 ucode_flags;
  1225. struct iwl_trans_config trans_cfg;
  1226. static const u8 no_reclaim_cmds[] = {
  1227. REPLY_RX_PHY_CMD,
  1228. REPLY_RX,
  1229. REPLY_RX_MPDU_CMD,
  1230. REPLY_COMPRESSED_BA,
  1231. STATISTICS_NOTIFICATION,
  1232. REPLY_TX,
  1233. };
  1234. const u8 *q_to_ac;
  1235. int n_q_to_ac;
  1236. int i;
  1237. /************************
  1238. * 1. Allocating HW data
  1239. ************************/
  1240. hw = iwl_alloc_all();
  1241. if (!hw) {
  1242. pr_err("%s: Cannot allocate network device\n",
  1243. cfg(trans)->name);
  1244. goto out;
  1245. }
  1246. op_mode = hw->priv;
  1247. op_mode->ops = &iwl_dvm_ops;
  1248. priv = IWL_OP_MODE_GET_DVM(op_mode);
  1249. priv->shrd = trans->shrd;
  1250. priv->fw = fw;
  1251. switch (cfg(priv)->device_family) {
  1252. case IWL_DEVICE_FAMILY_1000:
  1253. case IWL_DEVICE_FAMILY_100:
  1254. priv->lib = &iwl1000_lib;
  1255. break;
  1256. case IWL_DEVICE_FAMILY_2000:
  1257. case IWL_DEVICE_FAMILY_105:
  1258. priv->lib = &iwl2000_lib;
  1259. break;
  1260. case IWL_DEVICE_FAMILY_2030:
  1261. case IWL_DEVICE_FAMILY_135:
  1262. priv->lib = &iwl2030_lib;
  1263. break;
  1264. case IWL_DEVICE_FAMILY_5000:
  1265. priv->lib = &iwl5000_lib;
  1266. break;
  1267. case IWL_DEVICE_FAMILY_5150:
  1268. priv->lib = &iwl5150_lib;
  1269. break;
  1270. case IWL_DEVICE_FAMILY_6000:
  1271. case IWL_DEVICE_FAMILY_6005:
  1272. case IWL_DEVICE_FAMILY_6000i:
  1273. case IWL_DEVICE_FAMILY_6050:
  1274. case IWL_DEVICE_FAMILY_6150:
  1275. priv->lib = &iwl6000_lib;
  1276. break;
  1277. case IWL_DEVICE_FAMILY_6030:
  1278. priv->lib = &iwl6030_lib;
  1279. break;
  1280. default:
  1281. break;
  1282. }
  1283. if (WARN_ON(!priv->lib))
  1284. goto out_free_traffic_mem;
  1285. /*
  1286. * Populate the state variables that the transport layer needs
  1287. * to know about.
  1288. */
  1289. trans_cfg.op_mode = op_mode;
  1290. trans_cfg.no_reclaim_cmds = no_reclaim_cmds;
  1291. trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
  1292. trans_cfg.rx_buf_size_8k = iwlagn_mod_params.amsdu_size_8K;
  1293. if (!iwlagn_mod_params.wd_disable)
  1294. trans_cfg.queue_watchdog_timeout =
  1295. cfg(priv)->base_params->wd_timeout;
  1296. else
  1297. trans_cfg.queue_watchdog_timeout = IWL_WATCHHDOG_DISABLED;
  1298. ucode_flags = fw->ucode_capa.flags;
  1299. #ifndef CONFIG_IWLWIFI_P2P
  1300. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_P2P;
  1301. #endif
  1302. if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN) {
  1303. priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
  1304. trans_cfg.cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
  1305. trans_cfg.queue_to_fifo = iwlagn_ipan_queue_to_tx_fifo;
  1306. trans_cfg.n_queue_to_fifo =
  1307. ARRAY_SIZE(iwlagn_ipan_queue_to_tx_fifo);
  1308. q_to_ac = iwlagn_pan_queue_to_ac;
  1309. n_q_to_ac = ARRAY_SIZE(iwlagn_pan_queue_to_ac);
  1310. } else {
  1311. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  1312. trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  1313. trans_cfg.queue_to_fifo = iwlagn_default_queue_to_tx_fifo;
  1314. trans_cfg.n_queue_to_fifo =
  1315. ARRAY_SIZE(iwlagn_default_queue_to_tx_fifo);
  1316. q_to_ac = iwlagn_bss_queue_to_ac;
  1317. n_q_to_ac = ARRAY_SIZE(iwlagn_bss_queue_to_ac);
  1318. }
  1319. /* Configure transport layer */
  1320. iwl_trans_configure(trans(priv), &trans_cfg);
  1321. /* At this point both hw and priv are allocated. */
  1322. SET_IEEE80211_DEV(priv->hw, trans(priv)->dev);
  1323. /* show what debugging capabilities we have */
  1324. iwl_debug_config(priv);
  1325. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  1326. /* is antenna coupling more than 35dB ? */
  1327. priv->bt_ant_couple_ok =
  1328. (iwlagn_mod_params.ant_coupling >
  1329. IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
  1330. true : false;
  1331. /* enable/disable bt channel inhibition */
  1332. priv->bt_ch_announce = iwlagn_mod_params.bt_ch_announce;
  1333. IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n",
  1334. (priv->bt_ch_announce) ? "On" : "Off");
  1335. if (iwl_alloc_traffic_mem(priv))
  1336. IWL_ERR(priv, "Not enough memory to generate traffic log\n");
  1337. /* these spin locks will be used in apm_ops.init and EEPROM access
  1338. * we should init now
  1339. */
  1340. spin_lock_init(&trans(priv)->reg_lock);
  1341. spin_lock_init(&priv->statistics.lock);
  1342. /***********************
  1343. * 2. Read REV register
  1344. ***********************/
  1345. IWL_INFO(priv, "Detected %s, REV=0x%X\n",
  1346. cfg(priv)->name, trans(priv)->hw_rev);
  1347. if (iwl_trans_start_hw(trans(priv)))
  1348. goto out_free_traffic_mem;
  1349. /* Read the EEPROM */
  1350. if (iwl_eeprom_init(priv, trans(priv)->hw_rev)) {
  1351. IWL_ERR(priv, "Unable to init EEPROM\n");
  1352. goto out_free_traffic_mem;
  1353. }
  1354. /* Reset chip to save power until we load uCode during "up". */
  1355. iwl_trans_stop_hw(trans(priv));
  1356. if (iwl_eeprom_check_version(priv))
  1357. goto out_free_eeprom;
  1358. if (iwl_eeprom_init_hw_params(priv))
  1359. goto out_free_eeprom;
  1360. /* extract MAC Address */
  1361. iwl_eeprom_get_mac(priv, priv->addresses[0].addr);
  1362. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
  1363. priv->hw->wiphy->addresses = priv->addresses;
  1364. priv->hw->wiphy->n_addresses = 1;
  1365. num_mac = iwl_eeprom_query16(priv, EEPROM_NUM_MAC_ADDRESS);
  1366. if (num_mac > 1) {
  1367. memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
  1368. ETH_ALEN);
  1369. priv->addresses[1].addr[5]++;
  1370. priv->hw->wiphy->n_addresses++;
  1371. }
  1372. /************************
  1373. * 4. Setup HW constants
  1374. ************************/
  1375. iwl_set_hw_params(priv);
  1376. if (!(priv->hw_params.sku & EEPROM_SKU_CAP_IPAN_ENABLE)) {
  1377. IWL_DEBUG_INFO(priv, "Your EEPROM disabled PAN");
  1378. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
  1379. /*
  1380. * if not PAN, then don't support P2P -- might be a uCode
  1381. * packaging bug or due to the eeprom check above
  1382. */
  1383. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_P2P;
  1384. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  1385. trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  1386. trans_cfg.queue_to_fifo = iwlagn_default_queue_to_tx_fifo;
  1387. trans_cfg.n_queue_to_fifo =
  1388. ARRAY_SIZE(iwlagn_default_queue_to_tx_fifo);
  1389. q_to_ac = iwlagn_bss_queue_to_ac;
  1390. n_q_to_ac = ARRAY_SIZE(iwlagn_bss_queue_to_ac);
  1391. /* Configure transport layer again*/
  1392. iwl_trans_configure(trans(priv), &trans_cfg);
  1393. }
  1394. /*******************
  1395. * 5. Setup priv
  1396. *******************/
  1397. for (i = 0; i < IEEE80211_NUM_ACS; i++)
  1398. atomic_set(&priv->ac_stop_count[i], 0);
  1399. for (i = 0; i < IWL_MAX_HW_QUEUES; i++) {
  1400. if (i < n_q_to_ac)
  1401. priv->queue_to_ac[i] = q_to_ac[i];
  1402. else
  1403. priv->queue_to_ac[i] = IWL_INVALID_AC;
  1404. }
  1405. WARN_ON(trans_cfg.queue_to_fifo[trans_cfg.cmd_queue] !=
  1406. IWLAGN_CMD_FIFO_NUM);
  1407. if (iwl_init_drv(priv))
  1408. goto out_free_eeprom;
  1409. /* At this point both hw and priv are initialized. */
  1410. /********************
  1411. * 6. Setup services
  1412. ********************/
  1413. iwl_setup_deferred_work(priv);
  1414. iwl_setup_rx_handlers(priv);
  1415. iwl_testmode_init(priv);
  1416. iwl_power_initialize(priv);
  1417. iwl_tt_initialize(priv);
  1418. snprintf(priv->hw->wiphy->fw_version,
  1419. sizeof(priv->hw->wiphy->fw_version),
  1420. "%s", fw->fw_version);
  1421. priv->new_scan_threshold_behaviour =
  1422. !!(ucode_flags & IWL_UCODE_TLV_FLAGS_NEWSCAN);
  1423. priv->phy_calib_chain_noise_reset_cmd =
  1424. fw->ucode_capa.standard_phy_calibration_size;
  1425. priv->phy_calib_chain_noise_gain_cmd =
  1426. fw->ucode_capa.standard_phy_calibration_size + 1;
  1427. /* initialize all valid contexts */
  1428. iwl_init_context(priv, ucode_flags);
  1429. /**************************************************
  1430. * This is still part of probe() in a sense...
  1431. *
  1432. * 7. Setup and register with mac80211 and debugfs
  1433. **************************************************/
  1434. if (iwlagn_mac_setup_register(priv, &fw->ucode_capa))
  1435. goto out_destroy_workqueue;
  1436. if (iwl_dbgfs_register(priv, DRV_NAME))
  1437. IWL_ERR(priv,
  1438. "failed to create debugfs files. Ignoring error\n");
  1439. return op_mode;
  1440. out_destroy_workqueue:
  1441. destroy_workqueue(priv->workqueue);
  1442. priv->workqueue = NULL;
  1443. iwl_uninit_drv(priv);
  1444. out_free_eeprom:
  1445. iwl_eeprom_free(priv);
  1446. out_free_traffic_mem:
  1447. iwl_free_traffic_mem(priv);
  1448. ieee80211_free_hw(priv->hw);
  1449. out:
  1450. op_mode = NULL;
  1451. return op_mode;
  1452. }
  1453. static void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode)
  1454. {
  1455. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1456. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  1457. iwl_dbgfs_unregister(priv);
  1458. iwl_testmode_cleanup(priv);
  1459. iwlagn_mac_unregister(priv);
  1460. iwl_tt_exit(priv);
  1461. /*This will stop the queues, move the device to low power state */
  1462. priv->ucode_loaded = false;
  1463. iwl_trans_stop_device(trans(priv));
  1464. iwl_eeprom_free(priv);
  1465. /*netif_stop_queue(dev); */
  1466. flush_workqueue(priv->workqueue);
  1467. /* ieee80211_unregister_hw calls iwlagn_mac_stop, which flushes
  1468. * priv->workqueue... so we can't take down the workqueue
  1469. * until now... */
  1470. destroy_workqueue(priv->workqueue);
  1471. priv->workqueue = NULL;
  1472. iwl_free_traffic_mem(priv);
  1473. iwl_uninit_drv(priv);
  1474. dev_kfree_skb(priv->beacon_skb);
  1475. ieee80211_free_hw(priv->hw);
  1476. }
  1477. static const char * const desc_lookup_text[] = {
  1478. "OK",
  1479. "FAIL",
  1480. "BAD_PARAM",
  1481. "BAD_CHECKSUM",
  1482. "NMI_INTERRUPT_WDG",
  1483. "SYSASSERT",
  1484. "FATAL_ERROR",
  1485. "BAD_COMMAND",
  1486. "HW_ERROR_TUNE_LOCK",
  1487. "HW_ERROR_TEMPERATURE",
  1488. "ILLEGAL_CHAN_FREQ",
  1489. "VCC_NOT_STABLE",
  1490. "FH_ERROR",
  1491. "NMI_INTERRUPT_HOST",
  1492. "NMI_INTERRUPT_ACTION_PT",
  1493. "NMI_INTERRUPT_UNKNOWN",
  1494. "UCODE_VERSION_MISMATCH",
  1495. "HW_ERROR_ABS_LOCK",
  1496. "HW_ERROR_CAL_LOCK_FAIL",
  1497. "NMI_INTERRUPT_INST_ACTION_PT",
  1498. "NMI_INTERRUPT_DATA_ACTION_PT",
  1499. "NMI_TRM_HW_ER",
  1500. "NMI_INTERRUPT_TRM",
  1501. "NMI_INTERRUPT_BREAK_POINT",
  1502. "DEBUG_0",
  1503. "DEBUG_1",
  1504. "DEBUG_2",
  1505. "DEBUG_3",
  1506. };
  1507. static struct { char *name; u8 num; } advanced_lookup[] = {
  1508. { "NMI_INTERRUPT_WDG", 0x34 },
  1509. { "SYSASSERT", 0x35 },
  1510. { "UCODE_VERSION_MISMATCH", 0x37 },
  1511. { "BAD_COMMAND", 0x38 },
  1512. { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
  1513. { "FATAL_ERROR", 0x3D },
  1514. { "NMI_TRM_HW_ERR", 0x46 },
  1515. { "NMI_INTERRUPT_TRM", 0x4C },
  1516. { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
  1517. { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
  1518. { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
  1519. { "NMI_INTERRUPT_HOST", 0x66 },
  1520. { "NMI_INTERRUPT_ACTION_PT", 0x7C },
  1521. { "NMI_INTERRUPT_UNKNOWN", 0x84 },
  1522. { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
  1523. { "ADVANCED_SYSASSERT", 0 },
  1524. };
  1525. static const char *desc_lookup(u32 num)
  1526. {
  1527. int i;
  1528. int max = ARRAY_SIZE(desc_lookup_text);
  1529. if (num < max)
  1530. return desc_lookup_text[num];
  1531. max = ARRAY_SIZE(advanced_lookup) - 1;
  1532. for (i = 0; i < max; i++) {
  1533. if (advanced_lookup[i].num == num)
  1534. break;
  1535. }
  1536. return advanced_lookup[i].name;
  1537. }
  1538. #define ERROR_START_OFFSET (1 * sizeof(u32))
  1539. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  1540. static void iwl_dump_nic_error_log(struct iwl_priv *priv)
  1541. {
  1542. struct iwl_trans *trans = trans(priv);
  1543. u32 base;
  1544. struct iwl_error_event_table table;
  1545. base = priv->device_pointers.error_event_table;
  1546. if (priv->cur_ucode == IWL_UCODE_INIT) {
  1547. if (!base)
  1548. base = priv->fw->init_errlog_ptr;
  1549. } else {
  1550. if (!base)
  1551. base = priv->fw->inst_errlog_ptr;
  1552. }
  1553. if (!iwlagn_hw_valid_rtc_data_addr(base)) {
  1554. IWL_ERR(priv,
  1555. "Not valid error log pointer 0x%08X for %s uCode\n",
  1556. base,
  1557. (priv->cur_ucode == IWL_UCODE_INIT)
  1558. ? "Init" : "RT");
  1559. return;
  1560. }
  1561. /*TODO: Update dbgfs with ISR error stats obtained below */
  1562. iwl_read_targ_mem_words(trans, base, &table, sizeof(table));
  1563. if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
  1564. IWL_ERR(trans, "Start IWL Error Log Dump:\n");
  1565. IWL_ERR(trans, "Status: 0x%08lX, count: %d\n",
  1566. priv->shrd->status, table.valid);
  1567. }
  1568. trace_iwlwifi_dev_ucode_error(trans->dev, table.error_id, table.tsf_low,
  1569. table.data1, table.data2, table.line,
  1570. table.blink1, table.blink2, table.ilink1,
  1571. table.ilink2, table.bcon_time, table.gp1,
  1572. table.gp2, table.gp3, table.ucode_ver,
  1573. table.hw_ver, table.brd_ver);
  1574. IWL_ERR(priv, "0x%08X | %-28s\n", table.error_id,
  1575. desc_lookup(table.error_id));
  1576. IWL_ERR(priv, "0x%08X | uPc\n", table.pc);
  1577. IWL_ERR(priv, "0x%08X | branchlink1\n", table.blink1);
  1578. IWL_ERR(priv, "0x%08X | branchlink2\n", table.blink2);
  1579. IWL_ERR(priv, "0x%08X | interruptlink1\n", table.ilink1);
  1580. IWL_ERR(priv, "0x%08X | interruptlink2\n", table.ilink2);
  1581. IWL_ERR(priv, "0x%08X | data1\n", table.data1);
  1582. IWL_ERR(priv, "0x%08X | data2\n", table.data2);
  1583. IWL_ERR(priv, "0x%08X | line\n", table.line);
  1584. IWL_ERR(priv, "0x%08X | beacon time\n", table.bcon_time);
  1585. IWL_ERR(priv, "0x%08X | tsf low\n", table.tsf_low);
  1586. IWL_ERR(priv, "0x%08X | tsf hi\n", table.tsf_hi);
  1587. IWL_ERR(priv, "0x%08X | time gp1\n", table.gp1);
  1588. IWL_ERR(priv, "0x%08X | time gp2\n", table.gp2);
  1589. IWL_ERR(priv, "0x%08X | time gp3\n", table.gp3);
  1590. IWL_ERR(priv, "0x%08X | uCode version\n", table.ucode_ver);
  1591. IWL_ERR(priv, "0x%08X | hw version\n", table.hw_ver);
  1592. IWL_ERR(priv, "0x%08X | board version\n", table.brd_ver);
  1593. IWL_ERR(priv, "0x%08X | hcmd\n", table.hcmd);
  1594. IWL_ERR(priv, "0x%08X | isr0\n", table.isr0);
  1595. IWL_ERR(priv, "0x%08X | isr1\n", table.isr1);
  1596. IWL_ERR(priv, "0x%08X | isr2\n", table.isr2);
  1597. IWL_ERR(priv, "0x%08X | isr3\n", table.isr3);
  1598. IWL_ERR(priv, "0x%08X | isr4\n", table.isr4);
  1599. IWL_ERR(priv, "0x%08X | isr_pref\n", table.isr_pref);
  1600. IWL_ERR(priv, "0x%08X | wait_event\n", table.wait_event);
  1601. IWL_ERR(priv, "0x%08X | l2p_control\n", table.l2p_control);
  1602. IWL_ERR(priv, "0x%08X | l2p_duration\n", table.l2p_duration);
  1603. IWL_ERR(priv, "0x%08X | l2p_mhvalid\n", table.l2p_mhvalid);
  1604. IWL_ERR(priv, "0x%08X | l2p_addr_match\n", table.l2p_addr_match);
  1605. IWL_ERR(priv, "0x%08X | lmpm_pmg_sel\n", table.lmpm_pmg_sel);
  1606. IWL_ERR(priv, "0x%08X | timestamp\n", table.u_timestamp);
  1607. IWL_ERR(priv, "0x%08X | flow_handler\n", table.flow_handler);
  1608. }
  1609. #define EVENT_START_OFFSET (4 * sizeof(u32))
  1610. /**
  1611. * iwl_print_event_log - Dump error event log to syslog
  1612. *
  1613. */
  1614. static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
  1615. u32 num_events, u32 mode,
  1616. int pos, char **buf, size_t bufsz)
  1617. {
  1618. u32 i;
  1619. u32 base; /* SRAM byte address of event log header */
  1620. u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
  1621. u32 ptr; /* SRAM byte address of log data */
  1622. u32 ev, time, data; /* event log data */
  1623. unsigned long reg_flags;
  1624. struct iwl_trans *trans = trans(priv);
  1625. if (num_events == 0)
  1626. return pos;
  1627. base = priv->device_pointers.log_event_table;
  1628. if (priv->cur_ucode == IWL_UCODE_INIT) {
  1629. if (!base)
  1630. base = priv->fw->init_evtlog_ptr;
  1631. } else {
  1632. if (!base)
  1633. base = priv->fw->inst_evtlog_ptr;
  1634. }
  1635. if (mode == 0)
  1636. event_size = 2 * sizeof(u32);
  1637. else
  1638. event_size = 3 * sizeof(u32);
  1639. ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
  1640. /* Make sure device is powered up for SRAM reads */
  1641. spin_lock_irqsave(&trans->reg_lock, reg_flags);
  1642. if (unlikely(!iwl_grab_nic_access(trans)))
  1643. goto out_unlock;
  1644. /* Set starting address; reads will auto-increment */
  1645. iwl_write32(trans, HBUS_TARG_MEM_RADDR, ptr);
  1646. /* "time" is actually "data" for mode 0 (no timestamp).
  1647. * place event id # at far right for easier visual parsing. */
  1648. for (i = 0; i < num_events; i++) {
  1649. ev = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
  1650. time = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
  1651. if (mode == 0) {
  1652. /* data, ev */
  1653. if (bufsz) {
  1654. pos += scnprintf(*buf + pos, bufsz - pos,
  1655. "EVT_LOG:0x%08x:%04u\n",
  1656. time, ev);
  1657. } else {
  1658. trace_iwlwifi_dev_ucode_event(trans->dev, 0,
  1659. time, ev);
  1660. IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n",
  1661. time, ev);
  1662. }
  1663. } else {
  1664. data = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
  1665. if (bufsz) {
  1666. pos += scnprintf(*buf + pos, bufsz - pos,
  1667. "EVT_LOGT:%010u:0x%08x:%04u\n",
  1668. time, data, ev);
  1669. } else {
  1670. IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
  1671. time, data, ev);
  1672. trace_iwlwifi_dev_ucode_event(trans->dev, time,
  1673. data, ev);
  1674. }
  1675. }
  1676. }
  1677. /* Allow device to power down */
  1678. iwl_release_nic_access(trans);
  1679. out_unlock:
  1680. spin_unlock_irqrestore(&trans->reg_lock, reg_flags);
  1681. return pos;
  1682. }
  1683. /**
  1684. * iwl_print_last_event_logs - Dump the newest # of event log to syslog
  1685. */
  1686. static int iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
  1687. u32 num_wraps, u32 next_entry,
  1688. u32 size, u32 mode,
  1689. int pos, char **buf, size_t bufsz)
  1690. {
  1691. /*
  1692. * display the newest DEFAULT_LOG_ENTRIES entries
  1693. * i.e the entries just before the next ont that uCode would fill.
  1694. */
  1695. if (num_wraps) {
  1696. if (next_entry < size) {
  1697. pos = iwl_print_event_log(priv,
  1698. capacity - (size - next_entry),
  1699. size - next_entry, mode,
  1700. pos, buf, bufsz);
  1701. pos = iwl_print_event_log(priv, 0,
  1702. next_entry, mode,
  1703. pos, buf, bufsz);
  1704. } else
  1705. pos = iwl_print_event_log(priv, next_entry - size,
  1706. size, mode, pos, buf, bufsz);
  1707. } else {
  1708. if (next_entry < size) {
  1709. pos = iwl_print_event_log(priv, 0, next_entry,
  1710. mode, pos, buf, bufsz);
  1711. } else {
  1712. pos = iwl_print_event_log(priv, next_entry - size,
  1713. size, mode, pos, buf, bufsz);
  1714. }
  1715. }
  1716. return pos;
  1717. }
  1718. #define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
  1719. int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
  1720. char **buf, bool display)
  1721. {
  1722. u32 base; /* SRAM byte address of event log header */
  1723. u32 capacity; /* event log capacity in # entries */
  1724. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  1725. u32 num_wraps; /* # times uCode wrapped to top of log */
  1726. u32 next_entry; /* index of next entry to be written by uCode */
  1727. u32 size; /* # entries that we'll print */
  1728. u32 logsize;
  1729. int pos = 0;
  1730. size_t bufsz = 0;
  1731. struct iwl_trans *trans = trans(priv);
  1732. base = priv->device_pointers.log_event_table;
  1733. if (priv->cur_ucode == IWL_UCODE_INIT) {
  1734. logsize = priv->fw->init_evtlog_size;
  1735. if (!base)
  1736. base = priv->fw->init_evtlog_ptr;
  1737. } else {
  1738. logsize = priv->fw->inst_evtlog_size;
  1739. if (!base)
  1740. base = priv->fw->inst_evtlog_ptr;
  1741. }
  1742. if (!iwlagn_hw_valid_rtc_data_addr(base)) {
  1743. IWL_ERR(priv,
  1744. "Invalid event log pointer 0x%08X for %s uCode\n",
  1745. base,
  1746. (priv->cur_ucode == IWL_UCODE_INIT)
  1747. ? "Init" : "RT");
  1748. return -EINVAL;
  1749. }
  1750. /* event log header */
  1751. capacity = iwl_read_targ_mem(trans, base);
  1752. mode = iwl_read_targ_mem(trans, base + (1 * sizeof(u32)));
  1753. num_wraps = iwl_read_targ_mem(trans, base + (2 * sizeof(u32)));
  1754. next_entry = iwl_read_targ_mem(trans, base + (3 * sizeof(u32)));
  1755. if (capacity > logsize) {
  1756. IWL_ERR(priv, "Log capacity %d is bogus, limit to %d "
  1757. "entries\n", capacity, logsize);
  1758. capacity = logsize;
  1759. }
  1760. if (next_entry > logsize) {
  1761. IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
  1762. next_entry, logsize);
  1763. next_entry = logsize;
  1764. }
  1765. size = num_wraps ? capacity : next_entry;
  1766. /* bail out if nothing in log */
  1767. if (size == 0) {
  1768. IWL_ERR(trans, "Start IWL Event Log Dump: nothing in log\n");
  1769. return pos;
  1770. }
  1771. #ifdef CONFIG_IWLWIFI_DEBUG
  1772. if (!(iwl_have_debug_level(IWL_DL_FW_ERRORS)) && !full_log)
  1773. size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
  1774. ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
  1775. #else
  1776. size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
  1777. ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
  1778. #endif
  1779. IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n",
  1780. size);
  1781. #ifdef CONFIG_IWLWIFI_DEBUG
  1782. if (display) {
  1783. if (full_log)
  1784. bufsz = capacity * 48;
  1785. else
  1786. bufsz = size * 48;
  1787. *buf = kmalloc(bufsz, GFP_KERNEL);
  1788. if (!*buf)
  1789. return -ENOMEM;
  1790. }
  1791. if (iwl_have_debug_level(IWL_DL_FW_ERRORS) || full_log) {
  1792. /*
  1793. * if uCode has wrapped back to top of log,
  1794. * start at the oldest entry,
  1795. * i.e the next one that uCode would fill.
  1796. */
  1797. if (num_wraps)
  1798. pos = iwl_print_event_log(priv, next_entry,
  1799. capacity - next_entry, mode,
  1800. pos, buf, bufsz);
  1801. /* (then/else) start at top of log */
  1802. pos = iwl_print_event_log(priv, 0,
  1803. next_entry, mode, pos, buf, bufsz);
  1804. } else
  1805. pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
  1806. next_entry, size, mode,
  1807. pos, buf, bufsz);
  1808. #else
  1809. pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
  1810. next_entry, size, mode,
  1811. pos, buf, bufsz);
  1812. #endif
  1813. return pos;
  1814. }
  1815. static void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand)
  1816. {
  1817. unsigned int reload_msec;
  1818. unsigned long reload_jiffies;
  1819. #ifdef CONFIG_IWLWIFI_DEBUG
  1820. if (iwl_have_debug_level(IWL_DL_FW_ERRORS))
  1821. iwl_print_rx_config_cmd(priv, IWL_RXON_CTX_BSS);
  1822. #endif
  1823. /* uCode is no longer loaded. */
  1824. priv->ucode_loaded = false;
  1825. /* Set the FW error flag -- cleared on iwl_down */
  1826. set_bit(STATUS_FW_ERROR, &priv->status);
  1827. /* Cancel currently queued command. */
  1828. clear_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status);
  1829. iwl_abort_notification_waits(&priv->notif_wait);
  1830. /* Keep the restart process from trying to send host
  1831. * commands by clearing the ready bit */
  1832. clear_bit(STATUS_READY, &priv->status);
  1833. wake_up(&trans(priv)->wait_command_queue);
  1834. if (!ondemand) {
  1835. /*
  1836. * If firmware keep reloading, then it indicate something
  1837. * serious wrong and firmware having problem to recover
  1838. * from it. Instead of keep trying which will fill the syslog
  1839. * and hang the system, let's just stop it
  1840. */
  1841. reload_jiffies = jiffies;
  1842. reload_msec = jiffies_to_msecs((long) reload_jiffies -
  1843. (long) priv->reload_jiffies);
  1844. priv->reload_jiffies = reload_jiffies;
  1845. if (reload_msec <= IWL_MIN_RELOAD_DURATION) {
  1846. priv->reload_count++;
  1847. if (priv->reload_count >= IWL_MAX_CONTINUE_RELOAD_CNT) {
  1848. IWL_ERR(priv, "BUG_ON, Stop restarting\n");
  1849. return;
  1850. }
  1851. } else
  1852. priv->reload_count = 0;
  1853. }
  1854. if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  1855. if (iwlagn_mod_params.restart_fw) {
  1856. IWL_DEBUG_FW_ERRORS(priv,
  1857. "Restarting adapter due to uCode error.\n");
  1858. queue_work(priv->workqueue, &priv->restart);
  1859. } else
  1860. IWL_DEBUG_FW_ERRORS(priv,
  1861. "Detected FW error, but not restarting\n");
  1862. }
  1863. }
  1864. static void iwl_nic_error(struct iwl_op_mode *op_mode)
  1865. {
  1866. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1867. IWL_ERR(priv, "Loaded firmware version: %s\n",
  1868. priv->fw->fw_version);
  1869. iwl_dump_nic_error_log(priv);
  1870. iwl_dump_nic_event_log(priv, false, NULL, false);
  1871. iwlagn_fw_error(priv, false);
  1872. }
  1873. static void iwl_cmd_queue_full(struct iwl_op_mode *op_mode)
  1874. {
  1875. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1876. if (!iwl_check_for_ct_kill(priv)) {
  1877. IWL_ERR(priv, "Restarting adapter queue is full\n");
  1878. iwlagn_fw_error(priv, false);
  1879. }
  1880. }
  1881. static void iwl_nic_config(struct iwl_op_mode *op_mode)
  1882. {
  1883. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1884. priv->lib->nic_config(priv);
  1885. }
  1886. static void iwl_stop_sw_queue(struct iwl_op_mode *op_mode, int queue)
  1887. {
  1888. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1889. int ac = priv->queue_to_ac[queue];
  1890. if (WARN_ON_ONCE(ac == IWL_INVALID_AC))
  1891. return;
  1892. if (atomic_inc_return(&priv->ac_stop_count[ac]) > 1) {
  1893. IWL_DEBUG_TX_QUEUES(priv,
  1894. "queue %d (AC %d) already stopped\n",
  1895. queue, ac);
  1896. return;
  1897. }
  1898. set_bit(ac, &priv->transport_queue_stop);
  1899. ieee80211_stop_queue(priv->hw, ac);
  1900. }
  1901. static void iwl_wake_sw_queue(struct iwl_op_mode *op_mode, int queue)
  1902. {
  1903. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1904. int ac = priv->queue_to_ac[queue];
  1905. if (WARN_ON_ONCE(ac == IWL_INVALID_AC))
  1906. return;
  1907. if (atomic_dec_return(&priv->ac_stop_count[ac]) > 0) {
  1908. IWL_DEBUG_TX_QUEUES(priv,
  1909. "queue %d (AC %d) already awake\n",
  1910. queue, ac);
  1911. return;
  1912. }
  1913. clear_bit(ac, &priv->transport_queue_stop);
  1914. if (!priv->passive_no_rx)
  1915. ieee80211_wake_queue(priv->hw, ac);
  1916. }
  1917. void iwlagn_lift_passive_no_rx(struct iwl_priv *priv)
  1918. {
  1919. int ac;
  1920. if (!priv->passive_no_rx)
  1921. return;
  1922. for (ac = IEEE80211_AC_VO; ac < IEEE80211_NUM_ACS; ac++) {
  1923. if (!test_bit(ac, &priv->transport_queue_stop)) {
  1924. IWL_DEBUG_TX_QUEUES(priv, "Wake queue %d");
  1925. ieee80211_wake_queue(priv->hw, ac);
  1926. } else {
  1927. IWL_DEBUG_TX_QUEUES(priv, "Don't wake queue %d");
  1928. }
  1929. }
  1930. priv->passive_no_rx = false;
  1931. }
  1932. static void iwl_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)
  1933. {
  1934. struct ieee80211_tx_info *info;
  1935. info = IEEE80211_SKB_CB(skb);
  1936. kmem_cache_free(iwl_tx_cmd_pool, (info->driver_data[1]));
  1937. dev_kfree_skb_any(skb);
  1938. }
  1939. static void iwl_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
  1940. {
  1941. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1942. if (state)
  1943. set_bit(STATUS_RF_KILL_HW, &priv->status);
  1944. else
  1945. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  1946. wiphy_rfkill_set_hw_state(priv->hw->wiphy, state);
  1947. }
  1948. const struct iwl_op_mode_ops iwl_dvm_ops = {
  1949. .start = iwl_op_mode_dvm_start,
  1950. .stop = iwl_op_mode_dvm_stop,
  1951. .rx = iwl_rx_dispatch,
  1952. .queue_full = iwl_stop_sw_queue,
  1953. .queue_not_full = iwl_wake_sw_queue,
  1954. .hw_rf_kill = iwl_set_hw_rfkill_state,
  1955. .free_skb = iwl_free_skb,
  1956. .nic_error = iwl_nic_error,
  1957. .cmd_queue_full = iwl_cmd_queue_full,
  1958. .nic_config = iwl_nic_config,
  1959. };
  1960. /*****************************************************************************
  1961. *
  1962. * driver and module entry point
  1963. *
  1964. *****************************************************************************/
  1965. struct kmem_cache *iwl_tx_cmd_pool;
  1966. static int __init iwl_init(void)
  1967. {
  1968. int ret;
  1969. pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
  1970. pr_info(DRV_COPYRIGHT "\n");
  1971. iwl_tx_cmd_pool = kmem_cache_create("iwl_dev_cmd",
  1972. sizeof(struct iwl_device_cmd),
  1973. sizeof(void *), 0, NULL);
  1974. if (!iwl_tx_cmd_pool)
  1975. return -ENOMEM;
  1976. ret = iwlagn_rate_control_register();
  1977. if (ret) {
  1978. pr_err("Unable to register rate control algorithm: %d\n", ret);
  1979. goto error_rc_register;
  1980. }
  1981. ret = iwl_pci_register_driver();
  1982. if (ret)
  1983. goto error_pci_register;
  1984. return ret;
  1985. error_pci_register:
  1986. iwlagn_rate_control_unregister();
  1987. error_rc_register:
  1988. kmem_cache_destroy(iwl_tx_cmd_pool);
  1989. return ret;
  1990. }
  1991. static void __exit iwl_exit(void)
  1992. {
  1993. iwl_pci_unregister_driver();
  1994. iwlagn_rate_control_unregister();
  1995. kmem_cache_destroy(iwl_tx_cmd_pool);
  1996. }
  1997. module_exit(iwl_exit);
  1998. module_init(iwl_init);
  1999. #ifdef CONFIG_IWLWIFI_DEBUG
  2000. module_param_named(debug, iwlagn_mod_params.debug_level, uint,
  2001. S_IRUGO | S_IWUSR);
  2002. MODULE_PARM_DESC(debug, "debug output mask");
  2003. #endif
  2004. module_param_named(swcrypto, iwlagn_mod_params.sw_crypto, int, S_IRUGO);
  2005. MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
  2006. module_param_named(11n_disable, iwlagn_mod_params.disable_11n, uint, S_IRUGO);
  2007. MODULE_PARM_DESC(11n_disable,
  2008. "disable 11n functionality, bitmap: 1: full, 2: agg TX, 4: agg RX");
  2009. module_param_named(amsdu_size_8K, iwlagn_mod_params.amsdu_size_8K,
  2010. int, S_IRUGO);
  2011. MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
  2012. module_param_named(fw_restart, iwlagn_mod_params.restart_fw, int, S_IRUGO);
  2013. MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");
  2014. module_param_named(ucode_alternative,
  2015. iwlagn_mod_params.wanted_ucode_alternative,
  2016. int, S_IRUGO);
  2017. MODULE_PARM_DESC(ucode_alternative,
  2018. "specify ucode alternative to use from ucode file");
  2019. module_param_named(antenna_coupling, iwlagn_mod_params.ant_coupling,
  2020. int, S_IRUGO);
  2021. MODULE_PARM_DESC(antenna_coupling,
  2022. "specify antenna coupling in dB (defualt: 0 dB)");
  2023. module_param_named(bt_ch_inhibition, iwlagn_mod_params.bt_ch_announce,
  2024. bool, S_IRUGO);
  2025. MODULE_PARM_DESC(bt_ch_inhibition,
  2026. "Enable BT channel inhibition (default: enable)");
  2027. module_param_named(plcp_check, iwlagn_mod_params.plcp_check, bool, S_IRUGO);
  2028. MODULE_PARM_DESC(plcp_check, "Check plcp health (default: 1 [enabled])");
  2029. module_param_named(wd_disable, iwlagn_mod_params.wd_disable, int, S_IRUGO);
  2030. MODULE_PARM_DESC(wd_disable,
  2031. "Disable stuck queue watchdog timer 0=system default, "
  2032. "1=disable, 2=enable (default: 0)");
  2033. /*
  2034. * set bt_coex_active to true, uCode will do kill/defer
  2035. * every time the priority line is asserted (BT is sending signals on the
  2036. * priority line in the PCIx).
  2037. * set bt_coex_active to false, uCode will ignore the BT activity and
  2038. * perform the normal operation
  2039. *
  2040. * User might experience transmit issue on some platform due to WiFi/BT
  2041. * co-exist problem. The possible behaviors are:
  2042. * Able to scan and finding all the available AP
  2043. * Not able to associate with any AP
  2044. * On those platforms, WiFi communication can be restored by set
  2045. * "bt_coex_active" module parameter to "false"
  2046. *
  2047. * default: bt_coex_active = true (BT_COEX_ENABLE)
  2048. */
  2049. module_param_named(bt_coex_active, iwlagn_mod_params.bt_coex_active,
  2050. bool, S_IRUGO);
  2051. MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)");
  2052. module_param_named(led_mode, iwlagn_mod_params.led_mode, int, S_IRUGO);
  2053. MODULE_PARM_DESC(led_mode, "0=system default, "
  2054. "1=On(RF On)/Off(RF Off), 2=blinking, 3=Off (default: 0)");
  2055. module_param_named(power_save, iwlagn_mod_params.power_save,
  2056. bool, S_IRUGO);
  2057. MODULE_PARM_DESC(power_save,
  2058. "enable WiFi power management (default: disable)");
  2059. module_param_named(power_level, iwlagn_mod_params.power_level,
  2060. int, S_IRUGO);
  2061. MODULE_PARM_DESC(power_level,
  2062. "default power save level (range from 1 - 5, default: 1)");
  2063. module_param_named(auto_agg, iwlagn_mod_params.auto_agg,
  2064. bool, S_IRUGO);
  2065. MODULE_PARM_DESC(auto_agg,
  2066. "enable agg w/o check traffic load (default: enable)");
  2067. /*
  2068. * For now, keep using power level 1 instead of automatically
  2069. * adjusting ...
  2070. */
  2071. module_param_named(no_sleep_autoadjust, iwlagn_mod_params.no_sleep_autoadjust,
  2072. bool, S_IRUGO);
  2073. MODULE_PARM_DESC(no_sleep_autoadjust,
  2074. "don't automatically adjust sleep level "
  2075. "according to maximum network latency (default: true)");