From: Prasanna Vengateshan <prasanna.vengateshan@microchip.com>
To: <andrew@lunn.ch>, <netdev@vger.kernel.org>, <olteanv@gmail.com>,
<robh+dt@kernel.org>
Cc: <UNGLinuxDriver@microchip.com>, <woojung.huh@microchip.com>,
<hkallweit1@gmail.com>, <linux@armlinux.org.uk>,
<davem@davemloft.net>, <kuba@kernel.org>,
<linux-kernel@vger.kernel.org>, <vivien.didelot@gmail.com>,
<f.fainelli@gmail.com>, <devicetree@vger.kernel.org>,
<pabeni@redhat.com>
Subject: [RFC PATCH v11 net-next 08/10] net: dsa: microchip: add support for port mirror operations
Date: Fri, 25 Mar 2022 22:23:39 +0530 [thread overview]
Message-ID: <20220325165341.791013-9-prasanna.vengateshan@microchip.com> (raw)
In-Reply-To: <20220325165341.791013-1-prasanna.vengateshan@microchip.com>
Added support for port_mirror_add() and port_mirror_del operations
Sniffing is limited to one port & alert the user if any new
sniffing port is selected
Signed-off-by: Prasanna Vengateshan <prasanna.vengateshan@microchip.com>
Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
---
drivers/net/dsa/microchip/lan937x_main.c | 83 ++++++++++++++++++++++++
1 file changed, 83 insertions(+)
diff --git a/drivers/net/dsa/microchip/lan937x_main.c b/drivers/net/dsa/microchip/lan937x_main.c
index 51640234dda6..504b9a4edea2 100644
--- a/drivers/net/dsa/microchip/lan937x_main.c
+++ b/drivers/net/dsa/microchip/lan937x_main.c
@@ -98,6 +98,87 @@ static void lan937x_port_stp_state_set(struct dsa_switch *ds, int port,
ksz_update_port_member(dev, port);
}
+static int lan937x_port_mirror_add(struct dsa_switch *ds, int port,
+ struct dsa_mall_mirror_tc_entry *mirror,
+ bool ingress, struct netlink_ext_ack *extack)
+{
+ struct ksz_device *dev = ds->priv;
+ int ret, p;
+ u8 data;
+
+ /* Limit to one sniffer port
+ * Check if any of the port is already set for sniffing
+ * If yes, instruct the user to remove the previous entry & exit
+ */
+ for (p = 0; p < dev->port_cnt; p++) {
+ /* Skip the current sniffing port */
+ if (p == mirror->to_local_port)
+ continue;
+
+ ret = lan937x_pread8(dev, p, P_MIRROR_CTRL, &data);
+ if (ret < 0)
+ return ret;
+
+ if (data & PORT_MIRROR_SNIFFER) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Sniffer port is already configured, delete existing rules & retry");
+ return -EBUSY;
+ }
+ }
+
+ /* Configure ingress/egress mirroring */
+ if (ingress)
+ ret = lan937x_port_cfg(dev, port, P_MIRROR_CTRL, PORT_MIRROR_RX,
+ true);
+ else
+ ret = lan937x_port_cfg(dev, port, P_MIRROR_CTRL, PORT_MIRROR_TX,
+ true);
+ if (ret < 0)
+ return ret;
+
+ /* Configure sniffer port as other ports do not have
+ * PORT_MIRROR_SNIFFER is set
+ */
+ ret = lan937x_port_cfg(dev, mirror->to_local_port, P_MIRROR_CTRL,
+ PORT_MIRROR_SNIFFER, true);
+ if (ret < 0)
+ return ret;
+
+ return lan937x_cfg(dev, S_MIRROR_CTRL, SW_MIRROR_RX_TX, false);
+}
+
+static void lan937x_port_mirror_del(struct dsa_switch *ds, int port,
+ struct dsa_mall_mirror_tc_entry *mirror)
+{
+ struct ksz_device *dev = ds->priv;
+ bool in_use = false;
+ u8 data;
+ int p;
+
+ /* clear ingress/egress mirroring port */
+ if (mirror->ingress)
+ lan937x_port_cfg(dev, port, P_MIRROR_CTRL, PORT_MIRROR_RX,
+ false);
+ else
+ lan937x_port_cfg(dev, port, P_MIRROR_CTRL, PORT_MIRROR_TX,
+ false);
+
+ /* Check if any of the port is still referring to sniffer port */
+ for (p = 0; p < dev->port_cnt; p++) {
+ lan937x_pread8(dev, p, P_MIRROR_CTRL, &data);
+
+ if ((data & (PORT_MIRROR_RX | PORT_MIRROR_TX))) {
+ in_use = true;
+ break;
+ }
+ }
+
+ /* delete sniffing if there are no other mirroring rule exist */
+ if (!in_use)
+ lan937x_port_cfg(dev, mirror->to_local_port, P_MIRROR_CTRL,
+ PORT_MIRROR_SNIFFER, false);
+}
+
static void lan937x_config_cpu_port(struct dsa_switch *ds)
{
struct ksz_device *dev = ds->priv;
@@ -485,6 +566,8 @@ const struct dsa_switch_ops lan937x_switch_ops = {
.port_bridge_leave = ksz_port_bridge_leave,
.port_stp_state_set = lan937x_port_stp_state_set,
.port_fast_age = ksz_port_fast_age,
+ .port_mirror_add = lan937x_port_mirror_add,
+ .port_mirror_del = lan937x_port_mirror_del,
.port_max_mtu = lan937x_get_max_mtu,
.port_change_mtu = lan937x_change_mtu,
.phylink_get_caps = lan937x_phylink_get_caps,
--
2.30.2
next prev parent reply other threads:[~2022-03-25 16:55 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-25 16:53 [RFC PATCH v11 net-next 00/10] net: dsa: microchip: DSA driver support for LAN937x switch Prasanna Vengateshan
2022-03-25 16:53 ` [RFC PATCH v11 net-next 01/10] dt-bindings: net: make internal-delay-ps based on phy-mode Prasanna Vengateshan
2022-03-29 20:41 ` Rob Herring
2022-03-25 16:53 ` [RFC PATCH v11 net-next 02/10] dt-bindings: net: dsa: dt bindings for microchip lan937x Prasanna Vengateshan
2022-04-08 22:40 ` Vladimir Oltean
2022-03-25 16:53 ` [RFC PATCH v11 net-next 03/10] net: dsa: move mib->cnt_ptr reset code to ksz_common.c Prasanna Vengateshan
2022-03-25 16:53 ` [RFC PATCH v11 net-next 04/10] net: dsa: tag_ksz: add tag handling for Microchip LAN937x Prasanna Vengateshan
2022-03-25 16:53 ` [RFC PATCH v11 net-next 05/10] net: dsa: microchip: add DSA support for microchip lan937x Prasanna Vengateshan
2022-04-08 23:25 ` Vladimir Oltean
2022-03-25 16:53 ` [RFC PATCH v11 net-next 06/10] net: dsa: microchip: add support for phylink management Prasanna Vengateshan
2022-04-08 23:41 ` Vladimir Oltean
2022-04-29 15:58 ` Russell King (Oracle)
2022-03-25 16:53 ` [RFC PATCH v11 net-next 07/10] net: dsa: microchip: add support for ethtool port counters Prasanna Vengateshan
2022-03-25 16:53 ` Prasanna Vengateshan [this message]
2022-03-25 16:53 ` [RFC PATCH v11 net-next 09/10] net: dsa: microchip: add support for fdb and mdb management Prasanna Vengateshan
2022-03-25 16:53 ` [RFC PATCH v11 net-next 10/10] net: dsa: microchip: add support for vlan operations Prasanna Vengateshan
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=20220325165341.791013-9-prasanna.vengateshan@microchip.com \
--to=prasanna.vengateshan@microchip.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=f.fainelli@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=robh+dt@kernel.org \
--cc=vivien.didelot@gmail.com \
--cc=woojung.huh@microchip.com \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).