mac80211.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785
  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_FLUSH:
  650. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  651. IWL_DEBUG_HT(priv, "Flush Tx\n");
  652. ret = iwlagn_tx_agg_flush(priv, vif, sta, tid);
  653. break;
  654. case IEEE80211_AMPDU_TX_STOP_CONT:
  655. IWL_DEBUG_HT(priv, "stop Tx\n");
  656. ret = iwlagn_tx_agg_stop(priv, vif, sta, tid);
  657. if ((ret == 0) && (priv->agg_tids_count > 0)) {
  658. priv->agg_tids_count--;
  659. IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n",
  660. priv->agg_tids_count);
  661. }
  662. if (!priv->agg_tids_count &&
  663. priv->hw_params.use_rts_for_aggregation) {
  664. /*
  665. * switch off RTS/CTS if it was previously enabled
  666. */
  667. sta_priv->lq_sta.lq.general_params.flags &=
  668. ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
  669. iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
  670. &sta_priv->lq_sta.lq, CMD_ASYNC, false);
  671. }
  672. break;
  673. case IEEE80211_AMPDU_TX_OPERATIONAL:
  674. ret = iwlagn_tx_agg_oper(priv, vif, sta, tid, buf_size);
  675. break;
  676. }
  677. mutex_unlock(&priv->mutex);
  678. IWL_DEBUG_MAC80211(priv, "leave\n");
  679. return ret;
  680. }
  681. static int iwlagn_mac_sta_add(struct ieee80211_hw *hw,
  682. struct ieee80211_vif *vif,
  683. struct ieee80211_sta *sta)
  684. {
  685. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  686. struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
  687. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  688. bool is_ap = vif->type == NL80211_IFTYPE_STATION;
  689. int ret;
  690. u8 sta_id;
  691. IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
  692. sta->addr);
  693. sta_priv->sta_id = IWL_INVALID_STATION;
  694. atomic_set(&sta_priv->pending_frames, 0);
  695. if (vif->type == NL80211_IFTYPE_AP)
  696. sta_priv->client = true;
  697. ret = iwl_add_station_common(priv, vif_priv->ctx, sta->addr,
  698. is_ap, sta, &sta_id);
  699. if (ret) {
  700. IWL_ERR(priv, "Unable to add station %pM (%d)\n",
  701. sta->addr, ret);
  702. /* Should we return success if return code is EEXIST ? */
  703. return ret;
  704. }
  705. sta_priv->sta_id = sta_id;
  706. return 0;
  707. }
  708. static int iwlagn_mac_sta_remove(struct ieee80211_hw *hw,
  709. struct ieee80211_vif *vif,
  710. struct ieee80211_sta *sta)
  711. {
  712. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  713. struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
  714. int ret;
  715. IWL_DEBUG_INFO(priv, "proceeding to remove station %pM\n", sta->addr);
  716. if (vif->type == NL80211_IFTYPE_STATION) {
  717. /*
  718. * Station will be removed from device when the RXON
  719. * is set to unassociated -- just deactivate it here
  720. * to avoid re-programming it.
  721. */
  722. ret = 0;
  723. iwl_deactivate_station(priv, sta_priv->sta_id, sta->addr);
  724. } else {
  725. ret = iwl_remove_station(priv, sta_priv->sta_id, sta->addr);
  726. if (ret)
  727. IWL_DEBUG_QUIET_RFKILL(priv,
  728. "Error removing station %pM\n", sta->addr);
  729. }
  730. return ret;
  731. }
  732. static int iwlagn_mac_sta_state(struct ieee80211_hw *hw,
  733. struct ieee80211_vif *vif,
  734. struct ieee80211_sta *sta,
  735. enum ieee80211_sta_state old_state,
  736. enum ieee80211_sta_state new_state)
  737. {
  738. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  739. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  740. enum {
  741. NONE, ADD, REMOVE, HT_RATE_INIT, ADD_RATE_INIT,
  742. } op = NONE;
  743. int ret;
  744. IWL_DEBUG_MAC80211(priv, "station %pM state change %d->%d\n",
  745. sta->addr, old_state, new_state);
  746. mutex_lock(&priv->mutex);
  747. if (vif->type == NL80211_IFTYPE_STATION) {
  748. if (old_state == IEEE80211_STA_NOTEXIST &&
  749. new_state == IEEE80211_STA_NONE)
  750. op = ADD;
  751. else if (old_state == IEEE80211_STA_NONE &&
  752. new_state == IEEE80211_STA_NOTEXIST)
  753. op = REMOVE;
  754. else if (old_state == IEEE80211_STA_AUTH &&
  755. new_state == IEEE80211_STA_ASSOC)
  756. op = HT_RATE_INIT;
  757. } else {
  758. if (old_state == IEEE80211_STA_AUTH &&
  759. new_state == IEEE80211_STA_ASSOC)
  760. op = ADD_RATE_INIT;
  761. else if (old_state == IEEE80211_STA_ASSOC &&
  762. new_state == IEEE80211_STA_AUTH)
  763. op = REMOVE;
  764. }
  765. switch (op) {
  766. case ADD:
  767. ret = iwlagn_mac_sta_add(hw, vif, sta);
  768. if (ret)
  769. break;
  770. /*
  771. * Clear the in-progress flag, the AP station entry was added
  772. * but we'll initialize LQ only when we've associated (which
  773. * would also clear the in-progress flag). This is necessary
  774. * in case we never initialize LQ because association fails.
  775. */
  776. spin_lock_bh(&priv->sta_lock);
  777. priv->stations[iwl_sta_id(sta)].used &=
  778. ~IWL_STA_UCODE_INPROGRESS;
  779. spin_unlock_bh(&priv->sta_lock);
  780. break;
  781. case REMOVE:
  782. ret = iwlagn_mac_sta_remove(hw, vif, sta);
  783. break;
  784. case ADD_RATE_INIT:
  785. ret = iwlagn_mac_sta_add(hw, vif, sta);
  786. if (ret)
  787. break;
  788. /* Initialize rate scaling */
  789. IWL_DEBUG_INFO(priv,
  790. "Initializing rate scaling for station %pM\n",
  791. sta->addr);
  792. iwl_rs_rate_init(priv, sta, iwl_sta_id(sta));
  793. ret = 0;
  794. break;
  795. case HT_RATE_INIT:
  796. /* Initialize rate scaling */
  797. ret = iwl_sta_update_ht(priv, vif_priv->ctx, sta);
  798. if (ret)
  799. break;
  800. IWL_DEBUG_INFO(priv,
  801. "Initializing rate scaling for station %pM\n",
  802. sta->addr);
  803. iwl_rs_rate_init(priv, sta, iwl_sta_id(sta));
  804. ret = 0;
  805. break;
  806. default:
  807. ret = 0;
  808. break;
  809. }
  810. /*
  811. * mac80211 might WARN if we fail, but due the way we
  812. * (badly) handle hard rfkill, we might fail here
  813. */
  814. if (iwl_is_rfkill(priv))
  815. ret = 0;
  816. mutex_unlock(&priv->mutex);
  817. IWL_DEBUG_MAC80211(priv, "leave\n");
  818. return ret;
  819. }
  820. static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
  821. struct ieee80211_channel_switch *ch_switch)
  822. {
  823. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  824. struct ieee80211_conf *conf = &hw->conf;
  825. struct ieee80211_channel *channel = ch_switch->chandef.chan;
  826. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  827. /*
  828. * MULTI-FIXME
  829. * When we add support for multiple interfaces, we need to
  830. * revisit this. The channel switch command in the device
  831. * only affects the BSS context, but what does that really
  832. * mean? And what if we get a CSA on the second interface?
  833. * This needs a lot of work.
  834. */
  835. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  836. u16 ch;
  837. IWL_DEBUG_MAC80211(priv, "enter\n");
  838. mutex_lock(&priv->mutex);
  839. if (iwl_is_rfkill(priv))
  840. goto out;
  841. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  842. test_bit(STATUS_SCANNING, &priv->status) ||
  843. test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status))
  844. goto out;
  845. if (!iwl_is_associated_ctx(ctx))
  846. goto out;
  847. if (!priv->lib->set_channel_switch)
  848. goto out;
  849. ch = channel->hw_value;
  850. if (le16_to_cpu(ctx->active.channel) == ch)
  851. goto out;
  852. priv->current_ht_config.smps = conf->smps_mode;
  853. /* Configure HT40 channels */
  854. switch (cfg80211_get_chandef_type(&ch_switch->chandef)) {
  855. case NL80211_CHAN_NO_HT:
  856. case NL80211_CHAN_HT20:
  857. ctx->ht.is_40mhz = false;
  858. ctx->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
  859. break;
  860. case NL80211_CHAN_HT40MINUS:
  861. ctx->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  862. ctx->ht.is_40mhz = true;
  863. break;
  864. case NL80211_CHAN_HT40PLUS:
  865. ctx->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  866. ctx->ht.is_40mhz = true;
  867. break;
  868. }
  869. if ((le16_to_cpu(ctx->staging.channel) != ch))
  870. ctx->staging.flags = 0;
  871. iwl_set_rxon_channel(priv, channel, ctx);
  872. iwl_set_rxon_ht(priv, ht_conf);
  873. iwl_set_flags_for_band(priv, ctx, channel->band, ctx->vif);
  874. /*
  875. * at this point, staging_rxon has the
  876. * configuration for channel switch
  877. */
  878. set_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status);
  879. priv->switch_channel = cpu_to_le16(ch);
  880. if (priv->lib->set_channel_switch(priv, ch_switch)) {
  881. clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status);
  882. priv->switch_channel = 0;
  883. ieee80211_chswitch_done(ctx->vif, false);
  884. }
  885. out:
  886. mutex_unlock(&priv->mutex);
  887. IWL_DEBUG_MAC80211(priv, "leave\n");
  888. }
  889. void iwl_chswitch_done(struct iwl_priv *priv, bool is_success)
  890. {
  891. /*
  892. * MULTI-FIXME
  893. * See iwlagn_mac_channel_switch.
  894. */
  895. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  896. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  897. return;
  898. if (test_and_clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status))
  899. ieee80211_chswitch_done(ctx->vif, is_success);
  900. }
  901. static void iwlagn_configure_filter(struct ieee80211_hw *hw,
  902. unsigned int changed_flags,
  903. unsigned int *total_flags,
  904. u64 multicast)
  905. {
  906. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  907. __le32 filter_or = 0, filter_nand = 0;
  908. struct iwl_rxon_context *ctx;
  909. #define CHK(test, flag) do { \
  910. if (*total_flags & (test)) \
  911. filter_or |= (flag); \
  912. else \
  913. filter_nand |= (flag); \
  914. } while (0)
  915. IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
  916. changed_flags, *total_flags);
  917. CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
  918. /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */
  919. CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK);
  920. CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
  921. #undef CHK
  922. mutex_lock(&priv->mutex);
  923. for_each_context(priv, ctx) {
  924. ctx->staging.filter_flags &= ~filter_nand;
  925. ctx->staging.filter_flags |= filter_or;
  926. /*
  927. * Not committing directly because hardware can perform a scan,
  928. * but we'll eventually commit the filter flags change anyway.
  929. */
  930. }
  931. mutex_unlock(&priv->mutex);
  932. /*
  933. * Receiving all multicast frames is always enabled by the
  934. * default flags setup in iwl_connection_init_rx_config()
  935. * since we currently do not support programming multicast
  936. * filters into the device.
  937. */
  938. *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
  939. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
  940. }
  941. static void iwlagn_mac_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
  942. {
  943. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  944. mutex_lock(&priv->mutex);
  945. IWL_DEBUG_MAC80211(priv, "enter\n");
  946. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  947. IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n");
  948. goto done;
  949. }
  950. if (iwl_is_rfkill(priv)) {
  951. IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n");
  952. goto done;
  953. }
  954. /*
  955. * mac80211 will not push any more frames for transmit
  956. * until the flush is completed
  957. */
  958. if (drop) {
  959. IWL_DEBUG_MAC80211(priv, "send flush command\n");
  960. if (iwlagn_txfifo_flush(priv, 0)) {
  961. IWL_ERR(priv, "flush request fail\n");
  962. goto done;
  963. }
  964. }
  965. IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n");
  966. iwl_trans_wait_tx_queue_empty(priv->trans);
  967. done:
  968. mutex_unlock(&priv->mutex);
  969. IWL_DEBUG_MAC80211(priv, "leave\n");
  970. }
  971. static int iwlagn_mac_remain_on_channel(struct ieee80211_hw *hw,
  972. struct ieee80211_vif *vif,
  973. struct ieee80211_channel *channel,
  974. int duration,
  975. enum ieee80211_roc_type type)
  976. {
  977. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  978. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
  979. int err = 0;
  980. if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
  981. return -EOPNOTSUPP;
  982. if (!(ctx->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)))
  983. return -EOPNOTSUPP;
  984. IWL_DEBUG_MAC80211(priv, "enter\n");
  985. mutex_lock(&priv->mutex);
  986. if (test_bit(STATUS_SCAN_HW, &priv->status)) {
  987. /* mac80211 should not scan while ROC or ROC while scanning */
  988. if (WARN_ON_ONCE(priv->scan_type != IWL_SCAN_RADIO_RESET)) {
  989. err = -EBUSY;
  990. goto out;
  991. }
  992. iwl_scan_cancel_timeout(priv, 100);
  993. if (test_bit(STATUS_SCAN_HW, &priv->status)) {
  994. err = -EBUSY;
  995. goto out;
  996. }
  997. }
  998. priv->hw_roc_channel = channel;
  999. /* convert from ms to TU */
  1000. priv->hw_roc_duration = DIV_ROUND_UP(1000 * duration, 1024);
  1001. priv->hw_roc_start_notified = false;
  1002. cancel_delayed_work(&priv->hw_roc_disable_work);
  1003. if (!ctx->is_active) {
  1004. static const struct iwl_qos_info default_qos_data = {
  1005. .def_qos_parm = {
  1006. .ac[0] = {
  1007. .cw_min = cpu_to_le16(3),
  1008. .cw_max = cpu_to_le16(7),
  1009. .aifsn = 2,
  1010. .edca_txop = cpu_to_le16(1504),
  1011. },
  1012. .ac[1] = {
  1013. .cw_min = cpu_to_le16(7),
  1014. .cw_max = cpu_to_le16(15),
  1015. .aifsn = 2,
  1016. .edca_txop = cpu_to_le16(3008),
  1017. },
  1018. .ac[2] = {
  1019. .cw_min = cpu_to_le16(15),
  1020. .cw_max = cpu_to_le16(1023),
  1021. .aifsn = 3,
  1022. },
  1023. .ac[3] = {
  1024. .cw_min = cpu_to_le16(15),
  1025. .cw_max = cpu_to_le16(1023),
  1026. .aifsn = 7,
  1027. },
  1028. },
  1029. };
  1030. ctx->is_active = true;
  1031. ctx->qos_data = default_qos_data;
  1032. ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
  1033. memcpy(ctx->staging.node_addr,
  1034. priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr,
  1035. ETH_ALEN);
  1036. memcpy(ctx->staging.bssid_addr,
  1037. priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr,
  1038. ETH_ALEN);
  1039. err = iwlagn_commit_rxon(priv, ctx);
  1040. if (err)
  1041. goto out;
  1042. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK |
  1043. RXON_FILTER_PROMISC_MSK |
  1044. RXON_FILTER_CTL2HOST_MSK;
  1045. err = iwlagn_commit_rxon(priv, ctx);
  1046. if (err) {
  1047. iwlagn_disable_roc(priv);
  1048. goto out;
  1049. }
  1050. priv->hw_roc_setup = true;
  1051. }
  1052. err = iwl_scan_initiate(priv, ctx->vif, IWL_SCAN_ROC, channel->band);
  1053. if (err)
  1054. iwlagn_disable_roc(priv);
  1055. out:
  1056. mutex_unlock(&priv->mutex);
  1057. IWL_DEBUG_MAC80211(priv, "leave\n");
  1058. return err;
  1059. }
  1060. static int iwlagn_mac_cancel_remain_on_channel(struct ieee80211_hw *hw)
  1061. {
  1062. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1063. if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
  1064. return -EOPNOTSUPP;
  1065. IWL_DEBUG_MAC80211(priv, "enter\n");
  1066. mutex_lock(&priv->mutex);
  1067. iwl_scan_cancel_timeout(priv, priv->hw_roc_duration);
  1068. iwlagn_disable_roc(priv);
  1069. mutex_unlock(&priv->mutex);
  1070. IWL_DEBUG_MAC80211(priv, "leave\n");
  1071. return 0;
  1072. }
  1073. static void iwlagn_mac_rssi_callback(struct ieee80211_hw *hw,
  1074. struct ieee80211_vif *vif,
  1075. enum ieee80211_rssi_event rssi_event)
  1076. {
  1077. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1078. IWL_DEBUG_MAC80211(priv, "enter\n");
  1079. mutex_lock(&priv->mutex);
  1080. if (priv->cfg->bt_params &&
  1081. priv->cfg->bt_params->advanced_bt_coexist) {
  1082. if (rssi_event == RSSI_EVENT_LOW)
  1083. priv->bt_enable_pspoll = true;
  1084. else if (rssi_event == RSSI_EVENT_HIGH)
  1085. priv->bt_enable_pspoll = false;
  1086. iwlagn_send_advance_bt_config(priv);
  1087. } else {
  1088. IWL_DEBUG_MAC80211(priv, "Advanced BT coex disabled,"
  1089. "ignoring RSSI callback\n");
  1090. }
  1091. mutex_unlock(&priv->mutex);
  1092. IWL_DEBUG_MAC80211(priv, "leave\n");
  1093. }
  1094. static int iwlagn_mac_set_tim(struct ieee80211_hw *hw,
  1095. struct ieee80211_sta *sta, bool set)
  1096. {
  1097. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1098. queue_work(priv->workqueue, &priv->beacon_update);
  1099. return 0;
  1100. }
  1101. static int iwlagn_mac_conf_tx(struct ieee80211_hw *hw,
  1102. struct ieee80211_vif *vif, u16 queue,
  1103. const struct ieee80211_tx_queue_params *params)
  1104. {
  1105. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1106. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  1107. struct iwl_rxon_context *ctx = vif_priv->ctx;
  1108. int q;
  1109. if (WARN_ON(!ctx))
  1110. return -EINVAL;
  1111. IWL_DEBUG_MAC80211(priv, "enter\n");
  1112. if (!iwl_is_ready_rf(priv)) {
  1113. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  1114. return -EIO;
  1115. }
  1116. if (queue >= AC_NUM) {
  1117. IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
  1118. return 0;
  1119. }
  1120. q = AC_NUM - 1 - queue;
  1121. mutex_lock(&priv->mutex);
  1122. ctx->qos_data.def_qos_parm.ac[q].cw_min =
  1123. cpu_to_le16(params->cw_min);
  1124. ctx->qos_data.def_qos_parm.ac[q].cw_max =
  1125. cpu_to_le16(params->cw_max);
  1126. ctx->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
  1127. ctx->qos_data.def_qos_parm.ac[q].edca_txop =
  1128. cpu_to_le16((params->txop * 32));
  1129. ctx->qos_data.def_qos_parm.ac[q].reserved1 = 0;
  1130. mutex_unlock(&priv->mutex);
  1131. IWL_DEBUG_MAC80211(priv, "leave\n");
  1132. return 0;
  1133. }
  1134. static int iwlagn_mac_tx_last_beacon(struct ieee80211_hw *hw)
  1135. {
  1136. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1137. return priv->ibss_manager == IWL_IBSS_MANAGER;
  1138. }
  1139. static int iwl_set_mode(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  1140. {
  1141. iwl_connection_init_rx_config(priv, ctx);
  1142. iwlagn_set_rxon_chain(priv, ctx);
  1143. return iwlagn_commit_rxon(priv, ctx);
  1144. }
  1145. static int iwl_setup_interface(struct iwl_priv *priv,
  1146. struct iwl_rxon_context *ctx)
  1147. {
  1148. struct ieee80211_vif *vif = ctx->vif;
  1149. int err, ac;
  1150. lockdep_assert_held(&priv->mutex);
  1151. /*
  1152. * This variable will be correct only when there's just
  1153. * a single context, but all code using it is for hardware
  1154. * that supports only one context.
  1155. */
  1156. priv->iw_mode = vif->type;
  1157. ctx->is_active = true;
  1158. err = iwl_set_mode(priv, ctx);
  1159. if (err) {
  1160. if (!ctx->always_active)
  1161. ctx->is_active = false;
  1162. return err;
  1163. }
  1164. if (priv->cfg->bt_params && priv->cfg->bt_params->advanced_bt_coexist &&
  1165. vif->type == NL80211_IFTYPE_ADHOC) {
  1166. /*
  1167. * pretend to have high BT traffic as long as we
  1168. * are operating in IBSS mode, as this will cause
  1169. * the rate scaling etc. to behave as intended.
  1170. */
  1171. priv->bt_traffic_load = IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
  1172. }
  1173. /* set up queue mappings */
  1174. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  1175. vif->hw_queue[ac] = ctx->ac_to_queue[ac];
  1176. if (vif->type == NL80211_IFTYPE_AP)
  1177. vif->cab_queue = ctx->mcast_queue;
  1178. else
  1179. vif->cab_queue = IEEE80211_INVAL_HW_QUEUE;
  1180. return 0;
  1181. }
  1182. static int iwlagn_mac_add_interface(struct ieee80211_hw *hw,
  1183. struct ieee80211_vif *vif)
  1184. {
  1185. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1186. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  1187. struct iwl_rxon_context *tmp, *ctx = NULL;
  1188. int err;
  1189. enum nl80211_iftype viftype = ieee80211_vif_type_p2p(vif);
  1190. bool reset = false;
  1191. IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n",
  1192. viftype, vif->addr);
  1193. cancel_delayed_work_sync(&priv->hw_roc_disable_work);
  1194. mutex_lock(&priv->mutex);
  1195. iwlagn_disable_roc(priv);
  1196. if (!iwl_is_ready_rf(priv)) {
  1197. IWL_WARN(priv, "Try to add interface when device not ready\n");
  1198. err = -EINVAL;
  1199. goto out;
  1200. }
  1201. for_each_context(priv, tmp) {
  1202. u32 possible_modes =
  1203. tmp->interface_modes | tmp->exclusive_interface_modes;
  1204. if (tmp->vif) {
  1205. /* On reset we need to add the same interface again */
  1206. if (tmp->vif == vif) {
  1207. reset = true;
  1208. ctx = tmp;
  1209. break;
  1210. }
  1211. /* check if this busy context is exclusive */
  1212. if (tmp->exclusive_interface_modes &
  1213. BIT(tmp->vif->type)) {
  1214. err = -EINVAL;
  1215. goto out;
  1216. }
  1217. continue;
  1218. }
  1219. if (!(possible_modes & BIT(viftype)))
  1220. continue;
  1221. /* have maybe usable context w/o interface */
  1222. ctx = tmp;
  1223. break;
  1224. }
  1225. if (!ctx) {
  1226. err = -EOPNOTSUPP;
  1227. goto out;
  1228. }
  1229. vif_priv->ctx = ctx;
  1230. ctx->vif = vif;
  1231. /*
  1232. * In SNIFFER device type, the firmware reports the FCS to
  1233. * the host, rather than snipping it off. Unfortunately,
  1234. * mac80211 doesn't (yet) provide a per-packet flag for
  1235. * this, so that we have to set the hardware flag based
  1236. * on the interfaces added. As the monitor interface can
  1237. * only be present by itself, and will be removed before
  1238. * other interfaces are added, this is safe.
  1239. */
  1240. if (vif->type == NL80211_IFTYPE_MONITOR)
  1241. priv->hw->flags |= IEEE80211_HW_RX_INCLUDES_FCS;
  1242. else
  1243. priv->hw->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
  1244. err = iwl_setup_interface(priv, ctx);
  1245. if (!err || reset)
  1246. goto out;
  1247. ctx->vif = NULL;
  1248. priv->iw_mode = NL80211_IFTYPE_STATION;
  1249. out:
  1250. mutex_unlock(&priv->mutex);
  1251. IWL_DEBUG_MAC80211(priv, "leave\n");
  1252. return err;
  1253. }
  1254. static void iwl_teardown_interface(struct iwl_priv *priv,
  1255. struct ieee80211_vif *vif,
  1256. bool mode_change)
  1257. {
  1258. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1259. lockdep_assert_held(&priv->mutex);
  1260. if (priv->scan_vif == vif) {
  1261. iwl_scan_cancel_timeout(priv, 200);
  1262. iwl_force_scan_end(priv);
  1263. }
  1264. if (!mode_change) {
  1265. iwl_set_mode(priv, ctx);
  1266. if (!ctx->always_active)
  1267. ctx->is_active = false;
  1268. }
  1269. /*
  1270. * When removing the IBSS interface, overwrite the
  1271. * BT traffic load with the stored one from the last
  1272. * notification, if any. If this is a device that
  1273. * doesn't implement this, this has no effect since
  1274. * both values are the same and zero.
  1275. */
  1276. if (vif->type == NL80211_IFTYPE_ADHOC)
  1277. priv->bt_traffic_load = priv->last_bt_traffic_load;
  1278. }
  1279. static void iwlagn_mac_remove_interface(struct ieee80211_hw *hw,
  1280. struct ieee80211_vif *vif)
  1281. {
  1282. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1283. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1284. IWL_DEBUG_MAC80211(priv, "enter\n");
  1285. mutex_lock(&priv->mutex);
  1286. if (WARN_ON(ctx->vif != vif)) {
  1287. struct iwl_rxon_context *tmp;
  1288. IWL_ERR(priv, "ctx->vif = %p, vif = %p\n", ctx->vif, vif);
  1289. for_each_context(priv, tmp)
  1290. IWL_ERR(priv, "\tID = %d:\tctx = %p\tctx->vif = %p\n",
  1291. tmp->ctxid, tmp, tmp->vif);
  1292. }
  1293. ctx->vif = NULL;
  1294. iwl_teardown_interface(priv, vif, false);
  1295. mutex_unlock(&priv->mutex);
  1296. IWL_DEBUG_MAC80211(priv, "leave\n");
  1297. }
  1298. static int iwlagn_mac_change_interface(struct ieee80211_hw *hw,
  1299. struct ieee80211_vif *vif,
  1300. enum nl80211_iftype newtype, bool newp2p)
  1301. {
  1302. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1303. struct iwl_rxon_context *ctx, *tmp;
  1304. enum nl80211_iftype newviftype = newtype;
  1305. u32 interface_modes;
  1306. int err;
  1307. IWL_DEBUG_MAC80211(priv, "enter\n");
  1308. newtype = ieee80211_iftype_p2p(newtype, newp2p);
  1309. mutex_lock(&priv->mutex);
  1310. ctx = iwl_rxon_ctx_from_vif(vif);
  1311. /*
  1312. * To simplify this code, only support changes on the
  1313. * BSS context. The PAN context is usually reassigned
  1314. * by creating/removing P2P interfaces anyway.
  1315. */
  1316. if (ctx->ctxid != IWL_RXON_CTX_BSS) {
  1317. err = -EBUSY;
  1318. goto out;
  1319. }
  1320. if (!ctx->vif || !iwl_is_ready_rf(priv)) {
  1321. /*
  1322. * Huh? But wait ... this can maybe happen when
  1323. * we're in the middle of a firmware restart!
  1324. */
  1325. err = -EBUSY;
  1326. goto out;
  1327. }
  1328. /* Check if the switch is supported in the same context */
  1329. interface_modes = ctx->interface_modes | ctx->exclusive_interface_modes;
  1330. if (!(interface_modes & BIT(newtype))) {
  1331. err = -EBUSY;
  1332. goto out;
  1333. }
  1334. if (ctx->exclusive_interface_modes & BIT(newtype)) {
  1335. for_each_context(priv, tmp) {
  1336. if (ctx == tmp)
  1337. continue;
  1338. if (!tmp->is_active)
  1339. continue;
  1340. /*
  1341. * The current mode switch would be exclusive, but
  1342. * another context is active ... refuse the switch.
  1343. */
  1344. err = -EBUSY;
  1345. goto out;
  1346. }
  1347. }
  1348. /* success */
  1349. iwl_teardown_interface(priv, vif, true);
  1350. vif->type = newviftype;
  1351. vif->p2p = newp2p;
  1352. err = iwl_setup_interface(priv, ctx);
  1353. WARN_ON(err);
  1354. /*
  1355. * We've switched internally, but submitting to the
  1356. * device may have failed for some reason. Mask this
  1357. * error, because otherwise mac80211 will not switch
  1358. * (and set the interface type back) and we'll be
  1359. * out of sync with it.
  1360. */
  1361. err = 0;
  1362. out:
  1363. mutex_unlock(&priv->mutex);
  1364. IWL_DEBUG_MAC80211(priv, "leave\n");
  1365. return err;
  1366. }
  1367. static int iwlagn_mac_hw_scan(struct ieee80211_hw *hw,
  1368. struct ieee80211_vif *vif,
  1369. struct cfg80211_scan_request *req)
  1370. {
  1371. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1372. int ret;
  1373. IWL_DEBUG_MAC80211(priv, "enter\n");
  1374. if (req->n_channels == 0)
  1375. return -EINVAL;
  1376. mutex_lock(&priv->mutex);
  1377. /*
  1378. * If an internal scan is in progress, just set
  1379. * up the scan_request as per above.
  1380. */
  1381. if (priv->scan_type != IWL_SCAN_NORMAL) {
  1382. IWL_DEBUG_SCAN(priv,
  1383. "SCAN request during internal scan - defer\n");
  1384. priv->scan_request = req;
  1385. priv->scan_vif = vif;
  1386. ret = 0;
  1387. } else {
  1388. priv->scan_request = req;
  1389. priv->scan_vif = vif;
  1390. /*
  1391. * mac80211 will only ask for one band at a time
  1392. * so using channels[0] here is ok
  1393. */
  1394. ret = iwl_scan_initiate(priv, vif, IWL_SCAN_NORMAL,
  1395. req->channels[0]->band);
  1396. if (ret) {
  1397. priv->scan_request = NULL;
  1398. priv->scan_vif = NULL;
  1399. }
  1400. }
  1401. IWL_DEBUG_MAC80211(priv, "leave\n");
  1402. mutex_unlock(&priv->mutex);
  1403. return ret;
  1404. }
  1405. static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
  1406. {
  1407. struct iwl_addsta_cmd cmd = {
  1408. .mode = STA_CONTROL_MODIFY_MSK,
  1409. .station_flags_msk = STA_FLG_PWR_SAVE_MSK,
  1410. .sta.sta_id = sta_id,
  1411. };
  1412. iwl_send_add_sta(priv, &cmd, CMD_ASYNC);
  1413. }
  1414. static void iwlagn_mac_sta_notify(struct ieee80211_hw *hw,
  1415. struct ieee80211_vif *vif,
  1416. enum sta_notify_cmd cmd,
  1417. struct ieee80211_sta *sta)
  1418. {
  1419. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1420. struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
  1421. int sta_id;
  1422. IWL_DEBUG_MAC80211(priv, "enter\n");
  1423. switch (cmd) {
  1424. case STA_NOTIFY_SLEEP:
  1425. WARN_ON(!sta_priv->client);
  1426. sta_priv->asleep = true;
  1427. if (atomic_read(&sta_priv->pending_frames) > 0)
  1428. ieee80211_sta_block_awake(hw, sta, true);
  1429. break;
  1430. case STA_NOTIFY_AWAKE:
  1431. WARN_ON(!sta_priv->client);
  1432. if (!sta_priv->asleep)
  1433. break;
  1434. sta_priv->asleep = false;
  1435. sta_id = iwl_sta_id(sta);
  1436. if (sta_id != IWL_INVALID_STATION)
  1437. iwl_sta_modify_ps_wake(priv, sta_id);
  1438. break;
  1439. default:
  1440. break;
  1441. }
  1442. IWL_DEBUG_MAC80211(priv, "leave\n");
  1443. }
  1444. struct ieee80211_ops iwlagn_hw_ops = {
  1445. .tx = iwlagn_mac_tx,
  1446. .start = iwlagn_mac_start,
  1447. .stop = iwlagn_mac_stop,
  1448. #ifdef CONFIG_PM_SLEEP
  1449. .suspend = iwlagn_mac_suspend,
  1450. .resume = iwlagn_mac_resume,
  1451. .set_wakeup = iwlagn_mac_set_wakeup,
  1452. #endif
  1453. .add_interface = iwlagn_mac_add_interface,
  1454. .remove_interface = iwlagn_mac_remove_interface,
  1455. .change_interface = iwlagn_mac_change_interface,
  1456. .config = iwlagn_mac_config,
  1457. .configure_filter = iwlagn_configure_filter,
  1458. .set_key = iwlagn_mac_set_key,
  1459. .update_tkip_key = iwlagn_mac_update_tkip_key,
  1460. .set_rekey_data = iwlagn_mac_set_rekey_data,
  1461. .conf_tx = iwlagn_mac_conf_tx,
  1462. .bss_info_changed = iwlagn_bss_info_changed,
  1463. .ampdu_action = iwlagn_mac_ampdu_action,
  1464. .hw_scan = iwlagn_mac_hw_scan,
  1465. .sta_notify = iwlagn_mac_sta_notify,
  1466. .sta_state = iwlagn_mac_sta_state,
  1467. .channel_switch = iwlagn_mac_channel_switch,
  1468. .flush = iwlagn_mac_flush,
  1469. .tx_last_beacon = iwlagn_mac_tx_last_beacon,
  1470. .remain_on_channel = iwlagn_mac_remain_on_channel,
  1471. .cancel_remain_on_channel = iwlagn_mac_cancel_remain_on_channel,
  1472. .rssi_callback = iwlagn_mac_rssi_callback,
  1473. CFG80211_TESTMODE_CMD(iwlagn_mac_testmode_cmd)
  1474. CFG80211_TESTMODE_DUMP(iwlagn_mac_testmode_dump)
  1475. .set_tim = iwlagn_mac_set_tim,
  1476. };
  1477. /* This function both allocates and initializes hw and priv. */
  1478. struct ieee80211_hw *iwl_alloc_all(void)
  1479. {
  1480. struct iwl_priv *priv;
  1481. struct iwl_op_mode *op_mode;
  1482. /* mac80211 allocates memory for this device instance, including
  1483. * space for this driver's private structure */
  1484. struct ieee80211_hw *hw;
  1485. hw = ieee80211_alloc_hw(sizeof(struct iwl_priv) +
  1486. sizeof(struct iwl_op_mode), &iwlagn_hw_ops);
  1487. if (!hw)
  1488. goto out;
  1489. op_mode = hw->priv;
  1490. priv = IWL_OP_MODE_GET_DVM(op_mode);
  1491. priv->hw = hw;
  1492. out:
  1493. return hw;
  1494. }