diff options
author | Andrew Lynch <andrew.lynch@ni.com> | 2021-11-09 09:12:08 -0600 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2021-12-06 13:22:03 -0800 |
commit | b17d2dfa988344debe63f1b5d7e8556fef87218f (patch) | |
tree | a629c05ddf5c880eb475a36db773aaead8977cf9 /host/lib/transport | |
parent | 8ce91bc7383409602206128839a0cf2daa932319 (diff) | |
download | uhd-b17d2dfa988344debe63f1b5d7e8556fef87218f.tar.gz uhd-b17d2dfa988344debe63f1b5d7e8556fef87218f.tar.bz2 uhd-b17d2dfa988344debe63f1b5d7e8556fef87218f.zip |
dpdk: Upgrade to DPDK 19.11 API
Support DPDK versions 19.11 and 20.11
Diffstat (limited to 'host/lib/transport')
-rw-r--r-- | host/lib/transport/dpdk_simple.cpp | 6 | ||||
-rw-r--r-- | host/lib/transport/udp_dpdk_link.cpp | 20 | ||||
-rw-r--r-- | host/lib/transport/uhd-dpdk/dpdk_common.cpp | 50 | ||||
-rw-r--r-- | host/lib/transport/uhd-dpdk/dpdk_io_service.cpp | 62 |
4 files changed, 69 insertions, 69 deletions
diff --git a/host/lib/transport/dpdk_simple.cpp b/host/lib/transport/dpdk_simple.cpp index 835885cba..0e52d425d 100644 --- a/host/lib/transport/dpdk_simple.cpp +++ b/host/lib/transport/dpdk_simple.cpp @@ -129,9 +129,9 @@ public: // Extract the sender's address. This is only possible because we know // the memory layout of the buff - struct udp_hdr* udp_hdr_end = (struct udp_hdr*)buff->data(); - struct ipv4_hdr* ip_hdr_end = (struct ipv4_hdr*)(&udp_hdr_end[-1]); - struct ipv4_hdr* ip_hdr = (struct ipv4_hdr*)(&ip_hdr_end[-1]); + struct rte_udp_hdr* rte_udp_hdr_end = (struct rte_udp_hdr*)buff->data(); + struct rte_ipv4_hdr* ip_hdr_end = (struct rte_ipv4_hdr*)(&rte_udp_hdr_end[-1]); + struct rte_ipv4_hdr* ip_hdr = (struct rte_ipv4_hdr*)(&ip_hdr_end[-1]); _last_recv_addr = ip_hdr->src_addr; // Extract the buffer data diff --git a/host/lib/transport/udp_dpdk_link.cpp b/host/lib/transport/udp_dpdk_link.cpp index dc56de43c..b2fe55e24 100644 --- a/host/lib/transport/udp_dpdk_link.cpp +++ b/host/lib/transport/udp_dpdk_link.cpp @@ -101,13 +101,13 @@ udp_dpdk_link::sptr udp_dpdk_link::make(const dpdk::port_id_t port_id, void udp_dpdk_link::enqueue_recv_mbuf(struct rte_mbuf* mbuf) { // Get packet size - struct udp_hdr* hdr = rte_pktmbuf_mtod_offset( - mbuf, struct udp_hdr*, sizeof(struct ether_hdr) + sizeof(struct ipv4_hdr)); - size_t packet_size = rte_be_to_cpu_16(hdr->dgram_len) - sizeof(struct udp_hdr); + struct rte_udp_hdr* hdr = rte_pktmbuf_mtod_offset( + mbuf, struct rte_udp_hdr*, sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr)); + size_t packet_size = rte_be_to_cpu_16(hdr->dgram_len) - sizeof(struct rte_udp_hdr); // Prepare the dpdk_frame_buff auto buff = new (rte_mbuf_to_priv(mbuf)) dpdk_frame_buff(mbuf); buff->header_jump( - sizeof(struct ether_hdr) + sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr)); + sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr) + sizeof(struct rte_udp_hdr)); buff->set_packet_size(packet_size); // Add the dpdk_frame_buff to the list if (_recv_buff_head) { @@ -155,7 +155,7 @@ frame_buff::uptr udp_dpdk_link::get_send_buff(int32_t /*timeout_ms*/) if (mbuf) { auto buff = new (rte_mbuf_to_priv(mbuf)) dpdk_frame_buff(mbuf); buff->header_jump( - sizeof(struct ether_hdr) + sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr)); + sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr) + sizeof(struct rte_udp_hdr)); return frame_buff::uptr(buff); } return frame_buff::uptr(); @@ -169,12 +169,12 @@ void udp_dpdk_link::release_send_buff(frame_buff::uptr buff) if (buff_ptr->packet_size()) { // Fill in L2 header auto local_mac = _port->get_mac_addr(); - struct ether_hdr* l2_hdr = rte_pktmbuf_mtod(mbuf, struct ether_hdr*); - ether_addr_copy(&_remote_mac, &l2_hdr->d_addr); - ether_addr_copy(&local_mac, &l2_hdr->s_addr); - l2_hdr->ether_type = rte_cpu_to_be_16(ETHER_TYPE_IPv4); + struct rte_ether_hdr* l2_hdr = rte_pktmbuf_mtod(mbuf, struct rte_ether_hdr*); + rte_ether_addr_copy(&_remote_mac, &l2_hdr->d_addr); + rte_ether_addr_copy(&local_mac, &l2_hdr->s_addr); + l2_hdr->ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4); // Fill in L3 and L4 headers - dpdk::fill_udp_hdr(mbuf, + dpdk::fill_rte_udp_hdr(mbuf, _port, _remote_ipv4, _local_port, diff --git a/host/lib/transport/uhd-dpdk/dpdk_common.cpp b/host/lib/transport/uhd-dpdk/dpdk_common.cpp index 78b29513a..7ad124408 100644 --- a/host/lib/transport/uhd-dpdk/dpdk_common.cpp +++ b/host/lib/transport/uhd-dpdk/dpdk_common.cpp @@ -42,14 +42,14 @@ inline char* eal_add_opt( return ptr; } -inline void separate_ipv4_addr( - const std::string ipv4, uint32_t& ipv4_addr, uint32_t& netmask) +inline void separate_rte_ipv4_addr( + const std::string ipv4, uint32_t& rte_ipv4_addr, uint32_t& netmask) { std::vector<std::string> result; boost::algorithm::split( result, ipv4, [](const char& in) { return in == '/'; }, boost::token_compress_on); UHD_ASSERT_THROW(result.size() == 2); - ipv4_addr = (uint32_t)inet_addr(result[0].c_str()); + rte_ipv4_addr = (uint32_t)inet_addr(result[0].c_str()); int netbits = std::atoi(result[1].c_str()); netmask = htonl(0xffffffff << (32 - netbits)); } @@ -61,10 +61,10 @@ dpdk_port::uptr dpdk_port::make(port_id_t port, uint16_t num_desc, struct rte_mempool* rx_pktbuf_pool, struct rte_mempool* tx_pktbuf_pool, - std::string ipv4_address) + std::string rte_ipv4_address) { return std::make_unique<dpdk_port>( - port, mtu, num_queues, num_desc, rx_pktbuf_pool, tx_pktbuf_pool, ipv4_address); + port, mtu, num_queues, num_desc, rx_pktbuf_pool, tx_pktbuf_pool, rte_ipv4_address); } dpdk_port::dpdk_port(port_id_t port, @@ -73,7 +73,7 @@ dpdk_port::dpdk_port(port_id_t port, uint16_t num_desc, struct rte_mempool* rx_pktbuf_pool, struct rte_mempool* tx_pktbuf_pool, - std::string ipv4_address) + std::string rte_ipv4_address) : _port(port) , _mtu(mtu) , _num_queues(num_queues) @@ -94,7 +94,7 @@ dpdk_port::dpdk_port(port_id_t port, _mtu = actual_mtu; } - separate_ipv4_addr(ipv4_address, _ipv4, _netmask); + separate_rte_ipv4_addr(rte_ipv4_address, _ipv4, _netmask); /* Set hardware offloads */ struct rte_eth_dev_info dev_info; @@ -251,11 +251,11 @@ uint16_t dpdk_port::alloc_udp_port(uint16_t udp_port) return rte_cpu_to_be_16(port_selected); } -int dpdk_port::_arp_reply(queue_id_t queue_id, struct arp_hdr* arp_req) +int dpdk_port::_arp_reply(queue_id_t queue_id, struct rte_arp_hdr* arp_req) { struct rte_mbuf* mbuf; - struct ether_hdr* hdr; - struct arp_hdr* arp_frame; + struct rte_ether_hdr* hdr; + struct rte_arp_hdr* arp_frame; mbuf = rte_pktmbuf_alloc(_tx_pktbuf_pool); if (unlikely(mbuf == NULL)) { @@ -263,21 +263,21 @@ int dpdk_port::_arp_reply(queue_id_t queue_id, struct arp_hdr* arp_req) return -ENOMEM; } - hdr = rte_pktmbuf_mtod(mbuf, struct ether_hdr*); - arp_frame = (struct arp_hdr*)&hdr[1]; + hdr = rte_pktmbuf_mtod(mbuf, struct rte_ether_hdr*); + arp_frame = (struct rte_arp_hdr*)&hdr[1]; - ether_addr_copy(&arp_req->arp_data.arp_sha, &hdr->d_addr); - ether_addr_copy(&_mac_addr, &hdr->s_addr); - hdr->ether_type = rte_cpu_to_be_16(ETHER_TYPE_ARP); + rte_ether_addr_copy(&arp_req->arp_data.arp_sha, &hdr->d_addr); + rte_ether_addr_copy(&_mac_addr, &hdr->s_addr); + hdr->ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_ARP); - arp_frame->arp_hrd = rte_cpu_to_be_16(ARP_HRD_ETHER); - arp_frame->arp_pro = rte_cpu_to_be_16(ETHER_TYPE_IPv4); - arp_frame->arp_hln = 6; - arp_frame->arp_pln = 4; - arp_frame->arp_op = rte_cpu_to_be_16(ARP_OP_REPLY); - ether_addr_copy(&_mac_addr, &arp_frame->arp_data.arp_sha); + 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); + rte_ether_addr_copy(&_mac_addr, &arp_frame->arp_data.arp_sha); arp_frame->arp_data.arp_sip = _ipv4; - ether_addr_copy(&hdr->d_addr, &arp_frame->arp_data.arp_tha); + rte_ether_addr_copy(&hdr->d_addr, &arp_frame->arp_data.arp_tha); arp_frame->arp_data.arp_tip = arp_req->arp_data.arp_sip; mbuf->pkt_len = 42; @@ -418,7 +418,7 @@ void dpdk_ctx::init(const device_addr_t& user_args) device_addrs_t nics(num_dpdk_ports); RTE_ETH_FOREACH_DEV(i) { - struct ether_addr mac_addr; + struct rte_ether_addr mac_addr; rte_eth_macaddr_get(i, &mac_addr); nics[i]["dpdk_mac"] = eth_addr_to_string(mac_addr); } @@ -543,11 +543,11 @@ dpdk_port* dpdk_ctx::get_port(port_id_t port) const return _ports.at(port).get(); } -dpdk_port* dpdk_ctx::get_port(struct ether_addr mac_addr) const +dpdk_port* dpdk_ctx::get_port(struct rte_ether_addr mac_addr) const { assert(is_init_done()); for (const auto& port : _ports) { - struct ether_addr port_mac_addr; + struct rte_ether_addr port_mac_addr; rte_eth_macaddr_get(port.first, &port_mac_addr); for (int j = 0; j < 6; j++) { if (mac_addr.addr_bytes[j] != port_mac_addr.addr_bytes[j]) { diff --git a/host/lib/transport/uhd-dpdk/dpdk_io_service.cpp b/host/lib/transport/uhd-dpdk/dpdk_io_service.cpp index 1fcedca51..4c8fa3f35 100644 --- a/host/lib/transport/uhd-dpdk/dpdk_io_service.cpp +++ b/host/lib/transport/uhd-dpdk/dpdk_io_service.cpp @@ -572,7 +572,7 @@ int dpdk_io_service::_service_arp_request(dpdk::wait_req* req) { int status = 0; auto arp_req_data = (struct dpdk::arp_request*)req->data; - dpdk::ipv4_addr dst_addr = arp_req_data->tpa; + dpdk::rte_ipv4_addr dst_addr = arp_req_data->tpa; auto ctx_sptr = _ctx.lock(); UHD_ASSERT_THROW(ctx_sptr); dpdk::dpdk_port* port = ctx_sptr->get_port(arp_req_data->port); @@ -595,7 +595,7 @@ int dpdk_io_service::_service_arp_request(dpdk::wait_req* req) _send_arp_request(port, 0, arp_req_data->tpa); } else { entry = port->_arp_table.at(dst_addr); - if (is_zero_ether_addr(&entry->mac_addr)) { + if (rte_is_zero_ether_addr(&entry->mac_addr)) { UHD_LOG_TRACE("DPDK::IO_SERVICE", "ARP: Address in table, but not populated yet. Resending ARP request."); port->_arp_table.at(dst_addr)->reqs.push_back(req); @@ -603,7 +603,7 @@ int dpdk_io_service::_service_arp_request(dpdk::wait_req* req) _send_arp_request(port, 0, arp_req_data->tpa); } else { UHD_LOG_TRACE("DPDK::IO_SERVICE", "ARP: Address in table."); - ether_addr_copy(&entry->mac_addr, &arp_req_data->tha); + rte_ether_addr_copy(&entry->mac_addr, &arp_req_data->tha); status = 0; } } @@ -613,11 +613,11 @@ arp_end: } int dpdk_io_service::_send_arp_request( - dpdk::dpdk_port* port, dpdk::queue_id_t queue, dpdk::ipv4_addr ip) + dpdk::dpdk_port* port, dpdk::queue_id_t queue, dpdk::rte_ipv4_addr ip) { struct rte_mbuf* mbuf; - struct ether_hdr* hdr; - struct arp_hdr* arp_frame; + struct rte_ether_hdr* hdr; + struct rte_arp_hdr* arp_frame; mbuf = rte_pktmbuf_alloc(port->get_tx_pktbuf_pool()); if (unlikely(mbuf == NULL)) { @@ -626,21 +626,21 @@ int dpdk_io_service::_send_arp_request( return -ENOMEM; } - hdr = rte_pktmbuf_mtod(mbuf, struct ether_hdr*); - arp_frame = (struct arp_hdr*)&hdr[1]; + hdr = rte_pktmbuf_mtod(mbuf, struct rte_ether_hdr*); + arp_frame = (struct rte_arp_hdr*)&hdr[1]; - memset(hdr->d_addr.addr_bytes, 0xFF, ETHER_ADDR_LEN); + memset(hdr->d_addr.addr_bytes, 0xFF, RTE_ETHER_ADDR_LEN); hdr->s_addr = port->get_mac_addr(); - hdr->ether_type = rte_cpu_to_be_16(ETHER_TYPE_ARP); + hdr->ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_ARP); - arp_frame->arp_hrd = rte_cpu_to_be_16(ARP_HRD_ETHER); - arp_frame->arp_pro = rte_cpu_to_be_16(ETHER_TYPE_IPv4); - arp_frame->arp_hln = 6; - arp_frame->arp_pln = 4; - arp_frame->arp_op = rte_cpu_to_be_16(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, ETHER_ADDR_LEN); + memset(arp_frame->arp_data.arp_tha.addr_bytes, 0x00, RTE_ETHER_ADDR_LEN); arp_frame->arp_data.arp_tip = ip; mbuf->pkt_len = 42; @@ -657,7 +657,7 @@ int dpdk_io_service::_send_arp_request( /* Do a burst of RX on port */ int dpdk_io_service::_rx_burst(dpdk::dpdk_port* port, dpdk::queue_id_t queue) { - struct ether_hdr* hdr; + struct rte_ether_hdr* hdr; char* l2_data; struct rte_mbuf* bufs[RX_BURST_SIZE]; const uint16_t num_rx = @@ -668,20 +668,20 @@ int dpdk_io_service::_rx_burst(dpdk::dpdk_port* port, dpdk::queue_id_t queue) for (int buf = 0; buf < num_rx; buf++) { uint64_t ol_flags = bufs[buf]->ol_flags; - hdr = rte_pktmbuf_mtod(bufs[buf], struct ether_hdr*); + hdr = rte_pktmbuf_mtod(bufs[buf], struct rte_ether_hdr*); l2_data = (char*)&hdr[1]; switch (rte_be_to_cpu_16(hdr->ether_type)) { - case ETHER_TYPE_ARP: - _process_arp(port, queue, (struct arp_hdr*)l2_data); + case RTE_ETHER_TYPE_ARP: + _process_arp(port, queue, (struct rte_arp_hdr*)l2_data); rte_pktmbuf_free(bufs[buf]); break; - case ETHER_TYPE_IPv4: + case RTE_ETHER_TYPE_IPV4: 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) { UHD_LOG_WARNING("DPDK::IO_SERVICE", "RX packet missing IP cksum"); } else { - _process_ipv4(port, bufs[buf], (struct ipv4_hdr*)l2_data); + _process_ipv4(port, bufs[buf], (struct rte_ipv4_hdr*)l2_data); } break; default: @@ -693,10 +693,10 @@ 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 arp_hdr* arp_frame) + 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; - struct ether_addr dest_addr = arp_frame->arp_data.arp_sha; + 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) << " -> " << dpdk::eth_addr_to_string(dest_addr)); @@ -709,14 +709,14 @@ int dpdk_io_service::_process_arp( return -ENOMEM; } entry = new (entry) dpdk::arp_entry(); - ether_addr_copy(&dest_addr, &entry->mac_addr); + rte_ether_addr_copy(&dest_addr, &entry->mac_addr); port->_arp_table[dest_ip] = entry; } else { entry = port->_arp_table.at(dest_ip); - ether_addr_copy(&dest_addr, &entry->mac_addr); + rte_ether_addr_copy(&dest_addr, &entry->mac_addr); for (auto req : entry->reqs) { auto arp_data = (struct dpdk::arp_request*)req->data; - ether_addr_copy(&dest_addr, &arp_data->tha); + rte_ether_addr_copy(&dest_addr, &arp_data->tha); while (_servq.complete(req) == -ENOBUFS) ; } @@ -725,7 +725,7 @@ int dpdk_io_service::_process_arp( rte_spinlock_unlock(&port->_spinlock); /* Respond if this was an ARP request */ - if (arp_frame->arp_op == rte_cpu_to_be_16(ARP_OP_REQUEST) + if (arp_frame->arp_opcode == rte_cpu_to_be_16(RTE_ARP_OP_REQUEST) && arp_frame->arp_data.arp_tip == port->get_ipv4()) { UHD_LOG_TRACE("DPDK::IO_SERVICE", "Sending ARP reply."); port->_arp_reply(queue_id, arp_frame); @@ -735,7 +735,7 @@ int dpdk_io_service::_process_arp( } int dpdk_io_service::_process_ipv4( - dpdk::dpdk_port* port, struct rte_mbuf* mbuf, struct ipv4_hdr* pkt) + dpdk::dpdk_port* port, struct rte_mbuf* mbuf, struct rte_ipv4_hdr* pkt) { bool bcast = port->dst_is_broadcast(pkt->dst_addr); if (pkt->dst_addr != port->get_ipv4() && !bcast) { @@ -743,7 +743,7 @@ int dpdk_io_service::_process_ipv4( return -ENODEV; } if (pkt->next_proto_id == IPPROTO_UDP) { - return _process_udp(port, mbuf, (struct udp_hdr*)&pkt[1], bcast); + return _process_udp(port, mbuf, (struct rte_udp_hdr*)&pkt[1], bcast); } rte_pktmbuf_free(mbuf); return -EINVAL; @@ -751,7 +751,7 @@ int dpdk_io_service::_process_ipv4( int dpdk_io_service::_process_udp( - dpdk::dpdk_port* port, struct rte_mbuf* mbuf, struct udp_hdr* pkt, bool /*bcast*/) + dpdk::dpdk_port* port, struct rte_mbuf* mbuf, struct rte_udp_hdr* pkt, bool /*bcast*/) { // Get the link struct dpdk::ipv4_5tuple ht_key = {.flow_type = dpdk::flow_type::FLOW_TYPE_UDP, |