aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/dma/ioat
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-05-09 12:46:45 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-05-09 12:46:45 -0400
commit1763e735b0a093a6747078b3bd101f079e576ab6 (patch)
tree75203a3229977d12dc5a5990d1122e7a3d5f30fc /drivers/dma/ioat
parentb29bdba51924f6fd5971352ba111784dee3a5853 (diff)
parent3065c194670b61e213656ce25976d7c8a95e3c93 (diff)
Merge branch 'for-linus' of git://git.infradead.org/users/vkoul/slave-dma
Pull slave-dmaengine updates from Vinod Koul: "This time we have dmatest improvements from Andy along with dw_dmac fixes. He has also done support for acpi for dmanegine. Also we have bunch of fixes going in DT support for dmanegine for various folks. Then Haswell and other ioat changes from Dave and SUDMAC support from Shimoda." * 'for-linus' of git://git.infradead.org/users/vkoul/slave-dma: (53 commits) dma: tegra: implement suspend/resume callbacks dma:of: Use a mutex to protect the of_dma_list dma: of: Fix of_node reference leak dmaengine: sirf: move driver init from module_init to subsys_initcall sudmac: add support for SUDMAC dma: sh: add Kconfig at_hdmac: move to generic DMA binding ioatdma: ioat3_alloc_sed can be static ioatdma: Adding write back descriptor error status support for ioatdma 3.3 ioatdma: S1200 platforms ioatdma channel 2 and 3 falsely advertise RAID cap ioatdma: Adding support for 16 src PQ ops and super extended descriptors ioatdma: Removing hw bug workaround for CB3.x .2 and earlier dw_dmac: add ACPI support dmaengine: call acpi_dma_request_slave_channel as well dma: acpi-dma: introduce ACPI DMA helpers dma: of: Remove unnecessary list_empty check DMA: OF: Check properties value before running be32_to_cpup() on it DMA: of: Constant names ioatdma: skip silicon bug workaround for pq_align for cb3.3 ioatdma: Removing PQ val disable for cb3.3 ...
Diffstat (limited to 'drivers/dma/ioat')
-rw-r--r--drivers/dma/ioat/dma.c8
-rw-r--r--drivers/dma/ioat/dma.h53
-rw-r--r--drivers/dma/ioat/dma_v2.h2
-rw-r--r--drivers/dma/ioat/dma_v3.c912
-rw-r--r--drivers/dma/ioat/hw.h88
-rw-r--r--drivers/dma/ioat/pci.c20
-rw-r--r--drivers/dma/ioat/registers.h4
7 files changed, 950 insertions, 137 deletions
diff --git a/drivers/dma/ioat/dma.c b/drivers/dma/ioat/dma.c
index 1879a5942bfc..17a2393b3e25 100644
--- a/drivers/dma/ioat/dma.c
+++ b/drivers/dma/ioat/dma.c
@@ -892,7 +892,7 @@ MODULE_PARM_DESC(ioat_interrupt_style,
892 * ioat_dma_setup_interrupts - setup interrupt handler 892 * ioat_dma_setup_interrupts - setup interrupt handler
893 * @device: ioat device 893 * @device: ioat device
894 */ 894 */
895static int ioat_dma_setup_interrupts(struct ioatdma_device *device) 895int ioat_dma_setup_interrupts(struct ioatdma_device *device)
896{ 896{
897 struct ioat_chan_common *chan; 897 struct ioat_chan_common *chan;
898 struct pci_dev *pdev = device->pdev; 898 struct pci_dev *pdev = device->pdev;
@@ -941,6 +941,7 @@ msix:
941 } 941 }
942 } 942 }
943 intrctrl |= IOAT_INTRCTRL_MSIX_VECTOR_CONTROL; 943 intrctrl |= IOAT_INTRCTRL_MSIX_VECTOR_CONTROL;
944 device->irq_mode = IOAT_MSIX;
944 goto done; 945 goto done;
945 946
946msix_single_vector: 947msix_single_vector:
@@ -956,6 +957,7 @@ msix_single_vector:
956 pci_disable_msix(pdev); 957 pci_disable_msix(pdev);
957 goto msi; 958 goto msi;
958 } 959 }
960 device->irq_mode = IOAT_MSIX_SINGLE;
959 goto done; 961 goto done;
960 962
961msi: 963msi:
@@ -969,6 +971,7 @@ msi:
969 pci_disable_msi(pdev); 971 pci_disable_msi(pdev);
970 goto intx; 972 goto intx;
971 } 973 }
974 device->irq_mode = IOAT_MSIX;
972 goto done; 975 goto done;
973 976
974intx: 977intx:
@@ -977,6 +980,7 @@ intx:
977 if (err) 980 if (err)
978 goto err_no_irq; 981 goto err_no_irq;
979 982
983 device->irq_mode = IOAT_INTX;
980done: 984done:
981 if (device->intr_quirk) 985 if (device->intr_quirk)
982 device->intr_quirk(device); 986 device->intr_quirk(device);
@@ -987,9 +991,11 @@ done:
987err_no_irq: 991err_no_irq:
988 /* Disable all interrupt generation */ 992 /* Disable all interrupt generation */
989 writeb(0, device->reg_base + IOAT_INTRCTRL_OFFSET); 993 writeb(0, device->reg_base + IOAT_INTRCTRL_OFFSET);
994 device->irq_mode = IOAT_NOIRQ;
990 dev_err(dev, "no usable interrupts\n"); 995 dev_err(dev, "no usable interrupts\n");
991 return err; 996 return err;
992} 997}
998EXPORT_SYMBOL(ioat_dma_setup_interrupts);
993 999
994static void ioat_disable_interrupts(struct ioatdma_device *device) 1000static void ioat_disable_interrupts(struct ioatdma_device *device)
995{ 1001{
diff --git a/drivers/dma/ioat/dma.h b/drivers/dma/ioat/dma.h
index 53a4cbb78f47..54fb7b9ff9aa 100644
--- a/drivers/dma/ioat/dma.h
+++ b/drivers/dma/ioat/dma.h
@@ -39,6 +39,7 @@
39#define to_ioat_desc(lh) container_of(lh, struct ioat_desc_sw, node) 39#define to_ioat_desc(lh) container_of(lh, struct ioat_desc_sw, node)
40#define tx_to_ioat_desc(tx) container_of(tx, struct ioat_desc_sw, txd) 40#define tx_to_ioat_desc(tx) container_of(tx, struct ioat_desc_sw, txd)
41#define to_dev(ioat_chan) (&(ioat_chan)->device->pdev->dev) 41#define to_dev(ioat_chan) (&(ioat_chan)->device->pdev->dev)
42#define to_pdev(ioat_chan) ((ioat_chan)->device->pdev)
42 43
43#define chan_num(ch) ((int)((ch)->reg_base - (ch)->device->reg_base) / 0x80) 44#define chan_num(ch) ((int)((ch)->reg_base - (ch)->device->reg_base) / 0x80)
44 45
@@ -48,6 +49,14 @@
48 */ 49 */
49#define NULL_DESC_BUFFER_SIZE 1 50#define NULL_DESC_BUFFER_SIZE 1
50 51
52enum ioat_irq_mode {
53 IOAT_NOIRQ = 0,
54 IOAT_MSIX,
55 IOAT_MSIX_SINGLE,
56 IOAT_MSI,
57 IOAT_INTX
58};
59
51/** 60/**
52 * struct ioatdma_device - internal representation of a IOAT device 61 * struct ioatdma_device - internal representation of a IOAT device
53 * @pdev: PCI-Express device 62 * @pdev: PCI-Express device
@@ -72,11 +81,16 @@ struct ioatdma_device {
72 void __iomem *reg_base; 81 void __iomem *reg_base;
73 struct pci_pool *dma_pool; 82 struct pci_pool *dma_pool;
74 struct pci_pool *completion_pool; 83 struct pci_pool *completion_pool;
84#define MAX_SED_POOLS 5
85 struct dma_pool *sed_hw_pool[MAX_SED_POOLS];
86 struct kmem_cache *sed_pool;
75 struct dma_device common; 87 struct dma_device common;
76 u8 version; 88 u8 version;
77 struct msix_entry msix_entries[4]; 89 struct msix_entry msix_entries[4];
78 struct ioat_chan_common *idx[4]; 90 struct ioat_chan_common *idx[4];
79 struct dca_provider *dca; 91 struct dca_provider *dca;
92 enum ioat_irq_mode irq_mode;
93 u32 cap;
80 void (*intr_quirk)(struct ioatdma_device *device); 94 void (*intr_quirk)(struct ioatdma_device *device);
81 int (*enumerate_channels)(struct ioatdma_device *device); 95 int (*enumerate_channels)(struct ioatdma_device *device);
82 int (*reset_hw)(struct ioat_chan_common *chan); 96 int (*reset_hw)(struct ioat_chan_common *chan);
@@ -131,6 +145,20 @@ struct ioat_dma_chan {
131 u16 active; 145 u16 active;
132}; 146};
133 147
148/**
149 * struct ioat_sed_ent - wrapper around super extended hardware descriptor
150 * @hw: hardware SED
151 * @sed_dma: dma address for the SED
152 * @list: list member
153 * @parent: point to the dma descriptor that's the parent
154 */
155struct ioat_sed_ent {
156 struct ioat_sed_raw_descriptor *hw;
157 dma_addr_t dma;
158 struct ioat_ring_ent *parent;
159 unsigned int hw_pool;
160};
161
134static inline struct ioat_chan_common *to_chan_common(struct dma_chan *c) 162static inline struct ioat_chan_common *to_chan_common(struct dma_chan *c)
135{ 163{
136 return container_of(c, struct ioat_chan_common, common); 164 return container_of(c, struct ioat_chan_common, common);
@@ -179,7 +207,7 @@ __dump_desc_dbg(struct ioat_chan_common *chan, struct ioat_dma_descriptor *hw,
179 struct device *dev = to_dev(chan); 207 struct device *dev = to_dev(chan);
180 208
181 dev_dbg(dev, "desc[%d]: (%#llx->%#llx) cookie: %d flags: %#x" 209 dev_dbg(dev, "desc[%d]: (%#llx->%#llx) cookie: %d flags: %#x"
182 " ctl: %#x (op: %d int_en: %d compl: %d)\n", id, 210 " ctl: %#10.8x (op: %#x int_en: %d compl: %d)\n", id,
183 (unsigned long long) tx->phys, 211 (unsigned long long) tx->phys,
184 (unsigned long long) hw->next, tx->cookie, tx->flags, 212 (unsigned long long) hw->next, tx->cookie, tx->flags,
185 hw->ctl, hw->ctl_f.op, hw->ctl_f.int_en, hw->ctl_f.compl_write); 213 hw->ctl, hw->ctl_f.op, hw->ctl_f.int_en, hw->ctl_f.compl_write);
@@ -201,7 +229,7 @@ ioat_chan_by_index(struct ioatdma_device *device, int index)
201 return device->idx[index]; 229 return device->idx[index];
202} 230}
203 231
204static inline u64 ioat_chansts(struct ioat_chan_common *chan) 232static inline u64 ioat_chansts_32(struct ioat_chan_common *chan)
205{ 233{
206 u8 ver = chan->device->version; 234 u8 ver = chan->device->version;
207 u64 status; 235 u64 status;
@@ -218,6 +246,26 @@ static inline u64 ioat_chansts(struct ioat_chan_common *chan)
218 return status; 246 return status;
219} 247}
220 248
249#if BITS_PER_LONG == 64
250
251static inline u64 ioat_chansts(struct ioat_chan_common *chan)
252{
253 u8 ver = chan->device->version;
254 u64 status;
255
256 /* With IOAT v3.3 the status register is 64bit. */
257 if (ver >= IOAT_VER_3_3)
258 status = readq(chan->reg_base + IOAT_CHANSTS_OFFSET(ver));
259 else
260 status = ioat_chansts_32(chan);
261
262 return status;
263}
264
265#else
266#define ioat_chansts ioat_chansts_32
267#endif
268
221static inline void ioat_start(struct ioat_chan_common *chan) 269static inline void ioat_start(struct ioat_chan_common *chan)
222{ 270{
223 u8 ver = chan->device->version; 271 u8 ver = chan->device->version;
@@ -321,6 +369,7 @@ bool ioat_cleanup_preamble(struct ioat_chan_common *chan,
321 dma_addr_t *phys_complete); 369 dma_addr_t *phys_complete);
322void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type); 370void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type);
323void ioat_kobject_del(struct ioatdma_device *device); 371void ioat_kobject_del(struct ioatdma_device *device);
372int ioat_dma_setup_interrupts(struct ioatdma_device *device);
324extern const struct sysfs_ops ioat_sysfs_ops; 373extern const struct sysfs_ops ioat_sysfs_ops;
325extern struct ioat_sysfs_entry ioat_version_attr; 374extern struct ioat_sysfs_entry ioat_version_attr;
326extern struct ioat_sysfs_entry ioat_cap_attr; 375extern struct ioat_sysfs_entry ioat_cap_attr;
diff --git a/drivers/dma/ioat/dma_v2.h b/drivers/dma/ioat/dma_v2.h
index e100f644e344..29bf9448035d 100644
--- a/drivers/dma/ioat/dma_v2.h
+++ b/drivers/dma/ioat/dma_v2.h
@@ -137,6 +137,7 @@ struct ioat_ring_ent {
137 #ifdef DEBUG 137 #ifdef DEBUG
138 int id; 138 int id;
139 #endif 139 #endif
140 struct ioat_sed_ent *sed;
140}; 141};
141 142
142static inline struct ioat_ring_ent * 143static inline struct ioat_ring_ent *
@@ -157,6 +158,7 @@ static inline void ioat2_set_chainaddr(struct ioat2_dma_chan *ioat, u64 addr)
157 158
158int ioat2_dma_probe(struct ioatdma_device *dev, int dca); 159int ioat2_dma_probe(struct ioatdma_device *dev, int dca);
159int ioat3_dma_probe(struct ioatdma_device *dev, int dca); 160int ioat3_dma_probe(struct ioatdma_device *dev, int dca);
161void ioat3_dma_remove(struct ioatdma_device *dev);
160struct dca_provider *ioat2_dca_init(struct pci_dev *pdev, void __iomem *iobase); 162struct dca_provider *ioat2_dca_init(struct pci_dev *pdev, void __iomem *iobase);
161struct dca_provider *ioat3_dca_init(struct pci_dev *pdev, void __iomem *iobase); 163struct dca_provider *ioat3_dca_init(struct pci_dev *pdev, void __iomem *iobase);
162int ioat2_check_space_lock(struct ioat2_dma_chan *ioat, int num_descs); 164int ioat2_check_space_lock(struct ioat2_dma_chan *ioat, int num_descs);
diff --git a/drivers/dma/ioat/dma_v3.c b/drivers/dma/ioat/dma_v3.c
index e8336cce360b..ca6ea9b3551b 100644
--- a/drivers/dma/ioat/dma_v3.c
+++ b/drivers/dma/ioat/dma_v3.c
@@ -55,7 +55,7 @@
55/* 55/*
56 * Support routines for v3+ hardware 56 * Support routines for v3+ hardware
57 */ 57 */
58 58#include <linux/module.h>
59#include <linux/pci.h> 59#include <linux/pci.h>
60#include <linux/gfp.h> 60#include <linux/gfp.h>
61#include <linux/dmaengine.h> 61#include <linux/dmaengine.h>
@@ -70,6 +70,10 @@
70/* ioat hardware assumes at least two sources for raid operations */ 70/* ioat hardware assumes at least two sources for raid operations */
71#define src_cnt_to_sw(x) ((x) + 2) 71#define src_cnt_to_sw(x) ((x) + 2)
72#define src_cnt_to_hw(x) ((x) - 2) 72#define src_cnt_to_hw(x) ((x) - 2)
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)
73 77
74/* provide a lookup table for setting the source address in the base or 78/* provide a lookup table for setting the source address in the base or
75 * extended descriptor of an xor or pq descriptor 79 * extended descriptor of an xor or pq descriptor
@@ -77,7 +81,20 @@
77static const u8 xor_idx_to_desc = 0xe0; 81static const u8 xor_idx_to_desc = 0xe0;
78static const u8 xor_idx_to_field[] = { 1, 4, 5, 6, 7, 0, 1, 2 }; 82static const u8 xor_idx_to_field[] = { 1, 4, 5, 6, 7, 0, 1, 2 };
79static const u8 pq_idx_to_desc = 0xf8; 83static const u8 pq_idx_to_desc = 0xf8;
84static const u8 pq16_idx_to_desc[] = { 0, 0, 1, 1, 1, 1, 1, 1, 1,
85 2, 2, 2, 2, 2, 2, 2 };
80static const u8 pq_idx_to_field[] = { 1, 4, 5, 0, 1, 2, 4, 5 }; 86static const u8 pq_idx_to_field[] = { 1, 4, 5, 0, 1, 2, 4, 5 };
87static 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 */
94static const u8 pq16_idx_to_sed[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0,
95 1, 1, 1, 1, 1, 1, 1 };
96
97static void ioat3_eh(struct ioat2_dma_chan *ioat);
81 98
82static dma_addr_t xor_get_src(struct ioat_raw_descriptor *descs[2], int idx) 99static dma_addr_t xor_get_src(struct ioat_raw_descriptor *descs[2], int idx)
83{ 100{
@@ -101,6 +118,13 @@ static dma_addr_t pq_get_src(struct ioat_raw_descriptor *descs[2], int idx)
101 return raw->field[pq_idx_to_field[idx]]; 118 return raw->field[pq_idx_to_field[idx]];
102} 119}
103 120
121static 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
104static void pq_set_src(struct ioat_raw_descriptor *descs[2], 128static void pq_set_src(struct ioat_raw_descriptor *descs[2],
105 dma_addr_t addr, u32 offset, u8 coef, int idx) 129 dma_addr_t addr, u32 offset, u8 coef, int idx)
106{ 130{
@@ -111,6 +135,167 @@ static void pq_set_src(struct ioat_raw_descriptor *descs[2],
111 pq->coef[idx] = coef; 135 pq->coef[idx] = coef;
112} 136}
113 137
138static int sed_get_pq16_pool_idx(int src_cnt)
139{
140
141 return pq16_idx_to_sed[src_cnt];
142}
143
144static 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
163static 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
182static 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
202static 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
222static 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
228static 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
241static 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
253static 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
269static struct ioat_sed_ent *
270ioat3_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
290static 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
114static void ioat3_dma_unmap(struct ioat2_dma_chan *ioat, 299static void ioat3_dma_unmap(struct ioat2_dma_chan *ioat,
115 struct ioat_ring_ent *desc, int idx) 300 struct ioat_ring_ent *desc, int idx)
116{ 301{
@@ -223,6 +408,54 @@ static void ioat3_dma_unmap(struct ioat2_dma_chan *ioat,
223 } 408 }
224 break; 409 break;
225 } 410 }
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 }
226 default: 459 default:
227 dev_err(&pdev->dev, "%s: unknown op type: %#x\n", 460 dev_err(&pdev->dev, "%s: unknown op type: %#x\n",
228 __func__, desc->hw->ctl_f.op); 461 __func__, desc->hw->ctl_f.op);
@@ -250,6 +483,63 @@ static bool desc_has_ext(struct ioat_ring_ent *desc)
250 return false; 483 return false;
251} 484}
252 485
486static 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
500static 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
513static void
514desc_get_errstat(struct ioat2_dma_chan *ioat, struct ioat_ring_ent *desc)
515{
516 struct ioat_dma_descriptor *hw = desc->hw;
517
518 switch (hw->ctl_f.op) {
519 case IOAT_OP_PQ_VAL:
520 case IOAT_OP_PQ_VAL_16S:
521 {
522 struct ioat_pq_descriptor *pq = desc->pq;
523
524 /* check if there's error written */
525 if (!pq->dwbes_f.wbes)
526 return;
527
528 /* need to set a chanerr var for checking to clear later */
529
530 if (pq->dwbes_f.p_val_err)
531 *desc->result |= SUM_CHECK_P_RESULT;
532
533 if (pq->dwbes_f.q_val_err)
534 *desc->result |= SUM_CHECK_Q_RESULT;
535
536 return;
537 }
538 default:
539 return;
540 }
541}
542
253/** 543/**
254 * __cleanup - reclaim used descriptors 544 * __cleanup - reclaim used descriptors
255 * @ioat: channel (ring) to clean 545 * @ioat: channel (ring) to clean
@@ -260,6 +550,7 @@ static bool desc_has_ext(struct ioat_ring_ent *desc)
260static void __cleanup(struct ioat2_dma_chan *ioat, dma_addr_t phys_complete) 550static void __cleanup(struct ioat2_dma_chan *ioat, dma_addr_t phys_complete)
261{ 551{
262 struct ioat_chan_common *chan = &ioat->base; 552 struct ioat_chan_common *chan = &ioat->base;
553 struct ioatdma_device *device = chan->device;
263 struct ioat_ring_ent *desc; 554 struct ioat_ring_ent *desc;
264 bool seen_current = false; 555 bool seen_current = false;
265 int idx = ioat->tail, i; 556 int idx = ioat->tail, i;
@@ -268,6 +559,16 @@ static void __cleanup(struct ioat2_dma_chan *ioat, dma_addr_t phys_complete)
268 dev_dbg(to_dev(chan), "%s: head: %#x tail: %#x issued: %#x\n", 559 dev_dbg(to_dev(chan), "%s: head: %#x tail: %#x issued: %#x\n",
269 __func__, ioat->head, ioat->tail, ioat->issued); 560 __func__, ioat->head, ioat->tail, ioat->issued);
270 561
562 /*
563 * At restart of the channel, the completion address and the
564 * channel status will be 0 due to starting a new chain. Since
565 * it's new chain and the first descriptor "fails", there is
566 * nothing to clean up. We do not want to reap the entire submitted
567 * chain due to this 0 address value and then BUG.
568 */
569 if (!phys_complete)
570 return;
571
271 active = ioat2_ring_active(ioat); 572 active = ioat2_ring_active(ioat);
272 for (i = 0; i < active && !seen_current; i++) { 573 for (i = 0; i < active && !seen_current; i++) {
273 struct dma_async_tx_descriptor *tx; 574 struct dma_async_tx_descriptor *tx;
@@ -276,6 +577,11 @@ static void __cleanup(struct ioat2_dma_chan *ioat, dma_addr_t phys_complete)
276 prefetch(ioat2_get_ring_ent(ioat, idx + i + 1)); 577 prefetch(ioat2_get_ring_ent(ioat, idx + i + 1));
277 desc = ioat2_get_ring_ent(ioat, idx + i); 578 desc = ioat2_get_ring_ent(ioat, idx + i);
278 dump_desc_dbg(ioat, desc); 579 dump_desc_dbg(ioat, desc);
580
581 /* set err stat if we are using dwbes */
582 if (device->cap & IOAT_CAP_DWBES)
583 desc_get_errstat(ioat, desc);
584
279 tx = &desc->txd; 585 tx = &desc->txd;
280 if (tx->cookie) { 586 if (tx->cookie) {
281 dma_cookie_complete(tx); 587 dma_cookie_complete(tx);
@@ -294,6 +600,12 @@ static void __cleanup(struct ioat2_dma_chan *ioat, dma_addr_t phys_complete)
294 BUG_ON(i + 1 >= active); 600 BUG_ON(i + 1 >= active);
295 i++; 601 i++;
296 } 602 }
603
604 /* cleanup super extended descriptors */
605 if (desc->sed) {
606 ioat3_free_sed(device, desc->sed);
607 desc->sed = NULL;
608 }
297 } 609 }
298 smp_mb(); /* finish all descriptor reads before incrementing tail */ 610 smp_mb(); /* finish all descriptor reads before incrementing tail */
299 ioat->tail = idx + i; 611 ioat->tail = idx + i;
@@ -314,11 +626,22 @@ static void __cleanup(struct ioat2_dma_chan *ioat, dma_addr_t phys_complete)
314static void ioat3_cleanup(struct ioat2_dma_chan *ioat) 626static void ioat3_cleanup(struct ioat2_dma_chan *ioat)
315{ 627{
316 struct ioat_chan_common *chan = &ioat->base; 628 struct ioat_chan_common *chan = &ioat->base;
317 dma_addr_t phys_complete; 629 u64 phys_complete;
318 630
319 spin_lock_bh(&chan->cleanup_lock); 631 spin_lock_bh(&chan->cleanup_lock);
320 if (ioat_cleanup_preamble(chan, &phys_complete)) 632
633 if (ioat3_cleanup_preamble(chan, &phys_complete))
321 __cleanup(ioat, phys_complete); 634 __cleanup(ioat, phys_complete);
635
636 if (is_ioat_halted(*chan->completion)) {
637 u32 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
638
639 if (chanerr & IOAT_CHANERR_HANDLE_MASK) {
640 mod_timer(&chan->timer, jiffies + IDLE_TIMEOUT);
641 ioat3_eh(ioat);
642 }
643 }
644
322 spin_unlock_bh(&chan->cleanup_lock); 645 spin_unlock_bh(&chan->cleanup_lock);
323} 646}
324 647
@@ -333,15 +656,78 @@ static void ioat3_cleanup_event(unsigned long data)
333static void ioat3_restart_channel(struct ioat2_dma_chan *ioat) 656static void ioat3_restart_channel(struct ioat2_dma_chan *ioat)
334{ 657{
335 struct ioat_chan_common *chan = &ioat->base; 658 struct ioat_chan_common *chan = &ioat->base;
336 dma_addr_t phys_complete; 659 u64 phys_complete;
337 660
338 ioat2_quiesce(chan, 0); 661 ioat2_quiesce(chan, 0);
339 if (ioat_cleanup_preamble(chan, &phys_complete)) 662 if (ioat3_cleanup_preamble(chan, &phys_complete))
340 __cleanup(ioat, phys_complete); 663 __cleanup(ioat, phys_complete);
341 664
342 __ioat2_restart_chan(ioat); 665 __ioat2_restart_chan(ioat);
343} 666}
344 667
668static void ioat3_eh(struct ioat2_dma_chan *ioat)
669{
670 struct ioat_chan_common *chan = &ioat->base;
671 struct pci_dev *pdev = to_pdev(chan);
672 struct ioat_dma_descriptor *hw;
673 u64 phys_complete;
674 struct ioat_ring_ent *desc;
675 u32 err_handled = 0;
676 u32 chanerr_int;
677 u32 chanerr;
678
679 /* cleanup so tail points to descriptor that caused the error */
680 if (ioat3_cleanup_preamble(chan, &phys_complete))
681 __cleanup(ioat, phys_complete);
682
683 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
684 pci_read_config_dword(pdev, IOAT_PCI_CHANERR_INT_OFFSET, &chanerr_int);
685
686 dev_dbg(to_dev(chan), "%s: error = %x:%x\n",
687 __func__, chanerr, chanerr_int);
688
689 desc = ioat2_get_ring_ent(ioat, ioat->tail);
690 hw = desc->hw;
691 dump_desc_dbg(ioat, desc);
692
693 switch (hw->ctl_f.op) {
694 case IOAT_OP_XOR_VAL:
695 if (chanerr & IOAT_CHANERR_XOR_P_OR_CRC_ERR) {
696 *desc->result |= SUM_CHECK_P_RESULT;
697 err_handled |= IOAT_CHANERR_XOR_P_OR_CRC_ERR;
698 }
699 break;
700 case IOAT_OP_PQ_VAL:
701 case IOAT_OP_PQ_VAL_16S:
702 if (chanerr & IOAT_CHANERR_XOR_P_OR_CRC_ERR) {
703 *desc->result |= SUM_CHECK_P_RESULT;
704 err_handled |= IOAT_CHANERR_XOR_P_OR_CRC_ERR;
705 }
706 if (chanerr & IOAT_CHANERR_XOR_Q_ERR) {
707 *desc->result |= SUM_CHECK_Q_RESULT;
708 err_handled |= IOAT_CHANERR_XOR_Q_ERR;
709 }
710 break;
711 }
712
713 /* fault on unhandled error or spurious halt */
714 if (chanerr ^ err_handled || chanerr == 0) {
715 dev_err(to_dev(chan), "%s: fatal error (%x:%x)\n",
716 __func__, chanerr, err_handled);
717 BUG();
718 }
719
720 writel(chanerr, chan->reg_base + IOAT_CHANERR_OFFSET);
721 pci_write_config_dword(pdev, IOAT_PCI_CHANERR_INT_OFFSET, chanerr_int);
722
723 /* mark faulting descriptor as complete */
724 *chan->completion = desc->txd.phys;
725
726 spin_lock_bh(&ioat->prep_lock);
727 ioat3_restart_channel(ioat);
728 spin_unlock_bh(&ioat->prep_lock);
729}
730
345static void check_active(struct ioat2_dma_chan *ioat) 731static void check_active(struct ioat2_dma_chan *ioat)
346{ 732{
347 struct ioat_chan_common *chan = &ioat->base; 733 struct ioat_chan_common *chan = &ioat->base;
@@ -605,7 +991,8 @@ dump_pq_desc_dbg(struct ioat2_dma_chan *ioat, struct ioat_ring_ent *desc, struct
605 int i; 991 int i;
606 992
607 dev_dbg(dev, "desc[%d]: (%#llx->%#llx) flags: %#x" 993 dev_dbg(dev, "desc[%d]: (%#llx->%#llx) flags: %#x"
608 " sz: %#x ctl: %#x (op: %d int: %d compl: %d pq: '%s%s' src_cnt: %d)\n", 994 " sz: %#10.8x ctl: %#x (op: %#x int: %d compl: %d pq: '%s%s'"
995 " src_cnt: %d)\n",
609 desc_id(desc), (unsigned long long) desc->txd.phys, 996 desc_id(desc), (unsigned long long) desc->txd.phys,
610 (unsigned long long) (pq_ex ? pq_ex->next : pq->next), 997 (unsigned long long) (pq_ex ? pq_ex->next : pq->next),
611 desc->txd.flags, pq->size, pq->ctl, pq->ctl_f.op, pq->ctl_f.int_en, 998 desc->txd.flags, pq->size, pq->ctl, pq->ctl_f.op, pq->ctl_f.int_en,
@@ -617,6 +1004,42 @@ dump_pq_desc_dbg(struct ioat2_dma_chan *ioat, struct ioat_ring_ent *desc, struct
617 (unsigned long long) pq_get_src(descs, i), pq->coef[i]); 1004 (unsigned long long) pq_get_src(descs, i), pq->coef[i]);
618 dev_dbg(dev, "\tP: %#llx\n", pq->p_addr); 1005 dev_dbg(dev, "\tP: %#llx\n", pq->p_addr);
619 dev_dbg(dev, "\tQ: %#llx\n", pq->q_addr); 1006 dev_dbg(dev, "\tQ: %#llx\n", pq->q_addr);
1007 dev_dbg(dev, "\tNEXT: %#llx\n", pq->next);
1008}
1009
1010static void dump_pq16_desc_dbg(struct ioat2_dma_chan *ioat,
1011 struct ioat_ring_ent *desc)
1012{
1013 struct device *dev = to_dev(&ioat->base);
1014 struct ioat_pq_descriptor *pq = desc->pq;
1015 struct ioat_raw_descriptor *descs[] = { (void *)pq,
1016 (void *)pq,
1017 (void *)pq };
1018 int src_cnt = src16_cnt_to_sw(pq->ctl_f.src_cnt);
1019 int i;
1020
1021 if (desc->sed) {
1022 descs[1] = (void *)desc->sed->hw;
1023 descs[2] = (void *)desc->sed->hw + 64;
1024 }
1025
1026 dev_dbg(dev, "desc[%d]: (%#llx->%#llx) flags: %#x"
1027 " sz: %#x ctl: %#x (op: %#x int: %d compl: %d pq: '%s%s'"
1028 " src_cnt: %d)\n",
1029 desc_id(desc), (unsigned long long) desc->txd.phys,
1030 (unsigned long long) pq->next,
1031 desc->txd.flags, pq->size, pq->ctl,
1032 pq->ctl_f.op, pq->ctl_f.int_en,
1033 pq->ctl_f.compl_write,
1034 pq->ctl_f.p_disable ? "" : "p", pq->ctl_f.q_disable ? "" : "q",
1035 pq->ctl_f.src_cnt);
1036 for (i = 0; i < src_cnt; i++) {
1037 dev_dbg(dev, "\tsrc[%d]: %#llx coef: %#x\n", i,
1038 (unsigned long long) pq16_get_src(descs, i),
1039 pq->coef[i]);
1040 }
1041 dev_dbg(dev, "\tP: %#llx\n", pq->p_addr);
1042 dev_dbg(dev, "\tQ: %#llx\n", pq->q_addr);
620} 1043}
621 1044
622static struct dma_async_tx_descriptor * 1045static struct dma_async_tx_descriptor *
@@ -627,6 +1050,7 @@ __ioat3_prep_pq_lock(struct dma_chan *c, enum sum_check_flags *result,
627{ 1050{
628 struct ioat2_dma_chan *ioat = to_ioat2_chan(c); 1051 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
629 struct ioat_chan_common *chan = &ioat->base; 1052 struct ioat_chan_common *chan = &ioat->base;
1053 struct ioatdma_device *device = chan->device;
630 struct ioat_ring_ent *compl_desc; 1054 struct ioat_ring_ent *compl_desc;
631 struct ioat_ring_ent *desc; 1055 struct ioat_ring_ent *desc;
632 struct ioat_ring_ent *ext; 1056 struct ioat_ring_ent *ext;
@@ -637,6 +1061,7 @@ __ioat3_prep_pq_lock(struct dma_chan *c, enum sum_check_flags *result,
637 u32 offset = 0; 1061 u32 offset = 0;
638 u8 op = result ? IOAT_OP_PQ_VAL : IOAT_OP_PQ; 1062 u8 op = result ? IOAT_OP_PQ_VAL : IOAT_OP_PQ;
639 int i, s, idx, with_ext, num_descs; 1063 int i, s, idx, with_ext, num_descs;
1064 int cb32 = (device->version < IOAT_VER_3_3) ? 1 : 0;
640 1065
641 dev_dbg(to_dev(chan), "%s\n", __func__); 1066 dev_dbg(to_dev(chan), "%s\n", __func__);
642 /* the engine requires at least two sources (we provide 1067 /* the engine requires at least two sources (we provide
@@ -662,7 +1087,7 @@ __ioat3_prep_pq_lock(struct dma_chan *c, enum sum_check_flags *result,
662 * order. 1087 * order.
663 */ 1088 */
664 if (likely(num_descs) && 1089 if (likely(num_descs) &&
665 ioat2_check_space_lock(ioat, num_descs+1) == 0) 1090 ioat2_check_space_lock(ioat, num_descs + cb32) == 0)
666 idx = ioat->head; 1091 idx = ioat->head;
667 else 1092 else
668 return NULL; 1093 return NULL;
@@ -700,6 +1125,9 @@ __ioat3_prep_pq_lock(struct dma_chan *c, enum sum_check_flags *result,
700 pq->q_addr = dst[1] + offset; 1125 pq->q_addr = dst[1] + offset;
701 pq->ctl = 0; 1126 pq->ctl = 0;
702 pq->ctl_f.op = op; 1127 pq->ctl_f.op = op;
1128 /* we turn on descriptor write back error status */
1129 if (device->cap & IOAT_CAP_DWBES)
1130 pq->ctl_f.wb_en = result ? 1 : 0;
703 pq->ctl_f.src_cnt = src_cnt_to_hw(s); 1131 pq->ctl_f.src_cnt = src_cnt_to_hw(s);
704 pq->ctl_f.p_disable = !!(flags & DMA_PREP_PQ_DISABLE_P); 1132 pq->ctl_f.p_disable = !!(flags & DMA_PREP_PQ_DISABLE_P);
705 pq->ctl_f.q_disable = !!(flags & DMA_PREP_PQ_DISABLE_Q); 1133 pq->ctl_f.q_disable = !!(flags & DMA_PREP_PQ_DISABLE_Q);
@@ -716,26 +1144,140 @@ __ioat3_prep_pq_lock(struct dma_chan *c, enum sum_check_flags *result,
716 pq->ctl_f.fence = !!(flags & DMA_PREP_FENCE); 1144 pq->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
717 dump_pq_desc_dbg(ioat, desc, ext); 1145 dump_pq_desc_dbg(ioat, desc, ext);
718 1146
719 /* completion descriptor carries interrupt bit */ 1147 if (!cb32) {
720 compl_desc = ioat2_get_ring_ent(ioat, idx + i); 1148 pq->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
721 compl_desc->txd.flags = flags & DMA_PREP_INTERRUPT; 1149 pq->ctl_f.compl_write = 1;
722 hw = compl_desc->hw; 1150 compl_desc = desc;
723 hw->ctl = 0; 1151 } else {
724 hw->ctl_f.null = 1; 1152 /* completion descriptor carries interrupt bit */
725 hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT); 1153 compl_desc = ioat2_get_ring_ent(ioat, idx + i);
726 hw->ctl_f.compl_write = 1; 1154 compl_desc->txd.flags = flags & DMA_PREP_INTERRUPT;
727 hw->size = NULL_DESC_BUFFER_SIZE; 1155 hw = compl_desc->hw;
728 dump_desc_dbg(ioat, compl_desc); 1156 hw->ctl = 0;
1157 hw->ctl_f.null = 1;
1158 hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
1159 hw->ctl_f.compl_write = 1;
1160 hw->size = NULL_DESC_BUFFER_SIZE;
1161 dump_desc_dbg(ioat, compl_desc);
1162 }
1163
729 1164
730 /* we leave the channel locked to ensure in order submission */ 1165 /* we leave the channel locked to ensure in order submission */
731 return &compl_desc->txd; 1166 return &compl_desc->txd;
732} 1167}
733 1168
734static struct dma_async_tx_descriptor * 1169static struct dma_async_tx_descriptor *
1170__ioat3_prep_pq16_lock(struct dma_chan *c, enum sum_check_flags *result,
1171 const dma_addr_t *dst, const dma_addr_t *src,
1172 unsigned int src_cnt, const unsigned char *scf,
1173 size_t len, unsigned long flags)
1174{
1175 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
1176 struct ioat_chan_common *chan = &ioat->base;
1177 struct ioatdma_device *device = chan->device;
1178 struct ioat_ring_ent *desc;
1179 size_t total_len = len;
1180 struct ioat_pq_descriptor *pq;
1181 u32 offset = 0;
1182 u8 op;
1183 int i, s, idx, num_descs;
1184
1185 /* this function only handles src_cnt 9 - 16 */
1186 BUG_ON(src_cnt < 9);
1187
1188 /* this function is only called with 9-16 sources */
1189 op = result ? IOAT_OP_PQ_VAL_16S : IOAT_OP_PQ_16S;
1190
1191 dev_dbg(to_dev(chan), "%s\n", __func__);
1192
1193 num_descs = ioat2_xferlen_to_descs(ioat, len);
1194
1195 /*
1196 * 16 source pq is only available on cb3.3 and has no completion
1197 * write hw bug.
1198 */
1199 if (num_descs && ioat2_check_space_lock(ioat, num_descs) == 0)
1200 idx = ioat->head;
1201 else
1202 return NULL;
1203
1204 i = 0;
1205
1206 do {
1207 struct ioat_raw_descriptor *descs[4];
1208 size_t xfer_size = min_t(size_t, len, 1 << ioat->xfercap_log);
1209
1210 desc = ioat2_get_ring_ent(ioat, idx + i);
1211 pq = desc->pq;
1212
1213 descs[0] = (struct ioat_raw_descriptor *) pq;
1214
1215 desc->sed = ioat3_alloc_sed(device,
1216 sed_get_pq16_pool_idx(src_cnt));
1217 if (!desc->sed) {
1218 dev_err(to_dev(chan),
1219 "%s: no free sed entries\n", __func__);
1220 return NULL;
1221 }
1222
1223 pq->sed_addr = desc->sed->dma;
1224 desc->sed->parent = desc;
1225
1226 descs[1] = (struct ioat_raw_descriptor *)desc->sed->hw;
1227 descs[2] = (void *)descs[1] + 64;
1228
1229 for (s = 0; s < src_cnt; s++)
1230 pq16_set_src(descs, src[s], offset, scf[s], s);
1231
1232 /* see the comment for dma_maxpq in include/linux/dmaengine.h */
1233 if (dmaf_p_disabled_continue(flags))
1234 pq16_set_src(descs, dst[1], offset, 1, s++);
1235 else if (dmaf_continue(flags)) {
1236 pq16_set_src(descs, dst[0], offset, 0, s++);
1237 pq16_set_src(descs, dst[1], offset, 1, s++);
1238 pq16_set_src(descs, dst[1], offset, 0, s++);
1239 }
1240
1241 pq->size = xfer_size;
1242 pq->p_addr = dst[0] + offset;
1243 pq->q_addr = dst[1] + offset;
1244 pq->ctl = 0;
1245 pq->ctl_f.op = op;
1246 pq->ctl_f.src_cnt = src16_cnt_to_hw(s);
1247 /* we turn on descriptor write back error status */
1248 if (device->cap & IOAT_CAP_DWBES)
1249 pq->ctl_f.wb_en = result ? 1 : 0;
1250 pq->ctl_f.p_disable = !!(flags & DMA_PREP_PQ_DISABLE_P);
1251 pq->ctl_f.q_disable = !!(flags & DMA_PREP_PQ_DISABLE_Q);
1252
1253 len -= xfer_size;
1254 offset += xfer_size;
1255 } while (++i < num_descs);
1256
1257 /* last pq descriptor carries the unmap parameters and fence bit */
1258 desc->txd.flags = flags;
1259 desc->len = total_len;
1260 if (result)
1261 desc->result = result;
1262 pq->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
1263
1264 /* with cb3.3 we should be able to do completion w/o a null desc */
1265 pq->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
1266 pq->ctl_f.compl_write = 1;
1267
1268 dump_pq16_desc_dbg(ioat, desc);
1269
1270 /* we leave the channel locked to ensure in order submission */
1271 return &desc->txd;
1272}
1273
1274static struct dma_async_tx_descriptor *
735ioat3_prep_pq(struct dma_chan *chan, dma_addr_t *dst, dma_addr_t *src, 1275ioat3_prep_pq(struct dma_chan *chan, dma_addr_t *dst, dma_addr_t *src,
736 unsigned int src_cnt, const unsigned char *scf, size_t len, 1276 unsigned int src_cnt, const unsigned char *scf, size_t len,
737 unsigned long flags) 1277 unsigned long flags)
738{ 1278{
1279 struct dma_device *dma = chan->device;
1280
739 /* specify valid address for disabled result */ 1281 /* specify valid address for disabled result */
740 if (flags & DMA_PREP_PQ_DISABLE_P) 1282 if (flags & DMA_PREP_PQ_DISABLE_P)
741 dst[0] = dst[1]; 1283 dst[0] = dst[1];
@@ -755,11 +1297,20 @@ ioat3_prep_pq(struct dma_chan *chan, dma_addr_t *dst, dma_addr_t *src,
755 single_source_coef[0] = scf[0]; 1297 single_source_coef[0] = scf[0];
756 single_source_coef[1] = 0; 1298 single_source_coef[1] = 0;
757 1299
758 return __ioat3_prep_pq_lock(chan, NULL, dst, single_source, 2, 1300 return (src_cnt > 8) && (dma->max_pq > 8) ?
759 single_source_coef, len, flags); 1301 __ioat3_prep_pq16_lock(chan, NULL, dst, single_source,
760 } else 1302 2, single_source_coef, len,
761 return __ioat3_prep_pq_lock(chan, NULL, dst, src, src_cnt, scf, 1303 flags) :
762 len, flags); 1304 __ioat3_prep_pq_lock(chan, NULL, dst, single_source, 2,
1305 single_source_coef, len, flags);
1306
1307 } else {
1308 return (src_cnt > 8) && (dma->max_pq > 8) ?
1309 __ioat3_prep_pq16_lock(chan, NULL, dst, src, src_cnt,
1310 scf, len, flags) :
1311 __ioat3_prep_pq_lock(chan, NULL, dst, src, src_cnt,
1312 scf, len, flags);
1313 }
763} 1314}
764 1315
765struct dma_async_tx_descriptor * 1316struct dma_async_tx_descriptor *
@@ -767,6 +1318,8 @@ ioat3_prep_pq_val(struct dma_chan *chan, dma_addr_t *pq, dma_addr_t *src,
767 unsigned int src_cnt, const unsigned char *scf, size_t len, 1318 unsigned int src_cnt, const unsigned char *scf, size_t len,
768 enum sum_check_flags *pqres, unsigned long flags) 1319 enum sum_check_flags *pqres, unsigned long flags)
769{ 1320{
1321 struct dma_device *dma = chan->device;
1322
770 /* specify valid address for disabled result */ 1323 /* specify valid address for disabled result */
771 if (flags & DMA_PREP_PQ_DISABLE_P) 1324 if (flags & DMA_PREP_PQ_DISABLE_P)
772 pq[0] = pq[1]; 1325 pq[0] = pq[1];
@@ -778,14 +1331,18 @@ ioat3_prep_pq_val(struct dma_chan *chan, dma_addr_t *pq, dma_addr_t *src,
778 */ 1331 */
779 *pqres = 0; 1332 *pqres = 0;
780 1333
781 return __ioat3_prep_pq_lock(chan, pqres, pq, src, src_cnt, scf, len, 1334 return (src_cnt > 8) && (dma->max_pq > 8) ?
782 flags); 1335 __ioat3_prep_pq16_lock(chan, pqres, pq, src, src_cnt, scf, len,
1336 flags) :
1337 __ioat3_prep_pq_lock(chan, pqres, pq, src, src_cnt, scf, len,
1338 flags);
783} 1339}
784 1340
785static struct dma_async_tx_descriptor * 1341static struct dma_async_tx_descriptor *
786ioat3_prep_pqxor(struct dma_chan *chan, dma_addr_t dst, dma_addr_t *src, 1342ioat3_prep_pqxor(struct dma_chan *chan, dma_addr_t dst, dma_addr_t *src,
787 unsigned int src_cnt, size_t len, unsigned long flags) 1343 unsigned int src_cnt, size_t len, unsigned long flags)
788{ 1344{
1345 struct dma_device *dma = chan->device;
789 unsigned char scf[src_cnt]; 1346 unsigned char scf[src_cnt];
790 dma_addr_t pq[2]; 1347 dma_addr_t pq[2];
791 1348
@@ -794,8 +1351,11 @@ ioat3_prep_pqxor(struct dma_chan *chan, dma_addr_t dst, dma_addr_t *src,
794 flags |= DMA_PREP_PQ_DISABLE_Q; 1351 flags |= DMA_PREP_PQ_DISABLE_Q;
795 pq[1] = dst; /* specify valid address for disabled result */ 1352 pq[1] = dst; /* specify valid address for disabled result */
796 1353
797 return __ioat3_prep_pq_lock(chan, NULL, pq, src, src_cnt, scf, len, 1354 return (src_cnt > 8) && (dma->max_pq > 8) ?
798 flags); 1355 __ioat3_prep_pq16_lock(chan, NULL, pq, src, src_cnt, scf, len,
1356 flags) :
1357 __ioat3_prep_pq_lock(chan, NULL, pq, src, src_cnt, scf, len,
1358 flags);
799} 1359}
800 1360
801struct dma_async_tx_descriptor * 1361struct dma_async_tx_descriptor *
@@ -803,6 +1363,7 @@ ioat3_prep_pqxor_val(struct dma_chan *chan, dma_addr_t *src,
803 unsigned int src_cnt, size_t len, 1363 unsigned int src_cnt, size_t len,
804 enum sum_check_flags *result, unsigned long flags) 1364 enum sum_check_flags *result, unsigned long flags)
805{ 1365{
1366 struct dma_device *dma = chan->device;
806 unsigned char scf[src_cnt]; 1367 unsigned char scf[src_cnt];
807 dma_addr_t pq[2]; 1368 dma_addr_t pq[2];
808 1369
@@ -816,8 +1377,12 @@ ioat3_prep_pqxor_val(struct dma_chan *chan, dma_addr_t *src,
816 flags |= DMA_PREP_PQ_DISABLE_Q; 1377 flags |= DMA_PREP_PQ_DISABLE_Q;
817 pq[1] = pq[0]; /* specify valid address for disabled result */ 1378 pq[1] = pq[0]; /* specify valid address for disabled result */
818 1379
819 return __ioat3_prep_pq_lock(chan, result, pq, &src[1], src_cnt - 1, scf, 1380
820 len, flags); 1381 return (src_cnt > 8) && (dma->max_pq > 8) ?
1382 __ioat3_prep_pq16_lock(chan, result, pq, &src[1], src_cnt - 1,
1383 scf, len, flags) :
1384 __ioat3_prep_pq_lock(chan, result, pq, &src[1], src_cnt - 1,
1385 scf, len, flags);
821} 1386}
822 1387
823static struct dma_async_tx_descriptor * 1388static struct dma_async_tx_descriptor *
@@ -1167,6 +1732,56 @@ static int ioat3_dma_self_test(struct ioatdma_device *device)
1167 return 0; 1732 return 0;
1168} 1733}
1169 1734
1735static int ioat3_irq_reinit(struct ioatdma_device *device)
1736{
1737 int msixcnt = device->common.chancnt;
1738 struct pci_dev *pdev = device->pdev;
1739 int i;
1740 struct msix_entry *msix;
1741 struct ioat_chan_common *chan;
1742 int err = 0;
1743
1744 switch (device->irq_mode) {
1745 case IOAT_MSIX:
1746
1747 for (i = 0; i < msixcnt; i++) {
1748 msix = &device->msix_entries[i];
1749 chan = ioat_chan_by_index(device, i);
1750 devm_free_irq(&pdev->dev, msix->vector, chan);
1751 }
1752
1753 pci_disable_msix(pdev);
1754 break;
1755
1756 case IOAT_MSIX_SINGLE:
1757 msix = &device->msix_entries[0];
1758 chan = ioat_chan_by_index(device, 0);
1759 devm_free_irq(&pdev->dev, msix->vector, chan);
1760 pci_disable_msix(pdev);
1761 break;
1762
1763 case IOAT_MSI:
1764 chan = ioat_chan_by_index(device, 0);
1765 devm_free_irq(&pdev->dev, pdev->irq, chan);
1766 pci_disable_msi(pdev);
1767 break;
1768
1769 case IOAT_INTX:
1770 chan = ioat_chan_by_index(device, 0);
1771 devm_free_irq(&pdev->dev, pdev->irq, chan);
1772 break;
1773
1774 default:
1775 return 0;
1776 }
1777
1778 device->irq_mode = IOAT_NOIRQ;
1779
1780 err = ioat_dma_setup_interrupts(device);
1781
1782 return err;
1783}
1784
1170static int ioat3_reset_hw(struct ioat_chan_common *chan) 1785static int ioat3_reset_hw(struct ioat_chan_common *chan)
1171{ 1786{
1172 /* throw away whatever the channel was doing and get it 1787 /* throw away whatever the channel was doing and get it
@@ -1183,80 +1798,65 @@ static int ioat3_reset_hw(struct ioat_chan_common *chan)
1183 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET); 1798 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
1184 writel(chanerr, chan->reg_base + IOAT_CHANERR_OFFSET); 1799 writel(chanerr, chan->reg_base + IOAT_CHANERR_OFFSET);
1185 1800
1186 /* clear any pending errors */ 1801 if (device->version < IOAT_VER_3_3) {
1187 err = pci_read_config_dword(pdev, IOAT_PCI_CHANERR_INT_OFFSET, &chanerr); 1802 /* clear any pending errors */
1803 err = pci_read_config_dword(pdev,
1804 IOAT_PCI_CHANERR_INT_OFFSET, &chanerr);
1805 if (err) {
1806 dev_err(&pdev->dev,
1807 "channel error register unreachable\n");
1808 return err;
1809 }
1810 pci_write_config_dword(pdev,
1811 IOAT_PCI_CHANERR_INT_OFFSET, chanerr);
1812
1813 /* Clear DMAUNCERRSTS Cfg-Reg Parity Error status bit
1814 * (workaround for spurious config parity error after restart)
1815 */
1816 pci_read_config_word(pdev, IOAT_PCI_DEVICE_ID_OFFSET, &dev_id);
1817 if (dev_id == PCI_DEVICE_ID_INTEL_IOAT_TBG0) {
1818 pci_write_config_dword(pdev,
1819 IOAT_PCI_DMAUNCERRSTS_OFFSET,
1820 0x10);
1821 }
1822 }
1823
1824 err = ioat2_reset_sync(chan, msecs_to_jiffies(200));
1188 if (err) { 1825 if (err) {
1189 dev_err(&pdev->dev, "channel error register unreachable\n"); 1826 dev_err(&pdev->dev, "Failed to reset!\n");
1190 return err; 1827 return err;
1191 } 1828 }
1192 pci_write_config_dword(pdev, IOAT_PCI_CHANERR_INT_OFFSET, chanerr);
1193 1829
1194 /* Clear DMAUNCERRSTS Cfg-Reg Parity Error status bit 1830 if (device->irq_mode != IOAT_NOIRQ && is_bwd_ioat(pdev))
1195 * (workaround for spurious config parity error after restart) 1831 err = ioat3_irq_reinit(device);
1196 */
1197 pci_read_config_word(pdev, IOAT_PCI_DEVICE_ID_OFFSET, &dev_id);
1198 if (dev_id == PCI_DEVICE_ID_INTEL_IOAT_TBG0)
1199 pci_write_config_dword(pdev, IOAT_PCI_DMAUNCERRSTS_OFFSET, 0x10);
1200 1832
1201 return ioat2_reset_sync(chan, msecs_to_jiffies(200)); 1833 return err;
1202} 1834}
1203 1835
1204static bool is_jf_ioat(struct pci_dev *pdev) 1836static void ioat3_intr_quirk(struct ioatdma_device *device)
1205{ 1837{
1206 switch (pdev->device) { 1838 struct dma_device *dma;
1207 case PCI_DEVICE_ID_INTEL_IOAT_JSF0: 1839 struct dma_chan *c;
1208 case PCI_DEVICE_ID_INTEL_IOAT_JSF1: 1840 struct ioat_chan_common *chan;
1209 case PCI_DEVICE_ID_INTEL_IOAT_JSF2: 1841 u32 errmask;
1210 case PCI_DEVICE_ID_INTEL_IOAT_JSF3:
1211 case PCI_DEVICE_ID_INTEL_IOAT_JSF4:
1212 case PCI_DEVICE_ID_INTEL_IOAT_JSF5:
1213 case PCI_DEVICE_ID_INTEL_IOAT_JSF6:
1214 case PCI_DEVICE_ID_INTEL_IOAT_JSF7:
1215 case PCI_DEVICE_ID_INTEL_IOAT_JSF8:
1216 case PCI_DEVICE_ID_INTEL_IOAT_JSF9:
1217 return true;
1218 default:
1219 return false;
1220 }
1221}
1222 1842
1223static bool is_snb_ioat(struct pci_dev *pdev) 1843 dma = &device->common;
1224{
1225 switch (pdev->device) {
1226 case PCI_DEVICE_ID_INTEL_IOAT_SNB0:
1227 case PCI_DEVICE_ID_INTEL_IOAT_SNB1:
1228 case PCI_DEVICE_ID_INTEL_IOAT_SNB2:
1229 case PCI_DEVICE_ID_INTEL_IOAT_SNB3:
1230 case PCI_DEVICE_ID_INTEL_IOAT_SNB4:
1231 case PCI_DEVICE_ID_INTEL_IOAT_SNB5:
1232 case PCI_DEVICE_ID_INTEL_IOAT_SNB6:
1233 case PCI_DEVICE_ID_INTEL_IOAT_SNB7:
1234 case PCI_DEVICE_ID_INTEL_IOAT_SNB8:
1235 case PCI_DEVICE_ID_INTEL_IOAT_SNB9:
1236 return true;
1237 default:
1238 return false;
1239 }
1240}
1241 1844
1242static bool is_ivb_ioat(struct pci_dev *pdev) 1845 /*
1243{ 1846 * if we have descriptor write back error status, we mask the
1244 switch (pdev->device) { 1847 * error interrupts
1245 case PCI_DEVICE_ID_INTEL_IOAT_IVB0: 1848 */
1246 case PCI_DEVICE_ID_INTEL_IOAT_IVB1: 1849 if (device->cap & IOAT_CAP_DWBES) {
1247 case PCI_DEVICE_ID_INTEL_IOAT_IVB2: 1850 list_for_each_entry(c, &dma->channels, device_node) {
1248 case PCI_DEVICE_ID_INTEL_IOAT_IVB3: 1851 chan = to_chan_common(c);
1249 case PCI_DEVICE_ID_INTEL_IOAT_IVB4: 1852 errmask = readl(chan->reg_base +
1250 case PCI_DEVICE_ID_INTEL_IOAT_IVB5: 1853 IOAT_CHANERR_MASK_OFFSET);
1251 case PCI_DEVICE_ID_INTEL_IOAT_IVB6: 1854 errmask |= IOAT_CHANERR_XOR_P_OR_CRC_ERR |
1252 case PCI_DEVICE_ID_INTEL_IOAT_IVB7: 1855 IOAT_CHANERR_XOR_Q_ERR;
1253 case PCI_DEVICE_ID_INTEL_IOAT_IVB8: 1856 writel(errmask, chan->reg_base +
1254 case PCI_DEVICE_ID_INTEL_IOAT_IVB9: 1857 IOAT_CHANERR_MASK_OFFSET);
1255 return true; 1858 }
1256 default:
1257 return false;
1258 } 1859 }
1259
1260} 1860}
1261 1861
1262int ioat3_dma_probe(struct ioatdma_device *device, int dca) 1862int ioat3_dma_probe(struct ioatdma_device *device, int dca)
@@ -1268,30 +1868,33 @@ int ioat3_dma_probe(struct ioatdma_device *device, int dca)
1268 struct ioat_chan_common *chan; 1868 struct ioat_chan_common *chan;
1269 bool is_raid_device = false; 1869 bool is_raid_device = false;
1270 int err; 1870 int err;
1271 u32 cap;
1272 1871
1273 device->enumerate_channels = ioat2_enumerate_channels; 1872 device->enumerate_channels = ioat2_enumerate_channels;
1274 device->reset_hw = ioat3_reset_hw; 1873 device->reset_hw = ioat3_reset_hw;
1275 device->self_test = ioat3_dma_self_test; 1874 device->self_test = ioat3_dma_self_test;
1875 device->intr_quirk = ioat3_intr_quirk;
1276 dma = &device->common; 1876 dma = &device->common;
1277 dma->device_prep_dma_memcpy = ioat2_dma_prep_memcpy_lock; 1877 dma->device_prep_dma_memcpy = ioat2_dma_prep_memcpy_lock;
1278 dma->device_issue_pending = ioat2_issue_pending; 1878 dma->device_issue_pending = ioat2_issue_pending;
1279 dma->device_alloc_chan_resources = ioat2_alloc_chan_resources; 1879 dma->device_alloc_chan_resources = ioat2_alloc_chan_resources;
1280 dma->device_free_chan_resources = ioat2_free_chan_resources; 1880 dma->device_free_chan_resources = ioat2_free_chan_resources;
1281 1881
1282 if (is_jf_ioat(pdev) || is_snb_ioat(pdev) || is_ivb_ioat(pdev)) 1882 if (is_xeon_cb32(pdev))
1283 dma->copy_align = 6; 1883 dma->copy_align = 6;
1284 1884
1285 dma_cap_set(DMA_INTERRUPT, dma->cap_mask); 1885 dma_cap_set(DMA_INTERRUPT, dma->cap_mask);
1286 dma->device_prep_dma_interrupt = ioat3_prep_interrupt_lock; 1886 dma->device_prep_dma_interrupt = ioat3_prep_interrupt_lock;
1287 1887
1288 cap = readl(device->reg_base + IOAT_DMA_CAP_OFFSET); 1888 device->cap = readl(device->reg_base + IOAT_DMA_CAP_OFFSET);
1889
1890 if (is_bwd_noraid(pdev))
1891 device->cap &= ~(IOAT_CAP_XOR | IOAT_CAP_PQ | IOAT_CAP_RAID16SS);
1289 1892
1290 /* dca is incompatible with raid operations */ 1893 /* dca is incompatible with raid operations */
1291 if (dca_en && (cap & (IOAT_CAP_XOR|IOAT_CAP_PQ))) 1894 if (dca_en && (device->cap & (IOAT_CAP_XOR|IOAT_CAP_PQ)))
1292 cap &= ~(IOAT_CAP_XOR|IOAT_CAP_PQ); 1895 device->cap &= ~(IOAT_CAP_XOR|IOAT_CAP_PQ);
1293 1896
1294 if (cap & IOAT_CAP_XOR) { 1897 if (device->cap & IOAT_CAP_XOR) {
1295 is_raid_device = true; 1898 is_raid_device = true;
1296 dma->max_xor = 8; 1899 dma->max_xor = 8;
1297 dma->xor_align = 6; 1900 dma->xor_align = 6;
@@ -1302,53 +1905,86 @@ int ioat3_dma_probe(struct ioatdma_device *device, int dca)
1302 dma_cap_set(DMA_XOR_VAL, dma->cap_mask); 1905 dma_cap_set(DMA_XOR_VAL, dma->cap_mask);
1303 dma->device_prep_dma_xor_val = ioat3_prep_xor_val; 1906 dma->device_prep_dma_xor_val = ioat3_prep_xor_val;
1304 } 1907 }
1305 if (cap & IOAT_CAP_PQ) { 1908
1909 if (device->cap & IOAT_CAP_PQ) {
1306 is_raid_device = true; 1910 is_raid_device = true;
1307 dma_set_maxpq(dma, 8, 0);
1308 dma->pq_align = 6;
1309 1911
1310 dma_cap_set(DMA_PQ, dma->cap_mask);
1311 dma->device_prep_dma_pq = ioat3_prep_pq; 1912 dma->device_prep_dma_pq = ioat3_prep_pq;
1312
1313 dma_cap_set(DMA_PQ_VAL, dma->cap_mask);
1314 dma->device_prep_dma_pq_val = ioat3_prep_pq_val; 1913 dma->device_prep_dma_pq_val = ioat3_prep_pq_val;
1914 dma_cap_set(DMA_PQ, dma->cap_mask);
1915 dma_cap_set(DMA_PQ_VAL, dma->cap_mask);
1315 1916
1316 if (!(cap & IOAT_CAP_XOR)) { 1917 if (device->cap & IOAT_CAP_RAID16SS) {
1317 dma->max_xor = 8; 1918 dma_set_maxpq(dma, 16, 0);
1318 dma->xor_align = 6; 1919 dma->pq_align = 0;
1920 } else {
1921 dma_set_maxpq(dma, 8, 0);
1922 if (is_xeon_cb32(pdev))
1923 dma->pq_align = 6;
1924 else
1925 dma->pq_align = 0;
1926 }
1319 1927
1320 dma_cap_set(DMA_XOR, dma->cap_mask); 1928 if (!(device->cap & IOAT_CAP_XOR)) {
1321 dma->device_prep_dma_xor = ioat3_prep_pqxor; 1929 dma->device_prep_dma_xor = ioat3_prep_pqxor;
1322
1323 dma_cap_set(DMA_XOR_VAL, dma->cap_mask);
1324 dma->device_prep_dma_xor_val = ioat3_prep_pqxor_val; 1930 dma->device_prep_dma_xor_val = ioat3_prep_pqxor_val;
1931 dma_cap_set(DMA_XOR, dma->cap_mask);
1932 dma_cap_set(DMA_XOR_VAL, dma->cap_mask);
1933
1934 if (device->cap & IOAT_CAP_RAID16SS) {
1935 dma->max_xor = 16;
1936 dma->xor_align = 0;
1937 } else {
1938 dma->max_xor = 8;
1939 if (is_xeon_cb32(pdev))
1940 dma->xor_align = 6;
1941 else
1942 dma->xor_align = 0;
1943 }
1325 } 1944 }
1326 } 1945 }
1327 if (is_raid_device && (cap & IOAT_CAP_FILL_BLOCK)) { 1946
1947 if (is_raid_device && (device->cap & IOAT_CAP_FILL_BLOCK)) {
1328 dma_cap_set(DMA_MEMSET, dma->cap_mask); 1948 dma_cap_set(DMA_MEMSET, dma->cap_mask);
1329 dma->device_prep_dma_memset = ioat3_prep_memset_lock; 1949 dma->device_prep_dma_memset = ioat3_prep_memset_lock;
1330 } 1950 }
1331 1951
1332 1952
1333 if (is_raid_device) { 1953 dma->device_tx_status = ioat3_tx_status;
1334 dma->device_tx_status = ioat3_tx_status; 1954 device->cleanup_fn = ioat3_cleanup_event;
1335 device->cleanup_fn = ioat3_cleanup_event; 1955 device->timer_fn = ioat3_timer_event;
1336 device->timer_fn = ioat3_timer_event; 1956
1337 } else { 1957 if (is_xeon_cb32(pdev)) {
1338 dma->device_tx_status = ioat_dma_tx_status; 1958 dma_cap_clear(DMA_XOR_VAL, dma->cap_mask);
1339 device->cleanup_fn = ioat2_cleanup_event; 1959 dma->device_prep_dma_xor_val = NULL;
1340 device->timer_fn = ioat2_timer_event; 1960
1961 dma_cap_clear(DMA_PQ_VAL, dma->cap_mask);
1962 dma->device_prep_dma_pq_val = NULL;
1341 } 1963 }
1342 1964
1343 #ifdef CONFIG_ASYNC_TX_DISABLE_PQ_VAL_DMA 1965 /* starting with CB3.3 super extended descriptors are supported */
1344 dma_cap_clear(DMA_PQ_VAL, dma->cap_mask); 1966 if (device->cap & IOAT_CAP_RAID16SS) {
1345 dma->device_prep_dma_pq_val = NULL; 1967 char pool_name[14];
1346 #endif 1968 int i;
1969
1970 /* allocate sw descriptor pool for SED */
1971 device->sed_pool = kmem_cache_create("ioat_sed",
1972 sizeof(struct ioat_sed_ent), 0, 0, NULL);
1973 if (!device->sed_pool)
1974 return -ENOMEM;
1975
1976 for (i = 0; i < MAX_SED_POOLS; i++) {
1977 snprintf(pool_name, 14, "ioat_hw%d_sed", i);
1347 1978
1348 #ifdef CONFIG_ASYNC_TX_DISABLE_XOR_VAL_DMA 1979 /* allocate SED DMA pool */
1349 dma_cap_clear(DMA_XOR_VAL, dma->cap_mask); 1980 device->sed_hw_pool[i] = dma_pool_create(pool_name,
1350 dma->device_prep_dma_xor_val = NULL; 1981 &pdev->dev,
1351 #endif 1982 SED_SIZE * (i + 1), 64, 0);
1983 if (!device->sed_hw_pool[i])
1984 goto sed_pool_cleanup;
1985
1986 }
1987 }
1352 1988
1353 err = ioat_probe(device); 1989 err = ioat_probe(device);
1354 if (err) 1990 if (err)
@@ -1371,4 +2007,28 @@ int ioat3_dma_probe(struct ioatdma_device *device, int dca)
1371 device->dca = ioat3_dca_init(pdev, device->reg_base); 2007 device->dca = ioat3_dca_init(pdev, device->reg_base);
1372 2008
1373 return 0; 2009 return 0;
2010
2011sed_pool_cleanup:
2012 if (device->sed_pool) {
2013 int i;
2014 kmem_cache_destroy(device->sed_pool);
2015
2016 for (i = 0; i < MAX_SED_POOLS; i++)
2017 if (device->sed_hw_pool[i])
2018 dma_pool_destroy(device->sed_hw_pool[i]);
2019 }
2020
2021 return -ENOMEM;
2022}
2023
2024void ioat3_dma_remove(struct ioatdma_device *device)
2025{
2026 if (device->sed_pool) {
2027 int i;
2028 kmem_cache_destroy(device->sed_pool);
2029
2030 for (i = 0; i < MAX_SED_POOLS; i++)
2031 if (device->sed_hw_pool[i])
2032 dma_pool_destroy(device->sed_hw_pool[i]);
2033 }
1374} 2034}
diff --git a/drivers/dma/ioat/hw.h b/drivers/dma/ioat/hw.h
index 7cb74c62c719..5ee57d402a6e 100644
--- a/drivers/dma/ioat/hw.h
+++ b/drivers/dma/ioat/hw.h
@@ -30,11 +30,6 @@
30#define IOAT_PCI_DID_SCNB 0x65FF 30#define IOAT_PCI_DID_SCNB 0x65FF
31#define IOAT_PCI_DID_SNB 0x402F 31#define IOAT_PCI_DID_SNB 0x402F
32 32
33#define IOAT_VER_1_2 0x12 /* Version 1.2 */
34#define IOAT_VER_2_0 0x20 /* Version 2.0 */
35#define IOAT_VER_3_0 0x30 /* Version 3.0 */
36#define IOAT_VER_3_2 0x32 /* Version 3.2 */
37
38#define PCI_DEVICE_ID_INTEL_IOAT_IVB0 0x0e20 33#define PCI_DEVICE_ID_INTEL_IOAT_IVB0 0x0e20
39#define PCI_DEVICE_ID_INTEL_IOAT_IVB1 0x0e21 34#define PCI_DEVICE_ID_INTEL_IOAT_IVB1 0x0e21
40#define PCI_DEVICE_ID_INTEL_IOAT_IVB2 0x0e22 35#define PCI_DEVICE_ID_INTEL_IOAT_IVB2 0x0e22
@@ -46,6 +41,29 @@
46#define PCI_DEVICE_ID_INTEL_IOAT_IVB8 0x0e2e 41#define PCI_DEVICE_ID_INTEL_IOAT_IVB8 0x0e2e
47#define PCI_DEVICE_ID_INTEL_IOAT_IVB9 0x0e2f 42#define PCI_DEVICE_ID_INTEL_IOAT_IVB9 0x0e2f
48 43
44#define PCI_DEVICE_ID_INTEL_IOAT_HSW0 0x2f20
45#define PCI_DEVICE_ID_INTEL_IOAT_HSW1 0x2f21
46#define PCI_DEVICE_ID_INTEL_IOAT_HSW2 0x2f22
47#define PCI_DEVICE_ID_INTEL_IOAT_HSW3 0x2f23
48#define PCI_DEVICE_ID_INTEL_IOAT_HSW4 0x2f24
49#define PCI_DEVICE_ID_INTEL_IOAT_HSW5 0x2f25
50#define PCI_DEVICE_ID_INTEL_IOAT_HSW6 0x2f26
51#define PCI_DEVICE_ID_INTEL_IOAT_HSW7 0x2f27
52#define PCI_DEVICE_ID_INTEL_IOAT_HSW8 0x2f2e
53#define PCI_DEVICE_ID_INTEL_IOAT_HSW9 0x2f2f
54
55#define PCI_DEVICE_ID_INTEL_IOAT_BWD0 0x0C50
56#define PCI_DEVICE_ID_INTEL_IOAT_BWD1 0x0C51
57#define PCI_DEVICE_ID_INTEL_IOAT_BWD2 0x0C52
58#define PCI_DEVICE_ID_INTEL_IOAT_BWD3 0x0C53
59
60#define IOAT_VER_1_2 0x12 /* Version 1.2 */
61#define IOAT_VER_2_0 0x20 /* Version 2.0 */
62#define IOAT_VER_3_0 0x30 /* Version 3.0 */
63#define IOAT_VER_3_2 0x32 /* Version 3.2 */
64#define IOAT_VER_3_3 0x33 /* Version 3.3 */
65
66
49int system_has_dca_enabled(struct pci_dev *pdev); 67int system_has_dca_enabled(struct pci_dev *pdev);
50 68
51struct ioat_dma_descriptor { 69struct ioat_dma_descriptor {
@@ -147,7 +165,17 @@ struct ioat_xor_ext_descriptor {
147}; 165};
148 166
149struct ioat_pq_descriptor { 167struct ioat_pq_descriptor {
150 uint32_t size; 168 union {
169 uint32_t size;
170 uint32_t dwbes;
171 struct {
172 unsigned int rsvd:25;
173 unsigned int p_val_err:1;
174 unsigned int q_val_err:1;
175 unsigned int rsvd1:4;
176 unsigned int wbes:1;
177 } dwbes_f;
178 };
151 union { 179 union {
152 uint32_t ctl; 180 uint32_t ctl;
153 struct { 181 struct {
@@ -162,9 +190,14 @@ struct ioat_pq_descriptor {
162 unsigned int hint:1; 190 unsigned int hint:1;
163 unsigned int p_disable:1; 191 unsigned int p_disable:1;
164 unsigned int q_disable:1; 192 unsigned int q_disable:1;
165 unsigned int rsvd:11; 193 unsigned int rsvd2:2;
194 unsigned int wb_en:1;
195 unsigned int prl_en:1;
196 unsigned int rsvd3:7;
166 #define IOAT_OP_PQ 0x89 197 #define IOAT_OP_PQ 0x89
167 #define IOAT_OP_PQ_VAL 0x8a 198 #define IOAT_OP_PQ_VAL 0x8a
199 #define IOAT_OP_PQ_16S 0xa0
200 #define IOAT_OP_PQ_VAL_16S 0xa1
168 unsigned int op:8; 201 unsigned int op:8;
169 } ctl_f; 202 } ctl_f;
170 }; 203 };
@@ -172,7 +205,10 @@ struct ioat_pq_descriptor {
172 uint64_t p_addr; 205 uint64_t p_addr;
173 uint64_t next; 206 uint64_t next;
174 uint64_t src_addr2; 207 uint64_t src_addr2;
175 uint64_t src_addr3; 208 union {
209 uint64_t src_addr3;
210 uint64_t sed_addr;
211 };
176 uint8_t coef[8]; 212 uint8_t coef[8];
177 uint64_t q_addr; 213 uint64_t q_addr;
178}; 214};
@@ -221,4 +257,40 @@ struct ioat_pq_update_descriptor {
221struct ioat_raw_descriptor { 257struct ioat_raw_descriptor {
222 uint64_t field[8]; 258 uint64_t field[8];
223}; 259};
260
261struct ioat_pq16a_descriptor {
262 uint8_t coef[8];
263 uint64_t src_addr3;
264 uint64_t src_addr4;
265 uint64_t src_addr5;
266 uint64_t src_addr6;
267 uint64_t src_addr7;
268 uint64_t src_addr8;
269 uint64_t src_addr9;
270};
271
272struct ioat_pq16b_descriptor {
273 uint64_t src_addr10;
274 uint64_t src_addr11;
275 uint64_t src_addr12;
276 uint64_t src_addr13;
277 uint64_t src_addr14;
278 uint64_t src_addr15;
279 uint64_t src_addr16;
280 uint64_t rsvd;
281};
282
283union ioat_sed_pq_descriptor {
284 struct ioat_pq16a_descriptor a;
285 struct ioat_pq16b_descriptor b;
286};
287
288#define SED_SIZE 64
289
290struct ioat_sed_raw_descriptor {
291 uint64_t a[8];
292 uint64_t b[8];
293 uint64_t c[8];
294};
295
224#endif 296#endif
diff --git a/drivers/dma/ioat/pci.c b/drivers/dma/ioat/pci.c
index 71c7ecd80fac..2c8d560e6334 100644
--- a/drivers/dma/ioat/pci.c
+++ b/drivers/dma/ioat/pci.c
@@ -94,6 +94,23 @@ static struct pci_device_id ioat_pci_tbl[] = {
94 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_IVB8) }, 94 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_IVB8) },
95 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_IVB9) }, 95 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_IVB9) },
96 96
97 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_HSW0) },
98 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_HSW1) },
99 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_HSW2) },
100 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_HSW3) },
101 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_HSW4) },
102 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_HSW5) },
103 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_HSW6) },
104 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_HSW7) },
105 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_HSW8) },
106 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_HSW9) },
107
108 /* I/OAT v3.3 platforms */
109 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_BWD0) },
110 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_BWD1) },
111 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_BWD2) },
112 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IOAT_BWD3) },
113
97 { 0, } 114 { 0, }
98}; 115};
99MODULE_DEVICE_TABLE(pci, ioat_pci_tbl); 116MODULE_DEVICE_TABLE(pci, ioat_pci_tbl);
@@ -190,6 +207,9 @@ static void ioat_remove(struct pci_dev *pdev)
190 if (!device) 207 if (!device)
191 return; 208 return;
192 209
210 if (device->version >= IOAT_VER_3_0)
211 ioat3_dma_remove(device);
212
193 dev_err(&pdev->dev, "Removing dma and dca services\n"); 213 dev_err(&pdev->dev, "Removing dma and dca services\n");
194 if (device->dca) { 214 if (device->dca) {
195 unregister_dca_provider(device->dca, &pdev->dev); 215 unregister_dca_provider(device->dca, &pdev->dev);
diff --git a/drivers/dma/ioat/registers.h b/drivers/dma/ioat/registers.h
index 1391798542b6..2f1cfa0f1f47 100644
--- a/drivers/dma/ioat/registers.h
+++ b/drivers/dma/ioat/registers.h
@@ -79,6 +79,8 @@
79#define IOAT_CAP_APIC 0x00000080 79#define IOAT_CAP_APIC 0x00000080
80#define IOAT_CAP_XOR 0x00000100 80#define IOAT_CAP_XOR 0x00000100
81#define IOAT_CAP_PQ 0x00000200 81#define IOAT_CAP_PQ 0x00000200
82#define IOAT_CAP_DWBES 0x00002000
83#define IOAT_CAP_RAID16SS 0x00020000
82 84
83#define IOAT_CHANNEL_MMIO_SIZE 0x80 /* Each Channel MMIO space is this size */ 85#define IOAT_CHANNEL_MMIO_SIZE 0x80 /* Each Channel MMIO space is this size */
84 86
@@ -93,6 +95,8 @@
93#define IOAT_CHANCTRL_ERR_COMPLETION_EN 0x0004 95#define IOAT_CHANCTRL_ERR_COMPLETION_EN 0x0004
94#define IOAT_CHANCTRL_INT_REARM 0x0001 96#define IOAT_CHANCTRL_INT_REARM 0x0001
95#define IOAT_CHANCTRL_RUN (IOAT_CHANCTRL_INT_REARM |\ 97#define IOAT_CHANCTRL_RUN (IOAT_CHANCTRL_INT_REARM |\
98 IOAT_CHANCTRL_ERR_INT_EN |\
99 IOAT_CHANCTRL_ERR_COMPLETION_EN |\
96 IOAT_CHANCTRL_ANY_ERR_ABORT_EN) 100 IOAT_CHANCTRL_ANY_ERR_ABORT_EN)
97 101
98#define IOAT_DMA_COMP_OFFSET 0x02 /* 16-bit DMA channel compatibility */ 102#define IOAT_DMA_COMP_OFFSET 0x02 /* 16-bit DMA channel compatibility */