Grygorii Strashko | 68cf027 | 2019-04-26 20:12:23 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Texas Instruments CPDMA Driver |
| 4 | * |
| 5 | * Copyright (C) 2010 Texas Instruments |
| 6 | * |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 7 | */ |
| 8 | #include <linux/kernel.h> |
| 9 | #include <linux/spinlock.h> |
| 10 | #include <linux/device.h> |
Daniel Mack | 76fbc24 | 2012-06-28 06:12:32 +0000 | [diff] [blame] | 11 | #include <linux/module.h> |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 12 | #include <linux/slab.h> |
| 13 | #include <linux/err.h> |
| 14 | #include <linux/dma-mapping.h> |
| 15 | #include <linux/io.h> |
Sebastian Siewior | 817f6d1 | 2013-04-23 07:31:35 +0000 | [diff] [blame] | 16 | #include <linux/delay.h> |
Grygorii Strashko | 742fb20 | 2016-06-27 12:05:11 +0300 | [diff] [blame] | 17 | #include <linux/genalloc.h> |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 18 | #include "davinci_cpdma.h" |
| 19 | |
| 20 | /* DMA Registers */ |
| 21 | #define CPDMA_TXIDVER 0x00 |
| 22 | #define CPDMA_TXCONTROL 0x04 |
| 23 | #define CPDMA_TXTEARDOWN 0x08 |
| 24 | #define CPDMA_RXIDVER 0x10 |
| 25 | #define CPDMA_RXCONTROL 0x14 |
| 26 | #define CPDMA_SOFTRESET 0x1c |
| 27 | #define CPDMA_RXTEARDOWN 0x18 |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 28 | #define CPDMA_TX_PRI0_RATE 0x30 |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 29 | #define CPDMA_TXINTSTATRAW 0x80 |
| 30 | #define CPDMA_TXINTSTATMASKED 0x84 |
| 31 | #define CPDMA_TXINTMASKSET 0x88 |
| 32 | #define CPDMA_TXINTMASKCLEAR 0x8c |
| 33 | #define CPDMA_MACINVECTOR 0x90 |
| 34 | #define CPDMA_MACEOIVECTOR 0x94 |
| 35 | #define CPDMA_RXINTSTATRAW 0xa0 |
| 36 | #define CPDMA_RXINTSTATMASKED 0xa4 |
| 37 | #define CPDMA_RXINTMASKSET 0xa8 |
| 38 | #define CPDMA_RXINTMASKCLEAR 0xac |
| 39 | #define CPDMA_DMAINTSTATRAW 0xb0 |
| 40 | #define CPDMA_DMAINTSTATMASKED 0xb4 |
| 41 | #define CPDMA_DMAINTMASKSET 0xb8 |
| 42 | #define CPDMA_DMAINTMASKCLEAR 0xbc |
| 43 | #define CPDMA_DMAINT_HOSTERR BIT(1) |
| 44 | |
| 45 | /* the following exist only if has_ext_regs is set */ |
| 46 | #define CPDMA_DMACONTROL 0x20 |
| 47 | #define CPDMA_DMASTATUS 0x24 |
| 48 | #define CPDMA_RXBUFFOFS 0x28 |
| 49 | #define CPDMA_EM_CONTROL 0x2c |
| 50 | |
| 51 | /* Descriptor mode bits */ |
| 52 | #define CPDMA_DESC_SOP BIT(31) |
| 53 | #define CPDMA_DESC_EOP BIT(30) |
| 54 | #define CPDMA_DESC_OWNER BIT(29) |
| 55 | #define CPDMA_DESC_EOQ BIT(28) |
| 56 | #define CPDMA_DESC_TD_COMPLETE BIT(27) |
| 57 | #define CPDMA_DESC_PASS_CRC BIT(26) |
Mugunthan V N | f6e135c | 2013-02-11 09:52:18 +0000 | [diff] [blame] | 58 | #define CPDMA_DESC_TO_PORT_EN BIT(20) |
| 59 | #define CPDMA_TO_PORT_SHIFT 16 |
| 60 | #define CPDMA_DESC_PORT_MASK (BIT(18) | BIT(17) | BIT(16)) |
Mugunthan V N | 28a19fe | 2013-05-29 20:22:01 +0000 | [diff] [blame] | 61 | #define CPDMA_DESC_CRC_LEN 4 |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 62 | |
| 63 | #define CPDMA_TEARDOWN_VALUE 0xfffffffc |
| 64 | |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 65 | #define CPDMA_MAX_RLIM_CNT 16384 |
| 66 | |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 67 | struct cpdma_desc { |
| 68 | /* hardware fields */ |
| 69 | u32 hw_next; |
| 70 | u32 hw_buffer; |
| 71 | u32 hw_len; |
| 72 | u32 hw_mode; |
| 73 | /* software fields */ |
| 74 | void *sw_token; |
| 75 | u32 sw_buffer; |
| 76 | u32 sw_len; |
| 77 | }; |
| 78 | |
| 79 | struct cpdma_desc_pool { |
Olof Johansson | c767db5 | 2013-12-11 15:51:20 -0800 | [diff] [blame] | 80 | phys_addr_t phys; |
Arnd Bergmann | 8409299 | 2016-01-29 12:39:10 +0100 | [diff] [blame] | 81 | dma_addr_t hw_addr; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 82 | void __iomem *iomap; /* ioremap map */ |
| 83 | void *cpumap; /* dma_alloc map */ |
| 84 | int desc_size, mem_size; |
Grygorii Strashko | aeec302 | 2016-08-04 18:20:51 +0300 | [diff] [blame] | 85 | int num_desc; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 86 | struct device *dev; |
Grygorii Strashko | 742fb20 | 2016-06-27 12:05:11 +0300 | [diff] [blame] | 87 | struct gen_pool *gen_pool; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | enum cpdma_state { |
| 91 | CPDMA_STATE_IDLE, |
| 92 | CPDMA_STATE_ACTIVE, |
| 93 | CPDMA_STATE_TEARDOWN, |
| 94 | }; |
| 95 | |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 96 | struct cpdma_ctlr { |
| 97 | enum cpdma_state state; |
| 98 | struct cpdma_params params; |
| 99 | struct device *dev; |
| 100 | struct cpdma_desc_pool *pool; |
| 101 | spinlock_t lock; |
| 102 | struct cpdma_chan *channels[2 * CPDMA_MAX_CHANNELS]; |
Ivan Khoronzhuk | 3802dce1 | 2016-08-22 21:18:24 +0300 | [diff] [blame] | 103 | int chan_num; |
Grygorii Strashko | be034fc | 2017-01-06 14:07:34 -0600 | [diff] [blame] | 104 | int num_rx_desc; /* RX descriptors number */ |
| 105 | int num_tx_desc; /* TX descriptors number */ |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | struct cpdma_chan { |
Mugunthan V N | fae5082 | 2013-01-17 06:31:34 +0000 | [diff] [blame] | 109 | struct cpdma_desc __iomem *head, *tail; |
| 110 | void __iomem *hdp, *cp, *rxfree; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 111 | enum cpdma_state state; |
| 112 | struct cpdma_ctlr *ctlr; |
| 113 | int chan_num; |
| 114 | spinlock_t lock; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 115 | int count; |
Grygorii Strashko | 742fb20 | 2016-06-27 12:05:11 +0300 | [diff] [blame] | 116 | u32 desc_num; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 117 | u32 mask; |
| 118 | cpdma_handler_fn handler; |
| 119 | enum dma_data_direction dir; |
| 120 | struct cpdma_chan_stats stats; |
| 121 | /* offsets into dmaregs */ |
| 122 | int int_set, int_clear, td; |
Ivan Khoronzhuk | 0fc6432 | 2016-11-29 17:00:47 +0200 | [diff] [blame] | 123 | int weight; |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 124 | u32 rate_factor; |
| 125 | u32 rate; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 126 | }; |
| 127 | |
Ivan Khoronzhuk | 991ddb1 | 2016-11-11 15:45:24 +0200 | [diff] [blame] | 128 | struct cpdma_control_info { |
| 129 | u32 reg; |
| 130 | u32 shift, mask; |
| 131 | int access; |
| 132 | #define ACCESS_RO BIT(0) |
| 133 | #define ACCESS_WO BIT(1) |
| 134 | #define ACCESS_RW (ACCESS_RO | ACCESS_WO) |
| 135 | }; |
| 136 | |
| 137 | static struct cpdma_control_info controls[] = { |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 138 | [CPDMA_TX_RLIM] = {CPDMA_DMACONTROL, 8, 0xffff, ACCESS_RW}, |
Ivan Khoronzhuk | 991ddb1 | 2016-11-11 15:45:24 +0200 | [diff] [blame] | 139 | [CPDMA_CMD_IDLE] = {CPDMA_DMACONTROL, 3, 1, ACCESS_WO}, |
| 140 | [CPDMA_COPY_ERROR_FRAMES] = {CPDMA_DMACONTROL, 4, 1, ACCESS_RW}, |
| 141 | [CPDMA_RX_OFF_LEN_UPDATE] = {CPDMA_DMACONTROL, 2, 1, ACCESS_RW}, |
| 142 | [CPDMA_RX_OWNERSHIP_FLIP] = {CPDMA_DMACONTROL, 1, 1, ACCESS_RW}, |
| 143 | [CPDMA_TX_PRIO_FIXED] = {CPDMA_DMACONTROL, 0, 1, ACCESS_RW}, |
| 144 | [CPDMA_STAT_IDLE] = {CPDMA_DMASTATUS, 31, 1, ACCESS_RO}, |
| 145 | [CPDMA_STAT_TX_ERR_CODE] = {CPDMA_DMASTATUS, 20, 0xf, ACCESS_RW}, |
| 146 | [CPDMA_STAT_TX_ERR_CHAN] = {CPDMA_DMASTATUS, 16, 0x7, ACCESS_RW}, |
| 147 | [CPDMA_STAT_RX_ERR_CODE] = {CPDMA_DMASTATUS, 12, 0xf, ACCESS_RW}, |
| 148 | [CPDMA_STAT_RX_ERR_CHAN] = {CPDMA_DMASTATUS, 8, 0x7, ACCESS_RW}, |
| 149 | [CPDMA_RX_BUFFER_OFFSET] = {CPDMA_RXBUFFOFS, 0, 0xffff, ACCESS_RW}, |
| 150 | }; |
| 151 | |
Ivan Khoronzhuk | 925d65e | 2016-08-22 21:18:27 +0300 | [diff] [blame] | 152 | #define tx_chan_num(chan) (chan) |
| 153 | #define rx_chan_num(chan) ((chan) + CPDMA_MAX_CHANNELS) |
| 154 | #define is_rx_chan(chan) ((chan)->chan_num >= CPDMA_MAX_CHANNELS) |
| 155 | #define is_tx_chan(chan) (!is_rx_chan(chan)) |
| 156 | #define __chan_linear(chan_num) ((chan_num) & (CPDMA_MAX_CHANNELS - 1)) |
| 157 | #define chan_linear(chan) __chan_linear((chan)->chan_num) |
| 158 | |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 159 | /* The following make access to common cpdma_ctlr params more readable */ |
| 160 | #define dmaregs params.dmaregs |
| 161 | #define num_chan params.num_chan |
| 162 | |
| 163 | /* various accessors */ |
Grygorii Strashko | a6c83cc | 2017-01-06 14:07:29 -0600 | [diff] [blame] | 164 | #define dma_reg_read(ctlr, ofs) readl((ctlr)->dmaregs + (ofs)) |
| 165 | #define chan_read(chan, fld) readl((chan)->fld) |
| 166 | #define desc_read(desc, fld) readl(&(desc)->fld) |
| 167 | #define dma_reg_write(ctlr, ofs, v) writel(v, (ctlr)->dmaregs + (ofs)) |
| 168 | #define chan_write(chan, fld, v) writel(v, (chan)->fld) |
| 169 | #define desc_write(desc, fld, v) writel((u32)(v), &(desc)->fld) |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 170 | |
Mugunthan V N | f6e135c | 2013-02-11 09:52:18 +0000 | [diff] [blame] | 171 | #define cpdma_desc_to_port(chan, mode, directed) \ |
| 172 | do { \ |
| 173 | if (!is_rx_chan(chan) && ((directed == 1) || \ |
| 174 | (directed == 2))) \ |
| 175 | mode |= (CPDMA_DESC_TO_PORT_EN | \ |
| 176 | (directed << CPDMA_TO_PORT_SHIFT)); \ |
| 177 | } while (0) |
| 178 | |
Grygorii Strashko | 5fcc40a | 2017-01-06 14:07:31 -0600 | [diff] [blame] | 179 | static void cpdma_desc_pool_destroy(struct cpdma_ctlr *ctlr) |
Grygorii Strashko | 742fb20 | 2016-06-27 12:05:11 +0300 | [diff] [blame] | 180 | { |
Grygorii Strashko | 5fcc40a | 2017-01-06 14:07:31 -0600 | [diff] [blame] | 181 | struct cpdma_desc_pool *pool = ctlr->pool; |
| 182 | |
Grygorii Strashko | 742fb20 | 2016-06-27 12:05:11 +0300 | [diff] [blame] | 183 | if (!pool) |
| 184 | return; |
| 185 | |
Grygorii Strashko | aeec302 | 2016-08-04 18:20:51 +0300 | [diff] [blame] | 186 | WARN(gen_pool_size(pool->gen_pool) != gen_pool_avail(pool->gen_pool), |
Florian Fainelli | b4eb739 | 2018-05-21 11:45:51 -0700 | [diff] [blame] | 187 | "cpdma_desc_pool size %zd != avail %zd", |
Grygorii Strashko | aeec302 | 2016-08-04 18:20:51 +0300 | [diff] [blame] | 188 | gen_pool_size(pool->gen_pool), |
| 189 | gen_pool_avail(pool->gen_pool)); |
Grygorii Strashko | 742fb20 | 2016-06-27 12:05:11 +0300 | [diff] [blame] | 190 | if (pool->cpumap) |
Grygorii Strashko | 5fcc40a | 2017-01-06 14:07:31 -0600 | [diff] [blame] | 191 | dma_free_coherent(ctlr->dev, pool->mem_size, pool->cpumap, |
Grygorii Strashko | 742fb20 | 2016-06-27 12:05:11 +0300 | [diff] [blame] | 192 | pool->phys); |
Grygorii Strashko | 742fb20 | 2016-06-27 12:05:11 +0300 | [diff] [blame] | 193 | } |
| 194 | |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 195 | /* |
| 196 | * Utility constructs for a cpdma descriptor pool. Some devices (e.g. davinci |
| 197 | * emac) have dedicated on-chip memory for these descriptors. Some other |
| 198 | * devices (e.g. cpsw switches) use plain old memory. Descriptor pools |
| 199 | * abstract out these details |
| 200 | */ |
Colin Ian King | 40141bb4 | 2018-06-21 18:16:45 +0100 | [diff] [blame] | 201 | static int cpdma_desc_pool_create(struct cpdma_ctlr *ctlr) |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 202 | { |
Grygorii Strashko | 5fcc40a | 2017-01-06 14:07:31 -0600 | [diff] [blame] | 203 | struct cpdma_params *cpdma_params = &ctlr->params; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 204 | struct cpdma_desc_pool *pool; |
Grygorii Strashko | 5fcc40a | 2017-01-06 14:07:31 -0600 | [diff] [blame] | 205 | int ret = -ENOMEM; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 206 | |
Grygorii Strashko | 5fcc40a | 2017-01-06 14:07:31 -0600 | [diff] [blame] | 207 | pool = devm_kzalloc(ctlr->dev, sizeof(*pool), GFP_KERNEL); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 208 | if (!pool) |
Grygorii Strashko | 742fb20 | 2016-06-27 12:05:11 +0300 | [diff] [blame] | 209 | goto gen_pool_create_fail; |
Grygorii Strashko | 5fcc40a | 2017-01-06 14:07:31 -0600 | [diff] [blame] | 210 | ctlr->pool = pool; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 211 | |
Grygorii Strashko | 5fcc40a | 2017-01-06 14:07:31 -0600 | [diff] [blame] | 212 | pool->mem_size = cpdma_params->desc_mem_size; |
| 213 | pool->desc_size = ALIGN(sizeof(struct cpdma_desc), |
| 214 | cpdma_params->desc_align); |
| 215 | pool->num_desc = pool->mem_size / pool->desc_size; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 216 | |
Grygorii Strashko | 90225bf | 2017-01-06 14:07:33 -0600 | [diff] [blame] | 217 | if (cpdma_params->descs_pool_size) { |
| 218 | /* recalculate memory size required cpdma descriptor pool |
| 219 | * basing on number of descriptors specified by user and |
| 220 | * if memory size > CPPI internal RAM size (desc_mem_size) |
| 221 | * then switch to use DDR |
| 222 | */ |
| 223 | pool->num_desc = cpdma_params->descs_pool_size; |
| 224 | pool->mem_size = pool->desc_size * pool->num_desc; |
| 225 | if (pool->mem_size > cpdma_params->desc_mem_size) |
| 226 | cpdma_params->desc_mem_phys = 0; |
| 227 | } |
| 228 | |
Grygorii Strashko | 5fcc40a | 2017-01-06 14:07:31 -0600 | [diff] [blame] | 229 | pool->gen_pool = devm_gen_pool_create(ctlr->dev, ilog2(pool->desc_size), |
| 230 | -1, "cpdma"); |
Grygorii Strashko | 742fb20 | 2016-06-27 12:05:11 +0300 | [diff] [blame] | 231 | if (IS_ERR(pool->gen_pool)) { |
Grygorii Strashko | 5fcc40a | 2017-01-06 14:07:31 -0600 | [diff] [blame] | 232 | ret = PTR_ERR(pool->gen_pool); |
| 233 | dev_err(ctlr->dev, "pool create failed %d\n", ret); |
Grygorii Strashko | 742fb20 | 2016-06-27 12:05:11 +0300 | [diff] [blame] | 234 | goto gen_pool_create_fail; |
| 235 | } |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 236 | |
Grygorii Strashko | 5fcc40a | 2017-01-06 14:07:31 -0600 | [diff] [blame] | 237 | if (cpdma_params->desc_mem_phys) { |
| 238 | pool->phys = cpdma_params->desc_mem_phys; |
Grygorii Strashko | 7f3b490 | 2017-01-06 14:07:32 -0600 | [diff] [blame] | 239 | pool->iomap = devm_ioremap(ctlr->dev, pool->phys, |
| 240 | pool->mem_size); |
Grygorii Strashko | 5fcc40a | 2017-01-06 14:07:31 -0600 | [diff] [blame] | 241 | pool->hw_addr = cpdma_params->desc_hw_addr; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 242 | } else { |
Grygorii Strashko | 5fcc40a | 2017-01-06 14:07:31 -0600 | [diff] [blame] | 243 | pool->cpumap = dma_alloc_coherent(ctlr->dev, pool->mem_size, |
| 244 | &pool->hw_addr, GFP_KERNEL); |
Arnd Bergmann | 8409299 | 2016-01-29 12:39:10 +0100 | [diff] [blame] | 245 | pool->iomap = (void __iomem __force *)pool->cpumap; |
| 246 | pool->phys = pool->hw_addr; /* assumes no IOMMU, don't use this value */ |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 247 | } |
| 248 | |
Grygorii Strashko | 742fb20 | 2016-06-27 12:05:11 +0300 | [diff] [blame] | 249 | if (!pool->iomap) |
| 250 | goto gen_pool_create_fail; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 251 | |
Grygorii Strashko | 742fb20 | 2016-06-27 12:05:11 +0300 | [diff] [blame] | 252 | ret = gen_pool_add_virt(pool->gen_pool, (unsigned long)pool->iomap, |
| 253 | pool->phys, pool->mem_size, -1); |
| 254 | if (ret < 0) { |
Grygorii Strashko | 5fcc40a | 2017-01-06 14:07:31 -0600 | [diff] [blame] | 255 | dev_err(ctlr->dev, "pool add failed %d\n", ret); |
Grygorii Strashko | 742fb20 | 2016-06-27 12:05:11 +0300 | [diff] [blame] | 256 | goto gen_pool_add_virt_fail; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 257 | } |
Grygorii Strashko | 742fb20 | 2016-06-27 12:05:11 +0300 | [diff] [blame] | 258 | |
Grygorii Strashko | 5fcc40a | 2017-01-06 14:07:31 -0600 | [diff] [blame] | 259 | return 0; |
Grygorii Strashko | 742fb20 | 2016-06-27 12:05:11 +0300 | [diff] [blame] | 260 | |
| 261 | gen_pool_add_virt_fail: |
Grygorii Strashko | 5fcc40a | 2017-01-06 14:07:31 -0600 | [diff] [blame] | 262 | cpdma_desc_pool_destroy(ctlr); |
Grygorii Strashko | 742fb20 | 2016-06-27 12:05:11 +0300 | [diff] [blame] | 263 | gen_pool_create_fail: |
Grygorii Strashko | 5fcc40a | 2017-01-06 14:07:31 -0600 | [diff] [blame] | 264 | ctlr->pool = NULL; |
| 265 | return ret; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | static inline dma_addr_t desc_phys(struct cpdma_desc_pool *pool, |
| 269 | struct cpdma_desc __iomem *desc) |
| 270 | { |
| 271 | if (!desc) |
| 272 | return 0; |
Olof Johansson | c767db5 | 2013-12-11 15:51:20 -0800 | [diff] [blame] | 273 | return pool->hw_addr + (__force long)desc - (__force long)pool->iomap; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | static inline struct cpdma_desc __iomem * |
| 277 | desc_from_phys(struct cpdma_desc_pool *pool, dma_addr_t dma) |
| 278 | { |
Sriram | 6a1fef6 | 2011-03-22 02:31:03 +0000 | [diff] [blame] | 279 | return dma ? pool->iomap + dma - pool->hw_addr : NULL; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | static struct cpdma_desc __iomem * |
Grygorii Strashko | 742fb20 | 2016-06-27 12:05:11 +0300 | [diff] [blame] | 283 | cpdma_desc_alloc(struct cpdma_desc_pool *pool) |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 284 | { |
Grygorii Strashko | aeec302 | 2016-08-04 18:20:51 +0300 | [diff] [blame] | 285 | return (struct cpdma_desc __iomem *) |
| 286 | gen_pool_alloc(pool->gen_pool, pool->desc_size); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | static void cpdma_desc_free(struct cpdma_desc_pool *pool, |
| 290 | struct cpdma_desc __iomem *desc, int num_desc) |
| 291 | { |
Grygorii Strashko | 742fb20 | 2016-06-27 12:05:11 +0300 | [diff] [blame] | 292 | gen_pool_free(pool->gen_pool, (unsigned long)desc, pool->desc_size); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 293 | } |
| 294 | |
Ivan Khoronzhuk | 991ddb1 | 2016-11-11 15:45:24 +0200 | [diff] [blame] | 295 | static int _cpdma_control_set(struct cpdma_ctlr *ctlr, int control, int value) |
| 296 | { |
| 297 | struct cpdma_control_info *info = &controls[control]; |
| 298 | u32 val; |
| 299 | |
| 300 | if (!ctlr->params.has_ext_regs) |
| 301 | return -ENOTSUPP; |
| 302 | |
| 303 | if (ctlr->state != CPDMA_STATE_ACTIVE) |
| 304 | return -EINVAL; |
| 305 | |
| 306 | if (control < 0 || control >= ARRAY_SIZE(controls)) |
| 307 | return -ENOENT; |
| 308 | |
| 309 | if ((info->access & ACCESS_WO) != ACCESS_WO) |
| 310 | return -EPERM; |
| 311 | |
| 312 | val = dma_reg_read(ctlr, info->reg); |
| 313 | val &= ~(info->mask << info->shift); |
| 314 | val |= (value & info->mask) << info->shift; |
| 315 | dma_reg_write(ctlr, info->reg, val); |
| 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 320 | static int _cpdma_control_get(struct cpdma_ctlr *ctlr, int control) |
| 321 | { |
| 322 | struct cpdma_control_info *info = &controls[control]; |
| 323 | int ret; |
| 324 | |
| 325 | if (!ctlr->params.has_ext_regs) |
| 326 | return -ENOTSUPP; |
| 327 | |
| 328 | if (ctlr->state != CPDMA_STATE_ACTIVE) |
| 329 | return -EINVAL; |
| 330 | |
| 331 | if (control < 0 || control >= ARRAY_SIZE(controls)) |
| 332 | return -ENOENT; |
| 333 | |
| 334 | if ((info->access & ACCESS_RO) != ACCESS_RO) |
| 335 | return -EPERM; |
| 336 | |
| 337 | ret = (dma_reg_read(ctlr, info->reg) >> info->shift) & info->mask; |
| 338 | return ret; |
| 339 | } |
| 340 | |
| 341 | /* cpdma_chan_set_chan_shaper - set shaper for a channel |
| 342 | * Has to be called under ctlr lock |
| 343 | */ |
| 344 | static int cpdma_chan_set_chan_shaper(struct cpdma_chan *chan) |
| 345 | { |
| 346 | struct cpdma_ctlr *ctlr = chan->ctlr; |
| 347 | u32 rate_reg; |
| 348 | u32 rmask; |
| 349 | int ret; |
| 350 | |
| 351 | if (!chan->rate) |
| 352 | return 0; |
| 353 | |
| 354 | rate_reg = CPDMA_TX_PRI0_RATE + 4 * chan->chan_num; |
| 355 | dma_reg_write(ctlr, rate_reg, chan->rate_factor); |
| 356 | |
| 357 | rmask = _cpdma_control_get(ctlr, CPDMA_TX_RLIM); |
| 358 | rmask |= chan->mask; |
| 359 | |
| 360 | ret = _cpdma_control_set(ctlr, CPDMA_TX_RLIM, rmask); |
| 361 | return ret; |
| 362 | } |
| 363 | |
| 364 | static int cpdma_chan_on(struct cpdma_chan *chan) |
| 365 | { |
| 366 | struct cpdma_ctlr *ctlr = chan->ctlr; |
| 367 | struct cpdma_desc_pool *pool = ctlr->pool; |
| 368 | unsigned long flags; |
| 369 | |
| 370 | spin_lock_irqsave(&chan->lock, flags); |
| 371 | if (chan->state != CPDMA_STATE_IDLE) { |
| 372 | spin_unlock_irqrestore(&chan->lock, flags); |
| 373 | return -EBUSY; |
| 374 | } |
| 375 | if (ctlr->state != CPDMA_STATE_ACTIVE) { |
| 376 | spin_unlock_irqrestore(&chan->lock, flags); |
| 377 | return -EINVAL; |
| 378 | } |
| 379 | dma_reg_write(ctlr, chan->int_set, chan->mask); |
| 380 | chan->state = CPDMA_STATE_ACTIVE; |
| 381 | if (chan->head) { |
| 382 | chan_write(chan, hdp, desc_phys(pool, chan->head)); |
| 383 | if (chan->rxfree) |
| 384 | chan_write(chan, rxfree, chan->count); |
| 385 | } |
| 386 | |
| 387 | spin_unlock_irqrestore(&chan->lock, flags); |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | /* cpdma_chan_fit_rate - set rate for a channel and check if it's possible. |
| 392 | * rmask - mask of rate limited channels |
| 393 | * Returns min rate in Kb/s |
| 394 | */ |
| 395 | static int cpdma_chan_fit_rate(struct cpdma_chan *ch, u32 rate, |
| 396 | u32 *rmask, int *prio_mode) |
| 397 | { |
| 398 | struct cpdma_ctlr *ctlr = ch->ctlr; |
| 399 | struct cpdma_chan *chan; |
| 400 | u32 old_rate = ch->rate; |
| 401 | u32 new_rmask = 0; |
Ivan Khoronzhuk | 4bb6c35 | 2018-07-24 00:26:30 +0300 | [diff] [blame] | 402 | int rlim = 0; |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 403 | int i; |
| 404 | |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 405 | for (i = tx_chan_num(0); i < tx_chan_num(CPDMA_MAX_CHANNELS); i++) { |
| 406 | chan = ctlr->channels[i]; |
Ivan Khoronzhuk | 4bb6c35 | 2018-07-24 00:26:30 +0300 | [diff] [blame] | 407 | if (!chan) |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 408 | continue; |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 409 | |
| 410 | if (chan == ch) |
| 411 | chan->rate = rate; |
| 412 | |
| 413 | if (chan->rate) { |
Ivan Khoronzhuk | 4bb6c35 | 2018-07-24 00:26:30 +0300 | [diff] [blame] | 414 | rlim = 1; |
| 415 | new_rmask |= chan->mask; |
| 416 | continue; |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 417 | } |
Ivan Khoronzhuk | 4bb6c35 | 2018-07-24 00:26:30 +0300 | [diff] [blame] | 418 | |
| 419 | if (rlim) |
| 420 | goto err; |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | *rmask = new_rmask; |
Ivan Khoronzhuk | 4bb6c35 | 2018-07-24 00:26:30 +0300 | [diff] [blame] | 424 | *prio_mode = rlim; |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 425 | return 0; |
Ivan Khoronzhuk | 4bb6c35 | 2018-07-24 00:26:30 +0300 | [diff] [blame] | 426 | |
| 427 | err: |
| 428 | ch->rate = old_rate; |
| 429 | dev_err(ctlr->dev, "Upper cpdma ch%d is not rate limited\n", |
| 430 | chan->chan_num); |
| 431 | return -EINVAL; |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | static u32 cpdma_chan_set_factors(struct cpdma_ctlr *ctlr, |
| 435 | struct cpdma_chan *ch) |
| 436 | { |
| 437 | u32 delta = UINT_MAX, prev_delta = UINT_MAX, best_delta = UINT_MAX; |
| 438 | u32 best_send_cnt = 0, best_idle_cnt = 0; |
| 439 | u32 new_rate, best_rate = 0, rate_reg; |
| 440 | u64 send_cnt, idle_cnt; |
| 441 | u32 min_send_cnt, freq; |
| 442 | u64 divident, divisor; |
| 443 | |
| 444 | if (!ch->rate) { |
| 445 | ch->rate_factor = 0; |
| 446 | goto set_factor; |
| 447 | } |
| 448 | |
| 449 | freq = ctlr->params.bus_freq_mhz * 1000 * 32; |
| 450 | if (!freq) { |
| 451 | dev_err(ctlr->dev, "The bus frequency is not set\n"); |
| 452 | return -EINVAL; |
| 453 | } |
| 454 | |
| 455 | min_send_cnt = freq - ch->rate; |
| 456 | send_cnt = DIV_ROUND_UP(min_send_cnt, ch->rate); |
| 457 | while (send_cnt <= CPDMA_MAX_RLIM_CNT) { |
| 458 | divident = ch->rate * send_cnt; |
| 459 | divisor = min_send_cnt; |
| 460 | idle_cnt = DIV_ROUND_CLOSEST_ULL(divident, divisor); |
| 461 | |
| 462 | divident = freq * idle_cnt; |
| 463 | divisor = idle_cnt + send_cnt; |
| 464 | new_rate = DIV_ROUND_CLOSEST_ULL(divident, divisor); |
| 465 | |
| 466 | delta = new_rate >= ch->rate ? new_rate - ch->rate : delta; |
| 467 | if (delta < best_delta) { |
| 468 | best_delta = delta; |
| 469 | best_send_cnt = send_cnt; |
| 470 | best_idle_cnt = idle_cnt; |
| 471 | best_rate = new_rate; |
| 472 | |
| 473 | if (!delta) |
| 474 | break; |
| 475 | } |
| 476 | |
| 477 | if (prev_delta >= delta) { |
| 478 | prev_delta = delta; |
| 479 | send_cnt++; |
| 480 | continue; |
| 481 | } |
| 482 | |
| 483 | idle_cnt++; |
| 484 | divident = freq * idle_cnt; |
| 485 | send_cnt = DIV_ROUND_CLOSEST_ULL(divident, ch->rate); |
| 486 | send_cnt -= idle_cnt; |
| 487 | prev_delta = UINT_MAX; |
| 488 | } |
| 489 | |
| 490 | ch->rate = best_rate; |
| 491 | ch->rate_factor = best_send_cnt | (best_idle_cnt << 16); |
| 492 | |
| 493 | set_factor: |
| 494 | rate_reg = CPDMA_TX_PRI0_RATE + 4 * ch->chan_num; |
| 495 | dma_reg_write(ctlr, rate_reg, ch->rate_factor); |
| 496 | return 0; |
| 497 | } |
| 498 | |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 499 | struct cpdma_ctlr *cpdma_ctlr_create(struct cpdma_params *params) |
| 500 | { |
| 501 | struct cpdma_ctlr *ctlr; |
| 502 | |
George Cherian | e194312 | 2014-05-12 10:21:21 +0530 | [diff] [blame] | 503 | ctlr = devm_kzalloc(params->dev, sizeof(*ctlr), GFP_KERNEL); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 504 | if (!ctlr) |
| 505 | return NULL; |
| 506 | |
| 507 | ctlr->state = CPDMA_STATE_IDLE; |
| 508 | ctlr->params = *params; |
| 509 | ctlr->dev = params->dev; |
Ivan Khoronzhuk | 3802dce1 | 2016-08-22 21:18:24 +0300 | [diff] [blame] | 510 | ctlr->chan_num = 0; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 511 | spin_lock_init(&ctlr->lock); |
| 512 | |
Grygorii Strashko | 5fcc40a | 2017-01-06 14:07:31 -0600 | [diff] [blame] | 513 | if (cpdma_desc_pool_create(ctlr)) |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 514 | return NULL; |
Grygorii Strashko | be034fc | 2017-01-06 14:07:34 -0600 | [diff] [blame] | 515 | /* split pool equally between RX/TX by default */ |
| 516 | ctlr->num_tx_desc = ctlr->pool->num_desc / 2; |
| 517 | ctlr->num_rx_desc = ctlr->pool->num_desc - ctlr->num_tx_desc; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 518 | |
| 519 | if (WARN_ON(ctlr->num_chan > CPDMA_MAX_CHANNELS)) |
| 520 | ctlr->num_chan = CPDMA_MAX_CHANNELS; |
| 521 | return ctlr; |
| 522 | } |
| 523 | |
| 524 | int cpdma_ctlr_start(struct cpdma_ctlr *ctlr) |
| 525 | { |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 526 | struct cpdma_chan *chan; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 527 | unsigned long flags; |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 528 | int i, prio_mode; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 529 | |
| 530 | spin_lock_irqsave(&ctlr->lock, flags); |
| 531 | if (ctlr->state != CPDMA_STATE_IDLE) { |
| 532 | spin_unlock_irqrestore(&ctlr->lock, flags); |
| 533 | return -EBUSY; |
| 534 | } |
| 535 | |
| 536 | if (ctlr->params.has_soft_reset) { |
Sebastian Siewior | 817f6d1 | 2013-04-23 07:31:35 +0000 | [diff] [blame] | 537 | unsigned timeout = 10 * 100; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 538 | |
| 539 | dma_reg_write(ctlr, CPDMA_SOFTRESET, 1); |
Sebastian Siewior | 817f6d1 | 2013-04-23 07:31:35 +0000 | [diff] [blame] | 540 | while (timeout) { |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 541 | if (dma_reg_read(ctlr, CPDMA_SOFTRESET) == 0) |
| 542 | break; |
Sebastian Siewior | 817f6d1 | 2013-04-23 07:31:35 +0000 | [diff] [blame] | 543 | udelay(10); |
| 544 | timeout--; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 545 | } |
Sebastian Siewior | 817f6d1 | 2013-04-23 07:31:35 +0000 | [diff] [blame] | 546 | WARN_ON(!timeout); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | for (i = 0; i < ctlr->num_chan; i++) { |
Grygorii Strashko | a6c83cc | 2017-01-06 14:07:29 -0600 | [diff] [blame] | 550 | writel(0, ctlr->params.txhdp + 4 * i); |
| 551 | writel(0, ctlr->params.rxhdp + 4 * i); |
| 552 | writel(0, ctlr->params.txcp + 4 * i); |
| 553 | writel(0, ctlr->params.rxcp + 4 * i); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | dma_reg_write(ctlr, CPDMA_RXINTMASKCLEAR, 0xffffffff); |
| 557 | dma_reg_write(ctlr, CPDMA_TXINTMASKCLEAR, 0xffffffff); |
| 558 | |
| 559 | dma_reg_write(ctlr, CPDMA_TXCONTROL, 1); |
| 560 | dma_reg_write(ctlr, CPDMA_RXCONTROL, 1); |
| 561 | |
| 562 | ctlr->state = CPDMA_STATE_ACTIVE; |
| 563 | |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 564 | prio_mode = 0; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 565 | for (i = 0; i < ARRAY_SIZE(ctlr->channels); i++) { |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 566 | chan = ctlr->channels[i]; |
| 567 | if (chan) { |
| 568 | cpdma_chan_set_chan_shaper(chan); |
| 569 | cpdma_chan_on(chan); |
| 570 | |
| 571 | /* off prio mode if all tx channels are rate limited */ |
| 572 | if (is_tx_chan(chan) && !chan->rate) |
| 573 | prio_mode = 1; |
| 574 | } |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 575 | } |
Ivan Khoronzhuk | 991ddb1 | 2016-11-11 15:45:24 +0200 | [diff] [blame] | 576 | |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 577 | _cpdma_control_set(ctlr, CPDMA_TX_PRIO_FIXED, prio_mode); |
Ivan Khoronzhuk | 991ddb1 | 2016-11-11 15:45:24 +0200 | [diff] [blame] | 578 | _cpdma_control_set(ctlr, CPDMA_RX_BUFFER_OFFSET, 0); |
| 579 | |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 580 | spin_unlock_irqrestore(&ctlr->lock, flags); |
| 581 | return 0; |
| 582 | } |
| 583 | |
| 584 | int cpdma_ctlr_stop(struct cpdma_ctlr *ctlr) |
| 585 | { |
| 586 | unsigned long flags; |
| 587 | int i; |
| 588 | |
| 589 | spin_lock_irqsave(&ctlr->lock, flags); |
Ivan Khoronzhuk | b993eec | 2016-11-11 16:10:47 +0200 | [diff] [blame] | 590 | if (ctlr->state != CPDMA_STATE_ACTIVE) { |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 591 | spin_unlock_irqrestore(&ctlr->lock, flags); |
| 592 | return -EINVAL; |
| 593 | } |
| 594 | |
| 595 | ctlr->state = CPDMA_STATE_TEARDOWN; |
Ivan Khoronzhuk | 080d5c5a | 2016-08-22 21:18:25 +0300 | [diff] [blame] | 596 | spin_unlock_irqrestore(&ctlr->lock, flags); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 597 | |
| 598 | for (i = 0; i < ARRAY_SIZE(ctlr->channels); i++) { |
| 599 | if (ctlr->channels[i]) |
| 600 | cpdma_chan_stop(ctlr->channels[i]); |
| 601 | } |
| 602 | |
Ivan Khoronzhuk | 080d5c5a | 2016-08-22 21:18:25 +0300 | [diff] [blame] | 603 | spin_lock_irqsave(&ctlr->lock, flags); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 604 | dma_reg_write(ctlr, CPDMA_RXINTMASKCLEAR, 0xffffffff); |
| 605 | dma_reg_write(ctlr, CPDMA_TXINTMASKCLEAR, 0xffffffff); |
| 606 | |
| 607 | dma_reg_write(ctlr, CPDMA_TXCONTROL, 0); |
| 608 | dma_reg_write(ctlr, CPDMA_RXCONTROL, 0); |
| 609 | |
| 610 | ctlr->state = CPDMA_STATE_IDLE; |
| 611 | |
| 612 | spin_unlock_irqrestore(&ctlr->lock, flags); |
| 613 | return 0; |
| 614 | } |
| 615 | |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 616 | int cpdma_ctlr_destroy(struct cpdma_ctlr *ctlr) |
| 617 | { |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 618 | int ret = 0, i; |
| 619 | |
| 620 | if (!ctlr) |
| 621 | return -EINVAL; |
| 622 | |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 623 | if (ctlr->state != CPDMA_STATE_IDLE) |
| 624 | cpdma_ctlr_stop(ctlr); |
| 625 | |
Cyril Roelandt | 79876e0 | 2013-02-12 12:52:30 +0000 | [diff] [blame] | 626 | for (i = 0; i < ARRAY_SIZE(ctlr->channels); i++) |
| 627 | cpdma_chan_destroy(ctlr->channels[i]); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 628 | |
Grygorii Strashko | 5fcc40a | 2017-01-06 14:07:31 -0600 | [diff] [blame] | 629 | cpdma_desc_pool_destroy(ctlr); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 630 | return ret; |
| 631 | } |
| 632 | |
| 633 | int cpdma_ctlr_int_ctrl(struct cpdma_ctlr *ctlr, bool enable) |
| 634 | { |
| 635 | unsigned long flags; |
Grygorii Strashko | 6d307f6 | 2017-06-08 13:51:52 -0500 | [diff] [blame] | 636 | int i; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 637 | |
| 638 | spin_lock_irqsave(&ctlr->lock, flags); |
| 639 | if (ctlr->state != CPDMA_STATE_ACTIVE) { |
| 640 | spin_unlock_irqrestore(&ctlr->lock, flags); |
| 641 | return -EINVAL; |
| 642 | } |
| 643 | |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 644 | for (i = 0; i < ARRAY_SIZE(ctlr->channels); i++) { |
| 645 | if (ctlr->channels[i]) |
| 646 | cpdma_chan_int_ctrl(ctlr->channels[i], enable); |
| 647 | } |
| 648 | |
| 649 | spin_unlock_irqrestore(&ctlr->lock, flags); |
| 650 | return 0; |
| 651 | } |
| 652 | |
Mugunthan V N | 510a1e72 | 2013-02-17 22:19:20 +0000 | [diff] [blame] | 653 | void cpdma_ctlr_eoi(struct cpdma_ctlr *ctlr, u32 value) |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 654 | { |
Mugunthan V N | 510a1e72 | 2013-02-17 22:19:20 +0000 | [diff] [blame] | 655 | dma_reg_write(ctlr, CPDMA_MACEOIVECTOR, value); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 656 | } |
| 657 | |
Ivan Khoronzhuk | e05107e | 2016-08-22 21:18:26 +0300 | [diff] [blame] | 658 | u32 cpdma_ctrl_rxchs_state(struct cpdma_ctlr *ctlr) |
| 659 | { |
| 660 | return dma_reg_read(ctlr, CPDMA_RXINTSTATMASKED); |
| 661 | } |
Ivan Khoronzhuk | e05107e | 2016-08-22 21:18:26 +0300 | [diff] [blame] | 662 | |
| 663 | u32 cpdma_ctrl_txchs_state(struct cpdma_ctlr *ctlr) |
| 664 | { |
| 665 | return dma_reg_read(ctlr, CPDMA_TXINTSTATMASKED); |
| 666 | } |
Ivan Khoronzhuk | e05107e | 2016-08-22 21:18:26 +0300 | [diff] [blame] | 667 | |
Ivan Khoronzhuk | 0fc6432 | 2016-11-29 17:00:47 +0200 | [diff] [blame] | 668 | static void cpdma_chan_set_descs(struct cpdma_ctlr *ctlr, |
| 669 | int rx, int desc_num, |
| 670 | int per_ch_desc) |
| 671 | { |
| 672 | struct cpdma_chan *chan, *most_chan = NULL; |
| 673 | int desc_cnt = desc_num; |
| 674 | int most_dnum = 0; |
| 675 | int min, max, i; |
| 676 | |
| 677 | if (!desc_num) |
| 678 | return; |
| 679 | |
| 680 | if (rx) { |
| 681 | min = rx_chan_num(0); |
| 682 | max = rx_chan_num(CPDMA_MAX_CHANNELS); |
| 683 | } else { |
| 684 | min = tx_chan_num(0); |
| 685 | max = tx_chan_num(CPDMA_MAX_CHANNELS); |
| 686 | } |
| 687 | |
| 688 | for (i = min; i < max; i++) { |
| 689 | chan = ctlr->channels[i]; |
| 690 | if (!chan) |
| 691 | continue; |
| 692 | |
| 693 | if (chan->weight) |
| 694 | chan->desc_num = (chan->weight * desc_num) / 100; |
| 695 | else |
| 696 | chan->desc_num = per_ch_desc; |
| 697 | |
| 698 | desc_cnt -= chan->desc_num; |
| 699 | |
| 700 | if (most_dnum < chan->desc_num) { |
| 701 | most_dnum = chan->desc_num; |
| 702 | most_chan = chan; |
| 703 | } |
| 704 | } |
| 705 | /* use remains */ |
Grygorii Strashko | be034fc | 2017-01-06 14:07:34 -0600 | [diff] [blame] | 706 | if (most_chan) |
| 707 | most_chan->desc_num += desc_cnt; |
Ivan Khoronzhuk | 0fc6432 | 2016-11-29 17:00:47 +0200 | [diff] [blame] | 708 | } |
| 709 | |
Ivan Khoronzhuk | 3802dce1 | 2016-08-22 21:18:24 +0300 | [diff] [blame] | 710 | /** |
| 711 | * cpdma_chan_split_pool - Splits ctrl pool between all channels. |
| 712 | * Has to be called under ctlr lock |
| 713 | */ |
Grygorii Strashko | be034fc | 2017-01-06 14:07:34 -0600 | [diff] [blame] | 714 | int cpdma_chan_split_pool(struct cpdma_ctlr *ctlr) |
Ivan Khoronzhuk | 3802dce1 | 2016-08-22 21:18:24 +0300 | [diff] [blame] | 715 | { |
Ivan Khoronzhuk | 0fc6432 | 2016-11-29 17:00:47 +0200 | [diff] [blame] | 716 | int tx_per_ch_desc = 0, rx_per_ch_desc = 0; |
Ivan Khoronzhuk | 0fc6432 | 2016-11-29 17:00:47 +0200 | [diff] [blame] | 717 | int free_rx_num = 0, free_tx_num = 0; |
| 718 | int rx_weight = 0, tx_weight = 0; |
| 719 | int tx_desc_num, rx_desc_num; |
Ivan Khoronzhuk | 3802dce1 | 2016-08-22 21:18:24 +0300 | [diff] [blame] | 720 | struct cpdma_chan *chan; |
Grygorii Strashko | be034fc | 2017-01-06 14:07:34 -0600 | [diff] [blame] | 721 | int i; |
Ivan Khoronzhuk | 3802dce1 | 2016-08-22 21:18:24 +0300 | [diff] [blame] | 722 | |
| 723 | if (!ctlr->chan_num) |
Ivan Khoronzhuk | 0fc6432 | 2016-11-29 17:00:47 +0200 | [diff] [blame] | 724 | return 0; |
Ivan Khoronzhuk | 3802dce1 | 2016-08-22 21:18:24 +0300 | [diff] [blame] | 725 | |
Ivan Khoronzhuk | 3802dce1 | 2016-08-22 21:18:24 +0300 | [diff] [blame] | 726 | for (i = 0; i < ARRAY_SIZE(ctlr->channels); i++) { |
| 727 | chan = ctlr->channels[i]; |
Ivan Khoronzhuk | 0fc6432 | 2016-11-29 17:00:47 +0200 | [diff] [blame] | 728 | if (!chan) |
| 729 | continue; |
| 730 | |
| 731 | if (is_rx_chan(chan)) { |
| 732 | if (!chan->weight) |
| 733 | free_rx_num++; |
| 734 | rx_weight += chan->weight; |
| 735 | } else { |
| 736 | if (!chan->weight) |
| 737 | free_tx_num++; |
| 738 | tx_weight += chan->weight; |
Ivan Khoronzhuk | 0fc6432 | 2016-11-29 17:00:47 +0200 | [diff] [blame] | 739 | } |
Ivan Khoronzhuk | 3802dce1 | 2016-08-22 21:18:24 +0300 | [diff] [blame] | 740 | } |
Ivan Khoronzhuk | 0fc6432 | 2016-11-29 17:00:47 +0200 | [diff] [blame] | 741 | |
| 742 | if (rx_weight > 100 || tx_weight > 100) |
| 743 | return -EINVAL; |
| 744 | |
Grygorii Strashko | be034fc | 2017-01-06 14:07:34 -0600 | [diff] [blame] | 745 | tx_desc_num = ctlr->num_tx_desc; |
| 746 | rx_desc_num = ctlr->num_rx_desc; |
Ivan Khoronzhuk | 0fc6432 | 2016-11-29 17:00:47 +0200 | [diff] [blame] | 747 | |
| 748 | if (free_tx_num) { |
| 749 | tx_per_ch_desc = tx_desc_num - (tx_weight * tx_desc_num) / 100; |
| 750 | tx_per_ch_desc /= free_tx_num; |
| 751 | } |
| 752 | if (free_rx_num) { |
| 753 | rx_per_ch_desc = rx_desc_num - (rx_weight * rx_desc_num) / 100; |
| 754 | rx_per_ch_desc /= free_rx_num; |
| 755 | } |
| 756 | |
| 757 | cpdma_chan_set_descs(ctlr, 0, tx_desc_num, tx_per_ch_desc); |
| 758 | cpdma_chan_set_descs(ctlr, 1, rx_desc_num, rx_per_ch_desc); |
| 759 | |
| 760 | return 0; |
| 761 | } |
Grygorii Strashko | be034fc | 2017-01-06 14:07:34 -0600 | [diff] [blame] | 762 | |
Ivan Khoronzhuk | 0fc6432 | 2016-11-29 17:00:47 +0200 | [diff] [blame] | 763 | |
| 764 | /* cpdma_chan_set_weight - set weight of a channel in percentage. |
| 765 | * Tx and Rx channels have separate weights. That is 100% for RX |
| 766 | * and 100% for Tx. The weight is used to split cpdma resources |
| 767 | * in correct proportion required by the channels, including number |
| 768 | * of descriptors. The channel rate is not enough to know the |
| 769 | * weight of a channel as the maximum rate of an interface is needed. |
| 770 | * If weight = 0, then channel uses rest of descriptors leaved by |
| 771 | * weighted channels. |
| 772 | */ |
| 773 | int cpdma_chan_set_weight(struct cpdma_chan *ch, int weight) |
| 774 | { |
| 775 | struct cpdma_ctlr *ctlr = ch->ctlr; |
| 776 | unsigned long flags, ch_flags; |
| 777 | int ret; |
| 778 | |
| 779 | spin_lock_irqsave(&ctlr->lock, flags); |
| 780 | spin_lock_irqsave(&ch->lock, ch_flags); |
| 781 | if (ch->weight == weight) { |
| 782 | spin_unlock_irqrestore(&ch->lock, ch_flags); |
| 783 | spin_unlock_irqrestore(&ctlr->lock, flags); |
| 784 | return 0; |
| 785 | } |
| 786 | ch->weight = weight; |
| 787 | spin_unlock_irqrestore(&ch->lock, ch_flags); |
| 788 | |
| 789 | /* re-split pool using new channel weight */ |
| 790 | ret = cpdma_chan_split_pool(ctlr); |
| 791 | spin_unlock_irqrestore(&ctlr->lock, flags); |
| 792 | return ret; |
Ivan Khoronzhuk | 3802dce1 | 2016-08-22 21:18:24 +0300 | [diff] [blame] | 793 | } |
| 794 | |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 795 | /* cpdma_chan_get_min_rate - get minimum allowed rate for channel |
| 796 | * Should be called before cpdma_chan_set_rate. |
| 797 | * Returns min rate in Kb/s |
| 798 | */ |
| 799 | u32 cpdma_chan_get_min_rate(struct cpdma_ctlr *ctlr) |
| 800 | { |
| 801 | unsigned int divident, divisor; |
| 802 | |
| 803 | divident = ctlr->params.bus_freq_mhz * 32 * 1000; |
| 804 | divisor = 1 + CPDMA_MAX_RLIM_CNT; |
| 805 | |
| 806 | return DIV_ROUND_UP(divident, divisor); |
| 807 | } |
| 808 | |
| 809 | /* cpdma_chan_set_rate - limits bandwidth for transmit channel. |
| 810 | * The bandwidth * limited channels have to be in order beginning from lowest. |
| 811 | * ch - transmit channel the bandwidth is configured for |
| 812 | * rate - bandwidth in Kb/s, if 0 - then off shaper |
| 813 | */ |
| 814 | int cpdma_chan_set_rate(struct cpdma_chan *ch, u32 rate) |
| 815 | { |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 816 | unsigned long flags, ch_flags; |
Ivan Khoronzhuk | e33c2ef | 2017-01-18 02:28:06 +0200 | [diff] [blame] | 817 | struct cpdma_ctlr *ctlr; |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 818 | int ret, prio_mode; |
| 819 | u32 rmask; |
| 820 | |
| 821 | if (!ch || !is_tx_chan(ch)) |
| 822 | return -EINVAL; |
| 823 | |
| 824 | if (ch->rate == rate) |
| 825 | return rate; |
| 826 | |
Ivan Khoronzhuk | e33c2ef | 2017-01-18 02:28:06 +0200 | [diff] [blame] | 827 | ctlr = ch->ctlr; |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 828 | spin_lock_irqsave(&ctlr->lock, flags); |
| 829 | spin_lock_irqsave(&ch->lock, ch_flags); |
| 830 | |
| 831 | ret = cpdma_chan_fit_rate(ch, rate, &rmask, &prio_mode); |
| 832 | if (ret) |
| 833 | goto err; |
| 834 | |
| 835 | ret = cpdma_chan_set_factors(ctlr, ch); |
| 836 | if (ret) |
| 837 | goto err; |
| 838 | |
| 839 | spin_unlock_irqrestore(&ch->lock, ch_flags); |
| 840 | |
| 841 | /* on shapers */ |
| 842 | _cpdma_control_set(ctlr, CPDMA_TX_RLIM, rmask); |
| 843 | _cpdma_control_set(ctlr, CPDMA_TX_PRIO_FIXED, prio_mode); |
| 844 | spin_unlock_irqrestore(&ctlr->lock, flags); |
| 845 | return ret; |
| 846 | |
| 847 | err: |
| 848 | spin_unlock_irqrestore(&ch->lock, ch_flags); |
| 849 | spin_unlock_irqrestore(&ctlr->lock, flags); |
| 850 | return ret; |
| 851 | } |
| 852 | |
| 853 | u32 cpdma_chan_get_rate(struct cpdma_chan *ch) |
| 854 | { |
| 855 | unsigned long flags; |
| 856 | u32 rate; |
| 857 | |
| 858 | spin_lock_irqsave(&ch->lock, flags); |
| 859 | rate = ch->rate; |
| 860 | spin_unlock_irqrestore(&ch->lock, flags); |
| 861 | |
| 862 | return rate; |
| 863 | } |
| 864 | |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 865 | struct cpdma_chan *cpdma_chan_create(struct cpdma_ctlr *ctlr, int chan_num, |
Ivan Khoronzhuk | 925d65e | 2016-08-22 21:18:27 +0300 | [diff] [blame] | 866 | cpdma_handler_fn handler, int rx_type) |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 867 | { |
Ivan Khoronzhuk | 925d65e | 2016-08-22 21:18:27 +0300 | [diff] [blame] | 868 | int offset = chan_num * 4; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 869 | struct cpdma_chan *chan; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 870 | unsigned long flags; |
| 871 | |
Ivan Khoronzhuk | 925d65e | 2016-08-22 21:18:27 +0300 | [diff] [blame] | 872 | chan_num = rx_type ? rx_chan_num(chan_num) : tx_chan_num(chan_num); |
| 873 | |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 874 | if (__chan_linear(chan_num) >= ctlr->num_chan) |
Ivan Khoronzhuk | 8a83c5d | 2017-12-12 23:06:35 +0200 | [diff] [blame] | 875 | return ERR_PTR(-EINVAL); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 876 | |
George Cherian | e194312 | 2014-05-12 10:21:21 +0530 | [diff] [blame] | 877 | chan = devm_kzalloc(ctlr->dev, sizeof(*chan), GFP_KERNEL); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 878 | if (!chan) |
George Cherian | e194312 | 2014-05-12 10:21:21 +0530 | [diff] [blame] | 879 | return ERR_PTR(-ENOMEM); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 880 | |
| 881 | spin_lock_irqsave(&ctlr->lock, flags); |
George Cherian | e194312 | 2014-05-12 10:21:21 +0530 | [diff] [blame] | 882 | if (ctlr->channels[chan_num]) { |
| 883 | spin_unlock_irqrestore(&ctlr->lock, flags); |
| 884 | devm_kfree(ctlr->dev, chan); |
| 885 | return ERR_PTR(-EBUSY); |
| 886 | } |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 887 | |
| 888 | chan->ctlr = ctlr; |
| 889 | chan->state = CPDMA_STATE_IDLE; |
| 890 | chan->chan_num = chan_num; |
| 891 | chan->handler = handler; |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 892 | chan->rate = 0; |
Ivan Khoronzhuk | 0fc6432 | 2016-11-29 17:00:47 +0200 | [diff] [blame] | 893 | chan->weight = 0; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 894 | |
| 895 | if (is_rx_chan(chan)) { |
| 896 | chan->hdp = ctlr->params.rxhdp + offset; |
| 897 | chan->cp = ctlr->params.rxcp + offset; |
| 898 | chan->rxfree = ctlr->params.rxfree + offset; |
| 899 | chan->int_set = CPDMA_RXINTMASKSET; |
| 900 | chan->int_clear = CPDMA_RXINTMASKCLEAR; |
| 901 | chan->td = CPDMA_RXTEARDOWN; |
| 902 | chan->dir = DMA_FROM_DEVICE; |
| 903 | } else { |
| 904 | chan->hdp = ctlr->params.txhdp + offset; |
| 905 | chan->cp = ctlr->params.txcp + offset; |
| 906 | chan->int_set = CPDMA_TXINTMASKSET; |
| 907 | chan->int_clear = CPDMA_TXINTMASKCLEAR; |
| 908 | chan->td = CPDMA_TXTEARDOWN; |
| 909 | chan->dir = DMA_TO_DEVICE; |
| 910 | } |
| 911 | chan->mask = BIT(chan_linear(chan)); |
| 912 | |
| 913 | spin_lock_init(&chan->lock); |
| 914 | |
| 915 | ctlr->channels[chan_num] = chan; |
Ivan Khoronzhuk | 3802dce1 | 2016-08-22 21:18:24 +0300 | [diff] [blame] | 916 | ctlr->chan_num++; |
| 917 | |
| 918 | cpdma_chan_split_pool(ctlr); |
| 919 | |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 920 | spin_unlock_irqrestore(&ctlr->lock, flags); |
| 921 | return chan; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 922 | } |
| 923 | |
Ivan Khoronzhuk | 3802dce1 | 2016-08-22 21:18:24 +0300 | [diff] [blame] | 924 | int cpdma_chan_get_rx_buf_num(struct cpdma_chan *chan) |
Ivan Khoronzhuk | 1793331 | 2016-06-17 13:25:39 +0300 | [diff] [blame] | 925 | { |
Ivan Khoronzhuk | 3802dce1 | 2016-08-22 21:18:24 +0300 | [diff] [blame] | 926 | unsigned long flags; |
| 927 | int desc_num; |
| 928 | |
| 929 | spin_lock_irqsave(&chan->lock, flags); |
| 930 | desc_num = chan->desc_num; |
| 931 | spin_unlock_irqrestore(&chan->lock, flags); |
| 932 | |
| 933 | return desc_num; |
Ivan Khoronzhuk | 1793331 | 2016-06-17 13:25:39 +0300 | [diff] [blame] | 934 | } |
Ivan Khoronzhuk | 1793331 | 2016-06-17 13:25:39 +0300 | [diff] [blame] | 935 | |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 936 | int cpdma_chan_destroy(struct cpdma_chan *chan) |
| 937 | { |
Julia Lawall | f37c54b | 2012-08-14 05:49:47 +0000 | [diff] [blame] | 938 | struct cpdma_ctlr *ctlr; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 939 | unsigned long flags; |
| 940 | |
| 941 | if (!chan) |
| 942 | return -EINVAL; |
Julia Lawall | f37c54b | 2012-08-14 05:49:47 +0000 | [diff] [blame] | 943 | ctlr = chan->ctlr; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 944 | |
| 945 | spin_lock_irqsave(&ctlr->lock, flags); |
| 946 | if (chan->state != CPDMA_STATE_IDLE) |
| 947 | cpdma_chan_stop(chan); |
| 948 | ctlr->channels[chan->chan_num] = NULL; |
Ivan Khoronzhuk | 3802dce1 | 2016-08-22 21:18:24 +0300 | [diff] [blame] | 949 | ctlr->chan_num--; |
Ivan Khoronzhuk | b602e49 | 2016-11-08 15:16:05 +0200 | [diff] [blame] | 950 | devm_kfree(ctlr->dev, chan); |
Ivan Khoronzhuk | 3802dce1 | 2016-08-22 21:18:24 +0300 | [diff] [blame] | 951 | cpdma_chan_split_pool(ctlr); |
| 952 | |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 953 | spin_unlock_irqrestore(&ctlr->lock, flags); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 954 | return 0; |
| 955 | } |
| 956 | |
| 957 | int cpdma_chan_get_stats(struct cpdma_chan *chan, |
| 958 | struct cpdma_chan_stats *stats) |
| 959 | { |
| 960 | unsigned long flags; |
| 961 | if (!chan) |
| 962 | return -EINVAL; |
| 963 | spin_lock_irqsave(&chan->lock, flags); |
| 964 | memcpy(stats, &chan->stats, sizeof(*stats)); |
| 965 | spin_unlock_irqrestore(&chan->lock, flags); |
| 966 | return 0; |
| 967 | } |
| 968 | |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 969 | static void __cpdma_chan_submit(struct cpdma_chan *chan, |
| 970 | struct cpdma_desc __iomem *desc) |
| 971 | { |
| 972 | struct cpdma_ctlr *ctlr = chan->ctlr; |
| 973 | struct cpdma_desc __iomem *prev = chan->tail; |
| 974 | struct cpdma_desc_pool *pool = ctlr->pool; |
| 975 | dma_addr_t desc_dma; |
| 976 | u32 mode; |
| 977 | |
| 978 | desc_dma = desc_phys(pool, desc); |
| 979 | |
| 980 | /* simple case - idle channel */ |
| 981 | if (!chan->head) { |
| 982 | chan->stats.head_enqueue++; |
| 983 | chan->head = desc; |
| 984 | chan->tail = desc; |
| 985 | if (chan->state == CPDMA_STATE_ACTIVE) |
| 986 | chan_write(chan, hdp, desc_dma); |
| 987 | return; |
| 988 | } |
| 989 | |
| 990 | /* first chain the descriptor at the tail of the list */ |
| 991 | desc_write(prev, hw_next, desc_dma); |
| 992 | chan->tail = desc; |
| 993 | chan->stats.tail_enqueue++; |
| 994 | |
| 995 | /* next check if EOQ has been triggered already */ |
| 996 | mode = desc_read(prev, hw_mode); |
| 997 | if (((mode & (CPDMA_DESC_EOQ | CPDMA_DESC_OWNER)) == CPDMA_DESC_EOQ) && |
| 998 | (chan->state == CPDMA_STATE_ACTIVE)) { |
| 999 | desc_write(prev, hw_mode, mode & ~CPDMA_DESC_EOQ); |
| 1000 | chan_write(chan, hdp, desc_dma); |
| 1001 | chan->stats.misqueued++; |
| 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data, |
Sebastian Siewior | aef614e | 2013-04-23 07:31:38 +0000 | [diff] [blame] | 1006 | int len, int directed) |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1007 | { |
| 1008 | struct cpdma_ctlr *ctlr = chan->ctlr; |
| 1009 | struct cpdma_desc __iomem *desc; |
| 1010 | dma_addr_t buffer; |
| 1011 | unsigned long flags; |
| 1012 | u32 mode; |
| 1013 | int ret = 0; |
| 1014 | |
| 1015 | spin_lock_irqsave(&chan->lock, flags); |
| 1016 | |
| 1017 | if (chan->state == CPDMA_STATE_TEARDOWN) { |
| 1018 | ret = -EINVAL; |
| 1019 | goto unlock_ret; |
| 1020 | } |
| 1021 | |
Grygorii Strashko | 742fb20 | 2016-06-27 12:05:11 +0300 | [diff] [blame] | 1022 | if (chan->count >= chan->desc_num) { |
| 1023 | chan->stats.desc_alloc_fail++; |
| 1024 | ret = -ENOMEM; |
| 1025 | goto unlock_ret; |
| 1026 | } |
| 1027 | |
| 1028 | desc = cpdma_desc_alloc(ctlr->pool); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1029 | if (!desc) { |
| 1030 | chan->stats.desc_alloc_fail++; |
| 1031 | ret = -ENOMEM; |
| 1032 | goto unlock_ret; |
| 1033 | } |
| 1034 | |
| 1035 | if (len < ctlr->params.min_packet_size) { |
| 1036 | len = ctlr->params.min_packet_size; |
| 1037 | chan->stats.runt_transmit_buff++; |
| 1038 | } |
| 1039 | |
| 1040 | buffer = dma_map_single(ctlr->dev, data, len, chan->dir); |
Sebastian Siewior | 14bd076 | 2013-06-20 16:58:45 +0200 | [diff] [blame] | 1041 | ret = dma_mapping_error(ctlr->dev, buffer); |
| 1042 | if (ret) { |
| 1043 | cpdma_desc_free(ctlr->pool, desc, 1); |
| 1044 | ret = -EINVAL; |
| 1045 | goto unlock_ret; |
| 1046 | } |
| 1047 | |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1048 | mode = CPDMA_DESC_OWNER | CPDMA_DESC_SOP | CPDMA_DESC_EOP; |
Mugunthan V N | f6e135c | 2013-02-11 09:52:18 +0000 | [diff] [blame] | 1049 | cpdma_desc_to_port(chan, mode, directed); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1050 | |
Grygorii Strashko | a6c83cc | 2017-01-06 14:07:29 -0600 | [diff] [blame] | 1051 | /* Relaxed IO accessors can be used here as there is read barrier |
| 1052 | * at the end of write sequence. |
| 1053 | */ |
| 1054 | writel_relaxed(0, &desc->hw_next); |
| 1055 | writel_relaxed(buffer, &desc->hw_buffer); |
| 1056 | writel_relaxed(len, &desc->hw_len); |
| 1057 | writel_relaxed(mode | len, &desc->hw_mode); |
Florian Fainelli | c79c385 | 2018-05-21 11:45:55 -0700 | [diff] [blame] | 1058 | writel_relaxed((uintptr_t)token, &desc->sw_token); |
Grygorii Strashko | a6c83cc | 2017-01-06 14:07:29 -0600 | [diff] [blame] | 1059 | writel_relaxed(buffer, &desc->sw_buffer); |
| 1060 | writel_relaxed(len, &desc->sw_len); |
| 1061 | desc_read(desc, sw_len); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1062 | |
| 1063 | __cpdma_chan_submit(chan, desc); |
| 1064 | |
| 1065 | if (chan->state == CPDMA_STATE_ACTIVE && chan->rxfree) |
| 1066 | chan_write(chan, rxfree, 1); |
| 1067 | |
| 1068 | chan->count++; |
| 1069 | |
| 1070 | unlock_ret: |
| 1071 | spin_unlock_irqrestore(&chan->lock, flags); |
| 1072 | return ret; |
| 1073 | } |
| 1074 | |
Mugunthan V N | fae5082 | 2013-01-17 06:31:34 +0000 | [diff] [blame] | 1075 | bool cpdma_check_free_tx_desc(struct cpdma_chan *chan) |
| 1076 | { |
Mugunthan V N | fae5082 | 2013-01-17 06:31:34 +0000 | [diff] [blame] | 1077 | struct cpdma_ctlr *ctlr = chan->ctlr; |
| 1078 | struct cpdma_desc_pool *pool = ctlr->pool; |
Grygorii Strashko | 742fb20 | 2016-06-27 12:05:11 +0300 | [diff] [blame] | 1079 | bool free_tx_desc; |
| 1080 | unsigned long flags; |
Mugunthan V N | fae5082 | 2013-01-17 06:31:34 +0000 | [diff] [blame] | 1081 | |
Grygorii Strashko | 742fb20 | 2016-06-27 12:05:11 +0300 | [diff] [blame] | 1082 | spin_lock_irqsave(&chan->lock, flags); |
| 1083 | free_tx_desc = (chan->count < chan->desc_num) && |
| 1084 | gen_pool_avail(pool->gen_pool); |
| 1085 | spin_unlock_irqrestore(&chan->lock, flags); |
| 1086 | return free_tx_desc; |
Mugunthan V N | fae5082 | 2013-01-17 06:31:34 +0000 | [diff] [blame] | 1087 | } |
Mugunthan V N | fae5082 | 2013-01-17 06:31:34 +0000 | [diff] [blame] | 1088 | |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1089 | static void __cpdma_chan_free(struct cpdma_chan *chan, |
| 1090 | struct cpdma_desc __iomem *desc, |
| 1091 | int outlen, int status) |
| 1092 | { |
| 1093 | struct cpdma_ctlr *ctlr = chan->ctlr; |
| 1094 | struct cpdma_desc_pool *pool = ctlr->pool; |
| 1095 | dma_addr_t buff_dma; |
| 1096 | int origlen; |
Florian Fainelli | c79c385 | 2018-05-21 11:45:55 -0700 | [diff] [blame] | 1097 | uintptr_t token; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1098 | |
Florian Fainelli | c79c385 | 2018-05-21 11:45:55 -0700 | [diff] [blame] | 1099 | token = desc_read(desc, sw_token); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1100 | buff_dma = desc_read(desc, sw_buffer); |
| 1101 | origlen = desc_read(desc, sw_len); |
| 1102 | |
| 1103 | dma_unmap_single(ctlr->dev, buff_dma, origlen, chan->dir); |
| 1104 | cpdma_desc_free(pool, desc, 1); |
Florian Fainelli | c79c385 | 2018-05-21 11:45:55 -0700 | [diff] [blame] | 1105 | (*chan->handler)((void *)token, outlen, status); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | static int __cpdma_chan_process(struct cpdma_chan *chan) |
| 1109 | { |
| 1110 | struct cpdma_ctlr *ctlr = chan->ctlr; |
| 1111 | struct cpdma_desc __iomem *desc; |
| 1112 | int status, outlen; |
Sebastian Siewior | b4727e6 | 2013-04-23 07:31:39 +0000 | [diff] [blame] | 1113 | int cb_status = 0; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1114 | struct cpdma_desc_pool *pool = ctlr->pool; |
| 1115 | dma_addr_t desc_dma; |
| 1116 | unsigned long flags; |
| 1117 | |
| 1118 | spin_lock_irqsave(&chan->lock, flags); |
| 1119 | |
| 1120 | desc = chan->head; |
| 1121 | if (!desc) { |
| 1122 | chan->stats.empty_dequeue++; |
| 1123 | status = -ENOENT; |
| 1124 | goto unlock_ret; |
| 1125 | } |
| 1126 | desc_dma = desc_phys(pool, desc); |
| 1127 | |
Grygorii Strashko | a6c83cc | 2017-01-06 14:07:29 -0600 | [diff] [blame] | 1128 | status = desc_read(desc, hw_mode); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1129 | outlen = status & 0x7ff; |
| 1130 | if (status & CPDMA_DESC_OWNER) { |
| 1131 | chan->stats.busy_dequeue++; |
| 1132 | status = -EBUSY; |
| 1133 | goto unlock_ret; |
| 1134 | } |
Mugunthan V N | 28a19fe | 2013-05-29 20:22:01 +0000 | [diff] [blame] | 1135 | |
| 1136 | if (status & CPDMA_DESC_PASS_CRC) |
| 1137 | outlen -= CPDMA_DESC_CRC_LEN; |
| 1138 | |
Mugunthan V N | f6e135c | 2013-02-11 09:52:18 +0000 | [diff] [blame] | 1139 | status = status & (CPDMA_DESC_EOQ | CPDMA_DESC_TD_COMPLETE | |
Grygorii Strashko | a3a41d2 | 2018-03-15 15:15:50 -0500 | [diff] [blame] | 1140 | CPDMA_DESC_PORT_MASK | CPDMA_RX_VLAN_ENCAP); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1141 | |
| 1142 | chan->head = desc_from_phys(pool, desc_read(desc, hw_next)); |
| 1143 | chan_write(chan, cp, desc_dma); |
| 1144 | chan->count--; |
| 1145 | chan->stats.good_dequeue++; |
| 1146 | |
Grygorii Strashko | 12a303e | 2017-01-06 14:07:30 -0600 | [diff] [blame] | 1147 | if ((status & CPDMA_DESC_EOQ) && chan->head) { |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1148 | chan->stats.requeue++; |
| 1149 | chan_write(chan, hdp, desc_phys(pool, chan->head)); |
| 1150 | } |
| 1151 | |
| 1152 | spin_unlock_irqrestore(&chan->lock, flags); |
Sebastian Siewior | b4727e6 | 2013-04-23 07:31:39 +0000 | [diff] [blame] | 1153 | if (unlikely(status & CPDMA_DESC_TD_COMPLETE)) |
| 1154 | cb_status = -ENOSYS; |
| 1155 | else |
| 1156 | cb_status = status; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1157 | |
Sebastian Siewior | b4727e6 | 2013-04-23 07:31:39 +0000 | [diff] [blame] | 1158 | __cpdma_chan_free(chan, desc, outlen, cb_status); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1159 | return status; |
| 1160 | |
| 1161 | unlock_ret: |
| 1162 | spin_unlock_irqrestore(&chan->lock, flags); |
| 1163 | return status; |
| 1164 | } |
| 1165 | |
| 1166 | int cpdma_chan_process(struct cpdma_chan *chan, int quota) |
| 1167 | { |
| 1168 | int used = 0, ret = 0; |
| 1169 | |
| 1170 | if (chan->state != CPDMA_STATE_ACTIVE) |
| 1171 | return -EINVAL; |
| 1172 | |
| 1173 | while (used < quota) { |
| 1174 | ret = __cpdma_chan_process(chan); |
| 1175 | if (ret < 0) |
| 1176 | break; |
| 1177 | used++; |
| 1178 | } |
| 1179 | return used; |
| 1180 | } |
| 1181 | |
| 1182 | int cpdma_chan_start(struct cpdma_chan *chan) |
| 1183 | { |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 1184 | struct cpdma_ctlr *ctlr = chan->ctlr; |
| 1185 | unsigned long flags; |
| 1186 | int ret; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1187 | |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 1188 | spin_lock_irqsave(&ctlr->lock, flags); |
| 1189 | ret = cpdma_chan_set_chan_shaper(chan); |
| 1190 | spin_unlock_irqrestore(&ctlr->lock, flags); |
| 1191 | if (ret) |
| 1192 | return ret; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1193 | |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 1194 | ret = cpdma_chan_on(chan); |
| 1195 | if (ret) |
| 1196 | return ret; |
| 1197 | |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1198 | return 0; |
| 1199 | } |
| 1200 | |
| 1201 | int cpdma_chan_stop(struct cpdma_chan *chan) |
| 1202 | { |
| 1203 | struct cpdma_ctlr *ctlr = chan->ctlr; |
| 1204 | struct cpdma_desc_pool *pool = ctlr->pool; |
| 1205 | unsigned long flags; |
| 1206 | int ret; |
Sebastian Siewior | 817f6d1 | 2013-04-23 07:31:35 +0000 | [diff] [blame] | 1207 | unsigned timeout; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1208 | |
| 1209 | spin_lock_irqsave(&chan->lock, flags); |
Christian Riesch | cd11cf5 | 2014-03-24 13:46:27 +0100 | [diff] [blame] | 1210 | if (chan->state == CPDMA_STATE_TEARDOWN) { |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1211 | spin_unlock_irqrestore(&chan->lock, flags); |
| 1212 | return -EINVAL; |
| 1213 | } |
| 1214 | |
| 1215 | chan->state = CPDMA_STATE_TEARDOWN; |
| 1216 | dma_reg_write(ctlr, chan->int_clear, chan->mask); |
| 1217 | |
| 1218 | /* trigger teardown */ |
Christian Riesch | b4ad042 | 2012-02-22 21:58:00 +0000 | [diff] [blame] | 1219 | dma_reg_write(ctlr, chan->td, chan_linear(chan)); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1220 | |
| 1221 | /* wait for teardown complete */ |
Sebastian Siewior | 817f6d1 | 2013-04-23 07:31:35 +0000 | [diff] [blame] | 1222 | timeout = 100 * 100; /* 100 ms */ |
| 1223 | while (timeout) { |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1224 | u32 cp = chan_read(chan, cp); |
| 1225 | if ((cp & CPDMA_TEARDOWN_VALUE) == CPDMA_TEARDOWN_VALUE) |
| 1226 | break; |
Sebastian Siewior | 817f6d1 | 2013-04-23 07:31:35 +0000 | [diff] [blame] | 1227 | udelay(10); |
| 1228 | timeout--; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1229 | } |
Sebastian Siewior | 817f6d1 | 2013-04-23 07:31:35 +0000 | [diff] [blame] | 1230 | WARN_ON(!timeout); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1231 | chan_write(chan, cp, CPDMA_TEARDOWN_VALUE); |
| 1232 | |
| 1233 | /* handle completed packets */ |
Ilya Yanok | 7746ab0 | 2011-12-18 10:02:04 +0000 | [diff] [blame] | 1234 | spin_unlock_irqrestore(&chan->lock, flags); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1235 | do { |
| 1236 | ret = __cpdma_chan_process(chan); |
| 1237 | if (ret < 0) |
| 1238 | break; |
| 1239 | } while ((ret & CPDMA_DESC_TD_COMPLETE) == 0); |
Ilya Yanok | 7746ab0 | 2011-12-18 10:02:04 +0000 | [diff] [blame] | 1240 | spin_lock_irqsave(&chan->lock, flags); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1241 | |
| 1242 | /* remaining packets haven't been tx/rx'ed, clean them up */ |
| 1243 | while (chan->head) { |
| 1244 | struct cpdma_desc __iomem *desc = chan->head; |
| 1245 | dma_addr_t next_dma; |
| 1246 | |
| 1247 | next_dma = desc_read(desc, hw_next); |
| 1248 | chan->head = desc_from_phys(pool, next_dma); |
htbegin | ffb5ba9 | 2012-10-01 16:42:43 +0000 | [diff] [blame] | 1249 | chan->count--; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1250 | chan->stats.teardown_dequeue++; |
| 1251 | |
| 1252 | /* issue callback without locks held */ |
| 1253 | spin_unlock_irqrestore(&chan->lock, flags); |
| 1254 | __cpdma_chan_free(chan, desc, 0, -ENOSYS); |
| 1255 | spin_lock_irqsave(&chan->lock, flags); |
| 1256 | } |
| 1257 | |
| 1258 | chan->state = CPDMA_STATE_IDLE; |
| 1259 | spin_unlock_irqrestore(&chan->lock, flags); |
| 1260 | return 0; |
| 1261 | } |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1262 | |
| 1263 | int cpdma_chan_int_ctrl(struct cpdma_chan *chan, bool enable) |
| 1264 | { |
| 1265 | unsigned long flags; |
| 1266 | |
| 1267 | spin_lock_irqsave(&chan->lock, flags); |
| 1268 | if (chan->state != CPDMA_STATE_ACTIVE) { |
| 1269 | spin_unlock_irqrestore(&chan->lock, flags); |
| 1270 | return -EINVAL; |
| 1271 | } |
| 1272 | |
| 1273 | dma_reg_write(chan->ctlr, enable ? chan->int_set : chan->int_clear, |
| 1274 | chan->mask); |
| 1275 | spin_unlock_irqrestore(&chan->lock, flags); |
| 1276 | |
| 1277 | return 0; |
| 1278 | } |
| 1279 | |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1280 | int cpdma_control_get(struct cpdma_ctlr *ctlr, int control) |
| 1281 | { |
| 1282 | unsigned long flags; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1283 | int ret; |
| 1284 | |
| 1285 | spin_lock_irqsave(&ctlr->lock, flags); |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 1286 | ret = _cpdma_control_get(ctlr, control); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1287 | spin_unlock_irqrestore(&ctlr->lock, flags); |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 1288 | |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1289 | return ret; |
| 1290 | } |
| 1291 | |
| 1292 | int cpdma_control_set(struct cpdma_ctlr *ctlr, int control, int value) |
| 1293 | { |
| 1294 | unsigned long flags; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1295 | int ret; |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1296 | |
| 1297 | spin_lock_irqsave(&ctlr->lock, flags); |
Ivan Khoronzhuk | 991ddb1 | 2016-11-11 15:45:24 +0200 | [diff] [blame] | 1298 | ret = _cpdma_control_set(ctlr, control, value); |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1299 | spin_unlock_irqrestore(&ctlr->lock, flags); |
Ivan Khoronzhuk | 8f32b90 | 2016-11-29 17:00:48 +0200 | [diff] [blame] | 1300 | |
Cyril Chemparathy | ef8c2da | 2010-09-15 10:11:28 -0400 | [diff] [blame] | 1301 | return ret; |
| 1302 | } |
Sebastian Siewior | 4bc21d4 | 2013-04-24 08:48:22 +0000 | [diff] [blame] | 1303 | |
Grygorii Strashko | be034fc | 2017-01-06 14:07:34 -0600 | [diff] [blame] | 1304 | int cpdma_get_num_rx_descs(struct cpdma_ctlr *ctlr) |
| 1305 | { |
| 1306 | return ctlr->num_rx_desc; |
| 1307 | } |
Grygorii Strashko | be034fc | 2017-01-06 14:07:34 -0600 | [diff] [blame] | 1308 | |
| 1309 | int cpdma_get_num_tx_descs(struct cpdma_ctlr *ctlr) |
| 1310 | { |
| 1311 | return ctlr->num_tx_desc; |
| 1312 | } |
Grygorii Strashko | be034fc | 2017-01-06 14:07:34 -0600 | [diff] [blame] | 1313 | |
| 1314 | void cpdma_set_num_rx_descs(struct cpdma_ctlr *ctlr, int num_rx_desc) |
| 1315 | { |
| 1316 | ctlr->num_rx_desc = num_rx_desc; |
| 1317 | ctlr->num_tx_desc = ctlr->pool->num_desc - ctlr->num_rx_desc; |
| 1318 | } |