mac80211.c 41 KB

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