1 /*
2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 * Description: HCC TEST
15 * Author:
16 */
17
18 #ifndef HCC_TEST_HEADER
19 #define HCC_TEST_HEADER
20
21 #include "td_type.h"
22 #include "hcc_cfg_comm.h"
23 #ifndef CONFIG_HCC_SUPPORT_NON_OS
24 #include "soc_osal.h"
25 #endif
26
27 #define HCC_TEST_ARGC_MAX 5
28 #define HCC_TEST_REMOTE_CMD_ARGC_LEN 4 /* argc 1Byte + reserve 2Bytes */
29 #define HCC_TEST_SUBTYPE_DATA 0 /* test业务子类型:测试数据 */
30 #define HCC_TEST_SUBTYPE_COMMAND 5 /* test业务子类型:测试命令 */
31 #define HCC_TEST_CMD_STR "hcc_test_cmd"
32
33 typedef struct _hcc_test_result_ {
34 td_u32 trans_rate; /* 测试速率, 单位:Mbps */
35 td_u32 trans_bits; /* 测试传输总bit */
36 td_u64 trans_time; /* 测试耗时, 单位:us */
37 } hcc_test_result;
38
39 typedef struct _hcc_test_para_ {
40 td_u32 loop_cnt;
41 td_u32 expect_rx_cnt;
42 td_u32 test_data;
43 td_u16 frame_size;
44 td_u8 channel_id;
45 td_u8 test_service;
46 td_u8 master_to_slave;
47 hcc_queue_type test_queue_id;
48 } hcc_test_para;
49
50 typedef struct _hcc_test_stat_ {
51 td_bool test_stop; /* 开始进行流控,测试停止 */
52 } hcc_test_stat;
53
54 #define HCC_TEST_TASK_STOP 0
55 #define HCC_TEST_TASK_START 1
56 typedef struct _hcc_test_info_ {
57 /* reference to hcc test task */
58 #ifndef CONFIG_HCC_SUPPORT_NON_OS
59 osal_atomic hcc_test_start;
60 osal_wait hcc_test_wq;
61 osal_task *hcc_test_thread_handler;
62 #endif
63 hcc_test_para test_para;
64 hcc_test_stat test_stat;
65 hcc_test_result test_data;
66 td_u64 start_time;
67 td_u64 stop_time;
68 } hcc_test_info;
69
70 typedef struct _hcc_test_cmd_args_ {
71 td_u32 argv[HCC_TEST_ARGC_MAX];
72 td_u8 argc;
73 } hcc_test_cmd_args;
74
75 typedef enum {
76 HCC_TEST_CMD_TEST_INIT = 0, /* 测试模块初始化 */
77 HCC_TEST_CMD_INIT_ALL_PARAM_AND_START_TEST = 1, /* 设置收发必须的参数后启动测试,参数同HCC_TEST_CMD_INIT_ALL_PARAM */
78 HCC_TEST_CMD_TEST_MSG = 2, /* 发送 message */
79 HCC_TEST_CMD_SET_QUEUE = 3, /* 设置模式 */
80 HCC_TEST_CMD_SET_TX_CHANNEL = 4, /* 设置测试发送的逻辑通道 */
81 HCC_TEST_CMD_TEST_REG_OPT = 5, /* 测试寄存器读写接口 */
82 HCC_TEST_CMD_START_TEST = 6, /* 开始测试 */
83 HCC_TEST_CMD_INIT_ALL_PARAM = 7, /* 初始化所有测试参数,顺序依次为: 发送次数、帧长度、期望接收数量 */
84 HCC_TEST_CMD_PRINT_RESULT = 8, /* 打印测试统计量 */
85 HCC_TEST_CMD_M2S = 9, /* test host to slave */
86
87 HCC_TEST_CMD_ENABLE_TX_THREAD = 10, /* 发送使能/禁能线程 */
88 HCC_TEST_CMD_ENABLE_RX_THREAD = 11, /* 接收使能/禁能线程 */
89 HCC_TEST_UPDATE_CREDIT = 12,
90 HCC_TEST_GET_CREDIT = 13,
91 HCC_TEST_CMD_SET_TX_DATA = 14, /* 设置测试发送的数据内容 */
92 HCC_TEST_CMD_SET_REG_ADDR = 15, /* 设置寄存器地址 */
93 HCC_TEST_CMD_SET_MODE = 16, /* 设置模式 */
94
95 HCC_TEST_PRINT_QUEUE_INFO = 20, /* 队列信息打印 */
96 HCC_TEST_PRINT_SERVICE_INFO = 21, /* 业务信息打印 */
97 HCC_TEST_PRINT_BUS_INFO = 22, /* bus层维测信息打印 */
98 HCC_TEST_CMD_REMOTE = 31, /* 发给远端处理 */
99 HCC_TEST_CMD_MAX = 32
100 } hcc_test_cmd;
101
102 /********************** TEST SERVICE *****************************/
103 td_void hcc_test_init(td_void);
104 td_void hcc_test_deinit(td_void);
105 td_void hcc_test(td_void);
106 td_void hcc_adapt_test_free(hcc_queue_type queue_id, td_u8 *buf, td_u8 *user_param);
107
108 /********************** TEST *****************************/
109 td_s32 hcc_test_proc_local_cmd(td_u32 *argv, td_u32 argc);
110 td_void hcc_test_start_test_after_init_paras(td_void);
111 td_void hcc_test_print_test_result(td_void);
112
113 hcc_test_info *hcc_test_get_test_info(td_void);
114
115 td_void hcc_test_set_trans_rate(td_u32 rate);
116 td_void hcc_test_set_trans_time_us(td_u64 us);
117 td_u32 hcc_test_get_exp_rx_cnt(td_void);
118 td_u64 hcc_test_get_start_time(td_void);
119 td_void hcc_test_set_start_time(td_u64 us);
120 td_u64 hcc_test_get_stop_time(td_void);
121 td_void hcc_test_set_stop_time(td_u64 us);
122 td_u64 hcc_test_get_trans_time_us(td_void);
123 td_u32 hcc_test_get_trans_rate(td_void);
124 td_u32 hcc_test_get_trans_bits(td_void);
125 td_void hcc_test_set_trans_bits(td_u32 bits);
126 td_bool hcc_test_get_m2s_status(td_void);
127 td_u32 hcc_test_get_loop_cnt(td_void);
128 td_u16 hcc_test_get_frame_size(td_void);
129 td_u32 hcc_test_get_test_service(td_void);
130 td_bool hcc_test_is_test_stop(td_void);
131 td_void hcc_test_set_test_stop(td_bool stop);
132 hcc_queue_type hcc_test_get_test_queue_id(td_void);
133 td_void hcc_test_set_test_queue_id(td_u32 queue_id);
134 td_u32 hcc_test_get_test_data(td_void);
135 td_u8 hcc_test_get_test_chan(td_void);
136 /********************** TEST host device *****************************/
137 td_void hcc_test_get_credit(td_void);
138 td_void hcc_test_msg_init(td_void);
139 td_void hcc_test_register_opt(td_u32 cmd);
140 td_void hcc_test_set_register_addr(td_u32 addr, td_u32 offset, td_u32 value);
141 td_void hcc_test_reset_rx_stat(td_void);
142 td_void hcc_test_print_test_result(td_void);
143 td_u32 hcc_test_rx_proc(hcc_queue_type queue_id, td_u8 sub_type, td_u8 *buf, td_u32 len, td_u8 *user_param);
144 td_void hcc_test_start(td_void);
145 td_void hcc_test_start_test_after_init_paras(td_void);
146 int hcc_test_cmd_proc(int argc, char *argv[]);
147 td_s32 hcc_test_proc_remote_cmd(td_u32 *argv, td_u32 argc);
148 td_s32 hcc_test_cmd_ctrl_init(void);
149
hcc_get_timestamp(td_void)150 static inline td_u64 hcc_get_timestamp(td_void)
151 {
152 #ifndef CONFIG_HCC_SUPPORT_NON_OS
153 osal_timeval tv;
154 osal_gettimeofday(&tv);
155 return (td_u64)(tv.tv_sec * 1000000 + tv.tv_usec); /* ms转化 us * 1000000 */
156 #else
157 return 0;
158 #endif
159 }
160
161 typedef td_s32 (*hcc_test_proc)(td_u32 *argv, td_u32 argc);
162 td_void hcc_test_cmd_register(hcc_test_proc test_proc);
163 #endif /* HCC_TEST_HEADER */
164