@@ -4121,12 +4121,57 @@ static int mlx5e_init_nic_tx(struct mlx5e_priv *priv)
41214121 return 0 ;
41224122}
41234123
4124+ static void mlx5e_register_vport_rep (struct mlx5_core_dev * mdev )
4125+ {
4126+ struct mlx5_eswitch * esw = mdev -> priv .eswitch ;
4127+ int total_vfs = MLX5_TOTAL_VPORTS (mdev );
4128+ int vport ;
4129+ u8 mac [ETH_ALEN ];
4130+
4131+ if (!MLX5_CAP_GEN (mdev , vport_group_manager ))
4132+ return ;
4133+
4134+ mlx5_query_nic_vport_mac_address (mdev , 0 , mac );
4135+
4136+ for (vport = 1 ; vport < total_vfs ; vport ++ ) {
4137+ struct mlx5_eswitch_rep rep ;
4138+
4139+ rep .load = mlx5e_vport_rep_load ;
4140+ rep .unload = mlx5e_vport_rep_unload ;
4141+ rep .vport = vport ;
4142+ ether_addr_copy (rep .hw_id , mac );
4143+ mlx5_eswitch_register_vport_rep (esw , vport , & rep );
4144+ }
4145+ }
4146+
4147+ static void mlx5e_unregister_vport_rep (struct mlx5_core_dev * mdev )
4148+ {
4149+ struct mlx5_eswitch * esw = mdev -> priv .eswitch ;
4150+ int total_vfs = MLX5_TOTAL_VPORTS (mdev );
4151+ int vport ;
4152+
4153+ if (!MLX5_CAP_GEN (mdev , vport_group_manager ))
4154+ return ;
4155+
4156+ for (vport = 1 ; vport < total_vfs ; vport ++ )
4157+ mlx5_eswitch_unregister_vport_rep (esw , vport );
4158+ }
4159+
41244160static void mlx5e_nic_enable (struct mlx5e_priv * priv )
41254161{
41264162 struct net_device * netdev = priv -> netdev ;
41274163 struct mlx5_core_dev * mdev = priv -> mdev ;
41284164 struct mlx5_eswitch * esw = mdev -> priv .eswitch ;
41294165 struct mlx5_eswitch_rep rep ;
4166+ u16 max_mtu ;
4167+
4168+ mlx5e_init_l2_addr (priv );
4169+
4170+ /* MTU range: 68 - hw-specific max */
4171+ netdev -> min_mtu = ETH_MIN_MTU ;
4172+ mlx5_query_port_max_mtu (priv -> mdev , & max_mtu , 1 );
4173+ netdev -> max_mtu = MLX5E_HW2SW_MTU (max_mtu );
4174+ mlx5e_set_dev_port_mtu (priv );
41304175
41314176 mlx5_lag_add (mdev , netdev );
41324177
@@ -4141,6 +4186,8 @@ static void mlx5e_nic_enable(struct mlx5e_priv *priv)
41414186 mlx5_eswitch_register_vport_rep (esw , 0 , & rep );
41424187 }
41434188
4189+ mlx5e_register_vport_rep (mdev );
4190+
41444191 if (netdev -> reg_state != NETREG_REGISTERED )
41454192 return ;
41464193
@@ -4152,14 +4199,27 @@ static void mlx5e_nic_enable(struct mlx5e_priv *priv)
41524199 }
41534200
41544201 queue_work (priv -> wq , & priv -> set_rx_mode_work );
4202+
4203+ rtnl_lock ();
4204+ if (netif_running (netdev ))
4205+ mlx5e_open (netdev );
4206+ netif_device_attach (netdev );
4207+ rtnl_unlock ();
41554208}
41564209
41574210static void mlx5e_nic_disable (struct mlx5e_priv * priv )
41584211{
41594212 struct mlx5_core_dev * mdev = priv -> mdev ;
41604213 struct mlx5_eswitch * esw = mdev -> priv .eswitch ;
41614214
4215+ rtnl_lock ();
4216+ if (netif_running (priv -> netdev ))
4217+ mlx5e_close (priv -> netdev );
4218+ netif_device_detach (priv -> netdev );
4219+ rtnl_unlock ();
4220+
41624221 queue_work (priv -> wq , & priv -> set_rx_mode_work );
4222+ mlx5e_unregister_vport_rep (mdev );
41634223 if (MLX5_CAP_GEN (mdev , vport_group_manager ))
41644224 mlx5_eswitch_unregister_vport_rep (esw , 0 );
41654225 mlx5e_disable_async_events (priv );
@@ -4180,6 +4240,8 @@ static const struct mlx5e_profile mlx5e_nic_profile = {
41804240 .max_tc = MLX5E_MAX_NUM_TC ,
41814241};
41824242
4243+ /* mlx5e generic netdev management API (move to en_common.c) */
4244+
41834245struct net_device * mlx5e_create_netdev (struct mlx5_core_dev * mdev ,
41844246 const struct mlx5e_profile * profile ,
41854247 void * ppriv )
@@ -4219,14 +4281,12 @@ struct net_device *mlx5e_create_netdev(struct mlx5_core_dev *mdev,
42194281 return NULL ;
42204282}
42214283
4222- int mlx5e_attach_netdev (struct mlx5_core_dev * mdev , struct net_device * netdev )
4284+ int mlx5e_attach_netdev (struct mlx5e_priv * priv )
42234285{
4286+ struct mlx5_core_dev * mdev = priv -> mdev ;
42244287 const struct mlx5e_profile * profile ;
4225- struct mlx5e_priv * priv ;
4226- u16 max_mtu ;
42274288 int err ;
42284289
4229- priv = netdev_priv (netdev );
42304290 profile = priv -> profile ;
42314291 clear_bit (MLX5E_STATE_DESTROYING , & priv -> state );
42324292
@@ -4246,24 +4306,9 @@ int mlx5e_attach_netdev(struct mlx5_core_dev *mdev, struct net_device *netdev)
42464306
42474307 mlx5e_create_q_counter (priv );
42484308
4249- mlx5e_init_l2_addr (priv );
4250-
4251- /* MTU range: 68 - hw-specific max */
4252- netdev -> min_mtu = ETH_MIN_MTU ;
4253- mlx5_query_port_max_mtu (priv -> mdev , & max_mtu , 1 );
4254- netdev -> max_mtu = MLX5E_HW2SW_MTU (max_mtu );
4255-
4256- mlx5e_set_dev_port_mtu (priv );
4257-
42584309 if (profile -> enable )
42594310 profile -> enable (priv );
42604311
4261- rtnl_lock ();
4262- if (netif_running (netdev ))
4263- mlx5e_open (netdev );
4264- netif_device_attach (netdev );
4265- rtnl_unlock ();
4266-
42674312 return 0 ;
42684313
42694314err_close_drop_rq :
@@ -4276,55 +4321,12 @@ int mlx5e_attach_netdev(struct mlx5_core_dev *mdev, struct net_device *netdev)
42764321 return err ;
42774322}
42784323
4279- static void mlx5e_register_vport_rep (struct mlx5_core_dev * mdev )
4280- {
4281- struct mlx5_eswitch * esw = mdev -> priv .eswitch ;
4282- int total_vfs = MLX5_TOTAL_VPORTS (mdev );
4283- int vport ;
4284- u8 mac [ETH_ALEN ];
4285-
4286- if (!MLX5_CAP_GEN (mdev , vport_group_manager ))
4287- return ;
4288-
4289- mlx5_query_nic_vport_mac_address (mdev , 0 , mac );
4290-
4291- for (vport = 1 ; vport < total_vfs ; vport ++ ) {
4292- struct mlx5_eswitch_rep rep ;
4293-
4294- rep .load = mlx5e_vport_rep_load ;
4295- rep .unload = mlx5e_vport_rep_unload ;
4296- rep .vport = vport ;
4297- ether_addr_copy (rep .hw_id , mac );
4298- mlx5_eswitch_register_vport_rep (esw , vport , & rep );
4299- }
4300- }
4301-
4302- static void mlx5e_unregister_vport_rep (struct mlx5_core_dev * mdev )
4303- {
4304- struct mlx5_eswitch * esw = mdev -> priv .eswitch ;
4305- int total_vfs = MLX5_TOTAL_VPORTS (mdev );
4306- int vport ;
4307-
4308- if (!MLX5_CAP_GEN (mdev , vport_group_manager ))
4309- return ;
4310-
4311- for (vport = 1 ; vport < total_vfs ; vport ++ )
4312- mlx5_eswitch_unregister_vport_rep (esw , vport );
4313- }
4314-
4315- void mlx5e_detach_netdev (struct mlx5_core_dev * mdev , struct net_device * netdev )
4324+ void mlx5e_detach_netdev (struct mlx5e_priv * priv )
43164325{
4317- struct mlx5e_priv * priv = netdev_priv (netdev );
43184326 const struct mlx5e_profile * profile = priv -> profile ;
43194327
43204328 set_bit (MLX5E_STATE_DESTROYING , & priv -> state );
43214329
4322- rtnl_lock ();
4323- if (netif_running (netdev ))
4324- mlx5e_close (netdev );
4325- netif_device_detach (netdev );
4326- rtnl_unlock ();
4327-
43284330 if (profile -> disable )
43294331 profile -> disable (priv );
43304332 flush_workqueue (priv -> wq );
@@ -4336,6 +4338,17 @@ void mlx5e_detach_netdev(struct mlx5_core_dev *mdev, struct net_device *netdev)
43364338 cancel_delayed_work_sync (& priv -> update_stats_work );
43374339}
43384340
4341+ void mlx5e_destroy_netdev (struct mlx5e_priv * priv )
4342+ {
4343+ const struct mlx5e_profile * profile = priv -> profile ;
4344+ struct net_device * netdev = priv -> netdev ;
4345+
4346+ destroy_workqueue (priv -> wq );
4347+ if (profile -> cleanup )
4348+ profile -> cleanup (priv );
4349+ free_netdev (netdev );
4350+ }
4351+
43394352/* mlx5e_attach and mlx5e_detach scope should be only creating/destroying
43404353 * hardware contexts and to connect it to the current netdev.
43414354 */
@@ -4352,13 +4365,12 @@ static int mlx5e_attach(struct mlx5_core_dev *mdev, void *vpriv)
43524365 if (err )
43534366 return err ;
43544367
4355- err = mlx5e_attach_netdev (mdev , netdev );
4368+ err = mlx5e_attach_netdev (priv );
43564369 if (err ) {
43574370 mlx5e_destroy_mdev_resources (mdev );
43584371 return err ;
43594372 }
43604373
4361- mlx5e_register_vport_rep (mdev );
43624374 return 0 ;
43634375}
43644376
@@ -4370,8 +4382,7 @@ static void mlx5e_detach(struct mlx5_core_dev *mdev, void *vpriv)
43704382 if (!netif_device_present (netdev ))
43714383 return ;
43724384
4373- mlx5e_unregister_vport_rep (mdev );
4374- mlx5e_detach_netdev (mdev , netdev );
4385+ mlx5e_detach_netdev (priv );
43754386 mlx5e_destroy_mdev_resources (mdev );
43764387}
43774388
@@ -4418,7 +4429,7 @@ static void *mlx5e_add(struct mlx5_core_dev *mdev)
44184429 mlx5e_detach (mdev , priv );
44194430
44204431err_destroy_netdev :
4421- mlx5e_destroy_netdev (mdev , priv );
4432+ mlx5e_destroy_netdev (priv );
44224433
44234434err_unregister_reps :
44244435 for (vport = 1 ; vport < total_vfs ; vport ++ )
@@ -4427,24 +4438,13 @@ static void *mlx5e_add(struct mlx5_core_dev *mdev)
44274438 return NULL ;
44284439}
44294440
4430- void mlx5e_destroy_netdev (struct mlx5_core_dev * mdev , struct mlx5e_priv * priv )
4431- {
4432- const struct mlx5e_profile * profile = priv -> profile ;
4433- struct net_device * netdev = priv -> netdev ;
4434-
4435- destroy_workqueue (priv -> wq );
4436- if (profile -> cleanup )
4437- profile -> cleanup (priv );
4438- free_netdev (netdev );
4439- }
4440-
44414441static void mlx5e_remove (struct mlx5_core_dev * mdev , void * vpriv )
44424442{
44434443 struct mlx5e_priv * priv = vpriv ;
44444444
44454445 unregister_netdev (priv -> netdev );
44464446 mlx5e_detach (mdev , vpriv );
4447- mlx5e_destroy_netdev (mdev , priv );
4447+ mlx5e_destroy_netdev (priv );
44484448}
44494449
44504450static void * mlx5e_get_netdev (void * vpriv )
0 commit comments