netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [net-next 0/2] Add promiscous mode support in k2g network driver
@ 2018-04-02 16:17 Murali Karicheri
  2018-04-02 16:17 ` [net-next 1/2] net: netcp: add api to support set rx mode in netcp modules Murali Karicheri
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Murali Karicheri @ 2018-04-02 16:17 UTC (permalink / raw)
  To: w-kwok2, linux-kernel, davem, netdev, nsekhar, grygorii.strashko

This patch adds support for promiscuous mode in network driver for K2G
SoC. This depends on v3 of my series at
https://www.spinics.net/lists/kernel/msg2765942.html

I plan to fold this to the above series and submit again when the net-next
merge windows opens. At this time, please review and let me know if it
looks good or need any re-work. I would like to get this ready so that it
can be merged along with the above series.

The boot and promiscuous mode test logs are at
https://pastebin.ubuntu.com/p/XQCvFS3QZb/

WingMan Kwok (2):
  net: netcp: add api to support set rx mode in netcp modules
  net: netcp: ethss: k2g: add promiscuous mode support

 drivers/net/ethernet/ti/netcp.h       |  1 +
 drivers/net/ethernet/ti/netcp_core.c  | 19 ++++++++++++
 drivers/net/ethernet/ti/netcp_ethss.c | 56 +++++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+)

-- 
1.9.1

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

* [net-next 1/2] net: netcp: add api to support set rx mode in netcp modules
  2018-04-02 16:17 [net-next 0/2] Add promiscous mode support in k2g network driver Murali Karicheri
@ 2018-04-02 16:17 ` Murali Karicheri
  2018-04-02 16:17 ` [net-next 2/2] net: netcp: ethss: k2g: add promiscuous mode support Murali Karicheri
  2018-04-02 16:28 ` [net-next 0/2] Add promiscous mode support in k2g network driver David Miller
  2 siblings, 0 replies; 7+ messages in thread
From: Murali Karicheri @ 2018-04-02 16:17 UTC (permalink / raw)
  To: w-kwok2, linux-kernel, davem, netdev, nsekhar, grygorii.strashko

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

This patch adds an API to support setting rx mode in
netcp modules.  If a netcp module needs to be notified
when upper layer transitions from one rx mode to
another and react accordingly, such a module will implement
the new API set_rx_mode added in this patch.  Currently
rx modes supported are PROMISCUOUS and NON_PROMISCUOUS
modes.

Signed-off-by: WingMan Kwok <w-kwok2@ti.com>
Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
---
 drivers/net/ethernet/ti/netcp.h      |  1 +
 drivers/net/ethernet/ti/netcp_core.c | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/drivers/net/ethernet/ti/netcp.h b/drivers/net/ethernet/ti/netcp.h
index 416f732..c4ffdf4 100644
--- a/drivers/net/ethernet/ti/netcp.h
+++ b/drivers/net/ethernet/ti/netcp.h
@@ -214,6 +214,7 @@ struct netcp_module {
 	int	(*add_vid)(void *intf_priv, int vid);
 	int	(*del_vid)(void *intf_priv, int vid);
 	int	(*ioctl)(void *intf_priv, struct ifreq *req, int cmd);
+	int	(*set_rx_mode)(void *intf_priv, bool promisc);
 
 	/* used internally */
 	struct list_head	module_list;
diff --git a/drivers/net/ethernet/ti/netcp_core.c b/drivers/net/ethernet/ti/netcp_core.c
index 736f6f7..e40aa3e 100644
--- a/drivers/net/ethernet/ti/netcp_core.c
+++ b/drivers/net/ethernet/ti/netcp_core.c
@@ -1509,6 +1509,24 @@ static void netcp_addr_sweep_add(struct netcp_intf *netcp)
 	}
 }
 
