iwl-agn-rxon.c 26 KB

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