dp_txrx_wds.h 12 KB

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