aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGary R Hook <gary.hook@amd.com>2016-10-18 18:33:37 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2016-10-24 23:08:23 -0400
commit103600ab966a2f02d8986bbfdf87b762b1c6a06d (patch)
tree35cca53e7805aaf34f5d4432cd53ea2def92f811
parentec9b70df75b3600ca20338198a43173f23e6bb9b (diff)
crypto: ccp - Clean up the LSB slot allocation code
Fix a few problems revealed by testing: verify consistent units, especially in public slot allocation. Percolate some common initialization code up to a common routine. Add some comments. Signed-off-by: Gary R Hook <gary.hook@amd.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--drivers/crypto/ccp/ccp-dev-v3.c4
-rw-r--r--drivers/crypto/ccp/ccp-dev-v5.c20
-rw-r--r--drivers/crypto/ccp/ccp-dev.c4
3 files changed, 16 insertions, 12 deletions
diff --git a/drivers/crypto/ccp/ccp-dev-v3.c b/drivers/crypto/ccp/ccp-dev-v3.c
index 8d2dbacc6161..7bc09989e18a 100644
--- a/drivers/crypto/ccp/ccp-dev-v3.c
+++ b/drivers/crypto/ccp/ccp-dev-v3.c
@@ -404,10 +404,6 @@ static int ccp_init(struct ccp_device *ccp)
404 goto e_pool; 404 goto e_pool;
405 } 405 }
406 406
407 /* Initialize the queues used to wait for KSB space and suspend */
408 init_waitqueue_head(&ccp->sb_queue);
409 init_waitqueue_head(&ccp->suspend_queue);
410
411 dev_dbg(dev, "Starting threads...\n"); 407 dev_dbg(dev, "Starting threads...\n");
412 /* Create a kthread for each queue */ 408 /* Create a kthread for each queue */
413 for (i = 0; i < ccp->cmd_q_count; i++) { 409 for (i = 0; i < ccp->cmd_q_count; i++) {
diff --git a/drivers/crypto/ccp/ccp-dev-v5.c b/drivers/crypto/ccp/ccp-dev-v5.c
index faf3cb3ddce2..ff7816a2b8af 100644
--- a/drivers/crypto/ccp/ccp-dev-v5.c
+++ b/drivers/crypto/ccp/ccp-dev-v5.c
@@ -21,6 +21,12 @@
21 21
22#include "ccp-dev.h" 22#include "ccp-dev.h"
23 23
24/* Allocate the requested number of contiguous LSB slots
25 * from the LSB bitmap. Look in the private range for this
26 * queue first; failing that, check the public area.
27 * If no space is available, wait around.
28 * Return: first slot number
29 */
24static u32 ccp_lsb_alloc(struct ccp_cmd_queue *cmd_q, unsigned int count) 30static u32 ccp_lsb_alloc(struct ccp_cmd_queue *cmd_q, unsigned int count)
25{ 31{
26 struct ccp_device *ccp; 32 struct ccp_device *ccp;
@@ -50,7 +56,7 @@ static u32 ccp_lsb_alloc(struct ccp_cmd_queue *cmd_q, unsigned int count)
50 bitmap_set(ccp->lsbmap, start, count); 56 bitmap_set(ccp->lsbmap, start, count);
51 57
52 mutex_unlock(&ccp->sb_mutex); 58 mutex_unlock(&ccp->sb_mutex);
53 return start * LSB_ITEM_SIZE; 59 return start;
54 } 60 }
55 61
56 ccp->sb_avail = 0; 62 ccp->sb_avail = 0;
@@ -63,17 +69,18 @@ static u32 ccp_lsb_alloc(struct ccp_cmd_queue *cmd_q, unsigned int count)
63 } 69 }
64} 70}
65 71
72/* Free a number of LSB slots from the bitmap, starting at
73 * the indicated starting slot number.
74 */
66static void ccp_lsb_free(struct ccp_cmd_queue *cmd_q, unsigned int start, 75static void ccp_lsb_free(struct ccp_cmd_queue *cmd_q, unsigned int start,
67 unsigned int count) 76 unsigned int count)
68{ 77{
69 int lsbno = start / LSB_SIZE;
70
71 if (!start) 78 if (!start)
72 return; 79 return;
73 80
74 if (cmd_q->lsb == lsbno) { 81 if (cmd_q->lsb == start) {
75 /* An entry from the private LSB */ 82 /* An entry from the private LSB */
76 bitmap_clear(cmd_q->lsbmap, start % LSB_SIZE, count); 83 bitmap_clear(cmd_q->lsbmap, start, count);
77 } else { 84 } else {
78 /* From the shared LSBs */ 85 /* From the shared LSBs */
79 struct ccp_device *ccp = cmd_q->ccp; 86 struct ccp_device *ccp = cmd_q->ccp;
@@ -751,9 +758,6 @@ static int ccp5_init(struct ccp_device *ccp)
751 goto e_pool; 758 goto e_pool;
752 } 759 }
753 760
754 /* Initialize the queue used to suspend */
755 init_waitqueue_head(&ccp->suspend_queue);
756
757 dev_dbg(dev, "Loading LSB map...\n"); 761 dev_dbg(dev, "Loading LSB map...\n");
758 /* Copy the private LSB mask to the public registers */ 762 /* Copy the private LSB mask to the public registers */
759 status_lo = ioread32(ccp->io_regs + LSB_PRIVATE_MASK_LO_OFFSET); 763 status_lo = ioread32(ccp->io_regs + LSB_PRIVATE_MASK_LO_OFFSET);
diff --git a/drivers/crypto/ccp/ccp-dev.c b/drivers/crypto/ccp/ccp-dev.c
index c25515a80d33..511ab042b5e7 100644
--- a/drivers/crypto/ccp/ccp-dev.c
+++ b/drivers/crypto/ccp/ccp-dev.c
@@ -478,6 +478,10 @@ struct ccp_device *ccp_alloc_struct(struct device *dev)
478 ccp->sb_count = KSB_COUNT; 478 ccp->sb_count = KSB_COUNT;
479 ccp->sb_start = 0; 479 ccp->sb_start = 0;
480 480
481 /* Initialize the wait queues */
482 init_waitqueue_head(&ccp->sb_queue);
483 init_waitqueue_head(&ccp->suspend_queue);
484
481 ccp->ord = ccp_increment_unit_ordinal(); 485 ccp->ord = ccp_increment_unit_ordinal();
482 snprintf(ccp->name, MAX_CCP_NAME_LEN, "ccp-%u", ccp->ord); 486 snprintf(ccp->name, MAX_CCP_NAME_LEN, "ccp-%u", ccp->ord);
483 snprintf(ccp->rngname, MAX_CCP_NAME_LEN, "ccp-%u-rng", ccp->ord); 487 snprintf(ccp->rngname, MAX_CCP_NAME_LEN, "ccp-%u-rng", ccp->ord);