Originally authored by Tim Pletcher <bugs@pletch.org>, with my additions
The EEE sysctl calls if_init() with an ifnet where iflib expects its context. On an E610-XT2, writing eee_state can therefore block indefinitely in sx_xlock() and corrupt if_broadcastaddr, causing broadcasts to use the wrong destination address. Cache the requested policy under the iflib context lock and request a reset through the admin task if the interface is still administratively up. Recheck the setting after copying in the sysctl value so concurrent writers do not act on stale state. Identical writes remain no-ops. Replay EEE after hardware reset and PHY power-up, before enabling queues. Log EEE setup failures and retain the requested policy for subsequent initialization. When the interface is administratively down, update the PHY directly under the context lock instead of waiting for the next initialization. The physical link can stay active while the host interface is down, for example when it is shared with a BMC. Replay the policy when the interface stops while administratively down, which also covers a request whose queued reset lost a race with the stop, and on resume if the interface remains down. Requests made while suspended take effect on resume. Do not touch the PHY from this path while suspended, during detach or shutdown, in firmware recovery mode, or while an overtemp shutdown is pending. The setting selects which speeds advertise EEE. On E610, no longer reject an enable request based on the current link speed; that test also refused the request whenever there was no link. The existing link-up message still reports a negotiated speed without EEE support. On E610, skip Set PHY Config when the active EEE mask already matches, avoiding unnecessary link restarts during unrelated initialization. Preserve the active link-enable state instead of forcing the link on, so an EEE update on a down interface cannot re-enable a link disabled by the Link Default Override policy. Allow bounded retries of Set PHY Config only on an explicit firmware busy response, including when the preceding PHY power-up is still completing. Convert the firmware completion status to host order when recording it, so that the busy test also matches on big-endian systems. Take the context lock in the advertise_speed sysctl. It was the last PHY configuration path outside the lock, and on E610 both it and the EEE update rewrite the complete PHY configuration, so a concurrent change could restore the other's stale settings. Document the requested-setting readback, how changes are applied while up, down, and suspended, retry behavior, and recovery-mode restrictions. PR: 300670 MFC after: 1 week Sponsored by: BBOX.io Co-authored-by: Kevin Bowling <kbowling@FreeBSD.org>