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