iwl-mac80211.c 41 KB

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