iwl-core.c 73 KB

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