iwl-agn.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551
  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-ucode.h"
  42. #include "iwl-eeprom.h"
  43. #include "iwl-wifi.h"
  44. #include "iwl-dev.h"
  45. #include "iwl-core.h"
  46. #include "iwl-io.h"
  47. #include "iwl-agn-calib.h"
  48. #include "iwl-agn.h"
  49. #include "iwl-shared.h"
  50. #include "iwl-trans.h"
  51. #include "iwl-op-mode.h"
  52. /******************************************************************************
  53. *
  54. * module boiler plate
  55. *
  56. ******************************************************************************/
  57. /*
  58. * module name, copyright, version, etc.
  59. */
  60. #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
  61. #ifdef CONFIG_IWLWIFI_DEBUG
  62. #define VD "d"
  63. #else
  64. #define VD
  65. #endif
  66. #define DRV_VERSION IWLWIFI_VERSION VD
  67. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  68. MODULE_VERSION(DRV_VERSION);
  69. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  70. MODULE_LICENSE("GPL");
  71. MODULE_ALIAS("iwlagn");
  72. void iwl_update_chain_flags(struct iwl_priv *priv)
  73. {
  74. struct iwl_rxon_context *ctx;
  75. for_each_context(priv, ctx) {
  76. iwlagn_set_rxon_chain(priv, ctx);
  77. if (ctx->active.rx_chain != ctx->staging.rx_chain)
  78. iwlagn_commit_rxon(priv, ctx);
  79. }
  80. }
  81. /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
  82. static void iwl_set_beacon_tim(struct iwl_priv *priv,
  83. struct iwl_tx_beacon_cmd *tx_beacon_cmd,
  84. u8 *beacon, u32 frame_size)
  85. {
  86. u16 tim_idx;
  87. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
  88. /*
  89. * The index is relative to frame start but we start looking at the
  90. * variable-length part of the beacon.
  91. */
  92. tim_idx = mgmt->u.beacon.variable - beacon;
  93. /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
  94. while ((tim_idx < (frame_size - 2)) &&
  95. (beacon[tim_idx] != WLAN_EID_TIM))
  96. tim_idx += beacon[tim_idx+1] + 2;
  97. /* If TIM field was found, set variables */
  98. if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
  99. tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
  100. tx_beacon_cmd->tim_size = beacon[tim_idx+1];
  101. } else
  102. IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
  103. }
  104. int iwlagn_send_beacon_cmd(struct iwl_priv *priv)
  105. {
  106. struct iwl_tx_beacon_cmd *tx_beacon_cmd;
  107. struct iwl_host_cmd cmd = {
  108. .id = REPLY_TX_BEACON,
  109. .flags = CMD_SYNC,
  110. };
  111. struct ieee80211_tx_info *info;
  112. u32 frame_size;
  113. u32 rate_flags;
  114. u32 rate;
  115. /*
  116. * We have to set up the TX command, the TX Beacon command, and the
  117. * beacon contents.
  118. */
  119. lockdep_assert_held(&priv->shrd->mutex);
  120. if (!priv->beacon_ctx) {
  121. IWL_ERR(priv, "trying to build beacon w/o beacon context!\n");
  122. return 0;
  123. }
  124. if (WARN_ON(!priv->beacon_skb))
  125. return -EINVAL;
  126. /* Allocate beacon command */
  127. if (!priv->beacon_cmd)
  128. priv->beacon_cmd = kzalloc(sizeof(*tx_beacon_cmd), GFP_KERNEL);
  129. tx_beacon_cmd = priv->beacon_cmd;
  130. if (!tx_beacon_cmd)
  131. return -ENOMEM;
  132. frame_size = priv->beacon_skb->len;
  133. /* Set up TX command fields */
  134. tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
  135. tx_beacon_cmd->tx.sta_id = priv->beacon_ctx->bcast_sta_id;
  136. tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  137. tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
  138. TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
  139. /* Set up TX beacon command fields */
  140. iwl_set_beacon_tim(priv, tx_beacon_cmd, priv->beacon_skb->data,
  141. frame_size);
  142. /* Set up packet rate and flags */
  143. info = IEEE80211_SKB_CB(priv->beacon_skb);
  144. /*
  145. * Let's set up the rate at least somewhat correctly;
  146. * it will currently not actually be used by the uCode,
  147. * it uses the broadcast station's rate instead.
  148. */
  149. if (info->control.rates[0].idx < 0 ||
  150. info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
  151. rate = 0;
  152. else
  153. rate = info->control.rates[0].idx;
  154. priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
  155. hw_params(priv).valid_tx_ant);
  156. rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
  157. /* In mac80211, rates for 5 GHz start at 0 */
  158. if (info->band == IEEE80211_BAND_5GHZ)
  159. rate += IWL_FIRST_OFDM_RATE;
  160. else if (rate >= IWL_FIRST_CCK_RATE && rate <= IWL_LAST_CCK_RATE)
  161. rate_flags |= RATE_MCS_CCK_MSK;
  162. tx_beacon_cmd->tx.rate_n_flags =
  163. iwl_hw_set_rate_n_flags(rate, rate_flags);
  164. /* Submit command */
  165. cmd.len[0] = sizeof(*tx_beacon_cmd);
  166. cmd.data[0] = tx_beacon_cmd;
  167. cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
  168. cmd.len[1] = frame_size;
  169. cmd.data[1] = priv->beacon_skb->data;
  170. cmd.dataflags[1] = IWL_HCMD_DFL_NOCOPY;
  171. return iwl_trans_send_cmd(trans(priv), &cmd);
  172. }
  173. static void iwl_bg_beacon_update(struct work_struct *work)
  174. {
  175. struct iwl_priv *priv =
  176. container_of(work, struct iwl_priv, beacon_update);
  177. struct sk_buff *beacon;
  178. mutex_lock(&priv->shrd->mutex);
  179. if (!priv->beacon_ctx) {
  180. IWL_ERR(priv, "updating beacon w/o beacon context!\n");
  181. goto out;
  182. }
  183. if (priv->beacon_ctx->vif->type != NL80211_IFTYPE_AP) {
  184. /*
  185. * The ucode will send beacon notifications even in
  186. * IBSS mode, but we don't want to process them. But
  187. * we need to defer the type check to here due to
  188. * requiring locking around the beacon_ctx access.
  189. */
  190. goto out;
  191. }
  192. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  193. beacon = ieee80211_beacon_get(priv->hw, priv->beacon_ctx->vif);
  194. if (!beacon) {
  195. IWL_ERR(priv, "update beacon failed -- keeping old\n");
  196. goto out;
  197. }
  198. /* new beacon skb is allocated every time; dispose previous.*/
  199. dev_kfree_skb(priv->beacon_skb);
  200. priv->beacon_skb = beacon;
  201. iwlagn_send_beacon_cmd(priv);
  202. out:
  203. mutex_unlock(&priv->shrd->mutex);
  204. }
  205. static void iwl_bg_bt_runtime_config(struct work_struct *work)
  206. {
  207. struct iwl_priv *priv =
  208. container_of(work, struct iwl_priv, bt_runtime_config);
  209. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  210. return;
  211. /* dont send host command if rf-kill is on */
  212. if (!iwl_is_ready_rf(priv->shrd))
  213. return;
  214. iwlagn_send_advance_bt_config(priv);
  215. }
  216. static void iwl_bg_bt_full_concurrency(struct work_struct *work)
  217. {
  218. struct iwl_priv *priv =
  219. container_of(work, struct iwl_priv, bt_full_concurrency);
  220. struct iwl_rxon_context *ctx;
  221. mutex_lock(&priv->shrd->mutex);
  222. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  223. goto out;
  224. /* dont send host command if rf-kill is on */
  225. if (!iwl_is_ready_rf(priv->shrd))
  226. goto out;
  227. IWL_DEBUG_INFO(priv, "BT coex in %s mode\n",
  228. priv->bt_full_concurrent ?
  229. "full concurrency" : "3-wire");
  230. /*
  231. * LQ & RXON updated cmds must be sent before BT Config cmd
  232. * to avoid 3-wire collisions
  233. */
  234. for_each_context(priv, ctx) {
  235. iwlagn_set_rxon_chain(priv, ctx);
  236. iwlagn_commit_rxon(priv, ctx);
  237. }
  238. iwlagn_send_advance_bt_config(priv);
  239. out:
  240. mutex_unlock(&priv->shrd->mutex);
  241. }
  242. /**
  243. * iwl_bg_statistics_periodic - Timer callback to queue statistics
  244. *
  245. * This callback is provided in order to send a statistics request.
  246. *
  247. * This timer function is continually reset to execute within
  248. * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
  249. * was received. We need to ensure we receive the statistics in order
  250. * to update the temperature used for calibrating the TXPOWER.
  251. */
  252. static void iwl_bg_statistics_periodic(unsigned long data)
  253. {
  254. struct iwl_priv *priv = (struct iwl_priv *)data;
  255. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  256. return;
  257. /* dont send host command if rf-kill is on */
  258. if (!iwl_is_ready_rf(priv->shrd))
  259. return;
  260. iwl_send_statistics_request(priv, CMD_ASYNC, false);
  261. }
  262. static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base,
  263. u32 start_idx, u32 num_events,
  264. u32 capacity, u32 mode)
  265. {
  266. u32 i;
  267. u32 ptr; /* SRAM byte address of log data */
  268. u32 ev, time, data; /* event log data */
  269. unsigned long reg_flags;
  270. if (mode == 0)
  271. ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32));
  272. else
  273. ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32));
  274. /* Make sure device is powered up for SRAM reads */
  275. spin_lock_irqsave(&trans(priv)->reg_lock, reg_flags);
  276. if (iwl_grab_nic_access(trans(priv))) {
  277. spin_unlock_irqrestore(&trans(priv)->reg_lock, reg_flags);
  278. return;
  279. }
  280. /* Set starting address; reads will auto-increment */
  281. iwl_write32(trans(priv), HBUS_TARG_MEM_RADDR, ptr);
  282. rmb();
  283. /*
  284. * Refuse to read more than would have fit into the log from
  285. * the current start_idx. This used to happen due to the race
  286. * described below, but now WARN because the code below should
  287. * prevent it from happening here.
  288. */
  289. if (WARN_ON(num_events > capacity - start_idx))
  290. num_events = capacity - start_idx;
  291. /*
  292. * "time" is actually "data" for mode 0 (no timestamp).
  293. * place event id # at far right for easier visual parsing.
  294. */
  295. for (i = 0; i < num_events; i++) {
  296. ev = iwl_read32(trans(priv), HBUS_TARG_MEM_RDAT);
  297. time = iwl_read32(trans(priv), HBUS_TARG_MEM_RDAT);
  298. if (mode == 0) {
  299. trace_iwlwifi_dev_ucode_cont_event(priv, 0, time, ev);
  300. } else {
  301. data = iwl_read32(trans(priv), HBUS_TARG_MEM_RDAT);
  302. trace_iwlwifi_dev_ucode_cont_event(priv, time,
  303. data, ev);
  304. }
  305. }
  306. /* Allow device to power down */
  307. iwl_release_nic_access(trans(priv));
  308. spin_unlock_irqrestore(&trans(priv)->reg_lock, reg_flags);
  309. }
  310. static void iwl_continuous_event_trace(struct iwl_priv *priv)
  311. {
  312. u32 capacity; /* event log capacity in # entries */
  313. struct {
  314. u32 capacity;
  315. u32 mode;
  316. u32 wrap_counter;
  317. u32 write_counter;
  318. } __packed read;
  319. u32 base; /* SRAM byte address of event log header */
  320. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  321. u32 num_wraps; /* # times uCode wrapped to top of log */
  322. u32 next_entry; /* index of next entry to be written by uCode */
  323. base = priv->shrd->device_pointers.log_event_table;
  324. if (iwlagn_hw_valid_rtc_data_addr(base)) {
  325. iwl_read_targ_mem_words(trans(priv), base, &read, sizeof(read));
  326. capacity = read.capacity;
  327. mode = read.mode;
  328. num_wraps = read.wrap_counter;
  329. next_entry = read.write_counter;
  330. } else
  331. return;
  332. /*
  333. * Unfortunately, the uCode doesn't use temporary variables.
  334. * Therefore, it can happen that we read next_entry == capacity,
  335. * which really means next_entry == 0.
  336. */
  337. if (unlikely(next_entry == capacity))
  338. next_entry = 0;
  339. /*
  340. * Additionally, the uCode increases the write pointer before
  341. * the wraps counter, so if the write pointer is smaller than
  342. * the old write pointer (wrap occurred) but we read that no
  343. * wrap occurred, we actually read between the next_entry and
  344. * num_wraps update (this does happen in practice!!) -- take
  345. * that into account by increasing num_wraps.
  346. */
  347. if (unlikely(next_entry < priv->event_log.next_entry &&
  348. num_wraps == priv->event_log.num_wraps))
  349. num_wraps++;
  350. if (num_wraps == priv->event_log.num_wraps) {
  351. iwl_print_cont_event_trace(
  352. priv, base, priv->event_log.next_entry,
  353. next_entry - priv->event_log.next_entry,
  354. capacity, mode);
  355. priv->event_log.non_wraps_count++;
  356. } else {
  357. if (num_wraps - priv->event_log.num_wraps > 1)
  358. priv->event_log.wraps_more_count++;
  359. else
  360. priv->event_log.wraps_once_count++;
  361. trace_iwlwifi_dev_ucode_wrap_event(priv,
  362. num_wraps - priv->event_log.num_wraps,
  363. next_entry, priv->event_log.next_entry);
  364. if (next_entry < priv->event_log.next_entry) {
  365. iwl_print_cont_event_trace(
  366. priv, base, priv->event_log.next_entry,
  367. capacity - priv->event_log.next_entry,
  368. capacity, mode);
  369. iwl_print_cont_event_trace(
  370. priv, base, 0, next_entry, capacity, mode);
  371. } else {
  372. iwl_print_cont_event_trace(
  373. priv, base, next_entry,
  374. capacity - next_entry,
  375. capacity, mode);
  376. iwl_print_cont_event_trace(
  377. priv, base, 0, next_entry, capacity, mode);
  378. }
  379. }
  380. priv->event_log.num_wraps = num_wraps;
  381. priv->event_log.next_entry = next_entry;
  382. }
  383. /**
  384. * iwl_bg_ucode_trace - Timer callback to log ucode event
  385. *
  386. * The timer is continually set to execute every
  387. * UCODE_TRACE_PERIOD milliseconds after the last timer expired
  388. * this function is to perform continuous uCode event logging operation
  389. * if enabled
  390. */
  391. static void iwl_bg_ucode_trace(unsigned long data)
  392. {
  393. struct iwl_priv *priv = (struct iwl_priv *)data;
  394. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  395. return;
  396. if (priv->event_log.ucode_trace) {
  397. iwl_continuous_event_trace(priv);
  398. /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
  399. mod_timer(&priv->ucode_trace,
  400. jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
  401. }
  402. }
  403. static void iwl_bg_tx_flush(struct work_struct *work)
  404. {
  405. struct iwl_priv *priv =
  406. container_of(work, struct iwl_priv, tx_flush);
  407. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  408. return;
  409. /* do nothing if rf-kill is on */
  410. if (!iwl_is_ready_rf(priv->shrd))
  411. return;
  412. IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n");
  413. iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
  414. }
  415. void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags)
  416. {
  417. int i;
  418. /*
  419. * The default context is always valid,
  420. * the PAN context depends on uCode.
  421. */
  422. priv->shrd->valid_contexts = BIT(IWL_RXON_CTX_BSS);
  423. if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN)
  424. priv->shrd->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
  425. for (i = 0; i < NUM_IWL_RXON_CTX; i++)
  426. priv->contexts[i].ctxid = i;
  427. priv->contexts[IWL_RXON_CTX_BSS].always_active = true;
  428. priv->contexts[IWL_RXON_CTX_BSS].is_active = true;
  429. priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
  430. priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
  431. priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
  432. priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
  433. priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
  434. priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
  435. priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
  436. priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
  437. BIT(NL80211_IFTYPE_ADHOC);
  438. priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
  439. BIT(NL80211_IFTYPE_STATION);
  440. priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP;
  441. priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
  442. priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
  443. priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
  444. priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON;
  445. priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd =
  446. REPLY_WIPAN_RXON_TIMING;
  447. priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd =
  448. REPLY_WIPAN_RXON_ASSOC;
  449. priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM;
  450. priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN;
  451. priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY;
  452. priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID;
  453. priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION;
  454. priv->contexts[IWL_RXON_CTX_PAN].interface_modes =
  455. BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
  456. if (ucode_flags & IWL_UCODE_TLV_FLAGS_P2P)
  457. priv->contexts[IWL_RXON_CTX_PAN].interface_modes |=
  458. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  459. BIT(NL80211_IFTYPE_P2P_GO);
  460. priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP;
  461. priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA;
  462. priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P;
  463. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  464. }
  465. static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
  466. {
  467. struct iwl_ct_kill_config cmd;
  468. struct iwl_ct_kill_throttling_config adv_cmd;
  469. int ret = 0;
  470. iwl_write32(trans(priv), CSR_UCODE_DRV_GP1_CLR,
  471. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  472. priv->thermal_throttle.ct_kill_toggle = false;
  473. if (cfg(priv)->base_params->support_ct_kill_exit) {
  474. adv_cmd.critical_temperature_enter =
  475. cpu_to_le32(hw_params(priv).ct_kill_threshold);
  476. adv_cmd.critical_temperature_exit =
  477. cpu_to_le32(hw_params(priv).ct_kill_exit_threshold);
  478. ret = iwl_trans_send_cmd_pdu(trans(priv),
  479. REPLY_CT_KILL_CONFIG_CMD,
  480. CMD_SYNC, sizeof(adv_cmd), &adv_cmd);
  481. if (ret)
  482. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  483. else
  484. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  485. "succeeded, critical temperature enter is %d,"
  486. "exit is %d\n",
  487. hw_params(priv).ct_kill_threshold,
  488. hw_params(priv).ct_kill_exit_threshold);
  489. } else {
  490. cmd.critical_temperature_R =
  491. cpu_to_le32(hw_params(priv).ct_kill_threshold);
  492. ret = iwl_trans_send_cmd_pdu(trans(priv),
  493. REPLY_CT_KILL_CONFIG_CMD,
  494. CMD_SYNC, sizeof(cmd), &cmd);
  495. if (ret)
  496. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  497. else
  498. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  499. "succeeded, "
  500. "critical temperature is %d\n",
  501. hw_params(priv).ct_kill_threshold);
  502. }
  503. }
  504. static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
  505. {
  506. struct iwl_calib_cfg_cmd calib_cfg_cmd;
  507. struct iwl_host_cmd cmd = {
  508. .id = CALIBRATION_CFG_CMD,
  509. .len = { sizeof(struct iwl_calib_cfg_cmd), },
  510. .data = { &calib_cfg_cmd, },
  511. };
  512. memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
  513. calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_RT_CFG_ALL;
  514. calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg);
  515. return iwl_trans_send_cmd(trans(priv), &cmd);
  516. }
  517. static int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant)
  518. {
  519. struct iwl_tx_ant_config_cmd tx_ant_cmd = {
  520. .valid = cpu_to_le32(valid_tx_ant),
  521. };
  522. if (IWL_UCODE_API(nic(priv)->fw.ucode_ver) > 1) {
  523. IWL_DEBUG_HC(priv, "select valid tx ant: %u\n", valid_tx_ant);
  524. return iwl_trans_send_cmd_pdu(trans(priv),
  525. TX_ANT_CONFIGURATION_CMD,
  526. CMD_SYNC,
  527. sizeof(struct iwl_tx_ant_config_cmd),
  528. &tx_ant_cmd);
  529. } else {
  530. IWL_DEBUG_HC(priv, "TX_ANT_CONFIGURATION_CMD not supported\n");
  531. return -EOPNOTSUPP;
  532. }
  533. }
  534. /**
  535. * iwl_alive_start - called after REPLY_ALIVE notification received
  536. * from protocol/runtime uCode (initialization uCode's
  537. * Alive gets handled by iwl_init_alive_start()).
  538. */
  539. int iwl_alive_start(struct iwl_priv *priv)
  540. {
  541. int ret = 0;
  542. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  543. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  544. /* After the ALIVE response, we can send host commands to the uCode */
  545. set_bit(STATUS_ALIVE, &priv->shrd->status);
  546. /* Enable watchdog to monitor the driver tx queues */
  547. iwl_setup_watchdog(priv);
  548. if (iwl_is_rfkill(priv->shrd))
  549. return -ERFKILL;
  550. if (priv->event_log.ucode_trace) {
  551. /* start collecting data now */
  552. mod_timer(&priv->ucode_trace, jiffies);
  553. }
  554. /* download priority table before any calibration request */
  555. if (cfg(priv)->bt_params &&
  556. cfg(priv)->bt_params->advanced_bt_coexist) {
  557. /* Configure Bluetooth device coexistence support */
  558. if (cfg(priv)->bt_params->bt_sco_disable)
  559. priv->bt_enable_pspoll = false;
  560. else
  561. priv->bt_enable_pspoll = true;
  562. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  563. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  564. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  565. iwlagn_send_advance_bt_config(priv);
  566. priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS;
  567. priv->cur_rssi_ctx = NULL;
  568. iwl_send_prio_tbl(trans(priv));
  569. /* FIXME: w/a to force change uCode BT state machine */
  570. ret = iwl_send_bt_env(trans(priv), IWL_BT_COEX_ENV_OPEN,
  571. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  572. if (ret)
  573. return ret;
  574. ret = iwl_send_bt_env(trans(priv), IWL_BT_COEX_ENV_CLOSE,
  575. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  576. if (ret)
  577. return ret;
  578. } else {
  579. /*
  580. * default is 2-wire BT coexexistence support
  581. */
  582. iwl_send_bt_config(priv);
  583. }
  584. /*
  585. * Perform runtime calibrations, including DC calibration.
  586. */
  587. iwlagn_send_calib_cfg_rt(priv, IWL_CALIB_CFG_DC_IDX);
  588. ieee80211_wake_queues(priv->hw);
  589. priv->active_rate = IWL_RATES_MASK;
  590. /* Configure Tx antenna selection based on H/W config */
  591. iwlagn_send_tx_ant_config(priv, hw_params(priv).valid_tx_ant);
  592. if (iwl_is_associated_ctx(ctx) && !priv->wowlan) {
  593. struct iwl_rxon_cmd *active_rxon =
  594. (struct iwl_rxon_cmd *)&ctx->active;
  595. /* apply any changes in staging */
  596. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  597. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  598. } else {
  599. struct iwl_rxon_context *tmp;
  600. /* Initialize our rx_config data */
  601. for_each_context(priv, tmp)
  602. iwl_connection_init_rx_config(priv, tmp);
  603. iwlagn_set_rxon_chain(priv, ctx);
  604. }
  605. if (!priv->wowlan) {
  606. /* WoWLAN ucode will not reply in the same way, skip it */
  607. iwl_reset_run_time_calib(priv);
  608. }
  609. set_bit(STATUS_READY, &priv->shrd->status);
  610. /* Configure the adapter for unassociated operation */
  611. ret = iwlagn_commit_rxon(priv, ctx);
  612. if (ret)
  613. return ret;
  614. /* At this point, the NIC is initialized and operational */
  615. iwl_rf_kill_ct_config(priv);
  616. IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
  617. return iwl_power_update_mode(priv, true);
  618. }
  619. /**
  620. * iwl_clear_driver_stations - clear knowledge of all stations from driver
  621. * @priv: iwl priv struct
  622. *
  623. * This is called during iwl_down() to make sure that in the case
  624. * we're coming there from a hardware restart mac80211 will be
  625. * able to reconfigure stations -- if we're getting there in the
  626. * normal down flow then the stations will already be cleared.
  627. */
  628. static void iwl_clear_driver_stations(struct iwl_priv *priv)
  629. {
  630. struct iwl_rxon_context *ctx;
  631. spin_lock_bh(&priv->sta_lock);
  632. memset(priv->stations, 0, sizeof(priv->stations));
  633. priv->num_stations = 0;
  634. priv->ucode_key_table = 0;
  635. for_each_context(priv, ctx) {
  636. /*
  637. * Remove all key information that is not stored as part
  638. * of station information since mac80211 may not have had
  639. * a chance to remove all the keys. When device is
  640. * reconfigured by mac80211 after an error all keys will
  641. * be reconfigured.
  642. */
  643. memset(ctx->wep_keys, 0, sizeof(ctx->wep_keys));
  644. ctx->key_mapping_keys = 0;
  645. }
  646. spin_unlock_bh(&priv->sta_lock);
  647. }
  648. void iwl_down(struct iwl_priv *priv)
  649. {
  650. int exit_pending;
  651. IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
  652. lockdep_assert_held(&priv->shrd->mutex);
  653. iwl_scan_cancel_timeout(priv, 200);
  654. /*
  655. * If active, scanning won't cancel it, so say it expired.
  656. * No race since we hold the mutex here and a new one
  657. * can't come in at this time.
  658. */
  659. ieee80211_remain_on_channel_expired(priv->hw);
  660. exit_pending =
  661. test_and_set_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
  662. /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
  663. * to prevent rearm timer */
  664. del_timer_sync(&priv->watchdog);
  665. iwl_clear_ucode_stations(priv, NULL);
  666. iwl_dealloc_bcast_stations(priv);
  667. iwl_clear_driver_stations(priv);
  668. /* reset BT coex data */
  669. priv->bt_status = 0;
  670. priv->cur_rssi_ctx = NULL;
  671. priv->bt_is_sco = 0;
  672. if (cfg(priv)->bt_params)
  673. priv->bt_traffic_load =
  674. cfg(priv)->bt_params->bt_init_traffic_load;
  675. else
  676. priv->bt_traffic_load = 0;
  677. priv->bt_full_concurrent = false;
  678. priv->bt_ci_compliance = 0;
  679. /* Wipe out the EXIT_PENDING status bit if we are not actually
  680. * exiting the module */
  681. if (!exit_pending)
  682. clear_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
  683. if (priv->mac80211_registered)
  684. ieee80211_stop_queues(priv->hw);
  685. iwl_trans_stop_device(trans(priv));
  686. /* Clear out all status bits but a few that are stable across reset */
  687. priv->shrd->status &=
  688. test_bit(STATUS_RF_KILL_HW, &priv->shrd->status) <<
  689. STATUS_RF_KILL_HW |
  690. test_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status) <<
  691. STATUS_GEO_CONFIGURED |
  692. test_bit(STATUS_FW_ERROR, &priv->shrd->status) <<
  693. STATUS_FW_ERROR |
  694. test_bit(STATUS_EXIT_PENDING, &priv->shrd->status) <<
  695. STATUS_EXIT_PENDING;
  696. dev_kfree_skb(priv->beacon_skb);
  697. priv->beacon_skb = NULL;
  698. }
  699. /*****************************************************************************
  700. *
  701. * Workqueue callbacks
  702. *
  703. *****************************************************************************/
  704. static void iwl_bg_run_time_calib_work(struct work_struct *work)
  705. {
  706. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  707. run_time_calib_work);
  708. mutex_lock(&priv->shrd->mutex);
  709. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status) ||
  710. test_bit(STATUS_SCANNING, &priv->shrd->status)) {
  711. mutex_unlock(&priv->shrd->mutex);
  712. return;
  713. }
  714. if (priv->start_calib) {
  715. iwl_chain_noise_calibration(priv);
  716. iwl_sensitivity_calibration(priv);
  717. }
  718. mutex_unlock(&priv->shrd->mutex);
  719. }
  720. void iwlagn_prepare_restart(struct iwl_priv *priv)
  721. {
  722. struct iwl_rxon_context *ctx;
  723. bool bt_full_concurrent;
  724. u8 bt_ci_compliance;
  725. u8 bt_load;
  726. u8 bt_status;
  727. bool bt_is_sco;
  728. lockdep_assert_held(&priv->shrd->mutex);
  729. for_each_context(priv, ctx)
  730. ctx->vif = NULL;
  731. priv->is_open = 0;
  732. /*
  733. * __iwl_down() will clear the BT status variables,
  734. * which is correct, but when we restart we really
  735. * want to keep them so restore them afterwards.
  736. *
  737. * The restart process will later pick them up and
  738. * re-configure the hw when we reconfigure the BT
  739. * command.
  740. */
  741. bt_full_concurrent = priv->bt_full_concurrent;
  742. bt_ci_compliance = priv->bt_ci_compliance;
  743. bt_load = priv->bt_traffic_load;
  744. bt_status = priv->bt_status;
  745. bt_is_sco = priv->bt_is_sco;
  746. iwl_down(priv);
  747. priv->bt_full_concurrent = bt_full_concurrent;
  748. priv->bt_ci_compliance = bt_ci_compliance;
  749. priv->bt_traffic_load = bt_load;
  750. priv->bt_status = bt_status;
  751. priv->bt_is_sco = bt_is_sco;
  752. }
  753. static void iwl_bg_restart(struct work_struct *data)
  754. {
  755. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  756. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  757. return;
  758. if (test_and_clear_bit(STATUS_FW_ERROR, &priv->shrd->status)) {
  759. mutex_lock(&priv->shrd->mutex);
  760. iwlagn_prepare_restart(priv);
  761. mutex_unlock(&priv->shrd->mutex);
  762. iwl_cancel_deferred_work(priv);
  763. ieee80211_restart_hw(priv->hw);
  764. } else {
  765. WARN_ON(1);
  766. }
  767. }
  768. void iwlagn_disable_roc(struct iwl_priv *priv)
  769. {
  770. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
  771. lockdep_assert_held(&priv->shrd->mutex);
  772. if (!priv->hw_roc_setup)
  773. return;
  774. ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
  775. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  776. priv->hw_roc_channel = NULL;
  777. memset(ctx->staging.node_addr, 0, ETH_ALEN);
  778. iwlagn_commit_rxon(priv, ctx);
  779. ctx->is_active = false;
  780. priv->hw_roc_setup = false;
  781. }
  782. static void iwlagn_disable_roc_work(struct work_struct *work)
  783. {
  784. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  785. hw_roc_disable_work.work);
  786. mutex_lock(&priv->shrd->mutex);
  787. iwlagn_disable_roc(priv);
  788. mutex_unlock(&priv->shrd->mutex);
  789. }
  790. /*****************************************************************************
  791. *
  792. * driver setup and teardown
  793. *
  794. *****************************************************************************/
  795. static void iwl_setup_deferred_work(struct iwl_priv *priv)
  796. {
  797. priv->workqueue = create_singlethread_workqueue(DRV_NAME);
  798. init_waitqueue_head(&priv->shrd->wait_command_queue);
  799. INIT_WORK(&priv->restart, iwl_bg_restart);
  800. INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
  801. INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
  802. INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
  803. INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
  804. INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
  805. INIT_DELAYED_WORK(&priv->hw_roc_disable_work,
  806. iwlagn_disable_roc_work);
  807. iwl_setup_scan_deferred_work(priv);
  808. if (cfg(priv)->lib->bt_setup_deferred_work)
  809. cfg(priv)->lib->bt_setup_deferred_work(priv);
  810. init_timer(&priv->statistics_periodic);
  811. priv->statistics_periodic.data = (unsigned long)priv;
  812. priv->statistics_periodic.function = iwl_bg_statistics_periodic;
  813. init_timer(&priv->ucode_trace);
  814. priv->ucode_trace.data = (unsigned long)priv;
  815. priv->ucode_trace.function = iwl_bg_ucode_trace;
  816. init_timer(&priv->watchdog);
  817. priv->watchdog.data = (unsigned long)priv;
  818. priv->watchdog.function = iwl_bg_watchdog;
  819. }
  820. void iwl_cancel_deferred_work(struct iwl_priv *priv)
  821. {
  822. if (cfg(priv)->lib->cancel_deferred_work)
  823. cfg(priv)->lib->cancel_deferred_work(priv);
  824. cancel_work_sync(&priv->run_time_calib_work);
  825. cancel_work_sync(&priv->beacon_update);
  826. iwl_cancel_scan_deferred_work(priv);
  827. cancel_work_sync(&priv->bt_full_concurrency);
  828. cancel_work_sync(&priv->bt_runtime_config);
  829. cancel_delayed_work_sync(&priv->hw_roc_disable_work);
  830. del_timer_sync(&priv->statistics_periodic);
  831. del_timer_sync(&priv->ucode_trace);
  832. }
  833. static void iwl_init_hw_rates(struct iwl_priv *priv,
  834. struct ieee80211_rate *rates)
  835. {
  836. int i;
  837. for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
  838. rates[i].bitrate = iwl_rates[i].ieee * 5;
  839. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  840. rates[i].hw_value_short = i;
  841. rates[i].flags = 0;
  842. if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
  843. /*
  844. * If CCK != 1M then set short preamble rate flag.
  845. */
  846. rates[i].flags |=
  847. (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
  848. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  849. }
  850. }
  851. }
  852. static int iwl_init_drv(struct iwl_priv *priv)
  853. {
  854. int ret;
  855. spin_lock_init(&priv->sta_lock);
  856. mutex_init(&priv->shrd->mutex);
  857. INIT_LIST_HEAD(&trans(priv)->calib_results);
  858. priv->ieee_channels = NULL;
  859. priv->ieee_rates = NULL;
  860. priv->band = IEEE80211_BAND_2GHZ;
  861. priv->iw_mode = NL80211_IFTYPE_STATION;
  862. priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
  863. priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
  864. priv->agg_tids_count = 0;
  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, 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. if (priv->tx_cmd_pool)
  906. kmem_cache_destroy(priv->tx_cmd_pool);
  907. kfree(priv->scan_cmd);
  908. kfree(priv->beacon_cmd);
  909. kfree(rcu_dereference_raw(priv->noa_data));
  910. #ifdef CONFIG_IWLWIFI_DEBUGFS
  911. kfree(priv->wowlan_sram);
  912. #endif
  913. }
  914. /* Size of one Rx buffer in host DRAM */
  915. #define IWL_RX_BUF_SIZE_4K (4 * 1024)
  916. #define IWL_RX_BUF_SIZE_8K (8 * 1024)
  917. static void iwl_set_hw_params(struct iwl_priv *priv)
  918. {
  919. if (iwlagn_mod_params.amsdu_size_8K)
  920. hw_params(priv).rx_page_order =
  921. get_order(IWL_RX_BUF_SIZE_8K);
  922. else
  923. hw_params(priv).rx_page_order =
  924. get_order(IWL_RX_BUF_SIZE_4K);
  925. if (iwlagn_mod_params.disable_11n & IWL_DISABLE_HT_ALL)
  926. hw_params(priv).sku &= ~EEPROM_SKU_CAP_11N_ENABLE;
  927. hw_params(priv).num_ampdu_queues =
  928. cfg(priv)->base_params->num_of_ampdu_queues;
  929. hw_params(priv).shadow_reg_enable =
  930. cfg(priv)->base_params->shadow_reg_enable;
  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. {
  970. struct iwl_fw *fw = &nic(trans)->fw;
  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. /************************
  978. * 1. Allocating HW data
  979. ************************/
  980. hw = iwl_alloc_all();
  981. if (!hw) {
  982. pr_err("%s: Cannot allocate network device\n",
  983. cfg(trans)->name);
  984. err = -ENOMEM;
  985. goto out;
  986. }
  987. op_mode = hw->priv;
  988. op_mode->ops = &iwl_dvm_ops;
  989. priv = IWL_OP_MODE_GET_DVM(op_mode);
  990. priv->shrd = trans->shrd;
  991. priv->shrd->priv = priv;
  992. iwl_trans_configure(trans(priv), op_mode);
  993. /* At this point both hw and priv are allocated. */
  994. SET_IEEE80211_DEV(priv->hw, trans(priv)->dev);
  995. /* show what debugging capabilities we have */
  996. iwl_debug_config(priv);
  997. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  998. /* is antenna coupling more than 35dB ? */
  999. priv->bt_ant_couple_ok =
  1000. (iwlagn_mod_params.ant_coupling >
  1001. IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
  1002. true : false;
  1003. /* enable/disable bt channel inhibition */
  1004. priv->bt_ch_announce = iwlagn_mod_params.bt_ch_announce;
  1005. IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n",
  1006. (priv->bt_ch_announce) ? "On" : "Off");
  1007. if (iwl_alloc_traffic_mem(priv))
  1008. IWL_ERR(priv, "Not enough memory to generate traffic log\n");
  1009. /* these spin locks will be used in apm_ops.init and EEPROM access
  1010. * we should init now
  1011. */
  1012. spin_lock_init(&trans(priv)->reg_lock);
  1013. spin_lock_init(&priv->statistics.lock);
  1014. /***********************
  1015. * 3. Read REV register
  1016. ***********************/
  1017. IWL_INFO(priv, "Detected %s, REV=0x%X\n",
  1018. cfg(priv)->name, trans(priv)->hw_rev);
  1019. err = iwl_trans_start_hw(trans(priv));
  1020. if (err)
  1021. goto out_free_traffic_mem;
  1022. /*****************
  1023. * 4. Read EEPROM
  1024. *****************/
  1025. /* Read the EEPROM */
  1026. err = iwl_eeprom_init(trans(priv), trans(priv)->hw_rev);
  1027. /* Reset chip to save power until we load uCode during "up". */
  1028. iwl_trans_stop_hw(trans(priv));
  1029. if (err) {
  1030. IWL_ERR(priv, "Unable to init EEPROM\n");
  1031. goto out_free_traffic_mem;
  1032. }
  1033. err = iwl_eeprom_check_version(priv);
  1034. if (err)
  1035. goto out_free_eeprom;
  1036. err = iwl_eeprom_init_hw_params(priv);
  1037. if (err)
  1038. goto out_free_eeprom;
  1039. /* extract MAC Address */
  1040. iwl_eeprom_get_mac(priv->shrd, priv->addresses[0].addr);
  1041. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
  1042. priv->hw->wiphy->addresses = priv->addresses;
  1043. priv->hw->wiphy->n_addresses = 1;
  1044. num_mac = iwl_eeprom_query16(priv->shrd, EEPROM_NUM_MAC_ADDRESS);
  1045. if (num_mac > 1) {
  1046. memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
  1047. ETH_ALEN);
  1048. priv->addresses[1].addr[5]++;
  1049. priv->hw->wiphy->n_addresses++;
  1050. }
  1051. /************************
  1052. * 5. Setup HW constants
  1053. ************************/
  1054. iwl_set_hw_params(priv);
  1055. ucode_flags = fw->ucode_capa.flags;
  1056. #ifndef CONFIG_IWLWIFI_P2P
  1057. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
  1058. #endif
  1059. if (!(hw_params(priv).sku & EEPROM_SKU_CAP_IPAN_ENABLE))
  1060. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
  1061. /*
  1062. * if not PAN, then don't support P2P -- might be a uCode
  1063. * packaging bug or due to the eeprom check above
  1064. */
  1065. if (!(ucode_flags & IWL_UCODE_TLV_FLAGS_PAN))
  1066. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_P2P;
  1067. /*******************
  1068. * 6. Setup priv
  1069. *******************/
  1070. err = iwl_init_drv(priv);
  1071. if (err)
  1072. goto out_free_eeprom;
  1073. /* At this point both hw and priv are initialized. */
  1074. /********************
  1075. * 7. Setup services
  1076. ********************/
  1077. iwl_setup_deferred_work(priv);
  1078. iwl_setup_rx_handlers(priv);
  1079. iwl_testmode_init(priv);
  1080. iwl_power_initialize(priv);
  1081. iwl_tt_initialize(priv);
  1082. snprintf(priv->hw->wiphy->fw_version,
  1083. sizeof(priv->hw->wiphy->fw_version),
  1084. "%s", fw->fw_version);
  1085. priv->new_scan_threshold_behaviour =
  1086. !!(ucode_flags & IWL_UCODE_TLV_FLAGS_NEWSCAN);
  1087. if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN) {
  1088. priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
  1089. priv->shrd->cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
  1090. } else {
  1091. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  1092. priv->shrd->cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  1093. }
  1094. priv->phy_calib_chain_noise_reset_cmd =
  1095. fw->ucode_capa.standard_phy_calibration_size;
  1096. priv->phy_calib_chain_noise_gain_cmd =
  1097. fw->ucode_capa.standard_phy_calibration_size + 1;
  1098. /* initialize all valid contexts */
  1099. iwl_init_context(priv, ucode_flags);
  1100. /**************************************************
  1101. * This is still part of probe() in a sense...
  1102. *
  1103. * 9. Setup and register with mac80211 and debugfs
  1104. **************************************************/
  1105. err = iwlagn_mac_setup_register(priv, &fw->ucode_capa);
  1106. if (err)
  1107. goto out_destroy_workqueue;
  1108. err = iwl_dbgfs_register(priv, DRV_NAME);
  1109. if (err)
  1110. IWL_ERR(priv,
  1111. "failed to create debugfs files. Ignoring error: %d\n",
  1112. err);
  1113. return op_mode;
  1114. out_destroy_workqueue:
  1115. destroy_workqueue(priv->workqueue);
  1116. priv->workqueue = NULL;
  1117. iwl_uninit_drv(priv);
  1118. out_free_eeprom:
  1119. iwl_eeprom_free(priv->shrd);
  1120. out_free_traffic_mem:
  1121. iwl_free_traffic_mem(priv);
  1122. ieee80211_free_hw(priv->hw);
  1123. out:
  1124. op_mode = NULL;
  1125. return op_mode;
  1126. }
  1127. static void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode)
  1128. {
  1129. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1130. wait_for_completion(&nic(priv)->request_firmware_complete);
  1131. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  1132. iwl_dbgfs_unregister(priv);
  1133. iwl_testmode_cleanup(priv);
  1134. iwlagn_mac_unregister(priv);
  1135. iwl_tt_exit(priv);
  1136. /*This will stop the queues, move the device to low power state */
  1137. iwl_trans_stop_device(trans(priv));
  1138. iwl_dealloc_ucode(nic(priv));
  1139. iwl_eeprom_free(priv->shrd);
  1140. /*netif_stop_queue(dev); */
  1141. flush_workqueue(priv->workqueue);
  1142. /* ieee80211_unregister_hw calls iwlagn_mac_stop, which flushes
  1143. * priv->workqueue... so we can't take down the workqueue
  1144. * until now... */
  1145. destroy_workqueue(priv->workqueue);
  1146. priv->workqueue = NULL;
  1147. iwl_free_traffic_mem(priv);
  1148. iwl_uninit_drv(priv);
  1149. dev_kfree_skb(priv->beacon_skb);
  1150. ieee80211_free_hw(priv->hw);
  1151. }
  1152. const struct iwl_op_mode_ops iwl_dvm_ops = {
  1153. .start = iwl_op_mode_dvm_start,
  1154. .stop = iwl_op_mode_dvm_stop,
  1155. .rx = iwl_rx_dispatch,
  1156. .queue_full = iwl_stop_sw_queue,
  1157. .queue_not_full = iwl_wake_sw_queue,
  1158. .hw_rf_kill = iwl_set_hw_rfkill_state,
  1159. .free_skb = iwl_free_skb,
  1160. .nic_error = iwl_nic_error,
  1161. };
  1162. /*****************************************************************************
  1163. *
  1164. * driver and module entry point
  1165. *
  1166. *****************************************************************************/
  1167. static int __init iwl_init(void)
  1168. {
  1169. int ret;
  1170. pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
  1171. pr_info(DRV_COPYRIGHT "\n");
  1172. ret = iwlagn_rate_control_register();
  1173. if (ret) {
  1174. pr_err("Unable to register rate control algorithm: %d\n", ret);
  1175. return ret;
  1176. }
  1177. ret = iwl_pci_register_driver();
  1178. if (ret)
  1179. goto error_register;
  1180. return ret;
  1181. error_register:
  1182. iwlagn_rate_control_unregister();
  1183. return ret;
  1184. }
  1185. static void __exit iwl_exit(void)
  1186. {
  1187. iwl_pci_unregister_driver();
  1188. iwlagn_rate_control_unregister();
  1189. }
  1190. module_exit(iwl_exit);
  1191. module_init(iwl_init);
  1192. #ifdef CONFIG_IWLWIFI_DEBUG
  1193. module_param_named(debug, iwlagn_mod_params.debug_level, uint,
  1194. S_IRUGO | S_IWUSR);
  1195. MODULE_PARM_DESC(debug, "debug output mask");
  1196. #endif
  1197. module_param_named(swcrypto, iwlagn_mod_params.sw_crypto, int, S_IRUGO);
  1198. MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
  1199. module_param_named(queues_num, iwlagn_mod_params.num_of_queues, int, S_IRUGO);
  1200. MODULE_PARM_DESC(queues_num, "number of hw queues.");
  1201. module_param_named(11n_disable, iwlagn_mod_params.disable_11n, uint, S_IRUGO);
  1202. MODULE_PARM_DESC(11n_disable,
  1203. "disable 11n functionality, bitmap: 1: full, 2: agg TX, 4: agg RX");
  1204. module_param_named(amsdu_size_8K, iwlagn_mod_params.amsdu_size_8K,
  1205. int, S_IRUGO);
  1206. MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
  1207. module_param_named(fw_restart, iwlagn_mod_params.restart_fw, int, S_IRUGO);
  1208. MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");
  1209. module_param_named(ucode_alternative,
  1210. iwlagn_mod_params.wanted_ucode_alternative,
  1211. int, S_IRUGO);
  1212. MODULE_PARM_DESC(ucode_alternative,
  1213. "specify ucode alternative to use from ucode file");
  1214. module_param_named(antenna_coupling, iwlagn_mod_params.ant_coupling,
  1215. int, S_IRUGO);
  1216. MODULE_PARM_DESC(antenna_coupling,
  1217. "specify antenna coupling in dB (defualt: 0 dB)");
  1218. module_param_named(bt_ch_inhibition, iwlagn_mod_params.bt_ch_announce,
  1219. bool, S_IRUGO);
  1220. MODULE_PARM_DESC(bt_ch_inhibition,
  1221. "Enable BT channel inhibition (default: enable)");
  1222. module_param_named(plcp_check, iwlagn_mod_params.plcp_check, bool, S_IRUGO);
  1223. MODULE_PARM_DESC(plcp_check, "Check plcp health (default: 1 [enabled])");
  1224. module_param_named(ack_check, iwlagn_mod_params.ack_check, bool, S_IRUGO);
  1225. MODULE_PARM_DESC(ack_check, "Check ack health (default: 0 [disabled])");
  1226. module_param_named(wd_disable, iwlagn_mod_params.wd_disable, int, S_IRUGO);
  1227. MODULE_PARM_DESC(wd_disable,
  1228. "Disable stuck queue watchdog timer 0=system default, "
  1229. "1=disable, 2=enable (default: 0)");
  1230. /*
  1231. * set bt_coex_active to true, uCode will do kill/defer
  1232. * every time the priority line is asserted (BT is sending signals on the
  1233. * priority line in the PCIx).
  1234. * set bt_coex_active to false, uCode will ignore the BT activity and
  1235. * perform the normal operation
  1236. *
  1237. * User might experience transmit issue on some platform due to WiFi/BT
  1238. * co-exist problem. The possible behaviors are:
  1239. * Able to scan and finding all the available AP
  1240. * Not able to associate with any AP
  1241. * On those platforms, WiFi communication can be restored by set
  1242. * "bt_coex_active" module parameter to "false"
  1243. *
  1244. * default: bt_coex_active = true (BT_COEX_ENABLE)
  1245. */
  1246. module_param_named(bt_coex_active, iwlagn_mod_params.bt_coex_active,
  1247. bool, S_IRUGO);
  1248. MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)");
  1249. module_param_named(led_mode, iwlagn_mod_params.led_mode, int, S_IRUGO);
  1250. MODULE_PARM_DESC(led_mode, "0=system default, "
  1251. "1=On(RF On)/Off(RF Off), 2=blinking, 3=Off (default: 0)");
  1252. module_param_named(power_save, iwlagn_mod_params.power_save,
  1253. bool, S_IRUGO);
  1254. MODULE_PARM_DESC(power_save,
  1255. "enable WiFi power management (default: disable)");
  1256. module_param_named(power_level, iwlagn_mod_params.power_level,
  1257. int, S_IRUGO);
  1258. MODULE_PARM_DESC(power_level,
  1259. "default power save level (range from 1 - 5, default: 1)");
  1260. module_param_named(auto_agg, iwlagn_mod_params.auto_agg,
  1261. bool, S_IRUGO);
  1262. MODULE_PARM_DESC(auto_agg,
  1263. "enable agg w/o check traffic load (default: enable)");
  1264. /*
  1265. * For now, keep using power level 1 instead of automatically
  1266. * adjusting ...
  1267. */
  1268. module_param_named(no_sleep_autoadjust, iwlagn_mod_params.no_sleep_autoadjust,
  1269. bool, S_IRUGO);
  1270. MODULE_PARM_DESC(no_sleep_autoadjust,
  1271. "don't automatically adjust sleep level "
  1272. "according to maximum network latency (default: true)");