Skip to content

Commit df5d762

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 4a69c1b commit df5d762

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

drivers/wifi/nrf_wifi/inc/fmac_main.h

Lines changed: 9 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,10 @@ struct nrf_wifi_vif_ctx_zep {
6166
bool set_if_event_received;
6267
int set_if_status;
6368
#ifdef CONFIG_NET_STATISTICS_ETHERNET
69+
#ifdef CONFIG_NET_STATISTICS_ETHERNET_VENDOR
70+
struct net_stats_eth_vendor eth_stats_vendor_data[MAX_VENDOR_STATS];
71+
char vendor_key_strings[MAX_VENDOR_STATS][16];
72+
#endif /* CONFIG_NET_STATISTICS_ETHERNET_VENDOR */
6473
struct net_stats_eth eth_stats;
6574
#endif /* CONFIG_NET_STATISTICS_ETHERNET */
6675
#if defined(CONFIG_NRF70_STA_MODE) || defined(CONFIG_NRF70_RAW_DATA_RX)

drivers/wifi/nrf_wifi/src/net_if.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,16 @@ 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) {
12181228
LOG_ERR("%s Device not found", __func__);
@@ -1225,6 +1235,69 @@ 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,
1247+
RPU_STATS_TYPE_ALL,
1248+
&stats);
1249+
if (status != NRF_WIFI_STATUS_SUCCESS) {
1250+
LOG_ERR("%s: Failed to get RPU stats", __func__);
1251+
goto ret;
1252+
}
1253+
1254+
/* Treat stats.fw as a blob and divide into uint32_t chunks */
1255+
fw_stats_size = sizeof(stats.fw);
1256+
num_uint32 = fw_stats_size / sizeof(uint32_t);
1257+
fw_stats_bytes = (const uint8_t *)&stats.fw;
1258+
1259+
vendor_idx = 0;
1260+
1261+
for (i = 0; i < num_uint32 && vendor_idx < MAX_VENDOR_STATS - 1; i++) {
1262+
uint32_t val;
1263+
const char **key_ptr;
1264+
uint32_t *val_ptr;
1265+
1266+
/* Extract uint32_t value from blob */
1267+
memcpy(&val, fw_stats_bytes + i * sizeof(uint32_t), sizeof(uint32_t));
1268+
1269+
/* Create key name */
1270+
snprintk(vif_ctx_zep->vendor_key_strings[vendor_idx], 16, "fw_%zu", i);
1271+
1272+
/* Assign key */
1273+
key_ptr = (const char **)
1274+
&vif_ctx_zep->eth_stats_vendor_data[vendor_idx].key;
1275+
*key_ptr = vif_ctx_zep->vendor_key_strings[vendor_idx];
1276+
1277+
/* Assign value */
1278+
val_ptr = (uint32_t *)
1279+
&vif_ctx_zep->eth_stats_vendor_data[vendor_idx].value;
1280+
*val_ptr = val;
1281+
1282+
vendor_idx++;
1283+
}
1284+
1285+
/* Null terminator entry */
1286+
{
1287+
const char **key_ptr = (const char **)
1288+
&vif_ctx_zep->eth_stats_vendor_data[vendor_idx].key;
1289+
uint32_t *val_ptr = (uint32_t *)
1290+
&vif_ctx_zep->eth_stats_vendor_data[vendor_idx].value;
1291+
1292+
*key_ptr = NULL;
1293+
*val_ptr = 0;
1294+
}
1295+
1296+
/* Point to the static vendor data */
1297+
vif_ctx_zep->eth_stats.vendor = vif_ctx_zep->eth_stats_vendor_data;
1298+
1299+
ret:
1300+
#endif /* CONFIG_NET_STATISTICS_ETHERNET_VENDOR */
12281301
return &vif_ctx_zep->eth_stats;
12291302
out:
12301303
return NULL;

0 commit comments

Comments
 (0)