Skip to content

Commit 3b2712b

Browse files
committed
drivers: nrf_wifi: Switch to new stats API
nRF70 queries FW to fet the stats, use the new stats API and filter FW query depending on the type. Signed-off-by: Chaitanya Tata <[email protected]>
1 parent 6a6f753 commit 3b2712b

File tree

3 files changed

+36
-37
lines changed

3 files changed

+36
-37
lines changed

drivers/wifi/nrf_wifi/inc/net_if.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ enum nrf_wifi_status nrf_wifi_if_carr_state_chg(void *os_vif_ctx,
5656
int nrf_wifi_stats_get(const struct device *dev,
5757
struct net_stats_wifi *stats);
5858

59-
struct net_stats_eth *nrf_wifi_eth_stats_get(const struct device *dev);
59+
#ifdef CONFIG_NET_STATISTICS_ETHERNET
60+
struct net_stats_eth *nrf_wifi_eth_stats_get_type(const struct device *dev,
61+
uint32_t type);
62+
#endif /* CONFIG_NET_STATISTICS_ETHERNET */
6063

6164
void nrf_wifi_set_iface_event_handler(void *os_vif_ctx,
6265
struct nrf_wifi_umac_event_set_interface *event,

drivers/wifi/nrf_wifi/src/fmac_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ static const struct net_wifi_mgmt_offload wifi_offload_ops = {
978978
.wifi_iface.get_capabilities = nrf_wifi_if_caps_get,
979979
.wifi_iface.send = nrf_wifi_if_send,
980980
#ifdef CONFIG_NET_STATISTICS_ETHERNET
981-
.wifi_iface.get_stats = nrf_wifi_eth_stats_get,
981+
.wifi_iface.get_stats_type = nrf_wifi_eth_stats_get_type,
982982
#endif /* CONFIG_NET_STATISTICS_ETHERNET */
983983
#ifdef CONFIG_NET_L2_WIFI_MGMT
984984
.wifi_mgmt_api = &nrf_wifi_mgmt_ops,

drivers/wifi/nrf_wifi/src/net_if.c

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,8 @@ int nrf_wifi_if_set_config_zep(const struct device *dev,
12101210
}
12111211

12121212
#ifdef CONFIG_NET_STATISTICS_ETHERNET
1213-
struct net_stats_eth *nrf_wifi_eth_stats_get(const struct device *dev)
1213+
struct net_stats_eth *nrf_wifi_eth_stats_get_type(const struct device *dev,
1214+
uint32_t type)
12141215
{
12151216
struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL;
12161217
#ifdef CONFIG_NET_STATISTICS_ETHERNET_VENDOR
@@ -1222,24 +1223,34 @@ struct net_stats_eth *nrf_wifi_eth_stats_get(const struct device *dev)
12221223
const uint8_t *fw_stats_bytes;
12231224
size_t i;
12241225
int vendor_idx = 0;
1225-
#endif /* CONFIG_NET_STATISTICS_ETHERNET_VENDOR */
1226+
const char **key_ptr;
1227+
uint32_t *val_ptr;
1228+
uint32_t val;
1229+
#endif
12261230

12271231
if (!dev) {
12281232
LOG_ERR("%s Device not found", __func__);
1229-
goto out;
1233+
goto err;
12301234
}
12311235

12321236
vif_ctx_zep = dev->data;
12331237
if (!vif_ctx_zep) {
12341238
LOG_ERR("%s: vif_ctx_zep is NULL", __func__);
1235-
goto out;
1239+
goto err;
1240+
}
1241+
1242+
if (!(type & ETHERNET_STATS_TYPE_VENDOR)) {
1243+
#ifdef CONFIG_NET_STATISTICS_ETHERNET_VENDOR
1244+
vif_ctx_zep->eth_stats.vendor = NULL;
1245+
#endif
1246+
goto done;
12361247
}
12371248

12381249
#ifdef CONFIG_NET_STATISTICS_ETHERNET_VENDOR
12391250
rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep;
12401251
if (!rpu_ctx_zep || !rpu_ctx_zep->rpu_ctx) {
12411252
LOG_ERR("%s: rpu_ctx_zep or rpu_ctx is NULL", __func__);
1242-
goto out;
1253+
goto err;
12431254
}
12441255

12451256
memset(&stats, 0, sizeof(stats));
@@ -1248,7 +1259,7 @@ struct net_stats_eth *nrf_wifi_eth_stats_get(const struct device *dev)
12481259
&stats);
12491260
if (status != NRF_WIFI_STATUS_SUCCESS) {
12501261
LOG_ERR("%s: Failed to get RPU stats", __func__);
1251-
goto ret;
1262+
goto done;
12521263
}
12531264

12541265
/* Treat stats.fw as a blob and divide into uint32_t chunks */
@@ -1257,49 +1268,34 @@ struct net_stats_eth *nrf_wifi_eth_stats_get(const struct device *dev)
12571268
fw_stats_bytes = (const uint8_t *)&stats.fw;
12581269

12591270
vendor_idx = 0;
1260-
12611271
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));
1272+
memcpy(&val, fw_stats_bytes + i * sizeof(uint32_t),
1273+
sizeof(uint32_t));
12681274

1269-
/* Create key name */
1270-
snprintk(vif_ctx_zep->vendor_key_strings[vendor_idx], 16, "fw_%zu", i);
1275+
snprintk(vif_ctx_zep->vendor_key_strings[vendor_idx], 16,
1276+
"fw_%zu", i);
12711277

1272-
/* Assign key */
1273-
key_ptr = (const char **)
1274-
&vif_ctx_zep->eth_stats_vendor_data[vendor_idx].key;
1278+
key_ptr = (const char **) &vif_ctx_zep->eth_stats_vendor_data[vendor_idx].key;
12751279
*key_ptr = vif_ctx_zep->vendor_key_strings[vendor_idx];
12761280

1277-
/* Assign value */
1278-
val_ptr = (uint32_t *)
1279-
&vif_ctx_zep->eth_stats_vendor_data[vendor_idx].value;
1281+
val_ptr = (uint32_t *) &vif_ctx_zep->eth_stats_vendor_data[vendor_idx].value;
12801282
*val_ptr = val;
12811283

12821284
vendor_idx++;
12831285
}
12841286

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-
}
1287+
key_ptr = (const char **) &vif_ctx_zep->eth_stats_vendor_data[vendor_idx].key;
1288+
val_ptr = (uint32_t *) &vif_ctx_zep->eth_stats_vendor_data[vendor_idx].value;
1289+
*key_ptr = NULL;
1290+
*val_ptr = 0;
12951291

1296-
/* Point to the static vendor data */
12971292
vif_ctx_zep->eth_stats.vendor = vif_ctx_zep->eth_stats_vendor_data;
1293+
#endif
12981294

1299-
ret:
1300-
#endif /* CONFIG_NET_STATISTICS_ETHERNET_VENDOR */
1295+
done:
13011296
return &vif_ctx_zep->eth_stats;
1302-
out:
1297+
1298+
err:
13031299
return NULL;
13041300
}
13051301
#endif /* CONFIG_NET_STATISTICS_ETHERNET */

0 commit comments

Comments
 (0)