main.c 58 KB

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