drivers/crypto/bcm/cipher.c
Source file repositories/reference/linux-study-clean/drivers/crypto/bcm/cipher.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/crypto/bcm/cipher.c- Extension
.c- Size
- 131997 bytes
- Lines
- 4712
- 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/init.hlinux/errno.hlinux/kernel.hlinux/interrupt.hlinux/platform_device.hlinux/scatterlist.hlinux/crypto.hlinux/kthread.hlinux/rtnetlink.hlinux/sched.hlinux/string_choices.hlinux/of.hlinux/io.hlinux/bitops.hcrypto/algapi.hcrypto/aead.hcrypto/internal/aead.hcrypto/aes.hcrypto/internal/des.hcrypto/hmac.hcrypto/md5.hcrypto/authenc.hcrypto/skcipher.hcrypto/hash.hcrypto/sha1.hcrypto/sha2.hcrypto/sha3.hutil.hcipher.hspu.h
Detected Declarations
function select_channelfunction spu_skcipher_rx_sg_createfunction spu_skcipher_tx_sg_createfunction mailbox_send_messagefunction handle_skcipher_reqfunction handle_skcipher_respfunction spu_ahash_rx_sg_createfunction spu_ahash_tx_sg_createfunction handle_ahash_reqfunction itfunction spu_hmac_outer_hashfunction ahash_req_donefunction handle_ahash_respfunction spu_aead_rx_sg_createfunction spu_aead_tx_sg_createfunction handle_aead_reqfunction handle_aead_respfunction spu_chunk_cleanupfunction finish_reqfunction spu_rx_callbackfunction skcipher_enqueuefunction des_setkeyfunction threedes_setkeyfunction aes_setkeyfunction skcipher_setkeyfunction skcipher_encryptfunction skcipher_decryptfunction ahash_enqueuefunction __ahash_initfunction spu_no_incr_hashfunction ahash_initfunction __ahash_updatefunction ahash_updatefunction __ahash_finalfunction ahash_finalfunction __ahash_finupfunction ahash_finupfunction ahash_digestfunction ahash_setkeyfunction ahash_exportfunction ahash_importfunction ahash_hmac_setkeyfunction ahash_hmac_initfunction ahash_hmac_updatefunction ahash_hmac_finalfunction ahash_hmac_finupfunction ahash_hmac_digestfunction aead_need_fallback
Annotated Snippet
while ((err == -ENOBUFS) && (retry_cnt < SPU_MB_RETRY_MAX)) {
/*
* Mailbox queue is full. Since MAY_SLEEP is set, assume
* not in atomic context and we can wait and try again.
*/
retry_cnt++;
usleep_range(MBOX_SLEEP_MIN, MBOX_SLEEP_MAX);
err = mbox_send_message(iproc_priv.mbox[chan_idx],
mssg);
atomic_inc(&iproc_priv.mb_no_spc);
}
}
if (err < 0) {
atomic_inc(&iproc_priv.mb_send_fail);
return err;
}
/* Check error returned by mailbox controller */
err = mssg->error;
if (unlikely(err < 0)) {
dev_err(dev, "message error %d", err);
/* Signal txdone for mailbox channel */
}
/* Signal txdone for mailbox channel */
mbox_client_txdone(iproc_priv.mbox[chan_idx], err);
return err;
}
/**
* handle_skcipher_req() - Submit as much of a block cipher request as fits in
* a single SPU request message, starting at the current position in the request
* data.
* @rctx: Crypto request context
*
* This may be called on the crypto API thread, or, when a request is so large
* it must be broken into multiple SPU messages, on the thread used to invoke
* the response callback. When requests are broken into multiple SPU
* messages, we assume subsequent messages depend on previous results, and
* thus always wait for previous results before submitting the next message.
* Because requests are submitted in lock step like this, there is no need
* to synchronize access to request data structures.
*
* Return: -EINPROGRESS: request has been accepted and result will be returned
* asynchronously
* Any other value indicates an error
*/
static int handle_skcipher_req(struct iproc_reqctx_s *rctx)
{
struct spu_hw *spu = &iproc_priv.spu;
struct crypto_async_request *areq = rctx->parent;
struct skcipher_request *req =
container_of(areq, struct skcipher_request, base);
struct iproc_ctx_s *ctx = rctx->ctx;
struct spu_cipher_parms cipher_parms;
int err;
unsigned int chunksize; /* Num bytes of request to submit */
int remaining; /* Bytes of request still to process */
int chunk_start; /* Beginning of data for current SPU msg */
/* IV or ctr value to use in this SPU msg */
u8 local_iv_ctr[MAX_IV_SIZE];
u32 stat_pad_len; /* num bytes to align status field */
u32 pad_len; /* total length of all padding */
struct brcm_message *mssg; /* mailbox message */
/* number of entries in src and dst sg in mailbox message. */
u8 rx_frag_num = 2; /* response header and STATUS */
u8 tx_frag_num = 1; /* request header */
flow_log("%s\n", __func__);
cipher_parms.alg = ctx->cipher.alg;
cipher_parms.mode = ctx->cipher.mode;
cipher_parms.type = ctx->cipher_type;
cipher_parms.key_len = ctx->enckeylen;
cipher_parms.key_buf = ctx->enckey;
cipher_parms.iv_buf = local_iv_ctr;
cipher_parms.iv_len = rctx->iv_ctr_len;
mssg = &rctx->mb_mssg;
chunk_start = rctx->src_sent;
remaining = rctx->total_todo - chunk_start;
/* determine the chunk we are breaking off and update the indexes */
if ((ctx->max_payload != SPU_MAX_PAYLOAD_INF) &&
(remaining > ctx->max_payload))
chunksize = ctx->max_payload;
else
chunksize = remaining;
Annotation
- Immediate include surface: `linux/err.h`, `linux/module.h`, `linux/init.h`, `linux/errno.h`, `linux/kernel.h`, `linux/interrupt.h`, `linux/platform_device.h`, `linux/scatterlist.h`.
- Detected declarations: `function select_channel`, `function spu_skcipher_rx_sg_create`, `function spu_skcipher_tx_sg_create`, `function mailbox_send_message`, `function handle_skcipher_req`, `function handle_skcipher_resp`, `function spu_ahash_rx_sg_create`, `function spu_ahash_tx_sg_create`, `function handle_ahash_req`, `function it`.
- 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.