From patchwork Thu Jul 21 07:21:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikas Gupta X-Patchwork-Id: 12924814 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 374C1C43334 for ; Thu, 21 Jul 2022 07:22:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232431AbiGUHWD (ORCPT ); Thu, 21 Jul 2022 03:22:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232396AbiGUHV5 (ORCPT ); Thu, 21 Jul 2022 03:21:57 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96AAE7BE11 for ; Thu, 21 Jul 2022 00:21:49 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id x24-20020a17090ab01800b001f21556cf48so4376475pjq.4 for ; Thu, 21 Jul 2022 00:21:49 -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=4tbDvM/ARYtJL4bjfNEfZFzemfxnn/8UHyvUK82QuUM=; b=deQFvecZKLAFf+ZiUBb9kSBI8NWoX18V9CeV/+PI457fpSgZLiud8GJccpK7ik601v itVp8+HDX1p4EU2XlURkty9qH8TV6mRH8uGU0GlSpPxOtPwl8nfB9wbFNHOtfEnqW3HB w2M8ArC/6VxuMi9F8nGD/H2Btg24YRsKGul+Y= 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=4tbDvM/ARYtJL4bjfNEfZFzemfxnn/8UHyvUK82QuUM=; b=UpJXiVIBUW3aFeR4lqZp3dX0okigbB1ji1WzS84f68sqE3p/0yzPqfy/xT1zsXyT5D lrAIufNuTOHml03iS5y+yQ9OCeXy5YpZDR3wtX5hU7MuZk0e/kudHTGQxfhM9BkEbDID iWm1r9EntXm9qKJ2Cu7B6siIrkuADJ65yXQcPEV26feA0/z/PxqeX49tE3dFfExg8J0e NkL6hqr6BN5ynj735MH8sRwrqtGE2xhWDql89ulBZVLGkK5UulsB09pB0mj1tOJlG4d5 dmTx8shnUYZi76xCbAYLF1KhAFiEnEdjEtx+2iC17B4x4NTtAB493t1BddpUSCUR9TIA s2Og== X-Gm-Message-State: AJIora9XxvGzMH4kJR6xxnu2Se9sbFVZq6D132oy3fdu+Od7qBNGrz2t PWKCjeNQJQohdpgaavA3wxtp4w== X-Google-Smtp-Source: AGRyM1t45cSCpetLGdFrKHlD9QNPUQJhFXsNA3QG0U5zvDzOQU6/IqEIWCwtDQkASw6jQv+slMRg7w== X-Received: by 2002:a17:902:db02:b0:16c:5568:d740 with SMTP id m2-20020a170902db0200b0016c5568d740mr43110445plx.100.1658388108799; Thu, 21 Jul 2022 00:21:48 -0700 (PDT) Received: from rahul_yocto_ubuntu18.ibn.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id t8-20020a170902e84800b0016d2959cf37sm823611plg.279.2022.07.21.00.21.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 00:21:48 -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 v4 3/3] bnxt_en: implement callbacks for devlink selftests Date: Thu, 21 Jul 2022 12:51:21 +0530 Message-Id: <20220721072121.43648-4-vikas.gupta@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220721072121.43648-1-vikas.gupta@broadcom.com> References: <20220718062032.22426-1-vikas.gupta@broadcom.com> <20220721072121.43648-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;