1b7dd3c2eSLorenzo Bianconi /* SPDX-License-Identifier: ISC */
2b7dd3c2eSLorenzo Bianconi /* Copyright (C) 2020 MediaTek Inc. */
3b7dd3c2eSLorenzo Bianconi
4b7dd3c2eSLorenzo Bianconi #ifndef __MT76_CONNAC_H
5b7dd3c2eSLorenzo Bianconi #define __MT76_CONNAC_H
6b7dd3c2eSLorenzo Bianconi
7b7dd3c2eSLorenzo Bianconi #include "mt76.h"
8b7dd3c2eSLorenzo Bianconi
9140efef3SLorenzo Bianconi enum rx_pkt_type {
10140efef3SLorenzo Bianconi PKT_TYPE_TXS,
11140efef3SLorenzo Bianconi PKT_TYPE_TXRXV,
12140efef3SLorenzo Bianconi PKT_TYPE_NORMAL,
13140efef3SLorenzo Bianconi PKT_TYPE_RX_DUP_RFB,
14140efef3SLorenzo Bianconi PKT_TYPE_RX_TMR,
15140efef3SLorenzo Bianconi PKT_TYPE_RETRIEVE,
16140efef3SLorenzo Bianconi PKT_TYPE_TXRX_NOTIFY,
17140efef3SLorenzo Bianconi PKT_TYPE_RX_EVENT,
18140efef3SLorenzo Bianconi PKT_TYPE_NORMAL_MCU,
19140efef3SLorenzo Bianconi PKT_TYPE_RX_FW_MONITOR = 0x0c,
20140efef3SLorenzo Bianconi PKT_TYPE_TXRX_NOTIFY_V0 = 0x18,
21140efef3SLorenzo Bianconi };
22140efef3SLorenzo Bianconi
23b7dd3c2eSLorenzo Bianconi #define MT76_CONNAC_SCAN_IE_LEN 600
24abded041SSean Wang #define MT76_CONNAC_MAX_NUM_SCHED_SCAN_INTERVAL 10
25abded041SSean Wang #define MT76_CONNAC_MAX_TIME_SCHED_SCAN_INTERVAL U16_MAX
26b7dd3c2eSLorenzo Bianconi #define MT76_CONNAC_MAX_SCHED_SCAN_SSID 10
27b7dd3c2eSLorenzo Bianconi #define MT76_CONNAC_MAX_SCAN_MATCH 16
28b7dd3c2eSLorenzo Bianconi
29182071cdSLorenzo Bianconi #define MT76_CONNAC_MAX_WMM_SETS 4
30182071cdSLorenzo Bianconi
310da3c795SSean Wang #define MT76_CONNAC_COREDUMP_TIMEOUT (HZ / 20)
32723885a6SSean Wang #define MT76_CONNAC_COREDUMP_SZ (1300 * 1024)
330da3c795SSean Wang
345c0bed88SLorenzo Bianconi #define MT_TXD_SIZE (8 * 4)
355c0bed88SLorenzo Bianconi
365c0bed88SLorenzo Bianconi #define MT_USB_TXD_SIZE (MT_TXD_SIZE + 8 * 4)
375c0bed88SLorenzo Bianconi #define MT_USB_HDR_SIZE 4
385c0bed88SLorenzo Bianconi #define MT_USB_TAIL_SIZE 4
395c0bed88SLorenzo Bianconi
405c0bed88SLorenzo Bianconi #define MT_SDIO_TXD_SIZE (MT_TXD_SIZE + 8 * 4)
415c0bed88SLorenzo Bianconi #define MT_SDIO_TAIL_SIZE 8
425c0bed88SLorenzo Bianconi #define MT_SDIO_HDR_SIZE 4
435c0bed88SLorenzo Bianconi
440a178a60SLorenzo Bianconi #define MT_MSDU_ID_VALID BIT(15)
450a178a60SLorenzo Bianconi
465e610f8eSLorenzo Bianconi #define MT_TXD_LEN_LAST BIT(15)
475e610f8eSLorenzo Bianconi #define MT_TXD_LEN_MASK GENMASK(11, 0)
485e610f8eSLorenzo Bianconi #define MT_TXD_LEN_MSDU_LAST BIT(14)
495e610f8eSLorenzo Bianconi #define MT_TXD_LEN_AMSDU_LAST BIT(15)
505e610f8eSLorenzo Bianconi
51b7dd3c2eSLorenzo Bianconi enum {
52b7dd3c2eSLorenzo Bianconi CMD_CBW_20MHZ = IEEE80211_STA_RX_BW_20,
53b7dd3c2eSLorenzo Bianconi CMD_CBW_40MHZ = IEEE80211_STA_RX_BW_40,
54b7dd3c2eSLorenzo Bianconi CMD_CBW_80MHZ = IEEE80211_STA_RX_BW_80,
55b7dd3c2eSLorenzo Bianconi CMD_CBW_160MHZ = IEEE80211_STA_RX_BW_160,
56b7dd3c2eSLorenzo Bianconi CMD_CBW_10MHZ,
57b7dd3c2eSLorenzo Bianconi CMD_CBW_5MHZ,
58b7dd3c2eSLorenzo Bianconi CMD_CBW_8080MHZ,
59e88c07e9SShayne Chen CMD_CBW_320MHZ,
60b7dd3c2eSLorenzo Bianconi
61b7dd3c2eSLorenzo Bianconi CMD_HE_MCS_BW80 = 0,
62b7dd3c2eSLorenzo Bianconi CMD_HE_MCS_BW160,
63b7dd3c2eSLorenzo Bianconi CMD_HE_MCS_BW8080,
64b7dd3c2eSLorenzo Bianconi CMD_HE_MCS_BW_NUM
65b7dd3c2eSLorenzo Bianconi };
66b7dd3c2eSLorenzo Bianconi
67b7dd3c2eSLorenzo Bianconi enum {
68b7dd3c2eSLorenzo Bianconi HW_BSSID_0 = 0x0,
69b7dd3c2eSLorenzo Bianconi HW_BSSID_1,
70b7dd3c2eSLorenzo Bianconi HW_BSSID_2,
71b7dd3c2eSLorenzo Bianconi HW_BSSID_3,
72b7dd3c2eSLorenzo Bianconi HW_BSSID_MAX = HW_BSSID_3,
73b7dd3c2eSLorenzo Bianconi EXT_BSSID_START = 0x10,
74b7dd3c2eSLorenzo Bianconi EXT_BSSID_1,
75b7dd3c2eSLorenzo Bianconi EXT_BSSID_15 = 0x1f,
76b7dd3c2eSLorenzo Bianconi EXT_BSSID_MAX = EXT_BSSID_15,
77b7dd3c2eSLorenzo Bianconi REPEATER_BSSID_START = 0x20,
78b7dd3c2eSLorenzo Bianconi REPEATER_BSSID_MAX = 0x3f,
79b7dd3c2eSLorenzo Bianconi };
80b7dd3c2eSLorenzo Bianconi
81e351f4f0SLorenzo Bianconi struct mt76_connac_reg_map {
82e351f4f0SLorenzo Bianconi u32 phys;
83e351f4f0SLorenzo Bianconi u32 maps;
84e351f4f0SLorenzo Bianconi u32 size;
85e351f4f0SLorenzo Bianconi };
86e351f4f0SLorenzo Bianconi
87b7dd3c2eSLorenzo Bianconi struct mt76_connac_pm {
884ad65a54SLorenzo Bianconi bool enable:1;
894ad65a54SLorenzo Bianconi bool enable_user:1;
904ad65a54SLorenzo Bianconi bool ds_enable:1;
914ad65a54SLorenzo Bianconi bool ds_enable_user:1;
924ad65a54SLorenzo Bianconi bool suspended:1;
93b7dd3c2eSLorenzo Bianconi
94b7dd3c2eSLorenzo Bianconi spinlock_t txq_lock;
95b7dd3c2eSLorenzo Bianconi struct {
96b7dd3c2eSLorenzo Bianconi struct mt76_wcid *wcid;
97b7dd3c2eSLorenzo Bianconi struct sk_buff *skb;
98b7dd3c2eSLorenzo Bianconi } tx_q[IEEE80211_NUM_ACS];
99b7dd3c2eSLorenzo Bianconi
100b7dd3c2eSLorenzo Bianconi struct work_struct wake_work;
101e5f35576SLorenzo Bianconi wait_queue_head_t wait;
1027f2bc8baSLorenzo Bianconi
1037f2bc8baSLorenzo Bianconi struct {
1047f2bc8baSLorenzo Bianconi spinlock_t lock;
1057f2bc8baSLorenzo Bianconi u32 count;
1067f2bc8baSLorenzo Bianconi } wake;
107fad90e43SLorenzo Bianconi struct mutex mutex;
108b7dd3c2eSLorenzo Bianconi
109b7dd3c2eSLorenzo Bianconi struct delayed_work ps_work;
110b7dd3c2eSLorenzo Bianconi unsigned long last_activity;
111b7dd3c2eSLorenzo Bianconi unsigned long idle_timeout;
11277ba3491SLorenzo Bianconi
11336873246SLorenzo Bianconi struct {
11436873246SLorenzo Bianconi unsigned long last_wake_event;
11536873246SLorenzo Bianconi unsigned long awake_time;
11636873246SLorenzo Bianconi unsigned long last_doze_event;
11736873246SLorenzo Bianconi unsigned long doze_time;
11877ba3491SLorenzo Bianconi unsigned int lp_wake;
11936873246SLorenzo Bianconi } stats;
120b7dd3c2eSLorenzo Bianconi };
121b7dd3c2eSLorenzo Bianconi
1220da3c795SSean Wang struct mt76_connac_coredump {
1230da3c795SSean Wang struct sk_buff_head msg_list;
1240da3c795SSean Wang struct delayed_work work;
1250da3c795SSean Wang unsigned long last_activity;
1260da3c795SSean Wang };
1270da3c795SSean Wang
1286683d988SLorenzo Bianconi struct mt76_connac_sta_key_conf {
1296683d988SLorenzo Bianconi s8 keyidx;
1306683d988SLorenzo Bianconi u8 key[16];
1316683d988SLorenzo Bianconi };
1326683d988SLorenzo Bianconi
1335c0bed88SLorenzo Bianconi #define MT_TXP_MAX_BUF_NUM 6
1345c0bed88SLorenzo Bianconi
1355c0bed88SLorenzo Bianconi struct mt76_connac_fw_txp {
1365c0bed88SLorenzo Bianconi __le16 flags;
1375c0bed88SLorenzo Bianconi __le16 token;
1385c0bed88SLorenzo Bianconi u8 bss_idx;
1395c0bed88SLorenzo Bianconi __le16 rept_wds_wcid;
1405c0bed88SLorenzo Bianconi u8 nbuf;
1415c0bed88SLorenzo Bianconi __le32 buf[MT_TXP_MAX_BUF_NUM];
1425c0bed88SLorenzo Bianconi __le16 len[MT_TXP_MAX_BUF_NUM];
1435c0bed88SLorenzo Bianconi } __packed __aligned(4);
1445c0bed88SLorenzo Bianconi
1454cb4da17SLorenzo Bianconi #define MT_HW_TXP_MAX_MSDU_NUM 4
1464cb4da17SLorenzo Bianconi #define MT_HW_TXP_MAX_BUF_NUM 4
1474cb4da17SLorenzo Bianconi
1484cb4da17SLorenzo Bianconi struct mt76_connac_txp_ptr {
1494cb4da17SLorenzo Bianconi __le32 buf0;
1504cb4da17SLorenzo Bianconi __le16 len0;
1514cb4da17SLorenzo Bianconi __le16 len1;
1524cb4da17SLorenzo Bianconi __le32 buf1;
1534cb4da17SLorenzo Bianconi } __packed __aligned(4);
1544cb4da17SLorenzo Bianconi
1554cb4da17SLorenzo Bianconi struct mt76_connac_hw_txp {
1564cb4da17SLorenzo Bianconi __le16 msdu_id[MT_HW_TXP_MAX_MSDU_NUM];
1574cb4da17SLorenzo Bianconi struct mt76_connac_txp_ptr ptr[MT_HW_TXP_MAX_BUF_NUM / 2];
1584cb4da17SLorenzo Bianconi } __packed __aligned(4);
1594cb4da17SLorenzo Bianconi
1604cb4da17SLorenzo Bianconi struct mt76_connac_txp_common {
1614cb4da17SLorenzo Bianconi union {
1624cb4da17SLorenzo Bianconi struct mt76_connac_fw_txp fw;
1634cb4da17SLorenzo Bianconi struct mt76_connac_hw_txp hw;
1644cb4da17SLorenzo Bianconi };
1654cb4da17SLorenzo Bianconi };
1664cb4da17SLorenzo Bianconi
1674b3be9d8SLorenzo Bianconi struct mt76_connac_tx_free {
1684b3be9d8SLorenzo Bianconi __le16 rx_byte_cnt;
1694b3be9d8SLorenzo Bianconi __le16 ctrl;
170a8021cb9SLorenzo Bianconi __le32 txd;
1714b3be9d8SLorenzo Bianconi } __packed __aligned(4);
1724b3be9d8SLorenzo Bianconi
173b7dd3c2eSLorenzo Bianconi extern const struct wiphy_wowlan_support mt76_connac_wowlan_support;
174b7dd3c2eSLorenzo Bianconi
is_mt7922(struct mt76_dev * dev)17568808872SDeren Wu static inline bool is_mt7922(struct mt76_dev *dev)
17668808872SDeren Wu {
17768808872SDeren Wu return mt76_chip(dev) == 0x7922;
17868808872SDeren Wu }
17968808872SDeren Wu
is_mt7921(struct mt76_dev * dev)18067aa2743SLorenzo Bianconi static inline bool is_mt7921(struct mt76_dev *dev)
18167aa2743SLorenzo Bianconi {
18268808872SDeren Wu return mt76_chip(dev) == 0x7961 || is_mt7922(dev);
18367aa2743SLorenzo Bianconi }
18467aa2743SLorenzo Bianconi
is_mt7663(struct mt76_dev * dev)1857139b5c0SSean Wang static inline bool is_mt7663(struct mt76_dev *dev)
1867139b5c0SSean Wang {
1877139b5c0SSean Wang return mt76_chip(dev) == 0x7663;
1887139b5c0SSean Wang }
1897139b5c0SSean Wang
is_mt7915(struct mt76_dev * dev)190e2c93b68SLorenzo Bianconi static inline bool is_mt7915(struct mt76_dev *dev)
191e2c93b68SLorenzo Bianconi {
192e2c93b68SLorenzo Bianconi return mt76_chip(dev) == 0x7915;
193e2c93b68SLorenzo Bianconi }
194e2c93b68SLorenzo Bianconi
is_mt7916(struct mt76_dev * dev)195cb143967SBo Jiao static inline bool is_mt7916(struct mt76_dev *dev)
196cb143967SBo Jiao {
197cb143967SBo Jiao return mt76_chip(dev) == 0x7906;
198cb143967SBo Jiao }
199cb143967SBo Jiao
is_mt7981(struct mt76_dev * dev)2006bad146dSAlexander Couzens static inline bool is_mt7981(struct mt76_dev *dev)
2016bad146dSAlexander Couzens {
2026bad146dSAlexander Couzens return mt76_chip(dev) == 0x7981;
2036bad146dSAlexander Couzens }
2046bad146dSAlexander Couzens
is_mt7986(struct mt76_dev * dev)20599ad32a4SBo Jiao static inline bool is_mt7986(struct mt76_dev *dev)
20699ad32a4SBo Jiao {
20799ad32a4SBo Jiao return mt76_chip(dev) == 0x7986;
20899ad32a4SBo Jiao }
20999ad32a4SBo Jiao
is_mt798x(struct mt76_dev * dev)2106bad146dSAlexander Couzens static inline bool is_mt798x(struct mt76_dev *dev)
2116bad146dSAlexander Couzens {
2126bad146dSAlexander Couzens return is_mt7981(dev) || is_mt7986(dev);
2136bad146dSAlexander Couzens }
2146bad146dSAlexander Couzens
is_mt7996(struct mt76_dev * dev)215a6cf2b65SShayne Chen static inline bool is_mt7996(struct mt76_dev *dev)
216a6cf2b65SShayne Chen {
217a6cf2b65SShayne Chen return mt76_chip(dev) == 0x7990;
218a6cf2b65SShayne Chen }
219a6cf2b65SShayne Chen
is_mt7622(struct mt76_dev * dev)2202fec2ea6SLorenzo Bianconi static inline bool is_mt7622(struct mt76_dev *dev)
2212fec2ea6SLorenzo Bianconi {
2222fec2ea6SLorenzo Bianconi if (!IS_ENABLED(CONFIG_MT7622_WMAC))
2232fec2ea6SLorenzo Bianconi return false;
2242fec2ea6SLorenzo Bianconi
2252fec2ea6SLorenzo Bianconi return mt76_chip(dev) == 0x7622;
2262fec2ea6SLorenzo Bianconi }
2272fec2ea6SLorenzo Bianconi
is_mt7615(struct mt76_dev * dev)2282fec2ea6SLorenzo Bianconi static inline bool is_mt7615(struct mt76_dev *dev)
2292fec2ea6SLorenzo Bianconi {
2302fec2ea6SLorenzo Bianconi return mt76_chip(dev) == 0x7615 || mt76_chip(dev) == 0x7611;
2312fec2ea6SLorenzo Bianconi }
2322fec2ea6SLorenzo Bianconi
is_mt7611(struct mt76_dev * dev)2332fec2ea6SLorenzo Bianconi static inline bool is_mt7611(struct mt76_dev *dev)
2342fec2ea6SLorenzo Bianconi {
2352fec2ea6SLorenzo Bianconi return mt76_chip(dev) == 0x7611;
2362fec2ea6SLorenzo Bianconi }
2372fec2ea6SLorenzo Bianconi
is_connac_v1(struct mt76_dev * dev)2382fec2ea6SLorenzo Bianconi static inline bool is_connac_v1(struct mt76_dev *dev)
2392fec2ea6SLorenzo Bianconi {
2402fec2ea6SLorenzo Bianconi return is_mt7615(dev) || is_mt7663(dev) || is_mt7622(dev);
2412fec2ea6SLorenzo Bianconi }
2422fec2ea6SLorenzo Bianconi
is_mt76_fw_txp(struct mt76_dev * dev)2430a178a60SLorenzo Bianconi static inline bool is_mt76_fw_txp(struct mt76_dev *dev)
2440a178a60SLorenzo Bianconi {
2450a178a60SLorenzo Bianconi switch (mt76_chip(dev)) {
2460a178a60SLorenzo Bianconi case 0x7961:
2470a178a60SLorenzo Bianconi case 0x7922:
2480a178a60SLorenzo Bianconi case 0x7663:
2490a178a60SLorenzo Bianconi case 0x7622:
2500a178a60SLorenzo Bianconi return false;
2510a178a60SLorenzo Bianconi default:
2520a178a60SLorenzo Bianconi return true;
2530a178a60SLorenzo Bianconi }
2540a178a60SLorenzo Bianconi }
2550a178a60SLorenzo Bianconi
mt76_connac_chan_bw(struct cfg80211_chan_def * chandef)25644c73d17SLorenzo Bianconi static inline u8 mt76_connac_chan_bw(struct cfg80211_chan_def *chandef)
25744c73d17SLorenzo Bianconi {
25844c73d17SLorenzo Bianconi static const u8 width_to_bw[] = {
25944c73d17SLorenzo Bianconi [NL80211_CHAN_WIDTH_40] = CMD_CBW_40MHZ,
26044c73d17SLorenzo Bianconi [NL80211_CHAN_WIDTH_80] = CMD_CBW_80MHZ,
26144c73d17SLorenzo Bianconi [NL80211_CHAN_WIDTH_80P80] = CMD_CBW_8080MHZ,
26244c73d17SLorenzo Bianconi [NL80211_CHAN_WIDTH_160] = CMD_CBW_160MHZ,
26344c73d17SLorenzo Bianconi [NL80211_CHAN_WIDTH_5] = CMD_CBW_5MHZ,
26444c73d17SLorenzo Bianconi [NL80211_CHAN_WIDTH_10] = CMD_CBW_10MHZ,
26544c73d17SLorenzo Bianconi [NL80211_CHAN_WIDTH_20] = CMD_CBW_20MHZ,
26644c73d17SLorenzo Bianconi [NL80211_CHAN_WIDTH_20_NOHT] = CMD_CBW_20MHZ,
267e88c07e9SShayne Chen [NL80211_CHAN_WIDTH_320] = CMD_CBW_320MHZ,
26844c73d17SLorenzo Bianconi };
26944c73d17SLorenzo Bianconi
27044c73d17SLorenzo Bianconi if (chandef->width >= ARRAY_SIZE(width_to_bw))
27144c73d17SLorenzo Bianconi return 0;
27244c73d17SLorenzo Bianconi
27344c73d17SLorenzo Bianconi return width_to_bw[chandef->width];
27444c73d17SLorenzo Bianconi }
27544c73d17SLorenzo Bianconi
mt76_connac_lmac_mapping(u8 ac)2764a74ecc8SLorenzo Bianconi static inline u8 mt76_connac_lmac_mapping(u8 ac)
2774a74ecc8SLorenzo Bianconi {
2784a74ecc8SLorenzo Bianconi /* LMAC uses the reverse order of mac80211 AC indexes */
2794a74ecc8SLorenzo Bianconi return 3 - ac;
2804a74ecc8SLorenzo Bianconi }
2814a74ecc8SLorenzo Bianconi
2825c0bed88SLorenzo Bianconi static inline void *
mt76_connac_txwi_to_txp(struct mt76_dev * dev,struct mt76_txwi_cache * t)2835c0bed88SLorenzo Bianconi mt76_connac_txwi_to_txp(struct mt76_dev *dev, struct mt76_txwi_cache *t)
2845c0bed88SLorenzo Bianconi {
2855c0bed88SLorenzo Bianconi u8 *txwi;
2865c0bed88SLorenzo Bianconi
2875c0bed88SLorenzo Bianconi if (!t)
2885c0bed88SLorenzo Bianconi return NULL;
2895c0bed88SLorenzo Bianconi
2905c0bed88SLorenzo Bianconi txwi = mt76_get_txwi_ptr(dev, t);
2915c0bed88SLorenzo Bianconi
2925c0bed88SLorenzo Bianconi return (void *)(txwi + MT_TXD_SIZE);
2935c0bed88SLorenzo Bianconi }
2945c0bed88SLorenzo Bianconi
mt76_connac_spe_idx(u8 antenna_mask)295faf2e7b5SShayne Chen static inline u8 mt76_connac_spe_idx(u8 antenna_mask)
296faf2e7b5SShayne Chen {
297faf2e7b5SShayne Chen static const u8 ant_to_spe[] = {0, 0, 1, 0, 3, 2, 4, 0,
298faf2e7b5SShayne Chen 9, 8, 6, 10, 16, 12, 18, 0};
299faf2e7b5SShayne Chen
300faf2e7b5SShayne Chen if (antenna_mask >= sizeof(ant_to_spe))
301faf2e7b5SShayne Chen return 0;
302faf2e7b5SShayne Chen
303faf2e7b5SShayne Chen return ant_to_spe[antenna_mask];
304faf2e7b5SShayne Chen }
305faf2e7b5SShayne Chen
mt76_connac_irq_enable(struct mt76_dev * dev,u32 mask)3064fc44156SLorenzo Bianconi static inline void mt76_connac_irq_enable(struct mt76_dev *dev, u32 mask)
3074fc44156SLorenzo Bianconi {
3084fc44156SLorenzo Bianconi mt76_set_irq_mask(dev, 0, 0, mask);
3094fc44156SLorenzo Bianconi tasklet_schedule(&dev->irq_tasklet);
3104fc44156SLorenzo Bianconi }
3114fc44156SLorenzo Bianconi
3121755f6adSLorenzo Bianconi int mt76_connac_pm_wake(struct mt76_phy *phy, struct mt76_connac_pm *pm);
3131755f6adSLorenzo Bianconi void mt76_connac_power_save_sched(struct mt76_phy *phy,
3141755f6adSLorenzo Bianconi struct mt76_connac_pm *pm);
3151755f6adSLorenzo Bianconi void mt76_connac_free_pending_tx_skbs(struct mt76_connac_pm *pm,
3161755f6adSLorenzo Bianconi struct mt76_wcid *wcid);
3171755f6adSLorenzo Bianconi
mt76_connac_tx_cleanup(struct mt76_dev * dev)3189dfb28e9SLorenzo Bianconi static inline void mt76_connac_tx_cleanup(struct mt76_dev *dev)
3199dfb28e9SLorenzo Bianconi {
3209dfb28e9SLorenzo Bianconi dev->queue_ops->tx_cleanup(dev, dev->q_mcu[MT_MCUQ_WM], false);
3219dfb28e9SLorenzo Bianconi dev->queue_ops->tx_cleanup(dev, dev->q_mcu[MT_MCUQ_WA], false);
3229dfb28e9SLorenzo Bianconi }
3239dfb28e9SLorenzo Bianconi
3247f2bc8baSLorenzo Bianconi static inline bool
mt76_connac_pm_ref(struct mt76_phy * phy,struct mt76_connac_pm * pm)3257f2bc8baSLorenzo Bianconi mt76_connac_pm_ref(struct mt76_phy *phy, struct mt76_connac_pm *pm)
3267f2bc8baSLorenzo Bianconi {
3277f2bc8baSLorenzo Bianconi bool ret = false;
3287f2bc8baSLorenzo Bianconi
3297f2bc8baSLorenzo Bianconi spin_lock_bh(&pm->wake.lock);
3307f2bc8baSLorenzo Bianconi if (test_bit(MT76_STATE_PM, &phy->state))
3317f2bc8baSLorenzo Bianconi goto out;
3327f2bc8baSLorenzo Bianconi
3337f2bc8baSLorenzo Bianconi pm->wake.count++;
3347f2bc8baSLorenzo Bianconi ret = true;
3357f2bc8baSLorenzo Bianconi out:
3367f2bc8baSLorenzo Bianconi spin_unlock_bh(&pm->wake.lock);
3377f2bc8baSLorenzo Bianconi
3387f2bc8baSLorenzo Bianconi return ret;
3397f2bc8baSLorenzo Bianconi }
3407f2bc8baSLorenzo Bianconi
3417f2bc8baSLorenzo Bianconi static inline void
mt76_connac_pm_unref(struct mt76_phy * phy,struct mt76_connac_pm * pm)3426ab079e2SLorenzo Bianconi mt76_connac_pm_unref(struct mt76_phy *phy, struct mt76_connac_pm *pm)
3437f2bc8baSLorenzo Bianconi {
3447f2bc8baSLorenzo Bianconi spin_lock_bh(&pm->wake.lock);
3456ab079e2SLorenzo Bianconi
3467f2bc8baSLorenzo Bianconi pm->last_activity = jiffies;
3476ab079e2SLorenzo Bianconi if (--pm->wake.count == 0 &&
3486ab079e2SLorenzo Bianconi test_bit(MT76_STATE_MCU_RUNNING, &phy->state))
3496ab079e2SLorenzo Bianconi mt76_connac_power_save_sched(phy, pm);
3506ab079e2SLorenzo Bianconi
3517f2bc8baSLorenzo Bianconi spin_unlock_bh(&pm->wake.lock);
3527f2bc8baSLorenzo Bianconi }
3537f2bc8baSLorenzo Bianconi
354ec7bd7b4SLorenzo Bianconi static inline bool
mt76_connac_skip_fw_pmctrl(struct mt76_phy * phy,struct mt76_connac_pm * pm)355ec7bd7b4SLorenzo Bianconi mt76_connac_skip_fw_pmctrl(struct mt76_phy *phy, struct mt76_connac_pm *pm)
356ec7bd7b4SLorenzo Bianconi {
3574bfa2912SSean Wang struct mt76_dev *dev = phy->dev;
358ec7bd7b4SLorenzo Bianconi bool ret;
359ec7bd7b4SLorenzo Bianconi
3604bfa2912SSean Wang if (dev->token_count)
3614bfa2912SSean Wang return true;
3624bfa2912SSean Wang
363ec7bd7b4SLorenzo Bianconi spin_lock_bh(&pm->wake.lock);
364ec7bd7b4SLorenzo Bianconi ret = pm->wake.count || test_and_set_bit(MT76_STATE_PM, &phy->state);
365ec7bd7b4SLorenzo Bianconi spin_unlock_bh(&pm->wake.lock);
366ec7bd7b4SLorenzo Bianconi
367ec7bd7b4SLorenzo Bianconi return ret;
368ec7bd7b4SLorenzo Bianconi }
369ec7bd7b4SLorenzo Bianconi
3701755f6adSLorenzo Bianconi static inline void
mt76_connac_mutex_acquire(struct mt76_dev * dev,struct mt76_connac_pm * pm)3711755f6adSLorenzo Bianconi mt76_connac_mutex_acquire(struct mt76_dev *dev, struct mt76_connac_pm *pm)
3721755f6adSLorenzo Bianconi __acquires(&dev->mutex)
3731755f6adSLorenzo Bianconi {
3741755f6adSLorenzo Bianconi mutex_lock(&dev->mutex);
3751755f6adSLorenzo Bianconi mt76_connac_pm_wake(&dev->phy, pm);
3761755f6adSLorenzo Bianconi }
3771755f6adSLorenzo Bianconi
3781755f6adSLorenzo Bianconi static inline void
mt76_connac_mutex_release(struct mt76_dev * dev,struct mt76_connac_pm * pm)3791755f6adSLorenzo Bianconi mt76_connac_mutex_release(struct mt76_dev *dev, struct mt76_connac_pm *pm)
3801755f6adSLorenzo Bianconi __releases(&dev->mutex)
3811755f6adSLorenzo Bianconi {
3821755f6adSLorenzo Bianconi mt76_connac_power_save_sched(&dev->phy, pm);
3831755f6adSLorenzo Bianconi mutex_unlock(&dev->mutex);
3841755f6adSLorenzo Bianconi }
3851755f6adSLorenzo Bianconi
3866a8b899dSLorenzo Bianconi void mt76_connac_gen_ppe_thresh(u8 *he_ppet, int nss);
3879dfb28e9SLorenzo Bianconi int mt76_connac_init_tx_queues(struct mt76_phy *phy, int idx, int n_desc,
3889dfb28e9SLorenzo Bianconi int ring_base, u32 flags);
3895e610f8eSLorenzo Bianconi void mt76_connac_write_hw_txp(struct mt76_dev *dev,
3905e610f8eSLorenzo Bianconi struct mt76_tx_info *tx_info,
3915e610f8eSLorenzo Bianconi void *txp_ptr, u32 id);
3922b25b855SLorenzo Bianconi void mt76_connac_txp_skb_unmap(struct mt76_dev *dev,
3932b25b855SLorenzo Bianconi struct mt76_txwi_cache *txwi);
3940a178a60SLorenzo Bianconi void mt76_connac_tx_complete_skb(struct mt76_dev *mdev,
3950a178a60SLorenzo Bianconi struct mt76_queue_entry *e);
3961755f6adSLorenzo Bianconi void mt76_connac_pm_queue_skb(struct ieee80211_hw *hw,
3971755f6adSLorenzo Bianconi struct mt76_connac_pm *pm,
3981755f6adSLorenzo Bianconi struct mt76_wcid *wcid,
3991755f6adSLorenzo Bianconi struct sk_buff *skb);
4001755f6adSLorenzo Bianconi void mt76_connac_pm_dequeue_skbs(struct mt76_phy *phy,
4011755f6adSLorenzo Bianconi struct mt76_connac_pm *pm);
402182071cdSLorenzo Bianconi void mt76_connac2_mac_write_txwi(struct mt76_dev *dev, __le32 *txwi,
403182071cdSLorenzo Bianconi struct sk_buff *skb, struct mt76_wcid *wcid,
404182071cdSLorenzo Bianconi struct ieee80211_key_conf *key, int pid,
4051d5af0acSFelix Fietkau enum mt76_txq_id qid, u32 changed);
4060b8e2d69SLorenzo Bianconi u16 mt76_connac2_mac_tx_rate_val(struct mt76_phy *mphy,
4070b8e2d69SLorenzo Bianconi struct ieee80211_vif *vif,
4080b8e2d69SLorenzo Bianconi bool beacon, bool mcast);
40943eaa368SRyder Lee bool mt76_connac2_mac_fill_txs(struct mt76_dev *dev, struct mt76_wcid *wcid,
41043eaa368SRyder Lee __le32 *txs_data);
411b932425bSLorenzo Bianconi bool mt76_connac2_mac_add_txs_skb(struct mt76_dev *dev, struct mt76_wcid *wcid,
412dc877523SRyder Lee int pid, __le32 *txs_data);
413f71662deSLorenzo Bianconi void mt76_connac2_mac_decode_he_radiotap(struct mt76_dev *dev,
414f71662deSLorenzo Bianconi struct sk_buff *skb,
415f71662deSLorenzo Bianconi __le32 *rxv, u32 mode);
4160880d408SLorenzo Bianconi int mt76_connac2_reverse_frag0_hdr_trans(struct ieee80211_vif *vif,
4170880d408SLorenzo Bianconi struct sk_buff *skb, u16 hdr_offset);
418d832f5e7SLorenzo Bianconi int mt76_connac2_mac_fill_rx_rate(struct mt76_dev *dev,
419d832f5e7SLorenzo Bianconi struct mt76_rx_status *status,
420d832f5e7SLorenzo Bianconi struct ieee80211_supported_band *sband,
421d832f5e7SLorenzo Bianconi __le32 *rxv, u8 *mode);
422c8e370feSLorenzo Bianconi void mt76_connac2_tx_check_aggr(struct ieee80211_sta *sta, __le32 *txwi);
423c8e370feSLorenzo Bianconi void mt76_connac2_txwi_free(struct mt76_dev *dev, struct mt76_txwi_cache *t,
424c8e370feSLorenzo Bianconi struct ieee80211_sta *sta,
425c8e370feSLorenzo Bianconi struct list_head *free_list);
426c8e370feSLorenzo Bianconi void mt76_connac2_tx_token_put(struct mt76_dev *dev);
4271755f6adSLorenzo Bianconi
428*46d3304dSLorenzo Bianconi /* connac3 */
429*46d3304dSLorenzo Bianconi void mt76_connac3_mac_decode_he_radiotap(struct sk_buff *skb, __le32 *rxv,
430*46d3304dSLorenzo Bianconi u8 mode);
431b7dd3c2eSLorenzo Bianconi #endif /* __MT76_CONNAC_H */
432