dp_txrx_wds.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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_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->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_peer: WDS repeater 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, struct dp_peer *ta_peer,
  140. qdf_nbuf_t nbuf, uint8_t is_ad4_valid,
  141. uint8_t is_sa_valid, uint8_t is_chfrag_start,
  142. uint16_t sa_idx, uint16_t sa_sw_peer_id)
  143. {
  144. struct dp_peer *sa_peer;
  145. struct dp_ast_entry *ast;
  146. uint32_t flags = DP_AST_FLAGS_HM;
  147. uint32_t ret = 0;
  148. uint8_t wds_src_mac[QDF_MAC_ADDR_SIZE];
  149. if (!(is_chfrag_start && is_ad4_valid))
  150. return;
  151. if (qdf_unlikely(!is_sa_valid)) {
  152. qdf_mem_copy(wds_src_mac,
  153. (qdf_nbuf_data(nbuf) + QDF_MAC_ADDR_SIZE),
  154. QDF_MAC_ADDR_SIZE);
  155. dp_wds_ext_peer_learn(soc, ta_peer);
  156. ret = dp_peer_add_ast(soc,
  157. ta_peer,
  158. wds_src_mac,
  159. CDP_TXRX_AST_TYPE_WDS,
  160. flags);
  161. return;
  162. }
  163. qdf_spin_lock_bh(&soc->ast_lock);
  164. ast = soc->ast_table[sa_idx];
  165. if (!ast) {
  166. qdf_spin_unlock_bh(&soc->ast_lock);
  167. /*
  168. * In HKv1, it is possible that HW retains the AST entry in
  169. * GSE cache on 1 radio , even after the AST entry is deleted
  170. * (on another radio).
  171. *
  172. * Due to this, host might still get sa_is_valid indications
  173. * for frames with SA not really present in AST table.
  174. *
  175. * So we go ahead and send an add_ast command to FW in such
  176. * cases where sa is reported still as valid, so that FW will
  177. * invalidate this GSE cache entry and new AST entry gets
  178. * cached.
  179. */
  180. if (!soc->ast_override_support) {
  181. qdf_mem_copy(wds_src_mac,
  182. (qdf_nbuf_data(nbuf) + QDF_MAC_ADDR_SIZE),
  183. QDF_MAC_ADDR_SIZE);
  184. ret = dp_peer_add_ast(soc,
  185. ta_peer,
  186. wds_src_mac,
  187. CDP_TXRX_AST_TYPE_WDS,
  188. flags);
  189. return;
  190. } else {
  191. /* In HKv2 smart monitor case, when NAC client is
  192. * added first and this client roams within BSS to
  193. * connect to RE, since we have an AST entry for
  194. * NAC we get sa_is_valid bit set. So we check if
  195. * smart monitor is enabled and send add_ast command
  196. * to FW.
  197. */
  198. dp_monitor_neighbour_peer_add_ast(ta_peer->vdev->pdev,
  199. ta_peer,
  200. wds_src_mac, nbuf,
  201. flags);
  202. return;
  203. }
  204. }
  205. /*
  206. * Ensure we are updating the right AST entry by
  207. * validating ast_idx.
  208. * There is a possibility we might arrive here without
  209. * AST MAP event , so this check is mandatory
  210. */
  211. if (ast->is_mapped && (ast->ast_idx == sa_idx))
  212. ast->is_active = TRUE;
  213. if (ast->peer_id != ta_peer->peer_id) {
  214. if ((ast->type == CDP_TXRX_AST_TYPE_WDS_HM) ||
  215. (ast->type == CDP_TXRX_AST_TYPE_WDS_HM_SEC)) {
  216. qdf_spin_unlock_bh(&soc->ast_lock);
  217. return;
  218. }
  219. if ((ast->type != CDP_TXRX_AST_TYPE_STATIC) &&
  220. (ast->type != CDP_TXRX_AST_TYPE_SELF) &&
  221. (ast->type != CDP_TXRX_AST_TYPE_STA_BSS)) {
  222. if (ast->pdev_id != ta_peer->vdev->pdev->pdev_id) {
  223. /* This case is when a STA roams from one
  224. * repeater to another repeater, but these
  225. * repeaters are connected to root AP on
  226. * different radios.
  227. * Ex: rptr1 connected to ROOT AP over 5G
  228. * and rptr2 connected to ROOT AP over 2G
  229. * radio
  230. */
  231. dp_peer_del_ast(soc, ast);
  232. } else {
  233. /* this case is when a STA roams from one
  234. * reapter to another repeater, but inside
  235. * same radio.
  236. */
  237. /* For HKv2 do not update the AST entry if
  238. * new ta_peer is on STA vap as SRC port
  239. * learning is disable on STA vap
  240. */
  241. if (soc->ast_override_support &&
  242. (ta_peer->vdev->opmode == wlan_op_mode_sta)) {
  243. dp_peer_del_ast(soc, ast);
  244. } else {
  245. dp_wds_ext_peer_learn(soc, ta_peer);
  246. dp_peer_update_ast(soc, ta_peer, ast, flags);
  247. }
  248. qdf_spin_unlock_bh(&soc->ast_lock);
  249. return;
  250. }
  251. }
  252. /*
  253. * Do not kickout STA if it belongs to a different radio.
  254. * For DBDC repeater, it is possible to arrive here
  255. * for multicast loopback frames originated from connected
  256. * clients and looped back (intrabss) by Root AP
  257. */
  258. if (ast->pdev_id != ta_peer->vdev->pdev->pdev_id) {
  259. qdf_spin_unlock_bh(&soc->ast_lock);
  260. return;
  261. }
  262. qdf_spin_unlock_bh(&soc->ast_lock);
  263. /*
  264. * Kickout, when direct associated peer(SA) roams
  265. * to another AP and reachable via TA peer
  266. */
  267. sa_peer = dp_peer_get_ref_by_id(soc, ast->peer_id,
  268. DP_MOD_ID_RX);
  269. if (!sa_peer)
  270. return;
  271. if ((sa_peer->vdev->opmode == wlan_op_mode_ap) &&
  272. !sa_peer->delete_in_progress) {
  273. qdf_mem_copy(wds_src_mac,
  274. (qdf_nbuf_data(nbuf) + QDF_MAC_ADDR_SIZE),
  275. QDF_MAC_ADDR_SIZE);
  276. sa_peer->delete_in_progress = true;
  277. if (soc->cdp_soc.ol_ops->peer_sta_kickout) {
  278. soc->cdp_soc.ol_ops->peer_sta_kickout(
  279. soc->ctrl_psoc,
  280. sa_peer->vdev->pdev->pdev_id,
  281. wds_src_mac);
  282. }
  283. }
  284. dp_peer_unref_delete(sa_peer, DP_MOD_ID_RX);
  285. return;
  286. }
  287. qdf_spin_unlock_bh(&soc->ast_lock);
  288. }
  289. /**
  290. * dp_rx_wds_srcport_learn() - Add or update the STA PEER which
  291. * is behind the WDS repeater.
  292. *
  293. * @soc: core txrx main context
  294. * @rx_tlv_hdr: base address of RX TLV header
  295. * @ta_peer: WDS repeater peer
  296. * @nbuf: rx pkt
  297. *
  298. * Return: void:
  299. */
  300. static inline void
  301. dp_rx_wds_srcport_learn(struct dp_soc *soc,
  302. uint8_t *rx_tlv_hdr,
  303. struct dp_peer *ta_peer,
  304. qdf_nbuf_t nbuf,
  305. struct hal_rx_msdu_metadata msdu_end_info)
  306. {
  307. uint8_t sa_is_valid = qdf_nbuf_is_sa_valid(nbuf);
  308. uint8_t is_chfrag_start = 0;
  309. uint8_t is_ad4_valid = 0;
  310. if (qdf_unlikely(!ta_peer))
  311. return;
  312. is_chfrag_start = qdf_nbuf_is_rx_chfrag_start(nbuf);
  313. if (is_chfrag_start)
  314. is_ad4_valid = hal_rx_get_mpdu_mac_ad4_valid(soc->hal_soc, rx_tlv_hdr);
  315. /*
  316. * Get the AST entry from HW SA index and mark it as active
  317. */
  318. dp_rx_wds_add_or_update_ast(soc, ta_peer, nbuf, is_ad4_valid,
  319. sa_is_valid, is_chfrag_start,
  320. msdu_end_info.sa_idx, msdu_end_info.sa_sw_peer_id);
  321. }
  322. /*
  323. * dp_rx_ast_set_active() - set the active flag of the astentry
  324. * corresponding to a hw index.
  325. * @soc: core txrx main context
  326. * @sa_idx: hw idx
  327. * @is_active: active flag
  328. *
  329. */
  330. static inline QDF_STATUS dp_rx_ast_set_active(struct dp_soc *soc,
  331. uint16_t sa_idx, bool is_active)
  332. {
  333. struct dp_ast_entry *ast;
  334. qdf_spin_lock_bh(&soc->ast_lock);
  335. ast = soc->ast_table[sa_idx];
  336. if (!ast) {
  337. qdf_spin_unlock_bh(&soc->ast_lock);
  338. return QDF_STATUS_E_NULL_VALUE;
  339. }
  340. if (!ast->is_mapped) {
  341. qdf_spin_unlock_bh(&soc->ast_lock);
  342. return QDF_STATUS_E_INVAL;
  343. }
  344. /*
  345. * Ensure we are updating the right AST entry by
  346. * validating ast_idx.
  347. * There is a possibility we might arrive here without
  348. * AST MAP event , so this check is mandatory
  349. */
  350. if (ast->ast_idx == sa_idx) {
  351. ast->is_active = is_active;
  352. qdf_spin_unlock_bh(&soc->ast_lock);
  353. return QDF_STATUS_SUCCESS;
  354. }
  355. qdf_spin_unlock_bh(&soc->ast_lock);
  356. return QDF_STATUS_E_FAILURE;
  357. }
  358. #endif /* DP_TXRX_WDS*/