drivers/s390/crypto/zcrypt_api.c
Source file repositories/reference/linux-study-clean/drivers/s390/crypto/zcrypt_api.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/s390/crypto/zcrypt_api.c- Extension
.c- Size
- 52152 bytes
- Lines
- 2022
- Domain
- Driver Families
- Bucket
- drivers/s390
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/export.hlinux/module.hlinux/init.hlinux/interrupt.hlinux/miscdevice.hlinux/fs.hlinux/slab.hlinux/atomic.hlinux/uaccess.hlinux/hw_random.hlinux/debugfs.hlinux/cdev.hlinux/ctype.hlinux/capability.hasm/debug.hasm/trace/zcrypt.hzcrypt_api.hzcrypt_debug.hzcrypt_msgtype6.hzcrypt_msgtype50.hzcrypt_ccamisc.hzcrypt_ep11misc.h
Detected Declarations
struct zcdn_devicestruct zcdn_devicefunction changedfunction zcrypt_msgtype_registerfunction zcrypt_msgtype_unregisterfunction put_devicefunction put_devicefunction ioctlmask_showfunction ioctlmask_storefunction apmask_showfunction apmask_storefunction aqmask_showfunction aqmask_storefunction admask_showfunction admask_storefunction zcdn_create_storefunction zcdn_destroy_storefunction zcdn_device_releasefunction zcdn_createfunction zcdn_destroyfunction zcdn_destroy_allfunction zcrypt_readfunction zcrypt_writefunction zcrypt_openfunction zcrypt_releasefunction zcrypt_check_ioctlfunction zcrypt_check_cardfunction zcrypt_check_queuefunction zcrypt_drop_queuefunction zcrypt_card_comparefunction zcrypt_queue_comparefunction zcrypt_rsa_modexpofunction for_each_zcrypt_queuefunction zcrypt_rsa_crtfunction for_each_zcrypt_queuefunction _zcrypt_send_cprbfunction for_each_zcrypt_queuefunction zcrypt_send_cprbfunction is_desired_ep11_cardfunction is_desired_ep11_queuefunction _zcrypt_send_ep11_cprbfunction for_each_zcrypt_queuefunction zcrypt_send_ep11_cprbfunction zcrypt_rngfunction for_each_zcrypt_queuefunction zcrypt_device_status_maskfunction for_each_zcrypt_queuefunction zcrypt_device_status_mask_ext
Annotated Snippet
static const struct file_operations zcrypt_fops = {
.owner = THIS_MODULE,
.read = zcrypt_read,
.write = zcrypt_write,
.unlocked_ioctl = zcrypt_unlocked_ioctl,
.open = zcrypt_open,
.release = zcrypt_release,
};
/*
* Misc device.
*/
static struct miscdevice zcrypt_misc_device = {
.minor = MISC_DYNAMIC_MINOR,
.name = "z90crypt",
.fops = &zcrypt_fops,
};
static int zcrypt_rng_device_count;
static u32 *zcrypt_rng_buffer;
static int zcrypt_rng_buffer_index;
static DEFINE_MUTEX(zcrypt_rng_mutex);
static int zcrypt_rng_data_read(struct hwrng *rng, u32 *data)
{
int rc;
/*
* We don't need locking here because the RNG API guarantees serialized
* read method calls.
*/
if (zcrypt_rng_buffer_index == 0) {
rc = zcrypt_rng((char *)zcrypt_rng_buffer);
/* on ENODEV failure: retry once again after an AP bus rescan */
if (rc == -ENODEV && zcrypt_process_rescan())
rc = zcrypt_rng((char *)zcrypt_rng_buffer);
if (rc < 0)
return -EIO;
zcrypt_rng_buffer_index = rc / sizeof(*data);
}
*data = zcrypt_rng_buffer[--zcrypt_rng_buffer_index];
return sizeof(*data);
}
static struct hwrng zcrypt_rng_dev = {
.name = "zcrypt",
.data_read = zcrypt_rng_data_read,
.quality = 990,
};
int zcrypt_rng_device_add(void)
{
int rc = 0;
mutex_lock(&zcrypt_rng_mutex);
if (zcrypt_rng_device_count == 0) {
zcrypt_rng_buffer = kzalloc(PAGE_SIZE, GFP_KERNEL);
if (!zcrypt_rng_buffer) {
rc = -ENOMEM;
goto out;
}
zcrypt_rng_buffer_index = 0;
rc = hwrng_register(&zcrypt_rng_dev);
if (rc)
goto out_free;
zcrypt_rng_device_count = 1;
} else {
zcrypt_rng_device_count++;
}
mutex_unlock(&zcrypt_rng_mutex);
return 0;
out_free:
kfree(zcrypt_rng_buffer);
out:
mutex_unlock(&zcrypt_rng_mutex);
return rc;
}
void zcrypt_rng_device_remove(void)
{
mutex_lock(&zcrypt_rng_mutex);
zcrypt_rng_device_count--;
if (zcrypt_rng_device_count == 0) {
hwrng_unregister(&zcrypt_rng_dev);
kfree(zcrypt_rng_buffer);
}
mutex_unlock(&zcrypt_rng_mutex);
}
Annotation
- Immediate include surface: `linux/export.h`, `linux/module.h`, `linux/init.h`, `linux/interrupt.h`, `linux/miscdevice.h`, `linux/fs.h`, `linux/slab.h`, `linux/atomic.h`.
- Detected declarations: `struct zcdn_device`, `struct zcdn_device`, `function changed`, `function zcrypt_msgtype_register`, `function zcrypt_msgtype_unregister`, `function put_device`, `function put_device`, `function ioctlmask_show`, `function ioctlmask_store`, `function apmask_show`.
- Atlas domain: Driver Families / drivers/s390.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.