Commit e545f865 authored by Tobias Waldekranz's avatar Tobias Waldekranz Committed by Jakub Kicinski
Browse files

net: dsa: mv88e6xxx: Add helper to get a chip's max_vid



Most of the other chip info constants have helpers to get at them; add
one for max_vid to keep things consistent.

Suggested-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarTobias Waldekranz <tobias@waldekranz.com>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Link: https://lore.kernel.org/r/20201110185720.18228-1-tobias@waldekranz.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent ca787e0b
Loading
Loading
Loading
Loading
+9 −9
Original line number Original line Diff line number Diff line
@@ -1442,7 +1442,7 @@ static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port)


static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip)
{
{
	if (!chip->info->max_vid)
	if (!mv88e6xxx_max_vid(chip))
		return 0;
		return 0;


	return mv88e6xxx_g1_vtu_flush(chip);
	return mv88e6xxx_g1_vtu_flush(chip);
@@ -1484,7 +1484,7 @@ int mv88e6xxx_fid_map(struct mv88e6xxx_chip *chip, unsigned long *fid_bitmap)
	}
	}


	/* Set every FID bit used by the VLAN entries */
	/* Set every FID bit used by the VLAN entries */
	vlan.vid = chip->info->max_vid;
	vlan.vid = mv88e6xxx_max_vid(chip);
	vlan.valid = false;
	vlan.valid = false;


	do {
	do {
@@ -1496,7 +1496,7 @@ int mv88e6xxx_fid_map(struct mv88e6xxx_chip *chip, unsigned long *fid_bitmap)
			break;
			break;


		set_bit(vlan.fid, fid_bitmap);
		set_bit(vlan.fid, fid_bitmap);
	} while (vlan.vid < chip->info->max_vid);
	} while (vlan.vid < mv88e6xxx_max_vid(chip));


	return 0;
	return 0;
}
}
@@ -1587,7 +1587,7 @@ static int mv88e6xxx_port_vlan_filtering(struct dsa_switch *ds, int port,
	int err;
	int err;


	if (switchdev_trans_ph_prepare(trans))
	if (switchdev_trans_ph_prepare(trans))
		return chip->info->max_vid ? 0 : -EOPNOTSUPP;
		return mv88e6xxx_max_vid(chip) ? 0 : -EOPNOTSUPP;


	mv88e6xxx_reg_lock(chip);
	mv88e6xxx_reg_lock(chip);
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
	err = mv88e6xxx_port_set_8021q_mode(chip, port, mode);
@@ -1603,7 +1603,7 @@ mv88e6xxx_port_vlan_prepare(struct dsa_switch *ds, int port,
	struct mv88e6xxx_chip *chip = ds->priv;
	struct mv88e6xxx_chip *chip = ds->priv;
	int err;
	int err;


	if (!chip->info->max_vid)
	if (!mv88e6xxx_max_vid(chip))
		return -EOPNOTSUPP;
		return -EOPNOTSUPP;


	/* If the requested port doesn't belong to the same bridge as the VLAN
	/* If the requested port doesn't belong to the same bridge as the VLAN
@@ -1973,7 +1973,7 @@ static void mv88e6xxx_port_vlan_add(struct dsa_switch *ds, int port,
	u8 member;
	u8 member;
	u16 vid;
	u16 vid;


	if (!chip->info->max_vid)
	if (!mv88e6xxx_max_vid(chip))
		return;
		return;


	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
	if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port))
@@ -2051,7 +2051,7 @@ static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port,
	u16 pvid, vid;
	u16 pvid, vid;
	int err = 0;
	int err = 0;


	if (!chip->info->max_vid)
	if (!mv88e6xxx_max_vid(chip))
		return -EOPNOTSUPP;
		return -EOPNOTSUPP;


	mv88e6xxx_reg_lock(chip);
	mv88e6xxx_reg_lock(chip);
@@ -2157,7 +2157,7 @@ static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
		return err;
		return err;


	/* Dump VLANs' Filtering Information Databases */
	/* Dump VLANs' Filtering Information Databases */
	vlan.vid = chip->info->max_vid;
	vlan.vid = mv88e6xxx_max_vid(chip);
	vlan.valid = false;
	vlan.valid = false;


	do {
	do {
@@ -2172,7 +2172,7 @@ static int mv88e6xxx_port_db_dump(struct mv88e6xxx_chip *chip, int port,
						 cb, data);
						 cb, data);
		if (err)
		if (err)
			return err;
			return err;
	} while (vlan.vid < chip->info->max_vid);
	} while (vlan.vid < mv88e6xxx_max_vid(chip));


	return err;
	return err;
}
}
+5 −0
Original line number Original line Diff line number Diff line
@@ -673,6 +673,11 @@ static inline unsigned int mv88e6xxx_num_ports(struct mv88e6xxx_chip *chip)
	return chip->info->num_ports;
	return chip->info->num_ports;
}
}


static inline unsigned int mv88e6xxx_max_vid(struct mv88e6xxx_chip *chip)
{
	return chip->info->max_vid;
}

static inline u16 mv88e6xxx_port_mask(struct mv88e6xxx_chip *chip)
static inline u16 mv88e6xxx_port_mask(struct mv88e6xxx_chip *chip)
{
{
	return GENMASK((s32)mv88e6xxx_num_ports(chip) - 1, 0);
	return GENMASK((s32)mv88e6xxx_num_ports(chip) - 1, 0);
+4 −4
Original line number Original line Diff line number Diff line
@@ -450,14 +450,14 @@ static int mv88e6xxx_region_vtu_snapshot(struct devlink *dl,
	struct mv88e6xxx_vtu_entry vlan;
	struct mv88e6xxx_vtu_entry vlan;
	int err;
	int err;


	table = kcalloc(chip->info->max_vid + 1,
	table = kcalloc(mv88e6xxx_max_vid(chip) + 1,
			sizeof(struct mv88e6xxx_devlink_vtu_entry),
			sizeof(struct mv88e6xxx_devlink_vtu_entry),
			GFP_KERNEL);
			GFP_KERNEL);
	if (!table)
	if (!table)
		return -ENOMEM;
		return -ENOMEM;


	entry = table;
	entry = table;
	vlan.vid = chip->info->max_vid;
	vlan.vid = mv88e6xxx_max_vid(chip);
	vlan.valid = false;
	vlan.valid = false;


	mv88e6xxx_reg_lock(chip);
	mv88e6xxx_reg_lock(chip);
@@ -488,7 +488,7 @@ static int mv88e6xxx_region_vtu_snapshot(struct devlink *dl,
			break;
			break;


		entry++;
		entry++;
	} while (vlan.vid < chip->info->max_vid);
	} while (vlan.vid < mv88e6xxx_max_vid(chip));


	mv88e6xxx_reg_unlock(chip);
	mv88e6xxx_reg_unlock(chip);


@@ -676,7 +676,7 @@ static int mv88e6xxx_setup_devlink_regions_global(struct dsa_switch *ds,
				sizeof(struct mv88e6xxx_devlink_atu_entry);
				sizeof(struct mv88e6xxx_devlink_atu_entry);
			break;
			break;
		case MV88E6XXX_REGION_VTU:
		case MV88E6XXX_REGION_VTU:
			size = chip->info->max_vid *
			size = mv88e6xxx_max_vid(chip) *
				sizeof(struct mv88e6xxx_devlink_vtu_entry);
				sizeof(struct mv88e6xxx_devlink_vtu_entry);
			break;
			break;
		}
		}