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 
FWCMD_SET_ADDR_IDX(void * cmd,u32 value)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 
FWCMD_SET_ADDR_OFFSET(void * cmd,u32 value)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 
FWCMD_SET_ADDR_LEN(void * cmd,u32 value)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 
FWCMD_SET_ADDR_VALID(void * cmd,u32 value)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 
FWCMD_SET_ADDR_NET_TYPE(void * cmd,u32 value)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 
FWCMD_SET_ADDR_BCN_HIT_COND(void * cmd,u32 value)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 
FWCMD_SET_ADDR_HIT_RULE(void * cmd,u32 value)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 
FWCMD_SET_ADDR_BB_SEL(void * cmd,u32 value)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 
FWCMD_SET_ADDR_ADDR_MASK(void * cmd,u32 value)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 
FWCMD_SET_ADDR_MASK_SEL(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SMA_HASH(void * cmd,u32 value)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 
FWCMD_SET_ADDR_TMA_HASH(void * cmd,u32 value)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 
FWCMD_SET_ADDR_BSSID_CAM_IDX(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SMA0(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SMA1(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SMA2(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SMA3(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SMA4(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SMA5(void * cmd,u32 value)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 
FWCMD_SET_ADDR_TMA0(void * cmd,u32 value)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 
FWCMD_SET_ADDR_TMA1(void * cmd,u32 value)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 
FWCMD_SET_ADDR_TMA2(void * cmd,u32 value)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 
FWCMD_SET_ADDR_TMA3(void * cmd,u32 value)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 
FWCMD_SET_ADDR_TMA4(void * cmd,u32 value)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 
FWCMD_SET_ADDR_TMA5(void * cmd,u32 value)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 
FWCMD_SET_ADDR_MACID(void * cmd,u32 value)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 
FWCMD_SET_ADDR_PORT_INT(void * cmd,u32 value)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 
FWCMD_SET_ADDR_TSF_SYNC(void * cmd,u32 value)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 
FWCMD_SET_ADDR_TF_TRS(void * cmd,u32 value)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 
FWCMD_SET_ADDR_LSIG_TXOP(void * cmd,u32 value)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 
FWCMD_SET_ADDR_TGT_IND(void * cmd,u32 value)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 
FWCMD_SET_ADDR_FRM_TGT_IND(void * cmd,u32 value)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 
FWCMD_SET_ADDR_AID12(void * cmd,u32 value)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 
FWCMD_SET_ADDR_AID12_0(void * cmd,u32 value)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 
FWCMD_SET_ADDR_AID12_1(void * cmd,u32 value)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 
FWCMD_SET_ADDR_WOL_PATTERN(void * cmd,u32 value)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 
FWCMD_SET_ADDR_WOL_UC(void * cmd,u32 value)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 
FWCMD_SET_ADDR_WOL_MAGIC(void * cmd,u32 value)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 
FWCMD_SET_ADDR_WAPI(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SEC_ENT_MODE(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SEC_ENT0_KEYID(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SEC_ENT1_KEYID(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SEC_ENT2_KEYID(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SEC_ENT3_KEYID(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SEC_ENT4_KEYID(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SEC_ENT5_KEYID(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SEC_ENT6_KEYID(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SEC_ENT_VALID(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SEC_ENT0(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SEC_ENT1(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SEC_ENT2(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SEC_ENT3(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SEC_ENT4(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SEC_ENT5(void * cmd,u32 value)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 
FWCMD_SET_ADDR_SEC_ENT6(void * cmd,u32 value)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 
FWCMD_SET_ADDR_BSSID_IDX(void * cmd,u32 value)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 
FWCMD_SET_ADDR_BSSID_OFFSET(void * cmd,u32 value)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 
FWCMD_SET_ADDR_BSSID_LEN(void * cmd,u32 value)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 
FWCMD_SET_ADDR_BSSID_VALID(void * cmd,u32 value)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 
FWCMD_SET_ADDR_BSSID_BB_SEL(void * cmd,u32 value)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 
FWCMD_SET_ADDR_BSSID_BSS_COLOR(void * cmd,u32 value)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 
FWCMD_SET_ADDR_BSSID_BSSID0(void * cmd,u32 value)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 
FWCMD_SET_ADDR_BSSID_BSSID1(void * cmd,u32 value)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 
FWCMD_SET_ADDR_BSSID_BSSID2(void * cmd,u32 value)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 
FWCMD_SET_ADDR_BSSID_BSSID3(void * cmd,u32 value)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 
FWCMD_SET_ADDR_BSSID_BSSID4(void * cmd,u32 value)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 
FWCMD_SET_ADDR_BSSID_BSSID5(void * cmd,u32 value)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 void rtw89_cam_fill_dctl_sec_cam_info_v1(struct rtw89_dev *rtwdev,
359 					 struct rtw89_vif *rtwvif,
360 					 struct rtw89_sta *rtwsta,
361 					 u8 *cmd);
362 int rtw89_cam_fill_bssid_cam_info(struct rtw89_dev *rtwdev,
363 				  struct rtw89_vif *vif, u8 *cmd);
364 int rtw89_cam_sec_key_add(struct rtw89_dev *rtwdev,
365 			  struct ieee80211_vif *vif,
366 			  struct ieee80211_sta *sta,
367 			  struct ieee80211_key_conf *key);
368 int rtw89_cam_sec_key_del(struct rtw89_dev *rtwdev,
369 			  struct ieee80211_vif *vif,
370 			  struct ieee80211_sta *sta,
371 			  struct ieee80211_key_conf *key,
372 			  bool inform_fw);
373 void rtw89_cam_bssid_changed(struct rtw89_dev *rtwdev,
374 			     struct rtw89_vif *rtwvif);
375 void rtw89_cam_reset_keys(struct rtw89_dev *rtwdev);
376 #endif
377