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