iwl-core.c 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643
  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. /**
  427. * iwl_check_rxon_cmd - validate RXON structure is valid
  428. *
  429. * NOTE: This is really only useful during development and can eventually
  430. * be #ifdef'd out once the driver is stable and folks aren't actively
  431. * making changes
  432. */
  433. int iwl_check_rxon_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  434. {
  435. int error = 0;
  436. int counter = 1;
  437. struct iwl_rxon_cmd *rxon = &ctx->staging;
  438. if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
  439. error |= le32_to_cpu(rxon->flags &
  440. (RXON_FLG_TGJ_NARROW_BAND_MSK |
  441. RXON_FLG_RADAR_DETECT_MSK));
  442. if (error)
  443. IWL_WARN(priv, "check 24G fields %d | %d\n",
  444. counter++, error);
  445. } else {
  446. error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
  447. 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
  448. if (error)
  449. IWL_WARN(priv, "check 52 fields %d | %d\n",
  450. counter++, error);
  451. error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
  452. if (error)
  453. IWL_WARN(priv, "check 52 CCK %d | %d\n",
  454. counter++, error);
  455. }
  456. error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
  457. if (error)
  458. IWL_WARN(priv, "check mac addr %d | %d\n", counter++, error);
  459. /* make sure basic rates 6Mbps and 1Mbps are supported */
  460. error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
  461. ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
  462. if (error)
  463. IWL_WARN(priv, "check basic rate %d | %d\n", counter++, error);
  464. error |= (le16_to_cpu(rxon->assoc_id) > 2007);
  465. if (error)
  466. IWL_WARN(priv, "check assoc id %d | %d\n", counter++, error);
  467. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
  468. == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
  469. if (error)
  470. IWL_WARN(priv, "check CCK and short slot %d | %d\n",
  471. counter++, error);
  472. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
  473. == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
  474. if (error)
  475. IWL_WARN(priv, "check CCK & auto detect %d | %d\n",
  476. counter++, error);
  477. error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
  478. RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
  479. if (error)
  480. IWL_WARN(priv, "check TGG and auto detect %d | %d\n",
  481. counter++, error);
  482. if (error)
  483. IWL_WARN(priv, "Tuning to channel %d\n",
  484. le16_to_cpu(rxon->channel));
  485. if (error) {
  486. IWL_ERR(priv, "Not a valid iwl_rxon_assoc_cmd field values\n");
  487. return -1;
  488. }
  489. return 0;
  490. }
  491. EXPORT_SYMBOL(iwl_check_rxon_cmd);
  492. /**
  493. * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
  494. * @priv: staging_rxon is compared to active_rxon
  495. *
  496. * If the RXON structure is changing enough to require a new tune,
  497. * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
  498. * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
  499. */
  500. int iwl_full_rxon_required(struct iwl_priv *priv,
  501. struct iwl_rxon_context *ctx)
  502. {
  503. const struct iwl_rxon_cmd *staging = &ctx->staging;
  504. const struct iwl_rxon_cmd *active = &ctx->active;
  505. #define CHK(cond) \
  506. if ((cond)) { \
  507. IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
  508. return 1; \
  509. }
  510. #define CHK_NEQ(c1, c2) \
  511. if ((c1) != (c2)) { \
  512. IWL_DEBUG_INFO(priv, "need full RXON - " \
  513. #c1 " != " #c2 " - %d != %d\n", \
  514. (c1), (c2)); \
  515. return 1; \
  516. }
  517. /* These items are only settable from the full RXON command */
  518. CHK(!iwl_is_associated_ctx(ctx));
  519. CHK(compare_ether_addr(staging->bssid_addr, active->bssid_addr));
  520. CHK(compare_ether_addr(staging->node_addr, active->node_addr));
  521. CHK(compare_ether_addr(staging->wlap_bssid_addr,
  522. active->wlap_bssid_addr));
  523. CHK_NEQ(staging->dev_type, active->dev_type);
  524. CHK_NEQ(staging->channel, active->channel);
  525. CHK_NEQ(staging->air_propagation, active->air_propagation);
  526. CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates,
  527. active->ofdm_ht_single_stream_basic_rates);
  528. CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates,
  529. active->ofdm_ht_dual_stream_basic_rates);
  530. CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates,
  531. active->ofdm_ht_triple_stream_basic_rates);
  532. CHK_NEQ(staging->assoc_id, active->assoc_id);
  533. /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
  534. * be updated with the RXON_ASSOC command -- however only some
  535. * flag transitions are allowed using RXON_ASSOC */
  536. /* Check if we are not switching bands */
  537. CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK,
  538. active->flags & RXON_FLG_BAND_24G_MSK);
  539. /* Check if we are switching association toggle */
  540. CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK,
  541. active->filter_flags & RXON_FILTER_ASSOC_MSK);
  542. #undef CHK
  543. #undef CHK_NEQ
  544. return 0;
  545. }
  546. EXPORT_SYMBOL(iwl_full_rxon_required);
  547. u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv,
  548. struct iwl_rxon_context *ctx)
  549. {
  550. /*
  551. * Assign the lowest rate -- should really get this from
  552. * the beacon skb from mac80211.
  553. */
  554. if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK)
  555. return IWL_RATE_1M_PLCP;
  556. else
  557. return IWL_RATE_6M_PLCP;
  558. }
  559. EXPORT_SYMBOL(iwl_rate_get_lowest_plcp);
  560. static void _iwl_set_rxon_ht(struct iwl_priv *priv,
  561. struct iwl_ht_config *ht_conf,
  562. struct iwl_rxon_context *ctx)
  563. {
  564. struct iwl_rxon_cmd *rxon = &ctx->staging;
  565. if (!ctx->ht.enabled) {
  566. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
  567. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
  568. RXON_FLG_HT40_PROT_MSK |
  569. RXON_FLG_HT_PROT_MSK);
  570. return;
  571. }
  572. /* FIXME: if the definition of ht.protection changed, the "translation"
  573. * will be needed for rxon->flags
  574. */
  575. rxon->flags |= cpu_to_le32(ctx->ht.protection << RXON_FLG_HT_OPERATING_MODE_POS);
  576. /* Set up channel bandwidth:
  577. * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
  578. /* clear the HT channel mode before set the mode */
  579. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
  580. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  581. if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) {
  582. /* pure ht40 */
  583. if (ctx->ht.protection == IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
  584. rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
  585. /* Note: control channel is opposite of extension channel */
  586. switch (ctx->ht.extension_chan_offset) {
  587. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  588. rxon->flags &= ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  589. break;
  590. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  591. rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  592. break;
  593. }
  594. } else {
  595. /* Note: control channel is opposite of extension channel */
  596. switch (ctx->ht.extension_chan_offset) {
  597. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  598. rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  599. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
  600. break;
  601. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  602. rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  603. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
  604. break;
  605. case IEEE80211_HT_PARAM_CHA_SEC_NONE:
  606. default:
  607. /* channel location only valid if in Mixed mode */
  608. IWL_ERR(priv, "invalid extension channel offset\n");
  609. break;
  610. }
  611. }
  612. } else {
  613. rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
  614. }
  615. if (priv->cfg->ops->hcmd->set_rxon_chain)
  616. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  617. IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
  618. "extension channel offset 0x%x\n",
  619. le32_to_cpu(rxon->flags), ctx->ht.protection,
  620. ctx->ht.extension_chan_offset);
  621. }
  622. void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
  623. {
  624. struct iwl_rxon_context *ctx;
  625. for_each_context(priv, ctx)
  626. _iwl_set_rxon_ht(priv, ht_conf, ctx);
  627. }
  628. EXPORT_SYMBOL(iwl_set_rxon_ht);
  629. /* Return valid, unused, channel for a passive scan to reset the RF */
  630. u8 iwl_get_single_channel_number(struct iwl_priv *priv,
  631. enum ieee80211_band band)
  632. {
  633. const struct iwl_channel_info *ch_info;
  634. int i;
  635. u8 channel = 0;
  636. u8 min, max;
  637. struct iwl_rxon_context *ctx;
  638. if (band == IEEE80211_BAND_5GHZ) {
  639. min = 14;
  640. max = priv->channel_count;
  641. } else {
  642. min = 0;
  643. max = 14;
  644. }
  645. for (i = min; i < max; i++) {
  646. bool busy = false;
  647. for_each_context(priv, ctx) {
  648. busy = priv->channel_info[i].channel ==
  649. le16_to_cpu(ctx->staging.channel);
  650. if (busy)
  651. break;
  652. }
  653. if (busy)
  654. continue;
  655. channel = priv->channel_info[i].channel;
  656. ch_info = iwl_get_channel_info(priv, band, channel);
  657. if (is_channel_valid(ch_info))
  658. break;
  659. }
  660. return channel;
  661. }
  662. EXPORT_SYMBOL(iwl_get_single_channel_number);
  663. /**
  664. * iwl_set_rxon_channel - Set the band and channel values in staging RXON
  665. * @ch: requested channel as a pointer to struct ieee80211_channel
  666. * NOTE: Does not commit to the hardware; it sets appropriate bit fields
  667. * in the staging RXON flag structure based on the ch->band
  668. */
  669. int iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
  670. struct iwl_rxon_context *ctx)
  671. {
  672. enum ieee80211_band band = ch->band;
  673. u16 channel = ch->hw_value;
  674. if ((le16_to_cpu(ctx->staging.channel) == channel) &&
  675. (priv->band == band))
  676. return 0;
  677. ctx->staging.channel = cpu_to_le16(channel);
  678. if (band == IEEE80211_BAND_5GHZ)
  679. ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK;
  680. else
  681. ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
  682. priv->band = band;
  683. IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
  684. return 0;
  685. }
  686. EXPORT_SYMBOL(iwl_set_rxon_channel);
  687. void iwl_set_flags_for_band(struct iwl_priv *priv,
  688. struct iwl_rxon_context *ctx,
  689. enum ieee80211_band band,
  690. struct ieee80211_vif *vif)
  691. {
  692. if (band == IEEE80211_BAND_5GHZ) {
  693. ctx->staging.flags &=
  694. ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
  695. | RXON_FLG_CCK_MSK);
  696. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  697. } else {
  698. /* Copied from iwl_post_associate() */
  699. if (vif && vif->bss_conf.use_short_slot)
  700. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  701. else
  702. ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  703. ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
  704. ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK;
  705. ctx->staging.flags &= ~RXON_FLG_CCK_MSK;
  706. }
  707. }
  708. EXPORT_SYMBOL(iwl_set_flags_for_band);
  709. /*
  710. * initialize rxon structure with default values from eeprom
  711. */
  712. void iwl_connection_init_rx_config(struct iwl_priv *priv,
  713. struct iwl_rxon_context *ctx)
  714. {
  715. const struct iwl_channel_info *ch_info;
  716. memset(&ctx->staging, 0, sizeof(ctx->staging));
  717. if (!ctx->vif) {
  718. ctx->staging.dev_type = ctx->unused_devtype;
  719. } else switch (ctx->vif->type) {
  720. case NL80211_IFTYPE_AP:
  721. ctx->staging.dev_type = ctx->ap_devtype;
  722. break;
  723. case NL80211_IFTYPE_STATION:
  724. ctx->staging.dev_type = ctx->station_devtype;
  725. ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
  726. break;
  727. case NL80211_IFTYPE_ADHOC:
  728. ctx->staging.dev_type = ctx->ibss_devtype;
  729. ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
  730. ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
  731. RXON_FILTER_ACCEPT_GRP_MSK;
  732. break;
  733. default:
  734. IWL_ERR(priv, "Unsupported interface type %d\n",
  735. ctx->vif->type);
  736. break;
  737. }
  738. #if 0
  739. /* TODO: Figure out when short_preamble would be set and cache from
  740. * that */
  741. if (!hw_to_local(priv->hw)->short_preamble)
  742. ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  743. else
  744. ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  745. #endif
  746. ch_info = iwl_get_channel_info(priv, priv->band,
  747. le16_to_cpu(ctx->active.channel));
  748. if (!ch_info)
  749. ch_info = &priv->channel_info[0];
  750. ctx->staging.channel = cpu_to_le16(ch_info->channel);
  751. priv->band = ch_info->band;
  752. iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif);
  753. ctx->staging.ofdm_basic_rates =
  754. (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  755. ctx->staging.cck_basic_rates =
  756. (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  757. /* clear both MIX and PURE40 mode flag */
  758. ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
  759. RXON_FLG_CHANNEL_MODE_PURE_40);
  760. if (ctx->vif)
  761. memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN);
  762. ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff;
  763. ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff;
  764. ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff;
  765. }
  766. EXPORT_SYMBOL(iwl_connection_init_rx_config);
  767. void iwl_set_rate(struct iwl_priv *priv)
  768. {
  769. const struct ieee80211_supported_band *hw = NULL;
  770. struct ieee80211_rate *rate;
  771. struct iwl_rxon_context *ctx;
  772. int i;
  773. hw = iwl_get_hw_mode(priv, priv->band);
  774. if (!hw) {
  775. IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
  776. return;
  777. }
  778. priv->active_rate = 0;
  779. for (i = 0; i < hw->n_bitrates; i++) {
  780. rate = &(hw->bitrates[i]);
  781. if (rate->hw_value < IWL_RATE_COUNT_LEGACY)
  782. priv->active_rate |= (1 << rate->hw_value);
  783. }
  784. IWL_DEBUG_RATE(priv, "Set active_rate = %0x\n", priv->active_rate);
  785. for_each_context(priv, ctx) {
  786. ctx->staging.cck_basic_rates =
  787. (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  788. ctx->staging.ofdm_basic_rates =
  789. (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  790. }
  791. }
  792. EXPORT_SYMBOL(iwl_set_rate);
  793. void iwl_chswitch_done(struct iwl_priv *priv, bool is_success)
  794. {
  795. /*
  796. * MULTI-FIXME
  797. * See iwl_mac_channel_switch.
  798. */
  799. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  800. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  801. return;
  802. if (priv->switch_rxon.switch_in_progress) {
  803. ieee80211_chswitch_done(ctx->vif, is_success);
  804. mutex_lock(&priv->mutex);
  805. priv->switch_rxon.switch_in_progress = false;
  806. mutex_unlock(&priv->mutex);
  807. }
  808. }
  809. EXPORT_SYMBOL(iwl_chswitch_done);
  810. void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
  811. {
  812. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  813. struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
  814. /*
  815. * MULTI-FIXME
  816. * See iwl_mac_channel_switch.
  817. */
  818. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  819. struct iwl_rxon_cmd *rxon = (void *)&ctx->active;
  820. if (priv->switch_rxon.switch_in_progress) {
  821. if (!le32_to_cpu(csa->status) &&
  822. (csa->channel == priv->switch_rxon.channel)) {
  823. rxon->channel = csa->channel;
  824. ctx->staging.channel = csa->channel;
  825. IWL_DEBUG_11H(priv, "CSA notif: channel %d\n",
  826. le16_to_cpu(csa->channel));
  827. iwl_chswitch_done(priv, true);
  828. } else {
  829. IWL_ERR(priv, "CSA notif (fail) : channel %d\n",
  830. le16_to_cpu(csa->channel));
  831. iwl_chswitch_done(priv, false);
  832. }
  833. }
  834. }
  835. EXPORT_SYMBOL(iwl_rx_csa);
  836. #ifdef CONFIG_IWLWIFI_DEBUG
  837. void iwl_print_rx_config_cmd(struct iwl_priv *priv,
  838. struct iwl_rxon_context *ctx)
  839. {
  840. struct iwl_rxon_cmd *rxon = &ctx->staging;
  841. IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
  842. iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
  843. IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
  844. IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
  845. IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
  846. le32_to_cpu(rxon->filter_flags));
  847. IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
  848. IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
  849. rxon->ofdm_basic_rates);
  850. IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
  851. IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
  852. IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
  853. IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
  854. }
  855. EXPORT_SYMBOL(iwl_print_rx_config_cmd);
  856. #endif
  857. /**
  858. * iwl_irq_handle_error - called for HW or SW error interrupt from card
  859. */
  860. void iwl_irq_handle_error(struct iwl_priv *priv)
  861. {
  862. /* Set the FW error flag -- cleared on iwl_down */
  863. set_bit(STATUS_FW_ERROR, &priv->status);
  864. /* Cancel currently queued command. */
  865. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  866. IWL_ERR(priv, "Loaded firmware version: %s\n",
  867. priv->hw->wiphy->fw_version);
  868. priv->cfg->ops->lib->dump_nic_error_log(priv);
  869. if (priv->cfg->ops->lib->dump_csr)
  870. priv->cfg->ops->lib->dump_csr(priv);
  871. if (priv->cfg->ops->lib->dump_fh)
  872. priv->cfg->ops->lib->dump_fh(priv, NULL, false);
  873. priv->cfg->ops->lib->dump_nic_event_log(priv, false, NULL, false);
  874. #ifdef CONFIG_IWLWIFI_DEBUG
  875. if (iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS)
  876. iwl_print_rx_config_cmd(priv,
  877. &priv->contexts[IWL_RXON_CTX_BSS]);
  878. #endif
  879. wake_up_interruptible(&priv->wait_command_queue);
  880. /* Keep the restart process from trying to send host
  881. * commands by clearing the INIT status bit */
  882. clear_bit(STATUS_READY, &priv->status);
  883. if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  884. IWL_DEBUG(priv, IWL_DL_FW_ERRORS,
  885. "Restarting adapter due to uCode error.\n");
  886. if (priv->cfg->mod_params->restart_fw)
  887. queue_work(priv->workqueue, &priv->restart);
  888. }
  889. }
  890. EXPORT_SYMBOL(iwl_irq_handle_error);
  891. static int iwl_apm_stop_master(struct iwl_priv *priv)
  892. {
  893. int ret = 0;
  894. /* stop device's busmaster DMA activity */
  895. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
  896. ret = iwl_poll_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_MASTER_DISABLED,
  897. CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
  898. if (ret)
  899. IWL_WARN(priv, "Master Disable Timed Out, 100 usec\n");
  900. IWL_DEBUG_INFO(priv, "stop master\n");
  901. return ret;
  902. }
  903. void iwl_apm_stop(struct iwl_priv *priv)
  904. {
  905. IWL_DEBUG_INFO(priv, "Stop card, put in low power state\n");
  906. /* Stop device's DMA activity */
  907. iwl_apm_stop_master(priv);
  908. /* Reset the entire device */
  909. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  910. udelay(10);
  911. /*
  912. * Clear "initialization complete" bit to move adapter from
  913. * D0A* (powered-up Active) --> D0U* (Uninitialized) state.
  914. */
  915. iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  916. }
  917. EXPORT_SYMBOL(iwl_apm_stop);
  918. /*
  919. * Start up NIC's basic functionality after it has been reset
  920. * (e.g. after platform boot, or shutdown via iwl_apm_stop())
  921. * NOTE: This does not load uCode nor start the embedded processor
  922. */
  923. int iwl_apm_init(struct iwl_priv *priv)
  924. {
  925. int ret = 0;
  926. u16 lctl;
  927. IWL_DEBUG_INFO(priv, "Init card's basic functions\n");
  928. /*
  929. * Use "set_bit" below rather than "write", to preserve any hardware
  930. * bits already set by default after reset.
  931. */
  932. /* Disable L0S exit timer (platform NMI Work/Around) */
  933. iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  934. CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
  935. /*
  936. * Disable L0s without affecting L1;
  937. * don't wait for ICH L0s (ICH bug W/A)
  938. */
  939. iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  940. CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
  941. /* Set FH wait threshold to maximum (HW error during stress W/A) */
  942. iwl_set_bit(priv, CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL);
  943. /*
  944. * Enable HAP INTA (interrupt from management bus) to
  945. * wake device's PCI Express link L1a -> L0s
  946. * NOTE: This is no-op for 3945 (non-existant bit)
  947. */
  948. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  949. CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A);
  950. /*
  951. * HW bug W/A for instability in PCIe bus L0->L0S->L1 transition.
  952. * Check if BIOS (or OS) enabled L1-ASPM on this device.
  953. * If so (likely), disable L0S, so device moves directly L0->L1;
  954. * costs negligible amount of power savings.
  955. * If not (unlikely), enable L0S, so there is at least some
  956. * power savings, even without L1.
  957. */
  958. if (priv->cfg->base_params->set_l0s) {
  959. lctl = iwl_pcie_link_ctl(priv);
  960. if ((lctl & PCI_CFG_LINK_CTRL_VAL_L1_EN) ==
  961. PCI_CFG_LINK_CTRL_VAL_L1_EN) {
  962. /* L1-ASPM enabled; disable(!) L0S */
  963. iwl_set_bit(priv, CSR_GIO_REG,
  964. CSR_GIO_REG_VAL_L0S_ENABLED);
  965. IWL_DEBUG_POWER(priv, "L1 Enabled; Disabling L0S\n");
  966. } else {
  967. /* L1-ASPM disabled; enable(!) L0S */
  968. iwl_clear_bit(priv, CSR_GIO_REG,
  969. CSR_GIO_REG_VAL_L0S_ENABLED);
  970. IWL_DEBUG_POWER(priv, "L1 Disabled; Enabling L0S\n");
  971. }
  972. }
  973. /* Configure analog phase-lock-loop before activating to D0A */
  974. if (priv->cfg->base_params->pll_cfg_val)
  975. iwl_set_bit(priv, CSR_ANA_PLL_CFG,
  976. priv->cfg->base_params->pll_cfg_val);
  977. /*
  978. * Set "initialization complete" bit to move adapter from
  979. * D0U* --> D0A* (powered-up active) state.
  980. */
  981. iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  982. /*
  983. * Wait for clock stabilization; once stabilized, access to
  984. * device-internal resources is supported, e.g. iwl_write_prph()
  985. * and accesses to uCode SRAM.
  986. */
  987. ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
  988. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  989. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  990. if (ret < 0) {
  991. IWL_DEBUG_INFO(priv, "Failed to init the card\n");
  992. goto out;
  993. }
  994. /*
  995. * Enable DMA and BSM (if used) clocks, wait for them to stabilize.
  996. * BSM (Boostrap State Machine) is only in 3945 and 4965;
  997. * later devices (i.e. 5000 and later) have non-volatile SRAM,
  998. * and don't need BSM to restore data after power-saving sleep.
  999. *
  1000. * Write to "CLK_EN_REG"; "1" bits enable clocks, while "0" bits
  1001. * do not disable clocks. This preserves any hardware bits already
  1002. * set by default in "CLK_CTRL_REG" after reset.
  1003. */
  1004. if (priv->cfg->base_params->use_bsm)
  1005. iwl_write_prph(priv, APMG_CLK_EN_REG,
  1006. APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT);
  1007. else
  1008. iwl_write_prph(priv, APMG_CLK_EN_REG,
  1009. APMG_CLK_VAL_DMA_CLK_RQT);
  1010. udelay(20);
  1011. /* Disable L1-Active */
  1012. iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
  1013. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  1014. out:
  1015. return ret;
  1016. }
  1017. EXPORT_SYMBOL(iwl_apm_init);
  1018. int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
  1019. {
  1020. int ret = 0;
  1021. s8 prev_tx_power = priv->tx_power_user_lmt;
  1022. if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) {
  1023. IWL_WARN(priv,
  1024. "Requested user TXPOWER %d below lower limit %d.\n",
  1025. tx_power,
  1026. IWLAGN_TX_POWER_TARGET_POWER_MIN);
  1027. return -EINVAL;
  1028. }
  1029. if (tx_power > priv->tx_power_device_lmt) {
  1030. IWL_WARN(priv,
  1031. "Requested user TXPOWER %d above upper limit %d.\n",
  1032. tx_power, priv->tx_power_device_lmt);
  1033. return -EINVAL;
  1034. }
  1035. if (priv->tx_power_user_lmt != tx_power)
  1036. force = true;
  1037. /* if nic is not up don't send command */
  1038. if (iwl_is_ready_rf(priv)) {
  1039. priv->tx_power_user_lmt = tx_power;
  1040. if (force && priv->cfg->ops->lib->send_tx_power)
  1041. ret = priv->cfg->ops->lib->send_tx_power(priv);
  1042. else if (!priv->cfg->ops->lib->send_tx_power)
  1043. ret = -EOPNOTSUPP;
  1044. /*
  1045. * if fail to set tx_power, restore the orig. tx power
  1046. */
  1047. if (ret)
  1048. priv->tx_power_user_lmt = prev_tx_power;
  1049. }
  1050. /*
  1051. * Even this is an async host command, the command
  1052. * will always report success from uCode
  1053. * So once driver can placing the command into the queue
  1054. * successfully, driver can use priv->tx_power_user_lmt
  1055. * to reflect the current tx power
  1056. */
  1057. return ret;
  1058. }
  1059. EXPORT_SYMBOL(iwl_set_tx_power);
  1060. irqreturn_t iwl_isr_legacy(int irq, void *data)
  1061. {
  1062. struct iwl_priv *priv = data;
  1063. u32 inta, inta_mask;
  1064. u32 inta_fh;
  1065. unsigned long flags;
  1066. if (!priv)
  1067. return IRQ_NONE;
  1068. spin_lock_irqsave(&priv->lock, flags);
  1069. /* Disable (but don't clear!) interrupts here to avoid
  1070. * back-to-back ISRs and sporadic interrupts from our NIC.
  1071. * If we have something to service, the tasklet will re-enable ints.
  1072. * If we *don't* have something, we'll re-enable before leaving here. */
  1073. inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
  1074. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  1075. /* Discover which interrupts are active/pending */
  1076. inta = iwl_read32(priv, CSR_INT);
  1077. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  1078. /* Ignore interrupt if there's nothing in NIC to service.
  1079. * This may be due to IRQ shared with another device,
  1080. * or due to sporadic interrupts thrown from our NIC. */
  1081. if (!inta && !inta_fh) {
  1082. IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0, inta_fh == 0\n");
  1083. goto none;
  1084. }
  1085. if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
  1086. /* Hardware disappeared. It might have already raised
  1087. * an interrupt */
  1088. IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
  1089. goto unplugged;
  1090. }
  1091. IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  1092. inta, inta_mask, inta_fh);
  1093. inta &= ~CSR_INT_BIT_SCD;
  1094. /* iwl_irq_tasklet() will service interrupts and re-enable them */
  1095. if (likely(inta || inta_fh))
  1096. tasklet_schedule(&priv->irq_tasklet);
  1097. unplugged:
  1098. spin_unlock_irqrestore(&priv->lock, flags);
  1099. return IRQ_HANDLED;
  1100. none:
  1101. /* re-enable interrupts here since we don't have anything to service. */
  1102. /* only Re-enable if diabled by irq */
  1103. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  1104. iwl_enable_interrupts(priv);
  1105. spin_unlock_irqrestore(&priv->lock, flags);
  1106. return IRQ_NONE;
  1107. }
  1108. EXPORT_SYMBOL(iwl_isr_legacy);
  1109. void iwl_send_bt_config(struct iwl_priv *priv)
  1110. {
  1111. struct iwl_bt_cmd bt_cmd = {
  1112. .lead_time = BT_LEAD_TIME_DEF,
  1113. .max_kill = BT_MAX_KILL_DEF,
  1114. .kill_ack_mask = 0,
  1115. .kill_cts_mask = 0,
  1116. };
  1117. if (!bt_coex_active)
  1118. bt_cmd.flags = BT_COEX_DISABLE;
  1119. else
  1120. bt_cmd.flags = BT_COEX_ENABLE;
  1121. IWL_DEBUG_INFO(priv, "BT coex %s\n",
  1122. (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
  1123. if (iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  1124. sizeof(struct iwl_bt_cmd), &bt_cmd))
  1125. IWL_ERR(priv, "failed to send BT Coex Config\n");
  1126. }
  1127. EXPORT_SYMBOL(iwl_send_bt_config);
  1128. int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
  1129. {
  1130. struct iwl_statistics_cmd statistics_cmd = {
  1131. .configuration_flags =
  1132. clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
  1133. };
  1134. if (flags & CMD_ASYNC)
  1135. return iwl_send_cmd_pdu_async(priv, REPLY_STATISTICS_CMD,
  1136. sizeof(struct iwl_statistics_cmd),
  1137. &statistics_cmd, NULL);
  1138. else
  1139. return iwl_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
  1140. sizeof(struct iwl_statistics_cmd),
  1141. &statistics_cmd);
  1142. }
  1143. EXPORT_SYMBOL(iwl_send_statistics_request);
  1144. void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
  1145. struct iwl_rx_mem_buffer *rxb)
  1146. {
  1147. #ifdef CONFIG_IWLWIFI_DEBUG
  1148. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1149. struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
  1150. IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
  1151. sleep->pm_sleep_mode, sleep->pm_wakeup_src);
  1152. #endif
  1153. }
  1154. EXPORT_SYMBOL(iwl_rx_pm_sleep_notif);
  1155. void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
  1156. struct iwl_rx_mem_buffer *rxb)
  1157. {
  1158. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1159. u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  1160. IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
  1161. "notification for %s:\n", len,
  1162. get_cmd_string(pkt->hdr.cmd));
  1163. iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, len);
  1164. }
  1165. EXPORT_SYMBOL(iwl_rx_pm_debug_statistics_notif);
  1166. void iwl_rx_reply_error(struct iwl_priv *priv,
  1167. struct iwl_rx_mem_buffer *rxb)
  1168. {
  1169. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1170. IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
  1171. "seq 0x%04X ser 0x%08X\n",
  1172. le32_to_cpu(pkt->u.err_resp.error_type),
  1173. get_cmd_string(pkt->u.err_resp.cmd_id),
  1174. pkt->u.err_resp.cmd_id,
  1175. le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
  1176. le32_to_cpu(pkt->u.err_resp.error_info));
  1177. }
  1178. EXPORT_SYMBOL(iwl_rx_reply_error);
  1179. void iwl_clear_isr_stats(struct iwl_priv *priv)
  1180. {
  1181. memset(&priv->isr_stats, 0, sizeof(priv->isr_stats));
  1182. }
  1183. int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  1184. const struct ieee80211_tx_queue_params *params)
  1185. {
  1186. struct iwl_priv *priv = hw->priv;
  1187. struct iwl_rxon_context *ctx;
  1188. unsigned long flags;
  1189. int q;
  1190. IWL_DEBUG_MAC80211(priv, "enter\n");
  1191. if (!iwl_is_ready_rf(priv)) {
  1192. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  1193. return -EIO;
  1194. }
  1195. if (queue >= AC_NUM) {
  1196. IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
  1197. return 0;
  1198. }
  1199. q = AC_NUM - 1 - queue;
  1200. spin_lock_irqsave(&priv->lock, flags);
  1201. /*
  1202. * MULTI-FIXME
  1203. * This may need to be done per interface in nl80211/cfg80211/mac80211.
  1204. */
  1205. for_each_context(priv, ctx) {
  1206. ctx->qos_data.def_qos_parm.ac[q].cw_min =
  1207. cpu_to_le16(params->cw_min);
  1208. ctx->qos_data.def_qos_parm.ac[q].cw_max =
  1209. cpu_to_le16(params->cw_max);
  1210. ctx->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
  1211. ctx->qos_data.def_qos_parm.ac[q].edca_txop =
  1212. cpu_to_le16((params->txop * 32));
  1213. ctx->qos_data.def_qos_parm.ac[q].reserved1 = 0;
  1214. }
  1215. spin_unlock_irqrestore(&priv->lock, flags);
  1216. IWL_DEBUG_MAC80211(priv, "leave\n");
  1217. return 0;
  1218. }
  1219. EXPORT_SYMBOL(iwl_mac_conf_tx);
  1220. int iwl_mac_tx_last_beacon(struct ieee80211_hw *hw)
  1221. {
  1222. struct iwl_priv *priv = hw->priv;
  1223. return priv->ibss_manager == IWL_IBSS_MANAGER;
  1224. }
  1225. EXPORT_SYMBOL_GPL(iwl_mac_tx_last_beacon);
  1226. static void iwl_ht_conf(struct iwl_priv *priv,
  1227. struct ieee80211_vif *vif)
  1228. {
  1229. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  1230. struct ieee80211_sta *sta;
  1231. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1232. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1233. IWL_DEBUG_MAC80211(priv, "enter:\n");
  1234. if (!ctx->ht.enabled)
  1235. return;
  1236. ctx->ht.protection =
  1237. bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION;
  1238. ctx->ht.non_gf_sta_present =
  1239. !!(bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
  1240. ht_conf->single_chain_sufficient = false;
  1241. switch (vif->type) {
  1242. case NL80211_IFTYPE_STATION:
  1243. rcu_read_lock();
  1244. sta = ieee80211_find_sta(vif, bss_conf->bssid);
  1245. if (sta) {
  1246. struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
  1247. int maxstreams;
  1248. maxstreams = (ht_cap->mcs.tx_params &
  1249. IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
  1250. >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
  1251. maxstreams += 1;
  1252. if ((ht_cap->mcs.rx_mask[1] == 0) &&
  1253. (ht_cap->mcs.rx_mask[2] == 0))
  1254. ht_conf->single_chain_sufficient = true;
  1255. if (maxstreams <= 1)
  1256. ht_conf->single_chain_sufficient = true;
  1257. } else {
  1258. /*
  1259. * If at all, this can only happen through a race
  1260. * when the AP disconnects us while we're still
  1261. * setting up the connection, in that case mac80211
  1262. * will soon tell us about that.
  1263. */
  1264. ht_conf->single_chain_sufficient = true;
  1265. }
  1266. rcu_read_unlock();
  1267. break;
  1268. case NL80211_IFTYPE_ADHOC:
  1269. ht_conf->single_chain_sufficient = true;
  1270. break;
  1271. default:
  1272. break;
  1273. }
  1274. IWL_DEBUG_MAC80211(priv, "leave\n");
  1275. }
  1276. static inline void iwl_set_no_assoc(struct iwl_priv *priv,
  1277. struct ieee80211_vif *vif)
  1278. {
  1279. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1280. iwl_led_disassociate(priv);
  1281. /*
  1282. * inform the ucode that there is no longer an
  1283. * association and that no more packets should be
  1284. * sent
  1285. */
  1286. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1287. ctx->staging.assoc_id = 0;
  1288. iwlcore_commit_rxon(priv, ctx);
  1289. }
  1290. static void iwlcore_beacon_update(struct ieee80211_hw *hw,
  1291. struct ieee80211_vif *vif)
  1292. {
  1293. struct iwl_priv *priv = hw->priv;
  1294. unsigned long flags;
  1295. __le64 timestamp;
  1296. struct sk_buff *skb = ieee80211_beacon_get(hw, vif);
  1297. if (!skb)
  1298. return;
  1299. IWL_DEBUG_ASSOC(priv, "enter\n");
  1300. lockdep_assert_held(&priv->mutex);
  1301. if (!priv->beacon_ctx) {
  1302. IWL_ERR(priv, "update beacon but no beacon context!\n");
  1303. dev_kfree_skb(skb);
  1304. return;
  1305. }
  1306. spin_lock_irqsave(&priv->lock, flags);
  1307. if (priv->beacon_skb)
  1308. dev_kfree_skb(priv->beacon_skb);
  1309. priv->beacon_skb = skb;
  1310. timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
  1311. priv->timestamp = le64_to_cpu(timestamp);
  1312. IWL_DEBUG_ASSOC(priv, "leave\n");
  1313. spin_unlock_irqrestore(&priv->lock, flags);
  1314. if (!iwl_is_ready_rf(priv)) {
  1315. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  1316. return;
  1317. }
  1318. priv->cfg->ops->lib->post_associate(priv, priv->beacon_ctx->vif);
  1319. }
  1320. void iwl_bss_info_changed(struct ieee80211_hw *hw,
  1321. struct ieee80211_vif *vif,
  1322. struct ieee80211_bss_conf *bss_conf,
  1323. u32 changes)
  1324. {
  1325. struct iwl_priv *priv = hw->priv;
  1326. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1327. int ret;
  1328. IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
  1329. if (!iwl_is_alive(priv))
  1330. return;
  1331. mutex_lock(&priv->mutex);
  1332. if (changes & BSS_CHANGED_QOS) {
  1333. unsigned long flags;
  1334. spin_lock_irqsave(&priv->lock, flags);
  1335. ctx->qos_data.qos_active = bss_conf->qos;
  1336. iwl_update_qos(priv, ctx);
  1337. spin_unlock_irqrestore(&priv->lock, flags);
  1338. }
  1339. if (changes & BSS_CHANGED_BEACON_ENABLED) {
  1340. /*
  1341. * the add_interface code must make sure we only ever
  1342. * have a single interface that could be beaconing at
  1343. * any time.
  1344. */
  1345. if (vif->bss_conf.enable_beacon)
  1346. priv->beacon_ctx = ctx;
  1347. else
  1348. priv->beacon_ctx = NULL;
  1349. }
  1350. if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_AP) {
  1351. dev_kfree_skb(priv->beacon_skb);
  1352. priv->beacon_skb = ieee80211_beacon_get(hw, vif);
  1353. }
  1354. if (changes & BSS_CHANGED_BEACON_INT && vif->type == NL80211_IFTYPE_AP)
  1355. iwl_send_rxon_timing(priv, ctx);
  1356. if (changes & BSS_CHANGED_BSSID) {
  1357. IWL_DEBUG_MAC80211(priv, "BSSID %pM\n", bss_conf->bssid);
  1358. /*
  1359. * If there is currently a HW scan going on in the
  1360. * background then we need to cancel it else the RXON
  1361. * below/in post_associate will fail.
  1362. */
  1363. if (iwl_scan_cancel_timeout(priv, 100)) {
  1364. IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
  1365. IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
  1366. mutex_unlock(&priv->mutex);
  1367. return;
  1368. }
  1369. /* mac80211 only sets assoc when in STATION mode */
  1370. if (vif->type == NL80211_IFTYPE_ADHOC || bss_conf->assoc) {
  1371. memcpy(ctx->staging.bssid_addr,
  1372. bss_conf->bssid, ETH_ALEN);
  1373. /* currently needed in a few places */
  1374. memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN);
  1375. } else {
  1376. ctx->staging.filter_flags &=
  1377. ~RXON_FILTER_ASSOC_MSK;
  1378. }
  1379. }
  1380. /*
  1381. * This needs to be after setting the BSSID in case
  1382. * mac80211 decides to do both changes at once because
  1383. * it will invoke post_associate.
  1384. */
  1385. if (vif->type == NL80211_IFTYPE_ADHOC && changes & BSS_CHANGED_BEACON)
  1386. iwlcore_beacon_update(hw, vif);
  1387. if (changes & BSS_CHANGED_ERP_PREAMBLE) {
  1388. IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
  1389. bss_conf->use_short_preamble);
  1390. if (bss_conf->use_short_preamble)
  1391. ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  1392. else
  1393. ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  1394. }
  1395. if (changes & BSS_CHANGED_ERP_CTS_PROT) {
  1396. IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n", bss_conf->use_cts_prot);
  1397. if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
  1398. ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
  1399. else
  1400. ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
  1401. if (bss_conf->use_cts_prot)
  1402. ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
  1403. else
  1404. ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
  1405. }
  1406. if (changes & BSS_CHANGED_BASIC_RATES) {
  1407. /* XXX use this information
  1408. *
  1409. * To do that, remove code from iwl_set_rate() and put something
  1410. * like this here:
  1411. *
  1412. if (A-band)
  1413. ctx->staging.ofdm_basic_rates =
  1414. bss_conf->basic_rates;
  1415. else
  1416. ctx->staging.ofdm_basic_rates =
  1417. bss_conf->basic_rates >> 4;
  1418. ctx->staging.cck_basic_rates =
  1419. bss_conf->basic_rates & 0xF;
  1420. */
  1421. }
  1422. if (changes & BSS_CHANGED_HT) {
  1423. iwl_ht_conf(priv, vif);
  1424. if (priv->cfg->ops->hcmd->set_rxon_chain)
  1425. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  1426. }
  1427. if (changes & BSS_CHANGED_ASSOC) {
  1428. IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
  1429. if (bss_conf->assoc) {
  1430. priv->timestamp = bss_conf->timestamp;
  1431. iwl_led_associate(priv);
  1432. if (!iwl_is_rfkill(priv))
  1433. priv->cfg->ops->lib->post_associate(priv, vif);
  1434. } else
  1435. iwl_set_no_assoc(priv, vif);
  1436. }
  1437. if (changes && iwl_is_associated_ctx(ctx) && bss_conf->aid) {
  1438. IWL_DEBUG_MAC80211(priv, "Changes (%#x) while associated\n",
  1439. changes);
  1440. ret = iwl_send_rxon_assoc(priv, ctx);
  1441. if (!ret) {
  1442. /* Sync active_rxon with latest change. */
  1443. memcpy((void *)&ctx->active,
  1444. &ctx->staging,
  1445. sizeof(struct iwl_rxon_cmd));
  1446. }
  1447. }
  1448. if (changes & BSS_CHANGED_BEACON_ENABLED) {
  1449. if (vif->bss_conf.enable_beacon) {
  1450. memcpy(ctx->staging.bssid_addr,
  1451. bss_conf->bssid, ETH_ALEN);
  1452. memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN);
  1453. iwlcore_config_ap(priv, vif);
  1454. } else
  1455. iwl_set_no_assoc(priv, vif);
  1456. }
  1457. if (changes & BSS_CHANGED_IBSS) {
  1458. ret = priv->cfg->ops->lib->manage_ibss_station(priv, vif,
  1459. bss_conf->ibss_joined);
  1460. if (ret)
  1461. IWL_ERR(priv, "failed to %s IBSS station %pM\n",
  1462. bss_conf->ibss_joined ? "add" : "remove",
  1463. bss_conf->bssid);
  1464. }
  1465. if (changes & BSS_CHANGED_IDLE &&
  1466. priv->cfg->ops->hcmd->set_pan_params) {
  1467. if (priv->cfg->ops->hcmd->set_pan_params(priv))
  1468. IWL_ERR(priv, "failed to update PAN params\n");
  1469. }
  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. iwl_set_tx_power(priv, conf->power_level, false);
  1688. }
  1689. if (!iwl_is_ready(priv)) {
  1690. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  1691. goto out;
  1692. }
  1693. if (scan_active)
  1694. goto out;
  1695. for_each_context(priv, ctx) {
  1696. if (memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging)))
  1697. iwlcore_commit_rxon(priv, ctx);
  1698. else
  1699. IWL_DEBUG_INFO(priv,
  1700. "Not re-sending same RXON configuration.\n");
  1701. }
  1702. out:
  1703. IWL_DEBUG_MAC80211(priv, "leave\n");
  1704. mutex_unlock(&priv->mutex);
  1705. return ret;
  1706. }
  1707. EXPORT_SYMBOL(iwl_mac_config);
  1708. void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
  1709. {
  1710. struct iwl_priv *priv = hw->priv;
  1711. unsigned long flags;
  1712. /* IBSS can only be the IWL_RXON_CTX_BSS context */
  1713. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  1714. mutex_lock(&priv->mutex);
  1715. IWL_DEBUG_MAC80211(priv, "enter\n");
  1716. spin_lock_irqsave(&priv->lock, flags);
  1717. memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_config));
  1718. spin_unlock_irqrestore(&priv->lock, flags);
  1719. spin_lock_irqsave(&priv->lock, flags);
  1720. /* new association get rid of ibss beacon skb */
  1721. if (priv->beacon_skb)
  1722. dev_kfree_skb(priv->beacon_skb);
  1723. priv->beacon_skb = NULL;
  1724. priv->timestamp = 0;
  1725. spin_unlock_irqrestore(&priv->lock, flags);
  1726. iwl_scan_cancel_timeout(priv, 100);
  1727. if (!iwl_is_ready_rf(priv)) {
  1728. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  1729. mutex_unlock(&priv->mutex);
  1730. return;
  1731. }
  1732. /* we are restarting association process
  1733. * clear RXON_FILTER_ASSOC_MSK bit
  1734. */
  1735. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1736. iwlcore_commit_rxon(priv, ctx);
  1737. iwl_set_rate(priv);
  1738. mutex_unlock(&priv->mutex);
  1739. IWL_DEBUG_MAC80211(priv, "leave\n");
  1740. }
  1741. EXPORT_SYMBOL(iwl_mac_reset_tsf);
  1742. int iwl_alloc_txq_mem(struct iwl_priv *priv)
  1743. {
  1744. if (!priv->txq)
  1745. priv->txq = kzalloc(
  1746. sizeof(struct iwl_tx_queue) *
  1747. priv->cfg->base_params->num_of_queues,
  1748. GFP_KERNEL);
  1749. if (!priv->txq) {
  1750. IWL_ERR(priv, "Not enough memory for txq\n");
  1751. return -ENOMEM;
  1752. }
  1753. return 0;
  1754. }
  1755. EXPORT_SYMBOL(iwl_alloc_txq_mem);
  1756. void iwl_free_txq_mem(struct iwl_priv *priv)
  1757. {
  1758. kfree(priv->txq);
  1759. priv->txq = NULL;
  1760. }
  1761. EXPORT_SYMBOL(iwl_free_txq_mem);
  1762. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1763. #define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES)
  1764. void iwl_reset_traffic_log(struct iwl_priv *priv)
  1765. {
  1766. priv->tx_traffic_idx = 0;
  1767. priv->rx_traffic_idx = 0;
  1768. if (priv->tx_traffic)
  1769. memset(priv->tx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
  1770. if (priv->rx_traffic)
  1771. memset(priv->rx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
  1772. }
  1773. int iwl_alloc_traffic_mem(struct iwl_priv *priv)
  1774. {
  1775. u32 traffic_size = IWL_TRAFFIC_DUMP_SIZE;
  1776. if (iwl_debug_level & IWL_DL_TX) {
  1777. if (!priv->tx_traffic) {
  1778. priv->tx_traffic =
  1779. kzalloc(traffic_size, GFP_KERNEL);
  1780. if (!priv->tx_traffic)
  1781. return -ENOMEM;
  1782. }
  1783. }
  1784. if (iwl_debug_level & IWL_DL_RX) {
  1785. if (!priv->rx_traffic) {
  1786. priv->rx_traffic =
  1787. kzalloc(traffic_size, GFP_KERNEL);
  1788. if (!priv->rx_traffic)
  1789. return -ENOMEM;
  1790. }
  1791. }
  1792. iwl_reset_traffic_log(priv);
  1793. return 0;
  1794. }
  1795. EXPORT_SYMBOL(iwl_alloc_traffic_mem);
  1796. void iwl_free_traffic_mem(struct iwl_priv *priv)
  1797. {
  1798. kfree(priv->tx_traffic);
  1799. priv->tx_traffic = NULL;
  1800. kfree(priv->rx_traffic);
  1801. priv->rx_traffic = NULL;
  1802. }
  1803. EXPORT_SYMBOL(iwl_free_traffic_mem);
  1804. void iwl_dbg_log_tx_data_frame(struct iwl_priv *priv,
  1805. u16 length, struct ieee80211_hdr *header)
  1806. {
  1807. __le16 fc;
  1808. u16 len;
  1809. if (likely(!(iwl_debug_level & IWL_DL_TX)))
  1810. return;
  1811. if (!priv->tx_traffic)
  1812. return;
  1813. fc = header->frame_control;
  1814. if (ieee80211_is_data(fc)) {
  1815. len = (length > IWL_TRAFFIC_ENTRY_SIZE)
  1816. ? IWL_TRAFFIC_ENTRY_SIZE : length;
  1817. memcpy((priv->tx_traffic +
  1818. (priv->tx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
  1819. header, len);
  1820. priv->tx_traffic_idx =
  1821. (priv->tx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
  1822. }
  1823. }
  1824. EXPORT_SYMBOL(iwl_dbg_log_tx_data_frame);
  1825. void iwl_dbg_log_rx_data_frame(struct iwl_priv *priv,
  1826. u16 length, struct ieee80211_hdr *header)
  1827. {
  1828. __le16 fc;
  1829. u16 len;
  1830. if (likely(!(iwl_debug_level & IWL_DL_RX)))
  1831. return;
  1832. if (!priv->rx_traffic)
  1833. return;
  1834. fc = header->frame_control;
  1835. if (ieee80211_is_data(fc)) {
  1836. len = (length > IWL_TRAFFIC_ENTRY_SIZE)
  1837. ? IWL_TRAFFIC_ENTRY_SIZE : length;
  1838. memcpy((priv->rx_traffic +
  1839. (priv->rx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
  1840. header, len);
  1841. priv->rx_traffic_idx =
  1842. (priv->rx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
  1843. }
  1844. }
  1845. EXPORT_SYMBOL(iwl_dbg_log_rx_data_frame);
  1846. const char *get_mgmt_string(int cmd)
  1847. {
  1848. switch (cmd) {
  1849. IWL_CMD(MANAGEMENT_ASSOC_REQ);
  1850. IWL_CMD(MANAGEMENT_ASSOC_RESP);
  1851. IWL_CMD(MANAGEMENT_REASSOC_REQ);
  1852. IWL_CMD(MANAGEMENT_REASSOC_RESP);
  1853. IWL_CMD(MANAGEMENT_PROBE_REQ);
  1854. IWL_CMD(MANAGEMENT_PROBE_RESP);
  1855. IWL_CMD(MANAGEMENT_BEACON);
  1856. IWL_CMD(MANAGEMENT_ATIM);
  1857. IWL_CMD(MANAGEMENT_DISASSOC);
  1858. IWL_CMD(MANAGEMENT_AUTH);
  1859. IWL_CMD(MANAGEMENT_DEAUTH);
  1860. IWL_CMD(MANAGEMENT_ACTION);
  1861. default:
  1862. return "UNKNOWN";
  1863. }
  1864. }
  1865. const char *get_ctrl_string(int cmd)
  1866. {
  1867. switch (cmd) {
  1868. IWL_CMD(CONTROL_BACK_REQ);
  1869. IWL_CMD(CONTROL_BACK);
  1870. IWL_CMD(CONTROL_PSPOLL);
  1871. IWL_CMD(CONTROL_RTS);
  1872. IWL_CMD(CONTROL_CTS);
  1873. IWL_CMD(CONTROL_ACK);
  1874. IWL_CMD(CONTROL_CFEND);
  1875. IWL_CMD(CONTROL_CFENDACK);
  1876. default:
  1877. return "UNKNOWN";
  1878. }
  1879. }
  1880. void iwl_clear_traffic_stats(struct iwl_priv *priv)
  1881. {
  1882. memset(&priv->tx_stats, 0, sizeof(struct traffic_stats));
  1883. memset(&priv->rx_stats, 0, sizeof(struct traffic_stats));
  1884. priv->led_tpt = 0;
  1885. }
  1886. /*
  1887. * if CONFIG_IWLWIFI_DEBUGFS defined, iwl_update_stats function will
  1888. * record all the MGMT, CTRL and DATA pkt for both TX and Rx pass.
  1889. * Use debugFs to display the rx/rx_statistics
  1890. * if CONFIG_IWLWIFI_DEBUGFS not being defined, then no MGMT and CTRL
  1891. * information will be recorded, but DATA pkt still will be recorded
  1892. * for the reason of iwl_led.c need to control the led blinking based on
  1893. * number of tx and rx data.
  1894. *
  1895. */
  1896. void iwl_update_stats(struct iwl_priv *priv, bool is_tx, __le16 fc, u16 len)
  1897. {
  1898. struct traffic_stats *stats;
  1899. if (is_tx)
  1900. stats = &priv->tx_stats;
  1901. else
  1902. stats = &priv->rx_stats;
  1903. if (ieee80211_is_mgmt(fc)) {
  1904. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  1905. case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
  1906. stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
  1907. break;
  1908. case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
  1909. stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
  1910. break;
  1911. case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
  1912. stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
  1913. break;
  1914. case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
  1915. stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
  1916. break;
  1917. case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
  1918. stats->mgmt[MANAGEMENT_PROBE_REQ]++;
  1919. break;
  1920. case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
  1921. stats->mgmt[MANAGEMENT_PROBE_RESP]++;
  1922. break;
  1923. case cpu_to_le16(IEEE80211_STYPE_BEACON):
  1924. stats->mgmt[MANAGEMENT_BEACON]++;
  1925. break;
  1926. case cpu_to_le16(IEEE80211_STYPE_ATIM):
  1927. stats->mgmt[MANAGEMENT_ATIM]++;
  1928. break;
  1929. case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
  1930. stats->mgmt[MANAGEMENT_DISASSOC]++;
  1931. break;
  1932. case cpu_to_le16(IEEE80211_STYPE_AUTH):
  1933. stats->mgmt[MANAGEMENT_AUTH]++;
  1934. break;
  1935. case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
  1936. stats->mgmt[MANAGEMENT_DEAUTH]++;
  1937. break;
  1938. case cpu_to_le16(IEEE80211_STYPE_ACTION):
  1939. stats->mgmt[MANAGEMENT_ACTION]++;
  1940. break;
  1941. }
  1942. } else if (ieee80211_is_ctl(fc)) {
  1943. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  1944. case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
  1945. stats->ctrl[CONTROL_BACK_REQ]++;
  1946. break;
  1947. case cpu_to_le16(IEEE80211_STYPE_BACK):
  1948. stats->ctrl[CONTROL_BACK]++;
  1949. break;
  1950. case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
  1951. stats->ctrl[CONTROL_PSPOLL]++;
  1952. break;
  1953. case cpu_to_le16(IEEE80211_STYPE_RTS):
  1954. stats->ctrl[CONTROL_RTS]++;
  1955. break;
  1956. case cpu_to_le16(IEEE80211_STYPE_CTS):
  1957. stats->ctrl[CONTROL_CTS]++;
  1958. break;
  1959. case cpu_to_le16(IEEE80211_STYPE_ACK):
  1960. stats->ctrl[CONTROL_ACK]++;
  1961. break;
  1962. case cpu_to_le16(IEEE80211_STYPE_CFEND):
  1963. stats->ctrl[CONTROL_CFEND]++;
  1964. break;
  1965. case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
  1966. stats->ctrl[CONTROL_CFENDACK]++;
  1967. break;
  1968. }
  1969. } else {
  1970. /* data */
  1971. stats->data_cnt++;
  1972. stats->data_bytes += len;
  1973. }
  1974. iwl_leds_background(priv);
  1975. }
  1976. EXPORT_SYMBOL(iwl_update_stats);
  1977. #endif
  1978. static void iwl_force_rf_reset(struct iwl_priv *priv)
  1979. {
  1980. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1981. return;
  1982. if (!iwl_is_any_associated(priv)) {
  1983. IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n");
  1984. return;
  1985. }
  1986. /*
  1987. * There is no easy and better way to force reset the radio,
  1988. * the only known method is switching channel which will force to
  1989. * reset and tune the radio.
  1990. * Use internal short scan (single channel) operation to should
  1991. * achieve this objective.
  1992. * Driver should reset the radio when number of consecutive missed
  1993. * beacon, or any other uCode error condition detected.
  1994. */
  1995. IWL_DEBUG_INFO(priv, "perform radio reset.\n");
  1996. iwl_internal_short_hw_scan(priv);
  1997. }
  1998. int iwl_force_reset(struct iwl_priv *priv, int mode, bool external)
  1999. {
  2000. struct iwl_force_reset *force_reset;
  2001. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2002. return -EINVAL;
  2003. if (mode >= IWL_MAX_FORCE_RESET) {
  2004. IWL_DEBUG_INFO(priv, "invalid reset request.\n");
  2005. return -EINVAL;
  2006. }
  2007. force_reset = &priv->force_reset[mode];
  2008. force_reset->reset_request_count++;
  2009. if (!external) {
  2010. if (force_reset->last_force_reset_jiffies &&
  2011. time_after(force_reset->last_force_reset_jiffies +
  2012. force_reset->reset_duration, jiffies)) {
  2013. IWL_DEBUG_INFO(priv, "force reset rejected\n");
  2014. force_reset->reset_reject_count++;
  2015. return -EAGAIN;
  2016. }
  2017. }
  2018. force_reset->reset_success_count++;
  2019. force_reset->last_force_reset_jiffies = jiffies;
  2020. IWL_DEBUG_INFO(priv, "perform force reset (%d)\n", mode);
  2021. switch (mode) {
  2022. case IWL_RF_RESET:
  2023. iwl_force_rf_reset(priv);
  2024. break;
  2025. case IWL_FW_RESET:
  2026. /*
  2027. * if the request is from external(ex: debugfs),
  2028. * then always perform the request in regardless the module
  2029. * parameter setting
  2030. * if the request is from internal (uCode error or driver
  2031. * detect failure), then fw_restart module parameter
  2032. * need to be check before performing firmware reload
  2033. */
  2034. if (!external && !priv->cfg->mod_params->restart_fw) {
  2035. IWL_DEBUG_INFO(priv, "Cancel firmware reload based on "
  2036. "module parameter setting\n");
  2037. break;
  2038. }
  2039. IWL_ERR(priv, "On demand firmware reload\n");
  2040. /* Set the FW error flag -- cleared on iwl_down */
  2041. set_bit(STATUS_FW_ERROR, &priv->status);
  2042. wake_up_interruptible(&priv->wait_command_queue);
  2043. /*
  2044. * Keep the restart process from trying to send host
  2045. * commands by clearing the INIT status bit
  2046. */
  2047. clear_bit(STATUS_READY, &priv->status);
  2048. queue_work(priv->workqueue, &priv->restart);
  2049. break;
  2050. }
  2051. return 0;
  2052. }
  2053. /**
  2054. * iwl_bg_monitor_recover - Timer callback to check for stuck queue and recover
  2055. *
  2056. * During normal condition (no queue is stuck), the timer is continually set to
  2057. * execute every monitor_recover_period milliseconds after the last timer
  2058. * expired. When the queue read_ptr is at the same place, the timer is
  2059. * shorten to 100mSecs. This is
  2060. * 1) to reduce the chance that the read_ptr may wrap around (not stuck)
  2061. * 2) to detect the stuck queues quicker before the station and AP can
  2062. * disassociate each other.
  2063. *
  2064. * This function monitors all the tx queues and recover from it if any
  2065. * of the queues are stuck.
  2066. * 1. It first check the cmd queue for stuck conditions. If it is stuck,
  2067. * it will recover by resetting the firmware and return.
  2068. * 2. Then, it checks for station association. If it associates it will check
  2069. * other queues. If any queue is stuck, it will recover by resetting
  2070. * the firmware.
  2071. * Note: It the number of times the queue read_ptr to be at the same place to
  2072. * be MAX_REPEAT+1 in order to consider to be stuck.
  2073. */
  2074. /*
  2075. * The maximum number of times the read pointer of the tx queue at the
  2076. * same place without considering to be stuck.
  2077. */
  2078. #define MAX_REPEAT (2)
  2079. static int iwl_check_stuck_queue(struct iwl_priv *priv, int cnt)
  2080. {
  2081. struct iwl_tx_queue *txq;
  2082. struct iwl_queue *q;
  2083. txq = &priv->txq[cnt];
  2084. q = &txq->q;
  2085. /* queue is empty, skip */
  2086. if (q->read_ptr == q->write_ptr)
  2087. return 0;
  2088. if (q->read_ptr == q->last_read_ptr) {
  2089. /* a queue has not been read from last time */
  2090. if (q->repeat_same_read_ptr > MAX_REPEAT) {
  2091. IWL_ERR(priv,
  2092. "queue %d stuck %d time. Fw reload.\n",
  2093. q->id, q->repeat_same_read_ptr);
  2094. q->repeat_same_read_ptr = 0;
  2095. iwl_force_reset(priv, IWL_FW_RESET, false);
  2096. } else {
  2097. q->repeat_same_read_ptr++;
  2098. IWL_DEBUG_RADIO(priv,
  2099. "queue %d, not read %d time\n",
  2100. q->id,
  2101. q->repeat_same_read_ptr);
  2102. mod_timer(&priv->monitor_recover,
  2103. jiffies + msecs_to_jiffies(
  2104. IWL_ONE_HUNDRED_MSECS));
  2105. return 1;
  2106. }
  2107. } else {
  2108. q->last_read_ptr = q->read_ptr;
  2109. q->repeat_same_read_ptr = 0;
  2110. }
  2111. return 0;
  2112. }
  2113. void iwl_bg_monitor_recover(unsigned long data)
  2114. {
  2115. struct iwl_priv *priv = (struct iwl_priv *)data;
  2116. int cnt;
  2117. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2118. return;
  2119. /* monitor and check for stuck cmd queue */
  2120. if (iwl_check_stuck_queue(priv, priv->cmd_queue))
  2121. return;
  2122. /* monitor and check for other stuck queues */
  2123. if (iwl_is_any_associated(priv)) {
  2124. for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
  2125. /* skip as we already checked the command queue */
  2126. if (cnt == priv->cmd_queue)
  2127. continue;
  2128. if (iwl_check_stuck_queue(priv, cnt))
  2129. return;
  2130. }
  2131. }
  2132. if (priv->cfg->base_params->monitor_recover_period) {
  2133. /*
  2134. * Reschedule the timer to occur in
  2135. * priv->cfg->base_params->monitor_recover_period
  2136. */
  2137. mod_timer(&priv->monitor_recover, jiffies + msecs_to_jiffies(
  2138. priv->cfg->base_params->monitor_recover_period));
  2139. }
  2140. }
  2141. EXPORT_SYMBOL(iwl_bg_monitor_recover);
  2142. /*
  2143. * extended beacon time format
  2144. * time in usec will be changed into a 32-bit value in extended:internal format
  2145. * the extended part is the beacon counts
  2146. * the internal part is the time in usec within one beacon interval
  2147. */
  2148. u32 iwl_usecs_to_beacons(struct iwl_priv *priv, u32 usec, u32 beacon_interval)
  2149. {
  2150. u32 quot;
  2151. u32 rem;
  2152. u32 interval = beacon_interval * TIME_UNIT;
  2153. if (!interval || !usec)
  2154. return 0;
  2155. quot = (usec / interval) &
  2156. (iwl_beacon_time_mask_high(priv,
  2157. priv->hw_params.beacon_time_tsf_bits) >>
  2158. priv->hw_params.beacon_time_tsf_bits);
  2159. rem = (usec % interval) & iwl_beacon_time_mask_low(priv,
  2160. priv->hw_params.beacon_time_tsf_bits);
  2161. return (quot << priv->hw_params.beacon_time_tsf_bits) + rem;
  2162. }
  2163. EXPORT_SYMBOL(iwl_usecs_to_beacons);
  2164. /* base is usually what we get from ucode with each received frame,
  2165. * the same as HW timer counter counting down
  2166. */
  2167. __le32 iwl_add_beacon_time(struct iwl_priv *priv, u32 base,
  2168. u32 addon, u32 beacon_interval)
  2169. {
  2170. u32 base_low = base & iwl_beacon_time_mask_low(priv,
  2171. priv->hw_params.beacon_time_tsf_bits);
  2172. u32 addon_low = addon & iwl_beacon_time_mask_low(priv,
  2173. priv->hw_params.beacon_time_tsf_bits);
  2174. u32 interval = beacon_interval * TIME_UNIT;
  2175. u32 res = (base & iwl_beacon_time_mask_high(priv,
  2176. priv->hw_params.beacon_time_tsf_bits)) +
  2177. (addon & iwl_beacon_time_mask_high(priv,
  2178. priv->hw_params.beacon_time_tsf_bits));
  2179. if (base_low > addon_low)
  2180. res += base_low - addon_low;
  2181. else if (base_low < addon_low) {
  2182. res += interval + base_low - addon_low;
  2183. res += (1 << priv->hw_params.beacon_time_tsf_bits);
  2184. } else
  2185. res += (1 << priv->hw_params.beacon_time_tsf_bits);
  2186. return cpu_to_le32(res);
  2187. }
  2188. EXPORT_SYMBOL(iwl_add_beacon_time);
  2189. #ifdef CONFIG_PM
  2190. int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  2191. {
  2192. struct iwl_priv *priv = pci_get_drvdata(pdev);
  2193. /*
  2194. * This function is called when system goes into suspend state
  2195. * mac80211 will call iwl_mac_stop() from the mac80211 suspend function
  2196. * first but since iwl_mac_stop() has no knowledge of who the caller is,
  2197. * it will not call apm_ops.stop() to stop the DMA operation.
  2198. * Calling apm_ops.stop here to make sure we stop the DMA.
  2199. */
  2200. iwl_apm_stop(priv);
  2201. pci_save_state(pdev);
  2202. pci_disable_device(pdev);
  2203. pci_set_power_state(pdev, PCI_D3hot);
  2204. return 0;
  2205. }
  2206. EXPORT_SYMBOL(iwl_pci_suspend);
  2207. int iwl_pci_resume(struct pci_dev *pdev)
  2208. {
  2209. struct iwl_priv *priv = pci_get_drvdata(pdev);
  2210. int ret;
  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. pci_set_power_state(pdev, PCI_D0);
  2218. ret = pci_enable_device(pdev);
  2219. if (ret)
  2220. return ret;
  2221. pci_restore_state(pdev);
  2222. iwl_enable_interrupts(priv);
  2223. if (!(iwl_read32(priv, CSR_GP_CNTRL) &
  2224. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  2225. hw_rfkill = true;
  2226. if (hw_rfkill)
  2227. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2228. else
  2229. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2230. wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rfkill);
  2231. return 0;
  2232. }
  2233. EXPORT_SYMBOL(iwl_pci_resume);
  2234. #endif /* CONFIG_PM */