Commit 3e3e9fd8 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

nfp: reset local locks on init

NFP locks record the owner when held, for PCIe devices the owner
ID will be the PCIe link number.  When driver loads it should scan
known locks and if they indicate that they are held by local
endpoint but the driver doesn't hold them - release them.

Locks can be left taken for instance when kernel gets kexec-ed or
after a crash.  Management FW tries to clean up stale locks too,
but it currently depends on PCIe link going down which doesn't
always happen.
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: default avatarDirk van der Merwe <dirk.vandermerwe@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c77bbc64
...@@ -486,6 +486,10 @@ static int nfp_pci_probe(struct pci_dev *pdev, ...@@ -486,6 +486,10 @@ static int nfp_pci_probe(struct pci_dev *pdev,
goto err_disable_msix; goto err_disable_msix;
} }
err = nfp_resource_table_init(pf->cpp);
if (err)
goto err_cpp_free;
pf->hwinfo = nfp_hwinfo_read(pf->cpp); pf->hwinfo = nfp_hwinfo_read(pf->cpp);
dev_info(&pdev->dev, "Assembly: %s%s%s-%s CPLD: %s\n", dev_info(&pdev->dev, "Assembly: %s%s%s-%s CPLD: %s\n",
...@@ -548,6 +552,7 @@ static int nfp_pci_probe(struct pci_dev *pdev, ...@@ -548,6 +552,7 @@ static int nfp_pci_probe(struct pci_dev *pdev,
vfree(pf->dumpspec); vfree(pf->dumpspec);
err_hwinfo_free: err_hwinfo_free:
kfree(pf->hwinfo); kfree(pf->hwinfo);
err_cpp_free:
nfp_cpp_free(pf->cpp); nfp_cpp_free(pf->cpp);
err_disable_msix: err_disable_msix:
destroy_workqueue(pf->wq); destroy_workqueue(pf->wq);
......
...@@ -94,6 +94,8 @@ int nfp_nsp_read_sensors(struct nfp_nsp *state, unsigned int sensor_mask, ...@@ -94,6 +94,8 @@ int nfp_nsp_read_sensors(struct nfp_nsp *state, unsigned int sensor_mask,
/* MAC Statistics Accumulator */ /* MAC Statistics Accumulator */
#define NFP_RESOURCE_MAC_STATISTICS "mac.stat" #define NFP_RESOURCE_MAC_STATISTICS "mac.stat"
int nfp_resource_table_init(struct nfp_cpp *cpp);
struct nfp_resource * struct nfp_resource *
nfp_resource_acquire(struct nfp_cpp *cpp, const char *name); nfp_resource_acquire(struct nfp_cpp *cpp, const char *name);
......
...@@ -295,6 +295,8 @@ void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex); ...@@ -295,6 +295,8 @@ void nfp_cpp_mutex_free(struct nfp_cpp_mutex *mutex);
int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex); int nfp_cpp_mutex_lock(struct nfp_cpp_mutex *mutex);
int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex); int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex);
int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex); int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex);
int nfp_cpp_mutex_reclaim(struct nfp_cpp *cpp, int target,
unsigned long long address);
/** /**
* nfp_cppcore_pcie_unit() - Get PCI Unit of a CPP handle * nfp_cppcore_pcie_unit() - Get PCI Unit of a CPP handle
......
...@@ -59,6 +59,11 @@ static u32 nfp_mutex_unlocked(u16 interface) ...@@ -59,6 +59,11 @@ static u32 nfp_mutex_unlocked(u16 interface)
return (u32)interface << 16 | 0x0000; return (u32)interface << 16 | 0x0000;
} }
static u32 nfp_mutex_owner(u32 val)
{
return val >> 16;
}
static bool nfp_mutex_is_locked(u32 val) static bool nfp_mutex_is_locked(u32 val)
{ {
return (val & 0xffff) == 0x000f; return (val & 0xffff) == 0x000f;
...@@ -351,3 +356,43 @@ int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex) ...@@ -351,3 +356,43 @@ int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex)
return nfp_mutex_is_locked(tmp) ? -EBUSY : -EINVAL; return nfp_mutex_is_locked(tmp) ? -EBUSY : -EINVAL;
} }
/**
* nfp_cpp_mutex_reclaim() - Unlock mutex if held by local endpoint
* @cpp: NFP CPP handle
* @target: NFP CPP target ID (ie NFP_CPP_TARGET_CLS or NFP_CPP_TARGET_MU)
* @address: Offset into the address space of the NFP CPP target ID
*
* Release lock if held by local system. Extreme care is advised, call only
* when no local lock users can exist.
*
* Return: 0 if the lock was OK, 1 if locked by us, -errno on invalid mutex
*/
int nfp_cpp_mutex_reclaim(struct nfp_cpp *cpp, int target,
unsigned long long address)
{
const u32 mur = NFP_CPP_ID(target, 3, 0); /* atomic_read */
const u32 muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */
u16 interface = nfp_cpp_interface(cpp);
int err;
u32 tmp;
err = nfp_cpp_mutex_validate(interface, &target, address);
if (err)
return err;
/* Check lock */
err = nfp_cpp_readl(cpp, mur, address, &tmp);
if (err < 0)
return err;
if (nfp_mutex_is_unlocked(tmp) || nfp_mutex_owner(tmp) != interface)
return 0;
/* Bust the lock */
err = nfp_cpp_writel(cpp, muw, address, nfp_mutex_unlocked(interface));
if (err < 0)
return err;
return 1;
}
...@@ -338,3 +338,62 @@ u64 nfp_resource_size(struct nfp_resource *res) ...@@ -338,3 +338,62 @@ u64 nfp_resource_size(struct nfp_resource *res)
{ {
return res->size; return res->size;
} }
/**
* nfp_resource_table_init() - Run initial checks on the resource table
* @cpp: NFP CPP handle
*
* Start-of-day init procedure for resource table. Must be called before
* any local resource table users may exist.
*
* Return: 0 on success, -errno on failure
*/
int nfp_resource_table_init(struct nfp_cpp *cpp)
{
struct nfp_cpp_mutex *dev_mutex;
int i, err;
err = nfp_cpp_mutex_reclaim(cpp, NFP_RESOURCE_TBL_TARGET,
NFP_RESOURCE_TBL_BASE);
if (err < 0) {
nfp_err(cpp, "Error: failed to reclaim resource table mutex\n");
return err;
}
if (err)
nfp_warn(cpp, "Warning: busted main resource table mutex\n");
dev_mutex = nfp_cpp_mutex_alloc(cpp, NFP_RESOURCE_TBL_TARGET,
NFP_RESOURCE_TBL_BASE,
NFP_RESOURCE_TBL_KEY);
if (!dev_mutex)
return -ENOMEM;
if (nfp_cpp_mutex_lock(dev_mutex)) {
nfp_err(cpp, "Error: failed to claim resource table mutex\n");
nfp_cpp_mutex_free(dev_mutex);
return -EINVAL;
}
/* Resource 0 is the dev_mutex, start from 1 */
for (i = 1; i < NFP_RESOURCE_TBL_ENTRIES; i++) {
u64 addr = NFP_RESOURCE_TBL_BASE +
sizeof(struct nfp_resource_entry) * i;
err = nfp_cpp_mutex_reclaim(cpp, NFP_RESOURCE_TBL_TARGET, addr);
if (err < 0) {
nfp_err(cpp,
"Error: failed to reclaim resource %d mutex\n",
i);
goto err_unlock;
}
if (err)
nfp_warn(cpp, "Warning: busted resource %d mutex\n", i);
}
err = 0;
err_unlock:
nfp_cpp_mutex_unlock(dev_mutex);
nfp_cpp_mutex_free(dev_mutex);
return err;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment