i40evf_ethtool.c 24.5 KB
Newer Older
G
Greg Rose 已提交
1 2 3
/*******************************************************************************
 *
 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
4
 * Copyright(c) 2013 - 2016 Intel Corporation.
G
Greg Rose 已提交
5 6 7 8 9 10 11 12 13 14
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
15 16 17
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
G
Greg Rose 已提交
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
 * The full GNU General Public License is included in this distribution in
 * the file called "COPYING".
 *
 * Contact Information:
 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
 *
 ******************************************************************************/

/* ethtool support for i40evf */
#include "i40evf.h"

#include <linux/uaccess.h>

struct i40evf_stats {
	char stat_string[ETH_GSTRING_LEN];
	int stat_offset;
};

#define I40EVF_STAT(_name, _stat) { \
	.stat_string = _name, \
	.stat_offset = offsetof(struct i40evf_adapter, _stat) \
}

/* All stats are u64, so we don't need to track the size of the field. */
static const struct i40evf_stats i40evf_gstrings_stats[] = {
	I40EVF_STAT("rx_bytes", current_stats.rx_bytes),
	I40EVF_STAT("rx_unicast", current_stats.rx_unicast),
	I40EVF_STAT("rx_multicast", current_stats.rx_multicast),
	I40EVF_STAT("rx_broadcast", current_stats.rx_broadcast),
	I40EVF_STAT("rx_discards", current_stats.rx_discards),
	I40EVF_STAT("rx_unknown_protocol", current_stats.rx_unknown_protocol),
	I40EVF_STAT("tx_bytes", current_stats.tx_bytes),
	I40EVF_STAT("tx_unicast", current_stats.tx_unicast),
	I40EVF_STAT("tx_multicast", current_stats.tx_multicast),
	I40EVF_STAT("tx_broadcast", current_stats.tx_broadcast),
	I40EVF_STAT("tx_discards", current_stats.tx_discards),
	I40EVF_STAT("tx_errors", current_stats.tx_errors),
};

#define I40EVF_GLOBAL_STATS_LEN ARRAY_SIZE(i40evf_gstrings_stats)
59
#define I40EVF_QUEUE_STATS_LEN(_dev) \
M
Mitch Williams 已提交
60
	(((struct i40evf_adapter *)\
61
		netdev_priv(_dev))->num_active_queues \
62 63 64
		  * 2 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
#define I40EVF_STATS_LEN(_dev) \
	(I40EVF_GLOBAL_STATS_LEN + I40EVF_QUEUE_STATS_LEN(_dev))
G
Greg Rose 已提交
65

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
/* For now we have one and only one private flag and it is only defined
 * when we have support for the SKIP_CPU_SYNC DMA attribute.  Instead
 * of leaving all this code sitting around empty we will strip it unless
 * our one private flag is actually available.
 */
struct i40evf_priv_flags {
	char flag_string[ETH_GSTRING_LEN];
	u32 flag;
	bool read_only;
};

#define I40EVF_PRIV_FLAG(_name, _flag, _read_only) { \
	.flag_string = _name, \
	.flag = _flag, \
	.read_only = _read_only, \
}

static const struct i40evf_priv_flags i40evf_gstrings_priv_flags[] = {
	I40EVF_PRIV_FLAG("legacy-rx", I40EVF_FLAG_LEGACY_RX, 0),
};

#define I40EVF_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40evf_gstrings_priv_flags)

G
Greg Rose 已提交
89
/**
90
 * i40evf_get_link_ksettings - Get Link Speed and Duplex settings
G
Greg Rose 已提交
91
 * @netdev: network interface device structure
92
 * @cmd: ethtool command
G
Greg Rose 已提交
93 94 95 96
 *
 * Reports speed/duplex settings. Because this is a VF, we don't know what
 * kind of link we really have, so we fake it.
 **/
97 98
static int i40evf_get_link_ksettings(struct net_device *netdev,
				     struct ethtool_link_ksettings *cmd)
G
Greg Rose 已提交
99
{
M
Mitch Williams 已提交
100 101
	struct i40evf_adapter *adapter = netdev_priv(netdev);

102 103 104
	ethtool_link_ksettings_zero_link_mode(cmd, supported);
	cmd->base.autoneg = AUTONEG_DISABLE;
	cmd->base.port = PORT_NONE;
M
Mitch Williams 已提交
105 106 107
	/* Set speed and duplex */
	switch (adapter->link_speed) {
	case I40E_LINK_SPEED_40GB:
108
		cmd->base.speed = SPEED_40000;
M
Mitch Williams 已提交
109
		break;
110 111
	case I40E_LINK_SPEED_25GB:
#ifdef SPEED_25000
112
		cmd->base.speed = SPEED_25000;
113 114 115 116 117
#else
		netdev_info(netdev,
			    "Speed is 25G, display not supported by this version of ethtool.\n");
#endif
		break;
M
Mitch Williams 已提交
118
	case I40E_LINK_SPEED_20GB:
119
		cmd->base.speed = SPEED_20000;
M
Mitch Williams 已提交
120 121
		break;
	case I40E_LINK_SPEED_10GB:
122
		cmd->base.speed = SPEED_10000;
M
Mitch Williams 已提交
123 124
		break;
	case I40E_LINK_SPEED_1GB:
125
		cmd->base.speed = SPEED_1000;
M
Mitch Williams 已提交
126 127
		break;
	case I40E_LINK_SPEED_100MB:
128
		cmd->base.speed = SPEED_100;
M
Mitch Williams 已提交
129 130 131 132
		break;
	default:
		break;
	}
133
	cmd->base.duplex = DUPLEX_FULL;
G
Greg Rose 已提交
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148

	return 0;
}

/**
 * i40evf_get_sset_count - Get length of string set
 * @netdev: network interface device structure
 * @sset: id of string set
 *
 * Reports size of string table. This driver only supports
 * strings for statistics.
 **/
static int i40evf_get_sset_count(struct net_device *netdev, int sset)
{
	if (sset == ETH_SS_STATS)
149
		return I40EVF_STATS_LEN(netdev);
150 151
	else if (sset == ETH_SS_PRIV_FLAGS)
		return I40EVF_PRIV_FLAGS_STR_LEN;
G
Greg Rose 已提交
152
	else
153
		return -EINVAL;
G
Greg Rose 已提交
154 155 156 157 158 159 160 161 162 163 164 165 166 167
}

/**
 * i40evf_get_ethtool_stats - report device statistics
 * @netdev: network interface device structure
 * @stats: ethtool statistics structure
 * @data: pointer to data buffer
 *
 * All statistics are added to the data buffer as an array of u64.
 **/
static void i40evf_get_ethtool_stats(struct net_device *netdev,
				     struct ethtool_stats *stats, u64 *data)
{
	struct i40evf_adapter *adapter = netdev_priv(netdev);
168
	unsigned int i, j;
G
Greg Rose 已提交
169 170 171 172 173 174
	char *p;

	for (i = 0; i < I40EVF_GLOBAL_STATS_LEN; i++) {
		p = (char *)adapter + i40evf_gstrings_stats[i].stat_offset;
		data[i] =  *(u64 *)p;
	}
175
	for (j = 0; j < adapter->num_active_queues; j++) {
176 177
		data[i++] = adapter->tx_rings[j].stats.packets;
		data[i++] = adapter->tx_rings[j].stats.bytes;
G
Greg Rose 已提交
178
	}
179
	for (j = 0; j < adapter->num_active_queues; j++) {
180 181
		data[i++] = adapter->rx_rings[j].stats.packets;
		data[i++] = adapter->rx_rings[j].stats.bytes;
G
Greg Rose 已提交
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
	}
}

/**
 * i40evf_get_strings - Get string set
 * @netdev: network interface device structure
 * @sset: id of string set
 * @data: buffer for string data
 *
 * Builds stats string table.
 **/
