Skip to content

Commit

Permalink
net: fman: Configure fixed link in memac_initialization
Browse files Browse the repository at this point in the history
memac is the only mac which parses fixed links. Move the
parsing/configuring to its initialization function.

Signed-off-by: Sean Anderson <sean.anderson@seco.com>
Acked-by: Camelia Groza <camelia.groza@nxp.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Sean Anderson authored and Jakub Kicinski committed Aug 19, 2022
1 parent 7bd6396 commit 9ea4742
Showing 1 changed file with 46 additions and 47 deletions.
93 changes: 46 additions & 47 deletions drivers/net/ethernet/freescale/fman/mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ struct mac_priv_s {
/* List of multicast addresses */
struct list_head mc_addr_list;
struct platform_device *eth_dev;
struct fixed_phy_status *fixed_link;
u16 speed;
u16 max_speed;
};
Expand Down Expand Up @@ -391,6 +390,7 @@ static int memac_initialization(struct mac_device *mac_dev,
int err;
struct mac_priv_s *priv;
struct fman_mac_params params;
struct fixed_phy_status *fixed_link;

priv = mac_dev->priv;
mac_dev->set_promisc = memac_set_promiscuous;
Expand Down Expand Up @@ -429,21 +429,52 @@ static int memac_initialization(struct mac_device *mac_dev,
if (err < 0)
goto _return_fm_mac_free;

err = memac_cfg_fixed_link(mac_dev->fman_mac, priv->fixed_link);
if (err < 0)
goto _return_fm_mac_free;
if (!mac_dev->phy_node && of_phy_is_fixed_link(mac_node)) {
struct phy_device *phy;

err = of_phy_register_fixed_link(mac_node);
if (err)
goto _return_fm_mac_free;

fixed_link = kzalloc(sizeof(*fixed_link), GFP_KERNEL);
if (!fixed_link) {
err = -ENOMEM;
goto _return_fm_mac_free;
}

mac_dev->phy_node = of_node_get(mac_node);
phy = of_phy_find_device(mac_dev->phy_node);
if (!phy) {
err = -EINVAL;
of_node_put(mac_dev->phy_node);
goto _return_fixed_link_free;
}

fixed_link->link = phy->link;
fixed_link->speed = phy->speed;
fixed_link->duplex = phy->duplex;
fixed_link->pause = phy->pause;
fixed_link->asym_pause = phy->asym_pause;

put_device(&phy->mdio.dev);

err = memac_cfg_fixed_link(mac_dev->fman_mac, fixed_link);
if (err < 0)
goto _return_fixed_link_free;
}

err = memac_init(mac_dev->fman_mac);
if (err < 0)
goto _return_fm_mac_free;
goto _return_fixed_link_free;

dev_info(mac_dev->dev, "FMan MEMAC\n");

goto _return;

_return_fixed_link_free:
kfree(fixed_link);
_return_fm_mac_free:
memac_free(mac_dev->fman_mac);

_return:
return err;
}
Expand Down Expand Up @@ -570,7 +601,7 @@ static int mac_probe(struct platform_device *_of_dev)
dev_err(dev, "of_get_parent(%pOF) failed\n",
mac_node);
err = -EINVAL;
goto _return_of_get_parent;
goto _return_of_node_put;
}

of_dev = of_find_device_by_node(dev_node);
Expand Down Expand Up @@ -604,7 +635,7 @@ static int mac_probe(struct platform_device *_of_dev)
if (err < 0) {
dev_err(dev, "of_address_to_resource(%pOF) = %d\n",
mac_node, err);
goto _return_of_get_parent;
goto _return_of_node_put;
}

mac_dev->res = __devm_request_region(dev,
Expand All @@ -614,28 +645,28 @@ static int mac_probe(struct platform_device *_of_dev)
if (!mac_dev->res) {
dev_err(dev, "__devm_request_mem_region(mac) failed\n");
err = -EBUSY;
goto _return_of_get_parent;
goto _return_of_node_put;
}

priv->vaddr = devm_ioremap(dev, mac_dev->res->start,
resource_size(mac_dev->res));
if (!priv->vaddr) {
dev_err(dev, "devm_ioremap() failed\n");
err = -EIO;
goto _return_of_get_parent;
goto _return_of_node_put;
}

if (!of_device_is_available(mac_node)) {
err = -ENODEV;
goto _return_of_get_parent;
goto _return_of_node_put;
}

/* Get the cell-index */
err = of_property_read_u32(mac_node, "cell-index", &val);
if (err) {
dev_err(dev, "failed to read cell-index for %pOF\n", mac_node);
err = -EINVAL;
goto _return_of_get_parent;
goto _return_of_node_put;
}
priv->cell_index = (u8)val;

Expand All @@ -650,14 +681,14 @@ static int mac_probe(struct platform_device *_of_dev)
dev_err(dev, "of_count_phandle_with_args(%pOF, fsl,fman-ports) failed\n",
mac_node);
err = nph;
goto _return_of_get_parent;
goto _return_of_node_put;
}

if (nph != ARRAY_SIZE(mac_dev->port)) {
dev_err(dev, "Not supported number of fman-ports handles of mac node %pOF from device tree\n",
mac_node);
err = -EINVAL;
goto _return_of_get_parent;
goto _return_of_node_put;
}

for (i = 0; i < ARRAY_SIZE(mac_dev->port); i++) {
Expand Down Expand Up @@ -716,42 +747,12 @@ static int mac_probe(struct platform_device *_of_dev)

/* Get the rest of the PHY information */
mac_dev->phy_node = of_parse_phandle(mac_node, "phy-handle", 0);
if (!mac_dev->phy_node && of_phy_is_fixed_link(mac_node)) {
struct phy_device *phy;

err = of_phy_register_fixed_link(mac_node);
if (err)
goto _return_of_get_parent;

priv->fixed_link = kzalloc(sizeof(*priv->fixed_link),
GFP_KERNEL);
if (!priv->fixed_link) {
err = -ENOMEM;
goto _return_of_get_parent;
}

mac_dev->phy_node = of_node_get(mac_node);
phy = of_phy_find_device(mac_dev->phy_node);
if (!phy) {
err = -EINVAL;
of_node_put(mac_dev->phy_node);
goto _return_of_get_parent;
}

priv->fixed_link->link = phy->link;
priv->fixed_link->speed = phy->speed;
priv->fixed_link->duplex = phy->duplex;
priv->fixed_link->pause = phy->pause;
priv->fixed_link->asym_pause = phy->asym_pause;

put_device(&phy->mdio.dev);
}

err = init(mac_dev, mac_node);
if (err < 0) {
dev_err(dev, "mac_dev->init() = %d\n", err);
of_node_put(mac_dev->phy_node);
goto _return_of_get_parent;
goto _return_of_node_put;
}

/* pause frame autonegotiation enabled */
Expand Down Expand Up @@ -782,8 +783,6 @@ static int mac_probe(struct platform_device *_of_dev)

_return_of_node_put:
of_node_put(dev_node);
_return_of_get_parent:
kfree(priv->fixed_link);
_return:
return err;
}
Expand Down

0 comments on commit 9ea4742

Please sign in to comment.