Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 58 | #include <linux/module.h> |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 59 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 60 | #include <linux/gfp.h> |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 61 | #include <linux/dmaengine.h> |
| 62 | #include <linux/dma-mapping.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 63 | #include <linux/prefetch.h> |
Vinod Koul | 949ff5b | 2012-03-13 11:58:12 +0530 | [diff] [blame] | 64 | #include "../dmaengine.h" |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 65 | #include "registers.h" |
| 66 | #include "hw.h" |
| 67 | #include "dma.h" |
| 68 | #include "dma_v2.h" |
| 69 | |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 70 | /* 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) |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 73 | #define ndest_to_sw(x) ((x) + 1) |
| 74 | #define ndest_to_hw(x) ((x) - 1) |
| 75 | #define src16_cnt_to_sw(x) ((x) + 9) |
| 76 | #define src16_cnt_to_hw(x) ((x) - 9) |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 77 | |
| 78 | /* provide a lookup table for setting the source address in the base or |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 79 | * extended descriptor of an xor or pq descriptor |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 80 | */ |
Dan Williams | d0b0c8c | 2011-07-22 14:20:46 -0700 | [diff] [blame] | 81 | static const u8 xor_idx_to_desc = 0xe0; |
Andi Kleen | 9b487ce | 2011-06-07 15:26:33 -0700 | [diff] [blame] | 82 | static const u8 xor_idx_to_field[] = { 1, 4, 5, 6, 7, 0, 1, 2 }; |
| 83 | static const u8 pq_idx_to_desc = 0xf8; |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 84 | static const u8 pq16_idx_to_desc[] = { 0, 0, 1, 1, 1, 1, 1, 1, 1, |
| 85 | 2, 2, 2, 2, 2, 2, 2 }; |
Andi Kleen | 9b487ce | 2011-06-07 15:26:33 -0700 | [diff] [blame] | 86 | static const u8 pq_idx_to_field[] = { 1, 4, 5, 0, 1, 2, 4, 5 }; |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 87 | static const u8 pq16_idx_to_field[] = { 1, 4, 1, 2, 3, 4, 5, 6, 7, |
| 88 | 0, 1, 2, 3, 4, 5, 6 }; |
| 89 | |
| 90 | /* |
| 91 | * technically sources 1 and 2 do not require SED, but the op will have |
| 92 | * at least 9 descriptors so that's irrelevant. |
| 93 | */ |
| 94 | static const u8 pq16_idx_to_sed[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 95 | 1, 1, 1, 1, 1, 1, 1 }; |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 96 | |
Dave Jiang | 3f09ede | 2013-03-26 15:43:09 -0700 | [diff] [blame] | 97 | static void ioat3_eh(struct ioat2_dma_chan *ioat); |
| 98 | |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 99 | static dma_addr_t xor_get_src(struct ioat_raw_descriptor *descs[2], int idx) |
| 100 | { |
| 101 | struct ioat_raw_descriptor *raw = descs[xor_idx_to_desc >> idx & 1]; |
| 102 | |
| 103 | return raw->field[xor_idx_to_field[idx]]; |
| 104 | } |
| 105 | |
| 106 | static void xor_set_src(struct ioat_raw_descriptor *descs[2], |
| 107 | dma_addr_t addr, u32 offset, int idx) |
| 108 | { |
| 109 | struct ioat_raw_descriptor *raw = descs[xor_idx_to_desc >> idx & 1]; |
| 110 | |
| 111 | raw->field[xor_idx_to_field[idx]] = addr + offset; |
| 112 | } |
| 113 | |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 114 | static dma_addr_t pq_get_src(struct ioat_raw_descriptor *descs[2], int idx) |
| 115 | { |
| 116 | struct ioat_raw_descriptor *raw = descs[pq_idx_to_desc >> idx & 1]; |
| 117 | |
| 118 | return raw->field[pq_idx_to_field[idx]]; |
| 119 | } |
| 120 | |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 121 | static dma_addr_t pq16_get_src(struct ioat_raw_descriptor *desc[3], int idx) |
| 122 | { |
| 123 | struct ioat_raw_descriptor *raw = desc[pq16_idx_to_desc[idx]]; |
| 124 | |
| 125 | return raw->field[pq16_idx_to_field[idx]]; |
| 126 | } |
| 127 | |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 128 | static void pq_set_src(struct ioat_raw_descriptor *descs[2], |
| 129 | dma_addr_t addr, u32 offset, u8 coef, int idx) |
| 130 | { |
| 131 | struct ioat_pq_descriptor *pq = (struct ioat_pq_descriptor *) descs[0]; |
| 132 | struct ioat_raw_descriptor *raw = descs[pq_idx_to_desc >> idx & 1]; |
| 133 | |
| 134 | raw->field[pq_idx_to_field[idx]] = addr + offset; |
| 135 | pq->coef[idx] = coef; |
| 136 | } |
| 137 | |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 138 | static int sed_get_pq16_pool_idx(int src_cnt) |
| 139 | { |
| 140 | |
| 141 | return pq16_idx_to_sed[src_cnt]; |
| 142 | } |
| 143 | |
Dave Jiang | 8a52b9f | 2013-03-26 15:42:47 -0700 | [diff] [blame] | 144 | static bool is_jf_ioat(struct pci_dev *pdev) |
| 145 | { |
| 146 | switch (pdev->device) { |
| 147 | case PCI_DEVICE_ID_INTEL_IOAT_JSF0: |
| 148 | case PCI_DEVICE_ID_INTEL_IOAT_JSF1: |
| 149 | case PCI_DEVICE_ID_INTEL_IOAT_JSF2: |
| 150 | case PCI_DEVICE_ID_INTEL_IOAT_JSF3: |
| 151 | case PCI_DEVICE_ID_INTEL_IOAT_JSF4: |
| 152 | case PCI_DEVICE_ID_INTEL_IOAT_JSF5: |
| 153 | case PCI_DEVICE_ID_INTEL_IOAT_JSF6: |
| 154 | case PCI_DEVICE_ID_INTEL_IOAT_JSF7: |
| 155 | case PCI_DEVICE_ID_INTEL_IOAT_JSF8: |
| 156 | case PCI_DEVICE_ID_INTEL_IOAT_JSF9: |
| 157 | return true; |
| 158 | default: |
| 159 | return false; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | static bool is_snb_ioat(struct pci_dev *pdev) |
| 164 | { |
| 165 | switch (pdev->device) { |
| 166 | case PCI_DEVICE_ID_INTEL_IOAT_SNB0: |
| 167 | case PCI_DEVICE_ID_INTEL_IOAT_SNB1: |
| 168 | case PCI_DEVICE_ID_INTEL_IOAT_SNB2: |
| 169 | case PCI_DEVICE_ID_INTEL_IOAT_SNB3: |
| 170 | case PCI_DEVICE_ID_INTEL_IOAT_SNB4: |
| 171 | case PCI_DEVICE_ID_INTEL_IOAT_SNB5: |
| 172 | case PCI_DEVICE_ID_INTEL_IOAT_SNB6: |
| 173 | case PCI_DEVICE_ID_INTEL_IOAT_SNB7: |
| 174 | case PCI_DEVICE_ID_INTEL_IOAT_SNB8: |
| 175 | case PCI_DEVICE_ID_INTEL_IOAT_SNB9: |
| 176 | return true; |
| 177 | default: |
| 178 | return false; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | static bool is_ivb_ioat(struct pci_dev *pdev) |
| 183 | { |
| 184 | switch (pdev->device) { |
| 185 | case PCI_DEVICE_ID_INTEL_IOAT_IVB0: |
| 186 | case PCI_DEVICE_ID_INTEL_IOAT_IVB1: |
| 187 | case PCI_DEVICE_ID_INTEL_IOAT_IVB2: |
| 188 | case PCI_DEVICE_ID_INTEL_IOAT_IVB3: |
| 189 | case PCI_DEVICE_ID_INTEL_IOAT_IVB4: |
| 190 | case PCI_DEVICE_ID_INTEL_IOAT_IVB5: |
| 191 | case PCI_DEVICE_ID_INTEL_IOAT_IVB6: |
| 192 | case PCI_DEVICE_ID_INTEL_IOAT_IVB7: |
| 193 | case PCI_DEVICE_ID_INTEL_IOAT_IVB8: |
| 194 | case PCI_DEVICE_ID_INTEL_IOAT_IVB9: |
| 195 | return true; |
| 196 | default: |
| 197 | return false; |
| 198 | } |
| 199 | |
| 200 | } |
| 201 | |
| 202 | static bool is_hsw_ioat(struct pci_dev *pdev) |
| 203 | { |
| 204 | switch (pdev->device) { |
| 205 | case PCI_DEVICE_ID_INTEL_IOAT_HSW0: |
| 206 | case PCI_DEVICE_ID_INTEL_IOAT_HSW1: |
| 207 | case PCI_DEVICE_ID_INTEL_IOAT_HSW2: |
| 208 | case PCI_DEVICE_ID_INTEL_IOAT_HSW3: |
| 209 | case PCI_DEVICE_ID_INTEL_IOAT_HSW4: |
| 210 | case PCI_DEVICE_ID_INTEL_IOAT_HSW5: |
| 211 | case PCI_DEVICE_ID_INTEL_IOAT_HSW6: |
| 212 | case PCI_DEVICE_ID_INTEL_IOAT_HSW7: |
| 213 | case PCI_DEVICE_ID_INTEL_IOAT_HSW8: |
| 214 | case PCI_DEVICE_ID_INTEL_IOAT_HSW9: |
| 215 | return true; |
| 216 | default: |
| 217 | return false; |
| 218 | } |
| 219 | |
| 220 | } |
| 221 | |
| 222 | static bool is_xeon_cb32(struct pci_dev *pdev) |
| 223 | { |
| 224 | return is_jf_ioat(pdev) || is_snb_ioat(pdev) || is_ivb_ioat(pdev) || |
| 225 | is_hsw_ioat(pdev); |
| 226 | } |
| 227 | |
| 228 | static bool is_bwd_ioat(struct pci_dev *pdev) |
| 229 | { |
| 230 | switch (pdev->device) { |
| 231 | case PCI_DEVICE_ID_INTEL_IOAT_BWD0: |
| 232 | case PCI_DEVICE_ID_INTEL_IOAT_BWD1: |
| 233 | case PCI_DEVICE_ID_INTEL_IOAT_BWD2: |
| 234 | case PCI_DEVICE_ID_INTEL_IOAT_BWD3: |
| 235 | return true; |
| 236 | default: |
| 237 | return false; |
| 238 | } |
| 239 | } |
| 240 | |
Dave Jiang | d302398 | 2013-04-10 16:44:32 -0700 | [diff] [blame^] | 241 | static bool is_bwd_noraid(struct pci_dev *pdev) |
| 242 | { |
| 243 | switch (pdev->device) { |
| 244 | case PCI_DEVICE_ID_INTEL_IOAT_BWD2: |
| 245 | case PCI_DEVICE_ID_INTEL_IOAT_BWD3: |
| 246 | return true; |
| 247 | default: |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | } |
| 252 | |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 253 | static void pq16_set_src(struct ioat_raw_descriptor *desc[3], |
| 254 | dma_addr_t addr, u32 offset, u8 coef, int idx) |
| 255 | { |
| 256 | struct ioat_pq_descriptor *pq = (struct ioat_pq_descriptor *)desc[0]; |
| 257 | struct ioat_pq16a_descriptor *pq16 = |
| 258 | (struct ioat_pq16a_descriptor *)desc[1]; |
| 259 | struct ioat_raw_descriptor *raw = desc[pq16_idx_to_desc[idx]]; |
| 260 | |
| 261 | raw->field[pq16_idx_to_field[idx]] = addr + offset; |
| 262 | |
| 263 | if (idx < 8) |
| 264 | pq->coef[idx] = coef; |
| 265 | else |
| 266 | pq16->coef[idx - 8] = coef; |
| 267 | } |
| 268 | |
| 269 | struct ioat_sed_ent * |
| 270 | ioat3_alloc_sed(struct ioatdma_device *device, unsigned int hw_pool) |
| 271 | { |
| 272 | struct ioat_sed_ent *sed; |
| 273 | gfp_t flags = __GFP_ZERO | GFP_ATOMIC; |
| 274 | |
| 275 | sed = kmem_cache_alloc(device->sed_pool, flags); |
| 276 | if (!sed) |
| 277 | return NULL; |
| 278 | |
| 279 | sed->hw_pool = hw_pool; |
| 280 | sed->hw = dma_pool_alloc(device->sed_hw_pool[hw_pool], |
| 281 | flags, &sed->dma); |
| 282 | if (!sed->hw) { |
| 283 | kmem_cache_free(device->sed_pool, sed); |
| 284 | return NULL; |
| 285 | } |
| 286 | |
| 287 | return sed; |
| 288 | } |
| 289 | |
| 290 | void ioat3_free_sed(struct ioatdma_device *device, struct ioat_sed_ent *sed) |
| 291 | { |
| 292 | if (!sed) |
| 293 | return; |
| 294 | |
| 295 | dma_pool_free(device->sed_hw_pool[sed->hw_pool], sed->hw, sed->dma); |
| 296 | kmem_cache_free(device->sed_pool, sed); |
| 297 | } |
| 298 | |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 299 | static void ioat3_dma_unmap(struct ioat2_dma_chan *ioat, |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 300 | struct ioat_ring_ent *desc, int idx) |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 301 | { |
| 302 | struct ioat_chan_common *chan = &ioat->base; |
| 303 | struct pci_dev *pdev = chan->device->pdev; |
| 304 | size_t len = desc->len; |
| 305 | size_t offset = len - desc->hw->size; |
| 306 | struct dma_async_tx_descriptor *tx = &desc->txd; |
| 307 | enum dma_ctrl_flags flags = tx->flags; |
| 308 | |
| 309 | switch (desc->hw->ctl_f.op) { |
| 310 | case IOAT_OP_COPY: |
Dan Williams | 58c8649 | 2009-09-08 17:43:00 -0700 | [diff] [blame] | 311 | if (!desc->hw->ctl_f.null) /* skip 'interrupt' ops */ |
| 312 | ioat_dma_unmap(chan, flags, len, desc->hw); |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 313 | break; |
| 314 | case IOAT_OP_FILL: { |
| 315 | struct ioat_fill_descriptor *hw = desc->fill; |
| 316 | |
| 317 | if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP)) |
| 318 | ioat_unmap(pdev, hw->dst_addr - offset, len, |
| 319 | PCI_DMA_FROMDEVICE, flags, 1); |
| 320 | break; |
| 321 | } |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 322 | case IOAT_OP_XOR_VAL: |
| 323 | case IOAT_OP_XOR: { |
| 324 | struct ioat_xor_descriptor *xor = desc->xor; |
| 325 | struct ioat_ring_ent *ext; |
| 326 | struct ioat_xor_ext_descriptor *xor_ex = NULL; |
| 327 | int src_cnt = src_cnt_to_sw(xor->ctl_f.src_cnt); |
| 328 | struct ioat_raw_descriptor *descs[2]; |
| 329 | int i; |
| 330 | |
| 331 | if (src_cnt > 5) { |
| 332 | ext = ioat2_get_ring_ent(ioat, idx + 1); |
| 333 | xor_ex = ext->xor_ex; |
| 334 | } |
| 335 | |
| 336 | if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP)) { |
| 337 | descs[0] = (struct ioat_raw_descriptor *) xor; |
| 338 | descs[1] = (struct ioat_raw_descriptor *) xor_ex; |
| 339 | for (i = 0; i < src_cnt; i++) { |
| 340 | dma_addr_t src = xor_get_src(descs, i); |
| 341 | |
| 342 | ioat_unmap(pdev, src - offset, len, |
| 343 | PCI_DMA_TODEVICE, flags, 0); |
| 344 | } |
| 345 | |
| 346 | /* dest is a source in xor validate operations */ |
| 347 | if (xor->ctl_f.op == IOAT_OP_XOR_VAL) { |
| 348 | ioat_unmap(pdev, xor->dst_addr - offset, len, |
| 349 | PCI_DMA_TODEVICE, flags, 1); |
| 350 | break; |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP)) |
| 355 | ioat_unmap(pdev, xor->dst_addr - offset, len, |
| 356 | PCI_DMA_FROMDEVICE, flags, 1); |
| 357 | break; |
| 358 | } |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 359 | case IOAT_OP_PQ_VAL: |
| 360 | case IOAT_OP_PQ: { |
| 361 | struct ioat_pq_descriptor *pq = desc->pq; |
| 362 | struct ioat_ring_ent *ext; |
| 363 | struct ioat_pq_ext_descriptor *pq_ex = NULL; |
| 364 | int src_cnt = src_cnt_to_sw(pq->ctl_f.src_cnt); |
| 365 | struct ioat_raw_descriptor *descs[2]; |
| 366 | int i; |
| 367 | |
| 368 | if (src_cnt > 3) { |
| 369 | ext = ioat2_get_ring_ent(ioat, idx + 1); |
| 370 | pq_ex = ext->pq_ex; |
| 371 | } |
| 372 | |
| 373 | /* in the 'continue' case don't unmap the dests as sources */ |
| 374 | if (dmaf_p_disabled_continue(flags)) |
| 375 | src_cnt--; |
| 376 | else if (dmaf_continue(flags)) |
| 377 | src_cnt -= 3; |
| 378 | |
| 379 | if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP)) { |
| 380 | descs[0] = (struct ioat_raw_descriptor *) pq; |
| 381 | descs[1] = (struct ioat_raw_descriptor *) pq_ex; |
| 382 | for (i = 0; i < src_cnt; i++) { |
| 383 | dma_addr_t src = pq_get_src(descs, i); |
| 384 | |
| 385 | ioat_unmap(pdev, src - offset, len, |
| 386 | PCI_DMA_TODEVICE, flags, 0); |
| 387 | } |
| 388 | |
| 389 | /* the dests are sources in pq validate operations */ |
| 390 | if (pq->ctl_f.op == IOAT_OP_XOR_VAL) { |
| 391 | if (!(flags & DMA_PREP_PQ_DISABLE_P)) |
| 392 | ioat_unmap(pdev, pq->p_addr - offset, |
| 393 | len, PCI_DMA_TODEVICE, flags, 0); |
| 394 | if (!(flags & DMA_PREP_PQ_DISABLE_Q)) |
| 395 | ioat_unmap(pdev, pq->q_addr - offset, |
| 396 | len, PCI_DMA_TODEVICE, flags, 0); |
| 397 | break; |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP)) { |
| 402 | if (!(flags & DMA_PREP_PQ_DISABLE_P)) |
| 403 | ioat_unmap(pdev, pq->p_addr - offset, len, |
| 404 | PCI_DMA_BIDIRECTIONAL, flags, 1); |
| 405 | if (!(flags & DMA_PREP_PQ_DISABLE_Q)) |
| 406 | ioat_unmap(pdev, pq->q_addr - offset, len, |
| 407 | PCI_DMA_BIDIRECTIONAL, flags, 1); |
| 408 | } |
| 409 | break; |
| 410 | } |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 411 | case IOAT_OP_PQ_16S: |
| 412 | case IOAT_OP_PQ_VAL_16S: { |
| 413 | struct ioat_pq_descriptor *pq = desc->pq; |
| 414 | int src_cnt = src16_cnt_to_sw(pq->ctl_f.src_cnt); |
| 415 | struct ioat_raw_descriptor *descs[4]; |
| 416 | int i; |
| 417 | |
| 418 | /* in the 'continue' case don't unmap the dests as sources */ |
| 419 | if (dmaf_p_disabled_continue(flags)) |
| 420 | src_cnt--; |
| 421 | else if (dmaf_continue(flags)) |
| 422 | src_cnt -= 3; |
| 423 | |
| 424 | if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP)) { |
| 425 | descs[0] = (struct ioat_raw_descriptor *)pq; |
| 426 | descs[1] = (struct ioat_raw_descriptor *)(desc->sed->hw); |
| 427 | descs[2] = (struct ioat_raw_descriptor *)(&desc->sed->hw->b[0]); |
| 428 | for (i = 0; i < src_cnt; i++) { |
| 429 | dma_addr_t src = pq16_get_src(descs, i); |
| 430 | |
| 431 | ioat_unmap(pdev, src - offset, len, |
| 432 | PCI_DMA_TODEVICE, flags, 0); |
| 433 | } |
| 434 | |
| 435 | /* the dests are sources in pq validate operations */ |
| 436 | if (pq->ctl_f.op == IOAT_OP_XOR_VAL) { |
| 437 | if (!(flags & DMA_PREP_PQ_DISABLE_P)) |
| 438 | ioat_unmap(pdev, pq->p_addr - offset, |
| 439 | len, PCI_DMA_TODEVICE, |
| 440 | flags, 0); |
| 441 | if (!(flags & DMA_PREP_PQ_DISABLE_Q)) |
| 442 | ioat_unmap(pdev, pq->q_addr - offset, |
| 443 | len, PCI_DMA_TODEVICE, |
| 444 | flags, 0); |
| 445 | break; |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP)) { |
| 450 | if (!(flags & DMA_PREP_PQ_DISABLE_P)) |
| 451 | ioat_unmap(pdev, pq->p_addr - offset, len, |
| 452 | PCI_DMA_BIDIRECTIONAL, flags, 1); |
| 453 | if (!(flags & DMA_PREP_PQ_DISABLE_Q)) |
| 454 | ioat_unmap(pdev, pq->q_addr - offset, len, |
| 455 | PCI_DMA_BIDIRECTIONAL, flags, 1); |
| 456 | } |
| 457 | break; |
| 458 | } |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 459 | default: |
| 460 | dev_err(&pdev->dev, "%s: unknown op type: %#x\n", |
| 461 | __func__, desc->hw->ctl_f.op); |
| 462 | } |
| 463 | } |
| 464 | |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 465 | static bool desc_has_ext(struct ioat_ring_ent *desc) |
| 466 | { |
| 467 | struct ioat_dma_descriptor *hw = desc->hw; |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 468 | |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 469 | if (hw->ctl_f.op == IOAT_OP_XOR || |
| 470 | hw->ctl_f.op == IOAT_OP_XOR_VAL) { |
| 471 | struct ioat_xor_descriptor *xor = desc->xor; |
| 472 | |
| 473 | if (src_cnt_to_sw(xor->ctl_f.src_cnt) > 5) |
| 474 | return true; |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 475 | } else if (hw->ctl_f.op == IOAT_OP_PQ || |
| 476 | hw->ctl_f.op == IOAT_OP_PQ_VAL) { |
| 477 | struct ioat_pq_descriptor *pq = desc->pq; |
| 478 | |
| 479 | if (src_cnt_to_sw(pq->ctl_f.src_cnt) > 3) |
| 480 | return true; |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | return false; |
| 484 | } |
| 485 | |
Dave Jiang | 3f09ede | 2013-03-26 15:43:09 -0700 | [diff] [blame] | 486 | static u64 ioat3_get_current_completion(struct ioat_chan_common *chan) |
| 487 | { |
| 488 | u64 phys_complete; |
| 489 | u64 completion; |
| 490 | |
| 491 | completion = *chan->completion; |
| 492 | phys_complete = ioat_chansts_to_addr(completion); |
| 493 | |
| 494 | dev_dbg(to_dev(chan), "%s: phys_complete: %#llx\n", __func__, |
| 495 | (unsigned long long) phys_complete); |
| 496 | |
| 497 | return phys_complete; |
| 498 | } |
| 499 | |
| 500 | static bool ioat3_cleanup_preamble(struct ioat_chan_common *chan, |
| 501 | u64 *phys_complete) |
| 502 | { |
| 503 | *phys_complete = ioat3_get_current_completion(chan); |
| 504 | if (*phys_complete == chan->last_completion) |
| 505 | return false; |
| 506 | |
| 507 | clear_bit(IOAT_COMPLETION_ACK, &chan->state); |
| 508 | mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT); |
| 509 | |
| 510 | return true; |
| 511 | } |
| 512 | |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 513 | /** |
| 514 | * __cleanup - reclaim used descriptors |
| 515 | * @ioat: channel (ring) to clean |
| 516 | * |
| 517 | * The difference from the dma_v2.c __cleanup() is that this routine |
| 518 | * handles extended descriptors and dma-unmapping raid operations. |
| 519 | */ |
Dan Williams | 2750293 | 2012-03-23 13:36:42 -0700 | [diff] [blame] | 520 | static void __cleanup(struct ioat2_dma_chan *ioat, dma_addr_t phys_complete) |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 521 | { |
| 522 | struct ioat_chan_common *chan = &ioat->base; |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 523 | struct ioatdma_device *device = chan->device; |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 524 | struct ioat_ring_ent *desc; |
| 525 | bool seen_current = false; |
Dan Williams | 074cc47 | 2010-05-01 15:22:55 -0700 | [diff] [blame] | 526 | int idx = ioat->tail, i; |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 527 | u16 active; |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 528 | |
| 529 | dev_dbg(to_dev(chan), "%s: head: %#x tail: %#x issued: %#x\n", |
| 530 | __func__, ioat->head, ioat->tail, ioat->issued); |
| 531 | |
Dave Jiang | 3f09ede | 2013-03-26 15:43:09 -0700 | [diff] [blame] | 532 | /* |
| 533 | * At restart of the channel, the completion address and the |
| 534 | * channel status will be 0 due to starting a new chain. Since |
| 535 | * it's new chain and the first descriptor "fails", there is |
| 536 | * nothing to clean up. We do not want to reap the entire submitted |
| 537 | * chain due to this 0 address value and then BUG. |
| 538 | */ |
| 539 | if (!phys_complete) |
| 540 | return; |
| 541 | |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 542 | active = ioat2_ring_active(ioat); |
| 543 | for (i = 0; i < active && !seen_current; i++) { |
| 544 | struct dma_async_tx_descriptor *tx; |
| 545 | |
Dan Williams | 074cc47 | 2010-05-01 15:22:55 -0700 | [diff] [blame] | 546 | smp_read_barrier_depends(); |
| 547 | prefetch(ioat2_get_ring_ent(ioat, idx + i + 1)); |
| 548 | desc = ioat2_get_ring_ent(ioat, idx + i); |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 549 | dump_desc_dbg(ioat, desc); |
| 550 | tx = &desc->txd; |
| 551 | if (tx->cookie) { |
Russell King - ARM Linux | f7fbce0 | 2012-03-06 22:35:07 +0000 | [diff] [blame] | 552 | dma_cookie_complete(tx); |
Dan Williams | 074cc47 | 2010-05-01 15:22:55 -0700 | [diff] [blame] | 553 | ioat3_dma_unmap(ioat, desc, idx + i); |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 554 | if (tx->callback) { |
| 555 | tx->callback(tx->callback_param); |
| 556 | tx->callback = NULL; |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | if (tx->phys == phys_complete) |
| 561 | seen_current = true; |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 562 | |
| 563 | /* skip extended descriptors */ |
| 564 | if (desc_has_ext(desc)) { |
| 565 | BUG_ON(i + 1 >= active); |
| 566 | i++; |
| 567 | } |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 568 | |
| 569 | /* cleanup super extended descriptors */ |
| 570 | if (desc->sed) { |
| 571 | ioat3_free_sed(device, desc->sed); |
| 572 | desc->sed = NULL; |
| 573 | } |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 574 | } |
Dan Williams | 074cc47 | 2010-05-01 15:22:55 -0700 | [diff] [blame] | 575 | smp_mb(); /* finish all descriptor reads before incrementing tail */ |
| 576 | ioat->tail = idx + i; |
Dan Williams | aa75db0 | 2010-03-03 21:21:10 -0700 | [diff] [blame] | 577 | BUG_ON(active && !seen_current); /* no active descs have written a completion? */ |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 578 | chan->last_completion = phys_complete; |
Dan Williams | b9cc986 | 2010-03-03 21:21:13 -0700 | [diff] [blame] | 579 | |
Dan Williams | 074cc47 | 2010-05-01 15:22:55 -0700 | [diff] [blame] | 580 | if (active - i == 0) { |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 581 | dev_dbg(to_dev(chan), "%s: cancel completion timeout\n", |
| 582 | __func__); |
| 583 | clear_bit(IOAT_COMPLETION_PENDING, &chan->state); |
| 584 | mod_timer(&chan->timer, jiffies + IDLE_TIMEOUT); |
| 585 | } |
Dan Williams | b9cc986 | 2010-03-03 21:21:13 -0700 | [diff] [blame] | 586 | /* 5 microsecond delay per pending descriptor */ |
Dan Williams | 074cc47 | 2010-05-01 15:22:55 -0700 | [diff] [blame] | 587 | writew(min((5 * (active - i)), IOAT_INTRDELAY_MASK), |
Dan Williams | b9cc986 | 2010-03-03 21:21:13 -0700 | [diff] [blame] | 588 | chan->device->reg_base + IOAT_INTRDELAY_OFFSET); |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 589 | } |
| 590 | |
Dan Williams | 074cc47 | 2010-05-01 15:22:55 -0700 | [diff] [blame] | 591 | static void ioat3_cleanup(struct ioat2_dma_chan *ioat) |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 592 | { |
| 593 | struct ioat_chan_common *chan = &ioat->base; |
Dave Jiang | 3f09ede | 2013-03-26 15:43:09 -0700 | [diff] [blame] | 594 | u64 phys_complete; |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 595 | |
Dan Williams | b9cc986 | 2010-03-03 21:21:13 -0700 | [diff] [blame] | 596 | spin_lock_bh(&chan->cleanup_lock); |
Dave Jiang | 3f09ede | 2013-03-26 15:43:09 -0700 | [diff] [blame] | 597 | |
| 598 | if (ioat3_cleanup_preamble(chan, &phys_complete)) |
Dan Williams | 074cc47 | 2010-05-01 15:22:55 -0700 | [diff] [blame] | 599 | __cleanup(ioat, phys_complete); |
Dave Jiang | 3f09ede | 2013-03-26 15:43:09 -0700 | [diff] [blame] | 600 | |
| 601 | if (is_ioat_halted(*chan->completion)) { |
| 602 | u32 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET); |
| 603 | |
| 604 | if (chanerr & IOAT_CHANERR_HANDLE_MASK) { |
| 605 | mod_timer(&chan->timer, jiffies + IDLE_TIMEOUT); |
| 606 | ioat3_eh(ioat); |
| 607 | } |
| 608 | } |
| 609 | |
Dan Williams | b9cc986 | 2010-03-03 21:21:13 -0700 | [diff] [blame] | 610 | spin_unlock_bh(&chan->cleanup_lock); |
| 611 | } |
| 612 | |
Dan Williams | aa4d72a | 2010-03-03 21:21:13 -0700 | [diff] [blame] | 613 | static void ioat3_cleanup_event(unsigned long data) |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 614 | { |
Dan Williams | aa4d72a | 2010-03-03 21:21:13 -0700 | [diff] [blame] | 615 | struct ioat2_dma_chan *ioat = to_ioat2_chan((void *) data); |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 616 | |
Dan Williams | 074cc47 | 2010-05-01 15:22:55 -0700 | [diff] [blame] | 617 | ioat3_cleanup(ioat); |
Dan Williams | 773d9e2 | 2010-03-03 11:47:42 -0700 | [diff] [blame] | 618 | writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET); |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | static void ioat3_restart_channel(struct ioat2_dma_chan *ioat) |
| 622 | { |
| 623 | struct ioat_chan_common *chan = &ioat->base; |
Dave Jiang | 3f09ede | 2013-03-26 15:43:09 -0700 | [diff] [blame] | 624 | u64 phys_complete; |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 625 | |
Dan Williams | b372ec2 | 2010-03-03 11:47:42 -0700 | [diff] [blame] | 626 | ioat2_quiesce(chan, 0); |
Dave Jiang | 3f09ede | 2013-03-26 15:43:09 -0700 | [diff] [blame] | 627 | if (ioat3_cleanup_preamble(chan, &phys_complete)) |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 628 | __cleanup(ioat, phys_complete); |
| 629 | |
| 630 | __ioat2_restart_chan(ioat); |
| 631 | } |
| 632 | |
Dave Jiang | 3f09ede | 2013-03-26 15:43:09 -0700 | [diff] [blame] | 633 | static void ioat3_eh(struct ioat2_dma_chan *ioat) |
| 634 | { |
| 635 | struct ioat_chan_common *chan = &ioat->base; |
| 636 | struct pci_dev *pdev = to_pdev(chan); |
| 637 | struct ioat_dma_descriptor *hw; |
| 638 | u64 phys_complete; |
| 639 | struct ioat_ring_ent *desc; |
| 640 | u32 err_handled = 0; |
| 641 | u32 chanerr_int; |
| 642 | u32 chanerr; |
| 643 | |
| 644 | /* cleanup so tail points to descriptor that caused the error */ |
| 645 | if (ioat3_cleanup_preamble(chan, &phys_complete)) |
| 646 | __cleanup(ioat, phys_complete); |
| 647 | |
| 648 | chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET); |
| 649 | pci_read_config_dword(pdev, IOAT_PCI_CHANERR_INT_OFFSET, &chanerr_int); |
| 650 | |
| 651 | dev_dbg(to_dev(chan), "%s: error = %x:%x\n", |
| 652 | __func__, chanerr, chanerr_int); |
| 653 | |
| 654 | desc = ioat2_get_ring_ent(ioat, ioat->tail); |
| 655 | hw = desc->hw; |
| 656 | dump_desc_dbg(ioat, desc); |
| 657 | |
| 658 | switch (hw->ctl_f.op) { |
| 659 | case IOAT_OP_XOR_VAL: |
| 660 | if (chanerr & IOAT_CHANERR_XOR_P_OR_CRC_ERR) { |
| 661 | *desc->result |= SUM_CHECK_P_RESULT; |
| 662 | err_handled |= IOAT_CHANERR_XOR_P_OR_CRC_ERR; |
| 663 | } |
| 664 | break; |
| 665 | case IOAT_OP_PQ_VAL: |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 666 | case IOAT_OP_PQ_VAL_16S: |
Dave Jiang | 3f09ede | 2013-03-26 15:43:09 -0700 | [diff] [blame] | 667 | if (chanerr & IOAT_CHANERR_XOR_P_OR_CRC_ERR) { |
| 668 | *desc->result |= SUM_CHECK_P_RESULT; |
| 669 | err_handled |= IOAT_CHANERR_XOR_P_OR_CRC_ERR; |
| 670 | } |
| 671 | if (chanerr & IOAT_CHANERR_XOR_Q_ERR) { |
| 672 | *desc->result |= SUM_CHECK_Q_RESULT; |
| 673 | err_handled |= IOAT_CHANERR_XOR_Q_ERR; |
| 674 | } |
| 675 | break; |
| 676 | } |
| 677 | |
| 678 | /* fault on unhandled error or spurious halt */ |
| 679 | if (chanerr ^ err_handled || chanerr == 0) { |
| 680 | dev_err(to_dev(chan), "%s: fatal error (%x:%x)\n", |
| 681 | __func__, chanerr, err_handled); |
| 682 | BUG(); |
| 683 | } |
| 684 | |
| 685 | writel(chanerr, chan->reg_base + IOAT_CHANERR_OFFSET); |
| 686 | pci_write_config_dword(pdev, IOAT_PCI_CHANERR_INT_OFFSET, chanerr_int); |
| 687 | |
| 688 | /* mark faulting descriptor as complete */ |
| 689 | *chan->completion = desc->txd.phys; |
| 690 | |
| 691 | spin_lock_bh(&ioat->prep_lock); |
| 692 | ioat3_restart_channel(ioat); |
| 693 | spin_unlock_bh(&ioat->prep_lock); |
| 694 | } |
| 695 | |
Dave Jiang | 4dec23d | 2013-02-07 14:38:32 -0700 | [diff] [blame] | 696 | static void check_active(struct ioat2_dma_chan *ioat) |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 697 | { |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 698 | struct ioat_chan_common *chan = &ioat->base; |
| 699 | |
Dave Jiang | 4dec23d | 2013-02-07 14:38:32 -0700 | [diff] [blame] | 700 | if (ioat2_ring_active(ioat)) { |
| 701 | mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT); |
| 702 | return; |
| 703 | } |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 704 | |
Dave Jiang | 4dec23d | 2013-02-07 14:38:32 -0700 | [diff] [blame] | 705 | if (test_and_clear_bit(IOAT_CHAN_ACTIVE, &chan->state)) |
| 706 | mod_timer(&chan->timer, jiffies + IDLE_TIMEOUT); |
| 707 | else if (ioat->alloc_order > ioat_get_alloc_order()) { |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 708 | /* if the ring is idle, empty, and oversized try to step |
| 709 | * down the size |
| 710 | */ |
Dave Jiang | 4dec23d | 2013-02-07 14:38:32 -0700 | [diff] [blame] | 711 | reshape_ring(ioat, ioat->alloc_order - 1); |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 712 | |
| 713 | /* keep shrinking until we get back to our minimum |
| 714 | * default size |
| 715 | */ |
| 716 | if (ioat->alloc_order > ioat_get_alloc_order()) |
| 717 | mod_timer(&chan->timer, jiffies + IDLE_TIMEOUT); |
| 718 | } |
Dave Jiang | 4dec23d | 2013-02-07 14:38:32 -0700 | [diff] [blame] | 719 | |
| 720 | } |
| 721 | |
Fengguang Wu | a20702b | 2013-02-13 09:40:03 +0800 | [diff] [blame] | 722 | static void ioat3_timer_event(unsigned long data) |
Dave Jiang | 4dec23d | 2013-02-07 14:38:32 -0700 | [diff] [blame] | 723 | { |
| 724 | struct ioat2_dma_chan *ioat = to_ioat2_chan((void *) data); |
| 725 | struct ioat_chan_common *chan = &ioat->base; |
| 726 | dma_addr_t phys_complete; |
| 727 | u64 status; |
| 728 | |
| 729 | status = ioat_chansts(chan); |
| 730 | |
| 731 | /* when halted due to errors check for channel |
| 732 | * programming errors before advancing the completion state |
| 733 | */ |
| 734 | if (is_ioat_halted(status)) { |
| 735 | u32 chanerr; |
| 736 | |
| 737 | chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET); |
| 738 | dev_err(to_dev(chan), "%s: Channel halted (%x)\n", |
| 739 | __func__, chanerr); |
| 740 | if (test_bit(IOAT_RUN, &chan->state)) |
| 741 | BUG_ON(is_ioat_bug(chanerr)); |
| 742 | else /* we never got off the ground */ |
| 743 | return; |
| 744 | } |
| 745 | |
| 746 | /* if we haven't made progress and we have already |
| 747 | * acknowledged a pending completion once, then be more |
| 748 | * forceful with a restart |
| 749 | */ |
| 750 | spin_lock_bh(&chan->cleanup_lock); |
| 751 | if (ioat_cleanup_preamble(chan, &phys_complete)) |
| 752 | __cleanup(ioat, phys_complete); |
| 753 | else if (test_bit(IOAT_COMPLETION_ACK, &chan->state)) { |
| 754 | spin_lock_bh(&ioat->prep_lock); |
| 755 | ioat3_restart_channel(ioat); |
| 756 | spin_unlock_bh(&ioat->prep_lock); |
| 757 | spin_unlock_bh(&chan->cleanup_lock); |
| 758 | return; |
| 759 | } else { |
| 760 | set_bit(IOAT_COMPLETION_ACK, &chan->state); |
| 761 | mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT); |
| 762 | } |
| 763 | |
| 764 | |
| 765 | if (ioat2_ring_active(ioat)) |
| 766 | mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT); |
| 767 | else { |
| 768 | spin_lock_bh(&ioat->prep_lock); |
| 769 | check_active(ioat); |
| 770 | spin_unlock_bh(&ioat->prep_lock); |
| 771 | } |
| 772 | spin_unlock_bh(&chan->cleanup_lock); |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | static enum dma_status |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 776 | ioat3_tx_status(struct dma_chan *c, dma_cookie_t cookie, |
| 777 | struct dma_tx_state *txstate) |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 778 | { |
| 779 | struct ioat2_dma_chan *ioat = to_ioat2_chan(c); |
Russell King - ARM Linux | 96a2af4 | 2012-03-06 22:35:27 +0000 | [diff] [blame] | 780 | enum dma_status ret; |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 781 | |
Russell King - ARM Linux | 96a2af4 | 2012-03-06 22:35:27 +0000 | [diff] [blame] | 782 | ret = dma_cookie_status(c, cookie, txstate); |
| 783 | if (ret == DMA_SUCCESS) |
| 784 | return ret; |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 785 | |
Dan Williams | 074cc47 | 2010-05-01 15:22:55 -0700 | [diff] [blame] | 786 | ioat3_cleanup(ioat); |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 787 | |
Russell King - ARM Linux | 96a2af4 | 2012-03-06 22:35:27 +0000 | [diff] [blame] | 788 | return dma_cookie_status(c, cookie, txstate); |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | static struct dma_async_tx_descriptor * |
| 792 | ioat3_prep_memset_lock(struct dma_chan *c, dma_addr_t dest, int value, |
| 793 | size_t len, unsigned long flags) |
| 794 | { |
| 795 | struct ioat2_dma_chan *ioat = to_ioat2_chan(c); |
| 796 | struct ioat_ring_ent *desc; |
| 797 | size_t total_len = len; |
| 798 | struct ioat_fill_descriptor *fill; |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 799 | u64 src_data = (0x0101010101010101ULL) * (value & 0xff); |
Dan Williams | 074cc47 | 2010-05-01 15:22:55 -0700 | [diff] [blame] | 800 | int num_descs, idx, i; |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 801 | |
| 802 | num_descs = ioat2_xferlen_to_descs(ioat, len); |
Dan Williams | 074cc47 | 2010-05-01 15:22:55 -0700 | [diff] [blame] | 803 | if (likely(num_descs) && ioat2_check_space_lock(ioat, num_descs) == 0) |
| 804 | idx = ioat->head; |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 805 | else |
| 806 | return NULL; |
Dan Williams | cdef57d | 2009-09-21 09:22:29 -0700 | [diff] [blame] | 807 | i = 0; |
| 808 | do { |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 809 | size_t xfer_size = min_t(size_t, len, 1 << ioat->xfercap_log); |
| 810 | |
| 811 | desc = ioat2_get_ring_ent(ioat, idx + i); |
| 812 | fill = desc->fill; |
| 813 | |
| 814 | fill->size = xfer_size; |
| 815 | fill->src_data = src_data; |
| 816 | fill->dst_addr = dest; |
| 817 | fill->ctl = 0; |
| 818 | fill->ctl_f.op = IOAT_OP_FILL; |
| 819 | |
| 820 | len -= xfer_size; |
| 821 | dest += xfer_size; |
| 822 | dump_desc_dbg(ioat, desc); |
Dan Williams | cdef57d | 2009-09-21 09:22:29 -0700 | [diff] [blame] | 823 | } while (++i < num_descs); |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 824 | |
| 825 | desc->txd.flags = flags; |
| 826 | desc->len = total_len; |
| 827 | fill->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT); |
| 828 | fill->ctl_f.fence = !!(flags & DMA_PREP_FENCE); |
| 829 | fill->ctl_f.compl_write = 1; |
| 830 | dump_desc_dbg(ioat, desc); |
| 831 | |
| 832 | /* we leave the channel locked to ensure in order submission */ |
| 833 | return &desc->txd; |
| 834 | } |
| 835 | |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 836 | static struct dma_async_tx_descriptor * |
| 837 | __ioat3_prep_xor_lock(struct dma_chan *c, enum sum_check_flags *result, |
| 838 | dma_addr_t dest, dma_addr_t *src, unsigned int src_cnt, |
| 839 | size_t len, unsigned long flags) |
| 840 | { |
| 841 | struct ioat2_dma_chan *ioat = to_ioat2_chan(c); |
| 842 | struct ioat_ring_ent *compl_desc; |
| 843 | struct ioat_ring_ent *desc; |
| 844 | struct ioat_ring_ent *ext; |
| 845 | size_t total_len = len; |
| 846 | struct ioat_xor_descriptor *xor; |
| 847 | struct ioat_xor_ext_descriptor *xor_ex = NULL; |
| 848 | struct ioat_dma_descriptor *hw; |
Dan Williams | 074cc47 | 2010-05-01 15:22:55 -0700 | [diff] [blame] | 849 | int num_descs, with_ext, idx, i; |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 850 | u32 offset = 0; |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 851 | u8 op = result ? IOAT_OP_XOR_VAL : IOAT_OP_XOR; |
| 852 | |
| 853 | BUG_ON(src_cnt < 2); |
| 854 | |
| 855 | num_descs = ioat2_xferlen_to_descs(ioat, len); |
| 856 | /* we need 2x the number of descriptors to cover greater than 5 |
| 857 | * sources |
| 858 | */ |
| 859 | if (src_cnt > 5) { |
| 860 | with_ext = 1; |
| 861 | num_descs *= 2; |
| 862 | } else |
| 863 | with_ext = 0; |
| 864 | |
| 865 | /* completion writes from the raid engine may pass completion |
| 866 | * writes from the legacy engine, so we need one extra null |
| 867 | * (legacy) descriptor to ensure all completion writes arrive in |
| 868 | * order. |
| 869 | */ |
Dan Williams | 074cc47 | 2010-05-01 15:22:55 -0700 | [diff] [blame] | 870 | if (likely(num_descs) && ioat2_check_space_lock(ioat, num_descs+1) == 0) |
| 871 | idx = ioat->head; |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 872 | else |
| 873 | return NULL; |
Dan Williams | cdef57d | 2009-09-21 09:22:29 -0700 | [diff] [blame] | 874 | i = 0; |
| 875 | do { |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 876 | struct ioat_raw_descriptor *descs[2]; |
| 877 | size_t xfer_size = min_t(size_t, len, 1 << ioat->xfercap_log); |
| 878 | int s; |
| 879 | |
| 880 | desc = ioat2_get_ring_ent(ioat, idx + i); |
| 881 | xor = desc->xor; |
| 882 | |
| 883 | /* save a branch by unconditionally retrieving the |
| 884 | * extended descriptor xor_set_src() knows to not write |
| 885 | * to it in the single descriptor case |
| 886 | */ |
| 887 | ext = ioat2_get_ring_ent(ioat, idx + i + 1); |
| 888 | xor_ex = ext->xor_ex; |
| 889 | |
| 890 | descs[0] = (struct ioat_raw_descriptor *) xor; |
| 891 | descs[1] = (struct ioat_raw_descriptor *) xor_ex; |
| 892 | for (s = 0; s < src_cnt; s++) |
| 893 | xor_set_src(descs, src[s], offset, s); |
| 894 | xor->size = xfer_size; |
| 895 | xor->dst_addr = dest + offset; |
| 896 | xor->ctl = 0; |
| 897 | xor->ctl_f.op = op; |
| 898 | xor->ctl_f.src_cnt = src_cnt_to_hw(src_cnt); |
| 899 | |
| 900 | len -= xfer_size; |
| 901 | offset += xfer_size; |
| 902 | dump_desc_dbg(ioat, desc); |
Dan Williams | cdef57d | 2009-09-21 09:22:29 -0700 | [diff] [blame] | 903 | } while ((i += 1 + with_ext) < num_descs); |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 904 | |
| 905 | /* last xor descriptor carries the unmap parameters and fence bit */ |
| 906 | desc->txd.flags = flags; |
| 907 | desc->len = total_len; |
| 908 | if (result) |
| 909 | desc->result = result; |
| 910 | xor->ctl_f.fence = !!(flags & DMA_PREP_FENCE); |
| 911 | |
| 912 | /* completion descriptor carries interrupt bit */ |
| 913 | compl_desc = ioat2_get_ring_ent(ioat, idx + i); |
| 914 | compl_desc->txd.flags = flags & DMA_PREP_INTERRUPT; |
| 915 | hw = compl_desc->hw; |
| 916 | hw->ctl = 0; |
| 917 | hw->ctl_f.null = 1; |
| 918 | hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT); |
| 919 | hw->ctl_f.compl_write = 1; |
| 920 | hw->size = NULL_DESC_BUFFER_SIZE; |
| 921 | dump_desc_dbg(ioat, compl_desc); |
| 922 | |
| 923 | /* we leave the channel locked to ensure in order submission */ |
Dan Williams | 49954c1 | 2009-11-19 17:11:03 -0700 | [diff] [blame] | 924 | return &compl_desc->txd; |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | static struct dma_async_tx_descriptor * |
| 928 | ioat3_prep_xor(struct dma_chan *chan, dma_addr_t dest, dma_addr_t *src, |
| 929 | unsigned int src_cnt, size_t len, unsigned long flags) |
| 930 | { |
| 931 | return __ioat3_prep_xor_lock(chan, NULL, dest, src, src_cnt, len, flags); |
| 932 | } |
| 933 | |
| 934 | struct dma_async_tx_descriptor * |
| 935 | ioat3_prep_xor_val(struct dma_chan *chan, dma_addr_t *src, |
| 936 | unsigned int src_cnt, size_t len, |
| 937 | enum sum_check_flags *result, unsigned long flags) |
| 938 | { |
| 939 | /* the cleanup routine only sets bits on validate failure, it |
| 940 | * does not clear bits on validate success... so clear it here |
| 941 | */ |
| 942 | *result = 0; |
| 943 | |
| 944 | return __ioat3_prep_xor_lock(chan, result, src[0], &src[1], |
| 945 | src_cnt - 1, len, flags); |
| 946 | } |
| 947 | |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 948 | static void |
| 949 | dump_pq_desc_dbg(struct ioat2_dma_chan *ioat, struct ioat_ring_ent *desc, struct ioat_ring_ent *ext) |
| 950 | { |
| 951 | struct device *dev = to_dev(&ioat->base); |
| 952 | struct ioat_pq_descriptor *pq = desc->pq; |
| 953 | struct ioat_pq_ext_descriptor *pq_ex = ext ? ext->pq_ex : NULL; |
| 954 | struct ioat_raw_descriptor *descs[] = { (void *) pq, (void *) pq_ex }; |
| 955 | int src_cnt = src_cnt_to_sw(pq->ctl_f.src_cnt); |
| 956 | int i; |
| 957 | |
| 958 | dev_dbg(dev, "desc[%d]: (%#llx->%#llx) flags: %#x" |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 959 | " sz: %#10.8x ctl: %#x (op: %#x int: %d compl: %d pq: '%s%s'" |
| 960 | " src_cnt: %d)\n", |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 961 | desc_id(desc), (unsigned long long) desc->txd.phys, |
| 962 | (unsigned long long) (pq_ex ? pq_ex->next : pq->next), |
| 963 | desc->txd.flags, pq->size, pq->ctl, pq->ctl_f.op, pq->ctl_f.int_en, |
| 964 | pq->ctl_f.compl_write, |
| 965 | pq->ctl_f.p_disable ? "" : "p", pq->ctl_f.q_disable ? "" : "q", |
| 966 | pq->ctl_f.src_cnt); |
| 967 | for (i = 0; i < src_cnt; i++) |
| 968 | dev_dbg(dev, "\tsrc[%d]: %#llx coef: %#x\n", i, |
| 969 | (unsigned long long) pq_get_src(descs, i), pq->coef[i]); |
| 970 | dev_dbg(dev, "\tP: %#llx\n", pq->p_addr); |
| 971 | dev_dbg(dev, "\tQ: %#llx\n", pq->q_addr); |
Dave Jiang | 50f9f97 | 2013-03-04 10:59:54 -0700 | [diff] [blame] | 972 | dev_dbg(dev, "\tNEXT: %#llx\n", pq->next); |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 973 | } |
| 974 | |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 975 | static void dump_pq16_desc_dbg(struct ioat2_dma_chan *ioat, |
| 976 | struct ioat_ring_ent *desc) |
| 977 | { |
| 978 | struct device *dev = to_dev(&ioat->base); |
| 979 | struct ioat_pq_descriptor *pq = desc->pq; |
| 980 | struct ioat_raw_descriptor *descs[] = { (void *)pq, |
| 981 | (void *)pq, |
| 982 | (void *)pq }; |
| 983 | int src_cnt = src16_cnt_to_sw(pq->ctl_f.src_cnt); |
| 984 | int i; |
| 985 | |
| 986 | if (desc->sed) { |
| 987 | descs[1] = (void *)desc->sed->hw; |
| 988 | descs[2] = (void *)desc->sed->hw + 64; |
| 989 | } |
| 990 | |
| 991 | dev_dbg(dev, "desc[%d]: (%#llx->%#llx) flags: %#x" |
| 992 | " sz: %#x ctl: %#x (op: %#x int: %d compl: %d pq: '%s%s'" |
| 993 | " src_cnt: %d)\n", |
| 994 | desc_id(desc), (unsigned long long) desc->txd.phys, |
| 995 | (unsigned long long) pq->next, |
| 996 | desc->txd.flags, pq->size, pq->ctl, |
| 997 | pq->ctl_f.op, pq->ctl_f.int_en, |
| 998 | pq->ctl_f.compl_write, |
| 999 | pq->ctl_f.p_disable ? "" : "p", pq->ctl_f.q_disable ? "" : "q", |
| 1000 | pq->ctl_f.src_cnt); |
| 1001 | for (i = 0; i < src_cnt; i++) { |
| 1002 | dev_dbg(dev, "\tsrc[%d]: %#llx coef: %#x\n", i, |
| 1003 | (unsigned long long) pq16_get_src(descs, i), |
| 1004 | pq->coef[i]); |
| 1005 | } |
| 1006 | dev_dbg(dev, "\tP: %#llx\n", pq->p_addr); |
| 1007 | dev_dbg(dev, "\tQ: %#llx\n", pq->q_addr); |
| 1008 | } |
| 1009 | |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 1010 | static struct dma_async_tx_descriptor * |
| 1011 | __ioat3_prep_pq_lock(struct dma_chan *c, enum sum_check_flags *result, |
| 1012 | const dma_addr_t *dst, const dma_addr_t *src, |
| 1013 | unsigned int src_cnt, const unsigned char *scf, |
| 1014 | size_t len, unsigned long flags) |
| 1015 | { |
| 1016 | struct ioat2_dma_chan *ioat = to_ioat2_chan(c); |
| 1017 | struct ioat_chan_common *chan = &ioat->base; |
Dave Jiang | e088477 | 2013-04-10 16:44:20 -0700 | [diff] [blame] | 1018 | struct ioatdma_device *device = chan->device; |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 1019 | struct ioat_ring_ent *compl_desc; |
| 1020 | struct ioat_ring_ent *desc; |
| 1021 | struct ioat_ring_ent *ext; |
| 1022 | size_t total_len = len; |
| 1023 | struct ioat_pq_descriptor *pq; |
| 1024 | struct ioat_pq_ext_descriptor *pq_ex = NULL; |
| 1025 | struct ioat_dma_descriptor *hw; |
| 1026 | u32 offset = 0; |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 1027 | u8 op = result ? IOAT_OP_PQ_VAL : IOAT_OP_PQ; |
Dan Williams | 074cc47 | 2010-05-01 15:22:55 -0700 | [diff] [blame] | 1028 | int i, s, idx, with_ext, num_descs; |
Dave Jiang | e088477 | 2013-04-10 16:44:20 -0700 | [diff] [blame] | 1029 | int cb32 = (device->version < IOAT_VER_3_3) ? 1 : 0; |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 1030 | |
| 1031 | dev_dbg(to_dev(chan), "%s\n", __func__); |
| 1032 | /* the engine requires at least two sources (we provide |
| 1033 | * at least 1 implied source in the DMA_PREP_CONTINUE case) |
| 1034 | */ |
| 1035 | BUG_ON(src_cnt + dmaf_continue(flags) < 2); |
| 1036 | |
| 1037 | num_descs = ioat2_xferlen_to_descs(ioat, len); |
| 1038 | /* we need 2x the number of descriptors to cover greater than 3 |
Dan Williams | cd78809 | 2009-12-17 13:52:39 -0700 | [diff] [blame] | 1039 | * sources (we need 1 extra source in the q-only continuation |
| 1040 | * case and 3 extra sources in the p+q continuation case. |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 1041 | */ |
Dan Williams | cd78809 | 2009-12-17 13:52:39 -0700 | [diff] [blame] | 1042 | if (src_cnt + dmaf_p_disabled_continue(flags) > 3 || |
| 1043 | (dmaf_continue(flags) && !dmaf_p_disabled_continue(flags))) { |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 1044 | with_ext = 1; |
| 1045 | num_descs *= 2; |
| 1046 | } else |
| 1047 | with_ext = 0; |
| 1048 | |
| 1049 | /* completion writes from the raid engine may pass completion |
| 1050 | * writes from the legacy engine, so we need one extra null |
| 1051 | * (legacy) descriptor to ensure all completion writes arrive in |
| 1052 | * order. |
| 1053 | */ |
| 1054 | if (likely(num_descs) && |
Dave Jiang | e088477 | 2013-04-10 16:44:20 -0700 | [diff] [blame] | 1055 | ioat2_check_space_lock(ioat, num_descs + cb32) == 0) |
Dan Williams | 074cc47 | 2010-05-01 15:22:55 -0700 | [diff] [blame] | 1056 | idx = ioat->head; |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 1057 | else |
| 1058 | return NULL; |
Dan Williams | cdef57d | 2009-09-21 09:22:29 -0700 | [diff] [blame] | 1059 | i = 0; |
| 1060 | do { |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 1061 | struct ioat_raw_descriptor *descs[2]; |
| 1062 | size_t xfer_size = min_t(size_t, len, 1 << ioat->xfercap_log); |
| 1063 | |
| 1064 | desc = ioat2_get_ring_ent(ioat, idx + i); |
| 1065 | pq = desc->pq; |
| 1066 | |
| 1067 | /* save a branch by unconditionally retrieving the |
| 1068 | * extended descriptor pq_set_src() knows to not write |
| 1069 | * to it in the single descriptor case |
| 1070 | */ |
| 1071 | ext = ioat2_get_ring_ent(ioat, idx + i + with_ext); |
| 1072 | pq_ex = ext->pq_ex; |
| 1073 | |
| 1074 | descs[0] = (struct ioat_raw_descriptor *) pq; |
| 1075 | descs[1] = (struct ioat_raw_descriptor *) pq_ex; |
| 1076 | |
| 1077 | for (s = 0; s < src_cnt; s++) |
| 1078 | pq_set_src(descs, src[s], offset, scf[s], s); |
| 1079 | |
| 1080 | /* see the comment for dma_maxpq in include/linux/dmaengine.h */ |
| 1081 | if (dmaf_p_disabled_continue(flags)) |
| 1082 | pq_set_src(descs, dst[1], offset, 1, s++); |
| 1083 | else if (dmaf_continue(flags)) { |
| 1084 | pq_set_src(descs, dst[0], offset, 0, s++); |
| 1085 | pq_set_src(descs, dst[1], offset, 1, s++); |
| 1086 | pq_set_src(descs, dst[1], offset, 0, s++); |
| 1087 | } |
| 1088 | pq->size = xfer_size; |
| 1089 | pq->p_addr = dst[0] + offset; |
| 1090 | pq->q_addr = dst[1] + offset; |
| 1091 | pq->ctl = 0; |
| 1092 | pq->ctl_f.op = op; |
| 1093 | pq->ctl_f.src_cnt = src_cnt_to_hw(s); |
| 1094 | pq->ctl_f.p_disable = !!(flags & DMA_PREP_PQ_DISABLE_P); |
| 1095 | pq->ctl_f.q_disable = !!(flags & DMA_PREP_PQ_DISABLE_Q); |
| 1096 | |
| 1097 | len -= xfer_size; |
| 1098 | offset += xfer_size; |
Dan Williams | cdef57d | 2009-09-21 09:22:29 -0700 | [diff] [blame] | 1099 | } while ((i += 1 + with_ext) < num_descs); |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 1100 | |
| 1101 | /* last pq descriptor carries the unmap parameters and fence bit */ |
| 1102 | desc->txd.flags = flags; |
| 1103 | desc->len = total_len; |
| 1104 | if (result) |
| 1105 | desc->result = result; |
| 1106 | pq->ctl_f.fence = !!(flags & DMA_PREP_FENCE); |
| 1107 | dump_pq_desc_dbg(ioat, desc, ext); |
| 1108 | |
Dave Jiang | e088477 | 2013-04-10 16:44:20 -0700 | [diff] [blame] | 1109 | if (!cb32) { |
| 1110 | pq->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT); |
| 1111 | pq->ctl_f.compl_write = 1; |
| 1112 | compl_desc = desc; |
| 1113 | } else { |
| 1114 | /* completion descriptor carries interrupt bit */ |
| 1115 | compl_desc = ioat2_get_ring_ent(ioat, idx + i); |
| 1116 | compl_desc->txd.flags = flags & DMA_PREP_INTERRUPT; |
| 1117 | hw = compl_desc->hw; |
| 1118 | hw->ctl = 0; |
| 1119 | hw->ctl_f.null = 1; |
| 1120 | hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT); |
| 1121 | hw->ctl_f.compl_write = 1; |
| 1122 | hw->size = NULL_DESC_BUFFER_SIZE; |
| 1123 | dump_desc_dbg(ioat, compl_desc); |
| 1124 | } |
| 1125 | |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 1126 | |
| 1127 | /* we leave the channel locked to ensure in order submission */ |
Dan Williams | 49954c1 | 2009-11-19 17:11:03 -0700 | [diff] [blame] | 1128 | return &compl_desc->txd; |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | static struct dma_async_tx_descriptor * |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 1132 | __ioat3_prep_pq16_lock(struct dma_chan *c, enum sum_check_flags *result, |
| 1133 | const dma_addr_t *dst, const dma_addr_t *src, |
| 1134 | unsigned int src_cnt, const unsigned char *scf, |
| 1135 | size_t len, unsigned long flags) |
| 1136 | { |
| 1137 | struct ioat2_dma_chan *ioat = to_ioat2_chan(c); |
| 1138 | struct ioat_chan_common *chan = &ioat->base; |
| 1139 | struct ioatdma_device *device = chan->device; |
| 1140 | struct ioat_ring_ent *desc; |
| 1141 | size_t total_len = len; |
| 1142 | struct ioat_pq_descriptor *pq; |
| 1143 | u32 offset = 0; |
| 1144 | u8 op; |
| 1145 | int i, s, idx, num_descs; |
| 1146 | |
| 1147 | /* this function only handles src_cnt 9 - 16 */ |
| 1148 | BUG_ON(src_cnt < 9); |
| 1149 | |
| 1150 | /* this function is only called with 9-16 sources */ |
| 1151 | op = result ? IOAT_OP_PQ_VAL_16S : IOAT_OP_PQ_16S; |
| 1152 | |
| 1153 | dev_dbg(to_dev(chan), "%s\n", __func__); |
| 1154 | |
| 1155 | num_descs = ioat2_xferlen_to_descs(ioat, len); |
| 1156 | |
| 1157 | /* |
| 1158 | * 16 source pq is only available on cb3.3 and has no completion |
| 1159 | * write hw bug. |
| 1160 | */ |
| 1161 | if (num_descs && ioat2_check_space_lock(ioat, num_descs) == 0) |
| 1162 | idx = ioat->head; |
| 1163 | else |
| 1164 | return NULL; |
| 1165 | |
| 1166 | i = 0; |
| 1167 | |
| 1168 | do { |
| 1169 | struct ioat_raw_descriptor *descs[4]; |
| 1170 | size_t xfer_size = min_t(size_t, len, 1 << ioat->xfercap_log); |
| 1171 | |
| 1172 | desc = ioat2_get_ring_ent(ioat, idx + i); |
| 1173 | pq = desc->pq; |
| 1174 | |
| 1175 | descs[0] = (struct ioat_raw_descriptor *) pq; |
| 1176 | |
| 1177 | desc->sed = ioat3_alloc_sed(device, |
| 1178 | sed_get_pq16_pool_idx(src_cnt)); |
| 1179 | if (!desc->sed) { |
| 1180 | dev_err(to_dev(chan), |
| 1181 | "%s: no free sed entries\n", __func__); |
| 1182 | return NULL; |
| 1183 | } |
| 1184 | |
| 1185 | pq->sed_addr = desc->sed->dma; |
| 1186 | desc->sed->parent = desc; |
| 1187 | |
| 1188 | descs[1] = (struct ioat_raw_descriptor *)desc->sed->hw; |
| 1189 | descs[2] = (void *)descs[1] + 64; |
| 1190 | |
| 1191 | for (s = 0; s < src_cnt; s++) |
| 1192 | pq16_set_src(descs, src[s], offset, scf[s], s); |
| 1193 | |
| 1194 | /* see the comment for dma_maxpq in include/linux/dmaengine.h */ |
| 1195 | if (dmaf_p_disabled_continue(flags)) |
| 1196 | pq16_set_src(descs, dst[1], offset, 1, s++); |
| 1197 | else if (dmaf_continue(flags)) { |
| 1198 | pq16_set_src(descs, dst[0], offset, 0, s++); |
| 1199 | pq16_set_src(descs, dst[1], offset, 1, s++); |
| 1200 | pq16_set_src(descs, dst[1], offset, 0, s++); |
| 1201 | } |
| 1202 | |
| 1203 | pq->size = xfer_size; |
| 1204 | pq->p_addr = dst[0] + offset; |
| 1205 | pq->q_addr = dst[1] + offset; |
| 1206 | pq->ctl = 0; |
| 1207 | pq->ctl_f.op = op; |
| 1208 | pq->ctl_f.src_cnt = src16_cnt_to_hw(s); |
| 1209 | pq->ctl_f.p_disable = !!(flags & DMA_PREP_PQ_DISABLE_P); |
| 1210 | pq->ctl_f.q_disable = !!(flags & DMA_PREP_PQ_DISABLE_Q); |
| 1211 | |
| 1212 | len -= xfer_size; |
| 1213 | offset += xfer_size; |
| 1214 | } while (++i < num_descs); |
| 1215 | |
| 1216 | /* last pq descriptor carries the unmap parameters and fence bit */ |
| 1217 | desc->txd.flags = flags; |
| 1218 | desc->len = total_len; |
| 1219 | if (result) |
| 1220 | desc->result = result; |
| 1221 | pq->ctl_f.fence = !!(flags & DMA_PREP_FENCE); |
| 1222 | |
| 1223 | /* with cb3.3 we should be able to do completion w/o a null desc */ |
| 1224 | pq->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT); |
| 1225 | pq->ctl_f.compl_write = 1; |
| 1226 | |
| 1227 | dump_pq16_desc_dbg(ioat, desc); |
| 1228 | |
| 1229 | /* we leave the channel locked to ensure in order submission */ |
| 1230 | return &desc->txd; |
| 1231 | } |
| 1232 | |
| 1233 | static struct dma_async_tx_descriptor * |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 1234 | ioat3_prep_pq(struct dma_chan *chan, dma_addr_t *dst, dma_addr_t *src, |
| 1235 | unsigned int src_cnt, const unsigned char *scf, size_t len, |
| 1236 | unsigned long flags) |
| 1237 | { |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 1238 | struct dma_device *dma = chan->device; |
| 1239 | |
Dan Williams | de581b6 | 2009-11-19 17:08:45 -0700 | [diff] [blame] | 1240 | /* specify valid address for disabled result */ |
| 1241 | if (flags & DMA_PREP_PQ_DISABLE_P) |
| 1242 | dst[0] = dst[1]; |
| 1243 | if (flags & DMA_PREP_PQ_DISABLE_Q) |
| 1244 | dst[1] = dst[0]; |
| 1245 | |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 1246 | /* handle the single source multiply case from the raid6 |
| 1247 | * recovery path |
| 1248 | */ |
Dan Williams | de581b6 | 2009-11-19 17:08:45 -0700 | [diff] [blame] | 1249 | if ((flags & DMA_PREP_PQ_DISABLE_P) && src_cnt == 1) { |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 1250 | dma_addr_t single_source[2]; |
| 1251 | unsigned char single_source_coef[2]; |
| 1252 | |
| 1253 | BUG_ON(flags & DMA_PREP_PQ_DISABLE_Q); |
| 1254 | single_source[0] = src[0]; |
| 1255 | single_source[1] = src[0]; |
| 1256 | single_source_coef[0] = scf[0]; |
| 1257 | single_source_coef[1] = 0; |
| 1258 | |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 1259 | return (src_cnt > 8) && (dma->max_pq > 8) ? |
| 1260 | __ioat3_prep_pq16_lock(chan, NULL, dst, single_source, |
| 1261 | 2, single_source_coef, len, |
| 1262 | flags) : |
| 1263 | __ioat3_prep_pq_lock(chan, NULL, dst, single_source, 2, |
| 1264 | single_source_coef, len, flags); |
| 1265 | |
| 1266 | } else { |
| 1267 | return (src_cnt > 8) && (dma->max_pq > 8) ? |
| 1268 | __ioat3_prep_pq16_lock(chan, NULL, dst, src, src_cnt, |
| 1269 | scf, len, flags) : |
| 1270 | __ioat3_prep_pq_lock(chan, NULL, dst, src, src_cnt, |
| 1271 | scf, len, flags); |
| 1272 | } |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | struct dma_async_tx_descriptor * |
| 1276 | ioat3_prep_pq_val(struct dma_chan *chan, dma_addr_t *pq, dma_addr_t *src, |
| 1277 | unsigned int src_cnt, const unsigned char *scf, size_t len, |
| 1278 | enum sum_check_flags *pqres, unsigned long flags) |
| 1279 | { |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 1280 | struct dma_device *dma = chan->device; |
| 1281 | |
Dan Williams | de581b6 | 2009-11-19 17:08:45 -0700 | [diff] [blame] | 1282 | /* specify valid address for disabled result */ |
| 1283 | if (flags & DMA_PREP_PQ_DISABLE_P) |
| 1284 | pq[0] = pq[1]; |
| 1285 | if (flags & DMA_PREP_PQ_DISABLE_Q) |
| 1286 | pq[1] = pq[0]; |
| 1287 | |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 1288 | /* the cleanup routine only sets bits on validate failure, it |
| 1289 | * does not clear bits on validate success... so clear it here |
| 1290 | */ |
| 1291 | *pqres = 0; |
| 1292 | |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 1293 | return (src_cnt > 8) && (dma->max_pq > 8) ? |
| 1294 | __ioat3_prep_pq16_lock(chan, pqres, pq, src, src_cnt, scf, len, |
| 1295 | flags) : |
| 1296 | __ioat3_prep_pq_lock(chan, pqres, pq, src, src_cnt, scf, len, |
| 1297 | flags); |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 1298 | } |
| 1299 | |
Dan Williams | ae78662 | 2009-09-08 17:43:00 -0700 | [diff] [blame] | 1300 | static struct dma_async_tx_descriptor * |
| 1301 | ioat3_prep_pqxor(struct dma_chan *chan, dma_addr_t dst, dma_addr_t *src, |
| 1302 | unsigned int src_cnt, size_t len, unsigned long flags) |
| 1303 | { |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 1304 | struct dma_device *dma = chan->device; |
Dan Williams | ae78662 | 2009-09-08 17:43:00 -0700 | [diff] [blame] | 1305 | unsigned char scf[src_cnt]; |
| 1306 | dma_addr_t pq[2]; |
| 1307 | |
| 1308 | memset(scf, 0, src_cnt); |
Dan Williams | ae78662 | 2009-09-08 17:43:00 -0700 | [diff] [blame] | 1309 | pq[0] = dst; |
Dan Williams | de581b6 | 2009-11-19 17:08:45 -0700 | [diff] [blame] | 1310 | flags |= DMA_PREP_PQ_DISABLE_Q; |
| 1311 | pq[1] = dst; /* specify valid address for disabled result */ |
Dan Williams | ae78662 | 2009-09-08 17:43:00 -0700 | [diff] [blame] | 1312 | |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 1313 | return (src_cnt > 8) && (dma->max_pq > 8) ? |
| 1314 | __ioat3_prep_pq16_lock(chan, NULL, pq, src, src_cnt, scf, len, |
| 1315 | flags) : |
| 1316 | __ioat3_prep_pq_lock(chan, NULL, pq, src, src_cnt, scf, len, |
| 1317 | flags); |
Dan Williams | ae78662 | 2009-09-08 17:43:00 -0700 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | struct dma_async_tx_descriptor * |
| 1321 | ioat3_prep_pqxor_val(struct dma_chan *chan, dma_addr_t *src, |
| 1322 | unsigned int src_cnt, size_t len, |
| 1323 | enum sum_check_flags *result, unsigned long flags) |
| 1324 | { |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 1325 | struct dma_device *dma = chan->device; |
Dan Williams | ae78662 | 2009-09-08 17:43:00 -0700 | [diff] [blame] | 1326 | unsigned char scf[src_cnt]; |
| 1327 | dma_addr_t pq[2]; |
| 1328 | |
| 1329 | /* the cleanup routine only sets bits on validate failure, it |
| 1330 | * does not clear bits on validate success... so clear it here |
| 1331 | */ |
| 1332 | *result = 0; |
| 1333 | |
| 1334 | memset(scf, 0, src_cnt); |
Dan Williams | ae78662 | 2009-09-08 17:43:00 -0700 | [diff] [blame] | 1335 | pq[0] = src[0]; |
Dan Williams | de581b6 | 2009-11-19 17:08:45 -0700 | [diff] [blame] | 1336 | flags |= DMA_PREP_PQ_DISABLE_Q; |
| 1337 | pq[1] = pq[0]; /* specify valid address for disabled result */ |
Dan Williams | ae78662 | 2009-09-08 17:43:00 -0700 | [diff] [blame] | 1338 | |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 1339 | |
| 1340 | return (src_cnt > 8) && (dma->max_pq > 8) ? |
| 1341 | __ioat3_prep_pq16_lock(chan, result, pq, &src[1], src_cnt - 1, |
| 1342 | scf, len, flags) : |
| 1343 | __ioat3_prep_pq_lock(chan, result, pq, &src[1], src_cnt - 1, |
| 1344 | scf, len, flags); |
Dan Williams | ae78662 | 2009-09-08 17:43:00 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
Dan Williams | 58c8649 | 2009-09-08 17:43:00 -0700 | [diff] [blame] | 1347 | static struct dma_async_tx_descriptor * |
| 1348 | ioat3_prep_interrupt_lock(struct dma_chan *c, unsigned long flags) |
| 1349 | { |
| 1350 | struct ioat2_dma_chan *ioat = to_ioat2_chan(c); |
| 1351 | struct ioat_ring_ent *desc; |
| 1352 | struct ioat_dma_descriptor *hw; |
Dan Williams | 58c8649 | 2009-09-08 17:43:00 -0700 | [diff] [blame] | 1353 | |
Dan Williams | 074cc47 | 2010-05-01 15:22:55 -0700 | [diff] [blame] | 1354 | if (ioat2_check_space_lock(ioat, 1) == 0) |
| 1355 | desc = ioat2_get_ring_ent(ioat, ioat->head); |
Dan Williams | 58c8649 | 2009-09-08 17:43:00 -0700 | [diff] [blame] | 1356 | else |
| 1357 | return NULL; |
| 1358 | |
| 1359 | hw = desc->hw; |
| 1360 | hw->ctl = 0; |
| 1361 | hw->ctl_f.null = 1; |
| 1362 | hw->ctl_f.int_en = 1; |
| 1363 | hw->ctl_f.fence = !!(flags & DMA_PREP_FENCE); |
| 1364 | hw->ctl_f.compl_write = 1; |
| 1365 | hw->size = NULL_DESC_BUFFER_SIZE; |
| 1366 | hw->src_addr = 0; |
| 1367 | hw->dst_addr = 0; |
| 1368 | |
| 1369 | desc->txd.flags = flags; |
| 1370 | desc->len = 1; |
| 1371 | |
| 1372 | dump_desc_dbg(ioat, desc); |
| 1373 | |
| 1374 | /* we leave the channel locked to ensure in order submission */ |
| 1375 | return &desc->txd; |
| 1376 | } |
| 1377 | |
Greg Kroah-Hartman | 4bf27b8 | 2012-12-21 15:09:59 -0800 | [diff] [blame] | 1378 | static void ioat3_dma_test_callback(void *dma_async_param) |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1379 | { |
| 1380 | struct completion *cmp = dma_async_param; |
| 1381 | |
| 1382 | complete(cmp); |
| 1383 | } |
| 1384 | |
| 1385 | #define IOAT_NUM_SRC_TEST 6 /* must be <= 8 */ |
Greg Kroah-Hartman | 4bf27b8 | 2012-12-21 15:09:59 -0800 | [diff] [blame] | 1386 | static int ioat_xor_val_self_test(struct ioatdma_device *device) |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1387 | { |
| 1388 | int i, src_idx; |
| 1389 | struct page *dest; |
| 1390 | struct page *xor_srcs[IOAT_NUM_SRC_TEST]; |
| 1391 | struct page *xor_val_srcs[IOAT_NUM_SRC_TEST + 1]; |
| 1392 | dma_addr_t dma_srcs[IOAT_NUM_SRC_TEST + 1]; |
| 1393 | dma_addr_t dma_addr, dest_dma; |
| 1394 | struct dma_async_tx_descriptor *tx; |
| 1395 | struct dma_chan *dma_chan; |
| 1396 | dma_cookie_t cookie; |
| 1397 | u8 cmp_byte = 0; |
| 1398 | u32 cmp_word; |
| 1399 | u32 xor_val_result; |
| 1400 | int err = 0; |
| 1401 | struct completion cmp; |
| 1402 | unsigned long tmo; |
| 1403 | struct device *dev = &device->pdev->dev; |
| 1404 | struct dma_device *dma = &device->common; |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1405 | u8 op = 0; |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1406 | |
| 1407 | dev_dbg(dev, "%s\n", __func__); |
| 1408 | |
| 1409 | if (!dma_has_cap(DMA_XOR, dma->cap_mask)) |
| 1410 | return 0; |
| 1411 | |
| 1412 | for (src_idx = 0; src_idx < IOAT_NUM_SRC_TEST; src_idx++) { |
| 1413 | xor_srcs[src_idx] = alloc_page(GFP_KERNEL); |
| 1414 | if (!xor_srcs[src_idx]) { |
| 1415 | while (src_idx--) |
| 1416 | __free_page(xor_srcs[src_idx]); |
| 1417 | return -ENOMEM; |
| 1418 | } |
| 1419 | } |
| 1420 | |
| 1421 | dest = alloc_page(GFP_KERNEL); |
| 1422 | if (!dest) { |
| 1423 | while (src_idx--) |
| 1424 | __free_page(xor_srcs[src_idx]); |
| 1425 | return -ENOMEM; |
| 1426 | } |
| 1427 | |
| 1428 | /* Fill in src buffers */ |
| 1429 | for (src_idx = 0; src_idx < IOAT_NUM_SRC_TEST; src_idx++) { |
| 1430 | u8 *ptr = page_address(xor_srcs[src_idx]); |
| 1431 | for (i = 0; i < PAGE_SIZE; i++) |
| 1432 | ptr[i] = (1 << src_idx); |
| 1433 | } |
| 1434 | |
| 1435 | for (src_idx = 0; src_idx < IOAT_NUM_SRC_TEST; src_idx++) |
| 1436 | cmp_byte ^= (u8) (1 << src_idx); |
| 1437 | |
| 1438 | cmp_word = (cmp_byte << 24) | (cmp_byte << 16) | |
| 1439 | (cmp_byte << 8) | cmp_byte; |
| 1440 | |
| 1441 | memset(page_address(dest), 0, PAGE_SIZE); |
| 1442 | |
| 1443 | dma_chan = container_of(dma->channels.next, struct dma_chan, |
| 1444 | device_node); |
| 1445 | if (dma->device_alloc_chan_resources(dma_chan) < 1) { |
| 1446 | err = -ENODEV; |
| 1447 | goto out; |
| 1448 | } |
| 1449 | |
| 1450 | /* test xor */ |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1451 | op = IOAT_OP_XOR; |
| 1452 | |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1453 | dest_dma = dma_map_page(dev, dest, 0, PAGE_SIZE, DMA_FROM_DEVICE); |
| 1454 | for (i = 0; i < IOAT_NUM_SRC_TEST; i++) |
| 1455 | dma_srcs[i] = dma_map_page(dev, xor_srcs[i], 0, PAGE_SIZE, |
| 1456 | DMA_TO_DEVICE); |
| 1457 | tx = dma->device_prep_dma_xor(dma_chan, dest_dma, dma_srcs, |
| 1458 | IOAT_NUM_SRC_TEST, PAGE_SIZE, |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1459 | DMA_PREP_INTERRUPT | |
| 1460 | DMA_COMPL_SKIP_SRC_UNMAP | |
| 1461 | DMA_COMPL_SKIP_DEST_UNMAP); |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1462 | |
| 1463 | if (!tx) { |
| 1464 | dev_err(dev, "Self-test xor prep failed\n"); |
| 1465 | err = -ENODEV; |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1466 | goto dma_unmap; |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | async_tx_ack(tx); |
| 1470 | init_completion(&cmp); |
| 1471 | tx->callback = ioat3_dma_test_callback; |
| 1472 | tx->callback_param = &cmp; |
| 1473 | cookie = tx->tx_submit(tx); |
| 1474 | if (cookie < 0) { |
| 1475 | dev_err(dev, "Self-test xor setup failed\n"); |
| 1476 | err = -ENODEV; |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1477 | goto dma_unmap; |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1478 | } |
| 1479 | dma->device_issue_pending(dma_chan); |
| 1480 | |
| 1481 | tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000)); |
| 1482 | |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 1483 | if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_SUCCESS) { |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1484 | dev_err(dev, "Self-test xor timed out\n"); |
| 1485 | err = -ENODEV; |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1486 | goto dma_unmap; |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1487 | } |
| 1488 | |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1489 | dma_unmap_page(dev, dest_dma, PAGE_SIZE, DMA_FROM_DEVICE); |
| 1490 | for (i = 0; i < IOAT_NUM_SRC_TEST; i++) |
| 1491 | dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE, DMA_TO_DEVICE); |
| 1492 | |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1493 | dma_sync_single_for_cpu(dev, dest_dma, PAGE_SIZE, DMA_FROM_DEVICE); |
| 1494 | for (i = 0; i < (PAGE_SIZE / sizeof(u32)); i++) { |
| 1495 | u32 *ptr = page_address(dest); |
| 1496 | if (ptr[i] != cmp_word) { |
| 1497 | dev_err(dev, "Self-test xor failed compare\n"); |
| 1498 | err = -ENODEV; |
| 1499 | goto free_resources; |
| 1500 | } |
| 1501 | } |
Shuah Khan | ac49898 | 2012-10-25 10:22:32 -0600 | [diff] [blame] | 1502 | dma_sync_single_for_device(dev, dest_dma, PAGE_SIZE, DMA_FROM_DEVICE); |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1503 | |
| 1504 | /* skip validate if the capability is not present */ |
| 1505 | if (!dma_has_cap(DMA_XOR_VAL, dma_chan->device->cap_mask)) |
| 1506 | goto free_resources; |
| 1507 | |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1508 | op = IOAT_OP_XOR_VAL; |
| 1509 | |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1510 | /* validate the sources with the destintation page */ |
| 1511 | for (i = 0; i < IOAT_NUM_SRC_TEST; i++) |
| 1512 | xor_val_srcs[i] = xor_srcs[i]; |
| 1513 | xor_val_srcs[i] = dest; |
| 1514 | |
| 1515 | xor_val_result = 1; |
| 1516 | |
| 1517 | for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++) |
| 1518 | dma_srcs[i] = dma_map_page(dev, xor_val_srcs[i], 0, PAGE_SIZE, |
| 1519 | DMA_TO_DEVICE); |
| 1520 | tx = dma->device_prep_dma_xor_val(dma_chan, dma_srcs, |
| 1521 | IOAT_NUM_SRC_TEST + 1, PAGE_SIZE, |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1522 | &xor_val_result, DMA_PREP_INTERRUPT | |
| 1523 | DMA_COMPL_SKIP_SRC_UNMAP | |
| 1524 | DMA_COMPL_SKIP_DEST_UNMAP); |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1525 | if (!tx) { |
| 1526 | dev_err(dev, "Self-test zero prep failed\n"); |
| 1527 | err = -ENODEV; |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1528 | goto dma_unmap; |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | async_tx_ack(tx); |
| 1532 | init_completion(&cmp); |
| 1533 | tx->callback = ioat3_dma_test_callback; |
| 1534 | tx->callback_param = &cmp; |
| 1535 | cookie = tx->tx_submit(tx); |
| 1536 | if (cookie < 0) { |
| 1537 | dev_err(dev, "Self-test zero setup failed\n"); |
| 1538 | err = -ENODEV; |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1539 | goto dma_unmap; |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1540 | } |
| 1541 | dma->device_issue_pending(dma_chan); |
| 1542 | |
| 1543 | tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000)); |
| 1544 | |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 1545 | if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_SUCCESS) { |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1546 | dev_err(dev, "Self-test validate timed out\n"); |
| 1547 | err = -ENODEV; |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1548 | goto dma_unmap; |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1549 | } |
| 1550 | |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1551 | for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++) |
| 1552 | dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE, DMA_TO_DEVICE); |
| 1553 | |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1554 | if (xor_val_result != 0) { |
| 1555 | dev_err(dev, "Self-test validate failed compare\n"); |
| 1556 | err = -ENODEV; |
| 1557 | goto free_resources; |
| 1558 | } |
| 1559 | |
| 1560 | /* skip memset if the capability is not present */ |
| 1561 | if (!dma_has_cap(DMA_MEMSET, dma_chan->device->cap_mask)) |
| 1562 | goto free_resources; |
| 1563 | |
| 1564 | /* test memset */ |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1565 | op = IOAT_OP_FILL; |
| 1566 | |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1567 | dma_addr = dma_map_page(dev, dest, 0, |
| 1568 | PAGE_SIZE, DMA_FROM_DEVICE); |
| 1569 | tx = dma->device_prep_dma_memset(dma_chan, dma_addr, 0, PAGE_SIZE, |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1570 | DMA_PREP_INTERRUPT | |
| 1571 | DMA_COMPL_SKIP_SRC_UNMAP | |
| 1572 | DMA_COMPL_SKIP_DEST_UNMAP); |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1573 | if (!tx) { |
| 1574 | dev_err(dev, "Self-test memset prep failed\n"); |
| 1575 | err = -ENODEV; |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1576 | goto dma_unmap; |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | async_tx_ack(tx); |
| 1580 | init_completion(&cmp); |
| 1581 | tx->callback = ioat3_dma_test_callback; |
| 1582 | tx->callback_param = &cmp; |
| 1583 | cookie = tx->tx_submit(tx); |
| 1584 | if (cookie < 0) { |
| 1585 | dev_err(dev, "Self-test memset setup failed\n"); |
| 1586 | err = -ENODEV; |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1587 | goto dma_unmap; |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1588 | } |
| 1589 | dma->device_issue_pending(dma_chan); |
| 1590 | |
| 1591 | tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000)); |
| 1592 | |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 1593 | if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_SUCCESS) { |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1594 | dev_err(dev, "Self-test memset timed out\n"); |
| 1595 | err = -ENODEV; |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1596 | goto dma_unmap; |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1597 | } |
| 1598 | |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1599 | dma_unmap_page(dev, dma_addr, PAGE_SIZE, DMA_FROM_DEVICE); |
| 1600 | |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1601 | for (i = 0; i < PAGE_SIZE/sizeof(u32); i++) { |
| 1602 | u32 *ptr = page_address(dest); |
| 1603 | if (ptr[i]) { |
| 1604 | dev_err(dev, "Self-test memset failed compare\n"); |
| 1605 | err = -ENODEV; |
| 1606 | goto free_resources; |
| 1607 | } |
| 1608 | } |
| 1609 | |
| 1610 | /* test for non-zero parity sum */ |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1611 | op = IOAT_OP_XOR_VAL; |
| 1612 | |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1613 | xor_val_result = 0; |
| 1614 | for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++) |
| 1615 | dma_srcs[i] = dma_map_page(dev, xor_val_srcs[i], 0, PAGE_SIZE, |
| 1616 | DMA_TO_DEVICE); |
| 1617 | tx = dma->device_prep_dma_xor_val(dma_chan, dma_srcs, |
| 1618 | IOAT_NUM_SRC_TEST + 1, PAGE_SIZE, |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1619 | &xor_val_result, DMA_PREP_INTERRUPT | |
| 1620 | DMA_COMPL_SKIP_SRC_UNMAP | |
| 1621 | DMA_COMPL_SKIP_DEST_UNMAP); |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1622 | if (!tx) { |
| 1623 | dev_err(dev, "Self-test 2nd zero prep failed\n"); |
| 1624 | err = -ENODEV; |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1625 | goto dma_unmap; |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | async_tx_ack(tx); |
| 1629 | init_completion(&cmp); |
| 1630 | tx->callback = ioat3_dma_test_callback; |
| 1631 | tx->callback_param = &cmp; |
| 1632 | cookie = tx->tx_submit(tx); |
| 1633 | if (cookie < 0) { |
| 1634 | dev_err(dev, "Self-test 2nd zero setup failed\n"); |
| 1635 | err = -ENODEV; |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1636 | goto dma_unmap; |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1637 | } |
| 1638 | dma->device_issue_pending(dma_chan); |
| 1639 | |
| 1640 | tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000)); |
| 1641 | |
Linus Walleij | 0793448 | 2010-03-26 16:50:49 -0700 | [diff] [blame] | 1642 | if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_SUCCESS) { |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1643 | dev_err(dev, "Self-test 2nd validate timed out\n"); |
| 1644 | err = -ENODEV; |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1645 | goto dma_unmap; |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1646 | } |
| 1647 | |
| 1648 | if (xor_val_result != SUM_CHECK_P_RESULT) { |
| 1649 | dev_err(dev, "Self-test validate failed compare\n"); |
| 1650 | err = -ENODEV; |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1651 | goto dma_unmap; |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1652 | } |
| 1653 | |
Bartlomiej Zolnierkiewicz | 7369f56 | 2012-11-05 10:00:19 +0000 | [diff] [blame] | 1654 | for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++) |
| 1655 | dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE, DMA_TO_DEVICE); |
| 1656 | |
| 1657 | goto free_resources; |
| 1658 | dma_unmap: |
| 1659 | if (op == IOAT_OP_XOR) { |
| 1660 | dma_unmap_page(dev, dest_dma, PAGE_SIZE, DMA_FROM_DEVICE); |
| 1661 | for (i = 0; i < IOAT_NUM_SRC_TEST; i++) |
| 1662 | dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE, |
| 1663 | DMA_TO_DEVICE); |
| 1664 | } else if (op == IOAT_OP_XOR_VAL) { |
| 1665 | for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++) |
| 1666 | dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE, |
| 1667 | DMA_TO_DEVICE); |
| 1668 | } else if (op == IOAT_OP_FILL) |
| 1669 | dma_unmap_page(dev, dma_addr, PAGE_SIZE, DMA_FROM_DEVICE); |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1670 | free_resources: |
| 1671 | dma->device_free_chan_resources(dma_chan); |
| 1672 | out: |
| 1673 | src_idx = IOAT_NUM_SRC_TEST; |
| 1674 | while (src_idx--) |
| 1675 | __free_page(xor_srcs[src_idx]); |
| 1676 | __free_page(dest); |
| 1677 | return err; |
| 1678 | } |
| 1679 | |
Greg Kroah-Hartman | 4bf27b8 | 2012-12-21 15:09:59 -0800 | [diff] [blame] | 1680 | static int ioat3_dma_self_test(struct ioatdma_device *device) |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1681 | { |
| 1682 | int rc = ioat_dma_self_test(device); |
| 1683 | |
| 1684 | if (rc) |
| 1685 | return rc; |
| 1686 | |
| 1687 | rc = ioat_xor_val_self_test(device); |
| 1688 | if (rc) |
| 1689 | return rc; |
| 1690 | |
| 1691 | return 0; |
| 1692 | } |
| 1693 | |
Dave Jiang | 8a52b9f | 2013-03-26 15:42:47 -0700 | [diff] [blame] | 1694 | static int ioat3_irq_reinit(struct ioatdma_device *device) |
| 1695 | { |
| 1696 | int msixcnt = device->common.chancnt; |
| 1697 | struct pci_dev *pdev = device->pdev; |
| 1698 | int i; |
| 1699 | struct msix_entry *msix; |
| 1700 | struct ioat_chan_common *chan; |
| 1701 | int err = 0; |
| 1702 | |
| 1703 | switch (device->irq_mode) { |
| 1704 | case IOAT_MSIX: |
| 1705 | |
| 1706 | for (i = 0; i < msixcnt; i++) { |
| 1707 | msix = &device->msix_entries[i]; |
| 1708 | chan = ioat_chan_by_index(device, i); |
| 1709 | devm_free_irq(&pdev->dev, msix->vector, chan); |
| 1710 | } |
| 1711 | |
| 1712 | pci_disable_msix(pdev); |
| 1713 | break; |
| 1714 | |
| 1715 | case IOAT_MSIX_SINGLE: |
| 1716 | msix = &device->msix_entries[0]; |
| 1717 | chan = ioat_chan_by_index(device, 0); |
| 1718 | devm_free_irq(&pdev->dev, msix->vector, chan); |
| 1719 | pci_disable_msix(pdev); |
| 1720 | break; |
| 1721 | |
| 1722 | case IOAT_MSI: |
| 1723 | chan = ioat_chan_by_index(device, 0); |
| 1724 | devm_free_irq(&pdev->dev, pdev->irq, chan); |
| 1725 | pci_disable_msi(pdev); |
| 1726 | break; |
| 1727 | |
| 1728 | case IOAT_INTX: |
| 1729 | chan = ioat_chan_by_index(device, 0); |
| 1730 | devm_free_irq(&pdev->dev, pdev->irq, chan); |
| 1731 | break; |
| 1732 | |
| 1733 | default: |
| 1734 | return 0; |
| 1735 | } |
| 1736 | |
| 1737 | device->irq_mode = IOAT_NOIRQ; |
| 1738 | |
| 1739 | err = ioat_dma_setup_interrupts(device); |
| 1740 | |
| 1741 | return err; |
| 1742 | } |
| 1743 | |
Dan Williams | a6d52d7 | 2009-12-19 15:36:02 -0700 | [diff] [blame] | 1744 | static int ioat3_reset_hw(struct ioat_chan_common *chan) |
| 1745 | { |
| 1746 | /* throw away whatever the channel was doing and get it |
| 1747 | * initialized, with ioat3 specific workarounds |
| 1748 | */ |
| 1749 | struct ioatdma_device *device = chan->device; |
| 1750 | struct pci_dev *pdev = device->pdev; |
| 1751 | u32 chanerr; |
| 1752 | u16 dev_id; |
| 1753 | int err; |
| 1754 | |
| 1755 | ioat2_quiesce(chan, msecs_to_jiffies(100)); |
| 1756 | |
| 1757 | chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET); |
| 1758 | writel(chanerr, chan->reg_base + IOAT_CHANERR_OFFSET); |
| 1759 | |
Dave Jiang | 6ead7e4 | 2013-03-26 15:42:59 -0700 | [diff] [blame] | 1760 | if (device->version < IOAT_VER_3_3) { |
| 1761 | /* clear any pending errors */ |
| 1762 | err = pci_read_config_dword(pdev, |
| 1763 | IOAT_PCI_CHANERR_INT_OFFSET, &chanerr); |
| 1764 | if (err) { |
| 1765 | dev_err(&pdev->dev, |
| 1766 | "channel error register unreachable\n"); |
| 1767 | return err; |
| 1768 | } |
| 1769 | pci_write_config_dword(pdev, |
| 1770 | IOAT_PCI_CHANERR_INT_OFFSET, chanerr); |
Dan Williams | a6d52d7 | 2009-12-19 15:36:02 -0700 | [diff] [blame] | 1771 | |
Dave Jiang | 6ead7e4 | 2013-03-26 15:42:59 -0700 | [diff] [blame] | 1772 | /* Clear DMAUNCERRSTS Cfg-Reg Parity Error status bit |
| 1773 | * (workaround for spurious config parity error after restart) |
| 1774 | */ |
| 1775 | pci_read_config_word(pdev, IOAT_PCI_DEVICE_ID_OFFSET, &dev_id); |
| 1776 | if (dev_id == PCI_DEVICE_ID_INTEL_IOAT_TBG0) { |
| 1777 | pci_write_config_dword(pdev, |
| 1778 | IOAT_PCI_DMAUNCERRSTS_OFFSET, |
| 1779 | 0x10); |
| 1780 | } |
| 1781 | } |
Dan Williams | a6d52d7 | 2009-12-19 15:36:02 -0700 | [diff] [blame] | 1782 | |
Dave Jiang | 8a52b9f | 2013-03-26 15:42:47 -0700 | [diff] [blame] | 1783 | err = ioat2_reset_sync(chan, msecs_to_jiffies(200)); |
| 1784 | if (err) { |
| 1785 | dev_err(&pdev->dev, "Failed to reset!\n"); |
| 1786 | return err; |
Dave Jiang | 1a36306 | 2012-12-03 16:08:37 -0700 | [diff] [blame] | 1787 | } |
| 1788 | |
Dave Jiang | 8a52b9f | 2013-03-26 15:42:47 -0700 | [diff] [blame] | 1789 | if (device->irq_mode != IOAT_NOIRQ && is_bwd_ioat(pdev)) |
| 1790 | err = ioat3_irq_reinit(device); |
Dave Jiang | 1a36306 | 2012-12-03 16:08:37 -0700 | [diff] [blame] | 1791 | |
Dave Jiang | 8a52b9f | 2013-03-26 15:42:47 -0700 | [diff] [blame] | 1792 | return err; |
Dave Jiang | 570727b | 2013-03-25 14:37:31 -0700 | [diff] [blame] | 1793 | } |
| 1794 | |
Greg Kroah-Hartman | 4bf27b8 | 2012-12-21 15:09:59 -0800 | [diff] [blame] | 1795 | int ioat3_dma_probe(struct ioatdma_device *device, int dca) |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 1796 | { |
| 1797 | struct pci_dev *pdev = device->pdev; |
Dan Williams | 228c4f5 | 2009-11-19 17:07:10 -0700 | [diff] [blame] | 1798 | int dca_en = system_has_dca_enabled(pdev); |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 1799 | struct dma_device *dma; |
| 1800 | struct dma_chan *c; |
| 1801 | struct ioat_chan_common *chan; |
Dan Williams | e323271 | 2009-09-08 17:43:02 -0700 | [diff] [blame] | 1802 | bool is_raid_device = false; |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 1803 | int err; |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 1804 | u32 cap; |
| 1805 | |
| 1806 | device->enumerate_channels = ioat2_enumerate_channels; |
Dan Williams | a6d52d7 | 2009-12-19 15:36:02 -0700 | [diff] [blame] | 1807 | device->reset_hw = ioat3_reset_hw; |
Dan Williams | 9de6fc7 | 2009-09-08 17:42:58 -0700 | [diff] [blame] | 1808 | device->self_test = ioat3_dma_self_test; |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 1809 | dma = &device->common; |
| 1810 | dma->device_prep_dma_memcpy = ioat2_dma_prep_memcpy_lock; |
| 1811 | dma->device_issue_pending = ioat2_issue_pending; |
| 1812 | dma->device_alloc_chan_resources = ioat2_alloc_chan_resources; |
| 1813 | dma->device_free_chan_resources = ioat2_free_chan_resources; |
Dan Williams | 58c8649 | 2009-09-08 17:43:00 -0700 | [diff] [blame] | 1814 | |
Dave Jiang | 570727b | 2013-03-25 14:37:31 -0700 | [diff] [blame] | 1815 | if (is_xeon_cb32(pdev)) |
Dave Jiang | f26df1a | 2012-04-04 16:10:41 -0700 | [diff] [blame] | 1816 | dma->copy_align = 6; |
| 1817 | |
Dan Williams | 58c8649 | 2009-09-08 17:43:00 -0700 | [diff] [blame] | 1818 | dma_cap_set(DMA_INTERRUPT, dma->cap_mask); |
| 1819 | dma->device_prep_dma_interrupt = ioat3_prep_interrupt_lock; |
| 1820 | |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 1821 | cap = readl(device->reg_base + IOAT_DMA_CAP_OFFSET); |
Dan Williams | 228c4f5 | 2009-11-19 17:07:10 -0700 | [diff] [blame] | 1822 | |
Dave Jiang | d302398 | 2013-04-10 16:44:32 -0700 | [diff] [blame^] | 1823 | if (is_bwd_noraid(pdev)) |
| 1824 | cap &= ~(IOAT_CAP_XOR | IOAT_CAP_PQ | IOAT_CAP_RAID16SS); |
| 1825 | |
Dan Williams | 228c4f5 | 2009-11-19 17:07:10 -0700 | [diff] [blame] | 1826 | /* dca is incompatible with raid operations */ |
| 1827 | if (dca_en && (cap & (IOAT_CAP_XOR|IOAT_CAP_PQ))) |
| 1828 | cap &= ~(IOAT_CAP_XOR|IOAT_CAP_PQ); |
| 1829 | |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 1830 | if (cap & IOAT_CAP_XOR) { |
Dan Williams | e323271 | 2009-09-08 17:43:02 -0700 | [diff] [blame] | 1831 | is_raid_device = true; |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 1832 | dma->max_xor = 8; |
Dan Williams | 2adfc55 | 2010-05-01 15:22:56 -0700 | [diff] [blame] | 1833 | dma->xor_align = 6; |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 1834 | |
| 1835 | dma_cap_set(DMA_XOR, dma->cap_mask); |
| 1836 | dma->device_prep_dma_xor = ioat3_prep_xor; |
| 1837 | |
| 1838 | dma_cap_set(DMA_XOR_VAL, dma->cap_mask); |
| 1839 | dma->device_prep_dma_xor_val = ioat3_prep_xor_val; |
| 1840 | } |
Dave Jiang | eceec44 | 2013-03-26 15:43:15 -0700 | [diff] [blame] | 1841 | |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 1842 | if (cap & IOAT_CAP_PQ) { |
Dan Williams | e323271 | 2009-09-08 17:43:02 -0700 | [diff] [blame] | 1843 | is_raid_device = true; |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 1844 | |
| 1845 | if (cap & IOAT_CAP_RAID16SS) { |
| 1846 | dma_set_maxpq(dma, 16, 0); |
Dave Jiang | eceec44 | 2013-03-26 15:43:15 -0700 | [diff] [blame] | 1847 | dma->pq_align = 0; |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 1848 | } else { |
| 1849 | dma_set_maxpq(dma, 8, 0); |
| 1850 | if (is_xeon_cb32(pdev)) |
| 1851 | dma->pq_align = 6; |
| 1852 | else |
| 1853 | dma->pq_align = 0; |
| 1854 | } |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 1855 | |
| 1856 | dma_cap_set(DMA_PQ, dma->cap_mask); |
| 1857 | dma->device_prep_dma_pq = ioat3_prep_pq; |
| 1858 | |
| 1859 | dma_cap_set(DMA_PQ_VAL, dma->cap_mask); |
| 1860 | dma->device_prep_dma_pq_val = ioat3_prep_pq_val; |
Dan Williams | ae78662 | 2009-09-08 17:43:00 -0700 | [diff] [blame] | 1861 | |
| 1862 | if (!(cap & IOAT_CAP_XOR)) { |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 1863 | if (cap & IOAT_CAP_RAID16SS) { |
| 1864 | dma->max_xor = 16; |
Dave Jiang | eceec44 | 2013-03-26 15:43:15 -0700 | [diff] [blame] | 1865 | dma->xor_align = 0; |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 1866 | } else { |
| 1867 | dma->max_xor = 8; |
| 1868 | if (is_xeon_cb32(pdev)) |
| 1869 | dma->xor_align = 6; |
| 1870 | else |
| 1871 | dma->xor_align = 0; |
| 1872 | } |
Dan Williams | ae78662 | 2009-09-08 17:43:00 -0700 | [diff] [blame] | 1873 | |
| 1874 | dma_cap_set(DMA_XOR, dma->cap_mask); |
| 1875 | dma->device_prep_dma_xor = ioat3_prep_pqxor; |
| 1876 | |
| 1877 | dma_cap_set(DMA_XOR_VAL, dma->cap_mask); |
| 1878 | dma->device_prep_dma_xor_val = ioat3_prep_pqxor_val; |
| 1879 | } |
Dan Williams | d69d235b | 2009-09-08 17:42:59 -0700 | [diff] [blame] | 1880 | } |
Dave Jiang | eceec44 | 2013-03-26 15:43:15 -0700 | [diff] [blame] | 1881 | |
Dan Williams | e323271 | 2009-09-08 17:43:02 -0700 | [diff] [blame] | 1882 | if (is_raid_device && (cap & IOAT_CAP_FILL_BLOCK)) { |
| 1883 | dma_cap_set(DMA_MEMSET, dma->cap_mask); |
| 1884 | dma->device_prep_dma_memset = ioat3_prep_memset_lock; |
| 1885 | } |
| 1886 | |
| 1887 | |
Dave Jiang | 9a37f64 | 2013-02-26 09:20:36 -0700 | [diff] [blame] | 1888 | dma->device_tx_status = ioat3_tx_status; |
| 1889 | device->cleanup_fn = ioat3_cleanup_event; |
| 1890 | device->timer_fn = ioat3_timer_event; |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 1891 | |
Dave Jiang | 3f09ede | 2013-03-26 15:43:09 -0700 | [diff] [blame] | 1892 | if (is_xeon_cb32(pdev)) { |
| 1893 | dma_cap_clear(DMA_XOR_VAL, dma->cap_mask); |
| 1894 | dma->device_prep_dma_xor_val = NULL; |
Dan Williams | 7b3cc2b | 2009-11-19 17:10:37 -0700 | [diff] [blame] | 1895 | |
Dave Jiang | 3f09ede | 2013-03-26 15:43:09 -0700 | [diff] [blame] | 1896 | dma_cap_clear(DMA_PQ_VAL, dma->cap_mask); |
| 1897 | dma->device_prep_dma_pq_val = NULL; |
| 1898 | } |
Dan Williams | 7b3cc2b | 2009-11-19 17:10:37 -0700 | [diff] [blame] | 1899 | |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 1900 | /* starting with CB3.3 super extended descriptors are supported */ |
| 1901 | if (cap & IOAT_CAP_RAID16SS) { |
| 1902 | char pool_name[14]; |
| 1903 | int i; |
| 1904 | |
| 1905 | /* allocate sw descriptor pool for SED */ |
| 1906 | device->sed_pool = kmem_cache_create("ioat_sed", |
| 1907 | sizeof(struct ioat_sed_ent), 0, 0, NULL); |
| 1908 | if (!device->sed_pool) |
| 1909 | return -ENOMEM; |
| 1910 | |
| 1911 | for (i = 0; i < MAX_SED_POOLS; i++) { |
| 1912 | snprintf(pool_name, 14, "ioat_hw%d_sed", i); |
| 1913 | |
| 1914 | /* allocate SED DMA pool */ |
| 1915 | device->sed_hw_pool[i] = dma_pool_create(pool_name, |
| 1916 | &pdev->dev, |
| 1917 | SED_SIZE * (i + 1), 64, 0); |
| 1918 | if (!device->sed_hw_pool[i]) |
| 1919 | goto sed_pool_cleanup; |
| 1920 | |
| 1921 | } |
| 1922 | } |
| 1923 | |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 1924 | err = ioat_probe(device); |
| 1925 | if (err) |
| 1926 | return err; |
| 1927 | ioat_set_tcp_copy_break(262144); |
| 1928 | |
| 1929 | list_for_each_entry(c, &dma->channels, device_node) { |
| 1930 | chan = to_chan_common(c); |
| 1931 | writel(IOAT_DMA_DCA_ANY_CPU, |
| 1932 | chan->reg_base + IOAT_DCACTRL_OFFSET); |
| 1933 | } |
| 1934 | |
| 1935 | err = ioat_register(device); |
| 1936 | if (err) |
| 1937 | return err; |
Dan Williams | 5669e31 | 2009-09-08 17:42:56 -0700 | [diff] [blame] | 1938 | |
| 1939 | ioat_kobject_add(device, &ioat2_ktype); |
| 1940 | |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 1941 | if (dca) |
| 1942 | device->dca = ioat3_dca_init(pdev, device->reg_base); |
| 1943 | |
| 1944 | return 0; |
Dave Jiang | 7727eaa | 2013-04-15 10:25:56 -0700 | [diff] [blame] | 1945 | |
| 1946 | sed_pool_cleanup: |
| 1947 | if (device->sed_pool) { |
| 1948 | int i; |
| 1949 | kmem_cache_destroy(device->sed_pool); |
| 1950 | |
| 1951 | for (i = 0; i < MAX_SED_POOLS; i++) |
| 1952 | if (device->sed_hw_pool[i]) |
| 1953 | dma_pool_destroy(device->sed_hw_pool[i]); |
| 1954 | } |
| 1955 | |
| 1956 | return -ENOMEM; |
| 1957 | } |
| 1958 | |
| 1959 | void ioat3_dma_remove(struct ioatdma_device *device) |
| 1960 | { |
| 1961 | if (device->sed_pool) { |
| 1962 | int i; |
| 1963 | kmem_cache_destroy(device->sed_pool); |
| 1964 | |
| 1965 | for (i = 0; i < MAX_SED_POOLS; i++) |
| 1966 | if (device->sed_hw_pool[i]) |
| 1967 | dma_pool_destroy(device->sed_hw_pool[i]); |
| 1968 | } |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 1969 | } |