Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: phy.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: @(#)phy.fth 1.2 06/07/14 | |
43 | purpose: Intel Ophir/82571 transceiver routines | |
44 | copyright: Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. | |
45 | copyright: Use is subject to license terms. | |
46 | ||
47 | headerless | |
48 | ||
49 | 0 value an-debug? | |
50 | ||
51 | \ Put PHY in loopback mode temporarily to bring the link down | |
52 | : force-link-down ( -- ) | |
53 | phy-cr@ phycr.loopback or phy-cr! | |
54 | d# 1000 ms | |
55 | phy-cr@ phycr.loopback invert and phy-cr! | |
56 | ; | |
57 | ||
58 | : phy-reset-complete? ( -- flag ) phy-cr@ phycr.reset and 0= ; | |
59 | ||
60 | : wait-phy-reset ( -- flag ) | |
61 | d# 700 ['] phy-reset-complete? wait-status | |
62 | ; | |
63 | ||
64 | : (reset-transceiver) ( -- ok? ) | |
65 | phy-cr@ phycr.reset or phy-cr! | |
66 | wait-phy-reset | |
67 | ; | |
68 | ||
69 | : reset-transceiver ( -- ok? ) | |
70 | d# 15000 get-msecs + false | |
71 | begin | |
72 | over timed-out? 0= over 0= and | |
73 | while | |
74 | (reset-transceiver) if drop true then | |
75 | repeat nip | |
76 | dup 0= if ." Failed to reset transceiver!" cr exit then | |
77 | phy-cr@ phycr.speed-100 invert and phycr.duplex invert and phy-cr! | |
78 | ; | |
79 | ||
80 | : disable-auto-nego ( -- ) | |
81 | an-debug? if ." Disabling Autonegotiation" cr then | |
82 | phy-cr@ phycr.an-enable invert and phy-cr! | |
83 | ; | |
84 | ||
85 | : enable-auto-nego ( -- ) | |
86 | an-debug? if ." Enabling Autonegotiation" cr then | |
87 | phy-cr@ phycr.an-enable phycr.an-restart or or phy-cr! | |
88 | ; | |
89 | ||
90 | : an-link-speed&mode ( -- speed duplex-mode ) | |
91 | ||
92 | phy-sr@ physr.ext-status and if | |
93 | phy-1000-sr@ h# c00 and d# 10 rshift | |
94 | phy-1000-cr@ h# 300 and d# 8 rshift and ( 1000bt-common-cap ) | |
95 | d# 10 lshift | |
96 | dup gsr.lp-1000fdx and if drop 1000Mbps full-duplex exit then | |
97 | gsr.lp-1000hdx and if 1000Mbps half-duplex exit then | |
98 | then | |
99 | ||
100 | phy-anlpar@ phy-anar@ and ( an-common ) | |
101 | dup anlpar.100fdx and if drop 100Mbps full-duplex exit then | |
102 | dup anlpar.100hdx and if drop 100Mbps half-duplex exit then | |
103 | dup anlpar.10fdx and if drop 10Mbps full-duplex exit then | |
104 | dup anlpar.10hdx and if drop 10Mbps half-duplex exit then | |
105 | ; | |
106 | ||
107 | \ Interpret and apply the "supported-network-types" property if it exists | |
108 | : supported-speed&mode ( speed mode$ -- bit-mask ) | |
109 | rot case | |
110 | 10Mbps of | |
111 | " half" $= if h# 1 else h# 2 then | |
112 | endof | |
113 | 100Mbps of | |
114 | " half" $= if h# 4 else h# 8 then | |
115 | endof | |
116 | 1000Mbps of | |
117 | " half" $= if h# 10 else h# 20 then | |
118 | endof | |
119 | ( default ) 2drop 0 swap | |
120 | endcase | |
121 | ; | |
122 | ||
123 | : parse-supported-abilities ( str$ -- abilities ) | |
124 | base @ >r decimal | |
125 | ascii , left-parse-string 2drop | |
126 | ascii , left-parse-string $number drop -rot ( speed str$ ) | |
127 | ascii , left-parse-string 2drop ( speed mode$ ) | |
128 | supported-speed&mode ( bit-mask ) | |
129 | r> base ! | |
130 | ; | |
131 | ||
132 | : get-supported-abilities ( phy-abilty -- phy-abilty | abilty ) | |
133 | " supported-network-types" get-my-property 0= if | |
134 | begin | |
135 | decode-string ?dup | |
136 | while ( phy-abilty str1$ str2$ ) | |
137 | parse-supported-abilities ( phy-abilty str1$ mask ) | |
138 | 3 roll swap xor -rot ( phy-abilty' str1$ ) | |
139 | repeat 3drop ( phy-abilty' ) | |
140 | invert h# 3f and ( abilty ) | |
141 | then | |
142 | ; | |
143 | ||
144 | : phy-abilities ( -- abilities ) | |
145 | phy-sr@ d# 11 rshift h# f and | |
146 | gmii-phy? if phy-esr@ d# 12 rshift h# 3 and else 0 then d# 4 lshift or | |
147 | ( phy-abilty ) get-supported-abilities ( abilities ) | |
148 | ; | |
149 | ||
150 | \ Construct bit-mask abilities based on speed, duplex mode settings | |
151 | \ 0000.0001 10Mbps, Half Duplex | |
152 | \ 0000.0010 10Mbps, Full Duplex | |
153 | \ 0000.0100 100Mbps, Half Duplex | |
154 | \ 0000.1000 100Mbps, Full Duplex | |
155 | \ 0001.0000 1000Mbps, Half Duplex | |
156 | \ 0010.0000 1000Mbps, Full Duplex | |
157 | : construct-abilities ( speed duplex-mode -- abilities ) | |
158 | phy-abilities | |
159 | swap case | |
160 | half-duplex of h# 15 endof \ Mask FDX abilities | |
161 | full-duplex of h# 2a endof \ Mask HDX abilities | |
162 | auto-duplex of h# 3f endof | |
163 | endcase and | |
164 | swap case | |
165 | 10Mbps of h# 3 endof | |
166 | 100Mbps of h# c endof | |
167 | 1000Mbps of h# 30 endof | |
168 | auto-speed of h# 3f endof | |
169 | endcase and | |
170 | ; | |
171 | ||
172 | : publish-capabilities ( -- ) | |
173 | user-speed user-duplex construct-abilities ( abilities ) | |
174 | dup h# f and d# 5 lshift anar.selector-field or phy-anar! ( abilities ) | |
175 | gmii-phy? if ( abilities ) | |
176 | h# 30 and d# 4 lshift ( 1000-cap ) | |
177 | user-link-clock auto-link-clock <> if | |
178 | gcr.ms-cfg-enable or | |
179 | user-link-clock master-link-clock = if | |
180 | gcr.ms-cfg-value or | |
181 | then | |
182 | then | |
183 | phy-1000-cr! | |
184 | else ( abilities ) | |
185 | drop ( ) | |
186 | then ( ) | |
187 | ; | |
188 | ||
189 | : match-capabilities ( -- ok? ) | |
190 | phy-sr@ physr.ext-status and if | |
191 | phy-1000-sr@ h# c00 and d# 10 rshift | |
192 | phy-1000-cr@ h# 300 and d# 8 rshift | |
193 | and 0<> | |
194 | else | |
195 | 0 | |
196 | then | |
197 | phy-anlpar@ phy-anar@ and 0<> or | |
198 | ; | |
199 | ||
200 | \ Autonegotiation may take as much as 5 seconds with 10/100 BaseT PHYs | |
201 | : wait-autoneg-complete ( -- complete? ) | |
202 | d# 5000 get-msecs + false | |
203 | begin | |
204 | over timed-out? 0= | |
205 | over 0= and | |
206 | while | |
207 | d# 20 ms | |
208 | phy-sr@ physr.an-complete and if | |
209 | drop true | |
210 | then | |
211 | repeat nip | |
212 | ; | |
213 | ||
214 | : phy-link-up? ( -- up? ) | |
215 | phy-sr@ drop | |
216 | phy-sr@ physr.link-up and | |
217 | ; | |
218 | ||
219 | : link-up? ( -- flag ) phy-link-up? ; | |
220 | ||
221 | : wait-link-up? ( -- up? ) | |
222 | wait-phy-reset drop | |
223 | d# 2000 ['] phy-link-up? wait-status | |
224 | ; | |
225 | ||
226 | : (autonegotiate) ( -- link-up? ) | |
227 | ||
228 | \ Advertise my capabilities & start auto negotiation | |
229 | publish-capabilities | |
230 | enable-auto-nego | |
231 | ||
232 | \ Wait for auto negotiation to complete | |
233 | wait-autoneg-complete | |
234 | 0= if | |
235 | ." Timed out waiting for Autonegotation to complete" cr | |
236 | false exit | |
237 | then | |
238 | ||
239 | \ Check if autonegotation completed by parallel detection, | |
240 | \ and if so, whether there are any parallel detect (multiple | |
241 | \ link fault) errors | |
242 | phy-aner@ dup aner.lp-an-able and 0= swap aner.mlf and and if | |
243 | ." Multiple link faults seen during Autonegotiation" cr | |
244 | false exit | |
245 | then | |
246 | ||
247 | \ Check for common capabilities | |
248 | match-capabilities 0= if | |
249 | ." System and network incompatible for communicating" cr | |
250 | false exit | |
251 | then | |
252 | ||
253 | \ Valid Link established? | |
254 | phy-link-up? | |
255 | ; | |
256 | ||
257 | : do-autonegotiation ( -- link-up? ) | |
258 | (autonegotiate) if | |
259 | an-link-speed&mode set-chosen-speed&duplex | |
260 | true | |
261 | else | |
262 | ." Check cable and try again" cr | |
263 | false | |
264 | then | |
265 | ; | |
266 | ||
267 | : check-phy-capability ( -- ) | |
268 | user-speed user-duplex 2dup construct-abilities 0= if | |
269 | ." Not capable of " .link-speed,duplex | |
270 | -1 throw | |
271 | else | |
272 | 2drop | |
273 | then | |
274 | ; | |
275 | ||
276 | \ Set/Force link speed and mode, and check link status | |
277 | \ For 1Gbps, we manually configure local PHY as SLAVE | |
278 | : speed&mode-possible? ( speed duplex-mode -- link-up? ) | |
279 | over 1000Mbps = if | |
280 | gcr.ms-cfg-enable | |
281 | user-link-clock master-link-clock = if | |
282 | gcr.ms-cfg-value or | |
283 | then | |
284 | phy-1000-cr! | |
285 | then | |
286 | phy-cr@ b# 0010.0001.0100.0000 invert and \ Mask speed & duplex bits | |
287 | swap full-duplex = if phycr.duplex or then | |
288 | swap case | |
289 | 10Mbps of phycr.speed-10 endof | |
290 | 100Mbps of phycr.speed-100 endof | |
291 | 1000Mbps of phycr.speed-1000 endof | |
292 | endcase or | |
293 | phy-cr! | |
294 | wait-link-up? | |
295 | ; | |
296 | ||
297 | : set-speed&mode ( -- link-up? ) | |
298 | disable-auto-nego | |
299 | force-link-down | |
300 | user-speed user-duplex | |
301 | 2dup speed&mode-possible? if set-chosen-speed&duplex true exit then | |
302 | over 1000Mbps = if | |
303 | ." Cannot bringup link using non-autonegotation." cr | |
304 | ." Force link partner to " .link-speed,duplex ." as link-clock " | |
305 | user-link-clock master-link-clock = if | |
306 | ." slave" | |
307 | else | |
308 | ." master" | |
309 | then | |
310 | cr -1 throw | |
311 | then | |
312 | 2drop false | |
313 | ; | |
314 | ||
315 | : use-autonegotiation? ( -- flag ) | |
316 | user-speed auto-speed = user-duplex auto-duplex = or if | |
317 | true exit | |
318 | then | |
319 | user-speed 1000Mbps = if | |
320 | user-link-clock auto-link-clock = | |
321 | else | |
322 | false | |
323 | then | |
324 | ; | |
325 | ||
326 | : show-link-status ( -- ) | |
327 | phy-link-up? if | |
328 | chosen-speed chosen-duplex .link-speed,duplex ." Link up" | |
329 | else | |
330 | ." Link Down" | |
331 | then cr | |
332 | ; | |
333 | ||
334 | : setup-transceiver ( -- ok? ) | |
335 | reset-transceiver drop | |
336 | \ disable-link-events \ Should be turned off by reset but... | |
337 | check-phy-capability | |
338 | use-autonegotiation? if do-autonegotiation else set-speed&mode then | |
339 | show-link-status | |
340 | ; |