iwl-agn-rxon.c 42 KB

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