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 :
12 : namespace AicpuSchedule {
13 :
14 5 : AicpuSqeAdapter::AicpuSqeAdapter(const TsAicpuSqe &sqe, const int16_t version)
15 5 : : pid_(sqe.pid), cmd_type_(sqe.cmd_type), vf_id_(sqe.vf_id), tid_(sqe.tid), ts_id_(sqe.ts_id), sqe_(sqe),
16 5 : version_(version), invalid_sqe_(false)
17 : {
18 5 : aicpusd_info(
19 : "Enter cust aicpuSqeAdapter constructor, using TsAicpuSqe init, pid[%u], cmd_type[%u], vf id[%u], tid[%u], "
20 : "ts id[%u], version[%hu]",
21 : pid_,
22 : cmd_type_,
23 : vf_id_,
24 : tid_,
25 : ts_id_,
26 : version_);
27 5 : InitAdapterFuncMap();
28 5 : }
29 :
30 5 : AicpuSqeAdapter::AicpuSqeAdapter(const TsAicpuMsgInfo &msgInfo, const int16_t version)
31 5 : : pid_(msgInfo.pid), cmd_type_(msgInfo.cmd_type), vf_id_(msgInfo.vf_id), tid_(msgInfo.tid), ts_id_(msgInfo.ts_id),
32 5 : msg_Info_(msgInfo), version_(version), invalid_msg_info_(false)
33 : {
34 5 : aicpusd_info("Enter cust aicpuSqeAdapter constructor, using TsAicpuMsgInfo init, pid[%u], cmd_type[%u], vf "
35 : "id[%u], tid[%u], "
36 : "ts id[%u], version[%hu]",
37 : pid_,
38 : cmd_type_,
39 : vf_id_,
40 : tid_,
41 : ts_id_,
42 : version_);
43 5 : InitAdapterFuncMap();
44 5 : }
45 :
46 3 : AicpuSqeAdapter::AicpuSqeAdapter(const int16_t version) : version_(version), invalid_msg_info_(true), invalid_sqe_(true)
47 : {
48 3 : aicpusd_info("Enter AicpuSqeAdapter constructor, using version init, version[%hu]", version_);
49 3 : InitAdapterFuncMap();
50 3 : }
51 :
52 10 : uint8_t AicpuSqeAdapter::GetCmdType() const
53 : {
54 10 : return cmd_type_;
55 : }
56 :
57 1 : bool AicpuSqeAdapter::IsAdapterInvalidParameter() const
58 : {
59 1 : return invalid_sqe_ && invalid_msg_info_;
60 : }
61 :
62 13 : void AicpuSqeAdapter::InitAdapterFuncMap()
63 : {
64 13 : getDataDumpLoadInfoFuncMap_[VERSION_0] = &AicpuSqeAdapter::GetAicpuDataDumpInfoLoadV0;
65 13 : getDataDumpLoadInfoFuncMap_[VERSION_1] = &AicpuSqeAdapter::GetAicpuDataDumpInfoLoadV1;
66 :
67 13 : getDataDumpLoadRspFuncMap_[VERSION_0] = &AicpuSqeAdapter::AicpuDataDumpLoadResponseToTsV0;
68 13 : getDataDumpLoadRspFuncMap_[VERSION_1] = &AicpuSqeAdapter::AicpuDataDumpLoadResponseToTsV1;
69 13 : }
70 :
71 5 : void AicpuSqeAdapter::GetAicpuMsgVersionInfo(AicpuMsgVersionInfo &info)
72 : {
73 5 : TsAicpuMsgVersion tmpInfo = sqe_.u.aicpu_msg_version;
74 5 : aicpusd_info("Get msg version msg: magic num[%u], version[%hu].", tmpInfo.magic_num, tmpInfo.version);
75 5 : info.magic_num = tmpInfo.magic_num;
76 5 : info.version = tmpInfo.version;
77 5 : }
78 :
79 1 : int32_t AicpuSqeAdapter::AicpuMsgVersionResponseToTs(const int32_t ret)
80 : {
81 1 : TsAicpuMsgInfo msgInfo{};
82 1 : msgInfo.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
83 1 : msgInfo.vf_id = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
84 1 : msgInfo.tid = tid_;
85 1 : msgInfo.ts_id = ts_id_;
86 1 : msgInfo.cmd_type = cmd_type_;
87 1 : msgInfo.u.aicpu_resp.result_code = static_cast<uint16_t>(ret);
88 1 : msgInfo.u.aicpu_resp.task_id = INVALID_VALUE32;
89 1 : aicpusd_info("Msg version response info: cmd_type[%u], ret code[%u], stream id[%u], task id[%u].",
90 : msgInfo.cmd_type,
91 : msgInfo.u.aicpu_resp.result_code,
92 : msgInfo.u.aicpu_resp.stream_id,
93 : msgInfo.u.aicpu_resp.task_id);
94 2 : return ResponseToTs(msgInfo, 0U, AicpuDrvManager::GetInstance().GetDeviceId(), msgInfo.ts_id);
95 : }
96 :
97 1 : void AicpuSqeAdapter::GetAicpuDataDumpInfoLoadV0(AicpuDataDumpInfoLoad &info)
98 : {
99 1 : TsToAicpuDataDumpInfoLoad tmpinfo = sqe_.u.ts_to_aicpu_datadumploadinfo;
100 1 : aicpusd_info("Get aicpu data dump load info: dumpinfoPtr[%p], length[%u], task_id[%u],stream_id[%u].",
101 : tmpinfo.dumpinfoPtr,
102 : tmpinfo.length,
103 : tmpinfo.task_id,
104 : tmpinfo.stream_id);
105 1 : info.dumpinfoPtr = tmpinfo.dumpinfoPtr;
106 1 : info.length = tmpinfo.length;
107 1 : info.task_id = tmpinfo.task_id;
108 1 : info.stream_id = tmpinfo.stream_id;
109 1 : }
110 :
111 1 : void AicpuSqeAdapter::GetAicpuDataDumpInfoLoadV1(AicpuDataDumpInfoLoad &info)
112 : {
113 1 : TsToAicpuDataDumpInfoloadMsg tmpinfo = msg_Info_.u.ts_to_aicpu_datadump_info_load;
114 1 : aicpusd_info("Get aicpu data dump load info: dumpinfoPtr[%p], length[%u], task_id[%u],stream_id[%u].",
115 : tmpinfo.dumpinfoPtr,
116 : tmpinfo.length,
117 : tmpinfo.task_id,
118 : tmpinfo.stream_id);
119 1 : info.dumpinfoPtr = tmpinfo.dumpinfoPtr;
120 1 : info.length = tmpinfo.length;
121 1 : info.task_id = tmpinfo.task_id;
122 1 : info.stream_id = tmpinfo.stream_id;
123 1 : }
124 :
125 3 : void AicpuSqeAdapter::GetAicpuDataDumpInfoLoad(AicpuDataDumpInfoLoad &info)
126 : {
127 3 : aicpusd_info("Get aicpu datadump Info load.");
128 3 : if (getDataDumpLoadInfoFuncMap_.find(version_) == getDataDumpLoadInfoFuncMap_.end()) {
129 1 : aicpusd_err("The version[%hu] does not have a corresponding get data dump load info Function.", version_);
130 1 : return;
131 : }
132 2 : (this->*getDataDumpLoadInfoFuncMap_[version_])(info);
133 2 : return;
134 : }
135 :
136 1 : int32_t AicpuSqeAdapter::AicpuDataDumpLoadResponseToTsV1(const int32_t ret)
137 : {
138 1 : TsAicpuMsgInfo msgInfo{};
139 1 : msgInfo.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
140 1 : msgInfo.vf_id = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
141 1 : msgInfo.tid = tid_;
142 1 : msgInfo.ts_id = ts_id_;
143 1 : msgInfo.cmd_type = cmd_type_;
144 1 : msgInfo.u.aicpu_resp.result_code = static_cast<uint16_t>(ret);
145 1 : msgInfo.u.aicpu_resp.stream_id = msg_Info_.u.ts_to_aicpu_datadump_info_load.stream_id;
146 1 : msgInfo.u.aicpu_resp.task_id = msg_Info_.u.ts_to_aicpu_datadump_info_load.task_id;
147 1 : aicpusd_info("Aicpu data dump load response info: cmd_type[%u], ret[%u], streamid[%u], taskid[%u].",
148 : msgInfo.cmd_type,
149 : ret,
150 : msgInfo.u.aicpu_resp.stream_id,
151 : msgInfo.u.aicpu_resp.task_id);
152 2 : return ResponseToTs(msgInfo, 0U, AicpuDrvManager::GetInstance().GetDeviceId(), msgInfo.ts_id);
153 : }
154 :
155 1 : int32_t AicpuSqeAdapter::AicpuDataDumpLoadResponseToTsV0(const int32_t ret)
156 : {
157 1 : TsAicpuSqe aicpuSqe{};
158 1 : aicpuSqe.pid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
159 1 : aicpuSqe.vf_id = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
160 1 : aicpuSqe.tid = tid_;
161 1 : aicpuSqe.ts_id = ts_id_;
162 1 : aicpuSqe.cmd_type = AICPU_DATADUMP_RESPONSE;
163 1 : aicpuSqe.u.aicpu_dump_resp.result_code = static_cast<uint16_t>(ret);
164 1 : aicpuSqe.u.aicpu_dump_resp.cmd_type = AICPU_DATADUMP_LOADINFO;
165 1 : aicpuSqe.u.aicpu_dump_resp.task_id = sqe_.u.ts_to_aicpu_datadumploadinfo.task_id;
166 1 : aicpuSqe.u.aicpu_dump_resp.stream_id = sqe_.u.ts_to_aicpu_datadumploadinfo.stream_id;
167 1 : aicpuSqe.u.aicpu_dump_resp.reserved = STARS_DATADUMP_LOAD_INFO;
168 1 : aicpusd_info("Aicpu data dump load response info: cmd_type[%u], ret[%u], streamid[%u], taskid[%u].",
169 : aicpuSqe.cmd_type,
170 : ret,
171 : aicpuSqe.u.aicpu_dump_resp.stream_id,
172 : aicpuSqe.u.aicpu_dump_resp.task_id);
173 2 : return ResponseToTs(aicpuSqe, 0U, AicpuDrvManager::GetInstance().GetDeviceId(), aicpuSqe.ts_id);
174 : }
175 :
176 3 : int32_t AicpuSqeAdapter::AicpuDataDumpLoadResponseToTs(const int32_t ret)
177 : {
178 3 : aicpusd_info("Aicpu datadump load response to ts.");
179 3 : if (getDataDumpLoadRspFuncMap_.find(version_) == getDataDumpLoadRspFuncMap_.end()) {
180 1 : aicpusd_err("The version[%hu] does not have a corresponding get data dump load response Function.", version_);
181 1 : return AICPU_SCHEDULE_ERROR_NOT_FOUND_FUNCTION;
182 : }
183 2 : return (this->*getDataDumpLoadRspFuncMap_[version_])(ret);
184 : }
185 :
186 1 : int32_t AicpuSqeAdapter::ResponseToTs(
187 : TsAicpuSqe &aicpuSqe, unsigned int handleId, unsigned int devId, unsigned int tsId)
188 : {
189 1 : aicpusd_info("Begin to response use TsAicpuSqe.");
190 1 : const auto ret = tsDevSendMsgAsync(devId,
191 : static_cast<uint32_t>(tsId),
192 : PtrToPtr<TsAicpuSqe, char_t>(&aicpuSqe),
193 : static_cast<uint32_t>(sizeof(TsAicpuSqe)),
194 : handleId);
195 1 : AICPUSD_CHECK((ret == DRV_ERROR_NONE),
196 : AICPU_SCHEDULE_ERROR_INNER_ERROR,
197 : "Response to ts use"
198 : "tsDevSendMsgAsync failed, ret[%d]",
199 : ret);
200 1 : aicpusd_info("Finished to response use TsAicpuSqe.");
201 1 : return AICPU_SCHEDULE_OK;
202 : }
203 :
204 3 : int32_t AicpuSqeAdapter::ResponseToTs(
205 : TsAicpuMsgInfo &aicpuMsgInfo, unsigned int handleId, unsigned int devId, unsigned int tsId)
206 : {
207 3 : aicpusd_info("Begin to response use TsAicpuMsgInfo.");
208 3 : const auto ret = tsDevSendMsgAsync(devId,
209 : static_cast<uint32_t>(tsId),
210 : PtrToPtr<TsAicpuMsgInfo, char_t>(&aicpuMsgInfo),
211 : static_cast<uint32_t>(sizeof(TsAicpuMsgInfo)),
212 : handleId);
213 3 : AICPUSD_CHECK((ret == DRV_ERROR_NONE),
214 : AICPU_SCHEDULE_ERROR_INNER_ERROR,
215 : "Response to ts use"
216 : "tsDevSendMsgAsync failed, ret[%d]",
217 : ret);
218 3 : aicpusd_info("Finished to response use TsAicpuMsgInfo.");
219 3 : return AICPU_SCHEDULE_OK;
220 : }
221 :
222 1 : int32_t AicpuSqeAdapter::ResponseToTs(hwts_response_t &hwtsResp, uint32_t devId, EVENT_ID eventId, uint32_t subeventId)
223 : {
224 1 : aicpusd_info("Begin to response use hwtsResp.");
225 1 : const drvError_t ret = halEschedAckEvent(devId,
226 : eventId,
227 : subeventId,
228 : PtrToPtr<hwts_response_t, char_t>(&hwtsResp),
229 : static_cast<uint32_t>(sizeof(hwts_response_t)));
230 1 : AICPUSD_CHECK((ret == DRV_ERROR_NONE),
231 : AICPU_SCHEDULE_ERROR_INNER_ERROR,
232 : "Response to ts use"
233 : "halEschedAckEvent failed, ret[%d]",
234 : ret);
235 1 : aicpusd_info("Finished to response use hwtsResp.");
236 1 : return AICPU_SCHEDULE_OK;
237 : }
238 : } // namespace AicpuSchedule
|