iwl-core.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656
  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-debug.h"
  36. #include "iwl-core.h"
  37. #include "iwl-io.h"
  38. #include "iwl-power.h"
  39. #include "iwl-agn.h"
  40. #include "iwl-shared.h"
  41. #include "iwl-agn.h"
  42. #include "iwl-trans.h"
  43. const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  44. #define MAX_BIT_RATE_40_MHZ 150 /* Mbps */
  45. #define MAX_BIT_RATE_20_MHZ 72 /* Mbps */
  46. static void iwl_init_ht_hw_capab(const struct iwl_priv *priv,
  47. struct ieee80211_sta_ht_cap *ht_info,
  48. enum ieee80211_band band)
  49. {
  50. u16 max_bit_rate = 0;
  51. u8 rx_chains_num = hw_params(priv).rx_chains_num;
  52. u8 tx_chains_num = hw_params(priv).tx_chains_num;
  53. ht_info->cap = 0;
  54. memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
  55. ht_info->ht_supported = true;
  56. if (priv->cfg->ht_params &&
  57. priv->cfg->ht_params->ht_greenfield_support)
  58. ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
  59. ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
  60. max_bit_rate = MAX_BIT_RATE_20_MHZ;
  61. if (hw_params(priv).ht40_channel & BIT(band)) {
  62. ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  63. ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
  64. ht_info->mcs.rx_mask[4] = 0x01;
  65. max_bit_rate = MAX_BIT_RATE_40_MHZ;
  66. }
  67. if (iwlagn_mod_params.amsdu_size_8K)
  68. ht_info->cap |= IEEE80211_HT_CAP_MAX_AMSDU;
  69. ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
  70. if (priv->cfg->bt_params && priv->cfg->bt_params->ampdu_factor)
  71. ht_info->ampdu_factor = priv->cfg->bt_params->ampdu_factor;
  72. ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
  73. if (priv->cfg->bt_params && priv->cfg->bt_params->ampdu_density)
  74. ht_info->ampdu_density = priv->cfg->bt_params->ampdu_density;
  75. ht_info->mcs.rx_mask[0] = 0xFF;
  76. if (rx_chains_num >= 2)
  77. ht_info->mcs.rx_mask[1] = 0xFF;
  78. if (rx_chains_num >= 3)
  79. ht_info->mcs.rx_mask[2] = 0xFF;
  80. /* Highest supported Rx data rate */
  81. max_bit_rate *= rx_chains_num;
  82. WARN_ON(max_bit_rate & ~IEEE80211_HT_MCS_RX_HIGHEST_MASK);
  83. ht_info->mcs.rx_highest = cpu_to_le16(max_bit_rate);
  84. /* Tx MCS capabilities */
  85. ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  86. if (tx_chains_num != rx_chains_num) {
  87. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
  88. ht_info->mcs.tx_params |= ((tx_chains_num - 1) <<
  89. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
  90. }
  91. }
  92. /**
  93. * iwl_init_geos - Initialize mac80211's geo/channel info based from eeprom
  94. */
  95. int iwl_init_geos(struct iwl_priv *priv)
  96. {
  97. struct iwl_channel_info *ch;
  98. struct ieee80211_supported_band *sband;
  99. struct ieee80211_channel *channels;
  100. struct ieee80211_channel *geo_ch;
  101. struct ieee80211_rate *rates;
  102. int i = 0;
  103. s8 max_tx_power = IWLAGN_TX_POWER_TARGET_POWER_MIN;
  104. if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
  105. priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
  106. IWL_DEBUG_INFO(priv, "Geography modes already initialized.\n");
  107. set_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status);
  108. return 0;
  109. }
  110. channels = kcalloc(priv->channel_count,
  111. sizeof(struct ieee80211_channel), GFP_KERNEL);
  112. if (!channels)
  113. return -ENOMEM;
  114. rates = kcalloc(IWL_RATE_COUNT_LEGACY, sizeof(struct ieee80211_rate),
  115. GFP_KERNEL);
  116. if (!rates) {
  117. kfree(channels);
  118. return -ENOMEM;
  119. }
  120. /* 5.2GHz channels start after the 2.4GHz channels */
  121. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  122. sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
  123. /* just OFDM */
  124. sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
  125. sband->n_bitrates = IWL_RATE_COUNT_LEGACY - IWL_FIRST_OFDM_RATE;
  126. if (priv->cfg->sku & EEPROM_SKU_CAP_11N_ENABLE)
  127. iwl_init_ht_hw_capab(priv, &sband->ht_cap,
  128. IEEE80211_BAND_5GHZ);
  129. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  130. sband->channels = channels;
  131. /* OFDM & CCK */
  132. sband->bitrates = rates;
  133. sband->n_bitrates = IWL_RATE_COUNT_LEGACY;
  134. if (priv->cfg->sku & EEPROM_SKU_CAP_11N_ENABLE)
  135. iwl_init_ht_hw_capab(priv, &sband->ht_cap,
  136. IEEE80211_BAND_2GHZ);
  137. priv->ieee_channels = channels;
  138. priv->ieee_rates = rates;
  139. for (i = 0; i < priv->channel_count; i++) {
  140. ch = &priv->channel_info[i];
  141. /* FIXME: might be removed if scan is OK */
  142. if (!is_channel_valid(ch))
  143. continue;
  144. sband = &priv->bands[ch->band];
  145. geo_ch = &sband->channels[sband->n_channels++];
  146. geo_ch->center_freq =
  147. ieee80211_channel_to_frequency(ch->channel, ch->band);
  148. geo_ch->max_power = ch->max_power_avg;
  149. geo_ch->max_antenna_gain = 0xff;
  150. geo_ch->hw_value = ch->channel;
  151. if (is_channel_valid(ch)) {
  152. if (!(ch->flags & EEPROM_CHANNEL_IBSS))
  153. geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
  154. if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
  155. geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
  156. if (ch->flags & EEPROM_CHANNEL_RADAR)
  157. geo_ch->flags |= IEEE80211_CHAN_RADAR;
  158. geo_ch->flags |= ch->ht40_extension_channel;
  159. if (ch->max_power_avg > max_tx_power)
  160. max_tx_power = ch->max_power_avg;
  161. } else {
  162. geo_ch->flags |= IEEE80211_CHAN_DISABLED;
  163. }
  164. IWL_DEBUG_INFO(priv, "Channel %d Freq=%d[%sGHz] %s flag=0x%X\n",
  165. ch->channel, geo_ch->center_freq,
  166. is_channel_a_band(ch) ? "5.2" : "2.4",
  167. geo_ch->flags & IEEE80211_CHAN_DISABLED ?
  168. "restricted" : "valid",
  169. geo_ch->flags);
  170. }
  171. priv->tx_power_device_lmt = max_tx_power;
  172. priv->tx_power_user_lmt = max_tx_power;
  173. priv->tx_power_next = max_tx_power;
  174. if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
  175. priv->cfg->sku & EEPROM_SKU_CAP_BAND_52GHZ) {
  176. char buf[32];
  177. bus_get_hw_id(bus(priv), buf, sizeof(buf));
  178. IWL_INFO(priv, "Incorrectly detected BG card as ABG. "
  179. "Please send your %s to maintainer.\n", buf);
  180. priv->cfg->sku &= ~EEPROM_SKU_CAP_BAND_52GHZ;
  181. }
  182. IWL_INFO(priv, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
  183. priv->bands[IEEE80211_BAND_2GHZ].n_channels,
  184. priv->bands[IEEE80211_BAND_5GHZ].n_channels);
  185. set_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status);
  186. return 0;
  187. }
  188. /*
  189. * iwl_free_geos - undo allocations in iwl_init_geos
  190. */
  191. void iwl_free_geos(struct iwl_priv *priv)
  192. {
  193. kfree(priv->ieee_channels);
  194. kfree(priv->ieee_rates);
  195. clear_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status);
  196. }
  197. static bool iwl_is_channel_extension(struct iwl_priv *priv,
  198. enum ieee80211_band band,
  199. u16 channel, u8 extension_chan_offset)
  200. {
  201. const struct iwl_channel_info *ch_info;
  202. ch_info = iwl_get_channel_info(priv, band, channel);
  203. if (!is_channel_valid(ch_info))
  204. return false;
  205. if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
  206. return !(ch_info->ht40_extension_channel &
  207. IEEE80211_CHAN_NO_HT40PLUS);
  208. else if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW)
  209. return !(ch_info->ht40_extension_channel &
  210. IEEE80211_CHAN_NO_HT40MINUS);
  211. return false;
  212. }
  213. bool iwl_is_ht40_tx_allowed(struct iwl_priv *priv,
  214. struct iwl_rxon_context *ctx,
  215. struct ieee80211_sta_ht_cap *ht_cap)
  216. {
  217. if (!ctx->ht.enabled || !ctx->ht.is_40mhz)
  218. return false;
  219. /*
  220. * We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40
  221. * the bit will not set if it is pure 40MHz case
  222. */
  223. if (ht_cap && !ht_cap->ht_supported)
  224. return false;
  225. #ifdef CONFIG_IWLWIFI_DEBUGFS
  226. if (priv->disable_ht40)
  227. return false;
  228. #endif
  229. return iwl_is_channel_extension(priv, priv->band,
  230. le16_to_cpu(ctx->staging.channel),
  231. ctx->ht.extension_chan_offset);
  232. }
  233. static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
  234. {
  235. u16 new_val;
  236. u16 beacon_factor;
  237. /*
  238. * If mac80211 hasn't given us a beacon interval, program
  239. * the default into the device (not checking this here
  240. * would cause the adjustment below to return the maximum
  241. * value, which may break PAN.)
  242. */
  243. if (!beacon_val)
  244. return DEFAULT_BEACON_INTERVAL;
  245. /*
  246. * If the beacon interval we obtained from the peer
  247. * is too large, we'll have to wake up more often
  248. * (and in IBSS case, we'll beacon too much)
  249. *
  250. * For example, if max_beacon_val is 4096, and the
  251. * requested beacon interval is 7000, we'll have to
  252. * use 3500 to be able to wake up on the beacons.
  253. *
  254. * This could badly influence beacon detection stats.
  255. */
  256. beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
  257. new_val = beacon_val / beacon_factor;
  258. if (!new_val)
  259. new_val = max_beacon_val;
  260. return new_val;
  261. }
  262. int iwl_send_rxon_timing(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  263. {
  264. u64 tsf;
  265. s32 interval_tm, rem;
  266. struct ieee80211_conf *conf = NULL;
  267. u16 beacon_int;
  268. struct ieee80211_vif *vif = ctx->vif;
  269. conf = &priv->hw->conf;
  270. lockdep_assert_held(&priv->shrd->mutex);
  271. memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd));
  272. ctx->timing.timestamp = cpu_to_le64(priv->timestamp);
  273. ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval);
  274. beacon_int = vif ? vif->bss_conf.beacon_int : 0;
  275. /*
  276. * TODO: For IBSS we need to get atim_window from mac80211,
  277. * for now just always use 0
  278. */
  279. ctx->timing.atim_window = 0;
  280. if (ctx->ctxid == IWL_RXON_CTX_PAN &&
  281. (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION) &&
  282. iwl_is_associated(priv, IWL_RXON_CTX_BSS) &&
  283. priv->contexts[IWL_RXON_CTX_BSS].vif &&
  284. priv->contexts[IWL_RXON_CTX_BSS].vif->bss_conf.beacon_int) {
  285. ctx->timing.beacon_interval =
  286. priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval;
  287. beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
  288. } else if (ctx->ctxid == IWL_RXON_CTX_BSS &&
  289. iwl_is_associated(priv, IWL_RXON_CTX_PAN) &&
  290. priv->contexts[IWL_RXON_CTX_PAN].vif &&
  291. priv->contexts[IWL_RXON_CTX_PAN].vif->bss_conf.beacon_int &&
  292. (!iwl_is_associated_ctx(ctx) || !ctx->vif ||
  293. !ctx->vif->bss_conf.beacon_int)) {
  294. ctx->timing.beacon_interval =
  295. priv->contexts[IWL_RXON_CTX_PAN].timing.beacon_interval;
  296. beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
  297. } else {
  298. beacon_int = iwl_adjust_beacon_interval(beacon_int,
  299. IWL_MAX_UCODE_BEACON_INTERVAL * TIME_UNIT);
  300. ctx->timing.beacon_interval = cpu_to_le16(beacon_int);
  301. }
  302. ctx->beacon_int = beacon_int;
  303. tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
  304. interval_tm = beacon_int * TIME_UNIT;
  305. rem = do_div(tsf, interval_tm);
  306. ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
  307. ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1;
  308. IWL_DEBUG_ASSOC(priv,
  309. "beacon interval %d beacon timer %d beacon tim %d\n",
  310. le16_to_cpu(ctx->timing.beacon_interval),
  311. le32_to_cpu(ctx->timing.beacon_init_val),
  312. le16_to_cpu(ctx->timing.atim_window));
  313. return iwl_trans_send_cmd_pdu(trans(priv), ctx->rxon_timing_cmd,
  314. CMD_SYNC, sizeof(ctx->timing), &ctx->timing);
  315. }
  316. void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
  317. int hw_decrypt)
  318. {
  319. struct iwl_rxon_cmd *rxon = &ctx->staging;
  320. if (hw_decrypt)
  321. rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
  322. else
  323. rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
  324. }
  325. /* validate RXON structure is valid */
  326. int iwl_check_rxon_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  327. {
  328. struct iwl_rxon_cmd *rxon = &ctx->staging;
  329. u32 errors = 0;
  330. if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
  331. if (rxon->flags & RXON_FLG_TGJ_NARROW_BAND_MSK) {
  332. IWL_WARN(priv, "check 2.4G: wrong narrow\n");
  333. errors |= BIT(0);
  334. }
  335. if (rxon->flags & RXON_FLG_RADAR_DETECT_MSK) {
  336. IWL_WARN(priv, "check 2.4G: wrong radar\n");
  337. errors |= BIT(1);
  338. }
  339. } else {
  340. if (!(rxon->flags & RXON_FLG_SHORT_SLOT_MSK)) {
  341. IWL_WARN(priv, "check 5.2G: not short slot!\n");
  342. errors |= BIT(2);
  343. }
  344. if (rxon->flags & RXON_FLG_CCK_MSK) {
  345. IWL_WARN(priv, "check 5.2G: CCK!\n");
  346. errors |= BIT(3);
  347. }
  348. }
  349. if ((rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1) {
  350. IWL_WARN(priv, "mac/bssid mcast!\n");
  351. errors |= BIT(4);
  352. }
  353. /* make sure basic rates 6Mbps and 1Mbps are supported */
  354. if ((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0 &&
  355. (rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0) {
  356. IWL_WARN(priv, "neither 1 nor 6 are basic\n");
  357. errors |= BIT(5);
  358. }
  359. if (le16_to_cpu(rxon->assoc_id) > 2007) {
  360. IWL_WARN(priv, "aid > 2007\n");
  361. errors |= BIT(6);
  362. }
  363. if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
  364. == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) {
  365. IWL_WARN(priv, "CCK and short slot\n");
  366. errors |= BIT(7);
  367. }
  368. if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
  369. == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) {
  370. IWL_WARN(priv, "CCK and auto detect");
  371. errors |= BIT(8);
  372. }
  373. if ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
  374. RXON_FLG_TGG_PROTECT_MSK)) ==
  375. RXON_FLG_TGG_PROTECT_MSK) {
  376. IWL_WARN(priv, "TGg but no auto-detect\n");
  377. errors |= BIT(9);
  378. }
  379. if (rxon->channel == 0) {
  380. IWL_WARN(priv, "zero channel is invalid\n");
  381. errors |= BIT(10);
  382. }
  383. WARN(errors, "Invalid RXON (%#x), channel %d",
  384. errors, le16_to_cpu(rxon->channel));
  385. return errors ? -EINVAL : 0;
  386. }
  387. /**
  388. * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
  389. * @priv: staging_rxon is compared to active_rxon
  390. *
  391. * If the RXON structure is changing enough to require a new tune,
  392. * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
  393. * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
  394. */
  395. int iwl_full_rxon_required(struct iwl_priv *priv,
  396. struct iwl_rxon_context *ctx)
  397. {
  398. const struct iwl_rxon_cmd *staging = &ctx->staging;
  399. const struct iwl_rxon_cmd *active = &ctx->active;
  400. #define CHK(cond) \
  401. if ((cond)) { \
  402. IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
  403. return 1; \
  404. }
  405. #define CHK_NEQ(c1, c2) \
  406. if ((c1) != (c2)) { \
  407. IWL_DEBUG_INFO(priv, "need full RXON - " \
  408. #c1 " != " #c2 " - %d != %d\n", \
  409. (c1), (c2)); \
  410. return 1; \
  411. }
  412. /* These items are only settable from the full RXON command */
  413. CHK(!iwl_is_associated_ctx(ctx));
  414. CHK(compare_ether_addr(staging->bssid_addr, active->bssid_addr));
  415. CHK(compare_ether_addr(staging->node_addr, active->node_addr));
  416. CHK(compare_ether_addr(staging->wlap_bssid_addr,
  417. active->wlap_bssid_addr));
  418. CHK_NEQ(staging->dev_type, active->dev_type);
  419. CHK_NEQ(staging->channel, active->channel);
  420. CHK_NEQ(staging->air_propagation, active->air_propagation);
  421. CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates,
  422. active->ofdm_ht_single_stream_basic_rates);
  423. CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates,
  424. active->ofdm_ht_dual_stream_basic_rates);
  425. CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates,
  426. active->ofdm_ht_triple_stream_basic_rates);
  427. CHK_NEQ(staging->assoc_id, active->assoc_id);
  428. /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
  429. * be updated with the RXON_ASSOC command -- however only some
  430. * flag transitions are allowed using RXON_ASSOC */
  431. /* Check if we are not switching bands */
  432. CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK,
  433. active->flags & RXON_FLG_BAND_24G_MSK);
  434. /* Check if we are switching association toggle */
  435. CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK,
  436. active->filter_flags & RXON_FILTER_ASSOC_MSK);
  437. #undef CHK
  438. #undef CHK_NEQ
  439. return 0;
  440. }
  441. static void _iwl_set_rxon_ht(struct iwl_priv *priv,
  442. struct iwl_ht_config *ht_conf,
  443. struct iwl_rxon_context *ctx)
  444. {
  445. struct iwl_rxon_cmd *rxon = &ctx->staging;
  446. if (!ctx->ht.enabled) {
  447. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
  448. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
  449. RXON_FLG_HT40_PROT_MSK |
  450. RXON_FLG_HT_PROT_MSK);
  451. return;
  452. }
  453. /* FIXME: if the definition of ht.protection changed, the "translation"
  454. * will be needed for rxon->flags
  455. */
  456. rxon->flags |= cpu_to_le32(ctx->ht.protection << RXON_FLG_HT_OPERATING_MODE_POS);
  457. /* Set up channel bandwidth:
  458. * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
  459. /* clear the HT channel mode before set the mode */
  460. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
  461. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  462. if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) {
  463. /* pure ht40 */
  464. if (ctx->ht.protection == IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
  465. rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
  466. /* Note: control channel is opposite of extension channel */
  467. switch (ctx->ht.extension_chan_offset) {
  468. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  469. rxon->flags &= ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  470. break;
  471. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  472. rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  473. break;
  474. }
  475. } else {
  476. /* Note: control channel is opposite of extension channel */
  477. switch (ctx->ht.extension_chan_offset) {
  478. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  479. rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  480. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
  481. break;
  482. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  483. rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  484. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
  485. break;
  486. case IEEE80211_HT_PARAM_CHA_SEC_NONE:
  487. default:
  488. /* channel location only valid if in Mixed mode */
  489. IWL_ERR(priv, "invalid extension channel offset\n");
  490. break;
  491. }
  492. }
  493. } else {
  494. rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
  495. }
  496. iwlagn_set_rxon_chain(priv, ctx);
  497. IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
  498. "extension channel offset 0x%x\n",
  499. le32_to_cpu(rxon->flags), ctx->ht.protection,
  500. ctx->ht.extension_chan_offset);
  501. }
  502. void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
  503. {
  504. struct iwl_rxon_context *ctx;
  505. for_each_context(priv, ctx)
  506. _iwl_set_rxon_ht(priv, ht_conf, ctx);
  507. }
  508. /* Return valid, unused, channel for a passive scan to reset the RF */
  509. u8 iwl_get_single_channel_number(struct iwl_priv *priv,
  510. enum ieee80211_band band)
  511. {
  512. const struct iwl_channel_info *ch_info;
  513. int i;
  514. u8 channel = 0;
  515. u8 min, max;
  516. struct iwl_rxon_context *ctx;
  517. if (band == IEEE80211_BAND_5GHZ) {
  518. min = 14;
  519. max = priv->channel_count;
  520. } else {
  521. min = 0;
  522. max = 14;
  523. }
  524. for (i = min; i < max; i++) {
  525. bool busy = false;
  526. for_each_context(priv, ctx) {
  527. busy = priv->channel_info[i].channel ==
  528. le16_to_cpu(ctx->staging.channel);
  529. if (busy)
  530. break;
  531. }
  532. if (busy)
  533. continue;
  534. channel = priv->channel_info[i].channel;
  535. ch_info = iwl_get_channel_info(priv, band, channel);
  536. if (is_channel_valid(ch_info))
  537. break;
  538. }
  539. return channel;
  540. }
  541. /**
  542. * iwl_set_rxon_channel - Set the band and channel values in staging RXON
  543. * @ch: requested channel as a pointer to struct ieee80211_channel
  544. * NOTE: Does not commit to the hardware; it sets appropriate bit fields
  545. * in the staging RXON flag structure based on the ch->band
  546. */
  547. int iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
  548. struct iwl_rxon_context *ctx)
  549. {
  550. enum ieee80211_band band = ch->band;
  551. u16 channel = ch->hw_value;
  552. if ((le16_to_cpu(ctx->staging.channel) == channel) &&
  553. (priv->band == band))
  554. return 0;
  555. ctx->staging.channel = cpu_to_le16(channel);
  556. if (band == IEEE80211_BAND_5GHZ)
  557. ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK;
  558. else
  559. ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
  560. priv->band = band;
  561. IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
  562. return 0;
  563. }
  564. void iwl_set_flags_for_band(struct iwl_priv *priv,
  565. struct iwl_rxon_context *ctx,
  566. enum ieee80211_band band,
  567. struct ieee80211_vif *vif)
  568. {
  569. if (band == IEEE80211_BAND_5GHZ) {
  570. ctx->staging.flags &=
  571. ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
  572. | RXON_FLG_CCK_MSK);
  573. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  574. } else {
  575. /* Copied from iwl_post_associate() */
  576. if (vif && vif->bss_conf.use_short_slot)
  577. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  578. else
  579. ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  580. ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
  581. ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK;
  582. ctx->staging.flags &= ~RXON_FLG_CCK_MSK;
  583. }
  584. }
  585. /*
  586. * initialize rxon structure with default values from eeprom
  587. */
  588. void iwl_connection_init_rx_config(struct iwl_priv *priv,
  589. struct iwl_rxon_context *ctx)
  590. {
  591. const struct iwl_channel_info *ch_info;
  592. memset(&ctx->staging, 0, sizeof(ctx->staging));
  593. if (!ctx->vif) {
  594. ctx->staging.dev_type = ctx->unused_devtype;
  595. } else switch (ctx->vif->type) {
  596. case NL80211_IFTYPE_AP:
  597. ctx->staging.dev_type = ctx->ap_devtype;
  598. break;
  599. case NL80211_IFTYPE_STATION:
  600. ctx->staging.dev_type = ctx->station_devtype;
  601. ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
  602. break;
  603. case NL80211_IFTYPE_ADHOC:
  604. ctx->staging.dev_type = ctx->ibss_devtype;
  605. ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
  606. ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
  607. RXON_FILTER_ACCEPT_GRP_MSK;
  608. break;
  609. default:
  610. IWL_ERR(priv, "Unsupported interface type %d\n",
  611. ctx->vif->type);
  612. break;
  613. }
  614. #if 0
  615. /* TODO: Figure out when short_preamble would be set and cache from
  616. * that */
  617. if (!hw_to_local(priv->hw)->short_preamble)
  618. ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  619. else
  620. ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  621. #endif
  622. ch_info = iwl_get_channel_info(priv, priv->band,
  623. le16_to_cpu(ctx->active.channel));
  624. if (!ch_info)
  625. ch_info = &priv->channel_info[0];
  626. ctx->staging.channel = cpu_to_le16(ch_info->channel);
  627. priv->band = ch_info->band;
  628. iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif);
  629. ctx->staging.ofdm_basic_rates =
  630. (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  631. ctx->staging.cck_basic_rates =
  632. (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  633. /* clear both MIX and PURE40 mode flag */
  634. ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
  635. RXON_FLG_CHANNEL_MODE_PURE_40);
  636. if (ctx->vif)
  637. memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN);
  638. ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff;
  639. ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff;
  640. ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff;
  641. }
  642. void iwl_set_rate(struct iwl_priv *priv)
  643. {
  644. const struct ieee80211_supported_band *hw = NULL;
  645. struct ieee80211_rate *rate;
  646. struct iwl_rxon_context *ctx;
  647. int i;
  648. hw = iwl_get_hw_mode(priv, priv->band);
  649. if (!hw) {
  650. IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
  651. return;
  652. }
  653. priv->active_rate = 0;
  654. for (i = 0; i < hw->n_bitrates; i++) {
  655. rate = &(hw->bitrates[i]);
  656. if (rate->hw_value < IWL_RATE_COUNT_LEGACY)
  657. priv->active_rate |= (1 << rate->hw_value);
  658. }
  659. IWL_DEBUG_RATE(priv, "Set active_rate = %0x\n", priv->active_rate);
  660. for_each_context(priv, ctx) {
  661. ctx->staging.cck_basic_rates =
  662. (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  663. ctx->staging.ofdm_basic_rates =
  664. (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  665. }
  666. }
  667. void iwl_chswitch_done(struct iwl_priv *priv, bool is_success)
  668. {
  669. /*
  670. * MULTI-FIXME
  671. * See iwlagn_mac_channel_switch.
  672. */
  673. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  674. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  675. return;
  676. if (test_and_clear_bit(STATUS_CHANNEL_SWITCH_PENDING,
  677. &priv->shrd->status))
  678. ieee80211_chswitch_done(ctx->vif, is_success);
  679. }
  680. #ifdef CONFIG_IWLWIFI_DEBUG
  681. void iwl_print_rx_config_cmd(struct iwl_priv *priv,
  682. enum iwl_rxon_context_id ctxid)
  683. {
  684. struct iwl_rxon_context *ctx = &priv->contexts[ctxid];
  685. struct iwl_rxon_cmd *rxon = &ctx->staging;
  686. IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
  687. iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
  688. IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
  689. IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
  690. IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
  691. le32_to_cpu(rxon->filter_flags));
  692. IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
  693. IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
  694. rxon->ofdm_basic_rates);
  695. IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
  696. IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
  697. IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
  698. IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
  699. }
  700. #endif
  701. static void iwlagn_abort_notification_waits(struct iwl_priv *priv)
  702. {
  703. unsigned long flags;
  704. struct iwl_notification_wait *wait_entry;
  705. spin_lock_irqsave(&priv->notif_wait_lock, flags);
  706. list_for_each_entry(wait_entry, &priv->notif_waits, list)
  707. wait_entry->aborted = true;
  708. spin_unlock_irqrestore(&priv->notif_wait_lock, flags);
  709. wake_up_all(&priv->notif_waitq);
  710. }
  711. void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand)
  712. {
  713. unsigned int reload_msec;
  714. unsigned long reload_jiffies;
  715. /* Set the FW error flag -- cleared on iwl_down */
  716. set_bit(STATUS_FW_ERROR, &priv->shrd->status);
  717. /* Cancel currently queued command. */
  718. clear_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status);
  719. iwlagn_abort_notification_waits(priv);
  720. /* Keep the restart process from trying to send host
  721. * commands by clearing the ready bit */
  722. clear_bit(STATUS_READY, &priv->shrd->status);
  723. wake_up(&priv->shrd->wait_command_queue);
  724. if (!ondemand) {
  725. /*
  726. * If firmware keep reloading, then it indicate something
  727. * serious wrong and firmware having problem to recover
  728. * from it. Instead of keep trying which will fill the syslog
  729. * and hang the system, let's just stop it
  730. */
  731. reload_jiffies = jiffies;
  732. reload_msec = jiffies_to_msecs((long) reload_jiffies -
  733. (long) priv->reload_jiffies);
  734. priv->reload_jiffies = reload_jiffies;
  735. if (reload_msec <= IWL_MIN_RELOAD_DURATION) {
  736. priv->reload_count++;
  737. if (priv->reload_count >= IWL_MAX_CONTINUE_RELOAD_CNT) {
  738. IWL_ERR(priv, "BUG_ON, Stop restarting\n");
  739. return;
  740. }
  741. } else
  742. priv->reload_count = 0;
  743. }
  744. if (!test_bit(STATUS_EXIT_PENDING, &priv->shrd->status)) {
  745. if (iwlagn_mod_params.restart_fw) {
  746. IWL_DEBUG_FW_ERRORS(priv,
  747. "Restarting adapter due to uCode error.\n");
  748. queue_work(priv->shrd->workqueue, &priv->restart);
  749. } else
  750. IWL_DEBUG_FW_ERRORS(priv,
  751. "Detected FW error, but not restarting\n");
  752. }
  753. }
  754. static int iwl_apm_stop_master(struct iwl_priv *priv)
  755. {
  756. int ret = 0;
  757. /* stop device's busmaster DMA activity */
  758. iwl_set_bit(bus(priv), CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
  759. ret = iwl_poll_bit(bus(priv), CSR_RESET,
  760. CSR_RESET_REG_FLAG_MASTER_DISABLED,
  761. CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
  762. if (ret)
  763. IWL_WARN(priv, "Master Disable Timed Out, 100 usec\n");
  764. IWL_DEBUG_INFO(priv, "stop master\n");
  765. return ret;
  766. }
  767. void iwl_apm_stop(struct iwl_priv *priv)
  768. {
  769. IWL_DEBUG_INFO(priv, "Stop card, put in low power state\n");
  770. clear_bit(STATUS_DEVICE_ENABLED, &priv->shrd->status);
  771. /* Stop device's DMA activity */
  772. iwl_apm_stop_master(priv);
  773. /* Reset the entire device */
  774. iwl_set_bit(bus(priv), CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  775. udelay(10);
  776. /*
  777. * Clear "initialization complete" bit to move adapter from
  778. * D0A* (powered-up Active) --> D0U* (Uninitialized) state.
  779. */
  780. iwl_clear_bit(bus(priv), CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  781. }
  782. /*
  783. * Start up NIC's basic functionality after it has been reset
  784. * (e.g. after platform boot, or shutdown via iwl_apm_stop())
  785. * NOTE: This does not load uCode nor start the embedded processor
  786. */
  787. int iwl_apm_init(struct iwl_priv *priv)
  788. {
  789. int ret = 0;
  790. IWL_DEBUG_INFO(priv, "Init card's basic functions\n");
  791. /*
  792. * Use "set_bit" below rather than "write", to preserve any hardware
  793. * bits already set by default after reset.
  794. */
  795. /* Disable L0S exit timer (platform NMI Work/Around) */
  796. iwl_set_bit(bus(priv), CSR_GIO_CHICKEN_BITS,
  797. CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
  798. /*
  799. * Disable L0s without affecting L1;
  800. * don't wait for ICH L0s (ICH bug W/A)
  801. */
  802. iwl_set_bit(bus(priv), CSR_GIO_CHICKEN_BITS,
  803. CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
  804. /* Set FH wait threshold to maximum (HW error during stress W/A) */
  805. iwl_set_bit(bus(priv), CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL);
  806. /*
  807. * Enable HAP INTA (interrupt from management bus) to
  808. * wake device's PCI Express link L1a -> L0s
  809. */
  810. iwl_set_bit(bus(priv), CSR_HW_IF_CONFIG_REG,
  811. CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A);
  812. bus_apm_config(bus(priv));
  813. /* Configure analog phase-lock-loop before activating to D0A */
  814. if (priv->cfg->base_params->pll_cfg_val)
  815. iwl_set_bit(bus(priv), CSR_ANA_PLL_CFG,
  816. priv->cfg->base_params->pll_cfg_val);
  817. /*
  818. * Set "initialization complete" bit to move adapter from
  819. * D0U* --> D0A* (powered-up active) state.
  820. */
  821. iwl_set_bit(bus(priv), CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  822. /*
  823. * Wait for clock stabilization; once stabilized, access to
  824. * device-internal resources is supported, e.g. iwl_write_prph()
  825. * and accesses to uCode SRAM.
  826. */
  827. ret = iwl_poll_bit(bus(priv), CSR_GP_CNTRL,
  828. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  829. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  830. if (ret < 0) {
  831. IWL_DEBUG_INFO(priv, "Failed to init the card\n");
  832. goto out;
  833. }
  834. /*
  835. * Enable DMA clock and wait for it to stabilize.
  836. *
  837. * Write to "CLK_EN_REG"; "1" bits enable clocks, while "0" bits
  838. * do not disable clocks. This preserves any hardware bits already
  839. * set by default in "CLK_CTRL_REG" after reset.
  840. */
  841. iwl_write_prph(bus(priv), APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT);
  842. udelay(20);
  843. /* Disable L1-Active */
  844. iwl_set_bits_prph(bus(priv), APMG_PCIDEV_STT_REG,
  845. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  846. set_bit(STATUS_DEVICE_ENABLED, &priv->shrd->status);
  847. out:
  848. return ret;
  849. }
  850. int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
  851. {
  852. int ret;
  853. s8 prev_tx_power;
  854. bool defer;
  855. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  856. lockdep_assert_held(&priv->shrd->mutex);
  857. if (priv->tx_power_user_lmt == tx_power && !force)
  858. return 0;
  859. if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) {
  860. IWL_WARN(priv,
  861. "Requested user TXPOWER %d below lower limit %d.\n",
  862. tx_power,
  863. IWLAGN_TX_POWER_TARGET_POWER_MIN);
  864. return -EINVAL;
  865. }
  866. if (tx_power > priv->tx_power_device_lmt) {
  867. IWL_WARN(priv,
  868. "Requested user TXPOWER %d above upper limit %d.\n",
  869. tx_power, priv->tx_power_device_lmt);
  870. return -EINVAL;
  871. }
  872. if (!iwl_is_ready_rf(priv->shrd))
  873. return -EIO;
  874. /* scan complete and commit_rxon use tx_power_next value,
  875. * it always need to be updated for newest request */
  876. priv->tx_power_next = tx_power;
  877. /* do not set tx power when scanning or channel changing */
  878. defer = test_bit(STATUS_SCANNING, &priv->shrd->status) ||
  879. memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging));
  880. if (defer && !force) {
  881. IWL_DEBUG_INFO(priv, "Deferring tx power set\n");
  882. return 0;
  883. }
  884. prev_tx_power = priv->tx_power_user_lmt;
  885. priv->tx_power_user_lmt = tx_power;
  886. ret = iwlagn_send_tx_power(priv);
  887. /* if fail to set tx_power, restore the orig. tx power */
  888. if (ret) {
  889. priv->tx_power_user_lmt = prev_tx_power;
  890. priv->tx_power_next = prev_tx_power;
  891. }
  892. return ret;
  893. }
  894. void iwl_send_bt_config(struct iwl_priv *priv)
  895. {
  896. struct iwl_bt_cmd bt_cmd = {
  897. .lead_time = BT_LEAD_TIME_DEF,
  898. .max_kill = BT_MAX_KILL_DEF,
  899. .kill_ack_mask = 0,
  900. .kill_cts_mask = 0,
  901. };
  902. if (!iwlagn_mod_params.bt_coex_active)
  903. bt_cmd.flags = BT_COEX_DISABLE;
  904. else
  905. bt_cmd.flags = BT_COEX_ENABLE;
  906. priv->bt_enable_flag = bt_cmd.flags;
  907. IWL_DEBUG_INFO(priv, "BT coex %s\n",
  908. (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
  909. if (iwl_trans_send_cmd_pdu(trans(priv), REPLY_BT_CONFIG,
  910. CMD_SYNC, sizeof(struct iwl_bt_cmd), &bt_cmd))
  911. IWL_ERR(priv, "failed to send BT Coex Config\n");
  912. }
  913. int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
  914. {
  915. struct iwl_statistics_cmd statistics_cmd = {
  916. .configuration_flags =
  917. clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
  918. };
  919. if (flags & CMD_ASYNC)
  920. return iwl_trans_send_cmd_pdu(trans(priv), REPLY_STATISTICS_CMD,
  921. CMD_ASYNC,
  922. sizeof(struct iwl_statistics_cmd),
  923. &statistics_cmd);
  924. else
  925. return iwl_trans_send_cmd_pdu(trans(priv), REPLY_STATISTICS_CMD,
  926. CMD_SYNC,
  927. sizeof(struct iwl_statistics_cmd),
  928. &statistics_cmd);
  929. }
  930. #ifdef CONFIG_IWLWIFI_DEBUGFS
  931. #define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES)
  932. void iwl_reset_traffic_log(struct iwl_priv *priv)
  933. {
  934. priv->tx_traffic_idx = 0;
  935. priv->rx_traffic_idx = 0;
  936. if (priv->tx_traffic)
  937. memset(priv->tx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
  938. if (priv->rx_traffic)
  939. memset(priv->rx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
  940. }
  941. int iwl_alloc_traffic_mem(struct iwl_priv *priv)
  942. {
  943. u32 traffic_size = IWL_TRAFFIC_DUMP_SIZE;
  944. if (iwl_get_debug_level(priv->shrd) & IWL_DL_TX) {
  945. if (!priv->tx_traffic) {
  946. priv->tx_traffic =
  947. kzalloc(traffic_size, GFP_KERNEL);
  948. if (!priv->tx_traffic)
  949. return -ENOMEM;
  950. }
  951. }
  952. if (iwl_get_debug_level(priv->shrd) & IWL_DL_RX) {
  953. if (!priv->rx_traffic) {
  954. priv->rx_traffic =
  955. kzalloc(traffic_size, GFP_KERNEL);
  956. if (!priv->rx_traffic)
  957. return -ENOMEM;
  958. }
  959. }
  960. iwl_reset_traffic_log(priv);
  961. return 0;
  962. }
  963. void iwl_free_traffic_mem(struct iwl_priv *priv)
  964. {
  965. kfree(priv->tx_traffic);
  966. priv->tx_traffic = NULL;
  967. kfree(priv->rx_traffic);
  968. priv->rx_traffic = NULL;
  969. }
  970. void iwl_dbg_log_tx_data_frame(struct iwl_priv *priv,
  971. u16 length, struct ieee80211_hdr *header)
  972. {
  973. __le16 fc;
  974. u16 len;
  975. if (likely(!(iwl_get_debug_level(priv->shrd) & IWL_DL_TX)))
  976. return;
  977. if (!priv->tx_traffic)
  978. return;
  979. fc = header->frame_control;
  980. if (ieee80211_is_data(fc)) {
  981. len = (length > IWL_TRAFFIC_ENTRY_SIZE)
  982. ? IWL_TRAFFIC_ENTRY_SIZE : length;
  983. memcpy((priv->tx_traffic +
  984. (priv->tx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
  985. header, len);
  986. priv->tx_traffic_idx =
  987. (priv->tx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
  988. }
  989. }
  990. void iwl_dbg_log_rx_data_frame(struct iwl_priv *priv,
  991. u16 length, struct ieee80211_hdr *header)
  992. {
  993. __le16 fc;
  994. u16 len;
  995. if (likely(!(iwl_get_debug_level(priv->shrd) & IWL_DL_RX)))
  996. return;
  997. if (!priv->rx_traffic)
  998. return;
  999. fc = header->frame_control;
  1000. if (ieee80211_is_data(fc)) {
  1001. len = (length > IWL_TRAFFIC_ENTRY_SIZE)
  1002. ? IWL_TRAFFIC_ENTRY_SIZE : length;
  1003. memcpy((priv->rx_traffic +
  1004. (priv->rx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
  1005. header, len);
  1006. priv->rx_traffic_idx =
  1007. (priv->rx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
  1008. }
  1009. }
  1010. const char *get_mgmt_string(int cmd)
  1011. {
  1012. switch (cmd) {
  1013. IWL_CMD(MANAGEMENT_ASSOC_REQ);
  1014. IWL_CMD(MANAGEMENT_ASSOC_RESP);
  1015. IWL_CMD(MANAGEMENT_REASSOC_REQ);
  1016. IWL_CMD(MANAGEMENT_REASSOC_RESP);
  1017. IWL_CMD(MANAGEMENT_PROBE_REQ);
  1018. IWL_CMD(MANAGEMENT_PROBE_RESP);
  1019. IWL_CMD(MANAGEMENT_BEACON);
  1020. IWL_CMD(MANAGEMENT_ATIM);
  1021. IWL_CMD(MANAGEMENT_DISASSOC);
  1022. IWL_CMD(MANAGEMENT_AUTH);
  1023. IWL_CMD(MANAGEMENT_DEAUTH);
  1024. IWL_CMD(MANAGEMENT_ACTION);
  1025. default:
  1026. return "UNKNOWN";
  1027. }
  1028. }
  1029. const char *get_ctrl_string(int cmd)
  1030. {
  1031. switch (cmd) {
  1032. IWL_CMD(CONTROL_BACK_REQ);
  1033. IWL_CMD(CONTROL_BACK);
  1034. IWL_CMD(CONTROL_PSPOLL);
  1035. IWL_CMD(CONTROL_RTS);
  1036. IWL_CMD(CONTROL_CTS);
  1037. IWL_CMD(CONTROL_ACK);
  1038. IWL_CMD(CONTROL_CFEND);
  1039. IWL_CMD(CONTROL_CFENDACK);
  1040. default:
  1041. return "UNKNOWN";
  1042. }
  1043. }
  1044. void iwl_clear_traffic_stats(struct iwl_priv *priv)
  1045. {
  1046. memset(&priv->tx_stats, 0, sizeof(struct traffic_stats));
  1047. memset(&priv->rx_stats, 0, sizeof(struct traffic_stats));
  1048. }
  1049. /*
  1050. * if CONFIG_IWLWIFI_DEBUGFS defined, iwl_update_stats function will
  1051. * record all the MGMT, CTRL and DATA pkt for both TX and Rx pass.
  1052. * Use debugFs to display the rx/rx_statistics
  1053. * if CONFIG_IWLWIFI_DEBUGFS not being defined, then no MGMT and CTRL
  1054. * information will be recorded, but DATA pkt still will be recorded
  1055. * for the reason of iwl_led.c need to control the led blinking based on
  1056. * number of tx and rx data.
  1057. *
  1058. */
  1059. void iwl_update_stats(struct iwl_priv *priv, bool is_tx, __le16 fc, u16 len)
  1060. {
  1061. struct traffic_stats *stats;
  1062. if (is_tx)
  1063. stats = &priv->tx_stats;
  1064. else
  1065. stats = &priv->rx_stats;
  1066. if (ieee80211_is_mgmt(fc)) {
  1067. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  1068. case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
  1069. stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
  1070. break;
  1071. case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
  1072. stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
  1073. break;
  1074. case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
  1075. stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
  1076. break;
  1077. case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
  1078. stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
  1079. break;
  1080. case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
  1081. stats->mgmt[MANAGEMENT_PROBE_REQ]++;
  1082. break;
  1083. case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
  1084. stats->mgmt[MANAGEMENT_PROBE_RESP]++;
  1085. break;
  1086. case cpu_to_le16(IEEE80211_STYPE_BEACON):
  1087. stats->mgmt[MANAGEMENT_BEACON]++;
  1088. break;
  1089. case cpu_to_le16(IEEE80211_STYPE_ATIM):
  1090. stats->mgmt[MANAGEMENT_ATIM]++;
  1091. break;
  1092. case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
  1093. stats->mgmt[MANAGEMENT_DISASSOC]++;
  1094. break;
  1095. case cpu_to_le16(IEEE80211_STYPE_AUTH):
  1096. stats->mgmt[MANAGEMENT_AUTH]++;
  1097. break;
  1098. case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
  1099. stats->mgmt[MANAGEMENT_DEAUTH]++;
  1100. break;
  1101. case cpu_to_le16(IEEE80211_STYPE_ACTION):
  1102. stats->mgmt[MANAGEMENT_ACTION]++;
  1103. break;
  1104. }
  1105. } else if (ieee80211_is_ctl(fc)) {
  1106. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  1107. case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
  1108. stats->ctrl[CONTROL_BACK_REQ]++;
  1109. break;
  1110. case cpu_to_le16(IEEE80211_STYPE_BACK):
  1111. stats->ctrl[CONTROL_BACK]++;
  1112. break;
  1113. case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
  1114. stats->ctrl[CONTROL_PSPOLL]++;
  1115. break;
  1116. case cpu_to_le16(IEEE80211_STYPE_RTS):
  1117. stats->ctrl[CONTROL_RTS]++;
  1118. break;
  1119. case cpu_to_le16(IEEE80211_STYPE_CTS):
  1120. stats->ctrl[CONTROL_CTS]++;
  1121. break;
  1122. case cpu_to_le16(IEEE80211_STYPE_ACK):
  1123. stats->ctrl[CONTROL_ACK]++;
  1124. break;
  1125. case cpu_to_le16(IEEE80211_STYPE_CFEND):
  1126. stats->ctrl[CONTROL_CFEND]++;
  1127. break;
  1128. case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
  1129. stats->ctrl[CONTROL_CFENDACK]++;
  1130. break;
  1131. }
  1132. } else {
  1133. /* data */
  1134. stats->data_cnt++;
  1135. stats->data_bytes += len;
  1136. }
  1137. }
  1138. #endif
  1139. static void iwl_force_rf_reset(struct iwl_priv *priv)
  1140. {
  1141. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  1142. return;
  1143. if (!iwl_is_any_associated(priv)) {
  1144. IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n");
  1145. return;
  1146. }
  1147. /*
  1148. * There is no easy and better way to force reset the radio,
  1149. * the only known method is switching channel which will force to
  1150. * reset and tune the radio.
  1151. * Use internal short scan (single channel) operation to should
  1152. * achieve this objective.
  1153. * Driver should reset the radio when number of consecutive missed
  1154. * beacon, or any other uCode error condition detected.
  1155. */
  1156. IWL_DEBUG_INFO(priv, "perform radio reset.\n");
  1157. iwl_internal_short_hw_scan(priv);
  1158. }
  1159. int iwl_force_reset(struct iwl_priv *priv, int mode, bool external)
  1160. {
  1161. struct iwl_force_reset *force_reset;
  1162. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  1163. return -EINVAL;
  1164. if (mode >= IWL_MAX_FORCE_RESET) {
  1165. IWL_DEBUG_INFO(priv, "invalid reset request.\n");
  1166. return -EINVAL;
  1167. }
  1168. force_reset = &priv->force_reset[mode];
  1169. force_reset->reset_request_count++;
  1170. if (!external) {
  1171. if (force_reset->last_force_reset_jiffies &&
  1172. time_after(force_reset->last_force_reset_jiffies +
  1173. force_reset->reset_duration, jiffies)) {
  1174. IWL_DEBUG_INFO(priv, "force reset rejected\n");
  1175. force_reset->reset_reject_count++;
  1176. return -EAGAIN;
  1177. }
  1178. }
  1179. force_reset->reset_success_count++;
  1180. force_reset->last_force_reset_jiffies = jiffies;
  1181. IWL_DEBUG_INFO(priv, "perform force reset (%d)\n", mode);
  1182. switch (mode) {
  1183. case IWL_RF_RESET:
  1184. iwl_force_rf_reset(priv);
  1185. break;
  1186. case IWL_FW_RESET:
  1187. /*
  1188. * if the request is from external(ex: debugfs),
  1189. * then always perform the request in regardless the module
  1190. * parameter setting
  1191. * if the request is from internal (uCode error or driver
  1192. * detect failure), then fw_restart module parameter
  1193. * need to be check before performing firmware reload
  1194. */
  1195. if (!external && !iwlagn_mod_params.restart_fw) {
  1196. IWL_DEBUG_INFO(priv, "Cancel firmware reload based on "
  1197. "module parameter setting\n");
  1198. break;
  1199. }
  1200. IWL_ERR(priv, "On demand firmware reload\n");
  1201. iwlagn_fw_error(priv, true);
  1202. break;
  1203. }
  1204. return 0;
  1205. }
  1206. int iwl_cmd_echo_test(struct iwl_priv *priv)
  1207. {
  1208. int ret;
  1209. struct iwl_host_cmd cmd = {
  1210. .id = REPLY_ECHO,
  1211. .len = { 0 },
  1212. .flags = CMD_SYNC,
  1213. };
  1214. ret = iwl_trans_send_cmd(trans(priv), &cmd);
  1215. if (ret)
  1216. IWL_ERR(priv, "echo testing fail: 0X%x\n", ret);
  1217. else
  1218. IWL_DEBUG_INFO(priv, "echo testing pass\n");
  1219. return ret;
  1220. }
  1221. static inline int iwl_check_stuck_queue(struct iwl_priv *priv, int txq)
  1222. {
  1223. if (iwl_trans_check_stuck_queue(trans(priv), txq)) {
  1224. int ret;
  1225. ret = iwl_force_reset(priv, IWL_FW_RESET, false);
  1226. return (ret == -EAGAIN) ? 0 : 1;
  1227. }
  1228. return 0;
  1229. }
  1230. /*
  1231. * Making watchdog tick be a quarter of timeout assure we will
  1232. * discover the queue hung between timeout and 1.25*timeout
  1233. */
  1234. #define IWL_WD_TICK(timeout) ((timeout) / 4)
  1235. /*
  1236. * Watchdog timer callback, we check each tx queue for stuck, if if hung
  1237. * we reset the firmware. If everything is fine just rearm the timer.
  1238. */
  1239. void iwl_bg_watchdog(unsigned long data)
  1240. {
  1241. struct iwl_priv *priv = (struct iwl_priv *)data;
  1242. int cnt;
  1243. unsigned long timeout;
  1244. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  1245. return;
  1246. if (iwl_is_rfkill(priv->shrd))
  1247. return;
  1248. timeout = priv->cfg->base_params->wd_timeout;
  1249. if (timeout == 0)
  1250. return;
  1251. /* monitor and check for stuck cmd queue */
  1252. if (iwl_check_stuck_queue(priv, priv->shrd->cmd_queue))
  1253. return;
  1254. /* monitor and check for other stuck queues */
  1255. if (iwl_is_any_associated(priv)) {
  1256. for (cnt = 0; cnt < hw_params(priv).max_txq_num; cnt++) {
  1257. /* skip as we already checked the command queue */
  1258. if (cnt == priv->shrd->cmd_queue)
  1259. continue;
  1260. if (iwl_check_stuck_queue(priv, cnt))
  1261. return;
  1262. }
  1263. }
  1264. mod_timer(&priv->watchdog, jiffies +
  1265. msecs_to_jiffies(IWL_WD_TICK(timeout)));
  1266. }
  1267. void iwl_setup_watchdog(struct iwl_priv *priv)
  1268. {
  1269. unsigned int timeout = priv->cfg->base_params->wd_timeout;
  1270. if (!iwlagn_mod_params.wd_disable) {
  1271. /* use system default */
  1272. if (timeout && !priv->cfg->base_params->wd_disable)
  1273. mod_timer(&priv->watchdog,
  1274. jiffies +
  1275. msecs_to_jiffies(IWL_WD_TICK(timeout)));
  1276. else
  1277. del_timer(&priv->watchdog);
  1278. } else {
  1279. /* module parameter overwrite default configuration */
  1280. if (timeout && iwlagn_mod_params.wd_disable == 2)
  1281. mod_timer(&priv->watchdog,
  1282. jiffies +
  1283. msecs_to_jiffies(IWL_WD_TICK(timeout)));
  1284. else
  1285. del_timer(&priv->watchdog);
  1286. }
  1287. }
  1288. /**
  1289. * iwl_beacon_time_mask_low - mask of lower 32 bit of beacon time
  1290. * @priv -- pointer to iwl_priv data structure
  1291. * @tsf_bits -- number of bits need to shift for masking)
  1292. */
  1293. static inline u32 iwl_beacon_time_mask_low(struct iwl_priv *priv,
  1294. u16 tsf_bits)
  1295. {
  1296. return (1 << tsf_bits) - 1;
  1297. }
  1298. /**
  1299. * iwl_beacon_time_mask_high - mask of higher 32 bit of beacon time
  1300. * @priv -- pointer to iwl_priv data structure
  1301. * @tsf_bits -- number of bits need to shift for masking)
  1302. */
  1303. static inline u32 iwl_beacon_time_mask_high(struct iwl_priv *priv,
  1304. u16 tsf_bits)
  1305. {
  1306. return ((1 << (32 - tsf_bits)) - 1) << tsf_bits;
  1307. }
  1308. /*
  1309. * extended beacon time format
  1310. * time in usec will be changed into a 32-bit value in extended:internal format
  1311. * the extended part is the beacon counts
  1312. * the internal part is the time in usec within one beacon interval
  1313. */
  1314. u32 iwl_usecs_to_beacons(struct iwl_priv *priv, u32 usec, u32 beacon_interval)
  1315. {
  1316. u32 quot;
  1317. u32 rem;
  1318. u32 interval = beacon_interval * TIME_UNIT;
  1319. if (!interval || !usec)
  1320. return 0;
  1321. quot = (usec / interval) &
  1322. (iwl_beacon_time_mask_high(priv, IWLAGN_EXT_BEACON_TIME_POS) >>
  1323. IWLAGN_EXT_BEACON_TIME_POS);
  1324. rem = (usec % interval) & iwl_beacon_time_mask_low(priv,
  1325. IWLAGN_EXT_BEACON_TIME_POS);
  1326. return (quot << IWLAGN_EXT_BEACON_TIME_POS) + rem;
  1327. }
  1328. /* base is usually what we get from ucode with each received frame,
  1329. * the same as HW timer counter counting down
  1330. */
  1331. __le32 iwl_add_beacon_time(struct iwl_priv *priv, u32 base,
  1332. u32 addon, u32 beacon_interval)
  1333. {
  1334. u32 base_low = base & iwl_beacon_time_mask_low(priv,
  1335. IWLAGN_EXT_BEACON_TIME_POS);
  1336. u32 addon_low = addon & iwl_beacon_time_mask_low(priv,
  1337. IWLAGN_EXT_BEACON_TIME_POS);
  1338. u32 interval = beacon_interval * TIME_UNIT;
  1339. u32 res = (base & iwl_beacon_time_mask_high(priv,
  1340. IWLAGN_EXT_BEACON_TIME_POS)) +
  1341. (addon & iwl_beacon_time_mask_high(priv,
  1342. IWLAGN_EXT_BEACON_TIME_POS));
  1343. if (base_low > addon_low)
  1344. res += base_low - addon_low;
  1345. else if (base_low < addon_low) {
  1346. res += interval + base_low - addon_low;
  1347. res += (1 << IWLAGN_EXT_BEACON_TIME_POS);
  1348. } else
  1349. res += (1 << IWLAGN_EXT_BEACON_TIME_POS);
  1350. return cpu_to_le32(res);
  1351. }
  1352. void iwl_start_tx_ba_trans_ready(struct iwl_priv *priv,
  1353. enum iwl_rxon_context_id ctx,
  1354. u8 sta_id, u8 tid)
  1355. {
  1356. struct ieee80211_vif *vif;
  1357. u8 *addr = priv->stations[sta_id].sta.sta.addr;
  1358. if (ctx == NUM_IWL_RXON_CTX)
  1359. ctx = priv->stations[sta_id].ctxid;
  1360. vif = priv->contexts[ctx].vif;
  1361. ieee80211_start_tx_ba_cb_irqsafe(vif, addr, tid);
  1362. }
  1363. void iwl_stop_tx_ba_trans_ready(struct iwl_priv *priv,
  1364. enum iwl_rxon_context_id ctx,
  1365. u8 sta_id, u8 tid)
  1366. {
  1367. struct ieee80211_vif *vif;
  1368. u8 *addr = priv->stations[sta_id].sta.sta.addr;
  1369. if (ctx == NUM_IWL_RXON_CTX)
  1370. ctx = priv->stations[sta_id].ctxid;
  1371. vif = priv->contexts[ctx].vif;
  1372. ieee80211_stop_tx_ba_cb_irqsafe(vif, addr, tid);
  1373. }
  1374. void iwl_set_hw_rfkill_state(struct iwl_priv *priv, bool state)
  1375. {
  1376. wiphy_rfkill_set_hw_state(priv->hw->wiphy, state);
  1377. }
  1378. void iwl_nic_config(struct iwl_priv *priv)
  1379. {
  1380. priv->cfg->lib->nic_config(priv);
  1381. }
  1382. void iwl_free_skb(struct iwl_priv *priv, struct sk_buff *skb)
  1383. {
  1384. struct ieee80211_tx_info *info;
  1385. info = IEEE80211_SKB_CB(skb);
  1386. kmem_cache_free(priv->tx_cmd_pool, (info->driver_data[1]));
  1387. dev_kfree_skb_any(skb);
  1388. }
  1389. void iwl_stop_sw_queue(struct iwl_priv *priv, u8 ac)
  1390. {
  1391. ieee80211_stop_queue(priv->hw, ac);
  1392. }
  1393. void iwl_wake_sw_queue(struct iwl_priv *priv, u8 ac)
  1394. {
  1395. ieee80211_wake_queue(priv->hw, ac);
  1396. }