dpdk_legacy.h revision fbba0a3b
1/*
2 * Copyright (c) 2016  Intel Corporation.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef DPDK_LEGACY_H_
17#define DPDK_LEGACY_H_
18
19#include <rte_version.h>
20
21#if RTE_VERSION_NUM(17, 5, 0, 0) <= RTE_VERSION
22#ifndef DPDK_VERSION_GE_1705
23#define DPDK_VERSION_GE_1705
24#endif
25#endif
26
27/*
28 * IPv6 destination lookup callback.
29 */
30static int
31lpm6_dst_lookup(void *data, const struct in6_addr *addr,
32	struct tle_dest *res)
33{
34	int32_t rc;
35#ifdef DPDK_VERSION_GE_1705
36	uint32_t idx;
37#else
38	uint8_t idx;
39#endif
40	struct netbe_lcore *lc;
41	struct tle_dest *dst;
42	uintptr_t p;
43
44	lc = data;
45	p = (uintptr_t)addr->s6_addr;
46
47	rc = rte_lpm6_lookup(lc->lpm6, (uint8_t *)p, &idx);
48	if (rc == 0) {
49		dst = &lc->dst6[idx];
50		rte_memcpy(res, dst, dst->l2_len + dst->l3_len +
51			offsetof(struct tle_dest, hdr));
52	}
53	return rc;
54}
55
56static int
57netbe_find6(const struct in6_addr *laddr, uint16_t lport,
58	const struct in6_addr *raddr, uint32_t belc)
59{
60	uint32_t i, j;
61#ifdef DPDK_VERSION_GE_1705
62	uint32_t idx;
63#else
64	uint8_t idx;
65#endif
66	struct netbe_lcore *bc;
67
68	/* we have exactly one BE, use it for all traffic */
69	if (becfg.cpu_num == 1)
70		return 0;
71
72	/* search by provided be_lcore */
73	if (belc != LCORE_ID_ANY) {
74		for (i = 0; i != becfg.cpu_num; i++) {
75			bc = becfg.cpu + i;
76			if (belc == bc->id)
77				return i;
78		}
79		RTE_LOG(NOTICE, USER1, "%s: no stream with belcore=%u\n",
80			__func__, belc);
81		return -ENOENT;
82	}
83
84	/* search by local address */
85	if (memcmp(laddr, &in6addr_any, sizeof(*laddr)) != 0) {
86		for (i = 0; i != becfg.cpu_num; i++) {
87			bc = becfg.cpu + i;
88			/* search by queue for the local port */
89			for (j = 0; j != bc->prtq_num; j++) {
90				if (memcmp(laddr, &bc->prtq[j].port.ipv6,
91						sizeof(*laddr)) == 0) {
92
93					if (lport == 0)
94						return i;
95
96					if (verify_queue_for_port(bc->prtq + j,
97							lport) != 0)
98						return i;
99				}
100			}
101		}
102	}
103
104	/* search by remote address */
105	if (memcmp(raddr, &in6addr_any, sizeof(*raddr)) == 0) {
106		for (i = 0; i != becfg.cpu_num; i++) {
107			bc = becfg.cpu + i;
108			if (rte_lpm6_lookup(bc->lpm6,
109					(uint8_t *)(uintptr_t)raddr->s6_addr,
110					&idx) == 0) {
111
112				if (lport == 0)
113					return i;
114
115				/* search by queue for the local port */
116				for (j = 0; j != bc->prtq_num; j++)
117					if (verify_queue_for_port(bc->prtq + j,
118							lport) != 0)
119						return i;
120			}
121		}
122	}
123
124	return -ENOENT;
125}
126
127#endif /* DPDK_LEGACY_H_ */
128