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

Subversion Repositories srdydrdy_lib

[/] [srdydrdy_lib/] [trunk/] [examples/] [bridge/] [rtl/] [fib_lookup_fsm.v] - Blame information for rev 31

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 ghutchis
module fib_lookup_fsm
2
  (/*AUTOARG*/
3
  // Outputs
4 31 ghutchis
  lpp_drdy, ft_wdata, ft_rd_en, ft_wr_en, ft_addr, lout_start,
5
  lout_srdy, lout_dst_vld, refup_srdy, refup_page, refup_count,
6 4 ghutchis
  // Inputs
7 31 ghutchis
  clk, reset, lpp_data, lpp_srdy, ft_rdata, lout_drdy, refup_drdy
8 4 ghutchis
  );
9
 
10
  input clk, reset;
11
 
12 31 ghutchis
  input [`PM2F_SZ-1:0] lpp_data;
13 4 ghutchis
  input                    lpp_srdy;
14
  output reg               lpp_drdy;
15
 
16
  input [`FIB_ENTRY_SZ-1:0]       ft_rdata;
17
  output reg [`FIB_ENTRY_SZ-1:0]  ft_wdata;
18 5 ghutchis
  output reg                      ft_rd_en, ft_wr_en;
19 4 ghutchis
  output reg [`FIB_ASZ-1:0]       ft_addr;
20
 
21 31 ghutchis
  output [`LL_PG_ASZ-1:0]         lout_start;
22 4 ghutchis
  output reg                      lout_srdy;
23
  input                           lout_drdy;
24 31 ghutchis
  output reg [`NUM_PORTS-1:0]     lout_dst_vld;
25 4 ghutchis
 
26 31 ghutchis
  output                          refup_srdy;
27
  input                           refup_drdy;
28
  output [`LL_PG_ASZ-1:0]         refup_page;
29
  output [`LL_REFSZ-1:0]          refup_count;
30
 
31 4 ghutchis
  wire [`FIB_ASZ-1:0]             hf_out;
32
  reg [47:0]                      hf_in;
33
 
34
  wire [`NUM_PORTS-1:0]           source_port_mask;
35
 
36
  reg [`FIB_ASZ-1:0]              init_ctr, nxt_init_ctr;
37 31 ghutchis
  reg [5:0]                       state, nxt_state;
38
  reg                             lrefup_srdy;
39
  reg [`LL_REFSZ-1:0]             lrefup_count;
40
 
41 4 ghutchis
  assign source_port_mask = 1 << lpp_data[`PAR_SRCPORT];
42 31 ghutchis
 
43
  //assign lrefup_count = count_bits (lout_dst_vld);
44
  //assign refup_page  = lpp_data[`A2F_STARTPG];
45
  assign lout_start  = lpp_data[`A2F_STARTPG];
46 4 ghutchis
 
47 31 ghutchis
  function [`LL_REFSZ-1:0] count_bits;
48
    input [`NUM_PORTS-1:0] dest;
49
    integer     i, count;
50
    begin
51
      count = 0;
52
      for (i=0; i<4; i=i+1)
53
        if (dest[i]) count = count + 1;
54
      count_bits = count;
55
    end
56
  endfunction // for
57
 
58
  sd_iohalf #(.width(`LL_PG_ASZ+`LL_REFSZ)) refup_buf
59
    (.clk (clk), .reset (reset),
60
     .c_srdy (lrefup_srdy),
61
     .c_drdy (lrefup_drdy),
62
     .c_data ({lrefup_count, lpp_data[`A2F_STARTPG]}),
63
     .p_srdy (refup_srdy),
64
     .p_drdy (refup_drdy),
65
     .p_data ({refup_count, refup_page}));
66
 
67 4 ghutchis
  basic_hashfunc #(48, `FIB_ENTRIES) hashfunc
68
    (
69
     // Outputs
70
     .hf_out                            (hf_out),
71
     // Inputs
72
     .hf_in                             (hf_in));
73
 
74
  localparam s_idle = 0, s_da_lookup = 1, s_sa_lookup = 2,
75 31 ghutchis
    s_init0 = 3, s_init1 = 4, s_wait_refup = 5;
76 4 ghutchis
  localparam ns_idle = 1, ns_da_lookup = 2, ns_sa_lookup = 4,
77 31 ghutchis
    ns_init0 = 8, ns_init1 = 16, ns_wait_refup = 1 << s_wait_refup;
78 5 ghutchis
 
79 9 ghutchis
  reg                             amux;
80
 
81
  always @*
82
    begin
83
      case (amux)
84
 
85
        1 : ft_addr = init_ctr;
86
      endcase // case (amux)
87
    end
88 4 ghutchis
 
89
  always @*
90
    begin
91
      hf_in = 0;
