iwl-mac80211.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570
  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-trans.h"
  52. #include "iwl-op-mode.h"
  53. /*****************************************************************************
  54. *
  55. * mac80211 entry point functions
  56. *
  57. *****************************************************************************/
  58. static const struct ieee80211_iface_limit iwlagn_sta_ap_limits[] = {
  59. {
  60. .max = 1,
  61. .types = BIT(NL80211_IFTYPE_STATION),
  62. },
  63. {
  64. .max = 1,
  65. .types = BIT(NL80211_IFTYPE_AP),
  66. },
  67. };
  68. static const struct ieee80211_iface_limit iwlagn_2sta_limits[] = {
  69. {
  70. .max = 2,
  71. .types = BIT(NL80211_IFTYPE_STATION),
  72. },
  73. };
  74. static const struct ieee80211_iface_limit iwlagn_p2p_sta_go_limits[] = {
  75. {
  76. .max = 1,
  77. .types = BIT(NL80211_IFTYPE_STATION),
  78. },
  79. {
  80. .max = 1,
  81. .types = BIT(NL80211_IFTYPE_P2P_GO) |
  82. BIT(NL80211_IFTYPE_AP),
  83. },
  84. };
  85. static const struct ieee80211_iface_limit iwlagn_p2p_2sta_limits[] = {
  86. {
  87. .max = 2,
  88. .types = BIT(NL80211_IFTYPE_STATION),
  89. },
  90. {
  91. .max = 1,
  92. .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
  93. },
  94. };
  95. static const struct ieee80211_iface_combination
  96. iwlagn_iface_combinations_dualmode[] = {
  97. { .num_different_channels = 1,
  98. .max_interfaces = 2,
  99. .beacon_int_infra_match = true,
  100. .limits = iwlagn_sta_ap_limits,
  101. .n_limits = ARRAY_SIZE(iwlagn_sta_ap_limits),
  102. },
  103. { .num_different_channels = 1,
  104. .max_interfaces = 2,
  105. .limits = iwlagn_2sta_limits,
  106. .n_limits = ARRAY_SIZE(iwlagn_2sta_limits),
  107. },
  108. };
  109. static const struct ieee80211_iface_combination
  110. iwlagn_iface_combinations_p2p[] = {
  111. { .num_different_channels = 1,
  112. .max_interfaces = 2,
  113. .beacon_int_infra_match = true,
  114. .limits = iwlagn_p2p_sta_go_limits,
  115. .n_limits = ARRAY_SIZE(iwlagn_p2p_sta_go_limits),
  116. },
  117. { .num_different_channels = 1,
  118. .max_interfaces = 2,
  119. .limits = iwlagn_p2p_2sta_limits,
  120. .n_limits = ARRAY_SIZE(iwlagn_p2p_2sta_limits),
  121. },
  122. };
  123. /*
  124. * Not a mac80211 entry point function, but it fits in with all the
  125. * other mac80211 functions grouped here.
  126. */
  127. int iwlagn_mac_setup_register(struct iwl_priv *priv,
  128. struct iwl_ucode_capabilities *capa)
  129. {
  130. int ret;
  131. struct ieee80211_hw *hw = priv->hw;
  132. struct iwl_rxon_context *ctx;
  133. hw->rate_control_algorithm = "iwl-agn-rs";
  134. /* Tell mac80211 our characteristics */
  135. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  136. IEEE80211_HW_AMPDU_AGGREGATION |
  137. IEEE80211_HW_NEED_DTIM_PERIOD |
  138. IEEE80211_HW_SPECTRUM_MGMT |
  139. IEEE80211_HW_REPORTS_TX_ACK_STATUS;
  140. /*
  141. * Including the following line will crash some AP's. This
  142. * workaround removes the stimulus which causes the crash until
  143. * the AP software can be fixed.
  144. hw->max_tx_aggregation_subframes = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
  145. */
  146. hw->flags |= IEEE80211_HW_SUPPORTS_PS |
  147. IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
  148. if (hw_params(priv).sku & EEPROM_SKU_CAP_11N_ENABLE)
  149. hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
  150. IEEE80211_HW_SUPPORTS_STATIC_SMPS;
  151. if (capa->flags & IWL_UCODE_TLV_FLAGS_MFP)
  152. hw->flags |= IEEE80211_HW_MFP_CAPABLE;
  153. hw->sta_data_size = sizeof(struct iwl_station_priv);
  154. hw->vif_data_size = sizeof(struct iwl_vif_priv);
  155. for_each_context(priv, ctx) {
  156. hw->wiphy->interface_modes |= ctx->interface_modes;
  157. hw->wiphy->interface_modes |= ctx->exclusive_interface_modes;
  158. }
  159. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  160. if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)) {
  161. hw->wiphy->iface_combinations = iwlagn_iface_combinations_p2p;
  162. hw->wiphy->n_iface_combinations =
  163. ARRAY_SIZE(iwlagn_iface_combinations_p2p);
  164. } else if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) {
  165. hw->wiphy->iface_combinations =
  166. iwlagn_iface_combinations_dualmode;
  167. hw->wiphy->n_iface_combinations =
  168. ARRAY_SIZE(iwlagn_iface_combinations_dualmode);
  169. }
  170. hw->wiphy->max_remain_on_channel_duration = 1000;
  171. hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
  172. WIPHY_FLAG_DISABLE_BEACON_HINTS |
  173. WIPHY_FLAG_IBSS_RSN;
  174. if (nic(priv)->fw.ucode_wowlan.code.len &&
  175. device_can_wakeup(trans(priv)->dev)) {
  176. hw->wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
  177. WIPHY_WOWLAN_DISCONNECT |
  178. WIPHY_WOWLAN_EAP_IDENTITY_REQ |
  179. WIPHY_WOWLAN_RFKILL_RELEASE;
  180. if (!iwlagn_mod_params.sw_crypto)
  181. hw->wiphy->wowlan.flags |=
  182. WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
  183. WIPHY_WOWLAN_GTK_REKEY_FAILURE;
  184. hw->wiphy->wowlan.n_patterns = IWLAGN_WOWLAN_MAX_PATTERNS;
  185. hw->wiphy->wowlan.pattern_min_len =
  186. IWLAGN_WOWLAN_MIN_PATTERN_LEN;
  187. hw->wiphy->wowlan.pattern_max_len =
  188. IWLAGN_WOWLAN_MAX_PATTERN_LEN;
  189. }
  190. if (iwlagn_mod_params.power_save)
  191. hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
  192. else
  193. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  194. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
  195. /* we create the 802.11 header and a zero-length SSID element */
  196. hw->wiphy->max_scan_ie_len = capa->max_probe_length - 24 - 2;
  197. /* Default value; 4 EDCA QOS priorities */
  198. hw->queues = 4;
  199. hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
  200. if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
  201. priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  202. &priv->bands[IEEE80211_BAND_2GHZ];
  203. if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
  204. priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  205. &priv->bands[IEEE80211_BAND_5GHZ];
  206. hw->wiphy->hw_version = trans(priv)->hw_id;
  207. iwl_leds_init(priv);
  208. ret = ieee80211_register_hw(priv->hw);
  209. if (ret) {
  210. IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
  211. return ret;
  212. }
  213. priv->mac80211_registered = 1;
  214. return 0;
  215. }
  216. void iwlagn_mac_unregister(struct iwl_priv *priv)
  217. {
  218. if (!priv->mac80211_registered)
  219. return;
  220. iwl_leds_exit(priv);
  221. ieee80211_unregister_hw(priv->hw);
  222. priv->mac80211_registered = 0;
  223. }
  224. static int __iwl_up(struct iwl_priv *priv)
  225. {
  226. struct iwl_rxon_context *ctx;
  227. int ret;
  228. lockdep_assert_held(&priv->shrd->mutex);
  229. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status)) {
  230. IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
  231. return -EIO;
  232. }
  233. for_each_context(priv, ctx) {
  234. ret = iwlagn_alloc_bcast_station(priv, ctx);
  235. if (ret) {
  236. iwl_dealloc_bcast_stations(priv);
  237. return ret;
  238. }
  239. }
  240. ret = iwl_run_init_ucode(trans(priv));
  241. if (ret) {
  242. IWL_ERR(priv, "Failed to run INIT ucode: %d\n", ret);
  243. goto error;
  244. }
  245. ret = iwl_load_ucode_wait_alive(trans(priv), IWL_UCODE_REGULAR);
  246. if (ret) {
  247. IWL_ERR(priv, "Failed to start RT ucode: %d\n", ret);
  248. goto error;
  249. }
  250. ret = iwl_alive_start(priv);
  251. if (ret)
  252. goto error;
  253. return 0;
  254. error:
  255. set_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
  256. iwl_down(priv);
  257. clear_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
  258. IWL_ERR(priv, "Unable to initialize device.\n");
  259. return ret;
  260. }
  261. static int iwlagn_mac_start(struct ieee80211_hw *hw)
  262. {
  263. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  264. int ret;
  265. IWL_DEBUG_MAC80211(priv, "enter\n");
  266. /* we should be verifying the device is ready to be opened */
  267. mutex_lock(&priv->shrd->mutex);
  268. ret = __iwl_up(priv);
  269. mutex_unlock(&priv->shrd->mutex);
  270. if (ret)
  271. return ret;
  272. IWL_DEBUG_INFO(priv, "Start UP work done.\n");
  273. /* Now we should be done, and the READY bit should be set. */
  274. if (WARN_ON(!test_bit(STATUS_READY, &priv->shrd->status)))
  275. ret = -EIO;
  276. iwlagn_led_enable(priv);
  277. priv->is_open = 1;
  278. IWL_DEBUG_MAC80211(priv, "leave\n");
  279. return 0;
  280. }
  281. static void iwlagn_mac_stop(struct ieee80211_hw *hw)
  282. {
  283. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  284. IWL_DEBUG_MAC80211(priv, "enter\n");
  285. if (!priv->is_open)
  286. return;
  287. priv->is_open = 0;
  288. mutex_lock(&priv->shrd->mutex);
  289. iwl_down(priv);
  290. mutex_unlock(&priv->shrd->mutex);
  291. iwl_cancel_deferred_work(priv);
  292. flush_workqueue(priv->workqueue);
  293. /* User space software may expect getting rfkill changes
  294. * even if interface is down, trans->down will leave the RF
  295. * kill interrupt enabled
  296. */
  297. iwl_trans_stop_hw(trans(priv));
  298. IWL_DEBUG_MAC80211(priv, "leave\n");
  299. }
  300. static void iwlagn_mac_set_rekey_data(struct ieee80211_hw *hw,
  301. struct ieee80211_vif *vif,
  302. struct cfg80211_gtk_rekey_data *data)
  303. {
  304. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  305. if (iwlagn_mod_params.sw_crypto)
  306. return;
  307. IWL_DEBUG_MAC80211(priv, "enter\n");
  308. mutex_lock(&priv->shrd->mutex);
  309. if (priv->contexts[IWL_RXON_CTX_BSS].vif != vif)
  310. goto out;
  311. memcpy(priv->kek, data->kek, NL80211_KEK_LEN);
  312. memcpy(priv->kck, data->kck, NL80211_KCK_LEN);
  313. priv->replay_ctr =
  314. cpu_to_le64(be64_to_cpup((__be64 *)&data->replay_ctr));
  315. priv->have_rekey_data = true;
  316. out:
  317. mutex_unlock(&priv->shrd->mutex);
  318. IWL_DEBUG_MAC80211(priv, "leave\n");
  319. }
  320. #ifdef CONFIG_PM_SLEEP
  321. static int iwlagn_mac_suspend(struct ieee80211_hw *hw,
  322. struct cfg80211_wowlan *wowlan)
  323. {
  324. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  325. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  326. int ret;
  327. if (WARN_ON(!wowlan))
  328. return -EINVAL;
  329. IWL_DEBUG_MAC80211(priv, "enter\n");
  330. mutex_lock(&priv->shrd->mutex);
  331. /* Don't attempt WoWLAN when not associated, tear down instead. */
  332. if (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION ||
  333. !iwl_is_associated_ctx(ctx)) {
  334. ret = 1;
  335. goto out;
  336. }
  337. ret = iwlagn_suspend(priv, hw, wowlan);
  338. if (ret)
  339. goto error;
  340. device_set_wakeup_enable(trans(priv)->dev, true);
  341. /* Now let the ucode operate on its own */
  342. iwl_write32(trans(priv), CSR_UCODE_DRV_GP1_SET,
  343. CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE);
  344. goto out;
  345. error:
  346. priv->shrd->wowlan = false;
  347. iwlagn_prepare_restart(priv);
  348. ieee80211_restart_hw(priv->hw);
  349. out:
  350. mutex_unlock(&priv->shrd->mutex);
  351. IWL_DEBUG_MAC80211(priv, "leave\n");
  352. return ret;
  353. }
  354. static int iwlagn_mac_resume(struct ieee80211_hw *hw)
  355. {
  356. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  357. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  358. struct ieee80211_vif *vif;
  359. unsigned long flags;
  360. u32 base, status = 0xffffffff;
  361. int ret = -EIO;
  362. IWL_DEBUG_MAC80211(priv, "enter\n");
  363. mutex_lock(&priv->shrd->mutex);
  364. iwl_write32(trans(priv), CSR_UCODE_DRV_GP1_CLR,
  365. CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE);
  366. base = priv->shrd->device_pointers.error_event_table;
  367. if (iwlagn_hw_valid_rtc_data_addr(base)) {
  368. spin_lock_irqsave(&trans(priv)->reg_lock, flags);
  369. ret = iwl_grab_nic_access_silent(trans(priv));
  370. if (ret == 0) {
  371. iwl_write32(trans(priv), HBUS_TARG_MEM_RADDR, base);
  372. status = iwl_read32(trans(priv), HBUS_TARG_MEM_RDAT);
  373. iwl_release_nic_access(trans(priv));
  374. }
  375. spin_unlock_irqrestore(&trans(priv)->reg_lock, flags);
  376. #ifdef CONFIG_IWLWIFI_DEBUGFS
  377. if (ret == 0) {
  378. struct iwl_nic *nic = nic(priv);
  379. if (!priv->wowlan_sram)
  380. priv->wowlan_sram =
  381. kzalloc(nic->fw.ucode_wowlan.data.len,
  382. GFP_KERNEL);
  383. if (priv->wowlan_sram)
  384. _iwl_read_targ_mem_words(
  385. trans(priv), 0x800000,
  386. priv->wowlan_sram,
  387. nic->fw.ucode_wowlan.data.len / 4);
  388. }
  389. #endif
  390. }
  391. /* we'll clear ctx->vif during iwlagn_prepare_restart() */
  392. vif = ctx->vif;
  393. priv->shrd->wowlan = false;
  394. device_set_wakeup_enable(trans(priv)->dev, false);
  395. iwlagn_prepare_restart(priv);
  396. memset((void *)&ctx->active, 0, sizeof(ctx->active));
  397. iwl_connection_init_rx_config(priv, ctx);
  398. iwlagn_set_rxon_chain(priv, ctx);
  399. mutex_unlock(&priv->shrd->mutex);
  400. IWL_DEBUG_MAC80211(priv, "leave\n");
  401. ieee80211_resume_disconnect(vif);
  402. return 1;
  403. }
  404. #endif
  405. static void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  406. {
  407. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  408. IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  409. ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
  410. if (iwlagn_tx_skb(priv, skb))
  411. dev_kfree_skb_any(skb);
  412. }
  413. static void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw,
  414. struct ieee80211_vif *vif,
  415. struct ieee80211_key_conf *keyconf,
  416. struct ieee80211_sta *sta,
  417. u32 iv32, u16 *phase1key)
  418. {
  419. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  420. iwl_update_tkip_key(priv, vif, keyconf, sta, iv32, phase1key);
  421. }
  422. static int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  423. struct ieee80211_vif *vif,
  424. struct ieee80211_sta *sta,
  425. struct ieee80211_key_conf *key)
  426. {
  427. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  428. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  429. struct iwl_rxon_context *ctx = vif_priv->ctx;
  430. int ret;
  431. bool is_default_wep_key = false;
  432. IWL_DEBUG_MAC80211(priv, "enter\n");
  433. if (iwlagn_mod_params.sw_crypto) {
  434. IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
  435. return -EOPNOTSUPP;
  436. }
  437. switch (key->cipher) {
  438. case WLAN_CIPHER_SUITE_TKIP:
  439. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  440. /* fall through */
  441. case WLAN_CIPHER_SUITE_CCMP:
  442. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  443. break;
  444. default:
  445. break;
  446. }
  447. /*
  448. * We could program these keys into the hardware as well, but we
  449. * don't expect much multicast traffic in IBSS and having keys
  450. * for more stations is probably more useful.
  451. *
  452. * Mark key TX-only and return 0.
  453. */
  454. if (vif->type == NL80211_IFTYPE_ADHOC &&
  455. !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
  456. key->hw_key_idx = WEP_INVALID_OFFSET;
  457. return 0;
  458. }
  459. /* If they key was TX-only, accept deletion */
  460. if (cmd == DISABLE_KEY && key->hw_key_idx == WEP_INVALID_OFFSET)
  461. return 0;
  462. mutex_lock(&priv->shrd->mutex);
  463. iwl_scan_cancel_timeout(priv, 100);
  464. BUILD_BUG_ON(WEP_INVALID_OFFSET == IWLAGN_HW_KEY_DEFAULT);
  465. /*
  466. * If we are getting WEP group key and we didn't receive any key mapping
  467. * so far, we are in legacy wep mode (group key only), otherwise we are
  468. * in 1X mode.
  469. * In legacy wep mode, we use another host command to the uCode.
  470. */
  471. if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  472. key->cipher == WLAN_CIPHER_SUITE_WEP104) && !sta) {
  473. if (cmd == SET_KEY)
  474. is_default_wep_key = !ctx->key_mapping_keys;
  475. else
  476. is_default_wep_key =
  477. key->hw_key_idx == IWLAGN_HW_KEY_DEFAULT;
  478. }
  479. switch (cmd) {
  480. case SET_KEY:
  481. if (is_default_wep_key) {
  482. ret = iwl_set_default_wep_key(priv, vif_priv->ctx, key);
  483. break;
  484. }
  485. ret = iwl_set_dynamic_key(priv, vif_priv->ctx, key, sta);
  486. if (ret) {
  487. /*
  488. * can't add key for RX, but we don't need it
  489. * in the device for TX so still return 0
  490. */
  491. ret = 0;
  492. key->hw_key_idx = WEP_INVALID_OFFSET;
  493. }
  494. IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
  495. break;
  496. case DISABLE_KEY:
  497. if (is_default_wep_key)
  498. ret = iwl_remove_default_wep_key(priv, ctx, key);
  499. else
  500. ret = iwl_remove_dynamic_key(priv, ctx, key, sta);
  501. IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
  502. break;
  503. default:
  504. ret = -EINVAL;
  505. }
  506. mutex_unlock(&priv->shrd->mutex);
  507. IWL_DEBUG_MAC80211(priv, "leave\n");
  508. return ret;
  509. }
  510. static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
  511. struct ieee80211_vif *vif,
  512. enum ieee80211_ampdu_mlme_action action,
  513. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  514. u8 buf_size)
  515. {
  516. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  517. int ret = -EINVAL;
  518. struct iwl_station_priv *sta_priv = (void *) sta->drv_priv;
  519. IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
  520. sta->addr, tid);
  521. if (!(hw_params(priv).sku & EEPROM_SKU_CAP_11N_ENABLE))
  522. return -EACCES;
  523. IWL_DEBUG_MAC80211(priv, "enter\n");
  524. mutex_lock(&priv->shrd->mutex);
  525. switch (action) {
  526. case IEEE80211_AMPDU_RX_START:
  527. if (iwlagn_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
  528. break;
  529. IWL_DEBUG_HT(priv, "start Rx\n");
  530. ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn);
  531. break;
  532. case IEEE80211_AMPDU_RX_STOP:
  533. IWL_DEBUG_HT(priv, "stop Rx\n");
  534. ret = iwl_sta_rx_agg_stop(priv, sta, tid);
  535. break;
  536. case IEEE80211_AMPDU_TX_START:
  537. if (iwlagn_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
  538. break;
  539. IWL_DEBUG_HT(priv, "start Tx\n");
  540. ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn);
  541. break;
  542. case IEEE80211_AMPDU_TX_STOP:
  543. IWL_DEBUG_HT(priv, "stop Tx\n");
  544. ret = iwlagn_tx_agg_stop(priv, vif, sta, tid);
  545. if ((ret == 0) && (priv->agg_tids_count > 0)) {
  546. priv->agg_tids_count--;
  547. IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n",
  548. priv->agg_tids_count);
  549. }
  550. if (!priv->agg_tids_count && cfg(priv)->ht_params &&
  551. cfg(priv)->ht_params->use_rts_for_aggregation) {
  552. /*
  553. * switch off RTS/CTS if it was previously enabled
  554. */
  555. sta_priv->lq_sta.lq.general_params.flags &=
  556. ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
  557. iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
  558. &sta_priv->lq_sta.lq, CMD_ASYNC, false);
  559. }
  560. break;
  561. case IEEE80211_AMPDU_TX_OPERATIONAL:
  562. ret = iwlagn_tx_agg_oper(priv, vif, sta, tid, buf_size);
  563. break;
  564. }
  565. mutex_unlock(&priv->shrd->mutex);
  566. IWL_DEBUG_MAC80211(priv, "leave\n");
  567. return ret;
  568. }
  569. static int iwlagn_mac_sta_add(struct ieee80211_hw *hw,
  570. struct ieee80211_vif *vif,
  571. struct ieee80211_sta *sta)
  572. {
  573. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  574. struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
  575. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  576. bool is_ap = vif->type == NL80211_IFTYPE_STATION;
  577. int ret;
  578. u8 sta_id;
  579. IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
  580. sta->addr);
  581. sta_priv->sta_id = IWL_INVALID_STATION;
  582. atomic_set(&sta_priv->pending_frames, 0);
  583. if (vif->type == NL80211_IFTYPE_AP)
  584. sta_priv->client = true;
  585. ret = iwl_add_station_common(priv, vif_priv->ctx, sta->addr,
  586. is_ap, sta, &sta_id);
  587. if (ret) {
  588. IWL_ERR(priv, "Unable to add station %pM (%d)\n",
  589. sta->addr, ret);
  590. /* Should we return success if return code is EEXIST ? */
  591. return ret;
  592. }
  593. sta_priv->sta_id = sta_id;
  594. return 0;
  595. }
  596. static int iwlagn_mac_sta_remove(struct ieee80211_hw *hw,
  597. struct ieee80211_vif *vif,
  598. struct ieee80211_sta *sta)
  599. {
  600. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  601. struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
  602. int ret;
  603. IWL_DEBUG_INFO(priv, "proceeding to remove station %pM\n",
  604. sta->addr);
  605. ret = iwl_remove_station(priv, sta_priv->sta_id, sta->addr);
  606. if (ret)
  607. IWL_DEBUG_QUIET_RFKILL(priv, "Error removing station %pM\n",
  608. sta->addr);
  609. return ret;
  610. }
  611. static int iwlagn_mac_sta_state(struct ieee80211_hw *hw,
  612. struct ieee80211_vif *vif,
  613. struct ieee80211_sta *sta,
  614. enum ieee80211_sta_state old_state,
  615. enum ieee80211_sta_state new_state)
  616. {
  617. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  618. enum {
  619. NONE, ADD, REMOVE, RATE_INIT, ADD_RATE_INIT,
  620. } op = NONE;
  621. int ret;
  622. IWL_DEBUG_MAC80211(priv, "station %pM state change %d->%d\n",
  623. sta->addr, old_state, new_state);
  624. mutex_lock(&priv->shrd->mutex);
  625. if (vif->type == NL80211_IFTYPE_STATION) {
  626. if (old_state == IEEE80211_STA_NOTEXIST &&
  627. new_state == IEEE80211_STA_NONE)
  628. op = ADD;
  629. else if (old_state == IEEE80211_STA_NONE &&
  630. new_state == IEEE80211_STA_NOTEXIST)
  631. op = REMOVE;
  632. else if (old_state == IEEE80211_STA_AUTH &&
  633. new_state == IEEE80211_STA_ASSOC)
  634. op = RATE_INIT;
  635. } else {
  636. if (old_state == IEEE80211_STA_AUTH &&
  637. new_state == IEEE80211_STA_ASSOC)
  638. op = ADD_RATE_INIT;
  639. else if (old_state == IEEE80211_STA_ASSOC &&
  640. new_state == IEEE80211_STA_AUTH)
  641. op = REMOVE;
  642. }
  643. switch (op) {
  644. case ADD:
  645. ret = iwlagn_mac_sta_add(hw, vif, sta);
  646. break;
  647. case REMOVE:
  648. ret = iwlagn_mac_sta_remove(hw, vif, sta);
  649. break;
  650. case ADD_RATE_INIT:
  651. ret = iwlagn_mac_sta_add(hw, vif, sta);
  652. if (ret)
  653. break;
  654. /* fall through */
  655. case RATE_INIT:
  656. /* Initialize rate scaling */
  657. IWL_DEBUG_INFO(priv,
  658. "Initializing rate scaling for station %pM\n",
  659. sta->addr);
  660. iwl_rs_rate_init(priv, sta, iwl_sta_id(sta));
  661. ret = 0;
  662. break;
  663. default:
  664. ret = 0;
  665. break;
  666. }
  667. /*
  668. * mac80211 might WARN if we fail, but due the way we
  669. * (badly) handle hard rfkill, we might fail here
  670. */
  671. if (iwl_is_rfkill(priv->shrd))
  672. ret = 0;
  673. mutex_unlock(&priv->shrd->mutex);
  674. IWL_DEBUG_MAC80211(priv, "leave\n");
  675. return ret;
  676. }
  677. static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
  678. struct ieee80211_channel_switch *ch_switch)
  679. {
  680. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  681. const struct iwl_channel_info *ch_info;
  682. struct ieee80211_conf *conf = &hw->conf;
  683. struct ieee80211_channel *channel = ch_switch->channel;
  684. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  685. /*
  686. * MULTI-FIXME
  687. * When we add support for multiple interfaces, we need to
  688. * revisit this. The channel switch command in the device
  689. * only affects the BSS context, but what does that really
  690. * mean? And what if we get a CSA on the second interface?
  691. * This needs a lot of work.
  692. */
  693. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  694. u16 ch;
  695. IWL_DEBUG_MAC80211(priv, "enter\n");
  696. mutex_lock(&priv->shrd->mutex);
  697. if (iwl_is_rfkill(priv->shrd))
  698. goto out;
  699. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status) ||
  700. test_bit(STATUS_SCANNING, &priv->shrd->status) ||
  701. test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->shrd->status))
  702. goto out;
  703. if (!iwl_is_associated_ctx(ctx))
  704. goto out;
  705. if (!cfg(priv)->lib->set_channel_switch)
  706. goto out;
  707. ch = channel->hw_value;
  708. if (le16_to_cpu(ctx->active.channel) == ch)
  709. goto out;
  710. ch_info = iwl_get_channel_info(priv, channel->band, ch);
  711. if (!is_channel_valid(ch_info)) {
  712. IWL_DEBUG_MAC80211(priv, "invalid channel\n");
  713. goto out;
  714. }
  715. priv->current_ht_config.smps = conf->smps_mode;
  716. /* Configure HT40 channels */
  717. ctx->ht.enabled = conf_is_ht(conf);
  718. if (ctx->ht.enabled)
  719. iwlagn_config_ht40(conf, ctx);
  720. else
  721. ctx->ht.is_40mhz = false;
  722. if ((le16_to_cpu(ctx->staging.channel) != ch))
  723. ctx->staging.flags = 0;
  724. iwl_set_rxon_channel(priv, channel, ctx);
  725. iwl_set_rxon_ht(priv, ht_conf);
  726. iwl_set_flags_for_band(priv, ctx, channel->band, ctx->vif);
  727. iwl_set_rate(priv);
  728. /*
  729. * at this point, staging_rxon has the
  730. * configuration for channel switch
  731. */
  732. set_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->shrd->status);
  733. priv->switch_channel = cpu_to_le16(ch);
  734. if (cfg(priv)->lib->set_channel_switch(priv, ch_switch)) {
  735. clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->shrd->status);
  736. priv->switch_channel = 0;
  737. ieee80211_chswitch_done(ctx->vif, false);
  738. }
  739. out:
  740. mutex_unlock(&priv->shrd->mutex);
  741. IWL_DEBUG_MAC80211(priv, "leave\n");
  742. }
  743. static void iwlagn_configure_filter(struct ieee80211_hw *hw,
  744. unsigned int changed_flags,
  745. unsigned int *total_flags,
  746. u64 multicast)
  747. {
  748. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  749. __le32 filter_or = 0, filter_nand = 0;
  750. struct iwl_rxon_context *ctx;
  751. #define CHK(test, flag) do { \
  752. if (*total_flags & (test)) \
  753. filter_or |= (flag); \
  754. else \
  755. filter_nand |= (flag); \
  756. } while (0)
  757. IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
  758. changed_flags, *total_flags);
  759. CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
  760. /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */
  761. CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK);
  762. CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
  763. #undef CHK
  764. mutex_lock(&priv->shrd->mutex);
  765. for_each_context(priv, ctx) {
  766. ctx->staging.filter_flags &= ~filter_nand;
  767. ctx->staging.filter_flags |= filter_or;
  768. /*
  769. * Not committing directly because hardware can perform a scan,
  770. * but we'll eventually commit the filter flags change anyway.
  771. */
  772. }
  773. mutex_unlock(&priv->shrd->mutex);
  774. /*
  775. * Receiving all multicast frames is always enabled by the
  776. * default flags setup in iwl_connection_init_rx_config()
  777. * since we currently do not support programming multicast
  778. * filters into the device.
  779. */
  780. *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
  781. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
  782. }
  783. static void iwlagn_mac_flush(struct ieee80211_hw *hw, bool drop)
  784. {
  785. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  786. mutex_lock(&priv->shrd->mutex);
  787. IWL_DEBUG_MAC80211(priv, "enter\n");
  788. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status)) {
  789. IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n");
  790. goto done;
  791. }
  792. if (iwl_is_rfkill(priv->shrd)) {
  793. IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n");
  794. goto done;
  795. }
  796. /*
  797. * mac80211 will not push any more frames for transmit
  798. * until the flush is completed
  799. */
  800. if (drop) {
  801. IWL_DEBUG_MAC80211(priv, "send flush command\n");
  802. if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) {
  803. IWL_ERR(priv, "flush request fail\n");
  804. goto done;
  805. }
  806. }
  807. IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n");
  808. iwl_trans_wait_tx_queue_empty(trans(priv));
  809. done:
  810. mutex_unlock(&priv->shrd->mutex);
  811. IWL_DEBUG_MAC80211(priv, "leave\n");
  812. }
  813. static int iwlagn_mac_remain_on_channel(struct ieee80211_hw *hw,
  814. struct ieee80211_channel *channel,
  815. enum nl80211_channel_type channel_type,
  816. int duration)
  817. {
  818. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  819. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
  820. int err = 0;
  821. if (!(priv->shrd->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
  822. return -EOPNOTSUPP;
  823. if (!(ctx->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)))
  824. return -EOPNOTSUPP;
  825. IWL_DEBUG_MAC80211(priv, "enter\n");
  826. mutex_lock(&priv->shrd->mutex);
  827. if (test_bit(STATUS_SCAN_HW, &priv->shrd->status)) {
  828. err = -EBUSY;
  829. goto out;
  830. }
  831. priv->hw_roc_channel = channel;
  832. priv->hw_roc_chantype = channel_type;
  833. /* convert from ms to TU */
  834. priv->hw_roc_duration = DIV_ROUND_UP(1000 * duration, 1024);
  835. priv->hw_roc_start_notified = false;
  836. cancel_delayed_work(&priv->hw_roc_disable_work);
  837. if (!ctx->is_active) {
  838. static const struct iwl_qos_info default_qos_data = {
  839. .def_qos_parm = {
  840. .ac[0] = {
  841. .cw_min = cpu_to_le16(3),
  842. .cw_max = cpu_to_le16(7),
  843. .aifsn = 2,
  844. .edca_txop = cpu_to_le16(1504),
  845. },
  846. .ac[1] = {
  847. .cw_min = cpu_to_le16(7),
  848. .cw_max = cpu_to_le16(15),
  849. .aifsn = 2,
  850. .edca_txop = cpu_to_le16(3008),
  851. },
  852. .ac[2] = {
  853. .cw_min = cpu_to_le16(15),
  854. .cw_max = cpu_to_le16(1023),
  855. .aifsn = 3,
  856. },
  857. .ac[3] = {
  858. .cw_min = cpu_to_le16(15),
  859. .cw_max = cpu_to_le16(1023),
  860. .aifsn = 7,
  861. },
  862. },
  863. };
  864. ctx->is_active = true;
  865. ctx->qos_data = default_qos_data;
  866. ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
  867. memcpy(ctx->staging.node_addr,
  868. priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr,
  869. ETH_ALEN);
  870. memcpy(ctx->staging.bssid_addr,
  871. priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr,
  872. ETH_ALEN);
  873. err = iwlagn_commit_rxon(priv, ctx);
  874. if (err)
  875. goto out;
  876. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK |
  877. RXON_FILTER_PROMISC_MSK |
  878. RXON_FILTER_CTL2HOST_MSK;
  879. err = iwlagn_commit_rxon(priv, ctx);
  880. if (err) {
  881. iwlagn_disable_roc(priv);
  882. goto out;
  883. }
  884. priv->hw_roc_setup = true;
  885. }
  886. err = iwl_scan_initiate(priv, ctx->vif, IWL_SCAN_ROC, channel->band);
  887. if (err)
  888. iwlagn_disable_roc(priv);
  889. out:
  890. mutex_unlock(&priv->shrd->mutex);
  891. IWL_DEBUG_MAC80211(priv, "leave\n");
  892. return err;
  893. }
  894. static int iwlagn_mac_cancel_remain_on_channel(struct ieee80211_hw *hw)
  895. {
  896. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  897. if (!(priv->shrd->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
  898. return -EOPNOTSUPP;
  899. IWL_DEBUG_MAC80211(priv, "enter\n");
  900. mutex_lock(&priv->shrd->mutex);
  901. iwl_scan_cancel_timeout(priv, priv->hw_roc_duration);
  902. iwlagn_disable_roc(priv);
  903. mutex_unlock(&priv->shrd->mutex);
  904. IWL_DEBUG_MAC80211(priv, "leave\n");
  905. return 0;
  906. }
  907. static void iwlagn_mac_rssi_callback(struct ieee80211_hw *hw,
  908. enum ieee80211_rssi_event rssi_event)
  909. {
  910. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  911. IWL_DEBUG_MAC80211(priv, "enter\n");
  912. mutex_lock(&priv->shrd->mutex);
  913. if (cfg(priv)->bt_params &&
  914. cfg(priv)->bt_params->advanced_bt_coexist) {
  915. if (rssi_event == RSSI_EVENT_LOW)
  916. priv->bt_enable_pspoll = true;
  917. else if (rssi_event == RSSI_EVENT_HIGH)
  918. priv->bt_enable_pspoll = false;
  919. iwlagn_send_advance_bt_config(priv);
  920. } else {
  921. IWL_DEBUG_MAC80211(priv, "Advanced BT coex disabled,"
  922. "ignoring RSSI callback\n");
  923. }
  924. mutex_unlock(&priv->shrd->mutex);
  925. IWL_DEBUG_MAC80211(priv, "leave\n");
  926. }
  927. static int iwlagn_mac_set_tim(struct ieee80211_hw *hw,
  928. struct ieee80211_sta *sta, bool set)
  929. {
  930. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  931. queue_work(priv->workqueue, &priv->beacon_update);
  932. return 0;
  933. }
  934. static int iwlagn_mac_conf_tx(struct ieee80211_hw *hw,
  935. struct ieee80211_vif *vif, u16 queue,
  936. const struct ieee80211_tx_queue_params *params)
  937. {
  938. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  939. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  940. struct iwl_rxon_context *ctx = vif_priv->ctx;
  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. mutex_lock(&priv->shrd->mutex);
  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. mutex_unlock(&priv->shrd->mutex);
  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 void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
  1215. {
  1216. struct iwl_addsta_cmd cmd = {
  1217. .mode = STA_CONTROL_MODIFY_MSK,
  1218. .station_flags_msk = STA_FLG_PWR_SAVE_MSK,
  1219. .sta.sta_id = sta_id,
  1220. };
  1221. iwl_send_add_sta(priv, &cmd, CMD_ASYNC);
  1222. }
  1223. static void iwlagn_mac_sta_notify(struct ieee80211_hw *hw,
  1224. struct ieee80211_vif *vif,
  1225. enum sta_notify_cmd cmd,
  1226. struct ieee80211_sta *sta)
  1227. {
  1228. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1229. struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
  1230. int sta_id;
  1231. IWL_DEBUG_MAC80211(priv, "enter\n");
  1232. switch (cmd) {
  1233. case STA_NOTIFY_SLEEP:
  1234. WARN_ON(!sta_priv->client);
  1235. sta_priv->asleep = true;
  1236. if (atomic_read(&sta_priv->pending_frames) > 0)
  1237. ieee80211_sta_block_awake(hw, sta, true);
  1238. break;
  1239. case STA_NOTIFY_AWAKE:
  1240. WARN_ON(!sta_priv->client);
  1241. if (!sta_priv->asleep)
  1242. break;
  1243. sta_priv->asleep = false;
  1244. sta_id = iwl_sta_id(sta);
  1245. if (sta_id != IWL_INVALID_STATION)
  1246. iwl_sta_modify_ps_wake(priv, sta_id);
  1247. break;
  1248. default:
  1249. break;
  1250. }
  1251. IWL_DEBUG_MAC80211(priv, "leave\n");
  1252. }
  1253. struct ieee80211_ops iwlagn_hw_ops = {
  1254. .tx = iwlagn_mac_tx,
  1255. .start = iwlagn_mac_start,
  1256. .stop = iwlagn_mac_stop,
  1257. #ifdef CONFIG_PM_SLEEP
  1258. .suspend = iwlagn_mac_suspend,
  1259. .resume = iwlagn_mac_resume,
  1260. #endif
  1261. .add_interface = iwlagn_mac_add_interface,
  1262. .remove_interface = iwlagn_mac_remove_interface,
  1263. .change_interface = iwlagn_mac_change_interface,
  1264. .config = iwlagn_mac_config,
  1265. .configure_filter = iwlagn_configure_filter,
  1266. .set_key = iwlagn_mac_set_key,
  1267. .update_tkip_key = iwlagn_mac_update_tkip_key,
  1268. .set_rekey_data = iwlagn_mac_set_rekey_data,
  1269. .conf_tx = iwlagn_mac_conf_tx,
  1270. .bss_info_changed = iwlagn_bss_info_changed,
  1271. .ampdu_action = iwlagn_mac_ampdu_action,
  1272. .hw_scan = iwlagn_mac_hw_scan,
  1273. .sta_notify = iwlagn_mac_sta_notify,
  1274. .sta_state = iwlagn_mac_sta_state,
  1275. .channel_switch = iwlagn_mac_channel_switch,
  1276. .flush = iwlagn_mac_flush,
  1277. .tx_last_beacon = iwlagn_mac_tx_last_beacon,
  1278. .remain_on_channel = iwlagn_mac_remain_on_channel,
  1279. .cancel_remain_on_channel = iwlagn_mac_cancel_remain_on_channel,
  1280. .rssi_callback = iwlagn_mac_rssi_callback,
  1281. CFG80211_TESTMODE_CMD(iwlagn_mac_testmode_cmd)
  1282. CFG80211_TESTMODE_DUMP(iwlagn_mac_testmode_dump)
  1283. .set_tim = iwlagn_mac_set_tim,
  1284. };
  1285. /* This function both allocates and initializes hw and priv. */
  1286. struct ieee80211_hw *iwl_alloc_all(void)
  1287. {
  1288. struct iwl_priv *priv;
  1289. struct iwl_op_mode *op_mode;
  1290. /* mac80211 allocates memory for this device instance, including
  1291. * space for this driver's private structure */
  1292. struct ieee80211_hw *hw;
  1293. hw = ieee80211_alloc_hw(sizeof(struct iwl_priv) +
  1294. sizeof(struct iwl_op_mode), &iwlagn_hw_ops);
  1295. if (!hw)
  1296. goto out;
  1297. op_mode = hw->priv;
  1298. priv = IWL_OP_MODE_GET_DVM(op_mode);
  1299. priv->hw = hw;
  1300. out:
  1301. return hw;
  1302. }