[net-next,v2,1/2] net: dsa: mv88e6xxx: Split monitor port configuration
diff mbox series

Message ID 20191021210143.119426-2-irtimmer@gmail.com
State Changes Requested
Delegated to: David Miller
Headers show
Series
  • net: dsa: mv88e6xxx: Add support for port mirroring
Related show

Commit Message

Iwan R Timmer Oct. 21, 2019, 9:01 p.m. UTC
Separate the configuration of the egress and ingress monitor port.
This allows the port mirror functionality to do ingress and egress
port mirroring to separate ports.

Signed-off-by: Iwan R Timmer <irtimmer@gmail.com>
---
 drivers/net/dsa/mv88e6xxx/chip.c    |  9 ++++++++-
 drivers/net/dsa/mv88e6xxx/chip.h    |  3 ++-
 drivers/net/dsa/mv88e6xxx/global1.c | 23 +++++++++++------------
 drivers/net/dsa/mv88e6xxx/global1.h |  6 ++++--
 4 files changed, 25 insertions(+), 16 deletions(-)

Comments

Andrew Lunn Oct. 23, 2019, 1:06 a.m. UTC | #1
On Mon, Oct 21, 2019 at 11:01:42PM +0200, Iwan R Timmer wrote:
> Separate the configuration of the egress and ingress monitor port.
> This allows the port mirror functionality to do ingress and egress
> port mirroring to separate ports.
> 
> Signed-off-by: Iwan R Timmer <irtimmer@gmail.com>
> ---
>  drivers/net/dsa/mv88e6xxx/chip.c    |  9 ++++++++-
>  drivers/net/dsa/mv88e6xxx/chip.h    |  3 ++-
>  drivers/net/dsa/mv88e6xxx/global1.c | 23 +++++++++++------------
>  drivers/net/dsa/mv88e6xxx/global1.h |  6 ++++--
>  4 files changed, 25 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
> index 6787d560e9e3..e9735346838d 100644
> --- a/drivers/net/dsa/mv88e6xxx/chip.c
> +++ b/drivers/net/dsa/mv88e6xxx/chip.c
> @@ -2378,7 +2378,14 @@ static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
>  
>  		if (chip->info->ops->set_egress_port) {
>  			err = chip->info->ops->set_egress_port(chip,
> -							       upstream_port);
> +							       true,
> +							       upstream_port);
> +			if (err)
> +				return err;
> +
> +			err = chip->info->ops->set_egress_port(chip,
> +							       false,
> +							       upstream_port);

Hi Iwam

I never find true/false very simple to understand. Please could you
add an enum. We already have

enum mv88e6xxx_egress_mode {
        MV88E6XXX_EGRESS_MODE_UNMODIFIED,
        MV88E6XXX_EGRESS_MODE_UNTAGGED,
        MV88E6XXX_EGRESS_MODE_TAGGED,
        MV88E6XXX_EGRESS_MODE_ETHERTYPE,
};

so maybe

enum mv88e6xxx_egress_direction {
        MV88E6XXX_EGRESS_DIR_INGRESS,
        MV88E6XXX_EGRESS_DIR_EGRESS,
};

Otherwise the spirit of the patch is O.K.

	  Andrew

Patch
diff mbox series

diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index 6787d560e9e3..e9735346838d 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -2378,7 +2378,14 @@  static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
 
 		if (chip->info->ops->set_egress_port) {
 			err = chip->info->ops->set_egress_port(chip,
-							       upstream_port);
+							       true,
+							       upstream_port);
+			if (err)
+				return err;
+
+			err = chip->info->ops->set_egress_port(chip,
+							       false,
+							       upstream_port);
 			if (err)
 				return err;
 		}
