drivers/crypto/starfive/jh7110-hash.c
Source file repositories/reference/linux-study-clean/drivers/crypto/starfive/jh7110-hash.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/crypto/starfive/jh7110-hash.c- Extension
.c- Size
- 24732 bytes
- Lines
- 855
- 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.
- 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/engine.hcrypto/internal/hash.hcrypto/scatterwalk.hjh7110-cryp.hlinux/amba/pl080.hlinux/clk.hlinux/dma-direct.hlinux/interrupt.hlinux/iopoll.hlinux/kernel.hlinux/module.hlinux/platform_device.hlinux/pm_runtime.hlinux/reset.h
Detected Declarations
function Copyrightfunction starfive_hash_wait_hmac_donefunction starfive_hash_wait_key_donefunction starfive_hash_hmac_keyfunction starfive_hash_startfunction starfive_hash_dma_callbackfunction starfive_hash_dma_initfunction starfive_hash_dma_xferfunction starfive_hash_copy_hashfunction starfive_hash_done_taskfunction starfive_hash_one_requestfunction for_each_sgfunction starfive_hash_initfunction starfive_hash_updatefunction starfive_hash_finalfunction starfive_hash_finupfunction starfive_hash_digestfunction starfive_hash_exportfunction starfive_hash_importfunction starfive_hash_init_tfmfunction starfive_hash_exit_tfmfunction starfive_hash_long_setkeyfunction starfive_hash_setkeyfunction starfive_sha224_init_tfmfunction starfive_sha256_init_tfmfunction starfive_sha384_init_tfmfunction starfive_sha512_init_tfmfunction starfive_sm3_init_tfmfunction starfive_hmac_sha224_init_tfmfunction starfive_hmac_sha256_init_tfmfunction starfive_hmac_sha384_init_tfmfunction starfive_hmac_sha512_init_tfmfunction starfive_hmac_sm3_init_tfmfunction starfive_hash_register_algsfunction starfive_hash_unregister_algs
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Hash function and HMAC support for StarFive driver
*
* Copyright (c) 2022 StarFive Technology
*
*/
#include <crypto/engine.h>
#include <crypto/internal/hash.h>
#include <crypto/scatterwalk.h>
#include "jh7110-cryp.h"
#include <linux/amba/pl080.h>
#include <linux/clk.h>
#include <linux/dma-direct.h>
#include <linux/interrupt.h>
#include <linux/iopoll.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/reset.h>
#define STARFIVE_HASH_REGS_OFFSET 0x300
#define STARFIVE_HASH_SHACSR (STARFIVE_HASH_REGS_OFFSET + 0x0)
#define STARFIVE_HASH_SHAWDR (STARFIVE_HASH_REGS_OFFSET + 0x4)
#define STARFIVE_HASH_SHARDR (STARFIVE_HASH_REGS_OFFSET + 0x8)
#define STARFIVE_HASH_SHAWSR (STARFIVE_HASH_REGS_OFFSET + 0xC)
#define STARFIVE_HASH_SHAWLEN3 (STARFIVE_HASH_REGS_OFFSET + 0x10)
#define STARFIVE_HASH_SHAWLEN2 (STARFIVE_HASH_REGS_OFFSET + 0x14)
#define STARFIVE_HASH_SHAWLEN1 (STARFIVE_HASH_REGS_OFFSET + 0x18)
#define STARFIVE_HASH_SHAWLEN0 (STARFIVE_HASH_REGS_OFFSET + 0x1C)
#define STARFIVE_HASH_SHAWKR (STARFIVE_HASH_REGS_OFFSET + 0x20)
#define STARFIVE_HASH_SHAWKLEN (STARFIVE_HASH_REGS_OFFSET + 0x24)
#define STARFIVE_HASH_BUFLEN SHA512_BLOCK_SIZE
#define STARFIVE_HASH_RESET 0x2
static inline int starfive_hash_wait_busy(struct starfive_cryp_dev *cryp)
{
u32 status;
return readl_relaxed_poll_timeout(cryp->base + STARFIVE_HASH_SHACSR, status,
!(status & STARFIVE_HASH_BUSY), 10, 100000);
}
static inline int starfive_hash_wait_hmac_done(struct starfive_cryp_dev *cryp)
{
u32 status;
return readl_relaxed_poll_timeout(cryp->base + STARFIVE_HASH_SHACSR, status,
(status & STARFIVE_HASH_HMAC_DONE), 10, 100000);
}
static inline int starfive_hash_wait_key_done(struct starfive_cryp_ctx *ctx)
{
struct starfive_cryp_dev *cryp = ctx->cryp;
u32 status;
return readl_relaxed_poll_timeout(cryp->base + STARFIVE_HASH_SHACSR, status,
(status & STARFIVE_HASH_KEY_DONE), 10, 100000);
}
static int starfive_hash_hmac_key(struct starfive_cryp_ctx *ctx)
{
struct starfive_cryp_request_ctx *rctx = ctx->rctx;
struct starfive_cryp_dev *cryp = ctx->cryp;
int klen = ctx->keylen, loop;
unsigned int *key = (unsigned int *)ctx->key;
unsigned char *cl;
writel(ctx->keylen, cryp->base + STARFIVE_HASH_SHAWKLEN);
rctx->csr.hash.hmac = 1;
rctx->csr.hash.key_flag = 1;
writel(rctx->csr.hash.v, cryp->base + STARFIVE_HASH_SHACSR);
for (loop = 0; loop < klen / sizeof(unsigned int); loop++, key++)
writel(*key, cryp->base + STARFIVE_HASH_SHAWKR);
if (klen & 0x3) {
cl = (unsigned char *)key;
for (loop = 0; loop < (klen & 0x3); loop++, cl++)
writeb(*cl, cryp->base + STARFIVE_HASH_SHAWKR);
}
if (starfive_hash_wait_key_done(ctx))
return dev_err_probe(cryp->dev, -ETIMEDOUT, "starfive_hash_wait_key_done error\n");
Annotation
- Immediate include surface: `crypto/engine.h`, `crypto/internal/hash.h`, `crypto/scatterwalk.h`, `jh7110-cryp.h`, `linux/amba/pl080.h`, `linux/clk.h`, `linux/dma-direct.h`, `linux/interrupt.h`.
- Detected declarations: `function Copyright`, `function starfive_hash_wait_hmac_done`, `function starfive_hash_wait_key_done`, `function starfive_hash_hmac_key`, `function starfive_hash_start`, `function starfive_hash_dma_callback`, `function starfive_hash_dma_init`, `function starfive_hash_dma_xfer`, `function starfive_hash_copy_hash`, `function starfive_hash_done_task`.
- Atlas domain: Driver Families / drivers/crypto.
- Implementation status: source implementation candidate.
- 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.