From nobody Sat Apr 4 01:45:59 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 68A8D3A7F57; Fri, 20 Mar 2026 23:54:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774050875; cv=none; b=l2ks2G3BdndNxGXC5+oRS7+Xa2CUbSmolajBQMIKgaYkM0lGyldqVgzixPyC9VcX8wSfw015ocyT0JD8sS3hQM2HJ6hmrlgUCc6CQz/XzIS3oOnQ4Rg1uRYt8Hi+gHeLSUBxcjHOtUAZALGnVVLFns25tQWdBTfOiXCWhkYKk4A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774050875; c=relaxed/simple; bh=bx4TxW0kLmD+UsJZ3TF9KQwztd8ZY1iD8K9uIiWbb0g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k9bdWG+QPWc1v42azhc04xPnYeow1mkQmMb1PfFQCQnKU9UQPMNdP8t1PKjuXdlzmYWMQc95GtlLGAHBZasL39Tbd3CSHZ74nXZ6/9dY/Wb+aKybfeHw3n/yz1VvboZz+DM2i9sZk4mMrZD5l8fuBsfeswl45XTl6e+L/oF6tMQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: by linux.microsoft.com (Postfix, from userid 1202) id 5928320B6F01; Fri, 20 Mar 2026 16:54:34 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5928320B6F01 From: Long Li To: Long Li , Konstantin Taranov , Jakub Kicinski , "David S . Miller" , Paolo Abeni , Eric Dumazet , Andrew Lunn , Jason Gunthorpe , Leon Romanovsky , Haiyang Zhang , "K . Y . Srinivasan" , Wei Liu , Dexuan Cui Cc: Simon Horman , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 1/6] net: mana: Create separate EQs for each vPort Date: Fri, 20 Mar 2026 16:54:14 -0700 Message-ID: X-Mailer: git-send-email 2.43.7 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To prepare for assigning vPorts to dedicated MSI-X vectors, remove EQ sharing among the vPorts and create dedicated EQs for each vPort. Move the EQ definition from struct mana_context to struct mana_port_context and update related support functions. Export mana_create_eq() and mana_destroy_eq() for use by the MANA RDMA driver. Signed-off-by: Long Li --- Changes in v3: - Added NULL check for mpc->eqs in mana_ib_create_qp_rss() to prevent kernel crash when RSS QP is created before EQs are allocated --- drivers/infiniband/hw/mana/main.c | 14 ++- drivers/infiniband/hw/mana/qp.c | 16 ++- drivers/net/ethernet/microsoft/mana/mana_en.c | 109 ++++++++++-------- include/net/mana/mana.h | 7 +- 4 files changed, 94 insertions(+), 52 deletions(-) diff --git a/drivers/infiniband/hw/mana/main.c b/drivers/infiniband/hw/mana= /main.c index 8d99cd00f002..d51dd0ee85f4 100644 --- a/drivers/infiniband/hw/mana/main.c +++ b/drivers/infiniband/hw/mana/main.c @@ -20,8 +20,10 @@ void mana_ib_uncfg_vport(struct mana_ib_dev *dev, struct= mana_ib_pd *pd, pd->vport_use_count--; WARN_ON(pd->vport_use_count < 0); =20 - if (!pd->vport_use_count) + if (!pd->vport_use_count) { + mana_destroy_eq(mpc); mana_uncfg_vport(mpc); + } =20 mutex_unlock(&pd->vport_mutex); } @@ -55,15 +57,21 @@ int mana_ib_cfg_vport(struct mana_ib_dev *dev, u32 port= , struct mana_ib_pd *pd, return err; } =20 - mutex_unlock(&pd->vport_mutex); =20 pd->tx_shortform_allowed =3D mpc->tx_shortform_allowed; pd->tx_vp_offset =3D mpc->tx_vp_offset; + err =3D mana_create_eq(mpc); + if (err) { + mana_uncfg_vport(mpc); + pd->vport_use_count--; + } + + mutex_unlock(&pd->vport_mutex); =20 ibdev_dbg(&dev->ib_dev, "vport handle %llx pdid %x doorbell_id %x\n", mpc->port_handle, pd->pdn, doorbell_id); =20 - return 0; + return err; } =20 int mana_ib_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata) diff --git a/drivers/infiniband/hw/mana/qp.c b/drivers/infiniband/hw/mana/q= p.c index 82f84f7ad37a..80cf4ade4b75 100644 --- a/drivers/infiniband/hw/mana/qp.c +++ b/drivers/infiniband/hw/mana/qp.c @@ -188,7 +188,15 @@ static int mana_ib_create_qp_rss(struct ib_qp *ibqp, s= truct ib_pd *pd, cq_spec.gdma_region =3D cq->queue.gdma_region; cq_spec.queue_size =3D cq->cqe * COMP_ENTRY_SIZE; cq_spec.modr_ctx_id =3D 0; - eq =3D &mpc->ac->eqs[cq->comp_vector]; + /* EQs are created when a raw QP configures the vport. + * A raw QP must be created before creating rwq_ind_tbl. + */ + if (!mpc->eqs) { + ret =3D -EINVAL; + i--; + goto fail; + } + eq =3D &mpc->eqs[cq->comp_vector % mpc->num_queues]; cq_spec.attached_eq =3D eq->eq->id; =20 ret =3D mana_create_wq_obj(mpc, mpc->port_handle, GDMA_RQ, @@ -340,7 +348,11 @@ static int mana_ib_create_qp_raw(struct ib_qp *ibqp, s= truct ib_pd *ibpd, cq_spec.queue_size =3D send_cq->cqe * COMP_ENTRY_SIZE; cq_spec.modr_ctx_id =3D 0; eq_vec =3D send_cq->comp_vector; - eq =3D &mpc->ac->eqs[eq_vec]; + if (!mpc->eqs) { + err =3D -EINVAL; + goto err_destroy_queue; + } + eq =3D &mpc->eqs[eq_vec % mpc->num_queues]; cq_spec.attached_eq =3D eq->eq->id; =20 err =3D mana_create_wq_obj(mpc, mpc->port_handle, GDMA_SQ, &wq_spec, diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/et= hernet/microsoft/mana/mana_en.c index 7cae8a7b9f31..32f924d2a99b 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_en.c +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c @@ -1596,78 +1596,82 @@ void mana_destroy_wq_obj(struct mana_port_context *= apc, u32 wq_type, } EXPORT_SYMBOL_NS(mana_destroy_wq_obj, "NET_MANA"); =20 -static void mana_destroy_eq(struct mana_context *ac) +void mana_destroy_eq(struct mana_port_context *apc) { + struct mana_context *ac =3D apc->ac; struct gdma_context *gc =3D ac->gdma_dev->gdma_context; struct gdma_queue *eq; int i; =20 - if (!ac->eqs) + if (!apc->eqs) return; =20 - debugfs_remove_recursive(ac->mana_eqs_debugfs); - ac->mana_eqs_debugfs =3D NULL; + debugfs_remove_recursive(apc->mana_eqs_debugfs); + apc->mana_eqs_debugfs =3D NULL; =20 - for (i =3D 0; i < gc->max_num_queues; i++) { - eq =3D ac->eqs[i].eq; + for (i =3D 0; i < apc->num_queues; i++) { + eq =3D apc->eqs[i].eq; if (!eq) continue; =20 mana_gd_destroy_queue(gc, eq); } =20 - kfree(ac->eqs); - ac->eqs =3D NULL; + kfree(apc->eqs); + apc->eqs =3D NULL; } +EXPORT_SYMBOL_NS(mana_destroy_eq, "NET_MANA"); =20 -static void mana_create_eq_debugfs(struct mana_context *ac, int i) +static void mana_create_eq_debugfs(struct mana_port_context *apc, int i) { - struct mana_eq eq =3D ac->eqs[i]; + struct mana_eq eq =3D apc->eqs[i]; char eqnum[32]; =20 sprintf(eqnum, "eq%d", i); - eq.mana_eq_debugfs =3D debugfs_create_dir(eqnum, ac->mana_eqs_debugfs); + eq.mana_eq_debugfs =3D debugfs_create_dir(eqnum, apc->mana_eqs_debugfs); debugfs_create_u32("head", 0400, eq.mana_eq_debugfs, &eq.eq->head); debugfs_create_u32("tail", 0400, eq.mana_eq_debugfs, &eq.eq->tail); debugfs_create_file("eq_dump", 0400, eq.mana_eq_debugfs, eq.eq, &mana_dbg= _q_fops); } =20 -static int mana_create_eq(struct mana_context *ac) +int mana_create_eq(struct mana_port_context *apc) { - struct gdma_dev *gd =3D ac->gdma_dev; + struct gdma_dev *gd =3D apc->ac->gdma_dev; struct gdma_context *gc =3D gd->gdma_context; struct gdma_queue_spec spec =3D {}; int err; int i; =20 - ac->eqs =3D kzalloc_objs(struct mana_eq, gc->max_num_queues); - if (!ac->eqs) + WARN_ON(apc->eqs); + apc->eqs =3D kzalloc_objs(struct mana_eq, apc->num_queues); + if (!apc->eqs) return -ENOMEM; =20 spec.type =3D GDMA_EQ; spec.monitor_avl_buf =3D false; spec.queue_size =3D EQ_SIZE; spec.eq.callback =3D NULL; - spec.eq.context =3D ac->eqs; + spec.eq.context =3D apc->eqs; spec.eq.log2_throttle_limit =3D LOG2_EQ_THROTTLE; =20 - ac->mana_eqs_debugfs =3D debugfs_create_dir("EQs", gc->mana_pci_debugfs); + apc->mana_eqs_debugfs =3D debugfs_create_dir("EQs", apc->mana_port_debugf= s); =20 - for (i =3D 0; i < gc->max_num_queues; i++) { + for (i =3D 0; i < apc->num_queues; i++) { spec.eq.msix_index =3D (i + 1) % gc->num_msix_usable; - err =3D mana_gd_create_mana_eq(gd, &spec, &ac->eqs[i].eq); + err =3D mana_gd_create_mana_eq(gd, &spec, &apc->eqs[i].eq); if (err) { dev_err(gc->dev, "Failed to create EQ %d : %d\n", i, err); goto out; } - mana_create_eq_debugfs(ac, i); + mana_create_eq_debugfs(apc, i); } =20 return 0; out: - mana_destroy_eq(ac); + mana_destroy_eq(apc); return err; } +EXPORT_SYMBOL_NS(mana_create_eq, "NET_MANA"); =20 static int mana_fence_rq(struct mana_port_context *apc, struct mana_rxq *r= xq) { @@ -2421,7 +2425,7 @@ static int mana_create_txq(struct mana_port_context *= apc, spec.monitor_avl_buf =3D false; spec.queue_size =3D cq_size; spec.cq.callback =3D mana_schedule_napi; - spec.cq.parent_eq =3D ac->eqs[i].eq; + spec.cq.parent_eq =3D apc->eqs[i].eq; spec.cq.context =3D cq; err =3D mana_gd_create_mana_wq_cq(gd, &spec, &cq->gdma_cq); if (err) @@ -2814,13 +2818,12 @@ static void mana_create_rxq_debugfs(struct mana_por= t_context *apc, int idx) static int mana_add_rx_queues(struct mana_port_context *apc, struct net_device *ndev) { - struct mana_context *ac =3D apc->ac; struct mana_rxq *rxq; int err =3D 0; int i; =20 for (i =3D 0; i < apc->num_queues; i++) { - rxq =3D mana_create_rxq(apc, i, &ac->eqs[i], ndev); + rxq =3D mana_create_rxq(apc, i, &apc->eqs[i], ndev); if (!rxq) { err =3D -ENOMEM; netdev_err(ndev, "Failed to create rxq %d : %d\n", i, err); @@ -2839,9 +2842,8 @@ static int mana_add_rx_queues(struct mana_port_contex= t *apc, return err; } =20 -static void mana_destroy_vport(struct mana_port_context *apc) +static void mana_destroy_rxqs(struct mana_port_context *apc) { - struct gdma_dev *gd =3D apc->ac->gdma_dev; struct mana_rxq *rxq; u32 rxq_idx; =20 @@ -2853,8 +2855,12 @@ static void mana_destroy_vport(struct mana_port_cont= ext *apc) mana_destroy_rxq(apc, rxq, true); apc->rxqs[rxq_idx] =3D NULL; } +} + +static void mana_destroy_vport(struct mana_port_context *apc) +{ + struct gdma_dev *gd =3D apc->ac->gdma_dev; =20 - mana_destroy_txq(apc); mana_uncfg_vport(apc); =20 if (gd->gdma_context->is_pf && !apc->ac->bm_hostmode) @@ -2875,11 +2881,7 @@ static int mana_create_vport(struct mana_port_contex= t *apc, return err; } =20 - err =3D mana_cfg_vport(apc, gd->pdid, gd->doorbell); - if (err) - return err; - - return mana_create_txq(apc, net); + return mana_cfg_vport(apc, gd->pdid, gd->doorbell); } =20 static int mana_rss_table_alloc(struct mana_port_context *apc) @@ -3156,21 +3158,36 @@ int mana_alloc_queues(struct net_device *ndev) =20 err =3D mana_create_vport(apc, ndev); if (err) { - netdev_err(ndev, "Failed to create vPort %u : %d\n", apc->port_idx, err); + netdev_err(ndev, "Failed to create vPort %u : %d\n", + apc->port_idx, err); return err; } =20 + err =3D mana_create_eq(apc); + if (err) { + netdev_err(ndev, "Failed to create EQ on vPort %u: %d\n", + apc->port_idx, err); + goto destroy_vport; + } + + err =3D mana_create_txq(apc, ndev); + if (err) { + netdev_err(ndev, "Failed to create TXQ on vPort %u: %d\n", + apc->port_idx, err); + goto destroy_eq; + } + err =3D netif_set_real_num_tx_queues(ndev, apc->num_queues); if (err) { netdev_err(ndev, "netif_set_real_num_tx_queues () failed for ndev with num_queues %u = : %d\n", apc->num_queues, err); - goto destroy_vport; + goto destroy_txq; } =20 err =3D mana_add_rx_queues(apc, ndev); if (err) - goto destroy_vport; + goto destroy_rxq; =20 apc->rss_state =3D apc->num_queues > 1 ? TRI_STATE_TRUE : TRI_STATE_FALSE; =20 @@ -3179,7 +3196,7 @@ int mana_alloc_queues(struct net_device *ndev) netdev_err(ndev, "netif_set_real_num_rx_queues () failed for ndev with num_queues %u = : %d\n", apc->num_queues, err); - goto destroy_vport; + goto destroy_rxq; } =20 mana_rss_table_init(apc); @@ -3187,19 +3204,25 @@ int mana_alloc_queues(struct net_device *ndev) err =3D mana_config_rss(apc, TRI_STATE_TRUE, true, true); if (err) { netdev_err(ndev, "Failed to configure RSS table: %d\n", err); - goto destroy_vport; + goto destroy_rxq; } =20 if (gd->gdma_context->is_pf && !apc->ac->bm_hostmode) { err =3D mana_pf_register_filter(apc); if (err) - goto destroy_vport; + goto destroy_rxq; } =20 mana_chn_setxdp(apc, mana_xdp_get(apc)); =20 return 0; =20 +destroy_rxq: + mana_destroy_rxqs(apc); +destroy_txq: + mana_destroy_txq(apc); +destroy_eq: + mana_destroy_eq(apc); destroy_vport: mana_destroy_vport(apc); return err; @@ -3302,6 +3325,9 @@ static int mana_dealloc_queues(struct net_device *nde= v) netdev_err(ndev, "Failed to disable vPort: %d\n", err); =20 /* Even in err case, still need to cleanup the vPort */ + mana_destroy_rxqs(apc); + mana_destroy_txq(apc); + mana_destroy_eq(apc); mana_destroy_vport(apc); =20 return 0; @@ -3617,12 +3643,6 @@ int mana_probe(struct gdma_dev *gd, bool resuming) gd->driver_data =3D ac; } =20 - err =3D mana_create_eq(ac); - if (err) { - dev_err(dev, "Failed to create EQs: %d\n", err); - goto out; - } - err =3D mana_query_device_cfg(ac, MANA_MAJOR_VERSION, MANA_MINOR_VERSION, MANA_MICRO_VERSION, &num_ports, &bm_hostmode); if (err) @@ -3761,7 +3781,6 @@ void mana_remove(struct gdma_dev *gd, bool suspending) free_netdev(ndev); } =20 - mana_destroy_eq(ac); out: if (ac->per_port_queue_reset_wq) { destroy_workqueue(ac->per_port_queue_reset_wq); diff --git a/include/net/mana/mana.h b/include/net/mana/mana.h index 96d21cbbdee2..204c2b612a62 100644 --- a/include/net/mana/mana.h +++ b/include/net/mana/mana.h @@ -480,8 +480,6 @@ struct mana_context { u8 bm_hostmode; =20 struct mana_ethtool_hc_stats hc_stats; - struct mana_eq *eqs; - struct dentry *mana_eqs_debugfs; struct workqueue_struct *per_port_queue_reset_wq; /* Workqueue for querying hardware stats */ struct delayed_work gf_stats_work; @@ -501,6 +499,9 @@ struct mana_port_context { =20 u8 mac_addr[ETH_ALEN]; =20 + struct mana_eq *eqs; + struct dentry *mana_eqs_debugfs; + enum TRI_STATE rss_state; =20 mana_handle_t default_rxobj; @@ -1033,6 +1034,8 @@ void mana_destroy_wq_obj(struct mana_port_context *ap= c, u32 wq_type, int mana_cfg_vport(struct mana_port_context *apc, u32 protection_dom_id, u32 doorbell_pg_id); void mana_uncfg_vport(struct mana_port_context *apc); +int mana_create_eq(struct mana_port_context *apc); +void mana_destroy_eq(struct mana_port_context *apc); =20 struct net_device *mana_get_primary_netdev(struct mana_context *ac, u32 port_index, --=20 2.43.0 From nobody Sat Apr 4 01:45:59 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3ED303A7F72; Fri, 20 Mar 2026 23:54:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774050876; cv=none; b=sRSs4xiApVtm+510viZ0S68GDwvMED+FTvE8paCxWi/nu0ZNPiDwg7lPJmaLc0wiq/HwFigbcTrxr36OGDKzKKXApXaWUzjlbkT9UKH5XwsQ8/STl/dEeIdo60Ro5RNddxKV516hsd+j8VflIRpinyCG0XrkWPGDV8KWIbvJhmQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774050876; c=relaxed/simple; bh=lmfHT09RF3SpS5yieKdXKXAbO1QBMotlrB/8Dx0epFo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rw+7MwHXIOfvgNUmrh5bTVN7oXeXEqOHwpADxYSu6TfrnEdseIGWboc9ZnHybjSQZ5Qxc4YjnhanzglsHcYNigZxLtGJJgYXv5GN3cRMJm0Ai5Vi837X+BLvUmQiQKRbw/3bvVpUPErp6D4r+bGJDJ2vIWmKT5TuqUMdg/AFQX0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: by linux.microsoft.com (Postfix, from userid 1202) id 33B0120B6F1F; Fri, 20 Mar 2026 16:54:35 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 33B0120B6F1F From: Long Li To: Long Li , Konstantin Taranov , Jakub Kicinski , "David S . Miller" , Paolo Abeni , Eric Dumazet , Andrew Lunn , Jason Gunthorpe , Leon Romanovsky , Haiyang Zhang , "K . Y . Srinivasan" , Wei Liu , Dexuan Cui Cc: Simon Horman , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 2/6] net: mana: Query device capabilities and configure MSI-X sharing for EQs Date: Fri, 20 Mar 2026 16:54:15 -0700 Message-ID: X-Mailer: git-send-email 2.43.7 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When querying the device, adjust the max number of queues to allow dedicated MSI-X vectors for each vPort. The number of queues per vPort is clamped to no less than MANA_DEF_NUM_QUEUES. MSI-X sharing among vPorts is disabled by default and is only enabled when there are not enough MSI-X vectors for dedicated allocation. Rename mana_query_device_cfg() to mana_gd_query_device_cfg() as it is used at GDMA device probe time for querying device capabilities. Signed-off-by: Long Li --- Changes in v4: - Use MANA_DEF_NUM_QUEUES instead of hardcoded 16 for max_num_queues clamping Changes in v2: - Fixed misleading comment for max_num_queues vs max_num_queues_vport in gdma.h --- .../net/ethernet/microsoft/mana/gdma_main.c | 66 ++++++++++++++++--- drivers/net/ethernet/microsoft/mana/mana_en.c | 36 +++++----- include/net/mana/gdma.h | 13 +++- 3 files changed, 91 insertions(+), 24 deletions(-) diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/= ethernet/microsoft/mana/gdma_main.c index 2ba1fa3336f9..ae18b4054a02 100644 --- a/drivers/net/ethernet/microsoft/mana/gdma_main.c +++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c @@ -124,6 +124,9 @@ static int mana_gd_query_max_resources(struct pci_dev *= pdev) struct gdma_context *gc =3D pci_get_drvdata(pdev); struct gdma_query_max_resources_resp resp =3D {}; struct gdma_general_req req =3D {}; + unsigned int max_num_queues; + u8 bm_hostmode; + u16 num_ports; int err; =20 mana_gd_init_req_hdr(&req.hdr, GDMA_QUERY_MAX_RESOURCES, @@ -169,6 +172,40 @@ static int mana_gd_query_max_resources(struct pci_dev = *pdev) if (gc->max_num_queues > gc->num_msix_usable - 1) gc->max_num_queues =3D gc->num_msix_usable - 1; =20 + err =3D mana_gd_query_device_cfg(gc, MANA_MAJOR_VERSION, MANA_MINOR_VERSI= ON, + MANA_MICRO_VERSION, &num_ports, &bm_hostmode); + if (err) + return err; + + if (!num_ports) + return -EINVAL; + + /* + * Adjust gc->max_num_queues returned from the SOC to allow dedicated + * MSIx for each vPort. Clamp to no less than MANA_DEF_NUM_QUEUES. + */ + max_num_queues =3D (gc->num_msix_usable - 1) / num_ports; + max_num_queues =3D roundup_pow_of_two(max(max_num_queues, 1U)); + if (max_num_queues < MANA_DEF_NUM_QUEUES) + max_num_queues =3D MANA_DEF_NUM_QUEUES; + + /* + * Use dedicated MSIx for EQs whenever possible, use MSIx sharing for + * Ethernet EQs when (max_num_queues * num_ports > num_msix_usable - 1) + */ + max_num_queues =3D min(gc->max_num_queues, max_num_queues); + if (max_num_queues * num_ports > gc->num_msix_usable - 1) + gc->msi_sharing =3D true; + + /* If MSI is shared, use max allowed value */ + if (gc->msi_sharing) + gc->max_num_queues_vport =3D min(gc->num_msix_usable - 1, gc->max_num_qu= eues); + else + gc->max_num_queues_vport =3D max_num_queues; + + dev_info(gc->dev, "MSI sharing mode %d max queues %d\n", + gc->msi_sharing, gc->max_num_queues); + return 0; } =20 @@ -1831,6 +1868,7 @@ static int mana_gd_setup_hwc_irqs(struct pci_dev *pde= v) /* Need 1 interrupt for HWC */ max_irqs =3D min(num_online_cpus(), MANA_MAX_NUM_QUEUES) + 1; min_irqs =3D 2; + gc->msi_sharing =3D true; } =20 nvec =3D pci_alloc_irq_vectors(pdev, min_irqs, max_irqs, PCI_IRQ_MSIX); @@ -1909,6 +1947,8 @@ static void mana_gd_remove_irqs(struct pci_dev *pdev) =20 pci_free_irq_vectors(pdev); =20 + bitmap_free(gc->msi_bitmap); + gc->msi_bitmap =3D NULL; gc->max_num_msix =3D 0; gc->num_msix_usable =3D 0; } @@ -1943,20 +1983,30 @@ static int mana_gd_setup(struct pci_dev *pdev) if (err) goto destroy_hwc; =20 - err =3D mana_gd_query_max_resources(pdev); + err =3D mana_gd_detect_devices(pdev); if (err) goto destroy_hwc; =20 - err =3D mana_gd_setup_remaining_irqs(pdev); - if (err) { - dev_err(gc->dev, "Failed to setup remaining IRQs: %d", err); - goto destroy_hwc; - } - - err =3D mana_gd_detect_devices(pdev); + err =3D mana_gd_query_max_resources(pdev); if (err) goto destroy_hwc; =20 + if (!gc->msi_sharing) { + gc->msi_bitmap =3D bitmap_zalloc(gc->num_msix_usable, GFP_KERNEL); + if (!gc->msi_bitmap) { + err =3D -ENOMEM; + goto destroy_hwc; + } + /* Set bit for HWC */ + set_bit(0, gc->msi_bitmap); + } else { + err =3D mana_gd_setup_remaining_irqs(pdev); + if (err) { + dev_err(gc->dev, "Failed to setup remaining IRQs: %d", err); + goto destroy_hwc; + } + } + dev_dbg(&pdev->dev, "mana gdma setup successful\n"); return 0; =20 diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/et= hernet/microsoft/mana/mana_en.c index 32f924d2a99b..87a444a6c297 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_en.c +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c @@ -1000,10 +1000,9 @@ static int mana_init_port_context(struct mana_port_c= ontext *apc) return !apc->rxqs ? -ENOMEM : 0; } =20 -static int mana_send_request(struct mana_context *ac, void *in_buf, - u32 in_len, void *out_buf, u32 out_len) +static int gdma_mana_send_request(struct gdma_context *gc, void *in_buf, + u32 in_len, void *out_buf, u32 out_len) { - struct gdma_context *gc =3D ac->gdma_dev->gdma_context; struct gdma_resp_hdr *resp =3D out_buf; struct gdma_req_hdr *req =3D in_buf; struct device *dev =3D gc->dev; @@ -1037,6 +1036,14 @@ static int mana_send_request(struct mana_context *ac= , void *in_buf, return 0; } =20 +static int mana_send_request(struct mana_context *ac, void *in_buf, + u32 in_len, void *out_buf, u32 out_len) +{ + struct gdma_context *gc =3D ac->gdma_dev->gdma_context; + + return gdma_mana_send_request(gc, in_buf, in_len, out_buf, out_len); +} + static int mana_verify_resp_hdr(const struct gdma_resp_hdr *resp_hdr, const enum mana_command_code expected_code, const u32 min_size) @@ -1170,11 +1177,10 @@ static void mana_pf_deregister_filter(struct mana_p= ort_context *apc) err, resp.hdr.status); } =20 -static int mana_query_device_cfg(struct mana_context *ac, u32 proto_major_= ver, - u32 proto_minor_ver, u32 proto_micro_ver, - u16 *max_num_vports, u8 *bm_hostmode) +int mana_gd_query_device_cfg(struct gdma_context *gc, u32 proto_major_ver, + u32 proto_minor_ver, u32 proto_micro_ver, + u16 *max_num_vports, u8 *bm_hostmode) { - struct gdma_context *gc =3D ac->gdma_dev->gdma_context; struct mana_query_device_cfg_resp resp =3D {}; struct mana_query_device_cfg_req req =3D {}; struct device *dev =3D gc->dev; @@ -1189,7 +1195,7 @@ static int mana_query_device_cfg(struct mana_context = *ac, u32 proto_major_ver, req.proto_minor_ver =3D proto_minor_ver; req.proto_micro_ver =3D proto_micro_ver; =20 - err =3D mana_send_request(ac, &req, sizeof(req), &resp, sizeof(resp)); + err =3D gdma_mana_send_request(gc, &req, sizeof(req), &resp, sizeof(resp)= ); if (err) { dev_err(dev, "Failed to query config: %d", err); return err; @@ -1217,8 +1223,6 @@ static int mana_query_device_cfg(struct mana_context = *ac, u32 proto_major_ver, else *bm_hostmode =3D 0; =20 - debugfs_create_u16("adapter-MTU", 0400, gc->mana_pci_debugfs, &gc->adapte= r_mtu); - return 0; } =20 @@ -3373,7 +3377,7 @@ static int mana_probe_port(struct mana_context *ac, i= nt port_idx, int err; =20 ndev =3D alloc_etherdev_mq(sizeof(struct mana_port_context), - gc->max_num_queues); + gc->max_num_queues_vport); if (!ndev) return -ENOMEM; =20 @@ -3382,8 +3386,8 @@ static int mana_probe_port(struct mana_context *ac, i= nt port_idx, apc =3D netdev_priv(ndev); apc->ac =3D ac; apc->ndev =3D ndev; - apc->max_queues =3D gc->max_num_queues; - apc->num_queues =3D min(gc->max_num_queues, MANA_DEF_NUM_QUEUES); + apc->max_queues =3D gc->max_num_queues_vport; + apc->num_queues =3D min(gc->max_num_queues_vport, MANA_DEF_NUM_QUEUES); apc->tx_queue_size =3D DEF_TX_BUFFERS_PER_QUEUE; apc->rx_queue_size =3D DEF_RX_BUFFERS_PER_QUEUE; apc->port_handle =3D INVALID_MANA_HANDLE; @@ -3643,13 +3647,15 @@ int mana_probe(struct gdma_dev *gd, bool resuming) gd->driver_data =3D ac; } =20 - err =3D mana_query_device_cfg(ac, MANA_MAJOR_VERSION, MANA_MINOR_VERSION, - MANA_MICRO_VERSION, &num_ports, &bm_hostmode); + err =3D mana_gd_query_device_cfg(gc, MANA_MAJOR_VERSION, MANA_MINOR_VERSI= ON, + MANA_MICRO_VERSION, &num_ports, &bm_hostmode); if (err) goto out; =20 ac->bm_hostmode =3D bm_hostmode; =20 + debugfs_create_u16("adapter-MTU", 0400, gc->mana_pci_debugfs, &gc->adapte= r_mtu); + if (!resuming) { ac->num_ports =3D num_ports; =20 diff --git a/include/net/mana/gdma.h b/include/net/mana/gdma.h index 7fe3a1b61b2d..ecd9949df213 100644 --- a/include/net/mana/gdma.h +++ b/include/net/mana/gdma.h @@ -399,8 +399,10 @@ struct gdma_context { struct device *dev; struct dentry *mana_pci_debugfs; =20 - /* Per-vPort max number of queues */ + /* Hardware max number of queues */ unsigned int max_num_queues; + /* Per-vPort max number of queues */ + unsigned int max_num_queues_vport; unsigned int max_num_msix; unsigned int num_msix_usable; struct xarray irq_contexts; @@ -446,6 +448,12 @@ struct gdma_context { struct workqueue_struct *service_wq; =20 unsigned long flags; + + /* Indicate if this device is sharing MSI for EQs on MANA */ + bool msi_sharing; + + /* Bitmap tracks where MSI is allocated when it is not shared for EQs */ + unsigned long *msi_bitmap; }; =20 static inline bool mana_gd_is_mana(struct gdma_dev *gd) @@ -1013,4 +1021,7 @@ int mana_gd_resume(struct pci_dev *pdev); =20 bool mana_need_log(struct gdma_context *gc, int err); =20 +int mana_gd_query_device_cfg(struct gdma_context *gc, u32 proto_major_ver, + u32 proto_minor_ver, u32 proto_micro_ver, + u16 *max_num_vports, u8 *bm_hostmode); #endif /* _GDMA_H */ --=20 2.43.0 From nobody Sat Apr 4 01:45:59 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D7B043A75B8; Fri, 20 Mar 2026 23:54:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774050877; cv=none; b=qhk2OdVgPWYZxfH21Av5+efcq3wq0C2Iuzfs9kdh2y+DSLtTDcmewbLNZmxA5wheBrl9Js8NYoXIm7KutdcyYTkwUALcaGQN8IseXugMu63XF/Lj0AkkokCDSjO362DIp7TPlRx0ej89iG58zE1wxNZi6DegY+crIMmQ/0mXeOU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774050877; c=relaxed/simple; bh=fGuhJliU3H8NVEQTBCReaCUxzihzwHty7vesFp+ZJ8c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jq+8wiuRR0N61rlZQX4Yqlj4VeGC8al/OtsbkzKbOE42ySj6hEJXMnQx3zHrkLyxZYG28P2UGMa63sAcNSXekbsaypgYXwYe8kzo2m3Zg5Mgqq7osyIEN0aU+9hicXoiYbUxJqMKDdeVNUzG9ilGT9k3c0DvCnvE3tH9lzx5jyc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: by linux.microsoft.com (Postfix, from userid 1202) id E556520B6F15; Fri, 20 Mar 2026 16:54:35 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com E556520B6F15 From: Long Li To: Long Li , Konstantin Taranov , Jakub Kicinski , "David S . Miller" , Paolo Abeni , Eric Dumazet , Andrew Lunn , Jason Gunthorpe , Leon Romanovsky , Haiyang Zhang , "K . Y . Srinivasan" , Wei Liu , Dexuan Cui Cc: Simon Horman , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 3/6] net: mana: Introduce GIC context with refcounting for interrupt management Date: Fri, 20 Mar 2026 16:54:16 -0700 Message-ID: <5037d2c1d353a3d95a3ad2860ec7c0c7a6a2c550.1774049761.git.longli@microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To allow Ethernet EQs to use dedicated or shared MSI-X vectors and RDMA EQs to share the same MSI-X, introduce a GIC (GDMA IRQ Context) with reference counting. This allows the driver to create an interrupt context on an assigned or unassigned MSI-X vector and share it across multiple EQ consumers. Signed-off-by: Long Li --- Changes in v4: - Track dyn_msix in GIC context instead of re-checking pci_msix_can_alloc_dyn() on each call - Improved remove_irqs iteration to skip unallocated entries Changes in v2: - Fixed spelling typo in gdma_main.c ("difference" -> "different") --- .../net/ethernet/microsoft/mana/gdma_main.c | 159 ++++++++++++++++++ include/net/mana/gdma.h | 11 ++ 2 files changed, 170 insertions(+) diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/= ethernet/microsoft/mana/gdma_main.c index ae18b4054a02..69a4427919f5 100644 --- a/drivers/net/ethernet/microsoft/mana/gdma_main.c +++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c @@ -1587,6 +1587,164 @@ static irqreturn_t mana_gd_intr(int irq, void *arg) return IRQ_HANDLED; } =20 +void mana_gd_put_gic(struct gdma_context *gc, bool use_msi_bitmap, int msi) +{ + struct pci_dev *dev =3D to_pci_dev(gc->dev); + struct msi_map irq_map; + struct gdma_irq_context *gic; + int irq; + + mutex_lock(&gc->gic_mutex); + + gic =3D xa_load(&gc->irq_contexts, msi); + if (WARN_ON(!gic)) { + mutex_unlock(&gc->gic_mutex); + return; + } + + if (use_msi_bitmap) + gic->bitmap_refs--; + + if (use_msi_bitmap && gic->bitmap_refs =3D=3D 0) + clear_bit(msi, gc->msi_bitmap); + + if (!refcount_dec_and_test(&gic->refcount)) + goto out; + + irq =3D pci_irq_vector(dev, msi); + + irq_update_affinity_hint(irq, NULL); + free_irq(irq, gic); + + if (gic->dyn_msix) { + irq_map.virq =3D irq; + irq_map.index =3D msi; + pci_msix_free_irq(dev, irq_map); + } + + xa_erase(&gc->irq_contexts, msi); + kfree(gic); + +out: + mutex_unlock(&gc->gic_mutex); +} +EXPORT_SYMBOL_NS(mana_gd_put_gic, "NET_MANA"); + +/* + * Get a GIC (GDMA IRQ Context) on a MSI vector + * a MSI can be shared between different EQs, this function supports setti= ng + * up separate MSIs using a bitmap, or directly using the MSI index + * + * @use_msi_bitmap: + * True if MSI is assigned by this function on available slots from bitmap. + * False if MSI is passed from *msi_requested + */ +struct gdma_irq_context *mana_gd_get_gic(struct gdma_context *gc, + bool use_msi_bitmap, + int *msi_requested) +{ + struct gdma_irq_context *gic; + struct pci_dev *dev =3D to_pci_dev(gc->dev); + struct msi_map irq_map =3D { }; + int irq; + int msi; + int err; + + mutex_lock(&gc->gic_mutex); + + if (use_msi_bitmap) { + msi =3D find_first_zero_bit(gc->msi_bitmap, gc->num_msix_usable); + if (msi >=3D gc->num_msix_usable) { + dev_err(gc->dev, "No free MSI vectors available\n"); + gic =3D NULL; + goto out; + } + *msi_requested =3D msi; + } else { + msi =3D *msi_requested; + } + + gic =3D xa_load(&gc->irq_contexts, msi); + if (gic) { + refcount_inc(&gic->refcount); + if (use_msi_bitmap) { + gic->bitmap_refs++; + set_bit(msi, gc->msi_bitmap); + } + goto out; + } + + irq =3D pci_irq_vector(dev, msi); + if (irq =3D=3D -EINVAL) { + irq_map =3D pci_msix_alloc_irq_at(dev, msi, NULL); + if (!irq_map.virq) { + err =3D irq_map.index; + dev_err(gc->dev, + "Failed to alloc irq_map msi %d err %d\n", + msi, err); + gic =3D NULL; + goto out; + } + irq =3D irq_map.virq; + msi =3D irq_map.index; + } + + gic =3D kzalloc(sizeof(*gic), GFP_KERNEL); + if (!gic) { + if (irq_map.virq) + pci_msix_free_irq(dev, irq_map); + goto out; + } + + gic->handler =3D mana_gd_process_eq_events; + gic->msi =3D msi; + gic->irq =3D irq; + INIT_LIST_HEAD(&gic->eq_list); + spin_lock_init(&gic->lock); + + if (!gic->msi) + snprintf(gic->name, MANA_IRQ_NAME_SZ, "mana_hwc@pci:%s", + pci_name(dev)); + else + snprintf(gic->name, MANA_IRQ_NAME_SZ, "mana_msi%d@pci:%s", + gic->msi, pci_name(dev)); + + err =3D request_irq(irq, mana_gd_intr, 0, gic->name, gic); + if (err) { + dev_err(gc->dev, "Failed to request irq %d %s\n", + irq, gic->name); + kfree(gic); + gic =3D NULL; + if (irq_map.virq) + pci_msix_free_irq(dev, irq_map); + goto out; + } + + gic->dyn_msix =3D !!irq_map.virq; + refcount_set(&gic->refcount, 1); + gic->bitmap_refs =3D use_msi_bitmap ? 1 : 0; + + err =3D xa_err(xa_store(&gc->irq_contexts, msi, gic, GFP_KERNEL)); + if (err) { + dev_err(gc->dev, "Failed to store irq context for msi %d: %d\n", + msi, err); + free_irq(irq, gic); + kfree(gic); + gic =3D NULL; + if (irq_map.virq) + pci_msix_free_irq(dev, irq_map); + goto out; + } + + if (use_msi_bitmap) + set_bit(msi, gc->msi_bitmap); + +out: + mutex_unlock(&gc->gic_mutex); + return gic; +} +EXPORT_SYMBOL_NS(mana_gd_get_gic, "NET_MANA"); + int mana_gd_alloc_res_map(u32 res_avail, struct gdma_resource *r) { r->map =3D bitmap_zalloc(res_avail, GFP_KERNEL); @@ -2076,6 +2234,7 @@ static int mana_gd_probe(struct pci_dev *pdev, const = struct pci_device_id *ent) goto release_region; =20 mutex_init(&gc->eq_test_event_mutex); + mutex_init(&gc->gic_mutex); pci_set_drvdata(pdev, gc); gc->bar0_pa =3D pci_resource_start(pdev, 0); gc->bar0_size =3D pci_resource_len(pdev, 0); diff --git a/include/net/mana/gdma.h b/include/net/mana/gdma.h index ecd9949df213..4614a6a7271b 100644 --- a/include/net/mana/gdma.h +++ b/include/net/mana/gdma.h @@ -388,6 +388,11 @@ struct gdma_irq_context { spinlock_t lock; struct list_head eq_list; char name[MANA_IRQ_NAME_SZ]; + unsigned int msi; + unsigned int irq; + refcount_t refcount; + unsigned int bitmap_refs; + bool dyn_msix; }; =20 enum gdma_context_flags { @@ -449,6 +454,9 @@ struct gdma_context { =20 unsigned long flags; =20 + /* Protect access to GIC context */ + struct mutex gic_mutex; + /* Indicate if this device is sharing MSI for EQs on MANA */ bool msi_sharing; =20 @@ -1021,6 +1029,9 @@ int mana_gd_resume(struct pci_dev *pdev); =20 bool mana_need_log(struct gdma_context *gc, int err); =20 +struct gdma_irq_context *mana_gd_get_gic(struct gdma_context *gc, bool use= _msi_bitmap, + int *msi_requested); +void mana_gd_put_gic(struct gdma_context *gc, bool use_msi_bitmap, int msi= ); int mana_gd_query_device_cfg(struct gdma_context *gc, u32 proto_major_ver, u32 proto_minor_ver, u32 proto_micro_ver, u16 *max_num_vports, u8 *bm_hostmode); --=20 2.43.0 From nobody Sat Apr 4 01:45:59 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B21343D811B; Fri, 20 Mar 2026 23:54:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774050878; cv=none; b=l6uX6BpVi1WZ0tA5J+FW726ECcukx/SCoGGnTTVXmS1+2SwpdHk/rFI8CIoruOykxcHHwyUHGATJZ7o55V8iZKHOi6A7w/1MXeM1MWJ2oWTy8Ic7zW76wCqCOQ+YdXfbCiVubrcTVlUeCVpioXtoG4eVE23AWIi+YFD3KpvGeaE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774050878; c=relaxed/simple; bh=nt8OeVcboKxU0k35SmRxY1lNGHtGRZilRjjiqkf8xIE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=odfsb90QiSqa0Zof30O0lonS2Y1z56jsvXjV9bQRQBhOuMr5FFc4y055XNYXb7wHIJO88X7s/jwLbiB5poWxJ/3s1SkR61WIGiUzcZ5yUgaLqXEt4blyugTU/OF3S0j30sJlTVLd0hyYgk/WetWeB383U1ZDulVXE4scCCuwkrQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: by linux.microsoft.com (Postfix, from userid 1202) id A989020B6F1B; Fri, 20 Mar 2026 16:54:36 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com A989020B6F1B From: Long Li To: Long Li , Konstantin Taranov , Jakub Kicinski , "David S . Miller" , Paolo Abeni , Eric Dumazet , Andrew Lunn , Jason Gunthorpe , Leon Romanovsky , Haiyang Zhang , "K . Y . Srinivasan" , Wei Liu , Dexuan Cui Cc: Simon Horman , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 4/6] net: mana: Use GIC functions to allocate global EQs Date: Fri, 20 Mar 2026 16:54:17 -0700 Message-ID: <5844571ee73dd04570b8764cdbef86fdac3a7f95.1774049761.git.longli@microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace the GDMA global interrupt setup code with the new GIC allocation and release functions for managing interrupt contexts. Signed-off-by: Long Li --- .../net/ethernet/microsoft/mana/gdma_main.c | 80 +++---------------- 1 file changed, 10 insertions(+), 70 deletions(-) diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/= ethernet/microsoft/mana/gdma_main.c index 69a4427919f5..e7d5e589a217 100644 --- a/drivers/net/ethernet/microsoft/mana/gdma_main.c +++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c @@ -1860,30 +1860,13 @@ static int mana_gd_setup_dyn_irqs(struct pci_dev *p= dev, int nvec) * further used in irq_setup() */ for (i =3D 1; i <=3D nvec; i++) { - gic =3D kzalloc_obj(*gic); + gic =3D mana_gd_get_gic(gc, false, &i); if (!gic) { err =3D -ENOMEM; goto free_irq; } - gic->handler =3D mana_gd_process_eq_events; - INIT_LIST_HEAD(&gic->eq_list); - spin_lock_init(&gic->lock); - - snprintf(gic->name, MANA_IRQ_NAME_SZ, "mana_q%d@pci:%s", - i - 1, pci_name(pdev)); - - /* one pci vector is already allocated for HWC */ - irqs[i - 1] =3D pci_irq_vector(pdev, i); - if (irqs[i - 1] < 0) { - err =3D irqs[i - 1]; - goto free_current_gic; - } - - err =3D request_irq(irqs[i - 1], mana_gd_intr, 0, gic->name, gic); - if (err) - goto free_current_gic; =20 - xa_store(&gc->irq_contexts, i, gic, GFP_KERNEL); + irqs[i - 1] =3D gic->irq; } =20 /* @@ -1905,19 +1888,11 @@ static int mana_gd_setup_dyn_irqs(struct pci_dev *p= dev, int nvec) kfree(irqs); return 0; =20 -free_current_gic: - kfree(gic); free_irq: for (i -=3D 1; i > 0; i--) { irq =3D pci_irq_vector(pdev, i); - gic =3D xa_load(&gc->irq_contexts, i); - if (WARN_ON(!gic)) - continue; - irq_update_affinity_hint(irq, NULL); - free_irq(irq, gic); - xa_erase(&gc->irq_contexts, i); - kfree(gic); + mana_gd_put_gic(gc, false, i); } kfree(irqs); return err; @@ -1938,34 +1913,13 @@ static int mana_gd_setup_irqs(struct pci_dev *pdev,= int nvec) start_irqs =3D irqs; =20 for (i =3D 0; i < nvec; i++) { - gic =3D kzalloc_obj(*gic); + gic =3D mana_gd_get_gic(gc, false, &i); if (!gic) { err =3D -ENOMEM; goto free_irq; } =20 - gic->handler =3D mana_gd_process_eq_events; - INIT_LIST_HEAD(&gic->eq_list); - spin_lock_init(&gic->lock); - - if (!i) - snprintf(gic->name, MANA_IRQ_NAME_SZ, "mana_hwc@pci:%s", - pci_name(pdev)); - else - snprintf(gic->name, MANA_IRQ_NAME_SZ, "mana_q%d@pci:%s", - i - 1, pci_name(pdev)); - - irqs[i] =3D pci_irq_vector(pdev, i); - if (irqs[i] < 0) { - err =3D irqs[i]; - goto free_current_gic; - } - - err =3D request_irq(irqs[i], mana_gd_intr, 0, gic->name, gic); - if (err) - goto free_current_gic; - - xa_store(&gc->irq_contexts, i, gic, GFP_KERNEL); + irqs[i] =3D gic->irq; } =20 /* If number of IRQ is one extra than number of online CPUs, @@ -1994,19 +1948,11 @@ static int mana_gd_setup_irqs(struct pci_dev *pdev,= int nvec) kfree(start_irqs); return 0; =20 -free_current_gic: - kfree(gic); free_irq: for (i -=3D 1; i >=3D 0; i--) { irq =3D pci_irq_vector(pdev, i); - gic =3D xa_load(&gc->irq_contexts, i); - if (WARN_ON(!gic)) - continue; - irq_update_affinity_hint(irq, NULL); - free_irq(irq, gic); - xa_erase(&gc->irq_contexts, i); - kfree(gic); + mana_gd_put_gic(gc, false, i); } =20 kfree(start_irqs); @@ -2081,26 +2027,20 @@ static int mana_gd_setup_remaining_irqs(struct pci_= dev *pdev) static void mana_gd_remove_irqs(struct pci_dev *pdev) { struct gdma_context *gc =3D pci_get_drvdata(pdev); - struct gdma_irq_context *gic; int irq, i; =20 if (gc->max_num_msix < 1) return; =20 for (i =3D 0; i < gc->max_num_msix; i++) { - irq =3D pci_irq_vector(pdev, i); - if (irq < 0) - continue; - - gic =3D xa_load(&gc->irq_contexts, i); - if (WARN_ON(!gic)) + if (!xa_load(&gc->irq_contexts, i)) continue; =20 /* Need to clear the hint before free_irq */ + irq =3D pci_irq_vector(pdev, i); irq_update_affinity_hint(irq, NULL); - free_irq(irq, gic); - xa_erase(&gc->irq_contexts, i); - kfree(gic); + + mana_gd_put_gic(gc, false, i); } =20 pci_free_irq_vectors(pdev); --=20 2.43.0 From nobody Sat Apr 4 01:45:59 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A98183E3DA2; Fri, 20 Mar 2026 23:54:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774050880; cv=none; b=N3GooKY2IbtQdO5PkZjjDBbFlzPuQJlOYgzGNjq11vYsmBdCwrOZd7BwZpc+1fjt7o6jF3wDdUKA830x69oPt6jZ+AOIlfkmvgw2/NU9N8PZkVr5bnJsVHMTBYRfWnn407mrr8CsBiom/AGVRmyJdbpbfze8nX+8cGgaJPDzGsE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774050880; c=relaxed/simple; bh=RxYE/so7PkVMrNqNg4s1usnrGJ7/UNL8lShLCvr5o1Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GzmM2S7DlOD0FCpo+j3MhI1HNAsd0uSmB3MVOqKRXZEVuYqAVavRRLnbsi32WrUy3R+9dyNATr+1rDeY6u/LwlvYVpc6GZfbsrlzvaodpDufOWCQSRhktDqxxWQ9f11wrURPfbxVdX/mKpVe4HDOBeaTivEWAl5AUFDWs/1DRjg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: by linux.microsoft.com (Postfix, from userid 1202) id ACBF020B6F01; Fri, 20 Mar 2026 16:54:37 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com ACBF020B6F01 From: Long Li To: Long Li , Konstantin Taranov , Jakub Kicinski , "David S . Miller" , Paolo Abeni , Eric Dumazet , Andrew Lunn , Jason Gunthorpe , Leon Romanovsky , Haiyang Zhang , "K . Y . Srinivasan" , Wei Liu , Dexuan Cui Cc: Simon Horman , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 5/6] net: mana: Allocate interrupt context for each EQ when creating vPort Date: Fri, 20 Mar 2026 16:54:18 -0700 Message-ID: <11396c357c4ec2777da89951ca73ed239e265760.1774049761.git.longli@microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use GIC functions to create a dedicated interrupt context or acquire a shared interrupt context for each EQ when setting up a vPort. Signed-off-by: Long Li --- drivers/net/ethernet/microsoft/mana/gdma_main.c | 2 +- drivers/net/ethernet/microsoft/mana/mana_en.c | 17 ++++++++++++++++- include/net/mana/gdma.h | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/= ethernet/microsoft/mana/gdma_main.c index e7d5e589a217..34b19e0740e1 100644 --- a/drivers/net/ethernet/microsoft/mana/gdma_main.c +++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c @@ -826,7 +826,6 @@ static void mana_gd_deregister_irq(struct gdma_queue *q= ueue) } spin_unlock_irqrestore(&gic->lock, flags); =20 - queue->eq.msix_index =3D INVALID_PCI_MSIX_INDEX; synchronize_rcu(); } =20 @@ -941,6 +940,7 @@ static int mana_gd_create_eq(struct gdma_dev *gd, out: dev_err(dev, "Failed to create EQ: %d\n", err); mana_gd_destroy_eq(gc, false, queue); + queue->eq.msix_index =3D INVALID_PCI_MSIX_INDEX; return err; } =20 diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/et= hernet/microsoft/mana/mana_en.c index 87a444a6c297..22444c7530a5 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_en.c +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c @@ -1606,6 +1606,7 @@ void mana_destroy_eq(struct mana_port_context *apc) struct gdma_context *gc =3D ac->gdma_dev->gdma_context; struct gdma_queue *eq; int i; + unsigned int msi; =20 if (!apc->eqs) return; @@ -1618,7 +1619,9 @@ void mana_destroy_eq(struct mana_port_context *apc) if (!eq) continue; =20 + msi =3D eq->eq.msix_index; mana_gd_destroy_queue(gc, eq); + mana_gd_put_gic(gc, !gc->msi_sharing, msi); } =20 kfree(apc->eqs); @@ -1635,6 +1638,7 @@ static void mana_create_eq_debugfs(struct mana_port_c= ontext *apc, int i) eq.mana_eq_debugfs =3D debugfs_create_dir(eqnum, apc->mana_eqs_debugfs); debugfs_create_u32("head", 0400, eq.mana_eq_debugfs, &eq.eq->head); debugfs_create_u32("tail", 0400, eq.mana_eq_debugfs, &eq.eq->tail); + debugfs_create_u32("irq", 0400, eq.mana_eq_debugfs, &eq.eq->eq.irq); debugfs_create_file("eq_dump", 0400, eq.mana_eq_debugfs, eq.eq, &mana_dbg= _q_fops); } =20 @@ -1645,6 +1649,7 @@ int mana_create_eq(struct mana_port_context *apc) struct gdma_queue_spec spec =3D {}; int err; int i; + struct gdma_irq_context *gic; =20 WARN_ON(apc->eqs); apc->eqs =3D kzalloc_objs(struct mana_eq, apc->num_queues); @@ -1661,12 +1666,22 @@ int mana_create_eq(struct mana_port_context *apc) apc->mana_eqs_debugfs =3D debugfs_create_dir("EQs", apc->mana_port_debugf= s); =20 for (i =3D 0; i < apc->num_queues; i++) { - spec.eq.msix_index =3D (i + 1) % gc->num_msix_usable; + if (gc->msi_sharing) + spec.eq.msix_index =3D (i + 1) % gc->num_msix_usable; + + gic =3D mana_gd_get_gic(gc, !gc->msi_sharing, &spec.eq.msix_index); + if (!gic) { + err =3D -ENOMEM; + goto out; + } + err =3D mana_gd_create_mana_eq(gd, &spec, &apc->eqs[i].eq); if (err) { dev_err(gc->dev, "Failed to create EQ %d : %d\n", i, err); + mana_gd_put_gic(gc, !gc->msi_sharing, spec.eq.msix_index); goto out; } + apc->eqs[i].eq->eq.irq =3D gic->irq; mana_create_eq_debugfs(apc, i); } =20 diff --git a/include/net/mana/gdma.h b/include/net/mana/gdma.h index 4614a6a7271b..84f85b2299b4 100644 --- a/include/net/mana/gdma.h +++ b/include/net/mana/gdma.h @@ -342,6 +342,7 @@ struct gdma_queue { void *context; =20 unsigned int msix_index; + unsigned int irq; =20 u32 log2_throttle_limit; } eq; --=20 2.43.0 From nobody Sat Apr 4 01:45:59 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7C0CF3AA4E4; Fri, 20 Mar 2026 23:54:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774050880; cv=none; b=PPwYLGyjkBI9BEmmh2nF9j7sZrWjZ5OOgCcf5lkZxVgqJIfsOREGJpcSwLZIi7QGHcrAPRw83UHMSj9ppggFy+9pstgeWxINxiSTD1lMrmWh8YU1z7Dq1jz9RF0NvCk/cSzygpDbwAOEwcbYLzhfTR8m9r3DdWk9E9hY8DVtjws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774050880; c=relaxed/simple; bh=7U3YWQS7u2xteMc7s0vtl7nKzK9zjYBg+daZ4w0aDxw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=so3v0RUVOvpdnl01I87FjfEIrtzv0Ig2sUL8Pq0wGKNdn9Lb5brVOSaisHxzvn9Wj3oGi1u+eV4KqtepKUR0spI3VoQcyi8q8MbdNzwXsKn74VocYjWKt+unLCXJi2ZnU40T8SYJOrHb8Fkbnw355z4jHcNvN8YRxr3T0hbNvuw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: by linux.microsoft.com (Postfix, from userid 1202) id 72BB820B6F08; Fri, 20 Mar 2026 16:54:38 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 72BB820B6F08 From: Long Li To: Long Li , Konstantin Taranov , Jakub Kicinski , "David S . Miller" , Paolo Abeni , Eric Dumazet , Andrew Lunn , Jason Gunthorpe , Leon Romanovsky , Haiyang Zhang , "K . Y . Srinivasan" , Wei Liu , Dexuan Cui Cc: Simon Horman , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 6/6] RDMA/mana_ib: Allocate interrupt contexts on EQs Date: Fri, 20 Mar 2026 16:54:19 -0700 Message-ID: <899e1c1e2e8fd6a0c94aafa67051376993c1a820.1774049761.git.longli@microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the GIC functions to allocate interrupt contexts for RDMA EQs. These interrupt contexts may be shared with Ethernet EQs when MSI-X vectors are limited. The driver now supports allocating dedicated MSI-X for each EQ. Indicate this capability through driver capability bits. Signed-off-by: Long Li --- drivers/infiniband/hw/mana/main.c | 33 ++++++++++++++++++++++++++----- include/net/mana/gdma.h | 7 +++++-- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/drivers/infiniband/hw/mana/main.c b/drivers/infiniband/hw/mana= /main.c index d51dd0ee85f4..0b74dd093b41 100644 --- a/drivers/infiniband/hw/mana/main.c +++ b/drivers/infiniband/hw/mana/main.c @@ -787,6 +787,7 @@ int mana_ib_create_eqs(struct mana_ib_dev *mdev) { struct gdma_context *gc =3D mdev_to_gc(mdev); struct gdma_queue_spec spec =3D {}; + struct gdma_irq_context *gic; int err, i; =20 spec.type =3D GDMA_EQ; @@ -797,9 +798,15 @@ int mana_ib_create_eqs(struct mana_ib_dev *mdev) spec.eq.log2_throttle_limit =3D LOG2_EQ_THROTTLE; spec.eq.msix_index =3D 0; =20 + gic =3D mana_gd_get_gic(gc, false, &spec.eq.msix_index); + if (!gic) + return -ENOMEM; + err =3D mana_gd_create_mana_eq(mdev->gdma_dev, &spec, &mdev->fatal_err_eq= ); - if (err) + if (err) { + mana_gd_put_gic(gc, false, 0); return err; + } =20 mdev->eqs =3D kzalloc_objs(struct gdma_queue *, mdev->ib_dev.num_comp_vectors); @@ -810,31 +817,47 @@ int mana_ib_create_eqs(struct mana_ib_dev *mdev) spec.eq.callback =3D NULL; for (i =3D 0; i < mdev->ib_dev.num_comp_vectors; i++) { spec.eq.msix_index =3D (i + 1) % gc->num_msix_usable; + + gic =3D mana_gd_get_gic(gc, false, &spec.eq.msix_index); + if (!gic) { + err =3D -ENOMEM; + goto destroy_eqs; + } + err =3D mana_gd_create_mana_eq(mdev->gdma_dev, &spec, &mdev->eqs[i]); - if (err) + if (err) { + mana_gd_put_gic(gc, false, spec.eq.msix_index); goto destroy_eqs; + } } =20 return 0; =20 destroy_eqs: - while (i-- > 0) + while (i-- > 0) { mana_gd_destroy_queue(gc, mdev->eqs[i]); + mana_gd_put_gic(gc, false, (i + 1) % gc->num_msix_usable); + } kfree(mdev->eqs); destroy_fatal_eq: mana_gd_destroy_queue(gc, mdev->fatal_err_eq); + mana_gd_put_gic(gc, false, 0); return err; } =20 void mana_ib_destroy_eqs(struct mana_ib_dev *mdev) { struct gdma_context *gc =3D mdev_to_gc(mdev); - int i; + int i, msi; =20 mana_gd_destroy_queue(gc, mdev->fatal_err_eq); + mana_gd_put_gic(gc, false, 0); =20 - for (i =3D 0; i < mdev->ib_dev.num_comp_vectors; i++) + for (i =3D 0; i < mdev->ib_dev.num_comp_vectors; i++) { mana_gd_destroy_queue(gc, mdev->eqs[i]); + msi =3D (i + 1) % gc->num_msix_usable; + mana_gd_put_gic(gc, false, msi); + } =20 kfree(mdev->eqs); } diff --git a/include/net/mana/gdma.h b/include/net/mana/gdma.h index 84f85b2299b4..9faa072e779e 100644 --- a/include/net/mana/gdma.h +++ b/include/net/mana/gdma.h @@ -615,6 +615,7 @@ enum { #define GDMA_DRV_CAP_FLAG_1_HWC_TIMEOUT_RECONFIG BIT(3) #define GDMA_DRV_CAP_FLAG_1_GDMA_PAGES_4MB_1GB_2GB BIT(4) #define GDMA_DRV_CAP_FLAG_1_VARIABLE_INDIRECTION_TABLE_SUPPORT BIT(5) +#define GDMA_DRV_CAP_FLAG_1_HW_VPORT_LINK_AWARE BIT(6) =20 /* Driver can handle holes (zeros) in the device list */ #define GDMA_DRV_CAP_FLAG_1_DEV_LIST_HOLES_SUP BIT(11) @@ -631,7 +632,8 @@ enum { /* Driver detects stalled send queues and recovers them */ #define GDMA_DRV_CAP_FLAG_1_HANDLE_STALL_SQ_RECOVERY BIT(18) =20 -#define GDMA_DRV_CAP_FLAG_1_HW_VPORT_LINK_AWARE BIT(6) +/* Driver supports separate EQ/MSIs for each vPort */ +#define GDMA_DRV_CAP_FLAG_1_EQ_MSI_UNSHARE_MULTI_VPORT BIT(19) =20 /* Driver supports linearizing the skb when num_sge exceeds hardware limit= */ #define GDMA_DRV_CAP_FLAG_1_SKB_LINEARIZE BIT(20) @@ -659,7 +661,8 @@ enum { GDMA_DRV_CAP_FLAG_1_SKB_LINEARIZE | \ GDMA_DRV_CAP_FLAG_1_PROBE_RECOVERY | \ GDMA_DRV_CAP_FLAG_1_HANDLE_STALL_SQ_RECOVERY | \ - GDMA_DRV_CAP_FLAG_1_HWC_TIMEOUT_RECOVERY) + GDMA_DRV_CAP_FLAG_1_HWC_TIMEOUT_RECOVERY | \ + GDMA_DRV_CAP_FLAG_1_EQ_MSI_UNSHARE_MULTI_VPORT) =20 #define GDMA_DRV_CAP_FLAGS2 0 =20 --=20 2.43.0