Merge branch 'Multicast-improvement-in-Ocelot-and-Felix-drivers'
Vladimir Oltean says: ==================== Multicast improvement in Ocelot and Felix drivers This series makes some basic multicast forwarding functionality work for Felix DSA and for Ocelot switchdev. IGMP/MLD snooping in Felix is still missing, and there are other improvements to be made in the general area of multicast address filtering towards the CPU, but let's get these hardware-specific fixes out of the way first. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
commit
864cefeea0
|
@ -59,6 +59,29 @@ static int felix_fdb_del(struct dsa_switch *ds, int port,
|
|||
return ocelot_fdb_del(ocelot, port, addr, vid);
|
||||
}
|
||||
|
||||
/* This callback needs to be present */
|
||||
static int felix_mdb_prepare(struct dsa_switch *ds, int port,
|
||||
const struct switchdev_obj_port_mdb *mdb)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void felix_mdb_add(struct dsa_switch *ds, int port,
|
||||
const struct switchdev_obj_port_mdb *mdb)
|
||||
{
|
||||
struct ocelot *ocelot = ds->priv;
|
||||
|
||||
ocelot_port_mdb_add(ocelot, port, mdb);
|
||||
}
|
||||
|
||||
static int felix_mdb_del(struct dsa_switch *ds, int port,
|
||||
const struct switchdev_obj_port_mdb *mdb)
|
||||
{
|
||||
struct ocelot *ocelot = ds->priv;
|
||||
|
||||
return ocelot_port_mdb_del(ocelot, port, mdb);
|
||||
}
|
||||
|
||||
static void felix_bridge_stp_state_set(struct dsa_switch *ds, int port,
|
||||
u8 state)
|
||||
{
|
||||
|
@ -771,6 +794,9 @@ static const struct dsa_switch_ops felix_switch_ops = {
|
|||
.port_fdb_dump = felix_fdb_dump,
|
||||
.port_fdb_add = felix_fdb_add,
|
||||
.port_fdb_del = felix_fdb_del,
|
||||
.port_mdb_prepare = felix_mdb_prepare,
|
||||
.port_mdb_add = felix_mdb_add,
|
||||
.port_mdb_del = felix_mdb_del,
|
||||
.port_bridge_join = felix_bridge_join,
|
||||
.port_bridge_leave = felix_bridge_leave,
|
||||
.port_stp_state_set = felix_bridge_stp_state_set,
|
||||
|
|
|
@ -535,6 +535,10 @@ int ocelot_fdb_add(struct ocelot *ocelot, int port,
|
|||
const unsigned char *addr, u16 vid)
|
||||
{
|
||||
struct ocelot_port *ocelot_port = ocelot->ports[port];
|
||||
int pgid = port;
|
||||
|
||||
if (port == ocelot->npi)
|
||||
pgid = PGID_CPU;
|
||||
|
||||
if (!vid) {
|
||||
if (!ocelot_port->vlan_aware)
|
||||
|
@ -550,7 +554,7 @@ int ocelot_fdb_add(struct ocelot *ocelot, int port,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
return ocelot_mact_learn(ocelot, port, addr, vid, ENTRYTYPE_LOCKED);
|
||||
return ocelot_mact_learn(ocelot, pgid, addr, vid, ENTRYTYPE_LOCKED);
|
||||
}
|
||||
EXPORT_SYMBOL(ocelot_fdb_add);
|
||||
|
||||
|
@ -940,63 +944,128 @@ static struct ocelot_multicast *ocelot_multicast_get(struct ocelot *ocelot,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int ocelot_port_obj_add_mdb(struct net_device *dev,
|
||||
const struct switchdev_obj_port_mdb *mdb,
|
||||
struct switchdev_trans *trans)
|
||||
static enum macaccess_entry_type ocelot_classify_mdb(const unsigned char *addr)
|
||||
{
|
||||
struct ocelot_port_private *priv = netdev_priv(dev);
|
||||
struct ocelot_port *ocelot_port = &priv->port;
|
||||
struct ocelot *ocelot = ocelot_port->ocelot;
|
||||
if (addr[0] == 0x01 && addr[1] == 0x00 && addr[2] == 0x5e)
|
||||
return ENTRYTYPE_MACv4;
|
||||
if (addr[0] == 0x33 && addr[1] == 0x33)
|
||||
return ENTRYTYPE_MACv6;
|
||||
return ENTRYTYPE_NORMAL;
|
||||
}
|
||||
|
||||
static int ocelot_mdb_get_pgid(struct ocelot *ocelot,
|
||||
enum macaccess_entry_type entry_type)
|
||||
{
|
||||
int pgid;
|
||||
|
||||
/* According to VSC7514 datasheet 3.9.1.5 IPv4 Multicast Entries and
|
||||
* 3.9.1.6 IPv6 Multicast Entries, "Instead of a lookup in the
|
||||
* destination mask table (PGID), the destination set is programmed as
|
||||
* part of the entry MAC address.", and the DEST_IDX is set to 0.
|
||||
*/
|
||||
if (entry_type == ENTRYTYPE_MACv4 ||
|
||||
entry_type == ENTRYTYPE_MACv6)
|
||||
return 0;
|
||||
|
||||
for_each_nonreserved_multicast_dest_pgid(ocelot, pgid) {
|
||||
struct ocelot_multicast *mc;
|
||||
bool used = false;
|
||||
|
||||
list_for_each_entry(mc, &ocelot->multicast, list) {
|
||||
if (mc->pgid == pgid) {
|
||||
used = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!used)
|
||||
return pgid;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void ocelot_encode_ports_to_mdb(unsigned char *addr,
|
||||
struct ocelot_multicast *mc,
|
||||
enum macaccess_entry_type entry_type)
|
||||
{
|
||||
memcpy(addr, mc->addr, ETH_ALEN);
|
||||
|
||||
if (entry_type == ENTRYTYPE_MACv4) {
|
||||
addr[0] = 0;
|
||||
addr[1] = mc->ports >> 8;
|
||||
addr[2] = mc->ports & 0xff;
|
||||
} else if (entry_type == ENTRYTYPE_MACv6) {
|
||||
addr[0] = mc->ports >> 8;
|
||||
addr[1] = mc->ports & 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
int ocelot_port_mdb_add(struct ocelot *ocelot, int port,
|
||||
const struct switchdev_obj_port_mdb *mdb)
|
||||
{
|
||||
struct ocelot_port *ocelot_port = ocelot->ports[port];
|
||||
enum macaccess_entry_type entry_type;
|
||||
unsigned char addr[ETH_ALEN];
|
||||
struct ocelot_multicast *mc;
|
||||
int port = priv->chip_port;
|
||||
u16 vid = mdb->vid;
|
||||
bool new = false;
|
||||
|
||||
if (port == ocelot->npi)
|
||||
port = ocelot->num_phys_ports;
|
||||
|
||||
if (!vid)
|
||||
vid = ocelot_port->pvid;
|
||||
|
||||
entry_type = ocelot_classify_mdb(mdb->addr);
|
||||
|
||||
mc = ocelot_multicast_get(ocelot, mdb->addr, vid);
|
||||
if (!mc) {
|
||||
int pgid = ocelot_mdb_get_pgid(ocelot, entry_type);
|
||||
|
||||
if (pgid < 0) {
|
||||
dev_err(ocelot->dev,
|
||||
"No more PGIDs available for mdb %pM vid %d\n",
|
||||
mdb->addr, vid);
|
||||
return -ENOSPC;
|
||||
}
|
||||
|
||||
mc = devm_kzalloc(ocelot->dev, sizeof(*mc), GFP_KERNEL);
|
||||
if (!mc)
|
||||
return -ENOMEM;
|
||||
|
||||
memcpy(mc->addr, mdb->addr, ETH_ALEN);
|
||||
mc->vid = vid;
|
||||
mc->pgid = pgid;
|
||||
|
||||
list_add_tail(&mc->list, &ocelot->multicast);
|
||||
new = true;
|
||||
}
|
||||
|
||||
memcpy(addr, mc->addr, ETH_ALEN);
|
||||
addr[0] = 0;
|
||||
|
||||
if (!new) {
|
||||
addr[2] = mc->ports << 0;
|
||||
addr[1] = mc->ports << 8;
|
||||
ocelot_encode_ports_to_mdb(addr, mc, entry_type);
|
||||
ocelot_mact_forget(ocelot, addr, vid);
|
||||
}
|
||||
|
||||
mc->ports |= BIT(port);
|
||||
addr[2] = mc->ports << 0;
|
||||
addr[1] = mc->ports << 8;
|
||||
ocelot_encode_ports_to_mdb(addr, mc, entry_type);
|
||||
|
||||
return ocelot_mact_learn(ocelot, 0, addr, vid, ENTRYTYPE_MACv4);
|
||||
return ocelot_mact_learn(ocelot, mc->pgid, addr, vid, entry_type);
|
||||
}
|
||||
EXPORT_SYMBOL(ocelot_port_obj_add_mdb);
|
||||
EXPORT_SYMBOL(ocelot_port_mdb_add);
|
||||
|
||||
int ocelot_port_obj_del_mdb(struct net_device *dev,
|
||||
const struct switchdev_obj_port_mdb *mdb)
|
||||
int ocelot_port_mdb_del(struct ocelot *ocelot, int port,
|
||||
const struct switchdev_obj_port_mdb *mdb)
|
||||
{
|
||||
struct ocelot_port_private *priv = netdev_priv(dev);
|
||||
struct ocelot_port *ocelot_port = &priv->port;
|
||||
struct ocelot *ocelot = ocelot_port->ocelot;
|
||||
struct ocelot_port *ocelot_port = ocelot->ports[port];
|
||||
enum macaccess_entry_type entry_type;
|
||||
unsigned char addr[ETH_ALEN];
|
||||
struct ocelot_multicast *mc;
|
||||
int port = priv->chip_port;
|
||||
u16 vid = mdb->vid;
|
||||
|
||||
if (port == ocelot->npi)
|
||||
port = ocelot->num_phys_ports;
|
||||
|
||||
if (!vid)
|
||||
vid = ocelot_port->pvid;
|
||||
|
||||
|
@ -1004,10 +1073,9 @@ int ocelot_port_obj_del_mdb(struct net_device *dev,
|
|||
if (!mc)
|
||||
return -ENOENT;
|
||||
|
||||
memcpy(addr, mc->addr, ETH_ALEN);
|
||||
addr[2] = mc->ports << 0;
|
||||
addr[1] = mc->ports << 8;
|
||||
addr[0] = 0;
|
||||
entry_type = ocelot_classify_mdb(mdb->addr);
|
||||
|
||||
ocelot_encode_ports_to_mdb(addr, mc, entry_type);
|
||||
ocelot_mact_forget(ocelot, addr, vid);
|
||||
|
||||
mc->ports &= ~BIT(port);
|
||||
|
@ -1017,12 +1085,11 @@ int ocelot_port_obj_del_mdb(struct net_device *dev,
|
|||
return 0;
|
||||
}
|
||||
|
||||
addr[2] = mc->ports << 0;
|
||||
addr[1] = mc->ports << 8;
|
||||
ocelot_encode_ports_to_mdb(addr, mc, entry_type);
|
||||
|
||||
return ocelot_mact_learn(ocelot, 0, addr, vid, ENTRYTYPE_MACv4);
|
||||
return ocelot_mact_learn(ocelot, mc->pgid, addr, vid, entry_type);
|
||||
}
|
||||
EXPORT_SYMBOL(ocelot_port_obj_del_mdb);
|
||||
EXPORT_SYMBOL(ocelot_port_mdb_del);
|
||||
|
||||
int ocelot_port_bridge_join(struct ocelot *ocelot, int port,
|
||||
struct net_device *bridge)
|
||||
|
@ -1061,10 +1128,10 @@ static void ocelot_set_aggr_pgids(struct ocelot *ocelot)
|
|||
int i, port, lag;
|
||||
|
||||
/* Reset destination and aggregation PGIDS */
|
||||
for (port = 0; port < ocelot->num_phys_ports; port++)
|
||||
for_each_unicast_dest_pgid(ocelot, port)
|
||||
ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, port);
|
||||
|
||||
for (i = PGID_AGGR; i < PGID_SRC; i++)
|
||||
for_each_aggr_pgid(ocelot, i)
|
||||
ocelot_write_rix(ocelot, GENMASK(ocelot->num_phys_ports - 1, 0),
|
||||
ANA_PGID_PGID, i);
|
||||
|
||||
|
@ -1086,7 +1153,7 @@ static void ocelot_set_aggr_pgids(struct ocelot *ocelot)
|
|||
aggr_count++;
|
||||
}
|
||||
|
||||
for (i = PGID_AGGR; i < PGID_SRC; i++) {
|
||||
for_each_aggr_pgid(ocelot, i) {
|
||||
u32 ac;
|
||||
|
||||
ac = ocelot_read_rix(ocelot, ANA_PGID_PGID, i);
|
||||
|
@ -1448,7 +1515,7 @@ int ocelot_init(struct ocelot *ocelot)
|
|||
}
|
||||
|
||||
/* Allow broadcast MAC frames. */
|
||||
for (i = ocelot->num_phys_ports + 1; i < PGID_CPU; i++) {
|
||||
for_each_nonreserved_multicast_dest_pgid(ocelot, i) {
|
||||
u32 val = ANA_PGID_PGID_PGID(GENMASK(ocelot->num_phys_ports - 1, 0));
|
||||
|
||||
ocelot_write_rix(ocelot, val, ANA_PGID_PGID, i);
|
||||
|
|
|
@ -46,6 +46,7 @@ struct ocelot_multicast {
|
|||
unsigned char addr[ETH_ALEN];
|
||||
u16 vid;
|
||||
u16 ports;
|
||||
int pgid;
|
||||
};
|
||||
|
||||
struct ocelot_port_tc {
|
||||
|
@ -97,11 +98,6 @@ int ocelot_port_lag_join(struct ocelot *ocelot, int port,
|
|||
struct net_device *bond);
|
||||
void ocelot_port_lag_leave(struct ocelot *ocelot, int port,
|
||||
struct net_device *bond);
|
||||
int ocelot_port_obj_del_mdb(struct net_device *dev,
|
||||
const struct switchdev_obj_port_mdb *mdb);
|
||||
int ocelot_port_obj_add_mdb(struct net_device *dev,
|
||||
const struct switchdev_obj_port_mdb *mdb,
|
||||
struct switchdev_trans *trans);
|
||||
|
||||
u32 ocelot_port_readl(struct ocelot_port *port, u32 reg);
|
||||
void ocelot_port_writel(struct ocelot_port *port, u32 val, u32 reg);
|
||||
|
|
|
@ -422,7 +422,7 @@ static void ocelot_set_rx_mode(struct net_device *dev)
|
|||
* forwarded to the CPU port.
|
||||
*/
|
||||
val = GENMASK(ocelot->num_phys_ports - 1, 0);
|
||||
for (i = ocelot->num_phys_ports + 1; i < PGID_CPU; i++)
|
||||
for_each_nonreserved_multicast_dest_pgid(ocelot, i)
|
||||
ocelot_write_rix(ocelot, val, ANA_PGID_PGID, i);
|
||||
|
||||
__dev_mc_sync(dev, ocelot_mc_sync, ocelot_mc_unsync);
|
||||
|
@ -795,6 +795,32 @@ static int ocelot_port_vlan_del_vlan(struct net_device *dev,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int ocelot_port_obj_add_mdb(struct net_device *dev,
|
||||
const struct switchdev_obj_port_mdb *mdb,
|
||||
struct switchdev_trans *trans)
|
||||
{
|
||||
struct ocelot_port_private *priv = netdev_priv(dev);
|
||||
struct ocelot_port *ocelot_port = &priv->port;
|
||||
struct ocelot *ocelot = ocelot_port->ocelot;
|
||||
int port = priv->chip_port;
|
||||
|
||||
if (switchdev_trans_ph_prepare(trans))
|
||||
return 0;
|
||||
|
||||
return ocelot_port_mdb_add(ocelot, port, mdb);
|
||||
}
|
||||
|
||||
static int ocelot_port_obj_del_mdb(struct net_device *dev,
|
||||
const struct switchdev_obj_port_mdb *mdb)
|
||||
{
|
||||
struct ocelot_port_private *priv = netdev_priv(dev);
|
||||
struct ocelot_port *ocelot_port = &priv->port;
|
||||
struct ocelot *ocelot = ocelot_port->ocelot;
|
||||
int port = priv->chip_port;
|
||||
|
||||
return ocelot_port_mdb_del(ocelot, port, mdb);
|
||||
}
|
||||
|
||||
static int ocelot_port_obj_add(struct net_device *dev,
|
||||
const struct switchdev_obj *obj,
|
||||
struct switchdev_trans *trans,
|
||||
|
|
|
@ -65,6 +65,21 @@
|
|||
#define PGID_MCIPV4 62
|
||||
#define PGID_MCIPV6 63
|
||||
|
||||
#define for_each_unicast_dest_pgid(ocelot, pgid) \
|
||||
for ((pgid) = 0; \
|
||||
(pgid) < (ocelot)->num_phys_ports; \
|
||||
(pgid)++)
|
||||
|
||||
#define for_each_nonreserved_multicast_dest_pgid(ocelot, pgid) \
|
||||
for ((pgid) = (ocelot)->num_phys_ports + 1; \
|
||||
(pgid) < PGID_CPU; \
|
||||
(pgid)++)
|
||||
|
||||
#define for_each_aggr_pgid(ocelot, pgid) \
|
||||
for ((pgid) = PGID_AGGR; \
|
||||
(pgid) < PGID_SRC; \
|
||||
(pgid)++)
|
||||
|
||||
/* Aggregation PGIDs, one per Link Aggregation Code */
|
||||
#define PGID_AGGR 64
|
||||
|
||||
|
@ -641,5 +656,9 @@ int ocelot_cls_flower_destroy(struct ocelot *ocelot, int port,
|
|||
struct flow_cls_offload *f, bool ingress);
|
||||
int ocelot_cls_flower_stats(struct ocelot *ocelot, int port,
|
||||
struct flow_cls_offload *f, bool ingress);
|
||||
int ocelot_port_mdb_add(struct ocelot *ocelot, int port,
|
||||
const struct switchdev_obj_port_mdb *mdb);
|
||||
int ocelot_port_mdb_del(struct ocelot *ocelot, int port,
|
||||
const struct switchdev_obj_port_mdb *mdb);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue