main.c 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2013 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of version 2 of the GNU General Public License as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  30. #include <linux/kernel.h>
  31. #include <linux/module.h>
  32. #include <linux/init.h>
  33. #include <linux/slab.h>
  34. #include <linux/delay.h>
  35. #include <linux/sched.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/netdevice.h>
  38. #include <linux/etherdevice.h>
  39. #include <linux/if_arp.h>
  40. #include <net/mac80211.h>
  41. #include <asm/div64.h>
  42. #include "iwl-eeprom-read.h"
  43. #include "iwl-eeprom-parse.h"
  44. #include "iwl-io.h"
  45. #include "iwl-trans.h"
  46. #include "iwl-op-mode.h"
  47. #include "iwl-drv.h"
  48. #include "iwl-modparams.h"
  49. #include "iwl-prph.h"
  50. #include "dev.h"
  51. #include "calib.h"
  52. #include "agn.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. static const struct iwl_op_mode_ops iwl_dvm_ops;
  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->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. priv->nvm_data->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_dvm_send_cmd(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->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->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->status))
  211. return;
  212. /* dont send host command if rf-kill is on */
  213. if (!iwl_is_ready_rf(priv))
  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->mutex);
  223. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  224. goto out;
  225. /* dont send host command if rf-kill is on */
  226. if (!iwl_is_ready_rf(priv))
  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->mutex);
  242. }
  243. int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
  244. {
  245. struct iwl_statistics_cmd statistics_cmd = {
  246. .configuration_flags =
  247. clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
  248. };
  249. if (flags & CMD_ASYNC)
  250. return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
  251. CMD_ASYNC,
  252. sizeof(struct iwl_statistics_cmd),
  253. &statistics_cmd);
  254. else
  255. return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
  256. CMD_SYNC,
  257. sizeof(struct iwl_statistics_cmd),
  258. &statistics_cmd);
  259. }
  260. /**
  261. * iwl_bg_statistics_periodic - Timer callback to queue statistics
  262. *
  263. * This callback is provided in order to send a statistics request.
  264. *
  265. * This timer function is continually reset to execute within
  266. * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
  267. * was received. We need to ensure we receive the statistics in order
  268. * to update the temperature used for calibrating the TXPOWER.
  269. */
  270. static void iwl_bg_statistics_periodic(unsigned long data)
  271. {
  272. struct iwl_priv *priv = (struct iwl_priv *)data;
  273. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  274. return;
  275. /* dont send host command if rf-kill is on */
  276. if (!iwl_is_ready_rf(priv))
  277. return;
  278. iwl_send_statistics_request(priv, CMD_ASYNC, false);
  279. }
  280. static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base,
  281. u32 start_idx, u32 num_events,
  282. u32 capacity, u32 mode)
  283. {
  284. u32 i;
  285. u32 ptr; /* SRAM byte address of log data */
  286. u32 ev, time, data; /* event log data */
  287. unsigned long reg_flags;
  288. if (mode == 0)
  289. ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32));
  290. else
  291. ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32));
  292. /* Make sure device is powered up for SRAM reads */
  293. if (!iwl_trans_grab_nic_access(priv->trans, false, &reg_flags))
  294. return;
  295. /* Set starting address; reads will auto-increment */
  296. iwl_write32(priv->trans, HBUS_TARG_MEM_RADDR, ptr);
  297. /*
  298. * Refuse to read more than would have fit into the log from
  299. * the current start_idx. This used to happen due to the race
  300. * described below, but now WARN because the code below should
  301. * prevent it from happening here.
  302. */
  303. if (WARN_ON(num_events > capacity - start_idx))
  304. num_events = capacity - start_idx;
  305. /*
  306. * "time" is actually "data" for mode 0 (no timestamp).
  307. * place event id # at far right for easier visual parsing.
  308. */
  309. for (i = 0; i < num_events; i++) {
  310. ev = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT);
  311. time = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT);
  312. if (mode == 0) {
  313. trace_iwlwifi_dev_ucode_cont_event(
  314. priv->trans->dev, 0, time, ev);
  315. } else {
  316. data = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT);
  317. trace_iwlwifi_dev_ucode_cont_event(
  318. priv->trans->dev, time, data, ev);
  319. }
  320. }
  321. /* Allow device to power down */
  322. iwl_trans_release_nic_access(priv->trans, &reg_flags);
  323. }
  324. static void iwl_continuous_event_trace(struct iwl_priv *priv)
  325. {
  326. u32 capacity; /* event log capacity in # entries */
  327. struct {
  328. u32 capacity;
  329. u32 mode;
  330. u32 wrap_counter;
  331. u32 write_counter;
  332. } __packed read;
  333. u32 base; /* SRAM byte address of event log header */
  334. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  335. u32 num_wraps; /* # times uCode wrapped to top of log */
  336. u32 next_entry; /* index of next entry to be written by uCode */
  337. base = priv->device_pointers.log_event_table;
  338. if (iwlagn_hw_valid_rtc_data_addr(base)) {
  339. iwl_trans_read_mem_bytes(priv->trans, base,
  340. &read, sizeof(read));
  341. capacity = read.capacity;
  342. mode = read.mode;
  343. num_wraps = read.wrap_counter;
  344. next_entry = read.write_counter;
  345. } else
  346. return;
  347. /*
  348. * Unfortunately, the uCode doesn't use temporary variables.
  349. * Therefore, it can happen that we read next_entry == capacity,
  350. * which really means next_entry == 0.
  351. */
  352. if (unlikely(next_entry == capacity))
  353. next_entry = 0;
  354. /*
  355. * Additionally, the uCode increases the write pointer before
  356. * the wraps counter, so if the write pointer is smaller than
  357. * the old write pointer (wrap occurred) but we read that no
  358. * wrap occurred, we actually read between the next_entry and
  359. * num_wraps update (this does happen in practice!!) -- take
  360. * that into account by increasing num_wraps.
  361. */
  362. if (unlikely(next_entry < priv->event_log.next_entry &&
  363. num_wraps == priv->event_log.num_wraps))
  364. num_wraps++;
  365. if (num_wraps == priv->event_log.num_wraps) {
  366. iwl_print_cont_event_trace(
  367. priv, base, priv->event_log.next_entry,
  368. next_entry - priv->event_log.next_entry,
  369. capacity, mode);
  370. priv->event_log.non_wraps_count++;
  371. } else {
  372. if (num_wraps - priv->event_log.num_wraps > 1)
  373. priv->event_log.wraps_more_count++;
  374. else
  375. priv->event_log.wraps_once_count++;
  376. trace_iwlwifi_dev_ucode_wrap_event(priv->trans->dev,
  377. num_wraps - priv->event_log.num_wraps,
  378. next_entry, priv->event_log.next_entry);
  379. if (next_entry < priv->event_log.next_entry) {
  380. iwl_print_cont_event_trace(
  381. priv, base, priv->event_log.next_entry,
  382. capacity - priv->event_log.next_entry,
  383. capacity, mode);
  384. iwl_print_cont_event_trace(
  385. priv, base, 0, next_entry, capacity, mode);
  386. } else {
  387. iwl_print_cont_event_trace(
  388. priv, base, next_entry,
  389. capacity - next_entry,
  390. capacity, mode);
  391. iwl_print_cont_event_trace(
  392. priv, base, 0, next_entry, capacity, mode);
  393. }
  394. }
  395. priv->event_log.num_wraps = num_wraps;
  396. priv->event_log.next_entry = next_entry;
  397. }
  398. /**
  399. * iwl_bg_ucode_trace - Timer callback to log ucode event
  400. *
  401. * The timer is continually set to execute every
  402. * UCODE_TRACE_PERIOD milliseconds after the last timer expired
  403. * this function is to perform continuous uCode event logging operation
  404. * if enabled
  405. */
  406. static void iwl_bg_ucode_trace(unsigned long data)
  407. {
  408. struct iwl_priv *priv = (struct iwl_priv *)data;
  409. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  410. return;
  411. if (priv->event_log.ucode_trace) {
  412. iwl_continuous_event_trace(priv);
  413. /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
  414. mod_timer(&priv->ucode_trace,
  415. jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
  416. }
  417. }
  418. static void iwl_bg_tx_flush(struct work_struct *work)
  419. {
  420. struct iwl_priv *priv =
  421. container_of(work, struct iwl_priv, tx_flush);
  422. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  423. return;
  424. /* do nothing if rf-kill is on */
  425. if (!iwl_is_ready_rf(priv))
  426. return;
  427. IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n");
  428. iwlagn_dev_txfifo_flush(priv);
  429. }
  430. /*
  431. * queue/FIFO/AC mapping definitions
  432. */
  433. static const u8 iwlagn_bss_ac_to_fifo[] = {
  434. IWL_TX_FIFO_VO,
  435. IWL_TX_FIFO_VI,
  436. IWL_TX_FIFO_BE,
  437. IWL_TX_FIFO_BK,
  438. };
  439. static const u8 iwlagn_bss_ac_to_queue[] = {
  440. 0, 1, 2, 3,
  441. };
  442. static const u8 iwlagn_pan_ac_to_fifo[] = {
  443. IWL_TX_FIFO_VO_IPAN,
  444. IWL_TX_FIFO_VI_IPAN,
  445. IWL_TX_FIFO_BE_IPAN,
  446. IWL_TX_FIFO_BK_IPAN,
  447. };
  448. static const u8 iwlagn_pan_ac_to_queue[] = {
  449. 7, 6, 5, 4,
  450. };
  451. static void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags)
  452. {
  453. int i;
  454. /*
  455. * The default context is always valid,
  456. * the PAN context depends on uCode.
  457. */
  458. priv->valid_contexts = BIT(IWL_RXON_CTX_BSS);
  459. if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN)
  460. priv->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
  461. for (i = 0; i < NUM_IWL_RXON_CTX; i++)
  462. priv->contexts[i].ctxid = i;
  463. priv->contexts[IWL_RXON_CTX_BSS].always_active = true;
  464. priv->contexts[IWL_RXON_CTX_BSS].is_active = true;
  465. priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
  466. priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
  467. priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
  468. priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
  469. priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
  470. priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
  471. priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
  472. priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
  473. BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_MONITOR);
  474. priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
  475. BIT(NL80211_IFTYPE_STATION);
  476. priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP;
  477. priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
  478. priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
  479. priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
  480. memcpy(priv->contexts[IWL_RXON_CTX_BSS].ac_to_queue,
  481. iwlagn_bss_ac_to_queue, sizeof(iwlagn_bss_ac_to_queue));
  482. memcpy(priv->contexts[IWL_RXON_CTX_BSS].ac_to_fifo,
  483. iwlagn_bss_ac_to_fifo, sizeof(iwlagn_bss_ac_to_fifo));
  484. priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON;
  485. priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd =
  486. REPLY_WIPAN_RXON_TIMING;
  487. priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd =
  488. REPLY_WIPAN_RXON_ASSOC;
  489. priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM;
  490. priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN;
  491. priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY;
  492. priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID;
  493. priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION;
  494. priv->contexts[IWL_RXON_CTX_PAN].interface_modes =
  495. BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
  496. priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP;
  497. priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA;
  498. priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P;
  499. memcpy(priv->contexts[IWL_RXON_CTX_PAN].ac_to_queue,
  500. iwlagn_pan_ac_to_queue, sizeof(iwlagn_pan_ac_to_queue));
  501. memcpy(priv->contexts[IWL_RXON_CTX_PAN].ac_to_fifo,
  502. iwlagn_pan_ac_to_fifo, sizeof(iwlagn_pan_ac_to_fifo));
  503. priv->contexts[IWL_RXON_CTX_PAN].mcast_queue = IWL_IPAN_MCAST_QUEUE;
  504. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  505. }
  506. static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
  507. {
  508. struct iwl_ct_kill_config cmd;
  509. struct iwl_ct_kill_throttling_config adv_cmd;
  510. int ret = 0;
  511. iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR,
  512. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  513. priv->thermal_throttle.ct_kill_toggle = false;
  514. if (priv->lib->support_ct_kill_exit) {
  515. adv_cmd.critical_temperature_enter =
  516. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  517. adv_cmd.critical_temperature_exit =
  518. cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
  519. ret = iwl_dvm_send_cmd_pdu(priv,
  520. REPLY_CT_KILL_CONFIG_CMD,
  521. CMD_SYNC, sizeof(adv_cmd), &adv_cmd);
  522. if (ret)
  523. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  524. else
  525. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  526. "succeeded, critical temperature enter is %d,"
  527. "exit is %d\n",
  528. priv->hw_params.ct_kill_threshold,
  529. priv->hw_params.ct_kill_exit_threshold);
  530. } else {
  531. cmd.critical_temperature_R =
  532. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  533. ret = iwl_dvm_send_cmd_pdu(priv,
  534. REPLY_CT_KILL_CONFIG_CMD,
  535. CMD_SYNC, sizeof(cmd), &cmd);
  536. if (ret)
  537. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  538. else
  539. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  540. "succeeded, "
  541. "critical temperature is %d\n",
  542. priv->hw_params.ct_kill_threshold);
  543. }
  544. }
  545. static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
  546. {
  547. struct iwl_calib_cfg_cmd calib_cfg_cmd;
  548. struct iwl_host_cmd cmd = {
  549. .id = CALIBRATION_CFG_CMD,
  550. .len = { sizeof(struct iwl_calib_cfg_cmd), },
  551. .data = { &calib_cfg_cmd, },
  552. };
  553. memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
  554. calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_RT_CFG_ALL;
  555. calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg);
  556. return iwl_dvm_send_cmd(priv, &cmd);
  557. }
  558. static int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant)
  559. {
  560. struct iwl_tx_ant_config_cmd tx_ant_cmd = {
  561. .valid = cpu_to_le32(valid_tx_ant),
  562. };
  563. if (IWL_UCODE_API(priv->fw->ucode_ver) > 1) {
  564. IWL_DEBUG_HC(priv, "select valid tx ant: %u\n", valid_tx_ant);
  565. return iwl_dvm_send_cmd_pdu(priv,
  566. TX_ANT_CONFIGURATION_CMD,
  567. CMD_SYNC,
  568. sizeof(struct iwl_tx_ant_config_cmd),
  569. &tx_ant_cmd);
  570. } else {
  571. IWL_DEBUG_HC(priv, "TX_ANT_CONFIGURATION_CMD not supported\n");
  572. return -EOPNOTSUPP;
  573. }
  574. }
  575. static void iwl_send_bt_config(struct iwl_priv *priv)
  576. {
  577. struct iwl_bt_cmd bt_cmd = {
  578. .lead_time = BT_LEAD_TIME_DEF,
  579. .max_kill = BT_MAX_KILL_DEF,
  580. .kill_ack_mask = 0,
  581. .kill_cts_mask = 0,
  582. };
  583. if (!iwlwifi_mod_params.bt_coex_active)
  584. bt_cmd.flags = BT_COEX_DISABLE;
  585. else
  586. bt_cmd.flags = BT_COEX_ENABLE;
  587. priv->bt_enable_flag = bt_cmd.flags;
  588. IWL_DEBUG_INFO(priv, "BT coex %s\n",
  589. (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
  590. if (iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  591. CMD_SYNC, sizeof(struct iwl_bt_cmd), &bt_cmd))
  592. IWL_ERR(priv, "failed to send BT Coex Config\n");
  593. }
  594. /**
  595. * iwl_alive_start - called after REPLY_ALIVE notification received
  596. * from protocol/runtime uCode (initialization uCode's
  597. * Alive gets handled by iwl_init_alive_start()).
  598. */
  599. int iwl_alive_start(struct iwl_priv *priv)
  600. {
  601. int ret = 0;
  602. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  603. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  604. /* After the ALIVE response, we can send host commands to the uCode */
  605. set_bit(STATUS_ALIVE, &priv->status);
  606. if (iwl_is_rfkill(priv))
  607. return -ERFKILL;
  608. if (priv->event_log.ucode_trace) {
  609. /* start collecting data now */
  610. mod_timer(&priv->ucode_trace, jiffies);
  611. }
  612. /* download priority table before any calibration request */
  613. if (priv->lib->bt_params &&
  614. priv->lib->bt_params->advanced_bt_coexist) {
  615. /* Configure Bluetooth device coexistence support */
  616. if (priv->lib->bt_params->bt_sco_disable)
  617. priv->bt_enable_pspoll = false;
  618. else
  619. priv->bt_enable_pspoll = true;
  620. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  621. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  622. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  623. iwlagn_send_advance_bt_config(priv);
  624. priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS;
  625. priv->cur_rssi_ctx = NULL;
  626. iwl_send_prio_tbl(priv);
  627. /* FIXME: w/a to force change uCode BT state machine */
  628. ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
  629. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  630. if (ret)
  631. return ret;
  632. ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
  633. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  634. if (ret)
  635. return ret;
  636. } else if (priv->lib->bt_params) {
  637. /*
  638. * default is 2-wire BT coexexistence support
  639. */
  640. iwl_send_bt_config(priv);
  641. }
  642. /*
  643. * Perform runtime calibrations, including DC calibration.
  644. */
  645. iwlagn_send_calib_cfg_rt(priv, IWL_CALIB_CFG_DC_IDX);
  646. ieee80211_wake_queues(priv->hw);
  647. /* Configure Tx antenna selection based on H/W config */
  648. iwlagn_send_tx_ant_config(priv, priv->nvm_data->valid_tx_ant);
  649. if (iwl_is_associated_ctx(ctx) && !priv->wowlan) {
  650. struct iwl_rxon_cmd *active_rxon =
  651. (struct iwl_rxon_cmd *)&ctx->active;
  652. /* apply any changes in staging */
  653. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  654. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  655. } else {
  656. struct iwl_rxon_context *tmp;
  657. /* Initialize our rx_config data */
  658. for_each_context(priv, tmp)
  659. iwl_connection_init_rx_config(priv, tmp);
  660. iwlagn_set_rxon_chain(priv, ctx);
  661. }
  662. if (!priv->wowlan) {
  663. /* WoWLAN ucode will not reply in the same way, skip it */
  664. iwl_reset_run_time_calib(priv);
  665. }
  666. set_bit(STATUS_READY, &priv->status);
  667. /* Configure the adapter for unassociated operation */
  668. ret = iwlagn_commit_rxon(priv, ctx);
  669. if (ret)
  670. return ret;
  671. /* At this point, the NIC is initialized and operational */
  672. iwl_rf_kill_ct_config(priv);
  673. IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
  674. return iwl_power_update_mode(priv, true);
  675. }
  676. /**
  677. * iwl_clear_driver_stations - clear knowledge of all stations from driver
  678. * @priv: iwl priv struct
  679. *
  680. * This is called during iwl_down() to make sure that in the case
  681. * we're coming there from a hardware restart mac80211 will be
  682. * able to reconfigure stations -- if we're getting there in the
  683. * normal down flow then the stations will already be cleared.
  684. */
  685. static void iwl_clear_driver_stations(struct iwl_priv *priv)
  686. {
  687. struct iwl_rxon_context *ctx;
  688. spin_lock_bh(&priv->sta_lock);
  689. memset(priv->stations, 0, sizeof(priv->stations));
  690. priv->num_stations = 0;
  691. priv->ucode_key_table = 0;
  692. for_each_context(priv, ctx) {
  693. /*
  694. * Remove all key information that is not stored as part
  695. * of station information since mac80211 may not have had
  696. * a chance to remove all the keys. When device is
  697. * reconfigured by mac80211 after an error all keys will
  698. * be reconfigured.
  699. */
  700. memset(ctx->wep_keys, 0, sizeof(ctx->wep_keys));
  701. ctx->key_mapping_keys = 0;
  702. }
  703. spin_unlock_bh(&priv->sta_lock);
  704. }
  705. void iwl_down(struct iwl_priv *priv)
  706. {
  707. int exit_pending;
  708. IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
  709. lockdep_assert_held(&priv->mutex);
  710. iwl_scan_cancel_timeout(priv, 200);
  711. exit_pending =
  712. test_and_set_bit(STATUS_EXIT_PENDING, &priv->status);
  713. iwl_clear_ucode_stations(priv, NULL);
  714. iwl_dealloc_bcast_stations(priv);
  715. iwl_clear_driver_stations(priv);
  716. /* reset BT coex data */
  717. priv->bt_status = 0;
  718. priv->cur_rssi_ctx = NULL;
  719. priv->bt_is_sco = 0;
  720. if (priv->lib->bt_params)
  721. priv->bt_traffic_load =
  722. priv->lib->bt_params->bt_init_traffic_load;
  723. else
  724. priv->bt_traffic_load = 0;
  725. priv->bt_full_concurrent = false;
  726. priv->bt_ci_compliance = 0;
  727. /* Wipe out the EXIT_PENDING status bit if we are not actually
  728. * exiting the module */
  729. if (!exit_pending)
  730. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  731. if (priv->mac80211_registered)
  732. ieee80211_stop_queues(priv->hw);
  733. priv->ucode_loaded = false;
  734. iwl_trans_stop_device(priv->trans);
  735. /* Set num_aux_in_flight must be done after the transport is stopped */
  736. atomic_set(&priv->num_aux_in_flight, 0);
  737. /* Clear out all status bits but a few that are stable across reset */
  738. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  739. STATUS_RF_KILL_HW |
  740. test_bit(STATUS_FW_ERROR, &priv->status) <<
  741. STATUS_FW_ERROR |
  742. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  743. STATUS_EXIT_PENDING;
  744. dev_kfree_skb(priv->beacon_skb);
  745. priv->beacon_skb = NULL;
  746. }
  747. /*****************************************************************************
  748. *
  749. * Workqueue callbacks
  750. *
  751. *****************************************************************************/
  752. static void iwl_bg_run_time_calib_work(struct work_struct *work)
  753. {
  754. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  755. run_time_calib_work);
  756. mutex_lock(&priv->mutex);
  757. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  758. test_bit(STATUS_SCANNING, &priv->status)) {
  759. mutex_unlock(&priv->mutex);
  760. return;
  761. }
  762. if (priv->start_calib) {
  763. iwl_chain_noise_calibration(priv);
  764. iwl_sensitivity_calibration(priv);
  765. }
  766. mutex_unlock(&priv->mutex);
  767. }
  768. void iwlagn_prepare_restart(struct iwl_priv *priv)
  769. {
  770. bool bt_full_concurrent;
  771. u8 bt_ci_compliance;
  772. u8 bt_load;
  773. u8 bt_status;
  774. bool bt_is_sco;
  775. int i;
  776. lockdep_assert_held(&priv->mutex);
  777. priv->is_open = 0;
  778. /*
  779. * __iwl_down() will clear the BT status variables,
  780. * which is correct, but when we restart we really
  781. * want to keep them so restore them afterwards.
  782. *
  783. * The restart process will later pick them up and
  784. * re-configure the hw when we reconfigure the BT
  785. * command.
  786. */
  787. bt_full_concurrent = priv->bt_full_concurrent;
  788. bt_ci_compliance = priv->bt_ci_compliance;
  789. bt_load = priv->bt_traffic_load;
  790. bt_status = priv->bt_status;
  791. bt_is_sco = priv->bt_is_sco;
  792. iwl_down(priv);
  793. priv->bt_full_concurrent = bt_full_concurrent;
  794. priv->bt_ci_compliance = bt_ci_compliance;
  795. priv->bt_traffic_load = bt_load;
  796. priv->bt_status = bt_status;
  797. priv->bt_is_sco = bt_is_sco;
  798. /* reset aggregation queues */
  799. for (i = IWLAGN_FIRST_AMPDU_QUEUE; i < IWL_MAX_HW_QUEUES; i++)
  800. priv->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE;
  801. /* and stop counts */
  802. for (i = 0; i < IWL_MAX_HW_QUEUES; i++)
  803. atomic_set(&priv->queue_stop_count[i], 0);
  804. memset(priv->agg_q_alloc, 0, sizeof(priv->agg_q_alloc));
  805. }
  806. static void iwl_bg_restart(struct work_struct *data)
  807. {
  808. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  809. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  810. return;
  811. if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
  812. mutex_lock(&priv->mutex);
  813. iwlagn_prepare_restart(priv);
  814. mutex_unlock(&priv->mutex);
  815. iwl_cancel_deferred_work(priv);
  816. if (priv->mac80211_registered)
  817. ieee80211_restart_hw(priv->hw);
  818. else
  819. IWL_ERR(priv,
  820. "Cannot request restart before registrating with mac80211");
  821. } else {
  822. WARN_ON(1);
  823. }
  824. }
  825. /*****************************************************************************
  826. *
  827. * driver setup and teardown
  828. *
  829. *****************************************************************************/
  830. static void iwl_setup_deferred_work(struct iwl_priv *priv)
  831. {
  832. priv->workqueue = create_singlethread_workqueue(DRV_NAME);
  833. INIT_WORK(&priv->restart, iwl_bg_restart);
  834. INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
  835. INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
  836. INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
  837. INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
  838. INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
  839. iwl_setup_scan_deferred_work(priv);
  840. if (priv->lib->bt_params)
  841. iwlagn_bt_setup_deferred_work(priv);
  842. init_timer(&priv->statistics_periodic);
  843. priv->statistics_periodic.data = (unsigned long)priv;
  844. priv->statistics_periodic.function = iwl_bg_statistics_periodic;
  845. init_timer(&priv->ucode_trace);
  846. priv->ucode_trace.data = (unsigned long)priv;
  847. priv->ucode_trace.function = iwl_bg_ucode_trace;
  848. }
  849. void iwl_cancel_deferred_work(struct iwl_priv *priv)
  850. {
  851. if (priv->lib->bt_params)
  852. iwlagn_bt_cancel_deferred_work(priv);
  853. cancel_work_sync(&priv->run_time_calib_work);
  854. cancel_work_sync(&priv->beacon_update);
  855. iwl_cancel_scan_deferred_work(priv);
  856. cancel_work_sync(&priv->bt_full_concurrency);
  857. cancel_work_sync(&priv->bt_runtime_config);
  858. del_timer_sync(&priv->statistics_periodic);
  859. del_timer_sync(&priv->ucode_trace);
  860. }
  861. static int iwl_init_drv(struct iwl_priv *priv)
  862. {
  863. spin_lock_init(&priv->sta_lock);
  864. mutex_init(&priv->mutex);
  865. INIT_LIST_HEAD(&priv->calib_results);
  866. priv->band = IEEE80211_BAND_2GHZ;
  867. priv->plcp_delta_threshold = priv->lib->plcp_delta_threshold;
  868. priv->iw_mode = NL80211_IFTYPE_STATION;
  869. priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
  870. priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
  871. priv->agg_tids_count = 0;
  872. priv->rx_statistics_jiffies = jiffies;
  873. /* Choose which receivers/antennas to use */
  874. iwlagn_set_rxon_chain(priv, &priv->contexts[IWL_RXON_CTX_BSS]);
  875. iwl_init_scan_params(priv);
  876. /* init bt coex */
  877. if (priv->lib->bt_params &&
  878. priv->lib->bt_params->advanced_bt_coexist) {
  879. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  880. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  881. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  882. priv->bt_on_thresh = BT_ON_THRESHOLD_DEF;
  883. priv->bt_duration = BT_DURATION_LIMIT_DEF;
  884. priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
  885. }
  886. return 0;
  887. }
  888. static void iwl_uninit_drv(struct iwl_priv *priv)
  889. {
  890. kfree(priv->scan_cmd);
  891. kfree(priv->beacon_cmd);
  892. kfree(rcu_dereference_raw(priv->noa_data));
  893. iwl_calib_free_results(priv);
  894. #ifdef CONFIG_IWLWIFI_DEBUGFS
  895. kfree(priv->wowlan_sram);
  896. #endif
  897. }
  898. static void iwl_set_hw_params(struct iwl_priv *priv)
  899. {
  900. if (priv->cfg->ht_params)
  901. priv->hw_params.use_rts_for_aggregation =
  902. priv->cfg->ht_params->use_rts_for_aggregation;
  903. /* Device-specific setup */
  904. priv->lib->set_hw_params(priv);
  905. }
  906. /* show what optional capabilities we have */
  907. static void iwl_option_config(struct iwl_priv *priv)
  908. {
  909. #ifdef CONFIG_IWLWIFI_DEBUG
  910. IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUG enabled\n");
  911. #else
  912. IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUG disabled\n");
  913. #endif
  914. #ifdef CONFIG_IWLWIFI_DEBUGFS
  915. IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUGFS enabled\n");
  916. #else
  917. IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUGFS disabled\n");
  918. #endif
  919. #ifdef CONFIG_IWLWIFI_DEVICE_TRACING
  920. IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TRACING enabled\n");
  921. #else
  922. IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TRACING disabled\n");
  923. #endif
  924. }
  925. static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
  926. {
  927. struct iwl_nvm_data *data = priv->nvm_data;
  928. char *debug_msg;
  929. if (data->sku_cap_11n_enable &&
  930. !priv->cfg->ht_params) {
  931. IWL_ERR(priv, "Invalid 11n configuration\n");
  932. return -EINVAL;
  933. }
  934. if (!data->sku_cap_11n_enable && !data->sku_cap_band_24GHz_enable &&
  935. !data->sku_cap_band_52GHz_enable) {
  936. IWL_ERR(priv, "Invalid device sku\n");
  937. return -EINVAL;
  938. }
  939. debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
  940. IWL_DEBUG_INFO(priv, debug_msg,
  941. data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
  942. data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
  943. data->sku_cap_11n_enable ? "" : "NOT", "enabled");
  944. priv->hw_params.tx_chains_num =
  945. num_of_ant(data->valid_tx_ant);
  946. if (priv->cfg->rx_with_siso_diversity)
  947. priv->hw_params.rx_chains_num = 1;
  948. else
  949. priv->hw_params.rx_chains_num =
  950. num_of_ant(data->valid_rx_ant);
  951. IWL_DEBUG_INFO(priv, "Valid Tx ant: 0x%X, Valid Rx ant: 0x%X\n",
  952. data->valid_tx_ant,
  953. data->valid_rx_ant);
  954. return 0;
  955. }
  956. static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
  957. const struct iwl_cfg *cfg,
  958. const struct iwl_fw *fw,
  959. struct dentry *dbgfs_dir)
  960. {
  961. struct iwl_priv *priv;
  962. struct ieee80211_hw *hw;
  963. struct iwl_op_mode *op_mode;
  964. u16 num_mac;
  965. u32 ucode_flags;
  966. struct iwl_trans_config trans_cfg = {};
  967. static const u8 no_reclaim_cmds[] = {
  968. REPLY_RX_PHY_CMD,
  969. REPLY_RX_MPDU_CMD,
  970. REPLY_COMPRESSED_BA,
  971. STATISTICS_NOTIFICATION,
  972. REPLY_TX,
  973. };
  974. int i;
  975. /************************
  976. * 1. Allocating HW data
  977. ************************/
  978. hw = iwl_alloc_all();
  979. if (!hw) {
  980. pr_err("%s: Cannot allocate network device\n", cfg->name);
  981. goto out;
  982. }
  983. op_mode = hw->priv;
  984. op_mode->ops = &iwl_dvm_ops;
  985. priv = IWL_OP_MODE_GET_DVM(op_mode);
  986. priv->trans = trans;
  987. priv->dev = trans->dev;
  988. priv->cfg = cfg;
  989. priv->fw = fw;
  990. switch (priv->cfg->device_family) {
  991. case IWL_DEVICE_FAMILY_1000:
  992. case IWL_DEVICE_FAMILY_100:
  993. priv->lib = &iwl_dvm_1000_cfg;
  994. break;
  995. case IWL_DEVICE_FAMILY_2000:
  996. priv->lib = &iwl_dvm_2000_cfg;
  997. break;
  998. case IWL_DEVICE_FAMILY_105:
  999. priv->lib = &iwl_dvm_105_cfg;
  1000. break;
  1001. case IWL_DEVICE_FAMILY_2030:
  1002. case IWL_DEVICE_FAMILY_135:
  1003. priv->lib = &iwl_dvm_2030_cfg;
  1004. break;
  1005. case IWL_DEVICE_FAMILY_5000:
  1006. priv->lib = &iwl_dvm_5000_cfg;
  1007. break;
  1008. case IWL_DEVICE_FAMILY_5150:
  1009. priv->lib = &iwl_dvm_5150_cfg;
  1010. break;
  1011. case IWL_DEVICE_FAMILY_6000:
  1012. case IWL_DEVICE_FAMILY_6000i:
  1013. priv->lib = &iwl_dvm_6000_cfg;
  1014. break;
  1015. case IWL_DEVICE_FAMILY_6005:
  1016. priv->lib = &iwl_dvm_6005_cfg;
  1017. break;
  1018. case IWL_DEVICE_FAMILY_6050:
  1019. case IWL_DEVICE_FAMILY_6150:
  1020. priv->lib = &iwl_dvm_6050_cfg;
  1021. break;
  1022. case IWL_DEVICE_FAMILY_6030:
  1023. priv->lib = &iwl_dvm_6030_cfg;
  1024. break;
  1025. default:
  1026. break;
  1027. }
  1028. if (WARN_ON(!priv->lib))
  1029. goto out_free_hw;
  1030. /*
  1031. * Populate the state variables that the transport layer needs
  1032. * to know about.
  1033. */
  1034. trans_cfg.op_mode = op_mode;
  1035. trans_cfg.no_reclaim_cmds = no_reclaim_cmds;
  1036. trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
  1037. trans_cfg.rx_buf_size_8k = iwlwifi_mod_params.amsdu_size_8K;
  1038. if (!iwlwifi_mod_params.wd_disable)
  1039. trans_cfg.queue_watchdog_timeout =
  1040. priv->cfg->base_params->wd_timeout;
  1041. else
  1042. trans_cfg.queue_watchdog_timeout = IWL_WATCHDOG_DISABLED;
  1043. trans_cfg.command_names = iwl_dvm_cmd_strings;
  1044. trans_cfg.cmd_fifo = IWLAGN_CMD_FIFO_NUM;
  1045. WARN_ON(sizeof(priv->transport_queue_stop) * BITS_PER_BYTE <
  1046. priv->cfg->base_params->num_of_queues);
  1047. ucode_flags = fw->ucode_capa.flags;
  1048. if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN) {
  1049. priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
  1050. trans_cfg.cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
  1051. } else {
  1052. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  1053. trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  1054. }
  1055. /* Configure transport layer */
  1056. iwl_trans_configure(priv->trans, &trans_cfg);
  1057. trans->rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
  1058. trans->rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_res_start);
  1059. /* At this point both hw and priv are allocated. */
  1060. SET_IEEE80211_DEV(priv->hw, priv->trans->dev);
  1061. iwl_option_config(priv);
  1062. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  1063. /* is antenna coupling more than 35dB ? */
  1064. priv->bt_ant_couple_ok =
  1065. (iwlwifi_mod_params.ant_coupling >
  1066. IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
  1067. true : false;
  1068. /* bt channel inhibition enabled*/
  1069. priv->bt_ch_announce = true;
  1070. IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n",
  1071. (priv->bt_ch_announce) ? "On" : "Off");
  1072. /* these spin locks will be used in apm_ops.init and EEPROM access
  1073. * we should init now
  1074. */
  1075. spin_lock_init(&priv->statistics.lock);
  1076. /***********************
  1077. * 2. Read REV register
  1078. ***********************/
  1079. IWL_INFO(priv, "Detected %s, REV=0x%X\n",
  1080. priv->cfg->name, priv->trans->hw_rev);
  1081. if (iwl_trans_start_hw(priv->trans))
  1082. goto out_free_hw;
  1083. /* Read the EEPROM */
  1084. if (iwl_read_eeprom(priv->trans, &priv->eeprom_blob,
  1085. &priv->eeprom_blob_size)) {
  1086. IWL_ERR(priv, "Unable to init EEPROM\n");
  1087. goto out_free_hw;
  1088. }
  1089. /* Reset chip to save power until we load uCode during "up". */
  1090. iwl_trans_stop_hw(priv->trans, false);
  1091. priv->nvm_data = iwl_parse_eeprom_data(priv->trans->dev, priv->cfg,
  1092. priv->eeprom_blob,
  1093. priv->eeprom_blob_size);
  1094. if (!priv->nvm_data)
  1095. goto out_free_eeprom_blob;
  1096. if (iwl_nvm_check_version(priv->nvm_data, priv->trans))
  1097. goto out_free_eeprom;
  1098. if (iwl_eeprom_init_hw_params(priv))
  1099. goto out_free_eeprom;
  1100. /* extract MAC Address */
  1101. memcpy(priv->addresses[0].addr, priv->nvm_data->hw_addr, ETH_ALEN);
  1102. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
  1103. priv->hw->wiphy->addresses = priv->addresses;
  1104. priv->hw->wiphy->n_addresses = 1;
  1105. num_mac = priv->nvm_data->n_hw_addrs;
  1106. if (num_mac > 1) {
  1107. memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
  1108. ETH_ALEN);
  1109. priv->addresses[1].addr[5]++;
  1110. priv->hw->wiphy->n_addresses++;
  1111. }
  1112. /************************
  1113. * 4. Setup HW constants
  1114. ************************/
  1115. iwl_set_hw_params(priv);
  1116. if (!(priv->nvm_data->sku_cap_ipan_enable)) {
  1117. IWL_DEBUG_INFO(priv, "Your EEPROM disabled PAN");
  1118. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
  1119. /*
  1120. * if not PAN, then don't support P2P -- might be a uCode
  1121. * packaging bug or due to the eeprom check above
  1122. */
  1123. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  1124. trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  1125. /* Configure transport layer again*/
  1126. iwl_trans_configure(priv->trans, &trans_cfg);
  1127. }
  1128. /*******************
  1129. * 5. Setup priv
  1130. *******************/
  1131. for (i = 0; i < IWL_MAX_HW_QUEUES; i++) {
  1132. priv->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE;
  1133. if (i < IWLAGN_FIRST_AMPDU_QUEUE &&
  1134. i != IWL_DEFAULT_CMD_QUEUE_NUM &&
  1135. i != IWL_IPAN_CMD_QUEUE_NUM)
  1136. priv->queue_to_mac80211[i] = i;
  1137. atomic_set(&priv->queue_stop_count[i], 0);
  1138. }
  1139. if (iwl_init_drv(priv))
  1140. goto out_free_eeprom;
  1141. /* At this point both hw and priv are initialized. */
  1142. /********************
  1143. * 6. Setup services
  1144. ********************/
  1145. iwl_setup_deferred_work(priv);
  1146. iwl_setup_rx_handlers(priv);
  1147. iwl_power_initialize(priv);
  1148. iwl_tt_initialize(priv);
  1149. snprintf(priv->hw->wiphy->fw_version,
  1150. sizeof(priv->hw->wiphy->fw_version),
  1151. "%s", fw->fw_version);
  1152. priv->new_scan_threshold_behaviour =
  1153. !!(ucode_flags & IWL_UCODE_TLV_FLAGS_NEWSCAN);
  1154. priv->phy_calib_chain_noise_reset_cmd =
  1155. fw->ucode_capa.standard_phy_calibration_size;
  1156. priv->phy_calib_chain_noise_gain_cmd =
  1157. fw->ucode_capa.standard_phy_calibration_size + 1;
  1158. /* initialize all valid contexts */
  1159. iwl_init_context(priv, ucode_flags);
  1160. /**************************************************
  1161. * This is still part of probe() in a sense...
  1162. *
  1163. * 7. Setup and register with mac80211 and debugfs
  1164. **************************************************/
  1165. if (iwlagn_mac_setup_register(priv, &fw->ucode_capa))
  1166. goto out_destroy_workqueue;
  1167. if (iwl_dbgfs_register(priv, dbgfs_dir))
  1168. goto out_mac80211_unregister;
  1169. return op_mode;
  1170. out_mac80211_unregister:
  1171. iwlagn_mac_unregister(priv);
  1172. out_destroy_workqueue:
  1173. iwl_tt_exit(priv);
  1174. iwl_cancel_deferred_work(priv);
  1175. destroy_workqueue(priv->workqueue);
  1176. priv->workqueue = NULL;
  1177. iwl_uninit_drv(priv);
  1178. out_free_eeprom_blob:
  1179. kfree(priv->eeprom_blob);
  1180. out_free_eeprom:
  1181. iwl_free_nvm_data(priv->nvm_data);
  1182. out_free_hw:
  1183. ieee80211_free_hw(priv->hw);
  1184. out:
  1185. op_mode = NULL;
  1186. return op_mode;
  1187. }
  1188. static void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode)
  1189. {
  1190. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1191. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  1192. iwlagn_mac_unregister(priv);
  1193. iwl_tt_exit(priv);
  1194. kfree(priv->eeprom_blob);
  1195. iwl_free_nvm_data(priv->nvm_data);
  1196. /*netif_stop_queue(dev); */
  1197. flush_workqueue(priv->workqueue);
  1198. /* ieee80211_unregister_hw calls iwlagn_mac_stop, which flushes
  1199. * priv->workqueue... so we can't take down the workqueue
  1200. * until now... */
  1201. destroy_workqueue(priv->workqueue);
  1202. priv->workqueue = NULL;
  1203. iwl_uninit_drv(priv);
  1204. dev_kfree_skb(priv->beacon_skb);
  1205. iwl_trans_stop_hw(priv->trans, true);
  1206. ieee80211_free_hw(priv->hw);
  1207. }
  1208. static const char * const desc_lookup_text[] = {
  1209. "OK",
  1210. "FAIL",
  1211. "BAD_PARAM",
  1212. "BAD_CHECKSUM",
  1213. "NMI_INTERRUPT_WDG",
  1214. "SYSASSERT",
  1215. "FATAL_ERROR",
  1216. "BAD_COMMAND",
  1217. "HW_ERROR_TUNE_LOCK",
  1218. "HW_ERROR_TEMPERATURE",
  1219. "ILLEGAL_CHAN_FREQ",
  1220. "VCC_NOT_STABLE",
  1221. "FH_ERROR",
  1222. "NMI_INTERRUPT_HOST",
  1223. "NMI_INTERRUPT_ACTION_PT",
  1224. "NMI_INTERRUPT_UNKNOWN",
  1225. "UCODE_VERSION_MISMATCH",
  1226. "HW_ERROR_ABS_LOCK",
  1227. "HW_ERROR_CAL_LOCK_FAIL",
  1228. "NMI_INTERRUPT_INST_ACTION_PT",
  1229. "NMI_INTERRUPT_DATA_ACTION_PT",
  1230. "NMI_TRM_HW_ER",
  1231. "NMI_INTERRUPT_TRM",
  1232. "NMI_INTERRUPT_BREAK_POINT",
  1233. "DEBUG_0",
  1234. "DEBUG_1",
  1235. "DEBUG_2",
  1236. "DEBUG_3",
  1237. };
  1238. static struct { char *name; u8 num; } advanced_lookup[] = {
  1239. { "NMI_INTERRUPT_WDG", 0x34 },
  1240. { "SYSASSERT", 0x35 },
  1241. { "UCODE_VERSION_MISMATCH", 0x37 },
  1242. { "BAD_COMMAND", 0x38 },
  1243. { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
  1244. { "FATAL_ERROR", 0x3D },
  1245. { "NMI_TRM_HW_ERR", 0x46 },
  1246. { "NMI_INTERRUPT_TRM", 0x4C },
  1247. { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
  1248. { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
  1249. { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
  1250. { "NMI_INTERRUPT_HOST", 0x66 },
  1251. { "NMI_INTERRUPT_ACTION_PT", 0x7C },
  1252. { "NMI_INTERRUPT_UNKNOWN", 0x84 },
  1253. { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
  1254. { "ADVANCED_SYSASSERT", 0 },
  1255. };
  1256. static const char *desc_lookup(u32 num)
  1257. {
  1258. int i;
  1259. int max = ARRAY_SIZE(desc_lookup_text);
  1260. if (num < max)
  1261. return desc_lookup_text[num];
  1262. max = ARRAY_SIZE(advanced_lookup) - 1;
  1263. for (i = 0; i < max; i++) {
  1264. if (advanced_lookup[i].num == num)
  1265. break;
  1266. }
  1267. return advanced_lookup[i].name;
  1268. }
  1269. #define ERROR_START_OFFSET (1 * sizeof(u32))
  1270. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  1271. static void iwl_dump_nic_error_log(struct iwl_priv *priv)
  1272. {
  1273. struct iwl_trans *trans = priv->trans;
  1274. u32 base;
  1275. struct iwl_error_event_table table;
  1276. base = priv->device_pointers.error_event_table;
  1277. if (priv->cur_ucode == IWL_UCODE_INIT) {
  1278. if (!base)
  1279. base = priv->fw->init_errlog_ptr;
  1280. } else {
  1281. if (!base)
  1282. base = priv->fw->inst_errlog_ptr;
  1283. }
  1284. if (!iwlagn_hw_valid_rtc_data_addr(base)) {
  1285. IWL_ERR(priv,
  1286. "Not valid error log pointer 0x%08X for %s uCode\n",
  1287. base,
  1288. (priv->cur_ucode == IWL_UCODE_INIT)
  1289. ? "Init" : "RT");
  1290. return;
  1291. }
  1292. /*TODO: Update dbgfs with ISR error stats obtained below */
  1293. iwl_trans_read_mem_bytes(trans, base, &table, sizeof(table));
  1294. if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
  1295. IWL_ERR(trans, "Start IWL Error Log Dump:\n");
  1296. IWL_ERR(trans, "Status: 0x%08lX, count: %d\n",
  1297. priv->status, table.valid);
  1298. }
  1299. trace_iwlwifi_dev_ucode_error(trans->dev, table.error_id, table.tsf_low,
  1300. table.data1, table.data2, table.line,
  1301. table.blink1, table.blink2, table.ilink1,
  1302. table.ilink2, table.bcon_time, table.gp1,
  1303. table.gp2, table.gp3, table.ucode_ver,
  1304. table.hw_ver, table.brd_ver);
  1305. IWL_ERR(priv, "0x%08X | %-28s\n", table.error_id,
  1306. desc_lookup(table.error_id));
  1307. IWL_ERR(priv, "0x%08X | uPc\n", table.pc);
  1308. IWL_ERR(priv, "0x%08X | branchlink1\n", table.blink1);
  1309. IWL_ERR(priv, "0x%08X | branchlink2\n", table.blink2);
  1310. IWL_ERR(priv, "0x%08X | interruptlink1\n", table.ilink1);
  1311. IWL_ERR(priv, "0x%08X | interruptlink2\n", table.ilink2);
  1312. IWL_ERR(priv, "0x%08X | data1\n", table.data1);
  1313. IWL_ERR(priv, "0x%08X | data2\n", table.data2);
  1314. IWL_ERR(priv, "0x%08X | line\n", table.line);
  1315. IWL_ERR(priv, "0x%08X | beacon time\n", table.bcon_time);
  1316. IWL_ERR(priv, "0x%08X | tsf low\n", table.tsf_low);
  1317. IWL_ERR(priv, "0x%08X | tsf hi\n", table.tsf_hi);
  1318. IWL_ERR(priv, "0x%08X | time gp1\n", table.gp1);
  1319. IWL_ERR(priv, "0x%08X | time gp2\n", table.gp2);
  1320. IWL_ERR(priv, "0x%08X | time gp3\n", table.gp3);
  1321. IWL_ERR(priv, "0x%08X | uCode version\n", table.ucode_ver);
  1322. IWL_ERR(priv, "0x%08X | hw version\n", table.hw_ver);
  1323. IWL_ERR(priv, "0x%08X | board version\n", table.brd_ver);
  1324. IWL_ERR(priv, "0x%08X | hcmd\n", table.hcmd);
  1325. IWL_ERR(priv, "0x%08X | isr0\n", table.isr0);
  1326. IWL_ERR(priv, "0x%08X | isr1\n", table.isr1);
  1327. IWL_ERR(priv, "0x%08X | isr2\n", table.isr2);
  1328. IWL_ERR(priv, "0x%08X | isr3\n", table.isr3);
  1329. IWL_ERR(priv, "0x%08X | isr4\n", table.isr4);
  1330. IWL_ERR(priv, "0x%08X | isr_pref\n", table.isr_pref);
  1331. IWL_ERR(priv, "0x%08X | wait_event\n", table.wait_event);
  1332. IWL_ERR(priv, "0x%08X | l2p_control\n", table.l2p_control);
  1333. IWL_ERR(priv, "0x%08X | l2p_duration\n", table.l2p_duration);
  1334. IWL_ERR(priv, "0x%08X | l2p_mhvalid\n", table.l2p_mhvalid);
  1335. IWL_ERR(priv, "0x%08X | l2p_addr_match\n", table.l2p_addr_match);
  1336. IWL_ERR(priv, "0x%08X | lmpm_pmg_sel\n", table.lmpm_pmg_sel);
  1337. IWL_ERR(priv, "0x%08X | timestamp\n", table.u_timestamp);
  1338. IWL_ERR(priv, "0x%08X | flow_handler\n", table.flow_handler);
  1339. }
  1340. #define EVENT_START_OFFSET (4 * sizeof(u32))
  1341. /**
  1342. * iwl_print_event_log - Dump error event log to syslog
  1343. *
  1344. */
  1345. static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
  1346. u32 num_events, u32 mode,
  1347. int pos, char **buf, size_t bufsz)
  1348. {
  1349. u32 i;
  1350. u32 base; /* SRAM byte address of event log header */
  1351. u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
  1352. u32 ptr; /* SRAM byte address of log data */
  1353. u32 ev, time, data; /* event log data */
  1354. unsigned long reg_flags;
  1355. struct iwl_trans *trans = priv->trans;
  1356. if (num_events == 0)
  1357. return pos;
  1358. base = priv->device_pointers.log_event_table;
  1359. if (priv->cur_ucode == IWL_UCODE_INIT) {
  1360. if (!base)
  1361. base = priv->fw->init_evtlog_ptr;
  1362. } else {
  1363. if (!base)
  1364. base = priv->fw->inst_evtlog_ptr;
  1365. }
  1366. if (mode == 0)
  1367. event_size = 2 * sizeof(u32);
  1368. else
  1369. event_size = 3 * sizeof(u32);
  1370. ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
  1371. /* Make sure device is powered up for SRAM reads */
  1372. if (!iwl_trans_grab_nic_access(trans, false, &reg_flags))
  1373. return pos;
  1374. /* Set starting address; reads will auto-increment */
  1375. iwl_write32(trans, HBUS_TARG_MEM_RADDR, ptr);
  1376. /* "time" is actually "data" for mode 0 (no timestamp).
  1377. * place event id # at far right for easier visual parsing. */
  1378. for (i = 0; i < num_events; i++) {
  1379. ev = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
  1380. time = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
  1381. if (mode == 0) {
  1382. /* data, ev */
  1383. if (bufsz) {
  1384. pos += scnprintf(*buf + pos, bufsz - pos,
  1385. "EVT_LOG:0x%08x:%04u\n",
  1386. time, ev);
  1387. } else {
  1388. trace_iwlwifi_dev_ucode_event(trans->dev, 0,
  1389. time, ev);
  1390. IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n",
  1391. time, ev);
  1392. }
  1393. } else {
  1394. data = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
  1395. if (bufsz) {
  1396. pos += scnprintf(*buf + pos, bufsz - pos,
  1397. "EVT_LOGT:%010u:0x%08x:%04u\n",
  1398. time, data, ev);
  1399. } else {
  1400. IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
  1401. time, data, ev);
  1402. trace_iwlwifi_dev_ucode_event(trans->dev, time,
  1403. data, ev);
  1404. }
  1405. }
  1406. }
  1407. /* Allow device to power down */
  1408. iwl_trans_release_nic_access(trans, &reg_flags);
  1409. return pos;
  1410. }
  1411. /**
  1412. * iwl_print_last_event_logs - Dump the newest # of event log to syslog
  1413. */
  1414. static int iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
  1415. u32 num_wraps, u32 next_entry,
  1416. u32 size, u32 mode,
  1417. int pos, char **buf, size_t bufsz)
  1418. {
  1419. /*
  1420. * display the newest DEFAULT_LOG_ENTRIES entries
  1421. * i.e the entries just before the next ont that uCode would fill.
  1422. */
  1423. if (num_wraps) {
  1424. if (next_entry < size) {
  1425. pos = iwl_print_event_log(priv,
  1426. capacity - (size - next_entry),
  1427. size - next_entry, mode,
  1428. pos, buf, bufsz);
  1429. pos = iwl_print_event_log(priv, 0,
  1430. next_entry, mode,
  1431. pos, buf, bufsz);
  1432. } else
  1433. pos = iwl_print_event_log(priv, next_entry - size,
  1434. size, mode, pos, buf, bufsz);
  1435. } else {
  1436. if (next_entry < size) {
  1437. pos = iwl_print_event_log(priv, 0, next_entry,
  1438. mode, pos, buf, bufsz);
  1439. } else {
  1440. pos = iwl_print_event_log(priv, next_entry - size,
  1441. size, mode, pos, buf, bufsz);
  1442. }
  1443. }
  1444. return pos;
  1445. }
  1446. #define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
  1447. int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
  1448. char **buf)
  1449. {
  1450. u32 base; /* SRAM byte address of event log header */
  1451. u32 capacity; /* event log capacity in # entries */
  1452. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  1453. u32 num_wraps; /* # times uCode wrapped to top of log */
  1454. u32 next_entry; /* index of next entry to be written by uCode */
  1455. u32 size; /* # entries that we'll print */
  1456. u32 logsize;
  1457. int pos = 0;
  1458. size_t bufsz = 0;
  1459. struct iwl_trans *trans = priv->trans;
  1460. base = priv->device_pointers.log_event_table;
  1461. if (priv->cur_ucode == IWL_UCODE_INIT) {
  1462. logsize = priv->fw->init_evtlog_size;
  1463. if (!base)
  1464. base = priv->fw->init_evtlog_ptr;
  1465. } else {
  1466. logsize = priv->fw->inst_evtlog_size;
  1467. if (!base)
  1468. base = priv->fw->inst_evtlog_ptr;
  1469. }
  1470. if (!iwlagn_hw_valid_rtc_data_addr(base)) {
  1471. IWL_ERR(priv,
  1472. "Invalid event log pointer 0x%08X for %s uCode\n",
  1473. base,
  1474. (priv->cur_ucode == IWL_UCODE_INIT)
  1475. ? "Init" : "RT");
  1476. return -EINVAL;
  1477. }
  1478. /* event log header */
  1479. capacity = iwl_trans_read_mem32(trans, base);
  1480. mode = iwl_trans_read_mem32(trans, base + (1 * sizeof(u32)));
  1481. num_wraps = iwl_trans_read_mem32(trans, base + (2 * sizeof(u32)));
  1482. next_entry = iwl_trans_read_mem32(trans, base + (3 * sizeof(u32)));
  1483. if (capacity > logsize) {
  1484. IWL_ERR(priv, "Log capacity %d is bogus, limit to %d "
  1485. "entries\n", capacity, logsize);
  1486. capacity = logsize;
  1487. }
  1488. if (next_entry > logsize) {
  1489. IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
  1490. next_entry, logsize);
  1491. next_entry = logsize;
  1492. }
  1493. size = num_wraps ? capacity : next_entry;
  1494. /* bail out if nothing in log */
  1495. if (size == 0) {
  1496. IWL_ERR(trans, "Start IWL Event Log Dump: nothing in log\n");
  1497. return pos;
  1498. }
  1499. if (!(iwl_have_debug_level(IWL_DL_FW_ERRORS)) && !full_log)
  1500. size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
  1501. ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
  1502. IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n",
  1503. size);
  1504. #ifdef CONFIG_IWLWIFI_DEBUG
  1505. if (buf) {
  1506. if (full_log)
  1507. bufsz = capacity * 48;
  1508. else
  1509. bufsz = size * 48;
  1510. *buf = kmalloc(bufsz, GFP_KERNEL);
  1511. if (!*buf)
  1512. return -ENOMEM;
  1513. }
  1514. if (iwl_have_debug_level(IWL_DL_FW_ERRORS) || full_log) {
  1515. /*
  1516. * if uCode has wrapped back to top of log,
  1517. * start at the oldest entry,
  1518. * i.e the next one that uCode would fill.
  1519. */
  1520. if (num_wraps)
  1521. pos = iwl_print_event_log(priv, next_entry,
  1522. capacity - next_entry, mode,
  1523. pos, buf, bufsz);
  1524. /* (then/else) start at top of log */
  1525. pos = iwl_print_event_log(priv, 0,
  1526. next_entry, mode, pos, buf, bufsz);
  1527. } else
  1528. pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
  1529. next_entry, size, mode,
  1530. pos, buf, bufsz);
  1531. #else
  1532. pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
  1533. next_entry, size, mode,
  1534. pos, buf, bufsz);
  1535. #endif
  1536. return pos;
  1537. }
  1538. static void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand)
  1539. {
  1540. unsigned int reload_msec;
  1541. unsigned long reload_jiffies;
  1542. if (iwl_have_debug_level(IWL_DL_FW_ERRORS))
  1543. iwl_print_rx_config_cmd(priv, IWL_RXON_CTX_BSS);
  1544. /* uCode is no longer loaded. */
  1545. priv->ucode_loaded = false;
  1546. /* Set the FW error flag -- cleared on iwl_down */
  1547. set_bit(STATUS_FW_ERROR, &priv->status);
  1548. iwl_abort_notification_waits(&priv->notif_wait);
  1549. /* Keep the restart process from trying to send host
  1550. * commands by clearing the ready bit */
  1551. clear_bit(STATUS_READY, &priv->status);
  1552. if (!ondemand) {
  1553. /*
  1554. * If firmware keep reloading, then it indicate something
  1555. * serious wrong and firmware having problem to recover
  1556. * from it. Instead of keep trying which will fill the syslog
  1557. * and hang the system, let's just stop it
  1558. */
  1559. reload_jiffies = jiffies;
  1560. reload_msec = jiffies_to_msecs((long) reload_jiffies -
  1561. (long) priv->reload_jiffies);
  1562. priv->reload_jiffies = reload_jiffies;
  1563. if (reload_msec <= IWL_MIN_RELOAD_DURATION) {
  1564. priv->reload_count++;
  1565. if (priv->reload_count >= IWL_MAX_CONTINUE_RELOAD_CNT) {
  1566. IWL_ERR(priv, "BUG_ON, Stop restarting\n");
  1567. return;
  1568. }
  1569. } else
  1570. priv->reload_count = 0;
  1571. }
  1572. if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  1573. if (iwlwifi_mod_params.restart_fw) {
  1574. IWL_DEBUG_FW_ERRORS(priv,
  1575. "Restarting adapter due to uCode error.\n");
  1576. queue_work(priv->workqueue, &priv->restart);
  1577. } else
  1578. IWL_DEBUG_FW_ERRORS(priv,
  1579. "Detected FW error, but not restarting\n");
  1580. }
  1581. }
  1582. static void iwl_nic_error(struct iwl_op_mode *op_mode)
  1583. {
  1584. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1585. IWL_ERR(priv, "Loaded firmware version: %s\n",
  1586. priv->fw->fw_version);
  1587. iwl_dump_nic_error_log(priv);
  1588. iwl_dump_nic_event_log(priv, false, NULL);
  1589. iwlagn_fw_error(priv, false);
  1590. }
  1591. static void iwl_cmd_queue_full(struct iwl_op_mode *op_mode)
  1592. {
  1593. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1594. if (!iwl_check_for_ct_kill(priv)) {
  1595. IWL_ERR(priv, "Restarting adapter queue is full\n");
  1596. iwlagn_fw_error(priv, false);
  1597. }
  1598. }
  1599. #define EEPROM_RF_CONFIG_TYPE_MAX 0x3
  1600. static void iwl_nic_config(struct iwl_op_mode *op_mode)
  1601. {
  1602. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1603. /* SKU Control */
  1604. iwl_trans_set_bits_mask(priv->trans, CSR_HW_IF_CONFIG_REG,
  1605. CSR_HW_IF_CONFIG_REG_MSK_MAC_DASH |
  1606. CSR_HW_IF_CONFIG_REG_MSK_MAC_STEP,
  1607. (CSR_HW_REV_STEP(priv->trans->hw_rev) <<
  1608. CSR_HW_IF_CONFIG_REG_POS_MAC_STEP) |
  1609. (CSR_HW_REV_DASH(priv->trans->hw_rev) <<
  1610. CSR_HW_IF_CONFIG_REG_POS_MAC_DASH));
  1611. /* write radio config values to register */
  1612. if (priv->nvm_data->radio_cfg_type <= EEPROM_RF_CONFIG_TYPE_MAX) {
  1613. u32 reg_val =
  1614. priv->nvm_data->radio_cfg_type <<
  1615. CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE |
  1616. priv->nvm_data->radio_cfg_step <<
  1617. CSR_HW_IF_CONFIG_REG_POS_PHY_STEP |
  1618. priv->nvm_data->radio_cfg_dash <<
  1619. CSR_HW_IF_CONFIG_REG_POS_PHY_DASH;
  1620. iwl_trans_set_bits_mask(priv->trans, CSR_HW_IF_CONFIG_REG,
  1621. CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE |
  1622. CSR_HW_IF_CONFIG_REG_MSK_PHY_STEP |
  1623. CSR_HW_IF_CONFIG_REG_MSK_PHY_DASH,
  1624. reg_val);
  1625. IWL_INFO(priv, "Radio type=0x%x-0x%x-0x%x\n",
  1626. priv->nvm_data->radio_cfg_type,
  1627. priv->nvm_data->radio_cfg_step,
  1628. priv->nvm_data->radio_cfg_dash);
  1629. } else {
  1630. WARN_ON(1);
  1631. }
  1632. /* set CSR_HW_CONFIG_REG for uCode use */
  1633. iwl_set_bit(priv->trans, CSR_HW_IF_CONFIG_REG,
  1634. CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
  1635. CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
  1636. /* W/A : NIC is stuck in a reset state after Early PCIe power off
  1637. * (PCIe power is lost before PERST# is asserted),
  1638. * causing ME FW to lose ownership and not being able to obtain it back.
  1639. */
  1640. iwl_set_bits_mask_prph(priv->trans, APMG_PS_CTRL_REG,
  1641. APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
  1642. ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
  1643. if (priv->lib->nic_config)
  1644. priv->lib->nic_config(priv);
  1645. }
  1646. static void iwl_wimax_active(struct iwl_op_mode *op_mode)
  1647. {
  1648. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1649. clear_bit(STATUS_READY, &priv->status);
  1650. IWL_ERR(priv, "RF is used by WiMAX\n");
  1651. }
  1652. static void iwl_stop_sw_queue(struct iwl_op_mode *op_mode, int queue)
  1653. {
  1654. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1655. int mq = priv->queue_to_mac80211[queue];
  1656. if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE))
  1657. return;
  1658. if (atomic_inc_return(&priv->queue_stop_count[mq]) > 1) {
  1659. IWL_DEBUG_TX_QUEUES(priv,
  1660. "queue %d (mac80211 %d) already stopped\n",
  1661. queue, mq);
  1662. return;
  1663. }
  1664. set_bit(mq, &priv->transport_queue_stop);
  1665. ieee80211_stop_queue(priv->hw, mq);
  1666. }
  1667. static void iwl_wake_sw_queue(struct iwl_op_mode *op_mode, int queue)
  1668. {
  1669. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1670. int mq = priv->queue_to_mac80211[queue];
  1671. if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE))
  1672. return;
  1673. if (atomic_dec_return(&priv->queue_stop_count[mq]) > 0) {
  1674. IWL_DEBUG_TX_QUEUES(priv,
  1675. "queue %d (mac80211 %d) already awake\n",
  1676. queue, mq);
  1677. return;
  1678. }
  1679. clear_bit(mq, &priv->transport_queue_stop);
  1680. if (!priv->passive_no_rx)
  1681. ieee80211_wake_queue(priv->hw, mq);
  1682. }
  1683. void iwlagn_lift_passive_no_rx(struct iwl_priv *priv)
  1684. {
  1685. int mq;
  1686. if (!priv->passive_no_rx)
  1687. return;
  1688. for (mq = 0; mq < IWLAGN_FIRST_AMPDU_QUEUE; mq++) {
  1689. if (!test_bit(mq, &priv->transport_queue_stop)) {
  1690. IWL_DEBUG_TX_QUEUES(priv, "Wake queue %d", mq);
  1691. ieee80211_wake_queue(priv->hw, mq);
  1692. } else {
  1693. IWL_DEBUG_TX_QUEUES(priv, "Don't wake queue %d", mq);
  1694. }
  1695. }
  1696. priv->passive_no_rx = false;
  1697. }
  1698. static void iwl_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)
  1699. {
  1700. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1701. struct ieee80211_tx_info *info;
  1702. info = IEEE80211_SKB_CB(skb);
  1703. iwl_trans_free_tx_cmd(priv->trans, info->driver_data[1]);
  1704. ieee80211_free_txskb(priv->hw, skb);
  1705. }
  1706. static void iwl_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
  1707. {
  1708. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1709. if (state)
  1710. set_bit(STATUS_RF_KILL_HW, &priv->status);
  1711. else
  1712. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  1713. wiphy_rfkill_set_hw_state(priv->hw->wiphy, state);
  1714. }
  1715. static const struct iwl_op_mode_ops iwl_dvm_ops = {
  1716. .start = iwl_op_mode_dvm_start,
  1717. .stop = iwl_op_mode_dvm_stop,
  1718. .rx = iwl_rx_dispatch,
  1719. .queue_full = iwl_stop_sw_queue,
  1720. .queue_not_full = iwl_wake_sw_queue,
  1721. .hw_rf_kill = iwl_set_hw_rfkill_state,
  1722. .free_skb = iwl_free_skb,
  1723. .nic_error = iwl_nic_error,
  1724. .cmd_queue_full = iwl_cmd_queue_full,
  1725. .nic_config = iwl_nic_config,
  1726. .wimax_active = iwl_wimax_active,
  1727. };
  1728. /*****************************************************************************
  1729. *
  1730. * driver and module entry point
  1731. *
  1732. *****************************************************************************/
  1733. static int __init iwl_init(void)
  1734. {
  1735. int ret;
  1736. ret = iwlagn_rate_control_register();
  1737. if (ret) {
  1738. pr_err("Unable to register rate control algorithm: %d\n", ret);
  1739. return ret;
  1740. }
  1741. ret = iwl_opmode_register("iwldvm", &iwl_dvm_ops);
  1742. if (ret) {
  1743. pr_err("Unable to register op_mode: %d\n", ret);
  1744. iwlagn_rate_control_unregister();
  1745. }
  1746. return ret;
  1747. }
  1748. module_init(iwl_init);
  1749. static void __exit iwl_exit(void)
  1750. {
  1751. iwl_opmode_deregister("iwldvm");
  1752. iwlagn_rate_control_unregister();
  1753. }
  1754. module_exit(iwl_exit);