10e3d6777SRyder Lee /* SPDX-License-Identifier: ISC */ 217f1de56SFelix Fietkau /* 317f1de56SFelix Fietkau * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name> 417f1de56SFelix Fietkau */ 517f1de56SFelix Fietkau 617f1de56SFelix Fietkau #ifndef __MT76_H 717f1de56SFelix Fietkau #define __MT76_H 817f1de56SFelix Fietkau 917f1de56SFelix Fietkau #include <linux/kernel.h> 1017f1de56SFelix Fietkau #include <linux/io.h> 1117f1de56SFelix Fietkau #include <linux/spinlock.h> 1217f1de56SFelix Fietkau #include <linux/skbuff.h> 1317f1de56SFelix Fietkau #include <linux/leds.h> 14b40b15e1SLorenzo Bianconi #include <linux/usb.h> 15ef13edc0SFelix Fietkau #include <linux/average.h> 16f68d6762SFelix Fietkau #include <linux/soc/mediatek/mtk_wed.h> 1717f1de56SFelix Fietkau #include <net/mac80211.h> 18a9ca9f9cSYunsheng Lin #include <net/page_pool/helpers.h> 1917f1de56SFelix Fietkau #include "util.h" 20f0efa862SFelix Fietkau #include "testmode.h" 2117f1de56SFelix Fietkau 2217f1de56SFelix Fietkau #define MT_MCU_RING_SIZE 32 2317f1de56SFelix Fietkau #define MT_RX_BUF_SIZE 2048 24123bc712SDeren Wu #define MT_SKB_HEAD_LEN 256 2517f1de56SFelix Fietkau 26e1378e52SFelix Fietkau #define MT_MAX_NON_AQL_PKT 16 27e1378e52SFelix Fietkau #define MT_TXQ_FREE_THR 32 28e1378e52SFelix Fietkau 29d089692bSLorenzo Bianconi #define MT76_TOKEN_FREE_THR 64 30d089692bSLorenzo Bianconi 31f68d6762SFelix Fietkau #define MT_QFLAG_WED_RING GENMASK(1, 0) 32af8d2af5SLorenzo Bianconi #define MT_QFLAG_WED_TYPE GENMASK(4, 2) 33af8d2af5SLorenzo Bianconi #define MT_QFLAG_WED BIT(5) 34950d0abbSBo Jiao #define MT_QFLAG_WED_RRO BIT(6) 35950d0abbSBo Jiao #define MT_QFLAG_WED_RRO_EN BIT(7) 36f68d6762SFelix Fietkau 37f68d6762SFelix Fietkau #define __MT_WED_Q(_type, _n) (MT_QFLAG_WED | \ 38f68d6762SFelix Fietkau FIELD_PREP(MT_QFLAG_WED_TYPE, _type) | \ 39f68d6762SFelix Fietkau FIELD_PREP(MT_QFLAG_WED_RING, _n)) 40950d0abbSBo Jiao #define __MT_WED_RRO_Q(_type, _n) (MT_QFLAG_WED_RRO | __MT_WED_Q(_type, _n)) 41950d0abbSBo Jiao 42f68d6762SFelix Fietkau #define MT_WED_Q_TX(_n) __MT_WED_Q(MT76_WED_Q_TX, _n) 43cd372b8cSLorenzo Bianconi #define MT_WED_Q_RX(_n) __MT_WED_Q(MT76_WED_Q_RX, _n) 44f68d6762SFelix Fietkau #define MT_WED_Q_TXFREE __MT_WED_Q(MT76_WED_Q_TXFREE, 0) 45950d0abbSBo Jiao #define MT_WED_RRO_Q_DATA(_n) __MT_WED_RRO_Q(MT76_WED_RRO_Q_DATA, _n) 46950d0abbSBo Jiao #define MT_WED_RRO_Q_MSDU_PG(_n) __MT_WED_RRO_Q(MT76_WED_RRO_Q_MSDU_PG, _n) 47950d0abbSBo Jiao #define MT_WED_RRO_Q_IND __MT_WED_RRO_Q(MT76_WED_RRO_Q_IND, 0) 48f68d6762SFelix Fietkau 4917f1de56SFelix Fietkau struct mt76_dev; 5096747a51SFelix Fietkau struct mt76_phy; 51469d4818SLorenzo Bianconi struct mt76_wcid; 523ad08509SLorenzo Bianconi struct mt76s_intr; 5382334623SFelix Fietkau struct mt76_chanctx; 5482334623SFelix Fietkau struct mt76_vif_link; 5517f1de56SFelix Fietkau 566da5a291SStanislaw Gruszka struct mt76_reg_pair { 576da5a291SStanislaw Gruszka u32 reg; 586da5a291SStanislaw Gruszka u32 value; 596da5a291SStanislaw Gruszka }; 606da5a291SStanislaw Gruszka 61c50479faSStanislaw Gruszka enum mt76_bus_type { 62c50479faSStanislaw Gruszka MT76_BUS_MMIO, 63c50479faSStanislaw Gruszka MT76_BUS_USB, 64d39b52e3SSean Wang MT76_BUS_SDIO, 65c50479faSStanislaw Gruszka }; 66c50479faSStanislaw Gruszka 67f68d6762SFelix Fietkau enum mt76_wed_type { 68f68d6762SFelix Fietkau MT76_WED_Q_TX, 69f68d6762SFelix Fietkau MT76_WED_Q_TXFREE, 70cd372b8cSLorenzo Bianconi MT76_WED_Q_RX, 71950d0abbSBo Jiao MT76_WED_RRO_Q_DATA, 72950d0abbSBo Jiao MT76_WED_RRO_Q_MSDU_PG, 73950d0abbSBo Jiao MT76_WED_RRO_Q_IND, 74f68d6762SFelix Fietkau }; 75f68d6762SFelix Fietkau 7617f1de56SFelix Fietkau struct mt76_bus_ops { 7717f1de56SFelix Fietkau u32 (*rr)(struct mt76_dev *dev, u32 offset); 7817f1de56SFelix Fietkau void (*wr)(struct mt76_dev *dev, u32 offset, u32 val); 7917f1de56SFelix Fietkau u32 (*rmw)(struct mt76_dev *dev, u32 offset, u32 mask, u32 val); 8035e4ebeaSLorenzo Bianconi void (*write_copy)(struct mt76_dev *dev, u32 offset, const void *data, 8135e4ebeaSLorenzo Bianconi int len); 8235e4ebeaSLorenzo Bianconi void (*read_copy)(struct mt76_dev *dev, u32 offset, void *data, 8317f1de56SFelix Fietkau int len); 846da5a291SStanislaw Gruszka int (*wr_rp)(struct mt76_dev *dev, u32 base, 856da5a291SStanislaw Gruszka const struct mt76_reg_pair *rp, int len); 866da5a291SStanislaw Gruszka int (*rd_rp)(struct mt76_dev *dev, u32 base, 876da5a291SStanislaw Gruszka struct mt76_reg_pair *rp, int len); 88c50479faSStanislaw Gruszka enum mt76_bus_type type; 8917f1de56SFelix Fietkau }; 9017f1de56SFelix Fietkau 9161c51a74SLorenzo Bianconi #define mt76_is_usb(dev) ((dev)->bus->type == MT76_BUS_USB) 9261c51a74SLorenzo Bianconi #define mt76_is_mmio(dev) ((dev)->bus->type == MT76_BUS_MMIO) 93d39b52e3SSean Wang #define mt76_is_sdio(dev) ((dev)->bus->type == MT76_BUS_SDIO) 94c50479faSStanislaw Gruszka 9517f1de56SFelix Fietkau enum mt76_txq_id { 9617f1de56SFelix Fietkau MT_TXQ_VO = IEEE80211_AC_VO, 9717f1de56SFelix Fietkau MT_TXQ_VI = IEEE80211_AC_VI, 9817f1de56SFelix Fietkau MT_TXQ_BE = IEEE80211_AC_BE, 9917f1de56SFelix Fietkau MT_TXQ_BK = IEEE80211_AC_BK, 10017f1de56SFelix Fietkau MT_TXQ_PSD, 10117f1de56SFelix Fietkau MT_TXQ_BEACON, 10217f1de56SFelix Fietkau MT_TXQ_CAB, 10317f1de56SFelix Fietkau __MT_TXQ_MAX 10417f1de56SFelix Fietkau }; 10517f1de56SFelix Fietkau 106b1cb42adSLorenzo Bianconi enum mt76_mcuq_id { 107e637763bSLorenzo Bianconi MT_MCUQ_WM, 108e637763bSLorenzo Bianconi MT_MCUQ_WA, 109e637763bSLorenzo Bianconi MT_MCUQ_FWDL, 110b1cb42adSLorenzo Bianconi __MT_MCUQ_MAX 111b1cb42adSLorenzo Bianconi }; 112b1cb42adSLorenzo Bianconi 11317f1de56SFelix Fietkau enum mt76_rxq_id { 11417f1de56SFelix Fietkau MT_RXQ_MAIN, 11517f1de56SFelix Fietkau MT_RXQ_MCU, 116d3377b78SRyder Lee MT_RXQ_MCU_WA, 117fc8f841bSLorenzo Bianconi MT_RXQ_BAND1, 118fc8f841bSLorenzo Bianconi MT_RXQ_BAND1_WA, 119f9b627f1SBo Jiao MT_RXQ_MAIN_WA, 120fc8f841bSLorenzo Bianconi MT_RXQ_BAND2, 121fc8f841bSLorenzo Bianconi MT_RXQ_BAND2_WA, 12283eafc92SSujuan Chen MT_RXQ_RRO_BAND0, 12383eafc92SSujuan Chen MT_RXQ_RRO_BAND1, 12483eafc92SSujuan Chen MT_RXQ_RRO_BAND2, 12583eafc92SSujuan Chen MT_RXQ_MSDU_PAGE_BAND0, 12683eafc92SSujuan Chen MT_RXQ_MSDU_PAGE_BAND1, 12783eafc92SSujuan Chen MT_RXQ_MSDU_PAGE_BAND2, 12883eafc92SSujuan Chen MT_RXQ_TXFREE_BAND0, 12983eafc92SSujuan Chen MT_RXQ_TXFREE_BAND1, 13083eafc92SSujuan Chen MT_RXQ_TXFREE_BAND2, 13183eafc92SSujuan Chen MT_RXQ_RRO_IND, 13217f1de56SFelix Fietkau __MT_RXQ_MAX 13317f1de56SFelix Fietkau }; 13417f1de56SFelix Fietkau 135dc44c45cSLorenzo Bianconi enum mt76_band_id { 136dc44c45cSLorenzo Bianconi MT_BAND0, 137dc44c45cSLorenzo Bianconi MT_BAND1, 138dc44c45cSLorenzo Bianconi MT_BAND2, 139dc44c45cSLorenzo Bianconi __MT_MAX_BAND 140dc44c45cSLorenzo Bianconi }; 141dc44c45cSLorenzo Bianconi 142c368362cSRyder Lee enum mt76_cipher_type { 143c368362cSRyder Lee MT_CIPHER_NONE, 144c368362cSRyder Lee MT_CIPHER_WEP40, 145c368362cSRyder Lee MT_CIPHER_TKIP, 146c368362cSRyder Lee MT_CIPHER_TKIP_NO_MIC, 147c368362cSRyder Lee MT_CIPHER_AES_CCMP, 148c368362cSRyder Lee MT_CIPHER_WEP104, 149c368362cSRyder Lee MT_CIPHER_BIP_CMAC_128, 150c368362cSRyder Lee MT_CIPHER_WEP128, 151c368362cSRyder Lee MT_CIPHER_WAPI, 152c368362cSRyder Lee MT_CIPHER_CCMP_CCX, 153c368362cSRyder Lee MT_CIPHER_CCMP_256, 154c368362cSRyder Lee MT_CIPHER_GCMP, 155c368362cSRyder Lee MT_CIPHER_GCMP_256, 156c368362cSRyder Lee }; 157c368362cSRyder Lee 1583f306448SFelix Fietkau enum mt76_dfs_state { 1593f306448SFelix Fietkau MT_DFS_STATE_UNKNOWN, 1603f306448SFelix Fietkau MT_DFS_STATE_DISABLED, 1613f306448SFelix Fietkau MT_DFS_STATE_CAC, 1623f306448SFelix Fietkau MT_DFS_STATE_ACTIVE, 1633f306448SFelix Fietkau }; 1643f306448SFelix Fietkau 165*913a6182SMing Yen Hsieh #define MT76_RNR_SCAN_MAX_BSSIDS 16 166*913a6182SMing Yen Hsieh struct mt76_scan_rnr_param { 167*913a6182SMing Yen Hsieh u8 bssid[MT76_RNR_SCAN_MAX_BSSIDS][ETH_ALEN]; 168*913a6182SMing Yen Hsieh u8 channel[MT76_RNR_SCAN_MAX_BSSIDS]; 169*913a6182SMing Yen Hsieh u8 random_mac[ETH_ALEN]; 170*913a6182SMing Yen Hsieh u8 seq_num; 171*913a6182SMing Yen Hsieh u8 bssid_num; 172*913a6182SMing Yen Hsieh u32 sreq_flag; 173*913a6182SMing Yen Hsieh }; 174*913a6182SMing Yen Hsieh 17517f1de56SFelix Fietkau struct mt76_queue_buf { 17617f1de56SFelix Fietkau dma_addr_t addr; 177c3778443SFelix Fietkau u16 len:15, 178c3778443SFelix Fietkau skip_unmap:1; 17917f1de56SFelix Fietkau }; 18017f1de56SFelix Fietkau 181b5903c47SLorenzo Bianconi struct mt76_tx_info { 182b5903c47SLorenzo Bianconi struct mt76_queue_buf buf[32]; 183cfaae9e6SLorenzo Bianconi struct sk_buff *skb; 184b5903c47SLorenzo Bianconi int nbuf; 185b5903c47SLorenzo Bianconi u32 info; 186b5903c47SLorenzo Bianconi }; 187b5903c47SLorenzo Bianconi 18817f1de56SFelix Fietkau struct mt76_queue_entry { 18917f1de56SFelix Fietkau union { 19017f1de56SFelix Fietkau void *buf; 19117f1de56SFelix Fietkau struct sk_buff *skb; 19217f1de56SFelix Fietkau }; 193b40b15e1SLorenzo Bianconi union { 19417f1de56SFelix Fietkau struct mt76_txwi_cache *txwi; 195d7d4ea9aSStanislaw Gruszka struct urb *urb; 196d39b52e3SSean Wang int buf_sz; 197b40b15e1SLorenzo Bianconi }; 1984920a3a1SSujuan Chen dma_addr_t dma_addr[2]; 19975d4bf1fSFelix Fietkau u16 dma_len[2]; 200e1378e52SFelix Fietkau u16 wcid; 2017bd0650bSLorenzo Bianconi bool skip_buf0:1; 20227d5c528SFelix Fietkau bool skip_buf1:1; 2037bd0650bSLorenzo Bianconi bool done:1; 20417f1de56SFelix Fietkau }; 20517f1de56SFelix Fietkau 20617f1de56SFelix Fietkau struct mt76_queue_regs { 20717f1de56SFelix Fietkau u32 desc_base; 20817f1de56SFelix Fietkau u32 ring_size; 20917f1de56SFelix Fietkau u32 cpu_idx; 21017f1de56SFelix Fietkau u32 dma_idx; 21117f1de56SFelix Fietkau } __packed __aligned(4); 21217f1de56SFelix Fietkau 21317f1de56SFelix Fietkau struct mt76_queue { 21417f1de56SFelix Fietkau struct mt76_queue_regs __iomem *regs; 21517f1de56SFelix Fietkau 21617f1de56SFelix Fietkau spinlock_t lock; 2179716ef04SFelix Fietkau spinlock_t cleanup_lock; 21817f1de56SFelix Fietkau struct mt76_queue_entry *entry; 219950d0abbSBo Jiao struct mt76_rro_desc *rro_desc; 22017f1de56SFelix Fietkau struct mt76_desc *desc; 22117f1de56SFelix Fietkau 222b40b15e1SLorenzo Bianconi u16 first; 22317f1de56SFelix Fietkau u16 head; 22417f1de56SFelix Fietkau u16 tail; 2255304bf3bSLorenzo Bianconi u8 hw_idx; 2265304bf3bSLorenzo Bianconi u8 ep; 22717f1de56SFelix Fietkau int ndesc; 22817f1de56SFelix Fietkau int queued; 22917f1de56SFelix Fietkau int buf_size; 230cd44bc40SLorenzo Bianconi bool stopped; 23190d494c9SFelix Fietkau bool blocked; 23217f1de56SFelix Fietkau 23317f1de56SFelix Fietkau u8 buf_offset; 234950d0abbSBo Jiao u16 flags; 235f68d6762SFelix Fietkau 2362e420b88SLorenzo Bianconi struct mtk_wed_device *wed; 237f68d6762SFelix Fietkau u32 wed_regs; 23817f1de56SFelix Fietkau 23917f1de56SFelix Fietkau dma_addr_t desc_dma; 24017f1de56SFelix Fietkau struct sk_buff *rx_head; 2412f5c3c77SLorenzo Bianconi struct page_pool *page_pool; 24217f1de56SFelix Fietkau }; 24317f1de56SFelix Fietkau 244db0f04f3SLorenzo Bianconi struct mt76_mcu_ops { 2453688c18bSFelix Fietkau unsigned int max_retry; 246bb31a80eSLorenzo Bianconi u32 headroom; 247bb31a80eSLorenzo Bianconi u32 tailroom; 248bb31a80eSLorenzo Bianconi 249a74d6336SStanislaw Gruszka int (*mcu_send_msg)(struct mt76_dev *dev, int cmd, const void *data, 250a74d6336SStanislaw Gruszka int len, bool wait_resp); 2513688c18bSFelix Fietkau int (*mcu_skb_prepare_msg)(struct mt76_dev *dev, struct sk_buff *skb, 2523688c18bSFelix Fietkau int cmd, int *seq); 253f4d45fe2SLorenzo Bianconi int (*mcu_skb_send_msg)(struct mt76_dev *dev, struct sk_buff *skb, 254e452c6ebSFelix Fietkau int cmd, int *seq); 255f320d812SFelix Fietkau int (*mcu_parse_response)(struct mt76_dev *dev, int cmd, 256f320d812SFelix Fietkau struct sk_buff *skb, int seq); 257d39b52e3SSean Wang u32 (*mcu_rr)(struct mt76_dev *dev, u32 offset); 258d39b52e3SSean Wang void (*mcu_wr)(struct mt76_dev *dev, u32 offset, u32 val); 2596da5a291SStanislaw Gruszka int (*mcu_wr_rp)(struct mt76_dev *dev, u32 base, 2606da5a291SStanislaw Gruszka const struct mt76_reg_pair *rp, int len); 2616da5a291SStanislaw Gruszka int (*mcu_rd_rp)(struct mt76_dev *dev, u32 base, 2626da5a291SStanislaw Gruszka struct mt76_reg_pair *rp, int len); 26300496042SFelix Fietkau int (*mcu_restart)(struct mt76_dev *dev); 264db0f04f3SLorenzo Bianconi }; 265db0f04f3SLorenzo Bianconi 26617f1de56SFelix Fietkau struct mt76_queue_ops { 267cb8ed33dSLorenzo Bianconi int (*init)(struct mt76_dev *dev, 268cb8ed33dSLorenzo Bianconi int (*poll)(struct napi_struct *napi, int budget)); 26917f1de56SFelix Fietkau 270b1bfbe70SLorenzo Bianconi int (*alloc)(struct mt76_dev *dev, struct mt76_queue *q, 271b1bfbe70SLorenzo Bianconi int idx, int n_desc, int bufsize, 272b1bfbe70SLorenzo Bianconi u32 ring_base); 27317f1de56SFelix Fietkau 2745d581c33SFelix Fietkau int (*tx_queue_skb)(struct mt76_phy *phy, struct mt76_queue *q, 275d08295f5SFelix Fietkau enum mt76_txq_id qid, struct sk_buff *skb, 276d08295f5SFelix Fietkau struct mt76_wcid *wcid, struct ieee80211_sta *sta); 277469d4818SLorenzo Bianconi 278d95093a1SLorenzo Bianconi int (*tx_queue_skb_raw)(struct mt76_dev *dev, struct mt76_queue *q, 2795ed31128SLorenzo Bianconi struct sk_buff *skb, u32 tx_info); 2805ed31128SLorenzo Bianconi 28117f1de56SFelix Fietkau void *(*dequeue)(struct mt76_dev *dev, struct mt76_queue *q, bool flush, 28217f1de56SFelix Fietkau int *len, u32 *info, bool *more); 28317f1de56SFelix Fietkau 28417f1de56SFelix Fietkau void (*rx_reset)(struct mt76_dev *dev, enum mt76_rxq_id qid); 28517f1de56SFelix Fietkau 286e5655492SLorenzo Bianconi void (*tx_cleanup)(struct mt76_dev *dev, struct mt76_queue *q, 28717f1de56SFelix Fietkau bool flush); 28817f1de56SFelix Fietkau 289c001df97SLorenzo Bianconi void (*rx_cleanup)(struct mt76_dev *dev, struct mt76_queue *q); 290c001df97SLorenzo Bianconi 29117f1de56SFelix Fietkau void (*kick)(struct mt76_dev *dev, struct mt76_queue *q); 2923990465dSLorenzo Bianconi 2933990465dSLorenzo Bianconi void (*reset_q)(struct mt76_dev *dev, struct mt76_queue *q); 29417f1de56SFelix Fietkau }; 29517f1de56SFelix Fietkau 296dc877523SRyder Lee enum mt76_phy_type { 297dc877523SRyder Lee MT_PHY_TYPE_CCK, 298dc877523SRyder Lee MT_PHY_TYPE_OFDM, 299dc877523SRyder Lee MT_PHY_TYPE_HT, 300dc877523SRyder Lee MT_PHY_TYPE_HT_GF, 301dc877523SRyder Lee MT_PHY_TYPE_VHT, 302dc877523SRyder Lee MT_PHY_TYPE_HE_SU = 8, 303dc877523SRyder Lee MT_PHY_TYPE_HE_EXT_SU, 304dc877523SRyder Lee MT_PHY_TYPE_HE_TB, 305dc877523SRyder Lee MT_PHY_TYPE_HE_MU, 306c2eccffdSShayne Chen MT_PHY_TYPE_EHT_SU = 13, 307c2eccffdSShayne Chen MT_PHY_TYPE_EHT_TRIG, 308c2eccffdSShayne Chen MT_PHY_TYPE_EHT_MU, 309c2eccffdSShayne Chen __MT_PHY_TYPE_MAX, 310dc877523SRyder Lee }; 311dc877523SRyder Lee 312dc877523SRyder Lee struct mt76_sta_stats { 313c2eccffdSShayne Chen u64 tx_mode[__MT_PHY_TYPE_MAX]; 314731425f3SShayne Chen u64 tx_bw[5]; /* 20, 40, 80, 160, 320 */ 315dc877523SRyder Lee u64 tx_nss[4]; /* 1, 2, 3, 4 */ 316dc877523SRyder Lee u64 tx_mcs[16]; /* mcs idx */ 31743eaa368SRyder Lee u64 tx_bytes; 318c6cde7b7SSujuan Chen /* WED TX */ 319161a7528SPeter Chiu u32 tx_packets; /* unit: MSDU */ 32043eaa368SRyder Lee u32 tx_retries; 32143eaa368SRyder Lee u32 tx_failed; 322c6cde7b7SSujuan Chen /* WED RX */ 323c6cde7b7SSujuan Chen u64 rx_bytes; 324c6cde7b7SSujuan Chen u32 rx_packets; 325c6cde7b7SSujuan Chen u32 rx_errors; 326c6cde7b7SSujuan Chen u32 rx_drops; 327dc877523SRyder Lee }; 328dc877523SRyder Lee 329d71ef286SFelix Fietkau enum mt76_wcid_flags { 330d71ef286SFelix Fietkau MT_WCID_FLAG_CHECK_PS, 331d71ef286SFelix Fietkau MT_WCID_FLAG_PS, 332e151d71eSFelix Fietkau MT_WCID_FLAG_4ADDR, 33390e3abf0SFelix Fietkau MT_WCID_FLAG_HDR_TRANS, 334d71ef286SFelix Fietkau }; 335d71ef286SFelix Fietkau 3366b733f7cSShayne Chen #define MT76_N_WCIDS 1088 33736404c06SStanislaw Gruszka 338e394b575SFelix Fietkau /* stored in ieee80211_tx_info::hw_queue */ 339a062f001SLorenzo Bianconi #define MT_TX_HW_QUEUE_PHY GENMASK(3, 2) 340e394b575SFelix Fietkau 341ef13edc0SFelix Fietkau DECLARE_EWMA(signal, 10, 8); 342ef13edc0SFelix Fietkau 343db9f11d3SFelix Fietkau #define MT_WCID_TX_INFO_RATE GENMASK(15, 0) 344db9f11d3SFelix Fietkau #define MT_WCID_TX_INFO_NSS GENMASK(17, 16) 345db9f11d3SFelix Fietkau #define MT_WCID_TX_INFO_TXPWR_ADJ GENMASK(25, 18) 346db9f11d3SFelix Fietkau #define MT_WCID_TX_INFO_SET BIT(31) 347db9f11d3SFelix Fietkau 34817f1de56SFelix Fietkau struct mt76_wcid { 349aee5b8cfSFelix Fietkau struct mt76_rx_tid __rcu *aggr[IEEE80211_NUM_TIDS]; 350aee5b8cfSFelix Fietkau 351e1378e52SFelix Fietkau atomic_t non_aql_packets; 352d71ef286SFelix Fietkau unsigned long flags; 353d71ef286SFelix Fietkau 354ef13edc0SFelix Fietkau struct ewma_signal rssi; 355ef13edc0SFelix Fietkau int inactive_count; 356ef13edc0SFelix Fietkau 3579908d98aSRyder Lee struct rate_info rate; 358ef591d74SLorenzo Bianconi unsigned long ampdu_state; 3599908d98aSRyder Lee 36049e649c3SRyder Lee u16 idx; 36117f1de56SFelix Fietkau u8 hw_key_idx; 362730d6d0dSFelix Fietkau u8 hw_key_idx2; 36317f1de56SFelix Fietkau 3643ba20af8SFelix Fietkau u8 offchannel:1; 3659c68a57bSFelix Fietkau u8 sta:1; 36633eb14f1SFelix Fietkau u8 sta_disabled:1; 367b443e55fSRyder Lee u8 amsdu:1; 368a1a99d7bSLorenzo Bianconi u8 phy_idx:2; 36900e1ca0cSSean Wang u8 link_id:4; 3704f0f33d2SSean Wang bool link_valid; 3719c68a57bSFelix Fietkau 37230ce7f44SFelix Fietkau u8 rx_check_pn; 373a1b0bbd4SXing Song u8 rx_key_pn[IEEE80211_NUM_TIDS + 1][6]; 37401cfc1b4SLorenzo Bianconi u16 cipher; 37530ce7f44SFelix Fietkau 376db9f11d3SFelix Fietkau u32 tx_info; 37723405236SFelix Fietkau bool sw_iv; 37888046b2cSFelix Fietkau 3790335c034SFelix Fietkau struct list_head tx_list; 3800335c034SFelix Fietkau struct sk_buff_head tx_pending; 3810b3be9d1SFelix Fietkau struct sk_buff_head tx_offchannel; 3820335c034SFelix Fietkau 383bd1e3e7bSLorenzo Bianconi struct list_head list; 384bd1e3e7bSLorenzo Bianconi struct idr pktid; 385dc877523SRyder Lee 386dc877523SRyder Lee struct mt76_sta_stats stats; 387b73e1d92SLorenzo Bianconi 388b73e1d92SLorenzo Bianconi struct list_head poll_list; 389b1d21403SSean Wang 390b1d21403SSean Wang struct mt76_wcid *def_wcid; 39117f1de56SFelix Fietkau }; 39217f1de56SFelix Fietkau 39317f1de56SFelix Fietkau struct mt76_txq { 39451fb1278SFelix Fietkau u16 wcid; 39517f1de56SFelix Fietkau 39617f1de56SFelix Fietkau u16 agg_ssn; 39717f1de56SFelix Fietkau bool send_bar; 39817f1de56SFelix Fietkau bool aggr; 39917f1de56SFelix Fietkau }; 40017f1de56SFelix Fietkau 401950d0abbSBo Jiao struct mt76_wed_rro_ind { 402950d0abbSBo Jiao u32 se_id : 12; 403950d0abbSBo Jiao u32 rsv : 4; 404950d0abbSBo Jiao u32 start_sn : 12; 405950d0abbSBo Jiao u32 ind_reason : 4; 406950d0abbSBo Jiao u32 ind_cnt : 13; 407950d0abbSBo Jiao u32 win_sz : 3; 408950d0abbSBo Jiao u32 rsv2 : 13; 409950d0abbSBo Jiao u32 magic_cnt : 3; 410950d0abbSBo Jiao }; 411950d0abbSBo Jiao 41217f1de56SFelix Fietkau struct mt76_txwi_cache { 41317f1de56SFelix Fietkau struct list_head list; 414f3950a41SLorenzo Bianconi dma_addr_t dma_addr; 4156ca66722SLorenzo Bianconi 4162666beceSSujuan Chen union { 4176ca66722SLorenzo Bianconi struct sk_buff *skb; 4182666beceSSujuan Chen void *ptr; 4192666beceSSujuan Chen }; 42017f1de56SFelix Fietkau }; 42117f1de56SFelix Fietkau 422aee5b8cfSFelix Fietkau struct mt76_rx_tid { 423aee5b8cfSFelix Fietkau struct rcu_head rcu_head; 424aee5b8cfSFelix Fietkau 425aee5b8cfSFelix Fietkau struct mt76_dev *dev; 426aee5b8cfSFelix Fietkau 427aee5b8cfSFelix Fietkau spinlock_t lock; 428aee5b8cfSFelix Fietkau struct delayed_work reorder_work; 429aee5b8cfSFelix Fietkau 430a5d028d6SLorenzo Bianconi u16 id; 431aee5b8cfSFelix Fietkau u16 head; 4327c4f744dSRyder Lee u16 size; 4337c4f744dSRyder Lee u16 nframes; 434aee5b8cfSFelix Fietkau 435e7ec563eSMarkus Theil u8 num; 436e7ec563eSMarkus Theil 437aee5b8cfSFelix Fietkau u8 started:1, stopped:1, timer_pending:1; 438aee5b8cfSFelix Fietkau 439bd94d501SKees Cook struct sk_buff *reorder_buf[] __counted_by(size); 440aee5b8cfSFelix Fietkau }; 441aee5b8cfSFelix Fietkau 44288046b2cSFelix Fietkau #define MT_TX_CB_DMA_DONE BIT(0) 44388046b2cSFelix Fietkau #define MT_TX_CB_TXS_DONE BIT(1) 44488046b2cSFelix Fietkau #define MT_TX_CB_TXS_FAILED BIT(2) 44588046b2cSFelix Fietkau 4468548c6ebSFelix Fietkau #define MT_PACKET_ID_MASK GENMASK(6, 0) 447013b2dffSFelix Fietkau #define MT_PACKET_ID_NO_ACK 0 448013b2dffSFelix Fietkau #define MT_PACKET_ID_NO_SKB 1 44943eaa368SRyder Lee #define MT_PACKET_ID_WED 2 45043eaa368SRyder Lee #define MT_PACKET_ID_FIRST 3 4518548c6ebSFelix Fietkau #define MT_PACKET_ID_HAS_RATE BIT(7) 452c4a784e3SLorenzo Bianconi /* This is timer for when to give up when waiting for TXS callback, 453c4a784e3SLorenzo Bianconi * with starting time being the time at which the DMA_DONE callback 454c4a784e3SLorenzo Bianconi * was seen (so, we know packet was processed then, it should not take 455c4a784e3SLorenzo Bianconi * long after that for firmware to send the TXS callback if it is going 456c4a784e3SLorenzo Bianconi * to do so.) 457c4a784e3SLorenzo Bianconi */ 458c4a784e3SLorenzo Bianconi #define MT_TX_STATUS_SKB_TIMEOUT (HZ / 4) 45988046b2cSFelix Fietkau 46088046b2cSFelix Fietkau struct mt76_tx_cb { 46188046b2cSFelix Fietkau unsigned long jiffies; 46249e649c3SRyder Lee u16 wcid; 46388046b2cSFelix Fietkau u8 pktid; 46488046b2cSFelix Fietkau u8 flags; 46588046b2cSFelix Fietkau }; 46688046b2cSFelix Fietkau 46717f1de56SFelix Fietkau enum { 46817f1de56SFelix Fietkau MT76_STATE_INITIALIZED, 46941130c32SLorenzo Bianconi MT76_STATE_REGISTERED, 47017f1de56SFelix Fietkau MT76_STATE_RUNNING, 47187e022deSStanislaw Gruszka MT76_STATE_MCU_RUNNING, 47217f1de56SFelix Fietkau MT76_SCANNING, 473fcdfc29eSLorenzo Bianconi MT76_HW_SCANNING, 47420305f98SLorenzo Bianconi MT76_HW_SCHED_SCANNING, 475fd6c2dfaSFelix Fietkau MT76_RESTART, 47617f1de56SFelix Fietkau MT76_RESET, 47761c4fa72SFelix Fietkau MT76_MCU_RESET, 478b40b15e1SLorenzo Bianconi MT76_REMOVED, 479b40b15e1SLorenzo Bianconi MT76_READING_STATS, 480eb99cc95SLorenzo Bianconi MT76_STATE_POWER_OFF, 481c6bf2010SLorenzo Bianconi MT76_STATE_SUSPEND, 4827307f296SLorenzo Bianconi MT76_STATE_ROC, 48308523a2aSLorenzo Bianconi MT76_STATE_PM, 48436b7fce1SLorenzo Bianconi MT76_STATE_WED_RESET, 48517f1de56SFelix Fietkau }; 48617f1de56SFelix Fietkau 48717b0f68aSFelix Fietkau enum mt76_sta_event { 48817b0f68aSFelix Fietkau MT76_STA_EVENT_ASSOC, 48917b0f68aSFelix Fietkau MT76_STA_EVENT_AUTHORIZE, 49017b0f68aSFelix Fietkau MT76_STA_EVENT_DISASSOC, 49117b0f68aSFelix Fietkau }; 49217b0f68aSFelix Fietkau 49317f1de56SFelix Fietkau struct mt76_hw_cap { 49417f1de56SFelix Fietkau bool has_2ghz; 49517f1de56SFelix Fietkau bool has_5ghz; 496f7d2958cSLorenzo Bianconi bool has_6ghz; 49717f1de56SFelix Fietkau }; 49817f1de56SFelix Fietkau 4999ec0b821SFelix Fietkau #define MT_DRV_TXWI_NO_FREE BIT(0) 5009ec0b821SFelix Fietkau #define MT_DRV_TX_ALIGNED4_SKBS BIT(1) 5015ce09c1aSFelix Fietkau #define MT_DRV_SW_RX_AIRTIME BIT(2) 50294d4d076SLorenzo Bianconi #define MT_DRV_RX_DMA_HDR BIT(3) 503d3c82998SLorenzo Bianconi #define MT_DRV_HW_MGMT_TXQ BIT(4) 5045b0fb852SBen Greear #define MT_DRV_AMSDU_OFFLOAD BIT(5) 5050c5a89ceSFelix Fietkau #define MT_DRV_IGNORE_TXS_FAILED BIT(6) 5066ca66722SLorenzo Bianconi 50717f1de56SFelix Fietkau struct mt76_driver_ops { 5089ec0b821SFelix Fietkau u32 drv_flags; 509ea565833SFelix Fietkau u32 survey_flags; 51017f1de56SFelix Fietkau u16 txwi_size; 511d089692bSLorenzo Bianconi u16 token_size; 51222b980baSFelix Fietkau u8 mcs_rates; 51317f1de56SFelix Fietkau 51482334623SFelix Fietkau unsigned int link_data_size; 51582334623SFelix Fietkau 516c560b137SRyder Lee void (*update_survey)(struct mt76_phy *phy); 517f4fdd771SFelix Fietkau int (*set_channel)(struct mt76_phy *phy); 51817f1de56SFelix Fietkau 51917f1de56SFelix Fietkau int (*tx_prepare_skb)(struct mt76_dev *dev, void *txwi_ptr, 520cfaae9e6SLorenzo Bianconi enum mt76_txq_id qid, struct mt76_wcid *wcid, 521b5903c47SLorenzo Bianconi struct ieee80211_sta *sta, 522b5903c47SLorenzo Bianconi struct mt76_tx_info *tx_info); 52317f1de56SFelix Fietkau 524d80e52c7SFelix Fietkau void (*tx_complete_skb)(struct mt76_dev *dev, 525e226ba2eSLorenzo Bianconi struct mt76_queue_entry *e); 52617f1de56SFelix Fietkau 527b40b15e1SLorenzo Bianconi bool (*tx_status_data)(struct mt76_dev *dev, u8 *update); 528b40b15e1SLorenzo Bianconi 529fbe50d9aSFelix Fietkau bool (*rx_check)(struct mt76_dev *dev, void *data, int len); 530fbe50d9aSFelix Fietkau 53117f1de56SFelix Fietkau void (*rx_skb)(struct mt76_dev *dev, enum mt76_rxq_id q, 532c3137942SSujuan Chen struct sk_buff *skb, u32 *info); 53317f1de56SFelix Fietkau 53417f1de56SFelix Fietkau void (*rx_poll_complete)(struct mt76_dev *dev, enum mt76_rxq_id q); 535d71ef286SFelix Fietkau 536d71ef286SFelix Fietkau void (*sta_ps)(struct mt76_dev *dev, struct ieee80211_sta *sta, 537d71ef286SFelix Fietkau bool ps); 538e28487eaSFelix Fietkau 539e28487eaSFelix Fietkau int (*sta_add)(struct mt76_dev *dev, struct ieee80211_vif *vif, 540e28487eaSFelix Fietkau struct ieee80211_sta *sta); 541e28487eaSFelix Fietkau 54217b0f68aSFelix Fietkau int (*sta_event)(struct mt76_dev *dev, struct ieee80211_vif *vif, 54317b0f68aSFelix Fietkau struct ieee80211_sta *sta, enum mt76_sta_event ev); 5449c193de5SFelix Fietkau 545e28487eaSFelix Fietkau void (*sta_remove)(struct mt76_dev *dev, struct ieee80211_vif *vif, 546e28487eaSFelix Fietkau struct ieee80211_sta *sta); 54782334623SFelix Fietkau 54882334623SFelix Fietkau int (*vif_link_add)(struct mt76_phy *phy, struct ieee80211_vif *vif, 54982334623SFelix Fietkau struct ieee80211_bss_conf *link_conf, 55082334623SFelix Fietkau struct mt76_vif_link *mlink); 55182334623SFelix Fietkau 55282334623SFelix Fietkau void (*vif_link_remove)(struct mt76_phy *phy, 55382334623SFelix Fietkau struct ieee80211_vif *vif, 55482334623SFelix Fietkau struct ieee80211_bss_conf *link_conf, 55582334623SFelix Fietkau struct mt76_vif_link *mlink); 55617f1de56SFelix Fietkau }; 55717f1de56SFelix Fietkau 55817f1de56SFelix Fietkau struct mt76_channel_state { 55917f1de56SFelix Fietkau u64 cc_active; 56017f1de56SFelix Fietkau u64 cc_busy; 5616bfa6e38SLorenzo Bianconi u64 cc_rx; 5625ce09c1aSFelix Fietkau u64 cc_bss_rx; 563ea565833SFelix Fietkau u64 cc_tx; 564e5051965SFelix Fietkau 565e5051965SFelix Fietkau s8 noise; 56617f1de56SFelix Fietkau }; 56717f1de56SFelix Fietkau 56817f1de56SFelix Fietkau struct mt76_sband { 56917f1de56SFelix Fietkau struct ieee80211_supported_band sband; 57017f1de56SFelix Fietkau struct mt76_channel_state *chan; 57117f1de56SFelix Fietkau }; 57217f1de56SFelix Fietkau 573b40b15e1SLorenzo Bianconi /* addr req mask */ 574b40b15e1SLorenzo Bianconi #define MT_VEND_TYPE_EEPROM BIT(31) 575b40b15e1SLorenzo Bianconi #define MT_VEND_TYPE_CFG BIT(30) 576b40b15e1SLorenzo Bianconi #define MT_VEND_TYPE_MASK (MT_VEND_TYPE_EEPROM | MT_VEND_TYPE_CFG) 577b40b15e1SLorenzo Bianconi 578b40b15e1SLorenzo Bianconi #define MT_VEND_ADDR(type, n) (MT_VEND_TYPE_##type | (n)) 579b40b15e1SLorenzo Bianconi enum mt_vendor_req { 580b40b15e1SLorenzo Bianconi MT_VEND_DEV_MODE = 0x1, 581b40b15e1SLorenzo Bianconi MT_VEND_WRITE = 0x2, 5821e816c65SLorenzo Bianconi MT_VEND_POWER_ON = 0x4, 583b40b15e1SLorenzo Bianconi MT_VEND_MULTI_WRITE = 0x6, 584b40b15e1SLorenzo Bianconi MT_VEND_MULTI_READ = 0x7, 585b40b15e1SLorenzo Bianconi MT_VEND_READ_EEPROM = 0x9, 586b40b15e1SLorenzo Bianconi MT_VEND_WRITE_FCE = 0x42, 587b40b15e1SLorenzo Bianconi MT_VEND_WRITE_CFG = 0x46, 588b40b15e1SLorenzo Bianconi MT_VEND_READ_CFG = 0x47, 5891e816c65SLorenzo Bianconi MT_VEND_READ_EXT = 0x63, 5901e816c65SLorenzo Bianconi MT_VEND_WRITE_EXT = 0x66, 591d0846f08SSean Wang MT_VEND_FEATURE_SET = 0x91, 592b40b15e1SLorenzo Bianconi }; 593b40b15e1SLorenzo Bianconi 594b40b15e1SLorenzo Bianconi enum mt76u_in_ep { 595b40b15e1SLorenzo Bianconi MT_EP_IN_PKT_RX, 596b40b15e1SLorenzo Bianconi MT_EP_IN_CMD_RESP, 597b40b15e1SLorenzo Bianconi __MT_EP_IN_MAX, 598b40b15e1SLorenzo Bianconi }; 599b40b15e1SLorenzo Bianconi 600b40b15e1SLorenzo Bianconi enum mt76u_out_ep { 601b40b15e1SLorenzo Bianconi MT_EP_OUT_INBAND_CMD, 602b40b15e1SLorenzo Bianconi MT_EP_OUT_AC_BE, 60323cb16d2SLorenzo Bianconi MT_EP_OUT_AC_BK, 604b40b15e1SLorenzo Bianconi MT_EP_OUT_AC_VI, 605b40b15e1SLorenzo Bianconi MT_EP_OUT_AC_VO, 606b40b15e1SLorenzo Bianconi MT_EP_OUT_HCCA, 607b40b15e1SLorenzo Bianconi __MT_EP_OUT_MAX, 608b40b15e1SLorenzo Bianconi }; 609b40b15e1SLorenzo Bianconi 61009872957SLorenzo Bianconi struct mt76_mcu { 61109872957SLorenzo Bianconi struct mutex mutex; 61209872957SLorenzo Bianconi u32 msg_seq; 613e452c6ebSFelix Fietkau int timeout; 61409872957SLorenzo Bianconi 61509872957SLorenzo Bianconi struct sk_buff_head res_q; 61609872957SLorenzo Bianconi wait_queue_head_t wait; 61709872957SLorenzo Bianconi }; 61809872957SLorenzo Bianconi 61914663f0cSLorenzo Bianconi #define MT_TX_SG_MAX_SIZE 8 620972c5981SSean Wang #define MT_RX_SG_MAX_SIZE 4 621b40b15e1SLorenzo Bianconi #define MT_NUM_TX_ENTRIES 256 622b40b15e1SLorenzo Bianconi #define MT_NUM_RX_ENTRIES 128 623b40b15e1SLorenzo Bianconi #define MCU_RESP_URB_SIZE 1024 624b40b15e1SLorenzo Bianconi struct mt76_usb { 625b40b15e1SLorenzo Bianconi struct mutex usb_ctrl_mtx; 626a6bfb6d1SStanislaw Gruszka u8 *data; 627a6bfb6d1SStanislaw Gruszka u16 data_len; 628b40b15e1SLorenzo Bianconi 6299daf27e6SLorenzo Bianconi struct mt76_worker status_worker; 630be83a7e2SLorenzo Bianconi struct mt76_worker rx_worker; 6319daf27e6SLorenzo Bianconi 632284efb47SLorenzo Bianconi struct work_struct stat_work; 633b40b15e1SLorenzo Bianconi 634b40b15e1SLorenzo Bianconi u8 out_ep[__MT_EP_OUT_MAX]; 635b40b15e1SLorenzo Bianconi u8 in_ep[__MT_EP_IN_MAX]; 63663a7de5dSLorenzo Bianconi bool sg_en; 637b40b15e1SLorenzo Bianconi 638b40b15e1SLorenzo Bianconi struct mt76u_mcu { 639a18a494fSStanislaw Gruszka u8 *data; 640851ab66eSLorenzo Bianconi /* multiple reads */ 641851ab66eSLorenzo Bianconi struct mt76_reg_pair *rp; 642851ab66eSLorenzo Bianconi int rp_len; 643851ab66eSLorenzo Bianconi u32 base; 644b40b15e1SLorenzo Bianconi } mcu; 645b40b15e1SLorenzo Bianconi }; 646b40b15e1SLorenzo Bianconi 647bf08d585SSean Wang #define MT76S_XMIT_BUF_SZ 0x3fe00 648b1460bb4SDeren Wu #define MT76S_NUM_TX_ENTRIES 256 649b1460bb4SDeren Wu #define MT76S_NUM_RX_ENTRIES 512 650d39b52e3SSean Wang struct mt76_sdio { 651fefb584dSLorenzo Bianconi struct mt76_worker txrx_worker; 6526a618acbSLorenzo Bianconi struct mt76_worker status_worker; 6536a618acbSLorenzo Bianconi struct mt76_worker net_worker; 65492184eaeSWang Zhao struct mt76_worker stat_worker; 655974327a4SLorenzo Bianconi 656bf08d585SSean Wang u8 *xmit_buf; 657bf08d585SSean Wang u32 xmit_buf_sz; 6581522ff73SLorenzo Bianconi 659d39b52e3SSean Wang struct sdio_func *func; 660b4964908SSean Wang void *intr_data; 661dacf0acfSSean Wang u8 hw_ver; 662ca74b9b9SSean Wang wait_queue_head_t wait; 663d39b52e3SSean Wang 664fbce6136SLeon Yen int pse_mcu_quota_max; 665d39b52e3SSean Wang struct { 666d39b52e3SSean Wang int pse_data_quota; 667d39b52e3SSean Wang int ple_data_quota; 668d39b52e3SSean Wang int pse_mcu_quota; 6698c94f0e6SSean Wang int pse_page_size; 670d39b52e3SSean Wang int deficit; 671d39b52e3SSean Wang } sched; 6723ad08509SLorenzo Bianconi 6733ad08509SLorenzo Bianconi int (*parse_irq)(struct mt76_dev *dev, struct mt76s_intr *intr); 674d39b52e3SSean Wang }; 675d39b52e3SSean Wang 676f7bbb80fSLorenzo Bianconi struct mt76_mmio { 67727db1ad1SLorenzo Bianconi void __iomem *regs; 678957068c2SLorenzo Bianconi spinlock_t irq_lock; 679957068c2SLorenzo Bianconi u32 irqmask; 680f68d6762SFelix Fietkau 681f68d6762SFelix Fietkau struct mtk_wed_device wed; 68283eafc92SSujuan Chen struct mtk_wed_device wed_hif2; 68336b7fce1SLorenzo Bianconi struct completion wed_reset; 68436b7fce1SLorenzo Bianconi struct completion wed_reset_complete; 685f7bbb80fSLorenzo Bianconi }; 686f7bbb80fSLorenzo Bianconi 6875ce09c1aSFelix Fietkau struct mt76_rx_status { 6885ce09c1aSFelix Fietkau union { 6895ce09c1aSFelix Fietkau struct mt76_wcid *wcid; 69049e649c3SRyder Lee u16 wcid_idx; 6915ce09c1aSFelix Fietkau }; 6925ce09c1aSFelix Fietkau 6930fda6d7bSRyder Lee u32 reorder_time; 6945ce09c1aSFelix Fietkau 6955ce09c1aSFelix Fietkau u32 ampdu_ref; 6960fda6d7bSRyder Lee u32 timestamp; 6975ce09c1aSFelix Fietkau 6985ce09c1aSFelix Fietkau u8 iv[6]; 6995ce09c1aSFelix Fietkau 700128c9b7dSLorenzo Bianconi u8 phy_idx:2; 7015ce09c1aSFelix Fietkau u8 aggr:1; 702e195dad1SFelix Fietkau u8 qos_ctl; 7035ce09c1aSFelix Fietkau u16 seqno; 7045ce09c1aSFelix Fietkau 7055ce09c1aSFelix Fietkau u16 freq; 7065ce09c1aSFelix Fietkau u32 flag; 7075ce09c1aSFelix Fietkau u8 enc_flags; 708021af945SShayne Chen u8 encoding:3, bw:4; 709021af945SShayne Chen union { 710021af945SShayne Chen struct { 711021af945SShayne Chen u8 he_ru:3; 712021af945SShayne Chen u8 he_gi:2; 713021af945SShayne Chen u8 he_dcm:1; 714021af945SShayne Chen }; 715021af945SShayne Chen struct { 716021af945SShayne Chen u8 ru:4; 717021af945SShayne Chen u8 gi:2; 718021af945SShayne Chen } eht; 719021af945SShayne Chen }; 720021af945SShayne Chen 721cc4b3c13SLorenzo Bianconi u8 amsdu:1, first_amsdu:1, last_amsdu:1; 7225ce09c1aSFelix Fietkau u8 rate_idx; 723021af945SShayne Chen u8 nss:5, band:3; 7245ce09c1aSFelix Fietkau s8 signal; 7255ce09c1aSFelix Fietkau u8 chains; 7265ce09c1aSFelix Fietkau s8 chain_signal[IEEE80211_MAX_CHAINS]; 7275ce09c1aSFelix Fietkau }; 7285ce09c1aSFelix Fietkau 729502604f5SYN Chen struct mt76_freq_range_power { 730502604f5SYN Chen const struct cfg80211_sar_freq_ranges *range; 731502604f5SYN Chen s8 power; 732502604f5SYN Chen }; 733502604f5SYN Chen 734f0efa862SFelix Fietkau struct mt76_testmode_ops { 735c918c74dSShayne Chen int (*set_state)(struct mt76_phy *phy, enum mt76_testmode_state state); 736c918c74dSShayne Chen int (*set_params)(struct mt76_phy *phy, struct nlattr **tb, 737f0efa862SFelix Fietkau enum mt76_testmode_state new_state); 738c918c74dSShayne Chen int (*dump_stats)(struct mt76_phy *phy, struct sk_buff *msg); 739f0efa862SFelix Fietkau }; 740f0efa862SFelix Fietkau 741f0efa862SFelix Fietkau struct mt76_testmode_data { 742f0efa862SFelix Fietkau enum mt76_testmode_state state; 743f0efa862SFelix Fietkau 744f0efa862SFelix Fietkau u32 param_set[DIV_ROUND_UP(NUM_MT76_TM_ATTRS, 32)]; 745f0efa862SFelix Fietkau struct sk_buff *tx_skb; 746f0efa862SFelix Fietkau 747f0efa862SFelix Fietkau u32 tx_count; 7482601dda8SShayne Chen u16 tx_mpdu_len; 749f0efa862SFelix Fietkau 750f0efa862SFelix Fietkau u8 tx_rate_mode; 751f0efa862SFelix Fietkau u8 tx_rate_idx; 752f0efa862SFelix Fietkau u8 tx_rate_nss; 753f0efa862SFelix Fietkau u8 tx_rate_sgi; 754f0efa862SFelix Fietkau u8 tx_rate_ldpc; 7557f54c742SShayne Chen u8 tx_rate_stbc; 7561a38c2f5SShayne Chen u8 tx_ltf; 757f0efa862SFelix Fietkau 758f0efa862SFelix Fietkau u8 tx_antenna_mask; 759fdc9c18eSShayne Chen u8 tx_spe_idx; 760f0efa862SFelix Fietkau 761b8cbdb97SShayne Chen u8 tx_duty_cycle; 762b8cbdb97SShayne Chen u32 tx_time; 763b8cbdb97SShayne Chen u32 tx_ipg; 764b8cbdb97SShayne Chen 765f0efa862SFelix Fietkau u32 freq_offset; 766f0efa862SFelix Fietkau 767f0efa862SFelix Fietkau u8 tx_power[4]; 768f0efa862SFelix Fietkau u8 tx_power_control; 769f0efa862SFelix Fietkau 770c40b42c2SShayne Chen u8 addr[3][ETH_ALEN]; 771c40b42c2SShayne Chen 772f0efa862SFelix Fietkau u32 tx_pending; 773f0efa862SFelix Fietkau u32 tx_queued; 774ba459094SShayne Chen u16 tx_queued_limit; 775f0efa862SFelix Fietkau u32 tx_done; 776f0efa862SFelix Fietkau struct { 777f0efa862SFelix Fietkau u64 packets[__MT_RXQ_MAX]; 778f0efa862SFelix Fietkau u64 fcs_error[__MT_RXQ_MAX]; 779f0efa862SFelix Fietkau } rx_stats; 780f0efa862SFelix Fietkau }; 781f0efa862SFelix Fietkau 782bf18f717SFelix Fietkau struct mt76_vif_link { 78385d96704SLorenzo Bianconi u8 idx; 7844bada9b0SMing Yen Hsieh u8 link_idx; 78585d96704SLorenzo Bianconi u8 omac_idx; 78685d96704SLorenzo Bianconi u8 band_idx; 78785d96704SLorenzo Bianconi u8 wmm_idx; 78885d96704SLorenzo Bianconi u8 scan_seq_num; 7895ea3d983SFelix Fietkau u8 cipher; 7900cb065b9SLorenzo Bianconi u8 basic_rates_idx; 7910cb065b9SLorenzo Bianconi u8 mcast_rates_idx; 7920cb065b9SLorenzo Bianconi u8 beacon_rates_idx; 793e411b819SFelix Fietkau bool offchannel; 794f5020655SSean Wang struct ieee80211_chanctx_conf *ctx; 79531083e38SFelix Fietkau struct mt76_wcid *wcid; 796e24646efSFelix Fietkau struct mt76_vif_data *mvif; 797e24646efSFelix Fietkau struct rcu_head rcu_head; 798e24646efSFelix Fietkau }; 799e24646efSFelix Fietkau 800e24646efSFelix Fietkau struct mt76_vif_data { 801e24646efSFelix Fietkau struct mt76_vif_link __rcu *link[IEEE80211_MLD_MAX_NUM_LINKS]; 8023ba20af8SFelix Fietkau struct mt76_vif_link __rcu *offchannel_link; 803e24646efSFelix Fietkau 804a8f424c1SFelix Fietkau struct mt76_phy *roc_phy; 805e24646efSFelix Fietkau u16 valid_links; 806e24646efSFelix Fietkau u8 deflink_id; 80785d96704SLorenzo Bianconi }; 80885d96704SLorenzo Bianconi 809ac24dd35SFelix Fietkau struct mt76_phy { 810ac24dd35SFelix Fietkau struct ieee80211_hw *hw; 811ac24dd35SFelix Fietkau struct mt76_dev *dev; 812a3d01038SFelix Fietkau void *priv; 81396747a51SFelix Fietkau 814011849e0SFelix Fietkau unsigned long state; 81531083e38SFelix Fietkau unsigned int num_sta; 816dc44c45cSLorenzo Bianconi u8 band_idx; 817011849e0SFelix Fietkau 8180335c034SFelix Fietkau spinlock_t tx_lock; 8190335c034SFelix Fietkau struct list_head tx_list; 82091990519SLorenzo Bianconi struct mt76_queue *q_tx[__MT_TXQ_MAX]; 82191990519SLorenzo Bianconi 82296747a51SFelix Fietkau struct cfg80211_chan_def chandef; 82331083e38SFelix Fietkau struct cfg80211_chan_def main_chandef; 824f4fdd771SFelix Fietkau bool offchannel; 82582334623SFelix Fietkau bool radar_enabled; 82682334623SFelix Fietkau 827a8f424c1SFelix Fietkau struct delayed_work roc_work; 828a8f424c1SFelix Fietkau struct ieee80211_vif *roc_vif; 829a8f424c1SFelix Fietkau struct mt76_vif_link *roc_link; 830a8f424c1SFelix Fietkau 83182334623SFelix Fietkau struct mt76_chanctx *chanctx; 83296747a51SFelix Fietkau 83396747a51SFelix Fietkau struct mt76_channel_state *chan_state; 8343f306448SFelix Fietkau enum mt76_dfs_state dfs_state; 83596747a51SFelix Fietkau ktime_t survey_time; 83696747a51SFelix Fietkau 837d107501aSLorenzo Bianconi u32 aggr_stats[32]; 838d107501aSLorenzo Bianconi 83948dbce5cSLorenzo Bianconi struct mt76_hw_cap cap; 84096747a51SFelix Fietkau struct mt76_sband sband_2g; 84196747a51SFelix Fietkau struct mt76_sband sband_5g; 842cee3fd29SLorenzo Bianconi struct mt76_sband sband_6g; 843beaaeb6bSFelix Fietkau 84498df2baeSLorenzo Bianconi u8 macaddr[ETH_ALEN]; 84598df2baeSLorenzo Bianconi 846beaaeb6bSFelix Fietkau int txpower_cur; 847beaaeb6bSFelix Fietkau u8 antenna_mask; 848b9027e08SLorenzo Bianconi u16 chainmask; 849c918c74dSShayne Chen 850c918c74dSShayne Chen #ifdef CONFIG_NL80211_TESTMODE 851c918c74dSShayne Chen struct mt76_testmode_data test; 852c918c74dSShayne Chen #endif 853a782f8bfSLorenzo Bianconi 854a782f8bfSLorenzo Bianconi struct delayed_work mac_work; 855a782f8bfSLorenzo Bianconi u8 mac_work_count; 856cc4b3c13SLorenzo Bianconi 857cc4b3c13SLorenzo Bianconi struct { 858cc4b3c13SLorenzo Bianconi struct sk_buff *head; 859cc4b3c13SLorenzo Bianconi struct sk_buff **tail; 860cc4b3c13SLorenzo Bianconi u16 seqno; 861cc4b3c13SLorenzo Bianconi } rx_amsdu[__MT_RXQ_MAX]; 862502604f5SYN Chen 863502604f5SYN Chen struct mt76_freq_range_power *frp; 8643abd46ddSLorenzo Bianconi 8653abd46ddSLorenzo Bianconi struct { 8663abd46ddSLorenzo Bianconi struct led_classdev cdev; 8673abd46ddSLorenzo Bianconi char name[32]; 8683abd46ddSLorenzo Bianconi bool al; 8693abd46ddSLorenzo Bianconi u8 pin; 8703abd46ddSLorenzo Bianconi } leds; 871ac24dd35SFelix Fietkau }; 872ac24dd35SFelix Fietkau 87317f1de56SFelix Fietkau struct mt76_dev { 874ac24dd35SFelix Fietkau struct mt76_phy phy; /* must be first */ 875dc44c45cSLorenzo Bianconi struct mt76_phy *phys[__MT_MAX_BAND]; 87682334623SFelix Fietkau struct mt76_phy *band_phys[NUM_NL80211_BANDS]; 877bfc394ddSFelix Fietkau 87817f1de56SFelix Fietkau struct ieee80211_hw *hw; 87917f1de56SFelix Fietkau 8802666beceSSujuan Chen spinlock_t wed_lock; 88117f1de56SFelix Fietkau spinlock_t lock; 88217f1de56SFelix Fietkau spinlock_t cc_lock; 883108a4861SStanislaw Gruszka 8845ce09c1aSFelix Fietkau u32 cur_cc_bss_rx; 8855ce09c1aSFelix Fietkau 8865ce09c1aSFelix Fietkau struct mt76_rx_status rx_ampdu_status; 8875ce09c1aSFelix Fietkau u32 rx_ampdu_len; 8885ce09c1aSFelix Fietkau u32 rx_ampdu_ref; 8895ce09c1aSFelix Fietkau 890108a4861SStanislaw Gruszka struct mutex mutex; 891108a4861SStanislaw Gruszka 89217f1de56SFelix Fietkau const struct mt76_bus_ops *bus; 89317f1de56SFelix Fietkau const struct mt76_driver_ops *drv; 894db0f04f3SLorenzo Bianconi const struct mt76_mcu_ops *mcu_ops; 89517f1de56SFelix Fietkau struct device *dev; 896d1ddc536SFelix Fietkau struct device *dma_dev; 89717f1de56SFelix Fietkau 89809872957SLorenzo Bianconi struct mt76_mcu mcu; 89909872957SLorenzo Bianconi 90008f116c9SBreno Leitao struct net_device *napi_dev; 90108f116c9SBreno Leitao struct net_device *tx_napi_dev; 902c3d7c82aSFelix Fietkau spinlock_t rx_lock; 90317f1de56SFelix Fietkau struct napi_struct napi[__MT_RXQ_MAX]; 90417f1de56SFelix Fietkau struct sk_buff_head rx_skb[__MT_RXQ_MAX]; 905ec193b41SLorenzo Bianconi struct tasklet_struct irq_tasklet; 90617f1de56SFelix Fietkau 90717f1de56SFelix Fietkau struct list_head txwi_cache; 9082666beceSSujuan Chen struct list_head rxwi_cache; 909b1cb42adSLorenzo Bianconi struct mt76_queue *q_mcu[__MT_MCUQ_MAX]; 91017f1de56SFelix Fietkau struct mt76_queue q_rx[__MT_RXQ_MAX]; 91117f1de56SFelix Fietkau const struct mt76_queue_ops *queue_ops; 912c1e0d2beSLorenzo Bianconi int tx_dma_idx[4]; 91317f1de56SFelix Fietkau 914781eef5bSFelix Fietkau struct mt76_worker tx_worker; 9158402650aSLorenzo Bianconi struct napi_struct tx_napi; 916a33b8ab8SFelix Fietkau 917b17aff33SLorenzo Bianconi spinlock_t token_lock; 918b17aff33SLorenzo Bianconi struct idr token; 919f68d6762SFelix Fietkau u16 wed_token_count; 92061b5156bSFelix Fietkau u16 token_count; 92161b5156bSFelix Fietkau u16 token_size; 922b17aff33SLorenzo Bianconi 9232666beceSSujuan Chen spinlock_t rx_token_lock; 9242666beceSSujuan Chen struct idr rx_token; 9252666beceSSujuan Chen u16 rx_token_size; 9262666beceSSujuan Chen 92726e40d4cSFelix Fietkau wait_queue_head_t tx_wait; 928c34f1005SLorenzo Bianconi /* spinclock used to protect wcid pktid linked list */ 929c34f1005SLorenzo Bianconi spinlock_t status_lock; 93026e40d4cSFelix Fietkau 9315e616ad2SFelix Fietkau u32 wcid_mask[DIV_ROUND_UP(MT76_N_WCIDS, 32)]; 93236404c06SStanislaw Gruszka 933b619e013SEvelyn Tsai u64 vif_mask; 9342ab33b8dSFelix Fietkau 93536404c06SStanislaw Gruszka struct mt76_wcid global_wcid; 93636404c06SStanislaw Gruszka struct mt76_wcid __rcu *wcid[MT76_N_WCIDS]; 937bd1e3e7bSLorenzo Bianconi struct list_head wcid_list; 93836404c06SStanislaw Gruszka 939fbba711cSLorenzo Bianconi struct list_head sta_poll_list; 940fbba711cSLorenzo Bianconi spinlock_t sta_poll_lock; 941fbba711cSLorenzo Bianconi 94217f1de56SFelix Fietkau u32 rev; 94317f1de56SFelix Fietkau 944dc6057f4SLorenzo Bianconi struct tasklet_struct pre_tbtt_tasklet; 9453041c445SLorenzo Bianconi int beacon_int; 946c8a04d98SLorenzo Bianconi u8 beacon_mask; 9473041c445SLorenzo Bianconi 94817f1de56SFelix Fietkau struct debugfs_blob_wrapper eeprom; 94917f1de56SFelix Fietkau struct debugfs_blob_wrapper otp; 95017f1de56SFelix Fietkau 9515b257371SLorenzo Bianconi char alpha2[3]; 952d8b8890dSLorenzo Bianconi enum nl80211_dfs_regions region; 953d8b8890dSLorenzo Bianconi 954*913a6182SMing Yen Hsieh struct mt76_scan_rnr_param rnr; 955*913a6182SMing Yen Hsieh 95617f1de56SFelix Fietkau u32 debugfs_reg; 95717f1de56SFelix Fietkau 958e7173858SFelix Fietkau u8 csa_complete; 959e7173858SFelix Fietkau 960108a4861SStanislaw Gruszka u32 rxfilter; 961108a4861SStanislaw Gruszka 96231083e38SFelix Fietkau struct delayed_work scan_work; 96331083e38SFelix Fietkau struct { 96431083e38SFelix Fietkau struct cfg80211_scan_request *req; 96531083e38SFelix Fietkau struct ieee80211_channel *chan; 96631083e38SFelix Fietkau struct ieee80211_vif *vif; 967e411b819SFelix Fietkau struct mt76_vif_link *mlink; 96831083e38SFelix Fietkau struct mt76_phy *phy; 96931083e38SFelix Fietkau int chan_idx; 97031083e38SFelix Fietkau } scan; 97131083e38SFelix Fietkau 972f0efa862SFelix Fietkau #ifdef CONFIG_NL80211_TESTMODE 973f0efa862SFelix Fietkau const struct mt76_testmode_ops *test_ops; 974e7a6a044SShayne Chen struct { 975e7a6a044SShayne Chen const char *name; 976e7a6a044SShayne Chen u32 offset; 977e7a6a044SShayne Chen } test_mtd; 978f0efa862SFelix Fietkau #endif 979a86f1d01SLorenzo Bianconi struct workqueue_struct *wq; 980a86f1d01SLorenzo Bianconi 981f7bbb80fSLorenzo Bianconi union { 982f7bbb80fSLorenzo Bianconi struct mt76_mmio mmio; 983b40b15e1SLorenzo Bianconi struct mt76_usb usb; 984d39b52e3SSean Wang struct mt76_sdio sdio; 98517f1de56SFelix Fietkau }; 986f7bbb80fSLorenzo Bianconi }; 98717f1de56SFelix Fietkau 9887f03a563SLorenzo Bianconi /* per-phy stats. */ 9897f03a563SLorenzo Bianconi struct mt76_mib_stats { 9907f03a563SLorenzo Bianconi u32 ack_fail_cnt; 9917f03a563SLorenzo Bianconi u32 fcs_err_cnt; 9927f03a563SLorenzo Bianconi u32 rts_cnt; 9937f03a563SLorenzo Bianconi u32 rts_retries_cnt; 9947f03a563SLorenzo Bianconi u32 ba_miss_cnt; 9957f03a563SLorenzo Bianconi u32 tx_bf_cnt; 9967f03a563SLorenzo Bianconi u32 tx_mu_bf_cnt; 9977f03a563SLorenzo Bianconi u32 tx_mu_mpdu_cnt; 9987f03a563SLorenzo Bianconi u32 tx_mu_acked_mpdu_cnt; 9997f03a563SLorenzo Bianconi u32 tx_su_acked_mpdu_cnt; 10007f03a563SLorenzo Bianconi u32 tx_bf_ibf_ppdu_cnt; 10017f03a563SLorenzo Bianconi u32 tx_bf_ebf_ppdu_cnt; 10027f03a563SLorenzo Bianconi 10037f03a563SLorenzo Bianconi u32 tx_bf_rx_fb_all_cnt; 10047f03a563SLorenzo Bianconi u32 tx_bf_rx_fb_eht_cnt; 10057f03a563SLorenzo Bianconi u32 tx_bf_rx_fb_he_cnt; 10067f03a563SLorenzo Bianconi u32 tx_bf_rx_fb_vht_cnt; 10077f03a563SLorenzo Bianconi u32 tx_bf_rx_fb_ht_cnt; 10087f03a563SLorenzo Bianconi 10097f03a563SLorenzo Bianconi u32 tx_bf_rx_fb_bw; /* value of last sample, not cumulative */ 10107f03a563SLorenzo Bianconi u32 tx_bf_rx_fb_nc_cnt; 10117f03a563SLorenzo Bianconi u32 tx_bf_rx_fb_nr_cnt; 10127f03a563SLorenzo Bianconi u32 tx_bf_fb_cpl_cnt; 10137f03a563SLorenzo Bianconi u32 tx_bf_fb_trig_cnt; 10147f03a563SLorenzo Bianconi 10157f03a563SLorenzo Bianconi u32 tx_ampdu_cnt; 10167f03a563SLorenzo Bianconi u32 tx_stop_q_empty_cnt; 10177f03a563SLorenzo Bianconi u32 tx_mpdu_attempts_cnt; 10187f03a563SLorenzo Bianconi u32 tx_mpdu_success_cnt; 10197f03a563SLorenzo Bianconi u32 tx_pkt_ebf_cnt; 10207f03a563SLorenzo Bianconi u32 tx_pkt_ibf_cnt; 10217f03a563SLorenzo Bianconi 10227f03a563SLorenzo Bianconi u32 tx_rwp_fail_cnt; 10237f03a563SLorenzo Bianconi u32 tx_rwp_need_cnt; 10247f03a563SLorenzo Bianconi 10257f03a563SLorenzo Bianconi /* rx stats */ 10267f03a563SLorenzo Bianconi u32 rx_fifo_full_cnt; 10277f03a563SLorenzo Bianconi u32 channel_idle_cnt; 10287f03a563SLorenzo Bianconi u32 primary_cca_busy_time; 10297f03a563SLorenzo Bianconi u32 secondary_cca_busy_time; 10307f03a563SLorenzo Bianconi u32 primary_energy_detect_time; 10317f03a563SLorenzo Bianconi u32 cck_mdrdy_time; 10327f03a563SLorenzo Bianconi u32 ofdm_mdrdy_time; 10337f03a563SLorenzo Bianconi u32 green_mdrdy_time; 10347f03a563SLorenzo Bianconi u32 rx_vector_mismatch_cnt; 10357f03a563SLorenzo Bianconi u32 rx_delimiter_fail_cnt; 10367f03a563SLorenzo Bianconi u32 rx_mrdy_cnt; 10377f03a563SLorenzo Bianconi u32 rx_len_mismatch_cnt; 10387f03a563SLorenzo Bianconi u32 rx_mpdu_cnt; 10397f03a563SLorenzo Bianconi u32 rx_ampdu_cnt; 10407f03a563SLorenzo Bianconi u32 rx_ampdu_bytes_cnt; 10417f03a563SLorenzo Bianconi u32 rx_ampdu_valid_subframe_cnt; 10427f03a563SLorenzo Bianconi u32 rx_ampdu_valid_subframe_bytes_cnt; 10437f03a563SLorenzo Bianconi u32 rx_pfdrop_cnt; 10447f03a563SLorenzo Bianconi u32 rx_vec_queue_overflow_drop_cnt; 10457f03a563SLorenzo Bianconi u32 rx_ba_cnt; 10467f03a563SLorenzo Bianconi 10477f03a563SLorenzo Bianconi u32 tx_amsdu[8]; 10487f03a563SLorenzo Bianconi u32 tx_amsdu_cnt; 10491258c156SRyder Lee 10501258c156SRyder Lee /* mcu_muru_stats */ 10511258c156SRyder Lee u32 dl_cck_cnt; 10521258c156SRyder Lee u32 dl_ofdm_cnt; 10531258c156SRyder Lee u32 dl_htmix_cnt; 10541258c156SRyder Lee u32 dl_htgf_cnt; 10551258c156SRyder Lee u32 dl_vht_su_cnt; 10561258c156SRyder Lee u32 dl_vht_2mu_cnt; 10571258c156SRyder Lee u32 dl_vht_3mu_cnt; 10581258c156SRyder Lee u32 dl_vht_4mu_cnt; 10591258c156SRyder Lee u32 dl_he_su_cnt; 10601258c156SRyder Lee u32 dl_he_ext_su_cnt; 10611258c156SRyder Lee u32 dl_he_2ru_cnt; 10621258c156SRyder Lee u32 dl_he_2mu_cnt; 10631258c156SRyder Lee u32 dl_he_3ru_cnt; 10641258c156SRyder Lee u32 dl_he_3mu_cnt; 10651258c156SRyder Lee u32 dl_he_4ru_cnt; 10661258c156SRyder Lee u32 dl_he_4mu_cnt; 10671258c156SRyder Lee u32 dl_he_5to8ru_cnt; 10681258c156SRyder Lee u32 dl_he_9to16ru_cnt; 10691258c156SRyder Lee u32 dl_he_gtr16ru_cnt; 10701258c156SRyder Lee 10711258c156SRyder Lee u32 ul_hetrig_su_cnt; 10721258c156SRyder Lee u32 ul_hetrig_2ru_cnt; 10731258c156SRyder Lee u32 ul_hetrig_3ru_cnt; 10741258c156SRyder Lee u32 ul_hetrig_4ru_cnt; 10751258c156SRyder Lee u32 ul_hetrig_5to8ru_cnt; 10761258c156SRyder Lee u32 ul_hetrig_9to16ru_cnt; 10771258c156SRyder Lee u32 ul_hetrig_gtr16ru_cnt; 10781258c156SRyder Lee u32 ul_hetrig_2mu_cnt; 10791258c156SRyder Lee u32 ul_hetrig_3mu_cnt; 10801258c156SRyder Lee u32 ul_hetrig_4mu_cnt; 10817f03a563SLorenzo Bianconi }; 10827f03a563SLorenzo Bianconi 108322b980baSFelix Fietkau struct mt76_power_limits { 108422b980baSFelix Fietkau s8 cck[4]; 108522b980baSFelix Fietkau s8 ofdm[8]; 108622b980baSFelix Fietkau s8 mcs[4][10]; 1087a9627d99SShayne Chen s8 ru[7][12]; 1088975cd4d6SDeren Wu s8 eht[16][16]; 108922b980baSFelix Fietkau }; 109022b980baSFelix Fietkau 109154ae98ffSLorenzo Bianconi struct mt76_ethtool_worker_info { 109254ae98ffSLorenzo Bianconi u64 *data; 109354ae98ffSLorenzo Bianconi int idx; 109454ae98ffSLorenzo Bianconi int initial_stat_idx; 109554ae98ffSLorenzo Bianconi int worker_stat_count; 109654ae98ffSLorenzo Bianconi int sta_count; 109754ae98ffSLorenzo Bianconi }; 109854ae98ffSLorenzo Bianconi 109982334623SFelix Fietkau struct mt76_chanctx { 110082334623SFelix Fietkau struct mt76_phy *phy; 110182334623SFelix Fietkau }; 110282334623SFelix Fietkau 110354b8fdebSLorenzo Bianconi #define CCK_RATE(_idx, _rate) { \ 110454b8fdebSLorenzo Bianconi .bitrate = _rate, \ 110554b8fdebSLorenzo Bianconi .flags = IEEE80211_RATE_SHORT_PREAMBLE, \ 110654b8fdebSLorenzo Bianconi .hw_value = (MT_PHY_TYPE_CCK << 8) | (_idx), \ 110754b8fdebSLorenzo Bianconi .hw_value_short = (MT_PHY_TYPE_CCK << 8) | (4 + _idx), \ 110854b8fdebSLorenzo Bianconi } 110954b8fdebSLorenzo Bianconi 111054b8fdebSLorenzo Bianconi #define OFDM_RATE(_idx, _rate) { \ 111154b8fdebSLorenzo Bianconi .bitrate = _rate, \ 111254b8fdebSLorenzo Bianconi .hw_value = (MT_PHY_TYPE_OFDM << 8) | (_idx), \ 111354b8fdebSLorenzo Bianconi .hw_value_short = (MT_PHY_TYPE_OFDM << 8) | (_idx), \ 111454b8fdebSLorenzo Bianconi } 111554b8fdebSLorenzo Bianconi 111654b8fdebSLorenzo Bianconi extern struct ieee80211_rate mt76_rates[12]; 111754b8fdebSLorenzo Bianconi 1118d4131273SStanislaw Gruszka #define __mt76_rr(dev, ...) (dev)->bus->rr((dev), __VA_ARGS__) 1119d4131273SStanislaw Gruszka #define __mt76_wr(dev, ...) (dev)->bus->wr((dev), __VA_ARGS__) 1120d4131273SStanislaw Gruszka #define __mt76_rmw(dev, ...) (dev)->bus->rmw((dev), __VA_ARGS__) 112135e4ebeaSLorenzo Bianconi #define __mt76_wr_copy(dev, ...) (dev)->bus->write_copy((dev), __VA_ARGS__) 112235e4ebeaSLorenzo Bianconi #define __mt76_rr_copy(dev, ...) (dev)->bus->read_copy((dev), __VA_ARGS__) 1123d4131273SStanislaw Gruszka 112422c575c4SStanislaw Gruszka #define __mt76_set(dev, offset, val) __mt76_rmw(dev, offset, 0, val) 112522c575c4SStanislaw Gruszka #define __mt76_clear(dev, offset, val) __mt76_rmw(dev, offset, val, 0) 112622c575c4SStanislaw Gruszka 112717f1de56SFelix Fietkau #define mt76_rr(dev, ...) (dev)->mt76.bus->rr(&((dev)->mt76), __VA_ARGS__) 112817f1de56SFelix Fietkau #define mt76_wr(dev, ...) (dev)->mt76.bus->wr(&((dev)->mt76), __VA_ARGS__) 112917f1de56SFelix Fietkau #define mt76_rmw(dev, ...) (dev)->mt76.bus->rmw(&((dev)->mt76), __VA_ARGS__) 113035e4ebeaSLorenzo Bianconi #define mt76_wr_copy(dev, ...) (dev)->mt76.bus->write_copy(&((dev)->mt76), __VA_ARGS__) 113135e4ebeaSLorenzo Bianconi #define mt76_rr_copy(dev, ...) (dev)->mt76.bus->read_copy(&((dev)->mt76), __VA_ARGS__) 11326da5a291SStanislaw Gruszka #define mt76_wr_rp(dev, ...) (dev)->mt76.bus->wr_rp(&((dev)->mt76), __VA_ARGS__) 11336da5a291SStanislaw Gruszka #define mt76_rd_rp(dev, ...) (dev)->mt76.bus->rd_rp(&((dev)->mt76), __VA_ARGS__) 113417f1de56SFelix Fietkau 1135f4d45fe2SLorenzo Bianconi 1136e2c2fd0fSLorenzo Bianconi #define mt76_mcu_restart(dev, ...) (dev)->mt76.mcu_ops->mcu_restart(&((dev)->mt76)) 1137db0f04f3SLorenzo Bianconi 113817f1de56SFelix Fietkau #define mt76_set(dev, offset, val) mt76_rmw(dev, offset, 0, val) 113917f1de56SFelix Fietkau #define mt76_clear(dev, offset, val) mt76_rmw(dev, offset, val, 0) 114017f1de56SFelix Fietkau 114117f1de56SFelix Fietkau #define mt76_get_field(_dev, _reg, _field) \ 114217f1de56SFelix Fietkau FIELD_GET(_field, mt76_rr(dev, _reg)) 114317f1de56SFelix Fietkau 114417f1de56SFelix Fietkau #define mt76_rmw_field(_dev, _reg, _field, _val) \ 114517f1de56SFelix Fietkau mt76_rmw(_dev, _reg, _field, FIELD_PREP(_field, _val)) 114617f1de56SFelix Fietkau 114746436b5eSStanislaw Gruszka #define __mt76_rmw_field(_dev, _reg, _field, _val) \ 114846436b5eSStanislaw Gruszka __mt76_rmw(_dev, _reg, _field, FIELD_PREP(_field, _val)) 114946436b5eSStanislaw Gruszka 1150ac24dd35SFelix Fietkau #define mt76_hw(dev) (dev)->mphy.hw 115117f1de56SFelix Fietkau 115217f1de56SFelix Fietkau bool __mt76_poll(struct mt76_dev *dev, u32 offset, u32 mask, u32 val, 115317f1de56SFelix Fietkau int timeout); 115417f1de56SFelix Fietkau 115517f1de56SFelix Fietkau #define mt76_poll(dev, ...) __mt76_poll(&((dev)->mt76), __VA_ARGS__) 115617f1de56SFelix Fietkau 115735effe6cSDeren Wu bool ____mt76_poll_msec(struct mt76_dev *dev, u32 offset, u32 mask, u32 val, 115835effe6cSDeren Wu int timeout, int kick); 115935effe6cSDeren Wu #define __mt76_poll_msec(...) ____mt76_poll_msec(__VA_ARGS__, 10) 116035effe6cSDeren Wu #define mt76_poll_msec(dev, ...) ____mt76_poll_msec(&((dev)->mt76), __VA_ARGS__, 10) 116135effe6cSDeren Wu #define mt76_poll_msec_tick(dev, ...) ____mt76_poll_msec(&((dev)->mt76), __VA_ARGS__) 116217f1de56SFelix Fietkau 116317f1de56SFelix Fietkau void mt76_mmio_init(struct mt76_dev *dev, void __iomem *regs); 1164f37f0550SLorenzo Bianconi void mt76_pci_disable_aspm(struct pci_dev *pdev); 1165d53ab629SMichael Lo bool mt76_pci_aspm_supported(struct pci_dev *pdev); 116617f1de56SFelix Fietkau 116717f1de56SFelix Fietkau static inline u16 mt76_chip(struct mt76_dev *dev) 116817f1de56SFelix Fietkau { 116917f1de56SFelix Fietkau return dev->rev >> 16; 117017f1de56SFelix Fietkau } 117117f1de56SFelix Fietkau 117217f1de56SFelix Fietkau static inline u16 mt76_rev(struct mt76_dev *dev) 117317f1de56SFelix Fietkau { 117417f1de56SFelix Fietkau return dev->rev & 0xffff; 117517f1de56SFelix Fietkau } 117617f1de56SFelix Fietkau 11778a7386e7SLorenzo Bianconi void mt76_wed_release_rx_buf(struct mtk_wed_device *wed); 11788a7386e7SLorenzo Bianconi void mt76_wed_offload_disable(struct mtk_wed_device *wed); 11798a7386e7SLorenzo Bianconi void mt76_wed_reset_complete(struct mtk_wed_device *wed); 11808a7386e7SLorenzo Bianconi void mt76_wed_dma_reset(struct mt76_dev *dev); 11818a7386e7SLorenzo Bianconi int mt76_wed_net_setup_tc(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 11828a7386e7SLorenzo Bianconi struct net_device *netdev, enum tc_setup_type type, 11838a7386e7SLorenzo Bianconi void *type_data); 1184b92158a8SLorenzo Bianconi #ifdef CONFIG_NET_MEDIATEK_SOC_WED 11858a7386e7SLorenzo Bianconi u32 mt76_wed_init_rx_buf(struct mtk_wed_device *wed, int size); 11868a7386e7SLorenzo Bianconi int mt76_wed_offload_enable(struct mtk_wed_device *wed); 11878a7386e7SLorenzo Bianconi int mt76_wed_dma_setup(struct mt76_dev *dev, struct mt76_queue *q, bool reset); 11888a7386e7SLorenzo Bianconi #else 11898a7386e7SLorenzo Bianconi static inline u32 mt76_wed_init_rx_buf(struct mtk_wed_device *wed, int size) 11908a7386e7SLorenzo Bianconi { 11918a7386e7SLorenzo Bianconi return 0; 11928a7386e7SLorenzo Bianconi } 11938a7386e7SLorenzo Bianconi 11948a7386e7SLorenzo Bianconi static inline int mt76_wed_offload_enable(struct mtk_wed_device *wed) 11958a7386e7SLorenzo Bianconi { 11968a7386e7SLorenzo Bianconi return 0; 11978a7386e7SLorenzo Bianconi } 11988a7386e7SLorenzo Bianconi 11998a7386e7SLorenzo Bianconi static inline int mt76_wed_dma_setup(struct mt76_dev *dev, struct mt76_queue *q, 12008a7386e7SLorenzo Bianconi bool reset) 12018a7386e7SLorenzo Bianconi { 12028a7386e7SLorenzo Bianconi return 0; 12038a7386e7SLorenzo Bianconi } 1204b92158a8SLorenzo Bianconi #endif /* CONFIG_NET_MEDIATEK_SOC_WED */ 1205b92158a8SLorenzo Bianconi 120617f1de56SFelix Fietkau #define mt76xx_chip(dev) mt76_chip(&((dev)->mt76)) 120717f1de56SFelix Fietkau #define mt76xx_rev(dev) mt76_rev(&((dev)->mt76)) 120817f1de56SFelix Fietkau 1209cb8ed33dSLorenzo Bianconi #define mt76_init_queues(dev, ...) (dev)->mt76.queue_ops->init(&((dev)->mt76), __VA_ARGS__) 1210a23fde09SLorenzo Bianconi #define mt76_queue_alloc(dev, ...) (dev)->mt76.queue_ops->alloc(&((dev)->mt76), __VA_ARGS__) 12115ed31128SLorenzo Bianconi #define mt76_tx_queue_skb_raw(dev, ...) (dev)->mt76.queue_ops->tx_queue_skb_raw(&((dev)->mt76), __VA_ARGS__) 12125d581c33SFelix Fietkau #define mt76_tx_queue_skb(dev, ...) (dev)->mt76.queue_ops->tx_queue_skb(&((dev)->mphy), __VA_ARGS__) 121317f1de56SFelix Fietkau #define mt76_queue_rx_reset(dev, ...) (dev)->mt76.queue_ops->rx_reset(&((dev)->mt76), __VA_ARGS__) 121417f1de56SFelix Fietkau #define mt76_queue_tx_cleanup(dev, ...) (dev)->mt76.queue_ops->tx_cleanup(&((dev)->mt76), __VA_ARGS__) 1215c001df97SLorenzo Bianconi #define mt76_queue_rx_cleanup(dev, ...) (dev)->mt76.queue_ops->rx_cleanup(&((dev)->mt76), __VA_ARGS__) 121617f1de56SFelix Fietkau #define mt76_queue_kick(dev, ...) (dev)->mt76.queue_ops->kick(&((dev)->mt76), __VA_ARGS__) 12173990465dSLorenzo Bianconi #define mt76_queue_reset(dev, ...) (dev)->mt76.queue_ops->reset_q(&((dev)->mt76), __VA_ARGS__) 121817f1de56SFelix Fietkau 1219f473b42aSFelix Fietkau #define mt76_for_each_q_rx(dev, i) \ 1220b3ad9d6aSBo Jiao for (i = 0; i < ARRAY_SIZE((dev)->q_rx); i++) \ 1221b3ad9d6aSBo Jiao if ((dev)->q_rx[i].ndesc) 1222f473b42aSFelix Fietkau 1223e24646efSFelix Fietkau 1224e24646efSFelix Fietkau #define mt76_dereference(p, dev) \ 1225e24646efSFelix Fietkau rcu_dereference_protected(p, lockdep_is_held(&(dev)->mutex)) 1226e24646efSFelix Fietkau 1227c0f7b25aSLorenzo Bianconi struct mt76_dev *mt76_alloc_device(struct device *pdev, unsigned int size, 1228c0f7b25aSLorenzo Bianconi const struct ieee80211_ops *ops, 1229c0f7b25aSLorenzo Bianconi const struct mt76_driver_ops *drv_ops); 123017f1de56SFelix Fietkau int mt76_register_device(struct mt76_dev *dev, bool vht, 123117f1de56SFelix Fietkau struct ieee80211_rate *rates, int n_rates); 123217f1de56SFelix Fietkau void mt76_unregister_device(struct mt76_dev *dev); 1233def34a2fSLorenzo Bianconi void mt76_free_device(struct mt76_dev *dev); 1234c89d3625SFelix Fietkau void mt76_unregister_phy(struct mt76_phy *phy); 1235c89d3625SFelix Fietkau 1236a24f891aSFelix Fietkau struct mt76_phy *mt76_alloc_radio_phy(struct mt76_dev *dev, unsigned int size, 1237a24f891aSFelix Fietkau u8 band_idx); 1238c89d3625SFelix Fietkau struct mt76_phy *mt76_alloc_phy(struct mt76_dev *dev, unsigned int size, 1239dc44c45cSLorenzo Bianconi const struct ieee80211_ops *ops, 1240dc44c45cSLorenzo Bianconi u8 band_idx); 1241db78a791SLorenzo Bianconi int mt76_register_phy(struct mt76_phy *phy, bool vht, 1242db78a791SLorenzo Bianconi struct ieee80211_rate *rates, int n_rates); 1243e5d944b4SLorenzo Bianconi struct mt76_phy *mt76_vif_phy(struct ieee80211_hw *hw, 1244e5d944b4SLorenzo Bianconi struct ieee80211_vif *vif); 124517f1de56SFelix Fietkau 12463263039dSLorenzo Bianconi struct dentry *mt76_register_debugfs_fops(struct mt76_phy *phy, 1247f6e1f598SLorenzo Bianconi const struct file_operations *ops); 1248f6e1f598SLorenzo Bianconi static inline struct dentry *mt76_register_debugfs(struct mt76_dev *dev) 1249f6e1f598SLorenzo Bianconi { 12503263039dSLorenzo Bianconi return mt76_register_debugfs_fops(&dev->phy, NULL); 1251f6e1f598SLorenzo Bianconi } 1252f6e1f598SLorenzo Bianconi 12530b82a8e8SLorenzo Bianconi int mt76_queues_read(struct seq_file *s, void *data); 12548f410a8bSLorenzo Bianconi void mt76_seq_puts_array(struct seq_file *file, const char *str, 12558f410a8bSLorenzo Bianconi s8 *val, int len); 125617f1de56SFelix Fietkau 125717f1de56SFelix Fietkau int mt76_eeprom_init(struct mt76_dev *dev, int len); 125898df2baeSLorenzo Bianconi void mt76_eeprom_override(struct mt76_phy *phy); 1259a6342c31SChristian Marangi int mt76_get_of_data_from_mtd(struct mt76_dev *dev, void *eep, int offset, int len); 1260a1f57685SChristian Marangi int mt76_get_of_data_from_nvmem(struct mt76_dev *dev, void *eep, 1261a1f57685SChristian Marangi const char *cell_name, int len); 126217f1de56SFelix Fietkau 1263b1cb42adSLorenzo Bianconi struct mt76_queue * 1264b1cb42adSLorenzo Bianconi mt76_init_queue(struct mt76_dev *dev, int qid, int idx, int n_desc, 12652e420b88SLorenzo Bianconi int ring_base, void *wed, u32 flags); 1266b1cb42adSLorenzo Bianconi static inline int mt76_init_tx_queue(struct mt76_phy *phy, int qid, int idx, 12672e420b88SLorenzo Bianconi int n_desc, int ring_base, void *wed, 12682e420b88SLorenzo Bianconi u32 flags) 1269b1cb42adSLorenzo Bianconi { 1270b1cb42adSLorenzo Bianconi struct mt76_queue *q; 1271b1cb42adSLorenzo Bianconi 12722e420b88SLorenzo Bianconi q = mt76_init_queue(phy->dev, qid, idx, n_desc, ring_base, wed, flags); 1273b1cb42adSLorenzo Bianconi if (IS_ERR(q)) 1274b1cb42adSLorenzo Bianconi return PTR_ERR(q); 1275b1cb42adSLorenzo Bianconi 127691990519SLorenzo Bianconi phy->q_tx[qid] = q; 1277b1cb42adSLorenzo Bianconi 1278b1cb42adSLorenzo Bianconi return 0; 1279b1cb42adSLorenzo Bianconi } 1280b1cb42adSLorenzo Bianconi 1281b1cb42adSLorenzo Bianconi static inline int mt76_init_mcu_queue(struct mt76_dev *dev, int qid, int idx, 1282b1cb42adSLorenzo Bianconi int n_desc, int ring_base) 1283b1cb42adSLorenzo Bianconi { 1284b1cb42adSLorenzo Bianconi struct mt76_queue *q; 1285b1cb42adSLorenzo Bianconi 12862e420b88SLorenzo Bianconi q = mt76_init_queue(dev, qid, idx, n_desc, ring_base, NULL, 0); 1287b1cb42adSLorenzo Bianconi if (IS_ERR(q)) 1288b1cb42adSLorenzo Bianconi return PTR_ERR(q); 1289b1cb42adSLorenzo Bianconi 1290b1cb42adSLorenzo Bianconi dev->q_mcu[qid] = q; 1291b1cb42adSLorenzo Bianconi 1292b1cb42adSLorenzo Bianconi return 0; 1293b1cb42adSLorenzo Bianconi } 1294b671da33SLorenzo Bianconi 1295011849e0SFelix Fietkau static inline struct mt76_phy * 1296128c9b7dSLorenzo Bianconi mt76_dev_phy(struct mt76_dev *dev, u8 phy_idx) 1297011849e0SFelix Fietkau { 1298dc44c45cSLorenzo Bianconi if ((phy_idx == MT_BAND1 && dev->phys[phy_idx]) || 1299dc44c45cSLorenzo Bianconi (phy_idx == MT_BAND2 && dev->phys[phy_idx])) 1300dc44c45cSLorenzo Bianconi return dev->phys[phy_idx]; 1301128c9b7dSLorenzo Bianconi 1302011849e0SFelix Fietkau return &dev->phy; 1303011849e0SFelix Fietkau } 1304011849e0SFelix Fietkau 1305bfc394ddSFelix Fietkau static inline struct ieee80211_hw * 1306128c9b7dSLorenzo Bianconi mt76_phy_hw(struct mt76_dev *dev, u8 phy_idx) 1307bfc394ddSFelix Fietkau { 1308128c9b7dSLorenzo Bianconi return mt76_dev_phy(dev, phy_idx)->hw; 1309bfc394ddSFelix Fietkau } 1310bfc394ddSFelix Fietkau 1311f3950a41SLorenzo Bianconi static inline u8 * 1312f3950a41SLorenzo Bianconi mt76_get_txwi_ptr(struct mt76_dev *dev, struct mt76_txwi_cache *t) 1313f3950a41SLorenzo Bianconi { 1314f3950a41SLorenzo Bianconi return (u8 *)t - dev->drv->txwi_size; 1315f3950a41SLorenzo Bianconi } 1316f3950a41SLorenzo Bianconi 1317ee8aa945SLorenzo Bianconi /* increment with wrap-around */ 1318ee8aa945SLorenzo Bianconi static inline int mt76_incr(int val, int size) 1319ee8aa945SLorenzo Bianconi { 1320ee8aa945SLorenzo Bianconi return (val + 1) & (size - 1); 1321ee8aa945SLorenzo Bianconi } 1322ee8aa945SLorenzo Bianconi 1323ee8aa945SLorenzo Bianconi /* decrement with wrap-around */ 1324ee8aa945SLorenzo Bianconi static inline int mt76_decr(int val, int size) 1325ee8aa945SLorenzo Bianconi { 1326ee8aa945SLorenzo Bianconi return (val - 1) & (size - 1); 1327ee8aa945SLorenzo Bianconi } 1328ee8aa945SLorenzo Bianconi 13291d0496c6SStanislaw Gruszka u8 mt76_ac_to_hwq(u8 ac); 1330b40b15e1SLorenzo Bianconi 133117f1de56SFelix Fietkau static inline struct ieee80211_txq * 133217f1de56SFelix Fietkau mtxq_to_txq(struct mt76_txq *mtxq) 133317f1de56SFelix Fietkau { 133417f1de56SFelix Fietkau void *ptr = mtxq; 133517f1de56SFelix Fietkau 133617f1de56SFelix Fietkau return container_of(ptr, struct ieee80211_txq, drv_priv); 133717f1de56SFelix Fietkau } 133817f1de56SFelix Fietkau 13399c68a57bSFelix Fietkau static inline struct ieee80211_sta * 13409c68a57bSFelix Fietkau wcid_to_sta(struct mt76_wcid *wcid) 13419c68a57bSFelix Fietkau { 13429c68a57bSFelix Fietkau void *ptr = wcid; 13439c68a57bSFelix Fietkau 13449c68a57bSFelix Fietkau if (!wcid || !wcid->sta) 13459c68a57bSFelix Fietkau return NULL; 13469c68a57bSFelix Fietkau 1347b1d21403SSean Wang if (wcid->def_wcid) 1348b1d21403SSean Wang ptr = wcid->def_wcid; 1349b1d21403SSean Wang 13509c68a57bSFelix Fietkau return container_of(ptr, struct ieee80211_sta, drv_priv); 13519c68a57bSFelix Fietkau } 13529c68a57bSFelix Fietkau 135388046b2cSFelix Fietkau static inline struct mt76_tx_cb *mt76_tx_skb_cb(struct sk_buff *skb) 135488046b2cSFelix Fietkau { 135588046b2cSFelix Fietkau BUILD_BUG_ON(sizeof(struct mt76_tx_cb) > 135688046b2cSFelix Fietkau sizeof(IEEE80211_SKB_CB(skb)->status.status_driver_data)); 135788046b2cSFelix Fietkau return ((void *)IEEE80211_SKB_CB(skb)->status.status_driver_data); 135888046b2cSFelix Fietkau } 135988046b2cSFelix Fietkau 136077ae1d5eSRyder Lee static inline void *mt76_skb_get_hdr(struct sk_buff *skb) 136177ae1d5eSRyder Lee { 136277ae1d5eSRyder Lee struct mt76_rx_status mstat; 136377ae1d5eSRyder Lee u8 *data = skb->data; 136477ae1d5eSRyder Lee 136577ae1d5eSRyder Lee /* Alignment concerns */ 136677ae1d5eSRyder Lee BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he) % 4); 136777ae1d5eSRyder Lee BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he_mu) % 4); 136877ae1d5eSRyder Lee 136977ae1d5eSRyder Lee mstat = *((struct mt76_rx_status *)skb->cb); 137077ae1d5eSRyder Lee 137177ae1d5eSRyder Lee if (mstat.flag & RX_FLAG_RADIOTAP_HE) 137277ae1d5eSRyder Lee data += sizeof(struct ieee80211_radiotap_he); 137377ae1d5eSRyder Lee if (mstat.flag & RX_FLAG_RADIOTAP_HE_MU) 137477ae1d5eSRyder Lee data += sizeof(struct ieee80211_radiotap_he_mu); 137577ae1d5eSRyder Lee 137677ae1d5eSRyder Lee return data; 137777ae1d5eSRyder Lee } 137877ae1d5eSRyder Lee 13793bb45b5fSLorenzo Bianconi static inline void mt76_insert_hdr_pad(struct sk_buff *skb) 13803bb45b5fSLorenzo Bianconi { 13813bb45b5fSLorenzo Bianconi int len = ieee80211_get_hdrlen_from_skb(skb); 13823bb45b5fSLorenzo Bianconi 13833bb45b5fSLorenzo Bianconi if (len % 4 == 0) 13843bb45b5fSLorenzo Bianconi return; 13853bb45b5fSLorenzo Bianconi 13863bb45b5fSLorenzo Bianconi skb_push(skb, 2); 13873bb45b5fSLorenzo Bianconi memmove(skb->data, skb->data + 2, len); 13883bb45b5fSLorenzo Bianconi 13893bb45b5fSLorenzo Bianconi skb->data[len] = 0; 13903bb45b5fSLorenzo Bianconi skb->data[len + 1] = 0; 13913bb45b5fSLorenzo Bianconi } 13923bb45b5fSLorenzo Bianconi 13938548c6ebSFelix Fietkau static inline bool mt76_is_skb_pktid(u8 pktid) 13948548c6ebSFelix Fietkau { 13958548c6ebSFelix Fietkau if (pktid & MT_PACKET_ID_HAS_RATE) 13968548c6ebSFelix Fietkau return false; 13978548c6ebSFelix Fietkau 13988548c6ebSFelix Fietkau return pktid >= MT_PACKET_ID_FIRST; 13998548c6ebSFelix Fietkau } 14008548c6ebSFelix Fietkau 140107cda406SFelix Fietkau static inline u8 mt76_tx_power_nss_delta(u8 nss) 140207cda406SFelix Fietkau { 140307cda406SFelix Fietkau static const u8 nss_delta[4] = { 0, 6, 9, 12 }; 140403dd0d49SDeren Wu u8 idx = nss - 1; 140507cda406SFelix Fietkau 140603dd0d49SDeren Wu return (idx < ARRAY_SIZE(nss_delta)) ? nss_delta[idx] : 0; 140707cda406SFelix Fietkau } 140807cda406SFelix Fietkau 1409c918c74dSShayne Chen static inline bool mt76_testmode_enabled(struct mt76_phy *phy) 1410f0efa862SFelix Fietkau { 1411f0efa862SFelix Fietkau #ifdef CONFIG_NL80211_TESTMODE 1412c918c74dSShayne Chen return phy->test.state != MT76_TM_STATE_OFF; 1413c918c74dSShayne Chen #else 1414c918c74dSShayne Chen return false; 1415c918c74dSShayne Chen #endif 1416c918c74dSShayne Chen } 1417c918c74dSShayne Chen 1418c918c74dSShayne Chen static inline bool mt76_is_testmode_skb(struct mt76_dev *dev, 1419c918c74dSShayne Chen struct sk_buff *skb, 1420c918c74dSShayne Chen struct ieee80211_hw **hw) 1421c918c74dSShayne Chen { 1422c918c74dSShayne Chen #ifdef CONFIG_NL80211_TESTMODE 1423dc44c45cSLorenzo Bianconi int i; 1424dc44c45cSLorenzo Bianconi 1425dc44c45cSLorenzo Bianconi for (i = 0; i < ARRAY_SIZE(dev->phys); i++) { 1426dc44c45cSLorenzo Bianconi struct mt76_phy *phy = dev->phys[i]; 1427dc44c45cSLorenzo Bianconi 1428dc44c45cSLorenzo Bianconi if (phy && skb == phy->test.tx_skb) { 1429dc44c45cSLorenzo Bianconi *hw = dev->phys[i]->hw; 1430c918c74dSShayne Chen return true; 1431dc44c45cSLorenzo Bianconi } 1432dc44c45cSLorenzo Bianconi } 1433dc44c45cSLorenzo Bianconi return false; 1434f0efa862SFelix Fietkau #else 1435f0efa862SFelix Fietkau return false; 1436f0efa862SFelix Fietkau #endif 1437f0efa862SFelix Fietkau } 1438f0efa862SFelix Fietkau 143917f1de56SFelix Fietkau void mt76_rx(struct mt76_dev *dev, enum mt76_rxq_id q, struct sk_buff *skb); 14409fba6d07SFelix Fietkau void mt76_tx(struct mt76_phy *dev, struct ieee80211_sta *sta, 144117f1de56SFelix Fietkau struct mt76_wcid *wcid, struct sk_buff *skb); 144217f1de56SFelix Fietkau void mt76_wake_tx_queue(struct ieee80211_hw *hw, struct ieee80211_txq *txq); 144391990519SLorenzo Bianconi void mt76_stop_tx_queues(struct mt76_phy *phy, struct ieee80211_sta *sta, 144417f1de56SFelix Fietkau bool send_bar); 1445c50d105aSFelix Fietkau void mt76_tx_check_agg_ssn(struct ieee80211_sta *sta, struct sk_buff *skb); 14469fba6d07SFelix Fietkau void mt76_txq_schedule(struct mt76_phy *phy, enum mt76_txq_id qid); 14479fba6d07SFelix Fietkau void mt76_txq_schedule_all(struct mt76_phy *phy); 1448335e97acSLorenzo Bianconi void mt76_tx_worker_run(struct mt76_dev *dev); 1449781eef5bSFelix Fietkau void mt76_tx_worker(struct mt76_worker *w); 145017f1de56SFelix Fietkau void mt76_release_buffered_frames(struct ieee80211_hw *hw, 145117f1de56SFelix Fietkau struct ieee80211_sta *sta, 145217f1de56SFelix Fietkau u16 tids, int nframes, 145317f1de56SFelix Fietkau enum ieee80211_frame_release_type reason, 145417f1de56SFelix Fietkau bool more_data); 14555a95ca41SFelix Fietkau bool mt76_has_tx_pending(struct mt76_phy *phy); 1456f4fdd771SFelix Fietkau int mt76_update_channel(struct mt76_phy *phy); 1457c560b137SRyder Lee void mt76_update_survey(struct mt76_phy *phy); 145804414240SLorenzo Bianconi void mt76_update_survey_active_time(struct mt76_phy *phy, ktime_t time); 145917f1de56SFelix Fietkau int mt76_get_survey(struct ieee80211_hw *hw, int idx, 146017f1de56SFelix Fietkau struct survey_info *survey); 1461a71b648eSRyder Lee int mt76_rx_signal(u8 chain_mask, s8 *chain_signal); 1462bb3e3fecSRyder Lee void mt76_set_stream_caps(struct mt76_phy *phy, bool vht); 146317f1de56SFelix Fietkau 1464aee5b8cfSFelix Fietkau int mt76_rx_aggr_start(struct mt76_dev *dev, struct mt76_wcid *wcid, u8 tid, 14657c4f744dSRyder Lee u16 ssn, u16 size); 1466aee5b8cfSFelix Fietkau void mt76_rx_aggr_stop(struct mt76_dev *dev, struct mt76_wcid *wcid, u8 tid); 1467aee5b8cfSFelix Fietkau 146830ce7f44SFelix Fietkau void mt76_wcid_key_setup(struct mt76_dev *dev, struct mt76_wcid *wcid, 146930ce7f44SFelix Fietkau struct ieee80211_key_conf *key); 147079d1c94cSFelix Fietkau 147179d1c94cSFelix Fietkau void mt76_tx_status_lock(struct mt76_dev *dev, struct sk_buff_head *list) 1472c34f1005SLorenzo Bianconi __acquires(&dev->status_lock); 147379d1c94cSFelix Fietkau void mt76_tx_status_unlock(struct mt76_dev *dev, struct sk_buff_head *list) 1474c34f1005SLorenzo Bianconi __releases(&dev->status_lock); 147579d1c94cSFelix Fietkau 147688046b2cSFelix Fietkau int mt76_tx_status_skb_add(struct mt76_dev *dev, struct mt76_wcid *wcid, 147788046b2cSFelix Fietkau struct sk_buff *skb); 147888046b2cSFelix Fietkau struct sk_buff *mt76_tx_status_skb_get(struct mt76_dev *dev, 147979d1c94cSFelix Fietkau struct mt76_wcid *wcid, int pktid, 148079d1c94cSFelix Fietkau struct sk_buff_head *list); 148179d1c94cSFelix Fietkau void mt76_tx_status_skb_done(struct mt76_dev *dev, struct sk_buff *skb, 148279d1c94cSFelix Fietkau struct sk_buff_head *list); 14830fe88644SFelix Fietkau void __mt76_tx_complete_skb(struct mt76_dev *dev, u16 wcid, struct sk_buff *skb, 14840fe88644SFelix Fietkau struct list_head *free_list); 14850fe88644SFelix Fietkau static inline void 14860fe88644SFelix Fietkau mt76_tx_complete_skb(struct mt76_dev *dev, u16 wcid, struct sk_buff *skb) 14870fe88644SFelix Fietkau { 14880fe88644SFelix Fietkau __mt76_tx_complete_skb(dev, wcid, skb, NULL); 14890fe88644SFelix Fietkau } 14900fe88644SFelix Fietkau 1491c02f86eeSLorenzo Bianconi void mt76_tx_status_check(struct mt76_dev *dev, bool flush); 1492e28487eaSFelix Fietkau int mt76_sta_state(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1493e28487eaSFelix Fietkau struct ieee80211_sta *sta, 1494e28487eaSFelix Fietkau enum ieee80211_sta_state old_state, 1495e28487eaSFelix Fietkau enum ieee80211_sta_state new_state); 149631083e38SFelix Fietkau void __mt76_sta_remove(struct mt76_phy *phy, struct ieee80211_vif *vif, 149713f61dfcSLorenzo Bianconi struct ieee80211_sta *sta); 149843ba1922SFelix Fietkau void mt76_sta_pre_rcu_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 149943ba1922SFelix Fietkau struct ieee80211_sta *sta); 150030ce7f44SFelix Fietkau 150138a45beaSFelix Fietkau int mt76_get_min_avg_rssi(struct mt76_dev *dev, u8 phy_idx); 1502ef13edc0SFelix Fietkau 1503764bf166SRazvan Grigore s8 mt76_get_power_bound(struct mt76_phy *phy, s8 txpower); 1504764bf166SRazvan Grigore 15059313faacSFelix Fietkau int mt76_get_txpower(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 150624dab555SRameshkumar Sundaram unsigned int link_id, int *dbm); 1507b3cb885eSLorenzo Bianconi int mt76_init_sar_power(struct ieee80211_hw *hw, 1508b3cb885eSLorenzo Bianconi const struct cfg80211_sar_specs *sar); 1509b3cb885eSLorenzo Bianconi int mt76_get_sar_power(struct mt76_phy *phy, 1510b3cb885eSLorenzo Bianconi struct ieee80211_channel *chan, 1511b3cb885eSLorenzo Bianconi int power); 15129313faacSFelix Fietkau 1513e7173858SFelix Fietkau void mt76_csa_check(struct mt76_dev *dev); 1514e7173858SFelix Fietkau void mt76_csa_finish(struct mt76_dev *dev); 1515e7173858SFelix Fietkau 1516e49c76d4SLorenzo Bianconi int mt76_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant); 151787d53103SStanislaw Gruszka int mt76_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set); 1518eadfd98fSLorenzo Bianconi void mt76_insert_ccmp_hdr(struct sk_buff *skb, u8 key_id); 1519d2679d65SLorenzo Bianconi int mt76_get_rate(struct mt76_dev *dev, 1520d2679d65SLorenzo Bianconi struct ieee80211_supported_band *sband, 1521d2679d65SLorenzo Bianconi int idx, bool cck); 152231083e38SFelix Fietkau int mt76_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 152331083e38SFelix Fietkau struct ieee80211_scan_request *hw_req); 152431083e38SFelix Fietkau void mt76_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif); 15258b8ab5c2SLorenzo Bianconi void mt76_sw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 15268b8ab5c2SLorenzo Bianconi const u8 *mac); 15278b8ab5c2SLorenzo Bianconi void mt76_sw_scan_complete(struct ieee80211_hw *hw, 15288b8ab5c2SLorenzo Bianconi struct ieee80211_vif *vif); 15293f306448SFelix Fietkau enum mt76_dfs_state mt76_phy_dfs_state(struct mt76_phy *phy); 153082334623SFelix Fietkau int mt76_add_chanctx(struct ieee80211_hw *hw, 153182334623SFelix Fietkau struct ieee80211_chanctx_conf *conf); 153282334623SFelix Fietkau void mt76_remove_chanctx(struct ieee80211_hw *hw, 153382334623SFelix Fietkau struct ieee80211_chanctx_conf *conf); 153482334623SFelix Fietkau void mt76_change_chanctx(struct ieee80211_hw *hw, 153582334623SFelix Fietkau struct ieee80211_chanctx_conf *conf, 153682334623SFelix Fietkau u32 changed); 153782334623SFelix Fietkau int mt76_assign_vif_chanctx(struct ieee80211_hw *hw, 153882334623SFelix Fietkau struct ieee80211_vif *vif, 153982334623SFelix Fietkau struct ieee80211_bss_conf *link_conf, 154082334623SFelix Fietkau struct ieee80211_chanctx_conf *conf); 154182334623SFelix Fietkau void mt76_unassign_vif_chanctx(struct ieee80211_hw *hw, 154282334623SFelix Fietkau struct ieee80211_vif *vif, 154382334623SFelix Fietkau struct ieee80211_bss_conf *link_conf, 154482334623SFelix Fietkau struct ieee80211_chanctx_conf *conf); 154582334623SFelix Fietkau int mt76_switch_vif_chanctx(struct ieee80211_hw *hw, 154682334623SFelix Fietkau struct ieee80211_vif_chanctx_switch *vifs, 154782334623SFelix Fietkau int n_vifs, 154882334623SFelix Fietkau enum ieee80211_chanctx_switch_mode mode); 1549a8f424c1SFelix Fietkau int mt76_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1550a8f424c1SFelix Fietkau struct ieee80211_channel *chan, int duration, 1551a8f424c1SFelix Fietkau enum ieee80211_roc_type type); 1552a8f424c1SFelix Fietkau int mt76_cancel_remain_on_channel(struct ieee80211_hw *hw, 1553a8f424c1SFelix Fietkau struct ieee80211_vif *vif); 1554f0efa862SFelix Fietkau int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1555f0efa862SFelix Fietkau void *data, int len); 1556f0efa862SFelix Fietkau int mt76_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *skb, 1557f0efa862SFelix Fietkau struct netlink_callback *cb, void *data, int len); 1558c918c74dSShayne Chen int mt76_testmode_set_state(struct mt76_phy *phy, enum mt76_testmode_state state); 15592601dda8SShayne Chen int mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len); 1560f0efa862SFelix Fietkau 1561c918c74dSShayne Chen static inline void mt76_testmode_reset(struct mt76_phy *phy, bool disable) 1562f0efa862SFelix Fietkau { 1563f0efa862SFelix Fietkau #ifdef CONFIG_NL80211_TESTMODE 1564f0efa862SFelix Fietkau enum mt76_testmode_state state = MT76_TM_STATE_IDLE; 1565f0efa862SFelix Fietkau 1566c918c74dSShayne Chen if (disable || phy->test.state == MT76_TM_STATE_OFF) 1567f0efa862SFelix Fietkau state = MT76_TM_STATE_OFF; 1568f0efa862SFelix Fietkau 1569c918c74dSShayne Chen mt76_testmode_set_state(phy, state); 1570f0efa862SFelix Fietkau #endif 1571f0efa862SFelix Fietkau } 1572f0efa862SFelix Fietkau 157387d53103SStanislaw Gruszka 157417f1de56SFelix Fietkau /* internal */ 1575e394b575SFelix Fietkau static inline struct ieee80211_hw * 1576e394b575SFelix Fietkau mt76_tx_status_get_hw(struct mt76_dev *dev, struct sk_buff *skb) 1577e394b575SFelix Fietkau { 1578e394b575SFelix Fietkau struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1579a062f001SLorenzo Bianconi u8 phy_idx = (info->hw_queue & MT_TX_HW_QUEUE_PHY) >> 2; 1580a062f001SLorenzo Bianconi struct ieee80211_hw *hw = mt76_phy_hw(dev, phy_idx); 1581e394b575SFelix Fietkau 1582a062f001SLorenzo Bianconi info->hw_queue &= ~MT_TX_HW_QUEUE_PHY; 1583e394b575SFelix Fietkau 1584e394b575SFelix Fietkau return hw; 1585e394b575SFelix Fietkau } 1586e394b575SFelix Fietkau 158717f1de56SFelix Fietkau void mt76_put_txwi(struct mt76_dev *dev, struct mt76_txwi_cache *t); 15882666beceSSujuan Chen void mt76_put_rxwi(struct mt76_dev *dev, struct mt76_txwi_cache *t); 15892666beceSSujuan Chen struct mt76_txwi_cache *mt76_get_rxwi(struct mt76_dev *dev); 1590a97a467aSSujuan Chen void mt76_free_pending_rxwi(struct mt76_dev *dev); 15919d9d738bSFelix Fietkau void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames, 159281e850efSLorenzo Bianconi struct napi_struct *napi); 159381e850efSLorenzo Bianconi void mt76_rx_poll_complete(struct mt76_dev *dev, enum mt76_rxq_id q, 159481e850efSLorenzo Bianconi struct napi_struct *napi); 1595aee5b8cfSFelix Fietkau void mt76_rx_aggr_reorder(struct sk_buff *skb, struct sk_buff_head *frames); 1596c918c74dSShayne Chen void mt76_testmode_tx_pending(struct mt76_phy *phy); 1597fe5b5ab5SFelix Fietkau void mt76_queue_tx_complete(struct mt76_dev *dev, struct mt76_queue *q, 1598fe5b5ab5SFelix Fietkau struct mt76_queue_entry *e); 159982334623SFelix Fietkau int __mt76_set_channel(struct mt76_phy *phy, struct cfg80211_chan_def *chandef, 160082334623SFelix Fietkau bool offchannel); 1601f4fdd771SFelix Fietkau int mt76_set_channel(struct mt76_phy *phy, struct cfg80211_chan_def *chandef, 1602f4fdd771SFelix Fietkau bool offchannel); 160331083e38SFelix Fietkau void mt76_scan_work(struct work_struct *work); 160431083e38SFelix Fietkau void mt76_abort_scan(struct mt76_dev *dev); 1605a8f424c1SFelix Fietkau void mt76_roc_complete_work(struct work_struct *work); 1606a8f424c1SFelix Fietkau void mt76_abort_roc(struct mt76_phy *phy); 1607e411b819SFelix Fietkau struct mt76_vif_link *mt76_get_vif_phy_link(struct mt76_phy *phy, 1608e411b819SFelix Fietkau struct ieee80211_vif *vif); 1609e411b819SFelix Fietkau void mt76_put_vif_phy_link(struct mt76_phy *phy, struct ieee80211_vif *vif, 1610e411b819SFelix Fietkau struct mt76_vif_link *mlink); 161117f1de56SFelix Fietkau 1612b40b15e1SLorenzo Bianconi /* usb */ 1613b40b15e1SLorenzo Bianconi static inline bool mt76u_urb_error(struct urb *urb) 1614b40b15e1SLorenzo Bianconi { 1615b40b15e1SLorenzo Bianconi return urb->status && 1616b40b15e1SLorenzo Bianconi urb->status != -ECONNRESET && 1617b40b15e1SLorenzo Bianconi urb->status != -ESHUTDOWN && 1618b40b15e1SLorenzo Bianconi urb->status != -ENOENT; 1619b40b15e1SLorenzo Bianconi } 1620b40b15e1SLorenzo Bianconi 16215de4db8fSStanislaw Gruszka static inline int 1622b63aa031SStanislaw Gruszka mt76u_bulk_msg(struct mt76_dev *dev, void *data, int len, int *actual_len, 16233bcd979cSLorenzo Bianconi int timeout, int ep) 16245de4db8fSStanislaw Gruszka { 162580df01f4SLorenzo Bianconi struct usb_interface *uintf = to_usb_interface(dev->dev); 162680df01f4SLorenzo Bianconi struct usb_device *udev = interface_to_usbdev(uintf); 16275de4db8fSStanislaw Gruszka struct mt76_usb *usb = &dev->usb; 16285de4db8fSStanislaw Gruszka unsigned int pipe; 16295de4db8fSStanislaw Gruszka 1630b63aa031SStanislaw Gruszka if (actual_len) 16313bcd979cSLorenzo Bianconi pipe = usb_rcvbulkpipe(udev, usb->in_ep[ep]); 1632b63aa031SStanislaw Gruszka else 16333bcd979cSLorenzo Bianconi pipe = usb_sndbulkpipe(udev, usb->out_ep[ep]); 1634b63aa031SStanislaw Gruszka 1635b63aa031SStanislaw Gruszka return usb_bulk_msg(udev, pipe, data, len, actual_len, timeout); 16365de4db8fSStanislaw Gruszka } 16375de4db8fSStanislaw Gruszka 1638192ad406SLorenzo Bianconi void mt76_ethtool_page_pool_stats(struct mt76_dev *dev, u64 *data, int *index); 163954ae98ffSLorenzo Bianconi void mt76_ethtool_worker(struct mt76_ethtool_worker_info *wi, 1640731425f3SShayne Chen struct mt76_sta_stats *stats, bool eht); 1641e98e6df6SLorenzo Bianconi int mt76_skb_adjust_pad(struct sk_buff *skb, int pad); 16426cb596baSLorenzo Bianconi int __mt76u_vendor_request(struct mt76_dev *dev, u8 req, u8 req_type, 16436cb596baSLorenzo Bianconi u16 val, u16 offset, void *buf, size_t len); 1644b40b15e1SLorenzo Bianconi int mt76u_vendor_request(struct mt76_dev *dev, u8 req, 1645b40b15e1SLorenzo Bianconi u8 req_type, u16 val, u16 offset, 1646b40b15e1SLorenzo Bianconi void *buf, size_t len); 1647b40b15e1SLorenzo Bianconi void mt76u_single_wr(struct mt76_dev *dev, const u8 req, 1648b40b15e1SLorenzo Bianconi const u16 offset, const u32 val); 16496cb596baSLorenzo Bianconi void mt76u_read_copy(struct mt76_dev *dev, u32 offset, 16506cb596baSLorenzo Bianconi void *data, int len); 16516cb596baSLorenzo Bianconi u32 ___mt76u_rr(struct mt76_dev *dev, u8 req, u8 req_type, u32 addr); 16526cb596baSLorenzo Bianconi void ___mt76u_wr(struct mt76_dev *dev, u8 req, u8 req_type, 16536cb596baSLorenzo Bianconi u32 addr, u32 val); 16546cb596baSLorenzo Bianconi int __mt76u_init(struct mt76_dev *dev, struct usb_interface *intf, 16556cb596baSLorenzo Bianconi struct mt76_bus_ops *ops); 16566cb596baSLorenzo Bianconi int mt76u_init(struct mt76_dev *dev, struct usb_interface *intf); 165794e1cfa8SLorenzo Bianconi int mt76u_alloc_mcu_queue(struct mt76_dev *dev); 1658b40b15e1SLorenzo Bianconi int mt76u_alloc_queues(struct mt76_dev *dev); 165939d501d9SStanislaw Gruszka void mt76u_stop_tx(struct mt76_dev *dev); 166039d501d9SStanislaw Gruszka void mt76u_stop_rx(struct mt76_dev *dev); 166139d501d9SStanislaw Gruszka int mt76u_resume_rx(struct mt76_dev *dev); 1662b40b15e1SLorenzo Bianconi void mt76u_queues_deinit(struct mt76_dev *dev); 1663b40b15e1SLorenzo Bianconi 1664d39b52e3SSean Wang int mt76s_init(struct mt76_dev *dev, struct sdio_func *func, 1665d39b52e3SSean Wang const struct mt76_bus_ops *bus_ops); 1666d512b008SLorenzo Bianconi int mt76s_alloc_rx_queue(struct mt76_dev *dev, enum mt76_rxq_id qid); 1667d512b008SLorenzo Bianconi int mt76s_alloc_tx(struct mt76_dev *dev); 1668d39b52e3SSean Wang void mt76s_deinit(struct mt76_dev *dev); 1669764dee47SLorenzo Bianconi void mt76s_sdio_irq(struct sdio_func *func); 1670764dee47SLorenzo Bianconi void mt76s_txrx_worker(struct mt76_sdio *sdio); 1671ca74b9b9SSean Wang bool mt76s_txqs_empty(struct mt76_dev *dev); 1672dacf0acfSSean Wang int mt76s_hw_init(struct mt76_dev *dev, struct sdio_func *func, 1673dacf0acfSSean Wang int hw_ver); 1674764dee47SLorenzo Bianconi u32 mt76s_rr(struct mt76_dev *dev, u32 offset); 1675764dee47SLorenzo Bianconi void mt76s_wr(struct mt76_dev *dev, u32 offset, u32 val); 1676764dee47SLorenzo Bianconi u32 mt76s_rmw(struct mt76_dev *dev, u32 offset, u32 mask, u32 val); 1677764dee47SLorenzo Bianconi u32 mt76s_read_pcr(struct mt76_dev *dev); 1678764dee47SLorenzo Bianconi void mt76s_write_copy(struct mt76_dev *dev, u32 offset, 1679764dee47SLorenzo Bianconi const void *data, int len); 1680764dee47SLorenzo Bianconi void mt76s_read_copy(struct mt76_dev *dev, u32 offset, 1681764dee47SLorenzo Bianconi void *data, int len); 1682764dee47SLorenzo Bianconi int mt76s_wr_rp(struct mt76_dev *dev, u32 base, 1683764dee47SLorenzo Bianconi const struct mt76_reg_pair *data, 1684764dee47SLorenzo Bianconi int len); 1685764dee47SLorenzo Bianconi int mt76s_rd_rp(struct mt76_dev *dev, u32 base, 1686764dee47SLorenzo Bianconi struct mt76_reg_pair *data, int len); 1687d39b52e3SSean Wang 16889df0fab9SLorenzo Bianconi struct sk_buff * 1689a0a2034eSLorenzo Bianconi __mt76_mcu_msg_alloc(struct mt76_dev *dev, const void *data, 1690b146f238SLorenzo Bianconi int len, int data_len, gfp_t gfp); 1691a0a2034eSLorenzo Bianconi static inline struct sk_buff * 1692bb31a80eSLorenzo Bianconi mt76_mcu_msg_alloc(struct mt76_dev *dev, const void *data, 1693a0a2034eSLorenzo Bianconi int data_len) 1694a0a2034eSLorenzo Bianconi { 1695b146f238SLorenzo Bianconi return __mt76_mcu_msg_alloc(dev, data, data_len, data_len, GFP_KERNEL); 1696a0a2034eSLorenzo Bianconi } 1697a0a2034eSLorenzo Bianconi 1698c07a49d4SLorenzo Bianconi void mt76_mcu_rx_event(struct mt76_dev *dev, struct sk_buff *skb); 1699680abb25SLorenzo Bianconi struct sk_buff *mt76_mcu_get_response(struct mt76_dev *dev, 1700680abb25SLorenzo Bianconi unsigned long expires); 1701ae5ad627SFelix Fietkau int mt76_mcu_send_and_get_msg(struct mt76_dev *dev, int cmd, const void *data, 1702ae5ad627SFelix Fietkau int len, bool wait_resp, struct sk_buff **ret); 1703ae5ad627SFelix Fietkau int mt76_mcu_skb_send_and_get_msg(struct mt76_dev *dev, struct sk_buff *skb, 1704ae5ad627SFelix Fietkau int cmd, bool wait_resp, struct sk_buff **ret); 1705215a2efaSLorenzo Bianconi int __mt76_mcu_send_firmware(struct mt76_dev *dev, int cmd, const void *data, 1706215a2efaSLorenzo Bianconi int len, int max_len); 1707215a2efaSLorenzo Bianconi static inline int 1708215a2efaSLorenzo Bianconi mt76_mcu_send_firmware(struct mt76_dev *dev, int cmd, const void *data, 1709215a2efaSLorenzo Bianconi int len) 1710215a2efaSLorenzo Bianconi { 17115b8f1840SSean Wang int max_len = 4096 - dev->mcu_ops->headroom; 17125b8f1840SSean Wang 17135b8f1840SSean Wang return __mt76_mcu_send_firmware(dev, cmd, data, len, max_len); 1714215a2efaSLorenzo Bianconi } 1715215a2efaSLorenzo Bianconi 1716ae5ad627SFelix Fietkau static inline int 1717ae5ad627SFelix Fietkau mt76_mcu_send_msg(struct mt76_dev *dev, int cmd, const void *data, int len, 1718ae5ad627SFelix Fietkau bool wait_resp) 1719ae5ad627SFelix Fietkau { 1720ae5ad627SFelix Fietkau return mt76_mcu_send_and_get_msg(dev, cmd, data, len, wait_resp, NULL); 1721ae5ad627SFelix Fietkau } 1722ae5ad627SFelix Fietkau 1723ae5ad627SFelix Fietkau static inline int 1724ae5ad627SFelix Fietkau mt76_mcu_skb_send_msg(struct mt76_dev *dev, struct sk_buff *skb, int cmd, 1725ae5ad627SFelix Fietkau bool wait_resp) 1726ae5ad627SFelix Fietkau { 1727ae5ad627SFelix Fietkau return mt76_mcu_skb_send_and_get_msg(dev, skb, cmd, wait_resp, NULL); 1728ae5ad627SFelix Fietkau } 17299df0fab9SLorenzo Bianconi 17309220f695SLorenzo Bianconi void mt76_set_irq_mask(struct mt76_dev *dev, u32 addr, u32 clear, u32 set); 17319220f695SLorenzo Bianconi 173209382d8fSMing Yen Hsieh struct device_node * 173309382d8fSMing Yen Hsieh mt76_find_power_limits_node(struct mt76_dev *dev); 173409382d8fSMing Yen Hsieh struct device_node * 173509382d8fSMing Yen Hsieh mt76_find_channel_node(struct device_node *np, struct ieee80211_channel *chan); 173609382d8fSMing Yen Hsieh 173722b980baSFelix Fietkau s8 mt76_get_rate_power_limits(struct mt76_phy *phy, 173822b980baSFelix Fietkau struct ieee80211_channel *chan, 173922b980baSFelix Fietkau struct mt76_power_limits *dest, 174022b980baSFelix Fietkau s8 target_power); 174122b980baSFelix Fietkau 17423c37da57SLorenzo Bianconi static inline bool mt76_queue_is_rx(struct mt76_dev *dev, struct mt76_queue *q) 17433c37da57SLorenzo Bianconi { 17443c37da57SLorenzo Bianconi int i; 17453c37da57SLorenzo Bianconi 17463c37da57SLorenzo Bianconi for (i = 0; i < ARRAY_SIZE(dev->q_rx); i++) { 17473c37da57SLorenzo Bianconi if (q == &dev->q_rx[i]) 17483c37da57SLorenzo Bianconi return true; 17493c37da57SLorenzo Bianconi } 17503c37da57SLorenzo Bianconi 17513c37da57SLorenzo Bianconi return false; 17523c37da57SLorenzo Bianconi } 17533c37da57SLorenzo Bianconi 1754132d74d3SLorenzo Bianconi static inline bool mt76_queue_is_wed_tx_free(struct mt76_queue *q) 1755132d74d3SLorenzo Bianconi { 1756132d74d3SLorenzo Bianconi return (q->flags & MT_QFLAG_WED) && 1757132d74d3SLorenzo Bianconi FIELD_GET(MT_QFLAG_WED_TYPE, q->flags) == MT76_WED_Q_TXFREE; 1758132d74d3SLorenzo Bianconi } 1759132d74d3SLorenzo Bianconi 1760950d0abbSBo Jiao static inline bool mt76_queue_is_wed_rro(struct mt76_queue *q) 1761950d0abbSBo Jiao { 1762950d0abbSBo Jiao return q->flags & MT_QFLAG_WED_RRO; 1763950d0abbSBo Jiao } 1764950d0abbSBo Jiao 1765950d0abbSBo Jiao static inline bool mt76_queue_is_wed_rro_ind(struct mt76_queue *q) 1766950d0abbSBo Jiao { 1767950d0abbSBo Jiao return mt76_queue_is_wed_rro(q) && 1768950d0abbSBo Jiao FIELD_GET(MT_QFLAG_WED_TYPE, q->flags) == MT76_WED_RRO_Q_IND; 1769950d0abbSBo Jiao } 1770950d0abbSBo Jiao 1771950d0abbSBo Jiao static inline bool mt76_queue_is_wed_rro_data(struct mt76_queue *q) 1772950d0abbSBo Jiao { 1773950d0abbSBo Jiao return mt76_queue_is_wed_rro(q) && 1774950d0abbSBo Jiao (FIELD_GET(MT_QFLAG_WED_TYPE, q->flags) == MT76_WED_RRO_Q_DATA || 1775950d0abbSBo Jiao FIELD_GET(MT_QFLAG_WED_TYPE, q->flags) == MT76_WED_RRO_Q_MSDU_PG); 1776950d0abbSBo Jiao } 1777950d0abbSBo Jiao 177858bcd4edSLorenzo Bianconi static inline bool mt76_queue_is_wed_rx(struct mt76_queue *q) 177958bcd4edSLorenzo Bianconi { 1780950d0abbSBo Jiao if (!(q->flags & MT_QFLAG_WED)) 1781950d0abbSBo Jiao return false; 1782950d0abbSBo Jiao 1783950d0abbSBo Jiao return FIELD_GET(MT_QFLAG_WED_TYPE, q->flags) == MT76_WED_Q_RX || 1784950d0abbSBo Jiao mt76_queue_is_wed_rro_ind(q) || mt76_queue_is_wed_rro_data(q); 1785950d0abbSBo Jiao 178658bcd4edSLorenzo Bianconi } 178758bcd4edSLorenzo Bianconi 1788d089692bSLorenzo Bianconi struct mt76_txwi_cache * 1789d089692bSLorenzo Bianconi mt76_token_release(struct mt76_dev *dev, int token, bool *wake); 1790d089692bSLorenzo Bianconi int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi); 1791d089692bSLorenzo Bianconi void __mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked); 17922666beceSSujuan Chen struct mt76_txwi_cache *mt76_rx_token_release(struct mt76_dev *dev, int token); 17932666beceSSujuan Chen int mt76_rx_token_consume(struct mt76_dev *dev, void *ptr, 17942666beceSSujuan Chen struct mt76_txwi_cache *r, dma_addr_t phys); 17952f5c3c77SLorenzo Bianconi int mt76_create_page_pool(struct mt76_dev *dev, struct mt76_queue *q); 17962f5c3c77SLorenzo Bianconi static inline void mt76_put_page_pool_buf(void *buf, bool allow_direct) 17972f5c3c77SLorenzo Bianconi { 17982f5c3c77SLorenzo Bianconi struct page *page = virt_to_head_page(buf); 17992f5c3c77SLorenzo Bianconi 18002f5c3c77SLorenzo Bianconi page_pool_put_full_page(page->pp, page, allow_direct); 18012f5c3c77SLorenzo Bianconi } 18022f5c3c77SLorenzo Bianconi 18032f5c3c77SLorenzo Bianconi static inline void * 18042f5c3c77SLorenzo Bianconi mt76_get_page_pool_buf(struct mt76_queue *q, u32 *offset, u32 size) 18052f5c3c77SLorenzo Bianconi { 18062f5c3c77SLorenzo Bianconi struct page *page; 18072f5c3c77SLorenzo Bianconi 18082f5c3c77SLorenzo Bianconi page = page_pool_dev_alloc_frag(q->page_pool, offset, size); 18092f5c3c77SLorenzo Bianconi if (!page) 18102f5c3c77SLorenzo Bianconi return NULL; 18112f5c3c77SLorenzo Bianconi 18122f5c3c77SLorenzo Bianconi return page_address(page) + *offset; 18132f5c3c77SLorenzo Bianconi } 1814d089692bSLorenzo Bianconi 1815d089692bSLorenzo Bianconi static inline void mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked) 1816d089692bSLorenzo Bianconi { 1817d089692bSLorenzo Bianconi spin_lock_bh(&dev->token_lock); 1818d089692bSLorenzo Bianconi __mt76_set_tx_blocked(dev, blocked); 1819d089692bSLorenzo Bianconi spin_unlock_bh(&dev->token_lock); 1820d089692bSLorenzo Bianconi } 1821d089692bSLorenzo Bianconi 1822d089692bSLorenzo Bianconi static inline int 1823d089692bSLorenzo Bianconi mt76_token_get(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi) 1824d089692bSLorenzo Bianconi { 1825d089692bSLorenzo Bianconi int token; 1826d089692bSLorenzo Bianconi 1827d089692bSLorenzo Bianconi spin_lock_bh(&dev->token_lock); 182861b5156bSFelix Fietkau token = idr_alloc(&dev->token, *ptxwi, 0, dev->token_size, GFP_ATOMIC); 1829d089692bSLorenzo Bianconi spin_unlock_bh(&dev->token_lock); 1830d089692bSLorenzo Bianconi 1831d089692bSLorenzo Bianconi return token; 1832d089692bSLorenzo Bianconi } 1833d089692bSLorenzo Bianconi 1834d089692bSLorenzo Bianconi static inline struct mt76_txwi_cache * 1835d089692bSLorenzo Bianconi mt76_token_put(struct mt76_dev *dev, int token) 1836d089692bSLorenzo Bianconi { 1837d089692bSLorenzo Bianconi struct mt76_txwi_cache *txwi; 1838d089692bSLorenzo Bianconi 1839d089692bSLorenzo Bianconi spin_lock_bh(&dev->token_lock); 1840d089692bSLorenzo Bianconi txwi = idr_remove(&dev->token, token); 1841d089692bSLorenzo Bianconi spin_unlock_bh(&dev->token_lock); 1842d089692bSLorenzo Bianconi 1843d089692bSLorenzo Bianconi return txwi; 1844d089692bSLorenzo Bianconi } 184590052b84SLorenzo Bianconi 1846cbf5e61dSFelix Fietkau void mt76_wcid_init(struct mt76_wcid *wcid, u8 band_idx); 18470335c034SFelix Fietkau void mt76_wcid_cleanup(struct mt76_dev *dev, struct mt76_wcid *wcid); 1848387ab042SFelix Fietkau void mt76_wcid_add_poll(struct mt76_dev *dev, struct mt76_wcid *wcid); 1849bd1e3e7bSLorenzo Bianconi 1850e24646efSFelix Fietkau static inline void 1851e24646efSFelix Fietkau mt76_vif_init(struct ieee80211_vif *vif, struct mt76_vif_data *mvif) 1852e24646efSFelix Fietkau { 1853e24646efSFelix Fietkau struct mt76_vif_link *mlink = (struct mt76_vif_link *)vif->drv_priv; 1854e24646efSFelix Fietkau 1855e24646efSFelix Fietkau mlink->mvif = mvif; 1856e24646efSFelix Fietkau rcu_assign_pointer(mvif->link[0], mlink); 1857e24646efSFelix Fietkau } 1858e24646efSFelix Fietkau 185982334623SFelix Fietkau void mt76_vif_cleanup(struct mt76_dev *dev, struct ieee80211_vif *vif); 1860e24646efSFelix Fietkau 1861e24646efSFelix Fietkau static inline struct mt76_vif_link * 1862e24646efSFelix Fietkau mt76_vif_link(struct mt76_dev *dev, struct ieee80211_vif *vif, int link_id) 1863e24646efSFelix Fietkau { 1864e24646efSFelix Fietkau struct mt76_vif_link *mlink = (struct mt76_vif_link *)vif->drv_priv; 1865e24646efSFelix Fietkau struct mt76_vif_data *mvif = mlink->mvif; 1866e24646efSFelix Fietkau 1867e24646efSFelix Fietkau return mt76_dereference(mvif->link[link_id], dev); 1868e24646efSFelix Fietkau } 1869e24646efSFelix Fietkau 1870e24646efSFelix Fietkau static inline struct mt76_vif_link * 1871e24646efSFelix Fietkau mt76_vif_conf_link(struct mt76_dev *dev, struct ieee80211_vif *vif, 1872e24646efSFelix Fietkau struct ieee80211_bss_conf *link_conf) 1873e24646efSFelix Fietkau { 1874e24646efSFelix Fietkau struct mt76_vif_link *mlink = (struct mt76_vif_link *)vif->drv_priv; 1875e24646efSFelix Fietkau struct mt76_vif_data *mvif = mlink->mvif; 1876e24646efSFelix Fietkau 1877e24646efSFelix Fietkau if (link_conf == &vif->bss_conf) 1878e24646efSFelix Fietkau return mlink; 1879e24646efSFelix Fietkau 1880e24646efSFelix Fietkau return mt76_dereference(mvif->link[link_conf->link_id], dev); 1881e24646efSFelix Fietkau } 1882e24646efSFelix Fietkau 188382334623SFelix Fietkau static inline struct mt76_phy * 188482334623SFelix Fietkau mt76_vif_link_phy(struct mt76_vif_link *mlink) 188582334623SFelix Fietkau { 188682334623SFelix Fietkau struct mt76_chanctx *ctx; 188782334623SFelix Fietkau 188882334623SFelix Fietkau if (!mlink->ctx) 188982334623SFelix Fietkau return NULL; 189082334623SFelix Fietkau 189182334623SFelix Fietkau ctx = (struct mt76_chanctx *)mlink->ctx->drv_priv; 189282334623SFelix Fietkau 189382334623SFelix Fietkau return ctx->phy; 189482334623SFelix Fietkau } 189582334623SFelix Fietkau 189617f1de56SFelix Fietkau #endif 1897