main.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170
  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->eeprom_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 (unlikely(!iwl_grab_nic_access(priv->trans))) {
  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_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_read_targ_mem_bytes(priv->trans, base, &read, sizeof(read));
  344. capacity = read.capacity;
  345. mode = read.mode;
  346. num_wraps = read.wrap_counter;
  347. next_entry = read.write_counter;
  348. } else
  349. return;
  350. /*
  351. * Unfortunately, the uCode doesn't use temporary variables.
  352. * Therefore, it can happen that we read next_entry == capacity,
  353. * which really means next_entry == 0.
  354. */
  355. if (unlikely(next_entry == capacity))
  356. next_entry = 0;
  357. /*
  358. * Additionally, the uCode increases the write pointer before
  359. * the wraps counter, so if the write pointer is smaller than
  360. * the old write pointer (wrap occurred) but we read that no
  361. * wrap occurred, we actually read between the next_entry and
  362. * num_wraps update (this does happen in practice!!) -- take
  363. * that into account by increasing num_wraps.
  364. */
  365. if (unlikely(next_entry < priv->event_log.next_entry &&
  366. num_wraps == priv->event_log.num_wraps))
  367. num_wraps++;
  368. if (num_wraps == priv->event_log.num_wraps) {
  369. iwl_print_cont_event_trace(
  370. priv, base, priv->event_log.next_entry,
  371. next_entry - priv->event_log.next_entry,
  372. capacity, mode);
  373. priv->event_log.non_wraps_count++;
  374. } else {
  375. if (num_wraps - priv->event_log.num_wraps > 1)
  376. priv->event_log.wraps_more_count++;
  377. else
  378. priv->event_log.wraps_once_count++;
  379. trace_iwlwifi_dev_ucode_wrap_event(priv->trans->dev,
  380. num_wraps - priv->event_log.num_wraps,
  381. next_entry, priv->event_log.next_entry);
  382. if (next_entry < priv->event_log.next_entry) {
  383. iwl_print_cont_event_trace(
  384. priv, base, priv->event_log.next_entry,
  385. capacity - priv->event_log.next_entry,
  386. capacity, mode);
  387. iwl_print_cont_event_trace(
  388. priv, base, 0, next_entry, capacity, mode);
  389. } else {
  390. iwl_print_cont_event_trace(
  391. priv, base, next_entry,
  392. capacity - next_entry,
  393. capacity, mode);
  394. iwl_print_cont_event_trace(
  395. priv, base, 0, next_entry, capacity, mode);
  396. }
  397. }
  398. priv->event_log.num_wraps = num_wraps;
  399. priv->event_log.next_entry = next_entry;
  400. }
  401. /**
  402. * iwl_bg_ucode_trace - Timer callback to log ucode event
  403. *
  404. * The timer is continually set to execute every
  405. * UCODE_TRACE_PERIOD milliseconds after the last timer expired
  406. * this function is to perform continuous uCode event logging operation
  407. * if enabled
  408. */
  409. static void iwl_bg_ucode_trace(unsigned long data)
  410. {
  411. struct iwl_priv *priv = (struct iwl_priv *)data;
  412. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  413. return;
  414. if (priv->event_log.ucode_trace) {
  415. iwl_continuous_event_trace(priv);
  416. /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
  417. mod_timer(&priv->ucode_trace,
  418. jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
  419. }
  420. }
  421. static void iwl_bg_tx_flush(struct work_struct *work)
  422. {
  423. struct iwl_priv *priv =
  424. container_of(work, struct iwl_priv, tx_flush);
  425. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  426. return;
  427. /* do nothing if rf-kill is on */
  428. if (!iwl_is_ready_rf(priv))
  429. return;
  430. IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n");
  431. iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
  432. }
  433. /*
  434. * queue/FIFO/AC mapping definitions
  435. */
  436. static const u8 iwlagn_bss_ac_to_fifo[] = {
  437. IWL_TX_FIFO_VO,
  438. IWL_TX_FIFO_VI,
  439. IWL_TX_FIFO_BE,
  440. IWL_TX_FIFO_BK,
  441. };
  442. static const u8 iwlagn_bss_ac_to_queue[] = {
  443. 0, 1, 2, 3,
  444. };
  445. static const u8 iwlagn_pan_ac_to_fifo[] = {
  446. IWL_TX_FIFO_VO_IPAN,
  447. IWL_TX_FIFO_VI_IPAN,
  448. IWL_TX_FIFO_BE_IPAN,
  449. IWL_TX_FIFO_BK_IPAN,
  450. };
  451. static const u8 iwlagn_pan_ac_to_queue[] = {
  452. 7, 6, 5, 4,
  453. };
  454. static void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags)
  455. {
  456. int i;
  457. /*
  458. * The default context is always valid,
  459. * the PAN context depends on uCode.
  460. */
  461. priv->valid_contexts = BIT(IWL_RXON_CTX_BSS);
  462. if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN)
  463. priv->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
  464. for (i = 0; i < NUM_IWL_RXON_CTX; i++)
  465. priv->contexts[i].ctxid = i;
  466. priv->contexts[IWL_RXON_CTX_BSS].always_active = true;
  467. priv->contexts[IWL_RXON_CTX_BSS].is_active = true;
  468. priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
  469. priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
  470. priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
  471. priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
  472. priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
  473. priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
  474. priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
  475. priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
  476. BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_MONITOR);
  477. priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
  478. BIT(NL80211_IFTYPE_STATION);
  479. priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP;
  480. priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
  481. priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
  482. priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
  483. memcpy(priv->contexts[IWL_RXON_CTX_BSS].ac_to_queue,
  484. iwlagn_bss_ac_to_queue, sizeof(iwlagn_bss_ac_to_queue));
  485. memcpy(priv->contexts[IWL_RXON_CTX_BSS].ac_to_fifo,
  486. iwlagn_bss_ac_to_fifo, sizeof(iwlagn_bss_ac_to_fifo));
  487. priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON;
  488. priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd =
  489. REPLY_WIPAN_RXON_TIMING;
  490. priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd =
  491. REPLY_WIPAN_RXON_ASSOC;
  492. priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM;
  493. priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN;
  494. priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY;
  495. priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID;
  496. priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION;
  497. priv->contexts[IWL_RXON_CTX_PAN].interface_modes =
  498. BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
  499. if (ucode_flags & IWL_UCODE_TLV_FLAGS_P2P)
  500. priv->contexts[IWL_RXON_CTX_PAN].interface_modes |=
  501. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  502. BIT(NL80211_IFTYPE_P2P_GO);
  503. priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP;
  504. priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA;
  505. priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P;
  506. memcpy(priv->contexts[IWL_RXON_CTX_PAN].ac_to_queue,
  507. iwlagn_pan_ac_to_queue, sizeof(iwlagn_pan_ac_to_queue));
  508. memcpy(priv->contexts[IWL_RXON_CTX_PAN].ac_to_fifo,
  509. iwlagn_pan_ac_to_fifo, sizeof(iwlagn_pan_ac_to_fifo));
  510. priv->contexts[IWL_RXON_CTX_PAN].mcast_queue = IWL_IPAN_MCAST_QUEUE;
  511. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  512. }
  513. static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
  514. {
  515. struct iwl_ct_kill_config cmd;
  516. struct iwl_ct_kill_throttling_config adv_cmd;
  517. int ret = 0;
  518. iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR,
  519. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  520. priv->thermal_throttle.ct_kill_toggle = false;
  521. if (priv->cfg->base_params->support_ct_kill_exit) {
  522. adv_cmd.critical_temperature_enter =
  523. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  524. adv_cmd.critical_temperature_exit =
  525. cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
  526. ret = iwl_dvm_send_cmd_pdu(priv,
  527. REPLY_CT_KILL_CONFIG_CMD,
  528. CMD_SYNC, sizeof(adv_cmd), &adv_cmd);
  529. if (ret)
  530. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  531. else
  532. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  533. "succeeded, critical temperature enter is %d,"
  534. "exit is %d\n",
  535. priv->hw_params.ct_kill_threshold,
  536. priv->hw_params.ct_kill_exit_threshold);
  537. } else {
  538. cmd.critical_temperature_R =
  539. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  540. ret = iwl_dvm_send_cmd_pdu(priv,
  541. REPLY_CT_KILL_CONFIG_CMD,
  542. CMD_SYNC, sizeof(cmd), &cmd);
  543. if (ret)
  544. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  545. else
  546. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  547. "succeeded, "
  548. "critical temperature is %d\n",
  549. priv->hw_params.ct_kill_threshold);
  550. }
  551. }
  552. static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
  553. {
  554. struct iwl_calib_cfg_cmd calib_cfg_cmd;
  555. struct iwl_host_cmd cmd = {
  556. .id = CALIBRATION_CFG_CMD,
  557. .len = { sizeof(struct iwl_calib_cfg_cmd), },
  558. .data = { &calib_cfg_cmd, },
  559. };
  560. memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
  561. calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_RT_CFG_ALL;
  562. calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg);
  563. return iwl_dvm_send_cmd(priv, &cmd);
  564. }
  565. static int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant)
  566. {
  567. struct iwl_tx_ant_config_cmd tx_ant_cmd = {
  568. .valid = cpu_to_le32(valid_tx_ant),
  569. };
  570. if (IWL_UCODE_API(priv->fw->ucode_ver) > 1) {
  571. IWL_DEBUG_HC(priv, "select valid tx ant: %u\n", valid_tx_ant);
  572. return iwl_dvm_send_cmd_pdu(priv,
  573. TX_ANT_CONFIGURATION_CMD,
  574. CMD_SYNC,
  575. sizeof(struct iwl_tx_ant_config_cmd),
  576. &tx_ant_cmd);
  577. } else {
  578. IWL_DEBUG_HC(priv, "TX_ANT_CONFIGURATION_CMD not supported\n");
  579. return -EOPNOTSUPP;
  580. }
  581. }
  582. static void iwl_send_bt_config(struct iwl_priv *priv)
  583. {
  584. struct iwl_bt_cmd bt_cmd = {
  585. .lead_time = BT_LEAD_TIME_DEF,
  586. .max_kill = BT_MAX_KILL_DEF,
  587. .kill_ack_mask = 0,
  588. .kill_cts_mask = 0,
  589. };
  590. if (!iwlwifi_mod_params.bt_coex_active)
  591. bt_cmd.flags = BT_COEX_DISABLE;
  592. else
  593. bt_cmd.flags = BT_COEX_ENABLE;
  594. priv->bt_enable_flag = bt_cmd.flags;
  595. IWL_DEBUG_INFO(priv, "BT coex %s\n",
  596. (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
  597. if (iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  598. CMD_SYNC, sizeof(struct iwl_bt_cmd), &bt_cmd))
  599. IWL_ERR(priv, "failed to send BT Coex Config\n");
  600. }
  601. /**
  602. * iwl_alive_start - called after REPLY_ALIVE notification received
  603. * from protocol/runtime uCode (initialization uCode's
  604. * Alive gets handled by iwl_init_alive_start()).
  605. */
  606. int iwl_alive_start(struct iwl_priv *priv)
  607. {
  608. int ret = 0;
  609. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  610. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  611. /* After the ALIVE response, we can send host commands to the uCode */
  612. set_bit(STATUS_ALIVE, &priv->status);
  613. if (iwl_is_rfkill(priv))
  614. return -ERFKILL;
  615. if (priv->event_log.ucode_trace) {
  616. /* start collecting data now */
  617. mod_timer(&priv->ucode_trace, jiffies);
  618. }
  619. /* download priority table before any calibration request */
  620. if (priv->cfg->bt_params &&
  621. priv->cfg->bt_params->advanced_bt_coexist) {
  622. /* Configure Bluetooth device coexistence support */
  623. if (priv->cfg->bt_params->bt_sco_disable)
  624. priv->bt_enable_pspoll = false;
  625. else
  626. priv->bt_enable_pspoll = true;
  627. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  628. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  629. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  630. iwlagn_send_advance_bt_config(priv);
  631. priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS;
  632. priv->cur_rssi_ctx = NULL;
  633. iwl_send_prio_tbl(priv);
  634. /* FIXME: w/a to force change uCode BT state machine */
  635. ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
  636. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  637. if (ret)
  638. return ret;
  639. ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
  640. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  641. if (ret)
  642. return ret;
  643. } else {
  644. /*
  645. * default is 2-wire BT coexexistence support
  646. */
  647. iwl_send_bt_config(priv);
  648. }
  649. /*
  650. * Perform runtime calibrations, including DC calibration.
  651. */
  652. iwlagn_send_calib_cfg_rt(priv, IWL_CALIB_CFG_DC_IDX);
  653. ieee80211_wake_queues(priv->hw);
  654. /* Configure Tx antenna selection based on H/W config */
  655. iwlagn_send_tx_ant_config(priv, priv->eeprom_data->valid_tx_ant);
  656. if (iwl_is_associated_ctx(ctx) && !priv->wowlan) {
  657. struct iwl_rxon_cmd *active_rxon =
  658. (struct iwl_rxon_cmd *)&ctx->active;
  659. /* apply any changes in staging */
  660. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  661. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  662. } else {
  663. struct iwl_rxon_context *tmp;
  664. /* Initialize our rx_config data */
  665. for_each_context(priv, tmp)
  666. iwl_connection_init_rx_config(priv, tmp);
  667. iwlagn_set_rxon_chain(priv, ctx);
  668. }
  669. if (!priv->wowlan) {
  670. /* WoWLAN ucode will not reply in the same way, skip it */
  671. iwl_reset_run_time_calib(priv);
  672. }
  673. set_bit(STATUS_READY, &priv->status);
  674. /* Configure the adapter for unassociated operation */
  675. ret = iwlagn_commit_rxon(priv, ctx);
  676. if (ret)
  677. return ret;
  678. /* At this point, the NIC is initialized and operational */
  679. iwl_rf_kill_ct_config(priv);
  680. IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
  681. return iwl_power_update_mode(priv, true);
  682. }
  683. /**
  684. * iwl_clear_driver_stations - clear knowledge of all stations from driver
  685. * @priv: iwl priv struct
  686. *
  687. * This is called during iwl_down() to make sure that in the case
  688. * we're coming there from a hardware restart mac80211 will be
  689. * able to reconfigure stations -- if we're getting there in the
  690. * normal down flow then the stations will already be cleared.
  691. */
  692. static void iwl_clear_driver_stations(struct iwl_priv *priv)
  693. {
  694. struct iwl_rxon_context *ctx;
  695. spin_lock_bh(&priv->sta_lock);
  696. memset(priv->stations, 0, sizeof(priv->stations));
  697. priv->num_stations = 0;
  698. priv->ucode_key_table = 0;
  699. for_each_context(priv, ctx) {
  700. /*
  701. * Remove all key information that is not stored as part
  702. * of station information since mac80211 may not have had
  703. * a chance to remove all the keys. When device is
  704. * reconfigured by mac80211 after an error all keys will
  705. * be reconfigured.
  706. */
  707. memset(ctx->wep_keys, 0, sizeof(ctx->wep_keys));
  708. ctx->key_mapping_keys = 0;
  709. }
  710. spin_unlock_bh(&priv->sta_lock);
  711. }
  712. void iwl_down(struct iwl_priv *priv)
  713. {
  714. int exit_pending;
  715. IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
  716. lockdep_assert_held(&priv->mutex);
  717. iwl_scan_cancel_timeout(priv, 200);
  718. /*
  719. * If active, scanning won't cancel it, so say it expired.
  720. * No race since we hold the mutex here and a new one
  721. * can't come in at this time.
  722. */
  723. if (priv->ucode_loaded && priv->cur_ucode != IWL_UCODE_INIT)
  724. ieee80211_remain_on_channel_expired(priv->hw);
  725. exit_pending =
  726. test_and_set_bit(STATUS_EXIT_PENDING, &priv->status);
  727. iwl_clear_ucode_stations(priv, NULL);
  728. iwl_dealloc_bcast_stations(priv);
  729. iwl_clear_driver_stations(priv);
  730. /* reset BT coex data */
  731. priv->bt_status = 0;
  732. priv->cur_rssi_ctx = NULL;
  733. priv->bt_is_sco = 0;
  734. if (priv->cfg->bt_params)
  735. priv->bt_traffic_load =
  736. priv->cfg->bt_params->bt_init_traffic_load;
  737. else
  738. priv->bt_traffic_load = 0;
  739. priv->bt_full_concurrent = false;
  740. priv->bt_ci_compliance = 0;
  741. /* Wipe out the EXIT_PENDING status bit if we are not actually
  742. * exiting the module */
  743. if (!exit_pending)
  744. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  745. if (priv->mac80211_registered)
  746. ieee80211_stop_queues(priv->hw);
  747. priv->ucode_loaded = false;
  748. iwl_trans_stop_device(priv->trans);
  749. /* Set num_aux_in_flight must be done after the transport is stopped */
  750. atomic_set(&priv->num_aux_in_flight, 0);
  751. /* Clear out all status bits but a few that are stable across reset */
  752. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  753. STATUS_RF_KILL_HW |
  754. test_bit(STATUS_FW_ERROR, &priv->status) <<
  755. STATUS_FW_ERROR |
  756. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  757. STATUS_EXIT_PENDING;
  758. dev_kfree_skb(priv->beacon_skb);
  759. priv->beacon_skb = NULL;
  760. }
  761. /*****************************************************************************
  762. *
  763. * Workqueue callbacks
  764. *
  765. *****************************************************************************/
  766. static void iwl_bg_run_time_calib_work(struct work_struct *work)
  767. {
  768. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  769. run_time_calib_work);
  770. mutex_lock(&priv->mutex);
  771. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  772. test_bit(STATUS_SCANNING, &priv->status)) {
  773. mutex_unlock(&priv->mutex);
  774. return;
  775. }
  776. if (priv->start_calib) {
  777. iwl_chain_noise_calibration(priv);
  778. iwl_sensitivity_calibration(priv);
  779. }
  780. mutex_unlock(&priv->mutex);
  781. }
  782. void iwlagn_prepare_restart(struct iwl_priv *priv)
  783. {
  784. bool bt_full_concurrent;
  785. u8 bt_ci_compliance;
  786. u8 bt_load;
  787. u8 bt_status;
  788. bool bt_is_sco;
  789. int i;
  790. lockdep_assert_held(&priv->mutex);
  791. priv->is_open = 0;
  792. /*
  793. * __iwl_down() will clear the BT status variables,
  794. * which is correct, but when we restart we really
  795. * want to keep them so restore them afterwards.
  796. *
  797. * The restart process will later pick them up and
  798. * re-configure the hw when we reconfigure the BT
  799. * command.
  800. */
  801. bt_full_concurrent = priv->bt_full_concurrent;
  802. bt_ci_compliance = priv->bt_ci_compliance;
  803. bt_load = priv->bt_traffic_load;
  804. bt_status = priv->bt_status;
  805. bt_is_sco = priv->bt_is_sco;
  806. iwl_down(priv);
  807. priv->bt_full_concurrent = bt_full_concurrent;
  808. priv->bt_ci_compliance = bt_ci_compliance;
  809. priv->bt_traffic_load = bt_load;
  810. priv->bt_status = bt_status;
  811. priv->bt_is_sco = bt_is_sco;
  812. /* reset aggregation queues */
  813. for (i = IWLAGN_FIRST_AMPDU_QUEUE; i < IWL_MAX_HW_QUEUES; i++)
  814. priv->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE;
  815. /* and stop counts */
  816. for (i = 0; i < IWL_MAX_HW_QUEUES; i++)
  817. atomic_set(&priv->queue_stop_count[i], 0);
  818. memset(priv->agg_q_alloc, 0, sizeof(priv->agg_q_alloc));
  819. }
  820. static void iwl_bg_restart(struct work_struct *data)
  821. {
  822. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  823. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  824. return;
  825. if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
  826. mutex_lock(&priv->mutex);
  827. iwlagn_prepare_restart(priv);
  828. mutex_unlock(&priv->mutex);
  829. iwl_cancel_deferred_work(priv);
  830. if (priv->mac80211_registered)
  831. ieee80211_restart_hw(priv->hw);
  832. else
  833. IWL_ERR(priv,
  834. "Cannot request restart before registrating with mac80211");
  835. } else {
  836. WARN_ON(1);
  837. }
  838. }
  839. void iwlagn_disable_roc(struct iwl_priv *priv)
  840. {
  841. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
  842. lockdep_assert_held(&priv->mutex);
  843. if (!priv->hw_roc_setup)
  844. return;
  845. ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
  846. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  847. priv->hw_roc_channel = NULL;
  848. memset(ctx->staging.node_addr, 0, ETH_ALEN);
  849. iwlagn_commit_rxon(priv, ctx);
  850. ctx->is_active = false;
  851. priv->hw_roc_setup = false;
  852. }
  853. static void iwlagn_disable_roc_work(struct work_struct *work)
  854. {
  855. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  856. hw_roc_disable_work.work);
  857. mutex_lock(&priv->mutex);
  858. iwlagn_disable_roc(priv);
  859. mutex_unlock(&priv->mutex);
  860. }
  861. /*****************************************************************************
  862. *
  863. * driver setup and teardown
  864. *
  865. *****************************************************************************/
  866. static void iwl_setup_deferred_work(struct iwl_priv *priv)
  867. {
  868. priv->workqueue = create_singlethread_workqueue(DRV_NAME);
  869. INIT_WORK(&priv->restart, iwl_bg_restart);
  870. INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
  871. INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
  872. INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
  873. INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
  874. INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
  875. INIT_DELAYED_WORK(&priv->hw_roc_disable_work,
  876. iwlagn_disable_roc_work);
  877. iwl_setup_scan_deferred_work(priv);
  878. if (priv->cfg->bt_params)
  879. iwlagn_bt_setup_deferred_work(priv);
  880. init_timer(&priv->statistics_periodic);
  881. priv->statistics_periodic.data = (unsigned long)priv;
  882. priv->statistics_periodic.function = iwl_bg_statistics_periodic;
  883. init_timer(&priv->ucode_trace);
  884. priv->ucode_trace.data = (unsigned long)priv;
  885. priv->ucode_trace.function = iwl_bg_ucode_trace;
  886. }
  887. void iwl_cancel_deferred_work(struct iwl_priv *priv)
  888. {
  889. if (priv->cfg->bt_params)
  890. iwlagn_bt_cancel_deferred_work(priv);
  891. cancel_work_sync(&priv->run_time_calib_work);
  892. cancel_work_sync(&priv->beacon_update);
  893. iwl_cancel_scan_deferred_work(priv);
  894. cancel_work_sync(&priv->bt_full_concurrency);
  895. cancel_work_sync(&priv->bt_runtime_config);
  896. cancel_delayed_work_sync(&priv->hw_roc_disable_work);
  897. del_timer_sync(&priv->statistics_periodic);
  898. del_timer_sync(&priv->ucode_trace);
  899. }
  900. static int iwl_init_drv(struct iwl_priv *priv)
  901. {
  902. spin_lock_init(&priv->sta_lock);
  903. mutex_init(&priv->mutex);
  904. INIT_LIST_HEAD(&priv->calib_results);
  905. priv->band = IEEE80211_BAND_2GHZ;
  906. priv->plcp_delta_threshold =
  907. priv->cfg->base_params->plcp_delta_threshold;
  908. priv->iw_mode = NL80211_IFTYPE_STATION;
  909. priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
  910. priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
  911. priv->agg_tids_count = 0;
  912. priv->ucode_owner = IWL_OWNERSHIP_DRIVER;
  913. priv->rx_statistics_jiffies = jiffies;
  914. /* Choose which receivers/antennas to use */
  915. iwlagn_set_rxon_chain(priv, &priv->contexts[IWL_RXON_CTX_BSS]);
  916. iwl_init_scan_params(priv);
  917. /* init bt coex */
  918. if (priv->cfg->bt_params &&
  919. priv->cfg->bt_params->advanced_bt_coexist) {
  920. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  921. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  922. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  923. priv->bt_on_thresh = BT_ON_THRESHOLD_DEF;
  924. priv->bt_duration = BT_DURATION_LIMIT_DEF;
  925. priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
  926. }
  927. return 0;
  928. }
  929. static void iwl_uninit_drv(struct iwl_priv *priv)
  930. {
  931. kfree(priv->scan_cmd);
  932. kfree(priv->beacon_cmd);
  933. kfree(rcu_dereference_raw(priv->noa_data));
  934. iwl_calib_free_results(priv);
  935. #ifdef CONFIG_IWLWIFI_DEBUGFS
  936. kfree(priv->wowlan_sram);
  937. #endif
  938. }
  939. static void iwl_set_hw_params(struct iwl_priv *priv)
  940. {
  941. if (priv->cfg->ht_params)
  942. priv->hw_params.use_rts_for_aggregation =
  943. priv->cfg->ht_params->use_rts_for_aggregation;
  944. /* Device-specific setup */
  945. priv->lib->set_hw_params(priv);
  946. }
  947. /* show what optional capabilities we have */
  948. static void iwl_option_config(struct iwl_priv *priv)
  949. {
  950. #ifdef CONFIG_IWLWIFI_DEBUG
  951. IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUG enabled\n");
  952. #else
  953. IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUG disabled\n");
  954. #endif
  955. #ifdef CONFIG_IWLWIFI_DEBUGFS
  956. IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUGFS enabled\n");
  957. #else
  958. IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUGFS disabled\n");
  959. #endif
  960. #ifdef CONFIG_IWLWIFI_DEVICE_TRACING
  961. IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TRACING enabled\n");
  962. #else
  963. IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TRACING disabled\n");
  964. #endif
  965. #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
  966. IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TESTMODE enabled\n");
  967. #else
  968. IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TESTMODE disabled\n");
  969. #endif
  970. #ifdef CONFIG_IWLWIFI_P2P
  971. IWL_INFO(priv, "CONFIG_IWLWIFI_P2P enabled\n");
  972. #else
  973. IWL_INFO(priv, "CONFIG_IWLWIFI_P2P disabled\n");
  974. #endif
  975. }
  976. static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
  977. {
  978. priv->eeprom_data->sku = priv->eeprom_data->sku;
  979. if (priv->eeprom_data->sku & EEPROM_SKU_CAP_11N_ENABLE &&
  980. !priv->cfg->ht_params) {
  981. IWL_ERR(priv, "Invalid 11n configuration\n");
  982. return -EINVAL;
  983. }
  984. if (!priv->eeprom_data->sku) {
  985. IWL_ERR(priv, "Invalid device sku\n");
  986. return -EINVAL;
  987. }
  988. IWL_INFO(priv, "Device SKU: 0x%X\n", priv->eeprom_data->sku);
  989. priv->hw_params.tx_chains_num =
  990. num_of_ant(priv->eeprom_data->valid_tx_ant);
  991. if (priv->cfg->rx_with_siso_diversity)
  992. priv->hw_params.rx_chains_num = 1;
  993. else
  994. priv->hw_params.rx_chains_num =
  995. num_of_ant(priv->eeprom_data->valid_rx_ant);
  996. IWL_INFO(priv, "Valid Tx ant: 0x%X, Valid Rx ant: 0x%X\n",
  997. priv->eeprom_data->valid_tx_ant,
  998. priv->eeprom_data->valid_rx_ant);
  999. return 0;
  1000. }
  1001. static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
  1002. const struct iwl_cfg *cfg,
  1003. const struct iwl_fw *fw,
  1004. struct dentry *dbgfs_dir)
  1005. {
  1006. struct iwl_priv *priv;
  1007. struct ieee80211_hw *hw;
  1008. struct iwl_op_mode *op_mode;
  1009. u16 num_mac;
  1010. u32 ucode_flags;
  1011. struct iwl_trans_config trans_cfg;
  1012. static const u8 no_reclaim_cmds[] = {
  1013. REPLY_RX_PHY_CMD,
  1014. REPLY_RX_MPDU_CMD,
  1015. REPLY_COMPRESSED_BA,
  1016. STATISTICS_NOTIFICATION,
  1017. REPLY_TX,
  1018. };
  1019. int i;
  1020. /************************
  1021. * 1. Allocating HW data
  1022. ************************/
  1023. hw = iwl_alloc_all();
  1024. if (!hw) {
  1025. pr_err("%s: Cannot allocate network device\n", cfg->name);
  1026. goto out;
  1027. }
  1028. op_mode = hw->priv;
  1029. op_mode->ops = &iwl_dvm_ops;
  1030. priv = IWL_OP_MODE_GET_DVM(op_mode);
  1031. priv->trans = trans;
  1032. priv->dev = trans->dev;
  1033. priv->cfg = cfg;
  1034. priv->fw = fw;
  1035. switch (priv->cfg->device_family) {
  1036. case IWL_DEVICE_FAMILY_1000:
  1037. case IWL_DEVICE_FAMILY_100:
  1038. priv->lib = &iwl1000_lib;
  1039. break;
  1040. case IWL_DEVICE_FAMILY_2000:
  1041. case IWL_DEVICE_FAMILY_105:
  1042. priv->lib = &iwl2000_lib;
  1043. break;
  1044. case IWL_DEVICE_FAMILY_2030:
  1045. case IWL_DEVICE_FAMILY_135:
  1046. priv->lib = &iwl2030_lib;
  1047. break;
  1048. case IWL_DEVICE_FAMILY_5000:
  1049. priv->lib = &iwl5000_lib;
  1050. break;
  1051. case IWL_DEVICE_FAMILY_5150:
  1052. priv->lib = &iwl5150_lib;
  1053. break;
  1054. case IWL_DEVICE_FAMILY_6000:
  1055. case IWL_DEVICE_FAMILY_6005:
  1056. case IWL_DEVICE_FAMILY_6000i:
  1057. case IWL_DEVICE_FAMILY_6050:
  1058. case IWL_DEVICE_FAMILY_6150:
  1059. priv->lib = &iwl6000_lib;
  1060. break;
  1061. case IWL_DEVICE_FAMILY_6030:
  1062. priv->lib = &iwl6030_lib;
  1063. break;
  1064. default:
  1065. break;
  1066. }
  1067. if (WARN_ON(!priv->lib))
  1068. goto out_free_hw;
  1069. /*
  1070. * Populate the state variables that the transport layer needs
  1071. * to know about.
  1072. */
  1073. trans_cfg.op_mode = op_mode;
  1074. trans_cfg.no_reclaim_cmds = no_reclaim_cmds;
  1075. trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
  1076. trans_cfg.rx_buf_size_8k = iwlwifi_mod_params.amsdu_size_8K;
  1077. if (!iwlwifi_mod_params.wd_disable)
  1078. trans_cfg.queue_watchdog_timeout =
  1079. priv->cfg->base_params->wd_timeout;
  1080. else
  1081. trans_cfg.queue_watchdog_timeout = IWL_WATCHDOG_DISABLED;
  1082. trans_cfg.command_names = iwl_dvm_cmd_strings;
  1083. trans_cfg.cmd_fifo = IWLAGN_CMD_FIFO_NUM;
  1084. WARN_ON(sizeof(priv->transport_queue_stop) * BITS_PER_BYTE <
  1085. priv->cfg->base_params->num_of_queues);
  1086. ucode_flags = fw->ucode_capa.flags;
  1087. #ifndef CONFIG_IWLWIFI_P2P
  1088. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_P2P;
  1089. #endif
  1090. if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN) {
  1091. priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
  1092. trans_cfg.cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
  1093. } else {
  1094. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  1095. trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  1096. }
  1097. /* Configure transport layer */
  1098. iwl_trans_configure(priv->trans, &trans_cfg);
  1099. trans->rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
  1100. trans->rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_res_start);
  1101. /* At this point both hw and priv are allocated. */
  1102. SET_IEEE80211_DEV(priv->hw, priv->trans->dev);
  1103. iwl_option_config(priv);
  1104. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  1105. /* is antenna coupling more than 35dB ? */
  1106. priv->bt_ant_couple_ok =
  1107. (iwlwifi_mod_params.ant_coupling >
  1108. IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
  1109. true : false;
  1110. /* enable/disable bt channel inhibition */
  1111. priv->bt_ch_announce = iwlwifi_mod_params.bt_ch_announce;
  1112. IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n",
  1113. (priv->bt_ch_announce) ? "On" : "Off");
  1114. /* these spin locks will be used in apm_ops.init and EEPROM access
  1115. * we should init now
  1116. */
  1117. spin_lock_init(&priv->statistics.lock);
  1118. /***********************
  1119. * 2. Read REV register
  1120. ***********************/
  1121. IWL_INFO(priv, "Detected %s, REV=0x%X\n",
  1122. priv->cfg->name, priv->trans->hw_rev);
  1123. if (iwl_trans_start_hw(priv->trans))
  1124. goto out_free_hw;
  1125. /* Read the EEPROM */
  1126. if (iwl_read_eeprom(priv->trans, &priv->eeprom_blob,
  1127. &priv->eeprom_blob_size)) {
  1128. IWL_ERR(priv, "Unable to init EEPROM\n");
  1129. goto out_free_hw;
  1130. }
  1131. /* Reset chip to save power until we load uCode during "up". */
  1132. iwl_trans_stop_hw(priv->trans, false);
  1133. priv->eeprom_data = iwl_parse_eeprom_data(priv->trans->dev, priv->cfg,
  1134. priv->eeprom_blob,
  1135. priv->eeprom_blob_size);
  1136. if (!priv->eeprom_data)
  1137. goto out_free_eeprom_blob;
  1138. if (iwl_eeprom_check_version(priv->eeprom_data, priv->trans))
  1139. goto out_free_eeprom;
  1140. if (iwl_eeprom_init_hw_params(priv))
  1141. goto out_free_eeprom;
  1142. /* extract MAC Address */
  1143. memcpy(priv->addresses[0].addr, priv->eeprom_data->hw_addr, ETH_ALEN);
  1144. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
  1145. priv->hw->wiphy->addresses = priv->addresses;
  1146. priv->hw->wiphy->n_addresses = 1;
  1147. num_mac = priv->eeprom_data->n_hw_addrs;
  1148. if (num_mac > 1) {
  1149. memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
  1150. ETH_ALEN);
  1151. priv->addresses[1].addr[5]++;
  1152. priv->hw->wiphy->n_addresses++;
  1153. }
  1154. /************************
  1155. * 4. Setup HW constants
  1156. ************************/
  1157. iwl_set_hw_params(priv);
  1158. if (!(priv->eeprom_data->sku & EEPROM_SKU_CAP_IPAN_ENABLE)) {
  1159. IWL_DEBUG_INFO(priv, "Your EEPROM disabled PAN");
  1160. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
  1161. /*
  1162. * if not PAN, then don't support P2P -- might be a uCode
  1163. * packaging bug or due to the eeprom check above
  1164. */
  1165. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_P2P;
  1166. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  1167. trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  1168. /* Configure transport layer again*/
  1169. iwl_trans_configure(priv->trans, &trans_cfg);
  1170. }
  1171. /*******************
  1172. * 5. Setup priv
  1173. *******************/
  1174. for (i = 0; i < IWL_MAX_HW_QUEUES; i++) {
  1175. priv->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE;
  1176. if (i < IWLAGN_FIRST_AMPDU_QUEUE &&
  1177. i != IWL_DEFAULT_CMD_QUEUE_NUM &&
  1178. i != IWL_IPAN_CMD_QUEUE_NUM)
  1179. priv->queue_to_mac80211[i] = i;
  1180. atomic_set(&priv->queue_stop_count[i], 0);
  1181. }
  1182. if (iwl_init_drv(priv))
  1183. goto out_free_eeprom;
  1184. /* At this point both hw and priv are initialized. */
  1185. /********************
  1186. * 6. Setup services
  1187. ********************/
  1188. iwl_setup_deferred_work(priv);
  1189. iwl_setup_rx_handlers(priv);
  1190. iwl_testmode_init(priv);
  1191. iwl_power_initialize(priv);
  1192. iwl_tt_initialize(priv);
  1193. snprintf(priv->hw->wiphy->fw_version,
  1194. sizeof(priv->hw->wiphy->fw_version),
  1195. "%s", fw->fw_version);
  1196. priv->new_scan_threshold_behaviour =
  1197. !!(ucode_flags & IWL_UCODE_TLV_FLAGS_NEWSCAN);
  1198. priv->phy_calib_chain_noise_reset_cmd =
  1199. fw->ucode_capa.standard_phy_calibration_size;
  1200. priv->phy_calib_chain_noise_gain_cmd =
  1201. fw->ucode_capa.standard_phy_calibration_size + 1;
  1202. /* initialize all valid contexts */
  1203. iwl_init_context(priv, ucode_flags);
  1204. /**************************************************
  1205. * This is still part of probe() in a sense...
  1206. *
  1207. * 7. Setup and register with mac80211 and debugfs
  1208. **************************************************/
  1209. if (iwlagn_mac_setup_register(priv, &fw->ucode_capa))
  1210. goto out_destroy_workqueue;
  1211. if (iwl_dbgfs_register(priv, dbgfs_dir))
  1212. goto out_mac80211_unregister;
  1213. return op_mode;
  1214. out_mac80211_unregister:
  1215. iwlagn_mac_unregister(priv);
  1216. out_destroy_workqueue:
  1217. iwl_tt_exit(priv);
  1218. iwl_testmode_free(priv);
  1219. iwl_cancel_deferred_work(priv);
  1220. destroy_workqueue(priv->workqueue);
  1221. priv->workqueue = NULL;
  1222. iwl_uninit_drv(priv);
  1223. out_free_eeprom_blob:
  1224. kfree(priv->eeprom_blob);
  1225. out_free_eeprom:
  1226. iwl_free_eeprom_data(priv->eeprom_data);
  1227. out_free_hw:
  1228. ieee80211_free_hw(priv->hw);
  1229. out:
  1230. op_mode = NULL;
  1231. return op_mode;
  1232. }
  1233. static void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode)
  1234. {
  1235. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1236. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  1237. iwl_testmode_free(priv);
  1238. iwlagn_mac_unregister(priv);
  1239. iwl_tt_exit(priv);
  1240. kfree(priv->eeprom_blob);
  1241. iwl_free_eeprom_data(priv->eeprom_data);
  1242. /*netif_stop_queue(dev); */
  1243. flush_workqueue(priv->workqueue);
  1244. /* ieee80211_unregister_hw calls iwlagn_mac_stop, which flushes
  1245. * priv->workqueue... so we can't take down the workqueue
  1246. * until now... */
  1247. destroy_workqueue(priv->workqueue);
  1248. priv->workqueue = NULL;
  1249. iwl_uninit_drv(priv);
  1250. dev_kfree_skb(priv->beacon_skb);
  1251. iwl_trans_stop_hw(priv->trans, true);
  1252. ieee80211_free_hw(priv->hw);
  1253. }
  1254. static const char * const desc_lookup_text[] = {
  1255. "OK",
  1256. "FAIL",
  1257. "BAD_PARAM",
  1258. "BAD_CHECKSUM",
  1259. "NMI_INTERRUPT_WDG",
  1260. "SYSASSERT",
  1261. "FATAL_ERROR",
  1262. "BAD_COMMAND",
  1263. "HW_ERROR_TUNE_LOCK",
  1264. "HW_ERROR_TEMPERATURE",
  1265. "ILLEGAL_CHAN_FREQ",
  1266. "VCC_NOT_STABLE",
  1267. "FH_ERROR",
  1268. "NMI_INTERRUPT_HOST",
  1269. "NMI_INTERRUPT_ACTION_PT",
  1270. "NMI_INTERRUPT_UNKNOWN",
  1271. "UCODE_VERSION_MISMATCH",
  1272. "HW_ERROR_ABS_LOCK",
  1273. "HW_ERROR_CAL_LOCK_FAIL",
  1274. "NMI_INTERRUPT_INST_ACTION_PT",
  1275. "NMI_INTERRUPT_DATA_ACTION_PT",
  1276. "NMI_TRM_HW_ER",
  1277. "NMI_INTERRUPT_TRM",
  1278. "NMI_INTERRUPT_BREAK_POINT",
  1279. "DEBUG_0",
  1280. "DEBUG_1",
  1281. "DEBUG_2",
  1282. "DEBUG_3",
  1283. };
  1284. static struct { char *name; u8 num; } advanced_lookup[] = {
  1285. { "NMI_INTERRUPT_WDG", 0x34 },
  1286. { "SYSASSERT", 0x35 },
  1287. { "UCODE_VERSION_MISMATCH", 0x37 },
  1288. { "BAD_COMMAND", 0x38 },
  1289. { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
  1290. { "FATAL_ERROR", 0x3D },
  1291. { "NMI_TRM_HW_ERR", 0x46 },
  1292. { "NMI_INTERRUPT_TRM", 0x4C },
  1293. { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
  1294. { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
  1295. { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
  1296. { "NMI_INTERRUPT_HOST", 0x66 },
  1297. { "NMI_INTERRUPT_ACTION_PT", 0x7C },
  1298. { "NMI_INTERRUPT_UNKNOWN", 0x84 },
  1299. { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
  1300. { "ADVANCED_SYSASSERT", 0 },
  1301. };
  1302. static const char *desc_lookup(u32 num)
  1303. {
  1304. int i;
  1305. int max = ARRAY_SIZE(desc_lookup_text);
  1306. if (num < max)
  1307. return desc_lookup_text[num];
  1308. max = ARRAY_SIZE(advanced_lookup) - 1;
  1309. for (i = 0; i < max; i++) {
  1310. if (advanced_lookup[i].num == num)
  1311. break;
  1312. }
  1313. return advanced_lookup[i].name;
  1314. }
  1315. #define ERROR_START_OFFSET (1 * sizeof(u32))
  1316. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  1317. static void iwl_dump_nic_error_log(struct iwl_priv *priv)
  1318. {
  1319. struct iwl_trans *trans = priv->trans;
  1320. u32 base;
  1321. struct iwl_error_event_table table;
  1322. base = priv->device_pointers.error_event_table;
  1323. if (priv->cur_ucode == IWL_UCODE_INIT) {
  1324. if (!base)
  1325. base = priv->fw->init_errlog_ptr;
  1326. } else {
  1327. if (!base)
  1328. base = priv->fw->inst_errlog_ptr;
  1329. }
  1330. if (!iwlagn_hw_valid_rtc_data_addr(base)) {
  1331. IWL_ERR(priv,
  1332. "Not valid error log pointer 0x%08X for %s uCode\n",
  1333. base,
  1334. (priv->cur_ucode == IWL_UCODE_INIT)
  1335. ? "Init" : "RT");
  1336. return;
  1337. }
  1338. /*TODO: Update dbgfs with ISR error stats obtained below */
  1339. iwl_read_targ_mem_bytes(trans, base, &table, sizeof(table));
  1340. if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
  1341. IWL_ERR(trans, "Start IWL Error Log Dump:\n");
  1342. IWL_ERR(trans, "Status: 0x%08lX, count: %d\n",
  1343. priv->status, table.valid);
  1344. }
  1345. trace_iwlwifi_dev_ucode_error(trans->dev, table.error_id, table.tsf_low,
  1346. table.data1, table.data2, table.line,
  1347. table.blink1, table.blink2, table.ilink1,
  1348. table.ilink2, table.bcon_time, table.gp1,
  1349. table.gp2, table.gp3, table.ucode_ver,
  1350. table.hw_ver, table.brd_ver);
  1351. IWL_ERR(priv, "0x%08X | %-28s\n", table.error_id,
  1352. desc_lookup(table.error_id));
  1353. IWL_ERR(priv, "0x%08X | uPc\n", table.pc);
  1354. IWL_ERR(priv, "0x%08X | branchlink1\n", table.blink1);
  1355. IWL_ERR(priv, "0x%08X | branchlink2\n", table.blink2);
  1356. IWL_ERR(priv, "0x%08X | interruptlink1\n", table.ilink1);
  1357. IWL_ERR(priv, "0x%08X | interruptlink2\n", table.ilink2);
  1358. IWL_ERR(priv, "0x%08X | data1\n", table.data1);
  1359. IWL_ERR(priv, "0x%08X | data2\n", table.data2);
  1360. IWL_ERR(priv, "0x%08X | line\n", table.line);
  1361. IWL_ERR(priv, "0x%08X | beacon time\n", table.bcon_time);
  1362. IWL_ERR(priv, "0x%08X | tsf low\n", table.tsf_low);
  1363. IWL_ERR(priv, "0x%08X | tsf hi\n", table.tsf_hi);
  1364. IWL_ERR(priv, "0x%08X | time gp1\n", table.gp1);
  1365. IWL_ERR(priv, "0x%08X | time gp2\n", table.gp2);
  1366. IWL_ERR(priv, "0x%08X | time gp3\n", table.gp3);
  1367. IWL_ERR(priv, "0x%08X | uCode version\n", table.ucode_ver);
  1368. IWL_ERR(priv, "0x%08X | hw version\n", table.hw_ver);
  1369. IWL_ERR(priv, "0x%08X | board version\n", table.brd_ver);
  1370. IWL_ERR(priv, "0x%08X | hcmd\n", table.hcmd);
  1371. IWL_ERR(priv, "0x%08X | isr0\n", table.isr0);
  1372. IWL_ERR(priv, "0x%08X | isr1\n", table.isr1);
  1373. IWL_ERR(priv, "0x%08X | isr2\n", table.isr2);
  1374. IWL_ERR(priv, "0x%08X | isr3\n", table.isr3);
  1375. IWL_ERR(priv, "0x%08X | isr4\n", table.isr4);
  1376. IWL_ERR(priv, "0x%08X | isr_pref\n", table.isr_pref);
  1377. IWL_ERR(priv, "0x%08X | wait_event\n", table.wait_event);
  1378. IWL_ERR(priv, "0x%08X | l2p_control\n", table.l2p_control);
  1379. IWL_ERR(priv, "0x%08X | l2p_duration\n", table.l2p_duration);
  1380. IWL_ERR(priv, "0x%08X | l2p_mhvalid\n", table.l2p_mhvalid);
  1381. IWL_ERR(priv, "0x%08X | l2p_addr_match\n", table.l2p_addr_match);
  1382. IWL_ERR(priv, "0x%08X | lmpm_pmg_sel\n", table.lmpm_pmg_sel);
  1383. IWL_ERR(priv, "0x%08X | timestamp\n", table.u_timestamp);
  1384. IWL_ERR(priv, "0x%08X | flow_handler\n", table.flow_handler);
  1385. }
  1386. #define EVENT_START_OFFSET (4 * sizeof(u32))
  1387. /**
  1388. * iwl_print_event_log - Dump error event log to syslog
  1389. *
  1390. */
  1391. static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
  1392. u32 num_events, u32 mode,
  1393. int pos, char **buf, size_t bufsz)
  1394. {
  1395. u32 i;
  1396. u32 base; /* SRAM byte address of event log header */
  1397. u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
  1398. u32 ptr; /* SRAM byte address of log data */
  1399. u32 ev, time, data; /* event log data */
  1400. unsigned long reg_flags;
  1401. struct iwl_trans *trans = priv->trans;
  1402. if (num_events == 0)
  1403. return pos;
  1404. base = priv->device_pointers.log_event_table;
  1405. if (priv->cur_ucode == IWL_UCODE_INIT) {
  1406. if (!base)
  1407. base = priv->fw->init_evtlog_ptr;
  1408. } else {
  1409. if (!base)
  1410. base = priv->fw->inst_evtlog_ptr;
  1411. }
  1412. if (mode == 0)
  1413. event_size = 2 * sizeof(u32);
  1414. else
  1415. event_size = 3 * sizeof(u32);
  1416. ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
  1417. /* Make sure device is powered up for SRAM reads */
  1418. spin_lock_irqsave(&trans->reg_lock, reg_flags);
  1419. if (unlikely(!iwl_grab_nic_access(trans)))
  1420. goto out_unlock;
  1421. /* Set starting address; reads will auto-increment */
  1422. iwl_write32(trans, HBUS_TARG_MEM_RADDR, ptr);
  1423. /* "time" is actually "data" for mode 0 (no timestamp).
  1424. * place event id # at far right for easier visual parsing. */
  1425. for (i = 0; i < num_events; i++) {
  1426. ev = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
  1427. time = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
  1428. if (mode == 0) {
  1429. /* data, ev */
  1430. if (bufsz) {
  1431. pos += scnprintf(*buf + pos, bufsz - pos,
  1432. "EVT_LOG:0x%08x:%04u\n",
  1433. time, ev);
  1434. } else {
  1435. trace_iwlwifi_dev_ucode_event(trans->dev, 0,
  1436. time, ev);
  1437. IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n",
  1438. time, ev);
  1439. }
  1440. } else {
  1441. data = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
  1442. if (bufsz) {
  1443. pos += scnprintf(*buf + pos, bufsz - pos,
  1444. "EVT_LOGT:%010u:0x%08x:%04u\n",
  1445. time, data, ev);
  1446. } else {
  1447. IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
  1448. time, data, ev);
  1449. trace_iwlwifi_dev_ucode_event(trans->dev, time,
  1450. data, ev);
  1451. }
  1452. }
  1453. }
  1454. /* Allow device to power down */
  1455. iwl_release_nic_access(trans);
  1456. out_unlock:
  1457. spin_unlock_irqrestore(&trans->reg_lock, 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_read_targ_mem(trans, base);
  1529. mode = iwl_read_targ_mem(trans, base + (1 * sizeof(u32)));
  1530. num_wraps = iwl_read_targ_mem(trans, base + (2 * sizeof(u32)));
  1531. next_entry = iwl_read_targ_mem(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. u16 radio_cfg = priv->eeprom_data->radio_cfg;
  1660. /* SKU Control */
  1661. iwl_set_bits_mask(priv->trans, CSR_HW_IF_CONFIG_REG,
  1662. CSR_HW_IF_CONFIG_REG_MSK_MAC_DASH |
  1663. CSR_HW_IF_CONFIG_REG_MSK_MAC_STEP,
  1664. (CSR_HW_REV_STEP(priv->trans->hw_rev) <<
  1665. CSR_HW_IF_CONFIG_REG_POS_MAC_STEP) |
  1666. (CSR_HW_REV_DASH(priv->trans->hw_rev) <<
  1667. CSR_HW_IF_CONFIG_REG_POS_MAC_DASH));
  1668. /* write radio config values to register */
  1669. if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) <= EEPROM_RF_CONFIG_TYPE_MAX) {
  1670. u32 reg_val =
  1671. EEPROM_RF_CFG_TYPE_MSK(radio_cfg) <<
  1672. CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE |
  1673. EEPROM_RF_CFG_STEP_MSK(radio_cfg) <<
  1674. CSR_HW_IF_CONFIG_REG_POS_PHY_STEP |
  1675. EEPROM_RF_CFG_DASH_MSK(radio_cfg) <<
  1676. CSR_HW_IF_CONFIG_REG_POS_PHY_DASH;
  1677. iwl_set_bits_mask(priv->trans, CSR_HW_IF_CONFIG_REG,
  1678. CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE |
  1679. CSR_HW_IF_CONFIG_REG_MSK_PHY_STEP |
  1680. CSR_HW_IF_CONFIG_REG_MSK_PHY_DASH, reg_val);
  1681. IWL_INFO(priv, "Radio type=0x%x-0x%x-0x%x\n",
  1682. EEPROM_RF_CFG_TYPE_MSK(radio_cfg),
  1683. EEPROM_RF_CFG_STEP_MSK(radio_cfg),
  1684. EEPROM_RF_CFG_DASH_MSK(radio_cfg));
  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. dev_kfree_skb_any(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);