drivers/net/ethernet/mellanox/mlx5/core/lib/crypto.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/lib/crypto.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/lib/crypto.c- Extension
.c- Size
- 21398 bytes
- Lines
- 775
- Domain
- Driver Families
- Bucket
- drivers/net
- 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
mlx5_core.hlib/crypto.h
Detected Declarations
struct mlx5_crypto_dek_poolstruct mlx5_crypto_dek_bulkstruct mlx5_crypto_dek_privstruct mlx5_crypto_dekfunction mlx5_crypto_dek_get_idfunction mlx5_crypto_dek_get_key_szfunction mlx5_crypto_dek_fill_keyfunction mlx5_crypto_cmd_sync_cryptofunction mlx5_crypto_create_dek_bulkfunction mlx5_crypto_modify_dek_keyfunction mlx5_crypto_create_dek_keyfunction mlx5_crypto_destroy_dek_keyfunction mlx5_create_encryption_keyfunction mlx5_destroy_encryption_keyfunction mlx5_crypto_dek_bulk_createfunction mlx5_crypto_dek_pool_add_bulkfunction mlx5_crypto_dek_bulk_freefunction mlx5_crypto_dek_pool_remove_bulkfunction mlx5_crypto_dek_pool_popfunction mlx5_crypto_dek_need_syncfunction mlx5_crypto_dek_free_lockedfunction mlx5_crypto_dek_pool_pushfunction offunction mlx5_crypto_dek_bulk_handle_availfunction mlx5_crypto_dek_pool_splice_destroy_listfunction mlx5_crypto_dek_pool_free_wait_keysfunction list_for_each_entry_safefunction mlx5_crypto_dek_pool_reset_syncedfunction list_for_each_entry_safefunction list_for_each_entry_safefunction list_for_each_entry_safefunction mlx5_crypto_dek_sync_work_fnfunction mlx5_crypto_dek_destroyfunction mlx5_crypto_dek_free_destroy_listfunction mlx5_crypto_dek_destroy_work_fnfunction mlx5_crypto_dek_pool_createfunction mlx5_crypto_dek_pool_destroyfunction mlx5_crypto_dek_cleanup
Annotated Snippet
struct mlx5_crypto_dek_pool {
struct mlx5_core_dev *mdev;
u32 key_purpose;
int num_deks; /* the total number of keys in this pool */
int avail_deks; /* the number of available keys in this pool */
int in_use_deks; /* the number of being used keys in this pool */
struct mutex lock; /* protect the following lists, and the bulks */
struct list_head partial_list; /* some of keys are available */
struct list_head full_list; /* no available keys */
struct list_head avail_list; /* all keys are available to use */
/* No in-used keys, and all need to be synced.
* These bulks will be put to avail list after sync.
*/
struct list_head sync_list;
bool syncing;
struct list_head wait_for_free;
struct work_struct sync_work;
spinlock_t destroy_lock; /* protect destroy_list */
struct list_head destroy_list;
struct work_struct destroy_work;
};
struct mlx5_crypto_dek_bulk {
struct mlx5_core_dev *mdev;
int base_obj_id;
int avail_start; /* the bit to start search */
int num_deks; /* the total number of keys in a bulk */
int avail_deks; /* the number of keys available, with need_sync bit 0 */
int in_use_deks; /* the number of keys being used, with in_use bit 1 */
struct list_head entry;
/* 0: not being used by any user, 1: otherwise */
unsigned long *in_use;
/* The bits are set when they are used, and reset after crypto_sync
* is executed. So, the value 0 means the key is newly created, or not
* used after sync, and 1 means it is in use, or freed but not synced
*/
unsigned long *need_sync;
};
struct mlx5_crypto_dek_priv {
struct mlx5_core_dev *mdev;
int log_dek_obj_range;
};
struct mlx5_crypto_dek {
struct mlx5_crypto_dek_bulk *bulk;
struct list_head entry;
u32 obj_id;
};
u32 mlx5_crypto_dek_get_id(struct mlx5_crypto_dek *dek)
{
return dek->obj_id;
}
static int mlx5_crypto_dek_get_key_sz(struct mlx5_core_dev *mdev,
u32 sz_bytes, u8 *key_sz_p)
{
u32 sz_bits = sz_bytes * BITS_PER_BYTE;
switch (sz_bits) {
case 128:
*key_sz_p = MLX5_GENERAL_OBJECT_TYPE_ENCRYPTION_KEY_KEY_SIZE_128;
break;
case 256:
*key_sz_p = MLX5_GENERAL_OBJECT_TYPE_ENCRYPTION_KEY_KEY_SIZE_256;
break;
default:
mlx5_core_err(mdev, "Crypto offload error, invalid key size (%u bits)\n",
sz_bits);
return -EINVAL;
}
return 0;
}
static int mlx5_crypto_dek_fill_key(struct mlx5_core_dev *mdev, u8 *key_obj,
const void *key, u32 sz_bytes)
{
void *dst;
u8 key_sz;
int err;
err = mlx5_crypto_dek_get_key_sz(mdev, sz_bytes, &key_sz);
if (err)
Annotation
- Immediate include surface: `mlx5_core.h`, `lib/crypto.h`.
- Detected declarations: `struct mlx5_crypto_dek_pool`, `struct mlx5_crypto_dek_bulk`, `struct mlx5_crypto_dek_priv`, `struct mlx5_crypto_dek`, `function mlx5_crypto_dek_get_id`, `function mlx5_crypto_dek_get_key_sz`, `function mlx5_crypto_dek_fill_key`, `function mlx5_crypto_cmd_sync_crypto`, `function mlx5_crypto_create_dek_bulk`, `function mlx5_crypto_modify_dek_key`.
- Atlas domain: Driver Families / drivers/net.
- 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.