i40e_debugfs.c 70.6 KB
Newer Older
J
Jesse Brandeburg 已提交
1 2 3
/*******************************************************************************
 *
 * Intel Ethernet Controller XL710 Family Linux Driver
G
Greg Rose 已提交
4
 * Copyright(c) 2013 - 2014 Intel Corporation.
J
Jesse Brandeburg 已提交
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.
 *
G
Greg Rose 已提交
15 16
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
J
Jesse Brandeburg 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
 *
 * 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
 *
 ******************************************************************************/

#ifdef CONFIG_DEBUG_FS

#include <linux/fs.h>
#include <linux/debugfs.h>

#include "i40e.h"

static struct dentry *i40e_dbg_root;

/**
 * i40e_dbg_find_vsi - searches for the vsi with the given seid
38
 * @pf - the PF structure to search for the vsi
J
Jesse Brandeburg 已提交
39 40 41 42 43 44 45 46 47
 * @seid - seid of the vsi it is searching for
 **/
static struct i40e_vsi *i40e_dbg_find_vsi(struct i40e_pf *pf, int seid)
{
	int i;

	if (seid < 0)
		dev_info(&pf->pdev->dev, "%d: bad seid\n", seid);
	else
M
Mitch Williams 已提交
48
		for (i = 0; i < pf->num_alloc_vsi; i++)
J
Jesse Brandeburg 已提交
49 50 51 52 53 54 55 56
			if (pf->vsi[i] && (pf->vsi[i]->seid == seid))
				return pf->vsi[i];

	return NULL;
}

/**
 * i40e_dbg_find_veb - searches for the veb with the given seid
57
 * @pf - the PF structure to search for the veb
J
Jesse Brandeburg 已提交
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
 * @seid - seid of the veb it is searching for
 **/
static struct i40e_veb *i40e_dbg_find_veb(struct i40e_pf *pf, int seid)
{
	int i;

	if ((seid < I40E_BASE_VEB_SEID) ||
	    (seid > (I40E_BASE_VEB_SEID + I40E_MAX_VEB)))
		dev_info(&pf->pdev->dev, "%d: bad seid\n", seid);
	else
		for (i = 0; i < I40E_MAX_VEB; i++)
			if (pf->veb[i] && pf->veb[i]->seid == seid)
				return pf->veb[i];
	return NULL;
}

/**************************************************************
 * dump
 * The dump entry in debugfs is for getting a data snapshow of
 * the driver's current configuration and runtime details.
 * When the filesystem entry is written, a snapshot is taken.
 * When the entry is read, the most recent snapshot data is dumped.
 **************************************************************/
static char *i40e_dbg_dump_buf;
static ssize_t i40e_dbg_dump_data_len;
static ssize_t i40e_dbg_dump_buffer_len;

/**
 * i40e_dbg_dump_read - read the dump data
 * @filp: the opened file
 * @buffer: where to write the data for the user to read
 * @count: the size of the user's buffer
 * @ppos: file position offset
 **/
static ssize_t i40e_dbg_dump_read(struct file *filp, char __user *buffer,
				  size_t count, loff_t *ppos)
{
	int bytes_not_copied;
	int len;

	/* is *ppos bigger than the available data? */
	if (*ppos >= i40e_dbg_dump_data_len || !i40e_dbg_dump_buf)
		return 0;

	/* be sure to not read beyond the end of available data */
	len = min_t(int, count, (i40e_dbg_dump_data_len - *ppos));

	bytes_not_copied = copy_to_user(buffer, &i40e_dbg_dump_buf[*ppos], len);
R
Rasmus Villemoes 已提交
106 107
	if (bytes_not_copied)
		return -EFAULT;
J
Jesse Brandeburg 已提交
108 109 110 111 112 113 114

	*ppos += len;
	return len;
}

/**
 * i40e_dbg_prep_dump_buf
115
 * @pf: the PF we're working with
J
Jesse Brandeburg 已提交
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
 * @buflen: the desired buffer length
 *
 * Return positive if success, 0 if failed
 **/
static int i40e_dbg_prep_dump_buf(struct i40e_pf *pf, int buflen)
{
	/* if not already big enough, prep for re alloc */
	if (i40e_dbg_dump_buffer_len && i40e_dbg_dump_buffer_len < buflen) {
		kfree(i40e_dbg_dump_buf);
		i40e_dbg_dump_buffer_len = 0;
		i40e_dbg_dump_buf = NULL;
	}

	/* get a new buffer if needed */
	if (!i40e_dbg_dump_buf) {
		i40e_dbg_dump_buf = kzalloc(buflen, GFP_KERNEL);
		if (i40e_dbg_dump_buf != NULL)
			i40e_dbg_dump_buffer_len = buflen;
	}

	return i40e_dbg_dump_buffer_len;
}

/**
 * i40e_dbg_dump_write - trigger a datadump snapshot
 * @filp: the opened file
 * @buffer: where to find the user's data
 * @count: the length of the user's data
 * @ppos: file position offset
 *
 * Any write clears the stats
 **/
static ssize_t i40e_dbg_dump_write(struct file *filp,
				   const char __user *buffer,
				   size_t count, loff_t *ppos)
{
	struct i40e_pf *pf = filp->private_data;
	bool seid_found = false;
	long seid = -1;
	int buflen = 0;
	int i, ret;
	int len;
	u8 *p;

	/* don't allow partial writes */
	if (*ppos != 0)
		return 0;

	/* decode the SEID given to be dumped */
165 166 167 168
	ret = kstrtol_from_user(buffer, count, 0, &seid);

	if (ret) {
		dev_info(&pf->pdev->dev, "bad seid value\n");
J
Jesse Brandeburg 已提交
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
	} else if (seid == 0) {
		seid_found = true;

		kfree(i40e_dbg_dump_buf);
		i40e_dbg_dump_buffer_len = 0;
		i40e_dbg_dump_data_len = 0;
		i40e_dbg_dump_buf = NULL;
		dev_info(&pf->pdev->dev, "debug buffer freed\n");

	} else if (seid == pf->pf_seid || seid == 1) {
		seid_found = true;

		buflen = sizeof(struct i40e_pf);
		buflen += (sizeof(struct i40e_aq_desc)
		     * (pf->hw.aq.num_arq_entries + pf->hw.aq.num_asq_entries));

		if (i40e_dbg_prep_dump_buf(pf, buflen)) {
			p = i40e_dbg_dump_buf;

			len = sizeof(struct i40e_pf);
			memcpy(p, pf, len);
			p += len;

			len = (sizeof(struct i40e_aq_desc)
					* pf->hw.aq.num_asq_entries);
194
			memcpy(p, pf->hw.aq.asq.desc_buf.va, len);
J
Jesse Brandeburg 已提交
195 196 197 198
			p += len;

			len = (sizeof(struct i40e_aq_desc)
					* pf->hw.aq.num_arq_entries);
199
			memcpy(p, pf->hw.aq.arq.desc_buf.va, len);
J
Jesse Brandeburg 已提交
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
			p += len;

			i40e_dbg_dump_data_len = buflen;
			dev_info(&pf->pdev->dev,
				 "PF seid %ld dumped %d bytes\n",
				 seid, (int)i40e_dbg_dump_data_len);
		}
	} else if (seid >= I40E_BASE_VSI_SEID) {
		struct i40e_vsi *vsi = NULL;
		struct i40e_mac_filter *f;
		int filter_count = 0;

		mutex_lock(&pf->switch_mutex);
		vsi = i40e_dbg_find_vsi(pf, seid);
		if (!vsi) {
			mutex_unlock(&pf->switch_mutex);
			goto write_exit;
		}

		buflen = sizeof(struct i40e_vsi);
		buflen += sizeof(struct i40e_q_vector) * vsi->num_q_vectors;
		buflen += sizeof(struct i40e_ring) * 2 * vsi->num_queue_pairs;
		buflen += sizeof(struct i40e_tx_buffer) * vsi->num_queue_pairs;
		buflen += sizeof(struct i40e_rx_buffer) * vsi->num_queue_pairs;
		list_for_each_entry(f, &vsi->mac_filter_list, list)
			filter_count++;
		buflen += sizeof(struct i40e_mac_filter) * filter_count;

		if (i40e_dbg_prep_dump_buf(pf, buflen)) {
			p = i40e_dbg_dump_buf;
			seid_found = true;

			len = sizeof(struct i40e_vsi);
			memcpy(p, vsi, len);
			p += len;

236 237 238 239 240 241
			if (vsi->num_q_vectors) {
				len = (sizeof(struct i40e_q_vector)
					* vsi->num_q_vectors);
				memcpy(p, vsi->q_vectors, len);
				p += len;
			}
J
Jesse Brandeburg 已提交
242

243 244 245 246 247 248
			if (vsi->num_queue_pairs) {
				len = (sizeof(struct i40e_ring) *
				      vsi->num_queue_pairs);
				memcpy(p, vsi->tx_rings, len);
				p += len;
				memcpy(p, vsi->rx_rings, len);
J
Jesse Brandeburg 已提交
249 250
				p += len;
			}
251 252 253 254 255 256 257

			if (vsi->tx_rings[0]) {
				len = sizeof(struct i40e_tx_buffer);
				for (i = 0; i < vsi->num_queue_pairs; i++) {
					memcpy(p, vsi->tx_rings[i]->tx_bi, len);
					p += len;
				}
J
Jesse Brandeburg 已提交
258
				len = sizeof(struct i40e_rx_buffer);
259 260 261 262
				for (i = 0; i < vsi->num_queue_pairs; i++) {
					memcpy(p, vsi->rx_rings[i]->rx_bi, len);
					p += len;
				}
J
Jesse Brandeburg 已提交
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
			}

			/* macvlan filter list */
			len = sizeof(struct i40e_mac_filter);
			list_for_each_entry(f, &vsi->mac_filter_list, list) {
				memcpy(p, f, len);
				p += len;
			}

			i40e_dbg_dump_data_len = buflen;
			dev_info(&pf->pdev->dev,
				 "VSI seid %ld dumped %d bytes\n",
				 seid, (int)i40e_dbg_dump_data_len);
		}
		mutex_unlock(&pf->switch_mutex);
	} else if (seid >= I40E_BASE_VEB_SEID) {
		struct i40e_veb *veb = NULL;

		mutex_lock(&pf->switch_mutex);
		veb = i40e_dbg_find_veb(pf, seid);
		if (!veb) {
			mutex_unlock(&pf->switch_mutex);
			goto write_exit;
		}

		buflen = sizeof(struct i40e_veb);
		if (i40e_dbg_prep_dump_buf(pf, buflen)) {
			seid_found = true;
			memcpy(i40e_dbg_dump_buf, veb, buflen);
			i40e_dbg_dump_data_len = buflen;
			dev_info(&pf->pdev->dev,
				 "VEB seid %ld dumped %d bytes\n",
				 seid, (int)i40e_dbg_dump_data_len);
		}
		mutex_unlock(&pf->switch_mutex);
	}

write_exit:
	if (!seid_found)
		dev_info(&pf->pdev->dev, "unknown seid %ld\n", seid);

	return count;
}

static const struct file_operations i40e_dbg_dump_fops = {
	.owner = THIS_MODULE,
	.open =  simple_open,
	.read =  i40e_dbg_dump_read,
	.write = i40e_dbg_dump_write,
};

/**************************************************************
 * command
 * The command entry in debugfs is for giving the driver commands
 * to be executed - these may be for changing the internal switch
 * setup, adding or removing filters, or other things.  Many of
 * these will be useful for some forms of unit testing.
 **************************************************************/
321
static char i40e_dbg_command_buf[256] = "";
J
Jesse Brandeburg 已提交
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355

/**
 * i40e_dbg_command_read - read for command datum
 * @filp: the opened file
 * @buffer: where to write the data for the user to read
 * @count: the size of the user's buffer
 * @ppos: file position offset
 **/
static ssize_t i40e_dbg_command_read(struct file *filp, char __user *buffer,
				     size_t count, loff_t *ppos)
{
	struct i40e_pf *pf = filp->private_data;
	int bytes_not_copied;
	int buf_size = 256;
	char *buf;
	int len;

	/* don't allow partial reads */
	if (*ppos != 0)
		return 0;
	if (count < buf_size)
		return -ENOSPC;

	buf = kzalloc(buf_size, GFP_KERNEL);
	if (!buf)
		return -ENOSPC;

	len = snprintf(buf, buf_size, "%s: %s\n",
		       pf->vsi[pf->lan_vsi]->netdev->name,
		       i40e_dbg_command_buf);

	bytes_not_copied = copy_to_user(buffer, buf, len);
	kfree(buf);

R
Rasmus Villemoes 已提交
356 357
	if (bytes_not_copied)
		return -EFAULT;
J
Jesse Brandeburg 已提交
358 359 360 361 362 363

	*ppos = len;
	return len;
}

/**
S
Shannon Nelson 已提交
364
 * i40e_dbg_dump_vsi_seid - handles dump vsi seid write into command datum
J
Jesse Brandeburg 已提交
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
 * @pf: the i40e_pf created in command write
 * @seid: the seid the user put in
 **/
