Skip to content

Commit

Permalink
devlink: Add health buffer support
Browse files Browse the repository at this point in the history
Devlink health buffer is a mechanism to pass descriptors between drivers
and devlink. The API allows the driver to add objects, object pair,
value array (nested attributes), value and name.

Driver can use this API to fill the buffers in a format which can be
translated by the devlink to the netlink message.

In order to fulfill it, an internal buffer descriptor is defined. This
will hold the data and metadata per each attribute and by used to pass
actual commands to the netlink.

This mechanism will be later used in devlink health for dump and diagnose
data store by the drivers.

Signed-off-by: Eran Ben Elisha <eranbe@mellanox.com>
Reviewed-by: Moshe Shemesh <moshe@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eran Ben Elisha authored and David S. Miller committed Jan 18, 2019
1 parent f88c19a commit cb5ccfb
Show file tree
Hide file tree
Showing 3 changed files with 585 additions and 0 deletions.
76 changes: 76 additions & 0 deletions include/net/devlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ struct devlink_region;

typedef void devlink_snapshot_data_dest_t(const void *data);

struct devlink_health_buffer;

struct devlink_ops {
int (*reload)(struct devlink *devlink, struct netlink_ext_ack *extack);
int (*port_type_set)(struct devlink_port *devlink_port,
Expand Down Expand Up @@ -584,6 +586,22 @@ int devlink_region_snapshot_create(struct devlink_region *region, u64 data_len,
u8 *data, u32 snapshot_id,
devlink_snapshot_data_dest_t *data_destructor);

int devlink_health_buffer_nest_start(struct devlink_health_buffer *buffer,
int attrtype);
void devlink_health_buffer_nest_end(struct devlink_health_buffer *buffer);
void devlink_health_buffer_nest_cancel(struct devlink_health_buffer *buffer);
int devlink_health_buffer_put_object_name(struct devlink_health_buffer *buffer,
char *name);
int devlink_health_buffer_put_value_u8(struct devlink_health_buffer *buffer,
u8 value);
int devlink_health_buffer_put_value_u32(struct devlink_health_buffer *buffer,
u32 value);
int devlink_health_buffer_put_value_u64(struct devlink_health_buffer *buffer,
u64 value);
int devlink_health_buffer_put_value_string(struct devlink_health_buffer *buffer,
char *name);
int devlink_health_buffer_put_value_data(struct devlink_health_buffer *buffer,
void *data, int len);
#else

static inline struct devlink *devlink_alloc(const struct devlink_ops *ops,
Expand Down Expand Up @@ -844,6 +862,64 @@ devlink_region_snapshot_create(struct devlink_region *region, u64 data_len,
return 0;
}

static inline int
devlink_health_buffer_nest_start(struct devlink_health_buffer *buffer,
int attrtype)
{
return 0;
}

static inline void
devlink_health_buffer_nest_end(struct devlink_health_buffer *buffer)
{
}

static inline void
devlink_health_buffer_nest_cancel(struct devlink_health_buffer *buffer)
{
}

static inline int
devlink_health_buffer_put_object_name(struct devlink_health_buffer *buffer,
char *name)
{
return 0;
}

static inline int
devlink_health_buffer_put_value_u8(struct devlink_health_buffer *buffer,
u8 value)
{
return 0;
}

static inline int
devlink_health_buffer_put_value_u32(struct devlink_health_buffer *buffer,
u32 value)
{
return 0;
}

static inline int
devlink_health_buffer_put_value_u64(struct devlink_health_buffer *buffer,
u64 value)
{
return 0;
}

static inline int
devlink_health_buffer_put_value_string(struct devlink_health_buffer *buffer,
char *name)
{
return 0;
}

static inline int
devlink_health_buffer_put_value_data(struct devlink_health_buffer *buffer,
void *data, int len)
{
return 0;
}
#endif

#endif /* _NET_DEVLINK_H_ */
8 changes: 8 additions & 0 deletions include/uapi/linux/devlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,14 @@ enum devlink_attr {
DEVLINK_ATTR_REGION_CHUNK_ADDR, /* u64 */
DEVLINK_ATTR_REGION_CHUNK_LEN, /* u64 */

DEVLINK_ATTR_HEALTH_BUFFER_OBJECT, /* nested */
DEVLINK_ATTR_HEALTH_BUFFER_OBJECT_PAIR, /* nested */
DEVLINK_ATTR_HEALTH_BUFFER_OBJECT_NAME, /* string */
DEVLINK_ATTR_HEALTH_BUFFER_OBJECT_VALUE, /* nested */
DEVLINK_ATTR_HEALTH_BUFFER_OBJECT_VALUE_ARRAY, /* nested */
DEVLINK_ATTR_HEALTH_BUFFER_OBJECT_VALUE_TYPE, /* u8 */
DEVLINK_ATTR_HEALTH_BUFFER_OBJECT_VALUE_DATA, /* dynamic */

/* add new attributes above here, update the policy in devlink.c */

__DEVLINK_ATTR_MAX,
Expand Down
Loading

0 comments on commit cb5ccfb

Please sign in to comment.