Path: blob/main/sys/contrib/dev/mediatek/mt76/mt76x02_mac.h
48375 views
/* SPDX-License-Identifier: ISC */1/*2* Copyright (C) 2016 Felix Fietkau <[email protected]>3* Copyright (C) 2018 Stanislaw Gruszka <[email protected]>4*/56#ifndef __MT76X02_MAC_H7#define __MT76X02_MAC_H89struct mt76x02_dev;1011struct mt76x02_tx_status {12u8 valid:1;13u8 success:1;14u8 aggr:1;15u8 ack_req:1;16u8 wcid;17u8 pktid;18u8 retry;19u16 rate;20} __packed __aligned(2);2122#define MT_VIF_WCID(_n) (254 - ((_n) & 7))23#define MT_MAX_VIFS 82425#define MT_PKTID_RATE GENMASK(4, 0)26#define MT_PKTID_AC GENMASK(6, 5)2728struct mt76x02_vif {29struct mt76_wcid group_wcid; /* must be first */30u8 idx;31};3233DECLARE_EWMA(pktlen, 8, 8);3435struct mt76x02_sta {36struct mt76_wcid wcid; /* must be first */3738struct mt76x02_vif *vif;39struct mt76x02_tx_status status;40int n_frames;4142struct ewma_pktlen pktlen;43};4445#define MT_RXINFO_BA BIT(0)46#define MT_RXINFO_DATA BIT(1)47#define MT_RXINFO_NULL BIT(2)48#define MT_RXINFO_FRAG BIT(3)49#define MT_RXINFO_UNICAST BIT(4)50#define MT_RXINFO_MULTICAST BIT(5)51#define MT_RXINFO_BROADCAST BIT(6)52#define MT_RXINFO_MYBSS BIT(7)53#define MT_RXINFO_CRCERR BIT(8)54#define MT_RXINFO_ICVERR BIT(9)55#define MT_RXINFO_MICERR BIT(10)56#define MT_RXINFO_AMSDU BIT(11)57#define MT_RXINFO_HTC BIT(12)58#define MT_RXINFO_RSSI BIT(13)59#define MT_RXINFO_L2PAD BIT(14)60#define MT_RXINFO_AMPDU BIT(15)61#define MT_RXINFO_DECRYPT BIT(16)62#define MT_RXINFO_BSSIDX3 BIT(17)63#define MT_RXINFO_WAPI_KEY BIT(18)64#define MT_RXINFO_PN_LEN GENMASK(21, 19)65#define MT_RXINFO_SW_FTYPE0 BIT(22)66#define MT_RXINFO_SW_FTYPE1 BIT(23)67#define MT_RXINFO_PROBE_RESP BIT(24)68#define MT_RXINFO_BEACON BIT(25)69#define MT_RXINFO_DISASSOC BIT(26)70#define MT_RXINFO_DEAUTH BIT(27)71#define MT_RXINFO_ACTION BIT(28)72#define MT_RXINFO_TCP_SUM_ERR BIT(30)73#define MT_RXINFO_IP_SUM_ERR BIT(31)7475#define MT_RXWI_CTL_WCID GENMASK(7, 0)76#define MT_RXWI_CTL_KEY_IDX GENMASK(9, 8)77#define MT_RXWI_CTL_BSS_IDX GENMASK(12, 10)78#define MT_RXWI_CTL_UDF GENMASK(15, 13)79#define MT_RXWI_CTL_MPDU_LEN GENMASK(29, 16)80#define MT_RXWI_CTL_EOF BIT(31)8182#define MT_RXWI_TID GENMASK(3, 0)83#define MT_RXWI_SN GENMASK(15, 4)8485#define MT_RXWI_RATE_INDEX GENMASK(5, 0)86#define MT_RXWI_RATE_LDPC BIT(6)87#define MT_RXWI_RATE_BW GENMASK(8, 7)88#define MT_RXWI_RATE_SGI BIT(9)89#define MT_RXWI_RATE_STBC BIT(10)90#define MT_RXWI_RATE_LDPC_EXSYM BIT(11)91#define MT_RXWI_RATE_PHY GENMASK(15, 13)9293#define MT_RATE_INDEX_VHT_IDX GENMASK(3, 0)94#define MT_RATE_INDEX_VHT_NSS GENMASK(5, 4)9596struct mt76x02_rxwi {97__le32 rxinfo;9899__le32 ctl;100101__le16 tid_sn;102__le16 rate;103104u8 rssi[4];105106__le32 bbp_rxinfo[4];107};108109#define MT_TX_PWR_ADJ GENMASK(3, 0)110111enum mt76x2_phy_bandwidth {112MT_PHY_BW_20,113MT_PHY_BW_40,114MT_PHY_BW_80,115};116117#define MT_TXWI_FLAGS_FRAG BIT(0)118#define MT_TXWI_FLAGS_MMPS BIT(1)119#define MT_TXWI_FLAGS_CFACK BIT(2)120#define MT_TXWI_FLAGS_TS BIT(3)121#define MT_TXWI_FLAGS_AMPDU BIT(4)122#define MT_TXWI_FLAGS_MPDU_DENSITY GENMASK(7, 5)123#define MT_TXWI_FLAGS_TXOP GENMASK(9, 8)124#define MT_TXWI_FLAGS_NDPS BIT(10)125#define MT_TXWI_FLAGS_RTSBWSIG BIT(11)126#define MT_TXWI_FLAGS_NDP_BW GENMASK(13, 12)127#define MT_TXWI_FLAGS_SOUND BIT(14)128#define MT_TXWI_FLAGS_TX_RATE_LUT BIT(15)129130#define MT_TXWI_ACK_CTL_REQ BIT(0)131#define MT_TXWI_ACK_CTL_NSEQ BIT(1)132#define MT_TXWI_ACK_CTL_BA_WINDOW GENMASK(7, 2)133134struct mt76x02_txwi {135__le16 flags;136__le16 rate;137u8 ack_ctl;138u8 wcid;139__le16 len_ctl;140__le32 iv;141__le32 eiv;142u8 aid;143u8 txstream;144u8 ctl2;145u8 pktid;146} __packed __aligned(4);147148static inline bool mt76x02_wait_for_mac(struct mt76_dev *dev)149{150const u32 MAC_CSR0 = 0x1000;151int i;152153for (i = 0; i < 500; i++) {154if (test_bit(MT76_REMOVED, &dev->phy.state))155return false;156157switch (dev->bus->rr(dev, MAC_CSR0)) {158case 0:159case ~0:160break;161default:162return true;163}164usleep_range(5000, 10000);165}166return false;167}168169void mt76x02_mac_reset_counters(struct mt76x02_dev *dev);170void mt76x02_mac_set_short_preamble(struct mt76x02_dev *dev, bool enable);171int mt76x02_mac_shared_key_setup(struct mt76x02_dev *dev, u8 vif_idx,172u8 key_idx, struct ieee80211_key_conf *key);173int mt76x02_mac_wcid_set_key(struct mt76x02_dev *dev, u8 idx,174struct ieee80211_key_conf *key);175void mt76x02_mac_wcid_sync_pn(struct mt76x02_dev *dev, u8 idx,176struct ieee80211_key_conf *key);177void mt76x02_mac_wcid_setup(struct mt76x02_dev *dev, u8 idx, u8 vif_idx,178u8 *mac);179void mt76x02_mac_wcid_set_drop(struct mt76x02_dev *dev, u8 idx, bool drop);180void mt76x02_mac_wcid_set_rate(struct mt76x02_dev *dev, struct mt76_wcid *wcid,181const struct ieee80211_tx_rate *rate);182bool mt76x02_mac_load_tx_status(struct mt76x02_dev *dev,183struct mt76x02_tx_status *stat);184void mt76x02_send_tx_status(struct mt76x02_dev *dev,185struct mt76x02_tx_status *stat, u8 *update);186int mt76x02_mac_process_rx(struct mt76x02_dev *dev, struct sk_buff *skb,187void *rxi);188void mt76x02_mac_set_tx_protection(struct mt76x02_dev *dev, bool legacy_prot,189int ht_mode);190void mt76x02_mac_set_rts_thresh(struct mt76x02_dev *dev, u32 val);191void mt76x02_mac_setaddr(struct mt76x02_dev *dev, const u8 *addr);192void mt76x02_mac_write_txwi(struct mt76x02_dev *dev, struct mt76x02_txwi *txwi,193struct sk_buff *skb, struct mt76_wcid *wcid,194struct ieee80211_sta *sta, int len);195void mt76x02_mac_poll_tx_status(struct mt76x02_dev *dev, bool irq);196void mt76x02_tx_complete_skb(struct mt76_dev *mdev, struct mt76_queue_entry *e);197void mt76x02_update_channel(struct mt76_phy *mphy);198void mt76x02_mac_work(struct work_struct *work);199200void mt76x02_mac_cc_reset(struct mt76x02_dev *dev);201void mt76x02_mac_set_bssid(struct mt76x02_dev *dev, u8 idx, const u8 *addr);202void mt76x02_mac_set_beacon(struct mt76x02_dev *dev, struct sk_buff *skb);203void mt76x02_mac_set_beacon_enable(struct mt76x02_dev *dev,204struct ieee80211_vif *vif, bool enable);205206void mt76x02_edcca_init(struct mt76x02_dev *dev);207#endif208209210