main.c 60 KB

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