Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / dev / network / neptune / mif.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: mif.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: @(#)mif.fth 1.1 07/01/23
43purpose:
44copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47headerless
48
49h# 1.0000 constant data-valid-bit \ bit 16 of Clause 45 frame
50
51\ TA field of IEEE802.3ae clause45 frame has two bits. When a clause45
52\ frame operation is done, the lower bit of TA (named data-valid)
53\ changes from 0 to 1. We poll this bit for the completion of the
54\ operation.
55\ Note that the low 16 bits returned by mif-frame-output-reg@
56\ are the register value if mdio-wait is called by mdio-read.
57\ If mdio-wait is called by mdio-write, then the value
58\ returned by mif-frame-output-reg@ will only be used
59\ by mdio-write for error checking purpose. (See mdio-write)
60\
61: mdio-wait ( -- [ value true ] | false )
62 d# 2000 get-msecs + false ( end-time flag)
63 h# abcd -rot ( abcd end-time flag )
64 \ abcd is a place holder, to be replaced
65 \ by read back value.
66 \ abcd and f below are value of the first loop
67 begin ( abcd end-time flag )
68 over ( abcd end-time flag end-time )
69 timed-out? ( abcd end-time flag flag )
70 0= ( abcd end-time flag flag )
71 over ( abcd end-time flag flag flag )
72 0= ( abcd end-time flag flag flag )
73 and ( abcd end-time flag flag )
74 while
75 mif-frame-output-reg@ ( abcd end-time flag data )
76 dup data-valid-bit ( abcd end-time flag data data valid-bit-mask )
77 and ( abcd end-time flag data valid? )
78 0<> if ( abcd end-time flag data )
79 h# ffff and ( abcd end-time flag val )
80 nip -rot ( val abcd end-time )
81 nip true ( val end-time flag )
82 else ( abcd end-time flag data )
83 drop ( abcd end-time flag )
84 then ( abcd end-time flag )
85 repeat ( abcd end-time flag )
86 nip dup 0= if nip then ( val true | false )
87;
88
89\ mdio-write is used to write an address or a data to a MDIO
90\ Manageable Device (MMD).
91\
92\ When it is used to write an address, the OP field of the clause45
93\ frame is b'00, the data field (low 16bits) are the register addr.
94\ When it is used to write a data, the OP field of the frame is
95\ b'10, the data field contains the 16 bit data.
96\
97\ mdio-write calls mif-frame-outout-reg! to tell the serdes
98\ the register address or data, then it calls mdio-wait which
99\ in turn calls mif-frame-output-reg@ to check the data-valid bit
100\ to see if the write operation has succeeded (and also get the
101\ written data back for checking)
102\
103: mdio-write ( frame -- )
104 dup ( frame frame )
105 mif-frame-output-reg! ( frame )
106 mdio-wait ( frame [[value true] | false] )
107 0= if ( frame [value | ] )
108 cmn-error[ " mdio-write timed out." ]cmn-end
109 drop ( )
110 else ( frame value )
111 \ When we call mdio-wait to check the data-valid bit, the
112 \ data portion (lower 16bit of the frame) should contain
113 \ the same data we just wrote to the device. Here we check
114 \ they indeed match, print an error message if not.
115 h# ffff and ( frame value&0xFFFF )
116 swap h# ffff and ( value&0xFFFF frame&0xFFFF )
117 <> if cmn-error[ " mdio-write failed." ]cmn-end then
118 then
119;
120
121\ mdio-read calls mif-frame-outout-reg! to tell the serdes
122\ the address of the register which we will read data from,
123\ then it calls mdio-wait which in turn calls mif-frame-output-reg@
124\ to check the data-valid bit and get the data from the serdes
125\
126: mdio-read ( frame -- value )
127 mif-frame-output-reg! ( )
128 mdio-wait ( value true | false )
129 0= if cmn-error[ " mdio-read timed out." ]cmn-end false then
130;
131
132
133\ --------------------Clause45 Frame------------------------------
134\ IEEE 802.3 Clause45 MDIO Frame Reg Fields
135\ ST: Start of Frame, ST=00 for Clause45, ST=01 for Clause22
136\ OP: Operation Code,
137\ PRTAD: Port Addr
138\ DEVAD: Device Addr
139\ TA: Turnaround(time)
140\
141\ Frame ST OP PRTAD DEVAD TA ADDRESS/DATA
142\ [31:30] [29:28] [27:23] [22:18] [17:16] [15:0]
143\ Address 00 00 PPPPP EEEEE 10 aaaaaaaaaaaaaaaa
144\ Write 00 01 PPPPP EEEEE 10 dddddddddddddddd
145\ Read 00 11 PPPPP EEEEE Z0 dddddddddddddddd
146\ Post-read 00 10 PPPPP EEEEE Z0 dddddddddddddddd
147\
148\ DEVAD for LSIL serdes is 0x1E
149\ PRTAD for LSIL serdes is 8 for port0 and 9 for port1
150\ So
151\ ST OP PRTAD DEVAD
152\ Addr-P0 00 00 01000 11110 10 = 047a.AAAA
153\ Addr-P1 00 00 01001 11110 10 = 04Fa.AAAA
154\ Write-P0 00 01 01000 11110 10 = 147a.DDDD
155\ Write-P1 00 01 01001 11110 10 = 14Fa.DDDD
156\ Read-P0 00 11 01000 11110 10 = 347a.DDDD
157\ Read-P1 00 11 01001 11110 10 = 34Fa.DDDD
158\
159
160\ clause45-write assembles two clause45 frames based on the 4
161\ arguments on the stack and calls mdio-write twice, first for
162\ specifying reg address and second for actual data writing.
163\
164: clause45-write ( data reg-addr PRTAD DEVAD -- )
165 d# 18 lshift swap ( data reg-addr DEVAD' PRTAD )
166 d# 23 lshift ta=10 ( data reg-addr DEVAD' PRTAD' TA )
167 or or tuck or ( data frame frame' )
168 mdio-write ( data frame )
169 or op=write or ( frame'')
170 mdio-write ( )
171;
172
173\ clause45-read assembles two clause45 frames based on the 3
174\ arguments on the stack and calls mdio-write to specify the register
175\ address and calls mdio-read to read the register data.
176\
177: clause45-read ( PRTAD DEVAD reg-addr -- value )
178 -rot ( reg-addr PRTAD DEVAD )
179 d# 18 lshift swap ( reg-addr DEVAD' PRTAD )
180 d# 23 lshift TA=10 ( reg-addr DEVAD' PRTAD' TA )
181 or or swap ( frame[27:16]=PRTAD'|DEVAD'|TA reg-addr )
182 or dup ( frame[27:0] frame[27:0] ) \ OP=WR is implied
183 mdio-write ( frame[27:0] )
184 op=read45 or ( frame[29:0] ) \ bits[15:0] are don't care
185 mdio-read ( value )
186;