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