igb_uio: fix build
[dpdk.git] / lib / librte_eal / linuxapp / igb_uio / igb_uio.c
index 42c4fc9..865a276 100644 (file)
 #include <linux/io.h>
 #include <linux/msi.h>
 #include <linux/version.h>
+#include <linux/slab.h>
 
 #ifdef CONFIG_XEN_DOM0
 #include <xen/xen.h>
 #endif
 #include <rte_pci_dev_features.h>
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
-#define pci_cfg_access_lock   pci_block_user_cfg_access
-#define pci_cfg_access_unlock pci_unblock_user_cfg_access
-#endif
+#include "compat.h"
 
 #ifdef RTE_PCI_CONFIG
 #define PCI_SYS_FILE_BUF_SIZE      10
@@ -70,26 +68,6 @@ igbuio_get_uio_pci_dev(struct uio_info *info)
 }
 
 /* sriov sysfs */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34)
-static int pci_num_vf(struct pci_dev *dev)
-{
-       struct iov {
-               int pos;
-               int nres;
-               u32 cap;
-               u16 ctrl;
-               u16 total;
-               u16 initial;
-               u16 nr_virtfn;
-       } *iov = (struct iov *)dev->sriov;
-
-       if (!dev->is_physfn)
-               return 0;
-
-       return iov->nr_virtfn;
-}
-#endif
-
 static ssize_t
 show_max_vfs(struct device *dev, struct device_attribute *attr,
             char *buf)
