Skip to content

Commit 4bdf79d

Browse files
triha2workdavem330
authored andcommitted
net: dsa: microchip: correct KSZ8795 static MAC table access
The KSZ8795 driver code was modified to use on KSZ8863/73, which has different register definitions. Some of the new KSZ8795 register information are wrong compared to previous code. KSZ8795 also behaves differently in that the STATIC_MAC_TABLE_USE_FID and STATIC_MAC_TABLE_FID bits are off by 1 when doing MAC table reading than writing. To compensate that a special code was added to shift the register value by 1 before applying those bits. This is wrong when the code is running on KSZ8863, so this special code is only executed when KSZ8795 is detected. Fixes: 4b20a07 ("net: dsa: microchip: ksz8795: add support for ksz88xx chips") Signed-off-by: Tristram Ha <[email protected]> Reviewed-by: Horatiu Vultur <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6e8778f commit 4bdf79d

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

drivers/net/dsa/microchip/ksz8795.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,13 @@ static int ksz8_r_sta_mac_table(struct ksz_device *dev, u16 addr,
506506
(data_hi & masks[STATIC_MAC_TABLE_FWD_PORTS]) >>
507507
shifts[STATIC_MAC_FWD_PORTS];
508508
alu->is_override = (data_hi & masks[STATIC_MAC_TABLE_OVERRIDE]) ? 1 : 0;
509-
data_hi >>= 1;
509+
510+
/* KSZ8795 family switches have STATIC_MAC_TABLE_USE_FID and
511+
* STATIC_MAC_TABLE_FID definitions off by 1 when doing read on the
512+
* static MAC table compared to doing write.
513+
*/
514+
if (ksz_is_ksz87xx(dev))
515+
data_hi >>= 1;
510516
alu->is_static = true;
511517
alu->is_use_fid = (data_hi & masks[STATIC_MAC_TABLE_USE_FID]) ? 1 : 0;
512518
alu->fid = (data_hi & masks[STATIC_MAC_TABLE_FID]) >>

drivers/net/dsa/microchip/ksz_common.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,13 @@ static const u32 ksz8795_masks[] = {
331331
[STATIC_MAC_TABLE_VALID] = BIT(21),
332332
[STATIC_MAC_TABLE_USE_FID] = BIT(23),
333333
[STATIC_MAC_TABLE_FID] = GENMASK(30, 24),
334-
[STATIC_MAC_TABLE_OVERRIDE] = BIT(26),
335-
[STATIC_MAC_TABLE_FWD_PORTS] = GENMASK(24, 20),
334+
[STATIC_MAC_TABLE_OVERRIDE] = BIT(22),
335+
[STATIC_MAC_TABLE_FWD_PORTS] = GENMASK(20, 16),
336336
[DYNAMIC_MAC_TABLE_ENTRIES_H] = GENMASK(6, 0),
337-
[DYNAMIC_MAC_TABLE_MAC_EMPTY] = BIT(8),
337+
[DYNAMIC_MAC_TABLE_MAC_EMPTY] = BIT(7),
338338
[DYNAMIC_MAC_TABLE_NOT_READY] = BIT(7),
339339
[DYNAMIC_MAC_TABLE_ENTRIES] = GENMASK(31, 29),
340-
[DYNAMIC_MAC_TABLE_FID] = GENMASK(26, 20),
340+
[DYNAMIC_MAC_TABLE_FID] = GENMASK(22, 16),
341341
[DYNAMIC_MAC_TABLE_SRC_PORT] = GENMASK(26, 24),
342342
[DYNAMIC_MAC_TABLE_TIMESTAMP] = GENMASK(28, 27),
343343
[P_MII_TX_FLOW_CTRL] = BIT(5),

drivers/net/dsa/microchip/ksz_common.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,13 @@ static inline void ksz_regmap_unlock(void *__mtx)
601601
mutex_unlock(mtx);
602602
}
603603

604+
static inline bool ksz_is_ksz87xx(struct ksz_device *dev)
605+
{
606+
return dev->chip_id == KSZ8795_CHIP_ID ||
607+
dev->chip_id == KSZ8794_CHIP_ID ||
608+
dev->chip_id == KSZ8765_CHIP_ID;
609+
}
610+
604611
static inline bool ksz_is_ksz88x3(struct ksz_device *dev)
605612
{
606613
return dev->chip_id == KSZ8830_CHIP_ID;

0 commit comments

Comments
 (0)