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 5

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 ghutchis
module fib_lookup_fsm
2
  (/*AUTOARG*/
3
  // Outputs
4 5 ghutchis
  lpp_drdy, ft_wdata, ft_rd_en, ft_wr_en, ft_addr, lout_data,
5
  lout_srdy, lout_dst_vld,
6 4 ghutchis
  // Inputs
7
  clk, reset, lpp_data, lpp_srdy, ft_rdata, lout_drdy
8
  );
9
 
10
  input clk, reset;
11
 
12
  input [`PAR_DATA_SZ-1:0] lpp_data;
13
  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
  output reg [`NUM_PORTS-1:0]     lout_data;
22
  output reg                      lout_srdy;
23
  input                           lout_drdy;
24 5 ghutchis
  output [`NUM_PORTS-1:0]         lout_dst_vld;
25 4 ghutchis
 
26
  wire [`FIB_ASZ-1:0]             hf_out;
27
  reg [47:0]                      hf_in;
28
 
29
  wire [`NUM_PORTS-1:0]           source_port_mask;
30
 
31
  reg [`FIB_ASZ-1:0]              init_ctr, nxt_init_ctr;
32
  reg [4:0]                       state, nxt_state;
33
 
34
  assign source_port_mask = 1 << lpp_data[`PAR_SRCPORT];
35
 
36
  basic_hashfunc #(48, `FIB_ENTRIES) hashfunc
37
    (
38
     // Outputs
39
     .hf_out                            (hf_out),
40
     // Inputs
41
     .hf_in                             (hf_in));
42
 
43
  localparam s_idle = 0, s_da_lookup = 1, s_sa_lookup = 2,
44
    s_init0 = 3, s_init1 = 4;
45
  localparam ns_idle = 1, ns_da_lookup = 2, ns_sa_lookup = 4,
46
    ns_init0 = 8, ns_init1 = 16;
47 5 ghutchis
 
48
  // send all results back to their originating port
49
  assign lout_dst_vld = source_port_mask;
50 4 ghutchis
 
51
  always @*
52
    begin
53
      hf_in = 0;
54
      nxt_state = state;
55 5 ghutchis
      ft_rd_en = 0;
56
      ft_wr_en = 0;
57 4 ghutchis
      ft_addr = hf_out;
58
      lout_data = 0;
59
      lout_srdy = 0;
60
      lpp_drdy = 0;
61
      nxt_init_ctr = init_ctr;
62
 
63
      case (1'b1)
64
        state[s_idle] :
65
          begin
66
            // DA lookup
67
            if (lpp_data[`PAR_MACDA] & `MULTICAST)
68
              begin
69
                // flood the packet, don't bother to do DA lookup
70
                lout_data = ~source_port_mask;
71
                lout_srdy = 1;
72
                if (lout_drdy)
73
                  nxt_state = ns_sa_lookup;
74
              end
75
            else if (lpp_srdy)
76
              begin
77
                hf_in = lpp_data[`PAR_MACDA];
78 5 ghutchis
                ft_rd_en = 1;
79 4 ghutchis
                nxt_state = ns_da_lookup;
80
              end
81
          end
82
 
83
        // results from DA lookup are available this
84
        // state.  Make forwarding decision at this
85
        // point.
86
        state[s_da_lookup] :
87
          begin
88
            // no match, flood packet
89
            if (ft_rdata[`FIB_AGE] == 0)
90
              begin
91
                lout_data = ~source_port_mask;
92
              end
93
            else
94
              begin
95
                lout_data = 1 << ft_rdata[`FIB_PORT];
96
              end
97
 
98
            lout_srdy = 1;
99
            if (lout_drdy)
100
              nxt_state = ns_sa_lookup;
101
          end // case: state[s_da_lookup]
102
 
103
        // blind write out MACSA to FIB table
104
        // will bump out current occupant and update
105
        state[s_sa_lookup] :
106
          begin
107 5 ghutchis
            ft_wr_en = 1;
108 4 ghutchis
            hf_in = lpp_data[`PAR_MACSA];
109
            ft_wdata[`FIB_MACADDR] = lpp_data[`PAR_MACSA];
110
            ft_wdata[`FIB_AGE]  = `FIB_MAX_AGE;
111
            ft_wdata[`FIB_PORT] = lpp_data[`PAR_SRCPORT];
112
            nxt_state = ns_idle;
113
            lpp_drdy = 1;
114
          end
115
 
116
        state[s_init0] :
117
          begin
118
            nxt_init_ctr = 0;
119
            nxt_state = ns_init1;
120
          end
121
 
122
        state[s_init1] :
123
          begin
124
            nxt_init_ctr = init_ctr + 1;
125 5 ghutchis
            ft_wr_en = 1;
126 4 ghutchis
            ft_addr = init_ctr;
127
            ft_wdata = 0;
128
            if (ft_addr == (`FIB_ENTRIES-1))
129
              nxt_state = ns_idle;
130
          end
131
 
132
        default :
133
          nxt_state = ns_idle;
134
      endcase // case (1'b1)
135
    end // always @ *
136
 
137
  always @(posedge clk)
138
    begin
139
      if (reset)
140
        begin
141
          init_ctr <= #1 0;
142
          state    <= #1 ns_init0;
143
        end
144
      else
145
        begin
146
          init_ctr <= #1 nxt_init_ctr;
147
          state    <= #1 nxt_state;
148
        end
149
    end
150
 
151
endmodule // fib_lookup_fsm

powered by: WebSVN 2.1.0

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