static void i40e_dbg_dump_vsi_seid(struct i40e_pf *pf, int seid)
{
	struct rtnl_link_stats64 *nstat;
	struct i40e_mac_filter *f;
	struct i40e_vsi *vsi;
	int i;

	vsi = i40e_dbg_find_vsi(pf, seid);
	if (!vsi) {
		dev_info(&pf->pdev->dev,
			 "dump %d: seid not found\n", seid);
		return;
	}
	dev_info(&pf->pdev->dev, "vsi seid %d\n", seid);
382 383 384 385 386 387 388 389 390 391 392 393
	if (vsi->netdev) {
		struct net_device *nd = vsi->netdev;

		dev_info(&pf->pdev->dev, "    netdev: name = %s, state = %lu, flags = 0x%08x\n",
			 nd->name, nd->state, nd->flags);
		dev_info(&pf->pdev->dev, "        features      = 0x%08lx\n",
			 (unsigned long int)nd->features);
		dev_info(&pf->pdev->dev, "        hw_features   = 0x%08lx\n",
			 (unsigned long int)nd->hw_features);
		dev_info(&pf->pdev->dev, "        vlan_features = 0x%08lx\n",
			 (unsigned long int)nd->vlan_features);
	}
J
Jesse Brandeburg 已提交
394 395 396 397
	if (vsi->active_vlans)
		dev_info(&pf->pdev->dev,
			 "    vlgrp: & = %p\n", vsi->active_vlans);
	dev_info(&pf->pdev->dev,
398 399 400
		 "    state = %li flags = 0x%08lx, netdev_registered = %i, current_netdev_flags = 0x%04x\n",
		 vsi->state, vsi->flags,
		 vsi->netdev_registered, vsi->current_netdev_flags);
401
	if (vsi == pf->vsi[pf->lan_vsi])
402
		dev_info(&pf->pdev->dev, "    MAC address: %pM SAN MAC: %pM Port MAC: %pM\n",
403 404 405
			 pf->hw.mac.addr,
			 pf->hw.mac.san_addr,
			 pf->hw.mac.port_addr);
J
Jesse Brandeburg 已提交
406 407 408 409 410 411 412 413 414
	list_for_each_entry(f, &vsi->mac_filter_list, list) {
		dev_info(&pf->pdev->dev,
			 "    mac_filter_list: %pM vid=%d, is_netdev=%d is_vf=%d counter=%d\n",
			 f->macaddr, f->vlan, f->is_netdev, f->is_vf,
			 f->counter);
	}
	nstat = i40e_get_vsi_stats_struct(vsi);
	dev_info(&pf->pdev->dev,
		 "    net_stats: rx_packets = %lu, rx_bytes = %lu, rx_errors = %lu, rx_dropped = %lu\n",
J
Jesse Brandeburg 已提交
415 416 417 418
		 (unsigned long int)nstat->rx_packets,
		 (unsigned long int)nstat->rx_bytes,
		 (unsigned long int)nstat->rx_errors,
		 (unsigned long int)nstat->rx_dropped);
J
Jesse Brandeburg 已提交
419 420
	dev_info(&pf->pdev->dev,
		 "    net_stats: tx_packets = %lu, tx_bytes = %lu, tx_errors = %lu, tx_dropped = %lu\n",
J
Jesse Brandeburg 已提交
421 422 423 424
		 (unsigned long int)nstat->tx_packets,
		 (unsigned long int)nstat->tx_bytes,
		 (unsigned long int)nstat->tx_errors,
		 (unsigned long int)nstat->tx_dropped);
J
Jesse Brandeburg 已提交
425 426
	dev_info(&pf->pdev->dev,
		 "    net_stats: multicast = %lu, collisions = %lu\n",
J
Jesse Brandeburg 已提交
427 428
		 (unsigned long int)nstat->multicast,
		 (unsigned long int)nstat->collisions);
J
Jesse Brandeburg 已提交
429 430
	dev_info(&pf->pdev->dev,
		 "    net_stats: rx_length_errors = %lu, rx_over_errors = %lu, rx_crc_errors = %lu\n",
J
Jesse Brandeburg 已提交
431 432 433
		 (unsigned long int)nstat->rx_length_errors,
		 (unsigned long int)nstat->rx_over_errors,
		 (unsigned long int)nstat->rx_crc_errors);
J
Jesse Brandeburg 已提交
434 435
	dev_info(&pf->pdev->dev,
		 "    net_stats: rx_frame_errors = %lu, rx_fifo_errors = %lu, rx_missed_errors = %lu\n",
J
Jesse Brandeburg 已提交
436 437 438
		 (unsigned long int)nstat->rx_frame_errors,
		 (unsigned long int)nstat->rx_fifo_errors,
		 (unsigned long int)nstat->rx_missed_errors);
J
Jesse Brandeburg 已提交
439 440
	dev_info(&pf->pdev->dev,
		 "    net_stats: tx_aborted_errors = %lu, tx_carrier_errors = %lu, tx_fifo_errors = %lu\n",
J
Jesse Brandeburg 已提交
441 442 443
		 (unsigned long int)nstat->tx_aborted_errors,
		 (unsigned long int)nstat->tx_carrier_errors,
		 (unsigned long int)nstat->tx_fifo_errors);
J
Jesse Brandeburg 已提交
444 445
	dev_info(&pf->pdev->dev,
		 "    net_stats: tx_heartbeat_errors = %lu, tx_window_errors = %lu\n",
J
Jesse Brandeburg 已提交
446 447
		 (unsigned long int)nstat->tx_heartbeat_errors,
		 (unsigned long int)nstat->tx_window_errors);
J
Jesse Brandeburg 已提交
448 449
	dev_info(&pf->pdev->dev,
		 "    net_stats: rx_compressed = %lu, tx_compressed = %lu\n",
J
Jesse Brandeburg 已提交
450 451
		 (unsigned long int)nstat->rx_compressed,
		 (unsigned long int)nstat->tx_compressed);
J
Jesse Brandeburg 已提交
452 453
	dev_info(&pf->pdev->dev,
		 "    net_stats_offsets: rx_packets = %lu, rx_bytes = %lu, rx_errors = %lu, rx_dropped = %lu\n",
J
Jesse Brandeburg 已提交
454 455 456 457
		 (unsigned long int)vsi->net_stats_offsets.rx_packets,
		 (unsigned long int)vsi->net_stats_offsets.rx_bytes,
		 (unsigned long int)vsi->net_stats_offsets.rx_errors,
		 (unsigned long int)vsi->net_stats_offsets.rx_dropped);
J
Jesse Brandeburg 已提交
458 459
	dev_info(&pf->pdev->dev,
		 "    net_stats_offsets: tx_packets = %lu, tx_bytes = %lu, tx_errors = %lu, tx_dropped = %lu\n",
J
Jesse Brandeburg 已提交
460 461 462 463
		 (unsigned long int)vsi->net_stats_offsets.tx_packets,
		 (unsigned long int)vsi->net_stats_offsets.tx_bytes,
		 (unsigned long int)vsi->net_stats_offsets.tx_errors,
		 (unsigned long int)vsi->net_stats_offsets.tx_dropped);
J
Jesse Brandeburg 已提交
464 465
	dev_info(&pf->pdev->dev,
		 "    net_stats_offsets: multicast = %lu, collisions = %lu\n",
J
Jesse Brandeburg 已提交
466 467
		 (unsigned long int)vsi->net_stats_offsets.multicast,
		 (unsigned long int)vsi->net_stats_offsets.collisions);
J
Jesse Brandeburg 已提交
468 469
	dev_info(&pf->pdev->dev,
		 "    net_stats_offsets: rx_length_errors = %lu, rx_over_errors = %lu, rx_crc_errors = %lu\n",
J
Jesse Brandeburg 已提交
470 471 472
		 (unsigned long int)vsi->net_stats_offsets.rx_length_errors,
		 (unsigned long int)vsi->net_stats_offsets.rx_over_errors,
		 (unsigned long int)vsi->net_stats_offsets.rx_crc_errors);
J
Jesse Brandeburg 已提交
473 474
	dev_info(&pf->pdev->dev,
		 "    net_stats_offsets: rx_frame_errors = %lu, rx_fifo_errors = %lu, rx_missed_errors = %lu\n",
J
Jesse Brandeburg 已提交
475 476 477
		 (unsigned long int)vsi->net_stats_offsets.rx_frame_errors,
		 (unsigned long int)vsi->net_stats_offsets.rx_fifo_errors,
		 (unsigned long int)vsi->net_stats_offsets.rx_missed_errors);
J
Jesse Brandeburg 已提交
478 479
	dev_info(&pf->pdev->dev,
		 "    net_stats_offsets: tx_aborted_errors = %lu, tx_carrier_errors = %lu, tx_fifo_errors = %lu\n",
J
Jesse Brandeburg 已提交
480 481 482
		 (unsigned long int)vsi->net_stats_offsets.tx_aborted_errors,
		 (unsigned long int)vsi->net_stats_offsets.tx_carrier_errors,
		 (unsigned long int)vsi->net_stats_offsets.tx_fifo_errors);
J
Jesse Brandeburg 已提交
483 484
	dev_info(&pf->pdev->dev,
		 "    net_stats_offsets: tx_heartbeat_errors = %lu, tx_window_errors = %lu\n",
J
Jesse Brandeburg 已提交
485 486
		 (unsigned long int)vsi->net_stats_offsets.tx_heartbeat_errors,
		 (unsigned long int)vsi->net_stats_offsets.tx_window_errors);
J
Jesse Brandeburg 已提交
487 488
	dev_info(&pf->pdev->dev,
		 "    net_stats_offsets: rx_compressed = %lu, tx_compressed = %lu\n",
J
Jesse Brandeburg 已提交
489 490
		 (unsigned long int)vsi->net_stats_offsets.rx_compressed,
		 (unsigned long int)vsi->net_stats_offsets.tx_compressed);
J
Jesse Brandeburg 已提交
491 492 493 494
	dev_info(&pf->pdev->dev,
		 "    tx_restart = %d, tx_busy = %d, rx_buf_failed = %d, rx_page_failed = %d\n",
		 vsi->tx_restart, vsi->tx_busy,
		 vsi->rx_buf_failed, vsi->rx_page_failed);
495 496 497
	rcu_read_lock();
	for (i = 0; i < vsi->num_queue_pairs; i++) {
		struct i40e_ring *rx_ring = ACCESS_ONCE(vsi->rx_rings[i]);
J
Jesse Brandeburg 已提交
498

499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
		if (!rx_ring)
			continue;

		dev_info(&pf->pdev->dev,
			 "    rx_rings[%i]: desc = %p\n",
			 i, rx_ring->desc);
		dev_info(&pf->pdev->dev,
			 "    rx_rings[%i]: dev = %p, netdev = %p, rx_bi = %p\n",
			 i, rx_ring->dev,
			 rx_ring->netdev,
			 rx_ring->rx_bi);
		dev_info(&pf->pdev->dev,
			 "    rx_rings[%i]: state = %li, queue_index = %d, reg_idx = %d\n",
			 i, rx_ring->state,
			 rx_ring->queue_index,
			 rx_ring->reg_idx);
		dev_info(&pf->pdev->dev,
			 "    rx_rings[%i]: rx_hdr_len = %d, rx_buf_len = %d, dtype = %d\n",
			 i, rx_ring->rx_hdr_len,
			 rx_ring->rx_buf_len,
			 rx_ring->dtype);
		dev_info(&pf->pdev->dev,
			 "    rx_rings[%i]: hsplit = %d, next_to_use = %d, next_to_clean = %d, ring_active = %i\n",
			 i, rx_ring->hsplit,
			 rx_ring->next_to_use,
			 rx_ring->next_to_clean,
			 rx_ring->ring_active);
		dev_info(&pf->pdev->dev,
			 "    rx_rings[%i]: rx_stats: packets = %lld, bytes = %lld, non_eop_descs = %lld\n",
			 i, rx_ring->stats.packets,
			 rx_ring->stats.bytes,
			 rx_ring->rx_stats.non_eop_descs);
		dev_info(&pf->pdev->dev,
M
Mitch Williams 已提交
532
			 "    rx_rings[%i]: rx_stats: alloc_page_failed = %lld, alloc_buff_failed = %lld\n",
533
			 i,
M
Mitch Williams 已提交
534 535
			 rx_ring->rx_stats.alloc_page_failed,
			 rx_ring->rx_stats.alloc_buff_failed);
536 537 538
		dev_info(&pf->pdev->dev,
			 "    rx_rings[%i]: size = %i, dma = 0x%08lx\n",
			 i, rx_ring->size,
J
Jesse Brandeburg 已提交
539
			 (unsigned long int)rx_ring->dma);
540 541 542 543
		dev_info(&pf->pdev->dev,
			 "    rx_rings[%i]: vsi = %p, q_vector = %p\n",
			 i, rx_ring->vsi,
			 rx_ring->q_vector);
J
Jesse Brandeburg 已提交
544
	}
545 546
	for (i = 0; i < vsi->num_queue_pairs; i++) {
		struct i40e_ring *tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
J
Jesse Brandeburg 已提交
547

548 549
		if (!tx_ring)
			continue;
J
Jesse Brandeburg 已提交
550

551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585
		dev_info(&pf->pdev->dev,
			 "    tx_rings[%i]: desc = %p\n",
			 i, tx_ring->desc);
		dev_info(&pf->pdev->dev,
			 "    tx_rings[%i]: dev = %p, netdev = %p, tx_bi = %p\n",
			 i, tx_ring->dev,
			 tx_ring->netdev,
			 tx_ring->tx_bi);
		dev_info(&pf->pdev->dev,
			 "    tx_rings[%i]: state = %li, queue_index = %d, reg_idx = %d\n",
			 i, tx_ring->state,
			 tx_ring->queue_index,
			 tx_ring->reg_idx);
		dev_info(&pf->pdev->dev,
			 "    tx_rings[%i]: dtype = %d\n",
			 i, tx_ring->dtype);
		dev_info(&pf->pdev->dev,
			 "    tx_rings[%i]: hsplit = %d, next_to_use = %d, next_to_clean = %d, ring_active = %i\n",
			 i, tx_ring->hsplit,
			 tx_ring->next_to_use,
			 tx_ring->next_to_clean,
			 tx_ring->ring_active);
		dev_info(&pf->pdev->dev,
			 "    tx_rings[%i]: tx_stats: packets = %lld, bytes = %lld, restart_queue = %lld\n",
			 i, tx_ring->stats.packets,
			 tx_ring->stats.bytes,
			 tx_ring->tx_stats.restart_queue);
		dev_info(&pf->pdev->dev,
			 "    tx_rings[%i]: tx_stats: tx_busy = %lld, tx_done_old = %lld\n",
			 i,
			 tx_ring->tx_stats.tx_busy,
			 tx_ring->tx_stats.tx_done_old);
		dev_info(&pf->pdev->dev,
			 "    tx_rings[%i]: size = %i, dma = 0x%08lx\n",
			 i, tx_ring->size,
J
Jesse Brandeburg 已提交
586
			 (unsigned long int)tx_ring->dma);
587 588 589 590 591 592 593
		dev_info(&pf->pdev->dev,
			 "    tx_rings[%i]: vsi = %p, q_vector = %p\n",
			 i, tx_ring->vsi,
			 tx_ring->q_vector);
		dev_info(&pf->pdev->dev,
			 "    tx_rings[%i]: DCB tc = %d\n",
			 i, tx_ring->dcb_tc);
J
Jesse Brandeburg 已提交
594
	}
595
	rcu_read_unlock();
J
Jesse Brandeburg 已提交
596 597 598 599 600 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 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692
	dev_info(&pf->pdev->dev,
		 "    work_limit = %d, rx_itr_setting = %d (%s), tx_itr_setting = %d (%s)\n",
		 vsi->work_limit, vsi->rx_itr_setting,
		 ITR_IS_DYNAMIC(vsi->rx_itr_setting) ? "dynamic" : "fixed",
		 vsi->tx_itr_setting,
		 ITR_IS_DYNAMIC(vsi->tx_itr_setting) ? "dynamic" : "fixed");
	dev_info(&pf->pdev->dev,
		 "    max_frame = %d, rx_hdr_len = %d, rx_buf_len = %d dtype = %d\n",
		 vsi->max_frame, vsi->rx_hdr_len, vsi->rx_buf_len, vsi->dtype);
	dev_info(&pf->pdev->dev,
		 "    num_q_vectors = %i, base_vector = %i\n",
		 vsi->num_q_vectors, vsi->base_vector);
	dev_info(&pf->pdev->dev,
		 "    seid = %d, id = %d, uplink_seid = %d\n",
		 vsi->seid, vsi->id, vsi->uplink_seid);
	dev_info(&pf->pdev->dev,
		 "    base_queue = %d, num_queue_pairs = %d, num_desc = %d\n",
		 vsi->base_queue, vsi->num_queue_pairs, vsi->num_desc);
	dev_info(&pf->pdev->dev, "    type = %i\n", vsi->type);
	dev_info(&pf->pdev->dev,
		 "    info: valid_sections = 0x%04x, switch_id = 0x%04x\n",
		 vsi->info.valid_sections, vsi->info.switch_id);
	dev_info(&pf->pdev->dev,
		 "    info: sw_reserved[] = 0x%02x 0x%02x\n",
		 vsi->info.sw_reserved[0], vsi->info.sw_reserved[1]);
	dev_info(&pf->pdev->dev,
		 "    info: sec_flags = 0x%02x, sec_reserved = 0x%02x\n",
		 vsi->info.sec_flags, vsi->info.sec_reserved);
	dev_info(&pf->pdev->dev,
		 "    info: pvid = 0x%04x, fcoe_pvid = 0x%04x, port_vlan_flags = 0x%02x\n",
		 vsi->info.pvid, vsi->info.fcoe_pvid,
		 vsi->info.port_vlan_flags);
	dev_info(&pf->pdev->dev,
		 "    info: pvlan_reserved[] = 0x%02x 0x%02x 0x%02x\n",
		 vsi->info.pvlan_reserved[0], vsi->info.pvlan_reserved[1],
		 vsi->info.pvlan_reserved[2]);
	dev_info(&pf->pdev->dev,
		 "    info: ingress_table = 0x%08x, egress_table = 0x%08x\n",
		 vsi->info.ingress_table, vsi->info.egress_table);
	dev_info(&pf->pdev->dev,
		 "    info: cas_pv_stag = 0x%04x, cas_pv_flags= 0x%02x, cas_pv_reserved = 0x%02x\n",
		 vsi->info.cas_pv_tag, vsi->info.cas_pv_flags,
		 vsi->info.cas_pv_reserved);
	dev_info(&pf->pdev->dev,
		 "    info: queue_mapping[0..7 ] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
		 vsi->info.queue_mapping[0], vsi->info.queue_mapping[1],
		 vsi->info.queue_mapping[2], vsi->info.queue_mapping[3],
		 vsi->info.queue_mapping[4], vsi->info.queue_mapping[5],
		 vsi->info.queue_mapping[6], vsi->info.queue_mapping[7]);
	dev_info(&pf->pdev->dev,
		 "    info: queue_mapping[8..15] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
		 vsi->info.queue_mapping[8], vsi->info.queue_mapping[9],
		 vsi->info.queue_mapping[10], vsi->info.queue_mapping[11],
		 vsi->info.queue_mapping[12], vsi->info.queue_mapping[13],
		 vsi->info.queue_mapping[14], vsi->info.queue_mapping[15]);
	dev_info(&pf->pdev->dev,
		 "    info: tc_mapping[] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
		 vsi->info.tc_mapping[0], vsi->info.tc_mapping[1],
		 vsi->info.tc_mapping[2], vsi->info.tc_mapping[3],
		 vsi->info.tc_mapping[4], vsi->info.tc_mapping[5],
		 vsi->info.tc_mapping[6], vsi->info.tc_mapping[7]);
	dev_info(&pf->pdev->dev,
		 "    info: queueing_opt_flags = 0x%02x  queueing_opt_reserved[0..2] = 0x%02x 0x%02x 0x%02x\n",
		 vsi->info.queueing_opt_flags,
		 vsi->info.queueing_opt_reserved[0],
		 vsi->info.queueing_opt_reserved[1],
		 vsi->info.queueing_opt_reserved[2]);
	dev_info(&pf->pdev->dev,
		 "    info: up_enable_bits = 0x%02x\n",
		 vsi->info.up_enable_bits);
	dev_info(&pf->pdev->dev,
		 "    info: sched_reserved = 0x%02x, outer_up_table = 0x%04x\n",
		 vsi->info.sched_reserved, vsi->info.outer_up_table);
	dev_info(&pf->pdev->dev,
		 "    info: cmd_reserved[] = 0x%02x 0x%02x 0x%02x 0x0%02x 0x%02x 0x%02x 0x%02x 0x0%02x\n",
		 vsi->info.cmd_reserved[0], vsi->info.cmd_reserved[1],
		 vsi->info.cmd_reserved[2], vsi->info.cmd_reserved[3],
		 vsi->info.cmd_reserved[4], vsi->info.cmd_reserved[5],
		 vsi->info.cmd_reserved[6], vsi->info.cmd_reserved[7]);
	dev_info(&pf->pdev->dev,
		 "    info: qs_handle[] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
		 vsi->info.qs_handle[0], vsi->info.qs_handle[1],
		 vsi->info.qs_handle[2], vsi->info.qs_handle[3],
		 vsi->info.qs_handle[4], vsi->info.qs_handle[5],
		 vsi->info.qs_handle[6], vsi->info.qs_handle[7]);
	dev_info(&pf->pdev->dev,
		 "    info: stat_counter_idx = 0x%04x, sched_id = 0x%04x\n",
		 vsi->info.stat_counter_idx, vsi->info.sched_id);
	dev_info(&pf->pdev->dev,
		 "    info: resp_reserved[] = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
		 vsi->info.resp_reserved[0], vsi->info.resp_reserved[1],
		 vsi->info.resp_reserved[2], vsi->info.resp_reserved[3],
		 vsi->info.resp_reserved[4], vsi->info.resp_reserved[5],
		 vsi->info.resp_reserved[6], vsi->info.resp_reserved[7],
		 vsi->info.resp_reserved[8], vsi->info.resp_reserved[9],
		 vsi->info.resp_reserved[10], vsi->info.resp_reserved[11]);
	if (vsi->back)
693
		dev_info(&pf->pdev->dev, "    PF = %p\n", vsi->back);
J
Jesse Brandeburg 已提交
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714
	dev_info(&pf->pdev->dev, "    idx = %d\n", vsi->idx);
	dev_info(&pf->pdev->dev,
		 "    tc_config: numtc = %d, enabled_tc = 0x%x\n",
		 vsi->tc_config.numtc, vsi->tc_config.enabled_tc);
	for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
		dev_info(&pf->pdev->dev,
			 "    tc_config: tc = %d, qoffset = %d, qcount = %d, netdev_tc = %d\n",
			 i, vsi->tc_config.tc_info[i].qoffset,
			 vsi->tc_config.tc_info[i].qcount,
			 vsi->tc_config.tc_info[i].netdev_tc);
	}
	dev_info(&pf->pdev->dev,
		 "    bw: bw_limit = %d, bw_max_quanta = %d\n",
		 vsi->bw_limit, vsi->bw_max_quanta);
	for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
		dev_info(&pf->pdev->dev,
			 "    bw[%d]: ets_share_credits = %d, ets_limit_credits = %d, max_quanta = %d\n",
			 i, vsi->bw_ets_share_credits[i],
			 vsi->bw_ets_limit_credits[i],
			 vsi->bw_ets_max_quanta[i]);
	}
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733
#ifdef I40E_FCOE
	if (vsi->type == I40E_VSI_FCOE) {
		dev_info(&pf->pdev->dev,
			 "    fcoe_stats: rx_packets = %llu, rx_dwords = %llu, rx_dropped = %llu\n",
			 vsi->fcoe_stats.rx_fcoe_packets,
			 vsi->fcoe_stats.rx_fcoe_dwords,
			 vsi->fcoe_stats.rx_fcoe_dropped);
		dev_info(&pf->pdev->dev,
			 "    fcoe_stats: tx_packets = %llu, tx_dwords = %llu\n",
			 vsi->fcoe_stats.tx_fcoe_packets,
			 vsi->fcoe_stats.tx_fcoe_dwords);
		dev_info(&pf->pdev->dev,
			 "    fcoe_stats: bad_crc = %llu, last_error = %llu\n",
			 vsi->fcoe_stats.fcoe_bad_fccrc,
			 vsi->fcoe_stats.fcoe_last_error);
		dev_info(&pf->pdev->dev, "    fcoe_stats: ddp_count = %llu\n",
			 vsi->fcoe_stats.fcoe_ddp_count);
	}
