blob: ffe519382e111a04dd37c904a6080cee561e2d47 [file] [log] [blame]
Jens Osterkampaaec0fa2005-09-05 15:19:29 -07001/*
2 * Network device driver for Cell Processor-Based Blade
3 *
4 * (C) Copyright IBM Corp. 2005
5 *
6 * Authors : Utz Bacher <utz.bacher@de.ibm.com>
7 * Jens Osterkamp <Jens.Osterkamp@de.ibm.com>
8 *
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.
13 *
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.
18 *
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.
22 */
23
24#include <linux/netdevice.h>
25#include <linux/ethtool.h>
26#include <linux/pci.h>
27
28#include "spider_net.h"
29
Jim Lewis9b6b0b82006-09-22 17:22:53 -070030
Jim Lewis9b6b0b82006-09-22 17:22:53 -070031static 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" },
47};
48
Jens Osterkamp054034d2005-09-06 19:30:55 -070049static int
50spider_net_ethtool_get_settings(struct net_device *netdev,
51 struct ethtool_cmd *cmd)
52{
53 struct spider_net_card *card;
54 card = netdev_priv(netdev);
55
56 cmd->supported = (SUPPORTED_1000baseT_Full |
57 SUPPORTED_FIBRE);
58 cmd->advertising = (ADVERTISED_1000baseT_Full |
59 ADVERTISED_FIBRE);
60 cmd->port = PORT_FIBRE;
David Decotigny70739492011-04-27 18:32:40 +000061 ethtool_cmd_speed_set(cmd, card->phy.speed);
Jens Osterkamp054034d2005-09-06 19:30:55 -070062 cmd->duplex = DUPLEX_FULL;
63
64 return 0;
65}
66
Jens Osterkampaaec0fa2005-09-05 15:19:29 -070067static void
68spider_net_ethtool_get_drvinfo(struct net_device *netdev,
69 struct ethtool_drvinfo *drvinfo)
70{
71 struct spider_net_card *card;
72 card = netdev_priv(netdev);
73
74 /* clear and fill out info */
Jiri Pirko7826d432013-01-06 00:44:26 +000075 strlcpy(drvinfo->driver, spider_net_driver_name,
76 sizeof(drvinfo->driver));
77 strlcpy(drvinfo->version, VERSION, sizeof(drvinfo->version));
78 strlcpy(drvinfo->fw_version, "no information",
79 sizeof(drvinfo->fw_version));
80 strlcpy(drvinfo->bus_info, pci_name(card->pdev),
81 sizeof(drvinfo->bus_info));
Jens Osterkampaaec0fa2005-09-05 15:19:29 -070082}
83
84static void
85spider_net_ethtool_get_wol(struct net_device *netdev,
86 struct ethtool_wolinfo *wolinfo)
87{
88 /* no support for wol */
89 wolinfo->supported = 0;
90 wolinfo->wolopts = 0;
91}
92
93static u32
94spider_net_ethtool_get_msglevel(struct net_device *netdev)
95{
96 struct spider_net_card *card;
97 card = netdev_priv(netdev);
98 return card->msg_enable;
99}
100
101static void
102spider_net_ethtool_set_msglevel(struct net_device *netdev,
103 u32 level)
104{
105 struct spider_net_card *card;
106 card = netdev_priv(netdev);
107 card->msg_enable = level;
108}
109
110static int
111spider_net_ethtool_nway_reset(struct net_device *netdev)
112{
113 if (netif_running(netdev)) {
114 spider_net_stop(netdev);
115 spider_net_open(netdev);
116 }
117 return 0;
118}
119
Jim Lewisb68a60e2006-08-14 23:00:23 -0700120static void
121spider_net_ethtool_get_ringparam(struct net_device *netdev,
122 struct ethtool_ringparam *ering)
123{
Wang Chen8f15ea42008-11-12 23:38:36 -0800124 struct spider_net_card *card = netdev_priv(netdev);
Jim Lewisb68a60e2006-08-14 23:00:23 -0700125
126 ering->tx_max_pending = SPIDER_NET_TX_DESCRIPTORS_MAX;
Linas Vepstasd4ed8f82006-12-13 15:06:59 -0600127 ering->tx_pending = card->tx_chain.num_desc;
Jim Lewisb68a60e2006-08-14 23:00:23 -0700128 ering->rx_max_pending = SPIDER_NET_RX_DESCRIPTORS_MAX;
Linas Vepstasd4ed8f82006-12-13 15:06:59 -0600129 ering->rx_pending = card->rx_chain.num_desc;
Jim Lewisb68a60e2006-08-14 23:00:23 -0700130}
131
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700132static int spider_net_get_sset_count(struct net_device *netdev, int sset)
Jim Lewis9b6b0b82006-09-22 17:22:53 -0700133{
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700134 switch (sset) {
135 case ETH_SS_STATS:
Satyam Sharma7a876fa2007-09-26 22:29:02 -0700136 return ARRAY_SIZE(ethtool_stats_keys);
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700137 default:
138 return -EOPNOTSUPP;
139 }
Jim Lewis9b6b0b82006-09-22 17:22:53 -0700140}
141
142static void spider_net_get_ethtool_stats(struct net_device *netdev,
143 struct ethtool_stats *stats, u64 *data)
144{
Wang Chen8f15ea42008-11-12 23:38:36 -0800145 struct spider_net_card *card = netdev_priv(netdev);
Jim Lewis9b6b0b82006-09-22 17:22:53 -0700146
Satyam Sharma7a876fa2007-09-26 22:29:02 -0700147 data[0] = netdev->stats.tx_packets;
148 data[1] = netdev->stats.tx_bytes;
149 data[2] = netdev->stats.rx_packets;
150 data[3] = netdev->stats.rx_bytes;
151 data[4] = netdev->stats.tx_errors;
152 data[5] = netdev->stats.tx_dropped;
153 data[6] = netdev->stats.rx_dropped;
Jim Lewis9b6b0b82006-09-22 17:22:53 -0700154 data[7] = card->spider_stats.rx_desc_error;
155 data[8] = card->spider_stats.tx_timeouts;
156 data[9] = card->spider_stats.alloc_rx_skb_error;
157 data[10] = card->spider_stats.rx_iommu_map_error;
158 data[11] = card->spider_stats.tx_iommu_map_error;
159 data[12] = card->spider_stats.rx_desc_unk_state;
160}
161
162static void spider_net_get_strings(struct net_device *netdev, u32 stringset,
163 u8 *data)
164{
165 memcpy(data, ethtool_stats_keys, sizeof(ethtool_stats_keys));
166}
167
Jeff Garzik7282d492006-09-13 14:30:00 -0400168const struct ethtool_ops spider_net_ethtool_ops = {
Jens Osterkamp054034d2005-09-06 19:30:55 -0700169 .get_settings = spider_net_ethtool_get_settings,
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700170 .get_drvinfo = spider_net_ethtool_get_drvinfo,
171 .get_wol = spider_net_ethtool_get_wol,
172 .get_msglevel = spider_net_ethtool_get_msglevel,
173 .set_msglevel = spider_net_ethtool_set_msglevel,
Stephen Hemminger3a2c8922007-06-11 13:35:23 -0500174 .get_link = ethtool_op_get_link,
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700175 .nway_reset = spider_net_ethtool_nway_reset,
Jim Lewisb68a60e2006-08-14 23:00:23 -0700176 .get_ringparam = spider_net_ethtool_get_ringparam,
Jim Lewis9b6b0b82006-09-22 17:22:53 -0700177 .get_strings = spider_net_get_strings,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700178 .get_sset_count = spider_net_get_sset_count,
Jim Lewis9b6b0b82006-09-22 17:22:53 -0700179 .get_ethtool_stats = spider_net_get_ethtool_stats,
Jens Osterkampaaec0fa2005-09-05 15:19:29 -0700180};
181