Commit d76c740b authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files

Merge branch 'net-dsa-microchip-ksz8-refactor-fdb-dump-path'

Oleksij Rempel says:

====================
net: dsa: microchip: ksz8: refactor FDB dump path

Refactor FDB dump code path for Microchip KSZ8xxx series. This series
mostly makes some cosmetic reworks and allows to forward errors detected
by the regmap.

Change logs are part of patch commit messages.
====================

Link: https://lore.kernel.org/r/20240403125039.3414824-1-o.rempel@pengutronix.de


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents abdce840 8d575812
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -19,8 +19,6 @@ void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port);
void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port);
int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val);
int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val);
int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, u8 *mac_addr,
			 u8 *fid, u8 *src_port, u8 *timestamp, u16 *entries);
void ksz8_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, u64 *cnt);
void ksz8_r_mib_pkt(struct ksz_device *dev, int port, u16 addr,
		    u64 *dropped, u64 *cnt);
+68 −67
Original line number Diff line number Diff line
@@ -385,39 +385,39 @@ static int ksz8_valid_dyn_entry(struct ksz_device *dev, u8 *data)
	int timeout = 100;
	const u32 *masks;
	const u16 *regs;
	int ret;

	masks = dev->info->masks;
	regs = dev->info->regs;

	do {
		ksz_read8(dev, regs[REG_IND_DATA_CHECK], data);
		ret = ksz_read8(dev, regs[REG_IND_DATA_CHECK], data);
		if (ret)
			return ret;

		timeout--;
	} while ((*data & masks[DYNAMIC_MAC_TABLE_NOT_READY]) && timeout);

	/* Entry is not ready for accessing. */
	if (*data & masks[DYNAMIC_MAC_TABLE_NOT_READY]) {
		return -EAGAIN;
	/* Entry is ready for accessing. */
	} else {
		ksz_read8(dev, regs[REG_IND_DATA_8], data);
	if (*data & masks[DYNAMIC_MAC_TABLE_NOT_READY])
		return -ETIMEDOUT;

		/* There is no valid entry in the table. */
		if (*data & masks[DYNAMIC_MAC_TABLE_MAC_EMPTY])
			return -ENXIO;
	}
	return 0;
	/* Entry is ready for accessing. */
	return ksz_read8(dev, regs[REG_IND_DATA_8], data);
}

int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, u8 *mac_addr,
			 u8 *fid, u8 *src_port, u8 *timestamp, u16 *entries)
static int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, u8 *mac_addr,
				u8 *fid, u8 *src_port, u16 *entries)
{
	u32 data_hi, data_lo;
	const u8 *shifts;
	const u32 *masks;
	const u16 *regs;
	u16 ctrl_addr;
	u64 buf = 0;
	u8 data;
	int rc;
	int cnt;
	int ret;

	shifts = dev->info->shifts;
	masks = dev->info->masks;
@@ -426,20 +426,23 @@ int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, u8 *mac_addr,
	ctrl_addr = IND_ACC_TABLE(TABLE_DYNAMIC_MAC | TABLE_READ) | addr;

	mutex_lock(&dev->alu_mutex);
	ksz_write16(dev, regs[REG_IND_CTRL_0], ctrl_addr);
	ret = ksz_write16(dev, regs[REG_IND_CTRL_0], ctrl_addr);
	if (ret)
		goto unlock_alu;

	rc = ksz8_valid_dyn_entry(dev, &data);
	if (rc == -EAGAIN) {
		if (addr == 0)
			*entries = 0;
	} else if (rc == -ENXIO) {
	ret = ksz8_valid_dyn_entry(dev, &data);
	if (ret)
		goto unlock_alu;

	if (data & masks[DYNAMIC_MAC_TABLE_MAC_EMPTY]) {
		*entries = 0;
	/* At least one valid entry in the table. */
	} else {
		u64 buf = 0;
		int cnt;
		goto unlock_alu;
	}

	ret = ksz_read64(dev, regs[REG_IND_DATA_HI], &buf);
	if (ret)
		goto unlock_alu;

		ksz_read64(dev, regs[REG_IND_DATA_HI], &buf);
	data_hi = (u32)(buf >> 32);
	data_lo = (u32)buf;

@@ -454,8 +457,6 @@ int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, u8 *mac_addr,
		shifts[DYNAMIC_MAC_FID];
	*src_port = (data_hi & masks[DYNAMIC_MAC_TABLE_SRC_PORT]) >>
		shifts[DYNAMIC_MAC_SRC_PORT];
		*timestamp = (data_hi & masks[DYNAMIC_MAC_TABLE_TIMESTAMP]) >>
			shifts[DYNAMIC_MAC_TIMESTAMP];

	mac_addr[5] = (u8)data_lo;
	mac_addr[4] = (u8)(data_lo >> 8);
@@ -464,11 +465,11 @@ int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, u8 *mac_addr,

	mac_addr[1] = (u8)data_hi;
	mac_addr[0] = (u8)(data_hi >> 8);
		rc = 0;
	}

unlock_alu:
	mutex_unlock(&dev->alu_mutex);

	return rc;
	return ret;
}

static int ksz8_r_sta_mac_table(struct ksz_device *dev, u16 addr,
@@ -1193,29 +1194,29 @@ void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port)
int ksz8_fdb_dump(struct ksz_device *dev, int port,
		  dsa_fdb_dump_cb_t *cb, void *data)
{
	int ret = 0;
	u16 i = 0;
	u16 entries = 0;
	u8 timestamp = 0;
	u8 fid;
	u8 src_port;
	u8 mac[ETH_ALEN];
	u8 src_port, fid;
	u16 entries = 0;
	int ret, i;

	do {
	for (i = 0; i < KSZ8_DYN_MAC_ENTRIES; i++) {
		ret = ksz8_r_dyn_mac_table(dev, i, mac, &fid, &src_port,
					   &timestamp, &entries);
		if (!ret && port == src_port) {
			ret = cb(mac, fid, false, data);
					   &entries);
		if (ret)
				break;
		}
		i++;
	} while (i < entries);
			return ret;

		if (i >= entries)
		ret = 0;
			return 0;

		if (port == src_port) {
			ret = cb(mac, fid, false, data);
			if (ret)
				return ret;
		}
	}

	return 0;
}

static int ksz8_add_sta_mac(struct ksz_device *dev, int port,
			    const unsigned char *addr, u16 vid)
+1 −0
Original line number Diff line number Diff line
@@ -794,5 +794,6 @@
#define TAIL_TAG_LOOKUP			BIT(7)

#define FID_ENTRIES			128
#define KSZ8_DYN_MAC_ENTRIES		1024

#endif