blob: ddad26bb5c58cdca77b6a02c75f82821b0c5f430 [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
35extern char ixgb_driver_name[];
36extern char ixgb_driver_version[];
37
38extern int ixgb_up(struct ixgb_adapter *adapter);
39extern void ixgb_down(struct ixgb_adapter *adapter, boolean_t kill_watchdog);
40extern void ixgb_reset(struct ixgb_adapter *adapter);
41extern int ixgb_setup_rx_resources(struct ixgb_adapter *adapter);
42extern int ixgb_setup_tx_resources(struct ixgb_adapter *adapter);
43extern void ixgb_free_rx_resources(struct ixgb_adapter *adapter);
44extern void ixgb_free_tx_resources(struct ixgb_adapter *adapter);
45extern void ixgb_update_stats(struct ixgb_adapter *adapter);
46
Auke Kokc85fd6f2006-05-23 10:30:02 -070047#define IXGB_ALL_RAR_ENTRIES 16
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049struct ixgb_stats {
50 char stat_string[ETH_GSTRING_LEN];
51 int sizeof_stat;
52 int stat_offset;
53};
54
55#define IXGB_STAT(m) sizeof(((struct ixgb_adapter *)0)->m), \
56 offsetof(struct ixgb_adapter, m)
57static struct ixgb_stats ixgb_gstrings_stats[] = {
58 {"rx_packets", IXGB_STAT(net_stats.rx_packets)},
59 {"tx_packets", IXGB_STAT(net_stats.tx_packets)},
60 {"rx_bytes", IXGB_STAT(net_stats.rx_bytes)},
61 {"tx_bytes", IXGB_STAT(net_stats.tx_bytes)},
62 {"rx_errors", IXGB_STAT(net_stats.rx_errors)},
63 {"tx_errors", IXGB_STAT(net_stats.tx_errors)},
64 {"rx_dropped", IXGB_STAT(net_stats.rx_dropped)},
65 {"tx_dropped", IXGB_STAT(net_stats.tx_dropped)},
66 {"multicast", IXGB_STAT(net_stats.multicast)},
67 {"collisions", IXGB_STAT(net_stats.collisions)},
68
69/* { "rx_length_errors", IXGB_STAT(net_stats.rx_length_errors) }, */
70 {"rx_over_errors", IXGB_STAT(net_stats.rx_over_errors)},
71 {"rx_crc_errors", IXGB_STAT(net_stats.rx_crc_errors)},
72 {"rx_frame_errors", IXGB_STAT(net_stats.rx_frame_errors)},
73 {"rx_fifo_errors", IXGB_STAT(net_stats.rx_fifo_errors)},
74 {"rx_missed_errors", IXGB_STAT(net_stats.rx_missed_errors)},
75 {"tx_aborted_errors", IXGB_STAT(net_stats.tx_aborted_errors)},
76 {"tx_carrier_errors", IXGB_STAT(net_stats.tx_carrier_errors)},
77 {"tx_fifo_errors", IXGB_STAT(net_stats.tx_fifo_errors)},
78 {"tx_heartbeat_errors", IXGB_STAT(net_stats.tx_heartbeat_errors)},
79 {"tx_window_errors", IXGB_STAT(net_stats.tx_window_errors)},
80 {"tx_deferred_ok", IXGB_STAT(stats.dc)},
Auke Kok9b8118d2006-05-23 10:35:04 -070081 {"tx_timeout_count", IXGB_STAT(tx_timeout_count) },
Jesse Brandeburgdfd341e2007-01-06 09:51:38 -080082 {"tx_restart_queue", IXGB_STAT(restart_queue) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 {"rx_long_length_errors", IXGB_STAT(stats.roc)},
84 {"rx_short_length_errors", IXGB_STAT(stats.ruc)},
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 {"tx_tcp_seg_good", IXGB_STAT(stats.tsctc)},
86 {"tx_tcp_seg_failed", IXGB_STAT(stats.tsctfc)},
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 {"rx_flow_control_xon", IXGB_STAT(stats.xonrxc)},
88 {"rx_flow_control_xoff", IXGB_STAT(stats.xoffrxc)},
89 {"tx_flow_control_xon", IXGB_STAT(stats.xontxc)},
90 {"tx_flow_control_xoff", IXGB_STAT(stats.xofftxc)},
91 {"rx_csum_offload_good", IXGB_STAT(hw_csum_rx_good)},
92 {"rx_csum_offload_errors", IXGB_STAT(hw_csum_rx_error)},
93 {"tx_csum_offload_good", IXGB_STAT(hw_csum_tx_good)},
94 {"tx_csum_offload_errors", IXGB_STAT(hw_csum_tx_error)}
95};
96
Denis Chengff8ac602007-09-02 18:30:18 +080097#define IXGB_STATS_LEN ARRAY_SIZE(ixgb_gstrings_stats)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99static int
100ixgb_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
101{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700102 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
Malli Chilakaladb0baca2005-08-11 13:59:20 -0700105 ecmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 ecmd->port = PORT_FIBRE;
107 ecmd->transceiver = XCVR_EXTERNAL;
108
109 if(netif_carrier_ok(adapter->netdev)) {
110 ecmd->speed = SPEED_10000;
111 ecmd->duplex = DUPLEX_FULL;
112 } else {
113 ecmd->speed = -1;
114 ecmd->duplex = -1;
115 }
116
117 ecmd->autoneg = AUTONEG_DISABLE;
118 return 0;
119}
120
Auke Kok4de17c82006-05-23 10:29:46 -0700121static void ixgb_set_speed_duplex(struct net_device *netdev)
122{
123 struct ixgb_adapter *adapter = netdev_priv(netdev);
124 /* be optimistic about our link, since we were up before */
125 adapter->link_speed = 10000;
126 adapter->link_duplex = FULL_DUPLEX;
127 netif_carrier_on(netdev);
128 netif_wake_queue(netdev);
129}
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131static int
132ixgb_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
133{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700134 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 if(ecmd->autoneg == AUTONEG_ENABLE ||
137 ecmd->speed + ecmd->duplex != SPEED_10000 + DUPLEX_FULL)
138 return -EINVAL;
139
140 if(netif_running(adapter->netdev)) {
141 ixgb_down(adapter, TRUE);
142 ixgb_reset(adapter);
143 ixgb_up(adapter);
Auke Kok4de17c82006-05-23 10:29:46 -0700144 ixgb_set_speed_duplex(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 } else
146 ixgb_reset(adapter);
147
148 return 0;
149}
150
151static void
152ixgb_get_pauseparam(struct net_device *netdev,
153 struct ethtool_pauseparam *pause)
154{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700155 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 struct ixgb_hw *hw = &adapter->hw;
157
158 pause->autoneg = AUTONEG_DISABLE;
159
160 if(hw->fc.type == ixgb_fc_rx_pause)
161 pause->rx_pause = 1;
162 else if(hw->fc.type == ixgb_fc_tx_pause)
163 pause->tx_pause = 1;
164 else if(hw->fc.type == ixgb_fc_full) {
165 pause->rx_pause = 1;
166 pause->tx_pause = 1;
167 }
168}
169
170static int
171ixgb_set_pauseparam(struct net_device *netdev,
172 struct ethtool_pauseparam *pause)
173{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700174 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 struct ixgb_hw *hw = &adapter->hw;
176
177 if(pause->autoneg == AUTONEG_ENABLE)
178 return -EINVAL;
179
180 if(pause->rx_pause && pause->tx_pause)
181 hw->fc.type = ixgb_fc_full;
182 else if(pause->rx_pause && !pause->tx_pause)
183 hw->fc.type = ixgb_fc_rx_pause;
184 else if(!pause->rx_pause && pause->tx_pause)
185 hw->fc.type = ixgb_fc_tx_pause;
186 else if(!pause->rx_pause && !pause->tx_pause)
187 hw->fc.type = ixgb_fc_none;
188
189 if(netif_running(adapter->netdev)) {
190 ixgb_down(adapter, TRUE);
191 ixgb_up(adapter);
Auke Kok4de17c82006-05-23 10:29:46 -0700192 ixgb_set_speed_duplex(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 } else
194 ixgb_reset(adapter);
195
196 return 0;
197}
198
199static uint32_t
200ixgb_get_rx_csum(struct net_device *netdev)
201{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700202 struct ixgb_adapter *adapter = netdev_priv(netdev);
203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 return adapter->rx_csum;
205}
206
207static int
208ixgb_set_rx_csum(struct net_device *netdev, uint32_t data)
209{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700210 struct ixgb_adapter *adapter = netdev_priv(netdev);
211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 adapter->rx_csum = data;
213
214 if(netif_running(netdev)) {
215 ixgb_down(adapter,TRUE);
216 ixgb_up(adapter);
Auke Kok4de17c82006-05-23 10:29:46 -0700217 ixgb_set_speed_duplex(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 } else
219 ixgb_reset(adapter);
220 return 0;
221}
222
223static uint32_t
224ixgb_get_tx_csum(struct net_device *netdev)
225{
226 return (netdev->features & NETIF_F_HW_CSUM) != 0;
227}
228
229static int
230ixgb_set_tx_csum(struct net_device *netdev, uint32_t data)
231{
232 if (data)
233 netdev->features |= NETIF_F_HW_CSUM;
234 else
235 netdev->features &= ~NETIF_F_HW_CSUM;
236
237 return 0;
238}
239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240static int
241ixgb_set_tso(struct net_device *netdev, uint32_t data)
242{
243 if(data)
244 netdev->features |= NETIF_F_TSO;
245 else
246 netdev->features &= ~NETIF_F_TSO;
247 return 0;
248}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Auke Kokec9c3f52006-05-23 10:34:59 -0700250static uint32_t
251ixgb_get_msglevel(struct net_device *netdev)
252{
Auke Kok25943072006-05-26 09:35:57 -0700253 struct ixgb_adapter *adapter = netdev_priv(netdev);
Auke Kokec9c3f52006-05-23 10:34:59 -0700254 return adapter->msg_enable;
255}
256
257static void
258ixgb_set_msglevel(struct net_device *netdev, uint32_t data)
259{
Auke Kok25943072006-05-26 09:35:57 -0700260 struct ixgb_adapter *adapter = netdev_priv(netdev);
Auke Kokec9c3f52006-05-23 10:34:59 -0700261 adapter->msg_enable = data;
262}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263#define IXGB_GET_STAT(_A_, _R_) _A_->stats._R_
264
265static int
266ixgb_get_regs_len(struct net_device *netdev)
267{
268#define IXGB_REG_DUMP_LEN 136*sizeof(uint32_t)
269 return IXGB_REG_DUMP_LEN;
270}
271
272static void
273ixgb_get_regs(struct net_device *netdev,
274 struct ethtool_regs *regs, void *p)
275{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700276 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 struct ixgb_hw *hw = &adapter->hw;
278 uint32_t *reg = p;
279 uint32_t *reg_start = reg;
280 uint8_t i;
281
Malli Chilakala5e3c30d2005-04-28 19:04:07 -0700282 /* the 1 (one) below indicates an attempt at versioning, if the
Malli Chilakalaab707da2005-08-11 13:59:59 -0700283 * interface in ethtool or the driver changes, this 1 should be
284 * incremented */
Malli Chilakala5e3c30d2005-04-28 19:04:07 -0700285 regs->version = (1<<24) | hw->revision_id << 16 | hw->device_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287 /* General Registers */
288 *reg++ = IXGB_READ_REG(hw, CTRL0); /* 0 */
289 *reg++ = IXGB_READ_REG(hw, CTRL1); /* 1 */
290 *reg++ = IXGB_READ_REG(hw, STATUS); /* 2 */
291 *reg++ = IXGB_READ_REG(hw, EECD); /* 3 */
292 *reg++ = IXGB_READ_REG(hw, MFS); /* 4 */
293
294 /* Interrupt */
295 *reg++ = IXGB_READ_REG(hw, ICR); /* 5 */
296 *reg++ = IXGB_READ_REG(hw, ICS); /* 6 */
297 *reg++ = IXGB_READ_REG(hw, IMS); /* 7 */
298 *reg++ = IXGB_READ_REG(hw, IMC); /* 8 */
299
300 /* Receive */
301 *reg++ = IXGB_READ_REG(hw, RCTL); /* 9 */
302 *reg++ = IXGB_READ_REG(hw, FCRTL); /* 10 */
303 *reg++ = IXGB_READ_REG(hw, FCRTH); /* 11 */
304 *reg++ = IXGB_READ_REG(hw, RDBAL); /* 12 */
305 *reg++ = IXGB_READ_REG(hw, RDBAH); /* 13 */
306 *reg++ = IXGB_READ_REG(hw, RDLEN); /* 14 */
307 *reg++ = IXGB_READ_REG(hw, RDH); /* 15 */
308 *reg++ = IXGB_READ_REG(hw, RDT); /* 16 */
309 *reg++ = IXGB_READ_REG(hw, RDTR); /* 17 */
310 *reg++ = IXGB_READ_REG(hw, RXDCTL); /* 18 */
311 *reg++ = IXGB_READ_REG(hw, RAIDC); /* 19 */
312 *reg++ = IXGB_READ_REG(hw, RXCSUM); /* 20 */
313
Malli Chilakala9ef2eec2005-08-11 13:59:07 -0700314 /* there are 16 RAR entries in hardware, we only use 3 */
Auke Kokc85fd6f2006-05-23 10:30:02 -0700315 for(i = 0; i < IXGB_ALL_RAR_ENTRIES; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 *reg++ = IXGB_READ_REG_ARRAY(hw, RAL, (i << 1)); /*21,...,51 */
317 *reg++ = IXGB_READ_REG_ARRAY(hw, RAH, (i << 1)); /*22,...,52 */
318 }
319
320 /* Transmit */
321 *reg++ = IXGB_READ_REG(hw, TCTL); /* 53 */
322 *reg++ = IXGB_READ_REG(hw, TDBAL); /* 54 */
323 *reg++ = IXGB_READ_REG(hw, TDBAH); /* 55 */
324 *reg++ = IXGB_READ_REG(hw, TDLEN); /* 56 */
325 *reg++ = IXGB_READ_REG(hw, TDH); /* 57 */
326 *reg++ = IXGB_READ_REG(hw, TDT); /* 58 */
327 *reg++ = IXGB_READ_REG(hw, TIDV); /* 59 */
328 *reg++ = IXGB_READ_REG(hw, TXDCTL); /* 60 */
329 *reg++ = IXGB_READ_REG(hw, TSPMT); /* 61 */
330 *reg++ = IXGB_READ_REG(hw, PAP); /* 62 */
331
332 /* Physical */
333 *reg++ = IXGB_READ_REG(hw, PCSC1); /* 63 */
334 *reg++ = IXGB_READ_REG(hw, PCSC2); /* 64 */
335 *reg++ = IXGB_READ_REG(hw, PCSS1); /* 65 */
336 *reg++ = IXGB_READ_REG(hw, PCSS2); /* 66 */
337 *reg++ = IXGB_READ_REG(hw, XPCSS); /* 67 */
338 *reg++ = IXGB_READ_REG(hw, UCCR); /* 68 */
339 *reg++ = IXGB_READ_REG(hw, XPCSTC); /* 69 */
340 *reg++ = IXGB_READ_REG(hw, MACA); /* 70 */
341 *reg++ = IXGB_READ_REG(hw, APAE); /* 71 */
342 *reg++ = IXGB_READ_REG(hw, ARD); /* 72 */
343 *reg++ = IXGB_READ_REG(hw, AIS); /* 73 */
344 *reg++ = IXGB_READ_REG(hw, MSCA); /* 74 */
345 *reg++ = IXGB_READ_REG(hw, MSRWD); /* 75 */
346
347 /* Statistics */
348 *reg++ = IXGB_GET_STAT(adapter, tprl); /* 76 */
349 *reg++ = IXGB_GET_STAT(adapter, tprh); /* 77 */
350 *reg++ = IXGB_GET_STAT(adapter, gprcl); /* 78 */
351 *reg++ = IXGB_GET_STAT(adapter, gprch); /* 79 */
352 *reg++ = IXGB_GET_STAT(adapter, bprcl); /* 80 */
353 *reg++ = IXGB_GET_STAT(adapter, bprch); /* 81 */
354 *reg++ = IXGB_GET_STAT(adapter, mprcl); /* 82 */
355 *reg++ = IXGB_GET_STAT(adapter, mprch); /* 83 */
356 *reg++ = IXGB_GET_STAT(adapter, uprcl); /* 84 */
357 *reg++ = IXGB_GET_STAT(adapter, uprch); /* 85 */
358 *reg++ = IXGB_GET_STAT(adapter, vprcl); /* 86 */
359 *reg++ = IXGB_GET_STAT(adapter, vprch); /* 87 */
360 *reg++ = IXGB_GET_STAT(adapter, jprcl); /* 88 */
361 *reg++ = IXGB_GET_STAT(adapter, jprch); /* 89 */
362 *reg++ = IXGB_GET_STAT(adapter, gorcl); /* 90 */
363 *reg++ = IXGB_GET_STAT(adapter, gorch); /* 91 */
364 *reg++ = IXGB_GET_STAT(adapter, torl); /* 92 */
365 *reg++ = IXGB_GET_STAT(adapter, torh); /* 93 */
366 *reg++ = IXGB_GET_STAT(adapter, rnbc); /* 94 */
367 *reg++ = IXGB_GET_STAT(adapter, ruc); /* 95 */
368 *reg++ = IXGB_GET_STAT(adapter, roc); /* 96 */
369 *reg++ = IXGB_GET_STAT(adapter, rlec); /* 97 */
370 *reg++ = IXGB_GET_STAT(adapter, crcerrs); /* 98 */
371 *reg++ = IXGB_GET_STAT(adapter, icbc); /* 99 */
372 *reg++ = IXGB_GET_STAT(adapter, ecbc); /* 100 */
373 *reg++ = IXGB_GET_STAT(adapter, mpc); /* 101 */
374 *reg++ = IXGB_GET_STAT(adapter, tptl); /* 102 */
375 *reg++ = IXGB_GET_STAT(adapter, tpth); /* 103 */
376 *reg++ = IXGB_GET_STAT(adapter, gptcl); /* 104 */
377 *reg++ = IXGB_GET_STAT(adapter, gptch); /* 105 */
378 *reg++ = IXGB_GET_STAT(adapter, bptcl); /* 106 */
379 *reg++ = IXGB_GET_STAT(adapter, bptch); /* 107 */
380 *reg++ = IXGB_GET_STAT(adapter, mptcl); /* 108 */
381 *reg++ = IXGB_GET_STAT(adapter, mptch); /* 109 */
382 *reg++ = IXGB_GET_STAT(adapter, uptcl); /* 110 */
383 *reg++ = IXGB_GET_STAT(adapter, uptch); /* 111 */
384 *reg++ = IXGB_GET_STAT(adapter, vptcl); /* 112 */
385 *reg++ = IXGB_GET_STAT(adapter, vptch); /* 113 */
386 *reg++ = IXGB_GET_STAT(adapter, jptcl); /* 114 */
387 *reg++ = IXGB_GET_STAT(adapter, jptch); /* 115 */
388 *reg++ = IXGB_GET_STAT(adapter, gotcl); /* 116 */
389 *reg++ = IXGB_GET_STAT(adapter, gotch); /* 117 */
390 *reg++ = IXGB_GET_STAT(adapter, totl); /* 118 */
391 *reg++ = IXGB_GET_STAT(adapter, toth); /* 119 */
392 *reg++ = IXGB_GET_STAT(adapter, dc); /* 120 */
393 *reg++ = IXGB_GET_STAT(adapter, plt64c); /* 121 */
394 *reg++ = IXGB_GET_STAT(adapter, tsctc); /* 122 */
395 *reg++ = IXGB_GET_STAT(adapter, tsctfc); /* 123 */
396 *reg++ = IXGB_GET_STAT(adapter, ibic); /* 124 */
397 *reg++ = IXGB_GET_STAT(adapter, rfc); /* 125 */
398 *reg++ = IXGB_GET_STAT(adapter, lfc); /* 126 */
399 *reg++ = IXGB_GET_STAT(adapter, pfrc); /* 127 */
400 *reg++ = IXGB_GET_STAT(adapter, pftc); /* 128 */
401 *reg++ = IXGB_GET_STAT(adapter, mcfrc); /* 129 */
402 *reg++ = IXGB_GET_STAT(adapter, mcftc); /* 130 */
403 *reg++ = IXGB_GET_STAT(adapter, xonrxc); /* 131 */
404 *reg++ = IXGB_GET_STAT(adapter, xontxc); /* 132 */
405 *reg++ = IXGB_GET_STAT(adapter, xoffrxc); /* 133 */
406 *reg++ = IXGB_GET_STAT(adapter, xofftxc); /* 134 */
407 *reg++ = IXGB_GET_STAT(adapter, rjc); /* 135 */
408
409 regs->len = (reg - reg_start) * sizeof(uint32_t);
410}
411
412static int
413ixgb_get_eeprom_len(struct net_device *netdev)
414{
415 /* return size in bytes */
416 return (IXGB_EEPROM_SIZE << 1);
417}
418
419static int
420ixgb_get_eeprom(struct net_device *netdev,
421 struct ethtool_eeprom *eeprom, uint8_t *bytes)
422{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700423 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 struct ixgb_hw *hw = &adapter->hw;
425 uint16_t *eeprom_buff;
426 int i, max_len, first_word, last_word;
427 int ret_val = 0;
428
429 if(eeprom->len == 0) {
430 ret_val = -EINVAL;
431 goto geeprom_error;
432 }
433
434 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
435
436 max_len = ixgb_get_eeprom_len(netdev);
437
438 if(eeprom->offset > eeprom->offset + eeprom->len) {
439 ret_val = -EINVAL;
440 goto geeprom_error;
441 }
442
443 if((eeprom->offset + eeprom->len) > max_len)
444 eeprom->len = (max_len - eeprom->offset);
445
446 first_word = eeprom->offset >> 1;
447 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
448
449 eeprom_buff = kmalloc(sizeof(uint16_t) *
450 (last_word - first_word + 1), GFP_KERNEL);
451 if(!eeprom_buff)
452 return -ENOMEM;
453
454 /* note the eeprom was good because the driver loaded */
455 for(i = 0; i <= (last_word - first_word); i++) {
456 eeprom_buff[i] = ixgb_get_eeprom_word(hw, (first_word + i));
457 }
458
459 memcpy(bytes, (uint8_t *)eeprom_buff + (eeprom->offset & 1),
460 eeprom->len);
461 kfree(eeprom_buff);
462
463geeprom_error:
464 return ret_val;
465}
466
467static int
468ixgb_set_eeprom(struct net_device *netdev,
469 struct ethtool_eeprom *eeprom, uint8_t *bytes)
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_hw *hw = &adapter->hw;
473 uint16_t *eeprom_buff;
474 void *ptr;
475 int max_len, first_word, last_word;
476 uint16_t i;
477
478 if(eeprom->len == 0)
479 return -EINVAL;
480
481 if(eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
482 return -EFAULT;
483
484 max_len = ixgb_get_eeprom_len(netdev);
485
486 if(eeprom->offset > eeprom->offset + eeprom->len)
487 return -EINVAL;
488
489 if((eeprom->offset + eeprom->len) > max_len)
490 eeprom->len = (max_len - eeprom->offset);
491
492 first_word = eeprom->offset >> 1;
493 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
494 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
495 if(!eeprom_buff)
496 return -ENOMEM;
497
498 ptr = (void *)eeprom_buff;
499
500 if(eeprom->offset & 1) {
501 /* need read/modify/write of first changed EEPROM word */
502 /* only the second byte of the word is being modified */
503 eeprom_buff[0] = ixgb_read_eeprom(hw, first_word);
504 ptr++;
505 }
506 if((eeprom->offset + eeprom->len) & 1) {
507 /* need read/modify/write of last changed EEPROM word */
508 /* only the first byte of the word is being modified */
509 eeprom_buff[last_word - first_word]
510 = ixgb_read_eeprom(hw, last_word);
511 }
512
513 memcpy(ptr, bytes, eeprom->len);
514 for(i = 0; i <= (last_word - first_word); i++)
515 ixgb_write_eeprom(hw, first_word + i, eeprom_buff[i]);
516
517 /* Update the checksum over the first part of the EEPROM if needed */
518 if(first_word <= EEPROM_CHECKSUM_REG)
519 ixgb_update_eeprom_checksum(hw);
520
521 kfree(eeprom_buff);
522 return 0;
523}
524
525static void
526ixgb_get_drvinfo(struct net_device *netdev,
527 struct ethtool_drvinfo *drvinfo)
528{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700529 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
531 strncpy(drvinfo->driver, ixgb_driver_name, 32);
532 strncpy(drvinfo->version, ixgb_driver_version, 32);
533 strncpy(drvinfo->fw_version, "N/A", 32);
534 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
535 drvinfo->n_stats = IXGB_STATS_LEN;
536 drvinfo->regdump_len = ixgb_get_regs_len(netdev);
537 drvinfo->eedump_len = ixgb_get_eeprom_len(netdev);
538}
539
540static void
541ixgb_get_ringparam(struct net_device *netdev,
542 struct ethtool_ringparam *ring)
543{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700544 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
546 struct ixgb_desc_ring *rxdr = &adapter->rx_ring;
547
548 ring->rx_max_pending = MAX_RXD;
549 ring->tx_max_pending = MAX_TXD;
550 ring->rx_mini_max_pending = 0;
551 ring->rx_jumbo_max_pending = 0;
552 ring->rx_pending = rxdr->count;
553 ring->tx_pending = txdr->count;
554 ring->rx_mini_pending = 0;
555 ring->rx_jumbo_pending = 0;
556}
557
558static int
559ixgb_set_ringparam(struct net_device *netdev,
560 struct ethtool_ringparam *ring)
561{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700562 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
564 struct ixgb_desc_ring *rxdr = &adapter->rx_ring;
565 struct ixgb_desc_ring tx_old, tx_new, rx_old, rx_new;
566 int err;
567
568 tx_old = adapter->tx_ring;
569 rx_old = adapter->rx_ring;
570
571 if((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
572 return -EINVAL;
573
574 if(netif_running(adapter->netdev))
575 ixgb_down(adapter,TRUE);
576
577 rxdr->count = max(ring->rx_pending,(uint32_t)MIN_RXD);
578 rxdr->count = min(rxdr->count,(uint32_t)MAX_RXD);
Milind Arun Choudhary55e924c2007-04-27 13:55:31 -0700579 rxdr->count = ALIGN(rxdr->count, IXGB_REQ_RX_DESCRIPTOR_MULTIPLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
581 txdr->count = max(ring->tx_pending,(uint32_t)MIN_TXD);
582 txdr->count = min(txdr->count,(uint32_t)MAX_TXD);
Milind Arun Choudhary55e924c2007-04-27 13:55:31 -0700583 txdr->count = ALIGN(txdr->count, IXGB_REQ_TX_DESCRIPTOR_MULTIPLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
585 if(netif_running(adapter->netdev)) {
586 /* Try to get new resources before deleting old */
587 if((err = ixgb_setup_rx_resources(adapter)))
588 goto err_setup_rx;
589 if((err = ixgb_setup_tx_resources(adapter)))
590 goto err_setup_tx;
591
592 /* save the new, restore the old in order to free it,
593 * then restore the new back again */
594
595 rx_new = adapter->rx_ring;
596 tx_new = adapter->tx_ring;
597 adapter->rx_ring = rx_old;
598 adapter->tx_ring = tx_old;
599 ixgb_free_rx_resources(adapter);
600 ixgb_free_tx_resources(adapter);
601 adapter->rx_ring = rx_new;
602 adapter->tx_ring = tx_new;
603 if((err = ixgb_up(adapter)))
604 return err;
Auke Kok4de17c82006-05-23 10:29:46 -0700605 ixgb_set_speed_duplex(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 }
607
608 return 0;
609err_setup_tx:
610 ixgb_free_rx_resources(adapter);
611err_setup_rx:
612 adapter->rx_ring = rx_old;
613 adapter->tx_ring = tx_old;
614 ixgb_up(adapter);
615 return err;
616}
617
618/* toggle LED 4 times per second = 2 "blinks" per second */
619#define IXGB_ID_INTERVAL (HZ/4)
620
621/* bit defines for adapter->led_status */
622#define IXGB_LED_ON 0
623
624static void
625ixgb_led_blink_callback(unsigned long data)
626{
627 struct ixgb_adapter *adapter = (struct ixgb_adapter *)data;
628
629 if(test_and_change_bit(IXGB_LED_ON, &adapter->led_status))
630 ixgb_led_off(&adapter->hw);
631 else
632 ixgb_led_on(&adapter->hw);
633
634 mod_timer(&adapter->blink_timer, jiffies + IXGB_ID_INTERVAL);
635}
636
637static int
638ixgb_phys_id(struct net_device *netdev, uint32_t data)
639{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700640 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
642 if(!data || data > (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ))
643 data = (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ);
644
645 if(!adapter->blink_timer.function) {
646 init_timer(&adapter->blink_timer);
647 adapter->blink_timer.function = ixgb_led_blink_callback;
648 adapter->blink_timer.data = (unsigned long)adapter;
649 }
650
651 mod_timer(&adapter->blink_timer, jiffies);
652
Jesse Brandeburga91bb6a2006-08-31 14:27:50 -0700653 msleep_interruptible(data * 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 del_timer_sync(&adapter->blink_timer);
655 ixgb_led_off(&adapter->hw);
656 clear_bit(IXGB_LED_ON, &adapter->led_status);
657
658 return 0;
659}
660
661static int
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700662ixgb_get_sset_count(struct net_device *netdev, int sset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663{
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700664 switch (sset) {
665 case ETH_SS_STATS:
666 return IXGB_STATS_LEN;
667 default:
668 return -EOPNOTSUPP;
669 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670}
671
672static void
673ixgb_get_ethtool_stats(struct net_device *netdev,
674 struct ethtool_stats *stats, uint64_t *data)
675{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700676 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 int i;
678
679 ixgb_update_stats(adapter);
680 for(i = 0; i < IXGB_STATS_LEN; i++) {
681 char *p = (char *)adapter+ixgb_gstrings_stats[i].stat_offset;
682 data[i] = (ixgb_gstrings_stats[i].sizeof_stat ==
683 sizeof(uint64_t)) ? *(uint64_t *)p : *(uint32_t *)p;
684 }
685}
686
687static void
688ixgb_get_strings(struct net_device *netdev, uint32_t stringset, uint8_t *data)
689{
690 int i;
691
692 switch(stringset) {
693 case ETH_SS_STATS:
694 for(i=0; i < IXGB_STATS_LEN; i++) {
695 memcpy(data + i * ETH_GSTRING_LEN,
696 ixgb_gstrings_stats[i].stat_string,
697 ETH_GSTRING_LEN);
698 }
699 break;
700 }
701}
702
Jeff Garzik7282d492006-09-13 14:30:00 -0400703static const struct ethtool_ops ixgb_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 .get_settings = ixgb_get_settings,
705 .set_settings = ixgb_set_settings,
706 .get_drvinfo = ixgb_get_drvinfo,
707 .get_regs_len = ixgb_get_regs_len,
708 .get_regs = ixgb_get_regs,
709 .get_link = ethtool_op_get_link,
710 .get_eeprom_len = ixgb_get_eeprom_len,
711 .get_eeprom = ixgb_get_eeprom,
712 .set_eeprom = ixgb_set_eeprom,
713 .get_ringparam = ixgb_get_ringparam,
714 .set_ringparam = ixgb_set_ringparam,
715 .get_pauseparam = ixgb_get_pauseparam,
716 .set_pauseparam = ixgb_set_pauseparam,
717 .get_rx_csum = ixgb_get_rx_csum,
718 .set_rx_csum = ixgb_set_rx_csum,
719 .get_tx_csum = ixgb_get_tx_csum,
720 .set_tx_csum = ixgb_set_tx_csum,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 .set_sg = ethtool_op_set_sg,
Auke Kokec9c3f52006-05-23 10:34:59 -0700722 .get_msglevel = ixgb_get_msglevel,
723 .set_msglevel = ixgb_set_msglevel,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 .set_tso = ixgb_set_tso,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 .get_strings = ixgb_get_strings,
726 .phys_id = ixgb_phys_id,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700727 .get_sset_count = ixgb_get_sset_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 .get_ethtool_stats = ixgb_get_ethtool_stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729};
730
731void ixgb_set_ethtool_ops(struct net_device *netdev)
732{
733 SET_ETHTOOL_OPS(netdev, &ixgb_ethtool_ops);
734}