-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RDMA/mlx5: Move init and cleanup of UMR to umr.c
The first patch in a series to split UMR logic to a dedicated file. As a start, move the init and cleanup of UMR resources to umr.c. Link: https://lore.kernel.org/r/849e632dd1945a2534712a320cc5779f2149ba96.1649747695.git.leonro@nvidia.com Signed-off-by: Aharon Landau <aharonl@nvidia.com> Reviewed-by: Michael Guralnik <michaelgur@nvidia.com> Signed-off-by: Leon Romanovsky <leonro@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
- Loading branch information
Aharon Landau
authored and
Jason Gunthorpe
committed
Apr 25, 2022
1 parent
b5a93e7
commit 04876c1
Showing
4 changed files
with
125 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB | ||
/* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. */ | ||
|
||
#include "mlx5_ib.h" | ||
#include "umr.h" | ||
|
||
enum { | ||
MAX_UMR_WR = 128, | ||
}; | ||
|
||
static int mlx5r_umr_qp_rst2rts(struct mlx5_ib_dev *dev, struct ib_qp *qp) | ||
{ | ||
struct ib_qp_attr attr = {}; | ||
int ret; | ||
|
||
attr.qp_state = IB_QPS_INIT; | ||
attr.port_num = 1; | ||
ret = ib_modify_qp(qp, &attr, | ||
IB_QP_STATE | IB_QP_PKEY_INDEX | IB_QP_PORT); | ||
if (ret) { | ||
mlx5_ib_dbg(dev, "Couldn't modify UMR QP\n"); | ||
return ret; | ||
} | ||
|
||
memset(&attr, 0, sizeof(attr)); | ||
attr.qp_state = IB_QPS_RTR; | ||
|
||
ret = ib_modify_qp(qp, &attr, IB_QP_STATE); | ||
if (ret) { | ||
mlx5_ib_dbg(dev, "Couldn't modify umr QP to rtr\n"); | ||
return ret; | ||
} | ||
|
||
memset(&attr, 0, sizeof(attr)); | ||
attr.qp_state = IB_QPS_RTS; | ||
ret = ib_modify_qp(qp, &attr, IB_QP_STATE); | ||
if (ret) { | ||
mlx5_ib_dbg(dev, "Couldn't modify umr QP to rts\n"); | ||
return ret; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int mlx5r_umr_resource_init(struct mlx5_ib_dev *dev) | ||
{ | ||
struct ib_qp_init_attr init_attr = {}; | ||
struct ib_pd *pd; | ||
struct ib_cq *cq; | ||
struct ib_qp *qp; | ||
int ret; | ||
|
||
pd = ib_alloc_pd(&dev->ib_dev, 0); | ||
if (IS_ERR(pd)) { | ||
mlx5_ib_dbg(dev, "Couldn't create PD for sync UMR QP\n"); | ||
return PTR_ERR(pd); | ||
} | ||
|
||
cq = ib_alloc_cq(&dev->ib_dev, NULL, 128, 0, IB_POLL_SOFTIRQ); | ||
if (IS_ERR(cq)) { | ||
mlx5_ib_dbg(dev, "Couldn't create CQ for sync UMR QP\n"); | ||
ret = PTR_ERR(cq); | ||
goto destroy_pd; | ||
} | ||
|
||
init_attr.send_cq = cq; | ||
init_attr.recv_cq = cq; | ||
init_attr.sq_sig_type = IB_SIGNAL_ALL_WR; | ||
init_attr.cap.max_send_wr = MAX_UMR_WR; | ||
init_attr.cap.max_send_sge = 1; | ||
init_attr.qp_type = MLX5_IB_QPT_REG_UMR; | ||
init_attr.port_num = 1; | ||
qp = ib_create_qp(pd, &init_attr); | ||
if (IS_ERR(qp)) { | ||
mlx5_ib_dbg(dev, "Couldn't create sync UMR QP\n"); | ||
ret = PTR_ERR(qp); | ||
goto destroy_cq; | ||
} | ||
|
||
ret = mlx5r_umr_qp_rst2rts(dev, qp); | ||
if (ret) | ||
goto destroy_qp; | ||
|
||
dev->umrc.qp = qp; | ||
dev->umrc.cq = cq; | ||
dev->umrc.pd = pd; | ||
|
||
sema_init(&dev->umrc.sem, MAX_UMR_WR); | ||
|
||
return 0; | ||
|
||
destroy_qp: | ||
ib_destroy_qp(qp); | ||
destroy_cq: | ||
ib_free_cq(cq); | ||
destroy_pd: | ||
ib_dealloc_pd(pd); | ||
return ret; | ||
} | ||
|
||
void mlx5r_umr_resource_cleanup(struct mlx5_ib_dev *dev) | ||
{ | ||
ib_destroy_qp(dev->umrc.qp); | ||
ib_free_cq(dev->umrc.cq); | ||
ib_dealloc_pd(dev->umrc.pd); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ | ||
/* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. */ | ||
|
||
#ifndef _MLX5_IB_UMR_H | ||
#define _MLX5_IB_UMR_H | ||
|
||
#include "mlx5_ib.h" | ||
|
||
int mlx5r_umr_resource_init(struct mlx5_ib_dev *dev); | ||
void mlx5r_umr_resource_cleanup(struct mlx5_ib_dev *dev); | ||
|
||
#endif /* _MLX5_IB_UMR_H */ |