From: Stan Iliev <stani@google.com>
To: Tony Nguyen <anthony.l.nguyen@intel.com>,
Przemek Kitszel <przemyslaw.kitszel@intel.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
intel-wired-lan@lists.osuosl.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
David Decotigny <decot@google.com>,
Madhu Chittim <madhu.chittim@intel.com>,
Emil Tantilov <emil.s.tantilov@intel.com>,
Sridhar Samudrala <sridhar.samudrala@intel.com>,
Brian Vazquez <brianvv@google.com>, Li Li <boolli@google.com>,
Alexander Lobakin <aleksander.lobakin@intel.com>,
Daniel Zahka <daniel.zahka@gmail.com>,
Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-hardening@vger.kernel.org
Subject: [PATCH iwl-next 05/15] idpf: psp: add support for crypto capabilities
Date: Tue, 17 Nov 2026 14:55:11 +0000 [thread overview]
Message-ID: <20261117145522.1910636-6-stani@google.com> (raw)
In-Reply-To: <20261117145522.1910636-1-stani@google.com>
Add support for negotiating the crypto offload capabilities:
- Introduce VIRTCHNL2_OP_CRYPTO_GET_CAPS (564),
enum virtchnl2_cap_crypto and struct virtchnl2_crypto_get_caps.
- Implement idpf_send_get_crypto_caps() in the new
idpf_psp_virtchnl.c and call it from idpf_psp_negotiate_caps() in
idpf_psp_init(). PSP stays disabled, without failing probe, unless
PSP crypto offload and SADB entries are granted with a 21 or 26 bit
SA index width, and the SA indexes of all the SADB entries fit in
the width.
- Store the SADB size and the SA index width of the adapter in
adapter->psp.sadb_entries and adapter->psp.saidx_width.
Signed-off-by: Stan Iliev <stani@google.com>
---
drivers/net/ethernet/intel/idpf/Makefile | 2 +-
drivers/net/ethernet/intel/idpf/idpf_psp.c | 61 ++++++++++++++++
.../net/ethernet/intel/idpf/idpf_psp_def.h | 10 +++
.../ethernet/intel/idpf/idpf_psp_virtchnl.c | 71 +++++++++++++++++++
.../ethernet/intel/idpf/idpf_psp_virtchnl.h | 13 ++++
include/linux/net/intel/virtchnl2.h | 26 +++++++
6 files changed, 182 insertions(+), 1 deletion(-)
create mode 100644 drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c
create mode 100644 drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.h
diff --git a/drivers/net/ethernet/intel/idpf/Makefile b/drivers/net/ethernet/intel/idpf/Makefile
index 3162ea913417..8db28c228e04 100644
--- a/drivers/net/ethernet/intel/idpf/Makefile
+++ b/drivers/net/ethernet/intel/idpf/Makefile
@@ -21,7 +21,7 @@ idpf-$(CONFIG_IDPF_SINGLEQ) += idpf_singleq_txrx.o
idpf-$(CONFIG_PTP_1588_CLOCK) += idpf_ptp.o
idpf-$(CONFIG_PTP_1588_CLOCK) += idpf_virtchnl_ptp.o
-idpf-$(CONFIG_INET_PSP) += idpf_psp.o
+idpf-$(CONFIG_INET_PSP) += idpf_psp.o idpf_psp_virtchnl.o
idpf-y += xdp.o
idpf-y += xsk.o
diff --git a/drivers/net/ethernet/intel/idpf/idpf_psp.c b/drivers/net/ethernet/intel/idpf/idpf_psp.c
index c1297ec59163..c4f46f7337ef 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_psp.c
+++ b/drivers/net/ethernet/intel/idpf/idpf_psp.c
@@ -3,6 +3,59 @@
#include <net/psp.h>
#include "idpf_psp.h"
+#include "idpf_psp_virtchnl.h"
+
+/**
+ * idpf_psp_negotiate_caps - Negotiate the crypto and PSP capabilities
+ * @adapter: private data struct
+ *
+ * Query the crypto and PSP capabilities granted by the CP, check that they
+ * cover what the driver implements and apply the negotiated values. Must only
+ * be called if VIRTCHNL2_CAP_CRYPTO was negotiated.
+ *
+ * Return: 0 if PSP offload can be used, negative error code otherwise.
+ */
+static int idpf_psp_negotiate_caps(struct idpf_adapter *adapter)
+{
+ struct virtchnl2_crypto_get_caps crypto_caps = { };
+ struct device *dev = &adapter->pdev->dev;
+ u32 sadb_entries;
+ int err;
+
+ err = idpf_send_get_crypto_caps(adapter, &crypto_caps);
+ if (err)
+ return err;
+
+ if (!(le32_to_cpu(crypto_caps.crypto_caps) & VIRTCHNL2_CAP_CRYPTO_PSP)) {
+ dev_notice(dev, "PSP crypto offload not granted by CP\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (crypto_caps.saidx_width != IDPF_PSP_SAIDX_WIDTH_21 &&
+ crypto_caps.saidx_width != IDPF_PSP_SAIDX_WIDTH_26) {
+ dev_err(dev, "Unsupported PSP SA index width %u\n",
+ crypto_caps.saidx_width);
+ return -EOPNOTSUPP;
+ }
+
+ sadb_entries = le32_to_cpu(crypto_caps.num_sadb_entries);
+ if (!sadb_entries) {
+ dev_notice(dev, "No PSP SADB entries granted by CP\n");
+ return -EOPNOTSUPP;
+ }
+
+ /* The SA indexes of all the SADB entries must fit in the width */
+ if (sadb_entries > BIT(crypto_caps.saidx_width)) {
+ dev_err(dev, "%u PSP SADB entries don't fit in %u bit SA indexes\n",
+ sadb_entries, crypto_caps.saidx_width);
+ return -EOPNOTSUPP;
+ }
+
+ adapter->psp.sadb_entries = sadb_entries;
+ adapter->psp.saidx_width = crypto_caps.saidx_width;
+
+ return 0;
+}
/**
* idpf_psp_init - Initialize PSP offload
@@ -18,6 +71,7 @@ void idpf_psp_init(struct idpf_adapter *adapter)
{
struct idpf_adapter_psp *psp = &adapter->psp;
struct device *dev = &adapter->pdev->dev;
+ int err;
WRITE_ONCE(psp->enabled, false);
@@ -26,6 +80,13 @@ void idpf_psp_init(struct idpf_adapter *adapter)
return;
}
+ err = idpf_psp_negotiate_caps(adapter);
+ if (err) {
+ dev_warn(dev, "PSP disabled, capability negotiation failed: %d\n",
+ err);
+ return;
+ }
+
WRITE_ONCE(psp->enabled, true);
}
diff --git a/drivers/net/ethernet/intel/idpf/idpf_psp_def.h b/drivers/net/ethernet/intel/idpf/idpf_psp_def.h
index 2edb114784c1..3a9e40284106 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_psp_def.h
+++ b/drivers/net/ethernet/intel/idpf/idpf_psp_def.h
@@ -5,15 +5,25 @@
#include <net/psp.h>
+/* SA index widths supported by the driver, negotiated per adapter with
+ * VIRTCHNL2_OP_CRYPTO_GET_CAPS, see idpf_psp_negotiate_caps().
+ */
+#define IDPF_PSP_SAIDX_WIDTH_21 21
+#define IDPF_PSP_SAIDX_WIDTH_26 26
+
/**
* struct idpf_adapter_psp - PSP offload state of an adapter
* @enabled: PSP was negotiated with the CP in the last core init, see
* idpf_is_psp_ena()
+ * @sadb_entries: SADB size granted by VIRTCHNL2_OP_CRYPTO_GET_CAPS
+ * @saidx_width: SA index width granted by VIRTCHNL2_OP_CRYPTO_GET_CAPS
* @psp_dev: the PSP device, see idpf_psp_register()
* @caps: capabilities of @psp_dev
*/
struct idpf_adapter_psp {
bool enabled;
+ u32 sadb_entries;
+ u8 saidx_width;
struct psp_dev *psp_dev;
struct psp_dev_caps caps;
};
diff --git a/drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c
new file mode 100644
index 000000000000..65f7a9f63f90
--- /dev/null
+++ b/drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.c
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include "idpf_psp_virtchnl.h"
+#include "idpf_virtchnl.h"
+
+/**
+ * idpf_print_crypto_caps - Print values inside virtchnl2_crypto_get_caps
+ * @adapter: Driver specific private structure
+ * @caps: Pointer to virtchnl2_crypto_get_caps structure
+ */
+static void idpf_print_crypto_caps(struct idpf_adapter *adapter,
+ const struct virtchnl2_crypto_get_caps *caps)
+{
+ u32 num_sadb_entries = le32_to_cpu(caps->num_sadb_entries);
+ u32 crypto_caps = le32_to_cpu(caps->crypto_caps);
+
+ dev_dbg(&adapter->pdev->dev,
+ "virtchnl2_crypto_get_caps: crypto_caps=0x%08x (PSP=%u), num_sadb_entries=%u, saidx_width=%u\n",
+ crypto_caps, !!(crypto_caps & VIRTCHNL2_CAP_CRYPTO_PSP),
+ num_sadb_entries, caps->saidx_width);
+}
+
+/**
+ * idpf_send_get_crypto_caps - Send VIRTCHNL2_OP_CRYPTO_GET_CAPS request to CP
+ * @adapter: Driver specific private structure
+ * @caps: Output buffer for virtchnl2_crypto_get_caps
+ *
+ * Request the PSP crypto offload. Must only be sent if VIRTCHNL2_CAP_CRYPTO
+ * was granted.
+ *
+ * Return: 0 on success, negative on failure.
+ */
+int idpf_send_get_crypto_caps(struct idpf_adapter *adapter,
+ struct virtchnl2_crypto_get_caps *caps)
+{
+ struct libie_ctlq_xn_send_params xn_params = {
+ .chnl_opcode = VIRTCHNL2_OP_CRYPTO_GET_CAPS,
+ .timeout_ms = IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC,
+ };
+ struct virtchnl2_crypto_get_caps *send_caps;
+ int err;
+
+ /* Too large to be sent from the stack */
+ send_caps = kzalloc_obj(*send_caps);
+ if (!send_caps)
+ return -ENOMEM;
+
+ send_caps->crypto_caps = cpu_to_le32(VIRTCHNL2_CAP_CRYPTO_PSP);
+
+ err = idpf_send_mb_msg_kfree(adapter, &xn_params, send_caps,
+ sizeof(*send_caps));
+ if (err) {
+ dev_err(&adapter->pdev->dev, "Failed to get crypto caps: %d\n",
+ err);
+ return err;
+ }
+
+ if (xn_params.recv_mem.iov_len < sizeof(*caps)) {
+ dev_err(&adapter->pdev->dev, "Invalid crypto caps reply size: %zu\n",
+ xn_params.recv_mem.iov_len);
+ err = -EIO;
+ goto release_rx;
+ }
+
+ memcpy(caps, xn_params.recv_mem.iov_base, sizeof(*caps));
+ idpf_print_crypto_caps(adapter, caps);
+
+release_rx:
+ libie_ctlq_release_rx_buf(&xn_params.recv_mem);
+ return err;
+}
diff --git a/drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.h b/drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.h
new file mode 100644
index 000000000000..cf82ac9182ef
--- /dev/null
+++ b/drivers/net/ethernet/intel/idpf/idpf_psp_virtchnl.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef _IDPF_PSP_VIRTCHNL_H_
+#define _IDPF_PSP_VIRTCHNL_H_
+
+#include <linux/net/intel/libie/controlq.h>
+
+#include "idpf_psp.h"
+
+int idpf_send_get_crypto_caps(struct idpf_adapter *adapter,
+ struct virtchnl2_crypto_get_caps *caps);
+
+#endif /* !_IDPF_PSP_VIRTCHNL_H_ */
diff --git a/include/linux/net/intel/virtchnl2.h b/include/linux/net/intel/virtchnl2.h
index ec1a742b6557..59c379afcb71 100644
--- a/include/linux/net/intel/virtchnl2.h
+++ b/include/linux/net/intel/virtchnl2.h
@@ -84,6 +84,8 @@ enum virtchnl2_op {
VIRTCHNL2_OP_ADD_FLOW_RULE = 551,
VIRTCHNL2_OP_GET_FLOW_RULE = 552,
VIRTCHNL2_OP_DEL_FLOW_RULE = 553,
+ /* Crypto/PSP opcodes */
+ VIRTCHNL2_OP_CRYPTO_GET_CAPS = 564,
};
/**
@@ -1817,4 +1819,28 @@ struct virtchnl2_flow_rule_add_del {
};
VIRTCHNL2_CHECK_STRUCT_LEN(8, virtchnl2_flow_rule_add_del);
+/* Generic crypto offload types */
+enum virtchnl2_cap_crypto {
+ VIRTCHNL2_CAP_CRYPTO_PSP = BIT(0),
+};
+
+/**
+ * struct virtchnl2_crypto_get_caps - Crypto global capabilities
+ * @crypto_caps: See enum virtchnl2_cap_crypto
+ * @num_sadb_entries: Number of SADB entries of the function, not shared with
+ * the other functions of the device
+ * @saidx_width: SA index width in bits
+ * @padding: Padding to 256 bytes
+ *
+ * Request and response of VIRTCHNL2_OP_CRYPTO_GET_CAPS. On input @crypto_caps
+ * holds the requested capabilities, on output the granted ones.
+ */
+struct virtchnl2_crypto_get_caps {
+ __le32 crypto_caps;
+ __le32 num_sadb_entries;
+ u8 saidx_width;
+ u8 padding[247];
+};
+VIRTCHNL2_CHECK_STRUCT_LEN(256, virtchnl2_crypto_get_caps);
+
#endif /* _VIRTCHNL_2_H_ */
--
2.56.0.679.gc527c65306-goog
next prev parent reply other threads:[~2026-11-17 14:55 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 14:55 [PATCH iwl-next 00/15] idpf: add PSP offload support, part 1 Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 01/15] libie: wipe copied small send buffers on release Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 02/15] idpf: wipe mailbox " Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 03/15] idpf: make the mailbox workqueue visible in sysfs Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 04/15] idpf: psp: add psp offload initialization Stan Iliev
2026-11-17 14:55 ` Stan Iliev [this message]
2026-11-17 14:55 ` [PATCH iwl-next 06/15] idpf: psp: add support for psp capabilities Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 07/15] idpf: psp: add support for fips compliance status Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 08/15] idpf: psp: add support for psp rx key allocation Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 09/15] idpf: psp: add support for psp key rotation Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 10/15] idpf: psp: add support for psp statistics Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 11/15] idpf: psp: add psp tx key state Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 12/15] idpf: psp: add support for psp tx key deletion Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 13/15] idpf: psp: add psp work and tx key insertion completion Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 14/15] idpf: psp: add support for psp tx key insertion Stan Iliev
2026-11-17 14:55 ` [PATCH iwl-next 15/15] idpf: psp: add psp tx key registration Stan Iliev
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=20261117145522.1910636-6-stani@google.com \
--to=stani@google.com \
--cc=aleksander.lobakin@intel.com \
--cc=andrew+netdev@lunn.ch \
--cc=anthony.l.nguyen@intel.com \
--cc=boolli@google.com \
--cc=brianvv@google.com \
--cc=daniel.zahka@gmail.com \
--cc=davem@davemloft.net \
--cc=decot@google.com \
--cc=edumazet@kernel.org \
--cc=emil.s.tantilov@intel.com \
--cc=gustavoars@kernel.org \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=kees@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=madhu.chittim@intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=przemyslaw.kitszel@intel.com \
--cc=sridhar.samudrala@intel.com \
--cc=willemdebruijn.kernel@gmail.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
all inboxes | Powered by JetHome®