Netdev List
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: michael.chan@broadcom.com
Cc: Jakub Kicinski <kuba@kernel.org>,
	davem@davemloft.net, netdev@vger.kernel.org, edumazet@google.com,
	pabeni@redhat.com, andrew+netdev@lunn.ch,
	pavan.chebbi@broadcom.com, andrew.gospodarek@broadcom.com
Subject: Re: [PATCH net-next v2 07/15] bnxt_en: Allocate crypto structure and backing store
Date: Fri, 15 May 2026 18:10:13 -0700	[thread overview]
Message-ID: <20260516011013.1857516-1-kuba@kernel.org> (raw)
In-Reply-To: <20260512212105.3488258-8-michael.chan@broadcom.com>

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
bnxt_en: Allocate crypto structure and backing store

If the chip and firmware support crypto (TLS) offload, allocate a
bp->crypto_info software structure and backing store to support the RX
and TX contexts.  Each offloaded TLS connection requires a backing store
context for each direction.

> diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_crypto.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_crypto.c
> new file mode 100644
> index 000000000000..a5fee08eaa67
> --- /dev/null
> +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_crypto.c

[ ... ]

> +static u32 bnxt_get_max_crypto_key_ctx(struct bnxt *bp, int key_type)
> +{
> +	u32 fw_maj = BNXT_FW_MAJ(bp);
> +
> +	if (key_type == BNXT_TX_CRYPTO_KEY_TYPE)
> +		return (fw_maj < 233) ? BNXT_MAX_TX_CRYPTO_KEYS_PRE_233FW :
> +		       BNXT_MAX_TX_CRYPTO_KEYS;
> +
> +	return (fw_maj < 233) ? BNXT_MAX_RX_CRYPTO_KEYS_PRE_233FW :
> +	       BNXT_MAX_RX_CRYPTO_KEYS;
> +}

[ ... ]

> +void bnxt_alloc_crypto_info(struct bnxt *bp,
> +			    struct hwrm_func_qcaps_output *resp)
> +{
> +	u16 max_keys = le16_to_cpu(resp->max_key_ctxs_alloc);
> +	struct bnxt_crypto_info *crypto = bp->crypto_info;
> +
> +	if (BNXT_VF(bp))
> +		return;
> +	if (!crypto) {
> +		struct bnxt_kctx *kctx;
> +		int i;
> +
> +		crypto = kzalloc_obj(*crypto);
> +		if (!crypto) {
> +			netdev_warn(bp->dev,
> +				    "Unable to allocate crypto info\n");
> +			return;
> +		}
> +		for (i = 0; i < BNXT_MAX_CRYPTO_KEY_TYPE; i++) {
> +			kctx = &crypto->kctx[i];
> +			kctx->type = i;
> +			kctx->max_ctx = bnxt_get_max_crypto_key_ctx(bp, i);
> +		}
> +		bp->crypto_info = crypto;
> +	}
> +	crypto->max_key_ctxs_alloc = max_keys;
> +}

[Medium]
Should the kctx[].max_ctx values be refreshed on every call, rather than
only when bp->crypto_info is first allocated?

bnxt_alloc_crypto_info() can be invoked multiple times for a given bp.
__bnxt_hwrm_func_qcaps() is the caller, and it runs from paths such as
bnxt_resume(), bnxt_restore_pf_fw_resources(), bnxt_io_resume(), and
during SR-IOV enable, in addition to initial probe.

On the second and later calls, the crypto pointer is non-NULL, so the
loop that calls bnxt_get_max_crypto_key_ctx(bp, i) is skipped and only
crypto->max_key_ctxs_alloc is refreshed.

If BNXT_FW_MAJ(bp) crosses the 233 boundary between two qcaps queries on
the same driver instance (for example after a firmware update applied
across suspend/resume, or after a firmware reset that re-reads
fw_ver_code), the cached kctx[].max_ctx retains the pre-233 value of
65535 instead of being recomputed to 204800.

