]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
IB/cache: Add log messages for IB device state changes
authorMaher Sanalla <msanalla@nvidia.com>
Mon, 3 Feb 2025 12:48:04 +0000 (14:48 +0200)
committerLeon Romanovsky <leon@kernel.org>
Thu, 6 Feb 2025 08:40:50 +0000 (03:40 -0500)
Enhance visibility into IB device state transitions by adding log messages
to the kernel log (dmesg). Whenever an IB device changes state, a relevant
print will be printed, such as:

"mlx5_core 0000:08:00.0 mlx5_0: Port: 1 Link DOWN"
"mlx5_core 0000:08:00.0 rdmap8s0f0: Port: 2 Link ACTIVE"

Signed-off-by: Maher Sanalla <msanalla@nvidia.com>
Link: https://patch.msgid.link/2d26ccbd669bad99089fa2aebb5cba4014fc4999.1738586601.git.leon@kernel.org
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/infiniband/core/cache.c
include/rdma/ib_verbs.h

index f8413f8a9f26fcb00b07b387f0dbea658b00b80b..9979a351577f176ed5a15c34098ba7be24938694 100644 (file)
@@ -1501,6 +1501,12 @@ ib_cache_update(struct ib_device *device, u32 port, bool update_gids,
                device->port_data[port].cache.pkey = pkey_cache;
        }
        device->port_data[port].cache.lmc = tprops->lmc;
+
+       if (device->port_data[port].cache.port_state != IB_PORT_NOP &&
+           device->port_data[port].cache.port_state != tprops->state)
+               ibdev_info(device, "Port: %d Link %s\n", port,
+                          ib_port_state_to_str(tprops->state));
+
        device->port_data[port].cache.port_state = tprops->state;
 
        device->port_data[port].cache.subnet_prefix = tprops->subnet_prefix;
index 0ad104dae2539ba0ceb7e04088d6c0614cd46767..b59bf30de430adebf722f6a523871634421e4111 100644 (file)
@@ -519,6 +519,23 @@ enum ib_port_state {
        IB_PORT_ACTIVE_DEFER    = 5
 };
 
+static inline const char *__attribute_const__
+ib_port_state_to_str(enum ib_port_state state)
+{
+       const char * const states[] = {
+               [IB_PORT_NOP] = "NOP",
+               [IB_PORT_DOWN] = "DOWN",
+               [IB_PORT_INIT] = "INIT",
+               [IB_PORT_ARMED] = "ARMED",
+               [IB_PORT_ACTIVE] = "ACTIVE",
+               [IB_PORT_ACTIVE_DEFER] = "ACTIVE_DEFER",
+       };
+
+       if (state < ARRAY_SIZE(states))
+               return states[state];
+       return "UNKNOWN";
+}
+
 enum ib_port_phys_state {
        IB_PORT_PHYS_STATE_SLEEP = 1,
        IB_PORT_PHYS_STATE_POLLING = 2,