// Full RTEFI Rx/Tx pipeline // // Ports are abstract GMII (maybe should adjust their names?). // Non-GMII hardware can and should add an adapter layer to get // from GMII to RGMII or the MGT. Actual GMII hardware can just // connect these ports to the physical pins. // // Up to seven clients, each handling a UDP port, attach here. // // This module instantiates a series of modules for the data path // linking GMII Rx through to GMII Tx, shown in doc/rtefi.eps. // The several steps have instance names starting with a through e // (a_scan through e_crc). // module rtefi_center #( parameter paw = 11, // packet (memory) address width, nominal 11 parameter n_lat = 3, // latency of client pipeline parameter mac_aw = 10, // sets size (in 16-bit words) of DPRAM in Tx MAC parameter handle_arp = 1, parameter handle_icmp = 1, // The following parameters set the synthesis-time default, but all // can be overridden at run-time using the configuration port. // UDP ports 0 through 7 represent the index given in udp_sel. // While udp_port_cam.v is written parameterized, we limit it to // three bits and 8 ports for timing reasons. Port 0 is internally // implemented as echo; the rest will be user-defined via synthesis-time // plug-ins. Generally the UDP port numbers should be "well known", // but the case can be made to have them run-time override-able (without // resynthesizing) to help cope with unexpected network issues. // When a udp_port number is set to 0, that port is disabled. parameter [31:0] ip = {8'd192, 8'd168, 8'd7, 8'd4}, // 192.168.7.4 parameter [47:0] mac = 48'h12555500012d, parameter udp_port0 = 7, parameter udp_port1 = 801, parameter udp_port2 = 802, parameter udp_port3 = 803, parameter udp_port4 = 0, parameter udp_port5 = 0, parameter udp_port6 = 0, parameter udp_port7 = 0 ) ( // GMII Input (Rx) input rx_clk, input [7:0] rxd, input rx_dv, input rx_er, // GMII Output (Tx) input tx_clk, output [7:0] txd, output tx_en, // Configuration // When changing configuration (like IP) at run time with these ports, // it's recommended to turn off enable_rx during that process. input enable_rx, input config_clk, input [3:0] config_a, input [7:0] config_d, input config_s, // MAC/IP address write input config_p, // UDP port number write // Host side of Tx MAC // connect the 2 below to an external 16 bit dual port ram output [mac_aw - 1: 0] host_raddr, input [15:0] host_rdata, // address where we should start transmitting from input [mac_aw - 1: 0] buf_start_addr, // set start to trigger transmission, wait for done, reset start input tx_mac_start, output tx_mac_done, // As documented in doc/clients.eps output [10:0] len_c, output [6:0] raw_l, output [6:0] raw_s, output [7:0] idata, input [7*8-1:0] mux_data_in, // collection of odata // port to Rx MAC memory output [7:0] rx_mac_d, output [11:0] rx_mac_a, output rx_mac_wen, // port to Rx MAC handshake input rx_mac_hbank, output [1:0] rx_mac_buf_status, // port to Rx MAC packet selector input rx_mac_accept, output [7:0] rx_mac_status_d, output rx_mac_status_s, // Debugging output ibadge_stb, output [7:0] ibadge_data, output obadge_stb, output [7:0] obadge_data, output xdomain_fault, // Dumb stuff to get LEDs blinking output [3:0] scanner_debug, output rx_mon, output tx_mon, // Simulation-only output in_use ); // Overhead: make sure the tools can create an IOB on all GMII inputs reg [7:0] eth_in_r=0; reg eth_in_s_r=0, eth_in_e_r=0; always @(posedge rx_clk) begin eth_in_r <= rxd; eth_in_s_r <= rx_dv; eth_in_e_r <= rx_er; end // First real step: scan the input packet wire [3:0] ip_a; reg [7:0] ip_d=0; // MAC/IP config, Rx side wire [3:0] pno_a; reg [7:0] pno_d=0; // UDP port numbers wire [7:0] sdata; wire scanner_busy; wire sdata_s, sdata_l; wire [10:0] pack_len; wire [7:0] status_vec; wire status_valid; scanner #(.handle_arp(handle_arp), .handle_icmp(handle_icmp)) a_scan( .clk(rx_clk), .eth_in(eth_in_r), .eth_in_s(eth_in_s_r), .eth_in_e(eth_in_e_r), .enable_rx(enable_rx), .ip_a(ip_a), .ip_d(ip_d), .pno_a(pno_a), .pno_d(pno_d), .busy(scanner_busy), .debug(scanner_debug), .odata(sdata), .odata_s(sdata_s), .odata_f(sdata_l), .pack_len(pack_len), .status_vec(status_vec), .status_valid(status_valid) ); assign rx_mac_status_d = status_vec; assign rx_mac_status_s = status_valid; `ifdef SIMULATE // always @(negedge rx_clk) if (status_valid) $display("Rx scanner status %x", status_vec); `endif // Second step: create data flow to DPRAM wire [paw-1:0] pbuf_a_rx, gray_state; wire [8:0] pbuf_din; pbuf_writer #(.paw(paw)) b_write(.clk(rx_clk), .data_in(sdata), .data_s(sdata_s), .data_f(sdata_l), .pack_len(pack_len), .status_vec(status_vec), .status_valid(status_valid), .mem_a(pbuf_a_rx), .mem_d(pbuf_din), .rx_mac_d(rx_mac_d), .rx_mac_a(rx_mac_a), .rx_mac_wen(rx_mac_wen), .rx_mac_hbank(rx_mac_hbank), .rx_mac_buf_status(rx_mac_buf_status), .rx_mac_accept(rx_mac_accept), .gray_state(gray_state), .badge_stb(ibadge_stb) ); assign ibadge_data = pbuf_din[7:0]; // 1 MTU DPRAM; note the ninth bit used to mark Start of Frame. // Also note the lack of a write-enable; just write every cycle. // I hate jumbo frames. Expect paw=11, so memory is big enough to hold 1500 MTU. reg [8:0] pbuf[0:(1< 1) begin : mac_b mac_subset #( .mac_aw(mac_aw), .latency(precog_latency) ) txmac ( .host_raddr(host_raddr), .host_rdata(host_rdata), .buf_start_addr(buf_start_addr), .tx_mac_start(tx_mac_start), .tx_mac_done(tx_mac_done), .scanner_busy(scanner_busy), .tx_clk(tx_clk), .mac_data(tx_mac_data), .strobe_s(tx_mac_strobe_s), .strobe_l(tx_mac_strobe_l) ); end else begin : no_mac_b assign host_raddr = 0; assign tx_mac_strobe_s = 0; assign tx_mac_strobe_l = 0; assign tx_mac_data = 0; assign tx_mac_done = 0; end endgenerate // Slide data from Tx MAC in here // XXX no cross-checking that the MAC is avoiding collisions // using precog the way it's supposed to. wire xraw2_s = xraw_s | tx_mac_strobe_s; wire xraw2_l = xraw_l | tx_mac_strobe_l; wire [7:0] raw2_d = tx_mac_strobe_s ? tx_mac_data : raw_d; // Finally, add Ethernet CRC and GMII preamble wire opack_s; wire [7:0] opack_d; ethernet_crc_add e_crc(.clk(tx_clk), .raw_s(xraw2_s), .raw_l(xraw2_l), .raw_d(raw2_d), .opack_s(opack_s), .opack_d(opack_d) ); // Make sure these outputs can be put into an IOB reg [7:0] eth_out_r=0; reg eth_out_s_r=0; always @(posedge tx_clk) begin eth_out_r <= opack_d; eth_out_s_r <= opack_s; end assign txd = eth_out_r; assign tx_en = eth_out_s_r; // Has to be distinct from the IOBs assign rx_mon = eth_in_s_r; assign tx_mon = opack_s; // Hook for testing; not intended to be connected in hardware reg [paw-1:0] in_use_timer=0; assign in_use = |in_use_timer; always @(posedge rx_clk) begin if (in_use) in_use_timer <= in_use_timer - 1; if (rx_mon) in_use_timer <= {paw{1'b1}}; end // Memory for MAC/IP addresses reg [7:0] ip_mem[0:15]; always @(posedge config_clk) if (config_s) ip_mem[config_a] <= config_d; always @(posedge rx_clk) ip_d <= ip_mem[ip_a]; always @(posedge tx_clk) ip_mem_d_tx <= ip_mem[ip_mem_a_tx]; initial begin // Matches packets in at least arp3.dat, icmp3.dat, udp3.dat. ip_mem[0] = mac[47:40]; // Start of MAC ip_mem[1] = mac[39:32]; ip_mem[2] = mac[31:24]; ip_mem[3] = mac[23:16]; ip_mem[4] = mac[15:8]; ip_mem[5] = mac[7:0]; // End of MAC ip_mem[6] = ip[31:24]; // Start of IP ip_mem[7] = ip[23:16]; ip_mem[8] = ip[15:8]; ip_mem[9] = ip[7:0]; // End of IP end // Memory for UDP port numbers reg [7:0] pno_mem[0:15]; always @(posedge config_clk) if (config_p) pno_mem[config_a] <= config_d; always @(posedge rx_clk) pno_d <= pno_mem[pno_a]; initial begin pno_mem[0] = udp_port0[15:8]; pno_mem[1] = udp_port0[7:0]; pno_mem[2] = udp_port1[15:8]; pno_mem[3] = udp_port1[7:0]; pno_mem[4] = udp_port2[15:8]; pno_mem[5] = udp_port2[7:0]; pno_mem[6] = udp_port3[15:8]; pno_mem[7] = udp_port3[7:0]; pno_mem[8] = udp_port4[15:8]; pno_mem[9] = udp_port4[7:0]; pno_mem[10] = udp_port5[15:8]; pno_mem[11] = udp_port5[7:0]; pno_mem[12] = udp_port6[15:8]; pno_mem[13] = udp_port6[7:0]; pno_mem[14] = udp_port7[15:8]; pno_mem[15] = udp_port7[7:0]; end endmodule