iwl-mac80211.c 40 KB

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