Skip to content

netc driver refine and enhancement #93294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions boards/nxp/imx95_evk/board.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 NXP
* Copyright 2024-2025 NXP
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -10,21 +10,6 @@

static int board_init(void)
{
#if defined(CONFIG_ETH_NXP_IMX_NETC) && (DT_CHILD_NUM_STATUS_OKAY(DT_NODELABEL(netc)) != 0)
/* Port 0 to 2 protocol configure: RGMII, RGMII, XGMII */
BLK_CTRL_NETCMIX->CFG_LINK_MII_PROT = 0x00000522;
BLK_CTRL_NETCMIX->CFG_LINK_PCS_PROT_2 = 0x00000040;

/* Unlock the IERB. It will warm reset whole NETC. */
NETC_PRIV->NETCRR &= ~NETC_PRIV_NETCRR_LOCK_MASK;
while ((NETC_PRIV->NETCRR & NETC_PRIV_NETCRR_LOCK_MASK) != 0U) {
}

/* Lock the IERB. */
NETC_PRIV->NETCRR |= NETC_PRIV_NETCRR_LOCK_MASK;
while ((NETC_PRIV->NETCSR & NETC_PRIV_NETCSR_STATE_MASK) != 0U) {
}
#endif
return 0;
}

Expand Down
3 changes: 1 addition & 2 deletions boards/nxp/imx95_evk/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ Ethernet
--------

NETC driver supports to manage the Physical Station Interface (PSI).
The first ENET1 port could be enabled for M7 by west build option
``-DEXTRA_DTC_OVERLAY_FILE=enetc_psi0.overlay``.
The first ENET1 port could be enabled on M7 DDR platform.


Programming and Debugging (A55)
Expand Down
21 changes: 0 additions & 21 deletions boards/nxp/imx95_evk/dts/enetc_psi0.overlay

This file was deleted.

12 changes: 8 additions & 4 deletions boards/nxp/imx95_evk/imx95_evk_mimx9596_m7.dts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 NXP
* Copyright 2024-2025 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -26,12 +26,12 @@
&emdio {
pinctrl-0 = <&emdio_default>;
pinctrl-names = "default";
status = "disabled";
status = "okay";

phy0: phy@1 {
compatible = "realtek,rtl8211f";
reg = <0x1>;
status = "disabled";
status = "okay";
};
};

Expand All @@ -41,7 +41,11 @@
pinctrl-names = "default";
phy-handle = <&phy0>;
phy-connection-type = "rgmii";
status = "disabled";
status = "okay";
};

&enetc_ptp_clock {
status = "okay";
};

&flexspi {
Expand Down
1 change: 1 addition & 0 deletions drivers/ethernet/nxp_imx_netc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
if(CONFIG_ETH_NXP_IMX_NETC)
zephyr_library_sources(eth_nxp_imx_netc.c)
zephyr_library_sources(eth_nxp_imx_netc_psi.c)
zephyr_library_sources_ifdef(CONFIG_DT_HAS_NXP_IMX_NETC_BLK_CTRL_ENABLED eth_nxp_imx_netc_blk.c)
endif()

zephyr_library_sources_ifdef(CONFIG_DSA_NXP_IMX_NETC dsa_nxp_imx_netc.c)
14 changes: 14 additions & 0 deletions drivers/ethernet/nxp_imx_netc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,25 @@ menuconfig ETH_NXP_IMX_NETC

if ETH_NXP_IMX_NETC

DT_GIC_ITS_COMPAT := arm,gic-v3-its
DT_NETC_PATH := $(dt_nodelabel_path,netc)
DT_NETC_INT_PARENT_PATH := $(dt_node_ph_prop_path,$(DT_NETC_PATH),msi-parent)
DT_NETC_INT_IS_GIC := $(dt_node_has_compat,$(DT_NETC_INT_PARENT_PATH),$(DT_GIC_ITS_COMPAT))

config ETH_NXP_IMX_NETC_MSI_GIC
bool
default y if ($(DT_NETC_INT_IS_GIC) && DT_HAS_ARM_GIC_V3_ITS_ENABLED)
depends on GIC_V3_ITS
help
Use GIC ITS controller as MSI module for NXP NETC

if !ETH_NXP_IMX_NETC_MSI_GIC
config ETH_NXP_IMX_MSGINTR
int "Message Interrupt module select"
default 1
help
Message Interrupt module select.
endif

config ETH_NXP_IMX_RX_THREAD_PRIO
int "RX thread priority"
Expand Down
73 changes: 73 additions & 0 deletions drivers/ethernet/nxp_imx_netc/eth_nxp_imx_netc.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ LOG_MODULE_REGISTER(nxp_imx_eth);
#include <zephyr/net/phy.h>
#include <ethernet/eth_stats.h>
#include <zephyr/net/dsa_core.h>
#ifdef CONFIG_GIC_V3_ITS
#include <zephyr/drivers/interrupt_controller/gicv3_its.h>
#endif
#include "../eth.h"
#include "eth_nxp_imx_netc_priv.h"

Expand Down Expand Up @@ -173,6 +176,28 @@ static void netc_eth_rx_thread(void *arg1, void *unused1, void *unused2)
}
}