+static int netcp_set_promiscuous(struct netcp_intf *netcp, bool promisc)
+{
+	struct netcp_intf_modpriv *priv;
+	struct netcp_module *module;
+	int error;
+
+	for_each_module(netcp, priv) {
+		module = priv->netcp_module;
+		if (!module->set_rx_mode)
+			continue;
+
+		error = module->set_rx_mode(priv->module_priv, promisc);
+		if (error)
+			return error;
+	}
+	return 0;
+}
+
 static void netcp_set_rx_mode(struct net_device *ndev)
 {
 	struct netcp_intf *netcp = netdev_priv(ndev);
@@ -1538,6 +1556,7 @@ static void netcp_set_rx_mode(struct net_device *ndev)
 	/* finally sweep and callout into modules */
 	netcp_addr_sweep_del(netcp);
 	netcp_addr_sweep_add(netcp);
+	netcp_set_promiscuous(netcp, promisc);
 	spin_unlock(&netcp->lock);
 }
 
-- 
1.9.1

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

* [net-next 2/2] net: netcp: ethss: k2g: add promiscuous mode support
  2018-04-02 16:17 [net-next 0/2] Add promiscous mode support in k2g network driver Murali Karicheri
  2018-04-02 16:17 ` [net-next 1/2] net: netcp: add api to support set rx mode in netcp modules Murali Karicheri
@ 2018-04-02 16:17 ` Murali Karicheri
  2018-04-02 16:47   ` Andrew Lunn
  2018-04-02 16:28 ` [net-next 0/2] Add promiscous mode support in k2g network driver David Miller
  2 siblings, 1 reply; 7+ messages in thread
From: Murali Karicheri @ 2018-04-02 16:17 UTC (permalink / raw)
  To: w-kwok2, linux-kernel, davem, netdev, nsekhar, grygorii.strashko

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 f7af999..1ac2cd6 100644
--- a/drivers/net/ethernet/ti/netcp_ethss.c
+++ b/drivers/net/ethernet/ti/netcp_ethss.c
@@ -2771,6 +2771,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;
@@ -3523,6 +3578,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

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

* Re: [net-next 0/2] Add promiscous mode support in k2g network driver
  2018-04-02 16:17 [net-next 0/2] Add promiscous mode support in k2g network driver Murali Karicheri
  2018-04-02 16:17 ` [net-next 1/2] net: netcp: add api to support set rx mode in netcp modules Murali Karicheri
  2018-04-02 16:17 ` [net-next 2/2] net: netcp: ethss: k2g: add promiscuous mode support Murali Karicheri
@ 2018-04-02 16:28 ` David Miller
  2018-04-02 18:42   ` Murali Karicheri
  2 siblings, 1 reply; 7+ messages in thread
From: David Miller @ 2018-04-02 16:28 UTC (permalink / raw)
  To: m-karicheri2; +Cc: w-kwok2, linux-kernel, netdev, nsekhar, grygorii.strashko

From: Murali Karicheri <m-karicheri2@ti.com>
Date: Mon, 2 Apr 2018 12:17:17 -0400

> This patch adds support for promiscuous mode in network driver for K2G
> SoC. This depends on v3 of my series at
> https://www.spinics.net/lists/kernel/msg2765942.html

The net-next tree is closed, please resubmit this series after the merge
window when the net-next tree is openned back up.

Thank you.

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

* Re: [net-next 2/2] net: netcp: ethss: k2g: add promiscuous mode support
  2018-04-02 16:17 ` [net-next 2/2] net: netcp: ethss: k2g: add promiscuous mode support Murali Karicheri
@ 2018-04-02 16:47   ` Andrew Lunn
  2018-04-02 18:40     ` Murali Karicheri
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Lunn @ 2018-04-02 16:47 UTC (permalink / raw)
  To: Murali Karicheri
  Cc: w-kwok2, linux-kernel, davem, netdev, nsekhar, grygorii.strashko

On Mon, Apr 02, 2018 at 12:17:19PM -0400, Murali Karicheri wrote:
> +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);
> +	}

Hi Murali

Does this mean that in promisc mode, switching of frames between ports
in hardware is disabled? You are relying on the software bridge to
perform such bridging between ports?

You might want to look at skb->offload_fwd_mark. By setting this, you
can tell the software bridge the hardware has already bridged the
frame. You might then be able to have promisc enabled, and the
hardware still doing the forwarding.

	 Andrew

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

* Re: [net-next 2/2] net: netcp: ethss: k2g: add promiscuous mode support
  2018-04-02 16:47   ` Andrew Lunn
