Commit d9f9b9a4 authored by Arkadi Sharshevsky's avatar Arkadi Sharshevsky Committed by David S. Miller

devlink: Add support for resource abstraction

Add support for hardware resource abstraction over devlink. Each resource
is identified via id, furthermore it contains information regarding its
size and its related sub resources. Each resource can also provide its
current occupancy.

In some cases the sizes of some resources can be changed, yet for those
changes to take place a hot driver reload may be needed. The reload
capability will be introduced in the next patch.
Signed-off-by: default avatarArkadi Sharshevsky <arkadis@mellanox.com>
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2406e7e5
...@@ -26,6 +26,7 @@ struct devlink { ...@@ -26,6 +26,7 @@ struct devlink {
struct list_head port_list; struct list_head port_list;
struct list_head sb_list; struct list_head sb_list;
struct list_head dpipe_table_list; struct list_head dpipe_table_list;
struct list_head resource_list;
struct devlink_dpipe_headers *dpipe_headers; struct devlink_dpipe_headers *dpipe_headers;
const struct devlink_ops *ops; const struct devlink_ops *ops;
struct device *dev; struct device *dev;
...@@ -224,6 +225,61 @@ struct devlink_dpipe_headers { ...@@ -224,6 +225,61 @@ struct devlink_dpipe_headers {
unsigned int headers_count; unsigned int headers_count;
}; };
/**
* struct devlink_resource_ops - resource ops
* @occ_get: get the occupied size
* @size_validate: validate the size of the resource before update, reload
* is needed for changes to take place
*/
struct devlink_resource_ops {
u64 (*occ_get)(struct devlink *devlink);
int (*size_validate)(struct devlink *devlink, u64 size,
struct netlink_ext_ack *extack);
};
/**
* struct devlink_resource_size_params - resource's size parameters
* @size_min: minimum size which can be set
* @size_max: maximum size which can be set
* @size_granularity: size granularity
* @size_unit: resource's basic unit
*/
struct devlink_resource_size_params {
u64 size_min;
u64 size_max;
u64 size_granularity;
enum devlink_resource_unit unit;
};
/**
* struct devlink_resource - devlink resource
* @name: name of the resource
* @id: id, per devlink instance
* @size: size of the resource
* @size_new: updated size of the resource, reload is needed
* @size_valid: valid in case the total size of the resource is valid
* including its children
* @parent: parent resource
* @size_params: size parameters
* @list: parent list
* @resource_list: list of child resources
* @resource_ops: resource ops
*/
struct devlink_resource {
const char *name;
u64 id;
u64 size;
u64 size_new;
bool size_valid;
struct devlink_resource *parent;
struct devlink_resource_size_params *size_params;
struct list_head list;
struct list_head resource_list;
const struct devlink_resource_ops *resource_ops;
};
#define DEVLINK_RESOURCE_ID_PARENT_TOP 0
struct devlink_ops { struct devlink_ops {
int (*port_type_set)(struct devlink_port *devlink_port, int (*port_type_set)(struct devlink_port *devlink_port,
enum devlink_port_type port_type); enum devlink_port_type port_type);
...@@ -333,6 +389,20 @@ extern struct devlink_dpipe_header devlink_dpipe_header_ethernet; ...@@ -333,6 +389,20 @@ extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
extern struct devlink_dpipe_header devlink_dpipe_header_ipv4; extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
extern struct devlink_dpipe_header devlink_dpipe_header_ipv6; extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
int devlink_resource_register(struct devlink *devlink,
const char *resource_name,
bool top_hierarchy,
u64 resource_size,
u64 resource_id,
u64 parent_resource_id,
struct devlink_resource_size_params *size_params,
const struct devlink_resource_ops *resource_ops);
void devlink_resources_unregister(struct devlink *devlink,
struct devlink_resource *resource);
int devlink_resource_size_get(struct devlink *devlink,
u64 resource_id,
u64 *p_resource_size);
#else #else
static inline struct devlink *devlink_alloc(const struct devlink_ops *ops, static inline struct devlink *devlink_alloc(const struct devlink_ops *ops,
...@@ -469,6 +539,32 @@ devlink_dpipe_match_put(struct sk_buff *skb, ...@@ -469,6 +539,32 @@ devlink_dpipe_match_put(struct sk_buff *skb,
return 0; return 0;
} }
static inline int
devlink_resource_register(struct devlink *devlink,
const char *resource_name,
bool top_hierarchy,
u64 resource_size,
u64 resource_id,
u64 parent_resource_id,
struct devlink_resource_size_params *size_params,
const struct devlink_resource_ops *resource_ops)
{
return 0;
}
static inline void
devlink_resources_unregister(struct devlink *devlink,
struct devlink_resource *resource)
{
}
static inline int
devlink_resource_size_get(struct devlink *devlink, u64 resource_id,
u64 *p_resource_size)
{
return -EOPNOTSUPP;
}
#endif #endif
#endif /* _NET_DEVLINK_H_ */ #endif /* _NET_DEVLINK_H_ */
...@@ -70,6 +70,8 @@ enum devlink_command { ...@@ -70,6 +70,8 @@ enum devlink_command {
DEVLINK_CMD_DPIPE_ENTRIES_GET, DEVLINK_CMD_DPIPE_ENTRIES_GET,
DEVLINK_CMD_DPIPE_HEADERS_GET, DEVLINK_CMD_DPIPE_HEADERS_GET,
DEVLINK_CMD_DPIPE_TABLE_COUNTERS_SET, DEVLINK_CMD_DPIPE_TABLE_COUNTERS_SET,
DEVLINK_CMD_RESOURCE_SET,
DEVLINK_CMD_RESOURCE_DUMP,
/* add new commands above here */ /* add new commands above here */
__DEVLINK_CMD_MAX, __DEVLINK_CMD_MAX,
...@@ -202,6 +204,18 @@ enum devlink_attr { ...@@ -202,6 +204,18 @@ enum devlink_attr {
DEVLINK_ATTR_PAD, DEVLINK_ATTR_PAD,
DEVLINK_ATTR_ESWITCH_ENCAP_MODE, /* u8 */ DEVLINK_ATTR_ESWITCH_ENCAP_MODE, /* u8 */
DEVLINK_ATTR_RESOURCE_LIST, /* nested */
DEVLINK_ATTR_RESOURCE, /* nested */
DEVLINK_ATTR_RESOURCE_NAME, /* string */
DEVLINK_ATTR_RESOURCE_ID, /* u64 */
DEVLINK_ATTR_RESOURCE_SIZE, /* u64 */
DEVLINK_ATTR_RESOURCE_SIZE_NEW, /* u64 */
DEVLINK_ATTR_RESOURCE_SIZE_VALID, /* u8 */
DEVLINK_ATTR_RESOURCE_SIZE_MIN, /* u64 */
DEVLINK_ATTR_RESOURCE_SIZE_MAX, /* u64 */
DEVLINK_ATTR_RESOURCE_SIZE_GRAN, /* u64 */
DEVLINK_ATTR_RESOURCE_UNIT, /* u8 */
DEVLINK_ATTR_RESOURCE_OCC, /* u64 */
/* add new attributes above here, update the policy in devlink.c */ /* add new attributes above here, update the policy in devlink.c */
...@@ -245,4 +259,8 @@ enum devlink_dpipe_header_id { ...@@ -245,4 +259,8 @@ enum devlink_dpipe_header_id {
DEVLINK_DPIPE_HEADER_IPV6, DEVLINK_DPIPE_HEADER_IPV6,
}; };
enum devlink_resource_unit {
DEVLINK_RESOURCE_UNIT_ENTRY,
};
#endif /* _UAPI_LINUX_DEVLINK_H_ */ #endif /* _UAPI_LINUX_DEVLINK_H_ */
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment