devlink: Enable creation of the devlink-rate nodes from the driver
authorMichal Wilczynski <michal.wilczynski@intel.com>
Tue, 15 Nov 2022 10:48:17 +0000 (11:48 +0100)
committerJakub Kicinski <kuba@kernel.org>
Fri, 18 Nov 2022 05:41:26 +0000 (21:41 -0800)
Intel 100G card internal firmware hierarchy for Hierarchicial QoS is very
rigid and can't be easily removed. This requires an ability to export
default hierarchy to allow user to modify it. Currently the driver is
only able to create the 'leaf' nodes, which usually represent the vport.
This is not enough for HQoS implemented in Intel hardware.

Introduce new function devl_rate_node_create() that allows for creation
of the devlink-rate nodes from the driver.

Signed-off-by: Michal Wilczynski <michal.wilczynski@intel.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/devlink.h
net/core/devlink.c

index 366b23d3f973eb64aa7f2776a5ee4f65272f6d50..339a2ed02d3683468c90dc2446f536b1893df716 100644 (file)
@@ -1618,6 +1618,9 @@ void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port,
                                   u32 controller, u16 pf, u32 sf,
                                   bool external);
 int devl_rate_leaf_create(struct devlink_port *port, void *priv);
+struct devlink_rate *
+devl_rate_node_create(struct devlink *devlink, void *priv, char *node_name,
+                     struct devlink_rate *parent);
 void devl_rate_leaf_destroy(struct devlink_port *devlink_port);
 void devl_rate_nodes_destroy(struct devlink *devlink);
 void devlink_port_linecard_set(struct devlink_port *devlink_port,
index 525bdf42616374c1c534bd504bc99fe11b5f7776..3dfee7cd992904994a095b2248f91bd17099da03 100644 (file)
@@ -10384,6 +10384,51 @@ void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port, u32 contro
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_sf_set);
 
+/**
+ * devl_rate_node_create - create devlink rate node
+ * @devlink: devlink instance
+ * @priv: driver private data
+ * @node_name: name of the resulting node
+ * @parent: parent devlink_rate struct
+ *
+ * Create devlink rate object of type node
+ */
+struct devlink_rate *
+devl_rate_node_create(struct devlink *devlink, void *priv, char *node_name,
+                     struct devlink_rate *parent)
+{
+       struct devlink_rate *rate_node;
+
+       rate_node = devlink_rate_node_get_by_name(devlink, node_name);
+       if (!IS_ERR(rate_node))
+               return ERR_PTR(-EEXIST);
+
+       rate_node = kzalloc(sizeof(*rate_node), GFP_KERNEL);
+       if (!rate_node)
+               return ERR_PTR(-ENOMEM);
+
+       if (parent) {
+               rate_node->parent = parent;
+               refcount_inc(&rate_node->parent->refcnt);
+       }
+
+       rate_node->type = DEVLINK_RATE_TYPE_NODE;
+       rate_node->devlink = devlink;
+       rate_node->priv = priv;
+
+       rate_node->name = kstrdup(node_name, GFP_KERNEL);
+       if (!rate_node->name) {
+               kfree(rate_node);
+               return ERR_PTR(-ENOMEM);
+       }
+
+       refcount_set(&rate_node->refcnt, 1);
+       list_add(&rate_node->list, &devlink->rate_list);
+       devlink_rate_notify(rate_node, DEVLINK_CMD_RATE_NEW);
+       return rate_node;
+}
+EXPORT_SYMBOL_GPL(devl_rate_node_create);
+
 /**
  * devl_rate_leaf_create - create devlink rate leaf
  * @devlink_port: devlink port object to create rate object on