static void i40evf_get_strings(struct net_device *netdev, u32 sset, u8 *data)
{
	struct i40evf_adapter *adapter = netdev_priv(netdev);
	u8 *p = data;
	int i;

	if (sset == ETH_SS_STATS) {
200
		for (i = 0; i < (int)I40EVF_GLOBAL_STATS_LEN; i++) {
G
Greg Rose 已提交
201 202 203 204
			memcpy(p, i40evf_gstrings_stats[i].stat_string,
			       ETH_GSTRING_LEN);
			p += ETH_GSTRING_LEN;
		}
205
		for (i = 0; i < adapter->num_active_queues; i++) {
G
Greg Rose 已提交
206 207 208 209 210
			snprintf(p, ETH_GSTRING_LEN, "tx-%u.packets", i);
			p += ETH_GSTRING_LEN;
			snprintf(p, ETH_GSTRING_LEN, "tx-%u.bytes", i);
			p += ETH_GSTRING_LEN;
		}
211
		for (i = 0; i < adapter->num_active_queues; i++) {
G
Greg Rose 已提交
212 213 214 215 216
			snprintf(p, ETH_GSTRING_LEN, "rx-%u.packets", i);
			p += ETH_GSTRING_LEN;
			snprintf(p, ETH_GSTRING_LEN, "rx-%u.bytes", i);
			p += ETH_GSTRING_LEN;
		}
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
	} else if (sset == ETH_SS_PRIV_FLAGS) {
		for (i = 0; i < I40EVF_PRIV_FLAGS_STR_LEN; i++) {
			snprintf(p, ETH_GSTRING_LEN, "%s",
				 i40evf_gstrings_priv_flags[i].flag_string);
			p += ETH_GSTRING_LEN;
		}
	}
}

/**
 * i40evf_get_priv_flags - report device private flags
 * @dev: network interface device structure
 *
 * The get string set count and the string set should be matched for each
 * flag returned.  Add new strings for each flag to the i40e_gstrings_priv_flags
 * array.
 *
 * Returns a u32 bitmap of flags.
 **/
static u32 i40evf_get_priv_flags(struct net_device *netdev)
{
	struct i40evf_adapter *adapter = netdev_priv(netdev);
	u32 i, ret_flags = 0;

	for (i = 0; i < I40EVF_PRIV_FLAGS_STR_LEN; i++) {
		const struct i40evf_priv_flags *priv_flags;

		priv_flags = &i40evf_gstrings_priv_flags[i];

		if (priv_flags->flag & adapter->flags)
			ret_flags |= BIT(i);
	}

	return ret_flags;
}

/**
 * i40evf_set_priv_flags - set private flags
 * @dev: network interface device structure
 * @flags: bit flags to be set
 **/
static int i40evf_set_priv_flags(struct net_device *netdev, u32 flags)
{
	struct i40evf_adapter *adapter = netdev_priv(netdev);
261
	u32 orig_flags, new_flags, changed_flags;
262 263
	u32 i;

264 265
	orig_flags = READ_ONCE(adapter->flags);
	new_flags = orig_flags;
266 267 268 269 270 271 272

	for (i = 0; i < I40EVF_PRIV_FLAGS_STR_LEN; i++) {
		const struct i40evf_priv_flags *priv_flags;

		priv_flags = &i40evf_gstrings_priv_flags[i];

		if (flags & BIT(i))
273
			new_flags |= priv_flags->flag;
274
		else
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
			new_flags &= ~(priv_flags->flag);

		if (priv_flags->read_only &&
		    ((orig_flags ^ new_flags) & ~BIT(i)))
			return -EOPNOTSUPP;
	}

	/* Before we finalize any flag changes, any checks which we need to
	 * perform to determine if the new flags will be supported should go
	 * here...
	 */

	/* Compare and exchange the new flags into place. If we failed, that
	 * is if cmpxchg returns anything but the old value, this means
	 * something else must have modified the flags variable since we
	 * copied it. We'll just punt with an error and log something in the
	 * message buffer.
	 */
	if (cmpxchg(&adapter->flags, orig_flags, new_flags) != orig_flags) {
		dev_warn(&adapter->pdev->dev,
			 "Unable to update adapter->flags as it was modified by another thread...\n");
		return -EAGAIN;
297 298
	}

299
	changed_flags = orig_flags ^ new_flags;
300

301 302 303 304
	/* Process any additional changes needed as a result of flag changes.
	 * The changed_flags value reflects the list of bits that were changed
	 * in the code above.
	 */
305 306 307 308 309 310 311

	/* issue a reset to force legacy-rx change to take effect */
	if (changed_flags & I40EVF_FLAG_LEGACY_RX) {
		if (netif_running(netdev)) {
			adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
			schedule_work(&adapter->reset_task);
		}
G
Greg Rose 已提交
312
	}
313 314

	return 0;
G
Greg Rose 已提交
315 316 317 318 319 320 321 322 323 324 325
}

