Repository navigation
nxp mcxe247 enet standalone driver - #196
Conversation
Replace the fsl_enet based port with a register-level ENET, LAN8741 and eDMA driver that builds without the vendor SDK. - NXP_MCXE_ENET_IRQ: polled (0) or interrupt driven (1). The receive interrupt lets poll() return at once on an empty ring; send() sleeps in wfi when the transmit ring is full. - NXP_MCXE_ENET_EDMA: copy frames between the rings and wolfIP buffers with an eDMA channel, memcpy for short frames or on error. - NXP_MCXE_ENET_STATS: frame and DWT cycle counters for throughput profiling, read with nxp_mcxe_enet_stats_get(). - A full transmit ring waits for the oldest frame instead of failing, since wolfIP does not retry a dropped ACK. - config.h: RXBUF_SIZE and TXBUF_SIZE can be overridden by the build.
wolfIP_poll() takes up to 128 frames from each device per call. On a slow CPU under a line-rate UDP flood the socket buffer fills after a few datagrams, and the rest of the batch is processed only to be dropped before the application can read. A smaller budget lets the application drain the socket between batches.
eth_poll() released an errored frame (FIFO overrun, CRC error) and returned 0, which wolfIP takes as an empty ring, so poll_devices() stopped and left the rest of the ring for the next poll. Under a line-rate flood while the CPU was also transmitting, the MAC refilled each freed descriptor with another overrun fragment and the ring stayed full: in a UDP bidir test 71k polls returned 4k good frames and 93% of received frames overflowed the FIFO. Release errored frames and look at the next descriptor, returning on a good frame, an empty ring, or after one pass over the ring. UDP bidir at 80 MHz: board rx 2.9 -> 19.1 Mbit/s.
The checksums added one 16-bit word at a time, byte swapping each, and transport_checksum was a quarter of the CPU time on a Cortex-M4 at line rate. csum_add() adds 32-bit words in host byte order into a 64-bit sum, four per iteration, through memcpy so the buffer need not be aligned. csum_fold() folds to 16 bits once and swaps back to network order (the one's complement sum is byte order independent, RFC 1071 2(B)). The transport, ICMP, IP header and multicast checksums all use them. MCX E247 at 80 MHz: udp-rx 43.4 -> 56.0, udp-tx 41.7 -> 49.6, tcp-rx 27.0 -> 29.2, tcp-tx 25.6 -> 28.7 Mbit/s. Matches a byte-wise RFC 1071 reference for every length 0-1600 at four alignments; unit, multicast, asan, ubsan and ipv6 unit tests pass.
There was a problem hiding this comment.
🟡 Changes recommended
Critical timeout flaws can leave eth_send() blocked indefinitely and allow an active eDMA transfer to access buffers after ownership changes, risking hangs and data corruption.
2 open issues
What changed in this PR
Replaces the NXP MCX E247 port’s SDK-based Ethernet driver with a standalone implementation, adding optional interrupt-driven operation and throughput-focused data handling.
Changes:
- Programs the MAC, PHY, descriptor rings, and optional eDMA directly.
- Adds driver statistics and configurable socket buffers and poll budget.
- Consolidates core checksum routines into shared word-based helpers.
| File | Description |
|---|---|
src/wolfip.c |
Shares optimized checksum helpers and allows poll-budget overrides. |
src/port/nxp_mcxe_enet/README.md |
Documents standalone operation, build options, and memory requirements. |
src/port/nxp_mcxe_enet/nxp_mcxe_enet.h |
Exposes configuration options, statistics, and interrupt APIs. |
src/port/nxp_mcxe_enet/nxp_mcxe_enet.c |
Implements direct hardware initialization and ring-based receive/transmit paths. |
src/port/nxp_mcxe_enet/nxp_mcxe_enet_regs.h |
Defines hardware registers without SDK dependencies. |
src/port/nxp_mcxe_enet/config.h |
Allows applications to override receive and transmit buffer sizes. |
Review effort: Balanced
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #196
Scan targets checked: wolfip-src, wolfip-bugs
Not reviewed (no scan target covers them): src/port/nxp_mcxe_enet/README.md
Coverage: 4 of 5 in-scope changed file(s) opened by the reviewer; not opened: src/port/nxp_mcxe_enet/nxp_mcxe_enet_regs.h
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Max
A timed-out eDMA copy returned while the channel could still be pending or running, and its buffers then changed hands (the receive descriptor back to the MAC, the transmit buffer to the MAC). edma_stop() now keeps a channel that has not started from starting (clears START) and cancels a running one with CR.CX, then waits until it is idle. If it does not become idle, the eDMA is not used again and all copies use memcpy. tx_wait() slept in wfi until the transmit interrupt. DWT_CYCCNT stops while the core sleeps, so a transmitter that never raised the interrupt would never time out. It now polls the descriptor within the 5 ms limit, and the transmit interrupt, which only woke that wfi, is no longer enabled. Tested on the FRDM-MCXE247: the wolfBoot test-app speed suite passes at unchanged rates, and with the copy timeout forced to 20 cycles all 411124 copies were cancelled and redone by the CPU with no errors.
eth_send() rejects frames over 1518 bytes, but LINK_MTU was 1536, so wolfIP accepted 1519-1536 byte packet-socket frames that the driver then refused forever, blocking the socket's transmit queue. Set LINK_MTU to 1518 and check it against ENET_MAX_FRAME_LEN at build time; the socket buffer defaults stay at 1536 bytes.
|
aidangarske
left a comment
There was a problem hiding this comment.
Skoll Multi-Scan Review
Modes: review + review-security
Overall recommendation: REQUEST_CHANGES
Findings: 4 total — 4 posted, 0 skipped
4 finding(s) posted as inline comments (see file-level comments below)
Posted findings
- [High] [review+review-security] Transmit length limit omits the four-byte FCS that the MAC appends —
src/port/nxp_mcxe_enet/nxp_mcxe_enet.c:589 - [High] [review+review-security] Failed eDMA cancellation still hands live buffers to the MAC —
src/port/nxp_mcxe_enet/nxp_mcxe_enet.c:285-286 - [Medium] [review] Checksum rewrite lacks independent reference coverage —
src/wolfip.c:2298-2344 - [Low] [review] IRQ comments still promise a TX interrupt and wfi sleep —
src/port/nxp_mcxe_enet/nxp_mcxe_enet.h:41-45
Review generated by Skoll
CR.CX cancels whichever channel the controller is executing, not the driver's channel: the copy can finish after the ACTIVE read and an application channel start before the write, which then aborts the application's transfer. After a timeout, set CR.HALT so the controller starts no channel, wait for a running copy to finish by itself, withdraw one not started by clearing START, and clear HALT again unless it was already set. Other channels are delayed, not cancelled. The receive buffer is still handed back only once the channel is idle. Tested on the FRDM-MCXE247 with every copy forced to time out (EDMA_TIMEOUT_US 0): the network speed test passes on the memcpy fallback. Normal build rates unchanged.
aidangarske
left a comment
There was a problem hiding this comment.
Skoll Code Review
Scan type: review
Overall recommendation: REQUEST_CHANGES
Findings: 3 total — 3 posted, 0 skipped
3 finding(s) posted as inline comments (see file-level comments below)
Posted findings
- [High] Failed MDIO reads are treated as valid negotiated capabilities —
src/port/nxp_mcxe_enet/nxp_mcxe_enet.c:460-467 - [Medium] The documented five-second initialization bound can be doubled —
src/port/nxp_mcxe_enet/nxp_mcxe_enet.c:762-769 - [Medium] eDMA timeout recovery has no automated regression coverage —
src/port/nxp_mcxe_enet/nxp_mcxe_enet.c:305-323
Review generated by Skoll
- phy_wait_link() reads ANAR and ANLPAR with mdio_read() and polls again when either read fails, instead of deriving the speed and duplex from a data register that does not hold the value. - nxp_mcxe_enet_init() without link blocks for up to about 10 s (5 s auto-negotiation in the PHY bring-up, then 5 s for the link), not 5 s. Documented in the header. Tested on the FRDM-MCXE247: network speed test unchanged.
- Restart the MAC after an ENET DMA bus error, including one raised while the restart runs; report the count with nxp_mcxe_enet_bus_errors(). After a failed re-init, poll() and send() drop traffic until a call succeeds. - Remove the eDMA copy option: it was no faster for receive and 2-4% slower for transmit than memcpy. - Read the core clock live (SIRC range included) for timeouts and stats, and set the MDIO clock from it before each transfer; us_to_cycles() scales milliseconds and the remainder separately so long delays do not overflow. - Keep the PHY address found on the bus. For a parallel-detected link, read the resolved speed from PSCSR on a LAN8710/8720/8740/8741/8742, matched by model; other PHYs get 100 Mbit/s half duplex. - Check NXP_MCXE_ENET_SYSMPU_RGD against SYSMPU_RGD_NUM, only when the driver programs the system MPU, and WOLFIP_POLL_BUDGET >= 1. - Document the init return codes and blocking time, and that the MAC keeps the speed and duplex found at init until it is called again.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #196
Scan targets checked: wolfip-src, wolfip-bugs
Not reviewed (no scan target covers them): src/port/nxp_mcxe_enet/README.md, src/test/unit/unit.c, src/test/unit/unit_tests_proto.c
Coverage: 2 of 6 in-scope changed file(s) opened by the reviewer; not opened: src/port/nxp_mcxe_enet/nxp_mcxe_enet.h, src/port/nxp_mcxe_enet/nxp_mcxe_enet_board.h, src/port/nxp_mcxe_enet/nxp_mcxe_enet_regs.h, src/wolfip.c
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Lite
If MDIO stopped completing after the PHY reset write, each of the MDIO_TIMEOUT reset and auto-negotiation polls waited for the 1 ms MDIO timeout, blocking init for about 90 s. The first timeout now makes later MDIO transfers fail at once until nxp_mcxe_enet_init() runs again.
aidangarske
left a comment
There was a problem hiding this comment.
Skoll Code Review
Scan type: review
Overall recommendation: REQUEST_CHANGES
Findings: 2 total — 1 posted, 1 skipped
1 finding(s) posted as inline comments (see file-level comments below)
Posted findings
- [High] Receive descriptor fields are not read from a stable snapshot —
src/port/nxp_mcxe_enet/nxp_mcxe_enet.c:578-600
Skipped findings
- [Medium]
Standalone descriptor and recovery paths lack automated coverage
Review generated by Skoll
eth_poll() read the descriptor control word and then its length, so it could combine fields from two DMA states. rx_bd_snapshot() reads control, length and buffer, then control again, and retries until both control reads match, as ENET_GetRxBdSnapshot() in the MCUXpresso driver. After a few changing reads the descriptor is left for the next poll.
aidangarske
left a comment
There was a problem hiding this comment.
Can you add a Cortex-M4 compile job here for the polled driver and for IRQ mode with stats enabled? The LPC54S018 job builds a different driver. This would catch a broken MCXE247 build before it reaches wolfBoot.
- nxp_mcxe_enet_stop() disables the interrupt and the MAC, so a caller can stop it before a clock change; init stops a running MAC first. - send() returns -WOLFIP_EAGAIN at once when the TX ring is full instead of busy-waiting; wolfIP retries. Count refusals in tx_ring_full. - README: describe the transmit behavior and the wolfBoot test-app. - CI: Cortex-M4 compile of the driver and wolfIP core, polled and IRQ mode with stats, with -Werror and a check on the interrupt handler symbol.
|
Added in 28f7fe7: .github/workflows/mcxe247.yml compiles the MCXE247 driver and wolfIP core for Cortex-M4 with -Werror, polled and IRQ with stats, and checks the IRQ handler matches the mode. Both jobs pass. |
aidangarske
left a comment
There was a problem hiding this comment.
Looks good Tom, thank you!


Adds a standalone driver for mcxe247, eliminating sdk dependency.
Driver is interrupt-driven and optimized for throughput.
Goes with wolfSSL/wolfBoot#991