iwl-mac80211.c 41 KB

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