iwl-mac80211.c 41 KB

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