main.c 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2014 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-read.h"
  43. #include "iwl-eeprom-parse.h"
  44. #include "iwl-io.h"
  45. #include "iwl-trans.h"
  46. #include "iwl-op-mode.h"
  47. #include "iwl-drv.h"
  48. #include "iwl-modparams.h"
  49. #include "iwl-prph.h"
  50. #include "dev.h"
  51. #include "calib.h"
  52. #include "agn.h"
  53. /******************************************************************************
  54. *
  55. * module boiler plate
  56. *
  57. ******************************************************************************/
  58. /*
  59. * module name, copyright, version, etc.
  60. */
  61. #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
  62. #ifdef CONFIG_IWLWIFI_DEBUG
  63. #define VD "d"
  64. #else
  65. #define VD
  66. #endif
  67. #define DRV_VERSION IWLWIFI_VERSION VD
  68. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  69. MODULE_VERSION(DRV_VERSION);
  70. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  71. MODULE_LICENSE("GPL");
  72. static const struct iwl_op_mode_ops iwl_dvm_ops;
  73. void iwl_update_chain_flags(struct iwl_priv *priv)
  74. {
  75. struct iwl_rxon_context *ctx;
  76. for_each_context(priv, ctx) {
  77. iwlagn_set_rxon_chain(priv, ctx);
  78. if (ctx->active.rx_chain != ctx->staging.rx_chain)
  79. iwlagn_commit_rxon(priv, ctx);
  80. }
  81. }
  82. /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
  83. static void iwl_set_beacon_tim(struct iwl_priv *priv,
  84. struct iwl_tx_beacon_cmd *tx_beacon_cmd,
  85. u8 *beacon, u32 frame_size)
  86. {
  87. u16 tim_idx;
  88. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
  89. /*
  90. * The index is relative to frame start but we start looking at the
  91. * variable-length part of the beacon.
  92. */
  93. tim_idx = mgmt->u.beacon.variable - beacon;
  94. /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
  95. while ((tim_idx < (frame_size - 2)) &&
  96. (beacon[tim_idx] != WLAN_EID_TIM))
  97. tim_idx += beacon[tim_idx+1] + 2;
  98. /* If TIM field was found, set variables */
  99. if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
  100. tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
  101. tx_beacon_cmd->tim_size = beacon[tim_idx+1];
  102. } else
  103. IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
  104. }
  105. int iwlagn_send_beacon_cmd(struct iwl_priv *priv)
  106. {
  107. struct iwl_tx_beacon_cmd *tx_beacon_cmd;
  108. struct iwl_host_cmd cmd = {
  109. .id = REPLY_TX_BEACON,
  110. };
  111. struct ieee80211_tx_info *info;
  112. u32 frame_size;
  113. u32 rate_flags;
  114. u32 rate;
  115. /*
  116. * We have to set up the TX command, the TX Beacon command, and the
  117. * beacon contents.
  118. */
  119. lockdep_assert_held(&priv->mutex);
  120. if (!priv->beacon_ctx) {
  121. IWL_ERR(priv, "trying to build beacon w/o beacon context!\n");
  122. return 0;
  123. }
  124. if (WARN_ON(!priv->beacon_skb))
  125. return -EINVAL;
  126. /* Allocate beacon command */
  127. if (!priv->beacon_cmd)
  128. priv->beacon_cmd = kzalloc(sizeof(*tx_beacon_cmd), GFP_KERNEL);
  129. tx_beacon_cmd = priv->beacon_cmd;
  130. if (!tx_beacon_cmd)
  131. return -ENOMEM;
  132. frame_size = priv->beacon_skb->len;
  133. /* Set up TX command fields */
  134. tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
  135. tx_beacon_cmd->tx.sta_id = priv->beacon_ctx->bcast_sta_id;
  136. tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  137. tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
  138. TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
  139. /* Set up TX beacon command fields */
  140. iwl_set_beacon_tim(priv, tx_beacon_cmd, priv->beacon_skb->data,
  141. frame_size);
  142. /* Set up packet rate and flags */
  143. info = IEEE80211_SKB_CB(priv->beacon_skb);
  144. /*
  145. * Let's set up the rate at least somewhat correctly;
  146. * it will currently not actually be used by the uCode,
  147. * it uses the broadcast station's rate instead.
  148. */
  149. if (info->control.rates[0].idx < 0 ||
  150. info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
  151. rate = 0;
  152. else
  153. rate = info->control.rates[0].idx;
  154. priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
  155. priv->nvm_data->valid_tx_ant);
  156. rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
  157. /* In mac80211, rates for 5 GHz start at 0 */
  158. if (info->band == IEEE80211_BAND_5GHZ)
  159. rate += IWL_FIRST_OFDM_RATE;
  160. else if (rate >= IWL_FIRST_CCK_RATE && rate <= IWL_LAST_CCK_RATE)
  161. rate_flags |= RATE_MCS_CCK_MSK;
  162. tx_beacon_cmd->tx.rate_n_flags =
  163. iwl_hw_set_rate_n_flags(rate, rate_flags);
  164. /* Submit command */
  165. cmd.len[0] = sizeof(*tx_beacon_cmd);
  166. cmd.data[0] = tx_beacon_cmd;
  167. cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
  168. cmd.len[1] = frame_size;
  169. cmd.data[1] = priv->beacon_skb->data;
  170. cmd.dataflags[1] = IWL_HCMD_DFL_NOCOPY;
  171. return iwl_dvm_send_cmd(priv, &cmd);
  172. }
  173. static void iwl_bg_beacon_update(struct work_struct *work)
  174. {
  175. struct iwl_priv *priv =
  176. container_of(work, struct iwl_priv, beacon_update);
  177. struct sk_buff *beacon;
  178. mutex_lock(&priv->mutex);
  179. if (!priv->beacon_ctx) {
  180. IWL_ERR(priv, "updating beacon w/o beacon context!\n");
  181. goto out;
  182. }
  183. if (priv->beacon_ctx->vif->type != NL80211_IFTYPE_AP) {
  184. /*
  185. * The ucode will send beacon notifications even in
  186. * IBSS mode, but we don't want to process them. But
  187. * we need to defer the type check to here due to
  188. * requiring locking around the beacon_ctx access.
  189. */
  190. goto out;
  191. }
  192. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  193. beacon = ieee80211_beacon_get(priv->hw, priv->beacon_ctx->vif);
  194. if (!beacon) {
  195. IWL_ERR(priv, "update beacon failed -- keeping old\n");
  196. goto out;
  197. }
  198. /* new beacon skb is allocated every time; dispose previous.*/
  199. dev_kfree_skb(priv->beacon_skb);
  200. priv->beacon_skb = beacon;
  201. iwlagn_send_beacon_cmd(priv);
  202. out:
  203. mutex_unlock(&priv->mutex);
  204. }
  205. static void iwl_bg_bt_runtime_config(struct work_struct *work)
  206. {
  207. struct iwl_priv *priv =
  208. container_of(work, struct iwl_priv, bt_runtime_config);
  209. mutex_lock(&priv->mutex);
  210. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  211. goto out;
  212. /* dont send host command if rf-kill is on */
  213. if (!iwl_is_ready_rf(priv))
  214. goto out;
  215. iwlagn_send_advance_bt_config(priv);
  216. out:
  217. mutex_unlock(&priv->mutex);
  218. }
  219. static void iwl_bg_bt_full_concurrency(struct work_struct *work)
  220. {
  221. struct iwl_priv *priv =
  222. container_of(work, struct iwl_priv, bt_full_concurrency);
  223. struct iwl_rxon_context *ctx;
  224. mutex_lock(&priv->mutex);
  225. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  226. goto out;
  227. /* dont send host command if rf-kill is on */
  228. if (!iwl_is_ready_rf(priv))
  229. goto out;
  230. IWL_DEBUG_INFO(priv, "BT coex in %s mode\n",
  231. priv->bt_full_concurrent ?
  232. "full concurrency" : "3-wire");
  233. /*
  234. * LQ & RXON updated cmds must be sent before BT Config cmd
  235. * to avoid 3-wire collisions
  236. */
  237. for_each_context(priv, ctx) {
  238. iwlagn_set_rxon_chain(priv, ctx);
  239. iwlagn_commit_rxon(priv, ctx);
  240. }
  241. iwlagn_send_advance_bt_config(priv);
  242. out:
  243. mutex_unlock(&priv->mutex);
  244. }
  245. int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
  246. {
  247. struct iwl_statistics_cmd statistics_cmd = {
  248. .configuration_flags =
  249. clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
  250. };
  251. if (flags & CMD_ASYNC)
  252. return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
  253. CMD_ASYNC,
  254. sizeof(struct iwl_statistics_cmd),
  255. &statistics_cmd);
  256. else
  257. return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD, 0,
  258. sizeof(struct iwl_statistics_cmd),
  259. &statistics_cmd);
  260. }
  261. /**
  262. * iwl_bg_statistics_periodic - Timer callback to queue statistics
  263. *
  264. * This callback is provided in order to send a statistics request.
  265. *
  266. * This timer function is continually reset to execute within
  267. * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
  268. * was received. We need to ensure we receive the statistics in order
  269. * to update the temperature used for calibrating the TXPOWER.
  270. */
  271. static void iwl_bg_statistics_periodic(unsigned long data)
  272. {
  273. struct iwl_priv *priv = (struct iwl_priv *)data;
  274. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  275. return;
  276. /* dont send host command if rf-kill is on */
  277. if (!iwl_is_ready_rf(priv))
  278. return;
  279. iwl_send_statistics_request(priv, CMD_ASYNC, false);
  280. }
  281. static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base,
  282. u32 start_idx, u32 num_events,
  283. u32 capacity, u32 mode)
  284. {
  285. u32 i;
  286. u32 ptr; /* SRAM byte address of log data */
  287. u32 ev, time, data; /* event log data */
  288. unsigned long reg_flags;
  289. if (mode == 0)
  290. ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32));
  291. else
  292. ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32));
  293. /* Make sure device is powered up for SRAM reads */
  294. if (!iwl_trans_grab_nic_access(priv->trans, false, &reg_flags))
  295. return;
  296. /* Set starting address; reads will auto-increment */
  297. iwl_write32(priv->trans, 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(priv->trans, HBUS_TARG_MEM_RDAT);
  312. time = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT);
  313. if (mode == 0) {
  314. trace_iwlwifi_dev_ucode_cont_event(
  315. priv->trans->dev, 0, time, ev);
  316. } else {
  317. data = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT);
  318. trace_iwlwifi_dev_ucode_cont_event(
  319. priv->trans->dev, time, data, ev);
  320. }
  321. }
  322. /* Allow device to power down */
  323. iwl_trans_release_nic_access(priv->trans, &reg_flags);
  324. }
  325. static void iwl_continuous_event_trace(struct iwl_priv *priv)
  326. {
  327. u32 capacity; /* event log capacity in # entries */
  328. struct {
  329. u32 capacity;
  330. u32 mode;
  331. u32 wrap_counter;
  332. u32 write_counter;
  333. } __packed read;
  334. u32 base; /* SRAM byte address of event log header */
  335. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  336. u32 num_wraps; /* # times uCode wrapped to top of log */
  337. u32 next_entry; /* index of next entry to be written by uCode */
  338. base = priv->device_pointers.log_event_table;
  339. if (iwlagn_hw_valid_rtc_data_addr(base)) {
  340. iwl_trans_read_mem_bytes(priv->trans, base,
  341. &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(priv->trans->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);
  430. }
  431. /*
  432. * queue/FIFO/AC mapping definitions
  433. */
  434. static const u8 iwlagn_bss_ac_to_fifo[] = {
  435. IWL_TX_FIFO_VO,
  436. IWL_TX_FIFO_VI,
  437. IWL_TX_FIFO_BE,
  438. IWL_TX_FIFO_BK,
  439. };
  440. static const u8 iwlagn_bss_ac_to_queue[] = {
  441. 0, 1, 2, 3,
  442. };
  443. static const u8 iwlagn_pan_ac_to_fifo[] = {
  444. IWL_TX_FIFO_VO_IPAN,
  445. IWL_TX_FIFO_VI_IPAN,
  446. IWL_TX_FIFO_BE_IPAN,
  447. IWL_TX_FIFO_BK_IPAN,
  448. };
  449. static const u8 iwlagn_pan_ac_to_queue[] = {
  450. 7, 6, 5, 4,
  451. };
  452. static void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags)
  453. {
  454. int i;
  455. /*
  456. * The default context is always valid,
  457. * the PAN context depends on uCode.
  458. */
  459. priv->valid_contexts = BIT(IWL_RXON_CTX_BSS);
  460. if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN)
  461. priv->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
  462. for (i = 0; i < NUM_IWL_RXON_CTX; i++)
  463. priv->contexts[i].ctxid = i;
  464. priv->contexts[IWL_RXON_CTX_BSS].always_active = true;
  465. priv->contexts[IWL_RXON_CTX_BSS].is_active = true;
  466. priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
  467. priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
  468. priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
  469. priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
  470. priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
  471. priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
  472. priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
  473. priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
  474. BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_MONITOR);
  475. priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
  476. BIT(NL80211_IFTYPE_STATION);
  477. priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP;
  478. priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
  479. priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
  480. priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
  481. memcpy(priv->contexts[IWL_RXON_CTX_BSS].ac_to_queue,
  482. iwlagn_bss_ac_to_queue, sizeof(iwlagn_bss_ac_to_queue));
  483. memcpy(priv->contexts[IWL_RXON_CTX_BSS].ac_to_fifo,
  484. iwlagn_bss_ac_to_fifo, sizeof(iwlagn_bss_ac_to_fifo));
  485. priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON;
  486. priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd =
  487. REPLY_WIPAN_RXON_TIMING;
  488. priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd =
  489. REPLY_WIPAN_RXON_ASSOC;
  490. priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM;
  491. priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN;
  492. priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY;
  493. priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID;
  494. priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION;
  495. priv->contexts[IWL_RXON_CTX_PAN].interface_modes =
  496. BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
  497. priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP;
  498. priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA;
  499. priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P;
  500. memcpy(priv->contexts[IWL_RXON_CTX_PAN].ac_to_queue,
  501. iwlagn_pan_ac_to_queue, sizeof(iwlagn_pan_ac_to_queue));
  502. memcpy(priv->contexts[IWL_RXON_CTX_PAN].ac_to_fifo,
  503. iwlagn_pan_ac_to_fifo, sizeof(iwlagn_pan_ac_to_fifo));
  504. priv->contexts[IWL_RXON_CTX_PAN].mcast_queue = IWL_IPAN_MCAST_QUEUE;
  505. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  506. }
  507. static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
  508. {
  509. struct iwl_ct_kill_config cmd;
  510. struct iwl_ct_kill_throttling_config adv_cmd;
  511. int ret = 0;
  512. iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR,
  513. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  514. priv->thermal_throttle.ct_kill_toggle = false;
  515. if (priv->lib->support_ct_kill_exit) {
  516. adv_cmd.critical_temperature_enter =
  517. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  518. adv_cmd.critical_temperature_exit =
  519. cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
  520. ret = iwl_dvm_send_cmd_pdu(priv,
  521. REPLY_CT_KILL_CONFIG_CMD,
  522. 0, sizeof(adv_cmd), &adv_cmd);
  523. if (ret)
  524. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  525. else
  526. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  527. "succeeded, critical temperature enter is %d,"
  528. "exit is %d\n",
  529. priv->hw_params.ct_kill_threshold,
  530. priv->hw_params.ct_kill_exit_threshold);
  531. } else {
  532. cmd.critical_temperature_R =
  533. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  534. ret = iwl_dvm_send_cmd_pdu(priv,
  535. REPLY_CT_KILL_CONFIG_CMD,
  536. 0, sizeof(cmd), &cmd);
  537. if (ret)
  538. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  539. else
  540. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  541. "succeeded, "
  542. "critical temperature is %d\n",
  543. priv->hw_params.ct_kill_threshold);
  544. }
  545. }
  546. static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
  547. {
  548. struct iwl_calib_cfg_cmd calib_cfg_cmd;
  549. struct iwl_host_cmd cmd = {
  550. .id = CALIBRATION_CFG_CMD,
  551. .len = { sizeof(struct iwl_calib_cfg_cmd), },
  552. .data = { &calib_cfg_cmd, },
  553. };
  554. memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
  555. calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_RT_CFG_ALL;
  556. calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg);
  557. return iwl_dvm_send_cmd(priv, &cmd);
  558. }
  559. static int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant)
  560. {
  561. struct iwl_tx_ant_config_cmd tx_ant_cmd = {
  562. .valid = cpu_to_le32(valid_tx_ant),
  563. };
  564. if (IWL_UCODE_API(priv->fw->ucode_ver) > 1) {
  565. IWL_DEBUG_HC(priv, "select valid tx ant: %u\n", valid_tx_ant);
  566. return iwl_dvm_send_cmd_pdu(priv, TX_ANT_CONFIGURATION_CMD, 0,
  567. sizeof(struct iwl_tx_ant_config_cmd),
  568. &tx_ant_cmd);
  569. } else {
  570. IWL_DEBUG_HC(priv, "TX_ANT_CONFIGURATION_CMD not supported\n");
  571. return -EOPNOTSUPP;
  572. }
  573. }
  574. static void iwl_send_bt_config(struct iwl_priv *priv)
  575. {
  576. struct iwl_bt_cmd bt_cmd = {
  577. .lead_time = BT_LEAD_TIME_DEF,
  578. .max_kill = BT_MAX_KILL_DEF,
  579. .kill_ack_mask = 0,
  580. .kill_cts_mask = 0,
  581. };
  582. if (!iwlwifi_mod_params.bt_coex_active)
  583. bt_cmd.flags = BT_COEX_DISABLE;
  584. else
  585. bt_cmd.flags = BT_COEX_ENABLE;
  586. priv->bt_enable_flag = bt_cmd.flags;
  587. IWL_DEBUG_INFO(priv, "BT coex %s\n",
  588. (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
  589. if (iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  590. 0, sizeof(struct iwl_bt_cmd), &bt_cmd))
  591. IWL_ERR(priv, "failed to send BT Coex Config\n");
  592. }
  593. /**
  594. * iwl_alive_start - called after REPLY_ALIVE notification received
  595. * from protocol/runtime uCode (initialization uCode's
  596. * Alive gets handled by iwl_init_alive_start()).
  597. */
  598. int iwl_alive_start(struct iwl_priv *priv)
  599. {
  600. int ret = 0;
  601. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  602. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  603. /* After the ALIVE response, we can send host commands to the uCode */
  604. set_bit(STATUS_ALIVE, &priv->status);
  605. if (iwl_is_rfkill(priv))
  606. return -ERFKILL;
  607. if (priv->event_log.ucode_trace) {
  608. /* start collecting data now */
  609. mod_timer(&priv->ucode_trace, jiffies);
  610. }
  611. /* download priority table before any calibration request */
  612. if (priv->lib->bt_params &&
  613. priv->lib->bt_params->advanced_bt_coexist) {
  614. /* Configure Bluetooth device coexistence support */
  615. if (priv->lib->bt_params->bt_sco_disable)
  616. priv->bt_enable_pspoll = false;
  617. else
  618. priv->bt_enable_pspoll = true;
  619. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  620. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  621. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  622. iwlagn_send_advance_bt_config(priv);
  623. priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS;
  624. priv->cur_rssi_ctx = NULL;
  625. iwl_send_prio_tbl(priv);
  626. /* FIXME: w/a to force change uCode BT state machine */
  627. ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
  628. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  629. if (ret)
  630. return ret;
  631. ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
  632. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  633. if (ret)
  634. return ret;
  635. } else if (priv->lib->bt_params) {
  636. /*
  637. * default is 2-wire BT coexexistence support
  638. */
  639. iwl_send_bt_config(priv);
  640. }
  641. /*
  642. * Perform runtime calibrations, including DC calibration.
  643. */
  644. iwlagn_send_calib_cfg_rt(priv, IWL_CALIB_CFG_DC_IDX);
  645. ieee80211_wake_queues(priv->hw);
  646. /* Configure Tx antenna selection based on H/W config */
  647. iwlagn_send_tx_ant_config(priv, priv->nvm_data->valid_tx_ant);
  648. if (iwl_is_associated_ctx(ctx) && !priv->wowlan) {
  649. struct iwl_rxon_cmd *active_rxon =
  650. (struct iwl_rxon_cmd *)&ctx->active;
  651. /* apply any changes in staging */
  652. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  653. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  654. } else {
  655. struct iwl_rxon_context *tmp;
  656. /* Initialize our rx_config data */
  657. for_each_context(priv, tmp)
  658. iwl_connection_init_rx_config(priv, tmp);
  659. iwlagn_set_rxon_chain(priv, ctx);
  660. }
  661. if (!priv->wowlan) {
  662. /* WoWLAN ucode will not reply in the same way, skip it */
  663. iwl_reset_run_time_calib(priv);
  664. }
  665. set_bit(STATUS_READY, &priv->status);
  666. /* Configure the adapter for unassociated operation */
  667. ret = iwlagn_commit_rxon(priv, ctx);
  668. if (ret)
  669. return ret;
  670. /* At this point, the NIC is initialized and operational */
  671. iwl_rf_kill_ct_config(priv);
  672. IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
  673. return iwl_power_update_mode(priv, true);
  674. }
  675. /**
  676. * iwl_clear_driver_stations - clear knowledge of all stations from driver
  677. * @priv: iwl priv struct
  678. *
  679. * This is called during iwl_down() to make sure that in the case
  680. * we're coming there from a hardware restart mac80211 will be
  681. * able to reconfigure stations -- if we're getting there in the
  682. * normal down flow then the stations will already be cleared.
  683. */
  684. static void iwl_clear_driver_stations(struct iwl_priv *priv)
  685. {
  686. struct iwl_rxon_context *ctx;
  687. spin_lock_bh(&priv->sta_lock);
  688. memset(priv->stations, 0, sizeof(priv->stations));
  689. priv->num_stations = 0;
  690. priv->ucode_key_table = 0;
  691. for_each_context(priv, ctx) {
  692. /*
  693. * Remove all key information that is not stored as part
  694. * of station information since mac80211 may not have had
  695. * a chance to remove all the keys. When device is
  696. * reconfigured by mac80211 after an error all keys will
  697. * be reconfigured.
  698. */
  699. memset(ctx->wep_keys, 0, sizeof(ctx->wep_keys));
  700. ctx->key_mapping_keys = 0;
  701. }
  702. spin_unlock_bh(&priv->sta_lock);
  703. }
  704. void iwl_down(struct iwl_priv *priv)
  705. {
  706. int exit_pending;
  707. IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
  708. lockdep_assert_held(&priv->mutex);
  709. iwl_scan_cancel_timeout(priv, 200);
  710. exit_pending =
  711. test_and_set_bit(STATUS_EXIT_PENDING, &priv->status);
  712. iwl_clear_ucode_stations(priv, NULL);
  713. iwl_dealloc_bcast_stations(priv);
  714. iwl_clear_driver_stations(priv);
  715. /* reset BT coex data */
  716. priv->bt_status = 0;
  717. priv->cur_rssi_ctx = NULL;
  718. priv->bt_is_sco = 0;
  719. if (priv->lib->bt_params)
  720. priv->bt_traffic_load =
  721. priv->lib->bt_params->bt_init_traffic_load;
  722. else
  723. priv->bt_traffic_load = 0;
  724. priv->bt_full_concurrent = false;
  725. priv->bt_ci_compliance = 0;
  726. /* Wipe out the EXIT_PENDING status bit if we are not actually
  727. * exiting the module */
  728. if (!exit_pending)
  729. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  730. if (priv->mac80211_registered)
  731. ieee80211_stop_queues(priv->hw);
  732. priv->ucode_loaded = false;
  733. iwl_trans_stop_device(priv->trans);
  734. /* Set num_aux_in_flight must be done after the transport is stopped */
  735. atomic_set(&priv->num_aux_in_flight, 0);
  736. /* Clear out all status bits but a few that are stable across reset */
  737. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  738. STATUS_RF_KILL_HW |
  739. test_bit(STATUS_FW_ERROR, &priv->status) <<
  740. STATUS_FW_ERROR |
  741. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  742. STATUS_EXIT_PENDING;
  743. dev_kfree_skb(priv->beacon_skb);
  744. priv->beacon_skb = NULL;
  745. }
  746. /*****************************************************************************
  747. *
  748. * Workqueue callbacks
  749. *
  750. *****************************************************************************/
  751. static void iwl_bg_run_time_calib_work(struct work_struct *work)
  752. {
  753. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  754. run_time_calib_work);
  755. mutex_lock(&priv->mutex);
  756. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  757. test_bit(STATUS_SCANNING, &priv->status)) {
  758. mutex_unlock(&priv->mutex);
  759. return;
  760. }
  761. if (priv->start_calib) {
  762. iwl_chain_noise_calibration(priv);
  763. iwl_sensitivity_calibration(priv);
  764. }
  765. mutex_unlock(&priv->mutex);
  766. }
  767. void iwlagn_prepare_restart(struct iwl_priv *priv)
  768. {
  769. bool bt_full_concurrent;
  770. u8 bt_ci_compliance;
  771. u8 bt_load;
  772. u8 bt_status;
  773. bool bt_is_sco;
  774. int i;
  775. lockdep_assert_held(&priv->mutex);
  776. priv->is_open = 0;
  777. /*
  778. * __iwl_down() will clear the BT status variables,
  779. * which is correct, but when we restart we really
  780. * want to keep them so restore them afterwards.
  781. *
  782. * The restart process will later pick them up and
  783. * re-configure the hw when we reconfigure the BT
  784. * command.
  785. */
  786. bt_full_concurrent = priv->bt_full_concurrent;
  787. bt_ci_compliance = priv->bt_ci_compliance;
  788. bt_load = priv->bt_traffic_load;
  789. bt_status = priv->bt_status;
  790. bt_is_sco = priv->bt_is_sco;
  791. iwl_down(priv);
  792. priv->bt_full_concurrent = bt_full_concurrent;
  793. priv->bt_ci_compliance = bt_ci_compliance;
  794. priv->bt_traffic_load = bt_load;
  795. priv->bt_status = bt_status;
  796. priv->bt_is_sco = bt_is_sco;
  797. /* reset aggregation queues */
  798. for (i = IWLAGN_FIRST_AMPDU_QUEUE; i < IWL_MAX_HW_QUEUES; i++)
  799. priv->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE;
  800. /* and stop counts */
  801. for (i = 0; i < IWL_MAX_HW_QUEUES; i++)
  802. atomic_set(&priv->queue_stop_count[i], 0);
  803. memset(priv->agg_q_alloc, 0, sizeof(priv->agg_q_alloc));
  804. }
  805. static void iwl_bg_restart(struct work_struct *data)
  806. {
  807. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  808. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  809. return;
  810. if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
  811. mutex_lock(&priv->mutex);
  812. iwlagn_prepare_restart(priv);
  813. mutex_unlock(&priv->mutex);
  814. iwl_cancel_deferred_work(priv);
  815. if (priv->mac80211_registered)
  816. ieee80211_restart_hw(priv->hw);
  817. else
  818. IWL_ERR(priv,
  819. "Cannot request restart before registrating with mac80211\n");
  820. } else {
  821. WARN_ON(1);
  822. }
  823. }
  824. /*****************************************************************************
  825. *
  826. * driver setup and teardown
  827. *
  828. *****************************************************************************/
  829. static void iwl_setup_deferred_work(struct iwl_priv *priv)
  830. {
  831. priv->workqueue = create_singlethread_workqueue(DRV_NAME);
  832. INIT_WORK(&priv->restart, iwl_bg_restart);
  833. INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
  834. INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
  835. INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
  836. INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
  837. INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
  838. iwl_setup_scan_deferred_work(priv);
  839. if (priv->lib->bt_params)
  840. iwlagn_bt_setup_deferred_work(priv);
  841. init_timer(&priv->statistics_periodic);
  842. priv->statistics_periodic.data = (unsigned long)priv;
  843. priv->statistics_periodic.function = iwl_bg_statistics_periodic;
  844. init_timer(&priv->ucode_trace);
  845. priv->ucode_trace.data = (unsigned long)priv;
  846. priv->ucode_trace.function = iwl_bg_ucode_trace;
  847. }
  848. void iwl_cancel_deferred_work(struct iwl_priv *priv)
  849. {
  850. if (priv->lib->bt_params)
  851. iwlagn_bt_cancel_deferred_work(priv);
  852. cancel_work_sync(&priv->run_time_calib_work);
  853. cancel_work_sync(&priv->beacon_update);
  854. iwl_cancel_scan_deferred_work(priv);
  855. cancel_work_sync(&priv->bt_full_concurrency);
  856. cancel_work_sync(&priv->bt_runtime_config);
  857. del_timer_sync(&priv->statistics_periodic);
  858. del_timer_sync(&priv->ucode_trace);
  859. }
  860. static int iwl_init_drv(struct iwl_priv *priv)
  861. {
  862. spin_lock_init(&priv->sta_lock);
  863. mutex_init(&priv->mutex);
  864. INIT_LIST_HEAD(&priv->calib_results);
  865. priv->band = IEEE80211_BAND_2GHZ;
  866. priv->plcp_delta_threshold = priv->lib->plcp_delta_threshold;
  867. priv->iw_mode = NL80211_IFTYPE_STATION;
  868. priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
  869. priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
  870. priv->agg_tids_count = 0;
  871. priv->rx_statistics_jiffies = jiffies;
  872. /* Choose which receivers/antennas to use */
  873. iwlagn_set_rxon_chain(priv, &priv->contexts[IWL_RXON_CTX_BSS]);
  874. iwl_init_scan_params(priv);
  875. /* init bt coex */
  876. if (priv->lib->bt_params &&
  877. priv->lib->bt_params->advanced_bt_coexist) {
  878. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  879. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  880. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  881. priv->bt_on_thresh = BT_ON_THRESHOLD_DEF;
  882. priv->bt_duration = BT_DURATION_LIMIT_DEF;
  883. priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
  884. }
  885. return 0;
  886. }
  887. static void iwl_uninit_drv(struct iwl_priv *priv)
  888. {
  889. kfree(priv->scan_cmd);
  890. kfree(priv->beacon_cmd);
  891. kfree(rcu_dereference_raw(priv->noa_data));
  892. iwl_calib_free_results(priv);
  893. #ifdef CONFIG_IWLWIFI_DEBUGFS
  894. kfree(priv->wowlan_sram);
  895. #endif
  896. }
  897. static void iwl_set_hw_params(struct iwl_priv *priv)
  898. {
  899. if (priv->cfg->ht_params)
  900. priv->hw_params.use_rts_for_aggregation =
  901. priv->cfg->ht_params->use_rts_for_aggregation;
  902. /* Device-specific setup */
  903. priv->lib->set_hw_params(priv);
  904. }
  905. /* show what optional capabilities we have */
  906. static void iwl_option_config(struct iwl_priv *priv)
  907. {
  908. #ifdef CONFIG_IWLWIFI_DEBUG
  909. IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUG enabled\n");
  910. #else
  911. IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUG disabled\n");
  912. #endif
  913. #ifdef CONFIG_IWLWIFI_DEBUGFS
  914. IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUGFS enabled\n");
  915. #else
  916. IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUGFS disabled\n");
  917. #endif
  918. #ifdef CONFIG_IWLWIFI_DEVICE_TRACING
  919. IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TRACING enabled\n");
  920. #else
  921. IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TRACING disabled\n");
  922. #endif
  923. }
  924. static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
  925. {
  926. struct iwl_nvm_data *data = priv->nvm_data;
  927. if (data->sku_cap_11n_enable &&
  928. !priv->cfg->ht_params) {
  929. IWL_ERR(priv, "Invalid 11n configuration\n");
  930. return -EINVAL;
  931. }
  932. if (!data->sku_cap_11n_enable && !data->sku_cap_band_24GHz_enable &&
  933. !data->sku_cap_band_52GHz_enable) {
  934. IWL_ERR(priv, "Invalid device sku\n");
  935. return -EINVAL;
  936. }
  937. IWL_DEBUG_INFO(priv,
  938. "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n",
  939. data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
  940. data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
  941. data->sku_cap_11n_enable ? "" : "NOT", "enabled");
  942. priv->hw_params.tx_chains_num =
  943. num_of_ant(data->valid_tx_ant);
  944. if (priv->cfg->rx_with_siso_diversity)
  945. priv->hw_params.rx_chains_num = 1;
  946. else
  947. priv->hw_params.rx_chains_num =
  948. num_of_ant(data->valid_rx_ant);
  949. IWL_DEBUG_INFO(priv, "Valid Tx ant: 0x%X, Valid Rx ant: 0x%X\n",
  950. data->valid_tx_ant,
  951. data->valid_rx_ant);
  952. return 0;
  953. }
  954. static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
  955. const struct iwl_cfg *cfg,
  956. const struct iwl_fw *fw,
  957. struct dentry *dbgfs_dir)
  958. {
  959. struct iwl_priv *priv;
  960. struct ieee80211_hw *hw;
  961. struct iwl_op_mode *op_mode;
  962. u16 num_mac;
  963. u32 ucode_flags;
  964. struct iwl_trans_config trans_cfg = {};
  965. static const u8 no_reclaim_cmds[] = {
  966. REPLY_RX_PHY_CMD,
  967. REPLY_RX_MPDU_CMD,
  968. REPLY_COMPRESSED_BA,
  969. STATISTICS_NOTIFICATION,
  970. REPLY_TX,
  971. };
  972. int i;
  973. /************************
  974. * 1. Allocating HW data
  975. ************************/
  976. hw = iwl_alloc_all();
  977. if (!hw) {
  978. pr_err("%s: Cannot allocate network device\n", cfg->name);
  979. goto out;
  980. }
  981. op_mode = hw->priv;
  982. op_mode->ops = &iwl_dvm_ops;
  983. priv = IWL_OP_MODE_GET_DVM(op_mode);
  984. priv->trans = trans;
  985. priv->dev = trans->dev;
  986. priv->cfg = cfg;
  987. priv->fw = fw;
  988. switch (priv->cfg->device_family) {
  989. case IWL_DEVICE_FAMILY_1000:
  990. case IWL_DEVICE_FAMILY_100:
  991. priv->lib = &iwl_dvm_1000_cfg;
  992. break;
  993. case IWL_DEVICE_FAMILY_2000:
  994. priv->lib = &iwl_dvm_2000_cfg;
  995. break;
  996. case IWL_DEVICE_FAMILY_105:
  997. priv->lib = &iwl_dvm_105_cfg;
  998. break;
  999. case IWL_DEVICE_FAMILY_2030:
  1000. case IWL_DEVICE_FAMILY_135:
  1001. priv->lib = &iwl_dvm_2030_cfg;
  1002. break;
  1003. case IWL_DEVICE_FAMILY_5000:
  1004. priv->lib = &iwl_dvm_5000_cfg;
  1005. break;
  1006. case IWL_DEVICE_FAMILY_5150:
  1007. priv->lib = &iwl_dvm_5150_cfg;
  1008. break;
  1009. case IWL_DEVICE_FAMILY_6000:
  1010. case IWL_DEVICE_FAMILY_6000i:
  1011. priv->lib = &iwl_dvm_6000_cfg;
  1012. break;
  1013. case IWL_DEVICE_FAMILY_6005:
  1014. priv->lib = &iwl_dvm_6005_cfg;
  1015. break;
  1016. case IWL_DEVICE_FAMILY_6050:
  1017. case IWL_DEVICE_FAMILY_6150:
  1018. priv->lib = &iwl_dvm_6050_cfg;
  1019. break;
  1020. case IWL_DEVICE_FAMILY_6030:
  1021. priv->lib = &iwl_dvm_6030_cfg;
  1022. break;
  1023. default:
  1024. break;
  1025. }
  1026. if (WARN_ON(!priv->lib))
  1027. goto out_free_hw;
  1028. /*
  1029. * Populate the state variables that the transport layer needs
  1030. * to know about.
  1031. */
  1032. trans_cfg.op_mode = op_mode;
  1033. trans_cfg.no_reclaim_cmds = no_reclaim_cmds;
  1034. trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
  1035. trans_cfg.rx_buf_size_8k = iwlwifi_mod_params.amsdu_size_8K;
  1036. if (!iwlwifi_mod_params.wd_disable)
  1037. trans_cfg.queue_watchdog_timeout =
  1038. priv->cfg->base_params->wd_timeout;
  1039. else
  1040. trans_cfg.queue_watchdog_timeout = IWL_WATCHDOG_DISABLED;
  1041. trans_cfg.command_names = iwl_dvm_cmd_strings;
  1042. trans_cfg.cmd_fifo = IWLAGN_CMD_FIFO_NUM;
  1043. WARN_ON(sizeof(priv->transport_queue_stop) * BITS_PER_BYTE <
  1044. priv->cfg->base_params->num_of_queues);
  1045. ucode_flags = fw->ucode_capa.flags;
  1046. if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN) {
  1047. priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
  1048. trans_cfg.cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
  1049. } else {
  1050. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  1051. trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  1052. }
  1053. /* Configure transport layer */
  1054. iwl_trans_configure(priv->trans, &trans_cfg);
  1055. trans->rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
  1056. trans->rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_res_start);
  1057. /* At this point both hw and priv are allocated. */
  1058. SET_IEEE80211_DEV(priv->hw, priv->trans->dev);
  1059. iwl_option_config(priv);
  1060. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  1061. /* is antenna coupling more than 35dB ? */
  1062. priv->bt_ant_couple_ok =
  1063. (iwlwifi_mod_params.ant_coupling >
  1064. IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
  1065. true : false;
  1066. /* bt channel inhibition enabled*/
  1067. priv->bt_ch_announce = true;
  1068. IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n",
  1069. (priv->bt_ch_announce) ? "On" : "Off");
  1070. /* these spin locks will be used in apm_ops.init and EEPROM access
  1071. * we should init now
  1072. */
  1073. spin_lock_init(&priv->statistics.lock);
  1074. /***********************
  1075. * 2. Read REV register
  1076. ***********************/
  1077. IWL_INFO(priv, "Detected %s, REV=0x%X\n",
  1078. priv->cfg->name, priv->trans->hw_rev);
  1079. if (iwl_trans_start_hw(priv->trans))
  1080. goto out_free_hw;
  1081. /* Read the EEPROM */
  1082. if (iwl_read_eeprom(priv->trans, &priv->eeprom_blob,
  1083. &priv->eeprom_blob_size)) {
  1084. IWL_ERR(priv, "Unable to init EEPROM\n");
  1085. goto out_free_hw;
  1086. }
  1087. /* Reset chip to save power until we load uCode during "up". */
  1088. iwl_trans_stop_device(priv->trans);
  1089. priv->nvm_data = iwl_parse_eeprom_data(priv->trans->dev, priv->cfg,
  1090. priv->eeprom_blob,
  1091. priv->eeprom_blob_size);
  1092. if (!priv->nvm_data)
  1093. goto out_free_eeprom_blob;
  1094. if (iwl_nvm_check_version(priv->nvm_data, priv->trans))
  1095. goto out_free_eeprom;
  1096. if (iwl_eeprom_init_hw_params(priv))
  1097. goto out_free_eeprom;
  1098. /* extract MAC Address */
  1099. memcpy(priv->addresses[0].addr, priv->nvm_data->hw_addr, ETH_ALEN);
  1100. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
  1101. priv->hw->wiphy->addresses = priv->addresses;
  1102. priv->hw->wiphy->n_addresses = 1;
  1103. num_mac = priv->nvm_data->n_hw_addrs;
  1104. if (num_mac > 1) {
  1105. memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
  1106. ETH_ALEN);
  1107. priv->addresses[1].addr[5]++;
  1108. priv->hw->wiphy->n_addresses++;
  1109. }
  1110. /************************
  1111. * 4. Setup HW constants
  1112. ************************/
  1113. iwl_set_hw_params(priv);
  1114. if (!(priv->nvm_data->sku_cap_ipan_enable)) {
  1115. IWL_DEBUG_INFO(priv, "Your EEPROM disabled PAN\n");
  1116. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
  1117. /*
  1118. * if not PAN, then don't support P2P -- might be a uCode
  1119. * packaging bug or due to the eeprom check above
  1120. */
  1121. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  1122. trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  1123. /* Configure transport layer again*/
  1124. iwl_trans_configure(priv->trans, &trans_cfg);
  1125. }
  1126. /*******************
  1127. * 5. Setup priv
  1128. *******************/
  1129. for (i = 0; i < IWL_MAX_HW_QUEUES; i++) {
  1130. priv->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE;
  1131. if (i < IWLAGN_FIRST_AMPDU_QUEUE &&
  1132. i != IWL_DEFAULT_CMD_QUEUE_NUM &&
  1133. i != IWL_IPAN_CMD_QUEUE_NUM)
  1134. priv->queue_to_mac80211[i] = i;
  1135. atomic_set(&priv->queue_stop_count[i], 0);
  1136. }
  1137. if (iwl_init_drv(priv))
  1138. goto out_free_eeprom;
  1139. /* At this point both hw and priv are initialized. */
  1140. /********************
  1141. * 6. Setup services
  1142. ********************/
  1143. iwl_setup_deferred_work(priv);
  1144. iwl_setup_rx_handlers(priv);
  1145. iwl_power_initialize(priv);
  1146. iwl_tt_initialize(priv);
  1147. snprintf(priv->hw->wiphy->fw_version,
  1148. sizeof(priv->hw->wiphy->fw_version),
  1149. "%s", fw->fw_version);
  1150. priv->new_scan_threshold_behaviour =
  1151. !!(ucode_flags & IWL_UCODE_TLV_FLAGS_NEWSCAN);
  1152. priv->phy_calib_chain_noise_reset_cmd =
  1153. fw->ucode_capa.standard_phy_calibration_size;
  1154. priv->phy_calib_chain_noise_gain_cmd =
  1155. fw->ucode_capa.standard_phy_calibration_size + 1;
  1156. /* initialize all valid contexts */
  1157. iwl_init_context(priv, ucode_flags);
  1158. /**************************************************
  1159. * This is still part of probe() in a sense...
  1160. *
  1161. * 7. Setup and register with mac80211 and debugfs
  1162. **************************************************/
  1163. if (iwlagn_mac_setup_register(priv, &fw->ucode_capa))
  1164. goto out_destroy_workqueue;
  1165. if (iwl_dbgfs_register(priv, dbgfs_dir))
  1166. goto out_mac80211_unregister;
  1167. return op_mode;
  1168. out_mac80211_unregister:
  1169. iwlagn_mac_unregister(priv);
  1170. out_destroy_workqueue:
  1171. iwl_tt_exit(priv);
  1172. iwl_cancel_deferred_work(priv);
  1173. destroy_workqueue(priv->workqueue);
  1174. priv->workqueue = NULL;
  1175. iwl_uninit_drv(priv);
  1176. out_free_eeprom_blob:
  1177. kfree(priv->eeprom_blob);
  1178. out_free_eeprom:
  1179. iwl_free_nvm_data(priv->nvm_data);
  1180. out_free_hw:
  1181. ieee80211_free_hw(priv->hw);
  1182. out:
  1183. op_mode = NULL;
  1184. return op_mode;
  1185. }
  1186. static void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode)
  1187. {
  1188. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1189. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  1190. iwlagn_mac_unregister(priv);
  1191. iwl_tt_exit(priv);
  1192. kfree(priv->eeprom_blob);
  1193. iwl_free_nvm_data(priv->nvm_data);
  1194. /*netif_stop_queue(dev); */
  1195. flush_workqueue(priv->workqueue);
  1196. /* ieee80211_unregister_hw calls iwlagn_mac_stop, which flushes
  1197. * priv->workqueue... so we can't take down the workqueue
  1198. * until now... */
  1199. destroy_workqueue(priv->workqueue);
  1200. priv->workqueue = NULL;
  1201. iwl_uninit_drv(priv);
  1202. dev_kfree_skb(priv->beacon_skb);
  1203. iwl_trans_op_mode_leave(priv->trans);
  1204. ieee80211_free_hw(priv->hw);
  1205. }
  1206. static const char * const desc_lookup_text[] = {
  1207. "OK",
  1208. "FAIL",
  1209. "BAD_PARAM",
  1210. "BAD_CHECKSUM",
  1211. "NMI_INTERRUPT_WDG",
  1212. "SYSASSERT",
  1213. "FATAL_ERROR",
  1214. "BAD_COMMAND",
  1215. "HW_ERROR_TUNE_LOCK",
  1216. "HW_ERROR_TEMPERATURE",
  1217. "ILLEGAL_CHAN_FREQ",
  1218. "VCC_NOT_STABLE",
  1219. "FH_ERROR",
  1220. "NMI_INTERRUPT_HOST",
  1221. "NMI_INTERRUPT_ACTION_PT",
  1222. "NMI_INTERRUPT_UNKNOWN",
  1223. "UCODE_VERSION_MISMATCH",
  1224. "HW_ERROR_ABS_LOCK",
  1225. "HW_ERROR_CAL_LOCK_FAIL",
  1226. "NMI_INTERRUPT_INST_ACTION_PT",
  1227. "NMI_INTERRUPT_DATA_ACTION_PT",
  1228. "NMI_TRM_HW_ER",
  1229. "NMI_INTERRUPT_TRM",
  1230. "NMI_INTERRUPT_BREAK_POINT",
  1231. "DEBUG_0",
  1232. "DEBUG_1",
  1233. "DEBUG_2",
  1234. "DEBUG_3",
  1235. };
  1236. static struct { char *name; u8 num; } advanced_lookup[] = {
  1237. { "NMI_INTERRUPT_WDG", 0x34 },
  1238. { "SYSASSERT", 0x35 },
  1239. { "UCODE_VERSION_MISMATCH", 0x37 },
  1240. { "BAD_COMMAND", 0x38 },
  1241. { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
  1242. { "FATAL_ERROR", 0x3D },
  1243. { "NMI_TRM_HW_ERR", 0x46 },
  1244. { "NMI_INTERRUPT_TRM", 0x4C },
  1245. { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
  1246. { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
  1247. { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
  1248. { "NMI_INTERRUPT_HOST", 0x66 },
  1249. { "NMI_INTERRUPT_ACTION_PT", 0x7C },
  1250. { "NMI_INTERRUPT_UNKNOWN", 0x84 },
  1251. { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
  1252. { "ADVANCED_SYSASSERT", 0 },
  1253. };
  1254. static const char *desc_lookup(u32 num)
  1255. {
  1256. int i;
  1257. int max = ARRAY_SIZE(desc_lookup_text);
  1258. if (num < max)
  1259. return desc_lookup_text[num];
  1260. max = ARRAY_SIZE(advanced_lookup) - 1;
  1261. for (i = 0; i < max; i++) {
  1262. if (advanced_lookup[i].num == num)
  1263. break;
  1264. }
  1265. return advanced_lookup[i].name;
  1266. }
  1267. #define ERROR_START_OFFSET (1 * sizeof(u32))
  1268. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  1269. static void iwl_dump_nic_error_log(struct iwl_priv *priv)
  1270. {
  1271. struct iwl_trans *trans = priv->trans;
  1272. u32 base;
  1273. struct iwl_error_event_table table;
  1274. base = priv->device_pointers.error_event_table;
  1275. if (priv->cur_ucode == IWL_UCODE_INIT) {
  1276. if (!base)
  1277. base = priv->fw->init_errlog_ptr;
  1278. } else {
  1279. if (!base)
  1280. base = priv->fw->inst_errlog_ptr;
  1281. }
  1282. if (!iwlagn_hw_valid_rtc_data_addr(base)) {
  1283. IWL_ERR(priv,
  1284. "Not valid error log pointer 0x%08X for %s uCode\n",
  1285. base,
  1286. (priv->cur_ucode == IWL_UCODE_INIT)
  1287. ? "Init" : "RT");
  1288. return;
  1289. }
  1290. /*TODO: Update dbgfs with ISR error stats obtained below */
  1291. iwl_trans_read_mem_bytes(trans, base, &table, sizeof(table));
  1292. if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
  1293. IWL_ERR(trans, "Start IWL Error Log Dump:\n");
  1294. IWL_ERR(trans, "Status: 0x%08lX, count: %d\n",
  1295. priv->status, table.valid);
  1296. }
  1297. trace_iwlwifi_dev_ucode_error(trans->dev, table.error_id, table.tsf_low,
  1298. table.data1, table.data2, table.line,
  1299. table.blink1, table.blink2, table.ilink1,
  1300. table.ilink2, table.bcon_time, table.gp1,
  1301. table.gp2, table.gp3, table.ucode_ver,
  1302. table.hw_ver, table.brd_ver);
  1303. IWL_ERR(priv, "0x%08X | %-28s\n", table.error_id,
  1304. desc_lookup(table.error_id));
  1305. IWL_ERR(priv, "0x%08X | uPc\n", table.pc);
  1306. IWL_ERR(priv, "0x%08X | branchlink1\n", table.blink1);
  1307. IWL_ERR(priv, "0x%08X | branchlink2\n", table.blink2);
  1308. IWL_ERR(priv, "0x%08X | interruptlink1\n", table.ilink1);
  1309. IWL_ERR(priv, "0x%08X | interruptlink2\n", table.ilink2);
  1310. IWL_ERR(priv, "0x%08X | data1\n", table.data1);
  1311. IWL_ERR(priv, "0x%08X | data2\n", table.data2);
  1312. IWL_ERR(priv, "0x%08X | line\n", table.line);
  1313. IWL_ERR(priv, "0x%08X | beacon time\n", table.bcon_time);
  1314. IWL_ERR(priv, "0x%08X | tsf low\n", table.tsf_low);
  1315. IWL_ERR(priv, "0x%08X | tsf hi\n", table.tsf_hi);
  1316. IWL_ERR(priv, "0x%08X | time gp1\n", table.gp1);
  1317. IWL_ERR(priv, "0x%08X | time gp2\n", table.gp2);
  1318. IWL_ERR(priv, "0x%08X | time gp3\n", table.gp3);
  1319. IWL_ERR(priv, "0x%08X | uCode version\n", table.ucode_ver);
  1320. IWL_ERR(priv, "0x%08X | hw version\n", table.hw_ver);
  1321. IWL_ERR(priv, "0x%08X | board version\n", table.brd_ver);
  1322. IWL_ERR(priv, "0x%08X | hcmd\n", table.hcmd);
  1323. IWL_ERR(priv, "0x%08X | isr0\n", table.isr0);
  1324. IWL_ERR(priv, "0x%08X | isr1\n", table.isr1);
  1325. IWL_ERR(priv, "0x%08X | isr2\n", table.isr2);
  1326. IWL_ERR(priv, "0x%08X | isr3\n", table.isr3);
  1327. IWL_ERR(priv, "0x%08X | isr4\n", table.isr4);
  1328. IWL_ERR(priv, "0x%08X | isr_pref\n", table.isr_pref);
  1329. IWL_ERR(priv, "0x%08X | wait_event\n", table.wait_event);
  1330. IWL_ERR(priv, "0x%08X | l2p_control\n", table.l2p_control);
  1331. IWL_ERR(priv, "0x%08X | l2p_duration\n", table.l2p_duration);
  1332. IWL_ERR(priv, "0x%08X | l2p_mhvalid\n", table.l2p_mhvalid);
  1333. IWL_ERR(priv, "0x%08X | l2p_addr_match\n", table.l2p_addr_match);
  1334. IWL_ERR(priv, "0x%08X | lmpm_pmg_sel\n", table.lmpm_pmg_sel);
  1335. IWL_ERR(priv, "0x%08X | timestamp\n", table.u_timestamp);
  1336. IWL_ERR(priv, "0x%08X | flow_handler\n", table.flow_handler);
  1337. }
  1338. #define EVENT_START_OFFSET (4 * sizeof(u32))
  1339. /**
  1340. * iwl_print_event_log - Dump error event log to syslog
  1341. *
  1342. */
  1343. static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
  1344. u32 num_events, u32 mode,
  1345. int pos, char **buf, size_t bufsz)
  1346. {
  1347. u32 i;
  1348. u32 base; /* SRAM byte address of event log header */
  1349. u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
  1350. u32 ptr; /* SRAM byte address of log data */
  1351. u32 ev, time, data; /* event log data */
  1352. unsigned long reg_flags;
  1353. struct iwl_trans *trans = priv->trans;
  1354. if (num_events == 0)
  1355. return pos;
  1356. base = priv->device_pointers.log_event_table;
  1357. if (priv->cur_ucode == IWL_UCODE_INIT) {
  1358. if (!base)
  1359. base = priv->fw->init_evtlog_ptr;
  1360. } else {
  1361. if (!base)
  1362. base = priv->fw->inst_evtlog_ptr;
  1363. }
  1364. if (mode == 0)
  1365. event_size = 2 * sizeof(u32);
  1366. else
  1367. event_size = 3 * sizeof(u32);
  1368. ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
  1369. /* Make sure device is powered up for SRAM reads */
  1370. if (!iwl_trans_grab_nic_access(trans, false, &reg_flags))
  1371. return pos;
  1372. /* Set starting address; reads will auto-increment */
  1373. iwl_write32(trans, HBUS_TARG_MEM_RADDR, ptr);
  1374. /* "time" is actually "data" for mode 0 (no timestamp).
  1375. * place event id # at far right for easier visual parsing. */
  1376. for (i = 0; i < num_events; i++) {
  1377. ev = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
  1378. time = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
  1379. if (mode == 0) {
  1380. /* data, ev */
  1381. if (bufsz) {
  1382. pos += scnprintf(*buf + pos, bufsz - pos,
  1383. "EVT_LOG:0x%08x:%04u\n",
  1384. time, ev);
  1385. } else {
  1386. trace_iwlwifi_dev_ucode_event(trans->dev, 0,
  1387. time, ev);
  1388. IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n",
  1389. time, ev);
  1390. }
  1391. } else {
  1392. data = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
  1393. if (bufsz) {
  1394. pos += scnprintf(*buf + pos, bufsz - pos,
  1395. "EVT_LOGT:%010u:0x%08x:%04u\n",
  1396. time, data, ev);
  1397. } else {
  1398. IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
  1399. time, data, ev);
  1400. trace_iwlwifi_dev_ucode_event(trans->dev, time,
  1401. data, ev);
  1402. }
  1403. }
  1404. }
  1405. /* Allow device to power down */
  1406. iwl_trans_release_nic_access(trans, &reg_flags);
  1407. return pos;
  1408. }
  1409. /**
  1410. * iwl_print_last_event_logs - Dump the newest # of event log to syslog
  1411. */
  1412. static int iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
  1413. u32 num_wraps, u32 next_entry,
  1414. u32 size, u32 mode,
  1415. int pos, char **buf, size_t bufsz)
  1416. {
  1417. /*
  1418. * display the newest DEFAULT_LOG_ENTRIES entries
  1419. * i.e the entries just before the next ont that uCode would fill.
  1420. */
  1421. if (num_wraps) {
  1422. if (next_entry < size) {
  1423. pos = iwl_print_event_log(priv,
  1424. capacity - (size - next_entry),
  1425. size - next_entry, mode,
  1426. pos, buf, bufsz);
  1427. pos = iwl_print_event_log(priv, 0,
  1428. next_entry, mode,
  1429. pos, buf, bufsz);
  1430. } else
  1431. pos = iwl_print_event_log(priv, next_entry - size,
  1432. size, mode, pos, buf, bufsz);
  1433. } else {
  1434. if (next_entry < size) {
  1435. pos = iwl_print_event_log(priv, 0, next_entry,
  1436. mode, pos, buf, bufsz);
  1437. } else {
  1438. pos = iwl_print_event_log(priv, next_entry - size,
  1439. size, mode, pos, buf, bufsz);
  1440. }
  1441. }
  1442. return pos;
  1443. }
  1444. #define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
  1445. int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
  1446. char **buf)
  1447. {
  1448. u32 base; /* SRAM byte address of event log header */
  1449. u32 capacity; /* event log capacity in # entries */
  1450. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  1451. u32 num_wraps; /* # times uCode wrapped to top of log */
  1452. u32 next_entry; /* index of next entry to be written by uCode */
  1453. u32 size; /* # entries that we'll print */
  1454. u32 logsize;
  1455. int pos = 0;
  1456. size_t bufsz = 0;
  1457. struct iwl_trans *trans = priv->trans;
  1458. base = priv->device_pointers.log_event_table;
  1459. if (priv->cur_ucode == IWL_UCODE_INIT) {
  1460. logsize = priv->fw->init_evtlog_size;
  1461. if (!base)
  1462. base = priv->fw->init_evtlog_ptr;
  1463. } else {
  1464. logsize = priv->fw->inst_evtlog_size;
  1465. if (!base)
  1466. base = priv->fw->inst_evtlog_ptr;
  1467. }
  1468. if (!iwlagn_hw_valid_rtc_data_addr(base)) {
  1469. IWL_ERR(priv,
  1470. "Invalid event log pointer 0x%08X for %s uCode\n",
  1471. base,
  1472. (priv->cur_ucode == IWL_UCODE_INIT)
  1473. ? "Init" : "RT");
  1474. return -EINVAL;
  1475. }
  1476. /* event log header */
  1477. capacity = iwl_trans_read_mem32(trans, base);
  1478. mode = iwl_trans_read_mem32(trans, base + (1 * sizeof(u32)));
  1479. num_wraps = iwl_trans_read_mem32(trans, base + (2 * sizeof(u32)));
  1480. next_entry = iwl_trans_read_mem32(trans, base + (3 * sizeof(u32)));
  1481. if (capacity > logsize) {
  1482. IWL_ERR(priv, "Log capacity %d is bogus, limit to %d "
  1483. "entries\n", capacity, logsize);
  1484. capacity = logsize;
  1485. }
  1486. if (next_entry > logsize) {
  1487. IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
  1488. next_entry, logsize);
  1489. next_entry = logsize;
  1490. }
  1491. size = num_wraps ? capacity : next_entry;
  1492. /* bail out if nothing in log */
  1493. if (size == 0) {
  1494. IWL_ERR(trans, "Start IWL Event Log Dump: nothing in log\n");
  1495. return pos;
  1496. }
  1497. if (!(iwl_have_debug_level(IWL_DL_FW_ERRORS)) && !full_log)
  1498. size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
  1499. ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
  1500. IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n",
  1501. size);
  1502. #ifdef CONFIG_IWLWIFI_DEBUG
  1503. if (buf) {
  1504. if (full_log)
  1505. bufsz = capacity * 48;
  1506. else
  1507. bufsz = size * 48;
  1508. *buf = kmalloc(bufsz, GFP_KERNEL);
  1509. if (!*buf)
  1510. return -ENOMEM;
  1511. }
  1512. if (iwl_have_debug_level(IWL_DL_FW_ERRORS) || full_log) {
  1513. /*
  1514. * if uCode has wrapped back to top of log,
  1515. * start at the oldest entry,
  1516. * i.e the next one that uCode would fill.
  1517. */
  1518. if (num_wraps)
  1519. pos = iwl_print_event_log(priv, next_entry,
  1520. capacity - next_entry, mode,
  1521. pos, buf, bufsz);
  1522. /* (then/else) start at top of log */
  1523. pos = iwl_print_event_log(priv, 0,
  1524. next_entry, mode, pos, buf, bufsz);
  1525. } else
  1526. pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
  1527. next_entry, size, mode,
  1528. pos, buf, bufsz);
  1529. #else
  1530. pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
  1531. next_entry, size, mode,
  1532. pos, buf, bufsz);
  1533. #endif
  1534. return pos;
  1535. }
  1536. static void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand)
  1537. {
  1538. unsigned int reload_msec;
  1539. unsigned long reload_jiffies;
  1540. if (iwl_have_debug_level(IWL_DL_FW_ERRORS))
  1541. iwl_print_rx_config_cmd(priv, IWL_RXON_CTX_BSS);
  1542. /* uCode is no longer loaded. */
  1543. priv->ucode_loaded = false;
  1544. /* Set the FW error flag -- cleared on iwl_down */
  1545. set_bit(STATUS_FW_ERROR, &priv->status);
  1546. iwl_abort_notification_waits(&priv->notif_wait);
  1547. /* Keep the restart process from trying to send host
  1548. * commands by clearing the ready bit */
  1549. clear_bit(STATUS_READY, &priv->status);
  1550. if (!ondemand) {
  1551. /*
  1552. * If firmware keep reloading, then it indicate something
  1553. * serious wrong and firmware having problem to recover
  1554. * from it. Instead of keep trying which will fill the syslog
  1555. * and hang the system, let's just stop it
  1556. */
  1557. reload_jiffies = jiffies;
  1558. reload_msec = jiffies_to_msecs((long) reload_jiffies -
  1559. (long) priv->reload_jiffies);
  1560. priv->reload_jiffies = reload_jiffies;
  1561. if (reload_msec <= IWL_MIN_RELOAD_DURATION) {
  1562. priv->reload_count++;
  1563. if (priv->reload_count >= IWL_MAX_CONTINUE_RELOAD_CNT) {
  1564. IWL_ERR(priv, "BUG_ON, Stop restarting\n");
  1565. return;
  1566. }
  1567. } else
  1568. priv->reload_count = 0;
  1569. }
  1570. if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  1571. if (iwlwifi_mod_params.restart_fw) {
  1572. IWL_DEBUG_FW_ERRORS(priv,
  1573. "Restarting adapter due to uCode error.\n");
  1574. queue_work(priv->workqueue, &priv->restart);
  1575. } else
  1576. IWL_DEBUG_FW_ERRORS(priv,
  1577. "Detected FW error, but not restarting\n");
  1578. }
  1579. }
  1580. static void iwl_nic_error(struct iwl_op_mode *op_mode)
  1581. {
  1582. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1583. IWL_ERR(priv, "Loaded firmware version: %s\n",
  1584. priv->fw->fw_version);
  1585. iwl_dump_nic_error_log(priv);
  1586. iwl_dump_nic_event_log(priv, false, NULL);
  1587. iwlagn_fw_error(priv, false);
  1588. }
  1589. static void iwl_cmd_queue_full(struct iwl_op_mode *op_mode)
  1590. {
  1591. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1592. if (!iwl_check_for_ct_kill(priv)) {
  1593. IWL_ERR(priv, "Restarting adapter queue is full\n");
  1594. iwlagn_fw_error(priv, false);
  1595. }
  1596. }
  1597. #define EEPROM_RF_CONFIG_TYPE_MAX 0x3
  1598. static void iwl_nic_config(struct iwl_op_mode *op_mode)
  1599. {
  1600. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1601. /* SKU Control */
  1602. iwl_trans_set_bits_mask(priv->trans, CSR_HW_IF_CONFIG_REG,
  1603. CSR_HW_IF_CONFIG_REG_MSK_MAC_DASH |
  1604. CSR_HW_IF_CONFIG_REG_MSK_MAC_STEP,
  1605. (CSR_HW_REV_STEP(priv->trans->hw_rev) <<
  1606. CSR_HW_IF_CONFIG_REG_POS_MAC_STEP) |
  1607. (CSR_HW_REV_DASH(priv->trans->hw_rev) <<
  1608. CSR_HW_IF_CONFIG_REG_POS_MAC_DASH));
  1609. /* write radio config values to register */
  1610. if (priv->nvm_data->radio_cfg_type <= EEPROM_RF_CONFIG_TYPE_MAX) {
  1611. u32 reg_val =
  1612. priv->nvm_data->radio_cfg_type <<
  1613. CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE |
  1614. priv->nvm_data->radio_cfg_step <<
  1615. CSR_HW_IF_CONFIG_REG_POS_PHY_STEP |
  1616. priv->nvm_data->radio_cfg_dash <<
  1617. CSR_HW_IF_CONFIG_REG_POS_PHY_DASH;
  1618. iwl_trans_set_bits_mask(priv->trans, CSR_HW_IF_CONFIG_REG,
  1619. CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE |
  1620. CSR_HW_IF_CONFIG_REG_MSK_PHY_STEP |
  1621. CSR_HW_IF_CONFIG_REG_MSK_PHY_DASH,
  1622. reg_val);
  1623. IWL_INFO(priv, "Radio type=0x%x-0x%x-0x%x\n",
  1624. priv->nvm_data->radio_cfg_type,
  1625. priv->nvm_data->radio_cfg_step,
  1626. priv->nvm_data->radio_cfg_dash);
  1627. } else {
  1628. WARN_ON(1);
  1629. }
  1630. /* set CSR_HW_CONFIG_REG for uCode use */
  1631. iwl_set_bit(priv->trans, CSR_HW_IF_CONFIG_REG,
  1632. CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
  1633. CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
  1634. /* W/A : NIC is stuck in a reset state after Early PCIe power off
  1635. * (PCIe power is lost before PERST# is asserted),
  1636. * causing ME FW to lose ownership and not being able to obtain it back.
  1637. */
  1638. iwl_set_bits_mask_prph(priv->trans, APMG_PS_CTRL_REG,
  1639. APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
  1640. ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
  1641. if (priv->lib->nic_config)
  1642. priv->lib->nic_config(priv);
  1643. }
  1644. static void iwl_wimax_active(struct iwl_op_mode *op_mode)
  1645. {
  1646. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1647. clear_bit(STATUS_READY, &priv->status);
  1648. IWL_ERR(priv, "RF is used by WiMAX\n");
  1649. }
  1650. static void iwl_stop_sw_queue(struct iwl_op_mode *op_mode, int queue)
  1651. {
  1652. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1653. int mq = priv->queue_to_mac80211[queue];
  1654. if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE))
  1655. return;
  1656. if (atomic_inc_return(&priv->queue_stop_count[mq]) > 1) {
  1657. IWL_DEBUG_TX_QUEUES(priv,
  1658. "queue %d (mac80211 %d) already stopped\n",
  1659. queue, mq);
  1660. return;
  1661. }
  1662. set_bit(mq, &priv->transport_queue_stop);
  1663. ieee80211_stop_queue(priv->hw, mq);
  1664. }
  1665. static void iwl_wake_sw_queue(struct iwl_op_mode *op_mode, int queue)
  1666. {
  1667. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1668. int mq = priv->queue_to_mac80211[queue];
  1669. if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE))
  1670. return;
  1671. if (atomic_dec_return(&priv->queue_stop_count[mq]) > 0) {
  1672. IWL_DEBUG_TX_QUEUES(priv,
  1673. "queue %d (mac80211 %d) already awake\n",
  1674. queue, mq);
  1675. return;
  1676. }
  1677. clear_bit(mq, &priv->transport_queue_stop);
  1678. if (!priv->passive_no_rx)
  1679. ieee80211_wake_queue(priv->hw, mq);
  1680. }
  1681. void iwlagn_lift_passive_no_rx(struct iwl_priv *priv)
  1682. {
  1683. int mq;
  1684. if (!priv->passive_no_rx)
  1685. return;
  1686. for (mq = 0; mq < IWLAGN_FIRST_AMPDU_QUEUE; mq++) {
  1687. if (!test_bit(mq, &priv->transport_queue_stop)) {
  1688. IWL_DEBUG_TX_QUEUES(priv, "Wake queue %d\n", mq);
  1689. ieee80211_wake_queue(priv->hw, mq);
  1690. } else {
  1691. IWL_DEBUG_TX_QUEUES(priv, "Don't wake queue %d\n", mq);
  1692. }
  1693. }
  1694. priv->passive_no_rx = false;
  1695. }
  1696. static void iwl_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)
  1697. {
  1698. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1699. struct ieee80211_tx_info *info;
  1700. info = IEEE80211_SKB_CB(skb);
  1701. iwl_trans_free_tx_cmd(priv->trans, info->driver_data[1]);
  1702. ieee80211_free_txskb(priv->hw, skb);
  1703. }
  1704. static bool iwl_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
  1705. {
  1706. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1707. if (state)
  1708. set_bit(STATUS_RF_KILL_HW, &priv->status);
  1709. else
  1710. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  1711. wiphy_rfkill_set_hw_state(priv->hw->wiphy, state);
  1712. return false;
  1713. }
  1714. static void iwl_napi_add(struct iwl_op_mode *op_mode,
  1715. struct napi_struct *napi,
  1716. struct net_device *napi_dev,
  1717. int (*poll)(struct napi_struct *, int),
  1718. int weight)
  1719. {
  1720. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1721. ieee80211_napi_add(priv->hw, napi, napi_dev, poll, weight);
  1722. }
  1723. static const struct iwl_op_mode_ops iwl_dvm_ops = {
  1724. .start = iwl_op_mode_dvm_start,
  1725. .stop = iwl_op_mode_dvm_stop,
  1726. .rx = iwl_rx_dispatch,
  1727. .queue_full = iwl_stop_sw_queue,
  1728. .queue_not_full = iwl_wake_sw_queue,
  1729. .hw_rf_kill = iwl_set_hw_rfkill_state,
  1730. .free_skb = iwl_free_skb,
  1731. .nic_error = iwl_nic_error,
  1732. .cmd_queue_full = iwl_cmd_queue_full,
  1733. .nic_config = iwl_nic_config,
  1734. .wimax_active = iwl_wimax_active,
  1735. .napi_add = iwl_napi_add,
  1736. };
  1737. /*****************************************************************************
  1738. *
  1739. * driver and module entry point
  1740. *
  1741. *****************************************************************************/
  1742. static int __init iwl_init(void)
  1743. {
  1744. int ret;
  1745. ret = iwlagn_rate_control_register();
  1746. if (ret) {
  1747. pr_err("Unable to register rate control algorithm: %d\n", ret);
  1748. return ret;
  1749. }
  1750. ret = iwl_opmode_register("iwldvm", &iwl_dvm_ops);
  1751. if (ret) {
  1752. pr_err("Unable to register op_mode: %d\n", ret);
  1753. iwlagn_rate_control_unregister();
  1754. }
  1755. return ret;
  1756. }
  1757. module_init(iwl_init);
  1758. static void __exit iwl_exit(void)
  1759. {
  1760. iwl_opmode_deregister("iwldvm");
  1761. iwlagn_rate_control_unregister();
  1762. }
  1763. module_exit(iwl_exit);