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 #define FWCMD_SET_ADDR_IDX(cmd, value)					\
13 	le32p_replace_bits((__le32 *)(cmd) + 1, value, GENMASK(7, 0))
14 #define FWCMD_SET_ADDR_OFFSET(cmd, value)				\
15 	le32p_replace_bits((__le32 *)(cmd) + 1, value, GENMASK(15, 8))
16 #define FWCMD_SET_ADDR_LEN(cmd, value)					\
17 	le32p_replace_bits((__le32 *)(cmd) + 1, value, GENMASK(23, 16))
18 #define FWCMD_SET_ADDR_VALID(cmd, value)				\
19 	le32p_replace_bits((__le32 *)(cmd) + 2, value, BIT(0))
20 #define FWCMD_SET_ADDR_NET_TYPE(cmd, value)				\
21 	le32p_replace_bits((__le32 *)(cmd) + 2, value, GENMASK(2, 1))
22 #define FWCMD_SET_ADDR_BCN_HIT_COND(cmd, value)				\
23 	le32p_replace_bits((__le32 *)(cmd) + 2, value, GENMASK(4, 3))
24 #define FWCMD_SET_ADDR_HIT_RULE(cmd, value)				\
25 	le32p_replace_bits((__le32 *)(cmd) + 2, value, GENMASK(6, 5))
26 #define FWCMD_SET_ADDR_BB_SEL(cmd, value)				\
27 	le32p_replace_bits((__le32 *)(cmd) + 2, value, BIT(7))
28 #define FWCMD_SET_ADDR_ADDR_MASK(cmd, value)				\
29 	le32p_replace_bits((__le32 *)(cmd) + 2, value, GENMASK(13, 8))
30 #define FWCMD_SET_ADDR_MASK_SEL(cmd, value)				\
31 	le32p_replace_bits((__le32 *)(cmd) + 2, value, GENMASK(15, 14))
32 #define FWCMD_SET_ADDR_SMA_HASH(cmd, value)				\
33 	le32p_replace_bits((__le32 *)(cmd) + 2, value, GENMASK(23, 16))
34 #define FWCMD_SET_ADDR_TMA_HASH(cmd, value)				\
35 	le32p_replace_bits((__le32 *)(cmd) + 2, value, GENMASK(31, 24))
36 #define FWCMD_SET_ADDR_BSSID_CAM_IDX(cmd, value)			\
37 	le32p_replace_bits((__le32 *)(cmd) + 3, value, GENMASK(5, 0))
38 #define FWCMD_SET_ADDR_SMA0(cmd, value)					\
39 	le32p_replace_bits((__le32 *)(cmd) + 4, value, GENMASK(7, 0))
40 #define FWCMD_SET_ADDR_SMA1(cmd, value)					\
41 	le32p_replace_bits((__le32 *)(cmd) + 4, value, GENMASK(15, 8))
42 #define FWCMD_SET_ADDR_SMA2(cmd, value)					\
43 	le32p_replace_bits((__le32 *)(cmd) + 4, value, GENMASK(23, 16))
44 #define FWCMD_SET_ADDR_SMA3(cmd, value)					\
45 	le32p_replace_bits((__le32 *)(cmd) + 4, value, GENMASK(31, 24))
46 #define FWCMD_SET_ADDR_SMA4(cmd, value)					\
47 	le32p_replace_bits((__le32 *)(cmd) + 5, value, GENMASK(7, 0))
48 #define FWCMD_SET_ADDR_SMA5(cmd, value)					\
49 	le32p_replace_bits((__le32 *)(cmd) + 5, value, GENMASK(15, 8))
50 #define FWCMD_SET_ADDR_TMA0(cmd, value)					\
51 	le32p_replace_bits((__le32 *)(cmd) + 5, value, GENMASK(23, 16))
52 #define FWCMD_SET_ADDR_TMA1(cmd, value)					\
53 	le32p_replace_bits((__le32 *)(cmd) + 5, value, GENMASK(31, 24))
54 #define FWCMD_SET_ADDR_TMA2(cmd, value)					\
55 	le32p_replace_bits((__le32 *)(cmd) + 6, value, GENMASK(7, 0))
56 #define FWCMD_SET_ADDR_TMA3(cmd, value)					\
57 	le32p_replace_bits((__le32 *)(cmd) + 6, value, GENMASK(15, 8))
58 #define FWCMD_SET_ADDR_TMA4(cmd, value)					\
59 	le32p_replace_bits((__le32 *)(cmd) + 6, value, GENMASK(23, 16))
60 #define FWCMD_SET_ADDR_TMA5(cmd, value)					\
61 	le32p_replace_bits((__le32 *)(cmd) + 6, value, GENMASK(31, 24))
62 #define FWCMD_SET_ADDR_MACID(cmd, value)				\
63 	le32p_replace_bits((__le32 *)(cmd) + 8, value, GENMASK(7, 0))
64 #define FWCMD_SET_ADDR_PORT_INT(cmd, value)				\
65 	le32p_replace_bits((__le32 *)(cmd) + 8, value, GENMASK(10, 8))
66 #define FWCMD_SET_ADDR_TSF_SYNC(cmd, value)				\
67 	le32p_replace_bits((__le32 *)(cmd) + 8, value, GENMASK(13, 11))
68 #define FWCMD_SET_ADDR_TF_TRS(cmd, value)				\
69 	le32p_replace_bits((__le32 *)(cmd) + 8, value, BIT(14))
70 #define FWCMD_SET_ADDR_LSIG_TXOP(cmd, value)				\
71 	le32p_replace_bits((__le32 *)(cmd) + 8, value, BIT(15))
72 #define FWCMD_SET_ADDR_TGT_IND(cmd, value)				\
73 	le32p_replace_bits((__le32 *)(cmd) + 8, value, GENMASK(26, 24))
74 #define FWCMD_SET_ADDR_FRM_TGT_IND(cmd, value)				\
75 	le32p_replace_bits((__le32 *)(cmd) + 8, value, GENMASK(29, 27))
76 #define FWCMD_SET_ADDR_AID12(cmd, value)				\
77 	le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(11, 0))
78 #define FWCMD_SET_ADDR_AID12_0(cmd, value)				\
79 	le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(7, 0))
80 #define FWCMD_SET_ADDR_AID12_1(cmd, value)				\
81 	le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(11, 8))
82 #define FWCMD_SET_ADDR_WOL_PATTERN(cmd, value)				\
83 	le32p_replace_bits((__le32 *)(cmd) + 9, value, BIT(12))
84 #define FWCMD_SET_ADDR_WOL_UC(cmd, value)				\
85 	le32p_replace_bits((__le32 *)(cmd) + 9, value, BIT(13))
86 #define FWCMD_SET_ADDR_WOL_MAGIC(cmd, value)				\
87 	le32p_replace_bits((__le32 *)(cmd) + 9, value, BIT(14))
88 #define FWCMD_SET_ADDR_WAPI(cmd, value)					\
89 	le32p_replace_bits((__le32 *)(cmd) + 9, value, BIT(15))
90 #define FWCMD_SET_ADDR_SEC_ENT_MODE(cmd, value)				\
91 	le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(17, 16))
92 #define FWCMD_SET_ADDR_SEC_ENT0_KEYID(cmd, value)			\
93 	le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(19, 18))
94 #define FWCMD_SET_ADDR_SEC_ENT1_KEYID(cmd, value)			\
95 	le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(21, 20))
96 #define FWCMD_SET_ADDR_SEC_ENT2_KEYID(cmd, value)			\
97 	le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(23, 22))
98 #define FWCMD_SET_ADDR_SEC_ENT3_KEYID(cmd, value)			\
99 	le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(25, 24))
100 #define FWCMD_SET_ADDR_SEC_ENT4_KEYID(cmd, value)			\
101 	le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(27, 26))
102 #define FWCMD_SET_ADDR_SEC_ENT5_KEYID(cmd, value)			\
103 	le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(29, 28))
104 #define FWCMD_SET_ADDR_SEC_ENT6_KEYID(cmd, value)			\
105 	le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(31, 30))
106 #define FWCMD_SET_ADDR_SEC_ENT_VALID(cmd, value)			\
107 	le32p_replace_bits((__le32 *)(cmd) + 10, value, GENMASK(7, 0))
108 #define FWCMD_SET_ADDR_SEC_ENT0(cmd, value)				\
109 	le32p_replace_bits((__le32 *)(cmd) + 10, value, GENMASK(15, 8))
110 #define FWCMD_SET_ADDR_SEC_ENT1(cmd, value)				\
111 	le32p_replace_bits((__le32 *)(cmd) + 10, value, GENMASK(23, 16))
112 #define FWCMD_SET_ADDR_SEC_ENT2(cmd, value)				\
113 	le32p_replace_bits((__le32 *)(cmd) + 10, value, GENMASK(31, 24))
114 #define FWCMD_SET_ADDR_SEC_ENT3(cmd, value)				\
115 	le32p_replace_bits((__le32 *)(cmd) + 11, value, GENMASK(7, 0))
116 #define FWCMD_SET_ADDR_SEC_ENT4(cmd, value)				\
117 	le32p_replace_bits((__le32 *)(cmd) + 11, value, GENMASK(15, 8))
118 #define FWCMD_SET_ADDR_SEC_ENT5(cmd, value)				\
119 	le32p_replace_bits((__le32 *)(cmd) + 11, value, GENMASK(23, 16))
120 #define FWCMD_SET_ADDR_SEC_ENT6(cmd, value)				\
121 	le32p_replace_bits((__le32 *)(cmd) + 11, value, GENMASK(31, 24))
122 #define FWCMD_SET_ADDR_BSSID_IDX(cmd, value)				\
123 	le32p_replace_bits((__le32 *)(cmd) + 12, value, GENMASK(7, 0))
124 #define FWCMD_SET_ADDR_BSSID_OFFSET(cmd, value)				\
125 	le32p_replace_bits((__le32 *)(cmd) + 12, value, GENMASK(15, 8))
126 #define FWCMD_SET_ADDR_BSSID_LEN(cmd, value)				\
127 	le32p_replace_bits((__le32 *)(cmd) + 12, value, GENMASK(23, 16))
128 #define FWCMD_SET_ADDR_BSSID_VALID(cmd, value)				\
129 	le32p_replace_bits((__le32 *)(cmd) + 13, value, BIT(0))
130 #define FWCMD_SET_ADDR_BSSID_BB_SEL(cmd, value)				\
131 	le32p_replace_bits((__le32 *)(cmd) + 13, value, BIT(1))
132 #define FWCMD_SET_ADDR_BSSID_BSS_COLOR(cmd, value)			\
133 	le32p_replace_bits((__le32 *)(cmd) + 13, value, GENMASK(13, 8))
134 #define FWCMD_SET_ADDR_BSSID_BSSID0(cmd, value)				\
135 	le32p_replace_bits((__le32 *)(cmd) + 13, value, GENMASK(23, 16))
136 #define FWCMD_SET_ADDR_BSSID_BSSID1(cmd, value)				\
137 	le32p_replace_bits((__le32 *)(cmd) + 13, value, GENMASK(31, 24))
138 #define FWCMD_SET_ADDR_BSSID_BSSID2(cmd, value)				\
139 	le32p_replace_bits((__le32 *)(cmd) + 14, value, GENMASK(7, 0))
140 #define FWCMD_SET_ADDR_BSSID_BSSID3(cmd, value)				\
141 	le32p_replace_bits((__le32 *)(cmd) + 14, value, GENMASK(15, 8))
142 #define FWCMD_SET_ADDR_BSSID_BSSID4(cmd, value)				\
143 	le32p_replace_bits((__le32 *)(cmd) + 14, value, GENMASK(23, 16))
144 #define FWCMD_SET_ADDR_BSSID_BSSID5(cmd, value)				\
145 	le32p_replace_bits((__le32 *)(cmd) + 14, value, GENMASK(31, 24))
146 
147 int rtw89_cam_init(struct rtw89_dev *rtwdev, struct rtw89_vif *vif);
148 void rtw89_cam_deinit(struct rtw89_dev *rtwdev, struct rtw89_vif *vif);
149 void rtw89_cam_fill_addr_cam_info(struct rtw89_dev *rtwdev,
150 				  struct rtw89_vif *vif, u8 *cmd);
151 int rtw89_cam_fill_bssid_cam_info(struct rtw89_dev *rtwdev,
152 				  struct rtw89_vif *vif, u8 *cmd);
153 int rtw89_cam_sec_key_add(struct rtw89_dev *rtwdev,
154 			  struct ieee80211_vif *vif,
155 			  struct ieee80211_sta *sta,
156 			  struct ieee80211_key_conf *key);
157 int rtw89_cam_sec_key_del(struct rtw89_dev *rtwdev,
158 			  struct ieee80211_vif *vif,
159 			  struct ieee80211_sta *sta,
160 			  struct ieee80211_key_conf *key,
161 			  bool inform_fw);
162 void rtw89_cam_bssid_changed(struct rtw89_dev *rtwdev,
163 			     struct rtw89_vif *rtwvif);
164 void rtw89_cam_reset_keys(struct rtw89_dev *rtwdev);
165 #endif
166