drivers/crypto/hisilicon/sec2/sec_crypto.c
Source file repositories/reference/linux-study-clean/drivers/crypto/hisilicon/sec2/sec_crypto.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/crypto/hisilicon/sec2/sec_crypto.c- Extension
.c- Size
- 72835 bytes
- Lines
- 2782
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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
crypto/aes.hcrypto/aead.hcrypto/algapi.hcrypto/authenc.hcrypto/des.hcrypto/hash.hcrypto/internal/aead.hcrypto/internal/des.hcrypto/sha1.hcrypto/sha2.hcrypto/skcipher.hcrypto/xts.hlinux/crypto.hlinux/dma-mapping.hlinux/idr.hsec.hsec_crypto.h
Detected Declarations
struct sec_skcipherstruct sec_aeadfunction sec_alloc_req_idfunction sec_free_req_idfunction pre_parse_finished_bdfunction pre_parse_finished_bd3function sec_cb_status_checkfunction qp_send_messagefunction sec_alg_send_backlog_softfunction list_for_each_entry_safefunction sec_alg_send_backlogfunction sec_req_cbfunction sec_req_cb3function sec_alg_send_message_retryfunction sec_alg_try_enqueuefunction sec_alg_send_message_maybacklogfunction sec_bd_sendfunction sec_alloc_civ_resourcefunction sec_free_civ_resourcefunction sec_alloc_aiv_resourcefunction sec_free_aiv_resourcefunction sec_alloc_mac_resourcefunction sec_free_mac_resourcefunction sec_free_pbuf_resourcefunction packetsfunction sec_alg_resource_allocfunction sec_alg_resource_freefunction sec_alloc_qp_ctx_resourcefunction sec_free_qp_ctx_resourcefunction sec_create_qp_ctxfunction sec_release_qp_ctxfunction sec_ctx_base_initfunction sec_ctx_base_uninitfunction sec_cipher_initfunction sec_cipher_uninitfunction sec_auth_initfunction sec_auth_uninitfunction sec_skcipher_fbtfm_initfunction sec_skcipher_initfunction sec_skcipher_uninitfunction sec_skcipher_3des_setkeyfunction sec_skcipher_aes_sm4_setkeyfunction sec_skcipher_setkeyfunction sec_cipher_pbuf_mapfunction sec_cipher_pbuf_unmapfunction sec_aead_mac_initfunction fill_sg_to_hw_sgefunction sec_cipher_to_hw_sgl
Annotated Snippet
struct sec_skcipher {
u64 alg_msk;
struct skcipher_alg alg;
};
struct sec_aead {
u64 alg_msk;
struct aead_alg alg;
};
static int sec_aead_soft_crypto(struct sec_ctx *ctx,
struct aead_request *aead_req,
bool encrypt);
static int sec_skcipher_soft_crypto(struct sec_ctx *ctx,
struct skcipher_request *sreq, bool encrypt);
static int sec_alloc_req_id(struct sec_req *req, struct sec_qp_ctx *qp_ctx)
{
int req_id;
spin_lock_bh(&qp_ctx->id_lock);
req_id = idr_alloc_cyclic(&qp_ctx->req_idr, NULL, 0, qp_ctx->qp->sq_depth, GFP_ATOMIC);
spin_unlock_bh(&qp_ctx->id_lock);
return req_id;
}
static void sec_free_req_id(struct sec_req *req)
{
struct sec_qp_ctx *qp_ctx = req->qp_ctx;
int req_id = req->req_id;
if (unlikely(req_id < 0 || req_id >= qp_ctx->qp->sq_depth)) {
dev_err(req->ctx->dev, "free request id invalid!\n");
return;
}
spin_lock_bh(&qp_ctx->id_lock);
idr_remove(&qp_ctx->req_idr, req_id);
spin_unlock_bh(&qp_ctx->id_lock);
}
static void pre_parse_finished_bd(struct bd_status *status, void *resp)
{
struct sec_sqe *bd = resp;
status->done = le16_to_cpu(bd->type2.done_flag) & SEC_DONE_MASK;
status->icv = (le16_to_cpu(bd->type2.done_flag) & SEC_ICV_MASK) >> 1;
status->flag = (le16_to_cpu(bd->type2.done_flag) &
SEC_FLAG_MASK) >> SEC_FLAG_OFFSET;
status->tag = le16_to_cpu(bd->type2.tag);
status->err_type = bd->type2.error_type;
}
static void pre_parse_finished_bd3(struct bd_status *status, void *resp)
{
struct sec_sqe3 *bd3 = resp;
status->done = le16_to_cpu(bd3->done_flag) & SEC_DONE_MASK;
status->icv = (le16_to_cpu(bd3->done_flag) & SEC_ICV_MASK) >> 1;
status->flag = (le16_to_cpu(bd3->done_flag) &
SEC_FLAG_MASK) >> SEC_FLAG_OFFSET;
status->tag = le64_to_cpu(bd3->tag);
status->err_type = bd3->error_type;
}
static int sec_cb_status_check(struct sec_req *req,
struct bd_status *status)
{
struct sec_ctx *ctx = req->ctx;
if (unlikely(req->err_type || status->done != SEC_SQE_DONE)) {
dev_err_ratelimited(ctx->dev, "err_type[%d], done[%u]\n",
req->err_type, status->done);
return -EIO;
}
if (unlikely(ctx->alg_type == SEC_SKCIPHER)) {
if (unlikely(status->flag != SEC_SQE_CFLAG)) {
dev_err_ratelimited(ctx->dev, "flag[%u]\n",
status->flag);
return -EIO;
}
} else if (unlikely(ctx->alg_type == SEC_AEAD)) {
if (unlikely(status->flag != SEC_SQE_AEAD_FLAG ||
status->icv == SEC_ICV_ERR)) {
dev_err_ratelimited(ctx->dev,
"flag[%u], icv[%u]\n",
status->flag, status->icv);
return -EBADMSG;
}
Annotation
- Immediate include surface: `crypto/aes.h`, `crypto/aead.h`, `crypto/algapi.h`, `crypto/authenc.h`, `crypto/des.h`, `crypto/hash.h`, `crypto/internal/aead.h`, `crypto/internal/des.h`.
- Detected declarations: `struct sec_skcipher`, `struct sec_aead`, `function sec_alloc_req_id`, `function sec_free_req_id`, `function pre_parse_finished_bd`, `function pre_parse_finished_bd3`, `function sec_cb_status_check`, `function qp_send_message`, `function sec_alg_send_backlog_soft`, `function list_for_each_entry_safe`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.