Skip to content

Commit fbb7ddf

Browse files
Greg RoseJeff Kirsher
authored andcommitted
i40evf: core ethtool functionality
This patch contains the ethtool interface and related functionality. Since the VF driver is mostly unaware of link, much of that functionality is unused. The driver implements ethtool hooks for statistics, driver info, and some basic non-link-related driver settings. Signed-off-by: Mitch Williams <[email protected]> Signed-off-by: Greg Rose <[email protected]> Tested-by: Sibai Li <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent 7f12ad7 commit fbb7ddf

File tree

1 file changed

+390
-0
lines changed

1 file changed

+390
-0
lines changed
Lines changed: 390 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,390 @@
1+
/*******************************************************************************
2+
*
3+
* Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
4+
* Copyright(c) 2013 Intel Corporation.
5+
*
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.
9+
*
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
13+
* more details.
14+
*
15+
* The full GNU General Public License is included in this distribution in
16+
* the file called "COPYING".
17+
*
18+
* Contact Information:
19+
* e1000-devel Mailing List <[email protected]>
20+
* Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
21+
*
22+
******************************************************************************/
23+
24+
/* ethtool support for i40evf */
25+
#include "i40evf.h"
26+
27+
#include <linux/uaccess.h>
28+
29+
30+
struct i40evf_stats {
31+
char stat_string[ETH_GSTRING_LEN];
32+
int stat_offset;
33+
};
34+
35+
#define I40EVF_STAT(_name, _stat) { \
36+
.stat_string = _name, \
37+
.stat_offset = offsetof(struct i40evf_adapter, _stat) \
38+
}
39+
40+
/* All stats are u64, so we don't need to track the size of the field. */
41+
static const struct i40evf_stats i40evf_gstrings_stats[] = {
42+
I40EVF_STAT("rx_bytes", current_stats.rx_bytes),
43+
I40EVF_STAT("rx_unicast", current_stats.rx_unicast),
44+
I40EVF_STAT("rx_multicast", current_stats.rx_multicast),
45+
I40EVF_STAT("rx_broadcast", current_stats.rx_broadcast),
46+
I40EVF_STAT("rx_discards", current_stats.rx_discards),
47+
I40EVF_STAT("rx_errors", current_stats.rx_errors),
48+
I40EVF_STAT("rx_missed", current_stats.rx_missed),
49+
I40EVF_STAT("rx_unknown_protocol", current_stats.rx_unknown_protocol),
50+
I40EVF_STAT("tx_bytes", current_stats.tx_bytes),
51+
I40EVF_STAT("tx_unicast", current_stats.tx_unicast),
52+
I40EVF_STAT("tx_multicast", current_stats.tx_multicast),
53+
I40EVF_STAT("tx_broadcast", current_stats.tx_broadcast),
54+
I40EVF_STAT("tx_discards", current_stats.tx_discards),
55+
I40EVF_STAT("tx_errors", current_stats.tx_errors),
56+
};
57+
58+
#define I40EVF_GLOBAL_STATS_LEN ARRAY_SIZE(i40evf_gstrings_stats)
59+
#define I40EVF_QUEUE_STATS_LEN \
60+
(((struct i40evf_adapter *) \
61+
netdev_priv(netdev))->vsi_res->num_queue_pairs * 4)
62+
#define I40EVF_STATS_LEN (I40EVF_GLOBAL_STATS_LEN + I40EVF_QUEUE_STATS_LEN)
63+
64+
/**
65+
* i40evf_get_settings - Get Link Speed and Duplex settings
66+
* @netdev: network interface device structure
67+
* @ecmd: ethtool command
68+
*
69+
* Reports speed/duplex settings. Because this is a VF, we don't know what
70+
* kind of link we really have, so we fake it.
71+
**/
72+
static int i40evf_get_settings(struct net_device *netdev,
73+
struct ethtool_cmd *ecmd)
74+
{
75+
/* In the future the VF will be able to query the PF for
76+
* some information - for now use a dummy value
77+
*/
78+
ecmd->supported = SUPPORTED_10000baseT_Full;
79+
ecmd->autoneg = AUTONEG_DISABLE;
80+
ecmd->transceiver = XCVR_DUMMY1;
81+
ecmd->port = PORT_NONE;
82+
83+
return 0;
84+
}
85+
86+
/**
87+
* i40evf_get_sset_count - Get length of string set
88+
* @netdev: network interface device structure
89+
* @sset: id of string set
90+
*
91+
* Reports size of string table. This driver only supports
92+
* strings for statistics.
93+
**/
94+
static int i40evf_get_sset_count(struct net_device *netdev, int sset)
95+
{
96+
if (sset == ETH_SS_STATS)
97+
return I40EVF_STATS_LEN;
98+
else
99+
return -ENOTSUPP;
100+
}
101+
102+
/**
103+
* i40evf_get_ethtool_stats - report device statistics
104+
* @netdev: network interface device structure
105+
* @stats: ethtool statistics structure
106+
* @data: pointer to data buffer
107+
*
108+
* All statistics are added to the data buffer as an array of u64.
109+
**/
110+
static void i40evf_get_ethtool_stats(struct net_device *netdev,
111+
struct ethtool_stats *stats, u64 *data)
112+
{
113+
struct i40evf_adapter *adapter = netdev_priv(netdev);
114+
int i, j;
115+
char *p;
116+
117+
for (i = 0; i < I40EVF_GLOBAL_STATS_LEN; i++) {
118+
p = (char *)adapter + i40evf_gstrings_stats[i].stat_offset;
119+
data[i] = *(u64 *)p;
120+
}
121+
for (j = 0; j < adapter->vsi_res->num_queue_pairs; j++) {
122+
data[i++] = adapter->tx_rings[j]->stats.packets;
123+
data[i++] = adapter->tx_rings[j]->stats.bytes;
124+
}
125+
for (j = 0; j < adapter->vsi_res->num_queue_pairs; j++) {
126+
data[i++] = adapter->rx_rings[j]->stats.packets;
127+
data[i++] = adapter->rx_rings[j]->stats.bytes;
128+
}
129+
}
130+
131+
/**
132+
* i40evf_get_strings - Get string set
133+
* @netdev: network interface device structure
134+
* @sset: id of string set
135+
* @data: buffer for string data
136+
*
137+
* Builds stats string table.
138+
**/
139+
static void i40evf_get_strings(struct net_device *netdev, u32 sset, u8 *data)
140+
{
141+
struct i40evf_adapter *adapter = netdev_priv(netdev);
142+
u8 *p = data;
143+
int i;
144+
145+
if (sset == ETH_SS_STATS) {
146+
for (i = 0; i < I40EVF_GLOBAL_STATS_LEN; i++) {
147+
memcpy(p, i40evf_gstrings_stats[i].stat_string,
148+
ETH_GSTRING_LEN);
149+
p += ETH_GSTRING_LEN;
150+
}
151+
for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
152+
snprintf(p, ETH_GSTRING_LEN, "tx-%u.packets", i);
153+
p += ETH_GSTRING_LEN;
154+
snprintf(p, ETH_GSTRING_LEN, "tx-%u.bytes", i);
155+
p += ETH_GSTRING_LEN;
156+
}
157+
for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
158+
snprintf(p, ETH_GSTRING_LEN, "rx-%u.packets", i);
159+
p += ETH_GSTRING_LEN;
160+
snprintf(p, ETH_GSTRING_LEN, "rx-%u.bytes", i);
161+
p += ETH_GSTRING_LEN;
162+
}
163+
}
164+
}
165+
166+
/**
167+
* i40evf_get_msglevel - Get debug message level
168+
* @netdev: network interface device structure
169+
*
170+
* Returns current debug message level.
171+
**/
172+
static u32 i40evf_get_msglevel(struct net_device *netdev)
173+
{
174+
struct i40evf_adapter *adapter = netdev_priv(netdev);
175+
return adapter->msg_enable;
176+
}
177+
178+
/**
179+
* i40evf_get_msglevel - Set debug message level
180+
* @netdev: network interface device structure
181+
* @data: message level
182+
*
183+
* Set current debug message level. Higher values cause the driver to
184+
* be noisier.
185+
**/
186+
static void i40evf_set_msglevel(struct net_device *netdev, u32 data)
187+
{
188+
struct i40evf_adapter *adapter = netdev_priv(netdev);
189+
adapter->msg_enable = data;
190+
}
191+
192+
/**
193+
* i40evf_get_drvinto - Get driver info
194+
* @netdev: network interface device structure
195+
* @drvinfo: ethool driver info structure
196+
*
197+
* Returns information about the driver and device for display to the user.
198+
**/
199+
static void i40evf_get_drvinfo(struct net_device *netdev,
200+
struct ethtool_drvinfo *drvinfo)
201+
{
202+
struct i40evf_adapter *adapter = netdev_priv(netdev);
203+
204+
strlcpy(drvinfo->driver, i40evf_driver_name, 32);
205+
strlcpy(drvinfo->version, i40evf_driver_version, 32);
206+
207+
strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
208+
}
209+
210+
/**
211+
* i40evf_get_ringparam - Get ring parameters
212+
* @netdev: network interface device structure
213+
* @ring: ethtool ringparam structure
214+
*
215+
* Returns current ring parameters. TX and RX rings are reported separately,
216+
* but the number of rings is not reported.
217+
**/
218+
static void i40evf_get_ringparam(struct net_device *netdev,
219+
struct ethtool_ringparam *ring)
220+
{
221+
struct i40evf_adapter *adapter = netdev_priv(netdev);
222+
struct i40e_ring *tx_ring = adapter->tx_rings[0];
223+
struct i40e_ring *rx_ring = adapter->rx_rings[0];
224+
225+
ring->rx_max_pending = I40EVF_MAX_RXD;
226+
ring->tx_max_pending = I40EVF_MAX_TXD;
227+
ring->rx_pending = rx_ring->count;
228+
ring->tx_pending = tx_ring->count;
229+
}
230+
231+
/**
232+
* i40evf_set_ringparam - Set ring parameters
233+
* @netdev: network interface device structure
234+
* @ring: ethtool ringparam structure
235+
*
236+
* Sets ring parameters. TX and RX rings are controlled separately, but the
237+
* number of rings is not specified, so all rings get the same settings.
238+
**/
239+
static int i40evf_set_ringparam(struct net_device *netdev,
240+
struct ethtool_ringparam *ring)
241+
{
242+
struct i40evf_adapter *adapter = netdev_priv(netdev);
243+
u32 new_rx_count, new_tx_count;
244+
245+
if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
246+
return -EINVAL;
247+
248+
new_tx_count = clamp_t(u32, ring->tx_pending,
249+
I40EVF_MIN_TXD,
250+
I40EVF_MAX_TXD);
251+
new_tx_count = ALIGN(new_tx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
252+
253+
new_rx_count = clamp_t(u32, ring->rx_pending,
254+
I40EVF_MIN_RXD,
255+
I40EVF_MAX_RXD);
256+
new_rx_count = ALIGN(new_rx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
257+
258+
/* if nothing to do return success */
259+
if ((new_tx_count == adapter->txd_count) &&
260+
(new_rx_count == adapter->rxd_count))
261+
return 0;
262+
263+
adapter->txd_count = new_tx_count;
264+
adapter->rxd_count = new_rx_count;
265+
266+
if (netif_running(netdev))
267+
i40evf_reinit_locked(adapter);
268+
return 0;
269+
}
270+
271+
/**
272+
* i40evf_get_coalesce - Get interrupt coalescing settings
273+
* @netdev: network interface device structure
274+
* @ec: ethtool coalesce structure
275+
*
276+
* Returns current coalescing settings. This is referred to elsewhere in the
277+
* driver as Interrupt Throttle Rate, as this is how the hardware describes
278+
* this functionality.
279+
**/
280+
static int i40evf_get_coalesce(struct net_device *netdev,
281+
struct ethtool_coalesce *ec)
282+
{
283+
struct i40evf_adapter *adapter = netdev_priv(netdev);
284+
struct i40e_vsi *vsi = &adapter->vsi;
285+
286+
ec->tx_max_coalesced_frames = vsi->work_limit;
287+
ec->rx_max_coalesced_frames = vsi->work_limit;
288+
289+
if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
290+
ec->rx_coalesce_usecs = 1;
291+
else
292+
ec->rx_coalesce_usecs = vsi->rx_itr_setting;
293+
294+
if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
295+
ec->tx_coalesce_usecs = 1;
296+
else
297+
ec->tx_coalesce_usecs = vsi->tx_itr_setting;
298+
299+
return 0;
300+
}
301+
302+
/**
303+
* i40evf_set_coalesce - Set interrupt coalescing settings
304+
* @netdev: network interface device structure
305+
* @ec: ethtool coalesce structure
306+
*
307+
* Change current coalescing settings.
308+
**/
309+
static int i40evf_set_coalesce(struct net_device *netdev,
310+
struct ethtool_coalesce *ec)
311+
{
312+
struct i40evf_adapter *adapter = netdev_priv(netdev);
313+
struct i40e_hw *hw = &adapter->hw;
314+
struct i40e_vsi *vsi = &adapter->vsi;
315+
struct i40e_q_vector *q_vector;
316+
int i;
317+
318+
if (ec->tx_max_coalesced_frames || ec->rx_max_coalesced_frames)
319+
vsi->work_limit = ec->tx_max_coalesced_frames;
320+
321+
switch (ec->rx_coalesce_usecs) {
322+
case 0:
323+
vsi->rx_itr_setting = 0;
324+
break;
325+
case 1:
326+
vsi->rx_itr_setting = (I40E_ITR_DYNAMIC
327+
| ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
328+
break;
329+
default:
330+
if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
331+
(ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1)))
332+
return -EINVAL;
333+
vsi->rx_itr_setting = ec->rx_coalesce_usecs;
334+
break;
335+
}
336+
337+
switch (ec->tx_coalesce_usecs) {
338+
case 0:
339+
vsi->tx_itr_setting = 0;
340+
break;
341+
case 1:
342+
vsi->tx_itr_setting = (I40E_ITR_DYNAMIC
343+
| ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
344+
break;
345+
default:
346+
if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
347+
(ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1)))
348+
return -EINVAL;
349+
vsi->tx_itr_setting = ec->tx_coalesce_usecs;
350+
break;
351+
}
352+
353+
for (i = 0; i < adapter->num_msix_vectors - NONQ_VECS; i++) {
354+
q_vector = adapter->q_vector[i];
355+
q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
356+
wr32(hw, I40E_VFINT_ITRN1(0, i), q_vector->rx.itr);
357+
q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
358+
wr32(hw, I40E_VFINT_ITRN1(1, i), q_vector->tx.itr);
359+
i40e_flush(hw);
360+
}
361+
362+
return 0;
363+
}
364+
365+
static struct ethtool_ops i40evf_ethtool_ops = {
366+
.get_settings = i40evf_get_settings,
367+
.get_drvinfo = i40evf_get_drvinfo,
368+
.get_link = ethtool_op_get_link,
369+
.get_ringparam = i40evf_get_ringparam,
370+
.set_ringparam = i40evf_set_ringparam,
371+
.get_strings = i40evf_get_strings,
372+
.get_ethtool_stats = i40evf_get_ethtool_stats,
373+
.get_sset_count = i40evf_get_sset_count,
374+
.get_msglevel = i40evf_get_msglevel,
375+
.set_msglevel = i40evf_set_msglevel,
376+
.get_coalesce = i40evf_get_coalesce,
377+
.set_coalesce = i40evf_set_coalesce,
378+
};
379+
380+
/**
381+
* i40evf_set_ethtool_ops - Initialize ethtool ops struct
382+
* @netdev: network interface device structure
383+
*
384+
* Sets ethtool ops struct in our netdev so that ethtool can call
385+
* our functions.
386+
**/
387+
void i40evf_set_ethtool_ops(struct net_device *netdev)
388+
{
389+
SET_ETHTOOL_OPS(netdev, &i40evf_ethtool_ops);
390+
}

0 commit comments

Comments
 (0)