11 #include <rte_bus_pci.h>
12 #include <rte_malloc.h>
16 /* PF BAR and expansion BAR for the NSP interface */
17 #define NFP_CFG_PCIE_BAR 0
18 #define NFP_CFG_EXP_BAR 7
20 #define NFP_CFG_EXP_BAR_CFG_BASE 0x30000
22 /* There could be other NFP userspace tools using the NSP interface.
23 * Make sure there is no other process using it and locking the access for
27 nspv_aquire_process_lock(nfpu_desc_t *desc)
33 memset(&lock, 0, sizeof(lock));
35 snprintf(lockname, sizeof(lockname), "/var/lock/nfp%d", desc->nfp);
37 /* Using S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH */
38 desc->lock = open(lockname, O_RDWR | O_CREAT, 0666);
43 lock.l_type = F_WRLCK;
44 lock.l_whence = SEEK_SET;
47 rc = fcntl(desc->lock, F_SETLK, &lock);
49 if ((errno != EAGAIN) && (errno != EACCES)) {
60 nfpu_open(struct rte_pci_device *pci_dev, nfpu_desc_t *desc, int nfp)
62 void *cfg_base, *mem_base;
69 ret = nspv_aquire_process_lock(desc);
73 barsz = pci_dev->mem_resource[0].len;
81 /* Sanity check: we can assume any bar size less than 1MB an error */
85 /* Getting address for NFP expansion BAR registers */
86 cfg_base = pci_dev->mem_resource[0].addr;
87 cfg_base = (uint8_t *)cfg_base + NFP_CFG_EXP_BAR_CFG_BASE;
89 /* Getting address for NFP NSP interface registers */
90 mem_base = pci_dev->mem_resource[0].addr;
91 mem_base = (uint8_t *)mem_base + (NFP_CFG_EXP_BAR << (barsz - 3));
94 desc->nspu = rte_malloc("nfp nspu", sizeof(nspu_desc_t), 0);
95 nfp_nspu_init(desc->nspu, desc->nfp, NFP_CFG_PCIE_BAR, barsz,
96 NFP_CFG_EXP_BAR, cfg_base, mem_base);
102 nfpu_close(nfpu_desc_t *desc)
104 rte_free(desc->nspu);
106 unlink("/var/lock/nfp0");