@@ -283,34 +283,23 @@ ice_repr_reg_netdev(struct net_device *netdev)
283283 return register_netdev (netdev );
284284}
285285
286- static void ice_repr_remove_node (struct devlink_port * devlink_port )
287- {
288- devl_rate_leaf_destroy (devlink_port );
289- }
290-
291286/**
292- * ice_repr_rem - remove representor from VF
287+ * ice_repr_destroy - remove representor from VF
293288 * @repr: pointer to representor structure
294289 */
295- static void ice_repr_rem (struct ice_repr * repr )
290+ void ice_repr_destroy (struct ice_repr * repr )
296291{
297292 free_percpu (repr -> stats );
298293 free_netdev (repr -> netdev );
299294 kfree (repr );
300295}
301296
302- /**
303- * ice_repr_rem_vf - remove representor from VF
304- * @repr: pointer to representor structure
305- */
306- void ice_repr_rem_vf (struct ice_repr * repr )
297+ static void ice_repr_rem_vf (struct ice_repr * repr )
307298{
308- ice_repr_remove_node (& repr -> vf -> devlink_port );
309299 ice_eswitch_decfg_vsi (repr -> src_vsi , repr -> parent_mac );
310300 unregister_netdev (repr -> netdev );
311301 ice_devlink_destroy_vf_port (repr -> vf );
312302 ice_virtchnl_set_dflt_ops (repr -> vf );
313- ice_repr_rem (repr );
314303}
315304
316305static void ice_repr_set_tx_topology (struct ice_pf * pf )
@@ -327,13 +316,10 @@ static void ice_repr_set_tx_topology(struct ice_pf *pf)
327316}
328317
329318/**
330- * ice_repr_add - add representor for generic VSI
331- * @pf: pointer to PF structure
319+ * ice_repr_create - add representor for generic VSI
332320 * @src_vsi: pointer to VSI structure of device to represent
333- * @parent_mac: device MAC address
334321 */
335- static struct ice_repr *
336- ice_repr_add (struct ice_pf * pf , struct ice_vsi * src_vsi , const u8 * parent_mac )
322+ static struct ice_repr * ice_repr_create (struct ice_vsi * src_vsi )
337323{
338324 struct ice_netdev_priv * np ;
339325 struct ice_repr * repr ;
@@ -360,7 +346,10 @@ ice_repr_add(struct ice_pf *pf, struct ice_vsi *src_vsi, const u8 *parent_mac)
360346 np = netdev_priv (repr -> netdev );
361347 np -> repr = repr ;
362348
363- ether_addr_copy (repr -> parent_mac , parent_mac );
349+ repr -> netdev -> min_mtu = ETH_MIN_MTU ;
350+ repr -> netdev -> max_mtu = ICE_MAX_MTU ;
351+
352+ SET_NETDEV_DEV (repr -> netdev , ice_pf_to_dev (src_vsi -> back ));
364353
365354 return repr ;
366355
@@ -371,32 +360,15 @@ ice_repr_add(struct ice_pf *pf, struct ice_vsi *src_vsi, const u8 *parent_mac)
371360 return ERR_PTR (err );
372361}
373362
374- struct ice_repr * ice_repr_add_vf (struct ice_vf * vf )
363+ static int ice_repr_add_vf (struct ice_repr * repr )
375364{
376- struct ice_repr * repr ;
377- struct ice_vsi * vsi ;
365+ struct ice_vf * vf = repr -> vf ;
378366 int err ;
379367
380- vsi = ice_get_vf_vsi (vf );
381- if (!vsi )
382- return ERR_PTR (- ENOENT );
383-
384368 err = ice_devlink_create_vf_port (vf );
385369 if (err )
386- return ERR_PTR (err );
387-
388- repr = ice_repr_add (vf -> pf , vsi , vf -> hw_lan_addr );
389- if (IS_ERR (repr )) {
390- err = PTR_ERR (repr );
391- goto err_repr_add ;
392- }
393-
394- repr -> vf = vf ;
370+ return err ;
395371
396- repr -> netdev -> min_mtu = ETH_MIN_MTU ;
397- repr -> netdev -> max_mtu = ICE_MAX_MTU ;
398-
399- SET_NETDEV_DEV (repr -> netdev , ice_pf_to_dev (vf -> pf ));
400372 SET_NETDEV_DEVLINK_PORT (repr -> netdev , & vf -> devlink_port );
401373 err = ice_repr_reg_netdev (repr -> netdev );
402374 if (err )
@@ -409,15 +381,43 @@ struct ice_repr *ice_repr_add_vf(struct ice_vf *vf)
409381 ice_virtchnl_set_repr_ops (vf );
410382 ice_repr_set_tx_topology (vf -> pf );
411383
412- return repr ;
384+ return 0 ;
413385
414386err_cfg_vsi :
415387 unregister_netdev (repr -> netdev );
416388err_netdev :
417- ice_repr_rem (repr );
418- err_repr_add :
419389 ice_devlink_destroy_vf_port (vf );
420- return ERR_PTR (err );
390+ return err ;
391+ }
392+
393+ /**
394+ * ice_repr_create_vf - add representor for VF VSI
395+ * @vf: VF to create port representor on
396+ *
397+ * Set correct representor type for VF and functions pointer.
398+ *
399+ * Return: created port representor on success, error otherwise
400+ */
401+ struct ice_repr * ice_repr_create_vf (struct ice_vf * vf )
402+ {
403+ struct ice_vsi * vsi = ice_get_vf_vsi (vf );
404+ struct ice_repr * repr ;
405+
406+ if (!vsi )
407+ return ERR_PTR (- EINVAL );
408+
409+ repr = ice_repr_create (vsi );
410+ if (!repr )
411+ return ERR_PTR (- ENOMEM );
412+
413+ repr -> type = ICE_REPR_TYPE_VF ;
414+ repr -> vf = vf ;
415+ repr -> ops .add = ice_repr_add_vf ;
416+ repr -> ops .rem = ice_repr_rem_vf ;
417+
418+ ether_addr_copy (repr -> parent_mac , vf -> hw_lan_addr );
419+
420+ return repr ;
421421}
422422
423423struct ice_repr * ice_repr_get (struct ice_pf * pf , u32 id )
0 commit comments