dp_txrx_wds.h 14 KB

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