mac80211.c 46 KB

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