18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: ISC */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name> 48c2ecf20Sopenharmony_ci * Copyright (C) 2018 Stanislaw Gruszka <stf_xl@wp.pl> 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#ifndef __MT76X02_MAC_H 88c2ecf20Sopenharmony_ci#define __MT76X02_MAC_H 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_cistruct mt76x02_dev; 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_cistruct mt76x02_tx_status { 138c2ecf20Sopenharmony_ci u8 valid:1; 148c2ecf20Sopenharmony_ci u8 success:1; 158c2ecf20Sopenharmony_ci u8 aggr:1; 168c2ecf20Sopenharmony_ci u8 ack_req:1; 178c2ecf20Sopenharmony_ci u8 wcid; 188c2ecf20Sopenharmony_ci u8 pktid; 198c2ecf20Sopenharmony_ci u8 retry; 208c2ecf20Sopenharmony_ci u16 rate; 218c2ecf20Sopenharmony_ci} __packed __aligned(2); 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define MT_VIF_WCID(_n) (254 - ((_n) & 7)) 248c2ecf20Sopenharmony_ci#define MT_MAX_VIFS 8 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci#define MT_PKTID_RATE GENMASK(4, 0) 278c2ecf20Sopenharmony_ci#define MT_PKTID_AC GENMASK(6, 5) 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cistruct mt76x02_vif { 308c2ecf20Sopenharmony_ci struct mt76_wcid group_wcid; /* must be first */ 318c2ecf20Sopenharmony_ci u8 idx; 328c2ecf20Sopenharmony_ci}; 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ciDECLARE_EWMA(pktlen, 8, 8); 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_cistruct mt76x02_sta { 378c2ecf20Sopenharmony_ci struct mt76_wcid wcid; /* must be first */ 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci struct mt76x02_vif *vif; 408c2ecf20Sopenharmony_ci struct mt76x02_tx_status status; 418c2ecf20Sopenharmony_ci int n_frames; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci struct ewma_pktlen pktlen; 448c2ecf20Sopenharmony_ci}; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#define MT_RXINFO_BA BIT(0) 478c2ecf20Sopenharmony_ci#define MT_RXINFO_DATA BIT(1) 488c2ecf20Sopenharmony_ci#define MT_RXINFO_NULL BIT(2) 498c2ecf20Sopenharmony_ci#define MT_RXINFO_FRAG BIT(3) 508c2ecf20Sopenharmony_ci#define MT_RXINFO_UNICAST BIT(4) 518c2ecf20Sopenharmony_ci#define MT_RXINFO_MULTICAST BIT(5) 528c2ecf20Sopenharmony_ci#define MT_RXINFO_BROADCAST BIT(6) 538c2ecf20Sopenharmony_ci#define MT_RXINFO_MYBSS BIT(7) 548c2ecf20Sopenharmony_ci#define MT_RXINFO_CRCERR BIT(8) 558c2ecf20Sopenharmony_ci#define MT_RXINFO_ICVERR BIT(9) 568c2ecf20Sopenharmony_ci#define MT_RXINFO_MICERR BIT(10) 578c2ecf20Sopenharmony_ci#define MT_RXINFO_AMSDU BIT(11) 588c2ecf20Sopenharmony_ci#define MT_RXINFO_HTC BIT(12) 598c2ecf20Sopenharmony_ci#define MT_RXINFO_RSSI BIT(13) 608c2ecf20Sopenharmony_ci#define MT_RXINFO_L2PAD BIT(14) 618c2ecf20Sopenharmony_ci#define MT_RXINFO_AMPDU BIT(15) 628c2ecf20Sopenharmony_ci#define MT_RXINFO_DECRYPT BIT(16) 638c2ecf20Sopenharmony_ci#define MT_RXINFO_BSSIDX3 BIT(17) 648c2ecf20Sopenharmony_ci#define MT_RXINFO_WAPI_KEY BIT(18) 658c2ecf20Sopenharmony_ci#define MT_RXINFO_PN_LEN GENMASK(21, 19) 668c2ecf20Sopenharmony_ci#define MT_RXINFO_SW_FTYPE0 BIT(22) 678c2ecf20Sopenharmony_ci#define MT_RXINFO_SW_FTYPE1 BIT(23) 688c2ecf20Sopenharmony_ci#define MT_RXINFO_PROBE_RESP BIT(24) 698c2ecf20Sopenharmony_ci#define MT_RXINFO_BEACON BIT(25) 708c2ecf20Sopenharmony_ci#define MT_RXINFO_DISASSOC BIT(26) 718c2ecf20Sopenharmony_ci#define MT_RXINFO_DEAUTH BIT(27) 728c2ecf20Sopenharmony_ci#define MT_RXINFO_ACTION BIT(28) 738c2ecf20Sopenharmony_ci#define MT_RXINFO_TCP_SUM_ERR BIT(30) 748c2ecf20Sopenharmony_ci#define MT_RXINFO_IP_SUM_ERR BIT(31) 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci#define MT_RXWI_CTL_WCID GENMASK(7, 0) 778c2ecf20Sopenharmony_ci#define MT_RXWI_CTL_KEY_IDX GENMASK(9, 8) 788c2ecf20Sopenharmony_ci#define MT_RXWI_CTL_BSS_IDX GENMASK(12, 10) 798c2ecf20Sopenharmony_ci#define MT_RXWI_CTL_UDF GENMASK(15, 13) 808c2ecf20Sopenharmony_ci#define MT_RXWI_CTL_MPDU_LEN GENMASK(29, 16) 818c2ecf20Sopenharmony_ci#define MT_RXWI_CTL_EOF BIT(31) 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci#define MT_RXWI_TID GENMASK(3, 0) 848c2ecf20Sopenharmony_ci#define MT_RXWI_SN GENMASK(15, 4) 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci#define MT_RXWI_RATE_INDEX GENMASK(5, 0) 878c2ecf20Sopenharmony_ci#define MT_RXWI_RATE_LDPC BIT(6) 888c2ecf20Sopenharmony_ci#define MT_RXWI_RATE_BW GENMASK(8, 7) 898c2ecf20Sopenharmony_ci#define MT_RXWI_RATE_SGI BIT(9) 908c2ecf20Sopenharmony_ci#define MT_RXWI_RATE_STBC BIT(10) 918c2ecf20Sopenharmony_ci#define MT_RXWI_RATE_LDPC_EXSYM BIT(11) 928c2ecf20Sopenharmony_ci#define MT_RXWI_RATE_PHY GENMASK(15, 13) 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci#define MT_RATE_INDEX_VHT_IDX GENMASK(3, 0) 958c2ecf20Sopenharmony_ci#define MT_RATE_INDEX_VHT_NSS GENMASK(5, 4) 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_cistruct mt76x02_rxwi { 988c2ecf20Sopenharmony_ci __le32 rxinfo; 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci __le32 ctl; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci __le16 tid_sn; 1038c2ecf20Sopenharmony_ci __le16 rate; 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci u8 rssi[4]; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci __le32 bbp_rxinfo[4]; 1088c2ecf20Sopenharmony_ci}; 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci#define MT_TX_PWR_ADJ GENMASK(3, 0) 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_cienum mt76x2_phy_bandwidth { 1138c2ecf20Sopenharmony_ci MT_PHY_BW_20, 1148c2ecf20Sopenharmony_ci MT_PHY_BW_40, 1158c2ecf20Sopenharmony_ci MT_PHY_BW_80, 1168c2ecf20Sopenharmony_ci}; 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci#define MT_TXWI_FLAGS_FRAG BIT(0) 1198c2ecf20Sopenharmony_ci#define MT_TXWI_FLAGS_MMPS BIT(1) 1208c2ecf20Sopenharmony_ci#define MT_TXWI_FLAGS_CFACK BIT(2) 1218c2ecf20Sopenharmony_ci#define MT_TXWI_FLAGS_TS BIT(3) 1228c2ecf20Sopenharmony_ci#define MT_TXWI_FLAGS_AMPDU BIT(4) 1238c2ecf20Sopenharmony_ci#define MT_TXWI_FLAGS_MPDU_DENSITY GENMASK(7, 5) 1248c2ecf20Sopenharmony_ci#define MT_TXWI_FLAGS_TXOP GENMASK(9, 8) 1258c2ecf20Sopenharmony_ci#define MT_TXWI_FLAGS_NDPS BIT(10) 1268c2ecf20Sopenharmony_ci#define MT_TXWI_FLAGS_RTSBWSIG BIT(11) 1278c2ecf20Sopenharmony_ci#define MT_TXWI_FLAGS_NDP_BW GENMASK(13, 12) 1288c2ecf20Sopenharmony_ci#define MT_TXWI_FLAGS_SOUND BIT(14) 1298c2ecf20Sopenharmony_ci#define MT_TXWI_FLAGS_TX_RATE_LUT BIT(15) 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci#define MT_TXWI_ACK_CTL_REQ BIT(0) 1328c2ecf20Sopenharmony_ci#define MT_TXWI_ACK_CTL_NSEQ BIT(1) 1338c2ecf20Sopenharmony_ci#define MT_TXWI_ACK_CTL_BA_WINDOW GENMASK(7, 2) 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_cistruct mt76x02_txwi { 1368c2ecf20Sopenharmony_ci __le16 flags; 1378c2ecf20Sopenharmony_ci __le16 rate; 1388c2ecf20Sopenharmony_ci u8 ack_ctl; 1398c2ecf20Sopenharmony_ci u8 wcid; 1408c2ecf20Sopenharmony_ci __le16 len_ctl; 1418c2ecf20Sopenharmony_ci __le32 iv; 1428c2ecf20Sopenharmony_ci __le32 eiv; 1438c2ecf20Sopenharmony_ci u8 aid; 1448c2ecf20Sopenharmony_ci u8 txstream; 1458c2ecf20Sopenharmony_ci u8 ctl2; 1468c2ecf20Sopenharmony_ci u8 pktid; 1478c2ecf20Sopenharmony_ci} __packed __aligned(4); 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_cistatic inline bool mt76x02_wait_for_mac(struct mt76_dev *dev) 1508c2ecf20Sopenharmony_ci{ 1518c2ecf20Sopenharmony_ci const u32 MAC_CSR0 = 0x1000; 1528c2ecf20Sopenharmony_ci int i; 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci for (i = 0; i < 500; i++) { 1558c2ecf20Sopenharmony_ci if (test_bit(MT76_REMOVED, &dev->phy.state)) 1568c2ecf20Sopenharmony_ci return false; 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci switch (dev->bus->rr(dev, MAC_CSR0)) { 1598c2ecf20Sopenharmony_ci case 0: 1608c2ecf20Sopenharmony_ci case ~0: 1618c2ecf20Sopenharmony_ci break; 1628c2ecf20Sopenharmony_ci default: 1638c2ecf20Sopenharmony_ci return true; 1648c2ecf20Sopenharmony_ci } 1658c2ecf20Sopenharmony_ci usleep_range(5000, 10000); 1668c2ecf20Sopenharmony_ci } 1678c2ecf20Sopenharmony_ci return false; 1688c2ecf20Sopenharmony_ci} 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_civoid mt76x02_mac_reset_counters(struct mt76x02_dev *dev); 1718c2ecf20Sopenharmony_civoid mt76x02_mac_set_short_preamble(struct mt76x02_dev *dev, bool enable); 1728c2ecf20Sopenharmony_ciint mt76x02_mac_shared_key_setup(struct mt76x02_dev *dev, u8 vif_idx, 1738c2ecf20Sopenharmony_ci u8 key_idx, struct ieee80211_key_conf *key); 1748c2ecf20Sopenharmony_ciint mt76x02_mac_wcid_set_key(struct mt76x02_dev *dev, u8 idx, 1758c2ecf20Sopenharmony_ci struct ieee80211_key_conf *key); 1768c2ecf20Sopenharmony_civoid mt76x02_mac_wcid_sync_pn(struct mt76x02_dev *dev, u8 idx, 1778c2ecf20Sopenharmony_ci struct ieee80211_key_conf *key); 1788c2ecf20Sopenharmony_civoid mt76x02_mac_wcid_setup(struct mt76x02_dev *dev, u8 idx, u8 vif_idx, 1798c2ecf20Sopenharmony_ci u8 *mac); 1808c2ecf20Sopenharmony_civoid mt76x02_mac_wcid_set_drop(struct mt76x02_dev *dev, u8 idx, bool drop); 1818c2ecf20Sopenharmony_civoid mt76x02_mac_wcid_set_rate(struct mt76x02_dev *dev, struct mt76_wcid *wcid, 1828c2ecf20Sopenharmony_ci const struct ieee80211_tx_rate *rate); 1838c2ecf20Sopenharmony_cibool mt76x02_mac_load_tx_status(struct mt76x02_dev *dev, 1848c2ecf20Sopenharmony_ci struct mt76x02_tx_status *stat); 1858c2ecf20Sopenharmony_civoid mt76x02_send_tx_status(struct mt76x02_dev *dev, 1868c2ecf20Sopenharmony_ci struct mt76x02_tx_status *stat, u8 *update); 1878c2ecf20Sopenharmony_ciint mt76x02_mac_process_rx(struct mt76x02_dev *dev, struct sk_buff *skb, 1888c2ecf20Sopenharmony_ci void *rxi); 1898c2ecf20Sopenharmony_civoid mt76x02_mac_set_tx_protection(struct mt76x02_dev *dev, bool legacy_prot, 1908c2ecf20Sopenharmony_ci int ht_mode); 1918c2ecf20Sopenharmony_civoid mt76x02_mac_set_rts_thresh(struct mt76x02_dev *dev, u32 val); 1928c2ecf20Sopenharmony_civoid mt76x02_mac_setaddr(struct mt76x02_dev *dev, const u8 *addr); 1938c2ecf20Sopenharmony_civoid mt76x02_mac_write_txwi(struct mt76x02_dev *dev, struct mt76x02_txwi *txwi, 1948c2ecf20Sopenharmony_ci struct sk_buff *skb, struct mt76_wcid *wcid, 1958c2ecf20Sopenharmony_ci struct ieee80211_sta *sta, int len); 1968c2ecf20Sopenharmony_civoid mt76x02_mac_poll_tx_status(struct mt76x02_dev *dev, bool irq); 1978c2ecf20Sopenharmony_civoid mt76x02_tx_complete_skb(struct mt76_dev *mdev, struct mt76_queue_entry *e); 1988c2ecf20Sopenharmony_civoid mt76x02_update_channel(struct mt76_dev *mdev); 1998c2ecf20Sopenharmony_civoid mt76x02_mac_work(struct work_struct *work); 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_civoid mt76x02_mac_cc_reset(struct mt76x02_dev *dev); 2028c2ecf20Sopenharmony_civoid mt76x02_mac_set_bssid(struct mt76x02_dev *dev, u8 idx, const u8 *addr); 2038c2ecf20Sopenharmony_civoid mt76x02_mac_set_beacon(struct mt76x02_dev *dev, struct sk_buff *skb); 2048c2ecf20Sopenharmony_civoid mt76x02_mac_set_beacon_enable(struct mt76x02_dev *dev, 2058c2ecf20Sopenharmony_ci struct ieee80211_vif *vif, bool enable); 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_civoid mt76x02_edcca_init(struct mt76x02_dev *dev); 2088c2ecf20Sopenharmony_ci#endif 209