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