interplane.Get Omega
Read in your language

rtl8127-omega

aien-dev/rtl8127-omega

Brought by drakestapleton

branch main Branches Tags History

rtl8127-omega / om / rtl8127 / model.om

375 lines · 7444 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note model.om: a software RTL8127 for the tests. Backend unit for rtl8127.om: rtlrd, rtlwr, rtldly, rtlbar.
3note
4note It is a register array with the side effects the vendor driver relies on (reset bit that clears, MAC and PHY OCP windows,
5note FIFO-empty bits, the TX close pointer) and a ring simulator that walks the driver's TX and RX descriptors the way the chip
6note would. It refuses any DMA address outside the driver's region: that is the IOMMU window on a real machine, and every such
7note access is counted in mc[M_DMAF].
8note It is written from the same vendor source as the driver (no datasheet exists). It checks that the driver does what the
9note reference does, NOT that the reference is right for the chip.
10
11const M_ABS ulong 0
12const M_RSTK ulong 1
13const M_FIFO ulong 2
14const M_CLOB ulong 3
15const M_HCLO ulong 4
16const M_DEFR ulong 5
17const M_OCPL ulong 6
18const M_PHYL ulong 7
19const M_PHYB ulong 8
20const M_TXHW ulong 9
21const M_RXHW ulong 10
22const M_CLO ulong 11
23const M_TAIL ulong 12
24const M_TXOR ulong 13
25const M_RSTS ulong 14
26const M_WRS ulong 15
27const M_MACU ulong 16
28const M_MACL ulong 17
29const M_ENBR ulong 18
30const M_TNP ulong 19
31const M_RDS ulong 20
32const M_DMAF ulong 21
33const M_TXC ulong 22
34const M_RXOV ulong 23
35const M_OCPW ulong 24
36const M_DMAB ulong 25
37const M_WROC ulong 26
38const NOADDR ulong 18446744073709551615
39
40global mreg uchar 20480
41global mocp ulong 32768
42global mphy ulong 32768
43global mc ulong 40
44global mtxl ulong 64
45global mtxf uchar 4096
46global mrxf uchar 2048
47
48fn mget o ulong w ulong to ulong
49v = ulong 0
50for i ulong w
51v = or v shl ulong get mreg add o i mul i 8
52end
53ret v
54end
55fn mput o ulong w ulong v ulong to void
56for i ulong w
57put mreg add o i uchar and shr v mul i 8 255
58end
59end
60fn mbump x ulong to void
61put mc x add get mc x 1
62end
63
64note DMA address a, n bytes: the offset inside rdma, or NOADDR (and a fault counted) when it leaves the window.
65fn mdmao a ulong n ulong to ulong
66b = get mc M_DMAB
67if lt a b
68mbump M_DMAF
69ret NOADDR
70end
71if gt add sub a b n MEMSIZE
72mbump M_DMAF
73ret NOADDR
74end
75ret sub a b
76end
77fn mrd32 o ulong to ulong
78a = ulong get rdma o
79b = ulong get rdma add o 1
80c = ulong get rdma add o 2
81d = ulong get rdma add o 3
82ret or or or a shl b 8 shl c 16 shl d 24
83end
84fn mwr32 o ulong v ulong to void
85put rdma o uchar and v 255
86put rdma add o 1 uchar and shr v 8 255
87put rdma add o 2 uchar and shr v 16 255
88put rdma add o 3 uchar and shr v 24 255
89end
90fn mring lo ulong to ulong
91ret or mget lo 4 shl mget add lo 4 4 32
92end
93
94fn rtldly us ulong to void
95end
96fn rtlbar to void
97end
98
99fn mresetst to void
100put mc M_RXHW 0
101put mc M_TXHW get mc M_CLOB
102put mc M_TXOR get mc M_CLOB
103put mc M_CLO get mc M_CLOB
104put mc M_TAIL 0
105mput HWCLO0 4 get mc M_CLOB
106mbump M_RSTS
107end
108
109note Record the sent frame: length and its first 64 bytes, for the first 64 frames.
110fn mcap sz ulong bo ulong to void
111tc = get mc M_TXC
112if lt tc 64
113put mtxl tc sz
114for k ulong 64
115if lt k sz
116put mtxf add mul tc 64 k get rdma add bo k
117end
118end
119end
120put mc M_TXC add tc 1
121end
122
123note EOR must be set on exactly the last TX slot; a wrong EOR counts as a loud DMA fault.
124fn meor o1 ulong slot ulong to void
125last = ulong 0
126if eq slot sub TXN 1
127last = 1
128end
129eor = ulong 0
130if ne and o1 DOWN 0
131eor = 0
132end
133if ne and o1 DEOR 0
134eor = 1
135end
136if ne eor last
137put mc M_DMAF add get mc M_DMAF 1000
138end
139end
140
141note The chip fetches one descriptor at its index. 1 when it did, 0 when it must stop.
142fn mtxone ro ulong to ulong
143slot = rem and sub get mc M_TXHW get mc M_TXOR CLOMASK TXN
144d = add ro mul slot 32
145o1 = mrd32 d
146if eq and o1 DOWN 0
147ret 0
148end
149a = or mrd32 add d 8 shl mrd32 add d 12 32
150sz = and o1 262143
151bo = mdmao a sz
152if eq bo NOADDR
153ret 0
154end
155mcap sz bo
156meor o1 slot
157put mc M_TXHW and add get mc M_TXHW 1 CLOMASK
158if eq get mc M_DEFR 0
159put mc M_CLO add get mc M_CLO 1
160end
161ret 1
162end
163
164fn mtxrun to void
165ro = mdmao mring TNPDSLO mul TXN 32
166if eq ro NOADDR
167ret
168end
169if eq and mget CHIPCMD 1 CMDTXEN 0
170ret
171end
172if gt and sub get mc M_TAIL get mc M_TXHW CLOMASK TXN
173put mc M_DMAF add get mc M_DMAF 1000
174ret
175end
176while ne get mc M_TXHW and get mc M_TAIL CLOMASK bound 64
177if eq mtxone ro 0
178break
179end
180end
181mput HWCLO0 4 and get mc M_CLO CLOMASK
182end
183
184fn rtlrd off ulong w ulong to ulong
185if ne get mc M_ABS 0
186if eq w 4
187ret 4294967295
188end
189if eq w 2
190ret 65535
191end
192ret 255
193end
194if gt add off w MMIOMIN
195put mc M_DMAF add get mc M_DMAF 10000
196ret 0
197end
198if eq off CHIPCMD
199if ne and ulong get mreg off CMDRST 0
200if eq get mc M_RSTK 0
201put mreg off uchar and ulong get mreg off not CMDRST
202mresetst
203end
204end
205end
206if eq off MACOCP
207if eq w 4
208ret get mocp and shr get mc M_OCPL 16 32767
209end
210end
211if eq off PHYOCP
212if eq w 4
213ph = get mc M_PHYB
214if eq ph 1
215put mc M_PHYB 0
216ret 0
217end
218if eq ph 2
219pa = and shr get mc M_PHYL 16 32767
220pv = get mphy pa
221if eq pa 21008
222pv = 1
223if ne and get mphy 20992 4096 0
224pv = 3
225end
226end
227ret or OCPFLAG pv
228end
229ret 0
230end
231end
232if eq off HWCLO0
233if ne get mc M_HCLO 0
234ret add get mc M_CLO 1000
235end
236end
237ret mget off w
238end
239
240fn rtlwr off ulong w ulong v ulong to void
241mbump M_WRS
242if ne get mc M_ABS 0
243ret
244end
245if gt add off w MMIOMIN
246put mc M_DMAF add get mc M_DMAF 10000
247ret
248end
249if eq off MACOCP
250put mc M_OCPL v
251if ne and v OCPWRB 0
252put mocp and shr v 16 32767 and v 65535
253mbump M_OCPW
254end
255ret
256end
257if eq off PHYOCP
258put mc M_PHYL v
259if ne and v OCPWRB 0
260put mphy and shr v 16 32767 and v 65535
261put mc M_PHYB 1
262else
263put mc M_PHYB 2
264end
265ret
266end
267if or eq off MAC0 eq off MAC4
268if eq w 4
269if eq and mget CFG9346 1 UNLOCK UNLOCK
270mbump M_MACU
271else
272mbump M_MACL
273end
274end
275end
276if eq off TNPDSLO
277put mc M_TNP 1
278end
279if eq off RDSARLO
280put mc M_RDS 1
281end
282if eq off SWTAIL0
283mput off w v
284put mc M_TAIL v
285mtxrun
286ret
287end
288if eq off CHIPCMD
289if eq and v or CMDTXEN CMDRXEN or CMDTXEN CMDRXEN
290if or eq get mc M_TNP 0 eq get mc M_RDS 0
291put mc M_ENBR 1
292end
293end
294end
295if eq off ISR0
296mput off w and mget off w not v
297ret
298end
299mput off w v
300end
301
302note The chip receives a frame from the wire: n bytes from mrxf, then a 4 byte FCS. extra is OR-ed into the status word; force, when
303note nonzero, replaces the length field. Returns 0, or 1 chip not receiving, 2 no free descriptor (overflow counted), 3 bad buffer
304note address, 4 frame does not fit the posted buffer.
305fn mrxin n ulong extra ulong force ulong to ulong
306ro = mdmao mring RDSARLO mul RXN 16
307if eq ro NOADDR
308ret 1
309end
310if eq and mget CHIPCMD 1 CMDRXEN 0
311ret 1
312end
313d = add ro mul rem get mc M_RXHW RXN 16
314o1 = mrd32 d
315if eq and o1 DOWN 0
316mbump M_RXOV
317ret 2
318end
319size = and o1 RXLEN
320a = or mrd32 add d 8 shl mrd32 add d 12 32
321bo = mdmao a size
322if eq bo NOADDR
323ret 3
324end
325if gt add n 4 size
326ret 4
327end
328for k ulong n
329put rdma add bo k get mrxf k
330end
331for k ulong 4
332put rdma add add bo n k 204
333end
334l = add n 4
335if ne force 0
336l = force
337end
338mwr32 d or or or DFS DLS extra l
339put mc M_RXHW add get mc M_RXHW 1
340ret 0
341end
342
343note A freshly powered chip. dma is the bus address the driver will be given for rdma.
344fn mchip dma ulong to void
345for i ulong 40
346put mc i 0
347end
348for i ulong 20480
349put mreg i 0
350end
351for i ulong 32768
352put mocp i 0
353put mphy i 0
354end
355for i ulong MEMSIZE
356put rdma i 0
357end
358put mc M_DMAB dma
359mput TCR 4 or TCRID 1048576
360mput LLFIFO 2 512
361put mreg MCUCMD uchar or ulong get mreg MCUCMD or or MCUTXE MCURXE MCUOOB
362mput INTRMIT 2 259
363mput RXDTYPE 1 2
364mput RSSCTRL 4 3841
365mput QNUMCTL 2 264
366put mocp div OCPFMT 2 32770
367mput PHYSTAT 2 or or 16384 PHYSLNK PHYSFD
368mput ISR0 4 133
369mput IMR0 4 4294967295
370mput BAKADR0 4 857870664
371mput BAKADR1 2 21828
372for i ulong 6
373put mreg add MAC0 i uchar add 160 i
374end
375end