Loading...
Note: File does not exist in v6.13.7.
1/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
4 * Copyright(c) 2013 - 2014 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 <e1000-devel@lists.sourceforge.net>
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
30struct 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. */
41static 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 **/
72static 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 **/
94static 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 **/
110static 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 **/
139static 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 **/
172static 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 **/
186static 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 **/
199static 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 **/
218static 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 **/
239static 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 int i;
245
246 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
247 return -EINVAL;
248
249 new_tx_count = clamp_t(u32, ring->tx_pending,
250 I40EVF_MIN_TXD,
251 I40EVF_MAX_TXD);
252 new_tx_count = ALIGN(new_tx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
253
254 new_rx_count = clamp_t(u32, ring->rx_pending,
255 I40EVF_MIN_RXD,
256 I40EVF_MAX_RXD);
257 new_rx_count = ALIGN(new_rx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
258
259 /* if nothing to do return success */
260 if ((new_tx_count == adapter->tx_rings[0]->count) &&
261 (new_rx_count == adapter->rx_rings[0]->count))
262 return 0;
263
264 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
265 adapter->tx_rings[0]->count = new_tx_count;
266 adapter->rx_rings[0]->count = new_rx_count;
267 }
268
269 if (netif_running(netdev))
270 i40evf_reinit_locked(adapter);
271 return 0;
272}
273
274/**
275 * i40evf_get_coalesce - Get interrupt coalescing settings
276 * @netdev: network interface device structure
277 * @ec: ethtool coalesce structure
278 *
279 * Returns current coalescing settings. This is referred to elsewhere in the
280 * driver as Interrupt Throttle Rate, as this is how the hardware describes
281 * this functionality.
282 **/
283static int i40evf_get_coalesce(struct net_device *netdev,
284 struct ethtool_coalesce *ec)
285{
286 struct i40evf_adapter *adapter = netdev_priv(netdev);
287 struct i40e_vsi *vsi = &adapter->vsi;
288
289 ec->tx_max_coalesced_frames = vsi->work_limit;
290 ec->rx_max_coalesced_frames = vsi->work_limit;
291
292 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
293 ec->rx_coalesce_usecs = 1;
294 else
295 ec->rx_coalesce_usecs = vsi->rx_itr_setting;
296
297 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
298 ec->tx_coalesce_usecs = 1;
299 else
300 ec->tx_coalesce_usecs = vsi->tx_itr_setting;
301
302 return 0;
303}
304
305/**
306 * i40evf_set_coalesce - Set interrupt coalescing settings
307 * @netdev: network interface device structure
308 * @ec: ethtool coalesce structure
309 *
310 * Change current coalescing settings.
311 **/
312static int i40evf_set_coalesce(struct net_device *netdev,
313 struct ethtool_coalesce *ec)
314{
315 struct i40evf_adapter *adapter = netdev_priv(netdev);
316 struct i40e_hw *hw = &adapter->hw;
317 struct i40e_vsi *vsi = &adapter->vsi;
318 struct i40e_q_vector *q_vector;
319 int i;
320
321 if (ec->tx_max_coalesced_frames || ec->rx_max_coalesced_frames)
322 vsi->work_limit = ec->tx_max_coalesced_frames;
323
324 switch (ec->rx_coalesce_usecs) {
325 case 0:
326 vsi->rx_itr_setting = 0;
327 break;
328 case 1:
329 vsi->rx_itr_setting = (I40E_ITR_DYNAMIC
330 | ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
331 break;
332 default:
333 if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
334 (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1)))
335 return -EINVAL;
336 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
337 break;
338 }
339
340 switch (ec->tx_coalesce_usecs) {
341 case 0:
342 vsi->tx_itr_setting = 0;
343 break;
344 case 1:
345 vsi->tx_itr_setting = (I40E_ITR_DYNAMIC
346 | ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
347 break;
348 default:
349 if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
350 (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1)))
351 return -EINVAL;
352 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
353 break;
354 }
355
356 for (i = 0; i < adapter->num_msix_vectors - NONQ_VECS; i++) {
357 q_vector = adapter->q_vector[i];
358 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
359 wr32(hw, I40E_VFINT_ITRN1(0, i), q_vector->rx.itr);
360 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
361 wr32(hw, I40E_VFINT_ITRN1(1, i), q_vector->tx.itr);
362 i40e_flush(hw);
363 }
364
365 return 0;
366}
367
368static struct ethtool_ops i40evf_ethtool_ops = {
369 .get_settings = i40evf_get_settings,
370 .get_drvinfo = i40evf_get_drvinfo,
371 .get_link = ethtool_op_get_link,
372 .get_ringparam = i40evf_get_ringparam,
373 .set_ringparam = i40evf_set_ringparam,
374 .get_strings = i40evf_get_strings,
375 .get_ethtool_stats = i40evf_get_ethtool_stats,
376 .get_sset_count = i40evf_get_sset_count,
377 .get_msglevel = i40evf_get_msglevel,
378 .set_msglevel = i40evf_set_msglevel,
379 .get_coalesce = i40evf_get_coalesce,
380 .set_coalesce = i40evf_set_coalesce,
381};
382
383/**
384 * i40evf_set_ethtool_ops - Initialize ethtool ops struct
385 * @netdev: network interface device structure
386 *
387 * Sets ethtool ops struct in our netdev so that ethtool can call
388 * our functions.
389 **/
390void i40evf_set_ethtool_ops(struct net_device *netdev)
391{
392 SET_ETHTOOL_OPS(netdev, &i40evf_ethtool_ops);
393}