|
| 1 | +// Copyright 2025 CoreOS, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | +// |
| 15 | +// The NVIDIA BlueField [1] provider fetches configurations from the bootfifo interface. |
| 16 | +// [1] https://www.nvidia.com/en-eu/networking/products/data-processing-unit |
| 17 | + |
| 18 | +package nvidiabluefield |
| 19 | + |
| 20 | +import ( |
| 21 | + "bytes" |
| 22 | + "os" |
| 23 | + "os/exec" |
| 24 | + |
| 25 | + "github.com/coreos/ignition/v2/config/v3_6_experimental/types" |
| 26 | + "github.com/coreos/ignition/v2/internal/distro" |
| 27 | + "github.com/coreos/ignition/v2/internal/platform" |
| 28 | + "github.com/coreos/ignition/v2/internal/providers/util" |
| 29 | + "github.com/coreos/ignition/v2/internal/resource" |
| 30 | + |
| 31 | + "github.com/coreos/vcontext/report" |
| 32 | +) |
| 33 | + |
| 34 | +// bootfifo paths are exposed in sysfs by the mlxbf-bootctl platform driver. |
| 35 | +// https://github.com/torvalds/linux/blob/2fbe820/drivers/platform/mellanox/mlxbf-bootctl.c#L954 |
| 36 | +var bootfifoPaths = []string{ |
| 37 | + "/sys/bus/platform/devices/MLNXBF04:00/bootfifo", |
| 38 | +} |
| 39 | + |
| 40 | +func init() { |
| 41 | + platform.Register(platform.Provider{ |
| 42 | + Name: "nvidiabluefield", |
| 43 | + Fetch: fetchConfig, |
| 44 | + }) |
| 45 | +} |
| 46 | + |
| 47 | +func fetchConfig(f *resource.Fetcher) (cfg types.Config, rpt report.Report, err error) { |
| 48 | + // load mlxbf-bootctl module |
| 49 | + if _, err = f.Logger.LogCmd(exec.Command(distro.ModprobeCmd(), "mlxbf_bootctl"), "loading mlxbf-booctl kernel module"); err != nil { |
| 50 | + return |
| 51 | + } |
| 52 | + |
| 53 | + for _, bootfifoPath := range bootfifoPaths { |
| 54 | + f.Logger.Debug("Attempting to read bootfifo at %s", bootfifoPath) |
| 55 | + raw, err := os.ReadFile(bootfifoPath) |
| 56 | + |
| 57 | + if os.IsNotExist(err) { |
| 58 | + continue |
| 59 | + } else if err != nil { |
| 60 | + f.Logger.Err("Could not read bootfifo at %s: %v", bootfifoPath, err) |
| 61 | + continue |
| 62 | + } |
| 63 | + |
| 64 | + if len(raw) == 0 { |
| 65 | + continue |
| 66 | + } |
| 67 | + |
| 68 | + data := bytes.Trim(raw, "\x00") |
| 69 | + return util.ParseConfig(f.Logger, data) |
| 70 | + } |
| 71 | + |
| 72 | + f.Logger.Info("No config found in any of the NVIDIA BlueField bootfifo interfaces") |
| 73 | + return types.Config{}, report.Report{}, err |
| 74 | +} |
0 commit comments