Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: pkg.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: @(#)pkg.fth 1.1 07/01/23 | |
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 | defer open-hook ' noop to open-hook | |
50 | defer close-hook ' noop to close-hook | |
51 | ||
52 | 0 value obp-tftp | |
53 | ||
54 | : init-obp-tftp ( tftp-args$ -- okay? ) | |
55 | " obp-tftp" find-package if | |
56 | open-package | |
57 | else | |
58 | cmn-warn[ " Cannot open obp-tftp package" ]cmn-end | |
59 | 2drop 0 | |
60 | then | |
61 | dup to obp-tftp | |
62 | ; | |
63 | ||
64 | : init-txc ( -- ) | |
65 | \ Bind channel selected by my-dma-chan to this port's TXC | |
66 | 1 chan# lshift port txc-port-dma-p! | |
67 | ||
68 | \ Clear DMA_LENGTH, which is the number of bytes transmitted by DMA. | |
69 | \ This register is cleared on reads. | |
70 | chan# txc-dma-max-len-i@ drop | |
71 | ||
72 | port txc-debug! \ Select debug for the used port | |
73 | ||
74 | \ Set TXC_ENABLED (bit 4) of TXC_CONTROL to enable TXC. Set | |
75 | \ p-th bit to enable only the engine for port p | |
76 | txc-enabled 1 port lshift or txc-control! | |
77 | ; | |
78 | ||
79 | : use-gmii? ( -- flag ) | |
80 | portmode 1g-copper = if phy-sr@ physr.ext-status and 0<> else false then | |
81 | ; | |
82 | ||
83 | : publish-post-open-properties ( -- ) | |
84 | user-speed case | |
85 | auto-speed of " auto" endof | |
86 | 10Mbps of " 10" endof | |
87 | 100Mbps of " 100" endof | |
88 | 1000Mbps of " 1000" endof | |
89 | 10Gbps of " 10000" endof | |
90 | endcase | |
91 | encode-string " speed" property | |
92 | ||
93 | user-duplex case | |
94 | auto-duplex of " auto" endof | |
95 | half-duplex of " half" endof | |
96 | full-duplex of " full" endof | |
97 | endcase | |
98 | encode-string " duplex" property | |
99 | ||
100 | portmode 1g-copper = if | |
101 | use-gmii? if | |
102 | user-link-clock case | |
103 | auto-link-clock of " auto" endof | |
104 | master-link-clock of " master" endof | |
105 | slave-link-clock of " slave" endof | |
106 | endcase | |
107 | encode-string " link-clock" property | |
108 | then | |
109 | then | |
110 | ; | |
111 | ||
112 | \ Tx-header is very important. Even if we set CKSUM_EN_PKT_TYPE to 0 | |
113 | \ to disable checksum, TOT_XFER_LEN should still be set correctly. | |
114 | \ That is because the Neptune expects this number to be TR_LEN (of | |
115 | \ the Tx descriptor) minus 16 | |
116 | \ bits[63:62] CKSUM_EN_PKT_TYPE 0: No op, do not do checksum, 01 TCP, 10 UDP | |
117 | \ bits61 IP_VER 0=IPv4 1=IPv61 | |
118 | \ bit57 LLC | |
119 | \ bit56 VLAN | |
120 | \ bits[55:52] IHL | |
121 | \ bit[51:48] L3START | |
122 | \ bit[45:40] L4START | |
123 | \ bit[37:32] L4STUFF | |
124 | \ bit[29:16] TOT_XFER_LEN | |
125 | ||
126 | struct | |
127 | 2 field >pad-rsvd0 | |
128 | 2 field >tot-xfer-len-rsvd1 | |
129 | 1 field >l4stuff-rsvd2 | |
130 | 1 field >l4start-rsvd3 | |
131 | 1 field >l3start-ihl | |
132 | 1 field >vlan-llc-rsvd4-ip-ver-cksum-en-pkt-type | |
133 | 8 field >rsvd5 | |
134 | constant /tx-header | |
135 | ||
136 | /tx-header buffer: tx-header | |
137 | ||
138 | ||
139 | : make-tx-header ( ether-frame-len -- ) | |
140 | wbflip tx-header >tot-xfer-len-rsvd1 w! | |
141 | \ b31:30 = RSVD=b00 | |
142 | \ b29:16 = tot-xfer-len = /loopback-pkt - tx-header | |
143 | \ = /dst-src-macs + /ether-type + /loopback-data | |
144 | ||
145 | 0 tx-header >pad-rsvd0 w! \ b15:3=RSVD=0, b2:0=PAD=0 | |
146 | ||
147 | 19 tx-header >l4stuff-rsvd2 c! | |
148 | \ b39:38=RSVD=b00. b37:32 L4STUFF = (14+20+16)/2 = 25 =0x19 | |
149 | \ L4STUFF is where the tcp checksum is, which is at | |
150 | \ 16 from the begining of TCP's first byte | |
151 | ||
152 | 11 tx-header >l4start-rsvd3 c! | |
153 | \ b47:46=RSVD=b00. b45:40=L4START = (6+6+2+20)/2 = 17=0x11 | |
154 | ||
155 | 57 tx-header >l3start-ihl c! | |
156 | \ b55:52 IHL IP header = 5 (5x4B=20B) | |
157 | \ b51:48 L3START=[6(DA)+6(SA)+2(type)]/2 = 7 | |
158 | ||
159 | 0 tx-header >vlan-llc-rsvd4-ip-ver-cksum-en-pkt-type c! | |
160 | \ b63:62=CKSUM_EN_PKT_TYPE=1=TCP cksum. b61=IP_VER=0=IPv4 | |
161 | \ b63:62=CKSUM_EN_PKT_TYPE=0=No cksum. b61=IP_VER=0=IPv4 | |
162 | \ b60:58=RSVD=b000, b57=LLC = 0 b56=VLAN = 0 | |
163 | ||
164 | 0 tx-header >rsvd5 x! \ First 8B of Tx header is RSVD | |
165 | ; | |
166 | ||
167 | ||
168 | external | |
169 | ||
170 | \ XMAC and BMAC do not support padding, so the driver needs to | |
171 | \ ensure that the ethernet frame is minimun 60 bytes (Ethernet | |
172 | \ standard requires a minimun 46B of payload. 46B plus 12B dest | |
173 | \ and src MAC addresses and 2B ether-type = 60B) | |
174 | \ | |
175 | : write ( appl-buf len -- #sent ) | |
176 | link-up? 0= if | |
177 | cmn-note[ " Link down, restarting network initialization" ]cmn-end | |
178 | restart-net if | |
179 | 2drop 0 exit | |
180 | then | |
181 | then ( appl-buf len ) | |
182 | tbuf0 swap ( appl-buf tbuf-cpu-adr len ) | |
183 | ||
184 | \ If the packet from upper layer is shorter than 60B, then | |
185 | \ fill out the first 60 bytes of tbuf with zeros so that all | |
186 | \ the padding bytes will be zeros. | |
187 | dup /min-ether-len < if ( appl-buf tbuf-cpu-adr len ) | |
188 | over /min-ether-len erase ( appl-buf tbuf-cpu-adr len ) | |
189 | then | |
190 | ||
191 | 2dup ( appl-buf tbuf-cpu-adr len tbuf-cpu-adr len ) | |
192 | >r >r ( appl-buf tbuf-cpu-adr len )( R: len tbuf-cpu-adr ) | |
193 | ||
194 | \ Construct tx-header required by Neptune | |
195 | dup /min-ether-len < if | |
196 | /min-ether-len make-tx-header | |
197 | else | |
198 | dup make-tx-header ( appl-buf tbuf-cpu-adr len ) | |
199 | then | |
200 | ||
201 | \ First copy the tx-header just constructed by make-tx-header | |
202 | over tx-header swap ( appl-buf tbuf-cpu-adr len tx-header tbuf-cpu-adr ) | |
203 | /tx-header move ( appl-buf tbuf-cpu-adr len ) | |
204 | ||
205 | \ Next copy the ethernet frame passed down from upper layer | |
206 | swap /tx-header + swap ( appl-buf tbuf-cpu-adr+16 len ) | |
207 | move ( )( R: len tbuf-cpu-adr ) | |
208 | r> r> ( tbuf-cpu-adr len )( R: ) | |
209 | tuck ( len tbuf-cpu-adr len ) | |
210 | ||
211 | dup /min-ether-len < if | |
212 | drop /min-ether-len | |
213 | then ( len tbuf-cpu-adr LEN ) | |
214 | /tx-header + ( len tbuf-cpu-adr LEN' ) | |
215 | ||
216 | \ Application data has been copied from application data buffer | |
217 | \ to the 4K Tx block buffer pointed by nexttmd. The data is appended | |
218 | \ to Tx header and may be followed by some zero padding bytes if the | |
219 | \ data size is < 60. Now send data out to the network | |
220 | \ | |
221 | transmit 0= if | |
222 | drop 0 | |
223 | then ( #sent ) | |
224 | ; | |
225 | ||
226 | : read ( buf len -- -2 | actual-bytes-read ) | |
227 | rcr-has-pkt? if ( buf len ) | |
228 | get-pkt-addr&len-from-rcr ( buf len nextrcdaddr pkt-cpu-adr pktlen ) | |
229 | swap full-header + swap ( buf len nextrcdaddr pkt-cpu-adr' pktlen ) | |
230 | \ pkt-cpu-adr' = pkt-cpu-adr+18 | |
231 | ?dup if ( buf len nextrcdaddr pkt-cpu-adr' pktlen ) | |
232 | rot >r ( buf len pkt-cpu-adr' pktlen )( R: nextrcdaddr ) | |
233 | rot ( buf pkt-cpu-adr' pktlen len ) | |
234 | min ( buf pkt-cpu-adr' min[pktlen,len] ) | |
235 | >r ( buf pkt-cpu-adr' )( R: nextrcdaddr min ) | |
236 | swap ( pkt-cpu-adr' buf )( R: nextrcdaddr min ) | |
237 | r@ ( pkt-cpu-adr' buf min )( R: nextrcdaddr min ) | |
238 | move r> r> ( min nextrcdaddr )( R: ) | |
239 | else ( buf len nextrcdaddr pkt-cpu-adr' ) | |
240 | drop ( buf len nextrcdaddr ) | |
241 | nip nip 0 swap ( 0 nextrcdaddr ) | |
242 | then | |
243 | return-rx-buffer ( min|0 ) | |
244 | else | |
245 | 2drop 0 \ drop buf and len and put a 0 on stack | |
246 | then | |
247 | ?dup 0= if -2 then \ Upper layer wants to see -2 if we got 0 | |
248 | ; | |
249 | ||
250 | : close ( -- ) | |
251 | obp-tftp ?dup if close-package then | |
252 | pio if | |
253 | resetall | |
254 | unmap-resources | |
255 | then | |
256 | close-hook | |
257 | ; | |
258 | ||
259 | : open ( -- ok? ) | |
260 | make-path | |
261 | open-hook | |
262 | map-resources | |
263 | my-args parse-devargs ( tftp-args$ ) | |
264 | init-obp-tftp 0= if close false exit then | |
265 | ||
266 | check-user-inputs if | |
267 | niu? 0= if | |
268 | set-ldg | |
269 | then | |
270 | init-txc | |
271 | init-fflp | |
272 | bringup-link ?dup 0= if close false exit then | |
273 | publish-post-open-properties | |
274 | mac-address encode-bytes " mac-address" property | |
275 | else | |
276 | unmap-resources | |
277 | false | |
278 | then | |
279 | ; | |
280 | ||
281 | ||
282 | : load ( adr -- len ) | |
283 | " load" obp-tftp $call-method | |
284 | ; | |
285 | ||
286 | : reset ( -- ) | |
287 | pio if | |
288 | resetall | |
289 | unmap-resources | |
290 | else | |
291 | map-regs resetall | |
292 | unmap-regs | |
293 | then | |
294 | ; | |
295 | ||
296 | headerless |