Merge branch '95-calculate-tcp-checksum' into '93-network-processor'
Resolve "Calculate TCP Checksum" See merge request bslathi19/super6502!75
This commit is contained in:
@@ -18,4 +18,5 @@ src/eth_wrapper.sv
|
|||||||
src/ip_arb_mux_wrapper.sv
|
src/ip_arb_mux_wrapper.sv
|
||||||
src/ip_demux_wrapper.sv
|
src/ip_demux_wrapper.sv
|
||||||
src/tcp_dest_decap.sv
|
src/tcp_dest_decap.sv
|
||||||
src/tcp_parser.sv
|
src/tcp_parser.sv
|
||||||
|
src/checksum_calc.sv
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
module checksum_calc (
|
||||||
|
input i_rst,
|
||||||
|
input i_clk,
|
||||||
|
|
||||||
|
input i_clear,
|
||||||
|
input i_enable,
|
||||||
|
|
||||||
|
input [31:0] i_data,
|
||||||
|
|
||||||
|
output [15:0] o_checksum
|
||||||
|
);
|
||||||
|
|
||||||
|
logic [31:0] sum;
|
||||||
|
logic [15:0] sum_wrapped;
|
||||||
|
|
||||||
|
assign sum_wrapped = sum[15:0] + sum [31:16];
|
||||||
|
assign o_checksum = ~sum_wrapped;
|
||||||
|
|
||||||
|
always @(posedge i_clk) begin
|
||||||
|
if (i_rst || i_clear) begin
|
||||||
|
sum <= '0;
|
||||||
|
end else begin
|
||||||
|
if (i_enable) begin
|
||||||
|
sum <= sum + i_data[31:16] + i_data[15:0];
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
endmodule
|
||||||
@@ -24,14 +24,34 @@ module tcp_packet_generator (
|
|||||||
logic [31:0] counter, counter_next;
|
logic [31:0] counter, counter_next;
|
||||||
enum logic [1:0] {IDLE, HEADER, DATA} state, state_next;
|
enum logic [1:0] {IDLE, HEADER, DATA} state, state_next;
|
||||||
|
|
||||||
logic [15:0] checksum;
|
|
||||||
|
logic [31:0] checksum_counter, checksum_counter_next;
|
||||||
|
logic [15:0] data_checksum;
|
||||||
|
assign data_checksum = '0;
|
||||||
|
|
||||||
|
logic checksum_enable;
|
||||||
|
logic checksum_clear;
|
||||||
|
logic [31:0] checksum_data;
|
||||||
|
logic [15:0] checksum_final;
|
||||||
|
|
||||||
|
checksum_calc u_checksum_calc(
|
||||||
|
.i_rst (i_rst),
|
||||||
|
.i_clk (i_clk),
|
||||||
|
.i_clear (checksum_clear),
|
||||||
|
.i_enable (checksum_enable),
|
||||||
|
|
||||||
|
.i_data (checksum_data),
|
||||||
|
.o_checksum (checksum_final)
|
||||||
|
);
|
||||||
|
|
||||||
always_ff @(posedge i_clk) begin
|
always_ff @(posedge i_clk) begin
|
||||||
if (i_rst) begin
|
if (i_rst) begin
|
||||||
counter <= '0;
|
counter <= '0;
|
||||||
|
checksum_counter <= '0;
|
||||||
state <= IDLE;
|
state <= IDLE;
|
||||||
end else begin
|
end else begin
|
||||||
counter <= counter_next;
|
counter <= counter_next;
|
||||||
|
checksum_counter <= checksum_counter_next;
|
||||||
state <= state_next;
|
state <= state_next;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -41,11 +61,15 @@ always_comb begin
|
|||||||
m_ip.ip_payload_axis_tvalid = '0;
|
m_ip.ip_payload_axis_tvalid = '0;
|
||||||
m_ip.ip_payload_axis_tlast = '0;
|
m_ip.ip_payload_axis_tlast = '0;
|
||||||
o_packet_done = '0;
|
o_packet_done = '0;
|
||||||
|
checksum_clear = '0;
|
||||||
|
checksum_enable = '0;
|
||||||
|
|
||||||
case (state)
|
case (state)
|
||||||
|
|
||||||
IDLE: begin
|
IDLE: begin
|
||||||
counter_next = '0;
|
counter_next = '0;
|
||||||
|
checksum_counter_next = '0;
|
||||||
|
checksum_clear = '1;
|
||||||
|
|
||||||
if (i_hdr_valid) begin
|
if (i_hdr_valid) begin
|
||||||
m_ip.ip_hdr_valid = '1;
|
m_ip.ip_hdr_valid = '1;
|
||||||
@@ -65,6 +89,21 @@ always_comb begin
|
|||||||
|
|
||||||
HEADER: begin
|
HEADER: begin
|
||||||
m_ip.ip_payload_axis_tvalid = '1;
|
m_ip.ip_payload_axis_tvalid = '1;
|
||||||
|
if (checksum_counter < 8) begin
|
||||||
|
checksum_counter_next = checksum_counter + 1;
|
||||||
|
checksum_enable = '1;
|
||||||
|
end
|
||||||
|
|
||||||
|
case (checksum_counter)
|
||||||
|
0: checksum_data = m_ip.ip_source_ip;
|
||||||
|
1: checksum_data = m_ip.ip_dest_ip;
|
||||||
|
2: checksum_data = {8'b0, m_ip.ip_protocol, 16'd20}; // tcp length, not IP length
|
||||||
|
3: checksum_data = {i_source_port, i_dest_port};
|
||||||
|
4: checksum_data = i_seq_number;
|
||||||
|
5: checksum_data = i_ack_number;
|
||||||
|
6: checksum_data = {4'h5, 4'h0, i_flags, i_window_size};
|
||||||
|
7: checksum_data = '0; // checksum and urgent pointer
|
||||||
|
endcase
|
||||||
|
|
||||||
case (counter)
|
case (counter)
|
||||||
0: m_ip.ip_payload_axis_tdata = i_source_port[15:8];
|
0: m_ip.ip_payload_axis_tdata = i_source_port[15:8];
|
||||||
@@ -83,8 +122,8 @@ always_comb begin
|
|||||||
13: m_ip.ip_payload_axis_tdata = i_flags;
|
13: m_ip.ip_payload_axis_tdata = i_flags;
|
||||||
14: m_ip.ip_payload_axis_tdata = i_window_size[15:8];
|
14: m_ip.ip_payload_axis_tdata = i_window_size[15:8];
|
||||||
15: m_ip.ip_payload_axis_tdata = i_window_size[7:0];
|
15: m_ip.ip_payload_axis_tdata = i_window_size[7:0];
|
||||||
16: m_ip.ip_payload_axis_tdata = checksum[15:8];
|
16: m_ip.ip_payload_axis_tdata = checksum_final[15:8];
|
||||||
17: m_ip.ip_payload_axis_tdata = checksum[7:0];
|
17: m_ip.ip_payload_axis_tdata = checksum_final[7:0];
|
||||||
18: m_ip.ip_payload_axis_tdata = '0;
|
18: m_ip.ip_payload_axis_tdata = '0;
|
||||||
19: begin
|
19: begin
|
||||||
m_ip.ip_payload_axis_tdata = '0;
|
m_ip.ip_payload_axis_tdata = '0;
|
||||||
|
|||||||
@@ -199,6 +199,7 @@
|
|||||||
<efx:design_file name="src/sub/network_processor/src/tcp_dest_decap.sv" version="default" library="default" />
|
<efx:design_file name="src/sub/network_processor/src/tcp_dest_decap.sv" version="default" library="default" />
|
||||||
<efx:design_file name="src/sub/network_processor/src/tcp_packet_generator.sv" version="default" library="default" />
|
<efx:design_file name="src/sub/network_processor/src/tcp_packet_generator.sv" version="default" library="default" />
|
||||||
<efx:design_file name="src/sub/network_processor/src/tcp_tx_ctrl.sv" version="default" library="default" />
|
<efx:design_file name="src/sub/network_processor/src/tcp_tx_ctrl.sv" version="default" library="default" />
|
||||||
|
<efx:design_file name="src/sub/network_processor/src/checksum_calc.sv" version="default" library="default" />
|
||||||
<efx:design_file name="src/sub/interfaces/axil_intf.sv" version="default" library="default" />
|
<efx:design_file name="src/sub/interfaces/axil_intf.sv" version="default" library="default" />
|
||||||
<efx:design_file name="src/sub/interfaces/axis_intf.sv" version="default" library="default" />
|
<efx:design_file name="src/sub/interfaces/axis_intf.sv" version="default" library="default" />
|
||||||
<efx:design_file name="src/sub/interfaces/ip_intf.sv" version="default" library="default" />
|
<efx:design_file name="src/sub/interfaces/ip_intf.sv" version="default" library="default" />
|
||||||
|
|||||||
Reference in New Issue
Block a user