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