iwl-agn-rxon.c 40 KB

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