Commit | Line | Data |
---|---|---|
8ab89567 SN |
1 | /* |
2 | * Intel I/OAT DMA Linux driver | |
211a22ce | 3 | * Copyright(c) 2007 - 2009 Intel Corporation. |
8ab89567 SN |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms and conditions of the GNU General Public License, | |
7 | * version 2, as published by the Free Software Foundation. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
12 | * more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License along with | |
15 | * this program; if not, write to the Free Software Foundation, Inc., | |
16 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | |
17 | * | |
18 | * The full GNU General Public License is included in this distribution in | |
19 | * the file called "COPYING". | |
20 | * | |
21 | */ | |
22 | ||
23 | /* | |
24 | * This driver supports an Intel I/OAT DMA engine, which does asynchronous | |
25 | * copy operations. | |
26 | */ | |
27 | ||
28 | #include <linux/init.h> | |
29 | #include <linux/module.h> | |
30 | #include <linux/pci.h> | |
31 | #include <linux/interrupt.h> | |
2ed6dc34 | 32 | #include <linux/dca.h> |
584ec227 DW |
33 | #include "dma.h" |
34 | #include "registers.h" | |
35 | #include "hw.h" | |
8ab89567 | 36 | |
5149fd01 | 37 | MODULE_VERSION(IOAT_DMA_VERSION); |
8ab89567 SN |
38 | MODULE_LICENSE("GPL"); |
39 | MODULE_AUTHOR("Intel Corporation"); | |
40 | ||
41 | static struct pci_device_id ioat_pci_tbl[] = { | |
7bb67c14 | 42 | /* I/OAT v1 platforms */ |
8ab89567 SN |
43 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT) }, |
44 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_CNB) }, | |
45 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_SCNB) }, | |
46 | { PCI_DEVICE(PCI_VENDOR_ID_UNISYS, PCI_DEVICE_ID_UNISYS_DMA_DIRECTOR) }, | |
7bb67c14 SN |
47 | |
48 | /* I/OAT v2 platforms */ | |
49 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_SNB) }, | |
7f1b358a MS |
50 | |
51 | /* I/OAT v3 platforms */ | |
52 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG0) }, | |
53 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG1) }, | |
54 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG2) }, | |
55 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG3) }, | |
56 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG4) }, | |
57 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG5) }, | |
58 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG6) }, | |
59 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG7) }, | |
8ab89567 SN |
60 | { 0, } |
61 | }; | |
62 | ||
f2427e27 DW |
63 | static int __devinit ioat_pci_probe(struct pci_dev *pdev, |
64 | const struct pci_device_id *id); | |
8ab89567 | 65 | static void __devexit ioat_remove(struct pci_dev *pdev); |
8ab89567 | 66 | |
2ed6dc34 SN |
67 | static int ioat_dca_enabled = 1; |
68 | module_param(ioat_dca_enabled, int, 0644); | |
69 | MODULE_PARM_DESC(ioat_dca_enabled, "control support of dca service (default: 1)"); | |
70 | ||
e6c0b69a DW |
71 | #define DRV_NAME "ioatdma" |
72 | ||
7df7cf06 | 73 | static struct pci_driver ioat_pci_driver = { |
e6c0b69a | 74 | .name = DRV_NAME, |
8ab89567 | 75 | .id_table = ioat_pci_tbl, |
f2427e27 | 76 | .probe = ioat_pci_probe, |
8ab89567 | 77 | .remove = __devexit_p(ioat_remove), |
8ab89567 SN |
78 | }; |
79 | ||
f2427e27 DW |
80 | static struct ioatdma_device * |
81 | alloc_ioatdma(struct pci_dev *pdev, void __iomem *iobase) | |
82 | { | |
83 | struct device *dev = &pdev->dev; | |
84 | struct ioatdma_device *d = devm_kzalloc(dev, sizeof(*d), GFP_KERNEL); | |
85 | ||
86 | if (!d) | |
87 | return NULL; | |
88 | d->pdev = pdev; | |
89 | d->reg_base = iobase; | |
90 | return d; | |
91 | } | |
92 | ||
93 | static int __devinit ioat_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) | |
8ab89567 | 94 | { |
e6c0b69a | 95 | void __iomem * const *iomap; |
e6c0b69a | 96 | struct device *dev = &pdev->dev; |
f2427e27 | 97 | struct ioatdma_device *device; |
8ab89567 SN |
98 | int err; |
99 | ||
e6c0b69a | 100 | err = pcim_enable_device(pdev); |
8ab89567 | 101 | if (err) |
e6c0b69a | 102 | return err; |
8ab89567 | 103 | |
e6c0b69a | 104 | err = pcim_iomap_regions(pdev, 1 << IOAT_MMIO_BAR, DRV_NAME); |
8ab89567 | 105 | if (err) |
e6c0b69a DW |
106 | return err; |
107 | iomap = pcim_iomap_table(pdev); | |
108 | if (!iomap) | |
109 | return -ENOMEM; | |
8ab89567 | 110 | |
6a35528a | 111 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)); |
8ab89567 | 112 | if (err) |
284901a9 | 113 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
8ab89567 | 114 | if (err) |
e6c0b69a | 115 | return err; |
8ab89567 | 116 | |
6a35528a | 117 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); |
8ab89567 | 118 | if (err) |
284901a9 | 119 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
8ab89567 | 120 | if (err) |
e6c0b69a DW |
121 | return err; |
122 | ||
123 | device = devm_kzalloc(dev, sizeof(*device), GFP_KERNEL); | |
124 | if (!device) | |
125 | return -ENOMEM; | |
8ab89567 | 126 | |
8ab89567 SN |
127 | pci_set_master(pdev); |
128 | ||
f2427e27 DW |
129 | device = alloc_ioatdma(pdev, iomap[IOAT_MMIO_BAR]); |
130 | if (!device) | |
131 | return -ENOMEM; | |
132 | pci_set_drvdata(pdev, device); | |
133 | ||
134 | device->version = readb(device->reg_base + IOAT_VER_OFFSET); | |
135 | if (device->version == IOAT_VER_1_2) | |
136 | err = ioat1_dma_probe(device, ioat_dca_enabled); | |
137 | else if (device->version == IOAT_VER_2_0) | |
138 | err = ioat2_dma_probe(device, ioat_dca_enabled); | |
139 | else if (device->version >= IOAT_VER_3_0) | |
140 | err = ioat3_dma_probe(device, ioat_dca_enabled); | |
141 | else | |
e6c0b69a | 142 | return -ENODEV; |
4fac7fa5 | 143 | |
f2427e27 | 144 | if (err) { |
e6c0b69a DW |
145 | dev_err(dev, "Intel(R) I/OAT DMA Engine init failed\n"); |
146 | return -ENODEV; | |
147 | } | |
8ab89567 SN |
148 | |
149 | return 0; | |
8ab89567 SN |
150 | } |
151 | ||
8ab89567 SN |
152 | static void __devexit ioat_remove(struct pci_dev *pdev) |
153 | { | |
f2427e27 DW |
154 | struct ioatdma_device *device = pci_get_drvdata(pdev); |
155 | ||
156 | if (!device) | |
157 | return; | |
8ab89567 | 158 | |
4fac7fa5 DW |
159 | dev_err(&pdev->dev, "Removing dma and dca services\n"); |
160 | if (device->dca) { | |
161 | unregister_dca_provider(device->dca); | |
162 | free_dca_provider(device->dca); | |
163 | device->dca = NULL; | |
164 | } | |
f2427e27 | 165 | ioat_dma_remove(device); |
8ab89567 | 166 | } |
8ab89567 SN |
167 | |
168 | static int __init ioat_init_module(void) | |
169 | { | |
7df7cf06 | 170 | return pci_register_driver(&ioat_pci_driver); |
8ab89567 SN |
171 | } |
172 | module_init(ioat_init_module); | |
173 | ||
174 | static void __exit ioat_exit_module(void) | |
175 | { | |
7df7cf06 | 176 | pci_unregister_driver(&ioat_pci_driver); |
8ab89567 SN |
177 | } |
178 | module_exit(ioat_exit_module); |