mac80211.c 46 KB

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