iwl-mac80211.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of version 2 of the GNU General Public License as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/init.h>
  32. #include <linux/slab.h>
  33. #include <linux/dma-mapping.h>
  34. #include <linux/delay.h>
  35. #include <linux/sched.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/netdevice.h>
  38. #include <linux/etherdevice.h>
  39. #include <linux/if_arp.h>
  40. #include <net/mac80211.h>
  41. #include <asm/div64.h>
  42. #include "iwl-eeprom.h"
  43. #include "iwl-dev.h"
  44. #include "iwl-core.h"
  45. #include "iwl-io.h"
  46. #include "iwl-agn-calib.h"
  47. #include "iwl-agn.h"
  48. #include "iwl-shared.h"
  49. #include "iwl-trans.h"
  50. #include "iwl-op-mode.h"
  51. /*****************************************************************************
  52. *
  53. * mac80211 entry point functions
  54. *
  55. *****************************************************************************/
  56. static const struct ieee80211_iface_limit iwlagn_sta_ap_limits[] = {
  57. {
  58. .max = 1,
  59. .types = BIT(NL80211_IFTYPE_STATION),
  60. },
  61. {
  62. .max = 1,
  63. .types = BIT(NL80211_IFTYPE_AP),
  64. },
  65. };
  66. static const struct ieee80211_iface_limit iwlagn_2sta_limits[] = {
  67. {
  68. .max = 2,
  69. .types = BIT(NL80211_IFTYPE_STATION),
  70. },
  71. };
  72. static const struct ieee80211_iface_limit iwlagn_p2p_sta_go_limits[] = {
  73. {
  74. .max = 1,
  75. .types = BIT(NL80211_IFTYPE_STATION),
  76. },
  77. {
  78. .max = 1,
  79. .types = BIT(NL80211_IFTYPE_P2P_GO) |
  80. BIT(NL80211_IFTYPE_AP),
  81. },
  82. };
  83. static const struct ieee80211_iface_limit iwlagn_p2p_2sta_limits[] = {
  84. {
  85. .max = 2,
  86. .types = BIT(NL80211_IFTYPE_STATION),
  87. },
  88. {
  89. .max = 1,
  90. .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
  91. },
  92. };
  93. static const struct ieee80211_iface_combination
  94. iwlagn_iface_combinations_dualmode[] = {
  95. { .num_different_channels = 1,
  96. .max_interfaces = 2,
  97. .beacon_int_infra_match = true,
  98. .limits = iwlagn_sta_ap_limits,
  99. .n_limits = ARRAY_SIZE(iwlagn_sta_ap_limits),
  100. },
  101. { .num_different_channels = 1,
  102. .max_interfaces = 2,
  103. .limits = iwlagn_2sta_limits,
  104. .n_limits = ARRAY_SIZE(iwlagn_2sta_limits),
  105. },
  106. };
  107. static const struct ieee80211_iface_combination
  108. iwlagn_iface_combinations_p2p[] = {
  109. { .num_different_channels = 1,
  110. .max_interfaces = 2,
  111. .beacon_int_infra_match = true,
  112. .limits = iwlagn_p2p_sta_go_limits,
  113. .n_limits = ARRAY_SIZE(iwlagn_p2p_sta_go_limits),
  114. },
  115. { .num_different_channels = 1,
  116. .max_interfaces = 2,
  117. .limits = iwlagn_p2p_2sta_limits,
  118. .n_limits = ARRAY_SIZE(iwlagn_p2p_2sta_limits),
  119. },
  120. };
  121. /*
  122. * Not a mac80211 entry point function, but it fits in with all the
  123. * other mac80211 functions grouped here.
  124. */
  125. int iwlagn_mac_setup_register(struct iwl_priv *priv,
  126. const struct iwl_ucode_capabilities *capa)
  127. {
  128. int ret;
  129. struct ieee80211_hw *hw = priv->hw;
  130. struct iwl_rxon_context *ctx;
  131. hw->rate_control_algorithm = "iwl-agn-rs";
  132. /* Tell mac80211 our characteristics */
  133. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  134. IEEE80211_HW_AMPDU_AGGREGATION |
  135. IEEE80211_HW_NEED_DTIM_PERIOD |
  136. IEEE80211_HW_SPECTRUM_MGMT |
  137. IEEE80211_HW_REPORTS_TX_ACK_STATUS;
  138. /*
  139. * Including the following line will crash some AP's. This
  140. * workaround removes the stimulus which causes the crash until
  141. * the AP software can be fixed.
  142. hw->max_tx_aggregation_subframes = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
  143. */
  144. hw->flags |= IEEE80211_HW_SUPPORTS_PS |
  145. IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
  146. IEEE80211_HW_SCAN_WHILE_IDLE;
  147. if (hw_params(priv).sku & EEPROM_SKU_CAP_11N_ENABLE)
  148. hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
  149. IEEE80211_HW_SUPPORTS_STATIC_SMPS;
  150. #ifndef CONFIG_IWLWIFI_EXPERIMENTAL_MFP
  151. /* enable 11w if the uCode advertise */
  152. if (capa->flags & IWL_UCODE_TLV_FLAGS_MFP)
  153. #endif /* !CONFIG_IWLWIFI_EXPERIMENTAL_MFP */
  154. hw->flags |= IEEE80211_HW_MFP_CAPABLE;
  155. hw->sta_data_size = sizeof(struct iwl_station_priv);
  156. hw->vif_data_size = sizeof(struct iwl_vif_priv);
  157. for_each_context(priv, ctx) {
  158. hw->wiphy->interface_modes |= ctx->interface_modes;
  159. hw->wiphy->interface_modes |= ctx->exclusive_interface_modes;
  160. }
  161. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  162. if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)) {
  163. hw->wiphy->iface_combinations = iwlagn_iface_combinations_p2p;
  164. hw->wiphy->n_iface_combinations =
  165. ARRAY_SIZE(iwlagn_iface_combinations_p2p);
  166. } else if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) {
  167. hw->wiphy->iface_combinations =
  168. iwlagn_iface_combinations_dualmode;
  169. hw->wiphy->n_iface_combinations =
  170. ARRAY_SIZE(iwlagn_iface_combinations_dualmode);
  171. }
  172. hw->wiphy->max_remain_on_channel_duration = 1000;
  173. hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
  174. WIPHY_FLAG_DISABLE_BEACON_HINTS |
  175. WIPHY_FLAG_IBSS_RSN;
  176. if (priv->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
  177. trans(priv)->ops->wowlan_suspend &&
  178. device_can_wakeup(trans(priv)->dev)) {
  179. hw->wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
  180. WIPHY_WOWLAN_DISCONNECT |
  181. WIPHY_WOWLAN_EAP_IDENTITY_REQ |
  182. WIPHY_WOWLAN_RFKILL_RELEASE;
  183. if (!iwlagn_mod_params.sw_crypto)
  184. hw->wiphy->wowlan.flags |=
  185. WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
  186. WIPHY_WOWLAN_GTK_REKEY_FAILURE;
  187. hw->wiphy->wowlan.n_patterns = IWLAGN_WOWLAN_MAX_PATTERNS;
  188. hw->wiphy->wowlan.pattern_min_len =
  189. IWLAGN_WOWLAN_MIN_PATTERN_LEN;
  190. hw->wiphy->wowlan.pattern_max_len =
  191. IWLAGN_WOWLAN_MAX_PATTERN_LEN;
  192. }
  193. if (iwlagn_mod_params.power_save)
  194. hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
  195. else
  196. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  197. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
  198. /* we create the 802.11 header and a zero-length SSID element */
  199. hw->wiphy->max_scan_ie_len = capa->max_probe_length - 24 - 2;
  200. /* Default value; 4 EDCA QOS priorities */
  201. hw->queues = 4;
  202. hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
  203. if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
  204. priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  205. &priv->bands[IEEE80211_BAND_2GHZ];
  206. if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
  207. priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  208. &priv->bands[IEEE80211_BAND_5GHZ];
  209. hw->wiphy->hw_version = trans(priv)->hw_id;
  210. iwl_leds_init(priv);
  211. ret = ieee80211_register_hw(priv->hw);
  212. if (ret) {
  213. IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
  214. return ret;
  215. }
  216. priv->mac80211_registered = 1;
  217. return 0;
  218. }
  219. void iwlagn_mac_unregister(struct iwl_priv *priv)
  220. {
  221. if (!priv->mac80211_registered)
  222. return;
  223. iwl_leds_exit(priv);
  224. ieee80211_unregister_hw(priv->hw);
  225. priv->mac80211_registered = 0;
  226. }
  227. static int __iwl_up(struct iwl_priv *priv)
  228. {
  229. struct iwl_rxon_context *ctx;
  230. int ret;
  231. lockdep_assert_held(&priv->mutex);
  232. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  233. IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
  234. return -EIO;
  235. }
  236. for_each_context(priv, ctx) {
  237. ret = iwlagn_alloc_bcast_station(priv, ctx);
  238. if (ret) {
  239. iwl_dealloc_bcast_stations(priv);
  240. return ret;
  241. }
  242. }
  243. ret = iwl_run_init_ucode(priv);
  244. if (ret) {
  245. IWL_ERR(priv, "Failed to run INIT ucode: %d\n", ret);
  246. goto error;
  247. }
  248. ret = iwl_load_ucode_wait_alive(priv, IWL_UCODE_REGULAR);
  249. if (ret) {
  250. IWL_ERR(priv, "Failed to start RT ucode: %d\n", ret);
  251. goto error;
  252. }
  253. ret = iwl_alive_start(priv);
  254. if (ret)
  255. goto error;
  256. return 0;
  257. error:
  258. set_bit(STATUS_EXIT_PENDING, &priv->status);
  259. iwl_down(priv);
  260. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  261. IWL_ERR(priv, "Unable to initialize device.\n");
  262. return ret;
  263. }
  264. static int iwlagn_mac_start(struct ieee80211_hw *hw)
  265. {
  266. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  267. int ret;
  268. IWL_DEBUG_MAC80211(priv, "enter\n");
  269. /* we should be verifying the device is ready to be opened */
  270. mutex_lock(&priv->mutex);
  271. ret = __iwl_up(priv);
  272. mutex_unlock(&priv->mutex);
  273. if (ret)
  274. return ret;
  275. IWL_DEBUG_INFO(priv, "Start UP work done.\n");
  276. /* Now we should be done, and the READY bit should be set. */
  277. if (WARN_ON(!test_bit(STATUS_READY, &priv->status)))
  278. ret = -EIO;
  279. iwlagn_led_enable(priv);
  280. priv->is_open = 1;
  281. IWL_DEBUG_MAC80211(priv, "leave\n");
  282. return 0;
  283. }
  284. static void iwlagn_mac_stop(struct ieee80211_hw *hw)
  285. {
  286. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  287. IWL_DEBUG_MAC80211(priv, "enter\n");
  288. if (!priv->is_open)
  289. return;
  290. priv->is_open = 0;
  291. mutex_lock(&priv->mutex);
  292. iwl_down(priv);
  293. mutex_unlock(&priv->mutex);
  294. iwl_cancel_deferred_work(priv);
  295. flush_workqueue(priv->workqueue);
  296. /* User space software may expect getting rfkill changes
  297. * even if interface is down, trans->down will leave the RF
  298. * kill interrupt enabled
  299. */
  300. iwl_trans_stop_hw(trans(priv));
  301. IWL_DEBUG_MAC80211(priv, "leave\n");
  302. }
  303. static void iwlagn_mac_set_rekey_data(struct ieee80211_hw *hw,
  304. struct ieee80211_vif *vif,
  305. struct cfg80211_gtk_rekey_data *data)
  306. {
  307. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  308. if (iwlagn_mod_params.sw_crypto)
  309. return;
  310. IWL_DEBUG_MAC80211(priv, "enter\n");
  311. mutex_lock(&priv->mutex);
  312. if (priv->contexts[IWL_RXON_CTX_BSS].vif != vif)
  313. goto out;
  314. memcpy(priv->kek, data->kek, NL80211_KEK_LEN);
  315. memcpy(priv->kck, data->kck, NL80211_KCK_LEN);
  316. priv->replay_ctr =
  317. cpu_to_le64(be64_to_cpup((__be64 *)&data->replay_ctr));
  318. priv->have_rekey_data = true;
  319. out:
  320. mutex_unlock(&priv->mutex);
  321. IWL_DEBUG_MAC80211(priv, "leave\n");
  322. }
  323. #ifdef CONFIG_PM_SLEEP
  324. static int iwlagn_mac_suspend(struct ieee80211_hw *hw,
  325. struct cfg80211_wowlan *wowlan)
  326. {
  327. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  328. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  329. int ret;
  330. if (WARN_ON(!wowlan))
  331. return -EINVAL;
  332. IWL_DEBUG_MAC80211(priv, "enter\n");
  333. mutex_lock(&priv->mutex);
  334. /* Don't attempt WoWLAN when not associated, tear down instead. */
  335. if (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION ||
  336. !iwl_is_associated_ctx(ctx)) {
  337. ret = 1;
  338. goto out;
  339. }
  340. ret = iwlagn_suspend(priv, wowlan);
  341. if (ret)
  342. goto error;
  343. device_set_wakeup_enable(trans(priv)->dev, true);
  344. iwl_trans_wowlan_suspend(trans(priv));
  345. goto out;
  346. error:
  347. priv->wowlan = false;
  348. iwlagn_prepare_restart(priv);
  349. ieee80211_restart_hw(priv->hw);
  350. out:
  351. mutex_unlock(&priv->mutex);
  352. IWL_DEBUG_MAC80211(priv, "leave\n");
  353. return ret;
  354. }
  355. static int iwlagn_mac_resume(struct ieee80211_hw *hw)
  356. {
  357. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  358. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  359. struct ieee80211_vif *vif;
  360. unsigned long flags;
  361. u32 base, status = 0xffffffff;
  362. int ret = -EIO;
  363. IWL_DEBUG_MAC80211(priv, "enter\n");
  364. mutex_lock(&priv->mutex);
  365. iwl_write32(trans(priv), CSR_UCODE_DRV_GP1_CLR,
  366. CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE);
  367. base = priv->device_pointers.error_event_table;
  368. if (iwlagn_hw_valid_rtc_data_addr(base)) {
  369. spin_lock_irqsave(&trans(priv)->reg_lock, flags);
  370. ret = iwl_grab_nic_access_silent(trans(priv));
  371. if (likely(ret == 0)) {
  372. iwl_write32(trans(priv), HBUS_TARG_MEM_RADDR, base);
  373. status = iwl_read32(trans(priv), HBUS_TARG_MEM_RDAT);
  374. iwl_release_nic_access(trans(priv));
  375. }
  376. spin_unlock_irqrestore(&trans(priv)->reg_lock, flags);
  377. #ifdef CONFIG_IWLWIFI_DEBUGFS
  378. if (ret == 0) {
  379. const struct fw_img *img;
  380. img = &(priv->fw->img[IWL_UCODE_WOWLAN]);
  381. if (!priv->wowlan_sram) {
  382. priv->wowlan_sram =
  383. kzalloc(img->sec[IWL_UCODE_SECTION_DATA].len,
  384. GFP_KERNEL);
  385. }
  386. if (priv->wowlan_sram)
  387. _iwl_read_targ_mem_words(
  388. trans(priv), 0x800000,
  389. priv->wowlan_sram,
  390. img->sec[IWL_UCODE_SECTION_DATA].len / 4);
  391. }
  392. #endif
  393. }
  394. /* we'll clear ctx->vif during iwlagn_prepare_restart() */
  395. vif = ctx->vif;
  396. priv->wowlan = false;
  397. device_set_wakeup_enable(trans(priv)->dev, false);
  398. iwlagn_prepare_restart(priv);
  399. memset((void *)&ctx->active, 0, sizeof(ctx->active));
  400. iwl_connection_init_rx_config(priv, ctx);
  401. iwlagn_set_rxon_chain(priv, ctx);
  402. mutex_unlock(&priv->mutex);
  403. IWL_DEBUG_MAC80211(priv, "leave\n");
  404. ieee80211_resume_disconnect(vif);
  405. return 1;
  406. }
  407. #endif
  408. static void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  409. {
  410. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  411. IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  412. ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
  413. if (iwlagn_tx_skb(priv, skb))
  414. dev_kfree_skb_any(skb);
  415. }
  416. static void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw,
  417. struct ieee80211_vif *vif,
  418. struct ieee80211_key_conf *keyconf,
  419. struct ieee80211_sta *sta,
  420. u32 iv32, u16 *phase1key)
  421. {
  422. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  423. iwl_update_tkip_key(priv, vif, keyconf, sta, iv32, phase1key);
  424. }
  425. static int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  426. struct ieee80211_vif *vif,
  427. struct ieee80211_sta *sta,
  428. struct ieee80211_key_conf *key)
  429. {
  430. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  431. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  432. struct iwl_rxon_context *ctx = vif_priv->ctx;
  433. int ret;
  434. bool is_default_wep_key = false;
  435. IWL_DEBUG_MAC80211(priv, "enter\n");
  436. if (iwlagn_mod_params.sw_crypto) {
  437. IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
  438. return -EOPNOTSUPP;
  439. }
  440. switch (key->cipher) {
  441. case WLAN_CIPHER_SUITE_TKIP:
  442. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  443. /* fall through */
  444. case WLAN_CIPHER_SUITE_CCMP:
  445. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  446. break;
  447. default:
  448. break;
  449. }
  450. /*
  451. * We could program these keys into the hardware as well, but we
  452. * don't expect much multicast traffic in IBSS and having keys
  453. * for more stations is probably more useful.
  454. *
  455. * Mark key TX-only and return 0.
  456. */
  457. if (vif->type == NL80211_IFTYPE_ADHOC &&
  458. !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
  459. key->hw_key_idx = WEP_INVALID_OFFSET;
  460. return 0;
  461. }
  462. /* If they key was TX-only, accept deletion */
  463. if (cmd == DISABLE_KEY && key->hw_key_idx == WEP_INVALID_OFFSET)
  464. return 0;
  465. mutex_lock(&priv->mutex);
  466. iwl_scan_cancel_timeout(priv, 100);
  467. BUILD_BUG_ON(WEP_INVALID_OFFSET == IWLAGN_HW_KEY_DEFAULT);
  468. /*
  469. * If we are getting WEP group key and we didn't receive any key mapping
  470. * so far, we are in legacy wep mode (group key only), otherwise we are
  471. * in 1X mode.
  472. * In legacy wep mode, we use another host command to the uCode.
  473. */
  474. if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  475. key->cipher == WLAN_CIPHER_SUITE_WEP104) && !sta) {
  476. if (cmd == SET_KEY)
  477. is_default_wep_key = !ctx->key_mapping_keys;
  478. else
  479. is_default_wep_key =
  480. key->hw_key_idx == IWLAGN_HW_KEY_DEFAULT;
  481. }
  482. switch (cmd) {
  483. case SET_KEY:
  484. if (is_default_wep_key) {
  485. ret = iwl_set_default_wep_key(priv, vif_priv->ctx, key);
  486. break;
  487. }
  488. ret = iwl_set_dynamic_key(priv, vif_priv->ctx, key, sta);
  489. if (ret) {
  490. /*
  491. * can't add key for RX, but we don't need it
  492. * in the device for TX so still return 0
  493. */
  494. ret = 0;
  495. key->hw_key_idx = WEP_INVALID_OFFSET;
  496. }
  497. IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
  498. break;
  499. case DISABLE_KEY:
  500. if (is_default_wep_key)
  501. ret = iwl_remove_default_wep_key(priv, ctx, key);
  502. else
  503. ret = iwl_remove_dynamic_key(priv, ctx, key, sta);
  504. IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
  505. break;
  506. default:
  507. ret = -EINVAL;
  508. }
  509. mutex_unlock(&priv->mutex);
  510. IWL_DEBUG_MAC80211(priv, "leave\n");
  511. return ret;
  512. }
  513. static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
  514. struct ieee80211_vif *vif,
  515. enum ieee80211_ampdu_mlme_action action,
  516. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  517. u8 buf_size)
  518. {
  519. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  520. int ret = -EINVAL;
  521. struct iwl_station_priv *sta_priv = (void *) sta->drv_priv;
  522. IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
  523. sta->addr, tid);
  524. if (!(hw_params(priv).sku & EEPROM_SKU_CAP_11N_ENABLE))
  525. return -EACCES;
  526. IWL_DEBUG_MAC80211(priv, "enter\n");
  527. mutex_lock(&priv->mutex);
  528. switch (action) {
  529. case IEEE80211_AMPDU_RX_START:
  530. if (iwlagn_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
  531. break;
  532. IWL_DEBUG_HT(priv, "start Rx\n");
  533. ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn);
  534. break;
  535. case IEEE80211_AMPDU_RX_STOP:
  536. IWL_DEBUG_HT(priv, "stop Rx\n");
  537. ret = iwl_sta_rx_agg_stop(priv, sta, tid);
  538. break;
  539. case IEEE80211_AMPDU_TX_START:
  540. if (!trans(priv)->ops->tx_agg_setup)
  541. break;
  542. if (iwlagn_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
  543. break;
  544. IWL_DEBUG_HT(priv, "start Tx\n");
  545. ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn);
  546. break;
  547. case IEEE80211_AMPDU_TX_STOP:
  548. IWL_DEBUG_HT(priv, "stop Tx\n");
  549. ret = iwlagn_tx_agg_stop(priv, vif, sta, tid);
  550. if ((ret == 0) && (priv->agg_tids_count > 0)) {
  551. priv->agg_tids_count--;
  552. IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n",
  553. priv->agg_tids_count);
  554. }
  555. if (!priv->agg_tids_count &&
  556. hw_params(priv).use_rts_for_aggregation) {
  557. /*
  558. * switch off RTS/CTS if it was previously enabled
  559. */
  560. sta_priv->lq_sta.lq.general_params.flags &=
  561. ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
  562. iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
  563. &sta_priv->lq_sta.lq, CMD_ASYNC, false);
  564. }
  565. break;
  566. case IEEE80211_AMPDU_TX_OPERATIONAL:
  567. ret = iwlagn_tx_agg_oper(priv, vif, sta, tid, buf_size);
  568. break;
  569. }
  570. mutex_unlock(&priv->mutex);
  571. IWL_DEBUG_MAC80211(priv, "leave\n");
  572. return ret;
  573. }
  574. static int iwlagn_mac_sta_add(struct ieee80211_hw *hw,
  575. struct ieee80211_vif *vif,
  576. struct ieee80211_sta *sta)
  577. {
  578. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  579. struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
  580. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  581. bool is_ap = vif->type == NL80211_IFTYPE_STATION;
  582. int ret;
  583. u8 sta_id;
  584. IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
  585. sta->addr);
  586. sta_priv->sta_id = IWL_INVALID_STATION;
  587. atomic_set(&sta_priv->pending_frames, 0);
  588. if (vif->type == NL80211_IFTYPE_AP)
  589. sta_priv->client = true;
  590. ret = iwl_add_station_common(priv, vif_priv->ctx, sta->addr,
  591. is_ap, sta, &sta_id);
  592. if (ret) {
  593. IWL_ERR(priv, "Unable to add station %pM (%d)\n",
  594. sta->addr, ret);
  595. /* Should we return success if return code is EEXIST ? */
  596. return ret;
  597. }
  598. sta_priv->sta_id = sta_id;
  599. return 0;
  600. }
  601. static int iwlagn_mac_sta_remove(struct ieee80211_hw *hw,
  602. struct ieee80211_vif *vif,
  603. struct ieee80211_sta *sta)
  604. {
  605. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  606. struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
  607. int ret;
  608. IWL_DEBUG_INFO(priv, "proceeding to remove station %pM\n", sta->addr);
  609. if (vif->type == NL80211_IFTYPE_STATION) {
  610. /*
  611. * Station will be removed from device when the RXON
  612. * is set to unassociated -- just deactivate it here
  613. * to avoid re-programming it.
  614. */
  615. ret = 0;
  616. iwl_deactivate_station(priv, sta_priv->sta_id, sta->addr);
  617. } else {
  618. ret = iwl_remove_station(priv, sta_priv->sta_id, sta->addr);
  619. if (ret)
  620. IWL_DEBUG_QUIET_RFKILL(priv,
  621. "Error removing station %pM\n", sta->addr);
  622. }
  623. return ret;
  624. }
  625. static int iwlagn_mac_sta_state(struct ieee80211_hw *hw,
  626. struct ieee80211_vif *vif,
  627. struct ieee80211_sta *sta,
  628. enum ieee80211_sta_state old_state,
  629. enum ieee80211_sta_state new_state)
  630. {
  631. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  632. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  633. enum {
  634. NONE, ADD, REMOVE, HT_RATE_INIT, ADD_RATE_INIT,
  635. } op = NONE;
  636. int ret;
  637. IWL_DEBUG_MAC80211(priv, "station %pM state change %d->%d\n",
  638. sta->addr, old_state, new_state);
  639. mutex_lock(&priv->mutex);
  640. if (vif->type == NL80211_IFTYPE_STATION) {
  641. if (old_state == IEEE80211_STA_NOTEXIST &&
  642. new_state == IEEE80211_STA_NONE)
  643. op = ADD;
  644. else if (old_state == IEEE80211_STA_NONE &&
  645. new_state == IEEE80211_STA_NOTEXIST)
  646. op = REMOVE;
  647. else if (old_state == IEEE80211_STA_AUTH &&
  648. new_state == IEEE80211_STA_ASSOC)
  649. op = HT_RATE_INIT;
  650. } else {
  651. if (old_state == IEEE80211_STA_AUTH &&
  652. new_state == IEEE80211_STA_ASSOC)
  653. op = ADD_RATE_INIT;
  654. else if (old_state == IEEE80211_STA_ASSOC &&
  655. new_state == IEEE80211_STA_AUTH)
  656. op = REMOVE;
  657. }
  658. switch (op) {
  659. case ADD:
  660. ret = iwlagn_mac_sta_add(hw, vif, sta);
  661. break;
  662. case REMOVE:
  663. ret = iwlagn_mac_sta_remove(hw, vif, sta);
  664. break;
  665. case ADD_RATE_INIT:
  666. ret = iwlagn_mac_sta_add(hw, vif, sta);
  667. if (ret)
  668. break;
  669. /* Initialize rate scaling */
  670. IWL_DEBUG_INFO(priv,
  671. "Initializing rate scaling for station %pM\n",
  672. sta->addr);
  673. iwl_rs_rate_init(priv, sta, iwl_sta_id(sta));
  674. ret = 0;
  675. break;
  676. case HT_RATE_INIT:
  677. /* Initialize rate scaling */
  678. ret = iwl_sta_update_ht(priv, vif_priv->ctx, sta);
  679. if (ret)
  680. break;
  681. IWL_DEBUG_INFO(priv,
  682. "Initializing rate scaling for station %pM\n",
  683. sta->addr);
  684. iwl_rs_rate_init(priv, sta, iwl_sta_id(sta));
  685. ret = 0;
  686. break;
  687. default:
  688. ret = 0;
  689. break;
  690. }
  691. /*
  692. * mac80211 might WARN if we fail, but due the way we
  693. * (badly) handle hard rfkill, we might fail here
  694. */
  695. if (iwl_is_rfkill(priv))
  696. ret = 0;
  697. mutex_unlock(&priv->mutex);
  698. IWL_DEBUG_MAC80211(priv, "leave\n");
  699. return ret;
  700. }
  701. static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
  702. struct ieee80211_channel_switch *ch_switch)
  703. {
  704. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  705. const struct iwl_channel_info *ch_info;
  706. struct ieee80211_conf *conf = &hw->conf;
  707. struct ieee80211_channel *channel = ch_switch->channel;
  708. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  709. /*
  710. * MULTI-FIXME
  711. * When we add support for multiple interfaces, we need to
  712. * revisit this. The channel switch command in the device
  713. * only affects the BSS context, but what does that really
  714. * mean? And what if we get a CSA on the second interface?
  715. * This needs a lot of work.
  716. */
  717. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  718. u16 ch;
  719. IWL_DEBUG_MAC80211(priv, "enter\n");
  720. mutex_lock(&priv->mutex);
  721. if (iwl_is_rfkill(priv))
  722. goto out;
  723. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  724. test_bit(STATUS_SCANNING, &priv->status) ||
  725. test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status))
  726. goto out;
  727. if (!iwl_is_associated_ctx(ctx))
  728. goto out;
  729. if (!cfg(priv)->lib->set_channel_switch)
  730. goto out;
  731. ch = channel->hw_value;
  732. if (le16_to_cpu(ctx->active.channel) == ch)
  733. goto out;
  734. ch_info = iwl_get_channel_info(priv, channel->band, ch);
  735. if (!is_channel_valid(ch_info)) {
  736. IWL_DEBUG_MAC80211(priv, "invalid channel\n");
  737. goto out;
  738. }
  739. priv->current_ht_config.smps = conf->smps_mode;
  740. /* Configure HT40 channels */
  741. ctx->ht.enabled = conf_is_ht(conf);
  742. if (ctx->ht.enabled)
  743. iwlagn_config_ht40(conf, ctx);
  744. else
  745. ctx->ht.is_40mhz = false;
  746. if ((le16_to_cpu(ctx->staging.channel) != ch))
  747. ctx->staging.flags = 0;
  748. iwl_set_rxon_channel(priv, channel, ctx);
  749. iwl_set_rxon_ht(priv, ht_conf);
  750. iwl_set_flags_for_band(priv, ctx, channel->band, ctx->vif);
  751. iwl_set_rate(priv);
  752. /*
  753. * at this point, staging_rxon has the
  754. * configuration for channel switch
  755. */
  756. set_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status);
  757. priv->switch_channel = cpu_to_le16(ch);
  758. if (cfg(priv)->lib->set_channel_switch(priv, ch_switch)) {
  759. clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status);
  760. priv->switch_channel = 0;
  761. ieee80211_chswitch_done(ctx->vif, false);
  762. }
  763. out:
  764. mutex_unlock(&priv->mutex);
  765. IWL_DEBUG_MAC80211(priv, "leave\n");
  766. }
  767. static void iwlagn_configure_filter(struct ieee80211_hw *hw,
  768. unsigned int changed_flags,
  769. unsigned int *total_flags,
  770. u64 multicast)
  771. {
  772. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  773. __le32 filter_or = 0, filter_nand = 0;
  774. struct iwl_rxon_context *ctx;
  775. #define CHK(test, flag) do { \
  776. if (*total_flags & (test)) \
  777. filter_or |= (flag); \
  778. else \
  779. filter_nand |= (flag); \
  780. } while (0)
  781. IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
  782. changed_flags, *total_flags);
  783. CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
  784. /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */
  785. CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK);
  786. CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
  787. #undef CHK
  788. mutex_lock(&priv->mutex);
  789. for_each_context(priv, ctx) {
  790. ctx->staging.filter_flags &= ~filter_nand;
  791. ctx->staging.filter_flags |= filter_or;
  792. /*
  793. * Not committing directly because hardware can perform a scan,
  794. * but we'll eventually commit the filter flags change anyway.
  795. */
  796. }
  797. mutex_unlock(&priv->mutex);
  798. /*
  799. * Receiving all multicast frames is always enabled by the
  800. * default flags setup in iwl_connection_init_rx_config()
  801. * since we currently do not support programming multicast
  802. * filters into the device.
  803. */
  804. *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
  805. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
  806. }
  807. static void iwlagn_mac_flush(struct ieee80211_hw *hw, bool drop)
  808. {
  809. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  810. mutex_lock(&priv->mutex);
  811. IWL_DEBUG_MAC80211(priv, "enter\n");
  812. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  813. IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n");
  814. goto done;
  815. }
  816. if (iwl_is_rfkill(priv)) {
  817. IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n");
  818. goto done;
  819. }
  820. /*
  821. * mac80211 will not push any more frames for transmit
  822. * until the flush is completed
  823. */
  824. if (drop) {
  825. IWL_DEBUG_MAC80211(priv, "send flush command\n");
  826. if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) {
  827. IWL_ERR(priv, "flush request fail\n");
  828. goto done;
  829. }
  830. }
  831. IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n");
  832. iwl_trans_wait_tx_queue_empty(trans(priv));
  833. done:
  834. mutex_unlock(&priv->mutex);
  835. IWL_DEBUG_MAC80211(priv, "leave\n");
  836. }
  837. static int iwlagn_mac_remain_on_channel(struct ieee80211_hw *hw,
  838. struct ieee80211_channel *channel,
  839. enum nl80211_channel_type channel_type,
  840. int duration)
  841. {
  842. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  843. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
  844. int err = 0;
  845. if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
  846. return -EOPNOTSUPP;
  847. if (!(ctx->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)))
  848. return -EOPNOTSUPP;
  849. IWL_DEBUG_MAC80211(priv, "enter\n");
  850. mutex_lock(&priv->mutex);
  851. if (test_bit(STATUS_SCAN_HW, &priv->status)) {
  852. err = -EBUSY;
  853. goto out;
  854. }
  855. priv->hw_roc_channel = channel;
  856. priv->hw_roc_chantype = channel_type;
  857. /* convert from ms to TU */
  858. priv->hw_roc_duration = DIV_ROUND_UP(1000 * duration, 1024);
  859. priv->hw_roc_start_notified = false;
  860. cancel_delayed_work(&priv->hw_roc_disable_work);
  861. if (!ctx->is_active) {
  862. static const struct iwl_qos_info default_qos_data = {
  863. .def_qos_parm = {
  864. .ac[0] = {
  865. .cw_min = cpu_to_le16(3),
  866. .cw_max = cpu_to_le16(7),
  867. .aifsn = 2,
  868. .edca_txop = cpu_to_le16(1504),
  869. },
  870. .ac[1] = {
  871. .cw_min = cpu_to_le16(7),
  872. .cw_max = cpu_to_le16(15),
  873. .aifsn = 2,
  874. .edca_txop = cpu_to_le16(3008),
  875. },
  876. .ac[2] = {
  877. .cw_min = cpu_to_le16(15),
  878. .cw_max = cpu_to_le16(1023),
  879. .aifsn = 3,
  880. },
  881. .ac[3] = {
  882. .cw_min = cpu_to_le16(15),
  883. .cw_max = cpu_to_le16(1023),
  884. .aifsn = 7,
  885. },
  886. },
  887. };
  888. ctx->is_active = true;
  889. ctx->qos_data = default_qos_data;
  890. ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
  891. memcpy(ctx->staging.node_addr,
  892. priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr,
  893. ETH_ALEN);
  894. memcpy(ctx->staging.bssid_addr,
  895. priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr,
  896. ETH_ALEN);
  897. err = iwlagn_commit_rxon(priv, ctx);
  898. if (err)
  899. goto out;
  900. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK |
  901. RXON_FILTER_PROMISC_MSK |
  902. RXON_FILTER_CTL2HOST_MSK;
  903. err = iwlagn_commit_rxon(priv, ctx);
  904. if (err) {
  905. iwlagn_disable_roc(priv);
  906. goto out;
  907. }
  908. priv->hw_roc_setup = true;
  909. }
  910. err = iwl_scan_initiate(priv, ctx->vif, IWL_SCAN_ROC, channel->band);
  911. if (err)
  912. iwlagn_disable_roc(priv);
  913. out:
  914. mutex_unlock(&priv->mutex);
  915. IWL_DEBUG_MAC80211(priv, "leave\n");
  916. return err;
  917. }
  918. static int iwlagn_mac_cancel_remain_on_channel(struct ieee80211_hw *hw)
  919. {
  920. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  921. if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
  922. return -EOPNOTSUPP;
  923. IWL_DEBUG_MAC80211(priv, "enter\n");
  924. mutex_lock(&priv->mutex);
  925. iwl_scan_cancel_timeout(priv, priv->hw_roc_duration);
  926. iwlagn_disable_roc(priv);
  927. mutex_unlock(&priv->mutex);
  928. IWL_DEBUG_MAC80211(priv, "leave\n");
  929. return 0;
  930. }
  931. static void iwlagn_mac_rssi_callback(struct ieee80211_hw *hw,
  932. enum ieee80211_rssi_event rssi_event)
  933. {
  934. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  935. IWL_DEBUG_MAC80211(priv, "enter\n");
  936. mutex_lock(&priv->mutex);
  937. if (cfg(priv)->bt_params &&
  938. cfg(priv)->bt_params->advanced_bt_coexist) {
  939. if (rssi_event == RSSI_EVENT_LOW)
  940. priv->bt_enable_pspoll = true;
  941. else if (rssi_event == RSSI_EVENT_HIGH)
  942. priv->bt_enable_pspoll = false;
  943. iwlagn_send_advance_bt_config(priv);
  944. } else {
  945. IWL_DEBUG_MAC80211(priv, "Advanced BT coex disabled,"
  946. "ignoring RSSI callback\n");
  947. }
  948. mutex_unlock(&priv->mutex);
  949. IWL_DEBUG_MAC80211(priv, "leave\n");
  950. }
  951. static int iwlagn_mac_set_tim(struct ieee80211_hw *hw,
  952. struct ieee80211_sta *sta, bool set)
  953. {
  954. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  955. queue_work(priv->workqueue, &priv->beacon_update);
  956. return 0;
  957. }
  958. static int iwlagn_mac_conf_tx(struct ieee80211_hw *hw,
  959. struct ieee80211_vif *vif, u16 queue,
  960. const struct ieee80211_tx_queue_params *params)
  961. {
  962. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  963. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  964. struct iwl_rxon_context *ctx = vif_priv->ctx;
  965. int q;
  966. if (WARN_ON(!ctx))
  967. return -EINVAL;
  968. IWL_DEBUG_MAC80211(priv, "enter\n");
  969. if (!iwl_is_ready_rf(priv)) {
  970. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  971. return -EIO;
  972. }
  973. if (queue >= AC_NUM) {
  974. IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
  975. return 0;
  976. }
  977. q = AC_NUM - 1 - queue;
  978. mutex_lock(&priv->mutex);
  979. ctx->qos_data.def_qos_parm.ac[q].cw_min =
  980. cpu_to_le16(params->cw_min);
  981. ctx->qos_data.def_qos_parm.ac[q].cw_max =
  982. cpu_to_le16(params->cw_max);
  983. ctx->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
  984. ctx->qos_data.def_qos_parm.ac[q].edca_txop =
  985. cpu_to_le16((params->txop * 32));
  986. ctx->qos_data.def_qos_parm.ac[q].reserved1 = 0;
  987. mutex_unlock(&priv->mutex);
  988. IWL_DEBUG_MAC80211(priv, "leave\n");
  989. return 0;
  990. }
  991. static int iwlagn_mac_tx_last_beacon(struct ieee80211_hw *hw)
  992. {
  993. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  994. return priv->ibss_manager == IWL_IBSS_MANAGER;
  995. }
  996. static int iwl_set_mode(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  997. {
  998. iwl_connection_init_rx_config(priv, ctx);
  999. iwlagn_set_rxon_chain(priv, ctx);
  1000. return iwlagn_commit_rxon(priv, ctx);
  1001. }
  1002. static int iwl_setup_interface(struct iwl_priv *priv,
  1003. struct iwl_rxon_context *ctx)
  1004. {
  1005. struct ieee80211_vif *vif = ctx->vif;
  1006. int err;
  1007. lockdep_assert_held(&priv->mutex);
  1008. /*
  1009. * This variable will be correct only when there's just
  1010. * a single context, but all code using it is for hardware
  1011. * that supports only one context.
  1012. */
  1013. priv->iw_mode = vif->type;
  1014. ctx->is_active = true;
  1015. err = iwl_set_mode(priv, ctx);
  1016. if (err) {
  1017. if (!ctx->always_active)
  1018. ctx->is_active = false;
  1019. return err;
  1020. }
  1021. if (cfg(priv)->bt_params && cfg(priv)->bt_params->advanced_bt_coexist &&
  1022. vif->type == NL80211_IFTYPE_ADHOC) {
  1023. /*
  1024. * pretend to have high BT traffic as long as we
  1025. * are operating in IBSS mode, as this will cause
  1026. * the rate scaling etc. to behave as intended.
  1027. */
  1028. priv->bt_traffic_load = IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
  1029. }
  1030. return 0;
  1031. }
  1032. static int iwlagn_mac_add_interface(struct ieee80211_hw *hw,
  1033. struct ieee80211_vif *vif)
  1034. {
  1035. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1036. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  1037. struct iwl_rxon_context *tmp, *ctx = NULL;
  1038. int err;
  1039. enum nl80211_iftype viftype = ieee80211_vif_type_p2p(vif);
  1040. IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n",
  1041. viftype, vif->addr);
  1042. cancel_delayed_work_sync(&priv->hw_roc_disable_work);
  1043. mutex_lock(&priv->mutex);
  1044. iwlagn_disable_roc(priv);
  1045. if (!iwl_is_ready_rf(priv)) {
  1046. IWL_WARN(priv, "Try to add interface when device not ready\n");
  1047. err = -EINVAL;
  1048. goto out;
  1049. }
  1050. for_each_context(priv, tmp) {
  1051. u32 possible_modes =
  1052. tmp->interface_modes | tmp->exclusive_interface_modes;
  1053. if (tmp->vif) {
  1054. /* check if this busy context is exclusive */
  1055. if (tmp->exclusive_interface_modes &
  1056. BIT(tmp->vif->type)) {
  1057. err = -EINVAL;
  1058. goto out;
  1059. }
  1060. continue;
  1061. }
  1062. if (!(possible_modes & BIT(viftype)))
  1063. continue;
  1064. /* have maybe usable context w/o interface */
  1065. ctx = tmp;
  1066. break;
  1067. }
  1068. if (!ctx) {
  1069. err = -EOPNOTSUPP;
  1070. goto out;
  1071. }
  1072. vif_priv->ctx = ctx;
  1073. ctx->vif = vif;
  1074. err = iwl_setup_interface(priv, ctx);
  1075. if (!err)
  1076. goto out;
  1077. ctx->vif = NULL;
  1078. priv->iw_mode = NL80211_IFTYPE_STATION;
  1079. out:
  1080. mutex_unlock(&priv->mutex);
  1081. IWL_DEBUG_MAC80211(priv, "leave\n");
  1082. return err;
  1083. }
  1084. static void iwl_teardown_interface(struct iwl_priv *priv,
  1085. struct ieee80211_vif *vif,
  1086. bool mode_change)
  1087. {
  1088. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1089. lockdep_assert_held(&priv->mutex);
  1090. if (priv->scan_vif == vif) {
  1091. iwl_scan_cancel_timeout(priv, 200);
  1092. iwl_force_scan_end(priv);
  1093. }
  1094. if (!mode_change) {
  1095. iwl_set_mode(priv, ctx);
  1096. if (!ctx->always_active)
  1097. ctx->is_active = false;
  1098. }
  1099. /*
  1100. * When removing the IBSS interface, overwrite the
  1101. * BT traffic load with the stored one from the last
  1102. * notification, if any. If this is a device that
  1103. * doesn't implement this, this has no effect since
  1104. * both values are the same and zero.
  1105. */
  1106. if (vif->type == NL80211_IFTYPE_ADHOC)
  1107. priv->bt_traffic_load = priv->last_bt_traffic_load;
  1108. }
  1109. static void iwlagn_mac_remove_interface(struct ieee80211_hw *hw,
  1110. struct ieee80211_vif *vif)
  1111. {
  1112. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1113. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1114. IWL_DEBUG_MAC80211(priv, "enter\n");
  1115. mutex_lock(&priv->mutex);
  1116. if (WARN_ON(ctx->vif != vif)) {
  1117. struct iwl_rxon_context *tmp;
  1118. IWL_ERR(priv, "ctx->vif = %p, vif = %p\n", ctx->vif, vif);
  1119. for_each_context(priv, tmp)
  1120. IWL_ERR(priv, "\tID = %d:\tctx = %p\tctx->vif = %p\n",
  1121. tmp->ctxid, tmp, tmp->vif);
  1122. }
  1123. ctx->vif = NULL;
  1124. iwl_teardown_interface(priv, vif, false);
  1125. mutex_unlock(&priv->mutex);
  1126. IWL_DEBUG_MAC80211(priv, "leave\n");
  1127. }
  1128. static int iwlagn_mac_change_interface(struct ieee80211_hw *hw,
  1129. struct ieee80211_vif *vif,
  1130. enum nl80211_iftype newtype, bool newp2p)
  1131. {
  1132. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1133. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1134. struct iwl_rxon_context *bss_ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  1135. struct iwl_rxon_context *tmp;
  1136. enum nl80211_iftype newviftype = newtype;
  1137. u32 interface_modes;
  1138. int err;
  1139. IWL_DEBUG_MAC80211(priv, "enter\n");
  1140. newtype = ieee80211_iftype_p2p(newtype, newp2p);
  1141. mutex_lock(&priv->mutex);
  1142. if (!ctx->vif || !iwl_is_ready_rf(priv)) {
  1143. /*
  1144. * Huh? But wait ... this can maybe happen when
  1145. * we're in the middle of a firmware restart!
  1146. */
  1147. err = -EBUSY;
  1148. goto out;
  1149. }
  1150. interface_modes = ctx->interface_modes | ctx->exclusive_interface_modes;
  1151. if (!(interface_modes & BIT(newtype))) {
  1152. err = -EBUSY;
  1153. goto out;
  1154. }
  1155. /*
  1156. * Refuse a change that should be done by moving from the PAN
  1157. * context to the BSS context instead, if the BSS context is
  1158. * available and can support the new interface type.
  1159. */
  1160. if (ctx->ctxid == IWL_RXON_CTX_PAN && !bss_ctx->vif &&
  1161. (bss_ctx->interface_modes & BIT(newtype) ||
  1162. bss_ctx->exclusive_interface_modes & BIT(newtype))) {
  1163. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  1164. err = -EBUSY;
  1165. goto out;
  1166. }
  1167. if (ctx->exclusive_interface_modes & BIT(newtype)) {
  1168. for_each_context(priv, tmp) {
  1169. if (ctx == tmp)
  1170. continue;
  1171. if (!tmp->vif)
  1172. continue;
  1173. /*
  1174. * The current mode switch would be exclusive, but
  1175. * another context is active ... refuse the switch.
  1176. */
  1177. err = -EBUSY;
  1178. goto out;
  1179. }
  1180. }
  1181. /* success */
  1182. iwl_teardown_interface(priv, vif, true);
  1183. vif->type = newviftype;
  1184. vif->p2p = newp2p;
  1185. err = iwl_setup_interface(priv, ctx);
  1186. WARN_ON(err);
  1187. /*
  1188. * We've switched internally, but submitting to the
  1189. * device may have failed for some reason. Mask this
  1190. * error, because otherwise mac80211 will not switch
  1191. * (and set the interface type back) and we'll be
  1192. * out of sync with it.
  1193. */
  1194. err = 0;
  1195. out:
  1196. mutex_unlock(&priv->mutex);
  1197. IWL_DEBUG_MAC80211(priv, "leave\n");
  1198. return err;
  1199. }
  1200. static int iwlagn_mac_hw_scan(struct ieee80211_hw *hw,
  1201. struct ieee80211_vif *vif,
  1202. struct cfg80211_scan_request *req)
  1203. {
  1204. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1205. int ret;
  1206. IWL_DEBUG_MAC80211(priv, "enter\n");
  1207. if (req->n_channels == 0)
  1208. return -EINVAL;
  1209. mutex_lock(&priv->mutex);
  1210. /*
  1211. * If an internal scan is in progress, just set
  1212. * up the scan_request as per above.
  1213. */
  1214. if (priv->scan_type != IWL_SCAN_NORMAL) {
  1215. IWL_DEBUG_SCAN(priv,
  1216. "SCAN request during internal scan - defer\n");
  1217. priv->scan_request = req;
  1218. priv->scan_vif = vif;
  1219. ret = 0;
  1220. } else {
  1221. priv->scan_request = req;
  1222. priv->scan_vif = vif;
  1223. /*
  1224. * mac80211 will only ask for one band at a time
  1225. * so using channels[0] here is ok
  1226. */
  1227. ret = iwl_scan_initiate(priv, vif, IWL_SCAN_NORMAL,
  1228. req->channels[0]->band);
  1229. if (ret) {
  1230. priv->scan_request = NULL;
  1231. priv->scan_vif = NULL;
  1232. }
  1233. }
  1234. IWL_DEBUG_MAC80211(priv, "leave\n");
  1235. mutex_unlock(&priv->mutex);
  1236. return ret;
  1237. }
  1238. static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
  1239. {
  1240. struct iwl_addsta_cmd cmd = {
  1241. .mode = STA_CONTROL_MODIFY_MSK,
  1242. .station_flags_msk = STA_FLG_PWR_SAVE_MSK,
  1243. .sta.sta_id = sta_id,
  1244. };
  1245. iwl_send_add_sta(priv, &cmd, CMD_ASYNC);
  1246. }
  1247. static void iwlagn_mac_sta_notify(struct ieee80211_hw *hw,
  1248. struct ieee80211_vif *vif,
  1249. enum sta_notify_cmd cmd,
  1250. struct ieee80211_sta *sta)
  1251. {
  1252. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1253. struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
  1254. int sta_id;
  1255. IWL_DEBUG_MAC80211(priv, "enter\n");
  1256. switch (cmd) {
  1257. case STA_NOTIFY_SLEEP:
  1258. WARN_ON(!sta_priv->client);
  1259. sta_priv->asleep = true;
  1260. if (atomic_read(&sta_priv->pending_frames) > 0)
  1261. ieee80211_sta_block_awake(hw, sta, true);
  1262. break;
  1263. case STA_NOTIFY_AWAKE:
  1264. WARN_ON(!sta_priv->client);
  1265. if (!sta_priv->asleep)
  1266. break;
  1267. sta_priv->asleep = false;
  1268. sta_id = iwl_sta_id(sta);
  1269. if (sta_id != IWL_INVALID_STATION)
  1270. iwl_sta_modify_ps_wake(priv, sta_id);
  1271. break;
  1272. default:
  1273. break;
  1274. }
  1275. IWL_DEBUG_MAC80211(priv, "leave\n");
  1276. }
  1277. struct ieee80211_ops iwlagn_hw_ops = {
  1278. .tx = iwlagn_mac_tx,
  1279. .start = iwlagn_mac_start,
  1280. .stop = iwlagn_mac_stop,
  1281. #ifdef CONFIG_PM_SLEEP
  1282. .suspend = iwlagn_mac_suspend,
  1283. .resume = iwlagn_mac_resume,
  1284. #endif
  1285. .add_interface = iwlagn_mac_add_interface,
  1286. .remove_interface = iwlagn_mac_remove_interface,
  1287. .change_interface = iwlagn_mac_change_interface,
  1288. .config = iwlagn_mac_config,
  1289. .configure_filter = iwlagn_configure_filter,
  1290. .set_key = iwlagn_mac_set_key,
  1291. .update_tkip_key = iwlagn_mac_update_tkip_key,
  1292. .set_rekey_data = iwlagn_mac_set_rekey_data,
  1293. .conf_tx = iwlagn_mac_conf_tx,
  1294. .bss_info_changed = iwlagn_bss_info_changed,
  1295. .ampdu_action = iwlagn_mac_ampdu_action,
  1296. .hw_scan = iwlagn_mac_hw_scan,
  1297. .sta_notify = iwlagn_mac_sta_notify,
  1298. .sta_state = iwlagn_mac_sta_state,
  1299. .channel_switch = iwlagn_mac_channel_switch,
  1300. .flush = iwlagn_mac_flush,
  1301. .tx_last_beacon = iwlagn_mac_tx_last_beacon,
  1302. .remain_on_channel = iwlagn_mac_remain_on_channel,
  1303. .cancel_remain_on_channel = iwlagn_mac_cancel_remain_on_channel,
  1304. .rssi_callback = iwlagn_mac_rssi_callback,
  1305. CFG80211_TESTMODE_CMD(iwlagn_mac_testmode_cmd)
  1306. CFG80211_TESTMODE_DUMP(iwlagn_mac_testmode_dump)
  1307. .set_tim = iwlagn_mac_set_tim,
  1308. };
  1309. /* This function both allocates and initializes hw and priv. */
  1310. struct ieee80211_hw *iwl_alloc_all(void)
  1311. {
  1312. struct iwl_priv *priv;
  1313. struct iwl_op_mode *op_mode;
  1314. /* mac80211 allocates memory for this device instance, including
  1315. * space for this driver's private structure */
  1316. struct ieee80211_hw *hw;
  1317. hw = ieee80211_alloc_hw(sizeof(struct iwl_priv) +
  1318. sizeof(struct iwl_op_mode), &iwlagn_hw_ops);
  1319. if (!hw)
  1320. goto out;
  1321. op_mode = hw->priv;
  1322. priv = IWL_OP_MODE_GET_DVM(op_mode);
  1323. priv->hw = hw;
  1324. out:
  1325. return hw;
  1326. }