mac80211.c 42 KB

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