1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
4 * Copyright(c) 2013 - 2014 Intel Corporation.
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.
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
15 * 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/>.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
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
25 ******************************************************************************/
27 /* ethtool support for i40evf */
30 #include <linux/uaccess.h>
34 char stat_string[ETH_GSTRING_LEN];
38 #define I40EVF_STAT(_name, _stat) { \
39 .stat_string = _name, \
40 .stat_offset = offsetof(struct i40evf_adapter, _stat) \
43 /* All stats are u64, so we don't need to track the size of the field. */
44 static 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_unknown_protocol", current_stats.rx_unknown_protocol),
51 I40EVF_STAT("tx_bytes", current_stats.tx_bytes),
52 I40EVF_STAT("tx_unicast", current_stats.tx_unicast),
53 I40EVF_STAT("tx_multicast", current_stats.tx_multicast),
54 I40EVF_STAT("tx_broadcast", current_stats.tx_broadcast),
55 I40EVF_STAT("tx_discards", current_stats.tx_discards),
56 I40EVF_STAT("tx_errors", current_stats.tx_errors),
59 #define I40EVF_GLOBAL_STATS_LEN ARRAY_SIZE(i40evf_gstrings_stats)
60 #define I40EVF_QUEUE_STATS_LEN(_dev) \
61 (((struct i40evf_adapter *) \
62 netdev_priv(_dev))->vsi_res->num_queue_pairs \
63 * 2 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
64 #define I40EVF_STATS_LEN(_dev) \
65 (I40EVF_GLOBAL_STATS_LEN + I40EVF_QUEUE_STATS_LEN(_dev))
68 * i40evf_get_settings - Get Link Speed and Duplex settings
69 * @netdev: network interface device structure
70 * @ecmd: ethtool command
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.
75 static int i40evf_get_settings(struct net_device *netdev,
76 struct ethtool_cmd *ecmd)
78 /* In the future the VF will be able to query the PF for
79 * some information - for now use a dummy value
82 ecmd->autoneg = AUTONEG_DISABLE;
83 ecmd->transceiver = XCVR_DUMMY1;
84 ecmd->port = PORT_NONE;
90 * i40evf_get_sset_count - Get length of string set
91 * @netdev: network interface device structure
92 * @sset: id of string set
94 * Reports size of string table. This driver only supports
95 * strings for statistics.
97 static int i40evf_get_sset_count(struct net_device *netdev, int sset)
99 if (sset == ETH_SS_STATS)
100 return I40EVF_STATS_LEN(netdev);
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
111 * All statistics are added to the data buffer as an array of u64.
113 static void i40evf_get_ethtool_stats(struct net_device *netdev,
114 struct ethtool_stats *stats, u64 *data)
116 struct i40evf_adapter *adapter = netdev_priv(netdev);
120 for (i = 0; i < I40EVF_GLOBAL_STATS_LEN; i++) {
121 p = (char *)adapter + i40evf_gstrings_stats[i].stat_offset;
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;
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;
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
140 * Builds stats string table.
142 static void i40evf_get_strings(struct net_device *netdev, u32 sset, u8 *data)
144 struct i40evf_adapter *adapter = netdev_priv(netdev);
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,
152 p += ETH_GSTRING_LEN;
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;
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;
170 * i40evf_get_msglevel - Get debug message level
171 * @netdev: network interface device structure
173 * Returns current debug message level.
175 static u32 i40evf_get_msglevel(struct net_device *netdev)
177 struct i40evf_adapter *adapter = netdev_priv(netdev);
178 return adapter->msg_enable;
182 * i40evf_get_msglevel - Set debug message level
183 * @netdev: network interface device structure
184 * @data: message level
186 * Set current debug message level. Higher values cause the driver to
189 static void i40evf_set_msglevel(struct net_device *netdev, u32 data)
191 struct i40evf_adapter *adapter = netdev_priv(netdev);
192 adapter->msg_enable = data;
196 * i40evf_get_drvinto - Get driver info
197 * @netdev: network interface device structure
198 * @drvinfo: ethool driver info structure
200 * Returns information about the driver and device for display to the user.
202 static void i40evf_get_drvinfo(struct net_device *netdev,
203 struct ethtool_drvinfo *drvinfo)
205 struct i40evf_adapter *adapter = netdev_priv(netdev);
207 strlcpy(drvinfo->driver, i40evf_driver_name, 32);
208 strlcpy(drvinfo->version, i40evf_driver_version, 32);
210 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
214 * i40evf_get_ringparam - Get ring parameters
215 * @netdev: network interface device structure
216 * @ring: ethtool ringparam structure
218 * Returns current ring parameters. TX and RX rings are reported separately,
219 * but the number of rings is not reported.
221 static void i40evf_get_ringparam(struct net_device *netdev,
222 struct ethtool_ringparam *ring)
224 struct i40evf_adapter *adapter = netdev_priv(netdev);
226 ring->rx_max_pending = I40EVF_MAX_RXD;
227 ring->tx_max_pending = I40EVF_MAX_TXD;
228 ring->rx_pending = adapter->rx_desc_count;
229 ring->tx_pending = adapter->tx_desc_count;
233 * i40evf_set_ringparam - Set ring parameters
234 * @netdev: network interface device structure
235 * @ring: ethtool ringparam structure
237 * Sets ring parameters. TX and RX rings are controlled separately, but the
238 * number of rings is not specified, so all rings get the same settings.
240 static int i40evf_set_ringparam(struct net_device *netdev,
241 struct ethtool_ringparam *ring)
243 struct i40evf_adapter *adapter = netdev_priv(netdev);
244 u32 new_rx_count, new_tx_count;
246 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
249 new_tx_count = clamp_t(u32, ring->tx_pending,
252 new_tx_count = ALIGN(new_tx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
254 new_rx_count = clamp_t(u32, ring->rx_pending,
257 new_rx_count = ALIGN(new_rx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
259 /* if nothing to do return success */
260 if ((new_tx_count == adapter->tx_desc_count) &&
261 (new_rx_count == adapter->rx_desc_count))
264 adapter->tx_desc_count = new_tx_count;
265 adapter->rx_desc_count = new_rx_count;
267 if (netif_running(netdev))
268 i40evf_reinit_locked(adapter);
274 * i40evf_get_coalesce - Get interrupt coalescing settings
275 * @netdev: network interface device structure
276 * @ec: ethtool coalesce structure
278 * Returns current coalescing settings. This is referred to elsewhere in the
279 * driver as Interrupt Throttle Rate, as this is how the hardware describes
280 * this functionality.
282 static int i40evf_get_coalesce(struct net_device *netdev,
283 struct ethtool_coalesce *ec)
285 struct i40evf_adapter *adapter = netdev_priv(netdev);
286 struct i40e_vsi *vsi = &adapter->vsi;
288 ec->tx_max_coalesced_frames = vsi->work_limit;
289 ec->rx_max_coalesced_frames = vsi->work_limit;
291 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
292 ec->use_adaptive_rx_coalesce = 1;
294 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
295 ec->use_adaptive_tx_coalesce = 1;
297 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
298 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
304 * i40evf_set_coalesce - Set interrupt coalescing settings
305 * @netdev: network interface device structure
306 * @ec: ethtool coalesce structure
308 * Change current coalescing settings.
310 static int i40evf_set_coalesce(struct net_device *netdev,
311 struct ethtool_coalesce *ec)
313 struct i40evf_adapter *adapter = netdev_priv(netdev);
314 struct i40e_hw *hw = &adapter->hw;
315 struct i40e_vsi *vsi = &adapter->vsi;
316 struct i40e_q_vector *q_vector;
319 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
320 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
322 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
323 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1)))
324 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
329 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
330 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1)))
331 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
332 else if (ec->use_adaptive_tx_coalesce)
333 vsi->tx_itr_setting = (I40E_ITR_DYNAMIC |
334 ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
338 if (ec->use_adaptive_rx_coalesce)
339 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
341 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
343 if (ec->use_adaptive_tx_coalesce)
344 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
346 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
348 for (i = 0; i < adapter->num_msix_vectors - NONQ_VECS; i++) {
349 q_vector = adapter->q_vector[i];
350 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
351 wr32(hw, I40E_VFINT_ITRN1(0, i), q_vector->rx.itr);
352 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
353 wr32(hw, I40E_VFINT_ITRN1(1, i), q_vector->tx.itr);
361 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
362 * @adapter: board private structure
363 * @cmd: ethtool rxnfc command
365 * Returns Success if the flow is supported, else Invalid Input.
367 static int i40evf_get_rss_hash_opts(struct i40evf_adapter *adapter,
368 struct ethtool_rxnfc *cmd)
370 struct i40e_hw *hw = &adapter->hw;
371 u64 hena = (u64)rd32(hw, I40E_VFQF_HENA(0)) |
372 ((u64)rd32(hw, I40E_VFQF_HENA(1)) << 32);
374 /* We always hash on IP src and dest addresses */
375 cmd->data = RXH_IP_SRC | RXH_IP_DST;
377 switch (cmd->flow_type) {
379 if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP))
380 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
383 if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP))
384 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
395 if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP))
396 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
399 if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP))
400 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
418 * i40evf_get_rxnfc - command to get RX flow classification rules
419 * @netdev: network interface device structure
420 * @cmd: ethtool rxnfc command
422 * Returns Success if the command is supported.
424 static int i40evf_get_rxnfc(struct net_device *netdev,
425 struct ethtool_rxnfc *cmd,
428 struct i40evf_adapter *adapter = netdev_priv(netdev);
429 int ret = -EOPNOTSUPP;
432 case ETHTOOL_GRXRINGS:
433 cmd->data = adapter->vsi_res->num_queue_pairs;
437 ret = i40evf_get_rss_hash_opts(adapter, cmd);
447 * i40evf_set_rss_hash_opt - Enable/Disable flow types for RSS hash
448 * @adapter: board private structure
449 * @cmd: ethtool rxnfc command
451 * Returns Success if the flow input set is supported.
453 static int i40evf_set_rss_hash_opt(struct i40evf_adapter *adapter,
454 struct ethtool_rxnfc *nfc)
456 struct i40e_hw *hw = &adapter->hw;
458 u64 hena = (u64)rd32(hw, I40E_VFQF_HENA(0)) |
459 ((u64)rd32(hw, I40E_VFQF_HENA(1)) << 32);
461 /* RSS does not support anything other than hashing
462 * to queues on src and dst IPs and ports
464 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
465 RXH_L4_B_0_1 | RXH_L4_B_2_3))
468 /* We need at least the IP SRC and DEST fields for hashing */
469 if (!(nfc->data & RXH_IP_SRC) ||
470 !(nfc->data & RXH_IP_DST))
473 switch (nfc->flow_type) {
475 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
477 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
479 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
480 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
487 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
489 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
491 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
492 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
499 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
501 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
502 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
504 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
505 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
506 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
513 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
515 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
516 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
518 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
519 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
520 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
530 if ((nfc->data & RXH_L4_B_0_1) ||
531 (nfc->data & RXH_L4_B_2_3))
533 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
539 if ((nfc->data & RXH_L4_B_0_1) ||
540 (nfc->data & RXH_L4_B_2_3))
542 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
545 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
546 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
549 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
550 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
556 wr32(hw, I40E_VFQF_HENA(0), (u32)hena);
557 wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32));
564 * i40evf_set_rxnfc - command to set RX flow classification rules
565 * @netdev: network interface device structure
566 * @cmd: ethtool rxnfc command
568 * Returns Success if the command is supported.
570 static int i40evf_set_rxnfc(struct net_device *netdev,
571 struct ethtool_rxnfc *cmd)
573 struct i40evf_adapter *adapter = netdev_priv(netdev);
574 int ret = -EOPNOTSUPP;
578 ret = i40evf_set_rss_hash_opt(adapter, cmd);
588 * i40evf_get_channels: get the number of channels supported by the device
589 * @netdev: network interface device structure
590 * @ch: channel information structure
592 * For the purposes of our device, we only use combined channels, i.e. a tx/rx
593 * queue pair. Report one extra channel to match our "other" MSI-X vector.
595 static void i40evf_get_channels(struct net_device *netdev,
596 struct ethtool_channels *ch)
598 struct i40evf_adapter *adapter = netdev_priv(netdev);
600 /* Report maximum channels */
601 ch->max_combined = adapter->vsi_res->num_queue_pairs;
603 ch->max_other = NONQ_VECS;
604 ch->other_count = NONQ_VECS;
606 ch->combined_count = adapter->vsi_res->num_queue_pairs;
610 * i40evf_get_rxfh_indir_size - get the rx flow hash indirection table size
611 * @netdev: network interface device structure
613 * Returns the table size.
615 static u32 i40evf_get_rxfh_indir_size(struct net_device *netdev)
617 return (I40E_VFQF_HLUT_MAX_INDEX + 1) * 4;
621 * i40evf_get_rxfh - get the rx flow hash indirection table
622 * @netdev: network interface device structure
623 * @indir: indirection table
624 * @key: hash key (will be %NULL until get_rxfh_key_size is implemented)
626 * Reads the indirection table directly from the hardware. Always returns 0.
628 static int i40evf_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key)
630 struct i40evf_adapter *adapter = netdev_priv(netdev);
631 struct i40e_hw *hw = &adapter->hw;
635 for (i = 0, j = 0; i < I40E_VFQF_HLUT_MAX_INDEX; i++) {
636 hlut_val = rd32(hw, I40E_VFQF_HLUT(i));
637 indir[j++] = hlut_val & 0xff;
638 indir[j++] = (hlut_val >> 8) & 0xff;
639 indir[j++] = (hlut_val >> 16) & 0xff;
640 indir[j++] = (hlut_val >> 24) & 0xff;
646 * i40evf_set_rxfh - set the rx flow hash indirection table
647 * @netdev: network interface device structure
648 * @indir: indirection table
649 * @key: hash key (will be %NULL until get_rxfh_key_size is implemented)
651 * Returns -EINVAL if the table specifies an inavlid queue id, otherwise
652 * returns 0 after programming the table.
654 static int i40evf_set_rxfh(struct net_device *netdev, const u32 *indir,
657 struct i40evf_adapter *adapter = netdev_priv(netdev);
658 struct i40e_hw *hw = &adapter->hw;
662 for (i = 0, j = 0; i < I40E_VFQF_HLUT_MAX_INDEX + 1; i++) {
663 hlut_val = indir[j++];
664 hlut_val |= indir[j++] << 8;
665 hlut_val |= indir[j++] << 16;
666 hlut_val |= indir[j++] << 24;
667 wr32(hw, I40E_VFQF_HLUT(i), hlut_val);
673 static const struct ethtool_ops i40evf_ethtool_ops = {
674 .get_settings = i40evf_get_settings,
675 .get_drvinfo = i40evf_get_drvinfo,
676 .get_link = ethtool_op_get_link,
677 .get_ringparam = i40evf_get_ringparam,
678 .set_ringparam = i40evf_set_ringparam,
679 .get_strings = i40evf_get_strings,
680 .get_ethtool_stats = i40evf_get_ethtool_stats,
681 .get_sset_count = i40evf_get_sset_count,
682 .get_msglevel = i40evf_get_msglevel,
683 .set_msglevel = i40evf_set_msglevel,
684 .get_coalesce = i40evf_get_coalesce,
685 .set_coalesce = i40evf_set_coalesce,
686 .get_rxnfc = i40evf_get_rxnfc,
687 .set_rxnfc = i40evf_set_rxnfc,
688 .get_rxfh_indir_size = i40evf_get_rxfh_indir_size,
689 .get_rxfh = i40evf_get_rxfh,
690 .set_rxfh = i40evf_set_rxfh,
691 .get_channels = i40evf_get_channels,
695 * i40evf_set_ethtool_ops - Initialize ethtool ops struct
696 * @netdev: network interface device structure
698 * Sets ethtool ops struct in our netdev so that ethtool can call
701 void i40evf_set_ethtool_ops(struct net_device *netdev)
703 netdev->ethtool_ops = &i40evf_ethtool_ops;