mac80211.c 45 KB

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