From fbba0a3bf2dbfd86e48efe9745af9f94203d5f80 Mon Sep 17 00:00:00 2001 From: Mohammad Abdul Awal Date: Thu, 11 May 2017 13:36:12 +0100 Subject: Added rte_ring wrapper functions to support dpdk-17.05 and older version Change-Id: I5cfcff8be275ab2a2fb4ad6a62777a8cb88f425b Signed-off-by: Mohammad Abdul Awal --- examples/l4fwd/dpdk_legacy.h | 87 ++++++----------- examples/l4fwd/dpdk_version.h | 33 ------- examples/l4fwd/lcore.h | 181 ++++++++++++++++++++--------------- examples/l4fwd/pkt.c | 165 +++++++++++++++++++++++++++++++- examples/l4fwd/pkt_dpdk_legacy.h | 197 --------------------------------------- 5 files changed, 298 insertions(+), 365 deletions(-) delete mode 100644 examples/l4fwd/dpdk_version.h delete mode 100644 examples/l4fwd/pkt_dpdk_legacy.h (limited to 'examples') diff --git a/examples/l4fwd/dpdk_legacy.h b/examples/l4fwd/dpdk_legacy.h index 84fab17..7bf856f 100644 --- a/examples/l4fwd/dpdk_legacy.h +++ b/examples/l4fwd/dpdk_legacy.h @@ -13,32 +13,40 @@ * limitations under the License. */ -#ifndef MAIN_DPDK_LEGACY_H_ -#define MAIN_DPDK_LEGACY_H_ +#ifndef DPDK_LEGACY_H_ +#define DPDK_LEGACY_H_ -#include "dpdk_version.h" +#include + +#if RTE_VERSION_NUM(17, 5, 0, 0) <= RTE_VERSION +#ifndef DPDK_VERSION_GE_1705 +#define DPDK_VERSION_GE_1705 +#endif +#endif /* - * UDP IPv4 destination lookup callback. + * IPv6 destination lookup callback. */ static int -lpm4_dst_lookup(void *data, const struct in_addr *addr, +lpm6_dst_lookup(void *data, const struct in6_addr *addr, struct tle_dest *res) { int32_t rc; -#ifdef DPDK_VERSION_GE_1604 +#ifdef DPDK_VERSION_GE_1705 uint32_t idx; #else uint8_t idx; #endif struct netbe_lcore *lc; struct tle_dest *dst; + uintptr_t p; lc = data; + p = (uintptr_t)addr->s6_addr; - rc = rte_lpm_lookup(lc->lpm4, rte_be_to_cpu_32(addr->s_addr), &idx); + rc = rte_lpm6_lookup(lc->lpm6, (uint8_t *)p, &idx); if (rc == 0) { - dst = &lc->dst4[idx]; + dst = &lc->dst6[idx]; rte_memcpy(res, dst, dst->l2_len + dst->l3_len + offsetof(struct tle_dest, hdr)); } @@ -46,53 +54,11 @@ lpm4_dst_lookup(void *data, const struct in_addr *addr, } static int -lcore_lpm_init(struct netbe_lcore *lc) -{ - int32_t sid; - char str[RTE_LPM_NAMESIZE]; -#ifdef DPDK_VERSION_GE_1604 - const struct rte_lpm_config lpm4_cfg = { - .max_rules = MAX_RULES, - .number_tbl8s = MAX_TBL8, - }; -#endif - const struct rte_lpm6_config lpm6_cfg = { - .max_rules = MAX_RULES, - .number_tbl8s = MAX_TBL8, - }; - - sid = rte_lcore_to_socket_id(lc->id); - - snprintf(str, sizeof(str), "LPM4%u\n", lc->id); -#ifdef DPDK_VERSION_GE_1604 - lc->lpm4 = rte_lpm_create(str, sid, &lpm4_cfg); -#else - lc->lpm4 = rte_lpm_create(str, sid, MAX_RULES, 0); -#endif - RTE_LOG(NOTICE, USER1, "%s(lcore=%u): lpm4=%p;\n", - __func__, lc->id, lc->lpm4); - if (lc->lpm4 == NULL) - return -ENOMEM; - - snprintf(str, sizeof(str), "LPM6%u\n", lc->id); - lc->lpm6 = rte_lpm6_create(str, sid, &lpm6_cfg); - RTE_LOG(NOTICE, USER1, "%s(lcore=%u): lpm6=%p;\n", - __func__, lc->id, lc->lpm6); - if (lc->lpm6 == NULL) - return -ENOMEM; - - return 0; -} - -/* - * Helper functions, finds BE by given local and remote addresses. - */ -static int -netbe_find4(const struct in_addr *laddr, const uint16_t lport, - const struct in_addr *raddr, const uint32_t belc) +netbe_find6(const struct in6_addr *laddr, uint16_t lport, + const struct in6_addr *raddr, uint32_t belc) { uint32_t i, j; -#ifdef DPDK_VERSION_GE_1604 +#ifdef DPDK_VERSION_GE_1705 uint32_t idx; #else uint8_t idx; @@ -110,18 +76,19 @@ netbe_find4(const struct in_addr *laddr, const uint16_t lport, if (belc == bc->id) return i; } - RTE_LOG(NOTICE, USER1, "%s: no stream with be_lcore=%u\n", + RTE_LOG(NOTICE, USER1, "%s: no stream with belcore=%u\n", __func__, belc); return -ENOENT; } /* search by local address */ - if (laddr->s_addr != INADDR_ANY) { + if (memcmp(laddr, &in6addr_any, sizeof(*laddr)) != 0) { for (i = 0; i != becfg.cpu_num; i++) { bc = becfg.cpu + i; /* search by queue for the local port */ for (j = 0; j != bc->prtq_num; j++) { - if (laddr->s_addr == bc->prtq[j].port.ipv4) { + if (memcmp(laddr, &bc->prtq[j].port.ipv6, + sizeof(*laddr)) == 0) { if (lport == 0) return i; @@ -135,11 +102,11 @@ netbe_find4(const struct in_addr *laddr, const uint16_t lport, } /* search by remote address */ - if (raddr->s_addr != INADDR_ANY) { + if (memcmp(raddr, &in6addr_any, sizeof(*raddr)) == 0) { for (i = 0; i != becfg.cpu_num; i++) { bc = becfg.cpu + i; - if (rte_lpm_lookup(bc->lpm4, - rte_be_to_cpu_32(raddr->s_addr), + if (rte_lpm6_lookup(bc->lpm6, + (uint8_t *)(uintptr_t)raddr->s6_addr, &idx) == 0) { if (lport == 0) @@ -157,4 +124,4 @@ netbe_find4(const struct in_addr *laddr, const uint16_t lport, return -ENOENT; } -#endif /* MAIN_DPDK_LEGACY_H_ */ +#endif /* DPDK_LEGACY_H_ */ diff --git a/examples/l4fwd/dpdk_version.h b/examples/l4fwd/dpdk_version.h deleted file mode 100644 index 43235c8..0000000 --- a/examples/l4fwd/dpdk_version.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DPDK_VERSION_H_ -#define DPDK_VERSION_H_ - -#include - -#ifdef RTE_VER_MAJOR -#if RTE_VER_MAJOR >= 16 && RTE_VER_MINOR >= 4 -#define DPDK_VERSION_GE_1604 -#endif -#elif defined(RTE_VER_YEAR) -#if RTE_VERSION_NUM(16, 4, 0, 0) <= RTE_VERSION -#define DPDK_VERSION_GE_1604 -#endif -#else -#error "RTE_VER_MAJOR and RTE_VER_YEAR are undefined!" -#endif - -#endif /* DPDK_VERSION_H_ */ diff --git a/examples/l4fwd/lcore.h b/examples/l4fwd/lcore.h index 11cc239..9deddcc 100644 --- a/examples/l4fwd/lcore.h +++ b/examples/l4fwd/lcore.h @@ -21,30 +21,130 @@ #include "dpdk_legacy.h" /* - * IPv6 destination lookup callback. + * IPv4 destination lookup callback. */ static int -lpm6_dst_lookup(void *data, const struct in6_addr *addr, +lpm4_dst_lookup(void *data, const struct in_addr *addr, struct tle_dest *res) { int32_t rc; - uint8_t idx; + uint32_t idx; struct netbe_lcore *lc; struct tle_dest *dst; - uintptr_t p; lc = data; - p = (uintptr_t)addr->s6_addr; - rc = rte_lpm6_lookup(lc->lpm6, (uint8_t *)p, &idx); + rc = rte_lpm_lookup(lc->lpm4, rte_be_to_cpu_32(addr->s_addr), &idx); if (rc == 0) { - dst = &lc->dst6[idx]; + dst = &lc->dst4[idx]; rte_memcpy(res, dst, dst->l2_len + dst->l3_len + offsetof(struct tle_dest, hdr)); } return rc; } +static int +lcore_lpm_init(struct netbe_lcore *lc) +{ + int32_t sid; + char str[RTE_LPM_NAMESIZE]; + const struct rte_lpm_config lpm4_cfg = { + .max_rules = MAX_RULES, + .number_tbl8s = MAX_TBL8, + }; + const struct rte_lpm6_config lpm6_cfg = { + .max_rules = MAX_RULES, + .number_tbl8s = MAX_TBL8, + }; + + sid = rte_lcore_to_socket_id(lc->id); + + snprintf(str, sizeof(str), "LPM4%u\n", lc->id); + lc->lpm4 = rte_lpm_create(str, sid, &lpm4_cfg); + RTE_LOG(NOTICE, USER1, "%s(lcore=%u): lpm4=%p;\n", + __func__, lc->id, lc->lpm4); + if (lc->lpm4 == NULL) + return -ENOMEM; + + snprintf(str, sizeof(str), "LPM6%u\n", lc->id); + lc->lpm6 = rte_lpm6_create(str, sid, &lpm6_cfg); + RTE_LOG(NOTICE, USER1, "%s(lcore=%u): lpm6=%p;\n", + __func__, lc->id, lc->lpm6); + if (lc->lpm6 == NULL) + return -ENOMEM; + + return 0; +} + +/* + * Helper functions, finds BE by given local and remote addresses. + */ +static int +netbe_find4(const struct in_addr *laddr, const uint16_t lport, + const struct in_addr *raddr, const uint32_t belc) +{ + uint32_t i, j; + uint32_t idx; + struct netbe_lcore *bc; + + /* we have exactly one BE, use it for all traffic */ + if (becfg.cpu_num == 1) + return 0; + + /* search by provided be_lcore */ + if (belc != LCORE_ID_ANY) { + for (i = 0; i != becfg.cpu_num; i++) { + bc = becfg.cpu + i; + if (belc == bc->id) + return i; + } + RTE_LOG(NOTICE, USER1, "%s: no stream with be_lcore=%u\n", + __func__, belc); + return -ENOENT; + } + + /* search by local address */ + if (laddr->s_addr != INADDR_ANY) { + for (i = 0; i != becfg.cpu_num; i++) { + bc = becfg.cpu + i; + /* search by queue for the local port */ + for (j = 0; j != bc->prtq_num; j++) { + if (laddr->s_addr == bc->prtq[j].port.ipv4) { + + if (lport == 0) + return i; + + if (verify_queue_for_port(bc->prtq + j, + lport) != 0) + return i; + } + } + } + } + + /* search by remote address */ + if (raddr->s_addr != INADDR_ANY) { + for (i = 0; i != becfg.cpu_num; i++) { + bc = becfg.cpu + i; + if (rte_lpm_lookup(bc->lpm4, + rte_be_to_cpu_32(raddr->s_addr), + &idx) == 0) { + + if (lport == 0) + return i; + + /* search by queue for the local port */ + for (j = 0; j != bc->prtq_num; j++) + if (verify_queue_for_port(bc->prtq + j, + lport) != 0) + return i; + } + } + } + + return -ENOENT; +} + static int create_context(struct netbe_lcore *lc, const struct tle_ctx_param *ctx_prm) { @@ -211,73 +311,6 @@ netfe_lcore_cmp(const void *s1, const void *s2) return p1->lcore - p2->lcore; } -static int -netbe_find6(const struct in6_addr *laddr, uint16_t lport, - const struct in6_addr *raddr, uint32_t belc) -{ - uint32_t i, j; - uint8_t idx; - struct netbe_lcore *bc; - - /* we have exactly one BE, use it for all traffic */ - if (becfg.cpu_num == 1) - return 0; - - /* search by provided be_lcore */ - if (belc != LCORE_ID_ANY) { - for (i = 0; i != becfg.cpu_num; i++) { - bc = becfg.cpu + i; - if (belc == bc->id) - return i; - } - RTE_LOG(NOTICE, USER1, "%s: no stream with belcore=%u\n", - __func__, belc); - return -ENOENT; - } - - /* search by local address */ - if (memcmp(laddr, &in6addr_any, sizeof(*laddr)) != 0) { - for (i = 0; i != becfg.cpu_num; i++) { - bc = becfg.cpu + i; - /* search by queue for the local port */ - for (j = 0; j != bc->prtq_num; j++) { - if (memcmp(laddr, &bc->prtq[j].port.ipv6, - sizeof(*laddr)) == 0) { - - if (lport == 0) - return i; - - if (verify_queue_for_port(bc->prtq + j, - lport) != 0) - return i; - } - } - } - } - - /* search by remote address */ - if (memcmp(raddr, &in6addr_any, sizeof(*raddr)) == 0) { - for (i = 0; i != becfg.cpu_num; i++) { - bc = becfg.cpu + i; - if (rte_lpm6_lookup(bc->lpm6, - (uint8_t *)(uintptr_t)raddr->s6_addr, - &idx) == 0) { - - if (lport == 0) - return i; - - /* search by queue for the local port */ - for (j = 0; j != bc->prtq_num; j++) - if (verify_queue_for_port(bc->prtq + j, - lport) != 0) - return i; - } - } - } - - return -ENOENT; -} - static int netbe_find(const struct sockaddr_storage *la, const struct sockaddr_storage *ra, diff --git a/examples/l4fwd/pkt.c b/examples/l4fwd/pkt.c index 660e618..b9d53ce 100644 --- a/examples/l4fwd/pkt.c +++ b/examples/l4fwd/pkt.c @@ -18,6 +18,22 @@ #include "netbe.h" +struct ptype2cb { + uint32_t mask; + const char *name; + rte_rx_callback_fn fn; +}; + +enum { + ETHER_PTYPE = 0x1, + IPV4_PTYPE = 0x2, + IPV4_EXT_PTYPE = 0x4, + IPV6_PTYPE = 0x8, + IPV6_EXT_PTYPE = 0x10, + TCP_PTYPE = 0x20, + UDP_PTYPE = 0x40, +}; + static inline uint64_t _mbuf_tx_offload(uint64_t il2, uint64_t il3, uint64_t il4, uint64_t tso, uint64_t ol3, uint64_t ol2) @@ -869,4 +885,151 @@ typen_udp_rx_callback(uint8_t port, __rte_unused uint16_t queue, return compress_pkt_list(pkt, nb_pkts, x); } -#include "pkt_dpdk_legacy.h" +static uint32_t +get_ptypes(const struct netbe_port *uprt) +{ + uint32_t smask; + int32_t i, rc; + const uint32_t pmask = RTE_PTYPE_L2_MASK | RTE_PTYPE_L3_MASK | + RTE_PTYPE_L4_MASK; + + smask = 0; + rc = rte_eth_dev_get_supported_ptypes(uprt->id, pmask, NULL, 0); + if (rc < 0) { + RTE_LOG(ERR, USER1, + "%s(port=%u) failed to get supported ptypes;\n", + __func__, uprt->id); + return smask; + } + + uint32_t ptype[rc]; + rc = rte_eth_dev_get_supported_ptypes(uprt->id, pmask, ptype, rc); + + for (i = 0; i != rc; i++) { + switch (ptype[i]) { + case RTE_PTYPE_L2_ETHER: + smask |= ETHER_PTYPE; + break; + case RTE_PTYPE_L3_IPV4: + case RTE_PTYPE_L3_IPV4_EXT_UNKNOWN: + smask |= IPV4_PTYPE; + break; + case RTE_PTYPE_L3_IPV4_EXT: + smask |= IPV4_EXT_PTYPE; + break; + case RTE_PTYPE_L3_IPV6: + case RTE_PTYPE_L3_IPV6_EXT_UNKNOWN: + smask |= IPV6_PTYPE; + break; + case RTE_PTYPE_L3_IPV6_EXT: + smask |= IPV6_EXT_PTYPE; + break; + case RTE_PTYPE_L4_TCP: + smask |= TCP_PTYPE; + break; + case RTE_PTYPE_L4_UDP: + smask |= UDP_PTYPE; + break; + } + } + + return smask; +} + +int +setup_rx_cb(const struct netbe_port *uprt, struct netbe_lcore *lc, + uint16_t qid, uint32_t arp) +{ + int32_t rc; + uint32_t i, n, smask; + void *cb; + const struct ptype2cb *ptype2cb; + + static const struct ptype2cb tcp_ptype2cb[] = { + { + .mask = ETHER_PTYPE | IPV4_PTYPE | IPV4_EXT_PTYPE | + IPV6_PTYPE | IPV6_EXT_PTYPE | TCP_PTYPE, + .name = "HW l2/l3x/l4-tcp ptype", + .fn = type0_tcp_rx_callback, + }, + { + .mask = ETHER_PTYPE | IPV4_PTYPE | IPV6_PTYPE | + TCP_PTYPE, + .name = "HW l2/l3/l4-tcp ptype", + .fn = type1_tcp_rx_callback, + }, + { + .mask = 0, + .name = "tcp no HW ptype", + .fn = typen_tcp_rx_callback, + }, + }; + + static const struct ptype2cb tcp_arp_ptype2cb[] = { + { + .mask = 0, + .name = "tcp with arp no HW ptype", + .fn = typen_tcp_arp_rx_callback, + }, + }; + + static const struct ptype2cb udp_ptype2cb[] = { + { + .mask = ETHER_PTYPE | IPV4_PTYPE | IPV4_EXT_PTYPE | + IPV6_PTYPE | IPV6_EXT_PTYPE | UDP_PTYPE, + .name = "HW l2/l3x/l4-udp ptype", + .fn = type0_udp_rx_callback, + }, + { + .mask = ETHER_PTYPE | IPV4_PTYPE | IPV6_PTYPE | + UDP_PTYPE, + .name = "HW l2/l3/l4-udp ptype", + .fn = type1_udp_rx_callback, + }, + { + .mask = 0, + .name = "udp no HW ptype", + .fn = typen_udp_rx_callback, + }, + }; + + smask = get_ptypes(uprt); + + if (lc->proto == TLE_PROTO_TCP) { + if (arp != 0) { + ptype2cb = tcp_arp_ptype2cb; + n = RTE_DIM(tcp_arp_ptype2cb); + } else { + ptype2cb = tcp_ptype2cb; + n = RTE_DIM(tcp_ptype2cb); + } + } else if (lc->proto == TLE_PROTO_UDP) { + ptype2cb = udp_ptype2cb; + n = RTE_DIM(udp_ptype2cb); + } else { + RTE_LOG(ERR, USER1, + "%s(lc=%u) unsupported proto: %u\n", + __func__, lc->id, lc->proto); + return -EINVAL; + } + + for (i = 0; i != n; i++) { + if ((smask & ptype2cb[i].mask) == ptype2cb[i].mask) { + cb = rte_eth_add_rx_callback(uprt->id, qid, + ptype2cb[i].fn, lc); + rc = -rte_errno; + RTE_LOG(ERR, USER1, + "%s(port=%u), setup RX callback \"%s\" " + "returns %p;\n", + __func__, uprt->id, ptype2cb[i].name, cb); + return ((cb == NULL) ? rc : 0); + } + } + + /* no proper callback found. */ + RTE_LOG(ERR, USER1, + "%s(port=%u) failed to find an appropriate callback;\n", + __func__, uprt->id); + return -ENOENT; +} + diff --git a/examples/l4fwd/pkt_dpdk_legacy.h b/examples/l4fwd/pkt_dpdk_legacy.h deleted file mode 100644 index d840978..0000000 --- a/examples/l4fwd/pkt_dpdk_legacy.h +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef PKT_DPDK_LEGACY_H_ -#define PKT_DPDK_LEGACY_H_ - -#include "dpdk_version.h" - -struct ptype2cb { - uint32_t mask; - const char *name; - rte_rx_callback_fn fn; -}; - -enum { - ETHER_PTYPE = 0x1, - IPV4_PTYPE = 0x2, - IPV4_EXT_PTYPE = 0x4, - IPV6_PTYPE = 0x8, - IPV6_EXT_PTYPE = 0x10, - TCP_PTYPE = 0x20, - UDP_PTYPE = 0x40, -}; - -#ifdef DPDK_VERSION_GE_1604 - -static uint32_t -get_ptypes(const struct netbe_port *uprt) -{ - uint32_t smask; - int32_t i, rc; - const uint32_t pmask = RTE_PTYPE_L2_MASK | RTE_PTYPE_L3_MASK | - RTE_PTYPE_L4_MASK; - - smask = 0; - rc = rte_eth_dev_get_supported_ptypes(uprt->id, pmask, NULL, 0); - if (rc < 0) { - RTE_LOG(ERR, USER1, - "%s(port=%u) failed to get supported ptypes;\n", - __func__, uprt->id); - return smask; - } - - uint32_t ptype[rc]; - rc = rte_eth_dev_get_supported_ptypes(uprt->id, pmask, ptype, rc); - - for (i = 0; i != rc; i++) { - switch (ptype[i]) { - case RTE_PTYPE_L2_ETHER: - smask |= ETHER_PTYPE; - break; - case RTE_PTYPE_L3_IPV4: - case RTE_PTYPE_L3_IPV4_EXT_UNKNOWN: - smask |= IPV4_PTYPE; - break; - case RTE_PTYPE_L3_IPV4_EXT: - smask |= IPV4_EXT_PTYPE; - break; - case RTE_PTYPE_L3_IPV6: - case RTE_PTYPE_L3_IPV6_EXT_UNKNOWN: - smask |= IPV6_PTYPE; - break; - case RTE_PTYPE_L3_IPV6_EXT: - smask |= IPV6_EXT_PTYPE; - break; - case RTE_PTYPE_L4_TCP: - smask |= TCP_PTYPE; - break; - case RTE_PTYPE_L4_UDP: - smask |= UDP_PTYPE; - break; - } - } - - return smask; -} - -#else - -static uint32_t -get_ptypes(__rte_unused const struct netbe_port *uprt) -{ - return 0; -} - -#endif /* DPDK_VERSION_GE_1604 */ - -int -setup_rx_cb(const struct netbe_port *uprt, struct netbe_lcore *lc, - uint16_t qid, uint32_t arp) -{ - int32_t rc; - uint32_t i, n, smask; - void *cb; - const struct ptype2cb *ptype2cb; - - static const struct ptype2cb tcp_ptype2cb[] = { - { - .mask = ETHER_PTYPE | IPV4_PTYPE | IPV4_EXT_PTYPE | - IPV6_PTYPE | IPV6_EXT_PTYPE | TCP_PTYPE, - .name = "HW l2/l3x/l4-tcp ptype", - .fn = type0_tcp_rx_callback, - }, - { - .mask = ETHER_PTYPE | IPV4_PTYPE | IPV6_PTYPE | - TCP_PTYPE, - .name = "HW l2/l3/l4-tcp ptype", - .fn = type1_tcp_rx_callback, - }, - { - .mask = 0, - .name = "tcp no HW ptype", - .fn = typen_tcp_rx_callback, - }, - }; - - static const struct ptype2cb tcp_arp_ptype2cb[] = { - { - .mask = 0, - .name = "tcp with arp no HW ptype", - .fn = typen_tcp_arp_rx_callback, - }, - }; - - static const struct ptype2cb udp_ptype2cb[] = { - { - .mask = ETHER_PTYPE | IPV4_PTYPE | IPV4_EXT_PTYPE | - IPV6_PTYPE | IPV6_EXT_PTYPE | UDP_PTYPE, - .name = "HW l2/l3x/l4-udp ptype", - .fn = type0_udp_rx_callback, - }, - { - .mask = ETHER_PTYPE | IPV4_PTYPE | IPV6_PTYPE | - UDP_PTYPE, - .name = "HW l2/l3/l4-udp ptype", - .fn = type1_udp_rx_callback, - }, - { - .mask = 0, - .name = "udp no HW ptype", - .fn = typen_udp_rx_callback, - }, - }; - - smask = get_ptypes(uprt); - - if (lc->proto == TLE_PROTO_TCP) { - if (arp != 0) { - ptype2cb = tcp_arp_ptype2cb; - n = RTE_DIM(tcp_arp_ptype2cb); - } else { - ptype2cb = tcp_ptype2cb; - n = RTE_DIM(tcp_ptype2cb); - } - } else if (lc->proto == TLE_PROTO_UDP) { - ptype2cb = udp_ptype2cb; - n = RTE_DIM(udp_ptype2cb); - } else { - RTE_LOG(ERR, USER1, - "%s(lc=%u) unsupported proto: %u\n", - __func__, lc->id, lc->proto); - return -EINVAL; - } - - for (i = 0; i != n; i++) { - if ((smask & ptype2cb[i].mask) == ptype2cb[i].mask) { - cb = rte_eth_add_rx_callback(uprt->id, qid, - ptype2cb[i].fn, lc); - rc = -rte_errno; - RTE_LOG(ERR, USER1, - "%s(port=%u), setup RX callback \"%s\" " - "returns %p;\n", - __func__, uprt->id, ptype2cb[i].name, cb); - return ((cb == NULL) ? rc : 0); - } - } - - /* no proper callback found. */ - RTE_LOG(ERR, USER1, - "%s(port=%u) failed to find an appropriate callback;\n", - __func__, uprt->id); - return -ENOENT; -} - -#endif /* PKT_DPDK_LEGACY_H_ */ -- cgit 1.2.3-korg