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;
80 /* Getting address for NFP expansion BAR registers */
81 cfg_base = pci_dev->mem_resource[0].addr;
82 cfg_base = (uint8_t *)cfg_base + NFP_CFG_EXP_BAR_CFG_BASE;
84 /* Getting address for NFP NSP interface registers */
85 mem_base = pci_dev->mem_resource[0].addr;
86 mem_base = (uint8_t *)mem_base + (NFP_CFG_EXP_BAR << (barsz - 3));
89 desc->nspu = rte_malloc("nfp nspu", sizeof(nspu_desc_t), 0);
90 nfp_nspu_init(desc->nspu, desc->nfp, NFP_CFG_PCIE_BAR, barsz,
91 NFP_CFG_EXP_BAR, cfg_base, mem_base);
97 nfpu_close(nfpu_desc_t *desc)
101 unlink("/var/lock/nfp0");