iwl-agn-rxon.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350
  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 <linux/etherdevice.h>
  27. #include "iwl-dev.h"
  28. #include "iwl-agn.h"
  29. #include "iwl-core.h"
  30. #include "iwl-agn-calib.h"
  31. #include "iwl-trans.h"
  32. #include "iwl-shared.h"
  33. static int iwlagn_disable_bss(struct iwl_priv *priv,
  34. struct iwl_rxon_context *ctx,
  35. struct iwl_rxon_cmd *send)
  36. {
  37. __le32 old_filter = send->filter_flags;
  38. int ret;
  39. send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  40. ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd,
  41. CMD_SYNC, sizeof(*send), send);
  42. send->filter_flags = old_filter;
  43. if (ret)
  44. IWL_DEBUG_QUIET_RFKILL(priv,
  45. "Error clearing ASSOC_MSK on BSS (%d)\n", ret);
  46. return ret;
  47. }
  48. static int iwlagn_disable_pan(struct iwl_priv *priv,
  49. struct iwl_rxon_context *ctx,
  50. struct iwl_rxon_cmd *send)
  51. {
  52. struct iwl_notification_wait disable_wait;
  53. __le32 old_filter = send->filter_flags;
  54. u8 old_dev_type = send->dev_type;
  55. int ret;
  56. static const u8 deactivate_cmd[] = {
  57. REPLY_WIPAN_DEACTIVATION_COMPLETE
  58. };
  59. iwl_init_notification_wait(&priv->notif_wait, &disable_wait,
  60. deactivate_cmd, ARRAY_SIZE(deactivate_cmd),
  61. NULL, NULL);
  62. send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  63. send->dev_type = RXON_DEV_TYPE_P2P;
  64. ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd,
  65. CMD_SYNC, sizeof(*send), send);
  66. send->filter_flags = old_filter;
  67. send->dev_type = old_dev_type;
  68. if (ret) {
  69. IWL_ERR(priv, "Error disabling PAN (%d)\n", ret);
  70. iwl_remove_notification(&priv->notif_wait, &disable_wait);
  71. } else {
  72. ret = iwl_wait_notification(&priv->notif_wait,
  73. &disable_wait, HZ);
  74. if (ret)
  75. IWL_ERR(priv, "Timed out waiting for PAN disable\n");
  76. }
  77. return ret;
  78. }
  79. static int iwlagn_disconn_pan(struct iwl_priv *priv,
  80. struct iwl_rxon_context *ctx,
  81. struct iwl_rxon_cmd *send)
  82. {
  83. __le32 old_filter = send->filter_flags;
  84. int ret;
  85. send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  86. ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC,
  87. sizeof(*send), send);
  88. send->filter_flags = old_filter;
  89. return ret;
  90. }
  91. static void iwlagn_update_qos(struct iwl_priv *priv,
  92. struct iwl_rxon_context *ctx)
  93. {
  94. int ret;
  95. if (!ctx->is_active)
  96. return;
  97. ctx->qos_data.def_qos_parm.qos_flags = 0;
  98. if (ctx->qos_data.qos_active)
  99. ctx->qos_data.def_qos_parm.qos_flags |=
  100. QOS_PARAM_FLG_UPDATE_EDCA_MSK;
  101. if (ctx->ht.enabled)
  102. ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
  103. IWL_DEBUG_INFO(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
  104. ctx->qos_data.qos_active,
  105. ctx->qos_data.def_qos_parm.qos_flags);
  106. ret = iwl_dvm_send_cmd_pdu(priv, ctx->qos_cmd, CMD_SYNC,
  107. sizeof(struct iwl_qosparam_cmd),
  108. &ctx->qos_data.def_qos_parm);
  109. if (ret)
  110. IWL_DEBUG_QUIET_RFKILL(priv, "Failed to update QoS\n");
  111. }
  112. static int iwlagn_update_beacon(struct iwl_priv *priv,
  113. struct ieee80211_vif *vif)
  114. {
  115. lockdep_assert_held(&priv->mutex);
  116. dev_kfree_skb(priv->beacon_skb);
  117. priv->beacon_skb = ieee80211_beacon_get(priv->hw, vif);
  118. if (!priv->beacon_skb)
  119. return -ENOMEM;
  120. return iwlagn_send_beacon_cmd(priv);
  121. }
  122. static int iwlagn_send_rxon_assoc(struct iwl_priv *priv,
  123. struct iwl_rxon_context *ctx)
  124. {
  125. int ret = 0;
  126. struct iwl_rxon_assoc_cmd rxon_assoc;
  127. const struct iwl_rxon_cmd *rxon1 = &ctx->staging;
  128. const struct iwl_rxon_cmd *rxon2 = &ctx->active;
  129. if ((rxon1->flags == rxon2->flags) &&
  130. (rxon1->filter_flags == rxon2->filter_flags) &&
  131. (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
  132. (rxon1->ofdm_ht_single_stream_basic_rates ==
  133. rxon2->ofdm_ht_single_stream_basic_rates) &&
  134. (rxon1->ofdm_ht_dual_stream_basic_rates ==
  135. rxon2->ofdm_ht_dual_stream_basic_rates) &&
  136. (rxon1->ofdm_ht_triple_stream_basic_rates ==
  137. rxon2->ofdm_ht_triple_stream_basic_rates) &&
  138. (rxon1->acquisition_data == rxon2->acquisition_data) &&
  139. (rxon1->rx_chain == rxon2->rx_chain) &&
  140. (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
  141. IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
  142. return 0;
  143. }
  144. rxon_assoc.flags = ctx->staging.flags;
  145. rxon_assoc.filter_flags = ctx->staging.filter_flags;
  146. rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates;
  147. rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates;
  148. rxon_assoc.reserved1 = 0;
  149. rxon_assoc.reserved2 = 0;
  150. rxon_assoc.reserved3 = 0;
  151. rxon_assoc.ofdm_ht_single_stream_basic_rates =
  152. ctx->staging.ofdm_ht_single_stream_basic_rates;
  153. rxon_assoc.ofdm_ht_dual_stream_basic_rates =
  154. ctx->staging.ofdm_ht_dual_stream_basic_rates;
  155. rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain;
  156. rxon_assoc.ofdm_ht_triple_stream_basic_rates =
  157. ctx->staging.ofdm_ht_triple_stream_basic_rates;
  158. rxon_assoc.acquisition_data = ctx->staging.acquisition_data;
  159. ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_assoc_cmd,
  160. CMD_ASYNC, sizeof(rxon_assoc), &rxon_assoc);
  161. return ret;
  162. }
  163. static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
  164. {
  165. u16 new_val;
  166. u16 beacon_factor;
  167. /*
  168. * If mac80211 hasn't given us a beacon interval, program
  169. * the default into the device (not checking this here
  170. * would cause the adjustment below to return the maximum
  171. * value, which may break PAN.)
  172. */
  173. if (!beacon_val)
  174. return DEFAULT_BEACON_INTERVAL;
  175. /*
  176. * If the beacon interval we obtained from the peer
  177. * is too large, we'll have to wake up more often
  178. * (and in IBSS case, we'll beacon too much)
  179. *
  180. * For example, if max_beacon_val is 4096, and the
  181. * requested beacon interval is 7000, we'll have to
  182. * use 3500 to be able to wake up on the beacons.
  183. *
  184. * This could badly influence beacon detection stats.
  185. */
  186. beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
  187. new_val = beacon_val / beacon_factor;
  188. if (!new_val)
  189. new_val = max_beacon_val;
  190. return new_val;
  191. }
  192. static int iwl_send_rxon_timing(struct iwl_priv *priv,
  193. struct iwl_rxon_context *ctx)
  194. {
  195. u64 tsf;
  196. s32 interval_tm, rem;
  197. struct ieee80211_conf *conf = NULL;
  198. u16 beacon_int;
  199. struct ieee80211_vif *vif = ctx->vif;
  200. conf = &priv->hw->conf;
  201. lockdep_assert_held(&priv->mutex);
  202. memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd));
  203. ctx->timing.timestamp = cpu_to_le64(priv->timestamp);
  204. ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval);
  205. beacon_int = vif ? vif->bss_conf.beacon_int : 0;
  206. /*
  207. * TODO: For IBSS we need to get atim_window from mac80211,
  208. * for now just always use 0
  209. */
  210. ctx->timing.atim_window = 0;
  211. if (ctx->ctxid == IWL_RXON_CTX_PAN &&
  212. (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION) &&
  213. iwl_is_associated(priv, IWL_RXON_CTX_BSS) &&
  214. priv->contexts[IWL_RXON_CTX_BSS].vif &&
  215. priv->contexts[IWL_RXON_CTX_BSS].vif->bss_conf.beacon_int) {
  216. ctx->timing.beacon_interval =
  217. priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval;
  218. beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
  219. } else if (ctx->ctxid == IWL_RXON_CTX_BSS &&
  220. iwl_is_associated(priv, IWL_RXON_CTX_PAN) &&
  221. priv->contexts[IWL_RXON_CTX_PAN].vif &&
  222. priv->contexts[IWL_RXON_CTX_PAN].vif->bss_conf.beacon_int &&
  223. (!iwl_is_associated_ctx(ctx) || !ctx->vif ||
  224. !ctx->vif->bss_conf.beacon_int)) {
  225. ctx->timing.beacon_interval =
  226. priv->contexts[IWL_RXON_CTX_PAN].timing.beacon_interval;
  227. beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
  228. } else {
  229. beacon_int = iwl_adjust_beacon_interval(beacon_int,
  230. IWL_MAX_UCODE_BEACON_INTERVAL * TIME_UNIT);
  231. ctx->timing.beacon_interval = cpu_to_le16(beacon_int);
  232. }
  233. ctx->beacon_int = beacon_int;
  234. tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
  235. interval_tm = beacon_int * TIME_UNIT;
  236. rem = do_div(tsf, interval_tm);
  237. ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
  238. ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1;
  239. IWL_DEBUG_ASSOC(priv,
  240. "beacon interval %d beacon timer %d beacon tim %d\n",
  241. le16_to_cpu(ctx->timing.beacon_interval),
  242. le32_to_cpu(ctx->timing.beacon_init_val),
  243. le16_to_cpu(ctx->timing.atim_window));
  244. return iwl_dvm_send_cmd_pdu(priv, ctx->rxon_timing_cmd,
  245. CMD_SYNC, sizeof(ctx->timing), &ctx->timing);
  246. }
  247. static int iwlagn_rxon_disconn(struct iwl_priv *priv,
  248. struct iwl_rxon_context *ctx)
  249. {
  250. int ret;
  251. struct iwl_rxon_cmd *active = (void *)&ctx->active;
  252. if (ctx->ctxid == IWL_RXON_CTX_BSS) {
  253. ret = iwlagn_disable_bss(priv, ctx, &ctx->staging);
  254. } else {
  255. ret = iwlagn_disable_pan(priv, ctx, &ctx->staging);
  256. if (ret)
  257. return ret;
  258. if (ctx->vif) {
  259. ret = iwl_send_rxon_timing(priv, ctx);
  260. if (ret) {
  261. IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
  262. return ret;
  263. }
  264. ret = iwlagn_disconn_pan(priv, ctx, &ctx->staging);
  265. }
  266. }
  267. if (ret)
  268. return ret;
  269. /*
  270. * Un-assoc RXON clears the station table and WEP
  271. * keys, so we have to restore those afterwards.
  272. */
  273. iwl_clear_ucode_stations(priv, ctx);
  274. /* update -- might need P2P now */
  275. iwl_update_bcast_station(priv, ctx);
  276. iwl_restore_stations(priv, ctx);
  277. ret = iwl_restore_default_wep_keys(priv, ctx);
  278. if (ret) {
  279. IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
  280. return ret;
  281. }
  282. memcpy(active, &ctx->staging, sizeof(*active));
  283. return 0;
  284. }
  285. static int iwlagn_rxon_connect(struct iwl_priv *priv,
  286. struct iwl_rxon_context *ctx)
  287. {
  288. int ret;
  289. struct iwl_rxon_cmd *active = (void *)&ctx->active;
  290. /* RXON timing must be before associated RXON */
  291. if (ctx->ctxid == IWL_RXON_CTX_BSS) {
  292. ret = iwl_send_rxon_timing(priv, ctx);
  293. if (ret) {
  294. IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
  295. return ret;
  296. }
  297. }
  298. /* QoS info may be cleared by previous un-assoc RXON */
  299. iwlagn_update_qos(priv, ctx);
  300. /*
  301. * We'll run into this code path when beaconing is
  302. * enabled, but then we also need to send the beacon
  303. * to the device.
  304. */
  305. if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) {
  306. ret = iwlagn_update_beacon(priv, ctx->vif);
  307. if (ret) {
  308. IWL_ERR(priv,
  309. "Error sending required beacon (%d)!\n",
  310. ret);
  311. return ret;
  312. }
  313. }
  314. priv->start_calib = 0;
  315. /*
  316. * Apply the new configuration.
  317. *
  318. * Associated RXON doesn't clear the station table in uCode,
  319. * so we don't need to restore stations etc. after this.
  320. */
  321. ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC,
  322. sizeof(struct iwl_rxon_cmd), &ctx->staging);
  323. if (ret) {
  324. IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
  325. return ret;
  326. }
  327. memcpy(active, &ctx->staging, sizeof(*active));
  328. /* IBSS beacon needs to be sent after setting assoc */
  329. if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC))
  330. if (iwlagn_update_beacon(priv, ctx->vif))
  331. IWL_ERR(priv, "Error sending IBSS beacon\n");
  332. iwl_init_sensitivity(priv);
  333. /*
  334. * If we issue a new RXON command which required a tune then
  335. * we must send a new TXPOWER command or we won't be able to
  336. * Tx any frames.
  337. *
  338. * It's expected we set power here if channel is changing.
  339. */
  340. ret = iwl_set_tx_power(priv, priv->tx_power_next, true);
  341. if (ret) {
  342. IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
  343. return ret;
  344. }
  345. if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION &&
  346. cfg(priv)->ht_params && cfg(priv)->ht_params->smps_mode)
  347. ieee80211_request_smps(ctx->vif,
  348. cfg(priv)->ht_params->smps_mode);
  349. return 0;
  350. }
  351. int iwlagn_set_pan_params(struct iwl_priv *priv)
  352. {
  353. struct iwl_wipan_params_cmd cmd;
  354. struct iwl_rxon_context *ctx_bss, *ctx_pan;
  355. int slot0 = 300, slot1 = 0;
  356. int ret;
  357. if (priv->valid_contexts == BIT(IWL_RXON_CTX_BSS))
  358. return 0;
  359. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  360. lockdep_assert_held(&priv->mutex);
  361. ctx_bss = &priv->contexts[IWL_RXON_CTX_BSS];
  362. ctx_pan = &priv->contexts[IWL_RXON_CTX_PAN];
  363. /*
  364. * If the PAN context is inactive, then we don't need
  365. * to update the PAN parameters, the last thing we'll
  366. * have done before it goes inactive is making the PAN
  367. * parameters be WLAN-only.
  368. */
  369. if (!ctx_pan->is_active)
  370. return 0;
  371. memset(&cmd, 0, sizeof(cmd));
  372. /* only 2 slots are currently allowed */
  373. cmd.num_slots = 2;
  374. cmd.slots[0].type = 0; /* BSS */
  375. cmd.slots[1].type = 1; /* PAN */
  376. if (priv->hw_roc_setup) {
  377. /* both contexts must be used for this to happen */
  378. slot1 = IWL_MIN_SLOT_TIME;
  379. slot0 = 3000;
  380. } else if (ctx_bss->vif && ctx_pan->vif) {
  381. int bcnint = ctx_pan->beacon_int;
  382. int dtim = ctx_pan->vif->bss_conf.dtim_period ?: 1;
  383. /* should be set, but seems unused?? */
  384. cmd.flags |= cpu_to_le16(IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE);
  385. if (ctx_pan->vif->type == NL80211_IFTYPE_AP &&
  386. bcnint &&
  387. bcnint != ctx_bss->beacon_int) {
  388. IWL_ERR(priv,
  389. "beacon intervals don't match (%d, %d)\n",
  390. ctx_bss->beacon_int, ctx_pan->beacon_int);
  391. } else
  392. bcnint = max_t(int, bcnint,
  393. ctx_bss->beacon_int);
  394. if (!bcnint)
  395. bcnint = DEFAULT_BEACON_INTERVAL;
  396. slot0 = bcnint / 2;
  397. slot1 = bcnint - slot0;
  398. if (test_bit(STATUS_SCAN_HW, &priv->status) ||
  399. (!ctx_bss->vif->bss_conf.idle &&
  400. !ctx_bss->vif->bss_conf.assoc)) {
  401. slot0 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
  402. slot1 = IWL_MIN_SLOT_TIME;
  403. } else if (!ctx_pan->vif->bss_conf.idle &&
  404. !ctx_pan->vif->bss_conf.assoc) {
  405. slot1 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
  406. slot0 = IWL_MIN_SLOT_TIME;
  407. }
  408. } else if (ctx_pan->vif) {
  409. slot0 = 0;
  410. slot1 = max_t(int, 1, ctx_pan->vif->bss_conf.dtim_period) *
  411. ctx_pan->beacon_int;
  412. slot1 = max_t(int, DEFAULT_BEACON_INTERVAL, slot1);
  413. if (test_bit(STATUS_SCAN_HW, &priv->status)) {
  414. slot0 = slot1 * 3 - IWL_MIN_SLOT_TIME;
  415. slot1 = IWL_MIN_SLOT_TIME;
  416. }
  417. }
  418. cmd.slots[0].width = cpu_to_le16(slot0);
  419. cmd.slots[1].width = cpu_to_le16(slot1);
  420. ret = iwl_dvm_send_cmd_pdu(priv, REPLY_WIPAN_PARAMS, CMD_SYNC,
  421. sizeof(cmd), &cmd);
  422. if (ret)
  423. IWL_ERR(priv, "Error setting PAN parameters (%d)\n", ret);
  424. return ret;
  425. }
  426. static void _iwl_set_rxon_ht(struct iwl_priv *priv,
  427. struct iwl_ht_config *ht_conf,
  428. struct iwl_rxon_context *ctx)
  429. {
  430. struct iwl_rxon_cmd *rxon = &ctx->staging;
  431. if (!ctx->ht.enabled) {
  432. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
  433. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
  434. RXON_FLG_HT40_PROT_MSK |
  435. RXON_FLG_HT_PROT_MSK);
  436. return;
  437. }
  438. /* FIXME: if the definition of ht.protection changed, the "translation"
  439. * will be needed for rxon->flags
  440. */
  441. rxon->flags |= cpu_to_le32(ctx->ht.protection <<
  442. RXON_FLG_HT_OPERATING_MODE_POS);
  443. /* Set up channel bandwidth:
  444. * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
  445. /* clear the HT channel mode before set the mode */
  446. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
  447. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  448. if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) {
  449. /* pure ht40 */
  450. if (ctx->ht.protection ==
  451. IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
  452. rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
  453. /*
  454. * Note: control channel is opposite of extension
  455. * channel
  456. */
  457. switch (ctx->ht.extension_chan_offset) {
  458. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  459. rxon->flags &=
  460. ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  461. break;
  462. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  463. rxon->flags |=
  464. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  465. break;
  466. }
  467. } else {
  468. /*
  469. * Note: control channel is opposite of extension
  470. * channel
  471. */
  472. switch (ctx->ht.extension_chan_offset) {
  473. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  474. rxon->flags &=
  475. ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  476. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
  477. break;
  478. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  479. rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  480. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
  481. break;
  482. case IEEE80211_HT_PARAM_CHA_SEC_NONE:
  483. default:
  484. /*
  485. * channel location only valid if in Mixed
  486. * mode
  487. */
  488. IWL_ERR(priv,
  489. "invalid extension channel offset\n");
  490. break;
  491. }
  492. }
  493. } else {
  494. rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
  495. }
  496. iwlagn_set_rxon_chain(priv, ctx);
  497. IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
  498. "extension channel offset 0x%x\n",
  499. le32_to_cpu(rxon->flags), ctx->ht.protection,
  500. ctx->ht.extension_chan_offset);
  501. }
  502. void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
  503. {
  504. struct iwl_rxon_context *ctx;
  505. for_each_context(priv, ctx)
  506. _iwl_set_rxon_ht(priv, ht_conf, ctx);
  507. }
  508. /**
  509. * iwl_set_rxon_channel - Set the band and channel values in staging RXON
  510. * @ch: requested channel as a pointer to struct ieee80211_channel
  511. * NOTE: Does not commit to the hardware; it sets appropriate bit fields
  512. * in the staging RXON flag structure based on the ch->band
  513. */
  514. void iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
  515. struct iwl_rxon_context *ctx)
  516. {
  517. enum ieee80211_band band = ch->band;
  518. u16 channel = ch->hw_value;
  519. if ((le16_to_cpu(ctx->staging.channel) == channel) &&
  520. (priv->band == band))
  521. return;
  522. ctx->staging.channel = cpu_to_le16(channel);
  523. if (band == IEEE80211_BAND_5GHZ)
  524. ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK;
  525. else
  526. ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
  527. priv->band = band;
  528. IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
  529. }
  530. void iwl_set_flags_for_band(struct iwl_priv *priv,
  531. struct iwl_rxon_context *ctx,
  532. enum ieee80211_band band,
  533. struct ieee80211_vif *vif)
  534. {
  535. if (band == IEEE80211_BAND_5GHZ) {
  536. ctx->staging.flags &=
  537. ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
  538. | RXON_FLG_CCK_MSK);
  539. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  540. } else {
  541. /* Copied from iwl_post_associate() */
  542. if (vif && vif->bss_conf.use_short_slot)
  543. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  544. else
  545. ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  546. ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
  547. ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK;
  548. ctx->staging.flags &= ~RXON_FLG_CCK_MSK;
  549. }
  550. }
  551. static void iwl_set_rxon_hwcrypto(struct iwl_priv *priv,
  552. struct iwl_rxon_context *ctx, int hw_decrypt)
  553. {
  554. struct iwl_rxon_cmd *rxon = &ctx->staging;
  555. if (hw_decrypt)
  556. rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
  557. else
  558. rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
  559. }
  560. /* validate RXON structure is valid */
  561. static int iwl_check_rxon_cmd(struct iwl_priv *priv,
  562. struct iwl_rxon_context *ctx)
  563. {
  564. struct iwl_rxon_cmd *rxon = &ctx->staging;
  565. u32 errors = 0;
  566. if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
  567. if (rxon->flags & RXON_FLG_TGJ_NARROW_BAND_MSK) {
  568. IWL_WARN(priv, "check 2.4G: wrong narrow\n");
  569. errors |= BIT(0);
  570. }
  571. if (rxon->flags & RXON_FLG_RADAR_DETECT_MSK) {
  572. IWL_WARN(priv, "check 2.4G: wrong radar\n");
  573. errors |= BIT(1);
  574. }
  575. } else {
  576. if (!(rxon->flags & RXON_FLG_SHORT_SLOT_MSK)) {
  577. IWL_WARN(priv, "check 5.2G: not short slot!\n");
  578. errors |= BIT(2);
  579. }
  580. if (rxon->flags & RXON_FLG_CCK_MSK) {
  581. IWL_WARN(priv, "check 5.2G: CCK!\n");
  582. errors |= BIT(3);
  583. }
  584. }
  585. if ((rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1) {
  586. IWL_WARN(priv, "mac/bssid mcast!\n");
  587. errors |= BIT(4);
  588. }
  589. /* make sure basic rates 6Mbps and 1Mbps are supported */
  590. if ((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0 &&
  591. (rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0) {
  592. IWL_WARN(priv, "neither 1 nor 6 are basic\n");
  593. errors |= BIT(5);
  594. }
  595. if (le16_to_cpu(rxon->assoc_id) > 2007) {
  596. IWL_WARN(priv, "aid > 2007\n");
  597. errors |= BIT(6);
  598. }
  599. if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
  600. == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) {
  601. IWL_WARN(priv, "CCK and short slot\n");
  602. errors |= BIT(7);
  603. }
  604. if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
  605. == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) {
  606. IWL_WARN(priv, "CCK and auto detect");
  607. errors |= BIT(8);
  608. }
  609. if ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
  610. RXON_FLG_TGG_PROTECT_MSK)) ==
  611. RXON_FLG_TGG_PROTECT_MSK) {
  612. IWL_WARN(priv, "TGg but no auto-detect\n");
  613. errors |= BIT(9);
  614. }
  615. if (rxon->channel == 0) {
  616. IWL_WARN(priv, "zero channel is invalid\n");
  617. errors |= BIT(10);
  618. }
  619. WARN(errors, "Invalid RXON (%#x), channel %d",
  620. errors, le16_to_cpu(rxon->channel));
  621. return errors ? -EINVAL : 0;
  622. }
  623. /**
  624. * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
  625. * @priv: staging_rxon is compared to active_rxon
  626. *
  627. * If the RXON structure is changing enough to require a new tune,
  628. * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
  629. * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
  630. */
  631. static int iwl_full_rxon_required(struct iwl_priv *priv,
  632. struct iwl_rxon_context *ctx)
  633. {
  634. const struct iwl_rxon_cmd *staging = &ctx->staging;
  635. const struct iwl_rxon_cmd *active = &ctx->active;
  636. #define CHK(cond) \
  637. if ((cond)) { \
  638. IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
  639. return 1; \
  640. }
  641. #define CHK_NEQ(c1, c2) \
  642. if ((c1) != (c2)) { \
  643. IWL_DEBUG_INFO(priv, "need full RXON - " \
  644. #c1 " != " #c2 " - %d != %d\n", \
  645. (c1), (c2)); \
  646. return 1; \
  647. }
  648. /* These items are only settable from the full RXON command */
  649. CHK(!iwl_is_associated_ctx(ctx));
  650. CHK(compare_ether_addr(staging->bssid_addr, active->bssid_addr));
  651. CHK(compare_ether_addr(staging->node_addr, active->node_addr));
  652. CHK(compare_ether_addr(staging->wlap_bssid_addr,
  653. active->wlap_bssid_addr));
  654. CHK_NEQ(staging->dev_type, active->dev_type);
  655. CHK_NEQ(staging->channel, active->channel);
  656. CHK_NEQ(staging->air_propagation, active->air_propagation);
  657. CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates,
  658. active->ofdm_ht_single_stream_basic_rates);
  659. CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates,
  660. active->ofdm_ht_dual_stream_basic_rates);
  661. CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates,
  662. active->ofdm_ht_triple_stream_basic_rates);
  663. CHK_NEQ(staging->assoc_id, active->assoc_id);
  664. /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
  665. * be updated with the RXON_ASSOC command -- however only some
  666. * flag transitions are allowed using RXON_ASSOC */
  667. /* Check if we are not switching bands */
  668. CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK,
  669. active->flags & RXON_FLG_BAND_24G_MSK);
  670. /* Check if we are switching association toggle */
  671. CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK,
  672. active->filter_flags & RXON_FILTER_ASSOC_MSK);
  673. #undef CHK
  674. #undef CHK_NEQ
  675. return 0;
  676. }
  677. /**
  678. * iwlagn_commit_rxon - commit staging_rxon to hardware
  679. *
  680. * The RXON command in staging_rxon is committed to the hardware and
  681. * the active_rxon structure is updated with the new data. This
  682. * function correctly transitions out of the RXON_ASSOC_MSK state if
  683. * a HW tune is required based on the RXON structure changes.
  684. *
  685. * The connect/disconnect flow should be as the following:
  686. *
  687. * 1. make sure send RXON command with association bit unset if not connect
  688. * this should include the channel and the band for the candidate
  689. * to be connected to
  690. * 2. Add Station before RXON association with the AP
  691. * 3. RXON_timing has to send before RXON for connection
  692. * 4. full RXON command - associated bit set
  693. * 5. use RXON_ASSOC command to update any flags changes
  694. */
  695. int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  696. {
  697. /* cast away the const for active_rxon in this function */
  698. struct iwl_rxon_cmd *active = (void *)&ctx->active;
  699. bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
  700. int ret;
  701. lockdep_assert_held(&priv->mutex);
  702. if (!iwl_is_alive(priv))
  703. return -EBUSY;
  704. /* This function hardcodes a bunch of dual-mode assumptions */
  705. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  706. if (!ctx->is_active)
  707. return 0;
  708. /* always get timestamp with Rx frame */
  709. ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
  710. /*
  711. * force CTS-to-self frames protection if RTS-CTS is not preferred
  712. * one aggregation protection method
  713. */
  714. if (!priv->hw_params.use_rts_for_aggregation)
  715. ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
  716. if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) ||
  717. !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK))
  718. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  719. else
  720. ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  721. iwl_print_rx_config_cmd(priv, ctx->ctxid);
  722. ret = iwl_check_rxon_cmd(priv, ctx);
  723. if (ret) {
  724. IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
  725. return -EINVAL;
  726. }
  727. /*
  728. * receive commit_rxon request
  729. * abort any previous channel switch if still in process
  730. */
  731. if (test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status) &&
  732. (priv->switch_channel != ctx->staging.channel)) {
  733. IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
  734. le16_to_cpu(priv->switch_channel));
  735. iwl_chswitch_done(priv, false);
  736. }
  737. /*
  738. * If we don't need to send a full RXON, we can use
  739. * iwl_rxon_assoc_cmd which is used to reconfigure filter
  740. * and other flags for the current radio configuration.
  741. */
  742. if (!iwl_full_rxon_required(priv, ctx)) {
  743. ret = iwlagn_send_rxon_assoc(priv, ctx);
  744. if (ret) {
  745. IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
  746. return ret;
  747. }
  748. memcpy(active, &ctx->staging, sizeof(*active));
  749. /*
  750. * We do not commit tx power settings while channel changing,
  751. * do it now if after settings changed.
  752. */
  753. iwl_set_tx_power(priv, priv->tx_power_next, false);
  754. /* make sure we are in the right PS state */
  755. iwl_power_update_mode(priv, true);
  756. return 0;
  757. }
  758. iwl_set_rxon_hwcrypto(priv, ctx, !iwlagn_mod_params.sw_crypto);
  759. IWL_DEBUG_INFO(priv,
  760. "Going to commit RXON\n"
  761. " * with%s RXON_FILTER_ASSOC_MSK\n"
  762. " * channel = %d\n"
  763. " * bssid = %pM\n",
  764. (new_assoc ? "" : "out"),
  765. le16_to_cpu(ctx->staging.channel),
  766. ctx->staging.bssid_addr);
  767. /*
  768. * Always clear associated first, but with the correct config.
  769. * This is required as for example station addition for the
  770. * AP station must be done after the BSSID is set to correctly
  771. * set up filters in the device.
  772. */
  773. ret = iwlagn_rxon_disconn(priv, ctx);
  774. if (ret)
  775. return ret;
  776. ret = iwlagn_set_pan_params(priv);
  777. if (ret)
  778. return ret;
  779. if (new_assoc)
  780. return iwlagn_rxon_connect(priv, ctx);
  781. return 0;
  782. }
  783. void iwlagn_config_ht40(struct ieee80211_conf *conf,
  784. struct iwl_rxon_context *ctx)
  785. {
  786. if (conf_is_ht40_minus(conf)) {
  787. ctx->ht.extension_chan_offset =
  788. IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  789. ctx->ht.is_40mhz = true;
  790. } else if (conf_is_ht40_plus(conf)) {
  791. ctx->ht.extension_chan_offset =
  792. IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  793. ctx->ht.is_40mhz = true;
  794. } else {
  795. ctx->ht.extension_chan_offset =
  796. IEEE80211_HT_PARAM_CHA_SEC_NONE;
  797. ctx->ht.is_40mhz = false;
  798. }
  799. }
  800. int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
  801. {
  802. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  803. struct iwl_rxon_context *ctx;
  804. struct ieee80211_conf *conf = &hw->conf;
  805. struct ieee80211_channel *channel = conf->channel;
  806. const struct iwl_channel_info *ch_info;
  807. int ret = 0;
  808. IWL_DEBUG_MAC80211(priv, "enter: changed %#x\n", changed);
  809. mutex_lock(&priv->mutex);
  810. if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
  811. IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
  812. goto out;
  813. }
  814. if (!iwl_is_ready(priv)) {
  815. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  816. goto out;
  817. }
  818. if (changed & (IEEE80211_CONF_CHANGE_SMPS |
  819. IEEE80211_CONF_CHANGE_CHANNEL)) {
  820. /* mac80211 uses static for non-HT which is what we want */
  821. priv->current_ht_config.smps = conf->smps_mode;
  822. /*
  823. * Recalculate chain counts.
  824. *
  825. * If monitor mode is enabled then mac80211 will
  826. * set up the SM PS mode to OFF if an HT channel is
  827. * configured.
  828. */
  829. for_each_context(priv, ctx)
  830. iwlagn_set_rxon_chain(priv, ctx);
  831. }
  832. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  833. ch_info = iwl_get_channel_info(priv, channel->band,
  834. channel->hw_value);
  835. if (!is_channel_valid(ch_info)) {
  836. IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
  837. ret = -EINVAL;
  838. goto out;
  839. }
  840. for_each_context(priv, ctx) {
  841. /* Configure HT40 channels */
  842. if (ctx->ht.enabled != conf_is_ht(conf))
  843. ctx->ht.enabled = conf_is_ht(conf);
  844. if (ctx->ht.enabled) {
  845. /* if HT40 is used, it should not change
  846. * after associated except channel switch */
  847. if (!ctx->ht.is_40mhz ||
  848. !iwl_is_associated_ctx(ctx))
  849. iwlagn_config_ht40(conf, ctx);
  850. } else
  851. ctx->ht.is_40mhz = false;
  852. /*
  853. * Default to no protection. Protection mode will
  854. * later be set from BSS config in iwl_ht_conf
  855. */
  856. ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
  857. /* if we are switching from ht to 2.4 clear flags
  858. * from any ht related info since 2.4 does not
  859. * support ht */
  860. if (le16_to_cpu(ctx->staging.channel) !=
  861. channel->hw_value)
  862. ctx->staging.flags = 0;
  863. iwl_set_rxon_channel(priv, channel, ctx);
  864. iwl_set_rxon_ht(priv, &priv->current_ht_config);
  865. iwl_set_flags_for_band(priv, ctx, channel->band,
  866. ctx->vif);
  867. }
  868. iwl_update_bcast_stations(priv);
  869. /*
  870. * The list of supported rates and rate mask can be different
  871. * for each band; since the band may have changed, reset
  872. * the rate mask to what mac80211 lists.
  873. */
  874. iwl_set_rate(priv);
  875. }
  876. if (changed & (IEEE80211_CONF_CHANGE_PS |
  877. IEEE80211_CONF_CHANGE_IDLE)) {
  878. ret = iwl_power_update_mode(priv, false);
  879. if (ret)
  880. IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
  881. }
  882. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  883. IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
  884. priv->tx_power_user_lmt, conf->power_level);
  885. iwl_set_tx_power(priv, conf->power_level, false);
  886. }
  887. for_each_context(priv, ctx) {
  888. if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
  889. continue;
  890. iwlagn_commit_rxon(priv, ctx);
  891. }
  892. out:
  893. mutex_unlock(&priv->mutex);
  894. IWL_DEBUG_MAC80211(priv, "leave\n");
  895. return ret;
  896. }
  897. static void iwlagn_check_needed_chains(struct iwl_priv *priv,
  898. struct iwl_rxon_context *ctx,
  899. struct ieee80211_bss_conf *bss_conf)
  900. {
  901. struct ieee80211_vif *vif = ctx->vif;
  902. struct iwl_rxon_context *tmp;
  903. struct ieee80211_sta *sta;
  904. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  905. struct ieee80211_sta_ht_cap *ht_cap;
  906. bool need_multiple;
  907. lockdep_assert_held(&priv->mutex);
  908. switch (vif->type) {
  909. case NL80211_IFTYPE_STATION:
  910. rcu_read_lock();
  911. sta = ieee80211_find_sta(vif, bss_conf->bssid);
  912. if (!sta) {
  913. /*
  914. * If at all, this can only happen through a race
  915. * when the AP disconnects us while we're still
  916. * setting up the connection, in that case mac80211
  917. * will soon tell us about that.
  918. */
  919. need_multiple = false;
  920. rcu_read_unlock();
  921. break;
  922. }
  923. ht_cap = &sta->ht_cap;
  924. need_multiple = true;
  925. /*
  926. * If the peer advertises no support for receiving 2 and 3
  927. * stream MCS rates, it can't be transmitting them either.
  928. */
  929. if (ht_cap->mcs.rx_mask[1] == 0 &&
  930. ht_cap->mcs.rx_mask[2] == 0) {
  931. need_multiple = false;
  932. } else if (!(ht_cap->mcs.tx_params &
  933. IEEE80211_HT_MCS_TX_DEFINED)) {
  934. /* If it can't TX MCS at all ... */
  935. need_multiple = false;
  936. } else if (ht_cap->mcs.tx_params &
  937. IEEE80211_HT_MCS_TX_RX_DIFF) {
  938. int maxstreams;
  939. /*
  940. * But if it can receive them, it might still not
  941. * be able to transmit them, which is what we need
  942. * to check here -- so check the number of streams
  943. * it advertises for TX (if different from RX).
  944. */
  945. maxstreams = (ht_cap->mcs.tx_params &
  946. IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK);
  947. maxstreams >>=
  948. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
  949. maxstreams += 1;
  950. if (maxstreams <= 1)
  951. need_multiple = false;
  952. }
  953. rcu_read_unlock();
  954. break;
  955. case NL80211_IFTYPE_ADHOC:
  956. /* currently */
  957. need_multiple = false;
  958. break;
  959. default:
  960. /* only AP really */
  961. need_multiple = true;
  962. break;
  963. }
  964. ctx->ht_need_multiple_chains = need_multiple;
  965. if (!need_multiple) {
  966. /* check all contexts */
  967. for_each_context(priv, tmp) {
  968. if (!tmp->vif)
  969. continue;
  970. if (tmp->ht_need_multiple_chains) {
  971. need_multiple = true;
  972. break;
  973. }
  974. }
  975. }
  976. ht_conf->single_chain_sufficient = !need_multiple;
  977. }
  978. static void iwlagn_chain_noise_reset(struct iwl_priv *priv)
  979. {
  980. struct iwl_chain_noise_data *data = &priv->chain_noise_data;
  981. int ret;
  982. if ((data->state == IWL_CHAIN_NOISE_ALIVE) &&
  983. iwl_is_any_associated(priv)) {
  984. struct iwl_calib_chain_noise_reset_cmd cmd;
  985. /* clear data for chain noise calibration algorithm */
  986. data->chain_noise_a = 0;
  987. data->chain_noise_b = 0;
  988. data->chain_noise_c = 0;
  989. data->chain_signal_a = 0;
  990. data->chain_signal_b = 0;
  991. data->chain_signal_c = 0;
  992. data->beacon_count = 0;
  993. memset(&cmd, 0, sizeof(cmd));
  994. iwl_set_calib_hdr(&cmd.hdr,
  995. priv->phy_calib_chain_noise_reset_cmd);
  996. ret = iwl_dvm_send_cmd_pdu(priv,
  997. REPLY_PHY_CALIBRATION_CMD,
  998. CMD_SYNC, sizeof(cmd), &cmd);
  999. if (ret)
  1000. IWL_ERR(priv,
  1001. "Could not send REPLY_PHY_CALIBRATION_CMD\n");
  1002. data->state = IWL_CHAIN_NOISE_ACCUMULATE;
  1003. IWL_DEBUG_CALIB(priv, "Run chain_noise_calibrate\n");
  1004. }
  1005. }
  1006. void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
  1007. struct ieee80211_vif *vif,
  1008. struct ieee80211_bss_conf *bss_conf,
  1009. u32 changes)
  1010. {
  1011. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1012. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1013. int ret;
  1014. bool force = false;
  1015. mutex_lock(&priv->mutex);
  1016. if (unlikely(!iwl_is_ready(priv))) {
  1017. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  1018. mutex_unlock(&priv->mutex);
  1019. return;
  1020. }
  1021. if (unlikely(!ctx->vif)) {
  1022. IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n");
  1023. mutex_unlock(&priv->mutex);
  1024. return;
  1025. }
  1026. if (changes & BSS_CHANGED_BEACON_INT)
  1027. force = true;
  1028. if (changes & BSS_CHANGED_QOS) {
  1029. ctx->qos_data.qos_active = bss_conf->qos;
  1030. iwlagn_update_qos(priv, ctx);
  1031. }
  1032. ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
  1033. if (vif->bss_conf.use_short_preamble)
  1034. ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  1035. else
  1036. ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  1037. if (changes & BSS_CHANGED_ASSOC) {
  1038. if (bss_conf->assoc) {
  1039. priv->timestamp = bss_conf->last_tsf;
  1040. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  1041. } else {
  1042. /*
  1043. * If we disassociate while there are pending
  1044. * frames, just wake up the queues and let the
  1045. * frames "escape" ... This shouldn't really
  1046. * be happening to start with, but we should
  1047. * not get stuck in this case either since it
  1048. * can happen if userspace gets confused.
  1049. */
  1050. iwlagn_lift_passive_no_rx(priv);
  1051. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1052. if (ctx->ctxid == IWL_RXON_CTX_BSS)
  1053. priv->have_rekey_data = false;
  1054. }
  1055. iwlagn_bt_coex_rssi_monitor(priv);
  1056. }
  1057. if (ctx->ht.enabled) {
  1058. ctx->ht.protection = bss_conf->ht_operation_mode &
  1059. IEEE80211_HT_OP_MODE_PROTECTION;
  1060. ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode &
  1061. IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
  1062. iwlagn_check_needed_chains(priv, ctx, bss_conf);
  1063. iwl_set_rxon_ht(priv, &priv->current_ht_config);
  1064. }
  1065. iwlagn_set_rxon_chain(priv, ctx);
  1066. if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
  1067. ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
  1068. else
  1069. ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
  1070. if (bss_conf->use_cts_prot)
  1071. ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
  1072. else
  1073. ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
  1074. memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN);
  1075. if (vif->type == NL80211_IFTYPE_AP ||
  1076. vif->type == NL80211_IFTYPE_ADHOC) {
  1077. if (vif->bss_conf.enable_beacon) {
  1078. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  1079. priv->beacon_ctx = ctx;
  1080. } else {
  1081. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1082. priv->beacon_ctx = NULL;
  1083. }
  1084. }
  1085. /*
  1086. * If the ucode decides to do beacon filtering before
  1087. * association, it will lose beacons that are needed
  1088. * before sending frames out on passive channels. This
  1089. * causes association failures on those channels. Enable
  1090. * receiving beacons in such cases.
  1091. */
  1092. if (vif->type == NL80211_IFTYPE_STATION) {
  1093. if (!bss_conf->assoc)
  1094. ctx->staging.filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
  1095. else
  1096. ctx->staging.filter_flags &=
  1097. ~RXON_FILTER_BCON_AWARE_MSK;
  1098. }
  1099. if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
  1100. iwlagn_commit_rxon(priv, ctx);
  1101. if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
  1102. /*
  1103. * The chain noise calibration will enable PM upon
  1104. * completion. If calibration has already been run
  1105. * then we need to enable power management here.
  1106. */
  1107. if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
  1108. iwl_power_update_mode(priv, false);
  1109. /* Enable RX differential gain and sensitivity calibrations */
  1110. if (!priv->disable_chain_noise_cal)
  1111. iwlagn_chain_noise_reset(priv);
  1112. priv->start_calib = 1;
  1113. }
  1114. if (changes & BSS_CHANGED_IBSS) {
  1115. ret = iwlagn_manage_ibss_station(priv, vif,
  1116. bss_conf->ibss_joined);
  1117. if (ret)
  1118. IWL_ERR(priv, "failed to %s IBSS station %pM\n",
  1119. bss_conf->ibss_joined ? "add" : "remove",
  1120. bss_conf->bssid);
  1121. }
  1122. if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_ADHOC &&
  1123. priv->beacon_ctx) {
  1124. if (iwlagn_update_beacon(priv, vif))
  1125. IWL_ERR(priv, "Error sending IBSS beacon\n");
  1126. }
  1127. mutex_unlock(&priv->mutex);
  1128. }
  1129. void iwlagn_post_scan(struct iwl_priv *priv)
  1130. {
  1131. struct iwl_rxon_context *ctx;
  1132. /*
  1133. * We do not commit power settings while scan is pending,
  1134. * do it now if the settings changed.
  1135. */
  1136. iwl_power_set_mode(priv, &priv->power_data.sleep_cmd_next, false);
  1137. iwl_set_tx_power(priv, priv->tx_power_next, false);
  1138. /*
  1139. * Since setting the RXON may have been deferred while
  1140. * performing the scan, fire one off if needed
  1141. */
  1142. for_each_context(priv, ctx)
  1143. if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
  1144. iwlagn_commit_rxon(priv, ctx);
  1145. iwlagn_set_pan_params(priv);
  1146. }