ice: set Tx topology every time new repr is added
authorMichal Swiatkowski <michal.swiatkowski@linux.intel.com>
Tue, 24 Oct 2023 11:09:25 +0000 (13:09 +0200)
committerTony Nguyen <anthony.l.nguyen@intel.com>
Mon, 13 Nov 2023 19:42:14 +0000 (11:42 -0800)
It is needed to track correct Tx topology. Update it every time new
representor is created or remove node in case of removing corresponding
representor.

Still clear all node when removing switchdev mode as part of Tx topology
isn't related only to representors. Also clear ::rate_note value to
prevent skipping this node next time Tx topology is created.

Reviewed-by: Piotr Raczynski <piotr.raczynski@intel.com>
Reviewed-by: Wojciech Drewek <wojciech.drewek@intel.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
Tested-by: Sujai Buvaneswaran <sujai.buvaneswaran@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
drivers/net/ethernet/intel/ice/ice_devlink.c
drivers/net/ethernet/intel/ice/ice_devlink.h
drivers/net/ethernet/intel/ice/ice_eswitch.c
drivers/net/ethernet/intel/ice/ice_repr.c

index 80dc5445b50d45fa2f444221aebc18800e261c43..f4e24d11ebd08bde31fda0a40537e7edd729f50d 100644 (file)
@@ -810,6 +810,10 @@ static void ice_traverse_tx_tree(struct devlink *devlink, struct ice_sched_node
        struct ice_vf *vf;
        int i;
 
+       if (node->rate_node)
+               /* already added, skip to the next */
+               goto traverse_children;
+
        if (node->parent == tc_node) {
                /* create root node */
                rate_node = devl_rate_node_create(devlink, node, node->name, NULL);
@@ -831,6 +835,7 @@ static void ice_traverse_tx_tree(struct devlink *devlink, struct ice_sched_node
        if (rate_node && !IS_ERR(rate_node))
                node->rate_node = rate_node;
 
+traverse_children:
        for (i = 0; i < node->num_children; i++)
                ice_traverse_tx_tree(devlink, node->children[i], tc_node, pf);
 }
@@ -861,6 +866,30 @@ int ice_devlink_rate_init_tx_topology(struct devlink *devlink, struct ice_vsi *v
        return 0;
 }
 
+static void ice_clear_rate_nodes(struct ice_sched_node *node)
+{
+       node->rate_node = NULL;
+
+       for (int i = 0; i < node->num_children; i++)
+               ice_clear_rate_nodes(node->children[i]);
+}
+
+/**
+ * ice_devlink_rate_clear_tx_topology - clear node->rate_node
+ * @vsi: main vsi struct
+ *
+ * Clear rate_node to cleanup creation of Tx topology.
+ *
+ */
+void ice_devlink_rate_clear_tx_topology(struct ice_vsi *vsi)
+{
+       struct ice_port_info *pi = vsi->port_info;
+
+       mutex_lock(&pi->sched_lock);
+       ice_clear_rate_nodes(pi->root->children[0]);
+       mutex_unlock(&pi->sched_lock);
+}
+
 /**
  * ice_set_object_tx_share - sets node scheduling parameter
  * @pi: devlink struct instance
index 6ec96779f52e0abf105cdff7c36e90bb15f750fb..d291c0e2e17bfe6cee34fdf13bbba40e5fad8822 100644 (file)
@@ -20,5 +20,6 @@ void ice_devlink_destroy_regions(struct ice_pf *pf);
 
 int ice_devlink_rate_init_tx_topology(struct devlink *devlink, struct ice_vsi *vsi);
 void ice_tear_down_devlink_rate_tree(struct ice_pf *pf);
+void ice_devlink_rate_clear_tx_topology(struct ice_vsi *vsi);
 
 #endif /* _ICE_DEVLINK_H_ */
index 67231e43ffa66fd27f3e6aeb655725cb8bdc9f07..db70a62429e3053557063c8630e3b0917b778816 100644 (file)
@@ -519,6 +519,7 @@ err_vsi:
 static void ice_eswitch_disable_switchdev(struct ice_pf *pf)
 {
        struct ice_vsi *ctrl_vsi = pf->eswitch.control_vsi;
+       struct devlink *devlink = priv_to_devlink(pf);
 
        ice_eswitch_napi_disable(&pf->eswitch.reprs);
        ice_eswitch_br_offloads_deinit(pf);
@@ -526,6 +527,14 @@ static void ice_eswitch_disable_switchdev(struct ice_pf *pf)
        ice_eswitch_release_reprs(pf);
        ice_vsi_release(ctrl_vsi);
        ice_repr_rem_from_all_vfs(pf);
+
+       /* since all port representors are destroyed, there is
+        * no point in keeping the nodes
+        */
+       ice_devlink_rate_clear_tx_topology(ice_get_main_vsi(pf));
+       devl_lock(devlink);
+       devl_rate_nodes_destroy(devlink);
+       devl_unlock(devlink);
 }
 
 /**
index b29a3d010780e57c3186b7db4fecc8e69680fe71..fa36cc932c5f5c7b3907f5c849358a03da56ebd9 100644 (file)
@@ -278,6 +278,13 @@ ice_repr_reg_netdev(struct net_device *netdev)
        return register_netdev(netdev);
 }
 
+static void ice_repr_remove_node(struct devlink_port *devlink_port)
+{
+       devl_lock(devlink_port->devlink);
+       devl_rate_leaf_destroy(devlink_port);
+       devl_unlock(devlink_port->devlink);
+}
+
 /**
  * ice_repr_rem - remove representor from VF
  * @reprs: xarray storing representors
@@ -298,6 +305,7 @@ static void ice_repr_rem_vf(struct ice_vf *vf)
        if (!repr)
                return;
 
+       ice_repr_remove_node(&repr->vf->devlink_port);
        unregister_netdev(repr->netdev);
        ice_repr_rem(&vf->pf->eswitch.reprs, repr);
        ice_devlink_destroy_vf_port(vf);
@@ -310,7 +318,6 @@ static void ice_repr_rem_vf(struct ice_vf *vf)
  */
 void ice_repr_rem_from_all_vfs(struct ice_pf *pf)
 {
-       struct devlink *devlink;
        struct ice_vf *vf;
        unsigned int bkt;
 
@@ -318,14 +325,19 @@ void ice_repr_rem_from_all_vfs(struct ice_pf *pf)
 
        ice_for_each_vf(pf, bkt, vf)
                ice_repr_rem_vf(vf);
+}
+
+static void ice_repr_set_tx_topology(struct ice_pf *pf)
+{
+       struct devlink *devlink;
+
+       /* only export if ADQ and DCB disabled and eswitch enabled*/
+       if (ice_is_adq_active(pf) || ice_is_dcb_active(pf) ||
+           !ice_is_switchdev_running(pf))
+               return;
 
-       /* since all port representors are destroyed, there is
-        * no point in keeping the nodes
-        */
        devlink = priv_to_devlink(pf);
-       devl_lock(devlink);
-       devl_rate_nodes_destroy(devlink);
-       devl_unlock(devlink);
+       ice_devlink_rate_init_tx_topology(devlink, ice_get_main_vsi(pf));
 }
 
 /**
@@ -415,6 +427,7 @@ static struct ice_repr *ice_repr_add_vf(struct ice_vf *vf)
                goto err_netdev;
 
        ice_virtchnl_set_repr_ops(vf);
+       ice_repr_set_tx_topology(vf->pf);
 
        return repr;