mac80211.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775
  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->channel;
  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. ctx->ht.enabled = conf_is_ht(conf);
  855. if (ctx->ht.enabled)
  856. iwlagn_config_ht40(conf, ctx);
  857. else
  858. ctx->ht.is_40mhz = false;
  859. if ((le16_to_cpu(ctx->staging.channel) != ch))
  860. ctx->staging.flags = 0;
  861. iwl_set_rxon_channel(priv, channel, ctx);
  862. iwl_set_rxon_ht(priv, ht_conf);
  863. iwl_set_flags_for_band(priv, ctx, channel->band, ctx->vif);
  864. /*
  865. * at this point, staging_rxon has the
  866. * configuration for channel switch
  867. */
  868. set_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status);
  869. priv->switch_channel = cpu_to_le16(ch);
  870. if (priv->lib->set_channel_switch(priv, ch_switch)) {
  871. clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status);
  872. priv->switch_channel = 0;
  873. ieee80211_chswitch_done(ctx->vif, false);
  874. }
  875. out:
  876. mutex_unlock(&priv->mutex);
  877. IWL_DEBUG_MAC80211(priv, "leave\n");
  878. }
  879. void iwl_chswitch_done(struct iwl_priv *priv, bool is_success)
  880. {
  881. /*
  882. * MULTI-FIXME
  883. * See iwlagn_mac_channel_switch.
  884. */
  885. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  886. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  887. return;
  888. if (test_and_clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status))
  889. ieee80211_chswitch_done(ctx->vif, is_success);
  890. }
  891. static void iwlagn_configure_filter(struct ieee80211_hw *hw,
  892. unsigned int changed_flags,
  893. unsigned int *total_flags,
  894. u64 multicast)
  895. {
  896. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  897. __le32 filter_or = 0, filter_nand = 0;
  898. struct iwl_rxon_context *ctx;
  899. #define CHK(test, flag) do { \
  900. if (*total_flags & (test)) \
  901. filter_or |= (flag); \
  902. else \
  903. filter_nand |= (flag); \
  904. } while (0)
  905. IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
  906. changed_flags, *total_flags);
  907. CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
  908. /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */
  909. CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK);
  910. CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
  911. #undef CHK
  912. mutex_lock(&priv->mutex);
  913. for_each_context(priv, ctx) {
  914. ctx->staging.filter_flags &= ~filter_nand;
  915. ctx->staging.filter_flags |= filter_or;
  916. /*
  917. * Not committing directly because hardware can perform a scan,
  918. * but we'll eventually commit the filter flags change anyway.
  919. */
  920. }
  921. mutex_unlock(&priv->mutex);
  922. /*
  923. * Receiving all multicast frames is always enabled by the
  924. * default flags setup in iwl_connection_init_rx_config()
  925. * since we currently do not support programming multicast
  926. * filters into the device.
  927. */
  928. *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
  929. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
  930. }
  931. static void iwlagn_mac_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
  932. {
  933. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  934. mutex_lock(&priv->mutex);
  935. IWL_DEBUG_MAC80211(priv, "enter\n");
  936. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  937. IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n");
  938. goto done;
  939. }
  940. if (iwl_is_rfkill(priv)) {
  941. IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n");
  942. goto done;
  943. }
  944. /*
  945. * mac80211 will not push any more frames for transmit
  946. * until the flush is completed
  947. */
  948. if (drop) {
  949. IWL_DEBUG_MAC80211(priv, "send flush command\n");
  950. if (iwlagn_txfifo_flush(priv, 0)) {
  951. IWL_ERR(priv, "flush request fail\n");
  952. goto done;
  953. }
  954. }
  955. IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n");
  956. iwl_trans_wait_tx_queue_empty(priv->trans);
  957. done:
  958. mutex_unlock(&priv->mutex);
  959. IWL_DEBUG_MAC80211(priv, "leave\n");
  960. }
  961. static int iwlagn_mac_remain_on_channel(struct ieee80211_hw *hw,
  962. struct ieee80211_vif *vif,
  963. struct ieee80211_channel *channel,
  964. int duration,
  965. enum ieee80211_roc_type type)
  966. {
  967. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  968. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
  969. int err = 0;
  970. if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
  971. return -EOPNOTSUPP;
  972. if (!(ctx->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)))
  973. return -EOPNOTSUPP;
  974. IWL_DEBUG_MAC80211(priv, "enter\n");
  975. mutex_lock(&priv->mutex);
  976. if (test_bit(STATUS_SCAN_HW, &priv->status)) {
  977. /* mac80211 should not scan while ROC or ROC while scanning */
  978. if (WARN_ON_ONCE(priv->scan_type != IWL_SCAN_RADIO_RESET)) {
  979. err = -EBUSY;
  980. goto out;
  981. }
  982. iwl_scan_cancel_timeout(priv, 100);
  983. if (test_bit(STATUS_SCAN_HW, &priv->status)) {
  984. err = -EBUSY;
  985. goto out;
  986. }
  987. }
  988. priv->hw_roc_channel = channel;
  989. /* convert from ms to TU */
  990. priv->hw_roc_duration = DIV_ROUND_UP(1000 * duration, 1024);
  991. priv->hw_roc_start_notified = false;
  992. cancel_delayed_work(&priv->hw_roc_disable_work);
  993. if (!ctx->is_active) {
  994. static const struct iwl_qos_info default_qos_data = {
  995. .def_qos_parm = {
  996. .ac[0] = {
  997. .cw_min = cpu_to_le16(3),
  998. .cw_max = cpu_to_le16(7),
  999. .aifsn = 2,
  1000. .edca_txop = cpu_to_le16(1504),
  1001. },
  1002. .ac[1] = {
  1003. .cw_min = cpu_to_le16(7),
  1004. .cw_max = cpu_to_le16(15),
  1005. .aifsn = 2,
  1006. .edca_txop = cpu_to_le16(3008),
  1007. },
  1008. .ac[2] = {
  1009. .cw_min = cpu_to_le16(15),
  1010. .cw_max = cpu_to_le16(1023),
  1011. .aifsn = 3,
  1012. },
  1013. .ac[3] = {
  1014. .cw_min = cpu_to_le16(15),
  1015. .cw_max = cpu_to_le16(1023),
  1016. .aifsn = 7,
  1017. },
  1018. },
  1019. };
  1020. ctx->is_active = true;
  1021. ctx->qos_data = default_qos_data;
  1022. ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
  1023. memcpy(ctx->staging.node_addr,
  1024. priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr,
  1025. ETH_ALEN);
  1026. memcpy(ctx->staging.bssid_addr,
  1027. priv->contexts[IWL_RXON_CTX_BSS].staging.node_addr,
  1028. ETH_ALEN);
  1029. err = iwlagn_commit_rxon(priv, ctx);
  1030. if (err)
  1031. goto out;
  1032. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK |
  1033. RXON_FILTER_PROMISC_MSK |
  1034. RXON_FILTER_CTL2HOST_MSK;
  1035. err = iwlagn_commit_rxon(priv, ctx);
  1036. if (err) {
  1037. iwlagn_disable_roc(priv);
  1038. goto out;
  1039. }
  1040. priv->hw_roc_setup = true;
  1041. }
  1042. err = iwl_scan_initiate(priv, ctx->vif, IWL_SCAN_ROC, channel->band);
  1043. if (err)
  1044. iwlagn_disable_roc(priv);
  1045. out:
  1046. mutex_unlock(&priv->mutex);
  1047. IWL_DEBUG_MAC80211(priv, "leave\n");
  1048. return err;
  1049. }
  1050. static int iwlagn_mac_cancel_remain_on_channel(struct ieee80211_hw *hw)
  1051. {
  1052. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1053. if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
  1054. return -EOPNOTSUPP;
  1055. IWL_DEBUG_MAC80211(priv, "enter\n");
  1056. mutex_lock(&priv->mutex);
  1057. iwl_scan_cancel_timeout(priv, priv->hw_roc_duration);
  1058. iwlagn_disable_roc(priv);
  1059. mutex_unlock(&priv->mutex);
  1060. IWL_DEBUG_MAC80211(priv, "leave\n");
  1061. return 0;
  1062. }
  1063. static void iwlagn_mac_rssi_callback(struct ieee80211_hw *hw,
  1064. struct ieee80211_vif *vif,
  1065. enum ieee80211_rssi_event rssi_event)
  1066. {
  1067. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1068. IWL_DEBUG_MAC80211(priv, "enter\n");
  1069. mutex_lock(&priv->mutex);
  1070. if (priv->cfg->bt_params &&
  1071. priv->cfg->bt_params->advanced_bt_coexist) {
  1072. if (rssi_event == RSSI_EVENT_LOW)
  1073. priv->bt_enable_pspoll = true;
  1074. else if (rssi_event == RSSI_EVENT_HIGH)
  1075. priv->bt_enable_pspoll = false;
  1076. iwlagn_send_advance_bt_config(priv);
  1077. } else {
  1078. IWL_DEBUG_MAC80211(priv, "Advanced BT coex disabled,"
  1079. "ignoring RSSI callback\n");
  1080. }
  1081. mutex_unlock(&priv->mutex);
  1082. IWL_DEBUG_MAC80211(priv, "leave\n");
  1083. }
  1084. static int iwlagn_mac_set_tim(struct ieee80211_hw *hw,
  1085. struct ieee80211_sta *sta, bool set)
  1086. {
  1087. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1088. queue_work(priv->workqueue, &priv->beacon_update);
  1089. return 0;
  1090. }
  1091. static int iwlagn_mac_conf_tx(struct ieee80211_hw *hw,
  1092. struct ieee80211_vif *vif, u16 queue,
  1093. const struct ieee80211_tx_queue_params *params)
  1094. {
  1095. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1096. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  1097. struct iwl_rxon_context *ctx = vif_priv->ctx;
  1098. int q;
  1099. if (WARN_ON(!ctx))
  1100. return -EINVAL;
  1101. IWL_DEBUG_MAC80211(priv, "enter\n");
  1102. if (!iwl_is_ready_rf(priv)) {
  1103. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  1104. return -EIO;
  1105. }
  1106. if (queue >= AC_NUM) {
  1107. IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
  1108. return 0;
  1109. }
  1110. q = AC_NUM - 1 - queue;
  1111. mutex_lock(&priv->mutex);
  1112. ctx->qos_data.def_qos_parm.ac[q].cw_min =
  1113. cpu_to_le16(params->cw_min);
  1114. ctx->qos_data.def_qos_parm.ac[q].cw_max =
  1115. cpu_to_le16(params->cw_max);
  1116. ctx->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
  1117. ctx->qos_data.def_qos_parm.ac[q].edca_txop =
  1118. cpu_to_le16((params->txop * 32));
  1119. ctx->qos_data.def_qos_parm.ac[q].reserved1 = 0;
  1120. mutex_unlock(&priv->mutex);
  1121. IWL_DEBUG_MAC80211(priv, "leave\n");
  1122. return 0;
  1123. }
  1124. static int iwlagn_mac_tx_last_beacon(struct ieee80211_hw *hw)
  1125. {
  1126. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1127. return priv->ibss_manager == IWL_IBSS_MANAGER;
  1128. }
  1129. static int iwl_set_mode(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  1130. {
  1131. iwl_connection_init_rx_config(priv, ctx);
  1132. iwlagn_set_rxon_chain(priv, ctx);
  1133. return iwlagn_commit_rxon(priv, ctx);
  1134. }
  1135. static int iwl_setup_interface(struct iwl_priv *priv,
  1136. struct iwl_rxon_context *ctx)
  1137. {
  1138. struct ieee80211_vif *vif = ctx->vif;
  1139. int err, ac;
  1140. lockdep_assert_held(&priv->mutex);
  1141. /*
  1142. * This variable will be correct only when there's just
  1143. * a single context, but all code using it is for hardware
  1144. * that supports only one context.
  1145. */
  1146. priv->iw_mode = vif->type;
  1147. ctx->is_active = true;
  1148. err = iwl_set_mode(priv, ctx);
  1149. if (err) {
  1150. if (!ctx->always_active)
  1151. ctx->is_active = false;
  1152. return err;
  1153. }
  1154. if (priv->cfg->bt_params && priv->cfg->bt_params->advanced_bt_coexist &&
  1155. vif->type == NL80211_IFTYPE_ADHOC) {
  1156. /*
  1157. * pretend to have high BT traffic as long as we
  1158. * are operating in IBSS mode, as this will cause
  1159. * the rate scaling etc. to behave as intended.
  1160. */
  1161. priv->bt_traffic_load = IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
  1162. }
  1163. /* set up queue mappings */
  1164. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  1165. vif->hw_queue[ac] = ctx->ac_to_queue[ac];
  1166. if (vif->type == NL80211_IFTYPE_AP)
  1167. vif->cab_queue = ctx->mcast_queue;
  1168. else
  1169. vif->cab_queue = IEEE80211_INVAL_HW_QUEUE;
  1170. return 0;
  1171. }
  1172. static int iwlagn_mac_add_interface(struct ieee80211_hw *hw,
  1173. struct ieee80211_vif *vif)
  1174. {
  1175. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1176. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  1177. struct iwl_rxon_context *tmp, *ctx = NULL;
  1178. int err;
  1179. enum nl80211_iftype viftype = ieee80211_vif_type_p2p(vif);
  1180. bool reset = false;
  1181. IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n",
  1182. viftype, vif->addr);
  1183. cancel_delayed_work_sync(&priv->hw_roc_disable_work);
  1184. mutex_lock(&priv->mutex);
  1185. iwlagn_disable_roc(priv);
  1186. if (!iwl_is_ready_rf(priv)) {
  1187. IWL_WARN(priv, "Try to add interface when device not ready\n");
  1188. err = -EINVAL;
  1189. goto out;
  1190. }
  1191. for_each_context(priv, tmp) {
  1192. u32 possible_modes =
  1193. tmp->interface_modes | tmp->exclusive_interface_modes;
  1194. if (tmp->vif) {
  1195. /* On reset we need to add the same interface again */
  1196. if (tmp->vif == vif) {
  1197. reset = true;
  1198. ctx = tmp;
  1199. break;
  1200. }
  1201. /* check if this busy context is exclusive */
  1202. if (tmp->exclusive_interface_modes &
  1203. BIT(tmp->vif->type)) {
  1204. err = -EINVAL;
  1205. goto out;
  1206. }
  1207. continue;
  1208. }
  1209. if (!(possible_modes & BIT(viftype)))
  1210. continue;
  1211. /* have maybe usable context w/o interface */
  1212. ctx = tmp;
  1213. break;
  1214. }
  1215. if (!ctx) {
  1216. err = -EOPNOTSUPP;
  1217. goto out;
  1218. }
  1219. vif_priv->ctx = ctx;
  1220. ctx->vif = vif;
  1221. /*
  1222. * In SNIFFER device type, the firmware reports the FCS to
  1223. * the host, rather than snipping it off. Unfortunately,
  1224. * mac80211 doesn't (yet) provide a per-packet flag for
  1225. * this, so that we have to set the hardware flag based
  1226. * on the interfaces added. As the monitor interface can
  1227. * only be present by itself, and will be removed before
  1228. * other interfaces are added, this is safe.
  1229. */
  1230. if (vif->type == NL80211_IFTYPE_MONITOR)
  1231. priv->hw->flags |= IEEE80211_HW_RX_INCLUDES_FCS;
  1232. else
  1233. priv->hw->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
  1234. err = iwl_setup_interface(priv, ctx);
  1235. if (!err || reset)
  1236. goto out;
  1237. ctx->vif = NULL;
  1238. priv->iw_mode = NL80211_IFTYPE_STATION;
  1239. out:
  1240. mutex_unlock(&priv->mutex);
  1241. IWL_DEBUG_MAC80211(priv, "leave\n");
  1242. return err;
  1243. }
  1244. static void iwl_teardown_interface(struct iwl_priv *priv,
  1245. struct ieee80211_vif *vif,
  1246. bool mode_change)
  1247. {
  1248. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1249. lockdep_assert_held(&priv->mutex);
  1250. if (priv->scan_vif == vif) {
  1251. iwl_scan_cancel_timeout(priv, 200);
  1252. iwl_force_scan_end(priv);
  1253. }
  1254. if (!mode_change) {
  1255. iwl_set_mode(priv, ctx);
  1256. if (!ctx->always_active)
  1257. ctx->is_active = false;
  1258. }
  1259. /*
  1260. * When removing the IBSS interface, overwrite the
  1261. * BT traffic load with the stored one from the last
  1262. * notification, if any. If this is a device that
  1263. * doesn't implement this, this has no effect since
  1264. * both values are the same and zero.
  1265. */
  1266. if (vif->type == NL80211_IFTYPE_ADHOC)
  1267. priv->bt_traffic_load = priv->last_bt_traffic_load;
  1268. }
  1269. static void iwlagn_mac_remove_interface(struct ieee80211_hw *hw,
  1270. struct ieee80211_vif *vif)
  1271. {
  1272. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1273. struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
  1274. IWL_DEBUG_MAC80211(priv, "enter\n");
  1275. mutex_lock(&priv->mutex);
  1276. if (WARN_ON(ctx->vif != vif)) {
  1277. struct iwl_rxon_context *tmp;
  1278. IWL_ERR(priv, "ctx->vif = %p, vif = %p\n", ctx->vif, vif);
  1279. for_each_context(priv, tmp)
  1280. IWL_ERR(priv, "\tID = %d:\tctx = %p\tctx->vif = %p\n",
  1281. tmp->ctxid, tmp, tmp->vif);
  1282. }
  1283. ctx->vif = NULL;
  1284. iwl_teardown_interface(priv, vif, false);
  1285. mutex_unlock(&priv->mutex);
  1286. IWL_DEBUG_MAC80211(priv, "leave\n");
  1287. }
  1288. static int iwlagn_mac_change_interface(struct ieee80211_hw *hw,
  1289. struct ieee80211_vif *vif,
  1290. enum nl80211_iftype newtype, bool newp2p)
  1291. {
  1292. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1293. struct iwl_rxon_context *ctx, *tmp;
  1294. enum nl80211_iftype newviftype = newtype;
  1295. u32 interface_modes;
  1296. int err;
  1297. IWL_DEBUG_MAC80211(priv, "enter\n");
  1298. newtype = ieee80211_iftype_p2p(newtype, newp2p);
  1299. mutex_lock(&priv->mutex);
  1300. ctx = iwl_rxon_ctx_from_vif(vif);
  1301. /*
  1302. * To simplify this code, only support changes on the
  1303. * BSS context. The PAN context is usually reassigned
  1304. * by creating/removing P2P interfaces anyway.
  1305. */
  1306. if (ctx->ctxid != IWL_RXON_CTX_BSS) {
  1307. err = -EBUSY;
  1308. goto out;
  1309. }
  1310. if (!ctx->vif || !iwl_is_ready_rf(priv)) {
  1311. /*
  1312. * Huh? But wait ... this can maybe happen when
  1313. * we're in the middle of a firmware restart!
  1314. */
  1315. err = -EBUSY;
  1316. goto out;
  1317. }
  1318. /* Check if the switch is supported in the same context */
  1319. interface_modes = ctx->interface_modes | ctx->exclusive_interface_modes;
  1320. if (!(interface_modes & BIT(newtype))) {
  1321. err = -EBUSY;
  1322. goto out;
  1323. }
  1324. if (ctx->exclusive_interface_modes & BIT(newtype)) {
  1325. for_each_context(priv, tmp) {
  1326. if (ctx == tmp)
  1327. continue;
  1328. if (!tmp->is_active)
  1329. continue;
  1330. /*
  1331. * The current mode switch would be exclusive, but
  1332. * another context is active ... refuse the switch.
  1333. */
  1334. err = -EBUSY;
  1335. goto out;
  1336. }
  1337. }
  1338. /* success */
  1339. iwl_teardown_interface(priv, vif, true);
  1340. vif->type = newviftype;
  1341. vif->p2p = newp2p;
  1342. err = iwl_setup_interface(priv, ctx);
  1343. WARN_ON(err);
  1344. /*
  1345. * We've switched internally, but submitting to the
  1346. * device may have failed for some reason. Mask this
  1347. * error, because otherwise mac80211 will not switch
  1348. * (and set the interface type back) and we'll be
  1349. * out of sync with it.
  1350. */
  1351. err = 0;
  1352. out:
  1353. mutex_unlock(&priv->mutex);
  1354. IWL_DEBUG_MAC80211(priv, "leave\n");
  1355. return err;
  1356. }
  1357. static int iwlagn_mac_hw_scan(struct ieee80211_hw *hw,
  1358. struct ieee80211_vif *vif,
  1359. struct cfg80211_scan_request *req)
  1360. {
  1361. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1362. int ret;
  1363. IWL_DEBUG_MAC80211(priv, "enter\n");
  1364. if (req->n_channels == 0)
  1365. return -EINVAL;
  1366. mutex_lock(&priv->mutex);
  1367. /*
  1368. * If an internal scan is in progress, just set
  1369. * up the scan_request as per above.
  1370. */
  1371. if (priv->scan_type != IWL_SCAN_NORMAL) {
  1372. IWL_DEBUG_SCAN(priv,
  1373. "SCAN request during internal scan - defer\n");
  1374. priv->scan_request = req;
  1375. priv->scan_vif = vif;
  1376. ret = 0;
  1377. } else {
  1378. priv->scan_request = req;
  1379. priv->scan_vif = vif;
  1380. /*
  1381. * mac80211 will only ask for one band at a time
  1382. * so using channels[0] here is ok
  1383. */
  1384. ret = iwl_scan_initiate(priv, vif, IWL_SCAN_NORMAL,
  1385. req->channels[0]->band);
  1386. if (ret) {
  1387. priv->scan_request = NULL;
  1388. priv->scan_vif = NULL;
  1389. }
  1390. }
  1391. IWL_DEBUG_MAC80211(priv, "leave\n");
  1392. mutex_unlock(&priv->mutex);
  1393. return ret;
  1394. }
  1395. static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
  1396. {
  1397. struct iwl_addsta_cmd cmd = {
  1398. .mode = STA_CONTROL_MODIFY_MSK,
  1399. .station_flags_msk = STA_FLG_PWR_SAVE_MSK,
  1400. .sta.sta_id = sta_id,
  1401. };
  1402. iwl_send_add_sta(priv, &cmd, CMD_ASYNC);
  1403. }
  1404. static void iwlagn_mac_sta_notify(struct ieee80211_hw *hw,
  1405. struct ieee80211_vif *vif,
  1406. enum sta_notify_cmd cmd,
  1407. struct ieee80211_sta *sta)
  1408. {
  1409. struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
  1410. struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
  1411. int sta_id;
  1412. IWL_DEBUG_MAC80211(priv, "enter\n");
  1413. switch (cmd) {
  1414. case STA_NOTIFY_SLEEP:
  1415. WARN_ON(!sta_priv->client);
  1416. sta_priv->asleep = true;
  1417. if (atomic_read(&sta_priv->pending_frames) > 0)
  1418. ieee80211_sta_block_awake(hw, sta, true);
  1419. break;
  1420. case STA_NOTIFY_AWAKE:
  1421. WARN_ON(!sta_priv->client);
  1422. if (!sta_priv->asleep)
  1423. break;
  1424. sta_priv->asleep = false;
  1425. sta_id = iwl_sta_id(sta);
  1426. if (sta_id != IWL_INVALID_STATION)
  1427. iwl_sta_modify_ps_wake(priv, sta_id);
  1428. break;
  1429. default:
  1430. break;
  1431. }
  1432. IWL_DEBUG_MAC80211(priv, "leave\n");
  1433. }
  1434. struct ieee80211_ops iwlagn_hw_ops = {
  1435. .tx = iwlagn_mac_tx,
  1436. .start = iwlagn_mac_start,
  1437. .stop = iwlagn_mac_stop,
  1438. #ifdef CONFIG_PM_SLEEP
  1439. .suspend = iwlagn_mac_suspend,
  1440. .resume = iwlagn_mac_resume,
  1441. .set_wakeup = iwlagn_mac_set_wakeup,
  1442. #endif
  1443. .add_interface = iwlagn_mac_add_interface,
  1444. .remove_interface = iwlagn_mac_remove_interface,
  1445. .change_interface = iwlagn_mac_change_interface,
  1446. .config = iwlagn_mac_config,
  1447. .configure_filter = iwlagn_configure_filter,
  1448. .set_key = iwlagn_mac_set_key,
  1449. .update_tkip_key = iwlagn_mac_update_tkip_key,
  1450. .set_rekey_data = iwlagn_mac_set_rekey_data,
  1451. .conf_tx = iwlagn_mac_conf_tx,
  1452. .bss_info_changed = iwlagn_bss_info_changed,
  1453. .ampdu_action = iwlagn_mac_ampdu_action,
  1454. .hw_scan = iwlagn_mac_hw_scan,
  1455. .sta_notify = iwlagn_mac_sta_notify,
  1456. .sta_state = iwlagn_mac_sta_state,
  1457. .channel_switch = iwlagn_mac_channel_switch,
  1458. .flush = iwlagn_mac_flush,
  1459. .tx_last_beacon = iwlagn_mac_tx_last_beacon,
  1460. .remain_on_channel = iwlagn_mac_remain_on_channel,
  1461. .cancel_remain_on_channel = iwlagn_mac_cancel_remain_on_channel,
  1462. .rssi_callback = iwlagn_mac_rssi_callback,
  1463. CFG80211_TESTMODE_CMD(iwlagn_mac_testmode_cmd)
  1464. CFG80211_TESTMODE_DUMP(iwlagn_mac_testmode_dump)
  1465. .set_tim = iwlagn_mac_set_tim,
  1466. };
  1467. /* This function both allocates and initializes hw and priv. */
  1468. struct ieee80211_hw *iwl_alloc_all(void)
  1469. {
  1470. struct iwl_priv *priv;
  1471. struct iwl_op_mode *op_mode;
  1472. /* mac80211 allocates memory for this device instance, including
  1473. * space for this driver's private structure */
  1474. struct ieee80211_hw *hw;
  1475. hw = ieee80211_alloc_hw(sizeof(struct iwl_priv) +
  1476. sizeof(struct iwl_op_mode), &iwlagn_hw_ops);
  1477. if (!hw)
  1478. goto out;
  1479. op_mode = hw->priv;
  1480. priv = IWL_OP_MODE_GET_DVM(op_mode);
  1481. priv->hw = hw;
  1482. out:
  1483. return hw;
  1484. }