Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / dev / network / bge / bge-core.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: bge-core.fth
4\
5\ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6\
7\ - Do no alter or remove copyright notices
8\
9\ - Redistribution and use of this software in source and binary forms, with
10\ or without modification, are permitted provided that the following
11\ conditions are met:
12\
13\ - Redistribution of source code must retain the above copyright notice,
14\ this list of conditions and the following disclaimer.
15\
16\ - Redistribution in binary form must reproduce the above copyright notice,
17\ this list of conditions and the following disclaimer in the
18\ documentation and/or other materials provided with the distribution.
19\
20\ Neither the name of Sun Microsystems, Inc. or the names of contributors
21\ may be used to endorse or promote products derived from this software
22\ without specific prior written permission.
23\
24\ This software is provided "AS IS," without a warranty of any kind.
25\ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
26\ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
27\ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
28\ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
29\ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
30\ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
31\ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
32\ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
33\ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
34\ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
35\ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
36\
37\ You acknowledge that this software is not designed, licensed or
38\ intended for use in the design, construction, operation or maintenance of
39\ any nuclear facility.
40\
41\ ========== Copyright Header End ============================================
42id: @(#)bge-core.fth 1.6 07/05/31
43purpose: Core routines
44copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47headerless
48
49instance variable txpi \ Transmit Ring Producer Index
50instance variable rrci \ Receive Return Ring Consumer Index
51
52: txci@ ( -- txci ) status-blk 1 >status-tx-ci-n local-w@ ;
53: txpi@ ( -- txpi ) txpi @ ;
54: txpi! ( data -- ) txpi ! ;
55
56: rrpi@ ( -- rrpi ) status-blk 1 >status-rx-pi-n local-w@ ;
57: rrci@ ( -- rrci ) rrci @ ;
58: rrci! ( data -- ) rrci ! ;
59
60instance variable nextstdbd \ Pointer to next RX producer ring descriptor
61instance variable nextrrbd \ Pointer to next RX completion ring descriptor
62instance variable nexttxbd \ Pointer to next TX message descriptor
63
64\ Get current rx completion/tx message descriptor ring pointer (on CPU side).
65: nexttxbd@ ( -- txbdadr ) nexttxbd @ ;
66: nextrrbd@ ( -- rrbdadr ) nextrrbd @ ;
67: nextstdbd@ ( -- stdbd-adr ) nextstdbd @ ;
68
69\ Set current rx completion/tx message descriptor ring pointer (on CPU side).
70: nexttxbd! ( txbdadr -- ) nexttxbd ! ;
71: nextrrbd! ( rrbdadr -- ) nextrrbd ! ;
72: nextstdbd! ( stdbd-adr -- ) nextstdbd ! ;
73
74headers \ Useful Debug routines
75
76: force-coal ( -- ) \ force DMA Coalesce
77 8 h# 3c00 breg-bset
78;
79
80: status-buf ( -- adr len )
81 cpu-dma-base >dma-status-blk /status-blk
82;
83
84: mask-broadcast ( -- ) \ drop broadcast packets...
85 h# c200.0000 h# 480 breg!
86 h# 8600.0004 h# 488 breg!
87;
88
89headerless
90
91: enter-isr ( -- )
92 cpu-dma-base >dma-status-blk >status-tag local@ d# 24 << hpm-im0 breg!
93;
94
95: exit-isr ( -- )
96 0 hpm-im0 breg!
97;
98
99\ RX return consumer ring address calculations
100: rrci>rrbdadr ( n -- adr ) /rxring mod /rxbd * rrbd0 + ;
101: rrbdadr>rrci ( adr -- n ) rrbd0 - /rxbd / /rxring mod ;
102
103\ TX producer ring address calculations
104: txpi>txbdadr ( n -- adr ) /txring mod /txbd * txbd0 + ;
105: txbdadr>txpi ( adr -- n ) txbd0 - /txbd / /txring mod ;
106
107\ Standard Rx producer ring address calculations
108: stdpi>stdadr ( n -- adr ) /std-ring mod /rxbd * std0 + ;
109: stdadr>stdpi ( adr -- n ) std0 - /rxbd / /std-ring mod ;
110
111\ RX buffer address calculations
112: rxbuf#>rxbufadr ( n -- adr ) #rxbufs mod /rxbuf * rxbuf0 + ;
113: txbuf#>txbufadr ( n -- adr ) #txbufs mod /txbuf * txbuf0 + ;
114
115\ TX descriptor fields
116: txlength@ ( txbdadr -- len ) >txbd-len local-w@ ;
117: txlength! ( len txbdadr -- ) >txbd-len local-w! ;
118
119: txbufptr@ ( txbdadr -- adr ) drop txbuf0 ; \ ## Only 1 tx buffer needed
120: txbufptr! ( bufptr txbdadr -- ) 2drop ; \ ## Only 1 tx buffer needed
121
122\ RX descriptor fields
123: rxbufptr! ( bufptr rmdadr -- ) >rxbd-host-adr local-x! ;
124: rxbufptr@ ( rmdadr -- bufptr ) >rxbd-host-adr local-x@ ;
125
126\ Sync DMA address
127: sync-buf ( cpu-adr size -- ) over cpu>io-adr swap dma-sync ;
128
129\ TX descriptor initialization
130: txbd-init ( txbuf len txbdadr -- )
131 >r
132 r@ >txbd-len local-w!
133 cpu>io-adr r@ >txbd-host-adr local-x!
134 h# 84 r@ >txbd-flags local-w! \ Coalesce now, packet-end flag
135 0 r@ >txbd-rsvd local-w!
136 0 r@ >txbd-vlan local-w!
137 r> /txbd sync-buf
138;
139
140: rxlength@ ( rrbdadr -- len ) >rxbd-len local-w@ ;
141
142: rrci>pkt-len ( rrbdd# -- pkt-len )
143 rrci>rrbdadr rxlength@
144;
145
146: rrci>pkt-adr ( rrci -- pkt-adr )
147 rrci>rrbdadr >rxbd-host-adr local-x@ io>cpu-adr
148;
149
150: init-std-rbd ( rxbufadr rxbufsize stdadr -- )
151 >r
152 r@ stdadr>stdpi
153 r@ >rxbd-index local-w!
154 r@ >rxbd-len local-w!
155 r@ >rxbd-host-adr local-x!
156 0 r@ >rxbd-type local-w!
157 0 r@ >rxbd-flags local-w!
158 0 r@ >rxbd-ip-cksum local-w!
159 0 r@ >rxbd-tcp-cksum local-w!
160 0 r> >rxbd-err-flags local-w!
161;
162
163false instance value restart? \ To flag serious errors
164defer restart-net ( -- ok? ) \ To reinitialize after a serious error
165['] true to restart-net
166
167instance variable rxerr-status \ RXBD error status
168
169: rxerr-status@ ( -- data ) rxerr-status @ ;
170: rxerr-status! ( data -- ) rxerr-status ! ;
171
172: txmac-status@ ( -- data ) h# 460 breg@ ;
173
174: receive-errors? ( rxbdadr -- data )
175 dup >rxbd-flags local-w@ rxbd-flags.frame-err and 0<> ( rxbdadr error? )
176 swap >rxbd-err-flags local-w@ and ( error-data )
177 dup rxerr-status!
178;
179
180: transmit-errors? ( -- data )
181 txmac-status@ h# 30 and
182;
183
184\ Display transmit errors
185: .transmit-errors ( -- )
186 transmit-errors?
187 dup h# 10 and if cmn-error[ " TX Underrun" ]cmn-end then
188 h# 20 and if cmn-error[ " TX Overrun" ]cmn-end then
189;
190
191\ Display receive errors
192: .receive-errors ( -- )
193 rxerr-status@
194 dup rxbd-err.bad-crc and if cmn-error[ " RX Bad CRC" ]cmn-end then
195 dup rxbd-err.coll-detect and if cmn-error[ " RX Collision Detected" ]cmn-end then
196 dup rxbd-err.link-lost and if cmn-error[ " RX Link Lost" ]cmn-end then
197 dup rxbd-err.phy-err and if cmn-error[ " RX Phy Error" ]cmn-end then
198 dup rxbd-err.odd-nibble and if cmn-error[ " RX Odd # of Nibbles" ]cmn-end then
199 dup rxbd-err.mac-abort and if cmn-error[ " RX Mac Abort" ]cmn-end then
200 dup rxbd-err.too-small and if cmn-error[ " RX Packet < 64 bytes" ]cmn-end then
201 dup rxbd-err.truncated and if cmn-error[ " RX Packet Truncated" ]cmn-end then
202 rxbd-err.giant and if cmn-error[ " RX Packet > MTU Size" ]cmn-end then
203;
204
205\ Clear TX error bits in cached values and registers
206: clear-tx-errors ( -- )
207 h# 460 dup breg@ h# 30 or swap breg!
208;
209
210\ Clear RX error status
211: clear-rx-errors ( -- )
212 0 rxerr-status!
213;
214
215: get-tx-buffer ( -- txbufptr )
216 nexttxbd@ txbufptr@
217;
218
219\ Update mailbox Producer Index and Standard Producer Index
220: to-next-rrbd ( -- )
221 nextstdbd@ stdadr>stdpi dup hpm-spr-pi breg!
222 1+ stdpi>stdadr nextstdbd!
223;
224
225\ Get free buffer address and Initialize the next Standard Buffer Descriptor
226: reclaim-buffer ( rrbdadr -- )
227 rrbdadr>rrci rrci>pkt-adr cpu>io-adr /rxbuf
228 nextstdbd@ init-std-rbd
229;
230
231: ownership@ ( rbdadr -- pkt-waiting? )
232 rrbdadr>rrci /rxring mod rrpi@ <>
233;
234
235: return-buffer ( stdbdadr -- )
236 reclaim-buffer
237 to-next-rrbd
238;
239
240: receive-ready? ( -- pkt-waiting? )
241 nextrrbd@ dup /rxbd sync-buf \ Sync before looking at descriptor
242 ownership@
243;
244
245: receive ( -- pkt-handle pkt pktlen )
246 enter-isr
247 nextrrbd@ dup rrbdadr>rrci ( rrci )
248 dup hpm-rrci0 breg! ( rrci )
249 dup 1+ rrci>rrbdadr nextrrbd! ( rrci )
250 dup rrci>rrbdadr ( rrci rrbd-adr )
251
252 \ Drop packet on receive errors
253 receive-errors? if ( rrci )
254 .receive-errors clear-rx-errors ( rrci )
255 restart? if restart-net drop then
256 rrci>pkt-adr 0 exit ( pkt-adr 0 )
257 then ( rrci )
258
259 dup rrci>pkt-adr swap rrci>pkt-len ( pktadr pktlen )
260 2dup sync-buf ( pktadr pktlen )
261 exit-isr
262;
263
264\ *** Main transmit routines ***
265
266: transmit-complete? ( -- complete? ) \ Complete when the txpi=txci+1
267 txpi@ ( txpi-1 )
268 txci@ /txring mod = ( txpi-1 txci )
269;
270
271: send-wait ( -- ok? )
272 d# 4000 get-msecs +
273 begin
274 dup get-msecs >=
275 transmit-complete? 0= and 0=
276 until
277 drop transmit-complete? \ last try
278 dup 0= if
279 " Timeout waiting for transmit completion" diag-type-cr
280 true to restart?
281 then
282;
283
284: transmit ( txbuf len -- ok? )
285 enter-isr ( txbuf len )
286 2dup sync-buf ( txbuf len )
287 nexttxbd@ txbd-init ( )
288 nexttxbd@ txbdadr>txpi 1+ /txring mod ( txpi )
289 dup hpm-txpi0 breg! ( txpi )
290 dup txpi! ( txpi )
291 txpi>txbdadr nexttxbd! ( )
292 send-wait ( ok? )
293 transmit-errors? if
294 .transmit-errors clear-tx-errors drop false
295 restart? if restart-net drop then
296 then
297 exit-isr
298;
299
300
301: net-on ( -- ok? )
302 #rxbufs stdpi>stdadr nextstdbd! \ next uninitialized stdbd
303 txbd0 nexttxbd!
304 rrbd0 nextrrbd!
305 init-mac 0=
306;
307
308: disable-sm ( timeout register -- ) \ Disable state machine
309 >r
310 2 r@ breg-bclear
311 begin
312 r@ breg@ 2 and over 0<> and
313 while
314 1- 1 ms
315 repeat r> 2drop
316;
317
318: disable-rx-sms ( -- )
319 2 h# 468 disable-sm \ RX mac
320 2 h# 2c00 disable-sm \ RX BD Initiator
321 2 h# 2000 disable-sm \ RX List Placement
322 2 h# 3400 disable-sm \ RX List Selector
323 2 h# 2400 disable-sm \ RX Data BD Initiator
324 2 h# 2800 disable-sm \ RX Data Completion
325 2 h# 3000 disable-sm \ RX BD Completion
326;
327
328: disable-tx-sms ( -- )
329 2 h# 1400 disable-sm \ TX BD Selector
330 2 h# 1800 disable-sm \ TX BD Initiator
331 2 h# 0c00 disable-sm \ TX Data Initiator
332 4 h# 4800 disable-sm \ Read DMA
333 2 h# 1000 disable-sm \ Tx Data Completion
334 2 h# 6400 disable-sm \ DMA Completion
335 2 h# 1c00 disable-sm \ TX BD Completion
336 2 h# 045c disable-sm \ TX Mac
337;
338
339: disable-mem-sms ( -- )
340 2 h# 3c00 disable-sm \ Host Coalescing
341 4 h# 4c00 disable-sm \ DMA Write Mode
342 2 h# 3800 disable-sm \ MBUF Cluster
343
344[ifdef] ipmifw-support
345 \ Do not issue FTQ reset when IPMI/ASF fw is enabled
346 ipmifw-enabled? not if
347[then]
348 h# ffff.ffff h# 5c00 breg! \ FTQ reset register
349 0 h# 5c00 breg!
350[ifdef] ipmifw-support
351 then
352[then]
353
354 2 h# 4400 disable-sm \ Buffer Manager
355 2 h# 4000 disable-sm \ Memory Arbitrator
356;
357
358\ To properly shutdown, the we have to disable several state machines
359\ in the proper order.
360
361: net-off ( -- )
362
363[ifdef] ipmifw-support
364 ipmifw-enabled? if
365 pause-ipmifw \ Pause IPMI/ASF fw
366 bootcode-sig! \ Write bootcode magic KevT
367 then
368[then]
369
370 disable-rx-sms \ Disable Receive State Machines
371 disable-tx-sms \ Disable Transmit State Machines
372 disable-mem-sms \ Disable Memory State Machines
373 2 h# 6808 breg! \ Clear interrupt state
374
375[ifdef] ipmifw-support
376 enable-mem-access \ Ensure endianness, mem space, arbtr
377 ipmifw-enabled? if
378 reset-core-clks \ GRC reset - restarts IPMI/ASF fw
379 enable-mem-access \ Ensure endianness, mem space, arbtr
380 check-bootcode-compl \ Check bootcode compliment ~KevT
381 fcode-state-unload state-sig! \ send fcode driver unload notice
382 then
383[else]
384 reset-core-clks \ leave MAC in reset state
385[then]
386
387;
388