Skip to content

Commit

Permalink
Merge pull request #1426 from hginjgerx/dv
Browse files Browse the repository at this point in the history
libhns: Introduce hns direct verbs and support userspace congestion control algorithm configuration with dv api
  • Loading branch information
rleon committed Mar 10, 2024
2 parents 3ff0150 + 397b22b commit 5155f7f
Show file tree
Hide file tree
Showing 20 changed files with 530 additions and 41 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ add_subdirectory(providers/efa)
add_subdirectory(providers/efa/man)
add_subdirectory(providers/erdma)
add_subdirectory(providers/hns)
add_subdirectory(providers/hns/man)
add_subdirectory(providers/irdma)
add_subdirectory(providers/mana)
add_subdirectory(providers/mana/man)
Expand Down
1 change: 1 addition & 0 deletions debian/ibverbs-providers.install
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
etc/libibverbs.d/
usr/lib/*/libefa.so.*
usr/lib/*/libibverbs/lib*-rdmav*.so
usr/lib/*/libhns.so.*
usr/lib/*/libmana.so.*
usr/lib/*/libmlx4.so.*
usr/lib/*/libmlx5.so.*
4 changes: 2 additions & 2 deletions debian/ibverbs-providers.lintian-overrides
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# libefa, libmana, libmlx4 and libmlx5 are ibverbs provider that provides more functions.
ibverbs-providers: package-name-doesnt-match-sonames libefa1 libmana1 libmlx4-1 libmlx5-1
# libefa, libhns, libmana, libmlx4 and libmlx5 are ibverbs provider that provides more functions.
ibverbs-providers: package-name-doesnt-match-sonames libefa1 libhns-1 libmana1 libmlx4-1 libmlx5-1
6 changes: 6 additions & 0 deletions debian/ibverbs-providers.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ libefa.so.1 ibverbs-providers #MINVER#
efadv_cq_from_ibv_cq_ex@EFA_1.2 43
efadv_create_cq@EFA_1.2 43
efadv_query_mr@EFA_1.3 50
libhns.so.1 ibverbs-providers #MINVER#
* Build-Depends-Package: libibverbs-dev
HNS_1.0@HNS_1.0 51
hnsdv_is_supported@HNS_1.0 51
hnsdv_create_qp@HNS_1.0 51
hnsdv_query_device@HNS_1.0 51
libmana.so.1 ibverbs-providers #MINVER#
* Build-Depends-Package: libibverbs-dev
MANA_1.0@MANA_1.0 41
Expand Down
6 changes: 6 additions & 0 deletions debian/libibverbs-dev.install
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
usr/include/infiniband/arch.h
usr/include/infiniband/efadv.h
usr/include/infiniband/hnsdv.h
usr/include/infiniband/ib_user_ioctl_verbs.h
usr/include/infiniband/manadv.h
usr/include/infiniband/mlx4dv.h
Expand All @@ -15,6 +16,8 @@ usr/include/infiniband/verbs_api.h
usr/lib/*/lib*-rdmav*.a
usr/lib/*/libefa.a
usr/lib/*/libefa.so
usr/lib/*/libhns.a
usr/lib/*/libhns.so
usr/lib/*/libibverbs*.so
usr/lib/*/libibverbs.a
usr/lib/*/libmana.a
Expand All @@ -24,18 +27,21 @@ usr/lib/*/libmlx4.so
usr/lib/*/libmlx5.a
usr/lib/*/libmlx5.so
usr/lib/*/pkgconfig/libefa.pc
usr/lib/*/pkgconfig/libhns.pc
usr/lib/*/pkgconfig/libibverbs.pc
usr/lib/*/pkgconfig/libmana.pc
usr/lib/*/pkgconfig/libmlx4.pc
usr/lib/*/pkgconfig/libmlx5.pc
usr/share/man/man3/efadv_*.3
usr/share/man/man3/hnsdv_*.3
usr/share/man/man3/ibv_*
usr/share/man/man3/mbps_to_ibv_rate.3
usr/share/man/man3/manadv_*.3
usr/share/man/man3/mlx4dv_*.3
usr/share/man/man3/mlx5dv_*.3
usr/share/man/man3/mult_to_ibv_rate.3
usr/share/man/man7/efadv.7
usr/share/man/man7/hnsdv.7
usr/share/man/man7/manadv.7
usr/share/man/man7/mlx4dv.7
usr/share/man/man7/mlx5dv.7
16 changes: 16 additions & 0 deletions kernel-headers/rdma/hns-abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ struct hns_roce_ib_create_srq_resp {
__u32 cap_flags; /* Use enum hns_roce_srq_cap_flags */
};

