/* Copyright 2008 - 2016 Freescale Semiconductor, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of Freescale Semiconductor nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * ALTERNATIVELY, this software may be distributed under the terms of the * GNU General Public License ("GPL") as published by the Free Software * Foundation, either version 2 of that License or (at your option) any * later version. * * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include"bman_priv.h"
#define IRQNAME "BMan portal %d" #define MAX_IRQNAME 16 /* big enough for "BMan portal %d" */
struct bm_mc { struct bm_mc_command *cr; union bm_mc_result *rr;
u8 rridx, vbit; #ifdef CONFIG_FSL_DPAA_CHECKING enum { /* Can only be _mc_start()ed */
mc_idle, /* Can only be _mc_commit()ed or _mc_abort()ed */
mc_user, /* Can only be _mc_retry()ed */
mc_hw
} state; #endif
};
struct bm_addr { void *ce; /* cache-enabled */
__be32 *ce_be; /* Same as above but for direct access */ void __iomem *ci; /* cache-inhibited */
};
/* * This object type refers to a pool, it isn't *the* pool. There may be * more than one such object per BMan buffer pool, eg. if different users of the * pool are operating via different portals.
*/ struct bman_pool { /* index of the buffer pool to encapsulate (0-63) */
u32 bpid; /* Used for hash-table admin when using depletion notifications. */ struct bman_portal *portal; struct bman_pool *next;
};
/* Bit-wise logic to wrap a ring pointer by clearing the "carry bit" */ staticstruct bm_rcr_entry *rcr_carryclear(struct bm_rcr_entry *p)
{
uintptr_t addr = (uintptr_t)p;
addr &= ~RCR_CARRY;
return (struct bm_rcr_entry *)addr;
}
#ifdef CONFIG_FSL_DPAA_CHECKING /* Bit-wise logic to convert a ring pointer to a ring index */ staticint rcr_ptr2idx(struct bm_rcr_entry *e)
{ return ((uintptr_t)e >> RCR_SHIFT) & (BM_RCR_SIZE - 1);
} #endif
/* Increment the 'cursor' ring pointer, taking 'vbit' into account */ staticinlinevoid rcr_inc(struct bm_rcr *rcr)
{ /* increment to the next RCR pointer and handle overflow and 'vbit' */ struct bm_rcr_entry *partial = rcr->cursor + 1;
DPAA_ASSERT(mc->state == mc_hw); /* * The inactive response register's verb byte always returns zero until * its command is submitted and completed. This includes the valid-bit, * in case you were wondering...
*/ if (!rr->verb) {
dpaa_invalidate_touch_ro(rr); return NULL;
}
mc->rridx ^= 1;
mc->vbit ^= BM_MCC_VERB_VBIT; #ifdef CONFIG_FSL_DPAA_CHECKING
mc->state = mc_idle; #endif return rr;
}
staticinlineint bm_mc_result_timeout(struct bm_portal *portal, union bm_mc_result **mcr)
{ int timeout = BM_MCR_TIMEOUT;
do {
*mcr = bm_mc_result(portal); if (*mcr) break;
udelay(1);
} while (--timeout);
return timeout;
}
/* Disable all BSCN interrupts for the portal */ staticvoid bm_isr_bscn_disable(struct bm_portal *portal)
{
bm_out(portal, BM_REG_SCN(0), 0);
bm_out(portal, BM_REG_SCN(1), 0);
}
p = &portal->p; /* * prep the low-level portal struct with the mapped addresses from the * config, everything that follows depends on it and "config" is more * for (de)reference...
*/
p->addr.ce = c->addr_virt_ce;
p->addr.ce_be = c->addr_virt_ce;
p->addr.ci = c->addr_virt_ci; if (bm_rcr_init(p, bm_rcr_pvb, bm_rcr_cce)) {
dev_err(c->dev, "RCR initialisation failed\n"); goto fail_rcr;
} if (bm_mc_init(p)) {
dev_err(c->dev, "MC initialisation failed\n"); goto fail_mc;
} /* * Default to all BPIDs disabled, we enable as required at * run-time.
*/
bm_isr_bscn_disable(p);
/* Write-to-clear any stale interrupt status bits */
bm_out(p, BM_REG_ISDR, 0xffffffff);
portal->irq_sources = 0;
bm_out(p, BM_REG_IER, 0);
bm_out(p, BM_REG_ISR, 0xffffffff);
snprintf(portal->irqname, MAX_IRQNAME, IRQNAME, c->cpu); if (request_irq(c->irq, portal_isr, 0, portal->irqname, portal)) {
dev_err(c->dev, "request_irq() failed\n"); goto fail_irq;
}
if (dpaa_set_portal_irq_affinity(c->dev, c->irq, c->cpu)) goto fail_affinity;
/* Need RCR to be empty before continuing */
ret = bm_rcr_get_fill(p); if (ret) {
dev_err(c->dev, "RCR unclean\n"); goto fail_rcr_empty;
} /* Success */
portal->config = c;
int bman_get_bpid(conststruct bman_pool *pool)
{ return pool->bpid;
}
EXPORT_SYMBOL(bman_get_bpid);
staticvoid update_rcr_ci(struct bman_portal *p, int avail)
{ if (avail)
bm_rcr_cce_prefetch(&p->p); else
bm_rcr_cce_update(&p->p);
}
int bman_release(struct bman_pool *pool, conststruct bm_buffer *bufs, u8 num)
{ struct bman_portal *p; struct bm_rcr_entry *r; unsignedlong irqflags; int avail, timeout = 1000; /* 1ms */ int i = num - 1;
DPAA_ASSERT(num > 0 && num <= 8);
do {
p = get_affine_portal();
local_irq_save(irqflags);
avail = bm_rcr_get_avail(&p->p); if (avail < 2)
update_rcr_ci(p, avail);
r = bm_rcr_start(&p->p);
local_irq_restore(irqflags);
put_affine_portal(); if (likely(r)) break;
udelay(1);
} while (--timeout);
if (unlikely(!timeout)) return -ETIMEDOUT;
p = get_affine_portal();
local_irq_save(irqflags); /* * we can copy all but the first entry, as this can trigger badness * with the valid-bit
*/
bm_buffer_set64(r->bufs, bm_buffer_get64(bufs));
bm_buffer_set_bpid(r->bufs, pool->bpid); if (i)
memcpy(&r->bufs[1], &bufs[1], i * sizeof(bufs[0]));
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.