bnxt_backing_store_cfg_v2() then sizes the TCK/RCK backing stores from
those cached values:

	if (crypto) {
		ctxm = &ctx->ctx_arr[BNXT_CTX_TCK];
		rc = bnxt_setup_ctxm_pg_tbls(bp, ctxm,
					     BNXT_TCK(crypto).max_ctx, 1);
		...
		ctxm = &ctx->ctx_arr[BNXT_CTX_RCK];
		rc = bnxt_setup_ctxm_pg_tbls(bp, ctxm,
					     BNXT_RCK(crypto).max_ctx, 1);

and bnxt_setup_ctxm_pg_tbls() applies clamp_t(u32, entries,
ctxm->min_entries, ctxm->max_entries), so the stale 65535 caps the
allocation even if firmware now advertises a larger ctxm->max_entries.

Would moving the kctx[] initialization out of the if (!crypto) block, or
running it unconditionally, be a better fit for the function name and
kerneldoc which describe it as 'Allocate and initialize crypto offload
context' without noting the once-only initialization?

  reply	other threads:[~2026-05-16  1:10 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-12 21:20 [PATCH net-next v2 00/15] bnxt_en: Add kTLS TX offload support Michael Chan
2026-05-12 21:20 ` [PATCH net-next v2 01/15] bnxt_en: Add Midpath channel information Michael Chan
2026-05-12 21:20 ` [PATCH net-next v2 02/15] bnxt_en: Account for the MPC TX and CP rings Michael Chan
2026-05-12 21:20 ` [PATCH net-next v2 03/15] bnxt_en: Set default MPC ring count Michael Chan
2026-05-16  1:10   ` Jakub Kicinski
2026-05-12 21:20 ` [PATCH net-next v2 04/15] bnxt_en: Rename xdp_tx_lock to tx_lock Michael Chan
2026-05-12 21:20 ` [PATCH net-next v2 05/15] bnxt_en: Allocate and free MPC software structures Michael Chan
2026-05-12 21:20 ` [PATCH net-next v2 06/15] bnxt_en: Allocate and free MPC channels from firmware Michael Chan
2026-05-12 21:20 ` [PATCH net-next v2 07/15] bnxt_en: Allocate crypto structure and backing store Michael Chan
2026-05-16  1:10   ` Jakub Kicinski [this message]
2026-05-12 21:20 ` [PATCH net-next v2 08/15] bnxt_en: Reserve crypto RX and TX key contexts on a PF Michael Chan
2026-05-16  1:10   ` Jakub Kicinski
2026-05-12 21:20 ` [PATCH net-next v2 09/15] bnxt_en: Add infrastructure for crypto key context IDs Michael Chan
2026-05-16  1:10   ` Jakub Kicinski
2026-05-12 21:21 ` [PATCH net-next v2 10/15] bnxt_en: Add MPC transmit and completion functions Michael Chan
2026-05-16  1:10   ` Jakub Kicinski
2026-05-12 21:21 ` [PATCH net-next v2 11/15] bnxt_en: Add crypto MPC transmit/completion infrastructure Michael Chan
2026-05-16  1:10   ` Jakub Kicinski
2026-05-12 21:21 ` [PATCH net-next v2 12/15] bnxt_en: Support kTLS TX offload by implementing .tls_dev_add/del() Michael Chan
2026-05-16  1:10   ` Jakub Kicinski
2026-05-12 21:21 ` [PATCH net-next v2 13/15] bnxt_en: Implement kTLS TX normal path Michael Chan
2026-05-16  1:10   ` Jakub Kicinski
2026-05-12 21:21 ` [PATCH net-next v2 14/15] bnxt_en: Add support for inline transmit BDs Michael Chan
2026-05-12 21:21 ` [PATCH net-next v2 15/15] bnxt_en: Add kTLS retransmission support Michael Chan
2026-05-16  1:10   ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260516011013.1857516-1-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrew.gospodarek@broadcom.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=michael.chan@broadcom.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pavan.chebbi@broadcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox