drivers/net/ethernet/wangxun/libwx/wx_mbx.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/wangxun/libwx/wx_mbx.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/wangxun/libwx/wx_mbx.c- Extension
.c- Size
- 10114 bytes
- Lines
- 419
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/pci.hwx_type.hwx_mbx.h
Detected Declarations
function wx_obtain_mbx_lock_pffunction wx_check_for_bit_pffunction wx_check_for_ack_pffunction wx_check_for_msg_pffunction wx_write_mbx_pffunction wx_read_mbx_pffunction wx_check_for_rst_pffunction wx_read_v2p_mailboxfunction wx_mailbox_get_lock_vffunction wx_obtain_mbx_lock_vffunction wx_check_for_bit_vffunction wx_check_for_ack_vffunction wx_check_for_msg_vffunction wx_check_for_rst_vffunction wx_poll_for_msgfunction wx_poll_for_ackfunction wx_read_posted_mbxfunction wx_write_posted_mbxfunction wx_write_mbx_vffunction wx_read_mbx_vffunction wx_init_mbx_params_vfexport wx_init_mbx_params_vf
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2015 - 2025 Beijing WangXun Technology Co., Ltd. */
#include <linux/pci.h>
#include "wx_type.h"
#include "wx_mbx.h"
/**
* wx_obtain_mbx_lock_pf - obtain mailbox lock
* @wx: pointer to the HW structure
* @vf: the VF index
*
* Return: return 0 on success and -EBUSY on failure
**/
static int wx_obtain_mbx_lock_pf(struct wx *wx, u16 vf)
{
int count = 5;
u32 mailbox;
while (count--) {
/* Take ownership of the buffer */
wr32(wx, WX_PXMAILBOX(vf), WX_PXMAILBOX_PFU);
/* reserve mailbox for vf use */
mailbox = rd32(wx, WX_PXMAILBOX(vf));
if (mailbox & WX_PXMAILBOX_PFU)
return 0;
else if (count)
udelay(10);
}
wx_err(wx, "Failed to obtain mailbox lock for PF%d", vf);
return -EBUSY;
}
static int wx_check_for_bit_pf(struct wx *wx, u32 mask, int index)
{
u32 mbvficr = rd32(wx, WX_MBVFICR(index));
if (!(mbvficr & mask))
return -EBUSY;
wr32(wx, WX_MBVFICR(index), mask);
return 0;
}
/**
* wx_check_for_ack_pf - checks to see if the VF has acked
* @wx: pointer to the HW structure
* @vf: the VF index
*
* Return: return 0 if the VF has set the status bit or else -EBUSY
**/
int wx_check_for_ack_pf(struct wx *wx, u16 vf)
{
u32 index = vf / 16, vf_bit = vf % 16;
return wx_check_for_bit_pf(wx,
FIELD_PREP(WX_MBVFICR_VFACK_MASK,
BIT(vf_bit)),
index);
}
/**
* wx_check_for_msg_pf - checks to see if the VF has sent mail
* @wx: pointer to the HW structure
* @vf: the VF index
*
* Return: return 0 if the VF has got req bit or else -EBUSY
**/
int wx_check_for_msg_pf(struct wx *wx, u16 vf)
{
u32 index = vf / 16, vf_bit = vf % 16;
return wx_check_for_bit_pf(wx,
FIELD_PREP(WX_MBVFICR_VFREQ_MASK,
BIT(vf_bit)),
index);
}
/**
* wx_write_mbx_pf - Places a message in the mailbox
* @wx: pointer to the HW structure
* @msg: The message buffer
* @size: Length of buffer
* @vf: the VF index
*
* Return: return 0 on success and -EINVAL/-EBUSY on failure
**/
int wx_write_mbx_pf(struct wx *wx, u32 *msg, u16 size, u16 vf)
Annotation
- Immediate include surface: `linux/pci.h`, `wx_type.h`, `wx_mbx.h`.
- Detected declarations: `function wx_obtain_mbx_lock_pf`, `function wx_check_for_bit_pf`, `function wx_check_for_ack_pf`, `function wx_check_for_msg_pf`, `function wx_write_mbx_pf`, `function wx_read_mbx_pf`, `function wx_check_for_rst_pf`, `function wx_read_v2p_mailbox`, `function wx_mailbox_get_lock_vf`, `function wx_obtain_mbx_lock_vf`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: integration implementation candidate.
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.