iwl-agn-rxon.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955
  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-core.h"
  29. #include "iwl-agn-calib.h"
  30. #include "iwl-trans.h"
  31. #include "iwl-shared.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_trans_send_cmd_pdu(trans(priv), ctx->rxon_cmd,
  40. CMD_SYNC, sizeof(*send), send);
  41. send->filter_flags = old_filter;
  42. if (ret)
  43. IWL_ERR(priv, "Error clearing ASSOC_MSK on BSS (%d)\n", ret);
  44. return ret;
  45. }
  46. static int iwlagn_disable_pan(struct iwl_priv *priv,
  47. struct iwl_rxon_context *ctx,
  48. struct iwl_rxon_cmd *send)
  49. {
  50. struct iwl_notification_wait disable_wait;
  51. __le32 old_filter = send->filter_flags;
  52. u8 old_dev_type = send->dev_type;
  53. int ret;
  54. iwlagn_init_notification_wait(priv, &disable_wait,
  55. REPLY_WIPAN_DEACTIVATION_COMPLETE,
  56. NULL, NULL);
  57. send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  58. send->dev_type = RXON_DEV_TYPE_P2P;
  59. ret = iwl_trans_send_cmd_pdu(trans(priv), ctx->rxon_cmd,
  60. CMD_SYNC, sizeof(*send), send);
  61. send->filter_flags = old_filter;
  62. send->dev_type = old_dev_type;
  63. if (ret) {
  64. IWL_ERR(priv, "Error disabling PAN (%d)\n", ret);
  65. iwlagn_remove_notification(priv, &disable_wait);
  66. } else {
  67. ret = iwlagn_wait_notification(priv, &disable_wait, HZ);
  68. if (ret)
  69. IWL_ERR(priv, "Timed out waiting for PAN disable\n");
  70. }
  71. return ret;
  72. }
  73. static int iwlagn_disconn_pan(struct iwl_priv *priv,
  74. struct iwl_rxon_context *ctx,
  75. struct iwl_rxon_cmd *send)
  76. {
  77. __le32 old_filter = send->filter_flags;
  78. int ret;
  79. send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  80. ret = iwl_trans_send_cmd_pdu(trans(priv), ctx->rxon_cmd, CMD_SYNC,
  81. sizeof(*send), send);
  82. send->filter_flags = old_filter;
  83. return ret;
  84. }
  85. static void iwlagn_update_qos(struct iwl_priv *priv,
  86. struct iwl_rxon_context *ctx)
  87. {
  88. int ret;
  89. if (!ctx->is_active)
  90. return;
  91. ctx->qos_data.def_qos_parm.qos_flags = 0;
  92. if (ctx->qos_data.qos_active)
  93. ctx->qos_data.def_qos_parm.qos_flags |=
  94. QOS_PARAM_FLG_UPDATE_EDCA_MSK;
  95. if (ctx->ht.enabled)
  96. ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
  97. IWL_DEBUG_QOS(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
  98. ctx->qos_data.qos_active,
  99. ctx->qos_data.def_qos_parm.qos_flags);
  100. ret = iwl_trans_send_cmd_pdu(trans(priv), ctx->qos_cmd, CMD_SYNC,
  101. sizeof(struct iwl_qosparam_cmd),
  102. &ctx->qos_data.def_qos_parm);
  103. if (ret)
  104. IWL_ERR(priv, "Failed to update QoS\n");
  105. }
  106. static int iwlagn_update_beacon(struct iwl_priv *priv,
  107. struct ieee80211_vif *vif)
  108. {
  109. lockdep_assert_held(&priv->shrd->mutex);
  110. dev_kfree_skb(priv->beacon_skb);
  111. priv->beacon_skb = ieee80211_beacon_get(priv->hw, vif);
  112. if (!priv->beacon_skb)
  113. return -ENOMEM;
  114. return iwlagn_send_beacon_cmd(priv);
  115. }
  116. static int iwlagn_send_rxon_assoc(struct iwl_priv *priv,
  117. struct iwl_rxon_context *ctx)
  118. {
  119. int ret = 0;
  120. struct iwl_rxon_assoc_cmd rxon_assoc;
  121. const struct iwl_rxon_cmd *rxon1 = &ctx->staging;
  122. const struct iwl_rxon_cmd *rxon2 = &ctx->active;
  123. if ((rxon1->flags == rxon2->flags) &&
  124. (rxon1->filter_flags == rxon2->filter_flags) &&
  125. (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
  126. (rxon1->ofdm_ht_single_stream_basic_rates ==
  127. rxon2->ofdm_ht_single_stream_basic_rates) &&
  128. (rxon1->ofdm_ht_dual_stream_basic_rates ==
  129. rxon2->ofdm_ht_dual_stream_basic_rates) &&
  130. (rxon1->ofdm_ht_triple_stream_basic_rates ==
  131. rxon2->ofdm_ht_triple_stream_basic_rates) &&
  132. (rxon1->acquisition_data == rxon2->acquisition_data) &&
  133. (rxon1->rx_chain == rxon2->rx_chain) &&
  134. (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
  135. IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
  136. return 0;
  137. }
  138. rxon_assoc.flags = ctx->staging.flags;
  139. rxon_assoc.filter_flags = ctx->staging.filter_flags;
  140. rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates;
  141. rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates;
  142. rxon_assoc.reserved1 = 0;
  143. rxon_assoc.reserved2 = 0;
  144. rxon_assoc.reserved3 = 0;
  145. rxon_assoc.ofdm_ht_single_stream_basic_rates =
  146. ctx->staging.ofdm_ht_single_stream_basic_rates;
  147. rxon_assoc.ofdm_ht_dual_stream_basic_rates =
  148. ctx->staging.ofdm_ht_dual_stream_basic_rates;
  149. rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain;
  150. rxon_assoc.ofdm_ht_triple_stream_basic_rates =
  151. ctx->staging.ofdm_ht_triple_stream_basic_rates;
  152. rxon_assoc.acquisition_data = ctx->staging.acquisition_data;
  153. ret = iwl_trans_send_cmd_pdu(trans(priv), ctx->rxon_assoc_cmd,
  154. CMD_ASYNC, sizeof(rxon_assoc), &rxon_assoc);
  155. return ret;
  156. }
  157. static int iwlagn_rxon_disconn(struct iwl_priv *priv,
  158. struct iwl_rxon_context *ctx)
  159. {
  160. int ret;
  161. struct iwl_rxon_cmd *active = (void *)&ctx->active;
  162. if (ctx->ctxid == IWL_RXON_CTX_BSS) {
  163. ret = iwlagn_disable_bss(priv, ctx, &ctx->staging);
  164. } else {
  165. ret = iwlagn_disable_pan(priv, ctx, &ctx->staging);
  166. if (ret)
  167. return ret;
  168. if (ctx->vif) {
  169. ret = iwl_send_rxon_timing(priv, ctx);
  170. if (ret) {
  171. IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
  172. return ret;
  173. }
  174. ret = iwlagn_disconn_pan(priv, ctx, &ctx->staging);
  175. }
  176. }
  177. if (ret)
  178. return ret;
  179. /*
  180. * Un-assoc RXON clears the station table and WEP
  181. * keys, so we have to restore those afterwards.
  182. */
  183. iwl_clear_ucode_stations(priv, ctx);
  184. /* update -- might need P2P now */
  185. iwl_update_bcast_station(priv, ctx);
  186. iwl_restore_stations(priv, ctx);
  187. ret = iwl_restore_default_wep_keys(priv, ctx);
  188. if (ret) {
  189. IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
  190. return ret;
  191. }
  192. memcpy(active, &ctx->staging, sizeof(*active));
  193. return 0;
  194. }
  195. static int iwlagn_rxon_connect(struct iwl_priv *priv,
  196. struct iwl_rxon_context *ctx)
  197. {
  198. int ret;
  199. struct iwl_rxon_cmd *active = (void *)&ctx->active;
  200. /* RXON timing must be before associated RXON */
  201. if (ctx->ctxid == IWL_RXON_CTX_BSS) {
  202. ret = iwl_send_rxon_timing(priv, ctx);
  203. if (ret) {
  204. IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
  205. return ret;
  206. }
  207. }
  208. /* QoS info may be cleared by previous un-assoc RXON */
  209. iwlagn_update_qos(priv, ctx);
  210. /*
  211. * We'll run into this code path when beaconing is
  212. * enabled, but then we also need to send the beacon
  213. * to the device.
  214. */
  215. if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) {
  216. ret = iwlagn_update_beacon(priv, ctx->vif);
  217. if (ret) {
  218. IWL_ERR(priv,
  219. "Error sending required beacon (%d)!\n",
  220. ret);
  221. return ret;
  222. }
  223. }
  224. priv->start_calib = 0;
  225. /*
  226. * Apply the new configuration.
  227. *
  228. * Associated RXON doesn't clear the station table in uCode,
  229. * so we don't need to restore stations etc. after this.
  230. */
  231. ret = iwl_trans_send_cmd_pdu(trans(priv), ctx->rxon_cmd, CMD_SYNC,
  232. sizeof(struct iwl_rxon_cmd), &ctx->staging);
  233. if (ret) {
  234. IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
  235. return ret;
  236. }
  237. memcpy(active, &ctx->staging, sizeof(*active));
  238. iwl_reprogram_ap_sta(priv, ctx);
  239. /* IBSS beacon needs to be sent after setting assoc */
  240. if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC))
  241. if (iwlagn_update_beacon(priv, ctx->vif))
  242. IWL_ERR(priv, "Error sending IBSS beacon\n");
  243. iwl_init_sensitivity(priv);
  244. /*
  245. * If we issue a new RXON command which required a tune then
  246. * we must send a new TXPOWER command or we won't be able to
  247. * Tx any frames.
  248. *
  249. * It's expected we set power here if channel is changing.
  250. */
  251. ret = iwl_set_tx_power(priv, priv->tx_power_next, true);
  252. if (ret) {
  253. IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
  254. return ret;
  255. }
  256. if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION &&
  257. priv->cfg->ht_params && priv->cfg->ht_params->smps_mode)
  258. ieee80211_request_smps(ctx->vif,
  259. priv->cfg->ht_params->smps_mode);
  260. return 0;
  261. }
  262. int iwlagn_set_pan_params(struct iwl_priv *priv)
  263. {
  264. struct iwl_wipan_params_cmd cmd;
  265. struct iwl_rxon_context *ctx_bss, *ctx_pan;
  266. int slot0 = 300, slot1 = 0;
  267. int ret;
  268. if (priv->shrd->valid_contexts == BIT(IWL_RXON_CTX_BSS))
  269. return 0;
  270. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  271. lockdep_assert_held(&priv->shrd->mutex);
  272. ctx_bss = &priv->contexts[IWL_RXON_CTX_BSS];
  273. ctx_pan = &priv->contexts[IWL_RXON_CTX_PAN];
  274. /*
  275. * If the PAN context is inactive, then we don't need
  276. * to update the PAN parameters, the last thing we'll
  277. * have done before it goes inactive is making the PAN
  278. * parameters be WLAN-only.
  279. */
  280. if (!ctx_pan->is_active)
  281. return 0;
  282. memset(&cmd, 0, sizeof(cmd));
  283. /* only 2 slots are currently allowed */
  284. cmd.num_slots = 2;
  285. cmd.slots[0].type = 0; /* BSS */
  286. cmd.slots[1].type = 1; /* PAN */
  287. if (priv->hw_roc_setup) {
  288. /* both contexts must be used for this to happen */
  289. slot1 = IWL_MIN_SLOT_TIME;
  290. slot0 = 3000;
  291. } else if (ctx_bss->vif && ctx_pan->vif) {
  292. int bcnint = ctx_pan->beacon_int;
  293. int dtim = ctx_pan->vif->bss_conf.dtim_period ?: 1;
  294. /* should be set, but seems unused?? */
  295. cmd.flags |= cpu_to_le16(IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE);
  296. if (ctx_pan->vif->type == NL80211_IFTYPE_AP &&
  297. bcnint &&
  298. bcnint != ctx_bss->beacon_int) {
  299. IWL_ERR(priv,
  300. "beacon intervals don't match (%d, %d)\n",
  301. ctx_bss->beacon_int, ctx_pan->beacon_int);
  302. } else
  303. bcnint = max_t(int, bcnint,
  304. ctx_bss->beacon_int);
  305. if (!bcnint)
  306. bcnint = DEFAULT_BEACON_INTERVAL;
  307. slot0 = bcnint / 2;
  308. slot1 = bcnint - slot0;
  309. if (test_bit(STATUS_SCAN_HW, &priv->shrd->status) ||
  310. (!ctx_bss->vif->bss_conf.idle &&
  311. !ctx_bss->vif->bss_conf.assoc)) {
  312. slot0 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
  313. slot1 = IWL_MIN_SLOT_TIME;
  314. } else if (!ctx_pan->vif->bss_conf.idle &&
  315. !ctx_pan->vif->bss_conf.assoc) {
  316. slot1 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
  317. slot0 = IWL_MIN_SLOT_TIME;
  318. }
  319. } else if (ctx_pan->vif) {
  320. slot0 = 0;
  321. slot1 = max_t(int, 1, ctx_pan->vif->bss_conf.dtim_period) *
  322. ctx_pan->beacon_int;
  323. slot1 = max_t(int, DEFAULT_BEACON_INTERVAL, slot1);
  324. if (test_bit(STATUS_SCAN_HW, &priv->shrd->status)) {
  325. slot0 = slot1 * 3 - IWL_MIN_SLOT_TIME;
  326. slot1 = IWL_MIN_SLOT_TIME;
  327. }
  328. }
  329. cmd.slots[0].width = cpu_to_le16(slot0);
  330. cmd.slots[1].width = cpu_to_le16(slot1);
  331. ret = iwl_trans_send_cmd_pdu(trans(priv), REPLY_WIPAN_PARAMS, CMD_SYNC,
  332. sizeof(cmd), &cmd);
  333. if (ret)
  334. IWL_ERR(priv, "Error setting PAN parameters (%d)\n", ret);
  335. return ret;
  336. }
  337. /**
  338. * iwlagn_commit_rxon - commit staging_rxon to hardware
  339. *
  340. * The RXON command in staging_rxon is committed to the hardware and
  341. * the active_rxon structure is updated with the new data. This
  342. * function correctly transitions out of the RXON_ASSOC_MSK state if
  343. * a HW tune is required based on the RXON structure changes.
  344. *
  345. * The connect/disconnect flow should be as the following:
  346. *
  347. * 1. make sure send RXON command with association bit unset if not connect
  348. * this should include the channel and the band for the candidate
  349. * to be connected to
  350. * 2. Add Station before RXON association with the AP
  351. * 3. RXON_timing has to send before RXON for connection
  352. * 4. full RXON command - associated bit set
  353. * 5. use RXON_ASSOC command to update any flags changes
  354. */
  355. int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  356. {
  357. /* cast away the const for active_rxon in this function */
  358. struct iwl_rxon_cmd *active = (void *)&ctx->active;
  359. bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
  360. int ret;
  361. lockdep_assert_held(&priv->shrd->mutex);
  362. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  363. return -EINVAL;
  364. if (!iwl_is_alive(priv->shrd))
  365. return -EBUSY;
  366. /* This function hardcodes a bunch of dual-mode assumptions */
  367. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  368. if (!ctx->is_active)
  369. return 0;
  370. /* override BSSID if necessary due to preauth */
  371. if (ctx->preauth_bssid)
  372. memcpy(ctx->staging.bssid_addr, ctx->bssid, ETH_ALEN);
  373. /* always get timestamp with Rx frame */
  374. ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
  375. /*
  376. * force CTS-to-self frames protection if RTS-CTS is not preferred
  377. * one aggregation protection method
  378. */
  379. if (!(priv->cfg->ht_params &&
  380. priv->cfg->ht_params->use_rts_for_aggregation))
  381. ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
  382. if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) ||
  383. !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK))
  384. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  385. else
  386. ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  387. iwl_print_rx_config_cmd(priv, ctx->ctxid);
  388. ret = iwl_check_rxon_cmd(priv, ctx);
  389. if (ret) {
  390. IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
  391. return -EINVAL;
  392. }
  393. /*
  394. * receive commit_rxon request
  395. * abort any previous channel switch if still in process
  396. */
  397. if (test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->shrd->status) &&
  398. (priv->switch_channel != ctx->staging.channel)) {
  399. IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
  400. le16_to_cpu(priv->switch_channel));
  401. iwl_chswitch_done(priv, false);
  402. }
  403. /*
  404. * If we don't need to send a full RXON, we can use
  405. * iwl_rxon_assoc_cmd which is used to reconfigure filter
  406. * and other flags for the current radio configuration.
  407. */
  408. if (!iwl_full_rxon_required(priv, ctx)) {
  409. ret = iwlagn_send_rxon_assoc(priv, ctx);
  410. if (ret) {
  411. IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
  412. return ret;
  413. }
  414. memcpy(active, &ctx->staging, sizeof(*active));
  415. /*
  416. * We do not commit tx power settings while channel changing,
  417. * do it now if after settings changed.
  418. */
  419. iwl_set_tx_power(priv, priv->tx_power_next, false);
  420. /* make sure we are in the right PS state */
  421. iwl_power_update_mode(priv, true);
  422. return 0;
  423. }
  424. iwl_set_rxon_hwcrypto(priv, ctx, !iwlagn_mod_params.sw_crypto);
  425. IWL_DEBUG_INFO(priv,
  426. "Going to commit RXON\n"
  427. " * with%s RXON_FILTER_ASSOC_MSK\n"
  428. " * channel = %d\n"
  429. " * bssid = %pM\n",
  430. (new_assoc ? "" : "out"),
  431. le16_to_cpu(ctx->staging.channel),
  432. ctx->staging.bssid_addr);
  433. /*
  434. * Always clear associated first, but with the correct config.
  435. * This is required as for example station addition for the
  436. * AP station must be done after the BSSID is set to correctly
  437. * set up filters in the device.
  438. */
  439. ret = iwlagn_rxon_disconn(priv, ctx);
  440. if (ret)
  441. return ret;
  442. ret = iwlagn_set_pan_params(priv);
  443. if (ret)
  444. return ret;
  445. if (new_assoc)
  446. return iwlagn_rxon_connect(priv, ctx);
  447. return 0;
  448. }
  449. void iwlagn_config_ht40(struct ieee80211_conf *conf,
  450. struct iwl_rxon_context *ctx)
  451. {
  452. if (conf_is_ht40_minus(conf)) {
  453. ctx->ht.extension_chan_offset =
  454. IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  455. ctx->ht.is_40mhz = true;
  456. } else if (conf_is_ht40_plus(conf)) {
  457. ctx->ht.extension_chan_offset =
  458. IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  459. ctx->ht.is_40mhz = true;
  460. } else {
  461. ctx->ht.extension_chan_offset =
  462. IEEE80211_HT_PARAM_CHA_SEC_NONE;
  463. ctx->ht.is_40mhz = false;
  464. }
  465. }
  466. int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
  467. {
  468. struct iwl_priv *priv = hw->priv;
  469. struct iwl_rxon_context *ctx;
  470. struct ieee80211_conf *conf = &hw->conf;
  471. struct ieee80211_channel *channel = conf->channel;
  472. const struct iwl_channel_info *ch_info;
  473. int ret = 0;
  474. IWL_DEBUG_MAC80211(priv, "enter: changed %#x", changed);
  475. mutex_lock(&priv->shrd->mutex);
  476. if (unlikely(test_bit(STATUS_SCANNING, &priv->shrd->status))) {
  477. IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
  478. goto out;
  479. }
  480. if (!iwl_is_ready(priv->shrd)) {
  481. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  482. goto out;
  483. }
  484. if (changed & (IEEE80211_CONF_CHANGE_SMPS |
  485. IEEE80211_CONF_CHANGE_CHANNEL)) {
  486. /* mac80211 uses static for non-HT which is what we want */
  487. priv->current_ht_config.smps = conf->smps_mode;
  488. /*
  489. * Recalculate chain counts.
  490. *
  491. * If monitor mode is enabled then mac80211 will
  492. * set up the SM PS mode to OFF if an HT channel is
  493. * configured.
  494. */
  495. for_each_context(priv, ctx)
  496. iwlagn_set_rxon_chain(priv, ctx);
  497. }
  498. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  499. unsigned long flags;
  500. ch_info = iwl_get_channel_info(priv, channel->band,
  501. channel->hw_value);
  502. if (!is_channel_valid(ch_info)) {
  503. IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
  504. ret = -EINVAL;
  505. goto out;
  506. }
  507. spin_lock_irqsave(&priv->shrd->lock, flags);
  508. for_each_context(priv, ctx) {
  509. /* Configure HT40 channels */
  510. if (ctx->ht.enabled != conf_is_ht(conf))
  511. ctx->ht.enabled = conf_is_ht(conf);
  512. if (ctx->ht.enabled) {
  513. /* if HT40 is used, it should not change
  514. * after associated except channel switch */
  515. if (!ctx->ht.is_40mhz ||
  516. !iwl_is_associated_ctx(ctx))
  517. iwlagn_config_ht40(conf, ctx);
  518. } else
  519. ctx->ht.is_40mhz = false;
  520. /*
  521. * Default to no protection. Protection mode will
  522. * later be set from BSS config in iwl_ht_conf
  523. */
  524. ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
  525. /* if we are switching from ht to 2.4 clear flags
  526. * from any ht related info since 2.4 does not
  527. * support ht */
  528. if (le16_to_cpu(ctx->staging.channel) !=
  529. channel->hw_value)
  530. ctx->staging.flags = 0;
  531. iwl_set_rxon_channel(priv, channel, ctx);
  532. iwl_set_rxon_ht(priv, &priv->current_ht_config);
  533. iwl_set_flags_for_band(priv, ctx, channel->band,
  534. ctx->vif);
  535. }
  536. spin_unlock_irqrestore(&priv->shrd->lock, flags);
  537. iwl_update_bcast_stations(priv);
  538. /*
  539. * The list of supported rates and rate mask can be different
  540. * for each band; since the band may have changed, reset
  541. * the rate mask to what mac80211 lists.
  542. */
  543. iwl_set_rate(priv);
  544. }
  545. if (changed & (IEEE80211_CONF_CHANGE_PS |
  546. IEEE80211_CONF_CHANGE_IDLE)) {
  547. ret = iwl_power_update_mode(priv, false);
  548. if (ret)
  549. IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
  550. }
  551. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  552. IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
  553. priv->tx_power_user_lmt, conf->power_level);
  554. iwl_set_tx_power(priv, conf->power_level, false);
  555. }
  556. for_each_context(priv, ctx) {
  557. if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
  558. continue;
  559. iwlagn_commit_rxon(priv, ctx);
  560. }
  561. out:
  562. mutex_unlock(&priv->shrd->mutex);
  563. IWL_DEBUG_MAC80211(priv, "leave\n");
  564. return ret;
  565. }
  566. static void iwlagn_check_needed_chains(struct iwl_priv *priv,
  567. struct iwl_rxon_context *ctx,
  568. struct ieee80211_bss_conf *bss_conf)
  569. {
  570. struct ieee80211_vif *vif = ctx->vif;
  571. struct iwl_rxon_context *tmp;
  572. struct ieee80211_sta *sta;
  573. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  574. struct ieee80211_sta_ht_cap *ht_cap;
  575. bool need_multiple;
  576. lockdep_assert_held(&priv->shrd->mutex);
  577. switch (vif->type) {
  578. case NL80211_IFTYPE_STATION:
  579. rcu_read_lock();
  580. sta = ieee80211_find_sta(vif, bss_conf->bssid);
  581. if (!sta) {
  582. /*
  583. * If at all, this can only happen through a race
  584. * when the AP disconnects us while we're still
  585. * setting up the connection, in that case mac80211
  586. * will soon tell us about that.
  587. */
  588. need_multiple = false;
  589. rcu_read_unlock();
  590. break;
  591. }
  592. ht_cap = &sta->ht_cap;
  593. need_multiple = true;
  594. /*
  595. * If the peer advertises no support for receiving 2 and 3
  596. * stream MCS rates, it can't be transmitting them either.
  597. */
  598. if (ht_cap->mcs.rx_mask[1] == 0 &&
  599. ht_cap->mcs.rx_mask[2] == 0) {
  600. need_multiple = false;
  601. } else if (!(ht_cap->mcs.tx_params &
  602. IEEE80211_HT_MCS_TX_DEFINED)) {
  603. /* If it can't TX MCS at all ... */
  604. need_multiple = false;
  605. } else if (ht_cap->mcs.tx_params &
  606. IEEE80211_HT_MCS_TX_RX_DIFF) {
  607. int maxstreams;
  608. /*
  609. * But if it can receive them, it might still not
  610. * be able to transmit them, which is what we need
  611. * to check here -- so check the number of streams
  612. * it advertises for TX (if different from RX).
  613. */
  614. maxstreams = (ht_cap->mcs.tx_params &
  615. IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK);
  616. maxstreams >>=
  617. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
  618. maxstreams += 1;
  619. if (maxstreams <= 1)
  620. need_multiple = false;
  621. }
  622. rcu_read_unlock();
  623. break;
  624. case NL80211_IFTYPE_ADHOC:
  625. /* currently */
  626. need_multiple = false;
  627. break;
  628. default:
  629. /* only AP really */
  630. need_multiple = true;
  631. break;
  632. }
  633. ctx->ht_need_multiple_chains = need_multiple;
  634. if (!need_multiple) {
  635. /* check all contexts */
  636. for_each_context(priv, tmp) {
  637. if (!tmp->vif)
  638. continue;
  639. if (tmp->ht_need_multiple_chains) {
  640. need_multiple = true;
  641. break;
  642. }
  643. }
  644. }
  645. ht_conf->single_chain_sufficient = !need_multiple;
  646. }
  647. static void iwlagn_chain_noise_reset(struct iwl_priv *priv)
  648. {
  649. struct iwl_chain_noise_data *data = &priv->chain_noise_data;
  650. int ret;
  651. if ((data->state == IWL_CHAIN_NOISE_ALIVE) &&
  652. iwl_is_any_associated(priv)) {
  653. struct iwl_calib_chain_noise_reset_cmd cmd;
  654. /* clear data for chain noise calibration algorithm */
  655. data->chain_noise_a = 0;
  656. data->chain_noise_b = 0;
  657. data->chain_noise_c = 0;
  658. data->chain_signal_a = 0;
  659. data->chain_signal_b = 0;
  660. data->chain_signal_c = 0;
  661. data->beacon_count = 0;
  662. memset(&cmd, 0, sizeof(cmd));
  663. iwl_set_calib_hdr(&cmd.hdr,
  664. priv->phy_calib_chain_noise_reset_cmd);
  665. ret = iwl_trans_send_cmd_pdu(trans(priv),
  666. REPLY_PHY_CALIBRATION_CMD,
  667. CMD_SYNC, sizeof(cmd), &cmd);
  668. if (ret)
  669. IWL_ERR(priv,
  670. "Could not send REPLY_PHY_CALIBRATION_CMD\n");
  671. data->state = IWL_CHAIN_NOISE_ACCUMULATE;
  672. IWL_DEBUG_CALIB(priv, "Run chain_noise_calibrate\n");
  673. }
  674. }
  675. void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
  676. struct ieee80211_vif *vif,
  677. struct ieee80211_bss_conf *bss_conf,
  678. u32 changes)
  679. {
  680. struct iwl_priv *priv = hw->priv;
  681. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  682. int ret;
  683. bool force = false;
  684. mutex_lock(&priv->shrd->mutex);
  685. if (unlikely(!iwl_is_ready(priv->shrd))) {
  686. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  687. mutex_unlock(&priv->shrd->mutex);
  688. return;
  689. }
  690. if (unlikely(!ctx->vif)) {
  691. IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n");
  692. mutex_unlock(&priv->shrd->mutex);
  693. return;
  694. }
  695. if (changes & BSS_CHANGED_BEACON_INT)
  696. force = true;
  697. if (changes & BSS_CHANGED_QOS) {
  698. ctx->qos_data.qos_active = bss_conf->qos;
  699. iwlagn_update_qos(priv, ctx);
  700. }
  701. ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
  702. if (vif->bss_conf.use_short_preamble)
  703. ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  704. else
  705. ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  706. if (changes & BSS_CHANGED_ASSOC) {
  707. if (bss_conf->assoc) {
  708. priv->timestamp = bss_conf->timestamp;
  709. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  710. } else {
  711. /*
  712. * If we disassociate while there are pending
  713. * frames, just wake up the queues and let the
  714. * frames "escape" ... This shouldn't really
  715. * be happening to start with, but we should
  716. * not get stuck in this case either since it
  717. * can happen if userspace gets confused.
  718. */
  719. if (ctx->last_tx_rejected) {
  720. ctx->last_tx_rejected = false;
  721. iwl_trans_wake_any_queue(trans(priv),
  722. ctx->ctxid);
  723. }
  724. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  725. if (ctx->ctxid == IWL_RXON_CTX_BSS)
  726. priv->have_rekey_data = false;
  727. }
  728. iwlagn_bt_coex_rssi_monitor(priv);
  729. }
  730. if (ctx->ht.enabled) {
  731. ctx->ht.protection = bss_conf->ht_operation_mode &
  732. IEEE80211_HT_OP_MODE_PROTECTION;
  733. ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode &
  734. IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
  735. iwlagn_check_needed_chains(priv, ctx, bss_conf);
  736. iwl_set_rxon_ht(priv, &priv->current_ht_config);
  737. }
  738. iwlagn_set_rxon_chain(priv, ctx);
  739. if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
  740. ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
  741. else
  742. ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
  743. if (bss_conf->use_cts_prot)
  744. ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
  745. else
  746. ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
  747. memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN);
  748. if (vif->type == NL80211_IFTYPE_AP ||
  749. vif->type == NL80211_IFTYPE_ADHOC) {
  750. if (vif->bss_conf.enable_beacon) {
  751. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  752. priv->beacon_ctx = ctx;
  753. } else {
  754. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  755. priv->beacon_ctx = NULL;
  756. }
  757. }
  758. if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
  759. iwlagn_commit_rxon(priv, ctx);
  760. if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
  761. /*
  762. * The chain noise calibration will enable PM upon
  763. * completion. If calibration has already been run
  764. * then we need to enable power management here.
  765. */
  766. if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
  767. iwl_power_update_mode(priv, false);
  768. /* Enable RX differential gain and sensitivity calibrations */
  769. if (!priv->disable_chain_noise_cal)
  770. iwlagn_chain_noise_reset(priv);
  771. priv->start_calib = 1;
  772. WARN_ON(ctx->preauth_bssid);
  773. }
  774. if (changes & BSS_CHANGED_IBSS) {
  775. ret = iwlagn_manage_ibss_station(priv, vif,
  776. bss_conf->ibss_joined);
  777. if (ret)
  778. IWL_ERR(priv, "failed to %s IBSS station %pM\n",
  779. bss_conf->ibss_joined ? "add" : "remove",
  780. bss_conf->bssid);
  781. }
  782. if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_ADHOC &&
  783. priv->beacon_ctx) {
  784. if (iwlagn_update_beacon(priv, vif))
  785. IWL_ERR(priv, "Error sending IBSS beacon\n");
  786. }
  787. mutex_unlock(&priv->shrd->mutex);
  788. }
  789. void iwlagn_post_scan(struct iwl_priv *priv)
  790. {
  791. struct iwl_rxon_context *ctx;
  792. /*
  793. * We do not commit power settings while scan is pending,
  794. * do it now if the settings changed.
  795. */
  796. iwl_power_set_mode(priv, &priv->power_data.sleep_cmd_next, false);
  797. iwl_set_tx_power(priv, priv->tx_power_next, false);
  798. /*
  799. * Since setting the RXON may have been deferred while
  800. * performing the scan, fire one off if needed
  801. */
  802. for_each_context(priv, ctx)
  803. if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
  804. iwlagn_commit_rxon(priv, ctx);
  805. iwlagn_set_pan_params(priv);
  806. }