Commit 793ee362 authored by David S. Miller's avatar David S. Miller

Merge branch 'ocelot-phylink'

Vladimir Oltean says:

====================
Convert ocelot to phylink

The ocelot switchdev and felix dsa drivers are interesting because they
target the same class of hardware switches but used in different modes.

Colin has an interesting use case where he wants to use a hardware
switch supported by the ocelot switchdev driver with the felix dsa
driver.

So far, the existing hardware revisions were similar between the ocelot
and felix drivers, but not completely identical. With identical hardware,
it is absurd that the felix driver uses phylink while the ocelot driver
uses phylib - this should not be one of the differences between the
switchdev and dsa driver, and we could eliminate it.

Colin will need the common phylink support in ocelot and felix when
adding a phylink_pcs driver for the PCS1G block inside VSC7514, which
will make the felix driver work with either the NXP or the Microchip PCS.

As usual, Alex, Horatiu, sorry for bugging you, but it would be
appreciated if you could give this a quick run on actual VSC7514
hardware (which I don't have) to make sure I'm not introducing any
breakage.
====================

Fixes: 0f06a678 ("samples: Add an IPv6 "-6" option to the pktgen scripts")
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents e871ee69 e6e12df6
...@@ -796,23 +796,6 @@ static int felix_vlan_del(struct dsa_switch *ds, int port, ...@@ -796,23 +796,6 @@ static int felix_vlan_del(struct dsa_switch *ds, int port,
return ocelot_vlan_del(ocelot, port, vlan->vid); return ocelot_vlan_del(ocelot, port, vlan->vid);
} }
static int felix_port_enable(struct dsa_switch *ds, int port,
struct phy_device *phy)
{
struct ocelot *ocelot = ds->priv;
ocelot_port_enable(ocelot, port, phy);
return 0;
}
static void felix_port_disable(struct dsa_switch *ds, int port)
{
struct ocelot *ocelot = ds->priv;
return ocelot_port_disable(ocelot, port);
}
static void felix_phylink_validate(struct dsa_switch *ds, int port, static void felix_phylink_validate(struct dsa_switch *ds, int port,
unsigned long *supported, unsigned long *supported,
struct phylink_link_state *state) struct phylink_link_state *state)
...@@ -841,25 +824,9 @@ static void felix_phylink_mac_link_down(struct dsa_switch *ds, int port, ...@@ -841,25 +824,9 @@ static void felix_phylink_mac_link_down(struct dsa_switch *ds, int port,
phy_interface_t interface) phy_interface_t interface)
{ {
struct ocelot *ocelot = ds->priv; struct ocelot *ocelot = ds->priv;
struct ocelot_port *ocelot_port = ocelot->ports[port];
int err;
ocelot_port_rmwl(ocelot_port, 0, DEV_MAC_ENA_CFG_RX_ENA,
DEV_MAC_ENA_CFG);
ocelot_fields_write(ocelot, port, QSYS_SWITCH_PORT_MODE_PORT_ENA, 0); ocelot_phylink_mac_link_down(ocelot, port, link_an_mode, interface,
FELIX_MAC_QUIRKS);
err = ocelot_port_flush(ocelot, port);
if (err)
dev_err(ocelot->dev, "failed to flush port %d: %d\n",
port, err);
/* Put the port in reset. */
ocelot_port_writel(ocelot_port,
DEV_CLOCK_CFG_MAC_TX_RST |
DEV_CLOCK_CFG_MAC_RX_RST |
DEV_CLOCK_CFG_LINK_SPEED(OCELOT_SPEED_1000),
DEV_CLOCK_CFG);
} }
static void felix_phylink_mac_link_up(struct dsa_switch *ds, int port, static void felix_phylink_mac_link_up(struct dsa_switch *ds, int port,
...@@ -870,75 +837,11 @@ static void felix_phylink_mac_link_up(struct dsa_switch *ds, int port, ...@@ -870,75 +837,11 @@ static void felix_phylink_mac_link_up(struct dsa_switch *ds, int port,
bool tx_pause, bool rx_pause) bool tx_pause, bool rx_pause)
{ {
struct ocelot *ocelot = ds->priv; struct ocelot *ocelot = ds->priv;
struct ocelot_port *ocelot_port = ocelot->ports[port];
struct felix *felix = ocelot_to_felix(ocelot); struct felix *felix = ocelot_to_felix(ocelot);
u32 mac_fc_cfg;
/* Take port out of reset by clearing the MAC_TX_RST, MAC_RX_RST and
* PORT_RST bits in DEV_CLOCK_CFG. Note that the way this system is
* integrated is that the MAC speed is fixed and it's the PCS who is
* performing the rate adaptation, so we have to write "1000Mbps" into
* the LINK_SPEED field of DEV_CLOCK_CFG (which is also its default
* value).
*/
ocelot_port_writel(ocelot_port,
DEV_CLOCK_CFG_LINK_SPEED(OCELOT_SPEED_1000),
DEV_CLOCK_CFG);
switch (speed) {
case SPEED_10:
mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(3);
break;
case SPEED_100:
mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(2);
break;
case SPEED_1000:
case SPEED_2500:
mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(1);
break;
default:
dev_err(ocelot->dev, "Unsupported speed on port %d: %d\n",
port, speed);
return;
}
/* handle Rx pause in all cases, with 2500base-X this is used for rate
* adaptation.
*/
mac_fc_cfg |= SYS_MAC_FC_CFG_RX_FC_ENA;
if (tx_pause)
mac_fc_cfg |= SYS_MAC_FC_CFG_TX_FC_ENA |
SYS_MAC_FC_CFG_PAUSE_VAL_CFG(0xffff) |
SYS_MAC_FC_CFG_FC_LATENCY_CFG(0x7) |
SYS_MAC_FC_CFG_ZERO_PAUSE_ENA;
/* Flow control. Link speed is only used here to evaluate the time
* specification in incoming pause frames.
*/
ocelot_write_rix(ocelot, mac_fc_cfg, SYS_MAC_FC_CFG, port);
ocelot_write_rix(ocelot, 0, ANA_POL_FLOWC, port);
ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, tx_pause);
/* Undo the effects of felix_phylink_mac_link_down:
* enable MAC module
*/
ocelot_port_writel(ocelot_port, DEV_MAC_ENA_CFG_RX_ENA |
DEV_MAC_ENA_CFG_TX_ENA, DEV_MAC_ENA_CFG);
/* Enable receiving frames on the port, and activate auto-learning of
* MAC addresses.
*/
ocelot_write_gix(ocelot, ANA_PORT_PORT_CFG_LEARNAUTO |
ANA_PORT_PORT_CFG_RECV_ENA |
ANA_PORT_PORT_CFG_PORTID_VAL(port),
ANA_PORT_PORT_CFG, port);
/* Core: Enable port for frame transfer */ ocelot_phylink_mac_link_up(ocelot, port, phydev, link_an_mode,
ocelot_fields_write(ocelot, port, interface, speed, duplex, tx_pause, rx_pause,
QSYS_SWITCH_PORT_MODE_PORT_ENA, 1); FELIX_MAC_QUIRKS);
if (felix->info->port_sched_speed_set) if (felix->info->port_sched_speed_set)
felix->info->port_sched_speed_set(ocelot, port, speed); felix->info->port_sched_speed_set(ocelot, port, speed);
...@@ -1615,8 +1518,6 @@ const struct dsa_switch_ops felix_switch_ops = { ...@@ -1615,8 +1518,6 @@ const struct dsa_switch_ops felix_switch_ops = {
.phylink_mac_config = felix_phylink_mac_config, .phylink_mac_config = felix_phylink_mac_config,
.phylink_mac_link_down = felix_phylink_mac_link_down, .phylink_mac_link_down = felix_phylink_mac_link_down,
.phylink_mac_link_up = felix_phylink_mac_link_up, .phylink_mac_link_up = felix_phylink_mac_link_up,
.port_enable = felix_port_enable,
.port_disable = felix_port_disable,
.port_fdb_dump = felix_fdb_dump, .port_fdb_dump = felix_fdb_dump,
.port_fdb_add = felix_fdb_add, .port_fdb_add = felix_fdb_add,
.port_fdb_del = felix_fdb_del, .port_fdb_del = felix_fdb_del,
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#define _MSCC_FELIX_H #define _MSCC_FELIX_H
#define ocelot_to_felix(o) container_of((o), struct felix, ocelot) #define ocelot_to_felix(o) container_of((o), struct felix, ocelot)
#define FELIX_MAC_QUIRKS OCELOT_QUIRK_PCS_PERFORMS_RATE_ADAPTATION
/* Platform-specific information */ /* Platform-specific information */
struct felix_info { struct felix_info {
......
...@@ -16,7 +16,7 @@ config MSCC_OCELOT_SWITCH_LIB ...@@ -16,7 +16,7 @@ config MSCC_OCELOT_SWITCH_LIB
select NET_DEVLINK select NET_DEVLINK
select REGMAP_MMIO select REGMAP_MMIO
select PACKING select PACKING
select PHYLIB select PHYLINK
tristate tristate
help help
This is a hardware support library for Ocelot network switches. It is This is a hardware support library for Ocelot network switches. It is
......
...@@ -377,7 +377,7 @@ static u32 ocelot_read_eq_avail(struct ocelot *ocelot, int port) ...@@ -377,7 +377,7 @@ static u32 ocelot_read_eq_avail(struct ocelot *ocelot, int port)
return ocelot_read_rix(ocelot, QSYS_SW_STATUS, port); return ocelot_read_rix(ocelot, QSYS_SW_STATUS, port);
} }
int ocelot_port_flush(struct ocelot *ocelot, int port) static int ocelot_port_flush(struct ocelot *ocelot, int port)
{ {
unsigned int pause_ena; unsigned int pause_ena;
int err, val; int err, val;
...@@ -429,63 +429,118 @@ int ocelot_port_flush(struct ocelot *ocelot, int port) ...@@ -429,63 +429,118 @@ int ocelot_port_flush(struct ocelot *ocelot, int port)
return err; return err;
} }
EXPORT_SYMBOL(ocelot_port_flush);
void ocelot_adjust_link(struct ocelot *ocelot, int port, void ocelot_phylink_mac_link_down(struct ocelot *ocelot, int port,
struct phy_device *phydev) unsigned int link_an_mode,
phy_interface_t interface,
unsigned long quirks)
{ {
struct ocelot_port *ocelot_port = ocelot->ports[port]; struct ocelot_port *ocelot_port = ocelot->ports[port];
int speed, mode = 0; int err;
ocelot_port_rmwl(ocelot_port, 0, DEV_MAC_ENA_CFG_RX_ENA,
DEV_MAC_ENA_CFG);
ocelot_fields_write(ocelot, port, QSYS_SWITCH_PORT_MODE_PORT_ENA, 0);
err = ocelot_port_flush(ocelot, port);
if (err)
dev_err(ocelot->dev, "failed to flush port %d: %d\n",
port, err);
/* Put the port in reset. */
if (interface != PHY_INTERFACE_MODE_QSGMII ||
!(quirks & OCELOT_QUIRK_QSGMII_PORTS_MUST_BE_UP))
ocelot_port_rmwl(ocelot_port,
DEV_CLOCK_CFG_MAC_TX_RST |
DEV_CLOCK_CFG_MAC_TX_RST,
DEV_CLOCK_CFG_MAC_TX_RST |
DEV_CLOCK_CFG_MAC_TX_RST,
DEV_CLOCK_CFG);
}
EXPORT_SYMBOL_GPL(ocelot_phylink_mac_link_down);
switch (phydev->speed) { void ocelot_phylink_mac_link_up(struct ocelot *ocelot, int port,
struct phy_device *phydev,
unsigned int link_an_mode,
phy_interface_t interface,
int speed, int duplex,
bool tx_pause, bool rx_pause,
unsigned long quirks)
{
struct ocelot_port *ocelot_port = ocelot->ports[port];
int mac_speed, mode = 0;
u32 mac_fc_cfg;
/* The MAC might be integrated in systems where the MAC speed is fixed
* and it's the PCS who is performing the rate adaptation, so we have
* to write "1000Mbps" into the LINK_SPEED field of DEV_CLOCK_CFG
* (which is also its default value).
*/
if ((quirks & OCELOT_QUIRK_PCS_PERFORMS_RATE_ADAPTATION) ||
speed == SPEED_1000) {
mac_speed = OCELOT_SPEED_1000;
mode = DEV_MAC_MODE_CFG_GIGA_MODE_ENA;
} else if (speed == SPEED_2500) {
mac_speed = OCELOT_SPEED_2500;
mode = DEV_MAC_MODE_CFG_GIGA_MODE_ENA;
} else if (speed == SPEED_100) {
mac_speed = OCELOT_SPEED_100;
} else {
mac_speed = OCELOT_SPEED_10;
}
if (duplex == DUPLEX_FULL)
mode |= DEV_MAC_MODE_CFG_FDX_ENA;
ocelot_port_writel(ocelot_port, mode, DEV_MAC_MODE_CFG);
/* Take port out of reset by clearing the MAC_TX_RST, MAC_RX_RST and
* PORT_RST bits in DEV_CLOCK_CFG.
*/
ocelot_port_writel(ocelot_port, DEV_CLOCK_CFG_LINK_SPEED(mac_speed),
DEV_CLOCK_CFG);
switch (speed) {
case SPEED_10: case SPEED_10:
speed = OCELOT_SPEED_10; mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(OCELOT_SPEED_10);
break; break;
case SPEED_100: case SPEED_100:
speed = OCELOT_SPEED_100; mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(OCELOT_SPEED_100);
break; break;
case SPEED_1000: case SPEED_1000:
speed = OCELOT_SPEED_1000;
mode = DEV_MAC_MODE_CFG_GIGA_MODE_ENA;
break;
case SPEED_2500: case SPEED_2500:
speed = OCELOT_SPEED_2500; mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(OCELOT_SPEED_1000);
mode = DEV_MAC_MODE_CFG_GIGA_MODE_ENA;
break; break;
default: default:
dev_err(ocelot->dev, "Unsupported PHY speed on port %d: %d\n", dev_err(ocelot->dev, "Unsupported speed on port %d: %d\n",
port, phydev->speed); port, speed);
return; return;
} }
phy_print_status(phydev); /* Handle RX pause in all cases, with 2500base-X this is used for rate
* adaptation.
if (!phydev->link) */
return; mac_fc_cfg |= SYS_MAC_FC_CFG_RX_FC_ENA;
/* Only full duplex supported for now */
ocelot_port_writel(ocelot_port, DEV_MAC_MODE_CFG_FDX_ENA |
mode, DEV_MAC_MODE_CFG);
/* Disable HDX fast control */
ocelot_port_writel(ocelot_port, DEV_PORT_MISC_HDX_FAST_DIS,
DEV_PORT_MISC);
/* SGMII only for now */ if (tx_pause)
ocelot_port_writel(ocelot_port, PCS1G_MODE_CFG_SGMII_MODE_ENA, mac_fc_cfg |= SYS_MAC_FC_CFG_TX_FC_ENA |
PCS1G_MODE_CFG); SYS_MAC_FC_CFG_PAUSE_VAL_CFG(0xffff) |
ocelot_port_writel(ocelot_port, PCS1G_SD_CFG_SD_SEL, PCS1G_SD_CFG); SYS_MAC_FC_CFG_FC_LATENCY_CFG(0x7) |
SYS_MAC_FC_CFG_ZERO_PAUSE_ENA;
/* Enable PCS */ /* Flow control. Link speed is only used here to evaluate the time
ocelot_port_writel(ocelot_port, PCS1G_CFG_PCS_ENA, PCS1G_CFG); * specification in incoming pause frames.
*/
ocelot_write_rix(ocelot, mac_fc_cfg, SYS_MAC_FC_CFG, port);
/* No aneg on SGMII */ ocelot_write_rix(ocelot, 0, ANA_POL_FLOWC, port);
ocelot_port_writel(ocelot_port, 0, PCS1G_ANEG_CFG);
/* No loopback */ ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, tx_pause);
ocelot_port_writel(ocelot_port, 0, PCS1G_LB_CFG);
/* Enable MAC module */ /* Undo the effects of ocelot_phylink_mac_link_down:
* enable MAC module
*/
ocelot_port_writel(ocelot_port, DEV_MAC_ENA_CFG_RX_ENA | ocelot_port_writel(ocelot_port, DEV_MAC_ENA_CFG_RX_ENA |
DEV_MAC_ENA_CFG_TX_ENA, DEV_MAC_ENA_CFG); DEV_MAC_ENA_CFG_TX_ENA, DEV_MAC_ENA_CFG);
...@@ -502,39 +557,8 @@ void ocelot_adjust_link(struct ocelot *ocelot, int port, ...@@ -502,39 +557,8 @@ void ocelot_adjust_link(struct ocelot *ocelot, int port,
/* Core: Enable port for frame transfer */ /* Core: Enable port for frame transfer */
ocelot_fields_write(ocelot, port, ocelot_fields_write(ocelot, port,
QSYS_SWITCH_PORT_MODE_PORT_ENA, 1); QSYS_SWITCH_PORT_MODE_PORT_ENA, 1);
/* Flow control */
ocelot_write_rix(ocelot, SYS_MAC_FC_CFG_PAUSE_VAL_CFG(0xffff) |
SYS_MAC_FC_CFG_RX_FC_ENA | SYS_MAC_FC_CFG_TX_FC_ENA |
SYS_MAC_FC_CFG_ZERO_PAUSE_ENA |
SYS_MAC_FC_CFG_FC_LATENCY_CFG(0x7) |
SYS_MAC_FC_CFG_FC_LINK_SPEED(speed),
SYS_MAC_FC_CFG, port);
ocelot_write_rix(ocelot, 0, ANA_POL_FLOWC, port);
}
EXPORT_SYMBOL(ocelot_adjust_link);
void ocelot_port_enable(struct ocelot *ocelot, int port,
struct phy_device *phy)
{
/* Enable receiving frames on the port, and activate auto-learning of
* MAC addresses.
*/
ocelot_write_gix(ocelot, ANA_PORT_PORT_CFG_LEARNAUTO |
ANA_PORT_PORT_CFG_RECV_ENA |
ANA_PORT_PORT_CFG_PORTID_VAL(port),
ANA_PORT_PORT_CFG, port);
}
EXPORT_SYMBOL(ocelot_port_enable);
void ocelot_port_disable(struct ocelot *ocelot, int port)
{
struct ocelot_port *ocelot_port = ocelot->ports[port];
ocelot_port_writel(ocelot_port, 0, DEV_MAC_ENA_CFG);
ocelot_fields_write(ocelot, port, QSYS_SWITCH_PORT_MODE_PORT_ENA, 0);
} }
EXPORT_SYMBOL(ocelot_port_disable); EXPORT_SYMBOL_GPL(ocelot_phylink_mac_link_up);
static void ocelot_port_add_txtstamp_skb(struct ocelot *ocelot, int port, static void ocelot_port_add_txtstamp_skb(struct ocelot *ocelot, int port,
struct sk_buff *clone) struct sk_buff *clone)
...@@ -1956,6 +1980,15 @@ void ocelot_init_port(struct ocelot *ocelot, int port) ...@@ -1956,6 +1980,15 @@ void ocelot_init_port(struct ocelot *ocelot, int port)
/* Disable source address learning for standalone mode */ /* Disable source address learning for standalone mode */
ocelot_port_set_learning(ocelot, port, false); ocelot_port_set_learning(ocelot, port, false);
/* Set the port's initial logical port ID value, enable receiving
* frames on it, and configure the MAC address learning type to
* automatic.
*/
ocelot_write_gix(ocelot, ANA_PORT_PORT_CFG_LEARNAUTO |
ANA_PORT_PORT_CFG_RECV_ENA |
ANA_PORT_PORT_CFG_PORTID_VAL(port),
ANA_PORT_PORT_CFG, port);
/* Enable vcap lookups */ /* Enable vcap lookups */
ocelot_vcap_enable(ocelot, port); ocelot_vcap_enable(ocelot, port);
} }
......
...@@ -12,8 +12,7 @@ ...@@ -12,8 +12,7 @@
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
#include <linux/if_vlan.h> #include <linux/if_vlan.h>
#include <linux/net_tstamp.h> #include <linux/net_tstamp.h>
#include <linux/phy.h> #include <linux/phylink.h>
#include <linux/phy/phy.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/regmap.h> #include <linux/regmap.h>
...@@ -42,11 +41,9 @@ struct ocelot_port_tc { ...@@ -42,11 +41,9 @@ struct ocelot_port_tc {
struct ocelot_port_private { struct ocelot_port_private {
struct ocelot_port port; struct ocelot_port port;
struct net_device *dev; struct net_device *dev;
struct phy_device *phy; struct phylink *phylink;
struct phylink_config phylink_config;
u8 chip_port; u8 chip_port;
struct phy *serdes;
struct ocelot_port_tc tc; struct ocelot_port_tc tc;
}; };
...@@ -107,7 +104,7 @@ u32 ocelot_port_readl(struct ocelot_port *port, u32 reg); ...@@ -107,7 +104,7 @@ u32 ocelot_port_readl(struct ocelot_port *port, u32 reg);
void ocelot_port_writel(struct ocelot_port *port, u32 val, u32 reg); void ocelot_port_writel(struct ocelot_port *port, u32 val, u32 reg);
int ocelot_probe_port(struct ocelot *ocelot, int port, struct regmap *target, int ocelot_probe_port(struct ocelot *ocelot, int port, struct regmap *target,
struct phy_device *phy); struct device_node *portnp);
void ocelot_release_port(struct ocelot_port *ocelot_port); void ocelot_release_port(struct ocelot_port *ocelot_port);
int ocelot_devlink_init(struct ocelot *ocelot); int ocelot_devlink_init(struct ocelot *ocelot);
void ocelot_devlink_teardown(struct ocelot *ocelot); void ocelot_devlink_teardown(struct ocelot *ocelot);
......
...@@ -9,10 +9,14 @@ ...@@ -9,10 +9,14 @@
*/ */
#include <linux/if_bridge.h> #include <linux/if_bridge.h>
#include <linux/of_net.h>
#include <linux/phy/phy.h>
#include <net/pkt_cls.h> #include <net/pkt_cls.h>
#include "ocelot.h" #include "ocelot.h"
#include "ocelot_vcap.h" #include "ocelot_vcap.h"
#define OCELOT_MAC_QUIRKS OCELOT_QUIRK_QSGMII_PORTS_MUST_BE_UP
static struct ocelot *devlink_port_to_ocelot(struct devlink_port *dlp) static struct ocelot *devlink_port_to_ocelot(struct devlink_port *dlp)
{ {
return devlink_priv(dlp->devlink); return devlink_priv(dlp->devlink);
...@@ -381,15 +385,6 @@ static int ocelot_setup_tc(struct net_device *dev, enum tc_setup_type type, ...@@ -381,15 +385,6 @@ static int ocelot_setup_tc(struct net_device *dev, enum tc_setup_type type,
return 0; return 0;
} }
static void ocelot_port_adjust_link(struct net_device *dev)
{
struct ocelot_port_private *priv = netdev_priv(dev);
struct ocelot *ocelot = priv->port.ocelot;
int port = priv->chip_port;
ocelot_adjust_link(ocelot, port, dev->phydev);
}
static int ocelot_vlan_vid_prepare(struct net_device *dev, u16 vid, bool pvid, static int ocelot_vlan_vid_prepare(struct net_device *dev, u16 vid, bool pvid,
bool untagged) bool untagged)
{ {
...@@ -448,33 +443,8 @@ static int ocelot_vlan_vid_del(struct net_device *dev, u16 vid) ...@@ -448,33 +443,8 @@ static int ocelot_vlan_vid_del(struct net_device *dev, u16 vid)
static int ocelot_port_open(struct net_device *dev) static int ocelot_port_open(struct net_device *dev)
{ {
struct ocelot_port_private *priv = netdev_priv(dev); struct ocelot_port_private *priv = netdev_priv(dev);
struct ocelot_port *ocelot_port = &priv->port;
struct ocelot *ocelot = ocelot_port->ocelot;
int port = priv->chip_port;
int err;
if (priv->serdes) {
err = phy_set_mode_ext(priv->serdes, PHY_MODE_ETHERNET,
ocelot_port->phy_mode);
if (err) {
netdev_err(dev, "Could not set mode of SerDes\n");
return err;
}
}
err = phy_connect_direct(dev, priv->phy, &ocelot_port_adjust_link,
ocelot_port->phy_mode);
if (err) {
netdev_err(dev, "Could not attach to PHY\n");
return err;
}
dev->phydev = priv->phy; phylink_start(priv->phylink);
phy_attached_info(priv->phy);
phy_start(priv->phy);
ocelot_port_enable(ocelot, port, priv->phy);
return 0; return 0;
} }
...@@ -482,14 +452,8 @@ static int ocelot_port_open(struct net_device *dev) ...@@ -482,14 +452,8 @@ static int ocelot_port_open(struct net_device *dev)
static int ocelot_port_stop(struct net_device *dev) static int ocelot_port_stop(struct net_device *dev)
{ {
struct ocelot_port_private *priv = netdev_priv(dev); struct ocelot_port_private *priv = netdev_priv(dev);
struct ocelot *ocelot = priv->port.ocelot;
int port = priv->chip_port;
phy_disconnect(priv->phy); phylink_stop(priv->phylink);
dev->phydev = NULL;
ocelot_port_disable(ocelot, port);
return 0; return 0;
} }
...@@ -1528,8 +1492,188 @@ struct notifier_block ocelot_switchdev_blocking_nb __read_mostly = { ...@@ -1528,8 +1492,188 @@ struct notifier_block ocelot_switchdev_blocking_nb __read_mostly = {
.notifier_call = ocelot_switchdev_blocking_event, .notifier_call = ocelot_switchdev_blocking_event,
}; };
static void vsc7514_phylink_validate(struct phylink_config *config,
unsigned long *supported,
struct phylink_link_state *state)
{
struct net_device *ndev = to_net_dev(config->dev);
struct ocelot_port_private *priv = netdev_priv(ndev);
struct ocelot_port *ocelot_port = &priv->port;
__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = {};
if (state->interface != PHY_INTERFACE_MODE_NA &&
state->interface != ocelot_port->phy_mode) {
bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
return;
}
phylink_set_port_modes(mask);
phylink_set(mask, Pause);
phylink_set(mask, Autoneg);
phylink_set(mask, Asym_Pause);
phylink_set(mask, 10baseT_Half);
phylink_set(mask, 10baseT_Full);
phylink_set(mask, 100baseT_Half);
phylink_set(mask, 100baseT_Full);
phylink_set(mask, 1000baseT_Half);
phylink_set(mask, 1000baseT_Full);
phylink_set(mask, 1000baseX_Full);
phylink_set(mask, 2500baseT_Full);
phylink_set(mask, 2500baseX_Full);
bitmap_and(supported, supported, mask, __ETHTOOL_LINK_MODE_MASK_NBITS);
bitmap_and(state->advertising, state->advertising, mask,
__ETHTOOL_LINK_MODE_MASK_NBITS);
}
static void vsc7514_phylink_mac_config(struct phylink_config *config,
unsigned int link_an_mode,
const struct phylink_link_state *state)
{
struct net_device *ndev = to_net_dev(config->dev);
struct ocelot_port_private *priv = netdev_priv(ndev);
struct ocelot_port *ocelot_port = &priv->port;
/* Disable HDX fast control */
ocelot_port_writel(ocelot_port, DEV_PORT_MISC_HDX_FAST_DIS,
DEV_PORT_MISC);
/* SGMII only for now */
ocelot_port_writel(ocelot_port, PCS1G_MODE_CFG_SGMII_MODE_ENA,
PCS1G_MODE_CFG);
ocelot_port_writel(ocelot_port, PCS1G_SD_CFG_SD_SEL, PCS1G_SD_CFG);
/* Enable PCS */
ocelot_port_writel(ocelot_port, PCS1G_CFG_PCS_ENA, PCS1G_CFG);
/* No aneg on SGMII */
ocelot_port_writel(ocelot_port, 0, PCS1G_ANEG_CFG);
/* No loopback */
ocelot_port_writel(ocelot_port, 0, PCS1G_LB_CFG);
}
static void vsc7514_phylink_mac_link_down(struct phylink_config *config,
unsigned int link_an_mode,
phy_interface_t interface)
{
struct net_device *ndev = to_net_dev(config->dev);
struct ocelot_port_private *priv = netdev_priv(ndev);
struct ocelot *ocelot = priv->port.ocelot;
int port = priv->chip_port;
ocelot_phylink_mac_link_down(ocelot, port, link_an_mode, interface,
OCELOT_MAC_QUIRKS);
}
static void vsc7514_phylink_mac_link_up(struct phylink_config *config,
struct phy_device *phydev,
unsigned int link_an_mode,
phy_interface_t interface,
int speed, int duplex,
bool tx_pause, bool rx_pause)
{
struct net_device *ndev = to_net_dev(config->dev);
struct ocelot_port_private *priv = netdev_priv(ndev);
struct ocelot *ocelot = priv->port.ocelot;
int port = priv->chip_port;
ocelot_phylink_mac_link_up(ocelot, port, phydev, link_an_mode,
interface, speed, duplex,
tx_pause, rx_pause, OCELOT_MAC_QUIRKS);
}
static const struct phylink_mac_ops ocelot_phylink_ops = {
.validate = vsc7514_phylink_validate,
.mac_config = vsc7514_phylink_mac_config,
.mac_link_down = vsc7514_phylink_mac_link_down,
.mac_link_up = vsc7514_phylink_mac_link_up,
};
static int ocelot_port_phylink_create(struct ocelot *ocelot, int port,
struct device_node *portnp)
{
struct ocelot_port *ocelot_port = ocelot->ports[port];
struct ocelot_port_private *priv;
struct device *dev = ocelot->dev;
phy_interface_t phy_mode;
struct phylink *phylink;
int err;
of_get_phy_mode(portnp, &phy_mode);
/* DT bindings of internal PHY ports are broken and don't
* specify a phy-mode
*/
if (phy_mode == PHY_INTERFACE_MODE_NA)
phy_mode = PHY_INTERFACE_MODE_INTERNAL;
if (phy_mode != PHY_INTERFACE_MODE_SGMII &&
phy_mode != PHY_INTERFACE_MODE_QSGMII &&
phy_mode != PHY_INTERFACE_MODE_INTERNAL) {
dev_err(dev, "unsupported phy mode %s for port %d\n",
phy_modes(phy_mode), port);
return -EINVAL;
}
/* Ensure clock signals and speed are set on all QSGMII links */
if (phy_mode == PHY_INTERFACE_MODE_QSGMII)
ocelot_port_rmwl(ocelot_port, 0,
DEV_CLOCK_CFG_MAC_TX_RST |
DEV_CLOCK_CFG_MAC_TX_RST,
DEV_CLOCK_CFG);
ocelot_port->phy_mode = phy_mode;
if (phy_mode != PHY_INTERFACE_MODE_INTERNAL) {
struct phy *serdes = of_phy_get(portnp, NULL);
if (IS_ERR(serdes)) {
err = PTR_ERR(serdes);
dev_err_probe(dev, err,
"missing SerDes phys for port %d\n",
port);
return err;
}
err = phy_set_mode_ext(serdes, PHY_MODE_ETHERNET, phy_mode);
of_phy_put(serdes);
if (err) {
dev_err(dev, "Could not SerDes mode on port %d: %pe\n",
port, ERR_PTR(err));
return err;
}
}
priv = container_of(ocelot_port, struct ocelot_port_private, port);
priv->phylink_config.dev = &priv->dev->dev;
priv->phylink_config.type = PHYLINK_NETDEV;
phylink = phylink_create(&priv->phylink_config,
of_fwnode_handle(portnp),
phy_mode, &ocelot_phylink_ops);
if (IS_ERR(phylink)) {
err = PTR_ERR(phylink);
dev_err(dev, "Could not create phylink (%pe)\n", phylink);
return err;
}
priv->phylink = phylink;
err = phylink_of_phy_connect(phylink, portnp, 0);
if (err) {
dev_err(dev, "Could not connect to PHY: %pe\n", ERR_PTR(err));
phylink_destroy(phylink);
priv->phylink = NULL;
return err;
}
return 0;
}
int ocelot_probe_port(struct ocelot *ocelot, int port, struct regmap *target, int ocelot_probe_port(struct ocelot *ocelot, int port, struct regmap *target,
struct phy_device *phy) struct device_node *portnp)
{ {
struct ocelot_port_private *priv; struct ocelot_port_private *priv;
struct ocelot_port *ocelot_port; struct ocelot_port *ocelot_port;
...@@ -1542,7 +1686,6 @@ int ocelot_probe_port(struct ocelot *ocelot, int port, struct regmap *target, ...@@ -1542,7 +1686,6 @@ int ocelot_probe_port(struct ocelot *ocelot, int port, struct regmap *target,
SET_NETDEV_DEV(dev, ocelot->dev); SET_NETDEV_DEV(dev, ocelot->dev);
priv = netdev_priv(dev); priv = netdev_priv(dev);
priv->dev = dev; priv->dev = dev;
priv->phy = phy;
priv->chip_port = port; priv->chip_port = port;
ocelot_port = &priv->port; ocelot_port = &priv->port;
ocelot_port->ocelot = ocelot; ocelot_port->ocelot = ocelot;
...@@ -1563,15 +1706,23 @@ int ocelot_probe_port(struct ocelot *ocelot, int port, struct regmap *target, ...@@ -1563,15 +1706,23 @@ int ocelot_probe_port(struct ocelot *ocelot, int port, struct regmap *target,
ocelot_init_port(ocelot, port); ocelot_init_port(ocelot, port);
err = ocelot_port_phylink_create(ocelot, port, portnp);
if (err)
goto out;
err = register_netdev(dev); err = register_netdev(dev);
if (err) { if (err) {
dev_err(ocelot->dev, "register_netdev failed\n"); dev_err(ocelot->dev, "register_netdev failed\n");
free_netdev(dev); goto out;
ocelot->ports[port] = NULL;
return err;
} }
return 0; return 0;
out:
ocelot->ports[port] = NULL;
free_netdev(dev);
return err;
} }
void ocelot_release_port(struct ocelot_port *ocelot_port) void ocelot_release_port(struct ocelot_port *ocelot_port)
...@@ -1581,5 +1732,14 @@ void ocelot_release_port(struct ocelot_port *ocelot_port) ...@@ -1581,5 +1732,14 @@ void ocelot_release_port(struct ocelot_port *ocelot_port)
port); port);
unregister_netdev(priv->dev); unregister_netdev(priv->dev);
if (priv->phylink) {
rtnl_lock();
phylink_disconnect_phy(priv->phylink);
rtnl_unlock();
phylink_destroy(priv->phylink);
}
free_netdev(priv->dev); free_netdev(priv->dev);
} }
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/of_net.h> #include <linux/of_net.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/phylink.h>
#include <linux/of_mdio.h> #include <linux/of_mdio.h>
#include <linux/of_platform.h> #include <linux/of_platform.h>
#include <linux/mfd/syscon.h> #include <linux/mfd/syscon.h>
...@@ -945,13 +946,9 @@ static int mscc_ocelot_init_ports(struct platform_device *pdev, ...@@ -945,13 +946,9 @@ static int mscc_ocelot_init_ports(struct platform_device *pdev,
for_each_available_child_of_node(ports, portnp) { for_each_available_child_of_node(ports, portnp) {
struct ocelot_port_private *priv; struct ocelot_port_private *priv;
struct ocelot_port *ocelot_port; struct ocelot_port *ocelot_port;
struct device_node *phy_node;
struct devlink_port *dlp; struct devlink_port *dlp;
phy_interface_t phy_mode;
struct phy_device *phy;
struct regmap *target; struct regmap *target;
struct resource *res; struct resource *res;
struct phy *serdes;
char res_name[8]; char res_name[8];
if (of_property_read_u32(portnp, "reg", &reg)) if (of_property_read_u32(portnp, "reg", &reg))
...@@ -975,15 +972,6 @@ static int mscc_ocelot_init_ports(struct platform_device *pdev, ...@@ -975,15 +972,6 @@ static int mscc_ocelot_init_ports(struct platform_device *pdev,
goto out_teardown; goto out_teardown;
} }
phy_node = of_parse_phandle(portnp, "phy-handle", 0);
if (!phy_node)
continue;
phy = of_phy_find_device(phy_node);
of_node_put(phy_node);
if (!phy)
continue;
err = ocelot_port_devlink_init(ocelot, port, err = ocelot_port_devlink_init(ocelot, port,
DEVLINK_PORT_FLAVOUR_PHYSICAL); DEVLINK_PORT_FLAVOUR_PHYSICAL);
if (err) { if (err) {
...@@ -992,7 +980,7 @@ static int mscc_ocelot_init_ports(struct platform_device *pdev, ...@@ -992,7 +980,7 @@ static int mscc_ocelot_init_ports(struct platform_device *pdev,
} }
devlink_ports_registered |= BIT(port); devlink_ports_registered |= BIT(port);
err = ocelot_probe_port(ocelot, port, target, phy); err = ocelot_probe_port(ocelot, port, target, portnp);
if (err) { if (err) {
of_node_put(portnp); of_node_put(portnp);
goto out_teardown; goto out_teardown;
...@@ -1003,49 +991,6 @@ static int mscc_ocelot_init_ports(struct platform_device *pdev, ...@@ -1003,49 +991,6 @@ static int mscc_ocelot_init_ports(struct platform_device *pdev,
port); port);
dlp = &ocelot->devlink_ports[port]; dlp = &ocelot->devlink_ports[port];
devlink_port_type_eth_set(dlp, priv->dev); devlink_port_type_eth_set(dlp, priv->dev);
of_get_phy_mode(portnp, &phy_mode);
ocelot_port->phy_mode = phy_mode;
switch (ocelot_port->phy_mode) {
case PHY_INTERFACE_MODE_NA:
continue;
case PHY_INTERFACE_MODE_SGMII:
break;
case PHY_INTERFACE_MODE_QSGMII:
/* Ensure clock signals and speed is set on all
* QSGMII links
*/
ocelot_port_writel(ocelot_port,
DEV_CLOCK_CFG_LINK_SPEED
(OCELOT_SPEED_1000),
DEV_CLOCK_CFG);
break;
default:
dev_err(ocelot->dev,
"invalid phy mode for port%d, (Q)SGMII only\n",
port);
of_node_put(portnp);
err = -EINVAL;
goto out_teardown;
}
serdes = devm_of_phy_get(ocelot->dev, portnp, NULL);
if (IS_ERR(serdes)) {
err = PTR_ERR(serdes);
if (err == -EPROBE_DEFER)
dev_dbg(ocelot->dev, "deferring probe\n");
else
dev_err(ocelot->dev,
"missing SerDes phys for port%d\n",
port);
of_node_put(portnp);
goto out_teardown;
}
priv->serdes = serdes;
} }
/* Initialize unused devlink ports at the end */ /* Initialize unused devlink ports at the end */
......
...@@ -589,6 +589,9 @@ enum ocelot_sb_pool { ...@@ -589,6 +589,9 @@ enum ocelot_sb_pool {
OCELOT_SB_POOL_NUM, OCELOT_SB_POOL_NUM,
}; };
#define OCELOT_QUIRK_PCS_PERFORMS_RATE_ADAPTATION BIT(0)
#define OCELOT_QUIRK_QSGMII_PORTS_MUST_BE_UP BIT(1)
struct ocelot_port { struct ocelot_port {
struct ocelot *ocelot; struct ocelot *ocelot;
...@@ -798,18 +801,12 @@ void ocelot_init_port(struct ocelot *ocelot, int port); ...@@ -798,18 +801,12 @@ void ocelot_init_port(struct ocelot *ocelot, int port);
void ocelot_deinit_port(struct ocelot *ocelot, int port); void ocelot_deinit_port(struct ocelot *ocelot, int port);
/* DSA callbacks */ /* DSA callbacks */
void ocelot_port_enable(struct ocelot *ocelot, int port,
struct phy_device *phy);
void ocelot_port_disable(struct ocelot *ocelot, int port);
void ocelot_get_strings(struct ocelot *ocelot, int port, u32 sset, u8 *data); void ocelot_get_strings(struct ocelot *ocelot, int port, u32 sset, u8 *data);
void ocelot_get_ethtool_stats(struct ocelot *ocelot, int port, u64 *data); void ocelot_get_ethtool_stats(struct ocelot *ocelot, int port, u64 *data);
int ocelot_get_sset_count(struct ocelot *ocelot, int port, int sset); int ocelot_get_sset_count(struct ocelot *ocelot, int port, int sset);
int ocelot_get_ts_info(struct ocelot *ocelot, int port, int ocelot_get_ts_info(struct ocelot *ocelot, int port,
struct ethtool_ts_info *info); struct ethtool_ts_info *info);
void ocelot_set_ageing_time(struct ocelot *ocelot, unsigned int msecs); void ocelot_set_ageing_time(struct ocelot *ocelot, unsigned int msecs);
int ocelot_port_flush(struct ocelot *ocelot, int port);
void ocelot_adjust_link(struct ocelot *ocelot, int port,
struct phy_device *phydev);
int ocelot_port_vlan_filtering(struct ocelot *ocelot, int port, bool enabled); int ocelot_port_vlan_filtering(struct ocelot *ocelot, int port, bool enabled);
void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port, u8 state); void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port, u8 state);
void ocelot_apply_bridge_fwd_mask(struct ocelot *ocelot); void ocelot_apply_bridge_fwd_mask(struct ocelot *ocelot);
...@@ -894,6 +891,18 @@ int ocelot_sb_occ_tc_port_bind_get(struct ocelot *ocelot, int port, ...@@ -894,6 +891,18 @@ int ocelot_sb_occ_tc_port_bind_get(struct ocelot *ocelot, int port,
enum devlink_sb_pool_type pool_type, enum devlink_sb_pool_type pool_type,
u32 *p_cur, u32 *p_max); u32 *p_cur, u32 *p_max);
void ocelot_phylink_mac_link_down(struct ocelot *ocelot, int port,
unsigned int link_an_mode,
phy_interface_t interface,
unsigned long quirks);
void ocelot_phylink_mac_link_up(struct ocelot *ocelot, int port,
struct phy_device *phydev,
unsigned int link_an_mode,
phy_interface_t interface,
int speed, int duplex,
bool tx_pause, bool rx_pause,
unsigned long quirks);
#if IS_ENABLED(CONFIG_BRIDGE_MRP) #if IS_ENABLED(CONFIG_BRIDGE_MRP)
int ocelot_mrp_add(struct ocelot *ocelot, int port, int ocelot_mrp_add(struct ocelot *ocelot, int port,
const struct switchdev_obj_mrp *mrp); const struct switchdev_obj_mrp *mrp);
......
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