Line data Source code
1 : /* SPDX-License-Identifier: BSD-2-Clause
2 : * Copyright(c) HCL TECHNOLOGIES LTD
3 : * Submitted on behalf of a third-party: Intel Corporation, a
4 : * Delaware corporation, having its principal place of business
5 : * at 2200 Mission College Boulevard,
6 : * Santa Clara, California 95052, USA
7 : */
8 :
9 : #include "vr_dpdk_n3k_vxlan.h"
10 :
11 : #include <string.h>
12 :
13 : #include <rte_log.h>
14 : #include <rte_malloc.h>
15 : #include <rte_atomic.h>
16 :
17 : #include "vr_dpdk.h"
18 :
19 : enum { N3K_OFFLOAD_VNI_COUNT = 1 << 24 };
20 :
21 : static rte_atomic32_t *vni_to_nh;
22 :
23 : #define EMPTY_NH UINT32_MAX
24 :
25 : int
26 4 : vr_dpdk_n3k_offload_vxlan_init(uint32_t nh_count)
27 : {
28 4 : vni_to_nh = rte_malloc("n3k_offload_vxlan",
29 : N3K_OFFLOAD_VNI_COUNT * sizeof(*vni_to_nh), 0);
30 :
31 4 : if (vni_to_nh == NULL)
32 0 : return -ENOMEM;
33 :
34 : /* fill with EMPTY_NH */
35 4 : memset(vni_to_nh, 0xff, N3K_OFFLOAD_VNI_COUNT * sizeof(*vni_to_nh));
36 :
37 4 : return 0;
38 : }
39 :
40 : void
41 4 : vr_dpdk_n3k_offload_vxlan_exit(void)
42 : {
43 4 : rte_free(vni_to_nh);
44 4 : vni_to_nh = NULL;
45 4 : }
46 :
47 : int
48 0 : vr_dpdk_n3k_offload_vxlan_get_by_vni(uint32_t vnid, struct vr_n3k_offload_vxlan *out)
49 : {
50 0 : if (vnid >= N3K_OFFLOAD_VNI_COUNT)
51 0 : return -EINVAL;
52 :
53 0 : uint32_t nh = rte_atomic32_read(&vni_to_nh[vnid]);
54 0 : if (nh == EMPTY_NH)
55 0 : return -ENOENT;
56 :
57 0 : out->vnid = vnid;
58 0 : out->nexthop_id = nh;
59 0 : return 0;
60 : }
61 :
62 : int
63 2 : vr_dpdk_n3k_offload_vxlan_insert_copy_for_test(struct vr_n3k_offload_vxlan vxlan)
64 : {
65 2 : if (rte_atomic32_cmpset(
66 2 : (volatile uint32_t *)&vni_to_nh[vxlan.vnid].cnt,
67 : EMPTY_NH,
68 : vxlan.nexthop_id
69 : ) == 0)
70 0 : return -EEXIST;
71 :
72 2 : return 0;
73 : }
74 :
75 : int
76 0 : vr_dpdk_n3k_offload_vxlan_add(struct vr_nexthop *nh, int vnid)
77 : {
78 0 : RTE_LOG(
79 : DEBUG, VROUTER,
80 : "%s() called; nh=%p; nh_id=%d; nh_type=%d; vnid=%d;\n",
81 : __func__, nh, nh->nh_id, nh->nh_type, vnid
82 : );
83 :
84 : /* TODO(n3k): Handle multiple routers */
85 0 : if (nh->nh_rid != 0)
86 0 : return 0;
87 :
88 0 : rte_atomic32_set(&vni_to_nh[vnid], nh->nh_id);
89 :
90 0 : return 0;
91 : }
92 :
93 : int
94 0 : vr_dpdk_n3k_offload_vxlan_del(int vnid)
95 : {
96 0 : RTE_LOG(DEBUG, VROUTER, "%s() called; vnid=%d;\n", __func__, vnid);
97 :
98 0 : rte_atomic32_set(&vni_to_nh[vnid], EMPTY_NH);
99 :
100 0 : return 0;
101 : }
|