LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Murali Karicheri <m-karicheri2@ti.com>
To: <robh+dt@kernel.org>, <mark.rutland@arm.com>,
	<ssantosh@kernel.org>, <malat@debian.org>, <w-kwok2@ti.com>,
	<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>, <davem@davemloft.net>,
	<netdev@vger.kernel.org>, <grygorii.strashko@ti.com>,
	<nsekhar@ti.com>
Subject: [net-next PATCH v4 13/13] net: netcp: ethss: k2g: add promiscuous mode support
Date: Tue, 17 Apr 2018 17:30:42 -0400	[thread overview]
Message-ID: <1524000642-23944-14-git-send-email-m-karicheri2@ti.com> (raw)
In-Reply-To: <1524000642-23944-1-git-send-email-m-karicheri2@ti.com>

From: WingMan Kwok <w-kwok2@ti.com>

This patch adds support for promiscuous mode in k2g's network
driver. When upper layer instructs to transition from
non-promiscuous mode to promiscuous mode or vice versa
K2G network driver needs to configure ALE accordingly
so that in case of non-promiscuous mode, ALE will not flood
all unicast packets to host port, while in promiscuous
mode, it will pass all received unicast packets to
host port.

Signed-off-by: WingMan Kwok <w-kwok2@ti.com>
Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
---
 drivers/net/ethernet/ti/netcp_ethss.c | 56 +++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/drivers/net/ethernet/ti/netcp_ethss.c b/drivers/net/ethernet/ti/netcp_ethss.c
index 5bc7921..6a728d3 100644
--- a/drivers/net/ethernet/ti/netcp_ethss.c
+++ b/drivers/net/ethernet/ti/netcp_ethss.c
@@ -2775,6 +2775,61 @@ static inline int gbe_hwtstamp_set(struct gbe_intf *gbe_intf, struct ifreq *req)
 }
 #endif /* CONFIG_TI_CPTS */
 
+static int gbe_set_rx_mode(void *intf_priv, bool promisc)
+{
+	struct gbe_intf *gbe_intf = intf_priv;
+	struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
+	struct cpsw_ale *ale = gbe_dev->ale;
+	unsigned long timeout;
+	int i, ret = -ETIMEDOUT;
+
+	/* Disable(1)/Enable(0) Learn for all ports (host is port 0 and
+	 * slaves are port 1 and up
+	 */
+	for (i = 0; i <= gbe_dev->num_slaves; i++) {
+		cpsw_ale_control_set(ale, i,
+				     ALE_PORT_NOLEARN, !!promisc);
+		cpsw_ale_control_set(ale, i,
+				     ALE_PORT_NO_SA_UPDATE, !!promisc);
+	}
+
+	if (!promisc) {
+		/* Don't Flood All Unicast Packets to Host port */
+		cpsw_ale_control_set(ale, 0, ALE_P0_UNI_FLOOD, 0);
+		dev_vdbg(gbe_dev->dev, "promiscuous mode disabled\n");
+		return 0;
+	}
+
+	timeout = jiffies + HZ;
+
+	/* Clear All Untouched entries */
+	cpsw_ale_control_set(ale, 0, ALE_AGEOUT, 1);
+	do {
+		cpu_relax();
+		if (cpsw_ale_control_get(ale, 0, ALE_AGEOUT)) {
+			ret = 0;
+			break;
+		}
+
+	} while (time_after(timeout, jiffies));
+
+	/* Make sure it is not a false timeout */
+	if (ret && !cpsw_ale_control_get(ale, 0, ALE_AGEOUT))
+		return ret;
+
+	cpsw_ale_control_set(ale, 0, ALE_AGEOUT, 1);
+
+	/* Clear all mcast from ALE */
+	cpsw_ale_flush_multicast(ale,
+				 GBE_PORT_MASK(gbe_dev->ale_ports),
+				 -1);
+
+	/* Flood All Unicast Packets to Host port */
+	cpsw_ale_control_set(ale, 0, ALE_P0_UNI_FLOOD, 1);
+	dev_vdbg(gbe_dev->dev, "promiscuous mode enabled\n");
+	return ret;
+}
+
 static int gbe_ioctl(void *intf_priv, struct ifreq *req, int cmd)
 {
 	struct gbe_intf *gbe_intf = intf_priv;
@@ -3529,6 +3584,7 @@ static int gbe_probe(struct netcp_device *netcp_device, struct device *dev,
 		gbe_dev->max_num_slaves = 8;
 	} else if (of_device_is_compatible(node, "ti,netcp-gbe-2")) {
 		gbe_dev->max_num_slaves = 1;
+		gbe_module.set_rx_mode = gbe_set_rx_mode;
 	} else if (of_device_is_compatible(node, "ti,netcp-xgbe")) {
 		gbe_dev->max_num_slaves = 2;
 	} else {
-- 
1.9.1

  parent reply	other threads:[~2018-04-17 21:29 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-17 21:30 [net-next PATCH v4 00/13] Add support for netcp driver on K2G SoC Murali Karicheri
2018-04-17 21:30 ` [net-next PATCH v4 01/13] soc: ti: K2G: enhancement to support QMSS in K2G NAVSS Murali Karicheri
2018-04-17 21:30 ` [net-next PATCH v4 02/13] soc: ti: K2G: provide APIs to support driver probe deferral Murali Karicheri
2018-04-17 21:30 ` [net-next PATCH v4 03/13] net: netcp: ethss: use macro for checking ss_version consistently Murali Karicheri
2018-04-17 21:30 ` [net-next PATCH v4 04/13] net: netcp: ethss: make sgmii configuration conditional Murali Karicheri
2018-04-17 21:30 ` [net-next PATCH v4 05/13] net: netcp: ethss: add support for handling rgmii link interface Murali Karicheri
2018-04-17 21:30 ` [net-next PATCH v4 06/13] net: netcp: ethss: use rgmii link status for 2u cpsw hardware Murali Karicheri
2018-04-17 21:30 ` [net-next PATCH v4 07/13] net: netcp: ethss: map vlan priorities to zero flow Murali Karicheri
2018-04-17 21:30 ` [net-next PATCH v4 08/13] net: netcp: ethss: re-use stats handling code for 2u hardware Murali Karicheri
2018-04-17 21:30 ` [net-next PATCH v4 09/13] net: netcp: ethss: use of_get_phy_mode() to support different RGMII modes Murali Karicheri
2018-04-17 21:30 ` [net-next PATCH v4 10/13] Revert "net: netcp: remove dead code from the driver" Murali Karicheri
2018-04-17 21:30 ` [net-next PATCH v4 11/13] net: netcp: support probe deferral Murali Karicheri
2018-04-17 21:30 ` [net-next PATCH v4 12/13] net: netcp: add api to support set rx mode in netcp modules Murali Karicheri
2018-04-17 21:30 ` Murali Karicheri [this message]
2018-04-19  1:07 ` [net-next PATCH v4 00/13] Add support for netcp driver on K2G SoC David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1524000642-23944-14-git-send-email-m-karicheri2@ti.com \
    --to=m-karicheri2@ti.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=grygorii.strashko@ti.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=malat@debian.org \
    --cc=mark.rutland@arm.com \
    --cc=netdev@vger.kernel.org \
    --cc=nsekhar@ti.com \
    --cc=robh+dt@kernel.org \
    --cc=ssantosh@kernel.org \
    --cc=w-kwok2@ti.com \
    --subject='Re: [net-next PATCH v4 13/13] net: netcp: ethss: k2g: add promiscuous mode support' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).