Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: xmac.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 ============================================ | |
42 | id: @(#)xmac.fth 1.2 07/03/21 | |
43 | purpose: | |
44 | copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved | |
45 | copyright: Use is subject to license terms. | |
46 | ||
47 | headerless | |
48 | ||
49 | : xmac-init-protocol-param-regs ( -- ) | |
50 | h# 2d0a03 xmac-ipg! \ Inter Packet Gap 0 | |
51 | h# 4002040 xmac-min! \ Min Frame Size | |
52 | h# 5ee xmac-max! \ Max Frame & Burst Size | |
53 | ; | |
54 | \ 2d0a03 = 0010 1101 0000 1010 0000 0011 | |
55 | \ bits[ 2:0] ipg_value =0x3 : 12~15B IPG for xgmii | |
56 | \ bits[15:8] ipg_value1 =0xa : 12B IPG for mii/gmii | |
57 | \ bits[20:16] stretch ratio=0xd | |
58 | \ bits[23:21] stretch const=0x1 | |
59 | \ | |
60 | \ 4002040 = 0100 0000 0000 0010 0000 0100 0000 | |
61 | \ bits[ 9:0] TxMinPacketSize 0x40 64B | |
62 | \ bits[17:10] SlotTime 0x8 64 byte time | |
63 | \ bits[19:18] Reserved (assume) 0x0 | |
64 | \ bits[29:20] RxMinPacketSize 0x40 64B | |
65 | ||
66 | ||
67 | \ For an MAC addr=aa:bb:cc:dd:11:22, the three registers | |
68 | \ should be set as follows, | |
69 | \ XMAC_ADDR0=11:22, XMAC_ADDR1=cc:dd, XMAC_ADDR2=aa:bb | |
70 | \ | |
71 | : xmac-init-macaddr-regs ( -- ) | |
72 | mac-address ( addr len ) | |
73 | drop ( addr ) | |
74 | ||
75 | dup c@ 8 lshift ( addr aa00 ) \ aa: most significant mac byte | |
76 | over 1 + c@ or ( addr aabb ) | |
77 | xmac-addr2! ( addr ) | |
78 | ||
79 | dup 2 + c@ 8 lshift ( addr cc00 ) | |
80 | over 3 + c@ or ( addr ccdd ) | |
81 | xmac-addr1! ( addr ) | |
82 | ||
83 | dup 4 + c@ 8 lshift ( addr 1100 ) | |
84 | swap 5 + c@ or ( 1122 ) | |
85 | xmac-addr0! ( ) | |
86 | ||
87 | \ Alternate addresses (XMAC_ADDRx, x = 3 ~ 50) | |
88 | d# 48 0 do 0 i xmac-addr-i! loop | |
89 | ||
90 | \ Disable comparison with alternate MAC addr by clearing the register. | |
91 | 0 xmac-addr-cmpen! | |
92 | ; | |
93 | ||
94 | \ The 5 XMAC addr filter and mask registers starting at offset 0x818 | |
95 | : xmac-init-address-filter-regs ( -- ) | |
96 | 3 0 do 0 i xmac-add-filt-i! loop | |
97 | 0 xmac-add-filt12-mask! | |
98 | 0 xmac-add-filt00-mask! | |
99 | ; | |
100 | ||
101 | \ The 16 hash table registers starting at offset 0x840 | |
102 | : xmac-init-hashtable-regs ( -- ) | |
103 | d# 16 0 do 0 i xmac-hash-tbl-i! loop | |
104 | ; | |
105 | ||
106 | : xmac-init-counters ( -- ) | |
107 | 0 rxmac-bt-cnt! \ etherStatsOctes | |
108 | 0 rxmac-bt-frm-cnt! \ etherStatsBroadcastPkt | |
109 | 0 rxmac-mc-frm-cnt! \ etherStatsMulticastPkt | |
110 | 0 rxmac-frag-cnt! \ Receive Fragments Counter | |
111 | 0 rxmac-hist-cnt1! \ etherStatsPkts64Bytes , Histogram Cnt1 | |
112 | 0 rxmac-hist-cnt2! \ etherStatsPkts127Bytes | |
113 | 0 rxmac-hist-cnt3! \ etherStatsPkts128to255Bytes | |
114 | 0 rxmac-hist-cnt4! \ etherStatsPkts256to511Bytes | |
115 | 0 rxmac-hist-cnt5! \ etherStatsPkts512to1023Bytes | |
116 | 0 rxmac-hist-cnt6! \ etherStatsPkts1024to1522Bytes | |
117 | 0 rxmac-mpszer-cnt! \ Maximun Packet Length Error | |
118 | 0 rxmac-crc-er-cnt! \ RxMAC CRC Error Counter | |
119 | 0 mac-cd-vio-cnt! \ Rx Code Violation Counter | |
120 | 0 rxmac-al-er-cnt! \ Alignment Error Counter | |
121 | 0 txmac-frm-cnt! \ Transmit Frame Coutner | |
122 | 0 txmac-byte-cnt! \ Transmit Byte Coutner | |
123 | 0 link-fault-cnt! \ Link Fault Counter | |
124 | 0 rxmac-hist-cnt7! \ etherStatsPkts1523 and more bytes cnt | |
125 | ; | |
126 | ||
127 | : init-xmac ( -- ) | |
128 | xmac-init-protocol-param-regs \ XMAC_IPG, XMAC_MIN, XMAC_MAX | |
129 | xmac-init-macaddr-regs \ XMAC_ADDR... | |
130 | xmac-init-address-filter-regs \ XMAC_ADD_FILT, XMAC_ADD_FILT12_MASK | |
131 | \ XMAC_ADD_FILT00_MASK | |
132 | xmac-init-hashtable-regs \ XMAC_HASH_TBL | |
133 | xmac-init-counters \ Many counter regs like TxMAC_FRM_CNT | |
134 | ||
135 | xmac-config@ ( val ) | |
136 | link-is-up? if ( val ) | |
137 | mac-mode xmac-loopback <> if ( val ) | |
138 | xmac-tx-output-en or ( val ) | |
139 | then ( val ) | |
140 | xmac-led-polarity or ( val ) | |
141 | then ( val ) | |
142 | ||
143 | mac-mode normal <> ( val ) | |
144 | mac-mode 2xgf-ext-loopback <> and if | |
145 | \ Turn on promiscuous for internal loopback | |
146 | promis or ( val ) | |
147 | promis-group or ( val ) | |
148 | then ( val ) | |
149 | ||
150 | portmode 10gig < if ( val ) | |
151 | lfs-disable or ( val ) | |
152 | then ( val ) | |
153 | ||
154 | strip-crc or ( val ) | |
155 | xmac-config! ( ) | |
156 | ||
157 | \ During link initialization, it's possible for the remote_fault_detected | |
158 | \ bit to become set, which will prevent any transmits from happening. The | |
159 | \ register clears automatically on reads. | |
160 | xrxmac-status@ drop | |
161 | ; | |
162 | ||
163 | ||
164 | \ Wait for the self clear bit0 and bit1 of XTxMAC_SW_RST reg to be | |
165 | \ self cleared | |
166 | : wait-xmac-tx-rst ( -- flag ) | |
167 | xtxmac-sw-rst@ xtxmac-reg-rst xtxmac-soft-rst or and 0= | |
168 | ; | |
169 | ||
170 | ||
171 | \ Wait for the self clear bit1 of XRxMAC_SW_RST to be cleared | |
172 | : wait-xmac-rx-rst ( -- flag ) | |
173 | xrxmac-sw-rst@ xrxmac-reg-rst xrxmac-soft-rst or and 0= | |
174 | ; | |
175 | ||
176 | ||
177 | : reset-xmac ( -- ok? ) | |
178 | xtxmac-sw-rst@ xtxmac-reg-rst or xtxmac-soft-rst or xtxmac-sw-rst! | |
179 | d# 100 ['] wait-xmac-tx-rst wait-status | |
180 | dup 0= if cmn-error[ " reset-xmac tx failed" ]cmn-end exit then | |
181 | drop | |
182 | ||
183 | xrxmac-sw-rst@ xrxmac-reg-rst or xrxmac-soft-rst or xrxmac-sw-rst! | |
184 | d# 100 ['] wait-xmac-rx-rst wait-status | |
185 | dup 0= if cmn-error[ " reset-xmac rx failed" ]cmn-end then | |
186 | ; | |
187 | ||
188 | ||
189 | \ This is for selecting clock before we do reset-xmac. Do not | |
190 | \ try to initialize non-clock related parameters here because | |
191 | \ they will be wiped out by reset-xmac later. | |
192 | \ | |
193 | : init-xmac-xif ( -- ) | |
194 | ||
195 | 0 \ Put a 0 on stack to start building XIF part of XMAC_CONFIG | |
196 | \ So sel_por_clk_src is guaranteed to be 0 (PRM says "SW | |
197 | \ should always set sel_por_clk_src to 0 after POR" ) | |
198 | ||
199 | portmode 1g-copper = if ( val ) | |
200 | 1g-pcs-bypass or ( val ) | |
201 | then ( val ) | |
202 | ||
203 | \ Set XMAC to loopback mode BEFORE we do XMAC SW reset. | |
204 | \ By contrast, XPCS loopback must be set AFTER XPCS reset. | |
205 | mac-mode xmac-loopback = if ( val ) | |
206 | loopback or ( val ) | |
207 | then ( val ) | |
208 | ||
209 | portmode 1g-copper = if ( val ) | |
210 | chosen-speed 100Mbps = if \ Select internally generated 2.5MHz | |
211 | sel-clk-25mhz or \ clock for 100MHz operation | |
212 | then ( val ) | |
213 | then ( val ) | |
214 | xmac-config! ( ) | |
215 | ||
216 | \ Set Port Mode. | |
217 | xmac-config@ ( val ) | |
218 | mii-gmii-mode-mask invert and ( val ) | |
219 | ||
220 | portmode case ( val ) | |
221 | 10g-fiber of mii-gmii-mode=xgmii or endof | |
222 | 10g-copper of mii-gmii-mode=xgmii or endof | |
223 | 1g-copper of | |
224 | chosen-speed case | |
225 | 1000Mbps of mii-gmii-mode=gmii or endof | |
226 | 100Mbps of mii-gmii-mode=mii or endof | |
227 | 10Mbps of mii-gmii-mode=mii or endof | |
228 | endcase | |
229 | endof ( val ) | |
230 | endcase ( val ) | |
231 | xmac-config! ( ) | |
232 | ; | |
233 | ||
234 | \ Hostinfo tells which RDC Table should be used after a incoming | |
235 | \ frame's MAC address matchs one of the 20 possible cases (16 alternative | |
236 | \ MAC address, unique address, hash-hit, flow control and filter match) | |
237 | \ For Fcode driver, we only need to set the hostinfo for unique MAC address | |
238 | \ match, which is hostinfo17. But we do the same setting for flow control | |
239 | \ match because the checking for that match can not be disabled. | |
240 | \ (Only alternative addr, hash-hit and filter-match can be disabled) | |
241 | \ We use p-th RDC Table for port p. | |
242 | \ This word also disables comparison with 16 alternate MAC addresses, | |
243 | \ and the check for hash-hit and address filter hit. | |
244 | \ See PRM 22.3.11 | |
245 | \ | |
246 | : xmac-init-hostinfo ( -- ) | |
247 | d# 20 0 do | |
248 | port mpr or i xmac-host-infox! | |
249 | loop | |
250 | ||
251 | 0 xmac-addr-cmpen! \ Disable comparison with 16 alter addresses | |
252 | ||
253 | \ Disable checking for hash hit and filter address | |
254 | xmac-config@ hash-flt-en addr-flt-en or invert and xmac-config! | |
255 | ; | |
256 | ||
257 | \ Enable both Tx and Rx | |
258 | \ | |
259 | : enable-xmac ( -- ) | |
260 | xmac-config@ tx-enable or rxmac-en or ( val ) | |
261 | var-min-ipg-en invert and ( val ) | |
262 | mac-mode xmac-loopback <> if ( val ) | |
263 | xmac-tx-output-en or ( val ) | |
264 | then ( val ) | |
265 | xmac-config! ( ) | |
266 | ; | |
267 | ||
268 | \ Read XPCS control1 register and check the self clearing reset bit 15 | |
269 | : xpcs-reset-complete? ( -- flag ) xpcs-control1@ sw-reset and 0= ; | |
270 | ||
271 | : wait-xpcs-reset ( -- ok? ) d# 700 ['] xpcs-reset-complete? wait-status ; | |
272 | ||
273 | \ As recommended by the reset sequence in the MAC PRM, set bit 15 of | |
274 | \ BASE10G_CONTROL1 to reset the xpcs module. This is a self clearing bit | |
275 | \ | |
276 | : (reset-xpcs) ( -- ok? ) | |
277 | sw-reset xpcs-control1! | |
278 | wait-xpcs-reset | |
279 | ; | |
280 | ||
281 | \ Try to reset xpcs multiple times within 10 sec if necessary. | |
282 | \ | |
283 | \ In PCS case, reset-pcs actually resets the 1G optical | |
284 | \ transceiver. It is not clear, however, whether this reset-xpcs | |
285 | \ also resets the 10G bcm8704 optical transceiver interfacing with | |
286 | \ the xpcs layer. | |
287 | \ | |
288 | : reset-xpcs ( -- ok? ) | |
289 | d# 10000 get-msecs + false ( timeout flag ) | |
290 | begin ( timeout flag ) | |
291 | over timed-out? 0= over 0= and ( timeout flag continue? ) | |
292 | while ( timeout flag ) | |
293 | (reset-xpcs) if drop true then ( timeout flag ) | |
294 | repeat ( timeout flag ) | |
295 | nip dup 0= if ( flag ) | |
296 | cmn-warn[ " xpcs software reset failed" ]cmn-end | |
297 | then ( flag ) | |
298 | ; | |
299 | ||
300 | \ Make sure that xpcs_bypass is 0 so that we use internal xpcs. | |
301 | \ | |
302 | \ Although we must set xmac loopback BEFORE resetting xmac, | |
303 | \ we can not set xpcs loopback before xpcs software reset because | |
304 | \ XPCS software reset will wipe out the xpcs loopback setting. | |
305 | \ | |
306 | : init-xpcs ( -- ok? ) | |
307 | reset-xpcs | |
308 | mac-mode xpcs-loopback = if | |
309 | xpcs-control1@ csr-loopback or xpcs-control1! | |
310 | then | |
311 | ; | |
312 | ||
313 | : enable-xpcs | |
314 | xpcs-cfg-vendor1@ xpcs-en or tx-buf-en or | |
315 | xpcs-cfg-vendor1! | |
316 | ; | |
317 | ||
318 | : check-10g-user-inputs ( -- ok? ) | |
319 | case user-speed | |
320 | auto-speed of true endof | |
321 | 10Gbps of true endof | |
322 | 1000Mbps of false endof | |
323 | 100Mbps of false endof | |
324 | 10Mbps of false endof | |
325 | endcase | |
326 | case user-duplex | |
327 | auto-duplex of true endof | |
328 | full-duplex of true endof | |
329 | half-duplex of false endof | |
330 | endcase | |
331 | and dup 0= if | |
332 | user-speed user-duplex .link-speed,duplex ." is not supported" cr | |
333 | set-default-link-params | |
334 | then | |
335 | ; | |
336 | ||
337 | : update-xmac-tx-err-stat ( -- ) | |
338 | xtxmac-status@ xmac-tx-degrade-errs and | |
339 | tx-xmac-err-status or to tx-xmac-err-status | |
340 | ; | |
341 | ||
342 | : update-xmac-rx-err-stat ( -- ) | |
343 | xrxmac-status@ rx-oflow and | |
344 | rx-xmac-err-status or | |
345 | dup 0<> if | |
346 | cmn-error[ dup " RxMACOverflow = %x" ]cmn-end then | |
347 | to rx-xmac-err-status | |
348 | ; | |
349 | ||
350 | : .xmac-tx-err ( -- ) | |
351 | tx-xmac-err-status underflow and 0<> if ." TxMacUnderflow" cr then | |
352 | tx-xmac-err-status opp-max-pkt-err and 0<> if ." OppMaxPktSizeErr" cr then | |
353 | tx-xmac-err-status overflow and 0<> if ." TxMacOverflow" cr then | |
354 | ; | |
355 | ||
356 | : .xmac-rx-err ( -- ) | |
357 | rx-xmac-err-status rx-oflow and 0<> if ." RxMacOverflow" cr then | |
358 | ; | |
359 | ||
360 | : clear-xmac-tx-err ( -- ) | |
361 | tx-xmac-err-status xmac-tx-degrade-errs invert and | |
362 | to tx-xmac-err-status | |
363 | ; | |
364 | ||
365 | : clear-xmac-rx-err ( -- ) | |
366 | rx-xmac-err-status rx-oflow invert and | |
367 | to rx-xmac-err-status | |
368 | ; | |
369 | ||
370 | : disable-xmac-intr ( -- ) | |
371 | \ XMAC has Tx_/Rx_xMac Mask Register that is bit-by-bit corresponds | |
372 | \ to the layout of Tx/RxMAC Status Register. Set the bits to 0 | |
373 | \ so that none of them will generate interrupt | |
374 | 0 xtxmac-stat-msk! | |
375 | 0 xrxmac-stat-msk! | |
376 | ; |