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