blob: c8c93ac436d4c8c1729c833411a415805d3cde73 [file] [log] [blame]
Jeff Kirsher51dce242018-04-26 08:08:09 -07001// SPDX-License-Identifier: GPL-2.0
2/* Copyright(c) 1999 - 2008 Intel Corporation. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003
4/* ethtool support for ixgb */
5
6#include "ixgb.h"
7
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -08008#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Auke Kokc85fd6f2006-05-23 10:30:02 -070010#define IXGB_ALL_RAR_ENTRIES 16
11
Ajit Khaparded189a7e2009-10-13 01:46:56 +000012enum {NETDEV_STATS, IXGB_STATS};
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014struct ixgb_stats {
15 char stat_string[ETH_GSTRING_LEN];
Ajit Khaparded189a7e2009-10-13 01:46:56 +000016 int type;
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 int sizeof_stat;
18 int stat_offset;
19};
20
Ajit Khaparded189a7e2009-10-13 01:46:56 +000021#define IXGB_STAT(m) IXGB_STATS, \
22 FIELD_SIZEOF(struct ixgb_adapter, m), \
23 offsetof(struct ixgb_adapter, m)
24#define IXGB_NETDEV_STAT(m) NETDEV_STATS, \
25 FIELD_SIZEOF(struct net_device, m), \
26 offsetof(struct net_device, m)
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028static struct ixgb_stats ixgb_gstrings_stats[] = {
Ajit Khaparde0cdc0362009-10-07 02:46:59 +000029 {"rx_packets", IXGB_NETDEV_STAT(stats.rx_packets)},
30 {"tx_packets", IXGB_NETDEV_STAT(stats.tx_packets)},
31 {"rx_bytes", IXGB_NETDEV_STAT(stats.rx_bytes)},
32 {"tx_bytes", IXGB_NETDEV_STAT(stats.tx_bytes)},
33 {"rx_errors", IXGB_NETDEV_STAT(stats.rx_errors)},
34 {"tx_errors", IXGB_NETDEV_STAT(stats.tx_errors)},
35 {"rx_dropped", IXGB_NETDEV_STAT(stats.rx_dropped)},
36 {"tx_dropped", IXGB_NETDEV_STAT(stats.tx_dropped)},
37 {"multicast", IXGB_NETDEV_STAT(stats.multicast)},
38 {"collisions", IXGB_NETDEV_STAT(stats.collisions)},
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Ajit Khaparde0cdc0362009-10-07 02:46:59 +000040/* { "rx_length_errors", IXGB_NETDEV_STAT(stats.rx_length_errors) }, */
41 {"rx_over_errors", IXGB_NETDEV_STAT(stats.rx_over_errors)},
42 {"rx_crc_errors", IXGB_NETDEV_STAT(stats.rx_crc_errors)},
43 {"rx_frame_errors", IXGB_NETDEV_STAT(stats.rx_frame_errors)},
Auke Kokac0b3502008-02-21 15:10:41 -080044 {"rx_no_buffer_count", IXGB_STAT(stats.rnbc)},
Ajit Khaparde0cdc0362009-10-07 02:46:59 +000045 {"rx_fifo_errors", IXGB_NETDEV_STAT(stats.rx_fifo_errors)},
46 {"rx_missed_errors", IXGB_NETDEV_STAT(stats.rx_missed_errors)},
47 {"tx_aborted_errors", IXGB_NETDEV_STAT(stats.tx_aborted_errors)},
48 {"tx_carrier_errors", IXGB_NETDEV_STAT(stats.tx_carrier_errors)},
49 {"tx_fifo_errors", IXGB_NETDEV_STAT(stats.tx_fifo_errors)},
50 {"tx_heartbeat_errors", IXGB_NETDEV_STAT(stats.tx_heartbeat_errors)},
51 {"tx_window_errors", IXGB_NETDEV_STAT(stats.tx_window_errors)},
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 {"tx_deferred_ok", IXGB_STAT(stats.dc)},
Auke Kok9b8118d2006-05-23 10:35:04 -070053 {"tx_timeout_count", IXGB_STAT(tx_timeout_count) },
Jesse Brandeburgdfd341e2007-01-06 09:51:38 -080054 {"tx_restart_queue", IXGB_STAT(restart_queue) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 {"rx_long_length_errors", IXGB_STAT(stats.roc)},
56 {"rx_short_length_errors", IXGB_STAT(stats.ruc)},
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 {"tx_tcp_seg_good", IXGB_STAT(stats.tsctc)},
58 {"tx_tcp_seg_failed", IXGB_STAT(stats.tsctfc)},
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 {"rx_flow_control_xon", IXGB_STAT(stats.xonrxc)},
60 {"rx_flow_control_xoff", IXGB_STAT(stats.xoffrxc)},
61 {"tx_flow_control_xon", IXGB_STAT(stats.xontxc)},
62 {"tx_flow_control_xoff", IXGB_STAT(stats.xofftxc)},
63 {"rx_csum_offload_good", IXGB_STAT(hw_csum_rx_good)},
64 {"rx_csum_offload_errors", IXGB_STAT(hw_csum_rx_error)},
65 {"tx_csum_offload_good", IXGB_STAT(hw_csum_tx_good)},
66 {"tx_csum_offload_errors", IXGB_STAT(hw_csum_tx_error)}
67};
68
Denis Chengff8ac602007-09-02 18:30:18 +080069#define IXGB_STATS_LEN ARRAY_SIZE(ixgb_gstrings_stats)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71static int
Philippe Reynesf22913d2017-02-06 00:11:11 +010072ixgb_get_link_ksettings(struct net_device *netdev,
73 struct ethtool_link_ksettings *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
Malli Chilakala8908c6c2005-08-11 13:58:40 -070075 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Philippe Reynesf22913d2017-02-06 00:11:11 +010077 ethtool_link_ksettings_zero_link_mode(cmd, supported);
78 ethtool_link_ksettings_add_link_mode(cmd, supported, 10000baseT_Full);
79 ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE);
80
81 ethtool_link_ksettings_zero_link_mode(cmd, advertising);
82 ethtool_link_ksettings_add_link_mode(cmd, advertising, 10000baseT_Full);
83 ethtool_link_ksettings_add_link_mode(cmd, advertising, FIBRE);
84
85 cmd->base.port = PORT_FIBRE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Jesse Brandeburg03f83042008-07-08 15:52:13 -070087 if (netif_carrier_ok(adapter->netdev)) {
Philippe Reynesf22913d2017-02-06 00:11:11 +010088 cmd->base.speed = SPEED_10000;
89 cmd->base.duplex = DUPLEX_FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 } else {
Philippe Reynesf22913d2017-02-06 00:11:11 +010091 cmd->base.speed = SPEED_UNKNOWN;
92 cmd->base.duplex = DUPLEX_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 }
94
Philippe Reynesf22913d2017-02-06 00:11:11 +010095 cmd->base.autoneg = AUTONEG_DISABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 return 0;
97}
98
Michał Mirosławd7ccb8c2011-06-08 08:39:40 +000099void ixgb_set_speed_duplex(struct net_device *netdev)
Auke Kok4de17c82006-05-23 10:29:46 -0700100{
101 struct ixgb_adapter *adapter = netdev_priv(netdev);
102 /* be optimistic about our link, since we were up before */
103 adapter->link_speed = 10000;
104 adapter->link_duplex = FULL_DUPLEX;
105 netif_carrier_on(netdev);
106 netif_wake_queue(netdev);
107}
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109static int
Philippe Reynesf22913d2017-02-06 00:11:11 +0100110ixgb_set_link_ksettings(struct net_device *netdev,
111 const struct ethtool_link_ksettings *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700113 struct ixgb_adapter *adapter = netdev_priv(netdev);
Philippe Reynesf22913d2017-02-06 00:11:11 +0100114 u32 speed = cmd->base.speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Philippe Reynesf22913d2017-02-06 00:11:11 +0100116 if (cmd->base.autoneg == AUTONEG_ENABLE ||
117 (speed + cmd->base.duplex != SPEED_10000 + DUPLEX_FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 return -EINVAL;
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700119
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700120 if (netif_running(adapter->netdev)) {
Joe Perches446490ca2008-03-21 11:06:37 -0700121 ixgb_down(adapter, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 ixgb_reset(adapter);
123 ixgb_up(adapter);
Auke Kok4de17c82006-05-23 10:29:46 -0700124 ixgb_set_speed_duplex(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 } else
126 ixgb_reset(adapter);
127
128 return 0;
129}
130
131static void
132ixgb_get_pauseparam(struct net_device *netdev,
133 struct ethtool_pauseparam *pause)
134{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700135 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 struct ixgb_hw *hw = &adapter->hw;
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 pause->autoneg = AUTONEG_DISABLE;
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700139
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700140 if (hw->fc.type == ixgb_fc_rx_pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 pause->rx_pause = 1;
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700142 else if (hw->fc.type == ixgb_fc_tx_pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 pause->tx_pause = 1;
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700144 else if (hw->fc.type == ixgb_fc_full) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 pause->rx_pause = 1;
146 pause->tx_pause = 1;
147 }
148}
149
150static int
151ixgb_set_pauseparam(struct net_device *netdev,
152 struct ethtool_pauseparam *pause)
153{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700154 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 struct ixgb_hw *hw = &adapter->hw;
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700156
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700157 if (pause->autoneg == AUTONEG_ENABLE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 return -EINVAL;
159
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700160 if (pause->rx_pause && pause->tx_pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 hw->fc.type = ixgb_fc_full;
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700162 else if (pause->rx_pause && !pause->tx_pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 hw->fc.type = ixgb_fc_rx_pause;
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700164 else if (!pause->rx_pause && pause->tx_pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 hw->fc.type = ixgb_fc_tx_pause;
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700166 else if (!pause->rx_pause && !pause->tx_pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 hw->fc.type = ixgb_fc_none;
168
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700169 if (netif_running(adapter->netdev)) {
Joe Perches446490ca2008-03-21 11:06:37 -0700170 ixgb_down(adapter, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 ixgb_up(adapter);
Auke Kok4de17c82006-05-23 10:29:46 -0700172 ixgb_set_speed_duplex(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 } else
174 ixgb_reset(adapter);
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 return 0;
177}
178
Joe Perches222441a2008-04-03 10:06:25 -0700179static u32
Auke Kokec9c3f52006-05-23 10:34:59 -0700180ixgb_get_msglevel(struct net_device *netdev)
181{
Auke Kok25943072006-05-26 09:35:57 -0700182 struct ixgb_adapter *adapter = netdev_priv(netdev);
Auke Kokec9c3f52006-05-23 10:34:59 -0700183 return adapter->msg_enable;
184}
185
186static void
Joe Perches222441a2008-04-03 10:06:25 -0700187ixgb_set_msglevel(struct net_device *netdev, u32 data)
Auke Kokec9c3f52006-05-23 10:34:59 -0700188{
Auke Kok25943072006-05-26 09:35:57 -0700189 struct ixgb_adapter *adapter = netdev_priv(netdev);
Auke Kokec9c3f52006-05-23 10:34:59 -0700190 adapter->msg_enable = data;
191}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192#define IXGB_GET_STAT(_A_, _R_) _A_->stats._R_
193
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700194static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195ixgb_get_regs_len(struct net_device *netdev)
196{
Joe Perches222441a2008-04-03 10:06:25 -0700197#define IXGB_REG_DUMP_LEN 136*sizeof(u32)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 return IXGB_REG_DUMP_LEN;
199}
200
201static void
202ixgb_get_regs(struct net_device *netdev,
203 struct ethtool_regs *regs, void *p)
204{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700205 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 struct ixgb_hw *hw = &adapter->hw;
Joe Perches222441a2008-04-03 10:06:25 -0700207 u32 *reg = p;
208 u32 *reg_start = reg;
209 u8 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Malli Chilakala5e3c30d2005-04-28 19:04:07 -0700211 /* the 1 (one) below indicates an attempt at versioning, if the
Malli Chilakalaab707da2005-08-11 13:59:59 -0700212 * interface in ethtool or the driver changes, this 1 should be
213 * incremented */
Malli Chilakala5e3c30d2005-04-28 19:04:07 -0700214 regs->version = (1<<24) | hw->revision_id << 16 | hw->device_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216 /* General Registers */
217 *reg++ = IXGB_READ_REG(hw, CTRL0); /* 0 */
218 *reg++ = IXGB_READ_REG(hw, CTRL1); /* 1 */
219 *reg++ = IXGB_READ_REG(hw, STATUS); /* 2 */
220 *reg++ = IXGB_READ_REG(hw, EECD); /* 3 */
221 *reg++ = IXGB_READ_REG(hw, MFS); /* 4 */
222
223 /* Interrupt */
224 *reg++ = IXGB_READ_REG(hw, ICR); /* 5 */
225 *reg++ = IXGB_READ_REG(hw, ICS); /* 6 */
226 *reg++ = IXGB_READ_REG(hw, IMS); /* 7 */
227 *reg++ = IXGB_READ_REG(hw, IMC); /* 8 */
228
229 /* Receive */
230 *reg++ = IXGB_READ_REG(hw, RCTL); /* 9 */
231 *reg++ = IXGB_READ_REG(hw, FCRTL); /* 10 */
232 *reg++ = IXGB_READ_REG(hw, FCRTH); /* 11 */
233 *reg++ = IXGB_READ_REG(hw, RDBAL); /* 12 */
234 *reg++ = IXGB_READ_REG(hw, RDBAH); /* 13 */
235 *reg++ = IXGB_READ_REG(hw, RDLEN); /* 14 */
236 *reg++ = IXGB_READ_REG(hw, RDH); /* 15 */
237 *reg++ = IXGB_READ_REG(hw, RDT); /* 16 */
238 *reg++ = IXGB_READ_REG(hw, RDTR); /* 17 */
239 *reg++ = IXGB_READ_REG(hw, RXDCTL); /* 18 */
240 *reg++ = IXGB_READ_REG(hw, RAIDC); /* 19 */
241 *reg++ = IXGB_READ_REG(hw, RXCSUM); /* 20 */
242
Malli Chilakala9ef2eec2005-08-11 13:59:07 -0700243 /* there are 16 RAR entries in hardware, we only use 3 */
Jesse Brandeburg14593362008-07-08 15:52:33 -0700244 for (i = 0; i < IXGB_ALL_RAR_ENTRIES; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 *reg++ = IXGB_READ_REG_ARRAY(hw, RAL, (i << 1)); /*21,...,51 */
246 *reg++ = IXGB_READ_REG_ARRAY(hw, RAH, (i << 1)); /*22,...,52 */
247 }
248
249 /* Transmit */
250 *reg++ = IXGB_READ_REG(hw, TCTL); /* 53 */
251 *reg++ = IXGB_READ_REG(hw, TDBAL); /* 54 */
252 *reg++ = IXGB_READ_REG(hw, TDBAH); /* 55 */
253 *reg++ = IXGB_READ_REG(hw, TDLEN); /* 56 */
254 *reg++ = IXGB_READ_REG(hw, TDH); /* 57 */
255 *reg++ = IXGB_READ_REG(hw, TDT); /* 58 */
256 *reg++ = IXGB_READ_REG(hw, TIDV); /* 59 */
257 *reg++ = IXGB_READ_REG(hw, TXDCTL); /* 60 */
258 *reg++ = IXGB_READ_REG(hw, TSPMT); /* 61 */
259 *reg++ = IXGB_READ_REG(hw, PAP); /* 62 */
260
261 /* Physical */
262 *reg++ = IXGB_READ_REG(hw, PCSC1); /* 63 */
263 *reg++ = IXGB_READ_REG(hw, PCSC2); /* 64 */
264 *reg++ = IXGB_READ_REG(hw, PCSS1); /* 65 */
265 *reg++ = IXGB_READ_REG(hw, PCSS2); /* 66 */
266 *reg++ = IXGB_READ_REG(hw, XPCSS); /* 67 */
267 *reg++ = IXGB_READ_REG(hw, UCCR); /* 68 */
268 *reg++ = IXGB_READ_REG(hw, XPCSTC); /* 69 */
269 *reg++ = IXGB_READ_REG(hw, MACA); /* 70 */
270 *reg++ = IXGB_READ_REG(hw, APAE); /* 71 */
271 *reg++ = IXGB_READ_REG(hw, ARD); /* 72 */
272 *reg++ = IXGB_READ_REG(hw, AIS); /* 73 */
273 *reg++ = IXGB_READ_REG(hw, MSCA); /* 74 */
274 *reg++ = IXGB_READ_REG(hw, MSRWD); /* 75 */
275
276 /* Statistics */
277 *reg++ = IXGB_GET_STAT(adapter, tprl); /* 76 */
278 *reg++ = IXGB_GET_STAT(adapter, tprh); /* 77 */
279 *reg++ = IXGB_GET_STAT(adapter, gprcl); /* 78 */
280 *reg++ = IXGB_GET_STAT(adapter, gprch); /* 79 */
281 *reg++ = IXGB_GET_STAT(adapter, bprcl); /* 80 */
282 *reg++ = IXGB_GET_STAT(adapter, bprch); /* 81 */
283 *reg++ = IXGB_GET_STAT(adapter, mprcl); /* 82 */
284 *reg++ = IXGB_GET_STAT(adapter, mprch); /* 83 */
285 *reg++ = IXGB_GET_STAT(adapter, uprcl); /* 84 */
286 *reg++ = IXGB_GET_STAT(adapter, uprch); /* 85 */
287 *reg++ = IXGB_GET_STAT(adapter, vprcl); /* 86 */
288 *reg++ = IXGB_GET_STAT(adapter, vprch); /* 87 */
289 *reg++ = IXGB_GET_STAT(adapter, jprcl); /* 88 */
290 *reg++ = IXGB_GET_STAT(adapter, jprch); /* 89 */
291 *reg++ = IXGB_GET_STAT(adapter, gorcl); /* 90 */
292 *reg++ = IXGB_GET_STAT(adapter, gorch); /* 91 */
293 *reg++ = IXGB_GET_STAT(adapter, torl); /* 92 */
294 *reg++ = IXGB_GET_STAT(adapter, torh); /* 93 */
295 *reg++ = IXGB_GET_STAT(adapter, rnbc); /* 94 */
296 *reg++ = IXGB_GET_STAT(adapter, ruc); /* 95 */
297 *reg++ = IXGB_GET_STAT(adapter, roc); /* 96 */
298 *reg++ = IXGB_GET_STAT(adapter, rlec); /* 97 */
299 *reg++ = IXGB_GET_STAT(adapter, crcerrs); /* 98 */
300 *reg++ = IXGB_GET_STAT(adapter, icbc); /* 99 */
301 *reg++ = IXGB_GET_STAT(adapter, ecbc); /* 100 */
302 *reg++ = IXGB_GET_STAT(adapter, mpc); /* 101 */
303 *reg++ = IXGB_GET_STAT(adapter, tptl); /* 102 */
304 *reg++ = IXGB_GET_STAT(adapter, tpth); /* 103 */
305 *reg++ = IXGB_GET_STAT(adapter, gptcl); /* 104 */
306 *reg++ = IXGB_GET_STAT(adapter, gptch); /* 105 */
307 *reg++ = IXGB_GET_STAT(adapter, bptcl); /* 106 */
308 *reg++ = IXGB_GET_STAT(adapter, bptch); /* 107 */
309 *reg++ = IXGB_GET_STAT(adapter, mptcl); /* 108 */
310 *reg++ = IXGB_GET_STAT(adapter, mptch); /* 109 */
311 *reg++ = IXGB_GET_STAT(adapter, uptcl); /* 110 */
312 *reg++ = IXGB_GET_STAT(adapter, uptch); /* 111 */
313 *reg++ = IXGB_GET_STAT(adapter, vptcl); /* 112 */
314 *reg++ = IXGB_GET_STAT(adapter, vptch); /* 113 */
315 *reg++ = IXGB_GET_STAT(adapter, jptcl); /* 114 */
316 *reg++ = IXGB_GET_STAT(adapter, jptch); /* 115 */
317 *reg++ = IXGB_GET_STAT(adapter, gotcl); /* 116 */
318 *reg++ = IXGB_GET_STAT(adapter, gotch); /* 117 */
319 *reg++ = IXGB_GET_STAT(adapter, totl); /* 118 */
320 *reg++ = IXGB_GET_STAT(adapter, toth); /* 119 */
321 *reg++ = IXGB_GET_STAT(adapter, dc); /* 120 */
322 *reg++ = IXGB_GET_STAT(adapter, plt64c); /* 121 */
323 *reg++ = IXGB_GET_STAT(adapter, tsctc); /* 122 */
324 *reg++ = IXGB_GET_STAT(adapter, tsctfc); /* 123 */
325 *reg++ = IXGB_GET_STAT(adapter, ibic); /* 124 */
326 *reg++ = IXGB_GET_STAT(adapter, rfc); /* 125 */
327 *reg++ = IXGB_GET_STAT(adapter, lfc); /* 126 */
328 *reg++ = IXGB_GET_STAT(adapter, pfrc); /* 127 */
329 *reg++ = IXGB_GET_STAT(adapter, pftc); /* 128 */
330 *reg++ = IXGB_GET_STAT(adapter, mcfrc); /* 129 */
331 *reg++ = IXGB_GET_STAT(adapter, mcftc); /* 130 */
332 *reg++ = IXGB_GET_STAT(adapter, xonrxc); /* 131 */
333 *reg++ = IXGB_GET_STAT(adapter, xontxc); /* 132 */
334 *reg++ = IXGB_GET_STAT(adapter, xoffrxc); /* 133 */
335 *reg++ = IXGB_GET_STAT(adapter, xofftxc); /* 134 */
336 *reg++ = IXGB_GET_STAT(adapter, rjc); /* 135 */
337
Joe Perches222441a2008-04-03 10:06:25 -0700338 regs->len = (reg - reg_start) * sizeof(u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339}
340
341static int
342ixgb_get_eeprom_len(struct net_device *netdev)
343{
344 /* return size in bytes */
Eric Dumazet807540b2010-09-23 05:40:09 +0000345 return IXGB_EEPROM_SIZE << 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346}
347
348static int
349ixgb_get_eeprom(struct net_device *netdev,
Joe Perches222441a2008-04-03 10:06:25 -0700350 struct ethtool_eeprom *eeprom, u8 *bytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700352 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 struct ixgb_hw *hw = &adapter->hw;
Al Viroc6765042007-08-23 00:47:03 -0400354 __le16 *eeprom_buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 int i, max_len, first_word, last_word;
356 int ret_val = 0;
357
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700358 if (eeprom->len == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 ret_val = -EINVAL;
360 goto geeprom_error;
361 }
362
363 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
364
365 max_len = ixgb_get_eeprom_len(netdev);
366
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700367 if (eeprom->offset > eeprom->offset + eeprom->len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 ret_val = -EINVAL;
369 goto geeprom_error;
370 }
371
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700372 if ((eeprom->offset + eeprom->len) > max_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 eeprom->len = (max_len - eeprom->offset);
374
375 first_word = eeprom->offset >> 1;
376 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
377
Kees Cook6da2ec52018-06-12 13:55:00 -0700378 eeprom_buff = kmalloc_array(last_word - first_word + 1,
379 sizeof(__le16),
380 GFP_KERNEL);
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700381 if (!eeprom_buff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 return -ENOMEM;
383
384 /* note the eeprom was good because the driver loaded */
Jesse Brandeburg14593362008-07-08 15:52:33 -0700385 for (i = 0; i <= (last_word - first_word); i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 eeprom_buff[i] = ixgb_get_eeprom_word(hw, (first_word + i));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Jesse Brandeburg14593362008-07-08 15:52:33 -0700388 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 kfree(eeprom_buff);
390
391geeprom_error:
392 return ret_val;
393}
394
395static int
396ixgb_set_eeprom(struct net_device *netdev,
Joe Perches222441a2008-04-03 10:06:25 -0700397 struct ethtool_eeprom *eeprom, u8 *bytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700399 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 struct ixgb_hw *hw = &adapter->hw;
Joe Perches222441a2008-04-03 10:06:25 -0700401 u16 *eeprom_buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 void *ptr;
403 int max_len, first_word, last_word;
Joe Perches222441a2008-04-03 10:06:25 -0700404 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700406 if (eeprom->len == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 return -EINVAL;
408
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700409 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 return -EFAULT;
411
412 max_len = ixgb_get_eeprom_len(netdev);
413
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700414 if (eeprom->offset > eeprom->offset + eeprom->len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 return -EINVAL;
416
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700417 if ((eeprom->offset + eeprom->len) > max_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 eeprom->len = (max_len - eeprom->offset);
419
420 first_word = eeprom->offset >> 1;
421 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
422 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700423 if (!eeprom_buff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 return -ENOMEM;
425
426 ptr = (void *)eeprom_buff;
427
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700428 if (eeprom->offset & 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 /* need read/modify/write of first changed EEPROM word */
430 /* only the second byte of the word is being modified */
431 eeprom_buff[0] = ixgb_read_eeprom(hw, first_word);
432 ptr++;
433 }
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700434 if ((eeprom->offset + eeprom->len) & 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 /* need read/modify/write of last changed EEPROM word */
436 /* only the first byte of the word is being modified */
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700437 eeprom_buff[last_word - first_word]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 = ixgb_read_eeprom(hw, last_word);
439 }
440
441 memcpy(ptr, bytes, eeprom->len);
Jesse Brandeburg14593362008-07-08 15:52:33 -0700442 for (i = 0; i <= (last_word - first_word); i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 ixgb_write_eeprom(hw, first_word + i, eeprom_buff[i]);
444
445 /* Update the checksum over the first part of the EEPROM if needed */
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700446 if (first_word <= EEPROM_CHECKSUM_REG)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 ixgb_update_eeprom_checksum(hw);
448
449 kfree(eeprom_buff);
450 return 0;
451}
452
453static void
454ixgb_get_drvinfo(struct net_device *netdev,
455 struct ethtool_drvinfo *drvinfo)
456{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700457 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
Rick Jones612a94d2011-11-14 08:13:25 +0000459 strlcpy(drvinfo->driver, ixgb_driver_name,
460 sizeof(drvinfo->driver));
461 strlcpy(drvinfo->version, ixgb_driver_version,
462 sizeof(drvinfo->version));
Rick Jones612a94d2011-11-14 08:13:25 +0000463 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
464 sizeof(drvinfo->bus_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465}
466
467static void
468ixgb_get_ringparam(struct net_device *netdev,
469 struct ethtool_ringparam *ring)
470{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700471 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
473 struct ixgb_desc_ring *rxdr = &adapter->rx_ring;
474
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700475 ring->rx_max_pending = MAX_RXD;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 ring->tx_max_pending = MAX_TXD;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 ring->rx_pending = rxdr->count;
478 ring->tx_pending = txdr->count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479}
480
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700481static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482ixgb_set_ringparam(struct net_device *netdev,
483 struct ethtool_ringparam *ring)
484{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700485 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
487 struct ixgb_desc_ring *rxdr = &adapter->rx_ring;
488 struct ixgb_desc_ring tx_old, tx_new, rx_old, rx_new;
489 int err;
490
491 tx_old = adapter->tx_ring;
492 rx_old = adapter->rx_ring;
493
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700494 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 return -EINVAL;
496
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700497 if (netif_running(adapter->netdev))
Joe Perches446490ca2008-03-21 11:06:37 -0700498 ixgb_down(adapter, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
Joe Perches222441a2008-04-03 10:06:25 -0700500 rxdr->count = max(ring->rx_pending,(u32)MIN_RXD);
501 rxdr->count = min(rxdr->count,(u32)MAX_RXD);
Milind Arun Choudhary55e924c2007-04-27 13:55:31 -0700502 rxdr->count = ALIGN(rxdr->count, IXGB_REQ_RX_DESCRIPTOR_MULTIPLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Joe Perches222441a2008-04-03 10:06:25 -0700504 txdr->count = max(ring->tx_pending,(u32)MIN_TXD);
505 txdr->count = min(txdr->count,(u32)MAX_TXD);
Milind Arun Choudhary55e924c2007-04-27 13:55:31 -0700506 txdr->count = ALIGN(txdr->count, IXGB_REQ_TX_DESCRIPTOR_MULTIPLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700508 if (netif_running(adapter->netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 /* Try to get new resources before deleting old */
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700510 if ((err = ixgb_setup_rx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 goto err_setup_rx;
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700512 if ((err = ixgb_setup_tx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 goto err_setup_tx;
514
515 /* save the new, restore the old in order to free it,
516 * then restore the new back again */
517
518 rx_new = adapter->rx_ring;
519 tx_new = adapter->tx_ring;
520 adapter->rx_ring = rx_old;
521 adapter->tx_ring = tx_old;
522 ixgb_free_rx_resources(adapter);
523 ixgb_free_tx_resources(adapter);
524 adapter->rx_ring = rx_new;
525 adapter->tx_ring = tx_new;
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700526 if ((err = ixgb_up(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 return err;
Auke Kok4de17c82006-05-23 10:29:46 -0700528 ixgb_set_speed_duplex(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 }
530
531 return 0;
532err_setup_tx:
533 ixgb_free_rx_resources(adapter);
534err_setup_rx:
535 adapter->rx_ring = rx_old;
536 adapter->tx_ring = tx_old;
537 ixgb_up(adapter);
538 return err;
539}
540
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541static int
Jeff Kirsherec7e97e2011-05-03 05:17:34 +0000542ixgb_set_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700544 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Jeff Kirsherec7e97e2011-05-03 05:17:34 +0000546 switch (state) {
547 case ETHTOOL_ID_ACTIVE:
548 return 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Jeff Kirsherec7e97e2011-05-03 05:17:34 +0000550 case ETHTOOL_ID_ON:
551 ixgb_led_on(&adapter->hw);
552 break;
553
554 case ETHTOOL_ID_OFF:
555 case ETHTOOL_ID_INACTIVE:
556 ixgb_led_off(&adapter->hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 }
558
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 return 0;
560}
561
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700562static int
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700563ixgb_get_sset_count(struct net_device *netdev, int sset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700565 switch (sset) {
566 case ETH_SS_STATS:
567 return IXGB_STATS_LEN;
568 default:
569 return -EOPNOTSUPP;
570 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571}
572
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700573static void
574ixgb_get_ethtool_stats(struct net_device *netdev,
Joe Perches222441a2008-04-03 10:06:25 -0700575 struct ethtool_stats *stats, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700577 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 int i;
Ajit Khaparded189a7e2009-10-13 01:46:56 +0000579 char *p = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
581 ixgb_update_stats(adapter);
Jesse Brandeburg14593362008-07-08 15:52:33 -0700582 for (i = 0; i < IXGB_STATS_LEN; i++) {
Ajit Khaparded189a7e2009-10-13 01:46:56 +0000583 switch (ixgb_gstrings_stats[i].type) {
584 case NETDEV_STATS:
585 p = (char *) netdev +
586 ixgb_gstrings_stats[i].stat_offset;
587 break;
588 case IXGB_STATS:
589 p = (char *) adapter +
590 ixgb_gstrings_stats[i].stat_offset;
591 break;
592 }
593
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700594 data[i] = (ixgb_gstrings_stats[i].sizeof_stat ==
Joe Perches222441a2008-04-03 10:06:25 -0700595 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 }
597}
598
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700599static void
Joe Perches222441a2008-04-03 10:06:25 -0700600ixgb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601{
602 int i;
603
604 switch(stringset) {
605 case ETH_SS_STATS:
Jesse Brandeburg14593362008-07-08 15:52:33 -0700606 for (i = 0; i < IXGB_STATS_LEN; i++) {
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700607 memcpy(data + i * ETH_GSTRING_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 ixgb_gstrings_stats[i].stat_string,
609 ETH_GSTRING_LEN);
610 }
611 break;
612 }
613}
614
Jeff Garzik7282d492006-09-13 14:30:00 -0400615static const struct ethtool_ops ixgb_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 .get_drvinfo = ixgb_get_drvinfo,
617 .get_regs_len = ixgb_get_regs_len,
618 .get_regs = ixgb_get_regs,
619 .get_link = ethtool_op_get_link,
620 .get_eeprom_len = ixgb_get_eeprom_len,
621 .get_eeprom = ixgb_get_eeprom,
622 .set_eeprom = ixgb_set_eeprom,
623 .get_ringparam = ixgb_get_ringparam,
624 .set_ringparam = ixgb_set_ringparam,
625 .get_pauseparam = ixgb_get_pauseparam,
626 .set_pauseparam = ixgb_set_pauseparam,
Auke Kokec9c3f52006-05-23 10:34:59 -0700627 .get_msglevel = ixgb_get_msglevel,
628 .set_msglevel = ixgb_set_msglevel,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 .get_strings = ixgb_get_strings,
Jeff Kirsherec7e97e2011-05-03 05:17:34 +0000630 .set_phys_id = ixgb_set_phys_id,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700631 .get_sset_count = ixgb_get_sset_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 .get_ethtool_stats = ixgb_get_ethtool_stats,
Philippe Reynesf22913d2017-02-06 00:11:11 +0100633 .get_link_ksettings = ixgb_get_link_ksettings,
634 .set_link_ksettings = ixgb_set_link_ksettings,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635};
636
637void ixgb_set_ethtool_ops(struct net_device *netdev)
638{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +0000639 netdev->ethtool_ops = &ixgb_ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640}