#endif
J
Jesse Brandeburg 已提交
734 735 736 737 738 739 740 741 742 743
}

/**
 * i40e_dbg_dump_aq_desc - handles dump aq_desc write into command datum
 * @pf: the i40e_pf created in command write
 **/
static void i40e_dbg_dump_aq_desc(struct i40e_pf *pf)
{
	struct i40e_adminq_ring *ring;
	struct i40e_hw *hw = &pf->hw;
S
Shannon Nelson 已提交
744
	char hdr[32];
J
Jesse Brandeburg 已提交
745 746
	int i;

S
Shannon Nelson 已提交
747 748 749 750
	snprintf(hdr, sizeof(hdr), "%s %s:         ",
		 dev_driver_string(&pf->pdev->dev),
		 dev_name(&pf->pdev->dev));

J
Jesse Brandeburg 已提交
751 752 753 754 755
	/* first the send (command) ring, then the receive (event) ring */
	dev_info(&pf->pdev->dev, "AdminQ Tx Ring\n");
	ring = &(hw->aq.asq);
	for (i = 0; i < ring->count; i++) {
		struct i40e_aq_desc *d = I40E_ADMINQ_DESC(*ring, i);
J
Jesse Brandeburg 已提交
756

J
Jesse Brandeburg 已提交
757 758 759 760
		dev_info(&pf->pdev->dev,
			 "   at[%02d] flags=0x%04x op=0x%04x dlen=0x%04x ret=0x%04x cookie_h=0x%08x cookie_l=0x%08x\n",
			 i, d->flags, d->opcode, d->datalen, d->retval,
			 d->cookie_high, d->cookie_low);
S
Shannon Nelson 已提交
761 762
		print_hex_dump(KERN_INFO, hdr, DUMP_PREFIX_NONE,
			       16, 1, d->params.raw, 16, 0);
J
Jesse Brandeburg 已提交
763 764 765 766 767 768
	}

	dev_info(&pf->pdev->dev, "AdminQ Rx Ring\n");
	ring = &(hw->aq.arq);
	for (i = 0; i < ring->count; i++) {
		struct i40e_aq_desc *d = I40E_ADMINQ_DESC(*ring, i);
J
Jesse Brandeburg 已提交
769

J
Jesse Brandeburg 已提交
770 771 772 773
		dev_info(&pf->pdev->dev,
			 "   ar[%02d] flags=0x%04x op=0x%04x dlen=0x%04x ret=0x%04x cookie_h=0x%08x cookie_l=0x%08x\n",
			 i, d->flags, d->opcode, d->datalen, d->retval,
			 d->cookie_high, d->cookie_low);
S
Shannon Nelson 已提交
774 775
		print_hex_dump(KERN_INFO, hdr, DUMP_PREFIX_NONE,
			       16, 1, d->params.raw, 16, 0);
J
Jesse Brandeburg 已提交
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790
	}
}

/**
 * i40e_dbg_dump_desc - handles dump desc write into command datum
 * @cnt: number of arguments that the user supplied
 * @vsi_seid: vsi id entered by user
 * @ring_id: ring id entered by user
 * @desc_n: descriptor number entered by user
 * @pf: the i40e_pf created in command write
 * @is_rx_ring: true if rx, false if tx
 **/
static void i40e_dbg_dump_desc(int cnt, int vsi_seid, int ring_id, int desc_n,
			       struct i40e_pf *pf, bool is_rx_ring)
{
791 792
	struct i40e_tx_desc *txd;
	union i40e_rx_desc *rxd;
793
	struct i40e_ring *ring;
J
Jesse Brandeburg 已提交
794 795 796 797 798
	struct i40e_vsi *vsi;
	int i;

	vsi = i40e_dbg_find_vsi(pf, vsi_seid);
	if (!vsi) {
799
		dev_info(&pf->pdev->dev, "vsi %d not found\n", vsi_seid);
J
Jesse Brandeburg 已提交
800 801 802 803 804 805
		return;
	}
	if (ring_id >= vsi->num_queue_pairs || ring_id < 0) {
		dev_info(&pf->pdev->dev, "ring %d not found\n", ring_id);
		return;
	}
806
	if (!vsi->tx_rings || !vsi->tx_rings[0]->desc) {
807 808 809 810 811
		dev_info(&pf->pdev->dev,
			 "descriptor rings have not been allocated for vsi %d\n",
			 vsi_seid);
		return;
	}
812 813 814 815 816 817 818

