main.c 60 KB

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