main.c 65 KB

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