From patchwork Sat Mar 5 08:54:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 12770280 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8300CC433FE for ; Sat, 5 Mar 2022 08:55:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230322AbiCEI4H (ORCPT ); Sat, 5 Mar 2022 03:56:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230320AbiCEI4E (ORCPT ); Sat, 5 Mar 2022 03:56:04 -0500 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9B8B255F96 for ; Sat, 5 Mar 2022 00:55:12 -0800 (PST) Received: by mail-pl1-x632.google.com with SMTP id q11so9755537pln.11 for ; Sat, 05 Mar 2022 00:55:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ml7xun6dP/zJK3FYuN0f3n6jorU4OA2WLKALwDr2hms=; b=GMedcHfJ3BonoPIjeraOaqZDk+yzs54INvkqfGWaTjVV1d9Bef5cMUeJraBO2dXntc G5qvOva/tg7gLVWcEoIqArhp9+y/6z6IGD/+dIVSPAOGXAq5zPpayJLZBBdI7ngu4ad2 LGjC8uxgHz58rJ6E+nF0HN93VT4D40qPX8ILI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ml7xun6dP/zJK3FYuN0f3n6jorU4OA2WLKALwDr2hms=; b=47zsDmNELLAgDx8SB9kHiNMH4AzaJ8Mt09HVADbIk8bU12TSPoIzA2sFecSVPVBXdM eCmMnUoDecY+ntp00jjxFYdrVUBZpg3Z/lDM+Em5J7wm91nX9RC8oYHRV1Zae8NZcHoj Htji4g1pTk6tiQuYcC+M0P2E4hQ+OzIZhpbcySIMwIzhSJPfA9bj/uZmWmQJZNHwo5nC AISPCVdUaC6Hxq0iRBr/tirz25qDE/aJzZhC7h/UaS3svuJsRGGXm8hZpb5H8BvA2Lbk ilymu4BG9K5GKNq1Bi9qXKhinzEAXSJNqxj06gObzTILK+H+ojWnJsGVHKHpU/pTHAGA Yrjw== X-Gm-Message-State: AOAM533pzKG5fZEzw0TWVntemZmGaahNUjBE0hDh4mC+vGMWvuPllODy pASUeguuxd93TpUaoSwBg38HMA== X-Google-Smtp-Source: ABdhPJzmCmwORmh32dycoT4UCN9gQ5Hz4fzpt5zmXkA0D82zk4iSmrpWOSoDjXcsRhHm6aqowqU3Ow== X-Received: by 2002:a17:902:7805:b0:151:b8ec:202b with SMTP id p5-20020a170902780500b00151b8ec202bmr2406399pll.111.1646470511673; Sat, 05 Mar 2022 00:55:11 -0800 (PST) Received: from localhost.swdvt.lab.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id p28-20020a056a000a1c00b004f6519e61b7sm9213261pfh.21.2022.03.05.00.55.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 05 Mar 2022 00:55:11 -0800 (PST) From: Michael Chan To: davem@davemloft.net Cc: netdev@vger.kernel.org, kuba@kernel.org, gospo@broadcom.com Subject: [PATCH net-next 9/9] bnxt_en: add an nvm test for hw diagnose Date: Sat, 5 Mar 2022 03:54:42 -0500 Message-Id: <1646470482-13763-10-git-send-email-michael.chan@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1646470482-13763-1-git-send-email-michael.chan@broadcom.com> References: <1646470482-13763-1-git-send-email-michael.chan@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vikas Gupta Add an NVM test function for devlink hw reporter. In this function an NVM VPD area is read followed by a write. Test result is cached and if it is successful then the next test can be conducted only after HW_RETEST_MIN_TIME to avoid frequent writes to the NVM. Reviewed-by: Edwin Peer Signed-off-by: Vikas Gupta Signed-off-by: Michael Chan --- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 20 ++++- .../net/ethernet/broadcom/bnxt/bnxt_devlink.c | 82 ++++++++++++++++++- .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 22 ++--- .../net/ethernet/broadcom/bnxt/bnxt_ethtool.h | 7 ++ 4 files changed, 113 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.h b/drivers/net/ethernet/broadcom/bnxt/bnxt.h index fa0df43ddc1a..9dd878def3c2 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.h +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.h @@ -1544,17 +1544,29 @@ struct bnxt_ctx_mem_info { }; enum bnxt_hw_err { - BNXT_HW_STATUS_HEALTHY = 0x0, - BNXT_HW_STATUS_NVM_WRITE_ERR = 0x1, - BNXT_HW_STATUS_NVM_ERASE_ERR = 0x2, - BNXT_HW_STATUS_NVM_UNKNOWN_ERR = 0x3, + BNXT_HW_STATUS_HEALTHY = 0x0, + BNXT_HW_STATUS_NVM_WRITE_ERR = 0x1, + BNXT_HW_STATUS_NVM_ERASE_ERR = 0x2, + BNXT_HW_STATUS_NVM_UNKNOWN_ERR = 0x3, + BNXT_HW_STATUS_NVM_TEST_VPD_ENT_ERR = 0x4, + BNXT_HW_STATUS_NVM_TEST_VPD_READ_ERR = 0x5, + BNXT_HW_STATUS_NVM_TEST_VPD_WRITE_ERR = 0x6, + BNXT_HW_STATUS_NVM_TEST_INCMPL_ERR = 0x7, }; struct bnxt_hw_health { u32 nvm_err_address; u32 nvm_write_errors; u32 nvm_erase_errors; + u32 nvm_test_vpd_ent_errors; + u32 nvm_test_vpd_read_errors; + u32 nvm_test_vpd_write_errors; + u32 nvm_test_incmpl_errors; u8 synd; + /* max a test in a day if previous test was successful */ +#define HW_RETEST_MIN_TIME (1000 * 3600 * 24) + u8 nvm_test_result; + unsigned long nvm_test_timestamp; struct devlink_health_reporter *hw_reporter; }; diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c index a802bbda1c27..77e55105d645 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c @@ -20,6 +20,7 @@ #include "bnxt_ulp.h" #include "bnxt_ptp.h" #include "bnxt_coredump.h" +#include "bnxt_nvm_defs.h" /* NVRAM content constant and structure defs */ static void __bnxt_fw_recover(struct bnxt *bp) { @@ -263,20 +264,82 @@ static const char *hw_err_str(u8 synd) return "nvm erase error"; case BNXT_HW_STATUS_NVM_UNKNOWN_ERR: return "unrecognized nvm error"; + case BNXT_HW_STATUS_NVM_TEST_VPD_ENT_ERR: + return "nvm test vpd entry error"; + case BNXT_HW_STATUS_NVM_TEST_VPD_READ_ERR: + return "nvm test vpd read error"; + case BNXT_HW_STATUS_NVM_TEST_VPD_WRITE_ERR: + return "nvm test vpd write error"; + case BNXT_HW_STATUS_NVM_TEST_INCMPL_ERR: + return "nvm test incomplete error"; default: return "unknown hw error"; } } +static void bnxt_nvm_test(struct bnxt *bp) +{ + struct bnxt_hw_health *h = &bp->hw_health; + u32 datalen; + u16 index; + u8 *buf; + + if (!h->nvm_test_result) { + if (!h->nvm_test_timestamp || + time_after(jiffies, h->nvm_test_timestamp + + msecs_to_jiffies(HW_RETEST_MIN_TIME))) + h->nvm_test_timestamp = jiffies; + else + return; + } + + if (bnxt_find_nvram_item(bp->dev, BNX_DIR_TYPE_VPD, + BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE, + &index, NULL, &datalen) || !datalen) { + h->nvm_test_result = BNXT_HW_STATUS_NVM_TEST_VPD_ENT_ERR; + h->nvm_test_vpd_ent_errors++; + return; + } + + buf = kzalloc(datalen, GFP_KERNEL); + if (!buf) { + h->nvm_test_result = BNXT_HW_STATUS_NVM_TEST_INCMPL_ERR; + h->nvm_test_incmpl_errors++; + return; + } + + if (bnxt_get_nvram_item(bp->dev, index, 0, datalen, buf)) { + h->nvm_test_result = BNXT_HW_STATUS_NVM_TEST_VPD_READ_ERR; + h->nvm_test_vpd_read_errors++; + goto err; + } + + if (bnxt_flash_nvram(bp->dev, BNX_DIR_TYPE_VPD, BNX_DIR_ORDINAL_FIRST, + BNX_DIR_EXT_NONE, 0, 0, buf, datalen)) { + h->nvm_test_result = BNXT_HW_STATUS_NVM_TEST_VPD_WRITE_ERR; + h->nvm_test_vpd_write_errors++; + } + +err: + kfree(buf); +} + static int bnxt_hw_diagnose(struct devlink_health_reporter *reporter, struct devlink_fmsg *fmsg, struct netlink_ext_ack *extack) { struct bnxt *bp = devlink_health_reporter_priv(reporter); struct bnxt_hw_health *h = &bp->hw_health; + u8 synd = h->synd; int rc; - rc = devlink_fmsg_string_pair_put(fmsg, "Status", hw_err_str(h->synd)); + bnxt_nvm_test(bp); + if (h->nvm_test_result) { + synd = h->nvm_test_result; + devlink_health_report(h->hw_reporter, hw_err_str(synd), NULL); + } + + rc = devlink_fmsg_string_pair_put(fmsg, "Status", hw_err_str(synd)); if (rc) return rc; rc = devlink_fmsg_u32_pair_put(fmsg, "nvm_write_errors", h->nvm_write_errors); @@ -285,6 +348,23 @@ static int bnxt_hw_diagnose(struct devlink_health_reporter *reporter, rc = devlink_fmsg_u32_pair_put(fmsg, "nvm_erase_errors", h->nvm_erase_errors); if (rc) return rc; + rc = devlink_fmsg_u32_pair_put(fmsg, "nvm_test_vpd_ent_errors", + h->nvm_test_vpd_ent_errors); + if (rc) + return rc; + rc = devlink_fmsg_u32_pair_put(fmsg, "nvm_test_vpd_read_errors", + h->nvm_test_vpd_read_errors); + if (rc) + return rc; + rc = devlink_fmsg_u32_pair_put(fmsg, "nvm_test_vpd_write_errors", + h->nvm_test_vpd_write_errors); + if (rc) + return rc; + rc = devlink_fmsg_u32_pair_put(fmsg, "nvm_test_incomplete_errors", + h->nvm_test_incmpl_errors); + if (rc) + return rc; + return 0; } diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c index eadaca42ed96..178074795b27 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c @@ -2168,14 +2168,10 @@ static void bnxt_print_admin_err(struct bnxt *bp) netdev_info(bp->dev, "PF does not have admin privileges to flash or reset the device\n"); } -static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal, - u16 ext, u16 *index, u32 *item_length, - u32 *data_length); - -static int bnxt_flash_nvram(struct net_device *dev, u16 dir_type, - u16 dir_ordinal, u16 dir_ext, u16 dir_attr, - u32 dir_item_len, const u8 *data, - size_t data_len) +int bnxt_flash_nvram(struct net_device *dev, u16 dir_type, + u16 dir_ordinal, u16 dir_ext, u16 dir_attr, + u32 dir_item_len, const u8 *data, + size_t data_len) { struct bnxt *bp = netdev_priv(dev); struct hwrm_nvm_write_input *req; @@ -2819,8 +2815,8 @@ static int bnxt_get_nvram_directory(struct net_device *dev, u32 len, u8 *data) return rc; } -static int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset, - u32 length, u8 *data) +int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset, + u32 length, u8 *data) { struct bnxt *bp = netdev_priv(dev); int rc; @@ -2854,9 +2850,9 @@ static int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset, return rc; } -static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal, - u16 ext, u16 *index, u32 *item_length, - u32 *data_length) +int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal, + u16 ext, u16 *index, u32 *item_length, + u32 *data_length) { struct hwrm_nvm_find_dir_entry_output *output; struct hwrm_nvm_find_dir_entry_input *req; diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.h b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.h index 6aa44840f13a..2593e0049582 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.h +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.h @@ -56,6 +56,13 @@ int bnxt_hwrm_firmware_reset(struct net_device *dev, u8 proc_type, int bnxt_flash_package_from_fw_obj(struct net_device *dev, const struct firmware *fw, u32 install_type); int bnxt_get_pkginfo(struct net_device *dev, char *ver, int size); +int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal, u16 ext, + u16 *index, u32 *item_length, u32 *data_length); +int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset, + u32 length, u8 *data); +int bnxt_flash_nvram(struct net_device *dev, u16 dir_type, u16 dir_ordinal, + u16 dir_ext, u16 dir_attr, u32 dir_item_len, + const u8 *data, size_t data_len); void bnxt_ethtool_init(struct bnxt *bp); void bnxt_ethtool_free(struct bnxt *bp);