net: ethernet: stmicro: stmmac: Add loopback interface for rockchip

Add some user interface for usage, for example at RK3399:

  - scan rgmii delayline:

    echo (speed:10 100 1000) > /sys/devices/platform/fe300000.ethernet/phy_lb_scan

  - loopback test:

    echo (speed:10 100 1000) > /sys/devices/platform/fe300000.ethernet/phy_lb
    echo (speed:10 100 1000) > /sys/devices/platform/fe300000.ethernet/mac_lb

  - set/show delayline

    cat /sys/devices/platform/fe300000.ethernet/rgmii_delayline
    echo (tx delayline) (rx delayline) > /sys/devices/platform/fe300000.ethernet/rgmii_delayline

Signed-off-by: David Wu <david.wu@rock-chips.com>
Change-Id: Ic38d7f4e12987d5ebc1d81f693f955e8105657ac
This commit is contained in:
David Wu
2020-03-18 11:30:08 +08:00
parent 57e97b7aba
commit a442177046
5 changed files with 1520 additions and 1 deletions

View File

@@ -15,7 +15,7 @@ obj-$(CONFIG_DWMAC_IPQ806X) += dwmac-ipq806x.o
obj-$(CONFIG_DWMAC_LPC18XX) += dwmac-lpc18xx.o
obj-$(CONFIG_DWMAC_MESON) += dwmac-meson.o dwmac-meson8b.o
obj-$(CONFIG_DWMAC_OXNAS) += dwmac-oxnas.o
obj-$(CONFIG_DWMAC_ROCKCHIP) += dwmac-rk.o
obj-$(CONFIG_DWMAC_ROCKCHIP) += dwmac-rk.o dwmac-rk-tool.o
obj-$(CONFIG_DWMAC_SOCFPGA) += dwmac-altr-socfpga.o
obj-$(CONFIG_DWMAC_STI) += dwmac-sti.o
obj-$(CONFIG_DWMAC_STM32) += dwmac-stm32.o

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,25 @@
/* SPDX-License-Identifier: (GPL-2.0+ OR MIT) */
/*
* Copyright (c) 2020 Fuzhou Rockchip Electronics Co., Ltd
*/
#ifndef __DWMAC_RK_TOOL_H__
#define __DWMAC_RK_TOOL_H__
#include <linux/phy.h>
#include "stmmac.h"
void dwmac_rk_set_rgmii_delayline(struct stmmac_priv *priv, int tx_delay, int rx_delay);
void dwmac_rk_get_rgmii_delayline(struct stmmac_priv *priv, int *tx_delay, int *rx_delay);
int dwmac_rk_get_phy_interface(struct stmmac_priv *priv);
int dwmac_rk_create_loopback_sysfs(struct device *dev);
int dwmac_rk_remove_loopback_sysfs(struct device *device);
#ifdef CONFIG_DWMAC_RK_AUTO_DELAYLINE
int dwmac_rk_get_rgmii_delayline_from_vendor(struct stmmac_priv *priv);
int dwmac_rk_search_rgmii_delayline(struct stmmac_priv *priv);
#endif
#endif /* __DWMAC_RK_TOOL_H__ */

View File

@@ -33,6 +33,7 @@
#include <linux/pm_runtime.h>
#include <linux/soc/rockchip/rk_vendor_storage.h>
#include "stmmac_platform.h"
#include "dwmac-rk-tool.h"
struct rk_priv_data;
struct rk_gmac_ops {
@@ -1569,6 +1570,40 @@ static void rk_fix_speed(void *priv, unsigned int speed)
}
}
void dwmac_rk_set_rgmii_delayline(struct stmmac_priv *priv,
int tx_delay, int rx_delay)
{
struct rk_priv_data *bsp_priv = priv->plat->bsp_priv;
if (bsp_priv->ops->set_to_rgmii) {
bsp_priv->ops->set_to_rgmii(bsp_priv, tx_delay, rx_delay);
bsp_priv->tx_delay = tx_delay;
bsp_priv->rx_delay = rx_delay;
}
}
EXPORT_SYMBOL(dwmac_rk_set_rgmii_delayline);
void dwmac_rk_get_rgmii_delayline(struct stmmac_priv *priv,
int *tx_delay, int *rx_delay)
{
struct rk_priv_data *bsp_priv = priv->plat->bsp_priv;
if (!bsp_priv->ops->set_to_rgmii)
return;
*tx_delay = bsp_priv->tx_delay;
*rx_delay = bsp_priv->rx_delay;
}
EXPORT_SYMBOL(dwmac_rk_get_rgmii_delayline);
int dwmac_rk_get_phy_interface(struct stmmac_priv *priv)
{
struct rk_priv_data *bsp_priv = priv->plat->bsp_priv;
return bsp_priv->phy_iface;
}
EXPORT_SYMBOL(dwmac_rk_get_phy_interface);
void __weak rk_devinfo_get_eth_mac(u8 *mac)
{
}

View File

@@ -48,6 +48,7 @@
#include <net/pkt_cls.h>
#include "stmmac_ptp.h"
#include "stmmac.h"
#include "dwmac-rk-tool.h"
#include <linux/reset.h>
#include <linux/of_mdio.h>
#include "dwmac1000.h"
@@ -4446,6 +4447,14 @@ int stmmac_dvr_probe(struct device *device,
__func__);
#endif
ret = dwmac_rk_create_loopback_sysfs(device);
if (ret) {
netdev_err(priv->dev, "%s: ERROR %i create loopback sysfs\n",
__func__, ret);
unregister_netdev(ndev);
goto error_netdev_register;
}
return ret;
error_netdev_register: