iwl-agn.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629
  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->shrd->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. static void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags)
  414. {
  415. int i;
  416. /*
  417. * The default context is always valid,
  418. * the PAN context depends on uCode.
  419. */
  420. priv->shrd->valid_contexts = BIT(IWL_RXON_CTX_BSS);
  421. if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN)
  422. priv->shrd->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
  423. for (i = 0; i < NUM_IWL_RXON_CTX; i++)
  424. priv->contexts[i].ctxid = i;
  425. priv->contexts[IWL_RXON_CTX_BSS].always_active = true;
  426. priv->contexts[IWL_RXON_CTX_BSS].is_active = true;
  427. priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
  428. priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
  429. priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
  430. priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
  431. priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
  432. priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
  433. priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
  434. priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
  435. BIT(NL80211_IFTYPE_ADHOC);
  436. priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
  437. BIT(NL80211_IFTYPE_STATION);
  438. priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP;
  439. priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
  440. priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
  441. priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
  442. priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON;
  443. priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd =
  444. REPLY_WIPAN_RXON_TIMING;
  445. priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd =
  446. REPLY_WIPAN_RXON_ASSOC;
  447. priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM;
  448. priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN;
  449. priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY;
  450. priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID;
  451. priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION;
  452. priv->contexts[IWL_RXON_CTX_PAN].interface_modes =
  453. BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
  454. if (ucode_flags & IWL_UCODE_TLV_FLAGS_P2P)
  455. priv->contexts[IWL_RXON_CTX_PAN].interface_modes |=
  456. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  457. BIT(NL80211_IFTYPE_P2P_GO);
  458. priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP;
  459. priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA;
  460. priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P;
  461. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  462. }
  463. static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
  464. {
  465. struct iwl_ct_kill_config cmd;
  466. struct iwl_ct_kill_throttling_config adv_cmd;
  467. int ret = 0;
  468. iwl_write32(trans(priv), CSR_UCODE_DRV_GP1_CLR,
  469. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  470. priv->thermal_throttle.ct_kill_toggle = false;
  471. if (cfg(priv)->base_params->support_ct_kill_exit) {
  472. adv_cmd.critical_temperature_enter =
  473. cpu_to_le32(hw_params(priv).ct_kill_threshold);
  474. adv_cmd.critical_temperature_exit =
  475. cpu_to_le32(hw_params(priv).ct_kill_exit_threshold);
  476. ret = iwl_dvm_send_cmd_pdu(priv,
  477. REPLY_CT_KILL_CONFIG_CMD,
  478. CMD_SYNC, sizeof(adv_cmd), &adv_cmd);
  479. if (ret)
  480. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  481. else
  482. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  483. "succeeded, critical temperature enter is %d,"
  484. "exit is %d\n",
  485. hw_params(priv).ct_kill_threshold,
  486. hw_params(priv).ct_kill_exit_threshold);
  487. } else {
  488. cmd.critical_temperature_R =
  489. cpu_to_le32(hw_params(priv).ct_kill_threshold);
  490. ret = iwl_dvm_send_cmd_pdu(priv,
  491. REPLY_CT_KILL_CONFIG_CMD,
  492. CMD_SYNC, sizeof(cmd), &cmd);
  493. if (ret)
  494. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  495. else
  496. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  497. "succeeded, "
  498. "critical temperature is %d\n",
  499. hw_params(priv).ct_kill_threshold);
  500. }
  501. }
  502. static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
  503. {
  504. struct iwl_calib_cfg_cmd calib_cfg_cmd;
  505. struct iwl_host_cmd cmd = {
  506. .id = CALIBRATION_CFG_CMD,
  507. .len = { sizeof(struct iwl_calib_cfg_cmd), },
  508. .data = { &calib_cfg_cmd, },
  509. };
  510. memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
  511. calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_RT_CFG_ALL;
  512. calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg);
  513. return iwl_dvm_send_cmd(priv, &cmd);
  514. }
  515. static int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant)
  516. {
  517. struct iwl_tx_ant_config_cmd tx_ant_cmd = {
  518. .valid = cpu_to_le32(valid_tx_ant),
  519. };
  520. if (IWL_UCODE_API(priv->fw->ucode_ver) > 1) {
  521. IWL_DEBUG_HC(priv, "select valid tx ant: %u\n", valid_tx_ant);
  522. return iwl_dvm_send_cmd_pdu(priv,
  523. TX_ANT_CONFIGURATION_CMD,
  524. CMD_SYNC,
  525. sizeof(struct iwl_tx_ant_config_cmd),
  526. &tx_ant_cmd);
  527. } else {
  528. IWL_DEBUG_HC(priv, "TX_ANT_CONFIGURATION_CMD not supported\n");
  529. return -EOPNOTSUPP;
  530. }
  531. }
  532. /**
  533. * iwl_alive_start - called after REPLY_ALIVE notification received
  534. * from protocol/runtime uCode (initialization uCode's
  535. * Alive gets handled by iwl_init_alive_start()).
  536. */
  537. int iwl_alive_start(struct iwl_priv *priv)
  538. {
  539. int ret = 0;
  540. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  541. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  542. /* After the ALIVE response, we can send host commands to the uCode */
  543. set_bit(STATUS_ALIVE, &priv->status);
  544. /* Enable watchdog to monitor the driver tx queues */
  545. iwl_setup_watchdog(priv);
  546. if (iwl_is_rfkill(priv))
  547. return -ERFKILL;
  548. if (priv->event_log.ucode_trace) {
  549. /* start collecting data now */
  550. mod_timer(&priv->ucode_trace, jiffies);
  551. }
  552. /* download priority table before any calibration request */
  553. if (cfg(priv)->bt_params &&
  554. cfg(priv)->bt_params->advanced_bt_coexist) {
  555. /* Configure Bluetooth device coexistence support */
  556. if (cfg(priv)->bt_params->bt_sco_disable)
  557. priv->bt_enable_pspoll = false;
  558. else
  559. priv->bt_enable_pspoll = true;
  560. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  561. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  562. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  563. iwlagn_send_advance_bt_config(priv);
  564. priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS;
  565. priv->cur_rssi_ctx = NULL;
  566. iwl_send_prio_tbl(priv);
  567. /* FIXME: w/a to force change uCode BT state machine */
  568. ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
  569. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  570. if (ret)
  571. return ret;
  572. ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
  573. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  574. if (ret)
  575. return ret;
  576. } else {
  577. /*
  578. * default is 2-wire BT coexexistence support
  579. */
  580. iwl_send_bt_config(priv);
  581. }
  582. /*
  583. * Perform runtime calibrations, including DC calibration.
  584. */
  585. iwlagn_send_calib_cfg_rt(priv, IWL_CALIB_CFG_DC_IDX);
  586. ieee80211_wake_queues(priv->hw);
  587. priv->active_rate = IWL_RATES_MASK;
  588. /* Configure Tx antenna selection based on H/W config */
  589. iwlagn_send_tx_ant_config(priv, hw_params(priv).valid_tx_ant);
  590. if (iwl_is_associated_ctx(ctx) && !priv->wowlan) {
  591. struct iwl_rxon_cmd *active_rxon =
  592. (struct iwl_rxon_cmd *)&ctx->active;
  593. /* apply any changes in staging */
  594. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  595. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  596. } else {
  597. struct iwl_rxon_context *tmp;
  598. /* Initialize our rx_config data */
  599. for_each_context(priv, tmp)
  600. iwl_connection_init_rx_config(priv, tmp);
  601. iwlagn_set_rxon_chain(priv, ctx);
  602. }
  603. if (!priv->wowlan) {
  604. /* WoWLAN ucode will not reply in the same way, skip it */
  605. iwl_reset_run_time_calib(priv);
  606. }
  607. set_bit(STATUS_READY, &priv->status);
  608. /* Configure the adapter for unassociated operation */
  609. ret = iwlagn_commit_rxon(priv, ctx);
  610. if (ret)
  611. return ret;
  612. /* At this point, the NIC is initialized and operational */
  613. iwl_rf_kill_ct_config(priv);
  614. IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
  615. return iwl_power_update_mode(priv, true);
  616. }
  617. /**
  618. * iwl_clear_driver_stations - clear knowledge of all stations from driver
  619. * @priv: iwl priv struct
  620. *
  621. * This is called during iwl_down() to make sure that in the case
  622. * we're coming there from a hardware restart mac80211 will be
  623. * able to reconfigure stations -- if we're getting there in the
  624. * normal down flow then the stations will already be cleared.
  625. */
  626. static void iwl_clear_driver_stations(struct iwl_priv *priv)
  627. {
  628. struct iwl_rxon_context *ctx;
  629. spin_lock_bh(&priv->sta_lock);
  630. memset(priv->stations, 0, sizeof(priv->stations));
  631. priv->num_stations = 0;
  632. priv->ucode_key_table = 0;
  633. for_each_context(priv, ctx) {
  634. /*
  635. * Remove all key information that is not stored as part
  636. * of station information since mac80211 may not have had
  637. * a chance to remove all the keys. When device is
  638. * reconfigured by mac80211 after an error all keys will
  639. * be reconfigured.
  640. */
  641. memset(ctx->wep_keys, 0, sizeof(ctx->wep_keys));
  642. ctx->key_mapping_keys = 0;
  643. }
  644. spin_unlock_bh(&priv->sta_lock);
  645. }
  646. void iwl_down(struct iwl_priv *priv)
  647. {
  648. int exit_pending;
  649. IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
  650. lockdep_assert_held(&priv->mutex);
  651. iwl_scan_cancel_timeout(priv, 200);
  652. /*
  653. * If active, scanning won't cancel it, so say it expired.
  654. * No race since we hold the mutex here and a new one
  655. * can't come in at this time.
  656. */
  657. ieee80211_remain_on_channel_expired(priv->hw);
  658. exit_pending =
  659. test_and_set_bit(STATUS_EXIT_PENDING, &priv->status);
  660. /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
  661. * to prevent rearm timer */
  662. del_timer_sync(&priv->watchdog);
  663. iwl_clear_ucode_stations(priv, NULL);
  664. iwl_dealloc_bcast_stations(priv);
  665. iwl_clear_driver_stations(priv);
  666. /* reset BT coex data */
  667. priv->bt_status = 0;
  668. priv->cur_rssi_ctx = NULL;
  669. priv->bt_is_sco = 0;
  670. if (cfg(priv)->bt_params)
  671. priv->bt_traffic_load =
  672. cfg(priv)->bt_params->bt_init_traffic_load;
  673. else
  674. priv->bt_traffic_load = 0;
  675. priv->bt_full_concurrent = false;
  676. priv->bt_ci_compliance = 0;
  677. /* Wipe out the EXIT_PENDING status bit if we are not actually
  678. * exiting the module */
  679. if (!exit_pending)
  680. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  681. if (priv->mac80211_registered)
  682. ieee80211_stop_queues(priv->hw);
  683. iwl_trans_stop_device(trans(priv));
  684. /* Clear out all status bits but a few that are stable across reset */
  685. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  686. STATUS_RF_KILL_HW |
  687. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  688. STATUS_GEO_CONFIGURED |
  689. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  690. STATUS_EXIT_PENDING;
  691. priv->shrd->status &=
  692. test_bit(STATUS_FW_ERROR, &priv->shrd->status) <<
  693. STATUS_FW_ERROR;
  694. dev_kfree_skb(priv->beacon_skb);
  695. priv->beacon_skb = NULL;
  696. }
  697. /*****************************************************************************
  698. *
  699. * Workqueue callbacks
  700. *
  701. *****************************************************************************/
  702. static void iwl_bg_run_time_calib_work(struct work_struct *work)
  703. {
  704. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  705. run_time_calib_work);
  706. mutex_lock(&priv->mutex);
  707. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  708. test_bit(STATUS_SCANNING, &priv->status)) {
  709. mutex_unlock(&priv->mutex);
  710. return;
  711. }
  712. if (priv->start_calib) {
  713. iwl_chain_noise_calibration(priv);
  714. iwl_sensitivity_calibration(priv);
  715. }
  716. mutex_unlock(&priv->mutex);
  717. }
  718. void iwlagn_prepare_restart(struct iwl_priv *priv)
  719. {
  720. struct iwl_rxon_context *ctx;
  721. bool bt_full_concurrent;
  722. u8 bt_ci_compliance;
  723. u8 bt_load;
  724. u8 bt_status;
  725. bool bt_is_sco;
  726. lockdep_assert_held(&priv->mutex);
  727. for_each_context(priv, ctx)
  728. ctx->vif = NULL;
  729. priv->is_open = 0;
  730. /*
  731. * __iwl_down() will clear the BT status variables,
  732. * which is correct, but when we restart we really
  733. * want to keep them so restore them afterwards.
  734. *
  735. * The restart process will later pick them up and
  736. * re-configure the hw when we reconfigure the BT
  737. * command.
  738. */
  739. bt_full_concurrent = priv->bt_full_concurrent;
  740. bt_ci_compliance = priv->bt_ci_compliance;
  741. bt_load = priv->bt_traffic_load;
  742. bt_status = priv->bt_status;
  743. bt_is_sco = priv->bt_is_sco;
  744. iwl_down(priv);
  745. priv->bt_full_concurrent = bt_full_concurrent;
  746. priv->bt_ci_compliance = bt_ci_compliance;
  747. priv->bt_traffic_load = bt_load;
  748. priv->bt_status = bt_status;
  749. priv->bt_is_sco = bt_is_sco;
  750. }
  751. static void iwl_bg_restart(struct work_struct *data)
  752. {
  753. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  754. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  755. return;
  756. if (test_and_clear_bit(STATUS_FW_ERROR, &priv->shrd->status)) {
  757. mutex_lock(&priv->mutex);
  758. iwlagn_prepare_restart(priv);
  759. mutex_unlock(&priv->mutex);
  760. iwl_cancel_deferred_work(priv);
  761. ieee80211_restart_hw(priv->hw);
  762. } else {
  763. WARN_ON(1);
  764. }
  765. }
  766. void iwlagn_disable_roc(struct iwl_priv *priv)
  767. {
  768. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
  769. lockdep_assert_held(&priv->mutex);
  770. if (!priv->hw_roc_setup)
  771. return;
  772. ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
  773. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  774. priv->hw_roc_channel = NULL;
  775. memset(ctx->staging.node_addr, 0, ETH_ALEN);
  776. iwlagn_commit_rxon(priv, ctx);
  777. ctx->is_active = false;
  778. priv->hw_roc_setup = false;
  779. }
  780. static void iwlagn_disable_roc_work(struct work_struct *work)
  781. {
  782. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  783. hw_roc_disable_work.work);
  784. mutex_lock(&priv->mutex);
  785. iwlagn_disable_roc(priv);
  786. mutex_unlock(&priv->mutex);
  787. }
  788. /*****************************************************************************
  789. *
  790. * driver setup and teardown
  791. *
  792. *****************************************************************************/
  793. static void iwl_setup_deferred_work(struct iwl_priv *priv)
  794. {
  795. priv->workqueue = create_singlethread_workqueue(DRV_NAME);
  796. init_waitqueue_head(&priv->shrd->wait_command_queue);
  797. INIT_WORK(&priv->restart, iwl_bg_restart);
  798. INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
  799. INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
  800. INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
  801. INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
  802. INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
  803. INIT_DELAYED_WORK(&priv->hw_roc_disable_work,
  804. iwlagn_disable_roc_work);
  805. iwl_setup_scan_deferred_work(priv);
  806. if (cfg(priv)->bt_params)
  807. iwlagn_bt_setup_deferred_work(priv);
  808. init_timer(&priv->statistics_periodic);
  809. priv->statistics_periodic.data = (unsigned long)priv;
  810. priv->statistics_periodic.function = iwl_bg_statistics_periodic;
  811. init_timer(&priv->ucode_trace);
  812. priv->ucode_trace.data = (unsigned long)priv;
  813. priv->ucode_trace.function = iwl_bg_ucode_trace;
  814. init_timer(&priv->watchdog);
  815. priv->watchdog.data = (unsigned long)priv;
  816. priv->watchdog.function = iwl_bg_watchdog;
  817. }
  818. void iwl_cancel_deferred_work(struct iwl_priv *priv)
  819. {
  820. if (cfg(priv)->bt_params)
  821. iwlagn_bt_cancel_deferred_work(priv);
  822. cancel_work_sync(&priv->run_time_calib_work);
  823. cancel_work_sync(&priv->beacon_update);
  824. iwl_cancel_scan_deferred_work(priv);
  825. cancel_work_sync(&priv->bt_full_concurrency);
  826. cancel_work_sync(&priv->bt_runtime_config);
  827. cancel_delayed_work_sync(&priv->hw_roc_disable_work);
  828. del_timer_sync(&priv->statistics_periodic);
  829. del_timer_sync(&priv->ucode_trace);
  830. }
  831. static void iwl_init_hw_rates(struct ieee80211_rate *rates)
  832. {
  833. int i;
  834. for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
  835. rates[i].bitrate = iwl_rates[i].ieee * 5;
  836. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  837. rates[i].hw_value_short = i;
  838. rates[i].flags = 0;
  839. if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
  840. /*
  841. * If CCK != 1M then set short preamble rate flag.
  842. */
  843. rates[i].flags |=
  844. (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
  845. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  846. }
  847. }
  848. }
  849. static int iwl_init_drv(struct iwl_priv *priv)
  850. {
  851. int ret;
  852. spin_lock_init(&priv->sta_lock);
  853. mutex_init(&priv->mutex);
  854. INIT_LIST_HEAD(&priv->calib_results);
  855. priv->ieee_channels = NULL;
  856. priv->ieee_rates = NULL;
  857. priv->band = IEEE80211_BAND_2GHZ;
  858. priv->plcp_delta_threshold =
  859. cfg(priv)->base_params->plcp_delta_threshold;
  860. priv->iw_mode = NL80211_IFTYPE_STATION;
  861. priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
  862. priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
  863. priv->agg_tids_count = 0;
  864. priv->ucode_owner = IWL_OWNERSHIP_DRIVER;
  865. /* initialize force reset */
  866. priv->force_reset[IWL_RF_RESET].reset_duration =
  867. IWL_DELAY_NEXT_FORCE_RF_RESET;
  868. priv->force_reset[IWL_FW_RESET].reset_duration =
  869. IWL_DELAY_NEXT_FORCE_FW_RELOAD;
  870. priv->rx_statistics_jiffies = jiffies;
  871. /* Choose which receivers/antennas to use */
  872. iwlagn_set_rxon_chain(priv, &priv->contexts[IWL_RXON_CTX_BSS]);
  873. iwl_init_scan_params(priv);
  874. /* init bt coex */
  875. if (cfg(priv)->bt_params &&
  876. cfg(priv)->bt_params->advanced_bt_coexist) {
  877. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  878. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  879. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  880. priv->bt_on_thresh = BT_ON_THRESHOLD_DEF;
  881. priv->bt_duration = BT_DURATION_LIMIT_DEF;
  882. priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
  883. }
  884. ret = iwl_init_channel_map(priv);
  885. if (ret) {
  886. IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
  887. goto err;
  888. }
  889. ret = iwl_init_geos(priv);
  890. if (ret) {
  891. IWL_ERR(priv, "initializing geos failed: %d\n", ret);
  892. goto err_free_channel_map;
  893. }
  894. iwl_init_hw_rates(priv->ieee_rates);
  895. return 0;
  896. err_free_channel_map:
  897. iwl_free_channel_map(priv);
  898. err:
  899. return ret;
  900. }
  901. static void iwl_uninit_drv(struct iwl_priv *priv)
  902. {
  903. iwl_free_geos(priv);
  904. iwl_free_channel_map(priv);
  905. kfree(priv->scan_cmd);
  906. kfree(priv->beacon_cmd);
  907. kfree(rcu_dereference_raw(priv->noa_data));
  908. iwl_calib_free_results(priv);
  909. #ifdef CONFIG_IWLWIFI_DEBUGFS
  910. kfree(priv->wowlan_sram);
  911. #endif
  912. }
  913. /* Size of one Rx buffer in host DRAM */
  914. #define IWL_RX_BUF_SIZE_4K (4 * 1024)
  915. #define IWL_RX_BUF_SIZE_8K (8 * 1024)
  916. static void iwl_set_hw_params(struct iwl_priv *priv)
  917. {
  918. if (cfg(priv)->ht_params)
  919. hw_params(priv).use_rts_for_aggregation =
  920. cfg(priv)->ht_params->use_rts_for_aggregation;
  921. if (iwlagn_mod_params.amsdu_size_8K)
  922. hw_params(priv).rx_page_order =
  923. get_order(IWL_RX_BUF_SIZE_8K);
  924. else
  925. hw_params(priv).rx_page_order =
  926. get_order(IWL_RX_BUF_SIZE_4K);
  927. if (iwlagn_mod_params.disable_11n & IWL_DISABLE_HT_ALL)
  928. hw_params(priv).sku &= ~EEPROM_SKU_CAP_11N_ENABLE;
  929. hw_params(priv).num_ampdu_queues =
  930. cfg(priv)->base_params->num_of_ampdu_queues;
  931. hw_params(priv).wd_timeout = cfg(priv)->base_params->wd_timeout;
  932. /* Device-specific setup */
  933. cfg(priv)->lib->set_hw_params(priv);
  934. }
  935. static void iwl_debug_config(struct iwl_priv *priv)
  936. {
  937. dev_printk(KERN_INFO, trans(priv)->dev, "CONFIG_IWLWIFI_DEBUG "
  938. #ifdef CONFIG_IWLWIFI_DEBUG
  939. "enabled\n");
  940. #else
  941. "disabled\n");
  942. #endif
  943. dev_printk(KERN_INFO, trans(priv)->dev, "CONFIG_IWLWIFI_DEBUGFS "
  944. #ifdef CONFIG_IWLWIFI_DEBUGFS
  945. "enabled\n");
  946. #else
  947. "disabled\n");
  948. #endif
  949. dev_printk(KERN_INFO, trans(priv)->dev, "CONFIG_IWLWIFI_DEVICE_TRACING "
  950. #ifdef CONFIG_IWLWIFI_DEVICE_TRACING
  951. "enabled\n");
  952. #else
  953. "disabled\n");
  954. #endif
  955. dev_printk(KERN_INFO, trans(priv)->dev, "CONFIG_IWLWIFI_DEVICE_TESTMODE "
  956. #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
  957. "enabled\n");
  958. #else
  959. "disabled\n");
  960. #endif
  961. dev_printk(KERN_INFO, trans(priv)->dev, "CONFIG_IWLWIFI_P2P "
  962. #ifdef CONFIG_IWLWIFI_P2P
  963. "enabled\n");
  964. #else
  965. "disabled\n");
  966. #endif
  967. }
  968. static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
  969. const struct iwl_fw *fw)
  970. {
  971. int err = 0;
  972. struct iwl_priv *priv;
  973. struct ieee80211_hw *hw;
  974. struct iwl_op_mode *op_mode;
  975. u16 num_mac;
  976. u32 ucode_flags;
  977. struct iwl_trans_config trans_cfg;
  978. /************************
  979. * 1. Allocating HW data
  980. ************************/
  981. hw = iwl_alloc_all();
  982. if (!hw) {
  983. pr_err("%s: Cannot allocate network device\n",
  984. cfg(trans)->name);
  985. err = -ENOMEM;
  986. goto out;
  987. }
  988. op_mode = hw->priv;
  989. op_mode->ops = &iwl_dvm_ops;
  990. priv = IWL_OP_MODE_GET_DVM(op_mode);
  991. priv->shrd = trans->shrd;
  992. priv->fw = fw;
  993. /* TODO: remove fw from shared data later */
  994. priv->shrd->fw = fw;
  995. /*
  996. * Populate the state variables that the transport layer needs
  997. * to know about.
  998. */
  999. trans_cfg.op_mode = op_mode;
  1000. ucode_flags = fw->ucode_capa.flags;
  1001. #ifndef CONFIG_IWLWIFI_P2P
  1002. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
  1003. #endif
  1004. if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN) {
  1005. priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
  1006. trans_cfg.cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
  1007. } else {
  1008. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  1009. trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  1010. }
  1011. /* Configure transport layer */
  1012. iwl_trans_configure(trans(priv), &trans_cfg);
  1013. /* At this point both hw and priv are allocated. */
  1014. SET_IEEE80211_DEV(priv->hw, trans(priv)->dev);
  1015. /* show what debugging capabilities we have */
  1016. iwl_debug_config(priv);
  1017. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  1018. /* is antenna coupling more than 35dB ? */
  1019. priv->bt_ant_couple_ok =
  1020. (iwlagn_mod_params.ant_coupling >
  1021. IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
  1022. true : false;
  1023. /* enable/disable bt channel inhibition */
  1024. priv->bt_ch_announce = iwlagn_mod_params.bt_ch_announce;
  1025. IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n",
  1026. (priv->bt_ch_announce) ? "On" : "Off");
  1027. if (iwl_alloc_traffic_mem(priv))
  1028. IWL_ERR(priv, "Not enough memory to generate traffic log\n");
  1029. /* these spin locks will be used in apm_ops.init and EEPROM access
  1030. * we should init now
  1031. */
  1032. spin_lock_init(&trans(priv)->reg_lock);
  1033. spin_lock_init(&priv->statistics.lock);
  1034. /***********************
  1035. * 2. Read REV register
  1036. ***********************/
  1037. IWL_INFO(priv, "Detected %s, REV=0x%X\n",
  1038. cfg(priv)->name, trans(priv)->hw_rev);
  1039. err = iwl_trans_start_hw(trans(priv));
  1040. if (err)
  1041. goto out_free_traffic_mem;
  1042. /*****************
  1043. * 3. Read EEPROM
  1044. *****************/
  1045. err = iwl_eeprom_init(trans(priv), trans(priv)->hw_rev);
  1046. /* Reset chip to save power until we load uCode during "up". */
  1047. iwl_trans_stop_hw(trans(priv));
  1048. if (err) {
  1049. IWL_ERR(priv, "Unable to init EEPROM\n");
  1050. goto out_free_traffic_mem;
  1051. }
  1052. err = iwl_eeprom_check_version(priv);
  1053. if (err)
  1054. goto out_free_eeprom;
  1055. err = iwl_eeprom_init_hw_params(priv);
  1056. if (err)
  1057. goto out_free_eeprom;
  1058. /* extract MAC Address */
  1059. iwl_eeprom_get_mac(priv->shrd, priv->addresses[0].addr);
  1060. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
  1061. priv->hw->wiphy->addresses = priv->addresses;
  1062. priv->hw->wiphy->n_addresses = 1;
  1063. num_mac = iwl_eeprom_query16(priv->shrd, EEPROM_NUM_MAC_ADDRESS);
  1064. if (num_mac > 1) {
  1065. memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
  1066. ETH_ALEN);
  1067. priv->addresses[1].addr[5]++;
  1068. priv->hw->wiphy->n_addresses++;
  1069. }
  1070. /************************
  1071. * 4. Setup HW constants
  1072. ************************/
  1073. iwl_set_hw_params(priv);
  1074. if (!(hw_params(priv).sku & EEPROM_SKU_CAP_IPAN_ENABLE)) {
  1075. IWL_DEBUG_INFO(priv, "Your EEPROM disabled PAN");
  1076. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
  1077. /*
  1078. * if not PAN, then don't support P2P -- might be a uCode
  1079. * packaging bug or due to the eeprom check above
  1080. */
  1081. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_P2P;
  1082. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  1083. trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  1084. /* Configure transport layer again*/
  1085. iwl_trans_configure(trans(priv), &trans_cfg);
  1086. }
  1087. /*******************
  1088. * 5. Setup priv
  1089. *******************/
  1090. err = iwl_init_drv(priv);
  1091. if (err)
  1092. goto out_free_eeprom;
  1093. /* At this point both hw and priv are initialized. */
  1094. /********************
  1095. * 6. Setup services
  1096. ********************/
  1097. iwl_setup_deferred_work(priv);
  1098. iwl_setup_rx_handlers(priv);
  1099. iwl_testmode_init(priv);
  1100. iwl_power_initialize(priv);
  1101. iwl_tt_initialize(priv);
  1102. snprintf(priv->hw->wiphy->fw_version,
  1103. sizeof(priv->hw->wiphy->fw_version),
  1104. "%s", fw->fw_version);
  1105. priv->new_scan_threshold_behaviour =
  1106. !!(ucode_flags & IWL_UCODE_TLV_FLAGS_NEWSCAN);
  1107. priv->phy_calib_chain_noise_reset_cmd =
  1108. fw->ucode_capa.standard_phy_calibration_size;
  1109. priv->phy_calib_chain_noise_gain_cmd =
  1110. fw->ucode_capa.standard_phy_calibration_size + 1;
  1111. /* initialize all valid contexts */
  1112. iwl_init_context(priv, ucode_flags);
  1113. /**************************************************
  1114. * This is still part of probe() in a sense...
  1115. *
  1116. * 7. Setup and register with mac80211 and debugfs
  1117. **************************************************/
  1118. err = iwlagn_mac_setup_register(priv, &fw->ucode_capa);
  1119. if (err)
  1120. goto out_destroy_workqueue;
  1121. err = iwl_dbgfs_register(priv, DRV_NAME);
  1122. if (err)
  1123. IWL_ERR(priv,
  1124. "failed to create debugfs files. Ignoring error: %d\n",
  1125. err);
  1126. return op_mode;
  1127. out_destroy_workqueue:
  1128. destroy_workqueue(priv->workqueue);
  1129. priv->workqueue = NULL;
  1130. iwl_uninit_drv(priv);
  1131. out_free_eeprom:
  1132. iwl_eeprom_free(priv->shrd);
  1133. out_free_traffic_mem:
  1134. iwl_free_traffic_mem(priv);
  1135. ieee80211_free_hw(priv->hw);
  1136. out:
  1137. op_mode = NULL;
  1138. return op_mode;
  1139. }
  1140. static void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode)
  1141. {
  1142. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1143. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  1144. iwl_dbgfs_unregister(priv);
  1145. iwl_testmode_cleanup(priv);
  1146. iwlagn_mac_unregister(priv);
  1147. iwl_tt_exit(priv);
  1148. /*This will stop the queues, move the device to low power state */
  1149. iwl_trans_stop_device(trans(priv));
  1150. iwl_eeprom_free(priv->shrd);
  1151. /*netif_stop_queue(dev); */
  1152. flush_workqueue(priv->workqueue);
  1153. /* ieee80211_unregister_hw calls iwlagn_mac_stop, which flushes
  1154. * priv->workqueue... so we can't take down the workqueue
  1155. * until now... */
  1156. destroy_workqueue(priv->workqueue);
  1157. priv->workqueue = NULL;
  1158. iwl_free_traffic_mem(priv);
  1159. iwl_uninit_drv(priv);
  1160. dev_kfree_skb(priv->beacon_skb);
  1161. ieee80211_free_hw(priv->hw);
  1162. }
  1163. static void iwl_cmd_queue_full(struct iwl_op_mode *op_mode)
  1164. {
  1165. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1166. if (!iwl_check_for_ct_kill(priv)) {
  1167. IWL_ERR(priv, "Restarting adapter queue is full\n");
  1168. iwl_nic_error(op_mode);
  1169. }
  1170. }
  1171. static void iwl_nic_config(struct iwl_op_mode *op_mode)
  1172. {
  1173. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1174. cfg(priv)->lib->nic_config(priv);
  1175. }
  1176. static void iwl_stop_sw_queue(struct iwl_op_mode *op_mode, u8 ac)
  1177. {
  1178. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1179. set_bit(ac, &priv->transport_queue_stop);
  1180. ieee80211_stop_queue(priv->hw, ac);
  1181. }
  1182. static void iwl_wake_sw_queue(struct iwl_op_mode *op_mode, u8 ac)
  1183. {
  1184. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1185. clear_bit(ac, &priv->transport_queue_stop);
  1186. if (!priv->passive_no_rx)
  1187. ieee80211_wake_queue(priv->hw, ac);
  1188. }
  1189. void iwlagn_lift_passive_no_rx(struct iwl_priv *priv)
  1190. {
  1191. int ac;
  1192. if (!priv->passive_no_rx)
  1193. return;
  1194. for (ac = IEEE80211_AC_VO; ac < IEEE80211_NUM_ACS; ac++) {
  1195. if (!test_bit(ac, &priv->transport_queue_stop)) {
  1196. IWL_DEBUG_TX_QUEUES(priv, "Wake queue %d");
  1197. ieee80211_wake_queue(priv->hw, ac);
  1198. } else {
  1199. IWL_DEBUG_TX_QUEUES(priv, "Don't wake queue %d");
  1200. }
  1201. }
  1202. priv->passive_no_rx = false;
  1203. }
  1204. const struct iwl_op_mode_ops iwl_dvm_ops = {
  1205. .start = iwl_op_mode_dvm_start,
  1206. .stop = iwl_op_mode_dvm_stop,
  1207. .rx = iwl_rx_dispatch,
  1208. .queue_full = iwl_stop_sw_queue,
  1209. .queue_not_full = iwl_wake_sw_queue,
  1210. .hw_rf_kill = iwl_set_hw_rfkill_state,
  1211. .free_skb = iwl_free_skb,
  1212. .nic_error = iwl_nic_error,
  1213. .cmd_queue_full = iwl_cmd_queue_full,
  1214. .nic_config = iwl_nic_config,
  1215. };
  1216. /*****************************************************************************
  1217. *
  1218. * driver and module entry point
  1219. *
  1220. *****************************************************************************/
  1221. struct kmem_cache *iwl_tx_cmd_pool;
  1222. static int __init iwl_init(void)
  1223. {
  1224. int ret;
  1225. pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
  1226. pr_info(DRV_COPYRIGHT "\n");
  1227. iwl_tx_cmd_pool = kmem_cache_create("iwl_dev_cmd",
  1228. sizeof(struct iwl_device_cmd),
  1229. sizeof(void *), 0, NULL);
  1230. if (!iwl_tx_cmd_pool)
  1231. return -ENOMEM;
  1232. ret = iwlagn_rate_control_register();
  1233. if (ret) {
  1234. pr_err("Unable to register rate control algorithm: %d\n", ret);
  1235. goto error_rc_register;
  1236. }
  1237. ret = iwl_pci_register_driver();
  1238. if (ret)
  1239. goto error_pci_register;
  1240. return ret;
  1241. error_pci_register:
  1242. iwlagn_rate_control_unregister();
  1243. error_rc_register:
  1244. kmem_cache_destroy(iwl_tx_cmd_pool);
  1245. return ret;
  1246. }
  1247. static void __exit iwl_exit(void)
  1248. {
  1249. iwl_pci_unregister_driver();
  1250. iwlagn_rate_control_unregister();
  1251. kmem_cache_destroy(iwl_tx_cmd_pool);
  1252. }
  1253. module_exit(iwl_exit);
  1254. module_init(iwl_init);
  1255. #ifdef CONFIG_IWLWIFI_DEBUG
  1256. module_param_named(debug, iwlagn_mod_params.debug_level, uint,
  1257. S_IRUGO | S_IWUSR);
  1258. MODULE_PARM_DESC(debug, "debug output mask");
  1259. #endif
  1260. module_param_named(swcrypto, iwlagn_mod_params.sw_crypto, int, S_IRUGO);
  1261. MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
  1262. module_param_named(11n_disable, iwlagn_mod_params.disable_11n, uint, S_IRUGO);
  1263. MODULE_PARM_DESC(11n_disable,
  1264. "disable 11n functionality, bitmap: 1: full, 2: agg TX, 4: agg RX");
  1265. module_param_named(amsdu_size_8K, iwlagn_mod_params.amsdu_size_8K,
  1266. int, S_IRUGO);
  1267. MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
  1268. module_param_named(fw_restart, iwlagn_mod_params.restart_fw, int, S_IRUGO);
  1269. MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");
  1270. module_param_named(ucode_alternative,
  1271. iwlagn_mod_params.wanted_ucode_alternative,
  1272. int, S_IRUGO);
  1273. MODULE_PARM_DESC(ucode_alternative,
  1274. "specify ucode alternative to use from ucode file");
  1275. module_param_named(antenna_coupling, iwlagn_mod_params.ant_coupling,
  1276. int, S_IRUGO);
  1277. MODULE_PARM_DESC(antenna_coupling,
  1278. "specify antenna coupling in dB (defualt: 0 dB)");
  1279. module_param_named(bt_ch_inhibition, iwlagn_mod_params.bt_ch_announce,
  1280. bool, S_IRUGO);
  1281. MODULE_PARM_DESC(bt_ch_inhibition,
  1282. "Enable BT channel inhibition (default: enable)");
  1283. module_param_named(plcp_check, iwlagn_mod_params.plcp_check, bool, S_IRUGO);
  1284. MODULE_PARM_DESC(plcp_check, "Check plcp health (default: 1 [enabled])");
  1285. module_param_named(ack_check, iwlagn_mod_params.ack_check, bool, S_IRUGO);
  1286. MODULE_PARM_DESC(ack_check, "Check ack health (default: 0 [disabled])");
  1287. module_param_named(wd_disable, iwlagn_mod_params.wd_disable, int, S_IRUGO);
  1288. MODULE_PARM_DESC(wd_disable,
  1289. "Disable stuck queue watchdog timer 0=system default, "
  1290. "1=disable, 2=enable (default: 0)");
  1291. /*
  1292. * set bt_coex_active to true, uCode will do kill/defer
  1293. * every time the priority line is asserted (BT is sending signals on the
  1294. * priority line in the PCIx).
  1295. * set bt_coex_active to false, uCode will ignore the BT activity and
  1296. * perform the normal operation
  1297. *
  1298. * User might experience transmit issue on some platform due to WiFi/BT
  1299. * co-exist problem. The possible behaviors are:
  1300. * Able to scan and finding all the available AP
  1301. * Not able to associate with any AP
  1302. * On those platforms, WiFi communication can be restored by set
  1303. * "bt_coex_active" module parameter to "false"
  1304. *
  1305. * default: bt_coex_active = true (BT_COEX_ENABLE)
  1306. */
  1307. module_param_named(bt_coex_active, iwlagn_mod_params.bt_coex_active,
  1308. bool, S_IRUGO);
  1309. MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)");
  1310. module_param_named(led_mode, iwlagn_mod_params.led_mode, int, S_IRUGO);
  1311. MODULE_PARM_DESC(led_mode, "0=system default, "
  1312. "1=On(RF On)/Off(RF Off), 2=blinking, 3=Off (default: 0)");
  1313. module_param_named(power_save, iwlagn_mod_params.power_save,
  1314. bool, S_IRUGO);
  1315. MODULE_PARM_DESC(power_save,
  1316. "enable WiFi power management (default: disable)");
  1317. module_param_named(power_level, iwlagn_mod_params.power_level,
  1318. int, S_IRUGO);
  1319. MODULE_PARM_DESC(power_level,
  1320. "default power save level (range from 1 - 5, default: 1)");
  1321. module_param_named(auto_agg, iwlagn_mod_params.auto_agg,
  1322. bool, S_IRUGO);
  1323. MODULE_PARM_DESC(auto_agg,
  1324. "enable agg w/o check traffic load (default: enable)");
  1325. /*
  1326. * For now, keep using power level 1 instead of automatically
  1327. * adjusting ...
  1328. */
  1329. module_param_named(no_sleep_autoadjust, iwlagn_mod_params.no_sleep_autoadjust,
  1330. bool, S_IRUGO);
  1331. MODULE_PARM_DESC(no_sleep_autoadjust,
  1332. "don't automatically adjust sleep level "
  1333. "according to maximum network latency (default: true)");