net: dsa: mv88e6xxx: add PCL support
Subsystems (4)
cover net: dsa: mv88e6xxx: add PCL support
This small series implements the ethtool RXNFC operations in the mv88e6xxx DSA driver to configure a port's Layer 2 Policy Control List (PCL) supported by models such as 88E6352 and 88E6390 and equivalent.
This allows to configure a port to discard frames based on a configured destination or source MAC address and an optional VLAN, with e.g.:
# ethtool --config-nfc lan1 flow-type ether src 00:11:22:33:44:55 action -1
Vivien Didelot (3):
net: dsa: mv88e6xxx: complete ATU state definitions
net: dsa: mv88e6xxx: introduce .port_set_policy
net: dsa: mv88e6xxx: add RXNFC support
drivers/net/dsa/mv88e6xxx/chip.c | 241 ++++++++++++++++++++++-- drivers/net/dsa/mv88e6xxx/chip.h | 35 ++++ drivers/net/dsa/mv88e6xxx/global1.h | 43 +++-- drivers/net/dsa/mv88e6xxx/global1_atu.c | 6 +- drivers/net/dsa/mv88e6xxx/port.c | 74 ++++++++ drivers/net/dsa/mv88e6xxx/port.h | 17 +- 6 files changed, 388 insertions(+), 28 deletions(-)
Signature · 1 line
2.23.0
PATCH 1/3 net: dsa: mv88e6xxx: complete ATU state definitions
Marvell has different values for the state of a MAC address, depending on its multicast bit. This patch completes the definitions for these states.
At the same time, use 0 which is intuitive enough and simplifies the code a bit, instead of the UC or MC unused value.
--- drivers/net/dsa/mv88e6xxx/chip.c | 19 +++++------ drivers/net/dsa/mv88e6xxx/global1.h | 43 +++++++++++++++++-------- drivers/net/dsa/mv88e6xxx/global1_atu.c | 6 ++-- 3 files changed, 41 insertions(+), 27 deletions(-)
drivers/net/dsa/mv88e6xxx/chip.c +8 -11
@@ -1497,7 +1497,7 @@ static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port, fid = vlan.fid; } - entry.state =MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ; + entry.state =0 ;ether_addr_copy (entry.mac, addr);eth_addr_dec (entry.mac);
@@ -1506,17 +1506,16 @@ static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,return err;/* Initialize a fresh ATU entry if it isn't found */ -if (entry.state ==MV88E6XXX_G1_ATU_DATA_STATE_UNUSED || - !ether_addr_equal (entry.mac, addr)) { +if (!entry.state || !ether_addr_equal (entry.mac, addr)) {memset (&entry,0 ,sizeof (entry));ether_addr_copy (entry.mac, addr); }/* Purge the ATU entry only if no port is using it anymore */ -if (state ==MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ) { +if (!state) { entry.portvec &= ~BIT (port);if (!entry.portvec) - entry.state =MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ; + entry.state =0 ; }else { entry.portvec |=BIT (port); entry.state = state;
@@ -1732,8 +1731,7 @@ static int mv88e6xxx_port_fdb_del(struct dsa_switch *ds, int port,int err;mv88e6xxx_reg_lock (chip); - err =mv88e6xxx_port_db_load_purge (chip, port, addr, vid, -MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ); + err =mv88e6xxx_port_db_load_purge (chip, port, addr, vid,0 );mv88e6xxx_reg_unlock (chip);return err;
@@ -1747,7 +1745,7 @@ static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,bool is_static;int err; - addr.state =MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ; + addr.state =0 ;eth_broadcast_addr (addr.mac); do {
@@ -1755,7 +1753,7 @@ static int mv88e6xxx_port_db_dump_fid(struct mv88e6xxx_chip *chip,if (err)return err; -if (addr.state ==MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ) +if (!addr.state)break ;if (addr.trunk || (addr.portvec &BIT (port)) ==0 )
@@ -4690,8 +4688,7 @@ static int mv88e6xxx_port_mdb_del(struct dsa_switch *ds, int port,int err;mv88e6xxx_reg_lock (chip); - err =mv88e6xxx_port_db_load_purge (chip, port, mdb->addr, mdb->vid, -MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ); + err =mv88e6xxx_port_db_load_purge (chip, port, mdb->addr, mdb->vid,0 );mv88e6xxx_reg_unlock (chip);return err;
drivers/net/dsa/mv88e6xxx/global1.h +30 -13
49 lines not on this page · raw message
drivers/net/dsa/mv88e6xxx/global1_atu.c +3 -3
@@ -135,7 +135,7 @@ static int mv88e6xxx_g1_atu_data_read(struct mv88e6xxx_chip *chip,return err; entry->state = val &0xf ; -if (entry->state !=MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ) { +if (entry->state) { entry->trunk = !!(val &MV88E6XXX_G1_ATU_DATA_TRUNK ); entry->portvec = (val >>4 ) &mv88e6xxx_port_mask (chip); }
@@ -148,7 +148,7 @@ static int mv88e6xxx_g1_atu_data_write(struct mv88e6xxx_chip *chip, {u16 data = entry->state &0xf ; -if (entry->state !=MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ) { +if (entry->state) {if (entry->trunk) data |=MV88E6XXX_G1_ATU_DATA_TRUNK ;
@@ -209,7 +209,7 @@ int mv88e6xxx_g1_atu_getnext(struct mv88e6xxx_chip *chip, u16 fid,return err;/* Write the MAC address to iterate from only once */ -if (entry->state ==MV88E6XXX_G1_ATU_DATA_STATE_UNUSED ) { +if (!entry->state) { err =mv88e6xxx_g1_atu_mac_write (chip, entry);if (err)return err;
Signature · 1 line
2.23.0
Re: [PATCH net-next 1/3] net: dsa: mv88e6xxx: complete ATU state definitions
Quoted 8 lines · Vivien Didelot
Marvell has different values for the state of a MAC address, depending on its multicast bit. This patch completes the definitions for these states.
At the same time, use 0 which is intuitive enough and simplifies the code a bit, instead of the UC or MC unused value.
Signed-off-by Vivien Didelot <[email protected]>
Andrew
PATCH 2/3 net: dsa: mv88e6xxx: introduce .port_set_policy
In reply to Vivien DidelotIntroduce a new .port_set_policy operation to configure a port's Policy Control List, based on mapping such as DA, SA, Etype and so on.
Models similar to 88E6352 and 88E6390 are supported at the moment.
--- drivers/net/dsa/mv88e6xxx/chip.c | 9 ++++ drivers/net/dsa/mv88e6xxx/chip.h | 22 ++++++++++ drivers/net/dsa/mv88e6xxx/port.c | 74 ++++++++++++++++++++++++++++++++ drivers/net/dsa/mv88e6xxx/port.h | 17 +++++++- 4 files changed, 121 insertions(+), 1 deletion(-)
drivers/net/dsa/mv88e6xxx/chip.c +9 -0
@@ -3132,6 +3132,7 @@ static const struct mv88e6xxx_ops mv88e6172_ops = { .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay, .port_set_speed = mv88e6352_port_set_speed, .port_tag_remap = mv88e6095_port_tag_remap, + .port_set_policy = mv88e6352_port_set_policy, .port_set_frame_mode = mv88e6351_port_set_frame_mode, .port_set_egress_floods = mv88e6352_port_set_egress_floods, .port_set_ether_type = mv88e6351_port_set_ether_type,
@@ -3218,6 +3219,7 @@ static const struct mv88e6xxx_ops mv88e6176_ops = { .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay, .port_set_speed = mv88e6352_port_set_speed, .port_tag_remap = mv88e6095_port_tag_remap, + .port_set_policy = mv88e6352_port_set_policy, .port_set_frame_mode = mv88e6351_port_set_frame_mode, .port_set_egress_floods = mv88e6352_port_set_egress_floods, .port_set_ether_type = mv88e6351_port_set_ether_type,
@@ -3303,6 +3305,7 @@ static const struct mv88e6xxx_ops mv88e6190_ops = { .port_set_speed = mv88e6390_port_set_speed, .port_max_speed_mode = mv88e6390_port_max_speed_mode, .port_tag_remap = mv88e6390_port_tag_remap, + .port_set_policy = mv88e6352_port_set_policy, .port_set_frame_mode = mv88e6351_port_set_frame_mode, .port_set_egress_floods = mv88e6352_port_set_egress_floods, .port_set_ether_type = mv88e6351_port_set_ether_type,
@@ -3351,6 +3354,7 @@ static const struct mv88e6xxx_ops mv88e6190x_ops = { .port_set_speed = mv88e6390x_port_set_speed, .port_max_speed_mode = mv88e6390x_port_max_speed_mode, .port_tag_remap = mv88e6390_port_tag_remap, + .port_set_policy = mv88e6352_port_set_policy, .port_set_frame_mode = mv88e6351_port_set_frame_mode, .port_set_egress_floods = mv88e6352_port_set_egress_floods, .port_set_ether_type = mv88e6351_port_set_ether_type,
@@ -3448,6 +3452,7 @@ static const struct mv88e6xxx_ops mv88e6240_ops = { .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay, .port_set_speed = mv88e6352_port_set_speed, .port_tag_remap = mv88e6095_port_tag_remap, + .port_set_policy = mv88e6352_port_set_policy, .port_set_frame_mode = mv88e6351_port_set_frame_mode, .port_set_egress_floods = mv88e6352_port_set_egress_floods, .port_set_ether_type = mv88e6351_port_set_ether_type,
@@ -3539,6 +3544,7 @@ static const struct mv88e6xxx_ops mv88e6290_ops = { .port_set_speed = mv88e6390_port_set_speed, .port_max_speed_mode = mv88e6390_port_max_speed_mode, .port_tag_remap = mv88e6390_port_tag_remap, + .port_set_policy = mv88e6352_port_set_policy, .port_set_frame_mode = mv88e6351_port_set_frame_mode, .port_set_egress_floods = mv88e6352_port_set_egress_floods, .port_set_ether_type = mv88e6351_port_set_ether_type,
@@ -3809,6 +3815,7 @@ static const struct mv88e6xxx_ops mv88e6352_ops = { .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay, .port_set_speed = mv88e6352_port_set_speed, .port_tag_remap = mv88e6095_port_tag_remap, + .port_set_policy = mv88e6352_port_set_policy, .port_set_frame_mode = mv88e6351_port_set_frame_mode, .port_set_egress_floods = mv88e6352_port_set_egress_floods, .port_set_ether_type = mv88e6351_port_set_ether_type,
@@ -3863,6 +3870,7 @@ static const struct mv88e6xxx_ops mv88e6390_ops = { .port_set_speed = mv88e6390_port_set_speed, .port_max_speed_mode = mv88e6390_port_max_speed_mode, .port_tag_remap = mv88e6390_port_tag_remap, + .port_set_policy = mv88e6352_port_set_policy, .port_set_frame_mode = mv88e6351_port_set_frame_mode, .port_set_egress_floods = mv88e6352_port_set_egress_floods, .port_set_ether_type = mv88e6351_port_set_ether_type,
@@ -3915,6 +3923,7 @@ static const struct mv88e6xxx_ops mv88e6390x_ops = { .port_set_speed = mv88e6390x_port_set_speed, .port_max_speed_mode = mv88e6390x_port_max_speed_mode, .port_tag_remap = mv88e6390_port_tag_remap, + .port_set_policy = mv88e6352_port_set_policy, .port_set_frame_mode = mv88e6351_port_set_frame_mode, .port_set_egress_floods = mv88e6352_port_set_egress_floods, .port_set_ether_type = mv88e6351_port_set_ether_type,
drivers/net/dsa/mv88e6xxx/chip.h +22 -0
@@ -189,6 +189,24 @@ struct mv88e6xxx_port_hwtstamp {struct hwtstamp_config tstamp_config; }; +enum mv88e6xxx_policy_mapping { +MV88E6XXX_POLICY_MAPPING_DA , +MV88E6XXX_POLICY_MAPPING_SA , +MV88E6XXX_POLICY_MAPPING_VTU , +MV88E6XXX_POLICY_MAPPING_ETYPE , +MV88E6XXX_POLICY_MAPPING_PPPOE , +MV88E6XXX_POLICY_MAPPING_VBAS , +MV88E6XXX_POLICY_MAPPING_OPT82 , +MV88E6XXX_POLICY_MAPPING_UDP , +}; + +enum mv88e6xxx_policy_action { +MV88E6XXX_POLICY_ACTION_NORMAL , +MV88E6XXX_POLICY_ACTION_MIRROR , +MV88E6XXX_POLICY_ACTION_TRAP , +MV88E6XXX_POLICY_ACTION_DISCARD , +}; +struct mv88e6xxx_port {struct mv88e6xxx_chip *chip;int port;
@@ -381,6 +399,10 @@ struct mv88e6xxx_ops {int (*port_tag_remap)(struct mv88e6xxx_chip *chip,int port); +int (*port_set_policy)(struct mv88e6xxx_chip *chip,int port, +enum mv88e6xxx_policy_mapping mapping, +enum mv88e6xxx_policy_action action); +int (*port_set_frame_mode)(struct mv88e6xxx_chip *chip,int port,enum mv88e6xxx_frame_mode mode); int (*port_set_egress_floods)(struct mv88e6xxx_chip *chip, int port,
drivers/net/dsa/mv88e6xxx/port.c +74 -0
77 lines not on this page · raw message
drivers/net/dsa/mv88e6xxx/port.h +16 -1
@@ -222,7 +222,19 @@#define MV88E6XXX_PORT_PRI_OVERRIDE 0x0d/* Offset 0x0E: Policy Control Register */ -#define MV88E6XXX_PORT_POLICY_CTL 0x0e +#define MV88E6XXX_PORT_POLICY_CTL 0x0e +#define MV88E6XXX_PORT_POLICY_CTL_DA_MASK 0xc000 +#define MV88E6XXX_PORT_POLICY_CTL_SA_MASK 0x3000 +#define MV88E6XXX_PORT_POLICY_CTL_VTU_MASK 0x0c00 +#define MV88E6XXX_PORT_POLICY_CTL_ETYPE_MASK 0x0300 +#define MV88E6XXX_PORT_POLICY_CTL_PPPOE_MASK 0x00c0 +#define MV88E6XXX_PORT_POLICY_CTL_VBAS_MASK 0x0030 +#define MV88E6XXX_PORT_POLICY_CTL_OPT82_MASK 0x000c +#define MV88E6XXX_PORT_POLICY_CTL_UDP_MASK 0x0003 +#define MV88E6XXX_PORT_POLICY_CTL_NORMAL 0x0000 +#define MV88E6XXX_PORT_POLICY_CTL_MIRROR 0x0001 +#define MV88E6XXX_PORT_POLICY_CTL_TRAP 0x0002 +#define MV88E6XXX_PORT_POLICY_CTL_DISCARD 0x0003/* Offset 0x0F: Port Special Ether Type */ #define MV88E6XXX_PORT_ETH_TYPE 0x0f
@@ -324,6 +336,9 @@ int mv88e6185_port_set_egress_floods(struct mv88e6xxx_chip *chip, int port, bool unicast, bool multicast);int mv88e6352_port_set_egress_floods (struct mv88e6xxx_chip *chip,int port,bool unicast,bool multicast); +int mv88e6352_port_set_policy (struct mv88e6xxx_chip *chip,int port, +enum mv88e6xxx_policy_mapping mapping, +enum mv88e6xxx_policy_action action);int mv88e6351_port_set_ether_type (struct mv88e6xxx_chip *chip,int port,u16 etype); int mv88e6xxx_port_set_message_port(struct mv88e6xxx_chip *chip, int port,
Signature · 1 line
2.23.0
Re: [PATCH net-next 2/3] net: dsa: mv88e6xxx: introduce .port_set_policy
Quoted 6 lines · Vivien Didelot
Introduce a new .port_set_policy operation to configure a port's Policy Control List, based on mapping such as DA, SA, Etype and so on.
Models similar to 88E6352 and 88E6390 are supported at the moment.
Signed-off-by Vivien Didelot <[email protected]>
Andrew
Re: [PATCH net-next 2/3] net: dsa: mv88e6xxx: introduce .port_set_policy
In reply to Vivien Didelotdrivers/net/dsa/mv88e6xxx/chip.c static const struct mv88e6xxx_ops mv88e6172_ops = { · line 3138
Quoted 8 lines · On Sat, 7 Sep 2019 16:00:48 -0400 Vivien Didelot <[email protected]>…
drivers/net/dsa/mv88e6xxx/chip.c +1
-0@@ -3132,6 +3132,7 @@ static const struct mv88e6xxx_ops mv88e6172_ops = { .port_set_rgmii_delay = mv88e6352_port_set_rgmii_delay, .port_set_speed = mv88e6352_port_set_speed, .port_tag_remap = mv88e6095_port_tag_remap, + .port_set_policy = mv88e6352_port_set_policy, .port_set_frame_mode = mv88e6351_port_set_frame_mode, .port_set_egress_floods = mv88e6352_port_set_egress_floods, .port_set_ether_type = mv88e6351_port_set_ether_type,
Topaz also supports this, 6141 and 6341.
PATCH 3/3 net: dsa: mv88e6xxx: add RXNFC support
In reply to Vivien DidelotImplement the .get_rxnfc and .set_rxnfc DSA operations to configure a port's Layer 2 Policy Control List (PCL) via ethtool.
Currently only dropping frames based on MAC Destination or Source Address (including the option VLAN parameter) is supported.
--- drivers/net/dsa/mv88e6xxx/chip.c | 213 +++++++++++++++++++++++++++++++ drivers/net/dsa/mv88e6xxx/chip.h | 13 ++ 2 files changed, 226 insertions(+)
drivers/net/dsa/mv88e6xxx/chip.c +213 -0
@@ -1524,6 +1524,216 @@ static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port,return mv88e6xxx_g1_atu_loadpurge (chip, fid, &entry); } +static int mv88e6xxx_policy_apply (struct mv88e6xxx_chip *chip,int port, +const struct mv88e6xxx_policy *policy) +{ +enum mv88e6xxx_policy_mapping mapping = policy->mapping; +enum mv88e6xxx_policy_action action = policy->action; +const u8 *addr = policy->addr; +u16 vid = policy->vid; +u8 state; +int err; +int id; + +if (!chip->info->ops->port_set_policy) +return -EOPNOTSUPP ; + +switch (mapping) { +case MV88E6XXX_POLICY_MAPPING_DA : +case MV88E6XXX_POLICY_MAPPING_SA : +if (action ==MV88E6XXX_POLICY_ACTION_NORMAL ) + state =0 ;/* Dissociate the port and address */ +else if (action ==MV88E6XXX_POLICY_ACTION_DISCARD && +is_multicast_ether_addr (addr)) + state =MV88E6XXX_G1_ATU_DATA_STATE_MC_STATIC_POLICY ; +else if (action ==MV88E6XXX_POLICY_ACTION_DISCARD && +is_unicast_ether_addr (addr)) + state =MV88E6XXX_G1_ATU_DATA_STATE_UC_STATIC_POLICY ; +else +return -EOPNOTSUPP ; + + err =mv88e6xxx_port_db_load_purge (chip, port, addr, vid, + state); +if (err) +return err; +break ; +default : +return -EOPNOTSUPP ; + } + +/* Skip the port's policy clearing if the mapping is still in use */ +if (action ==MV88E6XXX_POLICY_ACTION_NORMAL ) +idr_for_each_entry (&chip->policies, policy, id) +if (policy->port == port && + policy->mapping == mapping && + policy->action != action) +return 0 ; + +return chip->info->ops->port_set_policy (chip, port, mapping, action); +} + +static int mv88e6xxx_policy_insert (struct mv88e6xxx_chip *chip,int port, +struct ethtool_rx_flow_spec *fs) +{ +struct ethhdr *mac_entry = &fs->h_u.ether_spec; +struct ethhdr *mac_mask = &fs->m_u.ether_spec; +enum mv88e6xxx_policy_mapping mapping; +enum mv88e6xxx_policy_action action; +struct mv88e6xxx_policy *policy; +u16 vid =0 ; +u8 *addr; +int err; +int id; + +if (fs->location !=RX_CLS_LOC_ANY ) +return -EINVAL ; + +if (fs->ring_cookie ==RX_CLS_FLOW_DISC ) + action =MV88E6XXX_POLICY_ACTION_DISCARD ; +else +return -EOPNOTSUPP ; + +switch (fs->flow_type & ~FLOW_EXT ) { +case ETHER_FLOW : +if (!is_zero_ether_addr (mac_mask->h_dest) && +is_zero_ether_addr (mac_mask->h_source)) { + mapping =MV88E6XXX_POLICY_MAPPING_DA ; + addr = mac_entry->h_dest; + }else if (is_zero_ether_addr (mac_mask->h_dest) && + !is_zero_ether_addr (mac_mask->h_source)) { + mapping =MV88E6XXX_POLICY_MAPPING_SA ; + addr = mac_entry->h_source; + }else { +/* Cannot support DA and SA mapping in the same rule */ +return -EOPNOTSUPP ; + } +break ; +default : +return -EOPNOTSUPP ; + } + +if ((fs->flow_type &FLOW_EXT ) && fs->m_ext.vlan_tci) { +if (fs->m_ext.vlan_tci !=0xffff ) +return -EOPNOTSUPP ; + vid =be16_to_cpu (fs->h_ext.vlan_tci) &VLAN_VID_MASK ; + } + +idr_for_each_entry (&chip->policies, policy, id) { +if (policy->port == port && policy->mapping == mapping && + policy->action == action && policy->vid == vid && +ether_addr_equal (policy->addr, addr)) +return -EEXIST ; + } + + policy =devm_kzalloc (chip->dev,sizeof (*policy),GFP_KERNEL ); +if (!policy) +return -ENOMEM ; + + fs->location =0 ; + err =idr_alloc_u32 (&chip->policies, policy, &fs->location,0xffffffff , +GFP_KERNEL ); +if (err) { +devm_kfree (chip->dev, policy); +return err; + } + +memcpy (&policy->fs, fs,sizeof (*fs)); +ether_addr_copy (policy->addr, addr); + policy->mapping = mapping; + policy->action = action; + policy->port = port; + policy->vid = vid; + + err =mv88e6xxx_policy_apply (chip, port, policy); +if (err) { +idr_remove (&chip->policies, fs->location); +devm_kfree (chip->dev, policy); +return err; + } + +return 0 ; +} + +static int mv88e6xxx_get_rxnfc (struct dsa_switch *ds,int port, +struct ethtool_rxnfc *rxnfc,u32 *rule_locs) +{ +struct ethtool_rx_flow_spec *fs = &rxnfc->fs; +struct mv88e6xxx_chip *chip = ds->priv; +struct mv88e6xxx_policy *policy; +int err; +int id; + +mv88e6xxx_reg_lock (chip); + +switch (rxnfc->cmd) { +case ETHTOOL_GRXCLSRLCNT : + rxnfc->data =0 ; + rxnfc->data |=RX_CLS_LOC_SPECIAL ; + rxnfc->rule_cnt =0 ; +idr_for_each_entry (&chip->policies, policy, id) +if (policy->port == port) + rxnfc->rule_cnt++; + err =0 ; +break ; +case ETHTOOL_GRXCLSRULE : + err = -ENOENT ; + policy =idr_find (&chip->policies, fs->location); +if (policy) { +memcpy (fs, &policy->fs,sizeof (*fs)); + err =0 ; + } +break ; +case ETHTOOL_GRXCLSRLALL : + rxnfc->data =0 ; + rxnfc->rule_cnt =0 ; +idr_for_each_entry (&chip->policies, policy, id) +if (policy->port == port) + rule_locs[rxnfc->rule_cnt++] = id; + err =0 ; +break ; +default : + err = -EOPNOTSUPP ; +break ; + } + +mv88e6xxx_reg_unlock (chip); + +return err; +} + +static int mv88e6xxx_set_rxnfc (struct dsa_switch *ds,int port, +struct ethtool_rxnfc *rxnfc) +{ +struct ethtool_rx_flow_spec *fs = &rxnfc->fs; +struct mv88e6xxx_chip *chip = ds->priv; +struct mv88e6xxx_policy *policy; +int err; + +mv88e6xxx_reg_lock (chip); + +switch (rxnfc->cmd) { +case ETHTOOL_SRXCLSRLINS : + err =mv88e6xxx_policy_insert (chip, port, fs); +break ; +case ETHTOOL_SRXCLSRLDEL : + err = -ENOENT ; + policy =idr_remove (&chip->policies, fs->location); +if (policy) { + policy->action =MV88E6XXX_POLICY_ACTION_NORMAL ; + err =mv88e6xxx_policy_apply (chip, port, policy); +devm_kfree (chip->dev, policy); + } +break ; +default : + err = -EOPNOTSUPP ; +break ; + } + +mv88e6xxx_reg_unlock (chip); + +return err; +} +static int mv88e6xxx_port_add_broadcast (struct mv88e6xxx_chip *chip,int port,u16 vid) {
@@ -4655,6 +4865,7 @@ static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)mutex_init (&chip->reg_lock);INIT_LIST_HEAD (&chip->mdios); +idr_init (&chip->policies);return chip; }
@@ -4739,6 +4950,8 @@ static const struct dsa_switch_ops mv88e6xxx_switch_ops = { .set_eeprom = mv88e6xxx_set_eeprom, .get_regs_len = mv88e6xxx_get_regs_len, .get_regs = mv88e6xxx_get_regs, + .get_rxnfc = mv88e6xxx_get_rxnfc, + .set_rxnfc = mv88e6xxx_set_rxnfc, .set_ageing_time = mv88e6xxx_set_ageing_time, .port_bridge_join = mv88e6xxx_port_bridge_join, .port_bridge_leave = mv88e6xxx_port_bridge_leave,
drivers/net/dsa/mv88e6xxx/chip.h +13 -0
@@ -8,6 +8,7 @@#ifndef _MV88E6XXX_CHIP_H#define _MV88E6XXX_CHIP_H +#include <linux/idr.h> #include <linux/if_vlan.h> #include <linux/irq.h> #include <linux/gpio/consumer.h>
@@ -207,6 +208,15 @@ enum mv88e6xxx_policy_action { MV88E6XXX_POLICY_ACTION_DISCARD, }; +struct mv88e6xxx_policy { +enum mv88e6xxx_policy_mapping mapping; +enum mv88e6xxx_policy_action action; +struct ethtool_rx_flow_spec fs; +u8 addr[ETH_ALEN ]; +int port; +u16 vid; +}; +struct mv88e6xxx_port {struct mv88e6xxx_chip *chip;int port;
@@ -265,6 +275,9 @@ struct mv88e6xxx_chip {/* List of mdio busses */ struct list_head mdios; +/* Policy Control List IDs and rules */ +struct idr policies; +/* There can be two interrupt controllers, which are chained * off a GPIO as interrupt source */
Signature · 1 line
2.23.0
Andrew Lunn
maintainerRe: [PATCH net-next 3/3] net: dsa: mv88e6xxx: add RXNFC support
Quoted 46 lines
drivers/net/dsa/mv88e6xxx/chip.c +46
-0+static int mv88e6xxx_policy_insert (struct mv88e6xxx_chip *chip,int port, +struct ethtool_rx_flow_spec *fs) +{ +struct ethhdr *mac_entry = &fs->h_u.ether_spec; +struct ethhdr *mac_mask = &fs->m_u.ether_spec; +enum mv88e6xxx_policy_mapping mapping; +enum mv88e6xxx_policy_action action; +struct mv88e6xxx_policy *policy; +u16 vid =0 ; +u8 *addr; +int err; +int id; + +if (fs->location !=RX_CLS_LOC_ANY ) +return -EINVAL ; + +if (fs->ring_cookie ==RX_CLS_FLOW_DISC ) + action =MV88E6XXX_POLICY_ACTION_DISCARD ; +else +return -EOPNOTSUPP ; + +switch (fs->flow_type & ~FLOW_EXT ) { +case ETHER_FLOW : +if (!is_zero_ether_addr (mac_mask->h_dest) && +is_zero_ether_addr (mac_mask->h_source)) { + mapping =MV88E6XXX_POLICY_MAPPING_DA ; + addr = mac_entry->h_dest; + }else if (is_zero_ether_addr (mac_mask->h_dest) && + !is_zero_ether_addr (mac_mask->h_source)) { + mapping =MV88E6XXX_POLICY_MAPPING_SA ; + addr = mac_entry->h_source; + }else { +/* Cannot support DA and SA mapping in the same rule */ +return -EOPNOTSUPP ; + } +break ; +default : +return -EOPNOTSUPP ; + } + +if ((fs->flow_type &FLOW_EXT ) && fs->m_ext.vlan_tci) { +if (fs->m_ext.vlan_tci !=0xffff ) +return -EOPNOTSUPP ; + vid =be16_to_cpu (fs->h_ext.vlan_tci) &VLAN_VID_MASK ; + } +
drivers/net/dsa/mv88e6xxx/chip.c static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port, · line 1630
Quoted 10 lines
drivers/net/dsa/mv88e6xxx/chip.c +10
-0+idr_for_each_entry (&chip->policies, policy, id) { +if (policy->port == port && policy->mapping == mapping && + policy->action == action && policy->vid == vid && +ether_addr_equal (policy->addr, addr)) +return -EEXIST ; + } + + policy =devm_kzalloc (chip->dev,sizeof (*policy),GFP_KERNEL ); +if (!policy) +return -ENOMEM ;
Hi Vivien
I think this might be the first time we have done dynamic memory allocation in the mv88e6xxx driver. It might even be a first for a DSA driver?
I'm not saying it is wrong, but maybe we should discuss it.
I assume you are doing this because the ATU entry itself is not sufficient?
How much memory is involved here, worst case? I assume one struct mv88e6xxx_policy per ATU entry? Which you think is too much to allocate as part of chip? I guess most users will never use this feature, so for most users it would be wasted memory. So i do see the point for dynamically allocating it.
Thanks
Andrew
Re: [PATCH net-next 3/3] net: dsa: mv88e6xxx: add RXNFC support
Hi Andrew,
Quoted 10 lines · Andrew Lunn
drivers/net/dsa/mv88e6xxx/chip.c static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port, · line 1630
Quoted 3 lines
drivers/net/dsa/mv88e6xxx/chip.c +3
-0+ policy =devm_kzalloc (chip->dev,sizeof (*policy),GFP_KERNEL ); +if (!policy) +return -ENOMEM ;I think this might be the first time we have done dynamic memory allocation in the mv88e6xxx driver. It might even be a first for a DSA driver?
I'm not saying it is wrong, but maybe we should discuss it.
Quoted 8 lines
I assume you are doing this because the ATU entry itself is not sufficient?
How much memory is involved here, worst case? I assume one struct
mv88e6xxx_policyper ATU entry? Which you think is too much to allocate as part of chip? I guess most users will never use this feature, so for most users it would be wasted memory. So i do see the point for dynamically allocating it.
A layer 2 policy is not limited to the ATU. It can also be based on a VTU entry, on the port's Etype, or frame's Etype. We can have 0, 1 or literally thousands of policies programmed by the user. The ethtool API does not store the entries and requires the driver to dump them on get operations, hence the allocation for simplicity. But we may accomodate the DSA layer in the future if there are more RXNFC users than just bcm_sf2 and mv88e6xxx.
Thanks,
Vivien
Re: [PATCH net-next 3/3] net: dsa: mv88e6xxx: add RXNFC support
Quoted 22 lines · Vivien Didelot
Hi Andrew,
Quoted 10 lines · Andrew Lunn
drivers/net/dsa/mv88e6xxx/chip.c static int mv88e6xxx_port_db_load_purge(struct mv88e6xxx_chip *chip, int port, · line 1630
Quoted 3 lines
drivers/net/dsa/mv88e6xxx/chip.c +3
-0+ policy =devm_kzalloc (chip->dev,sizeof (*policy),GFP_KERNEL ); +if (!policy) +return -ENOMEM ;I think this might be the first time we have done dynamic memory allocation in the mv88e6xxx driver. It might even be a first for a DSA driver?
I'm not saying it is wrong, but maybe we should discuss it.
Quoted 8 lines
I assume you are doing this because the ATU entry itself is not sufficient?
How much memory is involved here, worst case? I assume one struct
mv88e6xxx_policyper ATU entry? Which you think is too much to allocate as part of chip? I guess most users will never use this feature, so for most users it would be wasted memory. So i do see the point for dynamically allocating it.
Quoted 3 lines
A layer 2 policy is not limited to the ATU. It can also be based on a VTU entry, on the port's Etype, or frame's Etype. We can have 0, 1 or literally thousands of policies programmed by the user.
O.K, then it has to by dynamic memory.
Andrew
Re: [PATCH net-next 3/3] net: dsa: mv88e6xxx: add RXNFC support
In reply to Vivien DidelotQuoted 7 lines · Vivien Didelot
Implement the .get_rxnfc and .set_rxnfc DSA operations to configure a port's Layer 2 Policy Control List (PCL) via ethtool.
Currently only dropping frames based on MAC Destination or Source Address (including the option VLAN parameter) is supported.
Signed-off-by Vivien Didelot <[email protected]>
For the ethtool interface part:
Signature · 1 line
Florian
David Miller
maintainerFrom: Vivien Didelot <[email protected]>
Date: Sat, 7 Sep 2019 16:00:46 -0400
Quoted 8 lines
This small series implements the ethtool RXNFC operations in the mv88e6xxx DSA driver to configure a port's Layer 2 Policy Control List (PCL) supported by models such as 88E6352 and 88E6390 and equivalent.
This allows to configure a port to discard frames based on a configured destination or source MAC address and an optional VLAN, with e.g.:
# ethtool --config-nfc lan1 flow-type ether src 00:11:22:33:44:55 action -1
Series applied, thanks.