net: dsa: b53: ARL improvements
cover net: dsa: b53: ARL improvements
Hi all,
This patch series improves the b53 driver ARL search code by renaming the ARL entries to be reflective of what they are: bins, and then introduce the number of buckets so we can properly bound check ARL searches.
The final patch removes an unused argument.
Florian Fainelli (4):
net: dsa: b53: Rename num_arl_entries to num_arl_bins
net: dsa: b53: Provide number of ARL buckets
net: dsa: b53: Bound check ARL searches
net: dsa: b53: Remove is_static argument to b53_read_op()
drivers/net/dsa/b53/b53_common.c | 81 ++++++++++++++++++++------------ drivers/net/dsa/b53/b53_priv.h | 8 +++- 2 files changed, 58 insertions(+), 31 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/4 net: dsa: b53: Rename num_arl_entries to num_arl_bins
The variable currently holds the number of ARL bins per ARL buckets, which is different from the number of ARL entries which would be bins times buckets. We will be adding a num_arl_buckets in a subsequent patch so get variables straight now.
--- drivers/net/dsa/b53/b53_common.c | 52 ++++++++++++++++---------------- drivers/net/dsa/b53/b53_priv.h | 2 +- 2 files changed, 27 insertions(+), 27 deletions(-)
drivers/net/dsa/b53/b53_common.c +26 -26
@@ -1495,10 +1495,10 @@ static int b53_arl_read(struct b53_device *dev, u64 mac,if (ret)return ret; -bitmap_zero (free_bins, dev->num_arl_entries); +bitmap_zero (free_bins, dev->num_arl_bins);/* Read the bins */ -for (i =0 ; i < dev->num_arl_entries; i++) { +for (i =0 ; i < dev->num_arl_bins; i++) {u64 mac_vid;u32 fwd_entry;
@@ -1521,10 +1521,10 @@ static int b53_arl_read(struct b53_device *dev, u64 mac,return 0 ; } -if (bitmap_weight (free_bins, dev->num_arl_entries) ==0 ) +if (bitmap_weight (free_bins, dev->num_arl_bins) ==0 )return -ENOSPC ; - *idx =find_first_bit (free_bins, dev->num_arl_entries); + *idx =find_first_bit (free_bins, dev->num_arl_bins);return -ENOENT ; }
@@ -1692,7 +1692,7 @@ int b53_fdb_dump(struct dsa_switch *ds, int port,if (ret)return ret; -if (priv->num_arl_entries >2 ) { +if (priv->num_arl_bins >2 ) {b53_arl_search_rd (priv,1 , &results[1 ]); ret =b53_fdb_copy (port, &results[1 ], cb, data);if (ret)
@@ -2185,7 +2185,7 @@ struct b53_chip_data {u16 enabled_ports;u8 cpu_port;u8 vta_regs[3 ]; -u8 arl_entries; +u8 arl_bins;u8 duplex_reg;u8 jumbo_pm_reg;u8 jumbo_size_reg;
@@ -2204,7 +2204,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .dev_name = "BCM5325", .vlans = 16, .enabled_ports = 0x1f, - .arl_entries = 2, + .arl_bins = 2, .cpu_port = B53_CPU_PORT_25, .duplex_reg = B53_DUPLEX_STAT_FE, },
@@ -2213,7 +2213,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .dev_name = "BCM5365", .vlans = 256, .enabled_ports = 0x1f, - .arl_entries = 2, + .arl_bins = 2, .cpu_port = B53_CPU_PORT_25, .duplex_reg = B53_DUPLEX_STAT_FE, },
@@ -2222,7 +2222,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .dev_name = "BCM5389", .vlans = 4096, .enabled_ports = 0x1f, - .arl_entries = 4, + .arl_bins = 4, .cpu_port = B53_CPU_PORT, .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2234,7 +2234,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .dev_name = "BCM5395", .vlans = 4096, .enabled_ports = 0x1f, - .arl_entries = 4, + .arl_bins = 4, .cpu_port = B53_CPU_PORT, .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2246,7 +2246,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .dev_name = "BCM5397", .vlans = 4096, .enabled_ports = 0x1f, - .arl_entries = 4, + .arl_bins = 4, .cpu_port = B53_CPU_PORT, .vta_regs = B53_VTA_REGS_9798, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2258,7 +2258,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .dev_name = "BCM5398", .vlans = 4096, .enabled_ports = 0x7f, - .arl_entries = 4, + .arl_bins = 4, .cpu_port = B53_CPU_PORT, .vta_regs = B53_VTA_REGS_9798, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2270,7 +2270,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .dev_name = "BCM53115", .vlans = 4096, .enabled_ports = 0x1f, - .arl_entries = 4, + .arl_bins = 4, .vta_regs = B53_VTA_REGS, .cpu_port = B53_CPU_PORT, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2282,7 +2282,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .dev_name = "BCM53125", .vlans = 4096, .enabled_ports = 0xff, - .arl_entries = 4, + .arl_bins = 4, .cpu_port = B53_CPU_PORT, .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2294,7 +2294,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .dev_name = "BCM53128", .vlans = 4096, .enabled_ports = 0x1ff, - .arl_entries = 4, + .arl_bins = 4, .cpu_port = B53_CPU_PORT, .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2306,7 +2306,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .dev_name = "BCM63xx", .vlans = 4096, .enabled_ports = 0, /* pdata must provide them */ - .arl_entries = 4, + .arl_bins = 4, .cpu_port = B53_CPU_PORT, .vta_regs = B53_VTA_REGS_63XX, .duplex_reg = B53_DUPLEX_STAT_63XX,
@@ -2318,7 +2318,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .dev_name = "BCM53010", .vlans = 4096, .enabled_ports = 0x1f, - .arl_entries = 4, + .arl_bins = 4, .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2330,7 +2330,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .dev_name = "BCM53011", .vlans = 4096, .enabled_ports = 0x1bf, - .arl_entries = 4, + .arl_bins = 4, .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2342,7 +2342,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .dev_name = "BCM53012", .vlans = 4096, .enabled_ports = 0x1bf, - .arl_entries = 4, + .arl_bins = 4, .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2354,7 +2354,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .dev_name = "BCM53018", .vlans = 4096, .enabled_ports = 0x1f, - .arl_entries = 4, + .arl_bins = 4, .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2366,7 +2366,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .dev_name = "BCM53019", .vlans = 4096, .enabled_ports = 0x1f, - .arl_entries = 4, + .arl_bins = 4, .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2378,7 +2378,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .dev_name = "BCM585xx/586xx/88312", .vlans = 4096, .enabled_ports = 0x1ff, - .arl_entries = 4, + .arl_bins = 4, .cpu_port = B53_CPU_PORT, .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2390,7 +2390,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .dev_name = "BCM583xx/11360", .vlans = 4096, .enabled_ports = 0x103, - .arl_entries = 4, + .arl_bins = 4, .cpu_port = B53_CPU_PORT, .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2402,7 +2402,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .dev_name = "BCM7445", .vlans = 4096, .enabled_ports = 0x1ff, - .arl_entries = 4, + .arl_bins = 4, .cpu_port = B53_CPU_PORT, .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2414,7 +2414,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .dev_name = "BCM7278", .vlans = 4096, .enabled_ports = 0x1ff, - .arl_entries= 4, + .arl_bins = 4, .cpu_port = B53_CPU_PORT, .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2442,7 +2442,7 @@ static int b53_switch_init(struct b53_device *dev) dev->jumbo_pm_reg = chip->jumbo_pm_reg; dev->cpu_port = chip->cpu_port; dev->num_vlans = chip->vlans; - dev->num_arl_entries = chip->arl_entries; + dev->num_arl_bins = chip->arl_bins;break ; } }
drivers/net/dsa/b53/b53_priv.h +1 -1
@@ -117,7 +117,7 @@ struct b53_device {u8 jumbo_pm_reg;u8 jumbo_size_reg;int reset_gpio; -u8 num_arl_entries; +u8 num_arl_bins;enum dsa_tag_protocol tag_protocol;/* used ports mask */
Signature · 1 line
2.17.1
Re: [PATCH net-next 1/4] net: dsa: b53: Rename num_arl_entries to num_arl_bins
Quoted 6 lines · Florian Fainelli
The variable currently holds the number of ARL bins per ARL buckets, which is different from the number of ARL entries which would be bins times buckets. We will be adding a
num_arl_bucketsin a subsequent patch so get variables straight now.Signed-off-by Florian Fainelli <[email protected]>
Andrew
PATCH 2/4 net: dsa: b53: Provide number of ARL buckets
In reply to Florian FainelliIn preparation for doing proper upper bound checking of FDB/MDB entries being added to the ARL, provide the number of ARL buckets for each switch chip we support. All chips have 1024 buckets, except 7278 which has only 256.
--- drivers/net/dsa/b53/b53_common.c | 21 +++++++++++++++++++++ drivers/net/dsa/b53/b53_priv.h | 1 + 2 files changed, 22 insertions(+)
drivers/net/dsa/b53/b53_common.c +21 -0
@@ -2186,6 +2186,7 @@ struct b53_chip_data {u8 cpu_port;u8 vta_regs[3 ];u8 arl_bins; +u16 arl_buckets;u8 duplex_reg;u8 jumbo_pm_reg;u8 jumbo_size_reg;
@@ -2205,6 +2206,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .vlans = 16, .enabled_ports = 0x1f, .arl_bins = 2, + .arl_buckets = 1024, .cpu_port = B53_CPU_PORT_25, .duplex_reg = B53_DUPLEX_STAT_FE, },
@@ -2214,6 +2216,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .vlans = 256, .enabled_ports = 0x1f, .arl_bins = 2, + .arl_buckets = 1024, .cpu_port = B53_CPU_PORT_25, .duplex_reg = B53_DUPLEX_STAT_FE, },
@@ -2223,6 +2226,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .vlans = 4096, .enabled_ports = 0x1f, .arl_bins = 4, + .arl_buckets = 1024, .cpu_port = B53_CPU_PORT, .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2235,6 +2239,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .vlans = 4096, .enabled_ports = 0x1f, .arl_bins = 4, + .arl_buckets = 1024, .cpu_port = B53_CPU_PORT, .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2247,6 +2252,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .vlans = 4096, .enabled_ports = 0x1f, .arl_bins = 4, + .arl_buckets = 1024, .cpu_port = B53_CPU_PORT, .vta_regs = B53_VTA_REGS_9798, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2259,6 +2265,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .vlans = 4096, .enabled_ports = 0x7f, .arl_bins = 4, + .arl_buckets = 1024, .cpu_port = B53_CPU_PORT, .vta_regs = B53_VTA_REGS_9798, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2271,6 +2278,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .vlans = 4096, .enabled_ports = 0x1f, .arl_bins = 4, + .arl_buckets = 1024, .vta_regs = B53_VTA_REGS, .cpu_port = B53_CPU_PORT, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2283,6 +2291,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .vlans = 4096, .enabled_ports = 0xff, .arl_bins = 4, + .arl_buckets = 1024, .cpu_port = B53_CPU_PORT, .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2295,6 +2304,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .vlans = 4096, .enabled_ports = 0x1ff, .arl_bins = 4, + .arl_buckets = 1024, .cpu_port = B53_CPU_PORT, .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2307,6 +2317,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .vlans = 4096, .enabled_ports = 0, /* pdata must provide them */ .arl_bins = 4, + .arl_buckets = 1024, .cpu_port = B53_CPU_PORT, .vta_regs = B53_VTA_REGS_63XX, .duplex_reg = B53_DUPLEX_STAT_63XX,
@@ -2319,6 +2330,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .vlans = 4096, .enabled_ports = 0x1f, .arl_bins = 4, + .arl_buckets = 1024, .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2331,6 +2343,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .vlans = 4096, .enabled_ports = 0x1bf, .arl_bins = 4, + .arl_buckets = 1024, .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2343,6 +2356,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .vlans = 4096, .enabled_ports = 0x1bf, .arl_bins = 4, + .arl_buckets = 1024, .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2355,6 +2369,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .vlans = 4096, .enabled_ports = 0x1f, .arl_bins = 4, + .arl_buckets = 1024, .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2367,6 +2382,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .vlans = 4096, .enabled_ports = 0x1f, .arl_bins = 4, + .arl_buckets = 1024, .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2379,6 +2395,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .vlans = 4096, .enabled_ports = 0x1ff, .arl_bins = 4, + .arl_buckets = 1024, .cpu_port = B53_CPU_PORT, .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2391,6 +2408,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .vlans = 4096, .enabled_ports = 0x103, .arl_bins = 4, + .arl_buckets = 1024, .cpu_port = B53_CPU_PORT, .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2403,6 +2421,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .vlans = 4096, .enabled_ports = 0x1ff, .arl_bins = 4, + .arl_buckets = 1024, .cpu_port = B53_CPU_PORT, .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2415,6 +2434,7 @@ static const struct b53_chip_data b53_switch_chips[] = { .vlans = 4096, .enabled_ports = 0x1ff, .arl_bins = 4, + .arl_buckets = 256, .cpu_port = B53_CPU_PORT, .vta_regs = B53_VTA_REGS, .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2443,6 +2463,7 @@ static int b53_switch_init(struct b53_device *dev) dev->cpu_port = chip->cpu_port; dev->num_vlans = chip->vlans; dev->num_arl_bins = chip->arl_bins; + dev->num_arl_buckets = chip->arl_buckets;break ; } }
drivers/net/dsa/b53/b53_priv.h +1 -0
@@ -118,6 +118,7 @@ struct b53_device {u8 jumbo_size_reg;int reset_gpio;u8 num_arl_bins; +u16 num_arl_buckets;enum dsa_tag_protocol tag_protocol;/* used ports mask */
Signature · 1 line
2.17.1
Re: [PATCH net-next 2/4] net: dsa: b53: Provide number of ARL buckets
Quoted 6 lines · Florian Fainelli
In preparation for doing proper upper bound checking of FDB/MDB entries being added to the ARL, provide the number of ARL buckets for each switch chip we support. All chips have 1024 buckets, except 7278 which has only 256.
Signed-off-by Florian Fainelli <[email protected]>
Andrew
PATCH 3/4 net: dsa: b53: Bound check ARL searches
In reply to Florian FainelliARL searches are done by reading two ARL entries at a time, do not cap the search at 1024 which would only limit us to half of the possible ARL capacity, but use b53_max_arl_entries() instead which does the right multiplication between bins and indexes.
--- drivers/net/dsa/b53/b53_common.c | 2 +- drivers/net/dsa/b53/b53_priv.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/net/dsa/b53/b53_common.c +1 -1
@@ -1702,7 +1702,7 @@ int b53_fdb_dump(struct dsa_switch *ds, int port,break ; } - }while (count++ <1024 ); + }while (count++ <b53_max_arl_entries (priv) /2 );return 0 ; }
drivers/net/dsa/b53/b53_priv.h +5 -0
@@ -213,6 +213,11 @@ static inline int is58xx(struct b53_device *dev)#define B53_CPU_PORT_25 5#define B53_CPU_PORT 8 +static inline unsigned int b53_max_arl_entries (struct b53_device *dev) +{ +return dev->num_arl_buckets * dev->num_arl_bins; +} +struct b53_device *b53_switch_alloc (struct device *base,const struct b53_io_ops *ops,void *priv);
Signature · 1 line
2.17.1
Re: [PATCH net-next 3/4] net: dsa: b53: Bound check ARL searches
Quoted 6 lines · Florian Fainelli
ARL searches are done by reading two ARL entries at a time, do not cap the search at 1024 which would only limit us to half of the possible ARL capacity, but use
b53_max_arl_entries()instead which does the right multiplication between bins and indexes.Signed-off-by Florian Fainelli <[email protected]>
Andrew
PATCH 4/4 net: dsa: b53: Remove is_static argument to b53_read_op()
In reply to Florian FainelliThis argument is not used.
--- drivers/net/dsa/b53/b53_common.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/dsa/b53/b53_common.c +3 -3
@@ -1484,8 +1484,7 @@ static int b53_arl_rw_op(struct b53_device *dev, unsigned int op) }static int b53_arl_read (struct b53_device *dev,u64 mac, -u16 vid,struct b53_arl_entry *ent,u8 *idx, -bool is_valid) +u16 vid,struct b53_arl_entry *ent,u8 *idx) {DECLARE_BITMAP (free_bins,B53_ARLTBL_MAX_BIN_ENTRIES );unsigned int i;
@@ -1550,7 +1549,8 @@ static int b53_arl_op(struct b53_device *dev, int op, int port,if (ret)return ret; - ret =b53_arl_read (dev, mac, vid, &ent, &idx, is_valid); + ret =b53_arl_read (dev, mac, vid, &ent, &idx); +/* If this is a read, just finish now */ if (op)return ret;
Signature · 1 line
2.17.1
Re: [PATCH net-next 4/4] net: dsa: b53: Remove is_static argument to b53_read_op()
Quoted 3 lines · Florian Fainelli
This argument is not used.
Signed-off-by Florian Fainelli <[email protected]>
Andrew
David Miller
maintainerFrom: Florian Fainelli <[email protected]>
Date: Thu, 30 Apr 2020 11:49:07 -0700
Quoted 6 lines
This patch series improves the b53 driver ARL search code by renaming the ARL entries to be reflective of what they are: bins, and then introduce the number of buckets so we can properly bound check ARL searches.
The final patch removes an unused argument.
Series applied, thanks.