blob: ab5655eb060261209c547237e60aff4de3501ff1 [file] [log] [blame]
Dan Williamsbf40a682009-09-08 17:42:55 -07001/*
2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
4 *
5 * GPL LICENSE SUMMARY
6 *
7 * Copyright(c) 2004 - 2009 Intel Corporation. All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms and conditions of the GNU General Public License,
11 * version 2, as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 * The full GNU General Public License is included in this distribution in
23 * the file called "COPYING".
24 *
25 * BSD LICENSE
26 *
27 * Copyright(c) 2004-2009 Intel Corporation. All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions are met:
31 *
32 * * Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer.
34 * * Redistributions in binary form must reproduce the above copyright
35 * notice, this list of conditions and the following disclaimer in
36 * the documentation and/or other materials provided with the
37 * distribution.
38 * * Neither the name of Intel Corporation nor the names of its
39 * contributors may be used to endorse or promote products derived
40 * from this software without specific prior written permission.
41 *
42 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
46 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
47 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
48 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
49 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
50 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
52 * POSSIBILITY OF SUCH DAMAGE.
53 */
54
55/*
56 * Support routines for v3+ hardware
57 */
58
59#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090060#include <linux/gfp.h>
Dan Williamsbf40a682009-09-08 17:42:55 -070061#include <linux/dmaengine.h>
62#include <linux/dma-mapping.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040063#include <linux/prefetch.h>
Vinod Koul949ff5b2012-03-13 11:58:12 +053064#include "../dmaengine.h"
Dan Williamsbf40a682009-09-08 17:42:55 -070065#include "registers.h"
66#include "hw.h"
67#include "dma.h"
68#include "dma_v2.h"
69
Dan Williamsb094ad32009-09-08 17:42:57 -070070/* ioat hardware assumes at least two sources for raid operations */
71#define src_cnt_to_sw(x) ((x) + 2)
72#define src_cnt_to_hw(x) ((x) - 2)
73
74/* provide a lookup table for setting the source address in the base or
Dan Williamsd69d235b2009-09-08 17:42:59 -070075 * extended descriptor of an xor or pq descriptor
Dan Williamsb094ad32009-09-08 17:42:57 -070076 */
Dan Williamsd0b0c8c2011-07-22 14:20:46 -070077static const u8 xor_idx_to_desc = 0xe0;
Andi Kleen9b487ce2011-06-07 15:26:33 -070078static const u8 xor_idx_to_field[] = { 1, 4, 5, 6, 7, 0, 1, 2 };
79static const u8 pq_idx_to_desc = 0xf8;
80static const u8 pq_idx_to_field[] = { 1, 4, 5, 0, 1, 2, 4, 5 };
Dan Williamsb094ad32009-09-08 17:42:57 -070081
82static dma_addr_t xor_get_src(struct ioat_raw_descriptor *descs[2], int idx)
83{
84 struct ioat_raw_descriptor *raw = descs[xor_idx_to_desc >> idx & 1];
85
86 return raw->field[xor_idx_to_field[idx]];
87}
88
89static void xor_set_src(struct ioat_raw_descriptor *descs[2],
90 dma_addr_t addr, u32 offset, int idx)
91{
92 struct ioat_raw_descriptor *raw = descs[xor_idx_to_desc >> idx & 1];
93
94 raw->field[xor_idx_to_field[idx]] = addr + offset;
95}
96
Dan Williamsd69d235b2009-09-08 17:42:59 -070097static dma_addr_t pq_get_src(struct ioat_raw_descriptor *descs[2], int idx)
98{
99 struct ioat_raw_descriptor *raw = descs[pq_idx_to_desc >> idx & 1];
100
101 return raw->field[pq_idx_to_field[idx]];
102}
103
104static void pq_set_src(struct ioat_raw_descriptor *descs[2],
105 dma_addr_t addr, u32 offset, u8 coef, int idx)
106{
107 struct ioat_pq_descriptor *pq = (struct ioat_pq_descriptor *) descs[0];
108 struct ioat_raw_descriptor *raw = descs[pq_idx_to_desc >> idx & 1];
109
110 raw->field[pq_idx_to_field[idx]] = addr + offset;
111 pq->coef[idx] = coef;
112}
113
Dan Williamsbf40a682009-09-08 17:42:55 -0700114static void ioat3_dma_unmap(struct ioat2_dma_chan *ioat,
Dan Williamsb094ad32009-09-08 17:42:57 -0700115 struct ioat_ring_ent *desc, int idx)
Dan Williamsbf40a682009-09-08 17:42:55 -0700116{
117 struct ioat_chan_common *chan = &ioat->base;
118 struct pci_dev *pdev = chan->device->pdev;
119 size_t len = desc->len;
120 size_t offset = len - desc->hw->size;
121 struct dma_async_tx_descriptor *tx = &desc->txd;
122 enum dma_ctrl_flags flags = tx->flags;
123
124 switch (desc->hw->ctl_f.op) {
125 case IOAT_OP_COPY:
Dan Williams58c86492009-09-08 17:43:00 -0700126 if (!desc->hw->ctl_f.null) /* skip 'interrupt' ops */
127 ioat_dma_unmap(chan, flags, len, desc->hw);
Dan Williamsbf40a682009-09-08 17:42:55 -0700128 break;
129 case IOAT_OP_FILL: {
130 struct ioat_fill_descriptor *hw = desc->fill;
131
132 if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP))
133 ioat_unmap(pdev, hw->dst_addr - offset, len,
134 PCI_DMA_FROMDEVICE, flags, 1);
135 break;
136 }
Dan Williamsb094ad32009-09-08 17:42:57 -0700137 case IOAT_OP_XOR_VAL:
138 case IOAT_OP_XOR: {
139 struct ioat_xor_descriptor *xor = desc->xor;
140 struct ioat_ring_ent *ext;
141 struct ioat_xor_ext_descriptor *xor_ex = NULL;
142 int src_cnt = src_cnt_to_sw(xor->ctl_f.src_cnt);
143 struct ioat_raw_descriptor *descs[2];
144 int i;
145
146 if (src_cnt > 5) {
147 ext = ioat2_get_ring_ent(ioat, idx + 1);
148 xor_ex = ext->xor_ex;
149 }
150
151 if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
152 descs[0] = (struct ioat_raw_descriptor *) xor;
153 descs[1] = (struct ioat_raw_descriptor *) xor_ex;
154 for (i = 0; i < src_cnt; i++) {
155 dma_addr_t src = xor_get_src(descs, i);
156
157 ioat_unmap(pdev, src - offset, len,
158 PCI_DMA_TODEVICE, flags, 0);
159 }
160
161 /* dest is a source in xor validate operations */
162 if (xor->ctl_f.op == IOAT_OP_XOR_VAL) {
163 ioat_unmap(pdev, xor->dst_addr - offset, len,
164 PCI_DMA_TODEVICE, flags, 1);
165 break;
166 }
167 }
168
169 if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP))
170 ioat_unmap(pdev, xor->dst_addr - offset, len,
171 PCI_DMA_FROMDEVICE, flags, 1);
172 break;
173 }
Dan Williamsd69d235b2009-09-08 17:42:59 -0700174 case IOAT_OP_PQ_VAL:
175 case IOAT_OP_PQ: {
176 struct ioat_pq_descriptor *pq = desc->pq;
177 struct ioat_ring_ent *ext;
178 struct ioat_pq_ext_descriptor *pq_ex = NULL;
179 int src_cnt = src_cnt_to_sw(pq->ctl_f.src_cnt);
180 struct ioat_raw_descriptor *descs[2];
181 int i;
182
183 if (src_cnt > 3) {
184 ext = ioat2_get_ring_ent(ioat, idx + 1);
185 pq_ex = ext->pq_ex;
186 }
187
188 /* in the 'continue' case don't unmap the dests as sources */
189 if (dmaf_p_disabled_continue(flags))
190 src_cnt--;
191 else if (dmaf_continue(flags))
192 src_cnt -= 3;
193
194 if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
195 descs[0] = (struct ioat_raw_descriptor *) pq;
196 descs[1] = (struct ioat_raw_descriptor *) pq_ex;
197 for (i = 0; i < src_cnt; i++) {
198 dma_addr_t src = pq_get_src(descs, i);
199
200 ioat_unmap(pdev, src - offset, len,
201 PCI_DMA_TODEVICE, flags, 0);
202 }
203
204 /* the dests are sources in pq validate operations */
205 if (pq->ctl_f.op == IOAT_OP_XOR_VAL) {
206 if (!(flags & DMA_PREP_PQ_DISABLE_P))
207 ioat_unmap(pdev, pq->p_addr - offset,
208 len, PCI_DMA_TODEVICE, flags, 0);
209 if (!(flags & DMA_PREP_PQ_DISABLE_Q))
210 ioat_unmap(pdev, pq->q_addr - offset,
211 len, PCI_DMA_TODEVICE, flags, 0);
212 break;
213 }
214 }
215
216 if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP)) {
217 if (!(flags & DMA_PREP_PQ_DISABLE_P))
218 ioat_unmap(pdev, pq->p_addr - offset, len,
219 PCI_DMA_BIDIRECTIONAL, flags, 1);
220 if (!(flags & DMA_PREP_PQ_DISABLE_Q))
221 ioat_unmap(pdev, pq->q_addr - offset, len,
222 PCI_DMA_BIDIRECTIONAL, flags, 1);
223 }
224 break;
225 }
Dan Williamsbf40a682009-09-08 17:42:55 -0700226 default:
227 dev_err(&pdev->dev, "%s: unknown op type: %#x\n",
228 __func__, desc->hw->ctl_f.op);
229 }
230}
231
Dan Williamsb094ad32009-09-08 17:42:57 -0700232static bool desc_has_ext(struct ioat_ring_ent *desc)
233{
234 struct ioat_dma_descriptor *hw = desc->hw;
Dan Williamsbf40a682009-09-08 17:42:55 -0700235
Dan Williamsb094ad32009-09-08 17:42:57 -0700236 if (hw->ctl_f.op == IOAT_OP_XOR ||
237 hw->ctl_f.op == IOAT_OP_XOR_VAL) {
238 struct ioat_xor_descriptor *xor = desc->xor;
239
240 if (src_cnt_to_sw(xor->ctl_f.src_cnt) > 5)
241 return true;
Dan Williamsd69d235b2009-09-08 17:42:59 -0700242 } else if (hw->ctl_f.op == IOAT_OP_PQ ||
243 hw->ctl_f.op == IOAT_OP_PQ_VAL) {
244 struct ioat_pq_descriptor *pq = desc->pq;
245
246 if (src_cnt_to_sw(pq->ctl_f.src_cnt) > 3)
247 return true;
Dan Williamsb094ad32009-09-08 17:42:57 -0700248 }
249
250 return false;
251}
252
253/**
254 * __cleanup - reclaim used descriptors
255 * @ioat: channel (ring) to clean
256 *
257 * The difference from the dma_v2.c __cleanup() is that this routine
258 * handles extended descriptors and dma-unmapping raid operations.
259 */
Dan Williams27502932012-03-23 13:36:42 -0700260static void __cleanup(struct ioat2_dma_chan *ioat, dma_addr_t phys_complete)
Dan Williamsbf40a682009-09-08 17:42:55 -0700261{
262 struct ioat_chan_common *chan = &ioat->base;
263 struct ioat_ring_ent *desc;
264 bool seen_current = false;
Dan Williams074cc472010-05-01 15:22:55 -0700265 int idx = ioat->tail, i;
Dan Williamsbf40a682009-09-08 17:42:55 -0700266 u16 active;
Dan Williamsbf40a682009-09-08 17:42:55 -0700267
268 dev_dbg(to_dev(chan), "%s: head: %#x tail: %#x issued: %#x\n",
269 __func__, ioat->head, ioat->tail, ioat->issued);
270
271 active = ioat2_ring_active(ioat);
272 for (i = 0; i < active && !seen_current; i++) {
273 struct dma_async_tx_descriptor *tx;
274
Dan Williams074cc472010-05-01 15:22:55 -0700275 smp_read_barrier_depends();
276 prefetch(ioat2_get_ring_ent(ioat, idx + i + 1));
277 desc = ioat2_get_ring_ent(ioat, idx + i);
Dan Williamsbf40a682009-09-08 17:42:55 -0700278 dump_desc_dbg(ioat, desc);
279 tx = &desc->txd;
280 if (tx->cookie) {
Russell King - ARM Linuxf7fbce02012-03-06 22:35:07 +0000281 dma_cookie_complete(tx);
Dan Williams074cc472010-05-01 15:22:55 -0700282 ioat3_dma_unmap(ioat, desc, idx + i);
Dan Williamsbf40a682009-09-08 17:42:55 -0700283 if (tx->callback) {
284 tx->callback(tx->callback_param);
285 tx->callback = NULL;
286 }
287 }
288
289 if (tx->phys == phys_complete)
290 seen_current = true;
Dan Williamsb094ad32009-09-08 17:42:57 -0700291
292 /* skip extended descriptors */
293 if (desc_has_ext(desc)) {
294 BUG_ON(i + 1 >= active);
295 i++;
296 }
Dan Williamsbf40a682009-09-08 17:42:55 -0700297 }
Dan Williams074cc472010-05-01 15:22:55 -0700298 smp_mb(); /* finish all descriptor reads before incrementing tail */
299 ioat->tail = idx + i;
Dan Williamsaa75db02010-03-03 21:21:10 -0700300 BUG_ON(active && !seen_current); /* no active descs have written a completion? */
Dan Williamsbf40a682009-09-08 17:42:55 -0700301 chan->last_completion = phys_complete;
Dan Williamsb9cc9862010-03-03 21:21:13 -0700302
Dan Williams074cc472010-05-01 15:22:55 -0700303 if (active - i == 0) {
Dan Williamsbf40a682009-09-08 17:42:55 -0700304 dev_dbg(to_dev(chan), "%s: cancel completion timeout\n",
305 __func__);
306 clear_bit(IOAT_COMPLETION_PENDING, &chan->state);
307 mod_timer(&chan->timer, jiffies + IDLE_TIMEOUT);
308 }
Dan Williamsb9cc9862010-03-03 21:21:13 -0700309 /* 5 microsecond delay per pending descriptor */
Dan Williams074cc472010-05-01 15:22:55 -0700310 writew(min((5 * (active - i)), IOAT_INTRDELAY_MASK),
Dan Williamsb9cc9862010-03-03 21:21:13 -0700311 chan->device->reg_base + IOAT_INTRDELAY_OFFSET);
Dan Williamsbf40a682009-09-08 17:42:55 -0700312}
313
Dan Williams074cc472010-05-01 15:22:55 -0700314static void ioat3_cleanup(struct ioat2_dma_chan *ioat)
Dan Williamsbf40a682009-09-08 17:42:55 -0700315{
316 struct ioat_chan_common *chan = &ioat->base;
Dan Williams27502932012-03-23 13:36:42 -0700317 dma_addr_t phys_complete;
Dan Williamsbf40a682009-09-08 17:42:55 -0700318
Dan Williamsb9cc9862010-03-03 21:21:13 -0700319 spin_lock_bh(&chan->cleanup_lock);
Dan Williams074cc472010-05-01 15:22:55 -0700320 if (ioat_cleanup_preamble(chan, &phys_complete))
321 __cleanup(ioat, phys_complete);
Dan Williamsb9cc9862010-03-03 21:21:13 -0700322 spin_unlock_bh(&chan->cleanup_lock);
323}
324
Dan Williamsaa4d72a2010-03-03 21:21:13 -0700325static void ioat3_cleanup_event(unsigned long data)
Dan Williamsbf40a682009-09-08 17:42:55 -0700326{
Dan Williamsaa4d72a2010-03-03 21:21:13 -0700327 struct ioat2_dma_chan *ioat = to_ioat2_chan((void *) data);
Dan Williamsbf40a682009-09-08 17:42:55 -0700328
Dan Williams074cc472010-05-01 15:22:55 -0700329 ioat3_cleanup(ioat);
Dan Williams773d9e22010-03-03 11:47:42 -0700330 writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET);
Dan Williamsbf40a682009-09-08 17:42:55 -0700331}
332
333static void ioat3_restart_channel(struct ioat2_dma_chan *ioat)
334{
335 struct ioat_chan_common *chan = &ioat->base;
Dan Williams27502932012-03-23 13:36:42 -0700336 dma_addr_t phys_complete;
Dan Williamsbf40a682009-09-08 17:42:55 -0700337
Dan Williamsb372ec22010-03-03 11:47:42 -0700338 ioat2_quiesce(chan, 0);
Dan Williamsbf40a682009-09-08 17:42:55 -0700339 if (ioat_cleanup_preamble(chan, &phys_complete))
340 __cleanup(ioat, phys_complete);
341
342 __ioat2_restart_chan(ioat);
343}
344
Dave Jiang4dec23d2013-02-07 14:38:32 -0700345static void check_active(struct ioat2_dma_chan *ioat)
Dan Williamsbf40a682009-09-08 17:42:55 -0700346{
Dan Williamsbf40a682009-09-08 17:42:55 -0700347 struct ioat_chan_common *chan = &ioat->base;
348
Dave Jiang4dec23d2013-02-07 14:38:32 -0700349 if (ioat2_ring_active(ioat)) {
350 mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
351 return;
352 }
Dan Williamsbf40a682009-09-08 17:42:55 -0700353
Dave Jiang4dec23d2013-02-07 14:38:32 -0700354 if (test_and_clear_bit(IOAT_CHAN_ACTIVE, &chan->state))
355 mod_timer(&chan->timer, jiffies + IDLE_TIMEOUT);
356 else if (ioat->alloc_order > ioat_get_alloc_order()) {
Dan Williamsbf40a682009-09-08 17:42:55 -0700357 /* if the ring is idle, empty, and oversized try to step
358 * down the size
359 */
Dave Jiang4dec23d2013-02-07 14:38:32 -0700360 reshape_ring(ioat, ioat->alloc_order - 1);
Dan Williamsbf40a682009-09-08 17:42:55 -0700361
362 /* keep shrinking until we get back to our minimum
363 * default size
364 */
365 if (ioat->alloc_order > ioat_get_alloc_order())
366 mod_timer(&chan->timer, jiffies + IDLE_TIMEOUT);
367 }
Dave Jiang4dec23d2013-02-07 14:38:32 -0700368
369}
370
Fengguang Wua20702b2013-02-13 09:40:03 +0800371static void ioat3_timer_event(unsigned long data)
Dave Jiang4dec23d2013-02-07 14:38:32 -0700372{
373 struct ioat2_dma_chan *ioat = to_ioat2_chan((void *) data);
374 struct ioat_chan_common *chan = &ioat->base;
375 dma_addr_t phys_complete;
376 u64 status;
377
378 status = ioat_chansts(chan);
379
380 /* when halted due to errors check for channel
381 * programming errors before advancing the completion state
382 */
383 if (is_ioat_halted(status)) {
384 u32 chanerr;
385
386 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
387 dev_err(to_dev(chan), "%s: Channel halted (%x)\n",
388 __func__, chanerr);
389 if (test_bit(IOAT_RUN, &chan->state))
390 BUG_ON(is_ioat_bug(chanerr));
391 else /* we never got off the ground */
392 return;
393 }
394
395 /* if we haven't made progress and we have already
396 * acknowledged a pending completion once, then be more
397 * forceful with a restart
398 */
399 spin_lock_bh(&chan->cleanup_lock);
400 if (ioat_cleanup_preamble(chan, &phys_complete))
401 __cleanup(ioat, phys_complete);
402 else if (test_bit(IOAT_COMPLETION_ACK, &chan->state)) {
403 spin_lock_bh(&ioat->prep_lock);
404 ioat3_restart_channel(ioat);
405 spin_unlock_bh(&ioat->prep_lock);
406 spin_unlock_bh(&chan->cleanup_lock);
407 return;
408 } else {
409 set_bit(IOAT_COMPLETION_ACK, &chan->state);
410 mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
411 }
412
413
414 if (ioat2_ring_active(ioat))
415 mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
416 else {
417 spin_lock_bh(&ioat->prep_lock);
418 check_active(ioat);
419 spin_unlock_bh(&ioat->prep_lock);
420 }
421 spin_unlock_bh(&chan->cleanup_lock);
Dan Williamsbf40a682009-09-08 17:42:55 -0700422}
423
424static enum dma_status
Linus Walleij07934482010-03-26 16:50:49 -0700425ioat3_tx_status(struct dma_chan *c, dma_cookie_t cookie,
426 struct dma_tx_state *txstate)
Dan Williamsbf40a682009-09-08 17:42:55 -0700427{
428 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
Russell King - ARM Linux96a2af42012-03-06 22:35:27 +0000429 enum dma_status ret;
Dan Williamsbf40a682009-09-08 17:42:55 -0700430
Russell King - ARM Linux96a2af42012-03-06 22:35:27 +0000431 ret = dma_cookie_status(c, cookie, txstate);
432 if (ret == DMA_SUCCESS)
433 return ret;
Dan Williamsbf40a682009-09-08 17:42:55 -0700434
Dan Williams074cc472010-05-01 15:22:55 -0700435 ioat3_cleanup(ioat);
Dan Williamsbf40a682009-09-08 17:42:55 -0700436
Russell King - ARM Linux96a2af42012-03-06 22:35:27 +0000437 return dma_cookie_status(c, cookie, txstate);
Dan Williamsbf40a682009-09-08 17:42:55 -0700438}
439
440static struct dma_async_tx_descriptor *
441ioat3_prep_memset_lock(struct dma_chan *c, dma_addr_t dest, int value,
442 size_t len, unsigned long flags)
443{
444 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
445 struct ioat_ring_ent *desc;
446 size_t total_len = len;
447 struct ioat_fill_descriptor *fill;
Dan Williamsbf40a682009-09-08 17:42:55 -0700448 u64 src_data = (0x0101010101010101ULL) * (value & 0xff);
Dan Williams074cc472010-05-01 15:22:55 -0700449 int num_descs, idx, i;
Dan Williamsbf40a682009-09-08 17:42:55 -0700450
451 num_descs = ioat2_xferlen_to_descs(ioat, len);
Dan Williams074cc472010-05-01 15:22:55 -0700452 if (likely(num_descs) && ioat2_check_space_lock(ioat, num_descs) == 0)
453 idx = ioat->head;
Dan Williamsbf40a682009-09-08 17:42:55 -0700454 else
455 return NULL;
Dan Williamscdef57d2009-09-21 09:22:29 -0700456 i = 0;
457 do {
Dan Williamsbf40a682009-09-08 17:42:55 -0700458 size_t xfer_size = min_t(size_t, len, 1 << ioat->xfercap_log);
459
460 desc = ioat2_get_ring_ent(ioat, idx + i);
461 fill = desc->fill;
462
463 fill->size = xfer_size;
464 fill->src_data = src_data;
465 fill->dst_addr = dest;
466 fill->ctl = 0;
467 fill->ctl_f.op = IOAT_OP_FILL;
468
469 len -= xfer_size;
470 dest += xfer_size;
471 dump_desc_dbg(ioat, desc);
Dan Williamscdef57d2009-09-21 09:22:29 -0700472 } while (++i < num_descs);
Dan Williamsbf40a682009-09-08 17:42:55 -0700473
474 desc->txd.flags = flags;
475 desc->len = total_len;
476 fill->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
477 fill->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
478 fill->ctl_f.compl_write = 1;
479 dump_desc_dbg(ioat, desc);
480
481 /* we leave the channel locked to ensure in order submission */
482 return &desc->txd;
483}
484
Dan Williamsb094ad32009-09-08 17:42:57 -0700485static struct dma_async_tx_descriptor *
486__ioat3_prep_xor_lock(struct dma_chan *c, enum sum_check_flags *result,
487 dma_addr_t dest, dma_addr_t *src, unsigned int src_cnt,
488 size_t len, unsigned long flags)
489{
490 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
491 struct ioat_ring_ent *compl_desc;
492 struct ioat_ring_ent *desc;
493 struct ioat_ring_ent *ext;
494 size_t total_len = len;
495 struct ioat_xor_descriptor *xor;
496 struct ioat_xor_ext_descriptor *xor_ex = NULL;
497 struct ioat_dma_descriptor *hw;
Dan Williams074cc472010-05-01 15:22:55 -0700498 int num_descs, with_ext, idx, i;
Dan Williamsb094ad32009-09-08 17:42:57 -0700499 u32 offset = 0;
Dan Williamsb094ad32009-09-08 17:42:57 -0700500 u8 op = result ? IOAT_OP_XOR_VAL : IOAT_OP_XOR;
501
502 BUG_ON(src_cnt < 2);
503
504 num_descs = ioat2_xferlen_to_descs(ioat, len);
505 /* we need 2x the number of descriptors to cover greater than 5
506 * sources
507 */
508 if (src_cnt > 5) {
509 with_ext = 1;
510 num_descs *= 2;
511 } else
512 with_ext = 0;
513
514 /* completion writes from the raid engine may pass completion
515 * writes from the legacy engine, so we need one extra null
516 * (legacy) descriptor to ensure all completion writes arrive in
517 * order.
518 */
Dan Williams074cc472010-05-01 15:22:55 -0700519 if (likely(num_descs) && ioat2_check_space_lock(ioat, num_descs+1) == 0)
520 idx = ioat->head;
Dan Williamsb094ad32009-09-08 17:42:57 -0700521 else
522 return NULL;
Dan Williamscdef57d2009-09-21 09:22:29 -0700523 i = 0;
524 do {
Dan Williamsb094ad32009-09-08 17:42:57 -0700525 struct ioat_raw_descriptor *descs[2];
526 size_t xfer_size = min_t(size_t, len, 1 << ioat->xfercap_log);
527 int s;
528
529 desc = ioat2_get_ring_ent(ioat, idx + i);
530 xor = desc->xor;
531
532 /* save a branch by unconditionally retrieving the
533 * extended descriptor xor_set_src() knows to not write
534 * to it in the single descriptor case
535 */
536 ext = ioat2_get_ring_ent(ioat, idx + i + 1);
537 xor_ex = ext->xor_ex;
538
539 descs[0] = (struct ioat_raw_descriptor *) xor;
540 descs[1] = (struct ioat_raw_descriptor *) xor_ex;
541 for (s = 0; s < src_cnt; s++)
542 xor_set_src(descs, src[s], offset, s);
543 xor->size = xfer_size;
544 xor->dst_addr = dest + offset;
545 xor->ctl = 0;
546 xor->ctl_f.op = op;
547 xor->ctl_f.src_cnt = src_cnt_to_hw(src_cnt);
548
549 len -= xfer_size;
550 offset += xfer_size;
551 dump_desc_dbg(ioat, desc);
Dan Williamscdef57d2009-09-21 09:22:29 -0700552 } while ((i += 1 + with_ext) < num_descs);
Dan Williamsb094ad32009-09-08 17:42:57 -0700553
554 /* last xor descriptor carries the unmap parameters and fence bit */
555 desc->txd.flags = flags;
556 desc->len = total_len;
557 if (result)
558 desc->result = result;
559 xor->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
560
561 /* completion descriptor carries interrupt bit */
562 compl_desc = ioat2_get_ring_ent(ioat, idx + i);
563 compl_desc->txd.flags = flags & DMA_PREP_INTERRUPT;
564 hw = compl_desc->hw;
565 hw->ctl = 0;
566 hw->ctl_f.null = 1;
567 hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
568 hw->ctl_f.compl_write = 1;
569 hw->size = NULL_DESC_BUFFER_SIZE;
570 dump_desc_dbg(ioat, compl_desc);
571
572 /* we leave the channel locked to ensure in order submission */
Dan Williams49954c12009-11-19 17:11:03 -0700573 return &compl_desc->txd;
Dan Williamsb094ad32009-09-08 17:42:57 -0700574}
575
576static struct dma_async_tx_descriptor *
577ioat3_prep_xor(struct dma_chan *chan, dma_addr_t dest, dma_addr_t *src,
578 unsigned int src_cnt, size_t len, unsigned long flags)
579{
580 return __ioat3_prep_xor_lock(chan, NULL, dest, src, src_cnt, len, flags);
581}
582
583struct dma_async_tx_descriptor *
584ioat3_prep_xor_val(struct dma_chan *chan, dma_addr_t *src,
585 unsigned int src_cnt, size_t len,
586 enum sum_check_flags *result, unsigned long flags)
587{
588 /* the cleanup routine only sets bits on validate failure, it
589 * does not clear bits on validate success... so clear it here
590 */
591 *result = 0;
592
593 return __ioat3_prep_xor_lock(chan, result, src[0], &src[1],
594 src_cnt - 1, len, flags);
595}
596
Dan Williamsd69d235b2009-09-08 17:42:59 -0700597static void
598dump_pq_desc_dbg(struct ioat2_dma_chan *ioat, struct ioat_ring_ent *desc, struct ioat_ring_ent *ext)
599{
600 struct device *dev = to_dev(&ioat->base);
601 struct ioat_pq_descriptor *pq = desc->pq;
602 struct ioat_pq_ext_descriptor *pq_ex = ext ? ext->pq_ex : NULL;
603 struct ioat_raw_descriptor *descs[] = { (void *) pq, (void *) pq_ex };
604 int src_cnt = src_cnt_to_sw(pq->ctl_f.src_cnt);
605 int i;
606
607 dev_dbg(dev, "desc[%d]: (%#llx->%#llx) flags: %#x"
Dave Jiang50f9f972013-03-04 10:59:54 -0700608 " sz: %#10.8x ctl: %#x (op: %#x int: %d compl: %d pq: '%s%s' src_cnt: %d)\n",
Dan Williamsd69d235b2009-09-08 17:42:59 -0700609 desc_id(desc), (unsigned long long) desc->txd.phys,
610 (unsigned long long) (pq_ex ? pq_ex->next : pq->next),
611 desc->txd.flags, pq->size, pq->ctl, pq->ctl_f.op, pq->ctl_f.int_en,
612 pq->ctl_f.compl_write,
613 pq->ctl_f.p_disable ? "" : "p", pq->ctl_f.q_disable ? "" : "q",
614 pq->ctl_f.src_cnt);
615 for (i = 0; i < src_cnt; i++)
616 dev_dbg(dev, "\tsrc[%d]: %#llx coef: %#x\n", i,
617 (unsigned long long) pq_get_src(descs, i), pq->coef[i]);
618 dev_dbg(dev, "\tP: %#llx\n", pq->p_addr);
619 dev_dbg(dev, "\tQ: %#llx\n", pq->q_addr);
Dave Jiang50f9f972013-03-04 10:59:54 -0700620 dev_dbg(dev, "\tNEXT: %#llx\n", pq->next);
Dan Williamsd69d235b2009-09-08 17:42:59 -0700621}
622
623static struct dma_async_tx_descriptor *
624__ioat3_prep_pq_lock(struct dma_chan *c, enum sum_check_flags *result,
625 const dma_addr_t *dst, const dma_addr_t *src,
626 unsigned int src_cnt, const unsigned char *scf,
627 size_t len, unsigned long flags)
628{
629 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
630 struct ioat_chan_common *chan = &ioat->base;
631 struct ioat_ring_ent *compl_desc;
632 struct ioat_ring_ent *desc;
633 struct ioat_ring_ent *ext;
634 size_t total_len = len;
635 struct ioat_pq_descriptor *pq;
636 struct ioat_pq_ext_descriptor *pq_ex = NULL;
637 struct ioat_dma_descriptor *hw;
638 u32 offset = 0;
Dan Williamsd69d235b2009-09-08 17:42:59 -0700639 u8 op = result ? IOAT_OP_PQ_VAL : IOAT_OP_PQ;
Dan Williams074cc472010-05-01 15:22:55 -0700640 int i, s, idx, with_ext, num_descs;
Dan Williamsd69d235b2009-09-08 17:42:59 -0700641
642 dev_dbg(to_dev(chan), "%s\n", __func__);
643 /* the engine requires at least two sources (we provide
644 * at least 1 implied source in the DMA_PREP_CONTINUE case)
645 */
646 BUG_ON(src_cnt + dmaf_continue(flags) < 2);
647
648 num_descs = ioat2_xferlen_to_descs(ioat, len);
649 /* we need 2x the number of descriptors to cover greater than 3
Dan Williamscd788092009-12-17 13:52:39 -0700650 * sources (we need 1 extra source in the q-only continuation
651 * case and 3 extra sources in the p+q continuation case.
Dan Williamsd69d235b2009-09-08 17:42:59 -0700652 */
Dan Williamscd788092009-12-17 13:52:39 -0700653 if (src_cnt + dmaf_p_disabled_continue(flags) > 3 ||
654 (dmaf_continue(flags) && !dmaf_p_disabled_continue(flags))) {
Dan Williamsd69d235b2009-09-08 17:42:59 -0700655 with_ext = 1;
656 num_descs *= 2;
657 } else
658 with_ext = 0;
659
660 /* completion writes from the raid engine may pass completion
661 * writes from the legacy engine, so we need one extra null
662 * (legacy) descriptor to ensure all completion writes arrive in
663 * order.
664 */
665 if (likely(num_descs) &&
Dan Williams074cc472010-05-01 15:22:55 -0700666 ioat2_check_space_lock(ioat, num_descs+1) == 0)
667 idx = ioat->head;
Dan Williamsd69d235b2009-09-08 17:42:59 -0700668 else
669 return NULL;
Dan Williamscdef57d2009-09-21 09:22:29 -0700670 i = 0;
671 do {
Dan Williamsd69d235b2009-09-08 17:42:59 -0700672 struct ioat_raw_descriptor *descs[2];
673 size_t xfer_size = min_t(size_t, len, 1 << ioat->xfercap_log);
674
675 desc = ioat2_get_ring_ent(ioat, idx + i);
676 pq = desc->pq;
677
678 /* save a branch by unconditionally retrieving the
679 * extended descriptor pq_set_src() knows to not write
680 * to it in the single descriptor case
681 */
682 ext = ioat2_get_ring_ent(ioat, idx + i + with_ext);
683 pq_ex = ext->pq_ex;
684
685 descs[0] = (struct ioat_raw_descriptor *) pq;
686 descs[1] = (struct ioat_raw_descriptor *) pq_ex;
687
688 for (s = 0; s < src_cnt; s++)
689 pq_set_src(descs, src[s], offset, scf[s], s);
690
691 /* see the comment for dma_maxpq in include/linux/dmaengine.h */
692 if (dmaf_p_disabled_continue(flags))
693 pq_set_src(descs, dst[1], offset, 1, s++);
694 else if (dmaf_continue(flags)) {
695 pq_set_src(descs, dst[0], offset, 0, s++);
696 pq_set_src(descs, dst[1], offset, 1, s++);
697 pq_set_src(descs, dst[1], offset, 0, s++);
698 }
699 pq->size = xfer_size;
700 pq->p_addr = dst[0] + offset;
701 pq->q_addr = dst[1] + offset;
702 pq->ctl = 0;
703 pq->ctl_f.op = op;
704 pq->ctl_f.src_cnt = src_cnt_to_hw(s);
705 pq->ctl_f.p_disable = !!(flags & DMA_PREP_PQ_DISABLE_P);
706 pq->ctl_f.q_disable = !!(flags & DMA_PREP_PQ_DISABLE_Q);
707
708 len -= xfer_size;
709 offset += xfer_size;
Dan Williamscdef57d2009-09-21 09:22:29 -0700710 } while ((i += 1 + with_ext) < num_descs);
Dan Williamsd69d235b2009-09-08 17:42:59 -0700711
712 /* last pq descriptor carries the unmap parameters and fence bit */
713 desc->txd.flags = flags;
714 desc->len = total_len;
715 if (result)
716 desc->result = result;
717 pq->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
718 dump_pq_desc_dbg(ioat, desc, ext);
719
720 /* completion descriptor carries interrupt bit */
721 compl_desc = ioat2_get_ring_ent(ioat, idx + i);
722 compl_desc->txd.flags = flags & DMA_PREP_INTERRUPT;
723 hw = compl_desc->hw;
724 hw->ctl = 0;
725 hw->ctl_f.null = 1;
726 hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
727 hw->ctl_f.compl_write = 1;
728 hw->size = NULL_DESC_BUFFER_SIZE;
729 dump_desc_dbg(ioat, compl_desc);
730
731 /* we leave the channel locked to ensure in order submission */
Dan Williams49954c12009-11-19 17:11:03 -0700732 return &compl_desc->txd;
Dan Williamsd69d235b2009-09-08 17:42:59 -0700733}
734
735static struct dma_async_tx_descriptor *
736ioat3_prep_pq(struct dma_chan *chan, dma_addr_t *dst, dma_addr_t *src,
737 unsigned int src_cnt, const unsigned char *scf, size_t len,
738 unsigned long flags)
739{
Dan Williamsde581b62009-11-19 17:08:45 -0700740 /* specify valid address for disabled result */
741 if (flags & DMA_PREP_PQ_DISABLE_P)
742 dst[0] = dst[1];
743 if (flags & DMA_PREP_PQ_DISABLE_Q)
744 dst[1] = dst[0];
745
Dan Williamsd69d235b2009-09-08 17:42:59 -0700746 /* handle the single source multiply case from the raid6
747 * recovery path
748 */
Dan Williamsde581b62009-11-19 17:08:45 -0700749 if ((flags & DMA_PREP_PQ_DISABLE_P) && src_cnt == 1) {
Dan Williamsd69d235b2009-09-08 17:42:59 -0700750 dma_addr_t single_source[2];
751 unsigned char single_source_coef[2];
752
753 BUG_ON(flags & DMA_PREP_PQ_DISABLE_Q);
754 single_source[0] = src[0];
755 single_source[1] = src[0];
756 single_source_coef[0] = scf[0];
757 single_source_coef[1] = 0;
758
759 return __ioat3_prep_pq_lock(chan, NULL, dst, single_source, 2,
760 single_source_coef, len, flags);
761 } else
762 return __ioat3_prep_pq_lock(chan, NULL, dst, src, src_cnt, scf,
763 len, flags);
764}
765
766struct dma_async_tx_descriptor *
767ioat3_prep_pq_val(struct dma_chan *chan, dma_addr_t *pq, dma_addr_t *src,
768 unsigned int src_cnt, const unsigned char *scf, size_t len,
769 enum sum_check_flags *pqres, unsigned long flags)
770{
Dan Williamsde581b62009-11-19 17:08:45 -0700771 /* specify valid address for disabled result */
772 if (flags & DMA_PREP_PQ_DISABLE_P)
773 pq[0] = pq[1];
774 if (flags & DMA_PREP_PQ_DISABLE_Q)
775 pq[1] = pq[0];
776
Dan Williamsd69d235b2009-09-08 17:42:59 -0700777 /* the cleanup routine only sets bits on validate failure, it
778 * does not clear bits on validate success... so clear it here
779 */
780 *pqres = 0;
781
782 return __ioat3_prep_pq_lock(chan, pqres, pq, src, src_cnt, scf, len,
783 flags);
784}
785
Dan Williamsae786622009-09-08 17:43:00 -0700786static struct dma_async_tx_descriptor *
787ioat3_prep_pqxor(struct dma_chan *chan, dma_addr_t dst, dma_addr_t *src,
788 unsigned int src_cnt, size_t len, unsigned long flags)
789{
790 unsigned char scf[src_cnt];
791 dma_addr_t pq[2];
792
793 memset(scf, 0, src_cnt);
Dan Williamsae786622009-09-08 17:43:00 -0700794 pq[0] = dst;
Dan Williamsde581b62009-11-19 17:08:45 -0700795 flags |= DMA_PREP_PQ_DISABLE_Q;
796 pq[1] = dst; /* specify valid address for disabled result */
Dan Williamsae786622009-09-08 17:43:00 -0700797
798 return __ioat3_prep_pq_lock(chan, NULL, pq, src, src_cnt, scf, len,
799 flags);
800}
801
802struct dma_async_tx_descriptor *
803ioat3_prep_pqxor_val(struct dma_chan *chan, dma_addr_t *src,
804 unsigned int src_cnt, size_t len,
805 enum sum_check_flags *result, unsigned long flags)
806{
807 unsigned char scf[src_cnt];
808 dma_addr_t pq[2];
809
810 /* the cleanup routine only sets bits on validate failure, it
811 * does not clear bits on validate success... so clear it here
812 */
813 *result = 0;
814
815 memset(scf, 0, src_cnt);
Dan Williamsae786622009-09-08 17:43:00 -0700816 pq[0] = src[0];
Dan Williamsde581b62009-11-19 17:08:45 -0700817 flags |= DMA_PREP_PQ_DISABLE_Q;
818 pq[1] = pq[0]; /* specify valid address for disabled result */
Dan Williamsae786622009-09-08 17:43:00 -0700819
820 return __ioat3_prep_pq_lock(chan, result, pq, &src[1], src_cnt - 1, scf,
821 len, flags);
822}
823
Dan Williams58c86492009-09-08 17:43:00 -0700824static struct dma_async_tx_descriptor *
825ioat3_prep_interrupt_lock(struct dma_chan *c, unsigned long flags)
826{
827 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
828 struct ioat_ring_ent *desc;
829 struct ioat_dma_descriptor *hw;
Dan Williams58c86492009-09-08 17:43:00 -0700830
Dan Williams074cc472010-05-01 15:22:55 -0700831 if (ioat2_check_space_lock(ioat, 1) == 0)
832 desc = ioat2_get_ring_ent(ioat, ioat->head);
Dan Williams58c86492009-09-08 17:43:00 -0700833 else
834 return NULL;
835
836 hw = desc->hw;
837 hw->ctl = 0;
838 hw->ctl_f.null = 1;
839 hw->ctl_f.int_en = 1;
840 hw->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
841 hw->ctl_f.compl_write = 1;
842 hw->size = NULL_DESC_BUFFER_SIZE;
843 hw->src_addr = 0;
844 hw->dst_addr = 0;
845
846 desc->txd.flags = flags;
847 desc->len = 1;
848
849 dump_desc_dbg(ioat, desc);
850
851 /* we leave the channel locked to ensure in order submission */
852 return &desc->txd;
853}
854
Greg Kroah-Hartman4bf27b82012-12-21 15:09:59 -0800855static void ioat3_dma_test_callback(void *dma_async_param)
Dan Williams9de6fc72009-09-08 17:42:58 -0700856{
857 struct completion *cmp = dma_async_param;
858
859 complete(cmp);
860}
861
862#define IOAT_NUM_SRC_TEST 6 /* must be <= 8 */
Greg Kroah-Hartman4bf27b82012-12-21 15:09:59 -0800863static int ioat_xor_val_self_test(struct ioatdma_device *device)
Dan Williams9de6fc72009-09-08 17:42:58 -0700864{
865 int i, src_idx;
866 struct page *dest;
867 struct page *xor_srcs[IOAT_NUM_SRC_TEST];
868 struct page *xor_val_srcs[IOAT_NUM_SRC_TEST + 1];
869 dma_addr_t dma_srcs[IOAT_NUM_SRC_TEST + 1];
870 dma_addr_t dma_addr, dest_dma;
871 struct dma_async_tx_descriptor *tx;
872 struct dma_chan *dma_chan;
873 dma_cookie_t cookie;
874 u8 cmp_byte = 0;
875 u32 cmp_word;
876 u32 xor_val_result;
877 int err = 0;
878 struct completion cmp;
879 unsigned long tmo;
880 struct device *dev = &device->pdev->dev;
881 struct dma_device *dma = &device->common;
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +0000882 u8 op = 0;
Dan Williams9de6fc72009-09-08 17:42:58 -0700883
884 dev_dbg(dev, "%s\n", __func__);
885
886 if (!dma_has_cap(DMA_XOR, dma->cap_mask))
887 return 0;
888
889 for (src_idx = 0; src_idx < IOAT_NUM_SRC_TEST; src_idx++) {
890 xor_srcs[src_idx] = alloc_page(GFP_KERNEL);
891 if (!xor_srcs[src_idx]) {
892 while (src_idx--)
893 __free_page(xor_srcs[src_idx]);
894 return -ENOMEM;
895 }
896 }
897
898 dest = alloc_page(GFP_KERNEL);
899 if (!dest) {
900 while (src_idx--)
901 __free_page(xor_srcs[src_idx]);
902 return -ENOMEM;
903 }
904
905 /* Fill in src buffers */
906 for (src_idx = 0; src_idx < IOAT_NUM_SRC_TEST; src_idx++) {
907 u8 *ptr = page_address(xor_srcs[src_idx]);
908 for (i = 0; i < PAGE_SIZE; i++)
909 ptr[i] = (1 << src_idx);
910 }
911
912 for (src_idx = 0; src_idx < IOAT_NUM_SRC_TEST; src_idx++)
913 cmp_byte ^= (u8) (1 << src_idx);
914
915 cmp_word = (cmp_byte << 24) | (cmp_byte << 16) |
916 (cmp_byte << 8) | cmp_byte;
917
918 memset(page_address(dest), 0, PAGE_SIZE);
919
920 dma_chan = container_of(dma->channels.next, struct dma_chan,
921 device_node);
922 if (dma->device_alloc_chan_resources(dma_chan) < 1) {
923 err = -ENODEV;
924 goto out;
925 }
926
927 /* test xor */
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +0000928 op = IOAT_OP_XOR;
929
Dan Williams9de6fc72009-09-08 17:42:58 -0700930 dest_dma = dma_map_page(dev, dest, 0, PAGE_SIZE, DMA_FROM_DEVICE);
931 for (i = 0; i < IOAT_NUM_SRC_TEST; i++)
932 dma_srcs[i] = dma_map_page(dev, xor_srcs[i], 0, PAGE_SIZE,
933 DMA_TO_DEVICE);
934 tx = dma->device_prep_dma_xor(dma_chan, dest_dma, dma_srcs,
935 IOAT_NUM_SRC_TEST, PAGE_SIZE,
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +0000936 DMA_PREP_INTERRUPT |
937 DMA_COMPL_SKIP_SRC_UNMAP |
938 DMA_COMPL_SKIP_DEST_UNMAP);
Dan Williams9de6fc72009-09-08 17:42:58 -0700939
940 if (!tx) {
941 dev_err(dev, "Self-test xor prep failed\n");
942 err = -ENODEV;
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +0000943 goto dma_unmap;
Dan Williams9de6fc72009-09-08 17:42:58 -0700944 }
945
946 async_tx_ack(tx);
947 init_completion(&cmp);
948 tx->callback = ioat3_dma_test_callback;
949 tx->callback_param = &cmp;
950 cookie = tx->tx_submit(tx);
951 if (cookie < 0) {
952 dev_err(dev, "Self-test xor setup failed\n");
953 err = -ENODEV;
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +0000954 goto dma_unmap;
Dan Williams9de6fc72009-09-08 17:42:58 -0700955 }
956 dma->device_issue_pending(dma_chan);
957
958 tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
959
Linus Walleij07934482010-03-26 16:50:49 -0700960 if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
Dan Williams9de6fc72009-09-08 17:42:58 -0700961 dev_err(dev, "Self-test xor timed out\n");
962 err = -ENODEV;
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +0000963 goto dma_unmap;
Dan Williams9de6fc72009-09-08 17:42:58 -0700964 }
965
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +0000966 dma_unmap_page(dev, dest_dma, PAGE_SIZE, DMA_FROM_DEVICE);
967 for (i = 0; i < IOAT_NUM_SRC_TEST; i++)
968 dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE, DMA_TO_DEVICE);
969
Dan Williams9de6fc72009-09-08 17:42:58 -0700970 dma_sync_single_for_cpu(dev, dest_dma, PAGE_SIZE, DMA_FROM_DEVICE);
971 for (i = 0; i < (PAGE_SIZE / sizeof(u32)); i++) {
972 u32 *ptr = page_address(dest);
973 if (ptr[i] != cmp_word) {
974 dev_err(dev, "Self-test xor failed compare\n");
975 err = -ENODEV;
976 goto free_resources;
977 }
978 }
Shuah Khanac498982012-10-25 10:22:32 -0600979 dma_sync_single_for_device(dev, dest_dma, PAGE_SIZE, DMA_FROM_DEVICE);
Dan Williams9de6fc72009-09-08 17:42:58 -0700980
981 /* skip validate if the capability is not present */
982 if (!dma_has_cap(DMA_XOR_VAL, dma_chan->device->cap_mask))
983 goto free_resources;
984
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +0000985 op = IOAT_OP_XOR_VAL;
986
Dan Williams9de6fc72009-09-08 17:42:58 -0700987 /* validate the sources with the destintation page */
988 for (i = 0; i < IOAT_NUM_SRC_TEST; i++)
989 xor_val_srcs[i] = xor_srcs[i];
990 xor_val_srcs[i] = dest;
991
992 xor_val_result = 1;
993
994 for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
995 dma_srcs[i] = dma_map_page(dev, xor_val_srcs[i], 0, PAGE_SIZE,
996 DMA_TO_DEVICE);
997 tx = dma->device_prep_dma_xor_val(dma_chan, dma_srcs,
998 IOAT_NUM_SRC_TEST + 1, PAGE_SIZE,
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +0000999 &xor_val_result, DMA_PREP_INTERRUPT |
1000 DMA_COMPL_SKIP_SRC_UNMAP |
1001 DMA_COMPL_SKIP_DEST_UNMAP);
Dan Williams9de6fc72009-09-08 17:42:58 -07001002 if (!tx) {
1003 dev_err(dev, "Self-test zero prep failed\n");
1004 err = -ENODEV;
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +00001005 goto dma_unmap;
Dan Williams9de6fc72009-09-08 17:42:58 -07001006 }
1007
1008 async_tx_ack(tx);
1009 init_completion(&cmp);
1010 tx->callback = ioat3_dma_test_callback;
1011 tx->callback_param = &cmp;
1012 cookie = tx->tx_submit(tx);
1013 if (cookie < 0) {
1014 dev_err(dev, "Self-test zero setup failed\n");
1015 err = -ENODEV;
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +00001016 goto dma_unmap;
Dan Williams9de6fc72009-09-08 17:42:58 -07001017 }
1018 dma->device_issue_pending(dma_chan);
1019
1020 tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
1021
Linus Walleij07934482010-03-26 16:50:49 -07001022 if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
Dan Williams9de6fc72009-09-08 17:42:58 -07001023 dev_err(dev, "Self-test validate timed out\n");
1024 err = -ENODEV;
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +00001025 goto dma_unmap;
Dan Williams9de6fc72009-09-08 17:42:58 -07001026 }
1027
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +00001028 for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
1029 dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE, DMA_TO_DEVICE);
1030
Dan Williams9de6fc72009-09-08 17:42:58 -07001031 if (xor_val_result != 0) {
1032 dev_err(dev, "Self-test validate failed compare\n");
1033 err = -ENODEV;
1034 goto free_resources;
1035 }
1036
1037 /* skip memset if the capability is not present */
1038 if (!dma_has_cap(DMA_MEMSET, dma_chan->device->cap_mask))
1039 goto free_resources;
1040
1041 /* test memset */
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +00001042 op = IOAT_OP_FILL;
1043
Dan Williams9de6fc72009-09-08 17:42:58 -07001044 dma_addr = dma_map_page(dev, dest, 0,
1045 PAGE_SIZE, DMA_FROM_DEVICE);
1046 tx = dma->device_prep_dma_memset(dma_chan, dma_addr, 0, PAGE_SIZE,
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +00001047 DMA_PREP_INTERRUPT |
1048 DMA_COMPL_SKIP_SRC_UNMAP |
1049 DMA_COMPL_SKIP_DEST_UNMAP);
Dan Williams9de6fc72009-09-08 17:42:58 -07001050 if (!tx) {
1051 dev_err(dev, "Self-test memset prep failed\n");
1052 err = -ENODEV;
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +00001053 goto dma_unmap;
Dan Williams9de6fc72009-09-08 17:42:58 -07001054 }
1055
1056 async_tx_ack(tx);
1057 init_completion(&cmp);
1058 tx->callback = ioat3_dma_test_callback;
1059 tx->callback_param = &cmp;
1060 cookie = tx->tx_submit(tx);
1061 if (cookie < 0) {
1062 dev_err(dev, "Self-test memset setup failed\n");
1063 err = -ENODEV;
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +00001064 goto dma_unmap;
Dan Williams9de6fc72009-09-08 17:42:58 -07001065 }
1066 dma->device_issue_pending(dma_chan);
1067
1068 tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
1069
Linus Walleij07934482010-03-26 16:50:49 -07001070 if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
Dan Williams9de6fc72009-09-08 17:42:58 -07001071 dev_err(dev, "Self-test memset timed out\n");
1072 err = -ENODEV;
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +00001073 goto dma_unmap;
Dan Williams9de6fc72009-09-08 17:42:58 -07001074 }
1075
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +00001076 dma_unmap_page(dev, dma_addr, PAGE_SIZE, DMA_FROM_DEVICE);
1077
Dan Williams9de6fc72009-09-08 17:42:58 -07001078 for (i = 0; i < PAGE_SIZE/sizeof(u32); i++) {
1079 u32 *ptr = page_address(dest);
1080 if (ptr[i]) {
1081 dev_err(dev, "Self-test memset failed compare\n");
1082 err = -ENODEV;
1083 goto free_resources;
1084 }
1085 }
1086
1087 /* test for non-zero parity sum */
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +00001088 op = IOAT_OP_XOR_VAL;
1089
Dan Williams9de6fc72009-09-08 17:42:58 -07001090 xor_val_result = 0;
1091 for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
1092 dma_srcs[i] = dma_map_page(dev, xor_val_srcs[i], 0, PAGE_SIZE,
1093 DMA_TO_DEVICE);
1094 tx = dma->device_prep_dma_xor_val(dma_chan, dma_srcs,
1095 IOAT_NUM_SRC_TEST + 1, PAGE_SIZE,
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +00001096 &xor_val_result, DMA_PREP_INTERRUPT |
1097 DMA_COMPL_SKIP_SRC_UNMAP |
1098 DMA_COMPL_SKIP_DEST_UNMAP);
Dan Williams9de6fc72009-09-08 17:42:58 -07001099 if (!tx) {
1100 dev_err(dev, "Self-test 2nd zero prep failed\n");
1101 err = -ENODEV;
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +00001102 goto dma_unmap;
Dan Williams9de6fc72009-09-08 17:42:58 -07001103 }
1104
1105 async_tx_ack(tx);
1106 init_completion(&cmp);
1107 tx->callback = ioat3_dma_test_callback;
1108 tx->callback_param = &cmp;
1109 cookie = tx->tx_submit(tx);
1110 if (cookie < 0) {
1111 dev_err(dev, "Self-test 2nd zero setup failed\n");
1112 err = -ENODEV;
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +00001113 goto dma_unmap;
Dan Williams9de6fc72009-09-08 17:42:58 -07001114 }
1115 dma->device_issue_pending(dma_chan);
1116
1117 tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
1118
Linus Walleij07934482010-03-26 16:50:49 -07001119 if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
Dan Williams9de6fc72009-09-08 17:42:58 -07001120 dev_err(dev, "Self-test 2nd validate timed out\n");
1121 err = -ENODEV;
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +00001122 goto dma_unmap;
Dan Williams9de6fc72009-09-08 17:42:58 -07001123 }
1124
1125 if (xor_val_result != SUM_CHECK_P_RESULT) {
1126 dev_err(dev, "Self-test validate failed compare\n");
1127 err = -ENODEV;
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +00001128 goto dma_unmap;
Dan Williams9de6fc72009-09-08 17:42:58 -07001129 }
1130
Bartlomiej Zolnierkiewicz7369f562012-11-05 10:00:19 +00001131 for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
1132 dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE, DMA_TO_DEVICE);
1133
1134 goto free_resources;
1135dma_unmap:
1136 if (op == IOAT_OP_XOR) {
1137 dma_unmap_page(dev, dest_dma, PAGE_SIZE, DMA_FROM_DEVICE);
1138 for (i = 0; i < IOAT_NUM_SRC_TEST; i++)
1139 dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE,
1140 DMA_TO_DEVICE);
1141 } else if (op == IOAT_OP_XOR_VAL) {
1142 for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
1143 dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE,
1144 DMA_TO_DEVICE);
1145 } else if (op == IOAT_OP_FILL)
1146 dma_unmap_page(dev, dma_addr, PAGE_SIZE, DMA_FROM_DEVICE);
Dan Williams9de6fc72009-09-08 17:42:58 -07001147free_resources:
1148 dma->device_free_chan_resources(dma_chan);
1149out:
1150 src_idx = IOAT_NUM_SRC_TEST;
1151 while (src_idx--)
1152 __free_page(xor_srcs[src_idx]);
1153 __free_page(dest);
1154 return err;
1155}
1156
Greg Kroah-Hartman4bf27b82012-12-21 15:09:59 -08001157static int ioat3_dma_self_test(struct ioatdma_device *device)
Dan Williams9de6fc72009-09-08 17:42:58 -07001158{
1159 int rc = ioat_dma_self_test(device);
1160
1161 if (rc)
1162 return rc;
1163
1164 rc = ioat_xor_val_self_test(device);
1165 if (rc)
1166 return rc;
1167
1168 return 0;
1169}
1170
Dan Williamsa6d52d72009-12-19 15:36:02 -07001171static int ioat3_reset_hw(struct ioat_chan_common *chan)
1172{
1173 /* throw away whatever the channel was doing and get it
1174 * initialized, with ioat3 specific workarounds
1175 */
1176 struct ioatdma_device *device = chan->device;
1177 struct pci_dev *pdev = device->pdev;
1178 u32 chanerr;
1179 u16 dev_id;
1180 int err;
1181
1182 ioat2_quiesce(chan, msecs_to_jiffies(100));
1183
1184 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
1185 writel(chanerr, chan->reg_base + IOAT_CHANERR_OFFSET);
1186
Dave Jiang6decffd2012-11-27 15:16:08 -07001187 /* clear any pending errors */
Dan Williamsa6d52d72009-12-19 15:36:02 -07001188 err = pci_read_config_dword(pdev, IOAT_PCI_CHANERR_INT_OFFSET, &chanerr);
1189 if (err) {
1190 dev_err(&pdev->dev, "channel error register unreachable\n");
1191 return err;
1192 }
1193 pci_write_config_dword(pdev, IOAT_PCI_CHANERR_INT_OFFSET, chanerr);
1194
1195 /* Clear DMAUNCERRSTS Cfg-Reg Parity Error status bit
1196 * (workaround for spurious config parity error after restart)
1197 */
1198 pci_read_config_word(pdev, IOAT_PCI_DEVICE_ID_OFFSET, &dev_id);
1199 if (dev_id == PCI_DEVICE_ID_INTEL_IOAT_TBG0)
1200 pci_write_config_dword(pdev, IOAT_PCI_DMAUNCERRSTS_OFFSET, 0x10);
1201
1202 return ioat2_reset_sync(chan, msecs_to_jiffies(200));
1203}
1204
Dave Jiangf26df1a2012-04-04 16:10:41 -07001205static bool is_jf_ioat(struct pci_dev *pdev)
1206{
1207 switch (pdev->device) {
1208 case PCI_DEVICE_ID_INTEL_IOAT_JSF0:
1209 case PCI_DEVICE_ID_INTEL_IOAT_JSF1:
1210 case PCI_DEVICE_ID_INTEL_IOAT_JSF2:
1211 case PCI_DEVICE_ID_INTEL_IOAT_JSF3:
1212 case PCI_DEVICE_ID_INTEL_IOAT_JSF4:
1213 case PCI_DEVICE_ID_INTEL_IOAT_JSF5:
1214 case PCI_DEVICE_ID_INTEL_IOAT_JSF6:
1215 case PCI_DEVICE_ID_INTEL_IOAT_JSF7:
1216 case PCI_DEVICE_ID_INTEL_IOAT_JSF8:
1217 case PCI_DEVICE_ID_INTEL_IOAT_JSF9:
1218 return true;
1219 default:
1220 return false;
1221 }
1222}
1223
1224static bool is_snb_ioat(struct pci_dev *pdev)
1225{
1226 switch (pdev->device) {
1227 case PCI_DEVICE_ID_INTEL_IOAT_SNB0:
1228 case PCI_DEVICE_ID_INTEL_IOAT_SNB1:
1229 case PCI_DEVICE_ID_INTEL_IOAT_SNB2:
1230 case PCI_DEVICE_ID_INTEL_IOAT_SNB3:
1231 case PCI_DEVICE_ID_INTEL_IOAT_SNB4:
1232 case PCI_DEVICE_ID_INTEL_IOAT_SNB5:
1233 case PCI_DEVICE_ID_INTEL_IOAT_SNB6:
1234 case PCI_DEVICE_ID_INTEL_IOAT_SNB7:
1235 case PCI_DEVICE_ID_INTEL_IOAT_SNB8:
1236 case PCI_DEVICE_ID_INTEL_IOAT_SNB9:
1237 return true;
1238 default:
1239 return false;
1240 }
1241}
1242
Dave Jiang1a363062012-12-03 16:08:37 -07001243static bool is_ivb_ioat(struct pci_dev *pdev)
1244{
1245 switch (pdev->device) {
1246 case PCI_DEVICE_ID_INTEL_IOAT_IVB0:
1247 case PCI_DEVICE_ID_INTEL_IOAT_IVB1:
1248 case PCI_DEVICE_ID_INTEL_IOAT_IVB2:
1249 case PCI_DEVICE_ID_INTEL_IOAT_IVB3:
1250 case PCI_DEVICE_ID_INTEL_IOAT_IVB4:
1251 case PCI_DEVICE_ID_INTEL_IOAT_IVB5:
1252 case PCI_DEVICE_ID_INTEL_IOAT_IVB6:
1253 case PCI_DEVICE_ID_INTEL_IOAT_IVB7:
1254 case PCI_DEVICE_ID_INTEL_IOAT_IVB8:
1255 case PCI_DEVICE_ID_INTEL_IOAT_IVB9:
1256 return true;
1257 default:
1258 return false;
1259 }
1260
1261}
1262
Dave Jiang570727b2013-03-25 14:37:31 -07001263static bool is_hsw_ioat(struct pci_dev *pdev)
1264{
1265 switch (pdev->device) {
1266 case PCI_DEVICE_ID_INTEL_IOAT_HSW0:
1267 case PCI_DEVICE_ID_INTEL_IOAT_HSW1:
1268 case PCI_DEVICE_ID_INTEL_IOAT_HSW2:
1269 case PCI_DEVICE_ID_INTEL_IOAT_HSW3:
1270 case PCI_DEVICE_ID_INTEL_IOAT_HSW4:
1271 case PCI_DEVICE_ID_INTEL_IOAT_HSW5:
1272 case PCI_DEVICE_ID_INTEL_IOAT_HSW6:
1273 case PCI_DEVICE_ID_INTEL_IOAT_HSW7:
1274 case PCI_DEVICE_ID_INTEL_IOAT_HSW8:
1275 case PCI_DEVICE_ID_INTEL_IOAT_HSW9:
1276 return true;
1277 default:
1278 return false;
1279 }
1280
1281}
1282
1283static bool is_xeon_cb32(struct pci_dev *pdev)
1284{
1285 return is_jf_ioat(pdev) || is_snb_ioat(pdev) || is_ivb_ioat(pdev) ||
1286 is_hsw_ioat(pdev);
1287}
1288
Greg Kroah-Hartman4bf27b82012-12-21 15:09:59 -08001289int ioat3_dma_probe(struct ioatdma_device *device, int dca)
Dan Williamsbf40a682009-09-08 17:42:55 -07001290{
1291 struct pci_dev *pdev = device->pdev;
Dan Williams228c4f52009-11-19 17:07:10 -07001292 int dca_en = system_has_dca_enabled(pdev);
Dan Williamsbf40a682009-09-08 17:42:55 -07001293 struct dma_device *dma;
1294 struct dma_chan *c;
1295 struct ioat_chan_common *chan;
Dan Williamse3232712009-09-08 17:43:02 -07001296 bool is_raid_device = false;
Dan Williamsbf40a682009-09-08 17:42:55 -07001297 int err;
Dan Williamsbf40a682009-09-08 17:42:55 -07001298 u32 cap;
1299
1300 device->enumerate_channels = ioat2_enumerate_channels;
Dan Williamsa6d52d72009-12-19 15:36:02 -07001301 device->reset_hw = ioat3_reset_hw;
Dan Williams9de6fc72009-09-08 17:42:58 -07001302 device->self_test = ioat3_dma_self_test;
Dan Williamsbf40a682009-09-08 17:42:55 -07001303 dma = &device->common;
1304 dma->device_prep_dma_memcpy = ioat2_dma_prep_memcpy_lock;
1305 dma->device_issue_pending = ioat2_issue_pending;
1306 dma->device_alloc_chan_resources = ioat2_alloc_chan_resources;
1307 dma->device_free_chan_resources = ioat2_free_chan_resources;
Dan Williams58c86492009-09-08 17:43:00 -07001308
Dave Jiang570727b2013-03-25 14:37:31 -07001309 if (is_xeon_cb32(pdev))
Dave Jiangf26df1a2012-04-04 16:10:41 -07001310 dma->copy_align = 6;
1311
Dan Williams58c86492009-09-08 17:43:00 -07001312 dma_cap_set(DMA_INTERRUPT, dma->cap_mask);
1313 dma->device_prep_dma_interrupt = ioat3_prep_interrupt_lock;
1314
Dan Williamsbf40a682009-09-08 17:42:55 -07001315 cap = readl(device->reg_base + IOAT_DMA_CAP_OFFSET);
Dan Williams228c4f52009-11-19 17:07:10 -07001316
1317 /* dca is incompatible with raid operations */
1318 if (dca_en && (cap & (IOAT_CAP_XOR|IOAT_CAP_PQ)))
1319 cap &= ~(IOAT_CAP_XOR|IOAT_CAP_PQ);
1320
Dan Williamsb094ad32009-09-08 17:42:57 -07001321 if (cap & IOAT_CAP_XOR) {
Dan Williamse3232712009-09-08 17:43:02 -07001322 is_raid_device = true;
Dan Williamsb094ad32009-09-08 17:42:57 -07001323 dma->max_xor = 8;
Dan Williams2adfc552010-05-01 15:22:56 -07001324 dma->xor_align = 6;
Dan Williamsb094ad32009-09-08 17:42:57 -07001325
1326 dma_cap_set(DMA_XOR, dma->cap_mask);
1327 dma->device_prep_dma_xor = ioat3_prep_xor;
1328
1329 dma_cap_set(DMA_XOR_VAL, dma->cap_mask);
1330 dma->device_prep_dma_xor_val = ioat3_prep_xor_val;
1331 }
Dan Williamsd69d235b2009-09-08 17:42:59 -07001332 if (cap & IOAT_CAP_PQ) {
Dan Williamse3232712009-09-08 17:43:02 -07001333 is_raid_device = true;
Dan Williamsd69d235b2009-09-08 17:42:59 -07001334 dma_set_maxpq(dma, 8, 0);
Dan Williams2adfc552010-05-01 15:22:56 -07001335 dma->pq_align = 6;
Dan Williamsd69d235b2009-09-08 17:42:59 -07001336
1337 dma_cap_set(DMA_PQ, dma->cap_mask);
1338 dma->device_prep_dma_pq = ioat3_prep_pq;
1339
1340 dma_cap_set(DMA_PQ_VAL, dma->cap_mask);
1341 dma->device_prep_dma_pq_val = ioat3_prep_pq_val;
Dan Williamsae786622009-09-08 17:43:00 -07001342
1343 if (!(cap & IOAT_CAP_XOR)) {
1344 dma->max_xor = 8;
Dan Williams2adfc552010-05-01 15:22:56 -07001345 dma->xor_align = 6;
Dan Williamsae786622009-09-08 17:43:00 -07001346
1347 dma_cap_set(DMA_XOR, dma->cap_mask);
1348 dma->device_prep_dma_xor = ioat3_prep_pqxor;
1349
1350 dma_cap_set(DMA_XOR_VAL, dma->cap_mask);
1351 dma->device_prep_dma_xor_val = ioat3_prep_pqxor_val;
1352 }
Dan Williamsd69d235b2009-09-08 17:42:59 -07001353 }
Dan Williamse3232712009-09-08 17:43:02 -07001354 if (is_raid_device && (cap & IOAT_CAP_FILL_BLOCK)) {
1355 dma_cap_set(DMA_MEMSET, dma->cap_mask);
1356 dma->device_prep_dma_memset = ioat3_prep_memset_lock;
1357 }
1358
1359
Dave Jiang9a37f642013-02-26 09:20:36 -07001360 dma->device_tx_status = ioat3_tx_status;
1361 device->cleanup_fn = ioat3_cleanup_event;
1362 device->timer_fn = ioat3_timer_event;
Dan Williamsbf40a682009-09-08 17:42:55 -07001363
Dan Williams7b3cc2b2009-11-19 17:10:37 -07001364 #ifdef CONFIG_ASYNC_TX_DISABLE_PQ_VAL_DMA
1365 dma_cap_clear(DMA_PQ_VAL, dma->cap_mask);
1366 dma->device_prep_dma_pq_val = NULL;
1367 #endif
1368
1369 #ifdef CONFIG_ASYNC_TX_DISABLE_XOR_VAL_DMA
1370 dma_cap_clear(DMA_XOR_VAL, dma->cap_mask);
1371 dma->device_prep_dma_xor_val = NULL;
1372 #endif
1373
Dan Williamsbf40a682009-09-08 17:42:55 -07001374 err = ioat_probe(device);
1375 if (err)
1376 return err;
1377 ioat_set_tcp_copy_break(262144);
1378
1379 list_for_each_entry(c, &dma->channels, device_node) {
1380 chan = to_chan_common(c);
1381 writel(IOAT_DMA_DCA_ANY_CPU,
1382 chan->reg_base + IOAT_DCACTRL_OFFSET);
1383 }
1384
1385 err = ioat_register(device);
1386 if (err)
1387 return err;
Dan Williams5669e312009-09-08 17:42:56 -07001388
1389 ioat_kobject_add(device, &ioat2_ktype);
1390
Dan Williamsbf40a682009-09-08 17:42:55 -07001391 if (dca)
1392 device->dca = ioat3_dca_init(pdev, device->reg_base);
1393
1394 return 0;
1395}