Skip to content

nxp mcxe247 enet standalone driver - #196

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

twcook86 wants to merge 7 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

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%, 39,860 B / 2,064,384 B, total: 2% used)

stm32h563-freertos-echo

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

stm32h563-freertos-https

  • FLASH: .text +1,176 B (+0.4%, 283,316 B / 2,064,384 B, total: 14% used)

stm32h563-full

  • FLASH: .text +1,176 B (+0.3%, 354,180 B / 2,064,384 B, total: 17% used)

stm32h563-https

  • FLASH: .text +1,176 B (+0.4%, 280,396 B / 2,064,384 B, total: 14% used)

stm32h563-tzen-ssh

  • FLASH: .text +1,184 B (+0.4%, 319,012 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

(void)dev;

if (len == 0 || len > ENET_FRAME_MAX_FRAMELEN)
if (frame == NULL || len == 0U || len > ENET_MAX_FRAME_LEN)

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.

Transmit length limit omits the four-byte FCS that the MAC appends · Regression

enet_mac_start() programs RCR[MAX_FL] to 1518 (line 464). MAX_FL includes the FCS. eth_send() accepts up to 1518 bytes before the FCS and sets ENET_TXBD_TC, so the MAC appends four more. Inputs of 1515-1518 bytes therefore become 1519-1522 bytes on the wire, above the configured limit.

config.h and ll->mtu advertise LINK_MTU 1518, so these lengths are accepted and reported as sent. IPv4 and IPv6 traffic is not affected, because wolfIP_ip_mtu() caps the IP MTU at 1500 (a 1514-byte frame). The reachable cases are packet-socket or direct link-layer sends, and VLAN-tagged full-size frames.

The security scan reports that the removed SDK ENET_SendFrame() rejected lengths above MAX_FL - 4, which would make this a regression. The SDK source was not checked in this synthesis.

The scans disagree on severity: review rated it High/BLOCK and review-security rated it Low. The stricter rating is kept.

They also differ on the consequence. The review scan says a BABT abort silently loses the frame, while the security scan says an oversized frame is sent. The driver code does not settle this. NXP ENET manuals, as recalled rather than checked here, describe BABT as a status flag with no truncation, so do not rely on the frame-loss claim without confirming it in the MCXE24x manual or on hardware.

Suggested fix: Separate the on-wire limit from the transmit-data limit, using one of two options:

  1. If VLAN-sized frames are required (1518 bytes before FCS), keep 1518 as the software limit and set MAX_FL to 1522 (ENET_MAX_FRAME_LEN + 4U), checking the VLAN and receive-side implications.
  2. Otherwise, cap eth_send(), LINK_MTU and the compile-time check at 1514. This also lowers the VLAN sub-interface frame budget to 1510.

Add boundary tests for 1514, 1515 and 1518-byte sends.

break;
}
}
if (ret != 0 && edma_stop(ch) != 0)

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.

Failed eDMA cancellation still hands live buffers to the MAC · Logic

edma_stop() returns failure when it cannot confirm within EDMA_TIMEOUT_US that START and ACTIVE are clear. edma_copy() then only sets g_edma_dead and returns an error. frame_copy() falls back to memcpy() and returns normally. The caller then changes buffer ownership: eth_poll() calls rx_release(), and eth_send() marks the TX descriptor READY.

The channel has not been shown to be idle. It may still read an RX buffer while the MAC overwrites it, or write a TX buffer while the MAC is transmitting it. g_edma_dead stops later eDMA copies but does not make the current buffers safe.

This needs two failures in a row: a transfer error or timeout, then a cancellation that is not honored. It applies only with NXP_MCXE_ENET_EDMA enabled, which is the default.

The scans disagree on severity: review rated it High/BLOCK and review-security rated it Low (exceptional trigger, narrow reach). The stricter rating is kept.

Suggested fix: Treat a channel that cannot be confirmed idle as fatal for the current copy. Propagate the failure through frame_copy() and keep ownership of both buffers: do not release the RX descriptor or mark the TX descriptor READY. Alternatively, use a reference-manual-defined reset or disable sequence that guarantees the channel is quiet before returning. Add tests that force an unhonored cancellation on both RX and TX.

Comment thread src/wolfip.c
* as one of 16-bit network order words, byte swapped (RFC 1071 2(B)), and
* csum_fold() swaps it back. p need not be aligned. Only the last block
* added to a sum may have an odd length; its last byte is padded with zero. */
static uint64_t csum_add(uint64_t sum, const uint8_t *p, uint32_t len)

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.

Checksum rewrite lacks independent reference coverage · test

The new host-order, 32-bit batching sum is shared by the TCP/UDP, ICMP, IPv4 header and multicast checksums. Its correctness depends on byte order, carry folding and odd-tail handling.

test_transport_checksum and test_iphdr_set_checksum only assert a nonzero result. Other tests build or verify checksums with the same rewritten helpers, so a self-consistent endian or tail defect could pass. No direct sweep against an independent implementation across lengths and offsets was identified. Interoperability tests may exercise some cases indirectly. No defect in the implementation itself was reported.

Suggested fix: Compare the checksum functions against an independent byte-wise RFC 1071 implementation for lengths 0-1600 at offsets 0-3. Include odd-length transport bodies and known wire-format vectors, and run a big-endian build if one is supported.

* address, interface name and poll/send callbacks. May be called again to
* restart the interface. Returns 0 when the MAC is running, even without
* link, or a negative value when the PHY or MAC cannot be initialized. */
/* 1: interrupt driven. The receive interrupt marks frames waiting, so

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.

IRQ comments still promise a TX interrupt and wfi sleep · documentation

The option comment says a full TX ring sleeps in wfi until the transmit interrupt and that IRQ 73 must be routed. The implementation polls in tx_wait(), and enet_irq_enable() enables only the RX and error interrupts. The README is correct.

The same outdated design appears in the source-file preamble (nxp_mcxe_enet.c:7-9) and in the handler declaration comment (nxp_mcxe_enet.h:127).

Suggested fix: Update all three comments to match the code: only IRQs 74 (receive) and 75 (error) need routing to nxp_mcxe_enet_irq_handler(), and a full TX ring is polled until the oldest descriptor completes or times out.

#endif
}

static void enet_pins_init(void)

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.

The pin mux and the PTC3 PHY reset are hard coded here, and phy_init() only accepts a LAN8741 ID, so an E247 board with other routing or another PHY needs a driver edit. The other NXP ports keep this in a *_board.h and use common/nxp_phy.h for PHY bring-up, can this follow the same split?

/* The system MPU blocks the ENET bus master by default */
SYSMPU->CESR &= ~SYSMPU_CESR_VLD_MASK;
/* The system MPU blocks the ENET and eDMA bus masters by default */
SYSMPU_CESR &= ~SYSMPU_CESR_VLD;

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.

Clearing SYSMPU_CESR[VLD] turns off the system MPU for every bus master, not just ENET and eDMA, which is a lot for a NIC init to do on a part aimed at SIL 2 designs. Can you program a region descriptor for the ENET and eDMA masters instead, or leave the MPU to the application?

@aidangarske aidangarske assigned twcook86 and unassigned wolfSSL-Bot Nov 25, 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