2 * Intel I/OAT DMA Linux driver
3 * Copyright(c) 2004 - 2007 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 * 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.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
24 * This driver supports an Intel I/OAT DMA engine, which does asynchronous
28 #include <linux/init.h>
29 #include <linux/module.h>
30 #include <linux/pci.h>
31 #include <linux/interrupt.h>
33 #include "ioatdma_registers.h"
34 #include "ioatdma_hw.h"
36 MODULE_VERSION("1.24");
37 MODULE_LICENSE("GPL");
38 MODULE_AUTHOR("Intel Corporation");
40 static struct pci_device_id ioat_pci_tbl
[] = {
41 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_IOAT
) },
42 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_IOAT_CNB
) },
43 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_IOAT_SCNB
) },
44 { PCI_DEVICE(PCI_VENDOR_ID_UNISYS
, PCI_DEVICE_ID_UNISYS_DMA_DIRECTOR
) },
51 struct ioatdma_device
*dma
;
54 static int __devinit
ioat_probe(struct pci_dev
*pdev
,
55 const struct pci_device_id
*id
);
56 #ifdef IOAT_DMA_REMOVE
57 static void __devexit
ioat_remove(struct pci_dev
*pdev
);
60 static int ioat_setup_functionality(struct pci_dev
*pdev
, void __iomem
*iobase
)
62 struct ioat_device
*device
= pci_get_drvdata(pdev
);
66 version
= readb(iobase
+ IOAT_VER_OFFSET
);
69 device
->dma
= ioat_dma_probe(pdev
, iobase
);
78 static void ioat_shutdown_functionality(struct pci_dev
*pdev
)
80 struct ioat_device
*device
= pci_get_drvdata(pdev
);
83 ioat_dma_remove(device
->dma
);
88 static struct pci_driver ioat_pci_drv
= {
90 .id_table
= ioat_pci_tbl
,
92 .shutdown
= ioat_shutdown_functionality
,
93 #ifdef IOAT_DMA_REMOVE
94 .remove
= __devexit_p(ioat_remove
),
98 static int __devinit
ioat_probe(struct pci_dev
*pdev
,
99 const struct pci_device_id
*id
)
101 void __iomem
*iobase
;
102 struct ioat_device
*device
;
103 unsigned long mmio_start
, mmio_len
;
106 err
= pci_enable_device(pdev
);
108 goto err_enable_device
;
110 err
= pci_request_regions(pdev
, ioat_pci_drv
.name
);
112 goto err_request_regions
;
114 err
= pci_set_dma_mask(pdev
, DMA_64BIT_MASK
);
116 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
118 goto err_set_dma_mask
;
120 err
= pci_set_consistent_dma_mask(pdev
, DMA_64BIT_MASK
);
122 err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
124 goto err_set_dma_mask
;
126 mmio_start
= pci_resource_start(pdev
, 0);
127 mmio_len
= pci_resource_len(pdev
, 0);
128 iobase
= ioremap(mmio_start
, mmio_len
);
134 device
= kzalloc(sizeof(*device
), GFP_KERNEL
);
140 pci_set_drvdata(pdev
, device
);
141 device
->iobase
= iobase
;
143 pci_set_master(pdev
);
145 err
= ioat_setup_functionality(pdev
, iobase
);
157 pci_release_regions(pdev
);
158 pci_disable_device(pdev
);
164 #ifdef IOAT_DMA_REMOVE
166 * It is unsafe to remove this module: if removed while a requested
167 * dma is outstanding, esp. from tcp, it is possible to hang while
168 * waiting for something that will never finish, thus hanging at
169 * least one cpu. However, if you're feeling lucky and need to do
170 * some testing, this usually works just fine.
172 static void __devexit
ioat_remove(struct pci_dev
*pdev
)
174 struct ioat_device
*device
= pci_get_drvdata(pdev
);
176 ioat_shutdown_functionality(pdev
);
180 iounmap(device
->iobase
);
181 pci_release_regions(pdev
);
182 pci_disable_device(pdev
);
186 static int __init
ioat_init_module(void)
188 return pci_register_driver(&ioat_pci_drv
);
190 module_init(ioat_init_module
);
192 static void __exit
ioat_exit_module(void)
194 pci_unregister_driver(&ioat_pci_drv
);
196 module_exit(ioat_exit_module
);