blob: 5b354e3122c419655b8dd703bd165d597b730026 [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
4 Copyright(c) 1999 - 2006 Intel Corporation.
5
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070037struct ixgb_stats {
38 char stat_string[ETH_GSTRING_LEN];
39 int sizeof_stat;
40 int stat_offset;
41};
42
Julia Lawall030ed682008-02-11 09:25:40 -080043#define IXGB_STAT(m) FIELD_SIZEOF(struct ixgb_adapter, m), \
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 offsetof(struct ixgb_adapter, m)
45static struct ixgb_stats ixgb_gstrings_stats[] = {
46 {"rx_packets", IXGB_STAT(net_stats.rx_packets)},
47 {"tx_packets", IXGB_STAT(net_stats.tx_packets)},
48 {"rx_bytes", IXGB_STAT(net_stats.rx_bytes)},
49 {"tx_bytes", IXGB_STAT(net_stats.tx_bytes)},
50 {"rx_errors", IXGB_STAT(net_stats.rx_errors)},
51 {"tx_errors", IXGB_STAT(net_stats.tx_errors)},
52 {"rx_dropped", IXGB_STAT(net_stats.rx_dropped)},
53 {"tx_dropped", IXGB_STAT(net_stats.tx_dropped)},
54 {"multicast", IXGB_STAT(net_stats.multicast)},
55 {"collisions", IXGB_STAT(net_stats.collisions)},
56
57/* { "rx_length_errors", IXGB_STAT(net_stats.rx_length_errors) }, */
58 {"rx_over_errors", IXGB_STAT(net_stats.rx_over_errors)},
59 {"rx_crc_errors", IXGB_STAT(net_stats.rx_crc_errors)},
60 {"rx_frame_errors", IXGB_STAT(net_stats.rx_frame_errors)},
Auke Kokac0b3502008-02-21 15:10:41 -080061 {"rx_no_buffer_count", IXGB_STAT(stats.rnbc)},
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 {"rx_fifo_errors", IXGB_STAT(net_stats.rx_fifo_errors)},
63 {"rx_missed_errors", IXGB_STAT(net_stats.rx_missed_errors)},
64 {"tx_aborted_errors", IXGB_STAT(net_stats.tx_aborted_errors)},
65 {"tx_carrier_errors", IXGB_STAT(net_stats.tx_carrier_errors)},
66 {"tx_fifo_errors", IXGB_STAT(net_stats.tx_fifo_errors)},
67 {"tx_heartbeat_errors", IXGB_STAT(net_stats.tx_heartbeat_errors)},
68 {"tx_window_errors", IXGB_STAT(net_stats.tx_window_errors)},
69 {"tx_deferred_ok", IXGB_STAT(stats.dc)},
Auke Kok9b8118d2006-05-23 10:35:04 -070070 {"tx_timeout_count", IXGB_STAT(tx_timeout_count) },
Jesse Brandeburgdfd341e2007-01-06 09:51:38 -080071 {"tx_restart_queue", IXGB_STAT(restart_queue) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 {"rx_long_length_errors", IXGB_STAT(stats.roc)},
73 {"rx_short_length_errors", IXGB_STAT(stats.ruc)},
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 {"tx_tcp_seg_good", IXGB_STAT(stats.tsctc)},
75 {"tx_tcp_seg_failed", IXGB_STAT(stats.tsctfc)},
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 {"rx_flow_control_xon", IXGB_STAT(stats.xonrxc)},
77 {"rx_flow_control_xoff", IXGB_STAT(stats.xoffrxc)},
78 {"tx_flow_control_xon", IXGB_STAT(stats.xontxc)},
79 {"tx_flow_control_xoff", IXGB_STAT(stats.xofftxc)},
80 {"rx_csum_offload_good", IXGB_STAT(hw_csum_rx_good)},
81 {"rx_csum_offload_errors", IXGB_STAT(hw_csum_rx_error)},
82 {"tx_csum_offload_good", IXGB_STAT(hw_csum_tx_good)},
83 {"tx_csum_offload_errors", IXGB_STAT(hw_csum_tx_error)}
84};
85
Denis Chengff8ac602007-09-02 18:30:18 +080086#define IXGB_STATS_LEN ARRAY_SIZE(ixgb_gstrings_stats)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88static int
89ixgb_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
90{
Malli Chilakala8908c6c2005-08-11 13:58:40 -070091 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
Malli Chilakaladb0baca2005-08-11 13:59:20 -070094 ecmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 ecmd->port = PORT_FIBRE;
96 ecmd->transceiver = XCVR_EXTERNAL;
97
Jesse Brandeburg03f83042008-07-08 15:52:13 -070098 if (netif_carrier_ok(adapter->netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 ecmd->speed = SPEED_10000;
100 ecmd->duplex = DUPLEX_FULL;
101 } else {
102 ecmd->speed = -1;
103 ecmd->duplex = -1;
104 }
105
106 ecmd->autoneg = AUTONEG_DISABLE;
107 return 0;
108}
109
Auke Kok4de17c82006-05-23 10:29:46 -0700110static void ixgb_set_speed_duplex(struct net_device *netdev)
111{
112 struct ixgb_adapter *adapter = netdev_priv(netdev);
113 /* be optimistic about our link, since we were up before */
114 adapter->link_speed = 10000;
115 adapter->link_duplex = FULL_DUPLEX;
116 netif_carrier_on(netdev);
117 netif_wake_queue(netdev);
118}
119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120static int
121ixgb_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
122{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700123 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700125 if (ecmd->autoneg == AUTONEG_ENABLE ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 ecmd->speed + ecmd->duplex != SPEED_10000 + DUPLEX_FULL)
127 return -EINVAL;
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700128
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700129 if (netif_running(adapter->netdev)) {
Joe Perches446490c2008-03-21 11:06:37 -0700130 ixgb_down(adapter, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 ixgb_reset(adapter);
132 ixgb_up(adapter);
Auke Kok4de17c82006-05-23 10:29:46 -0700133 ixgb_set_speed_duplex(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 } else
135 ixgb_reset(adapter);
136
137 return 0;
138}
139
140static void
141ixgb_get_pauseparam(struct net_device *netdev,
142 struct ethtool_pauseparam *pause)
143{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700144 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 struct ixgb_hw *hw = &adapter->hw;
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 pause->autoneg = AUTONEG_DISABLE;
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700148
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700149 if (hw->fc.type == ixgb_fc_rx_pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 pause->rx_pause = 1;
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700151 else if (hw->fc.type == ixgb_fc_tx_pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 pause->tx_pause = 1;
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700153 else if (hw->fc.type == ixgb_fc_full) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 pause->rx_pause = 1;
155 pause->tx_pause = 1;
156 }
157}
158
159static int
160ixgb_set_pauseparam(struct net_device *netdev,
161 struct ethtool_pauseparam *pause)
162{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700163 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 struct ixgb_hw *hw = &adapter->hw;
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700165
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700166 if (pause->autoneg == AUTONEG_ENABLE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 return -EINVAL;
168
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700169 if (pause->rx_pause && pause->tx_pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 hw->fc.type = ixgb_fc_full;
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700171 else if (pause->rx_pause && !pause->tx_pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 hw->fc.type = ixgb_fc_rx_pause;
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700173 else if (!pause->rx_pause && pause->tx_pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 hw->fc.type = ixgb_fc_tx_pause;
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700175 else if (!pause->rx_pause && !pause->tx_pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 hw->fc.type = ixgb_fc_none;
177
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700178 if (netif_running(adapter->netdev)) {
Joe Perches446490c2008-03-21 11:06:37 -0700179 ixgb_down(adapter, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 ixgb_up(adapter);
Auke Kok4de17c82006-05-23 10:29:46 -0700181 ixgb_set_speed_duplex(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 } else
183 ixgb_reset(adapter);
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 return 0;
186}
187
Joe Perches222441a2008-04-03 10:06:25 -0700188static u32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189ixgb_get_rx_csum(struct net_device *netdev)
190{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700191 struct ixgb_adapter *adapter = netdev_priv(netdev);
192
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 return adapter->rx_csum;
194}
195
196static int
Joe Perches222441a2008-04-03 10:06:25 -0700197ixgb_set_rx_csum(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700199 struct ixgb_adapter *adapter = netdev_priv(netdev);
200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 adapter->rx_csum = data;
202
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700203 if (netif_running(netdev)) {
Joe Perches446490c2008-03-21 11:06:37 -0700204 ixgb_down(adapter, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 ixgb_up(adapter);
Auke Kok4de17c82006-05-23 10:29:46 -0700206 ixgb_set_speed_duplex(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 } else
208 ixgb_reset(adapter);
209 return 0;
210}
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700211
Joe Perches222441a2008-04-03 10:06:25 -0700212static u32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213ixgb_get_tx_csum(struct net_device *netdev)
214{
215 return (netdev->features & NETIF_F_HW_CSUM) != 0;
216}
217
218static int
Joe Perches222441a2008-04-03 10:06:25 -0700219ixgb_set_tx_csum(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
221 if (data)
222 netdev->features |= NETIF_F_HW_CSUM;
223 else
224 netdev->features &= ~NETIF_F_HW_CSUM;
225
226 return 0;
227}
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229static int
Joe Perches222441a2008-04-03 10:06:25 -0700230ixgb_set_tso(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700232 if (data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 netdev->features |= NETIF_F_TSO;
234 else
235 netdev->features &= ~NETIF_F_TSO;
236 return 0;
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700237}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Joe Perches222441a2008-04-03 10:06:25 -0700239static u32
Auke Kokec9c3f52006-05-23 10:34:59 -0700240ixgb_get_msglevel(struct net_device *netdev)
241{
Auke Kok25943072006-05-26 09:35:57 -0700242 struct ixgb_adapter *adapter = netdev_priv(netdev);
Auke Kokec9c3f52006-05-23 10:34:59 -0700243 return adapter->msg_enable;
244}
245
246static void
Joe Perches222441a2008-04-03 10:06:25 -0700247ixgb_set_msglevel(struct net_device *netdev, u32 data)
Auke Kokec9c3f52006-05-23 10:34:59 -0700248{
Auke Kok25943072006-05-26 09:35:57 -0700249 struct ixgb_adapter *adapter = netdev_priv(netdev);
Auke Kokec9c3f52006-05-23 10:34:59 -0700250 adapter->msg_enable = data;
251}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252#define IXGB_GET_STAT(_A_, _R_) _A_->stats._R_
253
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700254static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255ixgb_get_regs_len(struct net_device *netdev)
256{
Joe Perches222441a2008-04-03 10:06:25 -0700257#define IXGB_REG_DUMP_LEN 136*sizeof(u32)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 return IXGB_REG_DUMP_LEN;
259}
260
261static void
262ixgb_get_regs(struct net_device *netdev,
263 struct ethtool_regs *regs, void *p)
264{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700265 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 struct ixgb_hw *hw = &adapter->hw;
Joe Perches222441a2008-04-03 10:06:25 -0700267 u32 *reg = p;
268 u32 *reg_start = reg;
269 u8 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
Malli Chilakala5e3c30d2005-04-28 19:04:07 -0700271 /* the 1 (one) below indicates an attempt at versioning, if the
Malli Chilakalaab707da2005-08-11 13:59:59 -0700272 * interface in ethtool or the driver changes, this 1 should be
273 * incremented */
Malli Chilakala5e3c30d2005-04-28 19:04:07 -0700274 regs->version = (1<<24) | hw->revision_id << 16 | hw->device_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
276 /* General Registers */
277 *reg++ = IXGB_READ_REG(hw, CTRL0); /* 0 */
278 *reg++ = IXGB_READ_REG(hw, CTRL1); /* 1 */
279 *reg++ = IXGB_READ_REG(hw, STATUS); /* 2 */
280 *reg++ = IXGB_READ_REG(hw, EECD); /* 3 */
281 *reg++ = IXGB_READ_REG(hw, MFS); /* 4 */
282
283 /* Interrupt */
284 *reg++ = IXGB_READ_REG(hw, ICR); /* 5 */
285 *reg++ = IXGB_READ_REG(hw, ICS); /* 6 */
286 *reg++ = IXGB_READ_REG(hw, IMS); /* 7 */
287 *reg++ = IXGB_READ_REG(hw, IMC); /* 8 */
288
289 /* Receive */
290 *reg++ = IXGB_READ_REG(hw, RCTL); /* 9 */
291 *reg++ = IXGB_READ_REG(hw, FCRTL); /* 10 */
292 *reg++ = IXGB_READ_REG(hw, FCRTH); /* 11 */
293 *reg++ = IXGB_READ_REG(hw, RDBAL); /* 12 */
294 *reg++ = IXGB_READ_REG(hw, RDBAH); /* 13 */
295 *reg++ = IXGB_READ_REG(hw, RDLEN); /* 14 */
296 *reg++ = IXGB_READ_REG(hw, RDH); /* 15 */
297 *reg++ = IXGB_READ_REG(hw, RDT); /* 16 */
298 *reg++ = IXGB_READ_REG(hw, RDTR); /* 17 */
299 *reg++ = IXGB_READ_REG(hw, RXDCTL); /* 18 */
300 *reg++ = IXGB_READ_REG(hw, RAIDC); /* 19 */
301 *reg++ = IXGB_READ_REG(hw, RXCSUM); /* 20 */
302
Malli Chilakala9ef2eec2005-08-11 13:59:07 -0700303 /* there are 16 RAR entries in hardware, we only use 3 */
Auke Kokc85fd6f2006-05-23 10:30:02 -0700304 for(i = 0; i < IXGB_ALL_RAR_ENTRIES; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 *reg++ = IXGB_READ_REG_ARRAY(hw, RAL, (i << 1)); /*21,...,51 */
306 *reg++ = IXGB_READ_REG_ARRAY(hw, RAH, (i << 1)); /*22,...,52 */
307 }
308
309 /* Transmit */
310 *reg++ = IXGB_READ_REG(hw, TCTL); /* 53 */
311 *reg++ = IXGB_READ_REG(hw, TDBAL); /* 54 */
312 *reg++ = IXGB_READ_REG(hw, TDBAH); /* 55 */
313 *reg++ = IXGB_READ_REG(hw, TDLEN); /* 56 */
314 *reg++ = IXGB_READ_REG(hw, TDH); /* 57 */
315 *reg++ = IXGB_READ_REG(hw, TDT); /* 58 */
316 *reg++ = IXGB_READ_REG(hw, TIDV); /* 59 */
317 *reg++ = IXGB_READ_REG(hw, TXDCTL); /* 60 */
318 *reg++ = IXGB_READ_REG(hw, TSPMT); /* 61 */
319 *reg++ = IXGB_READ_REG(hw, PAP); /* 62 */
320
321 /* Physical */
322 *reg++ = IXGB_READ_REG(hw, PCSC1); /* 63 */
323 *reg++ = IXGB_READ_REG(hw, PCSC2); /* 64 */
324 *reg++ = IXGB_READ_REG(hw, PCSS1); /* 65 */
325 *reg++ = IXGB_READ_REG(hw, PCSS2); /* 66 */
326 *reg++ = IXGB_READ_REG(hw, XPCSS); /* 67 */
327 *reg++ = IXGB_READ_REG(hw, UCCR); /* 68 */
328 *reg++ = IXGB_READ_REG(hw, XPCSTC); /* 69 */
329 *reg++ = IXGB_READ_REG(hw, MACA); /* 70 */
330 *reg++ = IXGB_READ_REG(hw, APAE); /* 71 */
331 *reg++ = IXGB_READ_REG(hw, ARD); /* 72 */
332 *reg++ = IXGB_READ_REG(hw, AIS); /* 73 */
333 *reg++ = IXGB_READ_REG(hw, MSCA); /* 74 */
334 *reg++ = IXGB_READ_REG(hw, MSRWD); /* 75 */
335
336 /* Statistics */
337 *reg++ = IXGB_GET_STAT(adapter, tprl); /* 76 */
338 *reg++ = IXGB_GET_STAT(adapter, tprh); /* 77 */
339 *reg++ = IXGB_GET_STAT(adapter, gprcl); /* 78 */
340 *reg++ = IXGB_GET_STAT(adapter, gprch); /* 79 */
341 *reg++ = IXGB_GET_STAT(adapter, bprcl); /* 80 */
342 *reg++ = IXGB_GET_STAT(adapter, bprch); /* 81 */
343 *reg++ = IXGB_GET_STAT(adapter, mprcl); /* 82 */
344 *reg++ = IXGB_GET_STAT(adapter, mprch); /* 83 */
345 *reg++ = IXGB_GET_STAT(adapter, uprcl); /* 84 */
346 *reg++ = IXGB_GET_STAT(adapter, uprch); /* 85 */
347 *reg++ = IXGB_GET_STAT(adapter, vprcl); /* 86 */
348 *reg++ = IXGB_GET_STAT(adapter, vprch); /* 87 */
349 *reg++ = IXGB_GET_STAT(adapter, jprcl); /* 88 */
350 *reg++ = IXGB_GET_STAT(adapter, jprch); /* 89 */
351 *reg++ = IXGB_GET_STAT(adapter, gorcl); /* 90 */
352 *reg++ = IXGB_GET_STAT(adapter, gorch); /* 91 */
353 *reg++ = IXGB_GET_STAT(adapter, torl); /* 92 */
354 *reg++ = IXGB_GET_STAT(adapter, torh); /* 93 */
355 *reg++ = IXGB_GET_STAT(adapter, rnbc); /* 94 */
356 *reg++ = IXGB_GET_STAT(adapter, ruc); /* 95 */
357 *reg++ = IXGB_GET_STAT(adapter, roc); /* 96 */
358 *reg++ = IXGB_GET_STAT(adapter, rlec); /* 97 */
359 *reg++ = IXGB_GET_STAT(adapter, crcerrs); /* 98 */
360 *reg++ = IXGB_GET_STAT(adapter, icbc); /* 99 */
361 *reg++ = IXGB_GET_STAT(adapter, ecbc); /* 100 */
362 *reg++ = IXGB_GET_STAT(adapter, mpc); /* 101 */
363 *reg++ = IXGB_GET_STAT(adapter, tptl); /* 102 */
364 *reg++ = IXGB_GET_STAT(adapter, tpth); /* 103 */
365 *reg++ = IXGB_GET_STAT(adapter, gptcl); /* 104 */
366 *reg++ = IXGB_GET_STAT(adapter, gptch); /* 105 */
367 *reg++ = IXGB_GET_STAT(adapter, bptcl); /* 106 */
368 *reg++ = IXGB_GET_STAT(adapter, bptch); /* 107 */
369 *reg++ = IXGB_GET_STAT(adapter, mptcl); /* 108 */
370 *reg++ = IXGB_GET_STAT(adapter, mptch); /* 109 */
371 *reg++ = IXGB_GET_STAT(adapter, uptcl); /* 110 */
372 *reg++ = IXGB_GET_STAT(adapter, uptch); /* 111 */
373 *reg++ = IXGB_GET_STAT(adapter, vptcl); /* 112 */
374 *reg++ = IXGB_GET_STAT(adapter, vptch); /* 113 */
375 *reg++ = IXGB_GET_STAT(adapter, jptcl); /* 114 */
376 *reg++ = IXGB_GET_STAT(adapter, jptch); /* 115 */
377 *reg++ = IXGB_GET_STAT(adapter, gotcl); /* 116 */
378 *reg++ = IXGB_GET_STAT(adapter, gotch); /* 117 */
379 *reg++ = IXGB_GET_STAT(adapter, totl); /* 118 */
380 *reg++ = IXGB_GET_STAT(adapter, toth); /* 119 */
381 *reg++ = IXGB_GET_STAT(adapter, dc); /* 120 */
382 *reg++ = IXGB_GET_STAT(adapter, plt64c); /* 121 */
383 *reg++ = IXGB_GET_STAT(adapter, tsctc); /* 122 */
384 *reg++ = IXGB_GET_STAT(adapter, tsctfc); /* 123 */
385 *reg++ = IXGB_GET_STAT(adapter, ibic); /* 124 */
386 *reg++ = IXGB_GET_STAT(adapter, rfc); /* 125 */
387 *reg++ = IXGB_GET_STAT(adapter, lfc); /* 126 */
388 *reg++ = IXGB_GET_STAT(adapter, pfrc); /* 127 */
389 *reg++ = IXGB_GET_STAT(adapter, pftc); /* 128 */
390 *reg++ = IXGB_GET_STAT(adapter, mcfrc); /* 129 */
391 *reg++ = IXGB_GET_STAT(adapter, mcftc); /* 130 */
392 *reg++ = IXGB_GET_STAT(adapter, xonrxc); /* 131 */
393 *reg++ = IXGB_GET_STAT(adapter, xontxc); /* 132 */
394 *reg++ = IXGB_GET_STAT(adapter, xoffrxc); /* 133 */
395 *reg++ = IXGB_GET_STAT(adapter, xofftxc); /* 134 */
396 *reg++ = IXGB_GET_STAT(adapter, rjc); /* 135 */
397
Joe Perches222441a2008-04-03 10:06:25 -0700398 regs->len = (reg - reg_start) * sizeof(u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399}
400
401static int
402ixgb_get_eeprom_len(struct net_device *netdev)
403{
404 /* return size in bytes */
405 return (IXGB_EEPROM_SIZE << 1);
406}
407
408static int
409ixgb_get_eeprom(struct net_device *netdev,
Joe Perches222441a2008-04-03 10:06:25 -0700410 struct ethtool_eeprom *eeprom, u8 *bytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700412 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 struct ixgb_hw *hw = &adapter->hw;
Al Viroc6765042007-08-23 00:47:03 -0400414 __le16 *eeprom_buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 int i, max_len, first_word, last_word;
416 int ret_val = 0;
417
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700418 if (eeprom->len == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 ret_val = -EINVAL;
420 goto geeprom_error;
421 }
422
423 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
424
425 max_len = ixgb_get_eeprom_len(netdev);
426
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700427 if (eeprom->offset > eeprom->offset + eeprom->len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 ret_val = -EINVAL;
429 goto geeprom_error;
430 }
431
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700432 if ((eeprom->offset + eeprom->len) > max_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 eeprom->len = (max_len - eeprom->offset);
434
435 first_word = eeprom->offset >> 1;
436 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
437
Al Viroc6765042007-08-23 00:47:03 -0400438 eeprom_buff = kmalloc(sizeof(__le16) *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 (last_word - first_word + 1), 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 /* note the eeprom was good because the driver loaded */
444 for(i = 0; i <= (last_word - first_word); i++) {
445 eeprom_buff[i] = ixgb_get_eeprom_word(hw, (first_word + i));
446 }
447
Joe Perches222441a2008-04-03 10:06:25 -0700448 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 eeprom->len);
450 kfree(eeprom_buff);
451
452geeprom_error:
453 return ret_val;
454}
455
456static int
457ixgb_set_eeprom(struct net_device *netdev,
Joe Perches222441a2008-04-03 10:06:25 -0700458 struct ethtool_eeprom *eeprom, u8 *bytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700460 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 struct ixgb_hw *hw = &adapter->hw;
Joe Perches222441a2008-04-03 10:06:25 -0700462 u16 *eeprom_buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 void *ptr;
464 int max_len, first_word, last_word;
Joe Perches222441a2008-04-03 10:06:25 -0700465 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700467 if (eeprom->len == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 return -EINVAL;
469
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700470 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 return -EFAULT;
472
473 max_len = ixgb_get_eeprom_len(netdev);
474
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700475 if (eeprom->offset > eeprom->offset + eeprom->len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 return -EINVAL;
477
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700478 if ((eeprom->offset + eeprom->len) > max_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 eeprom->len = (max_len - eeprom->offset);
480
481 first_word = eeprom->offset >> 1;
482 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
483 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700484 if (!eeprom_buff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 return -ENOMEM;
486
487 ptr = (void *)eeprom_buff;
488
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700489 if (eeprom->offset & 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 /* need read/modify/write of first changed EEPROM word */
491 /* only the second byte of the word is being modified */
492 eeprom_buff[0] = ixgb_read_eeprom(hw, first_word);
493 ptr++;
494 }
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700495 if ((eeprom->offset + eeprom->len) & 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 /* need read/modify/write of last changed EEPROM word */
497 /* only the first byte of the word is being modified */
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700498 eeprom_buff[last_word - first_word]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 = ixgb_read_eeprom(hw, last_word);
500 }
501
502 memcpy(ptr, bytes, eeprom->len);
503 for(i = 0; i <= (last_word - first_word); i++)
504 ixgb_write_eeprom(hw, first_word + i, eeprom_buff[i]);
505
506 /* Update the checksum over the first part of the EEPROM if needed */
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700507 if (first_word <= EEPROM_CHECKSUM_REG)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 ixgb_update_eeprom_checksum(hw);
509
510 kfree(eeprom_buff);
511 return 0;
512}
513
514static void
515ixgb_get_drvinfo(struct net_device *netdev,
516 struct ethtool_drvinfo *drvinfo)
517{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700518 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
520 strncpy(drvinfo->driver, ixgb_driver_name, 32);
521 strncpy(drvinfo->version, ixgb_driver_version, 32);
522 strncpy(drvinfo->fw_version, "N/A", 32);
523 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
524 drvinfo->n_stats = IXGB_STATS_LEN;
525 drvinfo->regdump_len = ixgb_get_regs_len(netdev);
526 drvinfo->eedump_len = ixgb_get_eeprom_len(netdev);
527}
528
529static void
530ixgb_get_ringparam(struct net_device *netdev,
531 struct ethtool_ringparam *ring)
532{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700533 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
535 struct ixgb_desc_ring *rxdr = &adapter->rx_ring;
536
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700537 ring->rx_max_pending = MAX_RXD;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 ring->tx_max_pending = MAX_TXD;
539 ring->rx_mini_max_pending = 0;
540 ring->rx_jumbo_max_pending = 0;
541 ring->rx_pending = rxdr->count;
542 ring->tx_pending = txdr->count;
543 ring->rx_mini_pending = 0;
544 ring->rx_jumbo_pending = 0;
545}
546
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700547static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548ixgb_set_ringparam(struct net_device *netdev,
549 struct ethtool_ringparam *ring)
550{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700551 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
553 struct ixgb_desc_ring *rxdr = &adapter->rx_ring;
554 struct ixgb_desc_ring tx_old, tx_new, rx_old, rx_new;
555 int err;
556
557 tx_old = adapter->tx_ring;
558 rx_old = adapter->rx_ring;
559
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700560 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 return -EINVAL;
562
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700563 if (netif_running(adapter->netdev))
Joe Perches446490c2008-03-21 11:06:37 -0700564 ixgb_down(adapter, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Joe Perches222441a2008-04-03 10:06:25 -0700566 rxdr->count = max(ring->rx_pending,(u32)MIN_RXD);
567 rxdr->count = min(rxdr->count,(u32)MAX_RXD);
Milind Arun Choudhary55e924c2007-04-27 13:55:31 -0700568 rxdr->count = ALIGN(rxdr->count, IXGB_REQ_RX_DESCRIPTOR_MULTIPLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
Joe Perches222441a2008-04-03 10:06:25 -0700570 txdr->count = max(ring->tx_pending,(u32)MIN_TXD);
571 txdr->count = min(txdr->count,(u32)MAX_TXD);
Milind Arun Choudhary55e924c2007-04-27 13:55:31 -0700572 txdr->count = ALIGN(txdr->count, IXGB_REQ_TX_DESCRIPTOR_MULTIPLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700574 if (netif_running(adapter->netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 /* Try to get new resources before deleting old */
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700576 if ((err = ixgb_setup_rx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 goto err_setup_rx;
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700578 if ((err = ixgb_setup_tx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 goto err_setup_tx;
580
581 /* save the new, restore the old in order to free it,
582 * then restore the new back again */
583
584 rx_new = adapter->rx_ring;
585 tx_new = adapter->tx_ring;
586 adapter->rx_ring = rx_old;
587 adapter->tx_ring = tx_old;
588 ixgb_free_rx_resources(adapter);
589 ixgb_free_tx_resources(adapter);
590 adapter->rx_ring = rx_new;
591 adapter->tx_ring = tx_new;
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700592 if ((err = ixgb_up(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 return err;
Auke Kok4de17c82006-05-23 10:29:46 -0700594 ixgb_set_speed_duplex(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 }
596
597 return 0;
598err_setup_tx:
599 ixgb_free_rx_resources(adapter);
600err_setup_rx:
601 adapter->rx_ring = rx_old;
602 adapter->tx_ring = tx_old;
603 ixgb_up(adapter);
604 return err;
605}
606
607/* toggle LED 4 times per second = 2 "blinks" per second */
608#define IXGB_ID_INTERVAL (HZ/4)
609
610/* bit defines for adapter->led_status */
611#define IXGB_LED_ON 0
612
613static void
614ixgb_led_blink_callback(unsigned long data)
615{
616 struct ixgb_adapter *adapter = (struct ixgb_adapter *)data;
617
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700618 if (test_and_change_bit(IXGB_LED_ON, &adapter->led_status))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 ixgb_led_off(&adapter->hw);
620 else
621 ixgb_led_on(&adapter->hw);
622
623 mod_timer(&adapter->blink_timer, jiffies + IXGB_ID_INTERVAL);
624}
625
626static int
Joe Perches222441a2008-04-03 10:06:25 -0700627ixgb_phys_id(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700629 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
Stephen Hemminger273dc742007-10-29 10:46:13 -0700631 if (!data)
632 data = INT_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
Jesse Brandeburg03f83042008-07-08 15:52:13 -0700634 if (!adapter->blink_timer.function) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 init_timer(&adapter->blink_timer);
636 adapter->blink_timer.function = ixgb_led_blink_callback;
637 adapter->blink_timer.data = (unsigned long)adapter;
638 }
639
640 mod_timer(&adapter->blink_timer, jiffies);
641
Jesse Brandeburga91bb6a2006-08-31 14:27:50 -0700642 msleep_interruptible(data * 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 del_timer_sync(&adapter->blink_timer);
644 ixgb_led_off(&adapter->hw);
645 clear_bit(IXGB_LED_ON, &adapter->led_status);
646
647 return 0;
648}
649
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700650static int
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700651ixgb_get_sset_count(struct net_device *netdev, int sset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652{
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700653 switch (sset) {
654 case ETH_SS_STATS:
655 return IXGB_STATS_LEN;
656 default:
657 return -EOPNOTSUPP;
658 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659}
660
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700661static void
662ixgb_get_ethtool_stats(struct net_device *netdev,
Joe Perches222441a2008-04-03 10:06:25 -0700663 struct ethtool_stats *stats, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700665 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 int i;
667
668 ixgb_update_stats(adapter);
669 for(i = 0; i < IXGB_STATS_LEN; i++) {
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700670 char *p = (char *)adapter+ixgb_gstrings_stats[i].stat_offset;
671 data[i] = (ixgb_gstrings_stats[i].sizeof_stat ==
Joe Perches222441a2008-04-03 10:06:25 -0700672 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 }
674}
675
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700676static void
Joe Perches222441a2008-04-03 10:06:25 -0700677ixgb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678{
679 int i;
680
681 switch(stringset) {
682 case ETH_SS_STATS:
683 for(i=0; i < IXGB_STATS_LEN; i++) {
Jesse Brandeburg0060c072008-07-08 15:52:23 -0700684 memcpy(data + i * ETH_GSTRING_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 ixgb_gstrings_stats[i].stat_string,
686 ETH_GSTRING_LEN);
687 }
688 break;
689 }
690}
691
Jeff Garzik7282d492006-09-13 14:30:00 -0400692static const struct ethtool_ops ixgb_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 .get_settings = ixgb_get_settings,
694 .set_settings = ixgb_set_settings,
695 .get_drvinfo = ixgb_get_drvinfo,
696 .get_regs_len = ixgb_get_regs_len,
697 .get_regs = ixgb_get_regs,
698 .get_link = ethtool_op_get_link,
699 .get_eeprom_len = ixgb_get_eeprom_len,
700 .get_eeprom = ixgb_get_eeprom,
701 .set_eeprom = ixgb_set_eeprom,
702 .get_ringparam = ixgb_get_ringparam,
703 .set_ringparam = ixgb_set_ringparam,
704 .get_pauseparam = ixgb_get_pauseparam,
705 .set_pauseparam = ixgb_set_pauseparam,
706 .get_rx_csum = ixgb_get_rx_csum,
707 .set_rx_csum = ixgb_set_rx_csum,
708 .get_tx_csum = ixgb_get_tx_csum,
709 .set_tx_csum = ixgb_set_tx_csum,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 .set_sg = ethtool_op_set_sg,
Auke Kokec9c3f52006-05-23 10:34:59 -0700711 .get_msglevel = ixgb_get_msglevel,
712 .set_msglevel = ixgb_set_msglevel,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 .set_tso = ixgb_set_tso,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 .get_strings = ixgb_get_strings,
715 .phys_id = ixgb_phys_id,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700716 .get_sset_count = ixgb_get_sset_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 .get_ethtool_stats = ixgb_get_ethtool_stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718};
719
720void ixgb_set_ethtool_ops(struct net_device *netdev)
721{
722 SET_ETHTOOL_OPS(netdev, &ixgb_ethtool_ops);
723}