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