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 : #include "aicpusd_sqe_adapter.h"
11 : #include "aicpusd_msg_send.h"
12 : #include "aicpusd_message_queue.h"
13 :
14 : namespace AicpuSchedule {
15 73 : AicpuSqeAdapter::AicpuSqeAdapter(const TsAicpuSqe& sqe, const int16_t version)
16 73 : : pid_(sqe.pid),
17 73 : cmd_type_(sqe.cmd_type),
18 73 : vf_id_(sqe.vf_id),
19 73 : tid_(sqe.tid),
20 73 : ts_id_(sqe.ts_id),
21 73 : sqe_(sqe),
22 73 : version_(version),
23 73 : invalid_sqe_(false)
24 : {
25 73 : aicpusd_info(
26 : "Enter AicpuSqeAdapter constructor, using TsAicpuSqe init, pid[%u], cmd_type[%u], vf id[%u],"
27 : "tid[%u], ts id[%u], version[%hu]",
28 : pid_, cmd_type_, vf_id_, tid_, ts_id_, version_);
29 73 : InitAdapterFuncMap();
30 73 : }
31 :
32 30 : AicpuSqeAdapter::AicpuSqeAdapter(const TsAicpuMsgInfo& msgInfo, const int16_t version)
33 30 : : pid_(msgInfo.pid),
34 30 : cmd_type_(msgInfo.cmd_type),
35 30 : vf_id_(msgInfo.vf_id),
36 30 : tid_(msgInfo.tid),
37 30 : ts_id_(msgInfo.ts_id),
38 30 : msg_Info_(msgInfo),
39 30 : version_(version),
40 30 : invalid_msg_info_(false)
41 : {
42 30 : aicpusd_info(
43 : "Enter AicpuSqeAdapter constructor, using TsAicpuMsgInfo init, pid[%u], cmd_type[%u], vf id[%u],"
44 : "tid[%u], ts id[%u], version[%hu]",
45 : pid_, cmd_type_, vf_id_, tid_, ts_id_, version_);
46 30 : InitAdapterFuncMap();
47 30 : }
48 :
49 97 : AicpuSqeAdapter::AicpuSqeAdapter(const int16_t version) : version_(version), invalid_msg_info_(true), invalid_sqe_(true)
50 : {
51 97 : aicpusd_info("Enter AicpuSqeAdapter constructor, using version init, version[%hu]", version_);
52 97 : InitAdapterFuncMap();
53 97 : }
54 :
55 62 : uint8_t AicpuSqeAdapter::GetCmdType() const { return cmd_type_; }
56 :
57 114 : bool AicpuSqeAdapter::IsAdapterInvalidParameter() const { return invalid_sqe_ && invalid_msg_info_; }
58 :
59 40 : bool AicpuSqeAdapter::IsOpMappingDumpTaskInfoVaild(const AicpuOpMappingDumpTaskInfo& info) const
60 : {
61 40 : if (version_ == VERSION_0) {
62 66 : bool isOutOfRange = (info.proto_info_task_id > INVALID_VALUE16) ||
63 66 : (info.proto_info_stream_id > INVALID_VALUE16) || (info.stream_id > INVALID_VALUE16) ||
64 32 : (info.task_id > INVALID_VALUE16);
65 34 : return !isOutOfRange;
66 : }
67 6 : return true;
68 : }
69 :
70 200 : void AicpuSqeAdapter::InitAdapterFuncMap()
71 : {
72 200 : getModelOperateInfoFuncMap_[VERSION_0] = &AicpuSqeAdapter::GetAicpuModelOperateInfoV0;
73 200 : getModelOperateInfoFuncMap_[VERSION_1] = &AicpuSqeAdapter::GetAicpuModelOperateInfoV1;
74 :
75 200 : getModelOperateRspFuncMap_[VERSION_0] = &AicpuSqeAdapter::AicpuModelOperateResponseToTsV0;
76 200 : getModelOperateRspFuncMap_[VERSION_1] = &AicpuSqeAdapter::AicpuModelOperateResponseToTsV1;
77 :
78 200 : getDataDumpInfoFuncMap_[VERSION_0] = &AicpuSqeAdapter::GetAicpuDataDumpInfoV0;
79 200 : getDataDumpInfoFuncMap_[VERSION_1] = &AicpuSqeAdapter::GetAicpuDataDumpInfoV1;
80 :
81 200 : getDataDumpRspFuncMap_[VERSION_0] = &AicpuSqeAdapter::AicpuDumpResponseToTsV0;
82 200 : getDataDumpRspFuncMap_[VERSION_1] = &AicpuSqeAdapter::AicpuDumpResponseToTsV1;
83 :
84 200 : getDataDumpLoadInfoFuncMap_[VERSION_0] = &AicpuSqeAdapter::GetAicpuDataDumpInfoLoadV0;
85 200 : getDataDumpLoadInfoFuncMap_[VERSION_1] = &AicpuSqeAdapter::GetAicpuDataDumpInfoLoadV1;
86 :
87 200 : getDataDumpLoadRspFuncMap_[VERSION_0] = &AicpuSqeAdapter::AicpuDataDumpLoadResponseToTsV0;
88 200 : getDataDumpLoadRspFuncMap_[VERSION_1] = &AicpuSqeAdapter::AicpuDataDumpLoadResponseToTsV1;
89 :
90 200 : getTaskReportInfoFuncMap_[VERSION_0] = &AicpuSqeAdapter::GetAicpuTaskReportInfoV0;
91 200 : getTaskReportInfoFuncMap_[VERSION_1] = &AicpuSqeAdapter::GetAicpuTaskReportInfoV1;
92 :
93 200 : getErrorMsgRspFuncMap_[VERSION_0] = &AicpuSqeAdapter::ErrorMsgResponseToTsV0;
94 200 : getErrorMsgRspFuncMap_[VERSION_1] = &AicpuSqeAdapter::ErrorMsgResponseToTsV1;
95 :
96 200 : getTimeOutConfigRspFuncMap_[VERSION_0] = &AicpuSqeAdapter::AicpuTimeOutConfigResponseToTsV0;
97 200 : getTimeOutConfigRspFuncMap_[VERSION_1] = &AicpuSqeAdapter::AicpuTimeOutConfigResponseToTsV1;
98 :
99 200 : getLoadInfoFuncMap_[VERSION_0] = &AicpuSqeAdapter::GetAicpuInfoLoadV0;
100 200 : getLoadInfoFuncMap_[VERSION_1] = &AicpuSqeAdapter::GetAicpuInfoLoadV1;
101 :
102 200 : getInfoLoadRspFuncMap_[VERSION_0] = &AicpuSqeAdapter::AicpuInfoLoadResponseToTsV0;
103 200 : getInfoLoadRspFuncMap_[VERSION_1] = &AicpuSqeAdapter::AicpuInfoLoadResponseToTsV1;
104 :
105 200 : getDumpTaskInfoFuncMap_[VERSION_0] = &AicpuSqeAdapter::GetAicpuDumpTaskInfoV0;
106 200 : getDumpTaskInfoFuncMap_[VERSION_1] = &AicpuSqeAdapter::GetAicpuDumpTaskInfoV1;
107 :
108 200 : getRecordRspFuncMap_[VERSION_0] = &AicpuSqeAdapter::AicpuRecordResponseToTsV0;
109 200 : getRecordRspFuncMap_[VERSION_1] = &AicpuSqeAdapter::AicpuRecordResponseToTsV1;
110 :
111 200 : activeStreamSetMsgFuncMap_[VERSION_0] = &AicpuSqeAdapter::AicpuActiveStreamSetMsgV0;
112 200 : activeStreamSetMsgFuncMap_[VERSION_1] = &AicpuSqeAdapter::AicpuActiveStreamSetMsgV1;
113 :
114 200 : getAicErrReportInfoFuncMap_[VERSION_0] = &AicpuSqeAdapter::GetAicErrReportInfoV0;
115 200 : getAicErrReportInfoFuncMap_[VERSION_1] = &AicpuSqeAdapter::GetAicErrReportInfoV1;
116 200 : }
117 :
118 4 : void AicpuSqeAdapter::GetAicpuMsgVersionInfo(AicpuMsgVersionInfo& info)
119 : {
120 4 : TsAicpuMsgVersion tmpInfo = sqe_.u.aicpu_msg_version;
121 4 : aicpusd_info("Get msg version msg: magic num[%u], version[%hu].", tmpInfo.magic_num, tmpInfo.version);
122 4 : info.magic_num = tmpInfo.magic_num;
123 4 : info.version = tmpInfo.version;
124 4 : }
125 :
126 3 : int32_t AicpuSqeAdapter::AicpuMsgVersionResponseToTs(const int32_t ret)
127 : {
128 3 : TsAicpuMsgInfo msgInfo{};
129 3 : msgInfo.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
130 3 : msgInfo.vf_id = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
131 3 : msgInfo.tid = tid_;
132 3 : msgInfo.ts_id = ts_id_;
133 3 : msgInfo.cmd_type = cmd_type_;
134 3 : msgInfo.u.aicpu_resp.result_code = static_cast<uint16_t>(ret);
135 3 : msgInfo.u.aicpu_resp.task_id = INVALID_VALUE32;
136 3 : aicpusd_info(
137 : "Msg version response info: cmd_type[%u], ret code[%u], stream id[%u], task id[%u].", msgInfo.cmd_type,
138 : msgInfo.u.aicpu_resp.result_code, msgInfo.u.aicpu_resp.stream_id, msgInfo.u.aicpu_resp.task_id);
139 6 : return ResponseToTs(msgInfo, 0U, AicpuDrvManager::GetInstance().GetDeviceId(), msgInfo.ts_id);
140 : }
141 :
142 11 : void AicpuSqeAdapter::GetAicpuModelOperateInfo(AicpuModelOperateInfo& info)
143 : {
144 11 : if (getModelOperateInfoFuncMap_.find(version_) == getModelOperateInfoFuncMap_.end()) {
145 1 : aicpusd_err("The version[%hu] does not have a corresponding get model operate info Function.", version_);
146 1 : return;
147 : }
148 10 : (this->*getModelOperateInfoFuncMap_[version_])(info);
149 10 : return;
150 : }
151 :
152 5 : void AicpuSqeAdapter::GetAicpuModelOperateInfoV0(AicpuModelOperateInfo& info)
153 : {
154 5 : TsAicpuModelOperate tmpInfo = sqe_.u.aicpu_model_operate;
155 5 : aicpusd_info(
156 : "Aicpu model operator info: arg_ptr[%p], cmd_type[%u], model_id[%u], task_id[%u].", tmpInfo.arg_ptr,
157 : tmpInfo.cmd_type, tmpInfo.model_id, tmpInfo.task_id);
158 5 : info.arg_ptr = tmpInfo.arg_ptr;
159 5 : info.cmd_type = tmpInfo.cmd_type;
160 5 : info.model_id = tmpInfo.model_id;
161 5 : info.stream_id = tmpInfo.sq_id; // sq_id in rts acturally is stream id
162 5 : info.task_id = tmpInfo.task_id;
163 5 : info.reserved[0] = tmpInfo.reserved;
164 10 : return;
165 : }
166 :
167 5 : void AicpuSqeAdapter::GetAicpuModelOperateInfoV1(AicpuModelOperateInfo& info)
168 : {
169 5 : TsAicpuModelOperateMsg tmpInfo = msg_Info_.u.aicpu_model_operate;
170 5 : aicpusd_info(
171 : "Aicpu model operator info: arg_ptr[%p], cmd_type[%u], model_id[%u].", tmpInfo.arg_ptr, tmpInfo.cmd_type,
172 : tmpInfo.model_id);
173 5 : info.arg_ptr = tmpInfo.arg_ptr;
174 5 : info.cmd_type = tmpInfo.cmd_type;
175 5 : info.model_id = tmpInfo.model_id;
176 5 : info.stream_id = tmpInfo.stream_id;
177 5 : info.task_id = INVALID_VALUE16;
178 5 : info.reserved[0] = tmpInfo.reserved[0];
179 10 : return;
180 : }
181 :
182 7 : int32_t AicpuSqeAdapter::AicpuModelOperateResponseToTs(const int32_t ret, const uint32_t subEvent)
183 : {
184 7 : if (getModelOperateRspFuncMap_.find(version_) == getModelOperateRspFuncMap_.end()) {
185 1 : aicpusd_err("The version[%hu] does not have a corresponding get model operate response function.", version_);
186 1 : return AICPU_SCHEDULE_ERROR_NOT_FOUND_FUNCTION;
187 : }
188 6 : return (this->*getModelOperateRspFuncMap_[version_])(ret, subEvent);
189 : }
190 :
191 3 : int32_t AicpuSqeAdapter::AicpuModelOperateResponseToTsV0(const int32_t ret, const uint32_t subEvent)
192 : {
193 3 : TsAicpuModelOperate tmpInfo = sqe_.u.aicpu_model_operate;
194 3 : TsAicpuSqe aicpuSqe = {};
195 3 : aicpuSqe.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
196 3 : aicpuSqe.cmd_type = AICPU_MODEL_OPERATE_RESPONSE;
197 3 : aicpuSqe.vf_id = vf_id_;
198 3 : aicpuSqe.tid = tid_;
199 3 : aicpuSqe.ts_id = ts_id_;
200 3 : aicpuSqe.u.aicpu_model_operate_resp.cmd_type = AICPU_MODEL_OPERATE;
201 3 : aicpuSqe.u.aicpu_model_operate_resp.sub_cmd_type = tmpInfo.cmd_type;
202 3 : aicpuSqe.u.aicpu_model_operate_resp.model_id = tmpInfo.model_id;
203 3 : aicpuSqe.u.aicpu_model_operate_resp.result_code = static_cast<uint16_t>(ret);
204 3 : aicpuSqe.u.aicpu_model_operate_resp.task_id = tmpInfo.task_id;
205 3 : aicpuSqe.u.aicpu_model_operate_resp.sq_id = tmpInfo.sq_id;
206 3 : aicpusd_info("Aicpu model operate response info: cmd_type[%u], ret[%u]", cmd_type_, ret);
207 3 : hwts_response_t hwtsResp = {};
208 3 : hwtsResp.result = static_cast<uint32_t>(ret);
209 3 : hwtsResp.status = (ret == AICPU_SCHEDULE_OK) ? static_cast<uint32_t>(TASK_SUCC) : static_cast<uint32_t>(TASK_FAIL);
210 3 : hwtsResp.msg = PtrToPtr<TsAicpuSqe, char_t>(&aicpuSqe);
211 3 : hwtsResp.len = static_cast<int32_t>(sizeof(TsAicpuSqe));
212 6 : return ResponseToTs(hwtsResp, AicpuDrvManager::GetInstance().GetDeviceId(), EVENT_TS_CTRL_MSG, subEvent);
213 : }
214 :
215 3 : int32_t AicpuSqeAdapter::AicpuModelOperateResponseToTsV1(const int32_t ret, const uint32_t subEvent)
216 : {
217 3 : TsAicpuMsgInfo aicpuMsgInfo = {};
218 3 : aicpuMsgInfo.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
219 3 : aicpuMsgInfo.cmd_type = cmd_type_;
220 3 : aicpuMsgInfo.vf_id = vf_id_;
221 3 : aicpuMsgInfo.tid = tid_;
222 3 : aicpuMsgInfo.ts_id = ts_id_;
223 3 : aicpuMsgInfo.u.aicpu_resp.result_code = static_cast<uint16_t>(ret);
224 3 : aicpuMsgInfo.u.aicpu_resp.stream_id = INVALID_VALUE16;
225 3 : aicpuMsgInfo.u.aicpu_resp.task_id = INVALID_VALUE32;
226 3 : aicpuMsgInfo.u.aicpu_resp.reserved = 0;
227 3 : aicpusd_info(
228 : "Aicpu model operate response info: cmd_type[%u], ret[%u], stream_id[%u], task_id[%u]", cmd_type_, ret,
229 : aicpuMsgInfo.u.aicpu_resp.stream_id, aicpuMsgInfo.u.aicpu_resp.task_id);
230 3 : hwts_response_t hwtsResp = {};
231 3 : hwtsResp.result = static_cast<uint32_t>(ret);
232 3 : hwtsResp.status = (ret == AICPU_SCHEDULE_OK) ? static_cast<uint32_t>(TASK_SUCC) : static_cast<uint32_t>(TASK_FAIL);
233 3 : hwtsResp.msg = PtrToPtr<TsAicpuMsgInfo, char_t>(&aicpuMsgInfo);
234 3 : hwtsResp.len = static_cast<int32_t>(sizeof(TsAicpuMsgInfo));
235 6 : return ResponseToTs(hwtsResp, AicpuDrvManager::GetInstance().GetDeviceId(), EVENT_TS_CTRL_MSG, subEvent);
236 : }
237 :
238 8 : void AicpuSqeAdapter::GetAicpuTaskReportInfoV0(AicpuTaskReportInfo& info)
239 : {
240 8 : TsToAicpuTaskReport tmpInfo = sqe_.u.ts_to_aicpu_task_report;
241 8 : aicpusd_info(
242 : "Get aicpu task report info: task_id[%u], model_id[%u], result_code[%u], stream_id[%u]", tmpInfo.task_id,
243 : tmpInfo.model_id, tmpInfo.result_code, tmpInfo.stream_id);
244 8 : info.task_id = tmpInfo.task_id;
245 8 : info.model_id = tmpInfo.model_id;
246 8 : info.result_code = tmpInfo.result_code;
247 8 : info.stream_id = tmpInfo.stream_id;
248 8 : }
249 :
250 2 : void AicpuSqeAdapter::GetAicpuTaskReportInfoV1(AicpuTaskReportInfo& info)
251 : {
252 2 : TsToAicpuTaskReportMsg tmpInfo = msg_Info_.u.ts_to_aicpu_task_report;
253 2 : aicpusd_info(
254 : "Get aicpu task report info: task_id[%u], model_id[%u], result_code[%u], stream_id[%u]", tmpInfo.task_id,
255 : tmpInfo.model_id, tmpInfo.result_code, tmpInfo.stream_id);
256 2 : info.task_id = tmpInfo.task_id;
257 2 : info.model_id = tmpInfo.model_id;
258 2 : info.result_code = tmpInfo.result_code;
259 2 : info.stream_id = tmpInfo.stream_id;
260 2 : }
261 :
262 11 : void AicpuSqeAdapter::GetAicpuTaskReportInfo(AicpuTaskReportInfo& info)
263 : {
264 11 : if (getTaskReportInfoFuncMap_.find(version_) == getTaskReportInfoFuncMap_.end()) {
265 1 : aicpusd_err("The version[%hu] does not have a corresponding get task report function.", version_);
266 1 : return;
267 : }
268 10 : (this->*getTaskReportInfoFuncMap_[version_])(info);
269 10 : return;
270 : }
271 :
272 54 : void AicpuSqeAdapter::GetAicpuDumpTaskInfoV0(AicpuOpMappingDumpTaskInfo& opmappingInfo, AicpuDumpTaskInfo& dumpTaskInfo)
273 : {
274 54 : opmappingInfo.proto_info_task_id &= 0xFFFF;
275 54 : aicpusd_info(
276 : "Dump data from proto: task id[%u], stream id[%u], form adaper: task id[%u], stream id[%u]",
277 : opmappingInfo.proto_info_task_id, opmappingInfo.proto_info_stream_id, opmappingInfo.task_id,
278 : opmappingInfo.stream_id);
279 54 : dumpTaskInfo.task_id =
280 54 : opmappingInfo.proto_info_task_id == INVALID_VALUE16 ? opmappingInfo.task_id : opmappingInfo.proto_info_task_id;
281 54 : dumpTaskInfo.stream_id = opmappingInfo.proto_info_stream_id == INVALID_VALUE16 ? opmappingInfo.stream_id :
282 : opmappingInfo.proto_info_stream_id;
283 54 : dumpTaskInfo.context_id = INVALID_VALUE16;
284 54 : dumpTaskInfo.thread_id = INVALID_VALUE16;
285 54 : }
286 :
287 6 : void AicpuSqeAdapter::GetAicpuDumpTaskInfoV1(AicpuOpMappingDumpTaskInfo& opmappingInfo, AicpuDumpTaskInfo& dumpTaskInfo)
288 : {
289 6 : aicpusd_info(
290 : "Dump data from proto: task id[%u], stream id[%u], form adaper: task id[%u], stream id[%u]",
291 : opmappingInfo.proto_info_task_id, opmappingInfo.proto_info_stream_id, opmappingInfo.task_id,
292 : opmappingInfo.stream_id);
293 6 : dumpTaskInfo.task_id = opmappingInfo.proto_info_task_id;
294 6 : dumpTaskInfo.stream_id = INVALID_VALUE16;
295 6 : dumpTaskInfo.context_id = INVALID_VALUE16;
296 6 : dumpTaskInfo.thread_id = INVALID_VALUE16;
297 6 : }
298 :
299 61 : void AicpuSqeAdapter::GetAicpuDumpTaskInfo(AicpuOpMappingDumpTaskInfo& opmappingInfo, AicpuDumpTaskInfo& dumpTaskInfo)
300 : {
301 61 : if (getDumpTaskInfoFuncMap_.find(version_) == getDumpTaskInfoFuncMap_.end()) {
302 1 : aicpusd_err("The version[%hu] does not have a corresponding get dump task info function.", version_);
303 1 : return;
304 : }
305 60 : (this->*getDumpTaskInfoFuncMap_[version_])(opmappingInfo, dumpTaskInfo);
306 : }
307 :
308 10 : void AicpuSqeAdapter::GetAicpuDataDumpInfoV1(AicpuDataDumpInfo& info)
309 : {
310 10 : switch (cmd_type_) {
311 2 : case TS_AICPU_DEBUG_DATADUMP_REPORT: {
312 2 : TsToAicpuDebugDataDumpMsg tmpInfo = msg_Info_.u.ts_to_aicpu_debug_datadump;
313 2 : aicpusd_info(
314 : "Debug data dump info : dump_task_id[%u], debug_dump_task_id[%u], dump_stream_id[%u],"
315 : "is_model[%u], dumptype[%u], reserved[%u].",
316 : tmpInfo.dump_task_id, tmpInfo.debug_dump_task_id, tmpInfo.dump_stream_id, tmpInfo.is_model,
317 : tmpInfo.dump_type, tmpInfo.rsv);
318 2 : info.is_debug = true;
319 2 : info.dump_task_id = tmpInfo.dump_task_id;
320 2 : info.dump_stream_id = INVALID_VALUE16;
321 2 : info.debug_dump_task_id = tmpInfo.debug_dump_task_id;
322 2 : info.debug_dump_stream_id = INVALID_VALUE16;
323 2 : info.is_model = (tmpInfo.is_model == 1);
324 2 : break;
325 : }
326 7 : case TS_AICPU_NORMAL_DATADUMP_REPORT: {
327 7 : TsToAicpuNormalDataDumpMsg tmpInfo = msg_Info_.u.ts_to_aicpu_normal_datadump;
328 7 : aicpusd_info(
329 : "Data dump info : dump_task_id[%u], dump_stream_id[%u],"
330 : "is_model[%u], dumptype[%u], reserved[%u].",
331 : tmpInfo.dump_task_id, tmpInfo.dump_stream_id, tmpInfo.is_model, tmpInfo.dump_type, tmpInfo.rsv);
332 7 : info.is_debug = false;
333 7 : info.dump_task_id = tmpInfo.dump_task_id;
334 7 : info.dump_stream_id = INVALID_VALUE16;
335 7 : info.debug_dump_task_id = INVALID_VALUE32;
336 7 : info.debug_dump_stream_id = INVALID_VALUE16;
337 7 : info.is_model = (tmpInfo.is_model == 1);
338 7 : break;
339 : }
340 1 : default:
341 1 : aicpusd_err("The cmd type not found, cmd type[%u], Version[%d]", cmd_type_, version_);
342 : }
343 10 : info.file_name_stream_id = info.dump_stream_id;
344 10 : info.file_name_task_id = info.dump_task_id;
345 10 : return;
346 : }
347 :
348 11 : void AicpuSqeAdapter::GetAicpuDataDumpInfoV0(AicpuDataDumpInfo& info)
349 : {
350 11 : TsToAicpuDataDump tmpInfo = sqe_.u.ts_to_aicpu_datadump;
351 11 : aicpusd_info(
352 : "Data dump info: model_id[%u], stream_id[%u], task_id[%u], stream_id1[%u], task_id1[%u],"
353 : "ack_stream_id[%u], ack_task_id[%u].",
354 : tmpInfo.model_id, tmpInfo.stream_id, tmpInfo.task_id, tmpInfo.stream_id1, tmpInfo.task_id1,
355 : tmpInfo.ack_stream_id, tmpInfo.ack_task_id);
356 11 : info.dump_task_id = tmpInfo.task_id;
357 11 : info.dump_stream_id = tmpInfo.stream_id;
358 11 : info.debug_dump_task_id = tmpInfo.task_id1;
359 11 : info.debug_dump_stream_id = tmpInfo.stream_id1;
360 11 : info.is_model = (tmpInfo.model_id != INVALID_VALUE16);
361 11 : info.is_debug = ((tmpInfo.task_id1 != INVALID_VALUE16) && (tmpInfo.stream_id1 != INVALID_VALUE16));
362 11 : info.file_name_stream_id = info.is_debug ? tmpInfo.stream_id1 : tmpInfo.stream_id;
363 11 : info.file_name_task_id = info.is_debug ? tmpInfo.task_id1 : tmpInfo.task_id;
364 11 : }
365 :
366 22 : void AicpuSqeAdapter::GetAicpuDataDumpInfo(AicpuDataDumpInfo& info)
367 : {
368 22 : aicpusd_info("Get aicpu datadump Info.");
369 22 : if (getDataDumpInfoFuncMap_.find(version_) == getDataDumpInfoFuncMap_.end()) {
370 1 : aicpusd_err("The version[%hu] does not have a corresponding get data dump info Function.", version_);
371 1 : return;
372 : }
373 21 : (this->*getDataDumpInfoFuncMap_[version_])(info);
374 21 : return;
375 : }
376 :
377 11 : int32_t AicpuSqeAdapter::AicpuDumpResponseToTsV1(const int32_t ret)
378 : {
379 11 : TsAicpuMsgInfo msgInfo{};
380 11 : msgInfo.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
381 11 : msgInfo.vf_id = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
382 11 : msgInfo.tid = tid_;
383 11 : msgInfo.ts_id = ts_id_;
384 11 : msgInfo.cmd_type = cmd_type_;
385 11 : msgInfo.u.aicpu_resp.result_code = static_cast<uint16_t>(ret);
386 11 : switch (cmd_type_) {
387 7 : case TS_AICPU_NORMAL_DATADUMP_REPORT: {
388 7 : TsToAicpuNormalDataDumpMsg tmpInfo = msg_Info_.u.ts_to_aicpu_normal_datadump;
389 7 : msgInfo.u.aicpu_resp.task_id = tmpInfo.dump_task_id;
390 7 : msgInfo.u.aicpu_resp.stream_id = tmpInfo.dump_stream_id;
391 7 : msgInfo.u.aicpu_resp.reserved = tmpInfo.dump_type;
392 7 : break;
393 : }
394 3 : case TS_AICPU_DEBUG_DATADUMP_REPORT: {
395 3 : TsToAicpuDebugDataDumpMsg tmpInfo = msg_Info_.u.ts_to_aicpu_debug_datadump;
396 3 : msgInfo.u.aicpu_resp.task_id = tmpInfo.debug_dump_task_id;
397 3 : msgInfo.u.aicpu_resp.stream_id = tmpInfo.dump_stream_id;
398 3 : msgInfo.u.aicpu_resp.reserved = tmpInfo.dump_type;
399 3 : break;
400 : }
401 1 : default: {
402 1 : aicpusd_err("The cmd type not found, cmd type[%u], Version[%u]", cmd_type_, version_);
403 1 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
404 : }
405 : }
406 10 : aicpusd_info(
407 : "Aicpu dump response info: cmd_type[%u], ret[%u], task_id[%u], stream_id[%u]", cmd_type_,
408 : msgInfo.u.aicpu_resp.result_code, msgInfo.u.aicpu_resp.task_id, msgInfo.u.aicpu_resp.stream_id);
409 10 : return ResponseToTs(msgInfo, 0U, AicpuDrvManager::GetInstance().GetDeviceId(), msgInfo.ts_id);
410 : }
411 :
412 20 : int32_t AicpuSqeAdapter::AicpuDumpResponseToTsV0(const int32_t ret)
413 : {
414 20 : TsAicpuSqe aicpuSqe{};
415 20 : aicpuSqe.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
416 20 : aicpuSqe.vf_id = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
417 20 : aicpuSqe.tid = tid_;
418 20 : aicpuSqe.ts_id = ts_id_;
419 20 : aicpuSqe.cmd_type = AICPU_DATADUMP_RESPONSE;
420 20 : aicpuSqe.u.aicpu_dump_resp.result_code = static_cast<uint16_t>(ret);
421 20 : aicpuSqe.u.aicpu_dump_resp.cmd_type = AICPU_DATADUMP_REPORT;
422 20 : uint32_t handleId = 0U;
423 20 : if (cmd_type_ == AICPU_FFTS_PLUS_DATADUMP_REPORT) {
424 3 : aicpusd_info("Ffts plus dump response.");
425 3 : TsToAicpuFFTSPlusDataDump info = sqe_.u.ts_to_aicpu_ffts_plus_datadump;
426 3 : uint32_t ackStreamId = info.stream_id;
427 3 : uint32_t ackTaskId = info.task_id;
428 3 : if ((info.task_id1 != INVALID_VALUE16) && (info.stream_id1 != INVALID_VALUE16)) {
429 2 : ackStreamId = info.stream_id1;
430 2 : ackTaskId = info.task_id1;
431 : }
432 3 : aicpuSqe.u.aicpu_dump_resp.task_id = ackTaskId;
433 3 : aicpuSqe.u.aicpu_dump_resp.stream_id = ackStreamId;
434 3 : aicpuSqe.u.aicpu_dump_resp.reserved = info.reserved[0];
435 3 : handleId = info.model_id;
436 : } else {
437 17 : aicpuSqe.u.aicpu_dump_resp.task_id = sqe_.u.ts_to_aicpu_datadump.ack_task_id;
438 17 : aicpuSqe.u.aicpu_dump_resp.stream_id = sqe_.u.ts_to_aicpu_datadump.ack_stream_id;
439 17 : aicpuSqe.u.aicpu_dump_resp.reserved = sqe_.u.ts_to_aicpu_datadump.reserved[0];
440 17 : handleId = sqe_.u.ts_to_aicpu_datadump.model_id;
441 : }
442 20 : aicpusd_info(
443 : "Aicpu dump response info: cmd_type[%u], ret[%u], ack_stream_id[%u], ack_task_id[%u].", aicpuSqe.cmd_type, ret,
444 : aicpuSqe.u.aicpu_dump_resp.stream_id, aicpuSqe.u.aicpu_dump_resp.task_id);
445 40 : return ResponseToTs(aicpuSqe, handleId, AicpuDrvManager::GetInstance().GetDeviceId(), aicpuSqe.ts_id);
446 : }
447 :
448 32 : int32_t AicpuSqeAdapter::AicpuDumpResponseToTs(const int32_t ret)
449 : {
450 32 : aicpusd_info("Aicpu dump response to ts.");
451 32 : if (getDataDumpRspFuncMap_.find(version_) == getDataDumpRspFuncMap_.end()) {
452 1 : aicpusd_err("The version[%hu] does not have a corresponding get data dump response Function.", version_);
453 1 : return AICPU_SCHEDULE_ERROR_NOT_FOUND_FUNCTION;
454 : }
455 31 : return (this->*getDataDumpRspFuncMap_[version_])(ret);
456 : }
457 :
458 8 : void AicpuSqeAdapter::GetAicpuDumpFFTSPlusDataInfo(AicpuDumpFFTSPlusDataInfo& info)
459 : {
460 8 : aicpusd_info("Get aicpu dump FFTSPlus data Info.");
461 8 : info.i = sqe_.u.ts_to_aicpu_ffts_plus_datadump;
462 8 : return;
463 : }
464 :
465 9 : void AicpuSqeAdapter::GetAicpuDataDumpInfoLoadV0(AicpuDataDumpInfoLoad& info)
466 : {
467 9 : TsToAicpuDataDumpInfoLoad tmpinfo = sqe_.u.ts_to_aicpu_datadumploadinfo;
468 9 : aicpusd_info(
469 : "Get aicpu data dump load info: dumpinfoPtr[%p], length[%u], task_id[%u],stream_id[%u].", tmpinfo.dumpinfoPtr,
470 : tmpinfo.length, tmpinfo.task_id, tmpinfo.stream_id);
471 9 : info.dumpinfoPtr = tmpinfo.dumpinfoPtr;
472 9 : info.length = tmpinfo.length;
473 9 : info.task_id = tmpinfo.task_id;
474 9 : info.stream_id = tmpinfo.stream_id;
475 9 : }
476 :
477 17 : void AicpuSqeAdapter::GetAicpuDataDumpInfoLoadV1(AicpuDataDumpInfoLoad& info)
478 : {
479 17 : TsToAicpuDataDumpInfoloadMsg tmpinfo = msg_Info_.u.ts_to_aicpu_datadump_info_load;
480 17 : aicpusd_info(
481 : "Get aicpu data dump load info: dumpinfoPtr[%p], length[%u], task_id[%u],stream_id[%u].", tmpinfo.dumpinfoPtr,
482 : tmpinfo.length, tmpinfo.task_id, tmpinfo.stream_id);
483 17 : info.dumpinfoPtr = tmpinfo.dumpinfoPtr;
484 17 : info.length = tmpinfo.length;
485 17 : info.task_id = tmpinfo.task_id;
486 17 : info.stream_id = tmpinfo.stream_id;
487 17 : }
488 :
489 27 : void AicpuSqeAdapter::GetAicpuDataDumpInfoLoad(AicpuDataDumpInfoLoad& info)
490 : {
491 27 : aicpusd_info("Get aicpu datadump Info load.");
492 27 : if (getDataDumpLoadInfoFuncMap_.find(version_) == getDataDumpLoadInfoFuncMap_.end()) {
493 1 : aicpusd_err("The version[%hu] does not have a corresponding get data dump load info Function.", version_);
494 1 : return;
495 : }
496 26 : (this->*getDataDumpLoadInfoFuncMap_[version_])(info);
497 26 : return;
498 : }
499 :
500 7 : int32_t AicpuSqeAdapter::AicpuDataDumpLoadResponseToTsV1(const int32_t ret)
501 : {
502 7 : TsAicpuMsgInfo msgInfo{};
503 7 : msgInfo.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
504 7 : msgInfo.vf_id = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
505 7 : msgInfo.tid = tid_;
506 7 : msgInfo.ts_id = ts_id_;
507 7 : msgInfo.cmd_type = cmd_type_;
508 7 : msgInfo.u.aicpu_resp.result_code = static_cast<uint16_t>(ret);
509 7 : msgInfo.u.aicpu_resp.stream_id = msg_Info_.u.ts_to_aicpu_datadump_info_load.stream_id;
510 7 : msgInfo.u.aicpu_resp.task_id = msg_Info_.u.ts_to_aicpu_datadump_info_load.task_id;
511 7 : aicpusd_info(
512 : "Aicpu data dump load response info: cmd_type[%u], ret[%u], streamid[%u], taskid[%u].", msgInfo.cmd_type, ret,
513 : msgInfo.u.aicpu_resp.stream_id, msgInfo.u.aicpu_resp.task_id);
514 14 : return ResponseToTs(msgInfo, 0U, AicpuDrvManager::GetInstance().GetDeviceId(), msgInfo.ts_id);
515 : }
516 :
517 5 : int32_t AicpuSqeAdapter::AicpuDataDumpLoadResponseToTsV0(const int32_t ret)
518 : {
519 5 : TsAicpuSqe aicpuSqe{};
520 5 : aicpuSqe.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
521 5 : aicpuSqe.vf_id = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
522 5 : aicpuSqe.tid = tid_;
523 5 : aicpuSqe.ts_id = ts_id_;
524 5 : aicpuSqe.cmd_type = AICPU_DATADUMP_RESPONSE;
525 5 : aicpuSqe.u.aicpu_dump_resp.result_code = static_cast<uint16_t>(ret);
526 5 : aicpuSqe.u.aicpu_dump_resp.cmd_type = AICPU_DATADUMP_LOADINFO;
527 5 : aicpuSqe.u.aicpu_dump_resp.task_id = sqe_.u.ts_to_aicpu_datadumploadinfo.task_id;
528 5 : aicpuSqe.u.aicpu_dump_resp.stream_id = sqe_.u.ts_to_aicpu_datadumploadinfo.stream_id;
529 5 : aicpuSqe.u.aicpu_dump_resp.reserved = STARS_DATADUMP_LOAD_INFO;
530 5 : aicpusd_info(
531 : "Aicpu data dump load response info: cmd_type[%u], ret[%u], streamid[%u], taskid[%u].", aicpuSqe.cmd_type, ret,
532 : aicpuSqe.u.aicpu_dump_resp.stream_id, aicpuSqe.u.aicpu_dump_resp.task_id);
533 10 : return ResponseToTs(aicpuSqe, 0U, AicpuDrvManager::GetInstance().GetDeviceId(), aicpuSqe.ts_id);
534 : }
535 :
536 13 : int32_t AicpuSqeAdapter::AicpuDataDumpLoadResponseToTs(const int32_t ret)
537 : {
538 13 : aicpusd_info("Aicpu datadump load response to ts.");
539 13 : if (getDataDumpLoadRspFuncMap_.find(version_) == getDataDumpLoadRspFuncMap_.end()) {
540 1 : aicpusd_err("The version[%hu] does not have a corresponding get data dump load response Function.", version_);
541 1 : return AICPU_SCHEDULE_ERROR_NOT_FOUND_FUNCTION;
542 : }
543 12 : return (this->*getDataDumpLoadRspFuncMap_[version_])(ret);
544 : }
545 :
546 14 : void AicpuSqeAdapter::GetAicpuTimeOutConfigInfo(AicpuTimeOutConfigInfo& info)
547 : {
548 14 : aicpusd_info("Get aicpu timeout config Info.");
549 14 : if (version_ == 1) {
550 2 : info.i = msg_Info_.u.ts_to_aicpu_timeout_cfg;
551 : } else {
552 12 : info.i = sqe_.u.ts_to_aicpu_timeout_cfg;
553 : }
554 14 : return;
555 : }
556 :
557 5 : void AicpuSqeAdapter::GetAicpuInfoLoadV0(AicpuInfoLoad& info)
558 : {
559 5 : TsToAicpuInfoLoad tmpinfo = sqe_.u.ts_to_aicpu_info;
560 5 : aicpusd_info(
561 : "Get aicpu info: aicpuInfoPtr[%p], length[%u], stream_id[%u], task_id[%u]", tmpinfo.aicpuInfoPtr,
562 : tmpinfo.length, tmpinfo.stream_id, tmpinfo.task_id);
563 5 : info.aicpuInfoPtr = tmpinfo.aicpuInfoPtr;
564 5 : info.length = tmpinfo.length;
565 5 : info.stream_id = tmpinfo.stream_id;
566 5 : info.task_id = tmpinfo.task_id;
567 5 : }
568 :
569 2 : void AicpuSqeAdapter::GetAicpuInfoLoadV1(AicpuInfoLoad& info)
570 : {
571 2 : TsToAicpuInfoLoadMsg tmpinfo = msg_Info_.u.ts_to_aicpu_info_load;
572 2 : aicpusd_info(
573 : "Get aicpu common info: aicpuInfoPtr[%p], length[%u], stream_id[%u], task_id[%u]", tmpinfo.aicpu_info_ptr,
574 : tmpinfo.length, tmpinfo.stream_id, tmpinfo.task_id);
575 2 : info.aicpuInfoPtr = tmpinfo.aicpu_info_ptr;
576 2 : info.length = tmpinfo.length;
577 2 : info.stream_id = tmpinfo.stream_id;
578 2 : info.task_id = tmpinfo.task_id;
579 2 : }
580 :
581 8 : void AicpuSqeAdapter::GetAicpuInfoLoad(AicpuInfoLoad& info)
582 : {
583 8 : aicpusd_info("Get aicpu info load.");
584 8 : if (getLoadInfoFuncMap_.find(version_) == getLoadInfoFuncMap_.end()) {
585 1 : aicpusd_err("The version[%hu] does not have a corresponding get aicpu load info Function.", version_);
586 1 : return;
587 : }
588 7 : (this->*getLoadInfoFuncMap_[version_])(info);
589 7 : return;
590 : }
591 :
592 2 : void AicpuSqeAdapter::GetAicErrReportInfoV0(AicErrReportInfo& info)
593 : {
594 2 : aicpusd_info("Info is aic error.");
595 2 : info.u.aicError = sqe_.u.ts_to_aicpu_aic_err_report;
596 2 : return;
597 : }
598 :
599 2 : void AicpuSqeAdapter::GetAicErrReportInfoV1(AicErrReportInfo& info)
600 : {
601 2 : aicpusd_info("Info is aic error msg.");
602 2 : info.u.aicErrorMsg = msg_Info_.u.aic_err_msg;
603 2 : return;
604 : }
605 :
606 4 : void AicpuSqeAdapter::GetAicErrReportInfo(AicErrReportInfo& info)
607 : {
608 4 : aicpusd_info("Get aic err report Info.");
609 4 : if (getAicErrReportInfoFuncMap_.find(version_) == getAicErrReportInfoFuncMap_.end()) {
610 0 : aicpusd_err("The version[%hu] does not have a corresponding get aic error.", version_);
611 0 : return;
612 : }
613 4 : return (this->*getAicErrReportInfoFuncMap_[version_])(info);
614 : }
615 :
616 7 : int32_t AicpuSqeAdapter::ErrorMsgResponseToTsV0(ErrMsgRspInfo& rspInfo)
617 : {
618 7 : TsAicpuSqe aicpuSqe{};
619 7 : aicpuSqe.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
620 7 : aicpuSqe.cmd_type = AICPU_ERR_MSG_REPORT;
621 7 : aicpuSqe.vf_id = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
622 7 : aicpuSqe.tid = 0U; // no need tid
623 7 : aicpuSqe.ts_id = static_cast<uint8_t>(rspInfo.ts_id);
624 7 : aicpuSqe.u.aicpu_err_msg_report.result_code = rspInfo.err_code;
625 7 : aicpuSqe.u.aicpu_err_msg_report.stream_id = static_cast<uint16_t>(rspInfo.stream_id);
626 7 : aicpuSqe.u.aicpu_err_msg_report.task_id = static_cast<uint16_t>(rspInfo.task_id);
627 7 : aicpuSqe.u.aicpu_err_msg_report.offset = static_cast<uint16_t>(rspInfo.offset);
628 7 : aicpusd_info(
629 : "Error msg response info: cmd_type[%u], result_code[%u], rsp stream id[%u], rsp task id[%u]", aicpuSqe.cmd_type,
630 : rspInfo.err_code, rspInfo.stream_id, rspInfo.task_id);
631 14 : return ResponseToTs(aicpuSqe, rspInfo.model_id, AicpuDrvManager::GetInstance().GetDeviceId(), aicpuSqe.ts_id);
632 : }
633 :
634 3 : int32_t AicpuSqeAdapter::ErrorMsgResponseToTsV1(ErrMsgRspInfo& rspInfo)
635 : {
636 3 : TsAicpuMsgInfo msgInfo{};
637 3 : msgInfo.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
638 3 : msgInfo.cmd_type = cmd_type_;
639 3 : msgInfo.vf_id = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
640 3 : msgInfo.tid = 0U; // no need tid
641 3 : msgInfo.ts_id = static_cast<uint8_t>(rspInfo.ts_id);
642 3 : msgInfo.u.aicpu_resp.result_code = rspInfo.err_code;
643 3 : msgInfo.u.aicpu_resp.stream_id = static_cast<uint16_t>(rspInfo.stream_id);
644 3 : msgInfo.u.aicpu_resp.task_id = rspInfo.task_id;
645 3 : aicpusd_info(
646 : "Error msg response info: cmd_type[%u], result_code[%u], rsp stream id[%u], rsp task id[%u]", msgInfo.cmd_type,
647 : rspInfo.err_code, rspInfo.stream_id, rspInfo.task_id);
648 6 : return ResponseToTs(msgInfo, rspInfo.model_id, AicpuDrvManager::GetInstance().GetDeviceId(), msgInfo.ts_id);
649 : }
650 :
651 11 : int32_t AicpuSqeAdapter::AicpuSqeAdapter::ErrorMsgResponseToTs(ErrMsgRspInfo& rspInfo)
652 : {
653 11 : aicpusd_info("Error msg response to ts.");
654 11 : if (getErrorMsgRspFuncMap_.find(version_) == getErrorMsgRspFuncMap_.end()) {
655 1 : aicpusd_err("The version[%hu] does not have a corresponding get error msg response Function.", version_);
656 1 : return AICPU_SCHEDULE_ERROR_NOT_FOUND_FUNCTION;
657 : }
658 10 : return (this->*getErrorMsgRspFuncMap_[version_])(rspInfo);
659 : }
660 :
661 7 : void AicpuSqeAdapter::AicpuActiveStreamSetMsgV0(ActiveStreamInfo& info)
662 : {
663 7 : TsAicpuSqe aicpuSqe = {};
664 7 : aicpuSqe.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
665 7 : aicpuSqe.cmd_type = AICPU_ACTIVE_STREAM;
666 7 : aicpuSqe.vf_id = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
667 7 : aicpuSqe.tid = 0U; // no need tid
668 7 : aicpuSqe.ts_id = info.ts_id;
669 7 : aicpuSqe.u.aicpu_active_stream.stream_id = info.stream_id;
670 7 : aicpuSqe.u.aicpu_active_stream.aicpu_stamp = info.aicpu_stamp;
671 7 : aicpusd_info(
672 : "Active stream set sqe info: cmd_type[%u], stream id[%u], stamp[%u].", aicpuSqe.cmd_type,
673 : aicpuSqe.u.aicpu_active_stream.stream_id, aicpuSqe.u.aicpu_active_stream.aicpu_stamp);
674 7 : AicpuMsgSend::SetTsDevSendMsgAsync(info.device_id, info.ts_id, aicpuSqe, info.handle_id);
675 7 : }
676 :
677 1 : void AicpuSqeAdapter::AicpuActiveStreamSetMsgV1(ActiveStreamInfo& info)
678 : {
679 1 : TsAicpuMsgInfo msgInfo = {};
680 1 : msgInfo.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
681 1 : msgInfo.cmd_type = TS_AICPU_ACTIVE_STREAM;
682 1 : msgInfo.vf_id = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
683 1 : msgInfo.tid = 0U; // no need tid
684 1 : msgInfo.ts_id = info.ts_id;
685 1 : msgInfo.u.aicpu_active_stream.aicpu_stamp = info.aicpu_stamp;
686 1 : msgInfo.u.aicpu_active_stream.stream_id = info.stream_id;
687 1 : aicpusd_info(
688 : "Active stream set msg info: cmd_type[%u], stream id[%u], stamp[%u].", msgInfo.cmd_type,
689 : msgInfo.u.aicpu_active_stream.stream_id, msgInfo.u.aicpu_active_stream.aicpu_stamp);
690 1 : AicpuMsgSend::SetTsDevSendMsgAsync(info.device_id, info.ts_id, msgInfo, info.handle_id);
691 1 : }
692 :
693 9 : void AicpuSqeAdapter::AicpuActiveStreamSetMsg(ActiveStreamInfo& info)
694 : {
695 9 : aicpusd_info("Aicpu active stream set msg.");
696 9 : if (activeStreamSetMsgFuncMap_.find(version_) == activeStreamSetMsgFuncMap_.end()) {
697 1 : aicpusd_err("The version[%hu] does not have a corresponding get error msg response Function.", version_);
698 1 : return;
699 : }
700 8 : return (this->*activeStreamSetMsgFuncMap_[version_])(info);
701 : }
702 :
703 8 : int32_t AicpuSqeAdapter::AicpuNoticeTsPidResponse(const uint32_t deviceId) const
704 : {
705 8 : aicpusd_info("Aicpu notice ts pid response.");
706 8 : TsAicpuSqe aicpuSqe = {};
707 8 : aicpuSqe.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid()); // host pid
708 8 : aicpuSqe.cmd_type = AICPU_NOTICE_TS_PID;
709 8 : aicpuSqe.vf_id = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
710 16 : return ResponseToTs(aicpuSqe, 0U, deviceId, 0U);
711 : }
712 :
713 8 : int32_t AicpuSqeAdapter::AicpuRecordResponseToTsV0(AicpuRecordInfo& info)
714 : {
715 : TsAicpuSqe aicpuSqe;
716 8 : aicpuSqe.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
717 8 : aicpuSqe.cmd_type = AICPU_RECORD;
718 8 : aicpuSqe.vf_id = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
719 8 : aicpuSqe.tid = 0U; // notify is no need tid
720 8 : aicpuSqe.ts_id = info.ts_id;
721 8 : aicpuSqe.u.aicpu_record.record_type = info.record_type;
722 8 : aicpuSqe.u.aicpu_record.record_id = info.record_id;
723 8 : aicpuSqe.u.aicpu_record.fault_task_id = info.fault_task_id;
724 8 : aicpuSqe.u.aicpu_record.fault_stream_id = info.fault_stream_id;
725 8 : aicpuSqe.u.aicpu_record.ret_code = info.ret_code;
726 8 : const bool retSucc = info.ret_code == 0U ? true : false;
727 8 : aicpusd_info(
728 : "Record response to ts : pid[%u], cmd type[%u], vf_id[%u], tid[%u], ts_id[%u], record type[%u], "
729 : "record_id[%u], fault_task_id[%u], fault_stream_id[%u], ret[%u]",
730 : aicpuSqe.pid, aicpuSqe.cmd_type, aicpuSqe.vf_id, aicpuSqe.tid, aicpuSqe.ts_id,
731 : aicpuSqe.u.aicpu_record.record_type, aicpuSqe.u.aicpu_record.record_id, aicpuSqe.u.aicpu_record.fault_task_id,
732 : aicpuSqe.u.aicpu_record.fault_stream_id, aicpuSqe.u.aicpu_record.ret_code);
733 8 : if (!retSucc) {
734 5 : return ResponseToTs(aicpuSqe, 0U, info.dev_id, info.ts_id);
735 : }
736 3 : aicpusd_info("Use hal ts dev record response.");
737 3 : int32_t ret = halTsDevRecord(info.dev_id, info.ts_id, static_cast<uint32_t>(info.record_type), info.record_id);
738 3 : if (ret != static_cast<uint32_t>(DRV_ERROR_NONE)) {
739 1 : aicpusd_err(
740 : "Send event notify to ts failed, sendRet=%d, notifyId=%u, retVal=%d.", ret, info.record_id, info.ret_code);
741 1 : return AICPU_SCHEDULE_ERROR_FROM_DRV;
742 : }
743 2 : return AICPU_SCHEDULE_OK;
744 : }
745 :
746 2 : int32_t AicpuSqeAdapter::AicpuRecordResponseToTsV1(AicpuRecordInfo& info)
747 : {
748 : TsAicpuMsgInfo msgInfo;
749 2 : msgInfo.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
750 2 : msgInfo.cmd_type = TS_AICPU_RECORD;
751 2 : msgInfo.vf_id = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
752 2 : msgInfo.tid = 0U; // notify is no need tid
753 2 : msgInfo.ts_id = info.ts_id;
754 2 : msgInfo.u.aicpu_record.record_id = info.record_id;
755 2 : msgInfo.u.aicpu_record.record_type = info.record_type;
756 2 : msgInfo.u.aicpu_record.ret_code = info.ret_code;
757 2 : msgInfo.u.aicpu_record.fault_task_id = info.fault_task_id;
758 2 : uint32_t handleId = info.ret_code == 0 ? MSG_EVENT_SUB_EVENTID_RECORD : 0U;
759 2 : aicpusd_info(
760 : "Record response to ts : pid[%u], cmd type[%u], vf_id[%u], tid[%u], ts_id[%u], record type[%u], "
761 : "record_id[%u], fault_task_id[%u], ret[%u], hand id[%u]",
762 : msgInfo.pid, msgInfo.cmd_type, msgInfo.vf_id, msgInfo.tid, msgInfo.ts_id, msgInfo.u.aicpu_record.record_type,
763 : msgInfo.u.aicpu_record.record_id, msgInfo.u.aicpu_record.fault_task_id, msgInfo.u.aicpu_record.ret_code,
764 : handleId);
765 4 : return ResponseToTs(msgInfo, handleId, info.dev_id, msgInfo.ts_id);
766 : }
767 :
768 11 : int32_t AicpuSqeAdapter::AicpuRecordResponseToTs(AicpuRecordInfo& info)
769 : {
770 11 : if (getRecordRspFuncMap_.find(version_) == getRecordRspFuncMap_.end()) {
771 1 : aicpusd_err("The version[%hu] does not have a corresponding get record response Function.", version_);
772 1 : return AICPU_SCHEDULE_ERROR_NOT_FOUND_FUNCTION;
773 : }
774 10 : return (this->*getRecordRspFuncMap_[version_])(info);
775 : }
776 :
777 13 : int32_t AicpuSqeAdapter::AicpuTimeOutConfigResponseToTsV0(const int32_t ret)
778 : {
779 13 : TsAicpuSqe aicpuSqe{};
780 13 : aicpuSqe.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
781 13 : aicpuSqe.cmd_type = AICPU_TIMEOUT_CONFIG_RESPONSE;
782 13 : aicpuSqe.vf_id = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
783 13 : aicpuSqe.tid = tid_;
784 13 : aicpuSqe.ts_id = ts_id_;
785 13 : aicpuSqe.u.aicpu_timeout_cfg_resp.result = ret;
786 13 : aicpusd_info("Aicpu time out config response info: cmd_type[%u], ret[%u].", aicpuSqe.cmd_type, ret);
787 26 : return ResponseToTs(aicpuSqe, 0U, AicpuDrvManager::GetInstance().GetDeviceId(), aicpuSqe.ts_id);
788 : }
789 :
790 3 : int32_t AicpuSqeAdapter::AicpuTimeOutConfigResponseToTsV1(const int32_t ret)
791 : {
792 3 : TsAicpuMsgInfo msgInfo{};
793 3 : msgInfo.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
794 3 : msgInfo.cmd_type = cmd_type_;
795 3 : msgInfo.vf_id = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
796 3 : msgInfo.tid = tid_;
797 3 : msgInfo.ts_id = ts_id_;
798 3 : msgInfo.u.aicpu_resp.result_code = static_cast<uint16_t>(ret);
799 3 : msgInfo.u.aicpu_resp.stream_id = INVALID_VALUE16;
800 3 : msgInfo.u.aicpu_resp.task_id = INVALID_VALUE32;
801 3 : aicpusd_info(
802 : "Aicpu time out config response info: cmd_type[%u], ret[%u], stream id[%u], task id[%u].", msgInfo.cmd_type,
803 : ret, INVALID_VALUE16, INVALID_VALUE32);
804 6 : return ResponseToTs(msgInfo, 0U, AicpuDrvManager::GetInstance().GetDeviceId(), msgInfo.ts_id);
805 : }
806 :
807 17 : int32_t AicpuSqeAdapter::AicpuTimeOutConfigResponseToTs(const int32_t ret)
808 : {
809 17 : aicpusd_info("Aicpu timeout config response to ts.");
810 17 : if (getTimeOutConfigRspFuncMap_.find(version_) == getTimeOutConfigRspFuncMap_.end()) {
811 1 : aicpusd_err("The version[%hu] does not have a corresponding get time out config response Function.", version_);
812 1 : return AICPU_SCHEDULE_ERROR_NOT_FOUND_FUNCTION;
813 : }
814 16 : return (this->*getTimeOutConfigRspFuncMap_[version_])(ret);
815 : }
816 :
817 8 : int32_t AicpuSqeAdapter::AicpuInfoLoadResponseToTsV0(const int32_t ret)
818 : {
819 8 : TsAicpuSqe aicpuSqe{};
820 8 : TsToAicpuInfoLoad tmpInfo = sqe_.u.ts_to_aicpu_info;
821 8 : aicpuSqe.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
822 8 : aicpuSqe.tid = tid_;
823 8 : aicpuSqe.ts_id = ts_id_;
824 8 : aicpuSqe.vf_id = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
825 8 : aicpuSqe.cmd_type = AICPU_INFO_LOAD_RESPONSE;
826 8 : aicpuSqe.u.aicpu_resp.cmd_type = AICPU_INFO_LOAD;
827 8 : aicpuSqe.u.aicpu_resp.task_id = tmpInfo.task_id;
828 8 : aicpuSqe.u.aicpu_resp.result_code = static_cast<uint16_t>(ret);
829 8 : aicpuSqe.u.aicpu_resp.stream_id = tmpInfo.stream_id;
830 8 : aicpusd_info(
831 : "Aicpu load info response info: cmd_type[%u], ret[%u], stream id[%u], task id[%u].", aicpuSqe.cmd_type, ret,
832 : tmpInfo.stream_id, tmpInfo.task_id);
833 16 : return ResponseToTs(aicpuSqe, 0U, AicpuDrvManager::GetInstance().GetDeviceId(), aicpuSqe.ts_id);
834 : }
835 :
836 3 : int32_t AicpuSqeAdapter::AicpuInfoLoadResponseToTsV1(const int32_t ret)
837 : {
838 3 : TsAicpuMsgInfo msgInfo{};
839 3 : TsToAicpuInfoLoadMsg tmpInfo = msg_Info_.u.ts_to_aicpu_info_load;
840 3 : msgInfo.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
841 3 : msgInfo.tid = tid_;
842 3 : msgInfo.ts_id = ts_id_;
843 3 : msgInfo.vf_id = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
844 3 : msgInfo.cmd_type = cmd_type_;
845 3 : msgInfo.u.aicpu_resp.stream_id = tmpInfo.stream_id;
846 3 : msgInfo.u.aicpu_resp.task_id = tmpInfo.task_id;
847 3 : msgInfo.u.aicpu_resp.result_code = static_cast<uint16_t>(ret);
848 3 : msgInfo.u.aicpu_resp.reserved = 0;
849 3 : aicpusd_info(
850 : "Aicpu load info response info: cmd_type[%u], ret[%u], stream id[%u], task id[%u].", msgInfo.cmd_type, ret,
851 : tmpInfo.stream_id, tmpInfo.task_id);
852 6 : return ResponseToTs(msgInfo, 0U, AicpuDrvManager::GetInstance().GetDeviceId(), msgInfo.ts_id);
853 : }
854 :
855 12 : int32_t AicpuSqeAdapter::AicpuInfoLoadResponseToTs(const int32_t ret)
856 : {
857 12 : aicpusd_info("Aicpu info load response to ts.");
858 12 : if (getInfoLoadRspFuncMap_.find(version_) == getInfoLoadRspFuncMap_.end()) {
859 1 : aicpusd_err("The version[%hu] does not have a corresponding get load info response Function.", version_);
860 1 : return AICPU_SCHEDULE_ERROR_NOT_FOUND_FUNCTION;
861 : }
862 11 : return (this->*getInfoLoadRspFuncMap_[version_])(ret);
863 : }
864 :
865 66 : int32_t AicpuSqeAdapter::ResponseToTs(
866 : TsAicpuSqe& aicpuSqe, unsigned int handleId, unsigned int devId, unsigned int tsId) const
867 : {
868 66 : aicpusd_info("Begin to response use TsAicpuSqe.");
869 66 : const auto ret = tsDevSendMsgAsync(
870 : devId, static_cast<uint32_t>(tsId), PtrToPtr<TsAicpuSqe, char_t>(&aicpuSqe),
871 : static_cast<uint32_t>(sizeof(TsAicpuSqe)), handleId);
872 66 : AICPUSD_CHECK(
873 : (ret == DRV_ERROR_NONE), AICPU_SCHEDULE_ERROR_INNER_ERROR,
874 : "Response to ts use"
875 : "tsDevSendMsgAsync failed, ret[%d]",
876 : ret);
877 54 : if (FeatureCtrl::GetAicpuSchedMode() == SCHED_MODE_MSGQ) {
878 51 : MessageQueue::SendResponse(0U, 0U);
879 : }
880 54 : aicpusd_info("Finished to response use TsAicpuSqe.");
881 54 : return AICPU_SCHEDULE_OK;
882 : }
883 :
884 31 : int32_t AicpuSqeAdapter::ResponseToTs(
885 : TsAicpuMsgInfo& aicpuMsgInfo, unsigned int handleId, unsigned int devId, unsigned int tsId) const
886 : {
887 31 : aicpusd_info("Begin to response use TsAicpuMsgInfo.");
888 31 : const auto ret = tsDevSendMsgAsync(
889 : devId, static_cast<uint32_t>(tsId), PtrToPtr<TsAicpuMsgInfo, char_t>(&aicpuMsgInfo),
890 : static_cast<uint32_t>(sizeof(TsAicpuMsgInfo)), handleId);
891 31 : AICPUSD_CHECK(
892 : (ret == DRV_ERROR_NONE), AICPU_SCHEDULE_ERROR_INNER_ERROR,
893 : "Response to ts use"
894 : "tsDevSendMsgAsync failed, ret[%d]",
895 : ret);
896 31 : if (FeatureCtrl::GetAicpuSchedMode() == SCHED_MODE_MSGQ) {
897 20 : MessageQueue::SendResponse(0U, 0U);
898 : }
899 31 : aicpusd_info("Finished to response use TsAicpuMsgInfo.");
900 31 : return AICPU_SCHEDULE_OK;
901 : }
902 :
903 6 : int32_t AicpuSqeAdapter::ResponseToTs(
904 : hwts_response_t& hwtsResp, uint32_t devId, EVENT_ID eventId, uint32_t subeventId) const
905 : {
906 6 : aicpusd_info("Begin to response use hwtsResp.");
907 6 : if (FeatureCtrl::GetAicpuSchedMode() == SCHED_MODE_MSGQ) {
908 6 : MessageQueue::SendResponse(hwtsResp.result, hwtsResp.status);
909 6 : aicpusd_info("Finished to response use hwtsResp, result[%u], status[%u].", hwtsResp.result, hwtsResp.status);
910 : }
911 6 : const drvError_t ret = halEschedAckEvent(
912 : devId, eventId, subeventId, PtrToPtr<hwts_response_t, char_t>(&hwtsResp),
913 : static_cast<uint32_t>(sizeof(hwts_response_t)));
914 6 : AICPUSD_CHECK(
915 : (ret == DRV_ERROR_NONE), AICPU_SCHEDULE_ERROR_INNER_ERROR,
916 : "Response to ts use"
917 : "halEschedAckEvent failed, ret[%d]",
918 : ret);
919 6 : aicpusd_info("Finished to response use hwtsResp.");
920 6 : return AICPU_SCHEDULE_OK;
921 : }
922 : } // namespace AicpuSchedule
|