/**
 * i40evf_get_msglevel - Get debug message level
 * @netdev: network interface device structure
 *
 * Returns current debug message level.
 **/
static u32 i40evf_get_msglevel(struct net_device *netdev)
{
	struct i40evf_adapter *adapter = netdev_priv(netdev);
M
Mitch Williams 已提交
326

G
Greg Rose 已提交
327 328 329 330
	return adapter->msg_enable;
}

/**
331
 * i40evf_set_msglevel - Set debug message level
G
Greg Rose 已提交
332 333 334 335 336 337 338 339 340
 * @netdev: network interface device structure
 * @data: message level
 *
 * Set current debug message level. Higher values cause the driver to
 * be noisier.
 **/
static void i40evf_set_msglevel(struct net_device *netdev, u32 data)
{
	struct i40evf_adapter *adapter = netdev_priv(netdev);
M
Mitch Williams 已提交
341

342 343
	if (I40E_DEBUG_USER & data)
		adapter->hw.debug_mask = data;
G
Greg Rose 已提交
344 345 346 347
	adapter->msg_enable = data;
}

/**
348
 * i40evf_get_drvinfo - Get driver info
G
Greg Rose 已提交
349 350 351 352 353 354 355 356 357 358 359 360
 * @netdev: network interface device structure
 * @drvinfo: ethool driver info structure
 *
 * Returns information about the driver and device for display to the user.
 **/
static void i40evf_get_drvinfo(struct net_device *netdev,
			       struct ethtool_drvinfo *drvinfo)
{
	struct i40evf_adapter *adapter = netdev_priv(netdev);

	strlcpy(drvinfo->driver, i40evf_driver_name, 32);
	strlcpy(drvinfo->version, i40evf_driver_version, 32);
361
	strlcpy(drvinfo->fw_version, "N/A", 4);
G
Greg Rose 已提交
362
	strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
363
	drvinfo->n_priv_flags = I40EVF_PRIV_FLAGS_STR_LEN;
G
Greg Rose 已提交
364 365 366 367 368 369 370 371 372 373 374
}

/**
 * i40evf_get_ringparam - Get ring parameters
 * @netdev: network interface device structure
 * @ring: ethtool ringparam structure
 *
 * Returns current ring parameters. TX and RX rings are reported separately,
 * but the number of rings is not reported.
 **/
static void i40evf_get_ringparam(struct net_device *netdev,
M
Mitch Williams 已提交
375
				 struct ethtool_ringparam *ring)
G
Greg Rose 已提交
376 377 378 379 380
{
	struct i40evf_adapter *adapter = netdev_priv(netdev);

	ring->rx_max_pending = I40EVF_MAX_RXD;
	ring->tx_max_pending = I40EVF_MAX_TXD;
381 382
	ring->rx_pending = adapter->rx_desc_count;
	ring->tx_pending = adapter->tx_desc_count;
G
Greg Rose 已提交
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
}

/**
 * i40evf_set_ringparam - Set ring parameters
 * @netdev: network interface device structure
 * @ring: ethtool ringparam structure
 *
 * Sets ring parameters. TX and RX rings are controlled separately, but the
 * number of rings is not specified, so all rings get the same settings.
 **/
static int i40evf_set_ringparam(struct net_device *netdev,
				struct ethtool_ringparam *ring)
{
	struct i40evf_adapter *adapter = netdev_priv(netdev);
	u32 new_rx_count, new_tx_count;

	if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
		return -EINVAL;

	new_tx_count = clamp_t(u32, ring->tx_pending,
			       I40EVF_MIN_TXD,
			       I40EVF_MAX_TXD);
	new_tx_count = ALIGN(new_tx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);

	new_rx_count = clamp_t(u32, ring->rx_pending,
			       I40EVF_MIN_RXD,
			       I40EVF_MAX_RXD);
	new_rx_count = ALIGN(new_rx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);

	/* if nothing to do return success */
413 414
	if ((new_tx_count == adapter->tx_desc_count) &&
	    (new_rx_count == adapter->rx_desc_count))
G
Greg Rose 已提交
415 416
		return 0;

417 418
	adapter->tx_desc_count = new_tx_count;
	adapter->rx_desc_count = new_rx_count;
G
Greg Rose 已提交
419

420 421 422 423
	if (netif_running(netdev)) {
		adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
		schedule_work(&adapter->reset_task);
	}
424

G
Greg Rose 已提交
425 426 427 428
	return 0;
}

/**
429 430 431 432
 * __i40evf_get_coalesce - get per-queue coalesce settings
 * @netdev: the netdev to check
 * @ec: ethtool coalesce data structure
 * @queue: which queue to pick
G
Greg Rose 已提交
433
 *
434 435 436
 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
 * are per queue. If queue is <0 then we default to queue 0 as the
 * representative value.
G
Greg Rose 已提交
437
 **/
438 439 440
static int __i40evf_get_coalesce(struct net_device *netdev,
				 struct ethtool_coalesce *ec,
				 int queue)
G
Greg Rose 已提交
441 442 443
{
	struct i40evf_adapter *adapter = netdev_priv(netdev);
	struct i40e_vsi *vsi = &adapter->vsi;
444
	struct i40e_ring *rx_ring, *tx_ring;
G
Greg Rose 已提交
445 446 447 448

	ec->tx_max_coalesced_frames = vsi->work_limit;
	ec->rx_max_coalesced_frames = vsi->work_limit;

449 450 451 452 453 454 455 456 457 458 459 460
	/* Rx and Tx usecs per queue value. If user doesn't specify the
	 * queue, return queue 0's value to represent.
	 */
	if (queue < 0)
		queue = 0;
	else if (queue >= adapter->num_active_queues)
		return -EINVAL;

	rx_ring = &adapter->rx_rings[queue];
	tx_ring = &adapter->tx_rings[queue];

	if (ITR_IS_DYNAMIC(rx_ring->rx_itr_setting))
461
		ec->use_adaptive_rx_coalesce = 1;
G
Greg Rose 已提交
462

463
	if (ITR_IS_DYNAMIC(tx_ring->tx_itr_setting))
464 465
		ec->use_adaptive_tx_coalesce = 1;

466 467
	ec->rx_coalesce_usecs = rx_ring->rx_itr_setting & ~I40E_ITR_DYNAMIC;
	ec->tx_coalesce_usecs = tx_ring->tx_itr_setting & ~I40E_ITR_DYNAMIC;
G
Greg Rose 已提交
468 469 470 471 472

	return 0;
}

/**
473
 * i40evf_get_coalesce - Get interrupt coalescing settings
G
Greg Rose 已提交
474 475 476
 * @netdev: network interface device structure
 * @ec: ethtool coalesce structure
 *
477 478 479 480
 * Returns current coalescing settings. This is referred to elsewhere in the
 * driver as Interrupt Throttle Rate, as this is how the hardware describes
 * this functionality. Note that if per-queue settings have been modified this
 * only represents the settings of queue 0.
G
Greg Rose 已提交
481
 **/
482
static int i40evf_get_coalesce(struct net_device *netdev,
M
Mitch Williams 已提交
483
			       struct ethtool_coalesce *ec)
G
Greg Rose 已提交
484
{
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
	return __i40evf_get_coalesce(netdev, ec, -1);
}

/**
 * i40evf_get_per_queue_coalesce - get coalesce values for specific queue
 * @netdev: netdev to read
 * @ec: coalesce settings from ethtool
 * @queue: the queue to read
 *
 * Read specific queue's coalesce settings.
 **/
static int i40evf_get_per_queue_coalesce(struct net_device *netdev,
					 u32 queue,
					 struct ethtool_coalesce *ec)
{
	return __i40evf_get_coalesce(netdev, ec, queue);
}

/**
 * i40evf_set_itr_per_queue - set ITR values for specific queue
 * @vsi: the VSI to set values for
 * @ec: coalesce settings from ethtool
 * @queue: the queue to modify
 *
 * Change the ITR settings for a specific queue.
 **/
