Implement the devlink .info_get callback for idpf, reporting:
  - serial_number: PCI Device Serial Number, for device identification
  - fw.mgmt.api: running version of the driver-device communication
    channel (virtchnl)

This enables NIPA CI and other tools to uniquely identify devices under
test and track device capabilities. This phased implementation initially
focuses on stable, readily available information. Firmware version
information will be added in future patches as support is exposed
through virtchnl and the driver architecture allows reliable retrieval.

The serial number is omitted on devices that do not implement the PCI
Device Serial Number extended capability, where pci_get_dsn() returns 0,
rather than reporting an all-zero serial number.

$ devlink dev show
pci/0000:85:00.0

$ devlink dev info pci/0000:85:00.0
pci/0000:85:00.0:
  driver idpf
  serial_number 00-a0-c9-ff-ff-23-45-67
  versions:
      running:
        fw.mgmt.api 2.0

Link: 
https://github.com/linux-netdev/nipa/wiki/Netdev-CI-system#device-information
Signed-off-by: Paul Greenwalt <[email protected]>
---
 Documentation/networking/devlink/idpf.rst     | 30 +++++++++
 Documentation/networking/devlink/index.rst    |  1 +
 .../net/ethernet/intel/idpf/idpf_devlink.c    | 65 +++++++++++++++++++
 3 files changed, 96 insertions(+)
 create mode 100644 Documentation/networking/devlink/idpf.rst

diff --git a/Documentation/networking/devlink/idpf.rst 
b/Documentation/networking/devlink/idpf.rst
new file mode 100644
index 000000000000..91e25b872f4f
--- /dev/null
+++ b/Documentation/networking/devlink/idpf.rst
@@ -0,0 +1,30 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+====================
+idpf devlink support
+====================
+
+This document describes the devlink features implemented by the ``idpf``
+device driver.
+
+Info versions
+=============
+
+The following table lists the version reported by the ``idpf`` driver.
+
+.. list-table:: devlink info versions implemented
+    :widths: 5 5 5 90
+
+    * - Name
+      - Type
+      - Example
+      - Description
+    * - ``fw.mgmt.api``
+      - running
+      - 2.0
+      - 2-digit version number (major.minor) of the communication channel
+        (virtchnl) used by the device.
+
+The driver also reports the PCI Device Serial Number through the
+``serial_number`` attribute, on devices that implement the PCI Device Serial
+Number extended capability.
diff --git a/Documentation/networking/devlink/index.rst 
b/Documentation/networking/devlink/index.rst
index d4a83fdcff7f..538494b1051b 100644
--- a/Documentation/networking/devlink/index.rst
+++ b/Documentation/networking/devlink/index.rst
@@ -85,6 +85,7 @@ parameters, info versions, and other features it supports.
    hns3
    i40e
    ice
+   idpf
    ionic
    iosm
    ixd
diff --git a/drivers/net/ethernet/intel/idpf/idpf_devlink.c 
b/drivers/net/ethernet/intel/idpf/idpf_devlink.c
index 1669bdfc950b..527c7714f9f7 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_devlink.c
+++ b/drivers/net/ethernet/intel/idpf/idpf_devlink.c
@@ -1,10 +1,75 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /* Copyright (C) 2026 Intel Corporation */
 
+#include <linux/pci.h>
+#include <linux/unaligned.h>
+
 #include "idpf.h"
 #include "idpf_devlink.h"
 
+#define IDPF_DEVLINK_INFO_LEN          128
+
+/**
+ * idpf_info_get_dsn - format the PCI DSN as the device serial number
+ * @adapter: the idpf adapter structure
+ * @buf: buffer to store the formatted serial number
+ * @buf_size: size of @buf
+ *
+ * Return: true if the device reports a DSN, false otherwise.
+ */
+static bool idpf_info_get_dsn(struct idpf_adapter *adapter, char *buf,
+                             size_t buf_size)
+{
+       u64 dsn = pci_get_dsn(adapter->pdev);
+       u8 dsn_be[sizeof(dsn)];
+
+       if (!dsn)
+               return false;
+
+       /* Copy the DSN into an array in Big Endian format */
+       put_unaligned_be64(dsn, dsn_be);
+       snprintf(buf, buf_size, "%8phD", dsn_be);
+
+       return true;
+}
+
+/**
+ * idpf_devlink_info_get - .info_get devlink handler
+ * @devlink: devlink instance structure
+ * @req: the devlink info request
+ * @extack: extended netlink ack structure
+ *
+ * Callback for the devlink .info_get operation. Reports information about the
+ * device. The instance is registered only after the virtchnl handshake has
+ * completed, so the reported version is the one negotiated by the most recent
+ * successful handshake.
+ *
+ * Return: zero on success or a negative error code on failure.
+ */
+static int idpf_devlink_info_get(struct devlink *devlink,
+                                struct devlink_info_req *req,
+                                struct netlink_ext_ack *extack)
+{
+       struct idpf_adapter *adapter = devlink_priv(devlink);
+       char buf[IDPF_DEVLINK_INFO_LEN];
+       int err;
+
+       if (idpf_info_get_dsn(adapter, buf, sizeof(buf))) {
+               err = devlink_info_serial_number_put(req, buf);
+               if (err)
+                       return err;
+       }
+
+       snprintf(buf, sizeof(buf), "%u.%u",
+                adapter->virt_ver_maj, adapter->virt_ver_min);
+
+       return devlink_info_version_running_put(req,
+                                       
DEVLINK_INFO_VERSION_GENERIC_FW_MGMT_API,
+                                       buf);
+}
+
 static const struct devlink_ops idpf_devlink_ops = {
+       .info_get = idpf_devlink_info_get,
 };
 
 /**
-- 
2.52.0

Reply via email to