Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b5bacf86 authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'xgene-v2-mdio-and-ethtool'



Iyappan Subramanian says:

====================
drivers: net: xgene-v2: Add MDIO and ethtool support

This patch set,

- adds phy management and ethtool support
- fixes ethernet reset
- addresses review comments from previous patch set

v2: Address review comments from v1
	- removed mdio_lock, since there is a top level lock in mdio_bus.c

v1:
	- Initial version
====================

Signed-off-by: default avatarIyappan Subramanian <isubramanian@apm.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 9bdf64d5 1ffa8a7a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2,5 +2,5 @@
# Makefile for APM X-Gene Ethernet v2 driver
#

xgene-enet-v2-objs := main.o mac.o enet.o ring.o
xgene-enet-v2-objs := main.o mac.o enet.o ring.o mdio.o ethtool.o
obj-$(CONFIG_NET_XGENE_V2) += xgene-enet-v2.o
+18 −6
Original line number Diff line number Diff line
@@ -38,10 +38,24 @@ u32 xge_rd_csr(struct xge_pdata *pdata, u32 offset)
int xge_port_reset(struct net_device *ndev)
{
	struct xge_pdata *pdata = netdev_priv(ndev);
	struct device *dev = &pdata->pdev->dev;
	u32 data, wait = 10;

	xge_wr_csr(pdata, ENET_SRST, 0x3);
	xge_wr_csr(pdata, ENET_SRST, 0x2);
	xge_wr_csr(pdata, ENET_SRST, 0x0);
	xge_wr_csr(pdata, ENET_CLKEN, 0x3);
	xge_wr_csr(pdata, ENET_SRST, 0xf);
	xge_wr_csr(pdata, ENET_SRST, 0);
	xge_wr_csr(pdata, CFG_MEM_RAM_SHUTDOWN, 1);
	xge_wr_csr(pdata, CFG_MEM_RAM_SHUTDOWN, 0);

	do {
		usleep_range(100, 110);
		data = xge_rd_csr(pdata, BLOCK_MEM_RDY);
	} while (data != MEM_RDY && wait--);

	if (data != MEM_RDY) {
		dev_err(dev, "ECC init failed: %x\n", data);
		return -ETIMEDOUT;
	}

	xge_wr_csr(pdata, ENET_SHIM, DEVM_ARAUX_COH | DEVM_AWAUX_COH);

@@ -59,13 +73,11 @@ static void xge_traffic_resume(struct net_device *ndev)
	xge_wr_csr(pdata, RX_DV_GATE_REG, 1);
}

int xge_port_init(struct net_device *ndev)
void xge_port_init(struct net_device *ndev)
{
	struct xge_pdata *pdata = netdev_priv(ndev);

	pdata->phy_speed = SPEED_1000;
	xge_mac_init(pdata);
	xge_traffic_resume(ndev);

	return 0;
}
+2 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#define CFG_MEM_RAM_SHUTDOWN	0xd070
#define BLOCK_MEM_RDY		0xd074

#define MEM_RDY			0xffffffff
#define DEVM_ARAUX_COH		BIT(19)
#define DEVM_AWAUX_COH		BIT(3)

@@ -39,5 +40,6 @@
void xge_wr_csr(struct xge_pdata *pdata, u32 offset, u32 val);
u32 xge_rd_csr(struct xge_pdata *pdata, u32 offset);
int xge_port_reset(struct net_device *ndev);
void xge_port_init(struct net_device *ndev);

#endif  /* __XGENE_ENET_V2_ENET__H__ */
+121 −0
Original line number Diff line number Diff line
/*
 * Applied Micro X-Gene SoC Ethernet v2 Driver
 *
 * Copyright (c) 2017, Applied Micro Circuits Corporation
 * Author(s): Iyappan Subramanian <isubramanian@apm.com>
 *	      Keyur Chudgar <kchudgar@apm.com>
 *
 * This program is free software; you can redistribute  it and/or modify it
 * under  the terms of  the GNU General  Public License as published by the
 * Free Software Foundation;  either version 2 of the  License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "main.h"

struct xge_gstrings_stats {
	char name[ETH_GSTRING_LEN];
	int offset;
};

#define XGE_STAT(m)		{ #m, offsetof(struct xge_pdata, stats.m) }

static const struct xge_gstrings_stats gstrings_stats[] = {
	XGE_STAT(rx_packets),
	XGE_STAT(tx_packets),
	XGE_STAT(rx_bytes),
	XGE_STAT(tx_bytes),
	XGE_STAT(rx_errors)
};

#define XGE_STATS_LEN		ARRAY_SIZE(gstrings_stats)

static void xge_get_drvinfo(struct net_device *ndev,
			    struct ethtool_drvinfo *info)
{
	struct xge_pdata *pdata = netdev_priv(ndev);
	struct platform_device *pdev = pdata->pdev;

	strcpy(info->driver, "xgene-enet-v2");
	strcpy(info->version, XGENE_ENET_V2_VERSION);
	snprintf(info->fw_version, ETHTOOL_FWVERS_LEN, "N/A");
	sprintf(info->bus_info, "%s", pdev->name);
}

static void xge_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
{
	u8 *p = data;
	int i;

	if (stringset != ETH_SS_STATS)
		return;

	for (i = 0; i < XGE_STATS_LEN; i++) {
		memcpy(p, gstrings_stats[i].name, ETH_GSTRING_LEN);
		p += ETH_GSTRING_LEN;
	}
}

static int xge_get_sset_count(struct net_device *ndev, int sset)
{
	if (sset != ETH_SS_STATS)
		return -EINVAL;

	return XGE_STATS_LEN;
}

static void xge_get_ethtool_stats(struct net_device *ndev,
				  struct ethtool_stats *dummy,
				  u64 *data)
{
	void *pdata = netdev_priv(ndev);
	int i;

	for (i = 0; i < XGE_STATS_LEN; i++)
		*data++ = *(u64 *)(pdata + gstrings_stats[i].offset);
}

static int xge_get_link_ksettings(struct net_device *ndev,
				  struct ethtool_link_ksettings *cmd)
{
	struct phy_device *phydev = ndev->phydev;

	if (!phydev)
		return -ENODEV;

	return phy_ethtool_ksettings_get(phydev, cmd);
}

static int xge_set_link_ksettings(struct net_device *ndev,
				  const struct ethtool_link_ksettings *cmd)
{
	struct phy_device *phydev = ndev->phydev;

	if (!phydev)
		return -ENODEV;

	return phy_ethtool_ksettings_set(phydev, cmd);
}

static const struct ethtool_ops xge_ethtool_ops = {
	.get_drvinfo = xge_get_drvinfo,
	.get_link = ethtool_op_get_link,
	.get_strings = xge_get_strings,
	.get_sset_count = xge_get_sset_count,
	.get_ethtool_stats = xge_get_ethtool_stats,
	.get_link_ksettings = xge_get_link_ksettings,
	.set_link_ksettings = xge_set_link_ksettings,
};

void xge_set_ethtool_ops(struct net_device *ndev)
{
	ndev->ethtool_ops = &xge_ethtool_ops;
}
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ void xge_mac_reset(struct xge_pdata *pdata)
	xge_wr_csr(pdata, MAC_CONFIG_1, 0);
}

static void xge_mac_set_speed(struct xge_pdata *pdata)
void xge_mac_set_speed(struct xge_pdata *pdata)
{
	u32 icm0, icm2, ecm0, mc2;
	u32 intf_ctrl, rgmii;
Loading