iwl-mac80211.c 41 KB

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