From nobody Mon Jun 03 19:24:47 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VtNvz2SvDz5Js5C; Mon, 03 Jun 2024 19:24:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VtNvz1sfRz4V9Y; Mon, 3 Jun 2024 19:24:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717442687; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=C/Jl28HTiXRcN1I3bOHSNxUxLupm5F+aXZNz9MWMrXg=; b=sT2o0M2uj2yWod+UW2bLysjHs3FKo8kP0O7inNV9P2XLY/ooCzurA27yxzf5WccV/KLDV0 Opkfk3S+NAEy9jCAt1XulMusPaJzdaiU6U3/RX5qz5QvJqOTIKUhQxlmPdvj/ScNw150tT 9xFRxeP/dLUEvSKbuNjDZEVcogi43zH+4QiXQOhH6W+slexJ3/JqmKQ429C641fkK+Rmsu qCgTKFKfFQitnoudECpzoSpBtSykj5cqRMzXZahoBAZQLT7/UdNAaCz8wsKRTMlVa2Ytlz GaChjFUoRAbwZwOQ9W8kMHKLVj7mO2kDMgiLO3ZKeje4U2NSYdCXheIxd8Vonw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1717442687; a=rsa-sha256; cv=none; b=Q56ReaybZdo6tHlY+lgLxjET0EiReD+fHbvxyzJ0Cw/zAbtwOKJOK68QnRZfhc207gdi+P epSSYqPO+JyivCaTPy6De3CzINXxgZIt40hgmIey9Cfo9J3jQfXCVXWfi4X3oEd5y/Wkdi wAhy9Z9n5yigICF3R/H/P/F/Q7oZQqIa7vtLfV3NpVIVjxrUreyFzaUOm2MPuXzd5JQ4tc tMWWl2hTg+uGPk49Va0Ub2CGWPaQCnn46eQ7vJtyJfh0WY8huDdoXL8mBkewBbgwVKIs7E 3gMUsqvTMAsZCTYNjsa0j7/AN3h4ticCYLOquVJPngnjoj/yoflme73LLFKBXQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717442687; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=C/Jl28HTiXRcN1I3bOHSNxUxLupm5F+aXZNz9MWMrXg=; b=jQfSl4J5jg57hYvedgBgZUp3sZqev4tWhnWoXAzzGgSBj44CUE9sEwPdd79HXImLmbeokM AnzEemLczZtUrJ6dCOPy+OOgGoeGEXl+XV+d0VTiIW081govEUYgD6ECIle8AaQIrkHtDB CgXePT6KeRzCm7pxNWHNyqzE2CkiC9VVl7ceZWg83Q1HCRZpsG063Ny7oZ10LelqVHTN+P Khp2q+N0EXySmrqM54SCbSFSb84xU1j3I3upRYUDXfj7q+nhlUe69jvjARTM/oD3hRGURD dTVFf+jHK0gQHLer8wU0ixrtUIkoCPjR9CS+tEOS3tmaI1HXyknWDnBwsPZP1Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VtNvz1Kn5zndv; Mon, 3 Jun 2024 19:24:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 453JOlkY067265; Mon, 3 Jun 2024 19:24:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 453JOlBE067262; Mon, 3 Jun 2024 19:24:47 GMT (envelope-from git) Date: Mon, 3 Jun 2024 19:24:47 GMT Message-Id: <202406031924.453JOlBE067262@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 4083c62d6993 - stable/14 - if_bnxt: Correcting the firmware package version parsing logic List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 4083c62d69932a42992fcd235a7cecf610ad9e25 Auto-Submitted: auto-generated The branch stable/14 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=4083c62d69932a42992fcd235a7cecf610ad9e25 commit 4083c62d69932a42992fcd235a7cecf610ad9e25 Author: Sumit Saxena AuthorDate: 2024-02-23 08:20:26 +0000 Commit: Warner Losh CommitDate: 2024-06-03 19:23:12 +0000 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) --- sys/dev/bnxt/bnxt_sysctl.c | 58 +++++++++++++++++++++++++++++----------------- 1 file 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 #include #include +#include #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[] = ""; 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; }