Skip to contentSkip to conversation

net: mana: Support HW link state events

PATCH Superseded Haiyang Zhang 3 participants 5 messages Oct 13, 2025 – Oct 14, 2025

Subsystems (5)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: mana: Support HW link state events

From: Haiyang Zhang <[email protected]>

Handle the HW link state events received from HW channel, and set the proper link state, also stop/wake queues accordingly.

---
 .../net/ethernet/microsoft/mana/gdma_main.c   |  1 +
 .../net/ethernet/microsoft/mana/hw_channel.c  | 12 ++++
 drivers/net/ethernet/microsoft/mana/mana_en.c | 64 +++++++++++++++++--
 include/net/mana/gdma.h                       |  4 +-
 include/net/mana/hw_channel.h                 |  2 +
 include/net/mana/mana.h                       |  4 ++
 6 files changed, 79 insertions(+), 8 deletions(-)
drivers/net/ethernet/microsoft/mana/gdma_main.c +1 -0
index 43f034e180c4..effe0a2f207a 100644
@@ -528,6 +528,7 @@ static void mana_gd_process_eqe(struct gdma_queue *eq)
 	case GDMA_EQE_HWC_INIT_DONE:
 	case GDMA_EQE_HWC_SOC_SERVICE:
 	case GDMA_EQE_RNIC_QP_FATAL:
+	case GDMA_EQE_HWC_SOC_RECONFIG_DATA:
 		if (!eq->eq.callback)
 			break;
 
drivers/net/ethernet/microsoft/mana/hw_channel.c +12 -0
index ada6c78a2bef..4d4113628027 100644
@@ -118,6 +118,7 @@ static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self,
 	struct gdma_dev *gd = hwc->gdma_dev;
 	union hwc_init_type_data type_data;
 	union hwc_init_eq_id_db eq_db;
+	struct mana_context *ac;
 	u32 type, val;
 	int ret;
 
@@ -196,6 +197,17 @@ static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self,
 			hwc->hwc_timeout = val;
 			break;
 
+		case HWC_DATA_HW_LINK_CONNECT:
+		case HWC_DATA_HW_LINK_DISCONNECT:
+			ac = gd->gdma_context->mana.driver_data;
+			if (!ac)
+				break;
+
+			ac->link_event = type;
+			schedule_delayed_work(&ac->link_change_work, 0);
+
+			break;
+
 		default:
 			dev_warn(hwc->dev, "Received unknown reconfig type %u\n", type);
 			break;
drivers/net/ethernet/microsoft/mana/mana_en.c +57 -7

112 lines not on this page · raw message

