FPGA: minor clean-up of network routines

This commit is contained in:
2023-09-12 21:15:18 +02:00
parent b7239331ac
commit 56993d3597
4 changed files with 8 additions and 33 deletions

View File

@@ -37,10 +37,9 @@ void ethernet(AXI_STREAM &eth_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;

View File

@@ -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<axis_datamover_ctrl> &datamover_cmd_stream, uint64_t address, size_t bytes_to_write);
void data_collection_fsm(AXI_STREAM &eth_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)

View File

@@ -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;

View File

@@ -28,7 +28,7 @@ void ipv4(AXI_STREAM &eth_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)) {