1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /* Copyright(c) 2019-2020  Realtek Corporation
3  */
4 
5 #ifndef __RTW89_CAM_H__
6 #define __RTW89_CAM_H__
7 
8 #include "core.h"
9 
10 #define RTW89_SEC_CAM_LEN	20
11 
12 static inline void FWCMD_SET_ADDR_IDX(void *cmd, u32 value)
13 {
14 	le32p_replace_bits((__le32 *)(cmd) + 1, value, GENMASK(7, 0));
15 }
16 
17 static inline void FWCMD_SET_ADDR_OFFSET(void *cmd, u32 value)
18 {
19 	le32p_replace_bits((__le32 *)(cmd) + 1, value, GENMASK(15, 8));
20 }
21 
22 static inline void FWCMD_SET_ADDR_LEN(void *cmd, u32 value)
23 {
24 	le32p_replace_bits((__le32 *)(cmd) + 1, value, GENMASK(23, 16));
25 }
26 
27 static inline void FWCMD_SET_ADDR_VALID(void *cmd, u32 value)
28 {
29 	le32p_replace_bits((__le32 *)(cmd) + 2, value, BIT(0));
30 }
31 
32 static inline void FWCMD_SET_ADDR_NET_TYPE(void *cmd, u32 value)
33 {
34 	le32p_replace_bits((__le32 *)(cmd) + 2, value, GENMASK(2, 1));
35 }
36 
37 static inline void FWCMD_SET_ADDR_BCN_HIT_COND(void *cmd, u32 value)
38 {
39 	le32p_replace_bits((__le32 *)(cmd) + 2, value, GENMASK(4, 3));
40 }
41 
42 static inline void FWCMD_SET_ADDR_HIT_RULE(void *cmd, u32 value)
43 {
44 	le32p_replace_bits((__le32 *)(cmd) + 2, value, GENMASK(6, 5));
45 }
46 
47 static inline void FWCMD_SET_ADDR_BB_SEL(void *cmd, u32 value)
48 {
49 	le32p_replace_bits((__le32 *)(cmd) + 2, value, BIT(7));
50 }
51 
52 static inline void FWCMD_SET_ADDR_ADDR_MASK(void *cmd, u32 value)
53 {
54 	le32p_replace_bits((__le32 *)(cmd) + 2, value, GENMASK(13, 8));
55 }
56 
57 static inline void FWCMD_SET_ADDR_MASK_SEL(void *cmd, u32 value)
58 {
59 	le32p_replace_bits((__le32 *)(cmd) + 2, value, GENMASK(15, 14));
60 }
61 
62 static inline void FWCMD_SET_ADDR_SMA_HASH(void *cmd, u32 value)
63 {
64 	le32p_replace_bits((__le32 *)(cmd) + 2, value, GENMASK(23, 16));
65 }
66 
67 static inline void FWCMD_SET_ADDR_TMA_HASH(void *cmd, u32 value)
68 {
69 	le32p_replace_bits((__le32 *)(cmd) + 2, value, GENMASK(31, 24));
70 }
71 
72 static inline void FWCMD_SET_ADDR_BSSID_CAM_IDX(void *cmd, u32 value)
73 {
74 	le32p_replace_bits((__le32 *)(cmd) + 3, value, GENMASK(5, 0));
75 }
76 
77 static inline void FWCMD_SET_ADDR_SMA0(void *cmd, u32 value)
78 {
79 	le32p_replace_bits((__le32 *)(cmd) + 4, value, GENMASK(7, 0));
80 }
81 
82 static inline void FWCMD_SET_ADDR_SMA1(void *cmd, u32 value)
83 {
84 	le32p_replace_bits((__le32 *)(cmd) + 4, value, GENMASK(15, 8));
85 }
86 
87 static inline void FWCMD_SET_ADDR_SMA2(void *cmd, u32 value)
88 {
89 	le32p_replace_bits((__le32 *)(cmd) + 4, value, GENMASK(23, 16));
90 }
91 
92 static inline void FWCMD_SET_ADDR_SMA3(void *cmd, u32 value)
93 {
94 	le32p_replace_bits((__le32 *)(cmd) + 4, value, GENMASK(31, 24));
95 }
96 
97 static inline void FWCMD_SET_ADDR_SMA4(void *cmd, u32 value)
98 {
99 	le32p_replace_bits((__le32 *)(cmd) + 5, value, GENMASK(7, 0));
100 }
101 
102 static inline void FWCMD_SET_ADDR_SMA5(void *cmd, u32 value)
103 {
104 	le32p_replace_bits((__le32 *)(cmd) + 5, value, GENMASK(15, 8));
105 }
106 
107 static inline void FWCMD_SET_ADDR_TMA0(void *cmd, u32 value)
108 {
109 	le32p_replace_bits((__le32 *)(cmd) + 5, value, GENMASK(23, 16));
110 }
111 
112 static inline void FWCMD_SET_ADDR_TMA1(void *cmd, u32 value)
113 {
114 	le32p_replace_bits((__le32 *)(cmd) + 5, value, GENMASK(31, 24));
115 }
116 
117 static inline void FWCMD_SET_ADDR_TMA2(void *cmd, u32 value)
118 {
119 	le32p_replace_bits((__le32 *)(cmd) + 6, value, GENMASK(7, 0));
120 }
121 
122 static inline void FWCMD_SET_ADDR_TMA3(void *cmd, u32 value)
123 {
124 	le32p_replace_bits((__le32 *)(cmd) + 6, value, GENMASK(15, 8));
125 }
126 
127 static inline void FWCMD_SET_ADDR_TMA4(void *cmd, u32 value)
128 {
129 	le32p_replace_bits((__le32 *)(cmd) + 6, value, GENMASK(23, 16));
130 }
131 
132 static inline void FWCMD_SET_ADDR_TMA5(void *cmd, u32 value)
133 {
134 	le32p_replace_bits((__le32 *)(cmd) + 6, value, GENMASK(31, 24));
135 }
136 
137 static inline void FWCMD_SET_ADDR_MACID(void *cmd, u32 value)
138 {
139 	le32p_replace_bits((__le32 *)(cmd) + 8, value, GENMASK(7, 0));
140 }
141 
142 static inline void FWCMD_SET_ADDR_PORT_INT(void *cmd, u32 value)
143 {
144 	le32p_replace_bits((__le32 *)(cmd) + 8, value, GENMASK(10, 8));
145 }
146 
147 static inline void FWCMD_SET_ADDR_TSF_SYNC(void *cmd, u32 value)
148 {
149 	le32p_replace_bits((__le32 *)(cmd) + 8, value, GENMASK(13, 11));
150 }
151 
152 static inline void FWCMD_SET_ADDR_TF_TRS(void *cmd, u32 value)
153 {
154 	le32p_replace_bits((__le32 *)(cmd) + 8, value, BIT(14));
155 }
156 
157 static inline void FWCMD_SET_ADDR_LSIG_TXOP(void *cmd, u32 value)
158 {
159 	le32p_replace_bits((__le32 *)(cmd) + 8, value, BIT(15));
160 }
161 
162 static inline void FWCMD_SET_ADDR_TGT_IND(void *cmd, u32 value)
163 {
164 	le32p_replace_bits((__le32 *)(cmd) + 8, value, GENMASK(26, 24));
165 }
166 
167 static inline void FWCMD_SET_ADDR_FRM_TGT_IND(void *cmd, u32 value)
168 {
169 	le32p_replace_bits((__le32 *)(cmd) + 8, value, GENMASK(29, 27));
170 }
171 
172 static inline void FWCMD_SET_ADDR_AID12(void *cmd, u32 value)
173 {
174 	le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(11, 0));
175 }
176 
177 static inline void FWCMD_SET_ADDR_AID12_0(void *cmd, u32 value)
178 {
179 	le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(7, 0));
180 }
181 
182 static inline void FWCMD_SET_ADDR_AID12_1(void *cmd, u32 value)
183 {
184 	le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(11, 8));
185 }
186 
187 static inline void FWCMD_SET_ADDR_WOL_PATTERN(void *cmd, u32 value)
188 {
189 	le32p_replace_bits((__le32 *)(cmd) + 9, value, BIT(12));
190 }
191 
192 static inline void FWCMD_SET_ADDR_WOL_UC(void *cmd, u32 value)
193 {
194 	le32p_replace_bits((__le32 *)(cmd) + 9, value, BIT(13));
195 }
196 
197 static inline void FWCMD_SET_ADDR_WOL_MAGIC(void *cmd, u32 value)
198 {
199 	le32p_replace_bits((__le32 *)(cmd) + 9, value, BIT(14));
200 }
201 
202 static inline void FWCMD_SET_ADDR_WAPI(void *cmd, u32 value)
203 {
204 	le32p_replace_bits((__le32 *)(cmd) + 9, value, BIT(15));
205 }
206 
207 static inline void FWCMD_SET_ADDR_SEC_ENT_MODE(void *cmd, u32 value)
208 {
209 	le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(17, 16));
210 }
211 
212 static inline void FWCMD_SET_ADDR_SEC_ENT0_KEYID(void *cmd, u32 value)
213 {
214 	le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(19, 18));
215 }
216 
217 static inline void FWCMD_SET_ADDR_SEC_ENT1_KEYID(void *cmd, u32 value)
218 {
219 	le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(21, 20));
220 }
221 
222 static inline void FWCMD_SET_ADDR_SEC_ENT2_KEYID(void *cmd, u32 value)
223 {
224 	le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(23, 22));
225 }
226 
227 static inline void FWCMD_SET_ADDR_SEC_ENT3_KEYID(void *cmd, u32 value)
228 {
229 	le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(25, 24));
230 }
231 
232 static inline void FWCMD_SET_ADDR_SEC_ENT4_KEYID(void *cmd, u32 value)
233 {
234 	le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(27, 26));
235 }
236 
237 static inline void FWCMD_SET_ADDR_SEC_ENT5_KEYID(void *cmd, u32 value)
238 {
239 	le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(29, 28));
240 }
241 
242 static inline void FWCMD_SET_ADDR_SEC_ENT6_KEYID(void *cmd, u32 value)
243 {
244 	le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(31, 30));
245 }
246 
247 static inline void FWCMD_SET_ADDR_SEC_ENT_VALID(void *cmd, u32 value)
248 {
249 	le32p_replace_bits((__le32 *)(cmd) + 10, value, GENMASK(7, 0));
250 }
251 
252 static inline void FWCMD_SET_ADDR_SEC_ENT0(void *cmd, u32 value)
253 {
254 	le32p_replace_bits((__le32 *)(cmd) + 10, value, GENMASK(15, 8));
255 }
256 
257 static inline void FWCMD_SET_ADDR_SEC_ENT1(void *cmd, u32 value)
258 {
259 	le32p_replace_bits((__le32 *)(cmd) + 10, value, GENMASK(23, 16));
260 }
261 
262 static inline void FWCMD_SET_ADDR_SEC_ENT2(void *cmd, u32 value)
263 {
264 	le32p_replace_bits((__le32 *)(cmd) + 10, value, GENMASK(31, 24));
265 }
266 
267 static inline void FWCMD_SET_ADDR_SEC_ENT3(void *cmd, u32 value)
268 {
269 	le32p_replace_bits((__le32 *)(cmd) + 11, value, GENMASK(7, 0));
270 }
271 
272 static inline void FWCMD_SET_ADDR_SEC_ENT4(void *cmd, u32 value)
273 {
274 	le32p_replace_bits((__le32 *)(cmd) + 11, value, GENMASK(15, 8));
275 }
276 
277 static inline void FWCMD_SET_ADDR_SEC_ENT5(void *cmd, u32 value)
278 {
279 	le32p_replace_bits((__le32 *)(cmd) + 11, value, GENMASK(23, 16));
280 }
281 
282 static inline void FWCMD_SET_ADDR_SEC_ENT6(void *cmd, u32 value)
283 {
284 	le32p_replace_bits((__le32 *)(cmd) + 11, value, GENMASK(31, 24));
285 }
286 
287 static inline void FWCMD_SET_ADDR_BSSID_IDX(void *cmd, u32 value)
288 {
289 	le32p_replace_bits((__le32 *)(cmd) + 12, value, GENMASK(7, 0));
290 }
291 
292 static inline void FWCMD_SET_ADDR_BSSID_OFFSET(void *cmd, u32 value)
293 {
294 	le32p_replace_bits((__le32 *)(cmd) + 12, value, GENMASK(15, 8));
295 }
296 
297 static inline void FWCMD_SET_ADDR_BSSID_LEN(void *cmd, u32 value)
298 {
299 	le32p_replace_bits((__le32 *)(cmd) + 12, value, GENMASK(23, 16));
300 }
301 
302 static inline void FWCMD_SET_ADDR_BSSID_VALID(void *cmd, u32 value)
303 {
304 	le32p_replace_bits((__le32 *)(cmd) + 13, value, BIT(0));
305 }
306 
307 static inline void FWCMD_SET_ADDR_BSSID_BB_SEL(void *cmd, u32 value)
308 {
309 	le32p_replace_bits((__le32 *)(cmd) + 13, value, BIT(1));
310 }
311 
312 static inline void FWCMD_SET_ADDR_BSSID_BSS_COLOR(void *cmd, u32 value)
313 {
314 	le32p_replace_bits((__le32 *)(cmd) + 13, value, GENMASK(13, 8));
315 }
316 
317 static inline void FWCMD_SET_ADDR_BSSID_BSSID0(void *cmd, u32 value)
318 {
319 	le32p_replace_bits((__le32 *)(cmd) + 13, value, GENMASK(23, 16));
320 }
321 
322 static inline void FWCMD_SET_ADDR_BSSID_BSSID1(void *cmd, u32 value)
323 {
324 	le32p_replace_bits((__le32 *)(cmd) + 13, value, GENMASK(31, 24));
325 }
326 
327 static inline void FWCMD_SET_ADDR_BSSID_BSSID2(void *cmd, u32 value)
328 {
329 	le32p_replace_bits((__le32 *)(cmd) + 14, value, GENMASK(7, 0));
330 }
331 
332 static inline void FWCMD_SET_ADDR_BSSID_BSSID3(void *cmd, u32 value)
333 {
334 	le32p_replace_bits((__le32 *)(cmd) + 14, value, GENMASK(15, 8));
335 }
336 
337 static inline void FWCMD_SET_ADDR_BSSID_BSSID4(void *cmd, u32 value)
338 {
339 	le32p_replace_bits((__le32 *)(cmd) + 14, value, GENMASK(23, 16));
340 }
341 
342 static inline void FWCMD_SET_ADDR_BSSID_BSSID5(void *cmd, u32 value)
343 {
344 	le32p_replace_bits((__le32 *)(cmd) + 14, value, GENMASK(31, 24));
345 }
346 
347 int rtw89_cam_init(struct rtw89_dev *rtwdev, struct rtw89_vif *vif);
348 void rtw89_cam_deinit(struct rtw89_dev *rtwdev, struct rtw89_vif *vif);
349 int rtw89_cam_init_addr_cam(struct rtw89_dev *rtwdev,
350 			    struct rtw89_addr_cam_entry *addr_cam,
351 			    const struct rtw89_bssid_cam_entry *bssid_cam);
352 void rtw89_cam_deinit_addr_cam(struct rtw89_dev *rtwdev,
353 			       struct rtw89_addr_cam_entry *addr_cam);
354 void rtw89_cam_fill_addr_cam_info(struct rtw89_dev *rtwdev,
355 				  struct rtw89_vif *vif,
356 				  struct rtw89_sta *rtwsta,
357 				  const u8 *scan_mac_addr, u8 *cmd);
358 int rtw89_cam_fill_bssid_cam_info(struct rtw89_dev *rtwdev,
359 				  struct rtw89_vif *vif, u8 *cmd);
360 int rtw89_cam_sec_key_add(struct rtw89_dev *rtwdev,
361 			  struct ieee80211_vif *vif,
362 			  struct ieee80211_sta *sta,
363 			  struct ieee80211_key_conf *key);
364 int rtw89_cam_sec_key_del(struct rtw89_dev *rtwdev,
365 			  struct ieee80211_vif *vif,
366 			  struct ieee80211_sta *sta,
367 			  struct ieee80211_key_conf *key,
368 			  bool inform_fw);
369 void rtw89_cam_bssid_changed(struct rtw89_dev *rtwdev,
370 			     struct rtw89_vif *rtwvif);
371 void rtw89_cam_reset_keys(struct rtw89_dev *rtwdev);
372 #endif
373