mac80211.c 43 KB

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