diff --git a/boards/arm/frdm_k64f/Kconfig.defconfig b/boards/arm/frdm_k64f/Kconfig.defconfig index 1e818223d281..380051685ce8 100644 --- a/boards/arm/frdm_k64f/Kconfig.defconfig +++ b/boards/arm/frdm_k64f/Kconfig.defconfig @@ -53,9 +53,6 @@ if NETWORKING config NET_L2_ETHERNET default y if !MODEM -config ETH_MCUX_0 - default y if NET_L2_ETHERNET - endif # NETWORKING endif # BOARD_FRDM_K64F diff --git a/boards/arm/hexiwear_k64/Kconfig.defconfig b/boards/arm/hexiwear_k64/Kconfig.defconfig index 2f7f7a9e34f6..9ed25781ac92 100644 --- a/boards/arm/hexiwear_k64/Kconfig.defconfig +++ b/boards/arm/hexiwear_k64/Kconfig.defconfig @@ -59,8 +59,4 @@ config SPI_2 endif # SPI -config ETH_MCUX_0 - default y - depends on NET_L2_ETHERNET - endif # BOARD_HEXIWEAR_K64 diff --git a/boards/arm/ip_k66f/Kconfig.defconfig b/boards/arm/ip_k66f/Kconfig.defconfig index c321ba128ebd..56845b8a1b09 100644 --- a/boards/arm/ip_k66f/Kconfig.defconfig +++ b/boards/arm/ip_k66f/Kconfig.defconfig @@ -28,9 +28,6 @@ config NET_L2_ETHERNET config ETH_MCUX default y if NET_L2_ETHERNET -config ETH_MCUX_0 - default y if ETH_MCUX - config ETH_MCUX_RMII_EXT_CLK default y if ETH_MCUX diff --git a/boards/arm/mimxrt1020_evk/Kconfig.defconfig b/boards/arm/mimxrt1020_evk/Kconfig.defconfig index a9f3508ad14e..d9d1a22380a8 100644 --- a/boards/arm/mimxrt1020_evk/Kconfig.defconfig +++ b/boards/arm/mimxrt1020_evk/Kconfig.defconfig @@ -21,9 +21,6 @@ if NETWORKING config NET_L2_ETHERNET default y -config ETH_MCUX_0 - default y if NET_L2_ETHERNET - endif # NETWORKING endif # BOARD_MIMXRT1020_EVK diff --git a/boards/arm/mimxrt1050_evk/Kconfig.defconfig b/boards/arm/mimxrt1050_evk/Kconfig.defconfig index 45c18289328d..b1e1a68f777e 100644 --- a/boards/arm/mimxrt1050_evk/Kconfig.defconfig +++ b/boards/arm/mimxrt1050_evk/Kconfig.defconfig @@ -48,9 +48,6 @@ if NETWORKING config NET_L2_ETHERNET default y -config ETH_MCUX_0 - default y if NET_L2_ETHERNET - endif # NETWORKING if LVGL diff --git a/boards/arm/mimxrt1060_evk/Kconfig.defconfig b/boards/arm/mimxrt1060_evk/Kconfig.defconfig index 3737f29e6a73..bc601a6d75f7 100644 --- a/boards/arm/mimxrt1060_evk/Kconfig.defconfig +++ b/boards/arm/mimxrt1060_evk/Kconfig.defconfig @@ -45,9 +45,6 @@ if NETWORKING config NET_L2_ETHERNET default y -config ETH_MCUX_0 - default y if NET_L2_ETHERNET - endif # NETWORKING if LVGL diff --git a/boards/arm/mimxrt1064_evk/Kconfig.defconfig b/boards/arm/mimxrt1064_evk/Kconfig.defconfig index 736879248942..0ebd742d6189 100644 --- a/boards/arm/mimxrt1064_evk/Kconfig.defconfig +++ b/boards/arm/mimxrt1064_evk/Kconfig.defconfig @@ -44,9 +44,6 @@ if NETWORKING config NET_L2_ETHERNET default y -config ETH_MCUX_0 - default y if NET_L2_ETHERNET - endif # NETWORKING if LVGL diff --git a/drivers/ethernet/Kconfig.mcux b/drivers/ethernet/Kconfig.mcux index 6ee91c30b346..d8b3a0713e16 100644 --- a/drivers/ethernet/Kconfig.mcux +++ b/drivers/ethernet/Kconfig.mcux @@ -62,17 +62,6 @@ config ETH_MCUX_TX_BUFFERS help Set the number of TX buffers provided to the MCUX driver. -config ETH_MCUX_0 - bool "MCUX Ethernet port 0" - help - Include port 0 driver - -config ETH_MCUX_1 - bool "MCUX Ethernet port 1" - depends on SOC_MIMXRT1062 || SOC_MIMXRT1064 - help - Include port 1 driver - config ETH_MCUX_HW_ACCELERATION bool "Enable hardware acceleration" help diff --git a/drivers/ethernet/eth_mcux.c b/drivers/ethernet/eth_mcux.c index 4a5917695a82..14c17068ca81 100644 --- a/drivers/ethernet/eth_mcux.c +++ b/drivers/ethernet/eth_mcux.c @@ -2,7 +2,7 @@ * * Copyright (c) 2016-2017 ARM Ltd * Copyright (c) 2016 Linaro Ltd - * Copyright (c) 2018 Intel Coporation + * Copyright (c) 2018 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ @@ -39,7 +39,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include "fsl_enet.h" #include "fsl_phy.h" -#ifdef CONFIG_NET_POWER_MANAGEMENT +#if defined(CONFIG_NET_POWER_MANAGEMENT) #include "fsl_clock.h" #include #endif @@ -71,11 +71,14 @@ enum eth_mcux_phy_state { eth_mcux_phy_state_closing }; -static void eth_mcux_init(const struct device *dev); +#if defined(CONFIG_NET_POWER_MANAGEMENT) +extern uint32_t ENET_GetInstance(ENET_Type * base); +static const clock_ip_name_t enet_clocks[] = ENET_CLOCKS; +#endif -static const char * -phy_state_name(enum eth_mcux_phy_state state) __attribute__((unused)); +static void eth_mcux_init(const struct device *dev); +#if defined(CONFIG_ETH_MCUX_PHY_EXTRA_DEBUG) static const char *phy_state_name(enum eth_mcux_phy_state state) { static const char * const name[] = { @@ -91,14 +94,15 @@ static const char *phy_state_name(enum eth_mcux_phy_state state) return name[state]; } +#endif static const char *eth_name(ENET_Type *base) { switch ((int)base) { - case (int)ENET: + case DT_INST_REG_ADDR(0): return DT_INST_LABEL(0); -#if defined(CONFIG_ETH_MCUX_1) - case (int)ENET2: +#if DT_NODE_HAS_STATUS(DT_DRV_INST(1), okay) + case DT_INST_REG_ADDR(1): return DT_INST_LABEL(1); #endif default: @@ -114,7 +118,7 @@ struct eth_context { * used for anything. */ struct net_if *iface; -#ifdef CONFIG_NET_POWER_MANAGEMENT +#if defined(CONFIG_NET_POWER_MANAGEMENT) const char *clock_name; clock_ip_name_t clock; const struct device *clock_dev; @@ -154,7 +158,7 @@ struct eth_context { uint8_t frame_buf[NET_ETH_MAX_FRAME_SIZE]; /* Max MTU + ethernet header */ }; -#ifdef CONFIG_HAS_MCUX_CACHE +#if defined(CONFIG_HAS_MCUX_CACHE) static __nocache enet_rx_bd_struct_t __aligned(ENET_BUFF_ALIGNMENT) rx_buffer_desc[CONFIG_ETH_MCUX_RX_BUFFERS]; @@ -174,15 +178,15 @@ static struct net_pkt *ts_tx_pkt[CONFIG_ETH_MCUX_TX_BUFFERS]; static int ts_tx_rd, ts_tx_wr; #endif -/* Use ENET_FRAME_MAX_VALNFRAMELEN for VLAN frame size - * Use ENET_FRAME_MAX_FRAMELEN for ethernet frame size +/* Use ENET_FRAME_MAX_VLANFRAMELEN for VLAN frame size + * Use ENET_FRAME_MAX_FRAMELEN for Ethernet frame size */ #if defined(CONFIG_NET_VLAN) -#if !defined(ENET_FRAME_MAX_VALNFRAMELEN) -#define ENET_FRAME_MAX_VALNFRAMELEN (ENET_FRAME_MAX_FRAMELEN + 4) +#if !defined(ENET_FRAME_MAX_VLANFRAMELEN) +#define ENET_FRAME_MAX_VLANFRAMELEN (ENET_FRAME_MAX_FRAMELEN + 4) #endif #define ETH_MCUX_BUFFER_SIZE \ - ROUND_UP(ENET_FRAME_MAX_VALNFRAMELEN, ENET_BUFF_ALIGNMENT) + ROUND_UP(ENET_FRAME_MAX_VLANFRAMELEN, ENET_BUFF_ALIGNMENT) #else #define ETH_MCUX_BUFFER_SIZE \ ROUND_UP(ENET_FRAME_MAX_FRAMELEN, ENET_BUFF_ALIGNMENT) @@ -194,7 +198,7 @@ rx_buffer[CONFIG_ETH_MCUX_RX_BUFFERS][ETH_MCUX_BUFFER_SIZE]; static uint8_t __aligned(ENET_BUFF_ALIGNMENT) tx_buffer[CONFIG_ETH_MCUX_TX_BUFFERS][ETH_MCUX_BUFFER_SIZE]; -#ifdef CONFIG_NET_POWER_MANAGEMENT +#if defined(CONFIG_NET_POWER_MANAGEMENT) static void eth_mcux_phy_enter_reset(struct eth_context *context); void eth_mcux_phy_stop(struct eth_context *context); @@ -316,21 +320,21 @@ static inline struct net_if *get_iface(struct eth_context *ctx, uint16_t vlan_ta static void eth_mcux_phy_enter_reset(struct eth_context *context) { /* Reset the PHY. */ -#ifndef CONFIG_ETH_MCUX_NO_PHY_SMI +#if !defined(CONFIG_ETH_MCUX_NO_PHY_SMI) ENET_StartSMIWrite(context->base, context->phy_addr, PHY_BASICCONTROL_REG, kENET_MiiWriteValidFrame, PHY_BCTL_RESET_MASK); #endif context->phy_state = eth_mcux_phy_state_reset; -#ifdef CONFIG_ETH_MCUX_NO_PHY_SMI +#if defined(CONFIG_ETH_MCUX_NO_PHY_SMI) k_work_submit(&context->phy_work); #endif } static void eth_mcux_phy_start(struct eth_context *context) { -#ifdef CONFIG_ETH_MCUX_PHY_EXTRA_DEBUG +#if defined(CONFIG_ETH_MCUX_PHY_EXTRA_DEBUG) LOG_DBG("%s phy_state=%s", eth_name(context->base), phy_state_name(context->phy_state)); #endif @@ -341,7 +345,7 @@ static void eth_mcux_phy_start(struct eth_context *context) case eth_mcux_phy_state_initial: ENET_ActiveRead(context->base); /* Reset the PHY. */ -#ifndef CONFIG_ETH_MCUX_NO_PHY_SMI +#if !defined(CONFIG_ETH_MCUX_NO_PHY_SMI) ENET_StartSMIWrite(context->base, context->phy_addr, PHY_BASICCONTROL_REG, kENET_MiiWriteValidFrame, @@ -354,7 +358,7 @@ static void eth_mcux_phy_start(struct eth_context *context) k_work_submit(&context->phy_work); break; #endif -#ifdef CONFIG_SOC_SERIES_IMX_RT +#if defined(CONFIG_SOC_SERIES_IMX_RT) context->phy_state = eth_mcux_phy_state_initial; #else context->phy_state = eth_mcux_phy_state_reset; @@ -375,7 +379,7 @@ static void eth_mcux_phy_start(struct eth_context *context) void eth_mcux_phy_stop(struct eth_context *context) { -#ifdef CONFIG_ETH_MCUX_PHY_EXTRA_DEBUG +#if defined(CONFIG_ETH_MCUX_PHY_EXTRA_DEBUG) LOG_DBG("%s phy_state=%s", eth_name(context->base), phy_state_name(context->phy_state)); #endif @@ -411,20 +415,20 @@ static void eth_mcux_phy_event(struct eth_context *context) uint32_t status; #endif bool link_up; -#ifdef CONFIG_SOC_SERIES_IMX_RT +#if defined(CONFIG_SOC_SERIES_IMX_RT) status_t res; uint32_t ctrl2; #endif phy_duplex_t phy_duplex = kPHY_FullDuplex; phy_speed_t phy_speed = kPHY_Speed100M; -#ifdef CONFIG_ETH_MCUX_PHY_EXTRA_DEBUG +#if defined(CONFIG_ETH_MCUX_PHY_EXTRA_DEBUG) LOG_DBG("%s phy_state=%s", eth_name(context->base), phy_state_name(context->phy_state)); #endif switch (context->phy_state) { case eth_mcux_phy_state_initial: -#ifdef CONFIG_SOC_SERIES_IMX_RT +#if defined(CONFIG_SOC_SERIES_IMX_RT) ENET_DisableInterrupts(context->base, ENET_EIR_MII_MASK); res = PHY_Read(context->base, context->phy_addr, PHY_CONTROL2_REG, &ctrl2); @@ -441,7 +445,7 @@ static void eth_mcux_phy_event(struct eth_context *context) } context->phy_state = eth_mcux_phy_state_reset; #endif -#ifdef CONFIG_ETH_MCUX_NO_PHY_SMI +#if defined(CONFIG_ETH_MCUX_NO_PHY_SMI) /* * When the iface is available proceed with the eth link setup, * otherwise reschedule the eth_mcux_phy_event and check after @@ -464,7 +468,7 @@ static void eth_mcux_phy_event(struct eth_context *context) break; case eth_mcux_phy_state_reset: /* Setup PHY autonegotiation. */ -#ifndef CONFIG_ETH_MCUX_NO_PHY_SMI +#if !defined(CONFIG_ETH_MCUX_NO_PHY_SMI) ENET_StartSMIWrite(context->base, context->phy_addr, PHY_AUTONEG_ADVERTISE_REG, kENET_MiiWriteValidFrame, @@ -474,12 +478,12 @@ static void eth_mcux_phy_event(struct eth_context *context) PHY_10BASETX_HALFDUPLEX_MASK | 0x1U)); #endif context->phy_state = eth_mcux_phy_state_autoneg; -#ifdef CONFIG_ETH_MCUX_NO_PHY_SMI +#if defined(CONFIG_ETH_MCUX_NO_PHY_SMI) k_work_submit(&context->phy_work); #endif break; case eth_mcux_phy_state_autoneg: -#ifndef CONFIG_ETH_MCUX_NO_PHY_SMI +#if !defined(CONFIG_ETH_MCUX_NO_PHY_SMI) /* Setup PHY autonegotiation. */ ENET_StartSMIWrite(context->base, context->phy_addr, PHY_BASICCONTROL_REG, @@ -488,20 +492,20 @@ static void eth_mcux_phy_event(struct eth_context *context) PHY_BCTL_RESTART_AUTONEG_MASK)); #endif context->phy_state = eth_mcux_phy_state_restart; -#ifdef CONFIG_ETH_MCUX_NO_PHY_SMI +#if defined(CONFIG_ETH_MCUX_NO_PHY_SMI) k_work_submit(&context->phy_work); #endif break; case eth_mcux_phy_state_wait: case eth_mcux_phy_state_restart: /* Start reading the PHY basic status. */ -#ifndef CONFIG_ETH_MCUX_NO_PHY_SMI +#if !defined(CONFIG_ETH_MCUX_NO_PHY_SMI) ENET_StartSMIRead(context->base, context->phy_addr, PHY_BASICSTATUS_REG, kENET_MiiReadValidFrame); #endif context->phy_state = eth_mcux_phy_state_read_status; -#ifdef CONFIG_ETH_MCUX_NO_PHY_SMI +#if defined(CONFIG_ETH_MCUX_NO_PHY_SMI) k_work_submit(&context->phy_work); #endif break; @@ -515,7 +519,7 @@ static void eth_mcux_phy_event(struct eth_context *context) #endif if (link_up && !context->link_up) { /* Start reading the PHY control register. */ -#ifndef CONFIG_ETH_MCUX_NO_PHY_SMI +#if !defined(CONFIG_ETH_MCUX_NO_PHY_SMI) ENET_StartSMIRead(context->base, context->phy_addr, PHY_CONTROL1_REG, kENET_MiiReadValidFrame); @@ -528,7 +532,7 @@ static void eth_mcux_phy_event(struct eth_context *context) net_eth_carrier_on(context->iface); k_msleep(USEC_PER_MSEC); } -#ifdef CONFIG_ETH_MCUX_NO_PHY_SMI +#if defined(CONFIG_ETH_MCUX_NO_PHY_SMI) k_work_submit(&context->phy_work); #endif } else if (!link_up && context->link_up) { @@ -594,7 +598,7 @@ static void eth_mcux_delayed_phy_work(struct k_work *item) static void eth_mcux_phy_setup(struct eth_context *context) { -#ifdef CONFIG_SOC_SERIES_IMX_RT +#if defined(CONFIG_SOC_SERIES_IMX_RT) status_t res; uint32_t oms_override; @@ -689,7 +693,7 @@ static bool eth_get_ptp_data(struct net_if *iface, struct net_pkt *pkt, ptpTsData->messageType = hdr->message_type; ptpTsData->sequenceId = ntohs(hdr->sequence_id); -#ifdef CONFIG_ETH_MCUX_PHY_EXTRA_DEBUG +#if defined(CONFIG_ETH_MCUX_PHY_EXTRA_DEBUG) LOG_DBG("PTP packet: ver %d type %d len %d seq %d", ptpTsData->version, ptpTsData->messageType, @@ -853,7 +857,7 @@ static void eth_rx(struct eth_context *context) #endif } } -#endif +#endif /* CONFIG_NET_VLAN */ #if defined(CONFIG_PTP_CLOCK_MCUX) if (eth_get_ptp_data(get_iface(context, vlan_tag), pkt, @@ -925,7 +929,7 @@ static inline void ts_register_tx_event(struct eth_context *context) ts_tx_rd = 0; } } -#endif +#endif /* CONFIG_PTP_CLOCK_MCUX */ static void eth_callback(ENET_Type *base, enet_handle_t *handle, enet_event_t event, void *param) @@ -962,44 +966,6 @@ static void eth_callback(ENET_Type *base, enet_handle_t *handle, } } -#if DT_INST_PROP(0, zephyr_random_mac_address) || \ - DT_INST_PROP(1, zephyr_random_mac_address) -static void generate_random_mac(uint8_t *mac_addr) -{ - gen_random_mac(mac_addr, FREESCALE_OUI_B0, - FREESCALE_OUI_B1, FREESCALE_OUI_B2); -} -#endif - -#if !DT_INST_NODE_HAS_PROP(0, local_mac_address) || \ - DT_NODE_HAS_STATUS(DT_DRV_INST(1), okay) && \ - !DT_INST_NODE_HAS_PROP(1, local_mac_address) -static void generate_eth0_unique_mac(uint8_t *mac_addr) -{ - /* Trivially "hash" up to 128 bits of MCU unique identifier */ -#ifdef CONFIG_SOC_SERIES_IMX_RT - uint32_t id = OCOTP->CFG1 ^ OCOTP->CFG2; -#endif -#ifdef CONFIG_SOC_SERIES_KINETIS_K6X - uint32_t id = SIM->UIDH ^ SIM->UIDMH ^ SIM->UIDML ^ SIM->UIDL; -#endif - - mac_addr[0] |= 0x02; /* force LAA bit */ - - mac_addr[3] = id >> 8; - mac_addr[4] = id >> 16; - mac_addr[5] = id >> 0; -} -#endif - -#if DT_NODE_HAS_STATUS(DT_DRV_INST(1), okay) && !DT_INST_NODE_HAS_PROP(1, local_mac_address) -static void generate_eth1_unique_mac(uint8_t *mac_addr) -{ - generate_eth0_unique_mac(mac_addr); - mac_addr[5]++; -} -#endif - static void eth_mcux_init(const struct device *dev) { struct eth_context *context = dev->data; @@ -1030,7 +996,7 @@ static void eth_mcux_init(const struct device *dev) ENET_GetDefaultConfig(&enet_config); enet_config.interrupt |= kENET_RxFrameInterrupt; enet_config.interrupt |= kENET_TxFrameInterrupt; -#ifndef CONFIG_ETH_MCUX_NO_PHY_SMI +#if !defined(CONFIG_ETH_MCUX_NO_PHY_SMI) enet_config.interrupt |= kENET_MiiInterrupt; #endif @@ -1058,7 +1024,6 @@ static void eth_mcux_init(const struct device *dev) context->mac_addr, sys_clock); - #if defined(CONFIG_PTP_CLOCK_MCUX) ENET_AddMulticastGroup(context->base, ptp_multicast); @@ -1079,7 +1044,7 @@ static void eth_mcux_init(const struct device *dev) ENET_AddMulticastGroup(context->base, mdns_multicast); #endif -#ifndef CONFIG_ETH_MCUX_NO_PHY_SMI +#if !defined(CONFIG_ETH_MCUX_NO_PHY_SMI) ENET_SetSMI(context->base, sys_clock, false); #endif @@ -1102,6 +1067,9 @@ static int eth_init(const struct device *dev) #endif #if defined(CONFIG_NET_POWER_MANAGEMENT) + const uint32_t inst = ENET_GetInstance(context->base); + + context->clock = enet_clocks[inst]; context->clock_dev = device_get_binding(context->clock_name); #endif @@ -1111,20 +1079,14 @@ static int eth_init(const struct device *dev) k_delayed_work_init(&context->delayed_phy_work, eth_mcux_delayed_phy_work); - - /* Initialize/override OUI which may not be correct in - * devicetree. - */ - context->mac_addr[0] = FREESCALE_OUI_B0; - context->mac_addr[1] = FREESCALE_OUI_B1; - context->mac_addr[2] = FREESCALE_OUI_B2; if (context->generate_mac) { context->generate_mac(context->mac_addr); } eth_mcux_init(dev); - LOG_DBG("MAC %02x:%02x:%02x:%02x:%02x:%02x", + LOG_DBG("%s MAC %02x:%02x:%02x:%02x:%02x:%02x", + dev->name, context->mac_addr[0], context->mac_addr[1], context->mac_addr[2], context->mac_addr[3], context->mac_addr[4], context->mac_addr[5]); @@ -1196,6 +1158,34 @@ static enum ethernet_hw_caps eth_mcux_get_capabilities(const struct device *dev) ETHERNET_LINK_100BASE_T; } +static int eth_mcux_set_config(const struct device *dev, + enum ethernet_config_type type, + const struct ethernet_config *config) +{ + struct eth_context *context = dev->data; + + switch (type) { + case ETHERNET_CONFIG_TYPE_MAC_ADDRESS: + memcpy(context->mac_addr, + config->mac_address.addr, + sizeof(context->mac_addr)); + ENET_SetMacAddr(context->base, context->mac_addr); + net_if_set_link_addr(context->iface, context->mac_addr, + sizeof(context->mac_addr), + NET_LINK_ETHERNET); + LOG_DBG("%s MAC set to %02x:%02x:%02x:%02x:%02x:%02x", + dev->name, + context->mac_addr[0], context->mac_addr[1], + context->mac_addr[2], context->mac_addr[3], + context->mac_addr[4], context->mac_addr[5]); + return 0; + default: + break; + } + + return -ENOTSUP; +} + #if defined(CONFIG_PTP_CLOCK_MCUX) static const struct device *eth_mcux_get_ptp_clock(const struct device *dev) { @@ -1211,6 +1201,7 @@ static const struct ethernet_api api_funcs = { .get_ptp_clock = eth_mcux_get_ptp_clock, #endif .get_capabilities = eth_mcux_get_capabilities, + .set_config = eth_mcux_set_config, .send = eth_tx, }; @@ -1223,7 +1214,7 @@ static void eth_mcux_ptp_isr(const struct device *dev) } #endif -#if DT_INST_IRQ_HAS_NAME(0, common) +#if DT_INST_IRQ_HAS_NAME(0, common) || DT_INST_IRQ_HAS_NAME(1, common) static void eth_mcux_dispacher_isr(const struct device *dev) { struct eth_context *context = dev->data; @@ -1245,7 +1236,7 @@ static void eth_mcux_dispacher_isr(const struct device *dev) } #endif -#if DT_INST_IRQ_HAS_NAME(0, rx) +#if DT_INST_IRQ_HAS_NAME(0, rx) || DT_INST_IRQ_HAS_NAME(1, rx) static void eth_mcux_rx_isr(const struct device *dev) { struct eth_context *context = dev->data; @@ -1254,7 +1245,7 @@ static void eth_mcux_rx_isr(const struct device *dev) } #endif -#if DT_INST_IRQ_HAS_NAME(0, tx) +#if DT_INST_IRQ_HAS_NAME(0, tx) || DT_INST_IRQ_HAS_NAME(1, tx) static void eth_mcux_tx_isr(const struct device *dev) { struct eth_context *context = dev->data; @@ -1263,7 +1254,7 @@ static void eth_mcux_tx_isr(const struct device *dev) } #endif -#if DT_INST_IRQ_HAS_NAME(0, err_misc) +#if DT_INST_IRQ_HAS_NAME(0, err_misc) || DT_INST_IRQ_HAS_NAME(1, err_misc) static void eth_mcux_error_isr(const struct device *dev) { struct eth_context *context = dev->data; @@ -1276,116 +1267,227 @@ static void eth_mcux_error_isr(const struct device *dev) } #endif -static void eth_0_config_func(void); +#if DT_NODE_HAS_STATUS(DT_DRV_INST(0), okay) -static struct eth_context eth_0_context = { - .base = ENET, +#if DT_INST_PROP(0, zephyr_random_mac_address) && \ + NODE_HAS_VALID_MAC_ADDR(DT_DRV_INST(0)) +#error Conflict between 'local-mac-address' and 'zephyr,random-mac-address' +#endif + +#if !NODE_HAS_VALID_MAC_ADDR(DT_DRV_INST(0)) +static void generate_eth0_mac(uint8_t *mac_addr) +{ +#if DT_INST_PROP(0, zephyr_random_mac_address) + gen_random_mac(mac_addr, + FREESCALE_OUI_B0, FREESCALE_OUI_B1, FREESCALE_OUI_B2); +#else + /* Generate_unique_mac */ + mac_addr[0] = FREESCALE_OUI_B0; + mac_addr[1] = FREESCALE_OUI_B1; + mac_addr[2] = FREESCALE_OUI_B2; + /* Trivially "hash" up to 128 bits of MCU unique identifier */ +#if defined(CONFIG_SOC_SERIES_IMX_RT) + uint32_t id = OCOTP->CFG1 ^ OCOTP->CFG2; +#elif defined(CONFIG_SOC_SERIES_KINETIS_K6X) + uint32_t id = SIM->UIDH ^ SIM->UIDMH ^ SIM->UIDML ^ SIM->UIDL; +#else +#error "Unsupported SOC" +#endif + mac_addr[0] |= 0x02; /* force LAA bit */ + + mac_addr[3] = id >> 8; + mac_addr[4] = id >> 16; + mac_addr[5] = id >> 0; + + mac_addr[5] += 0; +#endif /* zephyr_random_mac_address */ +} +#endif + +static void eth0_config_func(void); + +static struct eth_context eth0_context = { + .base = (ENET_Type *)DT_INST_REG_ADDR(0), #if defined(CONFIG_NET_POWER_MANAGEMENT) .clock_name = DT_INST_CLOCKS_LABEL(0), - .clock = kCLOCK_Enet0, #endif - .config_func = eth_0_config_func, + .config_func = eth0_config_func, .phy_addr = 0U, .phy_duplex = kPHY_FullDuplex, .phy_speed = kPHY_Speed100M, -#if DT_INST_PROP(0, zephyr_random_mac_address) - .generate_mac = generate_random_mac, -#endif #if NODE_HAS_VALID_MAC_ADDR(DT_DRV_INST(0)) .mac_addr = DT_INST_PROP(0, local_mac_address), .generate_mac = NULL, #else - .generate_mac = generate_eth0_unique_mac, + .generate_mac = generate_eth0_mac, #endif }; ETH_NET_DEVICE_INIT(eth_mcux_0, DT_INST_LABEL(0), eth_init, - ETH_MCUX_PM_FUNC, ð_0_context, NULL, + ETH_MCUX_PM_FUNC, ð0_context, NULL, CONFIG_ETH_INIT_PRIORITY, &api_funcs, NET_ETH_MTU); -static void eth_0_config_func(void) +static void eth0_config_func(void) { #if DT_INST_IRQ_HAS_NAME(0, rx) IRQ_CONNECT(DT_INST_IRQ_BY_NAME(0, rx, irq), DT_INST_IRQ_BY_NAME(0, rx, priority), - eth_mcux_rx_isr, DEVICE_GET(eth_mcux_0), 0); + eth_mcux_rx_isr, + DEVICE_GET(eth_mcux_0), + 0); irq_enable(DT_INST_IRQ_BY_NAME(0, rx, irq)); #endif #if DT_INST_IRQ_HAS_NAME(0, tx) IRQ_CONNECT(DT_INST_IRQ_BY_NAME(0, tx, irq), DT_INST_IRQ_BY_NAME(0, tx, priority), - eth_mcux_tx_isr, DEVICE_GET(eth_mcux_0), 0); + eth_mcux_tx_isr, + DEVICE_GET(eth_mcux_0), + 0); irq_enable(DT_INST_IRQ_BY_NAME(0, tx, irq)); #endif #if DT_INST_IRQ_HAS_NAME(0, err_misc) IRQ_CONNECT(DT_INST_IRQ_BY_NAME(0, err_misc, irq), DT_INST_IRQ_BY_NAME(0, err_misc, priority), - eth_mcux_error_isr, DEVICE_GET(eth_mcux_0), 0); + eth_mcux_error_isr, + DEVICE_GET(eth_mcux_0), + 0); irq_enable(DT_INST_IRQ_BY_NAME(0, err_misc, irq)); #endif #if DT_INST_IRQ_HAS_NAME(0, common) IRQ_CONNECT(DT_INST_IRQ_BY_NAME(0, common, irq), DT_INST_IRQ_BY_NAME(0, common, priority), - eth_mcux_dispacher_isr, DEVICE_GET(eth_mcux_0), 0); + eth_mcux_dispacher_isr, + DEVICE_GET(eth_mcux_0), + 0); irq_enable(DT_INST_IRQ_BY_NAME(0, common, irq)); #endif #if defined(CONFIG_PTP_CLOCK_MCUX) +#if DT_NODE_HAS_STATUS(PTP_INST_NODEID(0), okay) IRQ_CONNECT(DT_IRQ_BY_NAME(PTP_INST_NODEID(0), ieee1588_tmr, irq), DT_IRQ_BY_NAME(PTP_INST_NODEID(0), ieee1588_tmr, priority), - eth_mcux_ptp_isr, DEVICE_GET(eth_mcux_0), 0); + eth_mcux_ptp_isr, + DEVICE_GET(eth_mcux_0), + 0); irq_enable(DT_IRQ_BY_NAME(PTP_INST_NODEID(0), ieee1588_tmr, irq)); #endif +#endif } +#endif /* DT_NODE_HAS_STATUS(DT_DRV_INST(0), okay) */ + +#if DT_NODE_HAS_STATUS(DT_DRV_INST(1), okay) -#if defined(CONFIG_ETH_MCUX_1) -static void eth_1_config_func(void); +#if DT_INST_PROP(1, zephyr_random_mac_address) && \ + NODE_HAS_VALID_MAC_ADDR(DT_DRV_INST(1)) +#error Conflict between 'local-mac-address' and 'zephyr,random-mac-address' +#endif -static struct eth_context eth_1_context = { - .base = ENET2, +#if !NODE_HAS_VALID_MAC_ADDR(DT_DRV_INST(1)) +static void generate_eth1_mac(uint8_t *mac_addr) +{ +#if DT_INST_PROP(1, zephyr_random_mac_address) + gen_random_mac(mac_addr, + FREESCALE_OUI_B0, FREESCALE_OUI_B1, FREESCALE_OUI_B2); +#else + /* Generate_unique_mac */ + mac_addr[0] = FREESCALE_OUI_B0; + mac_addr[1] = FREESCALE_OUI_B1; + mac_addr[2] = FREESCALE_OUI_B2; + /* Trivially "hash" up to 128 bits of MCU unique identifier */ +#if defined(CONFIG_SOC_SERIES_IMX_RT) + uint32_t id = OCOTP->CFG1 ^ OCOTP->CFG2; +#elif defined(CONFIG_SOC_SERIES_KINETIS_K6X) + uint32_t id = SIM->UIDH ^ SIM->UIDMH ^ SIM->UIDML ^ SIM->UIDL; +#else +#error "Unsupported SOC" +#endif + mac_addr[0] |= 0x02; /* force LAA bit */ + + mac_addr[3] = id >> 8; + mac_addr[4] = id >> 16; + mac_addr[5] = id >> 0; + + mac_addr[5] += 1; +#endif /* zephyr_random_mac_address */ +} +#endif + +static void eth1_config_func(void); + +static struct eth_context eth1_context = { + .base = (ENET_Type *)DT_INST_REG_ADDR(1), #if defined(CONFIG_NET_POWER_MANAGEMENT) .clock_name = DT_INST_CLOCKS_LABEL(1), - .clock = kCLOCK_Enet2, #endif - .config_func = eth_1_config_func, + .config_func = eth1_config_func, .phy_addr = 0U, .phy_duplex = kPHY_FullDuplex, .phy_speed = kPHY_Speed100M, -#if DT_INST_PROP(1, zephyr_random_mac_address) - .generate_mac = generate_random_mac, -#endif #if NODE_HAS_VALID_MAC_ADDR(DT_DRV_INST(1)) .mac_addr = DT_INST_PROP(1, local_mac_address), .generate_mac = NULL, #else - .generate_mac = generate_eth1_unique_mac, + .generate_mac = generate_eth1_mac, #endif }; ETH_NET_DEVICE_INIT(eth_mcux_1, DT_INST_LABEL(1), eth_init, - ETH_MCUX_PM_FUNC, ð_1_context, NULL, + ETH_MCUX_PM_FUNC, ð1_context, NULL, CONFIG_ETH_INIT_PRIORITY, &api_funcs, NET_ETH_MTU); -static void eth_1_config_func(void) +static void eth1_config_func(void) { +#if DT_INST_IRQ_HAS_NAME(1, rx) + IRQ_CONNECT(DT_INST_IRQ_BY_NAME(1, rx, irq), + DT_INST_IRQ_BY_NAME(1, rx, priority), + eth_mcux_rx_isr, + DEVICE_GET(eth_mcux_1), + 0); + irq_enable(DT_INST_IRQ_BY_NAME(1, rx, irq)); +#endif + +#if DT_INST_IRQ_HAS_NAME(1, tx) + IRQ_CONNECT(DT_INST_IRQ_BY_NAME(1, tx, irq), + DT_INST_IRQ_BY_NAME(1, tx, priority), + eth_mcux_tx_isr, + DEVICE_GET(eth_mcux_1), + 0); + irq_enable(DT_INST_IRQ_BY_NAME(1, tx, irq)); +#endif + +#if DT_INST_IRQ_HAS_NAME(1, err_misc) + IRQ_CONNECT(DT_INST_IRQ_BY_NAME(1, err_misc, irq), + DT_INST_IRQ_BY_NAME(1, err_misc, priority), + eth_mcux_error_isr, + DEVICE_GET(eth_mcux_1), + 0); + irq_enable(DT_INST_IRQ_BY_NAME(1, err_misc, irq)); +#endif + #if DT_INST_IRQ_HAS_NAME(1, common) IRQ_CONNECT(DT_INST_IRQ_BY_NAME(1, common, irq), DT_INST_IRQ_BY_NAME(1, common, priority), - eth_mcux_dispacher_isr, DEVICE_GET(eth_mcux_1), 0); - irq_enable(DT_INST_IRQ_BY_NAME(1, common, irq)) + eth_mcux_dispacher_isr, + DEVICE_GET(eth_mcux_1), + 0); + irq_enable(DT_INST_IRQ_BY_NAME(1, common, irq)); #endif #if defined(CONFIG_PTP_CLOCK_MCUX) +#if DT_NODE_HAS_STATUS(PTP_INST_NODEID(1), okay) IRQ_CONNECT(DT_IRQ_BY_NAME(PTP_INST_NODEID(1), ieee1588_tmr, irq), DT_IRQ_BY_NAME(PTP_INST_NODEID(1), ieee1588_tmr, priority), - eth_mcux_ptp_isr, DEVICE_GET(eth_mcux_1), 0); + eth_mcux_ptp_isr, + DEVICE_GET(eth_mcux_1), + 0); irq_enable(DT_IRQ_BY_NAME(PTP_INST_NODEID(1), ieee1588_tmr, irq)); #endif +#endif } -#endif /* CONFIG_ETH_MCUX_1 */ +#endif /* DT_NODE_HAS_STATUS(DT_DRV_INST(1), okay) */ #if defined(CONFIG_PTP_CLOCK_MCUX) struct ptp_context { @@ -1494,7 +1596,6 @@ static int ptp_clock_mcux_rate_adjust(const struct device *dev, float ratio) mul = val; } - ENET_Ptp1588AdjustTimer(context->base, corr, mul); return 0; diff --git a/samples/net/openthread/ncp/overlay-tri-n4m-br.conf b/samples/net/openthread/ncp/overlay-tri-n4m-br.conf index e762a0c088a5..bf91033a3276 100644 --- a/samples/net/openthread/ncp/overlay-tri-n4m-br.conf +++ b/samples/net/openthread/ncp/overlay-tri-n4m-br.conf @@ -26,7 +26,7 @@ CONFIG_USB_REQUEST_BUFFER_SIZE=2048 # disable ethernet on K64 CONFIG_NET_L2_ETHERNET=n -CONFIG_ETH_MCUX_0=n +CONFIG_ETH_MCUX=n CONFIG_IEEE802154_RF2XX=y CONFIG_NET_CONFIG_IEEE802154_DEV_NAME="RF2XX_0"