• 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: zdiag tx
15  * This file should be changed only infrequently and with great care.
16  */
17 #include "zdiag_tx.h"
18 #include "diag_channel_item.h"
19 #include "zdiag_mem.h"
20 #include "zdiag_debug.h"
21 #include "diag_adapt_layer.h"
22 #include "diag_dfx.h"
23 #include "errcode.h"
24 
zdiag_modify_pkt_before_2_hso(diag_channel_item_t * chan,msp_mux_packet_head_stru_t * mux_head)25 STATIC void zdiag_modify_pkt_before_2_hso(diag_channel_item_t *chan, msp_mux_packet_head_stru_t *mux_head)
26 {
27     if (mux_head->type == MUX_PKT_IND) {
28         mux_head->type = MUX_PKT_CMD;
29     }
30 
31     mux_head->au_id = chan->au_id;
32     mux_head->start_flag = MUX_START_FLAG;
33     mux_head->ver = MUX_PKT_VER;
34 }
35 
zdiag_pkt_router_hcc_tx(const diag_channel_item_t * chan,diag_pkt_handle_t * pkt,const msp_mux_packet_head_stru_t * mux_head)36 STATIC errcode_t zdiag_pkt_router_hcc_tx(const diag_channel_item_t *chan, diag_pkt_handle_t *pkt,
37     const msp_mux_packet_head_stru_t *mux_head)
38 {
39     unused(mux_head);
40     if (chan->tx_hook) {
41         return (errcode_t)chan->tx_hook(0, DFX_DATA_DIAG_PKT, pkt->data, pkt->data_len, pkt->data_cnt);
42     }
43 
44     return ERRCODE_FAIL;
45 }
46 
zdiag_pkt_router_hso_tx(diag_channel_item_t * chan,diag_pkt_handle_t * pkt,msp_mux_packet_head_stru_t * mux_head)47 STATIC errcode_t zdiag_pkt_router_hso_tx(diag_channel_item_t *chan, diag_pkt_handle_t *pkt,
48     msp_mux_packet_head_stru_t *mux_head)
49 {
50     dfx_log_debug("zdiag_pkt_router_hso_tx %d\r\n", pkt->data_cnt);
51     zdiag_modify_pkt_before_2_hso(chan, mux_head);
52     if (chan->tx_hook) {
53         if ((pkt->critical) != 0) {
54             return (errcode_t)chan->tx_hook(0, DFX_DATA_DIAG_PKT_CRITICAL, pkt->data, pkt->data_len, pkt->data_cnt);
55         } else {
56             return (errcode_t)chan->tx_hook(0, DFX_DATA_DIAG_PKT, pkt->data, pkt->data_len, pkt->data_cnt);
57         }
58     }
59 
60     return ERRCODE_FAIL;
61 }
62 
zdiag_pkt_router_tx(diag_pkt_handle_t * pkt)63 errcode_t zdiag_pkt_router_tx(diag_pkt_handle_t *pkt)
64 {
65     errcode_t ret;
66     msp_mux_packet_head_stru_t *mux_head = diag_pkt_handle_get_mux(pkt);
67     diag_addr dst = mux_head->dst;
68     diag_channel_item_t *chan = zdiag_dst_2_chan(dst);
69     diag_addr_attribute_t attribute = diag_adapt_addr_2_attribute(dst);
70     if (((uint32_t)attribute & DIAG_ADDR_ATTRIBUTE_HSO_CONNECT) != 0) {
71         ret = zdiag_pkt_router_hso_tx(chan, pkt, mux_head);
72     } else {
73         ret = zdiag_pkt_router_hcc_tx(chan, pkt, mux_head);
74     }
75 
76     return ret;
77 }
78