]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/net/ethernet/intel/i40e/i40e_debugfs.c
i40e: fix up scanf decoders
[mirror_ubuntu-hirsute-kernel.git] / drivers / net / ethernet / intel / i40e / i40e_debugfs.c
CommitLineData
02e9c290
JB
1/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 Intel Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * The full GNU General Public License is included in this distribution in
20 * the file called "COPYING".
21 *
22 * Contact Information:
23 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 *
26 ******************************************************************************/
27
28#ifdef CONFIG_DEBUG_FS
29
30#include <linux/fs.h>
31#include <linux/debugfs.h>
32
33#include "i40e.h"
34
35static struct dentry *i40e_dbg_root;
36
37/**
38 * i40e_dbg_find_vsi - searches for the vsi with the given seid
39 * @pf - the pf structure to search for the vsi
40 * @seid - seid of the vsi it is searching for
41 **/
42static struct i40e_vsi *i40e_dbg_find_vsi(struct i40e_pf *pf, int seid)
43{
44 int i;
45
46 if (seid < 0)
47 dev_info(&pf->pdev->dev, "%d: bad seid\n", seid);
48 else
49 for (i = 0; i < pf->hw.func_caps.num_vsis; i++)
50 if (pf->vsi[i] && (pf->vsi[i]->seid == seid))
51 return pf->vsi[i];
52
53 return NULL;
54}
55
56/**
57 * i40e_dbg_find_veb - searches for the veb with the given seid
58 * @pf - the pf structure to search for the veb
59 * @seid - seid of the veb it is searching for
60 **/
61static struct i40e_veb *i40e_dbg_find_veb(struct i40e_pf *pf, int seid)
62{
63 int i;
64
65 if ((seid < I40E_BASE_VEB_SEID) ||
66 (seid > (I40E_BASE_VEB_SEID + I40E_MAX_VEB)))
67 dev_info(&pf->pdev->dev, "%d: bad seid\n", seid);
68 else
69 for (i = 0; i < I40E_MAX_VEB; i++)
70 if (pf->veb[i] && pf->veb[i]->seid == seid)
71 return pf->veb[i];
72 return NULL;
73}
74
75/**************************************************************
76 * dump
77 * The dump entry in debugfs is for getting a data snapshow of
78 * the driver's current configuration and runtime details.
79 * When the filesystem entry is written, a snapshot is taken.
80 * When the entry is read, the most recent snapshot data is dumped.
81 **************************************************************/
82static char *i40e_dbg_dump_buf;
83static ssize_t i40e_dbg_dump_data_len;
84static ssize_t i40e_dbg_dump_buffer_len;
85
86/**
87 * i40e_dbg_dump_read - read the dump data
88 * @filp: the opened file
89 * @buffer: where to write the data for the user to read
90 * @count: the size of the user's buffer
91 * @ppos: file position offset
92 **/
93static ssize_t i40e_dbg_dump_read(struct file *filp, char __user *buffer,
94 size_t count, loff_t *ppos)
95{
96 int bytes_not_copied;
97 int len;
98
99 /* is *ppos bigger than the available data? */
100 if (*ppos >= i40e_dbg_dump_data_len || !i40e_dbg_dump_buf)
101 return 0;
102
103 /* be sure to not read beyond the end of available data */
104 len = min_t(int, count, (i40e_dbg_dump_data_len - *ppos));
105
106 bytes_not_copied = copy_to_user(buffer, &i40e_dbg_dump_buf[*ppos], len);
107 if (bytes_not_copied < 0)
108 return bytes_not_copied;
109
110 *ppos += len;
111 return len;
112}
113
114/**
115 * i40e_dbg_prep_dump_buf
116 * @pf: the pf we're working with
117 * @buflen: the desired buffer length
118 *
119 * Return positive if success, 0 if failed
120 **/
121static int i40e_dbg_prep_dump_buf(struct i40e_pf *pf, int buflen)
122{
123 /* if not already big enough, prep for re alloc */
124 if (i40e_dbg_dump_buffer_len && i40e_dbg_dump_buffer_len < buflen) {
125 kfree(i40e_dbg_dump_buf);
126 i40e_dbg_dump_buffer_len = 0;
127 i40e_dbg_dump_buf = NULL;
128 }
129
130 /* get a new buffer if needed */
131 if (!i40e_dbg_dump_buf) {
132 i40e_dbg_dump_buf = kzalloc(buflen, GFP_KERNEL);
133 if (i40e_dbg_dump_buf != NULL)
134 i40e_dbg_dump_buffer_len = buflen;
135 }
136
137 return i40e_dbg_dump_buffer_len;
138}
139
140/**
141 * i40e_dbg_dump_write - trigger a datadump snapshot
142 * @filp: the opened file
143 * @buffer: where to find the user's data
144 * @count: the length of the user's data
145 * @ppos: file position offset
146 *
147 * Any write clears the stats
148 **/
149static ssize_t i40e_dbg_dump_write(struct file *filp,
150 const char __user *buffer,
151 size_t count, loff_t *ppos)
152{
153 struct i40e_pf *pf = filp->private_data;
02e9c290 154 bool seid_found = false;
02e9c290
JB
155 long seid = -1;
156 int buflen = 0;
157 int i, ret;
158 int len;
159 u8 *p;
160
161 /* don't allow partial writes */
162 if (*ppos != 0)
163 return 0;
02e9c290
JB
164
165 /* decode the SEID given to be dumped */
004173cb
JB
166 ret = kstrtol_from_user(buffer, count, 0, &seid);
167
168 if (ret) {
169 dev_info(&pf->pdev->dev, "bad seid value\n");
02e9c290
JB
170 } else if (seid == 0) {
171 seid_found = true;
172
173 kfree(i40e_dbg_dump_buf);
174 i40e_dbg_dump_buffer_len = 0;
175 i40e_dbg_dump_data_len = 0;
176 i40e_dbg_dump_buf = NULL;
177 dev_info(&pf->pdev->dev, "debug buffer freed\n");
178
179 } else if (seid == pf->pf_seid || seid == 1) {
180 seid_found = true;
181
182 buflen = sizeof(struct i40e_pf);
183 buflen += (sizeof(struct i40e_aq_desc)
184 * (pf->hw.aq.num_arq_entries + pf->hw.aq.num_asq_entries));
185
186 if (i40e_dbg_prep_dump_buf(pf, buflen)) {
187 p = i40e_dbg_dump_buf;
188
189 len = sizeof(struct i40e_pf);
190 memcpy(p, pf, len);
191 p += len;
192
193 len = (sizeof(struct i40e_aq_desc)
194 * pf->hw.aq.num_asq_entries);
195 memcpy(p, pf->hw.aq.asq.desc, len);
196 p += len;
197
198 len = (sizeof(struct i40e_aq_desc)
199 * pf->hw.aq.num_arq_entries);
200 memcpy(p, pf->hw.aq.arq.desc, len);
201 p += len;
202
203 i40e_dbg_dump_data_len = buflen;
204 dev_info(&pf->pdev->dev,
205 "PF seid %ld dumped %d bytes\n",
206 seid, (int)i40e_dbg_dump_data_len);
207 }
208 } else if (seid >= I40E_BASE_VSI_SEID) {
209 struct i40e_vsi *vsi = NULL;
210 struct i40e_mac_filter *f;
211 int filter_count = 0;
212
213 mutex_lock(&pf->switch_mutex);
214 vsi = i40e_dbg_find_vsi(pf, seid);
215 if (!vsi) {
216 mutex_unlock(&pf->switch_mutex);
217 goto write_exit;
218 }
219
220 buflen = sizeof(struct i40e_vsi);
221 buflen += sizeof(struct i40e_q_vector) * vsi->num_q_vectors;
222 buflen += sizeof(struct i40e_ring) * 2 * vsi->num_queue_pairs;
223 buflen += sizeof(struct i40e_tx_buffer) * vsi->num_queue_pairs;
224 buflen += sizeof(struct i40e_rx_buffer) * vsi->num_queue_pairs;
225 list_for_each_entry(f, &vsi->mac_filter_list, list)
226 filter_count++;
227 buflen += sizeof(struct i40e_mac_filter) * filter_count;
228
229 if (i40e_dbg_prep_dump_buf(pf, buflen)) {
230 p = i40e_dbg_dump_buf;
231 seid_found = true;
232
233 len = sizeof(struct i40e_vsi);
234 memcpy(p, vsi, len);
235 p += len;
236
59072ba1
SN
237 if (vsi->num_q_vectors) {
238 len = (sizeof(struct i40e_q_vector)
239 * vsi->num_q_vectors);
240 memcpy(p, vsi->q_vectors, len);
241 p += len;
242 }
02e9c290 243
59072ba1
SN
244 if (vsi->num_queue_pairs) {
245 len = (sizeof(struct i40e_ring) *
246 vsi->num_queue_pairs);
247 memcpy(p, vsi->tx_rings, len);
248 p += len;
249 memcpy(p, vsi->rx_rings, len);
02e9c290
JB
250 p += len;
251 }
59072ba1
SN
252
253 if (vsi->tx_rings[0]) {
254 len = sizeof(struct i40e_tx_buffer);
255 for (i = 0; i < vsi->num_queue_pairs; i++) {
256 memcpy(p, vsi->tx_rings[i]->tx_bi, len);
257 p += len;
258 }
02e9c290 259 len = sizeof(struct i40e_rx_buffer);
59072ba1
SN
260 for (i = 0; i < vsi->num_queue_pairs; i++) {
261 memcpy(p, vsi->rx_rings[i]->rx_bi, len);
262 p += len;
263 }
02e9c290
JB
264 }
265
266 /* macvlan filter list */
267 len = sizeof(struct i40e_mac_filter);
268 list_for_each_entry(f, &vsi->mac_filter_list, list) {
269 memcpy(p, f, len);
270 p += len;
271 }
272
273 i40e_dbg_dump_data_len = buflen;
274 dev_info(&pf->pdev->dev,
275 "VSI seid %ld dumped %d bytes\n",
276 seid, (int)i40e_dbg_dump_data_len);
277 }
278 mutex_unlock(&pf->switch_mutex);
279 } else if (seid >= I40E_BASE_VEB_SEID) {
280 struct i40e_veb *veb = NULL;
281
282 mutex_lock(&pf->switch_mutex);
283 veb = i40e_dbg_find_veb(pf, seid);
284 if (!veb) {
285 mutex_unlock(&pf->switch_mutex);
286 goto write_exit;
287 }
288
289 buflen = sizeof(struct i40e_veb);
290 if (i40e_dbg_prep_dump_buf(pf, buflen)) {
291 seid_found = true;
292 memcpy(i40e_dbg_dump_buf, veb, buflen);
293 i40e_dbg_dump_data_len = buflen;
294 dev_info(&pf->pdev->dev,
295 "VEB seid %ld dumped %d bytes\n",
296 seid, (int)i40e_dbg_dump_data_len);
297 }
298 mutex_unlock(&pf->switch_mutex);
299 }
300
301write_exit:
302 if (!seid_found)
303 dev_info(&pf->pdev->dev, "unknown seid %ld\n", seid);
304
305 return count;
306}
307
308static const struct file_operations i40e_dbg_dump_fops = {
309 .owner = THIS_MODULE,
310 .open = simple_open,
311 .read = i40e_dbg_dump_read,
312 .write = i40e_dbg_dump_write,
313};
314
315/**************************************************************
316 * command
317 * The command entry in debugfs is for giving the driver commands
318 * to be executed - these may be for changing the internal switch
319 * setup, adding or removing filters, or other things. Many of
320 * these will be useful for some forms of unit testing.
321 **************************************************************/
322static char i40e_dbg_command_buf[256] = "hello world";
323
324/**
325 * i40e_dbg_command_read - read for command datum
326 * @filp: the opened file
327 * @buffer: where to write the data for the user to read
328 * @count: the size of the user's buffer
329 * @ppos: file position offset
330 **/
331static ssize_t i40e_dbg_command_read(struct file *filp, char __user *buffer,
332 size_t count, loff_t *ppos)
333{
334 struct i40e_pf *pf = filp->private_data;
335 int bytes_not_copied;
336 int buf_size = 256;
337 char *buf;
338 int len;
339
340 /* don't allow partial reads */
341 if (*ppos != 0)
342 return 0;
343 if (count < buf_size)
344 return -ENOSPC;
345
346 buf = kzalloc(buf_size, GFP_KERNEL);
347 if (!buf)
348 return -ENOSPC;
349
350 len = snprintf(buf, buf_size, "%s: %s\n",
351 pf->vsi[pf->lan_vsi]->netdev->name,
352 i40e_dbg_command_buf);
353
354 bytes_not_copied = copy_to_user(buffer, buf, len);
355 kfree(buf);
356
357 if (bytes_not_copied < 0)
358 return bytes_not_copied;
359
360 *ppos = len;
361 return len;
362}
363
364/**
365 * i40e_dbg_dump_vsi_seid - handles dump vsi seid write into pokem datum
366 * @pf: the i40e_pf created in command write
367 * @seid: the seid the user put in
368 **/
369static void i40e_dbg_dump_vsi_seid(struct i40e_pf *pf, int seid)
370{
371 struct rtnl_link_stats64 *nstat;
372 struct i40e_mac_filter *f;
373 struct i40e_vsi *vsi;
374 int i;
375
376 vsi = i40e_dbg_find_vsi(pf, seid);
377 if (!vsi) {
378 dev_info(&pf->pdev->dev,
379 "dump %d: seid not found\n", seid);
380 return;
381 }
382 dev_info(&pf->pdev->dev, "vsi seid %d\n", seid);
383 if (vsi->netdev)
384 dev_info(&pf->pdev->dev,
385 " netdev: name = %s\n",
386 vsi->netdev->name);
387 if (vsi->active_vlans)
388 dev_info(&pf->pdev->dev,
389 " vlgrp: & = %p\n", vsi->active_vlans);
390 dev_info(&pf->pdev->dev,
391 " netdev_registered = %i, current_netdev_flags = 0x%04x, state = %li flags = 0x%08lx\n",
392 vsi->netdev_registered,
393 vsi->current_netdev_flags, vsi->state, vsi->flags);
394 list_for_each_entry(f, &vsi->mac_filter_list, list) {
395 dev_info(&pf->pdev->dev,
396 " mac_filter_list: %pM vid=%d, is_netdev=%d is_vf=%d counter=%d\n",
397 f->macaddr, f->vlan, f->is_netdev, f->is_vf,
398 f->counter);
399 }
400 nstat = i40e_get_vsi_stats_struct(vsi);
401 dev_info(&pf->pdev->dev,
402 " net_stats: rx_packets = %lu, rx_bytes = %lu, rx_errors = %lu, rx_dropped = %lu\n",
403 (long unsigned int)nstat->rx_packets,
404 (long unsigned int)nstat->rx_bytes,
405 (long unsigned int)nstat->rx_errors,
406 (long unsigned int)nstat->rx_dropped);
407 dev_info(&pf->pdev->dev,
408 " net_stats: tx_packets = %lu, tx_bytes = %lu, tx_errors = %lu, tx_dropped = %lu\n",
409 (long unsigned int)nstat->tx_packets,
410 (long unsigned int)nstat->tx_bytes,
411 (long unsigned int)nstat->tx_errors,
412 (long unsigned int)nstat->tx_dropped);
413 dev_info(&pf->pdev->dev,
414 " net_stats: multicast = %lu, collisions = %lu\n",
415 (long unsigned int)nstat->multicast,
416 (long unsigned int)nstat->collisions);
417 dev_info(&pf->pdev->dev,
418 " net_stats: rx_length_errors = %lu, rx_over_errors = %lu, rx_crc_errors = %lu\n",
419 (long unsigned int)nstat->rx_length_errors,
420 (long unsigned int)nstat->rx_over_errors,
421 (long unsigned int)nstat->rx_crc_errors);
422 dev_info(&pf->pdev->dev,
423 " net_stats: rx_frame_errors = %lu, rx_fifo_errors = %lu, rx_missed_errors = %lu\n",
424 (long unsigned int)nstat->rx_frame_errors,
425 (long unsigned int)nstat->rx_fifo_errors,
426 (long unsigned int)nstat->rx_missed_errors);
427 dev_info(&pf->pdev->dev,
428 " net_stats: tx_aborted_errors = %lu, tx_carrier_errors = %lu, tx_fifo_errors = %lu\n",
429 (long unsigned int)nstat->tx_aborted_errors,
430 (long unsigned int)nstat->tx_carrier_errors,
431 (long unsigned int)nstat->tx_fifo_errors);
432 dev_info(&pf->pdev->dev,
433 " net_stats: tx_heartbeat_errors = %lu, tx_window_errors = %lu\n",
434 (long unsigned int)nstat->tx_heartbeat_errors,
435 (long unsigned int)nstat->tx_window_errors);
436 dev_info(&pf->pdev->dev,
437 " net_stats: rx_compressed = %lu, tx_compressed = %lu\n",
438 (long unsigned int)nstat->rx_compressed,
439 (long unsigned int)nstat->tx_compressed);
440 dev_info(&pf->pdev->dev,
441 " net_stats_offsets: rx_packets = %lu, rx_bytes = %lu, rx_errors = %lu, rx_dropped = %lu\n",
442 (long unsigned int)vsi->net_stats_offsets.rx_packets,
443 (long unsigned int)vsi->net_stats_offsets.rx_bytes,
444 (long unsigned int)vsi->net_stats_offsets.rx_errors,
445 (long unsigned int)vsi->net_stats_offsets.rx_dropped);
446 dev_info(&pf->pdev->dev,
447 " net_stats_offsets: tx_packets = %lu, tx_bytes = %lu, tx_errors = %lu, tx_dropped = %lu\n",
448 (long unsigned int)vsi->net_stats_offsets.tx_packets,
449 (long unsigned int)vsi->net_stats_offsets.tx_bytes,
450 (long unsigned int)vsi->net_stats_offsets.tx_errors,
451 (long unsigned int)vsi->net_stats_offsets.tx_dropped);
452 dev_info(&pf->pdev->dev,
453 " net_stats_offsets: multicast = %lu, collisions = %lu\n",
454 (long unsigned int)vsi->net_stats_offsets.multicast,
455 (long unsigned int)vsi->net_stats_offsets.collisions);
456 dev_info(&pf->pdev->dev,
457 " net_stats_offsets: rx_length_errors = %lu, rx_over_errors = %lu, rx_crc_errors = %lu\n",
458 (long unsigned int)vsi->net_stats_offsets.rx_length_errors,
459 (long unsigned int)vsi->net_stats_offsets.rx_over_errors,
460 (long unsigned int)vsi->net_stats_offsets.rx_crc_errors);
461 dev_info(&pf->pdev->dev,
462 " net_stats_offsets: rx_frame_errors = %lu, rx_fifo_errors = %lu, rx_missed_errors = %lu\n",
463 (long unsigned int)vsi->net_stats_offsets.rx_frame_errors,
464 (long unsigned int)vsi->net_stats_offsets.rx_fifo_errors,
465 (long unsigned int)vsi->net_stats_offsets.rx_missed_errors);
466 dev_info(&pf->pdev->dev,
467 " net_stats_offsets: tx_aborted_errors = %lu, tx_carrier_errors = %lu, tx_fifo_errors = %lu\n",
468 (long unsigned int)vsi->net_stats_offsets.tx_aborted_errors,
469 (long unsigned int)vsi->net_stats_offsets.tx_carrier_errors,
470 (long unsigned int)vsi->net_stats_offsets.tx_fifo_errors);
471 dev_info(&pf->pdev->dev,
472 " net_stats_offsets: tx_heartbeat_errors = %lu, tx_window_errors = %lu\n",
473 (long unsigned int)vsi->net_stats_offsets.tx_heartbeat_errors,
474 (long unsigned int)vsi->net_stats_offsets.tx_window_errors);
475 dev_info(&pf->pdev->dev,
476 " net_stats_offsets: rx_compressed = %lu, tx_compressed = %lu\n",
477 (long unsigned int)vsi->net_stats_offsets.rx_compressed,
478 (long unsigned int)vsi->net_stats_offsets.tx_compressed);
479 dev_info(&pf->pdev->dev,
480 " tx_restart = %d, tx_busy = %d, rx_buf_failed = %d, rx_page_failed = %d\n",
481 vsi->tx_restart, vsi->tx_busy,
482 vsi->rx_buf_failed, vsi->rx_page_failed);
9f65e15b
AD
483 rcu_read_lock();
484 for (i = 0; i < vsi->num_queue_pairs; i++) {
485 struct i40e_ring *rx_ring = ACCESS_ONCE(vsi->rx_rings[i]);
486 if (!rx_ring)
487 continue;
488
489 dev_info(&pf->pdev->dev,
490 " rx_rings[%i]: desc = %p\n",
491 i, rx_ring->desc);
492 dev_info(&pf->pdev->dev,
493 " rx_rings[%i]: dev = %p, netdev = %p, rx_bi = %p\n",
494 i, rx_ring->dev,
495 rx_ring->netdev,
496 rx_ring->rx_bi);
497 dev_info(&pf->pdev->dev,
498 " rx_rings[%i]: state = %li, queue_index = %d, reg_idx = %d\n",
499 i, rx_ring->state,
500 rx_ring->queue_index,
501 rx_ring->reg_idx);
502 dev_info(&pf->pdev->dev,
503 " rx_rings[%i]: rx_hdr_len = %d, rx_buf_len = %d, dtype = %d\n",
504 i, rx_ring->rx_hdr_len,
505 rx_ring->rx_buf_len,
506 rx_ring->dtype);
507 dev_info(&pf->pdev->dev,
508 " rx_rings[%i]: hsplit = %d, next_to_use = %d, next_to_clean = %d, ring_active = %i\n",
509 i, rx_ring->hsplit,
510 rx_ring->next_to_use,
511 rx_ring->next_to_clean,
512 rx_ring->ring_active);
513 dev_info(&pf->pdev->dev,
514 " rx_rings[%i]: rx_stats: packets = %lld, bytes = %lld, non_eop_descs = %lld\n",
515 i, rx_ring->stats.packets,
516 rx_ring->stats.bytes,
517 rx_ring->rx_stats.non_eop_descs);
518 dev_info(&pf->pdev->dev,
519 " rx_rings[%i]: rx_stats: alloc_rx_page_failed = %lld, alloc_rx_buff_failed = %lld\n",
520 i,
521 rx_ring->rx_stats.alloc_rx_page_failed,
522 rx_ring->rx_stats.alloc_rx_buff_failed);
523 dev_info(&pf->pdev->dev,
524 " rx_rings[%i]: size = %i, dma = 0x%08lx\n",
525 i, rx_ring->size,
526 (long unsigned int)rx_ring->dma);
527 dev_info(&pf->pdev->dev,
528 " rx_rings[%i]: vsi = %p, q_vector = %p\n",
529 i, rx_ring->vsi,
530 rx_ring->q_vector);
02e9c290 531 }
9f65e15b
AD
532 for (i = 0; i < vsi->num_queue_pairs; i++) {
533 struct i40e_ring *tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
534 if (!tx_ring)
535 continue;
536 dev_info(&pf->pdev->dev,
537 " tx_rings[%i]: desc = %p\n",
538 i, tx_ring->desc);
539 dev_info(&pf->pdev->dev,
540 " tx_rings[%i]: dev = %p, netdev = %p, tx_bi = %p\n",
541 i, tx_ring->dev,
542 tx_ring->netdev,
543 tx_ring->tx_bi);
544 dev_info(&pf->pdev->dev,
545 " tx_rings[%i]: state = %li, queue_index = %d, reg_idx = %d\n",
546 i, tx_ring->state,
547 tx_ring->queue_index,
548 tx_ring->reg_idx);
549 dev_info(&pf->pdev->dev,
550 " tx_rings[%i]: dtype = %d\n",
551 i, tx_ring->dtype);
552 dev_info(&pf->pdev->dev,
553 " tx_rings[%i]: hsplit = %d, next_to_use = %d, next_to_clean = %d, ring_active = %i\n",
554 i, tx_ring->hsplit,
555 tx_ring->next_to_use,
556 tx_ring->next_to_clean,
557 tx_ring->ring_active);
558 dev_info(&pf->pdev->dev,
559 " tx_rings[%i]: tx_stats: packets = %lld, bytes = %lld, restart_queue = %lld\n",
560 i, tx_ring->stats.packets,
561 tx_ring->stats.bytes,
562 tx_ring->tx_stats.restart_queue);
563 dev_info(&pf->pdev->dev,
564 " tx_rings[%i]: tx_stats: tx_busy = %lld, tx_done_old = %lld\n",
565 i,
566 tx_ring->tx_stats.tx_busy,
567 tx_ring->tx_stats.tx_done_old);
568 dev_info(&pf->pdev->dev,
569 " tx_rings[%i]: size = %i, dma = 0x%08lx\n",
570 i, tx_ring->size,
571 (long unsigned int)tx_ring->dma);
572 dev_info(&pf->pdev->dev,
573 " tx_rings[%i]: vsi = %p, q_vector = %p\n",
574 i, tx_ring->vsi,
575 tx_ring->q_vector);
576 dev_info(&pf->pdev->dev,
577 " tx_rings[%i]: DCB tc = %d\n",
578 i, tx_ring->dcb_tc);
02e9c290 579 }
9f65e15b 580 rcu_read_unlock();
02e9c290
JB
581 dev_info(&pf->pdev->dev,
582 " work_limit = %d, rx_itr_setting = %d (%s), tx_itr_setting = %d (%s)\n",
583 vsi->work_limit, vsi->rx_itr_setting,
584 ITR_IS_DYNAMIC(vsi->rx_itr_setting) ? "dynamic" : "fixed",
585 vsi->tx_itr_setting,
586 ITR_IS_DYNAMIC(vsi->tx_itr_setting) ? "dynamic" : "fixed");
587 dev_info(&pf->pdev->dev,
588 " max_frame = %d, rx_hdr_len = %d, rx_buf_len = %d dtype = %d\n",
589 vsi->max_frame, vsi->rx_hdr_len, vsi->rx_buf_len, vsi->dtype);
02e9c290
JB
590 dev_info(&pf->pdev->dev,
591 " num_q_vectors = %i, base_vector = %i\n",
592 vsi->num_q_vectors, vsi->base_vector);
593 dev_info(&pf->pdev->dev,
594 " seid = %d, id = %d, uplink_seid = %d\n",
595 vsi->seid, vsi->id, vsi->uplink_seid);
596 dev_info(&pf->pdev->dev,
597 " base_queue = %d, num_queue_pairs = %d, num_desc = %d\n",
598 vsi->base_queue, vsi->num_queue_pairs, vsi->num_desc);
599 dev_info(&pf->pdev->dev, " type = %i\n", vsi->type);
600 dev_info(&pf->pdev->dev,
601 " info: valid_sections = 0x%04x, switch_id = 0x%04x\n",
602 vsi->info.valid_sections, vsi->info.switch_id);
603 dev_info(&pf->pdev->dev,
604 " info: sw_reserved[] = 0x%02x 0x%02x\n",
605 vsi->info.sw_reserved[0], vsi->info.sw_reserved[1]);
606 dev_info(&pf->pdev->dev,
607 " info: sec_flags = 0x%02x, sec_reserved = 0x%02x\n",
608 vsi->info.sec_flags, vsi->info.sec_reserved);
609 dev_info(&pf->pdev->dev,
610 " info: pvid = 0x%04x, fcoe_pvid = 0x%04x, port_vlan_flags = 0x%02x\n",
611 vsi->info.pvid, vsi->info.fcoe_pvid,
612 vsi->info.port_vlan_flags);
613 dev_info(&pf->pdev->dev,
614 " info: pvlan_reserved[] = 0x%02x 0x%02x 0x%02x\n",
615 vsi->info.pvlan_reserved[0], vsi->info.pvlan_reserved[1],
616 vsi->info.pvlan_reserved[2]);
617 dev_info(&pf->pdev->dev,
618 " info: ingress_table = 0x%08x, egress_table = 0x%08x\n",
619 vsi->info.ingress_table, vsi->info.egress_table);
620 dev_info(&pf->pdev->dev,
621 " info: cas_pv_stag = 0x%04x, cas_pv_flags= 0x%02x, cas_pv_reserved = 0x%02x\n",
622 vsi->info.cas_pv_tag, vsi->info.cas_pv_flags,
623 vsi->info.cas_pv_reserved);
624 dev_info(&pf->pdev->dev,
625 " info: queue_mapping[0..7 ] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
626 vsi->info.queue_mapping[0], vsi->info.queue_mapping[1],
627 vsi->info.queue_mapping[2], vsi->info.queue_mapping[3],
628 vsi->info.queue_mapping[4], vsi->info.queue_mapping[5],
629 vsi->info.queue_mapping[6], vsi->info.queue_mapping[7]);
630 dev_info(&pf->pdev->dev,
631 " info: queue_mapping[8..15] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
632 vsi->info.queue_mapping[8], vsi->info.queue_mapping[9],
633 vsi->info.queue_mapping[10], vsi->info.queue_mapping[11],
634 vsi->info.queue_mapping[12], vsi->info.queue_mapping[13],
635 vsi->info.queue_mapping[14], vsi->info.queue_mapping[15]);
636 dev_info(&pf->pdev->dev,
637 " info: tc_mapping[] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
638 vsi->info.tc_mapping[0], vsi->info.tc_mapping[1],
639 vsi->info.tc_mapping[2], vsi->info.tc_mapping[3],
640 vsi->info.tc_mapping[4], vsi->info.tc_mapping[5],
641 vsi->info.tc_mapping[6], vsi->info.tc_mapping[7]);
642 dev_info(&pf->pdev->dev,
643 " info: queueing_opt_flags = 0x%02x queueing_opt_reserved[0..2] = 0x%02x 0x%02x 0x%02x\n",
644 vsi->info.queueing_opt_flags,
645 vsi->info.queueing_opt_reserved[0],
646 vsi->info.queueing_opt_reserved[1],
647 vsi->info.queueing_opt_reserved[2]);
648 dev_info(&pf->pdev->dev,
649 " info: up_enable_bits = 0x%02x\n",
650 vsi->info.up_enable_bits);
651 dev_info(&pf->pdev->dev,
652 " info: sched_reserved = 0x%02x, outer_up_table = 0x%04x\n",
653 vsi->info.sched_reserved, vsi->info.outer_up_table);
654 dev_info(&pf->pdev->dev,
655 " info: cmd_reserved[] = 0x%02x 0x%02x 0x%02x 0x0%02x 0x%02x 0x%02x 0x%02x 0x0%02x\n",
656 vsi->info.cmd_reserved[0], vsi->info.cmd_reserved[1],
657 vsi->info.cmd_reserved[2], vsi->info.cmd_reserved[3],
658 vsi->info.cmd_reserved[4], vsi->info.cmd_reserved[5],
659 vsi->info.cmd_reserved[6], vsi->info.cmd_reserved[7]);
660 dev_info(&pf->pdev->dev,
661 " info: qs_handle[] = 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
662 vsi->info.qs_handle[0], vsi->info.qs_handle[1],
663 vsi->info.qs_handle[2], vsi->info.qs_handle[3],
664 vsi->info.qs_handle[4], vsi->info.qs_handle[5],
665 vsi->info.qs_handle[6], vsi->info.qs_handle[7]);
666 dev_info(&pf->pdev->dev,
667 " info: stat_counter_idx = 0x%04x, sched_id = 0x%04x\n",
668 vsi->info.stat_counter_idx, vsi->info.sched_id);
669 dev_info(&pf->pdev->dev,
670 " 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",
671 vsi->info.resp_reserved[0], vsi->info.resp_reserved[1],
672 vsi->info.resp_reserved[2], vsi->info.resp_reserved[3],
673 vsi->info.resp_reserved[4], vsi->info.resp_reserved[5],
674 vsi->info.resp_reserved[6], vsi->info.resp_reserved[7],
675 vsi->info.resp_reserved[8], vsi->info.resp_reserved[9],
676 vsi->info.resp_reserved[10], vsi->info.resp_reserved[11]);
677 if (vsi->back)
678 dev_info(&pf->pdev->dev, " pf = %p\n", vsi->back);
679 dev_info(&pf->pdev->dev, " idx = %d\n", vsi->idx);
680 dev_info(&pf->pdev->dev,
681 " tc_config: numtc = %d, enabled_tc = 0x%x\n",
682 vsi->tc_config.numtc, vsi->tc_config.enabled_tc);
683 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
684 dev_info(&pf->pdev->dev,
685 " tc_config: tc = %d, qoffset = %d, qcount = %d, netdev_tc = %d\n",
686 i, vsi->tc_config.tc_info[i].qoffset,
687 vsi->tc_config.tc_info[i].qcount,
688 vsi->tc_config.tc_info[i].netdev_tc);
689 }
690 dev_info(&pf->pdev->dev,
691 " bw: bw_limit = %d, bw_max_quanta = %d\n",
692 vsi->bw_limit, vsi->bw_max_quanta);
693 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
694 dev_info(&pf->pdev->dev,
695 " bw[%d]: ets_share_credits = %d, ets_limit_credits = %d, max_quanta = %d\n",
696 i, vsi->bw_ets_share_credits[i],
697 vsi->bw_ets_limit_credits[i],
698 vsi->bw_ets_max_quanta[i]);
699 }
700}
701
702/**
703 * i40e_dbg_dump_aq_desc - handles dump aq_desc write into command datum
704 * @pf: the i40e_pf created in command write
705 **/
706static void i40e_dbg_dump_aq_desc(struct i40e_pf *pf)
707{
708 struct i40e_adminq_ring *ring;
709 struct i40e_hw *hw = &pf->hw;
710 int i;
711
712 /* first the send (command) ring, then the receive (event) ring */
713 dev_info(&pf->pdev->dev, "AdminQ Tx Ring\n");
714 ring = &(hw->aq.asq);
715 for (i = 0; i < ring->count; i++) {
716 struct i40e_aq_desc *d = I40E_ADMINQ_DESC(*ring, i);
717 dev_info(&pf->pdev->dev,
718 " at[%02d] flags=0x%04x op=0x%04x dlen=0x%04x ret=0x%04x cookie_h=0x%08x cookie_l=0x%08x\n",
719 i, d->flags, d->opcode, d->datalen, d->retval,
720 d->cookie_high, d->cookie_low);
721 dev_info(&pf->pdev->dev,
722 " %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
723 d->params.raw[0], d->params.raw[1], d->params.raw[2],
724 d->params.raw[3], d->params.raw[4], d->params.raw[5],
725 d->params.raw[6], d->params.raw[7], d->params.raw[8],
726 d->params.raw[9], d->params.raw[10], d->params.raw[11],
727 d->params.raw[12], d->params.raw[13],
728 d->params.raw[14], d->params.raw[15]);
729 }
730
731 dev_info(&pf->pdev->dev, "AdminQ Rx Ring\n");
732 ring = &(hw->aq.arq);
733 for (i = 0; i < ring->count; i++) {
734 struct i40e_aq_desc *d = I40E_ADMINQ_DESC(*ring, i);
735 dev_info(&pf->pdev->dev,
736 " ar[%02d] flags=0x%04x op=0x%04x dlen=0x%04x ret=0x%04x cookie_h=0x%08x cookie_l=0x%08x\n",
737 i, d->flags, d->opcode, d->datalen, d->retval,
738 d->cookie_high, d->cookie_low);
739 dev_info(&pf->pdev->dev,
740 " %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
741 d->params.raw[0], d->params.raw[1], d->params.raw[2],
742 d->params.raw[3], d->params.raw[4], d->params.raw[5],
743 d->params.raw[6], d->params.raw[7], d->params.raw[8],
744 d->params.raw[9], d->params.raw[10], d->params.raw[11],
745 d->params.raw[12], d->params.raw[13],
746 d->params.raw[14], d->params.raw[15]);
747 }
748}
749
750/**
751 * i40e_dbg_dump_desc - handles dump desc write into command datum
752 * @cnt: number of arguments that the user supplied
753 * @vsi_seid: vsi id entered by user
754 * @ring_id: ring id entered by user
755 * @desc_n: descriptor number entered by user
756 * @pf: the i40e_pf created in command write
757 * @is_rx_ring: true if rx, false if tx
758 **/
759static void i40e_dbg_dump_desc(int cnt, int vsi_seid, int ring_id, int desc_n,
760 struct i40e_pf *pf, bool is_rx_ring)
761{
762 union i40e_rx_desc *ds;
763 struct i40e_ring ring;
764 struct i40e_vsi *vsi;
765 int i;
766
767 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
768 if (!vsi) {
7792fe4f 769 dev_info(&pf->pdev->dev, "vsi %d not found\n", vsi_seid);
02e9c290
JB
770 return;
771 }
772 if (ring_id >= vsi->num_queue_pairs || ring_id < 0) {
773 dev_info(&pf->pdev->dev, "ring %d not found\n", ring_id);
02e9c290
JB
774 return;
775 }
29d0790e
SN
776 if (!vsi->tx_rings) {
777 dev_info(&pf->pdev->dev,
778 "descriptor rings have not been allocated for vsi %d\n",
779 vsi_seid);
780 return;
781 }
02e9c290 782 if (is_rx_ring)
9f65e15b 783 ring = *vsi->rx_rings[ring_id];
02e9c290 784 else
9f65e15b 785 ring = *vsi->tx_rings[ring_id];
02e9c290
JB
786 if (cnt == 2) {
787 dev_info(&pf->pdev->dev, "vsi = %02i %s ring = %02i\n",
788 vsi_seid, is_rx_ring ? "rx" : "tx", ring_id);
789 for (i = 0; i < ring.count; i++) {
790 if (is_rx_ring)
791 ds = I40E_RX_DESC(&ring, i);
792 else
793 ds = (union i40e_rx_desc *)
794 I40E_TX_DESC(&ring, i);
795 if ((sizeof(union i40e_rx_desc) ==
796 sizeof(union i40e_16byte_rx_desc)) || (!is_rx_ring))
797 dev_info(&pf->pdev->dev,
798 " d[%03i] = 0x%016llx 0x%016llx\n", i,
799 ds->read.pkt_addr, ds->read.hdr_addr);
800 else
801 dev_info(&pf->pdev->dev,
802 " d[%03i] = 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n",
803 i, ds->read.pkt_addr,
804 ds->read.hdr_addr,
805 ds->read.rsvd1, ds->read.rsvd2);
806 }
807 } else if (cnt == 3) {
808 if (desc_n >= ring.count || desc_n < 0) {
809 dev_info(&pf->pdev->dev,
810 "descriptor %d not found\n", desc_n);
811 return;
812 }
813 if (is_rx_ring)
814 ds = I40E_RX_DESC(&ring, desc_n);
815 else
816 ds = (union i40e_rx_desc *)I40E_TX_DESC(&ring, desc_n);
817 if ((sizeof(union i40e_rx_desc) ==
818 sizeof(union i40e_16byte_rx_desc)) || (!is_rx_ring))
819 dev_info(&pf->pdev->dev,
820 "vsi = %02i %s ring = %02i d[%03i] = 0x%016llx 0x%016llx\n",
821 vsi_seid, is_rx_ring ? "rx" : "tx", ring_id,
822 desc_n, ds->read.pkt_addr, ds->read.hdr_addr);
823 else
824 dev_info(&pf->pdev->dev,
825 "vsi = %02i rx ring = %02i d[%03i] = 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n",
826 vsi_seid, ring_id,
827 desc_n, ds->read.pkt_addr, ds->read.hdr_addr,
828 ds->read.rsvd1, ds->read.rsvd2);
829 } else {
7792fe4f 830 dev_info(&pf->pdev->dev, "dump desc rx/tx <vsi_seid> <ring_id> [<desc_n>]\n");
02e9c290
JB
831 }
832}
833
834/**
835 * i40e_dbg_dump_vsi_no_seid - handles dump vsi write into command datum
836 * @pf: the i40e_pf created in command write
837 **/
838static void i40e_dbg_dump_vsi_no_seid(struct i40e_pf *pf)
839{
840 int i;
841
842 for (i = 0; i < pf->hw.func_caps.num_vsis; i++)
843 if (pf->vsi[i])
844 dev_info(&pf->pdev->dev, "dump vsi[%d]: %d\n",
845 i, pf->vsi[i]->seid);
846}
847
848/**
849 * i40e_dbg_dump_stats - handles dump stats write into command datum
850 * @pf: the i40e_pf created in command write
851 * @estats: the eth stats structure to be dumped
852 **/
853static void i40e_dbg_dump_eth_stats(struct i40e_pf *pf,
854 struct i40e_eth_stats *estats)
855{
856 dev_info(&pf->pdev->dev, " ethstats:\n");
857 dev_info(&pf->pdev->dev,
858 " rx_bytes = \t%lld \trx_unicast = \t\t%lld \trx_multicast = \t%lld\n",
859 estats->rx_bytes, estats->rx_unicast, estats->rx_multicast);
860 dev_info(&pf->pdev->dev,
861 " rx_broadcast = \t%lld \trx_discards = \t\t%lld \trx_errors = \t%lld\n",
862 estats->rx_broadcast, estats->rx_discards, estats->rx_errors);
863 dev_info(&pf->pdev->dev,
864 " rx_missed = \t%lld \trx_unknown_protocol = \t%lld \ttx_bytes = \t%lld\n",
865 estats->rx_missed, estats->rx_unknown_protocol,
866 estats->tx_bytes);
867 dev_info(&pf->pdev->dev,
868 " tx_unicast = \t%lld \ttx_multicast = \t\t%lld \ttx_broadcast = \t%lld\n",
869 estats->tx_unicast, estats->tx_multicast, estats->tx_broadcast);
870 dev_info(&pf->pdev->dev,
871 " tx_discards = \t%lld \ttx_errors = \t\t%lld\n",
872 estats->tx_discards, estats->tx_errors);
873}
874
875/**
876 * i40e_dbg_dump_stats - handles dump stats write into command datum
877 * @pf: the i40e_pf created in command write
878 * @stats: the stats structure to be dumped
879 **/
880static void i40e_dbg_dump_stats(struct i40e_pf *pf,
881 struct i40e_hw_port_stats *stats)
882{
883 int i;
884
885 dev_info(&pf->pdev->dev, " stats:\n");
886 dev_info(&pf->pdev->dev,
887 " crc_errors = \t\t%lld \tillegal_bytes = \t%lld \terror_bytes = \t\t%lld\n",
888 stats->crc_errors, stats->illegal_bytes, stats->error_bytes);
889 dev_info(&pf->pdev->dev,
890 " mac_local_faults = \t%lld \tmac_remote_faults = \t%lld \trx_length_errors = \t%lld\n",
891 stats->mac_local_faults, stats->mac_remote_faults,
892 stats->rx_length_errors);
893 dev_info(&pf->pdev->dev,
894 " link_xon_rx = \t\t%lld \tlink_xoff_rx = \t\t%lld \tlink_xon_tx = \t\t%lld\n",
895 stats->link_xon_rx, stats->link_xoff_rx, stats->link_xon_tx);
896 dev_info(&pf->pdev->dev,
897 " link_xoff_tx = \t\t%lld \trx_size_64 = \t\t%lld \trx_size_127 = \t\t%lld\n",
898 stats->link_xoff_tx, stats->rx_size_64, stats->rx_size_127);
899 dev_info(&pf->pdev->dev,
900 " rx_size_255 = \t\t%lld \trx_size_511 = \t\t%lld \trx_size_1023 = \t\t%lld\n",
901 stats->rx_size_255, stats->rx_size_511, stats->rx_size_1023);
902 dev_info(&pf->pdev->dev,
903 " rx_size_big = \t\t%lld \trx_undersize = \t\t%lld \trx_jabber = \t\t%lld\n",
904 stats->rx_size_big, stats->rx_undersize, stats->rx_jabber);
905 dev_info(&pf->pdev->dev,
906 " rx_fragments = \t\t%lld \trx_oversize = \t\t%lld \ttx_size_64 = \t\t%lld\n",
907 stats->rx_fragments, stats->rx_oversize, stats->tx_size_64);
908 dev_info(&pf->pdev->dev,
909 " tx_size_127 = \t\t%lld \ttx_size_255 = \t\t%lld \ttx_size_511 = \t\t%lld\n",
910 stats->tx_size_127, stats->tx_size_255, stats->tx_size_511);
911 dev_info(&pf->pdev->dev,
912 " tx_size_1023 = \t\t%lld \ttx_size_big = \t\t%lld \tmac_short_packet_dropped = \t%lld\n",
913 stats->tx_size_1023, stats->tx_size_big,
914 stats->mac_short_packet_dropped);
915 for (i = 0; i < 8; i += 4) {
916 dev_info(&pf->pdev->dev,
917 " priority_xon_rx[%d] = \t%lld \t[%d] = \t%lld \t[%d] = \t%lld \t[%d] = \t%lld\n",
918 i, stats->priority_xon_rx[i],
919 i+1, stats->priority_xon_rx[i+1],
920 i+2, stats->priority_xon_rx[i+2],
921 i+3, stats->priority_xon_rx[i+3]);
922 }
923 for (i = 0; i < 8; i += 4) {
924 dev_info(&pf->pdev->dev,
925 " priority_xoff_rx[%d] = \t%lld \t[%d] = \t%lld \t[%d] = \t%lld \t[%d] = \t%lld\n",
926 i, stats->priority_xoff_rx[i],
927 i+1, stats->priority_xoff_rx[i+1],
928 i+2, stats->priority_xoff_rx[i+2],
929 i+3, stats->priority_xoff_rx[i+3]);
930 }
931 for (i = 0; i < 8; i += 4) {
932 dev_info(&pf->pdev->dev,
933 " priority_xon_tx[%d] = \t%lld \t[%d] = \t%lld \t[%d] = \t%lld \t[%d] = \t%lld\n",
934 i, stats->priority_xon_tx[i],
935 i+1, stats->priority_xon_tx[i+1],
936 i+2, stats->priority_xon_tx[i+2],
937 i+3, stats->priority_xon_rx[i+3]);
938 }
939 for (i = 0; i < 8; i += 4) {
940 dev_info(&pf->pdev->dev,
941 " priority_xoff_tx[%d] = \t%lld \t[%d] = \t%lld \t[%d] = \t%lld \t[%d] = \t%lld\n",
942 i, stats->priority_xoff_tx[i],
943 i+1, stats->priority_xoff_tx[i+1],
944 i+2, stats->priority_xoff_tx[i+2],
945 i+3, stats->priority_xoff_tx[i+3]);
946 }
947 for (i = 0; i < 8; i += 4) {
948 dev_info(&pf->pdev->dev,
949 " priority_xon_2_xoff[%d] = \t%lld \t[%d] = \t%lld \t[%d] = \t%lld \t[%d] = \t%lld\n",
950 i, stats->priority_xon_2_xoff[i],
951 i+1, stats->priority_xon_2_xoff[i+1],
952 i+2, stats->priority_xon_2_xoff[i+2],
953 i+3, stats->priority_xon_2_xoff[i+3]);
954 }
955
956 i40e_dbg_dump_eth_stats(pf, &stats->eth);
957}
958
959/**
960 * i40e_dbg_dump_veb_seid - handles dump stats of a single given veb
961 * @pf: the i40e_pf created in command write
962 * @seid: the seid the user put in
963 **/
964static void i40e_dbg_dump_veb_seid(struct i40e_pf *pf, int seid)
965{
966 struct i40e_veb *veb;
967
968 if ((seid < I40E_BASE_VEB_SEID) ||
969 (seid >= (I40E_MAX_VEB + I40E_BASE_VEB_SEID))) {
970 dev_info(&pf->pdev->dev, "%d: bad seid\n", seid);
971 return;
972 }
973
974 veb = i40e_dbg_find_veb(pf, seid);
975 if (!veb) {
976 dev_info(&pf->pdev->dev,
977 "%d: can't find veb\n", seid);
978 return;
979 }
980 dev_info(&pf->pdev->dev,
981 "veb idx=%d,%d stats_ic=%d seid=%d uplink=%d\n",
982 veb->idx, veb->veb_idx, veb->stats_idx, veb->seid,
983 veb->uplink_seid);
984 i40e_dbg_dump_eth_stats(pf, &veb->stats);
985}
986
987/**
988 * i40e_dbg_dump_veb_all - dumps all known veb's stats
989 * @pf: the i40e_pf created in command write
990 **/
991static void i40e_dbg_dump_veb_all(struct i40e_pf *pf)
992{
993 struct i40e_veb *veb;
994 int i;
995
996 for (i = 0; i < I40E_MAX_VEB; i++) {
997 veb = pf->veb[i];
998 if (veb)
999 i40e_dbg_dump_veb_seid(pf, veb->seid);
1000 }
1001}
1002
1003#define I40E_MAX_DEBUG_OUT_BUFFER (4096*4)
1004/**
1005 * i40e_dbg_command_write - write into command datum
1006 * @filp: the opened file
1007 * @buffer: where to find the user's data
1008 * @count: the length of the user's data
1009 * @ppos: file position offset
1010 **/
1011static ssize_t i40e_dbg_command_write(struct file *filp,
1012 const char __user *buffer,
1013 size_t count, loff_t *ppos)
1014{
1015 struct i40e_pf *pf = filp->private_data;
004173cb 1016 char *cmd_buf, *cmd_buf_tmp;
02e9c290
JB
1017 int bytes_not_copied;
1018 struct i40e_vsi *vsi;
02e9c290
JB
1019 int vsi_seid;
1020 int veb_seid;
1021 int cnt;
1022
1023 /* don't allow partial writes */
1024 if (*ppos != 0)
1025 return 0;
1026
1027 cmd_buf = kzalloc(count + 1, GFP_KERNEL);
1028 if (!cmd_buf)
1029 return count;
1030 bytes_not_copied = copy_from_user(cmd_buf, buffer, count);
1031 if (bytes_not_copied < 0)
1032 return bytes_not_copied;
1033 if (bytes_not_copied > 0)
1034 count -= bytes_not_copied;
1035 cmd_buf[count] = '\0';
1036
004173cb
JB
1037 cmd_buf_tmp = strchr(cmd_buf, '\n');
1038 if (cmd_buf_tmp) {
1039 *cmd_buf_tmp = '\0';
1040 count = cmd_buf_tmp - cmd_buf + 1;
1041 }
1042
02e9c290
JB
1043 if (strncmp(cmd_buf, "add vsi", 7) == 0) {
1044 vsi_seid = -1;
1045 cnt = sscanf(&cmd_buf[7], "%i", &vsi_seid);
1046 if (cnt == 0) {
1047 /* default to PF VSI */
1048 vsi_seid = pf->vsi[pf->lan_vsi]->seid;
1049 } else if (vsi_seid < 0) {
1050 dev_info(&pf->pdev->dev, "add VSI %d: bad vsi seid\n",
1051 vsi_seid);
1052 goto command_write_done;
1053 }
1054
1055 vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, vsi_seid, 0);
1056 if (vsi)
1057 dev_info(&pf->pdev->dev, "added VSI %d to relay %d\n",
1058 vsi->seid, vsi->uplink_seid);
1059 else
1060 dev_info(&pf->pdev->dev, "'%s' failed\n", cmd_buf);
1061
1062 } else if (strncmp(cmd_buf, "del vsi", 7) == 0) {
1063 sscanf(&cmd_buf[7], "%i", &vsi_seid);
1064 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1065 if (!vsi) {
1066 dev_info(&pf->pdev->dev, "del VSI %d: seid not found\n",
1067 vsi_seid);
1068 goto command_write_done;
1069 }
1070
1071 dev_info(&pf->pdev->dev, "deleting VSI %d\n", vsi_seid);
1072 i40e_vsi_release(vsi);
1073
1074 } else if (strncmp(cmd_buf, "add relay", 9) == 0) {
1075 struct i40e_veb *veb;
1076 int uplink_seid, i;
1077
1078 cnt = sscanf(&cmd_buf[9], "%i %i", &uplink_seid, &vsi_seid);
1079 if (cnt != 2) {
1080 dev_info(&pf->pdev->dev,
1081 "add relay: bad command string, cnt=%d\n",
1082 cnt);
1083 goto command_write_done;
1084 } else if (uplink_seid < 0) {
1085 dev_info(&pf->pdev->dev,
1086 "add relay %d: bad uplink seid\n",
1087 uplink_seid);
1088 goto command_write_done;
1089 }
1090
1091 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1092 if (!vsi) {
1093 dev_info(&pf->pdev->dev,
1094 "add relay: vsi VSI %d not found\n", vsi_seid);
1095 goto command_write_done;
1096 }
1097
1098 for (i = 0; i < I40E_MAX_VEB; i++)
1099 if (pf->veb[i] && pf->veb[i]->seid == uplink_seid)
1100 break;
1101 if (i >= I40E_MAX_VEB && uplink_seid != 0 &&
1102 uplink_seid != pf->mac_seid) {
1103 dev_info(&pf->pdev->dev,
1104 "add relay: relay uplink %d not found\n",
1105 uplink_seid);
1106 goto command_write_done;
1107 }
1108
1109 veb = i40e_veb_setup(pf, 0, uplink_seid, vsi_seid,
1110 vsi->tc_config.enabled_tc);
1111 if (veb)
1112 dev_info(&pf->pdev->dev, "added relay %d\n", veb->seid);
1113 else
1114 dev_info(&pf->pdev->dev, "add relay failed\n");
1115
1116 } else if (strncmp(cmd_buf, "del relay", 9) == 0) {
1117 int i;
1118 cnt = sscanf(&cmd_buf[9], "%i", &veb_seid);
1119 if (cnt != 1) {
1120 dev_info(&pf->pdev->dev,
1121 "del relay: bad command string, cnt=%d\n",
1122 cnt);
1123 goto command_write_done;
1124 } else if (veb_seid < 0) {
1125 dev_info(&pf->pdev->dev,
1126 "del relay %d: bad relay seid\n", veb_seid);
1127 goto command_write_done;
1128 }
1129
1130 /* find the veb */
1131 for (i = 0; i < I40E_MAX_VEB; i++)
1132 if (pf->veb[i] && pf->veb[i]->seid == veb_seid)
1133 break;
1134 if (i >= I40E_MAX_VEB) {
1135 dev_info(&pf->pdev->dev,
1136 "del relay: relay %d not found\n", veb_seid);
1137 goto command_write_done;
1138 }
1139
1140 dev_info(&pf->pdev->dev, "deleting relay %d\n", veb_seid);
1141 i40e_veb_release(pf->veb[i]);
1142
1143 } else if (strncmp(cmd_buf, "add macaddr", 11) == 0) {
02e9c290 1144 struct i40e_mac_filter *f;
738a9e9b
SN
1145 int vlan = 0;
1146 u8 ma[6];
02e9c290
JB
1147 int ret;
1148
1149 cnt = sscanf(&cmd_buf[11],
1150 "%i %hhx:%hhx:%hhx:%hhx:%hhx:%hhx %i",
1151 &vsi_seid,
1152 &ma[0], &ma[1], &ma[2], &ma[3], &ma[4], &ma[5],
1153 &vlan);
1154 if (cnt == 7) {
1155 vlan = 0;
1156 } else if (cnt != 8) {
1157 dev_info(&pf->pdev->dev,
1158 "add macaddr: bad command string, cnt=%d\n",
1159 cnt);
1160 goto command_write_done;
1161 }
1162
1163 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1164 if (!vsi) {
1165 dev_info(&pf->pdev->dev,
1166 "add macaddr: VSI %d not found\n", vsi_seid);
1167 goto command_write_done;
1168 }
1169
1170 f = i40e_add_filter(vsi, ma, vlan, false, false);
1171 ret = i40e_sync_vsi_filters(vsi);
1172 if (f && !ret)
1173 dev_info(&pf->pdev->dev,
1174 "add macaddr: %pM vlan=%d added to VSI %d\n",
1175 ma, vlan, vsi_seid);
1176 else
1177 dev_info(&pf->pdev->dev,
1178 "add macaddr: %pM vlan=%d to VSI %d failed, f=%p ret=%d\n",
1179 ma, vlan, vsi_seid, f, ret);
1180
1181 } else if (strncmp(cmd_buf, "del macaddr", 11) == 0) {
02e9c290 1182 int vlan = 0;
738a9e9b 1183 u8 ma[6];
02e9c290
JB
1184 int ret;
1185
1186 cnt = sscanf(&cmd_buf[11],
1187 "%i %hhx:%hhx:%hhx:%hhx:%hhx:%hhx %i",
1188 &vsi_seid,
1189 &ma[0], &ma[1], &ma[2], &ma[3], &ma[4], &ma[5],
1190 &vlan);
1191 if (cnt == 7) {
1192 vlan = 0;
1193 } else if (cnt != 8) {
1194 dev_info(&pf->pdev->dev,
1195 "del macaddr: bad command string, cnt=%d\n",
1196 cnt);
1197 goto command_write_done;
1198 }
1199
1200 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1201 if (!vsi) {
1202 dev_info(&pf->pdev->dev,
1203 "del macaddr: VSI %d not found\n", vsi_seid);
1204 goto command_write_done;
1205 }
1206
1207 i40e_del_filter(vsi, ma, vlan, false, false);
1208 ret = i40e_sync_vsi_filters(vsi);
1209 if (!ret)
1210 dev_info(&pf->pdev->dev,
1211 "del macaddr: %pM vlan=%d removed from VSI %d\n",
1212 ma, vlan, vsi_seid);
1213 else
1214 dev_info(&pf->pdev->dev,
1215 "del macaddr: %pM vlan=%d from VSI %d failed, ret=%d\n",
1216 ma, vlan, vsi_seid, ret);
1217
1218 } else if (strncmp(cmd_buf, "add pvid", 8) == 0) {
02e9c290 1219 i40e_status ret;
738a9e9b
SN
1220 u16 vid;
1221 int v;
02e9c290
JB
1222
1223 cnt = sscanf(&cmd_buf[8], "%i %u", &vsi_seid, &v);
1224 if (cnt != 2) {
1225 dev_info(&pf->pdev->dev,
1226 "add pvid: bad command string, cnt=%d\n", cnt);
1227 goto command_write_done;
1228 }
1229
1230 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1231 if (!vsi) {
1232 dev_info(&pf->pdev->dev, "add pvid: VSI %d not found\n",
1233 vsi_seid);
1234 goto command_write_done;
1235 }
1236
1237 vid = (unsigned)v;
1238 ret = i40e_vsi_add_pvid(vsi, vid);
1239 if (!ret)
1240 dev_info(&pf->pdev->dev,
1241 "add pvid: %d added to VSI %d\n",
1242 vid, vsi_seid);
1243 else
1244 dev_info(&pf->pdev->dev,
1245 "add pvid: %d to VSI %d failed, ret=%d\n",
1246 vid, vsi_seid, ret);
1247
1248 } else if (strncmp(cmd_buf, "del pvid", 8) == 0) {
1249
1250 cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid);
1251 if (cnt != 1) {
1252 dev_info(&pf->pdev->dev,
1253 "del pvid: bad command string, cnt=%d\n",
1254 cnt);
1255 goto command_write_done;
1256 }
1257
1258 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1259 if (!vsi) {
1260 dev_info(&pf->pdev->dev,
1261 "del pvid: VSI %d not found\n", vsi_seid);
1262 goto command_write_done;
1263 }
1264
1265 i40e_vsi_remove_pvid(vsi);
1266 dev_info(&pf->pdev->dev,
1267 "del pvid: removed from VSI %d\n", vsi_seid);
1268
1269 } else if (strncmp(cmd_buf, "dump", 4) == 0) {
1270 if (strncmp(&cmd_buf[5], "switch", 6) == 0) {
1271 i40e_fetch_switch_configuration(pf, true);
1272 } else if (strncmp(&cmd_buf[5], "vsi", 3) == 0) {
1273 cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid);
1274 if (cnt > 0)
1275 i40e_dbg_dump_vsi_seid(pf, vsi_seid);
1276 else
1277 i40e_dbg_dump_vsi_no_seid(pf);
1278 } else if (strncmp(&cmd_buf[5], "veb", 3) == 0) {
1279 cnt = sscanf(&cmd_buf[8], "%i", &vsi_seid);
1280 if (cnt > 0)
1281 i40e_dbg_dump_veb_seid(pf, vsi_seid);
1282 else
1283 i40e_dbg_dump_veb_all(pf);
1284 } else if (strncmp(&cmd_buf[5], "desc", 4) == 0) {
1285 int ring_id, desc_n;
1286 if (strncmp(&cmd_buf[10], "rx", 2) == 0) {
1287 cnt = sscanf(&cmd_buf[12], "%i %i %i",
1288 &vsi_seid, &ring_id, &desc_n);
1289 i40e_dbg_dump_desc(cnt, vsi_seid, ring_id,
1290 desc_n, pf, true);
1291 } else if (strncmp(&cmd_buf[10], "tx", 2)
1292 == 0) {
1293 cnt = sscanf(&cmd_buf[12], "%i %i %i",
1294 &vsi_seid, &ring_id, &desc_n);
1295 i40e_dbg_dump_desc(cnt, vsi_seid, ring_id,
1296 desc_n, pf, false);
1297 } else if (strncmp(&cmd_buf[10], "aq", 2) == 0) {
1298 i40e_dbg_dump_aq_desc(pf);
1299 } else {
1300 dev_info(&pf->pdev->dev,
1301 "dump desc tx <vsi_seid> <ring_id> [<desc_n>]\n");
1302 dev_info(&pf->pdev->dev,
1303 "dump desc rx <vsi_seid> <ring_id> [<desc_n>]\n");
1304 dev_info(&pf->pdev->dev, "dump desc aq\n");
1305 }
1306 } else if (strncmp(&cmd_buf[5], "stats", 5) == 0) {
1307 dev_info(&pf->pdev->dev, "pf stats:\n");
1308 i40e_dbg_dump_stats(pf, &pf->stats);
1309 dev_info(&pf->pdev->dev, "pf stats_offsets:\n");
1310 i40e_dbg_dump_stats(pf, &pf->stats_offsets);
1311 } else if (strncmp(&cmd_buf[5], "reset stats", 11) == 0) {
1312 dev_info(&pf->pdev->dev,
1313 "core reset count: %d\n", pf->corer_count);
1314 dev_info(&pf->pdev->dev,
1315 "global reset count: %d\n", pf->globr_count);
1316 dev_info(&pf->pdev->dev,
1317 "emp reset count: %d\n", pf->empr_count);
1318 dev_info(&pf->pdev->dev,
1319 "pf reset count: %d\n", pf->pfr_count);
1320 } else if (strncmp(&cmd_buf[5], "port", 4) == 0) {
1321 struct i40e_aqc_query_port_ets_config_resp *bw_data;
1322 struct i40e_dcbx_config *cfg =
1323 &pf->hw.local_dcbx_config;
1324 struct i40e_dcbx_config *r_cfg =
1325 &pf->hw.remote_dcbx_config;
1326 int i, ret;
1327
1328 bw_data = kzalloc(sizeof(
1329 struct i40e_aqc_query_port_ets_config_resp),
1330 GFP_KERNEL);
1331 if (!bw_data) {
1332 ret = -ENOMEM;
1333 goto command_write_done;
1334 }
1335
1336 ret = i40e_aq_query_port_ets_config(&pf->hw,
1337 pf->mac_seid,
1338 bw_data, NULL);
1339 if (ret) {
1340 dev_info(&pf->pdev->dev,
1341 "Query Port ETS Config AQ command failed =0x%x\n",
1342 pf->hw.aq.asq_last_status);
1343 kfree(bw_data);
1344 bw_data = NULL;
1345 goto command_write_done;
1346 }
1347 dev_info(&pf->pdev->dev,
1348 "port bw: tc_valid=0x%x tc_strict_prio=0x%x, tc_bw_max=0x%04x,0x%04x\n",
1349 bw_data->tc_valid_bits,
1350 bw_data->tc_strict_priority_bits,
1351 le16_to_cpu(bw_data->tc_bw_max[0]),
1352 le16_to_cpu(bw_data->tc_bw_max[1]));
1353 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1354 dev_info(&pf->pdev->dev, "port bw: tc_bw_share=%d tc_bw_limit=%d\n",
1355 bw_data->tc_bw_share_credits[i],
1356 le16_to_cpu(bw_data->tc_bw_limits[i]));
1357 }
1358
1359 kfree(bw_data);
1360 bw_data = NULL;
1361
1362 dev_info(&pf->pdev->dev,
1363 "port ets_cfg: willing=%d cbs=%d, maxtcs=%d\n",
1364 cfg->etscfg.willing, cfg->etscfg.cbs,
1365 cfg->etscfg.maxtcs);
1366 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1367 dev_info(&pf->pdev->dev, "port ets_cfg: %d prio_tc=%d tcbw=%d tctsa=%d\n",
1368 i, cfg->etscfg.prioritytable[i],
1369 cfg->etscfg.tcbwtable[i],
1370 cfg->etscfg.tsatable[i]);
1371 }
1372 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1373 dev_info(&pf->pdev->dev, "port ets_rec: %d prio_tc=%d tcbw=%d tctsa=%d\n",
1374 i, cfg->etsrec.prioritytable[i],
1375 cfg->etsrec.tcbwtable[i],
1376 cfg->etsrec.tsatable[i]);
1377 }
1378 dev_info(&pf->pdev->dev,
1379 "port pfc_cfg: willing=%d mbc=%d, pfccap=%d pfcenable=0x%x\n",
1380 cfg->pfc.willing, cfg->pfc.mbc,
1381 cfg->pfc.pfccap, cfg->pfc.pfcenable);
1382 dev_info(&pf->pdev->dev,
1383 "port app_table: num_apps=%d\n", cfg->numapps);
1384 for (i = 0; i < cfg->numapps; i++) {
1385 dev_info(&pf->pdev->dev, "port app_table: %d prio=%d selector=%d protocol=0x%x\n",
1386 i, cfg->app[i].priority,
1387 cfg->app[i].selector,
1388 cfg->app[i].protocolid);
1389 }
1390 /* Peer TLV DCBX data */
1391 dev_info(&pf->pdev->dev,
1392 "remote port ets_cfg: willing=%d cbs=%d, maxtcs=%d\n",
1393 r_cfg->etscfg.willing,
1394 r_cfg->etscfg.cbs, r_cfg->etscfg.maxtcs);
1395 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1396 dev_info(&pf->pdev->dev, "remote port ets_cfg: %d prio_tc=%d tcbw=%d tctsa=%d\n",
1397 i, r_cfg->etscfg.prioritytable[i],
1398 r_cfg->etscfg.tcbwtable[i],
1399 r_cfg->etscfg.tsatable[i]);
1400 }
1401 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1402 dev_info(&pf->pdev->dev, "remote port ets_rec: %d prio_tc=%d tcbw=%d tctsa=%d\n",
1403 i, r_cfg->etsrec.prioritytable[i],
1404 r_cfg->etsrec.tcbwtable[i],
1405 r_cfg->etsrec.tsatable[i]);
1406 }
1407 dev_info(&pf->pdev->dev,
1408 "remote port pfc_cfg: willing=%d mbc=%d, pfccap=%d pfcenable=0x%x\n",
1409 r_cfg->pfc.willing,
1410 r_cfg->pfc.mbc,
1411 r_cfg->pfc.pfccap,
1412 r_cfg->pfc.pfcenable);
1413 dev_info(&pf->pdev->dev,
1414 "remote port app_table: num_apps=%d\n",
1415 r_cfg->numapps);
1416 for (i = 0; i < r_cfg->numapps; i++) {
1417 dev_info(&pf->pdev->dev, "remote port app_table: %d prio=%d selector=%d protocol=0x%x\n",
1418 i, r_cfg->app[i].priority,
1419 r_cfg->app[i].selector,
1420 r_cfg->app[i].protocolid);
1421 }
1422 } else {
1423 dev_info(&pf->pdev->dev,
1424 "dump desc tx <vsi_seid> <ring_id> [<desc_n>], dump desc rx <vsi_seid> <ring_id> [<desc_n>],\n");
1425 dev_info(&pf->pdev->dev, "dump switch, dump vsi [seid] or\n");
1426 dev_info(&pf->pdev->dev, "dump stats\n");
1427 dev_info(&pf->pdev->dev, "dump reset stats\n");
1428 dev_info(&pf->pdev->dev, "dump port\n");
1429 dev_info(&pf->pdev->dev,
1430 "dump debug fwdata <cluster_id> <table_id> <index>\n");
1431 }
1432
1433 } else if (strncmp(cmd_buf, "msg_enable", 10) == 0) {
1434 u32 level;
1435 cnt = sscanf(&cmd_buf[10], "%i", &level);
1436 if (cnt) {
1437 if (I40E_DEBUG_USER & level) {
1438 pf->hw.debug_mask = level;
1439 dev_info(&pf->pdev->dev,
1440 "set hw.debug_mask = 0x%08x\n",
1441 pf->hw.debug_mask);
1442 }
1443 pf->msg_enable = level;
1444 dev_info(&pf->pdev->dev, "set msg_enable = 0x%08x\n",
1445 pf->msg_enable);
1446 } else {
1447 dev_info(&pf->pdev->dev, "msg_enable = 0x%08x\n",
1448 pf->msg_enable);
1449 }
1450 } else if (strncmp(cmd_buf, "pfr", 3) == 0) {
1451 dev_info(&pf->pdev->dev, "forcing PFR\n");
23326186 1452 i40e_do_reset_safe(pf, (1 << __I40E_PF_RESET_REQUESTED));
02e9c290
JB
1453
1454 } else if (strncmp(cmd_buf, "corer", 5) == 0) {
1455 dev_info(&pf->pdev->dev, "forcing CoreR\n");
23326186 1456 i40e_do_reset_safe(pf, (1 << __I40E_CORE_RESET_REQUESTED));
02e9c290
JB
1457
1458 } else if (strncmp(cmd_buf, "globr", 5) == 0) {
1459 dev_info(&pf->pdev->dev, "forcing GlobR\n");
23326186 1460 i40e_do_reset_safe(pf, (1 << __I40E_GLOBAL_RESET_REQUESTED));
02e9c290 1461
7823fe34
SN
1462 } else if (strncmp(cmd_buf, "empr", 4) == 0) {
1463 dev_info(&pf->pdev->dev, "forcing EMPR\n");
23326186 1464 i40e_do_reset_safe(pf, (1 << __I40E_EMP_RESET_REQUESTED));
7823fe34 1465
02e9c290
JB
1466 } else if (strncmp(cmd_buf, "read", 4) == 0) {
1467 u32 address;
1468 u32 value;
2706a20e 1469 cnt = sscanf(&cmd_buf[4], "%i", &address);
02e9c290
JB
1470 if (cnt != 1) {
1471 dev_info(&pf->pdev->dev, "read <reg>\n");
1472 goto command_write_done;
1473 }
1474
1475 /* check the range on address */
1476 if (address >= I40E_MAX_REGISTER) {
1477 dev_info(&pf->pdev->dev, "read reg address 0x%08x too large\n",
1478 address);
1479 goto command_write_done;
1480 }
1481
1482 value = rd32(&pf->hw, address);
1483 dev_info(&pf->pdev->dev, "read: 0x%08x = 0x%08x\n",
1484 address, value);
1485
1486 } else if (strncmp(cmd_buf, "write", 5) == 0) {
1487 u32 address, value;
2706a20e 1488 cnt = sscanf(&cmd_buf[5], "%i %i", &address, &value);
02e9c290
JB
1489 if (cnt != 2) {
1490 dev_info(&pf->pdev->dev, "write <reg> <value>\n");
1491 goto command_write_done;
1492 }
1493
1494 /* check the range on address */
1495 if (address >= I40E_MAX_REGISTER) {
1496 dev_info(&pf->pdev->dev, "write reg address 0x%08x too large\n",
1497 address);
1498 goto command_write_done;
1499 }
1500 wr32(&pf->hw, address, value);
1501 value = rd32(&pf->hw, address);
1502 dev_info(&pf->pdev->dev, "write: 0x%08x = 0x%08x\n",
1503 address, value);
1504 } else if (strncmp(cmd_buf, "clear_stats", 11) == 0) {
1505 if (strncmp(&cmd_buf[12], "vsi", 3) == 0) {
2706a20e 1506 cnt = sscanf(&cmd_buf[15], "%i", &vsi_seid);
02e9c290
JB
1507 if (cnt == 0) {
1508 int i;
1509 for (i = 0; i < pf->hw.func_caps.num_vsis; i++)
1510 i40e_vsi_reset_stats(pf->vsi[i]);
1511 dev_info(&pf->pdev->dev, "vsi clear stats called for all vsi's\n");
1512 } else if (cnt == 1) {
1513 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1514 if (!vsi) {
1515 dev_info(&pf->pdev->dev,
1516 "clear_stats vsi: bad vsi %d\n",
1517 vsi_seid);
1518 goto command_write_done;
1519 }
1520 i40e_vsi_reset_stats(vsi);
1521 dev_info(&pf->pdev->dev,
1522 "vsi clear stats called for vsi %d\n",
1523 vsi_seid);
1524 } else {
1525 dev_info(&pf->pdev->dev, "clear_stats vsi [seid]\n");
1526 }
1527 } else if (strncmp(&cmd_buf[12], "pf", 2) == 0) {
1528 i40e_pf_reset_stats(pf);
1529 dev_info(&pf->pdev->dev, "pf clear stats called\n");
1530 } else {
1531 dev_info(&pf->pdev->dev, "clear_stats vsi [seid] or clear_stats pf\n");
1532 }
1533 } else if ((strncmp(cmd_buf, "add fd_filter", 13) == 0) ||
1534 (strncmp(cmd_buf, "rem fd_filter", 13) == 0)) {
1535 struct i40e_fdir_data fd_data;
02e9c290
JB
1536 u16 packet_len, i, j = 0;
1537 char *asc_packet;
1538 bool add = false;
738a9e9b 1539 int ret;
02e9c290
JB
1540
1541 asc_packet = kzalloc(I40E_FDIR_MAX_RAW_PACKET_LOOKUP,
1542 GFP_KERNEL);
1543 if (!asc_packet)
1544 goto command_write_done;
1545
1546 fd_data.raw_packet = kzalloc(I40E_FDIR_MAX_RAW_PACKET_LOOKUP,
1547 GFP_KERNEL);
1548
1549 if (!fd_data.raw_packet) {
1550 kfree(asc_packet);
1551 asc_packet = NULL;
1552 goto command_write_done;
1553 }
1554
1555 if (strncmp(cmd_buf, "add", 3) == 0)
1556 add = true;
1557 cnt = sscanf(&cmd_buf[13],
1558 "%hx %2hhx %2hhx %hx %2hhx %2hhx %hx %x %hd %512s",
1559 &fd_data.q_index,
1560 &fd_data.flex_off, &fd_data.pctype,
1561 &fd_data.dest_vsi, &fd_data.dest_ctl,
1562 &fd_data.fd_status, &fd_data.cnt_index,
1563 &fd_data.fd_id, &packet_len, asc_packet);
1564 if (cnt != 10) {
1565 dev_info(&pf->pdev->dev,
1566 "program fd_filter: bad command string, cnt=%d\n",
1567 cnt);
1568 kfree(asc_packet);
1569 asc_packet = NULL;
1570 kfree(fd_data.raw_packet);
1571 goto command_write_done;
1572 }
1573
1574 /* fix packet length if user entered 0 */
1575 if (packet_len == 0)
1576 packet_len = I40E_FDIR_MAX_RAW_PACKET_LOOKUP;
1577
1578 /* make sure to check the max as well */
1579 packet_len = min_t(u16,
1580 packet_len, I40E_FDIR_MAX_RAW_PACKET_LOOKUP);
1581
02e9c290
JB
1582 for (i = 0; i < packet_len; i++) {
1583 sscanf(&asc_packet[j], "%2hhx ",
1584 &fd_data.raw_packet[i]);
1585 j += 3;
02e9c290 1586 }
3753cb24
NP
1587 dev_info(&pf->pdev->dev, "FD raw packet dump\n");
1588 print_hex_dump(KERN_INFO, "FD raw packet: ",
1589 DUMP_PREFIX_OFFSET, 16, 1,
1590 fd_data.raw_packet, packet_len, true);
02e9c290
JB
1591 ret = i40e_program_fdir_filter(&fd_data, pf, add);
1592 if (!ret) {
1593 dev_info(&pf->pdev->dev, "Filter command send Status : Success\n");
1594 } else {
1595 dev_info(&pf->pdev->dev,
1596 "Filter command send failed %d\n", ret);
1597 }
1598 kfree(fd_data.raw_packet);
1599 fd_data.raw_packet = NULL;
1600 kfree(asc_packet);
1601 asc_packet = NULL;
1602 } else if (strncmp(cmd_buf, "lldp", 4) == 0) {
1603 if (strncmp(&cmd_buf[5], "stop", 4) == 0) {
1604 int ret;
1605 ret = i40e_aq_stop_lldp(&pf->hw, false, NULL);
1606 if (ret) {
1607 dev_info(&pf->pdev->dev,
1608 "Stop LLDP AQ command failed =0x%x\n",
1609 pf->hw.aq.asq_last_status);
1610 goto command_write_done;
1611 }
1612 } else if (strncmp(&cmd_buf[5], "start", 5) == 0) {
1613 int ret;
1614 ret = i40e_aq_start_lldp(&pf->hw, NULL);
1615 if (ret) {
1616 dev_info(&pf->pdev->dev,
1617 "Start LLDP AQ command failed =0x%x\n",
1618 pf->hw.aq.asq_last_status);
1619 goto command_write_done;
1620 }
1621 } else if (strncmp(&cmd_buf[5],
1622 "get local", 9) == 0) {
738a9e9b 1623 u16 llen, rlen;
3753cb24 1624 int ret;
02e9c290 1625 u8 *buff;
02e9c290
JB
1626 buff = kzalloc(I40E_LLDPDU_SIZE, GFP_KERNEL);
1627 if (!buff)
1628 goto command_write_done;
1629
1630 ret = i40e_aq_get_lldp_mib(&pf->hw, 0,
1631 I40E_AQ_LLDP_MIB_LOCAL,
1632 buff, I40E_LLDPDU_SIZE,
1633 &llen, &rlen, NULL);
1634 if (ret) {
1635 dev_info(&pf->pdev->dev,
1636 "Get LLDP MIB (local) AQ command failed =0x%x\n",
1637 pf->hw.aq.asq_last_status);
1638 kfree(buff);
1639 buff = NULL;
1640 goto command_write_done;
1641 }
3753cb24
NP
1642 dev_info(&pf->pdev->dev, "LLDP MIB (local)\n");
1643 print_hex_dump(KERN_INFO, "LLDP MIB (local): ",
1644 DUMP_PREFIX_OFFSET, 16, 1,
1645 buff, I40E_LLDPDU_SIZE, true);
02e9c290
JB
1646 kfree(buff);
1647 buff = NULL;
1648 } else if (strncmp(&cmd_buf[5], "get remote", 10) == 0) {
738a9e9b 1649 u16 llen, rlen;
3753cb24 1650 int ret;
02e9c290 1651 u8 *buff;
02e9c290
JB
1652 buff = kzalloc(I40E_LLDPDU_SIZE, GFP_KERNEL);
1653 if (!buff)
1654 goto command_write_done;
1655
1656 ret = i40e_aq_get_lldp_mib(&pf->hw,
1657 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
1658 I40E_AQ_LLDP_MIB_LOCAL,
1659 buff, I40E_LLDPDU_SIZE,
1660 &llen, &rlen, NULL);
1661 if (ret) {
1662 dev_info(&pf->pdev->dev,
1663 "Get LLDP MIB (remote) AQ command failed =0x%x\n",
1664 pf->hw.aq.asq_last_status);
1665 kfree(buff);
1666 buff = NULL;
1667 goto command_write_done;
1668 }
3753cb24
NP
1669 dev_info(&pf->pdev->dev, "LLDP MIB (remote)\n");
1670 print_hex_dump(KERN_INFO, "LLDP MIB (remote): ",
1671 DUMP_PREFIX_OFFSET, 16, 1,
1672 buff, I40E_LLDPDU_SIZE, true);
02e9c290
JB
1673 kfree(buff);
1674 buff = NULL;
1675 } else if (strncmp(&cmd_buf[5], "event on", 8) == 0) {
1676 int ret;
1677 ret = i40e_aq_cfg_lldp_mib_change_event(&pf->hw,
1678 true, NULL);
1679 if (ret) {
1680 dev_info(&pf->pdev->dev,
1681 "Config LLDP MIB Change Event (on) AQ command failed =0x%x\n",
1682 pf->hw.aq.asq_last_status);
1683 goto command_write_done;
1684 }
1685 } else if (strncmp(&cmd_buf[5], "event off", 9) == 0) {
1686 int ret;
1687 ret = i40e_aq_cfg_lldp_mib_change_event(&pf->hw,
1688 false, NULL);
1689 if (ret) {
1690 dev_info(&pf->pdev->dev,
1691 "Config LLDP MIB Change Event (off) AQ command failed =0x%x\n",
1692 pf->hw.aq.asq_last_status);
1693 goto command_write_done;
1694 }
1695 }
1696 } else if (strncmp(cmd_buf, "nvm read", 8) == 0) {
3753cb24 1697 u16 buffer_len, bytes;
02e9c290
JB
1698 u16 module;
1699 u32 offset;
1700 u16 *buff;
1701 int ret;
1702
1703 cnt = sscanf(&cmd_buf[8], "%hx %x %hx",
1704 &module, &offset, &buffer_len);
1705 if (cnt == 0) {
1706 module = 0;
1707 offset = 0;
1708 buffer_len = 0;
1709 } else if (cnt == 1) {
1710 offset = 0;
1711 buffer_len = 0;
1712 } else if (cnt == 2) {
1713 buffer_len = 0;
1714 } else if (cnt > 3) {
1715 dev_info(&pf->pdev->dev,
1716 "nvm read: bad command string, cnt=%d\n", cnt);
1717 goto command_write_done;
1718 }
1719
520dfd8b
JB
1720 /* set the max length */
1721 buffer_len = min_t(u16, buffer_len, I40E_MAX_AQ_BUF_SIZE/2);
02e9c290
JB
1722
1723 bytes = 2 * buffer_len;
520dfd8b
JB
1724
1725 /* read at least 1k bytes, no more than 4kB */
1726 bytes = clamp(bytes, (u16)1024, (u16)I40E_MAX_AQ_BUF_SIZE);
02e9c290
JB
1727 buff = kzalloc(bytes, GFP_KERNEL);
1728 if (!buff)
1729 goto command_write_done;
1730
1731 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
1732 if (ret) {
1733 dev_info(&pf->pdev->dev,
1734 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1735 ret, pf->hw.aq.asq_last_status);
1736 kfree(buff);
1737 goto command_write_done;
1738 }
1739
1740 ret = i40e_aq_read_nvm(&pf->hw, module, (2 * offset),
1741 bytes, (u8 *)buff, true, NULL);
1742 i40e_release_nvm(&pf->hw);
1743 if (ret) {
1744 dev_info(&pf->pdev->dev,
1745 "Read NVM AQ failed err=%d status=0x%x\n",
1746 ret, pf->hw.aq.asq_last_status);
1747 } else {
1748 dev_info(&pf->pdev->dev,
1749 "Read NVM module=0x%x offset=0x%x words=%d\n",
1750 module, offset, buffer_len);
3753cb24
NP
1751 if (buffer_len)
1752 print_hex_dump(KERN_INFO, "NVM Dump: ",
1753 DUMP_PREFIX_OFFSET, 16, 2,
1754 buff, buffer_len, true);
02e9c290
JB
1755 }
1756 kfree(buff);
1757 buff = NULL;
1758 } else {
1759 dev_info(&pf->pdev->dev, "unknown command '%s'\n", cmd_buf);
1760 dev_info(&pf->pdev->dev, "available commands\n");
1761 dev_info(&pf->pdev->dev, " add vsi [relay_seid]\n");
1762 dev_info(&pf->pdev->dev, " del vsi [vsi_seid]\n");
1763 dev_info(&pf->pdev->dev, " add relay <uplink_seid> <vsi_seid>\n");
1764 dev_info(&pf->pdev->dev, " del relay <relay_seid>\n");
1765 dev_info(&pf->pdev->dev, " add macaddr <vsi_seid> <aa:bb:cc:dd:ee:ff> [vlan]\n");
1766 dev_info(&pf->pdev->dev, " del macaddr <vsi_seid> <aa:bb:cc:dd:ee:ff> [vlan]\n");
1767 dev_info(&pf->pdev->dev, " add pvid <vsi_seid> <vid>\n");
1768 dev_info(&pf->pdev->dev, " del pvid <vsi_seid>\n");
1769 dev_info(&pf->pdev->dev, " dump switch\n");
1770 dev_info(&pf->pdev->dev, " dump vsi [seid]\n");
1771 dev_info(&pf->pdev->dev, " dump desc tx <vsi_seid> <ring_id> [<desc_n>]\n");
1772 dev_info(&pf->pdev->dev, " dump desc rx <vsi_seid> <ring_id> [<desc_n>]\n");
1773 dev_info(&pf->pdev->dev, " dump desc aq\n");
1774 dev_info(&pf->pdev->dev, " dump stats\n");
1775 dev_info(&pf->pdev->dev, " dump reset stats\n");
1776 dev_info(&pf->pdev->dev, " msg_enable [level]\n");
1777 dev_info(&pf->pdev->dev, " read <reg>\n");
1778 dev_info(&pf->pdev->dev, " write <reg> <value>\n");
1779 dev_info(&pf->pdev->dev, " clear_stats vsi [seid]\n");
1780 dev_info(&pf->pdev->dev, " clear_stats pf\n");
1781 dev_info(&pf->pdev->dev, " pfr\n");
1782 dev_info(&pf->pdev->dev, " corer\n");
1783 dev_info(&pf->pdev->dev, " globr\n");
1784 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");
1785 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");
1786 dev_info(&pf->pdev->dev, " lldp start\n");
1787 dev_info(&pf->pdev->dev, " lldp stop\n");
1788 dev_info(&pf->pdev->dev, " lldp get local\n");
1789 dev_info(&pf->pdev->dev, " lldp get remote\n");
1790 dev_info(&pf->pdev->dev, " lldp event on\n");
1791 dev_info(&pf->pdev->dev, " lldp event off\n");
1792 dev_info(&pf->pdev->dev, " nvm read [module] [word_offset] [word_count]\n");
1793 }
1794
1795command_write_done:
1796 kfree(cmd_buf);
1797 cmd_buf = NULL;
02e9c290
JB
1798 return count;
1799}
1800
1801static const struct file_operations i40e_dbg_command_fops = {
1802 .owner = THIS_MODULE,
1803 .open = simple_open,
1804 .read = i40e_dbg_command_read,
1805 .write = i40e_dbg_command_write,
1806};
1807
1808/**************************************************************
1809 * netdev_ops
1810 * The netdev_ops entry in debugfs is for giving the driver commands
1811 * to be executed from the netdev operations.
1812 **************************************************************/
1813static char i40e_dbg_netdev_ops_buf[256] = "hello world";
1814
1815/**
1816 * i40e_dbg_netdev_ops - read for netdev_ops datum
1817 * @filp: the opened file
1818 * @buffer: where to write the data for the user to read
1819 * @count: the size of the user's buffer
1820 * @ppos: file position offset
1821 **/
1822static ssize_t i40e_dbg_netdev_ops_read(struct file *filp, char __user *buffer,
1823 size_t count, loff_t *ppos)
1824{
1825 struct i40e_pf *pf = filp->private_data;
1826 int bytes_not_copied;
1827 int buf_size = 256;
1828 char *buf;
1829 int len;
1830
1831 /* don't allow partal reads */
1832 if (*ppos != 0)
1833 return 0;
1834 if (count < buf_size)
1835 return -ENOSPC;
1836
1837 buf = kzalloc(buf_size, GFP_KERNEL);
1838 if (!buf)
1839 return -ENOSPC;
1840
1841 len = snprintf(buf, buf_size, "%s: %s\n",
1842 pf->vsi[pf->lan_vsi]->netdev->name,
1843 i40e_dbg_netdev_ops_buf);
1844
1845 bytes_not_copied = copy_to_user(buffer, buf, len);
1846 kfree(buf);
1847
1848 if (bytes_not_copied < 0)
1849 return bytes_not_copied;
1850
1851 *ppos = len;
1852 return len;
1853}
1854
1855/**
1856 * i40e_dbg_netdev_ops_write - write into netdev_ops datum
1857 * @filp: the opened file
1858 * @buffer: where to find the user's data
1859 * @count: the length of the user's data
1860 * @ppos: file position offset
1861 **/
1862static ssize_t i40e_dbg_netdev_ops_write(struct file *filp,
1863 const char __user *buffer,
1864 size_t count, loff_t *ppos)
1865{
1866 struct i40e_pf *pf = filp->private_data;
1867 int bytes_not_copied;
1868 struct i40e_vsi *vsi;
004173cb 1869 char *buf_tmp;
02e9c290
JB
1870 int vsi_seid;
1871 int i, cnt;
1872
1873 /* don't allow partial writes */
1874 if (*ppos != 0)
1875 return 0;
1876 if (count >= sizeof(i40e_dbg_netdev_ops_buf))
1877 return -ENOSPC;
1878
1879 memset(i40e_dbg_netdev_ops_buf, 0, sizeof(i40e_dbg_netdev_ops_buf));
1880 bytes_not_copied = copy_from_user(i40e_dbg_netdev_ops_buf,
1881 buffer, count);
1882 if (bytes_not_copied < 0)
1883 return bytes_not_copied;
1884 else if (bytes_not_copied > 0)
1885 count -= bytes_not_copied;
1886 i40e_dbg_netdev_ops_buf[count] = '\0';
1887
004173cb
JB
1888 buf_tmp = strchr(i40e_dbg_netdev_ops_buf, '\n');
1889 if (buf_tmp) {
1890 *buf_tmp = '\0';
1891 count = buf_tmp - i40e_dbg_netdev_ops_buf + 1;
1892 }
1893
02e9c290
JB
1894 if (strncmp(i40e_dbg_netdev_ops_buf, "tx_timeout", 10) == 0) {
1895 cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i", &vsi_seid);
1896 if (cnt != 1) {
1897 dev_info(&pf->pdev->dev, "tx_timeout <vsi_seid>\n");
1898 goto netdev_ops_write_done;
1899 }
1900 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1901 if (!vsi) {
1902 dev_info(&pf->pdev->dev,
1903 "tx_timeout: VSI %d not found\n", vsi_seid);
1904 goto netdev_ops_write_done;
1905 }
1906 if (rtnl_trylock()) {
1907 vsi->netdev->netdev_ops->ndo_tx_timeout(vsi->netdev);
1908 rtnl_unlock();
1909 dev_info(&pf->pdev->dev, "tx_timeout called\n");
1910 } else {
1911 dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n");
1912 }
1913 } else if (strncmp(i40e_dbg_netdev_ops_buf, "change_mtu", 10) == 0) {
1914 int mtu;
1915 cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i %i",
1916 &vsi_seid, &mtu);
1917 if (cnt != 2) {
1918 dev_info(&pf->pdev->dev, "change_mtu <vsi_seid> <mtu>\n");
1919 goto netdev_ops_write_done;
1920 }
1921 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1922 if (!vsi) {
1923 dev_info(&pf->pdev->dev,
1924 "change_mtu: VSI %d not found\n", vsi_seid);
1925 goto netdev_ops_write_done;
1926 }
1927 if (rtnl_trylock()) {
1928 vsi->netdev->netdev_ops->ndo_change_mtu(vsi->netdev,
1929 mtu);
1930 rtnl_unlock();
1931 dev_info(&pf->pdev->dev, "change_mtu called\n");
1932 } else {
1933 dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n");
1934 }
1935
1936 } else if (strncmp(i40e_dbg_netdev_ops_buf, "set_rx_mode", 11) == 0) {
1937 cnt = sscanf(&i40e_dbg_netdev_ops_buf[11], "%i", &vsi_seid);
1938 if (cnt != 1) {
1939 dev_info(&pf->pdev->dev, "set_rx_mode <vsi_seid>\n");
1940 goto netdev_ops_write_done;
1941 }
1942 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1943 if (!vsi) {
1944 dev_info(&pf->pdev->dev,
1945 "set_rx_mode: VSI %d not found\n", vsi_seid);
1946 goto netdev_ops_write_done;
1947 }
1948 if (rtnl_trylock()) {
1949 vsi->netdev->netdev_ops->ndo_set_rx_mode(vsi->netdev);
1950 rtnl_unlock();
1951 dev_info(&pf->pdev->dev, "set_rx_mode called\n");
1952 } else {
1953 dev_info(&pf->pdev->dev, "Could not acquire RTNL - please try again\n");
1954 }
1955
1956 } else if (strncmp(i40e_dbg_netdev_ops_buf, "napi", 4) == 0) {
1957 cnt = sscanf(&i40e_dbg_netdev_ops_buf[4], "%i", &vsi_seid);
1958 if (cnt != 1) {
1959 dev_info(&pf->pdev->dev, "napi <vsi_seid>\n");
1960 goto netdev_ops_write_done;
1961 }
1962 vsi = i40e_dbg_find_vsi(pf, vsi_seid);
1963 if (!vsi) {
1964 dev_info(&pf->pdev->dev, "napi: VSI %d not found\n",
1965 vsi_seid);
1966 goto netdev_ops_write_done;
1967 }
1968 for (i = 0; i < vsi->num_q_vectors; i++)
493fb300 1969 napi_schedule(&vsi->q_vectors[i]->napi);
02e9c290
JB
1970 dev_info(&pf->pdev->dev, "napi called\n");
1971 } else {
1972 dev_info(&pf->pdev->dev, "unknown command '%s'\n",
1973 i40e_dbg_netdev_ops_buf);
1974 dev_info(&pf->pdev->dev, "available commands\n");
1975 dev_info(&pf->pdev->dev, " tx_timeout <vsi_seid>\n");
1976 dev_info(&pf->pdev->dev, " change_mtu <vsi_seid> <mtu>\n");
1977 dev_info(&pf->pdev->dev, " set_rx_mode <vsi_seid>\n");
1978 dev_info(&pf->pdev->dev, " napi <vsi_seid>\n");
1979 }
1980netdev_ops_write_done:
1981 return count;
1982}
1983
1984static const struct file_operations i40e_dbg_netdev_ops_fops = {
1985 .owner = THIS_MODULE,
1986 .open = simple_open,
1987 .read = i40e_dbg_netdev_ops_read,
1988 .write = i40e_dbg_netdev_ops_write,
1989};
1990
1991/**
1992 * i40e_dbg_pf_init - setup the debugfs directory for the pf
1993 * @pf: the pf that is starting up
1994 **/
1995void i40e_dbg_pf_init(struct i40e_pf *pf)
1996{
6301002f 1997 struct dentry *pfile;
02e9c290 1998 const char *name = pci_name(pf->pdev);
6301002f 1999 const struct device *dev = &pf->pdev->dev;
02e9c290
JB
2000
2001 pf->i40e_dbg_pf = debugfs_create_dir(name, i40e_dbg_root);
6301002f
JB
2002 if (!pf->i40e_dbg_pf)
2003 return;
2004
2005 pfile = debugfs_create_file("command", 0600, pf->i40e_dbg_pf, pf,
2006 &i40e_dbg_command_fops);
2007 if (!pfile)
2008 goto create_failed;
2009
2010 pfile = debugfs_create_file("dump", 0600, pf->i40e_dbg_pf, pf,
2011 &i40e_dbg_dump_fops);
2012 if (!pfile)
2013 goto create_failed;
2014
2015 pfile = debugfs_create_file("netdev_ops", 0600, pf->i40e_dbg_pf, pf,
2016 &i40e_dbg_netdev_ops_fops);
2017 if (!pfile)
2018 goto create_failed;
2019
2020 return;
2021
2022create_failed:
2023 dev_info(dev, "debugfs dir/file for %s failed\n", name);
2024 debugfs_remove_recursive(pf->i40e_dbg_pf);
2025 return;
02e9c290
JB
2026}
2027
2028/**
2029 * i40e_dbg_pf_exit - clear out the pf's debugfs entries
2030 * @pf: the pf that is stopping
2031 **/
2032void i40e_dbg_pf_exit(struct i40e_pf *pf)
2033{
2034 debugfs_remove_recursive(pf->i40e_dbg_pf);
2035 pf->i40e_dbg_pf = NULL;
2036
2037 kfree(i40e_dbg_dump_buf);
2038 i40e_dbg_dump_buf = NULL;
2039}
2040
2041/**
2042 * i40e_dbg_init - start up debugfs for the driver
2043 **/
2044void i40e_dbg_init(void)
2045{
2046 i40e_dbg_root = debugfs_create_dir(i40e_driver_name, NULL);
2047 if (!i40e_dbg_root)
2048 pr_info("init of debugfs failed\n");
2049}
2050
2051/**
2052 * i40e_dbg_exit - clean out the driver's debugfs entries
2053 **/
2054void i40e_dbg_exit(void)
2055{
2056 debugfs_remove_recursive(i40e_dbg_root);
2057 i40e_dbg_root = NULL;
2058}
2059
2060#endif /* CONFIG_DEBUG_FS */