aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/crypto
diff options
context:
space:
mode:
authorKim Phillips <kim.phillips@freescale.com>2011-07-14 23:21:38 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2011-07-14 23:21:38 -0400
commit5228f0f79e983c2b39c202c75af901ceb0003fc1 (patch)
tree2694a01e0b400e2aa1f05e6b335a0f1ed233e981 /drivers/crypto
parent625426633d7786f26a33123a9d12bec476bcc3cd (diff)
crypto: talitos - ensure request ordering within a single tfm
Assign single target channel per tfm in talitos_cra_init instead of performing channel scheduling dynamically during the encryption request. This changes the talitos_submit interface to accept a new channel number argument. Without this, rapid bursts of misc. sized requests could make it possible for IPsec packets to be encrypted out-of-order, which would result in packet drops due to sequence numbers falling outside the anti-reply window on a peer gateway. Signed-off-by: Kim Phillips <kim.phillips@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto')
-rw-r--r--drivers/crypto/talitos.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index 854e2632f9a6..b8ca58394f05 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * talitos - Freescale Integrated Security Engine (SEC) device driver 2 * talitos - Freescale Integrated Security Engine (SEC) device driver
3 * 3 *
4 * Copyright (c) 2008-2010 Freescale Semiconductor, Inc. 4 * Copyright (c) 2008-2011 Freescale Semiconductor, Inc.
5 * 5 *
6 * Scatterlist Crypto API glue code copied from files with the following: 6 * Scatterlist Crypto API glue code copied from files with the following:
7 * Copyright (c) 2006-2007 Herbert Xu <herbert@gondor.apana.org.au> 7 * Copyright (c) 2006-2007 Herbert Xu <herbert@gondor.apana.org.au>
@@ -282,6 +282,7 @@ static int init_device(struct device *dev)
282/** 282/**
283 * talitos_submit - submits a descriptor to the device for processing 283 * talitos_submit - submits a descriptor to the device for processing
284 * @dev: the SEC device to be used 284 * @dev: the SEC device to be used
285 * @ch: the SEC device channel to be used
285 * @desc: the descriptor to be processed by the device 286 * @desc: the descriptor to be processed by the device
286 * @callback: whom to call when processing is complete 287 * @callback: whom to call when processing is complete
287 * @context: a handle for use by caller (optional) 288 * @context: a handle for use by caller (optional)
@@ -290,7 +291,7 @@ static int init_device(struct device *dev)
290 * callback must check err and feedback in descriptor header 291 * callback must check err and feedback in descriptor header
291 * for device processing status. 292 * for device processing status.
292 */ 293 */
293static int talitos_submit(struct device *dev, struct talitos_desc *desc, 294static int talitos_submit(struct device *dev, int ch, struct talitos_desc *desc,
294 void (*callback)(struct device *dev, 295 void (*callback)(struct device *dev,
295 struct talitos_desc *desc, 296 struct talitos_desc *desc,
296 void *context, int error), 297 void *context, int error),
@@ -298,15 +299,12 @@ static int talitos_submit(struct device *dev, struct talitos_desc *desc,
298{ 299{
299 struct talitos_private *priv = dev_get_drvdata(dev); 300 struct talitos_private *priv = dev_get_drvdata(dev);
300 struct talitos_request *request; 301 struct talitos_request *request;
301 unsigned long flags, ch; 302 unsigned long flags;
302 int head; 303 int head;
303 304
304 /* select done notification */ 305 /* select done notification */
305 desc->hdr |= DESC_HDR_DONE_NOTIFY; 306 desc->hdr |= DESC_HDR_DONE_NOTIFY;
306 307
307 /* emulate SEC's round-robin channel fifo polling scheme */
308 ch = atomic_inc_return(&priv->last_chan) & (priv->num_channels - 1);
309
310 spin_lock_irqsave(&priv->chan[ch].head_lock, flags); 308 spin_lock_irqsave(&priv->chan[ch].head_lock, flags);
311 309
312 if (!atomic_inc_not_zero(&priv->chan[ch].submit_count)) { 310 if (!atomic_inc_not_zero(&priv->chan[ch].submit_count)) {
@@ -706,6 +704,7 @@ static void talitos_unregister_rng(struct device *dev)
706 704
707struct talitos_ctx { 705struct talitos_ctx {
708 struct device *dev; 706 struct device *dev;
707 int ch;
709 __be32 desc_hdr_template; 708 __be32 desc_hdr_template;
710 u8 key[TALITOS_MAX_KEY_SIZE]; 709 u8 key[TALITOS_MAX_KEY_SIZE];
711 u8 iv[TALITOS_MAX_IV_LENGTH]; 710 u8 iv[TALITOS_MAX_IV_LENGTH];
@@ -1117,7 +1116,7 @@ static int ipsec_esp(struct talitos_edesc *edesc, struct aead_request *areq,
1117 map_single_talitos_ptr(dev, &desc->ptr[6], ivsize, ctx->iv, 0, 1116 map_single_talitos_ptr(dev, &desc->ptr[6], ivsize, ctx->iv, 0,
1118 DMA_FROM_DEVICE); 1117 DMA_FROM_DEVICE);
1119 1118
1120 ret = talitos_submit(dev, desc, callback, areq); 1119 ret = talitos_submit(dev, ctx->ch, desc, callback, areq);
1121 if (ret != -EINPROGRESS) { 1120 if (ret != -EINPROGRESS) {
1122 ipsec_esp_unmap(dev, edesc, areq); 1121 ipsec_esp_unmap(dev, edesc, areq);
1123 kfree(edesc); 1122 kfree(edesc);
@@ -1524,7 +1523,7 @@ static int common_nonsnoop(struct talitos_edesc *edesc,
1524 to_talitos_ptr(&desc->ptr[6], 0); 1523 to_talitos_ptr(&desc->ptr[6], 0);
1525 desc->ptr[6].j_extent = 0; 1524 desc->ptr[6].j_extent = 0;
1526 1525
1527 ret = talitos_submit(dev, desc, callback, areq); 1526 ret = talitos_submit(dev, ctx->ch, desc, callback, areq);
1528 if (ret != -EINPROGRESS) { 1527 if (ret != -EINPROGRESS) {
1529 common_nonsnoop_unmap(dev, edesc, areq); 1528 common_nonsnoop_unmap(dev, edesc, areq);
1530 kfree(edesc); 1529 kfree(edesc);
@@ -1703,7 +1702,7 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc,
1703 /* last DWORD empty */ 1702 /* last DWORD empty */
1704 desc->ptr[6] = zero_entry; 1703 desc->ptr[6] = zero_entry;
1705 1704
1706 ret = talitos_submit(dev, desc, callback, areq); 1705 ret = talitos_submit(dev, ctx->ch, desc, callback, areq);
1707 if (ret != -EINPROGRESS) { 1706 if (ret != -EINPROGRESS) {
1708 common_nonsnoop_hash_unmap(dev, edesc, areq); 1707 common_nonsnoop_hash_unmap(dev, edesc, areq);
1709 kfree(edesc); 1708 kfree(edesc);
@@ -2244,6 +2243,7 @@ static int talitos_cra_init(struct crypto_tfm *tfm)
2244 struct crypto_alg *alg = tfm->__crt_alg; 2243 struct crypto_alg *alg = tfm->__crt_alg;
2245 struct talitos_crypto_alg *talitos_alg; 2244 struct talitos_crypto_alg *talitos_alg;
2246 struct talitos_ctx *ctx = crypto_tfm_ctx(tfm); 2245 struct talitos_ctx *ctx = crypto_tfm_ctx(tfm);
2246 struct talitos_private *priv;
2247 2247
2248 if ((alg->cra_flags & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_AHASH) 2248 if ((alg->cra_flags & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_AHASH)
2249 talitos_alg = container_of(__crypto_ahash_alg(alg), 2249 talitos_alg = container_of(__crypto_ahash_alg(alg),
@@ -2256,6 +2256,11 @@ static int talitos_cra_init(struct crypto_tfm *tfm)
2256 /* update context with ptr to dev */ 2256 /* update context with ptr to dev */
2257 ctx->dev = talitos_alg->dev; 2257 ctx->dev = talitos_alg->dev;
2258 2258
2259 /* assign SEC channel to tfm in round-robin fashion */
2260 priv = dev_get_drvdata(ctx->dev);
2261 ctx->ch = atomic_inc_return(&priv->last_chan) &
2262 (priv->num_channels - 1);
2263
2259 /* copy descriptor header template value */ 2264 /* copy descriptor header template value */
2260 ctx->desc_hdr_template = talitos_alg->algt.desc_hdr_template; 2265 ctx->desc_hdr_template = talitos_alg->algt.desc_hdr_template;
2261 2266