1 /* 2 * Copyright (c) 2016-2021 The Linux Foundation. All rights reserved. 3 * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved. 4 * 5 * Permission to use, copy, modify, and/or distribute this software for 6 * any purpose with or without fee is hereby granted, provided that the 7 * above copyright notice and this permission notice appear in all 8 * copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 #ifndef _DP_TXRX_WDS_H_ 21 #define _DP_TXRX_WDS_H_ 22 23 #ifdef WIFI_MONITOR_SUPPORT 24 #include "dp_htt.h" 25 #include "dp_mon.h" 26 #endif 27 28 /* host managed flag */ 29 #define DP_AST_FLAGS_HM 0x0020 30 31 /* WDS AST entry aging timer value */ 32 #define DP_WDS_AST_AGING_TIMER_DEFAULT_MS 120000 33 #define DP_WDS_AST_AGING_TIMER_CNT \ 34 ((DP_WDS_AST_AGING_TIMER_DEFAULT_MS / DP_AST_AGING_TIMER_DEFAULT_MS) - 1) 35 36 /** 37 * dp_soc_wds_attach() - Setup WDS timer and AST table 38 * @soc: Datapath SOC handle 39 * 40 * Return: None 41 */ 42 void dp_soc_wds_attach(struct dp_soc *soc); 43 44 /** 45 * dp_soc_wds_detach() - Detach WDS data structures and timers 46 * @soc: DP SOC handle 47 * 48 * Return: None 49 */ 50 void dp_soc_wds_detach(struct dp_soc *soc); 51 #ifdef QCA_PEER_MULTIQ_SUPPORT 52 /** 53 * dp_peer_find_ast_index_by_flowq_id() - API to get ast idx for a given flowid 54 * @soc: soc handle 55 * @vdev_id: vdev ID 56 * @peer_mac_addr: mac address of the peer 57 * @flow_id: flow id to find ast index 58 * @tid: TID 59 * 60 * Return: ast index for a given flow id, -1 for fail cases 61 */ 62 int dp_peer_find_ast_index_by_flowq_id(struct cdp_soc_t *soc, 63 uint16_t vdev_id, uint8_t *peer_mac_addr, 64 uint8_t flow_id, uint8_t tid); 65 #endif 66 67 /** 68 * dp_rx_da_learn() - Add AST entry based on DA lookup 69 * This is a WAR for HK 1.0 and will 70 * be removed in HK 2.0 71 * 72 * @soc: core txrx main context 73 * @rx_tlv_hdr: start address of rx tlvs 74 * @ta_peer: Transmitter peer entry 75 * @nbuf: nbuf to retrieve destination mac for which AST will be added 76 * 77 */ 78 void 79 dp_rx_da_learn(struct dp_soc *soc, 80 uint8_t *rx_tlv_hdr, 81 struct dp_txrx_peer *ta_peer, 82 qdf_nbuf_t nbuf); 83 84 /** 85 * dp_tx_mec_handler() - Tx MEC Notify Handler 86 * @vdev: pointer to dp dev handler 87 * @status : Tx completion status from HTT descriptor 88 * 89 * Handles MEC notify event sent from fw to Host 90 * 91 * Return: none 92 */ 93 void dp_tx_mec_handler(struct dp_vdev *vdev, uint8_t *status); 94 #ifdef FEATURE_WDS 95 #ifdef FEATURE_MCL_REPEATER 96 static inline bool dp_tx_da_search_override(struct dp_vdev *vdev) 97 { 98 if (vdev->mec_enabled) 99 return true; 100 101 return false; 102 } 103 #else 104 static inline bool dp_tx_da_search_override(struct dp_vdev *vdev) 105 { 106 struct dp_soc *soc = vdev->pdev->soc; 107 108 /* 109 * If AST index override support is available (HKv2 etc), 110 * DA search flag be enabled always 111 * 112 * If AST index override support is not available (HKv1), 113 * DA search flag should be used for all modes except QWRAP 114 */ 115 if (soc->ast_override_support || !vdev->proxysta_vdev) 116 return true; 117 118 return false; 119 } 120 #endif /* FEATURE_MCL_REPEATER */ 121 #endif /* FEATURE_WDS */ 122 #ifdef WDS_VENDOR_EXTENSION 123 124 /** 125 * dp_txrx_peer_wds_tx_policy_update() - API to set tx wds policy 126 * 127 * @soc: DP soc handle 128 * @vdev_id: id of vdev handle 129 * @peer_mac: peer mac address 130 * @wds_tx_ucast: policy for unicast transmission 131 * @wds_tx_mcast: policy for multicast transmission 132 * 133 * Return: void 134 */ 135 QDF_STATUS 136 dp_txrx_peer_wds_tx_policy_update(struct cdp_soc_t *soc, uint8_t vdev_id, 137 uint8_t *peer_mac, int wds_tx_ucast, 138 int wds_tx_mcast); 139 140 /** 141 * dp_txrx_set_wds_rx_policy() - API to store datapath 142 * config parameters 143 * @soc_hdl: datapath soc handle 144 * @vdev_id: id of datapath vdev handle 145 * @val: WDS rx policy value 146 * 147 * Return: status 148 */ 149 QDF_STATUS 150 dp_txrx_set_wds_rx_policy(struct cdp_soc_t *soc_hdl, uint8_t vdev_id, 151 u_int32_t val); 152 #endif 153 154 /** 155 * dp_hmwds_ast_add_notify() - schedules hmwds ast add status work 156 * @peer: DP peer 157 * @mac_addr: ast mac addr 158 * @type: ast type 159 * @err: QDF_STATUS error code 160 * @is_peer_map: notify is from peer map 161 * 162 * Return: void 163 */ 164 void dp_hmwds_ast_add_notify(struct dp_peer *peer, 165 uint8_t *mac_addr, 166 enum cdp_txrx_ast_entry_type type, 167 QDF_STATUS err, 168 bool is_peer_map); 169 170 #ifdef QCA_SUPPORT_WDS_EXTENDED 171 /** 172 * dp_wds_ext_peer_learn() - function to send event to control 173 * path on receiving 1st 4-address frame from backhaul. 174 * @soc: DP soc 175 * @ta_peer: WDS repeater peer 176 * 177 * Return: void 178 */ 179 static inline void dp_wds_ext_peer_learn(struct dp_soc *soc, 180 struct dp_peer *ta_peer) 181 { 182 uint8_t wds_ext_src_mac[QDF_MAC_ADDR_SIZE]; 183 184 if (ta_peer->vdev->wds_ext_enabled && 185 !qdf_atomic_test_and_set_bit(WDS_EXT_PEER_INIT_BIT, 186 &ta_peer->txrx_peer->wds_ext.init)) { 187 qdf_mem_copy(wds_ext_src_mac, &ta_peer->mac_addr.raw[0], 188 QDF_MAC_ADDR_SIZE); 189 soc->cdp_soc.ol_ops->rx_wds_ext_peer_learn( 190 soc->ctrl_psoc, 191 ta_peer->peer_id, 192 ta_peer->vdev->vdev_id, 193 wds_ext_src_mac); 194 } 195 } 196 #else 197 static inline void dp_wds_ext_peer_learn(struct dp_soc *soc, 198 struct dp_peer *ta_peer) 199 { 200 } 201 #endif 202 203 /** 204 * dp_rx_wds_add_or_update_ast() - Add or update the ast entry. 205 * 206 * @soc: core txrx main context 207 * @ta_peer: WDS repeater txrx peer 208 * @nbuf: network buffer 209 * @is_ad4_valid: 4-address valid flag 210 * @is_sa_valid: source address valid flag 211 * @is_chfrag_start: frag start flag 212 * @sa_idx: source-address index for peer 213 * @sa_sw_peer_id: software source-address peer-id 214 * 215 * Return: void: 216 */ 217 static inline void 218 dp_rx_wds_add_or_update_ast(struct dp_soc *soc, 219 struct dp_txrx_peer *ta_peer, 220 qdf_nbuf_t nbuf, uint8_t is_ad4_valid, 221 uint8_t is_sa_valid, uint8_t is_chfrag_start, 222 uint16_t sa_idx, uint16_t sa_sw_peer_id) 223 { 224 struct dp_peer *sa_peer; 225 struct dp_ast_entry *ast; 226 uint32_t flags = DP_AST_FLAGS_HM; 227 struct dp_pdev *pdev = ta_peer->vdev->pdev; 228 uint8_t wds_src_mac[QDF_MAC_ADDR_SIZE]; 229 struct dp_peer *ta_base_peer; 230 231 232 if (!(is_chfrag_start && is_ad4_valid)) 233 return; 234 235 if (qdf_unlikely(!is_sa_valid)) { 236 qdf_mem_copy(wds_src_mac, 237 (qdf_nbuf_data(nbuf) + QDF_MAC_ADDR_SIZE), 238 QDF_MAC_ADDR_SIZE); 239 240 ta_base_peer = dp_peer_get_ref_by_id(soc, ta_peer->peer_id, 241 DP_MOD_ID_RX); 242 if (ta_base_peer) { 243 if (ta_peer->vdev->opmode == wlan_op_mode_ap) 244 dp_wds_ext_peer_learn(soc, ta_base_peer); 245 246 dp_peer_add_ast(soc, ta_base_peer, wds_src_mac, 247 CDP_TXRX_AST_TYPE_WDS, flags); 248 249 dp_peer_unref_delete(ta_base_peer, DP_MOD_ID_RX); 250 } 251 return; 252 } 253 254 qdf_spin_lock_bh(&soc->ast_lock); 255 ast = soc->ast_table[sa_idx]; 256 257 if (!ast) { 258 qdf_spin_unlock_bh(&soc->ast_lock); 259 /* 260 * In HKv1, it is possible that HW retains the AST entry in 261 * GSE cache on 1 radio , even after the AST entry is deleted 262 * (on another radio). 263 * 264 * Due to this, host might still get sa_is_valid indications 265 * for frames with SA not really present in AST table. 266 * 267 * So we go ahead and send an add_ast command to FW in such 268 * cases where sa is reported still as valid, so that FW will 269 * invalidate this GSE cache entry and new AST entry gets 270 * cached. 271 */ 272 if (!soc->ast_override_support) { 273 qdf_mem_copy(wds_src_mac, 274 (qdf_nbuf_data(nbuf) + QDF_MAC_ADDR_SIZE), 275 QDF_MAC_ADDR_SIZE); 276 277 ta_base_peer = dp_peer_get_ref_by_id(soc, 278 ta_peer->peer_id, 279 DP_MOD_ID_RX); 280 281 if (ta_base_peer) { 282 dp_peer_add_ast(soc, ta_base_peer, 283 wds_src_mac, 284 CDP_TXRX_AST_TYPE_WDS, 285 flags); 286 287 dp_peer_unref_delete(ta_base_peer, 288 DP_MOD_ID_RX); 289 } 290 return; 291 } else { 292 /* In HKv2 smart monitor case, when NAC client is 293 * added first and this client roams within BSS to 294 * connect to RE, since we have an AST entry for 295 * NAC we get sa_is_valid bit set. So we check if 296 * smart monitor is enabled and send add_ast command 297 * to FW. 298 */ 299 ta_base_peer = dp_peer_get_ref_by_id(soc, 300 ta_peer->peer_id, 301 DP_MOD_ID_RX); 302 if (ta_base_peer) { 303 dp_monitor_neighbour_peer_add_ast(pdev, 304 ta_base_peer, 305 wds_src_mac, 306 nbuf, 307 flags); 308 dp_peer_unref_delete(ta_base_peer, 309 DP_MOD_ID_RX); 310 } 311 return; 312 } 313 } 314 315 /* 316 * Ensure we are updating the right AST entry by 317 * validating ast_idx. 318 * There is a possibility we might arrive here without 319 * AST MAP event , so this check is mandatory 320 */ 321 if (ast->is_mapped && (ast->ast_idx == sa_idx)) 322 ast->is_active = TRUE; 323 324 if (ast->peer_id != ta_peer->peer_id) { 325 if ((ast->type == CDP_TXRX_AST_TYPE_WDS_HM) || 326 (ast->type == CDP_TXRX_AST_TYPE_WDS_HM_SEC)) { 327 qdf_spin_unlock_bh(&soc->ast_lock); 328 return; 329 } 330 331 if ((ast->type != CDP_TXRX_AST_TYPE_STATIC) && 332 (ast->type != CDP_TXRX_AST_TYPE_SELF) && 333 (ast->type != CDP_TXRX_AST_TYPE_STA_BSS)) { 334 if (ast->pdev_id != ta_peer->vdev->pdev->pdev_id) { 335 /* This case is when a STA roams from one 336 * repeater to another repeater, but these 337 * repeaters are connected to root AP on 338 * different radios. 339 * Ex: rptr1 connected to ROOT AP over 5G 340 * and rptr2 connected to ROOT AP over 2G 341 * radio 342 */ 343 dp_peer_del_ast(soc, ast); 344 } else { 345 /* this case is when a STA roams from one 346 * reapter to another repeater, but inside 347 * same radio. 348 */ 349 /* For HKv2 do not update the AST entry if 350 * new ta_peer is on STA vap as SRC port 351 * learning is disable on STA vap 352 */ 353 if (soc->ast_override_support && 354 (ta_peer->vdev->opmode == wlan_op_mode_sta)) { 355 dp_peer_del_ast(soc, ast); 356 } else { 357 ta_base_peer = 358 dp_peer_get_ref_by_id(soc, 359 ta_peer->peer_id, 360 DP_MOD_ID_RX); 361 if (ta_base_peer) { 362 dp_wds_ext_peer_learn(soc, 363 ta_base_peer); 364 dp_peer_update_ast(soc, 365 ta_base_peer, 366 ast, flags); 367 368 dp_peer_unref_delete(ta_base_peer, 369 DP_MOD_ID_RX); 370 } 371 } 372 qdf_spin_unlock_bh(&soc->ast_lock); 373 return; 374 } 375 } 376 /* 377 * Do not kickout STA if it belongs to a different radio. 378 * For DBDC repeater, it is possible to arrive here 379 * for multicast loopback frames originated from connected 380 * clients and looped back (intrabss) by Root AP 381 */ 382 if (ast->pdev_id != ta_peer->vdev->pdev->pdev_id) { 383 qdf_spin_unlock_bh(&soc->ast_lock); 384 return; 385 } 386 387 qdf_spin_unlock_bh(&soc->ast_lock); 388 /* 389 * Kickout, when direct associated peer(SA) roams 390 * to another AP and reachable via TA peer 391 */ 392 sa_peer = dp_peer_get_ref_by_id(soc, ast->peer_id, 393 DP_MOD_ID_RX); 394 if (!sa_peer) 395 return; 396 397 if ((sa_peer->vdev->opmode == wlan_op_mode_ap) && 398 !sa_peer->delete_in_progress) { 399 qdf_mem_copy(wds_src_mac, 400 (qdf_nbuf_data(nbuf) + QDF_MAC_ADDR_SIZE), 401 QDF_MAC_ADDR_SIZE); 402 sa_peer->delete_in_progress = true; 403 if (soc->cdp_soc.ol_ops->peer_sta_kickout) { 404 soc->cdp_soc.ol_ops->peer_sta_kickout( 405 soc->ctrl_psoc, 406 sa_peer->vdev->pdev->pdev_id, 407 wds_src_mac); 408 } 409 } 410 dp_peer_unref_delete(sa_peer, DP_MOD_ID_RX); 411 return; 412 } 413 414 qdf_spin_unlock_bh(&soc->ast_lock); 415 } 416 417 /** 418 * dp_rx_wds_srcport_learn() - Add or update the STA PEER which 419 * is behind the WDS repeater. 420 * @soc: core txrx main context 421 * @rx_tlv_hdr: base address of RX TLV header 422 * @ta_peer: WDS repeater peer 423 * @nbuf: rx pkt 424 * @msdu_end_info: 425 * 426 * Return: void: 427 */ 428 static inline void 429 dp_rx_wds_srcport_learn(struct dp_soc *soc, 430 uint8_t *rx_tlv_hdr, 431 struct dp_txrx_peer *ta_peer, 432 qdf_nbuf_t nbuf, 433 struct hal_rx_msdu_metadata msdu_end_info) 434 { 435 uint8_t sa_is_valid = qdf_nbuf_is_sa_valid(nbuf); 436 uint8_t is_chfrag_start = 0; 437 uint8_t is_ad4_valid = 0; 438 439 if (qdf_unlikely(!ta_peer)) 440 return; 441 442 is_chfrag_start = qdf_nbuf_is_rx_chfrag_start(nbuf); 443 if (is_chfrag_start) 444 is_ad4_valid = hal_rx_get_mpdu_mac_ad4_valid(soc->hal_soc, rx_tlv_hdr); 445 446 447 /* 448 * Get the AST entry from HW SA index and mark it as active 449 */ 450 dp_rx_wds_add_or_update_ast(soc, ta_peer, nbuf, is_ad4_valid, 451 sa_is_valid, is_chfrag_start, 452 msdu_end_info.sa_idx, msdu_end_info.sa_sw_peer_id); 453 } 454 455 #ifdef IPA_WDS_EASYMESH_FEATURE 456 /** 457 * dp_rx_ipa_wds_srcport_learn() - Add or update the STA PEER which 458 * is behind the WDS repeater. 459 * 460 * @soc: core txrx main context 461 * @ta_peer: WDS repeater peer 462 * @nbuf: rx pkt 463 * @msdu_end_info: msdu end info 464 * @ad4_valid: address4 valid bit 465 * @chfrag_start: Msdu start bit 466 * 467 * Return: void 468 */ 469 static inline void 470 dp_rx_ipa_wds_srcport_learn(struct dp_soc *soc, 471 struct dp_peer *ta_peer, qdf_nbuf_t nbuf, 472 struct hal_rx_msdu_metadata msdu_end_info, 473 bool ad4_valid, bool chfrag_start) 474 { 475 uint8_t sa_is_valid = qdf_nbuf_is_sa_valid(nbuf); 476 uint8_t is_chfrag_start = (uint8_t)chfrag_start; 477 uint8_t is_ad4_valid = (uint8_t)ad4_valid; 478 struct dp_txrx_peer *peer = (struct dp_txrx_peer *)ta_peer; 479 480 if (qdf_unlikely(!ta_peer)) 481 return; 482 483 /* 484 * Get the AST entry from HW SA index and mark it as active 485 */ 486 dp_rx_wds_add_or_update_ast(soc, peer, nbuf, is_ad4_valid, 487 sa_is_valid, is_chfrag_start, 488 msdu_end_info.sa_idx, 489 msdu_end_info.sa_sw_peer_id); 490 } 491 #endif 492 493 /** 494 * dp_rx_ast_set_active() - set the active flag of the astentry 495 * corresponding to a hw index. 496 * @soc: core txrx main context 497 * @sa_idx: hw idx 498 * @is_active: active flag 499 * 500 */ 501 static inline QDF_STATUS dp_rx_ast_set_active(struct dp_soc *soc, 502 uint16_t sa_idx, bool is_active) 503 { 504 struct dp_ast_entry *ast; 505 506 qdf_spin_lock_bh(&soc->ast_lock); 507 ast = soc->ast_table[sa_idx]; 508 509 if (!ast) { 510 qdf_spin_unlock_bh(&soc->ast_lock); 511 return QDF_STATUS_E_NULL_VALUE; 512 } 513 514 if (!ast->is_mapped) { 515 qdf_spin_unlock_bh(&soc->ast_lock); 516 return QDF_STATUS_E_INVAL; 517 } 518 519 /* 520 * Ensure we are updating the right AST entry by 521 * validating ast_idx. 522 * There is a possibility we might arrive here without 523 * AST MAP event , so this check is mandatory 524 */ 525 if (ast->ast_idx == sa_idx) { 526 ast->is_active = is_active; 527 qdf_spin_unlock_bh(&soc->ast_lock); 528 return QDF_STATUS_SUCCESS; 529 } 530 531 qdf_spin_unlock_bh(&soc->ast_lock); 532 return QDF_STATUS_E_FAILURE; 533 } 534 #endif /* DP_TXRX_WDS*/ 535