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