blob: 54d1a3c24e9cf7ced38c8bbf53f56c888254c792 [file] [log] [blame]
Dan Williams5cbafa62009-08-26 13:01:44 -07001/*
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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/slab.h>
Dan Williams5cbafa62009-08-26 13:01:44 -070031#include <linux/pci.h>
32#include <linux/interrupt.h>
33#include <linux/dmaengine.h>
34#include <linux/delay.h>
35#include <linux/dma-mapping.h>
36#include <linux/workqueue.h>
37#include <linux/i7300_idle.h>
38#include "dma.h"
39#include "dma_v2.h"
40#include "registers.h"
41#include "hw.h"
42
Dan Williamsbf40a682009-09-08 17:42:55 -070043int ioat_ring_alloc_order = 8;
Dan Williams5cbafa62009-08-26 13:01:44 -070044module_param(ioat_ring_alloc_order, int, 0644);
45MODULE_PARM_DESC(ioat_ring_alloc_order,
Dan Williams376ec372009-09-16 15:16:50 -070046 "ioat2+: allocate 2^n descriptors per channel"
47 " (default: 8 max: 16)");
Dan Williamsa3092182009-09-08 12:02:01 -070048static int ioat_ring_max_alloc_order = IOAT_MAX_ORDER;
49module_param(ioat_ring_max_alloc_order, int, 0644);
50MODULE_PARM_DESC(ioat_ring_max_alloc_order,
Dan Williams376ec372009-09-16 15:16:50 -070051 "ioat2+: upper limit for ring size (default: 16)");
Dan Williams5cbafa62009-08-26 13:01:44 -070052
Dan Williamsb094ad32009-09-08 17:42:57 -070053void __ioat2_issue_pending(struct ioat2_dma_chan *ioat)
Dan Williams5cbafa62009-08-26 13:01:44 -070054{
Dan Williams281befa2010-03-03 11:47:43 -070055 struct ioat_chan_common *chan = &ioat->base;
Dan Williams5cbafa62009-08-26 13:01:44 -070056
Dan Williams376ec372009-09-16 15:16:50 -070057 ioat->dmacount += ioat2_ring_pending(ioat);
Dan Williams5cbafa62009-08-26 13:01:44 -070058 ioat->issued = ioat->head;
Dan Williams281befa2010-03-03 11:47:43 -070059 writew(ioat->dmacount, chan->reg_base + IOAT_CHAN_DMACOUNT_OFFSET);
60 dev_dbg(to_dev(chan),
Dan Williams6df91832009-09-08 12:00:55 -070061 "%s: head: %#x tail: %#x issued: %#x count: %#x\n",
62 __func__, ioat->head, ioat->tail, ioat->issued, ioat->dmacount);
Dan Williams5cbafa62009-08-26 13:01:44 -070063}
64
Dan Williams281befa2010-03-03 11:47:43 -070065void ioat2_issue_pending(struct dma_chan *c)
Dan Williams5cbafa62009-08-26 13:01:44 -070066{
Dan Williams281befa2010-03-03 11:47:43 -070067 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
Dan Williams5cbafa62009-08-26 13:01:44 -070068
Dan Williams281befa2010-03-03 11:47:43 -070069 if (ioat2_ring_pending(ioat)) {
Dan Williams074cc472010-05-01 15:22:55 -070070 spin_lock_bh(&ioat->prep_lock);
Dan Williams5cbafa62009-08-26 13:01:44 -070071 __ioat2_issue_pending(ioat);
Dan Williams074cc472010-05-01 15:22:55 -070072 spin_unlock_bh(&ioat->prep_lock);
Dan Williams281befa2010-03-03 11:47:43 -070073 }
Dan Williams5cbafa62009-08-26 13:01:44 -070074}
75
76/**
77 * ioat2_update_pending - log pending descriptors
78 * @ioat: ioat2+ channel
79 *
Dan Williams281befa2010-03-03 11:47:43 -070080 * Check if the number of unsubmitted descriptors has exceeded the
Dan Williams074cc472010-05-01 15:22:55 -070081 * watermark. Called with prep_lock held
Dan Williams5cbafa62009-08-26 13:01:44 -070082 */
83static void ioat2_update_pending(struct ioat2_dma_chan *ioat)
84{
Dan Williams281befa2010-03-03 11:47:43 -070085 if (ioat2_ring_pending(ioat) > ioat_pending_level)
Dan Williams5cbafa62009-08-26 13:01:44 -070086 __ioat2_issue_pending(ioat);
Dan Williams5cbafa62009-08-26 13:01:44 -070087}
88
89static void __ioat2_start_null_desc(struct ioat2_dma_chan *ioat)
90{
Dan Williams5cbafa62009-08-26 13:01:44 -070091 struct ioat_ring_ent *desc;
92 struct ioat_dma_descriptor *hw;
Dan Williams5cbafa62009-08-26 13:01:44 -070093
94 if (ioat2_ring_space(ioat) < 1) {
95 dev_err(to_dev(&ioat->base),
96 "Unable to start null desc - ring full\n");
97 return;
98 }
99
Dan Williams6df91832009-09-08 12:00:55 -0700100 dev_dbg(to_dev(&ioat->base), "%s: head: %#x tail: %#x issued: %#x\n",
101 __func__, ioat->head, ioat->tail, ioat->issued);
Dan Williams074cc472010-05-01 15:22:55 -0700102 desc = ioat2_get_ring_ent(ioat, ioat->head);
Dan Williams5cbafa62009-08-26 13:01:44 -0700103
104 hw = desc->hw;
105 hw->ctl = 0;
106 hw->ctl_f.null = 1;
107 hw->ctl_f.int_en = 1;
108 hw->ctl_f.compl_write = 1;
109 /* set size to non-zero value (channel returns error when size is 0) */
110 hw->size = NULL_DESC_BUFFER_SIZE;
111 hw->src_addr = 0;
112 hw->dst_addr = 0;
113 async_tx_ack(&desc->txd);
Dan Williams09c8a5b2009-09-08 12:01:49 -0700114 ioat2_set_chainaddr(ioat, desc->txd.phys);
Dan Williams6df91832009-09-08 12:00:55 -0700115 dump_desc_dbg(ioat, desc);
Dan Williams074cc472010-05-01 15:22:55 -0700116 wmb();
117 ioat->head += 1;
Dan Williams5cbafa62009-08-26 13:01:44 -0700118 __ioat2_issue_pending(ioat);
119}
120
121static void ioat2_start_null_desc(struct ioat2_dma_chan *ioat)
122{
Dan Williams074cc472010-05-01 15:22:55 -0700123 spin_lock_bh(&ioat->prep_lock);
Dan Williams5cbafa62009-08-26 13:01:44 -0700124 __ioat2_start_null_desc(ioat);
Dan Williams074cc472010-05-01 15:22:55 -0700125 spin_unlock_bh(&ioat->prep_lock);
Dan Williams5cbafa62009-08-26 13:01:44 -0700126}
127
Dan Williams09c8a5b2009-09-08 12:01:49 -0700128static void __cleanup(struct ioat2_dma_chan *ioat, unsigned long phys_complete)
Dan Williams5cbafa62009-08-26 13:01:44 -0700129{
130 struct ioat_chan_common *chan = &ioat->base;
Dan Williams09c8a5b2009-09-08 12:01:49 -0700131 struct dma_async_tx_descriptor *tx;
Dan Williams5cbafa62009-08-26 13:01:44 -0700132 struct ioat_ring_ent *desc;
133 bool seen_current = false;
134 u16 active;
Dan Williams074cc472010-05-01 15:22:55 -0700135 int idx = ioat->tail, i;
Dan Williams5cbafa62009-08-26 13:01:44 -0700136
Dan Williams6df91832009-09-08 12:00:55 -0700137 dev_dbg(to_dev(chan), "%s: head: %#x tail: %#x issued: %#x\n",
138 __func__, ioat->head, ioat->tail, ioat->issued);
139
Dan Williams5cbafa62009-08-26 13:01:44 -0700140 active = ioat2_ring_active(ioat);
141 for (i = 0; i < active && !seen_current; i++) {
Dan Williams074cc472010-05-01 15:22:55 -0700142 smp_read_barrier_depends();
143 prefetch(ioat2_get_ring_ent(ioat, idx + i + 1));
144 desc = ioat2_get_ring_ent(ioat, idx + i);
Dan Williams5cbafa62009-08-26 13:01:44 -0700145 tx = &desc->txd;
Dan Williams6df91832009-09-08 12:00:55 -0700146 dump_desc_dbg(ioat, desc);
Dan Williams5cbafa62009-08-26 13:01:44 -0700147 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 }
Dan Williams074cc472010-05-01 15:22:55 -0700160 smp_mb(); /* finish all descriptor reads before incrementing tail */
161 ioat->tail = idx + i;
Dan Williamsaa75db02010-03-03 21:21:10 -0700162 BUG_ON(active && !seen_current); /* no active descs have written a completion? */
Dan Williams5cbafa62009-08-26 13:01:44 -0700163
164 chan->last_completion = phys_complete;
Dan Williams074cc472010-05-01 15:22:55 -0700165 if (active - i == 0) {
Dan Williams09c8a5b2009-09-08 12:01:49 -0700166 dev_dbg(to_dev(chan), "%s: cancel completion timeout\n",
167 __func__);
168 clear_bit(IOAT_COMPLETION_PENDING, &chan->state);
Dan Williamsa3092182009-09-08 12:02:01 -0700169 mod_timer(&chan->timer, jiffies + IDLE_TIMEOUT);
Dan Williams09c8a5b2009-09-08 12:01:49 -0700170 }
171}
Dan Williams5cbafa62009-08-26 13:01:44 -0700172
Dan Williams09c8a5b2009-09-08 12:01:49 -0700173/**
174 * ioat2_cleanup - clean finished descriptors (advance tail pointer)
175 * @chan: ioat channel to be cleaned up
176 */
177static void ioat2_cleanup(struct ioat2_dma_chan *ioat)
178{
179 struct ioat_chan_common *chan = &ioat->base;
180 unsigned long phys_complete;
181
Dan Williams074cc472010-05-01 15:22:55 -0700182 spin_lock_bh(&chan->cleanup_lock);
183 if (ioat_cleanup_preamble(chan, &phys_complete))
184 __cleanup(ioat, phys_complete);
Dan Williams5cbafa62009-08-26 13:01:44 -0700185 spin_unlock_bh(&chan->cleanup_lock);
186}
187
Dan Williamsaa4d72a2010-03-03 21:21:13 -0700188void ioat2_cleanup_event(unsigned long data)
Dan Williams5cbafa62009-08-26 13:01:44 -0700189{
Dan Williamsaa4d72a2010-03-03 21:21:13 -0700190 struct ioat2_dma_chan *ioat = to_ioat2_chan((void *) data);
Dan Williams5cbafa62009-08-26 13:01:44 -0700191
192 ioat2_cleanup(ioat);
Dan Williamsf6ab95b2009-09-08 12:01:21 -0700193 writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET);
Dan Williams5cbafa62009-08-26 13:01:44 -0700194}
195
Dan Williamsbf40a682009-09-08 17:42:55 -0700196void __ioat2_restart_chan(struct ioat2_dma_chan *ioat)
Dan Williams09c8a5b2009-09-08 12:01:49 -0700197{
198 struct ioat_chan_common *chan = &ioat->base;
199
200 /* set the tail to be re-issued */
201 ioat->issued = ioat->tail;
202 ioat->dmacount = 0;
203 set_bit(IOAT_COMPLETION_PENDING, &chan->state);
204 mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
205
206 dev_dbg(to_dev(chan),
207 "%s: head: %#x tail: %#x issued: %#x count: %#x\n",
208 __func__, ioat->head, ioat->tail, ioat->issued, ioat->dmacount);
209
210 if (ioat2_ring_pending(ioat)) {
211 struct ioat_ring_ent *desc;
212
213 desc = ioat2_get_ring_ent(ioat, ioat->tail);
214 ioat2_set_chainaddr(ioat, desc->txd.phys);
215 __ioat2_issue_pending(ioat);
216 } else
217 __ioat2_start_null_desc(ioat);
218}
219
Dan Williamsa6d52d72009-12-19 15:36:02 -0700220int ioat2_quiesce(struct ioat_chan_common *chan, unsigned long tmo)
Dan Williams09c8a5b2009-09-08 12:01:49 -0700221{
Dan Williamsa6d52d72009-12-19 15:36:02 -0700222 unsigned long end = jiffies + tmo;
223 int err = 0;
Dan Williams09c8a5b2009-09-08 12:01:49 -0700224 u32 status;
225
226 status = ioat_chansts(chan);
227 if (is_ioat_active(status) || is_ioat_idle(status))
228 ioat_suspend(chan);
229 while (is_ioat_active(status) || is_ioat_idle(status)) {
Dan Williams7e55a702010-01-13 13:33:12 -0700230 if (tmo && time_after(jiffies, end)) {
Dan Williamsa6d52d72009-12-19 15:36:02 -0700231 err = -ETIMEDOUT;
232 break;
233 }
Dan Williams09c8a5b2009-09-08 12:01:49 -0700234 status = ioat_chansts(chan);
235 cpu_relax();
236 }
237
Dan Williamsa6d52d72009-12-19 15:36:02 -0700238 return err;
239}
240
241int ioat2_reset_sync(struct ioat_chan_common *chan, unsigned long tmo)
242{
243 unsigned long end = jiffies + tmo;
244 int err = 0;
245
246 ioat_reset(chan);
247 while (ioat_reset_pending(chan)) {
248 if (end && time_after(jiffies, end)) {
249 err = -ETIMEDOUT;
250 break;
251 }
252 cpu_relax();
253 }
254
255 return err;
256}
257
258static void ioat2_restart_channel(struct ioat2_dma_chan *ioat)
259{
260 struct ioat_chan_common *chan = &ioat->base;
261 unsigned long phys_complete;
262
263 ioat2_quiesce(chan, 0);
Dan Williams09c8a5b2009-09-08 12:01:49 -0700264 if (ioat_cleanup_preamble(chan, &phys_complete))
265 __cleanup(ioat, phys_complete);
266
Dan Williamsbf40a682009-09-08 17:42:55 -0700267 __ioat2_restart_chan(ioat);
Dan Williams09c8a5b2009-09-08 12:01:49 -0700268}
269
Dan Williamse3232712009-09-08 17:43:02 -0700270void ioat2_timer_event(unsigned long data)
Dan Williams09c8a5b2009-09-08 12:01:49 -0700271{
Dan Williamsaa4d72a2010-03-03 21:21:13 -0700272 struct ioat2_dma_chan *ioat = to_ioat2_chan((void *) data);
Dan Williams09c8a5b2009-09-08 12:01:49 -0700273 struct ioat_chan_common *chan = &ioat->base;
274
Dan Williams09c8a5b2009-09-08 12:01:49 -0700275 if (test_bit(IOAT_COMPLETION_PENDING, &chan->state)) {
276 unsigned long phys_complete;
277 u64 status;
278
Dan Williams09c8a5b2009-09-08 12:01:49 -0700279 status = ioat_chansts(chan);
280
281 /* when halted due to errors check for channel
282 * programming errors before advancing the completion state
283 */
284 if (is_ioat_halted(status)) {
285 u32 chanerr;
286
287 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
Dan Williamsb57014d2009-11-19 17:10:07 -0700288 dev_err(to_dev(chan), "%s: Channel halted (%x)\n",
289 __func__, chanerr);
Dan Williams556ab452010-07-23 15:47:56 -0700290 if (test_bit(IOAT_RUN, &chan->state))
291 BUG_ON(is_ioat_bug(chanerr));
292 else /* we never got off the ground */
293 return;
Dan Williams09c8a5b2009-09-08 12:01:49 -0700294 }
295
296 /* if we haven't made progress and we have already
297 * acknowledged a pending completion once, then be more
298 * forceful with a restart
299 */
Dan Williams074cc472010-05-01 15:22:55 -0700300 spin_lock_bh(&chan->cleanup_lock);
301 if (ioat_cleanup_preamble(chan, &phys_complete)) {
Dan Williams09c8a5b2009-09-08 12:01:49 -0700302 __cleanup(ioat, phys_complete);
Dan Williams074cc472010-05-01 15:22:55 -0700303 } else if (test_bit(IOAT_COMPLETION_ACK, &chan->state)) {
304 spin_lock_bh(&ioat->prep_lock);
Dan Williams09c8a5b2009-09-08 12:01:49 -0700305 ioat2_restart_channel(ioat);
Dan Williams074cc472010-05-01 15:22:55 -0700306 spin_unlock_bh(&ioat->prep_lock);
307 } else {
Dan Williams09c8a5b2009-09-08 12:01:49 -0700308 set_bit(IOAT_COMPLETION_ACK, &chan->state);
309 mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
310 }
Dan Williams074cc472010-05-01 15:22:55 -0700311 spin_unlock_bh(&chan->cleanup_lock);
Dan Williamsa3092182009-09-08 12:02:01 -0700312 } else {
313 u16 active;
314
315 /* if the ring is idle, empty, and oversized try to step
316 * down the size
317 */
Dan Williams074cc472010-05-01 15:22:55 -0700318 spin_lock_bh(&chan->cleanup_lock);
319 spin_lock_bh(&ioat->prep_lock);
Dan Williamsa3092182009-09-08 12:02:01 -0700320 active = ioat2_ring_active(ioat);
321 if (active == 0 && ioat->alloc_order > ioat_get_alloc_order())
322 reshape_ring(ioat, ioat->alloc_order-1);
Dan Williams074cc472010-05-01 15:22:55 -0700323 spin_unlock_bh(&ioat->prep_lock);
324 spin_unlock_bh(&chan->cleanup_lock);
Dan Williamsa3092182009-09-08 12:02:01 -0700325
326 /* keep shrinking until we get back to our minimum
327 * default size
328 */
329 if (ioat->alloc_order > ioat_get_alloc_order())
330 mod_timer(&chan->timer, jiffies + IDLE_TIMEOUT);
Dan Williams09c8a5b2009-09-08 12:01:49 -0700331 }
Dan Williams09c8a5b2009-09-08 12:01:49 -0700332}
333
Dan Williamsa6d52d72009-12-19 15:36:02 -0700334static int ioat2_reset_hw(struct ioat_chan_common *chan)
335{
336 /* throw away whatever the channel was doing and get it initialized */
337 u32 chanerr;
338
339 ioat2_quiesce(chan, msecs_to_jiffies(100));
340
341 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
342 writel(chanerr, chan->reg_base + IOAT_CHANERR_OFFSET);
343
344 return ioat2_reset_sync(chan, msecs_to_jiffies(200));
345}
346
Dan Williams5cbafa62009-08-26 13:01:44 -0700347/**
348 * ioat2_enumerate_channels - find and initialize the device's channels
349 * @device: the device to be enumerated
350 */
Dan Williamsbf40a682009-09-08 17:42:55 -0700351int ioat2_enumerate_channels(struct ioatdma_device *device)
Dan Williams5cbafa62009-08-26 13:01:44 -0700352{
353 struct ioat2_dma_chan *ioat;
354 struct device *dev = &device->pdev->dev;
355 struct dma_device *dma = &device->common;
356 u8 xfercap_log;
357 int i;
358
359 INIT_LIST_HEAD(&dma->channels);
360 dma->chancnt = readb(device->reg_base + IOAT_CHANCNT_OFFSET);
Dan Williamsbb320782009-09-08 12:01:14 -0700361 dma->chancnt &= 0x1f; /* bits [4:0] valid */
362 if (dma->chancnt > ARRAY_SIZE(device->idx)) {
363 dev_warn(dev, "(%d) exceeds max supported channels (%zu)\n",
364 dma->chancnt, ARRAY_SIZE(device->idx));
365 dma->chancnt = ARRAY_SIZE(device->idx);
366 }
Dan Williams5cbafa62009-08-26 13:01:44 -0700367 xfercap_log = readb(device->reg_base + IOAT_XFERCAP_OFFSET);
Dan Williamsbb320782009-09-08 12:01:14 -0700368 xfercap_log &= 0x1f; /* bits [4:0] valid */
Dan Williams5cbafa62009-08-26 13:01:44 -0700369 if (xfercap_log == 0)
370 return 0;
Dan Williams6df91832009-09-08 12:00:55 -0700371 dev_dbg(dev, "%s: xfercap = %d\n", __func__, 1 << xfercap_log);
Dan Williams5cbafa62009-08-26 13:01:44 -0700372
373 /* FIXME which i/oat version is i7300? */
374#ifdef CONFIG_I7300_IDLE_IOAT_CHANNEL
375 if (i7300_idle_platform_probe(NULL, NULL, 1) == 0)
376 dma->chancnt--;
377#endif
378 for (i = 0; i < dma->chancnt; i++) {
379 ioat = devm_kzalloc(dev, sizeof(*ioat), GFP_KERNEL);
380 if (!ioat)
381 break;
382
Dan Williamsaa4d72a2010-03-03 21:21:13 -0700383 ioat_init_channel(device, &ioat->base, i);
Dan Williams5cbafa62009-08-26 13:01:44 -0700384 ioat->xfercap_log = xfercap_log;
Dan Williams074cc472010-05-01 15:22:55 -0700385 spin_lock_init(&ioat->prep_lock);
Dan Williamsa6d52d72009-12-19 15:36:02 -0700386 if (device->reset_hw(&ioat->base)) {
387 i = 0;
388 break;
389 }
Dan Williams5cbafa62009-08-26 13:01:44 -0700390 }
391 dma->chancnt = i;
392 return i;
393}
394
395static dma_cookie_t ioat2_tx_submit_unlock(struct dma_async_tx_descriptor *tx)
396{
397 struct dma_chan *c = tx->chan;
398 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
Dan Williams09c8a5b2009-09-08 12:01:49 -0700399 struct ioat_chan_common *chan = &ioat->base;
Dan Williams5cbafa62009-08-26 13:01:44 -0700400 dma_cookie_t cookie = c->cookie;
401
402 cookie++;
403 if (cookie < 0)
404 cookie = 1;
405 tx->cookie = cookie;
406 c->cookie = cookie;
Dan Williams6df91832009-09-08 12:00:55 -0700407 dev_dbg(to_dev(&ioat->base), "%s: cookie: %d\n", __func__, cookie);
408
Dan Williams09c8a5b2009-09-08 12:01:49 -0700409 if (!test_and_set_bit(IOAT_COMPLETION_PENDING, &chan->state))
410 mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
Dan Williams074cc472010-05-01 15:22:55 -0700411
412 /* make descriptor updates visible before advancing ioat->head,
413 * this is purposefully not smp_wmb() since we are also
414 * publishing the descriptor updates to a dma device
415 */
416 wmb();
417
418 ioat->head += ioat->produce;
419
Dan Williams5cbafa62009-08-26 13:01:44 -0700420 ioat2_update_pending(ioat);
Dan Williams074cc472010-05-01 15:22:55 -0700421 spin_unlock_bh(&ioat->prep_lock);
Dan Williams5cbafa62009-08-26 13:01:44 -0700422
423 return cookie;
424}
425
Dan Williamsa3092182009-09-08 12:02:01 -0700426static struct ioat_ring_ent *ioat2_alloc_ring_ent(struct dma_chan *chan, gfp_t flags)
Dan Williams5cbafa62009-08-26 13:01:44 -0700427{
428 struct ioat_dma_descriptor *hw;
429 struct ioat_ring_ent *desc;
430 struct ioatdma_device *dma;
431 dma_addr_t phys;
432
433 dma = to_ioatdma_device(chan->device);
Dan Williamsa3092182009-09-08 12:02:01 -0700434 hw = pci_pool_alloc(dma->dma_pool, flags, &phys);
Dan Williams5cbafa62009-08-26 13:01:44 -0700435 if (!hw)
436 return NULL;
437 memset(hw, 0, sizeof(*hw));
438
Dan Williams162b96e2009-09-08 17:53:04 -0700439 desc = kmem_cache_alloc(ioat2_cache, flags);
Dan Williams5cbafa62009-08-26 13:01:44 -0700440 if (!desc) {
441 pci_pool_free(dma->dma_pool, hw, phys);
442 return NULL;
443 }
Dan Williams162b96e2009-09-08 17:53:04 -0700444 memset(desc, 0, sizeof(*desc));
Dan Williams5cbafa62009-08-26 13:01:44 -0700445
446 dma_async_tx_descriptor_init(&desc->txd, chan);
447 desc->txd.tx_submit = ioat2_tx_submit_unlock;
448 desc->hw = hw;
449 desc->txd.phys = phys;
450 return desc;
451}
452
453static void ioat2_free_ring_ent(struct ioat_ring_ent *desc, struct dma_chan *chan)
454{
455 struct ioatdma_device *dma;
456
457 dma = to_ioatdma_device(chan->device);
458 pci_pool_free(dma->dma_pool, desc->hw, desc->txd.phys);
Dan Williams162b96e2009-09-08 17:53:04 -0700459 kmem_cache_free(ioat2_cache, desc);
Dan Williams5cbafa62009-08-26 13:01:44 -0700460}
461
Dan Williamsa3092182009-09-08 12:02:01 -0700462static struct ioat_ring_ent **ioat2_alloc_ring(struct dma_chan *c, int order, gfp_t flags)
463{
464 struct ioat_ring_ent **ring;
465 int descs = 1 << order;
466 int i;
467
468 if (order > ioat_get_max_alloc_order())
469 return NULL;
470
471 /* allocate the array to hold the software ring */
472 ring = kcalloc(descs, sizeof(*ring), flags);
473 if (!ring)
474 return NULL;
475 for (i = 0; i < descs; i++) {
476 ring[i] = ioat2_alloc_ring_ent(c, flags);
477 if (!ring[i]) {
478 while (i--)
479 ioat2_free_ring_ent(ring[i], c);
480 kfree(ring);
481 return NULL;
482 }
483 set_desc_id(ring[i], i);
484 }
485
486 /* link descs */
487 for (i = 0; i < descs-1; i++) {
488 struct ioat_ring_ent *next = ring[i+1];
489 struct ioat_dma_descriptor *hw = ring[i]->hw;
490
491 hw->next = next->txd.phys;
492 }
493 ring[i]->hw->next = ring[0]->txd.phys;
494
495 return ring;
496}
497
Dan Williams556ab452010-07-23 15:47:56 -0700498void ioat2_free_chan_resources(struct dma_chan *c);
499
Dan Williams5cbafa62009-08-26 13:01:44 -0700500/* ioat2_alloc_chan_resources - allocate/initialize ioat2 descriptor ring
501 * @chan: channel to be initialized
502 */
Dan Williamsbf40a682009-09-08 17:42:55 -0700503int ioat2_alloc_chan_resources(struct dma_chan *c)
Dan Williams5cbafa62009-08-26 13:01:44 -0700504{
505 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
506 struct ioat_chan_common *chan = &ioat->base;
507 struct ioat_ring_ent **ring;
Dan Williams556ab452010-07-23 15:47:56 -0700508 u64 status;
Dan Williamsa3092182009-09-08 12:02:01 -0700509 int order;
Dimitri Sivanich19d78a62011-05-06 10:33:44 -0500510 int i = 0;
Dan Williams5cbafa62009-08-26 13:01:44 -0700511
512 /* have we already been set up? */
513 if (ioat->ring)
514 return 1 << ioat->alloc_order;
515
516 /* Setup register to interrupt and write completion status on error */
Dan Williamsf6ab95b2009-09-08 12:01:21 -0700517 writew(IOAT_CHANCTRL_RUN, chan->reg_base + IOAT_CHANCTRL_OFFSET);
Dan Williams5cbafa62009-08-26 13:01:44 -0700518
Dan Williams5cbafa62009-08-26 13:01:44 -0700519 /* allocate a completion writeback area */
520 /* doing 2 32bit writes to mmio since 1 64b write doesn't work */
Dan Williams4fb9b9e2009-09-08 12:01:04 -0700521 chan->completion = pci_pool_alloc(chan->device->completion_pool,
522 GFP_KERNEL, &chan->completion_dma);
523 if (!chan->completion)
Dan Williams5cbafa62009-08-26 13:01:44 -0700524 return -ENOMEM;
525
Dan Williams4fb9b9e2009-09-08 12:01:04 -0700526 memset(chan->completion, 0, sizeof(*chan->completion));
527 writel(((u64) chan->completion_dma) & 0x00000000FFFFFFFF,
Dan Williams5cbafa62009-08-26 13:01:44 -0700528 chan->reg_base + IOAT_CHANCMP_OFFSET_LOW);
Dan Williams4fb9b9e2009-09-08 12:01:04 -0700529 writel(((u64) chan->completion_dma) >> 32,
Dan Williams5cbafa62009-08-26 13:01:44 -0700530 chan->reg_base + IOAT_CHANCMP_OFFSET_HIGH);
531
Dan Williamsa3092182009-09-08 12:02:01 -0700532 order = ioat_get_alloc_order();
533 ring = ioat2_alloc_ring(c, order, GFP_KERNEL);
Dan Williams5cbafa62009-08-26 13:01:44 -0700534 if (!ring)
535 return -ENOMEM;
Dan Williams5cbafa62009-08-26 13:01:44 -0700536
Dan Williams074cc472010-05-01 15:22:55 -0700537 spin_lock_bh(&chan->cleanup_lock);
538 spin_lock_bh(&ioat->prep_lock);
Dan Williams5cbafa62009-08-26 13:01:44 -0700539 ioat->ring = ring;
540 ioat->head = 0;
541 ioat->issued = 0;
542 ioat->tail = 0;
Dan Williamsa3092182009-09-08 12:02:01 -0700543 ioat->alloc_order = order;
Dan Williams074cc472010-05-01 15:22:55 -0700544 spin_unlock_bh(&ioat->prep_lock);
545 spin_unlock_bh(&chan->cleanup_lock);
Dan Williams5cbafa62009-08-26 13:01:44 -0700546
547 tasklet_enable(&chan->cleanup_task);
548 ioat2_start_null_desc(ioat);
549
Dan Williams556ab452010-07-23 15:47:56 -0700550 /* check that we got off the ground */
Dimitri Sivanich19d78a62011-05-06 10:33:44 -0500551 do {
552 udelay(1);
553 status = ioat_chansts(chan);
554 } while (i++ < 20 && !is_ioat_active(status) && !is_ioat_idle(status));
555
Dan Williams556ab452010-07-23 15:47:56 -0700556 if (is_ioat_active(status) || is_ioat_idle(status)) {
557 set_bit(IOAT_RUN, &chan->state);
558 return 1 << ioat->alloc_order;
559 } else {
560 u32 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
561
562 dev_WARN(to_dev(chan),
563 "failed to start channel chanerr: %#x\n", chanerr);
564 ioat2_free_chan_resources(c);
565 return -EFAULT;
566 }
Dan Williamsa3092182009-09-08 12:02:01 -0700567}
568
Dan Williamsbf40a682009-09-08 17:42:55 -0700569bool reshape_ring(struct ioat2_dma_chan *ioat, int order)
Dan Williamsa3092182009-09-08 12:02:01 -0700570{
571 /* reshape differs from normal ring allocation in that we want
572 * to allocate a new software ring while only
573 * extending/truncating the hardware ring
574 */
575 struct ioat_chan_common *chan = &ioat->base;
576 struct dma_chan *c = &chan->common;
Dan Williamsabb12df2010-05-01 15:22:54 -0700577 const u16 curr_size = ioat2_ring_size(ioat);
Dan Williamsa3092182009-09-08 12:02:01 -0700578 const u16 active = ioat2_ring_active(ioat);
579 const u16 new_size = 1 << order;
580 struct ioat_ring_ent **ring;
581 u16 i;
582
583 if (order > ioat_get_max_alloc_order())
584 return false;
585
586 /* double check that we have at least 1 free descriptor */
587 if (active == curr_size)
588 return false;
589
590 /* when shrinking, verify that we can hold the current active
591 * set in the new ring
592 */
593 if (active >= new_size)
594 return false;
595
596 /* allocate the array to hold the software ring */
597 ring = kcalloc(new_size, sizeof(*ring), GFP_NOWAIT);
598 if (!ring)
599 return false;
600
601 /* allocate/trim descriptors as needed */
602 if (new_size > curr_size) {
603 /* copy current descriptors to the new ring */
604 for (i = 0; i < curr_size; i++) {
605 u16 curr_idx = (ioat->tail+i) & (curr_size-1);
606 u16 new_idx = (ioat->tail+i) & (new_size-1);
607
608 ring[new_idx] = ioat->ring[curr_idx];
609 set_desc_id(ring[new_idx], new_idx);
610 }
611
612 /* add new descriptors to the ring */
613 for (i = curr_size; i < new_size; i++) {
614 u16 new_idx = (ioat->tail+i) & (new_size-1);
615
616 ring[new_idx] = ioat2_alloc_ring_ent(c, GFP_NOWAIT);
617 if (!ring[new_idx]) {
618 while (i--) {
619 u16 new_idx = (ioat->tail+i) & (new_size-1);
620
621 ioat2_free_ring_ent(ring[new_idx], c);
622 }
623 kfree(ring);
624 return false;
625 }
626 set_desc_id(ring[new_idx], new_idx);
627 }
628
629 /* hw link new descriptors */
630 for (i = curr_size-1; i < new_size; i++) {
631 u16 new_idx = (ioat->tail+i) & (new_size-1);
632 struct ioat_ring_ent *next = ring[(new_idx+1) & (new_size-1)];
633 struct ioat_dma_descriptor *hw = ring[new_idx]->hw;
634
635 hw->next = next->txd.phys;
636 }
637 } else {
638 struct ioat_dma_descriptor *hw;
639 struct ioat_ring_ent *next;
640
641 /* copy current descriptors to the new ring, dropping the
642 * removed descriptors
643 */
644 for (i = 0; i < new_size; i++) {
645 u16 curr_idx = (ioat->tail+i) & (curr_size-1);
646 u16 new_idx = (ioat->tail+i) & (new_size-1);
647
648 ring[new_idx] = ioat->ring[curr_idx];
649 set_desc_id(ring[new_idx], new_idx);
650 }
651
652 /* free deleted descriptors */
653 for (i = new_size; i < curr_size; i++) {
654 struct ioat_ring_ent *ent;
655
656 ent = ioat2_get_ring_ent(ioat, ioat->tail+i);
657 ioat2_free_ring_ent(ent, c);
658 }
659
660 /* fix up hardware ring */
661 hw = ring[(ioat->tail+new_size-1) & (new_size-1)]->hw;
662 next = ring[(ioat->tail+new_size) & (new_size-1)];
663 hw->next = next->txd.phys;
664 }
665
666 dev_dbg(to_dev(chan), "%s: allocated %d descriptors\n",
667 __func__, new_size);
668
669 kfree(ioat->ring);
670 ioat->ring = ring;
671 ioat->alloc_order = order;
672
673 return true;
Dan Williams5cbafa62009-08-26 13:01:44 -0700674}
675
676/**
Dan Williams074cc472010-05-01 15:22:55 -0700677 * ioat2_check_space_lock - verify space and grab ring producer lock
Dan Williams5cbafa62009-08-26 13:01:44 -0700678 * @ioat: ioat2,3 channel (ring) to operate on
679 * @num_descs: allocation length
680 */
Dan Williams074cc472010-05-01 15:22:55 -0700681int ioat2_check_space_lock(struct ioat2_dma_chan *ioat, int num_descs)
Dan Williams5cbafa62009-08-26 13:01:44 -0700682{
683 struct ioat_chan_common *chan = &ioat->base;
Dan Williams074cc472010-05-01 15:22:55 -0700684 bool retry;
Dan Williams5cbafa62009-08-26 13:01:44 -0700685
Dan Williams074cc472010-05-01 15:22:55 -0700686 retry:
687 spin_lock_bh(&ioat->prep_lock);
Dan Williamsa3092182009-09-08 12:02:01 -0700688 /* never allow the last descriptor to be consumed, we need at
689 * least one free at all times to allow for on-the-fly ring
690 * resizing.
691 */
Dan Williams074cc472010-05-01 15:22:55 -0700692 if (likely(ioat2_ring_space(ioat) > num_descs)) {
693 dev_dbg(to_dev(chan), "%s: num_descs: %d (%x:%x:%x)\n",
694 __func__, num_descs, ioat->head, ioat->tail, ioat->issued);
695 ioat->produce = num_descs;
696 return 0; /* with ioat->prep_lock held */
697 }
698 retry = test_and_set_bit(IOAT_RESHAPE_PENDING, &chan->state);
699 spin_unlock_bh(&ioat->prep_lock);
Dan Williamsa3092182009-09-08 12:02:01 -0700700
Dan Williams074cc472010-05-01 15:22:55 -0700701 /* is another cpu already trying to expand the ring? */
702 if (retry)
703 goto retry;
Dan Williams5cbafa62009-08-26 13:01:44 -0700704
Dan Williams074cc472010-05-01 15:22:55 -0700705 spin_lock_bh(&chan->cleanup_lock);
706 spin_lock_bh(&ioat->prep_lock);
707 retry = reshape_ring(ioat, ioat->alloc_order + 1);
708 clear_bit(IOAT_RESHAPE_PENDING, &chan->state);
709 spin_unlock_bh(&ioat->prep_lock);
710 spin_unlock_bh(&chan->cleanup_lock);
Dan Williamsbf40a682009-09-08 17:42:55 -0700711
Dan Williams074cc472010-05-01 15:22:55 -0700712 /* if we were able to expand the ring retry the allocation */
713 if (retry)
714 goto retry;
715
716 if (printk_ratelimit())
717 dev_dbg(to_dev(chan), "%s: ring full! num_descs: %d (%x:%x:%x)\n",
718 __func__, num_descs, ioat->head, ioat->tail, ioat->issued);
719
720 /* progress reclaim in the allocation failure case we may be
721 * called under bh_disabled so we need to trigger the timer
722 * event directly
723 */
724 if (jiffies > chan->timer.expires && timer_pending(&chan->timer)) {
725 struct ioatdma_device *device = chan->device;
726
727 mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
728 device->timer_fn((unsigned long) &chan->common);
Dan Williams5cbafa62009-08-26 13:01:44 -0700729 }
730
Dan Williams074cc472010-05-01 15:22:55 -0700731 return -ENOMEM;
Dan Williams5cbafa62009-08-26 13:01:44 -0700732}
733
Dan Williamsbf40a682009-09-08 17:42:55 -0700734struct dma_async_tx_descriptor *
Dan Williams5cbafa62009-08-26 13:01:44 -0700735ioat2_dma_prep_memcpy_lock(struct dma_chan *c, dma_addr_t dma_dest,
736 dma_addr_t dma_src, size_t len, unsigned long flags)
737{
738 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
739 struct ioat_dma_descriptor *hw;
740 struct ioat_ring_ent *desc;
741 dma_addr_t dst = dma_dest;
742 dma_addr_t src = dma_src;
743 size_t total_len = len;
Dan Williams074cc472010-05-01 15:22:55 -0700744 int num_descs, idx, i;
Dan Williams5cbafa62009-08-26 13:01:44 -0700745
746 num_descs = ioat2_xferlen_to_descs(ioat, len);
Dan Williams074cc472010-05-01 15:22:55 -0700747 if (likely(num_descs) && ioat2_check_space_lock(ioat, num_descs) == 0)
748 idx = ioat->head;
Dan Williams5cbafa62009-08-26 13:01:44 -0700749 else
750 return NULL;
Andrew Mortonf477f5b2009-09-21 09:17:58 -0700751 i = 0;
752 do {
Dan Williams5cbafa62009-08-26 13:01:44 -0700753 size_t copy = min_t(size_t, len, 1 << ioat->xfercap_log);
754
755 desc = ioat2_get_ring_ent(ioat, idx + i);
756 hw = desc->hw;
757
758 hw->size = copy;
759 hw->ctl = 0;
760 hw->src_addr = src;
761 hw->dst_addr = dst;
762
763 len -= copy;
764 dst += copy;
765 src += copy;
Dan Williams6df91832009-09-08 12:00:55 -0700766 dump_desc_dbg(ioat, desc);
Andrew Mortonf477f5b2009-09-21 09:17:58 -0700767 } while (++i < num_descs);
Dan Williams5cbafa62009-08-26 13:01:44 -0700768
769 desc->txd.flags = flags;
770 desc->len = total_len;
771 hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
Dan Williams128f2d52009-09-08 17:42:53 -0700772 hw->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
Dan Williams5cbafa62009-08-26 13:01:44 -0700773 hw->ctl_f.compl_write = 1;
Dan Williams6df91832009-09-08 12:00:55 -0700774 dump_desc_dbg(ioat, desc);
Dan Williams5cbafa62009-08-26 13:01:44 -0700775 /* we leave the channel locked to ensure in order submission */
776
777 return &desc->txd;
778}
779
780/**
781 * ioat2_free_chan_resources - release all the descriptors
782 * @chan: the channel to be cleaned
783 */
Dan Williamsbf40a682009-09-08 17:42:55 -0700784void ioat2_free_chan_resources(struct dma_chan *c)
Dan Williams5cbafa62009-08-26 13:01:44 -0700785{
786 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
787 struct ioat_chan_common *chan = &ioat->base;
Dan Williamsbf40a682009-09-08 17:42:55 -0700788 struct ioatdma_device *device = chan->device;
Dan Williams5cbafa62009-08-26 13:01:44 -0700789 struct ioat_ring_ent *desc;
790 const u16 total_descs = 1 << ioat->alloc_order;
791 int descs;
792 int i;
793
794 /* Before freeing channel resources first check
795 * if they have been previously allocated for this channel.
796 */
797 if (!ioat->ring)
798 return;
799
800 tasklet_disable(&chan->cleanup_task);
Dan Williams09c8a5b2009-09-08 12:01:49 -0700801 del_timer_sync(&chan->timer);
Dan Williamsaa4d72a2010-03-03 21:21:13 -0700802 device->cleanup_fn((unsigned long) c);
Dan Williamsa6d52d72009-12-19 15:36:02 -0700803 device->reset_hw(chan);
Dan Williams556ab452010-07-23 15:47:56 -0700804 clear_bit(IOAT_RUN, &chan->state);
Dan Williams5cbafa62009-08-26 13:01:44 -0700805
Dan Williams074cc472010-05-01 15:22:55 -0700806 spin_lock_bh(&chan->cleanup_lock);
807 spin_lock_bh(&ioat->prep_lock);
Dan Williams5cbafa62009-08-26 13:01:44 -0700808 descs = ioat2_ring_space(ioat);
Dan Williams6df91832009-09-08 12:00:55 -0700809 dev_dbg(to_dev(chan), "freeing %d idle descriptors\n", descs);
Dan Williams5cbafa62009-08-26 13:01:44 -0700810 for (i = 0; i < descs; i++) {
811 desc = ioat2_get_ring_ent(ioat, ioat->head + i);
812 ioat2_free_ring_ent(desc, c);
813 }
814
815 if (descs < total_descs)
816 dev_err(to_dev(chan), "Freeing %d in use descriptors!\n",
817 total_descs - descs);
818
819 for (i = 0; i < total_descs - descs; i++) {
820 desc = ioat2_get_ring_ent(ioat, ioat->tail + i);
Dan Williams6df91832009-09-08 12:00:55 -0700821 dump_desc_dbg(ioat, desc);
Dan Williams5cbafa62009-08-26 13:01:44 -0700822 ioat2_free_ring_ent(desc, c);
823 }
824
825 kfree(ioat->ring);
826 ioat->ring = NULL;
827 ioat->alloc_order = 0;
Dan Williamsbf40a682009-09-08 17:42:55 -0700828 pci_pool_free(device->completion_pool, chan->completion,
Dan Williams4fb9b9e2009-09-08 12:01:04 -0700829 chan->completion_dma);
Dan Williams074cc472010-05-01 15:22:55 -0700830 spin_unlock_bh(&ioat->prep_lock);
831 spin_unlock_bh(&chan->cleanup_lock);
Dan Williams5cbafa62009-08-26 13:01:44 -0700832
833 chan->last_completion = 0;
Dan Williams4fb9b9e2009-09-08 12:01:04 -0700834 chan->completion_dma = 0;
Dan Williams5cbafa62009-08-26 13:01:44 -0700835 ioat->dmacount = 0;
Dan Williams5cbafa62009-08-26 13:01:44 -0700836}
837
Dan Williams5669e312009-09-08 17:42:56 -0700838static ssize_t ring_size_show(struct dma_chan *c, char *page)
839{
840 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
841
842 return sprintf(page, "%d\n", (1 << ioat->alloc_order) & ~1);
843}
844static struct ioat_sysfs_entry ring_size_attr = __ATTR_RO(ring_size);
845
846static ssize_t ring_active_show(struct dma_chan *c, char *page)
847{
848 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
849
850 /* ...taken outside the lock, no need to be precise */
851 return sprintf(page, "%d\n", ioat2_ring_active(ioat));
852}
853static struct ioat_sysfs_entry ring_active_attr = __ATTR_RO(ring_active);
854
855static struct attribute *ioat2_attrs[] = {
856 &ring_size_attr.attr,
857 &ring_active_attr.attr,
858 &ioat_cap_attr.attr,
859 &ioat_version_attr.attr,
860 NULL,
861};
862
863struct kobj_type ioat2_ktype = {
864 .sysfs_ops = &ioat_sysfs_ops,
865 .default_attrs = ioat2_attrs,
866};
867
Dan Williams345d8522009-09-08 12:01:30 -0700868int __devinit ioat2_dma_probe(struct ioatdma_device *device, int dca)
Dan Williams5cbafa62009-08-26 13:01:44 -0700869{
870 struct pci_dev *pdev = device->pdev;
871 struct dma_device *dma;
872 struct dma_chan *c;
873 struct ioat_chan_common *chan;
874 int err;
875
876 device->enumerate_channels = ioat2_enumerate_channels;
Dan Williamsa6d52d72009-12-19 15:36:02 -0700877 device->reset_hw = ioat2_reset_hw;
Dan Williamsaa4d72a2010-03-03 21:21:13 -0700878 device->cleanup_fn = ioat2_cleanup_event;
Dan Williamsbf40a682009-09-08 17:42:55 -0700879 device->timer_fn = ioat2_timer_event;
Dan Williams9de6fc72009-09-08 17:42:58 -0700880 device->self_test = ioat_dma_self_test;
Dan Williams5cbafa62009-08-26 13:01:44 -0700881 dma = &device->common;
882 dma->device_prep_dma_memcpy = ioat2_dma_prep_memcpy_lock;
883 dma->device_issue_pending = ioat2_issue_pending;
884 dma->device_alloc_chan_resources = ioat2_alloc_chan_resources;
885 dma->device_free_chan_resources = ioat2_free_chan_resources;
Dan Williamsc50a8982010-10-13 15:43:10 -0700886 dma->device_tx_status = ioat_dma_tx_status;
Dan Williams5cbafa62009-08-26 13:01:44 -0700887
888 err = ioat_probe(device);
889 if (err)
890 return err;
891 ioat_set_tcp_copy_break(2048);
892
893 list_for_each_entry(c, &dma->channels, device_node) {
894 chan = to_chan_common(c);
895 writel(IOAT_DCACTRL_CMPL_WRITE_ENABLE | IOAT_DMA_DCA_ANY_CPU,
896 chan->reg_base + IOAT_DCACTRL_OFFSET);
897 }
898
899 err = ioat_register(device);
900 if (err)
901 return err;
Dan Williams5669e312009-09-08 17:42:56 -0700902
903 ioat_kobject_add(device, &ioat2_ktype);
904
Dan Williams5cbafa62009-08-26 13:01:44 -0700905 if (dca)
906 device->dca = ioat2_dca_init(pdev, device->reg_base);
907
Dan Williams5cbafa62009-08-26 13:01:44 -0700908 return err;
909}