OpenCores
URL https://opencores.org/ocsvn/loadbalancer/loadbalancer/trunk

Subversion Repositories loadbalancer

[/] [loadbalancer/] [trunk/] [output_port_lookup.v.bak] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 atalla
///////////////////////////////////////////////////////////////////////////////
2
// vim:set shiftwidth=3 softtabstop=3 expandtab:
3
// $Id: output_port_lookup.v 2201 2007-08-21 06:52:51Z jnaous $
4
//
5
// Module: switch_output_port.v
6
// Project: NF2.1
7
// Description: reads incoming packets parses them and decides on the output port
8
//  and adds it as a header. The design of this module assumes that only one eop
9
//  will be in the pipeline of this module at any given time.
10
//  i.e. we assume pkt length incl pkt and module headers >= 8*DATA_WIDTH bits
11
//  for a 64 bit datapath, this is 64 bytes.
12
//
13
///////////////////////////////////////////////////////////////////////////////
14
`timescale 1ns/1ps
15
  module output_port_lookup
16
    #(parameter DATA_WIDTH = 64,
17
      parameter CTRL_WIDTH=DATA_WIDTH/8,
18
      parameter UDP_REG_SRC_WIDTH = 2,
19
      parameter INPUT_ARBITER_STAGE_NUM = 2,
20
      parameter NUM_OUTPUT_QUEUES = 8,
21
      parameter STAGE_NUM = 4,
22
      parameter NUM_IQ_BITS = 3)
23
 
24
   (// --- data path interface
25
    output reg [DATA_WIDTH-1:0]        out_data,
26
    output reg [CTRL_WIDTH-1:0]        out_ctrl,
27
    output reg                         out_wr,
28
    input                              out_rdy,
29
 
30
    input  [DATA_WIDTH-1:0]            in_data,
31
    input  [CTRL_WIDTH-1:0]            in_ctrl,
32
    input                              in_wr,
33
    output                             in_rdy,
34
 
35
 
36
        input                              en,
37
    // --- Misc
38
    input                              clk,
39
    input                              reset);
40
 
41
   function integer log2;
42
      input integer number;
43
      begin
44
         log2=0;
45
         while(2**log2
46
            log2=log2+1;
47
         end
48
      end
49
   endfunction // log2
50
 
51
   //--------------------- Internal Parameter-------------------------
52
   parameter LUT_DEPTH_BITS = 4;
53
   parameter DEFAULT_MISS_OUTPUT_PORTS = 8'b01010101; // exclude the CPU queues
54
 
55
   parameter NUM_STATES = 4;
56
   parameter WAIT_TILL_DONE_DECODE = 1;
57
   parameter WRITE_HDR             = 2;
58
   parameter SKIP_HDRS             = 4;
59
   parameter WAIT_EOP              = 8;
60
 
61
   //---------------------- Wires and regs----------------------------
62
 
63
   wire                         lookup_ack;
64
   wire [47:0]                  dst_mac;
65
   wire [47:0]                  src_mac;
66
   wire [15:0]                  ethertype;
67
   wire [NUM_IQ_BITS-1:0]       src_port;
68
   wire                         eth_done;
69
   wire [NUM_OUTPUT_QUEUES-1:0] dst_ports;
70
   wire [NUM_OUTPUT_QUEUES-1:0] dst_ports_latched;
71
 
72
   wire [LUT_DEPTH_BITS-1:0]    rd_addr;          // address in table to read
73
   wire                         rd_req;           // request a read
74
   wire [NUM_OUTPUT_QUEUES-1:0] rd_oq;            // data read from the LUT at rd_addr
75
   wire                         rd_wr_protect;    // wr_protect bit read
76
   wire [47:0]                  rd_mac;           // data to match in the CAM
77
   wire                         rd_ack;           // pulses high when data is rdy
78
 
79
   wire [LUT_DEPTH_BITS-1:0]    wr_addr;
80
   wire                         wr_req;
81
   wire [NUM_OUTPUT_QUEUES-1:0] wr_oq;
82
   wire                         wr_protect;       // wr_protect bit to write
83
   wire [47:0]                  wr_mac;           // data to match in the CAM
84
   wire                         wr_ack;           // pulses high when wr is done
85
 
86
   wire                         lut_hit;          // pulses high on a hit
87
   wire                         lut_miss;         // pulses high on a miss
88
 
89
   reg                          in_fifo_rd_en;
90
   wire [CTRL_WIDTH-1:0]        in_fifo_ctrl_dout;
91
   wire [DATA_WIDTH-1:0]        in_fifo_data_dout;
92
   wire                         in_fifo_nearly_full;
93
   wire                         in_fifo_empty;
94
 
95
   reg                          dst_port_rd;
96
   wire                         dst_port_fifo_nearly_full;
97
   wire                         dst_port_fifo_empty;
98
 
99
   reg [NUM_STATES-1:0]         state, state_next;
100
 
101
   //------------------------- Modules-------------------------------
102
   ethernet_parser
103
     #(.DATA_WIDTH (DATA_WIDTH),
104
       .CTRL_WIDTH (CTRL_WIDTH),
105
       .NUM_IQ_BITS(NUM_IQ_BITS),
106
       .INPUT_ARBITER_STAGE_NUM(INPUT_ARBITER_STAGE_NUM))
107
     eth_parser
108
         (.in_data(in_data),
109
          .in_ctrl(in_ctrl),
110
          .in_wr(in_wr),
111
          .dst_mac (dst_mac),
112
          .src_mac(src_mac),
113
          .ethertype (ethertype),
114
          .eth_done (eth_done),
115
          .src_port(src_port),
116
          .reset(reset),
117
          .clk(clk));
118
 
119
 
120
   /* The size of this fifo has to be large enough to fit the previous modules' headers
121
    * and the ethernet header */
122
   small_fifo #(.WIDTH(DATA_WIDTH+CTRL_WIDTH), .MAX_DEPTH_BITS(4), .NEARLY_FULL(15))
123
      input_fifo
124
        (.din ({in_ctrl,in_data}),     // Data in
125
         .wr_en (in_wr),               // Write enable
126
         .rd_en (in_fifo_rd_en),       // Read the next word
127
         .dout ({in_fifo_ctrl_dout, in_fifo_data_dout}),
128
         .full (),
129
         .nearly_full (in_fifo_nearly_full),
130
         .empty (in_fifo_empty),
131
         .reset (reset),
132
         .clk (clk)
133
         );
134
 
135
   small_fifo #(.WIDTH(NUM_OUTPUT_QUEUES), .MAX_DEPTH_BITS(2), .NEARLY_FULL(3))
136
      dst_port_fifo
137
        (.din (dst_ports),     // Data in
138
         .wr_en (lut_hit|lut_miss),             // Write enable
139
         .rd_en (dst_port_rd),       // Read the next word
140
         .dout (dst_ports_latched),
141
         .full (),
142
         .nearly_full (dst_port_fifo_nearly_full),
143
         .empty (dst_port_fifo_empty),
144
         .reset (reset),
145
         .clk (clk)
146
         );
147
 
148
 
149
 
150
 
151
   //----------------------- Logic -----------------------------
152
 
153
   assign    in_rdy = !in_fifo_nearly_full && !dst_port_fifo_nearly_full;
154
 
155
   /*********************************************************************
156
    * Wait until the ethernet header has been decoded and the output
157
    * port is found, then write the module header and move the packet
158
    * to the output
159
    **********************************************************************/
160
   always @(*) begin
161
      out_ctrl = in_fifo_ctrl_dout;
162
      out_data = in_fifo_data_dout;
163
      state_next = state;
164
      out_wr = 0;
165
      in_fifo_rd_en = 0;
166
      dst_port_rd = 0;
167
 
168
      case(state)
169
        WAIT_TILL_DONE_DECODE: begin
170
           if(!dst_port_fifo_empty) begin
171
              dst_port_rd     = 1;
172
              state_next      = WRITE_HDR;
173
              in_fifo_rd_en   = 1;
174
           end
175
        end
176
 
177
        /* write Destionation output ports */
178
        WRITE_HDR: begin
179
           if(out_rdy) begin
180
              if(in_fifo_ctrl_dout==2'hFF) begin
181
                 out_data[31:16] = dst_ports_latched;
182
              end
183
              out_wr          = 1;
184
              in_fifo_rd_en   = 1;
185
              state_next      = SKIP_HDRS;
186
           end
187
        end
188
 
189
        /* Skip the rest of the headers */
190
        SKIP_HDRS: begin
191
           if(in_fifo_ctrl_dout==0) begin
192
              state_next = WAIT_EOP;
193
           end
194
           if(!in_fifo_empty & out_rdy) begin
195
              in_fifo_rd_en   = 1;
196
              out_wr          = 1;
197
           end
198
        end
199
 
200
        /* write all data */
201
        WAIT_EOP: begin
202
           if(in_fifo_ctrl_dout!=0)begin
203
              if(out_rdy) begin
204
                 state_next   = WAIT_TILL_DONE_DECODE;
205
                 out_wr       = 1;
206
              end
207
           end
208
           else if(!in_fifo_empty & out_rdy) begin
209
              in_fifo_rd_en   = 1;
210
              out_wr          = 1;
211
           end
212
        end // case: WAIT_EOP
213
 
214
      endcase // case(state)
215
   end // always @ (*)
216
 
217
   always @(posedge clk) begin
218
      if(reset) begin
219
         state <= WAIT_TILL_DONE_DECODE;
220
      end
221
      else begin
222
         state <= state_next;
223
      end
224
   end
225
endmodule // switch_output_port
226
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.