• 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: hcc module completion.
15  * Author:
16  * Create: 2021-05-13
17  */
18 
19 #ifndef HCC_MODULE_HEADER
20 #define HCC_MODULE_HEADER
21 
22 #include "td_type.h"
23 #include "soc_errno.h"
24 #include "hcc_queue.h"
25 #include "hcc_bus_types.h"
26 #include "hcc_dfx.h"
27 
28 #ifdef __cplusplus
29 #if __cplusplus
30 extern "C" {
31 #endif
32 #endif
33 
34 typedef struct _hcc_handler_ hcc_handler;
35 #define HCC_HDR_LEN hcc_get_head_len()
36 
37 typedef enum _hcc_module_init_errno_ {
38     HCC_MODULE_INIT_FAILED_INIT_STATE,
39     HCC_MODULE_INIT_FAILED_SET_STATE,
40     HCC_MODULE_INIT_FAILED_INIT_UNC_POOL,
41     HCC_MODULE_INIT_FAILED_INIT_QUEUE,
42     HCC_MODULE_INIT_FAILED_INIT_FLOW_CTRL,
43     HCC_MODULE_INIT_FAILED_INIT_TASK,
44     HCC_MODULE_INIT_FAILED_ADD_HANDLER,
45 } hcc_module_init_errno;
46 
47 #define HCC_DISABLE TD_FALSE
48 #define HCC_ENABLE  TD_TRUE
49 
50 #pragma pack(push, 1)
51 /* 4bytes */
52 typedef struct _hcc_header_ {
53     td_u8 sub_type : 4;  /* sub type to hcc type,refer to hcc_action_type */
54     td_u8 service_type : 4; /* main type to hcc type,refer to hcc_action_type */
55     td_u8 queue_id;  /* 队列ID, TX-RX队列为对应关系 */
56     td_u16 pay_len; /* payload的长度 */
57 } hcc_header;
58 #pragma pack(pop)
59 
60 typedef struct _hcc_serv_info_ {
61     td_u32 service_type : 4;
62     td_u32 bus_type : 4;
63     td_u32 rsv : 24;
64     osal_atomic service_enable;  /* enable after hcc_service_init */
65     hcc_adapt_ops *adapt;
66 } hcc_serv_info;
67 
68 typedef struct _hcc_service_list_ {
69     struct osal_list_head  service_list;
70     hcc_serv_info *service_info;
71 } hcc_service_list;
72 
73 typedef struct _hcc_transfer_resource_ {
74 #ifndef CONFIG_HCC_SUPPORT_NON_OS
75     osal_wait hcc_transfer_wq;
76     osal_wait hcc_fc_wq;
77     osal_task *hcc_transfer_thread_handler; // 主循环task
78 #endif
79 
80     td_u32 cur_trans_pkts : 12;
81     td_u32 max_proc_packets_per_loop : 12;
82     td_u32 rx_thread_enable : 1;
83     td_u32 tx_thread_enable : 1;
84     td_u32 task_run : 2;
85     td_u32 rsv : 4;
86 
87     td_u32 tx_fail_num_limit : 12;
88     td_u32 tx_fail_cnt : 12;
89     td_u32 rsv1 : 8;
90 
91     hcc_trans_queue *hcc_queues[HCC_DIR_COUNT];
92 } hcc_trans_resource;
93 
94 struct _hcc_handler_ {
95     hcc_data_queue *unc_pool_head;
96     hcc_trans_resource hcc_resource;
97     hcc_service_list hcc_serv; /* hcc注册的服务 */
98     hcc_bus *bus; /* 与当前逻辑通道对应的物理通道的结构 */
99     hcc_queue_cfg *que_cfg;
100     hcc_dfx *dfx_handle;
101     td_u8 que_max_cnt;
102     td_u8 srv_max_cnt;
103     td_u8 channel_id;
104     td_u8 unc_low_limit;
105     td_u8 hcc_state;  // HCC状态,使能、禁能、异常使用
106 };
107 
108 td_u32 hcc_check_overrun(hcc_handler *hcc);
109 td_void hcc_handle_tx_fail(hcc_handler *hcc);
110 td_u32 hcc_get_transfer_packet_num(hcc_handler *hcc);
111 td_s32 hcc_transfer_thread(td_void *data);
112 td_u16 hcc_tx_queue_proc(hcc_handler *hcc, hcc_trans_queue *queue);
113 hcc_service_type hcc_fuzzy_trans_queue_2_service(hcc_handler *hcc, hcc_queue_type queue_id);
114 hcc_service_type hcc_queue_id_2_service_type(hcc_handler *hcc, hcc_queue_dir dir, hcc_queue_type queue_id);
115 ext_errno hcc_sched_transfer(hcc_handler *hcc);
116 td_u16 hcc_rx_queue_proc(hcc_handler *hcc, hcc_trans_queue *queue);
117 td_void hcc_change_state(osal_atomic *atomic, td_u32 state);
118 td_bool hcc_check_header_vaild(TD_CONST hcc_handler *hcc, TD_CONST hcc_header *hdr);
119 td_void hcc_init_unc_buf(hcc_unc_struc *unc_buf, td_u8* buf, td_u32 len, hcc_transfer_param *param);
120 
121 /* HCC state */
122 typedef enum {
123     HCC_OFF = 0,    /* 关闭状态,不允许调用HCC接口发送数据 */
124     HCC_ON,         /* 打开状态,允许调用HCC接口收发数据 */
125     HCC_EXCEPTION,  /* 异常状态 */
126     HCC_BUS_FORBID, /* 禁止hcc bus reg 操作 */
127     HCC_STATE_END
128 } hcc_state_enum;
129 
130 td_void hcc_enable_switch(td_u8 chl, td_bool enable);
131 
132 td_s32 hcc_resume_xfer(td_u8 chl);
133 td_s32 hcc_stop_xfer(td_u8 chl);
134 
135 ext_errno hcc_dfx_init(hcc_handler *hcc);
136 td_void hcc_dfx_queue_total_pkt_increase(hcc_handler *hcc, hcc_service_type serv_type, hcc_queue_dir dir,
137                                          hcc_queue_type q_id, td_u8 cnt);
138 td_void hcc_dfx_queue_loss_pkt_increase(hcc_handler *hcc, hcc_queue_dir dir, hcc_queue_type q_id);
139 
140 /*
141  * 一个service对应多个队列,记录service的同时记录对应的queue 申请内存成功失败的次数
142  */
143 /* 回调业务alloc次数 */
144 td_void hcc_dfx_service_alloc_cb_cnt_increase(hcc_handler *hcc, hcc_service_type service_type);
145 /* 业务内存alloc返回成功或失败次数,异常时可能会有参数不正确问题 */
146 td_void hcc_dfx_service_alloc_cnt_increase(hcc_handler *hcc, hcc_service_type service_type,
147                                            hcc_queue_type queue_id, td_bool success);
148 /* 回调业务free次数 */
149 td_void hcc_dfx_service_free_cnt_increase(hcc_handler *hcc, hcc_service_type service_type);
150 
151 /* hcc链表、业务内存释放次数 */
152 td_void hcc_dfx_mem_free_cnt_increase(hcc_handler *hcc);
153 td_void hcc_dfx_unc_free_cnt_increase(hcc_handler *hcc);
154 /* hcc链表TX/RX方向申请成功或失败次数 */
155 td_void hcc_dfx_unc_alloc_cnt_increase(hcc_handler *hcc, hcc_queue_dir direction, td_bool success);
156 td_void hcc_dfx_service_total_increase(hcc_handler *hcc);
157 
158 td_void hcc_dfx_service_startsubq_cnt_increase(hcc_handler *hcc, hcc_service_type service_type);
159 td_void hcc_dfx_service_stopsubq_cnt_increase(hcc_handler *hcc, hcc_service_type service_type);
160 td_void hcc_dfx_service_rx_cnt_increase(hcc_handler *hcc, hcc_service_type service_type, hcc_queue_type queue_id);
161 td_void hcc_dfx_service_exp_rx_cnt_increase(hcc_handler *hcc, hcc_service_type service_type);
162 
163 td_void hcc_dfx_service_rx_err_cnt_increase(hcc_handler *hcc, hcc_service_type service_type);
164 
165 #ifdef __cplusplus
166 #if __cplusplus
167 }
168 #endif
169 #endif
170 
171 #endif /* HCC_MODULE_HEADER */
172