linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: bcmgenet: use promisc for unsupported filters
@ 2019-07-17 21:58 justinpopo6
  2019-07-18  3:38 ` Florian Fainelli
  2019-07-19  0:51 ` Doug Berger
  0 siblings, 2 replies; 4+ messages in thread
From: justinpopo6 @ 2019-07-17 21:58 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, bcm-kernel-feedback-list, davem, f.fainelli,
	opendmb, Justin Chen

From: Justin Chen <justinpopo6@gmail.com>

Currently we silently ignore filters if we cannot meet the filter
requirements. This will lead to the MAC dropping packets that are
expected to pass. A better solution would be to set the NIC to promisc
mode when the required filters cannot be met.

Also correct the number of MDF filters supported. It should be 17,
not 16.

Signed-off-by: Justin Chen <justinpopo6@gmail.com>
---
 drivers/net/ethernet/broadcom/genet/bcmgenet.c | 57 ++++++++++++--------------
 1 file changed, 26 insertions(+), 31 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
index 34466b8..a2b5780 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
@@ -3083,39 +3083,42 @@ static void bcmgenet_timeout(struct net_device *dev)
 	netif_tx_wake_all_queues(dev);
 }
 
-#define MAX_MC_COUNT	16
+#define MAX_MDF_FILTER	17
 
 static inline void bcmgenet_set_mdf_addr(struct bcmgenet_priv *priv,
 					 unsigned char *addr,
-					 int *i,
-					 int *mc)
+					 int *i)
 {
-	u32 reg;
-
 	bcmgenet_umac_writel(priv, addr[0] << 8 | addr[1],
 			     UMAC_MDF_ADDR + (*i * 4));
 	bcmgenet_umac_writel(priv, addr[2] << 24 | addr[3] << 16 |
 			     addr[4] << 8 | addr[5],
 			     UMAC_MDF_ADDR + ((*i + 1) * 4));
-	reg = bcmgenet_umac_readl(priv, UMAC_MDF_CTRL);
-	reg |= (1 << (MAX_MC_COUNT - *mc));
-	bcmgenet_umac_writel(priv, reg, UMAC_MDF_CTRL);
 	*i += 2;
-	(*mc)++;
 }
 
 static void bcmgenet_set_rx_mode(struct net_device *dev)
 {
 	struct bcmgenet_priv *priv = netdev_priv(dev);
 	struct netdev_hw_addr *ha;
-	int i, mc;
+	int i, nfilter;
 	u32 reg;
 
 	netif_dbg(priv, hw, dev, "%s: %08X\n", __func__, dev->flags);
 
-	/* Promiscuous mode */
+	/* Number of filters needed */
+	nfilter = netdev_uc_count(dev) + netdev_mc_count(dev) + 2;
+
+	/*
+	 * Turn on promicuous mode for three scenarios
+	 * 1. IFF_PROMISC flag is set
+	 * 2. IFF_ALLMULTI flag is set
+	 * 3. The number of filters needed exceeds the number filters
+	 *    supported by the hardware.
+	*/
 	reg = bcmgenet_umac_readl(priv, UMAC_CMD);
-	if (dev->flags & IFF_PROMISC) {
+	if ((dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) ||
+	    (nfilter > MAX_MDF_FILTER)) {
 		reg |= CMD_PROMISC;
 		bcmgenet_umac_writel(priv, reg, UMAC_CMD);
 		bcmgenet_umac_writel(priv, 0, UMAC_MDF_CTRL);
@@ -3125,32 +3128,24 @@ static void bcmgenet_set_rx_mode(struct net_device *dev)
 		bcmgenet_umac_writel(priv, reg, UMAC_CMD);
 	}
 
-	/* UniMac doesn't support ALLMULTI */
-	if (dev->flags & IFF_ALLMULTI) {
-		netdev_warn(dev, "ALLMULTI is not supported\n");
-		return;
-	}
-
 	/* update MDF filter */
 	i = 0;
-	mc = 0;
 	/* Broadcast */
-	bcmgenet_set_mdf_addr(priv, dev->broadcast, &i, &mc);
+	bcmgenet_set_mdf_addr(priv, dev->broadcast, &i);
 	/* my own address.*/
-	bcmgenet_set_mdf_addr(priv, dev->dev_addr, &i, &mc);
-	/* Unicast list*/
-	if (netdev_uc_count(dev) > (MAX_MC_COUNT - mc))
-		return;
+	bcmgenet_set_mdf_addr(priv, dev->dev_addr, &i);
 
-	if (!netdev_uc_empty(dev))
-		netdev_for_each_uc_addr(ha, dev)
-			bcmgenet_set_mdf_addr(priv, ha->addr, &i, &mc);
-	/* Multicast */
-	if (netdev_mc_empty(dev) || netdev_mc_count(dev) >= (MAX_MC_COUNT - mc))
-		return;
+	/* Unicast */
+	netdev_for_each_uc_addr(ha, dev)
+		bcmgenet_set_mdf_addr(priv, ha->addr, &i);
 
+	/* Multicast */
 	netdev_for_each_mc_addr(ha, dev)
-		bcmgenet_set_mdf_addr(priv, ha->addr, &i, &mc);
+		bcmgenet_set_mdf_addr(priv, ha->addr, &i);
+
+	/* Enable filters */
+	reg = GENMASK(MAX_MDF_FILTER - 1, MAX_MDF_FILTER - nfilter);
+	bcmgenet_umac_writel(priv, reg, UMAC_MDF_CTRL);
 }
 
 /* Set the hardware MAC address. */
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: bcmgenet: use promisc for unsupported filters
  2019-07-17 21:58 [PATCH] net: bcmgenet: use promisc for unsupported filters justinpopo6
@ 2019-07-18  3:38 ` Florian Fainelli
  2019-07-18 18:46   ` David Miller
  2019-07-19  0:51 ` Doug Berger
  1 sibling, 1 reply; 4+ messages in thread
From: Florian Fainelli @ 2019-07-18  3:38 UTC (permalink / raw)
  To: justinpopo6, netdev
  Cc: linux-kernel, bcm-kernel-feedback-list, davem, opendmb



On 7/17/2019 2:58 PM, justinpopo6@gmail.com wrote:
> From: Justin Chen <justinpopo6@gmail.com>
> 
> Currently we silently ignore filters if we cannot meet the filter
> requirements. This will lead to the MAC dropping packets that are
> expected to pass. A better solution would be to set the NIC to promisc
> mode when the required filters cannot be met.
> 
> Also correct the number of MDF filters supported. It should be 17,
> not 16.
> 
> Signed-off-by: Justin Chen <justinpopo6@gmail.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>

Thanks Justin!
-- 
Florian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: bcmgenet: use promisc for unsupported filters
  2019-07-18  3:38 ` Florian Fainelli
@ 2019-07-18 18:46   ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2019-07-18 18:46 UTC (permalink / raw)
  To: f.fainelli
  Cc: justinpopo6, netdev, linux-kernel, bcm-kernel-feedback-list, opendmb

From: Florian Fainelli <f.fainelli@gmail.com>
Date: Wed, 17 Jul 2019 20:38:47 -0700

> 
> 
> On 7/17/2019 2:58 PM, justinpopo6@gmail.com wrote:
>> From: Justin Chen <justinpopo6@gmail.com>
>> 
>> Currently we silently ignore filters if we cannot meet the filter
>> requirements. This will lead to the MAC dropping packets that are
>> expected to pass. A better solution would be to set the NIC to promisc
>> mode when the required filters cannot be met.
>> 
>> Also correct the number of MDF filters supported. It should be 17,
>> not 16.
>> 
>> Signed-off-by: Justin Chen <justinpopo6@gmail.com>
> 
> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>

Applied and queued up for -stable.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: bcmgenet: use promisc for unsupported filters
  2019-07-17 21:58 [PATCH] net: bcmgenet: use promisc for unsupported filters justinpopo6
  2019-07-18  3:38 ` Florian Fainelli
@ 2019-07-19  0:51 ` Doug Berger
  1 sibling, 0 replies; 4+ messages in thread
From: Doug Berger @ 2019-07-19  0:51 UTC (permalink / raw)
  To: justinpopo6, netdev
  Cc: linux-kernel, bcm-kernel-feedback-list, davem, f.fainelli

On 7/17/19 2:58 PM, justinpopo6@gmail.com wrote:
> From: Justin Chen <justinpopo6@gmail.com>
> 
> Currently we silently ignore filters if we cannot meet the filter
> requirements. This will lead to the MAC dropping packets that are
> expected to pass. A better solution would be to set the NIC to promisc
> mode when the required filters cannot be met.
> 
> Also correct the number of MDF filters supported. It should be 17,
> not 16.
> 
> Signed-off-by: Justin Chen <justinpopo6@gmail.com>

Acked-by: Doug Berger <opendmb@gmail.com>

Thanks Justin :)
    Doug

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-07-19  0:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-17 21:58 [PATCH] net: bcmgenet: use promisc for unsupported filters justinpopo6
2019-07-18  3:38 ` Florian Fainelli
2019-07-18 18:46   ` David Miller
2019-07-19  0:51 ` Doug Berger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).