Skip to content

Commit

Permalink
Merge branch 'lynx-pcs-interface-cleanup'
Browse files Browse the repository at this point in the history
Colin Foster says:

====================
lynx pcs interface cleanup

The current Felix driver (and Seville) rely directly on the lynx_pcs
device. There are other possible PCS interfaces that can be used with
this hardware, so this should be abstracted from felix. The generic
phylink_pcs is used instead.

While going through the code, there were some opportunities to change
some misleading variable names. Those are included in this patch set.

v1->v2
    * compile-time fixes for freescale parts
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Jan 2, 2022
2 parents 60c3320 + 0699b3e commit 0d6f01f
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 66 deletions.
3 changes: 1 addition & 2 deletions drivers/net/dsa/ocelot/felix.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <linux/of_net.h>
#include <linux/pci.h>
#include <linux/of.h>
#include <linux/pcs-lynx.h>
#include <net/pkt_sched.h>
#include <net/dsa.h>
#include "felix.h"
Expand Down Expand Up @@ -832,7 +831,7 @@ static void felix_phylink_mac_config(struct dsa_switch *ds, int port,
struct dsa_port *dp = dsa_to_port(ds, port);

if (felix->pcs && felix->pcs[port])
phylink_set_pcs(dp->pl, &felix->pcs[port]->pcs);
phylink_set_pcs(dp->pl, felix->pcs[port]);
}