static void i40evf_set_itr_per_queue(struct i40evf_adapter *adapter,
				     struct ethtool_coalesce *ec,
				     int queue)
{
515 516
	struct i40e_ring *rx_ring = &adapter->rx_rings[queue];
	struct i40e_ring *tx_ring = &adapter->tx_rings[queue];
G
Greg Rose 已提交
517
	struct i40e_vsi *vsi = &adapter->vsi;
518
	struct i40e_hw *hw = &adapter->hw;
G
Greg Rose 已提交
519
	struct i40e_q_vector *q_vector;
520 521
	u16 vector;

522 523
	rx_ring->rx_itr_setting = ec->rx_coalesce_usecs;
	tx_ring->tx_itr_setting = ec->tx_coalesce_usecs;
524

525 526 527
	rx_ring->rx_itr_setting |= I40E_ITR_DYNAMIC;
	if (!ec->use_adaptive_rx_coalesce)
		rx_ring->rx_itr_setting ^= I40E_ITR_DYNAMIC;
528

529 530 531
	tx_ring->tx_itr_setting |= I40E_ITR_DYNAMIC;
	if (!ec->use_adaptive_tx_coalesce)
		tx_ring->tx_itr_setting ^= I40E_ITR_DYNAMIC;
532

533 534
	q_vector = rx_ring->q_vector;
	q_vector->rx.itr = ITR_TO_REG(rx_ring->rx_itr_setting);
535 536 537
	vector = vsi->base_vector + q_vector->v_idx;
	wr32(hw, I40E_VFINT_ITRN1(I40E_RX_ITR, vector - 1), q_vector->rx.itr);

538 539
	q_vector = tx_ring->q_vector;
	q_vector->tx.itr = ITR_TO_REG(tx_ring->tx_itr_setting);
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
	vector = vsi->base_vector + q_vector->v_idx;
	wr32(hw, I40E_VFINT_ITRN1(I40E_TX_ITR, vector - 1), q_vector->tx.itr);

	i40e_flush(hw);
}

/**
 * __i40evf_set_coalesce - set coalesce settings for particular queue
 * @netdev: the netdev to change
 * @ec: ethtool coalesce settings
 * @queue: the queue to change
 *
 * Sets the coalesce settings for a particular queue.
 **/