@ 2018-04-02 18:40     ` Murali Karicheri
  0 siblings, 0 replies; 7+ messages in thread
From: Murali Karicheri @ 2018-04-02 18:40 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: w-kwok2, linux-kernel, davem, netdev, nsekhar, grygorii.strashko

Andrew,

Thanks for reviewing this!

On 04/02/2018 12:47 PM, Andrew Lunn wrote:
> On Mon, Apr 02, 2018 at 12:17:19PM -0400, Murali Karicheri wrote:
>> +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);
>> +	}
> 
> Hi Murali
> 
> Does this mean that in promisc mode, switching of frames between ports
> in hardware is disabled? You are relying on the software bridge to
> perform such bridging between ports?

The K2G switch has only one slave port. The other port is the host port.
So there is no switching applicable here. At the egress drivers provide 
frame with PS_FLAG to indicate which port the frame is forwarded to and
at the Ingress direction, it forward the received frame to the Host port
which is the only other port in a K2G switch (2u). To Implement
promiscuous mode, this requires ALE to be enabled and take advantage of
ALE feature to flood all received unicast frames to host port. In the 
non-promiscuous mode, it disables that feature. So only frames with
destination MAC address match is forwarded.

For other K2 devices that has more than one port available, what you say
is applicable. However we have not implemented the switch mode of these
devices with multiple ports and don't have plan to do the same anytime
in the future as this device is already matured and adding this feature
at this point doesn't make much sense now. The driver on these devices
currently bypass ALE and implement plain Ethernet interfaces (n port)
for Ethernet connectivity.

> 
> You might want to look at skb->offload_fwd_mark. By setting this, you
> can tell the software bridge the hardware has already bridged the
> frame. You might then be able to have promisc enabled, and the
> hardware still doing the forwarding.

Yes, if we decide to support switch mode for K2 devices, I will certainly
look at this and add support as you have suggested.

> 
> 	 Andrew
> 


-- 
Murali Karicheri
Linux Kernel, Keystone

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

* Re: [net-next 0/2] Add promiscous mode support in k2g network driver
  2018-04-02 16:28 ` [net-next 0/2] Add promiscous mode support in k2g network driver David Miller
@ 2018-04-02 18:42   ` Murali Karicheri
  0 siblings, 0 replies; 7+ messages in thread
From: Murali Karicheri @ 2018-04-02 18:42 UTC (permalink / raw)
  To: David Miller; +Cc: w-kwok2, linux-kernel, netdev, nsekhar, grygorii.strashko

On 04/02/2018 12:28 PM, David Miller wrote:
> From: Murali Karicheri <m-karicheri2@ti.com>
> Date: Mon, 2 Apr 2018 12:17:17 -0400
> 
>> This patch adds support for promiscuous mode in network driver for K2G
>> SoC. This depends on v3 of my series at
>> https://www.spinics.net/lists/kernel/msg2765942.html
> 
> The net-next tree is closed, please resubmit this series after the merge
> window when the net-next tree is openned back up.
> 
> Thank you.
> 
Sure! As I have indicated in my cover letter, I will fold this
to the other series and re-submit it when the merge window opens.

Thanks
-- 
Murali Karicheri
Linux Kernel, Keystone

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

end of thread, other threads:[~2018-04-02 18:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-02 16:17 [net-next 0/2] Add promiscous mode support in k2g network driver Murali Karicheri
2018-04-02 16:17 ` [net-next 1/2] net: netcp: add api to support set rx mode in netcp modules Murali Karicheri
2018-04-02 16:17 ` [net-next 2/2] net: netcp: ethss: k2g: add promiscuous mode support Murali Karicheri
2018-04-02 16:47   ` Andrew Lunn
2018-04-02 18:40     ` Murali Karicheri
2018-04-02 16:28 ` [net-next 0/2] Add promiscous mode support in k2g network driver David Miller
2018-04-02 18:42   ` Murali Karicheri

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