-
Notifications
You must be signed in to change notification settings - Fork 2
/
bl_utils.c
367 lines (303 loc) · 9.08 KB
/
bl_utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/**
****************************************************************************************
*
* @file bl_utils.c
*
* @brief IPC utility function definitions
*
* Copyright (C) BouffaloLab 2017-2018
*
****************************************************************************************
*/
#include <linux/device.h>
#include <linux/dmapool.h>
#include "bl_utils.h"
#include "bl_defs.h"
#include "bl_rx.h"
#include "bl_tx.h"
#include "bl_msg_rx.h"
#include "bl_debugfs.h"
#ifdef CONFIG_BL_DBG
unsigned long bl_filter_severity = 0xffffffff;
unsigned long bl_filter_module = 0xffffffff;
#else
unsigned long bl_filter_severity;
unsigned long bl_filter_module;
#endif
module_param(bl_filter_severity, ulong, S_IRUGO|S_IWUSR);
MODULE_PARM_DESC(bl_filter_severity, "used to filter severity");
module_param(bl_filter_module, ulong, S_IRUGO|S_IWUSR);
MODULE_PARM_DESC(bl_filter_module, "used to filter module");
/* FIXME */
struct device_attribute dev_attr_filter_severity;
EXPORT_SYMBOL_GPL(dev_attr_filter_severity);
struct device_attribute dev_attr_filter_module;
EXPORT_SYMBOL_GPL(dev_attr_filter_module);
static ssize_t filter_severity_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%lx\n", bl_filter_severity);
}
static ssize_t filter_severity_store(struct device *dev,
struct device_attribute *attr, const char *buf,
size_t count)
{
if (sscanf(buf, "%lx", &bl_filter_severity) != 1)
return -EINVAL;
return count;
}
DEVICE_ATTR_RW(filter_severity);
static ssize_t filter_module_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%lx\n", bl_filter_module);
}
static ssize_t filter_module_store(struct device *dev,
struct device_attribute *attr, const char *buf,
size_t count)
{
if (sscanf(buf, "%lx", &bl_filter_module) != 1)
return -EINVAL;
return count;
}
DEVICE_ATTR_RW(filter_module);
static void bl_do_log(const char *fmt_usr, va_list args)
{
static char buf[1024];
vsnprintf(buf, sizeof(buf), fmt_usr, args);
printk("%s", buf);
}
/**
****************************************************************************************
* @brief Function formatting a string and sending it to the defined output
*
* @param[in] fmt Format string
*
****************************************************************************************
*/
void dbg_test_print(const char *fmt, ...)
{
const char *fmt_usr = (const char*) fmt;
uint32_t severity = 0;
va_list args;
va_start(args, fmt);
//printk("%d %d %d %d\n", fmt_usr[0], fmt_usr[1], DBG_MOD_MAX, DBG_SEV_MIN);
// permit all the debug message is permited
bl_filter_severity = DBG_SEV_MAX;
if (bl_filter_severity == 0) return;
do
{
// Get the prefix
unsigned char prefix = ((unsigned char)*fmt_usr) & 0xFF;
// ASCII char, start of the user string
if (prefix < DBG_MOD_MIN) break;
if (prefix < DBG_MOD_MAX)
{
// test module, if filtered returns
if (~bl_filter_module & CO_BIT(prefix - DBG_MOD_MIN)) return;
}
else
{
// must be severity code
ASSERT_ERR(DBG_SEV_MIN <= prefix && prefix < DBG_SEV_MAX);
severity = (uint32_t)(prefix - DBG_SEV_MIN);
// test severity, if filtered returns
if (bl_filter_severity <= severity) return;
}
// Check first and second char
fmt_usr++;
}
while (fmt_usr != fmt + 2);
// print
bl_do_log(fmt_usr, args);
va_end(args);
}
/**
*
*/
static int dbginfo_allocs(struct bl_hw *bl_hw)
{
struct dbg_debug_dump_tag *buf;
u32 len = sizeof(*buf);
/* Allocate the debug information buffer */
buf = kmalloc(len, GFP_KERNEL);
if (!buf) {
printk(KERN_CRIT "%s:%d: buffer alloc of size %u failed\n\n",
__func__, __LINE__, len);
return -ENOMEM;
}
bl_hw->dbginfo.buf = buf;
return 0;
}
/**
*
*/
static void bl_dbginfo_deallocs(struct bl_hw *bl_hw)
{
if (bl_hw->dbginfo.buf) {
kfree(bl_hw->dbginfo.buf);
bl_hw->dbginfo.buf = NULL;
}
}
/**
* @brief Deallocate storage elements.
*
* This function deallocates all the elements required for communications with LMAC,
* such as Rx Data elements, MSGs elements, ...
*
* This function should be called in correspondence with the allocation function.
*
* @param[in] bl_hw Pointer to main structure storing all the relevant information
*/
static void bl_elems_deallocs(struct bl_hw *bl_hw)
{
BL_DBG(BL_FN_ENTRY_STR);
bl_dbginfo_deallocs(bl_hw);
}
/**
* @brief Allocate storage elements.
*
* This function allocates all the elements required for communications with LMAC,
* such as Rx Data elements, MSGs elements, ...
*
* This function should be called in correspondence with the deallocation function.
*
* @param[in] bl_hw Pointer to main structure storing all the relevant information
*/
static int bl_elems_allocs(struct bl_hw *bl_hw)
{
BL_DBG(BL_FN_ENTRY_STR);
/* Initialize the debug information buffer */
if (dbginfo_allocs(bl_hw)) {
printk(KERN_CRIT "%s:%d: ALLOCATIONS FAILED !\n", __func__,
__LINE__);
goto err_alloc;
}
return 0;
err_alloc:
bl_elems_deallocs(bl_hw);
return -ENOMEM;
}
/**
* WLAN driver call-back function for message reception indication
*/
u8 bl_msgind(void *pthis, void *hostid)
{
u8 ret = 0;
struct bl_hw *bl_hw = (struct bl_hw *)pthis;
struct ipc_e2a_msg *msg = (struct ipc_e2a_msg *)hostid;
BL_DBG(BL_FN_ENTRY_STR);
/* Relay further actions to the msg parser */
bl_rx_handle_msg(bl_hw, msg);
return ret;
}
/**
* FIXME
*
*/
u8 bl_msgackind(void *pthis, void *hostid)
{
struct bl_hw *bl_hw = (struct bl_hw *)pthis;
bl_hw->cmd_mgr.llind(&bl_hw->cmd_mgr, (struct bl_cmd *)hostid);
return -1;
}
/**
* WLAN driver call-back function for primary TBTT indication
*/
void bl_prim_tbtt_ind(void *pthis)
{
}
/**
* WLAN driver call-back function for secondary TBTT indication
*/
void bl_sec_tbtt_ind(void *pthis)
{
/* TODO */
}
/**
* WLAN driver call-back function for Debug message reception indication
*/
u8 bl_dbgind(void *pthis, void *hostid)
{
struct bl_dbg_elem *dbg_elem = hostid;
struct ipc_dbg_msg *dbg_msg;
u8 ret = 0;
/* Retrieve the message structure */
dbg_msg = (struct ipc_dbg_msg *)dbg_elem->dbgbuf_ptr;
/* Look for pattern which means that this hostbuf has been used for a MSG */
if (dbg_msg->pattern != IPC_DBG_VALID_PATTERN) {
ret = -1;
goto dbg_no_push;
}
/* Display the LMAC string */
printk("lmac %s", (char *)dbg_msg->string);
/* Reset the msg element and re-use it */
dbg_msg->pattern = 0;
wmb();
dbg_no_push:
return ret;
}
int bl_ipc_init(struct bl_hw *bl_hw)
{
struct ipc_host_cb_tag cb;
BL_DBG(BL_FN_ENTRY_STR);
/* initialize the API interface */
cb.recv_data_ind = bl_rxdataind;
cb.recv_msg_ind = bl_msgind;
cb.recv_msgack_ind = bl_msgackind;
cb.recv_dbg_ind = bl_dbgind;
cb.send_data_cfm = bl_txdatacfm;
cb.prim_tbtt_ind = bl_prim_tbtt_ind;
cb.sec_tbtt_ind = bl_sec_tbtt_ind;
/* set the IPC environment */
bl_hw->ipc_env = (struct ipc_host_env_tag *)
kzalloc(sizeof(struct ipc_host_env_tag), GFP_KERNEL);
/* call the initialization of the IPC */
ipc_host_init(bl_hw->ipc_env, &cb, bl_hw);
bl_cmd_mgr_init(&bl_hw->cmd_mgr);
return bl_elems_allocs(bl_hw);
}
/**
*
*/
void bl_ipc_deinit(struct bl_hw *bl_hw)
{
BL_DBG(BL_FN_ENTRY_STR);
bl_ipc_tx_drain(bl_hw);
bl_cmd_mgr_deinit(&bl_hw->cmd_mgr);
bl_elems_deallocs(bl_hw);
kfree(bl_hw->ipc_env);
bl_hw->ipc_env = NULL;
}
/**
* This assumes LMAC is still (tx wise) and there's no TX race until LMAC is up
* tx wise.
* This also lets both IPC sides remain in sync before resetting the LMAC,
* e.g with bl_send_reset.
*/
void bl_ipc_tx_drain(struct bl_hw *bl_hw)
{
int i, j;
BL_DBG(BL_FN_ENTRY_STR);
if (!bl_hw->ipc_env) {
printk("%s: bypassing (restart must have failed)\n", __func__);
return;
}
for (i = 0; i < BL_HWQ_NB; i++) {
for (j = 0; j < nx_txuser_cnt[i]; j++) {
struct sk_buff *skb;
while ((skb = (struct sk_buff *)ipc_host_tx_flush(bl_hw->ipc_env, i, j))) {
struct bl_sw_txhdr *sw_txhdr =
((struct bl_txhdr *)skb->data)->sw_hdr;
skb_pull(skb, sw_txhdr->headroom);
dev_kfree_skb_any(skb);
}
}
}
}
void bl_error_ind(struct bl_hw *bl_hw)
{
printk(KERN_CRIT "%s (type %d): dump received\n", __func__,
bl_hw->dbginfo.buf->dbg_info.error_type);
bl_hw->debugfs.trace_prst = true;
}