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 "securec.h"
12 : #include "ra_rs_err.h"
13 : #include "rs_inner.h"
14 : #include "dl_hal_function.h"
15 :
16 31 : int RsSensorNodeRegister(unsigned int phyId, struct rs_cb *rsCb)
17 : {
18 31 : struct halSensorNodeCfg cfg = {0};
19 : int ret;
20 :
21 31 : if (rsCb->sensorNode.sensorHandle != 0) {
22 0 : return 0;
23 : }
24 :
25 : // some non-hdc scenarios don't have corresponding API, skip to register sensor node
26 31 : if (rsCb->hccpMode != NETWORK_OFFLINE) {
27 6 : return 0;
28 : }
29 :
30 25 : ret = rsGetLocalDevIDByHostDevID(phyId, &rsCb->sensorNode.logicDevid);
31 25 : if (ret) {
32 0 : hccp_err("[init][rs_rdev]rsGetLocalDevIDByHostDevID failed, phyId(%u), ret(%d)", phyId, ret);
33 0 : return ret;
34 : }
35 :
36 25 : ret = sprintf_s(cfg.name, sizeof(cfg.name), "roce_rs_%d", getpid());
37 25 : if (ret <= 0) {
38 0 : hccp_err("[init][rs_rdev]sprintf_s name err, ret:%d, phyId:%u", ret, phyId);
39 0 : return -ESAFEFUNC;
40 : }
41 :
42 25 : cfg.NodeType = HAL_DMS_DEV_TYPE_HCCP;
43 25 : cfg.SensorType = RDMA_CQE_ERR_SENSOR_TYPE;
44 25 : cfg.AssertEventMask = RDMA_CQE_ERR_RETRY_TIMEOUT_EVENT_MASK;
45 25 : cfg.DeassertEventMask = RDMA_CQE_ERR_RETRY_TIMEOUT_EVENT_TYPE_MASK;
46 25 : ret = DlHalSensorNodeRegister(rsCb->sensorNode.logicDevid, &cfg, &rsCb->sensorNode.sensorHandle);
47 25 : if (ret != 0) {
48 0 : hccp_err("[init][rs_rdev]dl_hal_sensor_node_register failed, phyId(%u), logicDevid(%u), ret(%d)", phyId,
49 : rsCb->sensorNode.logicDevid, ret);
50 0 : return ret;
51 : }
52 :
53 25 : return 0;
54 : }
55 :
56 31 : void RsSensorNodeUnregister(struct rs_cb *rsCb)
57 : {
58 : // no need to unregister sensor node
59 31 : if (rsCb->sensorNode.sensorHandle == 0) {
60 6 : return;
61 : }
62 :
63 25 : RS_PTHREAD_MUTEX_LOCK(&rsCb->mutex);
64 25 : if (RsListEmpty(&rsCb->rdevList)) {
65 25 : (void)DlHalSensorNodeUnregister(rsCb->sensorNode.logicDevid, rsCb->sensorNode.sensorHandle);
66 25 : rsCb->sensorNode.sensorUpdateCnt = 0;
67 25 : rsCb->sensorNode.sensorHandle = 0;
68 : }
69 25 : RS_PTHREAD_MUTEX_ULOCK(&rsCb->mutex);
70 : }
|