Line data Source code
1 : /**
2 : * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #include <urma_types.h>
12 : #include "securec.h"
13 : #include "user_log.h"
14 : #include "dl_urma_function.h"
15 : #include "hccp_ctx.h"
16 : #include "ra_rs_err.h"
17 : #include "rs_ctx_inner.h"
18 : #include "rs_ub_tp.h"
19 :
20 1 : int RsUbGetTpInfoList(struct RsUbDevCb *devCb, struct GetTpCfg *cfg, struct HccpTpInfo infoList[], unsigned int *num)
21 : {
22 1 : urma_tp_info_t tpList[HCCP_MAX_TPID_INFO_NUM] = {0};
23 1 : urma_get_tp_cfg_t udmaCfg = {0};
24 1 : unsigned int tpCnt = *num;
25 : unsigned int i;
26 1 : int ret = 0;
27 :
28 1 : udmaCfg.flag.value = cfg->flag.value;
29 1 : udmaCfg.trans_mode = (urma_transport_mode_t)cfg->transMode;
30 1 : (void)memcpy_s(udmaCfg.local_eid.raw, sizeof(udmaCfg.local_eid.raw), cfg->localEid.raw, sizeof(cfg->localEid.raw));
31 1 : (void)memcpy_s(udmaCfg.peer_eid.raw, sizeof(udmaCfg.peer_eid.raw), cfg->peerEid.raw, sizeof(cfg->peerEid.raw));
32 :
33 1 : ret = RsUrmaGetTpList(devCb->urmaCtx, &udmaCfg, &tpCnt, tpList);
34 1 : CHK_PRT_RETURN(ret != 0,
35 : hccp_err("[rs_ub_ctx]rs_urma_get_tp_list failed, ret[%d] transMode:%u flag:0x%x "
36 : "tpCnt:%u localEid:%016llx:%016llx peerEid:%016llx:%016llx",
37 : ret, cfg->transMode, cfg->flag.value, tpCnt, (unsigned long long)be64toh(cfg->localEid.in6.subnetPrefix),
38 : (unsigned long long)be64toh(cfg->localEid.in6.interfaceId),
39 : (unsigned long long)be64toh(cfg->peerEid.in6.subnetPrefix),
40 : (unsigned long long)be64toh(cfg->peerEid.in6.interfaceId)),
41 : -EOPENSRC);
42 :
43 1 : *num = (tpCnt > *num) ? *num : tpCnt;
44 2 : for (i = 0; i < *num; ++i) {
45 1 : infoList[i].tpHandle = tpList[i].tp_handle;
46 : }
47 :
48 1 : return ret;
49 : }
50 :
51 4 : STATIC uint8_t RsGetBitmapCount(unsigned int attrBitmap)
52 : {
53 4 : unsigned int bitmap = attrBitmap;
54 4 : uint8_t bitmapCnt = 0;
55 :
56 16 : while (bitmap != 0) {
57 12 : bitmap &= (bitmap - 1); // clear the last digit 1
58 12 : bitmapCnt++;
59 : }
60 4 : return bitmapCnt;
61 : }
62 :
63 2 : int RsUbGetTpAttr(struct RsUbDevCb *devCb, unsigned int *attrBitmap, const uint64_t tpHandle, struct TpAttr *attr)
64 : {
65 2 : uint8_t tpAttrCnt = 0;
66 : int ret;
67 :
68 2 : tpAttrCnt = RsGetBitmapCount(*attrBitmap);
69 2 : ret = RsUrmaGetTpAttr(devCb->urmaCtx, tpHandle, &tpAttrCnt, attrBitmap, (urma_tp_attr_value_t *)attr);
70 2 : CHK_PRT_RETURN(ret != 0,
71 : hccp_err("rs_urma_get_tp_attr failed, attrBitmap:%u ret:%d errno:%d", *attrBitmap, ret, errno), ret);
72 :
73 1 : return ret;
74 : }
75 :
76 2 : int RsUbSetTpAttr(struct RsUbDevCb *devCb, const unsigned int attrBitmap, const uint64_t tpHandle, struct TpAttr *attr)
77 : {
78 2 : urma_net_addr_t dip = {0};
79 2 : urma_eid_t dEid = {0};
80 2 : uint8_t tpAttrCnt = 0;
81 : int ret;
82 :
83 2 : if ((attrBitmap & TP_ATTR_SIP_MASK) && (attrBitmap & TP_ATTR_SMAC_MASK)) {
84 0 : ret = RsUrmaGetSmac(devCb->urmaCtx, attr->sma);
85 0 : CHK_PRT_RETURN(ret != 0,
86 : hccp_err("RsUrmaGetSmac failed, attrBitmap:%u ret:%d errno:%d", attrBitmap, ret, errno), -EOPENSRC);
87 : }
88 :
89 2 : if ((attrBitmap & TP_ATTR_DIP_MASK) && (attrBitmap & TP_ATTR_DMAC_MASK)) {
90 2 : (void)memcpy_s(&dEid.raw, sizeof(urma_eid_t), attr->dip, sizeof(urma_eid_t));
91 2 : dip.sin_family = AF_INET;
92 2 : dip.in4.s_addr = dEid.in4.addr;
93 2 : ret = RsUrmaGetDmac(devCb->urmaCtx, &dip, attr->dma);
94 2 : CHK_PRT_RETURN(ret != 0,
95 : hccp_err("RsUrmaGetDmac failed, attrBitmap:%u ret:%d errno:%d", attrBitmap, ret, errno), -EOPENSRC);
96 : }
97 :
98 2 : tpAttrCnt = RsGetBitmapCount(attrBitmap);
99 2 : ret = RsUrmaSetTpAttr(devCb->urmaCtx, tpHandle, tpAttrCnt, attrBitmap, (urma_tp_attr_value_t *)attr);
100 2 : CHK_PRT_RETURN(ret != 0,
101 : hccp_err("rs_urma_set_tp_attr failed, attrBitmap:%u ret:%d errno:%d", attrBitmap, ret, errno), ret);
102 :
103 1 : return ret;
104 : }
|