sta.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  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. u32 wfx_rate_mask_to_hw(struct wfx_dev *wdev, u32 rates)
  21. {
  22. int i;
  23. u32 ret = 0;
  24. /* The device only supports 2GHz */
  25. struct ieee80211_supported_band *sband = wdev->hw->wiphy->bands[NL80211_BAND_2GHZ];
  26. for (i = 0; i < sband->n_bitrates; i++) {
  27. if (rates & BIT(i)) {
  28. if (i >= sband->n_bitrates)
  29. dev_warn(wdev->dev, "unsupported basic rate\n");
  30. else
  31. ret |= BIT(sband->bitrates[i].hw_value);
  32. }
  33. }
  34. return ret;
  35. }
  36. void wfx_cooling_timeout_work(struct work_struct *work)
  37. {
  38. struct wfx_dev *wdev = container_of(to_delayed_work(work), struct wfx_dev,
  39. cooling_timeout_work);
  40. wdev->chip_frozen = true;
  41. wfx_tx_unlock(wdev);
  42. }
  43. void wfx_suspend_hot_dev(struct wfx_dev *wdev, enum sta_notify_cmd cmd)
  44. {
  45. if (cmd == STA_NOTIFY_AWAKE) {
  46. /* Device recover normal temperature */
  47. if (cancel_delayed_work(&wdev->cooling_timeout_work))
  48. wfx_tx_unlock(wdev);
  49. } else {
  50. /* Device is too hot */
  51. schedule_delayed_work(&wdev->cooling_timeout_work, 10 * HZ);
  52. wfx_tx_lock(wdev);
  53. }
  54. }
  55. static void wfx_filter_beacon(struct wfx_vif *wvif, bool filter_beacon)
  56. {
  57. static const struct wfx_hif_ie_table_entry filter_ies[] = {
  58. {
  59. .ie_id = WLAN_EID_VENDOR_SPECIFIC,
  60. .has_changed = 1,
  61. .no_longer = 1,
  62. .has_appeared = 1,
  63. .oui = { 0x50, 0x6F, 0x9A },
  64. }, {
  65. .ie_id = WLAN_EID_HT_OPERATION,
  66. .has_changed = 1,
  67. .no_longer = 1,
  68. .has_appeared = 1,
  69. }, {
  70. .ie_id = WLAN_EID_ERP_INFO,
  71. .has_changed = 1,
  72. .no_longer = 1,
  73. .has_appeared = 1,
  74. }, {
  75. .ie_id = WLAN_EID_CHANNEL_SWITCH,
  76. .has_changed = 1,
  77. .no_longer = 1,
  78. .has_appeared = 1,
  79. }
  80. };
  81. if (!filter_beacon) {
  82. wfx_hif_beacon_filter_control(wvif, 0, 1);
  83. } else {
  84. wfx_hif_set_beacon_filter_table(wvif, ARRAY_SIZE(filter_ies), filter_ies);
  85. wfx_hif_beacon_filter_control(wvif, HIF_BEACON_FILTER_ENABLE, 0);
  86. }
  87. }
  88. void wfx_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
  89. unsigned int *total_flags, u64 unused)
  90. {
  91. bool filter_bssid, filter_prbreq, filter_beacon;
  92. struct ieee80211_vif *vif = NULL;
  93. struct wfx_dev *wdev = hw->priv;
  94. struct wfx_vif *wvif = NULL;
  95. /* Notes:
  96. * - Probe responses (FIF_BCN_PRBRESP_PROMISC) are never filtered
  97. * - PS-Poll (FIF_PSPOLL) are never filtered
  98. * - RTS, CTS and Ack (FIF_CONTROL) are always filtered
  99. * - Broken frames (FIF_FCSFAIL and FIF_PLCPFAIL) are always filtered
  100. * - Firmware does (yet) allow to forward unicast traffic sent to other stations (aka.
  101. * promiscuous mode)
  102. */
  103. *total_flags &= FIF_BCN_PRBRESP_PROMISC | FIF_ALLMULTI | FIF_OTHER_BSS |
  104. FIF_PROBE_REQ | FIF_PSPOLL;
  105. mutex_lock(&wdev->conf_mutex);
  106. while ((wvif = wvif_iterate(wdev, wvif)) != NULL) {
  107. mutex_lock(&wvif->scan_lock);
  108. /* Note: FIF_BCN_PRBRESP_PROMISC covers probe response and
  109. * beacons from other BSS
  110. */
  111. if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
  112. filter_beacon = false;
  113. else
  114. filter_beacon = true;
  115. wfx_filter_beacon(wvif, filter_beacon);
  116. if (*total_flags & FIF_OTHER_BSS)
  117. filter_bssid = false;
  118. else
  119. filter_bssid = true;
  120. vif = wvif_to_vif(wvif);
  121. /* In AP mode, chip can reply to probe request itself */
  122. if (*total_flags & FIF_PROBE_REQ && vif->type == NL80211_IFTYPE_AP) {
  123. dev_dbg(wdev->dev, "do not forward probe request in AP mode\n");
  124. *total_flags &= ~FIF_PROBE_REQ;
  125. }
  126. if (*total_flags & FIF_PROBE_REQ)
  127. filter_prbreq = false;
  128. else
  129. filter_prbreq = true;
  130. wfx_hif_set_rx_filter(wvif, filter_bssid, filter_prbreq);
  131. mutex_unlock(&wvif->scan_lock);
  132. }
  133. mutex_unlock(&wdev->conf_mutex);
  134. }
  135. static int wfx_get_ps_timeout(struct wfx_vif *wvif, bool *enable_ps)
  136. {
  137. struct ieee80211_channel *chan0 = NULL, *chan1 = NULL;
  138. struct ieee80211_conf *conf = &wvif->wdev->hw->conf;
  139. struct ieee80211_vif *vif = wvif_to_vif(wvif);
  140. WARN(!vif->cfg.assoc && enable_ps,
  141. "enable_ps is reliable only if associated");
  142. if (wdev_to_wvif(wvif->wdev, 0)) {
  143. struct wfx_vif *wvif_ch0 = wdev_to_wvif(wvif->wdev, 0);
  144. struct ieee80211_vif *vif_ch0 = wvif_to_vif(wvif_ch0);
  145. chan0 = vif_ch0->bss_conf.chandef.chan;
  146. }
  147. if (wdev_to_wvif(wvif->wdev, 1)) {
  148. struct wfx_vif *wvif_ch1 = wdev_to_wvif(wvif->wdev, 1);
  149. struct ieee80211_vif *vif_ch1 = wvif_to_vif(wvif_ch1);
  150. chan1 = vif_ch1->bss_conf.chandef.chan;
  151. }
  152. if (chan0 && chan1 && vif->type != NL80211_IFTYPE_AP) {
  153. if (chan0->hw_value == chan1->hw_value) {
  154. /* It is useless to enable PS if channels are the same. */
  155. if (enable_ps)
  156. *enable_ps = false;
  157. if (vif->cfg.assoc && vif->cfg.ps)
  158. dev_info(wvif->wdev->dev, "ignoring requested PS mode");
  159. return -1;
  160. }
  161. /* It is necessary to enable PS if channels are different. */
  162. if (enable_ps)
  163. *enable_ps = true;
  164. if (wfx_api_older_than(wvif->wdev, 3, 2))
  165. return 0;
  166. else
  167. return 30;
  168. }
  169. if (enable_ps)
  170. *enable_ps = vif->cfg.ps;
  171. if (vif->cfg.assoc && vif->cfg.ps)
  172. return conf->dynamic_ps_timeout;
  173. else
  174. return -1;
  175. }
  176. int wfx_update_pm(struct wfx_vif *wvif)
  177. {
  178. struct ieee80211_vif *vif = wvif_to_vif(wvif);
  179. int ps_timeout;
  180. bool ps;
  181. if (!vif->cfg.assoc)
  182. return 0;
  183. ps_timeout = wfx_get_ps_timeout(wvif, &ps);
  184. if (!ps)
  185. ps_timeout = 0;
  186. WARN_ON(ps_timeout < 0);
  187. if (wvif->uapsd_mask)
  188. ps_timeout = 0;
  189. if (!wait_for_completion_timeout(&wvif->set_pm_mode_complete, TU_TO_JIFFIES(512)))
  190. dev_warn(wvif->wdev->dev, "timeout while waiting of set_pm_mode_complete\n");
  191. return wfx_hif_set_pm(wvif, ps, ps_timeout);
  192. }
  193. int wfx_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  194. unsigned int link_id, u16 queue,
  195. const struct ieee80211_tx_queue_params *params)
  196. {
  197. struct wfx_dev *wdev = hw->priv;
  198. struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
  199. int old_uapsd = wvif->uapsd_mask;
  200. WARN_ON(queue >= hw->queues);
  201. mutex_lock(&wdev->conf_mutex);
  202. assign_bit(queue, &wvif->uapsd_mask, params->uapsd);
  203. wfx_hif_set_edca_queue_params(wvif, queue, params);
  204. if (vif->type == NL80211_IFTYPE_STATION &&
  205. old_uapsd != wvif->uapsd_mask) {
  206. wfx_hif_set_uapsd_info(wvif, wvif->uapsd_mask);
  207. wfx_update_pm(wvif);
  208. }
  209. mutex_unlock(&wdev->conf_mutex);
  210. return 0;
  211. }
  212. int wfx_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  213. {
  214. struct wfx_dev *wdev = hw->priv;
  215. struct wfx_vif *wvif = NULL;
  216. while ((wvif = wvif_iterate(wdev, wvif)) != NULL)
  217. wfx_hif_rts_threshold(wvif, value);
  218. return 0;
  219. }
  220. void wfx_event_report_rssi(struct wfx_vif *wvif, u8 raw_rcpi_rssi)
  221. {
  222. /* RSSI: signed Q8.0, RCPI: unsigned Q7.1
  223. * RSSI = RCPI / 2 - 110
  224. */
  225. struct ieee80211_vif *vif = wvif_to_vif(wvif);
  226. int rcpi_rssi;
  227. int cqm_evt;
  228. rcpi_rssi = raw_rcpi_rssi / 2 - 110;
  229. if (rcpi_rssi <= vif->bss_conf.cqm_rssi_thold)
  230. cqm_evt = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
  231. else
  232. cqm_evt = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
  233. ieee80211_cqm_rssi_notify(vif, cqm_evt, rcpi_rssi, GFP_KERNEL);
  234. }
  235. static void wfx_beacon_loss_work(struct work_struct *work)
  236. {
  237. struct wfx_vif *wvif = container_of(to_delayed_work(work), struct wfx_vif,
  238. beacon_loss_work);
  239. struct ieee80211_vif *vif = wvif_to_vif(wvif);
  240. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  241. ieee80211_beacon_loss(vif);
  242. schedule_delayed_work(to_delayed_work(work), msecs_to_jiffies(bss_conf->beacon_int));
  243. }
  244. void wfx_set_default_unicast_key(struct ieee80211_hw *hw, struct ieee80211_vif *vif, int idx)
  245. {
  246. struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
  247. wfx_hif_wep_default_key_id(wvif, idx);
  248. }
  249. void wfx_reset(struct wfx_vif *wvif)
  250. {
  251. struct wfx_dev *wdev = wvif->wdev;
  252. wfx_tx_lock_flush(wdev);
  253. wfx_hif_reset(wvif, false);
  254. wfx_tx_policy_init(wvif);
  255. if (wvif_count(wdev) <= 1)
  256. wfx_hif_set_block_ack_policy(wvif, 0xFF, 0xFF);
  257. wfx_tx_unlock(wdev);
  258. wvif->join_in_progress = false;
  259. cancel_delayed_work_sync(&wvif->beacon_loss_work);
  260. wvif = NULL;
  261. while ((wvif = wvif_iterate(wdev, wvif)) != NULL)
  262. wfx_update_pm(wvif);
  263. }
  264. int wfx_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_sta *sta)
  265. {
  266. struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
  267. struct wfx_sta_priv *sta_priv = (struct wfx_sta_priv *)&sta->drv_priv;
  268. sta_priv->vif_id = wvif->id;
  269. if (vif->type == NL80211_IFTYPE_STATION)
  270. wfx_hif_set_mfp(wvif, sta->mfp, sta->mfp);
  271. /* In station mode, the firmware interprets new link-id as a TDLS peer */
  272. if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
  273. return 0;
  274. sta_priv->link_id = ffz(wvif->link_id_map);
  275. wvif->link_id_map |= BIT(sta_priv->link_id);
  276. WARN_ON(!sta_priv->link_id);
  277. WARN_ON(sta_priv->link_id >= HIF_LINK_ID_MAX);
  278. wfx_hif_map_link(wvif, false, sta->addr, sta_priv->link_id, sta->mfp);
  279. return 0;
  280. }
  281. int wfx_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_sta *sta)
  282. {
  283. struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
  284. struct wfx_sta_priv *sta_priv = (struct wfx_sta_priv *)&sta->drv_priv;
  285. /* See note in wfx_sta_add() */
  286. if (!sta_priv->link_id)
  287. return 0;
  288. /* FIXME add a mutex? */
  289. wfx_hif_map_link(wvif, true, sta->addr, sta_priv->link_id, false);
  290. wvif->link_id_map &= ~BIT(sta_priv->link_id);
  291. return 0;
  292. }
  293. static int wfx_upload_ap_templates(struct wfx_vif *wvif)
  294. {
  295. struct ieee80211_vif *vif = wvif_to_vif(wvif);
  296. struct sk_buff *skb;
  297. skb = ieee80211_beacon_get(wvif->wdev->hw, vif, 0);
  298. if (!skb)
  299. return -ENOMEM;
  300. wfx_hif_set_template_frame(wvif, skb, HIF_TMPLT_BCN, API_RATE_INDEX_B_1MBPS);
  301. dev_kfree_skb(skb);
  302. skb = ieee80211_proberesp_get(wvif->wdev->hw, vif);
  303. if (!skb)
  304. return -ENOMEM;
  305. wfx_hif_set_template_frame(wvif, skb, HIF_TMPLT_PRBRES, API_RATE_INDEX_B_1MBPS);
  306. dev_kfree_skb(skb);
  307. return 0;
  308. }
  309. static void wfx_set_mfp_ap(struct wfx_vif *wvif)
  310. {
  311. struct ieee80211_vif *vif = wvif_to_vif(wvif);
  312. struct sk_buff *skb = ieee80211_beacon_get(wvif->wdev->hw, vif, 0);
  313. const int ieoffset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
  314. const u16 *ptr = (u16 *)cfg80211_find_ie(WLAN_EID_RSN, skb->data + ieoffset,
  315. skb->len - ieoffset);
  316. const int pairwise_cipher_suite_count_offset = 8 / sizeof(u16);
  317. const int pairwise_cipher_suite_size = 4 / sizeof(u16);
  318. const int akm_suite_size = 4 / sizeof(u16);
  319. if (ptr) {
  320. ptr += pairwise_cipher_suite_count_offset;
  321. if (WARN_ON(ptr > (u16 *)skb_tail_pointer(skb)))
  322. return;
  323. ptr += 1 + pairwise_cipher_suite_size * *ptr;
  324. if (WARN_ON(ptr > (u16 *)skb_tail_pointer(skb)))
  325. return;
  326. ptr += 1 + akm_suite_size * *ptr;
  327. if (WARN_ON(ptr > (u16 *)skb_tail_pointer(skb)))
  328. return;
  329. wfx_hif_set_mfp(wvif, *ptr & BIT(7), *ptr & BIT(6));
  330. }
  331. }
  332. int wfx_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  333. struct ieee80211_bss_conf *link_conf)
  334. {
  335. struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
  336. struct wfx_dev *wdev = wvif->wdev;
  337. int ret;
  338. wvif = NULL;
  339. while ((wvif = wvif_iterate(wdev, wvif)) != NULL)
  340. wfx_update_pm(wvif);
  341. wvif = (struct wfx_vif *)vif->drv_priv;
  342. wfx_upload_ap_templates(wvif);
  343. ret = wfx_hif_start(wvif, &vif->bss_conf, wvif->channel);
  344. if (ret > 0)
  345. return -EIO;
  346. wfx_set_mfp_ap(wvif);
  347. return ret;
  348. }
  349. void wfx_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  350. struct ieee80211_bss_conf *link_conf)
  351. {
  352. struct wfx_vif *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. struct wfx_vif *wvif_it;
  544. if (notify_cmd != STA_NOTIFY_AWAKE)
  545. return;
  546. /* Device won't be able to honor CAB if a scan is in progress on any interface. Prefer to
  547. * skip this DTIM and wait for the next one.
  548. */
  549. wvif_it = NULL;
  550. while ((wvif_it = wvif_iterate(wvif->wdev, wvif_it)) != NULL)
  551. if (mutex_is_locked(&wvif_it->scan_lock))
  552. return;
  553. if (!wfx_tx_queues_has_cab(wvif) || wvif->after_dtim_tx_allowed)
  554. dev_warn(wvif->wdev->dev, "incorrect sequence (%d CAB in queue)",
  555. wfx_tx_queues_has_cab(wvif));
  556. wvif->after_dtim_tx_allowed = true;
  557. wfx_bh_request_tx(wvif->wdev);
  558. }
  559. int wfx_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  560. struct ieee80211_ampdu_params *params)
  561. {
  562. /* Aggregation is implemented fully in firmware */
  563. switch (params->action) {
  564. case IEEE80211_AMPDU_RX_START:
  565. case IEEE80211_AMPDU_RX_STOP:
  566. /* Just acknowledge it to enable frame re-ordering */
  567. return 0;
  568. default:
  569. /* Leave the firmware doing its business for tx aggregation */
  570. return -EOPNOTSUPP;
  571. }
  572. }
  573. int wfx_add_chanctx(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *conf)
  574. {
  575. return 0;
  576. }
  577. void wfx_remove_chanctx(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *conf)
  578. {
  579. }
  580. void wfx_change_chanctx(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *conf, u32 changed)
  581. {
  582. }
  583. int wfx_assign_vif_chanctx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  584. struct ieee80211_bss_conf *link_conf,
  585. struct ieee80211_chanctx_conf *conf)
  586. {
  587. struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
  588. struct ieee80211_channel *ch = conf->def.chan;
  589. WARN(wvif->channel, "channel overwrite");
  590. wvif->channel = ch;
  591. return 0;
  592. }
  593. void wfx_unassign_vif_chanctx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  594. struct ieee80211_bss_conf *link_conf,
  595. struct ieee80211_chanctx_conf *conf)
  596. {
  597. struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
  598. struct ieee80211_channel *ch = conf->def.chan;
  599. WARN(wvif->channel != ch, "channel mismatch");
  600. wvif->channel = NULL;
  601. }
  602. int wfx_config(struct ieee80211_hw *hw, u32 changed)
  603. {
  604. return 0;
  605. }
  606. int wfx_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  607. {
  608. int i;
  609. struct wfx_dev *wdev = hw->priv;
  610. struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
  611. vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
  612. IEEE80211_VIF_SUPPORTS_UAPSD |
  613. IEEE80211_VIF_SUPPORTS_CQM_RSSI;
  614. mutex_lock(&wdev->conf_mutex);
  615. switch (vif->type) {
  616. case NL80211_IFTYPE_STATION:
  617. case NL80211_IFTYPE_ADHOC:
  618. case NL80211_IFTYPE_AP:
  619. break;
  620. default:
  621. mutex_unlock(&wdev->conf_mutex);
  622. return -EOPNOTSUPP;
  623. }
  624. wvif->wdev = wdev;
  625. wvif->link_id_map = 1; /* link-id 0 is reserved for multicast */
  626. INIT_WORK(&wvif->update_tim_work, wfx_update_tim_work);
  627. INIT_DELAYED_WORK(&wvif->beacon_loss_work, wfx_beacon_loss_work);
  628. init_completion(&wvif->set_pm_mode_complete);
  629. complete(&wvif->set_pm_mode_complete);
  630. INIT_WORK(&wvif->tx_policy_upload_work, wfx_tx_policy_upload_work);
  631. mutex_init(&wvif->scan_lock);
  632. init_completion(&wvif->scan_complete);
  633. INIT_WORK(&wvif->scan_work, wfx_hw_scan_work);
  634. wfx_tx_queues_init(wvif);
  635. wfx_tx_policy_init(wvif);
  636. for (i = 0; i < ARRAY_SIZE(wdev->vif); i++) {
  637. if (!wdev->vif[i]) {
  638. wdev->vif[i] = vif;
  639. wvif->id = i;
  640. break;
  641. }
  642. }
  643. WARN(i == ARRAY_SIZE(wdev->vif), "try to instantiate more vif than supported");
  644. wfx_hif_set_macaddr(wvif, vif->addr);
  645. mutex_unlock(&wdev->conf_mutex);
  646. wvif = NULL;
  647. while ((wvif = wvif_iterate(wdev, wvif)) != NULL) {
  648. /* Combo mode does not support Block Acks. We can re-enable them */
  649. if (wvif_count(wdev) == 1)
  650. wfx_hif_set_block_ack_policy(wvif, 0xFF, 0xFF);
  651. else
  652. wfx_hif_set_block_ack_policy(wvif, 0x00, 0x00);
  653. }
  654. return 0;
  655. }
  656. void wfx_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  657. {
  658. struct wfx_dev *wdev = hw->priv;
  659. struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
  660. wait_for_completion_timeout(&wvif->set_pm_mode_complete, msecs_to_jiffies(300));
  661. wfx_tx_queues_check_empty(wvif);
  662. mutex_lock(&wdev->conf_mutex);
  663. WARN(wvif->link_id_map != 1, "corrupted state");
  664. wfx_hif_reset(wvif, false);
  665. wfx_hif_set_macaddr(wvif, NULL);
  666. wfx_tx_policy_init(wvif);
  667. cancel_delayed_work_sync(&wvif->beacon_loss_work);
  668. wdev->vif[wvif->id] = NULL;
  669. mutex_unlock(&wdev->conf_mutex);
  670. wvif = NULL;
  671. while ((wvif = wvif_iterate(wdev, wvif)) != NULL) {
  672. /* Combo mode does not support Block Acks. We can re-enable them */
  673. if (wvif_count(wdev) == 1)
  674. wfx_hif_set_block_ack_policy(wvif, 0xFF, 0xFF);
  675. else
  676. wfx_hif_set_block_ack_policy(wvif, 0x00, 0x00);
  677. }
  678. }
  679. int wfx_start(struct ieee80211_hw *hw)
  680. {
  681. return 0;
  682. }
  683. void wfx_stop(struct ieee80211_hw *hw)
  684. {
  685. struct wfx_dev *wdev = hw->priv;
  686. WARN_ON(!skb_queue_empty_lockless(&wdev->tx_pending));
  687. }