iwl-agn.c 64 KB

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