From d9650a73efc505c88decba557bc5fd167a6434c1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 21 Apr 2024 01:41:07 +0000 Subject: [PATCH] Bump github.com/NVIDIA/go-nvlib from 0.2.0 to 0.3.0 Bumps [github.com/NVIDIA/go-nvlib](https://github.com/NVIDIA/go-nvlib) from 0.2.0 to 0.3.0. - [Release notes](https://github.com/NVIDIA/go-nvlib/releases) - [Commits](https://github.com/NVIDIA/go-nvlib/compare/v0.2.0...v0.3.0) --- updated-dependencies: - dependency-name: github.com/NVIDIA/go-nvlib dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- .../NVIDIA/go-nvlib/pkg/nvmdev/mock.go | 11 ++- .../NVIDIA/go-nvlib/pkg/nvmdev/nvmdev.go | 32 ++++---- .../NVIDIA/go-nvlib/pkg/nvpci/bytes/bytes.go | 14 ++-- .../NVIDIA/go-nvlib/pkg/nvpci/config.go | 20 ++--- .../NVIDIA/go-nvlib/pkg/nvpci/mlxpci.go | 18 ++--- .../NVIDIA/go-nvlib/pkg/nvpci/mmio/mmio.go | 6 +- .../NVIDIA/go-nvlib/pkg/nvpci/mmio/mock.go | 9 ++- .../NVIDIA/go-nvlib/pkg/nvpci/mock.go | 8 +- .../NVIDIA/go-nvlib/pkg/nvpci/nvpci.go | 56 +++++++------- .../NVIDIA/go-nvlib/pkg/nvpci/resources.go | 10 +-- .../NVIDIA/go-nvlib/pkg/pciids/pciids.go | 76 +++++++++---------- vendor/modules.txt | 2 +- 14 files changed, 137 insertions(+), 131 deletions(-) diff --git a/go.mod b/go.mod index 39209acb..721c842d 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/NVIDIA/vgpu-device-manager go 1.21 require ( - github.com/NVIDIA/go-nvlib v0.2.0 + github.com/NVIDIA/go-nvlib v0.3.0 github.com/google/uuid v1.6.0 github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.9.0 diff --git a/go.sum b/go.sum index 71cd7550..82b6cac7 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/NVIDIA/go-nvlib v0.2.0 h1:roq+SDstbP1fcy2XVH7wB2Gz2/Ud7Q+NGQYOcVITVrA= -github.com/NVIDIA/go-nvlib v0.2.0/go.mod h1:kFuLNTyD1tF6FbRFlk+/EdUW5BrkE+v1Y3A3/9zKSjA= +github.com/NVIDIA/go-nvlib v0.3.0 h1:vd7jSOthJTqzqIWZrv317xDr1+Mnjoy5X4N69W9YwQM= +github.com/NVIDIA/go-nvlib v0.3.0/go.mod h1:NasUuId9hYFvwzuOHCu9F2X6oTU2tG0JHTfbJYuDAbA= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= diff --git a/vendor/github.com/NVIDIA/go-nvlib/pkg/nvmdev/mock.go b/vendor/github.com/NVIDIA/go-nvlib/pkg/nvmdev/mock.go index 2a53d174..9425743c 100644 --- a/vendor/github.com/NVIDIA/go-nvlib/pkg/nvmdev/mock.go +++ b/vendor/github.com/NVIDIA/go-nvlib/pkg/nvmdev/mock.go @@ -25,14 +25,14 @@ import ( "github.com/NVIDIA/go-nvlib/pkg/nvpci/bytes" ) -// MockNvmdev mock mdev device +// MockNvmdev mock mdev device. type MockNvmdev struct { *nvmdev } var _ Interface = (*MockNvmdev)(nil) -// NewMock creates new mock mediated (vGPU) and parent PCI devices and removes old devices +// NewMock creates new mock mediated (vGPU) and parent PCI devices and removes old devices. func NewMock() (mock *MockNvmdev, rerr error) { mdevParentsRootDir, err := os.MkdirTemp(os.TempDir(), "") if err != nil { @@ -60,13 +60,13 @@ func NewMock() (mock *MockNvmdev, rerr error) { return mock, nil } -// Cleanup removes the mocked mediated (vGPU) and parent PCI devices root folders +// Cleanup removes the mocked mediated (vGPU) and parent PCI devices root folders. func (m *MockNvmdev) Cleanup() { os.RemoveAll(m.mdevParentsRoot) os.RemoveAll(m.mdevDevicesRoot) } -// AddMockA100Parent creates an A100 like parent GPU mock device +// AddMockA100Parent creates an A100 like parent GPU mock device. func (m *MockNvmdev) AddMockA100Parent(address string, numaNode int) error { deviceDir := filepath.Join(m.mdevParentsRoot, address) err := os.MkdirAll(deviceDir, 0755) @@ -220,6 +220,9 @@ func (m *MockNvmdev) AddMockA100Mdev(uuid string, mdevType string, mdevTypeDir s return err } err = os.Symlink(filepath.Join(mdevDeviceDir, "vfio_mdev"), filepath.Join(mdevDeviceDir, "driver")) + if err != nil { + return err + } _, err = os.Create(filepath.Join(mdevDeviceDir, "200")) if err != nil { diff --git a/vendor/github.com/NVIDIA/go-nvlib/pkg/nvmdev/nvmdev.go b/vendor/github.com/NVIDIA/go-nvlib/pkg/nvmdev/nvmdev.go index 92612582..989e4f33 100644 --- a/vendor/github.com/NVIDIA/go-nvlib/pkg/nvmdev/nvmdev.go +++ b/vendor/github.com/NVIDIA/go-nvlib/pkg/nvmdev/nvmdev.go @@ -33,7 +33,7 @@ const ( mdevDevicesRoot = "/sys/bus/mdev/devices" ) -// Interface allows us to get a list of NVIDIA MDEV (vGPU) and parent devices +// Interface allows us to get a list of NVIDIA MDEV (vGPU) and parent devices. type Interface interface { GetAllDevices() ([]*Device, error) GetAllParentDevices() ([]*ParentDevice, error) @@ -46,13 +46,13 @@ type nvmdev struct { var _ Interface = (*nvmdev)(nil) -// ParentDevice represents an NVIDIA parent PCI device +// ParentDevice represents an NVIDIA parent PCI device. type ParentDevice struct { *nvpci.NvidiaPCIDevice mdevPaths map[string]string } -// Device represents an NVIDIA MDEV (vGPU) device +// Device represents an NVIDIA MDEV (vGPU) device. type Device struct { Path string UUID string @@ -62,12 +62,12 @@ type Device struct { Parent *ParentDevice } -// New interface that allows us to get a list of all NVIDIA parent and MDEV (vGPU) devices +// New interface that allows us to get a list of all NVIDIA parent and MDEV (vGPU) devices. func New() Interface { return &nvmdev{mdevParentsRoot, mdevDevicesRoot} } -// GetAllParentDevices returns all NVIDIA Parent PCI devices on the system +// GetAllParentDevices returns all NVIDIA Parent PCI devices on the system. func (m *nvmdev) GetAllParentDevices() ([]*ParentDevice, error) { deviceDirs, err := os.ReadDir(m.mdevParentsRoot) if err != nil { @@ -101,7 +101,7 @@ func (m *nvmdev) GetAllParentDevices() ([]*ParentDevice, error) { return nvdevices, nil } -// GetAllDevices returns all NVIDIA mdev (vGPU) devices on the system +// GetAllDevices returns all NVIDIA mdev (vGPU) devices on the system. func (m *nvmdev) GetAllDevices() ([]*Device, error) { deviceDirs, err := os.ReadDir(m.mdevDevicesRoot) if err != nil { @@ -123,7 +123,7 @@ func (m *nvmdev) GetAllDevices() ([]*Device, error) { return nvdevices, nil } -// NewDevice constructs a Device, which represents an NVIDIA mdev (vGPU) device +// NewDevice constructs a Device, which represents an NVIDIA mdev (vGPU) device. func NewDevice(root string, uuid string) (*Device, error) { path := path.Join(root, uuid) @@ -240,14 +240,14 @@ func (m mdev) iommuGroup() (int, error) { return int(iommuGroup), nil } -// NewParentDevice constructs a ParentDevice +// NewParentDevice constructs a ParentDevice. func NewParentDevice(devicePath string) (*ParentDevice, error) { nvdevice, err := newNvidiaPCIDeviceFromPath(devicePath) if err != nil { return nil, fmt.Errorf("failed to construct NVIDIA PCI device: %v", err) } if nvdevice == nil { - // not a NVIDIA device + // not a NVIDIA device. return nil, err } @@ -275,7 +275,7 @@ func NewParentDevice(devicePath string) (*ParentDevice, error) { return &ParentDevice{nvdevice, mdevTypesMap}, err } -// CreateMDEVDevice creates a mediated device (vGPU) on the parent GPU +// CreateMDEVDevice creates a mediated device (vGPU) on the parent GPU. func (p *ParentDevice) CreateMDEVDevice(mdevType string, id string) error { mdevPath, ok := p.mdevPaths[mdevType] if !ok { @@ -292,7 +292,7 @@ func (p *ParentDevice) CreateMDEVDevice(mdevType string, id string) error { return nil } -// DeleteMDEVDevice deletes a mediated device (vGPU) +// DeleteMDEVDevice deletes a mediated device (vGPU). func (p *ParentDevice) DeleteMDEVDevice(id string) error { removeFile, err := os.OpenFile(filepath.Join(p.Path, id, "remove"), os.O_WRONLY|os.O_SYNC, 0200) if err != nil { @@ -306,7 +306,7 @@ func (p *ParentDevice) DeleteMDEVDevice(id string) error { return nil } -// Delete deletes a mediated device (vGPU) +// Delete deletes a mediated device (vGPU). func (m *Device) Delete() error { removeFile, err := os.OpenFile(filepath.Join(m.Path, "remove"), os.O_WRONLY|os.O_SYNC, 0200) if err != nil { @@ -320,7 +320,7 @@ func (m *Device) Delete() error { return nil } -// GetPhysicalFunction gets the physical PCI device backing a 'parent' device +// GetPhysicalFunction gets the physical PCI device backing a 'parent' device. func (p *ParentDevice) GetPhysicalFunction() (*nvpci.NvidiaPCIDevice, error) { if !p.IsVF { return p.NvidiaPCIDevice, nil @@ -334,18 +334,18 @@ func (p *ParentDevice) GetPhysicalFunction() (*nvpci.NvidiaPCIDevice, error) { return newNvidiaPCIDeviceFromPath(physfnPath) } -// GetPhysicalFunction gets the physical PCI device that a vGPU is created on +// GetPhysicalFunction gets the physical PCI device that a vGPU is created on. func (m *Device) GetPhysicalFunction() (*nvpci.NvidiaPCIDevice, error) { return m.Parent.GetPhysicalFunction() } -// IsMDEVTypeSupported checks if the mdevType is supported by the GPU +// IsMDEVTypeSupported checks if the mdevType is supported by the GPU. func (p *ParentDevice) IsMDEVTypeSupported(mdevType string) bool { _, found := p.mdevPaths[mdevType] return found } -// IsMDEVTypeAvailable checks if a vGPU instance of mdevType can be created on the parent GPU +// IsMDEVTypeAvailable checks if a vGPU instance of mdevType can be created on the parent GPU. func (p *ParentDevice) IsMDEVTypeAvailable(mdevType string) (bool, error) { availableInstances, err := p.GetAvailableMDEVInstances(mdevType) if err != nil { diff --git a/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/bytes/bytes.go b/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/bytes/bytes.go index 7788a1fb..04fb4aa9 100644 --- a/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/bytes/bytes.go +++ b/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/bytes/bytes.go @@ -21,12 +21,12 @@ import ( "unsafe" ) -// Raw returns just the bytes without any assumptions about layout +// Raw returns just the bytes without any assumptions about layout. type Raw interface { Raw() *[]byte } -// Reader used to read various data sizes in the byte array +// Reader used to read various data sizes in the byte array. type Reader interface { Read8(pos int) uint8 Read16(pos int) uint16 @@ -35,7 +35,7 @@ type Reader interface { Len() int } -// Writer used to write various sizes of data in the byte array +// Writer used to write various sizes of data in the byte array. type Writer interface { Write8(pos int, value uint8) Write16(pos int, value uint16) @@ -44,7 +44,7 @@ type Writer interface { Len() int } -// Bytes object for manipulating arbitrary byte arrays +// Bytes object for manipulating arbitrary byte arrays. type Bytes interface { Raw Reader @@ -70,12 +70,12 @@ func init() { } } -// New raw bytearray +// New raw bytearray. func New(data *[]byte) Bytes { return (*native)(data) } -// NewLittleEndian little endian ordering of bytes +// NewLittleEndian little endian ordering of bytes. func NewLittleEndian(data *[]byte) Bytes { if nativeByteOrder == binary.LittleEndian { return (*native)(data) @@ -84,7 +84,7 @@ func NewLittleEndian(data *[]byte) Bytes { return (*swapbo)(data) } -// NewBigEndian big endian ordering of bytes +// NewBigEndian big endian ordering of bytes. func NewBigEndian(data *[]byte) Bytes { if nativeByteOrder == binary.BigEndian { return (*native)(data) diff --git a/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/config.go b/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/config.go index e25e72f6..397c8650 100644 --- a/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/config.go +++ b/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/config.go @@ -24,24 +24,24 @@ import ( ) const ( - // PCICfgSpaceStandardSize represents the size in bytes of the standard config space + // PCICfgSpaceStandardSize represents the size in bytes of the standard config space. PCICfgSpaceStandardSize = 256 - // PCICfgSpaceExtendedSize represents the size in bytes of the extended config space + // PCICfgSpaceExtendedSize represents the size in bytes of the extended config space. PCICfgSpaceExtendedSize = 4096 - // PCICapabilityListPointer represents offset for the capability list pointer + // PCICapabilityListPointer represents offset for the capability list pointer. PCICapabilityListPointer = 0x34 - // PCIStatusCapabilityList represents the status register bit which indicates capability list support + // PCIStatusCapabilityList represents the status register bit which indicates capability list support. PCIStatusCapabilityList = 0x10 - // PCIStatusBytePosition represents the position of the status register + // PCIStatusBytePosition represents the position of the status register. PCIStatusBytePosition = 0x06 ) -// ConfigSpace PCI configuration space (standard extended) file path +// ConfigSpace PCI configuration space (standard extended) file path. type ConfigSpace struct { Path string } -// ConfigSpaceIO Interface for reading and writing raw and preconfigured values +// ConfigSpaceIO Interface for reading and writing raw and preconfigured values. type ConfigSpaceIO interface { bytes.Bytes GetVendorID() uint16 @@ -53,18 +53,18 @@ type configSpaceIO struct { bytes.Bytes } -// PCIStandardCapability standard PCI config space +// PCIStandardCapability standard PCI config space. type PCIStandardCapability struct { bytes.Bytes } -// PCIExtendedCapability extended PCI config space +// PCIExtendedCapability extended PCI config space. type PCIExtendedCapability struct { bytes.Bytes Version uint8 } -// PCICapabilities combines the standard and extended config space +// PCICapabilities combines the standard and extended config space. type PCICapabilities struct { Standard map[uint8]*PCIStandardCapability Extended map[uint16]*PCIExtendedCapability diff --git a/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/mlxpci.go b/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/mlxpci.go index 62937d7f..ddf7d19f 100644 --- a/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/mlxpci.go +++ b/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/mlxpci.go @@ -22,15 +22,15 @@ import ( ) const ( - // PCIMellanoxVendorID represents PCI vendor id for Mellanox + // PCIMellanoxVendorID represents PCI vendor id for Mellanox. PCIMellanoxVendorID uint16 = 0x15b3 - // PCINetworkControllerClass represents the PCI class for network controllers + // PCINetworkControllerClass represents the PCI class for network controllers. PCINetworkControllerClass uint32 = 0x020000 - // PCIBridgeClass represents the PCI class for network controllers + // PCIBridgeClass represents the PCI class for network controllers. PCIBridgeClass uint32 = 0x060400 ) -// GetNetworkControllers returns all Mellanox Network Controller PCI devices on the system +// GetNetworkControllers returns all Mellanox Network Controller PCI devices on the system. func (p *nvpci) GetNetworkControllers() ([]*NvidiaPCIDevice, error) { devices, err := p.GetAllDevices() if err != nil { @@ -47,7 +47,7 @@ func (p *nvpci) GetNetworkControllers() ([]*NvidiaPCIDevice, error) { return filtered, nil } -// GetPciBridges retrieves all Mellanox PCI(e) Bridges +// GetPciBridges retrieves all Mellanox PCI(e) Bridges. func (p *nvpci) GetPciBridges() ([]*NvidiaPCIDevice, error) { devices, err := p.GetAllDevices() if err != nil { @@ -64,17 +64,17 @@ func (p *nvpci) GetPciBridges() ([]*NvidiaPCIDevice, error) { return filtered, nil } -// IsNetworkController if class == 0x300 +// IsNetworkController if class == 0x300. func (d *NvidiaPCIDevice) IsNetworkController() bool { return d.Class == PCINetworkControllerClass } -// IsPciBridge if class == 0x0604 +// IsPciBridge if class == 0x0604. func (d *NvidiaPCIDevice) IsPciBridge() bool { return d.Class == PCIBridgeClass } -// IsDPU returns if a device is a DPU +// IsDPU returns if a device is a DPU. func (d *NvidiaPCIDevice) IsDPU() bool { if !strings.Contains(d.DeviceName, "BlueField") { return false @@ -87,7 +87,7 @@ func (d *NvidiaPCIDevice) IsDPU() bool { return false } -// GetDPUs returns all Mellanox DPU devices on the system +// GetDPUs returns all Mellanox DPU devices on the system. func (p *nvpci) GetDPUs() ([]*NvidiaPCIDevice, error) { devices, err := p.GetNetworkControllers() if err != nil { diff --git a/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/mmio/mmio.go b/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/mmio/mmio.go index 1535fa04..88dd7ddf 100644 --- a/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/mmio/mmio.go +++ b/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/mmio/mmio.go @@ -25,7 +25,7 @@ import ( "github.com/NVIDIA/go-nvlib/pkg/nvpci/bytes" ) -// Mmio memory map a region +// Mmio memory map a region. type Mmio interface { bytes.Raw bytes.Reader @@ -84,12 +84,12 @@ func open(path string, offset int, size int, flags int) (Mmio, error) { return &mmio{bytes.New(&mmap)}, nil } -// OpenRO open region readonly +// OpenRO open region readonly. func OpenRO(path string, offset int, size int) (Mmio, error) { return open(path, offset, size, os.O_RDONLY) } -// OpenRW open region read write +// OpenRW open region read write. func OpenRW(path string, offset int, size int) (Mmio, error) { return open(path, offset, size, os.O_RDWR) } diff --git a/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/mmio/mock.go b/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/mmio/mock.go index 57151b3f..da3074c1 100644 --- a/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/mmio/mock.go +++ b/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/mmio/mock.go @@ -48,18 +48,21 @@ func mockOpen(source *[]byte, offset int, size int, rw bool) (Mmio, error) { return m, nil } -// MockOpenRO open read only +// MockOpenRO open read only. func MockOpenRO(source *[]byte, offset int, size int) (Mmio, error) { return mockOpen(source, offset, size, false) } -// MockOpenRW open read write +// MockOpenRW open read write. func MockOpenRW(source *[]byte, offset int, size int) (Mmio, error) { return mockOpen(source, offset, size, true) } func (m *mockMmio) Close() error { - m = &mockMmio{} + m.Bytes = nil + m.source = nil + m.offset = 0 + m.rw = false return nil } diff --git a/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/mock.go b/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/mock.go index e4227121..7c1b69dd 100644 --- a/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/mock.go +++ b/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/mock.go @@ -24,14 +24,14 @@ import ( "github.com/NVIDIA/go-nvlib/pkg/nvpci/bytes" ) -// MockNvpci mock pci device +// MockNvpci mock pci device. type MockNvpci struct { *nvpci } var _ Interface = (*MockNvpci)(nil) -// NewMockNvpci create new mock PCI and remove old devices +// NewMockNvpci create new mock PCI and remove old devices. func NewMockNvpci() (mock *MockNvpci, rerr error) { rootDir, err := os.MkdirTemp(os.TempDir(), "") if err != nil { @@ -50,12 +50,12 @@ func NewMockNvpci() (mock *MockNvpci, rerr error) { return mock, nil } -// Cleanup remove the mocked PCI devices root folder +// Cleanup remove the mocked PCI devices root folder. func (m *MockNvpci) Cleanup() { os.RemoveAll(m.pciDevicesRoot) } -// AddMockA100 Create an A100 like GPU mock device +// AddMockA100 Create an A100 like GPU mock device. func (m *MockNvpci) AddMockA100(address string, numaNode int) error { deviceDir := filepath.Join(m.pciDevicesRoot, address) err := os.MkdirAll(deviceDir, 0755) diff --git a/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/nvpci.go b/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/nvpci.go index 5210ff50..6d83a577 100644 --- a/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/nvpci.go +++ b/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/nvpci.go @@ -29,23 +29,23 @@ import ( ) const ( - // PCIDevicesRoot represents base path for all pci devices under sysfs + // PCIDevicesRoot represents base path for all pci devices under sysfs. PCIDevicesRoot = "/sys/bus/pci/devices" - // PCINvidiaVendorID represents PCI vendor id for NVIDIA + // PCINvidiaVendorID represents PCI vendor id for NVIDIA. PCINvidiaVendorID uint16 = 0x10de - // PCIVgaControllerClass represents the PCI class for VGA Controllers + // PCIVgaControllerClass represents the PCI class for VGA Controllers. PCIVgaControllerClass uint32 = 0x030000 - // PCI3dControllerClass represents the PCI class for 3D Graphics accellerators + // PCI3dControllerClass represents the PCI class for 3D Graphics accellerators. PCI3dControllerClass uint32 = 0x030200 - // PCINvSwitchClass represents the PCI class for NVSwitches + // PCINvSwitchClass represents the PCI class for NVSwitches. PCINvSwitchClass uint32 = 0x068000 - // UnknownDeviceString is the device name to set for devices not found in the PCI database + // UnknownDeviceString is the device name to set for devices not found in the PCI database. UnknownDeviceString = "UNKNOWN_DEVICE" - // UnknownClassString is the class name to set for devices not found in the PCI database + // UnknownClassString is the class name to set for devices not found in the PCI database. UnknownClassString = "UNKNOWN_CLASS" ) -// Interface allows us to get a list of all NVIDIA PCI devices +// Interface allows us to get a list of all NVIDIA PCI devices. type Interface interface { GetAllDevices() ([]*NvidiaPCIDevice, error) Get3DControllers() ([]*NvidiaPCIDevice, error) @@ -59,10 +59,10 @@ type Interface interface { GetDPUs() ([]*NvidiaPCIDevice, error) } -// MemoryResources a more human readable handle +// MemoryResources a more human readable handle. type MemoryResources map[int]*MemoryResource -// ResourceInterface exposes some higher level functions of resources +// ResourceInterface exposes some higher level functions of resources. type ResourceInterface interface { GetTotalAddressableMemory(bool) (uint64, uint64) } @@ -76,7 +76,7 @@ type nvpci struct { var _ Interface = (*nvpci)(nil) var _ ResourceInterface = (*MemoryResources)(nil) -// NvidiaPCIDevice represents a PCI device for an NVIDIA product +// NvidiaPCIDevice represents a PCI device for an NVIDIA product. type NvidiaPCIDevice struct { Path string Address string @@ -93,34 +93,34 @@ type NvidiaPCIDevice struct { IsVF bool } -// IsVGAController if class == 0x300 +// IsVGAController if class == 0x300. func (d *NvidiaPCIDevice) IsVGAController() bool { return d.Class == PCIVgaControllerClass } -// Is3DController if class == 0x302 +// Is3DController if class == 0x302. func (d *NvidiaPCIDevice) Is3DController() bool { return d.Class == PCI3dControllerClass } -// IsNVSwitch if class == 0x068 +// IsNVSwitch if class == 0x068. func (d *NvidiaPCIDevice) IsNVSwitch() bool { return d.Class == PCINvSwitchClass } -// IsGPU either VGA for older cards or 3D for newer +// IsGPU either VGA for older cards or 3D for newer. func (d *NvidiaPCIDevice) IsGPU() bool { return d.IsVGAController() || d.Is3DController() } // IsResetAvailable some devices can be reset without rebooting, -// check if applicable +// check if applicable. func (d *NvidiaPCIDevice) IsResetAvailable() bool { _, err := os.Stat(path.Join(d.Path, "reset")) return err == nil } -// Reset perform a reset to apply a new configuration at HW level +// Reset perform a reset to apply a new configuration at HW level. func (d *NvidiaPCIDevice) Reset() error { err := os.WriteFile(path.Join(d.Path, "reset"), []byte("1"), 0) if err != nil { @@ -129,7 +129,7 @@ func (d *NvidiaPCIDevice) Reset() error { return nil } -// New interface that allows us to get a list of all NVIDIA PCI devices +// New interface that allows us to get a list of all NVIDIA PCI devices. func New(opts ...Option) Interface { n := &nvpci{} for _, opt := range opts { @@ -144,10 +144,10 @@ func New(opts ...Option) Interface { return n } -// Option defines a function for passing options to the New() call +// Option defines a function for passing options to the New() call. type Option func(*nvpci) -// WithLogger provides an Option to set the logger for the library +// WithLogger provides an Option to set the logger for the library. func WithLogger(logger logger) Option { return func(n *nvpci) { n.logger = logger @@ -170,7 +170,7 @@ func WithPCIDatabasePath(path string) Option { } } -// GetAllDevices returns all Nvidia PCI devices on the system +// GetAllDevices returns all Nvidia PCI devices on the system. func (p *nvpci) GetAllDevices() ([]*NvidiaPCIDevice, error) { deviceDirs, err := os.ReadDir(p.pciDevicesRoot) if err != nil { @@ -204,7 +204,7 @@ func (p *nvpci) GetAllDevices() ([]*NvidiaPCIDevice, error) { return nvdevices, nil } -// GetGPUByPciBusID constructs an NvidiaPCIDevice for the specified address (PCI Bus ID) +// GetGPUByPciBusID constructs an NvidiaPCIDevice for the specified address (PCI Bus ID). func (p *nvpci) GetGPUByPciBusID(address string) (*NvidiaPCIDevice, error) { devicePath := filepath.Join(p.pciDevicesRoot, address) @@ -265,7 +265,7 @@ func (p *nvpci) GetGPUByPciBusID(address string) (*NvidiaPCIDevice, error) { return nil, fmt.Errorf("unable to detect iommu_group for %s: %v", address, err) } - // device is a virtual function (VF) if "physfn" symlink exists + // device is a virtual function (VF) if "physfn" symlink exists. var isVF bool _, err = filepath.EvalSymlinks(path.Join(devicePath, "physfn")) if err == nil { @@ -347,7 +347,7 @@ func (p *nvpci) GetGPUByPciBusID(address string) (*NvidiaPCIDevice, error) { return nvdevice, nil } -// Get3DControllers returns all NVIDIA 3D Controller PCI devices on the system +// Get3DControllers returns all NVIDIA 3D Controller PCI devices on the system. func (p *nvpci) Get3DControllers() ([]*NvidiaPCIDevice, error) { devices, err := p.GetAllDevices() if err != nil { @@ -364,7 +364,7 @@ func (p *nvpci) Get3DControllers() ([]*NvidiaPCIDevice, error) { return filtered, nil } -// GetVGAControllers returns all NVIDIA VGA Controller PCI devices on the system +// GetVGAControllers returns all NVIDIA VGA Controller PCI devices on the system. func (p *nvpci) GetVGAControllers() ([]*NvidiaPCIDevice, error) { devices, err := p.GetAllDevices() if err != nil { @@ -381,7 +381,7 @@ func (p *nvpci) GetVGAControllers() ([]*NvidiaPCIDevice, error) { return filtered, nil } -// GetNVSwitches returns all NVIDIA NVSwitch PCI devices on the system +// GetNVSwitches returns all NVIDIA NVSwitch PCI devices on the system. func (p *nvpci) GetNVSwitches() ([]*NvidiaPCIDevice, error) { devices, err := p.GetAllDevices() if err != nil { @@ -398,7 +398,7 @@ func (p *nvpci) GetNVSwitches() ([]*NvidiaPCIDevice, error) { return filtered, nil } -// GetGPUs returns all NVIDIA GPU devices on the system +// GetGPUs returns all NVIDIA GPU devices on the system. func (p *nvpci) GetGPUs() ([]*NvidiaPCIDevice, error) { devices, err := p.GetAllDevices() if err != nil { @@ -415,7 +415,7 @@ func (p *nvpci) GetGPUs() ([]*NvidiaPCIDevice, error) { return filtered, nil } -// GetGPUByIndex returns an NVIDIA GPU device at a particular index +// GetGPUByIndex returns an NVIDIA GPU device at a particular index. func (p *nvpci) GetGPUByIndex(i int) (*NvidiaPCIDevice, error) { gpus, err := p.GetGPUs() if err != nil { diff --git a/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/resources.go b/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/resources.go index 6c6e53ee..b3b7d315 100644 --- a/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/resources.go +++ b/vendor/github.com/NVIDIA/go-nvlib/pkg/nvpci/resources.go @@ -29,7 +29,7 @@ const ( pmcBigEndian = 0x01000001 ) -// MemoryResource represents a mmio region +// MemoryResource represents a mmio region. type MemoryResource struct { Start uintptr End uintptr @@ -37,7 +37,7 @@ type MemoryResource struct { Path string } -// OpenRW read write mmio region +// OpenRW read write mmio region. func (mr *MemoryResource) OpenRW() (mmio.Mmio, error) { rw, err := mmio.OpenRW(mr.Path, 0, int(mr.End-mr.Start+1)) if err != nil { @@ -52,7 +52,7 @@ func (mr *MemoryResource) OpenRW() (mmio.Mmio, error) { return nil, fmt.Errorf("unknown endianness for mmio: %v", err) } -// OpenRO read only mmio region +// OpenRO read only mmio region. func (mr *MemoryResource) OpenRO() (mmio.Mmio, error) { ro, err := mmio.OpenRO(mr.Path, 0, int(mr.End-mr.Start+1)) if err != nil { @@ -67,7 +67,7 @@ func (mr *MemoryResource) OpenRO() (mmio.Mmio, error) { return nil, fmt.Errorf("unknown endianness for mmio: %v", err) } -// From Bit Twiddling Hacks, great resource for all low level bit manipulations +// From Bit Twiddling Hacks, great resource for all low level bit manipulations. func calcNextPowerOf2(n uint64) uint64 { n-- n |= n >> 1 @@ -83,7 +83,7 @@ func calcNextPowerOf2(n uint64) uint64 { // GetTotalAddressableMemory will accumulate the 32bit and 64bit memory windows // of each BAR and round the value if needed to the next power of 2; first -// return value is the accumulated 32bit addresable memory size the second one +// return value is the accumulated 32bit addressable memory size the second one // is the accumulated 64bit addressable memory size in bytes. These values are // needed to configure virtualized environments. func (mrs MemoryResources) GetTotalAddressableMemory(roundUp bool) (uint64, uint64) { diff --git a/vendor/github.com/NVIDIA/go-nvlib/pkg/pciids/pciids.go b/vendor/github.com/NVIDIA/go-nvlib/pkg/pciids/pciids.go index 5f25c004..343df08d 100644 --- a/vendor/github.com/NVIDIA/go-nvlib/pkg/pciids/pciids.go +++ b/vendor/github.com/NVIDIA/go-nvlib/pkg/pciids/pciids.go @@ -11,42 +11,42 @@ import ( "strings" ) -// token what the Lexer retruns +// token what the Lexer retruns. type token int const ( - // ILLEGAL a token which the Lexer does not understand + // ILLEGAL a token which the Lexer does not understand. ILLEGAL token = iota - // EOF end of file + // EOF end of file. EOF - // WS whitespace + // WS whitespace. WS - // NEWLINE '\n' + // NEWLINE '\n'. NEWLINE - // COMMENT '# something' + // COMMENT '# something'. COMMENT - // VENDOR PCI vendor + // VENDOR PCI vendor. VENDOR - // SUBVENDOR PCI subvendor + // SUBVENDOR PCI subvendor. SUBVENDOR - // DEVICE PCI device + // DEVICE PCI device. DEVICE - // CLASS PCI class + // CLASS PCI class. CLASS - // SUBCLASS PCI subclass + // SUBCLASS PCI subclass. SUBCLASS - // PROGIF PCI programming interface + // PROGIF PCI programming interface. PROGIF ) -// literal values from the Lexer +// literal values from the Lexer. type literal struct { ID string name string SubName string } -// scanner a lexical scanner +// scanner a lexical scanner. type scanner struct { r *bufio.Reader isVendor bool @@ -58,7 +58,7 @@ func newScanner(r io.Reader) *scanner { } // Since the pci.ids is line base we're consuming a whole line rather then only -// a single rune/char +// a single rune/char. func (s *scanner) readline() []byte { ln, err := s.r.ReadBytes('\n') if err == io.EOF { @@ -107,7 +107,7 @@ func isSubVendor(ln []byte) bool { return isLeadingTwoTabs(ln) } func isDevice(ln []byte) bool { return isLeadingOneTab(ln) } func isNewline(ln []byte) bool { return (ln[0] == '\n') } -// List of known device classes, subclasses and programming interfaces +// List of known device classes, subclasses and programming interfaces. func isClass(ln []byte) bool { return (ln[0] == 'C') } func isProgIf(ln []byte) bool { return isLeadingTwoTabs(ln) } func isSubClass(ln []byte) bool { return isLeadingOneTab(ln) } @@ -162,7 +162,7 @@ func (s *scanner) scan() (tok token, lit literal) { return ILLEGAL, literal{ID: string(line)} } -// parser reads the tokens returned by the Lexer and constructs the AST +// parser reads the tokens returned by the Lexer and constructs the AST. type parser struct { s *scanner buf struct { @@ -173,7 +173,7 @@ type parser struct { } // Various locations of pci.ids for different distributions. These may be more -// up to date then the embedded pci.ids db +// up to date then the embedded pci.ids db. var defaultPCIdbPaths = []string{ "/usr/share/misc/pci.ids", // Ubuntu "/usr/local/share/pci.ids", // RHEL like with manual update @@ -202,7 +202,7 @@ func NewDB(opts ...Option) Interface { return newParser(pcidbs).parse() } -// Option defines a function for passing options to the NewDB() call +// Option defines a function for passing options to the NewDB() call. type Option func(*pcidb) // WithFilePath provides an Option to set the file path @@ -216,7 +216,7 @@ func WithFilePath(path string) Option { } // newParser will attempt to read the db pci.ids from well known places or fall -// back to an internal db +// back to an internal db. func newParser(pcidbs []string) *parser { for _, db := range pcidbs { @@ -229,7 +229,7 @@ func newParser(pcidbs []string) *parser { } // We're using go embed above to have the byte array // correctly initialized with the internal shipped db - // if we cannot find an up to date in the filesystem + // if we cannot find an up to date in the filesystem. return newParserFromReader(bufio.NewReader(bytes.NewReader(defaultPCIdb))) } @@ -252,13 +252,13 @@ func (p *parser) unscan() { p.buf.n = 1 } var _ Interface = (*pcidb)(nil) -// Interface returns textual description of specific attributes of PCI devices +// Interface returns textual description of specific attributes of PCI devices. type Interface interface { GetDeviceName(uint16, uint16) (string, error) GetClassName(uint32) (string, error) } -// GetDeviceName return the textual description of the PCI device +// GetDeviceName return the textual description of the PCI device. func (d *pcidb) GetDeviceName(vendorID uint16, deviceID uint16) (string, error) { vendor, ok := d.vendors[vendorID] if !ok { @@ -273,7 +273,7 @@ func (d *pcidb) GetDeviceName(vendorID uint16, deviceID uint16) (string, error) return device.name, nil } -// GetClassName resturn the textual description of the PCI device class +// GetClassName resturn the textual description of the PCI device class. func (d *pcidb) GetClassName(classID uint32) (string, error) { class, ok := d.classes[classID] if !ok { @@ -282,53 +282,53 @@ func (d *pcidb) GetClassName(classID uint32) (string, error) { return class.name, nil } -// pcidb The complete set of PCI vendors and PCI classes +// pcidb The complete set of PCI vendors and PCI classes. type pcidb struct { vendors map[uint16]vendor classes map[uint32]class path string } -// vendor PCI vendors/devices/subVendors/SubDevices +// vendor PCI vendors/devices/subVendors/SubDevices. type vendor struct { name string devices map[uint16]device } -// subVendor PCI subVendor +// subVendor PCI subVendor. type subVendor struct { SubDevices map[uint16]SubDevice } -// SubDevice PCI SubDevice +// SubDevice PCI SubDevice. type SubDevice struct { name string } -// device PCI device +// device PCI device. type device struct { name string subVendors map[uint16]subVendor } -// class PCI classes/subClasses/Programming Interfaces +// class PCI classes/subClasses/Programming Interfaces. type class struct { name string subClasses map[uint32]subClass } -// subClass PCI subClass +// subClass PCI subClass. type subClass struct { name string progIfs map[uint8]progIf } -// progIf PCI Programming Interface +// progIf PCI Programming Interface. type progIf struct { name string } -// parse parses a PCI IDS entry +// parse parses a PCI IDS entry. func (p *parser) parse() Interface { db := &pcidb{ @@ -336,7 +336,7 @@ func (p *parser) parse() Interface { classes: map[uint32]class{}, } - // Used for housekeeping, breadcrumb for aggregated types + // Used for housekeeping, breadcrumb for aggregated types. var hkVendor vendor var hkDevice device @@ -349,8 +349,8 @@ func (p *parser) parse() Interface { for { tok, lit := p.scan() - // We're ignoring COMMENT, NEWLINE - // An EOF will break the loop + // We're ignoring COMMENT, NEWLINE. + // An EOF will break the loop. if tok == EOF { break } @@ -408,10 +408,10 @@ func (p *parser) parse() Interface { } hkSubClass = hkClass.subClasses[uint32(id)] - // Clear the last detected sub class + // Clear the last detected sub class. hkFullID = hkFullID & 0xFFFF0000 hkFullID = hkFullID | uint32(id)<<8 - // Clear the last detected prog iface + // Clear the last detected prog iface. hkFullID = hkFullID & 0xFFFFFF00 hkFullName[1] = fmt.Sprintf("%s (%02x)", lit.name, id) diff --git a/vendor/modules.txt b/vendor/modules.txt index 034ca22c..39fbf7aa 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,4 +1,4 @@ -# github.com/NVIDIA/go-nvlib v0.2.0 +# github.com/NVIDIA/go-nvlib v0.3.0 ## explicit; go 1.20 github.com/NVIDIA/go-nvlib/pkg/nvmdev github.com/NVIDIA/go-nvlib/pkg/nvpci