Skip to content

Commit 6c64ca6

Browse files
committed
refactor Perla clock ID workaround
1 parent 8dfd6f9 commit 6c64ca6

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

pkg/hardwareconfig/utils.go

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,32 @@ func GetClockIDFromInterface(iface string, hwDefPath string) (uint64, error) {
212212
return GetClockIDFromInterfaceWithCache(iface, hwDefPath, nil)
213213
}
214214

215+
func getPERLAClockIDFromPinCache(cache *PinCache) (uint64, error) {
216+
if cache == nil {
217+
var cacheErr error
218+
cache, cacheErr = GetDpllPins()
219+
if cacheErr != nil {
220+
glog.Warningf("PERLA workaround: failed to get pin cache: %v, falling back to serial number approach", cacheErr)
221+
cache = nil
222+
}
223+
}
224+
225+
if cache != nil {
226+
// Look for first pin with moduleName == "zl3073x"
227+
for clockID, pins := range cache.Pins {
228+
for _, pin := range pins {
229+
if pin.ModuleName == "zl3073x" {
230+
glog.Infof("PERLA workaround: Found zl3073x DPLL with clock ID %#x", clockID)
231+
return clockID, nil
232+
}
233+
}
234+
}
235+
glog.Warningf("PERLA workaround: No zl3073x DPLL found in pin cache, falling back to serial number approach")
236+
}
237+
238+
return 0, fmt.Errorf("no zl3073x DPLL found in pin cache")
239+
}
240+
215241
// GetClockIDFromInterfaceWithCache resolves clock ID with an optional pre-loaded pin cache.
216242
// This avoids repeatedly fetching the pin cache for PERLA workaround.
217243
func GetClockIDFromInterfaceWithCache(iface string, hwDefPath string, pinCache *PinCache) (uint64, error) {
@@ -239,31 +265,14 @@ func GetClockIDFromInterfaceWithCache(iface string, hwDefPath string, pinCache *
239265
if err != nil {
240266
return 0, fmt.Errorf("failed to run lspci -s %s, output: %s, err: %w", busAddr, lspciOutput, err)
241267
}
268+
242269
if strings.Contains(lspciOutput, "E825") {
243270
glog.Infof("Detected E825 device on %s (interface %s), using PERLA workaround", busAddr, iface)
244-
// Use provided cache or fetch new one
245-
cache := pinCache
246-
if cache == nil {
247-
var cacheErr error
248-
cache, cacheErr = GetDpllPins()
249-
if cacheErr != nil {
250-
glog.Warningf("PERLA workaround: failed to get pin cache: %v, falling back to serial number approach", cacheErr)
251-
cache = nil
252-
}
253-
}
254-
255-
if cache != nil {
256-
// Look for first pin with moduleName == "zl3073x"
257-
for clockID, pins := range cache.Pins {
258-
for _, pin := range pins {
259-
if pin.ModuleName == "zl3073x" {
260-
glog.Infof("PERLA workaround: Found zl3073x DPLL with clock ID %#x, associating with E825 interface %s", clockID, iface)
261-
return clockID, nil
262-
}
263-
}
264-
}
265-
glog.Warningf("PERLA workaround: No zl3073x DPLL found in pin cache, falling back to serial number approach")
271+
clockID, err := getPERLAClockIDFromPinCache(pinCache)
272+
if err != nil {
273+
return 0, fmt.Errorf("PERLA workaround: failed to get clock ID from pin cache: %v, falling back to serial number approach", err)
266274
}
275+
return clockID, nil
267276
}
268277

269278
// Step 3: Standard approach - Get serial number using devlink

0 commit comments

Comments
 (0)