Skip to content

Commit 4daa70c

Browse files
ffainellidavem330
authored andcommitted
net: dsa: bcm_sf2: Simplify bcm_sf2_cfp_rule_get_all()
There is no need to do a HW search of the TCAMs which is something slow and expensive. Since we already maintain a bitmask of active CFP rules, just iterate over those, starting from bit 1 (after the reserved entry) to get a count and index position to store the rule later on. As a result we can remove the code in bcm_sf2_cfp_rule_get() which acted on the "search" argument, and remove that argument. Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5d80bcb commit 4daa70c

File tree

1 file changed

+14
-54
lines changed

1 file changed

+14
-54
lines changed

drivers/net/dsa/bcm_sf2_cfp.c

Lines changed: 14 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -491,28 +491,24 @@ static int bcm_sf2_cfp_ipv4_rule_get(struct bcm_sf2_priv *priv, int port,
491491
}
492492

493493
static int bcm_sf2_cfp_rule_get(struct bcm_sf2_priv *priv, int port,
494-
struct ethtool_rxnfc *nfc, bool search)
494+
struct ethtool_rxnfc *nfc)
495495
{
496496
struct ethtool_tcpip4_spec *v4_spec = NULL, *v4_m_spec;
497497
unsigned int queue_num;
498498
u32 reg;
499499
int ret;
500500

501-
if (!search) {
502-
bcm_sf2_cfp_rule_addr_set(priv, nfc->fs.location);
501+
bcm_sf2_cfp_rule_addr_set(priv, nfc->fs.location);
503502

504-
ret = bcm_sf2_cfp_op(priv, OP_SEL_READ | ACT_POL_RAM);
505-
if (ret)
506-
return ret;
503+
ret = bcm_sf2_cfp_op(priv, OP_SEL_READ | ACT_POL_RAM);
504+
if (ret)
505+
return ret;
507506

508-
reg = core_readl(priv, CORE_ACT_POL_DATA0);
507+
reg = core_readl(priv, CORE_ACT_POL_DATA0);
509508

510-
ret = bcm_sf2_cfp_op(priv, OP_SEL_READ | TCAM_SEL);
511-
if (ret)
512-
return ret;
513-
} else {
514-
reg = core_readl(priv, CORE_ACT_POL_DATA0);
515-
}
509+
ret = bcm_sf2_cfp_op(priv, OP_SEL_READ | TCAM_SEL);
510+
if (ret)
511+
return ret;
516512

517513
/* Extract the destination port */
518514
nfc->fs.ring_cookie = fls((reg >> DST_MAP_IB_SHIFT) &
@@ -541,9 +537,6 @@ static int bcm_sf2_cfp_rule_get(struct bcm_sf2_priv *priv, int port,
541537
v4_m_spec = &nfc->fs.m_u.udp_ip4_spec;
542538
break;
543539
default:
544-
/* Clear to exit the search process */
545-
if (search)
546-
core_readl(priv, CORE_CFP_DATA_PORT(7));
547540
return -EINVAL;
548541
}
549542

@@ -577,44 +570,11 @@ static int bcm_sf2_cfp_rule_get_all(struct bcm_sf2_priv *priv,
577570
u32 *rule_locs)
578571
{
579572
unsigned int index = 1, rules_cnt = 0;
580-
int ret;
581-
u32 reg;
582573

583-
/* Do not poll on OP_STR_DONE to be self-clearing for search
584-
* operations, we cannot use bcm_sf2_cfp_op here because it completes
585-
* on clearing OP_STR_DONE which won't clear until the entire search
586-
* operation is over.
587-
*/
588-
reg = core_readl(priv, CORE_CFP_ACC);
589-
reg &= ~(XCESS_ADDR_MASK << XCESS_ADDR_SHIFT);
590-
reg |= index << XCESS_ADDR_SHIFT;
591-
reg &= ~(OP_SEL_MASK | RAM_SEL_MASK);
592-
reg |= OP_SEL_SEARCH | TCAM_SEL | OP_STR_DONE;
593-
core_writel(priv, reg, CORE_CFP_ACC);
594-
595-
do {
596-
/* Wait for results to be ready */
597-
reg = core_readl(priv, CORE_CFP_ACC);
598-
599-
/* Extract the address we are searching */
600-
index = reg >> XCESS_ADDR_SHIFT;
601-
index &= XCESS_ADDR_MASK;
602-
603-
/* We have a valid search result, so flag it accordingly */
604-
if (reg & SEARCH_STS) {
605-
ret = bcm_sf2_cfp_rule_get(priv, port, nfc, true);
606-
if (ret)
607-
continue;
608-
609-
rule_locs[rules_cnt] = index;
610-
rules_cnt++;
611-
}
612-
613-
/* Search is over break out */
614-
if (!(reg & OP_STR_DONE))
615-
break;
616-
617-
} while (index < priv->num_cfp_rules);
574+
for_each_set_bit_from(index, priv->cfp.used, priv->num_cfp_rules) {
575+
rule_locs[rules_cnt] = index;
576+
rules_cnt++;
577+
}
618578

619579
/* Put the TCAM size here */
620580
nfc->data = bcm_sf2_cfp_rule_size(priv);
@@ -640,7 +600,7 @@ int bcm_sf2_get_rxnfc(struct dsa_switch *ds, int port,
640600
nfc->data |= RX_CLS_LOC_SPECIAL;
641601
break;
642602
case ETHTOOL_GRXCLSRULE:
643-
ret = bcm_sf2_cfp_rule_get(priv, port, nfc, false);
603+
ret = bcm_sf2_cfp_rule_get(priv, port, nfc);
644604
break;
645605
case ETHTOOL_GRXCLSRLALL:
646606
ret = bcm_sf2_cfp_rule_get_all(priv, port, nfc, rule_locs);

0 commit comments

Comments
 (0)