diff options
| author | Scott Feldman <sfeldma@gmail.com> | 2015-05-10 12:47:49 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2015-05-12 18:43:53 -0400 |
| commit | f8e20a9f87d33865cc1d67f13da0db8d457fc3c9 (patch) | |
| tree | 0072db71330af1215e78c1def9033d62156a4183 /net/switchdev/switchdev.c | |
| parent | 3094333d9089d43e8b8f0418676fa6ae06c27b51 (diff) | |
switchdev: convert parent_id_get to switchdev attr get
Switch ID is just a gettable port attribute. Convert switchdev op
switchdev_parent_id_get to a switchdev attr.
Note: for sysfs and netlink interfaces, SWITCHDEV_ATTR_PORT_PARENT_ID is
called with SWITCHDEV_F_NO_RECUSE to limit switch ID user-visiblity to only
port netdevs. So when a port is stacked under bond/bridge, the user can
only query switch id via the switch ports, but not via the upper devices
Signed-off-by: Scott Feldman <sfeldma@gmail.com>
Acked-by: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/switchdev/switchdev.c')
| -rw-r--r-- | net/switchdev/switchdev.c | 38 |
1 files changed, 11 insertions, 27 deletions
diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c index 8f47187dc185..117fd0797abd 100644 --- a/net/switchdev/switchdev.c +++ b/net/switchdev/switchdev.c | |||
| @@ -19,24 +19,6 @@ | |||
| 19 | #include <net/switchdev.h> | 19 | #include <net/switchdev.h> |
| 20 | 20 | ||
| 21 | /** | 21 | /** |
| 22 | * switchdev_parent_id_get - Get ID of a switch | ||
| 23 | * @dev: port device | ||
| 24 | * @psid: switch ID | ||
| 25 | * | ||
| 26 | * Get ID of a switch this port is part of. | ||
| 27 | */ | ||
| 28 | int switchdev_parent_id_get(struct net_device *dev, | ||
| 29 | struct netdev_phys_item_id *psid) | ||
| 30 | { | ||
| 31 | const struct switchdev_ops *ops = dev->switchdev_ops; | ||
| 32 | |||
| 33 | if (!ops || !ops->switchdev_parent_id_get) | ||
| 34 | return -EOPNOTSUPP; | ||
| 35 | return ops->switchdev_parent_id_get(dev, psid); | ||
| 36 | } | ||
| 37 | EXPORT_SYMBOL_GPL(switchdev_parent_id_get); | ||
| 38 | |||
| 39 | /** | ||
| 40 | * switchdev_port_attr_get - Get port attribute | 22 | * switchdev_port_attr_get - Get port attribute |
| 41 | * | 23 | * |
| 42 | * @dev: port device | 24 | * @dev: port device |
| @@ -414,11 +396,10 @@ static struct net_device *switchdev_get_lowest_dev(struct net_device *dev) | |||
| 414 | struct list_head *iter; | 396 | struct list_head *iter; |
| 415 | 397 | ||
| 416 | /* Recusively search down until we find a sw port dev. | 398 | /* Recusively search down until we find a sw port dev. |
| 417 | * (A sw port dev supports switchdev_parent_id_get). | 399 | * (A sw port dev supports switchdev_port_attr_get). |
| 418 | */ | 400 | */ |
| 419 | 401 | ||
| 420 | if (dev->features & NETIF_F_HW_SWITCH_OFFLOAD && | 402 | if (ops && ops->switchdev_port_attr_get) |
| 421 | ops && ops->switchdev_parent_id_get) | ||
| 422 | return dev; | 403 | return dev; |
| 423 | 404 | ||
| 424 | netdev_for_each_lower_dev(dev, lower_dev, iter) { | 405 | netdev_for_each_lower_dev(dev, lower_dev, iter) { |
| @@ -432,8 +413,10 @@ static struct net_device *switchdev_get_lowest_dev(struct net_device *dev) | |||
| 432 | 413 | ||
| 433 | static struct net_device *switchdev_get_dev_by_nhs(struct fib_info *fi) | 414 | static struct net_device *switchdev_get_dev_by_nhs(struct fib_info *fi) |
| 434 | { | 415 | { |
| 435 | struct netdev_phys_item_id psid; | 416 | struct switchdev_attr attr = { |
| 436 | struct netdev_phys_item_id prev_psid; | 417 | .id = SWITCHDEV_ATTR_PORT_PARENT_ID, |
| 418 | }; | ||
| 419 | struct switchdev_attr prev_attr; | ||
| 437 | struct net_device *dev = NULL; | 420 | struct net_device *dev = NULL; |
| 438 | int nhsel; | 421 | int nhsel; |
| 439 | 422 | ||
| @@ -449,17 +432,18 @@ static struct net_device *switchdev_get_dev_by_nhs(struct fib_info *fi) | |||
| 449 | if (!dev) | 432 | if (!dev) |
| 450 | return NULL; | 433 | return NULL; |
| 451 | 434 | ||
| 452 | if (switchdev_parent_id_get(dev, &psid)) | 435 | if (switchdev_port_attr_get(dev, &attr)) |
| 453 | return NULL; | 436 | return NULL; |
| 454 | 437 | ||
| 455 | if (nhsel > 0) { | 438 | if (nhsel > 0) { |
| 456 | if (prev_psid.id_len != psid.id_len) | 439 | if (prev_attr.ppid.id_len != attr.ppid.id_len) |
| 457 | return NULL; | 440 | return NULL; |
| 458 | if (memcmp(prev_psid.id, psid.id, psid.id_len)) | 441 | if (memcmp(prev_attr.ppid.id, attr.ppid.id, |
| 442 | attr.ppid.id_len)) | ||
| 459 | return NULL; | 443 | return NULL; |
| 460 | } | 444 | } |
| 461 | 445 | ||
| 462 | prev_psid = psid; | 446 | prev_attr = attr; |
| 463 | } | 447 | } |
| 464 | 448 | ||
| 465 | return dev; | 449 | return dev; |
