Skip to content

Commit

Permalink
net: dsa: microchip: add support for phylink mac config
Browse files Browse the repository at this point in the history
This patch add support for phylink mac config for ksz series of
switches. All the files ksz8795, ksz9477 and lan937x uses the ksz common
xmii function. Instead of calling from the individual files, it is moved
to the ksz common phylink mac config function.

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 27, 2022
1 parent c476bed commit f3d890f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 33 deletions.
7 changes: 0 additions & 7 deletions drivers/net/dsa/microchip/ksz8795.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
#include "ksz8795_reg.h"
#include "ksz8.h"

static bool ksz_is_ksz88x3(struct ksz_device *dev)
{
return dev->chip_id == 0x8830;
}

static void ksz_cfg(struct ksz_device *dev, u32 addr, u8 bits, bool set)
{
regmap_update_bits(dev->regmap[0], addr, bits, set ? bits : 0);
Expand Down Expand Up @@ -1124,8 +1119,6 @@ static void ksz8795_cpu_interface_select(struct ksz_device *dev, int port)
port);
p->interface = dev->compat_interface;
}

ksz_set_xmii(dev, port, p->interface);
}

void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port)
Expand Down
4 changes: 0 additions & 4 deletions drivers/net/dsa/microchip/ksz9477.c
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,6 @@ void ksz9477_get_caps(struct ksz_device *dev, int port,

void ksz9477_port_setup(struct ksz_device *dev, int port, bool cpu_port)
{
struct ksz_port *p = &dev->ports[port];
struct dsa_switch *ds = dev->ds;
u16 data16;
u8 member;
Expand Down Expand Up @@ -987,9 +986,6 @@ void ksz9477_port_setup(struct ksz_device *dev, int port, bool cpu_port)
ksz_port_cfg(dev, port, REG_PORT_CTRL_0,
PORT_FORCE_TX_FLOW_CTRL | PORT_FORCE_RX_FLOW_CTRL,
true);

/* configure MAC to 1G & RGMII mode */
ksz_set_xmii(dev, port, p->interface);
}

if (cpu_port)
Expand Down
18 changes: 16 additions & 2 deletions drivers/net/dsa/microchip/ksz_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ static const struct ksz_dev_ops lan937x_dev_ops = {
.mirror_add = ksz9477_port_mirror_add,
.mirror_del = ksz9477_port_mirror_del,
.get_caps = lan937x_phylink_get_caps,
.phylink_mac_config = lan937x_phylink_mac_config,
.setup_rgmii_delay = lan937x_setup_rgmii_delay,
.fdb_dump = ksz9477_fdb_dump,
.fdb_add = ksz9477_fdb_add,
Expand Down Expand Up @@ -1409,7 +1408,8 @@ static int ksz_max_mtu(struct dsa_switch *ds, int port)
return dev->dev_ops->max_mtu(dev, port);
}

void ksz_set_xmii(struct ksz_device *dev, int port, phy_interface_t interface)
static void ksz_set_xmii(struct ksz_device *dev, int port,
phy_interface_t interface)
{
const u8 *bitval = dev->info->xmii_ctrl1;
struct ksz_port *p = &dev->ports[port];
Expand Down Expand Up @@ -1495,6 +1495,20 @@ static void ksz_phylink_mac_config(struct dsa_switch *ds, int port,
{
struct ksz_device *dev = ds->priv;

if (ksz_is_ksz88x3(dev))
return;

/* Internal PHYs */
if (dev->info->internal_phy[port])
return;

if (phylink_autoneg_inband(mode)) {
dev_err(dev->dev, "In-band AN not supported!\n");
return;
}

ksz_set_xmii(dev, port, state->interface);

if (dev->dev_ops->phylink_mac_config)
dev->dev_ops->phylink_mac_config(dev, port, mode, state);

Expand Down
6 changes: 5 additions & 1 deletion drivers/net/dsa/microchip/ksz_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ void ksz_init_mib_timer(struct ksz_device *dev);
void ksz_r_mib_stats64(struct ksz_device *dev, int port);
void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state);
bool ksz_get_gbit(struct ksz_device *dev, int port);
void ksz_set_xmii(struct ksz_device *dev, int port, phy_interface_t interface);
phy_interface_t ksz_get_xmii(struct ksz_device *dev, int port, bool gbit);
extern const struct ksz_chip_data ksz_switch_chips[];

Expand Down Expand Up @@ -447,6 +446,11 @@ static inline void ksz_regmap_unlock(void *__mtx)
mutex_unlock(mtx);
}

static inline bool ksz_is_ksz88x3(struct ksz_device *dev)
{
return dev->chip_id == KSZ8830_CHIP_ID;
}

static inline int is_lan937x(struct ksz_device *dev)
{
return dev->chip_id == LAN9370_CHIP_ID ||
Expand Down
3 changes: 0 additions & 3 deletions drivers/net/dsa/microchip/lan937x.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,5 @@ void lan937x_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val);
int lan937x_change_mtu(struct ksz_device *dev, int port, int new_mtu);
void lan937x_phylink_get_caps(struct ksz_device *dev, int port,
struct phylink_config *config);
void lan937x_phylink_mac_config(struct ksz_device *dev, int port,
unsigned int mode,
const struct phylink_link_state *state);
void lan937x_setup_rgmii_delay(struct ksz_device *dev, int port);
#endif
16 changes: 0 additions & 16 deletions drivers/net/dsa/microchip/lan937x_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,22 +383,6 @@ void lan937x_setup_rgmii_delay(struct ksz_device *dev, int port)
}
}

void lan937x_phylink_mac_config(struct ksz_device *dev, int port,
unsigned int mode,
const struct phylink_link_state *state)
{
/* Internal PHYs */
if (dev->info->internal_phy[port])
return;

if (phylink_autoneg_inband(mode)) {
dev_err(dev->dev, "In-band AN not supported!\n");
return;
}

ksz_set_xmii(dev, port, state->interface);
}

int lan937x_setup(struct dsa_switch *ds)
{
struct ksz_device *dev = ds->priv;
Expand Down

0 comments on commit f3d890f

Please sign in to comment.