	ring = kmemdup(is_rx_ring
		       ? vsi->rx_rings[ring_id] : vsi->tx_rings[ring_id],
		       sizeof(*ring), GFP_KERNEL);
	if (!ring)
		return;

J
Jesse Brandeburg 已提交
819 820 821
	if (cnt == 2) {
		dev_info(&pf->pdev->dev, "vsi = %02i %s ring = %02i\n",
			 vsi_seid, is_rx_ring ? "rx" : "tx", ring_id);
822
		for (i = 0; i < ring->count; i++) {
823
			if (!is_rx_ring) {
824
				txd = I40E_TX_DESC(ring, i);
J
Jesse Brandeburg 已提交
825
				dev_info(&pf->pdev->dev,
826 827 828 829 830
					 "   d[%03i] = 0x%016llx 0x%016llx\n",
					 i, txd->buffer_addr,
					 txd->cmd_type_offset_bsz);
			} else if (sizeof(union i40e_rx_desc) ==
				   sizeof(union i40e_16byte_rx_desc)) {
831
				rxd = I40E_RX_DESC(ring, i);
832 833 834 835 836
				dev_info(&pf->pdev->dev,
					 "   d[%03i] = 0x%016llx 0x%016llx\n",
					 i, rxd->read.pkt_addr,
					 rxd->read.hdr_addr);
			} else {
837
				rxd = I40E_RX_DESC(ring, i);
J
Jesse Brandeburg 已提交
838 839
				dev_info(&pf->pdev->dev,
					 "   d[%03i] = 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n",
840 841 842 843
					 i, rxd->read.pkt_addr,
					 rxd->read.hdr_addr,
					 rxd->read.rsvd1, rxd->read.rsvd2);
			}
J
Jesse Brandeburg 已提交
844 845
		}
	} else if (cnt == 3) {
846
		if (desc_n >= ring->count || desc_n < 0) {
J
Jesse Brandeburg 已提交
847 848
			dev_info(&pf->pdev->dev,
				 "descriptor %d not found\n", desc_n);
849
			goto out;
J
Jesse Brandeburg 已提交
850
		}
851
		if (!is_rx_ring) {
852
			txd = I40E_TX_DESC(ring, desc_n);
J
Jesse Brandeburg 已提交
853
			dev_info(&pf->pdev->dev,
854 855 856 857 858
				 "vsi = %02i tx ring = %02i d[%03i] = 0x%016llx 0x%016llx\n",
				 vsi_seid, ring_id, desc_n,
				 txd->buffer_addr, txd->cmd_type_offset_bsz);
		} else if (sizeof(union i40e_rx_desc) ==
			   sizeof(union i40e_16byte_rx_desc)) {
859
			rxd = I40E_RX_DESC(ring, desc_n);
860 861 862 863 864
			dev_info(&pf->pdev->dev,
				 "vsi = %02i rx ring = %02i d[%03i] = 0x%016llx 0x%016llx\n",
				 vsi_seid, ring_id, desc_n,
				 rxd->read.pkt_addr, rxd->read.hdr_addr);
		} else {
865
			rxd = I40E_RX_DESC(ring, desc_n);
J
Jesse Brandeburg 已提交
866 867
			dev_info(&pf->pdev->dev,
				 "vsi = %02i rx ring = %02i d[%03i] = 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n",
868 869 870 871
				 vsi_seid, ring_id, desc_n,
				 rxd->read.pkt_addr, rxd->read.hdr_addr,
				 rxd->read.rsvd1, rxd->read.rsvd2);
		}
J
Jesse Brandeburg 已提交
872
	} else {
873
		dev_info(&pf->pdev->dev, "dump desc rx/tx <vsi_seid> <ring_id> [<desc_n>]\n");
J
Jesse Brandeburg 已提交
874
	}
875 876

out:
877
	kfree(ring);
J
Jesse Brandeburg 已提交
878 879 880 881 882 883 884 885 886 887
}

/**
 * i40e_dbg_dump_vsi_no_seid - handles dump vsi write into command datum
 * @pf: the i40e_pf created in command write
 **/
static void i40e_dbg_dump_vsi_no_seid(struct i40e_pf *pf)
{
	int i;

M
Mitch Williams 已提交
888
	for (i = 0; i < pf->num_alloc_vsi; i++)
J
Jesse Brandeburg 已提交
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906
		if (pf->vsi[i])
			dev_info(&pf->pdev->dev, "dump vsi[%d]: %d\n",
				 i, pf->vsi[i]->seid);
}

/**
 * i40e_dbg_dump_stats - handles dump stats write into command datum
 * @pf: the i40e_pf created in command write
 * @estats: the eth stats structure to be dumped
 **/
static void i40e_dbg_dump_eth_stats(struct i40e_pf *pf,
				    struct i40e_eth_stats *estats)
{
	dev_info(&pf->pdev->dev, "  ethstats:\n");
	dev_info(&pf->pdev->dev,
		 "    rx_bytes = \t%lld \trx_unicast = \t\t%lld \trx_multicast = \t%lld\n",
		estats->rx_bytes, estats->rx_unicast, estats->rx_multicast);
	dev_info(&pf->pdev->dev,
907 908
		 "    rx_broadcast = \t%lld \trx_discards = \t\t%lld\n",
		 estats->rx_broadcast, estats->rx_discards);
J
Jesse Brandeburg 已提交
909
	dev_info(&pf->pdev->dev,
910 911
		 "    rx_unknown_protocol = \t%lld \ttx_bytes = \t%lld\n",
		 estats->rx_unknown_protocol, estats->tx_bytes);
J
Jesse Brandeburg 已提交
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936
	dev_info(&pf->pdev->dev,
		 "    tx_unicast = \t%lld \ttx_multicast = \t\t%lld \ttx_broadcast = \t%lld\n",
		 estats->tx_unicast, estats->tx_multicast, estats->tx_broadcast);
	dev_info(&pf->pdev->dev,
		 "    tx_discards = \t%lld \ttx_errors = \t\t%lld\n",
		 estats->tx_discards, estats->tx_errors);
}

/**
 * i40e_dbg_dump_veb_seid - handles dump stats of a single given veb
 * @pf: the i40e_pf created in command write
 * @seid: the seid the user put in
 **/
