From 56993d359794c818196cd4e6836d65a0c1402bfa Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Tue, 12 Sep 2023 21:15:18 +0200 Subject: [PATCH] FPGA: minor clean-up of network routines --- fpga/hls/ethernet.cpp | 7 +++---- fpga/hls/hls_jfjoch.h | 24 ------------------------ fpga/hls/icmp.cpp | 8 ++++---- fpga/hls/ipv4.cpp | 2 +- 4 files changed, 8 insertions(+), 33 deletions(-) diff --git a/fpga/hls/ethernet.cpp b/fpga/hls/ethernet.cpp index 9030761c..21b5c187 100644 --- a/fpga/hls/ethernet.cpp +++ b/fpga/hls/ethernet.cpp @@ -37,10 +37,9 @@ void ethernet(AXI_STREAM ð_in, if (state == INSPECT_HEADER) { dest = DEST_IGNORE; if (fpga_mac_addr != 0) { - ap_uint < 48 > dest_mac = get_mac_addr(packet_in.data, 0); - ap_uint < 48 > src_mac = get_mac_addr(packet_in.data, 48); - - ap_uint < 16 > ether_type = get_header_field_16(packet_in.data, 12 * 8); + ap_uint<48> dest_mac = packet_in.data(47, 0); + ap_uint<48> src_mac = packet_in.data(95, 48); + ap_uint<16> ether_type = get_header_field_16(packet_in.data, 12 * 8); if ((dest_mac == fpga_mac_addr) && (ether_type == ETHER_IP)) { state = FORWARD; diff --git a/fpga/hls/hls_jfjoch.h b/fpga/hls/hls_jfjoch.h index c98fbf1b..00652bf1 100644 --- a/fpga/hls/hls_jfjoch.h +++ b/fpga/hls/hls_jfjoch.h @@ -70,21 +70,6 @@ struct axis_addr { ap_uint<1> last; }; -struct axis_completion { - ap_uint<128> packet_mask; - ap_uint<64> frame_number; - ap_uint<64> exptime; - ap_uint<64> timestamp; - ap_uint<64> bunchid; - ap_uint<32> debug; - ap_uint<32> data_collection_id; - ap_uint<32> handle; - ap_uint<16> packet_count; - ap_uint<5> module; - ap_uint<1> flushing; - ap_uint<1> last; -}; - void setup_datamover (hls::stream &datamover_cmd_stream, uint64_t address, size_t bytes_to_write); void data_collection_fsm(AXI_STREAM ð_in, @@ -175,14 +160,6 @@ inline ap_uint<16> get_header_field_16(ap_uint<512> data, size_t position) { return retval; } -inline ap_uint<48> get_mac_addr(ap_uint<512> data, size_t position) { - return data(position+47,position); -} - -inline ap_uint<32> get_header_field_32_network_order(ap_uint<512> data, size_t position) { - return data(position+31, position); -} - static const uint8_t ECHO_REQUEST = 0x08; static const uint8_t ECHO_REPLY = 0x00; static const uint8_t PROTOCOL_ICMP = 0x01; @@ -195,7 +172,6 @@ static const uint32_t eth_payload_pos = 14 * 8; // 112 bits static const uint32_t ipv4_payload_pos = eth_payload_pos + 160; // 112 + 160 = 272 bits static const uint32_t udp_payload_pos = ipv4_payload_pos + 64; // 112 + 160 + 64 = 336 bits (42 bytes) - // Network cores #define UDP_METADATA_STREAM_WIDTH 48 #define udp_metadata_dest_port(x) x(15, 0) diff --git a/fpga/hls/icmp.cpp b/fpga/hls/icmp.cpp index 563fc18a..5b1e8b11 100755 --- a/fpga/hls/icmp.cpp +++ b/fpga/hls/icmp.cpp @@ -111,8 +111,8 @@ void icmp(AXI_STREAM& eth_in, AXI_STREAM& eth_out, uint64_t& counter, if (eth_in.read_nb(packet)) { if (state == INSPECT_HEADER) { - ap_uint < 48 > dest_mac = get_mac_addr(packet.data, 0); - ap_uint < 48 > src_mac = get_mac_addr(packet.data, 48); + ap_uint<48> dest_mac = packet.data(47, 0); + ap_uint<48> src_mac = packet.data(95, 48); // Swap MAC addresses for reply packet.data(47, 0) = src_mac; @@ -127,8 +127,8 @@ void icmp(AXI_STREAM& eth_in, AXI_STREAM& eth_out, uint64_t& counter, if ((icmp_type == ECHO_REQUEST) && (icmp_code == 0)) { - ap_uint < 32 > ipv4_src_ip = packet.data(eth_payload_pos + 127, eth_payload_pos + 96); - ap_uint < 32 > ipv4_dest_ip = packet.data(eth_payload_pos + 159, eth_payload_pos + 128); + ap_uint<32> ipv4_src_ip = packet.data(eth_payload_pos + 127, eth_payload_pos + 96); + ap_uint<32> ipv4_dest_ip = packet.data(eth_payload_pos + 159, eth_payload_pos + 128); packet.data(eth_payload_pos + 71, eth_payload_pos + 64) = 128; // IP time to live packet.data(eth_payload_pos + 95, eth_payload_pos + 80) = 0; diff --git a/fpga/hls/ipv4.cpp b/fpga/hls/ipv4.cpp index 281f3b1d..225cefdf 100644 --- a/fpga/hls/ipv4.cpp +++ b/fpga/hls/ipv4.cpp @@ -28,7 +28,7 @@ void ipv4(AXI_STREAM ð_in, ap_uint<4> ip_version = packet_in.data(eth_payload_pos + 8 - 1, eth_payload_pos + 4); ap_uint<8> ipv4_protocol = packet_in.data(eth_payload_pos + 80 - 1, eth_payload_pos + 72); - ap_uint<32> ipv4_dest_ip = get_header_field_32_network_order(packet_in.data, eth_payload_pos + 128); + ap_uint<32> ipv4_dest_ip = packet_in.data(eth_payload_pos + 128 + 31, eth_payload_pos + 128); ap_uint<16> ipv4_header_checksum_check = computeCheckSum20B(packet_in.data(eth_payload_pos + 159, eth_payload_pos)); if ((ip_version == 4) && (ipv4_dest_ip == fpga_ipv4_addr) && (ipv4_header_checksum_check == 0)) {