Commit 2fda45f0 authored by Marek Behún's avatar Marek Behún Committed by David S. Miller

net: dsa: mv88e6xxx: wrap .set_egress_port method

There are two implementations of the .set_egress_port method, and both
of them, if successful, set chip->*gress_dest_port variable.

To avoid code repetition, wrap this method into
mv88e6xxx_set_egress_port.
Signed-off-by: default avatarMarek Behún <kabel@kernel.org>
Reviewed-by: default avatarPavana Sharma <pavana.sharma@digi.com>
Reviewed-by: default avatarVladimir Oltean <olteanv@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 193c5b26
...@@ -2550,6 +2550,27 @@ static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port, ...@@ -2550,6 +2550,27 @@ static int mv88e6xxx_serdes_power(struct mv88e6xxx_chip *chip, int port,
return err; return err;
} }
static int mv88e6xxx_set_egress_port(struct mv88e6xxx_chip *chip,
enum mv88e6xxx_egress_direction direction,
int port)
{
int err;
if (!chip->info->ops->set_egress_port)
return -EOPNOTSUPP;
err = chip->info->ops->set_egress_port(chip, direction, port);
if (err)
return err;
if (direction == MV88E6XXX_EGRESS_DIR_INGRESS)
chip->ingress_dest_port = port;
else
chip->egress_dest_port = port;
return 0;
}
static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port) static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
{ {
struct dsa_switch *ds = chip->ds; struct dsa_switch *ds = chip->ds;
...@@ -2572,19 +2593,17 @@ static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port) ...@@ -2572,19 +2593,17 @@ static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)
return err; return err;
} }
if (chip->info->ops->set_egress_port) { err = mv88e6xxx_set_egress_port(chip,
err = chip->info->ops->set_egress_port(chip,
MV88E6XXX_EGRESS_DIR_INGRESS, MV88E6XXX_EGRESS_DIR_INGRESS,
upstream_port); upstream_port);
if (err) if (err && err != -EOPNOTSUPP)
return err; return err;
err = chip->info->ops->set_egress_port(chip, err = mv88e6xxx_set_egress_port(chip,
MV88E6XXX_EGRESS_DIR_EGRESS, MV88E6XXX_EGRESS_DIR_EGRESS,
upstream_port); upstream_port);
if (err) if (err && err != -EOPNOTSUPP)
return err; return err;
}
} }
return 0; return 0;
...@@ -5338,9 +5357,6 @@ static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port, ...@@ -5338,9 +5357,6 @@ static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
int i; int i;
int err; int err;
if (!chip->info->ops->set_egress_port)
return -EOPNOTSUPP;
mutex_lock(&chip->reg_lock); mutex_lock(&chip->reg_lock);
if ((ingress ? chip->ingress_dest_port : chip->egress_dest_port) != if ((ingress ? chip->ingress_dest_port : chip->egress_dest_port) !=
mirror->to_local_port) { mirror->to_local_port) {
...@@ -5355,9 +5371,8 @@ static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port, ...@@ -5355,9 +5371,8 @@ static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
goto out; goto out;
} }
err = chip->info->ops->set_egress_port(chip, err = mv88e6xxx_set_egress_port(chip, direction,
direction, mirror->to_local_port);
mirror->to_local_port);
if (err) if (err)
goto out; goto out;
} }
...@@ -5390,10 +5405,8 @@ static void mv88e6xxx_port_mirror_del(struct dsa_switch *ds, int port, ...@@ -5390,10 +5405,8 @@ static void mv88e6xxx_port_mirror_del(struct dsa_switch *ds, int port,
/* Reset egress port when no other mirror is active */ /* Reset egress port when no other mirror is active */
if (!other_mirrors) { if (!other_mirrors) {
if (chip->info->ops->set_egress_port(chip, if (mv88e6xxx_set_egress_port(chip, direction,
direction, dsa_upstream_port(ds, port)))
dsa_upstream_port(ds,
port)))
dev_err(ds->dev, "failed to set egress port\n"); dev_err(ds->dev, "failed to set egress port\n");
} }
......
...@@ -315,7 +315,6 @@ int mv88e6095_g1_set_egress_port(struct mv88e6xxx_chip *chip, ...@@ -315,7 +315,6 @@ int mv88e6095_g1_set_egress_port(struct mv88e6xxx_chip *chip,
enum mv88e6xxx_egress_direction direction, enum mv88e6xxx_egress_direction direction,
int port) int port)
{ {
int *dest_port_chip;
u16 reg; u16 reg;
int err; int err;
...@@ -325,13 +324,11 @@ int mv88e6095_g1_set_egress_port(struct mv88e6xxx_chip *chip, ...@@ -325,13 +324,11 @@ int mv88e6095_g1_set_egress_port(struct mv88e6xxx_chip *chip,
switch (direction) { switch (direction) {
case MV88E6XXX_EGRESS_DIR_INGRESS: case MV88E6XXX_EGRESS_DIR_INGRESS:
dest_port_chip = &chip->ingress_dest_port;
reg &= ~MV88E6185_G1_MONITOR_CTL_INGRESS_DEST_MASK; reg &= ~MV88E6185_G1_MONITOR_CTL_INGRESS_DEST_MASK;
reg |= port << reg |= port <<
__bf_shf(MV88E6185_G1_MONITOR_CTL_INGRESS_DEST_MASK); __bf_shf(MV88E6185_G1_MONITOR_CTL_INGRESS_DEST_MASK);
break; break;
case MV88E6XXX_EGRESS_DIR_EGRESS: case MV88E6XXX_EGRESS_DIR_EGRESS:
dest_port_chip = &chip->egress_dest_port;
reg &= ~MV88E6185_G1_MONITOR_CTL_EGRESS_DEST_MASK; reg &= ~MV88E6185_G1_MONITOR_CTL_EGRESS_DEST_MASK;
reg |= port << reg |= port <<
__bf_shf(MV88E6185_G1_MONITOR_CTL_EGRESS_DEST_MASK); __bf_shf(MV88E6185_G1_MONITOR_CTL_EGRESS_DEST_MASK);
...@@ -340,11 +337,7 @@ int mv88e6095_g1_set_egress_port(struct mv88e6xxx_chip *chip, ...@@ -340,11 +337,7 @@ int mv88e6095_g1_set_egress_port(struct mv88e6xxx_chip *chip,
return -EINVAL; return -EINVAL;
} }
err = mv88e6xxx_g1_write(chip, MV88E6185_G1_MONITOR_CTL, reg); return mv88e6xxx_g1_write(chip, MV88E6185_G1_MONITOR_CTL, reg);
if (!err)
*dest_port_chip = port;
return err;
} }
/* Older generations also call this the ARP destination. It has been /* Older generations also call this the ARP destination. It has been
...@@ -380,28 +373,20 @@ int mv88e6390_g1_set_egress_port(struct mv88e6xxx_chip *chip, ...@@ -380,28 +373,20 @@ int mv88e6390_g1_set_egress_port(struct mv88e6xxx_chip *chip,
enum mv88e6xxx_egress_direction direction, enum mv88e6xxx_egress_direction direction,
int port) int port)
{ {
int *dest_port_chip;
u16 ptr; u16 ptr;
int err;
switch (direction) { switch (direction) {
case MV88E6XXX_EGRESS_DIR_INGRESS: case MV88E6XXX_EGRESS_DIR_INGRESS:
dest_port_chip = &chip->ingress_dest_port;
ptr = MV88E6390_G1_MONITOR_MGMT_CTL_PTR_INGRESS_DEST; ptr = MV88E6390_G1_MONITOR_MGMT_CTL_PTR_INGRESS_DEST;
break; break;
case MV88E6XXX_EGRESS_DIR_EGRESS: case MV88E6XXX_EGRESS_DIR_EGRESS:
dest_port_chip = &chip->egress_dest_port;
ptr = MV88E6390_G1_MONITOR_MGMT_CTL_PTR_EGRESS_DEST; ptr = MV88E6390_G1_MONITOR_MGMT_CTL_PTR_EGRESS_DEST;
break; break;
default: default:
return -EINVAL; return -EINVAL;
} }
err = mv88e6390_g1_monitor_write(chip, ptr, port); return mv88e6390_g1_monitor_write(chip, ptr, port);
if (!err)
*dest_port_chip = port;
return err;
} }
int mv88e6390_g1_set_cpu_port(struct mv88e6xxx_chip *chip, int port) int mv88e6390_g1_set_cpu_port(struct mv88e6xxx_chip *chip, int port)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment