LCOV - code coverage report
Current view: top level - base_comm/resources/hccp/rdma_agent/inc - ra.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 22 22
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 6 6

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 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              : #ifndef RA_H
      12              : #define RA_H
      13              : 
      14              : #include <dlfcn.h>
      15              : #include <sched.h>
      16              : #include "stdio.h"
      17              : #include "hccp_common.h"
      18              : #ifndef HNS_ROCE_LLT
      19              : #include "dlog_pub.h"
      20              : #endif
      21              : #include "user_log.h"
      22              : #include "ra_rs_comm.h"
      23              : #include "rdma_lite.h"
      24              : 
      25              : #if defined(HNS_ROCE_LLT) || defined(DEFINE_HNS_LLT)
      26              : #define STATIC
      27              : #else
      28              : #define STATIC static
      29              : #endif
      30              : 
      31              : #define RA_MAX_PHY_ID_NUM 64
      32              : 
      33              : #define MAX_SUPPORT_IFNUM 65536
      34              : #define SOCKET_SEND_MAXLEN 2048
      35              : #define MAX_HDC_DATA 65536
      36              : #define MAX_SOCKET_NUM 16
      37              : 
      38              : #define MAX_WLIST_NUM 16
      39              : #define MAX_WLIST_NUM_V1 32
      40              : #define MAX_SG_LIST_LEN_MAX 2147483648
      41              : 
      42              : #define ra_conn_para_check(conn, num) ((num) == 0 || (num) > MAX_SOCKET_NUM)
      43              : 
      44              : #define PROCESS_RA_SIGN_LENGTH 49
      45              : #define PROCESS_RA_RESV_LENGTH 4
      46              : 
      47              : #define MAX_IP_LEN 64
      48              : 
      49              : #define MAX_POLL_CQE_NUM 100
      50              : 
      51              : struct ProcessRaSign {
      52              :     pid_t tgid;
      53              :     char sign[PROCESS_RA_SIGN_LENGTH];
      54              : };
      55              : 
      56              : #define container_of(ptr, type, member)                                                                                \
      57              :     ({                                                                                                                 \
      58              :         const typeof(((type *)0)->member) *__mptr = (ptr);                                                             \
      59              :         (type *)((char *)__mptr - offsetof(type, member));                                                             \
      60              :     })
      61              : 
      62              : #define list_entry(n, type, member) container_of(n, type, member)
      63              : 
      64              : struct RaListHead {
      65              :     struct RaListHead *next, *prev;
      66              : };
      67              : 
      68           21 : static inline void RA_INIT_LIST_HEAD(struct RaListHead *list)
      69              : {
      70           21 :     list->next = list;
      71           21 :     list->prev = list;
      72           21 : }
      73              : 
      74              : #define RA_LIST_GET_HEAD_ENTRY(pos, n, head, member, type)                                                             \
      75              :     do {                                                                                                               \
      76              :         (pos) = list_entry((head)->next, type, member);                                                                \
      77              :         (n) = list_entry((pos)->member.next, type, member);                                                            \
      78              :     } while (0)
      79              : 
      80            4 : static inline bool RaListEmpty(struct RaListHead *head)
      81              : {
      82            4 :     return head->next == head;
      83              : }
      84              : 
      85            4 : static inline void ra_list_add_(struct RaListHead *xnew, struct RaListHead *prev, struct RaListHead *next)
      86              : {
      87            4 :     next->prev = xnew;
      88            4 :     xnew->next = next;
      89            4 :     xnew->prev = prev;
      90            4 :     prev->next = xnew;
      91            4 : }
      92              : 
      93            4 : static inline void RaListAddTail(struct RaListHead *xnew, struct RaListHead *head)
      94              : {
      95            4 :     ra_list_add_(xnew, head->prev, head);
      96            4 : }
      97              : 
      98            5 : static inline void ra_list_del_(struct RaListHead *prev, struct RaListHead *next)
      99              : {
     100            5 :     next->prev = prev;
     101            5 :     prev->next = next;
     102            5 : }
     103              : 
     104            5 : static inline void RaListDel(struct RaListHead *entry)
     105              : {
     106            5 :     ra_list_del_(entry->prev, entry->next);
     107            5 : }
     108              : 
     109              : struct RaBackupInfo {
     110              :     bool backupFlag;
     111              :     struct rdev rdevInfo;
     112              : };
     113              : 
     114              : struct RaCqeErrInfo {
     115              :     pthread_mutex_t mutex;
     116              :     struct CqeErrInfo info;
     117              : };
     118              : 
     119              : enum RdmaLiteThreadStatus {
     120              :     LITE_THREAD_STATUS_DESTROY = 0,
     121              :     LITE_THREAD_STATUS_RUNNING = 1,
     122              :     LITE_THREAD_STATUS_FINISH_RUNNING = 2,
     123              :     LITE_THREAD_STATUS_SUSPEND = 3,
     124              : };
     125              : 
     126              : struct RaRdmaHandle {
     127              :     unsigned int rdevIndex;
     128              :     struct rdev rdevInfo;
     129              :     struct RaBackupInfo backupInfo;
     130              :     struct RaRdmaOps *rdmaOps;
     131              :     int supportLite;
     132              :     struct rdma_lite_context *liteCtx;
     133              :     struct RaListHead qpList;
     134              :     pthread_mutex_t rdevMutex;
     135              :     pthread_mutex_t cqeErrCntMutex;
     136              :     unsigned int cqeErrCnt;
     137              :     pthread_t tid;
     138              :     enum RdmaLiteThreadStatus threadStatus;
     139              :     bool disabledLiteThread;
     140              :     bool enabled910aLite;
     141              :     unsigned int logicDevid;
     142              :     int sensorUpdateCnt;
     143              :     uint64_t sensorHandle;
     144              :     uint64_t qpCnt; // record the number of ra_qp_create_with_attrs function calls
     145              :     bool enabled2mbLite;
     146              :     uint8_t gid[HCCP_GID_RAW_LEN];
     147              :     uint64_t notifyVa;
     148              :     uint64_t notifySize;
     149              :     struct RaListHead typicalLiteCqList;
     150              :     pthread_mutex_t typicalLiteCqMutex;
     151              : };
     152              : 
     153              : struct RaSocketHandle {
     154              :     int scopeId;
     155              :     struct rdev rdevInfo;
     156              :     struct RaSocketOps *socketOps;
     157              :     uint64_t closeCnt;   // record the number of ra_socket_batch_close function calls
     158              :     uint64_t connectCnt; // record the number of ra_socket_batch_connect function calls
     159              :     uint64_t abortCnt;   // record the number of ra_socket_batch_abort function calls
     160              : };
     161              : 
     162              : struct RaLoopbackInfo {
     163              :     struct ibv_cq *ibSendCq;
     164              :     struct ibv_cq *ibRecvCq;
     165              :     void *cqContext;
     166              :     struct ibv_comp_channel *compChannel;
     167              : };
     168              : 
     169              : struct RaCqHandleExt {
     170              :     unsigned long long addr;
     171              :     struct RaRdmaHandle *rdmaHandle;
     172              : };
     173              : 
     174              : struct RaTypicalCqHandle {
     175              :     unsigned int cqn;
     176              :     unsigned int phyId;
     177              :     unsigned int rdevIndex;
     178              :     struct RaRdmaHandle *rdmaHandle;
     179              :     struct RaRdmaOps *rdmaOps;
     180              :     struct rdma_lite_cq *liteCq;
     181              : };
     182              : 
     183              : struct RaQpHandle {
     184              :     unsigned int qpn;
     185              :     int qpMode;
     186              :     int flag;
     187              :     unsigned int phyId;
     188              :     unsigned int rdevIndex;
     189              :     struct RaRdmaOps *rdmaOps; // only ra use
     190              :     int supportLite;
     191              :     struct rdma_lite_cq *sendLiteCq;
     192              :     struct rdma_lite_cq *recvLiteCq;
     193              :     struct rdma_lite_qp *liteQp;
     194              :     unsigned int liteQpState;
     195              :     struct LiteMrInfo localMr[RA_MR_MAX_NUM];
     196              :     struct LiteMrInfo remMr[RA_MR_MAX_NUM];
     197              :     pthread_mutex_t qpMutex;
     198              :     struct RaCqeErrInfo cqeErrInfo;
     199              :     int dbIndex;
     200              :     unsigned int sendWrNum;
     201              :     unsigned int pollCqeNum;
     202              :     unsigned int recvWrNum;
     203              :     unsigned int pollRecvCqeNum;
     204              :     struct RaListHead list;
     205              :     struct RaRdmaHandle *rdmaHandle;
     206              :     struct rdma_lite_wc *liteWc;
     207              :     unsigned int memIdx;
     208              :     int sqSigAll;
     209              :     struct TypicalQpAttr typicalQpAttr;
     210              :     unsigned int psn;
     211              :     unsigned int gidIdx;
     212              :     unsigned int sqDepth; // only valid in RDMA Lite scenario
     213              :     unsigned int bpCnt;   // only valid in RDMA Lite scenario
     214              :     struct RaLoopbackInfo *loopbackInfo;
     215              :     struct RaQpHandle *loopbackQpHandle;
     216              :     int directFlag;
     217              : };
     218              : 
     219              : struct RaMrHandle {
     220              :     uint64_t addr;
     221              : };
     222              : 
     223              : enum GetIfaddrsVersion {
     224              :     GET_IFADDRS_VERSION_1 = 1,
     225              :     GET_IFADDRS_VERSION_2,
     226              :     GET_IFADDRS_VERSION_3,
     227              :     GET_IFADDRS_MAX_VERSION,
     228              : };
     229              : 
     230              : enum RaQpStatus {
     231              :     RA_QP_STATUS_DISCONNECT = 0,
     232              :     RA_QP_STATUS_CONNECTED = 1,
     233              :     RA_QP_STATUS_TIMEOUT = 2,
     234              :     RA_QP_STATUS_CONNECTING = 3,
     235              :     RA_QP_STATUS_REM_FD_CLOSE = 4,
     236              :     RA_QP_STATUS_PAUSE = 5,
     237              : };
     238              : #endif // RA_H
        

Generated by: LCOV version 2.0-1