• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18 
19 #ifndef __HCC_HOST_H
20 #define __HCC_HOST_H
21 
22 #include "hi_types.h"
23 #include "hcc_comm.h"
24 #include "oal_ext_if.h"
25 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
26 #include "oal_sdio_host_if.h"
27 #include "oal_sdio_comm.h"
28 #include "oal_thread.h"
29 #endif
30 
31 #ifdef __cplusplus
32 #if __cplusplus
33 extern "C" {
34 #endif
35 #endif
36 
37 /* ****************************************************************************
38  宏定义
39 *****************************************************************************/
40 #define HCC_OFF         0
41 #define HCC_ON          1
42 #define HCC_EXCEPTION   2
43 
44 #define HCC_TX_FLOW_HI_LEVEL 512
45 #define HCC_TX_FLOW_LO_LEVEL 128
46 
47 #define HCC_FLOW_HIGH_PRI_BUFF_CNT  5 /* device侧预留的高优先级专用buffer个数,要与OAL_NETBUF_HIGH_PRIORITY_COUNT相同 */
48 #define HCC_FLOW_LOW_PRI_BUFF_CNT   5
49 
50 #define LOG_P0                   0
51 #define LOG_P1                   1
52 #define LOG_P2                   2
53 #define LOG_P3                   3
54 #define LOG_ID                   4
55 #define SHIF_8_BIT               8
56 #define WORD_WIDTH               4
57 
58 #define HCC_HEARTBEAT_TIMEOUT           (10 * 1000)
59 #define VERIFY_CODE                     0x55aa55aa
60 #define HCC_NETBUF_RESERVED_ROOM_SIZE   (HCC_HDR_TOTAL_LEN + HISDIO_H2D_SCATT_BUFFLEN_ALIGN)
61 
62 /* ****************************************************************************
63  枚举定义
64 **************************************************************************** */
65 typedef enum {
66     HCC_FLOWCTRL_SDIO,
67     HCC_FLOWCTRL_CREDIT,
68     HCC_FLOWCTRL_BUTT
69 } hcc_flowctrl_type;
70 
71 typedef enum {
72     HCC_SINGLE_SEND = 0,
73     HCC_ASSEM_SEND,
74     HCC_MODE_COUNT
75 } hcc_send_mode;
76 
77 typedef enum {
78     HCC_TX,
79     HCC_RX,
80     HCC_DIR_COUNT
81 } hcc_chan_type;
82 
83 typedef hi_s32 (* hcc_rx_pre_do)(hi_u8 stype, hcc_netbuf_stru *pst_netbuf, hi_u8 **pre_do_context);
84 typedef hi_s32 (* hcc_rx_post_do)(hi_u8 stype, const hcc_netbuf_stru *pst_netbuf, hi_u8 *pre_do_context);
85 
86 #ifndef _PRE_FEATURE_HCC_TASK
87 typedef struct {
88     hcc_queue_type_enum queueType;
89     bool isVip;
90 } hcc_convert_queue_para;
91 #endif
92 
93 typedef struct {
94     hi_u32              pkts_count;
95     hcc_rx_pre_do       pre_do;
96     hcc_rx_post_do      post_do;
97     hi_void            *context;    /* the callback argument */
98 }hcc_rx_action_stru;
99 
100 typedef struct {
101     hcc_rx_action_stru action[HCC_ACTION_TYPE_BUTT];
102 } hcc_rx_action_info_stru;
103 
104 /* ****************************************************************************
105  结构体定义
106 **************************************************************************** */
107 typedef sdio_msg_rx hcc_msg_rx;
108 
109 typedef struct {
110     hi_u8                       flowctrl_flag;
111     hi_u8                       enable;
112     hi_u16                      flow_type;
113     hi_u16                      is_stopped;
114     hi_u16                      low_waterline;
115     hi_u16                      high_waterline;
116 } hcc_flow_ctrl_stru;
117 
118 typedef struct {
119     /* transfer pkts limit every loop */
120     hi_u32                      netbuf_pool_type;
121     hi_u32                      burst_limit;
122     hcc_flow_ctrl_stru          flow_ctrl;
123     hcc_send_mode               send_mode;
124     hi_u32                      total_pkts;
125     hi_u32                      loss_pkts;
126     oal_netbuf_head_stru        data_queue;
127     oal_spin_lock_stru          data_queue_lock;
128     wlan_net_queue_type         wlan_queue_id;
129 } hcc_trans_queue_stru;
130 
131 #define HCC_TX_ASSEM_INFO_MAX_NUM (HISDIO_HOST2DEV_SCATT_MAX + 1)
132 #define HCC_RX_ASSEM_INFO_MAX_NUM (HISDIO_DEV2HOST_SCATT_MAX + 1)
133 
134 typedef struct {
135     hcc_trans_queue_stru queues[HCC_QUEUE_COUNT];
136 } hcc_trans_queues_stru;
137 
138 typedef struct {
139     /* The +1 for the single pkt */
140     hi_u32 info[HCC_TX_ASSEM_INFO_MAX_NUM];
141 
142     /* The max support assemble pkts */
143     hi_u32 assemble_max_count;
144     /* netx assem pkts list */
145     oal_netbuf_head_stru assembled_head;
146     /* the queue is assembling */
147     hcc_queue_type_enum assembled_queue_type;
148 } hcc_tx_assem_info_stru;
149 
150 typedef struct {
151     hi_u32 info[HCC_RX_ASSEM_INFO_MAX_NUM];
152 } hcc_rx_assem_info;
153 
154 typedef hi_void (*flowctrl_cb)(hi_void);
155 
156 typedef struct {
157     hi_u32                      flowctrl_flag;
158     hi_u32                      flowctrl_on_count;
159     hi_u32                      flowctrl_off_count;
160     hi_u32                      flowctrl_reset_count;
161     hi_u32                      flowctrl_hipri_update_count;
162     hi_u8                       uc_hipriority_cnt;
163     hi_u8                       uc_lopriority_cnt;
164     hi_u8                       des_cnt;
165     hi_u8                       auc_resv[2];                 /* resv 2 对齐 */
166     oal_spin_lock_stru          st_hipri_lock;  /* 读写uc_hipriority_cnt时要加锁 */
167     oal_wait_queue_head_stru    wait_queue;
168     flowctrl_cb                 net_stopall;
169     flowctrl_cb                 net_startall;
170 #ifdef _PRE_WLAN_FEATURE_OFFLOAD_FLOWCTL
171     hcc_flowctl_get_mode    get_mode;
172     hcc_flowctl_stop_subq   stop_subq;
173     hcc_flowctl_start_subq  start_subq;
174 #endif
175     oal_timer_list_stru         flow_timer;
176     unsigned long               timeout;
177     oal_delayed_work  worker;
178     oal_spin_lock_stru lock;
179 } hcc_tx_flow_ctrl_info_stru;
180 
181 typedef struct {
182     hi_u8                       descr_num;
183     oal_netbuf_head_stru        tx_assem_descr_hdr;
184 } hcc_tx_assem_descr;
185 
186 typedef enum {
187     TIMER_ADD,
188     TIMER_RUNING,
189     TIMER_STOP,
190     TIMER_DEL
191 } hcc_timer_status;
192 
193 typedef struct {
194     hi_u32 verify_code;
195     hi_u32 timeout; /* device多长时间(单位:S) 没有收到心跳,则复位 */
196 } hcc_heartbeat_stru;
197 
198 typedef struct {
199     hi_u32 is_open;
200     hi_u32 reserve;
201 } hcc_open_gpio_soft_rest;
202 
203 typedef struct {
204     oal_kthread_stru            *hcc_transfer_thread;
205     oal_kthread_stru            *hcc_rx_thread;
206     oal_wait_queue_head_stru    hcc_transfer_wq;
207     oal_wait_queue_head_stru    hcc_rx_wq;
208     oal_timer_list_stru         hcc_timer;
209     hcc_timer_status            hcc_timer_status;
210 #ifdef _PRE_CONFIG_WLAN_THRANS_THREAD_DEBUG
211     hcc_thread_stat             thread_stat;
212 #endif
213     hcc_trans_queues_stru       hcc_queues[HCC_DIR_COUNT];
214     hcc_tx_assem_info_stru      tx_assem_info;
215     hcc_rx_assem_info           rx_assem_info;
216     hcc_tx_flow_ctrl_info_stru  tx_flow_ctrl;
217     hcc_rx_action_info_stru     rx_action_info;
218 #if(_PRE_OS_VERSION==_PRE_OS_VERSION_LITEOS)
219     hi_u32                    taskid;
220 #endif
221 } hcc_transfer_handler_stru;
222 
223 typedef hi_u8 oal_bool_enum_uint8;
224 typedef hi_s32 (*hmac_tcp_ack_process_func)(hi_void);
225 typedef oal_bool_enum_uint8 (*hmac_tcp_ack_need_schedule_func)(hi_void);
226 
227 typedef struct {
228     oal_atomic                  state;
229     oal_atomic                  tx_seq;
230     struct BusDev               *bus;
231     unsigned long               hdr_rever_max_len;
232 
233     oal_mutex_stru              tx_transfer_lock;
234     oal_wakelock_stru           tx_wake_lock;
235 
236     hcc_transfer_handler_stru hcc_transer_info;
237 
238     /* the tx descr info, first descr */
239     hcc_tx_assem_descr          tx_descr_info;
240     hmac_tcp_ack_process_func   p_hmac_tcp_ack_process_func;
241     hmac_tcp_ack_need_schedule_func p_hmac_tcp_ack_need_schedule_func;
242 } hcc_handler_stru;
243 
244 typedef hi_void (*hcc_tx_cb_callback)(hcc_handler_stru *hcc);
245 
246 #define HCC_TX_WAKELOCK_MAGIC 0xdead5ead
247 typedef struct {
248     hcc_tx_cb_callback destroy;
249     hi_u32 magic;
250 } hcc_tx_cb_stru;
251 
252 /* device侧结构体 */
253 #define HI_SYSERR_EXC_TASK_NAME_SIZE 8
254 
255 typedef struct {
256     hi_u8 timer_usage; /* *< Number of used system timers.CNcomment:当前使用系统定时器个数 CNend */
257     hi_u8 task_usage;  /* *< Number of used tasks.CNcomment:当前使用任务个数 CNend */
258     hi_u8 sem_usage;   /* *< Number of used semaphores.CNcomment:当前使用信号量个数 CNend */
259     hi_u8 queue_usage; /* *< Number of used message queues.CNcomment:当前使用消息队列个数 CNend */
260     hi_u8 mux_usage;   /* *< Number of used mutexes.CNcomment:当前使用互斥锁个数 CNend */
261     hi_u8 event_usage; /* *< Number of used events.CNcomment:当前使用事件个数 CNend */
262     hi_u16 err_info;   /* *< Error statistic HI_OS_STAT_XXX, used to log occurred errors.
263                           CNcomment:错误统计量HI_OS_STAT_XXX,用于记录曾经出现过的错误 CNend */
264 } hi_os_resource_use_stat;
265 
266 typedef struct {
267     hi_char name[HI_SYSERR_EXC_TASK_NAME_SIZE];
268     hi_u32 id;            /* *< task id.CNcomment:任务ID.CNend */
269     hi_u32 status;        /* *< task status.CNcomment:任务运行状态.CNend */
270     hi_u16 stack_peak;    /* *< stack peak.CNcomment:栈使用峰值.CNend */
271     hi_u16 stack_size;    /* *< stack size.CNcomment:任务栈大小.CNend */
272     hi_u32 sp;            /* *< stack point.CNcomment:栈指针.CNend */
273     hi_u32 stack[2];      /* *< stack[2] is stack top and end address.CNcomment:栈顶和栈底地址.CNend */
274     hi_u32 real_sp;       /* *< real stack point.CNcomment:真实栈指针.CNend */
275     hi_u32 overflow_flag; /* *< stack overflow flag.CNcomment:栈溢出标识.CNend */
276 } syserr_task_info;
277 
278 typedef struct {
279     hi_u32 pool_addr;    /* 内存池地址 */
280     hi_u32 pool_size;    /* 内存池大小 */
281     hi_u32 fail_count;   /* 内存申请失败计数 */
282     hi_u32 peek_size;    /* 内存池使用峰值 */
283     hi_u32 cur_use_size; /* 内存池已经使用大小(单位:byte) */
284 } hi_mem_pool_crash_info;
285 
286 
287 typedef struct {
288     hi_os_resource_use_stat usage; /* *< os resource used count.CNcomment:系统资源使用个数.CNend */
289     syserr_task_info task;         /* *< task information.CNcomment:任务信息.CNend */
290     hi_mem_pool_crash_info mem;    /* *< memory pool information.CNcomment:动态内存池信息.CNend */
291 } syserr_os_info;
292 
293 typedef struct {
294     hi_u32 mepc;
295     hi_u32 ra;
296     hi_u32 sp;
297     hi_u32 gp;
298     hi_u32 tp;
299     hi_u32 t0;
300     hi_u32 t1;
301     hi_u32 t2;
302     hi_u32 s0;
303     hi_u32 s1;
304     hi_u32 a0;
305     hi_u32 a1;
306     hi_u32 a2;
307     hi_u32 a3;
308     hi_u32 a4;
309     hi_u32 a5;
310 } syserr_reg_info;
311 
312 typedef struct {
313     hi_u32 mstatus;     /* *< CPU mstatus register value.CNcomment:CPU mstatus寄存器值.CNend */
314     hi_u32 mtval;       /* *< CPU mtval register value.CNcomment:CPU mtval寄存器值.CNend */
315     hi_u32 mcause;      /* *< CPU mcause register value.CNcomment:CPU mcause寄存器值.CNend */
316     hi_u32 ccause;      /* *< CPU ccause register value.CNcomment:CPU ccause寄存器值.CNend */
317     hi_u16 cur_task_id; /* *< current task id.CNcomment:当前任务ID.CNend */
318 } syserr_core_info;
319 
320 typedef struct {
321     syserr_os_info os_info;   /* *< OS data of crash information.CNcomment:死机OS信息.CNend */
322     syserr_reg_info reg_info; /* *< CPU registers of crash information.CNcomment:死机CPU寄存器信息.CNend */
323     syserr_core_info core_info; /* *< CPU CSR registers of crash information.CNcomment:死机CPU状态寄存器信息.CNend */
324 } hi_syserr_info;
325 
326 /* ****************************************************************************
327  全局变量声明
328 **************************************************************************** */
329 extern oal_netbuf_head_stru g_hcc_hmac_rx_netbuf;
330 extern hcc_handler_stru *g_hcc_host_handler;
331 extern hi_u8 g_hcc_sched_stat[FRW_EVENT_TYPE_BUTT];
332 extern hi_u8 g_hcc_flowctrl_stat[FRW_EVENT_TYPE_BUTT];
333 
334 /* ****************************************************************************
335  inline 函数定义
336 **************************************************************************** */
hcc_tx_transfer_lock(hcc_handler_stru * hcc)337 static inline void hcc_tx_transfer_lock(hcc_handler_stru *hcc)
338 {
339     oal_mutex_lock(&hcc->tx_transfer_lock);
340 }
341 
hcc_tx_transfer_unlock(hcc_handler_stru * hcc)342 static inline void hcc_tx_transfer_unlock(hcc_handler_stru *hcc)
343 {
344     if (OAL_WARN_ON(hcc == HI_NULL)) {
345         oal_io_print1("%s, hcc is null\n", (uintptr_t)__FUNCTION__);
346         return;
347     }
348 
349     oal_mutex_unlock(&hcc->tx_transfer_lock);
350 }
351 
hcc_rx_transfer_lock(const hcc_handler_stru * hcc)352 static inline void hcc_rx_transfer_lock(const hcc_handler_stru *hcc)
353 {
354     if (OAL_WARN_ON(hcc == HI_NULL)) {
355         oal_io_print1("%s, hcc is null\n", (uintptr_t)__FUNCTION__);
356         return;
357     }
358     oal_bus_rx_transfer_lock(hcc->bus);
359 }
360 
hcc_rx_transfer_unlock(const hcc_handler_stru * hcc)361 static inline void hcc_rx_transfer_unlock(const hcc_handler_stru *hcc)
362 {
363     if (OAL_WARN_ON(hcc == HI_NULL)) {
364         oal_io_print1("%s, hcc is null\n", (uintptr_t)__FUNCTION__);
365         return;
366     }
367     oal_bus_rx_transfer_unlock(hcc->bus);
368 }
369 
hcc_transfer_lock(hcc_handler_stru * hcc)370 static inline void hcc_transfer_lock(hcc_handler_stru *hcc)
371 {
372     if (OAL_WARN_ON(hcc == HI_NULL)) {
373         oal_io_print1("%s, hcc is null\n", (uintptr_t)__FUNCTION__);
374         return;
375     }
376 
377     hcc_rx_transfer_lock(hcc);
378 
379     hcc_tx_transfer_lock(hcc);
380 }
381 
hcc_transfer_unlock(hcc_handler_stru * hcc)382 static inline void hcc_transfer_unlock(hcc_handler_stru *hcc)
383 {
384     if (OAL_WARN_ON(hcc == HI_NULL)) {
385         oal_io_print1("%s, hcc is null\n", __FUNCTION__);
386         return;
387     }
388     hcc_tx_transfer_unlock(hcc);
389     hcc_rx_transfer_unlock(hcc);
390 }
391 
392 /* ****************************************************************************
393  函数声明
394 **************************************************************************** */
395 hi_s32 hcc_hmac_adapt_init(hi_void);
396 hi_u32 hcc_host_init(struct BusDev *bus);
397 hi_void hcc_host_exit(hcc_handler_stru *hcc);
398 hcc_handler_stru *hcc_host_get_handler(hi_void);
399 hi_void hcc_host_rx_queue_sched(hi_void);
400 hi_void hcc_host_tx_queue_sched(hi_void);
401 hi_s32 queues_flow_ctrl_check(hcc_handler_stru *hcc_handler, hcc_chan_type dir);
402 hi_s32 queues_len_check(hcc_handler_stru *hcc_handler, hcc_chan_type dir);
403 hi_void hcc_sched_transfer(hcc_handler_stru *hcc_handler);
404 hi_void hcc_print_device_mem_info(hi_void);
405 hi_void hi_wifi_device_deinit(const hcc_handler_stru *hcc_handler);
406 hi_void hcc_exit_task_thread(hcc_handler_stru *hcc);
407 hi_u8 hcc_get_thread_exit_flag(hi_void);
408 hi_s32 hcc_host_proc_tx_queue(hcc_handler_stru *hcc_handler, hcc_queue_type_enum type);
409 hi_s32 hcc_host_proc_rx_queue(hcc_handler_stru *hcc_handler, hcc_queue_type_enum type);
410 hi_void hcc_clear_all_queues(hcc_handler_stru *hcc_handler, hi_s32 is_need_lock);
411 hi_u8 hcc_list_overflow(hi_void);
412 hi_u32 hcc_host_tx(hcc_handler_stru *hcc_handler, oal_netbuf_stru *netbuf, const hcc_transfer_param *param);
413 hi_u32 hcc_send_control_msg(hcc_handler_stru *hcc_handler, hi_u8 sub_type, hi_u8 *buf, int len);
414 hi_s32 hi_wifi_enable_heart_beat(hi_bool enable);
415 hi_bool hi_wifi_get_heart_beat_enable(hi_void);
416 hi_u8 hcc_discard_key_frame(hi_void);
417 #ifdef __cplusplus
418 #if __cplusplus
419 }
420 #endif
421 #endif
422 
423 #endif
424