Skip to contentSkip to conversation

Print link status when it is changed

PATCH New Leon Romanovsky 1 participant 4 messages Jan 19, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Print link status when it is changed

In similar to netdev and hfi1 behaviour, add general implementation to IB/core to print IB port state changes.

"mlx5_core 0000:08:00.0 mlx5_0: Port DOWN"
"mlx5_core 0000:08:00.0 rocep8s0f0: Port ACTIVE"

Thanks

Maher Sanalla (3):
IB/cache: Add log messages for IB device state changes RDMA/core: Use ib_port_state_to_str() for IB state sysfs IB/hfi1: Remove state transition log message and opa_lstate_name()

 drivers/infiniband/core/cache.c     |  5 +++++
 drivers/infiniband/core/sysfs.c     | 14 +-------------
 drivers/infiniband/hw/hfi1/chip.c   | 18 ------------------
 drivers/infiniband/hw/hfi1/chip.h   |  1 -
 drivers/infiniband/hw/hfi1/driver.c |  2 +-
 drivers/infiniband/hw/hfi1/mad.c    |  4 ++--
 include/rdma/ib_verbs.h             | 17 +++++++++++++++++
 7 files changed, 26 insertions(+), 35 deletions(-)
Signature · 1 line
2.47.1
#1 lore raw

PATCH 1/3 IB/cache: Add log messages for IB device state changes

From: Maher Sanalla <[email protected]>

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 DOWN"
"mlx5_core 0000:08:00.0 rocep8s0f0: Port ACTIVE"

---
 drivers/infiniband/core/cache.c |  5 +++++
 include/rdma/ib_verbs.h         | 17 +++++++++++++++++
 2 files changed, 22 insertions(+)
drivers/infiniband/core/cache.c +5 -0
index f8413f8a9f26..a35a2f3c9ab1 100644
@@ -1501,6 +1501,11 @@ 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 != tprops->state)
+		ibdev_info(device, "Port %s\n",
+			   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;
include/rdma/ib_verbs.h +17 -0
index 0ad104dae253..b59bf30de430 100644
@@ -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,
Signature · 1 line
2.47.1
#2 lore raw

PATCH 2/3 RDMA/core: Use ib_port_state_to_str() for IB state sysfs

In reply to Leon Romanovsky

From: Maher Sanalla <[email protected]>

Refactor the IB state sysfs implementation to replace the local array used for converting IB state to string with the ib_port_state_to_str() function.

---
 drivers/infiniband/core/sysfs.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/infiniband/core/sysfs.c +1 -13
index 9f97bef02149..7491328ca5e6 100644
@@ -216,24 +216,12 @@ static ssize_t state_show(struct ib_device *ibdev, u32 port_num,
 	struct ib_port_attr attr;
 	ssize_t ret;
 
-	static const char *state_name[] = {
-		[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"
-	};
-
 	ret = ib_query_port(ibdev, port_num, &attr);
 	if (ret)
 		return ret;
 
 	return sysfs_emit(buf, "%d: %s\n", attr.state,
-			  attr.state >= 0 &&
-					  attr.state < ARRAY_SIZE(state_name) ?
-				  state_name[attr.state] :
-				  "UNKNOWN");
+			  ib_port_state_to_str(attr.state));
 }
 
 static ssize_t lid_show(struct ib_device *ibdev, u32 port_num,
Signature · 1 line
2.47.1
#3 lore raw

PATCH 3/3 IB/hfi1: Remove state transition log message and opa_lstate_name()

In reply to Leon Romanovsky

From: Maher Sanalla <[email protected]>

Remove the state transition log message from the hfi1 driver, as the IB core now logs the same information when handling a cache update event.

While at it, replace the hfi1-specific opa_lstate_name() function with the ib_verbs equivalent function, ib_port_state_to_str(), for converting IB port state to a string.

---
 drivers/infiniband/hw/hfi1/chip.c   | 18 ------------------
 drivers/infiniband/hw/hfi1/chip.h   |  1 -
 drivers/infiniband/hw/hfi1/driver.c |  2 +-
 drivers/infiniband/hw/hfi1/mad.c    |  4 ++--
 4 files changed, 3 insertions(+), 22 deletions(-)
drivers/infiniband/hw/hfi1/chip.c +0 -18
index a442eca498b8..368b6be3226f 100644
@@ -12882,22 +12882,6 @@ u32 chip_to_opa_pstate(struct hfi1_devdata *dd, u32 chip_pstate)
 	}
 }
 
-/* return the OPA port logical state name */
-const char *opa_lstate_name(u32 lstate)
-{
-	static const char * const port_logical_names[] = {
-		"PORT_NOP",
-		"PORT_DOWN",
-		"PORT_INIT",
-		"PORT_ARMED",
-		"PORT_ACTIVE",
-		"PORT_ACTIVE_DEFER",
-	};
-	if (lstate < ARRAY_SIZE(port_logical_names))
-		return port_logical_names[lstate];
-	return "unknown";
-}
-
 /* return the OPA port physical state name */
 const char *opa_pstate_name(u32 pstate)
 {
@@ -12956,8 +12940,6 @@ static void update_statusp(struct hfi1_pportdata *ppd, u32 state)
 			break;
 		}
 	}
-	dd_dev_info(ppd->dd, "logical state changed to %s (0x%x)\n",
-		    opa_lstate_name(state), state);
 }
 
 /**
drivers/infiniband/hw/hfi1/chip.h +0 -1
index 8841db16bde7..6992f6d40255 100644
@@ -771,7 +771,6 @@ int is_bx(struct hfi1_devdata *dd);
 bool is_urg_masked(struct hfi1_ctxtdata *rcd);
 u32 read_physical_state(struct hfi1_devdata *dd);
 u32 chip_to_opa_pstate(struct hfi1_devdata *dd, u32 chip_pstate);
-const char *opa_lstate_name(u32 lstate);
 const char *opa_pstate_name(u32 pstate);
 u32 driver_pstate(struct hfi1_pportdata *ppd);
 u32 driver_lstate(struct hfi1_pportdata *ppd);
drivers/infiniband/hw/hfi1/driver.c +1 -1
index 37a6794885d3..50826e7cdb7e 100644
@@ -968,7 +968,7 @@ static bool __set_armed_to_active(struct hfi1_packet *packet)
 		if (hwstate != IB_PORT_ACTIVE) {
 			dd_dev_info(packet->rcd->dd,
 				    "Unexpected link state %s\n",
-				    opa_lstate_name(hwstate));
+				    ib_port_state_to_str(hwstate));
 			return false;
 		}
 
drivers/infiniband/hw/hfi1/mad.c +2 -2
index a9883295f4af..b39f63ce6dfc 100644
@@ -1160,8 +1160,8 @@ static int port_states_transition_allowed(struct hfi1_pportdata *ppd,
 	if (ret == HFI_TRANSITION_DISALLOWED ||
 	    ret == HFI_TRANSITION_UNDEFINED) {
 		pr_warn("invalid logical state transition %s -> %s\n",
-			opa_lstate_name(logical_old),
-			opa_lstate_name(logical_new));
+			ib_port_state_to_str(logical_old),
+			ib_port_state_to_str(logical_new));
 		return ret;
 	}
 
Signature · 1 line
2.47.1