@@ -4121,12 +4121,57 @@ static int mlx5e_init_nic_tx(struct mlx5e_priv *priv)
4121
4121
return 0 ;
4122
4122
}
4123
4123
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
+
4124
4160
static void mlx5e_nic_enable (struct mlx5e_priv * priv )
4125
4161
{
4126
4162
struct net_device * netdev = priv -> netdev ;
4127
4163
struct mlx5_core_dev * mdev = priv -> mdev ;
4128
4164
struct mlx5_eswitch * esw = mdev -> priv .eswitch ;
4129
4165
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 );
4130
4175
4131
4176
mlx5_lag_add (mdev , netdev );
4132
4177
@@ -4141,6 +4186,8 @@ static void mlx5e_nic_enable(struct mlx5e_priv *priv)
4141
4186
mlx5_eswitch_register_vport_rep (esw , 0 , & rep );
4142
4187
}
4143
4188
4189
+ mlx5e_register_vport_rep (mdev );
4190
+
4144
4191
if (netdev -> reg_state != NETREG_REGISTERED )
4145
4192
return ;
4146
4193
@@ -4152,14 +4199,27 @@ static void mlx5e_nic_enable(struct mlx5e_priv *priv)
4152
4199
}
4153
4200
4154
4201
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 ();
4155
4208
}
4156
4209
4157
4210
static void mlx5e_nic_disable (struct mlx5e_priv * priv )
4158
4211
{
4159
4212
struct mlx5_core_dev * mdev = priv -> mdev ;
4160
4213
struct mlx5_eswitch * esw = mdev -> priv .eswitch ;
4161
4214
4215
+ rtnl_lock ();
4216
+ if (netif_running (priv -> netdev ))
4217
+ mlx5e_close (priv -> netdev );
4218
+ netif_device_detach (priv -> netdev );
4219
+ rtnl_unlock ();
4220
+
4162
4221
queue_work (priv -> wq , & priv -> set_rx_mode_work );
4222
+ mlx5e_unregister_vport_rep (mdev );
4163
4223
if (MLX5_CAP_GEN (mdev , vport_group_manager ))
4164
4224
mlx5_eswitch_unregister_vport_rep (esw , 0 );
4165
4225
mlx5e_disable_async_events (priv );
@@ -4180,6 +4240,8 @@ static const struct mlx5e_profile mlx5e_nic_profile = {
4180
4240
.max_tc = MLX5E_MAX_NUM_TC ,
4181
4241
};
4182
4242
4243
+ /* mlx5e generic netdev management API (move to en_common.c) */
4244
+
4183
4245
struct net_device * mlx5e_create_netdev (struct mlx5_core_dev * mdev ,
4184
4246
const struct mlx5e_profile * profile ,
4185
4247
void * ppriv )
@@ -4219,14 +4281,12 @@ struct net_device *mlx5e_create_netdev(struct mlx5_core_dev *mdev,
4219
4281
return NULL ;
4220
4282
}
4221
4283
4222
- int mlx5e_attach_netdev (struct mlx5_core_dev * mdev , struct net_device * netdev )
4284
+ int mlx5e_attach_netdev (struct mlx5e_priv * priv )
4223
4285
{
4286
+ struct mlx5_core_dev * mdev = priv -> mdev ;
4224
4287
const struct mlx5e_profile * profile ;
4225
- struct mlx5e_priv * priv ;
4226
- u16 max_mtu ;
4227
4288
int err ;
4228
4289
4229
- priv = netdev_priv (netdev );
4230
4290
profile = priv -> profile ;
4231
4291
clear_bit (MLX5E_STATE_DESTROYING , & priv -> state );
4232
4292
@@ -4246,24 +4306,9 @@ int mlx5e_attach_netdev(struct mlx5_core_dev *mdev, struct net_device *netdev)
4246
4306
4247
4307
mlx5e_create_q_counter (priv );
4248
4308
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
-
4258
4309
if (profile -> enable )
4259
4310
profile -> enable (priv );
4260
4311
4261
- rtnl_lock ();
4262
- if (netif_running (netdev ))
4263
- mlx5e_open (netdev );
4264
- netif_device_attach (netdev );
4265
- rtnl_unlock ();
4266
-
4267
4312
return 0 ;
4268
4313
4269
4314
err_close_drop_rq :
@@ -4276,55 +4321,12 @@ int mlx5e_attach_netdev(struct mlx5_core_dev *mdev, struct net_device *netdev)
4276
4321
return err ;
4277
4322
}
4278
4323
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 )
4316
4325
{
4317
- struct mlx5e_priv * priv = netdev_priv (netdev );
4318
4326
const struct mlx5e_profile * profile = priv -> profile ;
4319
4327
4320
4328
set_bit (MLX5E_STATE_DESTROYING , & priv -> state );
4321
4329
4322
- rtnl_lock ();
4323
- if (netif_running (netdev ))
4324
- mlx5e_close (netdev );
4325
- netif_device_detach (netdev );
4326
- rtnl_unlock ();
4327
-
4328
4330
if (profile -> disable )
4329
4331
profile -> disable (priv );
4330
4332
flush_workqueue (priv -> wq );
@@ -4336,6 +4338,17 @@ void mlx5e_detach_netdev(struct mlx5_core_dev *mdev, struct net_device *netdev)
4336
4338
cancel_delayed_work_sync (& priv -> update_stats_work );
4337
4339
}
4338
4340
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
+
4339
4352
/* mlx5e_attach and mlx5e_detach scope should be only creating/destroying
4340
4353
* hardware contexts and to connect it to the current netdev.
4341
4354
*/
@@ -4352,13 +4365,12 @@ static int mlx5e_attach(struct mlx5_core_dev *mdev, void *vpriv)
4352
4365
if (err )
4353
4366
return err ;
4354
4367
4355
- err = mlx5e_attach_netdev (mdev , netdev );
4368
+ err = mlx5e_attach_netdev (priv );
4356
4369
if (err ) {
4357
4370
mlx5e_destroy_mdev_resources (mdev );
4358
4371
return err ;
4359
4372
}
4360
4373
4361
- mlx5e_register_vport_rep (mdev );
4362
4374
return 0 ;
4363
4375
}
4364
4376
@@ -4370,8 +4382,7 @@ static void mlx5e_detach(struct mlx5_core_dev *mdev, void *vpriv)
4370
4382
if (!netif_device_present (netdev ))
4371
4383
return ;
4372
4384
4373
- mlx5e_unregister_vport_rep (mdev );
4374
- mlx5e_detach_netdev (mdev , netdev );
4385
+ mlx5e_detach_netdev (priv );
4375
4386
mlx5e_destroy_mdev_resources (mdev );
4376
4387
}
4377
4388
@@ -4418,7 +4429,7 @@ static void *mlx5e_add(struct mlx5_core_dev *mdev)
4418
4429
mlx5e_detach (mdev , priv );
4419
4430
4420
4431
err_destroy_netdev :
4421
- mlx5e_destroy_netdev (mdev , priv );
4432
+ mlx5e_destroy_netdev (priv );
4422
4433
4423
4434
err_unregister_reps :
4424
4435
for (vport = 1 ; vport < total_vfs ; vport ++ )
@@ -4427,24 +4438,13 @@ static void *mlx5e_add(struct mlx5_core_dev *mdev)
4427
4438
return NULL ;
4428
4439
}
4429
4440
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
-
4441
4441
static void mlx5e_remove (struct mlx5_core_dev * mdev , void * vpriv )
4442
4442
{
4443
4443
struct mlx5e_priv * priv = vpriv ;
4444
4444
4445
4445
unregister_netdev (priv -> netdev );
4446
4446
mlx5e_detach (mdev , vpriv );
4447
- mlx5e_destroy_netdev (mdev , priv );
4447
+ mlx5e_destroy_netdev (priv );
4448
4448
}
4449
4449
4450
4450
static void * mlx5e_get_netdev (void * vpriv )
0 commit comments