Actually I forgot that mii_media is setup when the miibus is attached (sometime after iflib_device_register). So my comments shouldn't apply. iflib_media_change and iflib_media_status aren't exposed though.

As is, the patch works.
I would still suggest exposing the iflib_media_* because init_locked is unavailable in the case of reset and I think the locks in the wrapper are useful?

Call iflib_init. You don't need the iflib lock held across your PHY routines - the wrapper you see here is so that normal drivers don't have to maintain their own locks. Any dedicated PHY driver is going to already be using its own locks. Exposing these would only further complicate the API with no benefit.

As is, the patch works.
I would still suggest exposing the iflib_media_* because init_locked is unavailable in the case of reset and I think the locks in the wrapper are useful?

Call iflib_init. You don't need the iflib lock held across your PHY routines - the wrapper you see here is so that normal drivers don't have to maintain their own locks. Any dedicated PHY driver is going to already be using its own locks. Exposing these would only further complicate the API with no benefit.

Your driver may not need to have the queues reset, but on most hardware where the PHY and MAC are managed together it avoids issues. In general, if the overhead of reset is an issue you're calling reset far far too often.

For more info on this bug, it occurs because all iflib drivers atm have iflib_get_media in IFDI_ATTACH_PRE. I don't think any of them actually use the media until later so you can either move the calls down into IFDI_ATTACH_POST or initialize the pointer and media before IFDI_ATTACH_PRE.

Updated patch works for me in the non-miibus (i.e., existing) case, tested with igb on Ampere eMAG. I have not yet updated Gerald's D20079 (to set the flag) or retested, but I'd be happy for this to go into HEAD now.