iwl-agn.c 68 KB

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