Commit 457c182a authored by Arun Ramadoss's avatar Arun Ramadoss Committed by David S. Miller

net: dsa: microchip: generic access to ksz9477 static and reserved table

The ksz9477 and lan937x has few difference in the static and reserved
table register 0x041C. For the ksz9477 if the bit 0 is 1 - read
operation and 0 - write operation. But for lan937x bit 1:0 used for
selecting the read/write operation, 01 - write and 10 - read.
To use ksz9477 mdb add/del and enable_stp_addr for the lan937x, masks &
shifts are introduced for ksz9477 & lan937x in ksz_common.c. Then
updated the function with masks & shifts based on the switch instead of
hard coding it.
Signed-off-by: default avatarArun Ramadoss <arun.ramadoss@microchip.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 092f8751
...@@ -644,11 +644,16 @@ int ksz9477_mdb_add(struct ksz_device *dev, int port, ...@@ -644,11 +644,16 @@ int ksz9477_mdb_add(struct ksz_device *dev, int port,
const struct switchdev_obj_port_mdb *mdb, struct dsa_db db) const struct switchdev_obj_port_mdb *mdb, struct dsa_db db)
{ {
u32 static_table[4]; u32 static_table[4];
const u8 *shifts;
const u32 *masks;
u32 data; u32 data;
int index; int index;
u32 mac_hi, mac_lo; u32 mac_hi, mac_lo;
int err = 0; int err = 0;
shifts = dev->info->shifts;
masks = dev->info->masks;
mac_hi = ((mdb->addr[0] << 8) | mdb->addr[1]); mac_hi = ((mdb->addr[0] << 8) | mdb->addr[1]);
mac_lo = ((mdb->addr[2] << 24) | (mdb->addr[3] << 16)); mac_lo = ((mdb->addr[2] << 24) | (mdb->addr[3] << 16));
mac_lo |= ((mdb->addr[4] << 8) | mdb->addr[5]); mac_lo |= ((mdb->addr[4] << 8) | mdb->addr[5]);
...@@ -657,8 +662,8 @@ int ksz9477_mdb_add(struct ksz_device *dev, int port, ...@@ -657,8 +662,8 @@ int ksz9477_mdb_add(struct ksz_device *dev, int port,
for (index = 0; index < dev->info->num_statics; index++) { for (index = 0; index < dev->info->num_statics; index++) {
/* find empty slot first */ /* find empty slot first */
data = (index << ALU_STAT_INDEX_S) | data = (index << shifts[ALU_STAT_INDEX]) |
ALU_STAT_READ | ALU_STAT_START; masks[ALU_STAT_READ] | ALU_STAT_START;
ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data); ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data);
/* wait to be finished */ /* wait to be finished */
...@@ -702,7 +707,7 @@ int ksz9477_mdb_add(struct ksz_device *dev, int port, ...@@ -702,7 +707,7 @@ int ksz9477_mdb_add(struct ksz_device *dev, int port,
ksz9477_write_table(dev, static_table); ksz9477_write_table(dev, static_table);
data = (index << ALU_STAT_INDEX_S) | ALU_STAT_START; data = (index << shifts[ALU_STAT_INDEX]) | ALU_STAT_START;
ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data); ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data);
/* wait to be finished */ /* wait to be finished */
...@@ -718,11 +723,16 @@ int ksz9477_mdb_del(struct ksz_device *dev, int port, ...@@ -718,11 +723,16 @@ int ksz9477_mdb_del(struct ksz_device *dev, int port,
const struct switchdev_obj_port_mdb *mdb, struct dsa_db db) const struct switchdev_obj_port_mdb *mdb, struct dsa_db db)
{ {
u32 static_table[4]; u32 static_table[4];
const u8 *shifts;
const u32 *masks;
u32 data; u32 data;
int index; int index;
int ret = 0; int ret = 0;
u32 mac_hi, mac_lo; u32 mac_hi, mac_lo;
shifts = dev->info->shifts;
masks = dev->info->masks;
mac_hi = ((mdb->addr[0] << 8) | mdb->addr[1]); mac_hi = ((mdb->addr[0] << 8) | mdb->addr[1]);
mac_lo = ((mdb->addr[2] << 24) | (mdb->addr[3] << 16)); mac_lo = ((mdb->addr[2] << 24) | (mdb->addr[3] << 16));
mac_lo |= ((mdb->addr[4] << 8) | mdb->addr[5]); mac_lo |= ((mdb->addr[4] << 8) | mdb->addr[5]);
...@@ -731,8 +741,8 @@ int ksz9477_mdb_del(struct ksz_device *dev, int port, ...@@ -731,8 +741,8 @@ int ksz9477_mdb_del(struct ksz_device *dev, int port,
for (index = 0; index < dev->info->num_statics; index++) { for (index = 0; index < dev->info->num_statics; index++) {
/* find empty slot first */ /* find empty slot first */
data = (index << ALU_STAT_INDEX_S) | data = (index << shifts[ALU_STAT_INDEX]) |
ALU_STAT_READ | ALU_STAT_START; masks[ALU_STAT_READ] | ALU_STAT_START;
ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data); ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data);
/* wait to be finished */ /* wait to be finished */
...@@ -774,7 +784,7 @@ int ksz9477_mdb_del(struct ksz_device *dev, int port, ...@@ -774,7 +784,7 @@ int ksz9477_mdb_del(struct ksz_device *dev, int port,
ksz9477_write_table(dev, static_table); ksz9477_write_table(dev, static_table);
data = (index << ALU_STAT_INDEX_S) | ALU_STAT_START; data = (index << shifts[ALU_STAT_INDEX]) | ALU_STAT_START;
ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data); ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data);
/* wait to be finished */ /* wait to be finished */
...@@ -1230,9 +1240,12 @@ void ksz9477_config_cpu_port(struct dsa_switch *ds) ...@@ -1230,9 +1240,12 @@ void ksz9477_config_cpu_port(struct dsa_switch *ds)
int ksz9477_enable_stp_addr(struct ksz_device *dev) int ksz9477_enable_stp_addr(struct ksz_device *dev)
{ {
const u32 *masks;
u32 data; u32 data;
int ret; int ret;
masks = dev->info->masks;
/* Enable Reserved multicast table */ /* Enable Reserved multicast table */
ksz_cfg(dev, REG_SW_LUE_CTRL_0, SW_RESV_MCAST_ENABLE, true); ksz_cfg(dev, REG_SW_LUE_CTRL_0, SW_RESV_MCAST_ENABLE, true);
...@@ -1242,7 +1255,7 @@ int ksz9477_enable_stp_addr(struct ksz_device *dev) ...@@ -1242,7 +1255,7 @@ int ksz9477_enable_stp_addr(struct ksz_device *dev)
if (ret < 0) if (ret < 0)
return ret; return ret;
data = ALU_STAT_START | ALU_RESV_MCAST_ADDR; data = ALU_STAT_START | ALU_RESV_MCAST_ADDR | masks[ALU_STAT_WRITE];
ret = ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data); ret = ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data);
if (ret < 0) if (ret < 0)
......
...@@ -419,12 +419,9 @@ ...@@ -419,12 +419,9 @@
#define REG_SW_ALU_STAT_CTRL__4 0x041C #define REG_SW_ALU_STAT_CTRL__4 0x041C
#define ALU_STAT_INDEX_M (BIT(4) - 1)
#define ALU_STAT_INDEX_S 16
#define ALU_RESV_MCAST_INDEX_M (BIT(6) - 1) #define ALU_RESV_MCAST_INDEX_M (BIT(6) - 1)
#define ALU_STAT_START BIT(7) #define ALU_STAT_START BIT(7)
#define ALU_RESV_MCAST_ADDR BIT(1) #define ALU_RESV_MCAST_ADDR BIT(1)
#define ALU_STAT_READ BIT(0)
#define REG_SW_ALU_VAL_A 0x0420 #define REG_SW_ALU_VAL_A 0x0420
......
...@@ -314,7 +314,24 @@ static const u16 ksz9477_regs[] = { ...@@ -314,7 +314,24 @@ static const u16 ksz9477_regs[] = {
[S_START_CTRL] = 0x0300, [S_START_CTRL] = 0x0300,
[S_BROADCAST_CTRL] = 0x0332, [S_BROADCAST_CTRL] = 0x0332,
[S_MULTICAST_CTRL] = 0x0331, [S_MULTICAST_CTRL] = 0x0331,
};
static const u32 ksz9477_masks[] = {
[ALU_STAT_WRITE] = 0,
[ALU_STAT_READ] = 1,
};
static const u8 ksz9477_shifts[] = {
[ALU_STAT_INDEX] = 16,
};
static const u32 lan937x_masks[] = {
[ALU_STAT_WRITE] = 1,
[ALU_STAT_READ] = 2,
};
static const u8 lan937x_shifts[] = {
[ALU_STAT_INDEX] = 8,
}; };
const struct ksz_chip_data ksz_switch_chips[] = { const struct ksz_chip_data ksz_switch_chips[] = {
...@@ -432,6 +449,8 @@ const struct ksz_chip_data ksz_switch_chips[] = { ...@@ -432,6 +449,8 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.mib_cnt = ARRAY_SIZE(ksz9477_mib_names), .mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
.reg_mib_cnt = MIB_COUNTER_NUM, .reg_mib_cnt = MIB_COUNTER_NUM,
.regs = ksz9477_regs, .regs = ksz9477_regs,
.masks = ksz9477_masks,
.shifts = ksz9477_shifts,
.supports_mii = {false, false, false, false, .supports_mii = {false, false, false, false,
false, true, false}, false, true, false},
.supports_rmii = {false, false, false, false, .supports_rmii = {false, false, false, false,
...@@ -456,6 +475,8 @@ const struct ksz_chip_data ksz_switch_chips[] = { ...@@ -456,6 +475,8 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.mib_cnt = ARRAY_SIZE(ksz9477_mib_names), .mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
.reg_mib_cnt = MIB_COUNTER_NUM, .reg_mib_cnt = MIB_COUNTER_NUM,
.regs = ksz9477_regs, .regs = ksz9477_regs,
.masks = ksz9477_masks,
.shifts = ksz9477_shifts,
.supports_mii = {false, false, false, false, .supports_mii = {false, false, false, false,
false, true, true}, false, true, true},
.supports_rmii = {false, false, false, false, .supports_rmii = {false, false, false, false,
...@@ -479,6 +500,8 @@ const struct ksz_chip_data ksz_switch_chips[] = { ...@@ -479,6 +500,8 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.mib_cnt = ARRAY_SIZE(ksz9477_mib_names), .mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
.reg_mib_cnt = MIB_COUNTER_NUM, .reg_mib_cnt = MIB_COUNTER_NUM,
.regs = ksz9477_regs, .regs = ksz9477_regs,
.masks = ksz9477_masks,
.shifts = ksz9477_shifts,
.supports_mii = {false, false, true}, .supports_mii = {false, false, true},
.supports_rmii = {false, false, true}, .supports_rmii = {false, false, true},
.supports_rgmii = {false, false, true}, .supports_rgmii = {false, false, true},
...@@ -499,6 +522,8 @@ const struct ksz_chip_data ksz_switch_chips[] = { ...@@ -499,6 +522,8 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.mib_cnt = ARRAY_SIZE(ksz9477_mib_names), .mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
.reg_mib_cnt = MIB_COUNTER_NUM, .reg_mib_cnt = MIB_COUNTER_NUM,
.regs = ksz9477_regs, .regs = ksz9477_regs,
.masks = ksz9477_masks,
.shifts = ksz9477_shifts,
.supports_mii = {false, false, false, false, .supports_mii = {false, false, false, false,
false, true, true}, false, true, true},
.supports_rmii = {false, false, false, false, .supports_rmii = {false, false, false, false,
...@@ -521,6 +546,8 @@ const struct ksz_chip_data ksz_switch_chips[] = { ...@@ -521,6 +546,8 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.mib_cnt = ARRAY_SIZE(ksz9477_mib_names), .mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
.reg_mib_cnt = MIB_COUNTER_NUM, .reg_mib_cnt = MIB_COUNTER_NUM,
.regs = ksz9477_regs, .regs = ksz9477_regs,
.masks = lan937x_masks,
.shifts = lan937x_shifts,
.supports_mii = {false, false, false, false, true}, .supports_mii = {false, false, false, false, true},
.supports_rmii = {false, false, false, false, true}, .supports_rmii = {false, false, false, false, true},
.supports_rgmii = {false, false, false, false, true}, .supports_rgmii = {false, false, false, false, true},
...@@ -539,6 +566,8 @@ const struct ksz_chip_data ksz_switch_chips[] = { ...@@ -539,6 +566,8 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.mib_cnt = ARRAY_SIZE(ksz9477_mib_names), .mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
.reg_mib_cnt = MIB_COUNTER_NUM, .reg_mib_cnt = MIB_COUNTER_NUM,
.regs = ksz9477_regs, .regs = ksz9477_regs,
.masks = lan937x_masks,
.shifts = lan937x_shifts,
.supports_mii = {false, false, false, false, true, true}, .supports_mii = {false, false, false, false, true, true},
.supports_rmii = {false, false, false, false, true, true}, .supports_rmii = {false, false, false, false, true, true},
.supports_rgmii = {false, false, false, false, true, true}, .supports_rgmii = {false, false, false, false, true, true},
...@@ -557,6 +586,8 @@ const struct ksz_chip_data ksz_switch_chips[] = { ...@@ -557,6 +586,8 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.mib_cnt = ARRAY_SIZE(ksz9477_mib_names), .mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
.reg_mib_cnt = MIB_COUNTER_NUM, .reg_mib_cnt = MIB_COUNTER_NUM,
.regs = ksz9477_regs, .regs = ksz9477_regs,
.masks = lan937x_masks,
.shifts = lan937x_shifts,
.supports_mii = {false, false, false, false, .supports_mii = {false, false, false, false,
true, true, false, false}, true, true, false, false},
.supports_rmii = {false, false, false, false, .supports_rmii = {false, false, false, false,
...@@ -579,6 +610,8 @@ const struct ksz_chip_data ksz_switch_chips[] = { ...@@ -579,6 +610,8 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.mib_cnt = ARRAY_SIZE(ksz9477_mib_names), .mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
.reg_mib_cnt = MIB_COUNTER_NUM, .reg_mib_cnt = MIB_COUNTER_NUM,
.regs = ksz9477_regs, .regs = ksz9477_regs,
.masks = lan937x_masks,
.shifts = lan937x_shifts,
.supports_mii = {false, false, false, false, .supports_mii = {false, false, false, false,
true, true, false, false}, true, true, false, false},
.supports_rmii = {false, false, false, false, .supports_rmii = {false, false, false, false,
...@@ -601,6 +634,8 @@ const struct ksz_chip_data ksz_switch_chips[] = { ...@@ -601,6 +634,8 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.mib_cnt = ARRAY_SIZE(ksz9477_mib_names), .mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
.reg_mib_cnt = MIB_COUNTER_NUM, .reg_mib_cnt = MIB_COUNTER_NUM,
.regs = ksz9477_regs, .regs = ksz9477_regs,
.masks = lan937x_masks,
.shifts = lan937x_shifts,
.supports_mii = {false, false, false, false, .supports_mii = {false, false, false, false,
true, true, false, false}, true, true, false, false},
.supports_rmii = {false, false, false, false, .supports_rmii = {false, false, false, false,
......
...@@ -191,6 +191,8 @@ enum ksz_masks { ...@@ -191,6 +191,8 @@ enum ksz_masks {
DYNAMIC_MAC_TABLE_FID, DYNAMIC_MAC_TABLE_FID,
DYNAMIC_MAC_TABLE_SRC_PORT, DYNAMIC_MAC_TABLE_SRC_PORT,
DYNAMIC_MAC_TABLE_TIMESTAMP, DYNAMIC_MAC_TABLE_TIMESTAMP,
ALU_STAT_WRITE,
ALU_STAT_READ,
}; };
enum ksz_shifts { enum ksz_shifts {
...@@ -203,6 +205,7 @@ enum ksz_shifts { ...@@ -203,6 +205,7 @@ enum ksz_shifts {
DYNAMIC_MAC_FID, DYNAMIC_MAC_FID,
DYNAMIC_MAC_TIMESTAMP, DYNAMIC_MAC_TIMESTAMP,
DYNAMIC_MAC_SRC_PORT, DYNAMIC_MAC_SRC_PORT,
ALU_STAT_INDEX,
}; };
struct alu_struct { struct alu_struct {
......
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