diff options
author | Florian Fainelli <f.fainelli@gmail.com> | 2019-02-06 12:45:35 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2019-02-06 17:16:11 -0500 |
commit | d6abc5969463359c366d459247b90366fcd6f5c5 (patch) | |
tree | b957d030e5c687e689f0da32c9585c81a7f6efbd /net/core/dev.c | |
parent | 47b98039fb6e1b3fc7b04a86a9c8ed5bbf604103 (diff) |
net: Introduce ndo_get_port_parent_id()
In preparation for getting rid of switchdev_ops, create a dedicated NDO
operation for getting the port's parent identifier. There are
essentially two classes of drivers that need to implement getting the
port's parent ID which are VF/PF drivers with a built-in switch, and
pure switchdev drivers such as mlxsw, ocelot, dsa etc.
We introduce a helper function: dev_get_port_parent_id() which supports
recursion into the lower devices to obtain the first port's parent ID.
Convert the bridge, core and ipv4 multicast routing code to check for
such ndo_get_port_parent_id() and call the helper function when valid
before falling back to switchdev_port_attr_get(). This will allow us to
convert all relevant drivers in one go instead of having to implement
both switchdev_port_attr_get() and ndo_get_port_parent_id() operations,
then get rid of switchdev_port_attr_get().
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/dev.c')
-rw-r--r-- | net/core/dev.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/net/core/dev.c b/net/core/dev.c index bfa4be42afff..8c6d5cf8a308 100644 --- a/net/core/dev.c +++ b/net/core/dev.c | |||
@@ -7878,6 +7878,63 @@ int dev_get_phys_port_name(struct net_device *dev, | |||
7878 | EXPORT_SYMBOL(dev_get_phys_port_name); | 7878 | EXPORT_SYMBOL(dev_get_phys_port_name); |
7879 | 7879 | ||
7880 | /** | 7880 | /** |
7881 | * dev_get_port_parent_id - Get the device's port parent identifier | ||
7882 | * @dev: network device | ||
7883 | * @ppid: pointer to a storage for the port's parent identifier | ||
7884 | * @recurse: allow/disallow recursion to lower devices | ||
7885 | * | ||
7886 | * Get the devices's port parent identifier | ||
7887 | */ | ||
7888 | int dev_get_port_parent_id(struct net_device *dev, | ||
7889 | struct netdev_phys_item_id *ppid, | ||
7890 | bool recurse) | ||
7891 | { | ||
7892 | const struct net_device_ops *ops = dev->netdev_ops; | ||
7893 | struct netdev_phys_item_id first = { }; | ||
7894 | struct net_device *lower_dev; | ||
7895 | struct list_head *iter; | ||
7896 | int err = -EOPNOTSUPP; | ||
7897 | |||
7898 | if (ops->ndo_get_port_parent_id) | ||
7899 | return ops->ndo_get_port_parent_id(dev, ppid); | ||
7900 | |||
7901 | if (!recurse) | ||
7902 | return err; | ||
7903 | |||
7904 | netdev_for_each_lower_dev(dev, lower_dev, iter) { | ||
7905 | err = dev_get_port_parent_id(lower_dev, ppid, recurse); | ||
7906 | if (err) | ||
7907 | break; | ||
7908 | if (!first.id_len) | ||
7909 | first = *ppid; | ||
7910 | else if (memcmp(&first, ppid, sizeof(*ppid))) | ||
7911 | return -ENODATA; | ||
7912 | } | ||
7913 | |||
7914 | return err; | ||
7915 | } | ||
7916 | EXPORT_SYMBOL(dev_get_port_parent_id); | ||
7917 | |||
7918 | /** | ||
7919 | * netdev_port_same_parent_id - Indicate if two network devices have | ||
7920 | * the same port parent identifier | ||
7921 | * @a: first network device | ||
7922 | * @b: second network device | ||
7923 | */ | ||
7924 | bool netdev_port_same_parent_id(struct net_device *a, struct net_device *b) | ||
7925 | { | ||
7926 | struct netdev_phys_item_id a_id = { }; | ||
7927 | struct netdev_phys_item_id b_id = { }; | ||
7928 | |||
7929 | if (dev_get_port_parent_id(a, &a_id, true) || | ||
7930 | dev_get_port_parent_id(b, &b_id, true)) | ||
7931 | return false; | ||
7932 | |||
7933 | return netdev_phys_item_id_same(&a_id, &b_id); | ||
7934 | } | ||
7935 | EXPORT_SYMBOL(netdev_port_same_parent_id); | ||
7936 | |||
7937 | /** | ||
7881 | * dev_change_proto_down - update protocol port state information | 7938 | * dev_change_proto_down - update protocol port state information |
7882 | * @dev: device | 7939 | * @dev: device |
7883 | * @proto_down: new value | 7940 | * @proto_down: new value |