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_COMM_H
20 #define __HCC_COMM_H
21
22 /* ****************************************************************************
23 1 其他头文件包含
24 **************************************************************************** */
25 #include "hi_types.h"
26 #include "frw_event.h"
27
28 #ifdef __cplusplus
29 #if __cplusplus
30 extern "C" {
31 #endif
32 #endif
33
34
35 /* ****************************************************************************
36 2 宏定义
37 *****************************************************************************/
38 #define hcc_get_event_hdr(pst_event) ((pst_event)->event_hdr)
39 #define hcc_get_event_payload(pst_event) ((hi_u8*)((pst_event)->auc_event_data))
40 #define hcc_get_event_len(pst_event) ((pst_event)->event_hdr.us_length)
41
42 #define hcc_field_setup(_p, _m, _v) ((_p)->_m = (_v))
43
44 /* 事件头初始化宏 */
45 #define hcc_mac_event_hdr_init(_pst_event_hdr, _en_type, _uc_sub_type, _uc_chip_id, _uc_device_id, _uc_vap_id, \
46 _us_length) \
47 do { \
48 hcc_field_setup((_pst_event_hdr), en_type, (_en_type)); \
49 hcc_field_setup((_pst_event_hdr), uc_sub_type, (_uc_sub_type)); \
50 hcc_field_setup((_pst_event_hdr), uc_chip_id, (_uc_chip_id)); \
51 hcc_field_setup((_pst_event_hdr), uc_device_id, (_uc_device_id)); \
52 hcc_field_setup((_pst_event_hdr), uc_vap_id, (_uc_vap_id)); \
53 hcc_field_setup((_pst_event_hdr), us_length, (_us_length)); \
54 } while (0)
55
56 #define HCC_TEST_CMD_START_TX 0
57 #define HCC_TEST_CMD_START_RX 1
58 #define HCC_TEST_CMD_START_LOOP 2
59 #define HCC_TEST_CMD_STOP_TEST 3
60
61 /* hcc tx transfer flow control */
62 #define HCC_FC_NONE 0x0 /* 无流控 */
63 #define HCC_FC_WAIT 0x1 /* 阻塞等待,如果是在中断上下文调用,该标记被自动清除,非中断上下文生效 */
64 #define HCC_FC_NET 0x2 /* 对于网络层的流控 */
65 #define HCC_FC_DROP 0x4 /* 流控采用丢包方式,流控时返回成功 */
66 #define HCC_FC_ALL (HCC_FC_WAIT | HCC_FC_NET | HCC_FC_DROP)
67
68 #define HCC_CONFIG_FRAME 0x80
69
70 #undef CONFIG_HCC_DEBUG
71 #undef CONFIG_HCC_TX_MULTI_BUF_CHECK
72 #define CONFIG_HCC_HEADER_CHECK_SUM
73
74 /* ****************************************************************************
75 2 结构体定义
76 **************************************************************************** */
77 typedef enum {
78 HCC_NETBUF_NORMAL_QUEUE = 0, /* netbuf is shared with others */
79 HCC_NETBUF_HIGH_QUEUE = 1, /* netbuf is special for high pri */
80 HCC_NETBUF_QUEUE_BUTT
81 } hcc_netbuf_queue_type_enum;
82
83 /* ****************************************************************************
84 结构名 : frw_event_hdr_stru
85 结构说明: 事件头结构体,
86 备注 : uc_length的值为(payload长度 + 事件头长度 - 2)
87 **************************************************************************** */
88 typedef struct {
89 hi_u8 type; /* 事件类型 */
90 hi_u8 sub_type; /* 事件子类型 */
91 hi_u8 chip_id; /* 芯片ID */
92 hi_u8 device_id; /* 设备ID */
93 hi_u8 vap_id; /* VAP ID */
94 hi_u8 resever; /* 保留 */
95 hi_u16 us_length; /* payload length */
96 } hcc_mac_event_hdr_stru;
97
98 typedef enum {
99 HCC_ACTION_TYPE_WIFI = 0, /* data from wifi */
100 HCC_ACTION_TYPE_OAM = 1, /* data from oam,sdt etc. */
101 HCC_ACTION_TYPE_TEST = 2, /* used for hcc transfer test */
102 HCC_ACTION_TYPE_BUTT
103 } hcc_action_type_enum;
104
105 typedef enum _wifi_sub_type_ {
106 WIFI_CONTROL_TYPE = 0,
107 WIFI_DATA_TYPE = 1,
108 WIFI_SUB_TYPE_BUTT,
109 } wifi_sub_type;
110
111 typedef enum _oam_sub_type_ {
112 DEAULT_VALUE = 0,
113 DUMP_REG = 1,
114 DUMP_MEM = 2,
115 } oam_sub_type;
116
117 typedef enum {
118 HCC_WIFI_SUB_TYPE_CONTROL = 0,
119 HCC_WIFI_SUB_TYPE_DATA = 1,
120 HCC_WIFI_SUB_TYPE_BUTT,
121 } hcc_event_wifi_sub_type;
122
123 typedef struct {
124 hi_u32 main_type;
125 hi_u32 sub_type;
126 hi_u8 extend_len;
127 hi_u32 fc_flag;
128 hi_u32 queue_id;
129 hi_u8 resv[3]; /* reserved bytes: 3. */
130 } hcc_transfer_param;
131
132 /* hcc protocol header
133 |-------hcc total(64B)-----|-----------package mem--------------|
134 |hcc hdr|pad hdr|hcc extend|pad_payload|--------payload---------|
135 */
136 #pragma pack(push, 1)
137 /* 4bytes */
138 struct hcc_header {
139 hi_u16 sub_type: 4; /* sub type to hcc type,refer to hcc_action_type */
140 hi_u16 main_type: 3; /* main type to hcc type,refer to hcc_action_type */
141 hi_u16 pad_hdr: 6; /* pad_hdr only need 6 bits, pad_hdr used to algin hcc tcm hdr(64B) */
142 hi_u16 pad_payload: 2; /* the pad to algin the payload addr */
143 hi_u16 more: 1; /* for hcc aggregation */
144 hi_u16 seq: 4; /* seq num for debug */
145 hi_u16 pay_len: 12; /* the payload length, did't contain the extend hcc hdr area */
146 } __OAL_DECLARE_PACKED;
147 #pragma pack(pop)
148
149 typedef struct hcc_header hcc_header_stru;
150
151 struct hcc_extend_hdr {
152 frw_event_type_enum_uint8 nest_type;
153 hi_u8 nest_sub_type;
154 hi_u8 chip_id : 2;
155 hi_u8 device_id : 2;
156 hi_u8 vap_id : 4;
157 hi_u8 config_frame;
158 } __OAL_DECLARE_PACKED;
159
160 typedef struct hcc_extend_hdr frw_hcc_extend_hdr_stru;
161
162 #define HCC_HDR_TOTAL_LEN 64
163 #define HCC_HDR_LEN (sizeof(hcc_header_stru))
164 #define HCC_HDR_RESERVED_MAX_LEN (HCC_HDR_TOTAL_LEN - HCC_HDR_LEN)
165 #define HCC_EXTEND_TOTAL_SIZE (WLAN_MAX_MAC_HDR_LEN + HI_MAX_DEV_CB_LEN + (hi_u32)sizeof(frw_hcc_extend_hdr_stru))
166
167 typedef enum _hcc_test_case_ {
168 HCC_TEST_CASE_TX = 0,
169 HCC_TEST_CASE_RX = 1,
170 HCC_TEST_CASE_LOOP = 2,
171 HCC_TEST_CASE_COUNT
172 } hcc_test_case;
173
174 /* less than 16,4bits for sub_type */
175 typedef enum _hcc_test_subtype_ {
176 HCC_TEST_SUBTYPE_CMD = 0, /* command mode */
177 HCC_TEST_SUBTYPE_DATA = 1,
178 HCC_TEST_SUBTYPE_BUTT
179 } hcc_test_subtype;
180
181 typedef struct _hcc_test_cmd_stru_ {
182 hi_u16 cmd_type;
183 hi_u16 cmd_len;
184 } hcc_test_cmd_stru;
185 #define hcc_get_test_cmd_data(base) (((hi_u8 *)(base)) + sizeof(hcc_test_cmd_stru))
186
187 typedef struct _hsdio_trans_test_info_ {
188 hi_u32 actual_tx_pkts;
189 hi_u8 resv[4]; /* 4 byte保留字段 */
190 hi_u64 total_h2d_trans_bytes; /* total bytes trans by from host to device */
191 hi_u64 total_d2h_trans_bytes; /* total bytes trans by from device to host */
192 } hsdio_trans_test_info;
193
194 typedef struct _hsdio_trans_test_rx_info_ {
195 hi_u32 total_trans_pkts;
196 hi_u32 pkt_len;
197 hi_u8 pkt_value;
198 hi_u8 resv[3]; /* 3 byte保留字段,word对齐 */
199 } hsdio_trans_test_rx_info;
200
201 enum _hcc_descr_type_ {
202 HCC_DESCR_ASSEM_RESET = 0,
203 HCC_NETBUF_QUEUE_SWITCH = 1,
204 HCC_DESCR_TYPE_BUTT
205 };
206
207 typedef hi_u32 hcc_descr_type;
208 /* This descr buff is reversed in device,
209 the callback function can't cost much time,
210 just for transfer sdio buff message */
211 struct hcc_descr_header {
212 hcc_descr_type descr_type;
213 };
214
215 typedef struct exception_bcpu_dump_header {
216 hi_u32 align_type;
217 hi_u32 start_addr;
218 hi_u32 men_len;
219 } exception_bcpu_dump_header;
220
221 enum dump_h2d_cmd {
222 READ_MEM = 0,
223 READ_REG = 1,
224
225 DUMP_H2D_BUTT,
226 };
227
228 enum dump_d2h_cmd {
229 DATA = 0,
230
231 DUMP_D2H_BUTT,
232 };
233 typedef hi_u8 hcc_netbuf_queue_type;
234
235 typedef enum {
236 DATA_HI_QUEUE = 0,
237 DATA_LO_QUEUE = 1,
238 HCC_QUEUE_COUNT
239 } hcc_queue_type_enum;
240
241 typedef struct {
242 frw_event_mem_stru *(*rx_adapt_func)(frw_event_mem_stru *);
243 } hcc_mac_event_table_stru;
244
245 /* ****************************************************************************
246 3 函数声明
247 **************************************************************************** */
248 typedef struct {
249 oal_netbuf_stru *pst_netbuf;
250 hi_s32 len; /* for hcc transfer */
251 } hcc_netbuf_stru;
252
253 typedef struct {
254 hi_u8 nest_type;
255 hi_u8 nest_sub_type;
256 hi_u16 buf_len;
257 hi_void *netbuf;
258 } hcc_event_stru;
259
260 /* ****************************************************************************
261 外部声明
262 **************************************************************************** */
263 extern hi_u8 g_sdio_txpkt_index;
264
265 /* ****************************************************************************
266 inline
267 **************************************************************************** */
268 /* the macro to set hcc hdr */
hcc_hdr_param_init(hcc_transfer_param * param,hi_u32 main_type,hi_u32 sub_type,hi_u8 extend_len,hi_u32 fc_type,hi_u32 queue_id)269 static inline hi_void hcc_hdr_param_init(hcc_transfer_param *param, hi_u32 main_type, hi_u32 sub_type,
270 hi_u8 extend_len, hi_u32 fc_type, hi_u32 queue_id)
271 {
272 param->main_type = main_type;
273 param->sub_type = sub_type;
274 param->extend_len = extend_len;
275 param->fc_flag = fc_type;
276 param->queue_id = queue_id;
277 }
278 #ifdef __cplusplus
279 #if __cplusplus
280 }
281 #endif
282 #endif
283
284 #endif
285