iwl-mac80211.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611
  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-ucode.h"
  43. #include "iwl-eeprom.h"
  44. #include "iwl-wifi.h"
  45. #include "iwl-dev.h"
  46. #include "iwl-core.h"
  47. #include "iwl-io.h"
  48. #include "iwl-agn-calib.h"
  49. #include "iwl-agn.h"
  50. #include "iwl-shared.h"
  51. #include "iwl-bus.h"
  52. #include "iwl-trans.h"
  53. #include "iwl-op-mode.h"
  54. /*****************************************************************************
  55. *
  56. * mac80211 entry point functions
  57. *
  58. *****************************************************************************/
  59. static const struct ieee80211_iface_limit iwlagn_sta_ap_limits[] = {
  60. {
  61. .max = 1,
  62. .types = BIT(NL80211_IFTYPE_STATION),
  63. },
  64. {
  65. .max = 1,
  66. .types = BIT(NL80211_IFTYPE_AP),
  67. },
  68. };
  69. static const struct ieee80211_iface_limit iwlagn_2sta_limits[] = {
  70. {
  71. .max = 2,
  72. .types = BIT(NL80211_IFTYPE_STATION),
  73. },
  74. };
  75. static const struct ieee80211_iface_limit iwlagn_p2p_sta_go_limits[] = {
  76. {
  77. .max = 1,
  78. .types = BIT(NL80211_IFTYPE_STATION),
  79. },
  80. {
  81. .max = 1,
  82. .types = BIT(NL80211_IFTYPE_P2P_GO) |
  83. BIT(NL80211_IFTYPE_AP),
  84. },
  85. };
  86. static const struct ieee80211_iface_limit iwlagn_p2p_2sta_limits[] = {
  87. {
  88. .max = 2,
  89. .types = BIT(NL80211_IFTYPE_STATION),
  90. },
  91. {
  92. .max = 1,
  93. .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
  94. },
  95. };
  96. static const struct ieee80211_iface_combination
  97. iwlagn_iface_combinations_dualmode[] = {
  98. { .num_different_channels = 1,
  99. .max_interfaces = 2,
  100. .beacon_int_infra_match = true,
  101. .limits = iwlagn_sta_ap_limits,
  102. .n_limits = ARRAY_SIZE(iwlagn_sta_ap_limits),
  103. },
  104. { .num_different_channels = 1,
  105. .max_interfaces = 2,
  106. .limits = iwlagn_2sta_limits,
  107. .n_limits = ARRAY_SIZE(iwlagn_2sta_limits),
  108. },
  109. };
  110. static const struct ieee80211_iface_combination
  111. iwlagn_iface_combinations_p2p[] = {
  112. { .num_different_channels = 1,
  113. .max_interfaces = 2,
  114. .beacon_int_infra_match = true,
  115. .limits = iwlagn_p2p_sta_go_limits,
  116. .n_limits = ARRAY_SIZE(iwlagn_p2p_sta_go_limits),
  117. },
  118. { .num_different_channels = 1,
  119. .max_interfaces = 2,
  120. .limits = iwlagn_p2p_2sta_limits,
  121. .n_limits = ARRAY_SIZE(iwlagn_p2p_2sta_limits),
  122. },
  123. };
  124. /*
  125. * Not a mac80211 entry point function, but it fits in with all the
  126. * other mac80211 functions grouped here.
  127. */
  128. int iwlagn_mac_setup_register(struct iwl_priv *priv,
  129. struct iwl_ucode_capabilities *capa)
  130. {
  131. int ret;
  132. struct ieee80211_hw *hw = priv->hw;
  133. struct iwl_rxon_context *ctx;
  134. hw->rate_control_algorithm = "iwl-agn-rs";
  135. /* Tell mac80211 our characteristics */
  136. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  137. IEEE80211_HW_AMPDU_AGGREGATION |
  138. IEEE80211_HW_NEED_DTIM_PERIOD |
  139. IEEE80211_HW_SPECTRUM_MGMT |
  140. IEEE80211_HW_REPORTS_TX_ACK_STATUS;
  141. /*
  142. * Including the following line will crash some AP's. This
  143. * workaround removes the stimulus which causes the crash until
  144. * the AP software can be fixed.
  145. hw->max_tx_aggregation_subframes = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
  146. */
  147. hw->flags |= IEEE80211_HW_SUPPORTS_PS |
  148. IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
  149. if (cfg(priv)->sku & EEPROM_SKU_CAP_11N_ENABLE)
  150. hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
  151. IEEE80211_HW_SUPPORTS_STATIC_SMPS;
  152. if (capa->flags & IWL_UCODE_TLV_FLAGS_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 (nic(priv)->fw.ucode_wowlan.code.len &&
  176. device_can_wakeup(trans(priv)->dev)) {
  177. hw->wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
  178. WIPHY_WOWLAN_DISCONNECT |
  179. WIPHY_WOWLAN_EAP_IDENTITY_REQ |
  180. WIPHY_WOWLAN_RFKILL_RELEASE;
  181. if (!iwlagn_mod_params.sw_crypto)
  182. hw->wiphy->wowlan.flags |=
  183. WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
  184. WIPHY_WOWLAN_GTK_REKEY_FAILURE;
  185. hw->wiphy->wowlan.n_patterns = IWLAGN_WOWLAN_MAX_PATTERNS;
  186. hw->wiphy->wowlan.pattern_min_len =
  187. IWLAGN_WOWLAN_MIN_PATTERN_LEN;
  188. hw->wiphy->wowlan.pattern_max_len =
  189. IWLAGN_WOWLAN_MAX_PATTERN_LEN;
  190. }
  191. if (iwlagn_mod_params.power_save)
  192. hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
  193. else
  194. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  195. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
  196. /* we create the 802.11 header and a zero-length SSID element */
  197. hw->wiphy->max_scan_ie_len = capa->max_probe_length - 24 - 2;
  198. /* Default value; 4 EDCA QOS priorities */
  199. hw->queues = 4;
  200. hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
  201. if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
  202. priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  203. &priv->bands[IEEE80211_BAND_2GHZ];
  204. if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
  205. priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  206. &priv->bands[IEEE80211_BAND_5GHZ];
  207. hw->wiphy->hw_version = trans(priv)->hw_id;
  208. iwl_leds_init(priv);
  209. ret = ieee80211_register_hw(priv->hw);
  210. if (ret) {
  211. IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
  212. return ret;
  213. }
  214. priv->mac80211_registered = 1;
  215. return 0;
  216. }
  217. void iwlagn_mac_unregister(struct iwl_priv *priv)
  218. {
  219. if (!priv->mac80211_registered)
  220. return;
  221. iwl_leds_exit(priv);
  222. ieee80211_unregister_hw(priv->hw);
  223. priv->mac80211_registered = 0;
  224. }
  225. static int __iwl_up(struct iwl_priv *priv)
  226. {
  227. struct iwl_rxon_context *ctx;
  228. int ret;
  229. lockdep_assert_held(&priv->shrd->mutex);
  230. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status)) {
  231. IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
  232. return -EIO;
  233. }
  234. for_each_context(priv, ctx) {
  235. ret = iwlagn_alloc_bcast_station(priv, ctx);
  236. if (ret) {
  237. iwl_dealloc_bcast_stations(priv);
  238. return ret;
  239. }
  240. }
  241. ret = iwl_run_init_ucode(trans(priv));
  242. if (ret) {
  243. IWL_ERR(priv, "Failed to run INIT ucode: %d\n", ret);
  244. goto error;
  245. }
  246. ret = iwl_load_ucode_wait_alive(trans(priv), IWL_UCODE_REGULAR);
  247. if (ret) {
  248. IWL_ERR(priv, "Failed to start RT ucode: %d\n", ret);
  249. goto error;
  250. }
  251. ret = iwl_alive_start(priv);
  252. if (ret)
  253. goto error;
  254. return 0;
  255. error:
  256. set_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
  257. iwl_down(priv);
  258. clear_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
  259. IWL_ERR(priv, "Unable to initialize device.\n");
  260. return ret;
  261. }
  262. static int iwlagn_mac_start(struct ieee80211_hw *hw)
  263. {
  264. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  265. int ret;
  266. IWL_DEBUG_MAC80211(priv, "enter\n");
  267. /* we should be verifying the device is ready to be opened */
  268. mutex_lock(&priv->shrd->mutex);
  269. ret = __iwl_up(priv);
  270. mutex_unlock(&priv->shrd->mutex);
  271. if (ret)
  272. return ret;
  273. IWL_DEBUG_INFO(priv, "Start UP work done.\n");
  274. /* Now we should be done, and the READY bit should be set. */
  275. if (WARN_ON(!test_bit(STATUS_READY, &priv->shrd->status)))
  276. ret = -EIO;
  277. iwlagn_led_enable(priv);
  278. priv->is_open = 1;
  279. IWL_DEBUG_MAC80211(priv, "leave\n");
  280. return 0;
  281. }
  282. static void iwlagn_mac_stop(struct ieee80211_hw *hw)
  283. {
  284. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  285. IWL_DEBUG_MAC80211(priv, "enter\n");
  286. if (!priv->is_open)
  287. return;
  288. priv->is_open = 0;
  289. mutex_lock(&priv->shrd->mutex);
  290. iwl_down(priv);
  291. mutex_unlock(&priv->shrd->mutex);
  292. iwl_cancel_deferred_work(priv);
  293. flush_workqueue(priv->workqueue);
  294. /* User space software may expect getting rfkill changes
  295. * even if interface is down, trans->down will leave the RF
  296. * kill interrupt enabled
  297. */
  298. iwl_trans_stop_hw(trans(priv));
  299. IWL_DEBUG_MAC80211(priv, "leave\n");
  300. }
  301. static void iwlagn_mac_set_rekey_data(struct ieee80211_hw *hw,
  302. struct ieee80211_vif *vif,
  303. struct cfg80211_gtk_rekey_data *data)
  304. {
  305. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  306. if (iwlagn_mod_params.sw_crypto)
  307. return;
  308. IWL_DEBUG_MAC80211(priv, "enter\n");
  309. mutex_lock(&priv->shrd->mutex);
  310. if (priv->contexts[IWL_RXON_CTX_BSS].vif != vif)
  311. goto out;
  312. memcpy(priv->kek, data->kek, NL80211_KEK_LEN);
  313. memcpy(priv->kck, data->kck, NL80211_KCK_LEN);
  314. priv->replay_ctr =
  315. cpu_to_le64(be64_to_cpup((__be64 *)&data->replay_ctr));
  316. priv->have_rekey_data = true;
  317. out:
  318. mutex_unlock(&priv->shrd->mutex);
  319. IWL_DEBUG_MAC80211(priv, "leave\n");
  320. }
  321. #ifdef CONFIG_PM_SLEEP
  322. static int iwlagn_mac_suspend(struct ieee80211_hw *hw,
  323. 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->shrd->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, hw, wowlan);
  339. if (ret)
  340. goto error;
  341. device_set_wakeup_enable(trans(priv)->dev, true);
  342. /* Now let the ucode operate on its own */
  343. iwl_write32(trans(priv), CSR_UCODE_DRV_GP1_SET,
  344. CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE);
  345. goto out;
  346. error:
  347. priv->shrd->wowlan = false;
  348. iwlagn_prepare_restart(priv);
  349. ieee80211_restart_hw(priv->hw);
  350. out:
  351. mutex_unlock(&priv->shrd->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->shrd->mutex);
  365. iwl_write32(trans(priv), CSR_UCODE_DRV_GP1_CLR,
  366. CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE);
  367. base = priv->shrd->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 (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. struct iwl_nic *nic = nic(priv);
  380. if (!priv->wowlan_sram)
  381. priv->wowlan_sram =
  382. kzalloc(nic->fw.ucode_wowlan.data.len,
  383. GFP_KERNEL);
  384. if (priv->wowlan_sram)
  385. _iwl_read_targ_mem_words(
  386. trans(priv), 0x800000,
  387. priv->wowlan_sram,
  388. nic->fw.ucode_wowlan.data.len / 4);
  389. }
  390. #endif
  391. }
  392. /* we'll clear ctx->vif during iwlagn_prepare_restart() */
  393. vif = ctx->vif;
  394. priv->shrd->wowlan = false;
  395. device_set_wakeup_enable(trans(priv)->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->shrd->mutex);
  401. IWL_DEBUG_MAC80211(priv, "leave\n");
  402. ieee80211_resume_disconnect(vif);
  403. return 1;
  404. }
  405. #endif
  406. static 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. static 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. static 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->shrd->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->shrd->mutex);
  508. IWL_DEBUG_MAC80211(priv, "leave\n");
  509. return ret;
  510. }
  511. static 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 (!(cfg(priv)->sku & EEPROM_SKU_CAP_11N_ENABLE))
  523. return -EACCES;
  524. IWL_DEBUG_MAC80211(priv, "enter\n");
  525. mutex_lock(&priv->shrd->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. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  537. ret = 0;
  538. break;
  539. case IEEE80211_AMPDU_TX_START:
  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 (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  554. ret = 0;
  555. if (!priv->agg_tids_count && cfg(priv)->ht_params &&
  556. cfg(priv)->ht_params->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->shrd->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 = 0;
  583. u8 sta_id;
  584. IWL_DEBUG_MAC80211(priv, "received request to add station %pM\n",
  585. sta->addr);
  586. mutex_lock(&priv->shrd->mutex);
  587. IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
  588. sta->addr);
  589. sta_priv->sta_id = IWL_INVALID_STATION;
  590. atomic_set(&sta_priv->pending_frames, 0);
  591. if (vif->type == NL80211_IFTYPE_AP)
  592. sta_priv->client = true;
  593. ret = iwl_add_station_common(priv, vif_priv->ctx, sta->addr,
  594. is_ap, sta, &sta_id);
  595. if (ret) {
  596. IWL_ERR(priv, "Unable to add station %pM (%d)\n",
  597. sta->addr, ret);
  598. /* Should we return success if return code is EEXIST ? */
  599. goto out;
  600. }
  601. sta_priv->sta_id = sta_id;
  602. /* Initialize rate scaling */
  603. IWL_DEBUG_INFO(priv, "Initializing rate scaling for station %pM\n",
  604. sta->addr);
  605. iwl_rs_rate_init(priv, sta, sta_id);
  606. out:
  607. mutex_unlock(&priv->shrd->mutex);
  608. IWL_DEBUG_MAC80211(priv, "leave\n");
  609. return ret;
  610. }
  611. static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
  612. struct ieee80211_channel_switch *ch_switch)
  613. {
  614. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  615. const struct iwl_channel_info *ch_info;
  616. struct ieee80211_conf *conf = &hw->conf;
  617. struct ieee80211_channel *channel = ch_switch->channel;
  618. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  619. /*
  620. * MULTI-FIXME
  621. * When we add support for multiple interfaces, we need to
  622. * revisit this. The channel switch command in the device
  623. * only affects the BSS context, but what does that really
  624. * mean? And what if we get a CSA on the second interface?
  625. * This needs a lot of work.
  626. */
  627. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  628. u16 ch;
  629. IWL_DEBUG_MAC80211(priv, "enter\n");
  630. mutex_lock(&priv->shrd->mutex);
  631. if (iwl_is_rfkill(priv->shrd))
  632. goto out;
  633. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status) ||
  634. test_bit(STATUS_SCANNING, &priv->shrd->status) ||
  635. test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->shrd->status))
  636. goto out;
  637. if (!iwl_is_associated_ctx(ctx))
  638. goto out;
  639. if (!cfg(priv)->lib->set_channel_switch)
  640. goto out;
  641. ch = channel->hw_value;
  642. if (le16_to_cpu(ctx->active.channel) == ch)
  643. goto out;
  644. ch_info = iwl_get_channel_info(priv, channel->band, ch);
  645. if (!is_channel_valid(ch_info)) {
  646. IWL_DEBUG_MAC80211(priv, "invalid channel\n");
  647. goto out;
  648. }
  649. spin_lock_irq(&priv->shrd->lock);
  650. priv->current_ht_config.smps = conf->smps_mode;
  651. /* Configure HT40 channels */
  652. ctx->ht.enabled = conf_is_ht(conf);
  653. if (ctx->ht.enabled)
  654. iwlagn_config_ht40(conf, ctx);
  655. else
  656. ctx->ht.is_40mhz = false;
  657. if ((le16_to_cpu(ctx->staging.channel) != ch))
  658. ctx->staging.flags = 0;
  659. iwl_set_rxon_channel(priv, channel, ctx);
  660. iwl_set_rxon_ht(priv, ht_conf);
  661. iwl_set_flags_for_band(priv, ctx, channel->band, ctx->vif);
  662. spin_unlock_irq(&priv->shrd->lock);
  663. iwl_set_rate(priv);
  664. /*
  665. * at this point, staging_rxon has the
  666. * configuration for channel switch
  667. */
  668. set_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->shrd->status);
  669. priv->switch_channel = cpu_to_le16(ch);
  670. if (cfg(priv)->lib->set_channel_switch(priv, ch_switch)) {
  671. clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->shrd->status);
  672. priv->switch_channel = 0;
  673. ieee80211_chswitch_done(ctx->vif, false);
  674. }
  675. out:
  676. mutex_unlock(&priv->shrd->mutex);
  677. IWL_DEBUG_MAC80211(priv, "leave\n");
  678. }
  679. static void iwlagn_configure_filter(struct ieee80211_hw *hw,
  680. unsigned int changed_flags,
  681. unsigned int *total_flags,
  682. u64 multicast)
  683. {
  684. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  685. __le32 filter_or = 0, filter_nand = 0;
  686. struct iwl_rxon_context *ctx;
  687. #define CHK(test, flag) do { \
  688. if (*total_flags & (test)) \
  689. filter_or |= (flag); \
  690. else \
  691. filter_nand |= (flag); \
  692. } while (0)
  693. IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
  694. changed_flags, *total_flags);
  695. CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
  696. /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */
  697. CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK);
  698. CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
  699. #undef CHK
  700. mutex_lock(&priv->shrd->mutex);
  701. for_each_context(priv, ctx) {
  702. ctx->staging.filter_flags &= ~filter_nand;
  703. ctx->staging.filter_flags |= filter_or;
  704. /*
  705. * Not committing directly because hardware can perform a scan,
  706. * but we'll eventually commit the filter flags change anyway.
  707. */
  708. }
  709. mutex_unlock(&priv->shrd->mutex);
  710. /*
  711. * Receiving all multicast frames is always enabled by the
  712. * default flags setup in iwl_connection_init_rx_config()
  713. * since we currently do not support programming multicast
  714. * filters into the device.
  715. */
  716. *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
  717. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
  718. }
  719. static void iwlagn_mac_flush(struct ieee80211_hw *hw, bool drop)
  720. {
  721. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  722. mutex_lock(&priv->shrd->mutex);
  723. IWL_DEBUG_MAC80211(priv, "enter\n");
  724. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status)) {
  725. IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n");
  726. goto done;
  727. }
  728. if (iwl_is_rfkill(priv->shrd)) {
  729. IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n");
  730. goto done;
  731. }
  732. /*
  733. * mac80211 will not push any more frames for transmit
  734. * until the flush is completed
  735. */
  736. if (drop) {
  737. IWL_DEBUG_MAC80211(priv, "send flush command\n");
  738. if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) {
  739. IWL_ERR(priv, "flush request fail\n");
  740. goto done;
  741. }
  742. }
  743. IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n");
  744. iwl_trans_wait_tx_queue_empty(trans(priv));
  745. done:
  746. mutex_unlock(&priv->shrd->mutex);
  747. IWL_DEBUG_MAC80211(priv, "leave\n");
  748. }
  749. static int iwlagn_mac_remain_on_channel(struct ieee80211_hw *hw,
  750. struct ieee80211_channel *channel,
  751. enum nl80211_channel_type channel_type,
  752. int duration)
  753. {
  754. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  755. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
  756. int err = 0;
  757. if (!(priv->shrd->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
  758. return -EOPNOTSUPP;
  759. if (!(ctx->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)))
  760. return -EOPNOTSUPP;
  761. IWL_DEBUG_MAC80211(priv, "enter\n");
  762. mutex_lock(&priv->shrd->mutex);
  763. if (test_bit(STATUS_SCAN_HW, &priv->shrd->status)) {
  764. err = -EBUSY;
  765. goto out;
  766. }
  767. priv->hw_roc_channel = channel;
  768. priv->hw_roc_chantype = channel_type;
  769. /* convert from ms to TU */
  770. priv->hw_roc_duration = DIV_ROUND_UP(1000 * duration, 1024);
  771. priv->hw_roc_start_notified = false;
  772. cancel_delayed_work(&priv->hw_roc_disable_work);
  773. if (!ctx->is_active) {
  774. static const struct iwl_qos_info default_qos_data = {
  775. .def_qos_parm = {
  776. .ac[0] = {
  777. .cw_min = cpu_to_le16(3),
  778. .cw_max = cpu_to_le16(7),
  779. .aifsn = 2,
  780. .edca_txop = cpu_to_le16(1504),
  781. },
  782. .ac[1] = {
  783. .cw_min = cpu_to_le16(7),
  784. .cw_max = cpu_to_le16(15),
  785. .aifsn = 2,
  786. .edca_txop = cpu_to_le16(3008),
  787. },
  788. .ac[2] = {
  789. .cw_min = cpu_to_le16(15),
  790. .cw_max = cpu_to_le16(1023),
  791. .aifsn = 3,
  792. },
  793. .ac[3] = {
  794. .cw_min = cpu_to_le16(15),
  795. .cw_max = cpu_to_le16(1023),
  796. .aifsn = 7,
  797. },
  798. },
  799. };
  800. ctx->is_active = true;
  801. ctx->qos_data = default_qos_data;
  802. ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
  803. memcpy(ctx->staging.node_addr,
  804. priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr,
  805. ETH_ALEN);
  806. memcpy(ctx->staging.bssid_addr,
  807. priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr,
  808. ETH_ALEN);
  809. err = iwlagn_commit_rxon(priv, ctx);
  810. if (err)
  811. goto out;
  812. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK |
  813. RXON_FILTER_PROMISC_MSK |
  814. RXON_FILTER_CTL2HOST_MSK;
  815. err = iwlagn_commit_rxon(priv, ctx);
  816. if (err) {
  817. iwlagn_disable_roc(priv);
  818. goto out;
  819. }
  820. priv->hw_roc_setup = true;
  821. }
  822. err = iwl_scan_initiate(priv, ctx->vif, IWL_SCAN_ROC, channel->band);
  823. if (err)
  824. iwlagn_disable_roc(priv);
  825. out:
  826. mutex_unlock(&priv->shrd->mutex);
  827. IWL_DEBUG_MAC80211(priv, "leave\n");
  828. return err;
  829. }
  830. static int iwlagn_mac_cancel_remain_on_channel(struct ieee80211_hw *hw)
  831. {
  832. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  833. if (!(priv->shrd->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
  834. return -EOPNOTSUPP;
  835. IWL_DEBUG_MAC80211(priv, "enter\n");
  836. mutex_lock(&priv->shrd->mutex);
  837. iwl_scan_cancel_timeout(priv, priv->hw_roc_duration);
  838. iwlagn_disable_roc(priv);
  839. mutex_unlock(&priv->shrd->mutex);
  840. IWL_DEBUG_MAC80211(priv, "leave\n");
  841. return 0;
  842. }
  843. static int iwlagn_mac_tx_sync(struct ieee80211_hw *hw,
  844. struct ieee80211_vif *vif,
  845. const u8 *bssid,
  846. enum ieee80211_tx_sync_type type)
  847. {
  848. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  849. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  850. struct iwl_rxon_context *ctx = vif_priv->ctx;
  851. int ret;
  852. u8 sta_id;
  853. if (ctx->ctxid != IWL_RXON_CTX_PAN)
  854. return 0;
  855. IWL_DEBUG_MAC80211(priv, "enter\n");
  856. mutex_lock(&priv->shrd->mutex);
  857. if (iwl_is_associated_ctx(ctx)) {
  858. ret = 0;
  859. goto out;
  860. }
  861. if (ctx->preauth_bssid || test_bit(STATUS_SCAN_HW,
  862. &priv->shrd->status)) {
  863. ret = -EBUSY;
  864. goto out;
  865. }
  866. ret = iwl_add_station_common(priv, ctx, bssid, true, NULL, &sta_id);
  867. if (ret)
  868. goto out;
  869. if (WARN_ON(sta_id != ctx->ap_sta_id)) {
  870. ret = -EIO;
  871. goto out_remove_sta;
  872. }
  873. memcpy(ctx->bssid, bssid, ETH_ALEN);
  874. ctx->preauth_bssid = true;
  875. ret = iwlagn_commit_rxon(priv, ctx);
  876. if (ret == 0)
  877. goto out;
  878. out_remove_sta:
  879. iwl_remove_station(priv, sta_id, bssid);
  880. out:
  881. mutex_unlock(&priv->shrd->mutex);
  882. IWL_DEBUG_MAC80211(priv, "leave\n");
  883. return ret;
  884. }
  885. static void iwlagn_mac_finish_tx_sync(struct ieee80211_hw *hw,
  886. struct ieee80211_vif *vif,
  887. const u8 *bssid,
  888. enum ieee80211_tx_sync_type type)
  889. {
  890. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  891. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  892. struct iwl_rxon_context *ctx = vif_priv->ctx;
  893. if (ctx->ctxid != IWL_RXON_CTX_PAN)
  894. return;
  895. IWL_DEBUG_MAC80211(priv, "enter\n");
  896. mutex_lock(&priv->shrd->mutex);
  897. if (iwl_is_associated_ctx(ctx))
  898. goto out;
  899. iwl_remove_station(priv, ctx->ap_sta_id, bssid);
  900. ctx->preauth_bssid = false;
  901. /* no need to commit */
  902. out:
  903. mutex_unlock(&priv->shrd->mutex);
  904. IWL_DEBUG_MAC80211(priv, "leave\n");
  905. }
  906. static void iwlagn_mac_rssi_callback(struct ieee80211_hw *hw,
  907. enum ieee80211_rssi_event rssi_event)
  908. {
  909. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  910. IWL_DEBUG_MAC80211(priv, "enter\n");
  911. mutex_lock(&priv->shrd->mutex);
  912. if (cfg(priv)->bt_params &&
  913. cfg(priv)->bt_params->advanced_bt_coexist) {
  914. if (rssi_event == RSSI_EVENT_LOW)
  915. priv->bt_enable_pspoll = true;
  916. else if (rssi_event == RSSI_EVENT_HIGH)
  917. priv->bt_enable_pspoll = false;
  918. iwlagn_send_advance_bt_config(priv);
  919. } else {
  920. IWL_DEBUG_MAC80211(priv, "Advanced BT coex disabled,"
  921. "ignoring RSSI callback\n");
  922. }
  923. mutex_unlock(&priv->shrd->mutex);
  924. IWL_DEBUG_MAC80211(priv, "leave\n");
  925. }
  926. static int iwlagn_mac_set_tim(struct ieee80211_hw *hw,
  927. struct ieee80211_sta *sta, bool set)
  928. {
  929. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  930. queue_work(priv->workqueue, &priv->beacon_update);
  931. return 0;
  932. }
  933. static int iwlagn_mac_conf_tx(struct ieee80211_hw *hw,
  934. struct ieee80211_vif *vif, u16 queue,
  935. const struct ieee80211_tx_queue_params *params)
  936. {
  937. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  938. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  939. struct iwl_rxon_context *ctx = vif_priv->ctx;
  940. unsigned long flags;
  941. int q;
  942. if (WARN_ON(!ctx))
  943. return -EINVAL;
  944. IWL_DEBUG_MAC80211(priv, "enter\n");
  945. if (!iwl_is_ready_rf(priv->shrd)) {
  946. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  947. return -EIO;
  948. }
  949. if (queue >= AC_NUM) {
  950. IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
  951. return 0;
  952. }
  953. q = AC_NUM - 1 - queue;
  954. spin_lock_irqsave(&priv->shrd->lock, flags);
  955. ctx->qos_data.def_qos_parm.ac[q].cw_min =
  956. cpu_to_le16(params->cw_min);
  957. ctx->qos_data.def_qos_parm.ac[q].cw_max =
  958. cpu_to_le16(params->cw_max);
  959. ctx->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
  960. ctx->qos_data.def_qos_parm.ac[q].edca_txop =
  961. cpu_to_le16((params->txop * 32));
  962. ctx->qos_data.def_qos_parm.ac[q].reserved1 = 0;
  963. spin_unlock_irqrestore(&priv->shrd->lock, flags);
  964. IWL_DEBUG_MAC80211(priv, "leave\n");
  965. return 0;
  966. }
  967. static int iwlagn_mac_tx_last_beacon(struct ieee80211_hw *hw)
  968. {
  969. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  970. return priv->ibss_manager == IWL_IBSS_MANAGER;
  971. }
  972. static int iwl_set_mode(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  973. {
  974. iwl_connection_init_rx_config(priv, ctx);
  975. iwlagn_set_rxon_chain(priv, ctx);
  976. return iwlagn_commit_rxon(priv, ctx);
  977. }
  978. static int iwl_setup_interface(struct iwl_priv *priv,
  979. struct iwl_rxon_context *ctx)
  980. {
  981. struct ieee80211_vif *vif = ctx->vif;
  982. int err;
  983. lockdep_assert_held(&priv->shrd->mutex);
  984. /*
  985. * This variable will be correct only when there's just
  986. * a single context, but all code using it is for hardware
  987. * that supports only one context.
  988. */
  989. priv->iw_mode = vif->type;
  990. ctx->is_active = true;
  991. err = iwl_set_mode(priv, ctx);
  992. if (err) {
  993. if (!ctx->always_active)
  994. ctx->is_active = false;
  995. return err;
  996. }
  997. if (cfg(priv)->bt_params && cfg(priv)->bt_params->advanced_bt_coexist &&
  998. vif->type == NL80211_IFTYPE_ADHOC) {
  999. /*
  1000. * pretend to have high BT traffic as long as we
  1001. * are operating in IBSS mode, as this will cause
  1002. * the rate scaling etc. to behave as intended.
  1003. */
  1004. priv->bt_traffic_load = IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
  1005. }
  1006. return 0;
  1007. }
  1008. static int iwlagn_mac_add_interface(struct ieee80211_hw *hw,
  1009. struct ieee80211_vif *vif)
  1010. {
  1011. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1012. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  1013. struct iwl_rxon_context *tmp, *ctx = NULL;
  1014. int err;
  1015. enum nl80211_iftype viftype = ieee80211_vif_type_p2p(vif);
  1016. IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n",
  1017. viftype, vif->addr);
  1018. cancel_delayed_work_sync(&priv->hw_roc_disable_work);
  1019. mutex_lock(&priv->shrd->mutex);
  1020. iwlagn_disable_roc(priv);
  1021. if (!iwl_is_ready_rf(priv->shrd)) {
  1022. IWL_WARN(priv, "Try to add interface when device not ready\n");
  1023. err = -EINVAL;
  1024. goto out;
  1025. }
  1026. for_each_context(priv, tmp) {
  1027. u32 possible_modes =
  1028. tmp->interface_modes | tmp->exclusive_interface_modes;
  1029. if (tmp->vif) {
  1030. /* check if this busy context is exclusive */
  1031. if (tmp->exclusive_interface_modes &
  1032. BIT(tmp->vif->type)) {
  1033. err = -EINVAL;
  1034. goto out;
  1035. }
  1036. continue;
  1037. }
  1038. if (!(possible_modes & BIT(viftype)))
  1039. continue;
  1040. /* have maybe usable context w/o interface */
  1041. ctx = tmp;
  1042. break;
  1043. }
  1044. if (!ctx) {
  1045. err = -EOPNOTSUPP;
  1046. goto out;
  1047. }
  1048. vif_priv->ctx = ctx;
  1049. ctx->vif = vif;
  1050. err = iwl_setup_interface(priv, ctx);
  1051. if (!err)
  1052. goto out;
  1053. ctx->vif = NULL;
  1054. priv->iw_mode = NL80211_IFTYPE_STATION;
  1055. out:
  1056. mutex_unlock(&priv->shrd->mutex);
  1057. IWL_DEBUG_MAC80211(priv, "leave\n");
  1058. return err;
  1059. }
  1060. static void iwl_teardown_interface(struct iwl_priv *priv,
  1061. struct ieee80211_vif *vif,
  1062. bool mode_change)
  1063. {
  1064. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1065. lockdep_assert_held(&priv->shrd->mutex);
  1066. if (priv->scan_vif == vif) {
  1067. iwl_scan_cancel_timeout(priv, 200);
  1068. iwl_force_scan_end(priv);
  1069. }
  1070. if (!mode_change) {
  1071. iwl_set_mode(priv, ctx);
  1072. if (!ctx->always_active)
  1073. ctx->is_active = false;
  1074. }
  1075. /*
  1076. * When removing the IBSS interface, overwrite the
  1077. * BT traffic load with the stored one from the last
  1078. * notification, if any. If this is a device that
  1079. * doesn't implement this, this has no effect since
  1080. * both values are the same and zero.
  1081. */
  1082. if (vif->type == NL80211_IFTYPE_ADHOC)
  1083. priv->bt_traffic_load = priv->last_bt_traffic_load;
  1084. }
  1085. static void iwlagn_mac_remove_interface(struct ieee80211_hw *hw,
  1086. struct ieee80211_vif *vif)
  1087. {
  1088. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1089. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1090. IWL_DEBUG_MAC80211(priv, "enter\n");
  1091. mutex_lock(&priv->shrd->mutex);
  1092. if (WARN_ON(ctx->vif != vif)) {
  1093. struct iwl_rxon_context *tmp;
  1094. IWL_ERR(priv, "ctx->vif = %p, vif = %p\n", ctx->vif, vif);
  1095. for_each_context(priv, tmp)
  1096. IWL_ERR(priv, "\tID = %d:\tctx = %p\tctx->vif = %p\n",
  1097. tmp->ctxid, tmp, tmp->vif);
  1098. }
  1099. ctx->vif = NULL;
  1100. iwl_teardown_interface(priv, vif, false);
  1101. mutex_unlock(&priv->shrd->mutex);
  1102. IWL_DEBUG_MAC80211(priv, "leave\n");
  1103. }
  1104. static int iwlagn_mac_change_interface(struct ieee80211_hw *hw,
  1105. struct ieee80211_vif *vif,
  1106. enum nl80211_iftype newtype, bool newp2p)
  1107. {
  1108. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1109. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1110. struct iwl_rxon_context *bss_ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  1111. struct iwl_rxon_context *tmp;
  1112. enum nl80211_iftype newviftype = newtype;
  1113. u32 interface_modes;
  1114. int err;
  1115. IWL_DEBUG_MAC80211(priv, "enter\n");
  1116. newtype = ieee80211_iftype_p2p(newtype, newp2p);
  1117. mutex_lock(&priv->shrd->mutex);
  1118. if (!ctx->vif || !iwl_is_ready_rf(priv->shrd)) {
  1119. /*
  1120. * Huh? But wait ... this can maybe happen when
  1121. * we're in the middle of a firmware restart!
  1122. */
  1123. err = -EBUSY;
  1124. goto out;
  1125. }
  1126. interface_modes = ctx->interface_modes | ctx->exclusive_interface_modes;
  1127. if (!(interface_modes & BIT(newtype))) {
  1128. err = -EBUSY;
  1129. goto out;
  1130. }
  1131. /*
  1132. * Refuse a change that should be done by moving from the PAN
  1133. * context to the BSS context instead, if the BSS context is
  1134. * available and can support the new interface type.
  1135. */
  1136. if (ctx->ctxid == IWL_RXON_CTX_PAN && !bss_ctx->vif &&
  1137. (bss_ctx->interface_modes & BIT(newtype) ||
  1138. bss_ctx->exclusive_interface_modes & BIT(newtype))) {
  1139. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  1140. err = -EBUSY;
  1141. goto out;
  1142. }
  1143. if (ctx->exclusive_interface_modes & BIT(newtype)) {
  1144. for_each_context(priv, tmp) {
  1145. if (ctx == tmp)
  1146. continue;
  1147. if (!tmp->vif)
  1148. continue;
  1149. /*
  1150. * The current mode switch would be exclusive, but
  1151. * another context is active ... refuse the switch.
  1152. */
  1153. err = -EBUSY;
  1154. goto out;
  1155. }
  1156. }
  1157. /* success */
  1158. iwl_teardown_interface(priv, vif, true);
  1159. vif->type = newviftype;
  1160. vif->p2p = newp2p;
  1161. err = iwl_setup_interface(priv, ctx);
  1162. WARN_ON(err);
  1163. /*
  1164. * We've switched internally, but submitting to the
  1165. * device may have failed for some reason. Mask this
  1166. * error, because otherwise mac80211 will not switch
  1167. * (and set the interface type back) and we'll be
  1168. * out of sync with it.
  1169. */
  1170. err = 0;
  1171. out:
  1172. mutex_unlock(&priv->shrd->mutex);
  1173. IWL_DEBUG_MAC80211(priv, "leave\n");
  1174. return err;
  1175. }
  1176. static int iwlagn_mac_hw_scan(struct ieee80211_hw *hw,
  1177. struct ieee80211_vif *vif,
  1178. struct cfg80211_scan_request *req)
  1179. {
  1180. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1181. int ret;
  1182. IWL_DEBUG_MAC80211(priv, "enter\n");
  1183. if (req->n_channels == 0)
  1184. return -EINVAL;
  1185. mutex_lock(&priv->shrd->mutex);
  1186. /*
  1187. * If an internal scan is in progress, just set
  1188. * up the scan_request as per above.
  1189. */
  1190. if (priv->scan_type != IWL_SCAN_NORMAL) {
  1191. IWL_DEBUG_SCAN(priv,
  1192. "SCAN request during internal scan - defer\n");
  1193. priv->scan_request = req;
  1194. priv->scan_vif = vif;
  1195. ret = 0;
  1196. } else {
  1197. priv->scan_request = req;
  1198. priv->scan_vif = vif;
  1199. /*
  1200. * mac80211 will only ask for one band at a time
  1201. * so using channels[0] here is ok
  1202. */
  1203. ret = iwl_scan_initiate(priv, vif, IWL_SCAN_NORMAL,
  1204. req->channels[0]->band);
  1205. if (ret) {
  1206. priv->scan_request = NULL;
  1207. priv->scan_vif = NULL;
  1208. }
  1209. }
  1210. IWL_DEBUG_MAC80211(priv, "leave\n");
  1211. mutex_unlock(&priv->shrd->mutex);
  1212. return ret;
  1213. }
  1214. static int iwlagn_mac_sta_remove(struct ieee80211_hw *hw,
  1215. struct ieee80211_vif *vif,
  1216. struct ieee80211_sta *sta)
  1217. {
  1218. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1219. struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
  1220. int ret;
  1221. IWL_DEBUG_MAC80211(priv, "enter: received request to remove "
  1222. "station %pM\n", sta->addr);
  1223. mutex_lock(&priv->shrd->mutex);
  1224. IWL_DEBUG_INFO(priv, "proceeding to remove station %pM\n",
  1225. sta->addr);
  1226. ret = iwl_remove_station(priv, sta_priv->sta_id, sta->addr);
  1227. if (ret)
  1228. IWL_DEBUG_QUIET_RFKILL(priv, "Error removing station %pM\n",
  1229. sta->addr);
  1230. mutex_unlock(&priv->shrd->mutex);
  1231. IWL_DEBUG_MAC80211(priv, "leave\n");
  1232. return ret;
  1233. }
  1234. static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
  1235. {
  1236. unsigned long flags;
  1237. spin_lock_irqsave(&priv->shrd->sta_lock, flags);
  1238. priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
  1239. priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
  1240. priv->stations[sta_id].sta.sta.modify_mask = 0;
  1241. priv->stations[sta_id].sta.sleep_tx_count = 0;
  1242. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  1243. iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  1244. spin_unlock_irqrestore(&priv->shrd->sta_lock, flags);
  1245. }
  1246. static void iwlagn_mac_sta_notify(struct ieee80211_hw *hw,
  1247. struct ieee80211_vif *vif,
  1248. enum sta_notify_cmd cmd,
  1249. struct ieee80211_sta *sta)
  1250. {
  1251. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1252. struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
  1253. int sta_id;
  1254. IWL_DEBUG_MAC80211(priv, "enter\n");
  1255. switch (cmd) {
  1256. case STA_NOTIFY_SLEEP:
  1257. WARN_ON(!sta_priv->client);
  1258. sta_priv->asleep = true;
  1259. if (atomic_read(&sta_priv->pending_frames) > 0)
  1260. ieee80211_sta_block_awake(hw, sta, true);
  1261. break;
  1262. case STA_NOTIFY_AWAKE:
  1263. WARN_ON(!sta_priv->client);
  1264. if (!sta_priv->asleep)
  1265. break;
  1266. sta_priv->asleep = false;
  1267. sta_id = iwl_sta_id(sta);
  1268. if (sta_id != IWL_INVALID_STATION)
  1269. iwl_sta_modify_ps_wake(priv, sta_id);
  1270. break;
  1271. default:
  1272. break;
  1273. }
  1274. IWL_DEBUG_MAC80211(priv, "leave\n");
  1275. }
  1276. struct ieee80211_ops iwlagn_hw_ops = {
  1277. .tx = iwlagn_mac_tx,
  1278. .start = iwlagn_mac_start,
  1279. .stop = iwlagn_mac_stop,
  1280. #ifdef CONFIG_PM_SLEEP
  1281. .suspend = iwlagn_mac_suspend,
  1282. .resume = iwlagn_mac_resume,
  1283. #endif
  1284. .add_interface = iwlagn_mac_add_interface,
  1285. .remove_interface = iwlagn_mac_remove_interface,
  1286. .change_interface = iwlagn_mac_change_interface,
  1287. .config = iwlagn_mac_config,
  1288. .configure_filter = iwlagn_configure_filter,
  1289. .set_key = iwlagn_mac_set_key,
  1290. .update_tkip_key = iwlagn_mac_update_tkip_key,
  1291. .set_rekey_data = iwlagn_mac_set_rekey_data,
  1292. .conf_tx = iwlagn_mac_conf_tx,
  1293. .bss_info_changed = iwlagn_bss_info_changed,
  1294. .ampdu_action = iwlagn_mac_ampdu_action,
  1295. .hw_scan = iwlagn_mac_hw_scan,
  1296. .sta_notify = iwlagn_mac_sta_notify,
  1297. .sta_add = iwlagn_mac_sta_add,
  1298. .sta_remove = iwlagn_mac_sta_remove,
  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. .tx_sync = iwlagn_mac_tx_sync,
  1308. .finish_tx_sync = iwlagn_mac_finish_tx_sync,
  1309. .set_tim = iwlagn_mac_set_tim,
  1310. };
  1311. /* This function both allocates and initializes hw and priv. */
  1312. struct ieee80211_hw *iwl_alloc_all(void)
  1313. {
  1314. struct iwl_priv *priv;
  1315. struct iwl_op_mode *op_mode;
  1316. /* mac80211 allocates memory for this device instance, including
  1317. * space for this driver's private structure */
  1318. struct ieee80211_hw *hw;
  1319. hw = ieee80211_alloc_hw(sizeof(struct iwl_priv) +
  1320. sizeof(struct iwl_op_mode), &iwlagn_hw_ops);
  1321. if (!hw)
  1322. goto out;
  1323. op_mode = hw->priv;
  1324. priv = IWL_OP_MODE_GET_DVM(op_mode);
  1325. priv->hw = hw;
  1326. out:
  1327. return hw;
  1328. }