Commit 5fcc40a9 authored by Grygorii Strashko's avatar Grygorii Strashko Committed by David S. Miller

net: ethernet: ti: cpdma: minimize number of parameters in cpdma_desc_pool_create/destroy()

Update cpdma_desc_pool_create/destroy() to accept only one parameter
struct cpdma_ctlr*, as this structure contains all required
information for pool creation/destruction.
Signed-off-by: default avatarGrygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 12a303e3
...@@ -181,8 +181,10 @@ static struct cpdma_control_info controls[] = { ...@@ -181,8 +181,10 @@ static struct cpdma_control_info controls[] = {
(directed << CPDMA_TO_PORT_SHIFT)); \ (directed << CPDMA_TO_PORT_SHIFT)); \
} while (0) } while (0)
static void cpdma_desc_pool_destroy(struct cpdma_desc_pool *pool) static void cpdma_desc_pool_destroy(struct cpdma_ctlr *ctlr)
{ {
struct cpdma_desc_pool *pool = ctlr->pool;
if (!pool) if (!pool)
return; return;
...@@ -191,7 +193,7 @@ static void cpdma_desc_pool_destroy(struct cpdma_desc_pool *pool) ...@@ -191,7 +193,7 @@ static void cpdma_desc_pool_destroy(struct cpdma_desc_pool *pool)
gen_pool_size(pool->gen_pool), gen_pool_size(pool->gen_pool),
gen_pool_avail(pool->gen_pool)); gen_pool_avail(pool->gen_pool));
if (pool->cpumap) if (pool->cpumap)
dma_free_coherent(pool->dev, pool->mem_size, pool->cpumap, dma_free_coherent(ctlr->dev, pool->mem_size, pool->cpumap,
pool->phys); pool->phys);
else else
iounmap(pool->iomap); iounmap(pool->iomap);
...@@ -203,37 +205,37 @@ static void cpdma_desc_pool_destroy(struct cpdma_desc_pool *pool) ...@@ -203,37 +205,37 @@ static void cpdma_desc_pool_destroy(struct cpdma_desc_pool *pool)
* devices (e.g. cpsw switches) use plain old memory. Descriptor pools * devices (e.g. cpsw switches) use plain old memory. Descriptor pools
* abstract out these details * abstract out these details
*/ */
static struct cpdma_desc_pool * int cpdma_desc_pool_create(struct cpdma_ctlr *ctlr)
cpdma_desc_pool_create(struct device *dev, u32 phys, dma_addr_t hw_addr,
int size, int align)
{ {
struct cpdma_params *cpdma_params = &ctlr->params;
struct cpdma_desc_pool *pool; struct cpdma_desc_pool *pool;
int ret; int ret = -ENOMEM;
pool = devm_kzalloc(dev, sizeof(*pool), GFP_KERNEL); pool = devm_kzalloc(ctlr->dev, sizeof(*pool), GFP_KERNEL);
if (!pool) if (!pool)
goto gen_pool_create_fail; goto gen_pool_create_fail;
ctlr->pool = pool;
pool->dev = dev; pool->mem_size = cpdma_params->desc_mem_size;
pool->mem_size = size; pool->desc_size = ALIGN(sizeof(struct cpdma_desc),
pool->desc_size = ALIGN(sizeof(struct cpdma_desc), align); cpdma_params->desc_align);
pool->num_desc = size / pool->desc_size; pool->num_desc = pool->mem_size / pool->desc_size;
pool->gen_pool = devm_gen_pool_create(dev, ilog2(pool->desc_size), -1, pool->gen_pool = devm_gen_pool_create(ctlr->dev, ilog2(pool->desc_size),
"cpdma"); -1, "cpdma");
if (IS_ERR(pool->gen_pool)) { if (IS_ERR(pool->gen_pool)) {
dev_err(dev, "pool create failed %ld\n", ret = PTR_ERR(pool->gen_pool);
PTR_ERR(pool->gen_pool)); dev_err(ctlr->dev, "pool create failed %d\n", ret);
goto gen_pool_create_fail; goto gen_pool_create_fail;
} }
if (phys) { if (cpdma_params->desc_mem_phys) {
pool->phys = phys; pool->phys = cpdma_params->desc_mem_phys;
pool->iomap = ioremap(phys, size); /* should be memremap? */ pool->iomap = ioremap(pool->phys, pool->mem_size);
pool->hw_addr = hw_addr; pool->hw_addr = cpdma_params->desc_hw_addr;
} else { } else {
pool->cpumap = dma_alloc_coherent(dev, size, &pool->hw_addr, pool->cpumap = dma_alloc_coherent(ctlr->dev, pool->mem_size,
GFP_KERNEL); &pool->hw_addr, GFP_KERNEL);
pool->iomap = (void __iomem __force *)pool->cpumap; pool->iomap = (void __iomem __force *)pool->cpumap;
pool->phys = pool->hw_addr; /* assumes no IOMMU, don't use this value */ pool->phys = pool->hw_addr; /* assumes no IOMMU, don't use this value */
} }
...@@ -244,16 +246,17 @@ cpdma_desc_pool_create(struct device *dev, u32 phys, dma_addr_t hw_addr, ...@@ -244,16 +246,17 @@ cpdma_desc_pool_create(struct device *dev, u32 phys, dma_addr_t hw_addr,
ret = gen_pool_add_virt(pool->gen_pool, (unsigned long)pool->iomap, ret = gen_pool_add_virt(pool->gen_pool, (unsigned long)pool->iomap,
pool->phys, pool->mem_size, -1); pool->phys, pool->mem_size, -1);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "pool add failed %d\n", ret); dev_err(ctlr->dev, "pool add failed %d\n", ret);
goto gen_pool_add_virt_fail; goto gen_pool_add_virt_fail;
} }
return pool; return 0;
gen_pool_add_virt_fail: gen_pool_add_virt_fail:
cpdma_desc_pool_destroy(pool); cpdma_desc_pool_destroy(ctlr);
gen_pool_create_fail: gen_pool_create_fail:
return NULL; ctlr->pool = NULL;
return ret;
} }
static inline dma_addr_t desc_phys(struct cpdma_desc_pool *pool, static inline dma_addr_t desc_phys(struct cpdma_desc_pool *pool,
...@@ -502,12 +505,7 @@ struct cpdma_ctlr *cpdma_ctlr_create(struct cpdma_params *params) ...@@ -502,12 +505,7 @@ struct cpdma_ctlr *cpdma_ctlr_create(struct cpdma_params *params)
ctlr->chan_num = 0; ctlr->chan_num = 0;
spin_lock_init(&ctlr->lock); spin_lock_init(&ctlr->lock);
ctlr->pool = cpdma_desc_pool_create(ctlr->dev, if (cpdma_desc_pool_create(ctlr))
ctlr->params.desc_mem_phys,
ctlr->params.desc_hw_addr,
ctlr->params.desc_mem_size,
ctlr->params.desc_align);
if (!ctlr->pool)
return NULL; return NULL;
if (WARN_ON(ctlr->num_chan > CPDMA_MAX_CHANNELS)) if (WARN_ON(ctlr->num_chan > CPDMA_MAX_CHANNELS))
...@@ -623,7 +621,7 @@ int cpdma_ctlr_destroy(struct cpdma_ctlr *ctlr) ...@@ -623,7 +621,7 @@ int cpdma_ctlr_destroy(struct cpdma_ctlr *ctlr)
for (i = 0; i < ARRAY_SIZE(ctlr->channels); i++) for (i = 0; i < ARRAY_SIZE(ctlr->channels); i++)
cpdma_chan_destroy(ctlr->channels[i]); cpdma_chan_destroy(ctlr->channels[i]);
cpdma_desc_pool_destroy(ctlr->pool); cpdma_desc_pool_destroy(ctlr);
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(cpdma_ctlr_destroy); EXPORT_SYMBOL_GPL(cpdma_ctlr_destroy);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment