Skip to content

Commit cbe9448

Browse files
dmarionflorincoras
authored andcommitted
qat: add Intel QuickAssist crypto driver
Native driver for the Intel QuickAssist 4xxx virtual function. The PF stays with the kernel qat_4xxx driver, which loads the firmware and assigns a service to each ring pair. The VF talks to it over the PF/VF mailbox: compatibility version, ring to service map (with CRC check), ring pair reset, init and shutdown. The device init adds the crypto queue group of the device generation, gen2-sym or gen4-sym, served by the qat-gen2-sym or qat-gen4-sym engine, and a queue to it per ring pair configured for symmetric crypto (2 per VF with the default sym;asym PF configuration). A thread may use several queues of the group, the enqueue nodes pick the one with the fewest requests in flight. There is an enqueue node per request type (cipher, AEAD, cipher with HMAC) and direction. Queue size limits are 128 to 4096 descriptors, power of 2, default 1024. Supported algorithms: AES-GCM 128/192/256 (AAD 8, 12, 20, 28) and ChaCha20-Poly1305 (AAD 0, 8, 12) as single pass AEAD on the UCS slice, AES-CBC and AES-CTR, and both chained with HMAC-SHA2-224/256/384/512. A device is refused when the PF reports capabilities without symmetric crypto, cipher, authentication, single pass AES-GCM or ChaCha20-Poly1305. Chained buffers are passed as scatter gather lists. The content descriptor of a key is built when the key is added, with the HMAC inner and outer state precomputed, and freed with vnet_dev_crypto_defer_free() when the key is removed. "show device" shows the ring pair state read from the hardware, "show device driver qat ring" decodes requests and responses on a ring and "show device driver qat session" the content descriptor of a crypto context. Type: feature Change-Id: Id3fc8b9e20efcb44253de3e70542a732de547a4d Signed-off-by: Damjan Marion <dmarion@0xa5.net>
1 parent 00ecab4 commit cbe9448

16 files changed

Lines changed: 3893 additions & 6 deletions

File tree

‎MAINTAINERS‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,11 @@ I: ice
483483
M: Damjan Marion <dmarion@0xa5.net>
484484
F: src/drivers/net/ice/
485485

486+
Intel QuickAssist (qat) crypto device driver
487+
I: qat
488+
M: Damjan Marion <dmarion@0xa5.net>
489+
F: src/drivers/crypto/qat/
490+
486491
Plugin - Dispatch Trace PCAP
487492
I: dispatch-trace
488493
M: Dave Barach <vpp@barachs.net>

‎src/drivers/crypto/CMakeLists.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright (c) 2026 Damjan Marion
23

34
add_subdirectory(octeon)
5+
add_subdirectory(qat)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright(c) 2026 Damjan Marion
3+
4+
add_vpp_driver(qat
5+
SOURCES
6+
algs.c
7+
cli.c
8+
deq.c
9+
enq.c
10+
format.c
11+
init.c
12+
pfvf.c
13+
queue.c
14+
session.c
15+
16+
MULTIARCH_SOURCES
17+
deq.c
18+
enq.c
19+
)

‎src/drivers/crypto/qat/README.rst‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
Intel QuickAssist crypto driver
2+
===============================
3+
4+
Overview
5+
--------
6+
7+
This driver provides native symmetric crypto support for Intel QuickAssist
8+
(QAT) virtual functions. The physical function (PF) stays with the kernel
9+
driver (e.g. ``qat_4xxx``), which loads the firmware and assigns a service to
10+
each ring pair. The driver uses the VF ring pairs assigned to symmetric
11+
crypto, one crypto queue each.
12+
13+
Device setup
14+
------------
15+
16+
Bind the VFs to ``vfio-pci`` and attach them to VPP, either with
17+
``device attach pci/<vf address> driver qat`` or in the startup config:
18+
19+
::
20+
21+
devices {
22+
dev pci/<vf address> { driver qat }
23+
}
24+
25+
Thread to queue assignment
26+
--------------------------
27+
28+
All VFs of the same QAT generation serve one crypto engine (e.g.
29+
``qat-gen4-sym``), and the queues of all of them are assigned to the VPP
30+
threads together. A device uses its first ``num-crypto-queues`` queues, by
31+
default as many as there are threads, up to the number of its symmetric
32+
crypto ring pairs.
33+
34+
Requests are completed by the thread which submitted them, so each queue
35+
serves exactly one thread. A thread may have several queues, also of
36+
different VFs; it submits each frame to its queue with the fewest requests in
37+
flight. A queue configured with a thread serves that thread, the other queues
38+
are spread round robin over all threads. A thread without a queue drops its
39+
requests and counts them as ``no-queue`` errors of the engine enqueue nodes.
40+
41+
The throughput limit is per PF, so a thread which should use more than one PF
42+
needs queues of VFs of different PFs. For example, with two VFs of different
43+
PFs and four threads:
44+
45+
::
46+
47+
devices {
48+
dev pci/<vf of pf 0> {
49+
driver qat
50+
crypto-queue 0 { threads 0 }
51+
crypto-queue 1 { threads 1 }
52+
}
53+
dev pci/<vf of pf 1> {
54+
driver qat
55+
crypto-queue 0 { threads 2 }
56+
crypto-queue 1 { threads 3 }
57+
}
58+
}
59+
60+
Without the ``crypto-queue`` settings the same queues are spread over the
61+
threads automatically. ``show device`` shows the threads of each queue.
62+
63+
PF service configuration
64+
------------------------
65+
66+
The services of a PF are set by the kernel driver through
67+
``/sys/bus/pci/devices/<pf address>/qat/cfg_services``. With the common
68+
default ``sym;asym``, the symmetric crypto throughput of the PF is about half
69+
of what the same PF reaches when configured for ``sym`` only. If the system
70+
doesn't need asymmetric crypto offload, configure the PF for ``sym``.
71+
72+
The throughput limit is per PF. Using more VFs of the same PF, or more ring
73+
pairs of a VF, doesn't increase it; to scale, use VFs of several PFs.
74+
75+
The services can only be changed while the PF is down and has no VFs. The VFs
76+
are recreated and need to be bound to ``vfio-pci`` again afterwards:
77+
78+
::
79+
80+
$ PF=/sys/bus/pci/devices/<pf address>
81+
$ echo 0 | sudo tee $PF/sriov_numvfs
82+
$ echo down | sudo tee $PF/qat/state
83+
$ echo sym | sudo tee $PF/qat/cfg_services
84+
$ echo up | sudo tee $PF/qat/state
85+
$ echo <number of vfs> | sudo tee $PF/sriov_numvfs
86+
87+
The setting doesn't survive a reboot; make it persistent in the configuration
88+
of whatever sets up the QAT devices at boot.

0 commit comments

Comments
 (0)