interplane.Get Omega
Read in your language

rtl8127-omega

aien-dev/rtl8127-omega

Brought by drakestapleton

branch main Branches Tags History

rtl8127-omega / cmd / rtl8127d / probe.om

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