static void i40e_dbg_dump_veb_seid(struct i40e_pf *pf, int seid)
{
	struct i40e_veb *veb;

	if ((seid < I40E_BASE_VEB_SEID) ||
	    (seid >= (I40E_MAX_VEB + I40E_BASE_VEB_SEID))) {
		dev_info(&pf->pdev->dev, "%d: bad seid\n", seid);
		return;
	}

	veb = i40e_dbg_find_veb(pf, seid);
	if (!veb) {
S
Shannon Nelson 已提交
937
		dev_info(&pf->pdev->dev, "can't find veb %d\n", seid);
J
Jesse Brandeburg 已提交
938 939 940
		return;
	}
	dev_info(&pf->pdev->dev,
941
		 "veb idx=%d,%d stats_ic=%d  seid=%d uplink=%d mode=%s\n",
J
Jesse Brandeburg 已提交
942
		 veb->idx, veb->veb_idx, veb->stats_idx, veb->seid,
943 944
		 veb->uplink_seid,
		 veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
J
Jesse Brandeburg 已提交
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976
	i40e_dbg_dump_eth_stats(pf, &veb->stats);
}

/**
 * i40e_dbg_dump_veb_all - dumps all known veb's stats
 * @pf: the i40e_pf created in command write
 **/
static void i40e_dbg_dump_veb_all(struct i40e_pf *pf)
{
	struct i40e_veb *veb;
	int i;

	for (i = 0; i < I40E_MAX_VEB; i++) {
		veb = pf->veb[i];
		if (veb)
			i40e_dbg_dump_veb_seid(pf, veb->seid);
	}
}

#define I40E_MAX_DEBUG_OUT_BUFFER (4096*4)
/**
 * i40e_dbg_command_write - write into command datum
 * @filp: the opened file
 * @buffer: where to find the user's data
 * @count: the length of the user's data
 * @ppos: file position offset
 **/
static ssize_t i40e_dbg_command_write(struct file *filp,
				      const char __user *buffer,
				      size_t count, loff_t *ppos)
{
	struct i40e_pf *pf = filp->private_data;
977
	char *cmd_buf, *cmd_buf_tmp;
J
Jesse Brandeburg 已提交
978 979 980 981 982 983 984 985 986 987 988 989 990 991
	int bytes_not_copied;
	struct i40e_vsi *vsi;
	int vsi_seid;
	int veb_seid;
	int cnt;

	/* don't allow partial writes */
	if (*ppos != 0)
		return 0;

	cmd_buf = kzalloc(count + 1, GFP_KERNEL);
	if (!cmd_buf)
		return count;
	bytes_not_copied = copy_from_user(cmd_buf, buffer, count);
R
Rasmus Villemoes 已提交
992
	if (bytes_not_copied) {
993
		kfree(cmd_buf);
R
Rasmus Villemoes 已提交
994
		return -EFAULT;
995
	}
J
Jesse Brandeburg 已提交
996 997
	cmd_buf[count] = '\0';

998 999 1000 1001 1002 1003
	cmd_buf_tmp = strchr(cmd_buf, '\n');
	if (cmd_buf_tmp) {
		*cmd_buf_tmp = '\0';
		count = cmd_buf_tmp - cmd_buf + 1;
	}

J
Jesse Brandeburg 已提交
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
	if (strncmp(cmd_buf, "add vsi", 7) == 0) {
		vsi_seid = -1;
		cnt = sscanf(&cmd_buf[7], "%i", &vsi_seid);
		if (cnt == 0) {
			/* default to PF VSI */
			vsi_seid = pf->vsi[pf->lan_vsi]->seid;
		} else if (vsi_seid < 0) {
			dev_info(&pf->pdev->dev, "add VSI %d: bad vsi seid\n",
				 vsi_seid);
			goto command_write_done;
		}

1016 1017 1018 1019 1020 1021 1022 1023 1024
		/* By default we are in VEPA mode, if this is the first VF/VMDq
		 * VSI to be added switch to VEB mode.
		 */
		if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
			pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
			i40e_do_reset_safe(pf,
					   BIT_ULL(__I40E_PF_RESET_REQUESTED));
		}

J
Jesse Brandeburg 已提交
1025 1026 1027 1028 1029 1030 1031 1032
		vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, vsi_seid, 0);
		if (vsi)
			dev_info(&pf->pdev->dev, "added VSI %d to relay %d\n",
				 vsi->seid, vsi->uplink_seid);
		else
			dev_info(&pf->pdev->dev, "'%s' failed\n", cmd_buf);

	} else if (strncmp(cmd_buf, "del vsi", 7) == 0) {
J
Jesse Brandeburg 已提交
1033 1034 1035 1036 1037 1038 1039
		cnt = sscanf(&cmd_buf[7], "%i", &vsi_seid);
		if (cnt != 1) {
			dev_info(&pf->pdev->dev,
				 "del vsi: bad command string, cnt=%d\n",
				 cnt);
			goto command_write_done;
		}
J
Jesse Brandeburg 已提交
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
		vsi = i40e_dbg_find_vsi(pf, vsi_seid);
		if (!vsi) {
			dev_info(&pf->pdev->dev, "del VSI %d: seid not found\n",
				 vsi_seid);
			goto command_write_done;
		}

		dev_info(&pf->pdev->dev, "deleting VSI %d\n", vsi_seid);
		i40e_vsi_release(vsi);

	} else if (strncmp(cmd_buf, "add relay", 9) == 0) {
		struct i40e_veb *veb;
		int uplink_seid, i;

		cnt = sscanf(&cmd_buf[9], "%i %i", &uplink_seid, &vsi_seid);
		if (cnt != 2) {
			dev_info(&pf->pdev->dev,
				 "add relay: bad command string, cnt=%d\n",
				 cnt);
			goto command_write_done;
		} else if (uplink_seid < 0) {
			dev_info(&pf->pdev->dev,
				 "add relay %d: bad uplink seid\n",
				 uplink_seid);
			goto command_write_done;
		}

		vsi = i40e_dbg_find_vsi(pf, vsi_seid);
		if (!vsi) {
			dev_info(&pf->pdev->dev,
S
Shannon Nelson 已提交
1070
				 "add relay: VSI %d not found\n", vsi_seid);
J
Jesse Brandeburg 已提交
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120
			goto command_write_done;
		}

		for (i = 0; i < I40E_MAX_VEB; i++)
			if (pf->veb[i] && pf->veb[i]->seid == uplink_seid)
				break;
		if (i >= I40E_MAX_VEB && uplink_seid != 0 &&
		    uplink_seid != pf->mac_seid) {
			dev_info(&pf->pdev->dev,
				 "add relay: relay uplink %d not found\n",
				 uplink_seid);
			goto command_write_done;
		}

		veb = i40e_veb_setup(pf, 0, uplink_seid, vsi_seid,
				     vsi->tc_config.enabled_tc);
		if (veb)
			dev_info(&pf->pdev->dev, "added relay %d\n", veb->seid);
		else
			dev_info(&pf->pdev->dev, "add relay failed\n");

	} else if (strncmp(cmd_buf, "del relay", 9) == 0) {
		int i;
		cnt = sscanf(&cmd_buf[9], "%i", &veb_seid);
		if (cnt != 1) {
			dev_info(&pf->pdev->dev,
				 "del relay: bad command string, cnt=%d\n",
				 cnt);
			goto command_write_done;
		} else if (veb_seid < 0) {
			dev_info(&pf->pdev->dev,
				 "del relay %d: bad relay seid\n", veb_seid);
			goto command_write_done;
		}

		/* find the veb */
		for (i = 0; i < I40E_MAX_VEB; i++)
			if (pf->veb[i] && pf->veb[i]->seid == veb_seid)
				break;
		if (i >= I40E_MAX_VEB) {
			dev_info(&pf->pdev->dev,
				 "del relay: relay %d not found\n", veb_seid);
			goto command_write_done;
		}

		dev_info(&pf->pdev->dev, "deleting relay %d\n", veb_seid);
		i40e_veb_release(pf->veb[i]);

	} else if (strncmp(cmd_buf, "add macaddr", 11) == 0) {
		struct i40e_mac_filter *f;
1121 1122
		int vlan = 0;
		u8 ma[6];
J
Jesse Brandeburg 已提交
1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145
		int ret;

		cnt = sscanf(&cmd_buf[11],
			     "%i %hhx:%hhx:%hhx:%hhx:%hhx:%hhx %i",
			     &vsi_seid,
			     &ma[0], &ma[1], &ma[2], &ma[3], &ma[4], &ma[5],
			     &vlan);
		if (cnt == 7) {
			vlan = 0;
		} else if (cnt != 8) {
			dev_info(&pf->pdev->dev,
				 "add macaddr: bad command string, cnt=%d\n",
				 cnt);
			goto command_write_done;
		}

		vsi = i40e_dbg_find_vsi(pf, vsi_seid);
		if (!vsi) {
			dev_info(&pf->pdev->dev,
				 "add macaddr: VSI %d not found\n", vsi_seid);
			goto command_write_done;
		}

1146
		spin_lock_bh(&vsi->mac_filter_list_lock);
J
Jesse Brandeburg 已提交
1147
		f = i40e_add_filter(vsi, ma, vlan, false, false);
1148
		spin_unlock_bh(&vsi->mac_filter_list_lock);
J
Jesse Brandeburg 已提交
1149
		ret = i40e_sync_vsi_filters(vsi);
J
Jesse Brandeburg 已提交
1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
		if (f && !ret)
			dev_info(&pf->pdev->dev,
				 "add macaddr: %pM vlan=%d added to VSI %d\n",
				 ma, vlan, vsi_seid);
		else
			dev_info(&pf->pdev->dev,
				 "add macaddr: %pM vlan=%d to VSI %d failed, f=%p ret=%d\n",
				 ma, vlan, vsi_seid, f, ret);

	} else if (strncmp(cmd_buf, "del macaddr", 11) == 0) {
		int vlan = 0;
1161
		u8 ma[6];
J
Jesse Brandeburg 已提交
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184
		int ret;

		cnt = sscanf(&cmd_buf[11],
			     "%i %hhx:%hhx:%hhx:%hhx:%hhx:%hhx %i",
			     &vsi_seid,
			     &ma[0], &ma[1], &ma[2], &ma[3], &ma[4], &ma[5],
			     &vlan);
		if (cnt == 7) {
			vlan = 0;
		} else if (cnt != 8) {
			dev_info(&pf->pdev->dev,
				 "del macaddr: bad command string, cnt=%d\n",
				 cnt);
			goto command_write_done;
		}

		vsi = i40e_dbg_find_vsi(pf, vsi_seid);
		if (!vsi) {
			dev_info(&pf->pdev->dev,
				 "del macaddr: VSI %d not found\n", vsi_seid);
			goto command_write_done;
		}

1185
		spin_lock_bh(&vsi->mac_filter_list_lock);
J
Jesse Brandeburg 已提交
1186
		i40e_del_filter(vsi, ma, vlan, false, false);
1187
		spin_unlock_bh(&vsi->mac_filter_list_lock);
J
Jesse Brandeburg 已提交
1188
		ret = i40e_sync_vsi_filters(vsi);
J
Jesse Brandeburg 已提交
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
		if (!ret)
			dev_info(&pf->pdev->dev,
				 "del macaddr: %pM vlan=%d removed from VSI %d\n",
				 ma, vlan, vsi_seid);
		else
			dev_info(&pf->pdev->dev,
				 "del macaddr: %pM vlan=%d from VSI %d failed, ret=%d\n",
				 ma, vlan, vsi_seid, ret);

	} else if (strncmp(cmd_buf, "add pvid", 8) == 0) {
		i40e_status ret;
1200
		u16 vid;
1201
		unsigned int v;
J
Jesse Brandeburg 已提交
1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216

		cnt = sscanf(&cmd_buf[8], "%i %u", &vsi_seid, &v);
		if (cnt != 2) {
			dev_info(&pf->pdev->dev,
				 "add pvid: bad command string, cnt=%d\n", cnt);
			goto command_write_done;
		}

		vsi = i40e_dbg_find_vsi(pf, vsi_seid);
		if (!vsi) {
			dev_info(&pf->pdev->dev, "add pvid: VSI %d not found\n",
				 vsi_seid);
			goto command_write_done;
		}

1217
		vid = v;
J
Jesse Brandeburg 已提交
1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294
		ret = i40e_vsi_add_pvid(vsi, vid);
		if (!ret)
			dev_info(&pf->pdev->dev,
				 "add pvid: %d added to VSI %d\n",
				 vid, vsi_seid);
		else
			dev_info(&pf->pdev->dev,
				 "add pvid: %d to VSI %d failed, ret=%d\n",
				 vid, vsi_seid, ret);

	} else if (strncmp(cmd_buf, "del pvid", 8) == 0) {

		cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid);
		if (cnt != 1) {
			dev_info(&pf->pdev->dev,
				 "del pvid: bad command string, cnt=%d\n",
				 cnt);
			goto command_write_done;
		}

		vsi = i40e_dbg_find_vsi(pf, vsi_seid);
		if (!vsi) {
			dev_info(&pf->pdev->dev,
				 "del pvid: VSI %d not found\n", vsi_seid);
			goto command_write_done;
		}

		i40e_vsi_remove_pvid(vsi);
		dev_info(&pf->pdev->dev,
			 "del pvid: removed from VSI %d\n", vsi_seid);

	} else if (strncmp(cmd_buf, "dump", 4) == 0) {
		if (strncmp(&cmd_buf[5], "switch", 6) == 0) {
			i40e_fetch_switch_configuration(pf, true);
		} else if (strncmp(&cmd_buf[5], "vsi", 3) == 0) {
			cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid);
			if (cnt > 0)
				i40e_dbg_dump_vsi_seid(pf, vsi_seid);
			else
				i40e_dbg_dump_vsi_no_seid(pf);
		} else if (strncmp(&cmd_buf[5], "veb", 3) == 0) {
			cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid);
			if (cnt > 0)
				i40e_dbg_dump_veb_seid(pf, vsi_seid);
			else
				i40e_dbg_dump_veb_all(pf);
		} else if (strncmp(&cmd_buf[5], "desc", 4) == 0) {
			int ring_id, desc_n;
			if (strncmp(&cmd_buf[10], "rx", 2) == 0) {
				cnt = sscanf(&cmd_buf[12], "%i %i %i",
					     &vsi_seid, &ring_id, &desc_n);
				i40e_dbg_dump_desc(cnt, vsi_seid, ring_id,
						   desc_n, pf, true);
			} else if (strncmp(&cmd_buf[10], "tx", 2)
					== 0) {
				cnt = sscanf(&cmd_buf[12], "%i %i %i",
					     &vsi_seid, &ring_id, &desc_n);
				i40e_dbg_dump_desc(cnt, vsi_seid, ring_id,
						   desc_n, pf, false);
			} else if (strncmp(&cmd_buf[10], "aq", 2) == 0) {
				i40e_dbg_dump_aq_desc(pf);
			} else {
				dev_info(&pf->pdev->dev,
					 "dump desc tx <vsi_seid> <ring_id> [<desc_n>]\n");
				dev_info(&pf->pdev->dev,
					 "dump desc rx <vsi_seid> <ring_id> [<desc_n>]\n");
				dev_info(&pf->pdev->dev, "dump desc aq\n");
			}
		} else if (strncmp(&cmd_buf[5], "reset stats", 11) == 0) {
			dev_info(&pf->pdev->dev,
				 "core reset count: %d\n", pf->corer_count);
			dev_info(&pf->pdev->dev,
				 "global reset count: %d\n", pf->globr_count);
			dev_info(&pf->pdev->dev,
				 "emp reset count: %d\n", pf->empr_count);
			dev_info(&pf->pdev->dev,
				 "pf reset count: %d\n", pf->pfr_count);
1295 1296 1297
			dev_info(&pf->pdev->dev,
				 "pf tx sluggish count: %d\n",
				 pf->tx_sluggish_count);
J
Jesse Brandeburg 已提交
1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339
		} else if (strncmp(&cmd_buf[5], "port", 4) == 0) {
			struct i40e_aqc_query_port_ets_config_resp *bw_data;
			struct i40e_dcbx_config *cfg =
						&pf->hw.local_dcbx_config;
			struct i40e_dcbx_config *r_cfg =
						&pf->hw.remote_dcbx_config;
			int i, ret;

			bw_data = kzalloc(sizeof(
				    struct i40e_aqc_query_port_ets_config_resp),
					  GFP_KERNEL);
			if (!bw_data) {
				ret = -ENOMEM;
				goto command_write_done;
			}

			ret = i40e_aq_query_port_ets_config(&pf->hw,
							    pf->mac_seid,
							    bw_data, NULL);
			if (ret) {
				dev_info(&pf->pdev->dev,
					 "Query Port ETS Config AQ command failed =0x%x\n",
					 pf->hw.aq.asq_last_status);
				kfree(bw_data);
				bw_data = NULL;
				goto command_write_done;
			}
			dev_info(&pf->pdev->dev,
				 "port bw: tc_valid=0x%x tc_strict_prio=0x%x, tc_bw_max=0x%04x,0x%04x\n",
				 bw_data->tc_valid_bits,
				 bw_data->tc_strict_priority_bits,
				 le16_to_cpu(bw_data->tc_bw_max[0]),
				 le16_to_cpu(bw_data->tc_bw_max[1]));
			for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
				dev_info(&pf->pdev->dev, "port bw: tc_bw_share=%d tc_bw_limit=%d\n",
					 bw_data->tc_bw_share_credits[i],
					 le16_to_cpu(bw_data->tc_bw_limits[i]));
			}

			kfree(bw_data);
			bw_data = NULL;

1340 1341
			dev_info(&pf->pdev->dev,
				 "port dcbx_mode=%d\n", cfg->dcbx_mode);
J
Jesse Brandeburg 已提交
1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401
			dev_info(&pf->pdev->dev,
				 "port ets_cfg: willing=%d cbs=%d, maxtcs=%d\n",
				 cfg->etscfg.willing, cfg->etscfg.cbs,
				 cfg->etscfg.maxtcs);
			for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
				dev_info(&pf->pdev->dev, "port ets_cfg: %d prio_tc=%d tcbw=%d tctsa=%d\n",
					 i, cfg->etscfg.prioritytable[i],
					 cfg->etscfg.tcbwtable[i],
					 cfg->etscfg.tsatable[i]);
			}
			for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
				dev_info(&pf->pdev->dev, "port ets_rec: %d prio_tc=%d tcbw=%d tctsa=%d\n",
					 i, cfg->etsrec.prioritytable[i],
					 cfg->etsrec.tcbwtable[i],
					 cfg->etsrec.tsatable[i]);
			}
			dev_info(&pf->pdev->dev,
				 "port pfc_cfg: willing=%d mbc=%d, pfccap=%d pfcenable=0x%x\n",
				 cfg->pfc.willing, cfg->pfc.mbc,
				 cfg->pfc.pfccap, cfg->pfc.pfcenable);
			dev_info(&pf->pdev->dev,
				 "port app_table: num_apps=%d\n", cfg->numapps);
			for (i = 0; i < cfg->numapps; i++) {
				dev_info(&pf->pdev->dev, "port app_table: %d prio=%d selector=%d protocol=0x%x\n",
					 i, cfg->app[i].priority,
					 cfg->app[i].selector,
					 cfg->app[i].protocolid);
			}
			/* Peer TLV DCBX data */
			dev_info(&pf->pdev->dev,
				 "remote port ets_cfg: willing=%d cbs=%d, maxtcs=%d\n",
				 r_cfg->etscfg.willing,
				 r_cfg->etscfg.cbs, r_cfg->etscfg.maxtcs);
			for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
				dev_info(&pf->pdev->dev, "remote port ets_cfg: %d prio_tc=%d tcbw=%d tctsa=%d\n",
					 i, r_cfg->etscfg.prioritytable[i],
					 r_cfg->etscfg.tcbwtable[i],
					 r_cfg->etscfg.tsatable[i]);
			}
			for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
				dev_info(&pf->pdev->dev, "remote port ets_rec: %d prio_tc=%d tcbw=%d tctsa=%d\n",
					 i, r_cfg->etsrec.prioritytable[i],
					 r_cfg->etsrec.tcbwtable[i],
					 r_cfg->etsrec.tsatable[i]);
			}
			dev_info(&pf->pdev->dev,
				 "remote port pfc_cfg: willing=%d mbc=%d, pfccap=%d pfcenable=0x%x\n",
				 r_cfg->pfc.willing,
				 r_cfg->pfc.mbc,
				 r_cfg->pfc.pfccap,
				 r_cfg->pfc.pfcenable);
			dev_info(&pf->pdev->dev,
				 "remote port app_table: num_apps=%d\n",
				 r_cfg->numapps);
			for (i = 0; i < r_cfg->numapps; i++) {
				dev_info(&pf->pdev->dev, "remote port app_table: %d prio=%d selector=%d protocol=0x%x\n",
					 i, r_cfg->app[i].priority,
					 r_cfg->app[i].selector,
					 r_cfg->app[i].protocolid);
			}
