1*1802d0beSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2c869f77dSJakub Kicinski /* 3c869f77dSJakub Kicinski * Copyright (C) 2014 Felix Fietkau <nbd@openwrt.org> 4c869f77dSJakub Kicinski * Copyright (C) 2015 Jakub Kicinski <kubakici@wp.pl> 5c869f77dSJakub Kicinski */ 6c869f77dSJakub Kicinski 7c869f77dSJakub Kicinski #ifndef __MT76_MAC_H 8c869f77dSJakub Kicinski #define __MT76_MAC_H 9c869f77dSJakub Kicinski 10c869f77dSJakub Kicinski struct mt76_tx_status { 11c869f77dSJakub Kicinski u8 valid:1; 12c869f77dSJakub Kicinski u8 success:1; 13c869f77dSJakub Kicinski u8 aggr:1; 14c869f77dSJakub Kicinski u8 ack_req:1; 15c869f77dSJakub Kicinski u8 is_probe:1; 16c869f77dSJakub Kicinski u8 wcid; 17c869f77dSJakub Kicinski u8 pktid; 18c869f77dSJakub Kicinski u8 retry; 19c869f77dSJakub Kicinski u16 rate; 20c869f77dSJakub Kicinski } __packed __aligned(2); 21c869f77dSJakub Kicinski 22c869f77dSJakub Kicinski /* Note: values in original "RSSI" and "SNR" fields are not actually what they 23c869f77dSJakub Kicinski * are called for MT7601U, names used by this driver are educated guesses 24c869f77dSJakub Kicinski * (see vendor mac/ral_omac.c). 25c869f77dSJakub Kicinski */ 26c869f77dSJakub Kicinski struct mt7601u_rxwi { 27c869f77dSJakub Kicinski __le32 rxinfo; 28c869f77dSJakub Kicinski 29c869f77dSJakub Kicinski __le32 ctl; 30c869f77dSJakub Kicinski 31c869f77dSJakub Kicinski __le16 frag_sn; 32c869f77dSJakub Kicinski __le16 rate; 33c869f77dSJakub Kicinski 34c869f77dSJakub Kicinski u8 unknown; 35c869f77dSJakub Kicinski u8 zero[3]; 36c869f77dSJakub Kicinski 37c869f77dSJakub Kicinski u8 snr; 38c869f77dSJakub Kicinski u8 ant; 39c869f77dSJakub Kicinski u8 gain; 40c869f77dSJakub Kicinski u8 freq_off; 41c869f77dSJakub Kicinski 42c869f77dSJakub Kicinski __le32 resv2; 43c869f77dSJakub Kicinski __le32 expert_ant; 44c869f77dSJakub Kicinski } __packed __aligned(4); 45c869f77dSJakub Kicinski 46c869f77dSJakub Kicinski #define MT_RXINFO_BA BIT(0) 47c869f77dSJakub Kicinski #define MT_RXINFO_DATA BIT(1) 48c869f77dSJakub Kicinski #define MT_RXINFO_NULL BIT(2) 49c869f77dSJakub Kicinski #define MT_RXINFO_FRAG BIT(3) 50c869f77dSJakub Kicinski #define MT_RXINFO_U2M BIT(4) 51c869f77dSJakub Kicinski #define MT_RXINFO_MULTICAST BIT(5) 52c869f77dSJakub Kicinski #define MT_RXINFO_BROADCAST BIT(6) 53c869f77dSJakub Kicinski #define MT_RXINFO_MYBSS BIT(7) 54c869f77dSJakub Kicinski #define MT_RXINFO_CRCERR BIT(8) 55c869f77dSJakub Kicinski #define MT_RXINFO_ICVERR BIT(9) 56c869f77dSJakub Kicinski #define MT_RXINFO_MICERR BIT(10) 57c869f77dSJakub Kicinski #define MT_RXINFO_AMSDU BIT(11) 58c869f77dSJakub Kicinski #define MT_RXINFO_HTC BIT(12) 59c869f77dSJakub Kicinski #define MT_RXINFO_RSSI BIT(13) 60c869f77dSJakub Kicinski #define MT_RXINFO_L2PAD BIT(14) 61c869f77dSJakub Kicinski #define MT_RXINFO_AMPDU BIT(15) 62c869f77dSJakub Kicinski #define MT_RXINFO_DECRYPT BIT(16) 63c869f77dSJakub Kicinski #define MT_RXINFO_BSSIDX3 BIT(17) 64c869f77dSJakub Kicinski #define MT_RXINFO_WAPI_KEY BIT(18) 65c869f77dSJakub Kicinski #define MT_RXINFO_PN_LEN GENMASK(21, 19) 66c869f77dSJakub Kicinski #define MT_RXINFO_SW_PKT_80211 BIT(22) 67c869f77dSJakub Kicinski #define MT_RXINFO_TCP_SUM_BYPASS BIT(28) 68c869f77dSJakub Kicinski #define MT_RXINFO_IP_SUM_BYPASS BIT(29) 69c869f77dSJakub Kicinski #define MT_RXINFO_TCP_SUM_ERR BIT(30) 70c869f77dSJakub Kicinski #define MT_RXINFO_IP_SUM_ERR BIT(31) 71c869f77dSJakub Kicinski 72c869f77dSJakub Kicinski #define MT_RXWI_CTL_WCID GENMASK(7, 0) 73c869f77dSJakub Kicinski #define MT_RXWI_CTL_KEY_IDX GENMASK(9, 8) 74c869f77dSJakub Kicinski #define MT_RXWI_CTL_BSS_IDX GENMASK(12, 10) 75c869f77dSJakub Kicinski #define MT_RXWI_CTL_UDF GENMASK(15, 13) 76c869f77dSJakub Kicinski #define MT_RXWI_CTL_MPDU_LEN GENMASK(27, 16) 77c869f77dSJakub Kicinski #define MT_RXWI_CTL_TID GENMASK(31, 28) 78c869f77dSJakub Kicinski 79c869f77dSJakub Kicinski #define MT_RXWI_FRAG GENMASK(3, 0) 80c869f77dSJakub Kicinski #define MT_RXWI_SN GENMASK(15, 4) 81c869f77dSJakub Kicinski 82c869f77dSJakub Kicinski #define MT_RXWI_RATE_MCS GENMASK(6, 0) 83c869f77dSJakub Kicinski #define MT_RXWI_RATE_BW BIT(7) 84c869f77dSJakub Kicinski #define MT_RXWI_RATE_SGI BIT(8) 85c869f77dSJakub Kicinski #define MT_RXWI_RATE_STBC GENMASK(10, 9) 86c869f77dSJakub Kicinski #define MT_RXWI_RATE_ETXBF BIT(11) 87c869f77dSJakub Kicinski #define MT_RXWI_RATE_SND BIT(12) 88c869f77dSJakub Kicinski #define MT_RXWI_RATE_ITXBF BIT(13) 89c869f77dSJakub Kicinski #define MT_RXWI_RATE_PHY GENMASK(15, 14) 90c869f77dSJakub Kicinski 91c869f77dSJakub Kicinski #define MT_RXWI_GAIN_RSSI_VAL GENMASK(5, 0) 92c869f77dSJakub Kicinski #define MT_RXWI_GAIN_RSSI_LNA_ID GENMASK(7, 6) 93c869f77dSJakub Kicinski #define MT_RXWI_ANT_AUX_LNA BIT(7) 94c869f77dSJakub Kicinski 95c869f77dSJakub Kicinski #define MT_RXWI_EANT_ENC_ANT_ID GENMASK(7, 0) 96c869f77dSJakub Kicinski 97c869f77dSJakub Kicinski enum mt76_phy_type { 98c869f77dSJakub Kicinski MT_PHY_TYPE_CCK, 99c869f77dSJakub Kicinski MT_PHY_TYPE_OFDM, 100c869f77dSJakub Kicinski MT_PHY_TYPE_HT, 101c869f77dSJakub Kicinski MT_PHY_TYPE_HT_GF, 102c869f77dSJakub Kicinski }; 103c869f77dSJakub Kicinski 104c869f77dSJakub Kicinski enum mt76_phy_bandwidth { 105c869f77dSJakub Kicinski MT_PHY_BW_20, 106c869f77dSJakub Kicinski MT_PHY_BW_40, 107c869f77dSJakub Kicinski }; 108c869f77dSJakub Kicinski 109c869f77dSJakub Kicinski struct mt76_txwi { 110c869f77dSJakub Kicinski __le16 flags; 111c869f77dSJakub Kicinski __le16 rate_ctl; 112c869f77dSJakub Kicinski 113c869f77dSJakub Kicinski u8 ack_ctl; 114c869f77dSJakub Kicinski u8 wcid; 115c869f77dSJakub Kicinski __le16 len_ctl; 116c869f77dSJakub Kicinski 117c869f77dSJakub Kicinski __le32 iv; 118c869f77dSJakub Kicinski 119c869f77dSJakub Kicinski __le32 eiv; 120c869f77dSJakub Kicinski 121c869f77dSJakub Kicinski u8 aid; 122c869f77dSJakub Kicinski u8 txstream; 123c869f77dSJakub Kicinski __le16 ctl; 124c869f77dSJakub Kicinski } __packed __aligned(4); 125c869f77dSJakub Kicinski 126c869f77dSJakub Kicinski #define MT_TXWI_FLAGS_FRAG BIT(0) 127c869f77dSJakub Kicinski #define MT_TXWI_FLAGS_MMPS BIT(1) 128c869f77dSJakub Kicinski #define MT_TXWI_FLAGS_CFACK BIT(2) 129c869f77dSJakub Kicinski #define MT_TXWI_FLAGS_TS BIT(3) 130c869f77dSJakub Kicinski #define MT_TXWI_FLAGS_AMPDU BIT(4) 131c869f77dSJakub Kicinski #define MT_TXWI_FLAGS_MPDU_DENSITY GENMASK(7, 5) 132c869f77dSJakub Kicinski #define MT_TXWI_FLAGS_TXOP GENMASK(9, 8) 133c869f77dSJakub Kicinski #define MT_TXWI_FLAGS_CWMIN GENMASK(12, 10) 134c869f77dSJakub Kicinski #define MT_TXWI_FLAGS_NO_RATE_FALLBACK BIT(13) 135c869f77dSJakub Kicinski #define MT_TXWI_FLAGS_TX_RPT BIT(14) 136c869f77dSJakub Kicinski #define MT_TXWI_FLAGS_TX_RATE_LUT BIT(15) 137c869f77dSJakub Kicinski 138c869f77dSJakub Kicinski #define MT_TXWI_RATE_MCS GENMASK(6, 0) 139c869f77dSJakub Kicinski #define MT_TXWI_RATE_BW BIT(7) 140c869f77dSJakub Kicinski #define MT_TXWI_RATE_SGI BIT(8) 141c869f77dSJakub Kicinski #define MT_TXWI_RATE_STBC GENMASK(10, 9) 142c869f77dSJakub Kicinski #define MT_TXWI_RATE_PHY_MODE GENMASK(15, 14) 143c869f77dSJakub Kicinski 144c869f77dSJakub Kicinski #define MT_TXWI_ACK_CTL_REQ BIT(0) 145c869f77dSJakub Kicinski #define MT_TXWI_ACK_CTL_NSEQ BIT(1) 146c869f77dSJakub Kicinski #define MT_TXWI_ACK_CTL_BA_WINDOW GENMASK(7, 2) 147c869f77dSJakub Kicinski 148c869f77dSJakub Kicinski #define MT_TXWI_LEN_BYTE_CNT GENMASK(11, 0) 149c869f77dSJakub Kicinski #define MT_TXWI_LEN_PKTID GENMASK(15, 12) 150c869f77dSJakub Kicinski 151c869f77dSJakub Kicinski #define MT_TXWI_CTL_TX_POWER_ADJ GENMASK(3, 0) 152c869f77dSJakub Kicinski #define MT_TXWI_CTL_CHAN_CHECK_PKT BIT(4) 153c869f77dSJakub Kicinski #define MT_TXWI_CTL_PIFS_REV BIT(6) 154c869f77dSJakub Kicinski 155c869f77dSJakub Kicinski u32 mt76_mac_process_rx(struct mt7601u_dev *dev, struct sk_buff *skb, 156c869f77dSJakub Kicinski u8 *data, void *rxi); 157c869f77dSJakub Kicinski int mt76_mac_wcid_set_key(struct mt7601u_dev *dev, u8 idx, 158c869f77dSJakub Kicinski struct ieee80211_key_conf *key); 159c869f77dSJakub Kicinski void mt76_mac_wcid_set_rate(struct mt7601u_dev *dev, struct mt76_wcid *wcid, 160c869f77dSJakub Kicinski const struct ieee80211_tx_rate *rate); 161c869f77dSJakub Kicinski 162c869f77dSJakub Kicinski int mt76_mac_shared_key_setup(struct mt7601u_dev *dev, u8 vif_idx, u8 key_idx, 163c869f77dSJakub Kicinski struct ieee80211_key_conf *key); 164c869f77dSJakub Kicinski u16 mt76_mac_tx_rate_val(struct mt7601u_dev *dev, 165c869f77dSJakub Kicinski const struct ieee80211_tx_rate *rate, u8 *nss_val); 166c869f77dSJakub Kicinski struct mt76_tx_status 167c869f77dSJakub Kicinski mt7601u_mac_fetch_tx_status(struct mt7601u_dev *dev); 168c869f77dSJakub Kicinski void mt76_send_tx_status(struct mt7601u_dev *dev, struct mt76_tx_status *stat); 169e96826bdSLorenzo Bianconi void mt7601u_set_macaddr(struct mt7601u_dev *dev, const u8 *addr); 170c869f77dSJakub Kicinski 171c869f77dSJakub Kicinski #endif 172