iwl-agn.c 43 KB

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