dp_txrx_wds.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. /*
  2. * Copyright (c) 2016-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2021-2022 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. void dp_soc_wds_attach(struct dp_soc *soc);
  32. void dp_soc_wds_detach(struct dp_soc *soc);
  33. #ifdef QCA_PEER_MULTIQ_SUPPORT
  34. int dp_peer_find_ast_index_by_flowq_id(struct cdp_soc_t *soc,
  35. uint16_t vdev_id, uint8_t *peer_mac_addr,
  36. uint8_t flow_id, uint8_t tid);
  37. #endif
  38. void
  39. dp_rx_da_learn(struct dp_soc *soc,
  40. uint8_t *rx_tlv_hdr,
  41. struct dp_txrx_peer *ta_peer,
  42. qdf_nbuf_t nbuf);
  43. void dp_tx_mec_handler(struct dp_vdev *vdev, uint8_t *status);
  44. #ifdef FEATURE_WDS
  45. #ifdef FEATURE_MCL_REPEATER
  46. static inline bool dp_tx_da_search_override(struct dp_vdev *vdev)
  47. {
  48. if (vdev->mec_enabled)
  49. return true;
  50. return false;
  51. }
  52. #else
  53. static inline bool dp_tx_da_search_override(struct dp_vdev *vdev)
  54. {
  55. struct dp_soc *soc = vdev->pdev->soc;
  56. /*
  57. * If AST index override support is available (HKv2 etc),
  58. * DA search flag be enabled always
  59. *
  60. * If AST index override support is not available (HKv1),
  61. * DA search flag should be used for all modes except QWRAP
  62. */
  63. if (soc->ast_override_support || !vdev->proxysta_vdev)
  64. return true;
  65. return false;
  66. }
  67. #endif /* FEATURE_MCL_REPEATER */
  68. #endif /* FEATURE_WDS */
  69. #ifdef WDS_VENDOR_EXTENSION
  70. QDF_STATUS
  71. dp_txrx_peer_wds_tx_policy_update(struct cdp_soc_t *cdp_soc, uint8_t vdev_id,
  72. uint8_t *peer_mac, int wds_tx_ucast,
  73. int wds_tx_mcast);
  74. QDF_STATUS
  75. dp_txrx_set_wds_rx_policy(struct cdp_soc_t *cdp_soc, uint8_t vdev_id,
  76. u_int32_t val);
  77. #endif
  78. /**
  79. * dp_hmwds_ast_add_notify() - schedules hmwds ast add status work
  80. * @peer: DP peer
  81. * @mac_addr: ast mac addr
  82. * @type: ast type
  83. * @err: QDF_STATUS error code
  84. * @is_peer_map: notify is from peer map
  85. *
  86. * Return: void
  87. */
  88. void dp_hmwds_ast_add_notify(struct dp_peer *peer,
  89. uint8_t *mac_addr,
  90. enum cdp_txrx_ast_entry_type type,
  91. QDF_STATUS err,
  92. bool is_peer_map);
  93. #ifdef QCA_SUPPORT_WDS_EXTENDED
  94. /**
  95. * dp_wds_ext_peer_learn() - function to send event to control
  96. * path on receiving 1st 4-address frame from backhaul.
  97. * @soc: DP soc
  98. * @ta_peer: WDS repeater peer
  99. *
  100. * Return: void
  101. */
  102. static inline void dp_wds_ext_peer_learn(struct dp_soc *soc,
  103. struct dp_peer *ta_peer)
  104. {
  105. uint8_t wds_ext_src_mac[QDF_MAC_ADDR_SIZE];
  106. if (ta_peer->vdev->wds_ext_enabled &&
  107. !qdf_atomic_test_and_set_bit(WDS_EXT_PEER_INIT_BIT,
  108. &ta_peer->txrx_peer->wds_ext.init)) {
  109. qdf_mem_copy(wds_ext_src_mac, &ta_peer->mac_addr.raw[0],
  110. QDF_MAC_ADDR_SIZE);
  111. soc->cdp_soc.ol_ops->rx_wds_ext_peer_learn(
  112. soc->ctrl_psoc,
  113. ta_peer->peer_id,
  114. ta_peer->vdev->vdev_id,
  115. wds_ext_src_mac);
  116. }
  117. }
  118. #else
  119. static inline void dp_wds_ext_peer_learn(struct dp_soc *soc,
  120. struct dp_peer *ta_peer)
  121. {
  122. }
  123. #endif
  124. /**
  125. * dp_rx_wds_add_or_update_ast() - Add or update the ast entry.
  126. *
  127. * @soc: core txrx main context
  128. * @ta_txrx_peer: WDS repeater txrx peer
  129. * @mac_addr: mac address of the peer
  130. * @is_ad4_valid: 4-address valid flag
  131. * @is_sa_valid: source address valid flag
  132. * @is_chfrag_start: frag start flag
  133. * @sa_idx: source-address index for peer
  134. * @sa_sw_peer_id: software source-address peer-id
  135. *
  136. * Return: void:
  137. */
  138. static inline void
  139. dp_rx_wds_add_or_update_ast(struct dp_soc *soc,
  140. struct dp_txrx_peer *ta_peer,
  141. qdf_nbuf_t nbuf, uint8_t is_ad4_valid,
  142. uint8_t is_sa_valid, uint8_t is_chfrag_start,
  143. uint16_t sa_idx, uint16_t sa_sw_peer_id)
  144. {
  145. struct dp_peer *sa_peer;
  146. struct dp_ast_entry *ast;
  147. uint32_t flags = DP_AST_FLAGS_HM;
  148. uint32_t ret = 0;
  149. struct dp_pdev *pdev = ta_peer->vdev->pdev;
  150. uint8_t wds_src_mac[QDF_MAC_ADDR_SIZE];
  151. struct dp_peer *ta_base_peer;
  152. if (!(is_chfrag_start && is_ad4_valid))
  153. return;
  154. if (qdf_unlikely(!is_sa_valid)) {
  155. qdf_mem_copy(wds_src_mac,
  156. (qdf_nbuf_data(nbuf) + QDF_MAC_ADDR_SIZE),
  157. QDF_MAC_ADDR_SIZE);
  158. ta_base_peer = dp_peer_get_ref_by_id(soc, ta_peer->peer_id,
  159. DP_MOD_ID_RX);
  160. if (ta_base_peer) {
  161. dp_wds_ext_peer_learn(soc, ta_base_peer);
  162. ret = dp_peer_add_ast(soc, ta_base_peer, wds_src_mac,
  163. CDP_TXRX_AST_TYPE_WDS, flags);
  164. dp_peer_unref_delete(ta_base_peer, DP_MOD_ID_RX);
  165. }
  166. return;
  167. }
  168. qdf_spin_lock_bh(&soc->ast_lock);
  169. ast = soc->ast_table[sa_idx];
  170. if (!ast) {
  171. qdf_spin_unlock_bh(&soc->ast_lock);
  172. /*
  173. * In HKv1, it is possible that HW retains the AST entry in
  174. * GSE cache on 1 radio , even after the AST entry is deleted
  175. * (on another radio).
  176. *
  177. * Due to this, host might still get sa_is_valid indications
  178. * for frames with SA not really present in AST table.
  179. *
  180. * So we go ahead and send an add_ast command to FW in such
  181. * cases where sa is reported still as valid, so that FW will
  182. * invalidate this GSE cache entry and new AST entry gets
  183. * cached.
  184. */
  185. if (!soc->ast_override_support) {
  186. qdf_mem_copy(wds_src_mac,
  187. (qdf_nbuf_data(nbuf) + QDF_MAC_ADDR_SIZE),
  188. QDF_MAC_ADDR_SIZE);
  189. ta_base_peer = dp_peer_get_ref_by_id(soc,
  190. ta_peer->peer_id,
  191. DP_MOD_ID_RX);
  192. if (ta_base_peer) {
  193. ret = dp_peer_add_ast(soc, ta_base_peer,
  194. wds_src_mac,
  195. CDP_TXRX_AST_TYPE_WDS,
  196. flags);
  197. dp_peer_unref_delete(ta_base_peer,
  198. DP_MOD_ID_RX);
  199. }
  200. return;
  201. } else {
  202. /* In HKv2 smart monitor case, when NAC client is
  203. * added first and this client roams within BSS to
  204. * connect to RE, since we have an AST entry for
  205. * NAC we get sa_is_valid bit set. So we check if
  206. * smart monitor is enabled and send add_ast command
  207. * to FW.
  208. */
  209. ta_base_peer = dp_peer_get_ref_by_id(soc,
  210. ta_peer->peer_id,
  211. DP_MOD_ID_RX);
  212. if (ta_base_peer) {
  213. dp_monitor_neighbour_peer_add_ast(pdev,
  214. ta_base_peer,
  215. wds_src_mac,
  216. nbuf,
  217. flags);
  218. dp_peer_unref_delete(ta_base_peer,
  219. DP_MOD_ID_RX);
  220. }
  221. return;
  222. }
  223. }
  224. /*
  225. * Ensure we are updating the right AST entry by
  226. * validating ast_idx.
  227. * There is a possibility we might arrive here without
  228. * AST MAP event , so this check is mandatory
  229. */
  230. if (ast->is_mapped && (ast->ast_idx == sa_idx))
  231. ast->is_active = TRUE;
  232. if (ast->peer_id != ta_peer->peer_id) {
  233. if ((ast->type == CDP_TXRX_AST_TYPE_WDS_HM) ||
  234. (ast->type == CDP_TXRX_AST_TYPE_WDS_HM_SEC)) {
  235. qdf_spin_unlock_bh(&soc->ast_lock);
  236. return;
  237. }
  238. if ((ast->type != CDP_TXRX_AST_TYPE_STATIC) &&
  239. (ast->type != CDP_TXRX_AST_TYPE_SELF) &&
  240. (ast->type != CDP_TXRX_AST_TYPE_STA_BSS)) {
  241. if (ast->pdev_id != ta_peer->vdev->pdev->pdev_id) {
  242. /* This case is when a STA roams from one
  243. * repeater to another repeater, but these
  244. * repeaters are connected to root AP on
  245. * different radios.
  246. * Ex: rptr1 connected to ROOT AP over 5G
  247. * and rptr2 connected to ROOT AP over 2G
  248. * radio
  249. */
  250. dp_peer_del_ast(soc, ast);
  251. } else {
  252. /* this case is when a STA roams from one
  253. * reapter to another repeater, but inside
  254. * same radio.
  255. */
  256. /* For HKv2 do not update the AST entry if
  257. * new ta_peer is on STA vap as SRC port
  258. * learning is disable on STA vap
  259. */
  260. if (soc->ast_override_support &&
  261. (ta_peer->vdev->opmode == wlan_op_mode_sta)) {
  262. dp_peer_del_ast(soc, ast);
  263. } else {
  264. ta_base_peer =
  265. dp_peer_get_ref_by_id(soc,
  266. ta_peer->peer_id,
  267. DP_MOD_ID_RX);
  268. if (ta_base_peer) {
  269. dp_wds_ext_peer_learn(soc,
  270. ta_base_peer);
  271. dp_peer_update_ast(soc,
  272. ta_base_peer,
  273. ast, flags);
  274. dp_peer_unref_delete(ta_base_peer,
  275. DP_MOD_ID_RX);
  276. }
  277. }
  278. qdf_spin_unlock_bh(&soc->ast_lock);
  279. return;
  280. }
  281. }
  282. /*
  283. * Do not kickout STA if it belongs to a different radio.
  284. * For DBDC repeater, it is possible to arrive here
  285. * for multicast loopback frames originated from connected
  286. * clients and looped back (intrabss) by Root AP
  287. */
  288. if (ast->pdev_id != ta_peer->vdev->pdev->pdev_id) {
  289. qdf_spin_unlock_bh(&soc->ast_lock);
  290. return;
  291. }
  292. qdf_spin_unlock_bh(&soc->ast_lock);
  293. /*
  294. * Kickout, when direct associated peer(SA) roams
  295. * to another AP and reachable via TA peer
  296. */
  297. sa_peer = dp_peer_get_ref_by_id(soc, ast->peer_id,
  298. DP_MOD_ID_RX);
  299. if (!sa_peer)
  300. return;
  301. if ((sa_peer->vdev->opmode == wlan_op_mode_ap) &&
  302. !sa_peer->delete_in_progress) {
  303. qdf_mem_copy(wds_src_mac,
  304. (qdf_nbuf_data(nbuf) + QDF_MAC_ADDR_SIZE),
  305. QDF_MAC_ADDR_SIZE);
  306. sa_peer->delete_in_progress = true;
  307. if (soc->cdp_soc.ol_ops->peer_sta_kickout) {
  308. soc->cdp_soc.ol_ops->peer_sta_kickout(
  309. soc->ctrl_psoc,
  310. sa_peer->vdev->pdev->pdev_id,
  311. wds_src_mac);
  312. }
  313. }
  314. dp_peer_unref_delete(sa_peer, DP_MOD_ID_RX);
  315. return;
  316. }
  317. qdf_spin_unlock_bh(&soc->ast_lock);
  318. }
  319. /**
  320. * dp_rx_wds_srcport_learn() - Add or update the STA PEER which
  321. * is behind the WDS repeater.
  322. *
  323. * @soc: core txrx main context
  324. * @rx_tlv_hdr: base address of RX TLV header
  325. * @ta_peer: WDS repeater peer
  326. * @nbuf: rx pkt
  327. *
  328. * Return: void:
  329. */
  330. static inline void
  331. dp_rx_wds_srcport_learn(struct dp_soc *soc,
  332. uint8_t *rx_tlv_hdr,
  333. struct dp_txrx_peer *ta_peer,
  334. qdf_nbuf_t nbuf,
  335. struct hal_rx_msdu_metadata msdu_end_info)
  336. {
  337. uint8_t sa_is_valid = qdf_nbuf_is_sa_valid(nbuf);
  338. uint8_t is_chfrag_start = 0;
  339. uint8_t is_ad4_valid = 0;
  340. if (qdf_unlikely(!ta_peer))
  341. return;
  342. is_chfrag_start = qdf_nbuf_is_rx_chfrag_start(nbuf);
  343. if (is_chfrag_start)
  344. is_ad4_valid = hal_rx_get_mpdu_mac_ad4_valid(soc->hal_soc, rx_tlv_hdr);
  345. /*
  346. * Get the AST entry from HW SA index and mark it as active
  347. */
  348. dp_rx_wds_add_or_update_ast(soc, ta_peer, nbuf, is_ad4_valid,
  349. sa_is_valid, is_chfrag_start,
  350. msdu_end_info.sa_idx, msdu_end_info.sa_sw_peer_id);
  351. }
  352. /*
  353. * dp_rx_ast_set_active() - set the active flag of the astentry
  354. * corresponding to a hw index.
  355. * @soc: core txrx main context
  356. * @sa_idx: hw idx
  357. * @is_active: active flag
  358. *
  359. */
  360. static inline QDF_STATUS dp_rx_ast_set_active(struct dp_soc *soc,
  361. uint16_t sa_idx, bool is_active)
  362. {
  363. struct dp_ast_entry *ast;
  364. qdf_spin_lock_bh(&soc->ast_lock);
  365. ast = soc->ast_table[sa_idx];
  366. if (!ast) {
  367. qdf_spin_unlock_bh(&soc->ast_lock);
  368. return QDF_STATUS_E_NULL_VALUE;
  369. }
  370. if (!ast->is_mapped) {
  371. qdf_spin_unlock_bh(&soc->ast_lock);
  372. return QDF_STATUS_E_INVAL;
  373. }
  374. /*
  375. * Ensure we are updating the right AST entry by
  376. * validating ast_idx.
  377. * There is a possibility we might arrive here without
  378. * AST MAP event , so this check is mandatory
  379. */
  380. if (ast->ast_idx == sa_idx) {
  381. ast->is_active = is_active;
  382. qdf_spin_unlock_bh(&soc->ast_lock);
  383. return QDF_STATUS_SUCCESS;
  384. }
  385. qdf_spin_unlock_bh(&soc->ast_lock);
  386. return QDF_STATUS_E_FAILURE;
  387. }
  388. #endif /* DP_TXRX_WDS*/