2020-09-16 19:31:01 +03:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
|
|
|
|
|
/* Copyright (c) 2019-2020 Marvell International Ltd. All rights reserved */
|
|
|
|
|
|
|
|
|
|
#include <linux/if_bridge.h>
|
|
|
|
|
#include <linux/if_vlan.h>
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
#include <linux/notifier.h>
|
|
|
|
|
#include <net/netevent.h>
|
|
|
|
|
#include <net/switchdev.h>
|
|
|
|
|
|
|
|
|
|
#include "prestera.h"
|
|
|
|
|
#include "prestera_hw.h"
|
|
|
|
|
#include "prestera_switchdev.h"
|
|
|
|
|
|
|
|
|
|
#define PRESTERA_VID_ALL (0xffff)
|
|
|
|
|
|
|
|
|
|
#define PRESTERA_DEFAULT_AGEING_TIME_MS 300000
|
|
|
|
|
#define PRESTERA_MAX_AGEING_TIME_MS 1000000000
|
|
|
|
|
#define PRESTERA_MIN_AGEING_TIME_MS 32000
|
|
|
|
|
|
|
|
|
|
struct prestera_fdb_event_work {
|
|
|
|
|
struct work_struct work;
|
|
|
|
|
struct switchdev_notifier_fdb_info fdb_info;
|
|
|
|
|
struct net_device *dev;
|
|
|
|
|
unsigned long event;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct prestera_switchdev {
|
|
|
|
|
struct prestera_switch *sw;
|
|
|
|
|
struct list_head bridge_list;
|
|
|
|
|
bool bridge_8021q_exists;
|
|
|
|
|
struct notifier_block swdev_nb_blk;
|
|
|
|
|
struct notifier_block swdev_nb;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct prestera_bridge {
|
|
|
|
|
struct list_head head;
|
|
|
|
|
struct net_device *dev;
|
|
|
|
|
struct prestera_switchdev *swdev;
|
|
|
|
|
struct list_head port_list;
|
|
|
|
|
bool vlan_enabled;
|
|
|
|
|
u16 bridge_id;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct prestera_bridge_port {
|
|
|
|
|
struct list_head head;
|
|
|
|
|
struct net_device *dev;
|
|
|
|
|
struct prestera_bridge *bridge;
|
|
|
|
|
struct list_head vlan_list;
|
|
|
|
|
refcount_t ref_count;
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
u8 stp_state;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct prestera_bridge_vlan {
|
|
|
|
|
struct list_head head;
|
|
|
|
|
struct list_head port_vlan_list;
|
|
|
|
|
u16 vid;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct prestera_port_vlan {
|
|
|
|
|
struct list_head br_vlan_head;
|
|
|
|
|
struct list_head port_head;
|
|
|
|
|
struct prestera_port *port;
|
|
|
|
|
struct prestera_bridge_port *br_port;
|
|
|
|
|
u16 vid;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct workqueue_struct *swdev_wq;
|
|
|
|
|
|
|
|
|
|
static void prestera_bridge_port_put(struct prestera_bridge_port *br_port);
|
|
|
|
|
|
|
|
|
|
static int prestera_port_vid_stp_set(struct prestera_port *port, u16 vid,
|
|
|
|
|
u8 state);
|
|
|
|
|
|
|
|
|
|
static struct prestera_bridge_vlan *
|
|
|
|
|
prestera_bridge_vlan_create(struct prestera_bridge_port *br_port, u16 vid)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_bridge_vlan *br_vlan;
|
|
|
|
|
|
|
|
|
|
br_vlan = kzalloc(sizeof(*br_vlan), GFP_KERNEL);
|
|
|
|
|
if (!br_vlan)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&br_vlan->port_vlan_list);
|
|
|
|
|
br_vlan->vid = vid;
|
|
|
|
|
list_add(&br_vlan->head, &br_port->vlan_list);
|
|
|
|
|
|
|
|
|
|
return br_vlan;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void prestera_bridge_vlan_destroy(struct prestera_bridge_vlan *br_vlan)
|
|
|
|
|
{
|
|
|
|
|
list_del(&br_vlan->head);
|
|
|
|
|
WARN_ON(!list_empty(&br_vlan->port_vlan_list));
|
|
|
|
|
kfree(br_vlan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct prestera_bridge_vlan *
|
|
|
|
|
prestera_bridge_vlan_by_vid(struct prestera_bridge_port *br_port, u16 vid)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_bridge_vlan *br_vlan;
|
|
|
|
|
|
|
|
|
|
list_for_each_entry(br_vlan, &br_port->vlan_list, head) {
|
|
|
|
|
if (br_vlan->vid == vid)
|
|
|
|
|
return br_vlan;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int prestera_bridge_vlan_port_count(struct prestera_bridge *bridge,
|
|
|
|
|
u16 vid)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_bridge_port *br_port;
|
|
|
|
|
struct prestera_bridge_vlan *br_vlan;
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
|
|
list_for_each_entry(br_port, &bridge->port_list, head) {
|
|
|
|
|
list_for_each_entry(br_vlan, &br_port->vlan_list, head) {
|
|
|
|
|
if (br_vlan->vid == vid) {
|
|
|
|
|
count += 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void prestera_bridge_vlan_put(struct prestera_bridge_vlan *br_vlan)
|
|
|
|
|
{
|
|
|
|
|
if (list_empty(&br_vlan->port_vlan_list))
|
|
|
|
|
prestera_bridge_vlan_destroy(br_vlan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct prestera_port_vlan *
|
|
|
|
|
prestera_port_vlan_by_vid(struct prestera_port *port, u16 vid)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_port_vlan *port_vlan;
|
|
|
|
|
|
|
|
|
|
list_for_each_entry(port_vlan, &port->vlans_list, port_head) {
|
|
|
|
|
if (port_vlan->vid == vid)
|
|
|
|
|
return port_vlan;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct prestera_port_vlan *
|
|
|
|
|
prestera_port_vlan_create(struct prestera_port *port, u16 vid, bool untagged)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_port_vlan *port_vlan;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
port_vlan = prestera_port_vlan_by_vid(port, vid);
|
|
|
|
|
if (port_vlan)
|
|
|
|
|
return ERR_PTR(-EEXIST);
|
|
|
|
|
|
|
|
|
|
err = prestera_hw_vlan_port_set(port, vid, true, untagged);
|
|
|
|
|
if (err)
|
|
|
|
|
return ERR_PTR(err);
|
|
|
|
|
|
|
|
|
|
port_vlan = kzalloc(sizeof(*port_vlan), GFP_KERNEL);
|
|
|
|
|
if (!port_vlan) {
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
|
goto err_port_vlan_alloc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
port_vlan->port = port;
|
|
|
|
|
port_vlan->vid = vid;
|
|
|
|
|
|
|
|
|
|
list_add(&port_vlan->port_head, &port->vlans_list);
|
|
|
|
|
|
|
|
|
|
return port_vlan;
|
|
|
|
|
|
|
|
|
|
err_port_vlan_alloc:
|
|
|
|
|
prestera_hw_vlan_port_set(port, vid, false, false);
|
|
|
|
|
return ERR_PTR(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
prestera_port_vlan_bridge_leave(struct prestera_port_vlan *port_vlan)
|
|
|
|
|
{
|
|
|
|
|
u32 fdb_flush_mode = PRESTERA_FDB_FLUSH_MODE_DYNAMIC;
|
|
|
|
|
struct prestera_port *port = port_vlan->port;
|
|
|
|
|
struct prestera_bridge_vlan *br_vlan;
|
|
|
|
|
struct prestera_bridge_port *br_port;
|
|
|
|
|
bool last_port, last_vlan;
|
|
|
|
|
u16 vid = port_vlan->vid;
|
|
|
|
|
int port_count;
|
|
|
|
|
|
|
|
|
|
br_port = port_vlan->br_port;
|
|
|
|
|
port_count = prestera_bridge_vlan_port_count(br_port->bridge, vid);
|
|
|
|
|
br_vlan = prestera_bridge_vlan_by_vid(br_port, vid);
|
|
|
|
|
|
|
|
|
|
last_vlan = list_is_singular(&br_port->vlan_list);
|
|
|
|
|
last_port = port_count == 1;
|
|
|
|
|
|
|
|
|
|
if (last_vlan)
|
|
|
|
|
prestera_hw_fdb_flush_port(port, fdb_flush_mode);
|
|
|
|
|
else if (last_port)
|
|
|
|
|
prestera_hw_fdb_flush_vlan(port->sw, vid, fdb_flush_mode);
|
|
|
|
|
else
|
|
|
|
|
prestera_hw_fdb_flush_port_vlan(port, vid, fdb_flush_mode);
|
|
|
|
|
|
|
|
|
|
list_del(&port_vlan->br_vlan_head);
|
|
|
|
|
prestera_bridge_vlan_put(br_vlan);
|
|
|
|
|
prestera_bridge_port_put(br_port);
|
|
|
|
|
port_vlan->br_port = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void prestera_port_vlan_destroy(struct prestera_port_vlan *port_vlan)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_port *port = port_vlan->port;
|
|
|
|
|
u16 vid = port_vlan->vid;
|
|
|
|
|
|
|
|
|
|
if (port_vlan->br_port)
|
|
|
|
|
prestera_port_vlan_bridge_leave(port_vlan);
|
|
|
|
|
|
|
|
|
|
prestera_hw_vlan_port_set(port, vid, false, false);
|
|
|
|
|
list_del(&port_vlan->port_head);
|
|
|
|
|
kfree(port_vlan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct prestera_bridge *
|
|
|
|
|
prestera_bridge_create(struct prestera_switchdev *swdev, struct net_device *dev)
|
|
|
|
|
{
|
|
|
|
|
bool vlan_enabled = br_vlan_enabled(dev);
|
|
|
|
|
struct prestera_bridge *bridge;
|
|
|
|
|
u16 bridge_id;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
if (vlan_enabled && swdev->bridge_8021q_exists) {
|
|
|
|
|
netdev_err(dev, "Only one VLAN-aware bridge is supported\n");
|
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bridge = kzalloc(sizeof(*bridge), GFP_KERNEL);
|
|
|
|
|
if (!bridge)
|
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
|
|
if (vlan_enabled) {
|
|
|
|
|
swdev->bridge_8021q_exists = true;
|
|
|
|
|
} else {
|
|
|
|
|
err = prestera_hw_bridge_create(swdev->sw, &bridge_id);
|
|
|
|
|
if (err) {
|
|
|
|
|
kfree(bridge);
|
|
|
|
|
return ERR_PTR(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bridge->bridge_id = bridge_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bridge->vlan_enabled = vlan_enabled;
|
|
|
|
|
bridge->swdev = swdev;
|
|
|
|
|
bridge->dev = dev;
|
|
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&bridge->port_list);
|
|
|
|
|
|
|
|
|
|
list_add(&bridge->head, &swdev->bridge_list);
|
|
|
|
|
|
|
|
|
|
return bridge;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void prestera_bridge_destroy(struct prestera_bridge *bridge)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_switchdev *swdev = bridge->swdev;
|
|
|
|
|
|
|
|
|
|
list_del(&bridge->head);
|
|
|
|
|
|
|
|
|
|
if (bridge->vlan_enabled)
|
|
|
|
|
swdev->bridge_8021q_exists = false;
|
|
|
|
|
else
|
|
|
|
|
prestera_hw_bridge_delete(swdev->sw, bridge->bridge_id);
|
|
|
|
|
|
|
|
|
|
WARN_ON(!list_empty(&bridge->port_list));
|
|
|
|
|
kfree(bridge);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void prestera_bridge_put(struct prestera_bridge *bridge)
|
|
|
|
|
{
|
|
|
|
|
if (list_empty(&bridge->port_list))
|
|
|
|
|
prestera_bridge_destroy(bridge);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
struct prestera_bridge *prestera_bridge_by_dev(struct prestera_switchdev *swdev,
|
|
|
|
|
const struct net_device *dev)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_bridge *bridge;
|
|
|
|
|
|
|
|
|
|
list_for_each_entry(bridge, &swdev->bridge_list, head)
|
|
|
|
|
if (bridge->dev == dev)
|
|
|
|
|
return bridge;
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct prestera_bridge_port *
|
|
|
|
|
__prestera_bridge_port_by_dev(struct prestera_bridge *bridge,
|
|
|
|
|
struct net_device *dev)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_bridge_port *br_port;
|
|
|
|
|
|
|
|
|
|
list_for_each_entry(br_port, &bridge->port_list, head) {
|
|
|
|
|
if (br_port->dev == dev)
|
|
|
|
|
return br_port;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct prestera_bridge_port *
|
|
|
|
|
prestera_bridge_port_by_dev(struct prestera_switchdev *swdev,
|
|
|
|
|
struct net_device *dev)
|
|
|
|
|
{
|
|
|
|
|
struct net_device *br_dev = netdev_master_upper_dev_get(dev);
|
|
|
|
|
struct prestera_bridge *bridge;
|
|
|
|
|
|
|
|
|
|
if (!br_dev)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
bridge = prestera_bridge_by_dev(swdev, br_dev);
|
|
|
|
|
if (!bridge)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return __prestera_bridge_port_by_dev(bridge, dev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct prestera_bridge_port *
|
|
|
|
|
prestera_bridge_port_create(struct prestera_bridge *bridge,
|
|
|
|
|
struct net_device *dev)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_bridge_port *br_port;
|
|
|
|
|
|
|
|
|
|
br_port = kzalloc(sizeof(*br_port), GFP_KERNEL);
|
|
|
|
|
if (!br_port)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
br_port->flags = BR_LEARNING | BR_FLOOD | BR_LEARNING_SYNC |
|
|
|
|
|
BR_MCAST_FLOOD;
|
|
|
|
|
br_port->stp_state = BR_STATE_DISABLED;
|
|
|
|
|
refcount_set(&br_port->ref_count, 1);
|
|
|
|
|
br_port->bridge = bridge;
|
|
|
|
|
br_port->dev = dev;
|
|
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&br_port->vlan_list);
|
|
|
|
|
list_add(&br_port->head, &bridge->port_list);
|
|
|
|
|
|
|
|
|
|
return br_port;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
prestera_bridge_port_destroy(struct prestera_bridge_port *br_port)
|
|
|
|
|
{
|
|
|
|
|
list_del(&br_port->head);
|
|
|
|
|
WARN_ON(!list_empty(&br_port->vlan_list));
|
|
|
|
|
kfree(br_port);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void prestera_bridge_port_get(struct prestera_bridge_port *br_port)
|
|
|
|
|
{
|
|
|
|
|
refcount_inc(&br_port->ref_count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void prestera_bridge_port_put(struct prestera_bridge_port *br_port)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_bridge *bridge = br_port->bridge;
|
|
|
|
|
|
|
|
|
|
if (refcount_dec_and_test(&br_port->ref_count)) {
|
|
|
|
|
prestera_bridge_port_destroy(br_port);
|
|
|
|
|
prestera_bridge_put(bridge);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct prestera_bridge_port *
|
|
|
|
|
prestera_bridge_port_add(struct prestera_bridge *bridge, struct net_device *dev)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_bridge_port *br_port;
|
|
|
|
|
|
|
|
|
|
br_port = __prestera_bridge_port_by_dev(bridge, dev);
|
|
|
|
|
if (br_port) {
|
|
|
|
|
prestera_bridge_port_get(br_port);
|
|
|
|
|
return br_port;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
br_port = prestera_bridge_port_create(bridge, dev);
|
|
|
|
|
if (!br_port)
|
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
|
|
return br_port;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
prestera_bridge_1d_port_join(struct prestera_bridge_port *br_port)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_port *port = netdev_priv(br_port->dev);
|
|
|
|
|
struct prestera_bridge *bridge = br_port->bridge;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
err = prestera_hw_bridge_port_add(port, bridge->bridge_id);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
err = prestera_hw_port_flood_set(port, br_port->flags & BR_FLOOD);
|
|
|
|
|
if (err)
|
|
|
|
|
goto err_port_flood_set;
|
|
|
|
|
|
|
|
|
|
err = prestera_hw_port_learning_set(port, br_port->flags & BR_LEARNING);
|
|
|
|
|
if (err)
|
|
|
|
|
goto err_port_learning_set;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
err_port_learning_set:
|
|
|
|
|
prestera_hw_port_flood_set(port, false);
|
|
|
|
|
err_port_flood_set:
|
|
|
|
|
prestera_hw_bridge_port_delete(port, bridge->bridge_id);
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int prestera_port_bridge_join(struct prestera_port *port,
|
|
|
|
|
struct net_device *upper)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_switchdev *swdev = port->sw->swdev;
|
|
|
|
|
struct prestera_bridge_port *br_port;
|
|
|
|
|
struct prestera_bridge *bridge;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
bridge = prestera_bridge_by_dev(swdev, upper);
|
|
|
|
|
if (!bridge) {
|
|
|
|
|
bridge = prestera_bridge_create(swdev, upper);
|
|
|
|
|
if (IS_ERR(bridge))
|
|
|
|
|
return PTR_ERR(bridge);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
br_port = prestera_bridge_port_add(bridge, port->dev);
|
|
|
|
|
if (IS_ERR(br_port)) {
|
|
|
|
|
err = PTR_ERR(br_port);
|
|
|
|
|
goto err_brport_create;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bridge->vlan_enabled)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
err = prestera_bridge_1d_port_join(br_port);
|
|
|
|
|
if (err)
|
|
|
|
|
goto err_port_join;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
err_port_join:
|
|
|
|
|
prestera_bridge_port_put(br_port);
|
|
|
|
|
err_brport_create:
|
|
|
|
|
prestera_bridge_put(bridge);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void prestera_bridge_1q_port_leave(struct prestera_bridge_port *br_port)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_port *port = netdev_priv(br_port->dev);
|
|
|
|
|
|
|
|
|
|
prestera_hw_fdb_flush_port(port, PRESTERA_FDB_FLUSH_MODE_ALL);
|
|
|
|
|
prestera_port_pvid_set(port, PRESTERA_DEFAULT_VID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void prestera_bridge_1d_port_leave(struct prestera_bridge_port *br_port)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_port *port = netdev_priv(br_port->dev);
|
|
|
|
|
|
|
|
|
|
prestera_hw_fdb_flush_port(port, PRESTERA_FDB_FLUSH_MODE_ALL);
|
|
|
|
|
prestera_hw_bridge_port_delete(port, br_port->bridge->bridge_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int prestera_port_vid_stp_set(struct prestera_port *port, u16 vid,
|
|
|
|
|
u8 state)
|
|
|
|
|
{
|
|
|
|
|
u8 hw_state = state;
|
|
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
|
case BR_STATE_DISABLED:
|
|
|
|
|
hw_state = PRESTERA_STP_DISABLED;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BR_STATE_BLOCKING:
|
|
|
|
|
case BR_STATE_LISTENING:
|
|
|
|
|
hw_state = PRESTERA_STP_BLOCK_LISTEN;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BR_STATE_LEARNING:
|
|
|
|
|
hw_state = PRESTERA_STP_LEARN;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BR_STATE_FORWARDING:
|
|
|
|
|
hw_state = PRESTERA_STP_FORWARD;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return prestera_hw_vlan_port_stp_set(port, vid, hw_state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void prestera_port_bridge_leave(struct prestera_port *port,
|
|
|
|
|
struct net_device *upper)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_switchdev *swdev = port->sw->swdev;
|
|
|
|
|
struct prestera_bridge_port *br_port;
|
|
|
|
|
struct prestera_bridge *bridge;
|
|
|
|
|
|
|
|
|
|
bridge = prestera_bridge_by_dev(swdev, upper);
|
|
|
|
|
if (!bridge)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
br_port = __prestera_bridge_port_by_dev(bridge, port->dev);
|
|
|
|
|
if (!br_port)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
bridge = br_port->bridge;
|
|
|
|
|
|
|
|
|
|
if (bridge->vlan_enabled)
|
|
|
|
|
prestera_bridge_1q_port_leave(br_port);
|
|
|
|
|
else
|
|
|
|
|
prestera_bridge_1d_port_leave(br_port);
|
|
|
|
|
|
|
|
|
|
prestera_hw_port_learning_set(port, false);
|
|
|
|
|
prestera_hw_port_flood_set(port, false);
|
|
|
|
|
prestera_port_vid_stp_set(port, PRESTERA_VID_ALL, BR_STATE_FORWARDING);
|
|
|
|
|
prestera_bridge_port_put(br_port);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int prestera_bridge_port_event(struct net_device *dev, unsigned long event,
|
|
|
|
|
void *ptr)
|
|
|
|
|
{
|
|
|
|
|
struct netdev_notifier_changeupper_info *info = ptr;
|
|
|
|
|
struct netlink_ext_ack *extack;
|
|
|
|
|
struct prestera_port *port;
|
|
|
|
|
struct net_device *upper;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
extack = netdev_notifier_info_to_extack(&info->info);
|
|
|
|
|
port = netdev_priv(dev);
|
|
|
|
|
upper = info->upper_dev;
|
|
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
|
case NETDEV_PRECHANGEUPPER:
|
|
|
|
|
if (!netif_is_bridge_master(upper)) {
|
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Unknown upper device type");
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!info->linking)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (netdev_has_any_upper_dev(upper)) {
|
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Upper device is already enslaved");
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NETDEV_CHANGEUPPER:
|
|
|
|
|
if (!netif_is_bridge_master(upper))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (info->linking) {
|
|
|
|
|
err = prestera_port_bridge_join(port, upper);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
} else {
|
|
|
|
|
prestera_port_bridge_leave(port, upper);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int prestera_port_attr_br_flags_set(struct prestera_port *port,
|
|
|
|
|
struct net_device *dev,
|
net: switchdev: pass flags and mask to both {PRE_,}BRIDGE_FLAGS attributes
This switchdev attribute offers a counterproductive API for a driver
writer, because although br_switchdev_set_port_flag gets passed a
"flags" and a "mask", those are passed piecemeal to the driver, so while
the PRE_BRIDGE_FLAGS listener knows what changed because it has the
"mask", the BRIDGE_FLAGS listener doesn't, because it only has the final
value. But certain drivers can offload only certain combinations of
settings, like for example they cannot change unicast flooding
independently of multicast flooding - they must be both on or both off.
The way the information is passed to switchdev makes drivers not
expressive enough, and unable to reject this request ahead of time, in
the PRE_BRIDGE_FLAGS notifier, so they are forced to reject it during
the deferred BRIDGE_FLAGS attribute, where the rejection is currently
ignored.
This patch also changes drivers to make use of the "mask" field for edge
detection when possible.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-02-12 17:15:55 +02:00
|
|
|
struct switchdev_brport_flags flags)
|
2020-09-16 19:31:01 +03:00
|
|
|
{
|
|
|
|
|
struct prestera_bridge_port *br_port;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
br_port = prestera_bridge_port_by_dev(port->sw->swdev, dev);
|
|
|
|
|
if (!br_port)
|
|
|
|
|
return 0;
|
|
|
|
|
|
net: switchdev: pass flags and mask to both {PRE_,}BRIDGE_FLAGS attributes
This switchdev attribute offers a counterproductive API for a driver
writer, because although br_switchdev_set_port_flag gets passed a
"flags" and a "mask", those are passed piecemeal to the driver, so while
the PRE_BRIDGE_FLAGS listener knows what changed because it has the
"mask", the BRIDGE_FLAGS listener doesn't, because it only has the final
value. But certain drivers can offload only certain combinations of
settings, like for example they cannot change unicast flooding
independently of multicast flooding - they must be both on or both off.
The way the information is passed to switchdev makes drivers not
expressive enough, and unable to reject this request ahead of time, in
the PRE_BRIDGE_FLAGS notifier, so they are forced to reject it during
the deferred BRIDGE_FLAGS attribute, where the rejection is currently
ignored.
This patch also changes drivers to make use of the "mask" field for edge
detection when possible.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-02-12 17:15:55 +02:00
|
|
|
if (flags.mask & BR_FLOOD) {
|
|
|
|
|
err = prestera_hw_port_flood_set(port, flags.val & BR_FLOOD);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2020-09-16 19:31:01 +03:00
|
|
|
|
net: switchdev: pass flags and mask to both {PRE_,}BRIDGE_FLAGS attributes
This switchdev attribute offers a counterproductive API for a driver
writer, because although br_switchdev_set_port_flag gets passed a
"flags" and a "mask", those are passed piecemeal to the driver, so while
the PRE_BRIDGE_FLAGS listener knows what changed because it has the
"mask", the BRIDGE_FLAGS listener doesn't, because it only has the final
value. But certain drivers can offload only certain combinations of
settings, like for example they cannot change unicast flooding
independently of multicast flooding - they must be both on or both off.
The way the information is passed to switchdev makes drivers not
expressive enough, and unable to reject this request ahead of time, in
the PRE_BRIDGE_FLAGS notifier, so they are forced to reject it during
the deferred BRIDGE_FLAGS attribute, where the rejection is currently
ignored.
This patch also changes drivers to make use of the "mask" field for edge
detection when possible.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-02-12 17:15:55 +02:00
|
|
|
if (flags.mask & BR_LEARNING) {
|
|
|
|
|
err = prestera_hw_port_learning_set(port,
|
|
|
|
|
flags.val & BR_LEARNING);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2020-09-16 19:31:01 +03:00
|
|
|
|
net: switchdev: pass flags and mask to both {PRE_,}BRIDGE_FLAGS attributes
This switchdev attribute offers a counterproductive API for a driver
writer, because although br_switchdev_set_port_flag gets passed a
"flags" and a "mask", those are passed piecemeal to the driver, so while
the PRE_BRIDGE_FLAGS listener knows what changed because it has the
"mask", the BRIDGE_FLAGS listener doesn't, because it only has the final
value. But certain drivers can offload only certain combinations of
settings, like for example they cannot change unicast flooding
independently of multicast flooding - they must be both on or both off.
The way the information is passed to switchdev makes drivers not
expressive enough, and unable to reject this request ahead of time, in
the PRE_BRIDGE_FLAGS notifier, so they are forced to reject it during
the deferred BRIDGE_FLAGS attribute, where the rejection is currently
ignored.
This patch also changes drivers to make use of the "mask" field for edge
detection when possible.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-02-12 17:15:55 +02:00
|
|
|
memcpy(&br_port->flags, &flags.val, sizeof(flags.val));
|
2020-09-16 19:31:01 +03:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int prestera_port_attr_br_ageing_set(struct prestera_port *port,
|
|
|
|
|
unsigned long ageing_clock_t)
|
|
|
|
|
{
|
|
|
|
|
unsigned long ageing_jiffies = clock_t_to_jiffies(ageing_clock_t);
|
|
|
|
|
u32 ageing_time_ms = jiffies_to_msecs(ageing_jiffies);
|
|
|
|
|
struct prestera_switch *sw = port->sw;
|
|
|
|
|
|
net: switchdev: remove the transaction structure from port attributes
Since the introduction of the switchdev API, port attributes were
transmitted to drivers for offloading using a two-step transactional
model, with a prepare phase that was supposed to catch all errors, and a
commit phase that was supposed to never fail.
Some classes of failures can never be avoided, like hardware access, or
memory allocation. In the latter case, merely attempting to move the
memory allocation to the preparation phase makes it impossible to avoid
memory leaks, since commit 91cf8eceffc1 ("switchdev: Remove unused
transaction item queue") which has removed the unused mechanism of
passing on the allocated memory between one phase and another.
It is time we admit that separating the preparation from the commit
phase is something that is best left for the driver to decide, and not
something that should be baked into the API, especially since there are
no switchdev callers that depend on this.
This patch removes the struct switchdev_trans member from switchdev port
attribute notifier structures, and converts drivers to not look at this
member.
In part, this patch contains a revert of my previous commit 2e554a7a5d8a
("net: dsa: propagate switchdev vlan_filtering prepare phase to
drivers").
For the most part, the conversion was trivial except for:
- Rocker's world implementation based on Broadcom OF-DPA had an odd
implementation of ofdpa_port_attr_bridge_flags_set. The conversion was
done mechanically, by pasting the implementation twice, then only
keeping the code that would get executed during prepare phase on top,
then only keeping the code that gets executed during the commit phase
on bottom, then simplifying the resulting code until this was obtained.
- DSA's offloading of STP state, bridge flags, VLAN filtering and
multicast router could be converted right away. But the ageing time
could not, so a shim was introduced and this was left for a further
commit.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Kurt Kanzenbach <kurt@linutronix.de> # hellcreek
Reviewed-by: Linus Walleij <linus.walleij@linaro.org> # RTL8366RB
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2021-01-09 02:01:50 +02:00
|
|
|
if (ageing_time_ms < PRESTERA_MIN_AGEING_TIME_MS ||
|
|
|
|
|
ageing_time_ms > PRESTERA_MAX_AGEING_TIME_MS)
|
|
|
|
|
return -ERANGE;
|
2020-09-16 19:31:01 +03:00
|
|
|
|
|
|
|
|
return prestera_hw_switch_ageing_set(sw, ageing_time_ms);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int prestera_port_attr_br_vlan_set(struct prestera_port *port,
|
|
|
|
|
struct net_device *dev,
|
|
|
|
|
bool vlan_enabled)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_switch *sw = port->sw;
|
|
|
|
|
struct prestera_bridge *bridge;
|
|
|
|
|
|
|
|
|
|
bridge = prestera_bridge_by_dev(sw->swdev, dev);
|
|
|
|
|
if (WARN_ON(!bridge))
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
if (bridge->vlan_enabled == vlan_enabled)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
netdev_err(bridge->dev, "VLAN filtering can't be changed for existing bridge\n");
|
|
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int prestera_port_bridge_vlan_stp_set(struct prestera_port *port,
|
|
|
|
|
struct prestera_bridge_vlan *br_vlan,
|
|
|
|
|
u8 state)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_port_vlan *port_vlan;
|
|
|
|
|
|
|
|
|
|
list_for_each_entry(port_vlan, &br_vlan->port_vlan_list, br_vlan_head) {
|
|
|
|
|
if (port_vlan->port != port)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
return prestera_port_vid_stp_set(port, br_vlan->vid, state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-08 21:06:22 -08:00
|
|
|
static int prestera_port_attr_stp_state_set(struct prestera_port *port,
|
|
|
|
|
struct net_device *dev,
|
|
|
|
|
u8 state)
|
2020-09-16 19:31:01 +03:00
|
|
|
{
|
|
|
|
|
struct prestera_bridge_port *br_port;
|
|
|
|
|
struct prestera_bridge_vlan *br_vlan;
|
|
|
|
|
int err;
|
|
|
|
|
u16 vid;
|
|
|
|
|
|
|
|
|
|
br_port = prestera_bridge_port_by_dev(port->sw->swdev, dev);
|
|
|
|
|
if (!br_port)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (!br_port->bridge->vlan_enabled) {
|
|
|
|
|
vid = br_port->bridge->bridge_id;
|
|
|
|
|
err = prestera_port_vid_stp_set(port, vid, state);
|
|
|
|
|
if (err)
|
|
|
|
|
goto err_port_stp_set;
|
|
|
|
|
} else {
|
|
|
|
|
list_for_each_entry(br_vlan, &br_port->vlan_list, head) {
|
|
|
|
|
err = prestera_port_bridge_vlan_stp_set(port, br_vlan,
|
|
|
|
|
state);
|
|
|
|
|
if (err)
|
|
|
|
|
goto err_port_vlan_stp_set;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
br_port->stp_state = state;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
err_port_vlan_stp_set:
|
|
|
|
|
list_for_each_entry_continue_reverse(br_vlan, &br_port->vlan_list, head)
|
|
|
|
|
prestera_port_bridge_vlan_stp_set(port, br_vlan, br_port->stp_state);
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
err_port_stp_set:
|
|
|
|
|
prestera_port_vid_stp_set(port, vid, br_port->stp_state);
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int prestera_port_obj_attr_set(struct net_device *dev,
|
2021-02-12 17:15:51 +02:00
|
|
|
const struct switchdev_attr *attr,
|
|
|
|
|
struct netlink_ext_ack *extack)
|
2020-09-16 19:31:01 +03:00
|
|
|
{
|
|
|
|
|
struct prestera_port *port = netdev_priv(dev);
|
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
|
|
switch (attr->id) {
|
|
|
|
|
case SWITCHDEV_ATTR_ID_PORT_STP_STATE:
|
2021-01-08 21:06:22 -08:00
|
|
|
err = prestera_port_attr_stp_state_set(port, attr->orig_dev,
|
|
|
|
|
attr->u.stp_state);
|
2020-09-16 19:31:01 +03:00
|
|
|
break;
|
|
|
|
|
case SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS:
|
net: switchdev: pass flags and mask to both {PRE_,}BRIDGE_FLAGS attributes
This switchdev attribute offers a counterproductive API for a driver
writer, because although br_switchdev_set_port_flag gets passed a
"flags" and a "mask", those are passed piecemeal to the driver, so while
the PRE_BRIDGE_FLAGS listener knows what changed because it has the
"mask", the BRIDGE_FLAGS listener doesn't, because it only has the final
value. But certain drivers can offload only certain combinations of
settings, like for example they cannot change unicast flooding
independently of multicast flooding - they must be both on or both off.
The way the information is passed to switchdev makes drivers not
expressive enough, and unable to reject this request ahead of time, in
the PRE_BRIDGE_FLAGS notifier, so they are forced to reject it during
the deferred BRIDGE_FLAGS attribute, where the rejection is currently
ignored.
This patch also changes drivers to make use of the "mask" field for edge
detection when possible.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-02-12 17:15:55 +02:00
|
|
|
if (attr->u.brport_flags.mask &
|
2020-09-16 19:31:01 +03:00
|
|
|
~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD))
|
|
|
|
|
err = -EINVAL;
|
|
|
|
|
break;
|
|
|
|
|
case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
|
net: switchdev: remove the transaction structure from port attributes
Since the introduction of the switchdev API, port attributes were
transmitted to drivers for offloading using a two-step transactional
model, with a prepare phase that was supposed to catch all errors, and a
commit phase that was supposed to never fail.
Some classes of failures can never be avoided, like hardware access, or
memory allocation. In the latter case, merely attempting to move the
memory allocation to the preparation phase makes it impossible to avoid
memory leaks, since commit 91cf8eceffc1 ("switchdev: Remove unused
transaction item queue") which has removed the unused mechanism of
passing on the allocated memory between one phase and another.
It is time we admit that separating the preparation from the commit
phase is something that is best left for the driver to decide, and not
something that should be baked into the API, especially since there are
no switchdev callers that depend on this.
This patch removes the struct switchdev_trans member from switchdev port
attribute notifier structures, and converts drivers to not look at this
member.
In part, this patch contains a revert of my previous commit 2e554a7a5d8a
("net: dsa: propagate switchdev vlan_filtering prepare phase to
drivers").
For the most part, the conversion was trivial except for:
- Rocker's world implementation based on Broadcom OF-DPA had an odd
implementation of ofdpa_port_attr_bridge_flags_set. The conversion was
done mechanically, by pasting the implementation twice, then only
keeping the code that would get executed during prepare phase on top,
then only keeping the code that gets executed during the commit phase
on bottom, then simplifying the resulting code until this was obtained.
- DSA's offloading of STP state, bridge flags, VLAN filtering and
multicast router could be converted right away. But the ageing time
could not, so a shim was introduced and this was left for a further
commit.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Kurt Kanzenbach <kurt@linutronix.de> # hellcreek
Reviewed-by: Linus Walleij <linus.walleij@linaro.org> # RTL8366RB
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2021-01-09 02:01:50 +02:00
|
|
|
err = prestera_port_attr_br_flags_set(port, attr->orig_dev,
|
2020-09-16 19:31:01 +03:00
|
|
|
attr->u.brport_flags);
|
|
|
|
|
break;
|
|
|
|
|
case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME:
|
net: switchdev: remove the transaction structure from port attributes
Since the introduction of the switchdev API, port attributes were
transmitted to drivers for offloading using a two-step transactional
model, with a prepare phase that was supposed to catch all errors, and a
commit phase that was supposed to never fail.
Some classes of failures can never be avoided, like hardware access, or
memory allocation. In the latter case, merely attempting to move the
memory allocation to the preparation phase makes it impossible to avoid
memory leaks, since commit 91cf8eceffc1 ("switchdev: Remove unused
transaction item queue") which has removed the unused mechanism of
passing on the allocated memory between one phase and another.
It is time we admit that separating the preparation from the commit
phase is something that is best left for the driver to decide, and not
something that should be baked into the API, especially since there are
no switchdev callers that depend on this.
This patch removes the struct switchdev_trans member from switchdev port
attribute notifier structures, and converts drivers to not look at this
member.
In part, this patch contains a revert of my previous commit 2e554a7a5d8a
("net: dsa: propagate switchdev vlan_filtering prepare phase to
drivers").
For the most part, the conversion was trivial except for:
- Rocker's world implementation based on Broadcom OF-DPA had an odd
implementation of ofdpa_port_attr_bridge_flags_set. The conversion was
done mechanically, by pasting the implementation twice, then only
keeping the code that would get executed during prepare phase on top,
then only keeping the code that gets executed during the commit phase
on bottom, then simplifying the resulting code until this was obtained.
- DSA's offloading of STP state, bridge flags, VLAN filtering and
multicast router could be converted right away. But the ageing time
could not, so a shim was introduced and this was left for a further
commit.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Kurt Kanzenbach <kurt@linutronix.de> # hellcreek
Reviewed-by: Linus Walleij <linus.walleij@linaro.org> # RTL8366RB
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2021-01-09 02:01:50 +02:00
|
|
|
err = prestera_port_attr_br_ageing_set(port,
|
2020-09-16 19:31:01 +03:00
|
|
|
attr->u.ageing_time);
|
|
|
|
|
break;
|
|
|
|
|
case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING:
|
net: switchdev: remove the transaction structure from port attributes
Since the introduction of the switchdev API, port attributes were
transmitted to drivers for offloading using a two-step transactional
model, with a prepare phase that was supposed to catch all errors, and a
commit phase that was supposed to never fail.
Some classes of failures can never be avoided, like hardware access, or
memory allocation. In the latter case, merely attempting to move the
memory allocation to the preparation phase makes it impossible to avoid
memory leaks, since commit 91cf8eceffc1 ("switchdev: Remove unused
transaction item queue") which has removed the unused mechanism of
passing on the allocated memory between one phase and another.
It is time we admit that separating the preparation from the commit
phase is something that is best left for the driver to decide, and not
something that should be baked into the API, especially since there are
no switchdev callers that depend on this.
This patch removes the struct switchdev_trans member from switchdev port
attribute notifier structures, and converts drivers to not look at this
member.
In part, this patch contains a revert of my previous commit 2e554a7a5d8a
("net: dsa: propagate switchdev vlan_filtering prepare phase to
drivers").
For the most part, the conversion was trivial except for:
- Rocker's world implementation based on Broadcom OF-DPA had an odd
implementation of ofdpa_port_attr_bridge_flags_set. The conversion was
done mechanically, by pasting the implementation twice, then only
keeping the code that would get executed during prepare phase on top,
then only keeping the code that gets executed during the commit phase
on bottom, then simplifying the resulting code until this was obtained.
- DSA's offloading of STP state, bridge flags, VLAN filtering and
multicast router could be converted right away. But the ageing time
could not, so a shim was introduced and this was left for a further
commit.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Kurt Kanzenbach <kurt@linutronix.de> # hellcreek
Reviewed-by: Linus Walleij <linus.walleij@linaro.org> # RTL8366RB
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2021-01-09 02:01:50 +02:00
|
|
|
err = prestera_port_attr_br_vlan_set(port, attr->orig_dev,
|
2020-09-16 19:31:01 +03:00
|
|
|
attr->u.vlan_filtering);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
err = -EOPNOTSUPP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
prestera_fdb_offload_notify(struct prestera_port *port,
|
|
|
|
|
struct switchdev_notifier_fdb_info *info)
|
|
|
|
|
{
|
|
|
|
|
struct switchdev_notifier_fdb_info send_info;
|
|
|
|
|
|
|
|
|
|
send_info.addr = info->addr;
|
|
|
|
|
send_info.vid = info->vid;
|
|
|
|
|
send_info.offloaded = true;
|
|
|
|
|
|
|
|
|
|
call_switchdev_notifiers(SWITCHDEV_FDB_OFFLOADED, port->dev,
|
|
|
|
|
&send_info.info, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int prestera_port_fdb_set(struct prestera_port *port,
|
|
|
|
|
struct switchdev_notifier_fdb_info *fdb_info,
|
|
|
|
|
bool adding)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_switch *sw = port->sw;
|
|
|
|
|
struct prestera_bridge_port *br_port;
|
|
|
|
|
struct prestera_bridge *bridge;
|
|
|
|
|
int err;
|
|
|
|
|
u16 vid;
|
|
|
|
|
|
|
|
|
|
br_port = prestera_bridge_port_by_dev(sw->swdev, port->dev);
|
|
|
|
|
if (!br_port)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
bridge = br_port->bridge;
|
|
|
|
|
|
|
|
|
|
if (bridge->vlan_enabled)
|
|
|
|
|
vid = fdb_info->vid;
|
|
|
|
|
else
|
|
|
|
|
vid = bridge->bridge_id;
|
|
|
|
|
|
|
|
|
|
if (adding)
|
|
|
|
|
err = prestera_hw_fdb_add(port, fdb_info->addr, vid, false);
|
|
|
|
|
else
|
|
|
|
|
err = prestera_hw_fdb_del(port, fdb_info->addr, vid);
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void prestera_fdb_event_work(struct work_struct *work)
|
|
|
|
|
{
|
|
|
|
|
struct switchdev_notifier_fdb_info *fdb_info;
|
|
|
|
|
struct prestera_fdb_event_work *swdev_work;
|
|
|
|
|
struct prestera_port *port;
|
|
|
|
|
struct net_device *dev;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
swdev_work = container_of(work, struct prestera_fdb_event_work, work);
|
|
|
|
|
dev = swdev_work->dev;
|
|
|
|
|
|
|
|
|
|
rtnl_lock();
|
|
|
|
|
|
|
|
|
|
port = prestera_port_dev_lower_find(dev);
|
|
|
|
|
if (!port)
|
|
|
|
|
goto out_unlock;
|
|
|
|
|
|
|
|
|
|
switch (swdev_work->event) {
|
|
|
|
|
case SWITCHDEV_FDB_ADD_TO_DEVICE:
|
|
|
|
|
fdb_info = &swdev_work->fdb_info;
|
2021-04-14 19:52:56 +03:00
|
|
|
if (!fdb_info->added_by_user || fdb_info->is_local)
|
2020-09-16 19:31:01 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
err = prestera_port_fdb_set(port, fdb_info, true);
|
|
|
|
|
if (err)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
prestera_fdb_offload_notify(port, fdb_info);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SWITCHDEV_FDB_DEL_TO_DEVICE:
|
|
|
|
|
fdb_info = &swdev_work->fdb_info;
|
|
|
|
|
prestera_port_fdb_set(port, fdb_info, false);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out_unlock:
|
|
|
|
|
rtnl_unlock();
|
|
|
|
|
|
|
|
|
|
kfree(swdev_work->fdb_info.addr);
|
|
|
|
|
kfree(swdev_work);
|
|
|
|
|
dev_put(dev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int prestera_switchdev_event(struct notifier_block *unused,
|
|
|
|
|
unsigned long event, void *ptr)
|
|
|
|
|
{
|
|
|
|
|
struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
|
|
|
|
|
struct switchdev_notifier_fdb_info *fdb_info;
|
|
|
|
|
struct switchdev_notifier_info *info = ptr;
|
|
|
|
|
struct prestera_fdb_event_work *swdev_work;
|
|
|
|
|
struct net_device *upper;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
if (event == SWITCHDEV_PORT_ATTR_SET) {
|
|
|
|
|
err = switchdev_handle_port_attr_set(dev, ptr,
|
|
|
|
|
prestera_netdev_check,
|
|
|
|
|
prestera_port_obj_attr_set);
|
|
|
|
|
return notifier_from_errno(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!prestera_netdev_check(dev))
|
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
|
|
|
|
|
|
upper = netdev_master_upper_dev_get_rcu(dev);
|
|
|
|
|
if (!upper)
|
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
|
|
|
|
|
|
if (!netif_is_bridge_master(upper))
|
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
|
|
|
|
|
|
swdev_work = kzalloc(sizeof(*swdev_work), GFP_ATOMIC);
|
|
|
|
|
if (!swdev_work)
|
|
|
|
|
return NOTIFY_BAD;
|
|
|
|
|
|
|
|
|
|
swdev_work->event = event;
|
|
|
|
|
swdev_work->dev = dev;
|
|
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
|
case SWITCHDEV_FDB_ADD_TO_DEVICE:
|
|
|
|
|
case SWITCHDEV_FDB_DEL_TO_DEVICE:
|
|
|
|
|
fdb_info = container_of(info,
|
|
|
|
|
struct switchdev_notifier_fdb_info,
|
|
|
|
|
info);
|
|
|
|
|
|
|
|
|
|
INIT_WORK(&swdev_work->work, prestera_fdb_event_work);
|
|
|
|
|
memcpy(&swdev_work->fdb_info, ptr,
|
|
|
|
|
sizeof(swdev_work->fdb_info));
|
|
|
|
|
|
|
|
|
|
swdev_work->fdb_info.addr = kzalloc(ETH_ALEN, GFP_ATOMIC);
|
|
|
|
|
if (!swdev_work->fdb_info.addr)
|
|
|
|
|
goto out_bad;
|
|
|
|
|
|
|
|
|
|
ether_addr_copy((u8 *)swdev_work->fdb_info.addr,
|
|
|
|
|
fdb_info->addr);
|
|
|
|
|
dev_hold(dev);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
kfree(swdev_work);
|
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
queue_work(swdev_wq, &swdev_work->work);
|
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
|
|
|
|
|
|
out_bad:
|
|
|
|
|
kfree(swdev_work);
|
|
|
|
|
return NOTIFY_BAD;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
prestera_port_vlan_bridge_join(struct prestera_port_vlan *port_vlan,
|
|
|
|
|
struct prestera_bridge_port *br_port)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_port *port = port_vlan->port;
|
|
|
|
|
struct prestera_bridge_vlan *br_vlan;
|
|
|
|
|
u16 vid = port_vlan->vid;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
if (port_vlan->br_port)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
err = prestera_hw_port_flood_set(port, br_port->flags & BR_FLOOD);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
err = prestera_hw_port_learning_set(port, br_port->flags & BR_LEARNING);
|
|
|
|
|
if (err)
|
|
|
|
|
goto err_port_learning_set;
|
|
|
|
|
|
|
|
|
|
err = prestera_port_vid_stp_set(port, vid, br_port->stp_state);
|
|
|
|
|
if (err)
|
|
|
|
|
goto err_port_vid_stp_set;
|
|
|
|
|
|
|
|
|
|
br_vlan = prestera_bridge_vlan_by_vid(br_port, vid);
|
|
|
|
|
if (!br_vlan) {
|
|
|
|
|
br_vlan = prestera_bridge_vlan_create(br_port, vid);
|
|
|
|
|
if (!br_vlan) {
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
|
goto err_bridge_vlan_get;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list_add(&port_vlan->br_vlan_head, &br_vlan->port_vlan_list);
|
|
|
|
|
|
|
|
|
|
prestera_bridge_port_get(br_port);
|
|
|
|
|
port_vlan->br_port = br_port;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
err_bridge_vlan_get:
|
|
|
|
|
prestera_port_vid_stp_set(port, vid, BR_STATE_FORWARDING);
|
|
|
|
|
err_port_vid_stp_set:
|
|
|
|
|
prestera_hw_port_learning_set(port, false);
|
|
|
|
|
err_port_learning_set:
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
prestera_bridge_port_vlan_add(struct prestera_port *port,
|
|
|
|
|
struct prestera_bridge_port *br_port,
|
|
|
|
|
u16 vid, bool is_untagged, bool is_pvid,
|
|
|
|
|
struct netlink_ext_ack *extack)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_port_vlan *port_vlan;
|
|
|
|
|
u16 old_pvid = port->pvid;
|
|
|
|
|
u16 pvid;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
if (is_pvid)
|
|
|
|
|
pvid = vid;
|
|
|
|
|
else
|
|
|
|
|
pvid = port->pvid == vid ? 0 : port->pvid;
|
|
|
|
|
|
|
|
|
|
port_vlan = prestera_port_vlan_by_vid(port, vid);
|
|
|
|
|
if (port_vlan && port_vlan->br_port != br_port)
|
|
|
|
|
return -EEXIST;
|
|
|
|
|
|
|
|
|
|
if (!port_vlan) {
|
|
|
|
|
port_vlan = prestera_port_vlan_create(port, vid, is_untagged);
|
|
|
|
|
if (IS_ERR(port_vlan))
|
|
|
|
|
return PTR_ERR(port_vlan);
|
|
|
|
|
} else {
|
|
|
|
|
err = prestera_hw_vlan_port_set(port, vid, true, is_untagged);
|
|
|
|
|
if (err)
|
|
|
|
|
goto err_port_vlan_set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = prestera_port_pvid_set(port, pvid);
|
|
|
|
|
if (err)
|
|
|
|
|
goto err_port_pvid_set;
|
|
|
|
|
|
|
|
|
|
err = prestera_port_vlan_bridge_join(port_vlan, br_port);
|
|
|
|
|
if (err)
|
|
|
|
|
goto err_port_vlan_bridge_join;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
err_port_vlan_bridge_join:
|
|
|
|
|
prestera_port_pvid_set(port, old_pvid);
|
|
|
|
|
err_port_pvid_set:
|
|
|
|
|
prestera_hw_vlan_port_set(port, vid, false, false);
|
|
|
|
|
err_port_vlan_set:
|
|
|
|
|
prestera_port_vlan_destroy(port_vlan);
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
prestera_bridge_port_vlan_del(struct prestera_port *port,
|
|
|
|
|
struct prestera_bridge_port *br_port, u16 vid)
|
|
|
|
|
{
|
|
|
|
|
u16 pvid = port->pvid == vid ? 0 : port->pvid;
|
|
|
|
|
struct prestera_port_vlan *port_vlan;
|
|
|
|
|
|
|
|
|
|
port_vlan = prestera_port_vlan_by_vid(port, vid);
|
|
|
|
|
if (WARN_ON(!port_vlan))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
prestera_port_vlan_bridge_leave(port_vlan);
|
|
|
|
|
prestera_port_pvid_set(port, pvid);
|
|
|
|
|
prestera_port_vlan_destroy(port_vlan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int prestera_port_vlans_add(struct prestera_port *port,
|
|
|
|
|
const struct switchdev_obj_port_vlan *vlan,
|
|
|
|
|
struct netlink_ext_ack *extack)
|
|
|
|
|
{
|
|
|
|
|
bool flag_untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
|
|
|
|
|
bool flag_pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
|
|
|
|
|
struct net_device *dev = vlan->obj.orig_dev;
|
|
|
|
|
struct prestera_bridge_port *br_port;
|
|
|
|
|
struct prestera_switch *sw = port->sw;
|
|
|
|
|
struct prestera_bridge *bridge;
|
|
|
|
|
|
|
|
|
|
if (netif_is_bridge_master(dev))
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
br_port = prestera_bridge_port_by_dev(sw->swdev, dev);
|
|
|
|
|
if (WARN_ON(!br_port))
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
bridge = br_port->bridge;
|
|
|
|
|
if (!bridge->vlan_enabled)
|
|
|
|
|
return 0;
|
|
|
|
|
|
net: switchdev: remove vid_begin -> vid_end range from VLAN objects
The call path of a switchdev VLAN addition to the bridge looks something
like this today:
nbp_vlan_init
| __br_vlan_set_default_pvid
| | |
| | br_afspec |
| | | |
| | v |
| | br_process_vlan_info |
| | | |
| | v |
| | br_vlan_info |
| | / \ /
| | / \ /
| | / \ /
| | / \ /
v v v v v
nbp_vlan_add br_vlan_add ------+
| ^ ^ | |
| / | | |
| / / / |
\ br_vlan_get_master/ / v
\ ^ / / br_vlan_add_existing
\ | / / |
\ | / / /
\ | / / /
\ | / / /
\ | / / /
v | | v /
__vlan_add /
/ | /
/ | /
v | /
__vlan_vid_add | /
\ | /
v v v
br_switchdev_port_vlan_add
The ranges UAPI was introduced to the bridge in commit bdced7ef7838
("bridge: support for multiple vlans and vlan ranges in setlink and
dellink requests") (Jan 10 2015). But the VLAN ranges (parsed in br_afspec)
have always been passed one by one, through struct bridge_vlan_info
tmp_vinfo, to br_vlan_info. So the range never went too far in depth.
Then Scott Feldman introduced the switchdev_port_bridge_setlink function
in commit 47f8328bb1a4 ("switchdev: add new switchdev bridge setlink").
That marked the introduction of the SWITCHDEV_OBJ_PORT_VLAN, which made
full use of the range. But switchdev_port_bridge_setlink was called like
this:
br_setlink
-> br_afspec
-> switchdev_port_bridge_setlink
Basically, the switchdev and the bridge code were not tightly integrated.
Then commit 41c498b9359e ("bridge: restore br_setlink back to original")
came, and switchdev drivers were required to implement
.ndo_bridge_setlink = switchdev_port_bridge_setlink for a while.
In the meantime, commits such as 0944d6b5a2fa ("bridge: try switchdev op
first in __vlan_vid_add/del") finally made switchdev penetrate the
br_vlan_info() barrier and start to develop the call path we have today.
But remember, br_vlan_info() still receives VLANs one by one.
Then Arkadi Sharshevsky refactored the switchdev API in 2017 in commit
29ab586c3d83 ("net: switchdev: Remove bridge bypass support from
switchdev") so that drivers would not implement .ndo_bridge_setlink any
longer. The switchdev_port_bridge_setlink also got deleted.
This refactoring removed the parallel bridge_setlink implementation from
switchdev, and left the only switchdev VLAN objects to be the ones
offloaded from __vlan_vid_add (basically RX filtering) and __vlan_add
(the latter coming from commit 9c86ce2c1ae3 ("net: bridge: Notify about
bridge VLANs")).
That is to say, today the switchdev VLAN object ranges are not used in
the kernel. Refactoring the above call path is a bit complicated, when
the bridge VLAN call path is already a bit complicated.
Let's go off and finish the job of commit 29ab586c3d83 by deleting the
bogus iteration through the VLAN ranges from the drivers. Some aspects
of this feature never made too much sense in the first place. For
example, what is a range of VLANs all having the BRIDGE_VLAN_INFO_PVID
flag supposed to mean, when a port can obviously have a single pvid?
This particular configuration _is_ denied as of commit 6623c60dc28e
("bridge: vlan: enforce no pvid flag in vlan ranges"), but from an API
perspective, the driver still has to play pretend, and only offload the
vlan->vid_end as pvid. And the addition of a switchdev VLAN object can
modify the flags of another, completely unrelated, switchdev VLAN
object! (a VLAN that is PVID will invalidate the PVID flag from whatever
other VLAN had previously been offloaded with switchdev and had that
flag. Yet switchdev never notifies about that change, drivers are
supposed to guess).
Nonetheless, having a VLAN range in the API makes error handling look
scarier than it really is - unwinding on errors and all of that.
When in reality, no one really calls this API with more than one VLAN.
It is all unnecessary complexity.
And despite appearing pretentious (two-phase transactional model and
all), the switchdev API is really sloppy because the VLAN addition and
removal operations are not paired with one another (you can add a VLAN
100 times and delete it just once). The bridge notifies through
switchdev of a VLAN addition not only when the flags of an existing VLAN
change, but also when nothing changes. There are switchdev drivers out
there who don't like adding a VLAN that has already been added, and
those checks don't really belong at driver level. But the fact that the
API contains ranges is yet another factor that prevents this from being
addressed in the future.
Of the existing switchdev pieces of hardware, it appears that only
Mellanox Spectrum supports offloading more than one VLAN at a time,
through mlxsw_sp_port_vlan_set. I have kept that code internal to the
driver, because there is some more bookkeeping that makes use of it, but
I deleted it from the switchdev API. But since the switchdev support for
ranges has already been de facto deleted by a Mellanox employee and
nobody noticed for 4 years, I'm going to assume it's not a biggie.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com> # switchdev and mlxsw
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Kurt Kanzenbach <kurt@linutronix.de> # hellcreek
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2021-01-09 02:01:46 +02:00
|
|
|
return prestera_bridge_port_vlan_add(port, br_port,
|
2021-01-14 10:35:56 +02:00
|
|
|
vlan->vid, flag_untagged,
|
net: switchdev: remove vid_begin -> vid_end range from VLAN objects
The call path of a switchdev VLAN addition to the bridge looks something
like this today:
nbp_vlan_init
| __br_vlan_set_default_pvid
| | |
| | br_afspec |
| | | |
| | v |
| | br_process_vlan_info |
| | | |
| | v |
| | br_vlan_info |
| | / \ /
| | / \ /
| | / \ /
| | / \ /
v v v v v
nbp_vlan_add br_vlan_add ------+
| ^ ^ | |
| / | | |
| / / / |
\ br_vlan_get_master/ / v
\ ^ / / br_vlan_add_existing
\ | / / |
\ | / / /
\ | / / /
\ | / / /
\ | / / /
v | | v /
__vlan_add /
/ | /
/ | /
v | /
__vlan_vid_add | /
\ | /
v v v
br_switchdev_port_vlan_add
The ranges UAPI was introduced to the bridge in commit bdced7ef7838
("bridge: support for multiple vlans and vlan ranges in setlink and
dellink requests") (Jan 10 2015). But the VLAN ranges (parsed in br_afspec)
have always been passed one by one, through struct bridge_vlan_info
tmp_vinfo, to br_vlan_info. So the range never went too far in depth.
Then Scott Feldman introduced the switchdev_port_bridge_setlink function
in commit 47f8328bb1a4 ("switchdev: add new switchdev bridge setlink").
That marked the introduction of the SWITCHDEV_OBJ_PORT_VLAN, which made
full use of the range. But switchdev_port_bridge_setlink was called like
this:
br_setlink
-> br_afspec
-> switchdev_port_bridge_setlink
Basically, the switchdev and the bridge code were not tightly integrated.
Then commit 41c498b9359e ("bridge: restore br_setlink back to original")
came, and switchdev drivers were required to implement
.ndo_bridge_setlink = switchdev_port_bridge_setlink for a while.
In the meantime, commits such as 0944d6b5a2fa ("bridge: try switchdev op
first in __vlan_vid_add/del") finally made switchdev penetrate the
br_vlan_info() barrier and start to develop the call path we have today.
But remember, br_vlan_info() still receives VLANs one by one.
Then Arkadi Sharshevsky refactored the switchdev API in 2017 in commit
29ab586c3d83 ("net: switchdev: Remove bridge bypass support from
switchdev") so that drivers would not implement .ndo_bridge_setlink any
longer. The switchdev_port_bridge_setlink also got deleted.
This refactoring removed the parallel bridge_setlink implementation from
switchdev, and left the only switchdev VLAN objects to be the ones
offloaded from __vlan_vid_add (basically RX filtering) and __vlan_add
(the latter coming from commit 9c86ce2c1ae3 ("net: bridge: Notify about
bridge VLANs")).
That is to say, today the switchdev VLAN object ranges are not used in
the kernel. Refactoring the above call path is a bit complicated, when
the bridge VLAN call path is already a bit complicated.
Let's go off and finish the job of commit 29ab586c3d83 by deleting the
bogus iteration through the VLAN ranges from the drivers. Some aspects
of this feature never made too much sense in the first place. For
example, what is a range of VLANs all having the BRIDGE_VLAN_INFO_PVID
flag supposed to mean, when a port can obviously have a single pvid?
This particular configuration _is_ denied as of commit 6623c60dc28e
("bridge: vlan: enforce no pvid flag in vlan ranges"), but from an API
perspective, the driver still has to play pretend, and only offload the
vlan->vid_end as pvid. And the addition of a switchdev VLAN object can
modify the flags of another, completely unrelated, switchdev VLAN
object! (a VLAN that is PVID will invalidate the PVID flag from whatever
other VLAN had previously been offloaded with switchdev and had that
flag. Yet switchdev never notifies about that change, drivers are
supposed to guess).
Nonetheless, having a VLAN range in the API makes error handling look
scarier than it really is - unwinding on errors and all of that.
When in reality, no one really calls this API with more than one VLAN.
It is all unnecessary complexity.
And despite appearing pretentious (two-phase transactional model and
all), the switchdev API is really sloppy because the VLAN addition and
removal operations are not paired with one another (you can add a VLAN
100 times and delete it just once). The bridge notifies through
switchdev of a VLAN addition not only when the flags of an existing VLAN
change, but also when nothing changes. There are switchdev drivers out
there who don't like adding a VLAN that has already been added, and
those checks don't really belong at driver level. But the fact that the
API contains ranges is yet another factor that prevents this from being
addressed in the future.
Of the existing switchdev pieces of hardware, it appears that only
Mellanox Spectrum supports offloading more than one VLAN at a time,
through mlxsw_sp_port_vlan_set. I have kept that code internal to the
driver, because there is some more bookkeeping that makes use of it, but
I deleted it from the switchdev API. But since the switchdev support for
ranges has already been de facto deleted by a Mellanox employee and
nobody noticed for 4 years, I'm going to assume it's not a biggie.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com> # switchdev and mlxsw
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Kurt Kanzenbach <kurt@linutronix.de> # hellcreek
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2021-01-09 02:01:46 +02:00
|
|
|
flag_pvid, extack);
|
2020-09-16 19:31:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int prestera_port_obj_add(struct net_device *dev,
|
|
|
|
|
const struct switchdev_obj *obj,
|
|
|
|
|
struct netlink_ext_ack *extack)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_port *port = netdev_priv(dev);
|
|
|
|
|
const struct switchdev_obj_port_vlan *vlan;
|
|
|
|
|
|
|
|
|
|
switch (obj->id) {
|
|
|
|
|
case SWITCHDEV_OBJ_ID_PORT_VLAN:
|
|
|
|
|
vlan = SWITCHDEV_OBJ_PORT_VLAN(obj);
|
net: switchdev: remove the transaction structure from port object notifiers
Since the introduction of the switchdev API, port objects were
transmitted to drivers for offloading using a two-step transactional
model, with a prepare phase that was supposed to catch all errors, and a
commit phase that was supposed to never fail.
Some classes of failures can never be avoided, like hardware access, or
memory allocation. In the latter case, merely attempting to move the
memory allocation to the preparation phase makes it impossible to avoid
memory leaks, since commit 91cf8eceffc1 ("switchdev: Remove unused
transaction item queue") which has removed the unused mechanism of
passing on the allocated memory between one phase and another.
It is time we admit that separating the preparation from the commit
phase is something that is best left for the driver to decide, and not
something that should be baked into the API, especially since there are
no switchdev callers that depend on this.
This patch removes the struct switchdev_trans member from switchdev port
object notifier structures, and converts drivers to not look at this
member.
Where driver conversion is trivial (like in the case of the Marvell
Prestera driver, NXP DPAA2 switch, TI CPSW, and Rocker drivers), it is
done in this patch.
Where driver conversion needs more attention (DSA, Mellanox Spectrum),
the conversion is left for subsequent patches and here we only fake the
prepare/commit phases at a lower level, just not in the switchdev
notifier itself.
Where the code has a natural structure that is best left alone as a
preparation and a commit phase (as in the case of the Ocelot switch),
that structure is left in place, just made to not depend upon the
switchdev transactional model.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2021-01-09 02:01:48 +02:00
|
|
|
return prestera_port_vlans_add(port, vlan, extack);
|
2020-09-16 19:31:01 +03:00
|
|
|
default:
|
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int prestera_port_vlans_del(struct prestera_port *port,
|
|
|
|
|
const struct switchdev_obj_port_vlan *vlan)
|
|
|
|
|
{
|
|
|
|
|
struct net_device *dev = vlan->obj.orig_dev;
|
|
|
|
|
struct prestera_bridge_port *br_port;
|
|
|
|
|
struct prestera_switch *sw = port->sw;
|
|
|
|
|
|
|
|
|
|
if (netif_is_bridge_master(dev))
|
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
|
|
br_port = prestera_bridge_port_by_dev(sw->swdev, dev);
|
|
|
|
|
if (WARN_ON(!br_port))
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
if (!br_port->bridge->vlan_enabled)
|
|
|
|
|
return 0;
|
|
|
|
|
|
net: switchdev: remove vid_begin -> vid_end range from VLAN objects
The call path of a switchdev VLAN addition to the bridge looks something
like this today:
nbp_vlan_init
| __br_vlan_set_default_pvid
| | |
| | br_afspec |
| | | |
| | v |
| | br_process_vlan_info |
| | | |
| | v |
| | br_vlan_info |
| | / \ /
| | / \ /
| | / \ /
| | / \ /
v v v v v
nbp_vlan_add br_vlan_add ------+
| ^ ^ | |
| / | | |
| / / / |
\ br_vlan_get_master/ / v
\ ^ / / br_vlan_add_existing
\ | / / |
\ | / / /
\ | / / /
\ | / / /
\ | / / /
v | | v /
__vlan_add /
/ | /
/ | /
v | /
__vlan_vid_add | /
\ | /
v v v
br_switchdev_port_vlan_add
The ranges UAPI was introduced to the bridge in commit bdced7ef7838
("bridge: support for multiple vlans and vlan ranges in setlink and
dellink requests") (Jan 10 2015). But the VLAN ranges (parsed in br_afspec)
have always been passed one by one, through struct bridge_vlan_info
tmp_vinfo, to br_vlan_info. So the range never went too far in depth.
Then Scott Feldman introduced the switchdev_port_bridge_setlink function
in commit 47f8328bb1a4 ("switchdev: add new switchdev bridge setlink").
That marked the introduction of the SWITCHDEV_OBJ_PORT_VLAN, which made
full use of the range. But switchdev_port_bridge_setlink was called like
this:
br_setlink
-> br_afspec
-> switchdev_port_bridge_setlink
Basically, the switchdev and the bridge code were not tightly integrated.
Then commit 41c498b9359e ("bridge: restore br_setlink back to original")
came, and switchdev drivers were required to implement
.ndo_bridge_setlink = switchdev_port_bridge_setlink for a while.
In the meantime, commits such as 0944d6b5a2fa ("bridge: try switchdev op
first in __vlan_vid_add/del") finally made switchdev penetrate the
br_vlan_info() barrier and start to develop the call path we have today.
But remember, br_vlan_info() still receives VLANs one by one.
Then Arkadi Sharshevsky refactored the switchdev API in 2017 in commit
29ab586c3d83 ("net: switchdev: Remove bridge bypass support from
switchdev") so that drivers would not implement .ndo_bridge_setlink any
longer. The switchdev_port_bridge_setlink also got deleted.
This refactoring removed the parallel bridge_setlink implementation from
switchdev, and left the only switchdev VLAN objects to be the ones
offloaded from __vlan_vid_add (basically RX filtering) and __vlan_add
(the latter coming from commit 9c86ce2c1ae3 ("net: bridge: Notify about
bridge VLANs")).
That is to say, today the switchdev VLAN object ranges are not used in
the kernel. Refactoring the above call path is a bit complicated, when
the bridge VLAN call path is already a bit complicated.
Let's go off and finish the job of commit 29ab586c3d83 by deleting the
bogus iteration through the VLAN ranges from the drivers. Some aspects
of this feature never made too much sense in the first place. For
example, what is a range of VLANs all having the BRIDGE_VLAN_INFO_PVID
flag supposed to mean, when a port can obviously have a single pvid?
This particular configuration _is_ denied as of commit 6623c60dc28e
("bridge: vlan: enforce no pvid flag in vlan ranges"), but from an API
perspective, the driver still has to play pretend, and only offload the
vlan->vid_end as pvid. And the addition of a switchdev VLAN object can
modify the flags of another, completely unrelated, switchdev VLAN
object! (a VLAN that is PVID will invalidate the PVID flag from whatever
other VLAN had previously been offloaded with switchdev and had that
flag. Yet switchdev never notifies about that change, drivers are
supposed to guess).
Nonetheless, having a VLAN range in the API makes error handling look
scarier than it really is - unwinding on errors and all of that.
When in reality, no one really calls this API with more than one VLAN.
It is all unnecessary complexity.
And despite appearing pretentious (two-phase transactional model and
all), the switchdev API is really sloppy because the VLAN addition and
removal operations are not paired with one another (you can add a VLAN
100 times and delete it just once). The bridge notifies through
switchdev of a VLAN addition not only when the flags of an existing VLAN
change, but also when nothing changes. There are switchdev drivers out
there who don't like adding a VLAN that has already been added, and
those checks don't really belong at driver level. But the fact that the
API contains ranges is yet another factor that prevents this from being
addressed in the future.
Of the existing switchdev pieces of hardware, it appears that only
Mellanox Spectrum supports offloading more than one VLAN at a time,
through mlxsw_sp_port_vlan_set. I have kept that code internal to the
driver, because there is some more bookkeeping that makes use of it, but
I deleted it from the switchdev API. But since the switchdev support for
ranges has already been de facto deleted by a Mellanox employee and
nobody noticed for 4 years, I'm going to assume it's not a biggie.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com> # switchdev and mlxsw
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Kurt Kanzenbach <kurt@linutronix.de> # hellcreek
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2021-01-09 02:01:46 +02:00
|
|
|
prestera_bridge_port_vlan_del(port, br_port, vlan->vid);
|
2020-09-16 19:31:01 +03:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int prestera_port_obj_del(struct net_device *dev,
|
|
|
|
|
const struct switchdev_obj *obj)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_port *port = netdev_priv(dev);
|
|
|
|
|
|
|
|
|
|
switch (obj->id) {
|
|
|
|
|
case SWITCHDEV_OBJ_ID_PORT_VLAN:
|
|
|
|
|
return prestera_port_vlans_del(port, SWITCHDEV_OBJ_PORT_VLAN(obj));
|
|
|
|
|
default:
|
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int prestera_switchdev_blk_event(struct notifier_block *unused,
|
|
|
|
|
unsigned long event, void *ptr)
|
|
|
|
|
{
|
|
|
|
|
struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
|
case SWITCHDEV_PORT_OBJ_ADD:
|
|
|
|
|
err = switchdev_handle_port_obj_add(dev, ptr,
|
|
|
|
|
prestera_netdev_check,
|
|
|
|
|
prestera_port_obj_add);
|
|
|
|
|
break;
|
|
|
|
|
case SWITCHDEV_PORT_OBJ_DEL:
|
|
|
|
|
err = switchdev_handle_port_obj_del(dev, ptr,
|
|
|
|
|
prestera_netdev_check,
|
|
|
|
|
prestera_port_obj_del);
|
|
|
|
|
break;
|
|
|
|
|
case SWITCHDEV_PORT_ATTR_SET:
|
|
|
|
|
err = switchdev_handle_port_attr_set(dev, ptr,
|
|
|
|
|
prestera_netdev_check,
|
|
|
|
|
prestera_port_obj_attr_set);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
err = -EOPNOTSUPP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return notifier_from_errno(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void prestera_fdb_event(struct prestera_switch *sw,
|
|
|
|
|
struct prestera_event *evt, void *arg)
|
|
|
|
|
{
|
|
|
|
|
struct switchdev_notifier_fdb_info info;
|
|
|
|
|
struct prestera_port *port;
|
|
|
|
|
|
|
|
|
|
port = prestera_find_port(sw, evt->fdb_evt.port_id);
|
|
|
|
|
if (!port)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
info.addr = evt->fdb_evt.data.mac;
|
|
|
|
|
info.vid = evt->fdb_evt.vid;
|
|
|
|
|
info.offloaded = true;
|
|
|
|
|
|
|
|
|
|
rtnl_lock();
|
|
|
|
|
|
|
|
|
|
switch (evt->id) {
|
|
|
|
|
case PRESTERA_FDB_EVENT_LEARNED:
|
|
|
|
|
call_switchdev_notifiers(SWITCHDEV_FDB_ADD_TO_BRIDGE,
|
|
|
|
|
port->dev, &info.info, NULL);
|
|
|
|
|
break;
|
|
|
|
|
case PRESTERA_FDB_EVENT_AGED:
|
|
|
|
|
call_switchdev_notifiers(SWITCHDEV_FDB_DEL_TO_BRIDGE,
|
|
|
|
|
port->dev, &info.info, NULL);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rtnl_unlock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int prestera_fdb_init(struct prestera_switch *sw)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
err = prestera_hw_event_handler_register(sw, PRESTERA_EVENT_TYPE_FDB,
|
|
|
|
|
prestera_fdb_event, NULL);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
err = prestera_hw_switch_ageing_set(sw, PRESTERA_DEFAULT_AGEING_TIME_MS);
|
|
|
|
|
if (err)
|
|
|
|
|
goto err_ageing_set;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
err_ageing_set:
|
|
|
|
|
prestera_hw_event_handler_unregister(sw, PRESTERA_EVENT_TYPE_FDB,
|
|
|
|
|
prestera_fdb_event);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void prestera_fdb_fini(struct prestera_switch *sw)
|
|
|
|
|
{
|
|
|
|
|
prestera_hw_event_handler_unregister(sw, PRESTERA_EVENT_TYPE_FDB,
|
|
|
|
|
prestera_fdb_event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int prestera_switchdev_handler_init(struct prestera_switchdev *swdev)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
swdev->swdev_nb.notifier_call = prestera_switchdev_event;
|
|
|
|
|
err = register_switchdev_notifier(&swdev->swdev_nb);
|
|
|
|
|
if (err)
|
|
|
|
|
goto err_register_swdev_notifier;
|
|
|
|
|
|
|
|
|
|
swdev->swdev_nb_blk.notifier_call = prestera_switchdev_blk_event;
|
|
|
|
|
err = register_switchdev_blocking_notifier(&swdev->swdev_nb_blk);
|
|
|
|
|
if (err)
|
|
|
|
|
goto err_register_blk_swdev_notifier;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
err_register_blk_swdev_notifier:
|
|
|
|
|
unregister_switchdev_notifier(&swdev->swdev_nb);
|
|
|
|
|
err_register_swdev_notifier:
|
|
|
|
|
destroy_workqueue(swdev_wq);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void prestera_switchdev_handler_fini(struct prestera_switchdev *swdev)
|
|
|
|
|
{
|
|
|
|
|
unregister_switchdev_blocking_notifier(&swdev->swdev_nb_blk);
|
|
|
|
|
unregister_switchdev_notifier(&swdev->swdev_nb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int prestera_switchdev_init(struct prestera_switch *sw)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_switchdev *swdev;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
swdev = kzalloc(sizeof(*swdev), GFP_KERNEL);
|
|
|
|
|
if (!swdev)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
|
|
sw->swdev = swdev;
|
|
|
|
|
swdev->sw = sw;
|
|
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&swdev->bridge_list);
|
|
|
|
|
|
|
|
|
|
swdev_wq = alloc_ordered_workqueue("%s_ordered", 0, "prestera_br");
|
|
|
|
|
if (!swdev_wq) {
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
|
goto err_alloc_wq;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = prestera_switchdev_handler_init(swdev);
|
|
|
|
|
if (err)
|
|
|
|
|
goto err_swdev_init;
|
|
|
|
|
|
|
|
|
|
err = prestera_fdb_init(sw);
|
|
|
|
|
if (err)
|
|
|
|
|
goto err_fdb_init;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
err_fdb_init:
|
|
|
|
|
err_swdev_init:
|
|
|
|
|
destroy_workqueue(swdev_wq);
|
|
|
|
|
err_alloc_wq:
|
|
|
|
|
kfree(swdev);
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void prestera_switchdev_fini(struct prestera_switch *sw)
|
|
|
|
|
{
|
|
|
|
|
struct prestera_switchdev *swdev = sw->swdev;
|
|
|
|
|
|
|
|
|
|
prestera_fdb_fini(sw);
|
|
|
|
|
prestera_switchdev_handler_fini(swdev);
|
|
|
|
|
destroy_workqueue(swdev_wq);
|
|
|
|
|
kfree(swdev);
|
|
|
|
|
}
|