mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-03 08:56:39 +07:00
e6c0b69a43
The driver currently duplicates much of what these routines offer, so just use the common code. For example ->irq_mode tracks what interrupt mode was initialized, which duplicates the ->msix_enabled and ->msi_enabled handling in pcim_release. This also adds a check to the return value of dma_async_device_register, which can fail. Signed-off-by: Maciej Sosnowski <maciej.sosnowski@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
184 lines
5.0 KiB
C
184 lines
5.0 KiB
C
/*
|
|
* Intel I/OAT DMA Linux driver
|
|
* Copyright(c) 2007 - 2009 Intel Corporation.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms and conditions of the GNU General Public License,
|
|
* version 2, as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
|
|
*
|
|
* The full GNU General Public License is included in this distribution in
|
|
* the file called "COPYING".
|
|
*
|
|
*/
|
|
|
|
/*
|
|
* This driver supports an Intel I/OAT DMA engine, which does asynchronous
|
|
* copy operations.
|
|
*/
|
|
|
|
#include <linux/init.h>
|
|
#include <linux/module.h>
|
|
#include <linux/pci.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/dca.h>
|
|
#include "dma.h"
|
|
#include "registers.h"
|
|
#include "hw.h"
|
|
|
|
MODULE_VERSION(IOAT_DMA_VERSION);
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_AUTHOR("Intel Corporation");
|
|
|
|
static struct pci_device_id ioat_pci_tbl[] = {
|
|
/* I/OAT v1 platforms */
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT) },
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_CNB) },
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_SCNB) },
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_UNISYS, PCI_DEVICE_ID_UNISYS_DMA_DIRECTOR) },
|
|
|
|
/* I/OAT v2 platforms */
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_SNB) },
|
|
|
|
/* I/OAT v3 platforms */
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG0) },
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG1) },
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG2) },
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG3) },
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG4) },
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG5) },
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG6) },
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG7) },
|
|
{ 0, }
|
|
};
|
|
|
|
struct ioat_device {
|
|
struct pci_dev *pdev;
|
|
struct ioatdma_device *dma;
|
|
struct dca_provider *dca;
|
|
};
|
|
|
|
static int __devinit ioat_probe(struct pci_dev *pdev,
|
|
const struct pci_device_id *id);
|
|
static void __devexit ioat_remove(struct pci_dev *pdev);
|
|
|
|
static int ioat_dca_enabled = 1;
|
|
module_param(ioat_dca_enabled, int, 0644);
|
|
MODULE_PARM_DESC(ioat_dca_enabled, "control support of dca service (default: 1)");
|
|
|
|
#define DRV_NAME "ioatdma"
|
|
|
|
static struct pci_driver ioat_pci_driver = {
|
|
.name = DRV_NAME,
|
|
.id_table = ioat_pci_tbl,
|
|
.probe = ioat_probe,
|
|
.remove = __devexit_p(ioat_remove),
|
|
};
|
|
|
|
static int __devinit ioat_probe(struct pci_dev *pdev,
|
|
const struct pci_device_id *id)
|
|
{
|
|
void __iomem * const *iomap;
|
|
void __iomem *iobase;
|
|
struct device *dev = &pdev->dev;
|
|
struct ioat_device *device;
|
|
int err;
|
|
|
|
err = pcim_enable_device(pdev);
|
|
if (err)
|
|
return err;
|
|
|
|
err = pcim_iomap_regions(pdev, 1 << IOAT_MMIO_BAR, DRV_NAME);
|
|
if (err)
|
|
return err;
|
|
iomap = pcim_iomap_table(pdev);
|
|
if (!iomap)
|
|
return -ENOMEM;
|
|
|
|
err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
|
|
if (err)
|
|
err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
|
|
if (err)
|
|
return err;
|
|
|
|
err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
|
|
if (err)
|
|
err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
|
|
if (err)
|
|
return err;
|
|
|
|
device = devm_kzalloc(dev, sizeof(*device), GFP_KERNEL);
|
|
if (!device)
|
|
return -ENOMEM;
|
|
|
|
device->pdev = pdev;
|
|
pci_set_drvdata(pdev, device);
|
|
iobase = iomap[IOAT_MMIO_BAR];
|
|
|
|
pci_set_master(pdev);
|
|
|
|
switch (readb(iobase + IOAT_VER_OFFSET)) {
|
|
case IOAT_VER_1_2:
|
|
device->dma = ioat_dma_probe(pdev, iobase);
|
|
if (device->dma && ioat_dca_enabled)
|
|
device->dca = ioat_dca_init(pdev, iobase);
|
|
break;
|
|
case IOAT_VER_2_0:
|
|
device->dma = ioat_dma_probe(pdev, iobase);
|
|
if (device->dma && ioat_dca_enabled)
|
|
device->dca = ioat2_dca_init(pdev, iobase);
|
|
break;
|
|
case IOAT_VER_3_0:
|
|
device->dma = ioat_dma_probe(pdev, iobase);
|
|
if (device->dma && ioat_dca_enabled)
|
|
device->dca = ioat3_dca_init(pdev, iobase);
|
|
break;
|
|
default:
|
|
return -ENODEV;
|
|
}
|
|
|
|
if (!device->dma) {
|
|
dev_err(dev, "Intel(R) I/OAT DMA Engine init failed\n");
|
|
return -ENODEV;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void __devexit ioat_remove(struct pci_dev *pdev)
|
|
{
|
|
struct ioat_device *device = pci_get_drvdata(pdev);
|
|
|
|
dev_err(&pdev->dev, "Removing dma and dca services\n");
|
|
if (device->dca) {
|
|
unregister_dca_provider(device->dca);
|
|
free_dca_provider(device->dca);
|
|
device->dca = NULL;
|
|
}
|
|
|
|
if (device->dma) {
|
|
ioat_dma_remove(device->dma);
|
|
device->dma = NULL;
|
|
}
|
|
}
|
|
|
|
static int __init ioat_init_module(void)
|
|
{
|
|
return pci_register_driver(&ioat_pci_driver);
|
|
}
|
|
module_init(ioat_init_module);
|
|
|
|
static void __exit ioat_exit_module(void)
|
|
{
|
|
pci_unregister_driver(&ioat_pci_driver);
|
|
}
|
|
module_exit(ioat_exit_module);
|