summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoakim Bech <joakim.xx.bech@stericsson.com>2011-05-27 09:50:33 +0200
committerPhilippe Langlais <philippe.langlais@stericsson.com>2012-05-22 11:04:36 +0200
commit1a2d5912e3212adcf88c7d51bd6d16e7c6389aef (patch)
tree3293bdbbedd1515f7053ef2e0500eae42cc0234d
parent8645233e6375a93e4054ad1568b79bed8271d50c (diff)
cryp: Session handling for software context
- Add a session id to the software crypto context in ux500 crypto driver. - Add a static global session id which is a counter that increases when a new job is started (it is ok that this variable loop back to zero when it reach the maximum value). - These session id's will be used to decide if the hardware registers needs be restored or not for continous jobs. As a result we gain performance when we don't need to restore hardware registers. ST-Ericsson ID: 342659 ST-Ericsson Linux next: Not tested, ER 320876 ST-Ericsson FOSS-OUT ID: Trivial Change-Id: I1a1f508e9969e438204d1b4a803f1d637c1e0d60 Signed-off-by: Joakim Bech <joakim.xx.bech@stericsson.com> Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/24019 Reviewed-by: QATOOLS Reviewed-by: QATEST Reviewed-by: Berne HEBARK <berne.hebark@stericsson.com>
-rw-r--r--drivers/crypto/ux500/cryp/cryp.h2
-rw-r--r--drivers/crypto/ux500/cryp/cryp_core.c37
2 files changed, 30 insertions, 9 deletions
diff --git a/drivers/crypto/ux500/cryp/cryp.h b/drivers/crypto/ux500/cryp/cryp.h
index bfa2beb694f..36835a3982e 100644
--- a/drivers/crypto/ux500/cryp/cryp.h
+++ b/drivers/crypto/ux500/cryp/cryp.h
@@ -80,7 +80,6 @@ enum cryp_mode {
/**
* struct cryp_config -
- * @keyrden: Cryp state enable/disable
* @keysize: Key size for AES
* @algomode: AES modes
* @algodir: Cryp Encryption or Decryption
@@ -88,7 +87,6 @@ enum cryp_mode {
* CRYP configuration structure to be passed to set configuration
*/
struct cryp_config {
- enum cryp_state keyrden;
int keysize;
enum cryp_algo_mode algomode;
enum cryp_algorithm_dir algodir;
diff --git a/drivers/crypto/ux500/cryp/cryp_core.c b/drivers/crypto/ux500/cryp/cryp_core.c
index 051874bff03..9cbfc63ba2b 100644
--- a/drivers/crypto/ux500/cryp/cryp_core.c
+++ b/drivers/crypto/ux500/cryp/cryp_core.c
@@ -42,6 +42,7 @@
#define BYTES_PER_WORD 4
static int cryp_mode;
+static atomic_t session_id;
static struct stedma40_chan_cfg *mem_to_engine;
static struct stedma40_chan_cfg *engine_to_mem;
@@ -85,6 +86,7 @@ struct cryp_ctx {
u8 updated;
struct cryp_device_context dev_ctx;
struct cryp_device_data *device;
+ u32 session_id;
};
static struct cryp_driver_data driver_data;
@@ -176,6 +178,18 @@ static inline void swap_words_in_key_and_bits_in_byte(const u8 *in,
}
}
+static void add_session_id(struct cryp_ctx *ctx)
+{
+ /*
+ * We never want 0 to be a valid value, since this is the default value
+ * for the software context.
+ */
+ if (unlikely(atomic_inc_and_test(&session_id)))
+ atomic_inc(&session_id);
+
+ ctx->session_id = atomic_read(&session_id);
+}
+
static irqreturn_t cryp_interrupt_handler(int irq, void *param)
{
struct cryp_ctx *ctx;
@@ -359,11 +373,10 @@ static int cryp_setup_context(struct cryp_ctx *ctx,
struct cryp_device_data *device_data)
{
u32 control_register = CRYP_CR_DEFAULT;
- cryp_flush_inoutfifo(device_data);
switch (cryp_mode) {
case CRYP_MODE_INTERRUPT:
- writel(CRYP_IMSC_DEFAULT, &device_data->base->imsc);
+ writel(CRYP_IMSC_DEFAULT, &device_data->base->imsc);
break;
case CRYP_MODE_DMA:
@@ -374,10 +387,8 @@ static int cryp_setup_context(struct cryp_ctx *ctx,
break;
}
- if (ctx->updated) {
- cryp_restore_device_context(device_data, &ctx->dev_ctx);
- control_register = ctx->dev_ctx.cr;
- } else {
+ if (ctx->updated == 0) {
+ cryp_flush_inoutfifo(device_data);
if (cfg_keys(ctx) != 0) {
dev_err(ctx->device->dev, "[%s]: cfg_keys failed!",
__func__);
@@ -394,7 +405,16 @@ static int cryp_setup_context(struct cryp_ctx *ctx,
cryp_set_configuration(device_data, &ctx->config,
&control_register);
- }
+ add_session_id(ctx);
+ } else if (ctx->updated == 1 &&
+ ctx->session_id != atomic_read(&session_id)) {
+ cryp_flush_inoutfifo(device_data);
+ cryp_restore_device_context(device_data, &ctx->dev_ctx);
+
+ add_session_id(ctx);
+ control_register = ctx->dev_ctx.cr;
+ } else
+ control_register = ctx->dev_ctx.cr;
writel(control_register | (CRYP_CRYPEN_ENABLE << CRYP_CR_CRYPEN_POS),
&device_data->base->cr);
@@ -735,6 +755,7 @@ static int hw_crypt_noxts(struct cryp_ctx *ctx,
}
ret = cryp_setup_context(ctx, device_data);
+
if (ret)
goto out;
@@ -2017,6 +2038,8 @@ static int u8500_cryp_probe(struct platform_device *pdev)
/* ... and signal that a new device is available. */
up(&driver_data.device_allocation);
+ atomic_set(&session_id, 1);
+
ret = cryp_algs_register_all();
if (ret) {
dev_err(dev, "[%s]: cryp_algs_register_all() failed!",