iwl-agn.c 65 KB

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