92
      nxt_state = state;
93 5 ghutchis
      ft_rd_en = 0;
94
      ft_wr_en = 0;
95 9 ghutchis
      amux = 0;
96 31 ghutchis
      lout_dst_vld = 0;
97 4 ghutchis
      lout_srdy = 0;
98
      lpp_drdy = 0;
99
      nxt_init_ctr = init_ctr;
100 31 ghutchis
      lrefup_srdy = 0;
101 4 ghutchis
 
102
      case (1'b1)
103
        state[s_idle] :
104
          begin
105
            // DA lookup
106 15 ghutchis
            if (lpp_srdy)
107 4 ghutchis
              begin
108 15 ghutchis
                if (lpp_data[`PAR_MACDA] & `MULTICAST)
109
                  begin
110
                    // flood the packet, don't bother to do DA lookup
111 31 ghutchis
                    lout_dst_vld = ~source_port_mask;
112 15 ghutchis
                    lout_srdy = 1;
113
                    if (lout_drdy)
114
                      nxt_state = ns_sa_lookup;
115
                  end
116
                else
117
                  begin
118
                    hf_in = lpp_data[`PAR_MACDA];
119
                    ft_rd_en = 1;
120
                    nxt_state = ns_da_lookup;
121
                  end // else: !if(lpp_data[`PAR_MACDA] & `MULTICAST)
122 4 ghutchis
              end
123
          end
124
 
125
        // results from DA lookup are available this
126
        // state.  Make forwarding decision at this
127
        // point.
128
        state[s_da_lookup] :
129
          begin
130
            // no match, flood packet
131
            if (ft_rdata[`FIB_AGE] == 0)
132
              begin
133 31 ghutchis
                lout_dst_vld = ~source_port_mask;
134 4 ghutchis
              end
135
            else
136
              begin
137 31 ghutchis
                lout_dst_vld = (1 << ft_rdata[`FIB_PORT]) & ~source_port_mask;
138 4 ghutchis
              end
139
 
140
            lout_srdy = 1;
141
            if (lout_drdy)
142
              nxt_state = ns_sa_lookup;
143
          end // case: state[s_da_lookup]
144
 
145
        // blind write out MACSA to FIB table
146
        // will bump out current occupant and update
147
        state[s_sa_lookup] :
148
          begin
149 5 ghutchis
            ft_wr_en = 1;
150 4 ghutchis
            hf_in = lpp_data[`PAR_MACSA];
151
            ft_wdata[`FIB_MACADDR] = lpp_data[`PAR_MACSA];
152
            ft_wdata[`FIB_AGE]  = `FIB_MAX_AGE;
153
            ft_wdata[`FIB_PORT] = lpp_data[`PAR_SRCPORT];
154
            nxt_state = ns_idle;
155 31 ghutchis
 
156
            lrefup_srdy = 1;
157
            if (lrefup_drdy)
158
              begin
159
                nxt_state = ns_idle;
160
                lpp_drdy = 1;
161
              end
162
            else
163
              nxt_state = ns_wait_refup;
164
          end // case: state[s_sa_lookup]
165
 
166
        state[s_wait_refup] :
167
          begin
168
            lrefup_srdy = 1;
169
            if (lrefup_drdy)
170
              begin
171
                nxt_state = ns_idle;
172
                lpp_drdy = 1;
173
              end
174 4 ghutchis
          end
175
 
176
        state[s_init0] :
177
          begin
178
            nxt_init_ctr = 0;
179
            nxt_state = ns_init1;
180
          end
181
 
182
        state[s_init1] :
183
          begin
184
            nxt_init_ctr = init_ctr + 1;
185 5 ghutchis
            ft_wr_en = 1;
186 9 ghutchis
            amux = 1;
187 4 ghutchis
            ft_wdata = 0;
188 9 ghutchis
            if (init_ctr == (`FIB_ENTRIES-1))
189 4 ghutchis
              nxt_state = ns_idle;
190
          end
191
 
192
        default :
193
          nxt_state = ns_idle;
194
      endcase // case (1'b1)
195
    end // always @ *
196
 
197
  always @(posedge clk)
198
    begin
199
      if (reset)
200
        begin
201
          init_ctr <= #1 0;
202
          state    <= #1 ns_init0;
203 31 ghutchis
          lrefup_count <= #1 0;
204 4 ghutchis
        end
205
      else
206
        begin
207
          init_ctr <= #1 nxt_init_ctr;
208
          state    <= #1 nxt_state;
209 31 ghutchis
          if (lout_srdy)
210
            lrefup_count <= #1 count_bits (lout_dst_vld);
211 4 ghutchis
        end
212
    end
213
 
214
endmodule // fib_lookup_fsm

powered by: WebSVN 2.1.0

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