Skip to content

Commit ac49a7f

Browse files
committed
Fall back to DPLL board labels for pin name validation when sysfs lacks SMA pins
On newer kernels (4.22+) SMA pins are not exposed via sysfs but are still configurable through DPLL. validatePinNames now accepts a strategy function (hasSysfsSMAPins) to decide per-device whether to check sysfs pins or DPLL board labels, mirroring the runtime pin-configuration path used by each plugin. Made-with: Cursor
1 parent ec64830 commit ac49a7f

File tree

2 files changed

+310
-52
lines changed

2 files changed

+310
-52
lines changed

addons/intel/validate.go

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ import (
1414
// It is a variable so it can be replaced in tests.
1515
var discoverSysfsPinsFunc = discoverPHCPins
1616

17+
// hasDPLLPinLabelFunc checks whether a pin name exists as a DPLL board label.
18+
// It is a variable so it can be replaced in tests.
19+
var hasDPLLPinLabelFunc = hasDPLLPinLabel
20+
21+
// hasSysfsSMAPinsFunc checks whether SMA pins are available via sysfs for a device.
22+
// It is a variable so it can be replaced in tests.
23+
var hasSysfsSMAPinsFunc = hasSysfsSMAPins
24+
25+
26+
func hasDPLLPinLabel(pinName string) bool {
27+
return len(DpllPins.GetAllPinsByLabel(pinName)) > 0
28+
}
29+
1730
// discoverPHCPins reads available PHC pin names from sysfs for a given device.
1831
// Returns the pin names found under /sys/class/net/<device>/device/ptp/<phc>/pins/
1932
func discoverPHCPins(device string) ([]string, error) {
@@ -95,27 +108,42 @@ func validateUnknownFields(rawJSON []byte, target interface{}) []string {
95108
return nil
96109
}
97110

98-
// validatePinNames checks that all pin names in the DevicePins map are valid
99-
// by discovering valid pins from sysfs at runtime.
100-
func validatePinNames(devicePins map[string]pinSet, pluginName string) []string {
111+
// validatePinNames checks that all pin names in the DevicePins map are valid.
112+
// The useSysfs strategy function decides per device whether to validate against
113+
// sysfs pins or DPLL board labels. This mirrors each plugin's runtime behavior:
114+
// - E810: passes hasSysfsSMAPins (sysfs when SMA1 exists, DPLL otherwise)
115+
// - E825/E830: passes alwaysSysfs (always sysfs, matching pinConfig.applyPinSet)
116+
func validatePinNames(devicePins map[string]pinSet, pluginName string, useSysfs func(string) bool) []string {
101117
var errs []string
102118
for device, pins := range devicePins {
103-
validPins, err := discoverSysfsPinsFunc(device)
104-
if err != nil {
105-
errs = append(errs, fmt.Sprintf(
106-
"%s plugin: failed to discover pins for device '%s': %v",
107-
pluginName, device, err))
108-
continue
109-
}
110-
validSet := make(map[string]bool, len(validPins))
111-
for _, p := range validPins {
112-
validSet[p] = true
113-
}
114-
for pinName := range pins {
115-
if !validSet[pinName] {
119+
if useSysfs(device) {
120+
// sysfs path: validate all pins against discovered sysfs pins
121+
sysfsPins, sysfsErr := discoverSysfsPinsFunc(device)
122+
if sysfsErr != nil {
116123
errs = append(errs, fmt.Sprintf(
117-
"%s plugin: unknown pin name '%s' for device '%s' (valid pins: %s)",
118-
pluginName, pinName, device, strings.Join(validPins, ", ")))
124+
"%s plugin: cannot discover sysfs pins for device '%s': %v",
125+
pluginName, device, sysfsErr))
126+
continue
127+
}
128+
validSet := make(map[string]bool, len(sysfsPins))
129+
for _, p := range sysfsPins {
130+
validSet[p] = true
131+
}
132+
for pinName := range pins {
133+
if !validSet[pinName] {
134+
errs = append(errs, fmt.Sprintf(
135+
"%s plugin: unknown pin name '%s' for device '%s' (valid sysfs pins: %s)",
136+
pluginName, pinName, device, strings.Join(sysfsPins, ", ")))
137+
}
138+
}
139+
} else {
140+
// DPLL path: validate all pins against DPLL board labels
141+
for pinName := range pins {
142+
if !hasDPLLPinLabelFunc(pinName) {
143+
errs = append(errs, fmt.Sprintf(
144+
"%s plugin: unknown pin name '%s' for device '%s' (not found in DPLL pin labels)",
145+
pluginName, pinName, device))
146+
}
119147
}
120148
}
121149
}
@@ -239,7 +267,7 @@ func ValidateE810Opts(rawJSON []byte) []string {
239267
return errs
240268
}
241269

242-
errs = append(errs, validatePinNames(opts.DevicePins, "e810")...)
270+
errs = append(errs, validatePinNames(opts.DevicePins, "e810", hasSysfsSMAPinsFunc)...)
243271
errs = append(errs, validatePinValues(opts.DevicePins, "e810")...)
244272

245273
// Validate interconnections
@@ -267,7 +295,7 @@ func ValidateE825Opts(rawJSON []byte) []string {
267295
return errs
268296
}
269297

270-
errs = append(errs, validatePinNames(opts.DevicePins, "e825")...)
298+
errs = append(errs, validatePinNames(opts.DevicePins, "e825", hasSysfsSMAPinsFunc)...)
271299
errs = append(errs, validatePinValues(opts.DevicePins, "e825")...)
272300

273301
return errs
@@ -290,7 +318,7 @@ func ValidateE830Opts(rawJSON []byte) []string {
290318
return errs
291319
}
292320

293-
errs = append(errs, validatePinNames(opts.DevicePins, "e830")...)
321+
errs = append(errs, validatePinNames(opts.DevicePins, "e830", hasSysfsSMAPinsFunc)...)
294322
errs = append(errs, validatePinValues(opts.DevicePins, "e830")...)
295323

296324
return errs

0 commit comments

Comments
 (0)