blob: 04e47189d830105a848d6b6db71c8dd26f625de9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
3
4 Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details.
15
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 The full GNU General Public License is included in this distribution in the
21 file called LICENSE.
22
23 Contact Information:
24 Linux NICS <linux.nics@intel.com>
25 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
47struct ixgb_stats {
48 char stat_string[ETH_GSTRING_LEN];
49 int sizeof_stat;
50 int stat_offset;
51};
52
53#define IXGB_STAT(m) sizeof(((struct ixgb_adapter *)0)->m), \
54 offsetof(struct ixgb_adapter, m)
55static struct ixgb_stats ixgb_gstrings_stats[] = {
56 {"rx_packets", IXGB_STAT(net_stats.rx_packets)},
57 {"tx_packets", IXGB_STAT(net_stats.tx_packets)},
58 {"rx_bytes", IXGB_STAT(net_stats.rx_bytes)},
59 {"tx_bytes", IXGB_STAT(net_stats.tx_bytes)},
60 {"rx_errors", IXGB_STAT(net_stats.rx_errors)},
61 {"tx_errors", IXGB_STAT(net_stats.tx_errors)},
62 {"rx_dropped", IXGB_STAT(net_stats.rx_dropped)},
63 {"tx_dropped", IXGB_STAT(net_stats.tx_dropped)},
64 {"multicast", IXGB_STAT(net_stats.multicast)},
65 {"collisions", IXGB_STAT(net_stats.collisions)},
66
67/* { "rx_length_errors", IXGB_STAT(net_stats.rx_length_errors) }, */
68 {"rx_over_errors", IXGB_STAT(net_stats.rx_over_errors)},
69 {"rx_crc_errors", IXGB_STAT(net_stats.rx_crc_errors)},
70 {"rx_frame_errors", IXGB_STAT(net_stats.rx_frame_errors)},
71 {"rx_fifo_errors", IXGB_STAT(net_stats.rx_fifo_errors)},
72 {"rx_missed_errors", IXGB_STAT(net_stats.rx_missed_errors)},
73 {"tx_aborted_errors", IXGB_STAT(net_stats.tx_aborted_errors)},
74 {"tx_carrier_errors", IXGB_STAT(net_stats.tx_carrier_errors)},
75 {"tx_fifo_errors", IXGB_STAT(net_stats.tx_fifo_errors)},
76 {"tx_heartbeat_errors", IXGB_STAT(net_stats.tx_heartbeat_errors)},
77 {"tx_window_errors", IXGB_STAT(net_stats.tx_window_errors)},
78 {"tx_deferred_ok", IXGB_STAT(stats.dc)},
79 {"rx_long_length_errors", IXGB_STAT(stats.roc)},
80 {"rx_short_length_errors", IXGB_STAT(stats.ruc)},
81#ifdef NETIF_F_TSO
82 {"tx_tcp_seg_good", IXGB_STAT(stats.tsctc)},
83 {"tx_tcp_seg_failed", IXGB_STAT(stats.tsctfc)},
84#endif
85 {"rx_flow_control_xon", IXGB_STAT(stats.xonrxc)},
86 {"rx_flow_control_xoff", IXGB_STAT(stats.xoffrxc)},
87 {"tx_flow_control_xon", IXGB_STAT(stats.xontxc)},
88 {"tx_flow_control_xoff", IXGB_STAT(stats.xofftxc)},
89 {"rx_csum_offload_good", IXGB_STAT(hw_csum_rx_good)},
90 {"rx_csum_offload_errors", IXGB_STAT(hw_csum_rx_error)},
91 {"tx_csum_offload_good", IXGB_STAT(hw_csum_tx_good)},
92 {"tx_csum_offload_errors", IXGB_STAT(hw_csum_tx_error)}
93};
94
95#define IXGB_STATS_LEN \
96 sizeof(ixgb_gstrings_stats) / sizeof(struct ixgb_stats)
97
98static int
99ixgb_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
100{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700101 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
Malli Chilakaladb0baca2005-08-11 13:59:20 -0700104 ecmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 ecmd->port = PORT_FIBRE;
106 ecmd->transceiver = XCVR_EXTERNAL;
107
108 if(netif_carrier_ok(adapter->netdev)) {
109 ecmd->speed = SPEED_10000;
110 ecmd->duplex = DUPLEX_FULL;
111 } else {
112 ecmd->speed = -1;
113 ecmd->duplex = -1;
114 }
115
116 ecmd->autoneg = AUTONEG_DISABLE;
117 return 0;
118}
119
120static 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
125 if(ecmd->autoneg == AUTONEG_ENABLE ||
126 ecmd->speed + ecmd->duplex != SPEED_10000 + DUPLEX_FULL)
127 return -EINVAL;
128
129 if(netif_running(adapter->netdev)) {
130 ixgb_down(adapter, TRUE);
131 ixgb_reset(adapter);
132 ixgb_up(adapter);
Malli Chilakala51b54b52005-08-11 13:58:23 -0700133 /* be optimistic about our link, since we were up before */
134 adapter->link_speed = 10000;
135 adapter->link_duplex = FULL_DUPLEX;
136 netif_carrier_on(netdev);
137 netif_wake_queue(netdev);
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 } else
140 ixgb_reset(adapter);
141
142 return 0;
143}
144
145static void
146ixgb_get_pauseparam(struct net_device *netdev,
147 struct ethtool_pauseparam *pause)
148{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700149 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 struct ixgb_hw *hw = &adapter->hw;
151
152 pause->autoneg = AUTONEG_DISABLE;
153
154 if(hw->fc.type == ixgb_fc_rx_pause)
155 pause->rx_pause = 1;
156 else if(hw->fc.type == ixgb_fc_tx_pause)
157 pause->tx_pause = 1;
158 else if(hw->fc.type == ixgb_fc_full) {
159 pause->rx_pause = 1;
160 pause->tx_pause = 1;
161 }
162}
163
164static int
165ixgb_set_pauseparam(struct net_device *netdev,
166 struct ethtool_pauseparam *pause)
167{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700168 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 struct ixgb_hw *hw = &adapter->hw;
170
171 if(pause->autoneg == AUTONEG_ENABLE)
172 return -EINVAL;
173
174 if(pause->rx_pause && pause->tx_pause)
175 hw->fc.type = ixgb_fc_full;
176 else if(pause->rx_pause && !pause->tx_pause)
177 hw->fc.type = ixgb_fc_rx_pause;
178 else if(!pause->rx_pause && pause->tx_pause)
179 hw->fc.type = ixgb_fc_tx_pause;
180 else if(!pause->rx_pause && !pause->tx_pause)
181 hw->fc.type = ixgb_fc_none;
182
183 if(netif_running(adapter->netdev)) {
184 ixgb_down(adapter, TRUE);
185 ixgb_up(adapter);
Malli Chilakala51b54b52005-08-11 13:58:23 -0700186 /* be optimistic about our link, since we were up before */
187 adapter->link_speed = 10000;
188 adapter->link_duplex = FULL_DUPLEX;
189 netif_carrier_on(netdev);
190 netif_wake_queue(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 } else
192 ixgb_reset(adapter);
193
194 return 0;
195}
196
197static uint32_t
198ixgb_get_rx_csum(struct net_device *netdev)
199{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700200 struct ixgb_adapter *adapter = netdev_priv(netdev);
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 return adapter->rx_csum;
203}
204
205static int
206ixgb_set_rx_csum(struct net_device *netdev, uint32_t data)
207{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700208 struct ixgb_adapter *adapter = netdev_priv(netdev);
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 adapter->rx_csum = data;
211
212 if(netif_running(netdev)) {
213 ixgb_down(adapter,TRUE);
214 ixgb_up(adapter);
Malli Chilakala51b54b52005-08-11 13:58:23 -0700215 /* be optimistic about our link, since we were up before */
216 adapter->link_speed = 10000;
217 adapter->link_duplex = FULL_DUPLEX;
218 netif_carrier_on(netdev);
219 netif_wake_queue(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 } else
221 ixgb_reset(adapter);
222 return 0;
223}
224
225static uint32_t
226ixgb_get_tx_csum(struct net_device *netdev)
227{
228 return (netdev->features & NETIF_F_HW_CSUM) != 0;
229}
230
231static int
232ixgb_set_tx_csum(struct net_device *netdev, uint32_t data)
233{
234 if (data)
235 netdev->features |= NETIF_F_HW_CSUM;
236 else
237 netdev->features &= ~NETIF_F_HW_CSUM;
238
239 return 0;
240}
241
242#ifdef NETIF_F_TSO
243static int
244ixgb_set_tso(struct net_device *netdev, uint32_t data)
245{
246 if(data)
247 netdev->features |= NETIF_F_TSO;
248 else
249 netdev->features &= ~NETIF_F_TSO;
250 return 0;
251}
252#endif /* NETIF_F_TSO */
253
254#define IXGB_GET_STAT(_A_, _R_) _A_->stats._R_
255
256static int
257ixgb_get_regs_len(struct net_device *netdev)
258{
259#define IXGB_REG_DUMP_LEN 136*sizeof(uint32_t)
260 return IXGB_REG_DUMP_LEN;
261}
262
263static void
264ixgb_get_regs(struct net_device *netdev,
265 struct ethtool_regs *regs, void *p)
266{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700267 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 struct ixgb_hw *hw = &adapter->hw;
269 uint32_t *reg = p;
270 uint32_t *reg_start = reg;
271 uint8_t i;
272
Malli Chilakala5e3c30d2005-04-28 19:04:07 -0700273 /* the 1 (one) below indicates an attempt at versioning, if the
Malli Chilakalaab707da2005-08-11 13:59:59 -0700274 * interface in ethtool or the driver changes, this 1 should be
275 * incremented */
Malli Chilakala5e3c30d2005-04-28 19:04:07 -0700276 regs->version = (1<<24) | hw->revision_id << 16 | hw->device_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
278 /* General Registers */
279 *reg++ = IXGB_READ_REG(hw, CTRL0); /* 0 */
280 *reg++ = IXGB_READ_REG(hw, CTRL1); /* 1 */
281 *reg++ = IXGB_READ_REG(hw, STATUS); /* 2 */
282 *reg++ = IXGB_READ_REG(hw, EECD); /* 3 */
283 *reg++ = IXGB_READ_REG(hw, MFS); /* 4 */
284
285 /* Interrupt */
286 *reg++ = IXGB_READ_REG(hw, ICR); /* 5 */
287 *reg++ = IXGB_READ_REG(hw, ICS); /* 6 */
288 *reg++ = IXGB_READ_REG(hw, IMS); /* 7 */
289 *reg++ = IXGB_READ_REG(hw, IMC); /* 8 */
290
291 /* Receive */
292 *reg++ = IXGB_READ_REG(hw, RCTL); /* 9 */
293 *reg++ = IXGB_READ_REG(hw, FCRTL); /* 10 */
294 *reg++ = IXGB_READ_REG(hw, FCRTH); /* 11 */
295 *reg++ = IXGB_READ_REG(hw, RDBAL); /* 12 */
296 *reg++ = IXGB_READ_REG(hw, RDBAH); /* 13 */
297 *reg++ = IXGB_READ_REG(hw, RDLEN); /* 14 */
298 *reg++ = IXGB_READ_REG(hw, RDH); /* 15 */
299 *reg++ = IXGB_READ_REG(hw, RDT); /* 16 */
300 *reg++ = IXGB_READ_REG(hw, RDTR); /* 17 */
301 *reg++ = IXGB_READ_REG(hw, RXDCTL); /* 18 */
302 *reg++ = IXGB_READ_REG(hw, RAIDC); /* 19 */
303 *reg++ = IXGB_READ_REG(hw, RXCSUM); /* 20 */
304
Malli Chilakala9ef2eec2005-08-11 13:59:07 -0700305 /* there are 16 RAR entries in hardware, we only use 3 */
306 for(i = 0; i < 16; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 *reg++ = IXGB_READ_REG_ARRAY(hw, RAL, (i << 1)); /*21,...,51 */
308 *reg++ = IXGB_READ_REG_ARRAY(hw, RAH, (i << 1)); /*22,...,52 */
309 }
310
311 /* Transmit */
312 *reg++ = IXGB_READ_REG(hw, TCTL); /* 53 */
313 *reg++ = IXGB_READ_REG(hw, TDBAL); /* 54 */
314 *reg++ = IXGB_READ_REG(hw, TDBAH); /* 55 */
315 *reg++ = IXGB_READ_REG(hw, TDLEN); /* 56 */
316 *reg++ = IXGB_READ_REG(hw, TDH); /* 57 */
317 *reg++ = IXGB_READ_REG(hw, TDT); /* 58 */
318 *reg++ = IXGB_READ_REG(hw, TIDV); /* 59 */
319 *reg++ = IXGB_READ_REG(hw, TXDCTL); /* 60 */
320 *reg++ = IXGB_READ_REG(hw, TSPMT); /* 61 */
321 *reg++ = IXGB_READ_REG(hw, PAP); /* 62 */
322
323 /* Physical */
324 *reg++ = IXGB_READ_REG(hw, PCSC1); /* 63 */
325 *reg++ = IXGB_READ_REG(hw, PCSC2); /* 64 */
326 *reg++ = IXGB_READ_REG(hw, PCSS1); /* 65 */
327 *reg++ = IXGB_READ_REG(hw, PCSS2); /* 66 */
328 *reg++ = IXGB_READ_REG(hw, XPCSS); /* 67 */
329 *reg++ = IXGB_READ_REG(hw, UCCR); /* 68 */
330 *reg++ = IXGB_READ_REG(hw, XPCSTC); /* 69 */
331 *reg++ = IXGB_READ_REG(hw, MACA); /* 70 */
332 *reg++ = IXGB_READ_REG(hw, APAE); /* 71 */
333 *reg++ = IXGB_READ_REG(hw, ARD); /* 72 */
334 *reg++ = IXGB_READ_REG(hw, AIS); /* 73 */
335 *reg++ = IXGB_READ_REG(hw, MSCA); /* 74 */
336 *reg++ = IXGB_READ_REG(hw, MSRWD); /* 75 */
337
338 /* Statistics */
339 *reg++ = IXGB_GET_STAT(adapter, tprl); /* 76 */
340 *reg++ = IXGB_GET_STAT(adapter, tprh); /* 77 */
341 *reg++ = IXGB_GET_STAT(adapter, gprcl); /* 78 */
342 *reg++ = IXGB_GET_STAT(adapter, gprch); /* 79 */
343 *reg++ = IXGB_GET_STAT(adapter, bprcl); /* 80 */
344 *reg++ = IXGB_GET_STAT(adapter, bprch); /* 81 */
345 *reg++ = IXGB_GET_STAT(adapter, mprcl); /* 82 */
346 *reg++ = IXGB_GET_STAT(adapter, mprch); /* 83 */
347 *reg++ = IXGB_GET_STAT(adapter, uprcl); /* 84 */
348 *reg++ = IXGB_GET_STAT(adapter, uprch); /* 85 */
349 *reg++ = IXGB_GET_STAT(adapter, vprcl); /* 86 */
350 *reg++ = IXGB_GET_STAT(adapter, vprch); /* 87 */
351 *reg++ = IXGB_GET_STAT(adapter, jprcl); /* 88 */
352 *reg++ = IXGB_GET_STAT(adapter, jprch); /* 89 */
353 *reg++ = IXGB_GET_STAT(adapter, gorcl); /* 90 */
354 *reg++ = IXGB_GET_STAT(adapter, gorch); /* 91 */
355 *reg++ = IXGB_GET_STAT(adapter, torl); /* 92 */
356 *reg++ = IXGB_GET_STAT(adapter, torh); /* 93 */
357 *reg++ = IXGB_GET_STAT(adapter, rnbc); /* 94 */
358 *reg++ = IXGB_GET_STAT(adapter, ruc); /* 95 */
359 *reg++ = IXGB_GET_STAT(adapter, roc); /* 96 */
360 *reg++ = IXGB_GET_STAT(adapter, rlec); /* 97 */
361 *reg++ = IXGB_GET_STAT(adapter, crcerrs); /* 98 */
362 *reg++ = IXGB_GET_STAT(adapter, icbc); /* 99 */
363 *reg++ = IXGB_GET_STAT(adapter, ecbc); /* 100 */
364 *reg++ = IXGB_GET_STAT(adapter, mpc); /* 101 */
365 *reg++ = IXGB_GET_STAT(adapter, tptl); /* 102 */
366 *reg++ = IXGB_GET_STAT(adapter, tpth); /* 103 */
367 *reg++ = IXGB_GET_STAT(adapter, gptcl); /* 104 */
368 *reg++ = IXGB_GET_STAT(adapter, gptch); /* 105 */
369 *reg++ = IXGB_GET_STAT(adapter, bptcl); /* 106 */
370 *reg++ = IXGB_GET_STAT(adapter, bptch); /* 107 */
371 *reg++ = IXGB_GET_STAT(adapter, mptcl); /* 108 */
372 *reg++ = IXGB_GET_STAT(adapter, mptch); /* 109 */
373 *reg++ = IXGB_GET_STAT(adapter, uptcl); /* 110 */
374 *reg++ = IXGB_GET_STAT(adapter, uptch); /* 111 */
375 *reg++ = IXGB_GET_STAT(adapter, vptcl); /* 112 */
376 *reg++ = IXGB_GET_STAT(adapter, vptch); /* 113 */
377 *reg++ = IXGB_GET_STAT(adapter, jptcl); /* 114 */
378 *reg++ = IXGB_GET_STAT(adapter, jptch); /* 115 */
379 *reg++ = IXGB_GET_STAT(adapter, gotcl); /* 116 */
380 *reg++ = IXGB_GET_STAT(adapter, gotch); /* 117 */
381 *reg++ = IXGB_GET_STAT(adapter, totl); /* 118 */
382 *reg++ = IXGB_GET_STAT(adapter, toth); /* 119 */
383 *reg++ = IXGB_GET_STAT(adapter, dc); /* 120 */
384 *reg++ = IXGB_GET_STAT(adapter, plt64c); /* 121 */
385 *reg++ = IXGB_GET_STAT(adapter, tsctc); /* 122 */
386 *reg++ = IXGB_GET_STAT(adapter, tsctfc); /* 123 */
387 *reg++ = IXGB_GET_STAT(adapter, ibic); /* 124 */
388 *reg++ = IXGB_GET_STAT(adapter, rfc); /* 125 */
389 *reg++ = IXGB_GET_STAT(adapter, lfc); /* 126 */
390 *reg++ = IXGB_GET_STAT(adapter, pfrc); /* 127 */
391 *reg++ = IXGB_GET_STAT(adapter, pftc); /* 128 */
392 *reg++ = IXGB_GET_STAT(adapter, mcfrc); /* 129 */
393 *reg++ = IXGB_GET_STAT(adapter, mcftc); /* 130 */
394 *reg++ = IXGB_GET_STAT(adapter, xonrxc); /* 131 */
395 *reg++ = IXGB_GET_STAT(adapter, xontxc); /* 132 */
396 *reg++ = IXGB_GET_STAT(adapter, xoffrxc); /* 133 */
397 *reg++ = IXGB_GET_STAT(adapter, xofftxc); /* 134 */
398 *reg++ = IXGB_GET_STAT(adapter, rjc); /* 135 */
399
400 regs->len = (reg - reg_start) * sizeof(uint32_t);
401}
402
403static int
404ixgb_get_eeprom_len(struct net_device *netdev)
405{
406 /* return size in bytes */
407 return (IXGB_EEPROM_SIZE << 1);
408}
409
410static int
411ixgb_get_eeprom(struct net_device *netdev,
412 struct ethtool_eeprom *eeprom, uint8_t *bytes)
413{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700414 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 struct ixgb_hw *hw = &adapter->hw;
416 uint16_t *eeprom_buff;
417 int i, max_len, first_word, last_word;
418 int ret_val = 0;
419
420 if(eeprom->len == 0) {
421 ret_val = -EINVAL;
422 goto geeprom_error;
423 }
424
425 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
426
427 max_len = ixgb_get_eeprom_len(netdev);
428
429 if(eeprom->offset > eeprom->offset + eeprom->len) {
430 ret_val = -EINVAL;
431 goto geeprom_error;
432 }
433
434 if((eeprom->offset + eeprom->len) > max_len)
435 eeprom->len = (max_len - eeprom->offset);
436
437 first_word = eeprom->offset >> 1;
438 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
439
440 eeprom_buff = kmalloc(sizeof(uint16_t) *
441 (last_word - first_word + 1), GFP_KERNEL);
442 if(!eeprom_buff)
443 return -ENOMEM;
444
445 /* note the eeprom was good because the driver loaded */
446 for(i = 0; i <= (last_word - first_word); i++) {
447 eeprom_buff[i] = ixgb_get_eeprom_word(hw, (first_word + i));
448 }
449
450 memcpy(bytes, (uint8_t *)eeprom_buff + (eeprom->offset & 1),
451 eeprom->len);
452 kfree(eeprom_buff);
453
454geeprom_error:
455 return ret_val;
456}
457
458static int
459ixgb_set_eeprom(struct net_device *netdev,
460 struct ethtool_eeprom *eeprom, uint8_t *bytes)
461{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700462 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 struct ixgb_hw *hw = &adapter->hw;
464 uint16_t *eeprom_buff;
465 void *ptr;
466 int max_len, first_word, last_word;
467 uint16_t i;
468
469 if(eeprom->len == 0)
470 return -EINVAL;
471
472 if(eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
473 return -EFAULT;
474
475 max_len = ixgb_get_eeprom_len(netdev);
476
477 if(eeprom->offset > eeprom->offset + eeprom->len)
478 return -EINVAL;
479
480 if((eeprom->offset + eeprom->len) > max_len)
481 eeprom->len = (max_len - eeprom->offset);
482
483 first_word = eeprom->offset >> 1;
484 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
485 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
486 if(!eeprom_buff)
487 return -ENOMEM;
488
489 ptr = (void *)eeprom_buff;
490
491 if(eeprom->offset & 1) {
492 /* need read/modify/write of first changed EEPROM word */
493 /* only the second byte of the word is being modified */
494 eeprom_buff[0] = ixgb_read_eeprom(hw, first_word);
495 ptr++;
496 }
497 if((eeprom->offset + eeprom->len) & 1) {
498 /* need read/modify/write of last changed EEPROM word */
499 /* only the first byte of the word is being modified */
500 eeprom_buff[last_word - first_word]
501 = ixgb_read_eeprom(hw, last_word);
502 }
503
504 memcpy(ptr, bytes, eeprom->len);
505 for(i = 0; i <= (last_word - first_word); i++)
506 ixgb_write_eeprom(hw, first_word + i, eeprom_buff[i]);
507
508 /* Update the checksum over the first part of the EEPROM if needed */
509 if(first_word <= EEPROM_CHECKSUM_REG)
510 ixgb_update_eeprom_checksum(hw);
511
512 kfree(eeprom_buff);
513 return 0;
514}
515
516static void
517ixgb_get_drvinfo(struct net_device *netdev,
518 struct ethtool_drvinfo *drvinfo)
519{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700520 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
522 strncpy(drvinfo->driver, ixgb_driver_name, 32);
523 strncpy(drvinfo->version, ixgb_driver_version, 32);
524 strncpy(drvinfo->fw_version, "N/A", 32);
525 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
526 drvinfo->n_stats = IXGB_STATS_LEN;
527 drvinfo->regdump_len = ixgb_get_regs_len(netdev);
528 drvinfo->eedump_len = ixgb_get_eeprom_len(netdev);
529}
530
531static void
532ixgb_get_ringparam(struct net_device *netdev,
533 struct ethtool_ringparam *ring)
534{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700535 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
537 struct ixgb_desc_ring *rxdr = &adapter->rx_ring;
538
539 ring->rx_max_pending = MAX_RXD;
540 ring->tx_max_pending = MAX_TXD;
541 ring->rx_mini_max_pending = 0;
542 ring->rx_jumbo_max_pending = 0;
543 ring->rx_pending = rxdr->count;
544 ring->tx_pending = txdr->count;
545 ring->rx_mini_pending = 0;
546 ring->rx_jumbo_pending = 0;
547}
548
549static int
550ixgb_set_ringparam(struct net_device *netdev,
551 struct ethtool_ringparam *ring)
552{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700553 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
555 struct ixgb_desc_ring *rxdr = &adapter->rx_ring;
556 struct ixgb_desc_ring tx_old, tx_new, rx_old, rx_new;
557 int err;
558
559 tx_old = adapter->tx_ring;
560 rx_old = adapter->rx_ring;
561
562 if((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
563 return -EINVAL;
564
565 if(netif_running(adapter->netdev))
566 ixgb_down(adapter,TRUE);
567
568 rxdr->count = max(ring->rx_pending,(uint32_t)MIN_RXD);
569 rxdr->count = min(rxdr->count,(uint32_t)MAX_RXD);
570 IXGB_ROUNDUP(rxdr->count, IXGB_REQ_RX_DESCRIPTOR_MULTIPLE);
571
572 txdr->count = max(ring->tx_pending,(uint32_t)MIN_TXD);
573 txdr->count = min(txdr->count,(uint32_t)MAX_TXD);
574 IXGB_ROUNDUP(txdr->count, IXGB_REQ_TX_DESCRIPTOR_MULTIPLE);
575
576 if(netif_running(adapter->netdev)) {
577 /* Try to get new resources before deleting old */
578 if((err = ixgb_setup_rx_resources(adapter)))
579 goto err_setup_rx;
580 if((err = ixgb_setup_tx_resources(adapter)))
581 goto err_setup_tx;
582
583 /* save the new, restore the old in order to free it,
584 * then restore the new back again */
585
586 rx_new = adapter->rx_ring;
587 tx_new = adapter->tx_ring;
588 adapter->rx_ring = rx_old;
589 adapter->tx_ring = tx_old;
590 ixgb_free_rx_resources(adapter);
591 ixgb_free_tx_resources(adapter);
592 adapter->rx_ring = rx_new;
593 adapter->tx_ring = tx_new;
594 if((err = ixgb_up(adapter)))
595 return err;
Malli Chilakala51b54b52005-08-11 13:58:23 -0700596 /* be optimistic about our link, since we were up before */
597 adapter->link_speed = 10000;
598 adapter->link_duplex = FULL_DUPLEX;
599 netif_carrier_on(netdev);
600 netif_wake_queue(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 }
602
603 return 0;
604err_setup_tx:
605 ixgb_free_rx_resources(adapter);
606err_setup_rx:
607 adapter->rx_ring = rx_old;
608 adapter->tx_ring = tx_old;
609 ixgb_up(adapter);
610 return err;
611}
612
613/* toggle LED 4 times per second = 2 "blinks" per second */
614#define IXGB_ID_INTERVAL (HZ/4)
615
616/* bit defines for adapter->led_status */
617#define IXGB_LED_ON 0
618
619static void
620ixgb_led_blink_callback(unsigned long data)
621{
622 struct ixgb_adapter *adapter = (struct ixgb_adapter *)data;
623
624 if(test_and_change_bit(IXGB_LED_ON, &adapter->led_status))
625 ixgb_led_off(&adapter->hw);
626 else
627 ixgb_led_on(&adapter->hw);
628
629 mod_timer(&adapter->blink_timer, jiffies + IXGB_ID_INTERVAL);
630}
631
632static int
633ixgb_phys_id(struct net_device *netdev, uint32_t data)
634{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700635 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
637 if(!data || data > (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ))
638 data = (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ);
639
640 if(!adapter->blink_timer.function) {
641 init_timer(&adapter->blink_timer);
642 adapter->blink_timer.function = ixgb_led_blink_callback;
643 adapter->blink_timer.data = (unsigned long)adapter;
644 }
645
646 mod_timer(&adapter->blink_timer, jiffies);
647
Nishanth Aravamudan3173c892005-09-11 02:09:55 -0700648 if (data)
649 schedule_timeout_interruptible(data * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 else
Nishanth Aravamudan3173c892005-09-11 02:09:55 -0700651 schedule_timeout_interruptible(MAX_SCHEDULE_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
653 del_timer_sync(&adapter->blink_timer);
654 ixgb_led_off(&adapter->hw);
655 clear_bit(IXGB_LED_ON, &adapter->led_status);
656
657 return 0;
658}
659
660static int
661ixgb_get_stats_count(struct net_device *netdev)
662{
663 return IXGB_STATS_LEN;
664}
665
666static void
667ixgb_get_ethtool_stats(struct net_device *netdev,
668 struct ethtool_stats *stats, uint64_t *data)
669{
Malli Chilakala8908c6c2005-08-11 13:58:40 -0700670 struct ixgb_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 int i;
672
673 ixgb_update_stats(adapter);
674 for(i = 0; i < IXGB_STATS_LEN; i++) {
675 char *p = (char *)adapter+ixgb_gstrings_stats[i].stat_offset;
676 data[i] = (ixgb_gstrings_stats[i].sizeof_stat ==
677 sizeof(uint64_t)) ? *(uint64_t *)p : *(uint32_t *)p;
678 }
679}
680
681static void
682ixgb_get_strings(struct net_device *netdev, uint32_t stringset, uint8_t *data)
683{
684 int i;
685
686 switch(stringset) {
687 case ETH_SS_STATS:
688 for(i=0; i < IXGB_STATS_LEN; i++) {
689 memcpy(data + i * ETH_GSTRING_LEN,
690 ixgb_gstrings_stats[i].stat_string,
691 ETH_GSTRING_LEN);
692 }
693 break;
694 }
695}
696
697struct ethtool_ops ixgb_ethtool_ops = {
698 .get_settings = ixgb_get_settings,
699 .set_settings = ixgb_set_settings,
700 .get_drvinfo = ixgb_get_drvinfo,
701 .get_regs_len = ixgb_get_regs_len,
702 .get_regs = ixgb_get_regs,
703 .get_link = ethtool_op_get_link,
704 .get_eeprom_len = ixgb_get_eeprom_len,
705 .get_eeprom = ixgb_get_eeprom,
706 .set_eeprom = ixgb_set_eeprom,
707 .get_ringparam = ixgb_get_ringparam,
708 .set_ringparam = ixgb_set_ringparam,
709 .get_pauseparam = ixgb_get_pauseparam,
710 .set_pauseparam = ixgb_set_pauseparam,
711 .get_rx_csum = ixgb_get_rx_csum,
712 .set_rx_csum = ixgb_set_rx_csum,
713 .get_tx_csum = ixgb_get_tx_csum,
714 .set_tx_csum = ixgb_set_tx_csum,
715 .get_sg = ethtool_op_get_sg,
716 .set_sg = ethtool_op_set_sg,
717#ifdef NETIF_F_TSO
718 .get_tso = ethtool_op_get_tso,
719 .set_tso = ixgb_set_tso,
720#endif
721 .get_strings = ixgb_get_strings,
722 .phys_id = ixgb_phys_id,
723 .get_stats_count = ixgb_get_stats_count,
724 .get_ethtool_stats = ixgb_get_ethtool_stats,
John W. Linvilledf859c52005-09-12 10:48:56 -0400725 .get_perm_addr = ethtool_op_get_perm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726};
727
728void ixgb_set_ethtool_ops(struct net_device *netdev)
729{
730 SET_ETHTOOL_OPS(netdev, &ixgb_ethtool_ops);
731}