iwl-mac80211.c 40 KB

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