• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description: diag debug
15  * This file should be changed only infrequently and with great care.
16  */
17 
18 #include "zdiag_debug.h"
19 #include "diag_adapt_layer.h"
20 #include "soc_diag_util.h"
21 
22 #define DIAG_TYPE_CMD 0
23 #define DIAG_TYPE_IND 1
24 #define DIAG_TYPE_CMD_ACK 0x02
25 #define DIAG_TYPE_MGR_ACK 0x03 /* system ack */
26 
27 uint32_t g_dfx_debug_level = DIAG_LOG_LEVEL_ERROR;
28 
printf_mux_packet_ack(const char * str,msp_mux_packet_head_stru_t * mux_packet)29 STATIC void printf_mux_packet_ack(const char *str, msp_mux_packet_head_stru_t *mux_packet)
30 {
31     msp_diag_head_cnf_stru_t *cnf = (msp_diag_head_cnf_stru_t *)mux_packet->puc_packet_data;
32     dfx_log_debug("[%s][type is ack]\r\n", str);
33     dfx_log_debug("[%s][req][sn=0x%04x][param_size=0x%04x][cmd_id=0x%04x][ctrl=0x%02x][pad=0x%02x]\r\n",
34                   str, cnf->sn, cnf->param_size, cnf->cmd_id, cnf->ctrl, cnf->pad);
35     unused(cnf);
36     unused(str);
37 }
38 
printf_mux_packet_ind(const char * str,msp_mux_packet_head_stru_t * mux_packet)39 STATIC void printf_mux_packet_ind(const char *str, msp_mux_packet_head_stru_t *mux_packet)
40 {
41     msp_diag_head_ind_stru_t *ind = (msp_diag_head_ind_stru_t *)mux_packet->puc_packet_data;
42     dfx_log_debug("[%s][type is ind]\r\n", str);
43     dfx_log_debug("[%s][req][cmd_id=0x%04x][param_size=0x%04x]\r\n", str, ind->cmd_id, ind->param_size);
44     unused(ind);
45     unused(str);
46 }
47 
printf_mux_packet_cmd(const char * str,msp_mux_packet_head_stru_t * mux_packet)48 STATIC void printf_mux_packet_cmd(const char *str, msp_mux_packet_head_stru_t *mux_packet)
49 {
50     msp_diag_head_req_stru_t *req = (msp_diag_head_req_stru_t *)mux_packet->puc_packet_data;
51     dfx_log_debug("[%s][type is cmd]\r\n", str);
52 
53     dfx_log_debug("[%s][req][sn=0x%04x][crc16=0x%04x][cmd_id=0x%04x][param_size=0x%04x]\r\n",
54                   str, req->sn, req->crc16, req->cmd_id, req->param_size);
55     unused(req);
56     unused(str);
57 }
58 
printf_mux_packet_unknown(const char * str,const msp_mux_packet_head_stru_t * mux_packet)59 STATIC void printf_mux_packet_unknown(const char *str, const msp_mux_packet_head_stru_t *mux_packet)
60 {
61     unused(str);
62     unused(mux_packet);
63     dfx_log_debug("[%s][type is unknown]\r\n", str);
64 }
65 
printf_mux_packet_new(const char * str,msp_mux_packet_head_stru_t * mux_packet)66 STATIC void printf_mux_packet_new(const char *str, msp_mux_packet_head_stru_t *mux_packet)
67 {
68     dfx_log_debug("[%s][mux][cmd_id=0x%04x][start_flag=0x%08x][au_id=0x%08x][type=0x%02x][ver=0x%02x][crc16=0x%04x]["
69                   "packet_data_size=0x%04x]\r\n",
70                   str, mux_packet->cmd_id, mux_packet->start_flag, mux_packet->au_id, mux_packet->type, mux_packet->ver,
71                   mux_packet->crc16, mux_packet->packet_data_size);
72 
73     switch (mux_packet->type) {
74         case DIAG_TYPE_CMD_ACK:
75         case DIAG_TYPE_MGR_ACK:
76             printf_mux_packet_ack(str, mux_packet);
77             break;
78         case MUX_PKT_CMD:
79             printf_mux_packet_cmd(str, mux_packet);
80             break;
81         case MUX_PKT_IND:
82             printf_mux_packet_ind(str, mux_packet);
83             break;
84         default:
85             printf_mux_packet_unknown(str, mux_packet);
86             break;
87     }
88 }
89 
zdiag_debug_print_pkt_info(const char * str,uint8_t * pkt)90 void zdiag_debug_print_pkt_info(const char *str, uint8_t *pkt)
91 {
92     bool remote_pkt = false;
93     msp_mux_packet_head_stru_t *mux_head = (msp_mux_packet_head_stru_t *)pkt;
94     msp_diag_head_ind_stru_t *ind_head = NULL;
95     msp_diag_head_req_stru_t *cmd_head = NULL;
96 
97     dfx_log_debug("---------------------------------------- cmd_id=%d S\r\n", mux_head->cmd_id);
98 
99     if (mux_head->type == MUX_PKT_CMD) {
100         cmd_head = (msp_diag_head_req_stru_t *)mux_head->puc_packet_data;
101     } else {
102         ind_head = (msp_diag_head_ind_stru_t *)mux_head->puc_packet_data;
103     }
104 
105     if (remote_pkt) {
106         dfx_log_debug("[%s][HCC_HEAD]YES\r\n", str);
107     } else {
108         dfx_log_debug("[%s][HCC_HEAD]NO\r\n", str);
109     }
110 
111     dfx_log_debug("[%s][MUX_HEAD]start_flag=0x%x au_id=0x%x type=0x%x ver=0x%x cmd_id=0x%x src=0x%02x dst=0x%02x\r\n",
112                   str, mux_head->start_flag, mux_head->au_id, mux_head->type,
113                   mux_head->ver, mux_head->cmd_id, mux_head->src, mux_head->dst);
114 
115     dfx_log_debug("[%s][MUX_HEAD]src=0x%x dst=0x%x ctrl=0x%x crc16=0x%x packet_data_size=0x%x\r\n",
116                   str, mux_head->src, mux_head->dst, mux_head->ctrl, mux_head->crc16, mux_head->packet_data_size);
117 
118     if (cmd_head) {
119         unused(ind_head);
120         dfx_log_debug("[%s][cmd_head]cmd_id=0x%x param_size=0x%x sn=0x%x crc16=0x%x\r\n",
121                       str, cmd_head->cmd_id, cmd_head->param_size, cmd_head->sn, cmd_head->crc16);
122     } else {
123         dfx_log_debug("[%s][ind_head]cmd_id=0x%x param_size=0x%x\r\n", str, ind_head->cmd_id, ind_head->param_size);
124     }
125 
126     printf_mux_packet_new(str, mux_head);
127     dfx_log_debug("---------------------------------------------------E\r\n");
128 }
129 
zdiag_pkt_printf(const char * str,const diag_pkt_handle_t * pkt)130 void zdiag_pkt_printf(const char *str, const diag_pkt_handle_t *pkt)
131 {
132     msp_mux_packet_head_stru_t *mux = diag_pkt_handle_get_mux(pkt);
133     dfx_log_debug("%s cnt=%d data_len[0]=%d data_len[1]=%d data_len[2]=%d\r\n",
134                   str, pkt->data_cnt,
135                   pkt->data_len[DIAG_PKT_DATA_ID_DATA_0],
136                   pkt->data_len[DIAG_PKT_DATA_ID_DATA_1],
137                   pkt->data_len[DIAG_PKT_DATA_ID_DATA_2]);
138     dfx_log_debug("%s src=%d dst=%d\r\n", str, mux->src, mux->dst);
139     unused(mux);
140     unused(str);
141 }
142