diff options
author | Luca Boccassi <luca.boccassi@gmail.com> | 2018-08-14 18:55:37 +0100 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2018-08-14 18:57:39 +0100 |
commit | ae1479de3027a4a0f68d90bf65ac6ff2b862b837 (patch) | |
tree | 5dbca675b6717b6b61abbe1a9583d5166fed942b /drivers/net/nfp/nfpcore | |
parent | 8cee230dd1f0f9f31f4b0339c671d0b1ee14e111 (diff) | |
parent | b63264c8342e6a1b6971c79550d2af2024b6a4de (diff) |
Merge branch 'upstream' into 18.08.x
Change-Id: Ifbda2d554199dd4d11e01f0090881b5f0103ae12
Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com>
Diffstat (limited to 'drivers/net/nfp/nfpcore')
-rw-r--r-- | drivers/net/nfp/nfpcore/nfp-common/nfp_platform.h | 1 | ||||
-rw-r--r-- | drivers/net/nfp/nfpcore/nfp_cpp.h | 6 | ||||
-rw-r--r-- | drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 184 | ||||
-rw-r--r-- | drivers/net/nfp/nfpcore/nfp_cppcore.c | 9 |
4 files changed, 53 insertions, 147 deletions
diff --git a/drivers/net/nfp/nfpcore/nfp-common/nfp_platform.h b/drivers/net/nfp/nfpcore/nfp-common/nfp_platform.h index b8541c59..d46574b1 100644 --- a/drivers/net/nfp/nfpcore/nfp-common/nfp_platform.h +++ b/drivers/net/nfp/nfpcore/nfp-common/nfp_platform.h @@ -13,7 +13,6 @@ #include <stdlib.h> #include <ctype.h> #include <inttypes.h> -#include <sys/cdefs.h> #include <sys/stat.h> #include <limits.h> #include <errno.h> diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index de2ff84e..1427954c 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -6,6 +6,8 @@ #ifndef __NFP_CPP_H__ #define __NFP_CPP_H__ +#include <rte_ethdev_pci.h> + #include "nfp-common/nfp_platform.h" #include "nfp-common/nfp_resid.h" @@ -54,7 +56,7 @@ struct nfp_cpp_operations { size_t area_priv_size; /* Instance an NFP CPP */ - int (*init)(struct nfp_cpp *cpp, const char *devname); + int (*init)(struct nfp_cpp *cpp, struct rte_pci_device *dev); /* * Free the bus. @@ -181,7 +183,7 @@ uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp); * * @return NFP CPP handle, or NULL on failure (and set errno accordingly). */ -struct nfp_cpp *nfp_cpp_from_device_name(const char *devname, +struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed); /* diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 2f5e7f6d..c68d9400 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -31,6 +31,7 @@ #include <sys/file.h> #include <sys/stat.h> +#include <rte_ethdev_pci.h> #include <rte_string_fns.h> #include "nfp_cpp.h" @@ -309,13 +310,8 @@ nfp_enable_bars(struct nfp_pcie_user *nfp) bar->csr = nfp->cfg + NFP_PCIE_CFG_BAR_PCIETOCPPEXPBAR(bar->index >> 3, bar->index & 7); - bar->iomem = - (char *)mmap(0, 1 << bar->bitsize, PROT_READ | PROT_WRITE, - MAP_SHARED, nfp->device, - bar->index << bar->bitsize); - if (bar->iomem == MAP_FAILED) - return (-ENOMEM); + bar->iomem = nfp->cfg + (bar->index << bar->bitsize); } return 0; } @@ -345,7 +341,6 @@ nfp_disable_bars(struct nfp_pcie_user *nfp) for (x = ARRAY_SIZE(nfp->bar); x > 0; x--) { bar = &nfp->bar[x - 1]; if (bar->iomem) { - munmap(bar->iomem, 1 << (nfp->barsz - 3)); bar->iomem = NULL; bar->lock = 0; } @@ -639,61 +634,32 @@ nfp_acquire_process_lock(struct nfp_pcie_user *desc) } static int -nfp6000_set_model(struct nfp_pcie_user *desc, struct nfp_cpp *cpp) +nfp6000_set_model(struct rte_pci_device *dev, struct nfp_cpp *cpp) { - char tmp_str[80]; - uint32_t tmp; - int fp; - - snprintf(tmp_str, sizeof(tmp_str), "%s/%s/config", PCI_DEVICES, - desc->busdev); - - fp = open(tmp_str, O_RDONLY); - if (!fp) - return -1; - - lseek(fp, 0x2e, SEEK_SET); + uint32_t model; - if (read(fp, &tmp, sizeof(tmp)) != sizeof(tmp)) { - printf("Error reading config file for model\n"); + if (rte_pci_read_config(dev, &model, 4, 0x2e) < 0) { + printf("nfp set model failed\n"); return -1; } - tmp = tmp << 16; - - if (close(fp) == -1) - return -1; - - nfp_cpp_model_set(cpp, tmp); + model = model << 16; + nfp_cpp_model_set(cpp, model); return 0; } static int -nfp6000_set_interface(struct nfp_pcie_user *desc, struct nfp_cpp *cpp) +nfp6000_set_interface(struct rte_pci_device *dev, struct nfp_cpp *cpp) { - char tmp_str[80]; - uint16_t tmp; - int fp; - - snprintf(tmp_str, sizeof(tmp_str), "%s/%s/config", PCI_DEVICES, - desc->busdev); + uint16_t interface; - fp = open(tmp_str, O_RDONLY); - if (!fp) - return -1; - - lseek(fp, 0x154, SEEK_SET); - - if (read(fp, &tmp, sizeof(tmp)) != sizeof(tmp)) { - printf("error reading config file for interface\n"); + if (rte_pci_read_config(dev, &interface, 2, 0x154) < 0) { + printf("nfp set interface failed\n"); return -1; } - if (close(fp) == -1) - return -1; - - nfp_cpp_interface_set(cpp, tmp); + nfp_cpp_interface_set(cpp, interface); return 0; } @@ -704,7 +670,7 @@ nfp6000_set_interface(struct nfp_pcie_user *desc, struct nfp_cpp *cpp) #define PCI_EXT_CAP_NEXT(header) ((header >> 20) & 0xffc) #define PCI_EXT_CAP_ID_DSN 0x03 static int -nfp_pci_find_next_ext_capability(int fp, int cap) +nfp_pci_find_next_ext_capability(struct rte_pci_device *dev, int cap) { uint32_t header; int ttl; @@ -713,9 +679,8 @@ nfp_pci_find_next_ext_capability(int fp, int cap) /* minimum 8 bytes per capability */ ttl = (PCI_CFG_SPACE_EXP_SIZE - PCI_CFG_SPACE_SIZE) / 8; - lseek(fp, pos, SEEK_SET); - if (read(fp, &header, sizeof(header)) != sizeof(header)) { - printf("error reading config file for serial\n"); + if (rte_pci_read_config(dev, &header, 4, pos) < 0) { + printf("nfp error reading extended capabilities\n"); return -1; } @@ -734,9 +699,8 @@ nfp_pci_find_next_ext_capability(int fp, int cap) if (pos < PCI_CFG_SPACE_SIZE) break; - lseek(fp, pos, SEEK_SET); - if (read(fp, &header, sizeof(header)) != sizeof(header)) { - printf("error reading config file for serial\n"); + if (rte_pci_read_config(dev, &header, 4, pos) < 0) { + printf("nfp error reading extended capabilities\n"); return -1; } } @@ -745,99 +709,70 @@ nfp_pci_find_next_ext_capability(int fp, int cap) } static int -nfp6000_set_serial(struct nfp_pcie_user *desc, struct nfp_cpp *cpp) +nfp6000_set_serial(struct rte_pci_device *dev, struct nfp_cpp *cpp) { - char tmp_str[80]; uint16_t tmp; uint8_t serial[6]; int serial_len = 6; - int fp, pos; + int pos; - snprintf(tmp_str, sizeof(tmp_str), "%s/%s/config", PCI_DEVICES, - desc->busdev); - - fp = open(tmp_str, O_RDONLY); - if (!fp) - return -1; - - pos = nfp_pci_find_next_ext_capability(fp, PCI_EXT_CAP_ID_DSN); + pos = nfp_pci_find_next_ext_capability(dev, PCI_EXT_CAP_ID_DSN); if (pos <= 0) { - printf("PCI_EXT_CAP_ID_DSN not found. Using default offset\n"); - lseek(fp, 0x156, SEEK_SET); + printf("PCI_EXT_CAP_ID_DSN not found. nfp set serial failed\n"); + return -1; } else { - lseek(fp, pos + 6, SEEK_SET); + pos += 6; } - if (read(fp, &tmp, sizeof(tmp)) != sizeof(tmp)) { - printf("error reading config file for serial\n"); + if (rte_pci_read_config(dev, &tmp, 2, pos) < 0) { + printf("nfp set serial failed\n"); return -1; } serial[4] = (uint8_t)((tmp >> 8) & 0xff); serial[5] = (uint8_t)(tmp & 0xff); - if (read(fp, &tmp, sizeof(tmp)) != sizeof(tmp)) { - printf("error reading config file for serial\n"); + pos += 2; + if (rte_pci_read_config(dev, &tmp, 2, pos) < 0) { + printf("nfp set serial failed\n"); return -1; } serial[2] = (uint8_t)((tmp >> 8) & 0xff); serial[3] = (uint8_t)(tmp & 0xff); - if (read(fp, &tmp, sizeof(tmp)) != sizeof(tmp)) { - printf("error reading config file for serial\n"); + pos += 2; + if (rte_pci_read_config(dev, &tmp, 2, pos) < 0) { + printf("nfp set serial failed\n"); return -1; } serial[0] = (uint8_t)((tmp >> 8) & 0xff); serial[1] = (uint8_t)(tmp & 0xff); - if (close(fp) == -1) - return -1; - nfp_cpp_serial_set(cpp, serial, serial_len); return 0; } static int -nfp6000_set_barsz(struct nfp_pcie_user *desc) +nfp6000_set_barsz(struct rte_pci_device *dev, struct nfp_pcie_user *desc) { - char tmp_str[80]; - unsigned long start, end, flags, tmp; - int i; - FILE *fp; - - snprintf(tmp_str, sizeof(tmp_str), "%s/%s/resource", PCI_DEVICES, - desc->busdev); - - fp = fopen(tmp_str, "r"); - if (!fp) - return -1; + unsigned long tmp; + int i = 0; - if (fscanf(fp, "0x%lx 0x%lx 0x%lx", &start, &end, &flags) == 0) { - printf("error reading resource file for bar size\n"); - fclose(fp); - return -1; - } + tmp = dev->mem_resource[0].len; - if (fclose(fp) == -1) - return -1; - - tmp = (end - start) + 1; - i = 0; while (tmp >>= 1) i++; + desc->barsz = i; return 0; } static int -nfp6000_init(struct nfp_cpp *cpp, const char *devname) +nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev) { - char link[120]; - char tmp_str[80]; - ssize_t size; int ret = 0; uint32_t model; struct nfp_pcie_user *desc; @@ -848,7 +783,7 @@ nfp6000_init(struct nfp_cpp *cpp, const char *devname) memset(desc->busdev, 0, BUSDEV_SZ); - strlcpy(desc->busdev, devname, sizeof(desc->busdev)); + strlcpy(desc->busdev, dev->device.name, sizeof(desc->busdev)); if (cpp->driver_lock_needed) { ret = nfp_acquire_process_lock(desc); @@ -856,39 +791,16 @@ nfp6000_init(struct nfp_cpp *cpp, const char *devname) return -1; } - snprintf(tmp_str, sizeof(tmp_str), "%s/%s/driver", PCI_DEVICES, - desc->busdev); - - size = readlink(tmp_str, link, sizeof(link)); - - if (size == -1) - tmp_str[0] = '\0'; - - if (size == sizeof(link)) - tmp_str[0] = '\0'; - - snprintf(tmp_str, sizeof(tmp_str), "%s/%s/resource0", PCI_DEVICES, - desc->busdev); - - desc->device = open(tmp_str, O_RDWR); - if (desc->device == -1) - return -1; - - if (nfp6000_set_model(desc, cpp) < 0) + if (nfp6000_set_model(dev, cpp) < 0) return -1; - if (nfp6000_set_interface(desc, cpp) < 0) + if (nfp6000_set_interface(dev, cpp) < 0) return -1; - if (nfp6000_set_serial(desc, cpp) < 0) + if (nfp6000_set_serial(dev, cpp) < 0) return -1; - if (nfp6000_set_barsz(desc) < 0) + if (nfp6000_set_barsz(dev, desc) < 0) return -1; - desc->cfg = (char *)mmap(0, 1 << (desc->barsz - 3), - PROT_READ | PROT_WRITE, - MAP_SHARED, desc->device, 0); - - if (desc->cfg == MAP_FAILED) - return -1; + desc->cfg = (char *)dev->mem_resource[0].addr; nfp_enable_bars(desc); @@ -904,16 +816,8 @@ static void nfp6000_free(struct nfp_cpp *cpp) { struct nfp_pcie_user *desc = nfp_cpp_priv(cpp); - int x; - /* Unmap may cause if there are any pending transaxctions */ nfp_disable_bars(desc); - munmap(desc->cfg, 1 << (desc->barsz - 3)); - - for (x = ARRAY_SIZE(desc->bar); x > 0; x--) { - if (desc->bar[x - 1].iomem) - munmap(desc->bar[x - 1].iomem, 1 << (desc->barsz - 3)); - } if (cpp->driver_lock_needed) close(desc->lock); close(desc->device); diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index f61143f7..75d3c974 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -12,6 +12,7 @@ #include <sys/types.h> #include <rte_byteorder.h> +#include <rte_ethdev_pci.h> #include "nfp_cpp.h" #include "nfp_target.h" @@ -542,7 +543,7 @@ nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t *value) } static struct nfp_cpp * -nfp_cpp_alloc(const char *devname, int driver_lock_needed) +nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed) { const struct nfp_cpp_operations *ops; struct nfp_cpp *cpp; @@ -561,7 +562,7 @@ nfp_cpp_alloc(const char *devname, int driver_lock_needed) cpp->driver_lock_needed = driver_lock_needed; if (cpp->op->init) { - err = cpp->op->init(cpp, devname); + err = cpp->op->init(cpp, dev); if (err < 0) { free(cpp); return NULL; @@ -604,9 +605,9 @@ nfp_cpp_free(struct nfp_cpp *cpp) } struct nfp_cpp * -nfp_cpp_from_device_name(const char *devname, int driver_lock_needed) +nfp_cpp_from_device_name(struct rte_pci_device *dev, int driver_lock_needed) { - return nfp_cpp_alloc(devname, driver_lock_needed); + return nfp_cpp_alloc(dev, driver_lock_needed); } /* |