Skip to content

Commit 8338d93

Browse files
ShayAgrosSaeed Mahameed
authored andcommitted
net/mlx5: Added devlink info callback
The callback is invoked using 'devlink dev info <pci>' command and returns the running and pending firmware version of the HCA and the name of the kernel driver. If there is a pending firmware version (a new version is burned but the HCA still runs with the previous) it is returned as the stored firmware version. Otherwise, the running version is returned for this field. Output example: $ devlink dev info pci/0000:00:06.0 pci/0000:00:06.0: driver mlx5_core versions: fixed: fw.psid MT_0000000009 running: fw.version 16.26.0100 stored: fw.version 16.26.0100 Signed-off-by: Shay Agroskin <[email protected]> Reviewed-by: Jakub Kicinski <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 9c86b07 commit 8338d93

File tree

2 files changed

+79
-0
lines changed
  • Documentation/networking/device_drivers/mellanox
  • drivers/net/ethernet/mellanox/mlx5/core

2 files changed

+79
-0
lines changed

Documentation/networking/device_drivers/mellanox/mlx5.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Contents
1010
========
1111

1212
- `Enabling the driver and kconfig options`_
13+
- `Devlink info`_
1314
- `Devlink health reporters`_
1415

1516
Enabling the driver and kconfig options
@@ -101,6 +102,24 @@ Enabling the driver and kconfig options
101102
- CONFIG_VXLAN: When chosen, mlx5 vxaln support will be enabled.
102103
- CONFIG_MLXFW: When chosen, mlx5 firmware flashing support will be enabled (via devlink and ethtool).
103104

105+
Devlink info
106+
============
107+
108+
The devlink info reports the running and stored firmware versions on device.
109+
It also prints the device PSID which represents the HCA board type ID.
110+
111+
User command example::
112+
113+
$ devlink dev info pci/0000:00:06.0
114+
pci/0000:00:06.0:
115+
driver mlx5_core
116+
versions:
117+
fixed:
118+
fw.psid MT_0000000009
119+
running:
120+
fw.version 16.26.0100
121+
stored:
122+
fw.version 16.26.0100
104123

105124
Devlink health reporters
106125
========================

drivers/net/ethernet/mellanox/mlx5/core/devlink.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,65 @@ static int mlx5_devlink_flash_update(struct devlink *devlink,
2525
return mlx5_firmware_flash(dev, fw, extack);
2626
}
2727

28+
static u8 mlx5_fw_ver_major(u32 version)
29+
{
30+
return (version >> 24) & 0xff;
31+
}
32+
33+
static u8 mlx5_fw_ver_minor(u32 version)
34+
{
35+
return (version >> 16) & 0xff;
36+
}
37+
38+
static u16 mlx5_fw_ver_subminor(u32 version)
39+
{
40+
return version & 0xffff;
41+
}
42+
43+
#define DEVLINK_FW_STRING_LEN 32
44+
45+
static int
46+
mlx5_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req,
47+
struct netlink_ext_ack *extack)
48+
{
49+
struct mlx5_core_dev *dev = devlink_priv(devlink);
50+
char version_str[DEVLINK_FW_STRING_LEN];
51+
u32 running_fw, stored_fw;
52+
int err;
53+
54+
err = devlink_info_driver_name_put(req, DRIVER_NAME);
55+
if (err)
56+
return err;
57+
58+
err = devlink_info_version_fixed_put(req, "fw.psid", dev->board_id);
59+
if (err)
60+
return err;
61+
62+
err = mlx5_fw_version_query(dev, &running_fw, &stored_fw);
63+
if (err)
64+
return err;
65+
66+
snprintf(version_str, sizeof(version_str), "%d.%d.%04d",
67+
mlx5_fw_ver_major(running_fw), mlx5_fw_ver_minor(running_fw),
68+
mlx5_fw_ver_subminor(running_fw));
69+
err = devlink_info_version_running_put(req, "fw.version", version_str);
70+
if (err)
71+
return err;
72+
73+
/* no pending version, return running (stored) version */
74+
if (stored_fw == 0)
75+
stored_fw = running_fw;
76+
77+
snprintf(version_str, sizeof(version_str), "%d.%d.%04d",
78+
mlx5_fw_ver_major(stored_fw), mlx5_fw_ver_minor(stored_fw),
79+
mlx5_fw_ver_subminor(stored_fw));
80+
err = devlink_info_version_stored_put(req, "fw.version", version_str);
81+
if (err)
82+
return err;
83+
84+
return 0;
85+
}
86+
2887
static const struct devlink_ops mlx5_devlink_ops = {
2988
#ifdef CONFIG_MLX5_ESWITCH
3089
.eswitch_mode_set = mlx5_devlink_eswitch_mode_set,
@@ -35,6 +94,7 @@ static const struct devlink_ops mlx5_devlink_ops = {
3594
.eswitch_encap_mode_get = mlx5_devlink_eswitch_encap_mode_get,
3695
#endif
3796
.flash_update = mlx5_devlink_flash_update,
97+
.info_get = mlx5_devlink_info_get,
3898
};
3999

40100
struct devlink *mlx5_devlink_alloc(void)

0 commit comments

Comments
 (0)