Skip to content

nxp mcxe247 enet standalone driver - #196

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

twcook86 wants to merge 15 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 thread src/port/nxp_mcxe_enet/nxp_mcxe_enet.c Resolved
Comment thread src/port/nxp_mcxe_enet/nxp_mcxe_enet.c Resolved

@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.
@twcook86 twcook86 assigned wolfSSL-Bot and unassigned twcook86 Nov 17, 2026
@twcook86
twcook86 requested a review from danielinux November 17, 2026 04:23
@twcook86 twcook86 assigned twcook86 and unassigned wolfSSL-Bot Nov 23, 2026
@twcook86 twcook86 mentioned this pull request Nov 24, 2026
@twcook86 twcook86 assigned wolfSSL-Bot and unassigned twcook86 Nov 24, 2026
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.
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

amd-zynq7000

  • OCM: .text +160 B (+0.1%, 234,680 B / 262,144 B, total: 90% used)

linux-x64-libwolfip

  • Code: .eh_frame +64 B, .eh_frame_hdr +16 B, .text -173 B (-0.1%, 165,289 B)

lpc54s018

  • FLASH: .text +128 B (+0.2%, 68,732 B / 16,777,216 B, total: 0% used)

stm32h563-echo

  • FLASH: .text +100 B (+0.3%, 40,016 B / 2,064,384 B, total: 2% used)

stm32h563-freertos-echo

  • FLASH: .text +104 B (+0.1%, 79,464 B / 2,064,384 B, total: 4% used)

stm32h563-freertos-https

  • FLASH: .text +688 B (+0.2%, 285,140 B / 2,064,384 B, total: 14% used)

stm32h563-full

  • FLASH: .text +656 B (+0.2%, 356,844 B / 2,064,384 B, total: 17% used)

stm32h563-https

  • FLASH: .text +688 B (+0.2%, 282,220 B / 2,064,384 B, total: 14% used)

stm32h563-tzen-ssh

  • FLASH: .text +648 B (+0.2%, 321,604 B / 654,336 B, total: 49% used)

stm32h563-wolfhal-nucleo

  • FLASH: .text +100 B (+0.2%, 40,492 B / 2,097,152 B, total: 2% used)

stm32n6

  • SRAM: .text +72 B (+0.1%, 129,856 B / 524,288 B, total: 25% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@twcook86
twcook86 requested review from dgarske and removed request for danielinux November 25, 2026 20:47
@dgarske
dgarske requested a review from aidangarske November 25, 2026 21:28

@aidangarske aidangarske left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Comment thread src/port/nxp_mcxe_enet/nxp_mcxe_enet.c Resolved
Comment thread src/port/nxp_mcxe_enet/nxp_mcxe_enet.c Resolved
Comment thread src/wolfip.c Resolved
Comment thread src/port/nxp_mcxe_enet/nxp_mcxe_enet.h Resolved
Comment thread src/port/nxp_mcxe_enet/nxp_mcxe_enet.c Resolved
Comment thread src/port/nxp_mcxe_enet/nxp_mcxe_enet.c Resolved
@aidangarske aidangarske assigned twcook86 and unassigned wolfSSL-Bot Nov 25, 2026

@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, 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/config.h, 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

Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Lite

Comment thread src/port/nxp_mcxe_enet/nxp_mcxe_enet.c Resolved

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 issues remain: the PHY helper include order breaks compilation/linking, and failed eDMA cancellation can leave DMA accessing caller-owned buffers after return, risking stack corruption.

2 open issues
2 resolved since last review

Review effort: Balanced

Comment thread src/port/nxp_mcxe_enet/nxp_mcxe_enet.c Resolved
Comment thread src/port/nxp_mcxe_enet/nxp_mcxe_enet.c Resolved

@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, src/test/unit/unit.c, src/test/unit/unit_tests_proto.c
Coverage: 1 of 2 in-scope changed file(s) opened by the reviewer; not opened: src/port/nxp_mcxe_enet/nxp_mcxe_enet.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: Lite

@wolfSSL-Fenrir-bot
wolfSSL-Fenrir-bot dismissed their stale review December 1, 2026 06:00

Fenrir's latest completed scan found no issues; clearing the prior automated change request.

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.

🔵 Needs a closer look

The timeout recovery uses global eDMA cancellation that can race with channel switching and abort an unrelated application's transfer.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

High severity Avoid cancelling unrelated transfers on the shared eDMA controller

src/​port/​nxp_mcxe_enet/​nxp_mcxe_enet.c:252

CR.CX cancels the controller's currently executing channel, not the channel identified by ch. The ENET channel can finish after the ACTIVE read and another application's eDMA channel can start before this write, causing the timeout recovery to abort an unrelated transfer. Reserving only NXP_MCXE_ENET_EDMA_CH does not prevent this race. Avoid global cancellation when the controller is shared—for example, prevent further starts of this channel and wait for it to become inactive before using the memcpy fallback—or require exclusive ownership of the entire controller.

2 resolved since last review

Review effort: Balanced

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.
@twcook86 twcook86 assigned wolfSSL-Bot and unassigned twcook86 Dec 1, 2026
@dgarske
dgarske requested a review from aidangarske December 1, 2026 21:42

@aidangarske aidangarske left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Comment thread src/port/nxp_mcxe_enet/nxp_mcxe_enet.c Resolved
Comment thread src/port/nxp_mcxe_enet/nxp_mcxe_enet.c Resolved
Comment thread src/port/nxp_mcxe_enet/nxp_mcxe_enet.c Resolved
@aidangarske aidangarske assigned twcook86 and unassigned wolfSSL-Bot Dec 1, 2026
- 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.
@twcook86
twcook86 requested a review from aidangarske December 2, 2026 18:48
- 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 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, 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

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

The driver lacks declarations for memcpy() and memset(), causing strict C99 build failures, and MDIO read failures can stall initialization for roughly 90 seconds.

2 open issues

Review effort: Balanced

Comment thread src/port/nxp_mcxe_enet/nxp_mcxe_enet.c Resolved
Comment thread src/port/nxp_mcxe_enet/nxp_mcxe_enet.c Resolved
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.
@twcook86 twcook86 assigned wolfSSL-Bot and unassigned twcook86 Dec 3, 2026
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.

5 participants