-
Notifications
You must be signed in to change notification settings - Fork 2
/
syscon.tcl
313 lines (274 loc) · 11.8 KB
/
syscon.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
set d [lindex [get_service_paths device] 0]
set sof [file join fejkon.sof]
set masters [get_service_paths master]
if {[llength $masters] == 0} {
puts " ==> WARNING: No masters found <=="
puts "To program the device, run 'device_download_sof \$d \$sof'"
return
}
set m [lindex $masters 0]
open_service master $m
puts ""
puts "=> Fejkon system console initialized"
puts ""
puts " Master is available at \$m"
puts ""
if {![jtag_debug_sense_clock $m]} {
puts " ==> WARNING: Clock not detected as running <=="
puts ""
}
puts " E.g:"
puts " - master_write_32 \$m 0x000e0000 5"
puts " - jtag_debug_reset_system \$m"
puts " - sfp \[1-4]"
puts " - enable \[1-4]"
puts " - fcstat \[1-4]"
puts " - pcie"
puts " - clocks"
puts " - id"
proc id {} {
global m
set off [expr 0x0]
master_write_32 $m [expr $off] 0
puts [format " Version : %s" [master_read_8 $m [expr $off + 0x2] 1]]
set po [master_read_8 $m [expr $off + 0x3] 1]
set fc_ports [expr $po & 0xf]
set eth_ports [expr ($po >> 4) & 0xf]
puts [format " Ports : FC %s Ethernet %s" $fc_ports $eth_ports]
puts [format " Git rev. : %s" [master_read_32 $m [expr $off + 0x4] 1]]
}
proc ltssm_str {state} {
switch $state {
0 { return "Detect.Quiet" }
1 { return "Detect.Active" }
2 { return "Polling.Active" }
3 { return "Polling.Compliance" }
4 { return "Polling.Configuration" }
5 { return "Polling.Speed" }
6 { return "config.Linkwidthstart" }
7 { return "Config.Linkaccept" }
8 { return "Config.Lanenumaccept" }
9 { return "Config.Lanenumwait" }
10 { return "Config.Complete" }
11 { return "Config.Idle" }
12 { return "Recovery.Rcvlock" }
13 { return "Recovery.Rcvconfig" }
14 { return "Recovery.Idle" }
15 { return "L0" }
16 { return "Disable" }
17 { return "Loopback.Entry" }
18 { return "Loopback.Active" }
19 { return "Loopback.Exit" }
20 { return "Hot.Reset" }
21 { return "LOs" }
25 { return "L2.transmit.Wake" }
26 { return "Recovery.Speed" }
27 { return "Recovery.Equalization, Phase 0" }
28 { return "Recovery.Equalization, Phase 1" }
29 { return "Recovery.Equalization, Phase 2" }
30 { return "Recovery.Equalization, Phase 3" }
31 { return "Recovery.Equalization, Done" }
default { return "<Unknown>" }
}
}
proc pcie {} {
global m
set off [expr 0x800]
set ltssm [expr [master_read_8 $m [expr $off + 0x180] 1]]
puts [format " LTSSM state : %s (0x%02x)" [ltssm_str $ltssm] $ltssm]
puts [format " Lanes active : %s" [format "x%d" [master_read_8 $m [expr $off + 0x181] 1]]]
puts [format " My ID : %s" [master_read_16 $m [expr $off + 0x00] 1]]
puts ""
puts [format " TLP RX : %s" [master_read_32 $m [expr $off + 0x04] 1]]
puts [format " TLP Unsupported RX : %s" [master_read_32 $m [expr $off + 0x08] 1]]
puts [format " TLP TX Data : %s" [master_read_32 $m [expr $off + 0x0c] 1]]
puts [format " TLP TX Instant : %s" [master_read_32 $m [expr $off + 0x10] 1]]
puts [format " TLP TX Response : %s" [master_read_32 $m [expr $off + 0x14] 1]]
puts ""
puts [format " Last TLP RX : %s" [master_read_32 $m [expr $off + 0x20] 8]]
puts [format " Last TLP TX Data : %s" [master_read_32 $m [expr $off + 0x40] 8]]
puts [format " Last TLP TX Instant : %s" [master_read_32 $m [expr $off + 0x60] 8]]
puts [format " Last TLP TX Response : %s" [master_read_32 $m [expr $off + 0x80] 8]]
puts ""
puts [format " C2H Packet counter : %s" [master_read_32 $m [expr $off + 0x18] 1]]
puts [format " C2H Start address : %s" [master_read_32 $m [expr $off + 0xA0] 1]]
puts [format " C2H End address : %s" [master_read_32 $m [expr $off + 0xA4] 1]]
puts [format " C2H Host read ptr : %s" [master_read_32 $m [expr $off + 0xA8] 1]]
puts [format " C2H Card write ptr : %s" [master_read_32 $m [expr $off + 0xAC] 1]]
}
proc clocks {} {
global m
set off [expr 0x20]
puts [format " PHY : %s MHz" [format "%.3f" [expr [master_read_32 $m [expr $off + 0x00] 1] / 1000000.0]]]
puts [format " PCIe : %s MHz" [format "%.3f" [expr [master_read_32 $m [expr $off + 0x04] 1] / 1000000.0]]]
}
proc check_fc_port {id} {
global m
set po [master_read_8 $m 0x3 1]
set fc_ports [expr $po & 0xf]
if {$id > $fc_ports} {
puts [format " ** WARNING ** Accessing past last FC port (# FC ports = %s)" $fc_ports]
}
if {$id <= 0} {
puts [format "FC Port IDs start at 1"]
return false
}
return true
}
proc check_eth_port {id} {
global m
set po [master_read_8 $m 0x3 1]
set eth_ports [expr ($po >> 4) & 0xf]
if {$id > [expr 2 + $eth_ports]} {
puts [format " ** WARNING ** Accessing past last Ethernet port (# Ethernet ports = %s)" $eth_ports]
}
if {$id <= 2} {
puts [format "Ethernet Port IDs start at 3"]
return false
}
return true
}
proc check_port {id} {
global m
set po [master_read_8 $m 0x3 1]
set fc_ports [expr $po & 0xf]
set eth_ports [expr ($po >> 4) & 0xf]
set ports [expr $fc_ports + $eth_ports]
if {$id > $ports} {
puts [format " ** WARNING ** Accessing past last port (# ports = %s)" $ports]
}
if {$id <= 0} {
puts [format "Port IDs start at 1"]
return false
}
return true
}
proc enable {id} {
if {![check_fc_port $id]} {
return
}
global m
set off [expr 0x100 * $id]
master_write_32 $m [expr $off] 0
}
proc fcstat {id} {
if {![check_fc_port $id]} {
return
}
global m
set off [expr 0x6000 + $id * 0x2000]
puts [format " XCVR : %s" [master_read_32 $m [expr $off + 0x00 * 4] 1]]
puts [format " Last Unk. : %s" [master_read_32 $m [expr $off + 0x01 * 4] 1]]
puts [format " State : %s" [master_read_32 $m [expr $off + 0x1000] 1]]
puts " -- Prims RX TX"
# TODO: Calculate rate?
puts [format " IDLE : %s %s" [master_read_32 $m [expr $off + 0x80 + 0x00 * 4] 1] [master_read_32 $m [expr $off + 0x100 + 0x00 * 4] 1]]
puts [format " R_RDY : %s %s" [master_read_32 $m [expr $off + 0x80 + 0x01 * 4] 1] [master_read_32 $m [expr $off + 0x100 + 0x01 * 4] 1]]
puts [format " VC_RDY : %s %s" [master_read_32 $m [expr $off + 0x80 + 0x02 * 4] 1] [master_read_32 $m [expr $off + 0x100 + 0x02 * 4] 1]]
puts [format " BB_SCS : %s %s" [master_read_32 $m [expr $off + 0x80 + 0x03 * 4] 1] [master_read_32 $m [expr $off + 0x100 + 0x03 * 4] 1]]
puts [format " BB_SCR : %s %s" [master_read_32 $m [expr $off + 0x80 + 0x04 * 4] 1] [master_read_32 $m [expr $off + 0x100 + 0x04 * 4] 1]]
puts [format " SOFi2 : %s %s" [master_read_32 $m [expr $off + 0x80 + 0x05 * 4] 1] [master_read_32 $m [expr $off + 0x100 + 0x05 * 4] 1]]
puts [format " SOFn2 : %s %s" [master_read_32 $m [expr $off + 0x80 + 0x06 * 4] 1] [master_read_32 $m [expr $off + 0x100 + 0x06 * 4] 1]]
puts [format " SOFi3 : %s %s" [master_read_32 $m [expr $off + 0x80 + 0x07 * 4] 1] [master_read_32 $m [expr $off + 0x100 + 0x07 * 4] 1]]
puts [format " SOFn3 : %s %s" [master_read_32 $m [expr $off + 0x80 + 0x08 * 4] 1] [master_read_32 $m [expr $off + 0x100 + 0x08 * 4] 1]]
puts [format " SOFf : %s %s" [master_read_32 $m [expr $off + 0x80 + 0x09 * 4] 1] [master_read_32 $m [expr $off + 0x100 + 0x09 * 4] 1]]
puts [format " EOFt : %s %s" [master_read_32 $m [expr $off + 0x80 + 0x0a * 4] 1] [master_read_32 $m [expr $off + 0x100 + 0x0a * 4] 1]]
puts [format " EOFa : %s %s" [master_read_32 $m [expr $off + 0x80 + 0x0b * 4] 1] [master_read_32 $m [expr $off + 0x100 + 0x0b * 4] 1]]
puts [format " EOFn : %s %s" [master_read_32 $m [expr $off + 0x80 + 0x0c * 4] 1] [master_read_32 $m [expr $off + 0x100 + 0x0c * 4] 1]]
puts [format " EOFni : %s %s" [master_read_32 $m [expr $off + 0x80 + 0x0d * 4] 1] [master_read_32 $m [expr $off + 0x100 + 0x0d * 4] 1]]
puts [format " NOS : %s %s" [master_read_32 $m [expr $off + 0x80 + 0x0e * 4] 1] [master_read_32 $m [expr $off + 0x100 + 0x0e * 4] 1]]
puts [format " OLS : %s %s" [master_read_32 $m [expr $off + 0x80 + 0x0f * 4] 1] [master_read_32 $m [expr $off + 0x100 + 0x0f * 4] 1]]
puts [format " LR : %s %s" [master_read_32 $m [expr $off + 0x80 + 0x10 * 4] 1] [master_read_32 $m [expr $off + 0x100 + 0x10 * 4] 1]]
puts [format " LRR : %s %s" [master_read_32 $m [expr $off + 0x80 + 0x11 * 4] 1] [master_read_32 $m [expr $off + 0x100 + 0x11 * 4] 1]]
puts [format " ARBff : %s %s" [master_read_32 $m [expr $off + 0x80 + 0x12 * 4] 1] [master_read_32 $m [expr $off + 0x100 + 0x12 * 4] 1]]
puts [format " Unknown : %s %s" [master_read_32 $m [expr $off + 0x80 + 0x13 * 4] 1] [master_read_32 $m [expr $off + 0x100 + 0x13 * 4] 1]]
}
proc sfp {id} {
if {![check_port $id]} {
return
}
global m
set off [expr 0x100 * $id]
set status [master_read_8 $m $off 1]
puts [format " SFP status: %s" $status]
if {[expr $status & 1] != 0} {
puts [format " - SFP present"]
} else {
puts [format " - SFP *not* present"]
}
if {[expr $status & 2] != 0} {
puts [format " - Loss of signal detected"]
}
if {[expr $status & 4] != 0} {
puts [format " - TX fault detected"]
}
if {[expr $status & 8] != 0} {
puts [format " - TX is disabled"]
} else {
puts [format " - TX is enabled"]
}
if {[expr $status & 1] == 0} {
# Only probe the SFP port if it is reported as present
return
}
master_write_32 $m [expr $off + 0x48] 0
# Configure ISER, SCL_LOW, SCL_HIGH, SDA_HOLD register
master_write_32 $m [expr $off + 0x4c] 0x0 ; # No interrupts
master_write_32 $m [expr $off + 0x60] 250
master_write_32 $m [expr $off + 0x64] 250
master_write_32 $m [expr $off + 0x68] 15
master_write_32 $m [expr $off + 0x48] 1
# Read three byte @ 0x0
master_write_32 $m [expr $off + 0x40] 0x2A0
master_write_32 $m [expr $off + 0x40] 0x000
master_write_32 $m [expr $off + 0x40] 0x2A1
master_write_32 $m [expr $off + 0x40] 0x000
master_write_32 $m [expr $off + 0x40] 0x000
master_write_32 $m [expr $off + 0x40] 0x100
puts [format " SFP identifier: %s" [master_read_8 $m [expr $off + 0x44] 1]]
puts [format " SFP ext. identifier: %s" [master_read_8 $m [expr $off + 0x44] 1]]
puts [format " SFP connector: %s" [master_read_8 $m [expr $off + 0x44] 1]]
# Read vendor @ 0x14
master_write_32 $m [expr $off + 0x40] 0x2A0
master_write_32 $m [expr $off + 0x40] 0x014
master_write_32 $m [expr $off + 0x40] 0x2A1
master_write_32 $m [expr $off + 0x40] 0x000
set vendor [master_read_8 $m [expr $off + 0x44] 1]
for {set i 0} {$i < 14} {incr i} {
master_write_32 $m [expr $off + 0x40] 0x000
lappend vendor [master_read_8 $m [expr $off + 0x44] 1]
}
master_write_32 $m [expr $off + 0x40] 0x100
lappend vendor [master_read_8 $m [expr $off + 0x44] 1]
puts [format " SFP vendor: '%s'" [binary format c* $vendor]]
# Read vendor PN @ 0x28
master_write_32 $m [expr $off + 0x40] 0x2A0
master_write_32 $m [expr $off + 0x40] 0x028
master_write_32 $m [expr $off + 0x40] 0x2A1
master_write_32 $m [expr $off + 0x40] 0x000
set vendor [master_read_8 $m [expr $off + 0x44] 1]
for {set i 0} {$i < 14} {incr i} {
master_write_32 $m [expr $off + 0x40] 0x000
lappend vendor [master_read_8 $m [expr $off + 0x44] 1]
}
master_write_32 $m [expr $off + 0x40] 0x100
lappend vendor [master_read_8 $m [expr $off + 0x44] 1]
puts [format " SFP vendor PN: '%s'" [binary format c* $vendor]]
# Read vendor SN @ 0x44
master_write_32 $m [expr $off + 0x40] 0x2A0
master_write_32 $m [expr $off + 0x40] 0x044
master_write_32 $m [expr $off + 0x40] 0x2A1
master_write_32 $m [expr $off + 0x40] 0x000
set vendor [master_read_8 $m [expr $off + 0x44] 1]
for {set i 0} {$i < 14} {incr i} {
master_write_32 $m [expr $off + 0x40] 0x000
lappend vendor [master_read_8 $m [expr $off + 0x44] 1]
}
master_write_32 $m [expr $off + 0x40] 0x100
lappend vendor [master_read_8 $m [expr $off + 0x44] 1]
puts [format " SFP vendor SN: '%s'" [binary format c* $vendor]]
}
proc generate {pkts} {
global m
master_write_32 $m 0x40 $pkts
}