drivers/crypto/virtio/virtio_crypto_core.c
Source file repositories/reference/linux-study-clean/drivers/crypto/virtio/virtio_crypto_core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/crypto/virtio/virtio_crypto_core.c- Extension
.c- Size
- 14579 bytes
- Lines
- 596
- Domain
- Driver Families
- Bucket
- drivers/crypto
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/err.hlinux/module.hlinux/virtio_config.hlinux/cpu.huapi/linux/virtio_crypto.hvirtio_crypto_common.h
Detected Declarations
function virtcrypto_clear_requestfunction virtio_crypto_ctrlq_callbackfunction virtcrypto_ctrlq_callbackfunction virtio_crypto_ctrl_vq_requestfunction virtcrypto_done_workfunction virtcrypto_dataq_callbackfunction virtcrypto_find_vqsfunction virtcrypto_alloc_queuesfunction virtcrypto_clean_affinityfunction virtcrypto_set_affinityfunction virtcrypto_free_queuesfunction virtcrypto_init_vqsfunction virtcrypto_update_statusfunction virtcrypto_start_crypto_enginesfunction virtcrypto_clear_crypto_enginesfunction virtcrypto_del_vqsfunction vcrypto_config_changed_workfunction virtcrypto_probefunction virtcrypto_free_unused_reqsfunction virtcrypto_removefunction virtcrypto_config_changedfunction virtcrypto_freezefunction virtcrypto_restore
Annotated Snippet
while ((vc_ctrl_req = virtqueue_get_buf(vq, &len)) != NULL) {
spin_unlock_irqrestore(&vcrypto->ctrl_lock, flags);
virtio_crypto_ctrlq_callback(vc_ctrl_req);
spin_lock_irqsave(&vcrypto->ctrl_lock, flags);
}
} while (!virtqueue_enable_cb(vq));
spin_unlock_irqrestore(&vcrypto->ctrl_lock, flags);
}
int virtio_crypto_ctrl_vq_request(struct virtio_crypto *vcrypto, struct scatterlist *sgs[],
unsigned int out_sgs, unsigned int in_sgs,
struct virtio_crypto_ctrl_request *vc_ctrl_req)
{
int err;
unsigned long flags;
init_completion(&vc_ctrl_req->compl);
spin_lock_irqsave(&vcrypto->ctrl_lock, flags);
err = virtqueue_add_sgs(vcrypto->ctrl_vq, sgs, out_sgs, in_sgs, vc_ctrl_req, GFP_ATOMIC);
if (err < 0) {
spin_unlock_irqrestore(&vcrypto->ctrl_lock, flags);
return err;
}
virtqueue_kick(vcrypto->ctrl_vq);
spin_unlock_irqrestore(&vcrypto->ctrl_lock, flags);
wait_for_completion(&vc_ctrl_req->compl);
return 0;
}
static void virtcrypto_done_work(struct work_struct *work)
{
struct data_queue *data_vq = from_work(data_vq, work, done_work);
struct virtqueue *vq = data_vq->vq;
struct virtio_crypto_request *vc_req;
unsigned long flags;
unsigned int len;
spin_lock_irqsave(&data_vq->lock, flags);
do {
virtqueue_disable_cb(vq);
while ((vc_req = virtqueue_get_buf(vq, &len)) != NULL) {
spin_unlock_irqrestore(&data_vq->lock, flags);
if (vc_req->alg_cb)
vc_req->alg_cb(vc_req, len);
spin_lock_irqsave(&data_vq->lock, flags);
}
} while (!virtqueue_enable_cb(vq));
spin_unlock_irqrestore(&data_vq->lock, flags);
}
static void virtcrypto_dataq_callback(struct virtqueue *vq)
{
struct virtio_crypto *vcrypto = vq->vdev->priv;
struct data_queue *dq = &vcrypto->data_vq[vq->index];
queue_work(system_bh_wq, &dq->done_work);
}
static int virtcrypto_find_vqs(struct virtio_crypto *vi)
{
struct virtqueue_info *vqs_info;
struct virtqueue **vqs;
int ret = -ENOMEM;
int i, total_vqs;
struct device *dev = &vi->vdev->dev;
/*
* We expect 1 data virtqueue, followed by
* possible N-1 data queues used in multiqueue mode,
* followed by control vq.
*/
total_vqs = vi->max_data_queues + 1;
/* Allocate space for find_vqs parameters */
vqs = kzalloc_objs(*vqs, total_vqs);
if (!vqs)
goto err_vq;
vqs_info = kzalloc_objs(*vqs_info, total_vqs);
if (!vqs_info)
goto err_vqs_info;
/* Parameters for control virtqueue */
vqs_info[total_vqs - 1].callback = virtcrypto_ctrlq_callback;
vqs_info[total_vqs - 1].name = "controlq";
/* Allocate/initialize parameters for data virtqueues */
Annotation
- Immediate include surface: `linux/err.h`, `linux/module.h`, `linux/virtio_config.h`, `linux/cpu.h`, `uapi/linux/virtio_crypto.h`, `virtio_crypto_common.h`.
- Detected declarations: `function virtcrypto_clear_request`, `function virtio_crypto_ctrlq_callback`, `function virtcrypto_ctrlq_callback`, `function virtio_crypto_ctrl_vq_request`, `function virtcrypto_done_work`, `function virtcrypto_dataq_callback`, `function virtcrypto_find_vqs`, `function virtcrypto_alloc_queues`, `function virtcrypto_clean_affinity`, `function virtcrypto_set_affinity`.
- Atlas domain: Driver Families / drivers/crypto.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.