2022-08-18 12:16:26 -04:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-or-later
|
|
|
|
/*
|
|
|
|
* Copyright 2008 - 2015 Freescale Semiconductor Inc.
|
2015-12-21 02:21:30 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/of_address.h>
|
|
|
|
#include <linux/of_platform.h>
|
|
|
|
#include <linux/of_net.h>
|
|
|
|
#include <linux/of_mdio.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/phy.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/phy_fixed.h>
|
net: dpaa: Convert to phylink
This converts DPAA to phylink. All macs are converted. This should work
with no device tree modifications (including those made in this series),
except for QSGMII (as noted previously).
The mEMAC configuration is one of the tricker areas. I have tried to
capture all the restrictions across the various models. Most of the time,
we assume that if the serdes supports a mode or the phy-interface-mode
specifies it, then we support it. The only place we can't do this is
(RG)MII, since there's no serdes. In that case, we rely on a (new)
devicetree property. There are also several cases where half-duplex is
broken. Unfortunately, only a single compatible is used for the MAC, so we
have to use the board compatible instead.
The 10GEC conversion is very straightforward, since it only supports XAUI.
There is generally nothing to configure.
The dTSEC conversion is broadly similar to mEMAC, but is simpler because we
don't support configuring the SerDes (though this can be easily added) and
we don't have multiple PCSs. From what I can tell, there's nothing
different in the driver or documentation between SGMII and 1000BASE-X
except for the advertising. Similarly, I couldn't find anything about
2500BASE-X. In both cases, I treat them like SGMII. These modes aren't used
by any in-tree boards. Similarly, despite being mentioned in the driver, I
couldn't find any documented SoCs which supported QSGMII. I have left it
unimplemented for now.
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-10-17 16:22:38 -04:00
|
|
|
#include <linux/phylink.h>
|
2015-12-21 02:21:30 +02:00
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/libfdt_env.h>
|
2023-07-26 19:49:39 -06:00
|
|
|
#include <linux/platform_device.h>
|
2015-12-21 02:21:30 +02:00
|
|
|
|
|
|
|
#include "mac.h"
|
|
|
|
#include "fman_mac.h"
|
|
|
|
#include "fman_dtsec.h"
|
|
|
|
#include "fman_tgec.h"
|
|
|
|
#include "fman_memac.h"
|
|
|
|
|
|
|
|
MODULE_LICENSE("Dual BSD/GPL");
|
|
|
|
MODULE_DESCRIPTION("FSL FMan MAC API based driver");
|
|
|
|
|
|
|
|
struct mac_priv_s {
|
|
|
|
u8 cell_index;
|
|
|
|
struct fman *fman;
|
|
|
|
/* List of multicast addresses */
|
|
|
|
struct list_head mc_addr_list;
|
|
|
|
struct platform_device *eth_dev;
|
|
|
|
u16 speed;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mac_address {
|
|
|
|
u8 addr[ETH_ALEN];
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
2022-09-02 17:57:30 -04:00
|
|
|
static void mac_exception(struct mac_device *mac_dev,
|
|
|
|
enum fman_mac_exceptions ex)
|
2015-12-21 02:21:30 +02:00
|
|
|
{
|
|
|
|
if (ex == FM_MAC_EX_10G_RX_FIFO_OVFL) {
|
|
|
|
/* don't flag RX FIFO after the first */
|
|
|
|
mac_dev->set_exception(mac_dev->fman_mac,
|
|
|
|
FM_MAC_EX_10G_RX_FIFO_OVFL, false);
|
2022-08-18 12:16:32 -04:00
|
|
|
dev_err(mac_dev->dev, "10G MAC got RX FIFO Error = %x\n", ex);
|
2015-12-21 02:21:30 +02:00
|
|
|
}
|
|
|
|
|
2022-08-18 12:16:32 -04:00
|
|
|
dev_dbg(mac_dev->dev, "%s:%s() -> %d\n", KBUILD_BASENAME ".c",
|
2015-12-21 02:21:30 +02:00
|
|
|
__func__, ex);
|
|
|
|
}
|
|
|
|
|
2022-08-18 12:16:34 -04:00
|
|
|
int fman_set_multi(struct net_device *net_dev, struct mac_device *mac_dev)
|
2015-12-21 02:21:30 +02:00
|
|
|
{
|
|
|
|
struct mac_priv_s *priv;
|
|
|
|
struct mac_address *old_addr, *tmp;
|
|
|
|
struct netdev_hw_addr *ha;
|
|
|
|
int err;
|
|
|
|
enet_addr_t *addr;
|
|
|
|
|
|
|
|
priv = mac_dev->priv;
|
|
|
|
|
|
|
|
/* Clear previous address list */
|
|
|
|
list_for_each_entry_safe(old_addr, tmp, &priv->mc_addr_list, list) {
|
|
|
|
addr = (enet_addr_t *)old_addr->addr;
|
|
|
|
err = mac_dev->remove_hash_mac_addr(mac_dev->fman_mac, addr);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
list_del(&old_addr->list);
|
|
|
|
kfree(old_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add all the addresses from the new list */
|
|
|
|
netdev_for_each_mc_addr(ha, net_dev) {
|
|
|
|
addr = (enet_addr_t *)ha->addr;
|
|
|
|
err = mac_dev->add_hash_mac_addr(mac_dev->fman_mac, addr);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
tmp = kmalloc(sizeof(*tmp), GFP_ATOMIC);
|
|
|
|
if (!tmp)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ether_addr_copy(tmp->addr, ha->addr);
|
|
|
|
list_add(&tmp->list, &priv->mc_addr_list);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEFINE_MUTEX(eth_lock);
|
|
|
|
|
|
|
|
static struct platform_device *dpaa_eth_add_device(int fman_id,
|
2017-10-16 21:36:07 +03:00
|
|
|
struct mac_device *mac_dev)
|
2015-12-21 02:21:30 +02:00
|
|
|
{
|
|
|
|
struct platform_device *pdev;
|
|
|
|
struct dpaa_eth_data data;
|
|
|
|
struct mac_priv_s *priv;
|
|
|
|
static int dpaa_eth_dev_cnt;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
priv = mac_dev->priv;
|
|
|
|
|
|
|
|
data.mac_dev = mac_dev;
|
|
|
|
data.mac_hw_id = priv->cell_index;
|
|
|
|
data.fman_hw_id = fman_id;
|
|
|
|
|
|
|
|
mutex_lock(ð_lock);
|
|
|
|
pdev = platform_device_alloc("dpaa-ethernet", dpaa_eth_dev_cnt);
|
|
|
|
if (!pdev) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto no_mem;
|
|
|
|
}
|
|
|
|
|
2022-08-18 12:16:32 -04:00
|
|
|
pdev->dev.parent = mac_dev->dev;
|
2017-06-19 18:04:16 +03:00
|
|
|
|
2015-12-21 02:21:30 +02:00
|
|
|
ret = platform_device_add_data(pdev, &data, sizeof(data));
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
ret = platform_device_add(pdev);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
dpaa_eth_dev_cnt++;
|
|
|
|
mutex_unlock(ð_lock);
|
|
|
|
|
|
|
|
return pdev;
|
|
|
|
|
|
|
|
err:
|
|
|
|
platform_device_put(pdev);
|
|
|
|
no_mem:
|
|
|
|
mutex_unlock(ð_lock);
|
|
|
|
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct of_device_id mac_match[] = {
|
net: dpaa: Convert to phylink
This converts DPAA to phylink. All macs are converted. This should work
with no device tree modifications (including those made in this series),
except for QSGMII (as noted previously).
The mEMAC configuration is one of the tricker areas. I have tried to
capture all the restrictions across the various models. Most of the time,
we assume that if the serdes supports a mode or the phy-interface-mode
specifies it, then we support it. The only place we can't do this is
(RG)MII, since there's no serdes. In that case, we rely on a (new)
devicetree property. There are also several cases where half-duplex is
broken. Unfortunately, only a single compatible is used for the MAC, so we
have to use the board compatible instead.
The 10GEC conversion is very straightforward, since it only supports XAUI.
There is generally nothing to configure.
The dTSEC conversion is broadly similar to mEMAC, but is simpler because we
don't support configuring the SerDes (though this can be easily added) and
we don't have multiple PCSs. From what I can tell, there's nothing
different in the driver or documentation between SGMII and 1000BASE-X
except for the advertising. Similarly, I couldn't find anything about
2500BASE-X. In both cases, I treat them like SGMII. These modes aren't used
by any in-tree boards. Similarly, despite being mentioned in the driver, I
couldn't find any documented SoCs which supported QSGMII. I have left it
unimplemented for now.
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-10-17 16:22:38 -04:00
|
|
|
{ .compatible = "fsl,fman-dtsec", .data = dtsec_initialization },
|
|
|
|
{ .compatible = "fsl,fman-xgec", .data = tgec_initialization },
|
2022-08-18 12:16:31 -04:00
|
|
|
{ .compatible = "fsl,fman-memac", .data = memac_initialization },
|
2015-12-21 02:21:30 +02:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, mac_match);
|
|
|
|
|
|
|
|
static int mac_probe(struct platform_device *_of_dev)
|
|
|
|
{
|
2016-05-16 16:57:14 +03:00
|
|
|
int err, i, nph;
|
2022-09-02 17:57:28 -04:00
|
|
|
int (*init)(struct mac_device *mac_dev, struct device_node *mac_node,
|
|
|
|
struct fman_mac_params *params);
|
2015-12-21 02:21:30 +02:00
|
|
|
struct device *dev;
|
|
|
|
struct device_node *mac_node, *dev_node;
|
|
|
|
struct mac_device *mac_dev;
|
|
|
|
struct platform_device *of_dev;
|
|
|
|
struct mac_priv_s *priv;
|
2022-09-02 17:57:28 -04:00
|
|
|
struct fman_mac_params params;
|
2016-05-16 16:57:14 +03:00
|
|
|
u32 val;
|
2015-12-21 02:21:30 +02:00
|
|
|
u8 fman_id;
|
net: of_get_phy_mode: Change API to solve int/unit warnings
Before this change of_get_phy_mode() returned an enum,
phy_interface_t. On error, -ENODEV etc, is returned. If the result of
the function is stored in a variable of type phy_interface_t, and the
compiler has decided to represent this as an unsigned int, comparision
with -ENODEV etc, is a signed vs unsigned comparision.
Fix this problem by changing the API. Make the function return an
error, or 0 on success, and pass a pointer, of type phy_interface_t,
where the phy mode should be stored.
v2:
Return with *interface set to PHY_INTERFACE_MODE_NA on error.
Add error checks to all users of of_get_phy_mode()
Fixup a few reverse christmas tree errors
Fixup a few slightly malformed reverse christmas trees
v3:
Fix 0-day reported errors.
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-11-04 02:40:33 +01:00
|
|
|
phy_interface_t phy_if;
|
2015-12-21 02:21:30 +02:00
|
|
|
|
|
|
|
dev = &_of_dev->dev;
|
|
|
|
mac_node = dev->of_node;
|
2022-08-18 12:16:31 -04:00
|
|
|
init = of_device_get_match_data(dev);
|
2015-12-21 02:21:30 +02:00
|
|
|
|
|
|
|
mac_dev = devm_kzalloc(dev, sizeof(*mac_dev), GFP_KERNEL);
|
2022-09-02 17:57:31 -04:00
|
|
|
if (!mac_dev)
|
|
|
|
return -ENOMEM;
|
2015-12-21 02:21:30 +02:00
|
|
|
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
|
2022-09-02 17:57:31 -04:00
|
|
|
if (!priv)
|
|
|
|
return -ENOMEM;
|
net: dpaa: Convert to phylink
This converts DPAA to phylink. All macs are converted. This should work
with no device tree modifications (including those made in this series),
except for QSGMII (as noted previously).
The mEMAC configuration is one of the tricker areas. I have tried to
capture all the restrictions across the various models. Most of the time,
we assume that if the serdes supports a mode or the phy-interface-mode
specifies it, then we support it. The only place we can't do this is
(RG)MII, since there's no serdes. In that case, we rely on a (new)
devicetree property. There are also several cases where half-duplex is
broken. Unfortunately, only a single compatible is used for the MAC, so we
have to use the board compatible instead.
The 10GEC conversion is very straightforward, since it only supports XAUI.
There is generally nothing to configure.
The dTSEC conversion is broadly similar to mEMAC, but is simpler because we
don't support configuring the SerDes (though this can be easily added) and
we don't have multiple PCSs. From what I can tell, there's nothing
different in the driver or documentation between SGMII and 1000BASE-X
except for the advertising. Similarly, I couldn't find anything about
2500BASE-X. In both cases, I treat them like SGMII. These modes aren't used
by any in-tree boards. Similarly, despite being mentioned in the driver, I
couldn't find any documented SoCs which supported QSGMII. I have left it
unimplemented for now.
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-10-17 16:22:38 -04:00
|
|
|
platform_set_drvdata(_of_dev, mac_dev);
|
2015-12-21 02:21:30 +02:00
|
|
|
|
|
|
|
/* Save private information */
|
|
|
|
mac_dev->priv = priv;
|
2022-08-18 12:16:32 -04:00
|
|
|
mac_dev->dev = dev;
|
2015-12-21 02:21:30 +02:00
|
|
|
|
|
|
|
INIT_LIST_HEAD(&priv->mc_addr_list);
|
|
|
|
|
|
|
|
/* Get the FM node */
|
|
|
|
dev_node = of_get_parent(mac_node);
|
|
|
|
if (!dev_node) {
|
2017-07-18 16:43:19 -05:00
|
|
|
dev_err(dev, "of_get_parent(%pOF) failed\n",
|
|
|
|
mac_node);
|
2022-09-02 17:57:31 -04:00
|
|
|
return -EINVAL;
|
2015-12-21 02:21:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
of_dev = of_find_device_by_node(dev_node);
|
|
|
|
if (!of_dev) {
|
2017-07-18 16:43:19 -05:00
|
|
|
dev_err(dev, "of_find_device_by_node(%pOF) failed\n", dev_node);
|
2015-12-21 02:21:30 +02:00
|
|
|
err = -EINVAL;
|
|
|
|
goto _return_of_node_put;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the FMan cell-index */
|
2016-05-16 16:57:14 +03:00
|
|
|
err = of_property_read_u32(dev_node, "cell-index", &val);
|
|
|
|
if (err) {
|
2017-07-18 16:43:19 -05:00
|
|
|
dev_err(dev, "failed to read cell-index for %pOF\n", dev_node);
|
2015-12-21 02:21:30 +02:00
|
|
|
err = -EINVAL;
|
|
|
|
goto _return_of_node_put;
|
|
|
|
}
|
|
|
|
/* cell-index 0 => FMan id 1 */
|
2016-05-16 16:57:14 +03:00
|
|
|
fman_id = (u8)(val + 1);
|
2015-12-21 02:21:30 +02:00
|
|
|
|
|
|
|
priv->fman = fman_bind(&of_dev->dev);
|
|
|
|
if (!priv->fman) {
|
2017-07-18 16:43:19 -05:00
|
|
|
dev_err(dev, "fman_bind(%pOF) failed\n", dev_node);
|
2015-12-21 02:21:30 +02:00
|
|
|
err = -ENODEV;
|
|
|
|
goto _return_of_node_put;
|
|
|
|
}
|
|
|
|
|
|
|
|
of_node_put(dev_node);
|
|
|
|
|
|
|
|
/* Get the address of the memory mapped registers */
|
2022-10-20 11:50:41 -04:00
|
|
|
mac_dev->res = platform_get_mem_or_io(_of_dev, 0);
|
|
|
|
if (!mac_dev->res) {
|
2022-09-02 17:57:27 -04:00
|
|
|
dev_err(dev, "could not get registers\n");
|
|
|
|
return -EINVAL;
|
2015-12-21 02:21:30 +02:00
|
|
|
}
|
|
|
|
|
2022-10-20 11:50:41 -04:00
|
|
|
err = devm_request_resource(dev, fman_get_mem_region(priv->fman),
|
|
|
|
mac_dev->res);
|
2022-09-02 17:57:27 -04:00
|
|
|
if (err) {
|
|
|
|
dev_err_probe(dev, err, "could not request resource\n");
|
2022-09-02 17:57:31 -04:00
|
|
|
return err;
|
2015-12-21 02:21:30 +02:00
|
|
|
}
|
|
|
|
|
2022-10-20 11:50:41 -04:00
|
|
|
mac_dev->vaddr = devm_ioremap(dev, mac_dev->res->start,
|
|
|
|
resource_size(mac_dev->res));
|
2022-09-02 17:57:27 -04:00
|
|
|
if (!mac_dev->vaddr) {
|
2015-12-21 02:21:30 +02:00
|
|
|
dev_err(dev, "devm_ioremap() failed\n");
|
2022-09-02 17:57:31 -04:00
|
|
|
return -EIO;
|
2015-12-21 02:21:30 +02:00
|
|
|
}
|
|
|
|
|
2022-09-02 17:57:31 -04:00
|
|
|
if (!of_device_is_available(mac_node))
|
|
|
|
return -ENODEV;
|
2015-12-21 02:21:30 +02:00
|
|
|
|
|
|
|
/* Get the cell-index */
|
2016-05-16 16:57:14 +03:00
|
|
|
err = of_property_read_u32(mac_node, "cell-index", &val);
|
|
|
|
if (err) {
|
2017-07-18 16:43:19 -05:00
|
|
|
dev_err(dev, "failed to read cell-index for %pOF\n", mac_node);
|
2022-09-02 17:57:31 -04:00
|
|
|
return -EINVAL;
|
2015-12-21 02:21:30 +02:00
|
|
|
}
|
2016-05-16 16:57:14 +03:00
|
|
|
priv->cell_index = (u8)val;
|
2015-12-21 02:21:30 +02:00
|
|
|
|
|
|
|
/* Get the MAC address */
|
of: net: pass the dst buffer to of_get_mac_address()
of_get_mac_address() returns a "const void*" pointer to a MAC address.
Lately, support to fetch the MAC address by an NVMEM provider was added.
But this will only work with platform devices. It will not work with
PCI devices (e.g. of an integrated root complex) and esp. not with DSA
ports.
There is an of_* variant of the nvmem binding which works without
devices. The returned data of a nvmem_cell_read() has to be freed after
use. On the other hand the return of_get_mac_address() points to some
static data without a lifetime. The trick for now, was to allocate a
device resource managed buffer which is then returned. This will only
work if we have an actual device.
Change it, so that the caller of of_get_mac_address() has to supply a
buffer where the MAC address is written to. Unfortunately, this will
touch all drivers which use the of_get_mac_address().
Usually the code looks like:
const char *addr;
addr = of_get_mac_address(np);
if (!IS_ERR(addr))
ether_addr_copy(ndev->dev_addr, addr);
This can then be simply rewritten as:
of_get_mac_address(np, ndev->dev_addr);
Sometimes is_valid_ether_addr() is used to test the MAC address.
of_get_mac_address() already makes sure, it just returns a valid MAC
address. Thus we can just test its return code. But we have to be
careful if there are still other sources for the MAC address before the
of_get_mac_address(). In this case we have to keep the
is_valid_ether_addr() call.
The following coccinelle patch was used to convert common cases to the
new style. Afterwards, I've manually gone over the drivers and fixed the
return code variable: either used a new one or if one was already
available use that. Mansour Moufid, thanks for that coccinelle patch!
<spml>
@a@
identifier x;
expression y, z;
@@
- x = of_get_mac_address(y);
+ x = of_get_mac_address(y, z);
<...
- ether_addr_copy(z, x);
...>
@@
identifier a.x;
@@
- if (<+... x ...+>) {}
@@
identifier a.x;
@@
if (<+... x ...+>) {
...
}
- else {}
@@
identifier a.x;
expression e;
@@
- if (<+... x ...+>@e)
- {}
- else
+ if (!(e))
{...}
@@
expression x, y, z;
@@
- x = of_get_mac_address(y, z);
+ of_get_mac_address(y, z);
... when != x
</spml>
All drivers, except drivers/net/ethernet/aeroflex/greth.c, were
compile-time tested.
Suggested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-04-12 19:47:17 +02:00
|
|
|
err = of_get_mac_address(mac_node, mac_dev->addr);
|
|
|
|
if (err)
|
2020-03-05 19:08:57 +02:00
|
|
|
dev_warn(dev, "of_get_mac_address(%pOF) failed\n", mac_node);
|
2015-12-21 02:21:30 +02:00
|
|
|
|
|
|
|
/* Get the port handles */
|
|
|
|
nph = of_count_phandle_with_args(mac_node, "fsl,fman-ports", NULL);
|
|
|
|
if (unlikely(nph < 0)) {
|
2017-07-18 16:43:19 -05:00
|
|
|
dev_err(dev, "of_count_phandle_with_args(%pOF, fsl,fman-ports) failed\n",
|
|
|
|
mac_node);
|
2022-09-02 17:57:31 -04:00
|
|
|
return nph;
|
2015-12-21 02:21:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nph != ARRAY_SIZE(mac_dev->port)) {
|
2017-07-18 16:43:19 -05:00
|
|
|
dev_err(dev, "Not supported number of fman-ports handles of mac node %pOF from device tree\n",
|
|
|
|
mac_node);
|
2022-09-02 17:57:31 -04:00
|
|
|
return -EINVAL;
|
2015-12-21 02:21:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(mac_dev->port); i++) {
|
|
|
|
/* Find the port node */
|
|
|
|
dev_node = of_parse_phandle(mac_node, "fsl,fman-ports", i);
|
|
|
|
if (!dev_node) {
|
2017-07-18 16:43:19 -05:00
|
|
|
dev_err(dev, "of_parse_phandle(%pOF, fsl,fman-ports) failed\n",
|
|
|
|
mac_node);
|
2022-09-02 17:57:31 -04:00
|
|
|
return -EINVAL;
|
2015-12-21 02:21:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
of_dev = of_find_device_by_node(dev_node);
|
|
|
|
if (!of_dev) {
|
2017-07-18 16:43:19 -05:00
|
|
|
dev_err(dev, "of_find_device_by_node(%pOF) failed\n",
|
|
|
|
dev_node);
|
2015-12-21 02:21:30 +02:00
|
|
|
err = -EINVAL;
|
|
|
|
goto _return_of_node_put;
|
|
|
|
}
|
|
|
|
|
|
|
|
mac_dev->port[i] = fman_port_bind(&of_dev->dev);
|
|
|
|
if (!mac_dev->port[i]) {
|
2017-07-18 16:43:19 -05:00
|
|
|
dev_err(dev, "dev_get_drvdata(%pOF) failed\n",
|
|
|
|
dev_node);
|
2015-12-21 02:21:30 +02:00
|
|
|
err = -EINVAL;
|
|
|
|
goto _return_of_node_put;
|
|
|
|
}
|
|
|
|
of_node_put(dev_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the PHY connection type */
|
net: of_get_phy_mode: Change API to solve int/unit warnings
Before this change of_get_phy_mode() returned an enum,
phy_interface_t. On error, -ENODEV etc, is returned. If the result of
the function is stored in a variable of type phy_interface_t, and the
compiler has decided to represent this as an unsigned int, comparision
with -ENODEV etc, is a signed vs unsigned comparision.
Fix this problem by changing the API. Make the function return an
error, or 0 on success, and pass a pointer, of type phy_interface_t,
where the phy mode should be stored.
v2:
Return with *interface set to PHY_INTERFACE_MODE_NA on error.
Add error checks to all users of of_get_phy_mode()
Fixup a few reverse christmas tree errors
Fixup a few slightly malformed reverse christmas trees
v3:
Fix 0-day reported errors.
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-11-04 02:40:33 +01:00
|
|
|
err = of_get_phy_mode(mac_node, &phy_if);
|
|
|
|
if (err) {
|
2015-12-21 02:21:30 +02:00
|
|
|
dev_warn(dev,
|
2017-07-18 16:43:19 -05:00
|
|
|
"of_get_phy_mode() for %pOF failed. Defaulting to SGMII\n",
|
|
|
|
mac_node);
|
2016-06-30 16:48:05 +03:00
|
|
|
phy_if = PHY_INTERFACE_MODE_SGMII;
|
2015-12-21 02:21:30 +02:00
|
|
|
}
|
2017-10-16 21:36:06 +03:00
|
|
|
mac_dev->phy_if = phy_if;
|
2015-12-21 02:21:30 +02:00
|
|
|
|
2022-09-02 17:57:28 -04:00
|
|
|
params.mac_id = priv->cell_index;
|
|
|
|
params.fm = (void *)priv->fman;
|
|
|
|
params.exception_cb = mac_exception;
|
|
|
|
params.event_cb = mac_exception;
|
|
|
|
|
|
|
|
err = init(mac_dev, mac_node, ¶ms);
|
2015-12-21 02:21:30 +02:00
|
|
|
if (err < 0)
|
net: dpaa: Convert to phylink
This converts DPAA to phylink. All macs are converted. This should work
with no device tree modifications (including those made in this series),
except for QSGMII (as noted previously).
The mEMAC configuration is one of the tricker areas. I have tried to
capture all the restrictions across the various models. Most of the time,
we assume that if the serdes supports a mode or the phy-interface-mode
specifies it, then we support it. The only place we can't do this is
(RG)MII, since there's no serdes. In that case, we rely on a (new)
devicetree property. There are also several cases where half-duplex is
broken. Unfortunately, only a single compatible is used for the MAC, so we
have to use the board compatible instead.
The 10GEC conversion is very straightforward, since it only supports XAUI.
There is generally nothing to configure.
The dTSEC conversion is broadly similar to mEMAC, but is simpler because we
don't support configuring the SerDes (though this can be easily added) and
we don't have multiple PCSs. From what I can tell, there's nothing
different in the driver or documentation between SGMII and 1000BASE-X
except for the advertising. Similarly, I couldn't find anything about
2500BASE-X. In both cases, I treat them like SGMII. These modes aren't used
by any in-tree boards. Similarly, despite being mentioned in the driver, I
couldn't find any documented SoCs which supported QSGMII. I have left it
unimplemented for now.
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-10-17 16:22:38 -04:00
|
|
|
return err;
|
2015-12-21 02:21:30 +02:00
|
|
|
|
of: net: pass the dst buffer to of_get_mac_address()
of_get_mac_address() returns a "const void*" pointer to a MAC address.
Lately, support to fetch the MAC address by an NVMEM provider was added.
But this will only work with platform devices. It will not work with
PCI devices (e.g. of an integrated root complex) and esp. not with DSA
ports.
There is an of_* variant of the nvmem binding which works without
devices. The returned data of a nvmem_cell_read() has to be freed after
use. On the other hand the return of_get_mac_address() points to some
static data without a lifetime. The trick for now, was to allocate a
device resource managed buffer which is then returned. This will only
work if we have an actual device.
Change it, so that the caller of of_get_mac_address() has to supply a
buffer where the MAC address is written to. Unfortunately, this will
touch all drivers which use the of_get_mac_address().
Usually the code looks like:
const char *addr;
addr = of_get_mac_address(np);
if (!IS_ERR(addr))
ether_addr_copy(ndev->dev_addr, addr);
This can then be simply rewritten as:
of_get_mac_address(np, ndev->dev_addr);
Sometimes is_valid_ether_addr() is used to test the MAC address.
of_get_mac_address() already makes sure, it just returns a valid MAC
address. Thus we can just test its return code. But we have to be
careful if there are still other sources for the MAC address before the
of_get_mac_address(). In this case we have to keep the
is_valid_ether_addr() call.
The following coccinelle patch was used to convert common cases to the
new style. Afterwards, I've manually gone over the drivers and fixed the
return code variable: either used a new one or if one was already
available use that. Mansour Moufid, thanks for that coccinelle patch!
<spml>
@a@
identifier x;
expression y, z;
@@
- x = of_get_mac_address(y);
+ x = of_get_mac_address(y, z);
<...
- ether_addr_copy(z, x);
...>
@@
identifier a.x;
@@
- if (<+... x ...+>) {}
@@
identifier a.x;
@@
if (<+... x ...+>) {
...
}
- else {}
@@
identifier a.x;
expression e;
@@
- if (<+... x ...+>@e)
- {}
- else
+ if (!(e))
{...}
@@
expression x, y, z;
@@
- x = of_get_mac_address(y, z);
+ of_get_mac_address(y, z);
... when != x
</spml>
All drivers, except drivers/net/ethernet/aeroflex/greth.c, were
compile-time tested.
Suggested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-04-12 19:47:17 +02:00
|
|
|
if (!is_zero_ether_addr(mac_dev->addr))
|
2020-03-05 19:08:57 +02:00
|
|
|
dev_info(dev, "FMan MAC address: %pM\n", mac_dev->addr);
|
2015-12-21 02:21:30 +02:00
|
|
|
|
2017-10-16 21:36:07 +03:00
|
|
|
priv->eth_dev = dpaa_eth_add_device(fman_id, mac_dev);
|
2015-12-21 02:21:30 +02:00
|
|
|
if (IS_ERR(priv->eth_dev)) {
|
net: dpaa: Convert to phylink
This converts DPAA to phylink. All macs are converted. This should work
with no device tree modifications (including those made in this series),
except for QSGMII (as noted previously).
The mEMAC configuration is one of the tricker areas. I have tried to
capture all the restrictions across the various models. Most of the time,
we assume that if the serdes supports a mode or the phy-interface-mode
specifies it, then we support it. The only place we can't do this is
(RG)MII, since there's no serdes. In that case, we rely on a (new)
devicetree property. There are also several cases where half-duplex is
broken. Unfortunately, only a single compatible is used for the MAC, so we
have to use the board compatible instead.
The 10GEC conversion is very straightforward, since it only supports XAUI.
There is generally nothing to configure.
The dTSEC conversion is broadly similar to mEMAC, but is simpler because we
don't support configuring the SerDes (though this can be easily added) and
we don't have multiple PCSs. From what I can tell, there's nothing
different in the driver or documentation between SGMII and 1000BASE-X
except for the advertising. Similarly, I couldn't find anything about
2500BASE-X. In both cases, I treat them like SGMII. These modes aren't used
by any in-tree boards. Similarly, despite being mentioned in the driver, I
couldn't find any documented SoCs which supported QSGMII. I have left it
unimplemented for now.
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-10-17 16:22:38 -04:00
|
|
|
err = PTR_ERR(priv->eth_dev);
|
2015-12-21 02:21:30 +02:00
|
|
|
dev_err(dev, "failed to add Ethernet platform device for MAC %d\n",
|
|
|
|
priv->cell_index);
|
|
|
|
priv->eth_dev = NULL;
|
|
|
|
}
|
|
|
|
|
2022-09-02 17:57:31 -04:00
|
|
|
return err;
|
2015-12-21 02:21:30 +02:00
|
|
|
|
|
|
|
_return_of_node_put:
|
|
|
|
of_node_put(dev_node);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2023-07-10 09:19:42 +02:00
|
|
|
static void mac_remove(struct platform_device *pdev)
|
2022-11-03 14:28:30 -04:00
|
|
|
{
|
|
|
|
struct mac_device *mac_dev = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
platform_device_unregister(mac_dev->priv->eth_dev);
|
|
|
|
}
|
|
|
|
|
2015-12-21 02:21:30 +02:00
|
|
|
static struct platform_driver mac_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = KBUILD_MODNAME,
|
|
|
|
.of_match_table = mac_match,
|
|
|
|
},
|
|
|
|
.probe = mac_probe,
|
2023-07-10 09:19:42 +02:00
|
|
|
.remove_new = mac_remove,
|
2015-12-21 02:21:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
builtin_platform_driver(mac_driver);
|