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