ixgb: add copper 10gig driver id
[deliverable/linux.git] / drivers / net / ixgb / ixgb_ethtool.c
CommitLineData
1da177e4
LT
1/*******************************************************************************
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{
8908c6cd 101 struct ixgb_adapter *adapter = netdev_priv(netdev);
1da177e4
LT
102
103 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
db0bacaa 104 ecmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
1da177e4
LT
105 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
4de17c8c
AK
120static void ixgb_set_speed_duplex(struct net_device *netdev)
121{
122 struct ixgb_adapter *adapter = netdev_priv(netdev);
123 /* be optimistic about our link, since we were up before */
124 adapter->link_speed = 10000;
125 adapter->link_duplex = FULL_DUPLEX;
126 netif_carrier_on(netdev);
127 netif_wake_queue(netdev);
128}
129
1da177e4
LT
130static int
131ixgb_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
132{
8908c6cd 133 struct ixgb_adapter *adapter = netdev_priv(netdev);
1da177e4
LT
134
135 if(ecmd->autoneg == AUTONEG_ENABLE ||
136 ecmd->speed + ecmd->duplex != SPEED_10000 + DUPLEX_FULL)
137 return -EINVAL;
138
139 if(netif_running(adapter->netdev)) {
140 ixgb_down(adapter, TRUE);
141 ixgb_reset(adapter);
142 ixgb_up(adapter);
4de17c8c 143 ixgb_set_speed_duplex(netdev);
1da177e4
LT
144 } else
145 ixgb_reset(adapter);
146
147 return 0;
148}
149
150static void
151ixgb_get_pauseparam(struct net_device *netdev,
152 struct ethtool_pauseparam *pause)
153{
8908c6cd 154 struct ixgb_adapter *adapter = netdev_priv(netdev);
1da177e4
LT
155 struct ixgb_hw *hw = &adapter->hw;
156
157 pause->autoneg = AUTONEG_DISABLE;
158
159 if(hw->fc.type == ixgb_fc_rx_pause)
160 pause->rx_pause = 1;
161 else if(hw->fc.type == ixgb_fc_tx_pause)
162 pause->tx_pause = 1;
163 else if(hw->fc.type == ixgb_fc_full) {
164 pause->rx_pause = 1;
165 pause->tx_pause = 1;
166 }
167}
168
169static int
170ixgb_set_pauseparam(struct net_device *netdev,
171 struct ethtool_pauseparam *pause)
172{
8908c6cd 173 struct ixgb_adapter *adapter = netdev_priv(netdev);
1da177e4
LT
174 struct ixgb_hw *hw = &adapter->hw;
175
176 if(pause->autoneg == AUTONEG_ENABLE)
177 return -EINVAL;
178
179 if(pause->rx_pause && pause->tx_pause)
180 hw->fc.type = ixgb_fc_full;
181 else if(pause->rx_pause && !pause->tx_pause)
182 hw->fc.type = ixgb_fc_rx_pause;
183 else if(!pause->rx_pause && pause->tx_pause)
184 hw->fc.type = ixgb_fc_tx_pause;
185 else if(!pause->rx_pause && !pause->tx_pause)
186 hw->fc.type = ixgb_fc_none;
187
188 if(netif_running(adapter->netdev)) {
189 ixgb_down(adapter, TRUE);
190 ixgb_up(adapter);
4de17c8c 191 ixgb_set_speed_duplex(netdev);
1da177e4
LT
192 } else
193 ixgb_reset(adapter);
194
195 return 0;
196}
197
198static uint32_t
199ixgb_get_rx_csum(struct net_device *netdev)
200{
8908c6cd
MC
201 struct ixgb_adapter *adapter = netdev_priv(netdev);
202
1da177e4
LT
203 return adapter->rx_csum;
204}
205
206static int
207ixgb_set_rx_csum(struct net_device *netdev, uint32_t data)
208{
8908c6cd
MC
209 struct ixgb_adapter *adapter = netdev_priv(netdev);
210
1da177e4
LT
211 adapter->rx_csum = data;
212
213 if(netif_running(netdev)) {
214 ixgb_down(adapter,TRUE);
215 ixgb_up(adapter);
4de17c8c 216 ixgb_set_speed_duplex(netdev);
1da177e4
LT
217 } else
218 ixgb_reset(adapter);
219 return 0;
220}
221
222static uint32_t
223ixgb_get_tx_csum(struct net_device *netdev)
224{
225 return (netdev->features & NETIF_F_HW_CSUM) != 0;
226}
227
228static int
229ixgb_set_tx_csum(struct net_device *netdev, uint32_t data)
230{
231 if (data)
232 netdev->features |= NETIF_F_HW_CSUM;
233 else
234 netdev->features &= ~NETIF_F_HW_CSUM;
235
236 return 0;
237}
238
239#ifdef NETIF_F_TSO
240static 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}
249#endif /* NETIF_F_TSO */
250
251#define IXGB_GET_STAT(_A_, _R_) _A_->stats._R_
252
253static int
254ixgb_get_regs_len(struct net_device *netdev)
255{
256#define IXGB_REG_DUMP_LEN 136*sizeof(uint32_t)
257 return IXGB_REG_DUMP_LEN;
258}
259
260static void
261ixgb_get_regs(struct net_device *netdev,
262 struct ethtool_regs *regs, void *p)
263{
8908c6cd 264 struct ixgb_adapter *adapter = netdev_priv(netdev);
1da177e4
LT
265 struct ixgb_hw *hw = &adapter->hw;
266 uint32_t *reg = p;
267 uint32_t *reg_start = reg;
268 uint8_t i;
269
5e3c30de 270 /* the 1 (one) below indicates an attempt at versioning, if the
ab707da7
MC
271 * interface in ethtool or the driver changes, this 1 should be
272 * incremented */
5e3c30de 273 regs->version = (1<<24) | hw->revision_id << 16 | hw->device_id;
1da177e4
LT
274
275 /* General Registers */
276 *reg++ = IXGB_READ_REG(hw, CTRL0); /* 0 */
277 *reg++ = IXGB_READ_REG(hw, CTRL1); /* 1 */
278 *reg++ = IXGB_READ_REG(hw, STATUS); /* 2 */
279 *reg++ = IXGB_READ_REG(hw, EECD); /* 3 */
280 *reg++ = IXGB_READ_REG(hw, MFS); /* 4 */
281
282 /* Interrupt */
283 *reg++ = IXGB_READ_REG(hw, ICR); /* 5 */
284 *reg++ = IXGB_READ_REG(hw, ICS); /* 6 */
285 *reg++ = IXGB_READ_REG(hw, IMS); /* 7 */
286 *reg++ = IXGB_READ_REG(hw, IMC); /* 8 */
287
288 /* Receive */
289 *reg++ = IXGB_READ_REG(hw, RCTL); /* 9 */
290 *reg++ = IXGB_READ_REG(hw, FCRTL); /* 10 */
291 *reg++ = IXGB_READ_REG(hw, FCRTH); /* 11 */
292 *reg++ = IXGB_READ_REG(hw, RDBAL); /* 12 */
293 *reg++ = IXGB_READ_REG(hw, RDBAH); /* 13 */
294 *reg++ = IXGB_READ_REG(hw, RDLEN); /* 14 */
295 *reg++ = IXGB_READ_REG(hw, RDH); /* 15 */
296 *reg++ = IXGB_READ_REG(hw, RDT); /* 16 */
297 *reg++ = IXGB_READ_REG(hw, RDTR); /* 17 */
298 *reg++ = IXGB_READ_REG(hw, RXDCTL); /* 18 */
299 *reg++ = IXGB_READ_REG(hw, RAIDC); /* 19 */
300 *reg++ = IXGB_READ_REG(hw, RXCSUM); /* 20 */
301
9ef2eec3
MC
302 /* there are 16 RAR entries in hardware, we only use 3 */
303 for(i = 0; i < 16; i++) {
1da177e4
LT
304 *reg++ = IXGB_READ_REG_ARRAY(hw, RAL, (i << 1)); /*21,...,51 */
305 *reg++ = IXGB_READ_REG_ARRAY(hw, RAH, (i << 1)); /*22,...,52 */
306 }
307
308 /* Transmit */
309 *reg++ = IXGB_READ_REG(hw, TCTL); /* 53 */
310 *reg++ = IXGB_READ_REG(hw, TDBAL); /* 54 */
311 *reg++ = IXGB_READ_REG(hw, TDBAH); /* 55 */
312 *reg++ = IXGB_READ_REG(hw, TDLEN); /* 56 */
313 *reg++ = IXGB_READ_REG(hw, TDH); /* 57 */
314 *reg++ = IXGB_READ_REG(hw, TDT); /* 58 */
315 *reg++ = IXGB_READ_REG(hw, TIDV); /* 59 */
316 *reg++ = IXGB_READ_REG(hw, TXDCTL); /* 60 */
317 *reg++ = IXGB_READ_REG(hw, TSPMT); /* 61 */
318 *reg++ = IXGB_READ_REG(hw, PAP); /* 62 */
319
320 /* Physical */
321 *reg++ = IXGB_READ_REG(hw, PCSC1); /* 63 */
322 *reg++ = IXGB_READ_REG(hw, PCSC2); /* 64 */
323 *reg++ = IXGB_READ_REG(hw, PCSS1); /* 65 */
324 *reg++ = IXGB_READ_REG(hw, PCSS2); /* 66 */
325 *reg++ = IXGB_READ_REG(hw, XPCSS); /* 67 */
326 *reg++ = IXGB_READ_REG(hw, UCCR); /* 68 */
327 *reg++ = IXGB_READ_REG(hw, XPCSTC); /* 69 */
328 *reg++ = IXGB_READ_REG(hw, MACA); /* 70 */
329 *reg++ = IXGB_READ_REG(hw, APAE); /* 71 */
330 *reg++ = IXGB_READ_REG(hw, ARD); /* 72 */
331 *reg++ = IXGB_READ_REG(hw, AIS); /* 73 */
332 *reg++ = IXGB_READ_REG(hw, MSCA); /* 74 */
333 *reg++ = IXGB_READ_REG(hw, MSRWD); /* 75 */
334
335 /* Statistics */
336 *reg++ = IXGB_GET_STAT(adapter, tprl); /* 76 */
337 *reg++ = IXGB_GET_STAT(adapter, tprh); /* 77 */
338 *reg++ = IXGB_GET_STAT(adapter, gprcl); /* 78 */
339 *reg++ = IXGB_GET_STAT(adapter, gprch); /* 79 */
340 *reg++ = IXGB_GET_STAT(adapter, bprcl); /* 80 */
341 *reg++ = IXGB_GET_STAT(adapter, bprch); /* 81 */
342 *reg++ = IXGB_GET_STAT(adapter, mprcl); /* 82 */
343 *reg++ = IXGB_GET_STAT(adapter, mprch); /* 83 */
344 *reg++ = IXGB_GET_STAT(adapter, uprcl); /* 84 */
345 *reg++ = IXGB_GET_STAT(adapter, uprch); /* 85 */
346 *reg++ = IXGB_GET_STAT(adapter, vprcl); /* 86 */
347 *reg++ = IXGB_GET_STAT(adapter, vprch); /* 87 */
348 *reg++ = IXGB_GET_STAT(adapter, jprcl); /* 88 */
349 *reg++ = IXGB_GET_STAT(adapter, jprch); /* 89 */
350 *reg++ = IXGB_GET_STAT(adapter, gorcl); /* 90 */
351 *reg++ = IXGB_GET_STAT(adapter, gorch); /* 91 */
352 *reg++ = IXGB_GET_STAT(adapter, torl); /* 92 */
353 *reg++ = IXGB_GET_STAT(adapter, torh); /* 93 */
354 *reg++ = IXGB_GET_STAT(adapter, rnbc); /* 94 */
355 *reg++ = IXGB_GET_STAT(adapter, ruc); /* 95 */
356 *reg++ = IXGB_GET_STAT(adapter, roc); /* 96 */
357 *reg++ = IXGB_GET_STAT(adapter, rlec); /* 97 */
358 *reg++ = IXGB_GET_STAT(adapter, crcerrs); /* 98 */
359 *reg++ = IXGB_GET_STAT(adapter, icbc); /* 99 */
360 *reg++ = IXGB_GET_STAT(adapter, ecbc); /* 100 */
361 *reg++ = IXGB_GET_STAT(adapter, mpc); /* 101 */
362 *reg++ = IXGB_GET_STAT(adapter, tptl); /* 102 */
363 *reg++ = IXGB_GET_STAT(adapter, tpth); /* 103 */
364 *reg++ = IXGB_GET_STAT(adapter, gptcl); /* 104 */
365 *reg++ = IXGB_GET_STAT(adapter, gptch); /* 105 */
366 *reg++ = IXGB_GET_STAT(adapter, bptcl); /* 106 */
367 *reg++ = IXGB_GET_STAT(adapter, bptch); /* 107 */
368 *reg++ = IXGB_GET_STAT(adapter, mptcl); /* 108 */
369 *reg++ = IXGB_GET_STAT(adapter, mptch); /* 109 */
370 *reg++ = IXGB_GET_STAT(adapter, uptcl); /* 110 */
371 *reg++ = IXGB_GET_STAT(adapter, uptch); /* 111 */
372 *reg++ = IXGB_GET_STAT(adapter, vptcl); /* 112 */
373 *reg++ = IXGB_GET_STAT(adapter, vptch); /* 113 */
374 *reg++ = IXGB_GET_STAT(adapter, jptcl); /* 114 */
375 *reg++ = IXGB_GET_STAT(adapter, jptch); /* 115 */
376 *reg++ = IXGB_GET_STAT(adapter, gotcl); /* 116 */
377 *reg++ = IXGB_GET_STAT(adapter, gotch); /* 117 */
378 *reg++ = IXGB_GET_STAT(adapter, totl); /* 118 */
379 *reg++ = IXGB_GET_STAT(adapter, toth); /* 119 */
380 *reg++ = IXGB_GET_STAT(adapter, dc); /* 120 */
381 *reg++ = IXGB_GET_STAT(adapter, plt64c); /* 121 */
382 *reg++ = IXGB_GET_STAT(adapter, tsctc); /* 122 */
383 *reg++ = IXGB_GET_STAT(adapter, tsctfc); /* 123 */
384 *reg++ = IXGB_GET_STAT(adapter, ibic); /* 124 */
385 *reg++ = IXGB_GET_STAT(adapter, rfc); /* 125 */
386 *reg++ = IXGB_GET_STAT(adapter, lfc); /* 126 */
387 *reg++ = IXGB_GET_STAT(adapter, pfrc); /* 127 */
388 *reg++ = IXGB_GET_STAT(adapter, pftc); /* 128 */
389 *reg++ = IXGB_GET_STAT(adapter, mcfrc); /* 129 */
390 *reg++ = IXGB_GET_STAT(adapter, mcftc); /* 130 */
391 *reg++ = IXGB_GET_STAT(adapter, xonrxc); /* 131 */
392 *reg++ = IXGB_GET_STAT(adapter, xontxc); /* 132 */
393 *reg++ = IXGB_GET_STAT(adapter, xoffrxc); /* 133 */
394 *reg++ = IXGB_GET_STAT(adapter, xofftxc); /* 134 */
395 *reg++ = IXGB_GET_STAT(adapter, rjc); /* 135 */
396
397 regs->len = (reg - reg_start) * sizeof(uint32_t);
398}
399
400static int
401ixgb_get_eeprom_len(struct net_device *netdev)
402{
403 /* return size in bytes */
404 return (IXGB_EEPROM_SIZE << 1);
405}
406
407static int
408ixgb_get_eeprom(struct net_device *netdev,
409 struct ethtool_eeprom *eeprom, uint8_t *bytes)
410{
8908c6cd 411 struct ixgb_adapter *adapter = netdev_priv(netdev);
1da177e4
LT
412 struct ixgb_hw *hw = &adapter->hw;
413 uint16_t *eeprom_buff;
414 int i, max_len, first_word, last_word;
415 int ret_val = 0;
416
417 if(eeprom->len == 0) {
418 ret_val = -EINVAL;
419 goto geeprom_error;
420 }
421
422 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
423
424 max_len = ixgb_get_eeprom_len(netdev);
425
426 if(eeprom->offset > eeprom->offset + eeprom->len) {
427 ret_val = -EINVAL;
428 goto geeprom_error;
429 }
430
431 if((eeprom->offset + eeprom->len) > max_len)
432 eeprom->len = (max_len - eeprom->offset);
433
434 first_word = eeprom->offset >> 1;
435 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
436
437 eeprom_buff = kmalloc(sizeof(uint16_t) *
438 (last_word - first_word + 1), GFP_KERNEL);
439 if(!eeprom_buff)
440 return -ENOMEM;
441
442 /* note the eeprom was good because the driver loaded */
443 for(i = 0; i <= (last_word - first_word); i++) {
444 eeprom_buff[i] = ixgb_get_eeprom_word(hw, (first_word + i));
445 }
446
447 memcpy(bytes, (uint8_t *)eeprom_buff + (eeprom->offset & 1),
448 eeprom->len);
449 kfree(eeprom_buff);
450
451geeprom_error:
452 return ret_val;
453}
454
455static int
456ixgb_set_eeprom(struct net_device *netdev,
457 struct ethtool_eeprom *eeprom, uint8_t *bytes)
458{
8908c6cd 459 struct ixgb_adapter *adapter = netdev_priv(netdev);
1da177e4
LT
460 struct ixgb_hw *hw = &adapter->hw;
461 uint16_t *eeprom_buff;
462 void *ptr;
463 int max_len, first_word, last_word;
464 uint16_t i;
465
466 if(eeprom->len == 0)
467 return -EINVAL;
468
469 if(eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
470 return -EFAULT;
471
472 max_len = ixgb_get_eeprom_len(netdev);
473
474 if(eeprom->offset > eeprom->offset + eeprom->len)
475 return -EINVAL;
476
477 if((eeprom->offset + eeprom->len) > max_len)
478 eeprom->len = (max_len - eeprom->offset);
479
480 first_word = eeprom->offset >> 1;
481 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
482 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
483 if(!eeprom_buff)
484 return -ENOMEM;
485
486 ptr = (void *)eeprom_buff;
487
488 if(eeprom->offset & 1) {
489 /* need read/modify/write of first changed EEPROM word */
490 /* only the second byte of the word is being modified */
491 eeprom_buff[0] = ixgb_read_eeprom(hw, first_word);
492 ptr++;
493 }
494 if((eeprom->offset + eeprom->len) & 1) {
495 /* need read/modify/write of last changed EEPROM word */
496 /* only the first byte of the word is being modified */
497 eeprom_buff[last_word - first_word]
498 = ixgb_read_eeprom(hw, last_word);
499 }
500
501 memcpy(ptr, bytes, eeprom->len);
502 for(i = 0; i <= (last_word - first_word); i++)
503 ixgb_write_eeprom(hw, first_word + i, eeprom_buff[i]);
504
505 /* Update the checksum over the first part of the EEPROM if needed */
506 if(first_word <= EEPROM_CHECKSUM_REG)
507 ixgb_update_eeprom_checksum(hw);
508
509 kfree(eeprom_buff);
510 return 0;
511}
512
513static void
514ixgb_get_drvinfo(struct net_device *netdev,
515 struct ethtool_drvinfo *drvinfo)
516{
8908c6cd 517 struct ixgb_adapter *adapter = netdev_priv(netdev);
1da177e4
LT
518
519 strncpy(drvinfo->driver, ixgb_driver_name, 32);
520 strncpy(drvinfo->version, ixgb_driver_version, 32);
521 strncpy(drvinfo->fw_version, "N/A", 32);
522 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
523 drvinfo->n_stats = IXGB_STATS_LEN;
524 drvinfo->regdump_len = ixgb_get_regs_len(netdev);
525 drvinfo->eedump_len = ixgb_get_eeprom_len(netdev);
526}
527
528static void
529ixgb_get_ringparam(struct net_device *netdev,
530 struct ethtool_ringparam *ring)
531{
8908c6cd 532 struct ixgb_adapter *adapter = netdev_priv(netdev);
1da177e4
LT
533 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
534 struct ixgb_desc_ring *rxdr = &adapter->rx_ring;
535
536 ring->rx_max_pending = MAX_RXD;
537 ring->tx_max_pending = MAX_TXD;
538 ring->rx_mini_max_pending = 0;
539 ring->rx_jumbo_max_pending = 0;
540 ring->rx_pending = rxdr->count;
541 ring->tx_pending = txdr->count;
542 ring->rx_mini_pending = 0;
543 ring->rx_jumbo_pending = 0;
544}
545
546static int
547ixgb_set_ringparam(struct net_device *netdev,
548 struct ethtool_ringparam *ring)
549{
8908c6cd 550 struct ixgb_adapter *adapter = netdev_priv(netdev);
1da177e4
LT
551 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
552 struct ixgb_desc_ring *rxdr = &adapter->rx_ring;
553 struct ixgb_desc_ring tx_old, tx_new, rx_old, rx_new;
554 int err;
555
556 tx_old = adapter->tx_ring;
557 rx_old = adapter->rx_ring;
558
559 if((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
560 return -EINVAL;
561
562 if(netif_running(adapter->netdev))
563 ixgb_down(adapter,TRUE);
564
565 rxdr->count = max(ring->rx_pending,(uint32_t)MIN_RXD);
566 rxdr->count = min(rxdr->count,(uint32_t)MAX_RXD);
567 IXGB_ROUNDUP(rxdr->count, IXGB_REQ_RX_DESCRIPTOR_MULTIPLE);
568
569 txdr->count = max(ring->tx_pending,(uint32_t)MIN_TXD);
570 txdr->count = min(txdr->count,(uint32_t)MAX_TXD);
571 IXGB_ROUNDUP(txdr->count, IXGB_REQ_TX_DESCRIPTOR_MULTIPLE);
572
573 if(netif_running(adapter->netdev)) {
574 /* Try to get new resources before deleting old */
575 if((err = ixgb_setup_rx_resources(adapter)))
576 goto err_setup_rx;
577 if((err = ixgb_setup_tx_resources(adapter)))
578 goto err_setup_tx;
579
580 /* save the new, restore the old in order to free it,
581 * then restore the new back again */
582
583 rx_new = adapter->rx_ring;
584 tx_new = adapter->tx_ring;
585 adapter->rx_ring = rx_old;
586 adapter->tx_ring = tx_old;
587 ixgb_free_rx_resources(adapter);
588 ixgb_free_tx_resources(adapter);
589 adapter->rx_ring = rx_new;
590 adapter->tx_ring = tx_new;
591 if((err = ixgb_up(adapter)))
592 return err;
4de17c8c 593 ixgb_set_speed_duplex(netdev);
1da177e4
LT
594 }
595
596 return 0;
597err_setup_tx:
598 ixgb_free_rx_resources(adapter);
599err_setup_rx:
600 adapter->rx_ring = rx_old;
601 adapter->tx_ring = tx_old;
602 ixgb_up(adapter);
603 return err;
604}
605
606/* toggle LED 4 times per second = 2 "blinks" per second */
607#define IXGB_ID_INTERVAL (HZ/4)
608
609/* bit defines for adapter->led_status */
610#define IXGB_LED_ON 0
611
612static void
613ixgb_led_blink_callback(unsigned long data)
614{
615 struct ixgb_adapter *adapter = (struct ixgb_adapter *)data;
616
617 if(test_and_change_bit(IXGB_LED_ON, &adapter->led_status))
618 ixgb_led_off(&adapter->hw);
619 else
620 ixgb_led_on(&adapter->hw);
621
622 mod_timer(&adapter->blink_timer, jiffies + IXGB_ID_INTERVAL);
623}
624
625static int
626ixgb_phys_id(struct net_device *netdev, uint32_t data)
627{
8908c6cd 628 struct ixgb_adapter *adapter = netdev_priv(netdev);
1da177e4
LT
629
630 if(!data || data > (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ))
631 data = (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ);
632
633 if(!adapter->blink_timer.function) {
634 init_timer(&adapter->blink_timer);
635 adapter->blink_timer.function = ixgb_led_blink_callback;
636 adapter->blink_timer.data = (unsigned long)adapter;
637 }
638
639 mod_timer(&adapter->blink_timer, jiffies);
640
3173c890
NA
641 if (data)
642 schedule_timeout_interruptible(data * HZ);
1da177e4 643 else
3173c890 644 schedule_timeout_interruptible(MAX_SCHEDULE_TIMEOUT);
1da177e4
LT
645
646 del_timer_sync(&adapter->blink_timer);
647 ixgb_led_off(&adapter->hw);
648 clear_bit(IXGB_LED_ON, &adapter->led_status);
649
650 return 0;
651}
652
653static int
654ixgb_get_stats_count(struct net_device *netdev)
655{
656 return IXGB_STATS_LEN;
657}
658
659static void
660ixgb_get_ethtool_stats(struct net_device *netdev,
661 struct ethtool_stats *stats, uint64_t *data)
662{
8908c6cd 663 struct ixgb_adapter *adapter = netdev_priv(netdev);
1da177e4
LT
664 int i;
665
666 ixgb_update_stats(adapter);
667 for(i = 0; i < IXGB_STATS_LEN; i++) {
668 char *p = (char *)adapter+ixgb_gstrings_stats[i].stat_offset;
669 data[i] = (ixgb_gstrings_stats[i].sizeof_stat ==
670 sizeof(uint64_t)) ? *(uint64_t *)p : *(uint32_t *)p;
671 }
672}
673
674static void
675ixgb_get_strings(struct net_device *netdev, uint32_t stringset, uint8_t *data)
676{
677 int i;
678
679 switch(stringset) {
680 case ETH_SS_STATS:
681 for(i=0; i < IXGB_STATS_LEN; i++) {
682 memcpy(data + i * ETH_GSTRING_LEN,
683 ixgb_gstrings_stats[i].stat_string,
684 ETH_GSTRING_LEN);
685 }
686 break;
687 }
688}
689
e9ab1d14 690static struct ethtool_ops ixgb_ethtool_ops = {
1da177e4
LT
691 .get_settings = ixgb_get_settings,
692 .set_settings = ixgb_set_settings,
693 .get_drvinfo = ixgb_get_drvinfo,
694 .get_regs_len = ixgb_get_regs_len,
695 .get_regs = ixgb_get_regs,
696 .get_link = ethtool_op_get_link,
697 .get_eeprom_len = ixgb_get_eeprom_len,
698 .get_eeprom = ixgb_get_eeprom,
699 .set_eeprom = ixgb_set_eeprom,
700 .get_ringparam = ixgb_get_ringparam,
701 .set_ringparam = ixgb_set_ringparam,
702 .get_pauseparam = ixgb_get_pauseparam,
703 .set_pauseparam = ixgb_set_pauseparam,
704 .get_rx_csum = ixgb_get_rx_csum,
705 .set_rx_csum = ixgb_set_rx_csum,
706 .get_tx_csum = ixgb_get_tx_csum,
707 .set_tx_csum = ixgb_set_tx_csum,
708 .get_sg = ethtool_op_get_sg,
709 .set_sg = ethtool_op_set_sg,
710#ifdef NETIF_F_TSO
711 .get_tso = ethtool_op_get_tso,
712 .set_tso = ixgb_set_tso,
713#endif
714 .get_strings = ixgb_get_strings,
715 .phys_id = ixgb_phys_id,
716 .get_stats_count = ixgb_get_stats_count,
717 .get_ethtool_stats = ixgb_get_ethtool_stats,
df859c51 718 .get_perm_addr = ethtool_op_get_perm_addr,
1da177e4
LT
719};
720
721void ixgb_set_ethtool_ops(struct net_device *netdev)
722{
723 SET_ETHTOOL_OPS(netdev, &ixgb_ethtool_ops);
724}
This page took 0.153714 seconds and 5 git commands to generate.