From 177cc71eb0eec54a29b75e2e922e5fbc233fe68d Mon Sep 17 00:00:00 2001 From: Craig McQueen Date: Tue, 10 Jan 2023 17:16:37 +1100 Subject: [PATCH] ksz8795: Fix bit offsets for static MAC address table Refer to KSZ8795CLX data sheet, Microchip document DS00002112E, section 4.4 "Static MAC Address Table", table 4-16. Unusually, the bit locations of the "FID" and "Use FID" fields are different for reads and writes. For KSZ8863 (not needed for T4000 Pro but done for completeness), refer to KSZ8863 data sheet, Microchip document DS00002335C, section 4.6 "Static MAC Address Table", table 4-10. This is for Inner Range YouTrack item: T4000PRO-255 LAN2 was not working with the expected IP address range --- drivers/net/dsa/microchip/ksz8.h | 9 +++++--- drivers/net/dsa/microchip/ksz8795.c | 32 +++++++++++++++++------------ 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8.h b/drivers/net/dsa/microchip/ksz8.h index 9d611895d3cf..bb98cc3d89f6 100644 --- a/drivers/net/dsa/microchip/ksz8.h +++ b/drivers/net/dsa/microchip/ksz8.h @@ -34,8 +34,10 @@ enum ksz_masks { VLAN_TABLE_MEMBERSHIP, VLAN_TABLE_VALID, STATIC_MAC_TABLE_VALID, - STATIC_MAC_TABLE_USE_FID, - STATIC_MAC_TABLE_FID, + STATIC_MAC_TABLE_USE_FID_R, + STATIC_MAC_TABLE_USE_FID_W, + STATIC_MAC_TABLE_FID_R, + STATIC_MAC_TABLE_FID_W, STATIC_MAC_TABLE_OVERRIDE, STATIC_MAC_TABLE_FWD_PORTS, DYNAMIC_MAC_TABLE_ENTRIES_H, @@ -51,7 +53,8 @@ enum ksz_shifts { VLAN_TABLE_MEMBERSHIP_S, VLAN_TABLE, STATIC_MAC_FWD_PORTS, - STATIC_MAC_FID, + STATIC_MAC_FID_R, + STATIC_MAC_FID_W, DYNAMIC_MAC_ENTRIES_H, DYNAMIC_MAC_ENTRIES, DYNAMIC_MAC_FID, diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index c9c682352ac3..3c6fee9db038 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -50,10 +50,12 @@ static const u32 ksz8795_masks[] = { [VLAN_TABLE_MEMBERSHIP] = GENMASK(11, 7), [VLAN_TABLE_VALID] = BIT(12), [STATIC_MAC_TABLE_VALID] = BIT(21), - [STATIC_MAC_TABLE_USE_FID] = BIT(23), - [STATIC_MAC_TABLE_FID] = GENMASK(30, 24), - [STATIC_MAC_TABLE_OVERRIDE] = BIT(26), - [STATIC_MAC_TABLE_FWD_PORTS] = GENMASK(24, 20), + [STATIC_MAC_TABLE_USE_FID_R] = BIT(24), + [STATIC_MAC_TABLE_USE_FID_W] = BIT(23), + [STATIC_MAC_TABLE_FID_R] = GENMASK(31, 25), + [STATIC_MAC_TABLE_FID_W] = GENMASK(30, 24), + [STATIC_MAC_TABLE_OVERRIDE] = BIT(22), + [STATIC_MAC_TABLE_FWD_PORTS] = GENMASK(20, 16), [DYNAMIC_MAC_TABLE_ENTRIES_H] = GENMASK(6, 0), [DYNAMIC_MAC_TABLE_MAC_EMPTY] = BIT(8), [DYNAMIC_MAC_TABLE_NOT_READY] = BIT(7), @@ -67,7 +69,8 @@ static const u8 ksz8795_shifts[] = { [VLAN_TABLE_MEMBERSHIP_S] = 7, [VLAN_TABLE] = 16, [STATIC_MAC_FWD_PORTS] = 16, - [STATIC_MAC_FID] = 24, + [STATIC_MAC_FID_R] = 25, + [STATIC_MAC_FID_W] = 24, [DYNAMIC_MAC_ENTRIES_H] = 3, [DYNAMIC_MAC_ENTRIES] = 29, [DYNAMIC_MAC_FID] = 16, @@ -100,8 +103,10 @@ static const u32 ksz8863_masks[] = { [VLAN_TABLE_MEMBERSHIP] = GENMASK(18, 16), [VLAN_TABLE_VALID] = BIT(19), [STATIC_MAC_TABLE_VALID] = BIT(19), - [STATIC_MAC_TABLE_USE_FID] = BIT(21), - [STATIC_MAC_TABLE_FID] = GENMASK(29, 26), + [STATIC_MAC_TABLE_USE_FID_R] = BIT(21), + [STATIC_MAC_TABLE_USE_FID_W] = BIT(21), + [STATIC_MAC_TABLE_FID_R] = GENMASK(25, 22), + [STATIC_MAC_TABLE_FID_W] = GENMASK(25, 22), [STATIC_MAC_TABLE_OVERRIDE] = BIT(20), [STATIC_MAC_TABLE_FWD_PORTS] = GENMASK(18, 16), [DYNAMIC_MAC_TABLE_ENTRIES_H] = GENMASK(5, 0), @@ -116,7 +121,8 @@ static const u32 ksz8863_masks[] = { static u8 ksz8863_shifts[] = { [VLAN_TABLE_MEMBERSHIP_S] = 16, [STATIC_MAC_FWD_PORTS] = 16, - [STATIC_MAC_FID] = 22, + [STATIC_MAC_FID_R] = 22, + [STATIC_MAC_FID_W] = 22, [DYNAMIC_MAC_ENTRIES_H] = 3, [DYNAMIC_MAC_ENTRIES] = 24, [DYNAMIC_MAC_FID] = 16, @@ -604,9 +610,9 @@ static int ksz8_r_sta_mac_table(struct ksz_device *dev, u16 addr, data_hi >>= 1; alu->is_static = true; alu->is_use_fid = - (data_hi & masks[STATIC_MAC_TABLE_USE_FID]) ? 1 : 0; - alu->fid = (data_hi & masks[STATIC_MAC_TABLE_FID]) >> - shifts[STATIC_MAC_FID]; + (data_hi & masks[STATIC_MAC_TABLE_USE_FID_R]) ? 1 : 0; + alu->fid = (data_hi & masks[STATIC_MAC_TABLE_FID_R]) >> + shifts[STATIC_MAC_FID_R]; return 0; } return -ENXIO; @@ -633,8 +639,8 @@ static void ksz8_w_sta_mac_table(struct ksz_device *dev, u16 addr, if (alu->is_override) data_hi |= masks[STATIC_MAC_TABLE_OVERRIDE]; if (alu->is_use_fid) { - data_hi |= masks[STATIC_MAC_TABLE_USE_FID]; - data_hi |= (u32)alu->fid << shifts[STATIC_MAC_FID]; + data_hi |= masks[STATIC_MAC_TABLE_USE_FID_W]; + data_hi |= ((u32)alu->fid << shifts[STATIC_MAC_FID_W]) & masks[STATIC_MAC_TABLE_FID_W]; } if (alu->is_static) data_hi |= masks[STATIC_MAC_TABLE_VALID]; -- 2.39.2