pci: use new address comparison function
[dpdk.git] / lib / librte_eal / bsdapp / eal / eal_pci.c
index 59ceb76..7d82195 100644 (file)
@@ -41,7 +41,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <stdarg.h>
 #include <errno.h>
 #include <dirent.h>
 #include <limits.h>
@@ -52,7 +51,6 @@
 #include <dev/pci/pcireg.h>
 
 #if defined(RTE_ARCH_X86)
-#include <sys/types.h>
 #include <machine/cpufunc.h>
 #endif
 
@@ -282,8 +280,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
        /* FreeBSD has no NUMA support (yet) */
        dev->device.numa_node = 0;
 
-       rte_pci_device_name(&dev->addr, dev->name, sizeof(dev->name));
-       dev->device.name = dev->name;
+       pci_name_set(dev);
 
        /* FreeBSD has only one pass through driver */
        dev->kdrv = RTE_KDRV_NIC_UIO;
@@ -326,7 +323,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
                int ret;
 
                TAILQ_FOREACH(dev2, &rte_pci_bus.device_list, next) {
-                       ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr);
+                       ret = rte_pci_addr_cmp(&dev->addr, &dev2->addr);
                        if (ret > 0)
                                continue;
                        else if (ret < 0) {
@@ -334,6 +331,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
                        } else { /* already registered */
                                dev2->kdrv = dev->kdrv;
                                dev2->max_vfs = dev->max_vfs;
+                               pci_name_set(dev2);
                                memmove(dev2->mem_resource,
                                        dev->mem_resource,
                                        sizeof(dev->mem_resource));
@@ -396,7 +394,7 @@ rte_pci_scan(void)
 
        close(fd);
 
-       RTE_LOG(ERR, EAL, "PCI scan found %u devices\n", dev_count);
+       RTE_LOG(DEBUG, EAL, "PCI scan found %u devices\n", dev_count);
        return 0;
 
 error:
@@ -405,6 +403,16 @@ error:
        return -1;
 }
 
+/*
+ * Get iommu class of PCI devices on the bus.
+ */
+enum rte_iova_mode
+rte_pci_get_iommu_class(void)
+{
+       /* Supports only RTE_KDRV_NIC_UIO */
+       return RTE_IOVA_PA;
+}
+
 int
 pci_update_device(const struct rte_pci_addr *addr)
 {
@@ -459,6 +467,7 @@ int rte_pci_read_config(const struct rte_pci_device *dev,
                void *buf, size_t len, off_t offset)
 {
        int fd = -1;
+       int size;
        struct pci_io pi = {
                .pi_sel = {
                        .pc_domain = dev->addr.domain,
@@ -467,25 +476,28 @@ int rte_pci_read_config(const struct rte_pci_device *dev,
                        .pc_func = dev->addr.function,
                },
                .pi_reg = offset,
-               .pi_width = len,
        };
 
-       if (len == 3 || len > sizeof(pi.pi_data)) {
-               RTE_LOG(ERR, EAL, "%s(): invalid pci read length\n", __func__);
-               goto error;
-       }
-
        fd = open("/dev/pci", O_RDWR);
        if (fd < 0) {
                RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
                goto error;
        }
 
-       if (ioctl(fd, PCIOCREAD, &pi) < 0)
-               goto error;
+       while (len > 0) {
+               size = (len >= 4) ? 4 : ((len >= 2) ? 2 : 1);
+               pi.pi_width = size;
+
+               if (ioctl(fd, PCIOCREAD, &pi) < 0)
+                       goto error;
+               memcpy(buf, &pi.pi_data, size);
+
+               buf = (char *)buf + size;
+               pi.pi_reg += size;
+               len -= size;
+       }
        close(fd);
 
-       memcpy(buf, &pi.pi_data, len);
        return 0;
 
  error: