Skip to content

Commit

Permalink
net: dsa: microchip: generic access to ksz9477 static and reserved table
Browse files Browse the repository at this point in the history
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: Arun Ramadoss <arun.ramadoss@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Arun Ramadoss authored and David S. Miller committed Jul 2, 2022
1 parent 092f875 commit 457c182
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
27 changes: 20 additions & 7 deletions drivers/net/dsa/microchip/ksz9477.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
u32 static_table[4];
const u8 *shifts;
const u32 *masks;
u32 data;
int index;
u32 mac_hi, mac_lo;
int err = 0;

shifts = dev->info->shifts;
masks = dev->info->masks;

mac_hi = ((mdb->addr[0] << 8) | mdb->addr[1]);
mac_lo = ((mdb->addr[2] << 24) | (mdb->addr[3] << 16));
mac_lo |= ((mdb->addr[4] << 8) | mdb->addr[5]);
Expand All @@ -657,8 +662,8 @@ int ksz9477_mdb_add(struct ksz_device *dev, int port,

for (index = 0; index < dev->info->num_statics; index++) {
/* find empty slot first */
data = (index << ALU_STAT_INDEX_S) |
ALU_STAT_READ | ALU_STAT_START;
data = (index << shifts[ALU_STAT_INDEX]) |
masks[ALU_STAT_READ] | ALU_STAT_START;
ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data);

/* wait to be finished */
Expand Down Expand Up @@ -702,7 +707,7 @@ int ksz9477_mdb_add(struct ksz_device *dev, int port,

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);

/* wait to be finished */
Expand All @@ -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)
{
u32 static_table[4];
const u8 *shifts;
const u32 *masks;
u32 data;
int index;
int ret = 0;
u32 mac_hi, mac_lo;

shifts = dev->info->shifts;
masks = dev->info->masks;

mac_hi = ((mdb->addr[0] << 8) | mdb->addr[1]);
mac_lo = ((mdb->addr[2] << 24) | (mdb->addr[3] << 16));
mac_lo |= ((mdb->addr[4] << 8) | mdb->addr[5]);
Expand All @@ -731,8 +741,8 @@ int ksz9477_mdb_del(struct ksz_device *dev, int port,

for (index = 0; index < dev->info->num_statics; index++) {
/* find empty slot first */
data = (index << ALU_STAT_INDEX_S) |
ALU_STAT_READ | ALU_STAT_START;
data = (index << shifts[ALU_STAT_INDEX]) |
masks[ALU_STAT_READ] | ALU_STAT_START;
ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data);

/* wait to be finished */
Expand Down Expand Up @@ -774,7 +784,7 @@ int ksz9477_mdb_del(struct ksz_device *dev, int port,

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);

/* wait to be finished */
Expand Down Expand Up @@ -1230,9 +1240,12 @@ void ksz9477_config_cpu_port(struct dsa_switch *ds)

int ksz9477_enable_stp_addr(struct ksz_device *dev)
{
const u32 *masks;
u32 data;
int ret;

masks = dev->info->masks;

/* Enable Reserved multicast table */
ksz_cfg(dev, REG_SW_LUE_CTRL_0, SW_RESV_MCAST_ENABLE, true);

Expand All @@ -1242,7 +1255,7 @@ int ksz9477_enable_stp_addr(struct ksz_device *dev)
if (ret < 0)
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);
if (ret < 0)
Expand Down
3 changes: 0 additions & 3 deletions drivers/net/dsa/microchip/ksz9477_reg.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,9 @@

#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_STAT_START BIT(7)
#define ALU_RESV_MCAST_ADDR BIT(1)
#define ALU_STAT_READ BIT(0)

#define REG_SW_ALU_VAL_A 0x0420

Expand Down
35 changes: 35 additions & 0 deletions drivers/net/dsa/microchip/ksz_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,24 @@ static const u16 ksz9477_regs[] = {
[S_START_CTRL] = 0x0300,
[S_BROADCAST_CTRL] = 0x0332,
[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[] = {
Expand Down Expand Up @@ -432,6 +449,8 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
.reg_mib_cnt = MIB_COUNTER_NUM,
.regs = ksz9477_regs,
.masks = ksz9477_masks,
.shifts = ksz9477_shifts,
.supports_mii = {false, false, false, false,
false, true, false},
.supports_rmii = {false, false, false, false,
Expand All @@ -456,6 +475,8 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
.reg_mib_cnt = MIB_COUNTER_NUM,
.regs = ksz9477_regs,
.masks = ksz9477_masks,
.shifts = ksz9477_shifts,
.supports_mii = {false, false, false, false,
false, true, true},
.supports_rmii = {false, false, false, false,
Expand All @@ -479,6 +500,8 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
.reg_mib_cnt = MIB_COUNTER_NUM,
.regs = ksz9477_regs,
.masks = ksz9477_masks,
.shifts = ksz9477_shifts,
.supports_mii = {false, false, true},
.supports_rmii = {false, false, true},
.supports_rgmii = {false, false, true},
Expand All @@ -499,6 +522,8 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
.reg_mib_cnt = MIB_COUNTER_NUM,
.regs = ksz9477_regs,
.masks = ksz9477_masks,
.shifts = ksz9477_shifts,
.supports_mii = {false, false, false, false,
false, true, true},
.supports_rmii = {false, false, false, false,
Expand All @@ -521,6 +546,8 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
.reg_mib_cnt = MIB_COUNTER_NUM,
.regs = ksz9477_regs,
.masks = lan937x_masks,
.shifts = lan937x_shifts,
.supports_mii = {false, false, false, false, true},
.supports_rmii = {false, false, false, false, true},
.supports_rgmii = {false, false, false, false, true},
Expand All @@ -539,6 +566,8 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
.reg_mib_cnt = MIB_COUNTER_NUM,
.regs = ksz9477_regs,
.masks = lan937x_masks,
.shifts = lan937x_shifts,
.supports_mii = {false, false, false, false, true, true},
.supports_rmii = {false, false, false, false, true, true},
.supports_rgmii = {false, false, false, false, true, true},
Expand All @@ -557,6 +586,8 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
.reg_mib_cnt = MIB_COUNTER_NUM,
.regs = ksz9477_regs,
.masks = lan937x_masks,
.shifts = lan937x_shifts,
.supports_mii = {false, false, false, false,
true, true, false, false},
.supports_rmii = {false, false, false, false,
Expand All @@ -579,6 +610,8 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
.reg_mib_cnt = MIB_COUNTER_NUM,
.regs = ksz9477_regs,
.masks = lan937x_masks,
.shifts = lan937x_shifts,
.supports_mii = {false, false, false, false,
true, true, false, false},
.supports_rmii = {false, false, false, false,
Expand All @@ -601,6 +634,8 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
.reg_mib_cnt = MIB_COUNTER_NUM,
.regs = ksz9477_regs,
.masks = lan937x_masks,
.shifts = lan937x_shifts,
.supports_mii = {false, false, false, false,
true, true, false, false},
.supports_rmii = {false, false, false, false,
Expand Down
3 changes: 3 additions & 0 deletions drivers/net/dsa/microchip/ksz_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ enum ksz_masks {
DYNAMIC_MAC_TABLE_FID,
DYNAMIC_MAC_TABLE_SRC_PORT,
DYNAMIC_MAC_TABLE_TIMESTAMP,
ALU_STAT_WRITE,
ALU_STAT_READ,
};

enum ksz_shifts {
Expand All @@ -203,6 +205,7 @@ enum ksz_shifts {
DYNAMIC_MAC_FID,
DYNAMIC_MAC_TIMESTAMP,
DYNAMIC_MAC_SRC_PORT,
ALU_STAT_INDEX,
};

struct alu_struct {
Expand Down

0 comments on commit 457c182

Please sign in to comment.