Path: blob/main/sys/contrib/dev/mediatek/mt76/mt76.h
105152 views
/* SPDX-License-Identifier: BSD-3-Clause-Clear */1/*2* Copyright (C) 2016 Felix Fietkau <[email protected]>3*/45#ifndef __MT76_H6#define __MT76_H78#include <linux/kernel.h>9#include <linux/io.h>10#include <linux/spinlock.h>11#include <linux/skbuff.h>12#include <linux/leds.h>13#include <linux/usb.h>14#include <linux/average.h>15#include <linux/soc/airoha/airoha_offload.h>16#include <linux/soc/mediatek/mtk_wed.h>17#if defined(__FreeBSD__)18#include <linux/wait.h>19#include <linux/bitfield.h>20#include <linux/debugfs.h>21#include <linux/pci.h>22#include <linux/interrupt.h>23#endif24#include <net/mac80211.h>25#include <net/page_pool/helpers.h>26#include "util.h"27#include "testmode.h"2829#define MT_MCU_RING_SIZE 3230#define MT_RX_BUF_SIZE 204831#define MT_SKB_HEAD_LEN 2563233#define MT_MAX_NON_AQL_PKT 1634#define MT_TXQ_FREE_THR 323536#define MT76_TOKEN_FREE_THR 643738#define MT_QFLAG_WED_RING GENMASK(1, 0)39#define MT_QFLAG_WED_TYPE GENMASK(4, 2)40#define MT_QFLAG_WED BIT(5)41#define MT_QFLAG_WED_RRO BIT(6)42#define MT_QFLAG_WED_RRO_EN BIT(7)43#define MT_QFLAG_EMI_EN BIT(8)44#define MT_QFLAG_NPU BIT(9)4546#define __MT_WED_Q(_type, _n) (MT_QFLAG_WED | \47FIELD_PREP(MT_QFLAG_WED_TYPE, _type) | \48FIELD_PREP(MT_QFLAG_WED_RING, _n))49#define __MT_WED_RRO_Q(_type, _n) (MT_QFLAG_WED_RRO | __MT_WED_Q(_type, _n))5051#define MT_WED_Q_TX(_n) __MT_WED_Q(MT76_WED_Q_TX, _n)52#define MT_WED_Q_RX(_n) __MT_WED_Q(MT76_WED_Q_RX, _n)53#define MT_WED_Q_TXFREE __MT_WED_Q(MT76_WED_Q_TXFREE, 0)54#define MT_WED_RRO_Q_DATA(_n) __MT_WED_RRO_Q(MT76_WED_RRO_Q_DATA, _n)55#define MT_WED_RRO_Q_MSDU_PG(_n) __MT_WED_RRO_Q(MT76_WED_RRO_Q_MSDU_PG, _n)56#define MT_WED_RRO_Q_IND __MT_WED_RRO_Q(MT76_WED_RRO_Q_IND, 0)57#define MT_WED_RRO_Q_RXDMAD_C __MT_WED_RRO_Q(MT76_WED_RRO_Q_RXDMAD_C, 0)5859#define __MT_NPU_Q(_type, _n) (MT_QFLAG_NPU | \60FIELD_PREP(MT_QFLAG_WED_TYPE, _type) | \61FIELD_PREP(MT_QFLAG_WED_RING, _n))62#define MT_NPU_Q_TX(_n) __MT_NPU_Q(MT76_WED_Q_TX, _n)63#define MT_NPU_Q_RX(_n) __MT_NPU_Q(MT76_WED_Q_RX, _n)6465struct mt76_dev;66struct mt76_phy;67struct mt76_wcid;68struct mt76s_intr;69struct mt76_chanctx;70struct mt76_vif_link;7172struct mt76_reg_pair {73u32 reg;74u32 value;75};7677enum mt76_bus_type {78MT76_BUS_MMIO,79MT76_BUS_USB,80MT76_BUS_SDIO,81};8283enum mt76_wed_type {84MT76_WED_Q_TX,85MT76_WED_Q_TXFREE,86MT76_WED_Q_RX,87MT76_WED_RRO_Q_DATA,88MT76_WED_RRO_Q_MSDU_PG,89MT76_WED_RRO_Q_IND,90MT76_WED_RRO_Q_RXDMAD_C,91};9293enum mt76_hwrro_mode {94MT76_HWRRO_OFF,95MT76_HWRRO_V3,96MT76_HWRRO_V3_1,97};9899struct mt76_bus_ops {100u32 (*rr)(struct mt76_dev *dev, u32 offset);101void (*wr)(struct mt76_dev *dev, u32 offset, u32 val);102u32 (*rmw)(struct mt76_dev *dev, u32 offset, u32 mask, u32 val);103void (*write_copy)(struct mt76_dev *dev, u32 offset, const void *data,104int len);105void (*read_copy)(struct mt76_dev *dev, u32 offset, void *data,106int len);107int (*wr_rp)(struct mt76_dev *dev, u32 base,108const struct mt76_reg_pair *rp, int len);109int (*rd_rp)(struct mt76_dev *dev, u32 base,110struct mt76_reg_pair *rp, int len);111enum mt76_bus_type type;112};113114#define mt76_is_usb(dev) ((dev)->bus->type == MT76_BUS_USB)115#define mt76_is_mmio(dev) ((dev)->bus->type == MT76_BUS_MMIO)116#define mt76_is_sdio(dev) ((dev)->bus->type == MT76_BUS_SDIO)117118enum mt76_txq_id {119MT_TXQ_VO = IEEE80211_AC_VO,120MT_TXQ_VI = IEEE80211_AC_VI,121MT_TXQ_BE = IEEE80211_AC_BE,122MT_TXQ_BK = IEEE80211_AC_BK,123MT_TXQ_PSD,124MT_TXQ_BEACON,125MT_TXQ_CAB,126__MT_TXQ_MAX127};128129enum mt76_mcuq_id {130MT_MCUQ_WM,131MT_MCUQ_WA,132MT_MCUQ_FWDL,133__MT_MCUQ_MAX134};135136enum mt76_rxq_id {137MT_RXQ_MAIN,138MT_RXQ_MCU,139MT_RXQ_MCU_WA,140MT_RXQ_BAND1,141MT_RXQ_BAND1_WA,142MT_RXQ_MAIN_WA,143MT_RXQ_BAND2,144MT_RXQ_BAND2_WA,145MT_RXQ_RRO_BAND0,146MT_RXQ_RRO_BAND1,147MT_RXQ_RRO_BAND2,148MT_RXQ_MSDU_PAGE_BAND0,149MT_RXQ_MSDU_PAGE_BAND1,150MT_RXQ_MSDU_PAGE_BAND2,151MT_RXQ_TXFREE_BAND0,152MT_RXQ_TXFREE_BAND1,153MT_RXQ_TXFREE_BAND2,154MT_RXQ_RRO_IND,155MT_RXQ_RRO_RXDMAD_C,156MT_RXQ_NPU0,157MT_RXQ_NPU1,158__MT_RXQ_MAX159};160161enum mt76_band_id {162MT_BAND0,163MT_BAND1,164MT_BAND2,165__MT_MAX_BAND166};167168enum mt76_cipher_type {169MT_CIPHER_NONE,170MT_CIPHER_WEP40,171MT_CIPHER_TKIP,172MT_CIPHER_TKIP_NO_MIC,173MT_CIPHER_AES_CCMP,174MT_CIPHER_WEP104,175MT_CIPHER_BIP_CMAC_128,176MT_CIPHER_WEP128,177MT_CIPHER_WAPI,178MT_CIPHER_CCMP_CCX,179MT_CIPHER_CCMP_256,180MT_CIPHER_GCMP,181MT_CIPHER_GCMP_256,182};183184enum mt76_dfs_state {185MT_DFS_STATE_UNKNOWN,186MT_DFS_STATE_DISABLED,187MT_DFS_STATE_CAC,188MT_DFS_STATE_ACTIVE,189};190191#define MT76_RNR_SCAN_MAX_BSSIDS 16192struct mt76_scan_rnr_param {193u8 bssid[MT76_RNR_SCAN_MAX_BSSIDS][ETH_ALEN];194u8 channel[MT76_RNR_SCAN_MAX_BSSIDS];195u8 random_mac[ETH_ALEN];196u8 seq_num;197u8 bssid_num;198u32 sreq_flag;199};200201struct mt76_queue_buf {202dma_addr_t addr;203u16 len:15,204skip_unmap:1;205};206207struct mt76_tx_info {208struct mt76_queue_buf buf[32];209struct sk_buff *skb;210int nbuf;211u32 info;212};213214struct mt76_queue_entry {215union {216void *buf;217struct sk_buff *skb;218};219union {220struct mt76_txwi_cache *txwi;221struct urb *urb;222int buf_sz;223};224dma_addr_t dma_addr[2];225u16 dma_len[2];226u16 wcid;227bool skip_buf0:1;228bool skip_buf1:1;229bool done:1;230};231232struct mt76_queue_regs {233u32 desc_base;234u32 ring_size;235u32 cpu_idx;236u32 dma_idx;237} __packed __aligned(4);238239struct mt76_queue {240struct mt76_queue_regs __iomem *regs;241242spinlock_t lock;243spinlock_t cleanup_lock;244struct mt76_queue_entry *entry;245struct mt76_rro_desc *rro_desc;246struct mt76_desc *desc;247248u16 first;249u16 head;250u16 tail;251u8 hw_idx;252u8 ep;253int ndesc;254int queued;255int buf_size;256bool stopped;257bool blocked;258259u8 buf_offset;260u16 flags;261u8 magic_cnt;262263__le16 *emi_cpu_idx;264265struct mtk_wed_device *wed;266struct mt76_dev *dev;267u32 wed_regs;268269dma_addr_t desc_dma;270struct sk_buff *rx_head;271struct page_pool *page_pool;272};273274struct mt76_mcu_ops {275unsigned int max_retry;276u32 headroom;277u32 tailroom;278279int (*mcu_send_msg)(struct mt76_dev *dev, int cmd, const void *data,280int len, bool wait_resp);281int (*mcu_skb_prepare_msg)(struct mt76_dev *dev, struct sk_buff *skb,282int cmd, int *seq);283int (*mcu_skb_send_msg)(struct mt76_dev *dev, struct sk_buff *skb,284int cmd, int *seq);285int (*mcu_parse_response)(struct mt76_dev *dev, int cmd,286struct sk_buff *skb, int seq);287u32 (*mcu_rr)(struct mt76_dev *dev, u32 offset);288void (*mcu_wr)(struct mt76_dev *dev, u32 offset, u32 val);289int (*mcu_wr_rp)(struct mt76_dev *dev, u32 base,290const struct mt76_reg_pair *rp, int len);291int (*mcu_rd_rp)(struct mt76_dev *dev, u32 base,292struct mt76_reg_pair *rp, int len);293int (*mcu_restart)(struct mt76_dev *dev);294};295296struct mt76_queue_ops {297int (*init)(struct mt76_dev *dev,298int (*poll)(struct napi_struct *napi, int budget));299300int (*alloc)(struct mt76_dev *dev, struct mt76_queue *q,301int idx, int n_desc, int bufsize,302u32 ring_base);303304int (*tx_queue_skb)(struct mt76_phy *phy, struct mt76_queue *q,305enum mt76_txq_id qid, struct sk_buff *skb,306struct mt76_wcid *wcid, struct ieee80211_sta *sta);307308int (*tx_queue_skb_raw)(struct mt76_dev *dev, struct mt76_queue *q,309struct sk_buff *skb, u32 tx_info);310311void *(*dequeue)(struct mt76_dev *dev, struct mt76_queue *q, bool flush,312int *len, u32 *info, bool *more);313314void (*rx_reset)(struct mt76_dev *dev, enum mt76_rxq_id qid);315316void (*tx_cleanup)(struct mt76_dev *dev, struct mt76_queue *q,317bool flush);318319void (*rx_queue_init)(struct mt76_dev *dev, enum mt76_rxq_id qid,320int (*poll)(struct napi_struct *napi, int budget));321322void (*rx_cleanup)(struct mt76_dev *dev, struct mt76_queue *q);323324void (*kick)(struct mt76_dev *dev, struct mt76_queue *q);325326void (*reset_q)(struct mt76_dev *dev, struct mt76_queue *q,327bool reset_idx);328};329330enum mt76_phy_type {331MT_PHY_TYPE_CCK,332MT_PHY_TYPE_OFDM,333MT_PHY_TYPE_HT,334MT_PHY_TYPE_HT_GF,335MT_PHY_TYPE_VHT,336MT_PHY_TYPE_HE_SU = 8,337MT_PHY_TYPE_HE_EXT_SU,338MT_PHY_TYPE_HE_TB,339MT_PHY_TYPE_HE_MU,340MT_PHY_TYPE_EHT_SU = 13,341MT_PHY_TYPE_EHT_TRIG,342MT_PHY_TYPE_EHT_MU,343__MT_PHY_TYPE_MAX,344};345346struct mt76_sta_stats {347u64 tx_mode[__MT_PHY_TYPE_MAX];348u64 tx_bw[5]; /* 20, 40, 80, 160, 320 */349u64 tx_nss[4]; /* 1, 2, 3, 4 */350u64 tx_mcs[16]; /* mcs idx */351u64 tx_bytes;352/* WED TX */353u32 tx_packets; /* unit: MSDU */354u32 tx_retries;355u32 tx_failed;356/* WED RX */357u64 rx_bytes;358u32 rx_packets;359u32 rx_errors;360u32 rx_drops;361};362363enum mt76_wcid_flags {364MT_WCID_FLAG_CHECK_PS,365MT_WCID_FLAG_PS,366MT_WCID_FLAG_4ADDR,367MT_WCID_FLAG_HDR_TRANS,368};369370#define MT76_N_WCIDS 1088371372/* stored in ieee80211_tx_info::hw_queue */373#define MT_TX_HW_QUEUE_PHY GENMASK(3, 2)374375DECLARE_EWMA(signal, 10, 8);376377#define MT_WCID_TX_INFO_RATE GENMASK(15, 0)378#define MT_WCID_TX_INFO_NSS GENMASK(17, 16)379#define MT_WCID_TX_INFO_TXPWR_ADJ GENMASK(25, 18)380#define MT_WCID_TX_INFO_SET BIT(31)381382struct mt76_wcid {383struct mt76_rx_tid __rcu *aggr[IEEE80211_NUM_TIDS];384385atomic_t non_aql_packets;386unsigned long flags;387388struct ewma_signal rssi;389int inactive_count;390391struct rate_info rate;392unsigned long ampdu_state;393394u16 idx;395u8 hw_key_idx;396u8 hw_key_idx2;397398u8 offchannel:1;399u8 sta:1;400u8 sta_disabled:1;401u8 amsdu:1;402u8 phy_idx:2;403u8 link_id:4;404bool link_valid;405406u8 rx_check_pn;407u8 rx_key_pn[IEEE80211_NUM_TIDS + 1][6];408u16 cipher;409410u32 tx_info;411bool sw_iv;412413struct list_head tx_list;414struct sk_buff_head tx_pending;415struct sk_buff_head tx_offchannel;416417struct list_head list;418struct idr pktid;419420struct mt76_sta_stats stats;421422struct list_head poll_list;423424struct mt76_wcid *def_wcid;425};426427struct mt76_txq {428u16 wcid;429430u16 agg_ssn;431bool send_bar;432bool aggr;433};434435/* data0 */436#define RRO_IND_DATA0_IND_REASON_MASK GENMASK(31, 28)437#define RRO_IND_DATA0_START_SEQ_MASK GENMASK(27, 16)438#define RRO_IND_DATA0_SEQ_ID_MASK GENMASK(11, 0)439/* data1 */440#define RRO_IND_DATA1_MAGIC_CNT_MASK GENMASK(31, 29)441#define RRO_IND_DATA1_IND_COUNT_MASK GENMASK(12, 0)442struct mt76_wed_rro_ind {443__le32 data0;444__le32 data1;445};446447struct mt76_txwi_cache {448struct list_head list;449dma_addr_t dma_addr;450451union {452struct sk_buff *skb;453void *ptr;454};455456u8 qid;457};458459struct mt76_rx_tid {460struct rcu_head rcu_head;461462struct mt76_dev *dev;463464spinlock_t lock;465struct delayed_work reorder_work;466467u16 id;468u16 head;469u16 size;470u16 nframes;471472u8 num;473474u8 started:1, stopped:1, timer_pending:1;475476struct sk_buff *reorder_buf[] __counted_by(size);477};478479#define MT_TX_CB_DMA_DONE BIT(0)480#define MT_TX_CB_TXS_DONE BIT(1)481#define MT_TX_CB_TXS_FAILED BIT(2)482483#define MT_PACKET_ID_MASK GENMASK(6, 0)484#define MT_PACKET_ID_NO_ACK 0485#define MT_PACKET_ID_NO_SKB 1486#define MT_PACKET_ID_WED 2487#define MT_PACKET_ID_FIRST 3488#define MT_PACKET_ID_HAS_RATE BIT(7)489/* This is timer for when to give up when waiting for TXS callback,490* with starting time being the time at which the DMA_DONE callback491* was seen (so, we know packet was processed then, it should not take492* long after that for firmware to send the TXS callback if it is going493* to do so.)494*/495#define MT_TX_STATUS_SKB_TIMEOUT (HZ / 4)496497struct mt76_tx_cb {498unsigned long jiffies;499u16 wcid;500u8 pktid;501u8 flags;502};503504enum {505MT76_STATE_INITIALIZED,506MT76_STATE_REGISTERED,507MT76_STATE_RUNNING,508MT76_STATE_MCU_RUNNING,509MT76_SCANNING,510MT76_HW_SCANNING,511MT76_HW_SCHED_SCANNING,512MT76_RESTART,513MT76_RESET,514MT76_MCU_RESET,515MT76_REMOVED,516MT76_READING_STATS,517MT76_STATE_POWER_OFF,518MT76_STATE_SUSPEND,519MT76_STATE_ROC,520MT76_STATE_PM,521MT76_STATE_WED_RESET,522};523524enum mt76_sta_event {525MT76_STA_EVENT_ASSOC,526MT76_STA_EVENT_AUTHORIZE,527MT76_STA_EVENT_DISASSOC,528};529530struct mt76_hw_cap {531bool has_2ghz;532bool has_5ghz;533bool has_6ghz;534};535536#define MT_DRV_TXWI_NO_FREE BIT(0)537#define MT_DRV_TX_ALIGNED4_SKBS BIT(1)538#define MT_DRV_SW_RX_AIRTIME BIT(2)539#define MT_DRV_RX_DMA_HDR BIT(3)540#define MT_DRV_HW_MGMT_TXQ BIT(4)541#define MT_DRV_AMSDU_OFFLOAD BIT(5)542#define MT_DRV_IGNORE_TXS_FAILED BIT(6)543544struct mt76_driver_ops {545u32 drv_flags;546u32 survey_flags;547u16 txwi_size;548u16 token_size;549u8 mcs_rates;550551unsigned int link_data_size;552553void (*update_survey)(struct mt76_phy *phy);554int (*set_channel)(struct mt76_phy *phy);555556int (*tx_prepare_skb)(struct mt76_dev *dev, void *txwi_ptr,557enum mt76_txq_id qid, struct mt76_wcid *wcid,558struct ieee80211_sta *sta,559struct mt76_tx_info *tx_info);560561void (*tx_complete_skb)(struct mt76_dev *dev,562struct mt76_queue_entry *e);563564bool (*tx_status_data)(struct mt76_dev *dev, u8 *update);565566bool (*rx_check)(struct mt76_dev *dev, void *data, int len);567568void (*rx_skb)(struct mt76_dev *dev, enum mt76_rxq_id q,569struct sk_buff *skb, u32 *info);570571void (*rx_poll_complete)(struct mt76_dev *dev, enum mt76_rxq_id q);572573void (*rx_rro_ind_process)(struct mt76_dev *dev, void *data);574int (*rx_rro_add_msdu_page)(struct mt76_dev *dev, struct mt76_queue *q,575dma_addr_t p, void *data);576577void (*sta_ps)(struct mt76_dev *dev, struct ieee80211_sta *sta,578bool ps);579580int (*sta_add)(struct mt76_dev *dev, struct ieee80211_vif *vif,581struct ieee80211_sta *sta);582583int (*sta_event)(struct mt76_dev *dev, struct ieee80211_vif *vif,584struct ieee80211_sta *sta, enum mt76_sta_event ev);585586void (*sta_remove)(struct mt76_dev *dev, struct ieee80211_vif *vif,587struct ieee80211_sta *sta);588589int (*vif_link_add)(struct mt76_phy *phy, struct ieee80211_vif *vif,590struct ieee80211_bss_conf *link_conf,591struct mt76_vif_link *mlink);592593void (*vif_link_remove)(struct mt76_phy *phy,594struct ieee80211_vif *vif,595struct ieee80211_bss_conf *link_conf,596struct mt76_vif_link *mlink);597};598599struct mt76_channel_state {600u64 cc_active;601u64 cc_busy;602u64 cc_rx;603u64 cc_bss_rx;604u64 cc_tx;605606s8 noise;607};608609struct mt76_sband {610struct ieee80211_supported_band sband;611struct mt76_channel_state *chan;612};613614/* addr req mask */615#define MT_VEND_TYPE_EEPROM BIT(31)616#define MT_VEND_TYPE_CFG BIT(30)617#define MT_VEND_TYPE_MASK (MT_VEND_TYPE_EEPROM | MT_VEND_TYPE_CFG)618619#define MT_VEND_ADDR(type, n) (MT_VEND_TYPE_##type | (n))620enum mt_vendor_req {621MT_VEND_DEV_MODE = 0x1,622MT_VEND_WRITE = 0x2,623MT_VEND_POWER_ON = 0x4,624MT_VEND_MULTI_WRITE = 0x6,625MT_VEND_MULTI_READ = 0x7,626MT_VEND_READ_EEPROM = 0x9,627MT_VEND_WRITE_FCE = 0x42,628MT_VEND_WRITE_CFG = 0x46,629MT_VEND_READ_CFG = 0x47,630MT_VEND_READ_EXT = 0x63,631MT_VEND_WRITE_EXT = 0x66,632MT_VEND_FEATURE_SET = 0x91,633};634635enum mt76u_in_ep {636MT_EP_IN_PKT_RX,637MT_EP_IN_CMD_RESP,638__MT_EP_IN_MAX,639};640641enum mt76u_out_ep {642MT_EP_OUT_INBAND_CMD,643MT_EP_OUT_AC_BE,644MT_EP_OUT_AC_BK,645MT_EP_OUT_AC_VI,646MT_EP_OUT_AC_VO,647MT_EP_OUT_HCCA,648__MT_EP_OUT_MAX,649};650651struct mt76_mcu {652struct mutex mutex;653u32 msg_seq;654int timeout;655656struct sk_buff_head res_q;657wait_queue_head_t wait;658};659660#define MT_TX_SG_MAX_SIZE 8661#define MT_RX_SG_MAX_SIZE 4662#define MT_NUM_TX_ENTRIES 256663#define MT_NUM_RX_ENTRIES 128664#define MCU_RESP_URB_SIZE 1024665struct mt76_usb {666struct mutex usb_ctrl_mtx;667u8 *data;668u16 data_len;669670struct mt76_worker status_worker;671struct mt76_worker rx_worker;672673struct work_struct stat_work;674675u8 out_ep[__MT_EP_OUT_MAX];676u8 in_ep[__MT_EP_IN_MAX];677bool sg_en;678679struct mt76u_mcu {680u8 *data;681/* multiple reads */682struct mt76_reg_pair *rp;683int rp_len;684u32 base;685} mcu;686};687688#define MT76S_XMIT_BUF_SZ 0x3fe00689#define MT76S_NUM_TX_ENTRIES 256690#define MT76S_NUM_RX_ENTRIES 512691struct mt76_sdio {692struct mt76_worker txrx_worker;693struct mt76_worker status_worker;694struct mt76_worker net_worker;695struct mt76_worker stat_worker;696697u8 *xmit_buf;698u32 xmit_buf_sz;699700struct sdio_func *func;701void *intr_data;702u8 hw_ver;703wait_queue_head_t wait;704705int pse_mcu_quota_max;706struct {707int pse_data_quota;708int ple_data_quota;709int pse_mcu_quota;710int pse_page_size;711int deficit;712} sched;713714int (*parse_irq)(struct mt76_dev *dev, struct mt76s_intr *intr);715};716717struct mt76_mmio {718void __iomem *regs;719spinlock_t irq_lock;720u32 irqmask;721722struct mtk_wed_device wed;723struct mtk_wed_device wed_hif2;724struct completion wed_reset;725struct completion wed_reset_complete;726727struct airoha_ppe_dev __rcu *ppe_dev;728struct airoha_npu __rcu *npu;729phys_addr_t phy_addr;730int npu_type;731};732733struct mt76_rx_status {734union {735struct mt76_wcid *wcid;736u16 wcid_idx;737};738739u32 reorder_time;740741u32 ampdu_ref;742u32 timestamp;743744u8 iv[6];745746u8 phy_idx:2;747u8 aggr:1;748u8 qos_ctl;749u16 seqno;750751u16 freq;752u32 flag;753u8 enc_flags;754u8 encoding:3, bw:4;755union {756struct {757u8 he_ru:3;758u8 he_gi:2;759u8 he_dcm:1;760};761struct {762u8 ru:4;763u8 gi:2;764} eht;765};766767u8 amsdu:1, first_amsdu:1, last_amsdu:1;768u8 rate_idx;769u8 nss:5, band:3;770s8 signal;771u8 chains;772s8 chain_signal[IEEE80211_MAX_CHAINS];773};774775struct mt76_freq_range_power {776const struct cfg80211_sar_freq_ranges *range;777s8 power;778};779780struct mt76_testmode_ops {781int (*set_state)(struct mt76_phy *phy, enum mt76_testmode_state state);782int (*set_params)(struct mt76_phy *phy, struct nlattr **tb,783enum mt76_testmode_state new_state);784int (*dump_stats)(struct mt76_phy *phy, struct sk_buff *msg);785};786787struct mt76_testmode_data {788enum mt76_testmode_state state;789790u32 param_set[DIV_ROUND_UP(NUM_MT76_TM_ATTRS, 32)];791struct sk_buff *tx_skb;792793u32 tx_count;794u16 tx_mpdu_len;795796u8 tx_rate_mode;797u8 tx_rate_idx;798u8 tx_rate_nss;799u8 tx_rate_sgi;800u8 tx_rate_ldpc;801u8 tx_rate_stbc;802u8 tx_ltf;803804u8 tx_antenna_mask;805u8 tx_spe_idx;806807u8 tx_duty_cycle;808u32 tx_time;809u32 tx_ipg;810811u32 freq_offset;812813u8 tx_power[4];814u8 tx_power_control;815816u8 addr[3][ETH_ALEN];817818u32 tx_pending;819u32 tx_queued;820u16 tx_queued_limit;821u32 tx_done;822struct {823u64 packets[__MT_RXQ_MAX];824u64 fcs_error[__MT_RXQ_MAX];825} rx_stats;826};827828struct mt76_vif_link {829u8 idx;830u8 link_idx;831u8 omac_idx;832u8 band_idx;833u8 wmm_idx;834u8 scan_seq_num;835u8 cipher;836u8 basic_rates_idx;837u8 mcast_rates_idx;838u8 beacon_rates_idx;839bool offchannel;840struct ieee80211_chanctx_conf *ctx;841struct mt76_wcid *wcid;842struct mt76_vif_data *mvif;843struct rcu_head rcu_head;844};845846struct mt76_vif_data {847struct mt76_vif_link __rcu *link[IEEE80211_MLD_MAX_NUM_LINKS];848struct mt76_vif_link __rcu *offchannel_link;849850struct mt76_phy *roc_phy;851u16 valid_links;852u8 deflink_id;853};854855struct mt76_phy {856struct ieee80211_hw *hw;857struct mt76_dev *dev;858void *priv;859860unsigned long state;861unsigned int num_sta;862u8 band_idx;863864spinlock_t tx_lock;865struct list_head tx_list;866struct mt76_queue *q_tx[__MT_TXQ_MAX];867868struct cfg80211_chan_def chandef;869struct cfg80211_chan_def main_chandef;870bool offchannel;871bool radar_enabled;872873struct delayed_work roc_work;874struct ieee80211_vif *roc_vif;875struct mt76_vif_link *roc_link;876877struct mt76_chanctx *chanctx;878879struct mt76_channel_state *chan_state;880enum mt76_dfs_state dfs_state;881ktime_t survey_time;882883u32 aggr_stats[32];884885struct mt76_hw_cap cap;886struct mt76_sband sband_2g;887struct mt76_sband sband_5g;888struct mt76_sband sband_6g;889890u8 macaddr[ETH_ALEN];891892int txpower_cur;893u8 antenna_mask;894u16 chainmask;895896#ifdef CONFIG_NL80211_TESTMODE897struct mt76_testmode_data test;898#endif899900struct delayed_work mac_work;901u8 mac_work_count;902903struct {904struct sk_buff *head;905struct sk_buff **tail;906u16 seqno;907} rx_amsdu[__MT_RXQ_MAX];908909struct mt76_freq_range_power *frp;910911struct {912struct led_classdev cdev;913char name[32];914bool al;915u8 pin;916} leds;917};918919struct mt76_dev {920struct mt76_phy phy; /* must be first */921struct mt76_phy *phys[__MT_MAX_BAND];922struct mt76_phy *band_phys[NUM_NL80211_BANDS];923924struct ieee80211_hw *hw;925926spinlock_t wed_lock;927spinlock_t lock;928spinlock_t cc_lock;929930u32 cur_cc_bss_rx;931932struct mt76_rx_status rx_ampdu_status;933u32 rx_ampdu_len;934u32 rx_ampdu_ref;935936struct mutex mutex;937938const struct mt76_bus_ops *bus;939const struct mt76_driver_ops *drv;940const struct mt76_mcu_ops *mcu_ops;941struct device *dev;942struct device *dma_dev;943944struct mt76_mcu mcu;945946struct net_device *napi_dev;947struct net_device *tx_napi_dev;948spinlock_t rx_lock;949struct napi_struct napi[__MT_RXQ_MAX];950struct sk_buff_head rx_skb[__MT_RXQ_MAX];951struct tasklet_struct irq_tasklet;952953struct list_head txwi_cache;954struct list_head rxwi_cache;955struct mt76_queue *q_mcu[__MT_MCUQ_MAX];956struct mt76_queue q_rx[__MT_RXQ_MAX];957const struct mt76_queue_ops *queue_ops;958int tx_dma_idx[4];959enum mt76_hwrro_mode hwrro_mode;960961struct mt76_worker tx_worker;962struct napi_struct tx_napi;963964spinlock_t token_lock;965struct idr token;966u16 wed_token_count;967u16 token_count;968u16 token_start;969u16 token_size;970971spinlock_t rx_token_lock;972struct idr rx_token;973u16 rx_token_size;974975wait_queue_head_t tx_wait;976/* spinclock used to protect wcid pktid linked list */977spinlock_t status_lock;978979u32 wcid_mask[DIV_ROUND_UP(MT76_N_WCIDS, 32)];980981u64 vif_mask;982983struct mt76_wcid global_wcid;984struct mt76_wcid __rcu *wcid[MT76_N_WCIDS];985struct list_head wcid_list;986987struct list_head sta_poll_list;988spinlock_t sta_poll_lock;989990u32 rev;991992struct tasklet_struct pre_tbtt_tasklet;993int beacon_int;994u8 beacon_mask;995996struct debugfs_blob_wrapper eeprom;997struct debugfs_blob_wrapper otp;998999char alpha2[3];1000enum nl80211_dfs_regions region;10011002struct mt76_scan_rnr_param rnr;10031004u32 debugfs_reg;10051006u8 csa_complete;10071008u32 rxfilter;10091010struct delayed_work scan_work;1011struct {1012struct cfg80211_scan_request *req;1013struct ieee80211_channel *chan;1014struct ieee80211_vif *vif;1015struct mt76_vif_link *mlink;1016struct mt76_phy *phy;1017int chan_idx;1018} scan;10191020#ifdef CONFIG_NL80211_TESTMODE1021const struct mt76_testmode_ops *test_ops;1022struct {1023const char *name;1024u32 offset;1025} test_mtd;1026#endif1027struct workqueue_struct *wq;10281029union {1030struct mt76_mmio mmio;1031struct mt76_usb usb;1032struct mt76_sdio sdio;1033};10341035atomic_t bus_hung;1036};10371038/* per-phy stats. */1039struct mt76_mib_stats {1040u32 ack_fail_cnt;1041u32 fcs_err_cnt;1042u32 rts_cnt;1043u32 rts_retries_cnt;1044u32 ba_miss_cnt;1045u32 tx_bf_cnt;1046u32 tx_mu_bf_cnt;1047u32 tx_mu_mpdu_cnt;1048u32 tx_mu_acked_mpdu_cnt;1049u32 tx_su_acked_mpdu_cnt;1050u32 tx_bf_ibf_ppdu_cnt;1051u32 tx_bf_ebf_ppdu_cnt;10521053u32 tx_bf_rx_fb_all_cnt;1054u32 tx_bf_rx_fb_eht_cnt;1055u32 tx_bf_rx_fb_he_cnt;1056u32 tx_bf_rx_fb_vht_cnt;1057u32 tx_bf_rx_fb_ht_cnt;10581059u32 tx_bf_rx_fb_bw; /* value of last sample, not cumulative */1060u32 tx_bf_rx_fb_nc_cnt;1061u32 tx_bf_rx_fb_nr_cnt;1062u32 tx_bf_fb_cpl_cnt;1063u32 tx_bf_fb_trig_cnt;10641065u32 tx_ampdu_cnt;1066u32 tx_stop_q_empty_cnt;1067u32 tx_mpdu_attempts_cnt;1068u32 tx_mpdu_success_cnt;1069u32 tx_pkt_ebf_cnt;1070u32 tx_pkt_ibf_cnt;10711072u32 tx_rwp_fail_cnt;1073u32 tx_rwp_need_cnt;10741075/* rx stats */1076u32 rx_fifo_full_cnt;1077u32 channel_idle_cnt;1078u32 primary_cca_busy_time;1079u32 secondary_cca_busy_time;1080u32 primary_energy_detect_time;1081u32 cck_mdrdy_time;1082u32 ofdm_mdrdy_time;1083u32 green_mdrdy_time;1084u32 rx_vector_mismatch_cnt;1085u32 rx_delimiter_fail_cnt;1086u32 rx_mrdy_cnt;1087u32 rx_len_mismatch_cnt;1088u32 rx_mpdu_cnt;1089u32 rx_ampdu_cnt;1090u32 rx_ampdu_bytes_cnt;1091u32 rx_ampdu_valid_subframe_cnt;1092u32 rx_ampdu_valid_subframe_bytes_cnt;1093u32 rx_pfdrop_cnt;1094u32 rx_vec_queue_overflow_drop_cnt;1095u32 rx_ba_cnt;10961097u32 tx_amsdu[8];1098u32 tx_amsdu_cnt;10991100/* mcu_muru_stats */1101u32 dl_cck_cnt;1102u32 dl_ofdm_cnt;1103u32 dl_htmix_cnt;1104u32 dl_htgf_cnt;1105u32 dl_vht_su_cnt;1106u32 dl_vht_2mu_cnt;1107u32 dl_vht_3mu_cnt;1108u32 dl_vht_4mu_cnt;1109u32 dl_he_su_cnt;1110u32 dl_he_ext_su_cnt;1111u32 dl_he_2ru_cnt;1112u32 dl_he_2mu_cnt;1113u32 dl_he_3ru_cnt;1114u32 dl_he_3mu_cnt;1115u32 dl_he_4ru_cnt;1116u32 dl_he_4mu_cnt;1117u32 dl_he_5to8ru_cnt;1118u32 dl_he_9to16ru_cnt;1119u32 dl_he_gtr16ru_cnt;11201121u32 ul_hetrig_su_cnt;1122u32 ul_hetrig_2ru_cnt;1123u32 ul_hetrig_3ru_cnt;1124u32 ul_hetrig_4ru_cnt;1125u32 ul_hetrig_5to8ru_cnt;1126u32 ul_hetrig_9to16ru_cnt;1127u32 ul_hetrig_gtr16ru_cnt;1128u32 ul_hetrig_2mu_cnt;1129u32 ul_hetrig_3mu_cnt;1130u32 ul_hetrig_4mu_cnt;1131};11321133struct mt76_power_limits {1134s8 cck[4];1135s8 ofdm[8];1136s8 mcs[4][10];1137s8 ru[7][12];1138s8 eht[16][16];11391140struct {1141s8 cck[4];1142s8 ofdm[4];1143s8 ofdm_bf[4];1144s8 ru[7][10];1145s8 ru_bf[7][10];1146} path;1147};11481149struct mt76_ethtool_worker_info {1150u64 *data;1151int idx;1152int initial_stat_idx;1153int worker_stat_count;1154int sta_count;1155};11561157struct mt76_chanctx {1158struct mt76_phy *phy;1159};11601161#define CCK_RATE(_idx, _rate) { \1162.bitrate = _rate, \1163.flags = IEEE80211_RATE_SHORT_PREAMBLE, \1164.hw_value = (MT_PHY_TYPE_CCK << 8) | (_idx), \1165.hw_value_short = (MT_PHY_TYPE_CCK << 8) | (4 + _idx), \1166}11671168#define OFDM_RATE(_idx, _rate) { \1169.bitrate = _rate, \1170.hw_value = (MT_PHY_TYPE_OFDM << 8) | (_idx), \1171.hw_value_short = (MT_PHY_TYPE_OFDM << 8) | (_idx), \1172}11731174extern struct ieee80211_rate mt76_rates[12];11751176#define __mt76_rr(dev, ...) (dev)->bus->rr((dev), __VA_ARGS__)1177#define __mt76_wr(dev, ...) (dev)->bus->wr((dev), __VA_ARGS__)1178#define __mt76_rmw(dev, ...) (dev)->bus->rmw((dev), __VA_ARGS__)1179#define __mt76_wr_copy(dev, ...) (dev)->bus->write_copy((dev), __VA_ARGS__)1180#define __mt76_rr_copy(dev, ...) (dev)->bus->read_copy((dev), __VA_ARGS__)11811182#define __mt76_set(dev, offset, val) __mt76_rmw(dev, offset, 0, val)1183#define __mt76_clear(dev, offset, val) __mt76_rmw(dev, offset, val, 0)11841185#define mt76_rr(dev, ...) (dev)->mt76.bus->rr(&((dev)->mt76), __VA_ARGS__)1186#define mt76_wr(dev, ...) (dev)->mt76.bus->wr(&((dev)->mt76), __VA_ARGS__)1187#define mt76_rmw(dev, ...) (dev)->mt76.bus->rmw(&((dev)->mt76), __VA_ARGS__)1188#define mt76_wr_copy(dev, ...) (dev)->mt76.bus->write_copy(&((dev)->mt76), __VA_ARGS__)1189#define mt76_rr_copy(dev, ...) (dev)->mt76.bus->read_copy(&((dev)->mt76), __VA_ARGS__)1190#define mt76_wr_rp(dev, ...) (dev)->mt76.bus->wr_rp(&((dev)->mt76), __VA_ARGS__)1191#define mt76_rd_rp(dev, ...) (dev)->mt76.bus->rd_rp(&((dev)->mt76), __VA_ARGS__)119211931194#define mt76_mcu_restart(dev, ...) (dev)->mt76.mcu_ops->mcu_restart(&((dev)->mt76))11951196#define mt76_set(dev, offset, val) mt76_rmw(dev, offset, 0, val)1197#define mt76_clear(dev, offset, val) mt76_rmw(dev, offset, val, 0)11981199#define mt76_get_field(_dev, _reg, _field) \1200FIELD_GET(_field, mt76_rr(dev, _reg))12011202#define mt76_rmw_field(_dev, _reg, _field, _val) \1203mt76_rmw(_dev, _reg, _field, FIELD_PREP(_field, _val))12041205#define __mt76_rmw_field(_dev, _reg, _field, _val) \1206__mt76_rmw(_dev, _reg, _field, FIELD_PREP(_field, _val))12071208#define mt76_hw(dev) (dev)->mphy.hw12091210bool __mt76_poll(struct mt76_dev *dev, u32 offset, u32 mask, u32 val,1211int timeout);12121213#define mt76_poll(dev, ...) __mt76_poll(&((dev)->mt76), __VA_ARGS__)12141215bool ____mt76_poll_msec(struct mt76_dev *dev, u32 offset, u32 mask, u32 val,1216int timeout, int kick);1217#define __mt76_poll_msec(...) ____mt76_poll_msec(__VA_ARGS__, 10)1218#define mt76_poll_msec(dev, ...) ____mt76_poll_msec(&((dev)->mt76), __VA_ARGS__, 10)1219#define mt76_poll_msec_tick(dev, ...) ____mt76_poll_msec(&((dev)->mt76), __VA_ARGS__)12201221void mt76_mmio_init(struct mt76_dev *dev, void __iomem *regs);1222void mt76_pci_disable_aspm(struct pci_dev *pdev);1223bool mt76_pci_aspm_supported(struct pci_dev *pdev);12241225static inline u16 mt76_chip(struct mt76_dev *dev)1226{1227return dev->rev >> 16;1228}12291230static inline u16 mt76_rev(struct mt76_dev *dev)1231{1232return dev->rev & 0xffff;1233}12341235void mt76_wed_release_rx_buf(struct mtk_wed_device *wed);1236void mt76_wed_offload_disable(struct mtk_wed_device *wed);1237void mt76_wed_reset_complete(struct mtk_wed_device *wed);1238void mt76_wed_dma_reset(struct mt76_dev *dev);1239int mt76_wed_net_setup_tc(struct ieee80211_hw *hw, struct ieee80211_vif *vif,1240struct net_device *netdev, enum tc_setup_type type,1241void *type_data);1242#ifdef CONFIG_NET_MEDIATEK_SOC_WED1243u32 mt76_wed_init_rx_buf(struct mtk_wed_device *wed, int size);1244int mt76_wed_offload_enable(struct mtk_wed_device *wed);1245int mt76_wed_dma_setup(struct mt76_dev *dev, struct mt76_queue *q, bool reset);1246#else1247static inline u32 mt76_wed_init_rx_buf(struct mtk_wed_device *wed, int size)1248{1249return 0;1250}12511252static inline int mt76_wed_offload_enable(struct mtk_wed_device *wed)1253{1254return 0;1255}12561257static inline int mt76_wed_dma_setup(struct mt76_dev *dev, struct mt76_queue *q,1258bool reset)1259{1260return 0;1261}1262#endif /* CONFIG_NET_MEDIATEK_SOC_WED */12631264#define mt76xx_chip(dev) mt76_chip(&((dev)->mt76))1265#define mt76xx_rev(dev) mt76_rev(&((dev)->mt76))12661267#define mt76_init_queues(dev, ...) (dev)->mt76.queue_ops->init(&((dev)->mt76), __VA_ARGS__)1268#define mt76_queue_alloc(dev, ...) (dev)->mt76.queue_ops->alloc(&((dev)->mt76), __VA_ARGS__)1269#define mt76_tx_queue_skb_raw(dev, ...) (dev)->mt76.queue_ops->tx_queue_skb_raw(&((dev)->mt76), __VA_ARGS__)1270#define mt76_tx_queue_skb(dev, ...) (dev)->mt76.queue_ops->tx_queue_skb(&((dev)->mphy), __VA_ARGS__)1271#define mt76_queue_rx_reset(dev, ...) (dev)->mt76.queue_ops->rx_reset(&((dev)->mt76), __VA_ARGS__)1272#define mt76_queue_tx_cleanup(dev, ...) (dev)->mt76.queue_ops->tx_cleanup(&((dev)->mt76), __VA_ARGS__)1273#define mt76_queue_rx_init(dev, ...) (dev)->mt76.queue_ops->rx_queue_init(&((dev)->mt76), __VA_ARGS__)1274#define mt76_queue_rx_cleanup(dev, ...) (dev)->mt76.queue_ops->rx_cleanup(&((dev)->mt76), __VA_ARGS__)1275#define mt76_queue_kick(dev, ...) (dev)->mt76.queue_ops->kick(&((dev)->mt76), __VA_ARGS__)1276#define mt76_queue_reset(dev, ...) (dev)->mt76.queue_ops->reset_q(&((dev)->mt76), __VA_ARGS__)12771278#define mt76_for_each_q_rx(dev, i) \1279for (i = 0; i < ARRAY_SIZE((dev)->q_rx); i++) \1280if ((dev)->q_rx[i].ndesc)128112821283#define mt76_dereference(p, dev) \1284rcu_dereference_protected(p, lockdep_is_held(&(dev)->mutex))12851286static inline struct mt76_dev *mt76_wed_to_dev(struct mtk_wed_device *wed)1287{1288#ifdef CONFIG_NET_MEDIATEK_SOC_WED1289if (wed->wlan.hif2)1290return container_of(wed, struct mt76_dev, mmio.wed_hif2);1291#endif /* CONFIG_NET_MEDIATEK_SOC_WED */1292return container_of(wed, struct mt76_dev, mmio.wed);1293}12941295static inline struct mt76_wcid *1296__mt76_wcid_ptr(struct mt76_dev *dev, u16 idx)1297{1298if (idx >= ARRAY_SIZE(dev->wcid))1299return NULL;1300return rcu_dereference(dev->wcid[idx]);1301}13021303#define mt76_wcid_ptr(dev, idx) __mt76_wcid_ptr(&(dev)->mt76, idx)13041305struct mt76_dev *mt76_alloc_device(struct device *pdev, unsigned int size,1306const struct ieee80211_ops *ops,1307const struct mt76_driver_ops *drv_ops);1308int mt76_register_device(struct mt76_dev *dev, bool vht,1309struct ieee80211_rate *rates, int n_rates);1310void mt76_unregister_device(struct mt76_dev *dev);1311void mt76_free_device(struct mt76_dev *dev);1312void mt76_reset_device(struct mt76_dev *dev);1313void mt76_unregister_phy(struct mt76_phy *phy);13141315struct mt76_phy *mt76_alloc_radio_phy(struct mt76_dev *dev, unsigned int size,1316u8 band_idx);1317struct mt76_phy *mt76_alloc_phy(struct mt76_dev *dev, unsigned int size,1318const struct ieee80211_ops *ops,1319u8 band_idx);1320int mt76_register_phy(struct mt76_phy *phy, bool vht,1321struct ieee80211_rate *rates, int n_rates);1322struct mt76_phy *mt76_vif_phy(struct ieee80211_hw *hw,1323struct ieee80211_vif *vif);13241325struct dentry *mt76_register_debugfs_fops(struct mt76_phy *phy,1326const struct file_operations *ops);1327static inline struct dentry *mt76_register_debugfs(struct mt76_dev *dev)1328{1329return mt76_register_debugfs_fops(&dev->phy, NULL);1330}13311332int mt76_queues_read(struct seq_file *s, void *data);1333void mt76_seq_puts_array(struct seq_file *file, const char *str,1334s8 *val, int len);13351336int mt76_eeprom_init(struct mt76_dev *dev, int len);1337int mt76_eeprom_override(struct mt76_phy *phy);1338int mt76_get_of_data_from_mtd(struct mt76_dev *dev, void *eep, int offset, int len);1339int mt76_get_of_data_from_nvmem(struct mt76_dev *dev, void *eep,1340const char *cell_name, int len);13411342struct mt76_queue *1343mt76_init_queue(struct mt76_dev *dev, int qid, int idx, int n_desc,1344int ring_base, void *wed, u32 flags);1345static inline int mt76_init_tx_queue(struct mt76_phy *phy, int qid, int idx,1346int n_desc, int ring_base, void *wed,1347u32 flags)1348{1349struct mt76_queue *q;13501351q = mt76_init_queue(phy->dev, qid, idx, n_desc, ring_base, wed, flags);1352if (IS_ERR(q))1353return PTR_ERR(q);13541355phy->q_tx[qid] = q;13561357return 0;1358}13591360static inline int mt76_init_mcu_queue(struct mt76_dev *dev, int qid, int idx,1361int n_desc, int ring_base)1362{1363struct mt76_queue *q;13641365q = mt76_init_queue(dev, qid, idx, n_desc, ring_base, NULL, 0);1366if (IS_ERR(q))1367return PTR_ERR(q);13681369dev->q_mcu[qid] = q;13701371return 0;1372}13731374static inline struct mt76_phy *1375mt76_dev_phy(struct mt76_dev *dev, u8 phy_idx)1376{1377if ((phy_idx == MT_BAND1 && dev->phys[phy_idx]) ||1378(phy_idx == MT_BAND2 && dev->phys[phy_idx]))1379return dev->phys[phy_idx];13801381return &dev->phy;1382}13831384static inline struct ieee80211_hw *1385mt76_phy_hw(struct mt76_dev *dev, u8 phy_idx)1386{1387return mt76_dev_phy(dev, phy_idx)->hw;1388}13891390static inline u8 *1391mt76_get_txwi_ptr(struct mt76_dev *dev, struct mt76_txwi_cache *t)1392{1393return (u8 *)t - dev->drv->txwi_size;1394}13951396/* increment with wrap-around */1397static inline int mt76_incr(int val, int size)1398{1399return (val + 1) & (size - 1);1400}14011402/* decrement with wrap-around */1403static inline int mt76_decr(int val, int size)1404{1405return (val - 1) & (size - 1);1406}14071408u8 mt76_ac_to_hwq(u8 ac);14091410static inline struct ieee80211_txq *1411mtxq_to_txq(struct mt76_txq *mtxq)1412{1413void *ptr = mtxq;14141415return container_of(ptr, struct ieee80211_txq, drv_priv);1416}14171418static inline struct ieee80211_sta *1419wcid_to_sta(struct mt76_wcid *wcid)1420{1421void *ptr = wcid;14221423if (!wcid || !wcid->sta)1424return NULL;14251426if (wcid->def_wcid)1427ptr = wcid->def_wcid;14281429return container_of(ptr, struct ieee80211_sta, drv_priv);1430}14311432static inline struct mt76_tx_cb *mt76_tx_skb_cb(struct sk_buff *skb)1433{1434BUILD_BUG_ON(sizeof(struct mt76_tx_cb) >1435sizeof(IEEE80211_SKB_CB(skb)->status.status_driver_data));1436return ((void *)IEEE80211_SKB_CB(skb)->status.status_driver_data);1437}14381439static inline void *mt76_skb_get_hdr(struct sk_buff *skb)1440{1441struct mt76_rx_status mstat;1442u8 *data = skb->data;14431444/* Alignment concerns */1445BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he) % 4);1446BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he_mu) % 4);14471448mstat = *((struct mt76_rx_status *)skb->cb);14491450if (mstat.flag & RX_FLAG_RADIOTAP_HE)1451data += sizeof(struct ieee80211_radiotap_he);1452if (mstat.flag & RX_FLAG_RADIOTAP_HE_MU)1453data += sizeof(struct ieee80211_radiotap_he_mu);14541455return data;1456}14571458static inline void mt76_insert_hdr_pad(struct sk_buff *skb)1459{1460int len = ieee80211_get_hdrlen_from_skb(skb);14611462if (len % 4 == 0)1463return;14641465skb_push(skb, 2);1466memmove(skb->data, skb->data + 2, len);14671468skb->data[len] = 0;1469skb->data[len + 1] = 0;1470}14711472static inline bool mt76_is_skb_pktid(u8 pktid)1473{1474if (pktid & MT_PACKET_ID_HAS_RATE)1475return false;14761477return pktid >= MT_PACKET_ID_FIRST;1478}14791480static inline u8 mt76_tx_power_path_delta(u8 path)1481{1482static const u8 path_delta[5] = { 0, 6, 9, 12, 14 };1483u8 idx = path - 1;14841485return (idx < ARRAY_SIZE(path_delta)) ? path_delta[idx] : 0;1486}14871488static inline bool mt76_testmode_enabled(struct mt76_phy *phy)1489{1490#ifdef CONFIG_NL80211_TESTMODE1491return phy->test.state != MT76_TM_STATE_OFF;1492#else1493return false;1494#endif1495}14961497static inline bool mt76_is_testmode_skb(struct mt76_dev *dev,1498struct sk_buff *skb,1499struct ieee80211_hw **hw)1500{1501#ifdef CONFIG_NL80211_TESTMODE1502int i;15031504for (i = 0; i < ARRAY_SIZE(dev->phys); i++) {1505struct mt76_phy *phy = dev->phys[i];15061507if (phy && skb == phy->test.tx_skb) {1508*hw = dev->phys[i]->hw;1509return true;1510}1511}1512return false;1513#else1514return false;1515#endif1516}15171518void mt76_rx(struct mt76_dev *dev, enum mt76_rxq_id q, struct sk_buff *skb);1519void mt76_tx(struct mt76_phy *dev, struct ieee80211_sta *sta,1520struct mt76_wcid *wcid, struct sk_buff *skb);1521void mt76_wake_tx_queue(struct ieee80211_hw *hw, struct ieee80211_txq *txq);1522void mt76_stop_tx_queues(struct mt76_phy *phy, struct ieee80211_sta *sta,1523bool send_bar);1524void mt76_tx_check_agg_ssn(struct ieee80211_sta *sta, struct sk_buff *skb);1525void mt76_txq_schedule(struct mt76_phy *phy, enum mt76_txq_id qid);1526void mt76_txq_schedule_all(struct mt76_phy *phy);1527void mt76_tx_worker_run(struct mt76_dev *dev);1528void mt76_tx_worker(struct mt76_worker *w);1529void mt76_release_buffered_frames(struct ieee80211_hw *hw,1530struct ieee80211_sta *sta,1531u16 tids, int nframes,1532enum ieee80211_frame_release_type reason,1533bool more_data);1534bool mt76_has_tx_pending(struct mt76_phy *phy);1535int mt76_update_channel(struct mt76_phy *phy);1536void mt76_update_survey(struct mt76_phy *phy);1537void mt76_update_survey_active_time(struct mt76_phy *phy, ktime_t time);1538int mt76_get_survey(struct ieee80211_hw *hw, int idx,1539struct survey_info *survey);1540int mt76_rx_signal(u8 chain_mask, s8 *chain_signal);1541void mt76_set_stream_caps(struct mt76_phy *phy, bool vht);15421543int mt76_rx_aggr_start(struct mt76_dev *dev, struct mt76_wcid *wcid, u8 tid,1544u16 ssn, u16 size);1545void mt76_rx_aggr_stop(struct mt76_dev *dev, struct mt76_wcid *wcid, u8 tid);15461547void mt76_wcid_key_setup(struct mt76_dev *dev, struct mt76_wcid *wcid,1548struct ieee80211_key_conf *key);15491550void mt76_tx_status_lock(struct mt76_dev *dev, struct sk_buff_head *list)1551__acquires(&dev->status_lock);1552void mt76_tx_status_unlock(struct mt76_dev *dev, struct sk_buff_head *list)1553__releases(&dev->status_lock);15541555int mt76_tx_status_skb_add(struct mt76_dev *dev, struct mt76_wcid *wcid,1556struct sk_buff *skb);1557struct sk_buff *mt76_tx_status_skb_get(struct mt76_dev *dev,1558struct mt76_wcid *wcid, int pktid,1559struct sk_buff_head *list);1560void mt76_tx_status_skb_done(struct mt76_dev *dev, struct sk_buff *skb,1561struct sk_buff_head *list);1562void __mt76_tx_complete_skb(struct mt76_dev *dev, u16 wcid, struct sk_buff *skb,1563struct list_head *free_list);1564static inline void1565mt76_tx_complete_skb(struct mt76_dev *dev, u16 wcid, struct sk_buff *skb)1566{1567__mt76_tx_complete_skb(dev, wcid, skb, NULL);1568}15691570void mt76_tx_status_check(struct mt76_dev *dev, bool flush);1571int mt76_sta_state(struct ieee80211_hw *hw, struct ieee80211_vif *vif,1572struct ieee80211_sta *sta,1573enum ieee80211_sta_state old_state,1574enum ieee80211_sta_state new_state);1575void __mt76_sta_remove(struct mt76_phy *phy, struct ieee80211_vif *vif,1576struct ieee80211_sta *sta);1577void mt76_sta_pre_rcu_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,1578struct ieee80211_sta *sta);15791580int mt76_get_min_avg_rssi(struct mt76_dev *dev, u8 phy_idx);15811582s8 mt76_get_power_bound(struct mt76_phy *phy, s8 txpower);15831584int mt76_get_txpower(struct ieee80211_hw *hw, struct ieee80211_vif *vif,1585unsigned int link_id, int *dbm);1586int mt76_init_sar_power(struct ieee80211_hw *hw,1587const struct cfg80211_sar_specs *sar);1588int mt76_get_sar_power(struct mt76_phy *phy,1589struct ieee80211_channel *chan,1590int power);15911592void mt76_csa_check(struct mt76_dev *dev);1593void mt76_csa_finish(struct mt76_dev *dev);15941595int mt76_get_antenna(struct ieee80211_hw *hw, int radio_idx, u32 *tx_ant,1596u32 *rx_ant);1597int mt76_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set);1598void mt76_insert_ccmp_hdr(struct sk_buff *skb, u8 key_id);1599int mt76_get_rate(struct mt76_dev *dev,1600struct ieee80211_supported_band *sband,1601int idx, bool cck);1602int mt76_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,1603struct ieee80211_scan_request *hw_req);1604void mt76_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif);1605void mt76_sw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,1606const u8 *mac);1607void mt76_sw_scan_complete(struct ieee80211_hw *hw,1608struct ieee80211_vif *vif);1609enum mt76_dfs_state mt76_phy_dfs_state(struct mt76_phy *phy);1610int mt76_add_chanctx(struct ieee80211_hw *hw,1611struct ieee80211_chanctx_conf *conf);1612void mt76_remove_chanctx(struct ieee80211_hw *hw,1613struct ieee80211_chanctx_conf *conf);1614void mt76_change_chanctx(struct ieee80211_hw *hw,1615struct ieee80211_chanctx_conf *conf,1616u32 changed);1617int mt76_assign_vif_chanctx(struct ieee80211_hw *hw,1618struct ieee80211_vif *vif,1619struct ieee80211_bss_conf *link_conf,1620struct ieee80211_chanctx_conf *conf);1621void mt76_unassign_vif_chanctx(struct ieee80211_hw *hw,1622struct ieee80211_vif *vif,1623struct ieee80211_bss_conf *link_conf,1624struct ieee80211_chanctx_conf *conf);1625int mt76_switch_vif_chanctx(struct ieee80211_hw *hw,1626struct ieee80211_vif_chanctx_switch *vifs,1627int n_vifs,1628enum ieee80211_chanctx_switch_mode mode);1629int mt76_remain_on_channel(struct ieee80211_hw *hw, struct ieee80211_vif *vif,1630struct ieee80211_channel *chan, int duration,1631enum ieee80211_roc_type type);1632int mt76_cancel_remain_on_channel(struct ieee80211_hw *hw,1633struct ieee80211_vif *vif);1634int mt76_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,1635void *data, int len);1636int mt76_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *skb,1637struct netlink_callback *cb, void *data, int len);1638int mt76_testmode_set_state(struct mt76_phy *phy, enum mt76_testmode_state state);1639int mt76_testmode_alloc_skb(struct mt76_phy *phy, u32 len);16401641#ifdef CONFIG_MT76_NPU1642void mt76_npu_check_ppe(struct mt76_dev *dev, struct sk_buff *skb,1643u32 info);1644int mt76_npu_dma_add_buf(struct mt76_phy *phy, struct mt76_queue *q,1645struct sk_buff *skb, struct mt76_queue_buf *buf,1646void *txwi_ptr);1647int mt76_npu_rx_queue_init(struct mt76_dev *dev, struct mt76_queue *q);1648int mt76_npu_fill_rx_queue(struct mt76_dev *dev, struct mt76_queue *q);1649void mt76_npu_queue_cleanup(struct mt76_dev *dev, struct mt76_queue *q);1650void mt76_npu_disable_irqs(struct mt76_dev *dev);1651int mt76_npu_init(struct mt76_dev *dev, phys_addr_t phy_addr, int type);1652void mt76_npu_deinit(struct mt76_dev *dev);1653void mt76_npu_queue_setup(struct mt76_dev *dev, struct mt76_queue *q);1654void mt76_npu_txdesc_cleanup(struct mt76_queue *q, int index);1655int mt76_npu_net_setup_tc(struct ieee80211_hw *hw, struct ieee80211_vif *vif,1656struct net_device *dev, enum tc_setup_type type,1657void *type_data);1658#else1659static inline void mt76_npu_check_ppe(struct mt76_dev *dev,1660struct sk_buff *skb, u32 info)1661{1662}16631664static inline int mt76_npu_dma_add_buf(struct mt76_phy *phy,1665struct mt76_queue *q,1666struct sk_buff *skb,1667struct mt76_queue_buf *buf,1668void *txwi_ptr)1669{1670return -EOPNOTSUPP;1671}16721673static inline int mt76_npu_fill_rx_queue(struct mt76_dev *dev,1674struct mt76_queue *q)1675{1676return 0;1677}16781679static inline void mt76_npu_queue_cleanup(struct mt76_dev *dev,1680struct mt76_queue *q)1681{1682}16831684static inline void mt76_npu_disable_irqs(struct mt76_dev *dev)1685{1686}16871688static inline int mt76_npu_init(struct mt76_dev *dev, phys_addr_t phy_addr,1689int type)1690{1691return 0;1692}16931694static inline void mt76_npu_deinit(struct mt76_dev *dev)1695{1696}16971698static inline void mt76_npu_queue_setup(struct mt76_dev *dev,1699struct mt76_queue *q)1700{1701}17021703static inline void mt76_npu_txdesc_cleanup(struct mt76_queue *q,1704int index)1705{1706}17071708static inline int mt76_npu_net_setup_tc(struct ieee80211_hw *hw,1709struct ieee80211_vif *vif,1710struct net_device *dev,1711enum tc_setup_type type,1712void *type_data)1713{1714return -EOPNOTSUPP;1715}1716#endif /* CONFIG_MT76_NPU */17171718static inline bool mt76_npu_device_active(struct mt76_dev *dev)1719{1720return !!rcu_access_pointer(dev->mmio.npu);1721}17221723static inline bool mt76_ppe_device_active(struct mt76_dev *dev)1724{1725return !!rcu_access_pointer(dev->mmio.ppe_dev);1726}17271728static inline int mt76_npu_send_msg(struct airoha_npu *npu, int ifindex,1729enum airoha_npu_wlan_set_cmd cmd,1730u32 val, gfp_t gfp)1731{1732return airoha_npu_wlan_send_msg(npu, ifindex, cmd, &val, sizeof(val),1733gfp);1734}17351736static inline int mt76_npu_get_msg(struct airoha_npu *npu, int ifindex,1737enum airoha_npu_wlan_get_cmd cmd,1738u32 *val, gfp_t gfp)1739{1740return airoha_npu_wlan_get_msg(npu, ifindex, cmd, val, sizeof(*val),1741gfp);1742}17431744static inline void mt76_testmode_reset(struct mt76_phy *phy, bool disable)1745{1746#ifdef CONFIG_NL80211_TESTMODE1747enum mt76_testmode_state state = MT76_TM_STATE_IDLE;17481749if (disable || phy->test.state == MT76_TM_STATE_OFF)1750state = MT76_TM_STATE_OFF;17511752mt76_testmode_set_state(phy, state);1753#endif1754}175517561757/* internal */1758static inline struct ieee80211_hw *1759mt76_tx_status_get_hw(struct mt76_dev *dev, struct sk_buff *skb)1760{1761struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);1762u8 phy_idx = (info->hw_queue & MT_TX_HW_QUEUE_PHY) >> 2;1763struct ieee80211_hw *hw = mt76_phy_hw(dev, phy_idx);17641765info->hw_queue &= ~MT_TX_HW_QUEUE_PHY;17661767return hw;1768}17691770void mt76_put_txwi(struct mt76_dev *dev, struct mt76_txwi_cache *t);1771void mt76_put_rxwi(struct mt76_dev *dev, struct mt76_txwi_cache *t);1772struct mt76_txwi_cache *mt76_get_rxwi(struct mt76_dev *dev);1773void mt76_free_pending_rxwi(struct mt76_dev *dev);1774void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames,1775struct napi_struct *napi);1776void mt76_rx_poll_complete(struct mt76_dev *dev, enum mt76_rxq_id q,1777struct napi_struct *napi);1778void mt76_rx_aggr_reorder(struct sk_buff *skb, struct sk_buff_head *frames);1779void mt76_testmode_tx_pending(struct mt76_phy *phy);1780void mt76_queue_tx_complete(struct mt76_dev *dev, struct mt76_queue *q,1781struct mt76_queue_entry *e);1782int __mt76_set_channel(struct mt76_phy *phy, struct cfg80211_chan_def *chandef,1783bool offchannel);1784int mt76_set_channel(struct mt76_phy *phy, struct cfg80211_chan_def *chandef,1785bool offchannel);1786void mt76_scan_work(struct work_struct *work);1787void mt76_abort_scan(struct mt76_dev *dev);1788void mt76_roc_complete_work(struct work_struct *work);1789void mt76_roc_complete(struct mt76_phy *phy);1790void mt76_abort_roc(struct mt76_phy *phy);1791struct mt76_vif_link *mt76_get_vif_phy_link(struct mt76_phy *phy,1792struct ieee80211_vif *vif);1793void mt76_put_vif_phy_link(struct mt76_phy *phy, struct ieee80211_vif *vif,1794struct mt76_vif_link *mlink);17951796/* usb */1797static inline bool mt76u_urb_error(struct urb *urb)1798{1799return urb->status &&1800urb->status != -ECONNRESET &&1801urb->status != -ESHUTDOWN &&1802urb->status != -ENOENT;1803}18041805static inline int1806mt76u_bulk_msg(struct mt76_dev *dev, void *data, int len, int *actual_len,1807int timeout, int ep)1808{1809#if defined(__FreeBSD__) && !defined(CONFIG_USB)1810return (0);1811#else1812struct usb_interface *uintf = to_usb_interface(dev->dev);1813struct usb_device *udev = interface_to_usbdev(uintf);1814struct mt76_usb *usb = &dev->usb;1815unsigned int pipe;18161817if (actual_len)1818pipe = usb_rcvbulkpipe(udev, usb->in_ep[ep]);1819else1820pipe = usb_sndbulkpipe(udev, usb->out_ep[ep]);18211822return usb_bulk_msg(udev, pipe, data, len, actual_len, timeout);1823#endif1824}18251826void mt76_ethtool_page_pool_stats(struct mt76_dev *dev, u64 *data, int *index);1827void mt76_ethtool_worker(struct mt76_ethtool_worker_info *wi,1828struct mt76_sta_stats *stats, bool eht);1829int mt76_skb_adjust_pad(struct sk_buff *skb, int pad);1830int __mt76u_vendor_request(struct mt76_dev *dev, u8 req, u8 req_type,1831u16 val, u16 offset, void *buf, size_t len);1832int mt76u_vendor_request(struct mt76_dev *dev, u8 req,1833u8 req_type, u16 val, u16 offset,1834void *buf, size_t len);1835void mt76u_single_wr(struct mt76_dev *dev, const u8 req,1836const u16 offset, const u32 val);1837void mt76u_read_copy(struct mt76_dev *dev, u32 offset,1838void *data, int len);1839u32 ___mt76u_rr(struct mt76_dev *dev, u8 req, u8 req_type, u32 addr);1840void ___mt76u_wr(struct mt76_dev *dev, u8 req, u8 req_type,1841u32 addr, u32 val);1842int __mt76u_init(struct mt76_dev *dev, struct usb_interface *intf,1843struct mt76_bus_ops *ops);1844int mt76u_init(struct mt76_dev *dev, struct usb_interface *intf);1845int mt76u_alloc_mcu_queue(struct mt76_dev *dev);1846int mt76u_alloc_queues(struct mt76_dev *dev);1847void mt76u_stop_tx(struct mt76_dev *dev);1848void mt76u_stop_rx(struct mt76_dev *dev);1849int mt76u_resume_rx(struct mt76_dev *dev);1850void mt76u_queues_deinit(struct mt76_dev *dev);18511852int mt76s_init(struct mt76_dev *dev, struct sdio_func *func,1853const struct mt76_bus_ops *bus_ops);1854int mt76s_alloc_rx_queue(struct mt76_dev *dev, enum mt76_rxq_id qid);1855int mt76s_alloc_tx(struct mt76_dev *dev);1856void mt76s_deinit(struct mt76_dev *dev);1857void mt76s_sdio_irq(struct sdio_func *func);1858void mt76s_txrx_worker(struct mt76_sdio *sdio);1859bool mt76s_txqs_empty(struct mt76_dev *dev);1860int mt76s_hw_init(struct mt76_dev *dev, struct sdio_func *func,1861int hw_ver);1862u32 mt76s_rr(struct mt76_dev *dev, u32 offset);1863void mt76s_wr(struct mt76_dev *dev, u32 offset, u32 val);1864u32 mt76s_rmw(struct mt76_dev *dev, u32 offset, u32 mask, u32 val);1865u32 mt76s_read_pcr(struct mt76_dev *dev);1866void mt76s_write_copy(struct mt76_dev *dev, u32 offset,1867const void *data, int len);1868void mt76s_read_copy(struct mt76_dev *dev, u32 offset,1869void *data, int len);1870int mt76s_wr_rp(struct mt76_dev *dev, u32 base,1871const struct mt76_reg_pair *data,1872int len);1873int mt76s_rd_rp(struct mt76_dev *dev, u32 base,1874struct mt76_reg_pair *data, int len);18751876struct sk_buff *1877__mt76_mcu_msg_alloc(struct mt76_dev *dev, const void *data,1878int len, int data_len, gfp_t gfp);1879static inline struct sk_buff *1880mt76_mcu_msg_alloc(struct mt76_dev *dev, const void *data,1881int data_len)1882{1883return __mt76_mcu_msg_alloc(dev, data, data_len, data_len, GFP_KERNEL);1884}18851886void mt76_mcu_rx_event(struct mt76_dev *dev, struct sk_buff *skb);1887struct sk_buff *mt76_mcu_get_response(struct mt76_dev *dev,1888unsigned long expires);1889int mt76_mcu_send_and_get_msg(struct mt76_dev *dev, int cmd, const void *data,1890int len, bool wait_resp, struct sk_buff **ret);1891int mt76_mcu_skb_send_and_get_msg(struct mt76_dev *dev, struct sk_buff *skb,1892int cmd, bool wait_resp, struct sk_buff **ret);1893#if defined(__linux__)1894int __mt76_mcu_send_firmware(struct mt76_dev *dev, int cmd, const void *data,1895#elif defined(__FreeBSD__)1896int __mt76_mcu_send_firmware(struct mt76_dev *dev, int cmd, const u8 *data,1897#endif1898int len, int max_len);1899static inline int1900mt76_mcu_send_firmware(struct mt76_dev *dev, int cmd, const void *data,1901int len)1902{1903int max_len = 4096 - dev->mcu_ops->headroom;19041905return __mt76_mcu_send_firmware(dev, cmd, data, len, max_len);1906}19071908static inline int1909mt76_mcu_send_msg(struct mt76_dev *dev, int cmd, const void *data, int len,1910bool wait_resp)1911{1912return mt76_mcu_send_and_get_msg(dev, cmd, data, len, wait_resp, NULL);1913}19141915static inline int1916mt76_mcu_skb_send_msg(struct mt76_dev *dev, struct sk_buff *skb, int cmd,1917bool wait_resp)1918{1919return mt76_mcu_skb_send_and_get_msg(dev, skb, cmd, wait_resp, NULL);1920}19211922void mt76_set_irq_mask(struct mt76_dev *dev, u32 addr, u32 clear, u32 set);19231924struct device_node *1925mt76_find_power_limits_node(struct mt76_dev *dev);1926struct device_node *1927mt76_find_channel_node(struct device_node *np, struct ieee80211_channel *chan);19281929s8 mt76_get_rate_power_limits(struct mt76_phy *phy,1930struct ieee80211_channel *chan,1931struct mt76_power_limits *dest,1932s8 target_power);19331934static inline bool mt76_queue_is_rx(struct mt76_dev *dev, struct mt76_queue *q)1935{1936int i;19371938for (i = 0; i < ARRAY_SIZE(dev->q_rx); i++) {1939if (q == &dev->q_rx[i])1940return true;1941}19421943return false;1944}19451946static inline bool mt76_queue_is_wed_tx_free(struct mt76_queue *q)1947{1948return (q->flags & MT_QFLAG_WED) &&1949FIELD_GET(MT_QFLAG_WED_TYPE, q->flags) == MT76_WED_Q_TXFREE;1950}19511952static inline bool mt76_queue_is_wed_rro(struct mt76_queue *q)1953{1954return q->flags & MT_QFLAG_WED_RRO;1955}19561957static inline bool mt76_queue_is_wed_rro_ind(struct mt76_queue *q)1958{1959return mt76_queue_is_wed_rro(q) &&1960FIELD_GET(MT_QFLAG_WED_TYPE, q->flags) == MT76_WED_RRO_Q_IND;1961}19621963static inline bool mt76_queue_is_wed_rro_rxdmad_c(struct mt76_queue *q)1964{1965return mt76_queue_is_wed_rro(q) &&1966FIELD_GET(MT_QFLAG_WED_TYPE, q->flags) == MT76_WED_RRO_Q_RXDMAD_C;1967}19681969static inline bool mt76_queue_is_wed_rro_data(struct mt76_queue *q)1970{1971return mt76_queue_is_wed_rro(q) &&1972FIELD_GET(MT_QFLAG_WED_TYPE, q->flags) == MT76_WED_RRO_Q_DATA;1973}19741975static inline bool mt76_queue_is_wed_rro_msdu_pg(struct mt76_queue *q)1976{1977return mt76_queue_is_wed_rro(q) &&1978FIELD_GET(MT_QFLAG_WED_TYPE, q->flags) ==1979MT76_WED_RRO_Q_MSDU_PG;1980}19811982static inline bool mt76_queue_is_wed_rx(struct mt76_queue *q)1983{1984return (q->flags & MT_QFLAG_WED) &&1985FIELD_GET(MT_QFLAG_WED_TYPE, q->flags) == MT76_WED_Q_RX;1986}19871988static inline bool mt76_queue_is_emi(struct mt76_queue *q)1989{1990return q->flags & MT_QFLAG_EMI_EN;1991}19921993static inline bool mt76_queue_is_npu(struct mt76_queue *q)1994{1995return q->flags & MT_QFLAG_NPU;1996}19971998static inline bool mt76_queue_is_npu_tx(struct mt76_queue *q)1999{2000return mt76_queue_is_npu(q) &&2001FIELD_GET(MT_QFLAG_WED_TYPE, q->flags) == MT76_WED_Q_TX;2002}20032004static inline bool mt76_queue_is_npu_rx(struct mt76_queue *q)2005{2006return mt76_queue_is_npu(q) &&2007FIELD_GET(MT_QFLAG_WED_TYPE, q->flags) == MT76_WED_Q_RX;2008}20092010struct mt76_txwi_cache *2011mt76_token_release(struct mt76_dev *dev, int token, bool *wake);2012int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi);2013void __mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked);2014struct mt76_txwi_cache *mt76_rx_token_release(struct mt76_dev *dev, int token);2015int mt76_rx_token_consume(struct mt76_dev *dev, void *ptr,2016struct mt76_txwi_cache *r, dma_addr_t phys);2017int mt76_create_page_pool(struct mt76_dev *dev, struct mt76_queue *q);2018static inline void mt76_put_page_pool_buf(void *buf, bool allow_direct)2019{2020struct page *page = virt_to_head_page(buf);20212022page_pool_put_full_page(pp_page_to_nmdesc(page)->pp, page,2023allow_direct);2024}20252026static inline void *2027mt76_get_page_pool_buf(struct mt76_queue *q, u32 *offset, u32 size)2028{2029struct page *page;20302031page = page_pool_alloc_frag(q->page_pool, offset, size,2032GFP_ATOMIC | __GFP_NOWARN | GFP_DMA32);2033if (!page)2034return NULL;20352036#if defined(__linux__)2037return page_address(page) + *offset;2038#elif defined(__FreeBSD__)2039return (void *)((uintptr_t)page_address(page) + *offset);2040#endif2041}20422043static inline void mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked)2044{2045spin_lock_bh(&dev->token_lock);2046__mt76_set_tx_blocked(dev, blocked);2047spin_unlock_bh(&dev->token_lock);2048}20492050static inline int2051mt76_token_get(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi)2052{2053int token;20542055spin_lock_bh(&dev->token_lock);2056token = idr_alloc(&dev->token, *ptxwi, 0, dev->token_size, GFP_ATOMIC);2057spin_unlock_bh(&dev->token_lock);20582059return token;2060}20612062static inline struct mt76_txwi_cache *2063mt76_token_put(struct mt76_dev *dev, int token)2064{2065struct mt76_txwi_cache *txwi;20662067spin_lock_bh(&dev->token_lock);2068txwi = idr_remove(&dev->token, token);2069spin_unlock_bh(&dev->token_lock);20702071return txwi;2072}20732074void mt76_wcid_init(struct mt76_wcid *wcid, u8 band_idx);2075void mt76_wcid_cleanup(struct mt76_dev *dev, struct mt76_wcid *wcid);2076void mt76_wcid_add_poll(struct mt76_dev *dev, struct mt76_wcid *wcid);20772078static inline void2079mt76_vif_init(struct ieee80211_vif *vif, struct mt76_vif_data *mvif)2080{2081struct mt76_vif_link *mlink = (struct mt76_vif_link *)vif->drv_priv;20822083mlink->mvif = mvif;2084rcu_assign_pointer(mvif->link[0], mlink);2085}20862087void mt76_vif_cleanup(struct mt76_dev *dev, struct ieee80211_vif *vif);2088u16 mt76_select_links(struct ieee80211_vif *vif, int max_active_links);20892090static inline struct mt76_vif_link *2091mt76_vif_link(struct mt76_dev *dev, struct ieee80211_vif *vif, int link_id)2092{2093struct mt76_vif_link *mlink = (struct mt76_vif_link *)vif->drv_priv;2094struct mt76_vif_data *mvif = mlink->mvif;20952096if (!link_id)2097return mlink;20982099return mt76_dereference(mvif->link[link_id], dev);2100}21012102static inline struct mt76_vif_link *2103mt76_vif_conf_link(struct mt76_dev *dev, struct ieee80211_vif *vif,2104struct ieee80211_bss_conf *link_conf)2105{2106struct mt76_vif_link *mlink = (struct mt76_vif_link *)vif->drv_priv;2107struct mt76_vif_data *mvif = mlink->mvif;21082109if (link_conf == &vif->bss_conf || !link_conf->link_id)2110return mlink;21112112return mt76_dereference(mvif->link[link_conf->link_id], dev);2113}21142115static inline struct mt76_phy *2116mt76_vif_link_phy(struct mt76_vif_link *mlink)2117{2118struct mt76_chanctx *ctx;21192120if (!mlink->ctx)2121return NULL;21222123ctx = (struct mt76_chanctx *)mlink->ctx->drv_priv;21242125return ctx->phy;2126}21272128#endif212921302131