From nobody Wed Mar 06 12:17:46 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 4TqWfL6fHmz5CTLP; Wed, 6 Mar 2024 12:17:46 +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 4TqWfL66rrz4G3P; Wed, 6 Mar 2024 12:17:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1709727466; 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=p9IrzvdHsNhO+hCu1GNyC9MaUru9L9He0re9fiBmqbg=; b=jSuUDEUmxFf5XF9Ii34Fq8dQcmxsM49ges3mvfyKqg5CWV9Y8/VQXPbu/YO/WG3nGE/xiG WVaZuO4/BuJQbW7WaPMve0D1CKJbUxXzOrUsGYJS9nEnjlUJNSdSa/MN2/Jwb0a2G5otjE y6CggS/m3EpVSEV1LbXIc+esDsGWJE//VViaqGB6LlToPkjdnZ9V0F5jQ4Yfan8xtms9lu d9hISXUhbBvqQF7srPlP2TMiJKi19vdu32G7ZJ2XUiA17SHngI/mGBBzRGgFuslc1xtgR7 Iu4VNIj0NEPh0JNXWwflppOjk8e4owFs8Q2eGJNBXSHWhUxtlJa6PQy4qUavWw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1709727466; a=rsa-sha256; cv=none; b=F6PHFOvMWSp1X1VwTOfWUJ70X+MBnfShkaoZCg+/wJDeesQg84jlIqY9EbBjHgR5etH1Lj Alh4yO+Tsxns3kIqcwjWxgl4oy1QIsAaIF57jpsnnnCWs/5qImvJrQKkY0l7+ps/seWan9 2LaNGXmPEJIPWPvjkyDNCo8OMbZW6+corLWF0365MnA35bG0qI4KQQhvvttkf6Q/PSN2Vd OSN2J1u6IXOvQJ15Q3DEh8r++9PXpjkk/8bLqEuWFd4Js5zb1ReQpiO4D4jzEgIVzSOj+V f+5zLr3IJwJRHVrqx7b/mO4hW6jnG8Ef92yVyMNX6luLIgBv424TFVKX7SOWbA== 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=1709727466; 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=p9IrzvdHsNhO+hCu1GNyC9MaUru9L9He0re9fiBmqbg=; b=d/YT9JpUDpUJ6s6oX9sFt891z690C/66PaS8pjbEhR/hiaypgBB1SUAquFt98t6i7j69yi QnFcI8f6Yc3LIs0/2nnIc1QVCDVtJrTWKpyI+SU+Ia8lxtA4Qjn5aYjJSlKGoYK9n2fVTr R6Q22MA271/WdClDcyfNaBR3T9oIFXK13SBtrlohh8DW6MiSGUk8rPEmkNBgwmTU2dzdGP 2MJfEwa9DA1a/TtzfU9f3wErOGoi2g061kqGTCp9ZMpqLTbO1DpYUm4FuYCBAgBmPjosU2 CMRvg/sfKrsFmck04TSckeXuoUCt0Y75bnBcOWt86sMJUX9PRRSyJ/yETU9Y9Q== 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 4TqWfL5k8nzpwL; Wed, 6 Mar 2024 12:17:46 +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 426CHko1002175; Wed, 6 Mar 2024 12:17:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 426CHksf002172; Wed, 6 Mar 2024 12:17:46 GMT (envelope-from git) Date: Wed, 6 Mar 2024 12:17:46 GMT Message-Id: <202403061217.426CHksf002172@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Sumit Saxena Subject: git: e436cb79666d - main - 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: ssaxena X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e436cb79666db3c8bb167d47ca9803c36013e32c Auto-Submitted: auto-generated The branch main has been updated by ssaxena: URL: https://cgit.FreeBSD.org/src/commit/?id=e436cb79666db3c8bb167d47ca9803c36013e32c commit e436cb79666db3c8bb167d47ca9803c36013e32c Author: Sumit Saxena AuthorDate: 2024-02-23 08:20:26 +0000 Commit: Sumit Saxena CommitDate: 2024-03-06 12:17:29 +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 --- 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 943e3019f579..971754029afd 100644 --- a/sys/dev/bnxt/bnxt_sysctl.c +++ b/sys/dev/bnxt/bnxt_sysctl.c @@ -28,6 +28,7 @@ #include #include +#include #include "bnxt.h" #include "bnxt_hwrm.h" @@ -719,6 +720,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) { @@ -726,11 +760,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; @@ -748,27 +780,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; }