sta.c 21 KB

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