From patchwork Fri Oct 20 21:27:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 13431198 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9EA12FE09 for ; Fri, 20 Oct 2023 21:28:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="Nb8Eu2HC" Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67F11D68 for ; Fri, 20 Oct 2023 14:28:16 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-5a9bf4fbd3fso934713a12.1 for ; Fri, 20 Oct 2023 14:28:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1697837296; x=1698442096; darn=vger.kernel.org; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=TjTk5x/BMqIltJXEN+AOADHZlZUg3zOJJYeLJ4J4OpY=; b=Nb8Eu2HChxrA6wOeJ7I94Oes8CxFOGOnvvt8xfkYA+gx6cfez10QDY74oxT4v3KTdN 748z3PfV9I5W7//4Zv58ZRsUpJcgXJaldSegPSHXTv3kn3BlQpxMDV7zCUJ2IykgG4+m 5WuSZt9F3XuzWHiETX/oz/fRMM2s6IHWY/lkk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697837296; x=1698442096; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TjTk5x/BMqIltJXEN+AOADHZlZUg3zOJJYeLJ4J4OpY=; b=aMCjH8KkkXPE22F+RQJHjiEaEUYAlatfbYUTDxF57qIbknlLo7fbtEYPQSKdsOkntp 3HcxsUbagmgJQusuf1qlCpkUd9p79BH+8KwMq0V3GZE5Qk4vUHmL8ItDK6xsGUJ8Uv+f lgsR7omzMbYy8+J5nAH2EMm7CFJxdRwuk3VhT9zRbZarvsRG2DREl9TrKYdoVaENFvbe icwEq1/Dj/VBlVrvijJ9bMyHiwPWgVEQrZZ8n7tzKt9wx1xk+zqgsDATxPZuK1lPRb+3 iSHRKbMyYRvGagijw2o8rSU7C4z9sIjDrPTWfyZbzTw/0x5Aoq9wOASm0SUAp2t94hVQ akTg== X-Gm-Message-State: AOJu0YxEe+kVm/23c53y1ZM3PlCW0IdccgMus1JexRui5rXCYHCG8IgX q/3yaDy9ZzTBcUuDki/jOCnwyA== X-Google-Smtp-Source: AGHT+IHEk8F2bAy2kWj8gYpd7i6aoc0i/OUmIKASpDsi/LJan3q1UUaC/PmnCieP8Tm2DKPnOEN6Mg== X-Received: by 2002:a17:90b:35c4:b0:27c:f48e:e245 with SMTP id nb4-20020a17090b35c400b0027cf48ee245mr3094844pjb.24.1697837295463; Fri, 20 Oct 2023 14:28:15 -0700 (PDT) Received: from lvnvda5233.lvn.broadcom.net ([192.19.161.250]) by smtp.gmail.com with ESMTPSA id j13-20020a17090a7e8d00b0026d4100e0e8sm1843348pjl.10.2023.10.20.14.28.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Oct 2023 14:28:15 -0700 (PDT) From: Michael Chan To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, gospo@broadcom.com, kalesh-anakkur.purayil@broadcom.com Subject: [PATCH net-next 5/8] bnxt_en: refactor speed independent ethtool modes Date: Fri, 20 Oct 2023 14:27:54 -0700 Message-Id: <20231020212757.173551-6-michael.chan@broadcom.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20231020212757.173551-1-michael.chan@broadcom.com> References: <20231020212757.173551-1-michael.chan@broadcom.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Edwin Peer A future patch in this series will change the algorithm used to determine ethtool speed and media modes. Extract the handling of the unrelated pause, autoneg modes into an independent function. Also separate FEC handling out of bnxt_fw_to_ethtool_*_spds(). No functional change. Signed-off-by: Edwin Peer Signed-off-by: Michael Chan --- .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 78 ++++++++++--------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c index 19b0bff9c590..98a767becd0d 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c @@ -1730,7 +1730,7 @@ bnxt_get_link_mode(struct bnxt_link_info *link_info) return link_mode; } -#define BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, name)\ +#define BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, lk_ksettings, name) \ { \ if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100MB) \ ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ @@ -1753,16 +1753,6 @@ bnxt_get_link_mode(struct bnxt_link_info *link_info) if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100GB) \ ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ 100000baseCR4_Full);\ - if ((fw_pause) & BNXT_LINK_PAUSE_RX) { \ - ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ - Pause); \ - if (!((fw_pause) & BNXT_LINK_PAUSE_TX)) \ - ethtool_link_ksettings_add_link_mode( \ - lk_ksettings, name, Asym_Pause);\ - } else if ((fw_pause) & BNXT_LINK_PAUSE_TX) { \ - ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\ - Asym_Pause); \ - } \ } #define BNXT_ETHTOOL_TO_FW_SPDS(fw_speeds, lk_ksettings, name) \ @@ -1820,6 +1810,39 @@ bnxt_get_link_mode(struct bnxt_link_info *link_info) (fw_speeds) |= BNXT_LINK_PAM4_SPEED_MSK_200GB; \ } +static void bnxt_get_ethtool_modes(struct bnxt_link_info *link_info, + struct ethtool_link_ksettings *lk_ksettings) +{ + struct bnxt *bp = container_of(link_info, struct bnxt, link_info); + + if (!(bp->phy_flags & BNXT_PHY_FL_NO_PAUSE)) { + ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, + Pause); + ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, + Asym_Pause); + } + + if (link_info->support_auto_speeds || link_info->support_pam4_auto_speeds) + ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, + Autoneg); + + if (~link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) + return; + + if (link_info->auto_pause_setting & BNXT_LINK_PAUSE_RX) + ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising, + Pause); + if (hweight8(link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH) == 1) + ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising, + Asym_Pause); + if (link_info->lp_pause & BNXT_LINK_PAUSE_RX) + ethtool_link_ksettings_add_link_mode(lk_ksettings, + lp_advertising, Pause); + if (hweight8(link_info->lp_pause & BNXT_LINK_PAUSE_BOTH) == 1) + ethtool_link_ksettings_add_link_mode(lk_ksettings, + lp_advertising, Asym_Pause); +} + static void bnxt_fw_to_ethtool_advertised_fec(struct bnxt_link_info *link_info, struct ethtool_link_ksettings *lk_ksettings) { @@ -1845,28 +1868,18 @@ static void bnxt_fw_to_ethtool_advertised_spds(struct bnxt_link_info *link_info, struct ethtool_link_ksettings *lk_ksettings) { u16 fw_speeds = link_info->advertising; - u8 fw_pause = 0; - if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) - fw_pause = link_info->auto_pause_setting; - - BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, advertising); + BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, lk_ksettings, advertising); fw_speeds = link_info->advertising_pam4; BNXT_FW_TO_ETHTOOL_PAM4_SPDS(fw_speeds, lk_ksettings, advertising); - bnxt_fw_to_ethtool_advertised_fec(link_info, lk_ksettings); } static void bnxt_fw_to_ethtool_lp_adv(struct bnxt_link_info *link_info, struct ethtool_link_ksettings *lk_ksettings) { u16 fw_speeds = link_info->lp_auto_link_speeds; - u8 fw_pause = 0; - - if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) - fw_pause = link_info->lp_pause; - BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, - lp_advertising); + BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, lk_ksettings, lp_advertising); fw_speeds = link_info->lp_auto_pam4_link_speeds; BNXT_FW_TO_ETHTOOL_PAM4_SPDS(fw_speeds, lk_ksettings, lp_advertising); } @@ -1895,25 +1908,11 @@ static void bnxt_fw_to_ethtool_support_fec(struct bnxt_link_info *link_info, static void bnxt_fw_to_ethtool_support_spds(struct bnxt_link_info *link_info, struct ethtool_link_ksettings *lk_ksettings) { - struct bnxt *bp = container_of(link_info, struct bnxt, link_info); u16 fw_speeds = link_info->support_speeds; - BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, 0, lk_ksettings, supported); + BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, lk_ksettings, supported); fw_speeds = link_info->support_pam4_speeds; BNXT_FW_TO_ETHTOOL_PAM4_SPDS(fw_speeds, lk_ksettings, supported); - - if (!(bp->phy_flags & BNXT_PHY_FL_NO_PAUSE)) { - ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, - Pause); - ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, - Asym_Pause); - } - - if (link_info->support_auto_speeds || - link_info->support_pam4_auto_speeds) - ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, - Autoneg); - bnxt_fw_to_ethtool_support_fec(link_info, lk_ksettings); } u32 bnxt_fw_to_ethtool_speed(u16 fw_link_speed) @@ -1977,7 +1976,9 @@ static int bnxt_get_link_ksettings(struct net_device *dev, link_info = &bp->link_info; mutex_lock(&bp->link_lock); + bnxt_get_ethtool_modes(link_info, lk_ksettings); bnxt_fw_to_ethtool_support_spds(link_info, lk_ksettings); + bnxt_fw_to_ethtool_support_fec(link_info, lk_ksettings); link_mode = bnxt_get_link_mode(link_info); if (link_mode != BNXT_LINK_MODE_UNKNOWN) ethtool_params_from_link_mode(lk_ksettings, link_mode); @@ -1986,6 +1987,7 @@ static int bnxt_get_link_ksettings(struct net_device *dev, if (link_info->autoneg) { bnxt_fw_to_ethtool_advertised_spds(link_info, lk_ksettings); + bnxt_fw_to_ethtool_advertised_fec(link_info, lk_ksettings); ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising, Autoneg); base->autoneg = AUTONEG_ENABLE;