mac80211.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  1. // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
  2. /* Copyright(c) 2019-2020 Realtek Corporation
  3. */
  4. #include "cam.h"
  5. #include "chan.h"
  6. #include "coex.h"
  7. #include "debug.h"
  8. #include "fw.h"
  9. #include "mac.h"
  10. #include "phy.h"
  11. #include "ps.h"
  12. #include "reg.h"
  13. #include "sar.h"
  14. #include "ser.h"
  15. #include "util.h"
  16. #include "wow.h"
  17. static void rtw89_ops_tx(struct ieee80211_hw *hw,
  18. struct ieee80211_tx_control *control,
  19. struct sk_buff *skb)
  20. {
  21. struct rtw89_dev *rtwdev = hw->priv;
  22. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  23. struct ieee80211_vif *vif = info->control.vif;
  24. struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
  25. struct ieee80211_sta *sta = control->sta;
  26. u32 flags = IEEE80211_SKB_CB(skb)->flags;
  27. int ret, qsel;
  28. if (rtwvif->offchan && !(flags & IEEE80211_TX_CTL_TX_OFFCHAN) && sta) {
  29. struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
  30. rtw89_debug(rtwdev, RTW89_DBG_TXRX, "ops_tx during offchan\n");
  31. skb_queue_tail(&rtwsta->roc_queue, skb);
  32. return;
  33. }
  34. ret = rtw89_core_tx_write(rtwdev, vif, sta, skb, &qsel);
  35. if (ret) {
  36. rtw89_err(rtwdev, "failed to transmit skb: %d\n", ret);
  37. ieee80211_free_txskb(hw, skb);
  38. return;
  39. }
  40. rtw89_core_tx_kick_off(rtwdev, qsel);
  41. }
  42. static void rtw89_ops_wake_tx_queue(struct ieee80211_hw *hw,
  43. struct ieee80211_txq *txq)
  44. {
  45. struct rtw89_dev *rtwdev = hw->priv;
  46. ieee80211_schedule_txq(hw, txq);
  47. queue_work(rtwdev->txq_wq, &rtwdev->txq_work);
  48. }
  49. static int rtw89_ops_start(struct ieee80211_hw *hw)
  50. {
  51. struct rtw89_dev *rtwdev = hw->priv;
  52. int ret;
  53. mutex_lock(&rtwdev->mutex);
  54. ret = rtw89_core_start(rtwdev);
  55. mutex_unlock(&rtwdev->mutex);
  56. return ret;
  57. }
  58. static void rtw89_ops_stop(struct ieee80211_hw *hw)
  59. {
  60. struct rtw89_dev *rtwdev = hw->priv;
  61. mutex_lock(&rtwdev->mutex);
  62. rtw89_core_stop(rtwdev);
  63. mutex_unlock(&rtwdev->mutex);
  64. }
  65. static int rtw89_ops_config(struct ieee80211_hw *hw, u32 changed)
  66. {
  67. struct rtw89_dev *rtwdev = hw->priv;
  68. /* let previous ips work finish to ensure we don't leave ips twice */
  69. cancel_work_sync(&rtwdev->ips_work);
  70. mutex_lock(&rtwdev->mutex);
  71. rtw89_leave_ps_mode(rtwdev);
  72. if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
  73. !(hw->conf.flags & IEEE80211_CONF_IDLE))
  74. rtw89_leave_ips(rtwdev);
  75. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  76. rtw89_config_entity_chandef(rtwdev, RTW89_SUB_ENTITY_0,
  77. &hw->conf.chandef);
  78. rtw89_set_channel(rtwdev);
  79. }
  80. if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
  81. (hw->conf.flags & IEEE80211_CONF_IDLE) &&
  82. !rtwdev->scanning)
  83. rtw89_enter_ips(rtwdev);
  84. mutex_unlock(&rtwdev->mutex);
  85. return 0;
  86. }
  87. static int rtw89_ops_add_interface(struct ieee80211_hw *hw,
  88. struct ieee80211_vif *vif)
  89. {
  90. struct rtw89_dev *rtwdev = hw->priv;
  91. struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
  92. int ret = 0;
  93. rtw89_debug(rtwdev, RTW89_DBG_STATE, "add vif %pM type %d, p2p %d\n",
  94. vif->addr, vif->type, vif->p2p);
  95. mutex_lock(&rtwdev->mutex);
  96. rtw89_leave_ips_by_hwflags(rtwdev);
  97. if (RTW89_CHK_FW_FEATURE(BEACON_FILTER, &rtwdev->fw))
  98. vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
  99. IEEE80211_VIF_SUPPORTS_CQM_RSSI;
  100. rtwvif->rtwdev = rtwdev;
  101. rtwvif->roc.state = RTW89_ROC_IDLE;
  102. rtwvif->offchan = false;
  103. list_add_tail(&rtwvif->list, &rtwdev->rtwvifs_list);
  104. INIT_WORK(&rtwvif->update_beacon_work, rtw89_core_update_beacon_work);
  105. INIT_DELAYED_WORK(&rtwvif->roc.roc_work, rtw89_roc_work);
  106. rtw89_leave_ps_mode(rtwdev);
  107. rtw89_traffic_stats_init(rtwdev, &rtwvif->stats);
  108. rtw89_vif_type_mapping(vif, false);
  109. rtwvif->port = rtw89_core_acquire_bit_map(rtwdev->hw_port,
  110. RTW89_PORT_NUM);
  111. if (rtwvif->port == RTW89_PORT_NUM) {
  112. ret = -ENOSPC;
  113. list_del_init(&rtwvif->list);
  114. goto out;
  115. }
  116. rtwvif->bcn_hit_cond = 0;
  117. rtwvif->mac_idx = RTW89_MAC_0;
  118. rtwvif->phy_idx = RTW89_PHY_0;
  119. rtwvif->sub_entity_idx = RTW89_SUB_ENTITY_0;
  120. rtwvif->chanctx_assigned = false;
  121. rtwvif->hit_rule = 0;
  122. rtwvif->reg_6ghz_power = RTW89_REG_6GHZ_POWER_DFLT;
  123. ether_addr_copy(rtwvif->mac_addr, vif->addr);
  124. INIT_LIST_HEAD(&rtwvif->general_pkt_list);
  125. ret = rtw89_mac_add_vif(rtwdev, rtwvif);
  126. if (ret) {
  127. rtw89_core_release_bit_map(rtwdev->hw_port, rtwvif->port);
  128. list_del_init(&rtwvif->list);
  129. goto out;
  130. }
  131. rtw89_core_txq_init(rtwdev, vif->txq);
  132. rtw89_btc_ntfy_role_info(rtwdev, rtwvif, NULL, BTC_ROLE_START);
  133. rtw89_recalc_lps(rtwdev);
  134. out:
  135. mutex_unlock(&rtwdev->mutex);
  136. return ret;
  137. }
  138. static void rtw89_ops_remove_interface(struct ieee80211_hw *hw,
  139. struct ieee80211_vif *vif)
  140. {
  141. struct rtw89_dev *rtwdev = hw->priv;
  142. struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
  143. rtw89_debug(rtwdev, RTW89_DBG_STATE, "remove vif %pM type %d p2p %d\n",
  144. vif->addr, vif->type, vif->p2p);
  145. cancel_work_sync(&rtwvif->update_beacon_work);
  146. cancel_delayed_work_sync(&rtwvif->roc.roc_work);
  147. mutex_lock(&rtwdev->mutex);
  148. rtw89_leave_ps_mode(rtwdev);
  149. rtw89_btc_ntfy_role_info(rtwdev, rtwvif, NULL, BTC_ROLE_STOP);
  150. rtw89_mac_remove_vif(rtwdev, rtwvif);
  151. rtw89_core_release_bit_map(rtwdev->hw_port, rtwvif->port);
  152. list_del_init(&rtwvif->list);
  153. rtw89_recalc_lps(rtwdev);
  154. rtw89_enter_ips_by_hwflags(rtwdev);
  155. mutex_unlock(&rtwdev->mutex);
  156. }
  157. static int rtw89_ops_change_interface(struct ieee80211_hw *hw,
  158. struct ieee80211_vif *vif,
  159. enum nl80211_iftype type, bool p2p)
  160. {
  161. struct rtw89_dev *rtwdev = hw->priv;
  162. int ret;
  163. set_bit(RTW89_FLAG_CHANGING_INTERFACE, rtwdev->flags);
  164. rtw89_debug(rtwdev, RTW89_DBG_STATE, "change vif %pM (%d)->(%d), p2p (%d)->(%d)\n",
  165. vif->addr, vif->type, type, vif->p2p, p2p);
  166. rtw89_ops_remove_interface(hw, vif);
  167. vif->type = type;
  168. vif->p2p = p2p;
  169. ret = rtw89_ops_add_interface(hw, vif);
  170. if (ret)
  171. rtw89_warn(rtwdev, "failed to change interface %d\n", ret);
  172. clear_bit(RTW89_FLAG_CHANGING_INTERFACE, rtwdev->flags);
  173. return ret;
  174. }
  175. static void rtw89_ops_configure_filter(struct ieee80211_hw *hw,
  176. unsigned int changed_flags,
  177. unsigned int *new_flags,
  178. u64 multicast)
  179. {
  180. struct rtw89_dev *rtwdev = hw->priv;
  181. const struct rtw89_mac_gen_def *mac = rtwdev->chip->mac_def;
  182. mutex_lock(&rtwdev->mutex);
  183. rtw89_leave_ps_mode(rtwdev);
  184. *new_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_FCSFAIL |
  185. FIF_BCN_PRBRESP_PROMISC | FIF_PROBE_REQ;
  186. if (changed_flags & FIF_ALLMULTI) {
  187. if (*new_flags & FIF_ALLMULTI)
  188. rtwdev->hal.rx_fltr &= ~B_AX_A_MC;
  189. else
  190. rtwdev->hal.rx_fltr |= B_AX_A_MC;
  191. }
  192. if (changed_flags & FIF_FCSFAIL) {
  193. if (*new_flags & FIF_FCSFAIL)
  194. rtwdev->hal.rx_fltr |= B_AX_A_CRC32_ERR;
  195. else
  196. rtwdev->hal.rx_fltr &= ~B_AX_A_CRC32_ERR;
  197. }
  198. if (changed_flags & FIF_OTHER_BSS) {
  199. if (*new_flags & FIF_OTHER_BSS)
  200. rtwdev->hal.rx_fltr &= ~B_AX_A_A1_MATCH;
  201. else
  202. rtwdev->hal.rx_fltr |= B_AX_A_A1_MATCH;
  203. }
  204. if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
  205. if (*new_flags & FIF_BCN_PRBRESP_PROMISC) {
  206. rtwdev->hal.rx_fltr &= ~B_AX_A_BCN_CHK_EN;
  207. rtwdev->hal.rx_fltr &= ~B_AX_A_BC;
  208. rtwdev->hal.rx_fltr &= ~B_AX_A_A1_MATCH;
  209. } else {
  210. rtwdev->hal.rx_fltr |= B_AX_A_BCN_CHK_EN;
  211. rtwdev->hal.rx_fltr |= B_AX_A_BC;
  212. rtwdev->hal.rx_fltr |= B_AX_A_A1_MATCH;
  213. }
  214. }
  215. if (changed_flags & FIF_PROBE_REQ) {
  216. if (*new_flags & FIF_PROBE_REQ) {
  217. rtwdev->hal.rx_fltr &= ~B_AX_A_BC_CAM_MATCH;
  218. rtwdev->hal.rx_fltr &= ~B_AX_A_UC_CAM_MATCH;
  219. } else {
  220. rtwdev->hal.rx_fltr |= B_AX_A_BC_CAM_MATCH;
  221. rtwdev->hal.rx_fltr |= B_AX_A_UC_CAM_MATCH;
  222. }
  223. }
  224. rtw89_write32_mask(rtwdev,
  225. rtw89_mac_reg_by_idx(rtwdev, mac->rx_fltr, RTW89_MAC_0),
  226. B_AX_RX_FLTR_CFG_MASK,
  227. rtwdev->hal.rx_fltr);
  228. if (!rtwdev->dbcc_en)
  229. goto out;
  230. rtw89_write32_mask(rtwdev,
  231. rtw89_mac_reg_by_idx(rtwdev, mac->rx_fltr, RTW89_MAC_1),
  232. B_AX_RX_FLTR_CFG_MASK,
  233. rtwdev->hal.rx_fltr);
  234. out:
  235. mutex_unlock(&rtwdev->mutex);
  236. }
  237. static const u8 ac_to_fw_idx[IEEE80211_NUM_ACS] = {
  238. [IEEE80211_AC_VO] = 3,
  239. [IEEE80211_AC_VI] = 2,
  240. [IEEE80211_AC_BE] = 0,
  241. [IEEE80211_AC_BK] = 1,
  242. };
  243. static u8 rtw89_aifsn_to_aifs(struct rtw89_dev *rtwdev,
  244. struct rtw89_vif *rtwvif, u8 aifsn)
  245. {
  246. struct ieee80211_vif *vif = rtwvif_to_vif(rtwvif);
  247. const struct rtw89_chan *chan = rtw89_chan_get(rtwdev,
  248. rtwvif->sub_entity_idx);
  249. u8 slot_time;
  250. u8 sifs;
  251. slot_time = vif->bss_conf.use_short_slot ? 9 : 20;
  252. sifs = chan->band_type == RTW89_BAND_5G ? 16 : 10;
  253. return aifsn * slot_time + sifs;
  254. }
  255. static void ____rtw89_conf_tx_edca(struct rtw89_dev *rtwdev,
  256. struct rtw89_vif *rtwvif, u16 ac)
  257. {
  258. struct ieee80211_tx_queue_params *params = &rtwvif->tx_params[ac];
  259. u32 val;
  260. u8 ecw_max, ecw_min;
  261. u8 aifs;
  262. /* 2^ecw - 1 = cw; ecw = log2(cw + 1) */
  263. ecw_max = ilog2(params->cw_max + 1);
  264. ecw_min = ilog2(params->cw_min + 1);
  265. aifs = rtw89_aifsn_to_aifs(rtwdev, rtwvif, params->aifs);
  266. val = FIELD_PREP(FW_EDCA_PARAM_TXOPLMT_MSK, params->txop) |
  267. FIELD_PREP(FW_EDCA_PARAM_CWMAX_MSK, ecw_max) |
  268. FIELD_PREP(FW_EDCA_PARAM_CWMIN_MSK, ecw_min) |
  269. FIELD_PREP(FW_EDCA_PARAM_AIFS_MSK, aifs);
  270. rtw89_fw_h2c_set_edca(rtwdev, rtwvif, ac_to_fw_idx[ac], val);
  271. }
  272. static const u32 ac_to_mu_edca_param[IEEE80211_NUM_ACS] = {
  273. [IEEE80211_AC_VO] = R_AX_MUEDCA_VO_PARAM_0,
  274. [IEEE80211_AC_VI] = R_AX_MUEDCA_VI_PARAM_0,
  275. [IEEE80211_AC_BE] = R_AX_MUEDCA_BE_PARAM_0,
  276. [IEEE80211_AC_BK] = R_AX_MUEDCA_BK_PARAM_0,
  277. };
  278. static void ____rtw89_conf_tx_mu_edca(struct rtw89_dev *rtwdev,
  279. struct rtw89_vif *rtwvif, u16 ac)
  280. {
  281. struct ieee80211_tx_queue_params *params = &rtwvif->tx_params[ac];
  282. struct ieee80211_he_mu_edca_param_ac_rec *mu_edca;
  283. u8 aifs, aifsn;
  284. u16 timer_32us;
  285. u32 reg;
  286. u32 val;
  287. if (!params->mu_edca)
  288. return;
  289. mu_edca = &params->mu_edca_param_rec;
  290. aifsn = FIELD_GET(GENMASK(3, 0), mu_edca->aifsn);
  291. aifs = aifsn ? rtw89_aifsn_to_aifs(rtwdev, rtwvif, aifsn) : 0;
  292. timer_32us = mu_edca->mu_edca_timer << 8;
  293. val = FIELD_PREP(B_AX_MUEDCA_BE_PARAM_0_TIMER_MASK, timer_32us) |
  294. FIELD_PREP(B_AX_MUEDCA_BE_PARAM_0_CW_MASK, mu_edca->ecw_min_max) |
  295. FIELD_PREP(B_AX_MUEDCA_BE_PARAM_0_AIFS_MASK, aifs);
  296. reg = rtw89_mac_reg_by_idx(rtwdev, ac_to_mu_edca_param[ac], rtwvif->mac_idx);
  297. rtw89_write32(rtwdev, reg, val);
  298. rtw89_mac_set_hw_muedca_ctrl(rtwdev, rtwvif, true);
  299. }
  300. static void __rtw89_conf_tx(struct rtw89_dev *rtwdev,
  301. struct rtw89_vif *rtwvif, u16 ac)
  302. {
  303. ____rtw89_conf_tx_edca(rtwdev, rtwvif, ac);
  304. ____rtw89_conf_tx_mu_edca(rtwdev, rtwvif, ac);
  305. }
  306. static void rtw89_conf_tx(struct rtw89_dev *rtwdev,
  307. struct rtw89_vif *rtwvif)
  308. {
  309. u16 ac;
  310. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  311. __rtw89_conf_tx(rtwdev, rtwvif, ac);
  312. }
  313. static void rtw89_station_mode_sta_assoc(struct rtw89_dev *rtwdev,
  314. struct ieee80211_vif *vif,
  315. struct ieee80211_bss_conf *conf)
  316. {
  317. struct ieee80211_sta *sta;
  318. if (vif->type != NL80211_IFTYPE_STATION)
  319. return;
  320. sta = ieee80211_find_sta(vif, conf->bssid);
  321. if (!sta) {
  322. rtw89_err(rtwdev, "can't find sta to set sta_assoc state\n");
  323. return;
  324. }
  325. rtw89_vif_type_mapping(vif, true);
  326. rtw89_core_sta_assoc(rtwdev, vif, sta);
  327. }
  328. static void rtw89_ops_bss_info_changed(struct ieee80211_hw *hw,
  329. struct ieee80211_vif *vif,
  330. struct ieee80211_bss_conf *conf,
  331. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 0, 0))
  332. u64 changed)
  333. #else
  334. u32 changed)
  335. #endif
  336. {
  337. struct rtw89_dev *rtwdev = hw->priv;
  338. struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
  339. mutex_lock(&rtwdev->mutex);
  340. rtw89_leave_ps_mode(rtwdev);
  341. if (changed & BSS_CHANGED_ASSOC) {
  342. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 0, 0))
  343. if (vif->cfg.assoc) {
  344. #else
  345. if (conf->assoc) {
  346. #endif
  347. rtw89_station_mode_sta_assoc(rtwdev, vif, conf);
  348. rtw89_phy_set_bss_color(rtwdev, vif);
  349. rtw89_chip_cfg_txpwr_ul_tb_offset(rtwdev, vif);
  350. rtw89_mac_port_update(rtwdev, rtwvif);
  351. rtw89_mac_set_he_obss_narrow_bw_ru(rtwdev, vif);
  352. rtw89_queue_chanctx_work(rtwdev);
  353. } else {
  354. /* Abort ongoing scan if cancel_scan isn't issued
  355. * when disconnected by peer
  356. */
  357. if (rtwdev->scanning)
  358. rtw89_hw_scan_abort(rtwdev, vif);
  359. }
  360. }
  361. if (changed & BSS_CHANGED_BSSID) {
  362. ether_addr_copy(rtwvif->bssid, conf->bssid);
  363. rtw89_cam_bssid_changed(rtwdev, rtwvif);
  364. rtw89_fw_h2c_cam(rtwdev, rtwvif, NULL, NULL);
  365. }
  366. if (changed & BSS_CHANGED_BEACON)
  367. rtw89_fw_h2c_update_beacon(rtwdev, rtwvif);
  368. if (changed & BSS_CHANGED_ERP_SLOT)
  369. rtw89_conf_tx(rtwdev, rtwvif);
  370. if (changed & BSS_CHANGED_HE_BSS_COLOR)
  371. rtw89_phy_set_bss_color(rtwdev, vif);
  372. if (changed & BSS_CHANGED_MU_GROUPS)
  373. rtw89_mac_bf_set_gid_table(rtwdev, vif, conf);
  374. if (changed & BSS_CHANGED_P2P_PS)
  375. rtw89_core_update_p2p_ps(rtwdev, vif);
  376. if (changed & BSS_CHANGED_CQM)
  377. rtw89_fw_h2c_set_bcn_fltr_cfg(rtwdev, vif, true);
  378. if (changed & BSS_CHANGED_PS)
  379. rtw89_recalc_lps(rtwdev);
  380. mutex_unlock(&rtwdev->mutex);
  381. }
  382. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 0, 0))
  383. static int rtw89_ops_start_ap(struct ieee80211_hw *hw,
  384. struct ieee80211_vif *vif,
  385. struct ieee80211_bss_conf *link_conf)
  386. #else
  387. static int rtw89_ops_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  388. #endif
  389. {
  390. struct rtw89_dev *rtwdev = hw->priv;
  391. struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
  392. const struct rtw89_chan *chan;
  393. mutex_lock(&rtwdev->mutex);
  394. chan = rtw89_chan_get(rtwdev, rtwvif->sub_entity_idx);
  395. if (chan->band_type == RTW89_BAND_6G) {
  396. mutex_unlock(&rtwdev->mutex);
  397. return -EOPNOTSUPP;
  398. }
  399. ether_addr_copy(rtwvif->bssid, vif->bss_conf.bssid);
  400. rtw89_cam_bssid_changed(rtwdev, rtwvif);
  401. rtw89_mac_port_update(rtwdev, rtwvif);
  402. rtw89_fw_h2c_assoc_cmac_tbl(rtwdev, vif, NULL);
  403. rtw89_fw_h2c_role_maintain(rtwdev, rtwvif, NULL, RTW89_ROLE_TYPE_CHANGE);
  404. rtw89_fw_h2c_join_info(rtwdev, rtwvif, NULL, true);
  405. rtw89_fw_h2c_cam(rtwdev, rtwvif, NULL, NULL);
  406. rtw89_chip_rfk_channel(rtwdev);
  407. rtw89_queue_chanctx_work(rtwdev);
  408. mutex_unlock(&rtwdev->mutex);
  409. return 0;
  410. }
  411. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 0, 0))
  412. static
  413. void rtw89_ops_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  414. struct ieee80211_bss_conf *link_conf)
  415. #else
  416. static
  417. void rtw89_ops_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  418. #endif
  419. {
  420. struct rtw89_dev *rtwdev = hw->priv;
  421. struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
  422. mutex_lock(&rtwdev->mutex);
  423. rtw89_mac_stop_ap(rtwdev, rtwvif);
  424. rtw89_fw_h2c_assoc_cmac_tbl(rtwdev, vif, NULL);
  425. rtw89_fw_h2c_join_info(rtwdev, rtwvif, NULL, true);
  426. mutex_unlock(&rtwdev->mutex);
  427. }
  428. static int rtw89_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
  429. bool set)
  430. {
  431. struct rtw89_dev *rtwdev = hw->priv;
  432. struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
  433. struct rtw89_vif *rtwvif = rtwsta->rtwvif;
  434. ieee80211_queue_work(rtwdev->hw, &rtwvif->update_beacon_work);
  435. return 0;
  436. }
  437. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 0, 0))
  438. static int rtw89_ops_conf_tx(struct ieee80211_hw *hw,
  439. struct ieee80211_vif *vif,
  440. unsigned int link_id, u16 ac,
  441. const struct ieee80211_tx_queue_params *params)
  442. #else
  443. static int rtw89_ops_conf_tx(struct ieee80211_hw *hw,
  444. struct ieee80211_vif *vif, u16 ac,
  445. const struct ieee80211_tx_queue_params *params)
  446. #endif
  447. {
  448. struct rtw89_dev *rtwdev = hw->priv;
  449. struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
  450. mutex_lock(&rtwdev->mutex);
  451. rtw89_leave_ps_mode(rtwdev);
  452. rtwvif->tx_params[ac] = *params;
  453. __rtw89_conf_tx(rtwdev, rtwvif, ac);
  454. mutex_unlock(&rtwdev->mutex);
  455. return 0;
  456. }
  457. static int __rtw89_ops_sta_state(struct ieee80211_hw *hw,
  458. struct ieee80211_vif *vif,
  459. struct ieee80211_sta *sta,
  460. enum ieee80211_sta_state old_state,
  461. enum ieee80211_sta_state new_state)
  462. {
  463. struct rtw89_dev *rtwdev = hw->priv;
  464. if (old_state == IEEE80211_STA_NOTEXIST &&
  465. new_state == IEEE80211_STA_NONE)
  466. return rtw89_core_sta_add(rtwdev, vif, sta);
  467. if (old_state == IEEE80211_STA_AUTH &&
  468. new_state == IEEE80211_STA_ASSOC) {
  469. if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
  470. return 0; /* defer to bss_info_changed to have vif info */
  471. return rtw89_core_sta_assoc(rtwdev, vif, sta);
  472. }
  473. if (old_state == IEEE80211_STA_ASSOC &&
  474. new_state == IEEE80211_STA_AUTH)
  475. return rtw89_core_sta_disassoc(rtwdev, vif, sta);
  476. if (old_state == IEEE80211_STA_AUTH &&
  477. new_state == IEEE80211_STA_NONE)
  478. return rtw89_core_sta_disconnect(rtwdev, vif, sta);
  479. if (old_state == IEEE80211_STA_NONE &&
  480. new_state == IEEE80211_STA_NOTEXIST)
  481. return rtw89_core_sta_remove(rtwdev, vif, sta);
  482. return 0;
  483. }
  484. static int rtw89_ops_sta_state(struct ieee80211_hw *hw,
  485. struct ieee80211_vif *vif,
  486. struct ieee80211_sta *sta,
  487. enum ieee80211_sta_state old_state,
  488. enum ieee80211_sta_state new_state)
  489. {
  490. struct rtw89_dev *rtwdev = hw->priv;
  491. int ret;
  492. mutex_lock(&rtwdev->mutex);
  493. rtw89_leave_ps_mode(rtwdev);
  494. ret = __rtw89_ops_sta_state(hw, vif, sta, old_state, new_state);
  495. mutex_unlock(&rtwdev->mutex);
  496. return ret;
  497. }
  498. static int rtw89_ops_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  499. struct ieee80211_vif *vif,
  500. struct ieee80211_sta *sta,
  501. struct ieee80211_key_conf *key)
  502. {
  503. struct rtw89_dev *rtwdev = hw->priv;
  504. int ret = 0;
  505. mutex_lock(&rtwdev->mutex);
  506. rtw89_leave_ps_mode(rtwdev);
  507. switch (cmd) {
  508. case SET_KEY:
  509. rtw89_btc_ntfy_specific_packet(rtwdev, PACKET_EAPOL_END);
  510. ret = rtw89_cam_sec_key_add(rtwdev, vif, sta, key);
  511. if (ret && ret != -EOPNOTSUPP) {
  512. rtw89_err(rtwdev, "failed to add key to sec cam\n");
  513. goto out;
  514. }
  515. break;
  516. case DISABLE_KEY:
  517. rtw89_hci_flush_queues(rtwdev, BIT(rtwdev->hw->queues) - 1,
  518. false);
  519. rtw89_mac_flush_txq(rtwdev, BIT(rtwdev->hw->queues) - 1, false);
  520. ret = rtw89_cam_sec_key_del(rtwdev, vif, sta, key, true);
  521. if (ret) {
  522. rtw89_err(rtwdev, "failed to remove key from sec cam\n");
  523. goto out;
  524. }
  525. break;
  526. }
  527. out:
  528. mutex_unlock(&rtwdev->mutex);
  529. return ret;
  530. }
  531. static int rtw89_ops_ampdu_action(struct ieee80211_hw *hw,
  532. struct ieee80211_vif *vif,
  533. struct ieee80211_ampdu_params *params)
  534. {
  535. struct rtw89_dev *rtwdev = hw->priv;
  536. struct ieee80211_sta *sta = params->sta;
  537. struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
  538. u16 tid = params->tid;
  539. struct ieee80211_txq *txq = sta->txq[tid];
  540. struct rtw89_txq *rtwtxq = (struct rtw89_txq *)txq->drv_priv;
  541. switch (params->action) {
  542. case IEEE80211_AMPDU_TX_START:
  543. #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0)
  544. return IEEE80211_AMPDU_TX_START_IMMEDIATE;
  545. #else
  546. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  547. break;
  548. #endif
  549. case IEEE80211_AMPDU_TX_STOP_CONT:
  550. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  551. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  552. mutex_lock(&rtwdev->mutex);
  553. clear_bit(RTW89_TXQ_F_AMPDU, &rtwtxq->flags);
  554. mutex_unlock(&rtwdev->mutex);
  555. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  556. break;
  557. case IEEE80211_AMPDU_TX_OPERATIONAL:
  558. mutex_lock(&rtwdev->mutex);
  559. set_bit(RTW89_TXQ_F_AMPDU, &rtwtxq->flags);
  560. rtwsta->ampdu_params[tid].agg_num = params->buf_size;
  561. rtwsta->ampdu_params[tid].amsdu = params->amsdu;
  562. rtw89_leave_ps_mode(rtwdev);
  563. mutex_unlock(&rtwdev->mutex);
  564. break;
  565. case IEEE80211_AMPDU_RX_START:
  566. mutex_lock(&rtwdev->mutex);
  567. rtw89_fw_h2c_ba_cam(rtwdev, rtwsta, true, params);
  568. mutex_unlock(&rtwdev->mutex);
  569. break;
  570. case IEEE80211_AMPDU_RX_STOP:
  571. mutex_lock(&rtwdev->mutex);
  572. rtw89_fw_h2c_ba_cam(rtwdev, rtwsta, false, params);
  573. mutex_unlock(&rtwdev->mutex);
  574. break;
  575. default:
  576. WARN_ON(1);
  577. return -ENOTSUPP;
  578. }
  579. return 0;
  580. }
  581. static int rtw89_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  582. {
  583. struct rtw89_dev *rtwdev = hw->priv;
  584. mutex_lock(&rtwdev->mutex);
  585. rtw89_leave_ps_mode(rtwdev);
  586. if (test_bit(RTW89_FLAG_POWERON, rtwdev->flags))
  587. rtw89_mac_update_rts_threshold(rtwdev, RTW89_MAC_0);
  588. mutex_unlock(&rtwdev->mutex);
  589. return 0;
  590. }
  591. static void rtw89_ops_sta_statistics(struct ieee80211_hw *hw,
  592. struct ieee80211_vif *vif,
  593. struct ieee80211_sta *sta,
  594. struct station_info *sinfo)
  595. {
  596. struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
  597. sinfo->txrate = rtwsta->ra_report.txrate;
  598. sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
  599. }
  600. static
  601. void __rtw89_drop_packets(struct rtw89_dev *rtwdev, struct ieee80211_vif *vif)
  602. {
  603. struct rtw89_vif *rtwvif;
  604. if (vif) {
  605. rtwvif = (struct rtw89_vif *)vif->drv_priv;
  606. rtw89_mac_pkt_drop_vif(rtwdev, rtwvif);
  607. } else {
  608. rtw89_for_each_rtwvif(rtwdev, rtwvif)
  609. rtw89_mac_pkt_drop_vif(rtwdev, rtwvif);
  610. }
  611. }
  612. static void rtw89_ops_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  613. u32 queues, bool drop)
  614. {
  615. struct rtw89_dev *rtwdev = hw->priv;
  616. mutex_lock(&rtwdev->mutex);
  617. rtw89_leave_lps(rtwdev);
  618. rtw89_hci_flush_queues(rtwdev, queues, drop);
  619. if (drop && !RTW89_CHK_FW_FEATURE(NO_PACKET_DROP, &rtwdev->fw))
  620. __rtw89_drop_packets(rtwdev, vif);
  621. else
  622. rtw89_mac_flush_txq(rtwdev, queues, drop);
  623. mutex_unlock(&rtwdev->mutex);
  624. }
  625. struct rtw89_iter_bitrate_mask_data {
  626. struct rtw89_dev *rtwdev;
  627. struct ieee80211_vif *vif;
  628. const struct cfg80211_bitrate_mask *mask;
  629. };
  630. static void rtw89_ra_mask_info_update_iter(void *data, struct ieee80211_sta *sta)
  631. {
  632. struct rtw89_iter_bitrate_mask_data *br_data = data;
  633. struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
  634. struct ieee80211_vif *vif = rtwvif_to_vif(rtwsta->rtwvif);
  635. if (vif != br_data->vif || vif->p2p)
  636. return;
  637. rtwsta->use_cfg_mask = true;
  638. rtwsta->mask = *br_data->mask;
  639. rtw89_phy_ra_updata_sta(br_data->rtwdev, sta, IEEE80211_RC_SUPP_RATES_CHANGED);
  640. }
  641. static void rtw89_ra_mask_info_update(struct rtw89_dev *rtwdev,
  642. struct ieee80211_vif *vif,
  643. const struct cfg80211_bitrate_mask *mask)
  644. {
  645. struct rtw89_iter_bitrate_mask_data br_data = { .rtwdev = rtwdev,
  646. .vif = vif,
  647. .mask = mask};
  648. ieee80211_iterate_stations_atomic(rtwdev->hw, rtw89_ra_mask_info_update_iter,
  649. &br_data);
  650. }
  651. static int rtw89_ops_set_bitrate_mask(struct ieee80211_hw *hw,
  652. struct ieee80211_vif *vif,
  653. const struct cfg80211_bitrate_mask *mask)
  654. {
  655. struct rtw89_dev *rtwdev = hw->priv;
  656. mutex_lock(&rtwdev->mutex);
  657. rtw89_phy_rate_pattern_vif(rtwdev, vif, mask);
  658. rtw89_ra_mask_info_update(rtwdev, vif, mask);
  659. mutex_unlock(&rtwdev->mutex);
  660. return 0;
  661. }
  662. static
  663. int rtw89_ops_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
  664. {
  665. struct rtw89_dev *rtwdev = hw->priv;
  666. struct rtw89_hal *hal = &rtwdev->hal;
  667. if (hal->ant_diversity) {
  668. if (tx_ant != rx_ant || hweight32(tx_ant) != 1)
  669. return -EINVAL;
  670. } else if (rx_ant != hw->wiphy->available_antennas_rx && rx_ant != hal->antenna_rx) {
  671. return -EINVAL;
  672. }
  673. mutex_lock(&rtwdev->mutex);
  674. hal->antenna_tx = tx_ant;
  675. hal->antenna_rx = rx_ant;
  676. hal->tx_path_diversity = false;
  677. hal->ant_diversity_fixed = true;
  678. mutex_unlock(&rtwdev->mutex);
  679. return 0;
  680. }
  681. static
  682. int rtw89_ops_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
  683. {
  684. struct rtw89_dev *rtwdev = hw->priv;
  685. struct rtw89_hal *hal = &rtwdev->hal;
  686. *tx_ant = hal->antenna_tx;
  687. *rx_ant = hal->antenna_rx;
  688. return 0;
  689. }
  690. static void rtw89_ops_sw_scan_start(struct ieee80211_hw *hw,
  691. struct ieee80211_vif *vif,
  692. const u8 *mac_addr)
  693. {
  694. struct rtw89_dev *rtwdev = hw->priv;
  695. struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
  696. mutex_lock(&rtwdev->mutex);
  697. rtw89_core_scan_start(rtwdev, rtwvif, mac_addr, false);
  698. mutex_unlock(&rtwdev->mutex);
  699. }
  700. static void rtw89_ops_sw_scan_complete(struct ieee80211_hw *hw,
  701. struct ieee80211_vif *vif)
  702. {
  703. struct rtw89_dev *rtwdev = hw->priv;
  704. mutex_lock(&rtwdev->mutex);
  705. rtw89_core_scan_complete(rtwdev, vif, false);
  706. mutex_unlock(&rtwdev->mutex);
  707. }
  708. static void rtw89_ops_reconfig_complete(struct ieee80211_hw *hw,
  709. enum ieee80211_reconfig_type reconfig_type)
  710. {
  711. struct rtw89_dev *rtwdev = hw->priv;
  712. if (reconfig_type == IEEE80211_RECONFIG_TYPE_RESTART)
  713. rtw89_ser_recfg_done(rtwdev);
  714. }
  715. static int rtw89_ops_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  716. struct ieee80211_scan_request *req)
  717. {
  718. struct rtw89_dev *rtwdev = hw->priv;
  719. struct rtw89_vif *rtwvif = vif_to_rtwvif_safe(vif);
  720. int ret = 0;
  721. if (!RTW89_CHK_FW_FEATURE(SCAN_OFFLOAD, &rtwdev->fw))
  722. return 1;
  723. if (rtwdev->scanning || rtwvif->offchan)
  724. return -EBUSY;
  725. mutex_lock(&rtwdev->mutex);
  726. rtw89_hw_scan_start(rtwdev, vif, req);
  727. ret = rtw89_hw_scan_offload(rtwdev, vif, true);
  728. if (ret) {
  729. rtw89_hw_scan_abort(rtwdev, vif);
  730. rtw89_err(rtwdev, "HW scan failed with status: %d\n", ret);
  731. }
  732. mutex_unlock(&rtwdev->mutex);
  733. return ret;
  734. }
  735. static void rtw89_ops_cancel_hw_scan(struct ieee80211_hw *hw,
  736. struct ieee80211_vif *vif)
  737. {
  738. struct rtw89_dev *rtwdev = hw->priv;
  739. if (!RTW89_CHK_FW_FEATURE(SCAN_OFFLOAD, &rtwdev->fw))
  740. return;
  741. if (!rtwdev->scanning)
  742. return;
  743. mutex_lock(&rtwdev->mutex);
  744. rtw89_hw_scan_abort(rtwdev, vif);
  745. mutex_unlock(&rtwdev->mutex);
  746. }
  747. static void rtw89_ops_sta_rc_update(struct ieee80211_hw *hw,
  748. struct ieee80211_vif *vif,
  749. struct ieee80211_sta *sta, u32 changed)
  750. {
  751. struct rtw89_dev *rtwdev = hw->priv;
  752. rtw89_phy_ra_updata_sta(rtwdev, sta, changed);
  753. }
  754. static int rtw89_ops_add_chanctx(struct ieee80211_hw *hw,
  755. struct ieee80211_chanctx_conf *ctx)
  756. {
  757. struct rtw89_dev *rtwdev = hw->priv;
  758. int ret;
  759. mutex_lock(&rtwdev->mutex);
  760. ret = rtw89_chanctx_ops_add(rtwdev, ctx);
  761. mutex_unlock(&rtwdev->mutex);
  762. return ret;
  763. }
  764. static void rtw89_ops_remove_chanctx(struct ieee80211_hw *hw,
  765. struct ieee80211_chanctx_conf *ctx)
  766. {
  767. struct rtw89_dev *rtwdev = hw->priv;
  768. mutex_lock(&rtwdev->mutex);
  769. rtw89_chanctx_ops_remove(rtwdev, ctx);
  770. mutex_unlock(&rtwdev->mutex);
  771. }
  772. static void rtw89_ops_change_chanctx(struct ieee80211_hw *hw,
  773. struct ieee80211_chanctx_conf *ctx,
  774. u32 changed)
  775. {
  776. struct rtw89_dev *rtwdev = hw->priv;
  777. mutex_lock(&rtwdev->mutex);
  778. rtw89_chanctx_ops_change(rtwdev, ctx, changed);
  779. mutex_unlock(&rtwdev->mutex);
  780. }
  781. static int rtw89_ops_assign_vif_chanctx(struct ieee80211_hw *hw,
  782. struct ieee80211_vif *vif,
  783. #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 0, 0)
  784. struct ieee80211_bss_conf *link_conf,
  785. #endif
  786. struct ieee80211_chanctx_conf *ctx)
  787. {
  788. struct rtw89_dev *rtwdev = hw->priv;
  789. struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
  790. int ret;
  791. mutex_lock(&rtwdev->mutex);
  792. ret = rtw89_chanctx_ops_assign_vif(rtwdev, rtwvif, ctx);
  793. mutex_unlock(&rtwdev->mutex);
  794. return ret;
  795. }
  796. static void rtw89_ops_unassign_vif_chanctx(struct ieee80211_hw *hw,
  797. struct ieee80211_vif *vif,
  798. #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 0, 0)
  799. struct ieee80211_bss_conf *link_conf,
  800. #endif
  801. struct ieee80211_chanctx_conf *ctx)
  802. {
  803. struct rtw89_dev *rtwdev = hw->priv;
  804. struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
  805. mutex_lock(&rtwdev->mutex);
  806. rtw89_chanctx_ops_unassign_vif(rtwdev, rtwvif, ctx);
  807. mutex_unlock(&rtwdev->mutex);
  808. }
  809. static int rtw89_ops_remain_on_channel(struct ieee80211_hw *hw,
  810. struct ieee80211_vif *vif,
  811. struct ieee80211_channel *chan,
  812. int duration,
  813. enum ieee80211_roc_type type)
  814. {
  815. struct rtw89_dev *rtwdev = hw->priv;
  816. struct rtw89_vif *rtwvif = vif_to_rtwvif_safe(vif);
  817. struct rtw89_roc *roc = &rtwvif->roc;
  818. if (!vif)
  819. return -EINVAL;
  820. mutex_lock(&rtwdev->mutex);
  821. if (roc->state != RTW89_ROC_IDLE) {
  822. mutex_unlock(&rtwdev->mutex);
  823. return -EBUSY;
  824. }
  825. if (rtwdev->scanning)
  826. rtw89_hw_scan_abort(rtwdev, vif);
  827. if (type == IEEE80211_ROC_TYPE_MGMT_TX)
  828. roc->state = RTW89_ROC_MGMT;
  829. else
  830. roc->state = RTW89_ROC_NORMAL;
  831. roc->duration = duration;
  832. roc->chan = *chan;
  833. roc->type = type;
  834. rtw89_roc_start(rtwdev, rtwvif);
  835. mutex_unlock(&rtwdev->mutex);
  836. return 0;
  837. }
  838. static int rtw89_ops_cancel_remain_on_channel(struct ieee80211_hw *hw,
  839. struct ieee80211_vif *vif)
  840. {
  841. struct rtw89_dev *rtwdev = hw->priv;
  842. struct rtw89_vif *rtwvif = vif_to_rtwvif_safe(vif);
  843. if (!rtwvif)
  844. return -EINVAL;
  845. cancel_delayed_work_sync(&rtwvif->roc.roc_work);
  846. mutex_lock(&rtwdev->mutex);
  847. rtw89_roc_end(rtwdev, rtwvif);
  848. mutex_unlock(&rtwdev->mutex);
  849. return 0;
  850. }
  851. static void rtw89_set_tid_config_iter(void *data, struct ieee80211_sta *sta)
  852. {
  853. struct cfg80211_tid_config *tid_config = data;
  854. struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
  855. struct rtw89_dev *rtwdev = rtwsta->rtwvif->rtwdev;
  856. rtw89_core_set_tid_config(rtwdev, sta, tid_config);
  857. }
  858. static int rtw89_ops_set_tid_config(struct ieee80211_hw *hw,
  859. struct ieee80211_vif *vif,
  860. struct ieee80211_sta *sta,
  861. struct cfg80211_tid_config *tid_config)
  862. {
  863. struct rtw89_dev *rtwdev = hw->priv;
  864. mutex_lock(&rtwdev->mutex);
  865. if (sta)
  866. rtw89_core_set_tid_config(rtwdev, sta, tid_config);
  867. else
  868. ieee80211_iterate_stations_atomic(rtwdev->hw,
  869. rtw89_set_tid_config_iter,
  870. tid_config);
  871. mutex_unlock(&rtwdev->mutex);
  872. return 0;
  873. }
  874. #ifdef CONFIG_PM
  875. static int rtw89_ops_suspend(struct ieee80211_hw *hw,
  876. struct cfg80211_wowlan *wowlan)
  877. {
  878. struct rtw89_dev *rtwdev = hw->priv;
  879. int ret;
  880. set_bit(RTW89_FLAG_FORBIDDEN_TRACK_WROK, rtwdev->flags);
  881. cancel_delayed_work_sync(&rtwdev->track_work);
  882. mutex_lock(&rtwdev->mutex);
  883. ret = rtw89_wow_suspend(rtwdev, wowlan);
  884. mutex_unlock(&rtwdev->mutex);
  885. if (ret) {
  886. rtw89_warn(rtwdev, "failed to suspend for wow %d\n", ret);
  887. clear_bit(RTW89_FLAG_FORBIDDEN_TRACK_WROK, rtwdev->flags);
  888. return 1;
  889. }
  890. return 0;
  891. }
  892. static int rtw89_ops_resume(struct ieee80211_hw *hw)
  893. {
  894. struct rtw89_dev *rtwdev = hw->priv;
  895. int ret;
  896. mutex_lock(&rtwdev->mutex);
  897. ret = rtw89_wow_resume(rtwdev);
  898. if (ret)
  899. rtw89_warn(rtwdev, "failed to resume for wow %d\n", ret);
  900. mutex_unlock(&rtwdev->mutex);
  901. clear_bit(RTW89_FLAG_FORBIDDEN_TRACK_WROK, rtwdev->flags);
  902. ieee80211_queue_delayed_work(rtwdev->hw, &rtwdev->track_work,
  903. RTW89_TRACK_WORK_PERIOD);
  904. return ret ? 1 : 0;
  905. }
  906. static void rtw89_ops_set_wakeup(struct ieee80211_hw *hw, bool enabled)
  907. {
  908. struct rtw89_dev *rtwdev = hw->priv;
  909. device_set_wakeup_enable(rtwdev->dev, enabled);
  910. }
  911. #endif
  912. const struct ieee80211_ops rtw89_ops = {
  913. .tx = rtw89_ops_tx,
  914. .wake_tx_queue = rtw89_ops_wake_tx_queue,
  915. .start = rtw89_ops_start,
  916. .stop = rtw89_ops_stop,
  917. .config = rtw89_ops_config,
  918. .add_interface = rtw89_ops_add_interface,
  919. .change_interface = rtw89_ops_change_interface,
  920. .remove_interface = rtw89_ops_remove_interface,
  921. .configure_filter = rtw89_ops_configure_filter,
  922. .bss_info_changed = rtw89_ops_bss_info_changed,
  923. .start_ap = rtw89_ops_start_ap,
  924. .stop_ap = rtw89_ops_stop_ap,
  925. .set_tim = rtw89_ops_set_tim,
  926. .conf_tx = rtw89_ops_conf_tx,
  927. .sta_state = rtw89_ops_sta_state,
  928. .set_key = rtw89_ops_set_key,
  929. .ampdu_action = rtw89_ops_ampdu_action,
  930. .set_rts_threshold = rtw89_ops_set_rts_threshold,
  931. .sta_statistics = rtw89_ops_sta_statistics,
  932. .flush = rtw89_ops_flush,
  933. .set_bitrate_mask = rtw89_ops_set_bitrate_mask,
  934. .set_antenna = rtw89_ops_set_antenna,
  935. .get_antenna = rtw89_ops_get_antenna,
  936. .sw_scan_start = rtw89_ops_sw_scan_start,
  937. .sw_scan_complete = rtw89_ops_sw_scan_complete,
  938. .reconfig_complete = rtw89_ops_reconfig_complete,
  939. .hw_scan = rtw89_ops_hw_scan,
  940. .cancel_hw_scan = rtw89_ops_cancel_hw_scan,
  941. .add_chanctx = rtw89_ops_add_chanctx,
  942. .remove_chanctx = rtw89_ops_remove_chanctx,
  943. .change_chanctx = rtw89_ops_change_chanctx,
  944. .assign_vif_chanctx = rtw89_ops_assign_vif_chanctx,
  945. .unassign_vif_chanctx = rtw89_ops_unassign_vif_chanctx,
  946. .remain_on_channel = rtw89_ops_remain_on_channel,
  947. .cancel_remain_on_channel = rtw89_ops_cancel_remain_on_channel,
  948. #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0)
  949. .set_sar_specs = rtw89_ops_set_sar_specs,
  950. #endif
  951. .sta_rc_update = rtw89_ops_sta_rc_update,
  952. .set_tid_config = rtw89_ops_set_tid_config,
  953. #ifdef CONFIG_PM
  954. .suspend = rtw89_ops_suspend,
  955. .resume = rtw89_ops_resume,
  956. .set_wakeup = rtw89_ops_set_wakeup,
  957. #endif
  958. };
  959. EXPORT_SYMBOL(rtw89_ops);