rtl8127-omega
aien-dev/rtl8127-omega
Brought by drakestapleton
rtl8127-omega / cmd / rtl8127d / probe.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note probe.om: rtl8127-probe, a READ-ONLY look at a Realtek RTL8127 (PCI 10ec:8127). It writes nothing to the chip. |
| 3 | note Usage: rtl8127-probe /sys/bus/pci/devices/<address>/resource2 (needs root to read the BAR) |
| 4 | note Prints the chip id, the MAC address the chip holds, and the link state. Exit codes: 0 read fine, 10 usage, 11 cannot open, 12 cannot map, |
| 5 | note 13 nothing behind the BAR (all ones), 14 not an RTL8127. |
| 6 | note Built together with rtl8127.om (constants only are used) and hw.om. |
| 7 | |
| 8 | text tid "rtl8127-probe: TxConfig 0x" |
| 9 | text tmac "rtl8127-probe: MAC (backup) " |
| 10 | text tmac0 "rtl8127-probe: MAC (current) " |
| 11 | text tlup "rtl8127-probe: link up, Mb/s " |
| 12 | text tldn "rtl8127-probe: link down\n" |
| 13 | text tro "rtl8127-probe: read-only, nothing was written to the chip\n" |
| 14 | text tusg "usage: rtl8127-probe /sys/bus/pci/devices/<address>/resource2\n" |
| 15 | text tbad "rtl8127-probe: this is not an RTL8127\n" |
| 16 | text tabs "rtl8127-probe: nothing answers behind the BAR (all ones)\n" |
| 17 | text tnl "\n" |
| 18 | text tcol ":" |
| 19 | |
| 20 | fn pch c ulong to void |
| 21 | b = new uchar 1 0 |
| 22 | put b 0 uchar c |
| 23 | w = write 1 b 0 1 |
| 24 | end |
| 25 | fn phex v ulong digits ulong to void |
| 26 | i = digits |
| 27 | while gt i 0 bound 16 |
| 28 | i = sub i 1 |
| 29 | n = and shr v mul i 4 15 |
| 30 | if gt n 9 |
| 31 | pch add n 87 |
| 32 | else |
| 33 | pch add n 48 |
| 34 | end |
| 35 | end |
| 36 | end |
| 37 | fn pdec v ulong to void |
| 38 | if ge v 10 |
| 39 | pdec div v 10 |
| 40 | end |
| 41 | pch add 48 rem v 10 |
| 42 | end |
| 43 | fn pmac lo ulong hi ulong to void |
| 44 | for i ulong 6 |
| 45 | x = ulong 0 |
| 46 | if lt i 4 |
| 47 | x = and shr lo mul i 8 255 |
| 48 | else |
| 49 | x = and shr hi mul sub i 4 8 255 |
| 50 | end |
| 51 | phex x 2 |
| 52 | if lt i 5 |
| 53 | w = write 1 tcol 0 1 |
| 54 | end |
| 55 | end |
| 56 | w = write 1 tnl 0 1 |
| 57 | end |
| 58 | |
| 59 | fn main to int |
| 60 | if lt argcnt 2 |
| 61 | w = write 2 tusg 0 len tusg |
| 62 | exit int 10 |
| 63 | end |
| 64 | pth = new uchar 256 0 |
| 65 | n = argread 1 pth 0 255 |
| 66 | if lt n 1 |
| 67 | exit int 10 |
| 68 | end |
| 69 | fd = fopen pth 0 ulong n 0 0 |
| 70 | if lt fd 0 |
| 71 | exit int 11 |
| 72 | end |
| 73 | h = mapnew int fd 0 MMIOMIN 1 1 |
| 74 | if lt h 0 |
| 75 | exit int 12 |
| 76 | end |
| 77 | put hm 0 h |
| 78 | tcr = rtlr32 TCR |
| 79 | if eq tcr 4294967295 |
| 80 | w = write 2 tabs 0 len tabs |
| 81 | exit int 13 |
| 82 | end |
| 83 | if ne and tcr TCRIDM TCRID |
| 84 | w = write 2 tbad 0 len tbad |
| 85 | exit int 14 |
| 86 | end |
| 87 | w = write 1 tid 0 len tid |
| 88 | phex tcr 8 |
| 89 | w = write 1 tnl 0 1 |
| 90 | w = write 1 tmac 0 len tmac |
| 91 | pmac rtlr32 BAKADR0 rtlr16 BAKADR1 |
| 92 | w = write 1 tmac0 0 len tmac0 |
| 93 | pmac rtlr32 MAC0 rtlr16 MAC4 |
| 94 | if eq rtllink 1 |
| 95 | w = write 1 tlup 0 len tlup |
| 96 | pdec get rs S_MBPS |
| 97 | w = write 1 tnl 0 1 |
| 98 | else |
| 99 | w = write 1 tldn 0 len tldn |
| 100 | end |
| 101 | w = write 1 tro 0 len tro |
| 102 | ret 0 |
| 103 | end |