xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/infineon/bcmdhd/bcmwifi_rspec.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Common OS-independent driver header for rate management.
3  *
4  * Portions of this code are copyright (c) 2022 Cypress Semiconductor Corporation
5  *
6  * Copyright (C) 1999-2017, Broadcom Corporation
7  *
8  *      Unless you and Broadcom execute a separate written software license
9  * agreement governing use of this software, this software is licensed to you
10  * under the terms of the GNU General Public License version 2 (the "GPL"),
11  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
12  * following added to such license:
13  *
14  *      As a special exception, the copyright holders of this software give you
15  * permission to link this software with independent modules, and to copy and
16  * distribute the resulting executable under terms of your choice, provided that
17  * you also meet, for each linked independent module, the terms and conditions of
18  * the license of that module.  An independent module is a module which is not
19  * derived from this software.  The special exception does not apply to any
20  * modifications of the software.
21  *
22  *      Notwithstanding the above, under no circumstances may you combine this
23  * software in any way with any other Broadcom software provided under a license
24  * other than the GPL, without Broadcom's express prior written consent.
25  *
26  *
27  * <<Broadcom-WL-IPTag/Open:>>
28  *
29  * $Id$
30  */
31 
32 #ifndef _bcmwifi_rspec_h_
33 #define _bcmwifi_rspec_h_
34 
35 #include <typedefs.h>
36 
37 /**
38  * ===================================================================================
39  * rate spec : holds rate and mode specific information required to generate a tx frame.
40  * Legacy CCK and OFDM information is held in the same manner as was done in the past.
41  * (in the lower byte) the upper 3 bytes primarily hold MIMO specific information
42  * ===================================================================================
43  */
44 typedef uint32	ratespec_t;
45 
46 /* Rate spec. definitions */
47 #define WL_RSPEC_RATE_MASK	0x000000FF	/**< Legacy rate or MCS or MCS + NSS */
48 #define WL_RSPEC_TXEXP_MASK	0x00000300	/**< Tx chain expansion beyond Nsts */
49 #define WL_RSPEC_TXEXP_SHIFT	8
50 #define WL_RSPEC_HE_GI_MASK	0x00000C00	/* HE GI indices */
51 #define WL_RSPEC_HE_GI_SHIFT	10
52 #define WL_RSPEC_BW_MASK	0x00070000	/**< Band width */
53 #define WL_RSPEC_BW_SHIFT	16
54 #define WL_RSPEC_DCM		0x00080000	/**< Dual Carrier Modulation */
55 #define WL_RSPEC_STBC		0x00100000	/**< STBC expansion, Nsts = 2 * Nss */
56 #define WL_RSPEC_TXBF		0x00200000
57 #define WL_RSPEC_LDPC		0x00400000
58 #define WL_RSPEC_SGI		0x00800000
59 #define WL_RSPEC_SHORT_PREAMBLE	0x00800000	/**< DSSS short preable - Encoding 0 */
60 #define WL_RSPEC_ENCODING_MASK	0x03000000	/**< Encoding of RSPEC_RATE field */
61 #define WL_RSPEC_ENCODING_SHIFT	24
62 
63 #define WL_RSPEC_OVERRIDE_RATE	0x40000000	/**< override rate only */
64 #define WL_RSPEC_OVERRIDE_MODE	0x80000000	/**< override both rate & mode */
65 
66 /* ======== RSPEC_HE_GI|RSPEC_SGI fields for HE ======== */
67 
68 /* GI for HE */
69 #define RSPEC_HE_LTF_GI(rspec)	(((rspec) & WL_RSPEC_HE_GI_MASK) >> WL_RSPEC_HE_GI_SHIFT)
70 #define WL_RSPEC_HE_1x_LTF_GI_0_8us	(0x0)
71 #define WL_RSPEC_HE_2x_LTF_GI_0_8us	(0x1)
72 #define WL_RSPEC_HE_2x_LTF_GI_1_6us	(0x2)
73 #define WL_RSPEC_HE_4x_LTF_GI_3_2us	(0x3)
74 #define RSPEC_ISHEGI(rspec)	(RSPEC_HE_LTF_GI(rspec) > WL_RSPEC_HE_1x_LTF_GI_0_8us)
75 #define HE_GI_TO_RSPEC(gi)	(((gi) << WL_RSPEC_HE_GI_SHIFT) & WL_RSPEC_HE_GI_MASK)
76 /* ======== RSPEC_RATE field ======== */
77 
78 /* Encoding 0 - legacy rate */
79 /* DSSS, CCK, and OFDM rates in [500kbps] units */
80 #define WL_RSPEC_LEGACY_RATE_MASK	0x0000007F
81 #define WLC_RATE_1M	2
82 #define WLC_RATE_2M	4
83 #define WLC_RATE_5M5	11
84 #define WLC_RATE_11M	22
85 #define WLC_RATE_6M	12
86 #define WLC_RATE_9M	18
87 #define WLC_RATE_12M	24
88 #define WLC_RATE_18M	36
89 #define WLC_RATE_24M	48
90 #define WLC_RATE_36M	72
91 #define WLC_RATE_48M	96
92 #define WLC_RATE_54M	108
93 
94 /* Encoding 1 - HT MCS */
95 #define WL_RSPEC_HT_MCS_MASK		0x0000007F	/**< HT MCS value mask in rspec */
96 
97 /* Encoding 2 - VHT MCS + NSS */
98 #define WL_RSPEC_VHT_MCS_MASK		0x0000000F	/**< VHT MCS value mask in rspec */
99 #define WL_RSPEC_VHT_NSS_MASK		0x000000F0	/**< VHT Nss value mask in rspec */
100 #define WL_RSPEC_VHT_NSS_SHIFT		4		/**< VHT Nss value shift in rspec */
101 
102 /* Encoding 3 - HE MCS + NSS */
103 #define WL_RSPEC_HE_MCS_MASK		0x0000000F	/**< HE MCS value mask in rspec */
104 #define WL_RSPEC_HE_NSS_MASK		0x000000F0	/**< HE Nss value mask in rspec */
105 #define WL_RSPEC_HE_NSS_SHIFT		4		/**< HE Nss value shift in rpsec */
106 
107 /* ======== RSPEC_BW field ======== */
108 
109 #define WL_RSPEC_BW_UNSPECIFIED	0
110 #define WL_RSPEC_BW_20MHZ	0x00010000
111 #define WL_RSPEC_BW_40MHZ	0x00020000
112 #define WL_RSPEC_BW_80MHZ	0x00030000
113 #define WL_RSPEC_BW_160MHZ	0x00040000
114 
115 /* ======== RSPEC_ENCODING field ======== */
116 
117 #define WL_RSPEC_ENCODE_RATE	0x00000000	/**< Legacy rate is stored in RSPEC_RATE */
118 #define WL_RSPEC_ENCODE_HT	0x01000000	/**< HT MCS is stored in RSPEC_RATE */
119 #define WL_RSPEC_ENCODE_VHT	0x02000000	/**< VHT MCS and NSS are stored in RSPEC_RATE */
120 #define WL_RSPEC_ENCODE_HE	0x03000000	/**< HE MCS and NSS are stored in RSPEC_RATE */
121 
122 /**
123  * ===============================
124  * Handy macros to parse rate spec
125  * ===============================
126  */
127 #define RSPEC_BW(rspec)		((rspec) & WL_RSPEC_BW_MASK)
128 #define RSPEC_IS20MHZ(rspec)	(RSPEC_BW(rspec) == WL_RSPEC_BW_20MHZ)
129 #define RSPEC_IS40MHZ(rspec)	(RSPEC_BW(rspec) == WL_RSPEC_BW_40MHZ)
130 #define RSPEC_IS80MHZ(rspec)	(RSPEC_BW(rspec) == WL_RSPEC_BW_80MHZ)
131 #define RSPEC_IS160MHZ(rspec)	(RSPEC_BW(rspec) == WL_RSPEC_BW_160MHZ)
132 
133 #define RSPEC_ISSGI(rspec)	(((rspec) & WL_RSPEC_SGI) != 0)
134 #define RSPEC_ISLDPC(rspec)	(((rspec) & WL_RSPEC_LDPC) != 0)
135 #define RSPEC_ISSTBC(rspec)	(((rspec) & WL_RSPEC_STBC) != 0)
136 #define RSPEC_ISTXBF(rspec)	(((rspec) & WL_RSPEC_TXBF) != 0)
137 
138 #define RSPEC_TXEXP(rspec)	(((rspec) & WL_RSPEC_TXEXP_MASK) >> WL_RSPEC_TXEXP_SHIFT)
139 
140 #define RSPEC_ENCODE(rspec)	(((rspec) & WL_RSPEC_ENCODING_MASK) >> WL_RSPEC_ENCODING_SHIFT)
141 #define RSPEC_ISLEGACY(rspec)	(((rspec) & WL_RSPEC_ENCODING_MASK) == WL_RSPEC_ENCODE_RATE)
142 
143 #define	RSPEC_ISCCK(rspec)	(RSPEC_ISLEGACY(rspec) && \
144 				 (int8)rate_info[(rspec) & WL_RSPEC_LEGACY_RATE_MASK] > 0)
145 #define	RSPEC_ISOFDM(rspec)	(RSPEC_ISLEGACY(rspec) && \
146 				 (int8)rate_info[(rspec) & WL_RSPEC_LEGACY_RATE_MASK] < 0)
147 
148 #define RSPEC_ISHT(rspec)	(((rspec) & WL_RSPEC_ENCODING_MASK) == WL_RSPEC_ENCODE_HT)
149 #ifdef WL11AC
150 #define RSPEC_ISVHT(rspec)	(((rspec) & WL_RSPEC_ENCODING_MASK) == WL_RSPEC_ENCODE_VHT)
151 #else /* WL11AC */
152 #define RSPEC_ISVHT(rspec)	0
153 #endif /* WL11AC */
154 #ifdef WL11AX
155 #define RSPEC_ISHE(rspec)	(((rspec) & WL_RSPEC_ENCODING_MASK) == WL_RSPEC_ENCODE_HE)
156 #else /* WL11AX */
157 #define RSPEC_ISHE(rspec)	0
158 #endif /* WL11AX */
159 
160 /**
161  * ================================
162  * Handy macros to create rate spec
163  * ================================
164  */
165 /* create ratespecs */
166 #define LEGACY_RSPEC(rate)	(WL_RSPEC_ENCODE_RATE | WL_RSPEC_BW_20MHZ | \
167 				 ((rate) & WL_RSPEC_LEGACY_RATE_MASK))
168 #define CCK_RSPEC(cck)		LEGACY_RSPEC(cck)
169 #define OFDM_RSPEC(ofdm)	LEGACY_RSPEC(ofdm)
170 #define HT_RSPEC(mcs)		(WL_RSPEC_ENCODE_HT | ((mcs) & WL_RSPEC_HT_MCS_MASK))
171 #define VHT_RSPEC(mcs, nss)	(WL_RSPEC_ENCODE_VHT | \
172 				 (((nss) << WL_RSPEC_VHT_NSS_SHIFT) & WL_RSPEC_VHT_NSS_MASK) | \
173 				 ((mcs) & WL_RSPEC_VHT_MCS_MASK))
174 #define HE_RSPEC(mcs, nss)	(WL_RSPEC_ENCODE_HE | \
175 				 (((nss) << WL_RSPEC_HE_NSS_SHIFT) & WL_RSPEC_HE_NSS_MASK) | \
176 				 ((mcs) & WL_RSPEC_HE_MCS_MASK))
177 
178 /**
179  * ==================
180  * Other handy macros
181  * ==================
182  */
183 
184 /* return rate in unit of Kbps */
185 #define RSPEC2KBPS(rspec)	wf_rspec_to_rate(rspec)
186 
187 /* return rate in unit of 500Kbps */
188 #define RSPEC2RATE(rspec)	((rspec) & WL_RSPEC_LEGACY_RATE_MASK)
189 
190 /**
191  * =================================
192  * Macros to use the rate_info table
193  * =================================
194  */
195 /* phy_rate table index is in [500kbps] units */
196 #define WLC_MAXRATE	108	/**< in 500kbps units */
197 extern const uint8 rate_info[];
198 /* phy_rate table value is encoded */
199 #define	RATE_INFO_OFDM_MASK	0x80	/* ofdm mask */
200 #define	RATE_INFO_RATE_MASK	0x7f	/* rate signal index mask */
201 #define	RATE_INFO_M_RATE_MASK	0x0f	/* M_RATE_TABLE index mask */
202 #define	RATE_INFO_RATE_ISCCK(r)	((r) <= WLC_MAXRATE && (int8)rate_info[r] > 0)
203 #define	RATE_INFO_RATE_ISOFDM(r) ((r) <= WLC_MAXRATE && (int8)rate_info[r] < 0)
204 
205 /**
206  * ===================
207  * function prototypes
208  * ===================
209  */
210 ratespec_t wf_vht_plcp_to_rspec(uint8 *plcp);
211 ratespec_t wf_he_plcp_to_rspec(uint8 *plcp);
212 uint wf_rspec_to_rate(ratespec_t rspec);
213 
214 #endif /* _bcmwifi_rspec_h_ */
215