mac80211.c 43 KB

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