main.c 61 KB

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