Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 53c83e91 authored by Antoine Tenart's avatar Antoine Tenart Committed by Herbert Xu
Browse files

crypto: inside-secure - add an invalidation flag



Add a flags field in the private structure, and a first flag for engines
needing context invalidation (currently only the eip197b). The
invalidation is needed when the engine includes a TRC cache, which will
also be true for the upcoming addition of the eip197d engine.

Suggested-by: default avatarOfer Heifetz <oferh@marvell.com>
Signed-off-by: default avatarAntoine Tenart <antoine.tenart@bootlin.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 998d2abb
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -927,6 +927,9 @@ static int safexcel_probe(struct platform_device *pdev)
	priv->dev = dev;
	priv->version = (enum safexcel_eip_version)of_device_get_match_data(dev);

	if (priv->version == EIP197B)
		priv->flags |= EIP197_TRC_CACHE;

	safexcel_init_register_offsets(priv);

	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+5 −0
Original line number Diff line number Diff line
@@ -546,6 +546,10 @@ struct safexcel_register_offsets {
	u32 pe;
};

enum safexcel_flags {
	EIP197_TRC_CACHE = BIT(0),
};

struct safexcel_crypto_priv {
	void __iomem *base;
	struct device *dev;
@@ -555,6 +559,7 @@ struct safexcel_crypto_priv {

	enum safexcel_eip_version version;
	struct safexcel_register_offsets offsets;
	u32 flags;

	/* context DMA pool */
	struct dma_pool *context_pool;
+8 −8
Original line number Diff line number Diff line
@@ -145,7 +145,7 @@ static int safexcel_skcipher_aes_setkey(struct crypto_skcipher *ctfm,
		return ret;
	}

	if (priv->version == EIP197B && ctx->base.ctxr_dma) {
	if (priv->flags & EIP197_TRC_CACHE && ctx->base.ctxr_dma) {
		for (i = 0; i < len / sizeof(u32); i++) {
			if (ctx->key[i] != cpu_to_le32(aes.key_enc[i])) {
				ctx->base.needs_inv = true;
@@ -179,7 +179,7 @@ static int safexcel_aead_aes_setkey(struct crypto_aead *ctfm, const u8 *key,
		goto badkey;

	/* Encryption key */
	if (priv->version == EIP197B && ctx->base.ctxr_dma &&
	if (priv->flags & EIP197_TRC_CACHE && ctx->base.ctxr_dma &&
	    memcmp(ctx->key, keys.enckey, keys.enckeylen))
		ctx->base.needs_inv = true;

@@ -218,7 +218,7 @@ static int safexcel_aead_aes_setkey(struct crypto_aead *ctfm, const u8 *key,
	crypto_aead_set_flags(ctfm, crypto_aead_get_flags(ctfm) &
				    CRYPTO_TFM_RES_MASK);

	if (priv->version == EIP197B && ctx->base.ctxr_dma &&
	if (priv->flags & EIP197_TRC_CACHE && ctx->base.ctxr_dma &&
	    (memcmp(ctx->ipad, istate.state, ctx->state_sz) ||
	     memcmp(ctx->opad, ostate.state, ctx->state_sz)))
		ctx->base.needs_inv = true;
@@ -612,7 +612,7 @@ static int safexcel_skcipher_send(struct crypto_async_request *async, int ring,
	struct safexcel_crypto_priv *priv = ctx->priv;
	int ret;

	BUG_ON(priv->version == EIP97IES && sreq->needs_inv);
	BUG_ON(!(priv->flags & EIP197_TRC_CACHE) && sreq->needs_inv);

	if (sreq->needs_inv)
		ret = safexcel_cipher_send_inv(async, ring, request, commands,
@@ -635,7 +635,7 @@ static int safexcel_aead_send(struct crypto_async_request *async, int ring,
	struct safexcel_crypto_priv *priv = ctx->priv;
	int ret;

	BUG_ON(priv->version == EIP97IES && sreq->needs_inv);
	BUG_ON(!(priv->flags & EIP197_TRC_CACHE) && sreq->needs_inv);

	if (sreq->needs_inv)
		ret = safexcel_cipher_send_inv(async, ring, request, commands,
@@ -725,7 +725,7 @@ static int safexcel_aes(struct crypto_async_request *base,
	ctx->mode = mode;

	if (ctx->base.ctxr) {
		if (priv->version == EIP197B && ctx->base.needs_inv) {
		if (priv->flags & EIP197_TRC_CACHE && ctx->base.needs_inv) {
			sreq->needs_inv = true;
			ctx->base.needs_inv = false;
		}
@@ -802,7 +802,7 @@ static void safexcel_skcipher_cra_exit(struct crypto_tfm *tfm)
	if (safexcel_cipher_cra_exit(tfm))
		return;

	if (priv->version == EIP197B) {
	if (priv->flags & EIP197_TRC_CACHE) {
		ret = safexcel_skcipher_exit_inv(tfm);
		if (ret)
			dev_warn(priv->dev, "skcipher: invalidation error %d\n",
@@ -822,7 +822,7 @@ static void safexcel_aead_cra_exit(struct crypto_tfm *tfm)
	if (safexcel_cipher_cra_exit(tfm))
		return;

	if (priv->version == EIP197B) {
	if (priv->flags & EIP197_TRC_CACHE) {
		ret = safexcel_aead_exit_inv(tfm);
		if (ret)
			dev_warn(priv->dev, "aead: invalidation error %d\n",
+4 −4
Original line number Diff line number Diff line
@@ -442,7 +442,7 @@ static int safexcel_handle_result(struct safexcel_crypto_priv *priv, int ring,
	struct safexcel_ahash_req *req = ahash_request_ctx(areq);
	int err;

	BUG_ON(priv->version == EIP97IES && req->needs_inv);
	BUG_ON(!(priv->flags & EIP197_TRC_CACHE) && req->needs_inv);

	if (req->needs_inv) {
		req->needs_inv = false;
@@ -575,7 +575,7 @@ static int safexcel_ahash_enqueue(struct ahash_request *areq)
	req->needs_inv = false;

	if (ctx->base.ctxr) {
		if (priv->version == EIP197B && !ctx->base.needs_inv &&
		if (priv->flags & EIP197_TRC_CACHE && !ctx->base.needs_inv &&
		    (req->processed[0] || req->processed[1]) &&
		    req->digest == CONTEXT_CONTROL_DIGEST_PRECOMPUTED)
			/* We're still setting needs_inv here, even though it is
@@ -784,7 +784,7 @@ static void safexcel_ahash_cra_exit(struct crypto_tfm *tfm)
	if (!ctx->base.ctxr)
		return;

	if (priv->version == EIP197B) {
	if (priv->flags & EIP197_TRC_CACHE) {
		ret = safexcel_ahash_exit_inv(tfm);
		if (ret)
			dev_warn(priv->dev, "hash: invalidation error %d\n", ret);
@@ -1005,7 +1005,7 @@ static int safexcel_hmac_alg_setkey(struct crypto_ahash *tfm, const u8 *key,
	if (ret)
		return ret;

	if (priv->version == EIP197B && ctx->base.ctxr) {
	if (priv->flags & EIP197_TRC_CACHE && ctx->base.ctxr) {
		for (i = 0; i < state_sz / sizeof(u32); i++) {
			if (ctx->ipad[i] != le32_to_cpu(istate.state[i]) ||
			    ctx->opad[i] != le32_to_cpu(ostate.state[i])) {