1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445
		} else if (strncmp(&cmd_buf[5], "debug fwdata", 12) == 0) {
			int cluster_id, table_id;
			int index, ret;
			u16 buff_len = 4096;
			u32 next_index;
			u8 next_table;
			u8 *buff;
			u16 rlen;

			cnt = sscanf(&cmd_buf[18], "%i %i %i",
				     &cluster_id, &table_id, &index);
			if (cnt != 3) {
				dev_info(&pf->pdev->dev,
					 "dump debug fwdata <cluster_id> <table_id> <index>\n");
				goto command_write_done;
			}

			dev_info(&pf->pdev->dev,
				 "AQ debug dump fwdata params %x %x %x %x\n",
				 cluster_id, table_id, index, buff_len);
			buff = kzalloc(buff_len, GFP_KERNEL);
			if (!buff)
				goto command_write_done;

			ret = i40e_aq_debug_dump(&pf->hw, cluster_id, table_id,
						 index, buff_len, buff, &rlen,
						 &next_table, &next_index,
						 NULL);
			if (ret) {
				dev_info(&pf->pdev->dev,
					 "debug dump fwdata AQ Failed %d 0x%x\n",
					 ret, pf->hw.aq.asq_last_status);
				kfree(buff);
				buff = NULL;
				goto command_write_done;
			}
			dev_info(&pf->pdev->dev,
				 "AQ debug dump fwdata rlen=0x%x next_table=0x%x next_index=0x%x\n",
				 rlen, next_table, next_index);
			print_hex_dump(KERN_INFO, "AQ buffer WB: ",
				       DUMP_PREFIX_OFFSET, 16, 1,
				       buff, rlen, true);
			kfree(buff);
			buff = NULL;
J
Jesse Brandeburg 已提交
1446 1447 1448
		} else {
			dev_info(&pf->pdev->dev,
				 "dump desc tx <vsi_seid> <ring_id> [<desc_n>], dump desc rx <vsi_seid> <ring_id> [<desc_n>],\n");
S
Shannon Nelson 已提交
1449 1450
			dev_info(&pf->pdev->dev, "dump switch\n");
			dev_info(&pf->pdev->dev, "dump vsi [seid]\n");
J
Jesse Brandeburg 已提交
1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474
			dev_info(&pf->pdev->dev, "dump reset stats\n");
			dev_info(&pf->pdev->dev, "dump port\n");
			dev_info(&pf->pdev->dev,
				 "dump debug fwdata <cluster_id> <table_id> <index>\n");
		}

	} else if (strncmp(cmd_buf, "msg_enable", 10) == 0) {
		u32 level;
		cnt = sscanf(&cmd_buf[10], "%i", &level);
		if (cnt) {
			if (I40E_DEBUG_USER & level) {
				pf->hw.debug_mask = level;
				dev_info(&pf->pdev->dev,
					 "set hw.debug_mask = 0x%08x\n",
					 pf->hw.debug_mask);
			}
			pf->msg_enable = level;
			dev_info(&pf->pdev->dev, "set msg_enable = 0x%08x\n",
				 pf->msg_enable);
		} else {
			dev_info(&pf->pdev->dev, "msg_enable = 0x%08x\n",
				 pf->msg_enable);
		}
	} else if (strncmp(cmd_buf, "pfr", 3) == 0) {
J
Jesse Brandeburg 已提交
1475
		dev_info(&pf->pdev->dev, "debugfs: forcing PFR\n");
1476
		i40e_do_reset_safe(pf, BIT(__I40E_PF_RESET_REQUESTED));
J
Jesse Brandeburg 已提交
1477 1478

	} else if (strncmp(cmd_buf, "corer", 5) == 0) {
J
Jesse Brandeburg 已提交
1479
		dev_info(&pf->pdev->dev, "debugfs: forcing CoreR\n");
1480
		i40e_do_reset_safe(pf, BIT(__I40E_CORE_RESET_REQUESTED));
J
Jesse Brandeburg 已提交
1481 1482

	} else if (strncmp(cmd_buf, "globr", 5) == 0) {
J
Jesse Brandeburg 已提交
1483
		dev_info(&pf->pdev->dev, "debugfs: forcing GlobR\n");
1484
		i40e_do_reset_safe(pf, BIT(__I40E_GLOBAL_RESET_REQUESTED));
J
Jesse Brandeburg 已提交
1485

1486
	} else if (strncmp(cmd_buf, "empr", 4) == 0) {
J
Jesse Brandeburg 已提交
1487
		dev_info(&pf->pdev->dev, "debugfs: forcing EMPR\n");
1488
		i40e_do_reset_safe(pf, BIT(__I40E_EMP_RESET_REQUESTED));
1489

J
Jesse Brandeburg 已提交
1490 1491 1492
	} else if (strncmp(cmd_buf, "read", 4) == 0) {
		u32 address;
		u32 value;
J
Jesse Brandeburg 已提交
1493

S
Shannon Nelson 已提交
1494
		cnt = sscanf(&cmd_buf[4], "%i", &address);
J
Jesse Brandeburg 已提交
1495 1496 1497 1498 1499 1500
		if (cnt != 1) {
			dev_info(&pf->pdev->dev, "read <reg>\n");
			goto command_write_done;
		}

		/* check the range on address */
S
Shannon Nelson 已提交
1501 1502
		if (address > (pf->ioremap_len - sizeof(u32))) {
			dev_info(&pf->pdev->dev, "read reg address 0x%08x too large, max=0x%08lx\n",
J
Jesse Brandeburg 已提交
1503
				 address, (unsigned long int)(pf->ioremap_len - sizeof(u32)));
J
Jesse Brandeburg 已提交
1504 1505 1506 1507 1508 1509 1510 1511 1512
			goto command_write_done;
		}

		value = rd32(&pf->hw, address);
		dev_info(&pf->pdev->dev, "read: 0x%08x = 0x%08x\n",
			 address, value);

	} else if (strncmp(cmd_buf, "write", 5) == 0) {
		u32 address, value;
J
Jesse Brandeburg 已提交
1513

S
Shannon Nelson 已提交
1514
		cnt = sscanf(&cmd_buf[5], "%i %i", &address, &value);
J
Jesse Brandeburg 已提交
1515 1516 1517 1518 1519 1520
		if (cnt != 2) {
			dev_info(&pf->pdev->dev, "write <reg> <value>\n");
			goto command_write_done;
		}

		/* check the range on address */
S
Shannon Nelson 已提交
1521 1522
		if (address > (pf->ioremap_len - sizeof(u32))) {
			dev_info(&pf->pdev->dev, "write reg address 0x%08x too large, max=0x%08lx\n",
J
Jesse Brandeburg 已提交
1523
				 address, (unsigned long int)(pf->ioremap_len - sizeof(u32)));
J
Jesse Brandeburg 已提交
1524 1525 1526 1527 1528 1529 1530 1531
			goto command_write_done;
		}
		wr32(&pf->hw, address, value);
		value = rd32(&pf->hw, address);
		dev_info(&pf->pdev->dev, "write: 0x%08x = 0x%08x\n",
			 address, value);
	} else if (strncmp(cmd_buf, "clear_stats", 11) == 0) {
		if (strncmp(&cmd_buf[12], "vsi", 3) == 0) {
S
Shannon Nelson 已提交
1532
			cnt = sscanf(&cmd_buf[15], "%i", &vsi_seid);
J
Jesse Brandeburg 已提交
1533 1534
			if (cnt == 0) {
				int i;
J
Jesse Brandeburg 已提交
1535

M
Mitch Williams 已提交
1536
				for (i = 0; i < pf->num_alloc_vsi; i++)
J
Jesse Brandeburg 已提交
1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553
					i40e_vsi_reset_stats(pf->vsi[i]);
				dev_info(&pf->pdev->dev, "vsi clear stats called for all vsi's\n");
			} else if (cnt == 1) {
				vsi = i40e_dbg_find_vsi(pf, vsi_seid);
				if (!vsi) {
					dev_info(&pf->pdev->dev,
						 "clear_stats vsi: bad vsi %d\n",
						 vsi_seid);
					goto command_write_done;
				}
				i40e_vsi_reset_stats(vsi);
				dev_info(&pf->pdev->dev,
					 "vsi clear stats called for vsi %d\n",
					 vsi_seid);
			} else {
				dev_info(&pf->pdev->dev, "clear_stats vsi [seid]\n");
			}
1554 1555 1556 1557 1558 1559 1560
		} else if (strncmp(&cmd_buf[12], "port", 4) == 0) {
			if (pf->hw.partition_id == 1) {
				i40e_pf_reset_stats(pf);
				dev_info(&pf->pdev->dev, "port stats cleared\n");
			} else {
				dev_info(&pf->pdev->dev, "clear port stats not allowed on this port partition\n");
			}
J
Jesse Brandeburg 已提交
1561
		} else {
1562
			dev_info(&pf->pdev->dev, "clear_stats vsi [seid] or clear_stats port\n");
J
Jesse Brandeburg 已提交
1563
		}
1564 1565 1566 1567 1568 1569 1570 1571
	} else if (strncmp(cmd_buf, "send aq_cmd", 11) == 0) {
		struct i40e_aq_desc *desc;
		i40e_status ret;

		desc = kzalloc(sizeof(struct i40e_aq_desc), GFP_KERNEL);
		if (!desc)
			goto command_write_done;
		cnt = sscanf(&cmd_buf[11],
1572
			     "%hi %hi %hi %hi %i %i %i %i %i %i",
1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619
			     &desc->flags,
			     &desc->opcode, &desc->datalen, &desc->retval,
			     &desc->cookie_high, &desc->cookie_low,
			     &desc->params.internal.param0,
			     &desc->params.internal.param1,
			     &desc->params.internal.param2,
			     &desc->params.internal.param3);
		if (cnt != 10) {
			dev_info(&pf->pdev->dev,
				 "send aq_cmd: bad command string, cnt=%d\n",
				 cnt);
			kfree(desc);
			desc = NULL;
			goto command_write_done;
		}
		ret = i40e_asq_send_command(&pf->hw, desc, NULL, 0, NULL);
		if (!ret) {
			dev_info(&pf->pdev->dev, "AQ command sent Status : Success\n");
		} else if (ret == I40E_ERR_ADMIN_QUEUE_ERROR) {
			dev_info(&pf->pdev->dev,
				 "AQ command send failed Opcode %x AQ Error: %d\n",
				 desc->opcode, pf->hw.aq.asq_last_status);
		} else {
			dev_info(&pf->pdev->dev,
				 "AQ command send failed Opcode %x Status: %d\n",
				 desc->opcode, ret);
		}
		dev_info(&pf->pdev->dev,
			 "AQ desc WB 0x%04x 0x%04x 0x%04x 0x%04x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
			 desc->flags, desc->opcode, desc->datalen, desc->retval,
			 desc->cookie_high, desc->cookie_low,
			 desc->params.internal.param0,
			 desc->params.internal.param1,
			 desc->params.internal.param2,
			 desc->params.internal.param3);
		kfree(desc);
		desc = NULL;
	} else if (strncmp(cmd_buf, "send indirect aq_cmd", 20) == 0) {
		struct i40e_aq_desc *desc;
		i40e_status ret;
		u16 buffer_len;
		u8 *buff;

		desc = kzalloc(sizeof(struct i40e_aq_desc), GFP_KERNEL);
		if (!desc)
			goto command_write_done;
		cnt = sscanf(&cmd_buf[20],
1620
			     "%hi %hi %hi %hi %i %i %i %i %i %i %hi",
1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675
			     &desc->flags,
			     &desc->opcode, &desc->datalen, &desc->retval,
			     &desc->cookie_high, &desc->cookie_low,
			     &desc->params.internal.param0,
			     &desc->params.internal.param1,
			     &desc->params.internal.param2,
			     &desc->params.internal.param3,
			     &buffer_len);
		if (cnt != 11) {
			dev_info(&pf->pdev->dev,
				 "send indirect aq_cmd: bad command string, cnt=%d\n",
				 cnt);
			kfree(desc);
			desc = NULL;
			goto command_write_done;
		}
		/* Just stub a buffer big enough in case user messed up */
		if (buffer_len == 0)
			buffer_len = 1280;

		buff = kzalloc(buffer_len, GFP_KERNEL);
		if (!buff) {
			kfree(desc);
			desc = NULL;
			goto command_write_done;
		}
		desc->flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
		ret = i40e_asq_send_command(&pf->hw, desc, buff,
					    buffer_len, NULL);
		if (!ret) {
			dev_info(&pf->pdev->dev, "AQ command sent Status : Success\n");
		} else if (ret == I40E_ERR_ADMIN_QUEUE_ERROR) {
			dev_info(&pf->pdev->dev,
				 "AQ command send failed Opcode %x AQ Error: %d\n",
				 desc->opcode, pf->hw.aq.asq_last_status);
		} else {
			dev_info(&pf->pdev->dev,
				 "AQ command send failed Opcode %x Status: %d\n",
				 desc->opcode, ret);
		}
		dev_info(&pf->pdev->dev,
			 "AQ desc WB 0x%04x 0x%04x 0x%04x 0x%04x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
			 desc->flags, desc->opcode, desc->datalen, desc->retval,
			 desc->cookie_high, desc->cookie_low,
			 desc->params.internal.param0,
			 desc->params.internal.param1,
			 desc->params.internal.param2,
			 desc->params.internal.param3);
		print_hex_dump(KERN_INFO, "AQ buffer WB: ",
			       DUMP_PREFIX_OFFSET, 16, 1,
			       buff, buffer_len, true);
		kfree(buff);
		buff = NULL;
		kfree(desc);
		desc = NULL;
J
Jesse Brandeburg 已提交
1676 1677
	} else if ((strncmp(cmd_buf, "add fd_filter", 13) == 0) ||
		   (strncmp(cmd_buf, "rem fd_filter", 13) == 0)) {
1678
		struct i40e_fdir_filter fd_data;
J
Jesse Brandeburg 已提交
1679 1680
		u16 packet_len, i, j = 0;
		char *asc_packet;
1681
		u8 *raw_packet;
J
Jesse Brandeburg 已提交
1682
		bool add = false;
1683
		int ret;
J
Jesse Brandeburg 已提交
1684

1685 1686 1687 1688 1689 1690 1691 1692 1693
		if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
			goto command_write_done;

		if (strncmp(cmd_buf, "add", 3) == 0)
			add = true;

		if (add && (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED))
			goto command_write_done;

1694
		asc_packet = kzalloc(I40E_FDIR_MAX_RAW_PACKET_SIZE,
J
Jesse Brandeburg 已提交
1695 1696 1697 1698
				     GFP_KERNEL);
		if (!asc_packet)
			goto command_write_done;

1699 1700
		raw_packet = kzalloc(I40E_FDIR_MAX_RAW_PACKET_SIZE,
				     GFP_KERNEL);
J
Jesse Brandeburg 已提交
1701

1702
		if (!raw_packet) {
J
Jesse Brandeburg 已提交
1703 1704 1705 1706 1707 1708
			kfree(asc_packet);
			asc_packet = NULL;
			goto command_write_done;
		}

		cnt = sscanf(&cmd_buf[13],
1709
			     "%hx %2hhx %2hhx %hx %2hhx %2hhx %hx %x %hd %511s",
J
Jesse Brandeburg 已提交
1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720
			     &fd_data.q_index,
			     &fd_data.flex_off, &fd_data.pctype,
			     &fd_data.dest_vsi, &fd_data.dest_ctl,
			     &fd_data.fd_status, &fd_data.cnt_index,
			     &fd_data.fd_id, &packet_len, asc_packet);
		if (cnt != 10) {
			dev_info(&pf->pdev->dev,
				 "program fd_filter: bad command string, cnt=%d\n",
				 cnt);
			kfree(asc_packet);
			asc_packet = NULL;
1721
			kfree(raw_packet);
J
Jesse Brandeburg 已提交
1722 1723 1724 1725 1726
			goto command_write_done;
		}

		/* fix packet length if user entered 0 */
		if (packet_len == 0)
1727
			packet_len = I40E_FDIR_MAX_RAW_PACKET_SIZE;
J
Jesse Brandeburg 已提交
1728 1729 1730

		/* make sure to check the max as well */
		packet_len = min_t(u16,
1731
				   packet_len, I40E_FDIR_MAX_RAW_PACKET_SIZE);
J
Jesse Brandeburg 已提交
1732 1733

		for (i = 0; i < packet_len; i++) {
J
Jesse Brandeburg 已提交
1734 1735 1736
			cnt = sscanf(&asc_packet[j], "%2hhx ", &raw_packet[i]);
			if (!cnt)
				break;
J
Jesse Brandeburg 已提交
1737 1738
			j += 3;
		}
1739 1740 1741
		dev_info(&pf->pdev->dev, "FD raw packet dump\n");
		print_hex_dump(KERN_INFO, "FD raw packet: ",
			       DUMP_PREFIX_OFFSET, 16, 1,
1742 1743
			       raw_packet, packet_len, true);
		ret = i40e_program_fdir_filter(&fd_data, raw_packet, pf, add);
J
Jesse Brandeburg 已提交
1744 1745 1746 1747 1748 1749
		if (!ret) {
			dev_info(&pf->pdev->dev, "Filter command send Status : Success\n");
		} else {
			dev_info(&pf->pdev->dev,
				 "Filter command send failed %d\n", ret);
		}
1750 1751
		kfree(raw_packet);
		raw_packet = NULL;
J
Jesse Brandeburg 已提交
1752 1753
		kfree(asc_packet);
		asc_packet = NULL;
1754 1755 1756
	} else if (strncmp(cmd_buf, "fd current cnt", 14) == 0) {
		dev_info(&pf->pdev->dev, "FD current total filter count for this interface: %d\n",
			 i40e_get_current_fd_count(pf));
J
Jesse Brandeburg 已提交
1757 1758 1759
	} else if (strncmp(cmd_buf, "lldp", 4) == 0) {
		if (strncmp(&cmd_buf[5], "stop", 4) == 0) {
			int ret;
J
Jesse Brandeburg 已提交
1760

J
Jesse Brandeburg 已提交
1761 1762 1763 1764 1765 1766 1767
			ret = i40e_aq_stop_lldp(&pf->hw, false, NULL);
			if (ret) {
				dev_info(&pf->pdev->dev,
					 "Stop LLDP AQ command failed =0x%x\n",
					 pf->hw.aq.asq_last_status);
				goto command_write_done;
			}
N
Neerav Parikh 已提交
1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782
			ret = i40e_aq_add_rem_control_packet_filter(&pf->hw,
						pf->hw.mac.addr,
						I40E_ETH_P_LLDP, 0,
						pf->vsi[pf->lan_vsi]->seid,
						0, true, NULL, NULL);
			if (ret) {
				dev_info(&pf->pdev->dev,
					"%s: Add Control Packet Filter AQ command failed =0x%x\n",
					__func__, pf->hw.aq.asq_last_status);
				goto command_write_done;
			}
#ifdef CONFIG_I40E_DCB
			pf->dcbx_cap = DCB_CAP_DCBX_HOST |
				       DCB_CAP_DCBX_VER_IEEE;
#endif /* CONFIG_I40E_DCB */
J
Jesse Brandeburg 已提交
1783 1784
		} else if (strncmp(&cmd_buf[5], "start", 5) == 0) {
			int ret;
J
Jesse Brandeburg 已提交
1785

N
Neerav Parikh 已提交
1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797
			ret = i40e_aq_add_rem_control_packet_filter(&pf->hw,
						pf->hw.mac.addr,
						I40E_ETH_P_LLDP, 0,
						pf->vsi[pf->lan_vsi]->seid,
						0, false, NULL, NULL);
			if (ret) {
				dev_info(&pf->pdev->dev,
					"%s: Remove Control Packet Filter AQ command failed =0x%x\n",
					__func__, pf->hw.aq.asq_last_status);
				/* Continue and start FW LLDP anyways */
			}

J
Jesse Brandeburg 已提交
1798 1799 1800 1801 1802 1803 1804
			ret = i40e_aq_start_lldp(&pf->hw, NULL);
			if (ret) {
				dev_info(&pf->pdev->dev,
					 "Start LLDP AQ command failed =0x%x\n",
					 pf->hw.aq.asq_last_status);
				goto command_write_done;
			}
N
Neerav Parikh 已提交
1805 1806 1807 1808
#ifdef CONFIG_I40E_DCB
			pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
				       DCB_CAP_DCBX_VER_IEEE;
#endif /* CONFIG_I40E_DCB */
J
Jesse Brandeburg 已提交
1809 1810
		} else if (strncmp(&cmd_buf[5],
			   "get local", 9) == 0) {
1811
			u16 llen, rlen;
1812
			int ret;
J
Jesse Brandeburg 已提交
1813
			u8 *buff;
J
Jesse Brandeburg 已提交
1814

J
Jesse Brandeburg 已提交
1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830
			buff = kzalloc(I40E_LLDPDU_SIZE, GFP_KERNEL);
			if (!buff)
				goto command_write_done;

			ret = i40e_aq_get_lldp_mib(&pf->hw, 0,
						   I40E_AQ_LLDP_MIB_LOCAL,
						   buff, I40E_LLDPDU_SIZE,
						   &llen, &rlen, NULL);
			if (ret) {
				dev_info(&pf->pdev->dev,
					 "Get LLDP MIB (local) AQ command failed =0x%x\n",
					 pf->hw.aq.asq_last_status);
				kfree(buff);
				buff = NULL;
				goto command_write_done;
			}
1831 1832 1833 1834
			dev_info(&pf->pdev->dev, "LLDP MIB (local)\n");
			print_hex_dump(KERN_INFO, "LLDP MIB (local): ",
				       DUMP_PREFIX_OFFSET, 16, 1,
				       buff, I40E_LLDPDU_SIZE, true);
J
Jesse Brandeburg 已提交
1835 1836 1837
			kfree(buff);
			buff = NULL;
		} else if (strncmp(&cmd_buf[5], "get remote", 10) == 0) {
1838
			u16 llen, rlen;
1839
			int ret;
J
Jesse Brandeburg 已提交
1840
			u8 *buff;
J
Jesse Brandeburg 已提交
1841

J
Jesse Brandeburg 已提交
1842 1843 1844 1845 1846 1847
			buff = kzalloc(I40E_LLDPDU_SIZE, GFP_KERNEL);
			if (!buff)
				goto command_write_done;

			ret = i40e_aq_get_lldp_mib(&pf->hw,
					I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
1848
					I40E_AQ_LLDP_MIB_REMOTE,
J
Jesse Brandeburg 已提交
1849 1850 1851 1852 1853 1854 1855 1856 1857 1858
					buff, I40E_LLDPDU_SIZE,
					&llen, &rlen, NULL);
			if (ret) {
				dev_info(&pf->pdev->dev,
					 "Get LLDP MIB (remote) AQ command failed =0x%x\n",
					 pf->hw.aq.asq_last_status);
				kfree(buff);
				buff = NULL;
				goto command_write_done;
			}
1859 1860 1861 1862
			dev_info(&pf->pdev->dev, "LLDP MIB (remote)\n");
			print_hex_dump(KERN_INFO, "LLDP MIB (remote): ",
				       DUMP_PREFIX_OFFSET, 16, 1,
				       buff, I40E_LLDPDU_SIZE, true);
J
Jesse Brandeburg 已提交
1863 1864 1865 1866
			kfree(buff);
			buff = NULL;
		} else if (strncmp(&cmd_buf[5], "event on", 8) == 0) {
			int ret;
J
Jesse Brandeburg 已提交
1867

J
Jesse Brandeburg 已提交
1868 1869 1870 1871 1872 1873 1874 1875 1876 1877
			ret = i40e_aq_cfg_lldp_mib_change_event(&pf->hw,
								true, NULL);
			if (ret) {
				dev_info(&pf->pdev->dev,
					 "Config LLDP MIB Change Event (on) AQ command failed =0x%x\n",
					 pf->hw.aq.asq_last_status);
				goto command_write_done;
			}
		} else if (strncmp(&cmd_buf[5], "event off", 9) == 0) {
			int ret;
J
Jesse Brandeburg 已提交
1878

J
Jesse Brandeburg 已提交
1879 1880 1881 1882 1883 1884 1885 1886 1887 1888
			ret = i40e_aq_cfg_lldp_mib_change_event(&pf->hw,
								false, NULL);
			if (ret) {
				dev_info(&pf->pdev->dev,
					 "Config LLDP MIB Change Event (off) AQ command failed =0x%x\n",
					 pf->hw.aq.asq_last_status);
				goto command_write_done;
			}
		}
	} else if (strncmp(cmd_buf, "nvm read", 8) == 0) {
1889
		u16 buffer_len, bytes;
J
Jesse Brandeburg 已提交
1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911
		u16 module;
		u32 offset;
		u16 *buff;
		int ret;

		cnt = sscanf(&cmd_buf[8], "%hx %x %hx",
			     &module, &offset, &buffer_len);
		if (cnt == 0) {
			module = 0;
			offset = 0;
			buffer_len = 0;
		} else if (cnt == 1) {
			offset = 0;
			buffer_len = 0;
		} else if (cnt == 2) {
			buffer_len = 0;
		} else if (cnt > 3) {
			dev_info(&pf->pdev->dev,
				 "nvm read: bad command string, cnt=%d\n", cnt);
			goto command_write_done;
		}

1912 1913
		/* set the max length */
		buffer_len = min_t(u16, buffer_len, I40E_MAX_AQ_BUF_SIZE/2);
J
Jesse Brandeburg 已提交
1914 1915

		bytes = 2 * buffer_len;
1916 1917 1918

		/* read at least 1k bytes, no more than 4kB */
		bytes = clamp(bytes, (u16)1024, (u16)I40E_MAX_AQ_BUF_SIZE);
J
Jesse Brandeburg 已提交
1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942
		buff = kzalloc(bytes, GFP_KERNEL);
		if (!buff)
			goto command_write_done;

		ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
		if (ret) {
			dev_info(&pf->pdev->dev,
				 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
				 ret, pf->hw.aq.asq_last_status);
			kfree(buff);
			goto command_write_done;
		}

		ret = i40e_aq_read_nvm(&pf->hw, module, (2 * offset),
				       bytes, (u8 *)buff, true, NULL);
		i40e_release_nvm(&pf->hw);
		if (ret) {
			dev_info(&pf->pdev->dev,
				 "Read NVM AQ failed err=%d status=0x%x\n",
				 ret, pf->hw.aq.asq_last_status);
		} else {
			dev_info(&pf->pdev->dev,
				 "Read NVM module=0x%x offset=0x%x words=%d\n",
				 module, offset, buffer_len);
1943
			if (bytes)
1944 1945
				print_hex_dump(KERN_INFO, "NVM Dump: ",
					DUMP_PREFIX_OFFSET, 16, 2,
1946
					buff, bytes, true);
J
Jesse Brandeburg 已提交
1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966
		}
		kfree(buff);
		buff = NULL;
	} else {
		dev_info(&pf->pdev->dev, "unknown command '%s'\n", cmd_buf);
		dev_info(&pf->pdev->dev, "available commands\n");
		dev_info(&pf->pdev->dev, "  add vsi [relay_seid]\n");
		dev_info(&pf->pdev->dev, "  del vsi [vsi_seid]\n");
		dev_info(&pf->pdev->dev, "  add relay <uplink_seid> <vsi_seid>\n");
		dev_info(&pf->pdev->dev, "  del relay <relay_seid>\n");
		dev_info(&pf->pdev->dev, "  add macaddr <vsi_seid> <aa:bb:cc:dd:ee:ff> [vlan]\n");
		dev_info(&pf->pdev->dev, "  del macaddr <vsi_seid> <aa:bb:cc:dd:ee:ff> [vlan]\n");
		dev_info(&pf->pdev->dev, "  add pvid <vsi_seid> <vid>\n");
		dev_info(&pf->pdev->dev, "  del pvid <vsi_seid>\n");
		dev_info(&pf->pdev->dev, "  dump switch\n");
		dev_info(&pf->pdev->dev, "  dump vsi [seid]\n");
		dev_info(&pf->pdev->dev, "  dump desc tx <vsi_seid> <ring_id> [<desc_n>]\n");
		dev_info(&pf->pdev->dev, "  dump desc rx <vsi_seid> <ring_id> [<desc_n>]\n");
		dev_info(&pf->pdev->dev, "  dump desc aq\n");
		dev_info(&pf->pdev->dev, "  dump reset stats\n");
1967
		dev_info(&pf->pdev->dev, "  dump debug fwdata <cluster_id> <table_id> <index>\n");
J
Jesse Brandeburg 已提交
1968 1969 1970 1971
		dev_info(&pf->pdev->dev, "  msg_enable [level]\n");
		dev_info(&pf->pdev->dev, "  read <reg>\n");
		dev_info(&pf->pdev->dev, "  write <reg> <value>\n");
		dev_info(&pf->pdev->dev, "  clear_stats vsi [seid]\n");
1972
		dev_info(&pf->pdev->dev, "  clear_stats port\n");
J
Jesse Brandeburg 已提交
1973 1974 1975
		dev_info(&pf->pdev->dev, "  pfr\n");
		dev_info(&pf->pdev->dev, "  corer\n");
		dev_info(&pf->pdev->dev, "  globr\n");
1976 1977
		dev_info(&pf->pdev->dev, "  send aq_cmd <flags> <opcode> <datalen> <retval> <cookie_h> <cookie_l> <param0> <param1> <param2> <param3>\n");
		dev_info(&pf->pdev->dev, "  send indirect aq_cmd <flags> <opcode> <datalen> <retval> <cookie_h> <cookie_l> <param0> <param1> <param2> <param3> <buffer_len>\n");
J
Jesse Brandeburg 已提交
1978 1979
		dev_info(&pf->pdev->dev, "  add fd_filter <dest q_index> <flex_off> <pctype> <dest_vsi> <dest_ctl> <fd_status> <cnt_index> <fd_id> <packet_len> <packet>\n");
		dev_info(&pf->pdev->dev, "  rem fd_filter <dest q_index> <flex_off> <pctype> <dest_vsi> <dest_ctl> <fd_status> <cnt_index> <fd_id> <packet_len> <packet>\n");
1980
		dev_info(&pf->pdev->dev, "  fd current cnt");
J
Jesse Brandeburg 已提交
1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007
		dev_info(&pf->pdev->dev, "  lldp start\n");
		dev_info(&pf->pdev->dev, "  lldp stop\n");
		dev_info(&pf->pdev->dev, "  lldp get local\n");
		dev_info(&pf->pdev->dev, "  lldp get remote\n");
		dev_info(&pf->pdev->dev, "  lldp event on\n");
		dev_info(&pf->pdev->dev, "  lldp event off\n");
		dev_info(&pf->pdev->dev, "  nvm read [module] [word_offset] [word_count]\n");
	}