enum hns_roce_congest_type_flags {
HNS_ROCE_CREATE_QP_FLAGS_DCQCN,
HNS_ROCE_CREATE_QP_FLAGS_LDCP,
HNS_ROCE_CREATE_QP_FLAGS_HC3,
HNS_ROCE_CREATE_QP_FLAGS_DIP,
};

enum hns_roce_create_qp_comp_mask {
HNS_ROCE_CREATE_QP_MASK_CONGEST_TYPE = 1 << 0,
};

struct hns_roce_ib_create_qp {
__aligned_u64 buf_addr;
__aligned_u64 db_addr;
Expand All @@ -81,6 +92,9 @@ struct hns_roce_ib_create_qp {
__u8 sq_no_prefetch;
__u8 reserved[5];
__aligned_u64 sdb_addr;
__aligned_u64 comp_mask; /* Use enum hns_roce_create_qp_comp_mask */
__aligned_u64 create_flags;
__aligned_u64 cong_type_flags;
};

enum hns_roce_qp_cap_flags {
Expand Down Expand Up @@ -114,6 +128,8 @@ struct hns_roce_ib_alloc_ucontext_resp {
__u32 reserved;
__u32 config;
__u32 max_inline_data;
__u8 congest_type;
__u8 reserved0[7];
};

struct hns_roce_ib_alloc_ucontext {
Expand Down
9 changes: 8 additions & 1 deletion providers/hns/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
rdma_provider(hns
rdma_shared_provider(hns libhns.map
1 1.0.${PACKAGE_VERSION}
hns_roce_u.c
hns_roce_u_buf.c
hns_roce_u_db.c
hns_roce_u_hw_v2.c
hns_roce_u_verbs.c
)

publish_headers(infiniband
hnsdv.h
)

rdma_pkg_config("hns" "libibverbs" "${CMAKE_THREAD_LIBS_INIT}")
83 changes: 54 additions & 29 deletions providers/hns/hns_roce_u.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,50 +97,33 @@ static uint32_t calc_table_shift(uint32_t entry_count, uint32_t size_shift)
return count_shift > size_shift ? count_shift - size_shift : 0;
}

static struct verbs_context *hns_roce_alloc_context(struct ibv_device *ibdev,
int cmd_fd,
void *private_data)
static int set_context_attr(struct hns_roce_device *hr_dev,
struct hns_roce_context *context,
struct hns_roce_alloc_ucontext_resp *resp)
{
struct hns_roce_device *hr_dev = to_hr_dev(ibdev);
struct hns_roce_alloc_ucontext_resp resp = {};
struct hns_roce_alloc_ucontext cmd = {};
struct ibv_device_attr dev_attrs;
struct hns_roce_context *context;
int i;

context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx,
RDMA_DRIVER_HNS);
if (!context)
return NULL;

cmd.config |= HNS_ROCE_EXSGE_FLAGS | HNS_ROCE_RQ_INLINE_FLAGS |
HNS_ROCE_CQE_INLINE_FLAGS;
if (ibv_cmd_get_context(&context->ibv_ctx, &cmd.ibv_cmd, sizeof(cmd),
&resp.ibv_resp, sizeof(resp)))
goto err_free;

if (!resp.cqe_size)
if (!resp->cqe_size)
context->cqe_size = HNS_ROCE_CQE_SIZE;
else if (resp.cqe_size <= HNS_ROCE_V3_CQE_SIZE)
context->cqe_size = resp.cqe_size;
else if (resp->cqe_size <= HNS_ROCE_V3_CQE_SIZE)
context->cqe_size = resp->cqe_size;
else
context->cqe_size = HNS_ROCE_V3_CQE_SIZE;

context->config = resp.config;
if (resp.config & HNS_ROCE_RSP_EXSGE_FLAGS)
context->max_inline_data = resp.max_inline_data;
context->config = resp->config;
if (resp->config & HNS_ROCE_RSP_EXSGE_FLAGS)
context->max_inline_data = resp->max_inline_data;

context->qp_table_shift = calc_table_shift(resp.qp_tab_size,
context->qp_table_shift = calc_table_shift(resp->qp_tab_size,
HNS_ROCE_QP_TABLE_BITS);
context->qp_table_mask = (1 << context->qp_table_shift) - 1;
pthread_mutex_init(&context->qp_table_mutex, NULL);
for (i = 0; i < HNS_ROCE_QP_TABLE_SIZE; ++i)
context->qp_table[i].refcnt = 0;

context->srq_table_shift = calc_table_shift(resp.srq_tab_size,
context->srq_table_shift = calc_table_shift(resp->srq_tab_size,
HNS_ROCE_SRQ_TABLE_BITS);
context->srq_table_mask = (1 << context->srq_table_shift) - 1;
pthread_mutex_init(&context->srq_table_mutex, NULL);
for (i = 0; i < HNS_ROCE_SRQ_TABLE_SIZE; ++i)
context->srq_table[i].refcnt = 0;

Expand All @@ -149,20 +132,49 @@ static struct verbs_context *hns_roce_alloc_context(struct ibv_device *ibdev,
struct ibv_device_attr_ex,
orig_attr),
sizeof(dev_attrs)))
goto err_free;
return EIO;

hr_dev->hw_version = dev_attrs.hw_ver;
hr_dev->congest_cap = resp->congest_type;
context->max_qp_wr = dev_attrs.max_qp_wr;
context->max_sge = dev_attrs.max_sge;
context->max_cqe = dev_attrs.max_cqe;
context->max_srq_wr = dev_attrs.max_srq_wr;
context->max_srq_sge = dev_attrs.max_srq_sge;

return 0;
}

static struct verbs_context *hns_roce_alloc_context(struct ibv_device *ibdev,
int cmd_fd,
void *private_data)
{
struct hns_roce_device *hr_dev = to_hr_dev(ibdev);
struct hns_roce_alloc_ucontext_resp resp = {};
struct hns_roce_alloc_ucontext cmd = {};
struct hns_roce_context *context;

context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx,
RDMA_DRIVER_HNS);
if (!context)
return NULL;

cmd.config |= HNS_ROCE_EXSGE_FLAGS | HNS_ROCE_RQ_INLINE_FLAGS |
HNS_ROCE_CQE_INLINE_FLAGS;
if (ibv_cmd_get_context(&context->ibv_ctx, &cmd.ibv_cmd, sizeof(cmd),
&resp.ibv_resp, sizeof(resp)))
goto err_free;

if (set_context_attr(hr_dev, context, &resp))
goto err_free;

context->uar = mmap(NULL, hr_dev->page_size, PROT_READ | PROT_WRITE,
MAP_SHARED, cmd_fd, 0);
if (context->uar == MAP_FAILED)
goto err_free;

pthread_mutex_init(&context->qp_table_mutex, NULL);
pthread_mutex_init(&context->srq_table_mutex, NULL);
pthread_spin_init(&context->uar_lock, PTHREAD_PROCESS_PRIVATE);

verbs_set_ops(&context->ibv_ctx, &hns_common_ops);
Expand Down Expand Up @@ -216,4 +228,17 @@ static const struct verbs_device_ops hns_roce_dev_ops = {
.uninit_device = hns_uninit_device,
.alloc_context = hns_roce_alloc_context,
};

bool is_hns_dev(struct ibv_device *device)
{
struct verbs_device *verbs_device = verbs_get_device(device);

return verbs_device->ops == &hns_roce_dev_ops;
}

bool hnsdv_is_supported(struct ibv_device *device)
{
return is_hns_dev(device);
}

PROVIDER_DRIVER(hns, hns_roce_dev_ops);
3 changes: 3 additions & 0 deletions providers/hns/hns_roce_u.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ struct hns_roce_device {
int page_size;
const struct hns_roce_u_hw *u_hw;
int hw_version;
uint8_t congest_cap;
};

struct hns_roce_buf {
Expand Down Expand Up @@ -494,6 +495,8 @@ void hns_roce_free_qp_buf(struct hns_roce_qp *qp, struct hns_roce_context *ctx);

void hns_roce_init_qp_indices(struct hns_roce_qp *qp);

bool is_hns_dev(struct ibv_device *device);

extern const struct hns_roce_u_hw hns_roce_u_hw_v2;

#endif /* _HNS_ROCE_U_H */
1 change: 1 addition & 0 deletions providers/hns/hns_roce_u_abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <infiniband/kern-abi.h>
#include <rdma/hns-abi.h>
#include <kernel-abi/hns-abi.h>
#include "hnsdv.h"

DECLARE_DRV_CMD(hns_roce_alloc_pd, IB_USER_VERBS_CMD_ALLOC_PD,
empty, hns_roce_ib_alloc_pd_resp);
Expand Down

0 comments on commit 5155f7f

Please sign in to comment.