-
Notifications
You must be signed in to change notification settings - Fork 2
/
bl_cfgfile.c
239 lines (196 loc) · 8.79 KB
/
bl_cfgfile.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
/**
****************************************************************************************
*
* @file bl_configparse.c
*
* Copyright (C) BouffaloLab 2017-2018
*
****************************************************************************************
*/
#include <linux/firmware.h>
#include <net/mac80211.h>
#include "bl_defs.h"
#include "bl_cfgfile.h"
/**
*
*/
static const char *bl_find_tag(const u8 *file_data, unsigned int file_size,
const char *tag_name, unsigned int tag_len)
{
unsigned int curr, line_start = 0, line_size;
BL_DBG(BL_FN_ENTRY_STR);
/* Walk through all the lines of the configuration file */
while (line_start < file_size) {
/* Search the end of the current line (or the end of the file) */
for (curr = line_start; curr < file_size; curr++)
if (file_data[curr] == '\n')
break;
/* Compute the line size */
line_size = curr - line_start;
/* Check if this line contains the expected tag */
if ((line_size == (strlen(tag_name) + tag_len)) &&
(!strncmp(&file_data[line_start], tag_name, strlen(tag_name))))
return (&file_data[line_start + strlen(tag_name)]);
/* Move to next line */
line_start = curr + 1;
}
/* Tag not found */
return NULL;
}
/**
* Parse the Config file used at init time
*/
int bl_parse_configfile(struct bl_hw *bl_hw, const char *filename,
struct bl_conf_file *config)
{
const struct firmware *config_fw;
u8 dflt_mac[ETH_ALEN] = { 0, 111, 111, 111, 111, 0 };
u8 new_mac[ETH_ALEN];
const u8 *tag_ptr = NULL;
bool fw_found = false;
BL_DBG(BL_FN_ENTRY_STR);
if (request_firmware(&config_fw, filename, bl_hw->dev) == 0)
fw_found = true;
/* Get MAC Address */
if (fw_found) {
tag_ptr = bl_find_tag(config_fw->data, config_fw->size,
"MAC_ADDR=", strlen("00:00:00:00:00:00"));
}
if (tag_ptr != NULL) {
if (sscanf(tag_ptr,
"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
new_mac + 0, new_mac + 1, new_mac + 2,
new_mac + 3, new_mac + 4, new_mac + 5) == ETH_ALEN) {
memcpy(config->mac_addr, new_mac, ETH_ALEN);
}
} else if (!config->mac_addr_ready) {
memcpy(config->mac_addr, dflt_mac, ETH_ALEN);
}
printk("MAC Address is:\n%pM\n", config->mac_addr);
/* Release the configuration file */
release_firmware(config_fw);
return 0;
}
/**
* Parse the Config file used at init time
*/
int bl_parse_phy_configfile(struct bl_hw *bl_hw, const char *filename,
struct bl_phy_conf_file *config)
{
const struct firmware *config_fw;
int ret;
const u8 *tag_ptr;
BL_DBG(BL_FN_ENTRY_STR);
if ((ret = request_firmware(&config_fw, filename, bl_hw->dev))) {
printk(KERN_CRIT "%s: Failed to get %s (%d)\n", __func__, filename, ret);
return ret;
}
/* Get Trident path mapping */
tag_ptr = bl_find_tag(config_fw->data, config_fw->size,
"TRD_PATH_MAPPING=", strlen("00"));
if (tag_ptr != NULL) {
u8 val;
if (sscanf(tag_ptr, "%hhx", &val) == 1)
config->trd.path_mapping = val;
else
config->trd.path_mapping = bl_hw->mod_params->phy_cfg;
} else
config->trd.path_mapping = bl_hw->mod_params->phy_cfg;
BL_DBG("Trident path mapping is: %d\n", config->trd.path_mapping);
/* Get DC offset compensation */
tag_ptr = bl_find_tag(config_fw->data, config_fw->size,
"TX_DC_OFF_COMP=", strlen("00000000"));
if (tag_ptr != NULL) {
if (sscanf(tag_ptr, "%08x", &config->trd.tx_dc_off_comp) != 1)
config->trd.tx_dc_off_comp = 0;
} else
config->trd.tx_dc_off_comp = 0;
BL_DBG("TX DC offset compensation is: %08X\n", config->trd.tx_dc_off_comp);
/* Get Karst TX IQ compensation value for path0 on 2.4GHz */
tag_ptr = bl_find_tag(config_fw->data, config_fw->size,
"KARST_TX_IQ_COMP_2_4G_PATH_0=", strlen("00000000"));
if (tag_ptr != NULL) {
if (sscanf(tag_ptr, "%08x", &config->karst.tx_iq_comp_2_4G[0]) != 1)
config->karst.tx_iq_comp_2_4G[0] = 0x01000000;
} else
config->karst.tx_iq_comp_2_4G[0] = 0x01000000;
BL_DBG("Karst TX IQ compensation for path 0 on 2.4GHz is: %08X\n", config->karst.tx_iq_comp_2_4G[0]);
/* Get Karst TX IQ compensation value for path1 on 2.4GHz */
tag_ptr = bl_find_tag(config_fw->data, config_fw->size,
"KARST_TX_IQ_COMP_2_4G_PATH_1=", strlen("00000000"));
if (tag_ptr != NULL) {
if (sscanf(tag_ptr, "%08x", &config->karst.tx_iq_comp_2_4G[1]) != 1)
config->karst.tx_iq_comp_2_4G[1] = 0x01000000;
} else
config->karst.tx_iq_comp_2_4G[1] = 0x01000000;
BL_DBG("Karst TX IQ compensation for path 1 on 2.4GHz is: %08X\n", config->karst.tx_iq_comp_2_4G[1]);
/* Get Karst RX IQ compensation value for path0 on 2.4GHz */
tag_ptr = bl_find_tag(config_fw->data, config_fw->size,
"KARST_RX_IQ_COMP_2_4G_PATH_0=", strlen("00000000"));
if (tag_ptr != NULL) {
if (sscanf(tag_ptr, "%08x", &config->karst.rx_iq_comp_2_4G[0]) != 1)
config->karst.rx_iq_comp_2_4G[0] = 0x01000000;
} else
config->karst.rx_iq_comp_2_4G[0] = 0x01000000;
BL_DBG("Karst RX IQ compensation for path 0 on 2.4GHz is: %08X\n", config->karst.rx_iq_comp_2_4G[0]);
/* Get Karst RX IQ compensation value for path1 on 2.4GHz */
tag_ptr = bl_find_tag(config_fw->data, config_fw->size,
"KARST_RX_IQ_COMP_2_4G_PATH_1=", strlen("00000000"));
if (tag_ptr != NULL) {
if (sscanf(tag_ptr, "%08x", &config->karst.rx_iq_comp_2_4G[1]) != 1)
config->karst.rx_iq_comp_2_4G[1] = 0x01000000;
} else
config->karst.rx_iq_comp_2_4G[1] = 0x01000000;
BL_DBG("Karst RX IQ compensation for path 1 on 2.4GHz is: %08X\n", config->karst.rx_iq_comp_2_4G[1]);
/* Get Karst TX IQ compensation value for path0 on 5GHz */
tag_ptr = bl_find_tag(config_fw->data, config_fw->size,
"KARST_TX_IQ_COMP_5G_PATH_0=", strlen("00000000"));
if (tag_ptr != NULL) {
if (sscanf(tag_ptr, "%08x", &config->karst.tx_iq_comp_5G[0]) != 1)
config->karst.tx_iq_comp_5G[0] = 0x01000000;
} else
config->karst.tx_iq_comp_5G[0] = 0x01000000;
BL_DBG("Karst TX IQ compensation for path 0 on 5GHz is: %08X\n", config->karst.tx_iq_comp_5G[0]);
/* Get Karst TX IQ compensation value for path1 on 5GHz */
tag_ptr = bl_find_tag(config_fw->data, config_fw->size,
"KARST_TX_IQ_COMP_5G_PATH_1=", strlen("00000000"));
if (tag_ptr != NULL) {
if (sscanf(tag_ptr, "%08x", &config->karst.tx_iq_comp_5G[1]) != 1)
config->karst.tx_iq_comp_5G[1] = 0x01000000;
} else
config->karst.tx_iq_comp_5G[1] = 0x01000000;
BL_DBG("Karst TX IQ compensation for path 1 on 5GHz is: %08X\n", config->karst.tx_iq_comp_5G[1]);
/* Get Karst RX IQ compensation value for path0 on 5GHz */
tag_ptr = bl_find_tag(config_fw->data, config_fw->size,
"KARST_RX_IQ_COMP_5G_PATH_0=", strlen("00000000"));
if (tag_ptr != NULL) {
if (sscanf(tag_ptr, "%08x", &config->karst.rx_iq_comp_5G[0]) != 1)
config->karst.rx_iq_comp_5G[0] = 0x01000000;
} else
config->karst.rx_iq_comp_5G[0] = 0x01000000;
BL_DBG("Karst RX IQ compensation for path 0 on 5GHz is: %08X\n", config->karst.rx_iq_comp_5G[0]);
/* Get Karst RX IQ compensation value for path1 on 5GHz */
tag_ptr = bl_find_tag(config_fw->data, config_fw->size,
"KARST_RX_IQ_COMP_5G_PATH_1=", strlen("00000000"));
if (tag_ptr != NULL) {
if (sscanf(tag_ptr, "%08x", &config->karst.rx_iq_comp_5G[1]) != 1)
config->karst.rx_iq_comp_5G[1] = 0x01000000;
} else
config->karst.rx_iq_comp_5G[1] = 0x01000000;
BL_DBG("Karst RX IQ compensation for path 1 on 5GHz is: %08X\n", config->karst.rx_iq_comp_5G[1]);
/* Get Karst default path */
tag_ptr = bl_find_tag(config_fw->data, config_fw->size,
"KARST_DEFAULT_PATH=", strlen("00"));
if (tag_ptr != NULL) {
u8 val;
if (sscanf(tag_ptr, "%hhx", &val) == 1)
config->karst.path_used = val;
else
config->karst.path_used = bl_hw->mod_params->phy_cfg;
} else
config->karst.path_used = bl_hw->mod_params->phy_cfg;
BL_DBG("Karst default path is: %d\n", config->karst.path_used);
/* Release the configuration file */
release_firmware(config_fw);
return 0;
}