static void felix_phylink_mac_link_down(struct dsa_switch *ds, int port,
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/dsa/ocelot/felix.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct felix {
const struct felix_info *info;
struct ocelot ocelot;
struct mii_bus *imdio;
struct lynx_pcs **pcs;
struct phylink_pcs **pcs;
resource_size_t switch_base;
resource_size_t imdio_base;
enum dsa_tag_protocol tag_proto;
Expand Down
28 changes: 15 additions & 13 deletions drivers/net/dsa/ocelot/felix_vsc9959.c
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ static int vsc9959_mdio_bus_alloc(struct ocelot *ocelot)
int rc;

felix->pcs = devm_kcalloc(dev, felix->info->num_ports,
sizeof(struct lynx_pcs *),
sizeof(struct phylink_pcs *),
GFP_KERNEL);
if (!felix->pcs) {
dev_err(dev, "failed to allocate array for PCS PHYs\n");
Expand Down Expand Up @@ -1088,26 +1088,26 @@ static int vsc9959_mdio_bus_alloc(struct ocelot *ocelot)

for (port = 0; port < felix->info->num_ports; port++) {
struct ocelot_port *ocelot_port = ocelot->ports[port];
struct mdio_device *pcs;
struct lynx_pcs *lynx;
struct phylink_pcs *phylink_pcs;
struct mdio_device *mdio_device;

if (dsa_is_unused_port(felix->ds, port))
continue;

if (ocelot_port->phy_mode == PHY_INTERFACE_MODE_INTERNAL)
continue;

pcs = mdio_device_create(felix->imdio, port);
if (IS_ERR(pcs))
mdio_device = mdio_device_create(felix->imdio, port);
if (IS_ERR(mdio_device))
continue;

lynx = lynx_pcs_create(pcs);
if (!lynx) {
mdio_device_free(pcs);
phylink_pcs = lynx_pcs_create(mdio_device);
if (!phylink_pcs) {
mdio_device_free(mdio_device);
continue;
}

felix->pcs[port] = lynx;
felix->pcs[port] = phylink_pcs;

dev_info(dev, "Found PCS at internal MDIO address %d\n", port);
}
Expand All @@ -1121,13 +1121,15 @@ static void vsc9959_mdio_bus_free(struct ocelot *ocelot)
int port;

for (port = 0; port < ocelot->num_phys_ports; port++) {
struct lynx_pcs *pcs = felix->pcs[port];
struct phylink_pcs *phylink_pcs = felix->pcs[port];
struct mdio_device *mdio_device;

if (!pcs)
if (!phylink_pcs)
continue;

mdio_device_free(pcs->mdio);
lynx_pcs_destroy(pcs);
mdio_device = lynx_get_mdio_device(phylink_pcs);
mdio_device_free(mdio_device);
lynx_pcs_destroy(phylink_pcs);
}
mdiobus_unregister(felix->imdio);
}
Expand Down
28 changes: 15 additions & 13 deletions drivers/net/dsa/ocelot/seville_vsc9953.c
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ static int vsc9953_mdio_bus_alloc(struct ocelot *ocelot)
int rc;

felix->pcs = devm_kcalloc(dev, felix->info->num_ports,
sizeof(struct phy_device *),
sizeof(struct phylink_pcs *),
GFP_KERNEL);
if (!felix->pcs) {
dev_err(dev, "failed to allocate array for PCS PHYs\n");
Expand All @@ -1039,27 +1039,27 @@ static int vsc9953_mdio_bus_alloc(struct ocelot *ocelot)

for (port = 0; port < felix->info->num_ports; port++) {
struct ocelot_port *ocelot_port = ocelot->ports[port];
struct phylink_pcs *phylink_pcs;
struct mdio_device *mdio_device;
int addr = port + 4;
struct mdio_device *pcs;
struct lynx_pcs *lynx;

if (dsa_is_unused_port(felix->ds, port))
continue;

if (ocelot_port->phy_mode == PHY_INTERFACE_MODE_INTERNAL)
continue;

pcs = mdio_device_create(felix->imdio, addr);
if (IS_ERR(pcs))
mdio_device = mdio_device_create(felix->imdio, addr);
if (IS_ERR(mdio_device))
continue;

lynx = lynx_pcs_create(pcs);
if (!lynx) {
mdio_device_free(pcs);
phylink_pcs = lynx_pcs_create(mdio_device);
if (!phylink_pcs) {
mdio_device_free(mdio_device);
continue;
}

felix->pcs[port] = lynx;
felix->pcs[port] = phylink_pcs;

dev_info(dev, "Found PCS at internal MDIO address %d\n", addr);
}
Expand All @@ -1073,13 +1073,15 @@ static void vsc9953_mdio_bus_free(struct ocelot *ocelot)
int port;

for (port = 0; port < ocelot->num_phys_ports; port++) {
struct lynx_pcs *pcs = felix->pcs[port];
struct phylink_pcs *phylink_pcs = felix->pcs[port];
struct mdio_device *mdio_device;

if (!pcs)
if (!phylink_pcs)
continue;

mdio_device_free(pcs->mdio);
lynx_pcs_destroy(pcs);
mdio_device = lynx_get_mdio_device(phylink_pcs);
mdio_device_free(mdio_device);
lynx_pcs_destroy(phylink_pcs);
}
mdiobus_unregister(felix->imdio);
}
Expand Down
13 changes: 8 additions & 5 deletions drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* Copyright 2019 NXP */

#include <linux/acpi.h>
#include <linux/pcs-lynx.h>
#include <linux/property.h>

#include "dpaa2-eth.h"
Expand Down Expand Up @@ -204,11 +205,13 @@ static int dpaa2_pcs_create(struct dpaa2_mac *mac,

static void dpaa2_pcs_destroy(struct dpaa2_mac *mac)
{
struct lynx_pcs *pcs = mac->pcs;
struct phylink_pcs *phylink_pcs = mac->pcs;

if (pcs) {
struct device *dev = &pcs->mdio->dev;
lynx_pcs_destroy(pcs);
if (phylink_pcs) {
struct mdio_device *mdio = lynx_get_mdio_device(phylink_pcs);
struct device *dev = &mdio->dev;

lynx_pcs_destroy(phylink_pcs);
put_device(dev);
mac->pcs = NULL;
}
Expand Down Expand Up @@ -292,7 +295,7 @@ int dpaa2_mac_connect(struct dpaa2_mac *mac)
mac->phylink = phylink;

if (mac->pcs)
phylink_set_pcs(mac->phylink, &mac->pcs->pcs);
phylink_set_pcs(mac->phylink, mac->pcs);

err = phylink_fwnode_phy_connect(mac->phylink, dpmac_node, 0);
if (err) {
Expand Down
3 changes: 1 addition & 2 deletions drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <linux/of_mdio.h>
#include <linux/of_net.h>
#include <linux/phylink.h>
#include <linux/pcs-lynx.h>

#include "dpmac.h"
#include "dpmac-cmd.h"
Expand All @@ -23,7 +22,7 @@ struct dpaa2_mac {
struct phylink *phylink;
phy_interface_t if_mode;
enum dpmac_link_type if_link_type;
struct lynx_pcs *pcs;
struct phylink_pcs *pcs;
struct fwnode_handle *fw_node;
};

Expand Down
28 changes: 16 additions & 12 deletions drivers/net/ethernet/freescale/enetc/enetc_pf.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <linux/of_platform.h>
#include <linux/of_mdio.h>
#include <linux/of_net.h>
#include <linux/pcs-lynx.h>
#include "enetc_ierb.h"
#include "enetc_pf.h"

Expand Down Expand Up @@ -828,8 +829,8 @@ static int enetc_imdio_create(struct enetc_pf *pf)
{
struct device *dev = &pf->si->pdev->dev;
struct enetc_mdio_priv *mdio_priv;
struct lynx_pcs *pcs_lynx;
struct mdio_device *pcs;
struct phylink_pcs *phylink_pcs;
struct mdio_device *mdio_device;
struct mii_bus *bus;
int err;

Expand All @@ -853,23 +854,23 @@ static int enetc_imdio_create(struct enetc_pf *pf)
goto free_mdio_bus;
}

pcs = mdio_device_create(bus, 0);
if (IS_ERR(pcs)) {
err = PTR_ERR(pcs);
dev_err(dev, "cannot create pcs (%d)\n", err);
mdio_device = mdio_device_create(bus, 0);
if (IS_ERR(mdio_device)) {
err = PTR_ERR(mdio_device);
dev_err(dev, "cannot create mdio device (%d)\n", err);
goto unregister_mdiobus;
}

pcs_lynx = lynx_pcs_create(pcs);
if (!pcs_lynx) {
mdio_device_free(pcs);
phylink_pcs = lynx_pcs_create(mdio_device);
if (!phylink_pcs) {
mdio_device_free(mdio_device);
err = -ENOMEM;
dev_err(dev, "cannot create lynx pcs (%d)\n", err);
goto unregister_mdiobus;
}

pf->imdio = bus;
pf->pcs = pcs_lynx;
pf->pcs = phylink_pcs;

return 0;

Expand All @@ -882,8 +883,11 @@ static int enetc_imdio_create(struct enetc_pf *pf)

static void enetc_imdio_remove(struct enetc_pf *pf)
{
struct mdio_device *mdio_device;

if (pf->pcs) {
mdio_device_free(pf->pcs->mdio);
mdio_device = lynx_get_mdio_device(pf->pcs);
mdio_device_free(mdio_device);
lynx_pcs_destroy(pf->pcs);
}
if (pf->imdio) {
Expand Down Expand Up @@ -941,7 +945,7 @@ static void enetc_pl_mac_config(struct phylink_config *config,

priv = netdev_priv(pf->si->ndev);
if (pf->pcs)
phylink_set_pcs(priv->phylink, &pf->pcs->pcs);
phylink_set_pcs(priv->phylink, pf->pcs);
}

static void enetc_force_rgmii_mac(struct enetc_hw *hw, int speed, int duplex)
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/ethernet/freescale/enetc/enetc_pf.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* Copyright 2017-2019 NXP */

#include "enetc.h"
#include <linux/pcs-lynx.h>
#include <linux/phylink.h>

#define ENETC_PF_NUM_RINGS 8

Expand Down Expand Up @@ -46,7 +46,7 @@ struct enetc_pf {

struct mii_bus *mdio; /* saved for cleanup */
struct mii_bus *imdio;
struct lynx_pcs *pcs;
struct phylink_pcs *pcs;

phy_interface_t if_mode;
struct phylink_config phylink_config;
Expand Down
36 changes: 26 additions & 10 deletions drivers/net/pcs/pcs-lynx.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
#define IF_MODE_SPEED_MSK GENMASK(3, 2)
#define IF_MODE_HALF_DUPLEX BIT(4)

struct lynx_pcs {
struct phylink_pcs pcs;
struct mdio_device *mdio;
};

enum sgmii_speed {
SGMII_SPEED_10 = 0,
SGMII_SPEED_100 = 1,
Expand All @@ -30,6 +35,15 @@ enum sgmii_speed {
};

#define phylink_pcs_to_lynx(pl_pcs) container_of((pl_pcs), struct lynx_pcs, pcs)
#define lynx_to_phylink_pcs(lynx) (&(lynx)->pcs)

struct mdio_device *lynx_get_mdio_device(struct phylink_pcs *pcs)
{
struct lynx_pcs *lynx = phylink_pcs_to_lynx(pcs);

return lynx->mdio;
}
EXPORT_SYMBOL(lynx_get_mdio_device);

static void lynx_pcs_get_state_usxgmii(struct mdio_device *pcs,
struct phylink_link_state *state)
Expand Down Expand Up @@ -329,25 +343,27 @@ static const struct phylink_pcs_ops lynx_pcs_phylink_ops = {
.pcs_link_up = lynx_pcs_link_up,
};

struct lynx_pcs *lynx_pcs_create(struct mdio_device *mdio)
struct phylink_pcs *lynx_pcs_create(struct mdio_device *mdio)
{
struct lynx_pcs *lynx_pcs;
struct lynx_pcs *lynx;

lynx_pcs = kzalloc(sizeof(*lynx_pcs), GFP_KERNEL);
if (!lynx_pcs)
lynx = kzalloc(sizeof(*lynx), GFP_KERNEL);
if (!lynx)
return NULL;

lynx_pcs->mdio = mdio;
lynx_pcs->pcs.ops = &lynx_pcs_phylink_ops;
lynx_pcs->pcs.poll = true;
lynx->mdio = mdio;
lynx->pcs.ops = &lynx_pcs_phylink_ops;
lynx->pcs.poll = true;

return lynx_pcs;
return lynx_to_phylink_pcs(lynx);
}
EXPORT_SYMBOL(lynx_pcs_create);

void lynx_pcs_destroy(struct lynx_pcs *pcs)
void lynx_pcs_destroy(struct phylink_pcs *pcs)
{
kfree(pcs);
struct lynx_pcs *lynx = phylink_pcs_to_lynx(pcs);

kfree(lynx);
}
EXPORT_SYMBOL(lynx_pcs_destroy);

Expand Down
9 changes: 3 additions & 6 deletions include/linux/pcs-lynx.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@
#include <linux/mdio.h>
#include <linux/phylink.h>

struct lynx_pcs {
struct phylink_pcs pcs;
struct mdio_device *mdio;
};
struct mdio_device *lynx_get_mdio_device(struct phylink_pcs *pcs);

struct lynx_pcs *lynx_pcs_create(struct mdio_device *mdio);
struct phylink_pcs *lynx_pcs_create(struct mdio_device *mdio);

void lynx_pcs_destroy(struct lynx_pcs *pcs);
void lynx_pcs_destroy(struct phylink_pcs *pcs);

#endif /* __LINUX_PCS_LYNX_H */

0 comments on commit 0d6f01f

Please sign in to comment.