command_write_done:
	kfree(cmd_buf);
	cmd_buf = NULL;
	return count;
}

static const struct file_operations i40e_dbg_command_fops = {
	.owner = THIS_MODULE,
	.open =  simple_open,
	.read =  i40e_dbg_command_read,
	.write = i40e_dbg_command_write,
};

/**************************************************************
 * netdev_ops
 * The netdev_ops entry in debugfs is for giving the driver commands
 * to be executed from the netdev operations.
 **************************************************************/
2008
static char i40e_dbg_netdev_ops_buf[256] = "";
J
Jesse Brandeburg 已提交
2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042

/**
 * i40e_dbg_netdev_ops - read for netdev_ops datum
 * @filp: the opened file
 * @buffer: where to write the data for the user to read
 * @count: the size of the user's buffer
 * @ppos: file position offset
 **/
static ssize_t i40e_dbg_netdev_ops_read(struct file *filp, char __user *buffer,
					size_t count, loff_t *ppos)
{
	struct i40e_pf *pf = filp->private_data;
	int bytes_not_copied;
	int buf_size = 256;
	char *buf;
	int len;

	/* don't allow partal reads */
	if (*ppos != 0)
		return 0;
	if (count < buf_size)
		return -ENOSPC;

	buf = kzalloc(buf_size, GFP_KERNEL);
	if (!buf)
		return -ENOSPC;

	len = snprintf(buf, buf_size, "%s: %s\n",
		       pf->vsi[pf->lan_vsi]->netdev->name,
		       i40e_dbg_netdev_ops_buf);

	bytes_not_copied = copy_to_user(buffer, buf, len);
	kfree(buf);

R
Rasmus Villemoes 已提交
2043 2044
	if (bytes_not_copied)
		return -EFAULT;
J
Jesse Brandeburg 已提交
2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063

	*ppos = len;
	return len;
}

