drivers/net/ethernet/mediatek/mtk_wed_mcu.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mediatek/mtk_wed_mcu.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mediatek/mtk_wed_mcu.c- Extension
.c- Size
- 9567 bytes
- Lines
- 412
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/firmware.hlinux/of_address.hlinux/of_reserved_mem.hlinux/mfd/syscon.hlinux/soc/mediatek/mtk_wed.hlinux/unaligned.hmtk_wed_regs.hmtk_wed_wo.hmtk_wed.h
Detected Declarations
function wo_r32function wo_w32function mtk_wed_mcu_msg_allocfunction mtk_wed_mcu_get_responsefunction mtk_wed_mcu_rx_eventfunction mtk_wed_update_rx_statsfunction mtk_wed_mcu_rx_unsolicited_eventfunction mtk_wed_mcu_skb_send_msgfunction mtk_wed_mcu_parse_responsefunction mtk_wed_mcu_send_msgfunction mtk_wed_mcu_msg_updatefunction mtk_wed_get_memory_regionfunction mtk_wed_mcu_run_firmwarefunction mtk_wed_mcu_load_firmwarefunction mtk_wed_mcu_read_fw_dlfunction mtk_wed_mcu_init
Annotated Snippet
if (!region->shared || !region->consumed) {
memcpy_toio(region->addr, ptr, length);
region->consumed = true;
break;
}
}
if (i == ARRAY_SIZE(mem_region))
return -EINVAL;
next:
region_ptr += sizeof(*fw_region);
ptr += length;
}
return 0;
}
static int
mtk_wed_mcu_load_firmware(struct mtk_wed_wo *wo)
{
const struct mtk_wed_fw_trailer *trailer;
const struct firmware *fw;
const char *fw_name;
u32 val, boot_cr;
int ret, i;
/* load firmware region metadata */
for (i = 0; i < ARRAY_SIZE(mem_region); i++) {
ret = mtk_wed_get_memory_region(wo->hw, mem_region[i].name, &mem_region[i]);
if (ret)
return ret;
}
/* set dummy cr */
wed_w32(wo->hw->wed_dev, MTK_WED_SCR0 + 4 * MTK_WED_DUMMY_CR_FWDL,
wo->hw->index + 1);
/* load firmware */
switch (wo->hw->version) {
case 2:
if (of_device_is_compatible(wo->hw->node,
"mediatek,mt7981-wed"))
fw_name = MT7981_FIRMWARE_WO;
else
fw_name = wo->hw->index ? MT7986_FIRMWARE_WO1
: MT7986_FIRMWARE_WO0;
break;
case 3:
fw_name = wo->hw->index ? MT7988_FIRMWARE_WO1
: MT7988_FIRMWARE_WO0;
break;
default:
return -EINVAL;
}
ret = request_firmware(&fw, fw_name, wo->hw->dev);
if (ret)
return ret;
trailer = (void *)(fw->data + fw->size -
sizeof(struct mtk_wed_fw_trailer));
dev_info(wo->hw->dev,
"MTK WED WO Firmware Version: %.10s, Build Time: %.15s\n",
trailer->fw_ver, trailer->build_date);
dev_info(wo->hw->dev, "MTK WED WO Chip ID %02x Region %d\n",
trailer->chip_id, trailer->num_region);
ret = mtk_wed_mcu_run_firmware(wo, fw);
if (ret)
goto out;
/* set the start address */
if (!mtk_wed_is_v3_or_greater(wo->hw) && wo->hw->index)
boot_cr = MTK_WO_MCU_CFG_LS_WA_BOOT_ADDR_ADDR;
else
boot_cr = MTK_WO_MCU_CFG_LS_WM_BOOT_ADDR_ADDR;
wo_w32(boot_cr, mem_region[MTK_WED_WO_REGION_EMI].phy_addr >> 16);
/* wo firmware reset */
wo_w32(MTK_WO_MCU_CFG_LS_WF_MCCR_CLR_ADDR, 0xc00);
val = wo_r32(MTK_WO_MCU_CFG_LS_WF_MCU_CFG_WM_WA_ADDR);
if (!mtk_wed_is_v3_or_greater(wo->hw) && wo->hw->index)
val |= MTK_WO_MCU_CFG_LS_WF_WM_WA_WA_CPU_RSTB_MASK;
else
val |= MTK_WO_MCU_CFG_LS_WF_WM_WA_WM_CPU_RSTB_MASK;
wo_w32(MTK_WO_MCU_CFG_LS_WF_MCU_CFG_WM_WA_ADDR, val);
out:
release_firmware(fw);
Annotation
- Immediate include surface: `linux/firmware.h`, `linux/of_address.h`, `linux/of_reserved_mem.h`, `linux/mfd/syscon.h`, `linux/soc/mediatek/mtk_wed.h`, `linux/unaligned.h`, `mtk_wed_regs.h`, `mtk_wed_wo.h`.
- Detected declarations: `function wo_r32`, `function wo_w32`, `function mtk_wed_mcu_msg_alloc`, `function mtk_wed_mcu_get_response`, `function mtk_wed_mcu_rx_event`, `function mtk_wed_update_rx_stats`, `function mtk_wed_mcu_rx_unsolicited_event`, `function mtk_wed_mcu_skb_send_msg`, `function mtk_wed_mcu_parse_response`, `function mtk_wed_mcu_send_msg`.
- 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.