@@ -107,20 +107,22 @@ func (s *SriovInfo) IsVF() bool {
107107
108108// NvidiaPCIDevice represents a PCI device for an NVIDIA product.
109109type NvidiaPCIDevice struct {
110- Path string
111- Address string
112- Vendor uint16
113- Class uint32
114- ClassName string
115- Device uint16
116- DeviceName string
117- Driver string
118- IommuGroup int
119- IommuFD string
120- NumaNode int
121- Config * ConfigSpace
122- Resources MemoryResources
123- SriovInfo SriovInfo
110+ Path string
111+ Address string
112+ Vendor uint16
113+ Class uint32
114+ ClassName string
115+ Device uint16
116+ SubsystemVendor uint16
117+ SubsystemDevice uint16
118+ DeviceName string
119+ Driver string
120+ IommuGroup int
121+ IommuFD string
122+ NumaNode int
123+ Config * ConfigSpace
124+ Resources MemoryResources
125+ SriovInfo SriovInfo
124126}
125127
126128// IsVGAController if class == 0x300.
@@ -298,6 +300,32 @@ func (p *nvpci) getNvidiaDeviceByPciBusID(address string, cache map[string]*Nvid
298300 return nil , fmt .Errorf ("unable to convert device string to uint16: %v" , deviceStr )
299301 }
300302
303+ var subsystemVendorID uint64
304+ subsystemVendor , err := os .ReadFile (path .Join (devicePath , "subsystem_vendor" ))
305+ switch {
306+ case err == nil :
307+ subsystemVendorStr := strings .TrimSpace (string (subsystemVendor ))
308+ subsystemVendorID , err = strconv .ParseUint (subsystemVendorStr , 0 , 16 )
309+ if err != nil {
310+ return nil , fmt .Errorf ("unable to convert subsystem vendor string to uint16: %v" , subsystemVendorStr )
311+ }
312+ case ! os .IsNotExist (err ):
313+ return nil , fmt .Errorf ("unable to read PCI subsystem vendor id for %s: %v" , address , err )
314+ }
315+
316+ var subsystemDeviceID uint64
317+ subsystemDevice , err := os .ReadFile (path .Join (devicePath , "subsystem_device" ))
318+ switch {
319+ case err == nil :
320+ subsystemDeviceStr := strings .TrimSpace (string (subsystemDevice ))
321+ subsystemDeviceID , err = strconv .ParseUint (subsystemDeviceStr , 0 , 16 )
322+ if err != nil {
323+ return nil , fmt .Errorf ("unable to convert subsystem device string to uint16: %v" , subsystemDeviceStr )
324+ }
325+ case ! os .IsNotExist (err ):
326+ return nil , fmt .Errorf ("unable to read PCI subsystem device id for %s: %v" , address , err )
327+ }
328+
301329 driver , err := getDriver (devicePath )
302330 if err != nil {
303331 return nil , fmt .Errorf ("unable to detect driver for %s: %w" , address , err )
@@ -391,20 +419,22 @@ func (p *nvpci) getNvidiaDeviceByPciBusID(address string, cache map[string]*Nvid
391419 }
392420
393421 nvdevice := & NvidiaPCIDevice {
394- Path : devicePath ,
395- Address : address ,
396- Vendor : uint16 (vendorID ),
397- Class : uint32 (classID ),
398- Device : uint16 (deviceID ),
399- Driver : driver ,
400- IommuGroup : int (iommuGroup ),
401- IommuFD : iommuFD ,
402- NumaNode : int (numaNode ),
403- Config : config ,
404- Resources : resources ,
405- DeviceName : deviceName ,
406- ClassName : className ,
407- SriovInfo : sriovInfo ,
422+ Path : devicePath ,
423+ Address : address ,
424+ Vendor : uint16 (vendorID ),
425+ Class : uint32 (classID ),
426+ Device : uint16 (deviceID ),
427+ SubsystemVendor : uint16 (subsystemVendorID ),
428+ SubsystemDevice : uint16 (subsystemDeviceID ),
429+ Driver : driver ,
430+ IommuGroup : int (iommuGroup ),
431+ IommuFD : iommuFD ,
432+ NumaNode : int (numaNode ),
433+ Config : config ,
434+ Resources : resources ,
435+ DeviceName : deviceName ,
436+ ClassName : className ,
437+ SriovInfo : sriovInfo ,
408438 }
409439
410440 // Cache physical functions only as VF can't be a root device.
0 commit comments