blob: df4dcfd364d868608d8782978e3b8f621a902e89 [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))
Mitch Williams32f5f542014-04-04 04:43:10 +0000298 ec->use_adaptive_rx_coalesce = 1;
Greg Rosefbb7ddf2013-12-21 06:12:56 +0000299
300 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +0000301 ec->use_adaptive_tx_coalesce = 1;
302
303 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
304 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Greg Rosefbb7ddf2013-12-21 06:12:56 +0000305
306 return 0;
307}
308
309/**
310 * i40evf_set_coalesce - Set interrupt coalescing settings
311 * @netdev: network interface device structure
312 * @ec: ethtool coalesce structure
313 *
314 * Change current coalescing settings.
315 **/
316static int i40evf_set_coalesce(struct net_device *netdev,
317 struct ethtool_coalesce *ec)
318{
319 struct i40evf_adapter *adapter = netdev_priv(netdev);
320 struct i40e_hw *hw = &adapter->hw;
321 struct i40e_vsi *vsi = &adapter->vsi;
322 struct i40e_q_vector *q_vector;
323 int i;
324
Mitch Williams32f5f542014-04-04 04:43:10 +0000325 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
326 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
Greg Rosefbb7ddf2013-12-21 06:12:56 +0000327
Mitch Williams32f5f542014-04-04 04:43:10 +0000328 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
329 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1)))
Greg Rosefbb7ddf2013-12-21 06:12:56 +0000330 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Greg Rosefbb7ddf2013-12-21 06:12:56 +0000331
Mitch Williams32f5f542014-04-04 04:43:10 +0000332 else
333 return -EINVAL;
334
335 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
336 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1)))
Greg Rosefbb7ddf2013-12-21 06:12:56 +0000337 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Mitch Williams32f5f542014-04-04 04:43:10 +0000338 else if (ec->use_adaptive_tx_coalesce)
339 vsi->tx_itr_setting = (I40E_ITR_DYNAMIC |
340 ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
341 else
342 return -EINVAL;
343
344 if (ec->use_adaptive_rx_coalesce)
345 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
346 else
347 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
348
349 if (ec->use_adaptive_tx_coalesce)
350 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
351 else
352 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Greg Rosefbb7ddf2013-12-21 06:12:56 +0000353
354 for (i = 0; i < adapter->num_msix_vectors - NONQ_VECS; i++) {
355 q_vector = adapter->q_vector[i];
356 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
357 wr32(hw, I40E_VFINT_ITRN1(0, i), q_vector->rx.itr);
358 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
359 wr32(hw, I40E_VFINT_ITRN1(1, i), q_vector->tx.itr);
360 i40e_flush(hw);
361 }
362
363 return 0;
364}
365
Mitch A Williams4e9dc312014-04-01 04:43:49 +0000366/**
367 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
368 * @adapter: board private structure
369 * @cmd: ethtool rxnfc command
370 *
371 * Returns Success if the flow is supported, else Invalid Input.
372 **/
373static int i40evf_get_rss_hash_opts(struct i40evf_adapter *adapter,
374 struct ethtool_rxnfc *cmd)
375{
376 struct i40e_hw *hw = &adapter->hw;
377 u64 hena = (u64)rd32(hw, I40E_VFQF_HENA(0)) |
378 ((u64)rd32(hw, I40E_VFQF_HENA(1)) << 32);
379
380 /* We always hash on IP src and dest addresses */
381 cmd->data = RXH_IP_SRC | RXH_IP_DST;
382
383 switch (cmd->flow_type) {
384 case TCP_V4_FLOW:
385 if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP))
386 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
387 break;
388 case UDP_V4_FLOW:
389 if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP))
390 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
391 break;
392
393 case SCTP_V4_FLOW:
394 case AH_ESP_V4_FLOW:
395 case AH_V4_FLOW:
396 case ESP_V4_FLOW:
397 case IPV4_FLOW:
398 break;
399
400 case TCP_V6_FLOW:
401 if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP))
402 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
403 break;
404 case UDP_V6_FLOW:
405 if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP))
406 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
407 break;
408
409 case SCTP_V6_FLOW:
410 case AH_ESP_V6_FLOW:
411 case AH_V6_FLOW:
412 case ESP_V6_FLOW:
413 case IPV6_FLOW:
414 break;
415 default:
416 cmd->data = 0;
417 return -EINVAL;
418 }
419
420 return 0;
421}
422
423/**
424 * i40evf_get_rxnfc - command to get RX flow classification rules
425 * @netdev: network interface device structure
426 * @cmd: ethtool rxnfc command
427 *
428 * Returns Success if the command is supported.
429 **/
430static int i40evf_get_rxnfc(struct net_device *netdev,
431 struct ethtool_rxnfc *cmd,
432 u32 *rule_locs)
433{
434 struct i40evf_adapter *adapter = netdev_priv(netdev);
435 int ret = -EOPNOTSUPP;
436
437 switch (cmd->cmd) {
438 case ETHTOOL_GRXRINGS:
439 cmd->data = adapter->vsi_res->num_queue_pairs;
440 ret = 0;
441 break;
442 case ETHTOOL_GRXFH:
443 ret = i40evf_get_rss_hash_opts(adapter, cmd);
444 break;
445 default:
446 break;
447 }
448
449 return ret;
450}
451
452/**
453 * i40evf_set_rss_hash_opt - Enable/Disable flow types for RSS hash
454 * @adapter: board private structure
455 * @cmd: ethtool rxnfc command
456 *
457 * Returns Success if the flow input set is supported.
458 **/
459static int i40evf_set_rss_hash_opt(struct i40evf_adapter *adapter,
460 struct ethtool_rxnfc *nfc)
461{
462 struct i40e_hw *hw = &adapter->hw;
463
464 u64 hena = (u64)rd32(hw, I40E_VFQF_HENA(0)) |
465 ((u64)rd32(hw, I40E_VFQF_HENA(1)) << 32);
466
467 /* RSS does not support anything other than hashing
468 * to queues on src and dst IPs and ports
469 */
470 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
471 RXH_L4_B_0_1 | RXH_L4_B_2_3))
472 return -EINVAL;
473
474 /* We need at least the IP SRC and DEST fields for hashing */
475 if (!(nfc->data & RXH_IP_SRC) ||
476 !(nfc->data & RXH_IP_DST))
477 return -EINVAL;
478
479 switch (nfc->flow_type) {
480 case TCP_V4_FLOW:
481 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
482 case 0:
483 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
484 break;
485 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
486 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
487 break;
488 default:
489 return -EINVAL;
490 }
491 break;
492 case TCP_V6_FLOW:
493 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
494 case 0:
495 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
496 break;
497 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
498 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
499 break;
500 default:
501 return -EINVAL;
502 }
503 break;
504 case UDP_V4_FLOW:
505 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
506 case 0:
507 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
508 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
509 break;
510 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
511 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
512 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
513 break;
514 default:
515 return -EINVAL;
516 }
517 break;
518 case UDP_V6_FLOW:
519 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
520 case 0:
521 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
522 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
523 break;
524 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
525 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
526 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
527 break;
528 default:
529 return -EINVAL;
530 }
531 break;
532 case AH_ESP_V4_FLOW:
533 case AH_V4_FLOW:
534 case ESP_V4_FLOW:
535 case SCTP_V4_FLOW:
536 if ((nfc->data & RXH_L4_B_0_1) ||
537 (nfc->data & RXH_L4_B_2_3))
538 return -EINVAL;
539 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
540 break;
541 case AH_ESP_V6_FLOW:
542 case AH_V6_FLOW:
543 case ESP_V6_FLOW:
544 case SCTP_V6_FLOW:
545 if ((nfc->data & RXH_L4_B_0_1) ||
546 (nfc->data & RXH_L4_B_2_3))
547 return -EINVAL;
548 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
549 break;
550 case IPV4_FLOW:
551 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
552 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
553 break;
554 case IPV6_FLOW:
555 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
556 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
557 break;
558 default:
559 return -EINVAL;
560 }
561
562 wr32(hw, I40E_VFQF_HENA(0), (u32)hena);
563 wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32));
564 i40e_flush(hw);
565
566 return 0;
567}
568
569/**
570 * i40evf_set_rxnfc - command to set RX flow classification rules
571 * @netdev: network interface device structure
572 * @cmd: ethtool rxnfc command
573 *
574 * Returns Success if the command is supported.
575 **/
576static int i40evf_set_rxnfc(struct net_device *netdev,
577 struct ethtool_rxnfc *cmd)
578{
579 struct i40evf_adapter *adapter = netdev_priv(netdev);
580 int ret = -EOPNOTSUPP;
581
582 switch (cmd->cmd) {
583 case ETHTOOL_SRXFH:
584 ret = i40evf_set_rss_hash_opt(adapter, cmd);
585 break;
586 default:
587 break;
588 }
589
590 return ret;
591}
592
593/**
594 * i40evf_get_channels: get the number of channels supported by the device
595 * @netdev: network interface device structure
596 * @ch: channel information structure
597 *
598 * For the purposes of our device, we only use combined channels, i.e. a tx/rx
599 * queue pair. Report one extra channel to match our "other" MSI-X vector.
600 **/
601static void i40evf_get_channels(struct net_device *netdev,
602 struct ethtool_channels *ch)
603{
604 struct i40evf_adapter *adapter = netdev_priv(netdev);
605
606 /* Report maximum channels */
607 ch->max_combined = adapter->vsi_res->num_queue_pairs;
608
609 ch->max_other = NONQ_VECS;
610 ch->other_count = NONQ_VECS;
611
612 ch->combined_count = adapter->vsi_res->num_queue_pairs;
613}
614
615/**
616 * i40evf_get_rxfh_indir_size - get the rx flow hash indirection table size
617 * @netdev: network interface device structure
618 *
619 * Returns the table size.
620 **/
621static u32 i40evf_get_rxfh_indir_size(struct net_device *netdev)
622{
623 return (I40E_VFQF_HLUT_MAX_INDEX + 1) * 4;
624}
625
626/**
627 * i40evf_get_rxfh_indir - get the rx flow hash indirection table
628 * @netdev: network interface device structure
629 * @indir: indirection table
630 *
631 * Reads the indirection table directly from the hardware. Always returns 0.
632 **/
633static int i40evf_get_rxfh_indir(struct net_device *netdev, u32 *indir)
634{
635 struct i40evf_adapter *adapter = netdev_priv(netdev);
636 struct i40e_hw *hw = &adapter->hw;
637 u32 hlut_val;
638 int i, j;
639
640 for (i = 0, j = 0; i < I40E_VFQF_HLUT_MAX_INDEX; i++) {
641 hlut_val = rd32(hw, I40E_VFQF_HLUT(i));
642 indir[j++] = hlut_val & 0xff;
643 indir[j++] = (hlut_val >> 8) & 0xff;
644 indir[j++] = (hlut_val >> 16) & 0xff;
645 indir[j++] = (hlut_val >> 24) & 0xff;
646 }
647 return 0;
648}
649
650/**
651 * i40evf_set_rxfh_indir - set the rx flow hash indirection table
652 * @netdev: network interface device structure
653 * @indir: indirection table
654 *
655 * Returns -EINVAL if the table specifies an inavlid queue id, otherwise
656 * returns 0 after programming the table.
657 **/
658static int i40evf_set_rxfh_indir(struct net_device *netdev, const u32 *indir)
659{
660 struct i40evf_adapter *adapter = netdev_priv(netdev);
661 struct i40e_hw *hw = &adapter->hw;
662 u32 hlut_val;
663 int i, j;
664
665 for (i = 0, j = 0; i < I40E_VFQF_HLUT_MAX_INDEX + 1; i++) {
666 hlut_val = indir[j++];
667 hlut_val |= indir[j++] << 8;
668 hlut_val |= indir[j++] << 16;
669 hlut_val |= indir[j++] << 24;
670 wr32(hw, I40E_VFQF_HLUT(i), hlut_val);
671 }
672
673 return 0;
674}
675
Mitch Williamsf0c53c72014-04-04 04:43:11 +0000676static const struct ethtool_ops i40evf_ethtool_ops = {
Greg Rosefbb7ddf2013-12-21 06:12:56 +0000677 .get_settings = i40evf_get_settings,
678 .get_drvinfo = i40evf_get_drvinfo,
679 .get_link = ethtool_op_get_link,
680 .get_ringparam = i40evf_get_ringparam,
681 .set_ringparam = i40evf_set_ringparam,
682 .get_strings = i40evf_get_strings,
683 .get_ethtool_stats = i40evf_get_ethtool_stats,
684 .get_sset_count = i40evf_get_sset_count,
685 .get_msglevel = i40evf_get_msglevel,
686 .set_msglevel = i40evf_set_msglevel,
687 .get_coalesce = i40evf_get_coalesce,
688 .set_coalesce = i40evf_set_coalesce,
Mitch A Williams4e9dc312014-04-01 04:43:49 +0000689 .get_rxnfc = i40evf_get_rxnfc,
690 .set_rxnfc = i40evf_set_rxnfc,
691 .get_rxfh_indir_size = i40evf_get_rxfh_indir_size,
692 .get_rxfh_indir = i40evf_get_rxfh_indir,
693 .set_rxfh_indir = i40evf_set_rxfh_indir,
694 .get_channels = i40evf_get_channels,
Greg Rosefbb7ddf2013-12-21 06:12:56 +0000695};
696
697/**
698 * i40evf_set_ethtool_ops - Initialize ethtool ops struct
699 * @netdev: network interface device structure
700 *
701 * Sets ethtool ops struct in our netdev so that ethtool can call
702 * our functions.
703 **/
704void i40evf_set_ethtool_ops(struct net_device *netdev)
705{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +0000706 netdev->ethtool_ops = &i40evf_ethtool_ops;
Greg Rosefbb7ddf2013-12-21 06:12:56 +0000707}