-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrs_testmode.c
380 lines (307 loc) · 8.59 KB
/
rs_testmode.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
368
369
370
371
372
373
374
375
376
377
378
379
380
// SPDX-License-Identifier: GPL-2.0-or-later
/**
* Copyright (C) [2022-2023] Renesas Electronics Corporation and/or its affiliates.
*/
////////////////////////////////////////////////////////////////////////////////
/// INCLUDE
#include <linux/version.h>
#include <net/mac80211.h>
#include <net/netlink.h>
#include "rs_core.h"
#include "rs_testmode.h"
#include "rs_mgmt_tx.h"
#include "rs_irq_dbg.h"
////////////////////////////////////////////////////////////////////////////////
/// MACRO DEFINITION
#define PRINT_CMD_INFO 0
#define RS_TM_SIZE 20
////////////////////////////////////////////////////////////////////////////////
/// GLOBAL FUNCTION
s32 rs_tm_reg(struct ieee80211_hw *hw, struct nlattr **tb)
{
struct rs_hw_priv *rs_hw = hw->priv;
u32 mem_addr, val32;
struct sk_buff *skb;
s32 status = 0;
if (!tb[RS_TM_AT_REG_OFFSET]) {
printk("Error finding register offset\n");
return -ENOMSG;
}
mem_addr = nla_get_u32(tb[RS_TM_AT_REG_OFFSET]);
switch (nla_get_u32(tb[RS_TM_AT_CMD])) {
case RS_TM_CMD_A2D_READ_REG: {
struct rs_dbg_mem_read_chk *mem_read_chk = &rs_hw->mgmt_return.mem_read_chk;
if ((status = rs_dbg_mem_read_ask(rs_hw, mem_addr, mem_read_chk)))
return status;
skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, RS_TM_SIZE);
if (!skb) {
printk("Error allocating memory\n");
return -ENOMEM;
}
val32 = mem_read_chk->mem_data;
if (nla_put_u32(skb, RS_TM_AT_REG_VALUE32, val32))
goto nla_put_failure;
status = cfg80211_testmode_reply(skb);
if (status < 0)
printk("Error testmode reply error : %d\n", status);
} break;
case RS_TM_CMD_A2D_WRITE_REG: {
if (!tb[RS_TM_AT_REG_VALUE32]) {
printk("Error finding value to write\n");
return -ENOMSG;
} else {
val32 = nla_get_u32(tb[RS_TM_AT_REG_VALUE32]);
if ((status = rs_dbg_mem_write_ask(rs_hw, mem_addr, val32)))
return status;
}
} break;
default:
printk("Unknown TM reg cmd ID\n");
return -ENOSYS;
}
return status;
nla_put_failure:
kfree_skb(skb);
return -EMSGSIZE;
}
s32 rs_tm_dbg_filter(struct ieee80211_hw *hw, struct nlattr **tb)
{
struct rs_hw_priv *rs_hw = hw->priv;
u32 filter;
s32 status = 0;
if (!tb[RS_TM_AT_REG_FILTER]) {
printk("Error finding filter value\n");
return -ENOMSG;
}
filter = nla_get_u32(tb[RS_TM_AT_REG_FILTER]);
RS_DBG("TM DBG filter, setting: 0x%x\n", filter);
switch (nla_get_u32(tb[RS_TM_AT_CMD])) {
case RS_TM_CMD_A2D_LOGMODEFILTER_SET:
if ((status = rs_dbg_mod_filter_set(rs_hw, filter)) != 0)
return status;
break;
case RS_TM_CMD_A2D_DBGLEVELFILTER_SET:
if ((status = rs_dbg_lvl_filter_set(rs_hw, filter)) != 0)
return status;
break;
case RS_TM_CMD_A2D_DBGOUTDIR_SET:
if ((status = rs_dbg_set_dir_out(rs_hw, filter)) != 0) {
return status;
}
(void)rs_irq_dbg_set(rs_hw, filter);
break;
default:
printk("Unknown testmode register command ID\n");
return -ENOSYS;
}
return status;
}
s32 rs_tm_rf_tx(struct ieee80211_hw *hw, struct nlattr **tb)
{
struct rs_hw_priv *rs_hw = hw->priv;
s32 status = 0;
u8 start = 0;
u16 frequency = 0;
u16 numFrames = 0;
u16 frameLen = 0;
u8 txRate = 0;
u8 txPower = 0;
u64 destAddr = 0;
u64 bssid = 0;
u8 GI = 0;
u8 greenField = 0;
u8 preambleType = 0;
u8 qosEnable = 0;
u8 ackPolicy = 0;
u8 aifsnVal = 0;
if (!tb[RS_TM_AT_START]) {
printk("Error finding start attribute\n");
return -ENOMSG;
}
start = nla_get_u8(tb[RS_TM_AT_START]);
if (start == VALUE_START) {
frequency = nla_get_u16(tb[RS_TM_AT_CH]);
numFrames = nla_get_u16(tb[RS_TM_AT_FRAMES_NUM]);
frameLen = nla_get_u16(tb[RS_TM_AT_FRAMES_LEN]);
txRate = nla_get_u8(tb[RS_TM_AT_RATE]);
txPower = nla_get_u8(tb[RS_TM_AT_POWER]);
destAddr = nla_get_u64(tb[RS_TM_AT_ADDR_DEST]);
bssid = nla_get_u64(tb[RS_TM_AT_BSSID]);
GI = nla_get_u8(tb[RS_TM_AT_GI]);
greenField = nla_get_u8(tb[RS_TM_AT_GREEN]);
preambleType = nla_get_u8(tb[RS_TM_AT_PREAMBLE]);
qosEnable = nla_get_u8(tb[RS_TM_AT_QOS]);
ackPolicy = nla_get_u8(tb[RS_TM_AT_ACK]);
aifsnVal = nla_get_u8(tb[RS_TM_AT_AIFSN]);
}
#if (PRINT_CMD_INFO)
printk("start %d\n", start);
printk("frequency %d\n", frequency);
printk("numFrames %d\n", numFrames);
printk("frameLen %d\n", frameLen);
printk("txRate %d\n", txRate);
printk("txPower %d\n", txPower);
printk("destAddr = %llx\n", destAddr);
printk("bssid = %llx\n", bssid);
printk("GI = %d\n", GI);
printk("greenField %d\n", greenField);
printk("preambleType %d\n", preambleType);
printk("qosEnable %d\n", qosEnable);
printk("ackPolicy %d\n", ackPolicy);
printk("aifsnVal %d\n", aifsnVal);
#endif
/*** Send the command to the LMAC ***/
if ((status = rs_rf_tx_req(rs_hw, start, frequency, numFrames, frameLen, txRate, txPower, destAddr,
bssid, GI, greenField, preambleType, qosEnable, ackPolicy, aifsnVal)))
return status;
return status;
}
s32 rs_tm_rf_cw(struct ieee80211_hw *hw, struct nlattr **tb)
{
struct rs_hw_priv *rs_hw = hw->priv;
s32 status = 0;
u8 start = 0;
u8 txPower = 0;
u16 frequency = 0;
if (!tb[RS_TM_AT_START]) {
printk("Error finding start attribute\n");
return -ENOMSG;
}
start = nla_get_u8(tb[RS_TM_AT_START]);
if (start == VALUE_START) {
txPower = nla_get_u8(tb[RS_TM_AT_POWER]);
frequency = nla_get_u16(tb[RS_TM_AT_CH]);
}
#if (PRINT_CMD_INFO)
printk("start %d\n", start);
printk("txPower %d\n", txPower);
printk("frequency %d\n", frequency);
#endif
if ((status = rs_rf_cw_req(rs_hw, start, txPower, frequency)))
return status;
return status;
}
s32 rs_tm_rf_cont(struct ieee80211_hw *hw, struct nlattr **tb)
{
struct rs_hw_priv *rs_hw = hw->priv;
s32 status = 0;
u8 start = 0;
u8 txRate = 0;
u8 txPower = 0;
u16 frequency = 0;
if (!tb[RS_TM_AT_START]) {
printk("Error finding start attribute\n");
return -ENOMSG;
}
start = nla_get_u8(tb[RS_TM_AT_START]);
if (start == VALUE_START) {
txRate = nla_get_u8(tb[RS_TM_AT_RATE]);
txPower = nla_get_u8(tb[RS_TM_AT_POWER]);
frequency = nla_get_u16(tb[RS_TM_AT_CH]);
}
#if (PRINT_CMD_INFO)
printk("start %d\n", start);
printk("txRate %d\n", txRate);
printk("txPower %d\n", txPower);
printk("frequency %d\n", frequency);
#endif
/*** Send the command to the LMAC ***/
if ((status = rs_rf_cont_req(rs_hw, start, txRate, txPower, frequency)))
return status;
return status;
}
s32 rs_tm_rf_ch(struct ieee80211_hw *hw, struct nlattr **tb)
{
struct rs_hw_priv *rs_hw = hw->priv;
s32 status = 0;
u16 frequency = 0;
if (!tb[RS_TM_AT_CH]) {
printk("Error finding channel attribute\n");
return -ENOMSG;
}
frequency = nla_get_u16(tb[RS_TM_AT_CH]);
#if (PRINT_CMD_INFO)
printk("frequency %d\n", frequency);
#endif
if ((status = rs_rf_ch_req(rs_hw, frequency)))
return status;
return status;
}
s32 rs_tm_rf_per(struct ieee80211_hw *hw, struct nlattr **tb)
{
struct rs_hw_priv *rs_hw = hw->priv;
struct sk_buff *skb;
struct rs_dbg_rf_per_chk *rf_per_chk = &rs_hw->mgmt_return.rf_per_chk;
s32 status = 0;
u8 start = 0;
if (!tb[RS_TM_AT_START]) {
printk("Error finding start attribute\n");
return -ENOMSG;
}
start = nla_get_u8(tb[RS_TM_AT_START]);
#if (PRINT_CMD_INFO)
printk("start %d\n", start);
#endif
if ((status = rs_rf_per_req(rs_hw, start, rf_per_chk)))
return status;
if (start == VALUE_PER_GET) {
u32 pass, fcs, phy, overflow;
/* Allocate the answer message */
skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 20);
if (!skb) {
printk("Error allocating memory\n");
return -ENOMEM;
}
pass = rf_per_chk->pass;
fcs = rf_per_chk->fcs;
phy = rf_per_chk->phy;
overflow = rf_per_chk->overflow;
if (nla_put_u32(skb, RS_TM_AT_PER_PASS, pass))
goto nla_put_failure;
if (nla_put_u32(skb, RS_TM_AT_PER_FCS, fcs))
goto nla_put_failure;
if (nla_put_u32(skb, RS_TM_AT_PER_PHY, phy))
goto nla_put_failure;
if (nla_put_u32(skb, RS_TM_AT_PER_OVERFLOW, overflow))
goto nla_put_failure;
#if (PRINT_CMD_INFO)
printk("pass %d\n", pass);
printk("fcs %d\n", fcs);
printk("phy %d\n", phy);
printk("overflow %d\n", overflow);
#endif
status = cfg80211_testmode_reply(skb);
if (status < 0)
printk("Error sending per msg : %d\n", status);
}
return status;
nla_put_failure:
kfree_skb(skb);
return -EMSGSIZE;
}
#ifdef CONFIG_RS_SPI
void hw_reset_fw(void);
#endif
s32 rs_tm_reset(struct ieee80211_hw *hw, struct nlattr **tb)
{
s32 status = 0;
#if (PRINT_CMD_INFO)
printk("TEST Mode RESET command.\n");
#endif
#ifdef CONFIG_RS_SPI
hw_reset_fw();
#endif
return status;
}
s32 rs_tm_host_log_level(struct ieee80211_hw *hw, struct nlattr **tb)
{
s32 status = 0;
u8 level = 0;
if (!tb[RS_TM_AT_REG_VALUE32]) {
printk("Error finding level attribute\n");
return -ENOMSG;
}
level = nla_get_u8(tb[RS_TM_AT_REG_VALUE32]);
set_host_log_level(level);
return status;
}