• 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: the header file of hcc public interfacer.
15  * Author:
16  * Create: 2021-05-13
17  */
18 
19 #ifndef HCC_INTERFACE_H
20 #define HCC_INTERFACE_H
21 #include "td_type.h"
22 #include "hcc_types.h"
23 #include "hcc.h"
24 #include "hcc_bus.h"
25 #include "hcc_test.h"
26 #include "hcc_cfg_comm.h"
27 
28 #ifdef __cplusplus
29 #if __cplusplus
30 extern "C" {
31 #endif
32 #endif
33 
34 #define HCC_TASK_NAME_MAX_LEN 20
35 #define HCC_CHANNEL_INVALID TD_U8_MAX
36 
37 typedef struct {
38     hcc_bus_type bus_type;
39     hcc_queue_cfg *queue_cfg;
40     td_char *task_name;
41     td_u8 task_pri;
42     td_u8 service_max_cnt;
43     td_u16 tx_fail_num_limit;
44     td_u8 queue_len;
45     td_u8 unc_pool_low_limit;
46     td_u16 unc_pool_size;
47     td_u16 max_proc_packets_per_loop;
48     td_u16 rsv;
49 } hcc_channel_param;
50 
51 /* HCC通道初始化/去初始化 */
52 td_u8 hcc_init(hcc_channel_param *init);
53 td_void hcc_deinit(td_u8 chl);
54 
55 /* 获取逻辑通道句柄 */
56 hcc_handler *hcc_get_handler(td_u8 chl);
57 
58 /*
59  * 使能/禁能调度接收线程,禁能后将使用直调方式
60  */
61 td_void hcc_enable_rx_thread(td_u8 chl, td_bool enable);
62 
63 /*
64  * 使能/禁能调度发送线程,禁能后将使用直调方式
65  */
66 td_void hcc_enable_tx_thread(td_u8 chl, td_bool enable);
67 
68 /*
69  * 消息机制: 该机制只支持通知 msg id, 不支持传数据,若需要传输数据请使用 hcc_tx_data 接口;
70  * 参数service_type: 业务类型,由于每个业务使用的bus可能不同,因此需要传入 service type, hcc才能用对应的bus传输.
71  */
72 ext_errno hcc_message_register(td_u8 chl, td_u8 rsv, hcc_rx_msg_type msg_id, hcc_msg_rx cb, td_u8 *cb_data);
73 ext_errno hcc_message_unregister(td_u8 chl, td_u8 rsv, hcc_rx_msg_type msg_id);
74 
75 /*
76  * buf是hcc head + payloadl; hcc head由调用者分配空间,由hcc填充;
77  * len:hcc head + payload的总长度; len一定要大于hcc头的长度
78  * 返回值: 成功:EXT_ERR_SUCCESS, 失败:其他值
79  * 若返回失败需要接口调用者释放内存;
80  * 注:所有hcc收到的pkt长度都是包含了hcc头结构的长度。
81  */
82 ext_errno hcc_tx_data(td_u8 chl, td_u8 *buf, td_u16 len, hcc_transfer_param *param);
83 ext_errno hcc_bt_tx_data(td_u8 chl, td_u8 *data_buf, td_u16 len, hcc_transfer_param *param);
84 
85 /*
86  * 可使用该接口获取 hcc 头结构的长度, hcc_tx_data 接口需要预留 hcc头结构的空间;
87  * Rx callback 中业务也可以使用该接口获取hcc头长度,以偏移到实际 payload 所在位置;
88  */
89 td_u16 hcc_get_head_len(td_void);
90 
91 td_bool hcc_get_state(td_u8 chl);
92 
93 /*************************************************bus layer interface*******************************************/
94 ext_errno hcc_send_message(td_u8 chl, hcc_tx_msg_type msg_id, td_u8 rsv);
95 
96 /*
97  * 读寄存器
98  * chl: 指定通道的寄存器
99  * addr: 寄存器地址数组(sdio:建议高16bit配置为0x4001,低2bit配置为0,
100  *                       sdio只取addr中第2-15bit的值,其他bit的值忽略,
101  *                      因此即使不按照建议配置addr,读取的也依然是0x4001XXXX寄存器。)
102  * value: 保存寄存器值数组
103  */
104 ext_errno hcc_read_reg(td_u8 chl, td_u32 addr, td_u32 *value);
105 
106 /*
107  * 写寄存器
108  * chl: 指定通道的寄存器
109  * addr: 寄存器地址数组(sdio:建议高16bit配置为0x4001,低2bit配置为0,
110  *                      sdio只取addr中第2-15bit的值,其他bit的值忽略,
111  *                      因此即使不按照建议配置addr,被写入的也依然是0x4001XXXX寄存器。)
112  * value: 保存寄存器值数组
113  */
114 ext_errno hcc_write_reg(td_u8 chl, td_u32 addr, td_u32 value);
115 
116 /*
117  * 获取通道传输的数据对齐长度
118  */
119 td_u32 hcc_get_channel_align_len(td_u8 chl);
120 
121 /*
122  * 设置tx总线聚合层个数.
123  */
124 td_void hcc_set_tx_sched_count(td_u8 chl, td_u8 count);
125 
126 /*
127  * 检查并关hcc流控.
128  */
129 td_u32 hcc_flowctrl_check_with_off(td_u8 *data);
130 
131 /*************************************************service layer interface*******************************************/
132 
133 /*
134  * hcc_service_type :  业务枚举类型
135  * chl       :  通道ID
136  * hcc_adapt_ops    :  业务回调接口
137  */
138 /*
139  * 业务初始化,业务类型对应的adapt结构,包括业务的内存分配、流控处理、Rx calbback;
140  */
141 ext_errno hcc_service_init(td_u8 chl, hcc_service_type service_type, hcc_adapt_ops *adapt);
142 ext_errno hcc_service_deinit(td_u8 chl, hcc_service_type service_type);
143 /*
144  * 更新流控credit值
145  * 对流控方式为  HCC_FLOWCTRL_CREDIT  的队列才有效;
146  * RX端在内存管理中更新credit值
147  * TX端在发送时获取credit值,根据credit的水线决定是否发送;
148  * 注意: 如果要使用该流控方式,需要在 hcc_service_init 之后使用 hcc_service_update_credit 更新下初始值,否则为0
149  */
150 td_void hcc_service_update_credit(td_u8 chl, hcc_service_type serv, td_u32 credit);
151 
152 /*************************************************flow ctrl interface*******************************************/
153 /*
154  * 获取/设置 流控水线值
155  * chl: 逻辑通道
156  * direction: 队列方向
157  * q_id: 队列ID
158  * low_line: 低水线值
159  * high_line: 高水线值
160  */
161 ext_errno hcc_flow_ctrl_set_water_line(td_u8 chl, hcc_queue_dir direction, td_u8 q_id,
162                                        td_u8 low_line, td_u8 high_line);
163 ext_errno hcc_flow_ctrl_get_water_line(td_u8 chl, hcc_queue_dir direction, td_u8 q_id,
164                                        td_u8 *low_line, td_u8 *high_line);
165 td_void hcc_ipc_complement_mem(td_void);
166 
167 #ifdef CONFIG_HCC_SUPPORT_IPC
168 td_u32 hcc_ipc_prequeue_remaining_packets(td_u8 queue_id);
169 #endif
170 #ifdef __cplusplus
171 #if __cplusplus
172 }
173 #endif
174 #endif
175 #endif /* HCC_INTERFACE_H */
176