@@ -106,7 +84,7 @@ store_max_vfs(struct device *dev, struct device_attribute *attr,
        unsigned long max_vfs;
        struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
 
-       if (0 != strict_strtoul(buf, 0, &max_vfs))
+       if (0 != kstrtoul(buf, 0, &max_vfs))
                return -EINVAL;
 
        if (0 == max_vfs)
@@ -197,7 +175,7 @@ store_max_read_request_size(struct device *dev,
        unsigned long size = 0;
        int ret;
 
-       if (strict_strtoul(buf, 0, &size) != 0)
+       if (0 != kstrtoul(buf, 0, &size))
                return -EINVAL;
 
        ret = pcie_set_readrq(pci_dev, (int)size);
@@ -228,62 +206,6 @@ static struct attribute *dev_attrs[] = {
 static const struct attribute_group dev_attr_grp = {
        .attrs = dev_attrs,
 };
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
-/* Check if INTX works to control irq's.
- * Set's INTX_DISABLE flag and reads it back
- */
-static bool pci_intx_mask_supported(struct pci_dev *pdev)
-{
-       bool mask_supported = false;
-       uint16_t orig, new;
-
-       pci_block_user_cfg_access(pdev);
-       pci_read_config_word(pdev, PCI_COMMAND, &orig);
-       pci_write_config_word(pdev, PCI_COMMAND,
-                             orig ^ PCI_COMMAND_INTX_DISABLE);
-       pci_read_config_word(pdev, PCI_COMMAND, &new);
-
-       if ((new ^ orig) & ~PCI_COMMAND_INTX_DISABLE) {
-               dev_err(&pdev->dev, "Command register changed from "
-                       "0x%x to 0x%x: driver or hardware bug?\n", orig, new);
-       } else if ((new ^ orig) & PCI_COMMAND_INTX_DISABLE) {
-               mask_supported = true;
-               pci_write_config_word(pdev, PCI_COMMAND, orig);
-       }
-       pci_unblock_user_cfg_access(pdev);
-
-       return mask_supported;
-}
-
-static bool pci_check_and_mask_intx(struct pci_dev *pdev)
-{
-       bool pending;
-       uint32_t status;
-
-       pci_block_user_cfg_access(pdev);
-       pci_read_config_dword(pdev, PCI_COMMAND, &status);
-
-       /* interrupt is not ours, goes to out */
-       pending = (((status >> 16) & PCI_STATUS_INTERRUPT) != 0);
-       if (pending) {
-               uint16_t old, new;
-
-               old = status;
-               if (status != 0)
-                       new = old & (~PCI_COMMAND_INTX_DISABLE);
-               else
-                       new = old | PCI_COMMAND_INTX_DISABLE;
-
-               if (old != new)
-                       pci_write_config_word(pdev, PCI_COMMAND, new);
-       }
-       pci_unblock_user_cfg_access(pdev);
-
-       return pending;
-}
-#endif
-
 /*
  * It masks the msix on/off of generating MSI-X messages.
  */
@@ -306,24 +228,6 @@ igbuio_msix_mask_irq(struct msi_desc *desc, int32_t state)
        }
 }
 
-static void
-igbuio_msi_mask_irq(struct irq_data *data, u32 enable)
-{
-       struct msi_desc *desc = irq_data_get_msi(data);
-       u32 mask_bits = desc->masked;
-       unsigned offset = data->irq - desc->dev->irq;
-       u32 mask = 1 << offset;
-       u32 flag = enable << offset;
-
-       mask_bits &= ~mask;
-       mask_bits |= flag;
-
-       if (desc->msi_attrib.maskbit && mask_bits != desc->masked) {
-               pci_write_config_dword(desc->dev, desc->mask_pos, mask_bits);
-               desc->masked = mask_bits;
-       }
-}
-
 /**
  * This is the irqcontrol callback to be registered to uio_info.
  * It can be used to disable/enable interrupt from user space processes.
@@ -346,11 +250,8 @@ igbuio_pci_irqcontrol(struct uio_info *info, s32 irq_state)
        pci_cfg_access_lock(pdev);
        if (udev->mode == RTE_INTR_MODE_LEGACY)
                pci_intx(pdev, !!irq_state);
-       else if (udev->mode == RTE_INTR_MODE_MSI) {
-               struct irq_data *data = irq_get_irq_data(pdev->irq);
 
-               igbuio_msi_mask_irq(data, !!irq_state);
-       } else if (udev->mode == RTE_INTR_MODE_MSIX) {
+       else if (udev->mode == RTE_INTR_MODE_MSIX) {
                struct msi_desc *desc;
 
                list_for_each_entry(desc, &pdev->msi_list, list)
@@ -387,7 +288,9 @@ igbuio_dom0_mmap_phys(struct uio_info *info, struct vm_area_struct *vma)
 
        idx = (int)vma->vm_pgoff;
        vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+#ifdef HAVE_PTE_MASK_PAGE_IOMAP
        vma->vm_page_prot.pgprot |= _PAGE_IOMAP;
+#endif
 
        return remap_pfn_range(vma,
                        vma->vm_start,
@@ -585,7 +488,6 @@ igbuio_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
        udev->info.version = "0.1";
        udev->info.handler = igbuio_pci_irqhandler;
        udev->info.irqcontrol = igbuio_pci_irqcontrol;
-       udev->info.irq = dev->irq;
 #ifdef CONFIG_XEN_DOM0
        /* check if the driver run on Xen Dom0 */
        if (xen_initial_domain())
@@ -595,9 +497,6 @@ igbuio_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
        udev->pdev = dev;
 
        switch (igbuio_intr_mode_preferred) {
-       case RTE_INTR_MODE_NONE:
-               udev->info.irq = 0;
-               break;
        case RTE_INTR_MODE_MSIX:
                /* Only 1 msi-x vector needed */
                msix_entry.entry = 0;
@@ -607,25 +506,22 @@ igbuio_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
                        udev->mode = RTE_INTR_MODE_MSIX;
                        break;
                }
-               /* fall back to MSI */
-       case RTE_INTR_MODE_MSI:
-               if (pci_enable_msi(dev) == 0) {
-                       dev_dbg(&dev->dev, "using MSI");
-                       udev->mode = RTE_INTR_MODE_MSI;
-                       break;
-               }
                /* fall back to INTX */
        case RTE_INTR_MODE_LEGACY:
                if (pci_intx_mask_supported(dev)) {
                        dev_dbg(&dev->dev, "using INTX");
                        udev->info.irq_flags = IRQF_SHARED;
+                       udev->info.irq = dev->irq;
                        udev->mode = RTE_INTR_MODE_LEGACY;
-               } else {
-                       dev_err(&dev->dev, "PCI INTX mask not supported\n");
-                       err = -EIO;
-                       goto fail_release_iomem;
+                       break;
                }
+               dev_notice(&dev->dev, "PCI INTX mask not supported\n");
+               /* fall back to no IRQ */
+       case RTE_INTR_MODE_NONE:
+               udev->mode = RTE_INTR_MODE_NONE;
+               udev->info.irq = 0;
                break;
+
        default:
                dev_err(&dev->dev, "invalid IRQ mode %u",
                        igbuio_intr_mode_preferred);
@@ -655,8 +551,6 @@ fail_release_iomem:
        igbuio_pci_release_iomem(&udev->info);
        if (udev->mode == RTE_INTR_MODE_MSIX)
                pci_disable_msix(udev->pdev);
-       else if (udev->mode == RTE_INTR_MODE_MSI)
-               pci_disable_msi(udev->pdev);
        pci_release_regions(dev);
 fail_disable:
        pci_disable_device(dev);
@@ -682,8 +576,6 @@ igbuio_pci_remove(struct pci_dev *dev)
        igbuio_pci_release_iomem(info);
        if (udev->mode == RTE_INTR_MODE_MSIX)
                pci_disable_msix(dev);
-       else if (udev->mode == RTE_INTR_MODE_MSI)
-               pci_disable_msi(dev);
        pci_release_regions(dev);
        pci_disable_device(dev);
        pci_set_drvdata(dev, NULL);
@@ -701,9 +593,6 @@ igbuio_config_intr_mode(char *intr_str)
        if (!strcmp(intr_str, RTE_INTR_MODE_MSIX_NAME)) {
                igbuio_intr_mode_preferred = RTE_INTR_MODE_MSIX;
                pr_info("Use MSIX interrupt\n");
-       } else if (!strcmp(intr_str, RTE_INTR_MODE_MSI_NAME)) {
-               igbuio_intr_mode_preferred = RTE_INTR_MODE_MSI;
-               pr_info("Use MSI interrupt\n");
        } else if (!strcmp(intr_str, RTE_INTR_MODE_LEGACY_NAME)) {
                igbuio_intr_mode_preferred = RTE_INTR_MODE_LEGACY;
                pr_info("Use legacy interrupt\n");
@@ -747,7 +636,6 @@ module_param(intr_mode, charp, S_IRUGO);
 MODULE_PARM_DESC(intr_mode,
 "igb_uio interrupt mode (default=msix):\n"
 "    " RTE_INTR_MODE_MSIX_NAME "       Use MSIX interrupt\n"
-"    " RTE_INTR_MODE_MSI_NAME "        Use MSI interrupt\n"
 "    " RTE_INTR_MODE_LEGACY_NAME "     Use Legacy interrupt\n"
 "\n");