Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Intel I/OAT DMA Linux driver |
| 3 | * Copyright(c) 2004 - 2009 Intel Corporation. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU General Public License, |
| 7 | * version 2, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in |
| 19 | * the file called "COPYING". |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | /* |
| 24 | * This driver supports an Intel I/OAT DMA engine (versions >= 2), which |
| 25 | * does asynchronous data movement and checksumming operations. |
| 26 | */ |
| 27 | |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/pci.h> |
| 31 | #include <linux/interrupt.h> |
| 32 | #include <linux/dmaengine.h> |
| 33 | #include <linux/delay.h> |
| 34 | #include <linux/dma-mapping.h> |
| 35 | #include <linux/workqueue.h> |
| 36 | #include <linux/i7300_idle.h> |
| 37 | #include "dma.h" |
| 38 | #include "dma_v2.h" |
| 39 | #include "registers.h" |
| 40 | #include "hw.h" |
| 41 | |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 42 | int ioat_ring_alloc_order = 8; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 43 | module_param(ioat_ring_alloc_order, int, 0644); |
| 44 | MODULE_PARM_DESC(ioat_ring_alloc_order, |
Dan Williams | 376ec37 | 2009-09-16 15:16:50 -0700 | [diff] [blame] | 45 | "ioat2+: allocate 2^n descriptors per channel" |
| 46 | " (default: 8 max: 16)"); |
Dan Williams | a309218 | 2009-09-08 12:02:01 -0700 | [diff] [blame] | 47 | static int ioat_ring_max_alloc_order = IOAT_MAX_ORDER; |
| 48 | module_param(ioat_ring_max_alloc_order, int, 0644); |
| 49 | MODULE_PARM_DESC(ioat_ring_max_alloc_order, |
Dan Williams | 376ec37 | 2009-09-16 15:16:50 -0700 | [diff] [blame] | 50 | "ioat2+: upper limit for ring size (default: 16)"); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 51 | |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 52 | void __ioat2_issue_pending(struct ioat2_dma_chan *ioat) |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 53 | { |
Dan Williams | 281befa | 2010-03-03 11:47:43 -0700 | [diff] [blame] | 54 | struct ioat_chan_common *chan = &ioat->base; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 55 | |
Dan Williams | 376ec37 | 2009-09-16 15:16:50 -0700 | [diff] [blame] | 56 | ioat->dmacount += ioat2_ring_pending(ioat); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 57 | ioat->issued = ioat->head; |
| 58 | /* make descriptor updates globally visible before notifying channel */ |
| 59 | wmb(); |
Dan Williams | 281befa | 2010-03-03 11:47:43 -0700 | [diff] [blame] | 60 | writew(ioat->dmacount, chan->reg_base + IOAT_CHAN_DMACOUNT_OFFSET); |
| 61 | dev_dbg(to_dev(chan), |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 62 | "%s: head: %#x tail: %#x issued: %#x count: %#x\n", |
| 63 | __func__, ioat->head, ioat->tail, ioat->issued, ioat->dmacount); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Dan Williams | 281befa | 2010-03-03 11:47:43 -0700 | [diff] [blame] | 66 | void ioat2_issue_pending(struct dma_chan *c) |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 67 | { |
Dan Williams | 281befa | 2010-03-03 11:47:43 -0700 | [diff] [blame] | 68 | struct ioat2_dma_chan *ioat = to_ioat2_chan(c); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 69 | |
Dan Williams | 281befa | 2010-03-03 11:47:43 -0700 | [diff] [blame] | 70 | if (ioat2_ring_pending(ioat)) { |
| 71 | spin_lock_bh(&ioat->ring_lock); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 72 | __ioat2_issue_pending(ioat); |
Dan Williams | 281befa | 2010-03-03 11:47:43 -0700 | [diff] [blame] | 73 | spin_unlock_bh(&ioat->ring_lock); |
| 74 | } |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /** |
| 78 | * ioat2_update_pending - log pending descriptors |
| 79 | * @ioat: ioat2+ channel |
| 80 | * |
Dan Williams | 281befa | 2010-03-03 11:47:43 -0700 | [diff] [blame] | 81 | * Check if the number of unsubmitted descriptors has exceeded the |
| 82 | * watermark. Called with ring_lock held |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 83 | */ |
| 84 | static void ioat2_update_pending(struct ioat2_dma_chan *ioat) |
| 85 | { |
Dan Williams | 281befa | 2010-03-03 11:47:43 -0700 | [diff] [blame] | 86 | if (ioat2_ring_pending(ioat) > ioat_pending_level) |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 87 | __ioat2_issue_pending(ioat); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | static void __ioat2_start_null_desc(struct ioat2_dma_chan *ioat) |
| 91 | { |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 92 | struct ioat_ring_ent *desc; |
| 93 | struct ioat_dma_descriptor *hw; |
| 94 | int idx; |
| 95 | |
| 96 | if (ioat2_ring_space(ioat) < 1) { |
| 97 | dev_err(to_dev(&ioat->base), |
| 98 | "Unable to start null desc - ring full\n"); |
| 99 | return; |
| 100 | } |
| 101 | |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 102 | dev_dbg(to_dev(&ioat->base), "%s: head: %#x tail: %#x issued: %#x\n", |
| 103 | __func__, ioat->head, ioat->tail, ioat->issued); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 104 | idx = ioat2_desc_alloc(ioat, 1); |
| 105 | desc = ioat2_get_ring_ent(ioat, idx); |
| 106 | |
| 107 | hw = desc->hw; |
| 108 | hw->ctl = 0; |
| 109 | hw->ctl_f.null = 1; |
| 110 | hw->ctl_f.int_en = 1; |
| 111 | hw->ctl_f.compl_write = 1; |
| 112 | /* set size to non-zero value (channel returns error when size is 0) */ |
| 113 | hw->size = NULL_DESC_BUFFER_SIZE; |
| 114 | hw->src_addr = 0; |
| 115 | hw->dst_addr = 0; |
| 116 | async_tx_ack(&desc->txd); |
Dan Williams | 09c8a5b | 2009-09-08 12:01:49 -0700 | [diff] [blame] | 117 | ioat2_set_chainaddr(ioat, desc->txd.phys); |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 118 | dump_desc_dbg(ioat, desc); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 119 | __ioat2_issue_pending(ioat); |
| 120 | } |
| 121 | |
| 122 | static void ioat2_start_null_desc(struct ioat2_dma_chan *ioat) |
| 123 | { |
| 124 | spin_lock_bh(&ioat->ring_lock); |
| 125 | __ioat2_start_null_desc(ioat); |
| 126 | spin_unlock_bh(&ioat->ring_lock); |
| 127 | } |
| 128 | |
Dan Williams | 09c8a5b | 2009-09-08 12:01:49 -0700 | [diff] [blame] | 129 | static void __cleanup(struct ioat2_dma_chan *ioat, unsigned long phys_complete) |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 130 | { |
| 131 | struct ioat_chan_common *chan = &ioat->base; |
Dan Williams | 09c8a5b | 2009-09-08 12:01:49 -0700 | [diff] [blame] | 132 | struct dma_async_tx_descriptor *tx; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 133 | struct ioat_ring_ent *desc; |
| 134 | bool seen_current = false; |
| 135 | u16 active; |
| 136 | int i; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 137 | |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 138 | dev_dbg(to_dev(chan), "%s: head: %#x tail: %#x issued: %#x\n", |
| 139 | __func__, ioat->head, ioat->tail, ioat->issued); |
| 140 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 141 | active = ioat2_ring_active(ioat); |
| 142 | for (i = 0; i < active && !seen_current; i++) { |
| 143 | prefetch(ioat2_get_ring_ent(ioat, ioat->tail + i + 1)); |
| 144 | desc = ioat2_get_ring_ent(ioat, ioat->tail + i); |
| 145 | tx = &desc->txd; |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 146 | dump_desc_dbg(ioat, desc); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 147 | if (tx->cookie) { |
| 148 | ioat_dma_unmap(chan, tx->flags, desc->len, desc->hw); |
| 149 | chan->completed_cookie = tx->cookie; |
| 150 | tx->cookie = 0; |
| 151 | if (tx->callback) { |
| 152 | tx->callback(tx->callback_param); |
| 153 | tx->callback = NULL; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | if (tx->phys == phys_complete) |
| 158 | seen_current = true; |
| 159 | } |
| 160 | ioat->tail += i; |
Dan Williams | aa75db0 | 2010-03-03 21:21:10 -0700 | [diff] [blame^] | 161 | BUG_ON(active && !seen_current); /* no active descs have written a completion? */ |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 162 | |
| 163 | chan->last_completion = phys_complete; |
Dan Williams | 09c8a5b | 2009-09-08 12:01:49 -0700 | [diff] [blame] | 164 | if (ioat->head == ioat->tail) { |
| 165 | dev_dbg(to_dev(chan), "%s: cancel completion timeout\n", |
| 166 | __func__); |
| 167 | clear_bit(IOAT_COMPLETION_PENDING, &chan->state); |
Dan Williams | a309218 | 2009-09-08 12:02:01 -0700 | [diff] [blame] | 168 | mod_timer(&chan->timer, jiffies + IDLE_TIMEOUT); |
Dan Williams | 09c8a5b | 2009-09-08 12:01:49 -0700 | [diff] [blame] | 169 | } |
| 170 | } |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 171 | |
Dan Williams | 09c8a5b | 2009-09-08 12:01:49 -0700 | [diff] [blame] | 172 | /** |
| 173 | * ioat2_cleanup - clean finished descriptors (advance tail pointer) |
| 174 | * @chan: ioat channel to be cleaned up |
| 175 | */ |
| 176 | static void ioat2_cleanup(struct ioat2_dma_chan *ioat) |
| 177 | { |
| 178 | struct ioat_chan_common *chan = &ioat->base; |
| 179 | unsigned long phys_complete; |
| 180 | |
| 181 | prefetch(chan->completion); |
| 182 | |
| 183 | if (!spin_trylock_bh(&chan->cleanup_lock)) |
| 184 | return; |
| 185 | |
| 186 | if (!ioat_cleanup_preamble(chan, &phys_complete)) { |
| 187 | spin_unlock_bh(&chan->cleanup_lock); |
| 188 | return; |
| 189 | } |
| 190 | |
| 191 | if (!spin_trylock_bh(&ioat->ring_lock)) { |
| 192 | spin_unlock_bh(&chan->cleanup_lock); |
| 193 | return; |
| 194 | } |
| 195 | |
| 196 | __cleanup(ioat, phys_complete); |
| 197 | |
| 198 | spin_unlock_bh(&ioat->ring_lock); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 199 | spin_unlock_bh(&chan->cleanup_lock); |
| 200 | } |
| 201 | |
Dan Williams | e323271 | 2009-09-08 17:43:02 -0700 | [diff] [blame] | 202 | void ioat2_cleanup_tasklet(unsigned long data) |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 203 | { |
| 204 | struct ioat2_dma_chan *ioat = (void *) data; |
| 205 | |
| 206 | ioat2_cleanup(ioat); |
Dan Williams | f6ab95b | 2009-09-08 12:01:21 -0700 | [diff] [blame] | 207 | writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 210 | void __ioat2_restart_chan(struct ioat2_dma_chan *ioat) |
Dan Williams | 09c8a5b | 2009-09-08 12:01:49 -0700 | [diff] [blame] | 211 | { |
| 212 | struct ioat_chan_common *chan = &ioat->base; |
| 213 | |
| 214 | /* set the tail to be re-issued */ |
| 215 | ioat->issued = ioat->tail; |
| 216 | ioat->dmacount = 0; |
| 217 | set_bit(IOAT_COMPLETION_PENDING, &chan->state); |
| 218 | mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT); |
| 219 | |
| 220 | dev_dbg(to_dev(chan), |
| 221 | "%s: head: %#x tail: %#x issued: %#x count: %#x\n", |
| 222 | __func__, ioat->head, ioat->tail, ioat->issued, ioat->dmacount); |
| 223 | |
| 224 | if (ioat2_ring_pending(ioat)) { |
| 225 | struct ioat_ring_ent *desc; |
| 226 | |
| 227 | desc = ioat2_get_ring_ent(ioat, ioat->tail); |
| 228 | ioat2_set_chainaddr(ioat, desc->txd.phys); |
| 229 | __ioat2_issue_pending(ioat); |
| 230 | } else |
| 231 | __ioat2_start_null_desc(ioat); |
| 232 | } |
| 233 | |
Dan Williams | a6d52d7 | 2009-12-19 15:36:02 -0700 | [diff] [blame] | 234 | int ioat2_quiesce(struct ioat_chan_common *chan, unsigned long tmo) |
Dan Williams | 09c8a5b | 2009-09-08 12:01:49 -0700 | [diff] [blame] | 235 | { |
Dan Williams | a6d52d7 | 2009-12-19 15:36:02 -0700 | [diff] [blame] | 236 | unsigned long end = jiffies + tmo; |
| 237 | int err = 0; |
Dan Williams | 09c8a5b | 2009-09-08 12:01:49 -0700 | [diff] [blame] | 238 | u32 status; |
| 239 | |
| 240 | status = ioat_chansts(chan); |
| 241 | if (is_ioat_active(status) || is_ioat_idle(status)) |
| 242 | ioat_suspend(chan); |
| 243 | while (is_ioat_active(status) || is_ioat_idle(status)) { |
Dan Williams | a6d52d7 | 2009-12-19 15:36:02 -0700 | [diff] [blame] | 244 | if (end && time_after(jiffies, end)) { |
| 245 | err = -ETIMEDOUT; |
| 246 | break; |
| 247 | } |
Dan Williams | 09c8a5b | 2009-09-08 12:01:49 -0700 | [diff] [blame] | 248 | status = ioat_chansts(chan); |
| 249 | cpu_relax(); |
| 250 | } |
| 251 | |
Dan Williams | a6d52d7 | 2009-12-19 15:36:02 -0700 | [diff] [blame] | 252 | return err; |
| 253 | } |
| 254 | |
| 255 | int ioat2_reset_sync(struct ioat_chan_common *chan, unsigned long tmo) |
| 256 | { |
| 257 | unsigned long end = jiffies + tmo; |
| 258 | int err = 0; |
| 259 | |
| 260 | ioat_reset(chan); |
| 261 | while (ioat_reset_pending(chan)) { |
| 262 | if (end && time_after(jiffies, end)) { |
| 263 | err = -ETIMEDOUT; |
| 264 | break; |
| 265 | } |
| 266 | cpu_relax(); |
| 267 | } |
| 268 | |
| 269 | return err; |
| 270 | } |
| 271 | |
| 272 | static void ioat2_restart_channel(struct ioat2_dma_chan *ioat) |
| 273 | { |
| 274 | struct ioat_chan_common *chan = &ioat->base; |
| 275 | unsigned long phys_complete; |
| 276 | |
| 277 | ioat2_quiesce(chan, 0); |
Dan Williams | 09c8a5b | 2009-09-08 12:01:49 -0700 | [diff] [blame] | 278 | if (ioat_cleanup_preamble(chan, &phys_complete)) |
| 279 | __cleanup(ioat, phys_complete); |
| 280 | |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 281 | __ioat2_restart_chan(ioat); |
Dan Williams | 09c8a5b | 2009-09-08 12:01:49 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Dan Williams | e323271 | 2009-09-08 17:43:02 -0700 | [diff] [blame] | 284 | void ioat2_timer_event(unsigned long data) |
Dan Williams | 09c8a5b | 2009-09-08 12:01:49 -0700 | [diff] [blame] | 285 | { |
| 286 | struct ioat2_dma_chan *ioat = (void *) data; |
| 287 | struct ioat_chan_common *chan = &ioat->base; |
| 288 | |
| 289 | spin_lock_bh(&chan->cleanup_lock); |
| 290 | if (test_bit(IOAT_COMPLETION_PENDING, &chan->state)) { |
| 291 | unsigned long phys_complete; |
| 292 | u64 status; |
| 293 | |
| 294 | spin_lock_bh(&ioat->ring_lock); |
| 295 | status = ioat_chansts(chan); |
| 296 | |
| 297 | /* when halted due to errors check for channel |
| 298 | * programming errors before advancing the completion state |
| 299 | */ |
| 300 | if (is_ioat_halted(status)) { |
| 301 | u32 chanerr; |
| 302 | |
| 303 | chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET); |
Dan Williams | b57014d | 2009-11-19 17:10:07 -0700 | [diff] [blame] | 304 | dev_err(to_dev(chan), "%s: Channel halted (%x)\n", |
| 305 | __func__, chanerr); |
Dan Williams | 09c8a5b | 2009-09-08 12:01:49 -0700 | [diff] [blame] | 306 | BUG_ON(is_ioat_bug(chanerr)); |
| 307 | } |
| 308 | |
| 309 | /* if we haven't made progress and we have already |
| 310 | * acknowledged a pending completion once, then be more |
| 311 | * forceful with a restart |
| 312 | */ |
| 313 | if (ioat_cleanup_preamble(chan, &phys_complete)) |
| 314 | __cleanup(ioat, phys_complete); |
| 315 | else if (test_bit(IOAT_COMPLETION_ACK, &chan->state)) |
| 316 | ioat2_restart_channel(ioat); |
| 317 | else { |
| 318 | set_bit(IOAT_COMPLETION_ACK, &chan->state); |
| 319 | mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT); |
| 320 | } |
| 321 | spin_unlock_bh(&ioat->ring_lock); |
Dan Williams | a309218 | 2009-09-08 12:02:01 -0700 | [diff] [blame] | 322 | } else { |
| 323 | u16 active; |
| 324 | |
| 325 | /* if the ring is idle, empty, and oversized try to step |
| 326 | * down the size |
| 327 | */ |
| 328 | spin_lock_bh(&ioat->ring_lock); |
| 329 | active = ioat2_ring_active(ioat); |
| 330 | if (active == 0 && ioat->alloc_order > ioat_get_alloc_order()) |
| 331 | reshape_ring(ioat, ioat->alloc_order-1); |
| 332 | spin_unlock_bh(&ioat->ring_lock); |
| 333 | |
| 334 | /* keep shrinking until we get back to our minimum |
| 335 | * default size |
| 336 | */ |
| 337 | if (ioat->alloc_order > ioat_get_alloc_order()) |
| 338 | mod_timer(&chan->timer, jiffies + IDLE_TIMEOUT); |
Dan Williams | 09c8a5b | 2009-09-08 12:01:49 -0700 | [diff] [blame] | 339 | } |
| 340 | spin_unlock_bh(&chan->cleanup_lock); |
| 341 | } |
| 342 | |
Dan Williams | a6d52d7 | 2009-12-19 15:36:02 -0700 | [diff] [blame] | 343 | static int ioat2_reset_hw(struct ioat_chan_common *chan) |
| 344 | { |
| 345 | /* throw away whatever the channel was doing and get it initialized */ |
| 346 | u32 chanerr; |
| 347 | |
| 348 | ioat2_quiesce(chan, msecs_to_jiffies(100)); |
| 349 | |
| 350 | chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET); |
| 351 | writel(chanerr, chan->reg_base + IOAT_CHANERR_OFFSET); |
| 352 | |
| 353 | return ioat2_reset_sync(chan, msecs_to_jiffies(200)); |
| 354 | } |
| 355 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 356 | /** |
| 357 | * ioat2_enumerate_channels - find and initialize the device's channels |
| 358 | * @device: the device to be enumerated |
| 359 | */ |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 360 | int ioat2_enumerate_channels(struct ioatdma_device *device) |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 361 | { |
| 362 | struct ioat2_dma_chan *ioat; |
| 363 | struct device *dev = &device->pdev->dev; |
| 364 | struct dma_device *dma = &device->common; |
| 365 | u8 xfercap_log; |
| 366 | int i; |
| 367 | |
| 368 | INIT_LIST_HEAD(&dma->channels); |
| 369 | dma->chancnt = readb(device->reg_base + IOAT_CHANCNT_OFFSET); |
Dan Williams | bb32078 | 2009-09-08 12:01:14 -0700 | [diff] [blame] | 370 | dma->chancnt &= 0x1f; /* bits [4:0] valid */ |
| 371 | if (dma->chancnt > ARRAY_SIZE(device->idx)) { |
| 372 | dev_warn(dev, "(%d) exceeds max supported channels (%zu)\n", |
| 373 | dma->chancnt, ARRAY_SIZE(device->idx)); |
| 374 | dma->chancnt = ARRAY_SIZE(device->idx); |
| 375 | } |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 376 | xfercap_log = readb(device->reg_base + IOAT_XFERCAP_OFFSET); |
Dan Williams | bb32078 | 2009-09-08 12:01:14 -0700 | [diff] [blame] | 377 | xfercap_log &= 0x1f; /* bits [4:0] valid */ |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 378 | if (xfercap_log == 0) |
| 379 | return 0; |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 380 | dev_dbg(dev, "%s: xfercap = %d\n", __func__, 1 << xfercap_log); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 381 | |
| 382 | /* FIXME which i/oat version is i7300? */ |
| 383 | #ifdef CONFIG_I7300_IDLE_IOAT_CHANNEL |
| 384 | if (i7300_idle_platform_probe(NULL, NULL, 1) == 0) |
| 385 | dma->chancnt--; |
| 386 | #endif |
| 387 | for (i = 0; i < dma->chancnt; i++) { |
| 388 | ioat = devm_kzalloc(dev, sizeof(*ioat), GFP_KERNEL); |
| 389 | if (!ioat) |
| 390 | break; |
| 391 | |
| 392 | ioat_init_channel(device, &ioat->base, i, |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 393 | device->timer_fn, |
| 394 | device->cleanup_tasklet, |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 395 | (unsigned long) ioat); |
| 396 | ioat->xfercap_log = xfercap_log; |
| 397 | spin_lock_init(&ioat->ring_lock); |
Dan Williams | a6d52d7 | 2009-12-19 15:36:02 -0700 | [diff] [blame] | 398 | if (device->reset_hw(&ioat->base)) { |
| 399 | i = 0; |
| 400 | break; |
| 401 | } |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 402 | } |
| 403 | dma->chancnt = i; |
| 404 | return i; |
| 405 | } |
| 406 | |
| 407 | static dma_cookie_t ioat2_tx_submit_unlock(struct dma_async_tx_descriptor *tx) |
| 408 | { |
| 409 | struct dma_chan *c = tx->chan; |
| 410 | struct ioat2_dma_chan *ioat = to_ioat2_chan(c); |
Dan Williams | 09c8a5b | 2009-09-08 12:01:49 -0700 | [diff] [blame] | 411 | struct ioat_chan_common *chan = &ioat->base; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 412 | dma_cookie_t cookie = c->cookie; |
| 413 | |
| 414 | cookie++; |
| 415 | if (cookie < 0) |
| 416 | cookie = 1; |
| 417 | tx->cookie = cookie; |
| 418 | c->cookie = cookie; |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 419 | dev_dbg(to_dev(&ioat->base), "%s: cookie: %d\n", __func__, cookie); |
| 420 | |
Dan Williams | 09c8a5b | 2009-09-08 12:01:49 -0700 | [diff] [blame] | 421 | if (!test_and_set_bit(IOAT_COMPLETION_PENDING, &chan->state)) |
| 422 | mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 423 | ioat2_update_pending(ioat); |
| 424 | spin_unlock_bh(&ioat->ring_lock); |
| 425 | |
| 426 | return cookie; |
| 427 | } |
| 428 | |
Dan Williams | a309218 | 2009-09-08 12:02:01 -0700 | [diff] [blame] | 429 | static struct ioat_ring_ent *ioat2_alloc_ring_ent(struct dma_chan *chan, gfp_t flags) |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 430 | { |
| 431 | struct ioat_dma_descriptor *hw; |
| 432 | struct ioat_ring_ent *desc; |
| 433 | struct ioatdma_device *dma; |
| 434 | dma_addr_t phys; |
| 435 | |
| 436 | dma = to_ioatdma_device(chan->device); |
Dan Williams | a309218 | 2009-09-08 12:02:01 -0700 | [diff] [blame] | 437 | hw = pci_pool_alloc(dma->dma_pool, flags, &phys); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 438 | if (!hw) |
| 439 | return NULL; |
| 440 | memset(hw, 0, sizeof(*hw)); |
| 441 | |
Dan Williams | 162b96e | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 442 | desc = kmem_cache_alloc(ioat2_cache, flags); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 443 | if (!desc) { |
| 444 | pci_pool_free(dma->dma_pool, hw, phys); |
| 445 | return NULL; |
| 446 | } |
Dan Williams | 162b96e | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 447 | memset(desc, 0, sizeof(*desc)); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 448 | |
| 449 | dma_async_tx_descriptor_init(&desc->txd, chan); |
| 450 | desc->txd.tx_submit = ioat2_tx_submit_unlock; |
| 451 | desc->hw = hw; |
| 452 | desc->txd.phys = phys; |
| 453 | return desc; |
| 454 | } |
| 455 | |
| 456 | static void ioat2_free_ring_ent(struct ioat_ring_ent *desc, struct dma_chan *chan) |
| 457 | { |
| 458 | struct ioatdma_device *dma; |
| 459 | |
| 460 | dma = to_ioatdma_device(chan->device); |
| 461 | pci_pool_free(dma->dma_pool, desc->hw, desc->txd.phys); |
Dan Williams | 162b96e | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 462 | kmem_cache_free(ioat2_cache, desc); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Dan Williams | a309218 | 2009-09-08 12:02:01 -0700 | [diff] [blame] | 465 | static struct ioat_ring_ent **ioat2_alloc_ring(struct dma_chan *c, int order, gfp_t flags) |
| 466 | { |
| 467 | struct ioat_ring_ent **ring; |
| 468 | int descs = 1 << order; |
| 469 | int i; |
| 470 | |
| 471 | if (order > ioat_get_max_alloc_order()) |
| 472 | return NULL; |
| 473 | |
| 474 | /* allocate the array to hold the software ring */ |
| 475 | ring = kcalloc(descs, sizeof(*ring), flags); |
| 476 | if (!ring) |
| 477 | return NULL; |
| 478 | for (i = 0; i < descs; i++) { |
| 479 | ring[i] = ioat2_alloc_ring_ent(c, flags); |
| 480 | if (!ring[i]) { |
| 481 | while (i--) |
| 482 | ioat2_free_ring_ent(ring[i], c); |
| 483 | kfree(ring); |
| 484 | return NULL; |
| 485 | } |
| 486 | set_desc_id(ring[i], i); |
| 487 | } |
| 488 | |
| 489 | /* link descs */ |
| 490 | for (i = 0; i < descs-1; i++) { |
| 491 | struct ioat_ring_ent *next = ring[i+1]; |
| 492 | struct ioat_dma_descriptor *hw = ring[i]->hw; |
| 493 | |
| 494 | hw->next = next->txd.phys; |
| 495 | } |
| 496 | ring[i]->hw->next = ring[0]->txd.phys; |
| 497 | |
| 498 | return ring; |
| 499 | } |
| 500 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 501 | /* ioat2_alloc_chan_resources - allocate/initialize ioat2 descriptor ring |
| 502 | * @chan: channel to be initialized |
| 503 | */ |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 504 | int ioat2_alloc_chan_resources(struct dma_chan *c) |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 505 | { |
| 506 | struct ioat2_dma_chan *ioat = to_ioat2_chan(c); |
| 507 | struct ioat_chan_common *chan = &ioat->base; |
| 508 | struct ioat_ring_ent **ring; |
Dan Williams | a309218 | 2009-09-08 12:02:01 -0700 | [diff] [blame] | 509 | int order; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 510 | |
| 511 | /* have we already been set up? */ |
| 512 | if (ioat->ring) |
| 513 | return 1 << ioat->alloc_order; |
| 514 | |
| 515 | /* Setup register to interrupt and write completion status on error */ |
Dan Williams | f6ab95b | 2009-09-08 12:01:21 -0700 | [diff] [blame] | 516 | writew(IOAT_CHANCTRL_RUN, chan->reg_base + IOAT_CHANCTRL_OFFSET); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 517 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 518 | /* allocate a completion writeback area */ |
| 519 | /* doing 2 32bit writes to mmio since 1 64b write doesn't work */ |
Dan Williams | 4fb9b9e | 2009-09-08 12:01:04 -0700 | [diff] [blame] | 520 | chan->completion = pci_pool_alloc(chan->device->completion_pool, |
| 521 | GFP_KERNEL, &chan->completion_dma); |
| 522 | if (!chan->completion) |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 523 | return -ENOMEM; |
| 524 | |
Dan Williams | 4fb9b9e | 2009-09-08 12:01:04 -0700 | [diff] [blame] | 525 | memset(chan->completion, 0, sizeof(*chan->completion)); |
| 526 | writel(((u64) chan->completion_dma) & 0x00000000FFFFFFFF, |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 527 | chan->reg_base + IOAT_CHANCMP_OFFSET_LOW); |
Dan Williams | 4fb9b9e | 2009-09-08 12:01:04 -0700 | [diff] [blame] | 528 | writel(((u64) chan->completion_dma) >> 32, |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 529 | chan->reg_base + IOAT_CHANCMP_OFFSET_HIGH); |
| 530 | |
Dan Williams | a309218 | 2009-09-08 12:02:01 -0700 | [diff] [blame] | 531 | order = ioat_get_alloc_order(); |
| 532 | ring = ioat2_alloc_ring(c, order, GFP_KERNEL); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 533 | if (!ring) |
| 534 | return -ENOMEM; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 535 | |
| 536 | spin_lock_bh(&ioat->ring_lock); |
| 537 | ioat->ring = ring; |
| 538 | ioat->head = 0; |
| 539 | ioat->issued = 0; |
| 540 | ioat->tail = 0; |
Dan Williams | a309218 | 2009-09-08 12:02:01 -0700 | [diff] [blame] | 541 | ioat->alloc_order = order; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 542 | spin_unlock_bh(&ioat->ring_lock); |
| 543 | |
| 544 | tasklet_enable(&chan->cleanup_task); |
| 545 | ioat2_start_null_desc(ioat); |
| 546 | |
Dan Williams | a309218 | 2009-09-08 12:02:01 -0700 | [diff] [blame] | 547 | return 1 << ioat->alloc_order; |
| 548 | } |
| 549 | |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 550 | bool reshape_ring(struct ioat2_dma_chan *ioat, int order) |
Dan Williams | a309218 | 2009-09-08 12:02:01 -0700 | [diff] [blame] | 551 | { |
| 552 | /* reshape differs from normal ring allocation in that we want |
| 553 | * to allocate a new software ring while only |
| 554 | * extending/truncating the hardware ring |
| 555 | */ |
| 556 | struct ioat_chan_common *chan = &ioat->base; |
| 557 | struct dma_chan *c = &chan->common; |
| 558 | const u16 curr_size = ioat2_ring_mask(ioat) + 1; |
| 559 | const u16 active = ioat2_ring_active(ioat); |
| 560 | const u16 new_size = 1 << order; |
| 561 | struct ioat_ring_ent **ring; |
| 562 | u16 i; |
| 563 | |
| 564 | if (order > ioat_get_max_alloc_order()) |
| 565 | return false; |
| 566 | |
| 567 | /* double check that we have at least 1 free descriptor */ |
| 568 | if (active == curr_size) |
| 569 | return false; |
| 570 | |
| 571 | /* when shrinking, verify that we can hold the current active |
| 572 | * set in the new ring |
| 573 | */ |
| 574 | if (active >= new_size) |
| 575 | return false; |
| 576 | |
| 577 | /* allocate the array to hold the software ring */ |
| 578 | ring = kcalloc(new_size, sizeof(*ring), GFP_NOWAIT); |
| 579 | if (!ring) |
| 580 | return false; |
| 581 | |
| 582 | /* allocate/trim descriptors as needed */ |
| 583 | if (new_size > curr_size) { |
| 584 | /* copy current descriptors to the new ring */ |
| 585 | for (i = 0; i < curr_size; i++) { |
| 586 | u16 curr_idx = (ioat->tail+i) & (curr_size-1); |
| 587 | u16 new_idx = (ioat->tail+i) & (new_size-1); |
| 588 | |
| 589 | ring[new_idx] = ioat->ring[curr_idx]; |
| 590 | set_desc_id(ring[new_idx], new_idx); |
| 591 | } |
| 592 | |
| 593 | /* add new descriptors to the ring */ |
| 594 | for (i = curr_size; i < new_size; i++) { |
| 595 | u16 new_idx = (ioat->tail+i) & (new_size-1); |
| 596 | |
| 597 | ring[new_idx] = ioat2_alloc_ring_ent(c, GFP_NOWAIT); |
| 598 | if (!ring[new_idx]) { |
| 599 | while (i--) { |
| 600 | u16 new_idx = (ioat->tail+i) & (new_size-1); |
| 601 | |
| 602 | ioat2_free_ring_ent(ring[new_idx], c); |
| 603 | } |
| 604 | kfree(ring); |
| 605 | return false; |
| 606 | } |
| 607 | set_desc_id(ring[new_idx], new_idx); |
| 608 | } |
| 609 | |
| 610 | /* hw link new descriptors */ |
| 611 | for (i = curr_size-1; i < new_size; i++) { |
| 612 | u16 new_idx = (ioat->tail+i) & (new_size-1); |
| 613 | struct ioat_ring_ent *next = ring[(new_idx+1) & (new_size-1)]; |
| 614 | struct ioat_dma_descriptor *hw = ring[new_idx]->hw; |
| 615 | |
| 616 | hw->next = next->txd.phys; |
| 617 | } |
| 618 | } else { |
| 619 | struct ioat_dma_descriptor *hw; |
| 620 | struct ioat_ring_ent *next; |
| 621 | |
| 622 | /* copy current descriptors to the new ring, dropping the |
| 623 | * removed descriptors |
| 624 | */ |
| 625 | for (i = 0; i < new_size; i++) { |
| 626 | u16 curr_idx = (ioat->tail+i) & (curr_size-1); |
| 627 | u16 new_idx = (ioat->tail+i) & (new_size-1); |
| 628 | |
| 629 | ring[new_idx] = ioat->ring[curr_idx]; |
| 630 | set_desc_id(ring[new_idx], new_idx); |
| 631 | } |
| 632 | |
| 633 | /* free deleted descriptors */ |
| 634 | for (i = new_size; i < curr_size; i++) { |
| 635 | struct ioat_ring_ent *ent; |
| 636 | |
| 637 | ent = ioat2_get_ring_ent(ioat, ioat->tail+i); |
| 638 | ioat2_free_ring_ent(ent, c); |
| 639 | } |
| 640 | |
| 641 | /* fix up hardware ring */ |
| 642 | hw = ring[(ioat->tail+new_size-1) & (new_size-1)]->hw; |
| 643 | next = ring[(ioat->tail+new_size) & (new_size-1)]; |
| 644 | hw->next = next->txd.phys; |
| 645 | } |
| 646 | |
| 647 | dev_dbg(to_dev(chan), "%s: allocated %d descriptors\n", |
| 648 | __func__, new_size); |
| 649 | |
| 650 | kfree(ioat->ring); |
| 651 | ioat->ring = ring; |
| 652 | ioat->alloc_order = order; |
| 653 | |
| 654 | return true; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | /** |
| 658 | * ioat2_alloc_and_lock - common descriptor alloc boilerplate for ioat2,3 ops |
| 659 | * @idx: gets starting descriptor index on successful allocation |
| 660 | * @ioat: ioat2,3 channel (ring) to operate on |
| 661 | * @num_descs: allocation length |
| 662 | */ |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 663 | int ioat2_alloc_and_lock(u16 *idx, struct ioat2_dma_chan *ioat, int num_descs) |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 664 | { |
| 665 | struct ioat_chan_common *chan = &ioat->base; |
| 666 | |
| 667 | spin_lock_bh(&ioat->ring_lock); |
Dan Williams | a309218 | 2009-09-08 12:02:01 -0700 | [diff] [blame] | 668 | /* never allow the last descriptor to be consumed, we need at |
| 669 | * least one free at all times to allow for on-the-fly ring |
| 670 | * resizing. |
| 671 | */ |
| 672 | while (unlikely(ioat2_ring_space(ioat) <= num_descs)) { |
| 673 | if (reshape_ring(ioat, ioat->alloc_order + 1) && |
| 674 | ioat2_ring_space(ioat) > num_descs) |
| 675 | break; |
| 676 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 677 | if (printk_ratelimit()) |
| 678 | dev_dbg(to_dev(chan), |
| 679 | "%s: ring full! num_descs: %d (%x:%x:%x)\n", |
| 680 | __func__, num_descs, ioat->head, ioat->tail, |
| 681 | ioat->issued); |
| 682 | spin_unlock_bh(&ioat->ring_lock); |
| 683 | |
Dan Williams | 09c8a5b | 2009-09-08 12:01:49 -0700 | [diff] [blame] | 684 | /* progress reclaim in the allocation failure case we |
| 685 | * may be called under bh_disabled so we need to trigger |
| 686 | * the timer event directly |
| 687 | */ |
| 688 | spin_lock_bh(&chan->cleanup_lock); |
| 689 | if (jiffies > chan->timer.expires && |
| 690 | timer_pending(&chan->timer)) { |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 691 | struct ioatdma_device *device = chan->device; |
| 692 | |
Dan Williams | 09c8a5b | 2009-09-08 12:01:49 -0700 | [diff] [blame] | 693 | mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT); |
| 694 | spin_unlock_bh(&chan->cleanup_lock); |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 695 | device->timer_fn((unsigned long) ioat); |
Dan Williams | 09c8a5b | 2009-09-08 12:01:49 -0700 | [diff] [blame] | 696 | } else |
| 697 | spin_unlock_bh(&chan->cleanup_lock); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 698 | return -ENOMEM; |
| 699 | } |
| 700 | |
| 701 | dev_dbg(to_dev(chan), "%s: num_descs: %d (%x:%x:%x)\n", |
| 702 | __func__, num_descs, ioat->head, ioat->tail, ioat->issued); |
| 703 | |
| 704 | *idx = ioat2_desc_alloc(ioat, num_descs); |
| 705 | return 0; /* with ioat->ring_lock held */ |
| 706 | } |
| 707 | |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 708 | struct dma_async_tx_descriptor * |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 709 | ioat2_dma_prep_memcpy_lock(struct dma_chan *c, dma_addr_t dma_dest, |
| 710 | dma_addr_t dma_src, size_t len, unsigned long flags) |
| 711 | { |
| 712 | struct ioat2_dma_chan *ioat = to_ioat2_chan(c); |
| 713 | struct ioat_dma_descriptor *hw; |
| 714 | struct ioat_ring_ent *desc; |
| 715 | dma_addr_t dst = dma_dest; |
| 716 | dma_addr_t src = dma_src; |
| 717 | size_t total_len = len; |
| 718 | int num_descs; |
| 719 | u16 idx; |
| 720 | int i; |
| 721 | |
| 722 | num_descs = ioat2_xferlen_to_descs(ioat, len); |
| 723 | if (likely(num_descs) && |
| 724 | ioat2_alloc_and_lock(&idx, ioat, num_descs) == 0) |
| 725 | /* pass */; |
| 726 | else |
| 727 | return NULL; |
Andrew Morton | f477f5b | 2009-09-21 09:17:58 -0700 | [diff] [blame] | 728 | i = 0; |
| 729 | do { |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 730 | size_t copy = min_t(size_t, len, 1 << ioat->xfercap_log); |
| 731 | |
| 732 | desc = ioat2_get_ring_ent(ioat, idx + i); |
| 733 | hw = desc->hw; |
| 734 | |
| 735 | hw->size = copy; |
| 736 | hw->ctl = 0; |
| 737 | hw->src_addr = src; |
| 738 | hw->dst_addr = dst; |
| 739 | |
| 740 | len -= copy; |
| 741 | dst += copy; |
| 742 | src += copy; |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 743 | dump_desc_dbg(ioat, desc); |
Andrew Morton | f477f5b | 2009-09-21 09:17:58 -0700 | [diff] [blame] | 744 | } while (++i < num_descs); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 745 | |
| 746 | desc->txd.flags = flags; |
| 747 | desc->len = total_len; |
| 748 | hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT); |
Dan Williams | 128f2d5 | 2009-09-08 17:42:53 -0700 | [diff] [blame] | 749 | hw->ctl_f.fence = !!(flags & DMA_PREP_FENCE); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 750 | hw->ctl_f.compl_write = 1; |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 751 | dump_desc_dbg(ioat, desc); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 752 | /* we leave the channel locked to ensure in order submission */ |
| 753 | |
| 754 | return &desc->txd; |
| 755 | } |
| 756 | |
| 757 | /** |
| 758 | * ioat2_free_chan_resources - release all the descriptors |
| 759 | * @chan: the channel to be cleaned |
| 760 | */ |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 761 | void ioat2_free_chan_resources(struct dma_chan *c) |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 762 | { |
| 763 | struct ioat2_dma_chan *ioat = to_ioat2_chan(c); |
| 764 | struct ioat_chan_common *chan = &ioat->base; |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 765 | struct ioatdma_device *device = chan->device; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 766 | struct ioat_ring_ent *desc; |
| 767 | const u16 total_descs = 1 << ioat->alloc_order; |
| 768 | int descs; |
| 769 | int i; |
| 770 | |
| 771 | /* Before freeing channel resources first check |
| 772 | * if they have been previously allocated for this channel. |
| 773 | */ |
| 774 | if (!ioat->ring) |
| 775 | return; |
| 776 | |
| 777 | tasklet_disable(&chan->cleanup_task); |
Dan Williams | 09c8a5b | 2009-09-08 12:01:49 -0700 | [diff] [blame] | 778 | del_timer_sync(&chan->timer); |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 779 | device->cleanup_tasklet((unsigned long) ioat); |
Dan Williams | a6d52d7 | 2009-12-19 15:36:02 -0700 | [diff] [blame] | 780 | device->reset_hw(chan); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 781 | |
| 782 | spin_lock_bh(&ioat->ring_lock); |
| 783 | descs = ioat2_ring_space(ioat); |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 784 | dev_dbg(to_dev(chan), "freeing %d idle descriptors\n", descs); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 785 | for (i = 0; i < descs; i++) { |
| 786 | desc = ioat2_get_ring_ent(ioat, ioat->head + i); |
| 787 | ioat2_free_ring_ent(desc, c); |
| 788 | } |
| 789 | |
| 790 | if (descs < total_descs) |
| 791 | dev_err(to_dev(chan), "Freeing %d in use descriptors!\n", |
| 792 | total_descs - descs); |
| 793 | |
| 794 | for (i = 0; i < total_descs - descs; i++) { |
| 795 | desc = ioat2_get_ring_ent(ioat, ioat->tail + i); |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 796 | dump_desc_dbg(ioat, desc); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 797 | ioat2_free_ring_ent(desc, c); |
| 798 | } |
| 799 | |
| 800 | kfree(ioat->ring); |
| 801 | ioat->ring = NULL; |
| 802 | ioat->alloc_order = 0; |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 803 | pci_pool_free(device->completion_pool, chan->completion, |
Dan Williams | 4fb9b9e | 2009-09-08 12:01:04 -0700 | [diff] [blame] | 804 | chan->completion_dma); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 805 | spin_unlock_bh(&ioat->ring_lock); |
| 806 | |
| 807 | chan->last_completion = 0; |
Dan Williams | 4fb9b9e | 2009-09-08 12:01:04 -0700 | [diff] [blame] | 808 | chan->completion_dma = 0; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 809 | ioat->dmacount = 0; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 812 | enum dma_status |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 813 | ioat2_is_complete(struct dma_chan *c, dma_cookie_t cookie, |
| 814 | dma_cookie_t *done, dma_cookie_t *used) |
| 815 | { |
| 816 | struct ioat2_dma_chan *ioat = to_ioat2_chan(c); |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 817 | struct ioatdma_device *device = ioat->base.device; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 818 | |
| 819 | if (ioat_is_complete(c, cookie, done, used) == DMA_SUCCESS) |
| 820 | return DMA_SUCCESS; |
| 821 | |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 822 | device->cleanup_tasklet((unsigned long) ioat); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 823 | |
| 824 | return ioat_is_complete(c, cookie, done, used); |
| 825 | } |
| 826 | |
Dan Williams | 5669e31 | 2009-09-08 17:42:56 -0700 | [diff] [blame] | 827 | static ssize_t ring_size_show(struct dma_chan *c, char *page) |
| 828 | { |
| 829 | struct ioat2_dma_chan *ioat = to_ioat2_chan(c); |
| 830 | |
| 831 | return sprintf(page, "%d\n", (1 << ioat->alloc_order) & ~1); |
| 832 | } |
| 833 | static struct ioat_sysfs_entry ring_size_attr = __ATTR_RO(ring_size); |
| 834 | |
| 835 | static ssize_t ring_active_show(struct dma_chan *c, char *page) |
| 836 | { |
| 837 | struct ioat2_dma_chan *ioat = to_ioat2_chan(c); |
| 838 | |
| 839 | /* ...taken outside the lock, no need to be precise */ |
| 840 | return sprintf(page, "%d\n", ioat2_ring_active(ioat)); |
| 841 | } |
| 842 | static struct ioat_sysfs_entry ring_active_attr = __ATTR_RO(ring_active); |
| 843 | |
| 844 | static struct attribute *ioat2_attrs[] = { |
| 845 | &ring_size_attr.attr, |
| 846 | &ring_active_attr.attr, |
| 847 | &ioat_cap_attr.attr, |
| 848 | &ioat_version_attr.attr, |
| 849 | NULL, |
| 850 | }; |
| 851 | |
| 852 | struct kobj_type ioat2_ktype = { |
| 853 | .sysfs_ops = &ioat_sysfs_ops, |
| 854 | .default_attrs = ioat2_attrs, |
| 855 | }; |
| 856 | |
Dan Williams | 345d852 | 2009-09-08 12:01:30 -0700 | [diff] [blame] | 857 | int __devinit ioat2_dma_probe(struct ioatdma_device *device, int dca) |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 858 | { |
| 859 | struct pci_dev *pdev = device->pdev; |
| 860 | struct dma_device *dma; |
| 861 | struct dma_chan *c; |
| 862 | struct ioat_chan_common *chan; |
| 863 | int err; |
| 864 | |
| 865 | device->enumerate_channels = ioat2_enumerate_channels; |
Dan Williams | a6d52d7 | 2009-12-19 15:36:02 -0700 | [diff] [blame] | 866 | device->reset_hw = ioat2_reset_hw; |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 867 | device->cleanup_tasklet = ioat2_cleanup_tasklet; |
| 868 | device->timer_fn = ioat2_timer_event; |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 869 | device->self_test = ioat_dma_self_test; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 870 | dma = &device->common; |
| 871 | dma->device_prep_dma_memcpy = ioat2_dma_prep_memcpy_lock; |
| 872 | dma->device_issue_pending = ioat2_issue_pending; |
| 873 | dma->device_alloc_chan_resources = ioat2_alloc_chan_resources; |
| 874 | dma->device_free_chan_resources = ioat2_free_chan_resources; |
| 875 | dma->device_is_tx_complete = ioat2_is_complete; |
| 876 | |
| 877 | err = ioat_probe(device); |
| 878 | if (err) |
| 879 | return err; |
| 880 | ioat_set_tcp_copy_break(2048); |
| 881 | |
| 882 | list_for_each_entry(c, &dma->channels, device_node) { |
| 883 | chan = to_chan_common(c); |
| 884 | writel(IOAT_DCACTRL_CMPL_WRITE_ENABLE | IOAT_DMA_DCA_ANY_CPU, |
| 885 | chan->reg_base + IOAT_DCACTRL_OFFSET); |
| 886 | } |
| 887 | |
| 888 | err = ioat_register(device); |
| 889 | if (err) |
| 890 | return err; |
Dan Williams | 5669e31 | 2009-09-08 17:42:56 -0700 | [diff] [blame] | 891 | |
| 892 | ioat_kobject_add(device, &ioat2_ktype); |
| 893 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 894 | if (dca) |
| 895 | device->dca = ioat2_dca_init(pdev, device->reg_base); |
| 896 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 897 | return err; |
| 898 | } |