Skip to content

Commit

Permalink
libhns: Support congestion control algorithm configuration with direc…
Browse files Browse the repository at this point in the history
…t verbs

Add support for configuration of congestion control algorithms in QP
granularity with direct verbs hnsdv_create_qp().

Signed-off-by: Junxian Huang <[email protected]>
  • Loading branch information
Junxian Huang authored and Junxian Huang committed Mar 5, 2024
1 parent fded8e4 commit 397b22b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 7 deletions.
1 change: 1 addition & 0 deletions providers/hns/hns_roce_u.c
Expand Up @@ -135,6 +135,7 @@ static int set_context_attr(struct hns_roce_device *hr_dev,
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;
Expand Down
1 change: 1 addition & 0 deletions providers/hns/hns_roce_u.h
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
45 changes: 40 additions & 5 deletions providers/hns/hns_roce_u_verbs.c
Expand Up @@ -786,7 +786,7 @@ int hns_roce_u_destroy_srq(struct ibv_srq *ibv_srq)
}

enum {
HNSDV_QP_SUP_COMP_MASK = 0,
HNSDV_QP_SUP_COMP_MASK = HNSDV_QP_INIT_ATTR_MASK_QP_CONGEST_TYPE,
};

static int check_hnsdv_qp_attr(struct hns_roce_context *ctx,
Expand Down Expand Up @@ -1209,10 +1209,33 @@ static int hns_roce_store_qp(struct hns_roce_context *ctx,
return 0;
}

static int to_cmd_cong_type(uint8_t cong_type, __u64 *cmd_cong_type)
{
switch (cong_type) {
case HNSDV_QP_CREATE_ENABLE_DCQCN:
*cmd_cong_type = HNS_ROCE_CREATE_QP_FLAGS_DCQCN;
break;
case HNSDV_QP_CREATE_ENABLE_LDCP:
*cmd_cong_type = HNS_ROCE_CREATE_QP_FLAGS_LDCP;
break;
case HNSDV_QP_CREATE_ENABLE_HC3:
*cmd_cong_type = HNS_ROCE_CREATE_QP_FLAGS_HC3;
break;
case HNSDV_QP_CREATE_ENABLE_DIP:
*cmd_cong_type = HNS_ROCE_CREATE_QP_FLAGS_DIP;
break;
default:
return EINVAL;
}

return 0;
}

static int qp_exec_create_cmd(struct ibv_qp_init_attr_ex *attr,
struct hns_roce_qp *qp,
struct hns_roce_context *ctx,
uint64_t *dwqe_mmap_key)
uint64_t *dwqe_mmap_key,
struct hnsdv_qp_init_attr *hns_attr)
{
struct hns_roce_create_qp_ex_resp resp_ex = {};
struct hns_roce_create_qp_ex cmd_ex = {};
Expand All @@ -1224,6 +1247,15 @@ static int qp_exec_create_cmd(struct ibv_qp_init_attr_ex *attr,
cmd_ex.log_sq_stride = qp->sq.wqe_shift;
cmd_ex.log_sq_bb_count = hr_ilog32(qp->sq.wqe_cnt);

if (hns_attr &&
hns_attr->comp_mask & HNSDV_QP_INIT_ATTR_MASK_QP_CONGEST_TYPE) {
ret = to_cmd_cong_type(hns_attr->congest_type,
&cmd_ex.cong_type_flags);
if (ret)
return ret;
cmd_ex.comp_mask |= HNS_ROCE_CREATE_QP_MASK_CONGEST_TYPE;
}

ret = ibv_cmd_create_qp_ex2(&ctx->ibv_ctx.context, &qp->verbs_qp, attr,
&cmd_ex.ibv_cmd, sizeof(cmd_ex),
&resp_ex.ibv_resp, sizeof(resp_ex));
Expand Down Expand Up @@ -1322,7 +1354,7 @@ static struct ibv_qp *create_qp(struct ibv_context *ibv_ctx,
if (ret)
goto err_buf;

ret = qp_exec_create_cmd(attr, qp, context, &dwqe_mmap_key);
ret = qp_exec_create_cmd(attr, qp, context, &dwqe_mmap_key, hns_attr);
if (ret)
goto err_cmd;

Expand Down Expand Up @@ -1403,9 +1435,9 @@ struct ibv_qp *hnsdv_create_qp(struct ibv_context *context,
int hnsdv_query_device(struct ibv_context *context,
struct hnsdv_context *attrs_out)
{
struct hns_roce_context *ctx = context ? to_hr_ctx(context) : NULL;
struct hns_roce_device *hr_dev = to_hr_dev(context->device);

if (!ctx || !attrs_out)
if (!hr_dev || !attrs_out)
return EINVAL;

if (!is_hns_dev(context->device)) {
Expand All @@ -1414,6 +1446,9 @@ int hnsdv_query_device(struct ibv_context *context,
}
memset(attrs_out, 0, sizeof(*attrs_out));

attrs_out->comp_mask |= HNSDV_CONTEXT_MASK_CONGEST_TYPE;
attrs_out->congest_type = hr_dev->congest_cap;

return 0;
}

Expand Down
25 changes: 23 additions & 2 deletions providers/hns/hnsdv.h
Expand Up @@ -15,12 +15,33 @@
extern "C" {
#endif

enum hnsdv_qp_congest_ctrl_type {
HNSDV_QP_CREATE_ENABLE_DCQCN = 1 << 0,
HNSDV_QP_CREATE_ENABLE_LDCP = 1 << 1,
HNSDV_QP_CREATE_ENABLE_HC3 = 1 << 2,
HNSDV_QP_CREATE_ENABLE_DIP = 1 << 3,
};

enum hnsdv_qp_init_attr_mask {
HNSDV_QP_INIT_ATTR_MASK_QP_CONGEST_TYPE = 1 << 1,
};

struct hnsdv_qp_init_attr {
uint64_t comp_mask;
uint64_t comp_mask; /* Use enum hnsdv_qp_init_attr_mask */
uint32_t create_flags;
uint8_t congest_type; /* Use enum hnsdv_qp_congest_ctrl_type */
uint8_t reserved[3];
};

enum hnsdv_query_context_comp_mask {
HNSDV_CONTEXT_MASK_CONGEST_TYPE = 1 << 0,
};

struct hnsdv_context {
uint64_t comp_mask;
uint64_t comp_mask; /* Use enum hnsdv_query_context_comp_mask */
uint64_t flags;
uint8_t congest_type; /* Use enum hnsdv_qp_congest_ctrl_type */
uint8_t reserved[7];
};

bool hnsdv_is_supported(struct ibv_device *device);
Expand Down

0 comments on commit 397b22b

Please sign in to comment.