/* Free the resources of crypto-engine */
crypto_engine_exit(jrpriv->engine);
}
/* * Put the CAAM in quiesce, ie stop * * Must be called with itr disabled
*/ staticint caam_jr_stop_processing(struct device *dev, u32 jrcr_bits)
{ struct caam_drv_private_jr *jrp = dev_get_drvdata(dev); unsignedint timeout = 100000;
/* Check the current status */ if (rd_reg32(&jrp->rregs->jrintstatus) & JRINT_ERR_HALT_INPROGRESS) goto wait_quiesce_completion;
/* Reset the field */
clrsetbits_32(&jrp->rregs->jrintstatus, JRINT_ERR_HALT_MASK, 0);
/* initiate flush / park (required prior to reset) */
wr_reg32(&jrp->rregs->jrcommand, jrcr_bits);
wait_quiesce_completion: while (((rd_reg32(&jrp->rregs->jrintstatus) & JRINT_ERR_HALT_MASK) ==
JRINT_ERR_HALT_INPROGRESS) && --timeout)
cpu_relax();
if ((rd_reg32(&jrp->rregs->jrintstatus) & JRINT_ERR_HALT_MASK) !=
JRINT_ERR_HALT_COMPLETE || timeout == 0) {
dev_err(dev, "failed to flush job ring %d\n", jrp->ridx); return -EIO;
}
return 0;
}
/* * Flush the job ring, so the jobs running will be stopped, jobs queued will be * invalidated and the CAAM will no longer fetch fron input ring. * * Must be called with itr disabled
*/ staticint caam_jr_flush(struct device *dev)
{ return caam_jr_stop_processing(dev, JRCR_RESET);
}
/* The resume can be used after a park or a flush if CAAM has not been reset */ staticint caam_jr_restart_processing(struct device *dev)
{ struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
u32 halt_status = rd_reg32(&jrp->rregs->jrintstatus) &
JRINT_ERR_HALT_MASK;
/* Check that the flush/park is completed */ if (halt_status != JRINT_ERR_HALT_COMPLETE) return -1;
/* Resume processing of jobs */
clrsetbits_32(&jrp->rregs->jrintstatus, 0, JRINT_ERR_HALT_COMPLETE);
return 0;
}
staticint caam_reset_hw_jr(struct device *dev)
{ struct caam_drv_private_jr *jrp = dev_get_drvdata(dev); unsignedint timeout = 100000; int err; /* * mask interrupts since we are going to poll * for reset completion status
*/
clrsetbits_32(&jrp->rregs->rconfig_lo, 0, JRCFG_IMSK);
err = caam_jr_flush(dev); if (err) return err;
/* * If a job ring is still allocated there is trouble ahead. Once * caam_jr_remove() returned, jrpriv will be freed and the registers * will get unmapped. So any user of such a job ring will probably * crash.
*/ if (atomic_read(&jrpriv->tfm_count)) {
dev_alert(jrdev, "Device is busy; consumers might start to crash\n"); return;
}
/* Remove the node from Physical JobR list maintained by driver */
spin_lock(&driver_data.jr_alloc_lock);
list_del(&jrpriv->list_node);
spin_unlock(&driver_data.jr_alloc_lock);
/* Release ring */
ret = caam_jr_shutdown(jrdev); if (ret)
dev_err(jrdev, "Failed to shut down job ring\n");
}
/* * Check the output ring for ready responses, kick * tasklet if jobs done.
*/
irqstate = rd_reg32(&jrp->rregs->jrintstatus); if (!(irqstate & JRINT_JR_INT)) return IRQ_NONE;
/* * If JobR error, we got more development work to do * Flag a bug now, but we really need to shut down and * restart the queue (and fix code).
*/ if (irqstate & JRINT_JR_ERROR) {
dev_err(dev, "job ring error: irqstate: %08x\n", irqstate);
BUG();
}
for (i = 0; CIRC_CNT(head, tail + i, JOBR_DEPTH) >= 1; i++) {
sw_idx = (tail + i) & (JOBR_DEPTH - 1);
if (jr_outentry_desc(jrp->outring, hw_idx) ==
caam_dma_to_cpu(jrp->entinfo[sw_idx].desc_addr_dma)) break; /* found */
} /* we should never fail to find a matching descriptor */
BUG_ON(CIRC_CNT(head, tail + i, JOBR_DEPTH) <= 0);
/* Unmap just-run descriptor so we can post-process */
dma_unmap_single(dev,
caam_dma_to_cpu(jr_outentry_desc(jrp->outring,
hw_idx)),
jrp->entinfo[sw_idx].desc_size,
DMA_TO_DEVICE);
/* mark completed, avoid matching on a recycled desc addr */
jrp->entinfo[sw_idx].desc_addr_dma = 0;
/* * if this job completed out-of-order, do not increment * the tail. Otherwise, increment tail by 1 plus the * number of subsequent jobs already completed out-of-order
*/ if (sw_idx == tail) { do {
tail = (tail + 1) & (JOBR_DEPTH - 1);
} while (CIRC_CNT(head, tail, JOBR_DEPTH) >= 1 &&
jrp->entinfo[tail].desc_addr_dma == 0);
/** * caam_jr_alloc() - Alloc a job ring for someone to use as needed. * * returns : pointer to the newly allocated physical * JobR dev can be written to if successful.
**/ struct device *caam_jr_alloc(void)
{ struct caam_drv_private_jr *jrpriv, *min_jrpriv = NULL; struct device *dev = ERR_PTR(-ENODEV); int min_tfm_cnt = INT_MAX; int tfm_cnt;
spin_lock(&driver_data.jr_alloc_lock);
if (list_empty(&driver_data.jr_list)) {
spin_unlock(&driver_data.jr_alloc_lock); return ERR_PTR(-ENODEV);
}
if (min_jrpriv) {
atomic_inc(&min_jrpriv->tfm_count);
dev = min_jrpriv->dev;
}
spin_unlock(&driver_data.jr_alloc_lock);
return dev;
}
EXPORT_SYMBOL(caam_jr_alloc);
/** * caam_jr_free() - Free the Job Ring * @rdev: points to the dev that identifies the Job ring to * be released.
**/ void caam_jr_free(struct device *rdev)
{ struct caam_drv_private_jr *jrpriv = dev_get_drvdata(rdev);
/** * caam_jr_enqueue() - Enqueue a job descriptor head. Returns -EINPROGRESS * if OK, -ENOSPC if the queue is full, -EIO if it cannot map the caller's * descriptor. * @dev: struct device of the job ring to be used * @desc: points to a job descriptor that execute our request. All * descriptors (and all referenced data) must be in a DMAable * region, and all data references must be physical addresses * accessible to CAAM (i.e. within a PAMU window granted * to it). * @cbk: pointer to a callback function to be invoked upon completion * of this request. This has the form: * callback(struct device *dev, u32 *desc, u32 stat, void *arg) * where: * dev: contains the job ring device that processed this * response. * desc: descriptor that initiated the request, same as * "desc" being argued to caam_jr_enqueue(). * status: untranslated status received from CAAM. See the * reference manual for a detailed description of * error meaning, or see the JRSTA definitions in the * register header file * areq: optional pointer to an argument passed with the * original request * @areq: optional pointer to a user argument for use at callback * time.
**/ int caam_jr_enqueue(struct device *dev, u32 *desc, void (*cbk)(struct device *dev, u32 *desc,
u32 status, void *areq), void *areq)
{ struct caam_drv_private_jr *jrp = dev_get_drvdata(dev); struct caam_jrentry_info *head_entry; int head, tail, desc_size;
dma_addr_t desc_dma;
/* * Guarantee that the descriptor's DMA address has been written to * the next slot in the ring before the write index is updated, since * other cores may update this index independently. * * Under heavy DDR load, smp_wmb() or dma_wmb() fail to make the input * ring be updated before the CAAM starts reading it. So, CAAM will * process, again, an old descriptor address and will put it in the * output ring. This will make caam_jr_dequeue() to fail, since this * old descriptor is not in the software ring. * To fix this, use wmb() which works on the full system instead of * inner/outer shareable domains.
*/
wmb();
jrp->head = (head + 1) & (JOBR_DEPTH - 1);
/* * Ensure that all job information has been written before * notifying CAAM that a new job was added to the input ring * using a memory barrier. The wr_reg32() uses api iowrite32() * to do the register write. iowrite32() issues a memory barrier * before the write operation.
*/
wr_reg32(&jrp->rregs->inpring_jobadd, 1);
jrp->inpring_avail--; if (!jrp->inpring_avail)
jrp->inpring_avail = rd_reg32(&jrp->rregs->inpring_avail);
/* Remove the node from Physical JobR list maintained by driver */
spin_lock(&driver_data.jr_alloc_lock);
list_del(&jrpriv->list_node);
spin_unlock(&driver_data.jr_alloc_lock);
if (jrpriv->hwrng)
caam_rng_exit(dev->parent);
if (ctrlpriv->caam_off_during_pm) { int err;
tasklet_disable(&jrpriv->irqtask);
/* mask itr to call flush */
clrsetbits_32(&jrpriv->rregs->rconfig_lo, 0, JRCFG_IMSK);
/* Invalid job in process */
err = caam_jr_flush(dev); if (err) {
dev_err(dev, "Failed to flush\n"); return err;
}
/* Dequeing jobs flushed */
caam_jr_dequeue((unsignedlong)&suspend_params);
/* Save state */
caam_jr_get_hw_state(dev);
} elseif (device_may_wakeup(&pdev->dev)) {
enable_irq_wake(jrpriv->irq);
}
if (ctrlpriv->caam_off_during_pm) {
u64 inp_addr; int err;
/* * Check if the CAAM has been resetted checking the address of * the input ring
*/
inp_addr = rd_reg64(&jrpriv->rregs->inpring_base); if (inp_addr != 0) { /* JR still has some configuration */ if (inp_addr == jrpriv->state.inpbusaddr) { /* JR has not been resetted */
err = caam_jr_restart_processing(dev); if (err) {
dev_err(dev, "Restart processing failed\n"); return err;
}
goto add_jr;
} elseif (ctrlpriv->optee_en) { /* JR has been used by OPTEE, reset it */
err = caam_reset_hw_jr(dev); if (err) {
dev_err(dev, "Failed to reset JR\n"); return err;
}
} else { /* No explanation, return error */ return -EIO;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.