[09/12] crypto: caam - bypass crypto-engine sw queue, if empty
diff mbox series

Message ID 1574029845-22796-10-git-send-email-iuliana.prodan@nxp.com
State New, archived
Headers show
Series
  • crypto: caam - backlogging support
Related show

Commit Message

Iuliana Prodan Nov. 17, 2019, 10:30 p.m. UTC
Bypass crypto-engine software queue, if empty, and send the request
directly to hardware. If this returns -ENOSPC, transfer the request to
crypto-engine and let it handle it.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
---
 drivers/crypto/caam/jr.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

Comments

Horia Geantă Nov. 21, 2019, 11:53 a.m. UTC | #1
On 11/18/2019 12:31 AM, Iuliana Prodan wrote:
> Bypass crypto-engine software queue, if empty, and send the request
> directly to hardware. If this returns -ENOSPC, transfer the request to
> crypto-engine and let it handle it.
> 
Could this optimization be added directly into the crypto engine?

> Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
> ---
>  drivers/crypto/caam/jr.c | 29 ++++++++++++++++++++++++++---
>  1 file changed, 26 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
> index 5c55d3d..ddf3d39 100644
> --- a/drivers/crypto/caam/jr.c
> +++ b/drivers/crypto/caam/jr.c
> @@ -476,10 +476,33 @@ int caam_jr_enqueue(struct device *dev, u32 *desc,
>  	struct caam_drv_private_jr *jrpriv = dev_get_drvdata(dev);
>  	struct caam_jr_request_entry *jrentry = areq;
>  	struct crypto_async_request *req = jrentry->base;
> +	int ret;
>  
> -	if (req->flags & CRYPTO_TFM_REQ_MAY_BACKLOG)
> -		return transfer_request_to_engine(jrpriv->engine, req);
> -
> +	if (req->flags & CRYPTO_TFM_REQ_MAY_BACKLOG) {
> +		if (crypto_queue_len(&jrpriv->engine->queue) == 0) {
> +			/*
> +			 * send the request to CAAM, if crypto-engine queue
> +			 * is empty
> +			 */
> +			ret = caam_jr_enqueue_no_bklog(dev, desc, cbk, jrentry);
> +			if (ret == -ENOSPC)
> +				/*
> +				 * CAAM has no space, so transfer the request
> +				 * to crypto-engine
> +				 */
> +				return transfer_request_to_engine(jrpriv->engine,
> +								  req);
> +			else
> +				return ret;
> +		} else {
> +			/*
> +			 * crypto-engine queue is not empty, so transfer the
> +			 * request to crypto-engine, to keep the order
> +			 * of requests
> +			 */
> +			return transfer_request_to_engine(jrpriv->engine, req);
> +		}
> +	}
>  	return caam_jr_enqueue_no_bklog(dev, desc, cbk, jrentry);
>  }
>  EXPORT_SYMBOL(caam_jr_enqueue);
>

Patch
diff mbox series

diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index 5c55d3d..ddf3d39 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -476,10 +476,33 @@  int caam_jr_enqueue(struct device *dev, u32 *desc,
 	struct caam_drv_private_jr *jrpriv = dev_get_drvdata(dev);
 	struct caam_jr_request_entry *jrentry = areq;
 	struct crypto_async_request *req = jrentry->base;
+	int ret;
 
-	if (req->flags & CRYPTO_TFM_REQ_MAY_BACKLOG)
-		return transfer_request_to_engine(jrpriv->engine, req);
-
+	if (req->flags & CRYPTO_TFM_REQ_MAY_BACKLOG) {
+		if (crypto_queue_len(&jrpriv->engine->queue) == 0) {
+			/*
+			 * send the request to CAAM, if crypto-engine queue
+			 * is empty
+			 */
+			ret = caam_jr_enqueue_no_bklog(dev, desc, cbk, jrentry);
+			if (ret == -ENOSPC)
+				/*
+				 * CAAM has no space, so transfer the request
+				 * to crypto-engine
+				 */
+				return transfer_request_to_engine(jrpriv->engine,
+								  req);
+			else
+				return ret;
+		} else {
+			/*
+			 * crypto-engine queue is not empty, so transfer the
+			 * request to crypto-engine, to keep the order
+			 * of requests
+			 */
+			return transfer_request_to_engine(jrpriv->engine, req);
+		}
+	}
 	return caam_jr_enqueue_no_bklog(dev, desc, cbk, jrentry);
 }
 EXPORT_SYMBOL(caam_jr_enqueue);