blob: 2638dfa8910213a7ac5fe7dc220f12e9e56dabf1 [file] [log] [blame]
Greg Rosefbb7ddf2013-12-21 06:12:56 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
Mitch Williams77d77f92014-02-20 19:29:12 -08004 * Copyright(c) 2013 - 2014 Intel Corporation.
Greg Rosefbb7ddf2013-12-21 06:12:56 +00005 *
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 *
Jesse Brandeburgb8316072014-04-05 07:46:11 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
Greg Rosefbb7ddf2013-12-21 06:12:56 +000018 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27/* ethtool support for i40evf */
28#include "i40evf.h"
29
30#include <linux/uaccess.h>
31
32
33struct i40evf_stats {
34 char stat_string[ETH_GSTRING_LEN];
35 int stat_offset;
36};
37
38#define I40EVF_STAT(_name, _stat) { \
39 .stat_string = _name, \
40 .stat_offset = offsetof(struct i40evf_adapter, _stat) \
41}
42
43/* All stats are u64, so we don't need to track the size of the field. */
44static const struct i40evf_stats i40evf_gstrings_stats[] = {
45 I40EVF_STAT("rx_bytes", current_stats.rx_bytes),
46 I40EVF_STAT("rx_unicast", current_stats.rx_unicast),
47 I40EVF_STAT("rx_multicast", current_stats.rx_multicast),
48 I40EVF_STAT("rx_broadcast", current_stats.rx_broadcast),
49 I40EVF_STAT("rx_discards", current_stats.rx_discards),
50 I40EVF_STAT("rx_errors", current_stats.rx_errors),
51 I40EVF_STAT("rx_missed", current_stats.rx_missed),
52 I40EVF_STAT("rx_unknown_protocol", current_stats.rx_unknown_protocol),
53 I40EVF_STAT("tx_bytes", current_stats.tx_bytes),
54 I40EVF_STAT("tx_unicast", current_stats.tx_unicast),
55 I40EVF_STAT("tx_multicast", current_stats.tx_multicast),
56 I40EVF_STAT("tx_broadcast", current_stats.tx_broadcast),
57 I40EVF_STAT("tx_discards", current_stats.tx_discards),
58 I40EVF_STAT("tx_errors", current_stats.tx_errors),
59};
60
61#define I40EVF_GLOBAL_STATS_LEN ARRAY_SIZE(i40evf_gstrings_stats)
62#define I40EVF_QUEUE_STATS_LEN \
63 (((struct i40evf_adapter *) \
64 netdev_priv(netdev))->vsi_res->num_queue_pairs * 4)
65#define I40EVF_STATS_LEN (I40EVF_GLOBAL_STATS_LEN + I40EVF_QUEUE_STATS_LEN)
66
67/**
68 * i40evf_get_settings - Get Link Speed and Duplex settings
69 * @netdev: network interface device structure
70 * @ecmd: ethtool command
71 *
72 * Reports speed/duplex settings. Because this is a VF, we don't know what
73 * kind of link we really have, so we fake it.
74 **/
75static int i40evf_get_settings(struct net_device *netdev,
76 struct ethtool_cmd *ecmd)
77{
78 /* In the future the VF will be able to query the PF for
79 * some information - for now use a dummy value
80 */
81 ecmd->supported = SUPPORTED_10000baseT_Full;
82 ecmd->autoneg = AUTONEG_DISABLE;
83 ecmd->transceiver = XCVR_DUMMY1;
84 ecmd->port = PORT_NONE;
85
86 return 0;
87}
88
89/**
90 * i40evf_get_sset_count - Get length of string set
91 * @netdev: network interface device structure
92 * @sset: id of string set
93 *
94 * Reports size of string table. This driver only supports
95 * strings for statistics.
96 **/
97static int i40evf_get_sset_count(struct net_device *netdev, int sset)
98{
99 if (sset == ETH_SS_STATS)
100 return I40EVF_STATS_LEN;
101 else
102 return -ENOTSUPP;
103}
104
105/**
106 * i40evf_get_ethtool_stats - report device statistics
107 * @netdev: network interface device structure
108 * @stats: ethtool statistics structure
109 * @data: pointer to data buffer
110 *
111 * All statistics are added to the data buffer as an array of u64.
112 **/
113static void i40evf_get_ethtool_stats(struct net_device *netdev,
114 struct ethtool_stats *stats, u64 *data)
115{
116 struct i40evf_adapter *adapter = netdev_priv(netdev);
117 int i, j;
118 char *p;
119
120 for (i = 0; i < I40EVF_GLOBAL_STATS_LEN; i++) {
121 p = (char *)adapter + i40evf_gstrings_stats[i].stat_offset;
122 data[i] = *(u64 *)p;
123 }
124 for (j = 0; j < adapter->vsi_res->num_queue_pairs; j++) {
125 data[i++] = adapter->tx_rings[j]->stats.packets;
126 data[i++] = adapter->tx_rings[j]->stats.bytes;
127 }
128 for (j = 0; j < adapter->vsi_res->num_queue_pairs; j++) {
129 data[i++] = adapter->rx_rings[j]->stats.packets;
130 data[i++] = adapter->rx_rings[j]->stats.bytes;
131 }
132}
133
134/**
135 * i40evf_get_strings - Get string set
136 * @netdev: network interface device structure
137 * @sset: id of string set
138 * @data: buffer for string data
139 *
140 * Builds stats string table.
141 **/
142static void i40evf_get_strings(struct net_device *netdev, u32 sset, u8 *data)
143{
144 struct i40evf_adapter *adapter = netdev_priv(netdev);
145 u8 *p = data;
146 int i;
147
148 if (sset == ETH_SS_STATS) {
149 for (i = 0; i < I40EVF_GLOBAL_STATS_LEN; i++) {
150 memcpy(p, i40evf_gstrings_stats[i].stat_string,
151 ETH_GSTRING_LEN);
152 p += ETH_GSTRING_LEN;
153 }
154 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
155 snprintf(p, ETH_GSTRING_LEN, "tx-%u.packets", i);
156 p += ETH_GSTRING_LEN;
157 snprintf(p, ETH_GSTRING_LEN, "tx-%u.bytes", i);
158 p += ETH_GSTRING_LEN;
159 }
160 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
161 snprintf(p, ETH_GSTRING_LEN, "rx-%u.packets", i);
162 p += ETH_GSTRING_LEN;
163 snprintf(p, ETH_GSTRING_LEN, "rx-%u.bytes", i);
164 p += ETH_GSTRING_LEN;
165 }
166 }
167}
168
169/**
170 * i40evf_get_msglevel - Get debug message level
171 * @netdev: network interface device structure
172 *
173 * Returns current debug message level.
174 **/
175static u32 i40evf_get_msglevel(struct net_device *netdev)
176{
177 struct i40evf_adapter *adapter = netdev_priv(netdev);
178 return adapter->msg_enable;
179}
180
181/**
182 * i40evf_get_msglevel - Set debug message level
183 * @netdev: network interface device structure
184 * @data: message level
185 *
186 * Set current debug message level. Higher values cause the driver to
187 * be noisier.
188 **/
189static void i40evf_set_msglevel(struct net_device *netdev, u32 data)
190{
191 struct i40evf_adapter *adapter = netdev_priv(netdev);
192 adapter->msg_enable = data;
193}
194
195/**
196 * i40evf_get_drvinto - Get driver info
197 * @netdev: network interface device structure
198 * @drvinfo: ethool driver info structure
199 *
200 * Returns information about the driver and device for display to the user.
201 **/
202static void i40evf_get_drvinfo(struct net_device *netdev,
203 struct ethtool_drvinfo *drvinfo)
204{
205 struct i40evf_adapter *adapter = netdev_priv(netdev);
206
207 strlcpy(drvinfo->driver, i40evf_driver_name, 32);
208 strlcpy(drvinfo->version, i40evf_driver_version, 32);
209
210 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
211}
212
213/**
214 * i40evf_get_ringparam - Get ring parameters
215 * @netdev: network interface device structure
216 * @ring: ethtool ringparam structure
217 *
218 * Returns current ring parameters. TX and RX rings are reported separately,
219 * but the number of rings is not reported.
220 **/
221static void i40evf_get_ringparam(struct net_device *netdev,
222 struct ethtool_ringparam *ring)
223{
224 struct i40evf_adapter *adapter = netdev_priv(netdev);
225 struct i40e_ring *tx_ring = adapter->tx_rings[0];
226 struct i40e_ring *rx_ring = adapter->rx_rings[0];
227
228 ring->rx_max_pending = I40EVF_MAX_RXD;
229 ring->tx_max_pending = I40EVF_MAX_TXD;
230 ring->rx_pending = rx_ring->count;
231 ring->tx_pending = tx_ring->count;
232}
233
234/**
235 * i40evf_set_ringparam - Set ring parameters
236 * @netdev: network interface device structure
237 * @ring: ethtool ringparam structure
238 *
239 * Sets ring parameters. TX and RX rings are controlled separately, but the
240 * number of rings is not specified, so all rings get the same settings.
241 **/
242static int i40evf_set_ringparam(struct net_device *netdev,
243 struct ethtool_ringparam *ring)
244{
245 struct i40evf_adapter *adapter = netdev_priv(netdev);
246 u32 new_rx_count, new_tx_count;
Mitch Williams77d77f92014-02-20 19:29:12 -0800247 int i;
Greg Rosefbb7ddf2013-12-21 06:12:56 +0000248
249 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
250 return -EINVAL;
251
252 new_tx_count = clamp_t(u32, ring->tx_pending,
253 I40EVF_MIN_TXD,
254 I40EVF_MAX_TXD);
255 new_tx_count = ALIGN(new_tx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
256
257 new_rx_count = clamp_t(u32, ring->rx_pending,
258 I40EVF_MIN_RXD,
259 I40EVF_MAX_RXD);
260 new_rx_count = ALIGN(new_rx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
261
262 /* if nothing to do return success */
Mitch Williams77d77f92014-02-20 19:29:12 -0800263 if ((new_tx_count == adapter->tx_rings[0]->count) &&
264 (new_rx_count == adapter->rx_rings[0]->count))
Greg Rosefbb7ddf2013-12-21 06:12:56 +0000265 return 0;
266
Mitch Williams77d77f92014-02-20 19:29:12 -0800267 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
268 adapter->tx_rings[0]->count = new_tx_count;
269 adapter->rx_rings[0]->count = new_rx_count;
270 }
Greg Rosefbb7ddf2013-12-21 06:12:56 +0000271
272 if (netif_running(netdev))
273 i40evf_reinit_locked(adapter);
274 return 0;
275}
276
277/**
278 * i40evf_get_coalesce - Get interrupt coalescing settings
279 * @netdev: network interface device structure
280 * @ec: ethtool coalesce structure
281 *
282 * Returns current coalescing settings. This is referred to elsewhere in the
283 * driver as Interrupt Throttle Rate, as this is how the hardware describes
284 * this functionality.
285 **/
286static int i40evf_get_coalesce(struct net_device *netdev,
287 struct ethtool_coalesce *ec)
288{
289 struct i40evf_adapter *adapter = netdev_priv(netdev);
290 struct i40e_vsi *vsi = &adapter->vsi;
291
292 ec->tx_max_coalesced_frames = vsi->work_limit;
293 ec->rx_max_coalesced_frames = vsi->work_limit;
294
295 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
296 ec->rx_coalesce_usecs = 1;
297 else
298 ec->rx_coalesce_usecs = vsi->rx_itr_setting;
299
300 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
301 ec->tx_coalesce_usecs = 1;
302 else
303 ec->tx_coalesce_usecs = vsi->tx_itr_setting;
304
305 return 0;
306}
307
308/**
309 * i40evf_set_coalesce - Set interrupt coalescing settings
310 * @netdev: network interface device structure
311 * @ec: ethtool coalesce structure
312 *
313 * Change current coalescing settings.
314 **/
315static int i40evf_set_coalesce(struct net_device *netdev,
316 struct ethtool_coalesce *ec)
317{
318 struct i40evf_adapter *adapter = netdev_priv(netdev);
319 struct i40e_hw *hw = &adapter->hw;
320 struct i40e_vsi *vsi = &adapter->vsi;
321 struct i40e_q_vector *q_vector;
322 int i;
323
324 if (ec->tx_max_coalesced_frames || ec->rx_max_coalesced_frames)
325 vsi->work_limit = ec->tx_max_coalesced_frames;
326
327 switch (ec->rx_coalesce_usecs) {
328 case 0:
329 vsi->rx_itr_setting = 0;
330 break;
331 case 1:
332 vsi->rx_itr_setting = (I40E_ITR_DYNAMIC
333 | ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
334 break;
335 default:
336 if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
337 (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1)))
338 return -EINVAL;
339 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
340 break;
341 }
342
343 switch (ec->tx_coalesce_usecs) {
344 case 0:
345 vsi->tx_itr_setting = 0;
346 break;
347 case 1:
348 vsi->tx_itr_setting = (I40E_ITR_DYNAMIC
349 | ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
350 break;
351 default:
352 if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
353 (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1)))
354 return -EINVAL;
355 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
356 break;
357 }
358
359 for (i = 0; i < adapter->num_msix_vectors - NONQ_VECS; i++) {
360 q_vector = adapter->q_vector[i];
361 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
362 wr32(hw, I40E_VFINT_ITRN1(0, i), q_vector->rx.itr);
363 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
364 wr32(hw, I40E_VFINT_ITRN1(1, i), q_vector->tx.itr);
365 i40e_flush(hw);
366 }
367
368 return 0;
369}
370
Mitch A Williams4e9dc312014-04-01 04:43:49 +0000371/**
372 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
373 * @adapter: board private structure
374 * @cmd: ethtool rxnfc command
375 *
376 * Returns Success if the flow is supported, else Invalid Input.
377 **/
378static int i40evf_get_rss_hash_opts(struct i40evf_adapter *adapter,
379 struct ethtool_rxnfc *cmd)
380{
381 struct i40e_hw *hw = &adapter->hw;
382 u64 hena = (u64)rd32(hw, I40E_VFQF_HENA(0)) |
383 ((u64)rd32(hw, I40E_VFQF_HENA(1)) << 32);
384
385 /* We always hash on IP src and dest addresses */
386 cmd->data = RXH_IP_SRC | RXH_IP_DST;
387
388 switch (cmd->flow_type) {
389 case TCP_V4_FLOW:
390 if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP))
391 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
392 break;
393 case UDP_V4_FLOW:
394 if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP))
395 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
396 break;
397
398 case SCTP_V4_FLOW:
399 case AH_ESP_V4_FLOW:
400 case AH_V4_FLOW:
401 case ESP_V4_FLOW:
402 case IPV4_FLOW:
403 break;
404
405 case TCP_V6_FLOW:
406 if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP))
407 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
408 break;
409 case UDP_V6_FLOW:
410 if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP))
411 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
412 break;
413
414 case SCTP_V6_FLOW:
415 case AH_ESP_V6_FLOW:
416 case AH_V6_FLOW:
417 case ESP_V6_FLOW:
418 case IPV6_FLOW:
419 break;
420 default:
421 cmd->data = 0;
422 return -EINVAL;
423 }
424
425 return 0;
426}
427
428/**
429 * i40evf_get_rxnfc - command to get RX flow classification rules
430 * @netdev: network interface device structure
431 * @cmd: ethtool rxnfc command
432 *
433 * Returns Success if the command is supported.
434 **/
435static int i40evf_get_rxnfc(struct net_device *netdev,
436 struct ethtool_rxnfc *cmd,
437 u32 *rule_locs)
438{
439 struct i40evf_adapter *adapter = netdev_priv(netdev);
440 int ret = -EOPNOTSUPP;
441
442 switch (cmd->cmd) {
443 case ETHTOOL_GRXRINGS:
444 cmd->data = adapter->vsi_res->num_queue_pairs;
445 ret = 0;
446 break;
447 case ETHTOOL_GRXFH:
448 ret = i40evf_get_rss_hash_opts(adapter, cmd);
449 break;
450 default:
451 break;
452 }
453
454 return ret;
455}
456
457/**
458 * i40evf_set_rss_hash_opt - Enable/Disable flow types for RSS hash
459 * @adapter: board private structure
460 * @cmd: ethtool rxnfc command
461 *
462 * Returns Success if the flow input set is supported.
463 **/
464static int i40evf_set_rss_hash_opt(struct i40evf_adapter *adapter,
465 struct ethtool_rxnfc *nfc)
466{
467 struct i40e_hw *hw = &adapter->hw;
468
469 u64 hena = (u64)rd32(hw, I40E_VFQF_HENA(0)) |
470 ((u64)rd32(hw, I40E_VFQF_HENA(1)) << 32);
471
472 /* RSS does not support anything other than hashing
473 * to queues on src and dst IPs and ports
474 */
475 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
476 RXH_L4_B_0_1 | RXH_L4_B_2_3))
477 return -EINVAL;
478
479 /* We need at least the IP SRC and DEST fields for hashing */
480 if (!(nfc->data & RXH_IP_SRC) ||
481 !(nfc->data & RXH_IP_DST))
482 return -EINVAL;
483
484 switch (nfc->flow_type) {
485 case TCP_V4_FLOW:
486 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
487 case 0:
488 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
489 break;
490 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
491 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
492 break;
493 default:
494 return -EINVAL;
495 }
496 break;
497 case TCP_V6_FLOW:
498 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
499 case 0:
500 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
501 break;
502 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
503 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
504 break;
505 default:
506 return -EINVAL;
507 }
508 break;
509 case UDP_V4_FLOW:
510 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
511 case 0:
512 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
513 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
514 break;
515 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
516 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
517 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
518 break;
519 default:
520 return -EINVAL;
521 }
522 break;
523 case UDP_V6_FLOW:
524 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
525 case 0:
526 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
527 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
528 break;
529 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
530 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
531 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
532 break;
533 default:
534 return -EINVAL;
535 }
536 break;
537 case AH_ESP_V4_FLOW:
538 case AH_V4_FLOW:
539 case ESP_V4_FLOW:
540 case SCTP_V4_FLOW:
541 if ((nfc->data & RXH_L4_B_0_1) ||
542 (nfc->data & RXH_L4_B_2_3))
543 return -EINVAL;
544 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
545 break;
546 case AH_ESP_V6_FLOW:
547 case AH_V6_FLOW:
548 case ESP_V6_FLOW:
549 case SCTP_V6_FLOW:
550 if ((nfc->data & RXH_L4_B_0_1) ||
551 (nfc->data & RXH_L4_B_2_3))
552 return -EINVAL;
553 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
554 break;
555 case IPV4_FLOW:
556 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
557 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
558 break;
559 case IPV6_FLOW:
560 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
561 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
562 break;
563 default:
564 return -EINVAL;
565 }
566
567 wr32(hw, I40E_VFQF_HENA(0), (u32)hena);
568 wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32));
569 i40e_flush(hw);
570
571 return 0;
572}
573
574/**
575 * i40evf_set_rxnfc - command to set RX flow classification rules
576 * @netdev: network interface device structure
577 * @cmd: ethtool rxnfc command
578 *
579 * Returns Success if the command is supported.
580 **/
581static int i40evf_set_rxnfc(struct net_device *netdev,
582 struct ethtool_rxnfc *cmd)
583{
584 struct i40evf_adapter *adapter = netdev_priv(netdev);
585 int ret = -EOPNOTSUPP;
586
587 switch (cmd->cmd) {
588 case ETHTOOL_SRXFH:
589 ret = i40evf_set_rss_hash_opt(adapter, cmd);
590 break;
591 default:
592 break;
593 }
594
595 return ret;
596}
597
598/**
599 * i40evf_get_channels: get the number of channels supported by the device
600 * @netdev: network interface device structure
601 * @ch: channel information structure
602 *
603 * For the purposes of our device, we only use combined channels, i.e. a tx/rx
604 * queue pair. Report one extra channel to match our "other" MSI-X vector.
605 **/
606static void i40evf_get_channels(struct net_device *netdev,
607 struct ethtool_channels *ch)
608{
609 struct i40evf_adapter *adapter = netdev_priv(netdev);
610
611 /* Report maximum channels */
612 ch->max_combined = adapter->vsi_res->num_queue_pairs;
613
614 ch->max_other = NONQ_VECS;
615 ch->other_count = NONQ_VECS;
616
617 ch->combined_count = adapter->vsi_res->num_queue_pairs;
618}
619
620/**
621 * i40evf_get_rxfh_indir_size - get the rx flow hash indirection table size
622 * @netdev: network interface device structure
623 *
624 * Returns the table size.
625 **/
626static u32 i40evf_get_rxfh_indir_size(struct net_device *netdev)
627{
628 return (I40E_VFQF_HLUT_MAX_INDEX + 1) * 4;
629}
630
631/**
632 * i40evf_get_rxfh_indir - get the rx flow hash indirection table
633 * @netdev: network interface device structure
634 * @indir: indirection table
635 *
636 * Reads the indirection table directly from the hardware. Always returns 0.
637 **/
638static int i40evf_get_rxfh_indir(struct net_device *netdev, u32 *indir)
639{
640 struct i40evf_adapter *adapter = netdev_priv(netdev);
641 struct i40e_hw *hw = &adapter->hw;
642 u32 hlut_val;
643 int i, j;
644
645 for (i = 0, j = 0; i < I40E_VFQF_HLUT_MAX_INDEX; i++) {
646 hlut_val = rd32(hw, I40E_VFQF_HLUT(i));
647 indir[j++] = hlut_val & 0xff;
648 indir[j++] = (hlut_val >> 8) & 0xff;
649 indir[j++] = (hlut_val >> 16) & 0xff;
650 indir[j++] = (hlut_val >> 24) & 0xff;
651 }
652 return 0;
653}
654
655/**
656 * i40evf_set_rxfh_indir - set the rx flow hash indirection table
657 * @netdev: network interface device structure
658 * @indir: indirection table
659 *
660 * Returns -EINVAL if the table specifies an inavlid queue id, otherwise
661 * returns 0 after programming the table.
662 **/
663static int i40evf_set_rxfh_indir(struct net_device *netdev, const u32 *indir)
664{
665 struct i40evf_adapter *adapter = netdev_priv(netdev);
666 struct i40e_hw *hw = &adapter->hw;
667 u32 hlut_val;
668 int i, j;
669
670 for (i = 0, j = 0; i < I40E_VFQF_HLUT_MAX_INDEX + 1; i++) {
671 hlut_val = indir[j++];
672 hlut_val |= indir[j++] << 8;
673 hlut_val |= indir[j++] << 16;
674 hlut_val |= indir[j++] << 24;
675 wr32(hw, I40E_VFQF_HLUT(i), hlut_val);
676 }
677
678 return 0;
679}
680
Greg Rosefbb7ddf2013-12-21 06:12:56 +0000681static struct ethtool_ops i40evf_ethtool_ops = {
682 .get_settings = i40evf_get_settings,
683 .get_drvinfo = i40evf_get_drvinfo,
684 .get_link = ethtool_op_get_link,
685 .get_ringparam = i40evf_get_ringparam,
686 .set_ringparam = i40evf_set_ringparam,
687 .get_strings = i40evf_get_strings,
688 .get_ethtool_stats = i40evf_get_ethtool_stats,
689 .get_sset_count = i40evf_get_sset_count,
690 .get_msglevel = i40evf_get_msglevel,
691 .set_msglevel = i40evf_set_msglevel,
692 .get_coalesce = i40evf_get_coalesce,
693 .set_coalesce = i40evf_set_coalesce,
Mitch A Williams4e9dc312014-04-01 04:43:49 +0000694 .get_rxnfc = i40evf_get_rxnfc,
695 .set_rxnfc = i40evf_set_rxnfc,
696 .get_rxfh_indir_size = i40evf_get_rxfh_indir_size,
697 .get_rxfh_indir = i40evf_get_rxfh_indir,
698 .set_rxfh_indir = i40evf_set_rxfh_indir,
699 .get_channels = i40evf_get_channels,
Greg Rosefbb7ddf2013-12-21 06:12:56 +0000700};
701
702/**
703 * i40evf_set_ethtool_ops - Initialize ethtool ops struct
704 * @netdev: network interface device structure
705 *
706 * Sets ethtool ops struct in our netdev so that ethtool can call
707 * our functions.
708 **/
709void i40evf_set_ethtool_ops(struct net_device *netdev)
710{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +0000711 netdev->ethtool_ops = &i40evf_ethtool_ops;
Greg Rosefbb7ddf2013-12-21 06:12:56 +0000712}