include/net/mana/gdma.h +3 -1
index 57df78cfbf82..637f42485dba 100644
@@ -590,6 +590,7 @@ enum {
 
 /* Driver can self reset on FPGA Reconfig EQE notification */
 #define GDMA_DRV_CAP_FLAG_1_HANDLE_RECONFIG_EQE BIT(17)
+#define GDMA_DRV_CAP_FLAG_1_HW_VPORT_LINK_AWARE BIT(6)
 
 #define GDMA_DRV_CAP_FLAGS1 \
 	(GDMA_DRV_CAP_FLAG_1_EQ_SHARING_MULTI_VPORT | \
@@ -599,7 +600,8 @@ enum {
 	 GDMA_DRV_CAP_FLAG_1_DEV_LIST_HOLES_SUP | \
 	 GDMA_DRV_CAP_FLAG_1_DYNAMIC_IRQ_ALLOC_SUPPORT | \
 	 GDMA_DRV_CAP_FLAG_1_SELF_RESET_ON_EQE | \
-	 GDMA_DRV_CAP_FLAG_1_HANDLE_RECONFIG_EQE)
+	 GDMA_DRV_CAP_FLAG_1_HANDLE_RECONFIG_EQE | \
+	 GDMA_DRV_CAP_FLAG_1_HW_VPORT_LINK_AWARE)
 
 #define GDMA_DRV_CAP_FLAGS2 0
 
include/net/mana/hw_channel.h +2 -0
index 83cf93338eb3..16feb39616c1 100644
@@ -24,6 +24,8 @@
 #define HWC_INIT_DATA_PF_DEST_CQ_ID	11
 
 #define HWC_DATA_CFG_HWC_TIMEOUT 1
+#define HWC_DATA_HW_LINK_CONNECT 2
+#define HWC_DATA_HW_LINK_DISCONNECT 3
 
 #define HW_CHANNEL_WAIT_RESOURCE_TIMEOUT_MS 30000
 
include/net/mana/mana.h +4 -0
index 0921485565c0..eee90bb9da1e 100644
@@ -477,6 +477,10 @@ struct mana_context {
 	struct dentry *mana_eqs_debugfs;
 
 	struct net_device *ports[MAX_PORTS_IN_MANA_DEV];
+
+	/* Link state change work */
+	struct delayed_work link_change_work;
+	u32 link_event;
 };
 
 struct mana_port_context {
Signature · 1 line
2.34.1
#1 lore raw

drivers/net/ethernet/microsoft/mana/mana_en.c static int mana_close(struct net_device *ndev) · line 112

Quoted 8 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +8 -0
+static void mana_link_state_handle(struct work_struct *w)
+{
+	struct mana_context *ac =
+		container_of(w, struct mana_context, link_change_work.work);
+	struct mana_port_context *apc;
+	struct net_device *ndev;
+	bool link_up;
+	int i;

Since you don't need ac here, i would postpone the assignment into the body of the function, so keeping with reverse christmass tree.

drivers/net/ethernet/microsoft/mana/mana_en.c static int mana_close(struct net_device *ndev) · line 117

Quoted 5 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +5 -0
+
+	if (!rtnl_trylock()) {
+		schedule_delayed_work(&ac->link_change_work, 1);
+		return;
+	}

Is there a deadlock you are trying to avoid here? Why not wait for the lock?

Quoted 19 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +19 -0
+
+	if (ac->link_event == HWC_DATA_HW_LINK_CONNECT)
+		link_up = true;
+	else if (ac->link_event == HWC_DATA_HW_LINK_DISCONNECT)
+		link_up = false;
+	else
+		goto out;
+
+	/* Process all ports */
+	for (i = 0; i < ac->num_ports; i++) {
+		ndev = ac->ports[i];
+		if (!ndev)
+			continue;
+
+		apc = netdev_priv(ndev);
+
+		if (link_up) {
+			netif_carrier_on(ndev);
+

drivers/net/ethernet/microsoft/mana/mana_en.c static int mana_close(struct net_device *ndev) · line 146

Quoted 10 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +10 -0
+			if (apc->port_is_up)
+				netif_tx_wake_all_queues(ndev);
+
+			__netdev_notify_peers(ndev);
+		} else {
+			if (netif_carrier_ok(ndev)) {
+				netif_tx_disable(ndev);
+				netif_carrier_off(ndev);
+			}
+		}

It is odd this is asymmetric. Up and down should really be opposites.

drivers/net/ethernet/microsoft/mana/mana_en.c void mana_remove(struct gdma_dev *gd, bool suspending) · line 3551

Quoted 5 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +1 -0
@@ -3500,6 +3548,8 @@ void mana_remove(struct gdma_dev *gd, bool suspending)
 	int err;
 	int i;
 
+	cancel_delayed_work_sync(&ac->link_change_work);

I don't know delayed work too well. Is this sufficient when the work requeues itself because it cannot get RTNL?

Andrew

maintainer
#2 lore raw
Quoted 21 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, October 13, 2025 5:13 PM
To: Haiyang Zhang <[email protected]>
Cc: [email protected]; [email protected]; Haiyang Zhang <[email protected]>; Paul Rosswurm <[email protected]>; Dexuan Cui <[email protected]>; KY Srinivasan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Long Li <[email protected]>; [email protected]; [email protected]; [email protected]; Konstantin Taranov <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Shiraz Saleem <[email protected]>; [email protected]; [email protected]; linux- [email protected]
Subject: [EXTERNAL] Re: [PATCH net-next] net: mana: Support HW link state events

Quoted 11 lines

drivers/net/ethernet/microsoft/mana/mana_en.c static int mana_close(struct net_device *ndev) · line 112

Quoted 8 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +8 -0
+static void mana_link_state_handle(struct work_struct *w)
+{
+	struct mana_context *ac =
+		container_of(w, struct mana_context, link_change_work.work);
+	struct mana_port_context *apc;
+	struct net_device *ndev;
+	bool link_up;
+	int i;

Since you don't need ac here, i would postpone the assignment into the body of the function, so keeping with reverse christmass tree.

Will do.

Quoted 9 lines

drivers/net/ethernet/microsoft/mana/mana_en.c static int mana_close(struct net_device *ndev) · line 117

Quoted 6 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +5 -0
+
+	if (!rtnl_trylock()) {
+		schedule_delayed_work(&ac->link_change_work, 1);
+		return;
+	}

Is there a deadlock you are trying to avoid here? Why not wait for the lock?

I think it's probably not needed, will double check...

Quoted 24 lines
Quoted 24 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +23 -0
+
+	if (ac->link_event == HWC_DATA_HW_LINK_CONNECT)
+		link_up = true;
+	else if (ac->link_event == HWC_DATA_HW_LINK_DISCONNECT)
+		link_up = false;
+	else
+		goto out;
+
+	/* Process all ports */
+	for (i = 0; i < ac->num_ports; i++) {
+		ndev = ac->ports[i];
+		if (!ndev)
+			continue;
+
+		apc = netdev_priv(ndev);
+
+		if (link_up) {
+			netif_carrier_on(ndev);
+
+			if (apc->port_is_up)
+				netif_tx_wake_all_queues(ndev);
+
+			__netdev_notify_peers(ndev);
Quoted 8 lines

drivers/net/ethernet/microsoft/mana/mana_en.c static int mana_close(struct net_device *ndev) · line 146

Quoted 6 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +6 -0
+		} else {
+			if (netif_carrier_ok(ndev)) {
+				netif_tx_disable(ndev);
+				netif_carrier_off(ndev);
+			}
+		}

It is odd this is asymmetric. Up and down should really be opposites.

For the up event, we need to delay the wake up queues if the mana_close() is called, or mana_open() isn't called yet.

Also, we notify peers only when link up.

Quoted 10 lines

Review void mana_remove(struct gdma_dev *gd, bool

Quoted 2 lines
(quoted diff) +0 -0
@@ -3500,6 +3548,8 @@ void mana_remove(struct gdma_dev *gd, bool

suspending)

drivers/net/ethernet/microsoft/mana/mana_en.c void mana_remove(struct gdma_dev *gd, bool suspending) · line 3551

Quoted 4 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +1 -0
 	int err;
 	int i;
 
+	cancel_delayed_work_sync(&ac->link_change_work);

I don't know delayed work too well. Is this sufficient when the work requeues itself because it cannot get RTNL?

cancel_work_sync()'s doc says "This function can be used even if the work re-queues itself". cancel_delayed_work_sync() calls the same underlying function but with WORK_CANCEL_DELAYED flag. So it should be OK.

Thanks,
- Haiyang

#3 lore raw
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +7 -0
+		if (link_up) {
+			netif_carrier_on(ndev);
+
+			if (apc->port_is_up)
+				netif_tx_wake_all_queues(ndev);
+
+			__netdev_notify_peers(ndev);
Quoted 8 lines

drivers/net/ethernet/microsoft/mana/mana_en.c static int mana_close(struct net_device *ndev) · line 146

Quoted 6 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +6 -0
+		} else {
+			if (netif_carrier_ok(ndev)) {
+				netif_tx_disable(ndev);
+				netif_carrier_off(ndev);
+			}
+		}

It is odd this is asymmetric. Up and down should really be opposites.

Quoted 4 lines

For the up event, we need to delay the wake up queues if the mana_close() is called, or mana_open() isn't called yet.

Also, we notify peers only when link up.

But why is this not symmetric?

On down, if port_is_up is not true, there is no need to disable tx and set the carrier off. There are also counters associated with netif_carrier_off() and netif_carrier_on(), and if you don't call them in symmetric pairs, the counters are going to look odd.

Quoted 4 lines

cancel_work_sync()'s doc says "This function can be used even if the work re-queues itself". cancel_delayed_work_sync() calls the same underlying function but with WORK_CANCEL_DELAYED flag. So it should be OK.

O.K, thanks

Andrew

maintainer
#4 lore raw
Quoted 39 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, October 13, 2025 7:22 PM
To: Haiyang Zhang <[email protected]>
Cc: Haiyang Zhang <[email protected]>; linux- [email protected]; [email protected]; Paul Rosswurm <[email protected]>; Dexuan Cui <[email protected]>; KY Srinivasan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Long Li <[email protected]>; [email protected]; [email protected]; [email protected]; Konstantin Taranov <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Shiraz Saleem <[email protected]>; [email protected]; [email protected]; linux- [email protected]
Subject: Re: [EXTERNAL] Re: [PATCH net-next] net: mana: Support HW link state events

Quoted 18 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +7 -0
+		if (link_up) {
+			netif_carrier_on(ndev);
+
+			if (apc->port_is_up)
+				netif_tx_wake_all_queues(ndev);
+
+			__netdev_notify_peers(ndev);
Quoted 8 lines

drivers/net/ethernet/microsoft/mana/mana_en.c static int mana_close(struct net_device *ndev) · line 146

Quoted 6 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +6 -0
+		} else {
+			if (netif_carrier_ok(ndev)) {
+				netif_tx_disable(ndev);
+				netif_carrier_off(ndev);
+			}
+		}

It is odd this is asymmetric. Up and down should really be opposites.

For the up event, we need to delay the wake up queues if the mana_close() is called, or mana_open() isn't called yet.

Quoted 8 lines
Quoted 1 line

Also, we notify peers only when link up.

But why is this not symmetric?

On down, if port_is_up is not true, there is no need to disable tx and set the carrier off. There are also counters associated with netif_carrier_off() and netif_carrier_on(), and if you don't call them in symmetric pairs, the counters are going to look odd.

I see. Will update the patch.

Thanks,
- Haiyang