sta.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Implementation of mac80211 API.
  4. *
  5. * Copyright (c) 2017-2020, Silicon Laboratories, Inc.
  6. * Copyright (c) 2010, ST-Ericsson
  7. */
  8. #include <linux/etherdevice.h>
  9. #include <net/mac80211.h>
  10. #include "sta.h"
  11. #include "wfx.h"
  12. #include "fwio.h"
  13. #include "bh.h"
  14. #include "key.h"
  15. #include "scan.h"
  16. #include "debug.h"
  17. #include "hif_tx.h"
  18. #include "hif_tx_mib.h"
  19. #define HIF_MAX_ARP_IP_ADDRTABLE_ENTRIES 2
  20. void wfx_cooling_timeout_work(struct work_struct *work)
  21. {
  22. struct wfx_dev *wdev = container_of(to_delayed_work(work), struct wfx_dev,
  23. cooling_timeout_work);
  24. wdev->chip_frozen = true;
  25. wfx_tx_unlock(wdev);
  26. }
  27. void wfx_suspend_hot_dev(struct wfx_dev *wdev, enum sta_notify_cmd cmd)
  28. {
  29. if (cmd == STA_NOTIFY_AWAKE) {
  30. /* Device recover normal temperature */
  31. if (cancel_delayed_work(&wdev->cooling_timeout_work))
  32. wfx_tx_unlock(wdev);
  33. } else {
  34. /* Device is too hot */
  35. schedule_delayed_work(&wdev->cooling_timeout_work, 10 * HZ);
  36. wfx_tx_lock(wdev);
  37. }
  38. }
  39. static void wfx_filter_beacon(struct wfx_vif *wvif, bool filter_beacon)
  40. {
  41. static const struct wfx_hif_ie_table_entry filter_ies[] = {
  42. {
  43. .ie_id = WLAN_EID_VENDOR_SPECIFIC,
  44. .has_changed = 1,
  45. .no_longer = 1,
  46. .has_appeared = 1,
  47. .oui = { 0x50, 0x6F, 0x9A },
  48. }, {
  49. .ie_id = WLAN_EID_HT_OPERATION,
  50. .has_changed = 1,
  51. .no_longer = 1,
  52. .has_appeared = 1,
  53. }, {
  54. .ie_id = WLAN_EID_ERP_INFO,
  55. .has_changed = 1,
  56. .no_longer = 1,
  57. .has_appeared = 1,
  58. }, {
  59. .ie_id = WLAN_EID_CHANNEL_SWITCH,
  60. .has_changed = 1,
  61. .no_longer = 1,
  62. .has_appeared = 1,
  63. }
  64. };
  65. if (!filter_beacon) {
  66. wfx_hif_beacon_filter_control(wvif, 0, 1);
  67. } else {
  68. wfx_hif_set_beacon_filter_table(wvif, ARRAY_SIZE(filter_ies), filter_ies);
  69. wfx_hif_beacon_filter_control(wvif, HIF_BEACON_FILTER_ENABLE, 0);
  70. }
  71. }
  72. void wfx_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
  73. unsigned int *total_flags, u64 unused)
  74. {
  75. bool filter_bssid, filter_prbreq, filter_beacon;
  76. struct ieee80211_vif *vif = NULL;
  77. struct wfx_dev *wdev = hw->priv;
  78. struct wfx_vif *wvif = NULL;
  79. /* Notes:
  80. * - Probe responses (FIF_BCN_PRBRESP_PROMISC) are never filtered
  81. * - PS-Poll (FIF_PSPOLL) are never filtered
  82. * - RTS, CTS and Ack (FIF_CONTROL) are always filtered
  83. * - Broken frames (FIF_FCSFAIL and FIF_PLCPFAIL) are always filtered
  84. * - Firmware does (yet) allow to forward unicast traffic sent to other stations (aka.
  85. * promiscuous mode)
  86. */
  87. *total_flags &= FIF_BCN_PRBRESP_PROMISC | FIF_ALLMULTI | FIF_OTHER_BSS |
  88. FIF_PROBE_REQ | FIF_PSPOLL;
  89. /* Filters are ignored during the scan. No frames are filtered. */
  90. if (mutex_is_locked(&wdev->scan_lock))
  91. return;
  92. mutex_lock(&wdev->conf_mutex);
  93. while ((wvif = wvif_iterate(wdev, wvif)) != NULL) {
  94. /* Note: FIF_BCN_PRBRESP_PROMISC covers probe response and
  95. * beacons from other BSS
  96. */
  97. if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
  98. filter_beacon = false;
  99. else
  100. filter_beacon = true;
  101. wfx_filter_beacon(wvif, filter_beacon);
  102. if (*total_flags & FIF_OTHER_BSS)
  103. filter_bssid = false;
  104. else
  105. filter_bssid = true;
  106. vif = wvif_to_vif(wvif);
  107. /* In AP mode, chip can reply to probe request itself */
  108. if (*total_flags & FIF_PROBE_REQ && vif->type == NL80211_IFTYPE_AP) {
  109. dev_dbg(wdev->dev, "do not forward probe request in AP mode\n");
  110. *total_flags &= ~FIF_PROBE_REQ;
  111. }
  112. if (*total_flags & FIF_PROBE_REQ)
  113. filter_prbreq = false;
  114. else
  115. filter_prbreq = true;
  116. wfx_hif_set_rx_filter(wvif, filter_bssid, filter_prbreq);
  117. }
  118. mutex_unlock(&wdev->conf_mutex);
  119. }
  120. static int wfx_get_ps_timeout(struct wfx_vif *wvif, bool *enable_ps)
  121. {
  122. struct ieee80211_channel *chan0 = NULL, *chan1 = NULL;
  123. struct ieee80211_conf *conf = &wvif->wdev->hw->conf;
  124. struct ieee80211_vif *vif = wvif_to_vif(wvif);
  125. WARN(!vif->cfg.assoc && enable_ps,
  126. "enable_ps is reliable only if associated");
  127. if (wdev_to_wvif(wvif->wdev, 0)) {
  128. struct wfx_vif *wvif_ch0 = wdev_to_wvif(wvif->wdev, 0);
  129. struct ieee80211_vif *vif_ch0 = wvif_to_vif(wvif_ch0);
  130. chan0 = vif_ch0->bss_conf.chanreq.oper.chan;
  131. }
  132. if (wdev_to_wvif(wvif->wdev, 1)) {
  133. struct wfx_vif *wvif_ch1 = wdev_to_wvif(wvif->wdev, 1);
  134. struct ieee80211_vif *vif_ch1 = wvif_to_vif(wvif_ch1);
  135. chan1 = vif_ch1->bss_conf.chanreq.oper.chan;
  136. }
  137. if (chan0 && chan1 && vif->type != NL80211_IFTYPE_AP) {
  138. if (chan0->hw_value == chan1->hw_value) {
  139. /* It is useless to enable PS if channels are the same. */
  140. if (enable_ps)
  141. *enable_ps = false;
  142. if (vif->cfg.assoc && vif->cfg.ps)
  143. dev_info(wvif->wdev->dev, "ignoring requested PS mode");
  144. return -1;
  145. }
  146. /* It is necessary to enable PS if channels are different. */
  147. if (enable_ps)
  148. *enable_ps = true;
  149. if (wfx_api_older_than(wvif->wdev, 3, 2))
  150. return 0;
  151. else
  152. return 30;
  153. }
  154. if (enable_ps)
  155. *enable_ps = vif->cfg.ps;
  156. if (vif->cfg.assoc && vif->cfg.ps)
  157. return conf->dynamic_ps_timeout;
  158. else
  159. return -1;
  160. }
  161. int wfx_update_pm(struct wfx_vif *wvif)
  162. {
  163. struct ieee80211_vif *vif = wvif_to_vif(wvif);
  164. int ps_timeout;
  165. bool ps;
  166. if (!vif->cfg.assoc)
  167. return 0;
  168. ps_timeout = wfx_get_ps_timeout(wvif, &ps);
  169. if (!ps)
  170. ps_timeout = 0;
  171. WARN_ON(ps_timeout < 0);
  172. if (wvif->uapsd_mask)
  173. ps_timeout = 0;
  174. if (!wait_for_completion_timeout(&wvif->set_pm_mode_complete, TU_TO_JIFFIES(512)))
  175. dev_warn(wvif->wdev->dev, "timeout while waiting of set_pm_mode_complete\n");
  176. return wfx_hif_set_pm(wvif, ps, ps_timeout);
  177. }
  178. int wfx_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  179. unsigned int link_id, u16 queue,
  180. const struct ieee80211_tx_queue_params *params)
  181. {
  182. struct wfx_dev *wdev = hw->priv;
  183. struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
  184. int old_uapsd = wvif->uapsd_mask;
  185. WARN_ON(queue >= hw->queues);
  186. mutex_lock(&wdev->conf_mutex);
  187. assign_bit(queue, &wvif->uapsd_mask, params->uapsd);
  188. wfx_hif_set_edca_queue_params(wvif, queue, params);
  189. if (vif->type == NL80211_IFTYPE_STATION &&
  190. old_uapsd != wvif->uapsd_mask) {
  191. wfx_hif_set_uapsd_info(wvif, wvif->uapsd_mask);
  192. wfx_update_pm(wvif);
  193. }
  194. mutex_unlock(&wdev->conf_mutex);
  195. return 0;
  196. }
  197. int wfx_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  198. {
  199. struct wfx_dev *wdev = hw->priv;
  200. struct wfx_vif *wvif = NULL;
  201. while ((wvif = wvif_iterate(wdev, wvif)) != NULL)
  202. wfx_hif_rts_threshold(wvif, value);
  203. return 0;
  204. }
  205. void wfx_event_report_rssi(struct wfx_vif *wvif, u8 raw_rcpi_rssi)
  206. {
  207. /* RSSI: signed Q8.0, RCPI: unsigned Q7.1
  208. * RSSI = RCPI / 2 - 110
  209. */
  210. struct ieee80211_vif *vif = wvif_to_vif(wvif);
  211. int rcpi_rssi;
  212. int cqm_evt;
  213. rcpi_rssi = raw_rcpi_rssi / 2 - 110;
  214. if (rcpi_rssi <= vif->bss_conf.cqm_rssi_thold)
  215. cqm_evt = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
  216. else
  217. cqm_evt = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
  218. ieee80211_cqm_rssi_notify(vif, cqm_evt, rcpi_rssi, GFP_KERNEL);
  219. }
  220. static void wfx_beacon_loss_work(struct work_struct *work)
  221. {
  222. struct wfx_vif *wvif = container_of(to_delayed_work(work), struct wfx_vif,
  223. beacon_loss_work);
  224. struct ieee80211_vif *vif = wvif_to_vif(wvif);
  225. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  226. ieee80211_beacon_loss(vif);
  227. schedule_delayed_work(to_delayed_work(work), msecs_to_jiffies(bss_conf->beacon_int));
  228. }
  229. void wfx_set_default_unicast_key(struct ieee80211_hw *hw, struct ieee80211_vif *vif, int idx)
  230. {
  231. struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
  232. wfx_hif_wep_default_key_id(wvif, idx);
  233. }
  234. void wfx_reset(struct wfx_vif *wvif)
  235. {
  236. struct wfx_dev *wdev = wvif->wdev;
  237. wfx_tx_lock_flush(wdev);
  238. wfx_hif_reset(wvif, false);
  239. wfx_tx_policy_init(wvif);
  240. if (wvif_count(wdev) <= 1)
  241. wfx_hif_set_block_ack_policy(wvif, 0xFF, 0xFF);
  242. wfx_tx_unlock(wdev);
  243. wvif->join_in_progress = false;
  244. cancel_delayed_work_sync(&wvif->beacon_loss_work);
  245. wvif = NULL;
  246. while ((wvif = wvif_iterate(wdev, wvif)) != NULL)
  247. wfx_update_pm(wvif);
  248. }
  249. int wfx_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_sta *sta)
  250. {
  251. struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
  252. struct wfx_sta_priv *sta_priv = (struct wfx_sta_priv *)&sta->drv_priv;
  253. sta_priv->vif_id = wvif->id;
  254. if (vif->type == NL80211_IFTYPE_STATION)
  255. wfx_hif_set_mfp(wvif, sta->mfp, sta->mfp);
  256. /* In station mode, the firmware interprets new link-id as a TDLS peer */
  257. if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
  258. return 0;
  259. sta_priv->link_id = ffz(wvif->link_id_map);
  260. wvif->link_id_map |= BIT(sta_priv->link_id);
  261. WARN_ON(!sta_priv->link_id);
  262. WARN_ON(sta_priv->link_id >= HIF_LINK_ID_MAX);
  263. wfx_hif_map_link(wvif, false, sta->addr, sta_priv->link_id, sta->mfp);
  264. return 0;
  265. }
  266. int wfx_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_sta *sta)
  267. {
  268. struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
  269. struct wfx_sta_priv *sta_priv = (struct wfx_sta_priv *)&sta->drv_priv;
  270. /* See note in wfx_sta_add() */
  271. if (!sta_priv->link_id)
  272. return 0;
  273. /* FIXME add a mutex? */
  274. wfx_hif_map_link(wvif, true, sta->addr, sta_priv->link_id, false);
  275. wvif->link_id_map &= ~BIT(sta_priv->link_id);
  276. return 0;
  277. }
  278. static int wfx_upload_ap_templates(struct wfx_vif *wvif)
  279. {
  280. struct ieee80211_vif *vif = wvif_to_vif(wvif);
  281. struct sk_buff *skb;
  282. skb = ieee80211_beacon_get(wvif->wdev->hw, vif, 0);
  283. if (!skb)
  284. return -ENOMEM;
  285. wfx_hif_set_template_frame(wvif, skb, HIF_TMPLT_BCN, API_RATE_INDEX_B_1MBPS);
  286. dev_kfree_skb(skb);
  287. skb = ieee80211_proberesp_get(wvif->wdev->hw, vif);
  288. if (!skb)
  289. return -ENOMEM;
  290. wfx_hif_set_template_frame(wvif, skb, HIF_TMPLT_PRBRES, API_RATE_INDEX_B_1MBPS);
  291. dev_kfree_skb(skb);
  292. return 0;
  293. }
  294. static int wfx_set_mfp_ap(struct wfx_vif *wvif)
  295. {
  296. struct ieee80211_vif *vif = wvif_to_vif(wvif);
  297. struct sk_buff *skb = ieee80211_beacon_get(wvif->wdev->hw, vif, 0);
  298. const int ieoffset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
  299. const int pairwise_cipher_suite_count_offset = 8 / sizeof(u16);
  300. const int pairwise_cipher_suite_size = 4 / sizeof(u16);
  301. const int akm_suite_size = 4 / sizeof(u16);
  302. int ret = -EINVAL;
  303. const u16 *ptr;
  304. if (unlikely(!skb))
  305. return -ENOMEM;
  306. ptr = (u16 *)cfg80211_find_ie(WLAN_EID_RSN, skb->data + ieoffset,
  307. skb->len - ieoffset);
  308. if (!ptr) {
  309. /* No RSN IE is fine in open networks */
  310. ret = 0;
  311. goto free_skb;
  312. }
  313. ptr += pairwise_cipher_suite_count_offset;
  314. if (WARN_ON(ptr > (u16 *)skb_tail_pointer(skb)))
  315. goto free_skb;
  316. ptr += 1 + pairwise_cipher_suite_size * *ptr;
  317. if (WARN_ON(ptr > (u16 *)skb_tail_pointer(skb)))
  318. goto free_skb;
  319. ptr += 1 + akm_suite_size * *ptr;
  320. if (WARN_ON(ptr > (u16 *)skb_tail_pointer(skb)))
  321. goto free_skb;
  322. wfx_hif_set_mfp(wvif, *ptr & BIT(7), *ptr & BIT(6));
  323. ret = 0;
  324. free_skb:
  325. dev_kfree_skb(skb);
  326. return ret;
  327. }
  328. int wfx_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  329. struct ieee80211_bss_conf *link_conf)
  330. {
  331. struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
  332. struct wfx_dev *wdev = wvif->wdev;
  333. int ret;
  334. wvif = NULL;
  335. while ((wvif = wvif_iterate(wdev, wvif)) != NULL)
  336. wfx_update_pm(wvif);
  337. wvif = (struct wfx_vif *)vif->drv_priv;
  338. wfx_upload_ap_templates(wvif);
  339. ret = wfx_hif_start(wvif, &vif->bss_conf, wvif->channel);
  340. if (ret > 0)
  341. return -EIO;
  342. return wfx_set_mfp_ap(wvif);
  343. }
  344. void wfx_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  345. struct ieee80211_bss_conf *link_conf)
  346. {
  347. struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
  348. struct wfx_dev *wdev = wvif->wdev;
  349. wvif = NULL;
  350. while ((wvif = wvif_iterate(wdev, wvif)) != NULL)
  351. wfx_update_pm(wvif);
  352. wvif = (struct wfx_vif *)vif->drv_priv;
  353. wfx_reset(wvif);
  354. }
  355. static void wfx_join(struct wfx_vif *wvif)
  356. {
  357. struct ieee80211_vif *vif = wvif_to_vif(wvif);
  358. struct ieee80211_bss_conf *conf = &vif->bss_conf;
  359. struct cfg80211_bss *bss = NULL;
  360. u8 ssid[IEEE80211_MAX_SSID_LEN];
  361. const u8 *ssid_ie = NULL;
  362. int ssid_len = 0;
  363. int ret;
  364. wfx_tx_lock_flush(wvif->wdev);
  365. bss = cfg80211_get_bss(wvif->wdev->hw->wiphy, wvif->channel, conf->bssid, NULL, 0,
  366. IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
  367. if (!bss && !vif->cfg.ibss_joined) {
  368. wfx_tx_unlock(wvif->wdev);
  369. return;
  370. }
  371. rcu_read_lock(); /* protect ssid_ie */
  372. if (bss)
  373. ssid_ie = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
  374. if (ssid_ie) {
  375. ssid_len = ssid_ie[1];
  376. if (ssid_len > IEEE80211_MAX_SSID_LEN)
  377. ssid_len = IEEE80211_MAX_SSID_LEN;
  378. memcpy(ssid, &ssid_ie[2], ssid_len);
  379. }
  380. rcu_read_unlock();
  381. cfg80211_put_bss(wvif->wdev->hw->wiphy, bss);
  382. wvif->join_in_progress = true;
  383. ret = wfx_hif_join(wvif, conf, wvif->channel, ssid, ssid_len);
  384. if (ret) {
  385. ieee80211_connection_loss(vif);
  386. wfx_reset(wvif);
  387. } else {
  388. /* Due to beacon filtering it is possible that the AP's beacon is not known for the
  389. * mac80211 stack. Disable filtering temporary to make sure the stack receives at
  390. * least one
  391. */
  392. wfx_filter_beacon(wvif, false);
  393. }
  394. wfx_tx_unlock(wvif->wdev);
  395. }
  396. static void wfx_join_finalize(struct wfx_vif *wvif, struct ieee80211_bss_conf *info)
  397. {
  398. struct ieee80211_vif *vif = wvif_to_vif(wvif);
  399. struct ieee80211_sta *sta = NULL;
  400. int ampdu_density = 0;
  401. bool greenfield = false;
  402. rcu_read_lock(); /* protect sta */
  403. if (info->bssid && !vif->cfg.ibss_joined)
  404. sta = ieee80211_find_sta(vif, info->bssid);
  405. if (sta && sta->deflink.ht_cap.ht_supported)
  406. ampdu_density = sta->deflink.ht_cap.ampdu_density;
  407. if (sta && sta->deflink.ht_cap.ht_supported &&
  408. !(info->ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT))
  409. greenfield = !!(sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_GRN_FLD);
  410. rcu_read_unlock();
  411. wvif->join_in_progress = false;
  412. wfx_hif_set_association_mode(wvif, ampdu_density, greenfield, info->use_short_preamble);
  413. wfx_hif_keep_alive_period(wvif, 0);
  414. /* beacon_loss_count is defined to 7 in net/mac80211/mlme.c. Let's use the same value. */
  415. wfx_hif_set_bss_params(wvif, vif->cfg.aid, 7);
  416. wfx_hif_set_beacon_wakeup_period(wvif, 1, 1);
  417. wfx_update_pm(wvif);
  418. }
  419. int wfx_join_ibss(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  420. {
  421. struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
  422. wfx_upload_ap_templates(wvif);
  423. wfx_join(wvif);
  424. return 0;
  425. }
  426. void wfx_leave_ibss(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  427. {
  428. struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
  429. wfx_reset(wvif);
  430. }
  431. static void wfx_enable_beacon(struct wfx_vif *wvif, bool enable)
  432. {
  433. /* Driver has Content After DTIM Beacon in queue. Driver is waiting for a signal from the
  434. * firmware. Since we are going to stop to send beacons, this signal will never happens. See
  435. * also wfx_suspend_resume_mc()
  436. */
  437. if (!enable && wfx_tx_queues_has_cab(wvif)) {
  438. wvif->after_dtim_tx_allowed = true;
  439. wfx_bh_request_tx(wvif->wdev);
  440. }
  441. wfx_hif_beacon_transmit(wvif, enable);
  442. }
  443. void wfx_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  444. struct ieee80211_bss_conf *info, u64 changed)
  445. {
  446. struct wfx_dev *wdev = hw->priv;
  447. struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
  448. int i;
  449. mutex_lock(&wdev->conf_mutex);
  450. if (changed & BSS_CHANGED_BASIC_RATES ||
  451. changed & BSS_CHANGED_BEACON_INT ||
  452. changed & BSS_CHANGED_BSSID) {
  453. if (vif->type == NL80211_IFTYPE_STATION)
  454. wfx_join(wvif);
  455. }
  456. if (changed & BSS_CHANGED_ASSOC) {
  457. if (vif->cfg.assoc || vif->cfg.ibss_joined)
  458. wfx_join_finalize(wvif, info);
  459. else if (!vif->cfg.assoc && vif->type == NL80211_IFTYPE_STATION)
  460. wfx_reset(wvif);
  461. else
  462. dev_warn(wdev->dev, "misunderstood change: ASSOC\n");
  463. }
  464. if (changed & BSS_CHANGED_BEACON_INFO) {
  465. if (vif->type != NL80211_IFTYPE_STATION)
  466. dev_warn(wdev->dev, "misunderstood change: BEACON_INFO\n");
  467. wfx_hif_set_beacon_wakeup_period(wvif, info->dtim_period, info->dtim_period);
  468. /* We temporary forwarded beacon for join process. It is now no more necessary. */
  469. wfx_filter_beacon(wvif, true);
  470. }
  471. if (changed & BSS_CHANGED_ARP_FILTER) {
  472. for (i = 0; i < HIF_MAX_ARP_IP_ADDRTABLE_ENTRIES; i++) {
  473. __be32 *arp_addr = &vif->cfg.arp_addr_list[i];
  474. if (vif->cfg.arp_addr_cnt > HIF_MAX_ARP_IP_ADDRTABLE_ENTRIES)
  475. arp_addr = NULL;
  476. if (i >= vif->cfg.arp_addr_cnt)
  477. arp_addr = NULL;
  478. wfx_hif_set_arp_ipv4_filter(wvif, i, arp_addr);
  479. }
  480. }
  481. if (changed & BSS_CHANGED_AP_PROBE_RESP || changed & BSS_CHANGED_BEACON)
  482. wfx_upload_ap_templates(wvif);
  483. if (changed & BSS_CHANGED_BEACON_ENABLED)
  484. wfx_enable_beacon(wvif, info->enable_beacon);
  485. if (changed & BSS_CHANGED_KEEP_ALIVE)
  486. wfx_hif_keep_alive_period(wvif,
  487. info->max_idle_period * USEC_PER_TU / USEC_PER_MSEC);
  488. if (changed & BSS_CHANGED_ERP_CTS_PROT)
  489. wfx_hif_erp_use_protection(wvif, info->use_cts_prot);
  490. if (changed & BSS_CHANGED_ERP_SLOT)
  491. wfx_hif_slot_time(wvif, info->use_short_slot ? 9 : 20);
  492. if (changed & BSS_CHANGED_CQM)
  493. wfx_hif_set_rcpi_rssi_threshold(wvif, info->cqm_rssi_thold, info->cqm_rssi_hyst);
  494. if (changed & BSS_CHANGED_TXPOWER)
  495. wfx_hif_set_output_power(wvif, info->txpower);
  496. if (changed & BSS_CHANGED_PS)
  497. wfx_update_pm(wvif);
  498. mutex_unlock(&wdev->conf_mutex);
  499. }
  500. static int wfx_update_tim(struct wfx_vif *wvif)
  501. {
  502. struct ieee80211_vif *vif = wvif_to_vif(wvif);
  503. struct sk_buff *skb;
  504. u16 tim_offset, tim_length;
  505. u8 *tim_ptr;
  506. skb = ieee80211_beacon_get_tim(wvif->wdev->hw, vif, &tim_offset,
  507. &tim_length, 0);
  508. if (!skb)
  509. return -ENOENT;
  510. tim_ptr = skb->data + tim_offset;
  511. if (tim_offset && tim_length >= 6) {
  512. /* Firmware handles DTIM counter internally */
  513. tim_ptr[2] = 0;
  514. /* Set/reset aid0 bit */
  515. if (wfx_tx_queues_has_cab(wvif))
  516. tim_ptr[4] |= 1;
  517. else
  518. tim_ptr[4] &= ~1;
  519. }
  520. wfx_hif_update_ie_beacon(wvif, tim_ptr, tim_length);
  521. dev_kfree_skb(skb);
  522. return 0;
  523. }
  524. static void wfx_update_tim_work(struct work_struct *work)
  525. {
  526. struct wfx_vif *wvif = container_of(work, struct wfx_vif, update_tim_work);
  527. wfx_update_tim(wvif);
  528. }
  529. int wfx_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
  530. {
  531. struct wfx_dev *wdev = hw->priv;
  532. struct wfx_sta_priv *sta_dev = (struct wfx_sta_priv *)&sta->drv_priv;
  533. struct wfx_vif *wvif = wdev_to_wvif(wdev, sta_dev->vif_id);
  534. if (!wvif) {
  535. dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__);
  536. return -EIO;
  537. }
  538. schedule_work(&wvif->update_tim_work);
  539. return 0;
  540. }
  541. void wfx_suspend_resume_mc(struct wfx_vif *wvif, enum sta_notify_cmd notify_cmd)
  542. {
  543. if (notify_cmd != STA_NOTIFY_AWAKE)
  544. return;
  545. /* Device won't be able to honor CAB if a scan is in progress on any interface. Prefer to
  546. * skip this DTIM and wait for the next one.
  547. */
  548. if (mutex_is_locked(&wvif->wdev->scan_lock))
  549. return;
  550. if (!wfx_tx_queues_has_cab(wvif) || wvif->after_dtim_tx_allowed)
  551. dev_warn(wvif->wdev->dev, "incorrect sequence (%d CAB in queue)",
  552. wfx_tx_queues_has_cab(wvif));
  553. wvif->after_dtim_tx_allowed = true;
  554. wfx_bh_request_tx(wvif->wdev);
  555. }
  556. int wfx_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  557. struct ieee80211_ampdu_params *params)
  558. {
  559. /* Aggregation is implemented fully in firmware */
  560. switch (params->action) {
  561. case IEEE80211_AMPDU_RX_START:
  562. case IEEE80211_AMPDU_RX_STOP:
  563. /* Just acknowledge it to enable frame re-ordering */
  564. return 0;
  565. default:
  566. /* Leave the firmware doing its business for tx aggregation */
  567. return -EOPNOTSUPP;
  568. }
  569. }
  570. int wfx_add_chanctx(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *conf)
  571. {
  572. return 0;
  573. }
  574. void wfx_remove_chanctx(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *conf)
  575. {
  576. }
  577. void wfx_change_chanctx(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *conf, u32 changed)
  578. {
  579. }
  580. int wfx_assign_vif_chanctx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  581. struct ieee80211_bss_conf *link_conf,
  582. struct ieee80211_chanctx_conf *conf)
  583. {
  584. struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
  585. struct ieee80211_channel *ch = conf->def.chan;
  586. WARN(wvif->channel, "channel overwrite");
  587. wvif->channel = ch;
  588. return 0;
  589. }
  590. void wfx_unassign_vif_chanctx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  591. struct ieee80211_bss_conf *link_conf,
  592. struct ieee80211_chanctx_conf *conf)
  593. {
  594. struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
  595. struct ieee80211_channel *ch = conf->def.chan;
  596. WARN(wvif->channel != ch, "channel mismatch");
  597. wvif->channel = NULL;
  598. }
  599. int wfx_config(struct ieee80211_hw *hw, u32 changed)
  600. {
  601. return 0;
  602. }
  603. int wfx_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  604. {
  605. int i;
  606. struct wfx_dev *wdev = hw->priv;
  607. struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
  608. vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
  609. IEEE80211_VIF_SUPPORTS_UAPSD |
  610. IEEE80211_VIF_SUPPORTS_CQM_RSSI;
  611. mutex_lock(&wdev->conf_mutex);
  612. switch (vif->type) {
  613. case NL80211_IFTYPE_STATION:
  614. case NL80211_IFTYPE_ADHOC:
  615. case NL80211_IFTYPE_AP:
  616. break;
  617. default:
  618. mutex_unlock(&wdev->conf_mutex);
  619. return -EOPNOTSUPP;
  620. }
  621. wvif->wdev = wdev;
  622. wvif->link_id_map = 1; /* link-id 0 is reserved for multicast */
  623. INIT_WORK(&wvif->update_tim_work, wfx_update_tim_work);
  624. INIT_DELAYED_WORK(&wvif->beacon_loss_work, wfx_beacon_loss_work);
  625. init_completion(&wvif->set_pm_mode_complete);
  626. complete(&wvif->set_pm_mode_complete);
  627. INIT_WORK(&wvif->tx_policy_upload_work, wfx_tx_policy_upload_work);
  628. init_completion(&wvif->scan_complete);
  629. INIT_WORK(&wvif->scan_work, wfx_hw_scan_work);
  630. INIT_WORK(&wvif->remain_on_channel_work, wfx_remain_on_channel_work);
  631. wfx_tx_queues_init(wvif);
  632. wfx_tx_policy_init(wvif);
  633. for (i = 0; i < ARRAY_SIZE(wdev->vif); i++) {
  634. if (!wdev->vif[i]) {
  635. wdev->vif[i] = vif;
  636. wvif->id = i;
  637. break;
  638. }
  639. }
  640. WARN(i == ARRAY_SIZE(wdev->vif), "try to instantiate more vif than supported");
  641. wfx_hif_set_macaddr(wvif, vif->addr);
  642. mutex_unlock(&wdev->conf_mutex);
  643. wvif = NULL;
  644. while ((wvif = wvif_iterate(wdev, wvif)) != NULL) {
  645. /* Combo mode does not support Block Acks. We can re-enable them */
  646. if (wvif_count(wdev) == 1)
  647. wfx_hif_set_block_ack_policy(wvif, 0xFF, 0xFF);
  648. else
  649. wfx_hif_set_block_ack_policy(wvif, 0x00, 0x00);
  650. }
  651. return 0;
  652. }
  653. void wfx_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  654. {
  655. struct wfx_dev *wdev = hw->priv;
  656. struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
  657. wait_for_completion_timeout(&wvif->set_pm_mode_complete, msecs_to_jiffies(300));
  658. wfx_tx_queues_check_empty(wvif);
  659. mutex_lock(&wdev->conf_mutex);
  660. WARN(wvif->link_id_map != 1, "corrupted state");
  661. wfx_hif_reset(wvif, false);
  662. wfx_hif_set_macaddr(wvif, NULL);
  663. wfx_tx_policy_init(wvif);
  664. cancel_delayed_work_sync(&wvif->beacon_loss_work);
  665. wdev->vif[wvif->id] = NULL;
  666. mutex_unlock(&wdev->conf_mutex);
  667. wvif = NULL;
  668. while ((wvif = wvif_iterate(wdev, wvif)) != NULL) {
  669. /* Combo mode does not support Block Acks. We can re-enable them */
  670. if (wvif_count(wdev) == 1)
  671. wfx_hif_set_block_ack_policy(wvif, 0xFF, 0xFF);
  672. else
  673. wfx_hif_set_block_ack_policy(wvif, 0x00, 0x00);
  674. }
  675. }
  676. int wfx_start(struct ieee80211_hw *hw)
  677. {
  678. return 0;
  679. }
  680. void wfx_stop(struct ieee80211_hw *hw, bool suspend)
  681. {
  682. struct wfx_dev *wdev = hw->priv;
  683. WARN_ON(!skb_queue_empty_lockless(&wdev->tx_pending));
  684. }