Commit de6dd626 authored by Arun Ramadoss's avatar Arun Ramadoss Committed by Paolo Abeni

net: dsa: ksz: added the generic port_stp_state_set function

The ksz8795 and ksz9477 uses the same algorithm for the
port_stp_state_set function except the register address is different. So
moved the algorithm to the ksz_common.c and used the dev_ops for
register read and write. This function can also used for the lan937x
part. Hence making it generic for all the parts.
Signed-off-by: default avatarArun Ramadoss <arun.ramadoss@microchip.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Link: https://lore.kernel.org/r/20220424112831.11504-1-arun.ramadoss@microchip.comSigned-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent fb0a43f5
...@@ -1027,40 +1027,7 @@ static void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member) ...@@ -1027,40 +1027,7 @@ static void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member)
static void ksz8_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) static void ksz8_port_stp_state_set(struct dsa_switch *ds, int port, u8 state)
{ {
struct ksz_device *dev = ds->priv; ksz_port_stp_state_set(ds, port, state, P_STP_CTRL);
struct ksz_port *p;
u8 data;
ksz_pread8(dev, port, P_STP_CTRL, &data);
data &= ~(PORT_TX_ENABLE | PORT_RX_ENABLE | PORT_LEARN_DISABLE);
switch (state) {
case BR_STATE_DISABLED:
data |= PORT_LEARN_DISABLE;
break;
case BR_STATE_LISTENING:
data |= (PORT_RX_ENABLE | PORT_LEARN_DISABLE);
break;
case BR_STATE_LEARNING:
data |= PORT_RX_ENABLE;
break;
case BR_STATE_FORWARDING:
data |= (PORT_TX_ENABLE | PORT_RX_ENABLE);
break;
case BR_STATE_BLOCKING:
data |= PORT_LEARN_DISABLE;
break;
default:
dev_err(ds->dev, "invalid STP state: %d\n", state);
return;
}
ksz_pwrite8(dev, port, P_STP_CTRL, data);
p = &dev->ports[port];
p->stp_state = state;
ksz_update_port_member(dev, port);
} }
static void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port) static void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port)
......
...@@ -160,9 +160,6 @@ ...@@ -160,9 +160,6 @@
#define PORT_DISCARD_NON_VID BIT(5) #define PORT_DISCARD_NON_VID BIT(5)
#define PORT_FORCE_FLOW_CTRL BIT(4) #define PORT_FORCE_FLOW_CTRL BIT(4)
#define PORT_BACK_PRESSURE BIT(3) #define PORT_BACK_PRESSURE BIT(3)
#define PORT_TX_ENABLE BIT(2)
#define PORT_RX_ENABLE BIT(1)
#define PORT_LEARN_DISABLE BIT(0)
#define REG_PORT_1_CTRL_3 0x13 #define REG_PORT_1_CTRL_3 0x13
#define REG_PORT_2_CTRL_3 0x23 #define REG_PORT_2_CTRL_3 0x23
......
...@@ -517,38 +517,7 @@ static void ksz9477_cfg_port_member(struct ksz_device *dev, int port, ...@@ -517,38 +517,7 @@ static void ksz9477_cfg_port_member(struct ksz_device *dev, int port,
static void ksz9477_port_stp_state_set(struct dsa_switch *ds, int port, static void ksz9477_port_stp_state_set(struct dsa_switch *ds, int port,
u8 state) u8 state)
{ {
struct ksz_device *dev = ds->priv; ksz_port_stp_state_set(ds, port, state, P_STP_CTRL);
struct ksz_port *p = &dev->ports[port];
u8 data;
ksz_pread8(dev, port, P_STP_CTRL, &data);
data &= ~(PORT_TX_ENABLE | PORT_RX_ENABLE | PORT_LEARN_DISABLE);
switch (state) {
case BR_STATE_DISABLED:
data |= PORT_LEARN_DISABLE;
break;
case BR_STATE_LISTENING:
data |= (PORT_RX_ENABLE | PORT_LEARN_DISABLE);
break;
case BR_STATE_LEARNING:
data |= PORT_RX_ENABLE;
break;
case BR_STATE_FORWARDING:
data |= (PORT_TX_ENABLE | PORT_RX_ENABLE);
break;
case BR_STATE_BLOCKING:
data |= PORT_LEARN_DISABLE;
break;
default:
dev_err(ds->dev, "invalid STP state: %d\n", state);
return;
}
ksz_pwrite8(dev, port, P_STP_CTRL, data);
p->stp_state = state;
ksz_update_port_member(dev, port);
} }
static void ksz9477_flush_dyn_mac_table(struct ksz_device *dev, int port) static void ksz9477_flush_dyn_mac_table(struct ksz_device *dev, int port)
......
...@@ -1586,10 +1586,6 @@ ...@@ -1586,10 +1586,6 @@
#define REG_PORT_LUE_MSTP_STATE 0x0B04 #define REG_PORT_LUE_MSTP_STATE 0x0B04
#define PORT_TX_ENABLE BIT(2)
#define PORT_RX_ENABLE BIT(1)
#define PORT_LEARN_DISABLE BIT(0)
/* C - PTP */ /* C - PTP */
#define REG_PTP_PORT_RX_DELAY__2 0x0C00 #define REG_PTP_PORT_RX_DELAY__2 0x0C00
......
...@@ -372,6 +372,46 @@ int ksz_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy) ...@@ -372,6 +372,46 @@ int ksz_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy)
} }
EXPORT_SYMBOL_GPL(ksz_enable_port); EXPORT_SYMBOL_GPL(ksz_enable_port);
void ksz_port_stp_state_set(struct dsa_switch *ds, int port,
u8 state, int reg)
{
struct ksz_device *dev = ds->priv;
struct ksz_port *p;
u8 data;
ksz_pread8(dev, port, reg, &data);
data &= ~(PORT_TX_ENABLE | PORT_RX_ENABLE | PORT_LEARN_DISABLE);
switch (state) {
case BR_STATE_DISABLED:
data |= PORT_LEARN_DISABLE;
break;
case BR_STATE_LISTENING:
data |= (PORT_RX_ENABLE | PORT_LEARN_DISABLE);
break;
case BR_STATE_LEARNING:
data |= PORT_RX_ENABLE;
break;
case BR_STATE_FORWARDING:
data |= (PORT_TX_ENABLE | PORT_RX_ENABLE);
break;
case BR_STATE_BLOCKING:
data |= PORT_LEARN_DISABLE;
break;
default:
dev_err(ds->dev, "invalid STP state: %d\n", state);
return;
}
ksz_pwrite8(dev, port, reg, data);
p = &dev->ports[port];
p->stp_state = state;
ksz_update_port_member(dev, port);
}
EXPORT_SYMBOL_GPL(ksz_port_stp_state_set);
struct ksz_device *ksz_switch_alloc(struct device *base, void *priv) struct ksz_device *ksz_switch_alloc(struct device *base, void *priv)
{ {
struct dsa_switch *ds; struct dsa_switch *ds;
......
...@@ -165,6 +165,8 @@ int ksz_port_bridge_join(struct dsa_switch *ds, int port, ...@@ -165,6 +165,8 @@ int ksz_port_bridge_join(struct dsa_switch *ds, int port,
struct netlink_ext_ack *extack); struct netlink_ext_ack *extack);
void ksz_port_bridge_leave(struct dsa_switch *ds, int port, void ksz_port_bridge_leave(struct dsa_switch *ds, int port,
struct dsa_bridge bridge); struct dsa_bridge bridge);
void ksz_port_stp_state_set(struct dsa_switch *ds, int port,
u8 state, int reg);
void ksz_port_fast_age(struct dsa_switch *ds, int port); void ksz_port_fast_age(struct dsa_switch *ds, int port);
int ksz_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb, int ksz_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb,
void *data); void *data);
...@@ -292,6 +294,11 @@ static inline void ksz_regmap_unlock(void *__mtx) ...@@ -292,6 +294,11 @@ static inline void ksz_regmap_unlock(void *__mtx)
mutex_unlock(mtx); mutex_unlock(mtx);
} }
/* STP State Defines */
#define PORT_TX_ENABLE BIT(2)
#define PORT_RX_ENABLE BIT(1)
#define PORT_LEARN_DISABLE BIT(0)
/* Regmap tables generation */ /* Regmap tables generation */
#define KSZ_SPI_OP_RD 3 #define KSZ_SPI_OP_RD 3
#define KSZ_SPI_OP_WR 2 #define KSZ_SPI_OP_WR 2
......
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