drivers/net/ethernet/fungible/funcore/fun_dev.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/fungible/funcore/fun_dev.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/fungible/funcore/fun_dev.c- Extension
.c- Size
- 21052 bytes
- Lines
- 834
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitmap.hlinux/delay.hlinux/interrupt.hlinux/io.hlinux/io-64-nonatomic-lo-hi.hlinux/mm.hlinux/module.hlinux/nvme.hlinux/pci.hlinux/wait.hlinux/sched/signal.hfun_queue.hfun_dev.h
Detected Declarations
struct fun_cmd_ctxstruct fun_sync_cmd_ctxfunction fun_wait_readyfunction fun_check_csts_rdyfunction fun_update_cc_enablefunction fun_disable_ctrlfunction fun_enable_ctrlfunction fun_map_barsfunction fun_unmap_barsfunction fun_set_dma_masksfunction fun_admin_irqfunction fun_complete_admin_cmdfunction fun_init_cmd_ctxfunction fun_enable_admin_queuefunction fun_disable_admin_queuefunction fun_adminq_stoppedfunction fun_wait_for_tagfunction fun_submit_admin_cmdfunction fun_abandon_admin_cmdfunction fun_admin_stopfunction fun_admin_cmd_sync_cbfunction fun_submit_admin_sync_cmdfunction fun_get_res_countfunction fun_res_destroyfunction fun_bindfunction fun_get_dev_limitsfunction fun_alloc_irqsfunction fun_alloc_irq_mgrfunction fun_reserve_irqsfunction for_each_clear_bitfunction fun_release_irqsfunction fun_serv_handlerfunction fun_serv_stopfunction fun_serv_restartfunction fun_serv_schedfunction sanitize_devfunction fun_dev_disablefunction fun_dev_enableexport fun_submit_admin_sync_cmdexport fun_get_res_countexport fun_res_destroyexport fun_bindexport fun_reserve_irqsexport fun_release_irqsexport fun_serv_stopexport fun_serv_restartexport fun_serv_schedexport fun_dev_disable
Annotated Snippet
struct fun_cmd_ctx {
fun_admin_callback_t cb; /* callback to invoke on completion */
void *cb_data; /* user data provided to callback */
int cpu; /* CPU where the cmd's tag was allocated */
};
/* Context for synchronous admin commands. */
struct fun_sync_cmd_ctx {
struct completion compl;
u8 *rsp_buf; /* caller provided response buffer */
unsigned int rsp_len; /* response buffer size */
u8 rsp_status; /* command response status */
};
/* Wait for the CSTS.RDY bit to match @enabled. */
static int fun_wait_ready(struct fun_dev *fdev, bool enabled)
{
unsigned int cap_to = NVME_CAP_TIMEOUT(fdev->cap_reg);
u32 bit = enabled ? NVME_CSTS_RDY : 0;
unsigned long deadline;
deadline = ((cap_to + 1) * HZ / 2) + jiffies; /* CAP.TO is in 500ms */
for (;;) {
u32 csts = readl(fdev->bar + NVME_REG_CSTS);
if (csts == ~0) {
dev_err(fdev->dev, "CSTS register read %#x\n", csts);
return -EIO;
}
if ((csts & NVME_CSTS_RDY) == bit)
return 0;
if (time_is_before_jiffies(deadline))
break;
msleep(100);
}
dev_err(fdev->dev,
"Timed out waiting for device to indicate RDY %u; aborting %s\n",
enabled, enabled ? "initialization" : "reset");
return -ETIMEDOUT;
}
/* Check CSTS and return an error if it is unreadable or has unexpected
* RDY value.
*/
static int fun_check_csts_rdy(struct fun_dev *fdev, unsigned int expected_rdy)
{
u32 csts = readl(fdev->bar + NVME_REG_CSTS);
u32 actual_rdy = csts & NVME_CSTS_RDY;
if (csts == ~0) {
dev_err(fdev->dev, "CSTS register read %#x\n", csts);
return -EIO;
}
if (actual_rdy != expected_rdy) {
dev_err(fdev->dev, "Unexpected CSTS RDY %u\n", actual_rdy);
return -EINVAL;
}
return 0;
}
/* Check that CSTS RDY has the expected value. Then write a new value to the CC
* register and wait for CSTS RDY to match the new CC ENABLE state.
*/
static int fun_update_cc_enable(struct fun_dev *fdev, unsigned int initial_rdy)
{
int rc = fun_check_csts_rdy(fdev, initial_rdy);
if (rc)
return rc;
writel(fdev->cc_reg, fdev->bar + NVME_REG_CC);
return fun_wait_ready(fdev, !!(fdev->cc_reg & NVME_CC_ENABLE));
}
static int fun_disable_ctrl(struct fun_dev *fdev)
{
fdev->cc_reg &= ~(NVME_CC_SHN_MASK | NVME_CC_ENABLE);
return fun_update_cc_enable(fdev, 1);
}
static int fun_enable_ctrl(struct fun_dev *fdev, u32 admin_cqesz_log2,
u32 admin_sqesz_log2)
{
fdev->cc_reg = (admin_cqesz_log2 << NVME_CC_IOCQES_SHIFT) |
(admin_sqesz_log2 << NVME_CC_IOSQES_SHIFT) |
((PAGE_SHIFT - 12) << NVME_CC_MPS_SHIFT) |
Annotation
- Immediate include surface: `linux/bitmap.h`, `linux/delay.h`, `linux/interrupt.h`, `linux/io.h`, `linux/io-64-nonatomic-lo-hi.h`, `linux/mm.h`, `linux/module.h`, `linux/nvme.h`.
- Detected declarations: `struct fun_cmd_ctx`, `struct fun_sync_cmd_ctx`, `function fun_wait_ready`, `function fun_check_csts_rdy`, `function fun_update_cc_enable`, `function fun_disable_ctrl`, `function fun_enable_ctrl`, `function fun_map_bars`, `function fun_unmap_bars`, `function fun_set_dma_masks`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.