#ifdef CONFIG_ETH_NXP_IMX_NETC_MSI_GIC

static void netc_tx_isr_handler(const void *arg)
{
const struct device *dev = (const struct device *)arg;
struct netc_eth_data *data = dev->data;

EP_CleanTxIntrFlags(&data->handle, 1, 0);
data->tx_done = true;
}

static void netc_rx_isr_handler(const void *arg)
{
const struct device *dev = (const struct device *)arg;
struct netc_eth_data *data = dev->data;

EP_CleanRxIntrFlags(&data->handle, 1);
k_sem_give(&data->rx_sem);
}

#else /* CONFIG_ETH_NXP_IMX_NETC_MSI_GIC */

static void msgintr_isr(void)
{
uint32_t irqs = NETC_MSGINTR->MSI[NETC_MSGINTR_CHANNEL].MSIR;
Expand Down Expand Up @@ -203,6 +228,8 @@ static void msgintr_isr(void)
SDK_ISR_EXIT_BARRIER;
}

#endif

int netc_eth_init_common(const struct device *dev)
{
const struct netc_eth_config *config = dev->config;
Expand All @@ -222,6 +249,51 @@ int netc_eth_init_common(const struct device *dev)
#endif

/* MSIX entry configuration */
#ifdef CONFIG_ETH_NXP_IMX_NETC_MSI_GIC
int ret;

if (config->msi_dev == NULL) {
LOG_ERR("MSI device is not configured");
return -ENODEV;
}
ret = its_setup_deviceid(config->msi_dev, config->msi_device_id, NETC_MSIX_ENTRY_NUM);
if (ret != 0) {
LOG_ERR("Failed to setup device ID for MSI: %d", ret);
return ret;
}
data->tx_intid = its_alloc_intid(config->msi_dev);
data->rx_intid = its_alloc_intid(config->msi_dev);

msg_addr = its_get_msi_addr(config->msi_dev);
msix_entry[NETC_TX_MSIX_ENTRY_IDX].control = kNETC_MsixIntrMaskBit;
msix_entry[NETC_TX_MSIX_ENTRY_IDX].msgAddr = msg_addr;
msix_entry[NETC_TX_MSIX_ENTRY_IDX].msgData = NETC_TX_MSIX_ENTRY_IDX;
ret = its_map_intid(config->msi_dev, config->msi_device_id, NETC_TX_MSIX_ENTRY_IDX,
data->tx_intid);
if (ret != 0) {
LOG_ERR("Failed to map TX MSI interrupt: %d", ret);
return ret;
}

msix_entry[NETC_RX_MSIX_ENTRY_IDX].control = kNETC_MsixIntrMaskBit;
msix_entry[NETC_RX_MSIX_ENTRY_IDX].msgAddr = msg_addr;
msix_entry[NETC_RX_MSIX_ENTRY_IDX].msgData = NETC_RX_MSIX_ENTRY_IDX;
ret = its_map_intid(config->msi_dev, config->msi_device_id, NETC_RX_MSIX_ENTRY_IDX,
data->rx_intid);
if (ret != 0) {
LOG_ERR("Failed to map RX MSI interrupt: %d", ret);
return ret;
}

if (!irq_is_enabled(data->tx_intid)) {
irq_connect_dynamic(data->tx_intid, 0, netc_tx_isr_handler, dev, 0);
irq_enable(data->tx_intid);
}
if (!irq_is_enabled(data->rx_intid)) {
irq_connect_dynamic(data->rx_intid, 0, netc_rx_isr_handler, dev, 0);
irq_enable(data->rx_intid);
}
#else
msg_addr = MSGINTR_GetIntrSelectAddr(NETC_MSGINTR, NETC_MSGINTR_CHANNEL);
msix_entry[NETC_TX_MSIX_ENTRY_IDX].control = kNETC_MsixIntrMaskBit;
msix_entry[NETC_TX_MSIX_ENTRY_IDX].msgAddr = msg_addr;
Expand All @@ -235,6 +307,7 @@ int netc_eth_init_common(const struct device *dev)
IRQ_CONNECT(NETC_MSGINTR_IRQ, 0, msgintr_isr, 0, 0);
irq_enable(NETC_MSGINTR_IRQ);
}
#endif

/* Endpoint configuration. */
EP_GetDefaultConfig(&ep_config);
Expand Down
Loading