diff options
Diffstat (limited to 'drivers/staging/ccree/ssi_request_mgr.c')
-rw-r--r-- | drivers/staging/ccree/ssi_request_mgr.c | 195 |
1 files changed, 104 insertions, 91 deletions
diff --git a/drivers/staging/ccree/ssi_request_mgr.c b/drivers/staging/ccree/ssi_request_mgr.c index e5c2f92857f6..a8a7dc672d4c 100644 --- a/drivers/staging/ccree/ssi_request_mgr.c +++ b/drivers/staging/ccree/ssi_request_mgr.c @@ -49,7 +49,6 @@ struct ssi_request_mgr_handle { dma_addr_t dummy_comp_buff_dma; struct cc_hw_desc monitor_desc; - volatile unsigned long monitor_lock; #ifdef COMP_IN_WQ struct workqueue_struct *workq; struct delayed_work compwork; @@ -69,19 +68,19 @@ static void comp_work_handler(struct work_struct *work); void request_mgr_fini(struct ssi_drvdata *drvdata) { struct ssi_request_mgr_handle *req_mgr_h = drvdata->request_mgr_handle; + struct device *dev = drvdata_to_dev(drvdata); if (!req_mgr_h) return; /* Not allocated */ if (req_mgr_h->dummy_comp_buff_dma != 0) { - dma_free_coherent(&drvdata->plat_dev->dev, - sizeof(u32), req_mgr_h->dummy_comp_buff, + dma_free_coherent(dev, sizeof(u32), req_mgr_h->dummy_comp_buff, req_mgr_h->dummy_comp_buff_dma); } - SSI_LOG_DEBUG("max_used_hw_slots=%d\n", (req_mgr_h->hw_queue_size - + dev_dbg(dev, "max_used_hw_slots=%d\n", (req_mgr_h->hw_queue_size - req_mgr_h->min_free_hw_slots)); - SSI_LOG_DEBUG("max_used_sw_slots=%d\n", req_mgr_h->max_used_sw_slots); + dev_dbg(dev, "max_used_sw_slots=%d\n", req_mgr_h->max_used_sw_slots); #ifdef COMP_IN_WQ flush_workqueue(req_mgr_h->workq); @@ -98,6 +97,7 @@ void request_mgr_fini(struct ssi_drvdata *drvdata) int request_mgr_init(struct ssi_drvdata *drvdata) { struct ssi_request_mgr_handle *req_mgr_h; + struct device *dev = drvdata_to_dev(drvdata); int rc = 0; req_mgr_h = kzalloc(sizeof(*req_mgr_h), GFP_KERNEL); @@ -110,24 +110,24 @@ int request_mgr_init(struct ssi_drvdata *drvdata) spin_lock_init(&req_mgr_h->hw_lock); #ifdef COMP_IN_WQ - SSI_LOG_DEBUG("Initializing completion workqueue\n"); + dev_dbg(dev, "Initializing completion workqueue\n"); req_mgr_h->workq = create_singlethread_workqueue("arm_cc7x_wq"); if (unlikely(!req_mgr_h->workq)) { - SSI_LOG_ERR("Failed creating work queue\n"); + dev_err(dev, "Failed creating work queue\n"); rc = -ENOMEM; goto req_mgr_init_err; } INIT_DELAYED_WORK(&req_mgr_h->compwork, comp_work_handler); #else - SSI_LOG_DEBUG("Initializing completion tasklet\n"); + dev_dbg(dev, "Initializing completion tasklet\n"); tasklet_init(&req_mgr_h->comptask, comp_handler, (unsigned long)drvdata); #endif - req_mgr_h->hw_queue_size = READ_REGISTER(drvdata->cc_base + - CC_REG_OFFSET(CRY_KERNEL, DSCRPTR_QUEUE_SRAM_SIZE)); - SSI_LOG_DEBUG("hw_queue_size=0x%08X\n", req_mgr_h->hw_queue_size); + req_mgr_h->hw_queue_size = cc_ioread(drvdata, + CC_REG(DSCRPTR_QUEUE_SRAM_SIZE)); + dev_dbg(dev, "hw_queue_size=0x%08X\n", req_mgr_h->hw_queue_size); if (req_mgr_h->hw_queue_size < MIN_HW_QUEUE_SIZE) { - SSI_LOG_ERR("Invalid HW queue size = %u (Min. required is %u)\n", - req_mgr_h->hw_queue_size, MIN_HW_QUEUE_SIZE); + dev_err(dev, "Invalid HW queue size = %u (Min. required is %u)\n", + req_mgr_h->hw_queue_size, MIN_HW_QUEUE_SIZE); rc = -ENOMEM; goto req_mgr_init_err; } @@ -135,13 +135,12 @@ int request_mgr_init(struct ssi_drvdata *drvdata) req_mgr_h->max_used_sw_slots = 0; /* Allocate DMA word for "dummy" completion descriptor use */ - req_mgr_h->dummy_comp_buff = dma_alloc_coherent(&drvdata->plat_dev->dev, - sizeof(u32), + req_mgr_h->dummy_comp_buff = dma_alloc_coherent(dev, sizeof(u32), &req_mgr_h->dummy_comp_buff_dma, GFP_KERNEL); if (!req_mgr_h->dummy_comp_buff) { - SSI_LOG_ERR("Not enough memory to allocate DMA (%zu) dropped " - "buffer\n", sizeof(u32)); + dev_err(dev, "Not enough memory to allocate DMA (%zu) dropped buffer\n", + sizeof(u32)); rc = -ENOMEM; goto req_mgr_init_err; } @@ -168,17 +167,17 @@ static inline void enqueue_seq( int i; for (i = 0; i < seq_len; i++) { - writel_relaxed(seq[i].word[0], (volatile void __iomem *)(cc_base + CC_REG_OFFSET(CRY_KERNEL, DSCRPTR_QUEUE_WORD0))); - writel_relaxed(seq[i].word[1], (volatile void __iomem *)(cc_base + CC_REG_OFFSET(CRY_KERNEL, DSCRPTR_QUEUE_WORD0))); - writel_relaxed(seq[i].word[2], (volatile void __iomem *)(cc_base + CC_REG_OFFSET(CRY_KERNEL, DSCRPTR_QUEUE_WORD0))); - writel_relaxed(seq[i].word[3], (volatile void __iomem *)(cc_base + CC_REG_OFFSET(CRY_KERNEL, DSCRPTR_QUEUE_WORD0))); - writel_relaxed(seq[i].word[4], (volatile void __iomem *)(cc_base + CC_REG_OFFSET(CRY_KERNEL, DSCRPTR_QUEUE_WORD0))); + writel_relaxed(seq[i].word[0], (volatile void __iomem *)(cc_base + CC_REG(DSCRPTR_QUEUE_WORD0))); + writel_relaxed(seq[i].word[1], (volatile void __iomem *)(cc_base + CC_REG(DSCRPTR_QUEUE_WORD0))); + writel_relaxed(seq[i].word[2], (volatile void __iomem *)(cc_base + CC_REG(DSCRPTR_QUEUE_WORD0))); + writel_relaxed(seq[i].word[3], (volatile void __iomem *)(cc_base + CC_REG(DSCRPTR_QUEUE_WORD0))); + writel_relaxed(seq[i].word[4], (volatile void __iomem *)(cc_base + CC_REG(DSCRPTR_QUEUE_WORD0))); wmb(); - writel_relaxed(seq[i].word[5], (volatile void __iomem *)(cc_base + CC_REG_OFFSET(CRY_KERNEL, DSCRPTR_QUEUE_WORD0))); + writel_relaxed(seq[i].word[5], (volatile void __iomem *)(cc_base + CC_REG(DSCRPTR_QUEUE_WORD0))); #ifdef DX_DUMP_DESCS - SSI_LOG_DEBUG("desc[%02d]: 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n", i, - seq[i].word[0], seq[i].word[1], seq[i].word[2], - seq[i].word[3], seq[i].word[4], seq[i].word[5]); + dev_dbg(dev, "desc[%02d]: 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n", + i, seq[i].word[0], seq[i].word[1], seq[i].word[2], + seq[i].word[3], seq[i].word[4], seq[i].word[5]); #endif } } @@ -198,11 +197,12 @@ static void request_mgr_complete(struct device *dev, void *dx_compl_h, void __io } static inline int request_mgr_queues_status_check( + struct ssi_drvdata *drvdata, struct ssi_request_mgr_handle *req_mgr_h, - void __iomem *cc_base, unsigned int total_seq_len) { unsigned long poll_queue; + struct device *dev = drvdata_to_dev(drvdata); /* SW queue is checked only once as it will not * be chaned during the poll becasue the spinlock_bh @@ -211,8 +211,8 @@ static inline int request_mgr_queues_status_check( if (unlikely(((req_mgr_h->req_queue_head + 1) & (MAX_REQUEST_QUEUE_SIZE - 1)) == req_mgr_h->req_queue_tail)) { - SSI_LOG_ERR("SW FIFO is full. req_queue_head=%d sw_fifo_len=%d\n", - req_mgr_h->req_queue_head, MAX_REQUEST_QUEUE_SIZE); + dev_err(dev, "SW FIFO is full. req_queue_head=%d sw_fifo_len=%d\n", + req_mgr_h->req_queue_head, MAX_REQUEST_QUEUE_SIZE); return -EBUSY; } @@ -222,8 +222,7 @@ static inline int request_mgr_queues_status_check( /* Wait for space in HW queue. Poll constant num of iterations. */ for (poll_queue = 0; poll_queue < SSI_MAX_POLL_ITER ; poll_queue++) { req_mgr_h->q_free_slots = - CC_HAL_READ_REGISTER(CC_REG_OFFSET(CRY_KERNEL, - DSCRPTR_QUEUE_CONTENT)); + cc_ioread(drvdata, CC_REG(DSCRPTR_QUEUE_CONTENT)); if (unlikely(req_mgr_h->q_free_slots < req_mgr_h->min_free_hw_slots)) { req_mgr_h->min_free_hw_slots = req_mgr_h->q_free_slots; @@ -234,16 +233,13 @@ static inline int request_mgr_queues_status_check( return 0; } - SSI_LOG_DEBUG("HW FIFO is full. q_free_slots=%d total_seq_len=%d\n", - req_mgr_h->q_free_slots, total_seq_len); + dev_dbg(dev, "HW FIFO is full. q_free_slots=%d total_seq_len=%d\n", + req_mgr_h->q_free_slots, total_seq_len); } /* No room in the HW queue try again later */ - SSI_LOG_DEBUG("HW FIFO full, timeout. req_queue_head=%d " - "sw_fifo_len=%d q_free_slots=%d total_seq_len=%d\n", - req_mgr_h->req_queue_head, - MAX_REQUEST_QUEUE_SIZE, - req_mgr_h->q_free_slots, - total_seq_len); + dev_dbg(dev, "HW FIFO full, timeout. req_queue_head=%d sw_fifo_len=%d q_free_slots=%d total_seq_len=%d\n", + req_mgr_h->req_queue_head, MAX_REQUEST_QUEUE_SIZE, + req_mgr_h->q_free_slots, total_seq_len); return -EAGAIN; } @@ -270,16 +266,17 @@ int send_request( unsigned int iv_seq_len = 0; unsigned int total_seq_len = len; /*initial sequence length*/ struct cc_hw_desc iv_seq[SSI_IVPOOL_SEQ_LEN]; + struct device *dev = drvdata_to_dev(drvdata); int rc; unsigned int max_required_seq_len = (total_seq_len + ((ssi_req->ivgen_dma_addr_len == 0) ? 0 : SSI_IVPOOL_SEQ_LEN) + - ((is_dout == 0) ? 1 : 0)); + (!is_dout ? 1 : 0)); #if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP) - rc = ssi_power_mgr_runtime_get(&drvdata->plat_dev->dev); + rc = ssi_power_mgr_runtime_get(dev); if (rc != 0) { - SSI_LOG_ERR("ssi_power_mgr_runtime_get returned %x\n", rc); + dev_err(dev, "ssi_power_mgr_runtime_get returned %x\n", rc); return rc; } #endif @@ -291,7 +288,7 @@ int send_request( * in case iv gen add the max size and in case of no dout add 1 * for the internal completion descriptor */ - rc = request_mgr_queues_status_check(req_mgr_h, cc_base, + rc = request_mgr_queues_status_check(drvdata, req_mgr_h, max_required_seq_len); if (likely(rc == 0)) /* There is enough place in the queue */ @@ -304,7 +301,7 @@ int send_request( * (SW queue is full) */ #if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP) - ssi_power_mgr_runtime_put_suspend(&drvdata->plat_dev->dev); + ssi_power_mgr_runtime_put_suspend(dev); #endif return rc; } @@ -324,12 +321,12 @@ int send_request( } if (ssi_req->ivgen_dma_addr_len > 0) { - SSI_LOG_DEBUG("Acquire IV from pool into %d DMA addresses %pad, %pad, %pad, IV-size=%u\n", - ssi_req->ivgen_dma_addr_len, - ssi_req->ivgen_dma_addr[0], - ssi_req->ivgen_dma_addr[1], - ssi_req->ivgen_dma_addr[2], - ssi_req->ivgen_size); + dev_dbg(dev, "Acquire IV from pool into %d DMA addresses %pad, %pad, %pad, IV-size=%u\n", + ssi_req->ivgen_dma_addr_len, + &ssi_req->ivgen_dma_addr[0], + &ssi_req->ivgen_dma_addr[1], + &ssi_req->ivgen_dma_addr[2], + ssi_req->ivgen_size); /* Acquire IV from pool */ rc = ssi_ivgen_getiv(drvdata, ssi_req->ivgen_dma_addr, @@ -337,10 +334,10 @@ int send_request( ssi_req->ivgen_size, iv_seq, &iv_seq_len); if (unlikely(rc != 0)) { - SSI_LOG_ERR("Failed to generate IV (rc=%d)\n", rc); + dev_err(dev, "Failed to generate IV (rc=%d)\n", rc); spin_unlock_bh(&req_mgr_h->hw_lock); #if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP) - ssi_power_mgr_runtime_put_suspend(&drvdata->plat_dev->dev); + ssi_power_mgr_runtime_put_suspend(dev); #endif return rc; } @@ -357,7 +354,7 @@ int send_request( req_mgr_h->req_queue_head = (req_mgr_h->req_queue_head + 1) & (MAX_REQUEST_QUEUE_SIZE - 1); /* TODO: Use circ_buf.h ? */ - SSI_LOG_DEBUG("Enqueue request head=%u\n", req_mgr_h->req_queue_head); + dev_dbg(dev, "Enqueue request head=%u\n", req_mgr_h->req_queue_head); #ifdef FLUSH_CACHE_ALL flush_cache_all(); @@ -369,11 +366,16 @@ int send_request( enqueue_seq(cc_base, &req_mgr_h->compl_desc, (is_dout ? 0 : 1)); if (unlikely(req_mgr_h->q_free_slots < total_seq_len)) { - /*This means that there was a problem with the resume*/ - BUG(); + /* This situation should never occur. Maybe indicating problem + * with resuming power. Set the free slot count to 0 and hope + * for the best. + */ + dev_err(dev, "HW free slot count mismatch."); + req_mgr_h->q_free_slots = 0; + } else { + /* Update the free slots in HW queue */ + req_mgr_h->q_free_slots -= total_seq_len; } - /* Update the free slots in HW queue */ - req_mgr_h->q_free_slots -= total_seq_len; spin_unlock_bh(&req_mgr_h->hw_lock); @@ -383,10 +385,9 @@ int send_request( */ wait_for_completion(&ssi_req->seq_compl); return 0; - } else { - /* Operation still in process */ - return -EINPROGRESS; } + /* Operation still in process */ + return -EINPROGRESS; } /*! @@ -409,7 +410,8 @@ int send_request_init( int rc = 0; /* Wait for space in HW and SW FIFO. Poll for as much as FIFO_TIMEOUT. */ - rc = request_mgr_queues_status_check(req_mgr_h, cc_base, total_seq_len); + rc = request_mgr_queues_status_check(drvdata, req_mgr_h, + total_seq_len); if (unlikely(rc != 0)) return rc; @@ -418,8 +420,8 @@ int send_request_init( enqueue_seq(cc_base, desc, len); /* Update the free slots in HW queue */ - req_mgr_h->q_free_slots = CC_HAL_READ_REGISTER(CC_REG_OFFSET(CRY_KERNEL, - DSCRPTR_QUEUE_CONTENT)); + req_mgr_h->q_free_slots = + cc_ioread(drvdata, CC_REG(DSCRPTR_QUEUE_CONTENT)); return 0; } @@ -448,7 +450,7 @@ static void comp_work_handler(struct work_struct *work) static void proc_completions(struct ssi_drvdata *drvdata) { struct ssi_crypto_req *ssi_req; - struct platform_device *plat_dev = drvdata->plat_dev; + struct device *dev = drvdata_to_dev(drvdata); struct ssi_request_mgr_handle *request_mgr_handle = drvdata->request_mgr_handle; #if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP) @@ -460,8 +462,13 @@ static void proc_completions(struct ssi_drvdata *drvdata) /* Dequeue request */ if (unlikely(request_mgr_handle->req_queue_head == request_mgr_handle->req_queue_tail)) { - SSI_LOG_ERR("Request queue is empty req_queue_head==req_queue_tail==%u\n", request_mgr_handle->req_queue_head); - BUG(); + /* We are supposed to handle a completion but our + * queue is empty. This is not normal. Return and + * hope for the best. + */ + dev_err(dev, "Request queue is empty head == tail %u\n", + request_mgr_handle->req_queue_head); + break; } ssi_req = &request_mgr_handle->req_queue[request_mgr_handle->req_queue_tail]; @@ -476,39 +483,40 @@ static void proc_completions(struct ssi_drvdata *drvdata) u32 axi_err; int i; - SSI_LOG_INFO("Delay\n"); + dev_info(dev, "Delay\n"); for (i = 0; i < 1000000; i++) - axi_err = READ_REGISTER(drvdata->cc_base + CC_REG_OFFSET(CRY_KERNEL, AXIM_MON_ERR)); + axi_err = cc_ioread(drvdata, + CC_REG(AXIM_MON_ERR)); } #endif /* COMPLETION_DELAY */ if (likely(ssi_req->user_cb)) - ssi_req->user_cb(&plat_dev->dev, ssi_req->user_arg, drvdata->cc_base); + ssi_req->user_cb(dev, ssi_req->user_arg, + drvdata->cc_base); request_mgr_handle->req_queue_tail = (request_mgr_handle->req_queue_tail + 1) & (MAX_REQUEST_QUEUE_SIZE - 1); - SSI_LOG_DEBUG("Dequeue request tail=%u\n", request_mgr_handle->req_queue_tail); - SSI_LOG_DEBUG("Request completed. axi_completed=%d\n", request_mgr_handle->axi_completed); + dev_dbg(dev, "Dequeue request tail=%u\n", + request_mgr_handle->req_queue_tail); + dev_dbg(dev, "Request completed. axi_completed=%d\n", + request_mgr_handle->axi_completed); #if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP) - rc = ssi_power_mgr_runtime_put_suspend(&plat_dev->dev); + rc = ssi_power_mgr_runtime_put_suspend(dev); if (rc != 0) - SSI_LOG_ERR("Failed to set runtime suspension %d\n", rc); + dev_err(dev, "Failed to set runtime suspension %d\n", + rc); #endif } } -static inline u32 cc_axi_comp_count(void __iomem *cc_base) +static inline u32 cc_axi_comp_count(struct ssi_drvdata *drvdata) { - /* The CC_HAL_READ_REGISTER macro implictly requires and uses - * a base MMIO register address variable named cc_base. - */ return FIELD_GET(AXIM_MON_COMP_VALUE, - CC_HAL_READ_REGISTER(AXIM_MON_BASE_OFFSET)); + cc_ioread(drvdata, CC_REG(AXIM_MON_COMP))); } /* Deferred service handler, run as interrupt-fired tasklet */ static void comp_handler(unsigned long devarg) { struct ssi_drvdata *drvdata = (struct ssi_drvdata *)devarg; - void __iomem *cc_base = drvdata->cc_base; struct ssi_request_mgr_handle *request_mgr_handle = drvdata->request_mgr_handle; @@ -517,12 +525,16 @@ static void comp_handler(unsigned long devarg) irq = (drvdata->irq & SSI_COMP_IRQ_MASK); if (irq & SSI_COMP_IRQ_MASK) { - /* To avoid the interrupt from firing as we unmask it, we clear it now */ - CC_HAL_WRITE_REGISTER(CC_REG_OFFSET(HOST_RGF, HOST_ICR), SSI_COMP_IRQ_MASK); + /* To avoid the interrupt from firing as we unmask it, + * we clear it now + */ + cc_iowrite(drvdata, CC_REG(HOST_ICR), SSI_COMP_IRQ_MASK); - /* Avoid race with above clear: Test completion counter once more */ + /* Avoid race with above clear: Test completion counter + * once more + */ request_mgr_handle->axi_completed += - cc_axi_comp_count(cc_base); + cc_axi_comp_count(drvdata); while (request_mgr_handle->axi_completed) { do { @@ -531,20 +543,21 @@ static void comp_handler(unsigned long devarg) * request_mgr_handle->axi_completed is 0. */ request_mgr_handle->axi_completed = - cc_axi_comp_count(cc_base); + cc_axi_comp_count(drvdata); } while (request_mgr_handle->axi_completed > 0); - /* To avoid the interrupt from firing as we unmask it, we clear it now */ - CC_HAL_WRITE_REGISTER(CC_REG_OFFSET(HOST_RGF, HOST_ICR), SSI_COMP_IRQ_MASK); + cc_iowrite(drvdata, CC_REG(HOST_ICR), + SSI_COMP_IRQ_MASK); - /* Avoid race with above clear: Test completion counter once more */ request_mgr_handle->axi_completed += - cc_axi_comp_count(cc_base); + cc_axi_comp_count(drvdata); } } - /* after verifing that there is nothing to do, Unmask AXI completion interrupt */ - CC_HAL_WRITE_REGISTER(CC_REG_OFFSET(HOST_RGF, HOST_IMR), - CC_HAL_READ_REGISTER(CC_REG_OFFSET(HOST_RGF, HOST_IMR)) & ~irq); + /* after verifing that there is nothing to do, + * unmask AXI completion interrupt + */ + cc_iowrite(drvdata, CC_REG(HOST_IMR), + cc_ioread(drvdata, CC_REG(HOST_IMR)) & ~irq); } /* |