Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / design / sys / iop / niu / rtl / fflp_cam_sched.v
CommitLineData
86530b38
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: fflp_cam_sched.v
4// Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
5// 4150 Network Circle, Santa Clara, California 95054, U.S.A.
6//
7// * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8//
9// This program is free software; you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation; version 2 of the License.
12//
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21//
22// For the avoidance of doubt, and except that if any non-GPL license
23// choice is available it will apply instead, Sun elects to use only
24// the General Public License version 2 (GPLv2) at this time for any
25// software where a choice of GPL license versions is made
26// available with the language indicating that GPLv2 or any later version
27// may be used, or where a choice of which version of the GPL is applied is
28// otherwise unspecified.
29//
30// Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
31// CA 95054 USA or visit www.sun.com if you need additional information or
32// have any questions.
33//
34// ========== Copyright Header End ============================================
35/**********************************************************************/
36/*project name: NIU */
37/*module name: fflp_cam_sched */
38/*description: Aabitration between CPU access and packet */
39/* classification */
40/* */
41/*parent module in: none */
42/*child modules in: none */
43/*interface modules: */
44/*author name: Jeanne Cai */
45/*date created: 16-03-2004 */
46/* */
47/* Copyright (c) 2004, Sun Microsystems, Inc. */
48/* Sun Proprietary and Confidential */
49/* */
50/*modifications: */
51/**********************************************************************/
52
53
54module fflp_cam_sched
55 (
56 cclk,
57 reset,
58 cam_srch_latency,
59 cam_srch_ratio,
60 fwd_req,
61 cpu_req_cam_acc,
62 fc_fifo_space_avail,
63
64 fwd_sched,
65 cpu_sched
66 );
67
68input cclk;
69input reset;
70input[3:0] cam_srch_latency;
71input[3:0] cam_srch_ratio;
72input fwd_req;
73input cpu_req_cam_acc;
74input fc_fifo_space_avail;
75
76output fwd_sched;
77output cpu_sched;
78
79reg fwd_sched_sm;
80reg cpu_sched_sm;
81reg inc_fwd_wait_cnt;
82reg reset_fwd_cnt;
83reg[1:0] next_state;
84
85wire fwd_sched;
86wire cpu_sched;
87wire[3:0] fwd_wait_cnt_in;
88wire[3:0] fwd_wait_cnt;
89wire fwd_sched_cnt_en;
90wire[3:0] fwd_sched_cnt_in;
91wire[3:0] fwd_sched_cnt;
92wire[1:0] state;
93
94wire fwd_wait_done;
95wire fwd_reqs_served;
96
97//state machine states
98parameter
99 FWD_ARB = 2'b00,
100 FWD_IDLE = 2'b01,
101 CPU_ARB = 2'b10,
102 CPU_IDLE = 2'b11;
103
104always @ (state or fwd_req or cpu_req_cam_acc or fc_fifo_space_avail or
105 fwd_wait_done or fwd_reqs_served)
106
107begin
108
109fwd_sched_sm = 1'b0;
110cpu_sched_sm = 1'b0;
111inc_fwd_wait_cnt= 1'b0;
112reset_fwd_cnt = 1'b0;
113next_state = 2'b0;
114
115case (state) //synopsys parallel_case full_case
116// 0in < case -full -parallel -message "0in ERROR: case check in fflp_cam_sched:state"
117
118FWD_ARB:
119begin
120 if (fwd_req & fc_fifo_space_avail)
121 begin
122 fwd_sched_sm = 1'b1;
123 inc_fwd_wait_cnt= 1'b1;
124 next_state = FWD_IDLE;
125 end
126 else if (cpu_req_cam_acc)
127 begin
128 cpu_sched_sm = 1'b1;
129 inc_fwd_wait_cnt= 1'b1;
130 next_state = CPU_IDLE;
131 end
132 else
133 next_state = state;
134
135end
136
137FWD_IDLE:
138begin
139 if (fwd_wait_done & fwd_reqs_served)
140 begin
141 inc_fwd_wait_cnt= 1'b0;
142 reset_fwd_cnt = 1'b1;
143 next_state = CPU_ARB;
144 end
145 else if (fwd_wait_done)
146 begin
147 inc_fwd_wait_cnt= 1'b0;
148 next_state = FWD_ARB;
149 end
150 else
151 begin
152 inc_fwd_wait_cnt= 1'b1;
153 next_state = state;
154 end
155end
156
157CPU_ARB:
158begin
159 if (cpu_req_cam_acc)
160 begin
161 cpu_sched_sm = 1'b1;
162 inc_fwd_wait_cnt= 1'b1;
163 next_state = CPU_IDLE;
164 end
165 else if (fwd_req & fc_fifo_space_avail)
166 begin
167 fwd_sched_sm = 1'b1;
168 inc_fwd_wait_cnt= 1'b1;
169 next_state = FWD_IDLE;
170 end
171 else
172 next_state = FWD_ARB;
173end
174
175CPU_IDLE:
176begin
177 if (fwd_wait_done) //use same counter is fine here since
178 //cpu_srch and cam pio_wr_cost pretty much the same cycles
179 begin
180 inc_fwd_wait_cnt= 1'b0;
181 next_state = FWD_ARB;
182 end
183 else
184 begin
185 inc_fwd_wait_cnt= 1'b1;
186 next_state = state;
187 end
188end
189
190default: next_state = FWD_ARB;
191
192endcase
193
194end
195
196
197dffr #(2) state_reg (cclk, reset, next_state, state);
198dffr #(1) fwd_sched_reg (cclk, reset, fwd_sched_sm, fwd_sched);
199dffr #(1) cpu_sched_reg (cclk, reset, cpu_sched_sm, cpu_sched);
200dffr #(4) fwd_wait_cnt_reg (cclk, reset, fwd_wait_cnt_in, fwd_wait_cnt);
201
202assign fwd_wait_cnt_in = {4{inc_fwd_wait_cnt}} & (fwd_wait_cnt[3:0] + 4'd1);
203assign fwd_wait_done = (fwd_wait_cnt == cam_srch_latency);
204
205
206/*********************************************************************/
207//allocate load balance, cpu bandwidth
208/*********************************************************************/
209assign fwd_reqs_served = (fwd_sched_cnt == cam_srch_ratio);
210assign fwd_sched_cnt_en = fwd_sched_sm | cpu_sched_sm;
211assign fwd_sched_cnt_in = (cpu_sched_sm | reset_fwd_cnt) ? 4'b0000 : (fwd_sched_cnt + 1);
212
213dffre #(4) fwd_sched_cnt_reg (cclk, reset, fwd_sched_cnt_en, fwd_sched_cnt_in, fwd_sched_cnt);
214
215
216endmodule