drivers/net/ethernet/netronome/nfp/nfpcore/nfp_mutex.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_mutex.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/netronome/nfp/nfpcore/nfp_mutex.c- Extension
.c- Size
- 9352 bytes
- Lines
- 369
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/delay.hlinux/device.hlinux/jiffies.hlinux/types.hlinux/slab.hlinux/wait.hnfp_cpp.hnfp6000/nfp6000.h
Detected Declarations
struct nfp_cpp_mutexfunction nfp_mutex_lockedfunction nfp_mutex_unlockedfunction nfp_mutex_ownerfunction nfp_mutex_is_lockedfunction nfp_mutex_is_unlockedfunction nfp_cpp_mutex_validatefunction nfp_cpp_mutex_initfunction nfp_cpp_mutex_allocfunction nfp_cpp_mutex_freefunction nfp_cpp_mutex_lockfunction nfp_cpp_mutex_unlockfunction nfp_cpp_mutex_trylockfunction nfp_cpp_mutex_reclaim
Annotated Snippet
struct nfp_cpp_mutex {
struct nfp_cpp *cpp;
int target;
u16 depth;
unsigned long long address;
u32 key;
};
static u32 nfp_mutex_locked(u16 interface)
{
return (u32)interface << 16 | 0x000f;
}
static u32 nfp_mutex_unlocked(u16 interface)
{
return (u32)interface << 16 | 0x0000;
}
static u32 nfp_mutex_owner(u32 val)
{
return val >> 16;
}
static bool nfp_mutex_is_locked(u32 val)
{
return (val & 0xffff) == 0x000f;
}
static bool nfp_mutex_is_unlocked(u32 val)
{
return (val & 0xffff) == 0000;
}
/* If you need more than 65536 recursive locks, please rethink your code. */
#define NFP_MUTEX_DEPTH_MAX 0xffff
static int
nfp_cpp_mutex_validate(u16 interface, int *target, unsigned long long address)
{
/* Not permitted on invalid interfaces */
if (NFP_CPP_INTERFACE_TYPE_of(interface) ==
NFP_CPP_INTERFACE_TYPE_INVALID)
return -EINVAL;
/* Address must be 64-bit aligned */
if (address & 7)
return -EINVAL;
if (*target != NFP_CPP_TARGET_MU)
return -EINVAL;
return 0;
}
/**
* nfp_cpp_mutex_init() - Initialize a mutex location
* @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
* @key: Unique 32-bit value for this mutex
*
* The CPP target:address must point to a 64-bit aligned location, and
* will initialize 64 bits of data at the location.
*
* This creates the initial mutex state, as locked by this
* nfp_cpp_interface().
*
* This function should only be called when setting up
* the initial lock state upon boot-up of the system.
*
* Return: 0 on success, or -errno on failure
*/
int nfp_cpp_mutex_init(struct nfp_cpp *cpp,
int target, unsigned long long address, u32 key)
{
const u32 muw = NFP_CPP_ID(target, 4, 0); /* atomic_write */
u16 interface = nfp_cpp_interface(cpp);
int err;
err = nfp_cpp_mutex_validate(interface, &target, address);
if (err)
return err;
err = nfp_cpp_writel(cpp, muw, address + 4, key);
if (err)
return err;
err = nfp_cpp_writel(cpp, muw, address, nfp_mutex_locked(interface));
if (err)
return err;
Annotation
- Immediate include surface: `linux/delay.h`, `linux/device.h`, `linux/jiffies.h`, `linux/types.h`, `linux/slab.h`, `linux/wait.h`, `nfp_cpp.h`, `nfp6000/nfp6000.h`.
- Detected declarations: `struct nfp_cpp_mutex`, `function nfp_mutex_locked`, `function nfp_mutex_unlocked`, `function nfp_mutex_owner`, `function nfp_mutex_is_locked`, `function nfp_mutex_is_unlocked`, `function nfp_cpp_mutex_validate`, `function nfp_cpp_mutex_init`, `function nfp_cpp_mutex_alloc`, `function nfp_cpp_mutex_free`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.