Skip to content

Commit

Permalink
libhns: Support DSCP in userspace
Browse files Browse the repository at this point in the history
Add support for DSCP by getting corresponding priority from kernel
according to the user specified DSCP.

Signed-off-by: Junxian Huang <[email protected]>
  • Loading branch information
Junxian Huang authored and Junxian Huang committed Apr 8, 2024
1 parent 8c4496b commit f2e92c3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
7 changes: 7 additions & 0 deletions providers/hns/hns_roce_u.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ enum hns_roce_pktype {
HNS_ROCE_PKTYPE_ROCE_V2_IPV4,
};

enum hns_roce_tc_map_mode {
HNS_ROCE_TC_MAP_MODE_PRIO,
HNS_ROCE_TC_MAP_MODE_DSCP,
};

struct hns_roce_db_page {
struct hns_roce_db_page *prev, *next;
struct hns_roce_buf buf;
Expand Down Expand Up @@ -324,6 +329,8 @@ struct hns_roce_qp {
unsigned int next_sge;
int port_num;
uint8_t sl;
uint8_t tc_mode;
uint8_t priority;
unsigned int qkey;
enum ibv_mtu path_mtu;

Expand Down
3 changes: 3 additions & 0 deletions providers/hns/hns_roce_u_abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,7 @@ DECLARE_DRV_CMD(hns_roce_create_srq_ex, IB_USER_VERBS_CMD_CREATE_XSRQ,
DECLARE_DRV_CMD(hns_roce_create_ah, IB_USER_VERBS_CMD_CREATE_AH, empty,
hns_roce_ib_create_ah_resp);

DECLARE_DRV_CMD(hns_roce_modify_qp_ex, IB_USER_VERBS_EX_CMD_MODIFY_QP,
empty, hns_roce_ib_modify_qp_resp);

#endif /* _HNS_ROCE_U_ABI_H */
20 changes: 15 additions & 5 deletions providers/hns/hns_roce_u_hw_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,9 @@ static void record_qp_attr(struct ibv_qp *qp, struct ibv_qp_attr *attr,
if (attr_mask & IBV_QP_PORT)
hr_qp->port_num = attr->port_num;

if (attr_mask & IBV_QP_AV)
if (hr_qp->tc_mode == HNS_ROCE_TC_MAP_MODE_DSCP)
hr_qp->sl = hr_qp->priority;
else if (attr_mask & IBV_QP_AV)
hr_qp->sl = attr->ah_attr.sl;

if (attr_mask & IBV_QP_QKEY)
Expand All @@ -1538,18 +1540,21 @@ static void record_qp_attr(struct ibv_qp *qp, struct ibv_qp_attr *attr,
static int hns_roce_u_v2_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
int attr_mask)
{
int ret;
struct ibv_modify_qp cmd;
struct hns_roce_modify_qp_ex_resp resp_ex = {};
struct hns_roce_modify_qp_ex cmd_ex = {};
struct hns_roce_qp *hr_qp = to_hr_qp(qp);
bool flag = false; /* modify qp to error */
int ret;

if ((attr_mask & IBV_QP_STATE) && (attr->qp_state == IBV_QPS_ERR)) {
pthread_spin_lock(&hr_qp->sq.lock);
pthread_spin_lock(&hr_qp->rq.lock);
flag = true;
}

ret = ibv_cmd_modify_qp(qp, attr, attr_mask, &cmd, sizeof(cmd));
ret = ibv_cmd_modify_qp_ex(qp, attr, attr_mask, &cmd_ex.ibv_cmd,
sizeof(cmd_ex), &resp_ex.ibv_resp,
sizeof(resp_ex));

if (flag) {
if (!ret)
Expand All @@ -1561,8 +1566,13 @@ static int hns_roce_u_v2_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
if (ret)
return ret;

if (attr_mask & IBV_QP_STATE)
if (attr_mask & IBV_QP_STATE) {
qp->state = attr->qp_state;
if (attr->qp_state == IBV_QPS_RTR) {
hr_qp->tc_mode = resp_ex.drv_payload.tc_mode;
hr_qp->priority = resp_ex.drv_payload.priority;
}
}

if ((attr_mask & IBV_QP_STATE) && attr->qp_state == IBV_QPS_RESET) {
if (qp->recv_cq)
Expand Down
3 changes: 3 additions & 0 deletions providers/hns/hns_roce_u_verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,9 @@ struct ibv_ah *hns_roce_u_create_ah(struct ibv_pd *pd, struct ibv_ah_attr *attr)
ah->av.mac, NULL))
goto err;

if (resp.tc_mode == HNS_ROCE_TC_MAP_MODE_DSCP)
ah->av.sl = resp.priority;

ah->av.udp_sport = get_ah_udp_sport(attr);

return &ah->ibv_ah;
Expand Down

0 comments on commit f2e92c3

Please sign in to comment.