From patchwork Wed Sep 28 00:58:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 12991533 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 D1E03C07E9D for ; Wed, 28 Sep 2022 00:59:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232210AbiI1A7b (ORCPT ); Tue, 27 Sep 2022 20:59:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232166AbiI1A71 (ORCPT ); Tue, 27 Sep 2022 20:59:27 -0400 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB9C815EF8C for ; Tue, 27 Sep 2022 17:59:20 -0700 (PDT) Received: by mail-qt1-x82f.google.com with SMTP id ay9so7174434qtb.0 for ; Tue, 27 Sep 2022 17:59:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date; bh=dXgzPooGk4oqaL9KEhjoxsvVh87wIf1K1w/56HGIIHk=; b=DVYZ2e63G/JB8DdigcEE1LTLq198k10EwaUUfYZHGZwHZHxjNozWugjQb1QoNZqFdM fVPukfevJcTzDeoW5O3Mnsmu0F4KMnhUNgnjWNL37P5PfVqh+6UPTSr2oPqwf4d6W03i yaeTqD9o/KjmT4YLLv57PTpOF06I/HTlYFpr8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date; bh=dXgzPooGk4oqaL9KEhjoxsvVh87wIf1K1w/56HGIIHk=; b=5TINW28dw2ZmHlB/COHFzXXSQC9jJiPJqSEenD72RZfImFEhwDVugKHGsqleDvxgKr Ud6EEwRMzhOJmCOj1F4gOpqGZKICTKkphUQYEhaPUnf7Sv73ee9/Cytc55gr2u2/8gSc VDrBBfWP+EmdeiWVn7/efXRQS2udrelEz3Ir6SJaCQ1HeYbo1XnWD5OoHhFoMkCMgPHQ zjtiltzvWZMh/Qri96QDSDg4NOCFenXJwXhAOpOPLec5GRr3bsMOqk6QUSEky69hvYtG EdyX8KemdRn1D31k5Gz6URV+gbG8AV18v0uvGh12b7DvzFiueXlRFy6yrf13+gaHQMXi zDwA== X-Gm-Message-State: ACrzQf0SXZTg6C/ym+HkIUCCIL3abp75G+GxU9Hq+R72ScNnATOsU3J3 6sOBcnOdIjpkQyEvXn2Tbq/1qA== X-Google-Smtp-Source: AMsMyM7tjysYVrW7oRy+IbZ1GXmJML9hS+cyreT1uzKUI7XO2ZxTCTqt8J3Z97nhwo0w+1cvUC6Htg== X-Received: by 2002:a05:622a:174d:b0:35c:bf34:fc7 with SMTP id l13-20020a05622a174d00b0035cbf340fc7mr25146802qtk.13.1664326759109; Tue, 27 Sep 2022 17:59:19 -0700 (PDT) Received: from localhost.swdvt.lab.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id i11-20020a05620a248b00b006cbb8ca04f8sm2078668qkn.40.2022.09.27.17.59.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Sep 2022 17:59:18 -0700 (PDT) From: Michael Chan To: davem@davemloft.net Cc: netdev@vger.kernel.org, kuba@kernel.org, edumazet@google.com, pabeni@redhat.com, gospo@broadcom.com, vikas.gupta@broadcom.com Subject: [PATCH net-next 5/6] bnxt_en: add .get_module_eeprom_by_page() support Date: Tue, 27 Sep 2022 20:58:43 -0400 Message-Id: <1664326724-1415-6-git-send-email-michael.chan@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1664326724-1415-1-git-send-email-michael.chan@broadcom.com> References: <1664326724-1415-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 support for .get_module_eeprom_by_page() callback which enables CMIS for pluggable modules. In the case that bank select is not enabled by f/w then all the requests fallback to .get_module_eeprom() callback. Reviewed-by: Pavan Chebbi Signed-off-by: Vikas Gupta Signed-off-by: Michael Chan --- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 9 +++ .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 55 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.h b/drivers/net/ethernet/broadcom/bnxt/bnxt.h index 0209f7caf490..03b1a0301a46 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.h +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.h @@ -2207,6 +2207,15 @@ struct bnxt { #define SFF_MODULE_ID_QSFP 0xc #define SFF_MODULE_ID_QSFP_PLUS 0xd #define SFF_MODULE_ID_QSFP28 0x11 +#define SFF_MODULE_ID_QSFP_DD 0x18 +#define SFF_MODULE_ID_DSFP 0x1b +#define SFF_MODULE_ID_QSFP_PLUS_CMIS 0x1e + +#define BNXT_SFF_MODULE_BANK_SUPPORTED(module_id) \ + ((module_id) == SFF_MODULE_ID_QSFP_DD || \ + (module_id) == SFF_MODULE_ID_QSFP28 || \ + (module_id) == SFF_MODULE_ID_QSFP_PLUS_CMIS) + #define SFF8636_FLATMEM_OFFSET 0x2 #define SFF8636_FLATMEM_MASK 0x4 #define SFF8636_OPT_PAGES_OFFSET 0xc3 diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c index 379afa670494..2b18af95aacb 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c @@ -3363,6 +3363,60 @@ static int bnxt_get_module_eeprom(struct net_device *dev, return 0; } +static int bnxt_get_module_eeprom_by_page(struct net_device *dev, + const struct ethtool_module_eeprom *page_data, + struct netlink_ext_ack *extack) +{ + struct bnxt *bp = netdev_priv(dev); + u16 length = page_data->length; + u8 *data = page_data->data; + u8 page = page_data->page; + u8 bank = page_data->bank; + u16 bytes_copied = 0; + u8 module_id; + int rc; + + /* Return -EOPNOTSUPP to fallback on .get_module_eeprom */ + if (!(bp->phy_flags & BNXT_PHY_FL_BANK_SEL)) + return -EOPNOTSUPP; + + rc = bnxt_module_status_check(bp); + if (rc) + return rc; + + rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0, 0, false, + 0, 1, &module_id); + if (rc) + return rc; + + if (!BNXT_SFF_MODULE_BANK_SUPPORTED(module_id)) + return -EOPNOTSUPP; + + while (length > 0) { + u16 chunk = ETH_MODULE_EEPROM_PAGE_LEN; + int rc; + + /* Do not access more than required */ + if (length < ETH_MODULE_EEPROM_PAGE_LEN) + chunk = length; + + rc = bnxt_read_sfp_module_eeprom_info(bp, + I2C_DEV_ADDR_A0, + page, bank, + true, page_data->offset, + chunk, data); + if (rc) + return rc; + + data += chunk; + length -= chunk; + bytes_copied += chunk; + page++; + } + + return bytes_copied; +} + static int bnxt_nway_reset(struct net_device *dev) { int rc = 0; @@ -4172,6 +4226,7 @@ const struct ethtool_ops bnxt_ethtool_ops = { .set_eee = bnxt_set_eee, .get_module_info = bnxt_get_module_info, .get_module_eeprom = bnxt_get_module_eeprom, + .get_module_eeprom_by_page = bnxt_get_module_eeprom_by_page, .nway_reset = bnxt_nway_reset, .set_phys_id = bnxt_set_phys_id, .self_test = bnxt_self_test,