|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
| 2 | +/* |
| 3 | + * Copyright (c) 2021 - 2022, Shanghai Yunsilicon Technology Co., Ltd. |
| 4 | + * All rights reserved. |
| 5 | + */ |
| 6 | + |
| 7 | +#include <config.h> |
| 8 | + |
| 9 | +#include <stdlib.h> |
| 10 | +#include <pthread.h> |
| 11 | +#include <string.h> |
| 12 | +#include <errno.h> |
| 13 | +#include <stdio.h> |
| 14 | +#include <util/compiler.h> |
| 15 | + |
| 16 | +#include "xscale.h" |
| 17 | +#include "xsc_hsi.h" |
| 18 | + |
| 19 | +struct xsc_qp *xsc_find_qp(struct xsc_context *ctx, uint32_t qpn) |
| 20 | +{ |
| 21 | + int tind = qpn >> XSC_QP_TABLE_SHIFT; |
| 22 | + |
| 23 | + if (ctx->qp_table[tind].refcnt) |
| 24 | + return ctx->qp_table[tind].table[qpn & XSC_QP_TABLE_MASK]; |
| 25 | + else |
| 26 | + return NULL; |
| 27 | +} |
| 28 | + |
| 29 | +int xsc_store_qp(struct xsc_context *ctx, uint32_t qpn, struct xsc_qp *qp) |
| 30 | +{ |
| 31 | + int tind = qpn >> XSC_QP_TABLE_SHIFT; |
| 32 | + |
| 33 | + if (!ctx->qp_table[tind].refcnt) { |
| 34 | + ctx->qp_table[tind].table = |
| 35 | + calloc(XSC_QP_TABLE_MASK + 1, sizeof(struct xsc_qp *)); |
| 36 | + if (!ctx->qp_table[tind].table) |
| 37 | + return -1; |
| 38 | + } |
| 39 | + |
| 40 | + ++ctx->qp_table[tind].refcnt; |
| 41 | + ctx->qp_table[tind].table[qpn & XSC_QP_TABLE_MASK] = qp; |
| 42 | + return 0; |
| 43 | +} |
| 44 | + |
| 45 | +void xsc_clear_qp(struct xsc_context *ctx, uint32_t qpn) |
| 46 | +{ |
| 47 | + int tind = qpn >> XSC_QP_TABLE_SHIFT; |
| 48 | + |
| 49 | + if (!--ctx->qp_table[tind].refcnt) |
| 50 | + free(ctx->qp_table[tind].table); |
| 51 | + else |
| 52 | + ctx->qp_table[tind].table[qpn & XSC_QP_TABLE_MASK] = NULL; |
| 53 | +} |
| 54 | + |
| 55 | +int xsc_err_state_qp(struct ibv_qp *qp, enum ibv_qp_state cur_state, |
| 56 | + enum ibv_qp_state state) |
| 57 | +{ |
| 58 | + struct xsc_err_state_qp_node *tmp, *err_rq_node, *err_sq_node; |
| 59 | + struct xsc_qp *xqp = to_xqp(qp); |
| 60 | + int ret = 0; |
| 61 | + |
| 62 | + xsc_dbg(to_xctx(qp->context)->dbg_fp, XSC_DBG_QP, |
| 63 | + "modify qp: qpid %d, cur_qp_state %d, qp_state %d\n", |
| 64 | + xqp->rsc.rsn, cur_state, state); |
| 65 | + if (cur_state == IBV_QPS_ERR && state != IBV_QPS_ERR) { |
| 66 | + if (qp->recv_cq) { |
| 67 | + list_for_each_safe(&to_xcq(qp->recv_cq)->err_state_qp_list, |
| 68 | + err_rq_node, tmp, entry) { |
| 69 | + if (err_rq_node->qp_id == xqp->rsc.rsn) { |
| 70 | + list_del(&err_rq_node->entry); |
| 71 | + free(err_rq_node); |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + if (qp->send_cq) { |
| 77 | + list_for_each_safe(&to_xcq(qp->send_cq)->err_state_qp_list, |
| 78 | + err_sq_node, tmp, entry) { |
| 79 | + if (err_sq_node->qp_id == xqp->rsc.rsn) { |
| 80 | + list_del(&err_sq_node->entry); |
| 81 | + free(err_sq_node); |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + return ret; |
| 86 | + } |
| 87 | + |
| 88 | + if (cur_state != IBV_QPS_ERR && state == IBV_QPS_ERR) { |
| 89 | + if (qp->recv_cq) { |
| 90 | + err_rq_node = calloc(1, sizeof(*err_rq_node)); |
| 91 | + if (!err_rq_node) |
| 92 | + return ENOMEM; |
| 93 | + err_rq_node->qp_id = xqp->rsc.rsn; |
| 94 | + err_rq_node->is_sq = false; |
| 95 | + list_add_tail(&to_xcq(qp->recv_cq)->err_state_qp_list, |
| 96 | + &err_rq_node->entry); |
| 97 | + } |
| 98 | + |
| 99 | + if (qp->send_cq) { |
| 100 | + err_sq_node = calloc(1, sizeof(*err_sq_node)); |
| 101 | + if (!err_sq_node) |
| 102 | + return ENOMEM; |
| 103 | + err_sq_node->qp_id = xqp->rsc.rsn; |
| 104 | + err_sq_node->is_sq = true; |
| 105 | + list_add_tail(&to_xcq(qp->send_cq)->err_state_qp_list, |
| 106 | + &err_sq_node->entry); |
| 107 | + } |
| 108 | + } |
| 109 | + return ret; |
| 110 | +} |
0 commit comments