iwl-agn-rxon.c 27 KB

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