/** * struct xgene_dma_chan - internal representation of an X-Gene DMA channel * @dma_chan: dmaengine channel object member * @pdma: X-Gene DMA device structure reference * @dev: struct device reference for dma mapping api * @id: raw id of this channel * @rx_irq: channel IRQ * @name: name of X-Gene DMA channel * @lock: serializes enqueue/dequeue operations to the descriptor pool * @pending: number of transaction request pushed to DMA controller for * execution, but still waiting for completion, * @max_outstanding: max number of outstanding request we can push to channel * @ld_pending: descriptors which are queued to run, but have not yet been * submitted to the hardware for execution * @ld_running: descriptors which are currently being executing by the hardware * @ld_completed: descriptors which have finished execution by the hardware. * These descriptors have already had their cleanup actions run. They * are waiting for the ACK bit to be set by the async tx API. * @desc_pool: descriptor pool for DMA operations * @tasklet: bottom half where all completed descriptors cleans * @tx_ring: transmit ring descriptor that we use to prepare actual * descriptors for further executions * @rx_ring: receive ring descriptor that we use to get completed DMA * descriptors during cleanup time
*/ struct xgene_dma_chan { struct dma_chan dma_chan; struct xgene_dma *pdma; struct device *dev; int id; int rx_irq; char name[10];
spinlock_t lock; int pending; int max_outstanding; struct list_head ld_pending; struct list_head ld_running; struct list_head ld_completed; struct dma_pool *desc_pool; struct tasklet_struct tasklet; struct xgene_dma_ring tx_ring; struct xgene_dma_ring rx_ring;
};
/** * struct xgene_dma - internal representation of an X-Gene DMA device * @dev: reference to this device's struct device * @clk: reference to this device's clock * @err_irq: DMA error irq number * @ring_num: start id number for DMA ring * @csr_dma: base for DMA register access * @csr_ring: base for DMA ring register access * @csr_ring_cmd: base for DMA ring command register access * @csr_efuse: base for efuse register access * @dma_dev: embedded struct dma_device * @chan: reference to X-Gene DMA channels
*/ struct xgene_dma { struct device *dev; struct clk *clk; int err_irq; int ring_num; void __iomem *csr_dma; void __iomem *csr_ring; void __iomem *csr_ring_cmd; void __iomem *csr_efuse; struct dma_device dma_dev[XGENE_DMA_MAX_CHANNEL]; struct xgene_dma_chan chan[XGENE_DMA_MAX_CHANNEL];
};
staticconstchar * const xgene_dma_desc_err[] = {
[ERR_DESC_AXI] = "AXI error when reading src/dst link list",
[ERR_BAD_DESC] = "ERR or El_ERR fields not set to zero in desc",
[ERR_READ_DATA_AXI] = "AXI error when reading data",
[ERR_WRITE_DATA_AXI] = "AXI error when writing data",
[ERR_FBP_TIMEOUT] = "Timeout on bufpool fetch",
[ERR_ECC] = "ECC double bit error",
[ERR_DIFF_SIZE] = "Bufpool too small to hold all the DIF result",
[ERR_SCT_GAT_LEN] = "Gather and scatter data length not same",
[ERR_CRC_ERR] = "CRC error",
[ERR_CHKSUM] = "Checksum error",
[ERR_DIF] = "DIF error",
};
staticconstchar * const xgene_dma_err[] = {
[ERR_DIF_SIZE_INT] = "DIF size error",
[ERR_GS_ERR_INT] = "Gather scatter not same size error",
[ERR_FPB_TIMEO_INT] = "Free pool time out error",
[ERR_WFIFO_OVF_INT] = "Write FIFO over flow error",
[ERR_RFIFO_OVF_INT] = "Read FIFO over flow error",
[ERR_WR_TIMEO_INT] = "Write time out error",
[ERR_RD_TIMEO_INT] = "Read time out error",
[ERR_WR_ERR_INT] = "HBF bus write error",
[ERR_RD_ERR_INT] = "HBF bus read error",
[ERR_BAD_DESC_INT] = "Ring descriptor HE0 not set error",
[ERR_DESC_DST_INT] = "HFB reading dst link address error",
[ERR_DESC_SRC_INT] = "HFB reading src link address error",
};
/** * xgene_dma_clean_completed_descriptor - free all descriptors which * has been completed and acked * @chan: X-Gene DMA channel * * This function is used on all completed and acked descriptors.
*/ staticvoid xgene_dma_clean_completed_descriptor(struct xgene_dma_chan *chan)
{ struct xgene_dma_desc_sw *desc, *_desc;
/* Run the callback for each descriptor, in order */
list_for_each_entry_safe(desc, _desc, &chan->ld_completed, node) { if (async_tx_test_ack(&desc->tx))
xgene_dma_clean_descriptor(chan, desc);
}
}
/** * xgene_dma_run_tx_complete_actions - cleanup a single link descriptor * @chan: X-Gene DMA channel * @desc: descriptor to cleanup and free * * This function is used on a descriptor which has been executed by the DMA * controller. It will run any callbacks, submit any dependencies.
*/ staticvoid xgene_dma_run_tx_complete_actions(struct xgene_dma_chan *chan, struct xgene_dma_desc_sw *desc)
{ struct dma_async_tx_descriptor *tx = &desc->tx;
/* * If this is not the last transaction in the group, * then no need to complete cookie and run any callback as * this is not the tx_descriptor which had been sent to caller * of this DMA request
*/
/* Run the link descriptor callback function */
dmaengine_desc_get_callback_invoke(tx, NULL);
/* Run any dependencies */
dma_run_dependencies(tx);
}
/** * xgene_dma_clean_running_descriptor - move the completed descriptor from * ld_running to ld_completed * @chan: X-Gene DMA channel * @desc: the descriptor which is completed * * Free the descriptor directly if acked by async_tx api, * else move it to queue ld_completed.
*/ staticvoid xgene_dma_clean_running_descriptor(struct xgene_dma_chan *chan, struct xgene_dma_desc_sw *desc)
{ /* Remove from the list of running transactions */
list_del(&desc->node);
/* * the client is allowed to attach dependent operations * until 'ack' is set
*/ if (!async_tx_test_ack(&desc->tx)) { /* * Move this descriptor to the list of descriptors which is * completed, but still awaiting the 'ack' bit to be set.
*/
list_add_tail(&desc->node, &chan->ld_completed); return;
}
/* Get hw descriptor from DMA tx ring */
desc_hw = &ring->desc_hw[ring->head];
/* * Increment the head count to point next * descriptor for next time
*/ if (++ring->head == ring->slots)
ring->head = 0;
/* Copy prepared sw descriptor data to hw descriptor */
memcpy(desc_hw, &desc_sw->desc1, sizeof(*desc_hw));
/* * Check if we have prepared 64B descriptor, * in this case we need one more hw descriptor
*/ if (desc_sw->flags & XGENE_DMA_FLAG_64B_DESC) {
desc_hw = &ring->desc_hw[ring->head];
/* Notify the hw that we have descriptor ready for execution */
iowrite32((desc_sw->flags & XGENE_DMA_FLAG_64B_DESC) ?
2 : 1, ring->cmd);
}
/** * xgene_chan_xfer_ld_pending - push any pending transactions to hw * @chan : X-Gene DMA channel * * LOCKING: must hold chan->lock
*/ staticvoid xgene_chan_xfer_ld_pending(struct xgene_dma_chan *chan)
{ struct xgene_dma_desc_sw *desc_sw, *_desc_sw;
/* * If the list of pending descriptors is empty, then we * don't need to do any work at all
*/ if (list_empty(&chan->ld_pending)) {
chan_dbg(chan, "No pending LDs\n"); return;
}
/* * Move elements from the queue of pending transactions onto the list * of running transactions and push it to hw for further executions
*/
list_for_each_entry_safe(desc_sw, _desc_sw, &chan->ld_pending, node) { /* * Check if have pushed max number of transactions to hw * as capable, so let's stop here and will push remaining * elements from pening ld queue after completing some * descriptors that we have already pushed
*/ if (chan->pending >= chan->max_outstanding) return;
xgene_chan_xfer_request(chan, desc_sw);
/* * Delete this element from ld pending queue and append it to * ld running queue
*/
list_move_tail(&desc_sw->node, &chan->ld_running);
}
}
/** * xgene_dma_cleanup_descriptors - cleanup link descriptors which are completed * and move them to ld_completed to free until flag 'ack' is set * @chan: X-Gene DMA channel * * This function is used on descriptors which have been executed by the DMA * controller. It will run any callbacks, submit any dependencies, then * free these descriptors if flag 'ack' is set.
*/ staticvoid xgene_dma_cleanup_descriptors(struct xgene_dma_chan *chan)
{ struct xgene_dma_ring *ring = &chan->rx_ring; struct xgene_dma_desc_sw *desc_sw, *_desc_sw; struct xgene_dma_desc_hw *desc_hw; struct list_head ld_completed;
u8 status;
INIT_LIST_HEAD(&ld_completed);
spin_lock(&chan->lock);
/* Clean already completed and acked descriptors */
xgene_dma_clean_completed_descriptor(chan);
/* Move all completed descriptors to ld completed queue, in order */
list_for_each_entry_safe(desc_sw, _desc_sw, &chan->ld_running, node) { /* Get subsequent hw descriptor from DMA rx ring */
desc_hw = &ring->desc_hw[ring->head];
/* Check if this descriptor has been completed */ if (unlikely(le64_to_cpu(desc_hw->m0) ==
XGENE_DMA_DESC_EMPTY_SIGNATURE)) break;
if (++ring->head == ring->slots)
ring->head = 0;
/* Check if we have any error with DMA transactions */
status = XGENE_DMA_DESC_STATUS(
XGENE_DMA_DESC_ELERR_RD(le64_to_cpu(
desc_hw->m0)),
XGENE_DMA_DESC_LERR_RD(le64_to_cpu(
desc_hw->m0))); if (status) { /* Print the DMA error type */
chan_err(chan, "%s\n", xgene_dma_desc_err[status]);
/* * We have DMA transactions error here. Dump DMA Tx
* and Rx descriptors for this request */
XGENE_DMA_DESC_DUMP(&desc_sw->desc1, "X-Gene DMA TX DESC1: ");
if (desc_sw->flags & XGENE_DMA_FLAG_64B_DESC)
XGENE_DMA_DESC_DUMP(&desc_sw->desc2, "X-Gene DMA TX DESC2: ");
/* Notify the hw about this completed descriptor */
iowrite32(-1, ring->cmd);
/* Mark this hw descriptor as processed */
desc_hw->m0 = cpu_to_le64(XGENE_DMA_DESC_EMPTY_SIGNATURE);
/* * Decrement the pending transaction count * as we have processed one
*/
chan->pending -= ((desc_sw->flags &
XGENE_DMA_FLAG_64B_DESC) ? 2 : 1);
/* * Delete this node from ld running queue and append it to * ld completed queue for further processing
*/
list_move_tail(&desc_sw->node, &ld_completed);
}
/* * Start any pending transactions automatically * In the ideal case, we keep the DMA controller busy while we go * ahead and free the descriptors below.
*/
xgene_chan_xfer_ld_pending(chan);
spin_unlock(&chan->lock);
/* Run the callback for each descriptor, in order */
list_for_each_entry_safe(desc_sw, _desc_sw, &ld_completed, node) {
xgene_dma_run_tx_complete_actions(chan, desc_sw);
xgene_dma_clean_running_descriptor(chan, desc_sw);
}
}
/* Has this channel already been allocated? */ if (chan->desc_pool) return 1;
chan->desc_pool = dma_pool_create(chan->name, chan->dev, sizeof(struct xgene_dma_desc_sw),
0, 0); if (!chan->desc_pool) {
chan_err(chan, "Failed to allocate descriptor pool\n"); return -ENOMEM;
}
chan_dbg(chan, "Allocate descriptor pool\n");
return 1;
}
/** * xgene_dma_free_desc_list - Free all descriptors in a queue * @chan: X-Gene DMA channel * @list: the list to free * * LOCKING: must hold chan->lock
*/ staticvoid xgene_dma_free_desc_list(struct xgene_dma_chan *chan, struct list_head *list)
{ struct xgene_dma_desc_sw *desc, *_desc;
/* * Save source addresses on local variable, may be we have to * prepare two descriptor to generate P and Q if both enabled * in the flags by client
*/
memcpy(_src, src, sizeof(*src) * src_cnt);
if (flags & DMA_PREP_PQ_DISABLE_P)
len = 0;
if (flags & DMA_PREP_PQ_DISABLE_Q)
_len = 0;
do { /* Allocate the link descriptor from DMA pool */ new = xgene_dma_alloc_descriptor(chan); if (!new) goto fail;
if (!first)
first = new;
new->tx.cookie = 0;
async_tx_ack(&new->tx);
/* Insert the link descriptor to the LD ring */
list_add_tail(&new->node, &first->tx_list);
/* * Prepare DMA descriptor to generate P, * if DMA_PREP_PQ_DISABLE_P flag is not set
*/ if (len) {
xgene_dma_prep_xor_desc(chan, new, &dst[0], src,
src_cnt, &len, multi); continue;
}
/* * Prepare DMA descriptor to generate Q, * if DMA_PREP_PQ_DISABLE_Q flag is not set
*/ if (_len) {
xgene_dma_prep_xor_desc(chan, new, &dst[1], _src,
src_cnt, &_len, scf);
}
} while (len || _len);
new->tx.flags = flags; /* client is in control of this ack */
new->tx.cookie = -EBUSY;
list_splice(&first->tx_list, &new->tx_list);
/* * Disable DMA channel IRQ until we process completed * descriptors
*/
disable_irq_nosync(chan->rx_irq);
/* * Schedule the tasklet to handle all cleanup of the current * transaction. It will start a new transaction if there is * one pending.
*/
tasklet_schedule(&chan->tasklet);
chan_dbg(chan, "Tx ring id 0x%X num %d desc 0x%p\n",
tx_ring->id, tx_ring->num, tx_ring->desc_vaddr);
/* Set the max outstanding request possible to this channel */
chan->max_outstanding = tx_ring->slots;
return ret;
}
staticint xgene_dma_init_rings(struct xgene_dma *pdma)
{ int ret, i, j;
for (i = 0; i < XGENE_DMA_MAX_CHANNEL; i++) {
ret = xgene_dma_create_chan_rings(&pdma->chan[i]); if (ret) { for (j = 0; j < i; j++)
xgene_dma_delete_chan_rings(&pdma->chan[j]); return ret;
}
}
/* Associate DMA ring to corresponding ring HW */
iowrite32(XGENE_DMA_ASSOC_RING_MNGR1,
pdma->csr_dma + XGENE_DMA_CFG_RING_WQ_ASSOC);
/* Configure RAID6 polynomial control setting */ if (is_pq_enabled(pdma))
iowrite32(XGENE_DMA_RAID6_MULTI_CTRL(0x1D),
pdma->csr_dma + XGENE_DMA_RAID6_CONT); else
dev_info(pdma->dev, "PQ is disabled in HW\n");
/* Bring up memory */
iowrite32(0x0, pdma->csr_ring + XGENE_DMA_RING_MEM_RAM_SHUTDOWN);
/* Force a barrier */
ioread32(pdma->csr_ring + XGENE_DMA_RING_MEM_RAM_SHUTDOWN);
/* reset may take up to 1ms */
usleep_range(1000, 1100);
if (ioread32(pdma->csr_ring + XGENE_DMA_RING_BLK_MEM_RDY)
!= XGENE_DMA_RING_BLK_MEM_RDY_VAL) {
dev_err(pdma->dev, "Failed to release ring mngr memory from shutdown\n"); return -ENODEV;
}
/* program threshold set 1 and all hysteresis */
iowrite32(XGENE_DMA_RING_THRESLD0_SET1_VAL,
pdma->csr_ring + XGENE_DMA_RING_THRESLD0_SET1);
iowrite32(XGENE_DMA_RING_THRESLD1_SET1_VAL,
pdma->csr_ring + XGENE_DMA_RING_THRESLD1_SET1);
iowrite32(XGENE_DMA_RING_HYSTERESIS_VAL,
pdma->csr_ring + XGENE_DMA_RING_HYSTERESIS);
/* Basically here, the X-Gene SoC DMA engine channel 0 supports XOR * and channel 1 supports XOR, PQ both. First thing here is we have * mechanism in hw to enable/disable PQ/XOR supports on channel 1, * we can make sure this by reading SoC Efuse register. * Second thing, we have hw errata that if we run channel 0 and * channel 1 simultaneously with executing XOR and PQ request, * suddenly DMA engine hangs, So here we enable XOR on channel 0 only * if XOR and PQ supports on channel 1 is disabled.
*/ if ((chan->id == XGENE_DMA_PQ_CHANNEL) &&
is_pq_enabled(chan->pdma)) {
dma_cap_set(DMA_PQ, dma_dev->cap_mask);
dma_cap_set(DMA_XOR, dma_dev->cap_mask);
} elseif ((chan->id == XGENE_DMA_XOR_CHANNEL) &&
!is_pq_enabled(chan->pdma)) {
dma_cap_set(DMA_XOR, dma_dev->cap_mask);
}
/* Set base and prep routines */
dma_dev->dev = chan->dev;
dma_dev->device_alloc_chan_resources = xgene_dma_alloc_chan_resources;
dma_dev->device_free_chan_resources = xgene_dma_free_chan_resources;
dma_dev->device_issue_pending = xgene_dma_issue_pending;
dma_dev->device_tx_status = xgene_dma_tx_status;
/* Initialize DMA device list head */
INIT_LIST_HEAD(&dma_dev->channels);
list_add_tail(&chan->dma_chan.device_node, &dma_dev->channels);
/* Register with Linux async DMA framework*/
ret = dma_async_device_register(dma_dev); if (ret) {
chan_err(chan, "Failed to register async device %d", ret);
tasklet_kill(&chan->tasklet);
staticint xgene_dma_init_async(struct xgene_dma *pdma)
{ int ret, i, j;
for (i = 0; i < XGENE_DMA_MAX_CHANNEL ; i++) {
ret = xgene_dma_async_register(pdma, i); if (ret) { for (j = 0; j < i; j++) {
dma_async_device_unregister(&pdma->dma_dev[j]);
tasklet_kill(&pdma->chan[j].tasklet);
}
return ret;
}
}
return ret;
}
staticvoid xgene_dma_async_unregister(struct xgene_dma *pdma)
{ int i;
for (i = 0; i < XGENE_DMA_MAX_CHANNEL; i++)
dma_async_device_unregister(&pdma->dma_dev[i]);
}
staticvoid xgene_dma_init_channels(struct xgene_dma *pdma)
{ struct xgene_dma_chan *chan; int i;
pdma->ring_num = XGENE_DMA_RING_NUM;
for (i = 0; i < XGENE_DMA_MAX_CHANNEL; i++) {
chan = &pdma->chan[i];
chan->dev = pdma->dev;
chan->pdma = pdma;
chan->id = i;
snprintf(chan->name, sizeof(chan->name), "dmachan%d", chan->id);
}
}
/* Get DMA csr region */
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) {
dev_err(&pdev->dev, "Failed to get csr region\n"); return -ENXIO;
}
pdma->csr_dma = devm_ioremap(&pdev->dev, res->start,
resource_size(res)); if (!pdma->csr_dma) {
dev_err(&pdev->dev, "Failed to ioremap csr region"); return -ENOMEM;
}
/* Get DMA ring csr region */
res = platform_get_resource(pdev, IORESOURCE_MEM, 1); if (!res) {
dev_err(&pdev->dev, "Failed to get ring csr region\n"); return -ENXIO;
}
pdma->csr_ring = devm_ioremap(&pdev->dev, res->start,
resource_size(res)); if (!pdma->csr_ring) {
dev_err(&pdev->dev, "Failed to ioremap ring csr region"); return -ENOMEM;
}
/* Get DMA ring cmd csr region */
res = platform_get_resource(pdev, IORESOURCE_MEM, 2); if (!res) {
dev_err(&pdev->dev, "Failed to get ring cmd csr region\n"); return -ENXIO;
}
pdma->csr_ring_cmd = devm_ioremap(&pdev->dev, res->start,
resource_size(res)); if (!pdma->csr_ring_cmd) {
dev_err(&pdev->dev, "Failed to ioremap ring cmd csr region"); return -ENOMEM;
}
/* Get efuse csr region */
res = platform_get_resource(pdev, IORESOURCE_MEM, 3); if (!res) {
dev_err(&pdev->dev, "Failed to get efuse csr region\n"); return -ENXIO;
}
pdma->csr_efuse = devm_ioremap(&pdev->dev, res->start,
resource_size(res)); if (!pdma->csr_efuse) {
dev_err(&pdev->dev, "Failed to ioremap efuse csr region"); return -ENOMEM;
}
/* Get DMA error interrupt */
irq = platform_get_irq(pdev, 0); if (irq <= 0) return -ENXIO;
pdma->err_irq = irq;
/* Get DMA Rx ring descriptor interrupts for all DMA channels */ for (i = 1; i <= XGENE_DMA_MAX_CHANNEL; i++) {
irq = platform_get_irq(pdev, i); if (irq <= 0) return -ENXIO;
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.