Skip to content

Commit

Permalink
drivers: net: Add APM X-Gene SoC ethernet driver support.
Browse files Browse the repository at this point in the history
This patch adds network driver for APM X-Gene SoC ethernet.

Signed-off-by: Iyappan Subramanian <isubramanian@apm.com>
Signed-off-by: Ravi Patel <rapatel@apm.com>
Signed-off-by: Keyur Chudgar <kchudgar@apm.com>
Signed-off-by: Dean Nelson <dnelson@redhat.com>
Reviewed-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Iyappan Subramanian authored and David S. Miller committed Aug 11, 2014
1 parent 3d39042 commit e6ad767
Show file tree
Hide file tree
Showing 11 changed files with 2,299 additions and 0 deletions.
1 change: 1 addition & 0 deletions drivers/net/ethernet/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ source "drivers/net/ethernet/allwinner/Kconfig"
source "drivers/net/ethernet/alteon/Kconfig"
source "drivers/net/ethernet/altera/Kconfig"
source "drivers/net/ethernet/amd/Kconfig"
source "drivers/net/ethernet/apm/Kconfig"
source "drivers/net/ethernet/apple/Kconfig"
source "drivers/net/ethernet/arc/Kconfig"
source "drivers/net/ethernet/atheros/Kconfig"
Expand Down
1 change: 1 addition & 0 deletions drivers/net/ethernet/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ obj-$(CONFIG_NET_VENDOR_ALLWINNER) += allwinner/
obj-$(CONFIG_NET_VENDOR_ALTEON) += alteon/
obj-$(CONFIG_ALTERA_TSE) += altera/
obj-$(CONFIG_NET_VENDOR_AMD) += amd/
obj-$(CONFIG_NET_XGENE) += apm/
obj-$(CONFIG_NET_VENDOR_APPLE) += apple/
obj-$(CONFIG_NET_VENDOR_ARC) += arc/
obj-$(CONFIG_NET_VENDOR_ATHEROS) += atheros/
Expand Down
1 change: 1 addition & 0 deletions drivers/net/ethernet/apm/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source "drivers/net/ethernet/apm/xgene/Kconfig"
5 changes: 5 additions & 0 deletions drivers/net/ethernet/apm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#
# Makefile for APM X-GENE Ethernet driver.
#

obj-$(CONFIG_NET_XGENE) += xgene/
9 changes: 9 additions & 0 deletions drivers/net/ethernet/apm/xgene/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
config NET_XGENE
tristate "APM X-Gene SoC Ethernet Driver"
select PHYLIB
help
This is the Ethernet driver for the on-chip ethernet interface on the
APM X-Gene SoC.

To compile this driver as a module, choose M here. This module will
be called xgene_enet.
6 changes: 6 additions & 0 deletions drivers/net/ethernet/apm/xgene/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# Makefile for APM X-Gene Ethernet Driver.
#

xgene-enet-objs := xgene_enet_hw.o xgene_enet_main.o xgene_enet_ethtool.o
obj-$(CONFIG_NET_XGENE) += xgene-enet.o
125 changes: 125 additions & 0 deletions drivers/net/ethernet/apm/xgene/xgene_enet_ethtool.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/* Applied Micro X-Gene SoC Ethernet Driver
*
* Copyright (c) 2014, Applied Micro Circuits Corporation
* Authors: Iyappan Subramanian <isubramanian@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 <linux/ethtool.h>
#include "xgene_enet_main.h"

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

#define XGENE_STAT(m) { #m, offsetof(struct xgene_enet_pdata, stats.m) }

static const struct xgene_gstrings_stats gstrings_stats[] = {
XGENE_STAT(rx_packets),
XGENE_STAT(tx_packets),
XGENE_STAT(rx_bytes),
XGENE_STAT(tx_bytes),
XGENE_STAT(rx_errors),
XGENE_STAT(tx_errors),
XGENE_STAT(rx_length_errors),
XGENE_STAT(rx_crc_errors),
XGENE_STAT(rx_frame_errors),
XGENE_STAT(rx_fifo_errors)
};

#define XGENE_STATS_LEN ARRAY_SIZE(gstrings_stats)

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

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

static int xgene_get_settings(struct net_device *ndev, struct ethtool_cmd *cmd)
{
struct xgene_enet_pdata *pdata = netdev_priv(ndev);
struct phy_device *phydev = pdata->phy_dev;

if (phydev == NULL)
return -ENODEV;

return phy_ethtool_gset(phydev, cmd);
}

static int xgene_set_settings(struct net_device *ndev, struct ethtool_cmd *cmd)
{
struct xgene_enet_pdata *pdata = netdev_priv(ndev);
struct phy_device *phydev = pdata->phy_dev;

if (phydev == NULL)
return -ENODEV;

return phy_ethtool_sset(phydev, cmd);
}

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

if (stringset != ETH_SS_STATS)
return;

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

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

return XGENE_STATS_LEN;
}

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

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

static const struct ethtool_ops xgene_ethtool_ops = {
.get_drvinfo = xgene_get_drvinfo,
.get_settings = xgene_get_settings,
.set_settings = xgene_set_settings,
.get_link = ethtool_op_get_link,
.get_strings = xgene_get_strings,
.get_sset_count = xgene_get_sset_count,
.get_ethtool_stats = xgene_get_ethtool_stats
};

void xgene_enet_set_ethtool_ops(struct net_device *ndev)
{
ndev->ethtool_ops = &xgene_ethtool_ops;
}
Loading

0 comments on commit e6ad767

Please sign in to comment.