Skip to content

Commit 86f7188

Browse files
committed
drivers: nrf_wifi: Implement vendor stats
Populate the vendor stats with nRF70 FW statistics, this is handy in debugging. Signed-off-by: Chaitanya Tata <[email protected]>
1 parent 06daf0e commit 86f7188

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

drivers/wifi/nrf_wifi/inc/fmac_main.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636

3737
#define NRF70_DRIVER_VERSION "1."KERNEL_VERSION_STRING
3838

39+
/* Calculate compile-time maximum for vendor stats */
40+
#ifdef CONFIG_NET_STATISTICS_ETHERNET_VENDOR
41+
#define MAX_VENDOR_STATS ((sizeof(struct rpu_sys_fw_stats) / sizeof(uint32_t)) + 1)
42+
#endif /* CONFIG_NET_STATISTICS_ETHERNET_VENDOR */
43+
3944
#ifndef CONFIG_NRF70_OFFLOADED_RAW_TX
4045
#ifndef CONFIG_NRF70_RADIO_TEST
4146
struct nrf_wifi_vif_ctx_zep {
@@ -61,6 +66,8 @@ struct nrf_wifi_vif_ctx_zep {
6166
bool set_if_event_received;
6267
int set_if_status;
6368
#ifdef CONFIG_NET_STATISTICS_ETHERNET
69+
struct net_stats_eth_vendor eth_stats_vendor_data[MAX_VENDOR_STATS];
70+
char vendor_key_strings[MAX_VENDOR_STATS][16];
6471
struct net_stats_eth eth_stats;
6572
#endif /* CONFIG_NET_STATISTICS_ETHERNET */
6673
#if defined(CONFIG_NRF70_STA_MODE) || defined(CONFIG_NRF70_RAW_DATA_RX)

drivers/wifi/nrf_wifi/src/net_if.c

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1213,9 +1213,19 @@ int nrf_wifi_if_set_config_zep(const struct device *dev,
12131213
struct net_stats_eth *nrf_wifi_eth_stats_get(const struct device *dev)
12141214
{
12151215
struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL;
1216+
#ifdef CONFIG_NET_STATISTICS_ETHERNET_VENDOR
1217+
struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL;
1218+
struct rpu_sys_op_stats stats;
1219+
enum nrf_wifi_status status;
1220+
size_t fw_stats_size;
1221+
size_t num_uint32;
1222+
const uint8_t *fw_stats_bytes;
1223+
size_t i;
1224+
int vendor_idx = 0;
1225+
#endif /* CONFIG_NET_STATISTICS_ETHERNET_VENDOR */
12161226

12171227
if (!dev) {
1218-
LOG_ERR("%s Device not found", __func__);
1228+
LOG_ERR("%s: Device not found", __func__);
12191229
goto out;
12201230
}
12211231

@@ -1225,6 +1235,63 @@ struct net_stats_eth *nrf_wifi_eth_stats_get(const struct device *dev)
12251235
goto out;
12261236
}
12271237

1238+
#ifdef CONFIG_NET_STATISTICS_ETHERNET_VENDOR
1239+
rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep;
1240+
if (!rpu_ctx_zep || !rpu_ctx_zep->rpu_ctx) {
1241+
LOG_ERR("%s: rpu_ctx_zep or rpu_ctx is NULL", __func__);
1242+
goto out;
1243+
}
1244+
1245+
memset(&stats, 0, sizeof(stats));
1246+
status = nrf_wifi_sys_fmac_stats_get(rpu_ctx_zep->rpu_ctx, RPU_STATS_TYPE_ALL, &stats);
1247+
if (status != NRF_WIFI_STATUS_SUCCESS) {
1248+
LOG_ERR("%s: Failed to get RPU stats", __func__);
1249+
goto ret;
1250+
}
1251+
1252+
/* Treat stats.fw as a blob and divide into uint32_t chunks */
1253+
fw_stats_size = sizeof(stats.fw);
1254+
num_uint32 = fw_stats_size / sizeof(uint32_t);
1255+
fw_stats_bytes = (const uint8_t *)&stats.fw;
1256+
1257+
vendor_idx = 0;
1258+
1259+
for (i = 0; i < num_uint32 && vendor_idx < MAX_VENDOR_STATS - 1; i++) {
1260+
uint32_t val;
1261+
const char **key_ptr;
1262+
uint32_t *val_ptr;
1263+
1264+
/* Extract uint32_t value from blob */
1265+
memcpy(&val, fw_stats_bytes + i * sizeof(uint32_t), sizeof(uint32_t));
1266+
1267+
/* Create key name */
1268+
snprintk(vif_ctx_zep->vendor_key_strings[vendor_idx], 16, "fw_%zu", i);
1269+
1270+
/* Assign key */
1271+
key_ptr = (const char **)&vif_ctx_zep->eth_stats_vendor_data[vendor_idx].key;
1272+
*key_ptr = vif_ctx_zep->vendor_key_strings[vendor_idx];
1273+
1274+
/* Assign value */
1275+
val_ptr = (uint32_t *)&vif_ctx_zep->eth_stats_vendor_data[vendor_idx].value;
1276+
*val_ptr = val;
1277+
1278+
vendor_idx++;
1279+
}
1280+
1281+
/* Null terminator entry */
1282+
{
1283+
const char **key_ptr = (const char **)&vif_ctx_zep->eth_stats_vendor_data[vendor_idx].key;
1284+
uint32_t *val_ptr = (uint32_t *)&vif_ctx_zep->eth_stats_vendor_data[vendor_idx].value;
1285+
1286+
*key_ptr = NULL;
1287+
*val_ptr = 0;
1288+
}
1289+
1290+
/* Point to the static vendor data */
1291+
vif_ctx_zep->eth_stats.vendor = vif_ctx_zep->eth_stats_vendor_data;
1292+
1293+
ret:
1294+
#endif /* CONFIG_NET_STATISTICS_ETHERNET_VENDOR */
12281295
return &vif_ctx_zep->eth_stats;
12291296
out:
12301297
return NULL;

0 commit comments

Comments
 (0)