Skip to content

NXP ENET driver: mutex used in ISR #89442

@duerrfk

Description

@duerrfk

Describe the bug

The NXP ENET driver uses a mutex inside an ISR.

Function ts_register_tx_event() (source file zephyr/drivers/ethernet/eth_nxp_enet.c) is invoked from the ISR when a TX packet timestamp is available. Before the timestamp is copied to the packet, a mutex is locked, most likely to protect the timestamp from concurrent read/write operations. Since mutexes are not allowed in ISR, the following assertion is triggered (when compiled with assertions):

ASSERTION FAIL [!arch_is_in_isr()] @ WEST_TOPDIR/zephyr/kernel/mutex.c:111

        mutexes cannot be used inside ISRs

The error shows if compiled with gPTP support (CONFIG_NET_GPTP=y), since gPTP requires packet timestamps.

I think, the problem can be fixed by simply removing the calls to the mutex in ts_register_tx_event() since the timestamp is also protected from concurrent read operations using a semaphore (ptp_ts_sem), which is only released after copying the timestamp to the packet. This semaphore ptp_ts_sem ensures sequential execution of writing the timestamp in ts_register_tx_event() (inside the ISR) and subsequently reading the timestamp after waiting for the semaphore ptp_ts_sem in eth_wait_for_ptp_ts().

I will make a pull request. There are a couple of more problems with the NXP ENET driver related to PTP, which I will address in further issues and pull requests (currently, gPTP does not work with the NXP ENET driver).

To Reproduce

Platform: Teensy 4.1 (same issue applies at least to all NXP i.MX RT106x platforms).

Compile with gPTP and assertions:

CONFIG_NET_GPTP=y
CONFIG_ASSERT=y

Run gPTP sample (samples/net/gptp), and wait until a timestamped PTP packet is transmitted (happens within seconds when network is up).

Expected behavior

System should not halt with assertion.

Impact

gPTP not working with NXP ENET driver if compiled with assertions.

Logs and console output

ASSERTION FAIL [!arch_is_in_isr()] @ WEST_TOPDIR/zephyr/kernel/mutex.c:111

        mutexes cannot be used inside ISRs

Environment (please complete the following information):

  • OS: Linux (Debian);
  • Target platform: Teensy 4.1 / NXP i.MX RT106x
  • Toolchain: SDK 0.17.0
  • Head May 4, 2025 (021d90b)

Additional context
n/a

Metadata

Metadata

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions