Commit 0b7a2721 authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

devlink: expose peer SF devlink instance

Introduce a new helper devl_port_fn_devlink_set() to be used by driver
assigning a devlink instance to the peer devlink port function.

Expose this to user over new netlink attribute nested under port
function nest to expose devlink handle related to the port function.

This is particularly helpful for user to understand the relationship
between devlink instances created for SFs and the port functions
they belong to.

Note that caller of devlink_port_notify() needs to hold devlink
instance lock, put the assertion to devl_port_fn_devlink_set() to make
this requirement explicit. Also note the limitations that only allow to
make this assignment for registered objects.
Signed-off-by: default avatarJiri Pirko <jiri@nvidia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c137743b
...@@ -150,6 +150,7 @@ struct devlink_port { ...@@ -150,6 +150,7 @@ struct devlink_port {
struct devlink_rate *devlink_rate; struct devlink_rate *devlink_rate;
struct devlink_linecard *linecard; struct devlink_linecard *linecard;
u32 rel_index;
}; };
struct devlink_port_new_attrs { struct devlink_port_new_attrs {
...@@ -1697,6 +1698,8 @@ void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 contro ...@@ -1697,6 +1698,8 @@ void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 contro
void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port, void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port,
u32 controller, u16 pf, u32 sf, u32 controller, u16 pf, u32 sf,
bool external); bool external);
int devl_port_fn_devlink_set(struct devlink_port *devlink_port,
struct devlink *fn_devlink);
struct devlink_rate * struct devlink_rate *
devl_rate_node_create(struct devlink *devlink, void *priv, char *node_name, devl_rate_node_create(struct devlink *devlink, void *priv, char *node_name,
struct devlink_rate *parent); struct devlink_rate *parent);
......
...@@ -680,6 +680,7 @@ enum devlink_port_function_attr { ...@@ -680,6 +680,7 @@ enum devlink_port_function_attr {
DEVLINK_PORT_FN_ATTR_STATE, /* u8 */ DEVLINK_PORT_FN_ATTR_STATE, /* u8 */
DEVLINK_PORT_FN_ATTR_OPSTATE, /* u8 */ DEVLINK_PORT_FN_ATTR_OPSTATE, /* u8 */
DEVLINK_PORT_FN_ATTR_CAPS, /* bitfield32 */ DEVLINK_PORT_FN_ATTR_CAPS, /* bitfield32 */
DEVLINK_PORT_FN_ATTR_DEVLINK, /* nested */
__DEVLINK_PORT_FUNCTION_ATTR_MAX, __DEVLINK_PORT_FUNCTION_ATTR_MAX,
DEVLINK_PORT_FUNCTION_ATTR_MAX = __DEVLINK_PORT_FUNCTION_ATTR_MAX - 1 DEVLINK_PORT_FUNCTION_ATTR_MAX = __DEVLINK_PORT_FUNCTION_ATTR_MAX - 1
......
...@@ -428,6 +428,13 @@ devlink_nl_port_function_attrs_put(struct sk_buff *msg, struct devlink_port *por ...@@ -428,6 +428,13 @@ devlink_nl_port_function_attrs_put(struct sk_buff *msg, struct devlink_port *por
if (err) if (err)
goto out; goto out;
err = devlink_port_fn_state_fill(port, msg, extack, &msg_updated); err = devlink_port_fn_state_fill(port, msg, extack, &msg_updated);
if (err)
goto out;
err = devlink_rel_devlink_handle_put(msg, port->devlink,
port->rel_index,
DEVLINK_PORT_FN_ATTR_DEVLINK,
&msg_updated);
out: out:
if (err || !msg_updated) if (err || !msg_updated)
nla_nest_cancel(msg, function_attr); nla_nest_cancel(msg, function_attr);
...@@ -1392,6 +1399,50 @@ void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port, u32 contro ...@@ -1392,6 +1399,50 @@ void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port, u32 contro
} }
EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_sf_set); EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_sf_set);
static void devlink_port_rel_notify_cb(struct devlink *devlink, u32 port_index)
{
struct devlink_port *devlink_port;
devlink_port = devlink_port_get_by_index(devlink, port_index);
if (!devlink_port)
return;
devlink_port_notify(devlink_port, DEVLINK_CMD_PORT_NEW);
}
static void devlink_port_rel_cleanup_cb(struct devlink *devlink, u32 port_index,
u32 rel_index)
{
struct devlink_port *devlink_port;
devlink_port = devlink_port_get_by_index(devlink, port_index);
if (devlink_port && devlink_port->rel_index == rel_index)
devlink_port->rel_index = 0;
}
/**
* devl_port_fn_devlink_set - Attach peer devlink
* instance to port function.
* @devlink_port: devlink port
* @fn_devlink: devlink instance to attach
*/
int devl_port_fn_devlink_set(struct devlink_port *devlink_port,
struct devlink *fn_devlink)
{
ASSERT_DEVLINK_PORT_REGISTERED(devlink_port);
if (WARN_ON(devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_PCI_SF ||
devlink_port->attrs.pci_sf.external))
return -EINVAL;
return devlink_rel_nested_in_add(&devlink_port->rel_index,
devlink_port->devlink->index,
devlink_port->index,
devlink_port_rel_notify_cb,
devlink_port_rel_cleanup_cb,
fn_devlink);
}
EXPORT_SYMBOL_GPL(devl_port_fn_devlink_set);
/** /**
* devlink_port_linecard_set - Link port with a linecard * devlink_port_linecard_set - Link port with a linecard
* *
......
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