/**
 * i40e_dbg_netdev_ops_write - write into netdev_ops datum
 * @filp: the opened file
 * @buffer: where to find the user's data
 * @count: the length of the user's data
 * @ppos: file position offset
 **/
static ssize_t i40e_dbg_netdev_ops_write(struct file *filp,
					 const char __user *buffer,
					 size_t count, loff_t *ppos)
{
	struct i40e_pf *pf = filp->private_data;
	int bytes_not_copied;
	struct i40e_vsi *vsi;
2064
	char *buf_tmp;
J
Jesse Brandeburg 已提交
2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076
	int vsi_seid;
	int i, cnt;

	/* don't allow partial writes */
	if (*ppos != 0)
		return 0;
	if (count >= sizeof(i40e_dbg_netdev_ops_buf))
		return -ENOSPC;

	memset(i40e_dbg_netdev_ops_buf, 0, sizeof(i40e_dbg_netdev_ops_buf));
	bytes_not_copied = copy_from_user(i40e_dbg_netdev_ops_buf,
					  buffer, count);
R
Rasmus Villemoes 已提交
2077 2078
	if (bytes_not_copied)
		return -EFAULT;
J
Jesse Brandeburg 已提交
2079 2080
	i40e_dbg_netdev_ops_buf[count] = '\0';

2081 2082 2083 2084 2085 2086
	buf_tmp = strchr(i40e_dbg_netdev_ops_buf, '\n');
	if (buf_tmp) {
		*buf_tmp = '\0';
		count = buf_tmp - i40e_dbg_netdev_ops_buf + 1;
	}

J
Jesse Brandeburg 已提交
2087 2088 2089 2090 2091 2092 2093 2094 2095 2096
	if (strncmp(i40e_dbg_netdev_ops_buf, "tx_timeout", 10) == 0) {
		cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i", &vsi_seid);
		if (cnt != 1) {
			dev_info(&pf->pdev->dev, "tx_timeout <vsi_seid>\n");
			goto netdev_ops_write_done;
		}
		vsi = i40e_dbg_find_vsi(pf, vsi_seid);
		if (!vsi) {
			dev_info(&pf->pdev->dev,
				 "tx_timeout: VSI %d not found\n", vsi_seid);
2097 2098 2099 2100 2101 2102 2103
		} else if (!vsi->netdev) {
			dev_info(&pf->pdev->dev, "tx_timeout: no netdev for VSI %d\n",
				 vsi_seid);
		} else if (test_bit(__I40E_DOWN, &vsi->state)) {
			dev_info(&pf->pdev->dev, "tx_timeout: VSI %d not UP\n",
				 vsi_seid);
		} else if (rtnl_trylock()) {
J
Jesse Brandeburg 已提交
2104 2105 2106 2107 2108 2109 2110 2111
			vsi->netdev->netdev_ops->ndo_tx_timeout(vsi->netdev);
			rtnl_unlock();
			dev_info(&pf->pdev->dev, "tx_timeout called\n");
		} else {
			dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n");
		}
	} else if (strncmp(i40e_dbg_netdev_ops_buf, "change_mtu", 10) == 0) {
		int mtu;
J
Jesse Brandeburg 已提交
2112

J
Jesse Brandeburg 已提交
2113 2114 2115 2116 2117 2118 2119 2120 2121 2122
		cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i %i",
			     &vsi_seid, &mtu);
		if (cnt != 2) {
			dev_info(&pf->pdev->dev, "change_mtu <vsi_seid> <mtu>\n");
			goto netdev_ops_write_done;
		}
		vsi = i40e_dbg_find_vsi(pf, vsi_seid);
		if (!vsi) {
			dev_info(&pf->pdev->dev,
				 "change_mtu: VSI %d not found\n", vsi_seid);
2123 2124 2125 2126
		} else if (!vsi->netdev) {
			dev_info(&pf->pdev->dev, "change_mtu: no netdev for VSI %d\n",
				 vsi_seid);
		} else if (rtnl_trylock()) {
J
Jesse Brandeburg 已提交
2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144
			vsi->netdev->netdev_ops->ndo_change_mtu(vsi->netdev,
								mtu);
			rtnl_unlock();
			dev_info(&pf->pdev->dev, "change_mtu called\n");
		} else {
			dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n");
		}

	} else if (strncmp(i40e_dbg_netdev_ops_buf, "set_rx_mode", 11) == 0) {
		cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i", &vsi_seid);
		if (cnt != 1) {
			dev_info(&pf->pdev->dev, "set_rx_mode <vsi_seid>\n");
			goto netdev_ops_write_done;
		}
		vsi = i40e_dbg_find_vsi(pf, vsi_seid);
		if (!vsi) {
			dev_info(&pf->pdev->dev,
				 "set_rx_mode: VSI %d not found\n", vsi_seid);
2145 2146 2147 2148
		} else if (!vsi->netdev) {
			dev_info(&pf->pdev->dev, "set_rx_mode: no netdev for VSI %d\n",
				 vsi_seid);
		} else if (rtnl_trylock()) {
J
Jesse Brandeburg 已提交
2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165
			vsi->netdev->netdev_ops->ndo_set_rx_mode(vsi->netdev);
			rtnl_unlock();
			dev_info(&pf->pdev->dev, "set_rx_mode called\n");
		} else {
			dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n");
		}

	} else if (strncmp(i40e_dbg_netdev_ops_buf, "napi", 4) == 0) {
		cnt = sscanf(&i40e_dbg_netdev_ops_buf[4], "%i", &vsi_seid);
		if (cnt != 1) {
			dev_info(&pf->pdev->dev, "napi <vsi_seid>\n");
			goto netdev_ops_write_done;
		}
		vsi = i40e_dbg_find_vsi(pf, vsi_seid);
		if (!vsi) {
			dev_info(&pf->pdev->dev, "napi: VSI %d not found\n",
				 vsi_seid);
2166 2167 2168 2169 2170 2171 2172
		} else if (!vsi->netdev) {
			dev_info(&pf->pdev->dev, "napi: no netdev for VSI %d\n",
				 vsi_seid);
		} else {
			for (i = 0; i < vsi->num_q_vectors; i++)
				napi_schedule(&vsi->q_vectors[i]->napi);
			dev_info(&pf->pdev->dev, "napi called\n");
J
Jesse Brandeburg 已提交
2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194
		}
	} else {
		dev_info(&pf->pdev->dev, "unknown command '%s'\n",
			 i40e_dbg_netdev_ops_buf);
		dev_info(&pf->pdev->dev, "available commands\n");
		dev_info(&pf->pdev->dev, "  tx_timeout <vsi_seid>\n");
		dev_info(&pf->pdev->dev, "  change_mtu <vsi_seid> <mtu>\n");
		dev_info(&pf->pdev->dev, "  set_rx_mode <vsi_seid>\n");
		dev_info(&pf->pdev->dev, "  napi <vsi_seid>\n");
	}
netdev_ops_write_done:
	return count;
}

static const struct file_operations i40e_dbg_netdev_ops_fops = {
	.owner = THIS_MODULE,
	.open = simple_open,
	.read = i40e_dbg_netdev_ops_read,
	.write = i40e_dbg_netdev_ops_write,
};

/**
2195 2196
 * i40e_dbg_pf_init - setup the debugfs directory for the PF
 * @pf: the PF that is starting up
J
Jesse Brandeburg 已提交
2197 2198 2199
 **/
void i40e_dbg_pf_init(struct i40e_pf *pf)
{
J
Jesse Brandeburg 已提交
2200
	struct dentry *pfile;
J
Jesse Brandeburg 已提交
2201
	const char *name = pci_name(pf->pdev);
J
Jesse Brandeburg 已提交
2202
	const struct device *dev = &pf->pdev->dev;
J
Jesse Brandeburg 已提交
2203 2204

	pf->i40e_dbg_pf = debugfs_create_dir(name, i40e_dbg_root);
J
Jesse Brandeburg 已提交
2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227
	if (!pf->i40e_dbg_pf)
		return;

	pfile = debugfs_create_file("command", 0600, pf->i40e_dbg_pf, pf,
				    &i40e_dbg_command_fops);
	if (!pfile)
		goto create_failed;

	pfile = debugfs_create_file("dump", 0600, pf->i40e_dbg_pf, pf,
				    &i40e_dbg_dump_fops);
	if (!pfile)
		goto create_failed;

	pfile = debugfs_create_file("netdev_ops", 0600, pf->i40e_dbg_pf, pf,
				    &i40e_dbg_netdev_ops_fops);
	if (!pfile)
		goto create_failed;

	return;

create_failed:
	dev_info(dev, "debugfs dir/file for %s failed\n", name);
	debugfs_remove_recursive(pf->i40e_dbg_pf);
J
Jesse Brandeburg 已提交
2228 2229 2230
}

/**
2231 2232
 * i40e_dbg_pf_exit - clear out the PF's debugfs entries
 * @pf: the PF that is stopping
J
Jesse Brandeburg 已提交
2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262
 **/
void i40e_dbg_pf_exit(struct i40e_pf *pf)
{
	debugfs_remove_recursive(pf->i40e_dbg_pf);
	pf->i40e_dbg_pf = NULL;

	kfree(i40e_dbg_dump_buf);
	i40e_dbg_dump_buf = NULL;
}

/**
 * i40e_dbg_init - start up debugfs for the driver
 **/
void i40e_dbg_init(void)
{
	i40e_dbg_root = debugfs_create_dir(i40e_driver_name, NULL);
	if (!i40e_dbg_root)
		pr_info("init of debugfs failed\n");
}

/**
 * i40e_dbg_exit - clean out the driver's debugfs entries
 **/
void i40e_dbg_exit(void)
{
	debugfs_remove_recursive(i40e_dbg_root);
	i40e_dbg_root = NULL;
}

#endif /* CONFIG_DEBUG_FS */