Linux 4.16.11
[linux/fpc-iii.git] / drivers / net / ethernet / toshiba / spider_net_ethtool.c
blob16bd036d06820e9139d04f05355a5a4e5127509c
1 /*
2 * Network device driver for Cell Processor-Based Blade
4 * (C) Copyright IBM Corp. 2005
6 * Authors : Utz Bacher <utz.bacher@de.ibm.com>
7 * Jens Osterkamp <Jens.Osterkamp@de.ibm.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
12 * any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <linux/netdevice.h>
25 #include <linux/ethtool.h>
26 #include <linux/pci.h>
28 #include "spider_net.h"
31 static struct {
32 const char str[ETH_GSTRING_LEN];
33 } ethtool_stats_keys[] = {
34 { "tx_packets" },
35 { "tx_bytes" },
36 { "rx_packets" },
37 { "rx_bytes" },
38 { "tx_errors" },
39 { "tx_dropped" },
40 { "rx_dropped" },
41 { "rx_descriptor_error" },
42 { "tx_timeouts" },
43 { "alloc_rx_skb_error" },
44 { "rx_iommu_map_error" },
45 { "tx_iommu_map_error" },
46 { "rx_desc_unk_state" },
49 static int
50 spider_net_ethtool_get_link_ksettings(struct net_device *netdev,
51 struct ethtool_link_ksettings *cmd)
53 struct spider_net_card *card;
54 card = netdev_priv(netdev);
56 ethtool_link_ksettings_zero_link_mode(cmd, supported);
57 ethtool_link_ksettings_add_link_mode(cmd, supported, 1000baseT_Full);
58 ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE);
60 ethtool_link_ksettings_zero_link_mode(cmd, advertising);
61 ethtool_link_ksettings_add_link_mode(cmd, advertising, 1000baseT_Full);
62 ethtool_link_ksettings_add_link_mode(cmd, advertising, FIBRE);
64 cmd->base.port = PORT_FIBRE;
65 cmd->base.speed = card->phy.speed;
66 cmd->base.duplex = DUPLEX_FULL;
68 return 0;
71 static void
72 spider_net_ethtool_get_drvinfo(struct net_device *netdev,
73 struct ethtool_drvinfo *drvinfo)
75 struct spider_net_card *card;
76 card = netdev_priv(netdev);
78 /* clear and fill out info */
79 strlcpy(drvinfo->driver, spider_net_driver_name,
80 sizeof(drvinfo->driver));
81 strlcpy(drvinfo->version, VERSION, sizeof(drvinfo->version));
82 strlcpy(drvinfo->fw_version, "no information",
83 sizeof(drvinfo->fw_version));
84 strlcpy(drvinfo->bus_info, pci_name(card->pdev),
85 sizeof(drvinfo->bus_info));
88 static void
89 spider_net_ethtool_get_wol(struct net_device *netdev,
90 struct ethtool_wolinfo *wolinfo)
92 /* no support for wol */
93 wolinfo->supported = 0;
94 wolinfo->wolopts = 0;
97 static u32
98 spider_net_ethtool_get_msglevel(struct net_device *netdev)
100 struct spider_net_card *card;
101 card = netdev_priv(netdev);
102 return card->msg_enable;
105 static void
106 spider_net_ethtool_set_msglevel(struct net_device *netdev,
107 u32 level)
109 struct spider_net_card *card;
110 card = netdev_priv(netdev);
111 card->msg_enable = level;
114 static int
115 spider_net_ethtool_nway_reset(struct net_device *netdev)
117 if (netif_running(netdev)) {
118 spider_net_stop(netdev);
119 spider_net_open(netdev);
121 return 0;
124 static void
125 spider_net_ethtool_get_ringparam(struct net_device *netdev,
126 struct ethtool_ringparam *ering)
128 struct spider_net_card *card = netdev_priv(netdev);
130 ering->tx_max_pending = SPIDER_NET_TX_DESCRIPTORS_MAX;
131 ering->tx_pending = card->tx_chain.num_desc;
132 ering->rx_max_pending = SPIDER_NET_RX_DESCRIPTORS_MAX;
133 ering->rx_pending = card->rx_chain.num_desc;
136 static int spider_net_get_sset_count(struct net_device *netdev, int sset)
138 switch (sset) {
139 case ETH_SS_STATS:
140 return ARRAY_SIZE(ethtool_stats_keys);
141 default:
142 return -EOPNOTSUPP;
146 static void spider_net_get_ethtool_stats(struct net_device *netdev,
147 struct ethtool_stats *stats, u64 *data)
149 struct spider_net_card *card = netdev_priv(netdev);
151 data[0] = netdev->stats.tx_packets;
152 data[1] = netdev->stats.tx_bytes;
153 data[2] = netdev->stats.rx_packets;
154 data[3] = netdev->stats.rx_bytes;
155 data[4] = netdev->stats.tx_errors;
156 data[5] = netdev->stats.tx_dropped;
157 data[6] = netdev->stats.rx_dropped;
158 data[7] = card->spider_stats.rx_desc_error;
159 data[8] = card->spider_stats.tx_timeouts;
160 data[9] = card->spider_stats.alloc_rx_skb_error;
161 data[10] = card->spider_stats.rx_iommu_map_error;
162 data[11] = card->spider_stats.tx_iommu_map_error;
163 data[12] = card->spider_stats.rx_desc_unk_state;
166 static void spider_net_get_strings(struct net_device *netdev, u32 stringset,
167 u8 *data)
169 memcpy(data, ethtool_stats_keys, sizeof(ethtool_stats_keys));
172 const struct ethtool_ops spider_net_ethtool_ops = {
173 .get_drvinfo = spider_net_ethtool_get_drvinfo,
174 .get_wol = spider_net_ethtool_get_wol,
175 .get_msglevel = spider_net_ethtool_get_msglevel,
176 .set_msglevel = spider_net_ethtool_set_msglevel,
177 .get_link = ethtool_op_get_link,
178 .nway_reset = spider_net_ethtool_nway_reset,
179 .get_ringparam = spider_net_ethtool_get_ringparam,
180 .get_strings = spider_net_get_strings,
181 .get_sset_count = spider_net_get_sset_count,
182 .get_ethtool_stats = spider_net_get_ethtool_stats,
183 .get_link_ksettings = spider_net_ethtool_get_link_ksettings,