Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | // ========== Copyright Header Begin ========================================== |
2 | // | |
3 | // OpenSPARC T2 Processor File: niu_dmc_descr_ring.vr | |
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 | #include <vera_defines.vrh> | |
36 | #include "niu_dmc_descr.vrh" | |
37 | #include "niu_mem.vrh" | |
38 | #include "pio_driver.vrh" | |
39 | #include "dmc_memory_map.vri" | |
40 | ||
41 | extern CSparseMem SparseMem; | |
42 | ||
43 | #define BYTES_PER_RBR_ENTRY 4 | |
44 | #define BYTES_PER_TBR_ENTRY 64 | |
45 | ||
46 | class CDescrRing { | |
47 | bit [63:0] ring_start_addr; | |
48 | bit [63:0] ring_current_addr; | |
49 | integer ring_size; | |
50 | integer desc_ring_tail_ptr; | |
51 | integer id ; | |
52 | integer address_incr; | |
53 | integer ring_page_id; | |
54 | integer xlate_on; | |
55 | ||
56 | bit rg_wrapp = 1'b0; | |
57 | bit ring_wrapped = 1'b0; | |
58 | ||
59 | VeraList_Cdescriptor desc_ring; | |
60 | function integer get_ring_size() { | |
61 | get_ring_size = desc_ring.size(); | |
62 | } | |
63 | task new(integer i = 0) { | |
64 | id = i; | |
65 | desc_ring = new(); | |
66 | } | |
67 | task add_descriptor(Cdescriptor desc){} | |
68 | task reclaim_buffers(integer n){} | |
69 | ||
70 | task initRing( bit [63:0] address, integer size, (integer xlate = 0), (integer page = 0), | |
71 | (integer for_tx_only = 0)) | |
72 | { | |
73 | xlate_on = xlate; | |
74 | ring_page_id = page; | |
75 | ring_start_addr = address; | |
76 | if(for_tx_only) | |
77 | ring_current_addr=64'h0; | |
78 | else | |
79 | ring_current_addr =ring_start_addr; | |
80 | ring_size = size; | |
81 | printf(" DEBUG ring initialized !! start addresss - %x, current_addr - %x , size - %x xlate - %d \n",ring_start_addr,ring_current_addr, ring_size,xlate_on); | |
82 | } | |
83 | ||
84 | function integer isRingEmpty() { | |
85 | if(get_ring_size()) isRingEmpty = 0; | |
86 | else isRingEmpty = 1; | |
87 | } | |
88 | ||
89 | function integer isRingFull() { | |
90 | if(get_ring_size() < ring_size ) isRingFull = 0; | |
91 | else isRingFull = 1; | |
92 | } | |
93 | } | |
94 | ||
95 | ||
96 | ||
97 | class CRxDescrRing extends CDescrRing { | |
98 | ||
99 | VeraList_CRxdescriptor desc_ring; | |
100 | integer initial_kick; | |
101 | bit [63:0] last_address; | |
102 | task new(integer i = 0) { | |
103 | address_incr = 4; | |
104 | id = i; | |
105 | initial_kick = 1; | |
106 | desc_ring = new(); | |
107 | } | |
108 | function CRxdescriptor front() { | |
109 | front = desc_ring.front(); | |
110 | } | |
111 | task pop_front(){ | |
112 | desc_ring.pop_front(); | |
113 | } | |
114 | task push_back( CRxdescriptor desc ) { | |
115 | desc_ring.push_back(desc); | |
116 | } | |
117 | function CRxdescriptor back() { | |
118 | back = desc_ring.back(); | |
119 | //printf(" in CRxDescrRing: address - %x \n",back.blk_addr); | |
120 | } | |
121 | function integer get_ring_size() { | |
122 | get_ring_size = desc_ring.size(); | |
123 | } | |
124 | task add_descriptor(CRxdescriptor desc); | |
125 | ||
126 | task reclaim_buffers(integer n); | |
127 | ||
128 | } | |
129 | ||
130 | task CRxDescrRing::reclaim_buffers(integer n){ | |
131 | CRxdescriptor desc; | |
132 | bit[43:0] pkt_address; | |
133 | bit[43:0] xlate_address; | |
134 | integer status; | |
135 | integer pkt_page_id; | |
136 | integer i; | |
137 | ||
138 | if(get_ring_size() < n) { | |
139 | printf("ERROR CRxDescrRing::reclaim_buffers: Cannot reclaim any buffers- ring size - %d n- %d\n",get_ring_size(),n); | |
140 | return; | |
141 | } else { | |
142 | for(i=0;i<n;i++) { | |
143 | desc = this.front(); | |
144 | pkt_address = {desc.blk_addr, 12'h0}; | |
145 | pkt_page_id= desc.pkt_page_id; | |
146 | this.desc_ring.pop_front(); | |
147 | xlate_address = SparseMem.xlate_addr(pkt_address,pkt_page_id,0); | |
148 | ||
149 | printf("debug: Pkt address to be deleted - %x \n",pkt_address); | |
150 | status = SparseMem.free_addr(xlate_address,1,pkt_page_id); | |
151 | printf("debug: xlate address to be deleted - %x %d \n",xlate_address,status); | |
152 | } | |
153 | printf(" debug: New ring size after reclaiming is %d \n",get_ring_size()); | |
154 | ||
155 | ||
156 | } | |
157 | } | |
158 | ||
159 | task CRxDescrRing::add_descriptor(CRxdescriptor desc){ | |
160 | ||
161 | // Always add at the tail of the ring | |
162 | // Hardware reads from the head of the ring | |
163 | ||
164 | CRxdescriptor last_desc; | |
165 | bit [63:0] address,new_address,translated_address; | |
166 | bit [31:0] mask_address; | |
167 | // printf(" DEBUG CDescrRing::add_descriptor !! start addresss - %x, current_addr - %x , size - %x addr_incr - %d \n",ring_start_addr,ring_current_addr, ring_size,address_incr); | |
168 | ||
169 | if(initial_kick & (get_ring_size()==0)) { | |
170 | address = ring_start_addr; | |
171 | desc.sw_address = address; | |
172 | last_address = desc.sw_address; | |
173 | //new_address is the software address | |
174 | // translated_address = translate_address(address); | |
175 | translated_address = (address); | |
176 | desc.address = translated_address; | |
177 | initial_kick = 0; | |
178 | } else { | |
179 | // last_desc = back(); | |
180 | // address = last_desc.sw_address; | |
181 | address = last_address ; | |
182 | //printf("Ven_DG val of prev_desc_addr %0h\n", address); | |
183 | if(address >= (ring_start_addr + (ring_size*BYTES_PER_RBR_ENTRY - address_incr))) { | |
184 | new_address = ring_start_addr; | |
185 | } else { | |
186 | new_address = address + address_incr; // 8 bytes /descriptor | |
187 | } | |
188 | //printf("Ven_DG2 val of curr_desc_addr %0h\n", new_address); | |
189 | // new_address is the software address | |
190 | // translate this address using the translation logic | |
191 | desc.sw_address = new_address; | |
192 | last_address = desc.sw_address; | |
193 | // translated_address = translate_address(new_address); | |
194 | translated_address = (new_address); | |
195 | desc.address = translated_address; | |
196 | } | |
197 | push_back(desc); | |
198 | desc.add(xlate_on,ring_page_id); // Writes this into the memory | |
199 | if(desc.sw_address >= (ring_start_addr + (ring_size*BYTES_PER_RBR_ENTRY - address_incr))) { | |
200 | ring_current_addr = 0; | |
201 | rg_wrapp = 1'b1; | |
202 | if(~ring_wrapped) | |
203 | ring_wrapped = 1'b1; | |
204 | else | |
205 | ring_wrapped = 1'b0; | |
206 | printf("Ven_DG RNG_WRAP %0b\n",ring_wrapped); | |
207 | } else { | |
208 | ring_current_addr = (desc.sw_address - ring_start_addr) + address_incr; | |
209 | rg_wrapp = 1'b0; | |
210 | } | |
211 | //printf("Ven_DG2 val of kick_for_curr_desc %0h\n", ring_current_addr); | |
212 | ||
213 | } | |
214 | ||
215 | class CTxDescrRing extends CDescrRing { | |
216 | ||
217 | VeraList_CTxdescriptor desc_ring; | |
218 | integer tx_init_kick; | |
219 | task new(integer i = 0) { | |
220 | address_incr = 8; | |
221 | id = i; | |
222 | tx_init_kick = 1; | |
223 | desc_ring = new(); | |
224 | } | |
225 | function CTxdescriptor back() { | |
226 | back = desc_ring.back(); | |
227 | } | |
228 | function CTxdescriptor front() { | |
229 | front = desc_ring.front(); | |
230 | } | |
231 | task push_back( CTxdescriptor desc ) { | |
232 | desc_ring.push_back(desc); | |
233 | } | |
234 | function integer get_ring_size() { | |
235 | get_ring_size = desc_ring.size(); | |
236 | } | |
237 | task add_descriptor(CTxdescriptor desc); | |
238 | task reclaim_buffers(integer n); | |
239 | ||
240 | } | |
241 | ||
242 | task CTxDescrRing::reclaim_buffers(integer n){ | |
243 | ||
244 | CTxdescriptor desc; | |
245 | bit[43:0] pkt_address; | |
246 | bit[43:0] xlate_address; | |
247 | integer status; | |
248 | integer pkt_page_id; | |
249 | integer i; | |
250 | ||
251 | if(get_ring_size() < n) { | |
252 | printf("::reclaim_buffers: Cannot reclaim any buffers- ring size - %d n- %d\n",get_ring_size(),n); | |
253 | return; | |
254 | } else { | |
255 | for(i=0;i<n;i++) { | |
256 | desc = this.front(); | |
257 | pkt_address = desc.sad; | |
258 | pkt_address = pkt_address; | |
259 | pkt_page_id= desc.pkt_page_id; | |
260 | this.desc_ring.pop_front(); | |
261 | xlate_address = SparseMem.xlate_addr(pkt_address,pkt_page_id,0); | |
262 | ||
263 | printf("debug: Pkt address to be deleted - %x \n",pkt_address); | |
264 | status = SparseMem.free_addr(xlate_address,1,pkt_page_id); | |
265 | printf("debug: xlate address to be deleted - %x %d \n",xlate_address,status); | |
266 | } | |
267 | printf(" debug: New ring size after reclaiming is %d \n",get_ring_size()); | |
268 | ||
269 | } | |
270 | ||
271 | ||
272 | } | |
273 | ||
274 | task CTxDescrRing::add_descriptor(CTxdescriptor desc){ | |
275 | ||
276 | // Always add at the tail of the ring | |
277 | // Hardware reads from the head of the ring | |
278 | ||
279 | CTxdescriptor last_desc; | |
280 | bit [63:0] address,new_address,translated_address; | |
281 | bit [31:0] mask_address; | |
282 | printf(" DEBUG CDescrRing::add_descriptor !! start addresss - %x, current_addr - %x , size - %x addr_incr - %d xlate_on - %d \n",ring_start_addr,ring_current_addr, ring_size,address_incr, xlate_on); | |
283 | ||
284 | if(tx_init_kick & (get_ring_size()==0)) { | |
285 | address = ring_start_addr; | |
286 | desc.sw_address = address; | |
287 | //new_address is the software address | |
288 | // translated_address = translate_address(address); | |
289 | translated_address = (address); | |
290 | desc.address = translated_address; | |
291 | tx_init_kick = 0; | |
292 | } else { | |
293 | last_desc = back(); | |
294 | address = last_desc.sw_address; | |
295 | //printf("Ven_DG val of prev_desc_addr %0h\n", address); | |
296 | if(address >= (ring_start_addr + (ring_size*BYTES_PER_TBR_ENTRY - address_incr))) { | |
297 | new_address = ring_start_addr; | |
298 | } else { | |
299 | new_address = address + address_incr; // 8 bytes /descriptor | |
300 | } | |
301 | //printf("Ven_DG2 val of curr_desc_addr %0h\n", new_address); | |
302 | // new_address is the software address | |
303 | // translate this address using the translation logic | |
304 | desc.sw_address = new_address; | |
305 | // translated_address = translate_address(new_address); | |
306 | translated_address = (new_address); | |
307 | desc.address = translated_address; | |
308 | } | |
309 | push_back(desc); | |
310 | desc.add(xlate_on,ring_page_id); // Writes this into the memory | |
311 | if(desc.sw_address >= (ring_start_addr + (ring_size*BYTES_PER_TBR_ENTRY - address_incr))) { | |
312 | ring_current_addr = 0; | |
313 | rg_wrapp = 1'b1; | |
314 | if(~ring_wrapped) | |
315 | ring_wrapped = 1'b1; | |
316 | else | |
317 | ring_wrapped = 1'b0; | |
318 | printf("Ven_DG RNG_WRAP %0b\n",ring_wrapped); | |
319 | } else { | |
320 | ring_current_addr = (desc.sw_address - ring_start_addr) + address_incr; | |
321 | rg_wrapp = 1'b0; | |
322 | } | |
323 | //printf("Ven_DG2 val of kick_for_curr_desc %0h\n", ring_current_addr); | |
324 | ||
325 | } | |
326 |