iwl-core.c 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2010 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  19. * USA
  20. *
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  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. #include <linux/kernel.h>
  29. #include <linux/module.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/sched.h>
  32. #include <linux/slab.h>
  33. #include <net/mac80211.h>
  34. #include "iwl-eeprom.h"
  35. #include "iwl-dev.h" /* FIXME: remove */
  36. #include "iwl-debug.h"
  37. #include "iwl-core.h"
  38. #include "iwl-io.h"
  39. #include "iwl-power.h"
  40. #include "iwl-sta.h"
  41. #include "iwl-helpers.h"
  42. MODULE_DESCRIPTION("iwl core");
  43. MODULE_VERSION(IWLWIFI_VERSION);
  44. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  45. MODULE_LICENSE("GPL");
  46. /*
  47. * set bt_coex_active to true, uCode will do kill/defer
  48. * every time the priority line is asserted (BT is sending signals on the
  49. * priority line in the PCIx).
  50. * set bt_coex_active to false, uCode will ignore the BT activity and
  51. * perform the normal operation
  52. *
  53. * User might experience transmit issue on some platform due to WiFi/BT
  54. * co-exist problem. The possible behaviors are:
  55. * Able to scan and finding all the available AP
  56. * Not able to associate with any AP
  57. * On those platforms, WiFi communication can be restored by set
  58. * "bt_coex_active" module parameter to "false"
  59. *
  60. * default: bt_coex_active = true (BT_COEX_ENABLE)
  61. */
  62. bool bt_coex_active = true;
  63. EXPORT_SYMBOL_GPL(bt_coex_active);
  64. module_param(bt_coex_active, bool, S_IRUGO);
  65. MODULE_PARM_DESC(bt_coex_active, "enable wifi/bluetooth co-exist");
  66. u32 iwl_debug_level;
  67. EXPORT_SYMBOL(iwl_debug_level);
  68. const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  69. EXPORT_SYMBOL(iwl_bcast_addr);
  70. /* This function both allocates and initializes hw and priv. */
  71. struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg)
  72. {
  73. struct iwl_priv *priv;
  74. /* mac80211 allocates memory for this device instance, including
  75. * space for this driver's private structure */
  76. struct ieee80211_hw *hw;
  77. hw = ieee80211_alloc_hw(sizeof(struct iwl_priv),
  78. cfg->ops->ieee80211_ops);
  79. if (hw == NULL) {
  80. pr_err("%s: Can not allocate network device\n",
  81. cfg->name);
  82. goto out;
  83. }
  84. priv = hw->priv;
  85. priv->hw = hw;
  86. out:
  87. return hw;
  88. }
  89. EXPORT_SYMBOL(iwl_alloc_all);
  90. #define MAX_BIT_RATE_40_MHZ 150 /* Mbps */
  91. #define MAX_BIT_RATE_20_MHZ 72 /* Mbps */
  92. static void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv,
  93. struct ieee80211_sta_ht_cap *ht_info,
  94. enum ieee80211_band band)
  95. {
  96. u16 max_bit_rate = 0;
  97. u8 rx_chains_num = priv->hw_params.rx_chains_num;
  98. u8 tx_chains_num = priv->hw_params.tx_chains_num;
  99. ht_info->cap = 0;
  100. memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
  101. ht_info->ht_supported = true;
  102. if (priv->cfg->ht_params &&
  103. priv->cfg->ht_params->ht_greenfield_support)
  104. ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
  105. ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
  106. max_bit_rate = MAX_BIT_RATE_20_MHZ;
  107. if (priv->hw_params.ht40_channel & BIT(band)) {
  108. ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  109. ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
  110. ht_info->mcs.rx_mask[4] = 0x01;
  111. max_bit_rate = MAX_BIT_RATE_40_MHZ;
  112. }
  113. if (priv->cfg->mod_params->amsdu_size_8K)
  114. ht_info->cap |= IEEE80211_HT_CAP_MAX_AMSDU;
  115. ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
  116. if (priv->cfg->bt_params && priv->cfg->bt_params->ampdu_factor)
  117. ht_info->ampdu_factor = priv->cfg->bt_params->ampdu_factor;
  118. ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
  119. if (priv->cfg->bt_params && priv->cfg->bt_params->ampdu_density)
  120. ht_info->ampdu_density = priv->cfg->bt_params->ampdu_density;
  121. ht_info->mcs.rx_mask[0] = 0xFF;
  122. if (rx_chains_num >= 2)
  123. ht_info->mcs.rx_mask[1] = 0xFF;
  124. if (rx_chains_num >= 3)
  125. ht_info->mcs.rx_mask[2] = 0xFF;
  126. /* Highest supported Rx data rate */
  127. max_bit_rate *= rx_chains_num;
  128. WARN_ON(max_bit_rate & ~IEEE80211_HT_MCS_RX_HIGHEST_MASK);
  129. ht_info->mcs.rx_highest = cpu_to_le16(max_bit_rate);
  130. /* Tx MCS capabilities */
  131. ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  132. if (tx_chains_num != rx_chains_num) {
  133. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
  134. ht_info->mcs.tx_params |= ((tx_chains_num - 1) <<
  135. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
  136. }
  137. }
  138. /**
  139. * iwlcore_init_geos - Initialize mac80211's geo/channel info based from eeprom
  140. */
  141. int iwlcore_init_geos(struct iwl_priv *priv)
  142. {
  143. struct iwl_channel_info *ch;
  144. struct ieee80211_supported_band *sband;
  145. struct ieee80211_channel *channels;
  146. struct ieee80211_channel *geo_ch;
  147. struct ieee80211_rate *rates;
  148. int i = 0;
  149. if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
  150. priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
  151. IWL_DEBUG_INFO(priv, "Geography modes already initialized.\n");
  152. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  153. return 0;
  154. }
  155. channels = kzalloc(sizeof(struct ieee80211_channel) *
  156. priv->channel_count, GFP_KERNEL);
  157. if (!channels)
  158. return -ENOMEM;
  159. rates = kzalloc((sizeof(struct ieee80211_rate) * IWL_RATE_COUNT_LEGACY),
  160. GFP_KERNEL);
  161. if (!rates) {
  162. kfree(channels);
  163. return -ENOMEM;
  164. }
  165. /* 5.2GHz channels start after the 2.4GHz channels */
  166. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  167. sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
  168. /* just OFDM */
  169. sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
  170. sband->n_bitrates = IWL_RATE_COUNT_LEGACY - IWL_FIRST_OFDM_RATE;
  171. if (priv->cfg->sku & IWL_SKU_N)
  172. iwlcore_init_ht_hw_capab(priv, &sband->ht_cap,
  173. IEEE80211_BAND_5GHZ);
  174. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  175. sband->channels = channels;
  176. /* OFDM & CCK */
  177. sband->bitrates = rates;
  178. sband->n_bitrates = IWL_RATE_COUNT_LEGACY;
  179. if (priv->cfg->sku & IWL_SKU_N)
  180. iwlcore_init_ht_hw_capab(priv, &sband->ht_cap,
  181. IEEE80211_BAND_2GHZ);
  182. priv->ieee_channels = channels;
  183. priv->ieee_rates = rates;
  184. for (i = 0; i < priv->channel_count; i++) {
  185. ch = &priv->channel_info[i];
  186. /* FIXME: might be removed if scan is OK */
  187. if (!is_channel_valid(ch))
  188. continue;
  189. sband = &priv->bands[ch->band];
  190. geo_ch = &sband->channels[sband->n_channels++];
  191. geo_ch->center_freq =
  192. ieee80211_channel_to_frequency(ch->channel, ch->band);
  193. geo_ch->max_power = ch->max_power_avg;
  194. geo_ch->max_antenna_gain = 0xff;
  195. geo_ch->hw_value = ch->channel;
  196. if (is_channel_valid(ch)) {
  197. if (!(ch->flags & EEPROM_CHANNEL_IBSS))
  198. geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
  199. if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
  200. geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
  201. if (ch->flags & EEPROM_CHANNEL_RADAR)
  202. geo_ch->flags |= IEEE80211_CHAN_RADAR;
  203. geo_ch->flags |= ch->ht40_extension_channel;
  204. if (ch->max_power_avg > priv->tx_power_device_lmt)
  205. priv->tx_power_device_lmt = ch->max_power_avg;
  206. } else {
  207. geo_ch->flags |= IEEE80211_CHAN_DISABLED;
  208. }
  209. IWL_DEBUG_INFO(priv, "Channel %d Freq=%d[%sGHz] %s flag=0x%X\n",
  210. ch->channel, geo_ch->center_freq,
  211. is_channel_a_band(ch) ? "5.2" : "2.4",
  212. geo_ch->flags & IEEE80211_CHAN_DISABLED ?
  213. "restricted" : "valid",
  214. geo_ch->flags);
  215. }
  216. if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
  217. priv->cfg->sku & IWL_SKU_A) {
  218. IWL_INFO(priv, "Incorrectly detected BG card as ABG. "
  219. "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n",
  220. priv->pci_dev->device,
  221. priv->pci_dev->subsystem_device);
  222. priv->cfg->sku &= ~IWL_SKU_A;
  223. }
  224. IWL_INFO(priv, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
  225. priv->bands[IEEE80211_BAND_2GHZ].n_channels,
  226. priv->bands[IEEE80211_BAND_5GHZ].n_channels);
  227. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  228. return 0;
  229. }
  230. EXPORT_SYMBOL(iwlcore_init_geos);
  231. /*
  232. * iwlcore_free_geos - undo allocations in iwlcore_init_geos
  233. */
  234. void iwlcore_free_geos(struct iwl_priv *priv)
  235. {
  236. kfree(priv->ieee_channels);
  237. kfree(priv->ieee_rates);
  238. clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
  239. }
  240. EXPORT_SYMBOL(iwlcore_free_geos);
  241. static bool iwl_is_channel_extension(struct iwl_priv *priv,
  242. enum ieee80211_band band,
  243. u16 channel, u8 extension_chan_offset)
  244. {
  245. const struct iwl_channel_info *ch_info;
  246. ch_info = iwl_get_channel_info(priv, band, channel);
  247. if (!is_channel_valid(ch_info))
  248. return false;
  249. if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
  250. return !(ch_info->ht40_extension_channel &
  251. IEEE80211_CHAN_NO_HT40PLUS);
  252. else if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW)
  253. return !(ch_info->ht40_extension_channel &
  254. IEEE80211_CHAN_NO_HT40MINUS);
  255. return false;
  256. }
  257. bool iwl_is_ht40_tx_allowed(struct iwl_priv *priv,
  258. struct iwl_rxon_context *ctx,
  259. struct ieee80211_sta_ht_cap *ht_cap)
  260. {
  261. if (!ctx->ht.enabled || !ctx->ht.is_40mhz)
  262. return false;
  263. /*
  264. * We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40
  265. * the bit will not set if it is pure 40MHz case
  266. */
  267. if (ht_cap && !ht_cap->ht_supported)
  268. return false;
  269. #ifdef CONFIG_IWLWIFI_DEBUGFS
  270. if (priv->disable_ht40)
  271. return false;
  272. #endif
  273. return iwl_is_channel_extension(priv, priv->band,
  274. le16_to_cpu(ctx->staging.channel),
  275. ctx->ht.extension_chan_offset);
  276. }
  277. EXPORT_SYMBOL(iwl_is_ht40_tx_allowed);
  278. static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
  279. {
  280. u16 new_val;
  281. u16 beacon_factor;
  282. /*
  283. * If mac80211 hasn't given us a beacon interval, program
  284. * the default into the device (not checking this here
  285. * would cause the adjustment below to return the maximum
  286. * value, which may break PAN.)
  287. */
  288. if (!beacon_val)
  289. return DEFAULT_BEACON_INTERVAL;
  290. /*
  291. * If the beacon interval we obtained from the peer
  292. * is too large, we'll have to wake up more often
  293. * (and in IBSS case, we'll beacon too much)
  294. *
  295. * For example, if max_beacon_val is 4096, and the
  296. * requested beacon interval is 7000, we'll have to
  297. * use 3500 to be able to wake up on the beacons.
  298. *
  299. * This could badly influence beacon detection stats.
  300. */
  301. beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
  302. new_val = beacon_val / beacon_factor;
  303. if (!new_val)
  304. new_val = max_beacon_val;
  305. return new_val;
  306. }
  307. int iwl_send_rxon_timing(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  308. {
  309. u64 tsf;
  310. s32 interval_tm, rem;
  311. struct ieee80211_conf *conf = NULL;
  312. u16 beacon_int;
  313. struct ieee80211_vif *vif = ctx->vif;
  314. conf = ieee80211_get_hw_conf(priv->hw);
  315. lockdep_assert_held(&priv->mutex);
  316. memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd));
  317. ctx->timing.timestamp = cpu_to_le64(priv->timestamp);
  318. ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval);
  319. beacon_int = vif ? vif->bss_conf.beacon_int : 0;
  320. /*
  321. * TODO: For IBSS we need to get atim_window from mac80211,
  322. * for now just always use 0
  323. */
  324. ctx->timing.atim_window = 0;
  325. if (ctx->ctxid == IWL_RXON_CTX_PAN &&
  326. (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION) &&
  327. iwl_is_associated(priv, IWL_RXON_CTX_BSS) &&
  328. priv->contexts[IWL_RXON_CTX_BSS].vif &&
  329. priv->contexts[IWL_RXON_CTX_BSS].vif->bss_conf.beacon_int) {
  330. ctx->timing.beacon_interval =
  331. priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval;
  332. beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
  333. } else if (ctx->ctxid == IWL_RXON_CTX_BSS &&
  334. iwl_is_associated(priv, IWL_RXON_CTX_PAN) &&
  335. priv->contexts[IWL_RXON_CTX_PAN].vif &&
  336. priv->contexts[IWL_RXON_CTX_PAN].vif->bss_conf.beacon_int &&
  337. (!iwl_is_associated_ctx(ctx) || !ctx->vif ||
  338. !ctx->vif->bss_conf.beacon_int)) {
  339. ctx->timing.beacon_interval =
  340. priv->contexts[IWL_RXON_CTX_PAN].timing.beacon_interval;
  341. beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
  342. } else {
  343. beacon_int = iwl_adjust_beacon_interval(beacon_int,
  344. priv->hw_params.max_beacon_itrvl * TIME_UNIT);
  345. ctx->timing.beacon_interval = cpu_to_le16(beacon_int);
  346. }
  347. tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
  348. interval_tm = beacon_int * TIME_UNIT;
  349. rem = do_div(tsf, interval_tm);
  350. ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
  351. ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1;
  352. IWL_DEBUG_ASSOC(priv,
  353. "beacon interval %d beacon timer %d beacon tim %d\n",
  354. le16_to_cpu(ctx->timing.beacon_interval),
  355. le32_to_cpu(ctx->timing.beacon_init_val),
  356. le16_to_cpu(ctx->timing.atim_window));
  357. return iwl_send_cmd_pdu(priv, ctx->rxon_timing_cmd,
  358. sizeof(ctx->timing), &ctx->timing);
  359. }
  360. EXPORT_SYMBOL(iwl_send_rxon_timing);
  361. void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
  362. int hw_decrypt)
  363. {
  364. struct iwl_rxon_cmd *rxon = &ctx->staging;
  365. if (hw_decrypt)
  366. rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
  367. else
  368. rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
  369. }
  370. EXPORT_SYMBOL(iwl_set_rxon_hwcrypto);
  371. /* validate RXON structure is valid */
  372. int iwl_check_rxon_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  373. {
  374. struct iwl_rxon_cmd *rxon = &ctx->staging;
  375. bool error = false;
  376. if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
  377. if (rxon->flags & RXON_FLG_TGJ_NARROW_BAND_MSK) {
  378. IWL_WARN(priv, "check 2.4G: wrong narrow\n");
  379. error = true;
  380. }
  381. if (rxon->flags & RXON_FLG_RADAR_DETECT_MSK) {
  382. IWL_WARN(priv, "check 2.4G: wrong radar\n");
  383. error = true;
  384. }
  385. } else {
  386. if (!(rxon->flags & RXON_FLG_SHORT_SLOT_MSK)) {
  387. IWL_WARN(priv, "check 5.2G: not short slot!\n");
  388. error = true;
  389. }
  390. if (rxon->flags & RXON_FLG_CCK_MSK) {
  391. IWL_WARN(priv, "check 5.2G: CCK!\n");
  392. error = true;
  393. }
  394. }
  395. if ((rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1) {
  396. IWL_WARN(priv, "mac/bssid mcast!\n");
  397. error = true;
  398. }
  399. /* make sure basic rates 6Mbps and 1Mbps are supported */
  400. if ((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0 &&
  401. (rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0) {
  402. IWL_WARN(priv, "neither 1 nor 6 are basic\n");
  403. error = true;
  404. }
  405. if (le16_to_cpu(rxon->assoc_id) > 2007) {
  406. IWL_WARN(priv, "aid > 2007\n");
  407. error = true;
  408. }
  409. if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
  410. == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) {
  411. IWL_WARN(priv, "CCK and short slot\n");
  412. error = true;
  413. }
  414. if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
  415. == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) {
  416. IWL_WARN(priv, "CCK and auto detect");
  417. error = true;
  418. }
  419. if ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
  420. RXON_FLG_TGG_PROTECT_MSK)) ==
  421. RXON_FLG_TGG_PROTECT_MSK) {
  422. IWL_WARN(priv, "TGg but no auto-detect\n");
  423. error = true;
  424. }
  425. if (error)
  426. IWL_WARN(priv, "Tuning to channel %d\n",
  427. le16_to_cpu(rxon->channel));
  428. if (error) {
  429. IWL_ERR(priv, "Invalid RXON\n");
  430. return -EINVAL;
  431. }
  432. return 0;
  433. }
  434. EXPORT_SYMBOL(iwl_check_rxon_cmd);
  435. /**
  436. * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
  437. * @priv: staging_rxon is compared to active_rxon
  438. *
  439. * If the RXON structure is changing enough to require a new tune,
  440. * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
  441. * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
  442. */
  443. int iwl_full_rxon_required(struct iwl_priv *priv,
  444. struct iwl_rxon_context *ctx)
  445. {
  446. const struct iwl_rxon_cmd *staging = &ctx->staging;
  447. const struct iwl_rxon_cmd *active = &ctx->active;
  448. #define CHK(cond) \
  449. if ((cond)) { \
  450. IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
  451. return 1; \
  452. }
  453. #define CHK_NEQ(c1, c2) \
  454. if ((c1) != (c2)) { \
  455. IWL_DEBUG_INFO(priv, "need full RXON - " \
  456. #c1 " != " #c2 " - %d != %d\n", \
  457. (c1), (c2)); \
  458. return 1; \
  459. }
  460. /* These items are only settable from the full RXON command */
  461. CHK(!iwl_is_associated_ctx(ctx));
  462. CHK(compare_ether_addr(staging->bssid_addr, active->bssid_addr));
  463. CHK(compare_ether_addr(staging->node_addr, active->node_addr));
  464. CHK(compare_ether_addr(staging->wlap_bssid_addr,
  465. active->wlap_bssid_addr));
  466. CHK_NEQ(staging->dev_type, active->dev_type);
  467. CHK_NEQ(staging->channel, active->channel);
  468. CHK_NEQ(staging->air_propagation, active->air_propagation);
  469. CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates,
  470. active->ofdm_ht_single_stream_basic_rates);
  471. CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates,
  472. active->ofdm_ht_dual_stream_basic_rates);
  473. CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates,
  474. active->ofdm_ht_triple_stream_basic_rates);
  475. CHK_NEQ(staging->assoc_id, active->assoc_id);
  476. /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
  477. * be updated with the RXON_ASSOC command -- however only some
  478. * flag transitions are allowed using RXON_ASSOC */
  479. /* Check if we are not switching bands */
  480. CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK,
  481. active->flags & RXON_FLG_BAND_24G_MSK);
  482. /* Check if we are switching association toggle */
  483. CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK,
  484. active->filter_flags & RXON_FILTER_ASSOC_MSK);
  485. #undef CHK
  486. #undef CHK_NEQ
  487. return 0;
  488. }
  489. EXPORT_SYMBOL(iwl_full_rxon_required);
  490. u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv,
  491. struct iwl_rxon_context *ctx)
  492. {
  493. /*
  494. * Assign the lowest rate -- should really get this from
  495. * the beacon skb from mac80211.
  496. */
  497. if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK)
  498. return IWL_RATE_1M_PLCP;
  499. else
  500. return IWL_RATE_6M_PLCP;
  501. }
  502. EXPORT_SYMBOL(iwl_rate_get_lowest_plcp);
  503. static void _iwl_set_rxon_ht(struct iwl_priv *priv,
  504. struct iwl_ht_config *ht_conf,
  505. struct iwl_rxon_context *ctx)
  506. {
  507. struct iwl_rxon_cmd *rxon = &ctx->staging;
  508. if (!ctx->ht.enabled) {
  509. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
  510. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
  511. RXON_FLG_HT40_PROT_MSK |
  512. RXON_FLG_HT_PROT_MSK);
  513. return;
  514. }
  515. /* FIXME: if the definition of ht.protection changed, the "translation"
  516. * will be needed for rxon->flags
  517. */
  518. rxon->flags |= cpu_to_le32(ctx->ht.protection << RXON_FLG_HT_OPERATING_MODE_POS);
  519. /* Set up channel bandwidth:
  520. * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
  521. /* clear the HT channel mode before set the mode */
  522. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
  523. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  524. if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) {
  525. /* pure ht40 */
  526. if (ctx->ht.protection == IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
  527. rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
  528. /* Note: control channel is opposite of extension channel */
  529. switch (ctx->ht.extension_chan_offset) {
  530. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  531. rxon->flags &= ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  532. break;
  533. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  534. rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  535. break;
  536. }
  537. } else {
  538. /* Note: control channel is opposite of extension channel */
  539. switch (ctx->ht.extension_chan_offset) {
  540. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  541. rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  542. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
  543. break;
  544. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  545. rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  546. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
  547. break;
  548. case IEEE80211_HT_PARAM_CHA_SEC_NONE:
  549. default:
  550. /* channel location only valid if in Mixed mode */
  551. IWL_ERR(priv, "invalid extension channel offset\n");
  552. break;
  553. }
  554. }
  555. } else {
  556. rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
  557. }
  558. if (priv->cfg->ops->hcmd->set_rxon_chain)
  559. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  560. IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
  561. "extension channel offset 0x%x\n",
  562. le32_to_cpu(rxon->flags), ctx->ht.protection,
  563. ctx->ht.extension_chan_offset);
  564. }
  565. void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
  566. {
  567. struct iwl_rxon_context *ctx;
  568. for_each_context(priv, ctx)
  569. _iwl_set_rxon_ht(priv, ht_conf, ctx);
  570. }
  571. EXPORT_SYMBOL(iwl_set_rxon_ht);
  572. /* Return valid, unused, channel for a passive scan to reset the RF */
  573. u8 iwl_get_single_channel_number(struct iwl_priv *priv,
  574. enum ieee80211_band band)
  575. {
  576. const struct iwl_channel_info *ch_info;
  577. int i;
  578. u8 channel = 0;
  579. u8 min, max;
  580. struct iwl_rxon_context *ctx;
  581. if (band == IEEE80211_BAND_5GHZ) {
  582. min = 14;
  583. max = priv->channel_count;
  584. } else {
  585. min = 0;
  586. max = 14;
  587. }
  588. for (i = min; i < max; i++) {
  589. bool busy = false;
  590. for_each_context(priv, ctx) {
  591. busy = priv->channel_info[i].channel ==
  592. le16_to_cpu(ctx->staging.channel);
  593. if (busy)
  594. break;
  595. }
  596. if (busy)
  597. continue;
  598. channel = priv->channel_info[i].channel;
  599. ch_info = iwl_get_channel_info(priv, band, channel);
  600. if (is_channel_valid(ch_info))
  601. break;
  602. }
  603. return channel;
  604. }
  605. EXPORT_SYMBOL(iwl_get_single_channel_number);
  606. /**
  607. * iwl_set_rxon_channel - Set the band and channel values in staging RXON
  608. * @ch: requested channel as a pointer to struct ieee80211_channel
  609. * NOTE: Does not commit to the hardware; it sets appropriate bit fields
  610. * in the staging RXON flag structure based on the ch->band
  611. */
  612. int iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
  613. struct iwl_rxon_context *ctx)
  614. {
  615. enum ieee80211_band band = ch->band;
  616. u16 channel = ch->hw_value;
  617. if ((le16_to_cpu(ctx->staging.channel) == channel) &&
  618. (priv->band == band))
  619. return 0;
  620. ctx->staging.channel = cpu_to_le16(channel);
  621. if (band == IEEE80211_BAND_5GHZ)
  622. ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK;
  623. else
  624. ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
  625. priv->band = band;
  626. IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
  627. return 0;
  628. }
  629. EXPORT_SYMBOL(iwl_set_rxon_channel);
  630. void iwl_set_flags_for_band(struct iwl_priv *priv,
  631. struct iwl_rxon_context *ctx,
  632. enum ieee80211_band band,
  633. struct ieee80211_vif *vif)
  634. {
  635. if (band == IEEE80211_BAND_5GHZ) {
  636. ctx->staging.flags &=
  637. ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
  638. | RXON_FLG_CCK_MSK);
  639. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  640. } else {
  641. /* Copied from iwl_post_associate() */
  642. if (vif && vif->bss_conf.use_short_slot)
  643. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  644. else
  645. ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  646. ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
  647. ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK;
  648. ctx->staging.flags &= ~RXON_FLG_CCK_MSK;
  649. }
  650. }
  651. EXPORT_SYMBOL(iwl_set_flags_for_band);
  652. /*
  653. * initialize rxon structure with default values from eeprom
  654. */
  655. void iwl_connection_init_rx_config(struct iwl_priv *priv,
  656. struct iwl_rxon_context *ctx)
  657. {
  658. const struct iwl_channel_info *ch_info;
  659. memset(&ctx->staging, 0, sizeof(ctx->staging));
  660. if (!ctx->vif) {
  661. ctx->staging.dev_type = ctx->unused_devtype;
  662. } else switch (ctx->vif->type) {
  663. case NL80211_IFTYPE_AP:
  664. ctx->staging.dev_type = ctx->ap_devtype;
  665. break;
  666. case NL80211_IFTYPE_STATION:
  667. ctx->staging.dev_type = ctx->station_devtype;
  668. ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
  669. break;
  670. case NL80211_IFTYPE_ADHOC:
  671. ctx->staging.dev_type = ctx->ibss_devtype;
  672. ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
  673. ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
  674. RXON_FILTER_ACCEPT_GRP_MSK;
  675. break;
  676. default:
  677. IWL_ERR(priv, "Unsupported interface type %d\n",
  678. ctx->vif->type);
  679. break;
  680. }
  681. #if 0
  682. /* TODO: Figure out when short_preamble would be set and cache from
  683. * that */
  684. if (!hw_to_local(priv->hw)->short_preamble)
  685. ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  686. else
  687. ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  688. #endif
  689. ch_info = iwl_get_channel_info(priv, priv->band,
  690. le16_to_cpu(ctx->active.channel));
  691. if (!ch_info)
  692. ch_info = &priv->channel_info[0];
  693. ctx->staging.channel = cpu_to_le16(ch_info->channel);
  694. priv->band = ch_info->band;
  695. iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif);
  696. ctx->staging.ofdm_basic_rates =
  697. (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  698. ctx->staging.cck_basic_rates =
  699. (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  700. /* clear both MIX and PURE40 mode flag */
  701. ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
  702. RXON_FLG_CHANNEL_MODE_PURE_40);
  703. if (ctx->vif)
  704. memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN);
  705. ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff;
  706. ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff;
  707. ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff;
  708. }
  709. EXPORT_SYMBOL(iwl_connection_init_rx_config);
  710. void iwl_set_rate(struct iwl_priv *priv)
  711. {
  712. const struct ieee80211_supported_band *hw = NULL;
  713. struct ieee80211_rate *rate;
  714. struct iwl_rxon_context *ctx;
  715. int i;
  716. hw = iwl_get_hw_mode(priv, priv->band);
  717. if (!hw) {
  718. IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
  719. return;
  720. }
  721. priv->active_rate = 0;
  722. for (i = 0; i < hw->n_bitrates; i++) {
  723. rate = &(hw->bitrates[i]);
  724. if (rate->hw_value < IWL_RATE_COUNT_LEGACY)
  725. priv->active_rate |= (1 << rate->hw_value);
  726. }
  727. IWL_DEBUG_RATE(priv, "Set active_rate = %0x\n", priv->active_rate);
  728. for_each_context(priv, ctx) {
  729. ctx->staging.cck_basic_rates =
  730. (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  731. ctx->staging.ofdm_basic_rates =
  732. (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  733. }
  734. }
  735. EXPORT_SYMBOL(iwl_set_rate);
  736. void iwl_chswitch_done(struct iwl_priv *priv, bool is_success)
  737. {
  738. /*
  739. * MULTI-FIXME
  740. * See iwl_mac_channel_switch.
  741. */
  742. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  743. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  744. return;
  745. if (priv->switch_rxon.switch_in_progress) {
  746. ieee80211_chswitch_done(ctx->vif, is_success);
  747. mutex_lock(&priv->mutex);
  748. priv->switch_rxon.switch_in_progress = false;
  749. mutex_unlock(&priv->mutex);
  750. }
  751. }
  752. EXPORT_SYMBOL(iwl_chswitch_done);
  753. void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
  754. {
  755. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  756. struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
  757. /*
  758. * MULTI-FIXME
  759. * See iwl_mac_channel_switch.
  760. */
  761. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  762. struct iwl_rxon_cmd *rxon = (void *)&ctx->active;
  763. if (priv->switch_rxon.switch_in_progress) {
  764. if (!le32_to_cpu(csa->status) &&
  765. (csa->channel == priv->switch_rxon.channel)) {
  766. rxon->channel = csa->channel;
  767. ctx->staging.channel = csa->channel;
  768. IWL_DEBUG_11H(priv, "CSA notif: channel %d\n",
  769. le16_to_cpu(csa->channel));
  770. iwl_chswitch_done(priv, true);
  771. } else {
  772. IWL_ERR(priv, "CSA notif (fail) : channel %d\n",
  773. le16_to_cpu(csa->channel));
  774. iwl_chswitch_done(priv, false);
  775. }
  776. }
  777. }
  778. EXPORT_SYMBOL(iwl_rx_csa);
  779. #ifdef CONFIG_IWLWIFI_DEBUG
  780. void iwl_print_rx_config_cmd(struct iwl_priv *priv,
  781. struct iwl_rxon_context *ctx)
  782. {
  783. struct iwl_rxon_cmd *rxon = &ctx->staging;
  784. IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
  785. iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
  786. IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
  787. IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
  788. IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
  789. le32_to_cpu(rxon->filter_flags));
  790. IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
  791. IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
  792. rxon->ofdm_basic_rates);
  793. IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
  794. IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
  795. IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
  796. IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
  797. }
  798. EXPORT_SYMBOL(iwl_print_rx_config_cmd);
  799. #endif
  800. /**
  801. * iwl_irq_handle_error - called for HW or SW error interrupt from card
  802. */
  803. void iwl_irq_handle_error(struct iwl_priv *priv)
  804. {
  805. unsigned int reload_msec;
  806. unsigned long reload_jiffies;
  807. /* Set the FW error flag -- cleared on iwl_down */
  808. set_bit(STATUS_FW_ERROR, &priv->status);
  809. /* Cancel currently queued command. */
  810. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  811. /* W/A for WiFi/WiMAX coex and WiMAX own the RF */
  812. if (priv->cfg->internal_wimax_coex &&
  813. (!(iwl_read_prph(priv, APMG_CLK_CTRL_REG) &
  814. APMS_CLK_VAL_MRB_FUNC_MODE) ||
  815. (iwl_read_prph(priv, APMG_PS_CTRL_REG) &
  816. APMG_PS_CTRL_VAL_RESET_REQ))) {
  817. wake_up_interruptible(&priv->wait_command_queue);
  818. /*
  819. *Keep the restart process from trying to send host
  820. * commands by clearing the INIT status bit
  821. */
  822. clear_bit(STATUS_READY, &priv->status);
  823. IWL_ERR(priv, "RF is used by WiMAX\n");
  824. return;
  825. }
  826. IWL_ERR(priv, "Loaded firmware version: %s\n",
  827. priv->hw->wiphy->fw_version);
  828. priv->cfg->ops->lib->dump_nic_error_log(priv);
  829. if (priv->cfg->ops->lib->dump_csr)
  830. priv->cfg->ops->lib->dump_csr(priv);
  831. if (priv->cfg->ops->lib->dump_fh)
  832. priv->cfg->ops->lib->dump_fh(priv, NULL, false);
  833. priv->cfg->ops->lib->dump_nic_event_log(priv, false, NULL, false);
  834. #ifdef CONFIG_IWLWIFI_DEBUG
  835. if (iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS)
  836. iwl_print_rx_config_cmd(priv,
  837. &priv->contexts[IWL_RXON_CTX_BSS]);
  838. #endif
  839. wake_up_interruptible(&priv->wait_command_queue);
  840. /* Keep the restart process from trying to send host
  841. * commands by clearing the INIT status bit */
  842. clear_bit(STATUS_READY, &priv->status);
  843. /*
  844. * If firmware keep reloading, then it indicate something
  845. * serious wrong and firmware having problem to recover
  846. * from it. Instead of keep trying which will fill the syslog
  847. * and hang the system, let's just stop it
  848. */
  849. reload_jiffies = jiffies;
  850. reload_msec = jiffies_to_msecs((long) reload_jiffies -
  851. (long) priv->reload_jiffies);
  852. priv->reload_jiffies = reload_jiffies;
  853. if (reload_msec <= IWL_MIN_RELOAD_DURATION) {
  854. priv->reload_count++;
  855. if (priv->reload_count >= IWL_MAX_CONTINUE_RELOAD_CNT) {
  856. IWL_ERR(priv, "BUG_ON, Stop restarting\n");
  857. return;
  858. }
  859. } else
  860. priv->reload_count = 0;
  861. if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  862. IWL_DEBUG(priv, IWL_DL_FW_ERRORS,
  863. "Restarting adapter due to uCode error.\n");
  864. if (priv->cfg->mod_params->restart_fw)
  865. queue_work(priv->workqueue, &priv->restart);
  866. }
  867. }
  868. EXPORT_SYMBOL(iwl_irq_handle_error);
  869. static int iwl_apm_stop_master(struct iwl_priv *priv)
  870. {
  871. int ret = 0;
  872. /* stop device's busmaster DMA activity */
  873. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
  874. ret = iwl_poll_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_MASTER_DISABLED,
  875. CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
  876. if (ret)
  877. IWL_WARN(priv, "Master Disable Timed Out, 100 usec\n");
  878. IWL_DEBUG_INFO(priv, "stop master\n");
  879. return ret;
  880. }
  881. void iwl_apm_stop(struct iwl_priv *priv)
  882. {
  883. IWL_DEBUG_INFO(priv, "Stop card, put in low power state\n");
  884. /* Stop device's DMA activity */
  885. iwl_apm_stop_master(priv);
  886. /* Reset the entire device */
  887. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  888. udelay(10);
  889. /*
  890. * Clear "initialization complete" bit to move adapter from
  891. * D0A* (powered-up Active) --> D0U* (Uninitialized) state.
  892. */
  893. iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  894. }
  895. EXPORT_SYMBOL(iwl_apm_stop);
  896. /*
  897. * Start up NIC's basic functionality after it has been reset
  898. * (e.g. after platform boot, or shutdown via iwl_apm_stop())
  899. * NOTE: This does not load uCode nor start the embedded processor
  900. */
  901. int iwl_apm_init(struct iwl_priv *priv)
  902. {
  903. int ret = 0;
  904. u16 lctl;
  905. IWL_DEBUG_INFO(priv, "Init card's basic functions\n");
  906. /*
  907. * Use "set_bit" below rather than "write", to preserve any hardware
  908. * bits already set by default after reset.
  909. */
  910. /* Disable L0S exit timer (platform NMI Work/Around) */
  911. iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  912. CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
  913. /*
  914. * Disable L0s without affecting L1;
  915. * don't wait for ICH L0s (ICH bug W/A)
  916. */
  917. iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  918. CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
  919. /* Set FH wait threshold to maximum (HW error during stress W/A) */
  920. iwl_set_bit(priv, CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL);
  921. /*
  922. * Enable HAP INTA (interrupt from management bus) to
  923. * wake device's PCI Express link L1a -> L0s
  924. * NOTE: This is no-op for 3945 (non-existant bit)
  925. */
  926. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  927. CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A);
  928. /*
  929. * HW bug W/A for instability in PCIe bus L0->L0S->L1 transition.
  930. * Check if BIOS (or OS) enabled L1-ASPM on this device.
  931. * If so (likely), disable L0S, so device moves directly L0->L1;
  932. * costs negligible amount of power savings.
  933. * If not (unlikely), enable L0S, so there is at least some
  934. * power savings, even without L1.
  935. */
  936. if (priv->cfg->base_params->set_l0s) {
  937. lctl = iwl_pcie_link_ctl(priv);
  938. if ((lctl & PCI_CFG_LINK_CTRL_VAL_L1_EN) ==
  939. PCI_CFG_LINK_CTRL_VAL_L1_EN) {
  940. /* L1-ASPM enabled; disable(!) L0S */
  941. iwl_set_bit(priv, CSR_GIO_REG,
  942. CSR_GIO_REG_VAL_L0S_ENABLED);
  943. IWL_DEBUG_POWER(priv, "L1 Enabled; Disabling L0S\n");
  944. } else {
  945. /* L1-ASPM disabled; enable(!) L0S */
  946. iwl_clear_bit(priv, CSR_GIO_REG,
  947. CSR_GIO_REG_VAL_L0S_ENABLED);
  948. IWL_DEBUG_POWER(priv, "L1 Disabled; Enabling L0S\n");
  949. }
  950. }
  951. /* Configure analog phase-lock-loop before activating to D0A */
  952. if (priv->cfg->base_params->pll_cfg_val)
  953. iwl_set_bit(priv, CSR_ANA_PLL_CFG,
  954. priv->cfg->base_params->pll_cfg_val);
  955. /*
  956. * Set "initialization complete" bit to move adapter from
  957. * D0U* --> D0A* (powered-up active) state.
  958. */
  959. iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  960. /*
  961. * Wait for clock stabilization; once stabilized, access to
  962. * device-internal resources is supported, e.g. iwl_write_prph()
  963. * and accesses to uCode SRAM.
  964. */
  965. ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
  966. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  967. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  968. if (ret < 0) {
  969. IWL_DEBUG_INFO(priv, "Failed to init the card\n");
  970. goto out;
  971. }
  972. /*
  973. * Enable DMA and BSM (if used) clocks, wait for them to stabilize.
  974. * BSM (Boostrap State Machine) is only in 3945 and 4965;
  975. * later devices (i.e. 5000 and later) have non-volatile SRAM,
  976. * and don't need BSM to restore data after power-saving sleep.
  977. *
  978. * Write to "CLK_EN_REG"; "1" bits enable clocks, while "0" bits
  979. * do not disable clocks. This preserves any hardware bits already
  980. * set by default in "CLK_CTRL_REG" after reset.
  981. */
  982. if (priv->cfg->base_params->use_bsm)
  983. iwl_write_prph(priv, APMG_CLK_EN_REG,
  984. APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT);
  985. else
  986. iwl_write_prph(priv, APMG_CLK_EN_REG,
  987. APMG_CLK_VAL_DMA_CLK_RQT);
  988. udelay(20);
  989. /* Disable L1-Active */
  990. iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
  991. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  992. out:
  993. return ret;
  994. }
  995. EXPORT_SYMBOL(iwl_apm_init);
  996. int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
  997. {
  998. int ret;
  999. s8 prev_tx_power;
  1000. bool defer;
  1001. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  1002. lockdep_assert_held(&priv->mutex);
  1003. if (priv->tx_power_user_lmt == tx_power && !force)
  1004. return 0;
  1005. if (!priv->cfg->ops->lib->send_tx_power)
  1006. return -EOPNOTSUPP;
  1007. if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) {
  1008. IWL_WARN(priv,
  1009. "Requested user TXPOWER %d below lower limit %d.\n",
  1010. tx_power,
  1011. IWLAGN_TX_POWER_TARGET_POWER_MIN);
  1012. return -EINVAL;
  1013. }
  1014. if (tx_power > priv->tx_power_device_lmt) {
  1015. IWL_WARN(priv,
  1016. "Requested user TXPOWER %d above upper limit %d.\n",
  1017. tx_power, priv->tx_power_device_lmt);
  1018. return -EINVAL;
  1019. }
  1020. if (!iwl_is_ready_rf(priv))
  1021. return -EIO;
  1022. /* scan complete and commit_rxon use tx_power_next value,
  1023. * it always need to be updated for newest request */
  1024. priv->tx_power_next = tx_power;
  1025. /* do not set tx power when scanning or channel changing */
  1026. defer = test_bit(STATUS_SCANNING, &priv->status) ||
  1027. memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging));
  1028. if (defer && !force) {
  1029. IWL_DEBUG_INFO(priv, "Deferring tx power set\n");
  1030. return 0;
  1031. }
  1032. prev_tx_power = priv->tx_power_user_lmt;
  1033. priv->tx_power_user_lmt = tx_power;
  1034. ret = priv->cfg->ops->lib->send_tx_power(priv);
  1035. /* if fail to set tx_power, restore the orig. tx power */
  1036. if (ret) {
  1037. priv->tx_power_user_lmt = prev_tx_power;
  1038. priv->tx_power_next = prev_tx_power;
  1039. }
  1040. return ret;
  1041. }
  1042. EXPORT_SYMBOL(iwl_set_tx_power);
  1043. void iwl_send_bt_config(struct iwl_priv *priv)
  1044. {
  1045. struct iwl_bt_cmd bt_cmd = {
  1046. .lead_time = BT_LEAD_TIME_DEF,
  1047. .max_kill = BT_MAX_KILL_DEF,
  1048. .kill_ack_mask = 0,
  1049. .kill_cts_mask = 0,
  1050. };
  1051. if (!bt_coex_active)
  1052. bt_cmd.flags = BT_COEX_DISABLE;
  1053. else
  1054. bt_cmd.flags = BT_COEX_ENABLE;
  1055. priv->bt_enable_flag = bt_cmd.flags;
  1056. IWL_DEBUG_INFO(priv, "BT coex %s\n",
  1057. (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
  1058. if (iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  1059. sizeof(struct iwl_bt_cmd), &bt_cmd))
  1060. IWL_ERR(priv, "failed to send BT Coex Config\n");
  1061. }
  1062. EXPORT_SYMBOL(iwl_send_bt_config);
  1063. int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
  1064. {
  1065. struct iwl_statistics_cmd statistics_cmd = {
  1066. .configuration_flags =
  1067. clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
  1068. };
  1069. if (flags & CMD_ASYNC)
  1070. return iwl_send_cmd_pdu_async(priv, REPLY_STATISTICS_CMD,
  1071. sizeof(struct iwl_statistics_cmd),
  1072. &statistics_cmd, NULL);
  1073. else
  1074. return iwl_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
  1075. sizeof(struct iwl_statistics_cmd),
  1076. &statistics_cmd);
  1077. }
  1078. EXPORT_SYMBOL(iwl_send_statistics_request);
  1079. void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
  1080. struct iwl_rx_mem_buffer *rxb)
  1081. {
  1082. #ifdef CONFIG_IWLWIFI_DEBUG
  1083. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1084. struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
  1085. IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
  1086. sleep->pm_sleep_mode, sleep->pm_wakeup_src);
  1087. #endif
  1088. }
  1089. EXPORT_SYMBOL(iwl_rx_pm_sleep_notif);
  1090. void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
  1091. struct iwl_rx_mem_buffer *rxb)
  1092. {
  1093. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1094. u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  1095. IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
  1096. "notification for %s:\n", len,
  1097. get_cmd_string(pkt->hdr.cmd));
  1098. iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, len);
  1099. }
  1100. EXPORT_SYMBOL(iwl_rx_pm_debug_statistics_notif);
  1101. void iwl_rx_reply_error(struct iwl_priv *priv,
  1102. struct iwl_rx_mem_buffer *rxb)
  1103. {
  1104. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1105. IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
  1106. "seq 0x%04X ser 0x%08X\n",
  1107. le32_to_cpu(pkt->u.err_resp.error_type),
  1108. get_cmd_string(pkt->u.err_resp.cmd_id),
  1109. pkt->u.err_resp.cmd_id,
  1110. le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
  1111. le32_to_cpu(pkt->u.err_resp.error_info));
  1112. }
  1113. EXPORT_SYMBOL(iwl_rx_reply_error);
  1114. void iwl_clear_isr_stats(struct iwl_priv *priv)
  1115. {
  1116. memset(&priv->isr_stats, 0, sizeof(priv->isr_stats));
  1117. }
  1118. int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  1119. const struct ieee80211_tx_queue_params *params)
  1120. {
  1121. struct iwl_priv *priv = hw->priv;
  1122. struct iwl_rxon_context *ctx;
  1123. unsigned long flags;
  1124. int q;
  1125. IWL_DEBUG_MAC80211(priv, "enter\n");
  1126. if (!iwl_is_ready_rf(priv)) {
  1127. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  1128. return -EIO;
  1129. }
  1130. if (queue >= AC_NUM) {
  1131. IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
  1132. return 0;
  1133. }
  1134. q = AC_NUM - 1 - queue;
  1135. spin_lock_irqsave(&priv->lock, flags);
  1136. /*
  1137. * MULTI-FIXME
  1138. * This may need to be done per interface in nl80211/cfg80211/mac80211.
  1139. */
  1140. for_each_context(priv, ctx) {
  1141. ctx->qos_data.def_qos_parm.ac[q].cw_min =
  1142. cpu_to_le16(params->cw_min);
  1143. ctx->qos_data.def_qos_parm.ac[q].cw_max =
  1144. cpu_to_le16(params->cw_max);
  1145. ctx->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
  1146. ctx->qos_data.def_qos_parm.ac[q].edca_txop =
  1147. cpu_to_le16((params->txop * 32));
  1148. ctx->qos_data.def_qos_parm.ac[q].reserved1 = 0;
  1149. }
  1150. spin_unlock_irqrestore(&priv->lock, flags);
  1151. IWL_DEBUG_MAC80211(priv, "leave\n");
  1152. return 0;
  1153. }
  1154. EXPORT_SYMBOL(iwl_mac_conf_tx);
  1155. int iwl_mac_tx_last_beacon(struct ieee80211_hw *hw)
  1156. {
  1157. struct iwl_priv *priv = hw->priv;
  1158. return priv->ibss_manager == IWL_IBSS_MANAGER;
  1159. }
  1160. EXPORT_SYMBOL_GPL(iwl_mac_tx_last_beacon);
  1161. static int iwl_set_mode(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  1162. {
  1163. iwl_connection_init_rx_config(priv, ctx);
  1164. if (priv->cfg->ops->hcmd->set_rxon_chain)
  1165. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  1166. return iwlcore_commit_rxon(priv, ctx);
  1167. }
  1168. static int iwl_setup_interface(struct iwl_priv *priv,
  1169. struct iwl_rxon_context *ctx)
  1170. {
  1171. struct ieee80211_vif *vif = ctx->vif;
  1172. int err;
  1173. lockdep_assert_held(&priv->mutex);
  1174. /*
  1175. * This variable will be correct only when there's just
  1176. * a single context, but all code using it is for hardware
  1177. * that supports only one context.
  1178. */
  1179. priv->iw_mode = vif->type;
  1180. ctx->is_active = true;
  1181. err = iwl_set_mode(priv, ctx);
  1182. if (err) {
  1183. if (!ctx->always_active)
  1184. ctx->is_active = false;
  1185. return err;
  1186. }
  1187. if (priv->cfg->bt_params && priv->cfg->bt_params->advanced_bt_coexist &&
  1188. vif->type == NL80211_IFTYPE_ADHOC) {
  1189. /*
  1190. * pretend to have high BT traffic as long as we
  1191. * are operating in IBSS mode, as this will cause
  1192. * the rate scaling etc. to behave as intended.
  1193. */
  1194. priv->bt_traffic_load = IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
  1195. }
  1196. return 0;
  1197. }
  1198. int iwl_mac_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1199. {
  1200. struct iwl_priv *priv = hw->priv;
  1201. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  1202. struct iwl_rxon_context *tmp, *ctx = NULL;
  1203. int err;
  1204. enum nl80211_iftype viftype = ieee80211_vif_type_p2p(vif);
  1205. IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n",
  1206. viftype, vif->addr);
  1207. mutex_lock(&priv->mutex);
  1208. if (!iwl_is_ready_rf(priv)) {
  1209. IWL_WARN(priv, "Try to add interface when device not ready\n");
  1210. err = -EINVAL;
  1211. goto out;
  1212. }
  1213. for_each_context(priv, tmp) {
  1214. u32 possible_modes =
  1215. tmp->interface_modes | tmp->exclusive_interface_modes;
  1216. if (tmp->vif) {
  1217. /* check if this busy context is exclusive */
  1218. if (tmp->exclusive_interface_modes &
  1219. BIT(tmp->vif->type)) {
  1220. err = -EINVAL;
  1221. goto out;
  1222. }
  1223. continue;
  1224. }
  1225. if (!(possible_modes & BIT(viftype)))
  1226. continue;
  1227. /* have maybe usable context w/o interface */
  1228. ctx = tmp;
  1229. break;
  1230. }
  1231. if (!ctx) {
  1232. err = -EOPNOTSUPP;
  1233. goto out;
  1234. }
  1235. vif_priv->ctx = ctx;
  1236. ctx->vif = vif;
  1237. err = iwl_setup_interface(priv, ctx);
  1238. if (!err)
  1239. goto out;
  1240. ctx->vif = NULL;
  1241. priv->iw_mode = NL80211_IFTYPE_STATION;
  1242. out:
  1243. mutex_unlock(&priv->mutex);
  1244. IWL_DEBUG_MAC80211(priv, "leave\n");
  1245. return err;
  1246. }
  1247. EXPORT_SYMBOL(iwl_mac_add_interface);
  1248. static void iwl_teardown_interface(struct iwl_priv *priv,
  1249. struct ieee80211_vif *vif,
  1250. bool mode_change)
  1251. {
  1252. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1253. lockdep_assert_held(&priv->mutex);
  1254. if (priv->scan_vif == vif) {
  1255. iwl_scan_cancel_timeout(priv, 200);
  1256. iwl_force_scan_end(priv);
  1257. }
  1258. if (!mode_change) {
  1259. iwl_set_mode(priv, ctx);
  1260. if (!ctx->always_active)
  1261. ctx->is_active = false;
  1262. }
  1263. /*
  1264. * When removing the IBSS interface, overwrite the
  1265. * BT traffic load with the stored one from the last
  1266. * notification, if any. If this is a device that
  1267. * doesn't implement this, this has no effect since
  1268. * both values are the same and zero.
  1269. */
  1270. if (vif->type == NL80211_IFTYPE_ADHOC)
  1271. priv->bt_traffic_load = priv->last_bt_traffic_load;
  1272. }
  1273. void iwl_mac_remove_interface(struct ieee80211_hw *hw,
  1274. struct ieee80211_vif *vif)
  1275. {
  1276. struct iwl_priv *priv = hw->priv;
  1277. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1278. IWL_DEBUG_MAC80211(priv, "enter\n");
  1279. mutex_lock(&priv->mutex);
  1280. WARN_ON(ctx->vif != vif);
  1281. ctx->vif = NULL;
  1282. iwl_teardown_interface(priv, vif, false);
  1283. memset(priv->bssid, 0, ETH_ALEN);
  1284. mutex_unlock(&priv->mutex);
  1285. IWL_DEBUG_MAC80211(priv, "leave\n");
  1286. }
  1287. EXPORT_SYMBOL(iwl_mac_remove_interface);
  1288. int iwl_alloc_txq_mem(struct iwl_priv *priv)
  1289. {
  1290. if (!priv->txq)
  1291. priv->txq = kzalloc(
  1292. sizeof(struct iwl_tx_queue) *
  1293. priv->cfg->base_params->num_of_queues,
  1294. GFP_KERNEL);
  1295. if (!priv->txq) {
  1296. IWL_ERR(priv, "Not enough memory for txq\n");
  1297. return -ENOMEM;
  1298. }
  1299. return 0;
  1300. }
  1301. EXPORT_SYMBOL(iwl_alloc_txq_mem);
  1302. void iwl_free_txq_mem(struct iwl_priv *priv)
  1303. {
  1304. kfree(priv->txq);
  1305. priv->txq = NULL;
  1306. }
  1307. EXPORT_SYMBOL(iwl_free_txq_mem);
  1308. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1309. #define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES)
  1310. void iwl_reset_traffic_log(struct iwl_priv *priv)
  1311. {
  1312. priv->tx_traffic_idx = 0;
  1313. priv->rx_traffic_idx = 0;
  1314. if (priv->tx_traffic)
  1315. memset(priv->tx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
  1316. if (priv->rx_traffic)
  1317. memset(priv->rx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
  1318. }
  1319. int iwl_alloc_traffic_mem(struct iwl_priv *priv)
  1320. {
  1321. u32 traffic_size = IWL_TRAFFIC_DUMP_SIZE;
  1322. if (iwl_debug_level & IWL_DL_TX) {
  1323. if (!priv->tx_traffic) {
  1324. priv->tx_traffic =
  1325. kzalloc(traffic_size, GFP_KERNEL);
  1326. if (!priv->tx_traffic)
  1327. return -ENOMEM;
  1328. }
  1329. }
  1330. if (iwl_debug_level & IWL_DL_RX) {
  1331. if (!priv->rx_traffic) {
  1332. priv->rx_traffic =
  1333. kzalloc(traffic_size, GFP_KERNEL);
  1334. if (!priv->rx_traffic)
  1335. return -ENOMEM;
  1336. }
  1337. }
  1338. iwl_reset_traffic_log(priv);
  1339. return 0;
  1340. }
  1341. EXPORT_SYMBOL(iwl_alloc_traffic_mem);
  1342. void iwl_free_traffic_mem(struct iwl_priv *priv)
  1343. {
  1344. kfree(priv->tx_traffic);
  1345. priv->tx_traffic = NULL;
  1346. kfree(priv->rx_traffic);
  1347. priv->rx_traffic = NULL;
  1348. }
  1349. EXPORT_SYMBOL(iwl_free_traffic_mem);
  1350. void iwl_dbg_log_tx_data_frame(struct iwl_priv *priv,
  1351. u16 length, struct ieee80211_hdr *header)
  1352. {
  1353. __le16 fc;
  1354. u16 len;
  1355. if (likely(!(iwl_debug_level & IWL_DL_TX)))
  1356. return;
  1357. if (!priv->tx_traffic)
  1358. return;
  1359. fc = header->frame_control;
  1360. if (ieee80211_is_data(fc)) {
  1361. len = (length > IWL_TRAFFIC_ENTRY_SIZE)
  1362. ? IWL_TRAFFIC_ENTRY_SIZE : length;
  1363. memcpy((priv->tx_traffic +
  1364. (priv->tx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
  1365. header, len);
  1366. priv->tx_traffic_idx =
  1367. (priv->tx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
  1368. }
  1369. }
  1370. EXPORT_SYMBOL(iwl_dbg_log_tx_data_frame);
  1371. void iwl_dbg_log_rx_data_frame(struct iwl_priv *priv,
  1372. u16 length, struct ieee80211_hdr *header)
  1373. {
  1374. __le16 fc;
  1375. u16 len;
  1376. if (likely(!(iwl_debug_level & IWL_DL_RX)))
  1377. return;
  1378. if (!priv->rx_traffic)
  1379. return;
  1380. fc = header->frame_control;
  1381. if (ieee80211_is_data(fc)) {
  1382. len = (length > IWL_TRAFFIC_ENTRY_SIZE)
  1383. ? IWL_TRAFFIC_ENTRY_SIZE : length;
  1384. memcpy((priv->rx_traffic +
  1385. (priv->rx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
  1386. header, len);
  1387. priv->rx_traffic_idx =
  1388. (priv->rx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
  1389. }
  1390. }
  1391. EXPORT_SYMBOL(iwl_dbg_log_rx_data_frame);
  1392. const char *get_mgmt_string(int cmd)
  1393. {
  1394. switch (cmd) {
  1395. IWL_CMD(MANAGEMENT_ASSOC_REQ);
  1396. IWL_CMD(MANAGEMENT_ASSOC_RESP);
  1397. IWL_CMD(MANAGEMENT_REASSOC_REQ);
  1398. IWL_CMD(MANAGEMENT_REASSOC_RESP);
  1399. IWL_CMD(MANAGEMENT_PROBE_REQ);
  1400. IWL_CMD(MANAGEMENT_PROBE_RESP);
  1401. IWL_CMD(MANAGEMENT_BEACON);
  1402. IWL_CMD(MANAGEMENT_ATIM);
  1403. IWL_CMD(MANAGEMENT_DISASSOC);
  1404. IWL_CMD(MANAGEMENT_AUTH);
  1405. IWL_CMD(MANAGEMENT_DEAUTH);
  1406. IWL_CMD(MANAGEMENT_ACTION);
  1407. default:
  1408. return "UNKNOWN";
  1409. }
  1410. }
  1411. const char *get_ctrl_string(int cmd)
  1412. {
  1413. switch (cmd) {
  1414. IWL_CMD(CONTROL_BACK_REQ);
  1415. IWL_CMD(CONTROL_BACK);
  1416. IWL_CMD(CONTROL_PSPOLL);
  1417. IWL_CMD(CONTROL_RTS);
  1418. IWL_CMD(CONTROL_CTS);
  1419. IWL_CMD(CONTROL_ACK);
  1420. IWL_CMD(CONTROL_CFEND);
  1421. IWL_CMD(CONTROL_CFENDACK);
  1422. default:
  1423. return "UNKNOWN";
  1424. }
  1425. }
  1426. void iwl_clear_traffic_stats(struct iwl_priv *priv)
  1427. {
  1428. memset(&priv->tx_stats, 0, sizeof(struct traffic_stats));
  1429. memset(&priv->rx_stats, 0, sizeof(struct traffic_stats));
  1430. }
  1431. /*
  1432. * if CONFIG_IWLWIFI_DEBUGFS defined, iwl_update_stats function will
  1433. * record all the MGMT, CTRL and DATA pkt for both TX and Rx pass.
  1434. * Use debugFs to display the rx/rx_statistics
  1435. * if CONFIG_IWLWIFI_DEBUGFS not being defined, then no MGMT and CTRL
  1436. * information will be recorded, but DATA pkt still will be recorded
  1437. * for the reason of iwl_led.c need to control the led blinking based on
  1438. * number of tx and rx data.
  1439. *
  1440. */
  1441. void iwl_update_stats(struct iwl_priv *priv, bool is_tx, __le16 fc, u16 len)
  1442. {
  1443. struct traffic_stats *stats;
  1444. if (is_tx)
  1445. stats = &priv->tx_stats;
  1446. else
  1447. stats = &priv->rx_stats;
  1448. if (ieee80211_is_mgmt(fc)) {
  1449. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  1450. case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
  1451. stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
  1452. break;
  1453. case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
  1454. stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
  1455. break;
  1456. case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
  1457. stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
  1458. break;
  1459. case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
  1460. stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
  1461. break;
  1462. case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
  1463. stats->mgmt[MANAGEMENT_PROBE_REQ]++;
  1464. break;
  1465. case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
  1466. stats->mgmt[MANAGEMENT_PROBE_RESP]++;
  1467. break;
  1468. case cpu_to_le16(IEEE80211_STYPE_BEACON):
  1469. stats->mgmt[MANAGEMENT_BEACON]++;
  1470. break;
  1471. case cpu_to_le16(IEEE80211_STYPE_ATIM):
  1472. stats->mgmt[MANAGEMENT_ATIM]++;
  1473. break;
  1474. case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
  1475. stats->mgmt[MANAGEMENT_DISASSOC]++;
  1476. break;
  1477. case cpu_to_le16(IEEE80211_STYPE_AUTH):
  1478. stats->mgmt[MANAGEMENT_AUTH]++;
  1479. break;
  1480. case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
  1481. stats->mgmt[MANAGEMENT_DEAUTH]++;
  1482. break;
  1483. case cpu_to_le16(IEEE80211_STYPE_ACTION):
  1484. stats->mgmt[MANAGEMENT_ACTION]++;
  1485. break;
  1486. }
  1487. } else if (ieee80211_is_ctl(fc)) {
  1488. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  1489. case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
  1490. stats->ctrl[CONTROL_BACK_REQ]++;
  1491. break;
  1492. case cpu_to_le16(IEEE80211_STYPE_BACK):
  1493. stats->ctrl[CONTROL_BACK]++;
  1494. break;
  1495. case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
  1496. stats->ctrl[CONTROL_PSPOLL]++;
  1497. break;
  1498. case cpu_to_le16(IEEE80211_STYPE_RTS):
  1499. stats->ctrl[CONTROL_RTS]++;
  1500. break;
  1501. case cpu_to_le16(IEEE80211_STYPE_CTS):
  1502. stats->ctrl[CONTROL_CTS]++;
  1503. break;
  1504. case cpu_to_le16(IEEE80211_STYPE_ACK):
  1505. stats->ctrl[CONTROL_ACK]++;
  1506. break;
  1507. case cpu_to_le16(IEEE80211_STYPE_CFEND):
  1508. stats->ctrl[CONTROL_CFEND]++;
  1509. break;
  1510. case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
  1511. stats->ctrl[CONTROL_CFENDACK]++;
  1512. break;
  1513. }
  1514. } else {
  1515. /* data */
  1516. stats->data_cnt++;
  1517. stats->data_bytes += len;
  1518. }
  1519. }
  1520. EXPORT_SYMBOL(iwl_update_stats);
  1521. #endif
  1522. static void iwl_force_rf_reset(struct iwl_priv *priv)
  1523. {
  1524. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1525. return;
  1526. if (!iwl_is_any_associated(priv)) {
  1527. IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n");
  1528. return;
  1529. }
  1530. /*
  1531. * There is no easy and better way to force reset the radio,
  1532. * the only known method is switching channel which will force to
  1533. * reset and tune the radio.
  1534. * Use internal short scan (single channel) operation to should
  1535. * achieve this objective.
  1536. * Driver should reset the radio when number of consecutive missed
  1537. * beacon, or any other uCode error condition detected.
  1538. */
  1539. IWL_DEBUG_INFO(priv, "perform radio reset.\n");
  1540. iwl_internal_short_hw_scan(priv);
  1541. }
  1542. int iwl_force_reset(struct iwl_priv *priv, int mode, bool external)
  1543. {
  1544. struct iwl_force_reset *force_reset;
  1545. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1546. return -EINVAL;
  1547. if (mode >= IWL_MAX_FORCE_RESET) {
  1548. IWL_DEBUG_INFO(priv, "invalid reset request.\n");
  1549. return -EINVAL;
  1550. }
  1551. force_reset = &priv->force_reset[mode];
  1552. force_reset->reset_request_count++;
  1553. if (!external) {
  1554. if (force_reset->last_force_reset_jiffies &&
  1555. time_after(force_reset->last_force_reset_jiffies +
  1556. force_reset->reset_duration, jiffies)) {
  1557. IWL_DEBUG_INFO(priv, "force reset rejected\n");
  1558. force_reset->reset_reject_count++;
  1559. return -EAGAIN;
  1560. }
  1561. }
  1562. force_reset->reset_success_count++;
  1563. force_reset->last_force_reset_jiffies = jiffies;
  1564. IWL_DEBUG_INFO(priv, "perform force reset (%d)\n", mode);
  1565. switch (mode) {
  1566. case IWL_RF_RESET:
  1567. iwl_force_rf_reset(priv);
  1568. break;
  1569. case IWL_FW_RESET:
  1570. /*
  1571. * if the request is from external(ex: debugfs),
  1572. * then always perform the request in regardless the module
  1573. * parameter setting
  1574. * if the request is from internal (uCode error or driver
  1575. * detect failure), then fw_restart module parameter
  1576. * need to be check before performing firmware reload
  1577. */
  1578. if (!external && !priv->cfg->mod_params->restart_fw) {
  1579. IWL_DEBUG_INFO(priv, "Cancel firmware reload based on "
  1580. "module parameter setting\n");
  1581. break;
  1582. }
  1583. IWL_ERR(priv, "On demand firmware reload\n");
  1584. /* Set the FW error flag -- cleared on iwl_down */
  1585. set_bit(STATUS_FW_ERROR, &priv->status);
  1586. wake_up_interruptible(&priv->wait_command_queue);
  1587. /*
  1588. * Keep the restart process from trying to send host
  1589. * commands by clearing the INIT status bit
  1590. */
  1591. clear_bit(STATUS_READY, &priv->status);
  1592. queue_work(priv->workqueue, &priv->restart);
  1593. break;
  1594. }
  1595. return 0;
  1596. }
  1597. int iwl_mac_change_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1598. enum nl80211_iftype newtype, bool newp2p)
  1599. {
  1600. struct iwl_priv *priv = hw->priv;
  1601. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1602. struct iwl_rxon_context *tmp;
  1603. u32 interface_modes;
  1604. int err;
  1605. newtype = ieee80211_iftype_p2p(newtype, newp2p);
  1606. mutex_lock(&priv->mutex);
  1607. interface_modes = ctx->interface_modes | ctx->exclusive_interface_modes;
  1608. if (!(interface_modes & BIT(newtype))) {
  1609. err = -EBUSY;
  1610. goto out;
  1611. }
  1612. if (ctx->exclusive_interface_modes & BIT(newtype)) {
  1613. for_each_context(priv, tmp) {
  1614. if (ctx == tmp)
  1615. continue;
  1616. if (!tmp->vif)
  1617. continue;
  1618. /*
  1619. * The current mode switch would be exclusive, but
  1620. * another context is active ... refuse the switch.
  1621. */
  1622. err = -EBUSY;
  1623. goto out;
  1624. }
  1625. }
  1626. /* success */
  1627. iwl_teardown_interface(priv, vif, true);
  1628. vif->type = newtype;
  1629. err = iwl_setup_interface(priv, ctx);
  1630. WARN_ON(err);
  1631. /*
  1632. * We've switched internally, but submitting to the
  1633. * device may have failed for some reason. Mask this
  1634. * error, because otherwise mac80211 will not switch
  1635. * (and set the interface type back) and we'll be
  1636. * out of sync with it.
  1637. */
  1638. err = 0;
  1639. out:
  1640. mutex_unlock(&priv->mutex);
  1641. return err;
  1642. }
  1643. EXPORT_SYMBOL(iwl_mac_change_interface);
  1644. /*
  1645. * On every watchdog tick we check (latest) time stamp. If it does not
  1646. * change during timeout period and queue is not empty we reset firmware.
  1647. */
  1648. static int iwl_check_stuck_queue(struct iwl_priv *priv, int cnt)
  1649. {
  1650. struct iwl_tx_queue *txq = &priv->txq[cnt];
  1651. struct iwl_queue *q = &txq->q;
  1652. unsigned long timeout;
  1653. int ret;
  1654. if (q->read_ptr == q->write_ptr) {
  1655. txq->time_stamp = jiffies;
  1656. return 0;
  1657. }
  1658. timeout = txq->time_stamp +
  1659. msecs_to_jiffies(priv->cfg->base_params->wd_timeout);
  1660. if (time_after(jiffies, timeout)) {
  1661. IWL_ERR(priv, "Queue %d stuck for %u ms.\n",
  1662. q->id, priv->cfg->base_params->wd_timeout);
  1663. ret = iwl_force_reset(priv, IWL_FW_RESET, false);
  1664. return (ret == -EAGAIN) ? 0 : 1;
  1665. }
  1666. return 0;
  1667. }
  1668. /*
  1669. * Making watchdog tick be a quarter of timeout assure we will
  1670. * discover the queue hung between timeout and 1.25*timeout
  1671. */
  1672. #define IWL_WD_TICK(timeout) ((timeout) / 4)
  1673. /*
  1674. * Watchdog timer callback, we check each tx queue for stuck, if if hung
  1675. * we reset the firmware. If everything is fine just rearm the timer.
  1676. */
  1677. void iwl_bg_watchdog(unsigned long data)
  1678. {
  1679. struct iwl_priv *priv = (struct iwl_priv *)data;
  1680. int cnt;
  1681. unsigned long timeout;
  1682. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1683. return;
  1684. timeout = priv->cfg->base_params->wd_timeout;
  1685. if (timeout == 0)
  1686. return;
  1687. /* monitor and check for stuck cmd queue */
  1688. if (iwl_check_stuck_queue(priv, priv->cmd_queue))
  1689. return;
  1690. /* monitor and check for other stuck queues */
  1691. if (iwl_is_any_associated(priv)) {
  1692. for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
  1693. /* skip as we already checked the command queue */
  1694. if (cnt == priv->cmd_queue)
  1695. continue;
  1696. if (iwl_check_stuck_queue(priv, cnt))
  1697. return;
  1698. }
  1699. }
  1700. mod_timer(&priv->watchdog, jiffies +
  1701. msecs_to_jiffies(IWL_WD_TICK(timeout)));
  1702. }
  1703. EXPORT_SYMBOL(iwl_bg_watchdog);
  1704. void iwl_setup_watchdog(struct iwl_priv *priv)
  1705. {
  1706. unsigned int timeout = priv->cfg->base_params->wd_timeout;
  1707. if (timeout)
  1708. mod_timer(&priv->watchdog,
  1709. jiffies + msecs_to_jiffies(IWL_WD_TICK(timeout)));
  1710. else
  1711. del_timer(&priv->watchdog);
  1712. }
  1713. EXPORT_SYMBOL(iwl_setup_watchdog);
  1714. /*
  1715. * extended beacon time format
  1716. * time in usec will be changed into a 32-bit value in extended:internal format
  1717. * the extended part is the beacon counts
  1718. * the internal part is the time in usec within one beacon interval
  1719. */
  1720. u32 iwl_usecs_to_beacons(struct iwl_priv *priv, u32 usec, u32 beacon_interval)
  1721. {
  1722. u32 quot;
  1723. u32 rem;
  1724. u32 interval = beacon_interval * TIME_UNIT;
  1725. if (!interval || !usec)
  1726. return 0;
  1727. quot = (usec / interval) &
  1728. (iwl_beacon_time_mask_high(priv,
  1729. priv->hw_params.beacon_time_tsf_bits) >>
  1730. priv->hw_params.beacon_time_tsf_bits);
  1731. rem = (usec % interval) & iwl_beacon_time_mask_low(priv,
  1732. priv->hw_params.beacon_time_tsf_bits);
  1733. return (quot << priv->hw_params.beacon_time_tsf_bits) + rem;
  1734. }
  1735. EXPORT_SYMBOL(iwl_usecs_to_beacons);
  1736. /* base is usually what we get from ucode with each received frame,
  1737. * the same as HW timer counter counting down
  1738. */
  1739. __le32 iwl_add_beacon_time(struct iwl_priv *priv, u32 base,
  1740. u32 addon, u32 beacon_interval)
  1741. {
  1742. u32 base_low = base & iwl_beacon_time_mask_low(priv,
  1743. priv->hw_params.beacon_time_tsf_bits);
  1744. u32 addon_low = addon & iwl_beacon_time_mask_low(priv,
  1745. priv->hw_params.beacon_time_tsf_bits);
  1746. u32 interval = beacon_interval * TIME_UNIT;
  1747. u32 res = (base & iwl_beacon_time_mask_high(priv,
  1748. priv->hw_params.beacon_time_tsf_bits)) +
  1749. (addon & iwl_beacon_time_mask_high(priv,
  1750. priv->hw_params.beacon_time_tsf_bits));
  1751. if (base_low > addon_low)
  1752. res += base_low - addon_low;
  1753. else if (base_low < addon_low) {
  1754. res += interval + base_low - addon_low;
  1755. res += (1 << priv->hw_params.beacon_time_tsf_bits);
  1756. } else
  1757. res += (1 << priv->hw_params.beacon_time_tsf_bits);
  1758. return cpu_to_le32(res);
  1759. }
  1760. EXPORT_SYMBOL(iwl_add_beacon_time);
  1761. #ifdef CONFIG_PM
  1762. int iwl_pci_suspend(struct device *device)
  1763. {
  1764. struct pci_dev *pdev = to_pci_dev(device);
  1765. struct iwl_priv *priv = pci_get_drvdata(pdev);
  1766. /*
  1767. * This function is called when system goes into suspend state
  1768. * mac80211 will call iwl_mac_stop() from the mac80211 suspend function
  1769. * first but since iwl_mac_stop() has no knowledge of who the caller is,
  1770. * it will not call apm_ops.stop() to stop the DMA operation.
  1771. * Calling apm_ops.stop here to make sure we stop the DMA.
  1772. */
  1773. iwl_apm_stop(priv);
  1774. return 0;
  1775. }
  1776. EXPORT_SYMBOL(iwl_pci_suspend);
  1777. int iwl_pci_resume(struct device *device)
  1778. {
  1779. struct pci_dev *pdev = to_pci_dev(device);
  1780. struct iwl_priv *priv = pci_get_drvdata(pdev);
  1781. bool hw_rfkill = false;
  1782. /*
  1783. * We disable the RETRY_TIMEOUT register (0x41) to keep
  1784. * PCI Tx retries from interfering with C3 CPU state.
  1785. */
  1786. pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
  1787. iwl_enable_interrupts(priv);
  1788. if (!(iwl_read32(priv, CSR_GP_CNTRL) &
  1789. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  1790. hw_rfkill = true;
  1791. if (hw_rfkill)
  1792. set_bit(STATUS_RF_KILL_HW, &priv->status);
  1793. else
  1794. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  1795. wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rfkill);
  1796. return 0;
  1797. }
  1798. EXPORT_SYMBOL(iwl_pci_resume);
  1799. const struct dev_pm_ops iwl_pm_ops = {
  1800. .suspend = iwl_pci_suspend,
  1801. .resume = iwl_pci_resume,
  1802. .freeze = iwl_pci_suspend,
  1803. .thaw = iwl_pci_resume,
  1804. .poweroff = iwl_pci_suspend,
  1805. .restore = iwl_pci_resume,
  1806. };
  1807. EXPORT_SYMBOL(iwl_pm_ops);
  1808. #endif /* CONFIG_PM */