Skip to content

Commit

Permalink
net: marvell: prestera: add phylink support
Browse files Browse the repository at this point in the history
For SFP port prestera driver will use kernel
phylink infrastucture to configure port mode based on
the module that has beed inserted

Co-developed-by: Yevhen Orlov <yevhen.orlov@plvision.eu>
Signed-off-by: Yevhen Orlov <yevhen.orlov@plvision.eu>
Co-developed-by: Taras Chornyi <taras.chornyi@plvision.eu>
Signed-off-by: Taras Chornyi <taras.chornyi@plvision.eu>
Signed-off-by: Oleksandr Mazur <oleksandr.mazur@plvision.eu>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Oleksandr Mazur authored and David S. Miller committed Jul 20, 2022
1 parent ffcdd11 commit 52323ef
Show file tree
Hide file tree
Showing 5 changed files with 334 additions and 62 deletions.
1 change: 1 addition & 0 deletions drivers/net/ethernet/marvell/prestera/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ config PRESTERA
depends on NET_SWITCHDEV && VLAN_8021Q
depends on BRIDGE || BRIDGE=n
select NET_DEVLINK
select PHYLINK
help
This driver supports Marvell Prestera Switch ASICs family.

Expand Down
10 changes: 10 additions & 0 deletions drivers/net/ethernet/marvell/prestera/prestera.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <linux/notifier.h>
#include <linux/skbuff.h>
#include <linux/workqueue.h>
#include <linux/phylink.h>
#include <net/devlink.h>
#include <uapi/linux/if_ether.h>

Expand Down Expand Up @@ -92,6 +93,7 @@ struct prestera_lag {
struct prestera_flow_block;

struct prestera_port_mac_state {
bool valid;
u32 mode;
u32 speed;
bool oper;
Expand Down Expand Up @@ -151,6 +153,13 @@ struct prestera_port {
struct prestera_port_phy_config cfg_phy;
struct prestera_port_mac_state state_mac;
struct prestera_port_phy_state state_phy;

struct phylink_config phy_config;
struct phylink *phy_link;
struct phylink_pcs phylink_pcs;

/* protects state_mac */
spinlock_t state_mac_lock;
};

struct prestera_device {
Expand Down Expand Up @@ -291,6 +300,7 @@ struct prestera_switch {
u32 mtu_min;
u32 mtu_max;
u8 id;
struct device_node *np;
struct prestera_router *router;
struct prestera_lag *lags;
struct prestera_counter *counter;
Expand Down
28 changes: 6 additions & 22 deletions drivers/net/ethernet/marvell/prestera/prestera_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,9 @@ prestera_ethtool_get_link_ksettings(struct net_device *dev,
ecmd->base.speed = SPEED_UNKNOWN;
ecmd->base.duplex = DUPLEX_UNKNOWN;

if (port->phy_link)
return phylink_ethtool_ksettings_get(port->phy_link, ecmd);

ecmd->base.autoneg = port->autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE;

if (port->caps.type == PRESTERA_PORT_TYPE_TP) {
Expand Down Expand Up @@ -648,6 +651,9 @@ prestera_ethtool_set_link_ksettings(struct net_device *dev,
u8 adver_fec;
int err;

if (port->phy_link)
return phylink_ethtool_ksettings_set(port->phy_link, ecmd);

err = prestera_port_type_set(ecmd, port);
if (err)
return err;
Expand Down Expand Up @@ -782,28 +788,6 @@ static int prestera_ethtool_nway_reset(struct net_device *dev)
return -EINVAL;
}

void prestera_ethtool_port_state_changed(struct prestera_port *port,
struct prestera_port_event *evt)
{
struct prestera_port_mac_state *smac = &port->state_mac;

smac->oper = evt->data.mac.oper;

if (smac->oper) {
smac->mode = evt->data.mac.mode;
smac->speed = evt->data.mac.speed;
smac->duplex = evt->data.mac.duplex;
smac->fc = evt->data.mac.fc;
smac->fec = evt->data.mac.fec;
} else {
smac->mode = PRESTERA_MAC_MODE_MAX;
smac->speed = SPEED_UNKNOWN;
smac->duplex = DUPLEX_UNKNOWN;
smac->fc = 0;
smac->fec = 0;
}
}

const struct ethtool_ops prestera_ethtool_ops = {
.get_drvinfo = prestera_ethtool_get_drvinfo,
.get_link_ksettings = prestera_ethtool_get_link_ksettings,
Expand Down
3 changes: 0 additions & 3 deletions drivers/net/ethernet/marvell/prestera/prestera_ethtool.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,4 @@ struct prestera_port;

extern const struct ethtool_ops prestera_ethtool_ops;

void prestera_ethtool_port_state_changed(struct prestera_port *port,
struct prestera_port_event *evt);

#endif /* _PRESTERA_ETHTOOL_H_ */
Loading

0 comments on commit 52323ef

Please sign in to comment.