blob: dbb7dd2f8e360e4d6c1013182e9d667a19d7fa56 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
Auke Kok0abb6eb2006-09-27 12:53:14 -07003 Intel PRO/10GbE Linux driver
Jesse Brandeburgf731a9e2008-07-08 15:53:09 -07004 Copyright(c) 1999 - 2008 Intel Corporation.
Auke Kok0abb6eb2006-09-27 12:53:14 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 more details.
Auke Kok0abb6eb2006-09-27 12:53:14 -070014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 You should have received a copy of the GNU General Public License along with
Auke Kok0abb6eb2006-09-27 12:53:14 -070016 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 Contact Information:
23 Linux NICS <linux.nics@intel.com>
Auke Kok0abb6eb2006-09-27 12:53:14 -070024 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29/* ethtool support for ixgb */
30
31#include "ixgb.h"
32
33#include <asm/uaccess.h>
34
Auke Kokc85fd6f2006-05-23 10:30:02 -070035#define IXGB_ALL_RAR_ENTRIES 16
36
Ajit Khaparded189a7e2009-10-13 01:46:56 +000037enum {NETDEV_STATS, IXGB_STATS};
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039struct ixgb_stats {
40 char stat_string[ETH_GSTRING_LEN];
Ajit Khaparded189a7e2009-10-13 01:46:56 +000041 int type;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 int sizeof_stat;
43 int stat_offset;
44};
45
Ajit Khaparded189a7e2009-10-13 01:46:56 +000046#define IXGB_STAT(m) IXGB_STATS, \
47 FIELD_SIZEOF(struct ixgb_adapter, m), \
48 offsetof(struct ixgb_adapter, m)
49#define IXGB_NETDEV_STAT(m) NETDEV_STATS, \
50 FIELD_SIZEOF(struct net_device, m), \
51 offsetof(struct net_device, m)
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053static struct ixgb_stats ixgb_gstrings_stats[] = {
Ajit Khaparde0cdc0362009-10-07 02:46:59 +000054 {"rx_packets", IXGB_NETDEV_STAT(stats.rx_packets)},
55 {"tx_packets", IXGB_NETDEV_STAT(stats.tx_packets)},
56 {"rx_bytes", IXGB_NETDEV_STAT(stats.rx_bytes)},
57 {"tx_bytes", IXGB_NETDEV_STAT(stats.tx_bytes)},
58 {"rx_errors", IXGB_NETDEV_STAT(stats.rx_errors)},
59 {"tx_errors", IXGB_NETDEV_STAT(stats.tx_errors)},
60 {"rx_dropped", IXGB_NETDEV_STAT(stats.rx_dropped)},
61 {"tx_dropped", IXGB_NETDEV_STAT(stats.tx_dropped)},
62 {"multicast", IXGB_NETDEV_STAT(stats.multicast)},
63 {"collisions", IXGB_NETDEV_STAT(stats.collisions)},
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Ajit Khaparde0cdc0362009-10-07 02:46:59 +000065/* { "rx_length_errors", IXGB_NETDEV_STAT(stats.rx_length_errors) }, */
66 {"rx_over_errors", IXGB_NETDEV_STAT(stats.rx_over_errors)},
67 {"rx_crc_errors", IXGB_NETDEV_STAT(stats.rx_crc_errors)},
68 {"rx_frame_errors", IXGB_NETDEV_STAT(stats.rx_frame_errors)},
Auke Kokac0b3502008-02-21 15:10:41 -080069 {"rx_no_buffer_count", IXGB_STAT(stats.rnbc)},
Ajit Khaparde0cdc0362009-10-07 02:46:59 +000070 {"rx_fifo_errors", IXGB_NETDEV_STAT(stats.rx_fifo_errors)},
71 {"rx_missed_errors", IXGB_NETDEV_STAT(stats.rx_missed_errors)},
72 {"tx_aborted_errors", IXGB_NETDEV_STAT(stats.tx_aborted_errors)},
73 {"tx_carrier_errors", IXGB_NETDEV_STAT(stats.tx_carrier_errors)},
74 {"tx_fifo_errors", IXGB_NETDEV_STAT(stats.tx_fifo_errors)},
75 {"tx_heartbeat_errors", IXGB_NETDEV_STAT(stats.tx_heartbeat_errors)},
76 {"tx_window_errors", IXGB_NETDEV_STAT(stats.tx_window_errors)},
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 {"tx_deferred_ok", IXGB_STAT(stats.dc)},
Auke Kok9b8118d2006-05-23 10:35:04 -070078 {"tx_timeout_count", IXGB_STAT(tx_timeout_count) },
Jesse Brandeburgdfd341e2007-01-06 09:51:38 -080079 {"tx_restart_queue", IXGB_STAT(restart_queue) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 {"rx_long_length_errors", IXGB_STAT(stats.roc)},
81 {"rx_short_length_errors", IXGB_STAT(stats.ruc)},
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 {"tx_tcp_seg_good", IXGB_STAT(stats.tsctc)},
83 {"tx_tcp_seg_failed", IXGB_STAT(stats.tsctfc)},
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 {"rx_flow_control_xon", IXGB_STAT(stats.xonrxc)},
85 {"rx_flow_control_xoff", IXGB_STAT(stats.xoffrxc)},
86 {"tx_flow_control_xon", IXGB_STAT(stats.xontxc)},
87 {"tx_flow_control_xoff", IXGB_STAT(stats.xofftxc)},
88 {"rx_csum_offload_good", IXGB_STAT(hw_csum_rx_good)},
89 {"rx_csum_offload_errors", IXGB_STAT(hw_csum_rx_error)},
90 {"tx_csum_offload_good", IXGB_STAT(hw_csum_tx_good)},
91 {"tx_csum_offload_errors", IXGB_STAT(hw_csum_tx_error)}
92};
93
Denis Chengff8ac602007-09-02 18:30:18 +080094#define IXGB_STATS_LEN ARRAY_SIZE(ixgb_gstrings_stats)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96static int
97ixgb_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
98{
Malli Chilakala8908c6c2005-08-11 13:58:40 -070099 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
Malli Chilakaladb0baca2005-08-11 13:59:20 -0700102 ecmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 ecmd->port = PORT_FIBRE;
104 ecmd->transceiver = XCVR_EXTERNAL;
105
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700106 if (netif_carrier_ok(adapter->netdev)) {
David Decotigny70739492011-04-27 18:32:40 +0000107 ethtool_cmd_speed_set(ecmd, SPEED_10000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 ecmd->duplex = DUPLEX_FULL;
109 } else {
David Decotigny70739492011-04-27 18:32:40 +0000110 ethtool_cmd_speed_set(ecmd, -1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 ecmd->duplex = -1;
112 }
113
114 ecmd->autoneg = AUTONEG_DISABLE;
115 return 0;
116}
117
Michał Mirosławd7ccb8c2011-06-08 08:39:40 +0000118void ixgb_set_speed_duplex(struct net_device *netdev)
Auke Kok4de17c82006-05-23 10:29:46 -0700119{
120 struct ixgb_adapter *adapter = netdev_priv(netdev);
121 /* be optimistic about our link, since we were up before */
122 adapter->link_speed = 10000;
123 adapter->link_duplex = FULL_DUPLEX;
124 netif_carrier_on(netdev);
125 netif_wake_queue(netdev);
126}
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128static int
129ixgb_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
130{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700131 struct ixgb_adapter *adapter = netdev_priv(netdev);
David Decotigny25db0332011-04-27 18:32:39 +0000132 u32 speed = ethtool_cmd_speed(ecmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700134 if (ecmd->autoneg == AUTONEG_ENABLE ||
David Decotigny25db0332011-04-27 18:32:39 +0000135 (speed + ecmd->duplex != SPEED_10000 + DUPLEX_FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 return -EINVAL;
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700137
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700138 if (netif_running(adapter->netdev)) {
Joe Perches446490c2008-03-21 11:06:37 -0700139 ixgb_down(adapter, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 ixgb_reset(adapter);
141 ixgb_up(adapter);
Auke Kok4de17c82006-05-23 10:29:46 -0700142 ixgb_set_speed_duplex(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 } else
144 ixgb_reset(adapter);
145
146 return 0;
147}
148
149static void
150ixgb_get_pauseparam(struct net_device *netdev,
151 struct ethtool_pauseparam *pause)
152{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700153 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 struct ixgb_hw *hw = &adapter->hw;
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 pause->autoneg = AUTONEG_DISABLE;
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700157
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700158 if (hw->fc.type == ixgb_fc_rx_pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 pause->rx_pause = 1;
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700160 else if (hw->fc.type == ixgb_fc_tx_pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 pause->tx_pause = 1;
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700162 else if (hw->fc.type == ixgb_fc_full) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 pause->rx_pause = 1;
164 pause->tx_pause = 1;
165 }
166}
167
168static int
169ixgb_set_pauseparam(struct net_device *netdev,
170 struct ethtool_pauseparam *pause)
171{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700172 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 struct ixgb_hw *hw = &adapter->hw;
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700174
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700175 if (pause->autoneg == AUTONEG_ENABLE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 return -EINVAL;
177
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700178 if (pause->rx_pause && pause->tx_pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 hw->fc.type = ixgb_fc_full;
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700180 else if (pause->rx_pause && !pause->tx_pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 hw->fc.type = ixgb_fc_rx_pause;
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700182 else if (!pause->rx_pause && pause->tx_pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 hw->fc.type = ixgb_fc_tx_pause;
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700184 else if (!pause->rx_pause && !pause->tx_pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 hw->fc.type = ixgb_fc_none;
186
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700187 if (netif_running(adapter->netdev)) {
Joe Perches446490c2008-03-21 11:06:37 -0700188 ixgb_down(adapter, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 ixgb_up(adapter);
Auke Kok4de17c82006-05-23 10:29:46 -0700190 ixgb_set_speed_duplex(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 } else
192 ixgb_reset(adapter);
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 return 0;
195}
196
Joe Perches222441a2008-04-03 10:06:25 -0700197static u32
Auke Kokec9c3f52006-05-23 10:34:59 -0700198ixgb_get_msglevel(struct net_device *netdev)
199{
Auke Kok25943072006-05-26 09:35:57 -0700200 struct ixgb_adapter *adapter = netdev_priv(netdev);
Auke Kokec9c3f52006-05-23 10:34:59 -0700201 return adapter->msg_enable;
202}
203
204static void
Joe Perches222441a2008-04-03 10:06:25 -0700205ixgb_set_msglevel(struct net_device *netdev, u32 data)
Auke Kokec9c3f52006-05-23 10:34:59 -0700206{
Auke Kok25943072006-05-26 09:35:57 -0700207 struct ixgb_adapter *adapter = netdev_priv(netdev);
Auke Kokec9c3f52006-05-23 10:34:59 -0700208 adapter->msg_enable = data;
209}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210#define IXGB_GET_STAT(_A_, _R_) _A_->stats._R_
211
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700212static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213ixgb_get_regs_len(struct net_device *netdev)
214{
Joe Perches222441a2008-04-03 10:06:25 -0700215#define IXGB_REG_DUMP_LEN 136*sizeof(u32)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 return IXGB_REG_DUMP_LEN;
217}
218
219static void
220ixgb_get_regs(struct net_device *netdev,
221 struct ethtool_regs *regs, void *p)
222{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700223 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 struct ixgb_hw *hw = &adapter->hw;
Joe Perches222441a2008-04-03 10:06:25 -0700225 u32 *reg = p;
226 u32 *reg_start = reg;
227 u8 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
Malli Chilakala5e3c30d2005-04-28 19:04:07 -0700229 /* the 1 (one) below indicates an attempt at versioning, if the
Malli Chilakalaab707da2005-08-11 13:59:59 -0700230 * interface in ethtool or the driver changes, this 1 should be
231 * incremented */
Malli Chilakala5e3c30d2005-04-28 19:04:07 -0700232 regs->version = (1<<24) | hw->revision_id << 16 | hw->device_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
234 /* General Registers */
235 *reg++ = IXGB_READ_REG(hw, CTRL0); /* 0 */
236 *reg++ = IXGB_READ_REG(hw, CTRL1); /* 1 */
237 *reg++ = IXGB_READ_REG(hw, STATUS); /* 2 */
238 *reg++ = IXGB_READ_REG(hw, EECD); /* 3 */
239 *reg++ = IXGB_READ_REG(hw, MFS); /* 4 */
240
241 /* Interrupt */
242 *reg++ = IXGB_READ_REG(hw, ICR); /* 5 */
243 *reg++ = IXGB_READ_REG(hw, ICS); /* 6 */
244 *reg++ = IXGB_READ_REG(hw, IMS); /* 7 */
245 *reg++ = IXGB_READ_REG(hw, IMC); /* 8 */
246
247 /* Receive */
248 *reg++ = IXGB_READ_REG(hw, RCTL); /* 9 */
249 *reg++ = IXGB_READ_REG(hw, FCRTL); /* 10 */
250 *reg++ = IXGB_READ_REG(hw, FCRTH); /* 11 */
251 *reg++ = IXGB_READ_REG(hw, RDBAL); /* 12 */
252 *reg++ = IXGB_READ_REG(hw, RDBAH); /* 13 */
253 *reg++ = IXGB_READ_REG(hw, RDLEN); /* 14 */
254 *reg++ = IXGB_READ_REG(hw, RDH); /* 15 */
255 *reg++ = IXGB_READ_REG(hw, RDT); /* 16 */
256 *reg++ = IXGB_READ_REG(hw, RDTR); /* 17 */
257 *reg++ = IXGB_READ_REG(hw, RXDCTL); /* 18 */
258 *reg++ = IXGB_READ_REG(hw, RAIDC); /* 19 */
259 *reg++ = IXGB_READ_REG(hw, RXCSUM); /* 20 */
260
Malli Chilakala9ef2eec2005-08-11 13:59:07 -0700261 /* there are 16 RAR entries in hardware, we only use 3 */
Jesse Brandeburg14593362008-07-08 15:52:33 -0700262 for (i = 0; i < IXGB_ALL_RAR_ENTRIES; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 *reg++ = IXGB_READ_REG_ARRAY(hw, RAL, (i << 1)); /*21,...,51 */
264 *reg++ = IXGB_READ_REG_ARRAY(hw, RAH, (i << 1)); /*22,...,52 */
265 }
266
267 /* Transmit */
268 *reg++ = IXGB_READ_REG(hw, TCTL); /* 53 */
269 *reg++ = IXGB_READ_REG(hw, TDBAL); /* 54 */
270 *reg++ = IXGB_READ_REG(hw, TDBAH); /* 55 */
271 *reg++ = IXGB_READ_REG(hw, TDLEN); /* 56 */
272 *reg++ = IXGB_READ_REG(hw, TDH); /* 57 */
273 *reg++ = IXGB_READ_REG(hw, TDT); /* 58 */
274 *reg++ = IXGB_READ_REG(hw, TIDV); /* 59 */
275 *reg++ = IXGB_READ_REG(hw, TXDCTL); /* 60 */
276 *reg++ = IXGB_READ_REG(hw, TSPMT); /* 61 */
277 *reg++ = IXGB_READ_REG(hw, PAP); /* 62 */
278
279 /* Physical */
280 *reg++ = IXGB_READ_REG(hw, PCSC1); /* 63 */
281 *reg++ = IXGB_READ_REG(hw, PCSC2); /* 64 */
282 *reg++ = IXGB_READ_REG(hw, PCSS1); /* 65 */
283 *reg++ = IXGB_READ_REG(hw, PCSS2); /* 66 */
284 *reg++ = IXGB_READ_REG(hw, XPCSS); /* 67 */
285 *reg++ = IXGB_READ_REG(hw, UCCR); /* 68 */
286 *reg++ = IXGB_READ_REG(hw, XPCSTC); /* 69 */
287 *reg++ = IXGB_READ_REG(hw, MACA); /* 70 */
288 *reg++ = IXGB_READ_REG(hw, APAE); /* 71 */
289 *reg++ = IXGB_READ_REG(hw, ARD); /* 72 */
290 *reg++ = IXGB_READ_REG(hw, AIS); /* 73 */
291 *reg++ = IXGB_READ_REG(hw, MSCA); /* 74 */
292 *reg++ = IXGB_READ_REG(hw, MSRWD); /* 75 */
293
294 /* Statistics */
295 *reg++ = IXGB_GET_STAT(adapter, tprl); /* 76 */
296 *reg++ = IXGB_GET_STAT(adapter, tprh); /* 77 */
297 *reg++ = IXGB_GET_STAT(adapter, gprcl); /* 78 */
298 *reg++ = IXGB_GET_STAT(adapter, gprch); /* 79 */
299 *reg++ = IXGB_GET_STAT(adapter, bprcl); /* 80 */
300 *reg++ = IXGB_GET_STAT(adapter, bprch); /* 81 */
301 *reg++ = IXGB_GET_STAT(adapter, mprcl); /* 82 */
302 *reg++ = IXGB_GET_STAT(adapter, mprch); /* 83 */
303 *reg++ = IXGB_GET_STAT(adapter, uprcl); /* 84 */
304 *reg++ = IXGB_GET_STAT(adapter, uprch); /* 85 */
305 *reg++ = IXGB_GET_STAT(adapter, vprcl); /* 86 */
306 *reg++ = IXGB_GET_STAT(adapter, vprch); /* 87 */
307 *reg++ = IXGB_GET_STAT(adapter, jprcl); /* 88 */
308 *reg++ = IXGB_GET_STAT(adapter, jprch); /* 89 */
309 *reg++ = IXGB_GET_STAT(adapter, gorcl); /* 90 */
310 *reg++ = IXGB_GET_STAT(adapter, gorch); /* 91 */
311 *reg++ = IXGB_GET_STAT(adapter, torl); /* 92 */
312 *reg++ = IXGB_GET_STAT(adapter, torh); /* 93 */
313 *reg++ = IXGB_GET_STAT(adapter, rnbc); /* 94 */
314 *reg++ = IXGB_GET_STAT(adapter, ruc); /* 95 */
315 *reg++ = IXGB_GET_STAT(adapter, roc); /* 96 */
316 *reg++ = IXGB_GET_STAT(adapter, rlec); /* 97 */
317 *reg++ = IXGB_GET_STAT(adapter, crcerrs); /* 98 */
318 *reg++ = IXGB_GET_STAT(adapter, icbc); /* 99 */
319 *reg++ = IXGB_GET_STAT(adapter, ecbc); /* 100 */
320 *reg++ = IXGB_GET_STAT(adapter, mpc); /* 101 */
321 *reg++ = IXGB_GET_STAT(adapter, tptl); /* 102 */
322 *reg++ = IXGB_GET_STAT(adapter, tpth); /* 103 */
323 *reg++ = IXGB_GET_STAT(adapter, gptcl); /* 104 */
324 *reg++ = IXGB_GET_STAT(adapter, gptch); /* 105 */
325 *reg++ = IXGB_GET_STAT(adapter, bptcl); /* 106 */
326 *reg++ = IXGB_GET_STAT(adapter, bptch); /* 107 */
327 *reg++ = IXGB_GET_STAT(adapter, mptcl); /* 108 */
328 *reg++ = IXGB_GET_STAT(adapter, mptch); /* 109 */
329 *reg++ = IXGB_GET_STAT(adapter, uptcl); /* 110 */
330 *reg++ = IXGB_GET_STAT(adapter, uptch); /* 111 */
331 *reg++ = IXGB_GET_STAT(adapter, vptcl); /* 112 */
332 *reg++ = IXGB_GET_STAT(adapter, vptch); /* 113 */
333 *reg++ = IXGB_GET_STAT(adapter, jptcl); /* 114 */
334 *reg++ = IXGB_GET_STAT(adapter, jptch); /* 115 */
335 *reg++ = IXGB_GET_STAT(adapter, gotcl); /* 116 */
336 *reg++ = IXGB_GET_STAT(adapter, gotch); /* 117 */
337 *reg++ = IXGB_GET_STAT(adapter, totl); /* 118 */
338 *reg++ = IXGB_GET_STAT(adapter, toth); /* 119 */
339 *reg++ = IXGB_GET_STAT(adapter, dc); /* 120 */
340 *reg++ = IXGB_GET_STAT(adapter, plt64c); /* 121 */
341 *reg++ = IXGB_GET_STAT(adapter, tsctc); /* 122 */
342 *reg++ = IXGB_GET_STAT(adapter, tsctfc); /* 123 */
343 *reg++ = IXGB_GET_STAT(adapter, ibic); /* 124 */
344 *reg++ = IXGB_GET_STAT(adapter, rfc); /* 125 */
345 *reg++ = IXGB_GET_STAT(adapter, lfc); /* 126 */
346 *reg++ = IXGB_GET_STAT(adapter, pfrc); /* 127 */
347 *reg++ = IXGB_GET_STAT(adapter, pftc); /* 128 */
348 *reg++ = IXGB_GET_STAT(adapter, mcfrc); /* 129 */
349 *reg++ = IXGB_GET_STAT(adapter, mcftc); /* 130 */
350 *reg++ = IXGB_GET_STAT(adapter, xonrxc); /* 131 */
351 *reg++ = IXGB_GET_STAT(adapter, xontxc); /* 132 */
352 *reg++ = IXGB_GET_STAT(adapter, xoffrxc); /* 133 */
353 *reg++ = IXGB_GET_STAT(adapter, xofftxc); /* 134 */
354 *reg++ = IXGB_GET_STAT(adapter, rjc); /* 135 */
355
Joe Perches222441a2008-04-03 10:06:25 -0700356 regs->len = (reg - reg_start) * sizeof(u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357}
358
359static int
360ixgb_get_eeprom_len(struct net_device *netdev)
361{
362 /* return size in bytes */
Eric Dumazet807540b2010-09-23 05:40:09 +0000363 return IXGB_EEPROM_SIZE << 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364}
365
366static int
367ixgb_get_eeprom(struct net_device *netdev,
Joe Perches222441a2008-04-03 10:06:25 -0700368 struct ethtool_eeprom *eeprom, u8 *bytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700370 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 struct ixgb_hw *hw = &adapter->hw;
Al Viroc6765042007-08-23 00:47:03 -0400372 __le16 *eeprom_buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 int i, max_len, first_word, last_word;
374 int ret_val = 0;
375
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700376 if (eeprom->len == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 ret_val = -EINVAL;
378 goto geeprom_error;
379 }
380
381 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
382
383 max_len = ixgb_get_eeprom_len(netdev);
384
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700385 if (eeprom->offset > eeprom->offset + eeprom->len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 ret_val = -EINVAL;
387 goto geeprom_error;
388 }
389
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700390 if ((eeprom->offset + eeprom->len) > max_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 eeprom->len = (max_len - eeprom->offset);
392
393 first_word = eeprom->offset >> 1;
394 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
395
Al Viroc6765042007-08-23 00:47:03 -0400396 eeprom_buff = kmalloc(sizeof(__le16) *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 (last_word - first_word + 1), GFP_KERNEL);
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700398 if (!eeprom_buff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 return -ENOMEM;
400
401 /* note the eeprom was good because the driver loaded */
Jesse Brandeburg14593362008-07-08 15:52:33 -0700402 for (i = 0; i <= (last_word - first_word); i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 eeprom_buff[i] = ixgb_get_eeprom_word(hw, (first_word + i));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Jesse Brandeburg14593362008-07-08 15:52:33 -0700405 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 kfree(eeprom_buff);
407
408geeprom_error:
409 return ret_val;
410}
411
412static int
413ixgb_set_eeprom(struct net_device *netdev,
Joe Perches222441a2008-04-03 10:06:25 -0700414 struct ethtool_eeprom *eeprom, u8 *bytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700416 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 struct ixgb_hw *hw = &adapter->hw;
Joe Perches222441a2008-04-03 10:06:25 -0700418 u16 *eeprom_buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 void *ptr;
420 int max_len, first_word, last_word;
Joe Perches222441a2008-04-03 10:06:25 -0700421 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700423 if (eeprom->len == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 return -EINVAL;
425
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700426 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 return -EFAULT;
428
429 max_len = ixgb_get_eeprom_len(netdev);
430
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700431 if (eeprom->offset > eeprom->offset + eeprom->len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 return -EINVAL;
433
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700434 if ((eeprom->offset + eeprom->len) > max_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 eeprom->len = (max_len - eeprom->offset);
436
437 first_word = eeprom->offset >> 1;
438 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
439 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700440 if (!eeprom_buff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 return -ENOMEM;
442
443 ptr = (void *)eeprom_buff;
444
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700445 if (eeprom->offset & 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 /* need read/modify/write of first changed EEPROM word */
447 /* only the second byte of the word is being modified */
448 eeprom_buff[0] = ixgb_read_eeprom(hw, first_word);
449 ptr++;
450 }
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700451 if ((eeprom->offset + eeprom->len) & 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 /* need read/modify/write of last changed EEPROM word */
453 /* only the first byte of the word is being modified */
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700454 eeprom_buff[last_word - first_word]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 = ixgb_read_eeprom(hw, last_word);
456 }
457
458 memcpy(ptr, bytes, eeprom->len);
Jesse Brandeburg14593362008-07-08 15:52:33 -0700459 for (i = 0; i <= (last_word - first_word); i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 ixgb_write_eeprom(hw, first_word + i, eeprom_buff[i]);
461
462 /* Update the checksum over the first part of the EEPROM if needed */
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700463 if (first_word <= EEPROM_CHECKSUM_REG)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 ixgb_update_eeprom_checksum(hw);
465
466 kfree(eeprom_buff);
467 return 0;
468}
469
470static void
471ixgb_get_drvinfo(struct net_device *netdev,
472 struct ethtool_drvinfo *drvinfo)
473{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700474 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
Rick Jones612a94d2011-11-14 08:13:25 +0000476 strlcpy(drvinfo->driver, ixgb_driver_name,
477 sizeof(drvinfo->driver));
478 strlcpy(drvinfo->version, ixgb_driver_version,
479 sizeof(drvinfo->version));
Rick Jones612a94d2011-11-14 08:13:25 +0000480 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
481 sizeof(drvinfo->bus_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 drvinfo->n_stats = IXGB_STATS_LEN;
483 drvinfo->regdump_len = ixgb_get_regs_len(netdev);
484 drvinfo->eedump_len = ixgb_get_eeprom_len(netdev);
485}
486
487static void
488ixgb_get_ringparam(struct net_device *netdev,
489 struct ethtool_ringparam *ring)
490{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700491 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
493 struct ixgb_desc_ring *rxdr = &adapter->rx_ring;
494
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700495 ring->rx_max_pending = MAX_RXD;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 ring->tx_max_pending = MAX_TXD;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 ring->rx_pending = rxdr->count;
498 ring->tx_pending = txdr->count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499}
500
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700501static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502ixgb_set_ringparam(struct net_device *netdev,
503 struct ethtool_ringparam *ring)
504{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700505 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
507 struct ixgb_desc_ring *rxdr = &adapter->rx_ring;
508 struct ixgb_desc_ring tx_old, tx_new, rx_old, rx_new;
509 int err;
510
511 tx_old = adapter->tx_ring;
512 rx_old = adapter->rx_ring;
513
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700514 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 return -EINVAL;
516
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700517 if (netif_running(adapter->netdev))
Joe Perches446490c2008-03-21 11:06:37 -0700518 ixgb_down(adapter, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
Joe Perches222441a2008-04-03 10:06:25 -0700520 rxdr->count = max(ring->rx_pending,(u32)MIN_RXD);
521 rxdr->count = min(rxdr->count,(u32)MAX_RXD);
Milind Arun Choudhary55e924c2007-04-27 13:55:31 -0700522 rxdr->count = ALIGN(rxdr->count, IXGB_REQ_RX_DESCRIPTOR_MULTIPLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
Joe Perches222441a2008-04-03 10:06:25 -0700524 txdr->count = max(ring->tx_pending,(u32)MIN_TXD);
525 txdr->count = min(txdr->count,(u32)MAX_TXD);
Milind Arun Choudhary55e924c2007-04-27 13:55:31 -0700526 txdr->count = ALIGN(txdr->count, IXGB_REQ_TX_DESCRIPTOR_MULTIPLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700528 if (netif_running(adapter->netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 /* Try to get new resources before deleting old */
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700530 if ((err = ixgb_setup_rx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 goto err_setup_rx;
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700532 if ((err = ixgb_setup_tx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 goto err_setup_tx;
534
535 /* save the new, restore the old in order to free it,
536 * then restore the new back again */
537
538 rx_new = adapter->rx_ring;
539 tx_new = adapter->tx_ring;
540 adapter->rx_ring = rx_old;
541 adapter->tx_ring = tx_old;
542 ixgb_free_rx_resources(adapter);
543 ixgb_free_tx_resources(adapter);
544 adapter->rx_ring = rx_new;
545 adapter->tx_ring = tx_new;
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700546 if ((err = ixgb_up(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 return err;
Auke Kok4de17c82006-05-23 10:29:46 -0700548 ixgb_set_speed_duplex(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 }
550
551 return 0;
552err_setup_tx:
553 ixgb_free_rx_resources(adapter);
554err_setup_rx:
555 adapter->rx_ring = rx_old;
556 adapter->tx_ring = tx_old;
557 ixgb_up(adapter);
558 return err;
559}
560
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561static int
Jeff Kirsherec7e97e2011-05-03 05:17:34 +0000562ixgb_set_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700564 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Jeff Kirsherec7e97e2011-05-03 05:17:34 +0000566 switch (state) {
567 case ETHTOOL_ID_ACTIVE:
568 return 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
Jeff Kirsherec7e97e2011-05-03 05:17:34 +0000570 case ETHTOOL_ID_ON:
571 ixgb_led_on(&adapter->hw);
572 break;
573
574 case ETHTOOL_ID_OFF:
575 case ETHTOOL_ID_INACTIVE:
576 ixgb_led_off(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 }
578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 return 0;
580}
581
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700582static int
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700583ixgb_get_sset_count(struct net_device *netdev, int sset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584{
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700585 switch (sset) {
586 case ETH_SS_STATS:
587 return IXGB_STATS_LEN;
588 default:
589 return -EOPNOTSUPP;
590 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591}
592
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700593static void
594ixgb_get_ethtool_stats(struct net_device *netdev,
Joe Perches222441a2008-04-03 10:06:25 -0700595 struct ethtool_stats *stats, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700597 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 int i;
Ajit Khaparded189a7e2009-10-13 01:46:56 +0000599 char *p = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
601 ixgb_update_stats(adapter);
Jesse Brandeburg14593362008-07-08 15:52:33 -0700602 for (i = 0; i < IXGB_STATS_LEN; i++) {
Ajit Khaparded189a7e2009-10-13 01:46:56 +0000603 switch (ixgb_gstrings_stats[i].type) {
604 case NETDEV_STATS:
605 p = (char *) netdev +
606 ixgb_gstrings_stats[i].stat_offset;
607 break;
608 case IXGB_STATS:
609 p = (char *) adapter +
610 ixgb_gstrings_stats[i].stat_offset;
611 break;
612 }
613
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700614 data[i] = (ixgb_gstrings_stats[i].sizeof_stat ==
Joe Perches222441a2008-04-03 10:06:25 -0700615 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 }
617}
618
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700619static void
Joe Perches222441a2008-04-03 10:06:25 -0700620ixgb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621{
622 int i;
623
624 switch(stringset) {
625 case ETH_SS_STATS:
Jesse Brandeburg14593362008-07-08 15:52:33 -0700626 for (i = 0; i < IXGB_STATS_LEN; i++) {
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700627 memcpy(data + i * ETH_GSTRING_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 ixgb_gstrings_stats[i].stat_string,
629 ETH_GSTRING_LEN);
630 }
631 break;
632 }
633}
634
Jeff Garzik7282d492006-09-13 14:30:00 -0400635static const struct ethtool_ops ixgb_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 .get_settings = ixgb_get_settings,
637 .set_settings = ixgb_set_settings,
638 .get_drvinfo = ixgb_get_drvinfo,
639 .get_regs_len = ixgb_get_regs_len,
640 .get_regs = ixgb_get_regs,
641 .get_link = ethtool_op_get_link,
642 .get_eeprom_len = ixgb_get_eeprom_len,
643 .get_eeprom = ixgb_get_eeprom,
644 .set_eeprom = ixgb_set_eeprom,
645 .get_ringparam = ixgb_get_ringparam,
646 .set_ringparam = ixgb_set_ringparam,
647 .get_pauseparam = ixgb_get_pauseparam,
648 .set_pauseparam = ixgb_set_pauseparam,
Auke Kokec9c3f52006-05-23 10:34:59 -0700649 .get_msglevel = ixgb_get_msglevel,
650 .set_msglevel = ixgb_set_msglevel,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 .get_strings = ixgb_get_strings,
Jeff Kirsherec7e97e2011-05-03 05:17:34 +0000652 .set_phys_id = ixgb_set_phys_id,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700653 .get_sset_count = ixgb_get_sset_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 .get_ethtool_stats = ixgb_get_ethtool_stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655};
656
657void ixgb_set_ethtool_ops(struct net_device *netdev)
658{
659 SET_ETHTOOL_OPS(netdev, &ixgb_ethtool_ops);
660}