Skip to content

Conversation

@kevinior
Copy link
Contributor

@kevinior kevinior commented Apr 9, 2025

After API_V2 auto-negotiation support was added by #86621 setup_mac_filter() was called before HAL_ETH_Init(), which resulted in received multicast packets being discarded.

This removes that call to setup_mac_filter() when API_V2 in enabled and calls it from eth_init_api_v2() instead, after HAL_ETH_Init().

I've verified the problem and tested the fix on a Nucleo-H563ZI with a simple application that just starts up and makes an mDNS query (which depends on working multicast).

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

I experience the multicast problem on main on an stm32h573i_dk.

I have the intention to test this patch. Thank you for it.

return -EINVAL;
}

setup_mac_filter(heth);
Copy link

Choose a reason for hiding this comment

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

Will this not result in calling it twice on api v1 devices?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

eth_init_api_v2() is only called on API_V2 devices.

marwaiehm-st
marwaiehm-st previously approved these changes Apr 9, 2025
Copy link
Contributor

@marwaiehm-st marwaiehm-st left a comment

Choose a reason for hiding this comment

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

LGTM

@maass-hamburg
Copy link
Member

how about moving setup_mac_filter() into the iface init right before net_if_carrier_off(iface); for both apis?

@kevinior
Copy link
Contributor Author

kevinior commented Apr 9, 2025

@maass-hamburg

how about moving setup_mac_filter() into the iface init right before net_if_carrier_off(iface); for both apis?

Seems like it would make it a bit neater, yes.

@kevinior
Copy link
Contributor Author

kevinior commented Apr 9, 2025

@maass-hamburg

how about moving setup_mac_filter() into the iface init right before net_if_carrier_off(iface); for both apis?

Except eth_init_api_v2() is called from eth_iface_init(), which is an API function. eth_initialize() is called as the driver initialization function. So I'm not really clear if that's a safe change.

@ghost
Copy link

ghost commented Apr 9, 2025

how about moving setup_mac_filter() into the iface init right before net_if_carrier_off(iface); for both apis?

Except eth_init_api_v2() is called from eth_iface_init(), which is an API function. eth_initialize() is called as the driver initialization function. So I'm not really clear if that's a safe change.

I had the same thought. It is not clear to me, why HAL_ETH_Init is called from the API function for V2 and from the driver initialization for V1.

@ghost
Copy link

ghost commented Apr 9, 2025

how about moving setup_mac_filter() into the iface init right before net_if_carrier_off(iface); for both apis?

Except eth_init_api_v2() is called from eth_iface_init(), which is an API function. eth_initialize() is called as the driver initialization function. So I'm not really clear if that's a safe change.

I had the same thought. It is not clear to me, why HAL_ETH_Init is called from the API function for V2 and from the driver initialization for V1.

I traced the call to the api init.

Its here

net_if_init();

Calls go through net_if_init -> init_iface -> api->init(.... with prio POST_KERNEL at CONFIG_NET_INIT_PRIO.

@ghost
Copy link

ghost commented Apr 9, 2025

I tested the patch in this state including:

diff --git a/drivers/ethernet/eth_stm32_hal.c b/drivers/ethernet/eth_stm32_hal.c
index 1ec5bb1f05a..bec5dae50ac 100644
--- a/drivers/ethernet/eth_stm32_hal.c
+++ b/drivers/ethernet/eth_stm32_hal.c
@@ -1192,6 +1192,7 @@ static void eth_iface_init(struct net_if *iface)
        const struct device *dev;
        struct eth_stm32_hal_dev_data *dev_data;
        bool is_first_init = false;
+       ETH_HandleTypeDef *heth;

        __ASSERT_NO_MSG(iface != NULL);

@@ -1201,6 +1202,9 @@ static void eth_iface_init(struct net_if *iface)
        dev_data = dev->data;
        __ASSERT_NO_MSG(dev_data != NULL);

+       heth = &dev_data->heth;
+       __ASSERT_NO_MSG(heth != NULL);
+
        if (dev_data->iface == NULL) {
                dev_data->iface = iface;
                is_first_init = true;

Which solved the problem for me.

@ghost
Copy link

ghost commented Apr 9, 2025

I tested the patch in this state including:

FYI @kevinior : undefined ETH_HandleTypeDef *heth; is the cause of the test failure.

@kevinior
Copy link
Contributor Author

kevinior commented Apr 9, 2025

@clamattia

I tested the patch in this state including:

FYI @kevinior : undefined ETH_HandleTypeDef *heth; is the cause of the test failure.

Thanks, I'll fix it in the morning.

@kevinior
Copy link
Contributor Author

Rebased onto latest main to force a CI re-run, since this unrelated test had failed.

@ghost
Copy link

ghost commented Apr 11, 2025

Could we get another (relevant, mine unfortunately not :) ) review on this?
@marwaiehm-st maybe?

@pdgendt
Copy link
Contributor

pdgendt commented Apr 11, 2025

Could we get another (relevant, mine unfortunately not :) ) review on this?

It needs assignee approval.

Copy link
Contributor

@marwaiehm-st marwaiehm-st left a comment

Choose a reason for hiding this comment

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

You need to update the commit message
Otherwise LGTM

After API_V2 auto-negotiation support was added by zephyrproject-rtos#86621
setup_mac_filter() was called before HAL_ETH_Init(), which resulted in
received multicast packets being discarded.

This moves the call to setup_mac_filter() to eth_iface_init(), after
HAL_ETH_Init() for both API_V1 and API_V2.

I've verified the problem and tested the fix on a Nucleo-H563ZI with a
simple application that just starts up and makes an mDNS query (which
depends on working multicast).

Signed-off-by: Kevin ORourke <[email protected]>
@kevinior
Copy link
Contributor Author

@marwaiehm-st

You need to update the commit message Otherwise LGTM

Is the commit message OK now?

@kevinior kevinior requested a review from marwaiehm-st April 11, 2025 12:20
@kartben kartben merged commit f68eefa into zephyrproject-rtos:main Apr 11, 2025
25 checks passed
@kevinior kevinior deleted the fix_multicast branch April 14, 2025 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants