[...] > static int airoha_alloc_gdm_port(struct airoha_eth *eth, > struct device_node *np, int index) > { > @@ -2931,19 +2995,30 @@ static int airoha_alloc_gdm_port(struct airoha_eth *eth, > port->id = id; > eth->ports[p] = port; > > - err = airoha_metadata_dst_alloc(port); > - if (err) > - return err; > + return airoha_metadata_dst_alloc(port); > +} > > - err = register_netdev(dev); > - if (err) > - goto free_metadata_dst; > +static int airoha_register_gdm_ports(struct airoha_eth *eth) > +{ > + int i; > > - return 0; > + for (i = 0; i < ARRAY_SIZE(eth->ports); i++) { > + struct airoha_gdm_port *port = eth->ports[i]; > + int err; > > -free_metadata_dst: > - airoha_metadata_dst_free(port); > - return err; > + if (!port) > + continue; > + > + err = airoha_setup_phylink(port->dev); > + if (err) > + return err; > + > + err = register_netdev(port->dev); > + if (err) > + return err; > + } > + > + return 0; > } > > static int airoha_probe(struct platform_device *pdev) > @@ -3034,6 +3109,10 @@ static int airoha_probe(struct platform_device *pdev) > } > } > > + err = airoha_register_gdm_ports(eth); is there any specific reason we need to alloc all netdevs before registering the given phylink? I guess you can just do it in airoha_alloc_gdm_port(), right? Regards, Lorenzo > + if (err) > + goto error_napi_stop; > + > return 0; > > error_napi_stop: > @@ -3047,10 +3126,14 @@ static int airoha_probe(struct platform_device *pdev) > for (i = 0; i < ARRAY_SIZE(eth->ports); i++) { > struct airoha_gdm_port *port = eth->ports[i]; > > - if (port && port->dev->reg_state == NETREG_REGISTERED) { > + if (!port) > + continue; > + > + if (port->dev->reg_state == NETREG_REGISTERED) { > unregister_netdev(port->dev); > - airoha_metadata_dst_free(port); > + phylink_destroy(port->phylink); > } > + airoha_metadata_dst_free(port); > } > free_netdev(eth->napi_dev); > platform_set_drvdata(pdev, NULL); > @@ -3076,6 +3159,7 @@ static void airoha_remove(struct platform_device *pdev) > > airoha_dev_stop(port->dev); > unregister_netdev(port->dev); > + phylink_destroy(port->phylink); > airoha_metadata_dst_free(port); > } > free_netdev(eth->napi_dev); > diff --git a/drivers/net/ethernet/airoha/airoha_eth.h b/drivers/net/ethernet/airoha/airoha_eth.h > index eb27a4ff5198..c144c1ece23b 100644 > --- a/drivers/net/ethernet/airoha/airoha_eth.h > +++ b/drivers/net/ethernet/airoha/airoha_eth.h > @@ -531,6 +531,9 @@ struct airoha_gdm_port { > struct net_device *dev; > int id; > > + struct phylink *phylink; > + struct phylink_config phylink_config; > + > struct airoha_hw_stats stats; > > DECLARE_BITMAP(qos_sq_bmap, AIROHA_NUM_QOS_CHANNELS); > -- > 2.51.0 >