aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/transport
diff options
context:
space:
mode:
authorLuca Boccassi <bluca@debian.org>2022-01-14 14:13:19 +0000
committerAaron Rossetto <aaron.rossetto@ni.com>2022-01-20 13:58:51 -0600
commitb1586ee26b61fedd74e3bc076f7ff58d7a72f615 (patch)
tree1ab09a06308acee12f2136e13e91246111fb9d87 /host/lib/transport
parent4e391500b54a22dbaae8692750ec25ae8a97ee6d (diff)
downloaduhd-b1586ee26b61fedd74e3bc076f7ff58d7a72f615.tar.gz
uhd-b1586ee26b61fedd74e3bc076f7ff58d7a72f615.tar.bz2
uhd-b1586ee26b61fedd74e3bc076f7ff58d7a72f615.zip
host: fix build with DPDK v21.11 LTS
Some APIs were changed with the latest DPDK LTS release, add some ifdefs to fix the build. Fixes https://github.com/EttusResearch/uhd/issues/547 Updated CMake file to reflect updated DPDK version. Fixed mbuf size to take ethernet headers into account. Updated documentation. Co-authored-by: Martin Anderseck <martin.anderseck@ni.com>
Diffstat (limited to 'host/lib/transport')
-rw-r--r--host/lib/transport/udp_dpdk_link.cpp5
-rw-r--r--host/lib/transport/uhd-dpdk/dpdk_common.cpp71
-rw-r--r--host/lib/transport/uhd-dpdk/dpdk_io_service.cpp34
3 files changed, 76 insertions, 34 deletions
diff --git a/host/lib/transport/udp_dpdk_link.cpp b/host/lib/transport/udp_dpdk_link.cpp
index 194b0536c..4249d4bb8 100644
--- a/host/lib/transport/udp_dpdk_link.cpp
+++ b/host/lib/transport/udp_dpdk_link.cpp
@@ -175,8 +175,13 @@ void udp_dpdk_link::release_send_buff(frame_buff::uptr buff)
// Fill in L2 header
auto local_mac = _port->get_mac_addr();
struct rte_ether_hdr* l2_hdr = rte_pktmbuf_mtod(mbuf, struct rte_ether_hdr*);
+#if RTE_VER_YEAR > 21 || (RTE_VER_YEAR == 21 && RTE_VER_MONTH == 11)
+ rte_ether_addr_copy(&_remote_mac, &l2_hdr->dst_addr);
+ rte_ether_addr_copy(&local_mac, &l2_hdr->src_addr);
+#else
rte_ether_addr_copy(&_remote_mac, &l2_hdr->d_addr);
rte_ether_addr_copy(&local_mac, &l2_hdr->s_addr);
+#endif
l2_hdr->ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
// Fill in L3 and L4 headers
dpdk::fill_rte_udp_hdr(mbuf,
diff --git a/host/lib/transport/uhd-dpdk/dpdk_common.cpp b/host/lib/transport/uhd-dpdk/dpdk_common.cpp
index a84b0f4a3..55bf57cdc 100644
--- a/host/lib/transport/uhd-dpdk/dpdk_common.cpp
+++ b/host/lib/transport/uhd-dpdk/dpdk_common.cpp
@@ -49,9 +49,9 @@ inline void separate_rte_ipv4_addr(
boost::algorithm::split(
result, ipv4, [](const char& in) { return in == '/'; }, boost::token_compress_on);
UHD_ASSERT_THROW(result.size() == 2);
- rte_ipv4_addr = (uint32_t)inet_addr(result[0].c_str());
- int netbits = std::atoi(result[1].c_str());
- netmask = htonl(0xffffffff << (32 - netbits));
+ rte_ipv4_addr = (uint32_t)inet_addr(result[0].c_str());
+ int netbits = std::atoi(result[1].c_str());
+ netmask = htonl(0xffffffff << (32 - netbits));
}
} // namespace
@@ -63,8 +63,13 @@ dpdk_port::uptr dpdk_port::make(port_id_t port,
struct rte_mempool* tx_pktbuf_pool,
std::string rte_ipv4_address)
{
- return std::make_unique<dpdk_port>(
- port, mtu, num_queues, num_desc, rx_pktbuf_pool, tx_pktbuf_pool, rte_ipv4_address);
+ return std::make_unique<dpdk_port>(port,
+ mtu,
+ num_queues,
+ num_desc,
+ rx_pktbuf_pool,
+ tx_pktbuf_pool,
+ rte_ipv4_address);
}
dpdk_port::dpdk_port(port_id_t port,
@@ -83,17 +88,6 @@ dpdk_port::dpdk_port(port_id_t port,
/* Set MTU and IPv4 address */
int retval;
- retval = rte_eth_dev_set_mtu(_port, _mtu);
- if (retval) {
- uint16_t actual_mtu;
- UHD_LOGGER_WARNING("DPDK")
- << boost::format("Port %d: Could not set mtu to %d") % _port % _mtu;
- rte_eth_dev_get_mtu(_port, &actual_mtu);
- UHD_LOGGER_WARNING("DPDK")
- << boost::format("Port %d: Current mtu=%d") % _port % actual_mtu;
- _mtu = actual_mtu;
- }
-
separate_rte_ipv4_addr(rte_ipv4_address, _ipv4, _netmask);
/* Set hardware offloads */
@@ -121,11 +115,19 @@ dpdk_port::dpdk_port(port_id_t port,
_num_queues = num_queues;
}
- struct rte_eth_conf port_conf = {};
- port_conf.rxmode.offloads = rx_offloads | DEV_RX_OFFLOAD_JUMBO_FRAME;
+ struct rte_eth_conf port_conf = {};
+#ifdef DEV_RX_OFFLOAD_JUMBO_FRAME
+ port_conf.rxmode.offloads = rx_offloads | DEV_RX_OFFLOAD_JUMBO_FRAME;
+#else
+ port_conf.rxmode.offloads = rx_offloads;
+#endif
+#if RTE_VER_YEAR > 21 || (RTE_VER_YEAR == 21 && RTE_VER_MONTH == 11)
+ port_conf.rxmode.mtu = _mtu;
+#else
port_conf.rxmode.max_rx_pkt_len = _mtu;
- port_conf.txmode.offloads = tx_offloads;
- port_conf.intr_conf.lsc = 1;
+#endif
+ port_conf.txmode.offloads = tx_offloads;
+ port_conf.intr_conf.lsc = 1;
retval = rte_eth_dev_configure(_port, _num_queues, _num_queues, &port_conf);
if (retval != 0) {
@@ -133,6 +135,17 @@ dpdk_port::dpdk_port(port_id_t port,
throw uhd::runtime_error("DPDK: Failed to configure the device");
}
+ retval = rte_eth_dev_set_mtu(_port, _mtu);
+ if (retval) {
+ uint16_t actual_mtu;
+ UHD_LOGGER_WARNING("DPDK")
+ << boost::format("Port %d: Could not set mtu to %d") % _port % _mtu;
+ rte_eth_dev_get_mtu(_port, &actual_mtu);
+ UHD_LOGGER_WARNING("DPDK")
+ << boost::format("Port %d: Current mtu=%d") % _port % actual_mtu;
+ _mtu = actual_mtu;
+ }
+
/* Set descriptor ring sizes */
uint16_t rx_desc = num_desc;
if (dev_info.rx_desc_lim.nb_max < rx_desc || dev_info.rx_desc_lim.nb_min > rx_desc
@@ -266,18 +279,27 @@ int dpdk_port::_arp_reply(queue_id_t queue_id, struct rte_arp_hdr* arp_req)
hdr = rte_pktmbuf_mtod(mbuf, struct rte_ether_hdr*);
arp_frame = (struct rte_arp_hdr*)&hdr[1];
+#if RTE_VER_YEAR > 21 || (RTE_VER_YEAR == 21 && RTE_VER_MONTH == 11)
+ rte_ether_addr_copy(&arp_req->arp_data.arp_sha, &hdr->dst_addr);
+ rte_ether_addr_copy(&_mac_addr, &hdr->src_addr);
+#else
rte_ether_addr_copy(&arp_req->arp_data.arp_sha, &hdr->d_addr);
rte_ether_addr_copy(&_mac_addr, &hdr->s_addr);
+#endif
hdr->ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_ARP);
arp_frame->arp_hardware = rte_cpu_to_be_16(RTE_ARP_HRD_ETHER);
arp_frame->arp_protocol = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
- arp_frame->arp_hlen = 6;
- arp_frame->arp_plen = 4;
- arp_frame->arp_opcode = rte_cpu_to_be_16(RTE_ARP_OP_REPLY);
+ arp_frame->arp_hlen = 6;
+ arp_frame->arp_plen = 4;
+ arp_frame->arp_opcode = rte_cpu_to_be_16(RTE_ARP_OP_REPLY);
rte_ether_addr_copy(&_mac_addr, &arp_frame->arp_data.arp_sha);
arp_frame->arp_data.arp_sip = _ipv4;
+#if RTE_VER_YEAR > 21 || (RTE_VER_YEAR == 21 && RTE_VER_MONTH == 11)
+ rte_ether_addr_copy(&hdr->dst_addr, &arp_frame->arp_data.arp_tha);
+#else
rte_ether_addr_copy(&hdr->d_addr, &arp_frame->arp_data.arp_tha);
+#endif
arp_frame->arp_data.arp_tip = arp_req->arp_data.arp_sip;
mbuf->pkt_len = 42;
@@ -619,7 +641,8 @@ struct rte_mempool* dpdk_ctx::_get_rx_pktbuf_pool(
unsigned int cpu_socket, size_t num_bufs)
{
if (!_rx_pktbuf_pools.at(cpu_socket)) {
- const int mbuf_size = _mtu + RTE_PKTMBUF_HEADROOM;
+ const int mbuf_size =
+ _mtu + RTE_PKTMBUF_HEADROOM + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
char name[32];
snprintf(name, sizeof(name), "rx_mbuf_pool_%u", cpu_socket);
_rx_pktbuf_pools[cpu_socket] = rte_pktmbuf_pool_create(name,
diff --git a/host/lib/transport/uhd-dpdk/dpdk_io_service.cpp b/host/lib/transport/uhd-dpdk/dpdk_io_service.cpp
index 4c8fa3f35..4133697ea 100644
--- a/host/lib/transport/uhd-dpdk/dpdk_io_service.cpp
+++ b/host/lib/transport/uhd-dpdk/dpdk_io_service.cpp
@@ -570,10 +570,10 @@ void dpdk_io_service::_service_xport_disconnect(dpdk::wait_req* req)
int dpdk_io_service::_service_arp_request(dpdk::wait_req* req)
{
- int status = 0;
- auto arp_req_data = (struct dpdk::arp_request*)req->data;
+ int status = 0;
+ auto arp_req_data = (struct dpdk::arp_request*)req->data;
dpdk::rte_ipv4_addr dst_addr = arp_req_data->tpa;
- auto ctx_sptr = _ctx.lock();
+ auto ctx_sptr = _ctx.lock();
UHD_ASSERT_THROW(ctx_sptr);
dpdk::dpdk_port* port = ctx_sptr->get_port(arp_req_data->port);
UHD_LOG_TRACE("DPDK::IO_SERVICE",
@@ -629,15 +629,20 @@ int dpdk_io_service::_send_arp_request(
hdr = rte_pktmbuf_mtod(mbuf, struct rte_ether_hdr*);
arp_frame = (struct rte_arp_hdr*)&hdr[1];
+#if RTE_VER_YEAR > 21 || (RTE_VER_YEAR == 21 && RTE_VER_MONTH == 11)
+ memset(hdr->dst_addr.addr_bytes, 0xFF, RTE_ETHER_ADDR_LEN);
+ hdr->src_addr = port->get_mac_addr();
+#else
memset(hdr->d_addr.addr_bytes, 0xFF, RTE_ETHER_ADDR_LEN);
- hdr->s_addr = port->get_mac_addr();
+ hdr->s_addr = port->get_mac_addr();
+#endif
hdr->ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_ARP);
- arp_frame->arp_hardware = rte_cpu_to_be_16(RTE_ARP_HRD_ETHER);
- arp_frame->arp_protocol = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
- arp_frame->arp_hlen = 6;
- arp_frame->arp_plen = 4;
- arp_frame->arp_opcode = rte_cpu_to_be_16(RTE_ARP_OP_REQUEST);
+ arp_frame->arp_hardware = rte_cpu_to_be_16(RTE_ARP_HRD_ETHER);
+ arp_frame->arp_protocol = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
+ arp_frame->arp_hlen = 6;
+ arp_frame->arp_plen = 4;
+ arp_frame->arp_opcode = rte_cpu_to_be_16(RTE_ARP_OP_REQUEST);
arp_frame->arp_data.arp_sha = port->get_mac_addr();
arp_frame->arp_data.arp_sip = port->get_ipv4();
memset(arp_frame->arp_data.arp_tha.addr_bytes, 0x00, RTE_ETHER_ADDR_LEN);
@@ -676,9 +681,18 @@ int dpdk_io_service::_rx_burst(dpdk::dpdk_port* port, dpdk::queue_id_t queue)
rte_pktmbuf_free(bufs[buf]);
break;
case RTE_ETHER_TYPE_IPV4:
+
+#if RTE_VER_YEAR > 21 || (RTE_VER_YEAR == 21 && RTE_VER_MONTH == 11)
+ if ((ol_flags & RTE_MBUF_F_RX_IP_CKSUM_MASK)
+ == RTE_MBUF_F_RX_IP_CKSUM_BAD) {
+ UHD_LOG_WARNING("DPDK::IO_SERVICE", "RX packet has bad IP cksum");
+ } else if ((ol_flags & RTE_MBUF_F_RX_IP_CKSUM_MASK)
+ == RTE_MBUF_F_RX_IP_CKSUM_NONE) {
+#else
if ((ol_flags & PKT_RX_IP_CKSUM_MASK) == PKT_RX_IP_CKSUM_BAD) {
UHD_LOG_WARNING("DPDK::IO_SERVICE", "RX packet has bad IP cksum");
} else if ((ol_flags & PKT_RX_IP_CKSUM_MASK) == PKT_RX_IP_CKSUM_NONE) {
+#endif
UHD_LOG_WARNING("DPDK::IO_SERVICE", "RX packet missing IP cksum");
} else {
_process_ipv4(port, bufs[buf], (struct rte_ipv4_hdr*)l2_data);
@@ -695,7 +709,7 @@ int dpdk_io_service::_rx_burst(dpdk::dpdk_port* port, dpdk::queue_id_t queue)
int dpdk_io_service::_process_arp(
dpdk::dpdk_port* port, dpdk::queue_id_t queue_id, struct rte_arp_hdr* arp_frame)
{
- uint32_t dest_ip = arp_frame->arp_data.arp_sip;
+ uint32_t dest_ip = arp_frame->arp_data.arp_sip;
struct rte_ether_addr dest_addr = arp_frame->arp_data.arp_sha;
UHD_LOG_TRACE("DPDK::IO_SERVICE",
"Processing ARP packet: " << dpdk::ipv4_num_to_str(dest_ip) << " -> "