1 /*******************************************************************************
3 Intel(R) 82576 Virtual Function Linux driver
4 Copyright(c) 2009 - 2012 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
28 /* ethtool support for igbvf */
30 #include <linux/netdevice.h>
31 #include <linux/ethtool.h>
32 #include <linux/pci.h>
33 #include <linux/vmalloc.h>
34 #include <linux/delay.h>
37 #include <linux/if_vlan.h>
41 char stat_string
[ETH_GSTRING_LEN
];
47 #define IGBVF_STAT(current, base) \
48 sizeof(((struct igbvf_adapter *)0)->current), \
49 offsetof(struct igbvf_adapter, current), \
50 offsetof(struct igbvf_adapter, base)
52 static const struct igbvf_stats igbvf_gstrings_stats
[] = {
53 { "rx_packets", IGBVF_STAT(stats
.gprc
, stats
.base_gprc
) },
54 { "tx_packets", IGBVF_STAT(stats
.gptc
, stats
.base_gptc
) },
55 { "rx_bytes", IGBVF_STAT(stats
.gorc
, stats
.base_gorc
) },
56 { "tx_bytes", IGBVF_STAT(stats
.gotc
, stats
.base_gotc
) },
57 { "multicast", IGBVF_STAT(stats
.mprc
, stats
.base_mprc
) },
58 { "lbrx_bytes", IGBVF_STAT(stats
.gorlbc
, stats
.base_gorlbc
) },
59 { "lbrx_packets", IGBVF_STAT(stats
.gprlbc
, stats
.base_gprlbc
) },
60 { "tx_restart_queue", IGBVF_STAT(restart_queue
, zero_base
) },
61 { "rx_long_byte_count", IGBVF_STAT(stats
.gorc
, stats
.base_gorc
) },
62 { "rx_csum_offload_good", IGBVF_STAT(hw_csum_good
, zero_base
) },
63 { "rx_csum_offload_errors", IGBVF_STAT(hw_csum_err
, zero_base
) },
64 { "rx_header_split", IGBVF_STAT(rx_hdr_split
, zero_base
) },
65 { "alloc_rx_buff_failed", IGBVF_STAT(alloc_rx_buff_failed
, zero_base
) },
68 #define IGBVF_GLOBAL_STATS_LEN ARRAY_SIZE(igbvf_gstrings_stats)
70 static const char igbvf_gstrings_test
[][ETH_GSTRING_LEN
] = {
71 "Link test (on/offline)"
74 #define IGBVF_TEST_LEN ARRAY_SIZE(igbvf_gstrings_test)
76 static int igbvf_get_settings(struct net_device
*netdev
,
77 struct ethtool_cmd
*ecmd
)
79 struct igbvf_adapter
*adapter
= netdev_priv(netdev
);
80 struct e1000_hw
*hw
= &adapter
->hw
;
83 ecmd
->supported
= SUPPORTED_1000baseT_Full
;
85 ecmd
->advertising
= ADVERTISED_1000baseT_Full
;
88 ecmd
->transceiver
= XCVR_DUMMY1
;
90 status
= er32(STATUS
);
91 if (status
& E1000_STATUS_LU
) {
92 if (status
& E1000_STATUS_SPEED_1000
)
93 ethtool_cmd_speed_set(ecmd
, SPEED_1000
);
94 else if (status
& E1000_STATUS_SPEED_100
)
95 ethtool_cmd_speed_set(ecmd
, SPEED_100
);
97 ethtool_cmd_speed_set(ecmd
, SPEED_10
);
99 if (status
& E1000_STATUS_FD
)
100 ecmd
->duplex
= DUPLEX_FULL
;
102 ecmd
->duplex
= DUPLEX_HALF
;
104 ethtool_cmd_speed_set(ecmd
, -1);
108 ecmd
->autoneg
= AUTONEG_DISABLE
;
113 static int igbvf_set_settings(struct net_device
*netdev
,
114 struct ethtool_cmd
*ecmd
)
119 static void igbvf_get_pauseparam(struct net_device
*netdev
,
120 struct ethtool_pauseparam
*pause
)
125 static int igbvf_set_pauseparam(struct net_device
*netdev
,
126 struct ethtool_pauseparam
*pause
)
131 static u32
igbvf_get_msglevel(struct net_device
*netdev
)
133 struct igbvf_adapter
*adapter
= netdev_priv(netdev
);
134 return adapter
->msg_enable
;
137 static void igbvf_set_msglevel(struct net_device
*netdev
, u32 data
)
139 struct igbvf_adapter
*adapter
= netdev_priv(netdev
);
140 adapter
->msg_enable
= data
;
143 static int igbvf_get_regs_len(struct net_device
*netdev
)
145 #define IGBVF_REGS_LEN 8
146 return IGBVF_REGS_LEN
* sizeof(u32
);
149 static void igbvf_get_regs(struct net_device
*netdev
,
150 struct ethtool_regs
*regs
, void *p
)
152 struct igbvf_adapter
*adapter
= netdev_priv(netdev
);
153 struct e1000_hw
*hw
= &adapter
->hw
;
156 memset(p
, 0, IGBVF_REGS_LEN
* sizeof(u32
));
158 regs
->version
= (1 << 24) | (adapter
->pdev
->revision
<< 16) |
159 adapter
->pdev
->device
;
161 regs_buff
[0] = er32(CTRL
);
162 regs_buff
[1] = er32(STATUS
);
164 regs_buff
[2] = er32(RDLEN(0));
165 regs_buff
[3] = er32(RDH(0));
166 regs_buff
[4] = er32(RDT(0));
168 regs_buff
[5] = er32(TDLEN(0));
169 regs_buff
[6] = er32(TDH(0));
170 regs_buff
[7] = er32(TDT(0));
173 static int igbvf_get_eeprom_len(struct net_device
*netdev
)
178 static int igbvf_get_eeprom(struct net_device
*netdev
,
179 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
184 static int igbvf_set_eeprom(struct net_device
*netdev
,
185 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
190 static void igbvf_get_drvinfo(struct net_device
*netdev
,
191 struct ethtool_drvinfo
*drvinfo
)
193 struct igbvf_adapter
*adapter
= netdev_priv(netdev
);
195 strlcpy(drvinfo
->driver
, igbvf_driver_name
, sizeof(drvinfo
->driver
));
196 strlcpy(drvinfo
->version
, igbvf_driver_version
,
197 sizeof(drvinfo
->version
));
198 strlcpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
),
199 sizeof(drvinfo
->bus_info
));
200 drvinfo
->regdump_len
= igbvf_get_regs_len(netdev
);
201 drvinfo
->eedump_len
= igbvf_get_eeprom_len(netdev
);
204 static void igbvf_get_ringparam(struct net_device
*netdev
,
205 struct ethtool_ringparam
*ring
)
207 struct igbvf_adapter
*adapter
= netdev_priv(netdev
);
208 struct igbvf_ring
*tx_ring
= adapter
->tx_ring
;
209 struct igbvf_ring
*rx_ring
= adapter
->rx_ring
;
211 ring
->rx_max_pending
= IGBVF_MAX_RXD
;
212 ring
->tx_max_pending
= IGBVF_MAX_TXD
;
213 ring
->rx_pending
= rx_ring
->count
;
214 ring
->tx_pending
= tx_ring
->count
;
217 static int igbvf_set_ringparam(struct net_device
*netdev
,
218 struct ethtool_ringparam
*ring
)
220 struct igbvf_adapter
*adapter
= netdev_priv(netdev
);
221 struct igbvf_ring
*temp_ring
;
223 u32 new_rx_count
, new_tx_count
;
225 if ((ring
->rx_mini_pending
) || (ring
->rx_jumbo_pending
))
228 new_rx_count
= max(ring
->rx_pending
, (u32
)IGBVF_MIN_RXD
);
229 new_rx_count
= min(new_rx_count
, (u32
)IGBVF_MAX_RXD
);
230 new_rx_count
= ALIGN(new_rx_count
, REQ_RX_DESCRIPTOR_MULTIPLE
);
232 new_tx_count
= max(ring
->tx_pending
, (u32
)IGBVF_MIN_TXD
);
233 new_tx_count
= min(new_tx_count
, (u32
)IGBVF_MAX_TXD
);
234 new_tx_count
= ALIGN(new_tx_count
, REQ_TX_DESCRIPTOR_MULTIPLE
);
236 if ((new_tx_count
== adapter
->tx_ring
->count
) &&
237 (new_rx_count
== adapter
->rx_ring
->count
)) {
242 while (test_and_set_bit(__IGBVF_RESETTING
, &adapter
->state
))
245 if (!netif_running(adapter
->netdev
)) {
246 adapter
->tx_ring
->count
= new_tx_count
;
247 adapter
->rx_ring
->count
= new_rx_count
;
251 temp_ring
= vmalloc(sizeof(struct igbvf_ring
));
260 * We can't just free everything and then setup again,
261 * because the ISRs in MSI-X mode get passed pointers
262 * to the tx and rx ring structs.
264 if (new_tx_count
!= adapter
->tx_ring
->count
) {
265 memcpy(temp_ring
, adapter
->tx_ring
, sizeof(struct igbvf_ring
));
267 temp_ring
->count
= new_tx_count
;
268 err
= igbvf_setup_tx_resources(adapter
, temp_ring
);
272 igbvf_free_tx_resources(adapter
->tx_ring
);
274 memcpy(adapter
->tx_ring
, temp_ring
, sizeof(struct igbvf_ring
));
277 if (new_rx_count
!= adapter
->rx_ring
->count
) {
278 memcpy(temp_ring
, adapter
->rx_ring
, sizeof(struct igbvf_ring
));
280 temp_ring
->count
= new_rx_count
;
281 err
= igbvf_setup_rx_resources(adapter
, temp_ring
);
285 igbvf_free_rx_resources(adapter
->rx_ring
);
287 memcpy(adapter
->rx_ring
, temp_ring
,sizeof(struct igbvf_ring
));
293 clear_bit(__IGBVF_RESETTING
, &adapter
->state
);
297 static int igbvf_link_test(struct igbvf_adapter
*adapter
, u64
*data
)
299 struct e1000_hw
*hw
= &adapter
->hw
;
302 hw
->mac
.ops
.check_for_link(hw
);
304 if (!(er32(STATUS
) & E1000_STATUS_LU
))
310 static void igbvf_diag_test(struct net_device
*netdev
,
311 struct ethtool_test
*eth_test
, u64
*data
)
313 struct igbvf_adapter
*adapter
= netdev_priv(netdev
);
315 set_bit(__IGBVF_TESTING
, &adapter
->state
);
318 * Link test performed before hardware reset so autoneg doesn't
319 * interfere with test result
321 if (igbvf_link_test(adapter
, &data
[0]))
322 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
324 clear_bit(__IGBVF_TESTING
, &adapter
->state
);
325 msleep_interruptible(4 * 1000);
328 static void igbvf_get_wol(struct net_device
*netdev
,
329 struct ethtool_wolinfo
*wol
)
335 static int igbvf_set_wol(struct net_device
*netdev
,
336 struct ethtool_wolinfo
*wol
)
341 static int igbvf_get_coalesce(struct net_device
*netdev
,
342 struct ethtool_coalesce
*ec
)
344 struct igbvf_adapter
*adapter
= netdev_priv(netdev
);
346 if (adapter
->itr_setting
<= 3)
347 ec
->rx_coalesce_usecs
= adapter
->itr_setting
;
349 ec
->rx_coalesce_usecs
= adapter
->itr_setting
>> 2;
354 static int igbvf_set_coalesce(struct net_device
*netdev
,
355 struct ethtool_coalesce
*ec
)
357 struct igbvf_adapter
*adapter
= netdev_priv(netdev
);
358 struct e1000_hw
*hw
= &adapter
->hw
;
360 if ((ec
->rx_coalesce_usecs
> IGBVF_MAX_ITR_USECS
) ||
361 ((ec
->rx_coalesce_usecs
> 3) &&
362 (ec
->rx_coalesce_usecs
< IGBVF_MIN_ITR_USECS
)) ||
363 (ec
->rx_coalesce_usecs
== 2))
366 /* convert to rate of irq's per second */
367 if (ec
->rx_coalesce_usecs
&& ec
->rx_coalesce_usecs
<= 3) {
368 adapter
->itr
= IGBVF_START_ITR
;
369 adapter
->itr_setting
= ec
->rx_coalesce_usecs
;
371 adapter
->itr
= ec
->rx_coalesce_usecs
<< 2;
372 adapter
->itr_setting
= adapter
->itr
;
376 hw
->hw_addr
+ adapter
->rx_ring
[0].itr_register
);
381 static int igbvf_nway_reset(struct net_device
*netdev
)
383 struct igbvf_adapter
*adapter
= netdev_priv(netdev
);
384 if (netif_running(netdev
))
385 igbvf_reinit_locked(adapter
);
390 static void igbvf_get_ethtool_stats(struct net_device
*netdev
,
391 struct ethtool_stats
*stats
,
394 struct igbvf_adapter
*adapter
= netdev_priv(netdev
);
397 igbvf_update_stats(adapter
);
398 for (i
= 0; i
< IGBVF_GLOBAL_STATS_LEN
; i
++) {
399 char *p
= (char *)adapter
+
400 igbvf_gstrings_stats
[i
].stat_offset
;
401 char *b
= (char *)adapter
+
402 igbvf_gstrings_stats
[i
].base_stat_offset
;
403 data
[i
] = ((igbvf_gstrings_stats
[i
].sizeof_stat
==
404 sizeof(u64
)) ? (*(u64
*)p
- *(u64
*)b
) :
405 (*(u32
*)p
- *(u32
*)b
));
410 static int igbvf_get_sset_count(struct net_device
*dev
, int stringset
)
414 return IGBVF_TEST_LEN
;
416 return IGBVF_GLOBAL_STATS_LEN
;
422 static void igbvf_get_strings(struct net_device
*netdev
, u32 stringset
,
430 memcpy(data
, *igbvf_gstrings_test
, sizeof(igbvf_gstrings_test
));
433 for (i
= 0; i
< IGBVF_GLOBAL_STATS_LEN
; i
++) {
434 memcpy(p
, igbvf_gstrings_stats
[i
].stat_string
,
436 p
+= ETH_GSTRING_LEN
;
442 static const struct ethtool_ops igbvf_ethtool_ops
= {
443 .get_settings
= igbvf_get_settings
,
444 .set_settings
= igbvf_set_settings
,
445 .get_drvinfo
= igbvf_get_drvinfo
,
446 .get_regs_len
= igbvf_get_regs_len
,
447 .get_regs
= igbvf_get_regs
,
448 .get_wol
= igbvf_get_wol
,
449 .set_wol
= igbvf_set_wol
,
450 .get_msglevel
= igbvf_get_msglevel
,
451 .set_msglevel
= igbvf_set_msglevel
,
452 .nway_reset
= igbvf_nway_reset
,
453 .get_link
= ethtool_op_get_link
,
454 .get_eeprom_len
= igbvf_get_eeprom_len
,
455 .get_eeprom
= igbvf_get_eeprom
,
456 .set_eeprom
= igbvf_set_eeprom
,
457 .get_ringparam
= igbvf_get_ringparam
,
458 .set_ringparam
= igbvf_set_ringparam
,
459 .get_pauseparam
= igbvf_get_pauseparam
,
460 .set_pauseparam
= igbvf_set_pauseparam
,
461 .self_test
= igbvf_diag_test
,
462 .get_sset_count
= igbvf_get_sset_count
,
463 .get_strings
= igbvf_get_strings
,
464 .get_ethtool_stats
= igbvf_get_ethtool_stats
,
465 .get_coalesce
= igbvf_get_coalesce
,
466 .set_coalesce
= igbvf_set_coalesce
,
469 void igbvf_set_ethtool_ops(struct net_device
*netdev
)
471 SET_ETHTOOL_OPS(netdev
, &igbvf_ethtool_ops
);