-
Notifications
You must be signed in to change notification settings - Fork 564
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: look up Links PCI vendor/product via PCI ID database
This increases `initramfs` size by 356060 bytes (raw text database is 1.3 MiB). In QEMU: ``` $ talosctl -n 172.20.0.2 get links eth0 -o yaml spec: ... productID: "0x1000" vendorID: "0x1af4" product: Virtio network device vendor: Red Hat, Inc. ``` Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
- Loading branch information
Showing
6 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
// Package pci provides methods to access PCI-related data. | ||
package pci | ||
|
||
import ( | ||
"github.com/siderolabs/go-pcidb/pkg/pcidb" | ||
) | ||
|
||
// Device describes PCI device. | ||
type Device struct { | ||
VendorID uint16 | ||
ProductID uint16 | ||
|
||
Vendor string | ||
Product string | ||
} | ||
|
||
// LookupDB looks up device info in the PCI database. | ||
func (d *Device) LookupDB() { | ||
d.Vendor, _ = pcidb.LookupVendor(d.VendorID) | ||
d.Product, _ = pcidb.LookupProduct(d.VendorID, d.ProductID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
package pci | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"fmt" | ||
"io/fs" | ||
"io/ioutil" | ||
"strconv" | ||
) | ||
|
||
const sysfsPath = "/sys/bus/pci/devices/%s/%s" | ||
|
||
func readID(busPath, name string) (uint16, error) { | ||
contents, err := ioutil.ReadFile(fmt.Sprintf(sysfsPath, busPath, name)) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
v, err := strconv.ParseUint(string(bytes.TrimSpace(contents)), 0, 16) | ||
|
||
return uint16(v), err | ||
} | ||
|
||
// SysfsDeviceInfo looks up vendor and product ID from sysfs. | ||
func SysfsDeviceInfo(busPath string) (*Device, error) { | ||
var ( | ||
d Device | ||
err error | ||
) | ||
|
||
d.ProductID, err = readID(busPath, "device") | ||
if err != nil { | ||
if errors.Is(err, fs.ErrNotExist) { | ||
return nil, nil | ||
} | ||
|
||
return nil, err | ||
} | ||
|
||
d.VendorID, err = readID(busPath, "vendor") | ||
if err != nil { | ||
if errors.Is(err, fs.ErrNotExist) { | ||
return nil, nil | ||
} | ||
|
||
return nil, err | ||
} | ||
|
||
return &d, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters