Skip to content

nxp mcxe247 enet standalone driver - #196

Open
twcook86 wants to merge 6 commits into
wolfSSL:masterfrom
twcook86:mcxe247_enet_standalone
Open

twcook86 wants to merge 6 commits into
wolfSSL:masterfrom
twcook86:mcxe247_enet_standalone

Conversation

@twcook86

@twcook86 twcook86 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Adds a standalone driver for mcxe247, eliminating sdk dependency.
Driver is interrupt-driven and optimized for throughput.

Goes with wolfSSL/wolfBoot#991

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.
Copilot AI balanced review requested due to automatic review settings November 16, 2026 23:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment on lines +243 to +245
(DWT_CYCCNT - start) >= ticks) {
ret = -1;
break;
Comment thread src/port/nxp_mcxe_enet/nxp_mcxe_enet.c Outdated
Comment on lines +533 to +549
#if NXP_MCXE_ENET_IRQ
uint32_t primask;
#endif

while ((bd->control & ENET_TXBD_READY) != 0U) {
if ((DWT_CYCCNT - start) >= ticks)
return -1;
#if NXP_MCXE_ENET_IRQ
/* Sleep until the transmit-complete interrupt. Interrupts are
* masked around the check so one that fires just before wfi still
* wakes it (a pending interrupt ends wfi even while masked). */
__asm__ volatile ("mrs %0, primask" : "=r"(primask));
__asm__ volatile ("cpsid i" ::: "memory");
if ((bd->control & ENET_TXBD_READY) != 0U)
__asm__ volatile ("wfi");
__asm__ volatile ("msr primask, %0" :: "r"(primask) : "memory");
#endif

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants