Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | /* 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 (pdata->phy_mode == PHY_INTERFACE_MODE_RGMII) { if (phydev == NULL) return -ENODEV; return phy_ethtool_gset(phydev, cmd); } else if (pdata->phy_mode == PHY_INTERFACE_MODE_SGMII) { cmd->supported = SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_MII; cmd->advertising = cmd->supported; ethtool_cmd_speed_set(cmd, SPEED_1000); cmd->duplex = DUPLEX_FULL; cmd->port = PORT_MII; cmd->transceiver = XCVR_INTERNAL; cmd->autoneg = AUTONEG_ENABLE; } else { cmd->supported = SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE; cmd->advertising = cmd->supported; ethtool_cmd_speed_set(cmd, SPEED_10000); cmd->duplex = DUPLEX_FULL; cmd->port = PORT_FIBRE; cmd->transceiver = XCVR_INTERNAL; cmd->autoneg = AUTONEG_DISABLE; } return 0; } 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 (pdata->phy_mode == PHY_INTERFACE_MODE_RGMII) { if (phydev == NULL) return -ENODEV; return phy_ethtool_sset(phydev, cmd); } return -EINVAL; } 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; } |