static int __i40evf_set_coalesce(struct net_device *netdev,
				 struct ethtool_coalesce *ec,
				 int queue)
{
	struct i40evf_adapter *adapter = netdev_priv(netdev);
	struct i40e_vsi *vsi = &adapter->vsi;
G
Greg Rose 已提交
560 561
	int i;

562 563 564
	if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
		vsi->work_limit = ec->tx_max_coalesced_frames_irq;

565 566 567 568 569 570
	if (ec->rx_coalesce_usecs == 0) {
		if (ec->use_adaptive_rx_coalesce)
			netif_info(adapter, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
	} else if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
		   (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
		netif_info(adapter, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
571
		return -EINVAL;
572
	}
573 574

	else
575 576 577 578 579 580
	if (ec->tx_coalesce_usecs == 0) {
		if (ec->use_adaptive_tx_coalesce)
			netif_info(adapter, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
	} else if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
		   (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
		netif_info(adapter, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
581
		return -EINVAL;
582
	}
583

584 585 586 587 588 589 590 591 592 593 594 595
	/* Rx and Tx usecs has per queue value. If user doesn't specify the
	 * queue, apply to all queues.
	 */
	if (queue < 0) {
		for (i = 0; i < adapter->num_active_queues; i++)
			i40evf_set_itr_per_queue(adapter, ec, i);
	} else if (queue < adapter->num_active_queues) {
		i40evf_set_itr_per_queue(adapter, ec, queue);
	} else {
		netif_info(adapter, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
			   adapter->num_active_queues - 1);
		return -EINVAL;
G
Greg Rose 已提交
596 597 598 599 600
	}

	return 0;
}

601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
/**
 * i40evf_set_coalesce - Set interrupt coalescing settings
 * @netdev: network interface device structure
 * @ec: ethtool coalesce structure
 *
 * Change current coalescing settings for every queue.
 **/
static int i40evf_set_coalesce(struct net_device *netdev,
			       struct ethtool_coalesce *ec)
{
	return __i40evf_set_coalesce(netdev, ec, -1);
}

/**
 * i40evf_set_per_queue_coalesce - set specific queue's coalesce settings
 * @netdev: the netdev to change
 * @ec: ethtool's coalesce settings
 * @queue: the queue to modify
 *
 * Modifies a specific queue's coalesce settings.
 */
static int i40evf_set_per_queue_coalesce(struct net_device *netdev,
					 u32 queue,
					 struct ethtool_coalesce *ec)
{
	return __i40evf_set_coalesce(netdev, ec, queue);
}

629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644
/**
 * i40evf_get_rxnfc - command to get RX flow classification rules
 * @netdev: network interface device structure
 * @cmd: ethtool rxnfc command
 *
 * Returns Success if the command is supported.
 **/
static int i40evf_get_rxnfc(struct net_device *netdev,
			    struct ethtool_rxnfc *cmd,
			    u32 *rule_locs)
{
	struct i40evf_adapter *adapter = netdev_priv(netdev);
	int ret = -EOPNOTSUPP;

	switch (cmd->cmd) {
	case ETHTOOL_GRXRINGS:
645
		cmd->data = adapter->num_active_queues;
646 647 648
		ret = 0;
		break;
	case ETHTOOL_GRXFH:
649 650
		netdev_info(netdev,
			    "RSS hash info is not available to vf, use pf.\n");
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671
		break;
	default:
		break;
	}

	return ret;
}
/**
 * i40evf_get_channels: get the number of channels supported by the device
 * @netdev: network interface device structure
 * @ch: channel information structure
 *
 * For the purposes of our device, we only use combined channels, i.e. a tx/rx
 * queue pair. Report one extra channel to match our "other" MSI-X vector.
 **/
static void i40evf_get_channels(struct net_device *netdev,
				struct ethtool_channels *ch)
{
	struct i40evf_adapter *adapter = netdev_priv(netdev);

	/* Report maximum channels */
672
	ch->max_combined = I40EVF_MAX_REQ_QUEUES;
673 674 675 676

	ch->max_other = NONQ_VECS;
	ch->other_count = NONQ_VECS;

677
	ch->combined_count = adapter->num_active_queues;
678 679
}

680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714
/**
 * i40evf_set_channels: set the new channel count
 * @netdev: network interface device structure
 * @ch: channel information structure
 *
 * Negotiate a new number of channels with the PF then do a reset.  During
 * reset we'll realloc queues and fix the RSS table.  Returns 0 on success,
 * negative on failure.
 **/
static int i40evf_set_channels(struct net_device *netdev,
			       struct ethtool_channels *ch)
{
	struct i40evf_adapter *adapter = netdev_priv(netdev);
	int num_req = ch->combined_count;

	if (num_req != adapter->num_active_queues &&
	    !(adapter->vf_res->vf_cap_flags &
	      VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)) {
		dev_info(&adapter->pdev->dev, "PF is not capable of queue negotiation.\n");
		return -EINVAL;
	}

	/* All of these should have already been checked by ethtool before this
	 * even gets to us, but just to be sure.
	 */
	if (num_req <= 0 || num_req > I40EVF_MAX_REQ_QUEUES)
		return -EINVAL;

	if (ch->rx_count || ch->tx_count || ch->other_count != NONQ_VECS)
		return -EINVAL;

	adapter->num_req_queues = num_req;
	return i40evf_request_queues(adapter, num_req);
}

715 716 717 718 719 720 721 722 723 724 725 726 727
/**
 * i40evf_get_rxfh_key_size - get the RSS hash key size
 * @netdev: network interface device structure
 *
 * Returns the table size.
 **/
static u32 i40evf_get_rxfh_key_size(struct net_device *netdev)
{
	struct i40evf_adapter *adapter = netdev_priv(netdev);

	return adapter->rss_key_size;
}

728 729 730 731 732 733 734 735
/**
 * i40evf_get_rxfh_indir_size - get the rx flow hash indirection table size
 * @netdev: network interface device structure
 *
 * Returns the table size.
 **/
static u32 i40evf_get_rxfh_indir_size(struct net_device *netdev)
{
736 737 738
	struct i40evf_adapter *adapter = netdev_priv(netdev);

	return adapter->rss_lut_size;
739 740 741
}

/**
742
 * i40evf_get_rxfh - get the rx flow hash indirection table
743 744
 * @netdev: network interface device structure
 * @indir: indirection table
M
Mitch Williams 已提交
745
 * @key: hash key
746 747 748
 *
 * Reads the indirection table directly from the hardware. Always returns 0.
 **/
749 750
static int i40evf_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
			   u8 *hfunc)
751 752
{
	struct i40evf_adapter *adapter = netdev_priv(netdev);
753
	u16 i;
754

755 756 757 758 759
	if (hfunc)
		*hfunc = ETH_RSS_HASH_TOP;
	if (!indir)
		return 0;

760
	memcpy(key, adapter->rss_key, adapter->rss_key_size);
761 762

	/* Each 32 bits pointed by 'indir' is stored with a lut entry */
763 764
	for (i = 0; i < adapter->rss_lut_size; i++)
		indir[i] = (u32)adapter->rss_lut[i];
765

766
	return 0;
767 768 769
}

/**
770
 * i40evf_set_rxfh - set the rx flow hash indirection table
771 772
 * @netdev: network interface device structure
 * @indir: indirection table
M
Mitch Williams 已提交
773
 * @key: hash key
774 775 776 777
 *
 * Returns -EINVAL if the table specifies an inavlid queue id, otherwise
 * returns 0 after programming the table.
 **/
778
static int i40evf_set_rxfh(struct net_device *netdev, const u32 *indir,
779
			   const u8 *key, const u8 hfunc)
780 781
{
	struct i40evf_adapter *adapter = netdev_priv(netdev);
782
	u16 i;
783

784 785 786 787 788 789 790
	/* We do not allow change in unsupported parameters */
	if (key ||
	    (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
		return -EOPNOTSUPP;
	if (!indir)
		return 0;

791
	if (key) {
792
		memcpy(adapter->rss_key, key, adapter->rss_key_size);
793 794
	}

795
	/* Each 32 bits pointed by 'indir' is stored with a lut entry */
796 797
	for (i = 0; i < adapter->rss_lut_size; i++)
		adapter->rss_lut[i] = (u8)(indir[i]);
798

799
	return i40evf_config_rss(adapter);
800 801
}

M
Mitch Williams 已提交
802
static const struct ethtool_ops i40evf_ethtool_ops = {
G
Greg Rose 已提交
803 804 805 806 807 808 809
	.get_drvinfo		= i40evf_get_drvinfo,
	.get_link		= ethtool_op_get_link,
	.get_ringparam		= i40evf_get_ringparam,
	.set_ringparam		= i40evf_set_ringparam,
	.get_strings		= i40evf_get_strings,
	.get_ethtool_stats	= i40evf_get_ethtool_stats,
	.get_sset_count		= i40evf_get_sset_count,
810 811
	.get_priv_flags		= i40evf_get_priv_flags,
	.set_priv_flags		= i40evf_set_priv_flags,
G
Greg Rose 已提交
812 813 814 815
	.get_msglevel		= i40evf_get_msglevel,
	.set_msglevel		= i40evf_set_msglevel,
	.get_coalesce		= i40evf_get_coalesce,
	.set_coalesce		= i40evf_set_coalesce,
816 817
	.get_per_queue_coalesce = i40evf_get_per_queue_coalesce,
	.set_per_queue_coalesce = i40evf_set_per_queue_coalesce,
818 819
	.get_rxnfc		= i40evf_get_rxnfc,
	.get_rxfh_indir_size	= i40evf_get_rxfh_indir_size,
820 821
	.get_rxfh		= i40evf_get_rxfh,
	.set_rxfh		= i40evf_set_rxfh,
822
	.get_channels		= i40evf_get_channels,
823
	.set_channels		= i40evf_set_channels,
824
	.get_rxfh_key_size	= i40evf_get_rxfh_key_size,
825
	.get_link_ksettings	= i40evf_get_link_ksettings,
G
Greg Rose 已提交
826 827 828 829 830 831 832 833 834 835 836
};

/**
 * i40evf_set_ethtool_ops - Initialize ethtool ops struct
 * @netdev: network interface device structure
 *
 * Sets ethtool ops struct in our netdev so that ethtool can call
 * our functions.
 **/
void i40evf_set_ethtool_ops(struct net_device *netdev)
{
837
	netdev->ethtool_ops = &i40evf_ethtool_ops;
G
Greg Rose 已提交
838
}