|
14 | 14 | #include "fmac_main.h"
|
15 | 15 | #include "wifi_util.h"
|
16 | 16 |
|
| 17 | +#include "rpu_lmac_phy_stats.h" |
| 18 | +#include "rpu_umac_stats.h" |
| 19 | + |
17 | 20 | extern struct nrf_wifi_drv_priv_zep rpu_drv_priv_zep;
|
18 | 21 | struct nrf_wifi_ctx_zep *ctx = &rpu_drv_priv_zep.rpu_ctx_zep;
|
19 | 22 |
|
@@ -963,6 +966,129 @@ static int nrf_wifi_util_rpu_recovery_info(const struct shell *sh,
|
963 | 966 | }
|
964 | 967 | #endif /* CONFIG_NRF_WIFI_RPU_RECOVERY */
|
965 | 968 |
|
| 969 | +static int nrf_wifi_dump_stats(const struct shell *sh, |
| 970 | + struct nrf_wifi_hal_dev_ctx *hal_dev_ctx, |
| 971 | + const char *name, |
| 972 | + struct rpu_stat_global *rpu_stat_g) |
| 973 | +{ |
| 974 | + int i; |
| 975 | + int j; |
| 976 | + int ret = 0; |
| 977 | + |
| 978 | + for (i = 0; rpu_stat_g[i].stats != NULL; i++) { |
| 979 | + struct rpu_stat_from_mem *rpu_stat = rpu_stat_g[i].stats; |
| 980 | + |
| 981 | + shell_fprintf(sh, SHELL_INFO, "RPU %s - %s\n", name, rpu_stat_g[i].name); |
| 982 | + shell_fprintf(sh, SHELL_INFO, "======================\n"); |
| 983 | + |
| 984 | + for (j = 0; rpu_stat[j].name[0] != '\0'; j++) { |
| 985 | + uint32_t value = 0; |
| 986 | + |
| 987 | + if (hal_rpu_mem_read(hal_dev_ctx, &value, |
| 988 | + rpu_stat[j].addr, sizeof(value)) != 0) { |
| 989 | + shell_fprintf(sh, SHELL_ERROR, |
| 990 | + "Failed to read stat %s\n", |
| 991 | + rpu_stat[j].name); |
| 992 | + continue; |
| 993 | + } |
| 994 | + |
| 995 | + shell_fprintf(sh, SHELL_INFO, "%s: %u\n", |
| 996 | + rpu_stat[j].name, |
| 997 | + value); |
| 998 | + } |
| 999 | + |
| 1000 | + shell_fprintf(sh, SHELL_INFO, "\n"); |
| 1001 | + } |
| 1002 | + |
| 1003 | + return ret; |
| 1004 | +} |
| 1005 | + |
| 1006 | +static int nrf_wifi_util_dump_rpu_stats_mem(const struct shell *sh, |
| 1007 | + size_t argc, |
| 1008 | + const char *argv[]) |
| 1009 | +{ |
| 1010 | + struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx; |
| 1011 | + struct nrf_wifi_hal_dev_ctx *hal_dev_ctx; |
| 1012 | + struct rpu_sys_op_stats stats; |
| 1013 | + enum rpu_stats_type stats_type = RPU_STATS_TYPE_ALL; |
| 1014 | + int ret; |
| 1015 | + |
| 1016 | + if (argc == 2) { |
| 1017 | + const char *type = argv[1]; |
| 1018 | + |
| 1019 | + if (!strcmp(type, "umac")) { |
| 1020 | + stats_type = RPU_STATS_TYPE_UMAC; |
| 1021 | + } else if (!strcmp(type, "lmac")) { |
| 1022 | + stats_type = RPU_STATS_TYPE_LMAC; |
| 1023 | + } else if (!strcmp(type, "all")) { |
| 1024 | + stats_type = RPU_STATS_TYPE_ALL; |
| 1025 | + } else { |
| 1026 | + shell_fprintf(sh, |
| 1027 | + SHELL_ERROR, |
| 1028 | + "Invalid stats type %s\n", |
| 1029 | + type); |
| 1030 | + return -ENOEXEC; |
| 1031 | + } |
| 1032 | + } |
| 1033 | + |
| 1034 | + k_mutex_lock(&ctx->rpu_lock, K_FOREVER); |
| 1035 | + if (!ctx->rpu_ctx) { |
| 1036 | + shell_fprintf(sh, |
| 1037 | + SHELL_ERROR, |
| 1038 | + "RPU context not initialized\n"); |
| 1039 | + ret = -ENOEXEC; |
| 1040 | + goto unlock; |
| 1041 | + } |
| 1042 | + fmac_dev_ctx = ctx->rpu_ctx; |
| 1043 | + if (!fmac_dev_ctx) { |
| 1044 | + shell_fprintf(sh, |
| 1045 | + SHELL_ERROR, |
| 1046 | + "RPU context not initialized\n"); |
| 1047 | + ret = -ENOEXEC; |
| 1048 | + goto unlock; |
| 1049 | + } |
| 1050 | + hal_dev_ctx = fmac_dev_ctx->hal_dev_ctx; |
| 1051 | + if (!hal_dev_ctx) { |
| 1052 | + shell_fprintf(sh, |
| 1053 | + SHELL_ERROR, |
| 1054 | + "HAL context not initialized\n"); |
| 1055 | + ret = -ENOEXEC; |
| 1056 | + goto unlock; |
| 1057 | + } |
| 1058 | + |
| 1059 | + |
| 1060 | + memset(&stats, 0, sizeof(struct rpu_sys_op_stats)); |
| 1061 | + |
| 1062 | + if (stats_type == RPU_STATS_TYPE_UMAC || stats_type == RPU_STATS_TYPE_ALL) { |
| 1063 | + nrf_wifi_hal_proc_ctx_set(hal_dev_ctx, RPU_PROC_TYPE_MCU_UMAC); |
| 1064 | + ret = nrf_wifi_dump_stats(sh, hal_dev_ctx, "UMAC", rpu_all_umac_stats); |
| 1065 | + if (ret != 0) { |
| 1066 | + shell_fprintf(sh, |
| 1067 | + SHELL_ERROR, |
| 1068 | + "Failed to dump UMAC stats\n"); |
| 1069 | + goto unlock; |
| 1070 | + } |
| 1071 | + } |
| 1072 | + |
| 1073 | + if (stats_type == RPU_STATS_TYPE_LMAC || stats_type == RPU_STATS_TYPE_ALL) { |
| 1074 | + nrf_wifi_hal_proc_ctx_set(hal_dev_ctx, RPU_PROC_TYPE_MCU_LMAC); |
| 1075 | + ret = nrf_wifi_dump_stats(sh, hal_dev_ctx, "LMAC", rpu_all_lmac_stats); |
| 1076 | + if (ret != 0) { |
| 1077 | + shell_fprintf(sh, |
| 1078 | + SHELL_ERROR, |
| 1079 | + "Failed to dump LMAC stats\n"); |
| 1080 | + goto unlock; |
| 1081 | + } |
| 1082 | + } |
| 1083 | + |
| 1084 | + /* Reset the proc context to default */ |
| 1085 | + nrf_wifi_hal_proc_ctx_set(hal_dev_ctx, RPU_PROC_TYPE_MCU_LMAC); |
| 1086 | + |
| 1087 | +unlock: |
| 1088 | + k_mutex_unlock(&ctx->rpu_lock); |
| 1089 | + return ret; |
| 1090 | +} |
| 1091 | + |
966 | 1092 | SHELL_STATIC_SUBCMD_SET_CREATE(
|
967 | 1093 | nrf_wifi_util_subcmds,
|
968 | 1094 | SHELL_CMD_ARG(he_ltf,
|
@@ -1066,6 +1192,13 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
|
1066 | 1192 | 1,
|
1067 | 1193 | 0),
|
1068 | 1194 | #endif /* CONFIG_NRF_WIFI_RPU_RECOVERY */
|
| 1195 | + SHELL_CMD_ARG(rpu_stats_mem, |
| 1196 | + NULL, |
| 1197 | + "Display RPU stats by reading from memory " |
| 1198 | + "Parameters: umac or lmac or or all (default)", |
| 1199 | + nrf_wifi_util_dump_rpu_stats_mem, |
| 1200 | + 1, |
| 1201 | + 1), |
1069 | 1202 | SHELL_SUBCMD_SET_END);
|
1070 | 1203 |
|
1071 | 1204 |
|
|
0 commit comments