dp_txrx_wds.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /*
  2. * Copyright (c) 2016-2019 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. /* WDS AST entry aging timer value */
  21. #define DP_WDS_AST_AGING_TIMER_DEFAULT_MS 120000
  22. #define DP_WDS_AST_AGING_TIMER_CNT \
  23. ((DP_WDS_AST_AGING_TIMER_DEFAULT_MS / DP_AST_AGING_TIMER_DEFAULT_MS) - 1)
  24. void dp_soc_wds_attach(struct dp_soc *soc);
  25. void dp_soc_wds_detach(struct dp_soc *soc);
  26. void
  27. dp_rx_da_learn(struct dp_soc *soc,
  28. uint8_t *rx_tlv_hdr,
  29. struct dp_peer *ta_peer,
  30. qdf_nbuf_t nbuf);
  31. void dp_tx_mec_handler(struct dp_vdev *vdev, uint8_t *status);
  32. #ifdef FEATURE_AST
  33. /*
  34. * dp_peer_delete_ast_entries(): Delete all AST entries for a peer
  35. * @soc - datapath soc handle
  36. * @peer - datapath peer handle
  37. *
  38. * Delete the AST entries belonging to a peer
  39. */
  40. static inline void dp_peer_delete_ast_entries(struct dp_soc *soc,
  41. struct dp_peer *peer)
  42. {
  43. struct dp_ast_entry *ast_entry, *temp_ast_entry;
  44. qdf_spin_lock_bh(&soc->ast_lock);
  45. DP_PEER_ITERATE_ASE_LIST(peer, ast_entry, temp_ast_entry)
  46. dp_peer_del_ast(soc, ast_entry);
  47. peer->self_ast_entry = NULL;
  48. qdf_spin_unlock_bh(&soc->ast_lock);
  49. }
  50. static void dp_peer_teardown_wifi3(struct cdp_vdev *vdev_hdl, void *peer_hdl)
  51. {
  52. struct dp_vdev *vdev = (struct dp_vdev *)vdev_hdl;
  53. struct dp_peer *peer = (struct dp_peer *)peer_hdl;
  54. struct dp_soc *soc = (struct dp_soc *)vdev->pdev->soc;
  55. /*
  56. * For BSS peer, new peer is not created on alloc_node if the
  57. * peer with same address already exists , instead refcnt is
  58. * increased for existing peer. Correspondingly in delete path,
  59. * only refcnt is decreased; and peer is only deleted , when all
  60. * references are deleted. So delete_in_progress should not be set
  61. * for bss_peer, unless only 2 reference remains (peer map reference
  62. * and peer hash table reference).
  63. */
  64. if (peer->bss_peer && (qdf_atomic_read(&peer->ref_cnt) > 2))
  65. return;
  66. peer->delete_in_progress = true;
  67. dp_peer_delete_ast_entries(soc, peer);
  68. }
  69. #endif
  70. #ifdef FEATURE_WDS
  71. static inline bool dp_tx_da_search_override(struct dp_vdev *vdev)
  72. {
  73. struct dp_soc *soc = vdev->pdev->soc;
  74. /*
  75. * If AST index override support is available (HKv2 etc),
  76. * DA search flag be enabled always
  77. *
  78. * If AST index override support is not available (HKv1),
  79. * DA search flag should be used for all modes except QWRAP
  80. */
  81. if (soc->ast_override_support || !vdev->proxysta_vdev)
  82. return true;
  83. return false;
  84. }
  85. #endif
  86. #ifdef WDS_VENDOR_EXTENSION
  87. void
  88. dp_txrx_peer_wds_tx_policy_update(struct cdp_peer *peer_handle,
  89. int wds_tx_ucast, int wds_tx_mcast);
  90. void
  91. dp_txrx_set_wds_rx_policy(struct cdp_vdev *vdev_handle,
  92. u_int32_t val);
  93. #endif
  94. /**
  95. * dp_rx_wds_add_or_update_ast() - Add or update the ast entry.
  96. *
  97. * @soc: core txrx main context
  98. * @ta_peer: WDS repeater peer
  99. * @mac_addr: mac address of the peer
  100. * @is_ad4_valid: 4-address valid flag
  101. * @is_sa_valid: source address valid flag
  102. * @is_chfrag_start: frag start flag
  103. * @sa_idx: source-address index for peer
  104. * @sa_sw_peer_id: software source-address peer-id
  105. *
  106. * Return: void:
  107. */
  108. static inline void
  109. dp_rx_wds_add_or_update_ast(struct dp_soc *soc, struct dp_peer *ta_peer,
  110. uint8_t *wds_src_mac, uint8_t is_ad4_valid,
  111. uint8_t is_sa_valid, uint8_t is_chfrag_start,
  112. uint16_t sa_idx, uint16_t sa_sw_peer_id)
  113. {
  114. struct dp_peer *sa_peer;
  115. struct dp_ast_entry *ast;
  116. uint32_t flags = IEEE80211_NODE_F_WDS_HM;
  117. uint32_t ret = 0;
  118. struct dp_neighbour_peer *neighbour_peer = NULL;
  119. struct dp_pdev *pdev = ta_peer->vdev->pdev;
  120. /* For AP mode : Do wds source port learning only if it is a
  121. * 4-address mpdu
  122. *
  123. * For STA mode : Frames from RootAP backend will be in 3-address mode,
  124. * till RootAP does the WDS source port learning; Hence in repeater/STA
  125. * mode, we enable learning even in 3-address mode , to avoid RootAP
  126. * backbone getting wrongly learnt as MEC on repeater
  127. */
  128. if (ta_peer->vdev->opmode != wlan_op_mode_sta) {
  129. if (!(is_chfrag_start && is_ad4_valid))
  130. return;
  131. } else {
  132. /* For HKv2 Source port learing is not needed in STA mode
  133. * as we have support in HW
  134. */
  135. if (soc->ast_override_support)
  136. return;
  137. }
  138. if (qdf_unlikely(!is_sa_valid)) {
  139. ret = dp_peer_add_ast(soc, ta_peer, wds_src_mac,
  140. CDP_TXRX_AST_TYPE_WDS, flags);
  141. return;
  142. }
  143. qdf_spin_lock_bh(&soc->ast_lock);
  144. ast = soc->ast_table[sa_idx];
  145. qdf_spin_unlock_bh(&soc->ast_lock);
  146. if (!ast) {
  147. /*
  148. * In HKv1, it is possible that HW retains the AST entry in
  149. * GSE cache on 1 radio , even after the AST entry is deleted
  150. * (on another radio).
  151. *
  152. * Due to this, host might still get sa_is_valid indications
  153. * for frames with SA not really present in AST table.
  154. *
  155. * So we go ahead and send an add_ast command to FW in such
  156. * cases where sa is reported still as valid, so that FW will
  157. * invalidate this GSE cache entry and new AST entry gets
  158. * cached.
  159. */
  160. if (!soc->ast_override_support) {
  161. ret = dp_peer_add_ast(soc, ta_peer, wds_src_mac,
  162. CDP_TXRX_AST_TYPE_WDS, flags);
  163. return;
  164. }
  165. if (soc->ast_override_support) {
  166. /* In HKv2 smart monitor case, when NAC client is
  167. * added first and this client roams within BSS to
  168. * connect to RE, since we have an AST entry for
  169. * NAC we get sa_is_valid bit set. So we check if
  170. * smart monitor is enabled and send add_ast command
  171. * to FW.
  172. */
  173. if (pdev->neighbour_peers_added) {
  174. qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
  175. TAILQ_FOREACH(neighbour_peer,
  176. &pdev->neighbour_peers_list,
  177. neighbour_peer_list_elem) {
  178. if (!qdf_mem_cmp(&neighbour_peer->
  179. neighbour_peers_macaddr
  180. , wds_src_mac,
  181. QDF_MAC_ADDR_SIZE)) {
  182. ret = dp_peer_add_ast
  183. (soc,
  184. ta_peer,
  185. wds_src_mac,
  186. CDP_TXRX_AST_TYPE_WDS,
  187. flags);
  188. QDF_TRACE
  189. (QDF_MODULE_ID_DP,
  190. QDF_TRACE_LEVEL_INFO,
  191. "sa valid and nac roamed to wds");
  192. break;
  193. }
  194. }
  195. qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
  196. }
  197. return;
  198. }
  199. }
  200. if ((ast->type == CDP_TXRX_AST_TYPE_WDS_HM) ||
  201. (ast->type == CDP_TXRX_AST_TYPE_WDS_HM_SEC))
  202. return;
  203. /*
  204. * Ensure we are updating the right AST entry by
  205. * validating ast_idx.
  206. * There is a possibility we might arrive here without
  207. * AST MAP event , so this check is mandatory
  208. */
  209. if (ast->is_mapped && (ast->ast_idx == sa_idx))
  210. ast->is_active = TRUE;
  211. if (sa_sw_peer_id != ta_peer->peer_ids[0]) {
  212. sa_peer = ast->peer;
  213. if ((ast->type != CDP_TXRX_AST_TYPE_STATIC) &&
  214. (ast->type != CDP_TXRX_AST_TYPE_SELF) &&
  215. (ast->type != CDP_TXRX_AST_TYPE_STA_BSS)) {
  216. if (ast->pdev_id != ta_peer->vdev->pdev->pdev_id) {
  217. /* This case is when a STA roams from one
  218. * repeater to another repeater, but these
  219. * repeaters are connected to root AP on
  220. * different radios.
  221. * Ex: rptr1 connected to ROOT AP over 5G
  222. * and rptr2 connected to ROOT AP over 2G
  223. * radio
  224. */
  225. qdf_spin_lock_bh(&soc->ast_lock);
  226. dp_peer_del_ast(soc, ast);
  227. qdf_spin_unlock_bh(&soc->ast_lock);
  228. } else {
  229. /* this case is when a STA roams from one
  230. * reapter to another repeater, but inside
  231. * same radio.
  232. */
  233. qdf_spin_lock_bh(&soc->ast_lock);
  234. dp_peer_update_ast(soc, ta_peer, ast, flags);
  235. qdf_spin_unlock_bh(&soc->ast_lock);
  236. return;
  237. }
  238. }
  239. /*
  240. * Do not kickout STA if it belongs to a different radio.
  241. * For DBDC repeater, it is possible to arrive here
  242. * for multicast loopback frames originated from connected
  243. * clients and looped back (intrabss) by Root AP
  244. */
  245. if (ast->pdev_id != ta_peer->vdev->pdev->pdev_id)
  246. return;
  247. /*
  248. * Kickout, when direct associated peer(SA) roams
  249. * to another AP and reachable via TA peer
  250. */
  251. if ((sa_peer->vdev->opmode == wlan_op_mode_ap) &&
  252. !sa_peer->delete_in_progress) {
  253. sa_peer->delete_in_progress = true;
  254. if (soc->cdp_soc.ol_ops->peer_sta_kickout) {
  255. soc->cdp_soc.ol_ops->peer_sta_kickout(
  256. sa_peer->vdev->pdev->ctrl_pdev,
  257. wds_src_mac);
  258. }
  259. }
  260. }
  261. }
  262. /**
  263. * dp_rx_wds_srcport_learn() - Add or update the STA PEER which
  264. * is behind the WDS repeater.
  265. *
  266. * @soc: core txrx main context
  267. * @rx_tlv_hdr: base address of RX TLV header
  268. * @ta_peer: WDS repeater peer
  269. * @nbuf: rx pkt
  270. *
  271. * Return: void:
  272. */
  273. static inline void
  274. dp_rx_wds_srcport_learn(struct dp_soc *soc,
  275. uint8_t *rx_tlv_hdr,
  276. struct dp_peer *ta_peer,
  277. qdf_nbuf_t nbuf)
  278. {
  279. uint16_t sa_sw_peer_id = hal_rx_msdu_end_sa_sw_peer_id_get(rx_tlv_hdr);
  280. uint8_t sa_is_valid = hal_rx_msdu_end_sa_is_valid_get(rx_tlv_hdr);
  281. uint8_t wds_src_mac[IEEE80211_ADDR_LEN];
  282. uint16_t sa_idx;
  283. uint8_t is_chfrag_start = 0;
  284. uint8_t is_ad4_valid = 0;
  285. if (qdf_unlikely(!ta_peer))
  286. return;
  287. is_chfrag_start = qdf_nbuf_is_rx_chfrag_start(nbuf);
  288. if (is_chfrag_start)
  289. is_ad4_valid = hal_rx_get_mpdu_mac_ad4_valid(rx_tlv_hdr);
  290. memcpy(wds_src_mac, (qdf_nbuf_data(nbuf) + IEEE80211_ADDR_LEN),
  291. IEEE80211_ADDR_LEN);
  292. /*
  293. * Get the AST entry from HW SA index and mark it as active
  294. */
  295. sa_idx = hal_rx_msdu_end_sa_idx_get(rx_tlv_hdr);
  296. dp_rx_wds_add_or_update_ast(soc, ta_peer, wds_src_mac, is_ad4_valid,
  297. sa_is_valid, is_chfrag_start,
  298. sa_idx, sa_sw_peer_id);
  299. }
  300. /*
  301. * dp_rx_ast_set_active() - set the active flag of the astentry
  302. * corresponding to a hw index.
  303. * @soc: core txrx main context
  304. * @sa_idx: hw idx
  305. * @is_active: active flag
  306. *
  307. */
  308. static inline QDF_STATUS dp_rx_ast_set_active(struct dp_soc *soc,
  309. uint16_t sa_idx, bool is_active)
  310. {
  311. struct dp_ast_entry *ast;
  312. qdf_spin_lock_bh(&soc->ast_lock);
  313. ast = soc->ast_table[sa_idx];
  314. /*
  315. * Ensure we are updating the right AST entry by
  316. * validating ast_idx.
  317. * There is a possibility we might arrive here without
  318. * AST MAP event , so this check is mandatory
  319. */
  320. if (ast && ast->is_mapped && (ast->ast_idx == sa_idx)) {
  321. ast->is_active = is_active;
  322. qdf_spin_unlock_bh(&soc->ast_lock);
  323. return QDF_STATUS_SUCCESS;
  324. }
  325. qdf_spin_unlock_bh(&soc->ast_lock);
  326. return QDF_STATUS_E_FAILURE;
  327. }
  328. #endif /* DP_TXRX_WDS*/