aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/crypto/ccp/ccp-dev-v5.c
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 /drivers/crypto/ccp/ccp-dev-v5.c
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>
Diffstat (limited to 'drivers/crypto/ccp/ccp-dev-v5.c')
-rw-r--r--drivers/crypto/ccp/ccp-dev-v5.c20
1 files changed, 12 insertions, 8 deletions
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);