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