From patchwork Mon Jul 18 06:20:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikas Gupta X-Patchwork-Id: 12920750 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 3A23CCCA489 for ; Mon, 18 Jul 2022 06:22:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233074AbiGRGVa (ORCPT ); Mon, 18 Jul 2022 02:21:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233296AbiGRGVP (ORCPT ); Mon, 18 Jul 2022 02:21:15 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1023A14029 for ; Sun, 17 Jul 2022 23:21:14 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id q5so8157711plr.11 for ; Sun, 17 Jul 2022 23:21:14 -0700 (PDT) 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=Suv7fvxByBEsdarSgRRAoorOw4J0pYwBOnqp2FQkPHc=; b=b+OIzHMNgZcIYD24Dw+As3dBkKL8uZZHF0ForcynZ3qgIu4kaPoRjPtn3GPBoJ4MUA TcA7AYT1s+wLQ1+9rvf5UiKXqFj0guQLfJMQiB8LIM2JvrnLfVqjdspvp7llpUQVhEJQ TljDVWFTJMAa/lbdq4YXePItgbOGblEfn0BpE= 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=Suv7fvxByBEsdarSgRRAoorOw4J0pYwBOnqp2FQkPHc=; b=1B0QhZc2EHSxsRdw1UI2LIZNLNLQPPzaWFAjeyq7ywfG31yEkTnmkh+GnvggC2B/qi cqAJuC3PGxSfDVkOKE6f4C+rVQzDklfbeO2AfTLqSQ6VqfpQOPwLkAfy6lT0rp1L+mgF QbAfcLwzf6+hln/x4i5sUjkhxuin1eirr23NR8UsOSBfupaO8xk1Z/dFr2CqFbMCllHX xDlFGJSDFo3Fp4Lfb/u9DtFBX88LpShyJienIldoyjMcPpuWFD8hIma4bLirCfThc1Hf wflL8fHYhq1/p2OVWe6RphfPmS53QKXGlnASGLuyftCYGiuq3jW3sz+nM1W89YQiQadL 95iQ== X-Gm-Message-State: AJIora8DsYMb548VQ8zCKWq3Tiijh+Xlg+PzqPUXU8aDJZ2+kg5yf0lH Lwplx639r42jvQD3i++9X4bfCA== X-Google-Smtp-Source: AGRyM1tFH8gRwx2TENSO+/lHYipZeB/ObN8QCw5ZygwkTjP8pO52wmkBDoJVMpfOC6oJS/hXw4nrgw== X-Received: by 2002:a17:903:2483:b0:16c:dfcf:38e8 with SMTP id p3-20020a170903248300b0016cdfcf38e8mr9767888plw.43.1658125273214; Sun, 17 Jul 2022 23:21:13 -0700 (PDT) Received: from rahul_yocto_ubuntu18.ibn.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id h22-20020a170902f7d600b0016c4fe627eesm8360164plw.241.2022.07.17.23.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jul 2022 23:21:12 -0700 (PDT) From: Vikas Gupta To: jiri@nvidia.com, kuba@kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davem@davemloft.net, dsahern@kernel.org, stephen@networkplumber.org, edumazet@google.com, pabeni@redhat.com, ast@kernel.org, leon@kernel.org, linux-doc@vger.kernel.org, corbet@lwn.net, michael.chan@broadcom.com, andrew.gospodarek@broadcom.com, Vikas Gupta Subject: [PATCH net-next v3 3/3] bnxt_en: implement callbacks for devlink selftests Date: Mon, 18 Jul 2022 11:50:32 +0530 Message-Id: <20220718062032.22426-4-vikas.gupta@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220718062032.22426-1-vikas.gupta@broadcom.com> References: <0220707182950.29348-1-vikas.gupta@broadcom.com> <20220718062032.22426-1-vikas.gupta@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add callbacks ============= .selftest_check: returns true for flash selftest. .selftest_run: runs a flash selftest. Signed-off-by: Vikas Gupta Reviewed-by: Michael Chan Reviewed-by: Andy Gospodarek --- .../net/ethernet/broadcom/bnxt/bnxt_devlink.c | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c index 6b3d4f4c2a75..927cf368d856 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c @@ -20,6 +20,8 @@ #include "bnxt_ulp.h" #include "bnxt_ptp.h" #include "bnxt_coredump.h" +#include "bnxt_nvm_defs.h" +#include "bnxt_ethtool.h" static void __bnxt_fw_recover(struct bnxt *bp) { @@ -610,6 +612,62 @@ static int bnxt_dl_reload_up(struct devlink *dl, enum devlink_reload_action acti return rc; } +static bool bnxt_nvm_test(struct bnxt *bp, struct netlink_ext_ack *extack) +{ + u32 datalen; + u16 index; + u8 *buf; + + if (bnxt_find_nvram_item(bp->dev, BNX_DIR_TYPE_VPD, + BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE, + &index, NULL, &datalen) || !datalen) { + NL_SET_ERR_MSG_MOD(extack, "nvm test vpd entry error"); + return false; + } + + buf = kzalloc(datalen, GFP_KERNEL); + if (!buf) { + NL_SET_ERR_MSG_MOD(extack, "insufficient memory for nvm test"); + return false; + } + + if (bnxt_get_nvram_item(bp->dev, index, 0, datalen, buf)) { + NL_SET_ERR_MSG_MOD(extack, "nvm test vpd read error"); + goto err; + } + + if (bnxt_flash_nvram(bp->dev, BNX_DIR_TYPE_VPD, BNX_DIR_ORDINAL_FIRST, + BNX_DIR_EXT_NONE, 0, 0, buf, datalen)) { + NL_SET_ERR_MSG_MOD(extack, "nvm test vpd write error"); + goto err; + } + + return true; + +err: + kfree(buf); + return false; +} + +static bool bnxt_dl_selftest_check(struct devlink *dl, int test_id, + struct netlink_ext_ack *extack) +{ + return (test_id == DEVLINK_SELFTEST_ATTR_FLASH); +} + +static u8 bnxt_dl_selftest_run(struct devlink *dl, int test_id, + struct netlink_ext_ack *extack) +{ + struct bnxt *bp = bnxt_get_bp_from_dl(dl); + + if (test_id == DEVLINK_SELFTEST_ATTR_FLASH) { + return (bnxt_nvm_test(bp, extack) ? DEVLINK_SELFTEST_PASS : + DEVLINK_SELFTEST_FAIL); + } + + return DEVLINK_SELFTEST_SKIP; +} + static const struct devlink_ops bnxt_dl_ops = { #ifdef CONFIG_BNXT_SRIOV .eswitch_mode_set = bnxt_dl_eswitch_mode_set, @@ -622,6 +680,8 @@ static const struct devlink_ops bnxt_dl_ops = { .reload_limits = BIT(DEVLINK_RELOAD_LIMIT_NO_RESET), .reload_down = bnxt_dl_reload_down, .reload_up = bnxt_dl_reload_up, + .selftest_check = bnxt_dl_selftest_check, + .selftest_run = bnxt_dl_selftest_run, }; static const struct devlink_ops bnxt_vf_dl_ops;