diff --git a/drivers/net/dsa/mv88e6xxx/chip.h b/drivers/net/dsa/mv88e6xxx/chip.h
index e9b1a1ac9a8e..42ce3109ebc9 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.h
+++ b/drivers/net/dsa/mv88e6xxx/chip.h
@@ -464,7 +464,8 @@  struct mv88e6xxx_ops {
 	int (*stats_get_stats)(struct mv88e6xxx_chip *chip,  int port,
 			       uint64_t *data);
 	int (*set_cpu_port)(struct mv88e6xxx_chip *chip, int port);
-	int (*set_egress_port)(struct mv88e6xxx_chip *chip, int port);
+	int (*set_egress_port)(struct mv88e6xxx_chip *chip, bool ingress,
+			       int port);
 
 #define MV88E6XXX_CASCADE_PORT_NONE		0xe
 #define MV88E6XXX_CASCADE_PORT_MULTIPLE		0xf
diff --git a/drivers/net/dsa/mv88e6xxx/global1.c b/drivers/net/dsa/mv88e6xxx/global1.c
index 25ec4c0ac589..35b9610cbe73 100644
--- a/drivers/net/dsa/mv88e6xxx/global1.c
+++ b/drivers/net/dsa/mv88e6xxx/global1.c
@@ -263,7 +263,8 @@  int mv88e6250_g1_ieee_pri_map(struct mv88e6xxx_chip *chip)
 /* Offset 0x1a: Monitor Control */
 /* Offset 0x1a: Monitor & MGMT Control on some devices */
 
-int mv88e6095_g1_set_egress_port(struct mv88e6xxx_chip *chip, int port)
+int mv88e6095_g1_set_egress_port(struct mv88e6xxx_chip *chip, bool ingress,
+				 int port)
 {
 	u16 reg;
 	int err;
@@ -272,11 +273,12 @@  int mv88e6095_g1_set_egress_port(struct mv88e6xxx_chip *chip, int port)
 	if (err)
 		return err;
 
-	reg &= ~(MV88E6185_G1_MONITOR_CTL_INGRESS_DEST_MASK |
-		 MV88E6185_G1_MONITOR_CTL_EGRESS_DEST_MASK);
+	reg &= ~(ingress ? MV88E6185_G1_MONITOR_CTL_INGRESS_DEST_MASK :
+			   MV88E6185_G1_MONITOR_CTL_EGRESS_DEST_MASK);
 
-	reg |= port << __bf_shf(MV88E6185_G1_MONITOR_CTL_INGRESS_DEST_MASK) |
-		port << __bf_shf(MV88E6185_G1_MONITOR_CTL_EGRESS_DEST_MASK);
+	reg |= port << (ingress ?
+	       __bf_shf(MV88E6185_G1_MONITOR_CTL_INGRESS_DEST_MASK) :
+	       __bf_shf(MV88E6185_G1_MONITOR_CTL_EGRESS_DEST_MASK));
 
 	return mv88e6xxx_g1_write(chip, MV88E6185_G1_MONITOR_CTL, reg);
 }
@@ -310,17 +312,14 @@  static int mv88e6390_g1_monitor_write(struct mv88e6xxx_chip *chip,
 	return mv88e6xxx_g1_write(chip, MV88E6390_G1_MONITOR_MGMT_CTL, reg);
 }
 
-int mv88e6390_g1_set_egress_port(struct mv88e6xxx_chip *chip, int port)
+int mv88e6390_g1_set_egress_port(struct mv88e6xxx_chip *chip, bool ingress,
+				 int port)
 {
 	u16 ptr;
 	int err;
 
-	ptr = MV88E6390_G1_MONITOR_MGMT_CTL_PTR_INGRESS_DEST;
-	err = mv88e6390_g1_monitor_write(chip, ptr, port);
-	if (err)
-		return err;
-
-	ptr = MV88E6390_G1_MONITOR_MGMT_CTL_PTR_EGRESS_DEST;
+	ptr = ingress ? MV88E6390_G1_MONITOR_MGMT_CTL_PTR_INGRESS_DEST :
+			MV88E6390_G1_MONITOR_MGMT_CTL_PTR_EGRESS_DEST;
 	err = mv88e6390_g1_monitor_write(chip, ptr, port);
 	if (err)
 		return err;
diff --git a/drivers/net/dsa/mv88e6xxx/global1.h b/drivers/net/dsa/mv88e6xxx/global1.h
index 0870fcc8bfc8..ef7e13f71927 100644
--- a/drivers/net/dsa/mv88e6xxx/global1.h
+++ b/drivers/net/dsa/mv88e6xxx/global1.h
@@ -287,8 +287,10 @@  int mv88e6095_g1_stats_set_histogram(struct mv88e6xxx_chip *chip);
 int mv88e6390_g1_stats_set_histogram(struct mv88e6xxx_chip *chip);
 void mv88e6xxx_g1_stats_read(struct mv88e6xxx_chip *chip, int stat, u32 *val);
 int mv88e6xxx_g1_stats_clear(struct mv88e6xxx_chip *chip);
-int mv88e6095_g1_set_egress_port(struct mv88e6xxx_chip *chip, int port);
-int mv88e6390_g1_set_egress_port(struct mv88e6xxx_chip *chip, int port);
+int mv88e6095_g1_set_egress_port(struct mv88e6xxx_chip *chip, bool ingress,
+				 int port);
+int mv88e6390_g1_set_egress_port(struct mv88e6xxx_chip *chip, bool ingress,
+				 int port);
 int mv88e6095_g1_set_cpu_port(struct mv88e6xxx_chip *chip, int port);
 int mv88e6390_g1_set_cpu_port(struct mv88e6xxx_chip *chip, int port);
 int mv88e6390_g1_mgmt_rsvd2cpu(struct mv88e6xxx_chip *chip);