patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / net / ixgb / ixgb_ethtool.c
1 /*******************************************************************************
2
3   
4   Copyright(c) 1999 - 2004 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
35 extern char ixgb_driver_name[];
36 extern char ixgb_driver_version[];
37
38 extern int ixgb_up(struct ixgb_adapter *adapter);
39 extern void ixgb_down(struct ixgb_adapter *adapter, boolean_t kill_watchdog);
40
41 static inline int ixgb_eeprom_size(struct ixgb_hw *hw)
42 {
43         /* return size in bytes */
44         return (IXGB_EEPROM_SIZE << 1);
45 }
46
47 struct 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)
55 static 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 /*      { "rx_length_errors", IXGB_STAT(net_stats.rx_length_errors) },  */
67         {"rx_over_errors", IXGB_STAT(net_stats.rx_over_errors)},
68         {"rx_crc_errors", IXGB_STAT(net_stats.rx_crc_errors)},
69         {"rx_frame_errors", IXGB_STAT(net_stats.rx_frame_errors)},
70         {"rx_fifo_errors", IXGB_STAT(net_stats.rx_fifo_errors)},
71         {"rx_missed_errors", IXGB_STAT(net_stats.rx_missed_errors)},
72         {"tx_aborted_errors", IXGB_STAT(net_stats.tx_aborted_errors)},
73         {"tx_carrier_errors", IXGB_STAT(net_stats.tx_carrier_errors)},
74         {"tx_fifo_errors", IXGB_STAT(net_stats.tx_fifo_errors)},
75         {"tx_heartbeat_errors", IXGB_STAT(net_stats.tx_heartbeat_errors)},
76         {"tx_window_errors", IXGB_STAT(net_stats.tx_window_errors)},
77         {"tx_deferred_ok", IXGB_STAT(stats.dc)},
78         {"rx_long_length_errors", IXGB_STAT(stats.roc)},
79         {"rx_short_length_errors", IXGB_STAT(stats.ruc)},
80 #ifdef NETIF_F_TSO
81         {"tx_tcp_seg_good", IXGB_STAT(stats.tsctc)},
82         {"tx_tcp_seg_failed", IXGB_STAT(stats.tsctfc)},
83 #endif
84         {"rx_flow_control_xon", IXGB_STAT(stats.xonrxc)},
85         {"rx_flow_control_xoff", IXGB_STAT(stats.xoffrxc)},
86         {"tx_flow_control_xon", IXGB_STAT(stats.xontxc)},
87         {"tx_flow_control_xoff", IXGB_STAT(stats.xofftxc)},
88         {"rx_csum_offload_good", IXGB_STAT(hw_csum_rx_good)},
89         {"rx_csum_offload_errors", IXGB_STAT(hw_csum_rx_error)},
90         {"tx_csum_offload_good", IXGB_STAT(hw_csum_tx_good)},
91         {"tx_csum_offload_errors", IXGB_STAT(hw_csum_tx_error)}
92 };
93
94 #define IXGB_STATS_LEN  \
95         sizeof(ixgb_gstrings_stats) / sizeof(struct ixgb_stats)
96
97 static void
98 ixgb_ethtool_gset(struct ixgb_adapter *adapter, struct ethtool_cmd *ecmd)
99 {
100         ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
101         ecmd->advertising = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
102         ecmd->port = PORT_FIBRE;
103         ecmd->transceiver = XCVR_EXTERNAL;
104
105         if (netif_carrier_ok(adapter->netdev)) {
106                 ecmd->speed = SPEED_10000;
107                 ecmd->duplex = DUPLEX_FULL;
108         } else {
109                 ecmd->speed = -1;
110                 ecmd->duplex = -1;
111         }
112
113         ecmd->autoneg = AUTONEG_DISABLE;
114 }
115
116 static int
117 ixgb_ethtool_sset(struct ixgb_adapter *adapter, struct ethtool_cmd *ecmd)
118 {
119         if (ecmd->autoneg == AUTONEG_ENABLE ||
120             ecmd->speed + ecmd->duplex != SPEED_10000 + DUPLEX_FULL)
121                 return -EINVAL;
122         else {
123                 ixgb_down(adapter, TRUE);
124                 ixgb_up(adapter);
125         }
126
127         return 0;
128 }
129
130 static int
131 ixgb_ethtool_gpause(struct ixgb_adapter *adapter,
132                     struct ethtool_pauseparam *epause)
133 {
134         struct ixgb_hw *hw = &adapter->hw;
135
136         epause->autoneg = AUTONEG_DISABLE;
137
138         if (hw->fc.type == ixgb_fc_rx_pause)
139                 epause->rx_pause = 1;
140         else if (hw->fc.type == ixgb_fc_tx_pause)
141                 epause->tx_pause = 1;
142         else if (hw->fc.type == ixgb_fc_full) {
143                 epause->rx_pause = 1;
144                 epause->tx_pause = 1;
145         }
146
147         return 0;
148 }
149
150 static int
151 ixgb_ethtool_spause(struct ixgb_adapter *adapter,
152                     struct ethtool_pauseparam *epause)
153 {
154         struct ixgb_hw *hw = &adapter->hw;
155
156         if (epause->autoneg == AUTONEG_ENABLE)
157                 return -EINVAL;
158
159         if (epause->rx_pause && epause->tx_pause)
160                 hw->fc.type = ixgb_fc_full;
161         else if (epause->rx_pause && !epause->tx_pause)
162                 hw->fc.type = ixgb_fc_rx_pause;
163         else if (!epause->rx_pause && epause->tx_pause)
164                 hw->fc.type = ixgb_fc_tx_pause;
165         else if (!epause->rx_pause && !epause->tx_pause)
166                 hw->fc.type = ixgb_fc_none;
167
168         ixgb_down(adapter, TRUE);
169         ixgb_up(adapter);
170
171         return 0;
172 }
173
174 static void
175 ixgb_ethtool_gdrvinfo(struct ixgb_adapter *adapter,
176                       struct ethtool_drvinfo *drvinfo)
177 {
178         strncpy(drvinfo->driver, ixgb_driver_name, 32);
179         strncpy(drvinfo->version, ixgb_driver_version, 32);
180         strncpy(drvinfo->fw_version, "N/A", 32);
181         strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
182         drvinfo->n_stats = IXGB_STATS_LEN;
183 #define IXGB_REG_DUMP_LEN  136*sizeof(uint32_t)
184         drvinfo->regdump_len = IXGB_REG_DUMP_LEN;
185         drvinfo->eedump_len = ixgb_eeprom_size(&adapter->hw);
186 }
187
188 #define IXGB_GET_STAT(_A_, _R_) _A_->stats._R_
189 static void
190 ixgb_ethtool_gregs(struct ixgb_adapter *adapter,
191                    struct ethtool_regs *regs, uint32_t * regs_buff)
192 {
193         struct ixgb_hw *hw = &adapter->hw;
194         uint32_t *reg = regs_buff;
195         uint32_t *reg_start = reg;
196         uint8_t i;
197
198         regs->version =
199             (adapter->hw.device_id << 16) | adapter->hw.subsystem_id;
200
201         /* General Registers */
202         *reg++ = IXGB_READ_REG(hw, CTRL0);      /*   0 */
203         *reg++ = IXGB_READ_REG(hw, CTRL1);      /*   1 */
204         *reg++ = IXGB_READ_REG(hw, STATUS);     /*   2 */
205         *reg++ = IXGB_READ_REG(hw, EECD);       /*   3 */
206         *reg++ = IXGB_READ_REG(hw, MFS);        /*   4 */
207
208         /* Interrupt */
209         *reg++ = IXGB_READ_REG(hw, ICR);        /*   5 */
210         *reg++ = IXGB_READ_REG(hw, ICS);        /*   6 */
211         *reg++ = IXGB_READ_REG(hw, IMS);        /*   7 */
212         *reg++ = IXGB_READ_REG(hw, IMC);        /*   8 */
213
214         /* Receive */
215         *reg++ = IXGB_READ_REG(hw, RCTL);       /*   9 */
216         *reg++ = IXGB_READ_REG(hw, FCRTL);      /*  10 */
217         *reg++ = IXGB_READ_REG(hw, FCRTH);      /*  11 */
218         *reg++ = IXGB_READ_REG(hw, RDBAL);      /*  12 */
219         *reg++ = IXGB_READ_REG(hw, RDBAH);      /*  13 */
220         *reg++ = IXGB_READ_REG(hw, RDLEN);      /*  14 */
221         *reg++ = IXGB_READ_REG(hw, RDH);        /*  15 */
222         *reg++ = IXGB_READ_REG(hw, RDT);        /*  16 */
223         *reg++ = IXGB_READ_REG(hw, RDTR);       /*  17 */
224         *reg++ = IXGB_READ_REG(hw, RXDCTL);     /*  18 */
225         *reg++ = IXGB_READ_REG(hw, RAIDC);      /*  19 */
226         *reg++ = IXGB_READ_REG(hw, RXCSUM);     /*  20 */
227
228         for (i = 0; i < IXGB_RAR_ENTRIES; i++) {
229                 *reg++ = IXGB_READ_REG_ARRAY(hw, RAL, (i << 1));        /*21,...,51 */
230                 *reg++ = IXGB_READ_REG_ARRAY(hw, RAH, (i << 1));        /*22,...,52 */
231         }
232
233         /* Transmit */
234         *reg++ = IXGB_READ_REG(hw, TCTL);       /*  53 */
235         *reg++ = IXGB_READ_REG(hw, TDBAL);      /*  54 */
236         *reg++ = IXGB_READ_REG(hw, TDBAH);      /*  55 */
237         *reg++ = IXGB_READ_REG(hw, TDLEN);      /*  56 */
238         *reg++ = IXGB_READ_REG(hw, TDH);        /*  57 */
239         *reg++ = IXGB_READ_REG(hw, TDT);        /*  58 */
240         *reg++ = IXGB_READ_REG(hw, TIDV);       /*  59 */
241         *reg++ = IXGB_READ_REG(hw, TXDCTL);     /*  60 */
242         *reg++ = IXGB_READ_REG(hw, TSPMT);      /*  61 */
243         *reg++ = IXGB_READ_REG(hw, PAP);        /*  62 */
244
245         /* Physical */
246         *reg++ = IXGB_READ_REG(hw, PCSC1);      /*  63 */
247         *reg++ = IXGB_READ_REG(hw, PCSC2);      /*  64 */
248         *reg++ = IXGB_READ_REG(hw, PCSS1);      /*  65 */
249         *reg++ = IXGB_READ_REG(hw, PCSS2);      /*  66 */
250         *reg++ = IXGB_READ_REG(hw, XPCSS);      /*  67 */
251         *reg++ = IXGB_READ_REG(hw, UCCR);       /*  68 */
252         *reg++ = IXGB_READ_REG(hw, XPCSTC);     /*  69 */
253         *reg++ = IXGB_READ_REG(hw, MACA);       /*  70 */
254         *reg++ = IXGB_READ_REG(hw, APAE);       /*  71 */
255         *reg++ = IXGB_READ_REG(hw, ARD);        /*  72 */
256         *reg++ = IXGB_READ_REG(hw, AIS);        /*  73 */
257         *reg++ = IXGB_READ_REG(hw, MSCA);       /*  74 */
258         *reg++ = IXGB_READ_REG(hw, MSRWD);      /*  75 */
259
260         /* Statistics */
261         *reg++ = IXGB_GET_STAT(adapter, tprl);  /*  76 */
262         *reg++ = IXGB_GET_STAT(adapter, tprh);  /*  77 */
263         *reg++ = IXGB_GET_STAT(adapter, gprcl); /*  78 */
264         *reg++ = IXGB_GET_STAT(adapter, gprch); /*  79 */
265         *reg++ = IXGB_GET_STAT(adapter, bprcl); /*  80 */
266         *reg++ = IXGB_GET_STAT(adapter, bprch); /*  81 */
267         *reg++ = IXGB_GET_STAT(adapter, mprcl); /*  82 */
268         *reg++ = IXGB_GET_STAT(adapter, mprch); /*  83 */
269         *reg++ = IXGB_GET_STAT(adapter, uprcl); /*  84 */
270         *reg++ = IXGB_GET_STAT(adapter, uprch); /*  85 */
271         *reg++ = IXGB_GET_STAT(adapter, vprcl); /*  86 */
272         *reg++ = IXGB_GET_STAT(adapter, vprch); /*  87 */
273         *reg++ = IXGB_GET_STAT(adapter, jprcl); /*  88 */
274         *reg++ = IXGB_GET_STAT(adapter, jprch); /*  89 */
275         *reg++ = IXGB_GET_STAT(adapter, gorcl); /*  90 */
276         *reg++ = IXGB_GET_STAT(adapter, gorch); /*  91 */
277         *reg++ = IXGB_GET_STAT(adapter, torl);  /*  92 */
278         *reg++ = IXGB_GET_STAT(adapter, torh);  /*  93 */
279         *reg++ = IXGB_GET_STAT(adapter, rnbc);  /*  94 */
280         *reg++ = IXGB_GET_STAT(adapter, ruc);   /*  95 */
281         *reg++ = IXGB_GET_STAT(adapter, roc);   /*  96 */
282         *reg++ = IXGB_GET_STAT(adapter, rlec);  /*  97 */
283         *reg++ = IXGB_GET_STAT(adapter, crcerrs);       /*  98 */
284         *reg++ = IXGB_GET_STAT(adapter, icbc);  /*  99 */
285         *reg++ = IXGB_GET_STAT(adapter, ecbc);  /* 100 */
286         *reg++ = IXGB_GET_STAT(adapter, mpc);   /* 101 */
287         *reg++ = IXGB_GET_STAT(adapter, tptl);  /* 102 */
288         *reg++ = IXGB_GET_STAT(adapter, tpth);  /* 103 */
289         *reg++ = IXGB_GET_STAT(adapter, gptcl); /* 104 */
290         *reg++ = IXGB_GET_STAT(adapter, gptch); /* 105 */
291         *reg++ = IXGB_GET_STAT(adapter, bptcl); /* 106 */
292         *reg++ = IXGB_GET_STAT(adapter, bptch); /* 107 */
293         *reg++ = IXGB_GET_STAT(adapter, mptcl); /* 108 */
294         *reg++ = IXGB_GET_STAT(adapter, mptch); /* 109 */
295         *reg++ = IXGB_GET_STAT(adapter, uptcl); /* 110 */
296         *reg++ = IXGB_GET_STAT(adapter, uptch); /* 111 */
297         *reg++ = IXGB_GET_STAT(adapter, vptcl); /* 112 */
298         *reg++ = IXGB_GET_STAT(adapter, vptch); /* 113 */
299         *reg++ = IXGB_GET_STAT(adapter, jptcl); /* 114 */
300         *reg++ = IXGB_GET_STAT(adapter, jptch); /* 115 */
301         *reg++ = IXGB_GET_STAT(adapter, gotcl); /* 116 */
302         *reg++ = IXGB_GET_STAT(adapter, gotch); /* 117 */
303         *reg++ = IXGB_GET_STAT(adapter, totl);  /* 118 */
304         *reg++ = IXGB_GET_STAT(adapter, toth);  /* 119 */
305         *reg++ = IXGB_GET_STAT(adapter, dc);    /* 120 */
306         *reg++ = IXGB_GET_STAT(adapter, plt64c);        /* 121 */
307         *reg++ = IXGB_GET_STAT(adapter, tsctc); /* 122 */
308         *reg++ = IXGB_GET_STAT(adapter, tsctfc);        /* 123 */
309         *reg++ = IXGB_GET_STAT(adapter, ibic);  /* 124 */
310         *reg++ = IXGB_GET_STAT(adapter, rfc);   /* 125 */
311         *reg++ = IXGB_GET_STAT(adapter, lfc);   /* 126 */
312         *reg++ = IXGB_GET_STAT(adapter, pfrc);  /* 127 */
313         *reg++ = IXGB_GET_STAT(adapter, pftc);  /* 128 */
314         *reg++ = IXGB_GET_STAT(adapter, mcfrc); /* 129 */
315         *reg++ = IXGB_GET_STAT(adapter, mcftc); /* 130 */
316         *reg++ = IXGB_GET_STAT(adapter, xonrxc);        /* 131 */
317         *reg++ = IXGB_GET_STAT(adapter, xontxc);        /* 132 */
318         *reg++ = IXGB_GET_STAT(adapter, xoffrxc);       /* 133 */
319         *reg++ = IXGB_GET_STAT(adapter, xofftxc);       /* 134 */
320         *reg++ = IXGB_GET_STAT(adapter, rjc);   /* 135 */
321
322         regs->len = (reg - reg_start) * sizeof(uint32_t);
323 }
324
325 static int
326 ixgb_ethtool_geeprom(struct ixgb_adapter *adapter,
327                      struct ethtool_eeprom *eeprom, uint16_t * eeprom_buff)
328 {
329         struct ixgb_hw *hw = &adapter->hw;
330         int i, max_len, first_word, last_word;
331         int ret_val = 0;
332
333         if (eeprom->len == 0) {
334                 ret_val = -EINVAL;
335                 goto geeprom_error;
336         }
337
338         eeprom->magic = hw->vendor_id | (hw->device_id << 16);
339
340         max_len = ixgb_eeprom_size(hw);
341
342         /* use our function to read the eeprom and update our cache */
343         ixgb_get_eeprom_data(hw);
344
345         if (eeprom->offset > eeprom->offset + eeprom->len) {
346                 ret_val = -EINVAL;
347                 goto geeprom_error;
348         }
349
350         if ((eeprom->offset + eeprom->len) > max_len)
351                 eeprom->len = (max_len - eeprom->offset);
352
353         first_word = eeprom->offset >> 1;
354         last_word = (eeprom->offset + eeprom->len - 1) >> 1;
355
356         for (i = 0; i <= (last_word - first_word); i++) {
357                 eeprom_buff[i] = hw->eeprom[first_word + i];
358         }
359       geeprom_error:
360         return ret_val;
361 }
362
363 static int
364 ixgb_ethtool_seeprom(struct ixgb_adapter *adapter,
365                      struct ethtool_eeprom *eeprom, void __user *user_data)
366 {
367         struct ixgb_hw *hw = &adapter->hw;
368         uint16_t eeprom_buff[256];
369         int i, max_len, first_word, last_word;
370         void *ptr;
371
372         if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
373                 return -EFAULT;
374
375         if (eeprom->len == 0)
376                 return -EINVAL;
377
378         max_len = ixgb_eeprom_size(hw);
379
380         if (eeprom->offset > eeprom->offset + eeprom->len)
381                 return -EINVAL;
382
383         if ((eeprom->offset + eeprom->len) > max_len)
384                 eeprom->len = (max_len - eeprom->offset);
385
386         first_word = eeprom->offset >> 1;
387         last_word = (eeprom->offset + eeprom->len - 1) >> 1;
388         ptr = (void *)eeprom_buff;
389
390         if (eeprom->offset & 1) {
391                 /* need read/modify/write of first changed EEPROM word */
392                 /* only the second byte of the word is being modified */
393                 eeprom_buff[0] = ixgb_read_eeprom(hw, first_word);
394                 ptr++;
395         }
396         if ((eeprom->offset + eeprom->len) & 1) {
397                 /* need read/modify/write of last changed EEPROM word */
398                 /* only the first byte of the word is being modified */
399                 eeprom_buff[last_word - first_word]
400                     = ixgb_read_eeprom(hw, last_word);
401         }
402         if (copy_from_user(ptr, user_data, eeprom->len))
403                 return -EFAULT;
404
405         for (i = 0; i <= (last_word - first_word); i++)
406                 ixgb_write_eeprom(hw, first_word + i, eeprom_buff[i]);
407
408         /* Update the checksum over the first part of the EEPROM if needed */
409         if (first_word <= EEPROM_CHECKSUM_REG)
410                 ixgb_update_eeprom_checksum(hw);
411
412         return 0;
413 }
414
415 /* toggle LED 4 times per second = 2 "blinks" per second */
416 #define IXGB_ID_INTERVAL        (HZ/4)
417
418 /* bit defines for adapter->led_status */
419 #define IXGB_LED_ON             0
420
421 static void ixgb_led_blink_callback(unsigned long data)
422 {
423         struct ixgb_adapter *adapter = (struct ixgb_adapter *)data;
424
425         if (test_and_change_bit(IXGB_LED_ON, &adapter->led_status))
426                 ixgb_led_off(&adapter->hw);
427         else
428                 ixgb_led_on(&adapter->hw);
429
430         mod_timer(&adapter->blink_timer, jiffies + IXGB_ID_INTERVAL);
431 }
432
433 static int
434 ixgb_ethtool_led_blink(struct ixgb_adapter *adapter, struct ethtool_value *id)
435 {
436         if (!adapter->blink_timer.function) {
437                 init_timer(&adapter->blink_timer);
438                 adapter->blink_timer.function = ixgb_led_blink_callback;
439                 adapter->blink_timer.data = (unsigned long)adapter;
440         }
441
442         mod_timer(&adapter->blink_timer, jiffies);
443
444         set_current_state(TASK_INTERRUPTIBLE);
445         if (id->data)
446                 schedule_timeout(id->data * HZ);
447         else
448                 schedule_timeout(MAX_SCHEDULE_TIMEOUT);
449
450         del_timer_sync(&adapter->blink_timer);
451         ixgb_led_off(&adapter->hw);
452         clear_bit(IXGB_LED_ON, &adapter->led_status);
453
454         return 0;
455 }
456
457 int ixgb_ethtool_ioctl(struct net_device *netdev, struct ifreq *ifr)
458 {
459         struct ixgb_adapter *adapter = netdev->priv;
460         void __user *addr = ifr->ifr_data;
461         uint32_t cmd;
462
463         if (get_user(cmd, (uint32_t __user *) addr))
464                 return -EFAULT;
465
466         switch (cmd) {
467         case ETHTOOL_GSET:{
468                         struct ethtool_cmd ecmd = { ETHTOOL_GSET };
469                         ixgb_ethtool_gset(adapter, &ecmd);
470                         if (copy_to_user(addr, &ecmd, sizeof(ecmd)))
471                                 return -EFAULT;
472                         return 0;
473                 }
474         case ETHTOOL_SSET:{
475                         struct ethtool_cmd ecmd;
476                         if (copy_from_user(&ecmd, addr, sizeof(ecmd)))
477                                 return -EFAULT;
478                         return ixgb_ethtool_sset(adapter, &ecmd);
479                 }
480         case ETHTOOL_GDRVINFO:{
481                         struct ethtool_drvinfo drvinfo = { ETHTOOL_GDRVINFO };
482                         ixgb_ethtool_gdrvinfo(adapter, &drvinfo);
483                         if (copy_to_user(addr, &drvinfo, sizeof(drvinfo)))
484                                 return -EFAULT;
485                         return 0;
486                 }
487         case ETHTOOL_GSTRINGS:{
488                         struct ethtool_gstrings gstrings = { ETHTOOL_GSTRINGS };
489                         char *strings = NULL;
490                         int err = 0;
491
492                         if (copy_from_user(&gstrings, addr, sizeof(gstrings)))
493                                 return -EFAULT;
494                         switch (gstrings.string_set) {
495                         case ETH_SS_STATS:{
496                                         int i;
497                                         gstrings.len = IXGB_STATS_LEN;
498                                         strings =
499                                             kmalloc(IXGB_STATS_LEN *
500                                                     ETH_GSTRING_LEN,
501                                                     GFP_KERNEL);
502                                         if (!strings)
503                                                 return -ENOMEM;
504                                         for (i = 0; i < IXGB_STATS_LEN; i++) {
505                                                 memcpy(&strings
506                                                        [i * ETH_GSTRING_LEN],
507                                                        ixgb_gstrings_stats[i].
508                                                        stat_string,
509                                                        ETH_GSTRING_LEN);
510                                         }
511                                         break;
512                                 }
513                         default:
514                                 return -EOPNOTSUPP;
515                         }
516                         if (copy_to_user(addr, &gstrings, sizeof(gstrings)))
517                                 err = -EFAULT;
518                         addr += offsetof(struct ethtool_gstrings, data);
519                         if (!err && copy_to_user(addr, strings,
520                                                  gstrings.len *
521                                                  ETH_GSTRING_LEN))
522                                 err = -EFAULT;
523
524                         kfree(strings);
525                         return err;
526                 }
527         case ETHTOOL_GREGS:{
528                         struct ethtool_regs regs = { ETHTOOL_GREGS };
529                         uint32_t regs_buff[IXGB_REG_DUMP_LEN];
530
531                         if (copy_from_user(&regs, addr, sizeof(regs)))
532                                 return -EFAULT;
533                         ixgb_ethtool_gregs(adapter, &regs, regs_buff);
534                         if (copy_to_user(addr, &regs, sizeof(regs)))
535                                 return -EFAULT;
536
537                         addr += offsetof(struct ethtool_regs, data);
538                         if (copy_to_user(addr, regs_buff, regs.len))
539                                 return -EFAULT;
540
541                         return 0;
542                 }
543         case ETHTOOL_NWAY_RST:{
544                         if (netif_running(netdev)) {
545                                 ixgb_down(adapter, TRUE);
546                                 ixgb_up(adapter);
547                         }
548                         return 0;
549                 }
550         case ETHTOOL_PHYS_ID:{
551                         struct ethtool_value id;
552                         if (copy_from_user(&id, addr, sizeof(id)))
553                                 return -EFAULT;
554                         return ixgb_ethtool_led_blink(adapter, &id);
555                 }
556         case ETHTOOL_GLINK:{
557                         struct ethtool_value link = { ETHTOOL_GLINK };
558                         link.data = netif_carrier_ok(netdev);
559                         if (copy_to_user(addr, &link, sizeof(link)))
560                                 return -EFAULT;
561                         return 0;
562                 }
563
564         case ETHTOOL_GEEPROM:{
565                         struct ethtool_eeprom eeprom = { ETHTOOL_GEEPROM };
566                         uint16_t eeprom_buff[IXGB_EEPROM_SIZE];
567                         void *ptr;
568                         int err = 0;
569
570                         if (copy_from_user(&eeprom, addr, sizeof(eeprom)))
571                                 return -EFAULT;
572
573                         if ((err =
574                              ixgb_ethtool_geeprom(adapter, &eeprom,
575                                                   eeprom_buff)) < 0)
576                                 return err;
577
578                         if (copy_to_user(addr, &eeprom, sizeof(eeprom)))
579                                 return -EFAULT;
580
581                         addr += offsetof(struct ethtool_eeprom, data);
582                         ptr = ((void *)eeprom_buff) + (eeprom.offset & 1);
583
584                         if (copy_to_user(addr, ptr, eeprom.len))
585                                 return -EFAULT;
586                         return 0;
587                 }
588         case ETHTOOL_SEEPROM:{
589                         struct ethtool_eeprom eeprom;
590
591                         if (copy_from_user(&eeprom, addr, sizeof(eeprom)))
592                                 return -EFAULT;
593
594                         addr += offsetof(struct ethtool_eeprom, data);
595                         return ixgb_ethtool_seeprom(adapter, &eeprom, addr);
596                 }
597         case ETHTOOL_GPAUSEPARAM:{
598                         struct ethtool_pauseparam epause =
599                             { ETHTOOL_GPAUSEPARAM };
600                         ixgb_ethtool_gpause(adapter, &epause);
601                         if (copy_to_user(addr, &epause, sizeof(epause)))
602                                 return -EFAULT;
603                         return 0;
604                 }
605         case ETHTOOL_SPAUSEPARAM:{
606                         struct ethtool_pauseparam epause;
607                         if (copy_from_user(&epause, addr, sizeof(epause)))
608                                 return -EFAULT;
609                         return ixgb_ethtool_spause(adapter, &epause);
610                 }
611         case ETHTOOL_GSTATS:{
612                         struct {
613                                 struct ethtool_stats eth_stats;
614                                 uint64_t data[IXGB_STATS_LEN];
615                         } stats = { {
616                         ETHTOOL_GSTATS, IXGB_STATS_LEN}};
617                         int i;
618
619                         for (i = 0; i < IXGB_STATS_LEN; i++)
620                                 stats.data[i] =
621                                     (ixgb_gstrings_stats[i].sizeof_stat ==
622                                      sizeof(uint64_t)) ? *(uint64_t *) ((char *)
623                                                                         adapter
624                                                                         +
625                                                                         ixgb_gstrings_stats
626                                                                         [i].
627                                                                         stat_offset)
628                                     : *(uint32_t *) ((char *)adapter +
629                                                      ixgb_gstrings_stats[i].
630                                                      stat_offset);
631                         if (copy_to_user(addr, &stats, sizeof(stats)))
632                                 return -EFAULT;
633                         return 0;
634                 }
635         case ETHTOOL_GRXCSUM:{
636                         struct ethtool_value edata = { ETHTOOL_GRXCSUM };
637
638                         edata.data = adapter->rx_csum;
639                         if (copy_to_user(addr, &edata, sizeof(edata)))
640                                 return -EFAULT;
641                         return 0;
642                 }
643         case ETHTOOL_SRXCSUM:{
644                         struct ethtool_value edata;
645
646                         if (copy_from_user(&edata, addr, sizeof(edata)))
647                                 return -EFAULT;
648                         adapter->rx_csum = edata.data;
649                         ixgb_down(adapter, TRUE);
650                         ixgb_up(adapter);
651                         return 0;
652                 }
653         case ETHTOOL_GTXCSUM:{
654                         struct ethtool_value edata = { ETHTOOL_GTXCSUM };
655
656                         edata.data = (netdev->features & NETIF_F_HW_CSUM) != 0;
657                         if (copy_to_user(addr, &edata, sizeof(edata)))
658                                 return -EFAULT;
659                         return 0;
660                 }
661         case ETHTOOL_STXCSUM:{
662                         struct ethtool_value edata;
663
664                         if (copy_from_user(&edata, addr, sizeof(edata)))
665                                 return -EFAULT;
666
667                         if (edata.data)
668                                 netdev->features |= NETIF_F_HW_CSUM;
669                         else
670                                 netdev->features &= ~NETIF_F_HW_CSUM;
671
672                         return 0;
673                 }
674         case ETHTOOL_GSG:{
675                         struct ethtool_value edata = { ETHTOOL_GSG };
676
677                         edata.data = (netdev->features & NETIF_F_SG) != 0;
678                         if (copy_to_user(addr, &edata, sizeof(edata)))
679                                 return -EFAULT;
680                         return 0;
681                 }
682         case ETHTOOL_SSG:{
683                         struct ethtool_value edata;
684
685                         if (copy_from_user(&edata, addr, sizeof(edata)))
686                                 return -EFAULT;
687
688                         if (edata.data)
689                                 netdev->features |= NETIF_F_SG;
690                         else
691                                 netdev->features &= ~NETIF_F_SG;
692
693                         return 0;
694                 }
695 #ifdef NETIF_F_TSO
696         case ETHTOOL_GTSO:{
697                         struct ethtool_value edata = { ETHTOOL_GTSO };
698
699                         edata.data = (netdev->features & NETIF_F_TSO) != 0;
700                         if (copy_to_user(addr, &edata, sizeof(edata)))
701                                 return -EFAULT;
702                         return 0;
703                 }
704         case ETHTOOL_STSO:{
705                         struct ethtool_value edata;
706
707                         if (copy_from_user(&edata, addr, sizeof(edata)))
708                                 return -EFAULT;
709
710                         if (edata.data)
711                                 netdev->features |= NETIF_F_TSO;
712                         else
713                                 netdev->features &= ~NETIF_F_TSO;
714
715                         return 0;
716                 }
717 #endif
718         default:
719                 return -EOPNOTSUPP;
720         }
721 }