iwl-core.c 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652
  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. struct ieee80211_ops *hw_ops)
  73. {
  74. struct iwl_priv *priv;
  75. /* mac80211 allocates memory for this device instance, including
  76. * space for this driver's private structure */
  77. struct ieee80211_hw *hw =
  78. ieee80211_alloc_hw(sizeof(struct iwl_priv), hw_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. /*
  91. * QoS support
  92. */
  93. static void iwl_update_qos(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  94. {
  95. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  96. return;
  97. if (!ctx->is_active)
  98. return;
  99. ctx->qos_data.def_qos_parm.qos_flags = 0;
  100. if (ctx->qos_data.qos_active)
  101. ctx->qos_data.def_qos_parm.qos_flags |=
  102. QOS_PARAM_FLG_UPDATE_EDCA_MSK;
  103. if (ctx->ht.enabled)
  104. ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
  105. IWL_DEBUG_QOS(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
  106. ctx->qos_data.qos_active,
  107. ctx->qos_data.def_qos_parm.qos_flags);
  108. iwl_send_cmd_pdu_async(priv, ctx->qos_cmd,
  109. sizeof(struct iwl_qosparam_cmd),
  110. &ctx->qos_data.def_qos_parm, NULL);
  111. }
  112. #define MAX_BIT_RATE_40_MHZ 150 /* Mbps */
  113. #define MAX_BIT_RATE_20_MHZ 72 /* Mbps */
  114. static void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv,
  115. struct ieee80211_sta_ht_cap *ht_info,
  116. enum ieee80211_band band)
  117. {
  118. u16 max_bit_rate = 0;
  119. u8 rx_chains_num = priv->hw_params.rx_chains_num;
  120. u8 tx_chains_num = priv->hw_params.tx_chains_num;
  121. ht_info->cap = 0;
  122. memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
  123. ht_info->ht_supported = true;
  124. if (priv->cfg->ht_params &&
  125. priv->cfg->ht_params->ht_greenfield_support)
  126. ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
  127. ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
  128. max_bit_rate = MAX_BIT_RATE_20_MHZ;
  129. if (priv->hw_params.ht40_channel & BIT(band)) {
  130. ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  131. ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
  132. ht_info->mcs.rx_mask[4] = 0x01;
  133. max_bit_rate = MAX_BIT_RATE_40_MHZ;
  134. }
  135. if (priv->cfg->mod_params->amsdu_size_8K)
  136. ht_info->cap |= IEEE80211_HT_CAP_MAX_AMSDU;
  137. ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
  138. if (priv->cfg->bt_params && priv->cfg->bt_params->ampdu_factor)
  139. ht_info->ampdu_factor = priv->cfg->bt_params->ampdu_factor;
  140. ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
  141. if (priv->cfg->bt_params && priv->cfg->bt_params->ampdu_density)
  142. ht_info->ampdu_density = priv->cfg->bt_params->ampdu_density;
  143. ht_info->mcs.rx_mask[0] = 0xFF;
  144. if (rx_chains_num >= 2)
  145. ht_info->mcs.rx_mask[1] = 0xFF;
  146. if (rx_chains_num >= 3)
  147. ht_info->mcs.rx_mask[2] = 0xFF;
  148. /* Highest supported Rx data rate */
  149. max_bit_rate *= rx_chains_num;
  150. WARN_ON(max_bit_rate & ~IEEE80211_HT_MCS_RX_HIGHEST_MASK);
  151. ht_info->mcs.rx_highest = cpu_to_le16(max_bit_rate);
  152. /* Tx MCS capabilities */
  153. ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  154. if (tx_chains_num != rx_chains_num) {
  155. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
  156. ht_info->mcs.tx_params |= ((tx_chains_num - 1) <<
  157. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
  158. }
  159. }
  160. /**
  161. * iwlcore_init_geos - Initialize mac80211's geo/channel info based from eeprom
  162. */
  163. int iwlcore_init_geos(struct iwl_priv *priv)
  164. {
  165. struct iwl_channel_info *ch;
  166. struct ieee80211_supported_band *sband;
  167. struct ieee80211_channel *channels;
  168. struct ieee80211_channel *geo_ch;
  169. struct ieee80211_rate *rates;
  170. int i = 0;
  171. if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
  172. priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
  173. IWL_DEBUG_INFO(priv, "Geography modes already initialized.\n");
  174. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  175. return 0;
  176. }
  177. channels = kzalloc(sizeof(struct ieee80211_channel) *
  178. priv->channel_count, GFP_KERNEL);
  179. if (!channels)
  180. return -ENOMEM;
  181. rates = kzalloc((sizeof(struct ieee80211_rate) * IWL_RATE_COUNT_LEGACY),
  182. GFP_KERNEL);
  183. if (!rates) {
  184. kfree(channels);
  185. return -ENOMEM;
  186. }
  187. /* 5.2GHz channels start after the 2.4GHz channels */
  188. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  189. sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
  190. /* just OFDM */
  191. sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
  192. sband->n_bitrates = IWL_RATE_COUNT_LEGACY - IWL_FIRST_OFDM_RATE;
  193. if (priv->cfg->sku & IWL_SKU_N)
  194. iwlcore_init_ht_hw_capab(priv, &sband->ht_cap,
  195. IEEE80211_BAND_5GHZ);
  196. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  197. sband->channels = channels;
  198. /* OFDM & CCK */
  199. sband->bitrates = rates;
  200. sband->n_bitrates = IWL_RATE_COUNT_LEGACY;
  201. if (priv->cfg->sku & IWL_SKU_N)
  202. iwlcore_init_ht_hw_capab(priv, &sband->ht_cap,
  203. IEEE80211_BAND_2GHZ);
  204. priv->ieee_channels = channels;
  205. priv->ieee_rates = rates;
  206. for (i = 0; i < priv->channel_count; i++) {
  207. ch = &priv->channel_info[i];
  208. /* FIXME: might be removed if scan is OK */
  209. if (!is_channel_valid(ch))
  210. continue;
  211. if (is_channel_a_band(ch))
  212. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  213. else
  214. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  215. geo_ch = &sband->channels[sband->n_channels++];
  216. geo_ch->center_freq =
  217. ieee80211_channel_to_frequency(ch->channel);
  218. geo_ch->max_power = ch->max_power_avg;
  219. geo_ch->max_antenna_gain = 0xff;
  220. geo_ch->hw_value = ch->channel;
  221. if (is_channel_valid(ch)) {
  222. if (!(ch->flags & EEPROM_CHANNEL_IBSS))
  223. geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
  224. if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
  225. geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
  226. if (ch->flags & EEPROM_CHANNEL_RADAR)
  227. geo_ch->flags |= IEEE80211_CHAN_RADAR;
  228. geo_ch->flags |= ch->ht40_extension_channel;
  229. if (ch->max_power_avg > priv->tx_power_device_lmt)
  230. priv->tx_power_device_lmt = ch->max_power_avg;
  231. } else {
  232. geo_ch->flags |= IEEE80211_CHAN_DISABLED;
  233. }
  234. IWL_DEBUG_INFO(priv, "Channel %d Freq=%d[%sGHz] %s flag=0x%X\n",
  235. ch->channel, geo_ch->center_freq,
  236. is_channel_a_band(ch) ? "5.2" : "2.4",
  237. geo_ch->flags & IEEE80211_CHAN_DISABLED ?
  238. "restricted" : "valid",
  239. geo_ch->flags);
  240. }
  241. if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
  242. priv->cfg->sku & IWL_SKU_A) {
  243. IWL_INFO(priv, "Incorrectly detected BG card as ABG. "
  244. "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n",
  245. priv->pci_dev->device,
  246. priv->pci_dev->subsystem_device);
  247. priv->cfg->sku &= ~IWL_SKU_A;
  248. }
  249. IWL_INFO(priv, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
  250. priv->bands[IEEE80211_BAND_2GHZ].n_channels,
  251. priv->bands[IEEE80211_BAND_5GHZ].n_channels);
  252. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  253. return 0;
  254. }
  255. EXPORT_SYMBOL(iwlcore_init_geos);
  256. /*
  257. * iwlcore_free_geos - undo allocations in iwlcore_init_geos
  258. */
  259. void iwlcore_free_geos(struct iwl_priv *priv)
  260. {
  261. kfree(priv->ieee_channels);
  262. kfree(priv->ieee_rates);
  263. clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
  264. }
  265. EXPORT_SYMBOL(iwlcore_free_geos);
  266. /*
  267. * iwlcore_tx_cmd_protection: Set rts/cts. 3945 and 4965 only share this
  268. * function.
  269. */
  270. void iwlcore_tx_cmd_protection(struct iwl_priv *priv,
  271. struct ieee80211_tx_info *info,
  272. __le16 fc, __le32 *tx_flags)
  273. {
  274. if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) {
  275. *tx_flags |= TX_CMD_FLG_RTS_MSK;
  276. *tx_flags &= ~TX_CMD_FLG_CTS_MSK;
  277. *tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
  278. if (!ieee80211_is_mgmt(fc))
  279. return;
  280. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  281. case cpu_to_le16(IEEE80211_STYPE_AUTH):
  282. case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
  283. case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
  284. case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
  285. *tx_flags &= ~TX_CMD_FLG_RTS_MSK;
  286. *tx_flags |= TX_CMD_FLG_CTS_MSK;
  287. break;
  288. }
  289. } else if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
  290. *tx_flags &= ~TX_CMD_FLG_RTS_MSK;
  291. *tx_flags |= TX_CMD_FLG_CTS_MSK;
  292. *tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
  293. }
  294. }
  295. EXPORT_SYMBOL(iwlcore_tx_cmd_protection);
  296. static bool iwl_is_channel_extension(struct iwl_priv *priv,
  297. enum ieee80211_band band,
  298. u16 channel, u8 extension_chan_offset)
  299. {
  300. const struct iwl_channel_info *ch_info;
  301. ch_info = iwl_get_channel_info(priv, band, channel);
  302. if (!is_channel_valid(ch_info))
  303. return false;
  304. if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
  305. return !(ch_info->ht40_extension_channel &
  306. IEEE80211_CHAN_NO_HT40PLUS);
  307. else if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW)
  308. return !(ch_info->ht40_extension_channel &
  309. IEEE80211_CHAN_NO_HT40MINUS);
  310. return false;
  311. }
  312. bool iwl_is_ht40_tx_allowed(struct iwl_priv *priv,
  313. struct iwl_rxon_context *ctx,
  314. struct ieee80211_sta_ht_cap *ht_cap)
  315. {
  316. if (!ctx->ht.enabled || !ctx->ht.is_40mhz)
  317. return false;
  318. /*
  319. * We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40
  320. * the bit will not set if it is pure 40MHz case
  321. */
  322. if (ht_cap && !ht_cap->ht_supported)
  323. return false;
  324. #ifdef CONFIG_IWLWIFI_DEBUGFS
  325. if (priv->disable_ht40)
  326. return false;
  327. #endif
  328. return iwl_is_channel_extension(priv, priv->band,
  329. le16_to_cpu(ctx->staging.channel),
  330. ctx->ht.extension_chan_offset);
  331. }
  332. EXPORT_SYMBOL(iwl_is_ht40_tx_allowed);
  333. static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
  334. {
  335. u16 new_val;
  336. u16 beacon_factor;
  337. /*
  338. * If mac80211 hasn't given us a beacon interval, program
  339. * the default into the device (not checking this here
  340. * would cause the adjustment below to return the maximum
  341. * value, which may break PAN.)
  342. */
  343. if (!beacon_val)
  344. return DEFAULT_BEACON_INTERVAL;
  345. /*
  346. * If the beacon interval we obtained from the peer
  347. * is too large, we'll have to wake up more often
  348. * (and in IBSS case, we'll beacon too much)
  349. *
  350. * For example, if max_beacon_val is 4096, and the
  351. * requested beacon interval is 7000, we'll have to
  352. * use 3500 to be able to wake up on the beacons.
  353. *
  354. * This could badly influence beacon detection stats.
  355. */
  356. beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
  357. new_val = beacon_val / beacon_factor;
  358. if (!new_val)
  359. new_val = max_beacon_val;
  360. return new_val;
  361. }
  362. int iwl_send_rxon_timing(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  363. {
  364. u64 tsf;
  365. s32 interval_tm, rem;
  366. struct ieee80211_conf *conf = NULL;
  367. u16 beacon_int;
  368. struct ieee80211_vif *vif = ctx->vif;
  369. conf = ieee80211_get_hw_conf(priv->hw);
  370. lockdep_assert_held(&priv->mutex);
  371. memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd));
  372. ctx->timing.timestamp = cpu_to_le64(priv->timestamp);
  373. ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval);
  374. beacon_int = vif ? vif->bss_conf.beacon_int : 0;
  375. /*
  376. * TODO: For IBSS we need to get atim_window from mac80211,
  377. * for now just always use 0
  378. */
  379. ctx->timing.atim_window = 0;
  380. if (ctx->ctxid == IWL_RXON_CTX_PAN &&
  381. (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION) &&
  382. iwl_is_associated(priv, IWL_RXON_CTX_BSS) &&
  383. priv->contexts[IWL_RXON_CTX_BSS].vif &&
  384. priv->contexts[IWL_RXON_CTX_BSS].vif->bss_conf.beacon_int) {
  385. ctx->timing.beacon_interval =
  386. priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval;
  387. beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
  388. } else if (ctx->ctxid == IWL_RXON_CTX_BSS &&
  389. iwl_is_associated(priv, IWL_RXON_CTX_PAN) &&
  390. priv->contexts[IWL_RXON_CTX_PAN].vif &&
  391. priv->contexts[IWL_RXON_CTX_PAN].vif->bss_conf.beacon_int &&
  392. (!iwl_is_associated_ctx(ctx) || !ctx->vif ||
  393. !ctx->vif->bss_conf.beacon_int)) {
  394. ctx->timing.beacon_interval =
  395. priv->contexts[IWL_RXON_CTX_PAN].timing.beacon_interval;
  396. beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
  397. } else {
  398. beacon_int = iwl_adjust_beacon_interval(beacon_int,
  399. priv->hw_params.max_beacon_itrvl * TIME_UNIT);
  400. ctx->timing.beacon_interval = cpu_to_le16(beacon_int);
  401. }
  402. tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
  403. interval_tm = beacon_int * TIME_UNIT;
  404. rem = do_div(tsf, interval_tm);
  405. ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
  406. ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1;
  407. IWL_DEBUG_ASSOC(priv,
  408. "beacon interval %d beacon timer %d beacon tim %d\n",
  409. le16_to_cpu(ctx->timing.beacon_interval),
  410. le32_to_cpu(ctx->timing.beacon_init_val),
  411. le16_to_cpu(ctx->timing.atim_window));
  412. return iwl_send_cmd_pdu(priv, ctx->rxon_timing_cmd,
  413. sizeof(ctx->timing), &ctx->timing);
  414. }
  415. EXPORT_SYMBOL(iwl_send_rxon_timing);
  416. void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
  417. int hw_decrypt)
  418. {
  419. struct iwl_rxon_cmd *rxon = &ctx->staging;
  420. if (hw_decrypt)
  421. rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
  422. else
  423. rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
  424. }
  425. EXPORT_SYMBOL(iwl_set_rxon_hwcrypto);
  426. /* validate RXON structure is valid */
  427. int iwl_check_rxon_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  428. {
  429. struct iwl_rxon_cmd *rxon = &ctx->staging;
  430. bool error = false;
  431. if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
  432. if (rxon->flags & RXON_FLG_TGJ_NARROW_BAND_MSK) {
  433. IWL_WARN(priv, "check 2.4G: wrong narrow\n");
  434. error = true;
  435. }
  436. if (rxon->flags & RXON_FLG_RADAR_DETECT_MSK) {
  437. IWL_WARN(priv, "check 2.4G: wrong radar\n");
  438. error = true;
  439. }
  440. } else {
  441. if (!(rxon->flags & RXON_FLG_SHORT_SLOT_MSK)) {
  442. IWL_WARN(priv, "check 5.2G: not short slot!\n");
  443. error = true;
  444. }
  445. if (rxon->flags & RXON_FLG_CCK_MSK) {
  446. IWL_WARN(priv, "check 5.2G: CCK!\n");
  447. error = true;
  448. }
  449. }
  450. if ((rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1) {
  451. IWL_WARN(priv, "mac/bssid mcast!\n");
  452. error = true;
  453. }
  454. /* make sure basic rates 6Mbps and 1Mbps are supported */
  455. if ((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0 &&
  456. (rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0) {
  457. IWL_WARN(priv, "neither 1 nor 6 are basic\n");
  458. error = true;
  459. }
  460. if (le16_to_cpu(rxon->assoc_id) > 2007) {
  461. IWL_WARN(priv, "aid > 2007\n");
  462. error = true;
  463. }
  464. if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
  465. == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) {
  466. IWL_WARN(priv, "CCK and short slot\n");
  467. error = true;
  468. }
  469. if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
  470. == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) {
  471. IWL_WARN(priv, "CCK and auto detect");
  472. error = true;
  473. }
  474. if ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
  475. RXON_FLG_TGG_PROTECT_MSK)) ==
  476. RXON_FLG_TGG_PROTECT_MSK) {
  477. IWL_WARN(priv, "TGg but no auto-detect\n");
  478. error = true;
  479. }
  480. if (error)
  481. IWL_WARN(priv, "Tuning to channel %d\n",
  482. le16_to_cpu(rxon->channel));
  483. if (error) {
  484. IWL_ERR(priv, "Invalid RXON\n");
  485. return -EINVAL;
  486. }
  487. return 0;
  488. }
  489. EXPORT_SYMBOL(iwl_check_rxon_cmd);
  490. /**
  491. * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
  492. * @priv: staging_rxon is compared to active_rxon
  493. *
  494. * If the RXON structure is changing enough to require a new tune,
  495. * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
  496. * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
  497. */
  498. int iwl_full_rxon_required(struct iwl_priv *priv,
  499. struct iwl_rxon_context *ctx)
  500. {
  501. const struct iwl_rxon_cmd *staging = &ctx->staging;
  502. const struct iwl_rxon_cmd *active = &ctx->active;
  503. #define CHK(cond) \
  504. if ((cond)) { \
  505. IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
  506. return 1; \
  507. }
  508. #define CHK_NEQ(c1, c2) \
  509. if ((c1) != (c2)) { \
  510. IWL_DEBUG_INFO(priv, "need full RXON - " \
  511. #c1 " != " #c2 " - %d != %d\n", \
  512. (c1), (c2)); \
  513. return 1; \
  514. }
  515. /* These items are only settable from the full RXON command */
  516. CHK(!iwl_is_associated_ctx(ctx));
  517. CHK(compare_ether_addr(staging->bssid_addr, active->bssid_addr));
  518. CHK(compare_ether_addr(staging->node_addr, active->node_addr));
  519. CHK(compare_ether_addr(staging->wlap_bssid_addr,
  520. active->wlap_bssid_addr));
  521. CHK_NEQ(staging->dev_type, active->dev_type);
  522. CHK_NEQ(staging->channel, active->channel);
  523. CHK_NEQ(staging->air_propagation, active->air_propagation);
  524. CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates,
  525. active->ofdm_ht_single_stream_basic_rates);
  526. CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates,
  527. active->ofdm_ht_dual_stream_basic_rates);
  528. CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates,
  529. active->ofdm_ht_triple_stream_basic_rates);
  530. CHK_NEQ(staging->assoc_id, active->assoc_id);
  531. /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
  532. * be updated with the RXON_ASSOC command -- however only some
  533. * flag transitions are allowed using RXON_ASSOC */
  534. /* Check if we are not switching bands */
  535. CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK,
  536. active->flags & RXON_FLG_BAND_24G_MSK);
  537. /* Check if we are switching association toggle */
  538. CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK,
  539. active->filter_flags & RXON_FILTER_ASSOC_MSK);
  540. #undef CHK
  541. #undef CHK_NEQ
  542. return 0;
  543. }
  544. EXPORT_SYMBOL(iwl_full_rxon_required);
  545. u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv,
  546. struct iwl_rxon_context *ctx)
  547. {
  548. /*
  549. * Assign the lowest rate -- should really get this from
  550. * the beacon skb from mac80211.
  551. */
  552. if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK)
  553. return IWL_RATE_1M_PLCP;
  554. else
  555. return IWL_RATE_6M_PLCP;
  556. }
  557. EXPORT_SYMBOL(iwl_rate_get_lowest_plcp);
  558. static void _iwl_set_rxon_ht(struct iwl_priv *priv,
  559. struct iwl_ht_config *ht_conf,
  560. struct iwl_rxon_context *ctx)
  561. {
  562. struct iwl_rxon_cmd *rxon = &ctx->staging;
  563. if (!ctx->ht.enabled) {
  564. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
  565. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
  566. RXON_FLG_HT40_PROT_MSK |
  567. RXON_FLG_HT_PROT_MSK);
  568. return;
  569. }
  570. /* FIXME: if the definition of ht.protection changed, the "translation"
  571. * will be needed for rxon->flags
  572. */
  573. rxon->flags |= cpu_to_le32(ctx->ht.protection << RXON_FLG_HT_OPERATING_MODE_POS);
  574. /* Set up channel bandwidth:
  575. * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
  576. /* clear the HT channel mode before set the mode */
  577. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
  578. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  579. if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) {
  580. /* pure ht40 */
  581. if (ctx->ht.protection == IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
  582. rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
  583. /* Note: control channel is opposite of extension channel */
  584. switch (ctx->ht.extension_chan_offset) {
  585. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  586. rxon->flags &= ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  587. break;
  588. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  589. rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  590. break;
  591. }
  592. } else {
  593. /* Note: control channel is opposite of extension channel */
  594. switch (ctx->ht.extension_chan_offset) {
  595. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  596. rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  597. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
  598. break;
  599. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  600. rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  601. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
  602. break;
  603. case IEEE80211_HT_PARAM_CHA_SEC_NONE:
  604. default:
  605. /* channel location only valid if in Mixed mode */
  606. IWL_ERR(priv, "invalid extension channel offset\n");
  607. break;
  608. }
  609. }
  610. } else {
  611. rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
  612. }
  613. if (priv->cfg->ops->hcmd->set_rxon_chain)
  614. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  615. IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
  616. "extension channel offset 0x%x\n",
  617. le32_to_cpu(rxon->flags), ctx->ht.protection,
  618. ctx->ht.extension_chan_offset);
  619. }
  620. void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
  621. {
  622. struct iwl_rxon_context *ctx;
  623. for_each_context(priv, ctx)
  624. _iwl_set_rxon_ht(priv, ht_conf, ctx);
  625. }
  626. EXPORT_SYMBOL(iwl_set_rxon_ht);
  627. /* Return valid, unused, channel for a passive scan to reset the RF */
  628. u8 iwl_get_single_channel_number(struct iwl_priv *priv,
  629. enum ieee80211_band band)
  630. {
  631. const struct iwl_channel_info *ch_info;
  632. int i;
  633. u8 channel = 0;
  634. u8 min, max;
  635. struct iwl_rxon_context *ctx;
  636. if (band == IEEE80211_BAND_5GHZ) {
  637. min = 14;
  638. max = priv->channel_count;
  639. } else {
  640. min = 0;
  641. max = 14;
  642. }
  643. for (i = min; i < max; i++) {
  644. bool busy = false;
  645. for_each_context(priv, ctx) {
  646. busy = priv->channel_info[i].channel ==
  647. le16_to_cpu(ctx->staging.channel);
  648. if (busy)
  649. break;
  650. }
  651. if (busy)
  652. continue;
  653. channel = priv->channel_info[i].channel;
  654. ch_info = iwl_get_channel_info(priv, band, channel);
  655. if (is_channel_valid(ch_info))
  656. break;
  657. }
  658. return channel;
  659. }
  660. EXPORT_SYMBOL(iwl_get_single_channel_number);
  661. /**
  662. * iwl_set_rxon_channel - Set the band and channel values in staging RXON
  663. * @ch: requested channel as a pointer to struct ieee80211_channel
  664. * NOTE: Does not commit to the hardware; it sets appropriate bit fields
  665. * in the staging RXON flag structure based on the ch->band
  666. */
  667. int iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
  668. struct iwl_rxon_context *ctx)
  669. {
  670. enum ieee80211_band band = ch->band;
  671. u16 channel = ch->hw_value;
  672. if ((le16_to_cpu(ctx->staging.channel) == channel) &&
  673. (priv->band == band))
  674. return 0;
  675. ctx->staging.channel = cpu_to_le16(channel);
  676. if (band == IEEE80211_BAND_5GHZ)
  677. ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK;
  678. else
  679. ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
  680. priv->band = band;
  681. IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
  682. return 0;
  683. }
  684. EXPORT_SYMBOL(iwl_set_rxon_channel);
  685. void iwl_set_flags_for_band(struct iwl_priv *priv,
  686. struct iwl_rxon_context *ctx,
  687. enum ieee80211_band band,
  688. struct ieee80211_vif *vif)
  689. {
  690. if (band == IEEE80211_BAND_5GHZ) {
  691. ctx->staging.flags &=
  692. ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
  693. | RXON_FLG_CCK_MSK);
  694. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  695. } else {
  696. /* Copied from iwl_post_associate() */
  697. if (vif && vif->bss_conf.use_short_slot)
  698. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  699. else
  700. ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  701. ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
  702. ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK;
  703. ctx->staging.flags &= ~RXON_FLG_CCK_MSK;
  704. }
  705. }
  706. EXPORT_SYMBOL(iwl_set_flags_for_band);
  707. /*
  708. * initialize rxon structure with default values from eeprom
  709. */
  710. void iwl_connection_init_rx_config(struct iwl_priv *priv,
  711. struct iwl_rxon_context *ctx)
  712. {
  713. const struct iwl_channel_info *ch_info;
  714. memset(&ctx->staging, 0, sizeof(ctx->staging));
  715. if (!ctx->vif) {
  716. ctx->staging.dev_type = ctx->unused_devtype;
  717. } else switch (ctx->vif->type) {
  718. case NL80211_IFTYPE_AP:
  719. ctx->staging.dev_type = ctx->ap_devtype;
  720. break;
  721. case NL80211_IFTYPE_STATION:
  722. ctx->staging.dev_type = ctx->station_devtype;
  723. ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
  724. break;
  725. case NL80211_IFTYPE_ADHOC:
  726. ctx->staging.dev_type = ctx->ibss_devtype;
  727. ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
  728. ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
  729. RXON_FILTER_ACCEPT_GRP_MSK;
  730. break;
  731. default:
  732. IWL_ERR(priv, "Unsupported interface type %d\n",
  733. ctx->vif->type);
  734. break;
  735. }
  736. #if 0
  737. /* TODO: Figure out when short_preamble would be set and cache from
  738. * that */
  739. if (!hw_to_local(priv->hw)->short_preamble)
  740. ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  741. else
  742. ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  743. #endif
  744. ch_info = iwl_get_channel_info(priv, priv->band,
  745. le16_to_cpu(ctx->active.channel));
  746. if (!ch_info)
  747. ch_info = &priv->channel_info[0];
  748. ctx->staging.channel = cpu_to_le16(ch_info->channel);
  749. priv->band = ch_info->band;
  750. iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif);
  751. ctx->staging.ofdm_basic_rates =
  752. (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  753. ctx->staging.cck_basic_rates =
  754. (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  755. /* clear both MIX and PURE40 mode flag */
  756. ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
  757. RXON_FLG_CHANNEL_MODE_PURE_40);
  758. if (ctx->vif)
  759. memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN);
  760. ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff;
  761. ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff;
  762. ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff;
  763. }
  764. EXPORT_SYMBOL(iwl_connection_init_rx_config);
  765. void iwl_set_rate(struct iwl_priv *priv)
  766. {
  767. const struct ieee80211_supported_band *hw = NULL;
  768. struct ieee80211_rate *rate;
  769. struct iwl_rxon_context *ctx;
  770. int i;
  771. hw = iwl_get_hw_mode(priv, priv->band);
  772. if (!hw) {
  773. IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
  774. return;
  775. }
  776. priv->active_rate = 0;
  777. for (i = 0; i < hw->n_bitrates; i++) {
  778. rate = &(hw->bitrates[i]);
  779. if (rate->hw_value < IWL_RATE_COUNT_LEGACY)
  780. priv->active_rate |= (1 << rate->hw_value);
  781. }
  782. IWL_DEBUG_RATE(priv, "Set active_rate = %0x\n", priv->active_rate);
  783. for_each_context(priv, ctx) {
  784. ctx->staging.cck_basic_rates =
  785. (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  786. ctx->staging.ofdm_basic_rates =
  787. (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  788. }
  789. }
  790. EXPORT_SYMBOL(iwl_set_rate);
  791. void iwl_chswitch_done(struct iwl_priv *priv, bool is_success)
  792. {
  793. /*
  794. * MULTI-FIXME
  795. * See iwl_mac_channel_switch.
  796. */
  797. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  798. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  799. return;
  800. if (priv->switch_rxon.switch_in_progress) {
  801. ieee80211_chswitch_done(ctx->vif, is_success);
  802. mutex_lock(&priv->mutex);
  803. priv->switch_rxon.switch_in_progress = false;
  804. mutex_unlock(&priv->mutex);
  805. }
  806. }
  807. EXPORT_SYMBOL(iwl_chswitch_done);
  808. void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
  809. {
  810. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  811. struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
  812. /*
  813. * MULTI-FIXME
  814. * See iwl_mac_channel_switch.
  815. */
  816. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  817. struct iwl_rxon_cmd *rxon = (void *)&ctx->active;
  818. if (priv->switch_rxon.switch_in_progress) {
  819. if (!le32_to_cpu(csa->status) &&
  820. (csa->channel == priv->switch_rxon.channel)) {
  821. rxon->channel = csa->channel;
  822. ctx->staging.channel = csa->channel;
  823. IWL_DEBUG_11H(priv, "CSA notif: channel %d\n",
  824. le16_to_cpu(csa->channel));
  825. iwl_chswitch_done(priv, true);
  826. } else {
  827. IWL_ERR(priv, "CSA notif (fail) : channel %d\n",
  828. le16_to_cpu(csa->channel));
  829. iwl_chswitch_done(priv, false);
  830. }
  831. }
  832. }
  833. EXPORT_SYMBOL(iwl_rx_csa);
  834. #ifdef CONFIG_IWLWIFI_DEBUG
  835. void iwl_print_rx_config_cmd(struct iwl_priv *priv,
  836. struct iwl_rxon_context *ctx)
  837. {
  838. struct iwl_rxon_cmd *rxon = &ctx->staging;
  839. IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
  840. iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
  841. IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
  842. IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
  843. IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
  844. le32_to_cpu(rxon->filter_flags));
  845. IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
  846. IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
  847. rxon->ofdm_basic_rates);
  848. IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
  849. IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
  850. IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
  851. IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
  852. }
  853. EXPORT_SYMBOL(iwl_print_rx_config_cmd);
  854. #endif
  855. /**
  856. * iwl_irq_handle_error - called for HW or SW error interrupt from card
  857. */
  858. void iwl_irq_handle_error(struct iwl_priv *priv)
  859. {
  860. /* Set the FW error flag -- cleared on iwl_down */
  861. set_bit(STATUS_FW_ERROR, &priv->status);
  862. /* Cancel currently queued command. */
  863. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  864. IWL_ERR(priv, "Loaded firmware version: %s\n",
  865. priv->hw->wiphy->fw_version);
  866. priv->cfg->ops->lib->dump_nic_error_log(priv);
  867. if (priv->cfg->ops->lib->dump_csr)
  868. priv->cfg->ops->lib->dump_csr(priv);
  869. if (priv->cfg->ops->lib->dump_fh)
  870. priv->cfg->ops->lib->dump_fh(priv, NULL, false);
  871. priv->cfg->ops->lib->dump_nic_event_log(priv, false, NULL, false);
  872. #ifdef CONFIG_IWLWIFI_DEBUG
  873. if (iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS)
  874. iwl_print_rx_config_cmd(priv,
  875. &priv->contexts[IWL_RXON_CTX_BSS]);
  876. #endif
  877. wake_up_interruptible(&priv->wait_command_queue);
  878. /* Keep the restart process from trying to send host
  879. * commands by clearing the INIT status bit */
  880. clear_bit(STATUS_READY, &priv->status);
  881. if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  882. IWL_DEBUG(priv, IWL_DL_FW_ERRORS,
  883. "Restarting adapter due to uCode error.\n");
  884. if (priv->cfg->mod_params->restart_fw)
  885. queue_work(priv->workqueue, &priv->restart);
  886. }
  887. }
  888. EXPORT_SYMBOL(iwl_irq_handle_error);
  889. static int iwl_apm_stop_master(struct iwl_priv *priv)
  890. {
  891. int ret = 0;
  892. /* stop device's busmaster DMA activity */
  893. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
  894. ret = iwl_poll_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_MASTER_DISABLED,
  895. CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
  896. if (ret)
  897. IWL_WARN(priv, "Master Disable Timed Out, 100 usec\n");
  898. IWL_DEBUG_INFO(priv, "stop master\n");
  899. return ret;
  900. }
  901. void iwl_apm_stop(struct iwl_priv *priv)
  902. {
  903. IWL_DEBUG_INFO(priv, "Stop card, put in low power state\n");
  904. /* Stop device's DMA activity */
  905. iwl_apm_stop_master(priv);
  906. /* Reset the entire device */
  907. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  908. udelay(10);
  909. /*
  910. * Clear "initialization complete" bit to move adapter from
  911. * D0A* (powered-up Active) --> D0U* (Uninitialized) state.
  912. */
  913. iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  914. }
  915. EXPORT_SYMBOL(iwl_apm_stop);
  916. /*
  917. * Start up NIC's basic functionality after it has been reset
  918. * (e.g. after platform boot, or shutdown via iwl_apm_stop())
  919. * NOTE: This does not load uCode nor start the embedded processor
  920. */
  921. int iwl_apm_init(struct iwl_priv *priv)
  922. {
  923. int ret = 0;
  924. u16 lctl;
  925. IWL_DEBUG_INFO(priv, "Init card's basic functions\n");
  926. /*
  927. * Use "set_bit" below rather than "write", to preserve any hardware
  928. * bits already set by default after reset.
  929. */
  930. /* Disable L0S exit timer (platform NMI Work/Around) */
  931. iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  932. CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
  933. /*
  934. * Disable L0s without affecting L1;
  935. * don't wait for ICH L0s (ICH bug W/A)
  936. */
  937. iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  938. CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
  939. /* Set FH wait threshold to maximum (HW error during stress W/A) */
  940. iwl_set_bit(priv, CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL);
  941. /*
  942. * Enable HAP INTA (interrupt from management bus) to
  943. * wake device's PCI Express link L1a -> L0s
  944. * NOTE: This is no-op for 3945 (non-existant bit)
  945. */
  946. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  947. CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A);
  948. /*
  949. * HW bug W/A for instability in PCIe bus L0->L0S->L1 transition.
  950. * Check if BIOS (or OS) enabled L1-ASPM on this device.
  951. * If so (likely), disable L0S, so device moves directly L0->L1;
  952. * costs negligible amount of power savings.
  953. * If not (unlikely), enable L0S, so there is at least some
  954. * power savings, even without L1.
  955. */
  956. if (priv->cfg->base_params->set_l0s) {
  957. lctl = iwl_pcie_link_ctl(priv);
  958. if ((lctl & PCI_CFG_LINK_CTRL_VAL_L1_EN) ==
  959. PCI_CFG_LINK_CTRL_VAL_L1_EN) {
  960. /* L1-ASPM enabled; disable(!) L0S */
  961. iwl_set_bit(priv, CSR_GIO_REG,
  962. CSR_GIO_REG_VAL_L0S_ENABLED);
  963. IWL_DEBUG_POWER(priv, "L1 Enabled; Disabling L0S\n");
  964. } else {
  965. /* L1-ASPM disabled; enable(!) L0S */
  966. iwl_clear_bit(priv, CSR_GIO_REG,
  967. CSR_GIO_REG_VAL_L0S_ENABLED);
  968. IWL_DEBUG_POWER(priv, "L1 Disabled; Enabling L0S\n");
  969. }
  970. }
  971. /* Configure analog phase-lock-loop before activating to D0A */
  972. if (priv->cfg->base_params->pll_cfg_val)
  973. iwl_set_bit(priv, CSR_ANA_PLL_CFG,
  974. priv->cfg->base_params->pll_cfg_val);
  975. /*
  976. * Set "initialization complete" bit to move adapter from
  977. * D0U* --> D0A* (powered-up active) state.
  978. */
  979. iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  980. /*
  981. * Wait for clock stabilization; once stabilized, access to
  982. * device-internal resources is supported, e.g. iwl_write_prph()
  983. * and accesses to uCode SRAM.
  984. */
  985. ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
  986. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  987. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  988. if (ret < 0) {
  989. IWL_DEBUG_INFO(priv, "Failed to init the card\n");
  990. goto out;
  991. }
  992. /*
  993. * Enable DMA and BSM (if used) clocks, wait for them to stabilize.
  994. * BSM (Boostrap State Machine) is only in 3945 and 4965;
  995. * later devices (i.e. 5000 and later) have non-volatile SRAM,
  996. * and don't need BSM to restore data after power-saving sleep.
  997. *
  998. * Write to "CLK_EN_REG"; "1" bits enable clocks, while "0" bits
  999. * do not disable clocks. This preserves any hardware bits already
  1000. * set by default in "CLK_CTRL_REG" after reset.
  1001. */
  1002. if (priv->cfg->base_params->use_bsm)
  1003. iwl_write_prph(priv, APMG_CLK_EN_REG,
  1004. APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT);
  1005. else
  1006. iwl_write_prph(priv, APMG_CLK_EN_REG,
  1007. APMG_CLK_VAL_DMA_CLK_RQT);
  1008. udelay(20);
  1009. /* Disable L1-Active */
  1010. iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
  1011. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  1012. out:
  1013. return ret;
  1014. }
  1015. EXPORT_SYMBOL(iwl_apm_init);
  1016. int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
  1017. {
  1018. int ret;
  1019. s8 prev_tx_power;
  1020. lockdep_assert_held(&priv->mutex);
  1021. if (priv->tx_power_user_lmt == tx_power && !force)
  1022. return 0;
  1023. if (!priv->cfg->ops->lib->send_tx_power)
  1024. return -EOPNOTSUPP;
  1025. if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) {
  1026. IWL_WARN(priv,
  1027. "Requested user TXPOWER %d below lower limit %d.\n",
  1028. tx_power,
  1029. IWLAGN_TX_POWER_TARGET_POWER_MIN);
  1030. return -EINVAL;
  1031. }
  1032. if (tx_power > priv->tx_power_device_lmt) {
  1033. IWL_WARN(priv,
  1034. "Requested user TXPOWER %d above upper limit %d.\n",
  1035. tx_power, priv->tx_power_device_lmt);
  1036. return -EINVAL;
  1037. }
  1038. if (!iwl_is_ready_rf(priv))
  1039. return -EIO;
  1040. /* scan complete use tx_power_next, need to be updated */
  1041. priv->tx_power_next = tx_power;
  1042. if (test_bit(STATUS_SCANNING, &priv->status) && !force) {
  1043. IWL_DEBUG_INFO(priv, "Deferring tx power set while scanning\n");
  1044. return 0;
  1045. }
  1046. prev_tx_power = priv->tx_power_user_lmt;
  1047. priv->tx_power_user_lmt = tx_power;
  1048. ret = priv->cfg->ops->lib->send_tx_power(priv);
  1049. /* if fail to set tx_power, restore the orig. tx power */
  1050. if (ret) {
  1051. priv->tx_power_user_lmt = prev_tx_power;
  1052. priv->tx_power_next = prev_tx_power;
  1053. }
  1054. return ret;
  1055. }
  1056. EXPORT_SYMBOL(iwl_set_tx_power);
  1057. irqreturn_t iwl_isr_legacy(int irq, void *data)
  1058. {
  1059. struct iwl_priv *priv = data;
  1060. u32 inta, inta_mask;
  1061. u32 inta_fh;
  1062. unsigned long flags;
  1063. if (!priv)
  1064. return IRQ_NONE;
  1065. spin_lock_irqsave(&priv->lock, flags);
  1066. /* Disable (but don't clear!) interrupts here to avoid
  1067. * back-to-back ISRs and sporadic interrupts from our NIC.
  1068. * If we have something to service, the tasklet will re-enable ints.
  1069. * If we *don't* have something, we'll re-enable before leaving here. */
  1070. inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
  1071. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  1072. /* Discover which interrupts are active/pending */
  1073. inta = iwl_read32(priv, CSR_INT);
  1074. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  1075. /* Ignore interrupt if there's nothing in NIC to service.
  1076. * This may be due to IRQ shared with another device,
  1077. * or due to sporadic interrupts thrown from our NIC. */
  1078. if (!inta && !inta_fh) {
  1079. IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0, inta_fh == 0\n");
  1080. goto none;
  1081. }
  1082. if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
  1083. /* Hardware disappeared. It might have already raised
  1084. * an interrupt */
  1085. IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
  1086. goto unplugged;
  1087. }
  1088. IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  1089. inta, inta_mask, inta_fh);
  1090. inta &= ~CSR_INT_BIT_SCD;
  1091. /* iwl_irq_tasklet() will service interrupts and re-enable them */
  1092. if (likely(inta || inta_fh))
  1093. tasklet_schedule(&priv->irq_tasklet);
  1094. unplugged:
  1095. spin_unlock_irqrestore(&priv->lock, flags);
  1096. return IRQ_HANDLED;
  1097. none:
  1098. /* re-enable interrupts here since we don't have anything to service. */
  1099. /* only Re-enable if diabled by irq */
  1100. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  1101. iwl_enable_interrupts(priv);
  1102. spin_unlock_irqrestore(&priv->lock, flags);
  1103. return IRQ_NONE;
  1104. }
  1105. EXPORT_SYMBOL(iwl_isr_legacy);
  1106. void iwl_send_bt_config(struct iwl_priv *priv)
  1107. {
  1108. struct iwl_bt_cmd bt_cmd = {
  1109. .lead_time = BT_LEAD_TIME_DEF,
  1110. .max_kill = BT_MAX_KILL_DEF,
  1111. .kill_ack_mask = 0,
  1112. .kill_cts_mask = 0,
  1113. };
  1114. if (!bt_coex_active)
  1115. bt_cmd.flags = BT_COEX_DISABLE;
  1116. else
  1117. bt_cmd.flags = BT_COEX_ENABLE;
  1118. IWL_DEBUG_INFO(priv, "BT coex %s\n",
  1119. (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
  1120. if (iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  1121. sizeof(struct iwl_bt_cmd), &bt_cmd))
  1122. IWL_ERR(priv, "failed to send BT Coex Config\n");
  1123. }
  1124. EXPORT_SYMBOL(iwl_send_bt_config);
  1125. int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
  1126. {
  1127. struct iwl_statistics_cmd statistics_cmd = {
  1128. .configuration_flags =
  1129. clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
  1130. };
  1131. if (flags & CMD_ASYNC)
  1132. return iwl_send_cmd_pdu_async(priv, REPLY_STATISTICS_CMD,
  1133. sizeof(struct iwl_statistics_cmd),
  1134. &statistics_cmd, NULL);
  1135. else
  1136. return iwl_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
  1137. sizeof(struct iwl_statistics_cmd),
  1138. &statistics_cmd);
  1139. }
  1140. EXPORT_SYMBOL(iwl_send_statistics_request);
  1141. void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
  1142. struct iwl_rx_mem_buffer *rxb)
  1143. {
  1144. #ifdef CONFIG_IWLWIFI_DEBUG
  1145. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1146. struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
  1147. IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
  1148. sleep->pm_sleep_mode, sleep->pm_wakeup_src);
  1149. #endif
  1150. }
  1151. EXPORT_SYMBOL(iwl_rx_pm_sleep_notif);
  1152. void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
  1153. struct iwl_rx_mem_buffer *rxb)
  1154. {
  1155. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1156. u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  1157. IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
  1158. "notification for %s:\n", len,
  1159. get_cmd_string(pkt->hdr.cmd));
  1160. iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, len);
  1161. }
  1162. EXPORT_SYMBOL(iwl_rx_pm_debug_statistics_notif);
  1163. void iwl_rx_reply_error(struct iwl_priv *priv,
  1164. struct iwl_rx_mem_buffer *rxb)
  1165. {
  1166. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1167. IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
  1168. "seq 0x%04X ser 0x%08X\n",
  1169. le32_to_cpu(pkt->u.err_resp.error_type),
  1170. get_cmd_string(pkt->u.err_resp.cmd_id),
  1171. pkt->u.err_resp.cmd_id,
  1172. le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
  1173. le32_to_cpu(pkt->u.err_resp.error_info));
  1174. }
  1175. EXPORT_SYMBOL(iwl_rx_reply_error);
  1176. void iwl_clear_isr_stats(struct iwl_priv *priv)
  1177. {
  1178. memset(&priv->isr_stats, 0, sizeof(priv->isr_stats));
  1179. }
  1180. int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  1181. const struct ieee80211_tx_queue_params *params)
  1182. {
  1183. struct iwl_priv *priv = hw->priv;
  1184. struct iwl_rxon_context *ctx;
  1185. unsigned long flags;
  1186. int q;
  1187. IWL_DEBUG_MAC80211(priv, "enter\n");
  1188. if (!iwl_is_ready_rf(priv)) {
  1189. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  1190. return -EIO;
  1191. }
  1192. if (queue >= AC_NUM) {
  1193. IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
  1194. return 0;
  1195. }
  1196. q = AC_NUM - 1 - queue;
  1197. spin_lock_irqsave(&priv->lock, flags);
  1198. /*
  1199. * MULTI-FIXME
  1200. * This may need to be done per interface in nl80211/cfg80211/mac80211.
  1201. */
  1202. for_each_context(priv, ctx) {
  1203. ctx->qos_data.def_qos_parm.ac[q].cw_min =
  1204. cpu_to_le16(params->cw_min);
  1205. ctx->qos_data.def_qos_parm.ac[q].cw_max =
  1206. cpu_to_le16(params->cw_max);
  1207. ctx->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
  1208. ctx->qos_data.def_qos_parm.ac[q].edca_txop =
  1209. cpu_to_le16((params->txop * 32));
  1210. ctx->qos_data.def_qos_parm.ac[q].reserved1 = 0;
  1211. }
  1212. spin_unlock_irqrestore(&priv->lock, flags);
  1213. IWL_DEBUG_MAC80211(priv, "leave\n");
  1214. return 0;
  1215. }
  1216. EXPORT_SYMBOL(iwl_mac_conf_tx);
  1217. int iwl_mac_tx_last_beacon(struct ieee80211_hw *hw)
  1218. {
  1219. struct iwl_priv *priv = hw->priv;
  1220. return priv->ibss_manager == IWL_IBSS_MANAGER;
  1221. }
  1222. EXPORT_SYMBOL_GPL(iwl_mac_tx_last_beacon);
  1223. static void iwl_ht_conf(struct iwl_priv *priv,
  1224. struct ieee80211_vif *vif)
  1225. {
  1226. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  1227. struct ieee80211_sta *sta;
  1228. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1229. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1230. IWL_DEBUG_MAC80211(priv, "enter:\n");
  1231. if (!ctx->ht.enabled)
  1232. return;
  1233. ctx->ht.protection =
  1234. bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION;
  1235. ctx->ht.non_gf_sta_present =
  1236. !!(bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
  1237. ht_conf->single_chain_sufficient = false;
  1238. switch (vif->type) {
  1239. case NL80211_IFTYPE_STATION:
  1240. rcu_read_lock();
  1241. sta = ieee80211_find_sta(vif, bss_conf->bssid);
  1242. if (sta) {
  1243. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  1244. int maxstreams;
  1245. maxstreams = (ht_cap->mcs.tx_params &
  1246. IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
  1247. >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
  1248. maxstreams += 1;
  1249. if ((ht_cap->mcs.rx_mask[1] == 0) &&
  1250. (ht_cap->mcs.rx_mask[2] == 0))
  1251. ht_conf->single_chain_sufficient = true;
  1252. if (maxstreams <= 1)
  1253. ht_conf->single_chain_sufficient = true;
  1254. } else {
  1255. /*
  1256. * If at all, this can only happen through a race
  1257. * when the AP disconnects us while we're still
  1258. * setting up the connection, in that case mac80211
  1259. * will soon tell us about that.
  1260. */
  1261. ht_conf->single_chain_sufficient = true;
  1262. }
  1263. rcu_read_unlock();
  1264. break;
  1265. case NL80211_IFTYPE_ADHOC:
  1266. ht_conf->single_chain_sufficient = true;
  1267. break;
  1268. default:
  1269. break;
  1270. }
  1271. IWL_DEBUG_MAC80211(priv, "leave\n");
  1272. }
  1273. static inline void iwl_set_no_assoc(struct iwl_priv *priv,
  1274. struct ieee80211_vif *vif)
  1275. {
  1276. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1277. iwl_led_disassociate(priv);
  1278. /*
  1279. * inform the ucode that there is no longer an
  1280. * association and that no more packets should be
  1281. * sent
  1282. */
  1283. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1284. ctx->staging.assoc_id = 0;
  1285. iwlcore_commit_rxon(priv, ctx);
  1286. }
  1287. static void iwlcore_beacon_update(struct ieee80211_hw *hw,
  1288. struct ieee80211_vif *vif)
  1289. {
  1290. struct iwl_priv *priv = hw->priv;
  1291. unsigned long flags;
  1292. __le64 timestamp;
  1293. struct sk_buff *skb = ieee80211_beacon_get(hw, vif);
  1294. if (!skb)
  1295. return;
  1296. IWL_DEBUG_ASSOC(priv, "enter\n");
  1297. lockdep_assert_held(&priv->mutex);
  1298. if (!priv->beacon_ctx) {
  1299. IWL_ERR(priv, "update beacon but no beacon context!\n");
  1300. dev_kfree_skb(skb);
  1301. return;
  1302. }
  1303. spin_lock_irqsave(&priv->lock, flags);
  1304. if (priv->beacon_skb)
  1305. dev_kfree_skb(priv->beacon_skb);
  1306. priv->beacon_skb = skb;
  1307. timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
  1308. priv->timestamp = le64_to_cpu(timestamp);
  1309. IWL_DEBUG_ASSOC(priv, "leave\n");
  1310. spin_unlock_irqrestore(&priv->lock, flags);
  1311. if (!iwl_is_ready_rf(priv)) {
  1312. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  1313. return;
  1314. }
  1315. priv->cfg->ops->lib->post_associate(priv, priv->beacon_ctx->vif);
  1316. }
  1317. void iwl_bss_info_changed(struct ieee80211_hw *hw,
  1318. struct ieee80211_vif *vif,
  1319. struct ieee80211_bss_conf *bss_conf,
  1320. u32 changes)
  1321. {
  1322. struct iwl_priv *priv = hw->priv;
  1323. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1324. int ret;
  1325. IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
  1326. if (!iwl_is_alive(priv))
  1327. return;
  1328. mutex_lock(&priv->mutex);
  1329. if (changes & (BSS_CHANGED_BSSID | BSS_CHANGED_ASSOC |
  1330. BSS_CHANGED_BEACON_ENABLED)) {
  1331. /*
  1332. * If there is currently a HW scan going on in the
  1333. * background then we need to cancel it else the RXON
  1334. * below in post_associate or set_no_assoc can fail.
  1335. */
  1336. if (iwl_scan_cancel_timeout(priv, 200)) {
  1337. IWL_WARN(priv, "Can not cancel scan\n");
  1338. goto out;
  1339. }
  1340. }
  1341. if (changes & BSS_CHANGED_QOS) {
  1342. unsigned long flags;
  1343. spin_lock_irqsave(&priv->lock, flags);
  1344. ctx->qos_data.qos_active = bss_conf->qos;
  1345. iwl_update_qos(priv, ctx);
  1346. spin_unlock_irqrestore(&priv->lock, flags);
  1347. }
  1348. if (changes & BSS_CHANGED_BEACON_ENABLED) {
  1349. /*
  1350. * the add_interface code must make sure we only ever
  1351. * have a single interface that could be beaconing at
  1352. * any time.
  1353. */
  1354. if (vif->bss_conf.enable_beacon)
  1355. priv->beacon_ctx = ctx;
  1356. else
  1357. priv->beacon_ctx = NULL;
  1358. }
  1359. if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_AP) {
  1360. dev_kfree_skb(priv->beacon_skb);
  1361. priv->beacon_skb = ieee80211_beacon_get(hw, vif);
  1362. }
  1363. if (changes & BSS_CHANGED_BEACON_INT && vif->type == NL80211_IFTYPE_AP)
  1364. iwl_send_rxon_timing(priv, ctx);
  1365. if (changes & BSS_CHANGED_BSSID) {
  1366. IWL_DEBUG_MAC80211(priv, "BSSID %pM\n", bss_conf->bssid);
  1367. /* mac80211 only sets assoc when in STATION mode */
  1368. if (vif->type == NL80211_IFTYPE_ADHOC || bss_conf->assoc) {
  1369. memcpy(ctx->staging.bssid_addr,
  1370. bss_conf->bssid, ETH_ALEN);
  1371. /* currently needed in a few places */
  1372. memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN);
  1373. } else {
  1374. ctx->staging.filter_flags &=
  1375. ~RXON_FILTER_ASSOC_MSK;
  1376. }
  1377. }
  1378. /*
  1379. * This needs to be after setting the BSSID in case
  1380. * mac80211 decides to do both changes at once because
  1381. * it will invoke post_associate.
  1382. */
  1383. if (vif->type == NL80211_IFTYPE_ADHOC && changes & BSS_CHANGED_BEACON)
  1384. iwlcore_beacon_update(hw, vif);
  1385. if (changes & BSS_CHANGED_ERP_PREAMBLE) {
  1386. IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
  1387. bss_conf->use_short_preamble);
  1388. if (bss_conf->use_short_preamble)
  1389. ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  1390. else
  1391. ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  1392. }
  1393. if (changes & BSS_CHANGED_ERP_CTS_PROT) {
  1394. IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n", bss_conf->use_cts_prot);
  1395. if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
  1396. ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
  1397. else
  1398. ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
  1399. if (bss_conf->use_cts_prot)
  1400. ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
  1401. else
  1402. ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
  1403. }
  1404. if (changes & BSS_CHANGED_BASIC_RATES) {
  1405. /* XXX use this information
  1406. *
  1407. * To do that, remove code from iwl_set_rate() and put something
  1408. * like this here:
  1409. *
  1410. if (A-band)
  1411. ctx->staging.ofdm_basic_rates =
  1412. bss_conf->basic_rates;
  1413. else
  1414. ctx->staging.ofdm_basic_rates =
  1415. bss_conf->basic_rates >> 4;
  1416. ctx->staging.cck_basic_rates =
  1417. bss_conf->basic_rates & 0xF;
  1418. */
  1419. }
  1420. if (changes & BSS_CHANGED_HT) {
  1421. iwl_ht_conf(priv, vif);
  1422. if (priv->cfg->ops->hcmd->set_rxon_chain)
  1423. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  1424. }
  1425. if (changes & BSS_CHANGED_ASSOC) {
  1426. IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
  1427. if (bss_conf->assoc) {
  1428. priv->timestamp = bss_conf->timestamp;
  1429. iwl_led_associate(priv);
  1430. if (!iwl_is_rfkill(priv))
  1431. priv->cfg->ops->lib->post_associate(priv, vif);
  1432. } else
  1433. iwl_set_no_assoc(priv, vif);
  1434. }
  1435. if (changes && iwl_is_associated_ctx(ctx) && bss_conf->aid) {
  1436. IWL_DEBUG_MAC80211(priv, "Changes (%#x) while associated\n",
  1437. changes);
  1438. ret = iwl_send_rxon_assoc(priv, ctx);
  1439. if (!ret) {
  1440. /* Sync active_rxon with latest change. */
  1441. memcpy((void *)&ctx->active,
  1442. &ctx->staging,
  1443. sizeof(struct iwl_rxon_cmd));
  1444. }
  1445. }
  1446. if (changes & BSS_CHANGED_BEACON_ENABLED) {
  1447. if (vif->bss_conf.enable_beacon) {
  1448. memcpy(ctx->staging.bssid_addr,
  1449. bss_conf->bssid, ETH_ALEN);
  1450. memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN);
  1451. iwl_led_associate(priv);
  1452. iwlcore_config_ap(priv, vif);
  1453. } else
  1454. iwl_set_no_assoc(priv, vif);
  1455. }
  1456. if (changes & BSS_CHANGED_IBSS) {
  1457. ret = priv->cfg->ops->lib->manage_ibss_station(priv, vif,
  1458. bss_conf->ibss_joined);
  1459. if (ret)
  1460. IWL_ERR(priv, "failed to %s IBSS station %pM\n",
  1461. bss_conf->ibss_joined ? "add" : "remove",
  1462. bss_conf->bssid);
  1463. }
  1464. if (changes & BSS_CHANGED_IDLE &&
  1465. priv->cfg->ops->hcmd->set_pan_params) {
  1466. if (priv->cfg->ops->hcmd->set_pan_params(priv))
  1467. IWL_ERR(priv, "failed to update PAN params\n");
  1468. }
  1469. out:
  1470. mutex_unlock(&priv->mutex);
  1471. IWL_DEBUG_MAC80211(priv, "leave\n");
  1472. }
  1473. EXPORT_SYMBOL(iwl_bss_info_changed);
  1474. static int iwl_set_mode(struct iwl_priv *priv, struct ieee80211_vif *vif)
  1475. {
  1476. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1477. iwl_connection_init_rx_config(priv, ctx);
  1478. if (priv->cfg->ops->hcmd->set_rxon_chain)
  1479. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  1480. return iwlcore_commit_rxon(priv, ctx);
  1481. }
  1482. int iwl_mac_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  1483. {
  1484. struct iwl_priv *priv = hw->priv;
  1485. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  1486. struct iwl_rxon_context *tmp, *ctx = NULL;
  1487. int err = 0;
  1488. IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n",
  1489. vif->type, vif->addr);
  1490. mutex_lock(&priv->mutex);
  1491. if (!iwl_is_ready_rf(priv)) {
  1492. IWL_WARN(priv, "Try to add interface when device not ready\n");
  1493. err = -EINVAL;
  1494. goto out;
  1495. }
  1496. for_each_context(priv, tmp) {
  1497. u32 possible_modes =
  1498. tmp->interface_modes | tmp->exclusive_interface_modes;
  1499. if (tmp->vif) {
  1500. /* check if this busy context is exclusive */
  1501. if (tmp->exclusive_interface_modes &
  1502. BIT(tmp->vif->type)) {
  1503. err = -EINVAL;
  1504. goto out;
  1505. }
  1506. continue;
  1507. }
  1508. if (!(possible_modes & BIT(vif->type)))
  1509. continue;
  1510. /* have maybe usable context w/o interface */
  1511. ctx = tmp;
  1512. break;
  1513. }
  1514. if (!ctx) {
  1515. err = -EOPNOTSUPP;
  1516. goto out;
  1517. }
  1518. vif_priv->ctx = ctx;
  1519. ctx->vif = vif;
  1520. /*
  1521. * This variable will be correct only when there's just
  1522. * a single context, but all code using it is for hardware
  1523. * that supports only one context.
  1524. */
  1525. priv->iw_mode = vif->type;
  1526. ctx->is_active = true;
  1527. err = iwl_set_mode(priv, vif);
  1528. if (err) {
  1529. if (!ctx->always_active)
  1530. ctx->is_active = false;
  1531. goto out_err;
  1532. }
  1533. if (priv->cfg->bt_params &&
  1534. priv->cfg->bt_params->advanced_bt_coexist &&
  1535. vif->type == NL80211_IFTYPE_ADHOC) {
  1536. /*
  1537. * pretend to have high BT traffic as long as we
  1538. * are operating in IBSS mode, as this will cause
  1539. * the rate scaling etc. to behave as intended.
  1540. */
  1541. priv->bt_traffic_load = IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
  1542. }
  1543. goto out;
  1544. out_err:
  1545. ctx->vif = NULL;
  1546. priv->iw_mode = NL80211_IFTYPE_STATION;
  1547. out:
  1548. mutex_unlock(&priv->mutex);
  1549. IWL_DEBUG_MAC80211(priv, "leave\n");
  1550. return err;
  1551. }
  1552. EXPORT_SYMBOL(iwl_mac_add_interface);
  1553. void iwl_mac_remove_interface(struct ieee80211_hw *hw,
  1554. struct ieee80211_vif *vif)
  1555. {
  1556. struct iwl_priv *priv = hw->priv;
  1557. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1558. IWL_DEBUG_MAC80211(priv, "enter\n");
  1559. mutex_lock(&priv->mutex);
  1560. WARN_ON(ctx->vif != vif);
  1561. ctx->vif = NULL;
  1562. if (priv->scan_vif == vif) {
  1563. iwl_scan_cancel_timeout(priv, 200);
  1564. iwl_force_scan_end(priv);
  1565. }
  1566. iwl_set_mode(priv, vif);
  1567. if (!ctx->always_active)
  1568. ctx->is_active = false;
  1569. /*
  1570. * When removing the IBSS interface, overwrite the
  1571. * BT traffic load with the stored one from the last
  1572. * notification, if any. If this is a device that
  1573. * doesn't implement this, this has no effect since
  1574. * both values are the same and zero.
  1575. */
  1576. if (vif->type == NL80211_IFTYPE_ADHOC)
  1577. priv->bt_traffic_load = priv->notif_bt_traffic_load;
  1578. memset(priv->bssid, 0, ETH_ALEN);
  1579. mutex_unlock(&priv->mutex);
  1580. IWL_DEBUG_MAC80211(priv, "leave\n");
  1581. }
  1582. EXPORT_SYMBOL(iwl_mac_remove_interface);
  1583. /**
  1584. * iwl_mac_config - mac80211 config callback
  1585. */
  1586. int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
  1587. {
  1588. struct iwl_priv *priv = hw->priv;
  1589. const struct iwl_channel_info *ch_info;
  1590. struct ieee80211_conf *conf = &hw->conf;
  1591. struct ieee80211_channel *channel = conf->channel;
  1592. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  1593. struct iwl_rxon_context *ctx;
  1594. unsigned long flags = 0;
  1595. int ret = 0;
  1596. u16 ch;
  1597. int scan_active = 0;
  1598. mutex_lock(&priv->mutex);
  1599. IWL_DEBUG_MAC80211(priv, "enter to channel %d changed 0x%X\n",
  1600. channel->hw_value, changed);
  1601. if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
  1602. test_bit(STATUS_SCANNING, &priv->status))) {
  1603. scan_active = 1;
  1604. IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
  1605. }
  1606. if (changed & (IEEE80211_CONF_CHANGE_SMPS |
  1607. IEEE80211_CONF_CHANGE_CHANNEL)) {
  1608. /* mac80211 uses static for non-HT which is what we want */
  1609. priv->current_ht_config.smps = conf->smps_mode;
  1610. /*
  1611. * Recalculate chain counts.
  1612. *
  1613. * If monitor mode is enabled then mac80211 will
  1614. * set up the SM PS mode to OFF if an HT channel is
  1615. * configured.
  1616. */
  1617. if (priv->cfg->ops->hcmd->set_rxon_chain)
  1618. for_each_context(priv, ctx)
  1619. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  1620. }
  1621. /* during scanning mac80211 will delay channel setting until
  1622. * scan finish with changed = 0
  1623. */
  1624. if (!changed || (changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
  1625. if (scan_active)
  1626. goto set_ch_out;
  1627. ch = channel->hw_value;
  1628. ch_info = iwl_get_channel_info(priv, channel->band, ch);
  1629. if (!is_channel_valid(ch_info)) {
  1630. IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
  1631. ret = -EINVAL;
  1632. goto set_ch_out;
  1633. }
  1634. spin_lock_irqsave(&priv->lock, flags);
  1635. for_each_context(priv, ctx) {
  1636. /* Configure HT40 channels */
  1637. ctx->ht.enabled = conf_is_ht(conf);
  1638. if (ctx->ht.enabled) {
  1639. if (conf_is_ht40_minus(conf)) {
  1640. ctx->ht.extension_chan_offset =
  1641. IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  1642. ctx->ht.is_40mhz = true;
  1643. } else if (conf_is_ht40_plus(conf)) {
  1644. ctx->ht.extension_chan_offset =
  1645. IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  1646. ctx->ht.is_40mhz = true;
  1647. } else {
  1648. ctx->ht.extension_chan_offset =
  1649. IEEE80211_HT_PARAM_CHA_SEC_NONE;
  1650. ctx->ht.is_40mhz = false;
  1651. }
  1652. } else
  1653. ctx->ht.is_40mhz = false;
  1654. /*
  1655. * Default to no protection. Protection mode will
  1656. * later be set from BSS config in iwl_ht_conf
  1657. */
  1658. ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
  1659. /* if we are switching from ht to 2.4 clear flags
  1660. * from any ht related info since 2.4 does not
  1661. * support ht */
  1662. if ((le16_to_cpu(ctx->staging.channel) != ch))
  1663. ctx->staging.flags = 0;
  1664. iwl_set_rxon_channel(priv, channel, ctx);
  1665. iwl_set_rxon_ht(priv, ht_conf);
  1666. iwl_set_flags_for_band(priv, ctx, channel->band,
  1667. ctx->vif);
  1668. }
  1669. spin_unlock_irqrestore(&priv->lock, flags);
  1670. if (priv->cfg->ops->lib->update_bcast_stations)
  1671. ret = priv->cfg->ops->lib->update_bcast_stations(priv);
  1672. set_ch_out:
  1673. /* The list of supported rates and rate mask can be different
  1674. * for each band; since the band may have changed, reset
  1675. * the rate mask to what mac80211 lists */
  1676. iwl_set_rate(priv);
  1677. }
  1678. if (changed & (IEEE80211_CONF_CHANGE_PS |
  1679. IEEE80211_CONF_CHANGE_IDLE)) {
  1680. ret = iwl_power_update_mode(priv, false);
  1681. if (ret)
  1682. IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
  1683. }
  1684. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  1685. IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
  1686. priv->tx_power_user_lmt, conf->power_level);
  1687. ret = iwl_set_tx_power(priv, conf->power_level, false);
  1688. if (ret)
  1689. IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
  1690. }
  1691. if (!iwl_is_ready(priv)) {
  1692. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  1693. goto out;
  1694. }
  1695. if (scan_active)
  1696. goto out;
  1697. for_each_context(priv, ctx) {
  1698. if (memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging)))
  1699. iwlcore_commit_rxon(priv, ctx);
  1700. else
  1701. IWL_DEBUG_INFO(priv,
  1702. "Not re-sending same RXON configuration.\n");
  1703. }
  1704. out:
  1705. IWL_DEBUG_MAC80211(priv, "leave\n");
  1706. mutex_unlock(&priv->mutex);
  1707. return ret;
  1708. }
  1709. EXPORT_SYMBOL(iwl_mac_config);
  1710. void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
  1711. {
  1712. struct iwl_priv *priv = hw->priv;
  1713. unsigned long flags;
  1714. /* IBSS can only be the IWL_RXON_CTX_BSS context */
  1715. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  1716. mutex_lock(&priv->mutex);
  1717. IWL_DEBUG_MAC80211(priv, "enter\n");
  1718. spin_lock_irqsave(&priv->lock, flags);
  1719. memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_config));
  1720. spin_unlock_irqrestore(&priv->lock, flags);
  1721. spin_lock_irqsave(&priv->lock, flags);
  1722. /* new association get rid of ibss beacon skb */
  1723. if (priv->beacon_skb)
  1724. dev_kfree_skb(priv->beacon_skb);
  1725. priv->beacon_skb = NULL;
  1726. priv->timestamp = 0;
  1727. spin_unlock_irqrestore(&priv->lock, flags);
  1728. iwl_scan_cancel_timeout(priv, 100);
  1729. if (!iwl_is_ready_rf(priv)) {
  1730. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  1731. mutex_unlock(&priv->mutex);
  1732. return;
  1733. }
  1734. /* we are restarting association process
  1735. * clear RXON_FILTER_ASSOC_MSK bit
  1736. */
  1737. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1738. iwlcore_commit_rxon(priv, ctx);
  1739. iwl_set_rate(priv);
  1740. mutex_unlock(&priv->mutex);
  1741. IWL_DEBUG_MAC80211(priv, "leave\n");
  1742. }
  1743. EXPORT_SYMBOL(iwl_mac_reset_tsf);
  1744. int iwl_alloc_txq_mem(struct iwl_priv *priv)
  1745. {
  1746. if (!priv->txq)
  1747. priv->txq = kzalloc(
  1748. sizeof(struct iwl_tx_queue) *
  1749. priv->cfg->base_params->num_of_queues,
  1750. GFP_KERNEL);
  1751. if (!priv->txq) {
  1752. IWL_ERR(priv, "Not enough memory for txq\n");
  1753. return -ENOMEM;
  1754. }
  1755. return 0;
  1756. }
  1757. EXPORT_SYMBOL(iwl_alloc_txq_mem);
  1758. void iwl_free_txq_mem(struct iwl_priv *priv)
  1759. {
  1760. kfree(priv->txq);
  1761. priv->txq = NULL;
  1762. }
  1763. EXPORT_SYMBOL(iwl_free_txq_mem);
  1764. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1765. #define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES)
  1766. void iwl_reset_traffic_log(struct iwl_priv *priv)
  1767. {
  1768. priv->tx_traffic_idx = 0;
  1769. priv->rx_traffic_idx = 0;
  1770. if (priv->tx_traffic)
  1771. memset(priv->tx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
  1772. if (priv->rx_traffic)
  1773. memset(priv->rx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
  1774. }
  1775. int iwl_alloc_traffic_mem(struct iwl_priv *priv)
  1776. {
  1777. u32 traffic_size = IWL_TRAFFIC_DUMP_SIZE;
  1778. if (iwl_debug_level & IWL_DL_TX) {
  1779. if (!priv->tx_traffic) {
  1780. priv->tx_traffic =
  1781. kzalloc(traffic_size, GFP_KERNEL);
  1782. if (!priv->tx_traffic)
  1783. return -ENOMEM;
  1784. }
  1785. }
  1786. if (iwl_debug_level & IWL_DL_RX) {
  1787. if (!priv->rx_traffic) {
  1788. priv->rx_traffic =
  1789. kzalloc(traffic_size, GFP_KERNEL);
  1790. if (!priv->rx_traffic)
  1791. return -ENOMEM;
  1792. }
  1793. }
  1794. iwl_reset_traffic_log(priv);
  1795. return 0;
  1796. }
  1797. EXPORT_SYMBOL(iwl_alloc_traffic_mem);
  1798. void iwl_free_traffic_mem(struct iwl_priv *priv)
  1799. {
  1800. kfree(priv->tx_traffic);
  1801. priv->tx_traffic = NULL;
  1802. kfree(priv->rx_traffic);
  1803. priv->rx_traffic = NULL;
  1804. }
  1805. EXPORT_SYMBOL(iwl_free_traffic_mem);
  1806. void iwl_dbg_log_tx_data_frame(struct iwl_priv *priv,
  1807. u16 length, struct ieee80211_hdr *header)
  1808. {
  1809. __le16 fc;
  1810. u16 len;
  1811. if (likely(!(iwl_debug_level & IWL_DL_TX)))
  1812. return;
  1813. if (!priv->tx_traffic)
  1814. return;
  1815. fc = header->frame_control;
  1816. if (ieee80211_is_data(fc)) {
  1817. len = (length > IWL_TRAFFIC_ENTRY_SIZE)
  1818. ? IWL_TRAFFIC_ENTRY_SIZE : length;
  1819. memcpy((priv->tx_traffic +
  1820. (priv->tx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
  1821. header, len);
  1822. priv->tx_traffic_idx =
  1823. (priv->tx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
  1824. }
  1825. }
  1826. EXPORT_SYMBOL(iwl_dbg_log_tx_data_frame);
  1827. void iwl_dbg_log_rx_data_frame(struct iwl_priv *priv,
  1828. u16 length, struct ieee80211_hdr *header)
  1829. {
  1830. __le16 fc;
  1831. u16 len;
  1832. if (likely(!(iwl_debug_level & IWL_DL_RX)))
  1833. return;
  1834. if (!priv->rx_traffic)
  1835. return;
  1836. fc = header->frame_control;
  1837. if (ieee80211_is_data(fc)) {
  1838. len = (length > IWL_TRAFFIC_ENTRY_SIZE)
  1839. ? IWL_TRAFFIC_ENTRY_SIZE : length;
  1840. memcpy((priv->rx_traffic +
  1841. (priv->rx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
  1842. header, len);
  1843. priv->rx_traffic_idx =
  1844. (priv->rx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
  1845. }
  1846. }
  1847. EXPORT_SYMBOL(iwl_dbg_log_rx_data_frame);
  1848. const char *get_mgmt_string(int cmd)
  1849. {
  1850. switch (cmd) {
  1851. IWL_CMD(MANAGEMENT_ASSOC_REQ);
  1852. IWL_CMD(MANAGEMENT_ASSOC_RESP);
  1853. IWL_CMD(MANAGEMENT_REASSOC_REQ);
  1854. IWL_CMD(MANAGEMENT_REASSOC_RESP);
  1855. IWL_CMD(MANAGEMENT_PROBE_REQ);
  1856. IWL_CMD(MANAGEMENT_PROBE_RESP);
  1857. IWL_CMD(MANAGEMENT_BEACON);
  1858. IWL_CMD(MANAGEMENT_ATIM);
  1859. IWL_CMD(MANAGEMENT_DISASSOC);
  1860. IWL_CMD(MANAGEMENT_AUTH);
  1861. IWL_CMD(MANAGEMENT_DEAUTH);
  1862. IWL_CMD(MANAGEMENT_ACTION);
  1863. default:
  1864. return "UNKNOWN";
  1865. }
  1866. }
  1867. const char *get_ctrl_string(int cmd)
  1868. {
  1869. switch (cmd) {
  1870. IWL_CMD(CONTROL_BACK_REQ);
  1871. IWL_CMD(CONTROL_BACK);
  1872. IWL_CMD(CONTROL_PSPOLL);
  1873. IWL_CMD(CONTROL_RTS);
  1874. IWL_CMD(CONTROL_CTS);
  1875. IWL_CMD(CONTROL_ACK);
  1876. IWL_CMD(CONTROL_CFEND);
  1877. IWL_CMD(CONTROL_CFENDACK);
  1878. default:
  1879. return "UNKNOWN";
  1880. }
  1881. }
  1882. void iwl_clear_traffic_stats(struct iwl_priv *priv)
  1883. {
  1884. memset(&priv->tx_stats, 0, sizeof(struct traffic_stats));
  1885. memset(&priv->rx_stats, 0, sizeof(struct traffic_stats));
  1886. priv->led_tpt = 0;
  1887. }
  1888. /*
  1889. * if CONFIG_IWLWIFI_DEBUGFS defined, iwl_update_stats function will
  1890. * record all the MGMT, CTRL and DATA pkt for both TX and Rx pass.
  1891. * Use debugFs to display the rx/rx_statistics
  1892. * if CONFIG_IWLWIFI_DEBUGFS not being defined, then no MGMT and CTRL
  1893. * information will be recorded, but DATA pkt still will be recorded
  1894. * for the reason of iwl_led.c need to control the led blinking based on
  1895. * number of tx and rx data.
  1896. *
  1897. */
  1898. void iwl_update_stats(struct iwl_priv *priv, bool is_tx, __le16 fc, u16 len)
  1899. {
  1900. struct traffic_stats *stats;
  1901. if (is_tx)
  1902. stats = &priv->tx_stats;
  1903. else
  1904. stats = &priv->rx_stats;
  1905. if (ieee80211_is_mgmt(fc)) {
  1906. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  1907. case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
  1908. stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
  1909. break;
  1910. case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
  1911. stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
  1912. break;
  1913. case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
  1914. stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
  1915. break;
  1916. case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
  1917. stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
  1918. break;
  1919. case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
  1920. stats->mgmt[MANAGEMENT_PROBE_REQ]++;
  1921. break;
  1922. case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
  1923. stats->mgmt[MANAGEMENT_PROBE_RESP]++;
  1924. break;
  1925. case cpu_to_le16(IEEE80211_STYPE_BEACON):
  1926. stats->mgmt[MANAGEMENT_BEACON]++;
  1927. break;
  1928. case cpu_to_le16(IEEE80211_STYPE_ATIM):
  1929. stats->mgmt[MANAGEMENT_ATIM]++;
  1930. break;
  1931. case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
  1932. stats->mgmt[MANAGEMENT_DISASSOC]++;
  1933. break;
  1934. case cpu_to_le16(IEEE80211_STYPE_AUTH):
  1935. stats->mgmt[MANAGEMENT_AUTH]++;
  1936. break;
  1937. case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
  1938. stats->mgmt[MANAGEMENT_DEAUTH]++;
  1939. break;
  1940. case cpu_to_le16(IEEE80211_STYPE_ACTION):
  1941. stats->mgmt[MANAGEMENT_ACTION]++;
  1942. break;
  1943. }
  1944. } else if (ieee80211_is_ctl(fc)) {
  1945. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  1946. case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
  1947. stats->ctrl[CONTROL_BACK_REQ]++;
  1948. break;
  1949. case cpu_to_le16(IEEE80211_STYPE_BACK):
  1950. stats->ctrl[CONTROL_BACK]++;
  1951. break;
  1952. case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
  1953. stats->ctrl[CONTROL_PSPOLL]++;
  1954. break;
  1955. case cpu_to_le16(IEEE80211_STYPE_RTS):
  1956. stats->ctrl[CONTROL_RTS]++;
  1957. break;
  1958. case cpu_to_le16(IEEE80211_STYPE_CTS):
  1959. stats->ctrl[CONTROL_CTS]++;
  1960. break;
  1961. case cpu_to_le16(IEEE80211_STYPE_ACK):
  1962. stats->ctrl[CONTROL_ACK]++;
  1963. break;
  1964. case cpu_to_le16(IEEE80211_STYPE_CFEND):
  1965. stats->ctrl[CONTROL_CFEND]++;
  1966. break;
  1967. case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
  1968. stats->ctrl[CONTROL_CFENDACK]++;
  1969. break;
  1970. }
  1971. } else {
  1972. /* data */
  1973. stats->data_cnt++;
  1974. stats->data_bytes += len;
  1975. }
  1976. iwl_leds_background(priv);
  1977. }
  1978. EXPORT_SYMBOL(iwl_update_stats);
  1979. #endif
  1980. static void iwl_force_rf_reset(struct iwl_priv *priv)
  1981. {
  1982. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1983. return;
  1984. if (!iwl_is_any_associated(priv)) {
  1985. IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n");
  1986. return;
  1987. }
  1988. /*
  1989. * There is no easy and better way to force reset the radio,
  1990. * the only known method is switching channel which will force to
  1991. * reset and tune the radio.
  1992. * Use internal short scan (single channel) operation to should
  1993. * achieve this objective.
  1994. * Driver should reset the radio when number of consecutive missed
  1995. * beacon, or any other uCode error condition detected.
  1996. */
  1997. IWL_DEBUG_INFO(priv, "perform radio reset.\n");
  1998. iwl_internal_short_hw_scan(priv);
  1999. }
  2000. int iwl_force_reset(struct iwl_priv *priv, int mode, bool external)
  2001. {
  2002. struct iwl_force_reset *force_reset;
  2003. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2004. return -EINVAL;
  2005. if (mode >= IWL_MAX_FORCE_RESET) {
  2006. IWL_DEBUG_INFO(priv, "invalid reset request.\n");
  2007. return -EINVAL;
  2008. }
  2009. force_reset = &priv->force_reset[mode];
  2010. force_reset->reset_request_count++;
  2011. if (!external) {
  2012. if (force_reset->last_force_reset_jiffies &&
  2013. time_after(force_reset->last_force_reset_jiffies +
  2014. force_reset->reset_duration, jiffies)) {
  2015. IWL_DEBUG_INFO(priv, "force reset rejected\n");
  2016. force_reset->reset_reject_count++;
  2017. return -EAGAIN;
  2018. }
  2019. }
  2020. force_reset->reset_success_count++;
  2021. force_reset->last_force_reset_jiffies = jiffies;
  2022. IWL_DEBUG_INFO(priv, "perform force reset (%d)\n", mode);
  2023. switch (mode) {
  2024. case IWL_RF_RESET:
  2025. iwl_force_rf_reset(priv);
  2026. break;
  2027. case IWL_FW_RESET:
  2028. /*
  2029. * if the request is from external(ex: debugfs),
  2030. * then always perform the request in regardless the module
  2031. * parameter setting
  2032. * if the request is from internal (uCode error or driver
  2033. * detect failure), then fw_restart module parameter
  2034. * need to be check before performing firmware reload
  2035. */
  2036. if (!external && !priv->cfg->mod_params->restart_fw) {
  2037. IWL_DEBUG_INFO(priv, "Cancel firmware reload based on "
  2038. "module parameter setting\n");
  2039. break;
  2040. }
  2041. IWL_ERR(priv, "On demand firmware reload\n");
  2042. /* Set the FW error flag -- cleared on iwl_down */
  2043. set_bit(STATUS_FW_ERROR, &priv->status);
  2044. wake_up_interruptible(&priv->wait_command_queue);
  2045. /*
  2046. * Keep the restart process from trying to send host
  2047. * commands by clearing the INIT status bit
  2048. */
  2049. clear_bit(STATUS_READY, &priv->status);
  2050. queue_work(priv->workqueue, &priv->restart);
  2051. break;
  2052. }
  2053. return 0;
  2054. }
  2055. /**
  2056. * iwl_bg_monitor_recover - Timer callback to check for stuck queue and recover
  2057. *
  2058. * During normal condition (no queue is stuck), the timer is continually set to
  2059. * execute every monitor_recover_period milliseconds after the last timer
  2060. * expired. When the queue read_ptr is at the same place, the timer is
  2061. * shorten to 100mSecs. This is
  2062. * 1) to reduce the chance that the read_ptr may wrap around (not stuck)
  2063. * 2) to detect the stuck queues quicker before the station and AP can
  2064. * disassociate each other.
  2065. *
  2066. * This function monitors all the tx queues and recover from it if any
  2067. * of the queues are stuck.
  2068. * 1. It first check the cmd queue for stuck conditions. If it is stuck,
  2069. * it will recover by resetting the firmware and return.
  2070. * 2. Then, it checks for station association. If it associates it will check
  2071. * other queues. If any queue is stuck, it will recover by resetting
  2072. * the firmware.
  2073. * Note: It the number of times the queue read_ptr to be at the same place to
  2074. * be MAX_REPEAT+1 in order to consider to be stuck.
  2075. */
  2076. /*
  2077. * The maximum number of times the read pointer of the tx queue at the
  2078. * same place without considering to be stuck.
  2079. */
  2080. #define MAX_REPEAT (2)
  2081. static int iwl_check_stuck_queue(struct iwl_priv *priv, int cnt)
  2082. {
  2083. struct iwl_tx_queue *txq;
  2084. struct iwl_queue *q;
  2085. txq = &priv->txq[cnt];
  2086. q = &txq->q;
  2087. /* queue is empty, skip */
  2088. if (q->read_ptr == q->write_ptr)
  2089. return 0;
  2090. if (q->read_ptr == q->last_read_ptr) {
  2091. /* a queue has not been read from last time */
  2092. if (q->repeat_same_read_ptr > MAX_REPEAT) {
  2093. IWL_ERR(priv,
  2094. "queue %d stuck %d time. Fw reload.\n",
  2095. q->id, q->repeat_same_read_ptr);
  2096. q->repeat_same_read_ptr = 0;
  2097. iwl_force_reset(priv, IWL_FW_RESET, false);
  2098. } else {
  2099. q->repeat_same_read_ptr++;
  2100. IWL_DEBUG_RADIO(priv,
  2101. "queue %d, not read %d time\n",
  2102. q->id,
  2103. q->repeat_same_read_ptr);
  2104. mod_timer(&priv->monitor_recover,
  2105. jiffies + msecs_to_jiffies(
  2106. IWL_ONE_HUNDRED_MSECS));
  2107. return 1;
  2108. }
  2109. } else {
  2110. q->last_read_ptr = q->read_ptr;
  2111. q->repeat_same_read_ptr = 0;
  2112. }
  2113. return 0;
  2114. }
  2115. void iwl_bg_monitor_recover(unsigned long data)
  2116. {
  2117. struct iwl_priv *priv = (struct iwl_priv *)data;
  2118. int cnt;
  2119. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2120. return;
  2121. /* monitor and check for stuck cmd queue */
  2122. if (iwl_check_stuck_queue(priv, priv->cmd_queue))
  2123. return;
  2124. /* monitor and check for other stuck queues */
  2125. if (iwl_is_any_associated(priv)) {
  2126. for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
  2127. /* skip as we already checked the command queue */
  2128. if (cnt == priv->cmd_queue)
  2129. continue;
  2130. if (iwl_check_stuck_queue(priv, cnt))
  2131. return;
  2132. }
  2133. }
  2134. if (priv->cfg->base_params->monitor_recover_period) {
  2135. /*
  2136. * Reschedule the timer to occur in
  2137. * priv->cfg->base_params->monitor_recover_period
  2138. */
  2139. mod_timer(&priv->monitor_recover, jiffies + msecs_to_jiffies(
  2140. priv->cfg->base_params->monitor_recover_period));
  2141. }
  2142. }
  2143. EXPORT_SYMBOL(iwl_bg_monitor_recover);
  2144. /*
  2145. * extended beacon time format
  2146. * time in usec will be changed into a 32-bit value in extended:internal format
  2147. * the extended part is the beacon counts
  2148. * the internal part is the time in usec within one beacon interval
  2149. */
  2150. u32 iwl_usecs_to_beacons(struct iwl_priv *priv, u32 usec, u32 beacon_interval)
  2151. {
  2152. u32 quot;
  2153. u32 rem;
  2154. u32 interval = beacon_interval * TIME_UNIT;
  2155. if (!interval || !usec)
  2156. return 0;
  2157. quot = (usec / interval) &
  2158. (iwl_beacon_time_mask_high(priv,
  2159. priv->hw_params.beacon_time_tsf_bits) >>
  2160. priv->hw_params.beacon_time_tsf_bits);
  2161. rem = (usec % interval) & iwl_beacon_time_mask_low(priv,
  2162. priv->hw_params.beacon_time_tsf_bits);
  2163. return (quot << priv->hw_params.beacon_time_tsf_bits) + rem;
  2164. }
  2165. EXPORT_SYMBOL(iwl_usecs_to_beacons);
  2166. /* base is usually what we get from ucode with each received frame,
  2167. * the same as HW timer counter counting down
  2168. */
  2169. __le32 iwl_add_beacon_time(struct iwl_priv *priv, u32 base,
  2170. u32 addon, u32 beacon_interval)
  2171. {
  2172. u32 base_low = base & iwl_beacon_time_mask_low(priv,
  2173. priv->hw_params.beacon_time_tsf_bits);
  2174. u32 addon_low = addon & iwl_beacon_time_mask_low(priv,
  2175. priv->hw_params.beacon_time_tsf_bits);
  2176. u32 interval = beacon_interval * TIME_UNIT;
  2177. u32 res = (base & iwl_beacon_time_mask_high(priv,
  2178. priv->hw_params.beacon_time_tsf_bits)) +
  2179. (addon & iwl_beacon_time_mask_high(priv,
  2180. priv->hw_params.beacon_time_tsf_bits));
  2181. if (base_low > addon_low)
  2182. res += base_low - addon_low;
  2183. else if (base_low < addon_low) {
  2184. res += interval + base_low - addon_low;
  2185. res += (1 << priv->hw_params.beacon_time_tsf_bits);
  2186. } else
  2187. res += (1 << priv->hw_params.beacon_time_tsf_bits);
  2188. return cpu_to_le32(res);
  2189. }
  2190. EXPORT_SYMBOL(iwl_add_beacon_time);
  2191. #ifdef CONFIG_PM
  2192. int iwl_pci_suspend(struct device *device)
  2193. {
  2194. struct pci_dev *pdev = to_pci_dev(device);
  2195. struct iwl_priv *priv = pci_get_drvdata(pdev);
  2196. /*
  2197. * This function is called when system goes into suspend state
  2198. * mac80211 will call iwl_mac_stop() from the mac80211 suspend function
  2199. * first but since iwl_mac_stop() has no knowledge of who the caller is,
  2200. * it will not call apm_ops.stop() to stop the DMA operation.
  2201. * Calling apm_ops.stop here to make sure we stop the DMA.
  2202. */
  2203. iwl_apm_stop(priv);
  2204. return 0;
  2205. }
  2206. EXPORT_SYMBOL(iwl_pci_suspend);
  2207. int iwl_pci_resume(struct device *device)
  2208. {
  2209. struct pci_dev *pdev = to_pci_dev(device);
  2210. struct iwl_priv *priv = pci_get_drvdata(pdev);
  2211. bool hw_rfkill = false;
  2212. /*
  2213. * We disable the RETRY_TIMEOUT register (0x41) to keep
  2214. * PCI Tx retries from interfering with C3 CPU state.
  2215. */
  2216. pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
  2217. iwl_enable_interrupts(priv);
  2218. if (!(iwl_read32(priv, CSR_GP_CNTRL) &
  2219. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  2220. hw_rfkill = true;
  2221. if (hw_rfkill)
  2222. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2223. else
  2224. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2225. wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rfkill);
  2226. return 0;
  2227. }
  2228. EXPORT_SYMBOL(iwl_pci_resume);
  2229. const struct dev_pm_ops iwl_pm_ops = {
  2230. .suspend = iwl_pci_suspend,
  2231. .resume = iwl_pci_resume,
  2232. .freeze = iwl_pci_suspend,
  2233. .thaw = iwl_pci_resume,
  2234. .poweroff = iwl_pci_suspend,
  2235. .restore = iwl_pci_resume,
  2236. };
  2237. EXPORT_SYMBOL(iwl_pm_ops);
  2238. #endif /* CONFIG_PM */