• 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 bus types.
15  * Author:
16  * Create: 2021-05-13
17  */
18 
19 #ifndef HCC_BUS_TYPES_HEADER
20 #define HCC_BUS_TYPES_HEADER
21 
22 #include "td_type.h"
23 #include "hcc_types.h"
24 #include "soc_osal.h"
25 #include "hcc_queue.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_BUS_STATE_TX    (1 << 0)
35 #define HCC_BUS_STATE_RX    (1 << 1)
36 #define HCC_BUS_STATE_ALL   (HCC_BUS_STATE_TX | HCC_BUS_STATE_RX)
37 
38 #define HCC_RX_MAX_MESSAGE 32
39 #define HCC_TX_MAX_MESSAGE 32
40 
41 /* Power Action */
42 typedef enum _hcc_bus_power_action_type_ {
43     HCC_BUS_POWER_DOWN,               /* The action when wlan power down */
44     HCC_BUS_POWER_UP,                 /* The action when wlan power up */
45     HCC_BUS_POWER_PATCH_LOAD_PREPARE, /* The action before patch downlaod */
46     HCC_BUS_POWER_PATCH_LAUCH,        /* The action after patch download before channel enabled */
47     HCC_BUS_POWER_BUTT
48 } hcc_bus_power_action_type;
49 
50 /*
51  * bus层传输约束
52  */
53 enum {
54     HCC_ADDR_ALIGN_MIN = 1,      /* 数据首地址1字节对齐 */
55     HCC_ADDR_ALIGN_WORD = 4,     /* 数据首地址4字节对齐 */
56 };
57 
58 enum {
59     HCC_DATA_LEN_ALIGN_MIN = 1,      /* 数据长度1字节对齐 */
60     HCC_DATA_LEN_ALIGN_WORD = 4,     /* 数据长度4字节对齐 */
61     HCC_DATA_LEN_ALIGN_DWORD = 8,     /* 数据长度8字节对齐 */
62     HCC_DATA_LEN_ALIGN_QWORD = 16,     /* 数据长度16字节对齐 */
63     HCC_DATA_LEN_ALIGN_32BYTES = 32,     /* 数据长度32字节对齐 */
64 };
65 
66 #define HCC_ADAPT_BUS_ASSEMBLE_CNT_MIN 1     /* 支持的最小聚合长度,为1则和不聚合一致 */
67 #define HCC_ADAPT_BUS_DESCR_ALIGN_BIT_MIN 0  /* 描述符需要左移几bit位,与描述符对齐长度相对应 */
68 
69 typedef td_s32 (*bus_pm_notify)(td_void);
70 typedef struct _hcc_bus_ hcc_bus;
71 typedef struct _bus_dev_ops {
72     td_u32 (*tx_proc)(hcc_bus *bus, hcc_trans_queue *queue, td_u16 *remain_pkt_nums);
73     ext_errno (*send_and_clear_msg)(TD_CONST hcc_bus *bus, td_u32 msg);
74     td_bool (*is_busy)(hcc_queue_dir dir);
75     td_void (*update_credit)(TD_CONST hcc_bus *bus, td_u32 free_cnt);  /* credit流控方式,在SDIO上只有 device->host */
76     td_s32 (*get_credit)(hcc_bus *bus, td_u32 *free_cnt);
77 #ifdef CONFIG_HCC_SUPPORT_REG_OPT
78     td_s32 (*read_reg)(td_u32 addr, td_u32 *value);
79     td_s32 (*write_reg)(td_u32 addr, td_u32 value);
80 #endif
81 #ifdef CONFIG_HCC_SUPPORT_PATCH_OPT
82     td_s32 (*patch_read)(hcc_bus *pst_bus, td_u8 *buff, td_u32 len, td_u32 timeout);
83     td_s32 (*patch_write)(hcc_bus *pst_bus, td_u8 *buff, td_u32 len);
84 #endif
85     td_s32 (*reinit)(hcc_bus *pst_bus);                                         /* ip reinit */
86     td_void (*stop_xfer)(td_void);
87     td_s32 (*resume_xfer)(td_void);
88     td_void (*flow_off)(hcc_bus *bus, td_bool check);
89     td_void (*flow_on)(hcc_bus *bus, td_bool unc_alloc);
90     td_s32 (*power_action)(hcc_bus *pst_bus, hcc_bus_power_action_type action); /* do something before power on/off */
91     td_s32 (*sleep_request)(hcc_bus *pst_bus);
92     td_s32 (*wakeup_request)(hcc_bus *pst_bus);
93     td_s32 (*pm_notify_register)(hcc_bus *pst_bus, bus_pm_notify suspend_func, bus_pm_notify resume_func);
94 } bus_dev_ops;
95 
96 struct bus_msg_stru {
97     hcc_msg_rx msg_rx;
98     td_void *data;
99     osal_atomic count;
100 };
101 
102 typedef td_void (*hcc_bus_dfx_f)(td_void);
103 typedef td_s32 (*hcc_service_f)(hcc_bus *bus, hcc_service_type service_type);
104 struct _hcc_bus_ {
105     td_u32 bus_type : 4; /* Current bus type: HCC_BUS_TYPE */
106     td_u32 max_trans_size : 12; /* Max size for each package */
107     td_u32 addr_align : 8; /* Buffer address of each package must aligned to this */
108     td_u32 len_align : 8;  /* Buffer length of each package must aligned to this */
109     td_u32 max_assemble_cnt : 8;  /* Max assemble count if bus support assemble. Fill 1 if not support. */
110     td_u32 descr_align_bit : 4;  /* Description aligned bits. */
111     td_void *hcc;  /* HCC handler, struct type: hcc_handler */
112     td_void *data; /* device driver structure reference */
113     hcc_unc_struc *rsv_buf; /* 预留缓存,由bus层根据驱动需要申请。
114                              * 使用场景(sdio为例):驱动获取不到内存可使用该缓存,但不会传给hcc,
115                              * 预留内存中的数据会被丢弃,以防止因获取不到内存导致驱动异常。
116                              */
117     hcc_bus_dfx_f hcc_bus_dfx;
118     hcc_service_f hcc_srv_hook;
119     bus_dev_ops *bus_ops;
120 
121     struct bus_msg_stru msg[HCC_RX_MAX_MESSAGE];
122     td_u32 last_msg;
123     td_u32 state : 4;
124     td_u32 tx_sched_count : 8; /* 发送聚合度 */
125     td_u32 force_update_queue_id : 8; /* 是否需要强制发送hcc队列信息 */
126     td_u32 cap_max_trans_size;
127 };
128 
129 #ifdef __cplusplus
130 #if __cplusplus
131 }
132 #endif
133 #endif
134 
135 #endif /* HCC_BUS_TYPES_HEADER */
136