iwl-agn-rxon.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. * Contact Information:
  22. * Intel Linux Wireless <ilw@linux.intel.com>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. *****************************************************************************/
  26. #include "iwl-dev.h"
  27. #include "iwl-agn.h"
  28. #include "iwl-sta.h"
  29. #include "iwl-core.h"
  30. #include "iwl-agn-calib.h"
  31. #include "iwl-helpers.h"
  32. static int iwlagn_disable_bss(struct iwl_priv *priv,
  33. struct iwl_rxon_context *ctx,
  34. struct iwl_rxon_cmd *send)
  35. {
  36. __le32 old_filter = send->filter_flags;
  37. int ret;
  38. send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  39. ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd, sizeof(*send), send);
  40. send->filter_flags = old_filter;
  41. if (ret)
  42. IWL_ERR(priv, "Error clearing ASSOC_MSK on BSS (%d)\n", ret);
  43. return ret;
  44. }
  45. static int iwlagn_disable_pan(struct iwl_priv *priv,
  46. struct iwl_rxon_context *ctx,
  47. struct iwl_rxon_cmd *send)
  48. {
  49. struct iwl_notification_wait disable_wait;
  50. __le32 old_filter = send->filter_flags;
  51. u8 old_dev_type = send->dev_type;
  52. int ret;
  53. iwlagn_init_notification_wait(priv, &disable_wait,
  54. REPLY_WIPAN_DEACTIVATION_COMPLETE,
  55. NULL, NULL);
  56. send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  57. send->dev_type = RXON_DEV_TYPE_P2P;
  58. ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd, sizeof(*send), send);
  59. send->filter_flags = old_filter;
  60. send->dev_type = old_dev_type;
  61. if (ret) {
  62. IWL_ERR(priv, "Error disabling PAN (%d)\n", ret);
  63. iwlagn_remove_notification(priv, &disable_wait);
  64. } else {
  65. ret = iwlagn_wait_notification(priv, &disable_wait, HZ);
  66. if (ret)
  67. IWL_ERR(priv, "Timed out waiting for PAN disable\n");
  68. }
  69. return ret;
  70. }
  71. static void iwlagn_update_qos(struct iwl_priv *priv,
  72. struct iwl_rxon_context *ctx)
  73. {
  74. int ret;
  75. if (!ctx->is_active)
  76. return;
  77. ctx->qos_data.def_qos_parm.qos_flags = 0;
  78. if (ctx->qos_data.qos_active)
  79. ctx->qos_data.def_qos_parm.qos_flags |=
  80. QOS_PARAM_FLG_UPDATE_EDCA_MSK;
  81. if (ctx->ht.enabled)
  82. ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
  83. IWL_DEBUG_QOS(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
  84. ctx->qos_data.qos_active,
  85. ctx->qos_data.def_qos_parm.qos_flags);
  86. ret = iwl_send_cmd_pdu(priv, ctx->qos_cmd,
  87. sizeof(struct iwl_qosparam_cmd),
  88. &ctx->qos_data.def_qos_parm);
  89. if (ret)
  90. IWL_ERR(priv, "Failed to update QoS\n");
  91. }
  92. static int iwlagn_update_beacon(struct iwl_priv *priv,
  93. struct ieee80211_vif *vif)
  94. {
  95. lockdep_assert_held(&priv->mutex);
  96. dev_kfree_skb(priv->beacon_skb);
  97. priv->beacon_skb = ieee80211_beacon_get(priv->hw, vif);
  98. if (!priv->beacon_skb)
  99. return -ENOMEM;
  100. return iwlagn_send_beacon_cmd(priv);
  101. }
  102. static int iwlagn_send_rxon_assoc(struct iwl_priv *priv,
  103. struct iwl_rxon_context *ctx)
  104. {
  105. int ret = 0;
  106. struct iwl_rxon_assoc_cmd rxon_assoc;
  107. const struct iwl_rxon_cmd *rxon1 = &ctx->staging;
  108. const struct iwl_rxon_cmd *rxon2 = &ctx->active;
  109. if ((rxon1->flags == rxon2->flags) &&
  110. (rxon1->filter_flags == rxon2->filter_flags) &&
  111. (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
  112. (rxon1->ofdm_ht_single_stream_basic_rates ==
  113. rxon2->ofdm_ht_single_stream_basic_rates) &&
  114. (rxon1->ofdm_ht_dual_stream_basic_rates ==
  115. rxon2->ofdm_ht_dual_stream_basic_rates) &&
  116. (rxon1->ofdm_ht_triple_stream_basic_rates ==
  117. rxon2->ofdm_ht_triple_stream_basic_rates) &&
  118. (rxon1->acquisition_data == rxon2->acquisition_data) &&
  119. (rxon1->rx_chain == rxon2->rx_chain) &&
  120. (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
  121. IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
  122. return 0;
  123. }
  124. rxon_assoc.flags = ctx->staging.flags;
  125. rxon_assoc.filter_flags = ctx->staging.filter_flags;
  126. rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates;
  127. rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates;
  128. rxon_assoc.reserved1 = 0;
  129. rxon_assoc.reserved2 = 0;
  130. rxon_assoc.reserved3 = 0;
  131. rxon_assoc.ofdm_ht_single_stream_basic_rates =
  132. ctx->staging.ofdm_ht_single_stream_basic_rates;
  133. rxon_assoc.ofdm_ht_dual_stream_basic_rates =
  134. ctx->staging.ofdm_ht_dual_stream_basic_rates;
  135. rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain;
  136. rxon_assoc.ofdm_ht_triple_stream_basic_rates =
  137. ctx->staging.ofdm_ht_triple_stream_basic_rates;
  138. rxon_assoc.acquisition_data = ctx->staging.acquisition_data;
  139. ret = iwl_send_cmd_pdu_async(priv, ctx->rxon_assoc_cmd,
  140. sizeof(rxon_assoc), &rxon_assoc, NULL);
  141. if (ret)
  142. return ret;
  143. return ret;
  144. }
  145. /**
  146. * iwlagn_commit_rxon - commit staging_rxon to hardware
  147. *
  148. * The RXON command in staging_rxon is committed to the hardware and
  149. * the active_rxon structure is updated with the new data. This
  150. * function correctly transitions out of the RXON_ASSOC_MSK state if
  151. * a HW tune is required based on the RXON structure changes.
  152. */
  153. int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  154. {
  155. /* cast away the const for active_rxon in this function */
  156. struct iwl_rxon_cmd *active = (void *)&ctx->active;
  157. bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
  158. bool old_assoc = !!(ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK);
  159. int ret;
  160. lockdep_assert_held(&priv->mutex);
  161. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  162. return -EINVAL;
  163. if (!iwl_is_alive(priv))
  164. return -EBUSY;
  165. /* This function hardcodes a bunch of dual-mode assumptions */
  166. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  167. if (!ctx->is_active)
  168. return 0;
  169. /* always get timestamp with Rx frame */
  170. ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
  171. if (ctx->ctxid == IWL_RXON_CTX_PAN && priv->_agn.hw_roc_channel) {
  172. struct ieee80211_channel *chan = priv->_agn.hw_roc_channel;
  173. iwl_set_rxon_channel(priv, chan, ctx);
  174. iwl_set_flags_for_band(priv, ctx, chan->band, NULL);
  175. ctx->staging.filter_flags |=
  176. RXON_FILTER_ASSOC_MSK |
  177. RXON_FILTER_PROMISC_MSK |
  178. RXON_FILTER_CTL2HOST_MSK;
  179. ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
  180. new_assoc = true;
  181. if (memcmp(&ctx->staging, &ctx->active,
  182. sizeof(ctx->staging)) == 0)
  183. return 0;
  184. }
  185. if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) ||
  186. !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK))
  187. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  188. else
  189. ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  190. ret = iwl_check_rxon_cmd(priv, ctx);
  191. if (ret) {
  192. IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
  193. return -EINVAL;
  194. }
  195. /*
  196. * receive commit_rxon request
  197. * abort any previous channel switch if still in process
  198. */
  199. if (priv->switch_rxon.switch_in_progress &&
  200. (priv->switch_rxon.channel != ctx->staging.channel)) {
  201. IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
  202. le16_to_cpu(priv->switch_rxon.channel));
  203. iwl_chswitch_done(priv, false);
  204. }
  205. /*
  206. * If we don't need to send a full RXON, we can use
  207. * iwl_rxon_assoc_cmd which is used to reconfigure filter
  208. * and other flags for the current radio configuration.
  209. */
  210. if (!iwl_full_rxon_required(priv, ctx)) {
  211. ret = iwlagn_send_rxon_assoc(priv, ctx);
  212. if (ret) {
  213. IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
  214. return ret;
  215. }
  216. memcpy(active, &ctx->staging, sizeof(*active));
  217. iwl_print_rx_config_cmd(priv, ctx);
  218. return 0;
  219. }
  220. if (priv->cfg->ops->hcmd->set_pan_params) {
  221. ret = priv->cfg->ops->hcmd->set_pan_params(priv);
  222. if (ret)
  223. return ret;
  224. }
  225. iwl_set_rxon_hwcrypto(priv, ctx, !priv->cfg->mod_params->sw_crypto);
  226. IWL_DEBUG_INFO(priv,
  227. "Going to commit RXON\n"
  228. " * with%s RXON_FILTER_ASSOC_MSK\n"
  229. " * channel = %d\n"
  230. " * bssid = %pM\n",
  231. (new_assoc ? "" : "out"),
  232. le16_to_cpu(ctx->staging.channel),
  233. ctx->staging.bssid_addr);
  234. /*
  235. * Always clear associated first, but with the correct config.
  236. * This is required as for example station addition for the
  237. * AP station must be done after the BSSID is set to correctly
  238. * set up filters in the device.
  239. */
  240. if ((old_assoc && new_assoc) || !new_assoc) {
  241. if (ctx->ctxid == IWL_RXON_CTX_BSS)
  242. ret = iwlagn_disable_bss(priv, ctx, &ctx->staging);
  243. else
  244. ret = iwlagn_disable_pan(priv, ctx, &ctx->staging);
  245. if (ret)
  246. return ret;
  247. memcpy(active, &ctx->staging, sizeof(*active));
  248. /*
  249. * Un-assoc RXON clears the station table and WEP
  250. * keys, so we have to restore those afterwards.
  251. */
  252. iwl_clear_ucode_stations(priv, ctx);
  253. iwl_restore_stations(priv, ctx);
  254. ret = iwl_restore_default_wep_keys(priv, ctx);
  255. if (ret) {
  256. IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
  257. return ret;
  258. }
  259. }
  260. /* RXON timing must be before associated RXON */
  261. ret = iwl_send_rxon_timing(priv, ctx);
  262. if (ret) {
  263. IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
  264. return ret;
  265. }
  266. if (new_assoc) {
  267. /* QoS info may be cleared by previous un-assoc RXON */
  268. iwlagn_update_qos(priv, ctx);
  269. /*
  270. * We'll run into this code path when beaconing is
  271. * enabled, but then we also need to send the beacon
  272. * to the device.
  273. */
  274. if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) {
  275. ret = iwlagn_update_beacon(priv, ctx->vif);
  276. if (ret) {
  277. IWL_ERR(priv,
  278. "Error sending required beacon (%d)!\n",
  279. ret);
  280. return ret;
  281. }
  282. }
  283. priv->start_calib = 0;
  284. /*
  285. * Apply the new configuration.
  286. *
  287. * Associated RXON doesn't clear the station table in uCode,
  288. * so we don't need to restore stations etc. after this.
  289. */
  290. ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd,
  291. sizeof(struct iwl_rxon_cmd), &ctx->staging);
  292. if (ret) {
  293. IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
  294. return ret;
  295. }
  296. memcpy(active, &ctx->staging, sizeof(*active));
  297. iwl_reprogram_ap_sta(priv, ctx);
  298. /* IBSS beacon needs to be sent after setting assoc */
  299. if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC))
  300. if (iwlagn_update_beacon(priv, ctx->vif))
  301. IWL_ERR(priv, "Error sending IBSS beacon\n");
  302. }
  303. iwl_print_rx_config_cmd(priv, ctx);
  304. iwl_init_sensitivity(priv);
  305. /*
  306. * If we issue a new RXON command which required a tune then we must
  307. * send a new TXPOWER command or we won't be able to Tx any frames.
  308. *
  309. * It's expected we set power here if channel is changing.
  310. */
  311. ret = iwl_set_tx_power(priv, priv->tx_power_next, true);
  312. if (ret) {
  313. IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
  314. return ret;
  315. }
  316. return 0;
  317. }
  318. int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
  319. {
  320. struct iwl_priv *priv = hw->priv;
  321. struct iwl_rxon_context *ctx;
  322. struct ieee80211_conf *conf = &hw->conf;
  323. struct ieee80211_channel *channel = conf->channel;
  324. const struct iwl_channel_info *ch_info;
  325. int ret = 0;
  326. IWL_DEBUG_MAC80211(priv, "changed %#x", changed);
  327. mutex_lock(&priv->mutex);
  328. if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
  329. IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
  330. goto out;
  331. }
  332. if (!iwl_is_ready(priv)) {
  333. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  334. goto out;
  335. }
  336. if (changed & (IEEE80211_CONF_CHANGE_SMPS |
  337. IEEE80211_CONF_CHANGE_CHANNEL)) {
  338. /* mac80211 uses static for non-HT which is what we want */
  339. priv->current_ht_config.smps = conf->smps_mode;
  340. /*
  341. * Recalculate chain counts.
  342. *
  343. * If monitor mode is enabled then mac80211 will
  344. * set up the SM PS mode to OFF if an HT channel is
  345. * configured.
  346. */
  347. if (priv->cfg->ops->hcmd->set_rxon_chain)
  348. for_each_context(priv, ctx)
  349. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  350. }
  351. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  352. unsigned long flags;
  353. ch_info = iwl_get_channel_info(priv, channel->band,
  354. channel->hw_value);
  355. if (!is_channel_valid(ch_info)) {
  356. IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
  357. ret = -EINVAL;
  358. goto out;
  359. }
  360. spin_lock_irqsave(&priv->lock, flags);
  361. for_each_context(priv, ctx) {
  362. /* Configure HT40 channels */
  363. if (ctx->ht.enabled != conf_is_ht(conf))
  364. ctx->ht.enabled = conf_is_ht(conf);
  365. if (ctx->ht.enabled) {
  366. if (conf_is_ht40_minus(conf)) {
  367. ctx->ht.extension_chan_offset =
  368. IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  369. ctx->ht.is_40mhz = true;
  370. } else if (conf_is_ht40_plus(conf)) {
  371. ctx->ht.extension_chan_offset =
  372. IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  373. ctx->ht.is_40mhz = true;
  374. } else {
  375. ctx->ht.extension_chan_offset =
  376. IEEE80211_HT_PARAM_CHA_SEC_NONE;
  377. ctx->ht.is_40mhz = false;
  378. }
  379. } else
  380. ctx->ht.is_40mhz = false;
  381. /*
  382. * Default to no protection. Protection mode will
  383. * later be set from BSS config in iwl_ht_conf
  384. */
  385. ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
  386. /* if we are switching from ht to 2.4 clear flags
  387. * from any ht related info since 2.4 does not
  388. * support ht */
  389. if (le16_to_cpu(ctx->staging.channel) !=
  390. channel->hw_value)
  391. ctx->staging.flags = 0;
  392. iwl_set_rxon_channel(priv, channel, ctx);
  393. iwl_set_rxon_ht(priv, &priv->current_ht_config);
  394. iwl_set_flags_for_band(priv, ctx, channel->band,
  395. ctx->vif);
  396. }
  397. spin_unlock_irqrestore(&priv->lock, flags);
  398. iwl_update_bcast_stations(priv);
  399. /*
  400. * The list of supported rates and rate mask can be different
  401. * for each band; since the band may have changed, reset
  402. * the rate mask to what mac80211 lists.
  403. */
  404. iwl_set_rate(priv);
  405. }
  406. if (changed & (IEEE80211_CONF_CHANGE_PS |
  407. IEEE80211_CONF_CHANGE_IDLE)) {
  408. ret = iwl_power_update_mode(priv, false);
  409. if (ret)
  410. IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
  411. }
  412. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  413. IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
  414. priv->tx_power_user_lmt, conf->power_level);
  415. iwl_set_tx_power(priv, conf->power_level, false);
  416. }
  417. for_each_context(priv, ctx) {
  418. if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
  419. continue;
  420. iwlagn_commit_rxon(priv, ctx);
  421. }
  422. out:
  423. mutex_unlock(&priv->mutex);
  424. return ret;
  425. }
  426. static void iwlagn_check_needed_chains(struct iwl_priv *priv,
  427. struct iwl_rxon_context *ctx,
  428. struct ieee80211_bss_conf *bss_conf)
  429. {
  430. struct ieee80211_vif *vif = ctx->vif;
  431. struct iwl_rxon_context *tmp;
  432. struct ieee80211_sta *sta;
  433. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  434. struct ieee80211_sta_ht_cap *ht_cap;
  435. bool need_multiple;
  436. lockdep_assert_held(&priv->mutex);
  437. switch (vif->type) {
  438. case NL80211_IFTYPE_STATION:
  439. rcu_read_lock();
  440. sta = ieee80211_find_sta(vif, bss_conf->bssid);
  441. if (!sta) {
  442. /*
  443. * If at all, this can only happen through a race
  444. * when the AP disconnects us while we're still
  445. * setting up the connection, in that case mac80211
  446. * will soon tell us about that.
  447. */
  448. need_multiple = false;
  449. rcu_read_unlock();
  450. break;
  451. }
  452. ht_cap = &sta->ht_cap;
  453. need_multiple = true;
  454. /*
  455. * If the peer advertises no support for receiving 2 and 3
  456. * stream MCS rates, it can't be transmitting them either.
  457. */
  458. if (ht_cap->mcs.rx_mask[1] == 0 &&
  459. ht_cap->mcs.rx_mask[2] == 0) {
  460. need_multiple = false;
  461. } else if (!(ht_cap->mcs.tx_params &
  462. IEEE80211_HT_MCS_TX_DEFINED)) {
  463. /* If it can't TX MCS at all ... */
  464. need_multiple = false;
  465. } else if (ht_cap->mcs.tx_params &
  466. IEEE80211_HT_MCS_TX_RX_DIFF) {
  467. int maxstreams;
  468. /*
  469. * But if it can receive them, it might still not
  470. * be able to transmit them, which is what we need
  471. * to check here -- so check the number of streams
  472. * it advertises for TX (if different from RX).
  473. */
  474. maxstreams = (ht_cap->mcs.tx_params &
  475. IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK);
  476. maxstreams >>=
  477. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
  478. maxstreams += 1;
  479. if (maxstreams <= 1)
  480. need_multiple = false;
  481. }
  482. rcu_read_unlock();
  483. break;
  484. case NL80211_IFTYPE_ADHOC:
  485. /* currently */
  486. need_multiple = false;
  487. break;
  488. default:
  489. /* only AP really */
  490. need_multiple = true;
  491. break;
  492. }
  493. ctx->ht_need_multiple_chains = need_multiple;
  494. if (!need_multiple) {
  495. /* check all contexts */
  496. for_each_context(priv, tmp) {
  497. if (!tmp->vif)
  498. continue;
  499. if (tmp->ht_need_multiple_chains) {
  500. need_multiple = true;
  501. break;
  502. }
  503. }
  504. }
  505. ht_conf->single_chain_sufficient = !need_multiple;
  506. }
  507. void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
  508. struct ieee80211_vif *vif,
  509. struct ieee80211_bss_conf *bss_conf,
  510. u32 changes)
  511. {
  512. struct iwl_priv *priv = hw->priv;
  513. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  514. int ret;
  515. bool force = false;
  516. mutex_lock(&priv->mutex);
  517. if (unlikely(!iwl_is_ready(priv))) {
  518. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  519. mutex_unlock(&priv->mutex);
  520. return;
  521. }
  522. if (unlikely(!ctx->vif)) {
  523. IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n");
  524. mutex_unlock(&priv->mutex);
  525. return;
  526. }
  527. if (changes & BSS_CHANGED_BEACON_INT)
  528. force = true;
  529. if (changes & BSS_CHANGED_QOS) {
  530. ctx->qos_data.qos_active = bss_conf->qos;
  531. iwlagn_update_qos(priv, ctx);
  532. }
  533. ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
  534. if (vif->bss_conf.use_short_preamble)
  535. ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  536. else
  537. ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  538. if (changes & BSS_CHANGED_ASSOC) {
  539. if (bss_conf->assoc) {
  540. priv->timestamp = bss_conf->timestamp;
  541. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  542. } else {
  543. /*
  544. * If we disassociate while there are pending
  545. * frames, just wake up the queues and let the
  546. * frames "escape" ... This shouldn't really
  547. * be happening to start with, but we should
  548. * not get stuck in this case either since it
  549. * can happen if userspace gets confused.
  550. */
  551. if (ctx->last_tx_rejected) {
  552. ctx->last_tx_rejected = false;
  553. iwl_wake_any_queue(priv, ctx);
  554. }
  555. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  556. }
  557. }
  558. if (ctx->ht.enabled) {
  559. ctx->ht.protection = bss_conf->ht_operation_mode &
  560. IEEE80211_HT_OP_MODE_PROTECTION;
  561. ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode &
  562. IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
  563. iwlagn_check_needed_chains(priv, ctx, bss_conf);
  564. iwl_set_rxon_ht(priv, &priv->current_ht_config);
  565. }
  566. if (priv->cfg->ops->hcmd->set_rxon_chain)
  567. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  568. if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
  569. ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
  570. else
  571. ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
  572. if (bss_conf->use_cts_prot)
  573. ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
  574. else
  575. ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
  576. memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN);
  577. if (vif->type == NL80211_IFTYPE_AP ||
  578. vif->type == NL80211_IFTYPE_ADHOC) {
  579. if (vif->bss_conf.enable_beacon) {
  580. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  581. priv->beacon_ctx = ctx;
  582. } else {
  583. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  584. priv->beacon_ctx = NULL;
  585. }
  586. }
  587. if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
  588. iwlagn_commit_rxon(priv, ctx);
  589. if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
  590. /*
  591. * The chain noise calibration will enable PM upon
  592. * completion. If calibration has already been run
  593. * then we need to enable power management here.
  594. */
  595. if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
  596. iwl_power_update_mode(priv, false);
  597. /* Enable RX differential gain and sensitivity calibrations */
  598. iwl_chain_noise_reset(priv);
  599. priv->start_calib = 1;
  600. }
  601. if (changes & BSS_CHANGED_IBSS) {
  602. ret = iwlagn_manage_ibss_station(priv, vif,
  603. bss_conf->ibss_joined);
  604. if (ret)
  605. IWL_ERR(priv, "failed to %s IBSS station %pM\n",
  606. bss_conf->ibss_joined ? "add" : "remove",
  607. bss_conf->bssid);
  608. }
  609. if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_ADHOC &&
  610. priv->beacon_ctx) {
  611. if (iwlagn_update_beacon(priv, vif))
  612. IWL_ERR(priv, "Error sending IBSS beacon\n");
  613. }
  614. mutex_unlock(&priv->mutex);
  615. }
  616. void iwlagn_post_scan(struct iwl_priv *priv)
  617. {
  618. struct iwl_rxon_context *ctx;
  619. /*
  620. * Since setting the RXON may have been deferred while
  621. * performing the scan, fire one off if needed
  622. */
  623. for_each_context(priv, ctx)
  624. if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
  625. iwlagn_commit_rxon(priv, ctx);
  626. if (priv->cfg->ops->hcmd->set_pan_params)
  627. priv->cfg->ops->hcmd->set_pan_params(priv);
  628. }