dp_txrx_wds.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. /*
  2. * Copyright (c) 2016-2021 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #ifndef _DP_TXRX_WDS_H_
  19. #define _DP_TXRX_WDS_H_
  20. #ifdef WIFI_MONITOR_SUPPORT
  21. #include "dp_htt.h"
  22. #include "dp_mon.h"
  23. #endif
  24. /* host managed flag */
  25. #define DP_AST_FLAGS_HM 0x0020
  26. /* WDS AST entry aging timer value */
  27. #define DP_WDS_AST_AGING_TIMER_DEFAULT_MS 120000
  28. #define DP_WDS_AST_AGING_TIMER_CNT \
  29. ((DP_WDS_AST_AGING_TIMER_DEFAULT_MS / DP_AST_AGING_TIMER_DEFAULT_MS) - 1)
  30. void dp_soc_wds_attach(struct dp_soc *soc);
  31. void dp_soc_wds_detach(struct dp_soc *soc);
  32. #ifdef QCA_PEER_MULTIQ_SUPPORT
  33. int dp_peer_find_ast_index_by_flowq_id(struct cdp_soc_t *soc,
  34. uint16_t vdev_id, uint8_t *peer_mac_addr,
  35. uint8_t flow_id, uint8_t tid);
  36. #endif
  37. void
  38. dp_rx_da_learn(struct dp_soc *soc,
  39. uint8_t *rx_tlv_hdr,
  40. struct dp_peer *ta_peer,
  41. qdf_nbuf_t nbuf);
  42. void dp_tx_mec_handler(struct dp_vdev *vdev, uint8_t *status);
  43. #ifdef FEATURE_WDS
  44. #ifdef FEATURE_MCL_REPEATER
  45. static inline bool dp_tx_da_search_override(struct dp_vdev *vdev)
  46. {
  47. if (vdev->mec_enabled)
  48. return true;
  49. return false;
  50. }
  51. #else
  52. static inline bool dp_tx_da_search_override(struct dp_vdev *vdev)
  53. {
  54. struct dp_soc *soc = vdev->pdev->soc;
  55. /*
  56. * If AST index override support is available (HKv2 etc),
  57. * DA search flag be enabled always
  58. *
  59. * If AST index override support is not available (HKv1),
  60. * DA search flag should be used for all modes except QWRAP
  61. */
  62. if (soc->ast_override_support || !vdev->proxysta_vdev)
  63. return true;
  64. return false;
  65. }
  66. #endif /* FEATURE_MCL_REPEATER */
  67. #endif /* FEATURE_WDS */
  68. #ifdef WDS_VENDOR_EXTENSION
  69. QDF_STATUS
  70. dp_txrx_peer_wds_tx_policy_update(struct cdp_soc_t *cdp_soc, uint8_t vdev_id,
  71. uint8_t *peer_mac, int wds_tx_ucast,
  72. int wds_tx_mcast);
  73. QDF_STATUS
  74. dp_txrx_set_wds_rx_policy(struct cdp_soc_t *cdp_soc, uint8_t vdev_id,
  75. u_int32_t val);
  76. #endif
  77. /**
  78. * dp_hmwds_ast_add_notify() - schedules hmwds ast add status work
  79. * @peer: DP peer
  80. * @mac_addr: ast mac addr
  81. * @type: ast type
  82. * @err: QDF_STATUS error code
  83. * @is_peer_map: notify is from peer map
  84. *
  85. * Return: void
  86. */
  87. void dp_hmwds_ast_add_notify(struct dp_peer *peer,
  88. uint8_t *mac_addr,
  89. enum cdp_txrx_ast_entry_type type,
  90. QDF_STATUS err,
  91. bool is_peer_map);
  92. #ifdef QCA_SUPPORT_WDS_EXTENDED
  93. /**
  94. * dp_wds_ext_peer_learn() - function to send event to control
  95. * path on receiving 1st 4-address frame from backhaul.
  96. * @soc: DP soc
  97. * @ta_peer: WDS repeater peer
  98. *
  99. * Return: void
  100. */
  101. static inline void dp_wds_ext_peer_learn(struct dp_soc *soc,
  102. struct dp_peer *ta_peer)
  103. {
  104. uint8_t wds_ext_src_mac[QDF_MAC_ADDR_SIZE];
  105. if (ta_peer->vdev->wds_ext_enabled &&
  106. !qdf_atomic_test_and_set_bit(WDS_EXT_PEER_INIT_BIT,
  107. &ta_peer->wds_ext.init)) {
  108. qdf_mem_copy(wds_ext_src_mac, &ta_peer->mac_addr.raw[0],
  109. QDF_MAC_ADDR_SIZE);
  110. soc->cdp_soc.ol_ops->rx_wds_ext_peer_learn(
  111. soc->ctrl_psoc,
  112. ta_peer->peer_id,
  113. ta_peer->vdev->vdev_id,
  114. wds_ext_src_mac);
  115. }
  116. }
  117. #else
  118. static inline void dp_wds_ext_peer_learn(struct dp_soc *soc,
  119. struct dp_peer *ta_peer)
  120. {
  121. }
  122. #endif
  123. /**
  124. * dp_rx_wds_add_or_update_ast() - Add or update the ast entry.
  125. *
  126. * @soc: core txrx main context
  127. * @ta_peer: WDS repeater peer
  128. * @mac_addr: mac address of the peer
  129. * @is_ad4_valid: 4-address valid flag
  130. * @is_sa_valid: source address valid flag
  131. * @is_chfrag_start: frag start flag
  132. * @sa_idx: source-address index for peer
  133. * @sa_sw_peer_id: software source-address peer-id
  134. *
  135. * Return: void:
  136. */
  137. static inline void
  138. dp_rx_wds_add_or_update_ast(struct dp_soc *soc, struct dp_peer *ta_peer,
  139. qdf_nbuf_t nbuf, uint8_t is_ad4_valid,
  140. uint8_t is_sa_valid, uint8_t is_chfrag_start,
  141. uint16_t sa_idx, uint16_t sa_sw_peer_id)
  142. {
  143. struct dp_peer *sa_peer;
  144. struct dp_ast_entry *ast;
  145. uint32_t flags = DP_AST_FLAGS_HM;
  146. uint32_t ret = 0;
  147. struct dp_pdev *pdev = ta_peer->vdev->pdev;
  148. uint8_t wds_src_mac[QDF_MAC_ADDR_SIZE];
  149. /* For AP mode : Do wds source port learning only if it is a
  150. * 4-address mpdu
  151. *
  152. * For STA mode : Frames from RootAP backend will be in 3-address mode,
  153. * till RootAP does the WDS source port learning; Hence in repeater/STA
  154. * mode, we enable learning even in 3-address mode , to avoid RootAP
  155. * backbone getting wrongly learnt as MEC on repeater
  156. */
  157. if (ta_peer->vdev->opmode != wlan_op_mode_sta) {
  158. if (!(is_chfrag_start && is_ad4_valid))
  159. return;
  160. } else {
  161. /* For HKv2 Source port learing is not needed in STA mode
  162. * as we have support in HW
  163. *
  164. * if sa_valid bit is set there is a AST entry added on AP VAP
  165. * and this peer has roamed behind ROOT AP in this case proceed
  166. * further to check for roaming
  167. */
  168. if (soc->ast_override_support && !is_sa_valid)
  169. return;
  170. }
  171. if (qdf_unlikely(!is_sa_valid)) {
  172. qdf_mem_copy(wds_src_mac,
  173. (qdf_nbuf_data(nbuf) + QDF_MAC_ADDR_SIZE),
  174. QDF_MAC_ADDR_SIZE);
  175. dp_wds_ext_peer_learn(soc, ta_peer);
  176. ret = dp_peer_add_ast(soc,
  177. ta_peer,
  178. wds_src_mac,
  179. CDP_TXRX_AST_TYPE_WDS,
  180. flags);
  181. return;
  182. }
  183. qdf_spin_lock_bh(&soc->ast_lock);
  184. ast = soc->ast_table[sa_idx];
  185. if (!ast) {
  186. qdf_spin_unlock_bh(&soc->ast_lock);
  187. /*
  188. * In HKv1, it is possible that HW retains the AST entry in
  189. * GSE cache on 1 radio , even after the AST entry is deleted
  190. * (on another radio).
  191. *
  192. * Due to this, host might still get sa_is_valid indications
  193. * for frames with SA not really present in AST table.
  194. *
  195. * So we go ahead and send an add_ast command to FW in such
  196. * cases where sa is reported still as valid, so that FW will
  197. * invalidate this GSE cache entry and new AST entry gets
  198. * cached.
  199. */
  200. if (!soc->ast_override_support) {
  201. qdf_mem_copy(wds_src_mac,
  202. (qdf_nbuf_data(nbuf) + QDF_MAC_ADDR_SIZE),
  203. QDF_MAC_ADDR_SIZE);
  204. ret = dp_peer_add_ast(soc,
  205. ta_peer,
  206. wds_src_mac,
  207. CDP_TXRX_AST_TYPE_WDS,
  208. flags);
  209. return;
  210. } else {
  211. /* In HKv2 smart monitor case, when NAC client is
  212. * added first and this client roams within BSS to
  213. * connect to RE, since we have an AST entry for
  214. * NAC we get sa_is_valid bit set. So we check if
  215. * smart monitor is enabled and send add_ast command
  216. * to FW.
  217. */
  218. dp_monitor_neighbour_peer_add_ast(pdev, ta_peer,
  219. wds_src_mac, nbuf,
  220. flags);
  221. return;
  222. }
  223. }
  224. if ((ast->type == CDP_TXRX_AST_TYPE_WDS_HM) ||
  225. (ast->type == CDP_TXRX_AST_TYPE_WDS_HM_SEC)) {
  226. qdf_spin_unlock_bh(&soc->ast_lock);
  227. return;
  228. }
  229. /*
  230. * Ensure we are updating the right AST entry by
  231. * validating ast_idx.
  232. * There is a possibility we might arrive here without
  233. * AST MAP event , so this check is mandatory
  234. */
  235. if (ast->is_mapped && (ast->ast_idx == sa_idx))
  236. ast->is_active = TRUE;
  237. if (sa_sw_peer_id != ta_peer->peer_id) {
  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. dp_wds_ext_peer_learn(soc, ta_peer);
  265. dp_peer_update_ast(soc, ta_peer, ast, flags);
  266. }
  267. qdf_spin_unlock_bh(&soc->ast_lock);
  268. return;
  269. }
  270. }
  271. /*
  272. * Do not kickout STA if it belongs to a different radio.
  273. * For DBDC repeater, it is possible to arrive here
  274. * for multicast loopback frames originated from connected
  275. * clients and looped back (intrabss) by Root AP
  276. */
  277. if (ast->pdev_id != ta_peer->vdev->pdev->pdev_id) {
  278. qdf_spin_unlock_bh(&soc->ast_lock);
  279. return;
  280. }
  281. qdf_spin_unlock_bh(&soc->ast_lock);
  282. /*
  283. * Kickout, when direct associated peer(SA) roams
  284. * to another AP and reachable via TA peer
  285. */
  286. sa_peer = dp_peer_get_ref_by_id(soc, ast->peer_id,
  287. DP_MOD_ID_RX);
  288. if (!sa_peer)
  289. return;
  290. if ((sa_peer->vdev->opmode == wlan_op_mode_ap) &&
  291. !sa_peer->delete_in_progress) {
  292. qdf_mem_copy(wds_src_mac,
  293. (qdf_nbuf_data(nbuf) + QDF_MAC_ADDR_SIZE),
  294. QDF_MAC_ADDR_SIZE);
  295. sa_peer->delete_in_progress = true;
  296. if (soc->cdp_soc.ol_ops->peer_sta_kickout) {
  297. soc->cdp_soc.ol_ops->peer_sta_kickout(
  298. soc->ctrl_psoc,
  299. sa_peer->vdev->pdev->pdev_id,
  300. wds_src_mac);
  301. }
  302. }
  303. dp_peer_unref_delete(sa_peer, DP_MOD_ID_RX);
  304. return;
  305. }
  306. qdf_spin_unlock_bh(&soc->ast_lock);
  307. }
  308. /**
  309. * dp_rx_wds_srcport_learn() - Add or update the STA PEER which
  310. * is behind the WDS repeater.
  311. *
  312. * @soc: core txrx main context
  313. * @rx_tlv_hdr: base address of RX TLV header
  314. * @ta_peer: WDS repeater peer
  315. * @nbuf: rx pkt
  316. *
  317. * Return: void:
  318. */
  319. static inline void
  320. dp_rx_wds_srcport_learn(struct dp_soc *soc,
  321. uint8_t *rx_tlv_hdr,
  322. struct dp_peer *ta_peer,
  323. qdf_nbuf_t nbuf,
  324. struct hal_rx_msdu_metadata msdu_end_info)
  325. {
  326. uint8_t sa_is_valid = qdf_nbuf_is_sa_valid(nbuf);
  327. uint8_t is_chfrag_start = 0;
  328. uint8_t is_ad4_valid = 0;
  329. if (qdf_unlikely(!ta_peer))
  330. return;
  331. is_chfrag_start = qdf_nbuf_is_rx_chfrag_start(nbuf);
  332. if (is_chfrag_start)
  333. is_ad4_valid = hal_rx_get_mpdu_mac_ad4_valid(soc->hal_soc, rx_tlv_hdr);
  334. /*
  335. * Get the AST entry from HW SA index and mark it as active
  336. */
  337. dp_rx_wds_add_or_update_ast(soc, ta_peer, nbuf, is_ad4_valid,
  338. sa_is_valid, is_chfrag_start,
  339. msdu_end_info.sa_idx, msdu_end_info.sa_sw_peer_id);
  340. }
  341. /*
  342. * dp_rx_ast_set_active() - set the active flag of the astentry
  343. * corresponding to a hw index.
  344. * @soc: core txrx main context
  345. * @sa_idx: hw idx
  346. * @is_active: active flag
  347. *
  348. */
  349. static inline QDF_STATUS dp_rx_ast_set_active(struct dp_soc *soc,
  350. uint16_t sa_idx, bool is_active)
  351. {
  352. struct dp_ast_entry *ast;
  353. qdf_spin_lock_bh(&soc->ast_lock);
  354. ast = soc->ast_table[sa_idx];
  355. if (!ast) {
  356. qdf_spin_unlock_bh(&soc->ast_lock);
  357. return QDF_STATUS_E_NULL_VALUE;
  358. }
  359. if (!ast->is_mapped) {
  360. qdf_spin_unlock_bh(&soc->ast_lock);
  361. return QDF_STATUS_E_INVAL;
  362. }
  363. /*
  364. * Ensure we are updating the right AST entry by
  365. * validating ast_idx.
  366. * There is a possibility we might arrive here without
  367. * AST MAP event , so this check is mandatory
  368. */
  369. if (ast->ast_idx == sa_idx) {
  370. ast->is_active = is_active;
  371. qdf_spin_unlock_bh(&soc->ast_lock);
  372. return QDF_STATUS_SUCCESS;
  373. }
  374. qdf_spin_unlock_bh(&soc->ast_lock);
  375. return QDF_STATUS_E_FAILURE;
  376. }
  377. #endif /* DP_TXRX_WDS*/