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 4

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

powered by: WebSVN 2.1.0

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