/* need to have at least one empty spot in the queue */ for (i = 0; i < lldev->nr_tres - 1; i++) { if (atomic_add_unless(&lldev->trepool[i].allocated, 1, 1)) break;
}
/* * Multiple TREs may be queued and waiting in the pending queue.
*/ staticvoid hidma_ll_tre_complete(struct tasklet_struct *t)
{ struct hidma_lldev *lldev = from_tasklet(lldev, t, task); struct hidma_tre *tre;
while (kfifo_out(&lldev->handoff_fifo, &tre, 1)) { /* call the user if it has been read by the hardware */ if (tre->callback)
tre->callback(tre->data);
}
}
tre_iterator = lldev->tre_processed_off;
tre = lldev->pending_tre_list[tre_iterator / HIDMA_TRE_SIZE]; if (!tre) {
spin_unlock_irqrestore(&lldev->lock, flags);
dev_warn(lldev->dev, "tre_index [%d] and tre out of sync\n",
tre_iterator / HIDMA_TRE_SIZE); return -EINVAL;
}
lldev->pending_tre_list[tre->tre_index] = NULL;
/* * Keep track of pending TREs that SW is expecting to receive * from HW. We got one now. Decrement our counter.
*/ if (atomic_dec_return(&lldev->pending_tre_count) < 0) {
dev_warn(lldev->dev, "tre count mismatch on completion");
atomic_set(&lldev->pending_tre_count, 0);
}
/* * Called to handle the interrupt for the channel. * Return a positive number if TRE or EVRE were consumed on this run. * Return a positive number if there are pending TREs or EVREs. * Return 0 if there is nothing to consume or no pending TREs/EVREs found.
*/ staticint hidma_handle_tre_completion(struct hidma_lldev *lldev)
{
u32 evre_ring_size = lldev->evre_ring_size;
u32 err_info, err_code, evre_write_off;
u32 evre_iterator;
u32 num_completed = 0;
/* * By the time control reaches here the number of EVREs and TREs * may not match. Only consume the ones that hardware told us.
*/ while ((evre_iterator != evre_write_off)) {
u32 *current_evre = lldev->evre_ring + evre_iterator;
u32 cfg;
/* * Read the new event descriptor written by the HW. * As we are processing the delivered events, other events * get queued to the SW for processing.
*/
evre_write_off =
readl_relaxed(lldev->evca + HIDMA_EVCA_WRITE_PTR_REG);
num_completed++;
/* * An error interrupt might have arrived while we are processing * the completed interrupt.
*/ if (!hidma_ll_isenabled(lldev)) break;
}
/* record the last processed tre offset */
lldev->evre_processed_off = evre_read_off;
}
return num_completed;
}
void hidma_cleanup_pending_tre(struct hidma_lldev *lldev, u8 err_info,
u8 err_code)
{ while (atomic_read(&lldev->pending_tre_count)) { if (hidma_post_completed(lldev, err_info, err_code)) break;
}
}
staticint hidma_ll_reset(struct hidma_lldev *lldev)
{
u32 val; int ret;
val = readl(lldev->trca + HIDMA_TRCA_CTRLSTS_REG);
val &= ~(HIDMA_CH_CONTROL_MASK << 16);
val |= HIDMA_CH_RESET << 16;
writel(val, lldev->trca + HIDMA_TRCA_CTRLSTS_REG);
/* * Delay 10ms after reset to allow DMA logic to quiesce. * Do a polled read up to 1ms and 10ms maximum.
*/
ret = readl_poll_timeout(lldev->trca + HIDMA_TRCA_CTRLSTS_REG, val,
HIDMA_CH_STATE(val) == HIDMA_CH_DISABLED,
1000, 10000); if (ret) {
dev_err(lldev->dev, "transfer channel did not reset\n"); return ret;
}
val = readl(lldev->evca + HIDMA_EVCA_CTRLSTS_REG);
val &= ~(HIDMA_CH_CONTROL_MASK << 16);
val |= HIDMA_CH_RESET << 16;
writel(val, lldev->evca + HIDMA_EVCA_CTRLSTS_REG);
/* * Delay 10ms after reset to allow DMA logic to quiesce. * Do a polled read up to 1ms and 10ms maximum.
*/
ret = readl_poll_timeout(lldev->evca + HIDMA_EVCA_CTRLSTS_REG, val,
HIDMA_CH_STATE(val) == HIDMA_CH_DISABLED,
1000, 10000); if (ret) return ret;
/* * The interrupt handler for HIDMA will try to consume as many pending * EVRE from the event queue as possible. Each EVRE has an associated * TRE that holds the user interface parameters. EVRE reports the * result of the transaction. Hardware guarantees ordering between EVREs * and TREs. We use last processed offset to figure out which TRE is * associated with which EVRE. If two TREs are consumed by HW, the EVREs * are in order in the event ring. * * This handler will do a one pass for consuming EVREs. Other EVREs may * be delivered while we are working. It will try to consume incoming * EVREs one more time and return. * * For unprocessed EVREs, hardware will trigger another interrupt until * all the interrupt bits are cleared. * * Hardware guarantees that by the time interrupt is observed, all data * transactions in flight are delivered to their respective places and * are visible to the CPU. * * On demand paging for IOMMU is only supported for PCIe via PRI * (Page Request Interface) not for HIDMA. All other hardware instances * including HIDMA work on pinned DMA addresses. * * HIDMA is not aware of IOMMU presence since it follows the DMA API. All * IOMMU latency will be built into the data movement time. By the time * interrupt happens, IOMMU lookups + data movement has already taken place. * * While the first read in a typical PCI endpoint ISR flushes all outstanding * requests traditionally to the destination, this concept does not apply * here for this HW.
*/ staticvoid hidma_ll_int_handler_internal(struct hidma_lldev *lldev, int cause)
{ unsignedlong irqflags;
if (cause & HIDMA_ERR_INT_MASK) {
dev_err(lldev->dev, "error 0x%x, disabling...\n",
cause);
/* Clear out pending interrupts */
writel(cause, lldev->evca + HIDMA_EVCA_IRQ_CLR_REG);
/* No further submissions. */
hidma_ll_disable(lldev);
/* Driver completes the txn and intimates the client.*/
hidma_cleanup_pending_tre(lldev, 0xFF,
HIDMA_EVRE_STATUS_ERROR);
/* * Fine tuned for this HW... * * This ISR has been designed for this particular hardware. Relaxed * read and write accessors are used for performance reasons due to * interrupt delivery guarantees. Do not copy this code blindly and * expect that to work. * * Try to consume as many EVREs as possible.
*/
hidma_handle_tre_completion(lldev);
}
status = readl_relaxed(lldev->evca + HIDMA_EVCA_IRQ_STAT_REG);
enable = readl_relaxed(lldev->evca + HIDMA_EVCA_IRQ_EN_REG);
cause = status & enable;
while (cause) {
hidma_ll_int_handler_internal(lldev, cause);
/* * Another interrupt might have arrived while we are * processing this one. Read the new cause.
*/
status = readl_relaxed(lldev->evca + HIDMA_EVCA_IRQ_STAT_REG);
enable = readl_relaxed(lldev->evca + HIDMA_EVCA_IRQ_EN_REG);
cause = status & enable;
}
int hidma_ll_enable(struct hidma_lldev *lldev)
{
u32 val; int ret;
val = readl(lldev->evca + HIDMA_EVCA_CTRLSTS_REG);
val &= ~(HIDMA_CH_CONTROL_MASK << 16);
val |= HIDMA_CH_ENABLE << 16;
writel(val, lldev->evca + HIDMA_EVCA_CTRLSTS_REG);
ret = readl_poll_timeout(lldev->evca + HIDMA_EVCA_CTRLSTS_REG, val,
hidma_is_chan_enabled(HIDMA_CH_STATE(val)),
1000, 10000); if (ret) {
dev_err(lldev->dev, "event channel did not get enabled\n"); return ret;
}
val = readl(lldev->trca + HIDMA_TRCA_CTRLSTS_REG);
val &= ~(HIDMA_CH_CONTROL_MASK << 16);
val |= HIDMA_CH_ENABLE << 16;
writel(val, lldev->trca + HIDMA_TRCA_CTRLSTS_REG);
ret = readl_poll_timeout(lldev->trca + HIDMA_TRCA_CTRLSTS_REG, val,
hidma_is_chan_enabled(HIDMA_CH_STATE(val)),
1000, 10000); if (ret) {
dev_err(lldev->dev, "transfer channel did not get enabled\n"); return ret;
}
val = readl(lldev->trca + HIDMA_TRCA_CTRLSTS_REG);
lldev->trch_state = HIDMA_CH_STATE(val);
val = readl(lldev->evca + HIDMA_EVCA_CTRLSTS_REG);
lldev->evch_state = HIDMA_CH_STATE(val);
/* both channels have to be enabled before calling this function */ if (hidma_is_chan_enabled(lldev->trch_state) &&
hidma_is_chan_enabled(lldev->evch_state)) returntrue;
/* copy the TRE into its location in the TRE ring */
spin_lock_irqsave(&lldev->lock, flags);
tre->tre_index = lldev->tre_write_offset / HIDMA_TRE_SIZE;
lldev->pending_tre_list[tre->tre_index] = tre;
memcpy(lldev->tre_ring + lldev->tre_write_offset,
&tre->tre_local[0], HIDMA_TRE_SIZE);
tre->err_code = 0;
tre->err_info = 0;
tre->queued = 1;
atomic_inc(&lldev->pending_tre_count);
lldev->tre_write_offset = (lldev->tre_write_offset + HIDMA_TRE_SIZE)
% lldev->tre_ring_size;
spin_unlock_irqrestore(&lldev->lock, flags);
}
/* * Note that even though we stop this channel if there is a pending transaction * in flight it will complete and follow the callback. This request will * prevent further requests to be made.
*/ int hidma_ll_disable(struct hidma_lldev *lldev)
{
u32 val; int ret;
/* The channel needs to be in working state */ if (!hidma_ll_isenabled(lldev)) return 0;
val = readl(lldev->trca + HIDMA_TRCA_CTRLSTS_REG);
val &= ~(HIDMA_CH_CONTROL_MASK << 16);
val |= HIDMA_CH_SUSPEND << 16;
writel(val, lldev->trca + HIDMA_TRCA_CTRLSTS_REG);
/* * Start the wait right after the suspend is confirmed. * Do a polled read up to 1ms and 10ms maximum.
*/
ret = readl_poll_timeout(lldev->trca + HIDMA_TRCA_CTRLSTS_REG, val,
HIDMA_CH_STATE(val) == HIDMA_CH_SUSPENDED,
1000, 10000); if (ret) return ret;
val = readl(lldev->evca + HIDMA_EVCA_CTRLSTS_REG);
val &= ~(HIDMA_CH_CONTROL_MASK << 16);
val |= HIDMA_CH_SUSPEND << 16;
writel(val, lldev->evca + HIDMA_EVCA_CTRLSTS_REG);
/* * Start the wait right after the suspend is confirmed * Delay up to 10ms after reset to allow DMA logic to quiesce.
*/
ret = readl_poll_timeout(lldev->evca + HIDMA_EVCA_CTRLSTS_REG, val,
HIDMA_CH_STATE(val) == HIDMA_CH_SUSPENDED,
1000, 10000); if (ret) return ret;
if (tre_ch >= lldev->nr_tres) {
dev_err(lldev->dev, "invalid TRE number in transfer params:%d",
tre_ch); return;
}
tre = &lldev->trepool[tre_ch]; if (atomic_read(&tre->allocated) != true) {
dev_err(lldev->dev, "trying to set params on an unused TRE:%d",
tre_ch); return;
}
/* * Called during initialization and after an error condition * to restore hardware state.
*/ int hidma_ll_setup(struct hidma_lldev *lldev)
{ int rc;
u64 addr;
u32 val;
u32 nr_tres = lldev->nr_tres;
/* disable interrupts again after reset */
writel(0, lldev->evca + HIDMA_EVCA_IRQ_CLR_REG);
writel(0, lldev->evca + HIDMA_EVCA_IRQ_EN_REG);
/* support IRQ by default */
val = readl(lldev->evca + HIDMA_EVCA_INTCTRL_REG);
val &= ~0xF; if (!lldev->msi_support)
val = val | 0x1;
writel(val, lldev->evca + HIDMA_EVCA_INTCTRL_REG);
/* clear all pending interrupts and enable them */
writel(ENABLE_IRQS, lldev->evca + HIDMA_EVCA_IRQ_CLR_REG);
writel(ENABLE_IRQS, lldev->evca + HIDMA_EVCA_IRQ_EN_REG);
}
tre = &lldev->trepool[tre_ch];
err_code = tre->err_code;
if (err_code & HIDMA_EVRE_STATUS_COMPLETE)
ret = DMA_COMPLETE; elseif (err_code & HIDMA_EVRE_STATUS_ERROR)
ret = DMA_ERROR; else
ret = DMA_IN_PROGRESS;
spin_unlock_irqrestore(&lldev->lock, flags);
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.