main.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of version 2 of the GNU General Public License as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  30. #include <linux/kernel.h>
  31. #include <linux/module.h>
  32. #include <linux/init.h>
  33. #include <linux/slab.h>
  34. #include <linux/delay.h>
  35. #include <linux/sched.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/netdevice.h>
  38. #include <linux/etherdevice.h>
  39. #include <linux/if_arp.h>
  40. #include <net/mac80211.h>
  41. #include <asm/div64.h>
  42. #include "iwl-eeprom-read.h"
  43. #include "iwl-eeprom-parse.h"
  44. #include "iwl-io.h"
  45. #include "iwl-trans.h"
  46. #include "iwl-op-mode.h"
  47. #include "iwl-drv.h"
  48. #include "iwl-modparams.h"
  49. #include "iwl-prph.h"
  50. #include "dev.h"
  51. #include "calib.h"
  52. #include "agn.h"
  53. /******************************************************************************
  54. *
  55. * module boiler plate
  56. *
  57. ******************************************************************************/
  58. /*
  59. * module name, copyright, version, etc.
  60. */
  61. #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
  62. #ifdef CONFIG_IWLWIFI_DEBUG
  63. #define VD "d"
  64. #else
  65. #define VD
  66. #endif
  67. #define DRV_VERSION IWLWIFI_VERSION VD
  68. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  69. MODULE_VERSION(DRV_VERSION);
  70. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  71. MODULE_LICENSE("GPL");
  72. static const struct iwl_op_mode_ops iwl_dvm_ops;
  73. void iwl_update_chain_flags(struct iwl_priv *priv)
  74. {
  75. struct iwl_rxon_context *ctx;
  76. for_each_context(priv, ctx) {
  77. iwlagn_set_rxon_chain(priv, ctx);
  78. if (ctx->active.rx_chain != ctx->staging.rx_chain)
  79. iwlagn_commit_rxon(priv, ctx);
  80. }
  81. }
  82. /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
  83. static void iwl_set_beacon_tim(struct iwl_priv *priv,
  84. struct iwl_tx_beacon_cmd *tx_beacon_cmd,
  85. u8 *beacon, u32 frame_size)
  86. {
  87. u16 tim_idx;
  88. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
  89. /*
  90. * The index is relative to frame start but we start looking at the
  91. * variable-length part of the beacon.
  92. */
  93. tim_idx = mgmt->u.beacon.variable - beacon;
  94. /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
  95. while ((tim_idx < (frame_size - 2)) &&
  96. (beacon[tim_idx] != WLAN_EID_TIM))
  97. tim_idx += beacon[tim_idx+1] + 2;
  98. /* If TIM field was found, set variables */
  99. if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
  100. tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
  101. tx_beacon_cmd->tim_size = beacon[tim_idx+1];
  102. } else
  103. IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
  104. }
  105. int iwlagn_send_beacon_cmd(struct iwl_priv *priv)
  106. {
  107. struct iwl_tx_beacon_cmd *tx_beacon_cmd;
  108. struct iwl_host_cmd cmd = {
  109. .id = REPLY_TX_BEACON,
  110. .flags = CMD_SYNC,
  111. };
  112. struct ieee80211_tx_info *info;
  113. u32 frame_size;
  114. u32 rate_flags;
  115. u32 rate;
  116. /*
  117. * We have to set up the TX command, the TX Beacon command, and the
  118. * beacon contents.
  119. */
  120. lockdep_assert_held(&priv->mutex);
  121. if (!priv->beacon_ctx) {
  122. IWL_ERR(priv, "trying to build beacon w/o beacon context!\n");
  123. return 0;
  124. }
  125. if (WARN_ON(!priv->beacon_skb))
  126. return -EINVAL;
  127. /* Allocate beacon command */
  128. if (!priv->beacon_cmd)
  129. priv->beacon_cmd = kzalloc(sizeof(*tx_beacon_cmd), GFP_KERNEL);
  130. tx_beacon_cmd = priv->beacon_cmd;
  131. if (!tx_beacon_cmd)
  132. return -ENOMEM;
  133. frame_size = priv->beacon_skb->len;
  134. /* Set up TX command fields */
  135. tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
  136. tx_beacon_cmd->tx.sta_id = priv->beacon_ctx->bcast_sta_id;
  137. tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  138. tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
  139. TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
  140. /* Set up TX beacon command fields */
  141. iwl_set_beacon_tim(priv, tx_beacon_cmd, priv->beacon_skb->data,
  142. frame_size);
  143. /* Set up packet rate and flags */
  144. info = IEEE80211_SKB_CB(priv->beacon_skb);
  145. /*
  146. * Let's set up the rate at least somewhat correctly;
  147. * it will currently not actually be used by the uCode,
  148. * it uses the broadcast station's rate instead.
  149. */
  150. if (info->control.rates[0].idx < 0 ||
  151. info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
  152. rate = 0;
  153. else
  154. rate = info->control.rates[0].idx;
  155. priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
  156. priv->nvm_data->valid_tx_ant);
  157. rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
  158. /* In mac80211, rates for 5 GHz start at 0 */
  159. if (info->band == IEEE80211_BAND_5GHZ)
  160. rate += IWL_FIRST_OFDM_RATE;
  161. else if (rate >= IWL_FIRST_CCK_RATE && rate <= IWL_LAST_CCK_RATE)
  162. rate_flags |= RATE_MCS_CCK_MSK;
  163. tx_beacon_cmd->tx.rate_n_flags =
  164. iwl_hw_set_rate_n_flags(rate, rate_flags);
  165. /* Submit command */
  166. cmd.len[0] = sizeof(*tx_beacon_cmd);
  167. cmd.data[0] = tx_beacon_cmd;
  168. cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
  169. cmd.len[1] = frame_size;
  170. cmd.data[1] = priv->beacon_skb->data;
  171. cmd.dataflags[1] = IWL_HCMD_DFL_NOCOPY;
  172. return iwl_dvm_send_cmd(priv, &cmd);
  173. }
  174. static void iwl_bg_beacon_update(struct work_struct *work)
  175. {
  176. struct iwl_priv *priv =
  177. container_of(work, struct iwl_priv, beacon_update);
  178. struct sk_buff *beacon;
  179. mutex_lock(&priv->mutex);
  180. if (!priv->beacon_ctx) {
  181. IWL_ERR(priv, "updating beacon w/o beacon context!\n");
  182. goto out;
  183. }
  184. if (priv->beacon_ctx->vif->type != NL80211_IFTYPE_AP) {
  185. /*
  186. * The ucode will send beacon notifications even in
  187. * IBSS mode, but we don't want to process them. But
  188. * we need to defer the type check to here due to
  189. * requiring locking around the beacon_ctx access.
  190. */
  191. goto out;
  192. }
  193. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  194. beacon = ieee80211_beacon_get(priv->hw, priv->beacon_ctx->vif);
  195. if (!beacon) {
  196. IWL_ERR(priv, "update beacon failed -- keeping old\n");
  197. goto out;
  198. }
  199. /* new beacon skb is allocated every time; dispose previous.*/
  200. dev_kfree_skb(priv->beacon_skb);
  201. priv->beacon_skb = beacon;
  202. iwlagn_send_beacon_cmd(priv);
  203. out:
  204. mutex_unlock(&priv->mutex);
  205. }
  206. static void iwl_bg_bt_runtime_config(struct work_struct *work)
  207. {
  208. struct iwl_priv *priv =
  209. container_of(work, struct iwl_priv, bt_runtime_config);
  210. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  211. return;
  212. /* dont send host command if rf-kill is on */
  213. if (!iwl_is_ready_rf(priv))
  214. return;
  215. iwlagn_send_advance_bt_config(priv);
  216. }
  217. static void iwl_bg_bt_full_concurrency(struct work_struct *work)
  218. {
  219. struct iwl_priv *priv =
  220. container_of(work, struct iwl_priv, bt_full_concurrency);
  221. struct iwl_rxon_context *ctx;
  222. mutex_lock(&priv->mutex);
  223. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  224. goto out;
  225. /* dont send host command if rf-kill is on */
  226. if (!iwl_is_ready_rf(priv))
  227. goto out;
  228. IWL_DEBUG_INFO(priv, "BT coex in %s mode\n",
  229. priv->bt_full_concurrent ?
  230. "full concurrency" : "3-wire");
  231. /*
  232. * LQ & RXON updated cmds must be sent before BT Config cmd
  233. * to avoid 3-wire collisions
  234. */
  235. for_each_context(priv, ctx) {
  236. iwlagn_set_rxon_chain(priv, ctx);
  237. iwlagn_commit_rxon(priv, ctx);
  238. }
  239. iwlagn_send_advance_bt_config(priv);
  240. out:
  241. mutex_unlock(&priv->mutex);
  242. }
  243. int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
  244. {
  245. struct iwl_statistics_cmd statistics_cmd = {
  246. .configuration_flags =
  247. clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
  248. };
  249. if (flags & CMD_ASYNC)
  250. return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
  251. CMD_ASYNC,
  252. sizeof(struct iwl_statistics_cmd),
  253. &statistics_cmd);
  254. else
  255. return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
  256. CMD_SYNC,
  257. sizeof(struct iwl_statistics_cmd),
  258. &statistics_cmd);
  259. }
  260. /**
  261. * iwl_bg_statistics_periodic - Timer callback to queue statistics
  262. *
  263. * This callback is provided in order to send a statistics request.
  264. *
  265. * This timer function is continually reset to execute within
  266. * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
  267. * was received. We need to ensure we receive the statistics in order
  268. * to update the temperature used for calibrating the TXPOWER.
  269. */
  270. static void iwl_bg_statistics_periodic(unsigned long data)
  271. {
  272. struct iwl_priv *priv = (struct iwl_priv *)data;
  273. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  274. return;
  275. /* dont send host command if rf-kill is on */
  276. if (!iwl_is_ready_rf(priv))
  277. return;
  278. iwl_send_statistics_request(priv, CMD_ASYNC, false);
  279. }
  280. static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base,
  281. u32 start_idx, u32 num_events,
  282. u32 capacity, u32 mode)
  283. {
  284. u32 i;
  285. u32 ptr; /* SRAM byte address of log data */
  286. u32 ev, time, data; /* event log data */
  287. unsigned long reg_flags;
  288. if (mode == 0)
  289. ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32));
  290. else
  291. ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32));
  292. /* Make sure device is powered up for SRAM reads */
  293. spin_lock_irqsave(&priv->trans->reg_lock, reg_flags);
  294. if (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);
  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->nvm_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. struct iwl_nvm_data *data = priv->nvm_data;
  979. char *debug_msg;
  980. if (data->sku_cap_11n_enable &&
  981. !priv->cfg->ht_params) {
  982. IWL_ERR(priv, "Invalid 11n configuration\n");
  983. return -EINVAL;
  984. }
  985. if (!data->sku_cap_11n_enable && !data->sku_cap_band_24GHz_enable &&
  986. !data->sku_cap_band_52GHz_enable) {
  987. IWL_ERR(priv, "Invalid device sku\n");
  988. return -EINVAL;
  989. }
  990. debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
  991. IWL_DEBUG_INFO(priv, debug_msg,
  992. data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
  993. data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
  994. data->sku_cap_11n_enable ? "" : "NOT", "enabled");
  995. priv->hw_params.tx_chains_num =
  996. num_of_ant(data->valid_tx_ant);
  997. if (priv->cfg->rx_with_siso_diversity)
  998. priv->hw_params.rx_chains_num = 1;
  999. else
  1000. priv->hw_params.rx_chains_num =
  1001. num_of_ant(data->valid_rx_ant);
  1002. IWL_DEBUG_INFO(priv, "Valid Tx ant: 0x%X, Valid Rx ant: 0x%X\n",
  1003. data->valid_tx_ant,
  1004. data->valid_rx_ant);
  1005. return 0;
  1006. }
  1007. static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
  1008. const struct iwl_cfg *cfg,
  1009. const struct iwl_fw *fw,
  1010. struct dentry *dbgfs_dir)
  1011. {
  1012. struct iwl_priv *priv;
  1013. struct ieee80211_hw *hw;
  1014. struct iwl_op_mode *op_mode;
  1015. u16 num_mac;
  1016. u32 ucode_flags;
  1017. struct iwl_trans_config trans_cfg = {};
  1018. static const u8 no_reclaim_cmds[] = {
  1019. REPLY_RX_PHY_CMD,
  1020. REPLY_RX_MPDU_CMD,
  1021. REPLY_COMPRESSED_BA,
  1022. STATISTICS_NOTIFICATION,
  1023. REPLY_TX,
  1024. };
  1025. int i;
  1026. /************************
  1027. * 1. Allocating HW data
  1028. ************************/
  1029. hw = iwl_alloc_all();
  1030. if (!hw) {
  1031. pr_err("%s: Cannot allocate network device\n", cfg->name);
  1032. goto out;
  1033. }
  1034. op_mode = hw->priv;
  1035. op_mode->ops = &iwl_dvm_ops;
  1036. priv = IWL_OP_MODE_GET_DVM(op_mode);
  1037. priv->trans = trans;
  1038. priv->dev = trans->dev;
  1039. priv->cfg = cfg;
  1040. priv->fw = fw;
  1041. switch (priv->cfg->device_family) {
  1042. case IWL_DEVICE_FAMILY_1000:
  1043. case IWL_DEVICE_FAMILY_100:
  1044. priv->lib = &iwl1000_lib;
  1045. break;
  1046. case IWL_DEVICE_FAMILY_2000:
  1047. case IWL_DEVICE_FAMILY_105:
  1048. priv->lib = &iwl2000_lib;
  1049. break;
  1050. case IWL_DEVICE_FAMILY_2030:
  1051. case IWL_DEVICE_FAMILY_135:
  1052. priv->lib = &iwl2030_lib;
  1053. break;
  1054. case IWL_DEVICE_FAMILY_5000:
  1055. priv->lib = &iwl5000_lib;
  1056. break;
  1057. case IWL_DEVICE_FAMILY_5150:
  1058. priv->lib = &iwl5150_lib;
  1059. break;
  1060. case IWL_DEVICE_FAMILY_6000:
  1061. case IWL_DEVICE_FAMILY_6005:
  1062. case IWL_DEVICE_FAMILY_6000i:
  1063. case IWL_DEVICE_FAMILY_6050:
  1064. case IWL_DEVICE_FAMILY_6150:
  1065. priv->lib = &iwl6000_lib;
  1066. break;
  1067. case IWL_DEVICE_FAMILY_6030:
  1068. priv->lib = &iwl6030_lib;
  1069. break;
  1070. default:
  1071. break;
  1072. }
  1073. if (WARN_ON(!priv->lib))
  1074. goto out_free_hw;
  1075. /*
  1076. * Populate the state variables that the transport layer needs
  1077. * to know about.
  1078. */
  1079. trans_cfg.op_mode = op_mode;
  1080. trans_cfg.no_reclaim_cmds = no_reclaim_cmds;
  1081. trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
  1082. trans_cfg.rx_buf_size_8k = iwlwifi_mod_params.amsdu_size_8K;
  1083. if (!iwlwifi_mod_params.wd_disable)
  1084. trans_cfg.queue_watchdog_timeout =
  1085. priv->cfg->base_params->wd_timeout;
  1086. else
  1087. trans_cfg.queue_watchdog_timeout = IWL_WATCHDOG_DISABLED;
  1088. trans_cfg.command_names = iwl_dvm_cmd_strings;
  1089. trans_cfg.cmd_fifo = IWLAGN_CMD_FIFO_NUM;
  1090. WARN_ON(sizeof(priv->transport_queue_stop) * BITS_PER_BYTE <
  1091. priv->cfg->base_params->num_of_queues);
  1092. ucode_flags = fw->ucode_capa.flags;
  1093. #ifndef CONFIG_IWLWIFI_P2P
  1094. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_P2P;
  1095. #endif
  1096. if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN) {
  1097. priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
  1098. trans_cfg.cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
  1099. } else {
  1100. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  1101. trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  1102. }
  1103. /* Configure transport layer */
  1104. iwl_trans_configure(priv->trans, &trans_cfg);
  1105. trans->rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
  1106. trans->rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_res_start);
  1107. /* At this point both hw and priv are allocated. */
  1108. SET_IEEE80211_DEV(priv->hw, priv->trans->dev);
  1109. iwl_option_config(priv);
  1110. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  1111. /* is antenna coupling more than 35dB ? */
  1112. priv->bt_ant_couple_ok =
  1113. (iwlwifi_mod_params.ant_coupling >
  1114. IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
  1115. true : false;
  1116. /* enable/disable bt channel inhibition */
  1117. priv->bt_ch_announce = iwlwifi_mod_params.bt_ch_announce;
  1118. IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n",
  1119. (priv->bt_ch_announce) ? "On" : "Off");
  1120. /* these spin locks will be used in apm_ops.init and EEPROM access
  1121. * we should init now
  1122. */
  1123. spin_lock_init(&priv->statistics.lock);
  1124. /***********************
  1125. * 2. Read REV register
  1126. ***********************/
  1127. IWL_INFO(priv, "Detected %s, REV=0x%X\n",
  1128. priv->cfg->name, priv->trans->hw_rev);
  1129. if (iwl_trans_start_hw(priv->trans))
  1130. goto out_free_hw;
  1131. /* Read the EEPROM */
  1132. if (iwl_read_eeprom(priv->trans, &priv->eeprom_blob,
  1133. &priv->eeprom_blob_size)) {
  1134. IWL_ERR(priv, "Unable to init EEPROM\n");
  1135. goto out_free_hw;
  1136. }
  1137. /* Reset chip to save power until we load uCode during "up". */
  1138. iwl_trans_stop_hw(priv->trans, false);
  1139. priv->nvm_data = iwl_parse_eeprom_data(priv->trans->dev, priv->cfg,
  1140. priv->eeprom_blob,
  1141. priv->eeprom_blob_size);
  1142. if (!priv->nvm_data)
  1143. goto out_free_eeprom_blob;
  1144. if (iwl_nvm_check_version(priv->nvm_data, priv->trans))
  1145. goto out_free_eeprom;
  1146. if (iwl_eeprom_init_hw_params(priv))
  1147. goto out_free_eeprom;
  1148. /* extract MAC Address */
  1149. memcpy(priv->addresses[0].addr, priv->nvm_data->hw_addr, ETH_ALEN);
  1150. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
  1151. priv->hw->wiphy->addresses = priv->addresses;
  1152. priv->hw->wiphy->n_addresses = 1;
  1153. num_mac = priv->nvm_data->n_hw_addrs;
  1154. if (num_mac > 1) {
  1155. memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
  1156. ETH_ALEN);
  1157. priv->addresses[1].addr[5]++;
  1158. priv->hw->wiphy->n_addresses++;
  1159. }
  1160. /************************
  1161. * 4. Setup HW constants
  1162. ************************/
  1163. iwl_set_hw_params(priv);
  1164. if (!(priv->nvm_data->sku_cap_ipan_enable)) {
  1165. IWL_DEBUG_INFO(priv, "Your EEPROM disabled PAN");
  1166. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
  1167. /*
  1168. * if not PAN, then don't support P2P -- might be a uCode
  1169. * packaging bug or due to the eeprom check above
  1170. */
  1171. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_P2P;
  1172. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  1173. trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  1174. /* Configure transport layer again*/
  1175. iwl_trans_configure(priv->trans, &trans_cfg);
  1176. }
  1177. /*******************
  1178. * 5. Setup priv
  1179. *******************/
  1180. for (i = 0; i < IWL_MAX_HW_QUEUES; i++) {
  1181. priv->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE;
  1182. if (i < IWLAGN_FIRST_AMPDU_QUEUE &&
  1183. i != IWL_DEFAULT_CMD_QUEUE_NUM &&
  1184. i != IWL_IPAN_CMD_QUEUE_NUM)
  1185. priv->queue_to_mac80211[i] = i;
  1186. atomic_set(&priv->queue_stop_count[i], 0);
  1187. }
  1188. if (iwl_init_drv(priv))
  1189. goto out_free_eeprom;
  1190. /* At this point both hw and priv are initialized. */
  1191. /********************
  1192. * 6. Setup services
  1193. ********************/
  1194. iwl_setup_deferred_work(priv);
  1195. iwl_setup_rx_handlers(priv);
  1196. iwl_testmode_init(priv);
  1197. iwl_power_initialize(priv);
  1198. iwl_tt_initialize(priv);
  1199. snprintf(priv->hw->wiphy->fw_version,
  1200. sizeof(priv->hw->wiphy->fw_version),
  1201. "%s", fw->fw_version);
  1202. priv->new_scan_threshold_behaviour =
  1203. !!(ucode_flags & IWL_UCODE_TLV_FLAGS_NEWSCAN);
  1204. priv->phy_calib_chain_noise_reset_cmd =
  1205. fw->ucode_capa.standard_phy_calibration_size;
  1206. priv->phy_calib_chain_noise_gain_cmd =
  1207. fw->ucode_capa.standard_phy_calibration_size + 1;
  1208. /* initialize all valid contexts */
  1209. iwl_init_context(priv, ucode_flags);
  1210. /**************************************************
  1211. * This is still part of probe() in a sense...
  1212. *
  1213. * 7. Setup and register with mac80211 and debugfs
  1214. **************************************************/
  1215. if (iwlagn_mac_setup_register(priv, &fw->ucode_capa))
  1216. goto out_destroy_workqueue;
  1217. if (iwl_dbgfs_register(priv, dbgfs_dir))
  1218. goto out_mac80211_unregister;
  1219. return op_mode;
  1220. out_mac80211_unregister:
  1221. iwlagn_mac_unregister(priv);
  1222. out_destroy_workqueue:
  1223. iwl_tt_exit(priv);
  1224. iwl_testmode_free(priv);
  1225. iwl_cancel_deferred_work(priv);
  1226. destroy_workqueue(priv->workqueue);
  1227. priv->workqueue = NULL;
  1228. iwl_uninit_drv(priv);
  1229. out_free_eeprom_blob:
  1230. kfree(priv->eeprom_blob);
  1231. out_free_eeprom:
  1232. iwl_free_nvm_data(priv->nvm_data);
  1233. out_free_hw:
  1234. ieee80211_free_hw(priv->hw);
  1235. out:
  1236. op_mode = NULL;
  1237. return op_mode;
  1238. }
  1239. static void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode)
  1240. {
  1241. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1242. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  1243. iwl_testmode_free(priv);
  1244. iwlagn_mac_unregister(priv);
  1245. iwl_tt_exit(priv);
  1246. kfree(priv->eeprom_blob);
  1247. iwl_free_nvm_data(priv->nvm_data);
  1248. /*netif_stop_queue(dev); */
  1249. flush_workqueue(priv->workqueue);
  1250. /* ieee80211_unregister_hw calls iwlagn_mac_stop, which flushes
  1251. * priv->workqueue... so we can't take down the workqueue
  1252. * until now... */
  1253. destroy_workqueue(priv->workqueue);
  1254. priv->workqueue = NULL;
  1255. iwl_uninit_drv(priv);
  1256. dev_kfree_skb(priv->beacon_skb);
  1257. iwl_trans_stop_hw(priv->trans, true);
  1258. ieee80211_free_hw(priv->hw);
  1259. }
  1260. static const char * const desc_lookup_text[] = {
  1261. "OK",
  1262. "FAIL",
  1263. "BAD_PARAM",
  1264. "BAD_CHECKSUM",
  1265. "NMI_INTERRUPT_WDG",
  1266. "SYSASSERT",
  1267. "FATAL_ERROR",
  1268. "BAD_COMMAND",
  1269. "HW_ERROR_TUNE_LOCK",
  1270. "HW_ERROR_TEMPERATURE",
  1271. "ILLEGAL_CHAN_FREQ",
  1272. "VCC_NOT_STABLE",
  1273. "FH_ERROR",
  1274. "NMI_INTERRUPT_HOST",
  1275. "NMI_INTERRUPT_ACTION_PT",
  1276. "NMI_INTERRUPT_UNKNOWN",
  1277. "UCODE_VERSION_MISMATCH",
  1278. "HW_ERROR_ABS_LOCK",
  1279. "HW_ERROR_CAL_LOCK_FAIL",
  1280. "NMI_INTERRUPT_INST_ACTION_PT",
  1281. "NMI_INTERRUPT_DATA_ACTION_PT",
  1282. "NMI_TRM_HW_ER",
  1283. "NMI_INTERRUPT_TRM",
  1284. "NMI_INTERRUPT_BREAK_POINT",
  1285. "DEBUG_0",
  1286. "DEBUG_1",
  1287. "DEBUG_2",
  1288. "DEBUG_3",
  1289. };
  1290. static struct { char *name; u8 num; } advanced_lookup[] = {
  1291. { "NMI_INTERRUPT_WDG", 0x34 },
  1292. { "SYSASSERT", 0x35 },
  1293. { "UCODE_VERSION_MISMATCH", 0x37 },
  1294. { "BAD_COMMAND", 0x38 },
  1295. { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
  1296. { "FATAL_ERROR", 0x3D },
  1297. { "NMI_TRM_HW_ERR", 0x46 },
  1298. { "NMI_INTERRUPT_TRM", 0x4C },
  1299. { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
  1300. { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
  1301. { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
  1302. { "NMI_INTERRUPT_HOST", 0x66 },
  1303. { "NMI_INTERRUPT_ACTION_PT", 0x7C },
  1304. { "NMI_INTERRUPT_UNKNOWN", 0x84 },
  1305. { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
  1306. { "ADVANCED_SYSASSERT", 0 },
  1307. };
  1308. static const char *desc_lookup(u32 num)
  1309. {
  1310. int i;
  1311. int max = ARRAY_SIZE(desc_lookup_text);
  1312. if (num < max)
  1313. return desc_lookup_text[num];
  1314. max = ARRAY_SIZE(advanced_lookup) - 1;
  1315. for (i = 0; i < max; i++) {
  1316. if (advanced_lookup[i].num == num)
  1317. break;
  1318. }
  1319. return advanced_lookup[i].name;
  1320. }
  1321. #define ERROR_START_OFFSET (1 * sizeof(u32))
  1322. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  1323. static void iwl_dump_nic_error_log(struct iwl_priv *priv)
  1324. {
  1325. struct iwl_trans *trans = priv->trans;
  1326. u32 base;
  1327. struct iwl_error_event_table table;
  1328. base = priv->device_pointers.error_event_table;
  1329. if (priv->cur_ucode == IWL_UCODE_INIT) {
  1330. if (!base)
  1331. base = priv->fw->init_errlog_ptr;
  1332. } else {
  1333. if (!base)
  1334. base = priv->fw->inst_errlog_ptr;
  1335. }
  1336. if (!iwlagn_hw_valid_rtc_data_addr(base)) {
  1337. IWL_ERR(priv,
  1338. "Not valid error log pointer 0x%08X for %s uCode\n",
  1339. base,
  1340. (priv->cur_ucode == IWL_UCODE_INIT)
  1341. ? "Init" : "RT");
  1342. return;
  1343. }
  1344. /*TODO: Update dbgfs with ISR error stats obtained below */
  1345. iwl_read_targ_mem_bytes(trans, base, &table, sizeof(table));
  1346. if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
  1347. IWL_ERR(trans, "Start IWL Error Log Dump:\n");
  1348. IWL_ERR(trans, "Status: 0x%08lX, count: %d\n",
  1349. priv->status, table.valid);
  1350. }
  1351. trace_iwlwifi_dev_ucode_error(trans->dev, table.error_id, table.tsf_low,
  1352. table.data1, table.data2, table.line,
  1353. table.blink1, table.blink2, table.ilink1,
  1354. table.ilink2, table.bcon_time, table.gp1,
  1355. table.gp2, table.gp3, table.ucode_ver,
  1356. table.hw_ver, table.brd_ver);
  1357. IWL_ERR(priv, "0x%08X | %-28s\n", table.error_id,
  1358. desc_lookup(table.error_id));
  1359. IWL_ERR(priv, "0x%08X | uPc\n", table.pc);
  1360. IWL_ERR(priv, "0x%08X | branchlink1\n", table.blink1);
  1361. IWL_ERR(priv, "0x%08X | branchlink2\n", table.blink2);
  1362. IWL_ERR(priv, "0x%08X | interruptlink1\n", table.ilink1);
  1363. IWL_ERR(priv, "0x%08X | interruptlink2\n", table.ilink2);
  1364. IWL_ERR(priv, "0x%08X | data1\n", table.data1);
  1365. IWL_ERR(priv, "0x%08X | data2\n", table.data2);
  1366. IWL_ERR(priv, "0x%08X | line\n", table.line);
  1367. IWL_ERR(priv, "0x%08X | beacon time\n", table.bcon_time);
  1368. IWL_ERR(priv, "0x%08X | tsf low\n", table.tsf_low);
  1369. IWL_ERR(priv, "0x%08X | tsf hi\n", table.tsf_hi);
  1370. IWL_ERR(priv, "0x%08X | time gp1\n", table.gp1);
  1371. IWL_ERR(priv, "0x%08X | time gp2\n", table.gp2);
  1372. IWL_ERR(priv, "0x%08X | time gp3\n", table.gp3);
  1373. IWL_ERR(priv, "0x%08X | uCode version\n", table.ucode_ver);
  1374. IWL_ERR(priv, "0x%08X | hw version\n", table.hw_ver);
  1375. IWL_ERR(priv, "0x%08X | board version\n", table.brd_ver);
  1376. IWL_ERR(priv, "0x%08X | hcmd\n", table.hcmd);
  1377. IWL_ERR(priv, "0x%08X | isr0\n", table.isr0);
  1378. IWL_ERR(priv, "0x%08X | isr1\n", table.isr1);
  1379. IWL_ERR(priv, "0x%08X | isr2\n", table.isr2);
  1380. IWL_ERR(priv, "0x%08X | isr3\n", table.isr3);
  1381. IWL_ERR(priv, "0x%08X | isr4\n", table.isr4);
  1382. IWL_ERR(priv, "0x%08X | isr_pref\n", table.isr_pref);
  1383. IWL_ERR(priv, "0x%08X | wait_event\n", table.wait_event);
  1384. IWL_ERR(priv, "0x%08X | l2p_control\n", table.l2p_control);
  1385. IWL_ERR(priv, "0x%08X | l2p_duration\n", table.l2p_duration);
  1386. IWL_ERR(priv, "0x%08X | l2p_mhvalid\n", table.l2p_mhvalid);
  1387. IWL_ERR(priv, "0x%08X | l2p_addr_match\n", table.l2p_addr_match);
  1388. IWL_ERR(priv, "0x%08X | lmpm_pmg_sel\n", table.lmpm_pmg_sel);
  1389. IWL_ERR(priv, "0x%08X | timestamp\n", table.u_timestamp);
  1390. IWL_ERR(priv, "0x%08X | flow_handler\n", table.flow_handler);
  1391. }
  1392. #define EVENT_START_OFFSET (4 * sizeof(u32))
  1393. /**
  1394. * iwl_print_event_log - Dump error event log to syslog
  1395. *
  1396. */
  1397. static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
  1398. u32 num_events, u32 mode,
  1399. int pos, char **buf, size_t bufsz)
  1400. {
  1401. u32 i;
  1402. u32 base; /* SRAM byte address of event log header */
  1403. u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
  1404. u32 ptr; /* SRAM byte address of log data */
  1405. u32 ev, time, data; /* event log data */
  1406. unsigned long reg_flags;
  1407. struct iwl_trans *trans = priv->trans;
  1408. if (num_events == 0)
  1409. return pos;
  1410. base = priv->device_pointers.log_event_table;
  1411. if (priv->cur_ucode == IWL_UCODE_INIT) {
  1412. if (!base)
  1413. base = priv->fw->init_evtlog_ptr;
  1414. } else {
  1415. if (!base)
  1416. base = priv->fw->inst_evtlog_ptr;
  1417. }
  1418. if (mode == 0)
  1419. event_size = 2 * sizeof(u32);
  1420. else
  1421. event_size = 3 * sizeof(u32);
  1422. ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
  1423. /* Make sure device is powered up for SRAM reads */
  1424. spin_lock_irqsave(&trans->reg_lock, reg_flags);
  1425. if (unlikely(!iwl_grab_nic_access(trans)))
  1426. goto out_unlock;
  1427. /* Set starting address; reads will auto-increment */
  1428. iwl_write32(trans, HBUS_TARG_MEM_RADDR, ptr);
  1429. /* "time" is actually "data" for mode 0 (no timestamp).
  1430. * place event id # at far right for easier visual parsing. */
  1431. for (i = 0; i < num_events; i++) {
  1432. ev = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
  1433. time = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
  1434. if (mode == 0) {
  1435. /* data, ev */
  1436. if (bufsz) {
  1437. pos += scnprintf(*buf + pos, bufsz - pos,
  1438. "EVT_LOG:0x%08x:%04u\n",
  1439. time, ev);
  1440. } else {
  1441. trace_iwlwifi_dev_ucode_event(trans->dev, 0,
  1442. time, ev);
  1443. IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n",
  1444. time, ev);
  1445. }
  1446. } else {
  1447. data = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
  1448. if (bufsz) {
  1449. pos += scnprintf(*buf + pos, bufsz - pos,
  1450. "EVT_LOGT:%010u:0x%08x:%04u\n",
  1451. time, data, ev);
  1452. } else {
  1453. IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
  1454. time, data, ev);
  1455. trace_iwlwifi_dev_ucode_event(trans->dev, time,
  1456. data, ev);
  1457. }
  1458. }
  1459. }
  1460. /* Allow device to power down */
  1461. iwl_release_nic_access(trans);
  1462. out_unlock:
  1463. spin_unlock_irqrestore(&trans->reg_lock, reg_flags);
  1464. return pos;
  1465. }
  1466. /**
  1467. * iwl_print_last_event_logs - Dump the newest # of event log to syslog
  1468. */
  1469. static int iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
  1470. u32 num_wraps, u32 next_entry,
  1471. u32 size, u32 mode,
  1472. int pos, char **buf, size_t bufsz)
  1473. {
  1474. /*
  1475. * display the newest DEFAULT_LOG_ENTRIES entries
  1476. * i.e the entries just before the next ont that uCode would fill.
  1477. */
  1478. if (num_wraps) {
  1479. if (next_entry < size) {
  1480. pos = iwl_print_event_log(priv,
  1481. capacity - (size - next_entry),
  1482. size - next_entry, mode,
  1483. pos, buf, bufsz);
  1484. pos = iwl_print_event_log(priv, 0,
  1485. next_entry, mode,
  1486. pos, buf, bufsz);
  1487. } else
  1488. pos = iwl_print_event_log(priv, next_entry - size,
  1489. size, mode, pos, buf, bufsz);
  1490. } else {
  1491. if (next_entry < size) {
  1492. pos = iwl_print_event_log(priv, 0, next_entry,
  1493. mode, pos, buf, bufsz);
  1494. } else {
  1495. pos = iwl_print_event_log(priv, next_entry - size,
  1496. size, mode, pos, buf, bufsz);
  1497. }
  1498. }
  1499. return pos;
  1500. }
  1501. #define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
  1502. int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
  1503. char **buf, bool display)
  1504. {
  1505. u32 base; /* SRAM byte address of event log header */
  1506. u32 capacity; /* event log capacity in # entries */
  1507. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  1508. u32 num_wraps; /* # times uCode wrapped to top of log */
  1509. u32 next_entry; /* index of next entry to be written by uCode */
  1510. u32 size; /* # entries that we'll print */
  1511. u32 logsize;
  1512. int pos = 0;
  1513. size_t bufsz = 0;
  1514. struct iwl_trans *trans = priv->trans;
  1515. base = priv->device_pointers.log_event_table;
  1516. if (priv->cur_ucode == IWL_UCODE_INIT) {
  1517. logsize = priv->fw->init_evtlog_size;
  1518. if (!base)
  1519. base = priv->fw->init_evtlog_ptr;
  1520. } else {
  1521. logsize = priv->fw->inst_evtlog_size;
  1522. if (!base)
  1523. base = priv->fw->inst_evtlog_ptr;
  1524. }
  1525. if (!iwlagn_hw_valid_rtc_data_addr(base)) {
  1526. IWL_ERR(priv,
  1527. "Invalid event log pointer 0x%08X for %s uCode\n",
  1528. base,
  1529. (priv->cur_ucode == IWL_UCODE_INIT)
  1530. ? "Init" : "RT");
  1531. return -EINVAL;
  1532. }
  1533. /* event log header */
  1534. capacity = iwl_read_targ_mem(trans, base);
  1535. mode = iwl_read_targ_mem(trans, base + (1 * sizeof(u32)));
  1536. num_wraps = iwl_read_targ_mem(trans, base + (2 * sizeof(u32)));
  1537. next_entry = iwl_read_targ_mem(trans, base + (3 * sizeof(u32)));
  1538. if (capacity > logsize) {
  1539. IWL_ERR(priv, "Log capacity %d is bogus, limit to %d "
  1540. "entries\n", capacity, logsize);
  1541. capacity = logsize;
  1542. }
  1543. if (next_entry > logsize) {
  1544. IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
  1545. next_entry, logsize);
  1546. next_entry = logsize;
  1547. }
  1548. size = num_wraps ? capacity : next_entry;
  1549. /* bail out if nothing in log */
  1550. if (size == 0) {
  1551. IWL_ERR(trans, "Start IWL Event Log Dump: nothing in log\n");
  1552. return pos;
  1553. }
  1554. #ifdef CONFIG_IWLWIFI_DEBUG
  1555. if (!(iwl_have_debug_level(IWL_DL_FW_ERRORS)) && !full_log)
  1556. size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
  1557. ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
  1558. #else
  1559. size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
  1560. ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
  1561. #endif
  1562. IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n",
  1563. size);
  1564. #ifdef CONFIG_IWLWIFI_DEBUG
  1565. if (display) {
  1566. if (full_log)
  1567. bufsz = capacity * 48;
  1568. else
  1569. bufsz = size * 48;
  1570. *buf = kmalloc(bufsz, GFP_KERNEL);
  1571. if (!*buf)
  1572. return -ENOMEM;
  1573. }
  1574. if (iwl_have_debug_level(IWL_DL_FW_ERRORS) || full_log) {
  1575. /*
  1576. * if uCode has wrapped back to top of log,
  1577. * start at the oldest entry,
  1578. * i.e the next one that uCode would fill.
  1579. */
  1580. if (num_wraps)
  1581. pos = iwl_print_event_log(priv, next_entry,
  1582. capacity - next_entry, mode,
  1583. pos, buf, bufsz);
  1584. /* (then/else) start at top of log */
  1585. pos = iwl_print_event_log(priv, 0,
  1586. next_entry, mode, pos, buf, bufsz);
  1587. } else
  1588. pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
  1589. next_entry, size, mode,
  1590. pos, buf, bufsz);
  1591. #else
  1592. pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
  1593. next_entry, size, mode,
  1594. pos, buf, bufsz);
  1595. #endif
  1596. return pos;
  1597. }
  1598. static void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand)
  1599. {
  1600. unsigned int reload_msec;
  1601. unsigned long reload_jiffies;
  1602. #ifdef CONFIG_IWLWIFI_DEBUG
  1603. if (iwl_have_debug_level(IWL_DL_FW_ERRORS))
  1604. iwl_print_rx_config_cmd(priv, IWL_RXON_CTX_BSS);
  1605. #endif
  1606. /* uCode is no longer loaded. */
  1607. priv->ucode_loaded = false;
  1608. /* Set the FW error flag -- cleared on iwl_down */
  1609. set_bit(STATUS_FW_ERROR, &priv->status);
  1610. iwl_abort_notification_waits(&priv->notif_wait);
  1611. /* Keep the restart process from trying to send host
  1612. * commands by clearing the ready bit */
  1613. clear_bit(STATUS_READY, &priv->status);
  1614. if (!ondemand) {
  1615. /*
  1616. * If firmware keep reloading, then it indicate something
  1617. * serious wrong and firmware having problem to recover
  1618. * from it. Instead of keep trying which will fill the syslog
  1619. * and hang the system, let's just stop it
  1620. */
  1621. reload_jiffies = jiffies;
  1622. reload_msec = jiffies_to_msecs((long) reload_jiffies -
  1623. (long) priv->reload_jiffies);
  1624. priv->reload_jiffies = reload_jiffies;
  1625. if (reload_msec <= IWL_MIN_RELOAD_DURATION) {
  1626. priv->reload_count++;
  1627. if (priv->reload_count >= IWL_MAX_CONTINUE_RELOAD_CNT) {
  1628. IWL_ERR(priv, "BUG_ON, Stop restarting\n");
  1629. return;
  1630. }
  1631. } else
  1632. priv->reload_count = 0;
  1633. }
  1634. if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  1635. if (iwlwifi_mod_params.restart_fw) {
  1636. IWL_DEBUG_FW_ERRORS(priv,
  1637. "Restarting adapter due to uCode error.\n");
  1638. queue_work(priv->workqueue, &priv->restart);
  1639. } else
  1640. IWL_DEBUG_FW_ERRORS(priv,
  1641. "Detected FW error, but not restarting\n");
  1642. }
  1643. }
  1644. static void iwl_nic_error(struct iwl_op_mode *op_mode)
  1645. {
  1646. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1647. IWL_ERR(priv, "Loaded firmware version: %s\n",
  1648. priv->fw->fw_version);
  1649. iwl_dump_nic_error_log(priv);
  1650. iwl_dump_nic_event_log(priv, false, NULL, false);
  1651. iwlagn_fw_error(priv, false);
  1652. }
  1653. static void iwl_cmd_queue_full(struct iwl_op_mode *op_mode)
  1654. {
  1655. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1656. if (!iwl_check_for_ct_kill(priv)) {
  1657. IWL_ERR(priv, "Restarting adapter queue is full\n");
  1658. iwlagn_fw_error(priv, false);
  1659. }
  1660. }
  1661. #define EEPROM_RF_CONFIG_TYPE_MAX 0x3
  1662. static void iwl_nic_config(struct iwl_op_mode *op_mode)
  1663. {
  1664. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1665. /* SKU Control */
  1666. iwl_set_bits_mask(priv->trans, CSR_HW_IF_CONFIG_REG,
  1667. CSR_HW_IF_CONFIG_REG_MSK_MAC_DASH |
  1668. CSR_HW_IF_CONFIG_REG_MSK_MAC_STEP,
  1669. (CSR_HW_REV_STEP(priv->trans->hw_rev) <<
  1670. CSR_HW_IF_CONFIG_REG_POS_MAC_STEP) |
  1671. (CSR_HW_REV_DASH(priv->trans->hw_rev) <<
  1672. CSR_HW_IF_CONFIG_REG_POS_MAC_DASH));
  1673. /* write radio config values to register */
  1674. if (priv->nvm_data->radio_cfg_type <= EEPROM_RF_CONFIG_TYPE_MAX) {
  1675. u32 reg_val =
  1676. priv->nvm_data->radio_cfg_type <<
  1677. CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE |
  1678. priv->nvm_data->radio_cfg_step <<
  1679. CSR_HW_IF_CONFIG_REG_POS_PHY_STEP |
  1680. priv->nvm_data->radio_cfg_dash <<
  1681. CSR_HW_IF_CONFIG_REG_POS_PHY_DASH;
  1682. iwl_set_bits_mask(priv->trans, CSR_HW_IF_CONFIG_REG,
  1683. CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE |
  1684. CSR_HW_IF_CONFIG_REG_MSK_PHY_STEP |
  1685. CSR_HW_IF_CONFIG_REG_MSK_PHY_DASH, reg_val);
  1686. IWL_INFO(priv, "Radio type=0x%x-0x%x-0x%x\n",
  1687. priv->nvm_data->radio_cfg_type,
  1688. priv->nvm_data->radio_cfg_step,
  1689. priv->nvm_data->radio_cfg_dash);
  1690. } else {
  1691. WARN_ON(1);
  1692. }
  1693. /* set CSR_HW_CONFIG_REG for uCode use */
  1694. iwl_set_bit(priv->trans, CSR_HW_IF_CONFIG_REG,
  1695. CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
  1696. CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
  1697. /* W/A : NIC is stuck in a reset state after Early PCIe power off
  1698. * (PCIe power is lost before PERST# is asserted),
  1699. * causing ME FW to lose ownership and not being able to obtain it back.
  1700. */
  1701. iwl_set_bits_mask_prph(priv->trans, APMG_PS_CTRL_REG,
  1702. APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
  1703. ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
  1704. if (priv->lib->nic_config)
  1705. priv->lib->nic_config(priv);
  1706. }
  1707. static void iwl_wimax_active(struct iwl_op_mode *op_mode)
  1708. {
  1709. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1710. clear_bit(STATUS_READY, &priv->status);
  1711. IWL_ERR(priv, "RF is used by WiMAX\n");
  1712. }
  1713. static void iwl_stop_sw_queue(struct iwl_op_mode *op_mode, int queue)
  1714. {
  1715. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1716. int mq = priv->queue_to_mac80211[queue];
  1717. if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE))
  1718. return;
  1719. if (atomic_inc_return(&priv->queue_stop_count[mq]) > 1) {
  1720. IWL_DEBUG_TX_QUEUES(priv,
  1721. "queue %d (mac80211 %d) already stopped\n",
  1722. queue, mq);
  1723. return;
  1724. }
  1725. set_bit(mq, &priv->transport_queue_stop);
  1726. ieee80211_stop_queue(priv->hw, mq);
  1727. }
  1728. static void iwl_wake_sw_queue(struct iwl_op_mode *op_mode, int queue)
  1729. {
  1730. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1731. int mq = priv->queue_to_mac80211[queue];
  1732. if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE))
  1733. return;
  1734. if (atomic_dec_return(&priv->queue_stop_count[mq]) > 0) {
  1735. IWL_DEBUG_TX_QUEUES(priv,
  1736. "queue %d (mac80211 %d) already awake\n",
  1737. queue, mq);
  1738. return;
  1739. }
  1740. clear_bit(mq, &priv->transport_queue_stop);
  1741. if (!priv->passive_no_rx)
  1742. ieee80211_wake_queue(priv->hw, mq);
  1743. }
  1744. void iwlagn_lift_passive_no_rx(struct iwl_priv *priv)
  1745. {
  1746. int mq;
  1747. if (!priv->passive_no_rx)
  1748. return;
  1749. for (mq = 0; mq < IWLAGN_FIRST_AMPDU_QUEUE; mq++) {
  1750. if (!test_bit(mq, &priv->transport_queue_stop)) {
  1751. IWL_DEBUG_TX_QUEUES(priv, "Wake queue %d", mq);
  1752. ieee80211_wake_queue(priv->hw, mq);
  1753. } else {
  1754. IWL_DEBUG_TX_QUEUES(priv, "Don't wake queue %d", mq);
  1755. }
  1756. }
  1757. priv->passive_no_rx = false;
  1758. }
  1759. static void iwl_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)
  1760. {
  1761. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1762. struct ieee80211_tx_info *info;
  1763. info = IEEE80211_SKB_CB(skb);
  1764. iwl_trans_free_tx_cmd(priv->trans, info->driver_data[1]);
  1765. ieee80211_free_txskb(priv->hw, skb);
  1766. }
  1767. static void iwl_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
  1768. {
  1769. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1770. if (state)
  1771. set_bit(STATUS_RF_KILL_HW, &priv->status);
  1772. else
  1773. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  1774. wiphy_rfkill_set_hw_state(priv->hw->wiphy, state);
  1775. }
  1776. static const struct iwl_op_mode_ops iwl_dvm_ops = {
  1777. .start = iwl_op_mode_dvm_start,
  1778. .stop = iwl_op_mode_dvm_stop,
  1779. .rx = iwl_rx_dispatch,
  1780. .queue_full = iwl_stop_sw_queue,
  1781. .queue_not_full = iwl_wake_sw_queue,
  1782. .hw_rf_kill = iwl_set_hw_rfkill_state,
  1783. .free_skb = iwl_free_skb,
  1784. .nic_error = iwl_nic_error,
  1785. .cmd_queue_full = iwl_cmd_queue_full,
  1786. .nic_config = iwl_nic_config,
  1787. .wimax_active = iwl_wimax_active,
  1788. };
  1789. /*****************************************************************************
  1790. *
  1791. * driver and module entry point
  1792. *
  1793. *****************************************************************************/
  1794. static int __init iwl_init(void)
  1795. {
  1796. int ret;
  1797. ret = iwlagn_rate_control_register();
  1798. if (ret) {
  1799. pr_err("Unable to register rate control algorithm: %d\n", ret);
  1800. return ret;
  1801. }
  1802. ret = iwl_opmode_register("iwldvm", &iwl_dvm_ops);
  1803. if (ret) {
  1804. pr_err("Unable to register op_mode: %d\n", ret);
  1805. iwlagn_rate_control_unregister();
  1806. }
  1807. return ret;
  1808. }
  1809. module_init(iwl_init);
  1810. static void __exit iwl_exit(void)
  1811. {
  1812. iwl_opmode_deregister("iwldvm");
  1813. iwlagn_rate_control_unregister();
  1814. }
  1815. module_exit(iwl_exit);