From nobody Sun Oct 06 03:49:26 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 4XLpF23tSyz5YCGf; Sun, 06 Oct 2024 03:49:26 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XLpF22b7Fz4FPD; Sun, 6 Oct 2024 03:49:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728186566; 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=QfnFFmgOBzzxphAkUhnNruB38/S4KWEaJ1JB3STr6N8=; b=U0kWXJxrCdXePZBv2Xf6FFEgGNJaSownF6ckw5CtrHm5c5ccDZHnsa2PWyIfvDRgRw/xUQ BkPvLO0actNh1+/oD4YyN+cjHe0WY2+GB4hpEFg9bS8oA4nnDkLJ5jTMm4/ErSi4I3NeFz y08dRkOhJ7lCL+oSGo1BzKVGS0vL/+FiFiQ7/4aqr1aHURE7S2X+MVXFDcB1hZsAjp/e0l i4faWkwvGt3TEbc+LAfcgIDlqxJ+xvExSAYAQohrr5VuvB3HGL3o8JjAkqmxt44v/TsQhK 5oRgN7M4OcE9KuEADoFK3nI/yGjRozQvVjmS7evcRMVcJydvHrect5ryOx1p5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728186566; 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=QfnFFmgOBzzxphAkUhnNruB38/S4KWEaJ1JB3STr6N8=; b=bp+IjmPGnsaiWTCSpHV7/li24P0qyBt5pAToG8HYd2HvzK2EPGph/KI32nV+v2XdigkBIi DA9xizivzRwewIPIh1IWYwEOmgVoQWEjC4UwUvS06iHe/hwbmM3fCHBvEB/2fR/waIe5d3 6RAV95FTtaooHlu9sPjTylEIf80bFmCJGPgiAFziuagp5r5mUcaxntfTQDv7oBXXryMTcz iySsn77I+745OkiOwNZ8Uc5KVF1PIxa/Bn4roL8ykx0bDoY14HqhwbH5g/LfM+VdAEGBQm UXCYHydVx3Qc1o/0V/60gda75fPmAbz63mevrY5UIqZcWK3QlCS6yU9iDQxSPg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728186566; a=rsa-sha256; cv=none; b=R9azZQKQ11Sazw96xXk5CvpZIsr0stxzoVqklF5dvGiWwURHi1vopVKq+VwHrtQMztECBM 8ysiuI7R7IFZ5JtJUGM0xBOFJKUDndUc2rIpUL0r71WrJSSW5Iif1gMYLP64EXgRM4ac/Z iUEFO9f3K7QG3nTWvgHeYXeJn+ZGuhvDU/k9wCWY84QNdWm8GrthSx8h1Ig2cjPtjGeY+M K6Iydt7OSVZkxhuKWP7kS+kYpKzVMX4LcCvOj/B8jUTMLyEcJNL38NnFLYkYuHlYzI8jGU yDEVppp3NvaywB2YF+8xkHjT36KKWqftSdjZYtC9NPfYKxGy0WUYyhf4kmIcpA== 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 4XLpF228c1zmmN; Sun, 6 Oct 2024 03:49:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4963nQ1f091950; Sun, 6 Oct 2024 03:49:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4963nQIh091947; Sun, 6 Oct 2024 03:49:26 GMT (envelope-from git) Date: Sun, 6 Oct 2024 03:49:26 GMT Message-Id: <202410060349.4963nQIh091947@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kevin Bowling Subject: git: 013d817b5393 - stable/14 - igc: Add NVM/firmware prints and sysctl 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: kbowling X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 013d817b539325017e00ede97d58c8adc16dbee3 Auto-Submitted: auto-generated The branch stable/14 has been updated by kbowling: URL: https://cgit.FreeBSD.org/src/commit/?id=013d817b539325017e00ede97d58c8adc16dbee3 commit 013d817b539325017e00ede97d58c8adc16dbee3 Author: Kevin Bowling AuthorDate: 2024-09-29 09:23:38 +0000 Commit: Kevin Bowling CommitDate: 2024-10-06 03:49:08 +0000 igc: Add NVM/firmware prints and sysctl This chipset suffered an (un)usual number of bugs and iterations. Let's add our NVM/firmware code from e1000 and the similar igc_nvm function from DPDK to keep track of issues. Sponsored by: BBOX.io (cherry picked from commit 33ed9bdca307bedb3d66a50ed7d4d7b4bf4acf39) --- sys/dev/igc/if_igc.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++ sys/dev/igc/if_igc.h | 2 + sys/dev/igc/igc_defines.h | 28 +++++++++++-- sys/dev/igc/igc_nvm.c | 81 ++++++++++++++++++++++++++++++++++++ sys/dev/igc/igc_nvm.h | 18 ++++++++ 5 files changed, 229 insertions(+), 4 deletions(-) diff --git a/sys/dev/igc/if_igc.c b/sys/dev/igc/if_igc.c index c78edab5e38a..006fecdab7b0 100644 --- a/sys/dev/igc/if_igc.c +++ b/sys/dev/igc/if_igc.c @@ -115,6 +115,10 @@ static void igc_update_stats_counters(struct igc_adapter *); static void igc_add_hw_stats(struct igc_adapter *adapter); static int igc_if_set_promisc(if_ctx_t ctx, int flags); static void igc_setup_vlan_hw_support(if_ctx_t ctx); +static void igc_fw_version(struct igc_adapter *); +static void igc_sbuf_fw_version(struct igc_fw_version *, struct sbuf *); +static void igc_print_fw_version(struct igc_adapter *); +static int igc_sysctl_print_fw_version(SYSCTL_HANDLER_ARGS); static int igc_sysctl_nvm_info(SYSCTL_HANDLER_ARGS); static void igc_print_nvm_info(struct igc_adapter *); static int igc_sysctl_debug_info(SYSCTL_HANDLER_ARGS); @@ -440,6 +444,12 @@ igc_if_attach_pre(if_ctx_t ctx) OID_AUTO, "nvm", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, adapter, 0, igc_sysctl_nvm_info, "I", "NVM Information"); + SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), + OID_AUTO, "fw_version", CTLTYPE_STRING | CTLFLAG_RD, + adapter, 0, igc_sysctl_print_fw_version, "A", + "Prints FW/NVM Versions"); + SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "debug", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, @@ -586,6 +596,11 @@ igc_if_attach_pre(if_ctx_t ctx) goto err_late; } + /* Save the EEPROM/NVM versions */ + igc_fw_version(adapter); + + igc_print_fw_version(adapter); + /* * Get Wake-on-Lan and Management info for later use */ @@ -2612,6 +2627,95 @@ igc_add_hw_stats(struct igc_adapter *adapter) "Rx Desc Min Thresh Count"); } +static void +igc_fw_version(struct igc_adapter *sc) +{ + struct igc_hw *hw = &sc->hw; + struct igc_fw_version *fw_ver = &sc->fw_ver; + + *fw_ver = (struct igc_fw_version){0}; + + igc_get_fw_version(hw, fw_ver); +} + +static void +igc_sbuf_fw_version(struct igc_fw_version *fw_ver, struct sbuf *buf) +{ + const char *space = ""; + + if (fw_ver->eep_major || fw_ver->eep_minor || fw_ver->eep_build) { + sbuf_printf(buf, "EEPROM V%d.%d-%d", fw_ver->eep_major, + fw_ver->eep_minor, fw_ver->eep_build); + space = " "; + } + + if (fw_ver->invm_major || fw_ver->invm_minor || fw_ver->invm_img_type) { + sbuf_printf(buf, "%sNVM V%d.%d imgtype%d", + space, fw_ver->invm_major, fw_ver->invm_minor, + fw_ver->invm_img_type); + space = " "; + } + + if (fw_ver->or_valid) { + sbuf_printf(buf, "%sOption ROM V%d-b%d-p%d", + space, fw_ver->or_major, fw_ver->or_build, + fw_ver->or_patch); + space = " "; + } + + if (fw_ver->etrack_id) + sbuf_printf(buf, "%seTrack 0x%08x", space, fw_ver->etrack_id); +} + +static void +igc_print_fw_version(struct igc_adapter *sc ) +{ + device_t dev = sc->dev; + struct sbuf *buf; + int error = 0; + + buf = sbuf_new_auto(); + if (!buf) { + device_printf(dev, "Could not allocate sbuf for output.\n"); + return; + } + + igc_sbuf_fw_version(&sc->fw_ver, buf); + + error = sbuf_finish(buf); + if (error) + device_printf(dev, "Error finishing sbuf: %d\n", error); + else if (sbuf_len(buf)) + device_printf(dev, "%s\n", sbuf_data(buf)); + + sbuf_delete(buf); +} + +static int +igc_sysctl_print_fw_version(SYSCTL_HANDLER_ARGS) +{ + struct igc_adapter *sc = (struct igc_adapter *)arg1; + device_t dev = sc->dev; + struct sbuf *buf; + int error = 0; + + buf = sbuf_new_for_sysctl(NULL, NULL, 128, req); + if (!buf) { + device_printf(dev, "Could not allocate sbuf for output.\n"); + return (ENOMEM); + } + + igc_sbuf_fw_version(&sc->fw_ver, buf); + + error = sbuf_finish(buf); + if (error) + device_printf(dev, "Error finishing sbuf: %d\n", error); + + sbuf_delete(buf); + + return (0); +} + /********************************************************************** * * This routine provides a way to dump out the adapter eeprom, diff --git a/sys/dev/igc/if_igc.h b/sys/dev/igc/if_igc.h index 92865b5b9eb1..727699baee5f 100644 --- a/sys/dev/igc/if_igc.h +++ b/sys/dev/igc/if_igc.h @@ -332,6 +332,8 @@ struct igc_adapter { u64 que_mask; + struct igc_fw_version fw_ver; + struct igc_int_delay_info tx_int_delay; struct igc_int_delay_info tx_abs_int_delay; struct igc_int_delay_info rx_int_delay; diff --git a/sys/dev/igc/igc_defines.h b/sys/dev/igc/igc_defines.h index 1701918c3a9c..e9ebd23c41c3 100644 --- a/sys/dev/igc/igc_defines.h +++ b/sys/dev/igc/igc_defines.h @@ -967,11 +967,31 @@ #define IGC_FLASH_UPDATES 2000 /* NVM Word Offsets */ -#define NVM_COMPAT 0x0003 -#define NVM_ID_LED_SETTINGS 0x0004 -#define NVM_FUTURE_INIT_WORD1 0x0019 -#define NVM_COMPAT_VALID_CSUM 0x0001 +#define NVM_COMPAT 0x0003 +#define NVM_ID_LED_SETTINGS 0x0004 +#define NVM_VERSION 0x0005 +#define NVM_FUTURE_INIT_WORD1 0x0019 +#define NVM_COMPAT_VALID_CSUM 0x0001 #define NVM_FUTURE_INIT_WORD1_VALID_CSUM 0x0040 +#define NVM_ETRACK_WORD 0x0042 +#define NVM_ETRACK_HIWORD 0x0043 +#define NVM_COMB_VER_OFF 0x0083 +#define NVM_COMB_VER_PTR 0x003d + +/* NVM version defines */ +#define NVM_MAJOR_MASK 0xF000 +#define NVM_MINOR_MASK 0x0FF0 +#define NVM_IMAGE_ID_MASK 0x000F +#define NVM_COMB_VER_MASK 0x00FF +#define NVM_MAJOR_SHIFT 12 +#define NVM_MINOR_SHIFT 4 +#define NVM_COMB_VER_SHFT 8 +#define NVM_VER_INVALID 0xFFFF +#define NVM_ETRACK_SHIFT 16 +#define NVM_ETRACK_VALID 0x8000 +#define NVM_NEW_DEC_MASK 0x0F00 +#define NVM_HEX_CONV 16 +#define NVM_HEX_TENS 10 #define NVM_INIT_CONTROL2_REG 0x000F #define NVM_INIT_CONTROL3_PORT_B 0x0014 diff --git a/sys/dev/igc/igc_nvm.c b/sys/dev/igc/igc_nvm.c index d86e04ffa0dc..b476a5fdbeac 100644 --- a/sys/dev/igc/igc_nvm.c +++ b/sys/dev/igc/igc_nvm.c @@ -716,4 +716,85 @@ static void igc_reload_nvm_generic(struct igc_hw *hw) IGC_WRITE_FLUSH(hw); } +/** + * igc_get_fw_version - Get firmware version information + * @hw: pointer to the HW structure + * @fw_vers: pointer to output version structure + * + * unsupported/not present features return 0 in version structure + **/ +void igc_get_fw_version(struct igc_hw *hw, struct igc_fw_version *fw_vers) +{ + u16 eeprom_verh, eeprom_verl, etrack_test, fw_version; + u8 q, hval, rem, result; + u16 comb_verh, comb_verl, comb_offset; + + memset(fw_vers, 0, sizeof(struct igc_fw_version)); + /* + * basic eeprom version numbers, bits used vary by part and by tool + * used to create the nvm images. Check which data format we have. + */ + switch (hw->mac.type) { + case igc_i225: + hw->nvm.ops.read(hw, NVM_ETRACK_HIWORD, 1, &etrack_test); + /* find combo image version */ + hw->nvm.ops.read(hw, NVM_COMB_VER_PTR, 1, &comb_offset); + if (comb_offset && comb_offset != NVM_VER_INVALID) { + hw->nvm.ops.read(hw, NVM_COMB_VER_OFF + comb_offset + 1, + 1, &comb_verh); + hw->nvm.ops.read(hw, NVM_COMB_VER_OFF + comb_offset, + 1, &comb_verl); + + /* get Option Rom version if it exists and is valid */ + if (comb_verh && comb_verl && + comb_verh != NVM_VER_INVALID && + comb_verl != NVM_VER_INVALID) { + fw_vers->or_valid = true; + fw_vers->or_major = comb_verl >> + NVM_COMB_VER_SHFT; + fw_vers->or_build = (comb_verl << + NVM_COMB_VER_SHFT) | + (comb_verh >> + NVM_COMB_VER_SHFT); + fw_vers->or_patch = comb_verh & + NVM_COMB_VER_MASK; + } + } + break; + default: + hw->nvm.ops.read(hw, NVM_ETRACK_HIWORD, 1, &etrack_test); + return; + } + hw->nvm.ops.read(hw, NVM_VERSION, 1, &fw_version); + fw_vers->eep_major = (fw_version & NVM_MAJOR_MASK) + >> NVM_MAJOR_SHIFT; + + /* check for old style version format in newer images*/ + if ((fw_version & NVM_NEW_DEC_MASK) == 0x0) { + eeprom_verl = (fw_version & NVM_COMB_VER_MASK); + } else { + eeprom_verl = (fw_version & NVM_MINOR_MASK) + >> NVM_MINOR_SHIFT; + } + /* Convert minor value to hex before assigning to output struct + * Val to be converted will not be higher than 99, per tool output + */ + q = eeprom_verl / NVM_HEX_CONV; + hval = q * NVM_HEX_TENS; + rem = eeprom_verl % NVM_HEX_CONV; + result = hval + rem; + fw_vers->eep_minor = result; + + if ((etrack_test & NVM_MAJOR_MASK) == NVM_ETRACK_VALID) { + hw->nvm.ops.read(hw, NVM_ETRACK_WORD, 1, &eeprom_verl); + hw->nvm.ops.read(hw, (NVM_ETRACK_WORD + 1), 1, &eeprom_verh); + fw_vers->etrack_id = (eeprom_verh << NVM_ETRACK_SHIFT) + | eeprom_verl; + } else if ((etrack_test & NVM_ETRACK_VALID) == 0) { + hw->nvm.ops.read(hw, NVM_ETRACK_WORD, 1, &eeprom_verh); + hw->nvm.ops.read(hw, (NVM_ETRACK_WORD + 1), 1, &eeprom_verl); + fw_vers->etrack_id = (eeprom_verh << NVM_ETRACK_SHIFT) | + eeprom_verl; + } +} diff --git a/sys/dev/igc/igc_nvm.h b/sys/dev/igc/igc_nvm.h index eae0db4b484b..b4b602af6595 100644 --- a/sys/dev/igc/igc_nvm.h +++ b/sys/dev/igc/igc_nvm.h @@ -7,6 +7,22 @@ #ifndef _IGC_NVM_H_ #define _IGC_NVM_H_ +struct igc_fw_version { + u32 etrack_id; + u16 eep_major; + u16 eep_minor; + u16 eep_build; + + u8 invm_major; + u8 invm_minor; + u8 invm_img_type; + + bool or_valid; + u16 or_major; + u16 or_build; + u16 or_patch; +}; + void igc_init_nvm_ops_generic(struct igc_hw *hw); s32 igc_null_read_nvm(struct igc_hw *hw, u16 a, u16 b, u16 *c); void igc_null_nvm_generic(struct igc_hw *hw); @@ -26,5 +42,7 @@ s32 igc_write_nvm_spi(struct igc_hw *hw, u16 offset, u16 words, u16 *data); s32 igc_update_nvm_checksum_generic(struct igc_hw *hw); void igc_release_nvm_generic(struct igc_hw *hw); +void igc_get_fw_version(struct igc_hw *hw, + struct igc_fw_version *fw_vers); #endif