2 * Intel I/OAT DMA Linux driver
3 * Copyright(c) 2007 - 2009 Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * The full GNU General Public License is included in this distribution in
15 * the file called "COPYING".
20 * This driver supports an Intel I/OAT DMA engine, which does asynchronous
24 #include <linux/init.h>
25 #include <linux/module.h>
26 #include <linux/pci.h>
27 #include <linux/interrupt.h>
28 #include <linux/dca.h>
29 #include <linux/slab.h>
30 #include <linux/acpi.h>
33 #include "registers.h"
36 MODULE_VERSION(IOAT_DMA_VERSION
);
37 MODULE_LICENSE("Dual BSD/GPL");
38 MODULE_AUTHOR("Intel Corporation");
40 static struct pci_device_id ioat_pci_tbl
[] = {
41 /* I/OAT v1 platforms */
42 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT
) },
43 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_CNB
) },
44 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_SCNB
) },
45 { PCI_VDEVICE(UNISYS
, PCI_DEVICE_ID_UNISYS_DMA_DIRECTOR
) },
47 /* I/OAT v2 platforms */
48 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_SNB
) },
50 /* I/OAT v3 platforms */
51 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_TBG0
) },
52 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_TBG1
) },
53 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_TBG2
) },
54 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_TBG3
) },
55 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_TBG4
) },
56 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_TBG5
) },
57 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_TBG6
) },
58 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_TBG7
) },
60 /* I/OAT v3.2 platforms */
61 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_JSF0
) },
62 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_JSF1
) },
63 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_JSF2
) },
64 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_JSF3
) },
65 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_JSF4
) },
66 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_JSF5
) },
67 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_JSF6
) },
68 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_JSF7
) },
69 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_JSF8
) },
70 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_JSF9
) },
72 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_SNB0
) },
73 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_SNB1
) },
74 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_SNB2
) },
75 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_SNB3
) },
76 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_SNB4
) },
77 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_SNB5
) },
78 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_SNB6
) },
79 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_SNB7
) },
80 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_SNB8
) },
81 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_SNB9
) },
83 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_IVB0
) },
84 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_IVB1
) },
85 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_IVB2
) },
86 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_IVB3
) },
87 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_IVB4
) },
88 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_IVB5
) },
89 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_IVB6
) },
90 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_IVB7
) },
91 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_IVB8
) },
92 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_IVB9
) },
94 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_HSW0
) },
95 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_HSW1
) },
96 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_HSW2
) },
97 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_HSW3
) },
98 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_HSW4
) },
99 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_HSW5
) },
100 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_HSW6
) },
101 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_HSW7
) },
102 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_HSW8
) },
103 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_HSW9
) },
105 /* I/OAT v3.3 platforms */
106 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_BWD0
) },
107 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_BWD1
) },
108 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_BWD2
) },
109 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_BWD3
) },
111 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_BDXDE0
) },
112 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_BDXDE1
) },
113 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_BDXDE2
) },
114 { PCI_VDEVICE(INTEL
, PCI_DEVICE_ID_INTEL_IOAT_BDXDE3
) },
118 MODULE_DEVICE_TABLE(pci
, ioat_pci_tbl
);
120 static int ioat_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
);
121 static void ioat_remove(struct pci_dev
*pdev
);
123 static int ioat_dca_enabled
= 1;
124 module_param(ioat_dca_enabled
, int, 0644);
125 MODULE_PARM_DESC(ioat_dca_enabled
, "control support of dca service (default: 1)");
127 struct kmem_cache
*ioat2_cache
;
128 struct kmem_cache
*ioat3_sed_cache
;
130 #define DRV_NAME "ioatdma"
132 static struct pci_driver ioat_pci_driver
= {
134 .id_table
= ioat_pci_tbl
,
135 .probe
= ioat_pci_probe
,
136 .remove
= ioat_remove
,
139 static struct ioatdma_device
*
140 alloc_ioatdma(struct pci_dev
*pdev
, void __iomem
*iobase
)
142 struct device
*dev
= &pdev
->dev
;
143 struct ioatdma_device
*d
= devm_kzalloc(dev
, sizeof(*d
), GFP_KERNEL
);
148 d
->reg_base
= iobase
;
153 * The dmaengine core assumes that async DMA devices will only be removed
154 * when they not used anymore, or it assumes dma_async_device_unregister()
155 * will only be called by dma driver exit routines. But this assumption is
156 * not true for the IOAT driver, which calls dma_async_device_unregister()
157 * from ioat_remove(). So current IOAT driver doesn't support device
158 * hot-removal because it may cause system crash to hot-remove inuse IOAT
161 * This is a hack to disable IOAT devices under ejectable PCI host bridge
162 * so it won't break PCI host bridge hot-removal.
164 static bool ioat_pci_has_ejectable_acpi_ancestor(struct pci_dev
*pdev
)
167 struct pci_bus
*bus
= pdev
->bus
;
168 struct acpi_device
*adev
;
172 for (adev
= ACPI_COMPANION(bus
->bridge
); adev
; adev
= adev
->parent
)
173 if (adev
->flags
.ejectable
)
180 static int ioat_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
182 void __iomem
* const *iomap
;
183 struct device
*dev
= &pdev
->dev
;
184 struct ioatdma_device
*device
;
187 if (ioat_pci_has_ejectable_acpi_ancestor(pdev
)) {
188 dev_dbg(&pdev
->dev
, "ignore ejectable IOAT device.\n");
192 err
= pcim_enable_device(pdev
);
196 err
= pcim_iomap_regions(pdev
, 1 << IOAT_MMIO_BAR
, DRV_NAME
);
199 iomap
= pcim_iomap_table(pdev
);
203 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(64));
205 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
209 err
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64));
211 err
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
215 device
= alloc_ioatdma(pdev
, iomap
[IOAT_MMIO_BAR
]);
218 pci_set_master(pdev
);
219 pci_set_drvdata(pdev
, device
);
221 device
->version
= readb(device
->reg_base
+ IOAT_VER_OFFSET
);
222 if (device
->version
== IOAT_VER_1_2
)
223 err
= ioat1_dma_probe(device
, ioat_dca_enabled
);
224 else if (device
->version
== IOAT_VER_2_0
)
225 err
= ioat2_dma_probe(device
, ioat_dca_enabled
);
226 else if (device
->version
>= IOAT_VER_3_0
)
227 err
= ioat3_dma_probe(device
, ioat_dca_enabled
);
232 dev_err(dev
, "Intel(R) I/OAT DMA Engine init failed\n");
239 static void ioat_remove(struct pci_dev
*pdev
)
241 struct ioatdma_device
*device
= pci_get_drvdata(pdev
);
246 dev_err(&pdev
->dev
, "Removing dma and dca services\n");
248 unregister_dca_provider(device
->dca
, &pdev
->dev
);
249 free_dca_provider(device
->dca
);
252 ioat_dma_remove(device
);
255 static int __init
ioat_init_module(void)
259 pr_info("%s: Intel(R) QuickData Technology Driver %s\n",
260 DRV_NAME
, IOAT_DMA_VERSION
);
262 ioat2_cache
= kmem_cache_create("ioat2", sizeof(struct ioat_ring_ent
),
263 0, SLAB_HWCACHE_ALIGN
, NULL
);
267 ioat3_sed_cache
= KMEM_CACHE(ioat_sed_ent
, 0);
268 if (!ioat3_sed_cache
)
269 goto err_ioat2_cache
;
271 err
= pci_register_driver(&ioat_pci_driver
);
273 goto err_ioat3_cache
;
278 kmem_cache_destroy(ioat3_sed_cache
);
281 kmem_cache_destroy(ioat2_cache
);
285 module_init(ioat_init_module
);
287 static void __exit
ioat_exit_module(void)
289 pci_unregister_driver(&ioat_pci_driver
);
290 kmem_cache_destroy(ioat2_cache
);
292 module_exit(ioat_exit_module
);