diff options
| author | Sumit Saxena <ssaxena@FreeBSD.org> | 2024-02-23 08:20:26 +0000 |
|---|---|---|
| committer | Warner Losh <imp@FreeBSD.org> | 2024-06-03 19:23:12 +0000 |
| commit | 4083c62d69932a42992fcd235a7cecf610ad9e25 (patch) | |
| tree | 5d397ac2e8d370aa03f291ec351fe62d7e6922e1 | |
| parent | e1f5c22be4317523102a98f7f62c780fbe73b40f (diff) | |
if_bnxt: Correcting the firmware package version parsing logic
The firmware package version currently appears as "Unknown" through
the sysctl interface. The parsing logic for extracting the firmware
package version from the package log has been modified to ensure
compatibility with all controllers.
Reviewed by: imp
Approved by: imp
Differential revision: https://reviews.freebsd.org/D42950
(cherry picked from commit e436cb79666db3c8bb167d47ca9803c36013e32c)
| -rw-r--r-- | sys/dev/bnxt/bnxt_sysctl.c | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/sys/dev/bnxt/bnxt_sysctl.c b/sys/dev/bnxt/bnxt_sysctl.c index 893e56b61099..5e92cf8bd756 100644 --- a/sys/dev/bnxt/bnxt_sysctl.c +++ b/sys/dev/bnxt/bnxt_sysctl.c @@ -29,6 +29,7 @@ #include <sys/cdefs.h> #include <sys/types.h> #include <sys/sysctl.h> +#include <sys/ctype.h> #include "bnxt.h" #include "bnxt_hwrm.h" @@ -720,6 +721,39 @@ static char *bnxt_chip_type[] = { }; #define MAX_CHIP_TYPE 3 +static char *bnxt_parse_pkglog(int desired_field, uint8_t *data, size_t datalen) +{ + char *retval = NULL; + char *p; + char *value; + int field = 0; + + if (datalen < 1) + return NULL; + /* null-terminate the log data (removing last '\n'): */ + data[datalen - 1] = 0; + for (p = data; *p != 0; p++) { + field = 0; + retval = NULL; + while (*p != 0 && *p != '\n') { + value = p; + while (*p != 0 && *p != '\t' && *p != '\n') + p++; + if (field == desired_field) + retval = value; + if (*p != '\t') + break; + *p = 0; + field++; + p++; + } + if (*p == 0) + break; + *p = 0; + } + return retval; +} + static int bnxt_package_ver_sysctl(SYSCTL_HANDLER_ARGS) { @@ -727,11 +761,9 @@ bnxt_package_ver_sysctl(SYSCTL_HANDLER_ARGS) struct iflib_dma_info dma_data; char *pkglog = NULL; char *p; - char *next; char unk[] = "<unknown>"; char *buf = unk; int rc; - int field; uint16_t ordinal = BNX_DIR_ORDINAL_FIRST; uint16_t index; uint32_t data_len; @@ -749,27 +781,11 @@ bnxt_package_ver_sysctl(SYSCTL_HANDLER_ARGS) &dma_data); if (rc == 0) { pkglog = dma_data.idi_vaddr; - /* NULL terminate (removes last \n) */ - pkglog[data_len-1] = 0; - - /* Set p = start of last line */ - p = strrchr(pkglog, '\n'); - if (p == NULL) - p = pkglog; - - /* Now find the correct tab delimited field */ - for (field = 0, next = p, - p = strsep(&next, "\t"); - field < - BNX_PKG_LOG_FIELD_IDX_PKG_VERSION && p; - p = strsep(&next, "\t")) { - field++; - } - if (field == BNX_PKG_LOG_FIELD_IDX_PKG_VERSION) + p = bnxt_parse_pkglog(BNX_PKG_LOG_FIELD_IDX_PKG_VERSION, pkglog, data_len); + if (p && *p != 0 && isdigit(*p)) buf = p; } - } - else + } else dma_data.idi_vaddr = NULL; } |
