14
14
*/
15
15
static int ice_repr_get_sw_port_id (struct ice_repr * repr )
16
16
{
17
- return repr -> vf -> pf -> hw .port_info -> lport ;
17
+ return repr -> src_vsi -> back -> hw .port_info -> lport ;
18
18
}
19
19
20
20
/**
@@ -35,7 +35,7 @@ ice_repr_get_phys_port_name(struct net_device *netdev, char *buf, size_t len)
35
35
return - EOPNOTSUPP ;
36
36
37
37
res = snprintf (buf , len , "pf%dvfr%d" , ice_repr_get_sw_port_id (repr ),
38
- repr -> vf -> vf_id );
38
+ repr -> id );
39
39
if (res <= 0 )
40
40
return - EOPNOTSUPP ;
41
41
return 0 ;
@@ -279,35 +279,80 @@ ice_repr_reg_netdev(struct net_device *netdev)
279
279
}
280
280
281
281
/**
282
- * ice_repr_add - add representor for VF
283
- * @vf: pointer to VF structure
282
+ * ice_repr_rem - remove representor from VF
283
+ * @reprs: xarray storing representors
284
+ * @repr: pointer to representor structure
284
285
*/
285
- static int ice_repr_add (struct ice_vf * vf )
286
+ static void ice_repr_rem (struct xarray * reprs , struct ice_repr * repr )
287
+ {
288
+ xa_erase (reprs , repr -> id );
289
+ kfree (repr -> q_vector );
290
+ free_netdev (repr -> netdev );
291
+ kfree (repr );
292
+ }
293
+
294
+ static void ice_repr_rem_vf (struct ice_vf * vf )
295
+ {
296
+ struct ice_repr * repr = xa_load (& vf -> pf -> eswitch .reprs , vf -> repr_id );
297
+
298
+ if (!repr )
299
+ return ;
300
+
301
+ unregister_netdev (repr -> netdev );
302
+ ice_repr_rem (& vf -> pf -> eswitch .reprs , repr );
303
+ ice_devlink_destroy_vf_port (vf );
304
+ ice_virtchnl_set_dflt_ops (vf );
305
+ }
306
+
307
+ /**
308
+ * ice_repr_rem_from_all_vfs - remove port representor for all VFs
309
+ * @pf: pointer to PF structure
310
+ */
311
+ void ice_repr_rem_from_all_vfs (struct ice_pf * pf )
312
+ {
313
+ struct devlink * devlink ;
314
+ struct ice_vf * vf ;
315
+ unsigned int bkt ;
316
+
317
+ lockdep_assert_held (& pf -> vfs .table_lock );
318
+
319
+ ice_for_each_vf (pf , bkt , vf )
320
+ ice_repr_rem_vf (vf );
321
+
322
+ /* since all port representors are destroyed, there is
323
+ * no point in keeping the nodes
324
+ */
325
+ devlink = priv_to_devlink (pf );
326
+ devl_lock (devlink );
327
+ devl_rate_nodes_destroy (devlink );
328
+ devl_unlock (devlink );
329
+ }
330
+
331
+ /**
332
+ * ice_repr_add - add representor for generic VSI
333
+ * @pf: pointer to PF structure
334
+ * @src_vsi: pointer to VSI structure of device to represent
335
+ * @parent_mac: device MAC address
336
+ */
337
+ static struct ice_repr *
338
+ ice_repr_add (struct ice_pf * pf , struct ice_vsi * src_vsi , const u8 * parent_mac )
286
339
{
287
340
struct ice_q_vector * q_vector ;
288
341
struct ice_netdev_priv * np ;
289
342
struct ice_repr * repr ;
290
- struct ice_vsi * vsi ;
291
343
int err ;
292
344
293
- vsi = ice_get_vf_vsi (vf );
294
- if (!vsi )
295
- return - EINVAL ;
296
-
297
345
repr = kzalloc (sizeof (* repr ), GFP_KERNEL );
298
346
if (!repr )
299
- return - ENOMEM ;
347
+ return ERR_PTR ( - ENOMEM ) ;
300
348
301
349
repr -> netdev = alloc_etherdev (sizeof (struct ice_netdev_priv ));
302
350
if (!repr -> netdev ) {
303
351
err = - ENOMEM ;
304
352
goto err_alloc ;
305
353
}
306
354
307
- repr -> src_vsi = vsi ;
308
- repr -> vf = vf ;
309
- repr -> q_id = vf -> vf_id ;
310
- vf -> repr = repr ;
355
+ repr -> src_vsi = src_vsi ;
311
356
np = netdev_priv (repr -> netdev );
312
357
np -> repr = repr ;
313
358
@@ -318,14 +363,47 @@ static int ice_repr_add(struct ice_vf *vf)
318
363
}
319
364
repr -> q_vector = q_vector ;
320
365
321
- err = xa_alloc (& vf -> pf -> eswitch .reprs , & repr -> id , repr ,
322
- xa_limit_32b , GFP_KERNEL );
366
+ err = xa_alloc (& pf -> eswitch .reprs , & repr -> id , repr ,
367
+ XA_LIMIT ( 1 , INT_MAX ) , GFP_KERNEL );
323
368
if (err )
324
369
goto err_xa_alloc ;
370
+ repr -> q_id = repr -> id ;
371
+
372
+ ether_addr_copy (repr -> parent_mac , parent_mac );
373
+
374
+ return repr ;
375
+
376
+ err_xa_alloc :
377
+ kfree (repr -> q_vector );
378
+ err_alloc_q_vector :
379
+ free_netdev (repr -> netdev );
380
+ err_alloc :
381
+ kfree (repr );
382
+ return ERR_PTR (err );
383
+ }
384
+
385
+ static int ice_repr_add_vf (struct ice_vf * vf )
386
+ {
387
+ struct ice_repr * repr ;
388
+ struct ice_vsi * vsi ;
389
+ int err ;
390
+
391
+ vsi = ice_get_vf_vsi (vf );
392
+ if (!vsi )
393
+ return - EINVAL ;
325
394
326
395
err = ice_devlink_create_vf_port (vf );
327
396
if (err )
328
- goto err_devlink ;
397
+ return err ;
398
+
399
+ repr = ice_repr_add (vf -> pf , vsi , vf -> hw_lan_addr );
400
+ if (IS_ERR (repr )) {
401
+ err = PTR_ERR (repr );
402
+ goto err_repr_add ;
403
+ }
404
+
405
+ vf -> repr_id = repr -> id ;
406
+ repr -> vf = vf ;
329
407
330
408
repr -> netdev -> min_mtu = ETH_MIN_MTU ;
331
409
repr -> netdev -> max_mtu = ICE_MAX_MTU ;
@@ -336,73 +414,17 @@ static int ice_repr_add(struct ice_vf *vf)
336
414
if (err )
337
415
goto err_netdev ;
338
416
339
- ether_addr_copy (repr -> parent_mac , vf -> hw_lan_addr );
340
417
ice_virtchnl_set_repr_ops (vf );
341
418
342
419
return 0 ;
343
420
344
421
err_netdev :
422
+ ice_repr_rem (& vf -> pf -> eswitch .reprs , repr );
423
+ err_repr_add :
345
424
ice_devlink_destroy_vf_port (vf );
346
- err_devlink :
347
- xa_erase (& vf -> pf -> eswitch .reprs , repr -> id );
348
- err_xa_alloc :
349
- kfree (repr -> q_vector );
350
- vf -> repr -> q_vector = NULL ;
351
- err_alloc_q_vector :
352
- free_netdev (repr -> netdev );
353
- repr -> netdev = NULL ;
354
- err_alloc :
355
- kfree (repr );
356
- vf -> repr = NULL ;
357
425
return err ;
358
426
}
359
427
360
- /**
361
- * ice_repr_rem - remove representor from VF
362
- * @vf: pointer to VF structure
363
- */
364
- static void ice_repr_rem (struct ice_vf * vf )
365
- {
366
- struct ice_repr * repr = vf -> repr ;
367
-
368
- if (!repr )
369
- return ;
370
-
371
- kfree (repr -> q_vector );
372
- unregister_netdev (repr -> netdev );
373
- ice_devlink_destroy_vf_port (vf );
374
- xa_erase (& vf -> pf -> eswitch .reprs , repr -> id );
375
- free_netdev (repr -> netdev );
376
- kfree (repr );
377
- vf -> repr = NULL ;
378
-
379
- ice_virtchnl_set_dflt_ops (vf );
380
- }
381
-
382
- /**
383
- * ice_repr_rem_from_all_vfs - remove port representor for all VFs
384
- * @pf: pointer to PF structure
385
- */
386
- void ice_repr_rem_from_all_vfs (struct ice_pf * pf )
387
- {
388
- struct devlink * devlink ;
389
- struct ice_vf * vf ;
390
- unsigned int bkt ;
391
-
392
- lockdep_assert_held (& pf -> vfs .table_lock );
393
-
394
- ice_for_each_vf (pf , bkt , vf )
395
- ice_repr_rem (vf );
396
-
397
- /* since all port representors are destroyed, there is
398
- * no point in keeping the nodes
399
- */
400
- devlink = priv_to_devlink (pf );
401
- devl_lock (devlink );
402
- devl_rate_nodes_destroy (devlink );
403
- devl_unlock (devlink );
404
- }
405
-
406
428
/**
407
429
* ice_repr_add_for_all_vfs - add port representor for all VFs
408
430
* @pf: pointer to PF structure
@@ -417,7 +439,7 @@ int ice_repr_add_for_all_vfs(struct ice_pf *pf)
417
439
lockdep_assert_held (& pf -> vfs .table_lock );
418
440
419
441
ice_for_each_vf (pf , bkt , vf ) {
420
- err = ice_repr_add (vf );
442
+ err = ice_repr_add_vf (vf );
421
443
if (err )
422
444
goto err ;
423
445
}
@@ -437,6 +459,14 @@ int ice_repr_add_for_all_vfs(struct ice_pf *pf)
437
459
return err ;
438
460
}
439
461
462
+ struct ice_repr * ice_repr_get_by_vsi (struct ice_vsi * vsi )
463
+ {
464
+ if (!vsi -> vf )
465
+ return NULL ;
466
+
467
+ return xa_load (& vsi -> back -> eswitch .reprs , vsi -> vf -> repr_id );
468
+ }
469
+
440
470
/**
441
471
* ice_repr_start_tx_queues - start Tx queues of port representor
442
472
* @repr: pointer to repr structure
0 commit comments