drivers/net/ethernet/airoha/airoha_npu.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/airoha/airoha_npu.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/airoha/airoha_npu.c- Extension
.c- Size
- 21066 bytes
- Lines
- 832
- 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.
- 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/devcoredump.hlinux/firmware.hlinux/platform_device.hlinux/of_net.hlinux/of_platform.hlinux/of_reserved_mem.hlinux/regmap.hairoha_eth.h
Detected Declarations
struct airoha_npu_fwstruct airoha_npu_soc_datastruct ppe_mbox_datastruct wlan_mbox_datafunction airoha_npu_send_msgfunction airoha_npu_load_firmwarefunction airoha_npu_load_firmware_from_dtsfunction airoha_npu_run_firmwarefunction airoha_npu_mbox_handlerfunction airoha_npu_wdt_workfunction airoha_npu_wdt_handlerfunction airoha_npu_ppe_initfunction airoha_npu_ppe_deinitfunction airoha_npu_ppe_flush_sram_entriesfunction airoha_npu_foe_commit_entryfunction airoha_npu_ppe_stats_setupfunction airoha_npu_wlan_msg_sendfunction airoha_npu_wlan_msg_getfunction airoha_npu_wlan_set_reserved_memoryfunction airoha_npu_wlan_init_memoryfunction airoha_npu_wlan_queue_addr_getfunction airoha_npu_wlan_irq_status_setfunction airoha_npu_wlan_irq_status_getfunction airoha_npu_wlan_irq_enablefunction airoha_npu_wlan_irq_disablefunction airoha_npu_putfunction airoha_npu_probefunction airoha_npu_removeexport airoha_npu_getexport airoha_npu_put
Annotated Snippet
struct airoha_npu_fw {
const char *name;
int max_size;
};
struct airoha_npu_soc_data {
struct airoha_npu_fw fw_rv32;
struct airoha_npu_fw fw_data;
};
#define MBOX_MSG_FUNC_ID GENMASK(14, 11)
#define MBOX_MSG_STATIC_BUF BIT(5)
#define MBOX_MSG_STATUS GENMASK(4, 2)
#define MBOX_MSG_DONE BIT(1)
#define MBOX_MSG_WAIT_RSP BIT(0)
#define PPE_TYPE_L2B_IPV4 2
#define PPE_TYPE_L2B_IPV4_IPV6 3
struct ppe_mbox_data {
u32 func_type;
u32 func_id;
union {
struct {
u8 cds;
u8 xpon_hal_api;
u8 wan_xsi;
u8 ct_joyme4;
u8 max_packet;
u8 rsv[3];
u32 ppe_type;
u32 wan_mode;
u32 wan_sel;
} init_info;
struct {
u32 func_id;
u32 size;
u32 data;
} set_info;
struct {
u32 npu_stats_addr;
u32 foe_stats_addr;
} stats_info;
};
};
struct wlan_mbox_data {
u32 ifindex:4;
u32 func_type:4;
u32 func_id;
DECLARE_FLEX_ARRAY(u8, d);
};
static int airoha_npu_send_msg(struct airoha_npu *npu, int func_id,
void *p, int size)
{
u16 core = 0; /* FIXME */
u32 val, offset = core << 4;
dma_addr_t dma_addr;
int ret;
dma_addr = dma_map_single(npu->dev, p, size, DMA_TO_DEVICE);
ret = dma_mapping_error(npu->dev, dma_addr);
if (ret)
return ret;
spin_lock_bh(&npu->cores[core].lock);
regmap_write(npu->regmap, REG_CR_MBQ0_CTRL(0) + offset, dma_addr);
regmap_write(npu->regmap, REG_CR_MBQ0_CTRL(1) + offset, size);
regmap_read(npu->regmap, REG_CR_MBQ0_CTRL(2) + offset, &val);
regmap_write(npu->regmap, REG_CR_MBQ0_CTRL(2) + offset, val + 1);
val = FIELD_PREP(MBOX_MSG_FUNC_ID, func_id) | MBOX_MSG_WAIT_RSP;
regmap_write(npu->regmap, REG_CR_MBQ0_CTRL(3) + offset, val);
ret = regmap_read_poll_timeout_atomic(npu->regmap,
REG_CR_MBQ0_CTRL(3) + offset,
val, (val & MBOX_MSG_DONE),
100, 100 * MSEC_PER_SEC);
if (!ret && FIELD_GET(MBOX_MSG_STATUS, val) != NPU_MBOX_SUCCESS)
ret = -EINVAL;
spin_unlock_bh(&npu->cores[core].lock);
dma_unmap_single(npu->dev, dma_addr, size, DMA_TO_DEVICE);
return ret;
}
static int airoha_npu_load_firmware(struct device *dev, void __iomem *addr,
Annotation
- Immediate include surface: `linux/devcoredump.h`, `linux/firmware.h`, `linux/platform_device.h`, `linux/of_net.h`, `linux/of_platform.h`, `linux/of_reserved_mem.h`, `linux/regmap.h`, `airoha_eth.h`.
- Detected declarations: `struct airoha_npu_fw`, `struct airoha_npu_soc_data`, `struct ppe_mbox_data`, `struct wlan_mbox_data`, `function airoha_npu_send_msg`, `function airoha_npu_load_firmware`, `function airoha_npu_load_firmware_from_dts`, `function airoha_npu_run_firmware`, `function airoha_npu_mbox_handler`, `function airoha_npu_wdt_work`.
- 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.