2010-09-15 22:11:28 +08:00
|
|
|
/*
|
|
|
|
* Texas Instruments CPDMA Driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Texas Instruments
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation version 2.
|
|
|
|
*
|
|
|
|
* This program is distributed "as is" WITHOUT ANY WARRANTY of any
|
|
|
|
* kind, whether express or implied; without even the implied warranty
|
|
|
|
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/device.h>
|
2012-06-28 14:12:32 +08:00
|
|
|
#include <linux/module.h>
|
2010-09-15 22:11:28 +08:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/io.h>
|
2013-04-23 15:31:35 +08:00
|
|
|
#include <linux/delay.h>
|
2016-06-27 17:05:11 +08:00
|
|
|
#include <linux/genalloc.h>
|
2010-09-15 22:11:28 +08:00
|
|
|
#include "davinci_cpdma.h"
|
|
|
|
|
|
|
|
/* DMA Registers */
|
|
|
|
#define CPDMA_TXIDVER 0x00
|
|
|
|
#define CPDMA_TXCONTROL 0x04
|
|
|
|
#define CPDMA_TXTEARDOWN 0x08
|
|
|
|
#define CPDMA_RXIDVER 0x10
|
|
|
|
#define CPDMA_RXCONTROL 0x14
|
|
|
|
#define CPDMA_SOFTRESET 0x1c
|
|
|
|
#define CPDMA_RXTEARDOWN 0x18
|
2016-11-29 23:00:48 +08:00
|
|
|
#define CPDMA_TX_PRI0_RATE 0x30
|
2010-09-15 22:11:28 +08:00
|
|
|
#define CPDMA_TXINTSTATRAW 0x80
|
|
|
|
#define CPDMA_TXINTSTATMASKED 0x84
|
|
|
|
#define CPDMA_TXINTMASKSET 0x88
|
|
|
|
#define CPDMA_TXINTMASKCLEAR 0x8c
|
|
|
|
#define CPDMA_MACINVECTOR 0x90
|
|
|
|
#define CPDMA_MACEOIVECTOR 0x94
|
|
|
|
#define CPDMA_RXINTSTATRAW 0xa0
|
|
|
|
#define CPDMA_RXINTSTATMASKED 0xa4
|
|
|
|
#define CPDMA_RXINTMASKSET 0xa8
|
|
|
|
#define CPDMA_RXINTMASKCLEAR 0xac
|
|
|
|
#define CPDMA_DMAINTSTATRAW 0xb0
|
|
|
|
#define CPDMA_DMAINTSTATMASKED 0xb4
|
|
|
|
#define CPDMA_DMAINTMASKSET 0xb8
|
|
|
|
#define CPDMA_DMAINTMASKCLEAR 0xbc
|
|
|
|
#define CPDMA_DMAINT_HOSTERR BIT(1)
|
|
|
|
|
|
|
|
/* the following exist only if has_ext_regs is set */
|
|
|
|
#define CPDMA_DMACONTROL 0x20
|
|
|
|
#define CPDMA_DMASTATUS 0x24
|
|
|
|
#define CPDMA_RXBUFFOFS 0x28
|
|
|
|
#define CPDMA_EM_CONTROL 0x2c
|
|
|
|
|
|
|
|
/* Descriptor mode bits */
|
|
|
|
#define CPDMA_DESC_SOP BIT(31)
|
|
|
|
#define CPDMA_DESC_EOP BIT(30)
|
|
|
|
#define CPDMA_DESC_OWNER BIT(29)
|
|
|
|
#define CPDMA_DESC_EOQ BIT(28)
|
|
|
|
#define CPDMA_DESC_TD_COMPLETE BIT(27)
|
|
|
|
#define CPDMA_DESC_PASS_CRC BIT(26)
|
2013-02-11 17:52:18 +08:00
|
|
|
#define CPDMA_DESC_TO_PORT_EN BIT(20)
|
|
|
|
#define CPDMA_TO_PORT_SHIFT 16
|
|
|
|
#define CPDMA_DESC_PORT_MASK (BIT(18) | BIT(17) | BIT(16))
|
2013-05-30 04:22:01 +08:00
|
|
|
#define CPDMA_DESC_CRC_LEN 4
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
#define CPDMA_TEARDOWN_VALUE 0xfffffffc
|
|
|
|
|
2016-11-29 23:00:48 +08:00
|
|
|
#define CPDMA_MAX_RLIM_CNT 16384
|
|
|
|
|
2010-09-15 22:11:28 +08:00
|
|
|
struct cpdma_desc {
|
|
|
|
/* hardware fields */
|
|
|
|
u32 hw_next;
|
|
|
|
u32 hw_buffer;
|
|
|
|
u32 hw_len;
|
|
|
|
u32 hw_mode;
|
|
|
|
/* software fields */
|
|
|
|
void *sw_token;
|
|
|
|
u32 sw_buffer;
|
|
|
|
u32 sw_len;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cpdma_desc_pool {
|
2013-12-12 07:51:20 +08:00
|
|
|
phys_addr_t phys;
|
net: davinci_cpdma: use dma_addr_t for DMA address
The davinci_cpdma mixes up physical addresses as seen from the CPU
and DMA addresses as seen from a DMA master, since it can operate
on both normal memory or an on-chip buffer. If dma_addr_t is
different from phys_addr_t, this means we get a compile-time warning
about the type mismatch:
ethernet/ti/davinci_cpdma.c: In function 'cpdma_desc_pool_create':
ethernet/ti/davinci_cpdma.c:182:48: error: passing argument 3 of 'dma_alloc_coherent' from incompatible pointer type [-Werror=incompatible-pointer-types]
pool->cpumap = dma_alloc_coherent(dev, size, &pool->phys,
In file included from ethernet/ti/davinci_cpdma.c:21:0:
dma-mapping.h:398:21: note: expected 'dma_addr_t * {aka long long unsigned int *}' but argument is of type 'phys_addr_t * {aka unsigned int *}'
static inline void *dma_alloc_coherent(struct device *dev, size_t size,
This slightly restructures the code so the address we use for
mapping RAM into a DMA address is always a dma_addr_t, avoiding
the warning. The code is correct even if both types are 32-bit
because the DMA master in this device only supports 32-bit addressing
anyway, independent of the types that are used.
We still assign this value to pool->phys, and that is wrong if
the driver is ever used with an IOMMU, but that value appears to
be never used, so there is no problem really. I've added a couple
of comments about where we do things that are slightly violating
the API.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-01-29 19:39:10 +08:00
|
|
|
dma_addr_t hw_addr;
|
2010-09-15 22:11:28 +08:00
|
|
|
void __iomem *iomap; /* ioremap map */
|
|
|
|
void *cpumap; /* dma_alloc map */
|
|
|
|
int desc_size, mem_size;
|
2016-08-04 23:20:51 +08:00
|
|
|
int num_desc;
|
2010-09-15 22:11:28 +08:00
|
|
|
struct device *dev;
|
2016-06-27 17:05:11 +08:00
|
|
|
struct gen_pool *gen_pool;
|
2010-09-15 22:11:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum cpdma_state {
|
|
|
|
CPDMA_STATE_IDLE,
|
|
|
|
CPDMA_STATE_ACTIVE,
|
|
|
|
CPDMA_STATE_TEARDOWN,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cpdma_ctlr {
|
|
|
|
enum cpdma_state state;
|
|
|
|
struct cpdma_params params;
|
|
|
|
struct device *dev;
|
|
|
|
struct cpdma_desc_pool *pool;
|
|
|
|
spinlock_t lock;
|
|
|
|
struct cpdma_chan *channels[2 * CPDMA_MAX_CHANNELS];
|
2016-08-23 02:18:24 +08:00
|
|
|
int chan_num;
|
2017-01-07 04:07:34 +08:00
|
|
|
int num_rx_desc; /* RX descriptors number */
|
|
|
|
int num_tx_desc; /* TX descriptors number */
|
2010-09-15 22:11:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cpdma_chan {
|
2013-01-17 14:31:34 +08:00
|
|
|
struct cpdma_desc __iomem *head, *tail;
|
|
|
|
void __iomem *hdp, *cp, *rxfree;
|
2010-09-15 22:11:28 +08:00
|
|
|
enum cpdma_state state;
|
|
|
|
struct cpdma_ctlr *ctlr;
|
|
|
|
int chan_num;
|
|
|
|
spinlock_t lock;
|
|
|
|
int count;
|
2016-06-27 17:05:11 +08:00
|
|
|
u32 desc_num;
|
2010-09-15 22:11:28 +08:00
|
|
|
u32 mask;
|
|
|
|
cpdma_handler_fn handler;
|
|
|
|
enum dma_data_direction dir;
|
|
|
|
struct cpdma_chan_stats stats;
|
|
|
|
/* offsets into dmaregs */
|
|
|
|
int int_set, int_clear, td;
|
2016-11-29 23:00:47 +08:00
|
|
|
int weight;
|
2016-11-29 23:00:48 +08:00
|
|
|
u32 rate_factor;
|
|
|
|
u32 rate;
|
2010-09-15 22:11:28 +08:00
|
|
|
};
|
|
|
|
|
2016-11-11 21:45:24 +08:00
|
|
|
struct cpdma_control_info {
|
|
|
|
u32 reg;
|
|
|
|
u32 shift, mask;
|
|
|
|
int access;
|
|
|
|
#define ACCESS_RO BIT(0)
|
|
|
|
#define ACCESS_WO BIT(1)
|
|
|
|
#define ACCESS_RW (ACCESS_RO | ACCESS_WO)
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct cpdma_control_info controls[] = {
|
2016-11-29 23:00:48 +08:00
|
|
|
[CPDMA_TX_RLIM] = {CPDMA_DMACONTROL, 8, 0xffff, ACCESS_RW},
|
2016-11-11 21:45:24 +08:00
|
|
|
[CPDMA_CMD_IDLE] = {CPDMA_DMACONTROL, 3, 1, ACCESS_WO},
|
|
|
|
[CPDMA_COPY_ERROR_FRAMES] = {CPDMA_DMACONTROL, 4, 1, ACCESS_RW},
|
|
|
|
[CPDMA_RX_OFF_LEN_UPDATE] = {CPDMA_DMACONTROL, 2, 1, ACCESS_RW},
|
|
|
|
[CPDMA_RX_OWNERSHIP_FLIP] = {CPDMA_DMACONTROL, 1, 1, ACCESS_RW},
|
|
|
|
[CPDMA_TX_PRIO_FIXED] = {CPDMA_DMACONTROL, 0, 1, ACCESS_RW},
|
|
|
|
[CPDMA_STAT_IDLE] = {CPDMA_DMASTATUS, 31, 1, ACCESS_RO},
|
|
|
|
[CPDMA_STAT_TX_ERR_CODE] = {CPDMA_DMASTATUS, 20, 0xf, ACCESS_RW},
|
|
|
|
[CPDMA_STAT_TX_ERR_CHAN] = {CPDMA_DMASTATUS, 16, 0x7, ACCESS_RW},
|
|
|
|
[CPDMA_STAT_RX_ERR_CODE] = {CPDMA_DMASTATUS, 12, 0xf, ACCESS_RW},
|
|
|
|
[CPDMA_STAT_RX_ERR_CHAN] = {CPDMA_DMASTATUS, 8, 0x7, ACCESS_RW},
|
|
|
|
[CPDMA_RX_BUFFER_OFFSET] = {CPDMA_RXBUFFOFS, 0, 0xffff, ACCESS_RW},
|
|
|
|
};
|
|
|
|
|
2016-08-23 02:18:27 +08:00
|
|
|
#define tx_chan_num(chan) (chan)
|
|
|
|
#define rx_chan_num(chan) ((chan) + CPDMA_MAX_CHANNELS)
|
|
|
|
#define is_rx_chan(chan) ((chan)->chan_num >= CPDMA_MAX_CHANNELS)
|
|
|
|
#define is_tx_chan(chan) (!is_rx_chan(chan))
|
|
|
|
#define __chan_linear(chan_num) ((chan_num) & (CPDMA_MAX_CHANNELS - 1))
|
|
|
|
#define chan_linear(chan) __chan_linear((chan)->chan_num)
|
|
|
|
|
2010-09-15 22:11:28 +08:00
|
|
|
/* The following make access to common cpdma_ctlr params more readable */
|
|
|
|
#define dmaregs params.dmaregs
|
|
|
|
#define num_chan params.num_chan
|
|
|
|
|
|
|
|
/* various accessors */
|
net: ethernet: ti: cpdma: am437x: allow descs to be plased in ddr
It's observed that cpsw/cpdma is not working properly when CPPI
descriptors are placed in DDR instead of internal CPPI RAM on am437x
SoC:
- rx/tx silently stops processing packets;
- or - after boot it's working for sometime, but stuck once Network
load is increased (ping is working, but iperf is not).
(The same issue has not been reproduced on am335x and am57xx).
It seems that write to HDP register processed faster by interconnect
than writing of descriptor memory buffer in DDR, which is probably
caused by store buffer / write buffer differences as these functions
are implemented differently across devices. So, to fix this i come up
with two minimal, required changes:
1) all accesses to the channel register HDP/CP/RXFREE registers should
be done using sync IO accessors readl()/writel(), because all previous
memory writes writes have to be completed before starting channel
(write to HDP) or completing desc processing.
2) the change 1 only doesn't work on am437x and additional reading of
desc's field is required right after the new descriptor was filled
with data and before pointer on it will be stored in
prev_desc->hw_next field or HDP register.
In addition, to above changes this patch eliminates all relaxed ordering
I/O accessors in this driver as suggested by David Miller to avoid such
kind of issues in the future, but with one exception - relaxed IO accessors
will still be used to fill desc in cpdma_chan_submit(), which is safe as
there is read barrier at the end of write sequence, and because sync IO
accessors usage here will affect on net performance.
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-01-07 04:07:29 +08:00
|
|
|
#define dma_reg_read(ctlr, ofs) readl((ctlr)->dmaregs + (ofs))
|
|
|
|
#define chan_read(chan, fld) readl((chan)->fld)
|
|
|
|
#define desc_read(desc, fld) readl(&(desc)->fld)
|
|
|
|
#define dma_reg_write(ctlr, ofs, v) writel(v, (ctlr)->dmaregs + (ofs))
|
|
|
|
#define chan_write(chan, fld, v) writel(v, (chan)->fld)
|
|
|
|
#define desc_write(desc, fld, v) writel((u32)(v), &(desc)->fld)
|
2010-09-15 22:11:28 +08:00
|
|
|
|
2013-02-11 17:52:18 +08:00
|
|
|
#define cpdma_desc_to_port(chan, mode, directed) \
|
|
|
|
do { \
|
|
|
|
if (!is_rx_chan(chan) && ((directed == 1) || \
|
|
|
|
(directed == 2))) \
|
|
|
|
mode |= (CPDMA_DESC_TO_PORT_EN | \
|
|
|
|
(directed << CPDMA_TO_PORT_SHIFT)); \
|
|
|
|
} while (0)
|
|
|
|
|
2017-01-07 04:07:31 +08:00
|
|
|
static void cpdma_desc_pool_destroy(struct cpdma_ctlr *ctlr)
|
2016-06-27 17:05:11 +08:00
|
|
|
{
|
2017-01-07 04:07:31 +08:00
|
|
|
struct cpdma_desc_pool *pool = ctlr->pool;
|
|
|
|
|
2016-06-27 17:05:11 +08:00
|
|
|
if (!pool)
|
|
|
|
return;
|
|
|
|
|
2016-08-04 23:20:51 +08:00
|
|
|
WARN(gen_pool_size(pool->gen_pool) != gen_pool_avail(pool->gen_pool),
|
|
|
|
"cpdma_desc_pool size %d != avail %d",
|
|
|
|
gen_pool_size(pool->gen_pool),
|
|
|
|
gen_pool_avail(pool->gen_pool));
|
2016-06-27 17:05:11 +08:00
|
|
|
if (pool->cpumap)
|
2017-01-07 04:07:31 +08:00
|
|
|
dma_free_coherent(ctlr->dev, pool->mem_size, pool->cpumap,
|
2016-06-27 17:05:11 +08:00
|
|
|
pool->phys);
|
|
|
|
}
|
|
|
|
|
2010-09-15 22:11:28 +08:00
|
|
|
/*
|
|
|
|
* Utility constructs for a cpdma descriptor pool. Some devices (e.g. davinci
|
|
|
|
* emac) have dedicated on-chip memory for these descriptors. Some other
|
|
|
|
* devices (e.g. cpsw switches) use plain old memory. Descriptor pools
|
|
|
|
* abstract out these details
|
|
|
|
*/
|
2017-01-07 04:07:31 +08:00
|
|
|
int cpdma_desc_pool_create(struct cpdma_ctlr *ctlr)
|
2010-09-15 22:11:28 +08:00
|
|
|
{
|
2017-01-07 04:07:31 +08:00
|
|
|
struct cpdma_params *cpdma_params = &ctlr->params;
|
2010-09-15 22:11:28 +08:00
|
|
|
struct cpdma_desc_pool *pool;
|
2017-01-07 04:07:31 +08:00
|
|
|
int ret = -ENOMEM;
|
2010-09-15 22:11:28 +08:00
|
|
|
|
2017-01-07 04:07:31 +08:00
|
|
|
pool = devm_kzalloc(ctlr->dev, sizeof(*pool), GFP_KERNEL);
|
2010-09-15 22:11:28 +08:00
|
|
|
if (!pool)
|
2016-06-27 17:05:11 +08:00
|
|
|
goto gen_pool_create_fail;
|
2017-01-07 04:07:31 +08:00
|
|
|
ctlr->pool = pool;
|
2010-09-15 22:11:28 +08:00
|
|
|
|
2017-01-07 04:07:31 +08:00
|
|
|
pool->mem_size = cpdma_params->desc_mem_size;
|
|
|
|
pool->desc_size = ALIGN(sizeof(struct cpdma_desc),
|
|
|
|
cpdma_params->desc_align);
|
|
|
|
pool->num_desc = pool->mem_size / pool->desc_size;
|
2010-09-15 22:11:28 +08:00
|
|
|
|
2017-01-07 04:07:33 +08:00
|
|
|
if (cpdma_params->descs_pool_size) {
|
|
|
|
/* recalculate memory size required cpdma descriptor pool
|
|
|
|
* basing on number of descriptors specified by user and
|
|
|
|
* if memory size > CPPI internal RAM size (desc_mem_size)
|
|
|
|
* then switch to use DDR
|
|
|
|
*/
|
|
|
|
pool->num_desc = cpdma_params->descs_pool_size;
|
|
|
|
pool->mem_size = pool->desc_size * pool->num_desc;
|
|
|
|
if (pool->mem_size > cpdma_params->desc_mem_size)
|
|
|
|
cpdma_params->desc_mem_phys = 0;
|
|
|
|
}
|
|
|
|
|
2017-01-07 04:07:31 +08:00
|
|
|
pool->gen_pool = devm_gen_pool_create(ctlr->dev, ilog2(pool->desc_size),
|
|
|
|
-1, "cpdma");
|
2016-06-27 17:05:11 +08:00
|
|
|
if (IS_ERR(pool->gen_pool)) {
|
2017-01-07 04:07:31 +08:00
|
|
|
ret = PTR_ERR(pool->gen_pool);
|
|
|
|
dev_err(ctlr->dev, "pool create failed %d\n", ret);
|
2016-06-27 17:05:11 +08:00
|
|
|
goto gen_pool_create_fail;
|
|
|
|
}
|
2010-09-15 22:11:28 +08:00
|
|
|
|
2017-01-07 04:07:31 +08:00
|
|
|
if (cpdma_params->desc_mem_phys) {
|
|
|
|
pool->phys = cpdma_params->desc_mem_phys;
|
2017-01-07 04:07:32 +08:00
|
|
|
pool->iomap = devm_ioremap(ctlr->dev, pool->phys,
|
|
|
|
pool->mem_size);
|
2017-01-07 04:07:31 +08:00
|
|
|
pool->hw_addr = cpdma_params->desc_hw_addr;
|
2010-09-15 22:11:28 +08:00
|
|
|
} else {
|
2017-01-07 04:07:31 +08:00
|
|
|
pool->cpumap = dma_alloc_coherent(ctlr->dev, pool->mem_size,
|
|
|
|
&pool->hw_addr, GFP_KERNEL);
|
net: davinci_cpdma: use dma_addr_t for DMA address
The davinci_cpdma mixes up physical addresses as seen from the CPU
and DMA addresses as seen from a DMA master, since it can operate
on both normal memory or an on-chip buffer. If dma_addr_t is
different from phys_addr_t, this means we get a compile-time warning
about the type mismatch:
ethernet/ti/davinci_cpdma.c: In function 'cpdma_desc_pool_create':
ethernet/ti/davinci_cpdma.c:182:48: error: passing argument 3 of 'dma_alloc_coherent' from incompatible pointer type [-Werror=incompatible-pointer-types]
pool->cpumap = dma_alloc_coherent(dev, size, &pool->phys,
In file included from ethernet/ti/davinci_cpdma.c:21:0:
dma-mapping.h:398:21: note: expected 'dma_addr_t * {aka long long unsigned int *}' but argument is of type 'phys_addr_t * {aka unsigned int *}'
static inline void *dma_alloc_coherent(struct device *dev, size_t size,
This slightly restructures the code so the address we use for
mapping RAM into a DMA address is always a dma_addr_t, avoiding
the warning. The code is correct even if both types are 32-bit
because the DMA master in this device only supports 32-bit addressing
anyway, independent of the types that are used.
We still assign this value to pool->phys, and that is wrong if
the driver is ever used with an IOMMU, but that value appears to
be never used, so there is no problem really. I've added a couple
of comments about where we do things that are slightly violating
the API.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-01-29 19:39:10 +08:00
|
|
|
pool->iomap = (void __iomem __force *)pool->cpumap;
|
|
|
|
pool->phys = pool->hw_addr; /* assumes no IOMMU, don't use this value */
|
2010-09-15 22:11:28 +08:00
|
|
|
}
|
|
|
|
|
2016-06-27 17:05:11 +08:00
|
|
|
if (!pool->iomap)
|
|
|
|
goto gen_pool_create_fail;
|
2010-09-15 22:11:28 +08:00
|
|
|
|
2016-06-27 17:05:11 +08:00
|
|
|
ret = gen_pool_add_virt(pool->gen_pool, (unsigned long)pool->iomap,
|
|
|
|
pool->phys, pool->mem_size, -1);
|
|
|
|
if (ret < 0) {
|
2017-01-07 04:07:31 +08:00
|
|
|
dev_err(ctlr->dev, "pool add failed %d\n", ret);
|
2016-06-27 17:05:11 +08:00
|
|
|
goto gen_pool_add_virt_fail;
|
2010-09-15 22:11:28 +08:00
|
|
|
}
|
2016-06-27 17:05:11 +08:00
|
|
|
|
2017-01-07 04:07:31 +08:00
|
|
|
return 0;
|
2016-06-27 17:05:11 +08:00
|
|
|
|
|
|
|
gen_pool_add_virt_fail:
|
2017-01-07 04:07:31 +08:00
|
|
|
cpdma_desc_pool_destroy(ctlr);
|
2016-06-27 17:05:11 +08:00
|
|
|
gen_pool_create_fail:
|
2017-01-07 04:07:31 +08:00
|
|
|
ctlr->pool = NULL;
|
|
|
|
return ret;
|
2010-09-15 22:11:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline dma_addr_t desc_phys(struct cpdma_desc_pool *pool,
|
|
|
|
struct cpdma_desc __iomem *desc)
|
|
|
|
{
|
|
|
|
if (!desc)
|
|
|
|
return 0;
|
2013-12-12 07:51:20 +08:00
|
|
|
return pool->hw_addr + (__force long)desc - (__force long)pool->iomap;
|
2010-09-15 22:11:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct cpdma_desc __iomem *
|
|
|
|
desc_from_phys(struct cpdma_desc_pool *pool, dma_addr_t dma)
|
|
|
|
{
|
2011-03-22 10:31:03 +08:00
|
|
|
return dma ? pool->iomap + dma - pool->hw_addr : NULL;
|
2010-09-15 22:11:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct cpdma_desc __iomem *
|
2016-06-27 17:05:11 +08:00
|
|
|
cpdma_desc_alloc(struct cpdma_desc_pool *pool)
|
2010-09-15 22:11:28 +08:00
|
|
|
{
|
2016-08-04 23:20:51 +08:00
|
|
|
return (struct cpdma_desc __iomem *)
|
|
|
|
gen_pool_alloc(pool->gen_pool, pool->desc_size);
|
2010-09-15 22:11:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cpdma_desc_free(struct cpdma_desc_pool *pool,
|
|
|
|
struct cpdma_desc __iomem *desc, int num_desc)
|
|
|
|
{
|
2016-06-27 17:05:11 +08:00
|
|
|
gen_pool_free(pool->gen_pool, (unsigned long)desc, pool->desc_size);
|
2010-09-15 22:11:28 +08:00
|
|
|
}
|
|
|
|
|
2016-11-11 21:45:24 +08:00
|
|
|
static int _cpdma_control_set(struct cpdma_ctlr *ctlr, int control, int value)
|
|
|
|
{
|
|
|
|
struct cpdma_control_info *info = &controls[control];
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
if (!ctlr->params.has_ext_regs)
|
|
|
|
return -ENOTSUPP;
|
|
|
|
|
|
|
|
if (ctlr->state != CPDMA_STATE_ACTIVE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (control < 0 || control >= ARRAY_SIZE(controls))
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
if ((info->access & ACCESS_WO) != ACCESS_WO)
|
|
|
|
return -EPERM;
|
|
|
|
|
|
|
|
val = dma_reg_read(ctlr, info->reg);
|
|
|
|
val &= ~(info->mask << info->shift);
|
|
|
|
val |= (value & info->mask) << info->shift;
|
|
|
|
dma_reg_write(ctlr, info->reg, val);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-29 23:00:48 +08:00
|
|
|
static int _cpdma_control_get(struct cpdma_ctlr *ctlr, int control)
|
|
|
|
{
|
|
|
|
struct cpdma_control_info *info = &controls[control];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!ctlr->params.has_ext_regs)
|
|
|
|
return -ENOTSUPP;
|
|
|
|
|
|
|
|
if (ctlr->state != CPDMA_STATE_ACTIVE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (control < 0 || control >= ARRAY_SIZE(controls))
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
if ((info->access & ACCESS_RO) != ACCESS_RO)
|
|
|
|
return -EPERM;
|
|
|
|
|
|
|
|
ret = (dma_reg_read(ctlr, info->reg) >> info->shift) & info->mask;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cpdma_chan_set_chan_shaper - set shaper for a channel
|
|
|
|
* Has to be called under ctlr lock
|
|
|
|
*/
|
|
|
|
static int cpdma_chan_set_chan_shaper(struct cpdma_chan *chan)
|
|
|
|
{
|
|
|
|
struct cpdma_ctlr *ctlr = chan->ctlr;
|
|
|
|
u32 rate_reg;
|
|
|
|
u32 rmask;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!chan->rate)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
rate_reg = CPDMA_TX_PRI0_RATE + 4 * chan->chan_num;
|
|
|
|
dma_reg_write(ctlr, rate_reg, chan->rate_factor);
|
|
|
|
|
|
|
|
rmask = _cpdma_control_get(ctlr, CPDMA_TX_RLIM);
|
|
|
|
rmask |= chan->mask;
|
|
|
|
|
|
|
|
ret = _cpdma_control_set(ctlr, CPDMA_TX_RLIM, rmask);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cpdma_chan_on(struct cpdma_chan *chan)
|
|
|
|
{
|
|
|
|
struct cpdma_ctlr *ctlr = chan->ctlr;
|
|
|
|
struct cpdma_desc_pool *pool = ctlr->pool;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&chan->lock, flags);
|
|
|
|
if (chan->state != CPDMA_STATE_IDLE) {
|
|
|
|
spin_unlock_irqrestore(&chan->lock, flags);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
if (ctlr->state != CPDMA_STATE_ACTIVE) {
|
|
|
|
spin_unlock_irqrestore(&chan->lock, flags);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
dma_reg_write(ctlr, chan->int_set, chan->mask);
|
|
|
|
chan->state = CPDMA_STATE_ACTIVE;
|
|
|
|
if (chan->head) {
|
|
|
|
chan_write(chan, hdp, desc_phys(pool, chan->head));
|
|
|
|
if (chan->rxfree)
|
|
|
|
chan_write(chan, rxfree, chan->count);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&chan->lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cpdma_chan_fit_rate - set rate for a channel and check if it's possible.
|
|
|
|
* rmask - mask of rate limited channels
|
|
|
|
* Returns min rate in Kb/s
|
|
|
|
*/
|
|
|
|
static int cpdma_chan_fit_rate(struct cpdma_chan *ch, u32 rate,
|
|
|
|
u32 *rmask, int *prio_mode)
|
|
|
|
{
|
|
|
|
struct cpdma_ctlr *ctlr = ch->ctlr;
|
|
|
|
struct cpdma_chan *chan;
|
|
|
|
u32 old_rate = ch->rate;
|
|
|
|
u32 new_rmask = 0;
|
|
|
|
int rlim = 1;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
*prio_mode = 0;
|
|
|
|
for (i = tx_chan_num(0); i < tx_chan_num(CPDMA_MAX_CHANNELS); i++) {
|
|
|
|
chan = ctlr->channels[i];
|
|
|
|
if (!chan) {
|
|
|
|
rlim = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chan == ch)
|
|
|
|
chan->rate = rate;
|
|
|
|
|
|
|
|
if (chan->rate) {
|
|
|
|
if (rlim) {
|
|
|
|
new_rmask |= chan->mask;
|
|
|
|
} else {
|
|
|
|
ch->rate = old_rate;
|
|
|
|
dev_err(ctlr->dev, "Prev channel of %dch is not rate limited\n",
|
|
|
|
chan->chan_num);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*prio_mode = 1;
|
|
|
|
rlim = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*rmask = new_rmask;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 cpdma_chan_set_factors(struct cpdma_ctlr *ctlr,
|
|
|
|
struct cpdma_chan *ch)
|
|
|
|
{
|
|
|
|
u32 delta = UINT_MAX, prev_delta = UINT_MAX, best_delta = UINT_MAX;
|
|
|
|
u32 best_send_cnt = 0, best_idle_cnt = 0;
|
|
|
|
u32 new_rate, best_rate = 0, rate_reg;
|
|
|
|
u64 send_cnt, idle_cnt;
|
|
|
|
u32 min_send_cnt, freq;
|
|
|
|
u64 divident, divisor;
|
|
|
|
|
|
|
|
if (!ch->rate) {
|
|
|
|
ch->rate_factor = 0;
|
|
|
|
goto set_factor;
|
|
|
|
}
|
|
|
|
|
|
|
|
freq = ctlr->params.bus_freq_mhz * 1000 * 32;
|
|
|
|
if (!freq) {
|
|
|
|
dev_err(ctlr->dev, "The bus frequency is not set\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
min_send_cnt = freq - ch->rate;
|
|
|
|
send_cnt = DIV_ROUND_UP(min_send_cnt, ch->rate);
|
|
|
|
while (send_cnt <= CPDMA_MAX_RLIM_CNT) {
|
|
|
|
divident = ch->rate * send_cnt;
|
|
|
|
divisor = min_send_cnt;
|
|
|
|
idle_cnt = DIV_ROUND_CLOSEST_ULL(divident, divisor);
|
|
|
|
|
|
|
|
divident = freq * idle_cnt;
|
|
|
|
divisor = idle_cnt + send_cnt;
|
|
|
|
new_rate = DIV_ROUND_CLOSEST_ULL(divident, divisor);
|
|
|
|
|
|
|
|
delta = new_rate >= ch->rate ? new_rate - ch->rate : delta;
|
|
|
|
if (delta < best_delta) {
|
|
|
|
best_delta = delta;
|
|
|
|
best_send_cnt = send_cnt;
|
|
|
|
best_idle_cnt = idle_cnt;
|
|
|
|
best_rate = new_rate;
|
|
|
|
|
|
|
|
if (!delta)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prev_delta >= delta) {
|
|
|
|
prev_delta = delta;
|
|
|
|
send_cnt++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
idle_cnt++;
|
|
|
|
divident = freq * idle_cnt;
|
|
|
|
send_cnt = DIV_ROUND_CLOSEST_ULL(divident, ch->rate);
|
|
|
|
send_cnt -= idle_cnt;
|
|
|
|
prev_delta = UINT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
ch->rate = best_rate;
|
|
|
|
ch->rate_factor = best_send_cnt | (best_idle_cnt << 16);
|
|
|
|
|
|
|
|
set_factor:
|
|
|
|
rate_reg = CPDMA_TX_PRI0_RATE + 4 * ch->chan_num;
|
|
|
|
dma_reg_write(ctlr, rate_reg, ch->rate_factor);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-15 22:11:28 +08:00
|
|
|
struct cpdma_ctlr *cpdma_ctlr_create(struct cpdma_params *params)
|
|
|
|
{
|
|
|
|
struct cpdma_ctlr *ctlr;
|
|
|
|
|
2014-05-12 12:51:21 +08:00
|
|
|
ctlr = devm_kzalloc(params->dev, sizeof(*ctlr), GFP_KERNEL);
|
2010-09-15 22:11:28 +08:00
|
|
|
if (!ctlr)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ctlr->state = CPDMA_STATE_IDLE;
|
|
|
|
ctlr->params = *params;
|
|
|
|
ctlr->dev = params->dev;
|
2016-08-23 02:18:24 +08:00
|
|
|
ctlr->chan_num = 0;
|
2010-09-15 22:11:28 +08:00
|
|
|
spin_lock_init(&ctlr->lock);
|
|
|
|
|
2017-01-07 04:07:31 +08:00
|
|
|
if (cpdma_desc_pool_create(ctlr))
|
2010-09-15 22:11:28 +08:00
|
|
|
return NULL;
|
2017-01-07 04:07:34 +08:00
|
|
|
/* split pool equally between RX/TX by default */
|
|
|
|
ctlr->num_tx_desc = ctlr->pool->num_desc / 2;
|
|
|
|
ctlr->num_rx_desc = ctlr->pool->num_desc - ctlr->num_tx_desc;
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
if (WARN_ON(ctlr->num_chan > CPDMA_MAX_CHANNELS))
|
|
|
|
ctlr->num_chan = CPDMA_MAX_CHANNELS;
|
|
|
|
return ctlr;
|
|
|
|
}
|
2012-04-20 18:56:09 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpdma_ctlr_create);
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
int cpdma_ctlr_start(struct cpdma_ctlr *ctlr)
|
|
|
|
{
|
2016-11-29 23:00:48 +08:00
|
|
|
struct cpdma_chan *chan;
|
2010-09-15 22:11:28 +08:00
|
|
|
unsigned long flags;
|
2016-11-29 23:00:48 +08:00
|
|
|
int i, prio_mode;
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&ctlr->lock, flags);
|
|
|
|
if (ctlr->state != CPDMA_STATE_IDLE) {
|
|
|
|
spin_unlock_irqrestore(&ctlr->lock, flags);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctlr->params.has_soft_reset) {
|
2013-04-23 15:31:35 +08:00
|
|
|
unsigned timeout = 10 * 100;
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
dma_reg_write(ctlr, CPDMA_SOFTRESET, 1);
|
2013-04-23 15:31:35 +08:00
|
|
|
while (timeout) {
|
2010-09-15 22:11:28 +08:00
|
|
|
if (dma_reg_read(ctlr, CPDMA_SOFTRESET) == 0)
|
|
|
|
break;
|
2013-04-23 15:31:35 +08:00
|
|
|
udelay(10);
|
|
|
|
timeout--;
|
2010-09-15 22:11:28 +08:00
|
|
|
}
|
2013-04-23 15:31:35 +08:00
|
|
|
WARN_ON(!timeout);
|
2010-09-15 22:11:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ctlr->num_chan; i++) {
|
net: ethernet: ti: cpdma: am437x: allow descs to be plased in ddr
It's observed that cpsw/cpdma is not working properly when CPPI
descriptors are placed in DDR instead of internal CPPI RAM on am437x
SoC:
- rx/tx silently stops processing packets;
- or - after boot it's working for sometime, but stuck once Network
load is increased (ping is working, but iperf is not).
(The same issue has not been reproduced on am335x and am57xx).
It seems that write to HDP register processed faster by interconnect
than writing of descriptor memory buffer in DDR, which is probably
caused by store buffer / write buffer differences as these functions
are implemented differently across devices. So, to fix this i come up
with two minimal, required changes:
1) all accesses to the channel register HDP/CP/RXFREE registers should
be done using sync IO accessors readl()/writel(), because all previous
memory writes writes have to be completed before starting channel
(write to HDP) or completing desc processing.
2) the change 1 only doesn't work on am437x and additional reading of
desc's field is required right after the new descriptor was filled
with data and before pointer on it will be stored in
prev_desc->hw_next field or HDP register.
In addition, to above changes this patch eliminates all relaxed ordering
I/O accessors in this driver as suggested by David Miller to avoid such
kind of issues in the future, but with one exception - relaxed IO accessors
will still be used to fill desc in cpdma_chan_submit(), which is safe as
there is read barrier at the end of write sequence, and because sync IO
accessors usage here will affect on net performance.
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-01-07 04:07:29 +08:00
|
|
|
writel(0, ctlr->params.txhdp + 4 * i);
|
|
|
|
writel(0, ctlr->params.rxhdp + 4 * i);
|
|
|
|
writel(0, ctlr->params.txcp + 4 * i);
|
|
|
|
writel(0, ctlr->params.rxcp + 4 * i);
|
2010-09-15 22:11:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
dma_reg_write(ctlr, CPDMA_RXINTMASKCLEAR, 0xffffffff);
|
|
|
|
dma_reg_write(ctlr, CPDMA_TXINTMASKCLEAR, 0xffffffff);
|
|
|
|
|
|
|
|
dma_reg_write(ctlr, CPDMA_TXCONTROL, 1);
|
|
|
|
dma_reg_write(ctlr, CPDMA_RXCONTROL, 1);
|
|
|
|
|
|
|
|
ctlr->state = CPDMA_STATE_ACTIVE;
|
|
|
|
|
2016-11-29 23:00:48 +08:00
|
|
|
prio_mode = 0;
|
2010-09-15 22:11:28 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(ctlr->channels); i++) {
|
2016-11-29 23:00:48 +08:00
|
|
|
chan = ctlr->channels[i];
|
|
|
|
if (chan) {
|
|
|
|
cpdma_chan_set_chan_shaper(chan);
|
|
|
|
cpdma_chan_on(chan);
|
|
|
|
|
|
|
|
/* off prio mode if all tx channels are rate limited */
|
|
|
|
if (is_tx_chan(chan) && !chan->rate)
|
|
|
|
prio_mode = 1;
|
|
|
|
}
|
2010-09-15 22:11:28 +08:00
|
|
|
}
|
2016-11-11 21:45:24 +08:00
|
|
|
|
2016-11-29 23:00:48 +08:00
|
|
|
_cpdma_control_set(ctlr, CPDMA_TX_PRIO_FIXED, prio_mode);
|
2016-11-11 21:45:24 +08:00
|
|
|
_cpdma_control_set(ctlr, CPDMA_RX_BUFFER_OFFSET, 0);
|
|
|
|
|
2010-09-15 22:11:28 +08:00
|
|
|
spin_unlock_irqrestore(&ctlr->lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-04-20 18:56:09 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpdma_ctlr_start);
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
int cpdma_ctlr_stop(struct cpdma_ctlr *ctlr)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&ctlr->lock, flags);
|
2016-11-11 22:10:47 +08:00
|
|
|
if (ctlr->state != CPDMA_STATE_ACTIVE) {
|
2010-09-15 22:11:28 +08:00
|
|
|
spin_unlock_irqrestore(&ctlr->lock, flags);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctlr->state = CPDMA_STATE_TEARDOWN;
|
2016-08-23 02:18:25 +08:00
|
|
|
spin_unlock_irqrestore(&ctlr->lock, flags);
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(ctlr->channels); i++) {
|
|
|
|
if (ctlr->channels[i])
|
|
|
|
cpdma_chan_stop(ctlr->channels[i]);
|
|
|
|
}
|
|
|
|
|
2016-08-23 02:18:25 +08:00
|
|
|
spin_lock_irqsave(&ctlr->lock, flags);
|
2010-09-15 22:11:28 +08:00
|
|
|
dma_reg_write(ctlr, CPDMA_RXINTMASKCLEAR, 0xffffffff);
|
|
|
|
dma_reg_write(ctlr, CPDMA_TXINTMASKCLEAR, 0xffffffff);
|
|
|
|
|
|
|
|
dma_reg_write(ctlr, CPDMA_TXCONTROL, 0);
|
|
|
|
dma_reg_write(ctlr, CPDMA_RXCONTROL, 0);
|
|
|
|
|
|
|
|
ctlr->state = CPDMA_STATE_IDLE;
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&ctlr->lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-04-20 18:56:09 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpdma_ctlr_stop);
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
int cpdma_ctlr_destroy(struct cpdma_ctlr *ctlr)
|
|
|
|
{
|
|
|
|
int ret = 0, i;
|
|
|
|
|
|
|
|
if (!ctlr)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (ctlr->state != CPDMA_STATE_IDLE)
|
|
|
|
cpdma_ctlr_stop(ctlr);
|
|
|
|
|
2013-02-12 20:52:30 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(ctlr->channels); i++)
|
|
|
|
cpdma_chan_destroy(ctlr->channels[i]);
|
2010-09-15 22:11:28 +08:00
|
|
|
|
2017-01-07 04:07:31 +08:00
|
|
|
cpdma_desc_pool_destroy(ctlr);
|
2010-09-15 22:11:28 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2012-04-20 18:56:09 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpdma_ctlr_destroy);
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
int cpdma_ctlr_int_ctrl(struct cpdma_ctlr *ctlr, bool enable)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
2017-06-09 02:51:52 +08:00
|
|
|
int i;
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&ctlr->lock, flags);
|
|
|
|
if (ctlr->state != CPDMA_STATE_ACTIVE) {
|
|
|
|
spin_unlock_irqrestore(&ctlr->lock, flags);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(ctlr->channels); i++) {
|
|
|
|
if (ctlr->channels[i])
|
|
|
|
cpdma_chan_int_ctrl(ctlr->channels[i], enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&ctlr->lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
2013-02-15 00:53:01 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpdma_ctlr_int_ctrl);
|
2010-09-15 22:11:28 +08:00
|
|
|
|
2013-02-18 06:19:20 +08:00
|
|
|
void cpdma_ctlr_eoi(struct cpdma_ctlr *ctlr, u32 value)
|
2010-09-15 22:11:28 +08:00
|
|
|
{
|
2013-02-18 06:19:20 +08:00
|
|
|
dma_reg_write(ctlr, CPDMA_MACEOIVECTOR, value);
|
2010-09-15 22:11:28 +08:00
|
|
|
}
|
2013-02-15 00:53:01 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpdma_ctlr_eoi);
|
2010-09-15 22:11:28 +08:00
|
|
|
|
2016-08-23 02:18:26 +08:00
|
|
|
u32 cpdma_ctrl_rxchs_state(struct cpdma_ctlr *ctlr)
|
|
|
|
{
|
|
|
|
return dma_reg_read(ctlr, CPDMA_RXINTSTATMASKED);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(cpdma_ctrl_rxchs_state);
|
|
|
|
|
|
|
|
u32 cpdma_ctrl_txchs_state(struct cpdma_ctlr *ctlr)
|
|
|
|
{
|
|
|
|
return dma_reg_read(ctlr, CPDMA_TXINTSTATMASKED);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(cpdma_ctrl_txchs_state);
|
|
|
|
|
2016-11-29 23:00:47 +08:00
|
|
|
static void cpdma_chan_set_descs(struct cpdma_ctlr *ctlr,
|
|
|
|
int rx, int desc_num,
|
|
|
|
int per_ch_desc)
|
|
|
|
{
|
|
|
|
struct cpdma_chan *chan, *most_chan = NULL;
|
|
|
|
int desc_cnt = desc_num;
|
|
|
|
int most_dnum = 0;
|
|
|
|
int min, max, i;
|
|
|
|
|
|
|
|
if (!desc_num)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (rx) {
|
|
|
|
min = rx_chan_num(0);
|
|
|
|
max = rx_chan_num(CPDMA_MAX_CHANNELS);
|
|
|
|
} else {
|
|
|
|
min = tx_chan_num(0);
|
|
|
|
max = tx_chan_num(CPDMA_MAX_CHANNELS);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = min; i < max; i++) {
|
|
|
|
chan = ctlr->channels[i];
|
|
|
|
if (!chan)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (chan->weight)
|
|
|
|
chan->desc_num = (chan->weight * desc_num) / 100;
|
|
|
|
else
|
|
|
|
chan->desc_num = per_ch_desc;
|
|
|
|
|
|
|
|
desc_cnt -= chan->desc_num;
|
|
|
|
|
|
|
|
if (most_dnum < chan->desc_num) {
|
|
|
|
most_dnum = chan->desc_num;
|
|
|
|
most_chan = chan;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* use remains */
|
2017-01-07 04:07:34 +08:00
|
|
|
if (most_chan)
|
|
|
|
most_chan->desc_num += desc_cnt;
|
2016-11-29 23:00:47 +08:00
|
|
|
}
|
|
|
|
|
2016-08-23 02:18:24 +08:00
|
|
|
/**
|
|
|
|
* cpdma_chan_split_pool - Splits ctrl pool between all channels.
|
|
|
|
* Has to be called under ctlr lock
|
|
|
|
*/
|
2017-01-07 04:07:34 +08:00
|
|
|
int cpdma_chan_split_pool(struct cpdma_ctlr *ctlr)
|
2016-08-23 02:18:24 +08:00
|
|
|
{
|
2016-11-29 23:00:47 +08:00
|
|
|
int tx_per_ch_desc = 0, rx_per_ch_desc = 0;
|
|
|
|
int free_rx_num = 0, free_tx_num = 0;
|
|
|
|
int rx_weight = 0, tx_weight = 0;
|
|
|
|
int tx_desc_num, rx_desc_num;
|
2016-08-23 02:18:24 +08:00
|
|
|
struct cpdma_chan *chan;
|
2017-01-07 04:07:34 +08:00
|
|
|
int i;
|
2016-08-23 02:18:24 +08:00
|
|
|
|
|
|
|
if (!ctlr->chan_num)
|
2016-11-29 23:00:47 +08:00
|
|
|
return 0;
|
2016-08-23 02:18:24 +08:00
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(ctlr->channels); i++) {
|
|
|
|
chan = ctlr->channels[i];
|
2016-11-29 23:00:47 +08:00
|
|
|
if (!chan)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (is_rx_chan(chan)) {
|
|
|
|
if (!chan->weight)
|
|
|
|
free_rx_num++;
|
|
|
|
rx_weight += chan->weight;
|
|
|
|
} else {
|
|
|
|
if (!chan->weight)
|
|
|
|
free_tx_num++;
|
|
|
|
tx_weight += chan->weight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rx_weight > 100 || tx_weight > 100)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2017-01-07 04:07:34 +08:00
|
|
|
tx_desc_num = ctlr->num_tx_desc;
|
|
|
|
rx_desc_num = ctlr->num_rx_desc;
|
2016-11-29 23:00:47 +08:00
|
|
|
|
|
|
|
if (free_tx_num) {
|
|
|
|
tx_per_ch_desc = tx_desc_num - (tx_weight * tx_desc_num) / 100;
|
|
|
|
tx_per_ch_desc /= free_tx_num;
|
|
|
|
}
|
|
|
|
if (free_rx_num) {
|
|
|
|
rx_per_ch_desc = rx_desc_num - (rx_weight * rx_desc_num) / 100;
|
|
|
|
rx_per_ch_desc /= free_rx_num;
|
2016-08-23 02:18:24 +08:00
|
|
|
}
|
2016-11-29 23:00:47 +08:00
|
|
|
|
|
|
|
cpdma_chan_set_descs(ctlr, 0, tx_desc_num, tx_per_ch_desc);
|
|
|
|
cpdma_chan_set_descs(ctlr, 1, rx_desc_num, rx_per_ch_desc);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2017-01-07 04:07:34 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpdma_chan_split_pool);
|
|
|
|
|
2016-11-29 23:00:47 +08:00
|
|
|
|
|
|
|
/* cpdma_chan_set_weight - set weight of a channel in percentage.
|
|
|
|
* Tx and Rx channels have separate weights. That is 100% for RX
|
|
|
|
* and 100% for Tx. The weight is used to split cpdma resources
|
|
|
|
* in correct proportion required by the channels, including number
|
|
|
|
* of descriptors. The channel rate is not enough to know the
|
|
|
|
* weight of a channel as the maximum rate of an interface is needed.
|
|
|
|
* If weight = 0, then channel uses rest of descriptors leaved by
|
|
|
|
* weighted channels.
|
|
|
|
*/
|
|
|
|
int cpdma_chan_set_weight(struct cpdma_chan *ch, int weight)
|
|
|
|
{
|
|
|
|
struct cpdma_ctlr *ctlr = ch->ctlr;
|
|
|
|
unsigned long flags, ch_flags;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&ctlr->lock, flags);
|
|
|
|
spin_lock_irqsave(&ch->lock, ch_flags);
|
|
|
|
if (ch->weight == weight) {
|
|
|
|
spin_unlock_irqrestore(&ch->lock, ch_flags);
|
|
|
|
spin_unlock_irqrestore(&ctlr->lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ch->weight = weight;
|
|
|
|
spin_unlock_irqrestore(&ch->lock, ch_flags);
|
|
|
|
|
|
|
|
/* re-split pool using new channel weight */
|
|
|
|
ret = cpdma_chan_split_pool(ctlr);
|
|
|
|
spin_unlock_irqrestore(&ctlr->lock, flags);
|
|
|
|
return ret;
|
2016-08-23 02:18:24 +08:00
|
|
|
}
|
2016-12-02 04:25:28 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpdma_chan_set_weight);
|
2016-08-23 02:18:24 +08:00
|
|
|
|
2016-11-29 23:00:48 +08:00
|
|
|
/* cpdma_chan_get_min_rate - get minimum allowed rate for channel
|
|
|
|
* Should be called before cpdma_chan_set_rate.
|
|
|
|
* Returns min rate in Kb/s
|
|
|
|
*/
|
|
|
|
u32 cpdma_chan_get_min_rate(struct cpdma_ctlr *ctlr)
|
|
|
|
{
|
|
|
|
unsigned int divident, divisor;
|
|
|
|
|
|
|
|
divident = ctlr->params.bus_freq_mhz * 32 * 1000;
|
|
|
|
divisor = 1 + CPDMA_MAX_RLIM_CNT;
|
|
|
|
|
|
|
|
return DIV_ROUND_UP(divident, divisor);
|
|
|
|
}
|
2016-12-02 04:25:28 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpdma_chan_get_min_rate);
|
2016-11-29 23:00:48 +08:00
|
|
|
|
|
|
|
/* cpdma_chan_set_rate - limits bandwidth for transmit channel.
|
|
|
|
* The bandwidth * limited channels have to be in order beginning from lowest.
|
|
|
|
* ch - transmit channel the bandwidth is configured for
|
|
|
|
* rate - bandwidth in Kb/s, if 0 - then off shaper
|
|
|
|
*/
|
|
|
|
int cpdma_chan_set_rate(struct cpdma_chan *ch, u32 rate)
|
|
|
|
{
|
|
|
|
unsigned long flags, ch_flags;
|
2017-01-18 08:28:06 +08:00
|
|
|
struct cpdma_ctlr *ctlr;
|
2016-11-29 23:00:48 +08:00
|
|
|
int ret, prio_mode;
|
|
|
|
u32 rmask;
|
|
|
|
|
|
|
|
if (!ch || !is_tx_chan(ch))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (ch->rate == rate)
|
|
|
|
return rate;
|
|
|
|
|
2017-01-18 08:28:06 +08:00
|
|
|
ctlr = ch->ctlr;
|
2016-11-29 23:00:48 +08:00
|
|
|
spin_lock_irqsave(&ctlr->lock, flags);
|
|
|
|
spin_lock_irqsave(&ch->lock, ch_flags);
|
|
|
|
|
|
|
|
ret = cpdma_chan_fit_rate(ch, rate, &rmask, &prio_mode);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
ret = cpdma_chan_set_factors(ctlr, ch);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&ch->lock, ch_flags);
|
|
|
|
|
|
|
|
/* on shapers */
|
|
|
|
_cpdma_control_set(ctlr, CPDMA_TX_RLIM, rmask);
|
|
|
|
_cpdma_control_set(ctlr, CPDMA_TX_PRIO_FIXED, prio_mode);
|
|
|
|
spin_unlock_irqrestore(&ctlr->lock, flags);
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
err:
|
|
|
|
spin_unlock_irqrestore(&ch->lock, ch_flags);
|
|
|
|
spin_unlock_irqrestore(&ctlr->lock, flags);
|
|
|
|
return ret;
|
|
|
|
}
|
2016-12-02 04:25:28 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpdma_chan_set_rate);
|
2016-11-29 23:00:48 +08:00
|
|
|
|
|
|
|
u32 cpdma_chan_get_rate(struct cpdma_chan *ch)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
u32 rate;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&ch->lock, flags);
|
|
|
|
rate = ch->rate;
|
|
|
|
spin_unlock_irqrestore(&ch->lock, flags);
|
|
|
|
|
|
|
|
return rate;
|
|
|
|
}
|
2016-12-02 04:25:28 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpdma_chan_get_rate);
|
2016-11-29 23:00:48 +08:00
|
|
|
|
2010-09-15 22:11:28 +08:00
|
|
|
struct cpdma_chan *cpdma_chan_create(struct cpdma_ctlr *ctlr, int chan_num,
|
2016-08-23 02:18:27 +08:00
|
|
|
cpdma_handler_fn handler, int rx_type)
|
2010-09-15 22:11:28 +08:00
|
|
|
{
|
2016-08-23 02:18:27 +08:00
|
|
|
int offset = chan_num * 4;
|
2010-09-15 22:11:28 +08:00
|
|
|
struct cpdma_chan *chan;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2016-08-23 02:18:27 +08:00
|
|
|
chan_num = rx_type ? rx_chan_num(chan_num) : tx_chan_num(chan_num);
|
|
|
|
|
2010-09-15 22:11:28 +08:00
|
|
|
if (__chan_linear(chan_num) >= ctlr->num_chan)
|
2017-12-13 05:06:35 +08:00
|
|
|
return ERR_PTR(-EINVAL);
|
2010-09-15 22:11:28 +08:00
|
|
|
|
2014-05-12 12:51:21 +08:00
|
|
|
chan = devm_kzalloc(ctlr->dev, sizeof(*chan), GFP_KERNEL);
|
2010-09-15 22:11:28 +08:00
|
|
|
if (!chan)
|
2014-05-12 12:51:21 +08:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&ctlr->lock, flags);
|
2014-05-12 12:51:21 +08:00
|
|
|
if (ctlr->channels[chan_num]) {
|
|
|
|
spin_unlock_irqrestore(&ctlr->lock, flags);
|
|
|
|
devm_kfree(ctlr->dev, chan);
|
|
|
|
return ERR_PTR(-EBUSY);
|
|
|
|
}
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
chan->ctlr = ctlr;
|
|
|
|
chan->state = CPDMA_STATE_IDLE;
|
|
|
|
chan->chan_num = chan_num;
|
|
|
|
chan->handler = handler;
|
2016-11-29 23:00:48 +08:00
|
|
|
chan->rate = 0;
|
2016-11-29 23:00:47 +08:00
|
|
|
chan->weight = 0;
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
if (is_rx_chan(chan)) {
|
|
|
|
chan->hdp = ctlr->params.rxhdp + offset;
|
|
|
|
chan->cp = ctlr->params.rxcp + offset;
|
|
|
|
chan->rxfree = ctlr->params.rxfree + offset;
|
|
|
|
chan->int_set = CPDMA_RXINTMASKSET;
|
|
|
|
chan->int_clear = CPDMA_RXINTMASKCLEAR;
|
|
|
|
chan->td = CPDMA_RXTEARDOWN;
|
|
|
|
chan->dir = DMA_FROM_DEVICE;
|
|
|
|
} else {
|
|
|
|
chan->hdp = ctlr->params.txhdp + offset;
|
|
|
|
chan->cp = ctlr->params.txcp + offset;
|
|
|
|
chan->int_set = CPDMA_TXINTMASKSET;
|
|
|
|
chan->int_clear = CPDMA_TXINTMASKCLEAR;
|
|
|
|
chan->td = CPDMA_TXTEARDOWN;
|
|
|
|
chan->dir = DMA_TO_DEVICE;
|
|
|
|
}
|
|
|
|
chan->mask = BIT(chan_linear(chan));
|
|
|
|
|
|
|
|
spin_lock_init(&chan->lock);
|
|
|
|
|
|
|
|
ctlr->channels[chan_num] = chan;
|
2016-08-23 02:18:24 +08:00
|
|
|
ctlr->chan_num++;
|
|
|
|
|
|
|
|
cpdma_chan_split_pool(ctlr);
|
|
|
|
|
2010-09-15 22:11:28 +08:00
|
|
|
spin_unlock_irqrestore(&ctlr->lock, flags);
|
|
|
|
return chan;
|
|
|
|
}
|
2012-04-20 18:56:09 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpdma_chan_create);
|
2010-09-15 22:11:28 +08:00
|
|
|
|
2016-08-23 02:18:24 +08:00
|
|
|
int cpdma_chan_get_rx_buf_num(struct cpdma_chan *chan)
|
net: ethernet: ti: cpsw: remove rx_descs property
There is no reason in rx_descs property because davinici_cpdma
driver splits pool of descriptors equally between tx and rx channels.
That is, if number of descriptors 256, 128 of them are for rx
channels. While receiving, the descriptor is freed to the pool and
then allocated with new skb. And if in DT the "rx_descs" is set to
64, then 128 - 64 = 64 descriptors are always in the pool and cannot
be used, for tx, for instance. It's not correct resource usage,
better to set it to half of pool, then the rx pool can be used in
full. It will not have any impact on performance, as anyway, the
"redundant" descriptors were unused.
Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-06-17 18:25:39 +08:00
|
|
|
{
|
2016-08-23 02:18:24 +08:00
|
|
|
unsigned long flags;
|
|
|
|
int desc_num;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&chan->lock, flags);
|
|
|
|
desc_num = chan->desc_num;
|
|
|
|
spin_unlock_irqrestore(&chan->lock, flags);
|
|
|
|
|
|
|
|
return desc_num;
|
net: ethernet: ti: cpsw: remove rx_descs property
There is no reason in rx_descs property because davinici_cpdma
driver splits pool of descriptors equally between tx and rx channels.
That is, if number of descriptors 256, 128 of them are for rx
channels. While receiving, the descriptor is freed to the pool and
then allocated with new skb. And if in DT the "rx_descs" is set to
64, then 128 - 64 = 64 descriptors are always in the pool and cannot
be used, for tx, for instance. It's not correct resource usage,
better to set it to half of pool, then the rx pool can be used in
full. It will not have any impact on performance, as anyway, the
"redundant" descriptors were unused.
Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-06-17 18:25:39 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(cpdma_chan_get_rx_buf_num);
|
|
|
|
|
2010-09-15 22:11:28 +08:00
|
|
|
int cpdma_chan_destroy(struct cpdma_chan *chan)
|
|
|
|
{
|
2012-08-14 13:49:47 +08:00
|
|
|
struct cpdma_ctlr *ctlr;
|
2010-09-15 22:11:28 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (!chan)
|
|
|
|
return -EINVAL;
|
2012-08-14 13:49:47 +08:00
|
|
|
ctlr = chan->ctlr;
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&ctlr->lock, flags);
|
|
|
|
if (chan->state != CPDMA_STATE_IDLE)
|
|
|
|
cpdma_chan_stop(chan);
|
|
|
|
ctlr->channels[chan->chan_num] = NULL;
|
2016-08-23 02:18:24 +08:00
|
|
|
ctlr->chan_num--;
|
2016-11-08 21:16:05 +08:00
|
|
|
devm_kfree(ctlr->dev, chan);
|
2016-08-23 02:18:24 +08:00
|
|
|
cpdma_chan_split_pool(ctlr);
|
|
|
|
|
2010-09-15 22:11:28 +08:00
|
|
|
spin_unlock_irqrestore(&ctlr->lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-04-20 18:56:09 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpdma_chan_destroy);
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
int cpdma_chan_get_stats(struct cpdma_chan *chan,
|
|
|
|
struct cpdma_chan_stats *stats)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
if (!chan)
|
|
|
|
return -EINVAL;
|
|
|
|
spin_lock_irqsave(&chan->lock, flags);
|
|
|
|
memcpy(stats, &chan->stats, sizeof(*stats));
|
|
|
|
spin_unlock_irqrestore(&chan->lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
2013-08-22 19:47:00 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpdma_chan_get_stats);
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
static void __cpdma_chan_submit(struct cpdma_chan *chan,
|
|
|
|
struct cpdma_desc __iomem *desc)
|
|
|
|
{
|
|
|
|
struct cpdma_ctlr *ctlr = chan->ctlr;
|
|
|
|
struct cpdma_desc __iomem *prev = chan->tail;
|
|
|
|
struct cpdma_desc_pool *pool = ctlr->pool;
|
|
|
|
dma_addr_t desc_dma;
|
|
|
|
u32 mode;
|
|
|
|
|
|
|
|
desc_dma = desc_phys(pool, desc);
|
|
|
|
|
|
|
|
/* simple case - idle channel */
|
|
|
|
if (!chan->head) {
|
|
|
|
chan->stats.head_enqueue++;
|
|
|
|
chan->head = desc;
|
|
|
|
chan->tail = desc;
|
|
|
|
if (chan->state == CPDMA_STATE_ACTIVE)
|
|
|
|
chan_write(chan, hdp, desc_dma);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* first chain the descriptor at the tail of the list */
|
|
|
|
desc_write(prev, hw_next, desc_dma);
|
|
|
|
chan->tail = desc;
|
|
|
|
chan->stats.tail_enqueue++;
|
|
|
|
|
|
|
|
/* next check if EOQ has been triggered already */
|
|
|
|
mode = desc_read(prev, hw_mode);
|
|
|
|
if (((mode & (CPDMA_DESC_EOQ | CPDMA_DESC_OWNER)) == CPDMA_DESC_EOQ) &&
|
|
|
|
(chan->state == CPDMA_STATE_ACTIVE)) {
|
|
|
|
desc_write(prev, hw_mode, mode & ~CPDMA_DESC_EOQ);
|
|
|
|
chan_write(chan, hdp, desc_dma);
|
|
|
|
chan->stats.misqueued++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data,
|
2013-04-23 15:31:38 +08:00
|
|
|
int len, int directed)
|
2010-09-15 22:11:28 +08:00
|
|
|
{
|
|
|
|
struct cpdma_ctlr *ctlr = chan->ctlr;
|
|
|
|
struct cpdma_desc __iomem *desc;
|
|
|
|
dma_addr_t buffer;
|
|
|
|
unsigned long flags;
|
|
|
|
u32 mode;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&chan->lock, flags);
|
|
|
|
|
|
|
|
if (chan->state == CPDMA_STATE_TEARDOWN) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto unlock_ret;
|
|
|
|
}
|
|
|
|
|
2016-06-27 17:05:11 +08:00
|
|
|
if (chan->count >= chan->desc_num) {
|
|
|
|
chan->stats.desc_alloc_fail++;
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto unlock_ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
desc = cpdma_desc_alloc(ctlr->pool);
|
2010-09-15 22:11:28 +08:00
|
|
|
if (!desc) {
|
|
|
|
chan->stats.desc_alloc_fail++;
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto unlock_ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len < ctlr->params.min_packet_size) {
|
|
|
|
len = ctlr->params.min_packet_size;
|
|
|
|
chan->stats.runt_transmit_buff++;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer = dma_map_single(ctlr->dev, data, len, chan->dir);
|
2013-06-20 22:58:45 +08:00
|
|
|
ret = dma_mapping_error(ctlr->dev, buffer);
|
|
|
|
if (ret) {
|
|
|
|
cpdma_desc_free(ctlr->pool, desc, 1);
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto unlock_ret;
|
|
|
|
}
|
|
|
|
|
2010-09-15 22:11:28 +08:00
|
|
|
mode = CPDMA_DESC_OWNER | CPDMA_DESC_SOP | CPDMA_DESC_EOP;
|
2013-02-11 17:52:18 +08:00
|
|
|
cpdma_desc_to_port(chan, mode, directed);
|
2010-09-15 22:11:28 +08:00
|
|
|
|
net: ethernet: ti: cpdma: am437x: allow descs to be plased in ddr
It's observed that cpsw/cpdma is not working properly when CPPI
descriptors are placed in DDR instead of internal CPPI RAM on am437x
SoC:
- rx/tx silently stops processing packets;
- or - after boot it's working for sometime, but stuck once Network
load is increased (ping is working, but iperf is not).
(The same issue has not been reproduced on am335x and am57xx).
It seems that write to HDP register processed faster by interconnect
than writing of descriptor memory buffer in DDR, which is probably
caused by store buffer / write buffer differences as these functions
are implemented differently across devices. So, to fix this i come up
with two minimal, required changes:
1) all accesses to the channel register HDP/CP/RXFREE registers should
be done using sync IO accessors readl()/writel(), because all previous
memory writes writes have to be completed before starting channel
(write to HDP) or completing desc processing.
2) the change 1 only doesn't work on am437x and additional reading of
desc's field is required right after the new descriptor was filled
with data and before pointer on it will be stored in
prev_desc->hw_next field or HDP register.
In addition, to above changes this patch eliminates all relaxed ordering
I/O accessors in this driver as suggested by David Miller to avoid such
kind of issues in the future, but with one exception - relaxed IO accessors
will still be used to fill desc in cpdma_chan_submit(), which is safe as
there is read barrier at the end of write sequence, and because sync IO
accessors usage here will affect on net performance.
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-01-07 04:07:29 +08:00
|
|
|
/* Relaxed IO accessors can be used here as there is read barrier
|
|
|
|
* at the end of write sequence.
|
|
|
|
*/
|
|
|
|
writel_relaxed(0, &desc->hw_next);
|
|
|
|
writel_relaxed(buffer, &desc->hw_buffer);
|
|
|
|
writel_relaxed(len, &desc->hw_len);
|
|
|
|
writel_relaxed(mode | len, &desc->hw_mode);
|
|
|
|
writel_relaxed(token, &desc->sw_token);
|
|
|
|
writel_relaxed(buffer, &desc->sw_buffer);
|
|
|
|
writel_relaxed(len, &desc->sw_len);
|
|
|
|
desc_read(desc, sw_len);
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
__cpdma_chan_submit(chan, desc);
|
|
|
|
|
|
|
|
if (chan->state == CPDMA_STATE_ACTIVE && chan->rxfree)
|
|
|
|
chan_write(chan, rxfree, 1);
|
|
|
|
|
|
|
|
chan->count++;
|
|
|
|
|
|
|
|
unlock_ret:
|
|
|
|
spin_unlock_irqrestore(&chan->lock, flags);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-04-20 18:56:09 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpdma_chan_submit);
|
2010-09-15 22:11:28 +08:00
|
|
|
|
2013-01-17 14:31:34 +08:00
|
|
|
bool cpdma_check_free_tx_desc(struct cpdma_chan *chan)
|
|
|
|
{
|
|
|
|
struct cpdma_ctlr *ctlr = chan->ctlr;
|
|
|
|
struct cpdma_desc_pool *pool = ctlr->pool;
|
2016-06-27 17:05:11 +08:00
|
|
|
bool free_tx_desc;
|
|
|
|
unsigned long flags;
|
2013-01-17 14:31:34 +08:00
|
|
|
|
2016-06-27 17:05:11 +08:00
|
|
|
spin_lock_irqsave(&chan->lock, flags);
|
|
|
|
free_tx_desc = (chan->count < chan->desc_num) &&
|
|
|
|
gen_pool_avail(pool->gen_pool);
|
|
|
|
spin_unlock_irqrestore(&chan->lock, flags);
|
|
|
|
return free_tx_desc;
|
2013-01-17 14:31:34 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(cpdma_check_free_tx_desc);
|
|
|
|
|
2010-09-15 22:11:28 +08:00
|
|
|
static void __cpdma_chan_free(struct cpdma_chan *chan,
|
|
|
|
struct cpdma_desc __iomem *desc,
|
|
|
|
int outlen, int status)
|
|
|
|
{
|
|
|
|
struct cpdma_ctlr *ctlr = chan->ctlr;
|
|
|
|
struct cpdma_desc_pool *pool = ctlr->pool;
|
|
|
|
dma_addr_t buff_dma;
|
|
|
|
int origlen;
|
|
|
|
void *token;
|
|
|
|
|
|
|
|
token = (void *)desc_read(desc, sw_token);
|
|
|
|
buff_dma = desc_read(desc, sw_buffer);
|
|
|
|
origlen = desc_read(desc, sw_len);
|
|
|
|
|
|
|
|
dma_unmap_single(ctlr->dev, buff_dma, origlen, chan->dir);
|
|
|
|
cpdma_desc_free(pool, desc, 1);
|
|
|
|
(*chan->handler)(token, outlen, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __cpdma_chan_process(struct cpdma_chan *chan)
|
|
|
|
{
|
|
|
|
struct cpdma_ctlr *ctlr = chan->ctlr;
|
|
|
|
struct cpdma_desc __iomem *desc;
|
|
|
|
int status, outlen;
|
2013-04-23 15:31:39 +08:00
|
|
|
int cb_status = 0;
|
2010-09-15 22:11:28 +08:00
|
|
|
struct cpdma_desc_pool *pool = ctlr->pool;
|
|
|
|
dma_addr_t desc_dma;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&chan->lock, flags);
|
|
|
|
|
|
|
|
desc = chan->head;
|
|
|
|
if (!desc) {
|
|
|
|
chan->stats.empty_dequeue++;
|
|
|
|
status = -ENOENT;
|
|
|
|
goto unlock_ret;
|
|
|
|
}
|
|
|
|
desc_dma = desc_phys(pool, desc);
|
|
|
|
|
net: ethernet: ti: cpdma: am437x: allow descs to be plased in ddr
It's observed that cpsw/cpdma is not working properly when CPPI
descriptors are placed in DDR instead of internal CPPI RAM on am437x
SoC:
- rx/tx silently stops processing packets;
- or - after boot it's working for sometime, but stuck once Network
load is increased (ping is working, but iperf is not).
(The same issue has not been reproduced on am335x and am57xx).
It seems that write to HDP register processed faster by interconnect
than writing of descriptor memory buffer in DDR, which is probably
caused by store buffer / write buffer differences as these functions
are implemented differently across devices. So, to fix this i come up
with two minimal, required changes:
1) all accesses to the channel register HDP/CP/RXFREE registers should
be done using sync IO accessors readl()/writel(), because all previous
memory writes writes have to be completed before starting channel
(write to HDP) or completing desc processing.
2) the change 1 only doesn't work on am437x and additional reading of
desc's field is required right after the new descriptor was filled
with data and before pointer on it will be stored in
prev_desc->hw_next field or HDP register.
In addition, to above changes this patch eliminates all relaxed ordering
I/O accessors in this driver as suggested by David Miller to avoid such
kind of issues in the future, but with one exception - relaxed IO accessors
will still be used to fill desc in cpdma_chan_submit(), which is safe as
there is read barrier at the end of write sequence, and because sync IO
accessors usage here will affect on net performance.
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-01-07 04:07:29 +08:00
|
|
|
status = desc_read(desc, hw_mode);
|
2010-09-15 22:11:28 +08:00
|
|
|
outlen = status & 0x7ff;
|
|
|
|
if (status & CPDMA_DESC_OWNER) {
|
|
|
|
chan->stats.busy_dequeue++;
|
|
|
|
status = -EBUSY;
|
|
|
|
goto unlock_ret;
|
|
|
|
}
|
2013-05-30 04:22:01 +08:00
|
|
|
|
|
|
|
if (status & CPDMA_DESC_PASS_CRC)
|
|
|
|
outlen -= CPDMA_DESC_CRC_LEN;
|
|
|
|
|
2013-02-11 17:52:18 +08:00
|
|
|
status = status & (CPDMA_DESC_EOQ | CPDMA_DESC_TD_COMPLETE |
|
2018-03-16 04:15:50 +08:00
|
|
|
CPDMA_DESC_PORT_MASK | CPDMA_RX_VLAN_ENCAP);
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
chan->head = desc_from_phys(pool, desc_read(desc, hw_next));
|
|
|
|
chan_write(chan, cp, desc_dma);
|
|
|
|
chan->count--;
|
|
|
|
chan->stats.good_dequeue++;
|
|
|
|
|
2017-01-07 04:07:30 +08:00
|
|
|
if ((status & CPDMA_DESC_EOQ) && chan->head) {
|
2010-09-15 22:11:28 +08:00
|
|
|
chan->stats.requeue++;
|
|
|
|
chan_write(chan, hdp, desc_phys(pool, chan->head));
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&chan->lock, flags);
|
2013-04-23 15:31:39 +08:00
|
|
|
if (unlikely(status & CPDMA_DESC_TD_COMPLETE))
|
|
|
|
cb_status = -ENOSYS;
|
|
|
|
else
|
|
|
|
cb_status = status;
|
2010-09-15 22:11:28 +08:00
|
|
|
|
2013-04-23 15:31:39 +08:00
|
|
|
__cpdma_chan_free(chan, desc, outlen, cb_status);
|
2010-09-15 22:11:28 +08:00
|
|
|
return status;
|
|
|
|
|
|
|
|
unlock_ret:
|
|
|
|
spin_unlock_irqrestore(&chan->lock, flags);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cpdma_chan_process(struct cpdma_chan *chan, int quota)
|
|
|
|
{
|
|
|
|
int used = 0, ret = 0;
|
|
|
|
|
|
|
|
if (chan->state != CPDMA_STATE_ACTIVE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
while (used < quota) {
|
|
|
|
ret = __cpdma_chan_process(chan);
|
|
|
|
if (ret < 0)
|
|
|
|
break;
|
|
|
|
used++;
|
|
|
|
}
|
|
|
|
return used;
|
|
|
|
}
|
2012-04-20 18:56:09 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpdma_chan_process);
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
int cpdma_chan_start(struct cpdma_chan *chan)
|
|
|
|
{
|
2016-11-29 23:00:48 +08:00
|
|
|
struct cpdma_ctlr *ctlr = chan->ctlr;
|
|
|
|
unsigned long flags;
|
|
|
|
int ret;
|
2010-09-15 22:11:28 +08:00
|
|
|
|
2016-11-29 23:00:48 +08:00
|
|
|
spin_lock_irqsave(&ctlr->lock, flags);
|
|
|
|
ret = cpdma_chan_set_chan_shaper(chan);
|
|
|
|
spin_unlock_irqrestore(&ctlr->lock, flags);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = cpdma_chan_on(chan);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2012-04-20 18:56:09 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpdma_chan_start);
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
int cpdma_chan_stop(struct cpdma_chan *chan)
|
|
|
|
{
|
|
|
|
struct cpdma_ctlr *ctlr = chan->ctlr;
|
|
|
|
struct cpdma_desc_pool *pool = ctlr->pool;
|
|
|
|
unsigned long flags;
|
|
|
|
int ret;
|
2013-04-23 15:31:35 +08:00
|
|
|
unsigned timeout;
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&chan->lock, flags);
|
net: davinci_emac: Fix rollback of emac_dev_open()
If an error occurs during the initialization in emac_dev_open() (the
driver's ndo_open function), interrupts, DMA descriptors etc. must be freed.
The current rollback code is buggy in several ways.
1) Freeing the interrupts. The current code will not free all interrupts
that were requested by the driver. Furthermore, the code tries to do a
platform_get_resource(priv->pdev, IORESOURCE_IRQ, -1) in its last
iteration.
This patch fixes these bugs.
2) Wrong order of err: and rollback: labels. If the setup of the PHY in
the code fails, the interrupts that have been requested before are
not freed:
request irq
if requesting irqs fails, goto rollback
setup phy
if phy setup fails, goto err
return 0
rollback:
free irqs
err:
This patch brings the code into the correct order.
3) The code calls napi_enable() and emac_int_enable(), but does not
undo both in case of an error.
This patch adds calls of emac_int_disable() and napi_disable() to the
rollback code.
4) RX DMA descriptors are not freed in case of an error: Right before
requesting the irqs, the function creates DMA descriptors for the
RX channel. These RX descriptors are never freed when we jump to either
rollback or err.
This patch adds code for freeing the DMA descriptors in the case of
an initialization error. This required a modification of
cpdma_ctrl_stop() in davinci_cpdma.c: We must be able to call this
function to free the DMA descriptors while the DMA channels are
in IDLE state (before cpdma_ctlr_start() was called).
Tested on a custom board with the Texas Instruments AM1808.
Signed-off-by: Christian Riesch <christian.riesch@omicron.at>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-03-24 20:46:27 +08:00
|
|
|
if (chan->state == CPDMA_STATE_TEARDOWN) {
|
2010-09-15 22:11:28 +08:00
|
|
|
spin_unlock_irqrestore(&chan->lock, flags);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
chan->state = CPDMA_STATE_TEARDOWN;
|
|
|
|
dma_reg_write(ctlr, chan->int_clear, chan->mask);
|
|
|
|
|
|
|
|
/* trigger teardown */
|
2012-02-23 05:58:00 +08:00
|
|
|
dma_reg_write(ctlr, chan->td, chan_linear(chan));
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
/* wait for teardown complete */
|
2013-04-23 15:31:35 +08:00
|
|
|
timeout = 100 * 100; /* 100 ms */
|
|
|
|
while (timeout) {
|
2010-09-15 22:11:28 +08:00
|
|
|
u32 cp = chan_read(chan, cp);
|
|
|
|
if ((cp & CPDMA_TEARDOWN_VALUE) == CPDMA_TEARDOWN_VALUE)
|
|
|
|
break;
|
2013-04-23 15:31:35 +08:00
|
|
|
udelay(10);
|
|
|
|
timeout--;
|
2010-09-15 22:11:28 +08:00
|
|
|
}
|
2013-04-23 15:31:35 +08:00
|
|
|
WARN_ON(!timeout);
|
2010-09-15 22:11:28 +08:00
|
|
|
chan_write(chan, cp, CPDMA_TEARDOWN_VALUE);
|
|
|
|
|
|
|
|
/* handle completed packets */
|
2011-12-18 18:02:04 +08:00
|
|
|
spin_unlock_irqrestore(&chan->lock, flags);
|
2010-09-15 22:11:28 +08:00
|
|
|
do {
|
|
|
|
ret = __cpdma_chan_process(chan);
|
|
|
|
if (ret < 0)
|
|
|
|
break;
|
|
|
|
} while ((ret & CPDMA_DESC_TD_COMPLETE) == 0);
|
2011-12-18 18:02:04 +08:00
|
|
|
spin_lock_irqsave(&chan->lock, flags);
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
/* remaining packets haven't been tx/rx'ed, clean them up */
|
|
|
|
while (chan->head) {
|
|
|
|
struct cpdma_desc __iomem *desc = chan->head;
|
|
|
|
dma_addr_t next_dma;
|
|
|
|
|
|
|
|
next_dma = desc_read(desc, hw_next);
|
|
|
|
chan->head = desc_from_phys(pool, next_dma);
|
2012-10-02 00:42:43 +08:00
|
|
|
chan->count--;
|
2010-09-15 22:11:28 +08:00
|
|
|
chan->stats.teardown_dequeue++;
|
|
|
|
|
|
|
|
/* issue callback without locks held */
|
|
|
|
spin_unlock_irqrestore(&chan->lock, flags);
|
|
|
|
__cpdma_chan_free(chan, desc, 0, -ENOSYS);
|
|
|
|
spin_lock_irqsave(&chan->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
chan->state = CPDMA_STATE_IDLE;
|
|
|
|
spin_unlock_irqrestore(&chan->lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-04-20 18:56:09 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpdma_chan_stop);
|
2010-09-15 22:11:28 +08:00
|
|
|
|
|
|
|
int cpdma_chan_int_ctrl(struct cpdma_chan *chan, bool enable)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&chan->lock, flags);
|
|
|
|
if (chan->state != CPDMA_STATE_ACTIVE) {
|
|
|
|
spin_unlock_irqrestore(&chan->lock, flags);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dma_reg_write(chan->ctlr, enable ? chan->int_set : chan->int_clear,
|
|
|
|
chan->mask);
|
|
|
|
spin_unlock_irqrestore(&chan->lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cpdma_control_get(struct cpdma_ctlr *ctlr, int control)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&ctlr->lock, flags);
|
2016-11-29 23:00:48 +08:00
|
|
|
ret = _cpdma_control_get(ctlr, control);
|
2010-09-15 22:11:28 +08:00
|
|
|
spin_unlock_irqrestore(&ctlr->lock, flags);
|
2016-11-29 23:00:48 +08:00
|
|
|
|
2010-09-15 22:11:28 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cpdma_control_set(struct cpdma_ctlr *ctlr, int control, int value)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&ctlr->lock, flags);
|
2016-11-11 21:45:24 +08:00
|
|
|
ret = _cpdma_control_set(ctlr, control, value);
|
2010-09-15 22:11:28 +08:00
|
|
|
spin_unlock_irqrestore(&ctlr->lock, flags);
|
2016-11-29 23:00:48 +08:00
|
|
|
|
2010-09-15 22:11:28 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2013-02-15 00:53:01 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpdma_control_set);
|
2013-04-24 16:48:22 +08:00
|
|
|
|
2017-01-07 04:07:34 +08:00
|
|
|
int cpdma_get_num_rx_descs(struct cpdma_ctlr *ctlr)
|
|
|
|
{
|
|
|
|
return ctlr->num_rx_desc;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(cpdma_get_num_rx_descs);
|
|
|
|
|
|
|
|
int cpdma_get_num_tx_descs(struct cpdma_ctlr *ctlr)
|
|
|
|
{
|
|
|
|
return ctlr->num_tx_desc;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(cpdma_get_num_tx_descs);
|
|
|
|
|
|
|
|
void cpdma_set_num_rx_descs(struct cpdma_ctlr *ctlr, int num_rx_desc)
|
|
|
|
{
|
|
|
|
ctlr->num_rx_desc = num_rx_desc;
|
|
|
|
ctlr->num_tx_desc = ctlr->pool->num_desc - ctlr->num_rx_desc;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(cpdma_set_num_rx_descs);
|
|
|
|
|
2013-04-24 16:48:22 +08:00
|
|
|
MODULE_LICENSE("GPL");
|