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[],
21 : unsigned int *num)
22 : {
23 1 : urma_tp_info_t tpList[HCCP_MAX_TPID_INFO_NUM] = {0};
24 1 : urma_get_tp_cfg_t udmaCfg = {0};
25 1 : unsigned int tpCnt = *num;
26 : unsigned int i;
27 1 : int ret = 0;
28 :
29 1 : udmaCfg.flag.value = cfg->flag.value;
30 1 : udmaCfg.trans_mode = (urma_transport_mode_t)cfg->transMode;
31 1 : (void)memcpy_s(udmaCfg.local_eid.raw, sizeof(udmaCfg.local_eid.raw),
32 1 : cfg->localEid.raw, sizeof(cfg->localEid.raw));
33 1 : (void)memcpy_s(udmaCfg.peer_eid.raw, sizeof(udmaCfg.peer_eid.raw), cfg->peerEid.raw, sizeof(cfg->peerEid.raw));
34 :
35 1 : ret = RsUrmaGetTpList(devCb->urmaCtx, &udmaCfg, &tpCnt, tpList);
36 1 : CHK_PRT_RETURN(ret != 0, hccp_err("[rs_ub_ctx]rs_urma_get_tp_list failed, ret[%d] transMode:%u flag:0x%x "
37 : "tpCnt:%u localEid:%016llx:%016llx peerEid:%016llx:%016llx", ret, cfg->transMode, cfg->flag.value, tpCnt,
38 : (unsigned long long)be64toh(cfg->localEid.in6.subnetPrefix),
39 : (unsigned long long)be64toh(cfg->localEid.in6.interfaceId),
40 : (unsigned long long)be64toh(cfg->peerEid.in6.subnetPrefix),
41 : (unsigned long long)be64toh(cfg->peerEid.in6.interfaceId)), -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,
64 : struct TpAttr *attr)
65 : {
66 2 : uint8_t tpAttrCnt = 0;
67 : int ret;
68 :
69 2 : tpAttrCnt = RsGetBitmapCount(*attrBitmap);
70 2 : ret = RsUrmaGetTpAttr(devCb->urmaCtx, tpHandle, &tpAttrCnt, attrBitmap,
71 : (urma_tp_attr_value_t *)attr);
72 2 : CHK_PRT_RETURN(ret != 0, hccp_err("rs_urma_get_tp_attr failed, attrBitmap:%u ret:%d errno:%d",
73 : *attrBitmap, ret, errno), ret);
74 :
75 1 : return ret;
76 : }
77 :
78 2 : int RsUbSetTpAttr(struct RsUbDevCb *devCb, const unsigned int attrBitmap, const uint64_t tpHandle,
79 : struct TpAttr *attr)
80 : {
81 2 : urma_net_addr_t dip = {0};
82 2 : urma_eid_t dEid = {0};
83 2 : uint8_t tpAttrCnt = 0;
84 : int ret;
85 :
86 2 : if ((attrBitmap & TP_ATTR_SIP_MASK) && (attrBitmap & TP_ATTR_SMAC_MASK)) {
87 0 : ret = RsUrmaGetSmac(devCb->urmaCtx, attr->sma);
88 0 : CHK_PRT_RETURN(ret != 0, hccp_err("RsUrmaGetSmac failed, attrBitmap:%u ret:%d errno:%d",
89 : attrBitmap, ret, errno), -EOPENSRC);
90 : }
91 :
92 2 : if ((attrBitmap & TP_ATTR_DIP_MASK) && (attrBitmap & TP_ATTR_DMAC_MASK)) {
93 2 : (void)memcpy_s(&dEid.raw, sizeof(urma_eid_t), attr->dip, sizeof(urma_eid_t));
94 2 : dip.sin_family = AF_INET;
95 2 : dip.in4.s_addr = dEid.in4.addr;
96 2 : ret = RsUrmaGetDmac(devCb->urmaCtx, &dip, attr->dma);
97 2 : CHK_PRT_RETURN(ret != 0, hccp_err("RsUrmaGetDmac failed, attrBitmap:%u ret:%d errno:%d",
98 : attrBitmap, ret, errno), -EOPENSRC);
99 : }
100 :
101 2 : tpAttrCnt = RsGetBitmapCount(attrBitmap);
102 2 : ret = RsUrmaSetTpAttr(devCb->urmaCtx, tpHandle, tpAttrCnt, attrBitmap,
103 : (urma_tp_attr_value_t *)attr);
104 2 : CHK_PRT_RETURN(ret != 0, hccp_err("rs_urma_set_tp_attr failed, attrBitmap:%u ret:%d errno:%d",
105 : attrBitmap, ret, errno), ret);
106 :
107 1 : return ret;
108 : }
|